{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\npublic class D {\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) throws IOException {\n        FastReader fr = new FastReader();\n        FastWriter fw = new FastWriter();\n        int n = fr.nextInt();\n        int m = fr.nextInt();\n        for (int r = 0; r < n / 2; r++) {\n            for (int c = 0; c < m; c++) {\n                fw.println((r + 1) + \" \" + (c + 1));\n                fw.println((n - r) + \" \" + (m - c));\n            }\n        }\n        if (n % 2 != 0) {\n            int r = n / 2;\n            for (int c = 0; c < m / 2; c++) {\n                fw.println((r + 1) + \" \" + (c + 1));\n                fw.println((r + 1) + \" \" + (m - c));\n            }\n            if (m % 2 != 0) fw.println((r + 1) + \" \" + (m / 2 + 1));\n        }\n        fw.close();\n    }\n}\n", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n \npublic class pillar {\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[200005];\n\t\tfor (int i=1;i<=n;i++) \n\t\ta[i]=sc.nextInt();\n\t\tfor (int i=2;i<n;i++) \n\t\tif (a[i-1]>a[i]&&a[i]<a[i+1]) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(\"YES\");\n\t}\n}\n\n", "complexity": "linear", "problem": "1197_B. Pillars", "from": "CODEFORCES"}
{"src": "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 SequenceTransformation {\n    void solve() {\n        int p = 1, n = in.nextInt();\n        while (n > 0) {\n            if (n == 1) {\n                out.print(p + \" \");\n                break;\n            }\n            if (n == 2) {\n                out.print(p + \" \");\n                out.print(2 * p + \" \");\n                break;\n            }\n            if (n == 3) {\n                out.print(p + \" \");\n                out.print(p + \" \");\n                out.print(3 * p + \" \");\n                break;\n            }\n            for (int i = 0; i < (n + 1) / 2; i++) {\n                out.print(p + \" \");\n            }\n            p *= 2;\n            n /= 2;\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 SequenceTransformation().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", "complexity": "linear", "problem": "1059_C. Sequence Transformation", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.*;\npublic class Solution\n{\n    public static void main(String [] args) throws IOException\n    {\n        PrintWriter pw=new PrintWriter(System.out);//use pw.println() not pw.write();\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(br.readLine());\n        /*\n        inputCopy\n5 3\nxyabd\noutputCopy\n29\ninputCopy\n7 4\nproblem\noutputCopy\n34\ninputCopy\n2 2\nab\noutputCopy\n-1\ninputCopy\n12 1\nabaabbaaabbb\noutputCopy\n1\n        */\n        int n=Integer.parseInt(st.nextToken());\n        int k=Integer.parseInt(st.nextToken());\n        st=new StringTokenizer(br.readLine());\n        String str=st.nextToken();\n        char [] arr=str.toCharArray();\n        Arrays.sort(arr);\n        int weight=arr[0]-96;\n        char a=arr[0];\n        int included=1;\n        for(int i=1;i<arr.length;++i)\n        {\n            if(included==k)\n                break;\n            char c=arr[i];\n            if(c-a<2)\n                continue;\n           \n            weight+=arr[i]-96;\n            ++included;\n            a=arr[i];\n            \n        }\n        if(included==k)\n            pw.println(weight);\n        else\n            pw.println(-1);\n        pw.close();//Do not forget to write it after every program return statement !!\n    }\n}\n/*\n\u2192Judgement Protocol\nTest: #1, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n5 3\nxyabd\nOutput\n29\nAnswer\n29\nChecker Log\nok 1 number(s): \"29\"\nTest: #2, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n7 4\nproblem\nOutput\n34\nAnswer\n34\nChecker Log\nok 1 number(s): \"34\"\nTest: #3, time: 139 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nab\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #4, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 1\nabaabbaaabbb\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #5, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #6, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #7, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\na\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #8, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #9, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #10, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nuwgmkyqeiaocs\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #11, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nhzdxpbfvrltnj\nOutput\n182\nAnswer\n182\nChecker Log\nok 1 number(s): \"182\"\nTest: #12, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nn\nOutput\n14\nAnswer\n14\nChecker Log\nok 1 number(s): \"14\"\nTest: #13, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 8\nsmzeblyjqw\nOutput\n113\nAnswer\n113\nChecker Log\nok 1 number(s): \"113\"\nTest: #14, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n20 20\ntzmvhskkyugkuuxpvtbh\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #15, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #16, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #17, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #18, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 7\niuiukrxcml\nOutput\n99\nAnswer\n99\nChecker Log\nok 1 number(s): \"99\"\nTest: #19, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #20, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 6\nfwseyrarkwcd\nOutput\n61\nAnswer\n61\nChecker Log\nok 1 number(s): \"61\"\nTest: #21, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nac\nOutput\n4\nAnswer\n4\nChecker Log\nok 1 number(s): \"4\"\nTest: #22, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nc\nOutput\n3\nAnswer\n3\nChecker Log\nok 1 number(s): \"3\"\nTest: #23, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nad\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #24, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER\nInput\n2 1\nac\nOutput\n-1\nAnswer\n1\nChecker Log\nwrong answer 1st number\n*/", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.SortedSet;\nimport java.util.Set;\nimport java.util.NavigableSet;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\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        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, FastScanner in, FastPrinter out) {\n            int n = in.nextInt();\n            int k = in.nextInt();\n            char[] c = in.next().toCharArray();\n            NavigableSet<Integer> ones = new TreeSet<>();\n            NavigableSet<Integer> zeros = new TreeSet<>();\n            for (int i = 0; i < n; i++) {\n                if (c[i] == '0') zeros.add(i);\n                else ones.add(i);\n            }\n            if (ones.isEmpty() || zeros.isEmpty() || ones.last() - ones.first() + 1 <= k || zeros.last() - zeros.first() + 1 <= k) {\n                out.println(\"tokitsukaze\");\n                return;\n            }\n            if (check(ones, n, k) && check(zeros, n, k)) {\n                out.println(\"quailty\");\n                return;\n            }\n            out.println(\"once again\");\n        }\n\n        private boolean check(NavigableSet<Integer> ones, int n, int k) {\n            for (int i = 0; i + k <= n; i++) {\n                int left = ones.first();\n                int right = ones.last();\n                if (left >= i) {\n                    left = ones.higher(i + k - 1);\n                }\n                if (right < i + k) {\n                    right = ones.lower(i);\n                }\n                if (right - left + 1 > k) {\n                    return false;\n                }\n            }\n            return true;\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        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 String readLine() {\n            try {\n                return super.readLine();\n            } catch (IOException e) {\n                return null;\n            }\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1190_C. Tokitsukaze and Duel", "from": "CODEFORCES"}
{"src": "import java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.nio.charset.Charset;\nimport java.util.*;\n\nimport static java.lang.System.gc;\nimport static java.lang.System.out;\n\npublic class Main {\n\n    Scanner scanner = new Scanner(System.in);\n\n    public static void main(String[] args) {\n        new Main().solve();\n    }\n\n\n    void solve() {\n\n        int n = scanner.nextInt();\n        scanner.nextLine();\n        String s1 = scanner.nextLine();\n        String s2 = scanner.nextLine();\n\n\n        int ans = 0;\n        boolean a[] = new boolean[30];\n        boolean b[] = new boolean[30];\n\n        for (int i = 0; i < n; i++) {\n            if (s1.charAt(i) != s2.charAt(i)) {\n                ans ++;\n                a[s1.charAt(i)  - 'a'] = true;\n                b[s2.charAt(i)  - 'a'] = true;\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            if (s1.charAt(i) != s2.charAt(i) && a[s2.charAt(i) - 'a'] && b[s1.charAt(i) - 'a']) {\n                for (int j = i + 1; j < n; j ++) {\n                    if (s1.charAt(i) == s2.charAt(j) && s1.charAt(j) == s2.charAt(i)) {\n                        out.println(ans - 2);\n                        out.println((i + 1) + \" \" + (j + 1));\n                        return;\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (s1.charAt(i) != s2.charAt(i) && (a[s2.charAt(i) - 'a'] || b[s1.charAt(i) - 'a'])) {\n                for (int j = i + 1; j < n; j ++) {\n                    if (s1.charAt(j) != s2.charAt(j) && (s1.charAt(i) == s2.charAt(j) || s1.charAt(j) == s2.charAt(i))) {\n                        out.println(ans - 1);\n                        out.println((i + 1) + \" \" + (j + 1));\n                        return;\n                    }\n                }\n            }\n        }\n\n        out.println(ans);\n        out.println(-1 + \" \" + -1);\n    }\n}", "complexity": "quadratic", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n    static int n;\n     static long TotalTime;\n    static Problem[] problems;\n    static StringBuilder sb;\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        sb = new StringBuilder();\n        n = sc.nextInt();\n        TotalTime = sc.nextLong();\n        problems = new Problem[n];\n        for (int i = 0; i < n; i++) {\n            problems[i] = new Problem (sc.nextInt(), sc.nextLong(), i);\n        }\n        Arrays.sort(problems);\n        long num = -1;\n        long high = n;\n        long low = 0;\n        int iter = 0;\n        while (high - low > 1) {\n            num = (high + low) / 2;\n            if (test(num, false)) {\n                low = num;\n            }\n            else {\n                high = num;\n            }\n        }\n        if (test(high, false))\n            num = high;\n        else\n            num = low;\n        test(num, true);\n        System.out.print(sb);\n    }\n\n    public static boolean test (long num, boolean print) {\n        int count = 0;\n        long sum = 0L;\n        if (print) sb.append(num + \"\\n\" + num + \"\\n\");\n        for (int i = 0; i < n && count < num; i++) {\n            if (problems[i].a >= num) {\n                count++;\n                sum += problems[i].t;\n                if (print) sb.append((problems[i].index + 1) + \" \");\n            }\n        }\n        return (count == num) && (sum <= TotalTime);\n    }\n\n    public static class Problem implements Comparable<Problem>  {\n        int a;\n        long t;\n        int index;\n        \n        public int compareTo(Problem o) {\n          return Long.compare(t, o.t);\n        }\n        public Problem (int a, long t, int index) {\n            this.a = a;\n            this.t = t;\n            this.index = index;\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}", "complexity": "nlogn", "problem": "913_D. Too Easy Problems", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport javax.lang.model.util.ElementScanner6;\npublic class codef\n{\n    public static void main(String ar[]) throws IOException\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer nk=new StringTokenizer(br.readLine());\n        int n=Integer.parseInt(nk.nextToken());\n        int k=Integer.parseInt(nk.nextToken());\n        String st[]=br.readLine().split(\" \");\n        \n        int ans[]=new int[n];\n        int a[]=new int[n];\n        for(int i=0;i<n;i++)\n            ans[i]=Integer.parseInt(st[i]);  \n\n        for(int i=1;i<n;i++)\n            a[i]=ans[i]-ans[i-1];\n        a[0]=-1;\n\n        Arrays.sort(a);\n        int count=0,sum=0;\n        for(int i=0;i<n;i++)\n            if(a[i]<0)\n                count++;\n            else\n                sum=sum+a[i];\n        \n        k=k-count;\n        int i=n-1;\n        while(k>0 && i>=0)\n        {\n            if(a[i]>-1)\n            {\n                sum=sum-a[i];\n                k--;\n            }\n            i--;\n        }\n        System.out.println(sum);\n    }\n}", "complexity": "nlogn", "problem": "1197_C. Array Splitting", "from": "CODEFORCES"}
{"src": "\n// LM10: The next Ballon d'or\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport javafx.util.Pair;\npublic class Main\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;li<arr.length;++li){ arr[li]=i();}}\n        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}\n        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }\n    }\n    public static void main(String[] args)throws IOException {\n        /*\ninputCopy\n4\n2 1 2 1\noutputCopy\n4\ninputCopy\n5\n0 -1 -1 -1 -1\noutputCopy\n4\n*/\n        PrintWriter pw = new PrintWriter(System.out);\n        FastReader fr = new FastReader();\n        int n=fr.i();\n        int [] arr=new int[n];\n        fr.scanIntArr(arr);\n        int min=Integer.MAX_VALUE;\n        int max=Integer.MIN_VALUE;\n        long sum=0;\n        if(n==1)\n        {\n            pw.println(arr[0]);\n            pw.flush();\n            pw.close();\n            return;\n        }\n        for(int i=0;i<n;++i)\n        {\n            if(arr[i]<min)\n                min=arr[i];\n            if(arr[i]>max)\n                max=arr[i];\n            sum+=Math.abs(arr[i]);\n        }\n        if(min>0)\n        {\n            sum-=2*min;\n        }\n        if(max<0)\n        {\n            sum+=2*max;\n        }\n        pw.println(sum);\n        pw.flush();\n        pw.close();\n    }\n}", "complexity": "linear", "problem": "1038_D. Slime", "from": "CODEFORCES"}
{"src": "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        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        // int n = Integer.parseInt(bf.readLine());\n        StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        int n = Integer.parseInt(st.nextToken());\n        int m = Integer.parseInt(st.nextToken());\n        StringBuilder ans1 = new StringBuilder();\n        StringBuilder ans2 = new StringBuilder();\n        for(int i=0; i<2229; i++) ans1.append('5');\n        ans1.append('6');\n        for(int i=0; i<2230; i++) ans2.append('4');\n        out.println(ans1.toString());\n        out.println(ans2.toString());\n        out.close(); System.exit(0);\n    }\n}\n", "complexity": "constant", "problem": "1028_B. Unnatural Conditions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\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    public static void main(String args[] ) {\n        \n        FastReader sc = new FastReader();\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int[] arr = new int[105];\n        \n        for(int i=0;i<m;i++){\n            int a = sc.nextInt();\n            arr[a]++;\n        }\n        \n        for(int i=1;i<=1000;i++){\n            int sum=0;\n            \n            for(int a:arr){\n                if(a!=0){\n                    sum+=(a/i);\n                }\n            }\n            \n            \n            if(sum<n){\n                System.out.println(i-1);\n                return;\n            }\n            \n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import javax.print.attribute.standard.RequestingUserName;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws NumberFormatException, IOException\n    {\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 tc = in.nextInt();\n        for(int i = 0; i < tc; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class Task {\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n            int k = in.nextInt();\n            int[] s = getArray(in.nextToken());\n            int[] a = getArray(in.nextToken());\n            int[] b = getArray(in.nextToken());\n\n            int[] per = new int[k];\n            boolean[] used = new boolean[k];\n            Arrays.fill(per , -1);\n\n            if(!check(s , a, per.clone(), k, used)){\n                out.println(\"NO\");\n                return;\n            }\n\n            for(int i = 0; i < s.length; i++){\n                if(per[s[i]] != -1){\n                    continue;\n                }\n                for(int j = 0; j < k; j++){\n                    if(used[j]){\n                        continue;\n                    }\n                    per[s[i]] = j;\n                    used[j] = true;\n                    if(check(s , a , per.clone() , k, used)){\n                        break;\n                    }\n                    per[s[i]] = -1;\n                    used[j] = false;\n                }\n            }\n\n            for(int i = 0; i < s.length; i++){\n                if(per[s[i]] == -1){\n                    out.println(\"NO\");\n                    return;\n                }\n                s[i] = per[s[i]];\n            }\n\n            if(cmp(s , b) > 0){\n                out.println(\"NO\");\n                return;\n            }\n\n\n            int last = 0;\n            for(int i = 0; i < k; i++){\n                if(per[i] == -1) {\n                    while(used[last])last++;\n                    per[i] = last;\n                    used[last] = true;\n                }\n            }\n\n            char[] result = new char[k];\n\n            for(int i = 0; i < k; i++){\n                result[i] = (char)('a' + per[i]);\n            }\n            out.println(\"YES\");\n            out.println(new String(result));\n        }\n\n        private int cmp(int[] a, int[] b){\n            for(int i = 0; i < a.length; i++){\n                if(a[i] != b[i]){\n                    return a[i] < b[i] ? -1 : 1;\n                }\n            }\n            return 0;\n        }\n\n\n        private boolean check(int[] s, int[] a, int[] per, int k, boolean[] used) {\n            int res[] = new int[s.length];\n            int last = k - 1;\n            for(int i = 0; i < res.length; ++i){\n\n                if(per[s[i]] == -1){\n\n                    while(last >= 0 && used[last]){\n                        last--;\n                    }\n\n                    if(last < 0){\n                        return false;\n                    }\n\n                    per[s[i]] = last;\n                    last--;\n                }\n                res[i] = per[s[i]];\n            }\n            return cmp(a , res) <= 0;\n        }\n\n        private int[] getArray(String nextToken) {\n            int result[] = new int[nextToken.length()];\n            for(int i = 0; i < nextToken.length(); i++){\n                result[i] = nextToken.charAt(i) - 'a';\n            }\n            return result;\n        }\n    }\n\n    static class InputReader {\n\n        BufferedReader in;\n        StringTokenizer tok;\n\n        public InputReader(InputStream stream){\n            in = new BufferedReader(new InputStreamReader(stream), 32768);\n            tok = null;\n        }\n\n        String nextToken()\n        {\n            String line = \"\";\n            while(tok == null || !tok.hasMoreTokens()) {\n                try {\n                    if((line = in.readLine()) != null)\n                        tok = new StringTokenizer(line);\n                    else\n                        return null;\n                } catch (IOException e) {\n                    e.printStackTrace();\n                    return null;\n                }\n            }\n            return tok.nextToken();\n        }\n        int nextInt(){\n            return Integer.parseInt(nextToken());\n        }\n        long nextLong()\t{\n            return Long.parseLong(nextToken());\n        }\n        double nextDouble()\t{\n            return Double.parseDouble(nextToken());\n        }\n\n    }\n\n}", "complexity": "quadratic", "problem": "1086_C. Vasya and Templates", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n    static int[] a;\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        a = sc.nextIntArray(n);\n        long inversions = divide(0, n - 1);\n//        out.println(inversions);\n//        System.err.println(Arrays.toString(a));\n        if (n == 5) out.println(\"Petr\");\n        else {\n            if (n % 2 == 0) out.println(inversions % 2 == 0 ? \"Petr\" : \"Um_nik\");\n            else out.println(inversions % 2 != 0 ? \"Petr\" : \"Um_nik\");\n        }\n        out.flush();\n        out.close();\n    }\n\n    static long divide(int b, int e) {\n        if (b == e) return 0;\n        long cnt = 0;\n        int mid = b + e >> 1;\n        cnt += divide(b, mid);\n        cnt += divide(mid + 1, e);\n        cnt += merge(b, mid, e);\n        return cnt;\n    }\n\n    static long merge(int b, int mid, int e) {\n        long cnt = 0;\n        int len = e - b + 1;\n        int[] tmp = new int[len];\n        int i = b, j = mid + 1;\n        for (int k = 0; k < len; k++) {\n            if (i == mid + 1 || (j != e + 1 && a[i] > a[j])) {\n                tmp[k] = a[j++];\n                cnt += (mid + 1 - i);\n            } else tmp[k] = a[i++];\n        }\n        for (int k = 0; k < len; k++)\n            a[b + k] = tmp[k];\n        return cnt;\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\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}", "complexity": "nlogn", "problem": "986_B. Petr and Permutations", "from": "CODEFORCES"}
{"src": "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 S=Integer.parseInt(s1[1]);\n            if(S%n==0)\n             System.out.println(S/n);\n            else\n             System.out.println(S/n+1);\n      }\n}", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\npublic class Main {\n\tstatic StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\tpublic static void main(String[] args) {\n\t\tint n=nextInt();\n\t\tint m=nextInt();\n\t\tlong b[]=new long[n];\n\t\tlong g[]=new long[m];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tb[i]=nextInt();\n\t\tfor(int i=0;i<m;i++)\n\t\t\tg[i]=nextInt();\n\t\tArrays.sort(b);\n\t\tArrays.sort(g);\n\t\tif(b[n-1]>g[0])\n\t\t\tSystem.out.println(\"-1\");\n\t\telse if(b[n-1]==g[0]){\n\t\t\tlong sum=0;\n\t\t\tfor(int i=0;i<m;i++)\n\t\t\t\tsum+=g[i];\n\t\t\tfor(int i=0;i<n-1;i++){\n\t\t\t\tsum+=(m*b[i]);\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}else{\n\t\t\tlong sum=0;\n\t\t\tfor(int i=0;i<m;i++)\n\t\t\t\tsum+=g[i];\n\t\t\tsum+=b[n-1];\n\t\t\tsum+=(b[n-2]*(m-1));\n\t\t\tfor(int i=0;i<n-2;i++){\n\t\t\t\tsum+=(m*b[i]);\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n\tstatic int nextInt(){\n\t\ttry {\n\t\t\tst.nextToken();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn (int)st.nval;\n\t}\n}\n", "complexity": "nlogn", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A912 {\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\t\n\t\tint A = scan.nextInt();\n\t\tint B = scan.nextInt();\n\t\tlong x = scan.nextInt();\n\t\tlong y = scan.nextInt();\n\t\tlong z = scan.nextInt();\n\t\t\n\t\tlong requiredA = x * 2 + y;\n\t\tlong requiredB = y + z * 3;\n\t\t\n\t\tlong neededA = Math.max(0, requiredA - A);\n\t\tlong neededB = Math.max(0, requiredB - B);\n\t\tSystem.out.print(neededA + neededB);\n\t}\n\n}\n", "complexity": "constant", "problem": "912_A. Tricky Alchemy", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class C {\n\n    void solve(){\n       int n = readInt();\n       int q = readInt();\n       int max = 0;\n       int[] a = new int[n];\n       Deque<Integer> deque = new ArrayDeque<>();\n       for(int i = 0;i<n;i++){\n           a[i] = readInt();\n           deque.addLast(a[i]);\n           max = Math.max(max, a[i]);\n       }\n        List<String> ans = new ArrayList<>();\n        while(deque.peekFirst() != max){\n           int one = deque.pollFirst();\n           int two = deque.pollFirst();\n           ans.add(one + \" \" + two);\n           deque.addFirst(one > two ? one : two);\n           deque.addLast(one > two ? two : one);\n           if(one == max) break;\n       }\n\n       for(int i = 0;i<n;i++){\n           a[i] = deque.pollFirst();\n       }\n\n       for(int i = 0;i<q;i++){\n          long x = readLong();\n           if(x <= ans.size()){\n               out.println(ans.get((int)x - 1));\n               continue;\n           }\n           x -= ans.size();\n           int y =(int) (x%(n - 1) - 1%(n - 1) + (n - 1)) % (n - 1) + 1;\n           out.println(max + \" \" + a[y]);\n       }\n    }\n\n    public static void main(String[] args) {\n        new C().run();\n    }\n\n    void run(){\n        init();\n        solve();\n        out.close();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init(){\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out  = new PrintWriter(System.out);\n    }\n\n    String readLine(){\n        try{\n            return in.readLine();\n        }catch(Exception ex){\n            throw new RuntimeException(ex);\n        }\n    }\n    String readString(){\n        while(!tok.hasMoreTokens()){\n            String nextLine = readLine();\n            if(nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt(){\n        return Integer.parseInt(readString());\n    }\n\n    long readLong(){\n        return Long.parseLong(readString());\n    }\n\n    double readDouble(){\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "linear", "problem": "1180_C. Valeriy and Deque", "from": "CODEFORCES"}
{"src": "//package contese_476;\nimport java.util.*;\npublic class q1 \n{\n\tint m=(int)1e9+7;\npublic class Node\n{\n\tint a;\n\tint b;\n\tpublic void Node(int a,int b)\n\t{\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t}\n}\npublic int mul(int a ,int b)\n{\na=a%m;\nb=b%m;\nreturn((a*b)%m);\n}\npublic int pow(int a,int b)\n{\n\tint x=1;\n\twhile(b>0)\n\t{\n\t\tif(b%2!=0)\n\t\t\tx=mul(x,a);\n\t\ta=mul(a,a);\n\t\tb=b/2;\n\t}\n\treturn x;\n}\npublic static long gcd(long a,long b)\n{\n\tif(b==0)\n\t\treturn a;\n\telse\n\t\treturn gcd(b,a%b);\n}\npublic static void main(String[] args)\n{\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tHashMap<Integer,Integer> h=new HashMap();\n\t//HashMap<Integer,Integer> h1=new HashMap();\n\tint[] a=new int[n];\n\tint x=sc.nextInt();\n\tfor(int i=0;i<n;i++)\n\t{\n\t\ta[i]=sc.nextInt();\n\t\tif(h.get(a[i])==null)\n\t\t{\n\t\t\th.put(a[i], 1);\n\t\t\t//h1.put(a[i],i);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\tcontinue;\n\t\t\n\t\telse\n\t\t{\n\t\t\t\n\t\t\tSystem.out.print(1);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\th.put(num, 1);\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(2);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tSystem.out.print(-1);\n\t\n     \n}\n\n}", "complexity": "linear", "problem": "1013_B. And", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n    private static int[] a;\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt(), m = sc.nextInt();\n\n        a = new int[101];\n        for (int i = 0; i < m; i++) {\n            int type = sc.nextInt();\n            a[type] = a[type] + 1;\n        }\n\n        int lo=1, hi=100, max=0;\n\n        while (lo <= hi) {\n            int mid = lo + (hi - lo)/2;\n            if (check(n, mid)) {\n                max = mid;\n                lo = mid+1;\n            } else {\n                hi = mid -1;\n            }\n        }\n        System.out.println(max);\n    }\n\n    public static boolean check(int n, int target) {\n        int result = 0;\n        for (int i=0; i <a.length; i++) {\n            result = result + (a[i] / target);\n        }\n        if (result >= n) {return true;}\n        return false;\n    }\n}", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1027D {\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[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tcc[i] = Integer.parseInt(st.nextToken());\n\t\tst = new StringTokenizer(br.readLine());\n\t\tint[] aa = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = Integer.parseInt(st.nextToken()) - 1;\n\t\tint[] used = new int[n];\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (used[i] == 2)\n\t\t\t\tcontinue;\n\t\t\tint j = i;\n\t\t\twhile (used[j] == 0) {\n\t\t\t\tused[j] = 1;\n\t\t\t\tj = aa[j];\n\t\t\t}\n\t\t\tif (used[j] == 1) {\n\t\t\t\tint c = cc[j];\n\t\t\t\twhile (used[j] == 1) {\n\t\t\t\t\tused[j] = 2;\n\t\t\t\t\tc = Math.min(c, cc[j]);\n\t\t\t\t\tj = aa[j];\n\t\t\t\t}\n\t\t\t\tans += c;\n\t\t\t}\n\t\t\tj = i;\n\t\t\twhile (used[j] == 1) {\n\t\t\t\tused[j] = 2;\n\t\t\t\tj = aa[j];\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "linear", "problem": "1027_D. Mouse Hunt", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    private void solve() {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        int n = nextInt(), m = nextInt(), u = 1, d = n;\n\n        while (u < d) {\n            for (int i = 1; i <= m; i++) {\n                out.println(u + \" \" + i);\n                out.println(d + \" \" + (m - i + 1));\n            }\n            u++;\n            d--;\n        }\n        if (u == d) {\n            int l = 1, r = m;\n            while (l < r) {\n                out.println(u + \" \" + l++);\n                out.println(d + \" \" + r--);\n            }\n            if (l == r) out.println(u + \" \" + l);\n        }\n\n        out.close();\n    }\n\n    public static void main(String[] args) {\n        new D().solve();\n    }\n\n    private BufferedReader br;\n    private StringTokenizer st;\n    private PrintWriter out;\n\n    private String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return st.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", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\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    public static void main(String args[] ) {\n        \n        FastReader sc = new FastReader();\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int[] arr = new int[105];\n        \n        for(int i=0;i<m;i++){\n            int a = sc.nextInt();\n            arr[a]++;\n        }\n        \n        for(int i=1;i<=1000;i++){\n            int sum=0;\n            \n            for(int a:arr){\n                if(a!=0){\n                    sum+=(a/i);\n                }\n            }\n            \n            \n            if(sum<n){\n                System.out.println(i-1);\n                return;\n            }\n            \n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "//package com.krakn.CF.B1159;\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        int n;\n        n = sc.nextInt();\n        int[] arr = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            arr[i] = sc.nextInt();\n        }\n\n        int min = 1000000000, temp;\n\n        for (int i = 0; i < n; i++) {\n            temp = arr[i] / Math.max(i, n - 1 - i);\n            if (temp < min)\n                min = temp;\n//            System.out.println(i + \" \" + temp);\n        }\n\n        System.out.println(min);\n    }\n}\n", "complexity": "linear", "problem": "1159_B. Expansion coefficient of the array", "from": "CODEFORCES"}
{"src": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\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\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\tString[] s=br.readLine().split(\" \");\n\t\tfor(int i=0;i<n;i++){\n\t\t\tA[i]=Integer.parseInt(s[i]);\n\t\t}\n\t\tMap memo=new HashMap();\n\t\tint[] f=new int[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(!memo.containsKey(A[i])){\n\t\t\t\tmemo.put(A[i],1);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tint ct=(int)memo.get(A[i]);\n\t\t\t\tmemo.put(A[i],ct+1);\n\t\t\t}\n\t\t\tint tot=0;\n\t\t\tif(memo.containsKey(A[i]-1)){\n\t\t\t\ttot+=(int)memo.get(A[i]-1);\n\t\t\t}\n\t\t\tif(memo.containsKey(A[i]+1)){\n\t\t\t\ttot+=(int)memo.get(A[i]+1);\n\t\t\t}\n\t\t\ttot+=(int)memo.get(A[i]);\n\t\t\tf[i]=tot;\n\t\t}\n\t\tBigInteger res=new BigInteger(\"0\");\n\t\tfor(int i=0;i<n;i++){\n\t\t\tint tot1=i+1-f[i];\n\t\t\tint tot2=0;\n\t\t\tif(memo.containsKey(A[i]-1)){\n\t\t\t\ttot2+=(int)memo.get(A[i]-1);\n\t\t\t}\n\t\t\tif(memo.containsKey(A[i]+1)){\n\t\t\t\ttot2+=(int)memo.get(A[i]+1);\n\t\t\t}\n\t\t\ttot2+=(int)memo.get(A[i]);\n\t\t\ttot2=n-i-1-(tot2-f[i]);\n\t\t\t//res+=(long)(tot1-tot2)*(long)A[i];\n\t\t\tres=res.add(BigInteger.valueOf((long)(tot1-tot2)*(long)A[i]));\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n\npublic class Main {\n    static int n=5;\n    static int[] arr=new int[5];\n\n    public static void main(String[] args) {\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        {\n            arr[i]=sc.nextInt();\n        }\n        for (int i=0;i<n;i++)\n        {\n            if (arr[i]>=0)\n            {\n                arr[i]=-arr[i]-1;\n            }\n        }\n        if (n%2!=0)\n        {\n            int min=0;\n            for (int i=1;i<n;i++)\n            {\n                if (arr[i]<arr[min])\n                    min=i;\n            }\n            arr[min]=-arr[min]-1;\n        }\n        for (int x:arr)\n        {\n            System.out.print(x + \" \");\n        }\n\n    }\n}", "complexity": "linear", "problem": "1180_B. Nick and Array", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args)\n    {\n        Scanner stdin = new Scanner(System.in);\n        /*int n = stdin.nextInt();\n        for(int i = 0; i < n; i++)\n        {\n        \ttest(stdin);\n        }*/\n        test(stdin);\n        stdin.close();\n    }\n    public static void test(Scanner stdin)\n    {\n    \tint n = stdin.nextInt();\n    \tint min = Integer.MAX_VALUE;\n    \tfor(int i = 0; i < n; i++)\n    \t{\n    \t\tint a = stdin.nextInt();\n    \t\tif((int)((1.0)*a/(Math.max(i, n - i - 1))) < min)\n    \t\t{ min = (int)((1.0)*a/(Math.max(i, n - i - 1))); }\n    \t}\n    \tSystem.out.println(min);\n    }\n}", "complexity": "linear", "problem": "1159_B. Expansion coefficient of the array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main2 {\n\n    private FastScanner scanner = new FastScanner();\n\n    public static void main(String[] args) {\n        new Main2().solve();\n    }\n\n    private void solve() {\n\n        int n = scanner.nextInt();\n\n\n        int a[][] = new int[n][3];\n\n        for (int i = 0; i < n; i++) {\n            a[i][0] = scanner.nextInt();\n            a[i][1] = scanner.nextInt();\n            a[i][2] = i;\n        }\n\n        int l = -1, r = -1;\n\n        Arrays.sort(a, (o1, o2) -> {\n            if (o1[0] != o2[0]) {\n                return o1[0] - o2[0];\n            } else {\n                return o2[1] - o1[1];\n            }\n        });\n\n        int maxr = -1, maxi = -1;\n        for (int i = 0; i < n; i++) {\n            if (a[i][1] <= maxr) {\n                l = a[i][2] + 1;\n                r = maxi + 1;\n                break;\n            }\n            if (a[i][1] > maxr) {\n                maxi = a[i][2];\n                maxr = a[i][1];\n            }\n        }\n\n        System.out.println(l + \" \" + r);\n\n\n    }\n\n    boolean check(int cnt[][], int[] tcnt, int mid) {\n        boolean ok = true;\n\n        for (int j = 0; j < 27; j++) {\n            if (cnt[mid][j] < tcnt[j]) {\n                ok = false;\n            }\n        }\n        return ok;\n    }\n\n    class Pair {\n        int c, f;\n    }\n\n    class FastScanner {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 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\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Integer[] nextA(int n) {\n            Integer a[] = new Integer[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = scanner.nextInt();\n            }\n            return a;\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            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "nlogn", "problem": "976_C. Nested Segments", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\n/* spar5h */\n\npublic class cf1 implements Runnable{    \n\t\n\tpublic void run() {\n\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\t\n\t\tint t = 1;\n\t\t\n\t\twhile(t-- > 0) {\n\t\t\t\n\t\t\tint n = s.nextInt(), m = s.nextInt();\n\t\t\t\n\t\t\tint[] a = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\ta[i] = s.nextInt();\n\t\t\t\n\t\t\tint[] b = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\tb[i] = s.nextInt();\n\t\t\t\n\t\t\tArrayList<Integer> list = new ArrayList<Integer>();\n\t\t\t\n\t\t\tlist.add(a[1]);\n\t\t\t\n\t\t\tfor(int i = 2; i <= n; i++) {\n\t\t\t\tlist.add(b[i]); list.add(a[i]);\n\t\t\t}\n\t\t\t\n\t\t\tlist.add(b[1]);\n\t\t\t\n\t\t\tdouble wt = m;\n\t\t\tboolean check = true;\n\t\t\t\n\t\t\tfor(int i = list.size() - 1; i >= 0; i--) {\n\t\t\t\t\n\t\t\t\tif(list.get(i) <= 1) {\n\t\t\t\t\tcheck = false; break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tdouble x = wt / (list.get(i) - 1);\n\t\t\t\t\t\t\n\t\t\t\twt += x;\n\t\t\t}\n\t\t\t\n\t\t\tif(check)\n\t\t\t\tw.println(wt - m);\n\t\t\telse\n\t\t\t\tw.println(-1);\n\t\t}\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\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new cf1(),\"cf1\",1<<26).start();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author Haya\n */\npublic class CommentaryBoxes {\n\n    public static void main(String[] args) {\n        \n        FastReader in = new FastReader();\n        \n        long n = in.nextLong();\n        long m = in.nextLong();\n        long a = in.nextLong();\n        long b = in.nextLong();\n        long total = 0;\n        \n        long val =(n%m);\n        if (n%m != 0){\n            \n            long x = (val)*b;\n            long y = (m-val)*a;\n            \n            total = Math.min(x, y);\n        }\n        System.out.println(Math.abs(total));\n        \n    }\n\n    public static class FastReader {\n\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() {\n            String string = \"\";\n            try {\n                string = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return string;\n        }\n\n    }\n\n}\n", "complexity": "linear", "problem": "990_A. Commentary Boxes", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class HelloWorld{\n\n     public static void main(String []args){\n        final long MOD = 1000000007;\n        Scanner scan = new Scanner(System.in);\n        int now = 1;\n        int maxStatements = scan.nextInt();\n        long[] dp = new long[maxStatements + 1];\n        dp[now] = 1;\n        while(maxStatements > 0)\n        {\n            String add = scan.next();\n            if (add.equals(\"f\"))\n            {\n                now++;\n            }\n            else\n            {\n                for (int k = 1; k <= now; k++)\n                {\n                    dp[k] = ((dp[k] + dp[k-1]) % MOD);\n                }\n            }\n            maxStatements--;\n        }\n        System.out.println(dp[now]);\n     }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ehab4 {\n    public static void main( String[] args ) {\n        Scanner in = new Scanner( System.in );\n\tint a = 0, b = 0;\n\tSystem.out.println( \"? 0 0 \" );\n\tSystem.out.flush();\n\tint c = in.nextInt();\n\tfor ( int i = 29; i >= 0; i-- ) {\n\t    System.out.println( \"? \" + ( a + ( 1 << i ) ) + \" \" + b );\n\t    System.out.flush();\n\t    int q1 = in.nextInt();\n\t    System.out.println( \"? \" + a + \" \" + ( b + ( 1 << i ) ) );\n\t    System.out.flush();\n\t    int q2 = in.nextInt();\n\t    if ( q1 == q2 ) {\n\t\tif ( c == 1 )\n\t\t    a += ( 1 << i );\n\t\telse if ( c == -1 )\n\t\t    b += ( 1 << i );\n\t\tc = q1;\n\t    }\n\t    else if ( q1 == -1 ) {\n\t\ta += ( 1 << i );\n\t\tb += ( 1 << i );\n\t    }\n\t    else if ( q1 == -2 )\n\t\treturn;\n\t}\n\tSystem.out.println( \"! \" + a + \" \" + b );\n\tSystem.out.flush();\n    }\n}\n", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tstatic void insert(TreeMap<Integer, Integer>map,int v,int d)\n\t{\n\t\tif(!map.containsKey(v))map.put(v, 0);\n\t\tmap.put(v, d+map.get(v));\n\t\tif(map.get(v)==0)map.remove(v);\n\t}\n\t\n\tstatic void cut(TreeSet<Integer> cuts, TreeMap<Integer, Integer>segments,int v)\n\t{\n\t\tint upper = cuts.higher(v) , lower = cuts.lower(v);\n\t\tinsert(segments, upper-lower, -1);\n\t\tinsert(segments, upper-v, 1);\n\t\tinsert(segments, v-lower, 1);\n\t\tcuts.add(v);\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint w = sc.nextInt(), h = sc.nextInt() , n = sc.nextInt();\n\t\tTreeSet<Integer> vCuts = new TreeSet<>() , hCuts = new TreeSet<>();\n\t\tTreeMap<Integer, Integer> vSegments = new TreeMap<>() , hSegments = new TreeMap<>();\n\t\tvCuts.add(0);vCuts.add(w);\n\t\thCuts.add(0);hCuts.add(h);\n\t\tinsert(vSegments, w, 1);\n\t\tinsert(hSegments, h, 1);\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(n-->0)\n\t\t{\n\t\t\tif(sc.next().equals(\"H\"))\n\t\t\t\tcut(hCuts, hSegments, sc.nextInt());\n\t\t\telse\n\t\t\t\tcut(vCuts, vSegments, sc.nextInt());\n\t\t\tsb.append(1l*hSegments.lastKey() * vSegments.lastKey() + \"\\n\");\n\t\t}\n\t\tSystem.out.println(sb);\n\t}\n\t\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic Scanner(InputStream s) {br = new BufferedReader(new InputStreamReader(s));}\n\t\tpublic Scanner(String file) throws FileNotFoundException {br = new BufferedReader(new FileReader(file));}\n\t\tpublic String next() throws IOException {while (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\tpublic 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\t\tpublic int[] nexIntArray() throws Throwable {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint[] a = new int[st.countTokens()];\n\t\t\tfor (int i = 0; i < a.length; i++)a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}", "complexity": "nlogn", "problem": "528_A. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n//import java.util.Scanner;\n\n\n\n\npublic class SingleWildcard {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner input =new Scanner(System.in);\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tchar[] s1 =new char[a];\n\t\ts1 = input.next().toCharArray();\n\t\t\n\t\tchar[] s2 = new char[b];\n\t\ts2 = input.next().toCharArray();\n\t    boolean condition = false;\n\t    for(int i=0; i<a;i++){\n\t    \tif(s1[i]=='*'){\n\t    \t\tcondition= true;\n\t    \t\tbreak;\n\t    \t}\n\t    }\n\t   \n\t    if(!condition){\n\t    \tif(match(s1,s2)){\n\t    \t\tSystem.out.println(\"YES\");\n\t    \t\t\n\t    \t}\n\t    \telse\n\t    \t\tSystem.out.println(\"NO\");\n\t       return;\n\t    }\n\t    else{\n\t    \tint i=0;\n\t    \tif(s1.length-1>s2.length){\n\t    \t\tSystem.out.println(\"NO\");\n\t    \t\treturn;\n\t    \t}\n\t    \twhile(i<s1.length && i<s2.length && s1[i]==s2[i]){\n\t    \t\ti++;\n\t    \t}\n\t    \tint j=s2.length-1;\n\t    \tint k = s1.length-1;\n\t    \twhile(j>=0 && k>=0 &&  s1[k]==s2[j] && i<=j){\n\t    \t\tj--;\n\t    \t\tk--;\n\t    \t}\n\t    \t//System.out.println(i);\n\t    \tif(i==k && i>=0 && i<s1.length && s1[i]=='*' ){\n\t    \t\tSystem.out.println(\"YES\");\n\t    \t\treturn;\n\t    \t}\n\t    \tSystem.out.println(\"NO\");\n\t    }\n\t\t\n\t\t\n\t}\n\t\n\tstatic boolean match(char[] s1,char[] s2){\n\t\tif(s1.length!=s2.length)return false;\n\t\tfor(int i=0; i<s1.length;i++){\n\t\t\tif(s1[i]!=s2[i])return false;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\n}\n", "complexity": "linear", "problem": "1023_A. Single Wildcard Pattern Matching", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringJoiner;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class Main {\n\n    static String S;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        S = sc.next();\n\n        System.out.println(solve());\n    }\n\n    static int solve() {\n        int ans = -1;\n        int time = 1;\n        int n = S.length();\n        for (int i = 1; i < n*2; i++) {\n            if( S.charAt((i-1)%n) != S.charAt(i%n) ) {\n                time++;\n            } else {\n                ans = Math.max(time, ans);\n                time = 1;\n            }\n        }\n        ans = Math.max(time, ans);\n\n        if( ans == n*2 ) {\n            return n;\n        } else {\n            return ans;\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++)\n                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++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n    }\n\n    static <A> void writeLines(A[] as, Function<A, String> f) {\n        PrintWriter pw = new PrintWriter(System.out);\n        for (A a : as) {\n            pw.println(f.apply(a));\n        }\n        pw.flush();\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 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 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", "complexity": "linear", "problem": "1025_C. Plasticine zebra", "from": "CODEFORCES"}
{"src": "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 a[]=new int[n];\n    for(int i=0;i<n;i++)\n    a[i]=sc.nextInt();\n    Arrays.sort(a);\n    //boolean \n    int t=1,c=0;\n    for(int i=1;i<n;i++){\n        if(a[i]==a[i-1])\n        {\n            if(i-2>=0&&a[i-2]==a[i-1]-1){\n                System.out.println(\"cslnb\");\n                return;\n            }\n            c++;\n        }\n        if(a[i]==a[i-1]&&a[i]==0){\n        System.out.println(\"cslnb\");\n        return;\n        }\n    }\n    if(c>1)\n    {\n        System.out.println(\"cslnb\");\n        return;\n    }\n    for(int i=0;i<n;i++){\n        if((a[i]-i)%2!=0)\n        t=t^1;\n    }\n    if(t==1)\n    System.out.println(\"cslnb\");\n    else\n    System.out.println(\"sjfnb\");\n    \n    \n    \n    }\n    \n}", "complexity": "linear", "problem": "1190_B. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class helloWorld \n{\n\tpublic static void main(String[] args) \n\t{\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint[] ar = new int[200];\n\t\t\n\t\tString str = in.next();\n\t\tfor(int i = 0; i < str.length(); i++)\n\t\t\tar[ str.charAt(i) ]++;\n\t\t\t\n\t\tint ans = 100000;\n\t\t\n\t\tfor(int i = 'A'; i < 'A' + m; i++)\n\t\t\tans = Math.min(ans, ar[i]);\n\t\tans *= m;\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\tin.close();\n\t}\n}\n\n", "complexity": "linear", "problem": "1038_A. Equality", "from": "CODEFORCES"}
{"src": " \n \n\n\nimport java.util.Scanner;\nimport javafx.geometry.Point2D;\n\n \npublic class ChessKing {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\nScanner input = new Scanner(System.in);\nlong size = input.nextLong();\nlong a = input.nextLong();\nlong b = input.nextLong();\n  long sum = a+b;\n   long d = sum-2;\n   long d1 = size*2 - sum;\nif(d<d1) System.out.println(\"White\");\nelse if(d>d1) System.out.println(\"Black\");\nelse System.out.println(\"White\");\n\n\n    }\n    \n}\n", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.lang.*;\nimport java.math.*;\n \npublic class Main{\n\t\n\tstatic ArrayList a[]=new ArrayList[200001];\n\tstatic int Count(int a[][],int n) {\n\t\tdsu d=new dsu(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(a[i][j]==0) {\n\t\t\t\t\td.union(i, j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint cnt=0;\n\t\tboolean chk[]=new boolean [n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint p=d.root(i);\n\t\t\tif(!chk[p]) {\n\t\t\t\tchk[p]=true;\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t    return cnt;\n\t}\n\tpublic void solve () {\n\t\tInputReader in = new InputReader(System.in);\n\t    PrintWriter pw = new PrintWriter(System.out); \n\t    int n=in.nextInt();\n\t    int a=in.nextInt();\n\t    int b=in.nextInt();\n\t    if(a==1 || b==1) {\n\t    \tint ans[][]=new int [n][n];\n\t    \tint temp=(a==1)?b:a;\n\t    \tfor(int i=1;i<=n-temp;i++) {\n\t    \t\tans[i][i-1]=1;\n\t    \t\tans[i-1][i]=1;\n\t    \t}\n\t    \tint freq=Count(ans,n);\n\t    \tif(freq!=1) {\n\t    \t\tpw.println(\"NO\");\n\t    \t}\n\t    \telse {\n\t    \t\tpw.println(\"YES\");\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(i==j) {\n\t    \t\t\t\t\tpw.print(0);\n\t    \t\t\t\t}\n\t    \t\t\t\telse\n\t    \t\t\t\t\tpw.print((ans[i][j]+((temp==b)?1:0))%2);\n\t    \t\t\t}\n\t    \t\t\tpw.println();\n\t    \t\t}\n\t    \t}\n\t    }\n\t    else {\n\t    \tpw.print(\"NO\");\n\t    }\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\tpublic static void main(String[] args) throws Exception {\n        \n        \n        new Thread(null,new Runnable() {\n        \tpublic void run() {\n        \t\tnew Main().solve();\n        \t}\n        },\"1\",1<<26).start();\n        \n        \n    }\n    static void debug(Object... o) {\n    \tSystem.out.println(Arrays.deepToString(o));\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        {\n            this.stream = stream;\n        }\n        public int snext() \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                } \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 = 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            {\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            {\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 String readString()\n        {\n            int c = snext();\n            while (isSpaceChar(c)) \n            {\n                c = snext();\n            }\n            StringBuilder res = new StringBuilder();\n            do \n            {\n                res.appendCodePoint(c);\n                c = snext();\n            } while (!isSpaceChar(c));\n            return res.toString();\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            {\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        public static long mod = 1000000007;\n        public static int d;\n        public static int p;\n        public static int q;\n        public void extended(int a,int b) {\n        \tif(b==0) {\n        \t\td=a;\n        \t\tp=1;\n        \t\tq=0;\n        \t}\n        \telse\n        \t{\n        \t\textended(b,a%b);\n        \t\tint temp=p;\n        \t\tp=q;\n        \t\tq=temp-(a/b)*q;\n        \t}\n        }\n        public static long[] shuffle(long[] a,Random gen)\n        {\n            int n = a.length;\n            for(int i=0;i<n;i++)\n            {\n                int ind = gen.nextInt(n-i)+i;\n                long temp = a[ind];\n                a[ind] = a[i];\n                a[i] = temp;\n            }\n            return a;\n        }\n        \n        public static void swap(int a, int b){\n            int temp = a;\n            a = b;\n            b = temp;\n        }\n        \n        public static HashSet<Integer> primeFactorization(int n)\n        {\n            HashSet<Integer> a =new HashSet<Integer>();\n            for(int i=2;i*i<=n;i++)\n            {\n                while(n%i==0)\n                {\n                    a.add(i);\n                    n/=i;\n                }\n            }\n            if(n!=1)\n                a.add(n);\n            return a;\n        }\n        \n        public static void sieve(boolean[] isPrime,int n)\n        {\n            for(int i=1;i<n;i++)\n                isPrime[i] = true;\n            \n            isPrime[0] = false;\n            isPrime[1] = false;\n            \n            for(int i=2;i*i<n;i++)\n            {\n                if(isPrime[i] == true)\n                {\n                    for(int j=(2*i);j<n;j+=i)\n                        isPrime[j] = false;\n                }\n            }\n        }\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        static class pair implements Comparable<pair>\n        {\n            Integer x;\n            Long y;\n            pair(int x,long y)\n            {\n                this.x=x;\n                this.y=y;\n                \n            }\n            \n           \n            public int compareTo(pair o) {\n                int result = x.compareTo(o.x);\n                if(result==0)\n                    result = y.compareTo(o.y);\n                \n                return result;\n            }  \n            \n            public String toString()\n            {\n                return x+\" \"+y;\n            }\n            \n            public boolean equals(Object o)\n            {\n                if (o instanceof pair)\n                {\n                    pair p = (pair)o;\n                    return p.x == x && p.y == y ;\n                }\n                return false;\n            }\n            \n            public int hashCode()\n            {\n                return new Long(x).hashCode()*31 + new Long(y).hashCode();\n            }\n        }\n        \n    \n}\nclass pair implements Comparable<pair>\n{\n    Integer x;\n    Long y;\n    pair(int x,long y)\n    {\n        this.x=x;\n        this.y=y;\n        \n    }\n    \n   \n    public int compareTo(pair o) {\n        int result = x.compareTo(o.x);\n        if(result==0)\n            result = y.compareTo(o.y);\n        \n        return result;\n    }  \n    \n    public String toString()\n    {\n        return x+\" \"+y;\n    }\n    \n    public boolean equals(Object o)\n    {\n        if (o instanceof pair)\n        {\n            pair p = (pair)o;\n            return p.x == x && p.y == y ;\n        }\n        return false;\n    }\n    \n    public int hashCode()\n    {\n        return new Long(x).hashCode()*31 + new Long(y).hashCode();\n    }\n}\nclass dsu{\n\tint parent[];\n\tdsu(int n){\n\t\tparent=new int[n+1];\n\t\tfor(int i=0;i<=n;i++)\n\t\t{\n\t\t\tparent[i]=i;\n\t\t}\n\t}\n\tint root(int n) {\n\t\twhile(parent[n]!=n)\n\t\t{ \n\t\t\tparent[n]=parent[parent[n]];\n\t\t\tn=parent[n];\n\t\t}\n\t\treturn n;\n\t}\n\tvoid union(int _a,int _b) {\n\t\tint p_a=root(_a);\n\t\tint p_b=root(_b);\n\t\t\n\t\t\tparent[p_a]=p_b;\n\t\t\n\t\t\t\n\t}\n\tboolean find(int a,int b) {\n\t\tif(root(a)==root(b))\n\t\t\treturn true;\n\t\telse\n\t\t\treturn  false;\n\t}\n\t\n\t\n}\n", "complexity": "quadratic", "problem": "990_D. Graph And Its Complement", "from": "CODEFORCES"}
{"src": "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            long x=Long.parseLong(s1[1]);\n            long y=Long.parseLong(s1[2]);\n            long S=0;\n            long mod=1000000007;\n            B a[]=new B[n];\n            TreeMap<Long,Long> tm=new TreeMap<Long,Long>();\n            long ans[]=new long[n];\n            for(int i=0;i<n;i++)\n            {\n              String s2[]=br.readLine().split(\" \");\n              long l=Long.parseLong(s2[0]);\n              long r=Long.parseLong(s2[1]);\n              B b1=new B(l,r);\n              a[i]=b1;\n            }\n            Arrays.sort(a,new The_Comp());\n            \n            for(int i=0;i<n;i++)\n            {\n                  long l=a[i].x;\n                  long r=a[i].y;\n                  if(tm.floorKey(l-1)!=null)\n                  {\n                        long u=tm.floorKey(l-1);\n                        long v=l;\n                        if((v-u)*y<x)\n                        { ans[i]=((r-u)*y)%mod; \n                          if(tm.get(u)>1)\n                           tm.put(u,tm.get(u)-1);\n                          else\n                          tm.remove(u); \n                        }\n                        else\n                        { ans[i]=(x+(r-l)*y)%mod; }\n                  }\n                  else\n                   ans[i]=(x+(r-l)*y)%mod;\n                  S=(S+ans[i])%mod;\n                  if(tm.containsKey(r))\n                   tm.put(r,1+tm.get(r));\n                  else\n                   tm.put(r,(long)1);\n            }\n            System.out.println(S);\n      }\n}\n\n\nclass The_Comp implements Comparator<B>\n{\n      public int compare(B b1,B b2)\n      {\n            if(b1.x>b2.x)\n             return 1;\n            else if(b1.x==b2.x)\n            {\n            if(b1.y>b2.y)\n             return 1;\n            else if(b1.y==b2.y)\n             return 0;\n            else\n             return -1;\n            }\n            else\n             return -1;\n      }\n}\nclass B\n{\n      long x=(long)1;\n      long y=(long)1;\n      public B(long l1,long l2)\n      { x=l1;  y=l2; }\n}", "complexity": "nlogn", "problem": "1061_D. TV Shows", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class e {\n\npublic static class FastReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t//than using direct \n\n\tpublic FastReader() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString 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 (Exception r) {\n\t\t\t\tr.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());//converts string to integer\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() {\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\t\t} catch (Exception r) {\n\t\t\tr.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n}\nstatic ArrayList<String>list1=new ArrayList<String>();\nstatic void combine(String instr, StringBuffer outstr, int index,int k)\n{\n\tif(outstr.length()==k)\n\t{\n\t\tlist1.add(outstr.toString());return;\n\t}\n\tif(outstr.toString().length()==0)\n\toutstr.append(instr.charAt(index));\n    for (int i = 0; i < instr.length(); i++)\n    {\n        outstr.append(instr.charAt(i));\n       \n        combine(instr, outstr, i + 1,k);\n        outstr.deleteCharAt(outstr.length() - 1);\n    }\n   index++;\n} \nstatic ArrayList<ArrayList<Integer>>l=new ArrayList<>();\nstatic void comb(int n,int k,int ind,ArrayList<Integer>list)\n{\n\tif(k==0)\n\t{\n\t\tl.add(new ArrayList<>(list));\n\n\t\treturn;\n\t}\n\t\n\t\n\tfor(int i=ind;i<=n;i++)\n\t{\n\t\tlist.add(i);\n\t\tcomb(n,k-1,ind+1,list);\n\t\t\n\t\tlist.remove(list.size()-1);\n\t\t\n\t}\n\t\n\t\n\t\n\t\n\t\n\n}\n\n\npublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\tFastReader in=new FastReader();\n\tHashMap<Integer,Integer>map=new HashMap<Integer,Integer>();\n\n\tint n=in.nextInt();\n\tint r=in.nextInt();\n\t \n\tdouble theta=(double)360/(double)n;\n\t \n\tdouble b=1-((double)2/(double)(1-Math.cos((double)2*Math.PI/(double)n)));\n\tdouble x=Math.sqrt(1-b)-1;\n\tdouble ans=(double)r/(double)x;\n\tSystem.out.println(ans);\n\n\n\n\n\n\t}\n}\n", "complexity": "constant", "problem": "1100_C. NN and the Optical Illusion", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class D5 {\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int a = input.nextInt(), v = input.nextInt();\n    int l = input.nextInt(), d = input.nextInt(), w = input.nextInt();\n    double lo = 0, hi = v;\n    for(int iter = 0; iter < 1000; iter++)\n    {\n        double mid = (lo+hi)/2;\n        if(can(mid, a, d, w)) lo = mid;\n        else hi = mid;\n    }\n    //System.out.println(lo);\n    double t1 = lo / a;\n    double gone = .5 * t1 * t1 * a;\n    if(lo > w)\n    {\n        gone += -a * .5 * (lo - w) / a * (lo - w) / a + lo * (lo - w) / a;\n        t1 += (lo - w) / a;\n    }\n    t1 += (d - gone) / lo;\n    //System.out.println(t1);\n    double v0 = Math.min(lo, w);\n    double togo = l - d;\n    double toAdd = (-v0 + Math.sqrt(v0 * v0 + 4 * togo * .5 * a)) / a;\n    if(toAdd * a + v0 > v)\n    {\n        double tt = (v - v0) / a;\n        t1 += tt;\n        togo -= .5 * a * tt * tt + v0 * tt;\n        t1 += togo / v;\n    }\n    else t1 += toAdd;\n    System.out.println(t1);\n}\nstatic boolean can(double v, double a, double d, double max)\n{\n    double t1 = v / a;\n    double distGone = .5 * a * t1 * t1;\n    if(v > max)\n    {\n        t1 = (v - max) / a;\n        distGone += -.5 * a * t1 * t1 + v * t1;\n    }\n    return distGone <= d;\n}\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\npublic class D909 {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        char[] line = br.readLine().toCharArray();\n        int n = line.length;\n\n        int l = 0;\n        ArrayList<Node> groups = new ArrayList<>();\n        Node node = new Node(line[0], 1);\n        groups.add(node);\n        for (int i = 1; i < n; i++) {\n            if (line[i] == groups.get(l).letter) {\n                groups.get(l).count++;\n            } else {\n                node = new Node(line[i], 1);\n                groups.add(node);\n                l++;\n            }\n        }\n\n        int moves = 0;\n        ArrayList<Node> temp = new ArrayList<>();\n        while (groups.size() > 1) {\n            moves++;\n\n            l = groups.size();\n            groups.get(0).count--;\n            groups.get(l - 1).count--;\n            for (int i = 1; i < l - 1; i++) {\n                groups.get(i).count -= 2;\n            }\n\n            int p;\n            for (p = 0; p < l; p++) {\n                if (groups.get(p).count > 0) {\n                    temp.add(groups.get(p));\n                    break;\n                }\n            }\n            int lTemp = temp.size();\n            for (p++; p < l; p++) {\n                if (groups.get(p).count <= 0) {\n                    continue;\n                }\n                if (groups.get(p).letter == temp.get(lTemp - 1).letter) {\n                    temp.get(lTemp - 1).count += groups.get(p).count;\n                } else {\n                    temp.add(groups.get(p));\n                    lTemp++;\n                }\n            }\n\n            groups.clear();\n            groups.addAll(temp);\n            temp.clear();\n        }\n\n        System.out.println(moves);\n    }\n\n    private static class Node {\n        char letter;\n        int count;\n\n        Node(char letter, int count) {\n            this.letter = letter;\n            this.count = count;\n        }\n    }\n}\n", "complexity": "linear", "problem": "909_D. Colorful Points", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class X\n{\n\tpublic static void main(String args[])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 s1 = br.readLine();\n\t\tString s2 = br.readLine();\n\t\tint i=0;\n\t\tchar c1,c2;\n\t\tint cost = 0;\n\t\twhile(i<n)\n\t\t{\n\t\t\tc1 = s1.charAt(i);\n\t\t\tc2 = s2.charAt(i);\n\t\t\tif(c1 != c2)\n\t\t\t{\n\t\t\t\tif((i+1)<n && s1.charAt(i+1) != s2.charAt(i+1) && s1.charAt(i) != s1.charAt(i+1))\n\t\t\t\t{\n\t\t\t\t\tcost +=1;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcost +=1;\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tSystem.out.println(cost);\n\t}\n}", "complexity": "linear", "problem": "1037_C. Equalize", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ChainReaction {\n\t\n\tpublic static void main(String [] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\tint num = kb.nextInt();\n\t\t\n\t\tint[] beacons = new int[1000002];\n\t\tfor (int i=0; i<num; i++) {\n\t\t\tbeacons[kb.nextInt()] = kb.nextInt();\n\t\t}\n\t\t\n\t\tint [] dp = new int[1000002];\n\t\tint max = 0;\n\t\tif (beacons[0] != 0)\n\t\t\tdp[0] = 1;\n\t\t\n\t\tfor (int i=1; i<dp.length; i++) {\n\t\t\tif (beacons[i] == 0) {\n\t\t\t\tdp[i] = dp[i-1];\n\t\t\t} else {\n\t\t\t\tint index = i-1-beacons[i];\n\t\t\t\tif (index<0)\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\telse\n\t\t\t\t\tdp[i] = 1 + dp[index];\n\t\t\t}\n\t\t\tmax = Math.max(max, dp[i]);\n\t\t\t//if (i<11)\n\t\t\t\t//System.out.println(i +\" is \"+dp[i]);\n\t\t}\n\t\t\n\t\tSystem.out.println(num-max);\n\t}\n\n}\n", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class A{\n       \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 = 1; i <= n; i++){\n                     ans += ((i*2) <= n) ? i : n-i+1;\n              }\n              System.out.println(ans);\n       }\n}", "complexity": "linear", "problem": "909_B. Segments", "from": "CODEFORCES"}
{"src": "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.Iterator;\nimport java.util.Objects;\nimport java.util.Stack;\n\n\nimport java.util.StringTokenizer;\n\n\n public class Test\n {\n    \n     static PrintWriter pw = new PrintWriter(System.out);\n\n    public static void main(String[] args)throws Exception\n    {\n        Reader.init(System.in);\n        int n = Reader.nextInt();\n        int p = Reader.nextInt();\n        int L = Reader.nextInt();\n        int R = Reader.nextInt();\n        int a = 1;\n        int b = n;\n        int res = 0;\n        \n        if(a == L && b == R)\n        {\n            res = 0;\n        }\n        else if(L != a && R != b && p >= L && p <= R)\n        {\n            res = Math.min(p-L, R-p);\n            res += R- L + 2;\n        }\n        else if(L != a && R != b && p < L )\n        {\n            res += L-p + 1;\n            res += R - L +1;\n        }\n        else if(L != a && R != b && p > R)\n        {\n            res += p-R + 1;\n            res += R - L +1;\n        }\n        else if(a == L && p >=L && p<=R)\n        {\n            res += R - p + 1;\n        }\n        else if(R == b && p>=L && p<=R)\n        {\n            res += p - L + 1;\n        }\n        else if(a == L && p > R)\n        {\n            res += p - R + 1;\n        }\n        else if(R == b && p<L)\n        {\n            res += L - p + 1;\n        }\n            \n            \n        pw.print(res);\n        pw.close();\n \n    }\n        \n}\n\nclass Reader {\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    public static int pars(String x) {\n        int num = 0;\n        int i = 0;\n        if (x.charAt(0) == '-') {\n            i = 1;\n        }\n        for (; i < x.length(); i++) {\n            num = num * 10 + (x.charAt(i) - '0');\n        }\n\n        if (x.charAt(0) == '-') {\n            return -num;\n        }\n\n        return num;\n    }\n\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                new InputStreamReader(input));\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    static void init(FileReader input) {\n        reader = new BufferedReader(input);\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    static String next() throws IOException {\n        while (!tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(\n                    reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return pars(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}", "complexity": "constant", "problem": "915_B. Browser", "from": "CODEFORCES"}
{"src": "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.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        static final long BIG = Long.MAX_VALUE - Long.MAX_VALUE % MODULO;\n        static final int[] ONE = new int[]{1};\n        int k;\n        int n;\n        long[] globalRes;\n        int[] p2;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            k = in.nextInt();\n            globalRes = new long[k + 1];\n            p2 = new int[n + 1];\n            p2[0] = 1;\n            for (int i = 1; i <= n; ++i) p2[i] = (int) (2 * p2[i - 1] % MODULO);\n            Vertex[] vs = new Vertex[n];\n            for (int i = 0; i < n; ++i) vs[i] = new Vertex();\n            for (int i = 0; i < n - 1; ++i) {\n                Vertex a = vs[in.nextInt() - 1];\n                Vertex b = vs[in.nextInt() - 1];\n                a.adj.add(b);\n                b.adj.add(a);\n            }\n            vs[0].dfs(null);\n            long[][] ways = new long[k + 1][k + 1];\n            ways[0][0] = 1;\n            for (int i = 1; i <= k; ++i) {\n                for (int j = 1; j <= k; ++j) {\n                    ways[i][j] = j * (ways[i - 1][j] + ways[i - 1][j - 1]) % MODULO;\n                }\n            }\n            long sum = 0;\n            for (int i = 1; i <= k; ++i) {\n                long s = globalRes[i];\n                s %= MODULO;\n                sum = (sum + s * ways[k][i]) % MODULO;\n            }\n            out.println(sum);\n        }\n\n        class Vertex {\n            int[] res;\n            int subtreeSize;\n            List<Vertex> adj = new ArrayList<>();\n\n            public void dfs(Vertex parent) {\n                subtreeSize = 1;\n                int[] prod = ONE;\n                for (Vertex child : adj)\n                    if (child != parent) {\n                        child.dfs(this);\n                        subtreeSize += child.subtreeSize;\n                    }\n                int mult = 2;//p2[n - subtreeSize];\n                for (Vertex child : adj)\n                    if (child != parent) {\n                        int[] c = child.res;\n                        prod = mul(prod, c);\n                        subFrom(globalRes, c, 1);\n                    }\n                addTo(globalRes, prod, mult);\n                res = insertEdge(prod);\n            }\n\n            private int[] insertEdge(int[] a) {\n                int len = a.length + 1;\n                if (len > k) len = k + 1;\n                int[] b = new int[len];\n                b[0] = a[0] * 2;\n                if (b[0] >= MODULO) b[0] -= MODULO;\n                for (int i = 1; i < len; ++i) {\n                    long s = a[i - 1];\n                    if (i < a.length) s += a[i];\n                    if (s >= MODULO) s -= MODULO;\n                    s = s * 2;\n                    if (s >= MODULO) s -= MODULO;\n                    b[i] = (int) s;\n                }\n                b[1] -= 1;\n                if (b[1] < 0) b[1] += MODULO;\n                return b;\n            }\n\n            private void addTo(long[] a, int[] b, int mult) {\n                for (int i = 0; i < b.length; ++i) {\n                    long s = a[i] + b[i] * (long) mult;\n                    if (s < 0) s -= BIG;\n                    a[i] = s;\n                }\n            }\n\n            private void subFrom(long[] a, int[] b, int mult) {\n                for (int i = 0; i < b.length; ++i) {\n                    long s = a[i] + (MODULO - b[i]) * (long) mult;\n                    if (s < 0) s -= BIG;\n                    a[i] = s;\n                }\n            }\n\n            private int[] mul(int[] a, int[] b) {\n                int len = a.length + b.length - 1;\n                if (len > k) len = k + 1;\n                int[] c = new int[len];\n                for (int i = 0; i < len; ++i) {\n                    long s = 0;\n                    int left = Math.max(0, i - (b.length - 1));\n                    int right = Math.min(a.length - 1, i);\n                    for (int ia = left; ia <= right; ++ia) {\n                        int ib = i - ia;\n                        s += a[ia] * (long) b[ib];\n                        if (s < 0) s -= BIG;\n                    }\n                    c[i] = (int) (s % MODULO);\n                }\n                return c;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1097_G. Vladislav and a Great Legend", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        FastReader in;\n        PrintWriter out;\n        int n;\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.nextInt();\n            if (n % 4 != 0) {\n                out.println(\"! -1\");\n                return;\n            }\n            int low = 0;\n            int high = n >> 1;\n            if (BValue(low) == 0) {\n                out.println(\"! \" + (low + 1));\n                return;\n            }\n            boolean value = BValue(low) > 0;\n            while (high - low > 1) {\n                int mid = (high + low) >> 1;\n                int BVal = BValue(mid);\n                if (BVal == 0) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if (value) {\n                    if (BVal < 0) {\n                        high = mid;\n                    } else {\n                        low = mid;\n                    }\n                } else {\n                    if (BVal > 0) {\n                        high = mid;\n                    } else {\n                        low = mid;\n                    }\n                }\n            }\n            out.println(\"! -1\");\n        }\n\n        public int BValue(int index) {\n            out.println(\"? \" + (index + 1));\n            out.flush();\n            int f = in.nextInt();\n            out.println(\"? \" + (index + 1 + (n >> 1)));\n            out.flush();\n            int s = in.nextInt();\n            return f - s;\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class Main {\n\tstatic Scanner sc = new Scanner (System.in);\n    public static void main(String[] args) {\n    \tint n = sc.nextInt();\n    \tint k = sc.nextInt();\n    \tchar str[][] = new char[5][n];\n        for(int i = 0;i < 4;i ++){\n        \tfor(int j = 0;j < n;j ++)\n                str[i][j] = '.';\n        }\n        if(k % 2 == 0){\n            k /= 2;\n            for(int i = 1;i <= 2;i++){\n                for(int j = 1;j <= k;j++)\n                     str[i][j] = '#'; \n            }\n        }\n        else{\n            str[1][n / 2] = '#';\n            if(k != 1){\n                int tmp = n / 2;\n                if(k <= n - 2){\n                    for(int i = 1;i<= (k - 1) / 2;i++){\n                        str[1][i] = '#';\n                        str[1][n - 1 - i] = '#';\n                    }\n                }\n                else{\n                    for(int i = 1;i <= n - 2;i++) str[1][i] = '#';\n                    k -= n - 2;\n                    for(int i = 1;i <= k/2;i++){\n                        str[2][i] = '#';\n                        str[2][n - 1 - i]='#';\n                    }\n                }\n     \n            }\n        }\n        System.out.println(\"YES\");\n        for(int i = 0;i < 4;i ++){\n        \tSystem.out.println(str[i]);\n        }\n    }\n }", "complexity": "linear", "problem": "980_B. Marlin", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class HammingDistancesSum {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString  a = sc.nextLine(), b = sc.nextLine();\n\t\tlong sum = 0;\n\t\tint frequency[][] = new int[200010][2];\n\t\tfor (int i = 1; i <= b.length(); i++) {\n\t        for (int j = 0; j < 2; j++)\n\t            frequency[i][j] = frequency[i - 1][j];\n\t        frequency[i][Character.getNumericValue((b.charAt(i - 1)))]++;\n\t    }\n\t   \n\t    for (int i = 0; i < a.length(); i++) {\n\t        int c = Character.getNumericValue(a.charAt(i));\n\t        for (int j = 0; j < 2; j++) {\n\t        \tint flippingTerm = Math.abs(c - j);\n\t        \tint endOfWindowValue = frequency[b.length() - a.length() + i + 1][j];\n\t        \tint startOfWindowOffset = frequency[i][j];\n\t            sum += flippingTerm * (endOfWindowValue - startOfWindowOffset);\n\t        }\n\t    }\n\t\tSystem.out.println(sum);\n\t\tsc.close();\n\t}\n}\n", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tSolution solution = new Solution();\n\t\tSystem.out.println(solution.solve());\n\t}\n\n\tprivate int solve() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\n\t\tint[] a = new int[m];\n\t\tfor (int i = 0; i < m; ++i) a[i] = in.nextInt();\n\n\t\tif (n > m) return 0;\n\n\t\tMap<Integer, Integer> map = new HashMap<>();\n\t\tfor (int k: a) map.put(k, map.getOrDefault(k, 0) + 1);\n\n\t\tList<Integer> keySet = new ArrayList<>(map.keySet());\n\t\tint end = m / n;\n\n\t\tkeySet.sort((u, v) -> -Integer.compare(u, v));\n\t\tdo {\n\t\t\tint count = 0;\n\t\t\tfor (int k: keySet) {\n\t\t\t\tcount += map.get(k) / end;\n\t\t\t\tif (count >= n) return end;\n\t\t\t}\n\t\t} while (--end > 0);\n\n\t\treturn 0;\n\t}\n}\n", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        FastReader in;\n        PrintWriter out;\n        int n;\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.nextInt();\n            if (n % 4 != 0) {\n                out.println(\"! -1\");\n                return;\n            }\n            int low = 0;\n            int high = n >> 1;\n            if (BValue(low) == 0) {\n                out.println(\"! \" + (low + 1));\n                return;\n            }\n            int fSign = Integer.signum(BValue(low));\n            while (high - low > 1) {\n                int mid = (high + low) >> 1;\n                int mSign = Integer.signum(BValue(mid));\n                if (mSign == 0) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if (mSign == -fSign) {\n                    high = mid;\n                } else {\n                    low = mid;\n                }\n            }\n            out.println(\"! -1\");\n        }\n\n        public int BValue(int index) {\n            out.println(\"? \" + (index + 1));\n            out.flush();\n            int f = in.nextInt();\n            out.println(\"? \" + (index + 1 + (n >> 1)));\n            out.flush();\n            int s = in.nextInt();\n            return f - s;\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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.HashSet;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tstatic ArrayList<Integer> [] adj;\n\tstatic int [] num;\n\tstatic int dfs(int u, int p){\n\t\tint cnt = 0;\n\t\tfor(int v:adj[u]){\n\t\t\tif(v != p)\n\t\t\t\tcnt += dfs(v, u);\n\t\t}\n\t\tif(adj[u].size() == 1 && u != 0 || u == 0 && adj[0].size() == 0)\n\t\t\tcnt++;\n\t\tnum[cnt]++;\n\t\treturn cnt;\n\t}\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tadj = new ArrayList[n];\n\t\tfor (int i = 0; i < adj.length; ++i) {\n\t\t\tadj[i] = new ArrayList<>();\n\t\t}\n\t\tfor (int i = 1; i < n; ++i) {\n\t\t\tint p = sc.nextInt()-1;\n\t\t\tadj[p].add(i);\n\t\t\tadj[i].add(p);\n\t\t}\n\t\tnum = new int[n+1];\n\t\tdfs(0, -1);\n\t\tfor (int i = 1; i < num.length; ++i) {\n\t\t\tnum[i] += num[i-1];\n\t\t}\n\t\tint cur = 1;\n\t\tfor (int i = 0; i < num.length; ++i) {\n\t\t\twhile(cur <= num[i]){\n\t\t\t\tout.print(i + \" \");\n\t\t\t\t++cur;\n\t\t\t}\t\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\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\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "1056_D. Decorate Apple Tree", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CoveredPointsCount {\n\t\n\t//UPSOLVE\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        \n\t\tint n = Integer.parseInt(st.nextToken());\n\t     \n\t\tlong[] myArray = new long[2 * n];\n\t        \n\t\t\tfor (int i = 0; i < n; i++)  {\n\t        \tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t        \tmyArray[2 * i] = Long.parseLong(st1.nextToken()) * 2;\n\t        \tmyArray[2 * i + 1] = Long.parseLong(st1.nextToken()) * 2 + 1;\n\t        }  \n\t        \n\t        Arrays.sort(myArray);\n\t        long[] ans = new long[n + 1];\n\t        int cnt = 0;\n\t       \n\t        for (int i = 0; i < 2 * n - 1; i++)   {\n\t            if (myArray[i] % 2 == 0) cnt++; else cnt--;\n\t            ans[cnt] += (myArray[i + 1] + 1) / 2 - (myArray[i] + 1) / 2;\n\t        }   \n\t        \n\t        StringBuilder answer = new StringBuilder();\n\t        \n\t        for (int i = 1; i < n + 1; i++) {\n\t        \tanswer.append(ans[i]);\n\t        \tanswer.append(\" \");\n\t        }  \n\t        \n\t        System.out.println(answer);\n\n\t}\n\n}\n", "complexity": "nlogn", "problem": "1000_C. Covered Points Count", "from": "CODEFORCES"}
{"src": "\nimport 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[] P = new int[n];\n        int[] check=new int[n];\n        for (int i = 1; i < n; i++) {\n\n            P[i] = scanner.nextInt();\n            P[i]--;\n            check[P[i]]++;\n        }\n        int[] leaves = new int[n];\n\n\n        for (int i=0;i<n;i++) {\n            if(check[i]==0){\n                leaves[P[i]]++;\n            }\n        }\n\n\n        for (int i = 0; i < n; i++) {\n\n            if (check[i]>0&&leaves[i]<3) {\n                System.out.println(\"No\");\n                return;\n            }\n        }\n        System.out.println(\"Yes\");\n    }\n}\n", "complexity": "linear", "problem": "913_B. Christmas Spruce", "from": "CODEFORCES"}
{"src": "import java .util.*;\nimport java .io.*;\npublic class Main{\n\tpublic static void main(String[]YAHIA_MOSTAFA){\n\t\tScanner sc =new Scanner(System.in);\n\t\tlong n=sc.nextLong(),x=sc.nextLong(),y=sc.nextLong();\n\t\tlong xb,xw,yb,yw;\n\t\txw=x-1;yw=y-1;xb=n-x;yb=n-y;\n\t\tif (x==n&&y==n){\n\t\t\tSystem.out.println(\"Black\");return;\n\t\t}\n\t\tlong c1=0,c2=0;\n\t\tlong f =Math.max(xb,yb);\n\t\tlong h =Math.max(xw,yw);\n\t\t//System.out.println(h+\" \"+f+\" \"+(h-f));\n\t\tif (h<=f)\n\t\t\tSystem.out.println(\"White\");\n\t\telse\n\t\t\tSystem.out.println(\"Black\");\n\t}\n}", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic final int MAXN= 1005;\n\tstatic final long MOD =1_000_000_007;\n\tstatic final boolean DEBUG= false;\n\tstatic int  n, m;\n\tstatic long stlr[][]= new long[MAXN][MAXN],bell[]= new long[MAXN],occ[];\n\tstatic PrintStream cerr=System.err;\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tReadin();\n\t\tstlr[0][0]= bell[0] =1;\n\t\tfor (int i=1; i<=m; i++)\n\t\t\tfor (int j=1;j<=i;j++) {\n\t\t\t\tstlr[i][j]= (stlr[i-1][j-1]+stlr[i-1][j]*(long)j)%MOD;\n\t\t\t\tbell[i]= (bell[i]+stlr[i][j])%MOD;\n\t\t\t}\n\t\tif (DEBUG)\n\t\t\tfor (int i=1; i<=m; i++) cerr.println(\"Bell[\"+i+\"] =\"+bell[i]);\n\t\tArrays.sort(occ);\n\t\tif (DEBUG) {\n\t\t\tcerr.println(\"After Sorting\");\n\t\t\tfor (int i=0;i<m; i++) cerr.println(occ[i]+\" \");}\n\t\tlong ans=1;\n\t\tfor (int i=0,j=0; i<m; i=j) {\n\t\t\tfor (j=i+1; j<m && occ[i]==occ[j];j++);\n\t\t\tans= (ans*bell[j-i])%MOD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic void Readin() {\n\t\tScanner  cin;\n\t\tif ( !DEBUG)cin= new Scanner(System.in);\n\t\telse {\n\t\t\ttry {\n\t\t\t\tcin = new Scanner(new File(\"input.txt\"));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\tif ( DEBUG)cerr.println(\"Not Fount input.txt\");\n\t\t\t\treturn ;\n\t\t\t}\n\t\t}\n\t\tm = cin.nextInt(); n=cin.nextInt();\n\t\tocc= new long[m];\n\t\tfor (int i=0; i<n; i++) {\n\t\t\tString s= cin.next();\n\t\t\tfor (int j=0;j <m; j++)\n\t\t\t\tocc[j]|=((long)(s.charAt(j)-'0'))<<i;\n\t\t}\n\t\tcin.close();\n\t}\n}\n", "complexity": "quadratic", "problem": "908_E. New Year and Entity Enumeration", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class EhabAndAnotherAnotherXorProblem implements Closeable {\n\n  private InputReader in = new InputReader(System.in);\n  private PrintWriter out = new PrintWriter(System.out);\n\n  public void solve() {\n    int initial = ask(0, 0);\n    int a = 0, b = 0;\n    if (initial == 0) {\n      for (int i = 0; i < 30; i++) {\n        int response = ask(1 << i, 0);\n        if (response == -1) {\n          a |= (1 << i);\n        }\n      }\n      b = a;\n    } else {\n      for (int i = 29; i >= 0; i--) {\n        int response = ask(a | (1 << i), b | (1 << i));\n        if (response != initial) {\n          if (response == 1) {\n            b |= (1 << i);\n          } else {\n            a |= (1 << i);\n          }\n          initial = ask(a, b);\n        } else {\n          response = ask(a | (1 << i), b);\n          if (response == -1) {\n            a |= (1 << i);\n            b |= (1 << i);\n          }\n        }\n        \n      }\n    }\n    answer(a, b);\n  }\n\n  private int ask(int c, int d) {\n    out.printf(\"? %d %d\\n\", c, d);\n    out.flush();\n    return in.ni();\n  }\n\n  private void answer(int a, int b) {\n    out.printf(\"! %d %d\\n\", a, b);\n    out.flush();\n  }\n\n  @Override\n  public void close() throws IOException {\n    in.close();\n    out.close();\n  }\n\n  static class InputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n      reader = new BufferedReader(new InputStreamReader(stream), 32768);\n      tokenizer = null;\n    }\n\n    public String next() {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n        try {\n          tokenizer = new StringTokenizer(reader.readLine());\n        } catch (IOException e) {\n          throw new RuntimeException(e);\n        }\n      }\n      return tokenizer.nextToken();\n    }\n\n    public int ni() {\n      return Integer.parseInt(next());\n    }\n\n    public long nl() {\n      return Long.parseLong(next());\n    }\n\n    public void close() throws IOException {\n      reader.close();\n    }\n  }\n\n  public static void main(String[] args) throws IOException {\n    try (EhabAndAnotherAnotherXorProblem instance = new EhabAndAnotherAnotherXorProblem()) {\n      instance.solve();\n    }\n  }\n}\n", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.lang.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.*;\n \npublic class Main {\n        \n    public static void main(String[] args) throws Exception{\n        FastReader sc=new FastReader(); \n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n        int n=sc.nextInt();\n        HashMap<String,Integer> map=new HashMap<String,Integer>();\n        for(int i=0;i<n;i++) {\n            map.put(sc.next(), 1);\n        }\n        ArrayList<String> list=new ArrayList<String>();\n        int count=0;\n        if(!map.containsKey(\"purple\")) {\n            count++;\n            list.add(\"Power\");\n        }\nif(!map.containsKey(\"green\")) {\n    count++;\n    list.add(\"Time\");\n        }\n\nif(!map.containsKey(\"blue\")) {\n    count++;\n    list.add(\"Space\");\n}\n\nif(!map.containsKey(\"orange\")) {\n    count++;\n    list.add(\"Soul\");\n}\n\nif(!map.containsKey(\"red\")) {\n    count++;\n    list.add(\"Reality\");\n}\n\nif(!map.containsKey(\"yellow\")) {\n    count++;\n    list.add(\"Mind\");\n}System.out.println(count);\n    for(String s:list) {\n        System.out.println(s);\n    }\n    }\n}\n\nclass 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} ", "complexity": "constant", "problem": "987_A. Infinity Gauntlet", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class AlexAndARhombus {\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\tSystem.out.println(n*n+(n-1)*(n-1));\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "1180_A. Alex and a Rhombus", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\n    static final long mod=(int)1e9+7;\n    public static void main(String[] args) throws Exception\n    {\n    \tFastReader in=new FastReader();\n    \tPrintWriter pw=new PrintWriter(System.out);\n    \tint n=in.nextInt();\n    \tlong ans=0;\n    \tfor(int i=2;2*i<=n;i++)\n    \t{\n    \t\tans+=i*(n/i-1);\n    \t}\n    \tans*=4;\n    \tpw.print(ans);\n    \tpw.flush();\n    }\n}\n\nclass pair\n{\n\tint f,s;\n}\n\nclass FastReader\n{\n    BufferedReader br;\n    StringTokenizer st;\n \n    public FastReader()\n    {\n        br=new BufferedReader(new InputStreamReader(System.in));\n    }\n \n    public String next() throws IOException\n    {\n        if(st==null || !st.hasMoreElements())\n        {\n            st=new StringTokenizer(br.readLine());\n        }\n        return st.nextToken();\n    }\n \n    public int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n \n    public long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n}", "complexity": "linear", "problem": "1062_D. Fun with Integers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    public static void main(String args[]) {\n        FastScanner scn = new FastScanner();\n        int n = scn.nextInt();\n        int s = scn.nextInt();\n        if (s <= n) {\n            System.out.println(1);\n        } else if (s > n) {\n            if(s%n == 0){\n                System.out.println(s/n);\n            } else {\n                System.out.println(s/n + 1);\n            }\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", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class e {\n\npublic static class FastReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t//than using direct \n\n\tpublic FastReader() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString 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 (Exception r) {\n\t\t\t\tr.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());//converts string to integer\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() {\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\t\t} catch (Exception r) {\n\t\t\tr.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n}\nstatic ArrayList<String>list1=new ArrayList<String>();\nstatic void combine(String instr, StringBuffer outstr, int index,int k)\n{\n\tif(outstr.length()==k)\n\t{\n\t\tlist1.add(outstr.toString());return;\n\t}\n\tif(outstr.toString().length()==0)\n\toutstr.append(instr.charAt(index));\n    for (int i = 0; i < instr.length(); i++)\n    {\n        outstr.append(instr.charAt(i));\n       \n        combine(instr, outstr, i + 1,k);\n        outstr.deleteCharAt(outstr.length() - 1);\n    }\n   index++;\n} \nstatic ArrayList<ArrayList<Integer>>l=new ArrayList<>();\nstatic void comb(int n,int k,int ind,ArrayList<Integer>list)\n{\n\tif(k==0)\n\t{\n\t\tl.add(new ArrayList<>(list));\n\n\t\treturn;\n\t}\n\t\n\t\n\tfor(int i=ind;i<=n;i++)\n\t{\n\t\tlist.add(i);\n\t\tcomb(n,k-1,ind+1,list);\n\t\t\n\t\tlist.remove(list.size()-1);\n\t\t\n\t}\n\t\n\t\n\t\n\t\n\t\n\n}\n\n\npublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\tFastReader in=new FastReader();\n\tHashMap<Integer,Integer>map=new HashMap<Integer,Integer>();\n\n\tint n=in.nextInt();\n\tint r=in.nextInt();\n\t \n\tdouble theta=(double)360/(double)n;\n\t \n\tdouble b=1-((double)2/(double)(1-Math.cos((double)2*Math.PI/(double)n)));\n\tdouble x=Math.sqrt(1-b)-1;\n\tdouble ans=(double)r/(double)x;\n\tSystem.out.println(ans);\n\n\n\n\n\n\t}\n}\n", "complexity": "constant", "problem": "1100_C. NN and the Optical Illusion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n    static MyScanner sc;\n    static PrintWriter pw;\n\n    public static void main(String[] args) throws Throwable {\n        sc = new MyScanner();\n        pw = new PrintWriter(System.out);\n\n        n = sc.nextInt();\n        T = sc.nextLong();\n        p = new int[n];\n        l = new int[n];\n        x = new int[n];\n        t = new int[n];\n        adj = new ArrayList[n];\n\n        for (int i = 0; i < n; i++)\n            x[i] = sc.nextInt();\n        for (int i = 0; i < n; i++)\n            t[i] = sc.nextInt();\n        adj[0] = new ArrayList<>();\n        for (int i = 1; i < n; i++) {\n            adj[i] = new ArrayList<>();\n            p[i] = sc.nextInt() - 1;\n            l[i] = sc.nextInt();\n            adj[p[i]].add(i);\n        }\n\n        ftCnt = new long[N];\n        ftSum = new long[N];\n        ans = new long[n];\n\n        dfs(0);\n        pw.println(ans[0]);\n\n        pw.flush();\n        pw.close();\n    }\n\n    static int n;\n    static long T;\n    static int[] p, l, x, t;\n    static ArrayList<Integer>[] adj;\n\n    static long[] ans;\n\n    static void dfs(int u) {\n        update(t[u], x[u], 1L * x[u] * t[u]);\n        ans[u] = getMaxCnt();\n        long[] vals = {-1, -1, -1};\n        for (int v : adj[u]) {\n            T -= 2 * l[v];\n            dfs(v);\n            vals[0] = ans[v];\n            Arrays.sort(vals);\n            T += 2 * l[v];\n        }\n        if (u != 0) {\n            if (vals[1] != -1)\n                ans[u] = Math.max(ans[u], vals[1]);\n        } else {\n            if (vals[2] != -1)\n                ans[u] = Math.max(ans[u], vals[2]);\n        }\n        update(t[u], -x[u], -1L * x[u] * t[u]);\n    }\n\n    static int N = (int) 1e6 + 2;\n    static long[] ftCnt, ftSum;\n\n    static void update(int idx, long cnt, long val) {\n        while (idx < N) {\n            ftCnt[idx] += cnt;\n            ftSum[idx] += val;\n            idx += (idx & -idx);\n        }\n    }\n\n    static long getSum(int idx) {\n        long ret = 0;\n        while (idx > 0) {\n            ret += ftSum[idx];\n            idx -= (idx & -idx);\n        }\n        return ret;\n    }\n\n    static long getCnt(int idx) {\n        long ret = 0;\n        while (idx > 0) {\n            ret += ftCnt[idx];\n            idx -= (idx & -idx);\n        }\n        return ret;\n    }\n\n    static long getMaxCnt() {\n        int start = 1, end = N - 1, ans = N - 1;\n        while (start <= end) {\n            int mid = (start + end) / 2;\n            if (getSum(mid) >= T) {\n                ans = mid;\n                end = mid - 1;\n            } else\n                start = mid + 1;\n        }\n        long remT = T - (ans > 1 ? getSum(ans - 1) : 0);\n        long cnt = (ans > 1 ? getCnt(ans - 1) : 0);\n        long cntOfVal = getCnt(ans) - cnt;\n        cnt += Math.min(cntOfVal, remT / ans);\n        return cnt;\n    }\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}", "complexity": "nlogn", "problem": "1099_F. Cookies", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class Code {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\t BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t int n = Integer.parseInt(br.readLine());\n\t\t HashMap<Double,Integer>h = new HashMap<>();\n\t\t double [] temp = new double[n];\n\t\t int m = 0;\n\t\t for(int i=0;i<n;i++) {\n\t\t\t String l = br.readLine();\n\t\t\t int[] x = new int[4];\n\t\t\t int k=0;\n\t\t\t boolean t = false;\n\t\t\t for(int j=0;j<l.length();j++) {\n\t\t\t\t if(l.charAt(j)=='(' || l.charAt(j)=='+' || l.charAt(j)==')' || l.charAt(j)=='/')\n\t\t\t\t\t x[k++] = j;\n\t\t\t }\n\t\t\t double a = Integer.parseInt(l.substring(x[0]+1,x[1]));\n\t\t\t double b = Integer.parseInt(l.substring(x[1]+1, x[2]));\n\t\t\t double c = Integer.parseInt(l.substring(x[3]+1));\n\t\t\t temp[m++] = (a+b)/c;\n\t\t\t //System.out.print((a+b)/c + \" \");\n\t\t\tif(h.containsKey((a+b)/c))\n\t\t\t\t\th.put((a+b)/c, h.get((a+b)/c)+1);\n\t\t\telse\n\t\t\t\th.put((a+b)/c, 1);\n\t\t }\n\t\t //System.out.println(h);\n\t\t for(int i=0;i<n;i++) {\n\t\t\t System.out.print(h.get(temp[i]) + \" \");\n\t\t }\n\t}\n\t}\n", "complexity": "linear", "problem": "958_D1. Hyperspace Jump (easy)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class programA {\n\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\tif(n%2 == 0)System.out.println(n/2 +1);\n\t\telse System.out.println((int)Math.ceil((double)n/2));\n\t}\n}\n\n\n\n\n", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigInteger;\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 p1096f {\n    static long MOD = 998244353;\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        BIT invert = new BIT(n+5);\n        BIT neg = new BIT(n+5);\n        long res = 0;\n        int[] arr = new int[n];\n        boolean[] has = new boolean[n+1];\n        long num1 = 0;\n        for(int i = 0; i < n; i++) {\n            arr[i] = in.nextInt();\n            if(arr[i] != -1) {\n                res += invert.read(n+5)-invert.read(arr[i]);\n                res %= MOD;\n                invert.update(arr[i], 1);\n                has[arr[i]] = true;\n            } else num1++;\n        }\n        if(num1 == 0) {\n            System.out.println(res);\n            return;\n        }\n        for(int i = 1; i <= n; i++) if(!has[i]) neg.update(i, 1);\n        long invertNum1 = modInv(num1, MOD);\n        res += ((num1*(num1-1))%MOD)*modInv(4, MOD);\n        res %= MOD;\n        long cnt = 0;\n        for(int i = 0; i < n; i++) {\n            if(arr[i] == -1) {\n                cnt++;\n                continue;\n            }\n            res += (((neg.read(n+5)-neg.read(arr[i]))*cnt)%MOD)*invertNum1;\n            res %= MOD;\n        }\n        cnt = 0;\n        for(int i = n-1; i >= 0; i--) {\n            if(arr[i] == -1) {\n                cnt++;\n                continue;\n            }\n            res += (((neg.read(arr[i]))*cnt)%MOD)*invertNum1;\n            res %= MOD;\n        }\n        System.out.println(res);\n    }\n    \n    //@\n    static class BIT {\n            int n;\n            int[] tree;\n            public BIT(int n) {\n                    this.n = n;\n                    tree = new int[n + 1];\n            }\n\n            int read(int i) {\n                    int sum = 0;\n                    while (i > 0) {\n                            sum += tree[i];\n                            i -= i & -i;\n                    }\n                    return sum;\n            }\n\n            void update(int i, int val) {\n                    while (i <= n) {\n                            tree[i] += val;\n                            i += i & -i;\n                    }\n            }\n            //$\n    }\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        return (BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod))).longValue();\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    \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", "complexity": "nlogn", "problem": "1096_F. Inversion Expectation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Waw{\n    \n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        long[] a = new long[n];\n        for(int i=0;i<n;i++) a[i] = sc.nextLong();\n        long[] p = new long[n];\n        p[n-1] = a[n-1];\n        for(int i=n-2;i>=0;i--){\n            if(a[i]<p[i+1]) p[i] = p[i+1]-1;\n            else p[i] = a[i];\n        }\n        long max = p[0];\n        long res = p[0] - a[0];\n        for(int i=1;i<n;i++){\n            if(max < p[i]) max = p[i];\n            res += max - a[i];\n        }\n        System.out.println(res);\n    }\n}", "complexity": "linear", "problem": "924_C. Riverside Curio", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StringWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.io.InputStream ;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\n\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(System.out);\n        //Scanner sc = new Scanner();\n        Reader in = new Reader();\n        Main solver = new Main();\n        solver.solve(out, in);\n        out.flush();\n        out.close();\n\n    }\n    \n    \n    void solve(PrintWriter out, Reader in) throws IOException{   \n        int n = in.nextInt();\n        int m = in.nextInt();\n        \n        \n        \n        int[] vert = new int[n+1];\n        for(int i=0 ;i<n ;i++) vert[i] = in.nextInt();\n        vert[n] = (int)1e9;\n        \n        int cnt=0,x,y;\n        ArrayList<Integer> arr = new ArrayList<>();\n        for(int i=0 ;i<m ;i++) {\n            x = in.nextInt();\n            y = in.nextInt();\n            in.nextInt();\n            \n            if(x==1) arr.add(y);\n        }\n        \n        horz = new int[arr.size()];\n        for(int i=0 ;i<arr.size();i++) horz[i] = arr.get(i);\n        \n        Arrays.sort(horz);\n        Arrays.sort(vert);\n        \n        int ans = 2*(int)1e5+10;\n        for(int i=0 ;i<=n ;i++){\n            int lesshorz = bs(vert[i],horz.length);\n            ans = Math.min(ans,i+horz.length-lesshorz-1);\n        }\n        out.println(ans);\n    }\n    \n    static int[] horz;\n    \n    static int bs(int num,int m){\n        int mid,lo=0,hi=m-1,r=-1;\n        \n        while(lo<=hi){\n            mid = (lo+hi)/2;\n            if(horz[mid]<num){\n                lo = mid+1;\n                r = mid;\n            }else{\n                hi =mid-1;\n            }\n        }\n        return r;\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        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n     \n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n     \n        public boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n     \n        public boolean isEndOfLine(int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n \n    }\n}\n", "complexity": "nlogn", "problem": "1075_C. The Tower is Going Home", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    private void solve() {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        int n = nextInt(), m = nextInt();\n        boolean[][] used = new boolean[n + 1][m + 1];\n\n        for (int j = 1; j <= (m + 1) / 2; j++) {\n            int x1 = 1, x2 = n;\n            for (int i = 1; i <= n; i++) {\n                if (x1 <= n && !used[x1][j]) {\n                    out.println(x1 + \" \" + j);\n                    used[x1++][j] = true;\n                }\n                if (x2 > 0 && !used[x2][m - j + 1]) {\n                    out.println(x2 + \" \" + (m - j + 1));\n                    used[x2--][m - j + 1] = true;\n                }\n            }\n        }\n\n        out.close();\n    }\n\n    public static void main(String[] args) {\n        new D().solve();\n    }\n\n    private BufferedReader br;\n    private StringTokenizer st;\n    private PrintWriter out;\n\n    private String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return st.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", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "/* 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\tstatic int check(int temp)\n\t{\n\t\tint count1 = 0; \n    while (temp>0) \n    { \n        if(temp % 2 != 0) \n        count1++; \n        temp/= 2; \n    } \n    return count1;\n\t}\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\tString a=sc.next();\n\t\tString b=sc.next();\n\t\tint m=a.length();\n\t\tint n=b.length();\n\t\tint[] zero=new int[n];\n\t\tint[] one=new int[n];\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tif(i==0)\n\t\t\t{\n\t\t\t\tif(b.charAt(i)=='0')\n\t\t\t\tzero[i]++;\n\t\t\t\telse\n\t\t\t\tone[i]++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tzero[i]=zero[i-1];\n\t\t\t\tone[i]=one[i-1];\n\t\t\t\tif(b.charAt(i)=='0')\n\t\t\t\tzero[i]++;\n\t\t\t\telse\n\t\t\t\tone[i]++;\n\t\t    }\n\t\t}\n\t\t\n\n\t\tlong res=0;\n\t\tfor(int i=0;i<m;i++)\n\t\t{\n\t\tint x=n-m+i;\n\t\tif(a.charAt(i)=='0')\n\t\tres+=one[x];\n\t\telse\n\t\tres+=zero[x];\n\t\tif(i>0)\n\t\t{\n\t\t\tif(a.charAt(i)=='0')\n\t\t\tres-=one[i-1];\n\t\t\telse\n\t\t\tres-=zero[i-1];\n\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(res);\n\t}\n}", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _1036_B_DiagonalWalkingV2 {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint Q = readInt();\n\t\twhile(Q-- > 0) {\n\t\t\tlong n = readLong(), m = readLong(), k = readLong();\n\t\t\tif(Math.max(n, m) > k) println(-1);\n\t\t\telse {\n\t\t\t\tlong ans = k;\n\t\t\t\tif(n%2 != k%2) ans--;\n\t\t\t\tif(m%2 != k%2) ans--;\n\t\t\t\tprintln(ans);\n\t\t\t}\n\t\t}\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", "complexity": "linear", "problem": "1036_B. Diagonal Walking v.2", "from": "CODEFORCES"}
{"src": "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        BTheHat solver = new BTheHat();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BTheHat {\n        PrintWriter out;\n        InputReader in;\n        int n;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            this.out = out;\n            this.in = in;\n            n = in.NextInt();\n            int desiredPair = -1;\n            int result = query(1);\n            if (result != 0) {\n                int l = 2, r = 1 + n / 2;\n                while (l < r) {\n                    int m = (l + r) / 2;\n                    int mRes = query(m);\n                    if (mRes == 0) {\n                        desiredPair = m;\n                        break;\n                    } else if (mRes == result) {\n                        l = m + 1;\n                    } else {\n                        r = m;\n                    }\n                }\n            } else {\n                desiredPair = 1;\n            }\n            out.println(\"! \" + desiredPair);\n        }\n\n        private int query(int i) {\n            int iV = queryValue(i);\n            int iN2V = queryValue(i + n / 2);\n            if (iV < iN2V) {\n                return -1;\n            } else if (iV > iN2V) {\n                return 1;\n            }\n            return 0;\n        }\n\n        private int queryValue(int i) {\n            out.println(\"? \" + i);\n            out.flush();\n            return in.NextInt();\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", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "\nimport java.io.PrintWriter;\n\nimport java.util.*;\nimport java.util.Arrays ; \nimport java .lang.String.* ;\nimport java .lang.StringBuilder ;\n\n\npublic class Test{\n    static int pos = 0 ; \n    static int  arr[] ; \n  static LinkedList l1 = new  LinkedList() ; \nstatic void find(int p ,char[]x,int put[],String s){\n    int c= 0 ; \n    for (int i = 0; i < s.length(); i++) {\n        if(x[p]==s.charAt(i)){\n        c++ ; }\n    }\n    put[p] = c ;  \n}\nstatic int mode(int m ,int[]x ){\n    int temp = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return m-temp ; \n             \n        }\n    }\n     return m-temp ; \n}\nstatic int mode2(int m ,int[]x ){\n    int temp = 0 ; \n    \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return x[i] ; \n             \n        }\n    }\n     return 0 ; \n}\nstatic int find(int x[],int temp){\n    int j = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]==temp) return j+1 ; \n        j++ ; \n    }\n    return -1 ; \n}\nstatic String ch(long[]x,long b){\n    for (int i = 0; i < x.length; i++) {\n        if(x[i]==b)return \"YES\" ;\n    }\n    return \"NO\" ; \n}\n\n    public static void main(String[] args)  {\n\n        Scanner in = new Scanner(System.in) ;\n        PrintWriter pw = new PrintWriter(System.out);   \n        long n = in.nextLong() ; \n        long count =1 ; \n        long temp =n/2;\n     temp+=count ;\n      \n       \n        System.out.println(temp);\n }               \n}\n\n", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String args[]) {\n\t\tScanner in=new Scanner(System.in);\n\t\tString str=in.next();\n\t\tint cnt=0;\n\t\tfor(int i=0;i<str.length();++i) {\n\t\t\tif(str.charAt(i)=='1') {\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\tint i=0;\n\t\tfor(;i<str.length();++i) {\n\t\t\tif(str.charAt(i)=='0') {\n\t\t\t\tSystem.out.print(\"0\");\n\t\t\t}\n\t\t\telse if(str.charAt(i)=='2') {\n\t\t\t\twhile(cnt-->0) {//\n\t\t\t\t\tSystem.out.print(\"1\");\n\t\t\t\t}\n\t\t\t\tSystem.out.print(\"2\");\n\t\t\t}\n\t\t}\n\t\twhile(cnt-->0) {\n\t\t\tSystem.out.print(\"1\");\n\t\t}\n\t\tin.close();\n\t}\n}", "complexity": "linear", "problem": "1009_B. Minimum Ternary String", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\npublic class FunctionHeight {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        long n = sc.nl();\n        long k = sc.nl();\n        long ans = (n+k-1)/n;\n        System.out.println(ans);\n    }\n\n    /////////// TEMPLATE FROM HERE /////////////////\n    private static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int ni() {\n            return Integer.parseInt(next());\n        }\n\n        float nf() {\n            return Float.parseFloat(next());\n        }\n\n        long nl() {\n            return Long.parseLong(next());\n        }\n\n        double nd() {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "constant", "problem": "1036_A. Function Height", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\nimport java.util.Scanner;\n\npublic class A1 {\n\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n\n        long size = scan.nextLong();\n        int numberOfSpecial = scan.nextInt();\n        long pageSize = scan.nextLong();\n\n        long[] specialItemsArray = new long[numberOfSpecial];\n        for (int i = 0; i < numberOfSpecial; i++) {\n            specialItemsArray[i] = scan.nextLong();\n        }\n\n        int totalRemoved = 0;\n        int step = 0;\n\n        long currentPageIndex = BigDecimal.valueOf(specialItemsArray[0]).divide(BigDecimal.valueOf(pageSize),2, RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();\n        int specialItemArrayIndex = 1;\n\n        while (specialItemArrayIndex < numberOfSpecial) {\n            long pageIndex = BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();\n            if (currentPageIndex != pageIndex) {\n                step++;\n                totalRemoved = specialItemArrayIndex;\n                currentPageIndex =  BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();\n            }\n            specialItemArrayIndex++;\n        }\n\n\n        System.out.println(step + 1);\n\n    }\n\n}\n", "complexity": "linear", "problem": "1190_A. Tokitsukaze and Discard Items", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n\npublic class Main {\n\n\tstatic class Task {\n\t\t\n\t\tint NN = 500005;\n\t\tint MOD = 1000000007;\n\t\tint INF = 2000000000;\n\t\tlong INFINITY = 2000000000000000000L;\n\t\t\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint t = in.nextInt();\n\t\t\twhile(t-->0) {\n\t\t\t\tlong n =in.nextLong();\n\t\t\t\tlong m = in.nextLong();\n\t\t\t\tlong x1 = in.nextLong();\n\t\t\t\tlong y1 = in.nextLong();\n\t\t\t\tlong x2 = in.nextLong();\n\t\t\t\tlong y2 = in.nextLong();\n\t\t\t\tlong x3 = in.nextLong();\n\t\t\t\tlong y3 = in.nextLong();\n\t\t\t\tlong x4 = in.nextLong();\n\t\t\t\tlong y4 = in.nextLong();\n\t\t\t\tlong w = white(1, 1, m, n);\n\t\t\t\tlong b = black(1, 1, m, n);\n\t\t\t\tlong whited = 0;\n\t\t\t\tif(x3 > x2 || x4 < x1 || y3 > y2 || y4 < y1) {\n\t\t\t\t\twhited = black(x1, y1, x2, y2);\n\t\t\t\t} else {\n\t\t\t\t\twhited = black(x1, y1, x2, y2);\n\t\t\t\t\tlong xm1 = Math.max(x1, x3);\n\t\t\t\t\tlong ym1 = Math.max(y1, y3);\n\t\t\t\t\tlong xm2 = Math.min(x2, x4);\n\t\t\t\t\tlong ym2 = Math.min(y2, y4);\n\t\t\t\t\twhited -= black(xm1, ym1, xm2, ym2);\n\t\t\t\t}\n\t\t\t\tb -= whited;w += whited;\n\t\t\t\tlong blacked = white(x3, y3, x4, y4);\n\t\t\t\tw-= blacked;b += blacked;\n\t\t\t\tout.println(w + \" \" + b);\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong black(long x1, long y1, long x2, long y2) {\n\t\t\tlong dx = (x2 - x1) + 1;\n\t\t\tlong dy = (y2 - y1) + 1;\n\t\t\tif((x1+y1)%2!=0) {\n\t\t\t\treturn ((dy+1)/2)*((dx+1)/2)+(dy/2)*(dx/2);\n\t\t\t}\n\t\t\treturn ((dy+1)/2)*((dx)/2)+(dy/2)*((dx+1)/2);\n\t\t}\n\t\t\n\t\tlong white(long x1, long y1, long x2, long y2) {\n\t\t\tlong dx = (x2 - x1) + 1;\n\t\t\tlong dy = (y2 - y1) + 1;\n\t\t\tif((x1+y1)%2==0) {\n\t\t\t\treturn ((dy+1)/2)*((dx+1)/2)+(dy/2)*(dx/2);\n\t\t\t}\n\t\t\treturn ((dy+1)/2)*(dx/2)+(dy/2)*((dx+1)/2);\n\t\t}\n\t\t\n\t}\n\t\n\tstatic void prepareIO(boolean isFileIO) {\n\t\t//long t1 = System.currentTimeMillis();\n\t\tTask solver = new Task();\n\t\t// Standard IO\n\t\tif(!isFileIO) { \n\t\t\tInputStream inputStream = System.in;\n\t        OutputStream outputStream = System.out;\n\t        InputReader in = new InputReader(inputStream);\n\t        PrintWriter out = new PrintWriter(outputStream);\n\t        solver.solve(in, out);\n\t        //out.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        out.close();\n\t\t}\n        // File IO\n\t\telse {\n\t\t\tString IPfilePath = System.getProperty(\"user.home\") + \"/Downloads/ip.in\";\n\t        String OPfilePath = System.getProperty(\"user.home\") + \"/Downloads/op.out\";\n\t        InputReader fin = new InputReader(IPfilePath);\n\t        PrintWriter fout = null;\n\t        try {\n\t\t\t\tfout = new PrintWriter(new File(OPfilePath));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t        solver.solve(fin, fout);\n\t        //fout.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        fout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n        prepareIO(false);\n\t}\n\t\n\tstatic class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n        \n        public InputReader(String filePath) {\n        \tFile file = new File(filePath);\n            try {\n\t\t\t\treader = new BufferedReader(new FileReader(file));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n            tokenizer = null;\n        }\n        \n        public String nextLine() {\n        \tString str = \"\";\n        \ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n        \treturn str;\n        }\n        \n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n        \treturn Double.parseDouble(next());\n        }\n        \n    }\n\n}", "complexity": "constant", "problem": "1080_C. Masha and two friends", "from": "CODEFORCES"}
{"src": "/**\n * Created by Baelish on 8/28/2018.\n */\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class F_DSU {\n    public static void main(String[] args)throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        \n        int brr[] = new int[2*n];\n        for (int i = 0; i < 2*n; i+= 2) {\n            brr[i] = in.nextInt();\n            brr[i+1] = in.nextInt();\n        }\n\n        arr = shrink(brr);\n        int imap[] = new int[2*n];\n        for (int i = 0; i < 2*n; i++) {\n            imap[arr[i]] = brr[i];\n        }\n\n        int idx = binarySearch(arr.length);\n        if(idx >= arr.length) pw.println(-1);\n        else pw.println(imap[idx]);\n\n        pw.close();\n    }\n    static int n, arr[];\n\n    static int binarySearch(int H) {\n        int lo = 0, hi = H, mid;\n        while (lo < hi) {\n            mid = (lo + hi) / 2;\n            if (check(mid)) hi = mid;\n            else lo = mid + 1;\n        }\n        if(lo > 0 && check(lo-1)) return lo-1;\n        return lo;\n    }\n\n    static boolean check(int m){\n        DSU dsu = new DSU(2*n);\n        for (int i = 0; i < n; i++) {\n            int u = arr[2*i], v = arr[2*i+1];\n            if(u > m) return false;\n            if(v > m){\n                if(++dsu.cycle[dsu.find(u)] >= 2) return false;\n            }\n            else{\n                if(!dsu.union(u, v)){\n                    if(++dsu.cycle[dsu.find(u)] >= 2) return false;\n                }\n                else{\n                    if(dsu.cycle[dsu.find(u)] >= 2) return false;\n                }\n            }\n        }\n        return true;\n    }\n\n    static class DSU{\n        int parent[], cycle[], n;\n        DSU(int N){\n            n = N;\n            parent = new int[N];\n            cycle = new int[N];\n            for(int i = 0; i < N; i++){\n                parent[i] = i;\n            }\n        }\n\n        DSU(int [] p){\n            parent = p; n = p.length;\n        }\n\n        int find(int i) {\n            int p = parent[i];\n            if (i == p) return i;\n            return parent[i] = find(p);\n        }\n\n        boolean equiv(int u, int v){\n            return find(u) == find(v);\n        }\n\n        boolean union(int u, int v){\n            u = find(u); v = find(v);\n            if(u != v) {\n                parent[u] = parent[v];\n                cycle[v] += cycle[u];\n            }\n            return u != v;\n        }\n\n        int count(){\n            int cnt = 0;\n            for(int i = 0; i < n; i++){\n                if(i == find(i)) cnt++;\n            }\n            return cnt;\n        }\n    }\n\n    public static int[] shrink(int[] a) {\n        int n = a.length;\n        long[] b = new long[n];\n        for(int i = 0;i < n;i++)b[i] = (long)a[i]<<32|i;\n        Arrays.sort(b);\n        int[] ret = new int[n];\n        int p = 0;\n        for(int i = 0;i < n;i++) {\n            if(i>0 && (b[i]^b[i-1])>>32!=0)p++;\n            ret[(int)b[i]] = p;\n        }\n        return ret;\n    }\n\n    static void debug(Object...obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n        static final int ints[] = new int[128];\n\n        public FastReader(InputStream is){\n            for(int i='0';i<='9';i++) ints[i]=i-'0';\n            this.is = is;\n        }\n\n        public 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        public boolean isSpaceChar(int c) {\n            return !(c >= 33 && c <= 126);\n        }\n        public int skip() {\n            int b;\n            while((b = readByte()) != -1 && isSpaceChar(b));\n            return b;\n        }\n\n        public String next(){\n            int b = skip();\n            StringBuilder sb = new StringBuilder();\n            while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n                sb.appendCodePoint(b);\n                b = readByte();\n            }\n            return sb.toString();\n        }\n\n        public int nextInt(){\n            int num = 0, b;\n            boolean minus = false;\n            while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n            if(b == '-'){\n                minus = true;\n                b = readByte();\n            }\n\n            while(true){\n                if(b >= '0' && b <= '9'){\n                    num = (num<<3) + (num<<1) + ints[b];\n                }else{\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public long nextLong() {\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<<3) + (num<<1) + ints[b];\n                }else{\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n       /* public char nextChar() {\n            return (char)skip();\n        }*/\n\n        public 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        /*private char buff[] = new char[1005];\n        public char[] nextCharArray(){\n            int b = skip(), p = 0;\n            while(!(isSpaceChar(b))){\n                buff[p++] = (char)b;\n                b = readByte();\n            }\n            return Arrays.copyOf(buff, p);\n        }*/\n    }\n}", "complexity": "quadratic", "problem": "1027_F. Session in BSU", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class n5D\n{\n    public static void main(String[] args)\n    {\n        double a = 0, v = 0, l = 0, d = 0, w = 0;\n        try\n        {\n            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n            String[] str = br.readLine().split(\" \");\n            a = Double.parseDouble(str[0]);\n            v = Double.parseDouble(str[1]);\n            str = br.readLine().split(\" \");\n            l = Double.parseDouble(str[0]);\n            d = Double.parseDouble(str[1]);\n            w = Double.parseDouble(str[2]);\n        }\n        catch(Exception e)\n        {\n            System.out.println(e);\n        }\n\n        double t1, t2, t3, t4, t5, t, D = 0;\n        \n        if (w > v) w = v;\n        t2 = d / v - v / a + w * w / 2 / a / v;\n        if (t2 >= 0)\n        {\n            t1 = v / a; \n            t3 = t1 - w / a;\n        }\n        else\n        {\n            if (Math.sqrt(2 * d / a) > (w / a))\n            {\n                t1 = Math.sqrt((2 * a * d + w * w) / (a * a * 2));\n                t3 = t1 - w / a;\n            }\n            else\n            {\n                t1 = Math.sqrt(2 * d / a);\n                t3 = 0;\n            }\n            t2 = 0;\n        }\n        t5 = (l - d - v * v / 2 / a + a * (t1 - t3) * (t1 - t3) / 2) / v;\n        if (t5 >= 0) t4 = v / a - (t1 - t3);\n        else\n        {\n            t5 = 0;\n            t4 = -t1 + t3 + Math.sqrt((t1 - t3) * (t1 - t3) + 2 * (l - d) / a);\n        }\n        t = t1 + t2 + t3 + t4 + t5;\n        System.out.println(t);\n        //System.out.println(t1 + \" \" + t2 + \" \" + t3 + \" \" + t4 + \" \" + t5);\n    }\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n    \n    public static long page(long p,long k){\n        \n        return (p-1)/k;\n        \n    }\n    \n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        \n        long n = sc.nextLong();\n        int m = sc.nextInt();\n        long k = sc.nextLong();\n        long[] p = new long[m];\n        long del = 0;\n        long nb = 1;\n        int op = 0;\n        for(int i=0;i<m;i++) p[i] = sc.nextLong();\n        for(int i=1;i<m;i++){\n            if(page(p[i]-del,k)!=page(p[i-1]-del,k)){\n                \n                del += nb;\n                nb = 1;\n                op++;\n                \n            }else{\n                nb++;\n                \n            }\n        }\n        if(nb!=0) op++;\n        \n        System.out.println(op);\n        \n    }\n    \n}", "complexity": "linear", "problem": "1191_C. Tokitsukaze and Discard Items", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.PrintWriter;\n\nimport java.util.*;\nimport java.util.Arrays ; \nimport java .lang.String.* ;\nimport java .lang.StringBuilder ;\n\n\npublic class Test{\n    static int pos = 0 ; \n    static int  arr[] ; \n  static LinkedList l1 = new  LinkedList() ; \nstatic void find(int p ,char[]x,int put[],String s){\n    int c= 0 ; \n    for (int i = 0; i < s.length(); i++) {\n        if(x[p]==s.charAt(i)){\n        c++ ; }\n    }\n    put[p] = c ;  \n}\nstatic int mode(int m ,int[]x ){\n    int temp = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return m-temp ; \n             \n        }\n    }\n     return m-temp ; \n}\nstatic int mode2(int m ,int[]x ){\n    int temp = 0 ; \n    \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return x[i] ; \n             \n        }\n    }\n     return 0 ; \n}\nstatic int find(int x[],int temp){\n    int j = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]==temp) return j+1 ; \n        j++ ; \n    }\n    return -1 ; \n}\nstatic String ch(long[]x,long b){\n    for (int i = 0; i < x.length; i++) {\n        if(x[i]==b)return \"YES\" ;\n    }\n    return \"NO\" ; \n}\n\n    public static void main(String[] args)  {\n\n        Scanner in = new Scanner(System.in) ;\n        PrintWriter pw = new PrintWriter(System.out);   \n     int k=in.nextInt(), n=in.nextInt(), s=in.nextInt(), p=in.nextInt() ;\n     int paper =n/s; \n     if(n%s!=0) paper++ ; \n     paper*=k ; \n     int fin = paper/p ; \n     if(paper%p!=0) fin++ ; \n        System.out.println( fin );\n       \n       \n }               \n}\n\n", "complexity": "constant", "problem": "965_A. Paper Airplanes", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\nimport java.io.*;\n\npublic class SolutionB {\n      public static void main(String args[])throws IOException{\n              Scanner sc = new Scanner(System.in);\n              int a[] = new int[1501];\n              for(int i = 0; i < 3; i++){\n                     a[sc.nextInt()]++;\n              }\n              if(a[1] > 0 || a[2] > 1 || a[3] > 2 || (a[4] == 2 && a[2] == 1)){\n                     System.out.println(\"YES\");\n              }else{\n                     System.out.println(\"NO\");\n              }\n      }\n}", "complexity": "constant", "problem": "911_C. Three Garlands", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\nimport java.util.Stack;\npublic class D527A2 {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tint N = in.nextInt();\n\t\tStack<Integer> stack = new Stack<>();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint num = in.nextInt() % 2;\n\t\t\tif(stack.size() >= 1 && stack.lastElement() == num)\n\t\t\t\tstack.pop();\n\t\t\telse\n\t\t\t\tstack.add(num);\n\t\t}\n\t\t\n\t\tSystem.out.println(stack.size() <= 1 ? \"YES\" : \"NO\");\n\t}\n\t\n\t/**\n\t * Source: Matt Fontaine\n\t */\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 chars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tint read() {\n\t\t\tif (chars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= chars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tchars = 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 (chars <= 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\t}\n\n}\n/*\n5\n2 1 1 2 5\noutputCopy\nYES\ninputCopy\n3\n4 5 3\noutputCopy\nYES\ninputCopy\n2\n10 10\noutputCopy\nYES\ninputCopy\n3\n1 2 3\noutputCopy\nNO\n\n5\n2 3 2 2 3\n\nYES\n*/", "complexity": "linear", "problem": "1092_D1. Great Vova Wall (Version 1)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\npublic class stacks {\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\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\t\n\t\tlong remove = 0;\n\t\t\n\t\tint[] heights = new int[n+1];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\theights[i] = sc.nextInt();\n\t\t\tremove += heights[i];\n\t\t}\n\t\t\n\t\tArrays.sort(heights);\n\t\t//System.out.println(Arrays.toString(heights));\n\t\tlong keep = 0;\n\t\tfor(int i = n; i> 0; i--) {\n\t\t\tif(heights[i-1] >= heights[i]) {\n\t\t\t\theights[i-1] = heights[i]-1;\n\t\t\t}\n\t\t\tkeep += heights[i] - heights[i-1];\n\t\t}\n\t\t//System.out.println(Arrays.toString(heights));\n\t\t\n\t\tpw.println(remove - keep);\n\t\tpw.close();\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", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "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.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 \\/\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            int n = in.nextInt();\n            int m = in.nextInt();\n\n            TaskC.pair[] songs = new TaskC.pair[n];\n            long sum = 0;\n            for (int i = 0; i < n; i++) {\n                songs[i] = new TaskC.pair(in.nextInt(), in.nextInt());\n                sum += songs[i].a;\n            }\n            Arrays.sort(songs);\n\n            int res = 0;\n            int idx = n - 1;\n            while (sum > m) {\n                if (idx < 0) {\n                    break;\n                }\n                sum -= (songs[idx].a - songs[idx].b);\n\n                res++;\n                idx--;\n            }\n\n            if (sum > m) {\n                out.println(-1);\n            } else {\n                out.println(res);\n            }\n        }\n\n        static class pair implements Comparable<TaskC.pair> {\n            int a;\n            int b;\n\n            pair(int a, int b) {\n                this.a = a;\n                this.b = b;\n            }\n\n            public int compareTo(TaskC.pair p) {\n                return (this.a - this.b) - (p.a - p.b);\n            }\n\n        }\n\n    }\n\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public Scanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public Scanner(String s) {\n            try {\n                br = new BufferedReader(new FileReader(s));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "1015_C. Songs Compression", "from": "CODEFORCES"}
{"src": "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 gaidash\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            final int SIZE = 256;\n            final int UNDEF = -1;\n\n            int nPixels = in.nextInt();\n            int groupSize = in.nextInt();\n            int[] a = in.nextIntArray(nPixels);\n            boolean[] exists = new boolean[SIZE];\n            int[] left = new int[SIZE];\n            int[] right = new int[SIZE];\n            int[] ret = new int[nPixels];\n            Arrays.fill(ret, UNDEF);\n\n            for (int i = 0; i < nPixels; i++) {\n                for (int p = 0; p < SIZE; p++) {\n                    if (exists[p] && left[p] <= a[i] && a[i] <= right[p]) {\n                        ret[i] = left[p];\n                        left[a[i]] = left[p];\n                        right[a[i]] = right[p];\n                        break;\n                    }\n                }\n                if (ret[i] == UNDEF) {\n                    int l = Math.max(a[i] - groupSize + 1, 0);\n                    int r = l + groupSize - 1;\n                    for (int p = a[i] - 1; p >= 0; p--) {\n                        if (exists[p]) {\n                            if (p >= l) {\n                                int d = p - l;\n                                l = p + 1;\n                                r += d + 1;\n                            }\n                            if (right[p] >= l) {\n                                right[p] = l - 1;\n                            }\n                        }\n                    }\n                    for (int p = a[i] + 1; p < SIZE; p++) {\n                        if (exists[p] && left[p] <= r) {\n                            r = left[p] - 1;\n                        }\n                    }\n                    left[a[i]] = l;\n                    right[a[i]] = r;\n                    ret[i] = l;\n                }\n                exists[a[i]] = true;\n            }\n//        for (int p : a) {\n//            System.out.println(\"Segment for pixel \" + p + \" = \" + \"(\" + left[p] + \" , \" + right[p] + \")\");\n//        }\n\n            out.print(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 print(int[] array) {\n            for (int i = 0; i < array.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(array[i]);\n            }\n        }\n\n        public void 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 int[] nextIntArray(int n) {\n            int[] array = new int[n];\n            for (int i = 0; i < n; ++i) array[i] = nextInt();\n            return array;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "980_C. Posterized", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner() {\n            try {\n                br = new BufferedReader(new InputStreamReader(System.in));\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e){e.printStackTrace();}\n        }\n\n        public String next() {\n            if (st.hasMoreTokens()) return 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 static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int n = sc.nextInt();\n        int best = 1;\n        int bestTime = Integer.MAX_VALUE;\n        for(int i=0;i<n;i++) {\n            int time;\n            int a = sc.nextInt();\n            time = (a%n==0 || a%n<=i) ? a/n : (a+n)/n;\n            if(time < bestTime) {\n                best = i + 1;\n                bestTime = time;\n            }\n        }\n\n        pw.println(best);\n        pw.close();\n    }\n}\n", "complexity": "linear", "problem": "996_B. World Cup", "from": "CODEFORCES"}
{"src": "//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&d4==2||d3==1&d4==1&d5==2||d5==1&d4==1&d3==2)\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(d3<d5&d3<d4) {\n\t\t\t    if(d3==1||d3==2||d3==0) System.out.println(1);\n\t\t        else                 System.out.println(2);\n\t\t\t    }\n\t\t\telse if (d5<d4&d5<d3){\n\t\t\t\t if(d5==1||d5==2||d5==0) System.out.println(1);\n\t\t\t\t\telse                 System.out.println(2);\n\t\t\t}\n\t\t\telse if(d4<d5&d4<d3) {\n\t\t\t\tif(d4==1||d4==2||d4==0) System.out.println(1);\n\t\t\t\telse                 System.out.println(2);\n\t\t\t}\n\t\t\telse if(d3==2&d5==2||d4==2&d5==2||d3==2&d4==2||d3==1&d5==1||d4==1&d5==1||d3==2&d4==1)\n\t\t\t\tSystem.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t\t\n\t\t\t\n\t\t\n\t\t \n\t\t    \n\t\t    \n\t}\n\t\n\tif(m==2||s==2||p==2) {\n\t\t\n\t\t\n\t\t\n\t\tchar c1 = S[0].charAt(1);\n\t\tchar c2 = S[1].charAt(1);\n\t\tchar c3 = S[2].charAt(1);\n\t\t\n\t\t\n\t\tif(c1==c2) {\n\t\t\tif(n1==n2) System.out.println(1);\n\t\t\telse if(d3==1||d3==2) System.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t}\n\t\tif(c1==c3) {\n\t\t\tif(n1==n3) System.out.println(1);\n\t\t\telse if(d4==1||d4==2) System.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t}\n\t\tif(c2==c3) {\n\t\t\tif(n2==n3) System.out.println(1);\n\t\t\telse if(d5==1||d5==2) System.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t}\n\t}\n\t\n\tif(m==1&s==1&p==1) System.out.println(2);\n\t\t\n\t\n\t\n}\n}\n", "complexity": "constant", "problem": "1191_B. Tokitsukaze and Mahjong", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\tstatic int 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\tString[] s = new String[2];\n\t\tfor(int i = 0; i < 2; i++){\n\t\t\ts[i] = scanner.next();\n\t\t}\n\t\tint n = s[0].length();\n\t\tchar[][] c = new char[2][n];\n\t\tfor(int i = 0; i < 2; i++){\n\t\t\tfor(int j = 0; j < n; j++){\n\t\t\t\tc[i][j] = s[i].charAt(j);\n\t\t\t}\n\t\t}\n\t\tint count = 0;\n\t\tfor(int i = 0; i < n-1; i++){\n\t\t\tif(c[0][i] == '0' && c[1][i] == '0' && c[0][i+1] == '0'){\n\t\t\t\tc[0][i] = 'X';\n\t\t\t\tc[1][i] = 'X';\n\t\t\t\tc[0][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(c[0][i] == '0' && c[1][i] == '0' && c[1][i+1] == '0'){\n\t\t\t\tc[0][i] = 'X';\n\t\t\t\tc[1][i] = 'X';\n\t\t\t\tc[1][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(c[0][i] == '0' && c[0][i+1] == '0' && c[1][i+1] == '0'){\n\t\t\t\tc[0][i] = 'X';\n\t\t\t\tc[0][i+1] = 'X';\n\t\t\t\tc[1][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(c[0][i+1] == '0' && c[1][i+1] == '0' && c[1][i] == '0'){\n\t\t\t\tc[1][i] = 'X';\n\t\t\t\tc[0][i+1] = 'X';\n\t\t\t\tc[1][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\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<Pair>{\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<Pair2> {\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", "complexity": "constant", "problem": "991_D. Bishwock", "from": "CODEFORCES"}
{"src": "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 Liavontsi Brechka\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        DEhabIEsheOdnaOcherednayaZadachaNaXor solver = new DEhabIEsheOdnaOcherednayaZadachaNaXor();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DEhabIEsheOdnaOcherednayaZadachaNaXor {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int c = 0;\n            int d = 0;\n\n            int prevSign = 0;\n            int nextSign;\n            boolean zeroOut = true;\n            for (int i = 29; i >= 0; i--) {\n                if (zeroOut) {\n                    print(c, d, out);\n                    prevSign = read(in);\n                }\n\n                print((1 << i) | c, (1 << i) | d, out);\n                nextSign = read(in);\n\n                if (prevSign == nextSign) {\n                    zeroOut = false;\n\n                    print((1 << i) | c, d, out);\n                    nextSign = read(in);\n\n                    if (nextSign < 0) {\n                        c = (1 << i) | c;\n                        d = (1 << i) | d;\n                    }\n                } else {\n                    zeroOut = true;\n\n                    if (nextSign < 0) c = (1 << i) | c;\n                    else d = (1 << i) | d;\n                }\n            }\n\n            out.printf(\"! %d %d\", c, d);\n            out.flush();\n        }\n\n        private void print(int c, int d, PrintWriter out) {\n            out.printf(\"? %d %d\\n\", c, d);\n            out.flush();\n        }\n\n        private int read(InputReader in) {\n            return in.nextInt();\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", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.net.Inet4Address;\nimport java.util.*;\n\npublic class l {\n    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    static long mod = (int) (1e9 + 7);\n    static int n;\n    static StringBuilder sol;\n\n    static class pair implements Comparable<pair> {\n        int L,R;\n        public pair( int x,int y) {\n            L=x;R=y;\n        }\n\n\n        public int compareTo(pair o) {\n            if (L!=o.L)return L-o.L;\n            return o.R-R;\n        }\n        public String toString(){\n            return L+\" \"+R;\n        }\n    }\n    static boolean is;\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        //FileWriter f = new FileWriter(\"C:\\\\Users\\\\Ibrahim\\\\out.txt\");\n        PrintWriter pw = new PrintWriter(System.out);\n        int m = sc.nextInt();\n        int n = sc.nextInt();\n        int q = sc.nextInt();\n        TreeSet<Integer>length= new TreeSet<>();\n        length.add(0);\n        length.add(n);\n        TreeSet<Integer>width= new TreeSet<>();\n        width.add(0);\n        width.add(m);\n        TreeMap<Integer,Integer>len= new TreeMap<>();\n        len.put(n,1);\n        TreeMap<Integer,Integer>wid= new TreeMap<>();\n        wid.put(m,1);\n        while (q-->0){\n            String t= sc.next();\n            if (t.equals(\"H\")) {\n                int x = sc.nextInt();\n                int k1 = length.ceiling(x);\n                int k2 = length.floor(x);\n                if (x != k1) {\n                    int s = k1 - k2;\n                    int con = len.get(s);\n                    if (con == 1) len.remove(s);\n                    else len.put(s, con - 1);\n                    len.put((k1 - x), len.getOrDefault((k1 - x), 0) + 1);\n                    len.put((x - k2), len.getOrDefault((x - k2), 0) + 1);\n                    length.add(x);\n                }\n            }\n            else {\n                int x = sc.nextInt();\n                int k1 = width.ceiling(x);\n                int k2 = width.floor(x);\n                if (x != k1) {\n                    int s = k1 - k2;\n                    //System.out.println(s+\" \"+k1+\" \"+k2);\n                    int con = wid.get(s);\n                    if (con == 1) wid.remove(s);\n                    else wid.put(s, con - 1);\n                    wid.put((k1 - x), wid.getOrDefault((k1 - x), 0) + 1);\n                    wid.put((x - k2), wid.getOrDefault((x - k2), 0) + 1);\n                    width.add(x);\n                }\n            }\n            pw.println(1l*len.lastKey()*wid.lastKey());\n        }\n\n        pw.flush();\n    }\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\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        public boolean ready() throws IOException {\n            return br.ready();\n        }\n\n\n    }\n\n}", "complexity": "nlogn", "problem": "527_C. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author caoash\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        BObtainingTheString solver = new BObtainingTheString();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BObtainingTheString {\n        public void solve(int testNumber, FastScanner br, PrintWriter pw) {\n            int n = br.nextInt();\n            String s = br.nextString();\n            String t = br.nextString();\n            char[] sarr = new char[n];\n            char[] tarr = new char[n];\n            int[] sAppear = new int[26];\n            int[] tAppear = new int[26];\n            for (int i = 0; i < s.length(); i++) {\n                sarr[i] = s.charAt(i);\n                tarr[i] = t.charAt(i);\n                sAppear[s.charAt(i) - 'a']++;\n                tAppear[t.charAt(i) - 'a']++;\n            }\n            for (int i = 0; i < 26; i++) {\n                if (sAppear[i] != tAppear[i]) {\n                    pw.println(-1);\n                    pw.close();\n                }\n            }\n            ArrayList<Integer> ans = new ArrayList<Integer>();\n            for (int i = 0; i < n; i++) {\n                char curr = tarr[i];\n                for (int j = i + 1; j < n; j++) {\n                    if (sarr[j] == curr) {\n                        for (int k = j; k > i; k--) {\n                            ans.add(k);\n                            char temp = sarr[k - 1];\n                            sarr[k - 1] = sarr[k];\n                            sarr[k] = temp;\n                        }\n                        break;\n                    }\n                }\n            }\n            pw.println(ans.size());\n            for (int e : ans) {\n                pw.print(e + \" \");\n            }\n            pw.close();\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        private FastScanner.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\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 interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1015_B. Obtaining the String", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class aaaaaaaaaaaaaaaa {\n\tpublic void run() throws Exception {\n\t\tScanner file = new Scanner(System.in);\n\t\tint a = file.nextInt(), b= file.nextInt(), c = file.nextInt(), n = file.nextInt();\n\t\ta -= c;\n\t\tb -= c;\n\t\tif (a < 0 || b < 0) System.out.println(-1);\n\t\telse {\n\t\t\tint x = a + b + c;\n\t\t\tif (x >= n) System.out.println(-1);\n\t\t\telse System.out.println(n - x);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew aaaaaaaaaaaaaaaa().run();\n\t}\n\n}", "complexity": "constant", "problem": "991_A. If at first you don't succeed...", "from": "CODEFORCES"}
{"src": "// discussed with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF915E {\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\tint n = Integer.parseInt(br.readLine());\n\t\tint q = Integer.parseInt(br.readLine());\n\t\tTreeMap<Integer, Integer> mp = new TreeMap<>();\n\t\tint ans = 0;\n\t\twhile (q-- > 0) {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tint l = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tint r = Integer.parseInt(st.nextToken());\n\t\t\tint t = Integer.parseInt(st.nextToken());\n\t\t\tMap.Entry<Integer, Integer> e;\n\t\t\tint l_, r_;\n\t\t\tif (t == 1) {\n\t\t\t\tif ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) >= l) {\n\t\t\t\t\tl_ = e.getKey();\n\t\t\t\t\tans -= r_ - l_;\n\t\t\t\t\tl = l_;\n\t\t\t\t\tr = Math.max(r, r_);\n\t\t\t\t}\n\t\t\t\twhile ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) <= r) {\n\t\t\t\t\tr_ = e.getValue();\n\t\t\t\t\tans -= r_ - l_;\n\t\t\t\t\tr = Math.max(r, r_);\n\t\t\t\t\tmp.remove(l_);\n\t\t\t\t}\n\t\t\t\tans += r - l;\n\t\t\t\tmp.put(l, r);\n\t\t\t} else {\n\t\t\t\tr_ = l;\n\t\t\t\tif ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) > l) {\n\t\t\t\t\tl_ = e.getKey();\n\t\t\t\t\tif (l_ < l)\n\t\t\t\t\t\tmp.put(l_, l);\n\t\t\t\t\telse\n\t\t\t\t\t\tmp.remove(l_);\n\t\t\t\t\tans -= r_ - l;\n\t\t\t\t}\n\t\t\t\twhile ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) < r) {\n\t\t\t\t\tr_ = e.getValue();\n\t\t\t\t\tmp.remove(l_);\n\t\t\t\t\tans -= r_ - l_;\n\t\t\t\t}\n\t\t\t\tif (r_ > r) {\n\t\t\t\t\tmp.put(r, r_);\n\t\t\t\t\tans += r_ - r;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(n - ans);\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "nlogn", "problem": "915_E. Physical Education Lessons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static String conv(String str) {\n\t\tboolean[] Arr = new boolean[26];\n\t\tfor (int i = 0; i < str.length(); i++) {\n\t\t\tArr[str.charAt(i) - 'a'] = true;\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < 26; i++) {\n\t\t\tif (Arr[i])\n\t\t\t\tsb.append((char) (i + 'a'));\n\t\t}\n\t\treturn \"\" + sb;\n\t}\n\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tScanner sc = new Scanner(System.in);\n\t\tHashSet<String> hs = new HashSet<String>();\n\t\tint[] Arr = new int[14];\n\t\tlong max = 0;\n\t\tfor (int i = 0; i < 14; i++) {\n\t\t\tArr[i] = sc.nextInt();\n\t\t}\n\n\t\tfor (int i = 0; i < 14; i++) {\n\t\t\tint[] arr = Arr.clone();\n\n\t\t\tlong sum = 0;\n\t\t\tint r = arr[i];\n\t\t\tarr[i] = 0;\n\t\t\tfor (int j = i + 1; j < arr.length && r > 0; j++) {\n\t\t\t\tarr[j]++;\n\t\t\t\tr--;\n\t\t\t}\n\t\t\tfor (int j = 0; j < arr.length; j++) {\n\t\t\t\tarr[j] +=( r / 14);\n\t\t\t\tif (j + 1 <= (r % 14)) {\n\t\t\t\t\tarr[j]++;\n\t\t\t\t}\n\t\t\t\tif (arr[j] % 2 == 0) {\n\t\t\t\t\tsum += arr[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, sum);\n\n\t\t}\n\t\tSystem.out.println(max);\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", "complexity": "constant", "problem": "975_B. Mancala", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\npublic class TaxiDriversAndLyft2 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tlong n = scanner.nextLong();\n\t\tlong m = scanner.nextLong();\n\t\tlong[] people = new long[(int) (n+m)];\n\t\tint[] taxiDrivers = new int[(int) (n+m)];\n\t\t\n\t\tfor(int i = 0;i< (n+m); i++) {\n\t\t\tpeople[i] = scanner.nextLong();\n\t\t}\n\t\t\n\t\tfor(int i = 0;i< (n+m); i++) {\n\t\t\ttaxiDrivers[i] = scanner.nextInt();\n\t\t}\n\t\t\n\t\tint lastTaxiDriverIndex = -1;\n\t\tlong[] riderCountArray = new long[(int) (m)];\n\t\tlong[] a1 = new long[(int)n];\n\t\tlong[] b1 = new long[(int)m];\n\t\t\n\t\tint j=0, k=0;\n\t\tfor(int i = 0;i< (n+m); i++) {\t\n\t\t\tif(taxiDrivers[i] == 0) {\n\t\t\t\ta1[j] = people[i];\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse  {\n\t\t\t\tb1[k] = people[i];\n\t\t\t\tk++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint l = 0, q=0;\n\t\tfor(int i=0;i<j;i++) {\n\t\t\twhile ((l<m-1 && m>1) && Math.abs(a1[i] - b1[l]) > Math.abs(a1[i] - b1[l+1])) {\n\t\t\t\tl++; \n\t\t\t}\n\t\t\t\n\t\t\triderCountArray[l]++;\t\n\t\t}\n\t\t\n\t\tfor(int i = 0;i< (m); i++) {\n\t\t\tSystem.out.print(riderCountArray[i]+\" \");\n\t\t}\n\t} \n}\n", "complexity": "linear", "problem": "1075_B. Taxi drivers and Lyft", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class cf {\n\n\tstatic class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner() {\n            try {\n                br = new BufferedReader(new InputStreamReader(System.in));\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e){e.printStackTrace();}\n        }\n\n        public String next() {\n            if (st.hasMoreTokens()) return 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 static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int n = sc.nextInt();\n        pw.println(n/2+1);\n        pw.close();\n    }\n}", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\twhile(sc.hasNext()) {\n\t\t\tint n=sc.nextInt();\n\t\t\tString s=sc.next();\n\t\t\tint sum=0;\n\t\t\tfor(int i=0;i<s.length();i++) {\n\t\t\t\tif(s.charAt(i)=='+') {\n\t\t\t\t\tsum++;\n\t\t\t\t}\n\t\t\t\tif(s.charAt(i)=='-'&&sum!=0) {\n\t\t\t\t\tsum--;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1159_A. A pile of stones", "from": "CODEFORCES"}
{"src": "\nimport 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.Scanner;\nimport java.util.StringTokenizer;\n\npublic class CF_1029E_Tree_with_Small_Distances {\n\tstatic ArrayList<Integer> adj[];\n\tstatic int dist[];\n\tstatic boolean visitParent[];\n\tstatic int ans=0;\n public static void main(String[] args) throws IOException {\n\tScanner sc = new Scanner(System.in);\n\tint n  =sc.nextInt();\n\tadj=new ArrayList[n+1];\n\tdist = new int[n+1];\n\tvisitParent = new boolean[n+1];\n\tfor(int i=0;i<=n;i++) adj[i]=new ArrayList<Integer>();\n\tint max=0;\n\t//first contribution\n\tfor(int i=1;i<n;i++){\n\t\tint u = sc.nextInt(),v=sc.nextInt();\n\t\tadj[u].add(v);\n\t\tadj[v].add(u);\n\t}\n\tdist[1]=0;\n\tdfs(1,1);\n System.out.println(ans);\n \n \n }\nprivate static void dfs(int i , int j) {\n\t// TODO Auto-generated method stub\n\tboolean f = false;\n\tfor(int k=0;k<adj[i].size();k++){\n\t\tint x = adj[i].get(k);\n\t\tif(x!=j){\n\t\t\tdist[x]=dist[i]+1;\n\t\t\tdfs(x,i);\n\t\t\tif(visitParent[x])\n\t\t\t\tf=true;\n\t\t}\n\t}\n\t//System.out.println(Arrays.toString(dist));\n\tif(dist[i]>2&&!visitParent[j]&&!f&&!visitParent[i]){\n\t\tvisitParent[j]=true;\n\t\tans++;\n\t\tfor(int v=0;v<adj[i].size();v++){\n\t\t\t\n\t\t}\n\t}\n\t\n}\nstatic class Scanner \n{\n    StringTokenizer st;\n    BufferedReader br;\n\n    public Scanner(InputStream s){  br = 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 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\n    public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n    public long nextLong() throws IOException {return Long.parseLong(next());}\n\n    public String nextLine() throws IOException {return br.readLine();}\n\n    public boolean ready() throws IOException {return br.ready(); }\n\n\n}\n\t\n}\n\n", "complexity": "linear", "problem": "1029_E. Tree with Small Distances", "from": "CODEFORCES"}
{"src": "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 OlyaAndMagicalSquare {\n    void solve() {\n        long[] dp = new long[32];\n        dp[0] = 0;\n        for (int i = 1; i < 32; i++) {\n            dp[i] = 4 * dp[i - 1] + 1;\n        }\n        \n        int T = in.nextInt();\n        L:\n        while (T-- > 0) {\n            int n = in.nextInt(); long k = in.nextLong();\n            \n            if (n > 31) {\n                out.println(\"YES \" + (n - 1));\n                continue;\n            }\n            \n            long tot = 0;\n            for (int a = n - 1; a >= 0; a--) {\n                k -= (1L << (n - a)) - 1;\n                if (k < 0) break;\n                if (k == 0) {\n                    out.println(\"YES \" + a);\n                    continue L;\n                }\n                long limit = (1L << (n + 1 - a)) - 3;\n                if (k <= tot || dp[a] > 0 && (k - tot + dp[a] - 1) / dp[a] <= limit) {\n                    out.println(\"YES \" + a);\n                    continue L;\n                }\n                tot += dp[a] * limit;\n            }\n            out.println(\"NO\");\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 OlyaAndMagicalSquare().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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main{\npublic static void main(String[] args){\n Scanner s= new Scanner(System.in);\n int n=s.nextInt();StringBuilder sb=new StringBuilder();\n long[] a=new long[n/2];\n for(int i=0;i<n/2;i++){\n                  a[i]=s.nextLong();\n }int j=0;long[] a2=new long[n/2];long[] a1=new long[n/2];\n a1[j]=a[a.length-1]/2;\n a2[j]=a[a.length-1]-a[a.length-1]/2;\n for(int i=(n-1)/2-1;i>=0;i--){\n //    a1[j]=a[i]/2;a2[j++]=a[i]-a[i]/2;\n    long n1=a1[j];\n    if((a[i]-n1)<a2[j]){\n      a2[j+1]=a2[j++];a1[j]=a[i]-a2[j];                      \n     }else{a1[++j]=n1;a2[j]=a[i]-n1;}\n }int k=0;//int[] ans=new int[2*n];\n for(int i=(n-1)/2;i>=0;i--)\n   sb.append(a1[i]+\" \");\n  for(int i=0;i<n/2;i++)\n    sb.append(a2[i]+\" \");\n            System.out.println(sb.toString());     \n}\n}", "complexity": "linear", "problem": "1093_C. Mishka and the Last Exam", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Pizza {\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong num = sc.nextLong() + 1;\n\t\tsc.close();\n\t\tSystem.out.println(num % 2 == 0 || num == 1 ? num / 2 : num);\n\t}\n\t\n}\n", "complexity": "constant", "problem": "979_A. Pizza, Pizza, Pizza!!!", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tSolution solution = new Solution();\n\t\tSystem.out.println(solution.solve());\n\t}\n\n\tprivate int solve() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\n\t\tint[] a = new int[m];\n\t\tfor (int i = 0; i < m; ++i) a[i] = in.nextInt();\n\n\t\tif (n > m) return 0;\n\n\t\tMap<Integer, Integer> map = new HashMap<>();\n\t\tfor (int k: a) map.put(k, map.getOrDefault(k, 0) + 1);\n\n\t\tList<Integer> keySet = new ArrayList<>(map.keySet());\n\t\tint end = m / n;\n\n\t\tkeySet.sort((u, v) -> -Integer.compare(u, v));\n\t\tdo {\n\t\t\tint count = 0;\n\t\t\tfor (int k: keySet) {\n\t\t\t\tcount += map.get(k) / end;\n\t\t\t\tif (count >= n) return end;\n\t\t\t}\n\t\t} while (--end > 0);\n\n\t\treturn 0;\n\t}\n}\n", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Cf1017A {\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 result = 1;\n        int thomasSum = 0;\n        StringTokenizer stk;\n        stk = new StringTokenizer(br.readLine());\n        int first = Integer.parseInt(stk.nextToken());\n        int second = Integer.parseInt(stk.nextToken());\n        int third = Integer.parseInt(stk.nextToken());\n        int fourth = Integer.parseInt(stk.nextToken());\n        thomasSum = first + second + third + fourth;\n        int tmp;\n        for (int i = 1; i < n; i++) {\n            stk = new StringTokenizer(br.readLine());\n            first = Integer.parseInt(stk.nextToken());\n            second = Integer.parseInt(stk.nextToken());\n            third = Integer.parseInt(stk.nextToken());\n            fourth = Integer.parseInt(stk.nextToken());\n            tmp = first + second + third + fourth;\n            if (tmp > thomasSum)\n                result++;\n        }\n        System.out.println(result);\n    }\n}", "complexity": "linear", "problem": "1017_A. The Rank", "from": "CODEFORCES"}
{"src": "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\tlong n = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tSystem.out.println(solve(n, k));\n\n\t\tsc.close();\n\t}\n\n\tstatic long solve(long n, long k) {\n\t\treturn Math.max(0, Math.min(n, k - 1) - ((k + 2) / 2) + 1);\n\t}\n}\n", "complexity": "constant", "problem": "1023_B. Pair of Toys", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C {\n\n\tstatic StringBuilder st = new StringBuilder();\n\n\t\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\n\t\tPoint [] square = new Point [4] ; \n\t\tPoint [] rotSquare = new Point[4] ; \n\t\t\n\t\tfor(int i = 0 ; i < 4 ;i++)\n\t\t\tsquare[i] = new Point(sc.nextInt() , sc.nextInt());\n\t\t\n\t\tfor(int i = 0 ; i < 4 ;i++)\n\t\t\trotSquare[i] = new Point(sc.nextInt() , sc.nextInt());\n\t\t\n\t\tboolean can = false ; \n\t\t\n\t\tfor(int x = -100 ; x <= 100 ; x++)\n\t\t\tfor(int y = -100 ; y <= 100 ; y++)\n\t\t\t\tcan |= inside(new Point(x , y), square) & inside(new Point (x , y), rotSquare);\n\t\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\tout.println(can ? \"YES\" : \"NO\");\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\n\t}\n\tstatic int crossProduct(Point a , Point b)\n\t{\n\t\tint ans = a.x * b.y - a.y * b.x ; \n\t\t\n\t\tif(ans < 0)return -1 ;\n\t\tif(ans == 0) return 0 ;\n\t\treturn 1 ; \n\t}\n\t\n\tstatic boolean inside(Point a , Point [] points)\n\t{\n\t\tboolean allPos = true ; \n\t\tboolean allNeg = true ; \n\t\t\n\t\tfor(int i = 0 ; i < 4 ; i++)\n\t\t{\n\t\t\tPoint v1 = new Point (points[i].x - a.x , points[i].y - a.y) ; \n\t\t\tPoint v2 = new Point (points[(i + 1) % 4].x - a.x , points[(i + 1) % 4].y - a.y) ; \n\t\t\t\n\t\t\tallPos &= crossProduct(v1, v2) >= 0;\n\t\t\tallNeg &= crossProduct(v1, v2) <= 0;\n\t\t}\n\t\treturn allPos | allNeg ; \n\t\t\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\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\n\t\t\treturn st.nextToken();\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}\n\n\tstatic void shuffle(int[] a) {\n\t\tint n = a.length;\n\t\tfor (int i = 0; i < n; i++) {\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}", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "    import jdk.nashorn.internal.objects.NativeArray;\n\n    import javax.swing.JOptionPane ;\n    import javax.swing.plaf.basic.BasicInternalFrameTitlePane;\n    import java.sql.SQLSyntaxErrorException;\n    import java.util.Arrays;\n    import java.util.Scanner;\n    import java.util.Vector;\n\n\n    import static jdk.nashorn.internal.objects.NativeArray.sort;\n    import static jdk.nashorn.internal.runtime.ScriptObject.toPropertyDescriptor;\n\n    public class Dialog1 {\n        private static int n ;\n        private static String s ;\n        private static char[] a;\n        public static void main(String[] args) {\n            Scanner input = new Scanner(System.in);\n            n = input.nextInt() ;\n            s = input.next() ;\n            a = s.toCharArray();\n            for(int i = 0 ; i < 200 ; ++i) {\n                int cur = i ;\n                boolean fl = true ;\n                for(int j = 0 ; j < n ; ++j) {\n                    if(a[j] == '+')\n                        ++cur ;\n                    else\n                        --cur ;\n                    if(cur < 0)\n                        fl = false ;\n                }\n                if(fl) {\n                    System.out.print(cur);\n                    return ;\n                }\n            }\n        }\n    }", "complexity": "linear", "problem": "1159_A. A pile of stones", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n    static class Data{\n        int x,i;\n        Data(int x,int i){\n            this.x = x;\n            this.i = i;\n        }\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(\"\\\\s\");\n        int N = Integer.parseInt(s[0]);\n        int K = Integer.parseInt(s[1]);\n        s = br.readLine().split(\"\\\\s\");\n        int[] arr = new int[N];\n        for(int i=0;i<N;++i) arr[i] = Integer.parseInt(s[i]);\n        solve(N,K,arr);   \n    }\n    \n    private static void solve(int N,int K,int[] arr){\n       PriorityQueue<Data> pq = new PriorityQueue<Data>(2000,(a,b) -> a.x - b.x == 0 ? b.i - a.i : b.x - a.x);\n       for(int i=0;i<arr.length;++i){\n           pq.offer(new Data(arr[i],i));\n       }\n       \n       int tot_sum = 0;\n       List<Integer> ls = new ArrayList<>();\n       Set<Integer> set = new HashSet<>();\n       \n       for(int i=1;i<=K;++i){\n           Data t = pq.poll();\n           tot_sum += t.x;\n           set.add(t.i);\n       }\n       int last = -1;\n       for(int i =0;i<arr.length;++i){\n           if(set.contains(i)){\n               K--;\n               //System.out.println(i);\n               if(K == 0) ls.add(arr.length-last-1);\n               else ls.add(i-last);\n               last = i;\n           }\n       }\n       \n       System.out.println(tot_sum);\n       int size = ls.size();\n       for(int i=0;i<size;++i){\n           System.out.print(ls.get(i) + \" \");\n       }\n    }\n}", "complexity": "nlogn", "problem": "1006_B. Polycarp's Practice", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MainG {\n\tstatic StdIn in = new StdIn();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic long M=(long)1e9+7;\n\t\n\tpublic static void main(String[] args) {\n\t\tchar[] cs = in.next().toCharArray();\n\t\tint n=cs.length;\n\t\tint[] x = new int[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\tx[i]=cs[i]-'0';\n\t\tlong[] dp1 = new long[n+1];\n\t\tfor(int i=0; i<n; ++i) \n\t\t\tdp1[i+1]=(x[i]+dp1[i]*10)%M;\n\t\tlong ans=0;\n\t\tfor(int d1=1; d1<=9; ++d1) {\n\t\t\tlong[][] dp2 = new long[2][n+1];\n\t\t\tfor(int i=0; i<n; ++i) {\n\t\t\t\tdp2[0][i+1]=x[i]>=d1?(10*dp2[0][i]+1)%M:dp2[0][i];\n\t\t\t\tfor(int d2=0; d2<x[i]; ++d2)\n\t\t\t\t\tdp2[1][i+1]=((d2>=d1?10*(dp2[0][i]+dp2[1][i])+dp1[i]+1:dp2[0][i]+dp2[1][i])+dp2[1][i+1])%M;\n\t\t\t\tfor(int d2=x[i]; d2<=9; ++d2)\n\t\t\t\t\tdp2[1][i+1]=((d2>=d1?10*dp2[1][i]+dp1[i]:dp2[1][i])+dp2[1][i+1])%M;\n\t\t\t}\n\t\t\tans+=dp2[0][n]+dp2[1][n];\n\t\t}\n\t\tout.println(ans%M);\n\t\tout.close();\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.HashMap;\n\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    } \n    \n    \n    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    \n    public static void main(String args[])\n    {\n        Reader sc=new Reader();\n        PrintWriter out=new PrintWriter(System.out);\n        int n=sc.i();\n        String s1=sc.s();\n        String s2=sc.s();\n        int pos1=-1;\n        int pos2=-1;\n        int arr[][][]=new int[100][100][2];\n        for(int i=0;i<n;i++)\n        {\n            if(s1.charAt(i)!=s2.charAt(i))\n            {\n                if(arr[s2.charAt(i)-97][s1.charAt(i)-97][0]==1)\n                {\n                    pos2=i;\n                    pos1=arr[s2.charAt(i)-97][s1.charAt(i)-97][1];\n                    break;\n                }\n                arr[s1.charAt(i)-97][s2.charAt(i)-97][0]=1;\n                arr[s1.charAt(i)-97][s2.charAt(i)-97][1]=i;\n            }\n        }\n        int ham=0;\n        for(int i=0;i<n;i++)\n        {\n            if(s1.charAt(i)!=s2.charAt(i))\n            ham++;\n        }\n        if(pos1!=-1&&pos2!=-1)\n        {\n            System.out.println(ham-2);\n            System.out.println(pos1+1+\" \"+(pos2+1));\n            System.exit(0);\n        }\n        \n        int arr1[][]=new int[100][2];\n        int arr2[][]=new int[100][2];\n        for(int i=0;i<n;i++)\n        {\n            if(s1.charAt(i)!=s2.charAt(i))\n            {\n                if(arr1[s1.charAt(i)-97][0]==1)\n                {\n                    pos2=i;\n                    pos1=arr1[s1.charAt(i)-97][1];\n                    break;\n                }\n                if(arr2[s2.charAt(i)-97][0]==1)\n                {\n                    pos2=i;\n                    pos1=arr2[s2.charAt(i)-97][1];\n                    break;\n                }\n                arr1[s2.charAt(i)-97][0]=1;\n                arr1[s2.charAt(i)-97][1]=i;\n                arr2[s1.charAt(i)-97][0]=1;\n                arr2[s1.charAt(i)-97][1]=i;\n            }\n        }\n        if(pos1!=-1&&pos2!=-1)\n        {\n            System.out.println(ham-1);\n            System.out.println(pos1+1+\" \"+(pos2+1));\n            System.exit(0);\n        }\n        System.out.println(ham);\n        System.out.println(pos1+\" \"+pos2);\n    }\n}", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class CF1068A {\n\tpublic CF1068A() {\n\t\tFS scan = new FS();\n\t\tlong n = scan.nextLong(), m = scan.nextLong(), k = scan.nextLong(), l = scan.nextLong();\n\t\tlong ceil = (k + l + m - 1) / m;\n\t\tif(k + l <= n && ceil * m <= n) System.out.println(ceil);\n\t\telse System.out.println(-1);\n\t}\n\tclass FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tpublic String next() {\n\t\t\twhile(!st.hasMoreTokens()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\t\tcatch(Exception e) { e.printStackTrace(); }\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\tpublic long nextLong() { return Long.parseLong(next()); }\n\t}\n\tpublic static void main(String[] args) { new CF1068A(); }\n}\n", "complexity": "constant", "problem": "1068_A. Birthday", "from": "CODEFORCES"}
{"src": "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 S=Integer.parseInt(s1[1]);\n            if(S%n==0)\n             System.out.println(S/n);\n            else\n             System.out.println(S/n+1);\n      }\n}", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class helloWorld \n{\n\tpublic static void main(String[] args) \n\t{\t\t\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\t\tint n = in.nextInt();\n\n\t\tint ans = n - (a + b - c);\n\t\tif(ans < 1 || a >= n || b >= n || c > a || c > b)\n\t\t\tans = -1;\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\tin.close();\n\t}\n}", "complexity": "constant", "problem": "991_A. If at first you don't succeed...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n\t{\t\n\t\tclass node{\n\t\tint data;\n\t\tnode next;\n\t\tpublic node(int val){\n\t\t\tdata=val;\n\t\t\tnext=null;\n\t\t}\n\t}\n\tclass linkedlist{\n\t\tnode start;\n\t\tnode end;\n\t\tint size;\n\t\tint turn;\n\t\tpublic linkedlist(){\n\t\t\tstart=null;\n\t\t\tend=null;\n\t\t\tsize=0;\n\t\t}\n\t\tvoid add(int val){\n\t\t\tif(size==0){\n\t\t\t\tnode t=new node(val);\n\t\t\t\tstart=t;\n\t\t\t\tend=t;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnode t=new node(val);\n\t\t\t\tend.next=t;\n\t\t\t\tend=end.next;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t}\n\t\tvoid myfunc(){\n\t\t\tif(start.data>start.next.data){\n\t\t\t\t// System.out.println(\"me ni hu\");\n\t\t\t\tnode t=new node(start.next.data);\n\t\t\t\tstart.next=start.next.next;\n\t\t\t\tend.next=t;\n\t\t\t\tend=end.next;\n\t\t\t}\n\t\t\telse{\n\t\t\t\t// System.out.println(\"me hu\");\n\t\t\t\tint t=start.data;\n\t\t\t\tstart=start.next;\n\t\t\t\tadd(t);\n\t\t\t\tsize--;\n\t\t\t}\n\t\t}\n\t\tint findmax(){\n\t\t\tint m=0;\n\t\t\tnode temp=start;\n\t\t\tfor(int i=0;i<size;i++){\n\t\t\t\tif(temp.data>m){\n\t\t\t\t\tm=temp.data;\n\t\t\t\t}\n\t\t\t\ttemp=temp.next;\n\t\t\t}\n\t\t\treturn m;\n\t\t}\n\t\tvoid display(){\n\t\t\tnode temp=start;\n\t\t\tfor(int i=0;i<size;i++){\n\t\t\t\tSystem.out.print(temp.data+\" \");\n\t\t\t\ttemp=temp.next;\n\t\t\t}\n\t\t\tSystem.out.println(\"\");\n\t\t}\n\t}\n\tlinkedlist l;\n\tpublic Main(){\n\t\tl=new linkedlist();\n\t}\n\tpublic static void main(String [] argv) throws IOException\n\t{\n\t\tBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\t\tMain ma=new Main();\n\t\tString[] l1=in.readLine().split(\" \");\n\t\tint n=Integer.parseInt(l1[0]);\n\t\tint q=Integer.parseInt(l1[1]);\n\t\tString[] ar=in.readLine().split(\" \");\n\t\tint a1=Integer.parseInt(ar[0]);\n\t\tint b1=Integer.parseInt(ar[1]);\n\t\tfor(int i=0;i<n;i++){\n\t\t\tma.l.add(Integer.parseInt(ar[i]));\n\t\t}\n\t\tint m=ma.l.findmax();\n\t\tint[][] pair=new int[n][2];\n\t\tint t=0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(ma.l.start.data==m)\n\t\t\t\tbreak;\n\t\t\tma.l.myfunc();\n\t\t\tpair[t][0]=ma.l.start.data;\n\t\t\tpair[t][1]=ma.l.start.next.data;\n\t\t\tt++;\n\t\t}\n\t\tint rl[]=new int[n];\n\t\tnode temp=ma.l.start;\n\t\tfor(int i=0;i<n;i++){\n\t\t\trl[i]=temp.data;\n\t\t\ttemp=temp.next;\n\t\t}\n\t\tfor(int i=0;i<q;i++){\n\t\t\tlong a=Long.parseLong(in.readLine());\n\t\t\tif(a==1){\n\t\t\t\tSystem.out.println(a1 + \" \" + b1);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(a<=t+1){\n\t\t\t\t\tSystem.out.println(pair[(int)(a-2)][0]+\" \"+pair[(int)(a-2)][1]);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif((a-t)%(n-1)==0){\n\t\t\t\t\t\tSystem.out.println(rl[0]+\" \"+rl[n-1]);\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tSystem.out.println(rl[0]+\" \"+rl[(int)((a-t)%(n-1))]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1179_A. Valeriy and Deque", "from": "CODEFORCES"}
{"src": "/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License.  You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.StringJoiner;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class Test {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        String[] line = reader.readLine().split(\" \");\n        int w = Integer.valueOf(line[0]);\n        int h = Integer.valueOf(line[1]);\n        int n = Integer.valueOf(line[2]);\n\n        Request[] requests = new Request[n];\n\n        for (int i = 0; i < n; i++) {\n            line = reader.readLine().split(\" \");\n            requests[i] = new Request(line[0], Integer.valueOf(line[1]));\n        }\n\n        for (long e : solve(h, w, requests))\n            System.out.println(e);\n\n//        int w = 200000, h = 200000, n = 400000;\n//        Request[] requests = generate(w, h, n);\n//\n//        long start = System.currentTimeMillis();\n//        solve(h, w, requests);\n//        long end = System.currentTimeMillis();\n//\n//        System.out.println(\"Time: \" + (end - start) + \" ms\");\n    }\n\n    private static Request[] generate(int w, int h, int n) {\n        Request[] requests = new Request[n];\n        Random rnd = new Random();\n\n        for (int i = 0; i < n; i++) {\n            requests[i] = rnd.nextBoolean() ? new Request(\"V\", rnd.nextInt(w)) : new Request(\"H\", rnd.nextInt(h));\n        }\n\n        return requests;\n    }\n\n    private static long[] solve(int h, int w, Request[] requests) {\n        TreeSet<Integer> hTree = new TreeSet<>();\n        TreeSet<Integer> wTree = new TreeSet<>();\n\n        Queue<CoordinateWithSize> hHeap = new PriorityQueue<>();\n        Queue<CoordinateWithSize> wHeap = new PriorityQueue<>();\n\n        hTree.add(0);\n        hTree.add(h);\n        wTree.add(0);\n        wTree.add(w);\n\n        hHeap.add(new CoordinateWithSize(0, h));\n        wHeap.add(new CoordinateWithSize(0, w));\n\n        long[] res = new long[requests.length];\n        for (int i = 0; i < requests.length; i++) {\n            Request request = requests[i];\n\n            switch (request.type) {\n                case \"H\": {\n                    if (!hTree.contains(request.coordinate)) {\n                        int higher = hTree.higher(request.coordinate);\n                        int lower = hTree.lower(request.coordinate);\n\n                        hHeap.add(new CoordinateWithSize(lower, request.coordinate - lower));\n                        hHeap.add(new CoordinateWithSize(request.coordinate, higher - request.coordinate));\n\n                        hTree.add(request.coordinate);\n                    }\n\n                    break;\n                }\n                case \"V\": {\n                    if (!wTree.contains(request.coordinate)) {\n                        int higher = wTree.higher(request.coordinate);\n                        int lower = wTree.lower(request.coordinate);\n\n                        wHeap.add(new CoordinateWithSize(lower, request.coordinate - lower));\n                        wHeap.add(new CoordinateWithSize(request.coordinate, higher - request.coordinate));\n\n                        wTree.add(request.coordinate);\n                    }\n\n                    break;\n                }\n                default:\n                    throw new IllegalStateException(\"Unknown type [type=\" + request.type + \"]\");\n            }\n\n            while (true) {\n                CoordinateWithSize c = hHeap.peek();\n                if (hTree.higher(c.coordinate) - c.coordinate == c.size)\n                    break;\n                hHeap.remove();\n            }\n\n            while (true) {\n                CoordinateWithSize c = wHeap.peek();\n                if (wTree.higher(c.coordinate) - c.coordinate == c.size)\n                    break;\n                wHeap.remove();\n            }\n\n            res[i] = 1L * hHeap.peek().size * wHeap.peek().size;\n        }\n\n        return res;\n    }\n\n    private static class CoordinateWithSize implements Comparable<CoordinateWithSize> {\n\n        private final int coordinate;\n\n        private final int size;\n\n        public CoordinateWithSize(int coordinate, int size) {\n            this.coordinate = coordinate;\n            this.size = size;\n        }\n\n        @Override public int compareTo(CoordinateWithSize o) {\n            return Integer.compare(o.size, size);\n        }\n    }\n\n    private static class Request {\n\n        private final String type;\n\n        private final int coordinate;\n\n        public Request(String type, int coordinate) {\n            this.type = type;\n            this.coordinate = coordinate;\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "527_C. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Three{\n    public static void main(String[] args) {\n\tScanner in = new Scanner (System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\n\tpair[] points = new pair [3];\n\tfor (int i = 0; i < 3; ++i) {\n\t    int x = in.nextInt();\n\t    int y = in.nextInt();\n\t    points[i] = new pair (x, y);\n\t}\n\n\tArrays.sort(points);\n\n\tint MaxY = Math.max(Math.max(points[0].y, points[1].y), points[2].y);\n\tint MinY = Math.min(Math.min(points[0].y, points[1].y), points[2].y);\n\n\tout.println(MaxY - MinY + points[2].x - points[0].x + 1);\n\tfor (int i = MinY; i <= MaxY; ++i)\n\t    out.println(points[1].x + \" \" + i);\n\tfor (int i = points[0].x; i < points[1].x; ++i)\n\t    out.println(i + \" \" + points[0].y);\n\tfor (int i = points[1].x + 1; i <= points[2].x; ++i)\n\t    out.println(i + \" \" + points[2].y);\n\t\n\tout.close();\n    }\n\n    public static class pair implements Comparable<pair> {\n\tint x, y;\n\tpublic pair (int x_, int y_) {\n\t    x = x_; y = y_;\n\t}\n\n\t@Override\n\tpublic int compareTo(pair o) {\n\t    return x - o.x;\n\t}\n    }\n}\n", "complexity": "nlogn", "problem": "1086_A. Connect Three", "from": "CODEFORCES"}
{"src": "    import java.util.Scanner;\n\n    public class Sasha1113A {\n\n        static int solution(int n, int v){\n            int count;\n            if(v>=n)\n                return n-1;\n            else{\n                count = (v-1) + ((n-v)*(n-v+1))/2;\n            }\n            return count;\n        }\n\n        public static void main(String[] args){\n            Scanner scan = new Scanner(System.in);\n            int n = scan.nextInt();\n            int v = scan.nextInt();\n\n            System.out.print(solution(n, v));\n        }\n    }\n", "complexity": "constant", "problem": "1113_A. Sasha and His Trip", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.*;\npublic class CF1003E{\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        int n = Integer.parseInt(s[0]);\n        int d = Integer.parseInt(s[1]);\n        int k = Integer.parseInt(s[2]);\n        StringBuffer sb = new StringBuffer();\n        int[] rem = new int[n];\n        int[] deg = new int[n];\n        int i = 0;\n        if(k == 1){\n            if(n <= 2){\n\n            }else{\n                System.out.println(\"NO\");\n                return;\n            }\n        }\n        for(i=0;i<d;i++){\n            if(i>=n-1){\n                System.out.println(\"NO\");\n                return;\n            }\n            sb.append((i+1) +\" \" + (i+2)+\"\\n\");\n            rem[i] = Math.min(i, d-i);\n            deg[i]++;\n            if(i+1<n)\n            deg[i+1]++;\n        }\n        if(i<n){\n            rem[i] = 0;\n            deg[i] = 1;\n        }\n        i++;\n        int j  = 0;\n        for(;i<n;i++){\n            //For all remaining Nodes\n            while(true){\n                if(j>=n){\n                    System.out.println(\"NO\");\n                    return;\n                }\n                if(rem[j] > 0 && deg[j]<k){\n                    deg[j]++;\n                    rem[i] = rem[j] - 1;\n                    sb.append((j+1)+\" \"+(i+1)+\"\\n\");\n                    deg[i]++;\n                    break;\n                }else{\n                    j++;\n                }\n            }\n        }\n        System.out.println(\"YES\");\n        System.out.println(sb);\n    }\n}\n", "complexity": "quadratic", "problem": "1003_E. Tree Constructing", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[] wide = new int[n], sta = new int[n];\n        HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();\n        for (int i = 0; i < n; i++) {\n        \twide[i] = sc.nextInt();\n        \thm.put(wide[i], i + 1);\n        }\n        Util.sort(wide);\n        sc.nextLine();\n        String s = sc.nextLine();\n        int tp = 0, pos = 0;\n        StringBuilder out = new StringBuilder();\n        for (int i = 0; i < s.length(); i++) {\n        \tint t;\n        \tif (s.charAt(i) == '0') {\n        \t\tt = wide[pos++];\n        \t\tsta[tp++] = t;\n        \t} else t = sta[--tp];\n        \tout.append(hm.get(t) + \" \");\n        }\n        System.out.println(out.toString());\n        sc.close();\n    }\n    public static class Util {\n    \t\n    \tpublic static <T extends Comparable<T> > void merge_sort(T[] a) {\n    \t\tObject[] aux = new Object[a.length];\n    \t\tmerge_sort0(a, aux, 0, a.length);\n    \t}\n    \t\n    \tpublic static <T extends Comparable<T> > void merge_sort(T[] a, int l, int r) {\n    \t\tObject[] aux = new Object[a.length];\n    \t\tmerge_sort0(a, aux, l, r);\n    \t}\n    \t\n    \t@SuppressWarnings(\"unchecked\")\n    \tprivate static <T extends Comparable<T> > void merge_sort0(T[] a, Object[] temp, int l, int r) {\n    \t\tif (l + 1 == r) return;\n    \t\tint mid = (l + r) >> 1;\n    \t\tmerge_sort0(a, temp, l, mid);\n    \t\tmerge_sort0(a, temp, mid, r);\n    \t\tint x = l, y = mid, c = l;\n    \t\twhile (x < mid || y < r) {\n    \t\t\tif (y == r || (x < mid && a[x].compareTo(a[y]) <= 0)) temp[c++] = a[x++];\n    \t\t\telse temp[c++] = a[y++];\n    \t\t}\n    \t\tfor (int i = l; i < r; i++) a[i] = (T)temp[i];\n    \t}\n    \t\n    \tstatic final Random RAN = new Random();\n    \t\n    \tpublic static <T extends Comparable<T> > void quick_sort(T[] a) {\n    \t\tquick_sort0(a, 0, a.length);\n    \t}\n    \t\n    \tpublic static <T extends Comparable<T> > void quick_sort(T[] a, int l, int r) {\n    \t\tquick_sort0(a, l, r);\n    \t}\n    \t\n    \tprivate static <T extends Comparable<T> > void quick_sort0(T[] a, int l, int r) {\n    \t\tif (l + 1 >= r) return;\n    \t\tint p = l + RAN.nextInt(r - l);\n    \t\tT t = a[p]; a[p] = a[l]; a[l] = t;\n    \t\tint x = l, y = r - 1;\n    \t\twhile (x < y) {\n    \t\t\twhile (x < y && a[y].compareTo(t) > 0) --y;\n    \t\t\twhile (x < y && a[x].compareTo(t) < 0) ++x;\n    \t\t\tif (x < y) {\n    \t\t\t\tT b = a[x]; a[x] = a[y]; a[y] = b;\n    \t\t\t\t++x; --y;\n    \t\t\t}\n    \t\t}\n    \t\tquick_sort0(a, l, y + 1);\n    \t\tquick_sort0(a, x, r);\n    \t}\n    \t\n    \tstatic final int BOUND = 8;\n    \t\n    \tpublic static void bucket_sort(int[] a) {\n    \t\tbucket_sort(a, 0, a.length);\n    \t}\n    \t\n    \tpublic static void bucket_sort(int[] a, int l, int r) {\n    \t\tint[] cnt = new int[1 << BOUND], b = new int[r - l + 1];\n    \t\tint y = 0;\n    \t\tfor (int i = l; i < r; i++) ++cnt[a[i] & (1 << BOUND) - 1];\n    \t\twhile (y < Integer.SIZE) {\n    \t\t\tfor (int i = 1; i < 1 << BOUND; i++) cnt[i] += cnt[i - 1];\n    \t\t\tfor (int i = r - 1; i >= l; i--) b[--cnt[a[i] >> y & (1 << BOUND) - 1]] = a[i];\n    \t\t\ty += BOUND;\n    \t\t\tArrays.fill(cnt, 0);\n    \t\t\tfor (int i = l; i < r; i++) {\n    \t\t\t\ta[i] = b[i - l];\n    \t\t\t\t++cnt[a[i] >> y & (1 << BOUND) - 1];\n    \t\t\t}\n    \t\t}\n    \t}\n    \t\n    \tpublic static void bucket_sort(long[] a) {\n    \t\tbucket_sort(a, 0, a.length);\n    \t}\n    \t\n    \tpublic static void bucket_sort(long[] a, int l, int r) {\n    \t\tint[] cnt = new int[1 << BOUND];\n    \t\tlong[] b = new long[r - l + 1];\n    \t\tint y = 0;\n    \t\twhile (y < Long.SIZE) {\n    \t\t\tArrays.fill(cnt, 0);\n    \t\t\tfor (int i = l; i < r; i++) ++cnt[(int) (a[i] >> y & (1 << BOUND) - 1)];\n    \t\t\tfor (int i = 1; i < 1 << BOUND; i++) cnt[i] += cnt[i - 1];\n    \t\t\tfor (int i = r - 1; i >= l; i--) b[--cnt[(int) (a[i] >> y & (1 << BOUND) - 1)]] = a[i];\n    \t\t\tfor (int i = l; i < r; i++) a[i] = b[i - l];\n    \t\t\ty += BOUND;\n    \t\t}\n    \t}\n    \t\n    \tpublic static void sort(int[] a) {\n    \t\tif (a.length <= 1 << BOUND) {\n    \t\t\tInteger[] b = new Integer[a.length];\n    \t\t\tfor (int i = 0; i < a.length; i++) b[i] = a[i];\n    \t\t\tquick_sort(b);\n    \t\t\tfor (int i = 0; i < a.length; i++) a[i] = b[i];\n    \t\t} else bucket_sort(a);\n    \t}\n\n    \tpublic static void sort(long[] a) {\n    \t\tif (a.length <= 1 << BOUND) {\n    \t\t\tLong[] b = new Long[a.length];\n    \t\t\tfor (int i = 0; i < a.length; i++) b[i] = a[i];\n    \t\t\tquick_sort(b);\n    \t\t\tfor (int i = 0; i < a.length; i++) a[i] = b[i];\n    \t\t} else bucket_sort(a);\n    \t}\n    \t\n    \tpublic static <T extends Comparable<T> > void sort(T[] a) {\n    \t\tquick_sort(a);\n    \t}\n    \t\n    \tpublic static void shuffle(int[] a) {\n    \t\tRandom ran = new Random();\n    \t\tfor (int i = 0; i < a.length; i++) {\n    \t\t\tint p = ran.nextInt(i + 1);\n    \t\t\tint q = a[p]; a[p] = a[i]; a[i] = q; \n    \t\t}\n    \t}\n    \t\n    \tpublic static void shuffle(long[] a) {\n    \t\tRandom ran = new Random();\n    \t\tfor (int i = 0; i < a.length; i++) {\n    \t\t\tint p = ran.nextInt(i + 1);\n    \t\t\tlong q = a[p]; a[p] = a[i]; a[i] = q; \n    \t\t}\n    \t}\n    \t\n    \tpublic static <T> void shuffle(T[] a) {\n    \t\tRandom ran = new Random();\n    \t\tfor (int i = 0; i < a.length; i++) {\n    \t\t\tint p = ran.nextInt(i + 1);\n    \t\t\tT q = a[p]; a[p] = a[i]; a[i] = q; \n    \t\t}\n    \t}\n    \t\n    }\n}", "complexity": "nlogn", "problem": "982_B. Bus of Characters", "from": "CODEFORCES"}
{"src": "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    ABirthday solver = new ABirthday();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class ABirthday {\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n      long N = in.readLong(), M = in.readLong(), K = in.readLong(), L = in.readLong();\n\n      long ans = ((L + K) - 1) / M + 1;\n      if (ans * M > N || ans * M - K < L) out.printLine(-1);\n      else out.printLine(ans);\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  static class InputReader {\n    private InputStream stream;\n    private byte[] buf = new byte[1024];\n    private int curChar;\n    private int numChars;\n    private InputReader.SpaceCharFilter filter;\n\n    public InputReader(InputStream stream) {\n      this.stream = stream;\n    }\n\n    public int read() {\n      if (numChars == -1) {\n        throw new InputMismatchException();\n      }\n      if (curChar >= numChars) {\n        curChar = 0;\n        try {\n          numChars = stream.read(buf);\n        } catch (IOException e) {\n          throw new InputMismatchException();\n        }\n        if (numChars <= 0) {\n          return -1;\n        }\n      }\n      return buf[curChar++];\n    }\n\n    public long readLong() {\n      int c = read();\n      while (isSpaceChar(c)) {\n        c = read();\n      }\n      int sgn = 1;\n      if (c == '-') {\n        sgn = -1;\n        c = read();\n      }\n      long res = 0;\n      do {\n        if (c < '0' || c > '9') {\n          throw new InputMismatchException();\n        }\n        res *= 10;\n        res += c - '0';\n        c = read();\n      } while (!isSpaceChar(c));\n      return res * sgn;\n    }\n\n    public boolean isSpaceChar(int c) {\n      if (filter != null) {\n        return filter.isSpaceChar(c);\n      }\n      return isWhitespace(c);\n    }\n\n    public static boolean isWhitespace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public interface SpaceCharFilter {\n      public boolean isSpaceChar(int ch);\n    }\n  }\n}\n", "complexity": "constant", "problem": "1068_A. Birthday", "from": "CODEFORCES"}
{"src": "import java.util.*;\n \npublic class Main {\n  public static void main(String[] args) {\n    Scanner sc = new Scanner(System.in);\n\t int[][] x = new int [200010][10];\n     String a = sc.nextLine(); \n     String b = sc.nextLine(); \n \t  int n = a.length();\n\t  int m = b.length();\n       for (int i = 1; i <= m; i++) {\n         for (int j = 0; j < 2; j++) {\n           x[i][j] = x[i - 1][j];\n         }\n         ++x[i][b.charAt(i - 1) - '0'];\n       }\n       long res = 0;\n        for (int i = 0, c; i < n; i++) {\n          c = a.charAt(i) - '0';\n           for (int j = 0; j < 2; j++) {\n             res += Math.abs(c - j) * (x[m - n + i + 1][j] - x[i][j]);\n           }\n        }\n         System.out.println(res);\n  }\n}", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "//Author: Patel Rag\n//Java version \"1.8.0_211\"\nimport java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n  static class FastReader\n  {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastReader(){ br = new BufferedReader(new 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 nextInt() { return Integer.parseInt(next()); }\n\n    long nextLong(){ return Long.parseLong(next()); }\n\n    double nextDouble(){ return Double.parseDouble(next()); }\n\n    float nextFloat() { return Float.parseFloat(next()); }\n\n    boolean nextBoolean() { return Boolean.parseBoolean(next()); }\n\n    String nextLine()\n    {\n      String str = \"\";\n      try\n      {\n        str = br.readLine();\n      }\n      catch (IOException e)\n      {\n        e.printStackTrace();\n      }\n      return str;\n    }\n  }\n  static long modExp(long x, long n, long mod)    //binary Modular exponentiation\n  {\n    long result = 1;\n    while(n > 0)\n    {\n        if(n % 2 == 1)\n            result = (result%mod * x%mod)%mod;\n        x = (x%mod * x%mod)%mod;\n        n=n/2;\n    }\n    return result;\n  }\n  static long gcd(long a, long b)\n  {\n    if(a==0) return b;\n    return gcd(b%a,a);\n  }\n  public static void main(String[] args)\n  throws IOException\n  {\n    FastReader fr = new FastReader();\n    long n = fr.nextLong();\n    long x = fr.nextLong();\n    long y = fr.nextLong();\n    long w = Long.min(x,y) - 1 + (x - Long.min(x,y)) + (y - Long.min(x,y));\n    long b = n - Long.max(x,y) + (Long.max(x,y) - x) + (Long.max(x,y) - y);\n    if(w <= b) System.out.println(\"White\");\n    else System.out.println(\"Black\");\n\n  }\n}\nclass Pair<U, V>  // Pair class\n{\n    public final U first;       // first field of a Pair\n    public final V second;      // second field of a Pair\n\n    private Pair(U first, V second)\n    {\n      this.first = first;\n      this.second = second;\n    }\n\n    @Override\n    public boolean equals(Object o)\n    {\n      if (this == o) return true;\n\n      if (o == null || getClass() != o.getClass()) return false;\n\n      Pair<?, ?> pair = (Pair<?, ?>) o;\n\n      if (!first.equals(pair.first)) return false;\n      return second.equals(pair.second);\n    }\n\n    @Override\n    public int hashCode()\n    {\n      return 31 * first.hashCode() + second.hashCode();\n    }\n\n    public static <U, V> Pair <U, V> of(U a, V b)\n    {\n      return new Pair<>(a, b);\n    }\n}\nclass myComp implements Comparator<Pair>\n{\n  public int compare(Pair a,Pair b)\n  {\n    if(a.first != b.first) return ((int)a.first - (int)b.first);\n    if(a.second != b.second) return ((int)a.second - (int)b.second);\n    return 0;\n  }\n}\nclass BIT       //Binary Indexed Tree aka Fenwick Tree\n{\n  public long[] m_array;\n\n  public BIT(long[] dat)\n  {\n    m_array = new long[dat.length + 1];\n    Arrays.fill(m_array,0);\n    for(int i = 0; i < dat.length; i++)\n    {\n      m_array[i + 1] = dat[i];\n    }\n    for(int i = 1; i < m_array.length; i++)\n    {\n      int j = i + (i & -i);\n      if(j < m_array.length)\n      {\n        m_array[j] = m_array[j] + m_array[i];\n      }\n    }\n  }\n\n  public final long prefix_query(int i)\n  {\n    long result = 0;\n    for(++i; i > 0; i = i - (i & -i))\n    {\n      result = result + m_array[i];\n    }\n    return result;\n  }\n\n  public final long range_query(int fro, int to)\n  {\n    if(fro == 0)\n    {\n      return prefix_query(to);\n    }\n    else\n    {\n      return (prefix_query(to) - prefix_query(fro - 1));\n    }\n  }\n\n  public void update(int i, long add)\n  {\n    for(++i; i < m_array.length; i = i + (i & -i))\n    {\n      m_array[i] = m_array[i] + add;\n    }\n  }\n}\n", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author MaxHeap\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    CBanhMi solver = new CBanhMi();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class CBanhMi {\n\n    long mod = (long) (1e9 + 7);\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n      int q = in.nextInt();\n      long[] two = new long[n + 1];\n      two[0] = 1;\n      for (int i = 1; i <= n; ++i) {\n        two[i] = (two[i - 1] * 2L);\n        two[i] %= mod;\n      }\n\n      char[] s = in.nextCharArray();\n      int[] acc = new int[n + 1];\n      for (int i = 1; i <= n; ++i) {\n        acc[i] = s[i - 1] == '0' ? 0 : 1;\n        acc[i] += acc[i - 1];\n      }\n      // 0 0 1 1 | 1: 1 1 2| 2: 2 3| 4: 5| 9\n      // 0 1 1 1| 1: 1 2 2| 2: 3 3| 5: 6| 11\n      // 0 1 1 wwqwq| 1: 1 2 2| 3: 5 3| 8: 8| 16\n      // 0 0 1 1| 1: 1 1 2| 3: 3 3| 6: 6| 12\n      // 0 0 0 1| 1: 1 1 1| 2: 2 2| 4: 4| 8\n      while (q-- > 0) {\n        int f = in.nextInt();\n        int t = in.nextInt();\n        int ones = acc[t] - acc[f - 1];\n        int zeros = (t - f + 1) - ones;\n        if (ones == 0) {\n          out.println(0);\n        } else {\n          long ans = two[t - f + 1] - (zeros > 0 ? two[zeros] : 0);\n          if (zeros == 0) {\n            --ans;\n          }\n          ans = (ans + mod) % mod;\n          out.println(ans);\n        }\n      }\n    }\n\n  }\n\n  static class InputReader implements FastIO {\n\n    private InputStream stream;\n    private static final int DEFAULT_BUFFER_SIZE = 1 << 16;\n    private static final int EOF = -1;\n    private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];\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 == EOF) {\n        throw new UnknownError();\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 ex) {\n            throw new InputMismatchException();\n          }\n\n          if (this.numChars <= 0) {\n            return EOF;\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      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      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 == EOF;\n    }\n\n    public char[] nextCharArray() {\n      return next().toCharArray();\n    }\n\n  }\n\n  static interface FastIO {\n\n  }\n}\n\n", "complexity": "linear", "problem": "1062_C. Banh-mi", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\n\npublic class Main {\n\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt(), m = scanner.nextInt();\n        int[] vertical = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            vertical[i] = scanner.nextInt();\n        }\n\n        Arrays.sort(vertical);\n\n\n        ArrayList<Integer> horisontal = new ArrayList<>();\n        int amount = 0;\n        for (int i = 0; i < m; i++) {\n            int x1 = scanner.nextInt(), x2 = scanner.nextInt(), y = scanner.nextInt();\n            if (x1 == 1) {\n                amount++;\n                horisontal.add(x2);\n            }\n        }\n\n        Collections.sort(horisontal);\n\n\n        if (amount == 0) {\n            System.out.println(0);\n            return;\n        }\n\n\n        int minVal = amount, horSize = horisontal.size(), verLen = vertical.length;\n        int h = 0, v = 0;\n\n        for (; v < verLen && h < horSize; ) {\n\n           while (h < horSize && horisontal.get(h) < vertical[v]){\n               h++;\n               amount--;\n           }\n           minVal = Math.min(minVal, amount + v);\n\n            while (h < horSize && v < verLen && horisontal.get(h) >= vertical[v]){\n                minVal = Math.min(minVal, amount + v);\n                v++;\n            }\n\n        }\n\n        if(horisontal.get(horSize - 1) < 1E9){\n            minVal = Math.min(minVal, v);\n        }\n\n\n\n        System.out.println(minVal);\n\n    }\n}\n", "complexity": "nlogn", "problem": "1075_C. The Tower is Going Home", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Codechef{\n\t\n\n    public static void main(String []args){\n    \t\t\tScanner in = new Scanner(System.in);\n\n    long n=in.nextLong();\n\t\tlong m=in.nextLong();\n\t\tlong k=in.nextLong();\n\t\tlong l=in.nextLong();\n \n\t\tlong j=((k+l)/m);\n\t\tif((k+l)%m!=0)j++;\n\t\tif((k+l>n) || j*m>n) {\n\t\t\tSystem.out.println(-1);\n\t\t}else {\n\t\t\t\n\t\t\tSystem.out.println(j);\n\t\t}\n\n\n    }\n\n}", "complexity": "constant", "problem": "1068_A. Birthday", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class RENAMETHISBITCH {\n\t\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\ttry (Scanner sc = new Scanner(System.in)) {\n\t\t\t\n\t\t\tint n = sc.nextInt();\n\t\t\tBigInteger m = sc.nextBigInteger();\n\t\t\t\n\t\t\tSystem.out.println(m.mod(BigInteger.valueOf(2).pow(n)));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "913_A. Modular Exponentiation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        int[] arr = new int[n];\n        HashMap<Integer, Integer> map = new HashMap<>();\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        for (int i = 0; i < n; i++) {\n            int x = Integer.parseInt(st.nextToken());\n            arr[i] = x;\n            if (!map.containsKey(x)) {\n                map.put(x, 1);\n            } else {\n                map.replace(x, map.get(x) + 1);\n            }\n        }\n        int[] power = new int[31];\n        for (int i = 0; i < 31; i++) {\n            power[i] = 1 << i; // 0 100=4 1000=8 10000=16\n        }\n        int c = 0;\n        for (int i = 0; i < n; i++) {\n        boolean f = false;\n        for (int j = 0; j <= 30; j++) {\n        int check = power[j] - arr[i];\n                if ((map.containsKey(check) && check != arr[i])) {\n                f = true; break;}\n                if((map.containsKey(check) && check == arr[i] && map.get(check) >=2)) {\n                    f = true; break;\n                }\n            }\n            if (!f) {\n                c++;\n            }\n        }\n        System.out.println(c);\n    }\n}", "complexity": "nlogn", "problem": "1005_C. Summarize to the Power of Two", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n\npublic class C994{\n\tstatic double area(double x1,double y1,double x2,double y2,double x3,double y3){\n\t\treturn Math.abs((x1 * (y2 - y3) +  \n        x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); \n\t}\n\tpublic static void main(String args[])throws IOException{\n\t\tScanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tint x11=sc.nextInt();\n\t\tint y11=sc.nextInt();\n\t\tint x12=sc.nextInt();\n\t\tint y12=sc.nextInt();\n\t\tint x13=sc.nextInt();\n\t\tint y13=sc.nextInt();\n\t\tint x14=sc.nextInt();\n\t\tint y14=sc.nextInt();\n\t\tdouble x1c=(x11+x12+x13+x14)/4.0;\n\t\tdouble y1c=(y11+y12+y13+y14)/4.0;\n\t\tint x21=sc.nextInt();\n\t\tint y21=sc.nextInt();\n\t\tint x22=sc.nextInt();\n\t\tint y22=sc.nextInt();\n\t\tint x23=sc.nextInt();\n\t\tint y23=sc.nextInt();\n\t\tint x24=sc.nextInt();\n\t\tint y24=sc.nextInt();\n\t\tdouble x2c=(x21+x22+x23+x24)/4.0;\n\t\tdouble y2c=(y21+y22+y23+y24)/4.0;\n\t\tdouble a1=area(x11,y11,x12,y12,x13,y13)+area(x11,y11,x13,y13,x14,y14);\n\t\tdouble a2=area(x21,y21,x22,y22,x23,y23)+area(x21,y21,x23,y23,x24,y24);\n\t\tif(a1==area(x11,y11,x12,y12,x21,y21)+area(x11,y11,x21,y21,x14,y14)+area(x21,y21,x12,y12,x13,y13)+area(x21,y21,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x22,y22)+area(x11,y11,x22,y22,x14,y14)+area(x22,y22,x12,y12,x13,y13)+area(x22,y22,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x23,y23)+area(x11,y11,x23,y23,x14,y14)+area(x23,y23,x12,y12,x13,y13)+area(x23,y23,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x24,y24)+area(x11,y11,x24,y24,x14,y14)+area(x24,y24,x12,y12,x13,y13)+area(x24,y24,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x2c,y2c)+area(x11,y11,x2c,y2c,x14,y14)+area(x2c,y2c,x12,y12,x13,y13)+area(x2c,y2c,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x11,y11)+area(x21,y21,x11,y11,x24,y24)+area(x11,y11,x22,y22,x23,y23)+area(x11,y11,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x12,y12)+area(x21,y21,x12,y12,x24,y24)+area(x12,y12,x22,y22,x23,y23)+area(x12,y12,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x13,y13)+area(x21,y21,x13,y13,x24,y24)+area(x13,y13,x22,y22,x23,y23)+area(x13,y13,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x14,y14)+area(x21,y21,x14,y14,x24,y24)+area(x14,y14,x22,y22,x23,y23)+area(x14,y14,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x1c,y1c)+area(x21,y21,x14,y14,x2c,y2c)+area(x1c,y1c,x22,y22,x23,y23)+area(x1c,y1c,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tpw.println(\"NO\");\n\t\tpw.close();\n\t}\n}", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "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 */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            TaskD.Pair[] p = new TaskD.Pair[n];\n            for (int i = 0; i < n; ++i) {\n                p[i] = new TaskD.Pair(in.nextLong(), in.nextLong());\n            }\n            Arrays.sort(p);\n            int last = 0;\n            int ans = 1;\n            for (int i = 1; i < n; ++i) {\n                if (p[i].x - p[i].w >= p[last].x + p[last].w) {\n                    last = i;\n                    ++ans;\n                }\n            }\n            out.println(ans);\n        }\n\n        static class Pair implements Comparable<TaskD.Pair> {\n            long x;\n            long w;\n\n            public Pair(long x, long w) {\n                this.x = x;\n                this.w = w;\n            }\n\n            public int compareTo(TaskD.Pair o) {\n                return Long.compare(x + w, o.x + o.w);\n            }\n\n            public String toString() {\n                return x + \" \" + w;\n            }\n\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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 long nextLong() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = pread();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = pread();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "528_B. Clique Problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\n\n\npublic class pr988B {\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\n        int n = Integer.parseInt(br.readLine());\n\n        ArrayList<String> a = new ArrayList<>();\n\n        for (int i = 0; i < n; i++) {\n            a.add(br.readLine());\n        }\n\n        if(solve(n, a)){\n            out.println(\"YES\");\n            for (String s : a) {\n                out.println(s);\n            }\n        }\n        else\n            out.println(\"NO\");\n\n        out.flush();\n        out.close();\n    }\n\n    private static boolean solve(int n, ArrayList<String> a) {\n        a.sort(Comparator.comparingInt(String::length));\n        for (int i = 0; i < n - 1; i++) {\n            if(!a.get(i+1).contains(a.get(i))) return false;\n        }\n        return true;\n    }\n}\n", "complexity": "nlogn", "problem": "988_B. Substrings Sort", "from": "CODEFORCES"}
{"src": "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 TwoSquares {\n    \n    int INF = 1000;\n    \n    void solve() {\n        int[][] s1 = new int[4][2];\n        for (int i = 0; i < 4; i++) {\n            s1[i][0] = in.nextInt();\n            s1[i][1] = in.nextInt();\n        }\n        \n        int[][] s2 = new int[4][2];\n        for (int i = 0; i < 4; i++) {\n            s2[i][0] = in.nextInt();\n            s2[i][1] = in.nextInt();\n        }\n        \n        if (ok(s1, s2)) {\n            out.println(\"Yes\");\n            return;\n        }\n        \n        rotate(s1);\n        rotate(s2);\n        \n        if (ok(s2, s1)) {\n            out.println(\"Yes\");\n            return;\n        }\n        \n        out.println(\"No\");\n    }\n    \n    void rotate(int[][] s) {\n        for (int i = 0; i < 4; i++) {\n            int x = s[i][0], y = s[i][1];\n            s[i][0] = x - y;\n            s[i][1] = x + y;\n        }\n    }\n    \n    boolean ok(int[][] s1, int[][] s2) {\n        int xmin = INF, xmax = -INF, ymin = INF, ymax = -INF;\n        for (int i = 0; i < 4; i++) {\n            xmin = Math.min(xmin, s1[i][0]);\n            xmax = Math.max(xmax, s1[i][0]);\n            ymin = Math.min(ymin, s1[i][1]);\n            ymax = Math.max(ymax, s1[i][1]);\n        }\n        \n        for (int i = 0; i < 4; i++) {\n            if (s2[i][0] >= xmin && s2[i][0] <= xmax && s2[i][1] >= ymin && s2[i][1] <= ymax) return true;\n        }\n        \n        int[] mid2 = new int[]{s2[0][0] + s2[2][0], s2[0][1] + s2[2][1]};\n        return mid2[0] >= xmin * 2 && mid2[0] <= xmax * 2 && mid2[1] >= ymin * 2 && mid2[1] <= ymax * 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 TwoSquares().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", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n//201920181\n\npublic class Polycarp{\n\n\tpublic static void main(String args[]){\n\t\tScanner s = new Scanner(System.in);\n        int rem[] = new int[3];\n\t\t\n\t\tArrays.fill(rem,-1);\n\t\trem[0] = 0;\n        char ch[] = s.next().toCharArray();\n\t\tint n = ch.length;\n \t\tlong dp[] = new long[n];\n\n        int sum = 0;\n\t\t\n        for(int i=0;i<ch.length;i++){\n\t\t   sum = sum + (ch[i]-48);\n\t\t   if(rem[sum%3] != -1)\n\t\t\t    if(i>0){\n\t\t\t\t\tdp[i] = Math.max(dp[i-1],dp[rem[sum%3]]+1);}\n\t\t\t\telse\n\t\t\t\t\tdp[i] = 1;\n\t       else\n\t\t\t   if(i>0)\n\t\t\t\t   dp[i] = dp[i-1];\n\t\t\t   \n\t\t   \n\t\t   rem[sum%3] = i;\n\t\t   sum = sum%3;\n\t\t   \n\t\t}\t\t\n\t\t \n\n            System.out.println(dp[n-1]);\t\t\t\n\t\t\n\t\t\n\t}\n}\n", "complexity": "linear", "problem": "1005_D. Polycarp and Div 3", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\npublic class Main {\n\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        long n = scanner.nextLong();\n        long x = scanner.nextLong(), y = scanner.nextLong();\n        long whiteSteps, blackSteps;\n\n        if(x == 1 || y == 1){\n            whiteSteps = (x - 1) + (y - 1);\n        } else {\n            whiteSteps = Math.min((x - 1) + Math.abs(y - x), (y - 1) + Math.abs(y - x));\n        }\n\n        if(x == n || y == n){\n            blackSteps = (n - x) + (n - y);\n        } else {\n            blackSteps = Math.min((n - x) + Math.abs(y - x), (n - y) + Math.abs(y - x));\n        }\n\n        if (whiteSteps <= blackSteps){\n            System.out.println(\"White\");\n        } else {\n            System.out.println(\"Black\");\n        }\n\n    }\n}\n", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "//package com.krakn.CF.D1159;\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        int n, k;\n        n = sc.nextInt();\n        k = sc.nextInt();\n\n        int a = (n - k) / 2;\n\n        StringBuilder s = new StringBuilder();\n\n        int i;\n        while (s.length() < n) {\n            i = 0;\n            while (i < a && s.length() < n) {\n                s.append(\"0\");\n                i++;\n            }\n            if (s.length() < n) s.append(\"1\");\n        }\n\n        System.out.println(s);\n    }\n}\n", "complexity": "linear", "problem": "1159_D. The minimal unique substring", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.concurrent.atomic.AtomicReferenceArray;\n\npublic class NastyaWardrobe {\n    static long modulo = 1000000007;\n    static long ans = 0;\n    public static void main(String[] args) throws IOException {\n\n        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));\n        String[] s1 = inp.readLine().split(\" \");\n        long clothes = Long.parseLong(s1[0]);\n        long months = Long.parseLong(s1[1]);\n\n        //formula 2^k(2x-1)+1;\n        calc(clothes,months);\n        System.out.print(ans);\n    }\n    static void calc(long clothes,long months){\n        if(clothes!=0) {\n            long a;\n            long count = 0;\n            ArrayList<Long> list = new ArrayList<>();\n            if (months >= 2) {\n                a = 2;\n                long c = months;\n\n                while (c > 1) {\n                    if (c % 2 == 1) {\n                        count++;\n                        list.add(a);\n                    }\n                    c = c / 2;\n\n                    a = (a * a) % modulo;\n                }\n                while (count > 0) {\n                    long b = list.get(0);\n                    list.remove(0);\n                    a = (a * b) % modulo;\n                    count--;\n                }\n\n            } else {\n                a = (long) Math.pow(2, months);\n            }\n\n\n            long b = clothes;\n\n            //System.out.println(b);\n            b = (2 * b - 1) % modulo;\n            ans = (a * b) % modulo;\n            ans = (ans + 1) % modulo;\n        }else{\n            ans = 0;\n        }\n\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Test { public static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nint n= sc.nextInt();\nint x= (int)Math.sqrt(n) ;\nint a[] = new int[n+5];\nfor(int i=1,o=n,j;i<=n;i+=x)\nfor(j=(int)Math.min(i+x-1,n);j>=i;a[j--]=o--);\nfor(int i=1;i<=n;i++)System.out.print(a[i]+\" \");\nSystem.out.println();\n\n\n} \n}", "complexity": "linear", "problem": "1017_C. The Phone Number", "from": "CODEFORCES"}
{"src": "/**\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    static int n,k,left[],right[],arr[];\n    static long MOD = 1000000007,count[],dp[];\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        n = ni();\n        k = ni();\n        int stack[] = new int[1000001];\n        int top = -1;\n        arr = new int[n];\n        left = new int[n];\n        right = new int[n];\n        for(int i=0;i<n;++i) {\n            arr[i] = ni();\n            while(top>=0 && arr[stack[top]]<=arr[i])\n                top--;\n            if(top==-1)\n                left[i] = 0;\n            else left[i] = stack[top]+1;\n            stack[++top] = i;\n        }\n        top = -1;\n        for(int i=n-1;i>=0;--i) {\n            while(top>=0 && arr[stack[top]]<arr[i])\n                top--;\n            if(top==-1)\n                right[i] = n-1;\n            else right[i] = stack[top]-1;\n            stack[++top] = i;\n        }\n        //pa(\"left\", left);\n        //pa(\"right\", right);\n        dp = new long[n+1];\n        for(int i=0;i<=n;++i) {\n            if(i<k)\n              continue;\n            dp[i] = dp[i-k+1] + (i-k+1);\n        }\n        count = new long[n];\n        long ans = 0;\n        for(int i=0;i<n;++i) {\n            int len = right[i]-left[i]+1;\n            int lef = i-left[i];\n            int rig = right[i]-i;\n            long count = dp[len] - dp[lef] - dp[rig];\n            if(count>=MOD)\n              count%=MOD;\n            ans += count*arr[i];\n            if(ans>=MOD)\n                ans%=MOD;\n        }\n        pl(ans);\n        pw.flush();\n        pw.close();\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class Reader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        public Reader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public Reader(String file_name) throws IOException {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[64];\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}", "complexity": "linear", "problem": "1037_F. Maximum Reduction", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\npublic class Main {\n    \n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int N = sc.nextInt();\n        long dest = sc.nextLong();\n        long max = (long)N * ((long)N + 1L) / 2L;\n        if (dest < 2 * N - 1 || dest > max) {\n            out.println(\"No\");\n            out.close();\n            return;\n        }\n        int[] d = new int[N + 1];\n        int[] f = new int[N + 1];\n        int K = 1;\n        for (; K <= N; K++) {\n            long dep = 1L, cnt = 1L, c = 1L;\n            long t = 1L;\n            while (cnt < N) {\n                c = c * K;\n                dep++;\n                t += (dep * Math.min(c, N - cnt));\n                cnt += c;\n            }\n            if (t <= dest) break;\n        }\n        out.println(\"Yes\");\n        int dep = 1; long cnt = 1L, c = 1L;\n        long t = 1L;\n        d[1] = 1;\n        while (cnt < N) {\n            dep++; c = c * K; \n            long x = (long)N - cnt;\n            int min;\n            if (c >= x) min = (int)x;\n            else min = (int)c;\n            d[dep] = min;\n            t += (dep * Math.min(c, (long)N - cnt)); cnt += c;\n        }\n        dest -= t;\n        int curDep = dep; int nextDep = dep + 1;\n        while (dest > 0) {\n            if (d[curDep] <= 1) curDep--;\n            d[curDep]--;\n            long next = Math.min(nextDep++, dest + curDep);\n            dest -= ((int)next - curDep);\n            d[(int)next]++;\n        }\n        int first = 1;\n        for (int i = 2; i < nextDep; i++) {\n            int p = 0, fn = first - d[i - 1] + 1;\n            for (int j = first + 1; j <= first + d[i]; j++) {\n                if (p == K) {\n                    fn++; p = 0;\n                }\n                p++; f[j] = fn;\n            }\n            first += d[i];\n        }\n        for (int i = 2; i <= N; i++)\n            out.format(\"%d \", f[i]);\n        out.close();\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                } 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 int[] nextIntArray(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; ++i) {\n                a[i] = nextInt();\n            }\n            return a;\n        }\n        \n        public long[] nextLongArray(int n) {\n            long[] a = new long[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextLong();\n            }\n            return a;\n        }*/\n    }\n}", "complexity": "nlogn", "problem": "1098_C. Construct a tree", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Double.*;\nimport java.lang.Math.*;\n\npublic class two_squares {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew two_squares().run();\n\t}\n\n\tpublic void run() throws Exception {\n\t\tFastIO file = new FastIO();\n\t\tdouble x1 = file.nextInt();\n\t\tdouble y1 = file.nextInt();\n\t\tdouble x2 = file.nextInt();\n\t\tdouble y2 = file.nextInt();\n\t\tdouble x3 = file.nextInt();\n\t\tdouble y3 = file.nextInt();\n\t\tdouble x4 = file.nextInt();\n\t\tdouble y4 = file.nextInt();\n\t\tdouble minx1, maxx1, miny1, maxy1;\n\t\tminx1 = Math.min(x1, Math.min(x2, Math.min(x3, x4)));\n\t\tmaxx1 = Math.max(x1, Math.max(x2, Math.max(x3, x4)));\n\t\tminy1 = Math.min(y1, Math.min(y2, Math.min(y3, y4)));\n\t\tmaxy1 = Math.max(y1, Math.max(y2, Math.max(y3, y4)));\n\t\tdouble x5 = file.nextInt();\n\t\tdouble y5 = file.nextInt();\n\t\tdouble x6 = file.nextInt();\n\t\tdouble y6 = file.nextInt();\n\t\tdouble x7 = file.nextInt();\n\t\tdouble y7 = file.nextInt();\n\t\tdouble x8 = file.nextInt();\n\t\tdouble y8 = file.nextInt();\n\t\tdouble minx2, maxx2, miny2, maxy2;\n\t\tminx2 = Math.min(x5, Math.min(x6, Math.min(x7, x8)));\n\t\tmaxx2 = Math.max(x5, Math.max(x6, Math.max(x7, x8)));\n\t\tminy2 = Math.min(y5, Math.min(y6, Math.min(y7, y8)));\n\t\tmaxy2 = Math.max(y5, Math.max(y6, Math.max(y7, y8)));\n\t\tPoint _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;\n\t\t_1 = new Point(x1, y1);\n\t\t_2 = new Point(x2, y2);\n\t\t_3 = new Point(x3, y3);\n\t\t_4 = new Point(x4, y4);\n\t\t_5 = new Point(x5, y5);\n\t\t_6 = new Point(x6, y6);\n\t\t_7 = new Point(x7, y7);\n\t\t_8 = new Point(x8, y8);\n\t\t_9 = new Point(minx1, maxy1);\n\t\t_10 = new Point(minx1, miny1);\n\t\t_11 = new Point(maxx1, maxy1);\n\t\t_12 = new Point(maxx1, miny1);\n\t\tdouble m1 = (minx2 + maxx2) / 2;\n\t\tdouble m2 = (miny2 + maxy2) / 2;\n\t\t_13 = new Point(minx2, m2);\n\t\t_14 = new Point(m1, miny2);\n\t\t_15 = new Point(maxx2, m2);\n\t\t_16 = new Point(m1, maxy2);\n\t\tPoint[] a = {_1, _2, _3, _4};\n\t\tPoint[] b = {_5, _6, _7, _8};\n\t\tboolean works = false;\n\t\tLine[] aa = {new Line(_9,_10), new Line(_10, _12), new Line(_12, _11), new Line(_11, _9)};\n\t\tLine[] bb = {new Line(_13, _14), new Line(_14, _15), new Line(_15, _16), new Line(_16, _13)};\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\tif (aa[i].intersection(bb[i]) != null) {\n\t\t\t\t\tworks = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (Point p : b) {\n\t\t\tif (p.x >= minx1 && p.x <= maxx1 && p.y >= miny1 && p.y <= maxy1) {\n\t\t\t\tworks = true;\n\t\t\t}\n\t\t}\n\t\tfor (Point p : a) {\n\t\t\tboolean result = false;\n\t\t      for (int i = 0, j = b.length - 1; i < b.length; j = i++) {\n\t\t        if ((b[i].y > p.y) != (b[j].y > p.y) &&\n\t\t            (p.x < (b[j].x - b[i].x) * (p.y - b[i].y) / (b[j].y-b[i].y) + b[i].x)) {\n\t\t          result = !result;\n\t\t         }\n\t\t      }\n\t\t      if (result) works = true;\n\t\t}\n\t\tSystem.out.println(works ? \"YES\" : \"NO\");\n\t}\n\tpublic static class Point {\n\t\tdouble x, y;\n\t\tpublic Point(double a, double b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\t}\n\tpublic static class Line {\n\t\tPoint a, b;\n\t\tpublic Line(Point x, Point y) {\n\t\t\ta = x;\n\t\t\tb = y;\n\t\t}\n\t\tpublic Point intersection(Line o) {\n\t\t\tdouble x1 = a.x;\n\t\t\tdouble y1 = a.y;\n\t\t\tdouble x2 = b.x;\n\t\t\tdouble y2 = b.y;\n\t\t\tdouble x3 = o.a.x;\n\t\t\tdouble y3 = o.a.y;\n\t\t\tdouble x4 = o.b.x;\n\t\t\tdouble y4 = o.b.y;\n\t\t\tdouble denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);\n\t\t\t  double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3))/denom;\n\t\t\t  double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3))/denom;\n\t\t\t    if (ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f) {\n\t\t\t        return new Point((int) (x1 + ua*(x2 - x1)), (int) (y1 + ua*(y2 - y1)));\n\t\t\t    }\n\n\t\t\t  return null;\n\t\t}\n\t}\n\tpublic static class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastIO() {\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 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 / 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 / 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", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class java2 {\n    public static void main(String[] args) {\n        Scanner r = new Scanner(System.in);\n        int n=r.nextInt();\n        int []l=new int[1005];\n        int []ri=new int[1005];\n        int []candy=new int[1005];\n        for(int i=1;i<=n;++i)\n        {\n            l[i]=r.nextInt();\n        }\n        for(int i=1;i<=n;++i)\n        {\n            ri[i]=r.nextInt();\n        }\n        for(int i=1;i<=n;++i)\n        {\n            if(l[i]>i-1||ri[i]>n-i)\n            {\n                System.out.println(\"NO\");\n                System.exit(0);\n            }\n            candy[i]=n-l[i]-ri[i];\n        }\n        for(int i=1;i<=n;++i)\n        {\n            int left=0,right=0;\n            for(int j=1;j<=i-1;++j)\n            {\n                if(candy[j]>candy[i])\n                {\n                    ++left;\n                }\n            }\n            for(int j=i+1;j<=n;++j)\n            {\n                if(candy[j]>candy[i])\n                {\n                    ++right;\n                }\n            }\n            if(left!=l[i]||right!=ri[i])\n            {\n                System.out.println(\"NO\");\n                System.exit(0);\n            }\n        }\n        System.out.println(\"YES\");\n        for(int i=1;i<=n;++i)\n        {\n            System.out.print(candy[i]+\" \");\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1054_C. Candies Distribution", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.util.PriorityQueue;\nimport static java.lang.Math.*;\n\npublic class solution 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\tstatic int mod = (int)1e9+7;\n\tpublic static long fastexpo(long pow)\n\t{\n\t\tlong expo = 2;\n\t\tlong ans = 1;\n\t\twhile(pow!=0)\n\t\t{\n\t\t\tif((pow&1)==1)\n\t\t\t{\n\t\t\t\tans = (ans*expo)%mod;\n\t\t\t}\n\t\t\texpo = (expo*expo)%mod;\n\t\t\tpow = pow>>1;\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static void main(String args[]) throws Exception {\n        new Thread(null, new solution(),\"Main\",1<<26).start();\n    }\n\tpublic void run() {\n        InputReader sc  = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tlong x = sc.nextLong();\n\t\tif(x==0)\n\t\t{\n\t\t\tout.println(0);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\tlong k = sc.nextLong();\n\t\tlong a = ((fastexpo(k+1)%mod)*(x%mod))%mod;\n\t\tlong b = (-1*fastexpo(k)%mod+mod)%mod;\n\t\tlong ans = (a+b+1)%mod;\n\t\tout.println(ans);\n\t\tout.close();\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C{\n    static PrintWriter out;\n    static InputReader in;\n    public static void main(String args[]){\n        out = new PrintWriter(System.out);\n        in = new InputReader();\n        new C();\n        out.flush(); out.close();\n    }   \n    C(){\n       int w = solve();\n       out.print(w == 0 ? \"sjfnb\" : \"cslnb\");\n    }\n    int n;\n    long a[];\n    int solve(){\n        n = in.nextInt(); a = new long[n];\n        long sum = 0;\n        for(int i = 0; i < n; i++)sum += a[i] = in.nextLong();\n        if(sum == 0){\n            return 1;\n        }\n        Arrays.sort(a);\n        int c = 0, c0 = 0; long p = -1, max = 0;\n        int f = 0;\n        long t = -1; int pp = -1;\n        for(int i = 0; i < n; i++){\n            if(a[i] == p){\n                c++;\n            }else{\n                if(p == 0)c0 = c;\n                if(c >= 2){f++; t = p; pp = i - 2;}\n                max = Math.max(max, c);\n                p = a[i];\n                c = 1;\n            }\n        }\n        max = Math.max(max, c);\n        sum = 0;\n        if(c >= 2){f++; t = p; pp = n - 2;}\n        if(max > 2 || c0 > 1 || f > 1)return 1;\n        if(f == 1){\n            long v = Arrays.binarySearch(a, t - 1);\n            if(v >= 0)return 1;\n            a[pp]--; sum = 1;\n        }\n\n        p = -1;\n        for(int i = 0; i < n; i++){\n            sum += a[i] - (p + 1);\n            a[i] = p + 1;\n            p = a[i];\n        }\n\n        return 1 - (int)(sum % 2);\n    }\n    public static class InputReader{\n        BufferedReader br;\n        StringTokenizer st;\n        InputReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\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        public String next(){\n            while(st == null || !st.hasMoreTokens()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch(IOException e){}\n            }\n            return st.nextToken();\n        }\n    }\n}\n        ", "complexity": "linear", "problem": "1190_B. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "//q4\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class q4 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));\n        \n        int query = in.nextInt();\n        \n        while (query -- > 0) {\n            int n = in.nextInt();\n            int k = in.nextInt();\n            \n            char[] arr = new char[n];\n            //slot all n into char array\n            String code = in.next();\n            for (int i = 0; i < n; i++) {\n                arr[i] = code.charAt(i);\n                \n            }\n            \n            //R, G, B cycle\n            int r = 0;\n            int g = 0;\n            int b = 0;\n            \n            for (int i = 0; i < k; i++) {\n                if (i % 3 == 0) {\n                    if (arr[i] == 'R') {g++; b++;}\n                    else if (arr[i] == 'G') {r++; b++;}\n                    else {r++; g++;} //if is 'B'\n                } else if (i % 3 == 1) {\n                    if (arr[i] == 'G') {g++; b++;}\n                    else if (arr[i] == 'B') {r++; b++;}\n                    else {r++; g++;} //if is 'R'\n                } else { //if mod 3 is 2\n                    if (arr[i] == 'B') {g++; b++;}\n                    else if (arr[i] == 'R') {r++; b++;}\n                    else {r++; g++;} //if is 'G'     \n                }\n            }\n            \n            //starting from kth position, if different then add 1, and check (j-k)th position\n            int rMin = r;\n            int gMin = g;\n            int bMin = b;\n            for (int j = k; j < n; j++) {\n                //R cycle\n                if ((j % 3 == 0 && arr[j] != 'R') ||  \n                    (j % 3 == 1 && arr[j] != 'G') ||\n                    (j % 3 == 2 && arr[j] != 'B')) {\n                    r++;\n                }\n                //R cycle \n                if (((j - k) % 3 == 0 && arr[j - k] != 'R') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'G') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'B')) {\n                    r--;\n                }\n                rMin = Math.min(r, rMin);\n                //G cycle\n                if ((j % 3 == 0 && arr[j] != 'G') ||  \n                    (j % 3 == 1 && arr[j] != 'B') ||\n                    (j % 3 == 2 && arr[j] != 'R')) {\n                    g++;\n                } \n                if (((j - k) % 3 == 0 && arr[j - k] != 'G') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'B') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'R')) {\n                    g--;\n                }      \n                gMin = Math.min(gMin, g);\n                //B cycle\n                if ((j % 3 == 0 && arr[j] != 'B') ||  \n                    (j % 3 == 1 && arr[j] != 'R') ||\n                    (j % 3 == 2 && arr[j] != 'G')) {\n                    b++;\n                }       \n                if (((j - k) % 3 == 0 && arr[j - k] != 'B') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'R') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'G')) {\n                    b--;\n                } \n                bMin = Math.min(bMin, b);\n                \n            }\n            \n            out.println(Math.min(Math.min(rMin, gMin), bMin));\n            \n        }\n        out.flush();\n        \n    } \n    \n}", "complexity": "quadratic", "problem": "1196_D2. RGB Substring (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\nimport java.util.Map;\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 Ribhav\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        CGlassCarving solver = new CGlassCarving();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class CGlassCarving {\n        public void solve(int testNumber, FastReader s, PrintWriter out) {\n            TreeMap<Long, Integer> mapH = new TreeMap<>();\n            TreeMap<Long, Integer> mapV = new TreeMap<>();\n            TreeMap<Long, Integer> hDiff = new TreeMap<>();\n            TreeMap<Long, Integer> vDiff = new TreeMap<>();\n            long width = s.nextInt();\n            long height = s.nextInt();\n            mapH.put(0L, 1);\n            mapV.put(0L, 1);\n            mapV.put(width, 1);\n            mapH.put(height, 1);\n            vDiff.put(width, 1);\n            hDiff.put(height, 1);\n            long maxV = height;\n            long maxH = width;\n            int n = s.nextInt();\n            for (int i = 0; i < n; i++) {\n                char ch = s.nextCharacter();\n                long cut = s.nextInt();\n                if (ch == 'H') {\n                    Long next = mapH.higherKey(cut);\n                    Long prev = mapH.lowerKey(cut);\n                    Long diff = next - prev;\n                    int freq = hDiff.get(diff);\n                    if (freq == 1) {\n                        hDiff.remove(diff);\n                    } else {\n                        hDiff.put(diff, freq - 1);\n                    }\n                    hDiff.put(next - cut, hDiff.getOrDefault(next - cut, 0) + 1);\n                    hDiff.put(cut - prev, hDiff.getOrDefault(cut - prev, 0) + 1);\n                    mapH.put(cut, mapH.getOrDefault(cut, 0) + 1);\n                } else {\n                    Long next = mapV.higherKey(cut);\n                    Long prev = mapV.lowerKey(cut);\n                    Long diff = next - prev;\n                    int freq = vDiff.get(diff);\n                    if (freq == 1) {\n                        vDiff.remove(diff);\n                    } else {\n                        vDiff.put(diff, freq - 1);\n                    }\n                    vDiff.put(next - cut, vDiff.getOrDefault(next - cut, 0) + 1);\n                    vDiff.put(cut - prev, vDiff.getOrDefault(cut - prev, 0) + 1);\n                    mapV.put(cut, mapV.getOrDefault(cut, 0) + 1);\n                }\n\n                out.println(hDiff.lastKey() * vDiff.lastKey());\n            }\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private FastReader.SpaceCharFilter filter;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public char nextCharacter() {\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\n", "complexity": "nlogn", "problem": "527_C. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\n\npublic class First {\n    StreamTokenizer in;\n    PrintWriter out;\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\n\n    void run() throws IOException {\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n    }\n\n    void solve() throws IOException {\n        int n = nextInt(), k = nextInt(), sum = 0, count = 0;\n        String str = nextString();\n        char[] arr = str.toCharArray();\n        boolean[] bool = new boolean[26];\n        for(char ch: arr){\n            bool[((int)ch)-97] = true;\n        }\n        for(int i = 0; i < 26; i++){\n            if(bool[i]){\n                sum += i+1;\n                count++;\n                i += 1;\n            }\n            if(count == k) break;\n        }\n        if(count == k) out.println(sum);\n        else out.println(-1);\n    }\n\n    public static void main(String[] args) throws IOException {\n        new First().run();\n    }\n}", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.System.out;\n\npublic class Main {\n\n    private FastScanner scanner = new FastScanner();\n\n    public static void main(String[] args) {\n        new Main().solve();\n    }\n\n    private List<Integer>[] gr = new ArrayList[1000_000+5];\n    private int dp[][] = new int[21][1000_000+5];\n    private boolean used[] = new boolean[1000_000+5];\n\n    void init(int v, int p) {\n        Stack<Integer> st = new Stack<>();\n        st.push(v);\n        st.push(p);\n        while (!st.isEmpty()) {\n            p = st.pop();\n            v = st.pop();\n            used[v] = true;\n\n            dp[0][v] =  p;\n            for (int i = 1; i <= 20; i++) {\n                if (dp[i - 1][v] != -1) {\n                    dp[i][v] = dp[i - 1][dp[i - 1][v]];\n                }\n            }\n\n            for (int next : gr[v]) {\n                if (!used[next]) {\n                    st.push(next);\n                    st.push(v);\n                }\n            }\n\n        }\n    }\n\n\n    private void solve() {\n        int n = scanner.nextInt(), k = scanner.nextInt();\n        boolean[] ans = new boolean[1000_000 + 5];\n\n        for (int i = 0; i < n; i++) {\n            gr[i] = new ArrayList<>();\n        }\n\n        for (int i = 0; i < n - 1; i ++) {\n            int u = scanner.nextInt() - 1, v = scanner.nextInt() - 1;\n            gr[u].add(v);\n            gr[v].add(u);\n        }\n\n        k = n - k - 1;\n        ans[n - 1] = true;\n\n        init(n - 1 , n - 1);\n\n        int t, d, next;\n        for (int i = n - 2; i >= 0; i--) {\n            t = i;\n            d = 1;\n            if (ans[i]) {\n                continue;\n            }\n            for (int j = 20; j >= 0; j--){\n                next = dp[j][t];\n                if (next != -1 && !ans[next]) {\n                    t = next;\n                    d +=  1 << j;\n                }\n            }\n\n            if (d <= k) {\n                k -=d;\n                t = i;\n\n                while (!ans[t]) {\n                    ans[t] = true;\n                    t = dp[0][t];\n                }\n            }\n            if (k == 0) {\n                break;\n            }\n        }\n        StringBuilder sb = new StringBuilder(\"\");\n        for (int i = 0; i < n; i++) {\n            if (!ans[i]) {\n                sb.append(i + 1).append(\" \");\n            }\n        }\n        System.out.println(sb.toString());\n    }\n\n    class FastScanner {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "nlogn", "problem": "980_E. The Number Games", "from": "CODEFORCES"}
{"src": "import java.util.*;\n \npublic class Main{\n    private static final int MAX_SIZE = 100005;\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        if(((m + 1) / 60 < a) || ((m + 1) / 60 == a && (m + 1) % 60 <= b)) {\n            out(0, 0);\n            System.exit(0);\n        }\n        for(int i = 2; i <= n; i++) {\n            int x = sc.nextInt();\n            int y = sc.nextInt();\n\n            int bb = b + 2 * m + 2;\n            int aa = a + bb / 60;\n            bb %= 60;\n\n            if((aa < x) || (aa == x && bb <= y)) {\n                b = b + m + 1;\n                a = a + b / 60;\n                b %= 60;\n                out(a, b);\n                System.exit(0);\n            }\n            a = x;\n            b = y;\n        }\n        b = b + m + 1;\n        a = a + b / 60;\n        b = b % 60;        \n        out(a, b);\n    }\n\n    private static void out(int a, int b) {\n        cout(a);\n        cout(\" \");\n        cout(b);\n    }\n\n    private static void cout(Object a) {\n        System.out.print(a);\n    }\n}", "complexity": "linear", "problem": "967_A. Mind the Gap", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tString s = sc.next();\n\n\t\tStringBuilder ans = new StringBuilder();\n\t\tint count = 0;\n\t\tint open = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) == '(') {\n\t\t\t\tans.append(\"(\");\n\t\t\t\tcount++;\n\t\t\t\topen++;\n\t\t\t} else {\n\t\t\t\tans.append(\")\");\n\t\t\t\topen--;\n\t\t\t}\n\t\t\tif (count == k / 2) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\twhile (open > 0) {\n\t\t\tans.append(\")\");\n\t\t\topen--;\n\t\t}\n\t\tSystem.out.println(ans.toString());\n\t}\n}", "complexity": "linear", "problem": "1023_C. Bracket Subsequence", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    void run() {\n        in = new FastScanner();\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\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 s) {\n            try {\n                br = new BufferedReader(new FileReader(s));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        public String nextToken() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\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 Main().run();\n    }\n\n    void solve() {\n        int t = in.nextInt();\n\n        for (int sdfsdf = 0; sdfsdf < t; sdfsdf++) {\n            long n = in.nextLong();\n            long k = in.nextLong();\n\n            if (n == 1) {\n                if (k == 1)  {\n                    out.println(\"YES 0\");\n                } else {\n                    out.println(\"NO\");\n                }\n                continue;\n            }\n\n            if (k == 3) {\n                if (n == 2) {\n                    out.println(\"NO\");\n                } else {\n                    out.println(\"YES \" + (n - 1));\n                }\n                continue;\n            }\n\n            long cuts = 1;\n            long squares = 4;\n            int zoom = 1;\n\n            while (k > cuts + squares) {\n                cuts += squares;\n                squares *= 4;\n                zoom++;\n            }\n\n            if (zoom > n) {\n                out.println(\"NO\");\n                continue;\n            }\n\n            if (zoom == n && k > cuts) {\n                out.println(\"NO\");\n                continue;\n            }\n\n            long current_cuts = k - cuts;\n\n            if (current_cuts > squares - (2L * Math.sqrt(squares) - 1L)) {\n                out.println(\"YES \" + (n - zoom - 1L));\n            } else {\n                out.println(\"YES \" + (n - zoom));\n            }\n        }\n    }\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "/*\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 newpackage;\nimport java.util.*;\n/**\n *\n * @author parpaorsa\n */\npublic class NewClass {\n    static Scanner in=new Scanner(System.in);\n    public static void main(String[] args) {\n        int n = in.nextInt(),ans=Integer.MAX_VALUE,t=0;\n        String x = in.next();\n        for (int i = 0; i < n; i++) {\n            if(x.charAt(i)=='-')t--;\n            else t++;\n            ans=Math.min(ans,t);\n        }\n           if(ans <= 0) \n               System.out.println(Math.abs(ans)+t);\n           else \n               System.out.println(t);\n    }\n \n}\n", "complexity": "linear", "problem": "1159_A. A pile of stones", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Problem\n{\n\n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    static int[] rt;\n    static int[] size;\n\n    static void initialize(int n){\n        rt = new int[n + 1];\n        size = new int[n + 1];\n        for(int i = 0; i < rt.length; i++){\n            rt[i] = i;\n            size[i] = 1;\n        }\n    }\n    \n    static int root(int x){\n        while(rt[x] != x){\n            rt[x] = rt[rt[x]];\n            x = rt[x];\n        }\n        return x;\n    }\n    \n    static long union(int x,int y){\n        int root_x = root(x);\n        int root_y = root(y);\n        if(root_x == root_y) return 0;\n        long val = size[root_x] *1l* size[root_y];\n        if(size[root_x]<size[root_y]){\n            rt[root_x] = rt[root_y];\n            size[root_y] += size[root_x];\n        }\n        else{\n            rt[root_y] = rt[root_x];\n            size[root_x] += size[root_y];            \n        }\n        \n        return val;\n    }\n    \n    static void solve()\n    {\n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out);            \n        \n        int t = 1;\n        \n        while(t-- > 0){\n            int n = in.nextInt();\n            int[] arr = in.nextIntArray(n);\n            ArrayList<Pair> list = new ArrayList<>();\n            \n            for(int i = 1; i < n; i++){\n                int u = in.nextInt() - 1;\n                int v = in.nextInt() - 1;\n                list.add(new Pair(u, v, Math.max(arr[u],arr[v])));\n            }\n            list.sort((p1,p2) -> Integer.compare(p1.i, p2.i));\n            initialize(n);\n            long s1 = 0;\n            for(int i = 0; i < list.size(); i++){\n                s1 += union(list.get(i).x, list.get(i).y) * list.get(i).i;\n            }\n            for(int i = 0; i < list.size(); i++){\n                Pair p = list.get(i);\n                p.i = Math.min(arr[p.x],arr[p.y]);\n            }\n            list.sort((p1,p2) -> -Integer.compare(p1.i, p2.i));\n            initialize(n);\n            long s2 = 0;\n            for(int i = 0; i < list.size(); i++){\n                s2 += union(list.get(i).x, list.get(i).y) * list.get(i).i;\n            }\n            \n            out.println(s1 - s2);\n        }\n        \n        out.close();\n    }\n    \n    public static void main(String[] args)\n    {\n        new Thread(null ,new Runnable(){\n            public void run(){\n                try{\n                    solve();\n                } catch(Exception e){\n                    e.printStackTrace();\n                }\n            }\n        },\"1\",1<<26).start();\n        \n    }\n\n    static class Pair implements Comparable<Pair>\n    {\n\n        int x,y;\n        int i;\n\n\n        Pair (int x,int y)\n        {\n                this.x = x;\n                this.y = y;\n        }\n\n        Pair (int x,int y, int i)\n        {\n                this.x = x;\n                this.y = y;\n                this.i = i;\n        }\n\n        public int compareTo(Pair o)\n        {\n            if(this.x != o.x)\n                return -Integer.compare(this.x, o.y);\n            return -Integer.compare(this.y,o.y);\n                //return 0;\n        }\n\n        public boolean equals(Object o)\n        {\n            if (o instanceof Pair)\n            {\n                Pair p = (Pair)o;\n                return p.x == x && p.y==y;\n            }\n            return false;\n        }\n\n        @Override\n        public String toString()\n        {\n            return x + \" \"+ y + \" \"+i;\n        }\n\n        /*public int hashCode()\n        {\n            return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n        }*/\n\n    } \n\n    static long add(long a,long b){\n        long x=(a+b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n\n    static long sub(long a,long b){\n        long x=(a-b);\n        while(x<0) x+=mod;\n        return x;\n    }\n    \n    static long mul(long a,long b){\n        long x=(a*b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n    \n    static String rev(String s){\n        StringBuilder sb=new StringBuilder(s);\n        sb.reverse();\n        return sb.toString();\n    }\n    \n    static long gcd(long x,long y)\n    {\n        if(y==0)\n                return x;\n        else\n                return gcd(y,x%y);\n    }\n\n    static int gcd(int x,int y)\n    {\n        if(y==0)\n                return x;\n        else \n                return gcd(y,x%y);\n    }\n\n    static long pow(long n,long p,long m)\n    {\n         long  result = 1;\n          if(p==0){\n            return n;\n          }\n          \n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\n            if(result >= m)\n               result %= m;\n            p >>=1;\n            n*=n;\n            if(n >= m)\n                n%=m;\n        }\n        \n        return result;\n    }\n\n    static long pow(long n,long p)\n    {\n        long  result = 1;\n          if(p==0)\n            return 1;\n\n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\t    \n            p >>=1;\n            n*=n;\t    \n        }\n        return result;\n    }\n\n    static void debug(Object... o)\n    {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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", "complexity": "nlogn", "problem": "915_F. Imbalance Value of a Tree", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class TestClass\n{\n   public static void main(String args[])\n   {\n   \tScanner in = new Scanner(System.in);\n   \tint n = in.nextInt();\n   \tint m = in.nextInt();\n   \tint k = in.nextInt();\n   \tint arr[] = new int[n+1];\n   \tfor(int i =0;i<n;i++)\n   \t arr[i+1]= in.nextInt();\n   \t\n   \tlong sum[] = new long [n+1];\n   \t\n   \tfor(int i=1;i<=n;i++)\n   \t sum[i]=sum[i-1]+arr[i];\n   \t\n    long dp[] = new long[n+1];\n\n    for(int i =1;i<=n;i++)\n    {\n      for(int j=i;j>i-m&&j>=1;j--)\n      {\n        long val = sum[i]-sum[j-1]+dp[j-1]-k;\n        dp[i]= Math.max(dp[i],val);\n      }\t\n    }\n    long max =0;\n    for(int i =1;i<=n;i++)\n     max=Math.max(max,dp[i]);\n    \n    System.out.println(max);\n     \n   }\t\n}", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class test{\npublic static void main(String args[])\n{\nScanner s=new Scanner(System.in);\nint n=s.nextInt();\nint m=s.nextInt();\nint arr[]=new int[n];\nint max = Integer.MIN_VALUE;\n        long sum = 0;\n        for(int i=0;i<n;i++)\n        {\n            arr[i] = s.nextInt();\n            sum = sum + arr[i];\n            max = Math.max(max,arr[i]);\n        }\n        Arrays.sort(arr);\n        int i = 0;\n        int count = 0;\n        int d = 0;\n        for(i=0; i<n; i++)\n        {\n            if(arr[i] > d)\n            {\n                count++;\n                d++;\n            }\n            else if(arr[i] == d && arr[i] > 0)\n            {\n                count++;\n            }\n        }\n        //System.out.println(count + \" \" + max);\n        if(max - d > 0)\n        {\n            count = count + max - d;\n        }\n        System.out.println(sum - count);}}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class tr {\n\tstatic int[][] ad;\n    static boolean []vis;\n    static int []goods;\n    static int[][]sol;\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\tint max=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=sc.nextInt();\n\t\tStack<Integer> s=new Stack<>();\n\t\tboolean f=true;\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tmax=Math.max(max,a[i]);\n\t\t\t\t\tif(!s.isEmpty() && a[i]>s.peek())\n\t\t\t\t\t\tf=false;\n\t\t\t\t\ts.push(a[i]);\n\t\t\t\t\twhile(!s.isEmpty()) {\n\t\t\t\t\t\tint high=s.pop();\n\t\t\t\t\t\tif(s.isEmpty() || s.peek()!=high) {\n\t\t\t\t\t\t\ts.push(high);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ts.pop();\n\t\t\t\t\t}\n\t\t\t\t//\tSystem.out.println(s+\" \"+max);\n\t\t\t\t}\n\t\t\t\t//System.out.println(f+\" \"+max);\n\t\t\t\tif(f && s.size()==0)\n\t\t\t\t\tout.println(\"YES\");\n\t\t\t\telse if(f && s.size()==1 && s.peek()==max)\n\t\t\t\t\tout.println(\"YES\");\n\t\t\t\telse\n\t\t\t\t\tout.println(\"NO\");\n\t\t out.flush();\n\t}\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 pair implements Comparable<pair> {\n\t\tint a;\n\t\tint b;\n\n\t\tpair(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn a + \" \" + b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\t\t\treturn  o.a-a ;\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}", "complexity": "linear", "problem": "1092_D1. Great Vova Wall (Version 1)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class MargariteBestPresent_1080B {\n\n\tprivate static int f(int x) {\n\t\treturn (x%2==0)?x/2:(x-1)/2-x;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n,r,l;\n\t\tn = sc.nextInt();\n\t\twhile(n-->0) {\n\t\t\tl = sc.nextInt();\n\t\t\tr = sc.nextInt();\n\n\t\t\tSystem.out.println(f(r)-f(l-1));\n\t\t}\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "1080_B. Margarite and the best present", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class helloWorld \n{\n\tpublic static void main(String[] args) \n\t{\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint l = 1000, r = 0, u = 1000, b = 0;\n\t\t\n\t\tfor(int i = 0; i < n; i++ ) {\n\t\t\tString str = in.next();\n\t\t\tfor(int j = 0; j < m; j++)\n\t\t\t\tif(str.charAt(j) == 'B') {\n\t\t\t\t\tl = Math.min(j+1, l);\n\t\t\t\t\tr = Math.max(j+1, r);\n\t\t\t\t\tu = Math.min(i+1, u);\n\t\t\t\t\tb = Math.max(i+1, b);\n\t\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println((u+b)/2 + \" \" + (l+r)/2);\n\t\t\n\t\tin.close();\n\t}\n}\n\n\n\n", "complexity": "quadratic", "problem": "1028_A. Find Square", "from": "CODEFORCES"}
{"src": "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 pandusonu\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            // out.print(\"Case #\" + testNumber + \": \");\n            int n = in.readInt();\n            int[] a = in.readIntArray(n);\n            int[][] sol = new int[n][n];\n            for (int i = 0; i < n; i++) {\n                sol[0][i] = a[i];\n            }\n            for (int i = 1; i < n; i++) {\n                for (int j = 0; j < n - i; j++) {\n                    sol[i][j] = sol[i - 1][j] ^ sol[i - 1][j + 1];\n                }\n            }\n            for (int i = 1; i < n; i++) {\n                for (int j = 0; j < n - i; j++) {\n                    sol[i][j] = Math.max(sol[i][j], Math.max(sol[i - 1][j], sol[i - 1][j + 1]));\n                }\n            }\n            int q = in.readInt();\n            for (int i = 0; i < q; i++) {\n                int l = in.readInt() - 1;\n                int r = in.readInt() - 1;\n                out.println(sol[r - l][l]);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private final InputStream stream;\n        private final 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 read() {\n            try {\n                if (curChar >= numChars) {\n                    curChar = 0;\n                    numChars = stream.read(buf);\n                    if (numChars <= 0)\n                        return -1;\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n            return buf[curChar++];\n        }\n\n        public int readInt() {\n            return (int) readLong();\n        }\n\n        public long readLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n                if (c == -1) throw new RuntimeException();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? (-res) : (res);\n        }\n\n        public int[] readIntArray(int size) {\n            int[] arr = new int[size];\n            for (int i = 0; i < size; i++) arr[i] = readInt();\n            return arr;\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", "complexity": "quadratic", "problem": "983_B. XOR-pyramid", "from": "CODEFORCES"}
{"src": "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 EhabAndAComponentChoosingProblem {\n    \n    long INF = (long) 1e18;\n    \n    int n;\n    int[] a;\n    \n    int[][] G;\n    \n    void solve() {\n        n = in.nextInt();\n        a = new int[n];\n        for (int i = 0; i < n; i++) a[i] = in.nextInt();\n        int[] fr = new int[n - 1], to = new int[n - 1];\n        for (int i = 0; i < n - 1; i++) {\n            fr[i] = in.nextInt() - 1;\n            to[i] = in.nextInt() - 1;\n        }\n        G = build_graph(n, fr, to);\n        \n        int[][] ret = bfs(G, 0);\n        int[] par = ret[0], ord = ret[2];\n        \n        long best = -INF;\n        long[] dp = new long[n];\n        for (int i = n - 1; i >= 0; i--) {\n            int u = ord[i];\n            dp[u] = a[u];\n            for (int v : G[u]) {\n                if (v != par[u]) {\n                    if (dp[v] > 0) dp[u] += dp[v];\n                }\n            }\n            best = Math.max(best, dp[u]);\n        }\n        \n        int k = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            int u = ord[i];\n            dp[u] = a[u];\n            for (int v : G[u]) {\n                if (v != par[u]) {\n                    if (dp[v] > 0) dp[u] += dp[v];\n                }\n            }\n            if (dp[u] == best) {\n                dp[u] = -INF;\n                k++;\n            }\n        }\n        \n        out.printf(\"%d %d%n\", best * k, k);\n    }\n    \n    int[][] bfs(int[][] G, int root) {\n        int n = G.length;\n        \n        int[] par = new int[n];\n        Arrays.fill(par, -1);\n        \n        int[] dep = new int[n];\n        dep[root] = 0;\n        \n        int[] qu = new int[n];\n        qu[0] = root;\n        for (int l = 0, r = 1; l < r; l++) {\n            int u = qu[l];\n            for (int v : G[u]) {\n                if (v != par[u]) {\n                    qu[r++] = v;\n                    par[v] = u;\n                    dep[v] = dep[u] + 1;\n                }\n            }\n        }\n        \n        return new int[][]{par, dep, qu};\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            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]]] = to[i];\n            G[to[i]][--cnt[to[i]]] = from[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 EhabAndAComponentChoosingProblem().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", "complexity": "linear", "problem": "1088_E. Ehab and a component choosing problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class BOOL {\n    static char [][]ch;\n    static int n,m;\nprivate static FastReader in =new FastReader();\n    public static void main(String[] args) {\n    int n=in.nextInt();\n    int a[]=new int[1000002];\n    int dp[]=new int[1000002],ans=0;\n    for(int i=0;i<n;i++){a[in.nextInt()]=in.nextInt();}\n    dp[0]=a[0]==0?0:1;\n    for(int i=1;i<1000002;i++){\n    if(a[i]==0){dp[i]=dp[i-1];}\n    else{\n    if(a[i]>=i){dp[i]=1;}\n    else{\n    dp[i]=dp[i-a[i]-1]+1;\n    }}\n    if(dp[i]>=ans)ans=dp[i];\n    }\n        System.out.println(n-ans);\n    }}\nclass 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", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.lang.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.*;\n \npublic class Main {\n        \n    public static void main(String[] args) throws Exception{\n        FastReader sc=new FastReader(); \n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n        int n=sc.nextInt();\n        int[] font=new int[n];\n        int[] cost=new int[n];\n        for(int i=0;i<n;i++) {\n            font[i]=sc.nextInt();\n        \n        }\n        for(int i=0;i<n;i++) {\n            cost[i]=sc.nextInt();\n        }\n        int[] dou= new int[n];\n        for(int i=0;i<n;i++) {\n            int min=Integer.MAX_VALUE;\n            for(int j=0;j<i;j++) {\n                if(font[j]<font[i]) {\n                    if(min>cost[i]+cost[j]) {\n                        min=cost[i]+cost[j];\n                    }\n                }\n            }\n            dou[i]=min;\n        }\n        int ans=Integer.MAX_VALUE;\n        for(int i=0;i<n;i++) {\n            int min=Integer.MAX_VALUE;\n            for(int j=0;j<i;j++) {\n                if(dou[j]!=Integer.MAX_VALUE && font[j]<font[i]) {\n                    if(min>dou[j]+cost[i]) {\n                        min=dou[j]+cost[i];\n                    }\n                }\n            }\n            if(min<ans) {\n                ans=min;\n            }\n        }\n        if(ans==Integer.MAX_VALUE) {\n            System.out.println(-1);\n        }\n        else {\n            System.out.println(ans);\n        }\n    }\n}\n\nclass 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} ", "complexity": "quadratic", "problem": "987_C. Three displays", "from": "CODEFORCES"}
{"src": "/* 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\tScanner in=new Scanner(System.in);\n\t\tlong x=in.nextLong();\n\t\tlong k=in.nextLong();\n\t\t\n\t\tlong mod=1000000007;\n\t\tlong get=power(2,k,mod);\n\t\tlong ans=((get%mod)*((2*x)%mod))%mod-get+1;\n\t\tif(ans<0)\n\t\tans+=mod;\n\t\tif(x==0)\n\t\tans=0;\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\tstatic long power(long x, long y, long p)\n    {\n        // Initialize result\n        long res = 1;     \n        \n        // Update x if it is more  \n        // than or equal to p\n        x = x % p; \n     \n        while (y > 0)\n        {\n            // If y is odd, multiply x\n            // with result\n            if((y & 1)==1)\n                res = (res * x) % p;\n     \n            // y must be even now\n            // y = y / 2\n            y = y >> 1; \n            x = (x * x) % p; \n        }\n        return res;\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": " import java.util.Scanner;\n    public class New_Year_and_Curling {\n        static final double E = 0.00001;\n \n        public static void main(String[] args) {\n            Scanner sc = new Scanner(System.in);\n \n            int n = sc.nextInt();\n            int r = sc.nextInt();\n            double[] y = new double[n];\n            int arr[] = new int[n];\n \n            for (int i = 0; i < n; i++) {\n                arr[i] =sc.nextInt();\n                double top = r; // if we make it 0 and subtract from the result will get WA (do not know why!!!)\n                int x = arr[i];\n                for(int  j =0 ;j<i;j++)\n                {\n                    if(Math.abs(arr[j] -x )<=2*r) {\n \n                            top = Math.max(top  , y[j] + Math.sqrt((4 * r * r) - ((arr[j] - x) * (arr[j] - x))));\n \n                    }\n                }\n                y[i] = top ;\n                double res = y[i] ;\n                System.out.print(res+\" \");\n            }\n \n        }\n \n    }", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class ChainReaction implements Closeable {\n\n  private InputReader in = new InputReader(System.in);\n  private PrintWriter out = new PrintWriter(System.out);\n  \n  private class Beacon implements Comparable<Beacon> {\n    private int position, range, score;\n\n    private Beacon(int position, int range) {\n      this.position = position;\n      this.range = range;\n    }\n\n    public void setScore(int score) {\n      this.score = score;\n    }\n\n    @Override\n    public int compareTo(Beacon o) {\n      return Integer.compare(this.position, o.position);\n    }\n  }\n\n  public void solve() {\n    int n = in.ni();\n    if (n == 1) {\n      out.println(0);\n      return;\n    }\n    beacons = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n      beacons.add(new Beacon(in.ni(), in.ni()));\n    }\n    beacons.sort(Comparator.naturalOrder());\n    for (int i = 1; i < n; i++) {\n      int left = 0, right = i - 1, position = beacons.get(i).position, range = beacons.get(i).range;\n      int leftmost = i;\n      while (left <= right) {\n        int mid = left + (right - left) / 2;\n        if (position - range <= beacons.get(mid).position) {\n          leftmost = Math.min(leftmost, mid);\n          right = mid - 1;\n        } else {\n          left = mid + 1;\n        }\n      }\n      beacons.get(i).setScore(i - leftmost);\n    }\n    dp = new Integer[n];\n    int ans = Integer.MAX_VALUE;\n    for (int i = n - 1; i >= 0; i--) {\n      ans = Math.min(n - 1 - i + recurse(i), ans);\n    }\n    out.println(ans);\n  }\n  \n  private List<Beacon> beacons;\n  private Integer[] dp;\n  \n  private int recurse(int idx) {\n    if (idx <= 0) return 0;\n    \n    if (dp[idx] != null) return dp[idx];\n    \n    int destroyed = beacons.get(idx).score;\n    int ans = destroyed + recurse(idx - destroyed - 1);\n    return dp[idx] = ans;\n  }\n  \n  @Override\n  public void close() throws IOException {\n    in.close();\n    out.close();\n  }\n\n  static class InputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n      reader = new BufferedReader(new InputStreamReader(stream), 32768);\n      tokenizer = null;\n    }\n\n    public String next() {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n        try {\n          tokenizer = new StringTokenizer(reader.readLine());\n        } catch (IOException e) {\n          throw new RuntimeException(e);\n        }\n      }\n      return tokenizer.nextToken();\n    }\n\n    public int ni() {\n      return Integer.parseInt(next());\n    }\n\n    public long nl() {\n      return Long.parseLong(next());\n    }\n\n    public void close() throws IOException {\n      reader.close();\n    }\n  }\n\n  public static void main(String[] args) throws IOException {\n    try (ChainReaction instance = new ChainReaction()) {\n      instance.solve();\n    }\n  }\n}\n", "complexity": "nlogn", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Vector;\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        int m = sc.nextInt();\n        int a[] = new int[n];\n        int b[] = new int[n];\n        for (int i = 0; i < n; i++) a[i] = sc.nextInt();\n        for (int i = 0; i < n; i++) b[i] = sc.nextInt();\n        int c[] = new int[2 * n];\n        c[0] = a[0];\n        for (int i = 1; i < n; i++) {\n            c[i * 2] = a[i];\n            c[i * 2 - 1] = b[i];\n            if (a[i] == 1 || b[i] == 1) {\n                System.out.print(-1);\n                System.exit(0);\n            }\n        }\n        c[2 * n - 1] = b[0];\n        if (a[0] == 1 || b[0] == 1) {\n            System.out.print(-1);\n            System.exit(0);\n        }\n        System.out.println(bin_search(c, m));\n    }\n\n    private static double bin_search(int[] c, int m) {\n        double start = 0;\n        double end = Integer.MAX_VALUE;\n        double mid;\n        while (start + 0.0000001 < end) {\n            mid = (start + end) / 2;\n            if (test(mid, m, c)) end = mid;\n            else start = mid;\n        }\n        return end;\n    }\n\n    private static boolean test(double fuel, int m, int[] c) {\n        for (int i = 0; i < c.length; i++) {\n            fuel -= (m + fuel) / c[i];\n            if (fuel < 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n", "complexity": "nlogn", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n    public static void main (String[] args) {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        try {\n            String parameterStringList[] = reader.readLine().split(\" \");\n            int x = Integer.parseInt(parameterStringList[0]);\n            int y = Integer.parseInt(parameterStringList[1]);\n            int z = Integer.parseInt(parameterStringList[2]);\n            int t1 = Integer.parseInt(parameterStringList[3]);\n            int t2 = Integer.parseInt(parameterStringList[4]);\n            int t3 = Integer.parseInt(parameterStringList[5]);\n\n            int T1 = Math.abs(x-y) * t1;\n            int T2 = Math.abs(x-z) * t2 + 3*t3 + Math.abs(x-y) * t2;\n\n            if(T2 <= T1) System.out.println(\"YES\");\n            else System.out.println(\"NO\");\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}", "complexity": "constant", "problem": "1054_A. Elevator or Stairs?", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class GenerateLogin {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString a = scan.next();\n\t\tString b = scan.next();\n\t\tchar last = b.charAt(0);\n\t\tString ans = \"\"+a.charAt(0);\n\t\tfor(int i = 1;i<a.length();i++){\n\t\t\tif(a.charAt(i)>=last)break;\n\t\t\tans+=a.charAt(i);\n\t\t}\n\t\tans+=last;\n\t\tSystem.out.println(ans);\n\t}\n\n}\n", "complexity": "linear", "problem": "909_A. Generate Login", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * CodeForces Round 5D. Follow Traffic Rules\n * Created by Darren on 14-9-14.\n */\npublic class Main {\n    Reader in = new Reader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n\n    int a, v;\n    int l, d, w;\n\n    void run() throws IOException {\n        a = in.nextInt();\n        v = in.nextInt();\n        l = in.nextInt();\n        d = in.nextInt();\n        w = in.nextInt();\n\n        double totalTime = 0.0;\n        if (v >= w) {\n            if (w*w >= 2*a*d) {\n                double x = Math.sqrt(2*a*d);\n                totalTime = x / a;\n                if ((v*v-x*x) >= 2*a*(l-d))\n                    totalTime += (-2*x+Math.sqrt(4*x*x+8*a*(l-d))) / (2*a);\n                else\n                    totalTime += (v-x)/(1.0*a) + (l-d-(v*v-x*x)/(2.0*a))/v;\n            } else {\n//                totalTime = (-2*w+Math.sqrt(4*w*w+8*a*(l-d))) / (2*a);\n                if (2*v*v-w*w <= 2*a*d) {\n                    totalTime = v / (1.0*a) + (v-w) / (1.0*a) + (d-(2*v*v-w*w)/(2.0*a)) / v;\n                } else {\n                    double x = Math.sqrt((2*a*d+w*w)/2.0);\n                    totalTime = x / a + (x-w) / a;\n                }\n                if ((v*v-w*w) >= 2*a*(l-d))\n                    totalTime += (-2*w+Math.sqrt(4*w*w+8*a*(l-d))) / (2*a);\n                else\n                    totalTime += (v-w)/(1.0*a) + (l-d-(v*v-w*w)/(2.0*a))/v;\n            }\n        } else {\n            if (v*v >= 2*a*l)\n                totalTime = Math.sqrt(l*2.0/a);\n            else\n                totalTime = v / (1.0*a) + (l-v*v/(2.0*a)) / v;\n        }\n\n        out.printf(\"%.10f\", totalTime);\n        out.flush();\n    }\n\n    void solve() throws IOException {\n\n    }\n\n    static class Reader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        public Reader(InputStream input) {\n            reader = new BufferedReader(new InputStreamReader(input));\n            tokenizer = new StringTokenizer(\"\");\n        }\n\n        /** get next word */\n        String nextToken() 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        String readLine() throws IOException {\n            return reader.readLine();\n        }\n\n        char nextChar() throws IOException {\n            return (char)reader.read();\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", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "/*\n * Created on 17.05.2019\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * @author Wolfgang Weck\n */\npublic class C01Easy {\n\tpublic static void main(String[] args) {\n\t\ttry (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {\n\t\t\tfinal String[] line = r.readLine().split(\" \");\n\t\t\tfinal int N = Integer.parseInt(line[0]), P = Integer.parseInt(line[1]);\n\t\t\tfinal String[] numS = r.readLine().split(\" \");\n\t\t\tif (numS.length != N) throw new IllegalArgumentException();\n\t\t\tfinal int[] n = new int[N];\n\t\t\tint sum1 = 0, sum2 = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tn[i] = Integer.parseInt(numS[i]) % P;\n\t\t\t\tsum2 += n[i];\n\t\t\t\tif (sum2 >= P) sum2 -= P;\n\t\t\t}\n\t\t\tint max = sum2;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tsum1 += n[i];\n\t\t\t\tif (sum1 >= P) sum1 -= P;\n\t\t\t\tsum2 -= n[i];\n\t\t\t\tif (sum2 < 0) sum2 += P;\n\t\t\t\tfinal int s = sum1 + sum2;\n\t\t\t\tif (s > max) max = s;\n\t\t\t}\n\t\t\tSystem.out.println(max);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "958_C1. Encryption (easy)", "from": "CODEFORCES"}
{"src": "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        if(n==0)\n        System.out.println(0);\n        else if(n%2==1)\n        System.out.println((n+1)/2);\n        else\n        System.out.println(n+1);\n    }\n}", "complexity": "constant", "problem": "979_A. Pizza, Pizza, Pizza!!!", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.System.in;\n\npublic class Main {\n    public static void main(String[] args)throws IOException{\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[][] point = new int[n][];\n        for(int i=0;i<n;i++) point[i] = new int[]{sc.nextInt(),sc.nextInt()};\n        Arrays.sort(point,(a,b)->((a[0]-a[1])-(b[0]-b[1])));\n        TreeMap<Integer,Integer> tm = new TreeMap<>();\n        int ans = 0;\n        for(int i=n-1;i>=0;i--){\n            int x = point[i][0], w = point[i][1];\n            Map.Entry<Integer,Integer> cur =  tm.ceilingEntry(x+w);\n            int curRes;\n            if(cur==null) curRes = 1;\n            else curRes = cur.getValue()+1;\n            ans = Math.max(ans,curRes);\n            Map.Entry<Integer,Integer> upper = tm.ceilingEntry(x-w);\n            if(upper==null||upper.getValue()<curRes) tm.put(x-w,curRes);\n            //Integer key = tm.\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "nlogn", "problem": "528_B. Clique Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic 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    boolean chpr(int n)\n    {\n    \tif(n==1)\n    \t{\n    \t\treturn true;\n    \t}if(n==2)\n    \t{\n    \t\treturn true;\n    \t}\n    \tif(n==3)\n    \t{\n    \t\treturn true;\n    \t}\n    \tif(n%2==0)\n    \t{\n    \t\treturn false;\n\n    \t}\n    \tif(n%3==0)\n    \t{\n    \t\treturn false;\n    \t}\n    \t\n    \tint w=2;\n \t\tint i=5;\n    \twhile(i*i<=n)\n    \t{\n    \t\tif(n%i==0)\n    \t\t{\n    \t\t\treturn false;\n    \t\t}\n    \t\ti+=w;\n    \t\tw=6-w;\n    \t}\n    \treturn true;\n\n    }\n    \n    void solve() {\n\n\n        int n=ni();\n        int k=ni();\n        int rr=2*n;\n        int gr=5*n;\n        int br=8*n;\n        o.println((long)(Math.ceil(rr*1.0/k)+Math.ceil(gr*1.0/k)+Math.ceil(br*1.0/k)));\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n    //---------- I/O Template ----------\n    \n    public static void main(String[] args) { new bhaa().run(); }\n    void run() { \n        is = System.in; \n        o = new PrintWriter(System.out);\n        solve();\n        o.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte() { \n        if(ptr >= len) { ptr = 0; \n            try { len = is.read(input); } \n            catch(IOException e) { throw new InputMismatchException(); } \n            if(len <= 0) { return -1; } \n        } return input[ptr++];\n    }\n    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n    int skip() { \n        int b = readByte(); \n        while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n        return b;\n    }\n    \n    char nc() { return (char)skip(); }\n    String ns() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    String nLine() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    int ni() { \n        int n = 0, b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        if(b == -1) { return -1; }  //no input \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n    long nl() { \n        long n = 0L;    int b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n\n    double nd() { return Double.parseDouble(ns()); }\n    float nf() { return Float.parseFloat(ns()); }\n    int[] nia(int n) { \n        int a[] = new int[n]; \n        for(int i = 0; i < n; i++) { a[i] = ni(); } \n        return a;\n    }\n    long[] nla(int n) { \n        long a[] = new long[n]; \n        for(int i = 0; i < n; i++) { a[i] = nl(); } \n        return a;\n    }\n    int [][] nim(int n)\n    {\n        int mat[][]=new int[n][n];\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                mat[i][j]=ni();\n            }\n        }\n        return mat;\n    }\n    long [][] nlm(int n)\n    {\n        long mat[][]=new long[n][n];\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                mat[i][j]=nl();\n            }\n        }\n        return mat;\n    }\n    \n\n\n\n\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    void piarr(int arr[])\n    {\n        for(int i=0;i<arr.length;i++)\n        {\n            o.print(arr[i]+\" \");\n\n        }\n        o.println();\n    }\n    void plarr(long arr[])\n    {\n        for(int i=0;i<arr.length;i++)\n        {\n            o.print(arr[i]+\" \");\n\n        }\n        o.println();\n    }\n    \n    void pimat(int mat[][])\n    {\n        for(int i=0;i<mat.length;i++)\n        {\n            for(int j=0;j<mat[0].length;j++)\n            {\n                o.print(mat[i][j]);\n            }\n            o.println();\n        }\n    }\n    void plmat(long mat[][])\n    {\n        for(int i=0;i<mat.length;i++)\n        {\n            for(int j=0;j<mat[0].length;j++)\n            {\n                o.print(mat[i][j]);\n            }\n            o.println();\n        }\n\n    }\n\n\n\n\n    //////////////////////////////////// template finished //////////////////////////////////////\n\n\n\n}", "complexity": "constant", "problem": "1080_A. Petya and Origami", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tComp c1 = getComp(scanner);\n\t\tComp c2 = getComp(scanner);\n\t\tc1.sortByPrice();\n\t\tc2.sortByPrice();\t\n\t\tint i = 0;\n\t\tint j = 0;\n\t\twhile(i < c1.num || j < c2.num) {\n\t\t\tElem xi = (i < c1.num) ? c1.elems.get(i) : null;\n\t\t\tElem yj = (j < c2.num) ? c2.elems.get(j) : null;\n\t\t\tif(xi != null && yj != null) {\n\t\t\t\tif(xi.price >= yj.price) {\n\t\t\t\t\tif(!c2.resultSet.contains(xi)) {\n\t\t\t\t\t\tc1.resultSet.add(xi);\n\t\t\t\t\t}\n\t\t\t\t\ti++;\n\t\t\t\t} else {\n\t\t\t\t\tif(!c1.resultSet.contains(yj)) {\n\t\t\t\t\t\tc2.resultSet.add(yj);\n\t\t\t\t\t}\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t} else\n\t\t\tif(xi != null) {\n\t\t\t\tif(!c2.resultSet.contains(xi)) {\n\t\t\t\t\tc1.resultSet.add(xi);\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t} else {\n\t\t\t\tif(!c1.resultSet.contains(yj)) {\n\t\t\t\t\tc2.resultSet.add(yj);\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\t\t\t\t\n\t\t}\n\t\t\n\t\tlong result = c1.getResultPrice() + c2.getResultPrice();\n\t\tSystem.out.println(result);\n   }\n   \n   private static Comp getComp(Scanner scanner) {\n\t   Comp c = new Comp();\n\t   c.num = scanner.nextInt();\n\t   for(int i = 0; i < c.num; i++) {\n\t\t   c.addElem(scanner.nextLong(), scanner.nextLong());\n\t   }\n\t   return c;\n   }\n}\n\nclass Comp {\n\tint num;\n\tList<Elem> elems = new ArrayList<>();\n\tSet<Elem> resultSet = new HashSet<>();\n\t\n\tvoid addElem(long el, long pr) {\n\t\tElem elem = new Elem(el, pr);\n\t\telems.add(elem);\n\t}\n\t\n\tvoid sortByPrice() {\n\t\tCollections.sort(elems);\n\t}\n\t\n\tlong getResultPrice() {\n\t\tlong sumPrice = 0;\n\t\tfor(Elem elem : resultSet) {\n\t\t\tsumPrice += elem.price;\n\t\t}\n\t\t\n\t\treturn sumPrice;\n\t}\n}\n\nclass Elem implements Comparable<Elem> {\n\tlong elem;\n\tlong price;\n\t\n\tpublic Elem(long el, long pr) {\n\t\tthis.elem = el;\n\t\tthis.price = pr;\n\t}\n\t\n\tpublic int compareTo(Elem other) {\n\t\treturn (int) (other.price - price);\n\t}\n\t\n\tpublic boolean equals(Object o) {\n\t\tif(!(o instanceof Elem)) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tElem other = (Elem) o;\n\t\treturn (other.elem == elem);\n\t}\n\t\n\tpublic int hashCode() {\n\t\treturn (int) elem;\n\t}\n\t\n\tpublic String toString() {\n\t\treturn \"(\" + elem + \", \" + price + \")\";\n\t}\n}\n", "complexity": "nlogn", "problem": "981_B. Businessmen Problems", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new PrintStream(System.out));\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        int n = Integer.parseInt(st.nextToken());\n        int m = Integer.parseInt(st.nextToken());\n        long[] arrB = new long[n];\n        long[] arrG = new long[m];\n        st=new StringTokenizer(f.readLine());\n        for(int i=0;i<n;i++){\n            arrB[i]=Long.parseLong(st.nextToken());\n        }\n        st=new StringTokenizer(f.readLine());\n        for(int j=0;j<m;j++){\n            arrG[j]=Long.parseLong(st.nextToken());\n        }\n        Arrays.sort(arrB);\n        Arrays.sort(arrG);\n        long ans = 0;\n//        for (int i = 0; i < n; i++) ans += arrB[i] * m;\n//        for (int i = 0; i < m - 1; i++) ans += arrG[i] - arrB[0];\n//        if (arrB[m - 1] != arrB[0]) {\n//            if (arrB.length == 1) {\n//                ans=-1;\n//            }\n//            else ans += arrG[m - 1] - arrB[1];\n//        }\n//        if (arrG[m-1] < arrB[0]) {\n//            ans=-1;\n//        }\n        for(int i=0;i<n;i++){\n            ans+=arrB[i]*(long)m;\n        }\n        for(int i=1;i<m;i++){\n            ans+=arrG[i]-arrB[n-1];\n        }\n        if(arrB[n-1]!=arrG[0]){\n            if(n==1){\n                ans=-1;\n            }\n            else{\n                //smallest g goes to second to last\n                ans+=arrG[0]-arrB[n-2];\n            }\n        }\n        if(arrB[n-1]>arrG[0]){\n            ans=-1;\n        }\n        System.out.println(ans);\n        f.close();\n        out.close();\n    }\n}", "complexity": "nlogn", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class mad{\n    \n    public static void main(String[] args){\n        Scanner sc = new Scanner(System.in);\n        int cura = 0,curb = 0;\n        int ver;\n        System.out.println(\"? 0 0\");\n        System.out.flush();\n        ver = sc.nextInt();\n        for(int i=29;i>=0;i--){\n            System.out.println(\"? \"+(cura+(1<<i))+\" \"+curb);\n            System.out.flush();\n            int temp1 = sc.nextInt();\n            System.out.println(\"? \"+cura+\" \"+(curb+(1<<i)));\n            System.out.flush();\n            int temp2 = sc.nextInt();\n            if(temp1!=temp2){\n                if(temp2==1){\n                    cura += (1<<i);\n                    curb += (1<<i);\n                }\n            }\n            else{\n                if(ver==1) cura += (1<<i);\n                if(ver==-1) curb += (1<<i);\n                \n                ver = temp1;\n            }\n        }\n        System.out.println(\"! \"+cura+\" \"+curb);\n    }\n    \n}", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "/* 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\t\tlong n,s,p;\n\t\t\tScanner in=new Scanner(System.in);\n\t\t\tn=in.nextLong();\n\t\t\ts=in.nextLong();\n\t\t\tif(n==1 && s<=1)\n\t\t\t{\n\t\t\t    System.out.print(n-1);\n\t\t\t}\n\t        else if(s<n)\n\t        {\n\t            if(s%2!=0)\n\t\t        {System.out.print(s/2);}\n\t\t        else\n\t\t        {System.out.print(s/2-1);}\n\t        }\n\t        else if(s==n)\n\t{\n\t    if(s%2==0)\n\t\t{System.out.println((n/2)-1);}\n\t\telse\n\t\t{System.out.println(n/2);}\n\t}\n\telse if(s<=(2*n-1))\t\n\t{\n\t\tSystem.out.print((2*n+1-s)/2);\n\t}\n\telse\n\t{\n\t\tSystem.out.print(0);\n\t}\n\t}\n}", "complexity": "constant", "problem": "1023_B. Pair of Toys", "from": "CODEFORCES"}
{"src": "/*\n * Created on 17.05.2019\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * @author Wolfgang Weck\n */\npublic class A01Easy {\n\tprivate static interface Matrix {\n\t\tboolean get(int i, int j);\n\n\t\tint size();\n\t}\n\n\tprivate static class MData implements Matrix {\n\t\tprivate final boolean[][] m;\n\n\t\tMData(boolean[][] m) {\n\t\t\tthis.m = m;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean get(int i, int j) {\n\t\t\treturn m[i][j];\n\t\t}\n\n\t\t@Override\n\t\tpublic int size() {\n\t\t\treturn m.length;\n\t\t}\n\t}\n\n\tprivate static abstract class MDecorator implements Matrix {\n\t\tprotected final Matrix inner;\n\n\t\tMDecorator(Matrix inner) {\n\t\t\tthis.inner = inner;\n\t\t}\n\n\t\t@Override\n\t\tpublic int size() {\n\t\t\treturn inner.size();\n\t\t}\n\t}\n\n\tprivate static class MHFlip extends MDecorator {\n\t\tMHFlip(Matrix inner) {\n\t\t\tsuper(inner);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean get(int i, int j) {\n\t\t\treturn inner.get(size() - 1 - i, j);\n\t\t}\n\t}\n\n\tprivate static class MVFlip extends MDecorator {\n\t\tMVFlip(Matrix inner) {\n\t\t\tsuper(inner);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean get(int i, int j) {\n\t\t\treturn inner.get(i, size() - 1 - j);\n\t\t}\n\t}\n\n\tprivate static class MRot extends MDecorator {\n\t\tMRot(Matrix inner) {\n\t\t\tsuper(inner);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean get(int i, int j) {\n\t\t\treturn inner.get(j, size() - 1 - i);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {\n\t\t\tfinal int N = Integer.parseInt(r.readLine());\n\t\t\tMatrix m1 = readMatrix(r, N), m2 = readMatrix(r, N);\n\t\t\tboolean matched = matchesFlipped(m1, m2);\n\t\t\tint i = 0;\n\t\t\twhile (i < 3 && !matched) {\n\t\t\t\tm1 = new MRot(m1);\n\t\t\t\tmatched = matchesFlipped(m1, m2);\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tSystem.out.println(matched ? \"Yes\" : \"No\");\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tprivate static Matrix readMatrix(BufferedReader r, int n) throws IOException {\n\t\tboolean[][] m = new boolean[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString line = r.readLine();\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tm[i][j] = line.charAt(j) == 'X';\n\t\t\t}\n\t\t}\n\t\treturn new MData(m);\n\t}\n\n\tprivate static boolean matches(Matrix m1, Matrix m2) {\n\t\tint i = 0, j = 0, n = m1.size();\n\t\twhile (i < n && m1.get(i, j) == m2.get(i, j)) {\n\t\t\tj++;\n\t\t\tif (j == n) {\n\t\t\t\tj = 0;\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn i == n;\n\t}\n\n\tprivate static boolean matchesFlipped(Matrix m1, Matrix m2) {\n\t\treturn matches(m1, m2) || matches(new MHFlip(m1), m2) || matches(new MVFlip(m1), m2);\n\t}\n}\n", "complexity": "quadratic", "problem": "958_A1. Death Stars (easy)", "from": "CODEFORCES"}
{"src": "//Author: Patel Rag\n//Java version \"1.8.0_211\"\nimport java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n  static class FastReader\n  {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastReader(){ br = new BufferedReader(new 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 nextInt() { return Integer.parseInt(next()); }\n\n    long nextLong(){ return Long.parseLong(next()); }\n\n    double nextDouble(){ return Double.parseDouble(next()); }\n\n    float nextFloat() { return Float.parseFloat(next()); }\n\n    boolean nextBoolean() { return Boolean.parseBoolean(next()); }\n\n    String nextLine()\n    {\n      String str = \"\";\n      try\n      {\n        str = br.readLine();\n      }\n      catch (IOException e)\n      {\n        e.printStackTrace();\n      }\n      return str;\n    }\n  }\n  static long modExp(long x, long n, long mod)    //binary Modular exponentiation\n  {\n    long result = 1;\n    while(n > 0)\n    {\n        if(n % 2 == 1)\n            result = (result%mod * x%mod)%mod;\n        x = (x%mod * x%mod)%mod;\n        n=n/2;\n    }\n    return result;\n  }\n  static long gcd(long a, long b)\n  {\n    if(a==0) return b;\n    return gcd(b%a,a);\n  }\n  public static void main(String[] args)\n  throws IOException\n  {\n    FastReader fr = new FastReader();\n    int n = fr.nextInt();\n    int q = fr.nextInt();\n    long[] a = new long[n];\n    long[] k = new long[q];\n    for(int i = 0; i < n; i++) a[i] = fr.nextLong();\n    for(int i = 0; i < q; i++) k[i] = fr.nextLong();\n    long[] pre = new long[n];\n    pre[0] = a[0];\n    for(int i = 1; i < n; i++) pre[i] = pre[i-1] + a[i];\n    long pd = 0;\n    for(int i = 0; i < q; i++)\n    {\n      int l = 0;\n      int r = n - 1;\n      while(r > l)\n      {\n        int mid = (l + r) >> 1;\n\n        if(pre[mid] - pd < k[i])\n        {\n          l = mid + 1;\n        }\n        else if(pre[mid] - pd > k[i])\n        {\n          r = mid - 1;\n        }\n        else\n        {\n          l = r = mid;\n        }\n      }\n      int ans = 0;\n      if(pre[l] - pd <= k[i])\n      {\n        ans = n - l - 1;\n      }\n      else\n      {\n        ans = n - l;\n      }\n      if(ans == 0) ans  = n;\n      pd = pd + k[i];\n      if(pd >= pre[n-1]) pd = 0;\n      System.out.println(ans);\n    }\n  }\n}\nclass pair\n{\n  public int first;\n  public int second;\n  public pair(int first,int second)\n  {\n    this.first = first;\n    this.second = second;\n  }\n  public pair(pair p)\n  {\n    this.first = p.first;\n    this.second = p.second;\n  }\n  public int first() { return first; }\n  public int second() { return second; }\n  public void setFirst(int first) { this.first = first; }\n  public void setSecond(int second) { this.second = second; }\n}\nclass myComp implements Comparator<pair>\n{\n  public int compare(pair a,pair b)\n  {\n    if(a.first != b.first) return (a.first - b.first);\n    return (b.second - a.second);\n  }\n}\nclass BIT       //Binary Indexed Tree aka Fenwick Tree\n{\n  public long[] m_array;\n\n  public BIT(long[] dat)\n  {\n    m_array = new long[dat.length + 1];\n    Arrays.fill(m_array,0);\n    for(int i = 0; i < dat.length; i++)\n    {\n      m_array[i + 1] = dat[i];\n    }\n    for(int i = 1; i < m_array.length; i++)\n    {\n      int j = i + (i & -i);\n      if(j < m_array.length)\n      {\n        m_array[j] = m_array[j] + m_array[i];\n      }\n    }\n  }\n\n  public final long prefix_query(int i)\n  {\n    long result = 0;\n    for(++i; i > 0; i = i - (i & -i))\n    {\n      result = result + m_array[i];\n    }\n    return result;\n  }\n\n  public final long range_query(int fro, int to)\n  {\n    if(fro == 0)\n    {\n      return prefix_query(to);\n    }\n    else\n    {\n      return (prefix_query(to) - prefix_query(fro - 1));\n    }\n  }\n\n  public void update(int i, long add)\n  {\n    for(++i; i < m_array.length; i = i + (i & -i))\n    {\n      m_array[i] = m_array[i] + add;\n    }\n  }\n}\n", "complexity": "nlogn", "problem": "975_C. Valhalla Siege", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.*;\nimport java.security.SecureRandom;\n\npublic class WCS {\n\t\n\tpublic static class Vector implements Comparable <Vector>  {\n\t\tlong x, y;\n\t\tint position;\n\t\tVector first, second;\n\t\tboolean toReverse;\n\t\t\n\t\tpublic Vector(long xx, long yy, int p) {\n\t\t\tx = xx;\n\t\t\ty = yy;\n\t\t\tposition = p;\n\t\t\tfirst = null;\n\t\t\tsecond = null;\n\t\t\ttoReverse = false;\n\t\t}\n\t\t\n\t\tpublic Vector negate() {\n\t\t\tVector vv = new Vector(-x, -y, position);\n\t\t\tvv.first = first;\n\t\t\tvv.second = second;\n\t\t\tvv.toReverse = !toReverse;\n\t\t\treturn vv;\n\t\t}\n\t\t\n\t\tpublic Vector add(Vector v) {\n\t\t\tVector sum = new Vector(this.x + v.x, this.y + v.y, position);\n\t\t\tsum.first = this;\n\t\t\tsum.second = v;\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tpublic Vector subtract(Vector v) {\n\t\t\treturn this.add(v.negate());\n\t\t}\n\t\t\n\t\tpublic double euclideanNorm() {\n\t\t\treturn Math.sqrt(x * x + y * y);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Vector v) {\n\t\t\tdouble thisa = Math.atan2(this.y, this.x);\n\t\t\tdouble va = Math.atan2(v.y, v.x);\n\t\t\tif(thisa < 0)\n\t\t\t\tthisa += 2 * Math.PI;\n\t\t\tif(va < 0)\n\t\t\t\tva += 2 * Math.PI;\n\t\t\tif(thisa < va)\n\t\t\t\treturn -1;\n\t\t\tif(thisa > va)\n\t\t\t\treturn 1;\n\t\t\treturn Integer.compare(this.position, v.position);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y;\n\t\t}\n\t}\n\t\n\tpublic static void dfs(Vector curr, int[] ans) {\n\t\tif(curr.first == null) {\n\t\t\tans[curr.position] = curr.toReverse ? -1 : 1;\n\t\t\treturn;\n\t\t}\n\t\tcurr.first.toReverse ^= curr.toReverse;\n\t\tcurr.second.toReverse ^= curr.toReverse;\n\t\tdfs(curr.first, ans);\n\t\tdfs(curr.second, ans);\n\t}\n\t\n\tpublic static boolean ok(Vector v1, Vector v2) {\n\t\treturn v1.add(v2).euclideanNorm() <= Math.max(v1.euclideanNorm(), v2.euclideanNorm());\n\t}\n\t\n\tpublic static void stop(long k) {\n\t\tlong time = System.currentTimeMillis();\n\t\twhile(System.currentTimeMillis() - time < k);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = in.nextInt();\n\t\tTreeSet <Vector> vectors = new TreeSet <> ();\n\t\tfor(int i = 0; i < n; i ++) {\n\t\t\tVector v = new Vector(in.nextLong(), in.nextLong(), i);\n\t\t\tvectors.add(v);\n\t\t}\n\t\twhile(vectors.size() > 2) {\n\t\t\t//System.out.println(vectors);\n\t\t\t//stop(500);\n\t\t\t\n\t\t\tTreeSet <Vector> support = new TreeSet <> ();\n\t\t\t\n\t\t\twhile(vectors.size() > 0) {\n\t\t\t\tVector curr = vectors.pollFirst();\n\t\t\t\tVector next1 = vectors.higher(curr);\n\t\t\t\tVector next2 = vectors.lower(curr.negate());\n\t\t\t\tVector next3 = vectors.higher(curr.negate());\n\t\t\t\tVector next4 = vectors.lower(curr);\n\t\t\t\t\n\t\t\t\t//System.out.println(\"CURR: \" + curr + \"\\n\" + next1 + \"\\n\" + next2);\n\t\t\t\t\n\t\t\t\tif(next1 != null) {\n\t\t\t\t\tif(ok(curr, next1)) {\n\t\t\t\t\t\tsupport.add(curr.add(next1));\n\t\t\t\t\t\tvectors.remove(next1);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next1 != null) {\n\t\t\t\t\tif(ok(curr, next1.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next1));\n\t\t\t\t\t\tvectors.remove(next1);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next2 != null) {\n\t\t\t\t\tif(ok(curr, next2)) {\n\t\t\t\t\t\tsupport.add(curr.add(next2));\n\t\t\t\t\t\tvectors.remove(next2);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next2 != null) {\n\t\t\t\t\tif(ok(curr, next2.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next2));\n\t\t\t\t\t\tvectors.remove(next2);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next3 != null) {\n\t\t\t\t\tif(ok(curr, next3)) {\n\t\t\t\t\t\tsupport.add(curr.add(next3));\n\t\t\t\t\t\tvectors.remove(next3);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next3 != null) {\n\t\t\t\t\tif(ok(curr, next3.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next3));\n\t\t\t\t\t\tvectors.remove(next3);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next4 != null) {\n\t\t\t\t\tif(ok(curr, next4)) {\n\t\t\t\t\t\tsupport.add(curr.add(next4));\n\t\t\t\t\t\tvectors.remove(next4);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next4 != null) {\n\t\t\t\t\tif(ok(curr, next4.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next4));\n\t\t\t\t\t\tvectors.remove(next4);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tsupport.add(curr);\n\t\t\t}\n\t\t\t\n\t\t\tvectors = support;\n\t\t}\n\t\t\n\t\tif(vectors.size() == 2) {\n\t\t\tVector curr = vectors.pollFirst();\n\t\t\tVector next = vectors.pollFirst();\n\t\t\tVector add = curr.add(next);\n\t\t\tVector sub = curr.subtract(next);\n\t\t\tif(sub.euclideanNorm() <= add.euclideanNorm())\n\t\t\t\tvectors.add(sub);\n\t\t\telse\n\t\t\t\tvectors.add(add);\n\t\t}\n\t\t\n\t\t//System.out.println(vectors.first().euclideanNorm());\n\t\t\n\t\tStringBuilder buffer = new StringBuilder();\n\t\tint[] ans = new int[n];\n\t\tdfs(vectors.pollFirst(), ans);\n\t\tfor(int i = 0; i < n; i ++)\n\t\t\tbuffer.append(ans[i] + \" \");\n\t\tSystem.out.println(buffer);\n\t}\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                }\n                catch (IOException  e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n \n        BigInteger nextBigInteger() {\n        \treturn new BigInteger(in.next());\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        char nextChar() {\n            return in.next().charAt(0);\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            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n    \n    static FastReader in = new FastReader();\n    static OutputStream out = new BufferedOutputStream(System.out);\n    \n    public static byte[] toByte(Object o) {\n        return String.valueOf(o).getBytes();\n    }\n    \n    public static void sop(Object o) {\n        System.out.print(o);\n    }\n}", "complexity": "nlogn", "problem": "995_C. Leaving the Bar", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A4 {\n\n    public BufferedReader input;\n    public PrintWriter output;\n    public StringTokenizer stoken = new StringTokenizer(\"\");\n\n    public static void main(String[] args) throws IOException {\n        new A4();\n    }\n\n    A4() throws IOException {\n        input = new BufferedReader(new InputStreamReader(System.in));\n        output = new PrintWriter(System.out);\n        run();\n        input.close();\n        output.close();\n    }\n\n    private void run() throws IOException {\n        int n = Math.toIntExact(nextLong());\n        int m = Math.toIntExact(nextLong());\n        int[] coor = new int[n + 1];\n        int[] ss = new int[n + 1];\n        for (int i = 0; i < n; i++) {\n            coor[i] = Math.toIntExact(nextLong());\n        }\n        coor[n] = 1000000000;\n        Arrays.sort(coor);\n        for (int i = 0; i < m; i++) {\n            long x1 = nextLong();\n            long x2 = nextLong();\n            nextLong();\n            if (x1 == 1 && x2 >= coor[0]) {\n                int l = 0;\n                int r = n + 1;\n                while (r - l > 1) {\n                    int mi = (r + l) / 2;\n                    if (coor[mi] > x2) {\n                        r = mi;\n                    } else {\n                        l = mi;\n                    }\n                }\n                ss[l]++;\n            }\n        }\n        long[] ans = new long[n + 1];\n        ans[n] = ss[n] + n;\n        long min = ans[n];\n        for (int i = n - 1; i > -1; i--) {\n            ans[i] = ans[i + 1] - 1 + ss[i];\n            if (ans[i] < min) {\n                min = ans[i];\n            }\n        }\n        System.out.println(min);\n    }\n\n    private Long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    private String nextString() throws IOException {\n        while (!stoken.hasMoreTokens()) {\n            String st = input.readLine();\n            stoken = new StringTokenizer(st);\n        }\n        return stoken.nextToken();\n    }\n}", "complexity": "nlogn", "problem": "1075_C. The Tower is Going Home", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Codechef{\n\tstatic int max=Integer.MIN_VALUE;\n\tstatic int res=0;\n\tstatic int[] checkMax(int arr[],int j){\n             int sum=0;\n             int x=arr[j];\n        \t\twhile(x!=0){\n        \t\t        if(j+1==15){\n        \t\t        \tj=0;\n        \t\t        }else{\n        \t\t        \tarr[j+1]=arr[j+1]+1;\n        \t\t        }\n        \t\t        // if(arr[j+1]%2==0){\n        \t\t        // \tsum=sum+arr[j+1];\n        \t\t        // \tif(sum>=max){\n        \t\t        // \tmax=sum;\n        \t\t        // }\n        \t\t        // }\n\n        \t\t        \n        \t\t        x--;\n        \t\t        j++;\n        \t\t}\n        \t\t     return arr;\n\n\t}\n      \n\n    public static void main(String []args){\n       Scanner sc = new Scanner (System.in);\n    long a [] = new long [14];\n    long b [] = new long [14];\n    long p,q,r,s,max = 0;\n    for(int i = 0; i < 14; i++) a[i] = sc.nextInt();\n    for(int i = 0; i < 14; i++){\n      p = a[i]%14;\n      q = a[i]/14;\n      r = 0;\n      s = 0;\n      for(int j = 0; j < 14; j++) b[j] = a[j];\n      b[i] = 0;\n      int j = (i+1)%14;\n      for(; r < p; r++) {\n        b[j]++;\n        j=(j+1)%14;\n      }\n      for( j = 0; j < 14; j++) {\n        b[j] += q;\n        if(b[j] % 2 == 0) s+= b[j];\n      }\n      max = Math.max(max,s);\n    }\n    System.out.println(max);\n\n\n\n    }\n\n}", "complexity": "constant", "problem": "975_B. Mancala", "from": "CODEFORCES"}
{"src": "import javafx.util.Pair;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Beacon8 {\n    public static void main(String[] args) throws IOException {\n//        int[] arr = {1, 3, 7, 18};\n//        int bIndex = Arrays.binarySearch(arr, 4);\n//        System.out.println(bIndex);\n\n\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        Map<Integer, Integer> beacons = new TreeMap<>();\n\n        for (int i = 0; i < n; i++) {\n            int index = scan.nextInt();\n            int power = scan.nextInt();\n            beacons.put(index, power);\n        }\n        int[] indicesArr = new int[n];\n        int arrInd = 0;\n        for (int index : beacons.keySet()) {\n            indicesArr[arrInd] = index;\n            arrInd++;\n        }\n       // Integer[] indicesArr = ((Integer[])beacons.keySet().toArray());\n        int[] nDestroys = new int[n];\n        for (int i = 0; i < n; i++) {\n            int bIndex = Arrays.binarySearch(indicesArr, indicesArr[i] - beacons.get(indicesArr[i]));\n            if (bIndex < 0)\n                bIndex = -(bIndex + 1);\n            nDestroys[i] = i - bIndex;\n        }\n        int[] totalBeacons = new int[n];\n        int maxBeacons = 1;\n        totalBeacons[0] = 1;\n        for (int i = 1; i < n; i++) {\n            if (nDestroys[i] == 0)\n                totalBeacons[i] = totalBeacons[i - 1] + 1;\n            else {\n                if ((i - nDestroys[i] - 1) >= 0)\n                    totalBeacons[i] = totalBeacons[i - nDestroys[i] - 1] + 1;\n                else\n                    totalBeacons[i] = 1;\n            }\n               // totalBeacons[i] = totalBeacons[i - nDestroys[i]] + 1;\n            //totalBeacons[i] = i - nDestroys[i] + totalBeacons[i - nDestroys[i]] + 1;\n            if(totalBeacons[i] > maxBeacons)\n                maxBeacons = totalBeacons[i];\n        }\n//        System.out.println(\"\\ntotalBeacons array\");\n//        for (int i = 0; i < n; i++) {\n//            System.out.print(totalBeacons[i] + \" \");\n//        }\n//        if (maxBeacons == -1)\n//            System.out.println(n);\n        System.out.println(n - maxBeacons);\n    }\n\n}\n", "complexity": "nlogn", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1082D {\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[] aa = new int[n];\n\t\tint[] i1 = new int[n];\n\t\tint[] i2 = new int[n];\n\t\tint n1 = 0, n2 = 0, m2 = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = Integer.parseInt(st.nextToken());\n\t\t\taa[i] = a;\n\t\t\tif (a == 1)\n\t\t\t\ti1[n1++] = i;\n\t\t\telse {\n\t\t\t\ti2[n2++] = i;\n\t\t\t\tm2 += a;\n\t\t\t}\n\t\t}\n\t\tif (m2 < (n2 - 1) * 2 + n1) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tint m = n2 - 1 + n1;\n\t\tint d = n2 - 1 + Math.min(n1, 2);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(\"YES \" + d);\n\t\tpw.println(m);\n\t\tfor (int i = 0; i + 1 < n2; i++) {\n\t\t\tpw.println((i2[i] + 1) + \" \" + (i2[i + 1] + 1));\n\t\t\taa[i2[i]]--; aa[i2[i + 1]]--;\n\t\t}\n\t\tif (n1 > 0) {\n\t\t\twhile (n2 > 0 && aa[i2[n2 - 1]] == 0)\n\t\t\t\tn2--;\n\t\t\tpw.println((i2[n2 - 1] + 1) + \" \" + (i1[n1 - 1] + 1));\n\t\t\taa[i2[n2 - 1]]--;\n\t\t\tn1--;\n\t\t}\n\t\tfor (int i = 0, j = 0; j < n1; j++) {\n\t\t\twhile (aa[i2[i]] == 0)\n\t\t\t\ti++;\n\t\t\tpw.println((i2[i] + 1) + \" \" + (i1[j] + 1));\n\t\t\taa[i2[i]]--;\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "linear", "problem": "1082_D. Maximum Diameter Graph", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\n\npublic class Div1_526C {\n\n\tstatic int nV;\n\n\tstatic ArrayList<Integer>[] chldn;\n\n\tstatic int root;\n\n\tstatic int[][] anc;\n\tstatic int[] depth;\n\n\tstatic int[] num;\n\n\tstatic int[] nLoc;\n\n\tstatic int[][] tree;\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\tnV = Integer.parseInt(reader.readLine());\n\n\t\tchldn = new ArrayList[nV];\n\t\tfor (int i = 0; i < nV; i++) {\n\t\t\tchldn[i] = new ArrayList<>();\n\t\t}\n\n\t\tanc = new int[nV][21];\n\t\tdepth = new int[nV];\n\n\t\tnum = new int[nV];\n\t\tnLoc = new int[nV];\n\t\ttree = new int[nV * 4][2];\n\t\tfor (int[] a : tree) {\n\t\t\ta[0] = a[1] = -1;\n\t\t}\n\n\t\troot = 0;\n\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 0; i < nV; i++) {\n\t\t\tnum[i] = Integer.parseInt(inputData.nextToken());\n\t\t\tnLoc[num[i]] = i;\n\t\t}\n\n\t\tinputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 1; i < nV; i++) {\n\t\t\tanc[i][0] = Integer.parseInt(inputData.nextToken()) - 1;\n\t\t\tchldn[anc[i][0]].add(i);\n\t\t}\n\n\t\tpreprocess();\n\n\t\tbuild(1, 0, nV - 1);\n\n\t\tint nQ = Integer.parseInt(reader.readLine());\n\n\t\twhile (nQ-- > 0) {\n\t\t\tinputData = new StringTokenizer(reader.readLine());\n\t\t\tif (inputData.nextToken().equals(\"1\")) {\n\t\t\t\tint a = Integer.parseInt(inputData.nextToken()) - 1;\n\t\t\t\tint b = Integer.parseInt(inputData.nextToken()) - 1;\n\n\t\t\t\tint temp = num[a];\n\t\t\t\tnum[a] = num[b];\n\t\t\t\tnum[b] = temp;\n\n\t\t\t\tnLoc[num[a]] = a;\n\t\t\t\tnLoc[num[b]] = b;\n\n\t\t\t\tupdate(1, 0, nV - 1, num[a]);\n\t\t\t\tupdate(1, 0, nV - 1, num[b]);\n\t\t\t} else {\n\t\t\t\tprinter.println(query(1, 0, nV - 1, nLoc[0], nLoc[0]) + 1);\n\t\t\t}\n\t\t}\n\t\tprinter.close();\n\t}\n\n\tstatic void build(int nI, int cL, int cR) {\n\t\tif (cL == cR) {\n\t\t\ttree[nI][0] = nLoc[cL];\n\t\t\ttree[nI][1] = nLoc[cL];\n\t\t} else {\n\t\t\tint mid = (cL + cR) >> 1;\n\t\t\tbuild(nI * 2, cL, mid);\n\t\t\tbuild(nI * 2 + 1, mid + 1, cR);\n\t\t\tif (tree[nI * 2][0] != -1 && tree[nI * 2 + 1][0] != -1) {\n\t\t\t\tmerge(tree[nI * 2][0], tree[nI * 2][1], tree[nI * 2 + 1][0], tree[nI * 2 + 1][1]);\n\t\t\t\ttree[nI][0] = mResp[0];\n\t\t\t\ttree[nI][1] = mResp[1];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int query(int nI, int cL, int cR, int e1, int e2) {\n\t\tif (cL == cR) {\n\t\t\tmerge(e1, e2, nLoc[cL], nLoc[cL]);\n\t\t\tif (mResp[0] != -1) {\n\t\t\t\treturn cL;\n\t\t\t} else {\n\t\t\t\treturn cL - 1;\n\t\t\t}\n\t\t}\n\t\tint mid = (cL + cR) >> 1;\n\n\t\tmerge(tree[nI * 2][0], tree[nI * 2][1], e1, e2);\n\t\tif (mResp[0] != -1) {\n\t\t\treturn query(nI * 2 + 1, mid + 1, cR, mResp[0], mResp[1]);\n\t\t}\n\t\treturn query(nI * 2, cL, mid, e1, e2);\n\t}\n\n\tstatic void update(int nI, int cL, int cR, int uI) {\n\t\tif (cL == cR) {\n\t\t\ttree[nI][0] = nLoc[cL];\n\t\t\ttree[nI][1] = nLoc[cL];\n\t\t} else {\n\t\t\tint mid = (cL + cR) >> 1;\n\t\t\tif (uI <= mid) {\n\t\t\t\tupdate(nI * 2, cL, mid, uI);\n\t\t\t} else {\n\t\t\t\tupdate(nI * 2 + 1, mid + 1, cR, uI);\n\t\t\t}\n\t\t\tmerge(tree[nI * 2][0], tree[nI * 2][1], tree[nI * 2 + 1][0], tree[nI * 2 + 1][1]);\n\t\t\ttree[nI][0] = mResp[0];\n\t\t\ttree[nI][1] = mResp[1];\n\t\t}\n\t}\n\n\tstatic int[] mResp = new int[2];\n\n\tstatic void merge1(int... a) {\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tif (a[i] == -1) {\n\t\t\t\tmResp[0] = mResp[1] = -1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif (onPath(a[0], a[1], a[2])) {\n\t\t\tmResp[0] = a[0];\n\t\t\tmResp[1] = a[1];\n\t\t\treturn;\n\t\t}\n\t\tif (onPath(a[0], a[2], a[1])) {\n\t\t\tmResp[0] = a[0];\n\t\t\tmResp[1] = a[2];\n\t\t\treturn;\n\t\t}\n\t\tif (onPath(a[1], a[2], a[0])) {\n\t\t\tmResp[0] = a[1];\n\t\t\tmResp[1] = a[2];\n\t\t\treturn;\n\t\t}\n\t\tmResp[0] = mResp[1] = -1;\n\t}\n\n\tstatic void merge(int... a) {\n\t\tmerge1(a[0], a[1], a[2]);\n\t\tmerge1(mResp[0], mResp[1], a[3]);\n\t}\n\n\tstatic boolean onPath(int a, int b, int c) {\n\t\tif (a == c || b == c) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (depth[a] > depth[c]) {\n\t\t\ta = jump(a, depth[a] - depth[c] - 1);\n\t\t}\n\t\tif (depth[b] > depth[c]) {\n\t\t\tb = jump(b, depth[b] - depth[c] - 1);\n\t\t}\n\t\tif (a == b) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (anc[a][0] == c || anc[b][0] == c) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t// good for depth of up to 1_048_576 = 2^20\n\n\tstatic void preprocess() {\n\t\tanc[root][0] = root;\n\t\tfParent(root);\n\n\t\tfor (int k = 1; k <= 20; k++) {\n\t\t\tfor (int i = 0; i < nV; i++) {\n\t\t\t\tanc[i][k] = anc[anc[i][k - 1]][k - 1];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void fParent(int cV) {\n\t\tfor (int aV : chldn[cV]) {\n\t\t\tanc[aV][0] = cV;\n\t\t\tdepth[aV] = depth[cV] + 1;\n\t\t\tfParent(aV);\n\t\t}\n\t}\n\n\tstatic int fLCA(int a, int b) {\n\t\tif (depth[a] > depth[b]) {\n\t\t\tint temp = b;\n\t\t\tb = a;\n\t\t\ta = temp;\n\t\t}\n\t\tb = jump(b, depth[b] - depth[a]);\n\t\tif (a == b) {\n\t\t\treturn a;\n\t\t}\n\t\tfor (int i = 20; i >= 0; i--) {\n\t\t\tif (anc[a][i] != anc[b][i]) {\n\t\t\t\ta = anc[a][i];\n\t\t\t\tb = anc[b][i];\n\t\t\t}\n\t\t}\n\t\treturn anc[a][0];\n\t}\n\n\tstatic int jump(int cV, int d) {\n\t\tfor (int i = 0; i <= 20; i++) {\n\t\t\tif ((d & (1 << i)) != 0) {\n\t\t\t\tcV = anc[cV][i];\n\t\t\t}\n\t\t}\n\t\treturn cV;\n\t}\n\n\tstatic Comparator<Integer> BY_DEPTH = new Comparator<Integer>() {\n\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\treturn -Integer.compare(depth[o1], depth[o2]); // greatest depth first\n\t\t}\n\t};\n}", "complexity": "nlogn", "problem": "1084_F. Max Mex", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class round569d2b {\n\n\tpublic static void main(String args[]) {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\t\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\t\tif (n % 2 == 0) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (arr[i] >= 0) {\n\t\t\t\t\tarr[i] = -1*arr[i]-1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tint max = Integer.MIN_VALUE;\n\t\t\tint maxIndex = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint elem = arr[i];\n\t\t\t\tif (elem < 0) {\n\t\t\t\t\telem = -1*elem-1;\n\t\t\t\t}\n\t\t\t\tif (elem > max) {\n\t\t\t\t\tmax = elem;\n\t\t\t\t\tmaxIndex = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i == maxIndex) {\n\t\t\t\t\tif (arr[i] < 0) {\n\t\t\t\t\t\tarr[i] = -1*arr[i]-1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (arr[i] >= 0) {\n\t\t\t\t\t\tarr[i] = -1*arr[i]-1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < n ;i++) {\n\t\t\tsb.append(arr[i] + \" \");\n\t\t\t\n\t\t}\n\t\tSystem.out.println(sb);\n\n\t}\n\n\t// ======================================================================================\n\t// =============================== Reference Code =======================================\n\t// ======================================================================================\n\n\tstatic int greatestDivisor(int n) {\n\t\tint limit = (int) Math.sqrt(n);\n\t\tint max = 1;\n\t\tfor (int i = 2; i <= limit; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tmax = Integer.max(max, i);\n\t\t\t\tmax = Integer.max(max, n / i);\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n\n\t// Method to return all primes smaller than or equal to \n\t// n using Sieve of Eratosthenes \n\tstatic boolean[] sieveOfEratosthenes(int n) {\n\t\t// Create a boolean array \"prime[0..n]\" and initialize \n\t\t// all entries it as true. A value in prime[i] will \n\t\t// finally be false if i is Not a prime, else true. \n\t\tboolean prime[] = new boolean[n + 1];\n\t\tfor (int i = 0; i <= n; i++)\n\t\t\tprime[i] = true;\n\n\t\tprime[0] = false;\n\t\tprime[1] = false;\n\n\t\tfor (int p = 2; p * p <= n; p++) {\n\t\t\t// If prime[p] is not changed, then it is a prime \n\t\t\tif (prime[p] == true) {\n\t\t\t\t// Update all multiples of p \n\t\t\t\tfor (int i = p * p; i <= n; i += p)\n\t\t\t\t\tprime[i] = false;\n\t\t\t}\n\t\t}\n\n\t\treturn prime;\n\t}\n\n\t// Binary search for number greater than or equal to target\n\t// returns -1 if number not found\n\tprivate static int bin_gteq(int[] a, int key) {\n\t\tint low = 0;\n\t\tint high = a.length;\n\t\tint max_limit = high;\n\t\twhile (low < high) {\n\t\t\tint mid = low + (high - low) / 2;\n\t\t\tif (a[mid] < key) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else\n\t\t\t\thigh = mid;\n\t\t}\n\n\t\treturn high == max_limit ? -1 : high;\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\tif (a == 0)\n\t\t\treturn b;\n\n\t\treturn gcd(b % a, a);\n\t}\n\n\tstatic class Tuple<X, Y> {\n\t\tpublic final X x;\n\t\tpublic final Y y;\n\n\t\tpublic Tuple(X x, Y 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\t}\n\n\tstatic class Tuple3<X, Y, Z> {\n\t\tpublic final X x;\n\t\tpublic final Y y;\n\t\tpublic final Z z;\n\n\t\tpublic Tuple3(X x, Y y, Z z) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.z = z;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \",\" + y + \",\" + z + \")\";\n\t\t}\n\t}\n\n\tstatic Tuple3<Integer, Integer, Integer> gcdExtended(int a, int b, int x, int y) {\n\t\t// Base Case \n\t\tif (a == 0) {\n\t\t\tx = 0;\n\t\t\ty = 1;\n\t\t\treturn new Tuple3(0, 1, b);\n\t\t}\n\n\t\tint x1 = 1, y1 = 1; // To store results of recursive call \n\t\tTuple3<Integer, Integer, Integer> tuple = gcdExtended(b % a, a, x1, y1);\n\t\tint gcd = tuple.z;\n\t\tx1 = tuple.x;\n\t\ty1 = tuple.y;\n\n\t\t// Update x and y using results of recursive \n\t\t// call \n\t\tx = y1 - (b / a) * x1;\n\t\ty = x1;\n\n\t\treturn new Tuple3(x, y, gcd);\n\t}\n\n\t// Returns modulo inverse of a  \n\t// with respect to m using extended \n\t// Euclid Algorithm. Refer below post for details: \n\t// https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/ \n\tstatic int inv(int a, int m) {\n\t\tint m0 = m, t, q;\n\t\tint x0 = 0, x1 = 1;\n\n\t\tif (m == 1)\n\t\t\treturn 0;\n\n\t\t// Apply extended Euclid Algorithm \n\t\twhile (a > 1) {\n\t\t\t// q is quotient \n\t\t\tq = a / m;\n\n\t\t\tt = m;\n\n\t\t\t// m is remainder now, process \n\t\t\t// same as euclid's algo \n\t\t\tm = a % m;\n\t\t\ta = t;\n\n\t\t\tt = x0;\n\n\t\t\tx0 = x1 - q * x0;\n\n\t\t\tx1 = t;\n\t\t}\n\n\t\t// Make x1 positive \n\t\tif (x1 < 0)\n\t\t\tx1 += m0;\n\n\t\treturn x1;\n\t}\n\n\t// k is size of num[] and rem[]. \n\t// Returns the smallest number \n\t// x such that: \n\t// x % num[0] = rem[0], \n\t// x % num[1] = rem[1], \n\t// .................. \n\t// x % num[k-2] = rem[k-1] \n\t// Assumption: Numbers in num[] are pairwise  \n\t// coprime (gcd for every pair is 1) \n\tstatic int findMinX(int num[], int rem[], int k) {\n\t\t// Compute product of all numbers \n\t\tint prod = 1;\n\t\tfor (int i = 0; i < k; i++)\n\t\t\tprod *= num[i];\n\n\t\t// Initialize result \n\t\tint result = 0;\n\n\t\t// Apply above formula \n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint pp = prod / num[i];\n\t\t\tresult += rem[i] * inv(pp, num[i]) * pp;\n\t\t}\n\n\t\treturn result % prod;\n\t}\n\n\t/**\n\t * Source: Matt Fontaine\n\t */\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 chars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tint read() {\n\t\t\tif (chars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= chars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tchars = 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 (chars <= 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\t}\n\n}", "complexity": "linear", "problem": "1180_B. Nick and Array", "from": "CODEFORCES"}
{"src": "/**\n *   Author: Ridam Nagar\n *   Date: 27 February 2019\n *   Time: 01:17:36\n**/\n/* \npackage codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{     \n  static String reverse(String s){\n    String reverse=\"\";\n    for(int i=s.length()-1;i>=0;i--){\n        reverse=reverse + s.charAt(i);\n    }\n    return reverse;\n  }\n\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 x=m%(int)Math.pow(2,n);\n         System.out.println(x);\n\n\n\n}\n}", "complexity": "constant", "problem": "913_A. Modular Exponentiation", "from": "CODEFORCES"}
{"src": "import org.omg.PortableServer.AdapterActivator;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.net.CookieHandler;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.util.concurrent.LinkedBlockingDeque;\n\nimport static java.lang.Math.*;\n\npublic class TaskA implements Runnable {\n    long m = (int)1e9+7;\n    PrintWriter w;\n    InputReader c;\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n        int n = c.nextInt();\n        int a[] = scanArrayI(n);\n        int maxtime = Integer.MAX_VALUE,ind = -1;\n        for(int i=0;i<n;i++){\n            int time = Integer.MAX_VALUE;\n            if(a[i]<i+1)\n                time = i;\n            else{\n                time = (int)ceil((a[i] - i)/(double)n) * n + i;\n            }\n            if(time<maxtime){\n                maxtime = time;\n                ind = i;\n            }\n        }\n        w.println(ind+1);\n        w.close();\n    }\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static void sortbyColumn(int arr[][], int col){\n        Arrays.sort(arr, new Comparator<int[]>()\n        {\n            public int compare(int[] o1, int[] o2){\n                return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    public static class DJSet {\n        public int[] upper;\n\n        public DJSet(int n) {\n            upper = new int[n];\n            Arrays.fill(upper, -1);\n        }\n\n        public int root(int x) {\n            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n        }\n\n        public boolean equiv(int x, int y) {\n            return root(x) == root(y);\n        }\n\n        public boolean union(int x, int y) {\n            x = root(x);\n            y = root(y);\n            if (x != y) {\n                if (upper[y] < upper[x]) {\n                    int d = x;\n                    x = y;\n                    y = d;\n                }\n                upper[x] += upper[y];\n                upper[y] = x;\n            }\n            return x == y;\n        }\n    }\n    public static int[] radixSort(int[] f)    {\n        int[] to = new int[f.length];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n    public void printArray(int[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n){\n        int a[] = new int[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n){\n        long a[] = new long[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars==-1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                }\n                catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        public int nextInt() {\n            int c = read();\n\n            while(isSpaceChar(c))\n                c = read();\n\n            int sgn = 1;\n\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n\n            int res = 0;\n            do {\n                if(c<'0'||c>'9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskA(),\"TaskA\",1<<26).start();\n    }\n}", "complexity": "nlogn", "problem": "996_B. World Cup", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\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    int m = in.nextInt();\n    long boyMax = 0;\n    int NBoyMax = 0;\n\n    long sweets = 0;\n    TreeSet<Long> boyMember = new TreeSet<>();\n    for (int i = 0; i < n; i++) {\n      long input = in.nextLong();\n      boyMember.add(input);\n      if (boyMax < input) {\n        boyMax = input;\n        NBoyMax = 1;\n      } else if (boyMax == input) NBoyMax++;\n      sweets += (input * m);\n    }\n\n    long smallestGirl = (long) 1e8 + 1;\n    long sum = 0;\n    for (int i = 0; i < m; i++) {\n      long input = in.nextLong();\n      sum += input;\n      if (smallestGirl > input) smallestGirl = input;\n    }\n\n    if (smallestGirl < boyMember.last()) {\n      out.println(-1);\n    } else if (smallestGirl == boyMember.last()) {\n      sweets += sum - boyMember.last() * m;\n      out.println(sweets);\n    } else {\n\n      if (NBoyMax > 1) {\n        sweets += sum - boyMember.last() * m;\n        out.println(sweets);\n      } else {\n        Object[] boyList = boyMember.toArray();\n        if (boyList.length > 1) {\n          long boy = 0;\n          boy = (long)boyList[boyList.length - 2];\n          sweets += (sum - smallestGirl - boyMember.last() * (m - 1));\n          sweets += (smallestGirl - boy);\n          out.println(sweets);\n        } else {\n          out.println(-1);\n        }\n      }\n    }\n\n    in.close();\n    out.close();\n  }\n}", "complexity": "linear", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class Split {\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 k= sc.nextInt();\n\t\tint a[] = new int[n];\n\t\tint d[] = new int[n-1];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i] = sc.nextInt();\n\t\t\tif(i>0)\n\t\t\t\td[i-1] = a[i-1] - a[i];\n\t\t}\n\t\tArrays.sort(d);\n\t\tint t = 0;\n\t\tfor(int i=0;i<k-1;i++)\n\t\t\tt += d[i];\n\t\tSystem.out.println(a[n-1]-a[0]+t);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "1197_C. Array Splitting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class RGBSubstring {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        int Q = scanner.nextInt();\n        while(Q-->0) {\n            int N = scanner.nextInt();\n            int K = scanner.nextInt();\n            String s1 = \"RGB\";\n            String s2 = \"GBR\";\n            String s3 = \"BRG\";\n            char[] arr = scanner.next().toCharArray();\n            int[] cnts = new int[3];\n            for(int i = 0; i < K; i++) {\n                int ind = i % 3;\n                if (arr[i] != s1.charAt(ind)) cnts[0]++;\n                if (arr[i] != s2.charAt(ind)) cnts[1]++;\n                if (arr[i] != s3.charAt(ind)) cnts[2]++;\n            }\n            int ans = Math.min(Math.min(cnts[0], cnts[1]), cnts[2]);\n            for(int i = K; i < N; i++) {\n                int ind = (K-1)%3;\n                int[] nextCnts = new int[3];\n                nextCnts[1] = cnts[0];\n                nextCnts[2] = cnts[1];\n                nextCnts[0] = cnts[2];\n                if ('R' != arr[i-K]) nextCnts[1]--;\n                if ('G' != arr[i-K]) nextCnts[2]--;\n                if ('B' != arr[i-K]) nextCnts[0]--;\n                if (arr[i] != s1.charAt(ind)) nextCnts[0]++;\n                if (arr[i] != s2.charAt(ind)) nextCnts[1]++;\n                if (arr[i] != s3.charAt(ind)) nextCnts[2]++;\n                cnts = nextCnts;\n                for(int j = 0; j < 3; j++) ans = Math.min(ans, cnts[j]);\n            }\n            out.println(ans);\n        }\n        out.flush();\n    }\n    \n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n        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", "complexity": "quadratic", "problem": "1196_D1. RGB Substring (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class NickAndArray {\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\t int array[]=new int[n];\n\t\t int max=Integer.MAX_VALUE;\n\t\t int index=0;\n\t\t for(int i=0;i<n;i++)\n\t\t {\n\t\t\t int k=sc.nextInt();\n\t\t\t array[i]=k;\n\t\t\t if(array[i]>=0)\n\t\t\t {\n\t\t\t\t array[i]=-array[i]-1;\n\t\t\t }\n\t\t\t if(array[i]<max)\n\t\t\t {\n\t\t\t\t max=array[i];\n\t\t\t\t index=i;\n\t\t\t\t \n\t\t\t }\n\t\t }\n\t\t if(n%2!=0)\n\t\t {\n\t\t\t array[index]=-array[index]-1;\n\t\t }\n\t\t for(int i=0;i<n;i++)\n\t\t {\n\t\t\t System.out.print(array[i]+\" \" );\n\t\t }\n\t}\n\n}\n", "complexity": "linear", "problem": "1180_B. Nick and Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tstatic boolean canWinFromOneMove(char []s,int k) {\n\t\tint prefix=0;\n\t\tint n=s.length;\n\t\tfor(int i=0;i<n && s[i]==s[0];i++)\n\t\t\tprefix++;\n\t\tint suffix=0;\n\t\tfor(int i=n-1;i>=0 && s[i]==s[n-1];i--)\n\t\t\tsuffix++;\n\t\t\n\t\treturn s[0]==s[n-1] && prefix+suffix+k>=n || Math.max(prefix, suffix)+k>=n;\n\t\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\tint n=sc.nextInt(),k=sc.nextInt();\n\t\tchar []s=sc.next().toCharArray();\n\t\tif(canWinFromOneMove(s, k)) {\n\t\t\tSystem.out.println(\"tokitsukaze\");\n\t\t\treturn;\n\t\t}\n\t\tint []suff=new int [n+1];\n\t\tsuff[n-1]=1;\n\t\tfor(int i=n-2;i>=0;i--) {\n\t\t\tsuff[i]=1+(s[i+1]==s[i]?suff[i+1]:0);\n\t\t}\n\t\tfor(int i=n-2;i>=0;i--)\n\t\t\tsuff[i]=Math.max(suff[i], suff[i+1]);\n\t\tint max=0,curr=0;\n\t\tboolean draw=false;\n\t\tint ones=0;\n\t\tfor(int i=0;i+k<=n;i++) {\n\t\t\t\n\t\t\t// one\n\t\t\tint prefix=ones==i?k+ones:max;\n\t\t\tint suffix=i+k==n?k:s[i+k]=='1' && suff[i+k]==n-(i+k)?k+suff[i+k]:suff[i+k];\n\t\t\tchar first=i==0?'1':s[0],last=i+k==n?'1':s[n-1];\n\t\t\tboolean zero=first==last && prefix+suffix+k>=n || Math.max(prefix, suffix)+k>=n;\n\t\t\t// zero\n\t\t\t prefix=ones==0?k+ones:max;\n\t\t\t suffix=i+k==n?k:s[i+k]=='0' && suff[i+k]==n-(i+k)?k+suff[i+k]:suff[i+k];\n\t\t\t first=i==0?'0':s[0];\n\t\t\t last=i+k==n?'0':s[n-1];\n\t\t\tboolean one=first==last && prefix+suffix+k>=n || Math.max(prefix, suffix)+k>=n;\n\t\t\tif(!zero || !one) {\n//\t\t\t\tSystem.err.println(i+1);\n\t\t\t\tdraw=true;\n\t\t\t}\n\t\t\tif(s[i]=='1')\n\t\t\t\tones++;\n\t\t\tif(i>0 && s[i]==s[i-1] )\n\t\t\t\tcurr++;\n\t\t\telse\n\t\t\t\tcurr=1;\n\t\t\tmax=Math.max(max, curr);\n\t\t}\n\t\tout.println(draw?\"once again\":\"quailty\");\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "linear", "problem": "1190_C. Tokitsukaze and Duel", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class c {\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tint n = in.nextInt(), m = in.nextInt();\n\t\tlong bounty = in.nextInt(), increase = in.nextInt();\n\t\tint damage = in.nextInt();\n\t\tint[] mh = new int[n];\n\t\tint[] sh = new int[n];\n\t\tint[] reg = new int[n];\n\t\tlong countKilled = 0;\n\t\tArrayList<Event> es = new ArrayList<>();\n\t\tEvent[] regen = new Event[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tmh[i] = in.nextInt();\n\t\t\tsh[i] = in.nextInt();\n\t\t\treg[i] = in.nextInt();\n\t\t\tif(sh[i] <= damage)\n\t\t\t\tcountKilled++;\n\t\t\tif(reg[i] > 0) {\n\t\t\t\tint time = (damage+1 - sh[i]+reg[i]-1)/reg[i];\n\t\t\t\tif(time > 0 && mh[i] >= damage+1) {\n\t\t\t\t\tEvent e2 = new Event(time, i, damage+1);\n\t\t\t\t\tregen[i] = e2;\n\t\t\t\t\tes.add(e2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<m;i++) {\n\t\t\tEvent e = new Event(in.nextInt(), in.nextInt()-1, in.nextInt());\n\t\t\tes.add(e);\n\t\t\tif(reg[e.e] > 0) {\n\t\t\t\tint time = (damage+1 - e.h+reg[e.e]-1)/reg[e.e];\n\t\t\t\tif(time > 0 && mh[e.e] >= damage+1) {\n\t\t\t\t\tEvent e2 = new Event(e.t + time, e.e, damage+1);\n\t\t\t\t\te.regen = e2;\n\t\t\t\t\tes.add(e2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tCollections.sort(es, (a,b) -> a.t-b.t);\n\t\tlong ans = countKilled*bounty;\n\t\tint lastTime = 0;\n\t\tfor(Event e : es) {\n\t\t\tif(e.t == -1) continue;\n\t\t\tif(regen[e.e] != e && regen[e.e] != null) {\n\t\t\t\tregen[e.e].t = -1;\n\t\t\t\tregen[e.e] = null;\n\t\t\t}\n\t\t\tif(lastTime != e.t) {\n\t\t\t\tans = Math.max(ans, countKilled*(bounty+(e.t-1)*increase));\n\t\t\t}\n\t\t\tif(sh[e.e] <= damage)\n\t\t\t\tcountKilled--;\n\t\t\tsh[e.e] = e.h;\n\t\t\tif(sh[e.e] <= damage)\n\t\t\t\tcountKilled++;\n\t\t\tif(e.regen != null) {\n\t\t\t\tregen[e.e] = e.regen;\n\t\t\t}\n\t\t\tlastTime = e.t;\n\t\t}\n\t\tif(countKilled != 0) {\n\t\t\tif(increase > 0)\n\t\t\t\tans = -1;\n\t\t\telse\n\t\t\t\tans = Math.max(ans, countKilled*bounty);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic class Event {\n\t\tint t;\n\t\tint e;\n\t\tint h;\n\t\tEvent regen;\n\t\tpublic Event(int tt, int ee, int hh) {\n\t\t\tt = tt;\n\t\t\te = ee;\n\t\t\th = hh;\n\t\t}\n\t}\n\tstatic class FastScanner {\n\t    BufferedReader br;\n\t    StringTokenizer st;\n\t    public FastScanner(InputStream i) {\n\t        br = new BufferedReader(new InputStreamReader(i));\n\t        st = new StringTokenizer(\"\");\n\t    }\n\t    public String next() throws IOException {\n\t        if(st.hasMoreTokens())\n\t            return st.nextToken();\n\t        else\n\t            st = new StringTokenizer(br.readLine());\n\t        return next();\n\t    }\n\t    public int nextInt() throws IOException {\n\t        return Integer.parseInt(next());\n\t    }\n\t    public long nextLong() throws IOException {\n\t        return Long.parseLong(next());\n\t    }\n\t    public double nextDouble() throws IOException {\n\t        return Double.parseDouble(next());\n\t    }\n\t}\n}\n", "complexity": "nlogn", "problem": "912_C. Perun, Ult!", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class KingEscape {\n\n    public static void main(String[] args) {\n        Reader read = new Reader();\n\n        int n = read.nextInt();\n        int a1 = read.nextInt();\n        int a2 = read.nextInt();\n        int b1 = read.nextInt();\n        int b2 = read.nextInt();\n        int c1 = read.nextInt();\n        int c2 = read.nextInt();\n\n        if (b1 > a1 && b2 > a2 && c1 > a1 && c2 > a2)\n            System.out.print(\"YES\");\n        else if (b1 > a1 && b2 < a2 && c1 > a1 && c2 < a2)\n            System.out.print(\"YES\");\n        else if (b1 < a1 && b2 > a2 && c1 < a1 && c2 > a2)\n            System.out.print(\"YES\");\n        else if (b1 < a1 && b2 < a2 && c1 < a1 && c2 < a2)\n            System.out.print(\"YES\");\n        else\n            System.out.print(\"NO\");\n    }\n\n    private static class Reader {\n\n        private final BufferedReader reader;\n        private final String separator;\n        private String ln;\n        private String[] tokens;\n        private int ptr;\n\n        Reader(String separator, InputStream input) {\n            this.reader = new BufferedReader(new InputStreamReader(input));\n            this.separator = separator;\n            this.ptr = -1;\n        }\n\n        Reader(String separator) { this(separator, System.in); }\n\n        Reader() { this(\" \"); }\n\n        String nextStr(){\n            if (Objects.isNull(ln)) {\n                try {\n                    ln = reader.readLine();\n                } catch (IOException e) {\n                    System.out.println(e.getMessage());\n                }\n                if (Objects.nonNull(ln)) {\n                    tokens = ln.split(separator);\n                    ptr = 0;\n                } else {\n                    throw new NoSuchElementException(\"no next element\");\n                }\n\n            } else if (ptr == tokens.length) {\n                ln = null;\n                tokens = null;\n                ptr = -1;\n                return nextStr();\n            }\n\n            return tokens[ptr++];\n        }\n\n        int nextInt() { return Integer.parseInt(nextStr()); }\n\n        long nextLong() { return Long.parseLong(nextStr()); }\n\n        double nextDouble() { return Double.parseDouble(nextStr()); }\n    }\n}\n", "complexity": "constant", "problem": "1033_A. King Escape", "from": "CODEFORCES"}
{"src": "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.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        ReaderFastIO in = new ReaderFastIO(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        DConcatenatedMultiples solver = new DConcatenatedMultiples();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DConcatenatedMultiples {\n        public void solve(int testNumber, ReaderFastIO in, PrintWriter out) {\n\n            Map<Integer, Integer>[] mapMods = new HashMap[11];\n\n            int n = in.nextInt();\n            int k = in.nextInt();\n            int[] a = in.readArrayInt(n);\n\n            for (int i = 0; i < 11; i++) {\n                mapMods[i] = new HashMap<>();\n            }\n\n            for (int i = 0; i < n; i++) {\n                int pot = getPot(a[i]);\n                mapMods[pot].put(a[i] % k, mapMods[pot].getOrDefault(a[i] % k, 0) + 1);\n            }\n\n            long ct = 0;\n\n            for (int i = 0; i < n; i++) {\n\n                int ownPot = getPot(a[i]);\n                long suffix = a[i] * 10L;\n                for (int j = 1; j <= 10; j++) {\n\n                    int mod = (int) (suffix % k);\n                    int comMod = (k - mod) % k;\n                    int qt = mapMods[j].getOrDefault(comMod, 0);\n\n                    if (j == ownPot && (a[i] % k) == comMod) {\n                        qt--;\n                    }\n\n                    ct += qt;\n\n                    suffix = (suffix * 10L) % k;\n                }\n\n            }\n\n            out.println(ct);\n        }\n\n        public int getPot(int x) {\n\n            int ct = 0;\n\n            while (x != 0) {\n                x /= 10;\n                ct++;\n            }\n\n            return ct;\n        }\n\n    }\n\n    static class ReaderFastIO {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public ReaderFastIO() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public ReaderFastIO(InputStream input) {\n            br = new BufferedReader(new InputStreamReader(input));\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        public int[] readArrayInt(int n) {\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\n", "complexity": "nlogn", "problem": "1029_D. Concatenated Multiples", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Equator {\n\tpublic static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static StringTokenizer st;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = intArray(n);\n\t\t\n\t\tlong s = 0;\n\t\tfor (int x : a)\n\t\t\ts += x;\n\t\t\n\t\tlong m = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tm += a[i];\n\t\t\tif (m*2 >= s) {\n\t\t\t\tSystem.out.println(i+1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static String nextLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n\n\tpublic static String nextString() 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\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static int[] intArray(int n) throws IOException {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextInt();\n\t\treturn a;\n\t}\n\n\tpublic static int[][] intArray(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\n\tpublic static long[] longArray(int n) throws IOException {\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}", "complexity": "linear", "problem": "962_A. Equator", "from": "CODEFORCES"}
{"src": "//package codeforces;\n\nimport java.util.Scanner;\n\npublic class Fingerprints {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tint[] code = new int[scanner.nextInt()];\n\t\tint[] prints = new int[scanner.nextInt()];\n\n\t\tfor (int i = 0; i < code.length; i++) {\n\t\t\tcode[i] = scanner.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < prints.length; i++) {\n\t\t\tprints[i] = scanner.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < code.length; i++) {\n\t\t\tfor (int j = 0; j < prints.length; j++) {\n\t\t\t\tif (code[i] == prints[j]) {\n\t\t\t\t\tSystem.out.print(prints[j] + \" \");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tscanner.close();\n\t}\n\n}\n", "complexity": "quadratic", "problem": "994_A. Fingerprints", "from": "CODEFORCES"}
{"src": "/*\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 long MOD = 1000L * 1000L * 1000L + 7;\n    private static final int[] dx = {0, -1, 0, 1};\n    private static final int[] dy = {1, 0, -1, 0};\n    private static final String yes = \"Yes\";\n    private static final String no = \"No\";\n\n    int n;\n    int m;\n    char[][] mat;\n    long base = 397;\n    void solve() throws IOException {\n        n = nextInt();\n        m = nextInt();\n        mat = new char[n][m];\n        for (int i = 0; i < n; i++) {\n            mat[i] = nextString().toCharArray();\n        }\n\n        int alpha = 26;\n        long[] pow = new long[alpha];\n        pow[0] = 1;\n        for (int i = 1; i < alpha; i++) {\n            pow[i] = pow[i - 1] * base % MOD;\n        }\n\n        long res = 0;\n        for (int l = 0; l < m; l++) {\n            //[l, r]\n            long[] hash = new long[n];\n            long[] mask = new long[n];\n            for (int r = l; r < m; r++) {\n                for (int i = 0; i < n; i++) {\n                    hash[i] += pow[mat[i][r] - 'a'];\n                    hash[i] %= MOD;\n                    mask[i] = mask[i] ^ (1L << (mat[i][r] - 'a'));\n                }\n\n                int start = 0;\n                while (start < n) {\n                    if ((mask[start] & (mask[start] - 1)) != 0) {\n                        start++;\n                        continue;\n                    }\n\n                    int end = start;\n                    List<Long> l1 = new ArrayList<>();\n                    while (end < n && (mask[end] & (mask[end] - 1)) == 0) {\n                        l1.add(hash[end]);\n                        end++;\n                    }\n\n                    start = end;\n                    res += manacher(l1);\n                }\n            }\n        }\n\n        outln(res);\n    }\n\n    long manacher(List<Long> arr) {\n        int len = arr.size();\n        long[] t = new long[len * 2 + 3];\n        t[0] = -1;\n        t[len * 2 + 2] = -2;\n        for (int i = 0; i < len; i++) {\n            t[2 * i + 1] = -3;\n            t[2 * i + 2] = arr.get(i);\n        }\n\n        t[len * 2 + 1] = -3;\n        int[] p = new int[t.length];\n        int center = 0, right = 0;\n        for (int i = 1; i < t.length - 1; i++) {\n            int mirror = 2 * center - i;\n            if (right > i) {\n                p[i] = Math.min(right - i, p[mirror]);\n            }\n\n            // attempt to expand palindrome centered at i\n            while (t[i + (1 + p[i])] == t[i - (1 + p[i])]) {\n                p[i]++;\n            }\n\n            // if palindrome centered at i expands past right,\n            // adjust center based on expanded palindrome.\n            if (i + p[i] > right) {\n                center = i;\n                right = i + p[i];\n            }\n        }\n\n        long res = 0;\n        for (int i = 0; i < 2 * len; i++) {\n            int parLength = p[i + 2];\n            if (i % 2 == 0) {\n                res += (parLength + 1) / 2;\n            }\n            else {\n                res += parLength / 2;\n            }\n        }\n\n        return res;\n    }\n\n    void shuffle(int[] a) {\n        int n = a.length;\n        for(int i = 0; i < n; i++) {\n            int r = i + (int) (Math.random() * (n - i));\n            int tmp = a[i];\n            a[i] = a[r];\n            a[r] = tmp;\n        }\n    }\n    long gcd(long a, long b) {\n        while(a != 0 && b != 0) {\n            long c = b;\n            b = a % b;\n            a = c;\n        }\n        return a + b;\n    }\n    private void outln(Object o) {\n        out.println(o);\n    }\n    private void out(Object o) {\n        out.print(o);\n    }\n    private void formatPrint(double val) {\n        outln(String.format(\"%.9f%n\", val));\n    }\n    public 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}", "complexity": "nlogn", "problem": "1080_E. Sonya and Matrix Beauty", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class loser\n{\n    static class InputReader {\n        public BufferedReader br;\n        public StringTokenizer token;\n        public InputReader(InputStream stream)\n        {\n            br=new BufferedReader(new InputStreamReader(stream),32768);\n            token=null;\n        }\n\n        public String next()\n        {\n            while(token==null || !token.hasMoreTokens())\n            {\n                try\n                {\n                    token=new StringTokenizer(br.readLine());\n                }\n                catch(IOException e)\n                {\n                    throw new RuntimeException(e);\n                }\n            }\n            return token.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    static class card{\n        int l;\n        int r;\n        public card(int ch,int i)\n        {\n            this.l=ch;\n            this.r=i;\n        }\n    }\n    static class sort implements Comparator<card>\n    {\n        public int compare(card o1,card o2)\n        {\n            if(o1.l!=o2.l)\n                return (int)(o1.l-o2.l);\n            else\n                return (int)(o1.r-o2.r);\n        }\n    }\n    static void shuffle(long a[])\n    {\n        List<Long> l=new ArrayList<>();\n        for(int i=0;i<a.length;i++)\n            l.add(a[i]);\n        Collections.shuffle(l);\n        for(int i=0;i<a.length;i++)\n            a[i]=l.get(i);\n    }\n\n    /*static long gcd(long a,long b)\n    {\n    if(b==0)\n    return a;\n    else\n    return gcd(b,a%b);\n    }\n    static int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE,ans3=Integer.MAX_VALUE,ans4=Integer.MAX_VALUE;\n    static boolean v[]=new boolean[101];\n    static void dfs(Integer so,Set<Integer> s[]){\n    if(!v[so.intValue()])\n    {\n    v[so]=true;\n    for(Integer h:s[so.intValue()])\n    {\n    if(!v[h.intValue()])\n    dfs(h,s);\n    }\n    }\n    }\n    static class Print{\n    public PrintWriter out;\n    Print(OutputStream o)\n    {\n    out=new PrintWriter(o);\n    }\n    }\n    static int CeilIndex(int A[], int l, int r, int key) \n    { \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\n    return r; \n    } \n\n    static int LongestIncreasingSubsequenceLength(int A[], int size) \n    { \n    // Add boundary case, when array size is one \n    int[] tailTable = new int[size]; \n    int len; // always points empty slot \n    tailTable[0] = A[0]; \n    len = 1; \n    for (int i = 1; i < size; i++) { \n    if (A[i] < tailTable[0]) \n    // new smallest value \n    tailTable[0] = A[i]; \n\n    else if (A[i] > tailTable[len - 1]) \n    // A[i] wants to extend largest subsequence \n    tailTable[len++] = A[i]; \n\n    else\n    // A[i] wants to be current end candidate of an existing \n    // subsequence. It will replace ceil value in tailTable \n    tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; \n    } \n    return len; \n    }*/\n    /*static int binary(int n)\n    {\n    int s=1;\n    while(n>0)\n    {\n    s=s<<1;\n    n--;\n    }\n    return s-1;\n    }\n    static StringBuilder bin(int i,int n)\n    {\n    StringBuilder s=new StringBuilder();\n    while(i>0)\n    {\n    s.append(i%2);\n    i=i/2;\n    }\n    while(s.length()!=n)\n    {\n    s.append(0);\n    }\n    return s.reverse();\n    }*/\n    static boolean valid(int i,int j,int n,int m)\n    {\n        if(i<n && i>=0 && j<m && j>=0)\n            return true;\n        else\n            return false;\n    }\n\n    public static void main(String[] args) \n    {\n        InputReader sc=new InputReader(System.in);\n        int n=sc.nextInt();\n        int s=sc.nextInt();\n        card c[]=new card[n];\n        for(int i=0;i<n;i++)\n        {\n            int x=sc.nextInt();\n            int y=sc.nextInt();\n            c[i]=new card(x,y);\n        }\n        Arrays.sort(c,new sort());\n        int time=0;\n        for(int i=n-1;i>=0;i--)\n        {\n            time+=s-c[i].l;\n            if((c[i].r-time)>0)\n            time+=c[i].r-time;\n            s=c[i].l;\n        }\n        if(c[0].l!=0)\n        time+=c[0].l;\n        System.out.println(time);\n    }\n}", "complexity": "nlogn", "problem": "608_A. Saitama Destroys Hotel", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Long.*;\nimport static java.lang.Math.*;\nimport static java.lang.System.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class Main {\n\n    Main() throws IOException {\n        String a = nextLine();\n        String b = nextLine();\n        long ans = 0;\n        int s = 0;\n        for (int i = 0; i < b.length() - a.length(); ++i) {\n            s += b.charAt(i) == '1' ? 1 : 0;\n        }\n\n        for (int i = 0; i < a.length(); ++i) {\n            s += b.charAt(i + b.length() - a.length()) == '1' ? 1 : 0;\n            ans += a.charAt(i) == '1' ? b.length() - a.length() + 1 - s : s;\n            s -= b.charAt(i) == '1' ? 1 : 0;\n        }\n        out.println(ans);\n    }\n\n\n    //////////////////////////////\n    PrintWriter out = new PrintWriter(System.out, false);\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer stok = null;\n    String nextLine() throws IOException {\n        while (stok == null || !stok.hasMoreTokens()) {\n            stok = new StringTokenizer(in.readLine());\n        }\n        return stok.nextToken();\n    }\n\n\n    public static void main(String args[]) throws IOException {\n        if (args.length > 0) {\n            setIn(new FileInputStream(args[0] + \".inp\"));\n            setOut(new PrintStream(args[0] + \".out\"));\n        }\n        Main solver = new Main();\n        solver.out.flush();  //  could be replace with a method, but nah, this is just competitive programming :p\n    }\n}\n", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class vas2 {\n    public static void main( String[] args ) {\n\tScanner in = new Scanner( System.in );\n\tint n = in.nextInt();\n\tString st = in.next();\n\tint[] a = new int[n];\n\tfor ( int i = 0; i < n; i++ )\n\t    a[i] = st.charAt( i ) - 48;\n\tboolean c = false;\n\tfor ( int i = 1; !c && i < n; i++ ) {\n\t    int s = 0;\n\t    for ( int j = 0; j < i; j++ )\n\t\ts += a[j];\n\t    int t = 0;\n\t    for ( int j = i; j < n; j++ ) {\n\t\tt += a[j];\n\t\tif ( t > s )\n\t\t    if ( t - a[j] != s )\n\t\t\tbreak;\n\t\t    else\n\t\t\tt = a[j];\n\t    }\n\t    if ( t == s )\n\t\tc = true;\n\t}\n\tSystem.out.println( c ? \"YES\" : \"NO\" );\n    }\n}\n", "complexity": "quadratic", "problem": "1030_C. Vasya and Golden Ticket", "from": "CODEFORCES"}
{"src": "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 LogicalExpression {\n    \n    int N = 256;\n    \n    void solve() {\n        Expression[] E = new Expression[N];\n        for (int i = 0; i < N; i++) E[i] = new Expression();\n        \n        E[Integer.parseInt(\"00001111\", 2)].update_f(\"x\");\n        E[Integer.parseInt(\"00110011\", 2)].update_f(\"y\");\n        E[Integer.parseInt(\"01010101\", 2)].update_f(\"z\");\n        \n        for (int l = 2; l < 40; l++) {\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < N; j++) {\n                    if (E[i].e != null && E[j].t != null && E[i].e.length() + E[j].t.length() + 1 == l) {\n                        E[i | j].update_e(E[i].e + '|' + E[j].t);\n                    }\n                    if (E[i].t != null && E[j].f != null && E[i].t.length() + E[j].f.length() + 1 == l) {\n                        E[i & j].update_t(E[i].t + '&' + E[j].f);\n                    }\n                }\n                if (E[i].f != null) E[i ^ (N - 1)].update_f('!' + E[i].f);\n            }\n        }\n        \n        String[] res = new String[N];\n        for (int i = 0; i < N; i++) res[i] = E[i].calc_best();\n        \n        int n = in.nextInt();\n        for (int i = 0; i < n; i++) {\n            int x = Integer.parseInt(in.nextToken(), 2);\n            out.println(res[x]);\n        }\n    }\n    \n    static class Expression {\n        String e, t, f;\n        \n        Expression() {\n        }\n        \n        public Expression(String e, String t, String f) {\n            this.e = e;\n            this.t = t;\n            this.f = f;\n        }\n        \n        String calc_best() {\n            String best = e;\n            if (compare(best, t) > 0) best = t;\n            if (compare(best, f) > 0) best = f;\n            return best;\n        }\n        \n        void update_e(String ne) {\n            if (e == null || compare(e, ne) > 0) {\n                e = ne;\n                update_f('(' + e + ')');\n            }\n        }\n        \n        void update_t(String nt) {\n            if (t == null || compare(t, nt) > 0) {\n                t = nt;\n                update_e(t);\n            }\n        }\n        \n        void update_f(String nf) {\n            if (f == null || compare(f, nf) > 0) {\n                f = nf;\n                update_t(f);\n            }\n        }\n        \n        int compare(String a, String b) {\n            if (a.length() != b.length()) return Integer.compare(a.length(), b.length());\n            return a.compareTo(b);\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 LogicalExpression().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", "complexity": "quadratic", "problem": "913_E. Logical Expression", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class FirstClass {\n\t\n\tpublic static void main(String[] args)throws IOException\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n = Integer.parseInt(br.readLine());\n\t\t\n\t\tint arr[] = new int [n];\n\t\t\n\t\tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\n\t\tfor(int i = 0 ; i < n ; i++)\n\t\t{\n\t\t\tarr[i] = Integer.parseInt(st1.nextToken());\n\t\t}\n\t\t\n\t\tint max = -1;\n\t\tboolean flag = true;\n\t\t\n\t\tfor(int i = 0 ; i < n ; i++)\n\t\t{\n\t\t\tif(arr[i] > max+1)\n\t\t\t{\n\t\t\t\tflag = false;\n\t\t\t\tout.println(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmax = Math.max(max, arr[i]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(flag)\n\t\t\tout.println(-1);\n\t\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "1054_B. Appending Mex", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class AnnoyingPresent {\n\n\t\n\t//UPSOLVED\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n        long n = Long.parseLong(st.nextToken()) , m = Long.parseLong(st.nextToken());\n        \n        long sum = 0;\n        \n        for(int i=0;i<m;i++){\n        \tStringTokenizer st1 = new StringTokenizer(br.readLine());\n            sum+= n* Long.parseLong(st1.nextToken());\n            Long a= Long.parseLong(st1.nextToken());\n            if(a < 0){\n                if(n % 2 == 0)\n                    sum += n*n / 4*a;\n                else{\n                    sum += (n/2) * (n/2+1) * a;\n                }\n            }\n            else\n                sum += (a*(n) * (n-1) / 2);\n            \n        }\n        System.out.println((double)sum/n);\n\t}\n\n}\n", "complexity": "linear", "problem": "1009_C. Annoying Present", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.reflect.Array;\n\n\t\tpublic class codeforces\n\t\t{\t\n\t\t\tpublic static void main(String[] args)\n\t\t\t{\n\t\t\t\tInputReader in = new InputReader(System.in);\n\t\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\n\t\t\t\tint n = in.nextInt();\n\t\t\t\tlong U = in.nextLong();\n\t\t\t\tlong[] E = new long[n];\n\t\t\t\tdouble max = -1;\n\t\t\t\t\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t\tE[i] = in.nextLong();\n\t\t\t\t\n\t\t\t\tfor(int k=1;k<n-1;k++)\n\t\t\t\t{\n\t\t\t\t\tint i = k + 1, j = n - 1, mid = 0;\n\t\t\t\t\tdouble T = 0;\n\t\t\t\t\t\n\t\t\t\t\twhile(i < j)\n\t\t\t\t\t{\n\t\t\t\t\t\tmid = (int)Math.ceil((double)(i+j)/2);\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(E[mid] - E[k-1] <= U)\n\t\t\t\t\t\t\ti = mid;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tj = mid - 1;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tj = k;\n\t\t\t\t\tk = i;\n\t\t\t\t\ti = j - 1;\n\t\t\t\t\t\n\t\t\t\t\tT = E[k] - E[j];\n\t\t\t\t\tT /= E[k] - E[i];\n\t\t\t\t\t\n\t\t\t\t\tif(E[k] - E[i] <= U)\n\t\t\t\t\t\tmax = Math.max(max, T);\n\t\t\t\t\t\n\t\t\t\t\tk = j;\n\t\t\t\t}\t\n\t\t\t\t\n\t\t\t\tpw.println(max);\n\t\t\t\t\n\t\t\t\tpw.flush();\n\t\t\t\tpw.close();\n\t\t\t}\n\t\t\t\n\t\t/*\tpublic static void DFS(int sourse)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tvisited[sourse] = true;\n\t\t\t\t\n\t\t\t\tfor(int u : adj[sourse])\n\t\t\t\t{\n\t\t\t\t\tif(!visited[u])\n\t\t\t\t\t{\n\t\t\t\t\t\tDFS(u);\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\tpublic static ArrayList Divisors(long n)\n\t\t\t{\n\t\t\t    ArrayList<Long> div = new ArrayList<>();\n\t\t\t    \n\t\t\t    for (long i=1; i<=Math.sqrt(n); i++)\n\t\t\t    {\n\t\t\t        if (n%i == 0)\n\t\t\t        {\n\t\t\t        \tdiv.add(i);\n\t\t\t                \n\t\t\t            if(n/i != i)\n\t\t\t            \tdiv.add(n/i);\n\t\t\t        }\n\t\t\t    }\n\t\t\t    return div;\n\t\t\t}\n\t\t\n\t\t\tpublic static int BinarySearch(long[] a, long k)\n\t\t\t{\n\t\t\t\tint n = a.length;\n\t\t\t\tint i = 0, j = n-1;\n\t\t\t\tint mid = 0;\n\t\t\t\t\n\t\t\t\tif(k < a[0])\n\t\t\t\t\treturn 0;\n\t\t\t\telse if(k >= a[n-1])\n\t\t\t\t\treturn n;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\twhile(j - i > 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tmid = (i+j)/2;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(k >= a[mid])\n\t\t\t\t\t\t\ti = mid;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tj = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn i+1;\n\t\t\t}\n\t\t\tpublic static long GCD(long a,long b)\n\t\t\t{\n\t\t\t\tif(b==0)\n\t\t\t\t\treturn a;\n\t\t\t\telse\n\t\t\t\t\treturn GCD(b,a%b);\n\t\t\t}\n\t\t\t\n\t\t\tstatic class pair implements Comparable<pair>\n\t\t\t{\n\t\t\t\tInteger x, y;\n\t\t\t\tpair(int x,int y)\n\t\t\t\t{\n\t\t\t\t\tthis.x=x;\n\t\t\t\t\tthis.y=y;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic int compareTo(pair o) {\n\t\t\t\t\tint result = x.compareTo(o.x);\n\t\t\t\t\tif(result==0)\n\t\t\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\t\t\n\t\t\t\t\treturn result;\n\t\t\t\t}  \n\t\t\t\t\n\t\t\t\tpublic String toString()\n\t\t\t\t{\n\t\t\t\t\treturn x+\" \"+y;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic boolean equals(Object o)\n\t\t\t\t{\n\t\t\t\t\tif (o instanceof pair)\n\t\t\t\t    {\n\t\t\t\t\t\tpair p = (pair)o;\n\t\t\t\t\t\treturn p.x - x == 0 && p.y - y == 0 ;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic int hashCode()\n\t\t\t\t{\n\t\t\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tstatic class InputReader \n\t\t\t{\n\t\t\t\t \n\t\t\t\tprivate final InputStream stream;\n\t\t\t\tprivate final byte[] buf = new byte[8192];\n\t\t\t\tprivate int curChar, snumChars;\n\t\t\t\tprivate SpaceCharFilter filter;\n\t\t \n\t\t\t\tpublic InputReader(InputStream stream) \n\t\t\t\t{\n\t\t\t\t\tthis.stream = stream;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic int snext() \n\t\t\t\t{\n\t\t\t\t\tif (snumChars == -1)\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tif (curChar >= snumChars) \n\t\t\t\t\t{\n\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\ttry \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t\t\t} \n\t\t\t\t\t\tcatch (IOException e) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic int nextInt() \n\t\t\t    {\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t\t{\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tint sgn = 1;\n\t\t\t\t\tif (c == '-')\n\t\t\t\t    {\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tint res = 0;\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res * sgn;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic long nextLong()\n\t\t\t    {\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t\t{\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tint sgn = 1;\n\t\t\t\t\tif (c == '-') \n\t\t\t\t\t{\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tlong res = 0;\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res * sgn;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic int[] nextIntArray(int n) \n\t\t\t\t{\n\t\t\t\t\tint a[] = new int[n];\n\t\t\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t\t\t{\n\t\t\t\t\t\ta[i] = nextInt();\n\t\t\t\t\t}\n\t\t\t\t\treturn a;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic String readString()\n\t\t\t    {\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t\t{\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res.toString();\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic String nextLine() \n\t\t\t\t{\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isEndOfLine(c));\n\t\t\t\t\treturn res.toString();\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic boolean isSpaceChar(int c) \n\t\t\t\t{\n\t\t\t\t\tif (filter != null)\n\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t}\n\t\t \n\t\t\t\tprivate boolean isEndOfLine(int c) \n\t\t\t\t{\n\t\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic interface SpaceCharFilter\n\t\t\t    {\n\t\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tstatic class CodeX {\n\t        public static void sort(long arr[]) {\n\t            merge_sort(arr, 0, arr.length - 1);\n\t        }\n\t\n\t        private static void merge_sort(long A[], long start, long end) {\n\t            if (start < end) {\n\t                long mid = (start + end) / 2;\n\t                merge_sort(A, start, mid);\n\t                merge_sort(A, mid + 1, end);\n\t                merge(A, start, mid, end);\n\t            }\n\t\n\t        }\n\t\n\t        private static void merge(long A[], long start,long mid, long end) {\n\t            long p = start, q = mid + 1;\n\t            long Arr[] = new long[(int)(end - start + 1)];\n\t            long k = 0;\n\t\n\t            for (int i = (int)start; i <= end; i++) {\n\t                if (p > mid)\n\t                    Arr[(int)k++] = A[(int)q++];\n\t\n\t                else if (q > end)\n\t                    Arr[(int)k++] = A[(int)p++];\n\t\n\t                else if (A[(int)p] < A[(int)q])\n\t                    Arr[(int)k++] = A[(int)p++];\n\t\n\t                else\n\t                    Arr[(int)k++] = A[(int)q++];\n\t            }\n\t            for (int i = 0; i < k; i++) {\n\t                A[(int)start++] = Arr[i];\n\t            }\n\t\n\t        }\n\t\n\t    }\n\t\t}\t\n\t\t\n\n\t\t\t", "complexity": "nlogn", "problem": "957_C. Three-level Laser", "from": "CODEFORCES"}
{"src": "import java.io.DataInputStream; \nimport java.io.FileInputStream; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.Scanner; \nimport java.util.StringTokenizer;\nimport java.io.BufferedReader; \n\n import java.util.*;\npublic class Main \n{ \nstatic Graph graph[];\n\tpublic static void add_edge(int u,int v)\n\t{\n\t\tgraph[u].adj.add(graph[v]);\n\t\tgraph[v].adj.add(graph[u]);\n\t}\n\tpublic static void dfs(int index)\n\t{\n\t\tGraph z=graph[index];\n\t\tz.vis=1;Graph v;\n\t\tfor( int i=0;i<z.adj.size();i++)\n\t\t{\n\t\t\tv=z.adj.get(i);\n\t\t\tif(v.vis==0)\n\t\t\t{\n\t\t\t\tv.dist=z.dist+1;\n\t\t\t\tv.parent=z.val;\n\t\t\t\tdfs(v.val);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t}\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    public static void main(String[] args) \n    { \n        FastReader sc=new FastReader();\n\t\tint n=sc.nextInt();\n\t\tPair arr[]=new Pair[n];\n\t\tPair pref[]=new Pair[n];\n\t\tPair suff[]=new Pair[n];\n\t\tfor( int i=0;i<n;i++)\n\t\t{\n\t\t\tlong u=sc.nextLong();\n\t\t\tlong v=sc.nextLong();\n\t\t\tarr[i]=new Pair(u,v);\n\t\t\tpref[i]=new Pair(0,0);\n\t\t\tsuff[i]=new Pair(0,0);\n\t\t}\n\t\tpref[0].x=arr[0].x;\n\t\tpref[0].y=arr[0].y;\n\t\tfor( int i=1;i<n;i++)\n\t\t{\n\t\t\tpref[i].x=(long)Math.max(pref[i-1].x,arr[i].x);\n\t\t\tpref[i].y=(long)Math.min(pref[i-1].y,arr[i].y);\n\t\t}\n\t\tsuff[n-1].x=arr[n-1].x;\n\t\tsuff[n-1].y=arr[n-1].y;\n\t\tfor( int i=n-2;i>=0;i--)\n\t\t{\n\t\t\tsuff[i].x=(long)Math.max(suff[i+1].x,arr[i].x);\n\t\t\tsuff[i].y=(long)Math.min(suff[i+1].y,arr[i].y);\n\t\t}\n\t\tlong max=Long.MIN_VALUE;\n\t\tlong ans=0;\n\t\t\n\t\tfor( int i=0;i<n;i++)\n\t\t{\n\t\t\tlong val=Long.MAX_VALUE;\n\t\t\tlong val1=Long.MAX_VALUE;\n\t\t\t\n\t\t\tif(i!=0&&i!=n-1)\n\t\t\t{\n\t\t\t\t val=(long)Math.min(pref[i-1].y,suff[i+1].y)-(long)Math.max(pref[i-1].x,suff[i+1].x);\n\t\t\t\t \n\t\t\t}\n\t\t\telse if(i!=n-1)\n\t\t\t{\n\t\t\t\tval=suff[i+1].y-suff[i+1].x;\n\t\t\t}\n\t\t\telse\n\t\t\t\tval=pref[i-1].y-pref[i-1].x;\n\t\t\t\n\t\t\tans=val;\n\t\t\tif(ans<0)\n\t\t\t\tans=0;\n\t\t\tmax=(long)Math.max(ans,max);\n\t\t}\n\t\tSystem.out.println(max);\n     \n       \n\t\t\n\t\t\n\t\t\n    } \n}\nclass mycomparator implements Comparator<Graph>\n{\n\tpublic int compare(Graph a, Graph b)\n\t{\n\t\treturn b.dist-a.dist;\n\t}\n}\nclass Graph\n{\n\tint vis,col,val;int parent;int deg;int dist;\n\tArrayList<Graph> adj;\n\tGraph(int val)\n\t{\n\t\tvis=0;\n\t\tcol=-1;\n\t\tadj=new ArrayList<>();\n\t\tparent=-1;\n\t\tthis.val=val;\n\t\tdeg=0;\n\t\tdist=-1;\n\t}\n}\nclass Pair\n{\n\tlong x,y;\n\tPair( long x, long y)\n\t{\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t}\n}", "complexity": "linear", "problem": "1029_C. Maximal Intersection", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ehab4 {\n    public static void main( String[] args ) {\n        Scanner in = new Scanner( System.in );\n\tint a = 0, b = 0;\n\tSystem.out.println( \"? 0 0 \" );\n\tSystem.out.flush();\n\tint c = in.nextInt();\n\tfor ( int i = 29; i >= 0; i-- ) {\n\t    System.out.println( \"? \" + ( a + ( 1 << i ) ) + \" \" + b );\n\t    System.out.flush();\n\t    int q1 = in.nextInt();\n\t    System.out.println( \"? \" + a + \" \" + ( b + ( 1 << i ) ) );\n\t    System.out.flush();\n\t    int q2 = in.nextInt();\n\t    if ( q1 == q2 ) {\n\t\tif ( c == 1 )\n\t\t    a += ( 1 << i );\n\t\telse if ( c == -1 )\n\t\t    b += ( 1 << i );\n\t\tc = q1;\n\t    }\n\t    else if ( q1 == -1 ) {\n\t\ta += ( 1 << i );\n\t\tb += ( 1 << i );\n\t    }\n\t    else if ( q1 == -2 )\n\t\treturn;\n\t}\n\tSystem.out.println( \"! \" + a + \" \" + b );\n\tSystem.out.flush();\n    }\n}\n", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class Main {\n    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(System.out);\n        //Scanner sc = new Scanner();\n        Reader in = new Reader();\n        Main solver = new Main();\n        solver.solve(out, in);\n        out.flush();\n        out.close();\n \n    }\n \n    static int INF = (int)1e5*4*4+5;\n    static int maxn = (int)1e5*2+1;\n    static int mod=(int)1e9+7 ;\n    static int n,m,k,t,q,x,a,b,y;\n    \n    static ArrayList<Integer> adj[];\n    static int[] dist,parent,back;\n    static boolean[] vis,vist;\n    static int root=0,ans=1;\n    \n    \n    void solve(PrintWriter out, Reader in) throws IOException{\n        n = in.nextInt();\n\n\n        if(n==1) {out.println(1);return;}\n        adj = new ArrayList[n+1];\n        for(int i=1;i<=n;i++) \n            adj[i] = new ArrayList<Integer>();\n        \n        int u,v;\n        for(int i=0;i<n-1;i++){\n            u = in.nextInt();\n            v = in.nextInt();\n             \n            adj[u].add(v);\n            adj[v].add(u);\n        }\n        \n        vist = new boolean[n+1];\n        vis = new boolean[n+1];\n        vist[1] =true;\n        makeroot(1);\n        \n        parent = new int[n+1];\n        dist = new int[n+1];\n        back = new int[n+1];\n        \n        dfs(root,0);\n        calcdist(root);\n        \n        vist = new boolean[n+1];\n        vis = new boolean[n+1];\n        vist[root] =true;\n        \n        \n\n        PriorityQueue<Node> pq = new PriorityQueue<Node>();\n        for(int i=1;i<=n;i++){\n            if(i!=root) pq.add(new Node(i,dist[i]));\n        }\n        \n        Node elm;\n        int rt = root;\n        out.print(1);\n        \n        makeroot(root);\n        removeNodes(root,rt);\n        ans+=dist[rt];\n        out.print(\" \"+ans);\n        int itr=2;\n        for(int i=2;i<=n;i++){\n            \n            elm = pq.remove();\n            if(vis[elm.idx]) continue;\n            removeNodes(back[elm.idx],elm.idx);\n            ans += elm.dist+1;\n            out.print(\" \"+ans);\n            itr++;\n        }\n        for(int i=itr;i<n;i++)\n            out.print(\" \"+ans);\n        out.println();\n    }\n    \n    //<>\n    \n    static class Node implements Comparable<Node>{\n        int dist,idx;\n        \n        Node(int idx,int dist){\n            this.idx = idx;\n            this.dist = dist;\n        }\n        \n        public int compareTo(Node o) {\n            return o.dist-this.dist;\n        }\n    }\n    \n    static void removeNodes(int s,int e){\n        vis[s]=true;\n        while(s!=e){\n            vis[s] = true;\n            s = parent[s];\n        }\n        vis[s]=true;\n        return;\n    }\n    \n    static int calcdist(int s){\n        int res=0;\n        int tmp=0;\n        for(int e:adj[s]){\n            if(e!=parent[s]){\n                tmp= calcdist(e);\n                if(1+tmp>res){\n                    res = 1+tmp;\n                    back[s] = back[e];\n                }\n            }\n        }\n        \n        if(res==0) back[s]=s;\n        return dist[s] = res;\n    }\n    \n    static void dfs(int s,int p){\n        for(int e:adj[s]){\n            if(e!=p){\n                parent[e]=s;\n                dfs(e,s);\n            }\n        }\n        return;\n    }\n    \n    static void makeroot(int s){\n        Queue<Integer> q = new LinkedList<>();\n        q.add(s);\n        \n        int elm=0;\n        while(q.size()!=0){\n            elm = q.remove();\n            for(int e:adj[elm]){\n                if(!vist[e]){\n                    vist[e]=true;\n                    q.add(e);\n                    root = e;\n                }\n            }\n        }\n        return;\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}", "complexity": "nlogn", "problem": "958_B2. Maximum Control (medium)", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.min;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic void solve() throws Exception {\n\t\tint n = scanInt();\n\t\tlong l[] = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tl[i] = scanLong();\n\t\t}\n\t\tlong e1 = 0, e2 = 0, ans = 0;\n\t\tboolean water = false;\n\t\tString types = scanString();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong li = l[i], cur;\n\t\t\tswitch (types.charAt(i)) {\n\t\t\tcase 'G':\n\t\t\t\tcur = min(e1, li);\n\t\t\t\te1 -= cur;\n\t\t\t\tli -= cur;\n\t\t\t\te2 += 2 * cur;\n\t\t\t\tans += 2 * cur;\n\t\t\t\te2 += li;\n\t\t\t\tans += 3 * li;\n\t\t\t\tbreak;\n\t\t\tcase 'W':\n\t\t\t\twater = true;\n\t\t\t\te1 += li;\n\t\t\t\tans += 2 * li;\n\t\t\t\tbreak;\n\t\t\tcase 'L':\n\t\t\t\tcur = min(e1, li);\n\t\t\t\te1 -= cur;\n\t\t\t\tli -= cur;\n\t\t\t\tans += 2 * cur;\n\t\t\t\tcur = min(e2, li);\n\t\t\t\te2 -= cur;\n\t\t\t\tli -= cur;\n\t\t\t\tans += 3 * cur;\n\t\t\t\tans += (water ? 4 : 6) * li;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1091_F. New Year and the Mallard Expedition", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Test3 {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tint x=Integer.parseInt(br.readLine());\n\t\tint y=Integer.parseInt(br.readLine());\n\t\tSystem.out.print((int)(y%(Math.pow(2, x))));\n\t}\n}\n", "complexity": "constant", "problem": "913_A. Modular Exponentiation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    public static void main(String[] args)throws IOException{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int t = Integer.parseInt(br.readLine());\n        StringTokenizer st;\n        for(int z=0;z<t;z++){\n            st = new StringTokenizer(br.readLine());\n            int n = Integer.parseInt(st.nextToken());\n            st = new StringTokenizer(br.readLine());\n            int min=1;\n            int max=1;\n            for(int i=0;i<n;i++){\n                int k = Integer.parseInt(st.nextToken());\n                if(max<k){\n                    min = max;\n                    max = k;\n                }else if(min<k){\n                    min = k;\n                }\n            }\n            int res = Math.min(n-2,min-1);\n            System.out.println(res);\n        }\n    }\n}\n\n", "complexity": "linear", "problem": "1197_A. DIY Wooden Ladder", "from": "CODEFORCES"}
{"src": "// discussed with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF915D {\n\tstatic ArrayList[] aa;\n\tstatic boolean[] visited, instack;\n\tstatic int[] stack;\n\tstatic int cnt, h_, i_, j_;\n\tstatic boolean dfs1(int i) {\n\t\tif (visited[i]) {\n\t\t\tif (instack[i]) {\n\t\t\t\th_ = i;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tvisited[i] = instack[i] = true;\n\t\tstack[cnt++] = i;\n\t\tArrayList<Integer> adj = aa[i];\n\t\tfor (int j : adj)\n\t\t\tif (dfs1(j))\n\t\t\t\treturn true;\n\t\tinstack[i] = false;\n\t\tcnt--;\n\t\treturn false;\n\t}\n\tstatic boolean dfs2(int i) {\n\t\tif (visited[i])\n\t\t\treturn instack[i];\n\t\tvisited[i] = instack[i] = true;\n\t\tArrayList<Integer> adj = aa[i];\n\t\tfor (int j : adj)\n\t\t\tif (!(i == i_ && j == j_) && dfs2(j))\n\t\t\t\treturn true;\n\t\tinstack[i] = false;\n\t\treturn false;\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\taa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\twhile (m-- > 0) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint i = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tint j = Integer.parseInt(st.nextToken()) - 1;\n\t\t\taa[i].add(j);\n\t\t}\n\t\tvisited = new boolean[n];\n\t\tinstack = new boolean[n];\n\t\tstack = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif (dfs1(i))\n\t\t\t\tbreak;\n\t\tif (cnt == 0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\tfor (j_ = h_, i_ = stack[--cnt]; ; j_ = i_, i_ = stack[--cnt]) {\n\t\t\tArrays.fill(visited, false);\n\t\t\tArrays.fill(instack, false);\n\t\t\tboolean cycle = false;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (dfs2(i)) {\n\t\t\t\t\tcycle = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (!cycle) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (i_ == h_)\n\t\t\t\tbreak;\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t}\n}\n", "complexity": "quadratic", "problem": "915_D. Almost Acyclic Graph", "from": "CODEFORCES"}
{"src": "//package fourninetysixDiv3;\nimport java.util.HashMap;\nimport java.util.Scanner;\npublic class Median_Segments_general {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint m = s.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = s.nextInt();\n\t\t}\n\t\tSystem.out.println(func(n, m, arr)-func(n, m+1, arr));\n\t}\n\tpublic static long func(int n,int m,int[] arr) {\n\t\tHashMap<Long, Integer> map = new HashMap<>();\n\t\tmap.put((long) 0, 1);\n\t\tlong sum = 0;\n\t\tlong res = 0;\n\t\tlong add=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(arr[i]<m) {\n\t\t\t\tsum--;\n\t\t\t\tif(map.containsKey(sum)) {\n\t\t\t\t\tadd-=map.get(sum);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif(map.containsKey(sum)) {\n\t\t\t\t\tadd+=map.get(sum);\n\t\t\t\t}\n\t\t\t\tsum++;\n\t\t\t}\n\t\t\tres+=add;\n\t\t\tif(map.containsKey(sum)) {\n\t\t\t\tmap.put(sum, map.get(sum)+1);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmap.put(sum,1);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}\n", "complexity": "nlogn", "problem": "1005_E1. Median on Segments (Permutations Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    private static void solve(InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n\n        List<List<Integer>> g = new ArrayList<>(n + 1);\n        for (int i = 0; i < n + 1; i++) {\n            g.add(new LinkedList<>());\n        }\n\n        int degree1 = 0, degree2 = 0, root = 0;\n        for (int i = 0; i < n - 1; i++) {\n            int a = in.nextInt();\n            int b = in.nextInt();\n\n            g.get(a).add(b);\n            g.get(b).add(a);\n\n            if (g.get(a).size() > degree1) {\n\n                if (a == root) {\n                    degree1 = g.get(a).size();\n                } else {\n                    degree2 = degree1;\n                    degree1 = g.get(a).size();\n                    root = a;\n                }\n\n            } else if (g.get(a).size() > degree2) {\n                degree2 = g.get(a).size();\n            }\n\n            if (g.get(b).size() > degree1) {\n\n                if (b == root) {\n                    degree1 = g.get(b).size();\n                } else {\n                    degree2 = degree1;\n                    degree1 = g.get(b).size();\n                    root = b;\n                }\n\n            } else if (g.get(b).size() > degree2) {\n                degree2 = g.get(b).size();\n            }\n        }\n\n        if (degree2 > 2) {\n            out.print(\"No\");\n        } else {\n            out.println(\"Yes\");\n\n            List<Integer> leaves = new LinkedList<>();\n            for (int i = 1; i <= n; i++) {\n                if (i != root) {\n                    if (g.get(i).size() == 1) {\n                        leaves.add(i);\n                    }\n                }\n            }\n\n            out.println(leaves.size());\n            for (int i : leaves) {\n                out.println(root + \" \" + i);\n            }\n        }\n    }\n\n    private static void shuffleArray(int[] array) {\n        int index;\n        Random random = new Random();\n        for (int i = array.length - 1; i > 0; i--) {\n            index = random.nextInt(i + 1);\n            if (index != i) {\n                array[index] ^= array[i];\n                array[i] ^= array[index];\n                array[index] ^= array[i];\n            }\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    private static class InputReader {\n        private BufferedReader br;\n        private 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        byte nextByte() {\n            return Byte.parseByte(next());\n        }\n\n        short nextShort() {\n            return Short.parseShort(next());\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    private 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", "complexity": "linear", "problem": "981_C. Useful Decomposition", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF903F {\n\tstatic final int INF = 0x3f3f3f3f;\n\tstatic void fill(int[][][][] aa, int a) {\n\t\tfor (int h0 = 0; h0 <= 4; h0++)\n\t\t\tfor (int h1 = 0; h1 <= 4; h1++)\n\t\t\t\tfor (int h2 = 0; h2 <= 4; h2++)\n\t\t\t\t\tfor (int h3 = 0; h3 <= 4; h3++)\n\t\t\t\t\t\taa[h0][h1][h2][h3] = a;\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\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint a1 = Integer.parseInt(st.nextToken());\n\t\tint a2 = Integer.parseInt(st.nextToken());\n\t\tint a3 = Integer.parseInt(st.nextToken());\n\t\tint a4 = Integer.parseInt(st.nextToken());\n\t\tint[] aa = new int[10];\n\t\taa[0] = aa[1] = aa[2] = aa[3] = a1;\n\t\taa[4] = aa[5] = aa[6] = a2;\n\t\taa[7] = aa[8] = a3;\n\t\taa[9] = a4;\n\t\tint[][] ww = new int[10][4];\n\t\tww[0][0] = 1;\n\t\tww[1][1] = 1;\n\t\tww[2][2] = 1;\n\t\tww[3][3] = 1;\n\t\tww[4][0] = ww[4][1] = 2;\n\t\tww[5][1] = ww[5][2] = 2;\n\t\tww[6][2] = ww[6][3] = 2;\n\t\tww[7][0] = ww[7][1] = ww[7][2] = 3;\n\t\tww[8][1] = ww[8][2] = ww[8][3] = 3;\n\t\tww[9][0] = ww[9][1] = ww[9][2] = ww[9][3] = 4;\n\t\tchar[][] cc = new char[4][n + 8];\n\t\tfor (int k = 0; k < 4; k++) {\n\t\t\tchar[] c_ = cc[k];\n\t\t\tbr.readLine().getChars(0, n, c_, 4);\n\t\t\tc_[0] = c_[1] = c_[2] = c_[3]\n\t\t\t\t= c_[n + 4] = c_[n + 5] = c_[n + 6] = c_[n + 7] = '.';\n\t\t}\n\t\tint[][][][] dp = new int[5][5][5][5];\n\t\tint[][][][] dq = new int[5][5][5][5];\n\t\tfill(dp, INF);\n\t\tdp[4][4][4][4] = 0;\n\t\tint[] hh = new int[4];\n\t\tfor (int i = 0; i < n + 4; i++) {\n\t\t\tfor (int h0 = 0; h0 <= 4; h0++)\n\t\t\t\tfor (int h1 = 0; h1 <= 4; h1++)\n\t\t\t\t\tfor (int h2 = 0; h2 <= 4; h2++)\n\t\t\t\t\t\tfor (int h3 = 0; h3 <= 4; h3++)\n\t\t\t\t\t\t\tfor (int s = 0; s < 10; s++) {\n\t\t\t\t\t\t\t\thh[0] = h0;\n\t\t\t\t\t\t\t\thh[1] = h1;\n\t\t\t\t\t\t\t\thh[2] = h2;\n\t\t\t\t\t\t\t\thh[3] = h3;\n\t\t\t\t\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\t\t\t\t\tint h = ww[s][k];\n\t\t\t\t\t\t\t\t\tif (hh[k] < h) {\n\t\t\t\t\t\t\t\t\t\twhile (h < 4 && cc[k][i + h] == '.')\n\t\t\t\t\t\t\t\t\t\t\th++;\n\t\t\t\t\t\t\t\t\t\thh[k] = h;\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\tint x = dp[h0][h1][h2][h3] + aa[s];\n\t\t\t\t\t\t\t\tif (dp[hh[0]][hh[1]][hh[2]][hh[3]] > x)\n\t\t\t\t\t\t\t\t\tdp[hh[0]][hh[1]][hh[2]][hh[3]] = x;\n\t\t\t\t\t\t\t}\n\t\t\tfill(dq, INF);\n\t\t\tfor (int h0 = 1; h0 <= 4; h0++) {\n\t\t\t\thh[0] = h0 < 4 || cc[0][i + 4] == '*' ? h0 - 1 : 4;\n\t\t\t\tfor (int h1 = 1; h1 <= 4; h1++) {\n\t\t\t\t\thh[1] = h1 < 4 || cc[1][i + 4] == '*' ? h1 - 1 : 4;\n\t\t\t\t\tfor (int h2 = 1; h2 <= 4; h2++) {\n\t\t\t\t\t\thh[2] = h2 < 4 || cc[2][i + 4] == '*' ? h2 - 1 : 4;\n\t\t\t\t\t\tfor (int h3 = 1; h3 <= 4; h3++) {\n\t\t\t\t\t\t\thh[3] = h3 < 4 || cc[3][i + 4] == '*' ? h3 - 1 : 4;\n\t\t\t\t\t\t\tint x = dp[h0][h1][h2][h3];\n\t\t\t\t\t\t\tif (dq[hh[0]][hh[1]][hh[2]][hh[3]] > x)\n\t\t\t\t\t\t\t\tdq[hh[0]][hh[1]][hh[2]][hh[3]] = x;\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[][][][] tmp = dp; dp = dq; dq = tmp;\n\t\t}\n\t\tSystem.out.println(dp[4][4][4][4]);\n\t}\n}\n", "complexity": "linear", "problem": "903_F. Clear The Matrix", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class SFly {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\n\t\tint planet = Integer.parseInt(lector.readLine());\n\t\tint ini = Integer.parseInt(lector.readLine());\n\t\tdouble peso = ini;\n\t\tint[] desp = new int[planet];\n\t\tint[] ater = new int[planet];\n\t\tString[] temp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tdesp[i] = Integer.parseInt(temp[i]);\n\t\t\tif(desp[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tater[i] = Integer.parseInt(temp[i]);\n\t\t\tif(ater[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = null;\n\t\tint i=planet-1;\n\t\tpeso = (peso*ater[0])/(ater[0]-1);\n\t\twhile(i>0) {\n\t\t\tpeso = (peso*desp[i])/(desp[i]-1);\n\t\t\tpeso = (peso*ater[i])/(ater[i]-1);\n\t\t\ti--;\n\t\t}\n\t\tpeso = (peso*desp[0])/(desp[0]-1);\n\t\tpeso = peso - ini;\n\t\tSystem.out.println(peso);\n\t\tlector.close();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "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        TaskG solver = new TaskG();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG {\n        static int[][] g;\n        static int n;\n        static int[] a;\n        static int[][] edges;\n        static long[] dp;\n        static long[] dpPathToRootWithDetours;\n        static int time = 0;\n        static int[] appearance;\n        static int[] firstAppearance;\n        static int[] depth;\n\n        public static void dfs(int i, int parE) {\n            firstAppearance[i] = time;\n            appearance[time++] = i;\n            dp[i] = a[i];\n            for (int eIndex : g[i]) {\n                if (eIndex == parE) continue;\n                int child = i ^ edges[eIndex][0] ^ edges[eIndex][1];\n                dfs(child, eIndex);\n                appearance[time++] = i;\n                dp[i] += Math.max(dp[child] - edges[eIndex][2] * 2, 0);\n            }\n        }\n\n        public static void dfs2(int i, int parE) {\n            if (i == 0) {\n                dpPathToRootWithDetours[i] = dp[i];\n            } else {\n                int par = i ^ edges[parE][0] ^ edges[parE][1];\n                depth[i] = depth[par] + 1;\n                dpPathToRootWithDetours[i] = dpPathToRootWithDetours[par] - Math.max(0, dp[i] - edges[parE][2] * 2);\n                dpPathToRootWithDetours[i] -= edges[parE][2];\n                dpPathToRootWithDetours[i] += dp[i];\n\n                long myPathWeight = Math.max(dp[i] - edges[parE][2] * 2, 0);\n                long change = dp[par] - myPathWeight - edges[parE][2] * 2;\n                change = Math.max(change, 0);\n                dp[i] += change;\n            }\n            for (int eIndex : g[i]) {\n                if (eIndex == parE) continue;\n                dfs2(i ^ edges[eIndex][0] ^ edges[eIndex][1], eIndex);\n            }\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.NextInt();\n            int q = in.NextInt();\n            a = in.NextIntArray(n);\n            edges = new int[n - 1][3];\n            {\n                long[] count = new long[n];\n                for (int i = 0; i < n - 1; i++) {\n                    int u = in.NextInt() - 1;\n                    int v = in.NextInt() - 1;\n                    int w = in.NextInt();\n                    edges[i][0] = u;\n                    edges[i][1] = v;\n                    edges[i][2] = w;\n                    count[u]++;\n                    count[v]++;\n                }\n\n                g = new int[n][];\n                for (int i = 0; i < n; i++) {\n                    g[i] = new int[(int) count[i]];\n                }\n                for (int i = 0; i < n - 1; i++) {\n                    for (int j = 0; j < 2; j++) {\n                        g[edges[i][j]][(int) --count[edges[i][j]]] = i;\n                    }\n                }\n            }\n            dp = new long[n];\n            dpPathToRootWithDetours = new long[n];\n            depth = new int[n];\n            firstAppearance = new int[n];\n            appearance = new int[(n - 1) * 2 + 1];\n            dfs(0, -1);\n            dfs2(0, -1);\n            GraphLowestCommonAncestor.LCA lca = GraphLowestCommonAncestor.createLCA(appearance, firstAppearance, depth);\n            firstAppearance = null;\n            depth = null;\n            appearance = null;\n            edges = null;\n            g = null;\n            for (int i = 0; i < q; i++) {\n                int u = in.NextInt() - 1;\n                int v = in.NextInt() - 1;\n                int lcaI = lca.getLCA(u, v);\n                long res = dpPathToRootWithDetours[u] + dpPathToRootWithDetours[v] - 2 * dpPathToRootWithDetours[lcaI] + dp[lcaI];\n                out.println(res);\n            }\n        }\n\n    }\n\n    static class MinRangeSparseTable implements ISearchInRange {\n        private final int[][] sparseTables;\n        private final long[] array;\n        private final boolean reverseOrdered;\n\n        public MinRangeSparseTable(long[] array, boolean reverseOrdered) {\n            this.reverseOrdered = reverseOrdered;\n            this.array = array;\n            int LCALength = IntegerExtension.getNumberOfBits(array.length);\n            sparseTables = new int[LCALength][];\n            sparseTables[0] = new int[array.length];\n            for (int i = 0; i < array.length; i++) {\n                sparseTables[0][i] = i;\n            }\n            for (int i = 1; i < LCALength; i++) {\n                int size = 1 << i;\n                int jumpSize = 1 << (i - 1);\n                sparseTables[i] = new int[sparseTables[0].length - size + 1];\n                for (int j = 0; j < sparseTables[i].length; j++) {\n                    sparseTables[i][j] = min(sparseTables[i - 1][j], sparseTables[i - 1][j + jumpSize]);\n                }\n            }\n        }\n\n        private int min(int a, int b) {\n            return ((array[a] < array[b]) ^ reverseOrdered) ? a : b;\n        }\n\n\n        public Pair<Long, Long> queryIndexValueInRange(long l, long r) {\n            int size = (int) (r - l + 1);\n            int LCAIndex = IntegerExtension.getNumberOfBits(size) - 1;\n            int sizeNeeded = 1 << LCAIndex;\n            int res = min(sparseTables[LCAIndex][(int) l], sparseTables[LCAIndex][(int) (r - sizeNeeded + 1)]);\n            return new Pair<>((long) res, array[res]);\n        }\n\n        public MinRangeSparseTable(long[] array) {\n            this(array, false);\n        }\n\n    }\n\n    static class GraphLowestCommonAncestor {\n        public static GraphLowestCommonAncestor.LCA createLCA(int[] appearances, final int[] firstAppearance, final int[] depth) {\n            return new GraphLowestCommonAncestor.LCA_MinRangeSparseTable(appearances, firstAppearance, depth);\n        }\n\n        public interface LCA {\n            int getLCA(int a, int b);\n\n        }\n\n        private static class LCA_MinRangeSparseTable implements GraphLowestCommonAncestor.LCA {\n            private final MinRangeSparseTable minRangeSparseTable;\n            private final int[] firstAppearance;\n            private final int[] indexToNode;\n\n            public LCA_MinRangeSparseTable(int[] appearances, final int[] firstAppearance, final int[] depth) {\n                this.firstAppearance = firstAppearance;\n                this.indexToNode = appearances;\n                long[] depthOrder = new long[appearances.length];\n                for (int i = 0; i < depthOrder.length; i++) {\n                    depthOrder[i] = depth[appearances[i]];\n                }\n                minRangeSparseTable = new MinRangeSparseTable(depthOrder);\n            }\n\n\n            public int getLCA(int a, int b) {\n                a = firstAppearance[a];\n                b = firstAppearance[b];\n                int l = Math.min(a, b), r = Math.max(a, b);\n                return indexToNode[(int) (long) minRangeSparseTable.queryIndexValueInRange(l, r).first];\n            }\n\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 int[] NextIntArray(int n) {\n            return NextIntArray(n, 0);\n        }\n\n        public int[] NextIntArray(int n, int offset) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = NextInt() + offset;\n            }\n            return a;\n        }\n\n    }\n\n    static interface ISearchInRange {\n    }\n\n    static class Pair<T1, T2> {\n        public T1 first;\n        public T2 second;\n\n        public Pair(T1 f, T2 s) {\n            first = f;\n            second = s;\n        }\n\n    }\n\n    static class IntegerExtension {\n        public static int getNumberOfBits(long i) {\n            return 64 - Long.numberOfLeadingZeros(i);\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "1000_G. Two-Paths", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\npublic class alex\n{\n    public static void main(String[] args)throws IOException\n    {\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();int sum=1;\n        for(int i=1;i<=n;i++)\n        {\n            sum=sum+(4*(i-1));\n        }\n        System.out.println(sum);\n    }\n}", "complexity": "linear", "problem": "1180_A. Alex and a Rhombus", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\npublic class TaskB implements Runnable {\n    boolean prime[] = new boolean[(int)1e6+10];\n    InputReader c;\n    PrintWriter w;\n\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n\n        char a[] = c.next().toCharArray(), b[] = c.next().toCharArray();\n        int n = a.length, m = b.length;\n\n        int[][] prefix = new int[m][2];\n        for(int i=0;i<m;i++){\n            if(i!=0) {\n                prefix[i][0] = prefix[i-1][0];\n                prefix[i][1] = prefix[i-1][1];\n            }\n            prefix[i][b[i] - '0']++;\n            //w.println(prefix[i][0]+\" \"+prefix[i][1]);\n        }\n\n        long res = 0;\n        for(int i=0;i<n;i++){\n            int temp = a[i] - '0';\n\n            res += prefix[m - n + i][temp^1];\n            if(i!=0) res -= prefix[i-1][temp^1];\n        }\n\n        w.println(res);\n\n        w.close();\n    }\n\n    void sieveOfEratosthenes(int n) {\n        for(int i=0;i<n;i++)\n            prime[i] = true;\n\n        for(int p = 2; p*p <=n; p++)\n        {\n            if(prime[p] == true)\n            {\n                for(int i = p*p; i <= n; i += p)\n                    prime[i] = false;\n            }\n        }\n    }\n    class pair implements Comparable<pair>{\n        char ch;\n        int ind;\n\n        @Override\n        public String toString() {\n            return \"pair{\" +\n                    \"ch=\" + ch +\n                    \", ind=\" + ind +\n                    '}';\n        }\n\n        public pair(char ch, int ind) {\n            this.ch = ch;\n            this.ind = ind;\n        }\n        public int compareTo(pair car) {\n            if(this.ch==car.ch)\n                return this.ind - car.ind;\n            return this.ch - car.ch;\n        }\n    }\n    public static void sortbyColumn(int arr[][], int col){\n        Arrays.sort(arr, new Comparator<int[]>()\n        {\n            public int compare(int[] o1, int[] o2){\n                return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    static long gcd(long a, long b){\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static class DJSet {\n        public int[] upper;\n        public DJSet(int n) {\n            upper = new int[n];\n            Arrays.fill(upper, -1);\n        }\n\n        public int root(int x) {\n            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n        }\n\n        public boolean equiv(int x, int y) {\n            return root(x) == root(y);\n        }\n\n        public boolean union(int x, int y) {\n            x = root(x);\n            y = root(y);\n            if (x != y) {\n                if (upper[y] < upper[x]) {\n                    int d = x;\n                    x = y;\n                    y = d;\n                }\n                upper[x] += upper[y];\n                upper[y] = x;\n            }\n            return x == y;\n        }\n    }\n    public static int[] radixSort(int[] f) {\n        int[] to = new int[f.length];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n    public void printArray(int[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n){\n        int a[] = new int[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n){\n        long a[] = new long[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars==-1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                }\n                catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        public int nextInt() {\n            int c = read();\n\n            while(isSpaceChar(c))\n                c = read();\n\n            int sgn = 1;\n\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n\n            int res = 0;\n            do {\n                if(c<'0'||c>'9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskB(),\"TaskB\",1<<26).start();\n    }\n}\n\n\n\n", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class cf2 {\n\tstatic final double EPS = 1e-9;\n\n  public static void main(String[] args) throws IOException {\n\t Scanner sc = new Scanner(System.in);\n\t\n\t //rec\n\t int xr1=sc.nextInt(), yr1=sc.nextInt(), xr2=sc.nextInt(),yr2=sc.nextInt();\n\t int xr3=sc.nextInt(), yr3=sc.nextInt(), xr4=sc.nextInt(),yr4=sc.nextInt();\n\t\n\t Point pr1 = new Point(xr1, yr1);\n\t Point pr2 = new Point(xr2, yr2);\n\t Point pr3 = new Point(xr3, yr3);\n\t Point pr4 = new Point(xr4, yr4);\n\t \n\t LineSegment lr1 = new LineSegment(pr1, pr2);\n\t LineSegment lr2 = new LineSegment(pr2, pr3);\n\t LineSegment lr3 = new LineSegment(pr3, pr4);\n\t LineSegment lr4 = new LineSegment(pr4, pr1);\n\t \n\t //diamond\n\t int xd1=sc.nextInt(), yd1=sc.nextInt(), xd2=sc.nextInt(),yd2=sc.nextInt();\n\t int xd3=sc.nextInt(), yd3=sc.nextInt(), xd4=sc.nextInt(),yd4=sc.nextInt();\n\t \n\t Point p1 = new Point(xd1, yd1);\n\t Point p2 = new Point(xd2, yd2);\n\t Point p3 = new Point(xd3, yd3);\n\t Point p4 = new Point(xd4, yd4);\n\t \n\t Point [] pt = new Point [5];\n\t pt[0]=p1;  pt[1]=p2;  pt[2]=p3;  pt[3]=p4;  pt[4]=p1;\n\t Polygon pg = new Polygon(pt);\n\t \n\t if(pg.inside(pr1)||pg.inside(pr2)||pg.inside(pr3)||pg.inside(pr4)) {\n\t\t System.out.println(\"YES\");\n\t\t return;\n\t }\n\t\n\t \n\t LineSegment ld1 = new LineSegment(p1, p2);\n\t LineSegment ld2 = new LineSegment(p2, p3);\n\t LineSegment ld3 = new LineSegment(p3, p4);\n\t LineSegment ld4 = new LineSegment(p4, p1);\n\t \n\t Rectangle rec = new Rectangle(new Point(Math.min(Math.min(xr3,xr4),Math.min(xr1,xr2)), Math.min(Math.min(yr3,yr4),Math.min(yr1,yr2))), \n\t\t\t new Point(Math.max(Math.max(xr3,xr4),Math.max(xr1,xr2)), Math.max(Math.max(yr3,yr4),Math.max(yr1,yr2))) );\n\t \n\t if(rec.contains(p1)||rec.contains(p2)||rec.contains(p3)||rec.contains(p4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld1.intersect(lr1)||ld1.intersect(lr3)||ld1.intersect(lr3)||ld1.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld2.intersect(lr1)||ld2.intersect(lr3)||ld2.intersect(lr3)||ld2.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld3.intersect(lr1)||ld3.intersect(lr3)||ld3.intersect(lr3)||ld3.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld4.intersect(lr1)||ld4.intersect(lr3)||ld4.intersect(lr3)||ld4.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t System.out.println(\"NO\");\n\t \n\t \n\t \n\t \n}\n  \n  public static class Polygon { \n\t\t// Cases to handle: collinear points, polygons with n < 3\n\n\t\tstatic final double EPS = 1e-9;\n\t\t\n\t\tPoint[] g; \t\t\t//first point = last point, counter-clockwise representation\n\t\t\n\t\tPolygon(Point[] o) { g = o; }\n\n\t\tdouble perimeter()\n\t\t{\n\t\t\tdouble sum = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; ++i)\n\t\t\t\tsum += g[i].dist(g[i+1]);\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tdouble area() \t\t//clockwise/anti-clockwise check, for convex/concave polygons\n\t\t{\n\t\t\tdouble area = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; ++i)\n\t\t\t\tarea += g[i].x * g[i+1].y - g[i].y * g[i+1].x;\n\t\t\treturn Math.abs(area) / 2.0;\t\t\t//negative value in case of clockwise\n\t\t}\n\n\t\n\t\t\n\t\tboolean inside(Point p)\t//for convex/concave polygons - winding number algorithm \n\t\t{\n\t\t\tdouble sum = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; ++i)\n\t\t\t{\n\t\t\t\tdouble angle = Point.angle(g[i], p, g[i+1]);\n\t\t\t\tif((Math.abs(angle) < EPS || Math.abs(angle - Math.PI) < EPS) && p.between(g[i], g[i+1]))\n\t\t\t\t\treturn true;\n\t\t\t\tif(Point.ccw(p, g[i], g[i+1]))\n\t\t\t\t\tsum += angle;\n\t\t\t\telse\n\t\t\t\t\tsum -= angle;\n\t\t\t}\n\n\t\t\treturn Math.abs(2 * Math.PI - Math.abs(sum)) < EPS;\t\t//abs makes it work for clockwise\n\t\t}\n\t\t/*\n\t\t * Another way if the polygon is convex\n\t\t * 1. Triangulate the poylgon through p\n\t\t * 2. Check if sum areas == poygon area\n\t\t * 3. Handle empty polygon\n\t\t */\n\t\t\n\t\t\n\n\t\n\t\tPoint centroid()\t\t//center of mass\n\t\t{\n\t\t\tdouble cx = 0.0, cy = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; i++)\n\t\t\t{\n\t\t\t\tdouble x1 = g[i].x, y1 = g[i].y;\n\t\t\t\tdouble x2 = g[i+1].x, y2 = g[i+1].y;\n\n\t\t\t\tdouble f = x1 * y2 - x2 * y1;\n\t\t\t\tcx += (x1 + x2) * f;\n\t\t\t\tcy += (y1 + y2) * f;\n\t\t\t}\n\t\t\tdouble area = area();\t\t//remove abs\n\t\t\tcx /= 6.0 * area;\n\t\t\tcy /= 6.0 * area;\n\t\t\treturn new Point(cx, cy);\n\t\t}\n\t}\n  \n   static class LineSegment {\n\n\t\tPoint p, q;\n\t\t\n\t\tLineSegment(Point a, Point b) { p = a; q = b; }\n\t\t\n\n\t\tboolean intersect(LineSegment ls)\n\t\t{\n\t\t\tLine l1 = new Line(p, q), l2 = new Line(ls.p, ls.q);\n\t\t\tif(l1.parallel(l2))\n\t\t\t{\n\t\t\t\tif(l1.same(l2))\n\t\t\t\t\treturn p.between(ls.p, ls.q) || q.between(ls.p, ls.q) || ls.p.between(p, q) || ls.q.between(p, q);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tPoint c = l1.intersect(l2);\n\t\t\treturn c.between(p, q) && c.between(ls.p, ls.q);\n\t\t}\n\n\t}\n  \n   static class Rectangle {\n\n\t\tstatic final double EPS = 1e-9;\n\t\t\n\t\tPoint ll, ur;\n\n\t\tRectangle(Point a, Point b) { ll = a; ur = b; }\n\n\t\tdouble area() { return (ur.x - ll.x) * (ur.y - ll.y); }\n\n\t\tboolean contains(Point p)\n\t\t{\n\t\t\treturn p.x <= ur.x + EPS && p.x + EPS >= ll.x && p.y <= ur.y + EPS && p.y + EPS >= ll.y;\n\t\t}\n\n\t\tRectangle intersect(Rectangle r)\n\t\t{\n\t\t\tPoint ll = new Point(Math.max(this.ll.x, r.ll.x), Math.max(this.ll.y, r.ll.y));\n\t\t\tPoint ur = new Point(Math.min(this.ur.x, r.ur.x), Math.min(this.ur.y, r.ur.y));\n\t\t\tif(Math.abs(ur.x - ll.x) > EPS && Math.abs(ur.y - ll.y) > EPS && this.contains(ll) && this.contains(ur) && r.contains(ll) && r.contains(ur))\n\t\t\t\treturn new Rectangle(ll, ur);\n\t\t\treturn null;\n\t\t}\n\n\t}\n   static class Line {\n\n\t\tstatic final double INF = 1e9, EPS = 1e-9;\n\t\t\n\t\tdouble a, b, c;\n\t\t\n\t\tLine(Point p, Point q)\n\t\t{\n\t\t\tif(Math.abs(p.x - q.x) < EPS) {\ta = 1; b = 0; c = -p.x;\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ta = (p.y - q.y) / (q.x - p.x);\n\t\t\t\tb = 1.0;\n\t\t\t\tc = -(a * p.x + p.y);\n\t\t\t}\n\t\t\t\t\t\t\n\t\t}\n\t\t\n\t\tLine(Point p, double m) { a = -m; b = 1; c =  -(a * p.x + p.y); } \n\t\t\n\t\tboolean parallel(Line l) { return Math.abs(a - l.a) < EPS && Math.abs(b - l.b) < EPS; }\n\t\t\n\t\tboolean same(Line l) { return parallel(l) && Math.abs(c - l.c) < EPS; }\n\t\t\n\t\tPoint intersect(Line l)\n\t\t{\n\t\t\tif(parallel(l))\n\t\t\t\treturn null;\n\t\t\tdouble x = (b * l.c - c * l.b) / (a * l.b - b * l.a);\n\t\t\tdouble y;\n\t\t\tif(Math.abs(b) < EPS)\n\t\t\t\t y = -l.a * x - l.c;\n\t\t\telse\n\t\t\t\ty = -a * x - c;\n\t\t\t\n\t\t\treturn new Point(x, y);\n\t\t}\n\t\t\n\t\tPoint closestPoint(Point p)\n\t\t{\n\t\t\tif(Math.abs(b) < EPS) return new Point(-c, p.y);\n\t\t\tif(Math.abs(a) < EPS) return new Point(p.x, -c);\n\t\t\treturn intersect(new Line(p, 1 / a));\n\t\t}\n\t\t\t\t\n\t}\n\n   public static class Vector {\n\n\t\tdouble x, y; \n\n\t\tVector(double a, double b) { x = a; y = b; }\n\n\t\tVector(Point a, Point b) { this(b.x - a.x, b.y - a.y); }\n\n\t\tVector scale(double s) { return new Vector(x * s, y * s); }              //s is a non-negative value\n\n\t\tdouble dot(Vector v) { return (x * v.x + y * v.y); }\n\n\t\tdouble cross(Vector v) { return x * v.y - y * v.x; }\n\n\t\tdouble norm2() { return x * x + y * y; }\n\n\t\tVector reverse() { return new Vector(-x, -y); }\n\n\t\tVector normalize() \n\t\t{ \n\t\t\tdouble d = Math.sqrt(norm2());\n\t\t\treturn scale(1 / d);\n\t\t}\t\t\n\t}\n   \n   static class Point implements Comparable<Point>{\n\n\t\tstatic final double EPS = 1e-9;\n\n\t\tdouble x, y;                  \n\n\t\tPoint(double a, double b) { x = a; y = b; }  \n\t\t\n\t\tpublic int compareTo(Point p)\n\t\t{\n\t\t\tif(Math.abs(x - p.x) > EPS) return x > p.x ? 1 : -1;\n\t\t\tif(Math.abs(y - p.y) > EPS) return y > p.y ? 1 : -1;\n\t\t\treturn 0;\n\t\t}\n\t\tstatic double angle(Point a, Point o, Point b)  // angle AOB\n\t\t{\n\t\t\tVector oa = new Vector(o, a), ob = new Vector(o, b);\n\t\t\treturn Math.acos(oa.dot(ob) / Math.sqrt(oa.norm2() * ob.norm2()));\n\t\t}\n\t\tstatic boolean ccw(Point p, Point q, Point r)\n\t\t{\n\t\t\treturn new Vector(p, q).cross(new Vector(p, r)) > 0;\n\t\t}\n\t\t\n\t\tpublic double dist(Point p) { return Math.sqrt(sq(x - p.x) + sq(y - p.y)); }\n\t\t\n\t\tstatic double sq(double x) { return x * x; }\n\t\t\n\t\tPoint rotate(double angle)\n\t\t{\n\t\t\tdouble c = Math.cos(angle), s = Math.sin(angle);\n\t\t\treturn new Point(x * c - y * s, x * s + y * c);\n\t\t}\n\t\t// for integer points and rotation by 90 (counterclockwise) : swap x and y, negate x\n\t\t\n\t\n\t\t\n\t\tboolean between(Point p, Point q)\n\t\t{\n\t\t\treturn x < Math.max(p.x, q.x) + EPS && x + EPS > Math.min(p.x, q.x)\n\t\t\t\t\t&& y < Math.max(p.y, q.y) + EPS && y + EPS > Math.min(p.y, q.y);\n\t\t}\n\t\t\n\t\t//returns true if it is on the line defined by a and b\n\t\n\t\t//returns true if it is on the ray whose start point is a and passes through b\n\t\t// Another way: find closest point and calculate the distance between it and p\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 Scanner(String file) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(file));\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 long nextlong() throws IOException {\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\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", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "//q4\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class q4 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        \n        int query = in.nextInt();\n        \n        while (query -- > 0) {\n            int n = in.nextInt();\n            int k = in.nextInt();\n            \n            char[] arr = new char[n];\n            //slot all n into char array\n            String code = in.next();\n            for (int i = 0; i < n; i++) {\n                arr[i] = code.charAt(i);\n                \n            }\n            \n            //R, G, B cycle\n            int r = 0;\n            int g = 0;\n            int b = 0;\n            \n            for (int i = 0; i < k; i++) {\n                if (i % 3 == 0) {\n                    if (arr[i] == 'R') {g++; b++;}\n                    else if (arr[i] == 'G') {r++; b++;}\n                    else {r++; g++;} //if is 'B'\n                } else if (i % 3 == 1) {\n                    if (arr[i] == 'G') {g++; b++;}\n                    else if (arr[i] == 'B') {r++; b++;}\n                    else {r++; g++;} //if is 'R'\n                } else { //if mod 3 is 2\n                    if (arr[i] == 'B') {g++; b++;}\n                    else if (arr[i] == 'R') {r++; b++;}\n                    else {r++; g++;} //if is 'G'     \n                }\n            }\n            \n            //starting from kth position, if different then add 1, and check (j-k)th position\n            int rMin = r;\n            int gMin = g;\n            int bMin = b;\n            for (int j = k; j < n; j++) {\n                //R cycle\n                if ((j % 3 == 0 && arr[j] != 'R') ||  \n                    (j % 3 == 1 && arr[j] != 'G') ||\n                    (j % 3 == 2 && arr[j] != 'B')) {\n                    r++;\n                }\n                //R cycle \n                if (((j - k) % 3 == 0 && arr[j - k] != 'R') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'G') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'B')) {\n                    r--;\n                }\n                rMin = Math.min(r, rMin);\n                //G cycle\n                if ((j % 3 == 0 && arr[j] != 'G') ||  \n                    (j % 3 == 1 && arr[j] != 'B') ||\n                    (j % 3 == 2 && arr[j] != 'R')) {\n                    g++;\n                } \n                if (((j - k) % 3 == 0 && arr[j - k] != 'G') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'B') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'R')) {\n                    g--;\n                }      \n                gMin = Math.min(gMin, g);\n                //B cycle\n                if ((j % 3 == 0 && arr[j] != 'B') ||  \n                    (j % 3 == 1 && arr[j] != 'R') ||\n                    (j % 3 == 2 && arr[j] != 'G')) {\n                    b++;\n                }       \n                if (((j - k) % 3 == 0 && arr[j - k] != 'B') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'R') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'G')) {\n                    b--;\n                } \n                bMin = Math.min(bMin, b);\n                \n            }\n            \n            System.out.println(Math.min(Math.min(rMin, gMin), bMin));\n            \n        }\n        \n    } \n    \n}", "complexity": "quadratic", "problem": "1196_D2. RGB Substring (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.List;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {\n            Debug debug = new Debug();\n            int n = in.nextInt();\n            int K = in.nextInt();\n\n            List<Integer>[] g = GraphUtils.nextU(in, n, n - 1, true);\n            int[] center = GraphUtils.getCenter(g);\n            if (center.length == 2) {\n                out.println(\"No\");\n                return;\n            }\n\n            int[][] pars = GraphUtils.parents3(g, center[0]);\n            int[] par = pars[0], ord = pars[1], depth = pars[2];\n            int[] deg = new int[n];\n            for (int i = 0; i < n; ++i) deg[i] = g[i].size();\n\n            if (deg[center[0]] < 3) {\n                out.println(\"No\");\n                return;\n            }\n\n            // all leaves depth = K\n            for (int i = 0; i < n; ++i) {\n                if (deg[i] == 1) {\n                    if (depth[i] != K) {\n                        out.println(\"No\");\n                        return;\n                    }\n                } else if (i != center[0]) {\n                    if (deg[i] < 4) {\n                        out.println(\"No\");\n                        return;\n                    }\n                }\n            }\n            out.println(\"Yes\");\n        }\n\n    }\n\n    static class GraphUtils {\n        public static List<Integer>[] nextU(FastReader in, int n, int m, boolean oneIndexed) {\n            int diff = oneIndexed ? 1 : 0;\n            List<Integer>[] g = new List[n];\n            for (int i = 0; i < n; ++i) g[i] = new ArrayList<>();\n            for (int i = 0; i < m; ++i) {\n                int u = in.nextInt() - diff;\n                int v = in.nextInt() - diff;\n                g[u].add(v);\n                g[v].add(u);\n            }\n            return g;\n        }\n\n        public static int[][] parents3(List<Integer>[] g, int root) {\n            int n = g.length;\n            int[] par = new int[n];\n            ArrayUtils.fill(par, -1);\n\n            int[] depth = new int[n];\n            depth[0] = 0;\n\n            int[] q = new int[n];\n            q[0] = root;\n            for (int p = 0, r = 1; p < r; p++) {\n                int cur = q[p];\n                for (int nex : g[cur]) {\n                    if (par[cur] != nex) {\n                        q[r++] = nex;\n                        par[nex] = cur;\n                        depth[nex] = depth[cur] + 1;\n                    }\n                }\n            }\n            return new int[][]{par, q, depth};\n        }\n\n        public static int[] getCenter(List<Integer>[] g) {\n            int n = g.length;\n            int[] q = new int[n];\n            int[] deg = new int[n];\n            int p = 0;\n            for (int i = 0; i < n; i++) {\n                deg[i] = g[i].size();\n                if (g[i].size() <= 1) { // < for n=1\n                    q[p++] = i;\n                }\n            }\n            int bound = p == n ? 0 : p;\n            for (int z = 0; z < p; z++) {\n                if (bound == z && p < n) bound = p;\n                int cur = q[z];\n                deg[cur]--;\n                for (int e : g[cur]) {\n                    if (--deg[e] == 1) q[p++] = e;\n                }\n            }\n            assert p == n;\n            assert bound >= n - 2 && bound < n;\n            if (bound == n - 2) {\n                return new int[]{q[n - 2], q[n - 1]};\n            } else {\n                return new int[]{q[n - 1]};\n            }\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static void fill(int[] array, int value) {\n            Arrays.fill(array, value);\n        }\n\n    }\n\n    static class Debug {\n        PrintWriter out;\n        boolean oj;\n        boolean system;\n        long timeBegin;\n        Runtime runtime;\n\n        public Debug(PrintWriter out) {\n            oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            this.out = out;\n            this.timeBegin = System.currentTimeMillis();\n            this.runtime = Runtime.getRuntime();\n        }\n\n        public Debug() {\n            system = true;\n            oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            OutputStream outputStream = System.out;\n            this.out = new PrintWriter(outputStream);\n            this.timeBegin = System.currentTimeMillis();\n            this.runtime = Runtime.getRuntime();\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1067_B. Multihedgehog", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class AAA {\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());\t\n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint m=Integer.parseInt(st.nextToken());\n\t\tString a=\"\";\n\t\tString b=\"\";\n\t\tfor(int i=0;i<1129;i++) {\n\t\t\ta+=\"1\";\n\t\t\tb+=\"8\";\n\t\t}\n\t\ta+=\"9\";\n\t\tb+=\"1\";\n\t\t\n\t\tSystem.out.println(a);\n\t\tSystem.out.println(b);\n\t}\n\t\t\n}\n", "complexity": "constant", "problem": "1028_B. Unnatural Conditions", "from": "CODEFORCES"}
{"src": "    import java.util.*;\n    import java.io.*;\n    import java.lang.*;\n    import java.math.*;\n    public class B {\n        public static void main(String[] args) throws Exception {\n            BufferedReader bf = new BufferedReader(new InputStreamReader(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            Integer[] a = new Integer[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n            Arrays.sort(a);\n            int[] b = new int[n];\n            for(int i=0; i<n; i++) b[i] = a[i].intValue();\n            boolean diff = false;\n            boolean diff2 = false;\n            Set<Integer> vals = new HashSet<Integer>();\n            vals.add(b[0]);\n            int valval = 0;\n            for(int i=1; i<n; i++) {\n                vals.add(b[i]);\n                if(b[i] == b[i-1]) {\n                    if(!diff) {\n                        diff = true;\n                        valval = b[i];\n                    }\n                    else diff2 = true;\n                }\n            } \n            long sum = 0;\n            for(int i : b) sum += i;\n            sum -= 1L*n*(n-1)/2;\n\n            if(diff && !diff2) {\n                if(!vals.contains((valval-1)) && (valval > 0)) {\n                    if(sum%2 == 0) out.println(\"cslnb\"); else out.println(\"sjfnb\");\n                }\n                else out.println(\"cslnb\");\n            }\n            else if(diff2) out.println(\"cslnb\");\n            else if(sum%2 == 0) out.println(\"cslnb\"); else out.println(\"sjfnb\");\n            // int n = Integer.parseInt(st.nextToken());\n     \n            \n            out.close(); System.exit(0);\n        }\n    }", "complexity": "linear", "problem": "1190_B. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "//package ContestEd69;\n\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class mainD {\n    public static PrintWriter out = new PrintWriter(System.out);\n    public static FastScanner enter = new FastScanner(System.in);\n    public static long[] arr;\n    public static void main(String[] args) throws IOException {\n        int n=enter.nextInt();\n        int m=enter.nextInt();\n        long k=enter.nextLong();\n        arr=new long[n+1];\n        for (int i = 1; i <n+1 ; i++) {\n            arr[i]=enter.nextLong();\n        }\n        long[] summ=new long[n+1];\n        for (int i = 1; i <n+1 ; i++) {\n            summ[i]+=arr[i]+summ[i-1];\n        }\n\n        long[] best=new long[n+1];\n\n        for (int i = 1; i <n+1 ; i++) {\n            best[i]=Math.max(0, ((i-m>=0) ? best[i-m]+summ[i]-summ[i-m]-k:0));\n        }\n        long ans=best[1];\n\n        for (int i = 1; i <n+1 ; i++) {\n            ans=Math.max(ans,best[i]);\n            for (int j = 1; j <m ; j++) {\n                ans=Math.max(ans, ((i-j>=0) ? best[i-j] -k +summ[i]-summ[i-j]:0));\n            }\n        }\n        System.out.println(ans);\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer stok;\n\n        FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        String next() 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(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        char nextChar() throws IOException {\n            return (char) (br.read());\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\npublic class Main {\n    static long m = 1000000007;\n    static long powmod(long x, long y, long p)\n    {\n        // Initialize result\n        long res = 1;\n\n        // Update x if it is more\n        // than or equal to p\n        x = x % p;\n\n        while (y > 0)\n        {\n            // If y is odd, multiply x\n            // with result\n            if((y & 1)==1)\n                res = (res * x) % p;\n\n            // y must be even now\n            // y = y / 2\n            y = y >> 1;\n            x = (x * x) % p;\n        }\n        return res;\n    }\n\n    static long mulmod(long a, long b, long mod){\n        long res=0;\n        a = a % mod;\n        while (b > 0)\n        {\n            // If b is odd, add 'a' to result\n            if (b % 2 == 1)\n                res = (res + a) % mod;\n\n            // Multiply 'a' with 2\n            a = (a * 2) % mod;\n\n            // Divide b by 2\n            b /= 2;\n        }\n\n        // Return result\n        return res % mod;\n    }\n\n    public static void main(String args[] ) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        long x = sc.nextLong();\n        long k = sc.nextLong();\n        if(x>0) {\n            long d= powmod(2,k,m);\n            long ans= mulmod(d,2,m)%m;\n            ans= mulmod(ans,x,m)%m;\n            ans++;\n            ans%=m;\n            ans= (ans-d+m)%m;\n            System.out.println(ans);\n        }\n        else\n            System.out.println(0);\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.util.Map.*;\npublic class codeforces {\n     static int count =0;\n     static boolean f=false;\n     static int [] arr;\n\tstatic \tPrintWriter pw=new PrintWriter(System.out);\n\tstatic void solve(int index , int mask) {\n\t\tif(index==arr.length) {\n\t\t\tint sum1=0; int sum2=0;\n\t\t\tfor(int i=0;i<arr.length;i++) {\n\t\t\t\tif((mask & 1<<i)!=0) sum1+=arr[i];\n\t\t\t\t\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tsolve(index+1, mask | 1<<index);\n\t\tsolve(index+1, mask);\n\t}\n\tpublic static void main(String [] args) throws IOException, InterruptedException {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint x=sc.nextInt();\n\t\tint y=sc.nextInt();\n\t\tpair [] arr=new pair[x];\n\t\tfor(int i=0;i<x;i++) arr[i]=new pair(i, sc.nextInt(),0);\n\t\tfor(int i=0;i<x;i++) arr[i].y=sc.nextInt();\n\t\tArrays.sort(arr);\n\t\tPriorityQueue<Integer> qq=new PriorityQueue<>();\n\t\t//pw.println(Arrays.toString(arr));\n\t\tLong [] list=new Long [x];\n\t\tlong sum=0; \n\t\tfor(int i=0;i<x;i++) {\n\t\t\tpair w=arr[i];\n\t\t\tif(qq.size()<y) {\n\t\t\t\tqq.add(w.y);\n\t\t\t\tsum+=w.y;\n\t\t\t\tlist[w.i]=sum;\n\n\t\t\t}else if(!qq.isEmpty()) {\n\t\t\t\tsum+=w.y;\n\t\t\t\tlist[w.i]=sum;\n\t\t\t\tint first=qq.poll();\n\t\t\t\tif(w.y>first) {\n\t\t\t\t\tsum-=first;\n\t\t\t\t\tqq.add(w.y);\n\t\t\t\t}else {\n\t\t\t\t\tqq.add(first);\n\t\t\t\t\tsum-=w.y;\n\t\t\t\t}\n\t\t\t} else list[w.i]=(long) w.y;\n\t\t\t//pw.println(qq);\n\t\t}\n\t\tfor(Long w:list) pw.print(w+\" \"); \n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\t\n\tstatic class pair implements Comparable<pair>{\n\t\tString  name; int x,y,i ;\n\t\tpublic pair(String name , int x) {\n\t\t\tthis.name=name; this.x=x;\n\t\t}\n\t\t\n\t\tpublic pair (int i,int x,int y) {\n\t\t\tthis.i=i; this.x=x; this.y=y; \n\t\t}\n\t\tpublic int compareTo(pair o) {\n\t\t\treturn x-o.x;\n\t\t}\n\t\tpublic int compareTo1(pair o) {\n\t\t\tif(!name.equals(o.name))\n\t\t\t\treturn name.compareTo(o.name);\n\t\t\treturn x-o.x;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn i+\" \"+x+\" \"+y;\n\t\t}\n\t}\n\n   static 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\t}", "complexity": "nlogn", "problem": "994_B. Knights of a Polygonal Table", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces913F {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tinput.close();\n\t\tfinal int mod = 998244353;\n\t\t\n\t\tint frac = multiply(a, inverse(b, mod), mod);\n\t\tint reverse = (mod+1-frac)%mod;\n\t\t\n\t\tint[] fracpower = new int[n+1];\n\t\tint[] reversepower = new int[n+1];\n\t\tfracpower[0] = 1;\n\t\treversepower[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfracpower[i] = multiply(fracpower[i-1], frac, mod);\n\t\t\treversepower[i] = multiply(reversepower[i-1], reverse, mod);\n\t\t}\n\t\t\n\t\tint[][] dp1 = new int[n+1][n+1];\n\t\tdp1[2][1] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tif (j == 1) {\n\t\t\t\t\tdp1[i][j] = fracpower[i-1];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);\n\t\t\t\t}\n\t\t\t\tif (j == i-1) {\n\t\t\t\t\tdp1[i][j] += reversepower[i-1];\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp2 = new int[n+1][n+1];\n\t\tdp2[1][1] = 1;\n\t\tdp2[2][1] = 1;\n\t\tdp2[2][2] = 0;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tdp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);\n\t\t\t\tval += dp2[i][j];\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tdp2[i][i] = (mod+1-val)%mod;\n\t\t}\n\t\t\n\t\t/*for (int i = 2; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tSystem.out.print(dp2[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}*/\n\t\t\n\t\tint[] EV = new int[n+1];\n\t\tEV[1] = 0;\n\t\tEV[2] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tint r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];\n\t\t\t\tr %= mod;\n\t\t\t\tval += multiply(dp2[i][j], r, mod);\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tval += multiply((i*(i-1))/2, dp2[i][i], mod);\n\t\t\tval %= mod;\n\t\t\t\n\t\t\tint s = (mod+1-dp2[i][i])%mod;\n\t\t\tEV[i] = multiply(val, inverse(s, mod), mod);\n\t\t}\n\t\t\n\t\tSystem.out.println(EV[n]);\n\t}\n\t\n\tpublic static int multiply(int a, int b, int mod) {\n\t\tlong x = (long)a*(long)b;\n\t\treturn (int) (x%mod);\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}", "complexity": "quadratic", "problem": "913_F. Strongly Connected Tournament", "from": "CODEFORCES"}
{"src": "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<Pair>[] g;\n    String s;\n    int[][] a;\n    void solve() throws IOException {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        a = new int[n][m];\n        for (int i = 0; i < n; i++) {\n            String s = in.nextLine();\n            for (int j = 0; j < m; j++) {\n                a[i][j] = s.charAt(j);\n            }\n        }\n\n        int[][] f = new int[n][m];\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++)\n                f[i][j] = inf;\n\n        for (int i = 0; i < n; i++) {\n            int cnt = 0;\n            for (int j = 0; j < m; j++) {\n                if (a[i][j] == '*') {\n                    f[i][j] = Math.min(f[i][j], cnt);\n                    cnt++;\n                } else {\n                    cnt = 0;\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            int cnt = 0;\n            for (int j = m - 1; j >= 0; j--) {\n                if (a[i][j] == '*') {\n                    f[i][j] = Math.min(f[i][j], cnt);\n                    cnt++;\n                } else {\n                    cnt = 0;\n                }\n            }\n        }\n\n        for (int j = 0; j < m; j++) {\n            int cnt = 0;\n            for (int i = 0; i < n; i++) {\n                if (a[i][j] == '*') {\n                    f[i][j] = Math.min(f[i][j], cnt);\n                    cnt++;\n                } else {\n                    cnt = 0;\n                }\n            }\n        }\n\n        for (int j = 0; j < m; j++) {\n            int cnt = 0;\n            for (int i = n - 1; i >= 0; i--) {\n                if (a[i][j] == '*') {\n                    f[i][j] = Math.min(f[i][j], cnt);\n                    cnt++;\n                } else {\n                    cnt = 0;\n                }\n            }\n        }\n\n        ArrayList<Item> ans = new ArrayList<>();\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++) {\n                if (a[i][j] == '*' && f[i][j] > 0)\n                    ans.add(new Item(i + 1, j + 1, f[i][j]));\n            }\n        boolean[][] used = new boolean[n][m];\n        for (int i = 0; i < n; i++) {\n            int cnt = 0;\n            for (int j = 0; j < m; j++) {\n                if (a[i][j] == '*' && f[i][j] > 0) {\n                    cnt = Math.max(cnt, f[i][j] + 1);\n                }\n                if (cnt > 0) used[i][j] = true;\n                cnt--;\n            }\n            cnt = 0;\n            for (int j = m - 1; j >= 0; j--) {\n                if (a[i][j] == '*' && f[i][j] > 0) {\n                    cnt = Math.max(cnt, f[i][j] + 1);\n                }\n                if (cnt > 0) used[i][j] = true;\n                cnt--;\n            }\n        }\n\n        for (int j = 0; j < m; j++) {\n            int cnt = 0;\n            for (int i = 0; i < n; i++) {\n                if (a[i][j] == '*' && f[i][j] > 0) {\n                    cnt = Math.max(cnt, f[i][j] + 1);\n                }\n                if (cnt > 0) used[i][j] = true;\n                cnt--;\n            }\n            cnt = 0;\n            for (int i = n - 1; i >= 0; i--) {\n                if (a[i][j] == '*' && f[i][j] > 0) {\n                    cnt = Math.max(cnt, f[i][j] + 1);\n                }\n                if (cnt > 0) used[i][j] = true;\n                cnt--;\n            }\n        }\n\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++)\n                if (a[i][j] == '*' && !used[i][j]) {\n                    out.println(-1);\n                    return;\n                }\n\n        out.println(ans.size());\n        for (Item i : ans)\n            out.println(i.a + \" \" + i.b + \" \" + i.c);\n    }\n\n\n    class Pair implements Comparable<Pair>{\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}", "complexity": "quadratic", "problem": "1015_E2. Stars Drawing (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    public static void main(String[] args)throws IOException{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        int[] a = new int[n];\n        for(int i=0;i<n;i++) a[i] = Integer.parseInt(st.nextToken());\n        int ind = 0;\n        for(int i=0;i<n;i++){\n            if(a[i]==n){\n                ind = i;\n                break;\n            }\n        }\n        boolean ok = true;\n        for(int i=ind+1;i<n;i++) if(a[i]>a[i-1]) ok = false;\n        for(int i=ind-1;i>=0;i--) if(a[i]>a[i+1]) ok = false;\n        if(ok) System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n        \n    }\n}\n\n", "complexity": "linear", "problem": "1197_B. Pillars", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Solve4 {\n\n    public static void main(String[] args) throws IOException {\n      FastReader sc = new FastReader();\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(Math.abs(x-y)*t1 < (Math.abs(x-z)+Math.abs(x-y))*t2+3*t3 ) System.out.println(\"NO\");\n      else System.out.println(\"YES\");\n    }\n\n    static class FastReader {\n\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public String next() throws IOException {\n            if (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(br.readLine());\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n\n        public String nextLine() {\n            String s = \"\";\n            try {\n                s = br.readLine();\n            } catch (IOException ex) {\n            }\n            return s;\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "1054_A. Elevator or Stairs?", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class codef8 {\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint num = sc.nextInt();\n\t\tint beacon[] = new int[1000001];\n\t\tint pos[] = new int[num];\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tint position = sc.nextInt();\n\t\t\tbeacon[position] = sc.nextInt();\n\t\t\tpos[i] = position;\n\t\t}\n\t\tint dp[] = new int[1000001];\n\t\tint max = 0;\n\t\tif (beacon[0] != 0)\n\t\t\tdp[0] = 1;\n\t\t\n\t\tfor (int i = 1; i <= 1000000; i++) {\n\t\t\tif (beacon[i] == 0) {\n\t\t\t\tdp[i] = dp[i-1];\n\t\t\t} \n\t\t\telse {\n\t\t\t\tint j = i - beacon[i] - 1;\n\t\t\t\tif (j < 0) {\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp[i] = dp[j] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, dp[i]);\n\t\t}\t\t\n\t\tSystem.out.println(num-max);\n\t}\n\n}\n", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class coins\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 i,k,n,v;\n  String a;\n  a=in.readLine();\n  for(i=0;i<a.length();i++)\n  {\n   if(a.charAt(i)==' ')\n   break;\n  }\n  n=Integer.parseInt(a.substring(0,i));\n  v=Integer.parseInt(a.substring(i+1));\n  k=v%n;\n  v=v/n;\n  if(k>0)\n  v++;\n  System.out.println(v);\n }\n}\n", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\n\npublic class First {\n    StreamTokenizer in;\n    PrintWriter out;\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\n\n    void run() throws IOException {\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n    }\n\n    void solve() throws IOException {\n        int n = nextInt(), k = nextInt(), sum = 0, count = 0;\n        String str = nextString();\n        char[] arr = str.toCharArray();\n        boolean[] bool = new boolean[26];\n        for(char ch: arr){\n            bool[((int)ch)-97] = true;\n        }\n        for(int i = 0; i < 26; i++){\n            if(bool[i]){\n                sum += i+1;\n                count++;\n                i += 1;\n            }\n            if(count == k) break;\n        }\n        if(count == k) out.println(sum);\n        else out.println(-1);\n    }\n\n    public static void main(String[] args) throws IOException {\n        new First().run();\n    }\n}", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.util.*; \n\n\npublic class p7{\n\t\n\tstatic class FastReader{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t}\n\n\tpublic static void main(String[] args) \n\t{ \n        FastReader sc = new FastReader(); \n        //PrintWriter out = new PrintWriter(System.out); \n        int n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tlong one = (long)Math.pow(2, k) - 1;\n\t\t\n\t\tlong[] arr = new long[n+1];\n\t\t\n\t\tarr[0] = 0;\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tarr[i] = sc.nextLong();\n\t\t\tarr[i] ^= arr[i-1];\n\t\t}\n\n\t\tMap<Long, Long> count = new HashMap<>();\n\n\t\tfor(int i=0;i<=n;i++){\n\t\t\tLong key = Math.min(arr[i], (arr[i]^one));\n\t\t\tLong val = count.get(key);\n\t\t\tif(val==null) val = 0L;\n\t\t\tcount.put(key, val+1);\n\t\t}\n\n\t\tlong num = n;\n\t\tlong ans = num*(num+1)/2;\n\t\t\n\t\tfor(Map.Entry<Long, Long> ent: count.entrySet()){\n\t\t\t\n\t\t\tLong cnt = ent.getValue();\n\t\t\t\n\t\t\tlong num1 = cnt/2;\n\t\t\tlong num2 = (cnt+1)/2;\n\t\t\t\n\t\t\tans -= ( (num1*(num1-1))/2 );\n\t\t\tans -= ( (num2*(num2-1))/2 );\n\t\t}\n\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "nlogn", "problem": "1054_D. Changing Array", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Vector;\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        int m = sc.nextInt();\n        int a[] = new int[n];\n        int b[] = new int[n];\n        for (int i = 0; i < n; i++) a[i] = sc.nextInt();\n        for (int i = 0; i < n; i++) b[i] = sc.nextInt();\n        int c[] = new int[2 * n];\n        c[0] = a[0];\n        for (int i = 1; i < n; i++) {\n            c[i * 2] = a[i];\n            c[i * 2 - 1] = b[i];\n            if (a[i] == 1 || b[i] == 1) {\n                System.out.print(-1);\n                System.exit(0);\n            }\n        }\n        c[2 * n - 1] = b[0];\n        if (a[0] == 1 || b[0] == 1) {\n            System.out.print(-1);\n            System.exit(0);\n        }\n        System.out.println(bin_search(c, m));\n    }\n\n    private static double bin_search(int[] c, int m) {\n        double start = 0;\n        double end = Integer.MAX_VALUE;\n        double mid;\n        while (start + 0.0000001 < end) {\n            mid = (start + end) / 2;\n            if (test(mid, m, c)) end = mid;\n            else start = mid;\n        }\n        return end;\n    }\n\n    private static boolean test(double fuel, int m, int[] c) {\n        for (int i = 0; i < c.length; i++) {\n            fuel -= (m + fuel) / c[i];\n            if (fuel < 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n", "complexity": "nlogn", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class FUck {\n\n\t\tpublic static void main(String args[])\n\t\t{\n\t\t\tScanner scan=new Scanner(System.in);\n\t\t\tint n=scan.nextInt();\n\t\t\tint k=scan.nextInt();\n\t\t\tString t=scan.next();\n\t\t\tint mx=0;\n\t\t\tfor(int i=1;i<n;i++)\n\t\t\t{\n\t\t\t\tint gd=1;\n\t\t\t\tfor(int j=0;j<i;j++)\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tif(t.charAt(j)!=t.charAt((n-i)+j))\n\t\t\t\t\t{\n\t\t\t\t\t\t\n\t\t\t\t\t\tgd=0;\n\t\t\t\t\t\t// i think i can break here\n\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tif(gd==1){\n\t\t\t\t\tmx=i;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.print(t);\n\t\t\tfor(int i=2;i<=k;i++)\n\t\t\t{\n\t\t\t\tfor(int j=mx;j<n;j++)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(t.charAt(j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n", "complexity": "quadratic", "problem": "1029_A. Many Equal Substrings", "from": "CODEFORCES"}
{"src": "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            String s2[]=br.readLine().split(\" \");\n            int n=Integer.parseInt(s1[0]);\n            int m=Integer.parseInt(s1[1]);\n            int a[]=new int[n];\n            int b[]=new int[n];\n            int c[]=new int[n];\n            int d[]=new int[n];\n            HashSet<Integer> hs=new HashSet<Integer>();\n            hs.add(0);\n            hs.add(m);\n            int max=0;\n            for(int i=0;i<n;i++)\n            {\n                  a[i]=Integer.parseInt(s2[i]);\n                  if(i%2==0)\n                   b[i]=1;\n                  hs.add(a[i]);\n            }\n            \n            c[0]=a[0];\n            for(int i=1;i<n;i++)\n            {\n                  if(b[i]==0)\n                   c[i]=c[i-1];\n                  else\n                   c[i]=c[i-1]+a[i]-a[i-1];\n            }\n            \n            if(b[n-1]==0)\n             d[n-1]=m-a[n-1];\n            for(int i=n-2;i>=0;i--)\n            {\n                  if(b[i]==1)\n                   d[i]=d[i+1];\n                  else\n                   d[i]=d[i+1]+a[i+1]-a[i];\n            }\n            \n            max=c[n-1];\n            if(b[n-1]==0)\n             max+=m-a[n-1];\n            //System.out.println(max);\n            for(int i=n-1;i>=0;i--)\n            {\n                  int u=a[i]-1;\n                  int v=a[i]+1;\n                  if(!hs.contains(u))\n                  {\n                        if(b[i]==0)\n                        {\n                             int r=1+m-a[i]-d[i]+c[i-1];\n                             max=Math.max(max,r);\n                        }\n                        else\n                        {\n                              int l=0;\n                              if(i>0)\n                               l=a[i-1];\n                              int r=c[i]-1+m-a[i]-d[i];\n                              max=Math.max(max,r);\n                        }\n                  }\n                  \n                  if(!hs.contains(v))\n                  {\n                        if(b[i]==0)\n                        {\n                           if(i==n-1)\n                           {\n                              int r=c[i]+1;\n                              max=Math.max(max,r);\n                           }\n                           else\n                           {\n                               int r=c[i]+1+m-a[i+1]-d[i+1];\n                               max=Math.max(max,r);\n                           }\n                        }\n                        else\n                        {\n                                if(i==n-1)\n                                {\n                                   int r=c[i]+m-a[i]-1;\n                                   max=Math.max(max,r);\n                                }\n                                else\n                                {\n                                    int r=c[i]+m-a[i+1]-d[i+1]+a[i+1]-1-a[i];  \n                                    max=Math.max(max,r);\n                                }\n                        }\n                  }\n            }\n            \n            System.out.println(max);\n      }\n}", "complexity": "linear", "problem": "1000_B. Light It Up", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic 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 k = 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\tfor(int i = n-1; i > 0; i--)\n\t\t\tarr[i] -= arr[i-1];\n\t\tarr[0] = 0;\n\t\tArrays.sort(arr);\n\t\tlong sum = 0;\n\t\tfor(int i = n-k; i >= 0; i--)\n\t\t\tsum += arr[i];\n\t\tSystem.out.println(sum);\n\t}\n}", "complexity": "nlogn", "problem": "1197_C. Array Splitting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\n/* spar5h */\n\npublic class cf1 implements Runnable{    \n\t\n\tpublic void run() {\n\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\t\n\t\tint t = 1;\n\t\t\n\t\twhile(t-- > 0) {\n\t\t\t\n\t\t\tint n = s.nextInt(), m = s.nextInt();\n\t\t\t\n\t\t\tint[] a = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\ta[i] = s.nextInt();\n\t\t\t\n\t\t\tint[] b = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\tb[i] = s.nextInt();\n\t\t\t\n\t\t\tArrayList<Integer> list = new ArrayList<Integer>();\n\t\t\t\n\t\t\tlist.add(a[1]);\n\t\t\t\n\t\t\tfor(int i = 2; i <= n; i++) {\n\t\t\t\tlist.add(b[i]); list.add(a[i]);\n\t\t\t}\n\t\t\t\n\t\t\tlist.add(b[1]);\n\t\t\t\n\t\t\tdouble wt = m;\n\t\t\tboolean check = true;\n\t\t\t\n\t\t\tfor(int i = list.size() - 1; i >= 0; i--) {\n\t\t\t\t\n\t\t\t\tif(list.get(i) <= 1) {\n\t\t\t\t\tcheck = false; break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tdouble x = wt / (list.get(i) - 1);\n\t\t\t\t\t\t\n\t\t\t\twt += x;\n\t\t\t}\n\t\t\t\n\t\t\tif(check)\n\t\t\t\tw.println(wt - m);\n\t\t\telse\n\t\t\t\tw.println(-1);\n\t\t}\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\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new cf1(),\"cf1\",1<<26).start();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.stream.IntStream;\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(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\n        Solver solver = new Solver();\n        solver.solve(in, out);\n        out.close();\n    }\n\n    static class Solver {\n        int n;\n        int n2;\n        InputReader in;\n        PrintWriter out;\n\n        public void solve(InputReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.readInt();\n            n2 = n/2;\n\n            int res = find();\n            out.print(\"! \");\n            out.println(res);\n        }\n\n        public int find() {\n            if (n%4 != 0) return -1;\n            int c = compare(0);\n            if (c == 0) return 1;\n            int s = 1;\n            int f = n2-1;\n            if (c > 0) {\n                s = n2+1;\n                f = n-1;\n            }\n            while (s <= f) {\n                int m = (s+f)/2;\n                int v = compare(m);\n                if (v == 0) return m+1;\n                else if (v < 0) s = m+1;\n                else f = m-1;\n            }\n            return -1;\n        }\n\n        public int compare(int z) {\n            out.print(\"? \");\n            out.println(z+1);\n            out.flush();\n            int r1 = in.readInt();\n            out.print(\"? \");\n            out.println((z+n2)%n+1);\n            out.flush();\n            int r2 = in.readInt();\n            return r1-r2;\n        }\n\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            this.reader = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String read() {\n            try {\n                if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                }\n            } catch (IOException ex) {\n                throw new RuntimeException(ex);\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int readInt() {\n            return Integer.parseInt(read());\n        }\n\n        public long readLong() {\n            return Long.parseLong(read());\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\n}", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class Solution{\n    private long [] sums;\n    private void solve(){\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n        int [] arr = new int[n];\n        this.sums = new long[n];\n        for(int i = 0; i < n; i++){\n            arr[i] = sc.nextInt();\n            sums[i] = arr[i] + (i == 0 ? 0 : sums[i - 1]);\n        }\n        long ans = 0;\n        for(int i = 1; i <= n && i <= m; i++){\n            ans = Math.max(ans, sum(0, i - 1) - k);\n        }\n        long [] dp = new long[n];\n        for(int i = 0; i < n; i++){\n            if(i + 1 >= m){\n                long cur = sum(i - m + 1, i) - k;\n                if(i - m >= 0){\n                    cur += dp[i - m];\n                }\n                dp[i] = Math.max(dp[i], cur);\n            }\n            for(int j = 0; j <= m && i + j < n; j++){\n                ans = Math.max(ans, dp[i] + sum(i + 1, i + j) - k * (j > 0 ? 1 : 0));\n            }\n        }\n        System.out.println(ans);\n    }\n    private long sum(int l, int r){\n        if(l <= 0){\n            return sums[r];\n        }else{\n            return sums[r] - sums[l - 1];\n        }\n    }\n    public static void main(String [] args){\n        new Solution().solve();\n    }\n}", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\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\n        long totalBlocks = 0;\n        long a[] = new long[n];\n        for(int i = 0; i < n; ++i) {\n            a[i] = sc.nextLong();\n            totalBlocks += a[i];\n        }\n\n        Arrays.sort(a);\n\n        long selected = 0;\n        for(int i = 0; i < n; ++i) {\n            if(a[i] > selected)\n                selected++;\n        }\n\n        long leftCols = a[n - 1] - selected;\n        long remBlocks = totalBlocks - leftCols - n;\n\n        System.out.print(remBlocks);\n    }\n}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "/*\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.ArrayList;\nimport java.util.Scanner;\n\n/**\n *\n * @author Ahmed\n */\n\n\n\n\npublic class Watermelon {\n\n   static class Passengers {\n  \n     public int floor ;\n     public int time;\n     \n     \n     public Passengers( int floor  , int time){\n         this.floor =floor;\n         this.time =time;\n     }\n     \n}\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        \n        Scanner in = new Scanner(System.in);\n        \n        int x = in.nextInt() , y = in.nextInt();\n        \n        ArrayList<Passengers> list = new ArrayList<>();\n        \n        for(int i = 1 ; i <= x ; ++i){\n            list.add(new Passengers(in.nextInt(), in.nextInt()));\n        }\n        \n        int sum = 0 ;\n       for(int i = list.size() - 1 ; i >= 0 ; --i)\n       {\n          int s = y -  list.get(i).floor;\n          sum = sum + s ; \n          \n          if(sum < list.get(i).time)\n          {\n              sum = sum + ( list.get(i).time - sum);\n          }\n          \n          y = list.get(i).floor;\n       } \n        \n        \n       if( list.get(list.size() - 1).floor != 0){\n           sum = sum  + (list.get(0).floor);\n       }\n        System.out.println(sum);\n    }\n    \n}\n", "complexity": "linear", "problem": "608_A. Saitama Destroys Hotel", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class MinimumDiameterTree{\n    public static void main(String[] args) {\n\tInputReader in = new InputReader (System.in);\n\tPrintWriter out = new PrintWriter (System.out);\n\n\tint n = in.nextInt();\n\tint s = in.nextInt();\n\tint deg[] = new int [n];\n\t\n\tfor (int i = 1; i < n; ++i) {\n\t    deg[in.nextInt() - 1] ++;\n\t    deg[in.nextInt() - 1] ++;\n\t}\n\n\tint l = 0;\n\tfor (int i = 0; i < n; ++i)\n\t    if (deg[i] == 1) l ++;\n\n\tout.println((double) 2 * s / l);\n\tout.close();\n    }\n\n    public static class InputReader {\n\tpublic BufferedReader reader;\n\tpublic StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t    reader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t    tokenizer = null;\n\t}\n\n\tpublic String next() {\n\t    while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\ttry {\n\t\t    tokenizer = new StringTokenizer(reader.readLine());\n\t\t} catch(IOException e) {\n\t\t    throw new RuntimeException(e);\n\t\t}\n\t    }\n\t    return tokenizer.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t    return Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "linear", "problem": "1086_B. Minimum Diameter Tree", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n \n/**\n *\n * @author Antonio \"Teo\" Alurralde\n */\npublic class Main {\n  public static void main(String[] args) throws IOException {\n    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    int n = Integer.parseInt(br.readLine());\n    StringTokenizer tok = new StringTokenizer(br.readLine());\n    int ax = Integer.parseInt(tok.nextToken());\n    int ay = Integer.parseInt(tok.nextToken());\n    tok = new StringTokenizer(br.readLine());\n    int bx = Integer.parseInt(tok.nextToken());\n    int by = Integer.parseInt(tok.nextToken());\n    tok = new StringTokenizer(br.readLine());\n    int cx = Integer.parseInt(tok.nextToken());\n    int cy = Integer.parseInt(tok.nextToken());\n    boolean ans = (bx < ax && cx < ax && by < ay && cy < ay) ||\n    (bx < ax && cx < ax && by > ay && cy > ay) ||\n    (bx > ax && cx > ax && by < ay && cy < ay) ||\n    (bx > ax && cx > ax && by > ay && cy > ay);\n    System.out.print(ans?\"YES\":\"NO\");\n  }\n}\n", "complexity": "constant", "problem": "1033_A. King Escape", "from": "CODEFORCES"}
{"src": "/**\n * Created by Aminul on 3/14/2019.\n */\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\nimport static java.lang.Math.max;\n\npublic class E_2 {\n    public static void main(String[] args) throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        int n = in.nextInt(), k = in.nextInt(), N = (int) 5e6 + 1;\n        int left = 0, right = 0;\n        int a[] = new int[n + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = in.nextInt();\n            if (a[i] == k) left++;\n        }\n        int f[] = new int[N + 1];\n        int ans = 0;\n        for (int i = n; i >= 1; i--) {\n            if (a[i] == k) left--;\n            f[a[i]]++;\n            f[a[i]] = max(f[a[i]], 1 + right);\n            ans = max(ans, f[a[i]] + left);\n            if (a[i] == k) right++;\n        }\n        pw.println(ans);\n        pw.close();\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n\n        public FastReader(InputStream is) {\n            this.is = is;\n        }\n\n        public 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        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = (num << 3) + (num << 1) + (b - '0');\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "1082_E. Increasing Frequency", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class TreasureHunt {\n\t\n\tpublic static String Solve() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tsc.nextLine();\n\t\tString kuro = sc.nextLine(), shiro = sc.nextLine(), katie = sc.nextLine();\n\t\tsc.close();\n\t\tString[] output = {\"Kuro\", \"Shiro\", \"Katie\", \"Draw\"};\n\t\tif(n >= kuro.length())\n\t\t\treturn output[3];\n\t\tint[] maxArr = new int[3];\t\t\n\t\tint[][] freq = new int[3][58];\n\t\tfor(int i = 0; i < kuro.length(); i++) {\n\t\t\tmaxArr[0] = ++freq[0][kuro.charAt(i) - 65] > maxArr[0]? freq[0][kuro.charAt(i) - 65] : maxArr[0];\n\t\t\tmaxArr[1] = ++freq[1][shiro.charAt(i) - 65] > maxArr[1]? freq[1][shiro.charAt(i) - 65] : maxArr[1];\n\t\t\tmaxArr[2] = ++freq[2][katie.charAt(i) - 65] > maxArr[2]? freq[2][katie.charAt(i) - 65] : maxArr[2];\n\t\t}\n\t\tint winner = 0, max = 0;\n\t\tfor(int i = 0; i < 3; i++) {\n\t\t\tif(kuro.length() - maxArr[i] >= n)\n\t\t\t\tmaxArr[i] += n;\n\t\t\telse \n\t\t\t\tmaxArr[i] = n == 1? kuro.length() - 1: kuro.length();\n\t\t\tif(max < maxArr[i]) {\n\t\t\t\twinner = i;\n\t\t\t\tmax = maxArr[i];\n\t\t\t} else if(max == maxArr[i])\n\t\t\t\twinner = 3;\n\t\t}\n\t\t\n\t\treturn output[winner];\n\t}\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(Solve());\n\t}\n}\n", "complexity": "linear", "problem": "979_B. Treasure Hunt", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class CF1197B {\n    public static void main(String[] args) {\n        FastReader input = new FastReader();\n        int n = input.nextInt();\n        int[] arr = new int[n];\n        int max = 0;\n        int maxIndex = 0;\n        for(int i = 0;i < n;i++){\n            arr[i] = input.nextInt();\n            if(arr[i] > max){\n                max = arr[i];\n                maxIndex = i;\n            }\n        }\n        int j = maxIndex - 1;\n        int k = maxIndex + 1;\n        while (j >= 0 && k < n){\n            if(arr[j] > arr[k]){\n                if(arr[j] < max){\n                    max = arr[j];\n                    j--;\n                }\n                else {\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n            else{\n                if(arr[k] < max){\n                    max = arr[k];\n                    k++;\n                }\n                else{\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if(j >= 0){\n            while (j >= 0){\n                if(arr[j] < max){\n                    max = arr[j];\n                    j--;\n                }\n                else{\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if(k < n){\n            while (k < n){\n                if(arr[k] < max){\n                    max = arr[k];\n                    k++;\n                }\n                else{\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if(j == -1 && k == n){\n            System.out.println(\"YES\");\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}", "complexity": "linear", "problem": "1197_B. Pillars", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author programajor\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        BigInteger mod = new BigInteger(\"1000000007\");\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            BigInteger x = new BigInteger(in.next());\n            BigInteger k = new BigInteger(in.next());\n            if (x.longValue() == 0) {\n                out.print(x);\n                return;\n            }\n            BigInteger pow = powerWithMod(new BigInteger(\"2\"), k);\n            BigInteger current = x.mod(mod).multiply(pow).mod(mod);\n            BigInteger result = current.multiply(new BigInteger(\"2\")).mod(mod)\n                    .subtract(pow.subtract(new BigInteger(\"1\")).mod(mod))\n                    .mod(mod);\n            out.print(result);\n        }\n\n        BigInteger powerWithMod(BigInteger base, BigInteger exponent) {\n            if (exponent.longValue() == 0) {\n                return new BigInteger(\"1\");\n            }\n            BigInteger temp = powerWithMod(base, exponent.divide(new BigInteger(\"2\")));\n            BigInteger term = temp.mod(mod);\n            if (exponent.mod(new BigInteger(\"2\")).intValue() == 0) {\n                return term.multiply(term.mod(mod)).mod(mod);\n            } else {\n                return term.multiply(term.mod(mod)).multiply(base.mod(mod)).mod(mod);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 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    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\n// author @mdazmat9\npublic  class codeforces{\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 test = 1;\n        for (int ind = 0; ind < test; ind++) {\n          int [] a=new int[3];\n          a[0]=sc.nextInt();\n          a[1]=sc.nextInt();\n          a[2]=sc.nextInt();\n          Arrays.sort(a);\n          int k1=a[0];\n          int k2=a[1];\n          int k3=a[2];\n          if(k1==1 || k2==1 || k3==1){\n              out.println(\"YES\");\n          }\n          else if((k1==2 && k2==2)||(k2==2 && k3==2)){\n              out.println(\"YES\");\n            }\n            else if(k1==3 && k2==3 && k3==3){\n              out.println(\"YES\");\n          }\n          else if(k1==2 && k2==4 && k3==4){\n              out.println(\"YES\");\n          }\n          else\n              out.println(\"NO\");\n\n        }\n        out.flush();\n    }\n\n\n\n\n\n    static   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    static long gcd(long a , long b)\n    {\n        if(b == 0)\n            return a;\n        return gcd(b , a % b);\n    }\n\n}\nclass Scanner {\n    public BufferedReader reader;\n    public StringTokenizer st;\n\n    public Scanner(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n        st = null;\n    }\n\n    public String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                String line = reader.readLine();\n                if (line == null) return null;\n                st = new StringTokenizer(line);\n            } catch (Exception e) {\n                throw (new RuntimeException());\n            }\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    public long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    public double nextDouble() {\n        return Double.parseDouble(next());\n    }\n}\n\nclass OutputWriter {\n    BufferedWriter writer;\n\n    public OutputWriter(OutputStream stream) {\n        writer = new BufferedWriter(new OutputStreamWriter(stream));\n    }\n\n    public void print(int i) throws IOException {\n        writer.write(i);\n    }\n\n    public void print(String s) throws IOException {\n        writer.write(s);\n    }\n\n    public void print(char[] c) throws IOException {\n        writer.write(c);\n    }\n\n    public void close() throws IOException {\n        writer.close();\n    }\n\n}", "complexity": "constant", "problem": "911_C. Three Garlands", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n \n \npublic class Main {\n\t\n\tstatic InputReader in = new InputReader(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic long oo = 1000000000000L;\n\t\n\tpublic static void main(String[] args) throws IOException {\n \n\t\tint n = in.nextInt();\n\t\tint q = in.nextInt();\n\t\t\n\t\tArrayDeque<Integer> dq = new ArrayDeque<>();\n\t\tint max = -1;\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tdq.add(x);\n\t\t\tmax = Math.max(max, x);\n\t\t}\n\t\tArrayList<Pair> ans = new ArrayList<>();\n\t\twhile(dq.peekFirst() != max) {\n\t\t\tint a = dq.pollFirst();\n\t\t\tint b = dq.pollFirst();\n\t\t\tans.add(new Pair(a, b));\n\t\t\tif(a > b) {\n\t\t\t\tdq.addFirst(a);\n\t\t\t\tdq.addLast(b);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdq.addFirst(b);\n\t\t\t\tdq.addLast(a);\n\t\t\t}\n\t\t}\n\t\tArrayList<Integer> a = new ArrayList<>();\n\t\tdq.pollFirst();\n\t\tfor(int x : dq)\n\t\t\ta.add(x);\n\t\twhile(q --> 0) {\n\t\t\tlong m = in.nextLong() - 1;\n\t\t\tif(m < ans.size()) {\n\t\t\t\tSystem.out.println(ans.get((int)m).first + \" \" + ans.get((int)m).second);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint idx = (int)((m - ans.size()) % a.size());\n\t\t\t\tSystem.out.println(max + \" \" + a.get(idx));\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\t\n\t\n\tstatic long lcm(long a, long b) {\n\t\treturn a * b / gcd(a, b);\n\t}\n\t\n\tstatic boolean nextPermutation(int[] a) {\n\t\tfor(int i = a.length - 2; i >= 0; --i) {\n\t\t\tif(a[i] < a[i+1]) {\n\t\t\t\tfor(int j = a.length - 1; ; --j) {\n\t\t\t\t\tif(a[i] < a[j]) {\n\t\t\t\t\t\tint t = a[i];\n\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\tfor(i++, j = a.length - 1; i < j; ++i, --j) {\n\t\t\t\t\t\t\tt = a[i];\n\t\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\t\n\tstatic void shuffle(int[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tint t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic void shuffle(long[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tlong t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic int lower_bound(int[] a, int n, int k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\tstatic int lower_bound(long[] a, int n, long k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\t\n\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\tstatic long gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\t\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint first, second;\n \n\t\tpublic Pair(int first, int second) {\n\t\t\tsuper();\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn this.first != o.first ? this.first - o.first : this.second - o.second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + first;\n\t\t\tresult = prime * result + second;\n\t\t\treturn result;\n\t\t}\n \n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tPair other = (Pair) obj;\n\t\t\tif (first != other.first)\n\t\t\t\treturn false;\n\t\t\tif (second != other.second)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t}\n\t\n\t\n}\n \n \n \nclass InputReader {\n \n\tprivate final InputStream stream;\n\tprivate final byte[] buf = new byte[8192];\n\tprivate int curChar, snumChars;\n \n\tpublic InputReader(InputStream st) {\n\t\tthis.stream = st;\n\t}\n \n\tpublic int read() {\n\t\tif (snumChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= snumChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (snumChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n \n\tpublic int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n \n\tpublic long nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n \n\tpublic int[] nextIntArray(int n) {\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\treturn a;\n\t}\n \n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n \n\tprivate boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n \n}", "complexity": "linear", "problem": "1180_C. Valeriy and Deque", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class AAA {\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());\t\n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint m=Integer.parseInt(st.nextToken());\n\t\tString a=\"\";\n\t\tString b=\"\";\n\t\tfor(int i=0;i<1129;i++) {\n\t\t\ta+=\"1\";\n\t\t\tb+=\"8\";\n\t\t}\n\t\ta+=\"9\";\n\t\tb+=\"1\";\n\t\t\n\t\tSystem.out.println(a);\n\t\tSystem.out.println(b);\n\t}\n\t\t\n}\n", "complexity": "constant", "problem": "1028_B. Unnatural Conditions", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class E1180D {\n\n    public static void main(String args[]) {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n\n        // Move from both ends, Time limit exceeded on test 6\n        for (int i= 1; i<= m/2; i++) {\n            // String s = \"\";\n            int i2 = m -i + 1; // the other end of i\n            // i is left row, i2 is right row\n            for (int j = 1; j <= n ; j++) {\n                int j2 = n - j + 1;\n                // start with (i,j), then go thru all the cell with (,i) and (,i2)\n                pw.println(j + \" \" + i);\n                pw.println(j2+ \" \" + i2);\n                // s += j + \" \" + i + \"\\n\" + j2+ \" \" + i2 + \"\\n\";\n            }\n            // out.print(s);\n        }\n        \n        // if n is odd, there is one line in the middle\n        if (m % 2 == 1) {\n            int i2 = m /2 + 1; // this is the middle column\n            for (int j = 1; j <= n/2 ; j++) {\n                int j2 = n - j + 1;\n                // start with (i,j), then go thru all the cell with (,i) and (,i2)\n                pw.println(j + \" \" + i2);\n                pw.println(j2+ \" \" + i2);\n            }\n            if (n %2 == 1) {\n                int j = n /2 + 1;\n                pw.println(j + \" \" + i2);\n            }\n        }\n        pw.flush();\n        pw.close();\n    }    \n}\n", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class C {\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        int counter = 0;\n        for(int i=0; i<2*n/3; i++) System.out.println(\"0 \" + i);\n        for(int i=0; i<n-2*n/3; i++) System.out.println(\"3 \" + (2*i+1));\n\n    }\n}\n", "complexity": "linear", "problem": "1067_C. Knights", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\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\n        long totalBlocks = 0;\n        long a[] = new long[n];\n        for(int i = 0; i < n; ++i) {\n            a[i] = sc.nextLong();\n            totalBlocks += a[i];\n        }\n\n        Arrays.sort(a);\n\n        long selected = 0;\n        for(int i = 0; i < n; ++i) {\n            if(a[i] > selected)\n                selected++;\n        }\n\n        long leftCols = a[n - 1] - selected;\n        long remBlocks = totalBlocks - leftCols - n;\n\n        System.out.print(remBlocks);\n    }\n}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class codef8 {\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint num = sc.nextInt();\n\t\tint beacon[] = new int[1000001];\n\t\tint pos[] = new int[num];\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tint position = sc.nextInt();\n\t\t\tbeacon[position] = sc.nextInt();\n\t\t\tpos[i] = position;\n\t\t}\n\t\tint dp[] = new int[1000001];\n\t\tint max = 1;\n\t\tif (beacon[0] != 0)\n\t\t\tdp[0] = 1;\n\t\t\n\t\tfor (int i = 1; i <= 1000000; i++) {\n\t\t\tif (beacon[i] == 0) {\n\t\t\t\tdp[i] = dp[i-1];\n\t\t\t} \n\t\t\telse {\n\t\t\t\tint j = i - beacon[i] - 1;\n\t\t\t\tif (j < 0) {\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp[i] = dp[j] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, dp[i]);\n\t\t}\t\t\n\t\tSystem.out.println(num-max);\n\t}\n\n}\n", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "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        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            int inv = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < i; j++) {\n                    if (a[j] > a[i]) {\n                        inv++;\n                    }\n                }\n            }\n            int m = in.nextInt();\n            for (int i = 0; i < m; i++) {\n                int l = in.nextInt();\n                int r = in.nextInt();\n                int s = (r - l + 1) * (r - l) / 2;\n                inv = (inv + s) % 2;\n                out.println(inv % 2 == 0 ? \"even\" : \"odd\");\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import com.sun.org.apache.xpath.internal.operations.Bool;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        MyScanner scan = new MyScanner();\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n\n        int n = scan.nextInt();\n        int[] vals = new int[n];\n        for (int i = 0; i < n; i++) {\n            vals[i] = scan.nextInt();\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (solve(i, vals)) {\n                out.print('A');\n            } else {\n                out.print('B');\n            }\n        }\n\n        out.close();\n    }\n\n    static HashMap<Integer, Boolean> dpResult = new HashMap<>();\n\n    private static boolean solve(int pos, int[] vals) {\n        if (dpResult.containsKey(pos)) return dpResult.get(pos);\n        int val = vals[pos];\n        boolean hasLose = false;\n        for (int i = pos; i < vals.length; i += val) {\n            if (i == pos) continue;\n            if (vals[i] <= vals[pos]) continue;\n            if (hasLose) break;\n            if (!solve(i, vals)) {\n                hasLose = true;\n            }\n        }\n        for (int i = pos; i >= 0; i -= val) {\n            if (i == pos) continue;\n            if (vals[i] <= vals[pos]) continue;\n            if (hasLose) break;\n            if (!solve(i, vals)) {\n                hasLose = true;\n            }\n        }\n        dpResult.put(pos, hasLose);\n        return hasLose;\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}", "complexity": "nlogn", "problem": "1033_C. Permutation Game", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    public void solve() {\n        int n = ni();\n        int a = ni();\n        int b = ni();\n\n        long ans = 0;\n        HashMap<Long, Long> m = new HashMap<>();\n        HashMap<String, Long> s = new HashMap<>();\n\n        for (int i = 0; i < n; i++) {\n            ni();\n            long vx = ni();\n            long vy = ni();\n            long v = (long) a * vx - vy;\n            String k = vx + \"|\" + vy;\n            long cs = s.getOrDefault(k, 0L);\n            long c = m.getOrDefault(v, 0L);\n            ans += c - cs;\n            m.put(v, c + 1);\n            s.put(k, cs + 1);\n        }\n        write (ans * 2 + \"\\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}", "complexity": "linear", "problem": "975_D. Ghosts", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class pr1073B {\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\n        int n = Integer.parseInt(br.readLine());\n\n        int[] a = new int[n];\n        int[] b = new int[n];\n\n        StringTokenizer st = new StringTokenizer(br.readLine());\n\n        for (int i = 0; i < n; i++) {\n            a[i] = Integer.parseInt(st.nextToken());\n        }\n        st = new StringTokenizer(br.readLine());\n        for (int i = 0; i < n; i++) {\n            b[i] = Integer.parseInt(st.nextToken());\n        }\n\n        solve(n, a, b, out);\n        out.flush();\n        out.close();\n    }\n\n    private static void solve(int n, int[] a, int[] b, PrintWriter out) {\n        boolean[] book = new boolean[n+1];\n        boolean f;\n        int j1 = 0, j2 = 0;\n        for (int i = 0; i < n; i++) {\n            f = false;\n            int num = b[i];\n            if(!book[num]) {\n                f = true;\n                j1 = j2;\n                for (;j2 < n; j2++) {\n                    book[a[j2]] = true;\n                    if (a[j2] == num) {\n                        j2++;\n                        break;\n                    }\n                }\n            }\n            out.print(f ? j2-j1 + \" \": 0 + \" \");\n        }\n    }\n}\n", "complexity": "linear", "problem": "1073_B. Vasya and Books", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class LectureSleep {\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        public float nextFloat() {\n            return Float.parseFloat(next());\n        }\n\n    }\n\n    static InputReader r = new InputReader(System.in);\n    static PrintWriter pw = new PrintWriter(System.out);\n\n\n    public static void main(String[] args) {\n        int n = r.nextInt(); // duration of lecture\n        int k = r.nextInt(); // number of minutes keep mishka awake\n        int[] theorems = new int[n+1];\n        for(int i = 1; i <= n; i++){\n            theorems[i] = r.nextInt();\n        }\n        int[] mishka = new int[n+1];\n        for(int i = 1; i <= n; i++){\n            mishka[i] = r.nextInt();\n        }\n        int[] sums = new int[n+1];\n        for(int i = 1; i <= n; i++){\n            if(mishka[i] == 0){\n                sums[i] = sums[i-1] + theorems[i];\n            } else{\n                sums[i] = sums[i-1];\n            }\n        }\n        int max = 0;\n        for(int i = 1; i <= n-k+1; i++){\n            int sum = sums[i+k-1] - sums[i-1];\n            max = Math.max(max, sum);\n        }\n        int totalSum = 0;\n        for(int i = 1; i <= n; i++){\n            if(mishka[i] == 1){\n                totalSum += theorems[i];\n            }\n        }\n\n        pw.println(totalSum + max);\n\n        pw.close();\n    }\n}", "complexity": "linear", "problem": "961_B. Lecture Sleep", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class C {\n\n\tpublic static int mod = 1000000000 + 7;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tString n = br.readLine();\n\t\tint k = Integer.parseInt(br.readLine());\n\t\tint l = n.length();\n\t\t\n\t\tif(k == 0) {\n\t\t\tSystem.out.println(1);\n\t\t}else {\n\t\t\tint max = 1000;\n\t\t\tif (l <= 10) {\n\t\t\t\tmax = Integer.min(1000, Integer.parseInt(n, 2));\n\t\t\t}\n\n\t\t\tint[] steps = new int[max + 1];\n\t\t\t\t\t\n\t\t\tfor (int i = 2; i <= max; i++) {\n\t\t\t\tint ones = numberOfOnes(i);\n\t\t\t\tsteps[i] = 1 + steps[ones];\n\t\t\t}\n\n\t\t\tif (l <= 10) {\n\t\t\t\tint ans = 0;\n\t\t\t\tfor (int i = 1; i <= max; i++) {\n\t\t\t\t\tif (steps[i] == k) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.println(ans);\n\t\t\t} else {\n\t\t\t\tint[][] C = binomial(max);\n\n\t\t\t\tint ans = 0;\n\t\t\t\tint count = 0;\n\n\t\t\t\tfor (int i = 0; i < l; i++) {\n\t\t\t\t\tif (n.charAt(i) == '1') {\n\t\t\t\t\t\tfor (int j = count; j < max; j++) {\n\t\t\t\t\t\t\tif (steps[j] == k - 1) {\n\t\t\t\t\t\t\t\tans = (ans + C[l - i - 1][j - count]) % mod;\n\t\t\t\t\t\t\t\tif (i == 0 && k == 1) {\n\t\t\t\t\t\t\t\t\tans = (ans + mod - 1) % 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\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tint ones = 0;\n\t\t\t\tfor (int i = 0; i < l; i++) {\n\t\t\t\t\tif (n.charAt(i) == '1') {\n\t\t\t\t\t\tones++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (steps[ones] == k-1) {\n\t\t\t\t\tans = (ans + 1) % mod;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static int numberOfOnes(int x) {\n\t\tchar[] s = Integer.toBinaryString(x).toCharArray();\n\t\tint count = 0;\n\t\tfor (char c : s) {\n\t\t\tif (c == '1') {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n\n\tpublic static int[][] binomial(int n) {\n\t\tint[][] C = new int[n + 1][n + 1];\n\n\t\tfor (int i = 0; i <= n; 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] % mod) + (C[i - 1][j] % mod)) % mod;\n\t\t\t}\n\t\t}\n\n\t\treturn C;\n\t}\n\n}\n", "complexity": "linear", "problem": "914_C. Travelling Salesman and Special Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.PrintWriter;\n\nimport java.io.InputStreamReader;\n\nimport java.io.IOException;\n\nimport java.util.StringTokenizer;\n\nimport java.util.Arrays;\n\npublic class Main {\n    \n    static Scanner in = new Scanner();\n    static PrintWriter out = new PrintWriter(System.out);\n    \n    public static void main(String[] args) throws IOException {\n        long n = in.nextLong(), m = in.nextLong();\n        out.print(m / n + (m % n == 0 ? 0 : 1));\n        out.close();\n    }\n    \n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public Scanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            st = new StringTokenizer(\"\");\n        }\n        \n        public String next() throws IOException {\n            if(!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}", "complexity": "constant", "problem": "1036_A. Function Height", "from": "CODEFORCES"}
{"src": "import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;\nimport jdk.management.cmm.SystemResourcePressureMXBean;\n\nimport java.awt.*;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.util.List;\nimport java.math.*;\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) {\n        solver s = new solver();\n        int t = 1;\n        while (t > 0) {\n            s.solve();\n            t--;\n        }\n        out.close();\n    }\n\n   /* static class descend implements Comparator<pair1> {\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 next() {\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 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 class card {\n        long a;\n        int cnt;\n        int i;\n\n        public card(long a, int cnt, int i) {\n            this.a = a;\n            this.cnt = cnt;\n            this.i = i;\n        }\n    }\n\n    static class ascend implements Comparator<pair> {\n        public int compare(pair o1, pair o2) {\n            return o1.a - o2.a;\n        }\n    }\n\n    static class extra {\n\n        static boolean v[] = new boolean[100001];\n        static List<Integer> l = new ArrayList<>();\n        static int t;\n\n        static void shuffle(long a[]) {\n            List<Long> l = new ArrayList<>();\n            for (int i = 0; i < a.length; i++)\n                l.add(a[i]);\n            Collections.shuffle(l);\n            for (int i = 0; i < a.length; i++)\n                a[i] = l.get(i);\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                return true;\n            else\n                return false;\n        }\n\n        static void seive() {\n            for (int i = 2; i < 100001; i++) {\n                if (!v[i]) {\n                    t++;\n                    l.add(i);\n                    for (int j = 2 * i; j < 100001; j += i)\n                        v[j] = true;\n                }\n            }\n        }\n\n        static int binary(long 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[mid] == val) {\n                    r = mid - 1;\n                    ans = mid;\n                } else if (a[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(int x, int 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(int x, int y, int 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\n    static class pair {\n        int a;\n        int b;\n\n        public pair(int a, int i) {\n            this.a = a;\n            this.b = i;\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 long m = (long) 1e9 + 7;\n\n    static class solver {\n        void solve() {\n            int n = sc.nextInt();\n            int ans=0;\n            int a[]=new int[2*n];\n            for (int i = 0; i < 2 * n; i++) {\n               a[i]=sc.nextInt();\n            }\n            for(int i=0;i<2*n;i++)\n            {\n                if(a[i]>0)\n                {\n                    int j=0;\n                    for(j=i+1;a[i]!=a[j];j++)\n                    {\n                        if(a[j]>0)\n                            ans++;\n                    }\n                    a[j]=0;\n                }\n            }\n            System.out.println(ans);\n        }\n    }\n}", "complexity": "quadratic", "problem": "995_B. Suit and Tie", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    private static void solve(InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n        int m = in.nextInt();\n\n        String[] sa = new String[n];\n        for (int i = 0; i < n; i++) {\n            sa[i] = in.next();\n        }\n\n        Set<Integer> switches = new HashSet<>();\n        for (int i = 0; i < m; i++) {\n            int cnt = 0, swtch = -1;\n            for (int j = 0; j < n; j++) {\n                if (sa[j].charAt(i) == '1') {\n                    cnt++;\n                    swtch = j;\n                    if (cnt > 1)\n                        break;\n                }\n            }\n\n            if (cnt == 1) {\n                switches.add(swtch);\n            }\n        }\n\n        out.print(switches.size() == n ? \"NO\" : \"YES\");\n    }\n\n    private static void shuffleArray(int[] array) {\n        int index;\n        Random random = new Random();\n        for (int i = array.length - 1; i > 0; i--) {\n            index = random.nextInt(i + 1);\n            if (index != i) {\n                array[index] ^= array[i];\n                array[i] ^= array[index];\n                array[index] ^= array[i];\n            }\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    private static class InputReader {\n        private BufferedReader br;\n        private 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    private 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", "complexity": "quadratic", "problem": "985_B. Switches and Lamps", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class CodeForces\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n\t\tSystem.out.println(input.nextInt() / 2 + 1);\n\t}\n}", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class MicroWorld {\n\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\t\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\t\n\t\tint[] temp = new int[1000001];\n\t\t\n\t\tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t\t\n\t\tfor (int i = 0; i < n; i++){\n\t\t\t\n\t\t\ttemp[Integer.parseInt(st1.nextToken())]++;\n\t\t}\n\t\t\n\t\tint b = k + 1;\n\t\t\n\t\tfor (int i = 1000000; i > 0; i--){\n\t\t\t\n\t\t\tif (temp[i] > 0){\n\t\t\t\tif (b <= k){\n\t\t\t\t\tn -= temp[i];\n\t\t\t\t}\n\t\t\t\tb = 1;\n\t\t\t}else{\n\t\t\t\tb++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(n);\n\t\t\n\t}\n\n}\n", "complexity": "nlogn", "problem": "990_B. Micro-World", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class SonyaExhibition {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer tokenizer;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = nextInt();\n\t\tint[] arr = {0,1};\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tSystem.out.print(arr[i % 2]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic static String next() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\tString line = br.readLine();\n\t\t\tif (line == null)\n\t\t\t\tthrow new IOException();\n\t\t\ttokenizer = new StringTokenizer(line);\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n}\n", "complexity": "linear", "problem": "1004_B. Sonya and Exhibition", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ayyyyyy\n{\n\tpublic static void main(String[] args) { new ayyyyyy(); }\n\tScanner in = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\t\n\tint t, n;\n\tint[] a;\n\t\n\tayyyyyy()\n\t{\n\t\tt = in.nextInt();\n\t\twhile (t --> 0)\n\t\t{\n\t\t\ta = new int[n = in.nextInt()];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = in.nextInt();\n\t\t\tshuffle(a);\n\t\t\tArrays.sort(a);\n\t\t\tout.println(Math.min(n-2, a[n-2]-1));\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\tvoid shuffle(int[] x)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tint swp = (int)(n*Math.random());\n\t\t\tint tmp = x[swp];\n\t\t\tx[swp] = x[i];\n\t\t\tx[i] = tmp;\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "1197_A. DIY Wooden Ladder", "from": "CODEFORCES"}
{"src": "//package contese_476;\nimport java.util.*;\npublic class q1 \n{\n\tint m=(int)1e9+7;\npublic class Node\n{\n\tint a;\n\tint b;\n\tpublic void Node(int a,int b)\n\t{\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t}\n}\npublic int mul(int a ,int b)\n{\na=a%m;\nb=b%m;\nreturn((a*b)%m);\n}\npublic int pow(int a,int b)\n{\n\tint x=1;\n\twhile(b>0)\n\t{\n\t\tif(b%2!=0)\n\t\t\tx=mul(x,a);\n\t\ta=mul(a,a);\n\t\tb=b/2;\n\t}\n\treturn x;\n}\npublic static long gcd(long a,long b)\n{\n\tif(b==0)\n\t\treturn a;\n\telse\n\t\treturn gcd(b,a%b);\n}\npublic static void main(String[] args)\n{\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tHashMap<Integer,Integer> h=new HashMap();\n\t//HashMap<Integer,Integer> h1=new HashMap();\n\tint[] a=new int[n];\n\tint x=sc.nextInt();\n\tfor(int i=0;i<n;i++)\n\t{\n\t\ta[i]=sc.nextInt();\n\t\tif(h.get(a[i])==null)\n\t\t{\n\t\t\th.put(a[i], 1);\n\t\t\t//h1.put(a[i],i);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\tcontinue;\n\t\t\n\t\telse\n\t\t{\n\t\t\t\n\t\t\tSystem.out.print(1);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\th.put(num, 1);\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(2);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tSystem.out.print(-1);\n\t\n     \n}\n\n}", "complexity": "linear", "problem": "1013_B. And", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\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.LinkedHashMap;\nimport java.util.Map;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n */\npublic class Practice {\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(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            String[] arr1 = new String[n];\n            String[] arr2 = new String[n];\n            for (int i = 0; i < n; i++) {\n                arr1[i] = in.next();\n            }\n            for (int i = 0; i < n; i++) {\n                arr2[i] = in.next();\n            }\n            int ans = 0;\n            boolean arr[]=new boolean[n];\n            boolean found=false;\n            for (int i = 0; i < arr1.length; i++) {\n                for(int j=0;j<arr1.length;j++){\n                    found=false;\n                    if(arr1[i].equals(arr2[j]) && !arr[j]){\n                        found=true;\n                        arr[j]=true;\n                        break;\n                    }\n                }\n                if(!found){\n                    ans++;\n                }\n            }\n            out.println(ans);\n        }\n    }\n\n    public static boolean checkPrime(int n, int p) {\n        for (int i = 2; i <= Math.sqrt(n) && i <= p; i++) {\n            if (n % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    public static void mergeArrays(int[] arr1, int[] arr2, int n1,\n            int n2, int[] arr3) {\n        int i = 0, j = 0, k = 0;\n        while (i < n1 && j < n2) {\n            if (arr1[i] < arr2[j]) {\n                arr3[k++] = arr1[i++];\n            } else {\n                arr3[k++] = arr2[j++];\n            }\n        }\n        while (i < n1) {\n            arr3[k++] = arr1[i++];\n        }\n        while (j < n2) {\n            arr3[k++] = arr2[j++];\n        }\n    }\n\n    public 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 nCr(int n, int r) {\n        return n * (n - 1) / 2;\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        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n    }\n\n}\n", "complexity": "quadratic", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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 sumit\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            CChessboard solver = new CChessboard();\n            solver.solve(1, in, out);\n            out.close();\n      }\n\n      static class CChessboard {\n            int[] nextPermutation(int[] array) {\n                  int i = array.length - 1;\n                  while (i > 0 && array[i - 1] >= array[i]) {\n                        i--;\n                  }\n\n                  if (i <= 0) {\n                        return null;\n                  }\n\n                  int j = array.length - 1;\n\n                  while (array[j] <= array[i - 1]) {\n                        j--;\n                  }\n\n                  int temp = array[i - 1];\n                  array[i - 1] = array[j];\n                  array[j] = temp;\n\n                  j = array.length - 1;\n\n                  while (i < j) {\n                        temp = array[i];\n                        array[i] = array[j];\n                        array[j] = temp;\n                        i++;\n                        j--;\n                  }\n\n                  return array;\n            }\n\n            public void solve(int testNumber, InputReader in, OutputWriter out) {\n                  int n = in.nextInt();\n                  int arr[][][] = new int[4][n][n];\n                  int sum[] = new int[4];\n\n                  for (int k = 0; k < 4; k++) {\n                        for (int i = 0; i < n; i++) {\n                              String str = in.next();\n                              for (int j = 0; j < n; j++) {\n                                    arr[k][i][j] = (str.charAt(j) - '0');\n                              }\n                        }\n                  }\n\n                  for (int k = 0; k < 4; k++) {\n                        for (int i = 0; i < n; i++) {\n                              for (int j = 0; j < n; j++) {\n                                    if ((i + j) % 2 == arr[k][i][j])\n                                          sum[k]++;\n                              }\n                        }\n                  }\n\n                  int perm[] = new int[4];\n                  for (int i = 0; i < 4; i++)\n                        perm[i] = i;\n\n\n                  int min = Integer.MAX_VALUE;\n                  while (true) {\n                        perm = nextPermutation(perm);\n\n                        if (perm == null)\n                              break;\n\n                        int sm = 0;\n                        for (int j = 0; j < 4; j++) {\n                              if (j % 2 == 0) {\n                                    sm += (sum[perm[j]]);\n                              } else {\n                                    sm += (n * n - sum[perm[j]]);\n                              }\n                        }\n                        min = Math.min(min, sm);\n\n                        sm = 0;\n                        for (int j = 0; j < 4; j++) {\n                              if (j % 2 == 0) {\n                                    sm += (n * n - sum[perm[j]]);\n                              } else {\n                                    sm += (sum[perm[j]]);\n                              }\n                        }\n                        min = Math.min(sm, min);\n\n\n                  }\n                  out.printLine(min);\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(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 (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\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 & 15;\n\n                        c = read();\n                  } while (!isSpaceChar(c));\n\n                  return res * sgn;\n            }\n\n            public String next() {\n                  int c = read();\n\n                  while (isSpaceChar(c))\n                        c = read();\n\n                  StringBuilder res = new StringBuilder();\n\n                  do {\n                        res.appendCodePoint(c);\n\n                        c = read();\n                  } while (!isSpaceChar(c));\n\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}\n\n", "complexity": "quadratic", "problem": "961_C. Chessboard", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner read = new Scanner(System.in);\n        double a = (double)read.nextInt();\n        double v = (double)read.nextInt();\n        double l = (double)read.nextInt();\n        double d = (double)read.nextInt();\n        double w = (double)read.nextInt();\n        double t=0;\n        if(w>=v){\n            double d1=v*v/(2*a);\n            if(d1>l){\n                t+= Math.sqrt(2*l/a);\n            }\n            else{\n                t+= v/a + (l-d1)/v;\n            }\n        }\n        else{\n            double temp = (v-w)/a;\n            double d1 = v*v/(2*a);\n            double d2 = d - v*temp + a*temp*temp/2;\n            if(d1>d2){\n                double temp2 = Math.sqrt(2*a*d);\n                if(temp2<w){\n                    w=temp2;\n                    temp=(v-w)/a;\n                    t+= temp2/a;\n                }\n                else{\n                    double vx=Math.sqrt(v*v/2+a*d2);\n                    t+= (vx/a) + ((vx-w)/a);\n                }\n            }\n            else{\n                t+= (v/a) + ((d2-d1)/v) + (temp);\n            }\n            double d3 = d + w*temp + a*temp*temp/2;\n            if(d3>l){\n                t+= (-w+Math.sqrt(w*w+2*a*(l-d)))/a;\n            }\n            else{\n                t+= (temp) + ((l-d3)/v);\n            }\n        }\n        System.out.printf(\"%.6f\", t);\n        read.close();\n    }\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "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 m=Integer.parseInt(s1[1]);\n            int a[]=new int[n];\n            String s2[]=br.readLine().split(\" \");\n            long S=0;\n            for(int i=0;i<n;i++)\n            { a[i]=Integer.parseInt(s2[i]);  S+=(long)a[i]; }\n            \n            Arrays.sort(a);\n            m=a[n-1];\n            int last=1;\n            int t=1;\n            for(int i=1;i<n-1;i++)\n            {\n                  if(a[i]==last)\n                   t++;\n                  else\n                  {\n                        t++;\n                        last=last+1;\n                  }\n            }\n            if(last<m)\n            { t+=m-last; }\n            else\n             t++;\n            System.out.println(S-t);\n      }\n}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n    private static int[] a;\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt(), m = sc.nextInt();\n\n        a = new int[101];\n        for (int i = 0; i < m; i++) {\n            int type = sc.nextInt();\n            a[type] = a[type] + 1;\n        }\n\n        int lo=1, hi=100, max=0;\n\n        while (lo <= hi) {\n            int mid = lo + (hi - lo)/2;\n            if (check(n, mid)) {\n                max = mid;\n                lo = mid+1;\n            } else {\n                hi = mid -1;\n            }\n        }\n        System.out.println(max);\n    }\n\n    public static boolean check(int n, int target) {\n        int result = 0;\n        for (int i=0; i <a.length; i++) {\n            result = result + (a[i] / target);\n        }\n        if (result >= n) {return true;}\n        return false;\n    }\n}", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ErrorCorrectSystem\n{\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tString a = scan.next();\n\t\tString b = scan.next();\n\t\t\n\t\tint[][] mismatch = new int[26][26];\n\t\tfor(int i = 0; i < 26; i++) Arrays.fill(mismatch[i], -1);\n\t\tint[][] pair = new int[2][26];\n\t\tfor(int i = 0; i < 2; i++) Arrays.fill(pair[i], -1);\n\t\tint hd = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(a.charAt(i) != b.charAt(i)) {\n\t\t\t\thd++;\n\t\t\t\tmismatch[a.charAt(i)-'a'][b.charAt(i)-'a'] = i;\n\t\t\t\tpair[0][a.charAt(i)-'a'] = i;\n\t\t\t\tpair[1][b.charAt(i)-'a'] = i;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < 26; i++) {\n\t\t\tfor(int j = i+1; j < 26; j++) {\n\t\t\t\tif(mismatch[i][j] > -1 && mismatch[j][i] > -1) {\n\t\t\t\t\tSystem.out.println(hd-2);\n\t\t\t\t\tSystem.out.println((mismatch[i][j]+1)+\" \"+(mismatch[j][i]+1));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(a.charAt(i) != b.charAt(i)) {\n\t\t\t\t//try a gets b's letter\n\t\t\t\tif(pair[0][b.charAt(i)-'a'] > -1) {\n\t\t\t\t\tSystem.out.println(hd-1);\n\t\t\t\t\tSystem.out.println((i+1)+\" \"+(pair[0][b.charAt(i)-'a']+1));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(hd);\n\t\tSystem.out.println(\"-1 -1\");\n\t}\n\n}\n", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringJoiner;\nimport java.util.StringTokenizer;\nimport java.util.concurrent.ThreadLocalRandom;\nimport java.util.function.Function;\n\npublic class Main {\n\n    static int T;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        T = sc.nextInt();\n\n        PrintWriter pw = new PrintWriter(System.out);\n        for (int i = 0; i < T; i++) {\n            int n = sc.nextInt();\n            int[] a = sc.nextIntArray(n);\n            int[] ans = solve(n, a);\n            StringJoiner j = new StringJoiner(\" \");\n            for (int each : ans) {\n                j.add(String.valueOf(each));\n            }\n            pw.println(j.toString());\n        }\n        pw.flush();\n    }\n\n    static int[] solve(int N, int[] A) {\n        // a/b \u304c1\u306b\u8fd1\u3044\u3082\u306e\u3092\u63a2\u3059\n        shuffle(A);\n        Arrays.sort(A);\n        int cur = A[0];\n        int time = 1;\n        double r = 0;\n        int prev = -1;\n        int a = -1;\n        int b = -1;\n        for (int i = 1; i < N; i++) {\n            if( cur == A[i] ) {\n                time++;\n\n                if( time == 2 ) {\n                    if( prev != -1 ) {\n                        double r1 = (double)prev/cur;\n                        if( r1 > r ) {\n                            r = r1;\n                            a = prev;\n                            b = cur;\n                        }\n                    }\n                    prev = cur;\n                }\n\n                if( time == 4 ) {\n                    return new int[]{cur, cur, cur, cur};\n                }\n\n            } else {\n                time = 1;\n                cur = A[i];\n            }\n        }\n\n        return new int[]{a, a, b, b};\n    }\n\n    static void shuffle(int[] a) {\n        Random r = ThreadLocalRandom.current();\n        for (int i = a.length-1; i >= 0; i--) {\n            int j = r.nextInt(i+1);\n            int t = a[i];\n            a[i] = a[j];\n            a[j] = t;\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++)\n                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++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n    }\n\n    static <A> void writeLines(A[] as, Function<A, String> f) {\n        PrintWriter pw = new PrintWriter(System.out);\n        for (A a : as) {\n            pw.println(f.apply(a));\n        }\n        pw.flush();\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 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 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", "complexity": "nlogn", "problem": "1027_C. Minimum Value Rectangle", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\npublic class ElevatorOrStairs {\n\n\tprivate static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static final OutputStreamWriter writer = new OutputStreamWriter(System.out);\n\t\n\tpublic static void main(String...strings) throws Exception {\n\t\tString[] specs = reader.readLine().split(\" \");\n\t\t\n\t\tint x = Integer.parseInt(specs[0]);\n\t\tint y = Integer.parseInt(specs[1]);\n\t\tint z = Integer.parseInt(specs[2]);\n\t\tint t1 = Integer.parseInt(specs[3]);\n\t\tint t2 = Integer.parseInt(specs[4]);\n\t\tint t3 = Integer.parseInt(specs[5]);\n\t\t\n\t\treader.close();\n\t\tString ans = solve(x, y, z, t1, t2, t3);\n\t\twriter.append(ans);\n\t\twriter.flush();\n\t\twriter.close();\n\t}\n\t\n\tprivate static String solve(int x, int y, int z, int t1, int t2, int t3) {\n\t\tint time_using_stairs = Math.abs(x - y) * t1;\n\t\tint elevator_time_between_floor = Math.abs(x - z) * t2;\n\t\tint elevator_from_z_to_x = elevator_time_between_floor + 2*t3;\n\t\t\n \t\tint time_using_elevator = elevator_from_z_to_x + (Math.abs(x - y) * t2) + t3;\n \t\t\n \t\tif(time_using_elevator <= time_using_stairs) {\n \t\t\treturn \"YES\";\n \t\t}\n \t\treturn \"NO\";\n\t}\n}", "complexity": "constant", "problem": "1054_A. Elevator or Stairs?", "from": "CODEFORCES"}
{"src": "\t\t\n\t\t\t\t\t\t\timport 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.InputMismatchException;\n\t\t\t\t\t\t\t\t\t\t\tpublic class Solution1 implements Runnable\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tstatic final long MAX = 1000000007L;\n\t\t\t\t\t\t\t\t\t\t\t\tstatic class InputReader\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\t\tprivate InputStream stream;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate byte[] buf = new byte[1024];\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate int curChar;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate int numChars;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate SpaceCharFilter filter;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic InputReader(InputStream stream)\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\t\tthis.stream = stream;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic int read()\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\t\tif (numChars==-1) \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\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\tif (curChar >= numChars)\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\tcurChar = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttry \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\t\t\t\t\tnumChars = stream.read(buf);\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\t\t\t\tcatch (IOException e)\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\t\t\t\t\tthrow new InputMismatchException();\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\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn -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\treturn buf[curChar++];\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\t\tpublic String nextLine()\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\t\tString str = \"\";\n\t\t\t\t\t\t\t\t\t\t\t            try\n\t\t\t\t\t\t\t\t\t\t\t            {\n\t\t\t\t\t\t\t\t\t\t\t                str = br.readLine();\n\t\t\t\t\t\t\t\t\t\t\t            }\n\t\t\t\t\t\t\t\t\t\t\t            catch (IOException e)\n\t\t\t\t\t\t\t\t\t\t\t            {\n\t\t\t\t\t\t\t\t\t\t\t                e.printStackTrace();\n\t\t\t\t\t\t\t\t\t\t\t            }\n\t\t\t\t\t\t\t\t\t\t\t            return str;\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\tpublic int nextInt()\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\t\tint c = read();\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\twhile(isSpaceChar(c)) \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tint sgn = 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\tif (c == '-') \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\tsgn = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tint res = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdo \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\tif(c<'0'||c>'9') \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\twhile (!isSpaceChar(c)); \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\treturn res * sgn;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic long nextLong() \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\t\tint c = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c == '-') \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\tsgn = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tlong res = 0;\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\tdo \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\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\twhile (!isSpaceChar(c));\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * sgn;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic double nextDouble() \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\t\tint c = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c == '-') \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\tsgn = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tdouble res = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (!isSpaceChar(c) && c != '.') \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\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tif (c == '.') \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\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdouble m = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (!isSpaceChar(c)) \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\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tm /= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * sgn;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic String readString() \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\t\tint c = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdo \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\tres.appendCodePoint(c);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\twhile (!isSpaceChar(c));\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\treturn res.toString();\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\t\tpublic boolean isSpaceChar(int c) \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\t\tif (filter != null)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t\t\t\t\t\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\t\tpublic String next() \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\t\treturn readString();\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic interface SpaceCharFilter \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\t\tpublic boolean isSpaceChar(int ch);\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 \t\n\t\t\t\t\t\t\t\t\t\t\t\tpublic static void main(String args[]) throws Exception\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\t\tnew Thread(null, new Solution1(),\"Solution1\",1<<26).start();\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\tlong gcd(long a, long b)\n\t\t\t\t\t\t\t\t\t\t\t    {\n\t\t\t\t\t\t\t\t\t\t\t        if (a == 0)\n\t\t\t\t\t\t\t\t\t\t\t            return b;\n\t\t\t\t\t\t\t\t\t\t\t         \n\t\t\t\t\t\t\t\t\t\t\t        return gcd(b%a, a);\n\t\t\t\t\t\t\t\t\t\t\t    }\n\t\t\t\t\t\t\t\t\t\t\t    // method to return LCM of two numbers\n\t\t\t\t\t\t\t\t\t\t\t\t long lcm(long a, long b)\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\t        return (a*b)/gcd(a, b);\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\t int root(int a){\n\t\t\t\t\t\t\t\t\t\t\t\t\t while(arr[a] != a){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t arr[a] = arr[arr[a]];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t a = arr[a];\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\t return a;\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\t void union(int a,int b){\n\t\t\t\t\t\t\t\t\t\t\t\t\t int xroot = root(a);\n\t\t\t\t\t\t\t\t\t\t\t\t\t int yroot = root(b);\n\t\t\t\t\t\t\t\t\t\t\t\t\t if(arr[xroot] < arr[yroot]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t arr[xroot] = yroot;\n\t\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\t\t arr[yroot] = xroot;\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\t boolean find(int a,int b){\n\t\t\t\t\t\t\t\t\t\t\t\t\t int roota = root(a);\n\t\t\t\t\t\t\t\t\t\t\t\t\t int rootb = root(b);\n\t\t\t\t\t\t\t\t\t\t\t\t\t if(roota == rootb){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t return true;\n\t\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\t\t return false;\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\t int[] arr;\n\t\t\t\t\t\t\t\t\t\t\t\t final int level = 20;\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\tpublic void run()\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\t\tInputReader sc= new InputReader(System.in);\n\t\t\t\t\t\t\t\t\t\t\t\t\tPrintWriter w= new PrintWriter(System.out);\n\t\t\t\t\t\t\t\t\t\t\t\t\tint n = sc.nextInt();\n\t\t\t\t\t\t\t\t\t\t\t\t\tchar[] ch = new char[n];\n\t\t\t\t\t\t\t\t\t\t\t\t\tchar[] ch2 = new char[n];\n\t\t\t\t\t\t\t\t\t\t\t\t\tch = sc.next().toCharArray();\n\t\t\t\t\t\t\t\t\t\t\t\t\tch2 = sc.next().toCharArray();\n\t\t\t\t\t\t\t\t\t\t\t\t\tHashSet<Integer> hset[] = new HashSet[26];\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor(int i = 0;i < 26;i++){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\thset[i]  =new HashSet();\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\tint count = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor(int i = 0;i < ch.length;i++){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thset[ch[i]-97].add(ch2[i]-97);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount++;\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\tboolean flag = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint swap1 = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint swap2 = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint rem = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor(int i = 0;i < ch.length;i++){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(hset[ch2[i]-97].size() != 0){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tswap1 = i;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tflag = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(hset[ch2[i]-97].contains(ch[i]-97)){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trem = i;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount-=2;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tflag = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\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\t\t\t\t}\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\tif(flag){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount--;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println(count);\n\t\t\t\t\t\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\t\t\t\t\tif(i != swap1 && ch[i] == ch2[swap1] && ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println((swap1+1) + \" \" + (i+1));\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.close();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSystem.exit(0);\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\t\t\t}\n\t\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\t\tif(rem == -1){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println(count);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println(\"-1 -1\");\n\t\t\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\t\t\tw.println(count);\n\t\t\t\t\t\t\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\t\t\t\t\t\tif(i != rem && ch[i] == ch2[rem] && ch[rem] == ch2[i] && ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println((rem+1) + \" \" + (i+1));\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.close();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSystem.exit(0);\n\t\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\t\t\t\t}\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\tw.close();\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\tboolean fun(long[] prefix,long mid,long temp,long[] arr){\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(temp >= prefix[(int)mid]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn true;\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\treturn false;\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\tstatic class Pair implements Comparable<Pair>{\n\t\t\t\t\t\t\t\t\t\t\t\t\tint x;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint y;\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\tPair(){}\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tPair(int x,int y){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.x = x;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.y = y;\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\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\tpublic int compareTo(Pair p){\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\treturn Long.compare(this.x,p.x);\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}", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class SFly {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\n\t\tint planet = Integer.parseInt(lector.readLine());\n\t\tint ini = Integer.parseInt(lector.readLine());\n\t\tdouble peso = ini;\n\t\tint[] desp = new int[planet];\n\t\tint[] ater = new int[planet];\n\t\tString[] temp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tdesp[i] = Integer.parseInt(temp[i]);\n\t\t\tif(desp[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tater[i] = Integer.parseInt(temp[i]);\n\t\t\tif(ater[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = null;\n\t\tint i=planet-1;\n\t\tpeso = (peso*ater[0])/(ater[0]-1);\n\t\twhile(i>0) {\n\t\t\tpeso = (peso*desp[i])/(desp[i]-1);\n\t\t\tpeso = (peso*ater[i])/(ater[i]-1);\n\t\t\ti--;\n\t\t}\n\t\tpeso = (peso*desp[0])/(desp[0]-1);\n\t\tpeso = peso - ini;\n\t\tSystem.out.println(peso);\n\t\tlector.close();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n    static StringTokenizer tok;\n    static boolean hasNext()\n    {\n        while(tok==null||!tok.hasMoreTokens())\n            try{\n                tok=new StringTokenizer(in.readLine());\n            }\n            catch(Exception e){\n                return false;\n            }\n        return true;\n    }\n    static String next()\n    {\n        hasNext();\n        return tok.nextToken();\n    }\n    static long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n    static int nextInt()\n    {\n        return Integer.parseInt(next());\n    }\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));\n\n    public static void main(String[] args) {\n        Map<Integer,Integer> map = new HashMap();\n        map.put(0,1);\n        int n = nextInt();\n        int m = nextInt();\n        int index = -1;\n        int a[] = new int[n];\n        for(int i=0;i<n;i++){\n            a[i]=nextInt();\n            if(a[i]==m)\n                index=i;\n        }\n        int sum = 0;\n        for(int i=0;i<index;i++){\n            if (a[i]<m)\n                sum--;\n            else\n                sum++;\n            if (map.containsKey(sum)){\n                map.put(sum,map.get(sum)+1);\n            }else {\n                map.put(sum,1);\n            }\n        }\n        long ans = 0;\n        for(int i=index;i<n;i++){\n            if (a[i]<m)\n                sum--;\n            else if(a[i]>m)\n                sum++;\n            if (map.containsKey(sum))\n                ans+=map.get(sum);\n            if (map.containsKey(sum-1))\n                ans+=map.get(sum-1);\n        }\n        out.print(ans);\n        out.flush();\n    }\n}\n", "complexity": "nlogn", "problem": "1005_E1. Median on Segments (Permutations Edition)", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        HashSet<Integer> set = new HashSet<>();\n        for(int i = 0; i<n; i++){\n            int a = sc.nextInt();\n            if(a!=0){\n                set.add(a);\n            }\n        }\n        System.out.println(set.size());\n    }\n}", "complexity": "linear", "problem": "992_A. Nastya and an Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class Solution {\n    private static int[] dx = {\n            -1, -1, -1,\n            0, 0,\n            1, 1, 1};\n    private static int[] dy = {\n            -1, 0, 1,\n            -1, 1,\n            -1, 0, 1};\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n\n        int r = in.nextInt();\n        int c = in.nextInt();\n        boolean[][] m = new boolean[r + 1][c + 1];\n        boolean[][] inp = new boolean[r + 1][c + 1];\n        for (int i = 0; i < r; i++) {\n            String s = in.next();\n            //System.out.println(m[i]);\n            for (int j = 0; j < s.length(); j++) {\n                if (s.charAt(j) == '#') {\n                    m[i][j] = true;\n                    inp[i][j] = true;\n                }\n            }\n        }\n\n        for (int i = 0; i < r; i++) {\n            for (int j = 0; j < c; j++) {\n                if (canPress(i, j, r, c, inp)) {\n\n                    // make press\n                    for (int k = 0; k < 8; k++) {\n                        int xi = i + dx[k];\n                        int yi = j + dy[k];\n                        m[xi][yi] = false;\n                    }\n\n                }\n            }\n        }\n        boolean isLeftAny = false;\n        for (int i = 0; i < r && !isLeftAny; i++) {\n            for (int j = 0; j < c && !isLeftAny; j++) {\n                if (m[i][j]) {\n                    isLeftAny = true;\n                    break;\n                }\n            }\n        }\n        if(isLeftAny){\n            System.out.println(\"NO\");\n        }else{\n            System.out.println(\"YES\");\n        }\n    }\n\n    private static boolean canPress(int x, int y, int r, int c, boolean[][] inp) {\n        for (int i = 0; i < 8; i++) {\n            int xi = x + dx[i];\n            int yi = y + dy[i];\n            if (xi < 0 || yi < 0) {\n                return false;\n            }\n            if (xi >= r || yi >= c) {\n                return false;\n            }\n            if(!inp[xi][yi]){\n                return false;\n            }\n        }\n        return true;\n    }\n}\n\n", "complexity": "quadratic", "problem": "1059_B. Forgery", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\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[] game=new int[n];\n        int[] bill=new int[m];\n        for (int i = 0; i <n ; i++) {\n            game[i]=scan.nextInt();\n        }\n        for (int i = 0; i <m ; i++) {\n            bill[i]=scan.nextInt();\n        }\n        int i=0;\n        int j=0;\n        int ans=0;\n        while (i<m){\n            boolean f=true;\n            for (int k = j; k <n ; k++) {\n                if (bill[i]>=game[k]){\n                    ans++;\n                    i++;\n                    j=k+1;\n                    f=false;\n                    break;\n                }\n            }\n            if (f){\n                break;\n            }\n        }\n        System.out.println(ans);\n    }\n}\n\n\n", "complexity": "linear", "problem": "1009_A. Game Shopping", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\npublic class Practice {\n\t\n\t   \n\n\t\tpublic static void main(String []args)\n\t\t{\n\t\t\tScanner sc=new Scanner(System.in);\n\t\t\tint n=sc.nextInt();\n\t\t\tsc.nextLine();\n\t\t\tString s=sc.nextLine();\n\t\t\t//System.out.println(s);\n\t\t\tchar c[]=s.toCharArray();\n\t\t\tArrayList a =new ArrayList();\n\t\t\t\n\t\t\tfor(int i=0;i<c.length;i++)\n\t\t\t{\n\t\t\t\t//System.out.println(c[i]);\n\t\t\t\ta.add(c[i]);\n\t\t\t}\n\t\t\n\t\t\tint x=Collections.frequency(a,'0' );\n\t\t\tint y=Collections.frequency(a,'1');\n\t\t\t\n\t\t\t//System.out.println(x+ \"  \"+y );\n\t\t\tif(y==0 || y==1)\n\t\t\t{\n\t\t\t\tSystem.out.println(s);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(y>=2)\n\t\t\t\t{\n\t\t\t\t\tString s1=\"1\";\n\t\t\t\t\tfor(int i=0;i<x;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\ts1=s1+\"0\";\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(s1);\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\n\t\t\t\n\t\t\t\n\t\t\t\n\t}\n\n}", "complexity": "linear", "problem": "976_A. Minimum Binary Number", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        FastReader in;\n        PrintWriter out;\n        int n;\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.nextInt();\n            if (n % 4 != 0) {\n                out.println(\"! -1\");\n                return;\n            }\n            int low = 0;\n            int high = n >> 1;\n            int fSign = Integer.signum(BValue(low));\n            if (fSign == 0) {\n                out.println(\"! \" + (low + 1));\n                return;\n            }\n            while (high - low > 1) {\n                int mid = (high + low) >> 1;\n                int mSign = Integer.signum(BValue(mid));\n                if (mSign == 0) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if (mSign == -fSign) {\n                    high = mid;\n                } else {\n                    low = mid;\n                }\n            }\n            out.println(\"! -1\");\n        }\n\n        public int BValue(int index) {\n            out.println(\"? \" + (index + 1));\n            out.flush();\n            int f = in.nextInt();\n            out.println(\"? \" + (index + 1 + (n >> 1)));\n            out.flush();\n            int s = in.nextInt();\n            return f - s;\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C{\n    static PrintWriter out;\n    static InputReader in;\n    public static void main(String args[]){\n        out = new PrintWriter(System.out);\n        in = new InputReader();\n        new C();\n        out.flush(); out.close();\n    }   \n    C(){\n       int a = solve();\n       out.print(a == 0 ? \"tokitsukaze\" : a == 1 ? \"quailty\" : \"once again\");\n    }\n    int n, k;\n    char ch[]; int a[], c0 = 0, c1 = 0;\n    TreeSet<Integer> ts[] = new TreeSet[2];\n    boolean check(){\n        int min = 0, max = n;\n        if(!ts[0].isEmpty()){\n            min = ts[0].first(); max = ts[0].last();\n            if(max - min + 1 > k)return true;\n        }\n        if(!ts[1].isEmpty()){\n            min = ts[1].first(); max = ts[1].last();\n            if(max - min + 1 > k)return true;   \n        }\n        return false;\n    }\n    int solve(){\n        n  = in.nextInt(); k = in.nextInt();\n        ch = in.next().trim().toCharArray(); a = new int[n];\n        for(int i = 0; i < n; i++)c1 += a[i] = ch[i] - '0';\n        c0 = n - c1;\n        for(int i = 0; i < k; i++){\n            if(a[i] == 0)c0--; else c1--;\n        }\n        if(c0 == 0 || c1 == 0)return 0;\n        for(int i = k; i < n; i++){\n            if(a[i] == 0)c0--; else c1--;\n            if(a[i - k] == 0)c0++; else c1++;\n            if(c0 == 0 || c1 == 0)return 0;\n        }\n\n        for(int i = 0; i < 2; i++)ts[i] = new TreeSet<>();\n        for(int i = 0; i < n; i++){\n            ts[a[i]].add(i);\n        }\n        for(int i = 0; i < k; i++){\n            ts[a[i]].remove(i);\n        }\n        if(check())return 2;\n        for(int i = k; i < n; i++){\n            ts[a[i]].remove(i); ts[a[i - k]].add(i - k);\n            if(check())return 2;\n        }\n        return 1;\n    }\n    public static class InputReader{\n        BufferedReader br;\n        StringTokenizer st;\n        InputReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\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        public String next(){\n            while(st == null || !st.hasMoreTokens()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch(IOException e){}\n            }\n            return st.nextToken();\n        }\n    }\n}\n        ", "complexity": "linear", "problem": "1190_C. Tokitsukaze and Duel", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.util.Map.Entry;\n\npublic class Codeforces {\n\n    static int n;\n    static double max;\n    static int[] pre;\n\n    public static void findIntensity(int l){\n        for(int i = 0, j = i + l; j < n + 1; i++, j++){\n            double res = (pre[j] - pre[i]) / (double) l;\n            max = Math.max(max, res);\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        n = Integer.parseInt(st.nextToken());\n        int k = Integer.parseInt(st.nextToken());\n        int[] heat = new int[n];\n        st = new StringTokenizer(br.readLine());\n        for(int i = 0; i < n; i++){\n            heat[i] = Integer.parseInt(st.nextToken());\n        }\n        max = 0;\n        pre = new int[n + 1];\n        pre[0] = 0;\n        for(int i = 0; i < n; i++){\n            pre[i + 1] = pre[i] + heat[i];\n        }\n        for(int i = k; i <= n; i++){\n            findIntensity(i);\n        }\n        System.out.println(max);\n    }\n}", "complexity": "quadratic", "problem": "1003_C. Intense Heat", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class code{\n    public static void main(String[] args) throws IOException{\n        Scanner sc = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int ok,ok2;\n        int va,vb;\n        va = 0;\n        vb = 0;\n        out.println(\"? \"+va+\" \"+vb);\n        out.flush();\n        ok = sc.nextInt();\n        for(int i=29;i>=0;i--){\n            if(ok==0){\n                va += (1<<i);\n                out.println(\"? \"+va+\" \"+vb);\n                out.flush();\n                ok2 = sc.nextInt();\n                if(ok2==1){\n                    va -= (1<<i);\n                }else{\n                    vb += (1<<i);\n                }\n            }else{\n                va += (1<<i);\n                vb += (1<<i);\n                out.println(\"? \"+va+\" \"+vb);\n                out.flush();\n                ok2 = sc.nextInt();\n                if(ok==ok2){\n                    vb -= (1<<i);\n                    out.println(\"? \"+va+\" \"+vb);\n                    out.flush();\n                    ok2 = sc.nextInt();\n                    if(ok2==1){\n                        va -= (1<<i);\n                    }else{\n                        vb += (1<<i);\n                    }\n                }else{\n                    if(ok==1){\n                        vb -= (1<<i);\n                        out.println(\"? \"+va+\" \"+vb);\n                        out.flush();\n                        ok = sc.nextInt();\n                    }\n                    else {\n                        va -= (1<<i);\n                        out.println(\"? \"+va+\" \"+vb);\n                        out.flush();\n                        ok = sc.nextInt();\n                    }\n                }\n            }\n        }\n        out.println(\"! \"+va+\" \"+vb);\n        out.flush();\n    }\n}", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    private static void solve(InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n\n        if (n < 6) {\n            out.println(-1);\n        } else {\n            int m = (n - 2);\n            for (int i = 2; i <= m; i++) {\n                out.println(\"1 \" + i);\n            }\n            out.println(m + \" \" + (m + 1));\n            out.println(m + \" \" + (m + 2));\n        }\n\n        for (int i = 2; i <= n; i++) {\n            out.println(\"1 \" + i);\n        }\n    }\n\n    private static void shuffleArray(int[] array) {\n        int index;\n        Random random = new Random();\n        for (int i = array.length - 1; i > 0; i--) {\n            index = random.nextInt(i + 1);\n            if (index != i) {\n                array[index] ^= array[i];\n                array[i] ^= array[index];\n                array[index] ^= array[i];\n            }\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    private static class InputReader {\n        private BufferedReader br;\n        private 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        byte nextByte() {\n            return Byte.parseByte(next());\n        }\n\n        short nextShort() {\n            return Short.parseShort(next());\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    private 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", "complexity": "linear", "problem": "959_C. Mahmoud and Ehab and the wrong algorithm", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class P1196D2 {\n\n    static boolean multipleIndependent = true;\n\n    void run() {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        char[] s = in.next().toCharArray();\n        int[] dp = new int[3];\n        char[] c = {'R', 'G', 'B'};\n        int min = Integer.MAX_VALUE;\n        for (int i = 0; i < k; i++) {\n            dp[0] += s[i] == c[(i + 0) % 3] ? 0 : 1;\n            dp[1] += s[i] == c[(i + 1) % 3] ? 0 : 1;\n            dp[2] += s[i] == c[(i + 2) % 3] ? 0 : 1;\n        }\n        min = Math.min(Math.min(Math.min(dp[0], dp[1]), dp[2]), min);\n//        System.out.println(Arrays.toString(dp));\n        for (int i = k; i < n; i++) {\n            dp[0] += (s[i] == c[(i + 0) % 3] ? 0 : 1) - (s[i - k] == c[(i - k + 0) % 3] ? 0 : 1);\n            dp[1] += (s[i] == c[(i + 1) % 3] ? 0 : 1) - (s[i - k] == c[(i - k + 1) % 3] ? 0 : 1);\n            dp[2] += (s[i] == c[(i + 2) % 3] ? 0 : 1) - (s[i - k] == c[(i - k + 2) % 3] ? 0 : 1);\n            min = Math.min(Math.min(Math.min(dp[0], dp[1]), dp[2]), min);\n//            System.out.println(Arrays.toString(dp));\n        }\n        System.out.println(min);\n    }\n\n\n    /* -----: Template :----- */\n    static InputReader in = new InputReader(System.in);\n\n    public static void main(String[] args) {\n        P1196D2 p = new P1196D2();\n        int q = multipleIndependent ? in.nextInt() : 1;\n        while (q-- > 0) {\n            p.run();\n        }\n    }\n\n    int numLength(long n) {\n        int l = 0;\n        while (n > 0) {\n            n /= 10;\n            l++;\n        }\n        return l;\n    }\n\n    <R> long binarySearch(long lowerBound, long upperBound,\n            R value, Function<Long, R> generatorFunction, Comparator<R> comparator) {\n        if (lowerBound <= upperBound) {\n            long mid = (lowerBound + upperBound) / 2;\n            int compare = comparator.compare(generatorFunction.apply(mid), value);\n            if (compare == 0) {\n                return mid;\n            } else if (compare < 0) {\n                return binarySearch(mid + 1, upperBound, value, generatorFunction, comparator);\n            } else {\n                return binarySearch(lowerBound, mid - 1, value, generatorFunction, comparator);\n            }\n        } else {\n            return -1;\n        }\n    }\n\n    <T> Integer[] sortSimultaneously(T[] key, Comparator<T> comparator,\n            Object[]... moreArrays) {\n        int n = key.length;\n        for (Object[] array : moreArrays) {\n            if (array.length != n) {\n                throw new RuntimeException(\"Arrays must have equals lengths\");\n            }\n        }\n        Integer[] indices = new Integer[n];\n        for (int i = 0; i < n; i++) {\n            indices[i] = i;\n        }\n        Comparator<Integer> delegatingComparator = (a, b) -> {\n            return comparator.compare(key[a], key[b]);\n        };\n        Arrays.sort(indices, delegatingComparator);\n        reorder(indices, key);\n        for (Object[] array : moreArrays) {\n            reorder(indices, array);\n        }\n        return indices;\n    }\n\n    void reorder(Integer[] indices, Object[] arr) {\n        if (indices.length != arr.length) {\n            throw new RuntimeException(\"Arrays must have equals lengths\");\n        }\n        int n = arr.length;\n        Object[] copy = new Object[n];\n        for (int i = 0; i < n; i++) {\n            copy[i] = arr[indices[i]];\n        }\n        System.arraycopy(copy, 0, arr, 0, n);\n    }\n\n    int prodMod(int a, int b, int mod) {\n        return (int) (((long) a) * b % mod);\n    }\n\n    long prodMod(long a, long b, long mod) {\n        long res = 0;\n        a %= mod;\n        b %= mod;\n        while (b > 0) {\n            if ((b & 1) > 0) {\n                res = (res + a) % mod;\n            }\n            a = (a << 1) % mod;\n            b >>= 1;\n        }\n        return res;\n    }\n\n    long sumMod(int[] b, long mod) {\n        long res = 0;\n        for (int i = 0; i < b.length; i++) {\n            res = (res + b[i] % mod) % mod;\n        }\n        return res;\n    }\n\n    long sumMod(long[] a, long mod) {\n        long res = 0;\n        for (int i = 0; i < a.length; i++) {\n            res = (res + a[i] % mod) % mod;\n        }\n        return res;\n    }\n\n    long sumProdMod(int[] a, long b, long mod) {\n        long res = sumMod(a, mod);\n        return prodMod(res, b, mod);\n    }\n\n    long sumProdMod(long[] a, long b, long mod) {\n        long res = sumMod(a, mod);\n        return prodMod(res, b, mod);\n    }\n\n    long sumProdMod(int[] a, int[] b, long mod) {\n        if (a.length != b.length) {\n            throw new RuntimeException(\"Arrays must have equals lengths\");\n        }\n        long res = 0;\n        for (int i = 0; i < a.length; i++) {\n            res = (res + prodMod(a[i], b[i], mod)) % mod;\n        }\n        return res;\n    }\n\n    long sumProdMod(long[] a, long[] b, long mod) {\n        if (a.length != b.length) {\n            throw new RuntimeException(\"Arrays must have equals lengths\");\n        }\n        long res = 0;\n        for (int i = 0; i < a.length; i++) {\n            res = (res + prodMod(a[i], b[i], mod)) % mod;\n        }\n        return res;\n    }\n\n    int[] toPrimitive(Integer[] arr) {\n        int[] res = new int[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    int[][] toPrimitive(Integer[][] arr) {\n        int[][] res = new int[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toPrimitive(arr[i]);\n        }\n        return res;\n    }\n\n    long[] toPrimitive(Long[] arr) {\n        long[] res = new long[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    long[][] toPrimitive(Long[][] arr) {\n        long[][] res = new long[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toPrimitive(arr[i]);\n        }\n        return res;\n    }\n\n    Integer[] toWrapper(int[] arr) {\n        Integer[] res = new Integer[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    Integer[][] toWrapper(int[][] arr) {\n        Integer[][] res = new Integer[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toWrapper(arr[i]);\n        }\n        return res;\n    }\n\n    Long[] toWrapper(long[] arr) {\n        Long[] res = new Long[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    Long[][] toWrapper(long[][] arr) {\n        Long[][] res = new Long[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toWrapper(arr[i]);\n        }\n        return res;\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        public int[] nextIntArray(int n) {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n            return arr;\n        }\n\n        public <T> T[] nextIntArray(int n, Function<Integer, T> function, Class<T> c) {\n            T[] arr = (T[]) Array.newInstance(c, n);\n            for (int i = 0; i < n; i++) {\n                arr[i] = function.apply(nextInt());\n            }\n            return arr;\n        }\n\n        public long[] nextLongArray(int n) {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n            return arr;\n        }\n\n        public <T> T[] nextLongArray(int n, Function<Long, T> function, Class<T> c) {\n            T[] arr = (T[]) Array.newInstance(c, n);\n            for (int i = 0; i < n; i++) {\n                arr[i] = function.apply(nextLong());\n            }\n            return arr;\n        }\n\n        public int[][] nextIntMap(int n, int m) {\n            int[][] map = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                map[i] = nextIntArray(m);\n            }\n            return map;\n        }\n\n        public long[][] nextLongMap(int n, int m) {\n            long[][] map = new long[n][m];\n            for (int i = 0; i < n; i++) {\n                map[i] = nextLongArray(m);\n            }\n            return map;\n        }\n\n        public char[][] nextCharMap(int n) {\n            char[][] map = new char[n][];\n            for (int i = 0; i < n; i++) {\n                map[i] = next().toCharArray();\n            }\n            return map;\n        }\n\n        public void readColumns(Object[]... columns) {\n            int n = columns[0].length;\n            for (Object[] column : columns) {\n                if (column.length != n) {\n                    throw new RuntimeException(\"Arrays must have equals lengths\");\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                for (Object[] column : columns) {\n                    column[i] = read(column[i].getClass());\n                }\n            }\n        }\n\n        public <T> T read(Class<T> c) {\n            throw new UnsupportedOperationException(\"To be implemented\");\n        }\n\n    }\n\n}\n", "complexity": "quadratic", "problem": "1196_D2. RGB Substring (hard version)", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\n// _ h _ r _ t r _\n// _ t _ t _ s t _\n\n\n\n\npublic class TaskA implements Runnable {\n    long m = (int)1e9+7;\n    PrintWriter w;\n    InputReader c;\n    final int MAXN = (int)1e6 + 100;\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n\n        int n = c.nextInt(), hamming_distance = 0;\n        char[] s = c.next().toCharArray(), t = c.next().toCharArray();\n        HashMap<Character, HashSet<Character>> replace = new HashMap<>();\n        HashMap<Character, Integer> map = new HashMap<>();\n\n        for(int i=0;i<n;++i) if(s[i] != t[i]) {\n            HashSet<Character> temp;\n            if(replace.containsKey(s[i])){\n                temp = replace.get(s[i]);\n                temp.add(t[i]);\n            } else {\n                temp = new HashSet<>();\n                temp.add(t[i]);\n            }\n            map.put(s[i],i);\n            replace.put(s[i], temp);\n            hamming_distance++;\n        }\n\n        int l = -1, r = -1;\n        boolean global_check = false;\n        for(int i=0;i<n;i++) if(s[i] != t[i]) {\n            if(replace.containsKey(t[i])) {\n                HashSet<Character> indices = replace.get(t[i]);\n                int ind = map.get(t[i]);\n                l = i + 1;\n                r = ind + 1;\n                if (indices.contains(s[i])) {\n                    hamming_distance -= 2;\n                    global_check = true;\n                    break;\n                }\n            }\n            if(global_check) break;\n        }\n\n        if(!global_check && l!=-1) hamming_distance--;\n        else if(global_check){\n            for(int i=0;i<n;i++) {\n                if(t[i] == s[l-1] && s[i] == t[l-1]){\n                    r = i + 1;\n                    break;\n                }\n            }\n        }\n        w.println(hamming_distance);\n        w.println(l+\" \"+r);\n\n        w.close();\n    }\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static void sortbyColumn(int arr[][], int col){\n        Arrays.sort(arr, new Comparator<int[]>()\n        {\n            public int compare(int[] o1, int[] o2){\n                return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    public static class DJSet {\n        public int[] upper;\n\n        public DJSet(int n) {\n            upper = new int[n];\n            Arrays.fill(upper, -1);\n        }\n\n        public int root(int x) {\n            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n        }\n\n        public boolean equiv(int x, int y) {\n            return root(x) == root(y);\n        }\n\n        public boolean union(int x, int y) {\n            x = root(x);\n            y = root(y);\n            if (x != y) {\n                if (upper[y] < upper[x]) {\n                    int d = x;\n                    x = y;\n                    y = d;\n                }\n                upper[x] += upper[y];\n                upper[y] = x;\n            }\n            return x == y;\n        }\n    }\n    public static int[] radixSort(int[] f)    {\n        int[] to = new int[f.length];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n    public void printArray(int[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n){\n        int a[] = new int[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n){\n        long a[] = new long[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars==-1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                }\n                catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        public int nextInt() {\n            int c = read();\n\n            while(isSpaceChar(c))\n                c = read();\n\n            int sgn = 1;\n\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n\n            int res = 0;\n            do {\n                if(c<'0'||c>'9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskA(),\"TaskA\",1<<26).start();\n    }\n}", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1009E {\n\tstatic final int MD = 998244353;\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[] aa = new int[1 + n];\n\t\tfor (int i = 1, a = 0; i <= n; i++)\n\t\t\taa[i] = a = (a + Integer.parseInt(st.nextToken())) % MD;\n\t\tint[] pp = new int[n];\n\t\tpp[0] = 1;\n\t\tfor (int i = 1, p = 1; i < n; i++) {\n\t\t\tpp[i] = p;\n\t\t\tp = p * 2 % MD;\n\t\t}\n\t\tint d = 0;\n\t\tlong ans = 0;\n\t\tfor (int i = n - 1; i >= 0; i--) {\t// rest at i\n\t\t\td = (d * 2 % MD + aa[n - 1 - i]) % MD;\t// rest again before n\n\t\t\tans = (ans + (long) (d + aa[n - i]) * pp[i]) % MD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "linear", "problem": "1009_E. Intercity Travelling", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author aryssoncf\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        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            try {\n                int n = in.readInt();\n                int[] x = new int[n], w = new int[n];\n                in.readIntArrays(x, w);\n                int[] begin = new int[n], end = new int[n];\n                Arrays.setAll(begin, i -> x[i] - w[i]);\n                Arrays.setAll(end, i -> x[i] + w[i]);\n                int m = ArrayUtils.compress(begin, end).length;\n                int[] dp = new int[m + 1], order = ArrayUtils.order(end);\n                int idx = 0;\n                for (int i = 0; i < m; i++) {\n                    if (i > 0) {\n                        dp[i] = dp[i - 1];\n                    }\n                    while (idx < n && end[order[idx]] == i) {\n                        dp[i] = Math.max(dp[i], dp[begin[order[idx]]] + 1);\n                        idx++;\n                    }\n                }\n                int res = dp[m - 1];\n                out.printLine(res);\n            } catch (Exception e) {\n                e.printStackTrace();\n            }\n        }\n\n    }\n\n    static class Sorter {\n        private static final int INSERTION_THRESHOLD = 16;\n\n        private Sorter() {\n        }\n\n        public static void sort(IntList list, IntComparator comparator) {\n            quickSort(list, 0, list.size() - 1, (Integer.bitCount(Integer.highestOneBit(list.size()) - 1) * 5) >> 1,\n                    comparator);\n        }\n\n        private static void quickSort(IntList list, int from, int to, int remaining, IntComparator comparator) {\n            if (to - from < INSERTION_THRESHOLD) {\n                insertionSort(list, from, to, comparator);\n                return;\n            }\n            if (remaining == 0) {\n                heapSort(list, from, to, comparator);\n                return;\n            }\n            remaining--;\n            int pivotIndex = (from + to) >> 1;\n            int pivot = list.get(pivotIndex);\n            list.swap(pivotIndex, to);\n            int storeIndex = from;\n            int equalIndex = to;\n            for (int i = from; i < equalIndex; i++) {\n                int value = comparator.compare(list.get(i), pivot);\n                if (value < 0) {\n                    list.swap(storeIndex++, i);\n                } else if (value == 0) {\n                    list.swap(--equalIndex, i--);\n                }\n            }\n            quickSort(list, from, storeIndex - 1, remaining, comparator);\n            for (int i = equalIndex; i <= to; i++) {\n                list.swap(storeIndex++, i);\n            }\n            quickSort(list, storeIndex, to, remaining, comparator);\n        }\n\n        private static void heapSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = (to + from - 1) >> 1; i >= from; i--) {\n                siftDown(list, i, to, comparator, from);\n            }\n            for (int i = to; i > from; i--) {\n                list.swap(from, i);\n                siftDown(list, from, i - 1, comparator, from);\n            }\n        }\n\n        private static void siftDown(IntList list, int start, int end, IntComparator comparator, int delta) {\n            int value = list.get(start);\n            while (true) {\n                int child = ((start - delta) << 1) + 1 + delta;\n                if (child > end) {\n                    return;\n                }\n                int childValue = list.get(child);\n                if (child + 1 <= end) {\n                    int otherValue = list.get(child + 1);\n                    if (comparator.compare(otherValue, childValue) > 0) {\n                        child++;\n                        childValue = otherValue;\n                    }\n                }\n                if (comparator.compare(value, childValue) >= 0) {\n                    return;\n                }\n                list.swap(start, child);\n                start = child;\n            }\n        }\n\n        private static void insertionSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = from + 1; i <= to; i++) {\n                int value = list.get(i);\n                for (int j = i - 1; j >= from; j--) {\n                    if (comparator.compare(list.get(j), value) <= 0) {\n                        break;\n                    }\n                    list.swap(j, j + 1);\n                }\n            }\n        }\n\n    }\n\n    static interface IntList extends IntReversableCollection {\n        public abstract int get(int index);\n\n        public abstract void set(int index, int value);\n\n        public abstract void addAt(int index, int value);\n\n        public abstract void removeAt(int index);\n\n        default public void swap(int first, int second) {\n            if (first == second) {\n                return;\n            }\n            int temp = get(first);\n            set(first, get(second));\n            set(second, temp);\n        }\n\n        default public IntIterator intIterator() {\n            return new IntIterator() {\n                private int at;\n                private boolean removed;\n\n                public int value() {\n                    if (removed) {\n                        throw new IllegalStateException();\n                    }\n                    return get(at);\n                }\n\n                public boolean advance() {\n                    at++;\n                    removed = false;\n                    return isValid();\n                }\n\n                public boolean isValid() {\n                    return !removed && at < size();\n                }\n\n                public void remove() {\n                    removeAt(at);\n                    at--;\n                    removed = true;\n                }\n            };\n        }\n\n        default public void add(int value) {\n            addAt(size(), value);\n        }\n\n        default public IntList sort(IntComparator comparator) {\n            Sorter.sort(this, comparator);\n            return this;\n        }\n\n        default IntList unique() {\n            int last = Integer.MIN_VALUE;\n            IntList result = new IntArrayList();\n            int size = size();\n            for (int i = 0; i < size; i++) {\n                int current = get(i);\n                if (current != last) {\n                    result.add(current);\n                    last = current;\n                }\n            }\n            return result;\n        }\n\n        default public IntList subList(final int from, final int to) {\n            return new IntList() {\n                private final int shift;\n                private final int size;\n\n                {\n                    if (from < 0 || from > to || to > IntList.this.size()) {\n                        throw new IndexOutOfBoundsException(\"from = \" + from + \", to = \" + to + \", size = \" + size());\n                    }\n                    shift = from;\n                    size = to - from;\n                }\n\n                public int size() {\n                    return size;\n                }\n\n                public int get(int at) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    return IntList.this.get(at + shift);\n                }\n\n                public void addAt(int index, int value) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void removeAt(int index) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void set(int at, int value) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    IntList.this.set(at + shift, value);\n                }\n\n                public IntList compute() {\n                    return new IntArrayList(this);\n                }\n            };\n        }\n\n    }\n\n    static interface IntComparator {\n        IntComparator DEFAULT = Integer::compare;\n\n        int compare(int first, int second);\n\n    }\n\n    static class Range {\n        public static IntList range(int from, int to) {\n            int[] result = new int[Math.abs(from - to)];\n            int current = from;\n            if (from <= to) {\n                for (int i = 0; i < result.length; i++) {\n                    result[i] = current++;\n                }\n            } else {\n                for (int i = 0; i < result.length; i++) {\n                    result[i] = current--;\n                }\n            }\n            return new IntArray(result);\n        }\n\n    }\n\n    static interface IntReversableCollection extends IntCollection {\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 interface IntStream extends Iterable<Integer>, Comparable<IntStream> {\n        IntIterator intIterator();\n\n        default Iterator<Integer> iterator() {\n            return new Iterator<Integer>() {\n                private IntIterator it = intIterator();\n\n                public boolean hasNext() {\n                    return it.isValid();\n                }\n\n                public Integer next() {\n                    int result = it.value();\n                    it.advance();\n                    return result;\n                }\n            };\n        }\n\n        default int compareTo(IntStream c) {\n            IntIterator it = intIterator();\n            IntIterator jt = c.intIterator();\n            while (it.isValid() && jt.isValid()) {\n                int i = it.value();\n                int j = jt.value();\n                if (i < j) {\n                    return -1;\n                } else if (i > j) {\n                    return 1;\n                }\n                it.advance();\n                jt.advance();\n            }\n            if (it.isValid()) {\n                return 1;\n            }\n            if (jt.isValid()) {\n                return -1;\n            }\n            return 0;\n        }\n\n    }\n\n    static 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 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 int[] toArray() {\n            int size = size();\n            int[] array = new int[size];\n            int i = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                array[i++] = it.value();\n            }\n            return array;\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 IntArray extends IntAbstractStream implements IntList {\n        private int[] data;\n\n        public IntArray(int[] arr) {\n            data = arr;\n        }\n\n        public int size() {\n            return data.length;\n        }\n\n        public int get(int at) {\n            return data[at];\n        }\n\n        public void addAt(int index, int value) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void removeAt(int index) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void set(int index, int value) {\n            data[index] = value;\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static int[] range(int from, int to) {\n            return Range.range(from, to).toArray();\n        }\n\n        public static int[] createOrder(int size) {\n            return range(0, size);\n        }\n\n        public static int[] sort(int[] array, IntComparator comparator) {\n            return sort(array, 0, array.length, comparator);\n        }\n\n        public static int[] sort(int[] array, int from, int to, IntComparator comparator) {\n            if (from == 0 && to == array.length) {\n                new IntArray(array).sort(comparator);\n            } else {\n                new IntArray(array).subList(from, to).sort(comparator);\n            }\n            return array;\n        }\n\n        public static int[] order(final int[] array) {\n            return sort(createOrder(array.length), (first, second) -> Integer.compare(array[first], array[second]));\n        }\n\n        public static int[] unique(int[] array) {\n            return new IntArray(array).unique().toArray();\n        }\n\n        public static int[] compress(int[]... arrays) {\n            int totalLength = 0;\n            for (int[] array : arrays) {\n                totalLength += array.length;\n            }\n            int[] all = new int[totalLength];\n            int delta = 0;\n            for (int[] array : arrays) {\n                System.arraycopy(array, 0, all, delta, array.length);\n                delta += array.length;\n            }\n            sort(all, IntComparator.DEFAULT);\n            all = unique(all);\n            for (int[] array : arrays) {\n                for (int i = 0; i < array.length; i++) {\n                    array[i] = Arrays.binarySearch(all, array[i]);\n                }\n            }\n            return all;\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 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        public void set(int index, int value) {\n            if (index >= size) {\n                throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n            }\n            data[index] = value;\n        }\n\n        public int[] toArray() {\n            return Arrays.copyOf(data, size);\n        }\n\n    }\n\n    static abstract class IntAbstractStream implements IntStream {\n        public String toString() {\n            StringBuilder builder = new StringBuilder();\n            boolean first = true;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                if (first) {\n                    first = false;\n                } else {\n                    builder.append(' ');\n                }\n                builder.append(it.value());\n            }\n            return builder.toString();\n        }\n\n        public boolean equals(Object o) {\n            if (!(o instanceof IntStream)) {\n                return false;\n            }\n            IntStream c = (IntStream) o;\n            IntIterator it = intIterator();\n            IntIterator jt = c.intIterator();\n            while (it.isValid() && jt.isValid()) {\n                if (it.value() != jt.value()) {\n                    return false;\n                }\n                it.advance();\n                jt.advance();\n            }\n            return !it.isValid() && !jt.isValid();\n        }\n\n        public int hashCode() {\n            int result = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                result *= 31;\n                result += it.value();\n            }\n            return result;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "528_B. Clique Problem", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.stream.Collectors;\n\npublic class PlayingPiano {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\t int n = scanner.nextInt();\n\t\t \n\t\t List<Integer> as = new LinkedList<>();\n\t\t int[] as2 = new int[n];\n\t\t \n\t\t for (int i = 0; i < n; i++) {\n\t\t\t int a = scanner.nextInt();\n\t\t\t as.add(a);\n\t\t\t as2[i] = a;\n\t\t }\n\t\t \n\t\t //System.out.println(solve(as));\n\t\t System.out.println(solve2(as2));\n\t\t\n\t\tscanner.close();\n\t}\n\n\tpublic static String solve(List<Integer> as) {\n\t\tList<Integer> fingers = new LinkedList<>();\n\t\t fingers.add(1);\n\t\t fingers.add(2);\n\t\t fingers.add(3);\n\t\t fingers.add(4);\n\t\t fingers.add(5);\n\t\t \n\t\t List<Integer> solution = assign(as, fingers, fingers);\n\t\t if (solution == null) {\n\t\t\t return \"-1\";\n\t\t } else {\n\t\t\t StringBuilder sb = new StringBuilder();\n\t\t\t for (int b : solution) {\n\t\t\t\t sb.append(b);\n\t\t\t\t sb.append(\" \");\n\t\t\t }\n\t\t\t sb.deleteCharAt(sb.length() - 1);\n\t\t\t return sb.toString();\n\t\t }\n\t}\n\n\tprivate static List<Integer> assign(List<Integer> as, List<Integer> fingers, List<Integer> allFingers) {\n\t\t// if fingers is empty return null\n\t\tif (fingers.isEmpty()) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t// if as size is one then return first element in fingers\n\t\tif (as.size() == 1) {\n\t\t\tList<Integer> ret = new LinkedList<>();\n\t\t\tret.add(fingers.get(0));\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\t// get sublist\n\t\tList<Integer> subList = as.subList(1, as.size());\n\t\t\n\t\tfor (int i = 0; i < fingers.size(); i++) {\n\t\t\t// recursively call with sublist and limited list of fingers\n\t\t\tList<Integer> subFingers = new LinkedList<>();\n\t\t\tfinal int j = i;\n\t\t\tif (as.get(0) < as.get(1)) {\n\t\t\t\t subFingers = allFingers.stream()\n\t\t\t\t\t    .filter(p -> p > fingers.get(j)).collect(Collectors.toList());\n\t\t\t} else if (as.get(0) > as.get(1)) {\n\t\t\t\tsubFingers = allFingers.stream()\n\t\t\t\t\t    .filter(p -> p < fingers.get(j)).collect(Collectors.toList());\n\t\t\t} else {\n\t\t\t\tsubFingers = allFingers.stream()\n\t\t\t\t\t    .filter(p -> p != fingers.get(j)).collect(Collectors.toList());\n\t\t\t}\n\t\t\t\n\t\t\tList<Integer> ret = assign(subList, subFingers, allFingers);\n\t\t\tif (ret != null) {\n\t\t\t\tList<Integer> solution = new LinkedList<>();\n\t\t\t\tsolution.add(fingers.get(i));\n\t\t\t\tsolution.addAll(ret);\n\t\t\t\treturn solution;\n\t\t\t}\n\t\t\t\n\t\t\t// if return is null, then return null, else return an array\n\t\t}\n\t\treturn null;\n\t\t\n\t}\n\t\n\tpublic static String solve2(int[] as) {\n\t\tint[] ret = new int[as.length];\n\t\t\n\t\tif (as.length == 1) return \"1\";\n\t\t\n\t\tif (as[0] < as[1]) ret[0] = 1;\n\t\telse if (as[0] == as[1])\tret[0] = 3;\n\t\telse ret[0] = 5;\n\t\t\n\t\tfor (int i = 1; i < as.length - 1; i++) {\n\t\t\tif (as[i-1] < as[i] && ret[i-1] == 5) return \"-1\";\n\t\t\tif (as[i-1] > as[i] && ret[i-1] == 1) return \"-1\";\n\t\t\t\n\t\t\tif (as[i-1] < as[i] && as[i] < as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] + 1;\n\t\t\t} else if (as[i-1] == as[i] && as[i] < as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 1 ? 2 : 1;\n\t\t\t} else if (as[i-1] > as[i] && as[i] < as[i+1]) {\n\t\t\t\tret[i] = 1;\n\t\t\t} else if (as[i-1] < as[i] && as[i] == as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] + 1;\n\t\t\t} else if (as[i-1] == as[i] && as[i] == as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 4 ? 2 : 4;\n\t\t\t} else if (as[i-1] > as[i] && as[i] == as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 2 ? 1 : 2;\n\t\t\t} else if (as[i-1] < as[i] && as[i] > as[i+1]) {\n\t\t\t\tret[i] = 5;\n\t\t\t} else if (as[i-1] == as[i] && as[i] > as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 5 ? 4 : 5;\n\t\t\t} else if (as[i-1] > as[i] && as[i] > as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] - 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (as.length > 1) {\n\t\t\tif (as[as.length - 1] > as[as.length - 2]) {\n\t\t\t\tif (ret[as.length - 2] == 5)\n\t\t\t\t\treturn \"-1\";\n\t\t\t\tret[as.length - 1] = 5;\n\t\t\t} else if (as[as.length - 1] == as[as.length - 2]) {\n\t\t\t\tret[as.length - 1] = ret[as.length - 2] == 5 ? 4 : 5;\n\t\t\t} else {\n\t\t\t\tif (ret[as.length - 2] == 1)\n\t\t\t\t\treturn \"-1\";\n\t\t\t\tret[as.length - 1] = 1;\n\t\t\t} \n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\t for (int b : ret) {\n\t\t\t sb.append(b);\n\t\t\t sb.append(\" \");\n\t\t }\n\t\t sb.deleteCharAt(sb.length() - 1);\n\t\t return sb.toString();\n\t}\n\n}\n", "complexity": "linear", "problem": "1032_C. Playing Piano", "from": "CODEFORCES"}
{"src": "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        E solver = new E();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class E {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.ni(), K = in.ni();\n            long mod = 998244353;\n            long[][] dp = new long[n + 1][n + 1];\n            for (int lim = 1; lim <= n; lim++) {\n                long sum = 1;\n                dp[0][lim] = 1;\n                for (int i = 1; i <= n; i++) {\n                    dp[i][lim] = (dp[i][lim] + sum) % mod;\n                    sum = (sum + dp[i][lim]) % mod;\n                    if (i >= lim)\n                        sum = (sum - dp[i - lim][lim] + mod) % mod;\n                }\n            }\n            long ans = 0;\n            for (int k = 1; k < Math.min(K, n + 1); k++) {\n                long h = dp[n][k] - dp[n][k - 1];\n                int lim = K / k;\n                if (K % k == 0)\n                    lim--;\n                if (lim > n)\n                    lim = n;\n                ans += dp[n][lim] * h % mod;\n            }\n            out.println(2 * ans % mod);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream stream) {\n            in = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String ns() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(ns());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1027_E. Inverse Coloring", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A961_Tetris {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\t\tint platforms = input.nextInt();\n\t\tint in = input.nextInt();\n\t\tint[] cols = new int[platforms];\n\t\tint[] squares = new int[in];\n\t\t\n\t\tfor (int i = 0; i < in; i ++) {\n\t\t\tsquares[i] = input.nextInt();\n\t\t}\n\t\t\n\t\tboolean hi = false;\n\t\tint score = 0;\n\t\t\n\t\tfor (int i = 0; i < in; i ++) {\n\t\t\tcols[squares[i] - 1] ++;\n\t\t\thi = checkscore(cols);\n\t\t\tif (hi == true) {\n\t\t\t\thi = false;\n\t\t\t\tscore ++;\n\t\t\t\tfor (int j = 0; j < cols.length; j ++) {\n\t\t\t\t\tcols[j] --;\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\tSystem.out.println(score);\n\t\t\n\t}\n\t\n\tpublic static boolean checkscore(int[] cols) {\n\t\tfor (int i = 0; i < cols.length; i ++) {\n\t\t\tif (cols[i] == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn true;\n\t\t\n\t}\n\n}\n", "complexity": "quadratic", "problem": "961_A. Tetris", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n\n    private FastScanner scanner = new FastScanner();\n\n    public static void main(String[] args) {\n        new Main().solve();\n    }\n\n\n    private void solve() {\n        int n = scanner.nextInt();\n\n        Map<Integer, Integer> cnt = new HashMap<>();\n\n        for (int i = 0; i < n; i++) {\n            String s = scanner.nextLine();\n\n            LinkedList<Character> st = new LinkedList<>();\n\n            for (char c : s.toCharArray()) {\n                if (c == ')' && !st.isEmpty() && st.getLast() == '(') {\n                    st.pollLast();\n                    continue;\n                }\n                st.addLast(c);\n            }\n\n            int t = st.size();\n            Set<Character> set = new HashSet<>(st);\n            if (set.size() > 1) {\n                continue;\n            }\n            if (set.isEmpty()) {\n                cnt.put(0, cnt.getOrDefault(0, 0) + 1);\n                continue;\n            }\n\n            if (st.getLast() == '(') {\n                cnt.put(t, cnt.getOrDefault(t, 0) + 1);\n            } else {\n                cnt.put(-t, cnt.getOrDefault(-t, 0) + 1);\n            }\n        }\n\n        long ans = 0;\n\n        for (int next : cnt.keySet()) {\n            if (next == 0) {\n                ans += (long) cnt.get(next) * (cnt.get(next) - 1) + cnt.get(next);\n            } else if (next > 0) {\n                int t = next * -1;\n                if (cnt.containsKey(t)) {\n                    ans += (long) cnt.get(next) * cnt.get(t);\n                }\n            }\n        }\n\n        System.out.print(ans);\n\n    }\n\n    class FastScanner {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n            tokenizer = null;\n        }\n\n        String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Integer[] nextA(int n) {\n            Integer a[] = new Integer[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = scanner.nextInt();\n            }\n            return a;\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            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "990_C. Bracket Sequences Concatenation Problem", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class loser\n{\n    static class InputReader {\n        public BufferedReader br;\n        public StringTokenizer token;\n        public InputReader(InputStream stream)\n        {\n            br=new BufferedReader(new InputStreamReader(stream),32768);\n            token=null;\n        }\n\n        public String next()\n        {\n            while(token==null || !token.hasMoreTokens())\n            {\n                try\n                {\n                    token=new StringTokenizer(br.readLine());\n                }\n                catch(IOException e)\n                {\n                    throw new RuntimeException(e);\n                }\n            }\n            return token.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    static class card{\n        long a;\n        int i;\n        public card(long a,int i)\n        {\n            this.a=a;\n            this.i=i;\n        }\n    }\n    static class sort implements Comparator<pair>\n    {\n        public int compare(pair o1,pair o2)\n        {\n            if(o1.a!=o2.a)\n                return (int)(o1.a-o2.a);\n            else\n                return (int)(o1.b-o2.b);\n        }\n    }\n    static void shuffle(long a[])\n    {\n        List<Long> l=new ArrayList<>();\n        for(int i=0;i<a.length;i++)\n            l.add(a[i]);\n        Collections.shuffle(l);\n        for(int i=0;i<a.length;i++)\n            a[i]=l.get(i);\n    }\n\n    /*static long gcd(long a,long b)\n    {\n    if(b==0)\n    return a;\n    else\n    return gcd(b,a%b);\n    }*/\n    /*static boolean valid(int i,int j)\n    {\n    if(i<4 && i>=0 && j<4 && j>=0)\n    return true;\n    else\n    return false;\n    }*/\n    static class pair{\n        int a,b;\n        public pair(int a,int b)\n        {\n            this.a=a;\n            this.b=b;\n        }\n    }\n    public  static void main(String[] args) \n    {\n        InputReader sc=new InputReader(System.in);\n        int k=sc.nextInt();\n        int n=sc.nextInt();\n        int s=sc.nextInt();\n        int p=sc.nextInt();\n        long d=(long)Math.ceil((double)n/s);\n        if(d==0)\n        d=1;\n        d=k*d;\n        long ans=(long)Math.ceil((double)d/p);\n        System.out.println(ans);\n    }\n}", "complexity": "constant", "problem": "965_A. Paper Airplanes", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\npublic class D999 {\n    public static void main(String args[])throws IOException\n    {\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        int m=sc.nextInt();\n        int req=n/m;\n        int arr[]=new int[n+1];\n        int size[]=new int[m];\n        List<Integer> list[]=new ArrayList[m];\n        for(int i=0;i<m;i++)\n        {\n            list[i]=new ArrayList<>();\n        }\n        for(int i=1;i<=n;i++)\n        {\n            arr[i]=sc.nextInt();\n            size[arr[i]%m]++;\n            list[arr[i]%m].add(i);\n        }\n        long tot=0;int x=0,y=0;\n        List<Integer> idx=new ArrayList<>();\n        for(int i=0;i < 2*m;i++)\n        {\n            //System.out.println(i+\" \"+size[i%m]);\n            if(size[i%m]>req)\n            {\n                for(int j=0;j<size[i%m]-req;j++)\n                {\n                    idx.add(list[i%m].get(j));\n                    y++;\n                    \n                }\n                size[i%m]=req;\n                //System.out.println(i+\" \"+x+\" \"+y);\n            }\n            else if(size[i%m]<req)\n            {\n                //System.out.println(idx+\" \"+i);\n                while(x!=y && size[i%m]<req)\n                {\n                    int num=arr[idx.get(x)];\n                    int gg=i-num%m;\n                    tot+=gg;\n                    arr[idx.get(x)]+=gg;\n                    x++;\n                    size[i%m]++;\n                }\n            }\n        }\n        System.out.println(tot);\n        for(int i=1;i<=n;i++)\n        {\n            System.out.print(arr[i]+\" \");\n        }\n    }\n}", "complexity": "linear", "problem": "999_D. Equalize the Remainders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CoveredPointsCount {\n\t\n\t//UPSOLVE\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        \n\t\tint n = Integer.parseInt(st.nextToken());\n\t     \n\t\tlong[] myArray = new long[2 * n];\n\t        \n\t\t\tfor (int i = 0; i < n; i++)  {\n\t        \tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t        \tmyArray[2 * i] = Long.parseLong(st1.nextToken()) * 2;\n\t        \tmyArray[2 * i + 1] = Long.parseLong(st1.nextToken()) * 2 + 1;\n\t        }  \n\t        \n\t        Arrays.sort(myArray);\n\t        long[] ans = new long[n + 1];\n\t        int cnt = 0;\n\t       \n\t        for (int i = 0; i < 2 * n - 1; i++)   {\n\t            if (myArray[i] % 2 == 0) cnt++; else cnt--;\n\t            ans[cnt] += (myArray[i + 1] + 1) / 2 - (myArray[i] + 1) / 2;\n\t        }   \n\t        \n\t        StringBuilder answer = new StringBuilder();\n\t        \n\t        for (int i = 1; i < n + 1; i++) {\n\t        \tanswer.append(ans[i]);\n\t        \tanswer.append(\" \");\n\t        }  \n\t        \n\t        System.out.println(answer);\n\n\t}\n\n}\n", "complexity": "nlogn", "problem": "1000_C. Covered Points Count", "from": "CODEFORCES"}
{"src": "import java.util.*;\n \nimport javax.lang.model.util.ElementScanner6;\n \nimport java.io.*;\n \npublic class Main {\n \n    public static void main(String[] args) {\n \n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader inp = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Solver solver = new Solver();\n        solver.solve(inp, out);\n        out.close();\n \n    }\n \n \n \n \n \n    static class Solver {\n\n        class pair implements Comparable<pair>{\n\n            int i;\n            long dist;\n            public pair(int i,long dist)\n            {\n                this.i=i;\n                this.dist=dist;\n            }\n\n            public int compareTo(pair p)\n            {\n                return Long.compare(this.dist,p.dist);\n            }\n\n        }\n \n        class Node implements Comparable < Node > {\n            int i;\n            int cnt;\n \n            Node(int i, int cnt) {\n                this.i = i;\n                this.cnt = cnt;\n            }\n \n            public int compareTo(Node n) {\n                if (this.cnt == n.cnt) {\n                    return Integer.compare(this.i, n.i);\n                }\n                return Integer.compare(this.cnt, n.cnt);\n            }\n        }\n \n        public boolean done(int[] sp, int[] par) {\n            int root;\n \n            root = findSet(sp[0], par);\n \n            for (int i = 1; i < sp.length; i++) {\n                if (root != findSet(sp[i], par))\n                    return false;\n            }\n            return true;\n        }\n        public int findSet(int i, int[] par) {\n            int x = i;\n            boolean flag = false;\n            while (par[i] >= 0) {\n                flag = true;\n                i = par[i];\n            }\n            if (flag)\n                par[x] = i;\n            return i;\n        }\n \n        public void unionSet(int i, int j, int[] par) {\n            int x = findSet(i, par);\n            int y = findSet(j, par);\n            if (x < y) {\n                par[y] = x;\n            } else {\n                par[x] = y;\n            }\n        }\n \n        public 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        public boolean isPrime(int n)\n        {\n            for(int i=2;i<n;i++)\n            {\n                if(n%i==0)\n                {\n                    return false;\n                }\n            }\n            return true;\n        }\n \n \n        public void minPrimeFactor(int n, int[] s) {\n            boolean prime[] = new boolean[n + 1];\n            Arrays.fill(prime, true);\n            s[1] = 1;\n            s[2] = 2;\n            for (int i = 4; i <= n; i += 2) {\n                prime[i] = false;\n                s[i] = 2;\n            }\n \n            for (int i = 3; i <= n; i += 2) {\n                if (prime[i]) {\n                    s[i] = i;\n                    for (int j = 2 * i; j <= n; j += i) {\n                        prime[j] = false;\n                        s[j] = i;\n                    }\n                }\n            }\n \n        }\n \n \n        public void findAllPrime(int n, ArrayList < Node > al, int s[]) {\n            int curr = s[n];\n            int cnt = 1;\n            while (n > 1) {\n                n /= s[n];\n                if (curr == s[n]) {\n                    cnt++;\n                    continue;\n \n                }\n                Node n1 = new Node(curr, cnt);\n                al.add(n1);\n \n                curr = s[n];\n                cnt = 1;\n            }\n        }\n \n \n \n        public int binarySearch(int n, int k) {\n            int left = 1;\n            int right = 100000000 + 5;\n            int ans = 0;\n            while (left <= right) {\n                int mid = (left + right) / 2;\n                if (n / mid >= k) {\n                    left = mid + 1;\n                    ans = mid;\n                } else {\n                    right = mid - 1;\n                }\n            }\n \n            return ans;\n        }\n        public boolean checkPallindrom(String s) {\n            char ch[] = s.toCharArray();\n \n            for (int i = 0; i < s.length() / 2; i++) {\n                if (ch[i] != ch[s.length() - 1 - i])\n                    return false;\n            }\n            return true;\n        }\n \n \n \n \n        public void remove(ArrayList < Integer > [] al, int x) {\n            for (int i = 0; i < al.length; i++) {\n                for (int j = 0; j < al[i].size(); j++) {\n \n                    if (al[i].get(j) == x)\n                        al[i].remove(j);\n \n                }\n            }\n        }\n \n        public long gcd(long a, long b) {\n            if (a == 0)\n                return b;\n            return gcd(b % a, a);\n        }\n \n \n        public void printDivisors(long n, ArrayList < Long > al) {\n            // Note that this loop runs till square root \n            for (long i = 1; i <= Math.sqrt(n); i++) {\n                if (n % i == 0) {\n                    // If divisors are equal, print only one \n                    if (n / i == i) {\n                        al.add(i);\n                    } else // Otherwise print both \n                    {\n                        al.add(i);\n                        al.add(n / i);\n                    }\n \n                }\n            }\n        }\n \n        public static long constructSegment(long seg[], long arr[], int low, int high, int pos) {\n            if (low == high) {\n                seg[pos] = arr[low];\n                return seg[pos];\n            }\n            int mid = (low + high) / 2;\n            long t1 = constructSegment(seg, arr, low, mid, (2 * pos) + 1);\n            long t2 = constructSegment(seg, arr, mid + 1, high, (2 * pos) + 2);\n            seg[pos] = t1 + t2;\n            return seg[pos];\n \n        }\n        public static long querySegment(long seg[], int low, int high, int qlow, int qhigh, int pos) {\n \n            if (qlow <= low && qhigh >= high) {\n                return seg[pos];\n            } else if (qlow > high || qhigh < low) {\n                return 0;\n            } else {\n                long ans = 0;\n                int mid = (low + high) / 2;\n                ans += querySegment(seg, low, mid, qlow, qhigh, (2 * pos) + 1);\n                ans += querySegment(seg, mid + 1, high, qlow, qhigh, (2 * pos) + 2);\n                return ans;\n            }\n \n        }\n        public static int lcs(char[] X, char[] Y, int m, int n) {\n            if (m == 0 || n == 0)\n                return 0;\n            if (X[m - 1] == Y[n - 1])\n                return 1 + lcs(X, Y, m - 1, n - 1);\n            else\n                return Integer.max(lcs(X, Y, m, n - 1), lcs(X, Y, m - 1, n));\n        }\n \n        public static long recursion(long start, long end, long cnt[], int a, int b) {\n \n            long min = 0;\n            long count = 0;\n            int ans1 = -1;\n            int ans2 = -1;\n            int l = 0;\n            int r = cnt.length - 1;\n            while (l <= r) {\n                int mid = (l + r) / 2;\n                if (cnt[mid] >= start) {\n                    ans1 = mid;\n                    r = mid - 1;\n                } else {\n                    l = mid + 1;\n                }\n            }\n \n            l = 0;\n            r = cnt.length - 1;\n            while (l <= r) {\n                int mid = (l + r) / 2;\n                if (cnt[mid] <= end) {\n                    ans2 = mid;\n                    l = mid + 1;\n                } else {\n                    r = mid - 1;\n                }\n            }\n \n            if (ans1 == -1 || ans2 == -1 || ans2 < ans1) {\n                // System.out.println(\"min1 \"+min);\n                min = a;\n                return a;\n \n            } else {\n                min = b * (end - start + 1) * (ans2 - ans1 + 1);\n            }\n            if (start == end) {\n                // System.out.println(\"min \"+min);\n                return min;\n            }\n            long mid = (end + start) / 2;\n            min = Long.min(min, recursion(start, mid, cnt, a, b) + recursion(mid + 1, end, cnt, a, b));\n            // System.out.println(\"min \"+min);\n            return min;\n        }\n \n \n \n \n \n        public int dfs_util(ArrayList < Integer > [] al, boolean vis[], int x, int[] s, int lvl[]) {\n \n            vis[x] = true;\n            int cnt = 1;\n            for (int i = 0; i < al[x].size(); i++) {\n \n                if (!vis[al[x].get(i)]) {\n                    lvl[al[x].get(i)] = lvl[x] + 1;\n                    cnt += dfs_util(al, vis, al[x].get(i), s, lvl);\n \n \n                }\n \n \n            }\n            s[x] = cnt;\n            return s[x];\n        }\n \n        public void dfs(ArrayList[] al, int[] s, int[] lvl) {\n \n            boolean vis[] = new boolean[al.length];\n            for (int i = 0; i < al.length; i++) {\n                if (!vis[i]) {\n                    lvl[i] = 1;\n                    dfs_util(al, vis, i, s, lvl);\n                }\n            }\n        }\n \n        public int[] computeLps(String s)\n        {\n            int ans[] =new int[s.length()];\n            char ch[] = s.toCharArray();\n            int n = s.length();\n            int i=1;\n            int len=0;\n            ans[0]=0;\n            while(i<n)\n            {\n                if(ch[i]==ch[len])\n                {\n                    len++;\n                    ans[i]=len;\n                    i++;\n                }\n                else\n                {\n                    if(len!=0)\n                    {\n                        len=ans[len-1];\n                    }\n                    else\n                    {\n                        ans[i]=len;\n                        i++;\n                    }\n                }\n            }\n\n            return ans;\n\n        }\n \n \n        private void solve(InputReader inp, PrintWriter out1) {\n            int n = inp.nextInt();\n            int m = inp.nextInt();\n            long k = inp.nextLong();\n            long arr[] = new long[n];\n\n            for(int i=0;i<n;i++)\n            {\n                arr[i] = inp.nextLong();\n\n            }\n            long ans=0;\n            for(int i=0;i<m;i++)\n            {\n                long sum=0;\n                for(int j=i;j<n;j++)\n                {\n                    \n\n                    if(j%m==i)\n                    {\n                        if(sum<0)\n                        {\n                           sum=0;\n                        }\n                        sum-=k;\n                    }\n                    \n                    sum+=arr[j];\n                    \n                    ans=Math.max(ans,sum);\n                }\n\n            \n\n            }\n\n            System.out.println(ans);\n           \n\n           \n            \n        }\n \n \n}\n \n \n    static class InputReader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n \n        InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n \n        String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n \n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n \n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\nclass ele implements Comparable < ele > {\n    int value;\n    int i;\n    boolean flag;\n    public ele(int value, int i) {\n        this.value = value;\n        this.i = i;\n        this.flag = false;\n    }\n    public int compareTo(ele e) {\n        return Integer.compare(this.value, e.value);\n    }\n}", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class LightItUp {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t StringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\tint previous = 0;\n\t\tint array[] = new int[n+1];\n\t\tint answer = 0;\n\t\t\n\t\tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tarray[i] = Integer.parseInt(st1.nextToken());\n\t\t\tif(i % 2 == 0){\n\t\t\t\tanswer += (array[i] - previous);\n\t\t\t}\n\t\t\tprevious = array[i];\n\t\t}\n\t\t\n\t\tif(n % 2 == 0){\n\t\t\tanswer += (m - previous);\n\t\t}\n\t\tprevious = m;\n\t\tint max = Integer.MAX_VALUE;\n\t\t\n\t\twhile(n-- != 0){\n\t\t\tint temp = array[n];\n\t\t\tif(n%2 == 0){\n\t\t\t\tarray[n] = array[n+1] - (previous - array[n]);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tarray[n] = array[n+1] + (previous - array[n]);\n\t\t\t}\n\t\t\tprevious = temp;\n\t\t\tmax = Math.min(max, array[n]);\n\t\t}\n\t\tif(max>=-1){\n\t\t\tSystem.out.println(answer);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(answer - (max+1));\n\t\t}\n\n\t}\n\n}\n", "complexity": "linear", "problem": "1000_B. Light It Up", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.function.Function;\n\npublic class Main {\n\n    static int N;\n    static int[] U, V;\n    static int[] A;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        N = sc.nextInt();\n        U = new int[N-1];\n        V = new int[N-1];\n        for (int i = 0; i < N - 1; i++) {\n            U[i] = sc.nextInt()-1;\n            V[i] = sc.nextInt()-1;\n        }\n        A = sc.nextIntArray(N, -1);\n\n        System.out.println(solve() ? \"Yes\" : \"No\");\n    }\n\n    static boolean solve() {\n        if( A[0] != 0 ) return false;\n\n        int[][] G = adjB(N, U, V);\n\n        Map<Integer, Integer> parents = new HashMap<>();\n        for (Node node : orderFromRoot(N, G, 0)) {\n            parents.put(node.a, node.parent);\n        }\n        ArrayDeque<Integer> q = new ArrayDeque<>();\n        for (int next : G[0]) {\n            q.add(0);\n        }\n\n        int idx = 1;\n        while(!q.isEmpty()) {\n            int p = q.poll();\n            int a = A[idx++];\n            if( parents.get(a) != p ) {\n                return false;\n            }\n\n            for (int next : G[a]) {\n                if( next == p ) continue;\n\n                q.add(a);\n            }\n        }\n        return true;\n    }\n\n    static int[][] adjB(int n, int[] from, int[] to) {\n        int[][] adj = new int[n][];\n        int[] cnt = new int[n];\n        for (int f : from) {\n            cnt[f]++;\n        }\n        for (int t : to) {\n            cnt[t]++;\n        }\n        for (int i = 0; i < n; i++) {\n            adj[i] = new int[cnt[i]];\n        }\n        for (int i = 0; i < from.length; i++) {\n            adj[from[i]][--cnt[from[i]]] = to[i];\n            adj[to[i]][--cnt[to[i]]] = from[i];\n        }\n        return adj;\n    }\n\n    static Node[] orderFromRoot(int N, int[][] G, int root) {\n        ArrayDeque<Node> q = new ArrayDeque<>();\n        Node[] ret = new Node[N];\n        int idx = 0;\n        q.add(new Node(-1, root));\n        while(!q.isEmpty()) {\n            Node n = q.poll();\n            ret[idx++] = n;\n            for (int next : G[n.a]) {\n                if( next == n.parent ) continue;\n\n                q.add(new Node(n.a, next));\n            }\n        }\n        return ret;\n    }\n\n    static class Node {\n        int parent, a;\n\n        public Node(int parent, int a) {\n            this.parent = parent;\n            this.a = a;\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++)\n                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++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n    }\n\n    static <A> void writeLines(A[] as, Function<A, String> f) {\n        PrintWriter pw = new PrintWriter(System.out);\n        for (A a : as) {\n            pw.println(f.apply(a));\n        }\n        pw.flush();\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 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 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", "complexity": "nlogn", "problem": "1037_D. Valid BFS?", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.*;\npublic class Solution\n{\n    public static void main(String [] args) throws IOException\n    {\n        PrintWriter pw=new PrintWriter(System.out);//use pw.println() not pw.write();\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(br.readLine());\n        /*\n        inputCopy\n5 3\nxyabd\noutputCopy\n29\ninputCopy\n7 4\nproblem\noutputCopy\n34\ninputCopy\n2 2\nab\noutputCopy\n-1\ninputCopy\n12 1\nabaabbaaabbb\noutputCopy\n1\n        */\n        int n=Integer.parseInt(st.nextToken());\n        int k=Integer.parseInt(st.nextToken());\n        st=new StringTokenizer(br.readLine());\n        String str=st.nextToken();\n        char [] arr=str.toCharArray();\n        Arrays.sort(arr);\n        int weight=arr[0]-96;\n        char a=arr[0];\n        int included=1;\n        for(int i=1;i<arr.length;++i)\n        {\n            if(included==k)\n                break;\n            char c=arr[i];\n            if(c-a<2)\n                continue;\n           \n            weight+=arr[i]-96;\n            ++included;\n            a=arr[i];\n            \n        }\n        if(included==k)\n            pw.println(weight);\n        else\n            pw.println(-1);\n        pw.close();//Do not forget to write it after every program return statement !!\n    }\n}\n/*\n\u2192Judgement Protocol\nTest: #1, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n5 3\nxyabd\nOutput\n29\nAnswer\n29\nChecker Log\nok 1 number(s): \"29\"\nTest: #2, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n7 4\nproblem\nOutput\n34\nAnswer\n34\nChecker Log\nok 1 number(s): \"34\"\nTest: #3, time: 139 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nab\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #4, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 1\nabaabbaaabbb\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #5, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #6, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #7, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\na\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #8, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #9, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #10, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nuwgmkyqeiaocs\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #11, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nhzdxpbfvrltnj\nOutput\n182\nAnswer\n182\nChecker Log\nok 1 number(s): \"182\"\nTest: #12, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nn\nOutput\n14\nAnswer\n14\nChecker Log\nok 1 number(s): \"14\"\nTest: #13, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 8\nsmzeblyjqw\nOutput\n113\nAnswer\n113\nChecker Log\nok 1 number(s): \"113\"\nTest: #14, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n20 20\ntzmvhskkyugkuuxpvtbh\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #15, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #16, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #17, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #18, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 7\niuiukrxcml\nOutput\n99\nAnswer\n99\nChecker Log\nok 1 number(s): \"99\"\nTest: #19, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #20, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 6\nfwseyrarkwcd\nOutput\n61\nAnswer\n61\nChecker Log\nok 1 number(s): \"61\"\nTest: #21, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nac\nOutput\n4\nAnswer\n4\nChecker Log\nok 1 number(s): \"4\"\nTest: #22, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nc\nOutput\n3\nAnswer\n3\nChecker Log\nok 1 number(s): \"3\"\nTest: #23, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nad\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #24, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER\nInput\n2 1\nac\nOutput\n-1\nAnswer\n1\nChecker Log\nwrong answer 1st number\n*/", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A\n{\n    public static int palin(String str)\n    {\n        int flag=0;\n        int l=str.length();\n        for(int i=0;i<l/2;i++)\n        {\n            if(str.charAt(i)!=str.charAt(l-i-1))\n            {\n                flag=1;\n                break;\n            }\n        }\n        if(flag==1)\n        return 0;\n        else\n        return 1;\n    }\n    public static void main(String args[])\n    {\n        Scanner sc=new Scanner(System.in);\n        String str=sc.next();\n        HashSet<Character> hs=new HashSet<>();\n        for(int i=0;i<str.length();i++)\n        {\n            hs.add(str.charAt(i));\n        }\n        if(hs.size()==1)\n        System.out.println(0);\n        else if(palin(str)==0)\n        System.out.println(str.length());\n        else\n        System.out.println(str.length()-1);\n    }\n}", "complexity": "linear", "problem": "981_A. Antipalindrome", "from": "CODEFORCES"}
{"src": " 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   CF111111\n{\n  BufferedReader in;\n  StringTokenizer as;\n  int nums[],nums2[];\n  int[] nums1[];\n  boolean con = true;\n \n  ArrayList < Integer >  ar = new ArrayList < Integer >();\n  ArrayList < Integer >  fi = new ArrayList < Integer >();\n  Map<Integer,Integer > map = new HashMap<Integer, Integer>();\n  public static void main (String[] args)\n  {\n    new CF111111  ();\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  public int LIS(int arr[])\n  {\n    int n = arr.length;\n    int sun[] = new int [n];\n    int cur = 0;\n    for(int x = 0;x<n;x++)\n    {\n      int temp = Arrays.binarySearch(sun,0,cur,arr[x]);\n      if(temp < 0)\n        temp = -temp -1;\n      sun[temp] = arr[x];\n      if(temp == cur)\n        cur++;\n    }\n    return cur;\n    \n  }\n  \n  \n  \n  \n  public CF111111  ()\n  {\n    try\n    {\n      \n      in = new BufferedReader (new InputStreamReader (System.in));\n      int a = nextInt();\n      for(int xx1 = 0;xx1<a;xx1++)\n      {\n        int b = nextInt();\n        nums = new int [b];\n        for(int x = 0;x<b;x++)\n        {\n          nums[x] = nextInt();\n        }\n         int max = 0;\n         int max2 = -1;\n         for(int x = 0;x<b;x++)\n         {\n           if(nums[x] >= max)\n           {\n             max2 = max;\n             max = nums[x];\n           }\n           else if(nums[x] >= max2)\n             max2 = nums[x];\n         }\n        System.out.println(Math.min(max2, b-1)-1);\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}", "complexity": "linear", "problem": "1197_A. DIY Wooden Ladder", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.Scanner;\npublic class abc{\n    public static int check(StringBuilder s)\n    {\n    \tint countRemove=0;\n    \tif(!s.toString().contains(\"xxx\")) return countRemove;\n    \telse{\n    \t\t\n    \t\tfor(int i=1;i<s.length()-1;i++)\n    \t\t{\n    \t\t\tif(s.charAt(i-1)=='x' && s.charAt(i)=='x' && s.charAt(i+1)=='x')\n    \t\t\t{\n    \t\t\t\n    \t\t\t\tcountRemove++;\n    \t\t\t}\n    \t\t}\n    \t\treturn countRemove;\n    \t}\n    }\n   \n\tpublic static void main (String[] args) {\n\t\n\tScanner sc = new Scanner(System.in);\n\tint n = sc.nextInt();\n\t//sc= new Scanner(System.in);\n\tString s = sc.next();\n\tStringBuilder sb = new StringBuilder(\"\");\n\tsb.append(s);\n\t\n    System.out.println(check(sb));\n\t\n\t\n\t\n\t}\n}", "complexity": "linear", "problem": "978_B. File Name", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.ListIterator;\nimport java.util.Collection;\nimport java.util.AbstractList;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Deque;\nimport java.util.ArrayDeque;\nimport java.util.NoSuchElementException;\nimport java.util.ConcurrentModificationException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author cunbidun\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        DPairOfLines solver = new DPairOfLines();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DPairOfLines {\n        private static final int INF = (int) 2e9 + 7;\n        private InputReader in;\n        private PrintWriter out;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            int n = in.nextInt();\n            if (n <= 4) {\n                out.println(\"YES\");\n                return;\n            }\n            TreeList<PairII> list = new TreeList<>();\n            PairII[] a = new PairII[n + 1];\n            for (int i = 1; i <= n; i++) {\n                a[i] = (new PairII(in.nextInt(), in.nextInt()));\n                list.add(a[i]);\n            }\n            PairII pos1 = new PairII(INF, INF);\n            PairII pos2 = new PairII(INF, INF);\n            for (int i = 1; i <= 5; i++) {\n                for (int j = i + 1; j <= 5; j++) {\n                    for (int k = j + 1; k <= 5; k++) {\n                        int x1 = a[i].first;\n                        int y1 = a[i].second;\n                        int x2 = a[j].first;\n                        int y2 = a[j].second;\n                        int x = a[k].first;\n                        int y = a[k].second;\n                        long s = (long) (y2 - y1) * x + (long) (x1 - x2) * y + ((long) x2 * y1 - (long) x1 * y2);\n                        if (s == 0) {\n                            pos1 = a[i];\n                            pos2 = a[j];\n                        }\n                    }\n                }\n            }\n\n            if (pos1.equals(new PairII(INF, INF))) {\n                out.println(\"NO\");\n                return;\n            }\n            int x1 = pos1.first;\n            int y1 = pos1.second;\n            int x2 = pos2.first;\n            int y2 = pos2.second;\n            for (int i = 0; i < list.size(); i++) {\n                int x = list.get(i).first;\n                int y = list.get(i).second;\n                long s = (long) (y2 - y1) * x + (long) (x1 - x2) * y + ((long) x2 * y1 - (long) x1 * y2);\n                if (s == 0) {\n                    list.remove(i);\n                    i--;\n                }\n            }\n            if (list.size() <= 2) {\n                out.println(\"YES\");\n                return;\n            }\n            x1 = list.get(0).first;\n            y1 = list.get(0).second;\n            x2 = list.get(1).first;\n            y2 = list.get(1).second;\n            for (int i = 0; i < list.size(); i++) {\n                int x = list.get(i).first;\n                int y = list.get(i).second;\n                long s = (long) (y2 - y1) * x + (long) (x1 - x2) * y + ((long) x2 * y1 - (long) x1 * y2);\n                if (s == 0) {\n                    list.remove(i);\n                    i--;\n                }\n            }\n            if (list.size() == 0) {\n                out.println(\"YES\");\n            } else out.println(\"NO\");\n        }\n\n    }\n\n    static interface OrderedIterator<E> extends Iterator<E> {\n    }\n\n    static class PairII implements Comparable<PairII> {\n        public int first;\n        public int second;\n\n        public PairII(int 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            PairII pair = (PairII) o;\n\n            return first == pair.first && second == pair.second;\n        }\n\n        public String toString() {\n            return \"(\" + first + \",\" + second + \")\";\n        }\n\n        public int compareTo(PairII o) {\n            int value = Integer.compare(first, o.first);\n            if (value != 0) {\n                return value;\n            }\n            return Integer.compare(second, o.second);\n        }\n\n    }\n\n    static class TreeList<E> extends AbstractList<E> {\n        private TreeList.AVLNode<E> root;\n        private int size;\n\n        public TreeList() {\n            super();\n        }\n\n        public TreeList(final Collection<? extends E> coll) {\n            super();\n            if (!coll.isEmpty()) {\n                root = new TreeList.AVLNode<>(coll);\n                size = coll.size();\n            }\n        }\n\n        public E get(final int index) {\n            return root.get(index).getValue();\n        }\n\n        public int size() {\n            return size;\n        }\n\n        public Iterator<E> iterator() {\n            // override to go 75% faster\n            return listIterator(0);\n        }\n\n        public ListIterator<E> listIterator() {\n            // override to go 75% faster\n            return listIterator(0);\n        }\n\n        public ListIterator<E> listIterator(final int fromIndex) {\n            return new TreeList.TreeListIterator<>(this, fromIndex);\n        }\n\n        public int indexOf(final Object object) {\n            // override to go 75% faster\n            if (root == null) {\n                return -1;\n            }\n            return root.indexOf(object, root.relativePosition);\n        }\n\n        public boolean contains(final Object object) {\n            return indexOf(object) >= 0;\n        }\n\n        public Object[] toArray() {\n            final Object[] array = new Object[size()];\n            if (root != null) {\n                root.toArray(array, root.relativePosition);\n            }\n            return array;\n        }\n\n        public void add(final int index, final E obj) {\n            modCount++;\n            if (root == null) {\n                root = new TreeList.AVLNode<>(index, obj, null, null);\n            } else {\n                root = root.insert(index, obj);\n            }\n            size++;\n        }\n\n        public boolean addAll(final Collection<? extends E> c) {\n            if (c.isEmpty()) {\n                return false;\n            }\n            modCount += c.size();\n            final TreeList.AVLNode<E> cTree = new TreeList.AVLNode<>(c);\n            root = root == null ? cTree : root.addAll(cTree, size);\n            size += c.size();\n            return true;\n        }\n\n        public E set(final int index, final E obj) {\n            final TreeList.AVLNode<E> node = root.get(index);\n            final E result = node.value;\n            node.setValue(obj);\n            return result;\n        }\n\n        public E remove(final int index) {\n            modCount++;\n            final E result = get(index);\n            root = root.remove(index);\n            size--;\n            return result;\n        }\n\n        public void clear() {\n            modCount++;\n            root = null;\n            size = 0;\n        }\n\n        static class AVLNode<E> {\n            private TreeList.AVLNode<E> left;\n            private boolean leftIsPrevious;\n            private TreeList.AVLNode<E> right;\n            private boolean rightIsNext;\n            private int height;\n            private int relativePosition;\n            private E value;\n\n            private AVLNode(final int relativePosition, final E obj,\n                            final TreeList.AVLNode<E> rightFollower, final TreeList.AVLNode<E> leftFollower) {\n                this.relativePosition = relativePosition;\n                value = obj;\n                rightIsNext = true;\n                leftIsPrevious = true;\n                right = rightFollower;\n                left = leftFollower;\n            }\n\n            private AVLNode(final Collection<? extends E> coll) {\n                this(coll.iterator(), 0, coll.size() - 1, 0, null, null);\n            }\n\n            private AVLNode(final Iterator<? extends E> iterator, final int start, final int end,\n                            final int absolutePositionOfParent, final TreeList.AVLNode<E> prev, final TreeList.AVLNode<E> next) {\n                final int mid = start + (end - start) / 2;\n                if (start < mid) {\n                    left = new TreeList.AVLNode<>(iterator, start, mid - 1, mid, prev, this);\n                } else {\n                    leftIsPrevious = true;\n                    left = prev;\n                }\n                value = iterator.next();\n                relativePosition = mid - absolutePositionOfParent;\n                if (mid < end) {\n                    right = new TreeList.AVLNode<>(iterator, mid + 1, end, mid, this, next);\n                } else {\n                    rightIsNext = true;\n                    right = next;\n                }\n                recalcHeight();\n            }\n\n            E getValue() {\n                return value;\n            }\n\n            void setValue(final E obj) {\n                this.value = obj;\n            }\n\n            TreeList.AVLNode<E> get(final int index) {\n                final int indexRelativeToMe = index - relativePosition;\n\n                if (indexRelativeToMe == 0) {\n                    return this;\n                }\n\n                final TreeList.AVLNode<E> nextNode = indexRelativeToMe < 0 ? getLeftSubTree() : getRightSubTree();\n                if (nextNode == null) {\n                    return null;\n                }\n                return nextNode.get(indexRelativeToMe);\n            }\n\n            int indexOf(final Object object, final int index) {\n                if (getLeftSubTree() != null) {\n                    final int result = left.indexOf(object, index + left.relativePosition);\n                    if (result != -1) {\n                        return result;\n                    }\n                }\n                if (value == null ? value == object : value.equals(object)) {\n                    return index;\n                }\n                if (getRightSubTree() != null) {\n                    return right.indexOf(object, index + right.relativePosition);\n                }\n                return -1;\n            }\n\n            void toArray(final Object[] array, final int index) {\n                array[index] = value;\n                if (getLeftSubTree() != null) {\n                    left.toArray(array, index + left.relativePosition);\n                }\n                if (getRightSubTree() != null) {\n                    right.toArray(array, index + right.relativePosition);\n                }\n            }\n\n            TreeList.AVLNode<E> next() {\n                if (rightIsNext || right == null) {\n                    return right;\n                }\n                return right.min();\n            }\n\n            TreeList.AVLNode<E> previous() {\n                if (leftIsPrevious || left == null) {\n                    return left;\n                }\n                return left.max();\n            }\n\n            TreeList.AVLNode<E> insert(final int index, final E obj) {\n                final int indexRelativeToMe = index - relativePosition;\n\n                if (indexRelativeToMe <= 0) {\n                    return insertOnLeft(indexRelativeToMe, obj);\n                }\n                return insertOnRight(indexRelativeToMe, obj);\n            }\n\n            private TreeList.AVLNode<E> insertOnLeft(final int indexRelativeToMe, final E obj) {\n                if (getLeftSubTree() == null) {\n                    setLeft(new TreeList.AVLNode<>(-1, obj, this, left), null);\n                } else {\n                    setLeft(left.insert(indexRelativeToMe, obj), null);\n                }\n\n                if (relativePosition >= 0) {\n                    relativePosition++;\n                }\n                final TreeList.AVLNode<E> ret = balance();\n                recalcHeight();\n                return ret;\n            }\n\n            private TreeList.AVLNode<E> insertOnRight(final int indexRelativeToMe, final E obj) {\n                if (getRightSubTree() == null) {\n                    setRight(new TreeList.AVLNode<>(+1, obj, right, this), null);\n                } else {\n                    setRight(right.insert(indexRelativeToMe, obj), null);\n                }\n                if (relativePosition < 0) {\n                    relativePosition--;\n                }\n                final TreeList.AVLNode<E> ret = balance();\n                recalcHeight();\n                return ret;\n            }\n\n            private TreeList.AVLNode<E> getLeftSubTree() {\n                return leftIsPrevious ? null : left;\n            }\n\n            private TreeList.AVLNode<E> getRightSubTree() {\n                return rightIsNext ? null : right;\n            }\n\n            private TreeList.AVLNode<E> max() {\n                return getRightSubTree() == null ? this : right.max();\n            }\n\n            private TreeList.AVLNode<E> min() {\n                return getLeftSubTree() == null ? this : left.min();\n            }\n\n            TreeList.AVLNode<E> remove(final int index) {\n                final int indexRelativeToMe = index - relativePosition;\n\n                if (indexRelativeToMe == 0) {\n                    return removeSelf();\n                }\n                if (indexRelativeToMe > 0) {\n                    setRight(right.remove(indexRelativeToMe), right.right);\n                    if (relativePosition < 0) {\n                        relativePosition++;\n                    }\n                } else {\n                    setLeft(left.remove(indexRelativeToMe), left.left);\n                    if (relativePosition > 0) {\n                        relativePosition--;\n                    }\n                }\n                recalcHeight();\n                return balance();\n            }\n\n            private TreeList.AVLNode<E> removeMax() {\n                if (getRightSubTree() == null) {\n                    return removeSelf();\n                }\n                setRight(right.removeMax(), right.right);\n                if (relativePosition < 0) {\n                    relativePosition++;\n                }\n                recalcHeight();\n                return balance();\n            }\n\n            private TreeList.AVLNode<E> removeMin() {\n                if (getLeftSubTree() == null) {\n                    return removeSelf();\n                }\n                setLeft(left.removeMin(), left.left);\n                if (relativePosition > 0) {\n                    relativePosition--;\n                }\n                recalcHeight();\n                return balance();\n            }\n\n            private TreeList.AVLNode<E> removeSelf() {\n                if (getRightSubTree() == null && getLeftSubTree() == null) {\n                    return null;\n                }\n                if (getRightSubTree() == null) {\n                    if (relativePosition > 0) {\n                        left.relativePosition += relativePosition;\n                    }\n                    left.max().setRight(null, right);\n                    return left;\n                }\n                if (getLeftSubTree() == null) {\n                    right.relativePosition += relativePosition - (relativePosition < 0 ? 0 : 1);\n                    right.min().setLeft(null, left);\n                    return right;\n                }\n\n                if (heightRightMinusLeft() > 0) {\n                    // more on the right, so delete from the right\n                    final TreeList.AVLNode<E> rightMin = right.min();\n                    value = rightMin.value;\n                    if (leftIsPrevious) {\n                        left = rightMin.left;\n                    }\n                    right = right.removeMin();\n                    if (relativePosition < 0) {\n                        relativePosition++;\n                    }\n                } else {\n                    // more on the left or equal, so delete from the left\n                    final TreeList.AVLNode<E> leftMax = left.max();\n                    value = leftMax.value;\n                    if (rightIsNext) {\n                        right = leftMax.right;\n                    }\n                    final TreeList.AVLNode<E> leftPrevious = left.left;\n                    left = left.removeMax();\n                    if (left == null) {\n                        // special case where left that was deleted was a double link\n                        // only occurs when height difference is equal\n                        left = leftPrevious;\n                        leftIsPrevious = true;\n                    }\n                    if (relativePosition > 0) {\n                        relativePosition--;\n                    }\n                }\n                recalcHeight();\n                return this;\n            }\n\n            private TreeList.AVLNode<E> balance() {\n                switch (heightRightMinusLeft()) {\n                    case 1:\n                    case 0:\n                    case -1:\n                        return this;\n                    case -2:\n                        if (left.heightRightMinusLeft() > 0) {\n                            setLeft(left.rotateLeft(), null);\n                        }\n                        return rotateRight();\n                    case 2:\n                        if (right.heightRightMinusLeft() < 0) {\n                            setRight(right.rotateRight(), null);\n                        }\n                        return rotateLeft();\n                    default:\n                        throw new RuntimeException(\"tree inconsistent!\");\n                }\n            }\n\n            private int getOffset(final TreeList.AVLNode<E> node) {\n                if (node == null) {\n                    return 0;\n                }\n                return node.relativePosition;\n            }\n\n            private int setOffset(final TreeList.AVLNode<E> node, final int newOffest) {\n                if (node == null) {\n                    return 0;\n                }\n                final int oldOffset = getOffset(node);\n                node.relativePosition = newOffest;\n                return oldOffset;\n            }\n\n            private void recalcHeight() {\n                height = Math.max(\n                        getLeftSubTree() == null ? -1 : getLeftSubTree().height,\n                        getRightSubTree() == null ? -1 : getRightSubTree().height) + 1;\n            }\n\n            private int getHeight(final TreeList.AVLNode<E> node) {\n                return node == null ? -1 : node.height;\n            }\n\n            private int heightRightMinusLeft() {\n                return getHeight(getRightSubTree()) - getHeight(getLeftSubTree());\n            }\n\n            private TreeList.AVLNode<E> rotateLeft() {\n                final TreeList.AVLNode<E> newTop = right; // can't be faedelung!\n                final TreeList.AVLNode<E> movedNode = getRightSubTree().getLeftSubTree();\n\n                final int newTopPosition = relativePosition + getOffset(newTop);\n                final int myNewPosition = -newTop.relativePosition;\n                final int movedPosition = getOffset(newTop) + getOffset(movedNode);\n\n                setRight(movedNode, newTop);\n                newTop.setLeft(this, null);\n\n                setOffset(newTop, newTopPosition);\n                setOffset(this, myNewPosition);\n                setOffset(movedNode, movedPosition);\n                return newTop;\n            }\n\n            private TreeList.AVLNode<E> rotateRight() {\n                final TreeList.AVLNode<E> newTop = left;\n                final TreeList.AVLNode<E> movedNode = getLeftSubTree().getRightSubTree();\n\n                final int newTopPosition = relativePosition + getOffset(newTop);\n                final int myNewPosition = -newTop.relativePosition;\n                final int movedPosition = getOffset(newTop) + getOffset(movedNode);\n\n                setLeft(movedNode, newTop);\n                newTop.setRight(this, null);\n\n                setOffset(newTop, newTopPosition);\n                setOffset(this, myNewPosition);\n                setOffset(movedNode, movedPosition);\n                return newTop;\n            }\n\n            private void setLeft(final TreeList.AVLNode<E> node, final TreeList.AVLNode<E> previous) {\n                leftIsPrevious = node == null;\n                left = leftIsPrevious ? previous : node;\n                recalcHeight();\n            }\n\n            private void setRight(final TreeList.AVLNode<E> node, final TreeList.AVLNode<E> next) {\n                rightIsNext = node == null;\n                right = rightIsNext ? next : node;\n                recalcHeight();\n            }\n\n            private TreeList.AVLNode<E> addAll(TreeList.AVLNode<E> otherTree, final int currentSize) {\n                final TreeList.AVLNode<E> maxNode = max();\n                final TreeList.AVLNode<E> otherTreeMin = otherTree.min();\n\n                // We need to efficiently merge the two AVL trees while keeping them\n                // balanced (or nearly balanced). To do this, we take the shorter\n                // tree and combine it with a similar-height subtree of the taller\n                // tree. There are two symmetric cases:\n                //   * this tree is taller, or\n                //   * otherTree is taller.\n                if (otherTree.height > height) {\n                    // CASE 1: The other tree is taller than this one. We will thus\n                    // merge this tree into otherTree.\n\n                    // STEP 1: Remove the maximum element from this tree.\n                    final TreeList.AVLNode<E> leftSubTree = removeMax();\n\n                    // STEP 2: Navigate left from the root of otherTree until we\n                    // contains a subtree, s, that is no taller than me. (While we are\n                    // navigating left, we store the nodes we encounter in a stack\n                    // so that we can re-balance them in step 4.)\n                    final Deque<TreeList.AVLNode<E>> sAncestors = new ArrayDeque<>();\n                    TreeList.AVLNode<E> s = otherTree;\n                    int sAbsolutePosition = s.relativePosition + currentSize;\n                    int sParentAbsolutePosition = 0;\n                    while (s != null && s.height > getHeight(leftSubTree)) {\n                        sParentAbsolutePosition = sAbsolutePosition;\n                        sAncestors.push(s);\n                        s = s.left;\n                        if (s != null) {\n                            sAbsolutePosition += s.relativePosition;\n                        }\n                    }\n\n                    // STEP 3: Replace s with a newly constructed subtree whose root\n                    // is maxNode, whose left subtree is leftSubTree, and whose right\n                    // subtree is s.\n                    maxNode.setLeft(leftSubTree, null);\n                    maxNode.setRight(s, otherTreeMin);\n                    if (leftSubTree != null) {\n                        leftSubTree.max().setRight(null, maxNode);\n                        leftSubTree.relativePosition -= currentSize - 1;\n                    }\n                    if (s != null) {\n                        s.min().setLeft(null, maxNode);\n                        s.relativePosition = sAbsolutePosition - currentSize + 1;\n                    }\n                    maxNode.relativePosition = currentSize - 1 - sParentAbsolutePosition;\n                    otherTree.relativePosition += currentSize;\n\n                    // STEP 4: Re-balance the tree and recalculate the heights of s's ancestors.\n                    s = maxNode;\n                    while (!sAncestors.isEmpty()) {\n                        final TreeList.AVLNode<E> sAncestor = sAncestors.pop();\n                        sAncestor.setLeft(s, null);\n                        s = sAncestor.balance();\n                    }\n                    return s;\n                }\n                otherTree = otherTree.removeMin();\n\n                final Deque<TreeList.AVLNode<E>> sAncestors = new ArrayDeque<>();\n                TreeList.AVLNode<E> s = this;\n                int sAbsolutePosition = s.relativePosition;\n                int sParentAbsolutePosition = 0;\n                while (s != null && s.height > getHeight(otherTree)) {\n                    sParentAbsolutePosition = sAbsolutePosition;\n                    sAncestors.push(s);\n                    s = s.right;\n                    if (s != null) {\n                        sAbsolutePosition += s.relativePosition;\n                    }\n                }\n\n                otherTreeMin.setRight(otherTree, null);\n                otherTreeMin.setLeft(s, maxNode);\n                if (otherTree != null) {\n                    otherTree.min().setLeft(null, otherTreeMin);\n                    otherTree.relativePosition++;\n                }\n                if (s != null) {\n                    s.max().setRight(null, otherTreeMin);\n                    s.relativePosition = sAbsolutePosition - currentSize;\n                }\n                otherTreeMin.relativePosition = currentSize - sParentAbsolutePosition;\n\n                s = otherTreeMin;\n                while (!sAncestors.isEmpty()) {\n                    final TreeList.AVLNode<E> sAncestor = sAncestors.pop();\n                    sAncestor.setRight(s, null);\n                    s = sAncestor.balance();\n                }\n                return s;\n            }\n\n        }\n\n        static class TreeListIterator<E> implements ListIterator<E>, OrderedIterator<E> {\n            private final TreeList<E> parent;\n            private TreeList.AVLNode<E> next;\n            private int nextIndex;\n            private TreeList.AVLNode<E> current;\n            private int currentIndex;\n            private int expectedModCount;\n\n            private TreeListIterator(final TreeList<E> parent, final int fromIndex) throws IndexOutOfBoundsException {\n                super();\n                this.parent = parent;\n                this.expectedModCount = parent.modCount;\n                this.next = parent.root == null ? null : parent.root.get(fromIndex);\n                this.nextIndex = fromIndex;\n                this.currentIndex = -1;\n            }\n\n            private void checkModCount() {\n                if (parent.modCount != expectedModCount) {\n                    throw new ConcurrentModificationException();\n                }\n            }\n\n            public boolean hasNext() {\n                return nextIndex < parent.size();\n            }\n\n            public E next() {\n                checkModCount();\n                if (!hasNext()) {\n                    throw new NoSuchElementException(\"No element at index \" + nextIndex + \".\");\n                }\n                if (next == null) {\n                    next = parent.root.get(nextIndex);\n                }\n                final E value = next.getValue();\n                current = next;\n                currentIndex = nextIndex++;\n                next = next.next();\n                return value;\n            }\n\n            public boolean hasPrevious() {\n                return nextIndex > 0;\n            }\n\n            public E previous() {\n                checkModCount();\n                if (!hasPrevious()) {\n                    throw new NoSuchElementException(\"Already at start of list.\");\n                }\n                if (next == null) {\n                    next = parent.root.get(nextIndex - 1);\n                } else {\n                    next = next.previous();\n                }\n                final E value = next.getValue();\n                current = next;\n                currentIndex = --nextIndex;\n                return value;\n            }\n\n            public int nextIndex() {\n                return nextIndex;\n            }\n\n            public int previousIndex() {\n                return nextIndex() - 1;\n            }\n\n            public void remove() {\n                checkModCount();\n                if (currentIndex == -1) {\n                    throw new IllegalStateException();\n                }\n                parent.remove(currentIndex);\n                if (nextIndex != currentIndex) {\n                    // remove() following next()\n                    nextIndex--;\n                }\n                // the AVL node referenced by next may have become stale after a remove\n                // reset it now: will be retrieved by next call to next()/previous() via nextIndex\n                next = null;\n                current = null;\n                currentIndex = -1;\n                expectedModCount++;\n            }\n\n            public void set(final E obj) {\n                checkModCount();\n                if (current == null) {\n                    throw new IllegalStateException();\n                }\n                current.setValue(obj);\n            }\n\n            public void add(final E obj) {\n                checkModCount();\n                parent.add(nextIndex, obj);\n                current = null;\n                currentIndex = -1;\n                nextIndex++;\n                expectedModCount++;\n            }\n\n        }\n\n    }\n\n    static class InputReader extends InputStream {\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 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                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        private static boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "961_D. Pair Of Lines", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class GFG {\n\tpublic static void main (String[] args) {\n\t    Scanner sc = new Scanner (System.in);\n\t    int n = sc.nextInt();\n\t    int a = sc.nextInt();\n\t    int b = sc.nextInt();\n\t    int c = sc.nextInt();\n\t    int ans = 0;\n\t    int t= sc.nextInt();\n\t    int arr[] = new int[n];\n\t    for(int i=0;i<n;i++){\n\t        int nn = sc.nextInt();\n\t        ans+=a;\n\t        if(b<c){\n\t            ans += (t-nn) * (c - b);\n\t        }\n\t    }\n\t    System.out.println(ans);\n\t}\n}", "complexity": "linear", "problem": "964_B. Messages", "from": "CODEFORCES"}
{"src": "\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\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n744444444747477777774\n44444447474747777777\n */\n\n/**\n *\n * @author Andy Phan\n */\npublic class b {\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        Integer[] arr = new Integer[n];\n        int numZ = 0;\n        for(int i = 0; i < n; i++) {\n            arr[i] = in.nextInt();\n            if(arr[i] == 0) numZ++;\n        }\n        \n        Arrays.sort(arr);\n        \n        \n        if(numZ > 1) {\n            System.out.println(\"cslnb\");\n            return;\n        }\n        int numDup = 0;\n        int[] arr2 = new int[n];\n        for(int i = 0; i < n; i++) {\n            arr2[i] = arr[i];\n            if(i != 0) {\n                if(arr2[i] == arr2[i-1]) {\n                    arr2[i-1]--;\n                    numDup++;\n                }\n            }\n        }\n        \n        if(numDup > 1) {\n            System.out.println(\"cslnb\");\n            return;\n        }\n        \n        \n        for(int i = 0; i < n; i++) {\n            if(i != 0) {\n                if(arr2[i] == arr2[i-1]) {\n                    System.out.println(\"cslnb\");\n                    return;\n                }\n            }\n        }\n        long num = 0;\n        if(numDup == 1) num++;\n        for(int i = 0; i < n; i++) {\n            num += arr2[i]-i;\n        }\n        \n        if(num%2 == 0) {\n            System.out.println(\"cslnb\");\n        } else {\n            System.out.println(\"sjfnb\");\n        }\n        \n\n        out.close();\n    }\n    \n    static class FS {\n\n        BufferedReader in;\n        StringTokenizer token;\n        \n        public FS(InputStream str) {\n            in = new BufferedReader(new InputStreamReader(str));\n        }\n        \n        public String next() {\n            if (token == null || !token.hasMoreElements()) {\n                try {\n                    token = new StringTokenizer(in.readLine());\n                } catch (IOException ex) {\n                }\n                return next();\n            }\n            return token.nextToken();\n        }\n        \n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n    }\n}\n", "complexity": "linear", "problem": "1191_D. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class D {\n\n\tstatic final boolean stdin = true;\n\tstatic final String filename = \"\";\n\tstatic FastScanner br;\n\tstatic PrintWriter pw;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tif (stdin) {\n\t\t\tbr = new FastScanner();\n\t\t\tpw = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t} else {\n\t\t\tbr = new FastScanner(filename + \".in\");\n\t\t\tpw = new PrintWriter(new FileWriter(filename + \".out\"));\n\t\t}\n\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(br, pw);\n\t}\n\n\tstatic class Solver {\n\t\tstatic long mod = (long) (1e10);\n\n\t\tpublic void solve(FastScanner br, PrintWriter pw) throws IOException {\n\t\t\tint n = br.ni();\n\t\t\tInteger[] in = br.nIa(n);\n\t\t\tTreeSet<Integer> ts = new TreeSet<Integer>();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tts.add(in[i]);\n\t\t\t}\n\t\t\tString twoSol = \"\";\n\t\t\tfor (int i = 0; i <= 30; i++) {\n\t\t\t\tfor (int j : in) {\n\t\t\t\t\tif (ts.contains(j + (int) Math.pow(2, i))) {\n\t\t\t\t\t\tif (ts.contains(j - (int) Math.pow(2, i))) {\n\t\t\t\t\t\t\tpw.println(3);\n\t\t\t\t\t\t\tpw.println(j + \" \" + (j + (int) Math.pow(2, i)) + \" \" + (j - (int) Math.pow(2, i)));\n\t\t\t\t\t\t\tpw.close();\n\t\t\t\t\t\t\tSystem.exit(0);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\ttwoSol = (j + \" \" + (j + (int) Math.pow(2, i)));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (twoSol.isEmpty()) {\n\t\t\t\tpw.println(1);\n\t\t\t\tpw.println(in[0]);\n\t\t\t} else {\n\t\t\t\tpw.println(2);\n\t\t\t\tpw.println(twoSol);\n\t\t\t}\n\t\t\tpw.close();\n\t\t}\n\n\t\tstatic long gcd(long a, long b) {\n\t\t\tif (a > b)\n\t\t\t\treturn gcd(b, a);\n\t\t\tif (a == 0)\n\t\t\t\treturn b;\n\t\t\treturn gcd(b % a, a);\n\t\t}\n\n\t\tstatic long lcm(long a, long b) {\n\t\t\treturn a * (b / gcd(a, b));\n\t\t}\n\n\t\tstatic long pow(long a, long b) {\n\t\t\tif (b == 0)\n\t\t\t\treturn 1L;\n\t\t\tlong val = pow(a, b / 2);\n\t\t\tif (b % 2 == 0)\n\t\t\t\treturn val * val % mod;\n\t\t\telse\n\t\t\t\treturn val * val % mod * a % mod;\n\t\t}\n\n\t}\n\n\tstatic class Point implements Comparable<Point> {\n\t\tint a;\n\t\tint b;\n\n\t\tPoint(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn this.a - o.a;\n\t\t}\n\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(String s) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tArrayList<Integer>[] ng(int n, int e) {\n\t\t\tArrayList<Integer>[] adj = new ArrayList[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tadj[i] = new ArrayList<Integer>();\n\t\t\t}\n\t\t\tfor (int i = 0; i < e; i++) {\n\t\t\t\tint a = ni() - 1;\n\t\t\t\tint b = ni() - 1;\n\t\t\t\tadj[a].add(b);\n\t\t\t\tadj[b].add(a);\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\n\t\tInteger[] nIa(int n) {\n\t\t\tInteger[] arr = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = ni();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tint[] nia(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = ni();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tLong[] nLa(int n) {\n\t\t\tLong[] arr = new Long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nl();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] nla(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nl();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tString[] nsa(int n) {\n\t\t\tString[] arr = new String[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tString nt() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint ni() {\n\t\t\treturn Integer.parseInt(nt());\n\t\t}\n\n\t\tlong nl() {\n\t\t\treturn Long.parseLong(nt());\n\t\t}\n\n\t\tdouble nd() {\n\t\t\treturn Double.parseDouble(nt());\n\t\t}\n\n\t}\n}", "complexity": "nlogn", "problem": "988_D. Points and Powers of Two", "from": "CODEFORCES"}
{"src": "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.LinkedList;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Set;\n\npublic class Main {\n\tprivate static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tString[] s = br.readLine().trim().split(\" \");\n\t\tint n = Integer.parseInt(s[0]);\n\t\tint m = Integer.parseInt(s[1]);\n\t\tlong b[] = new long[n];\n\t\ts = br.readLine().trim().split(\" \");\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tb[i] = Integer.parseInt(s[i]);\n\t\t}\n\t\tlong g[] = new long[m];\n\t\ts = br.readLine().trim().split(\" \");\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tg[i] = Integer.parseInt(s[i]);\n\t\t}\n\t\tArrays.sort(b);\n\t\tArrays.sort(g);\n\t\tif(g[0] < b[n-1]) {\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t\telse if(g[0] == b[n-1]){\n\t\t\tlong ans = 0;\n\t\t\tfor(int i = 0; i < m; i++) {\n\t\t\t\tans += g[i];\n\t\t\t}\n\t\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\t\tans += (m)*b[i];\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\n\t\t}\n\t\telse {\n\t\t\tlong ans = 0;\n\t\t\tfor(int i = 0; i < m; i++) {\n\t\t\t\tans += g[i];\n\t\t\t}\n\t\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\t\tans += (m)*b[i];\n\t\t\t}\n\t\t\tans += b[n-1]-b[n-2];\n\t\t\tSystem.out.println(ans);\n\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n    public static void main(String[] args){\n        try {\n            new Main().solve();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n    ArrayList<Edge>[]edge;\n    int n,m,cnt=0;\n    int ord;\n    int[]order;int[]vis;\n    Edge[] e;\n    private void solve() throws Exception{\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        n=in.nextInt();m=in.nextInt();\n        edge=new ArrayList[n+1];\n        e=new Edge[m];\n        vis=new int[n+1];\n        order=new int[n+1];\n        for(int i=1;i<=n;i++){\n            edge[i]=new ArrayList<>();\n        }\n        for(int i=1;i<=m;i++){\n            int s=in.nextInt(),t=in.nextInt(),c=in.nextInt();\n            edge[s].add(new Edge(s,t,c,i));\n        }\n        int l=0,r=1000000000;\n        while (l<r){\n            int mid=(l+r)>>>1;\n            if(judge(mid,false))r=mid;\n            else l=mid+1;\n        }\n        out.print(l+\" \");\n        judge(l,true);\n        Arrays.sort(e,0,cnt,Comparator.comparingInt(x->x.id));\n        int ans=0;\n        int[]a=new int[m];\n        for(int i=0;i<cnt;i++){\n            if(order[e[i].s]<order[e[i].t])a[ans++]=e[i].id;\n        }\n        out.println(ans);\n        for(int i=0;i<ans;i++){\n            out.print(a[i]+\" \");\n        }\n        out.println();\n        out.flush();\n    }\n    boolean judge(int min,boolean mod){\n        Arrays.fill(vis,0);\n        cycle=false;\n        for(int i=1;i<=n;i++){\n            if(vis[i]==0){\n                dfs(i,min,mod);\n                if(cycle)return false;\n            }\n        }\n        return true;\n    }\n    boolean cycle=false;\n    void dfs(int cur,int min,boolean mod){\n        if(cycle)return;\n        vis[cur]=1;\n        for(Edge e:edge[cur]){\n            if(e.c<=min){\n                if(mod)this.e[cnt++]=e;\n                continue;\n            }\n            if(vis[e.t]==1){\n                cycle=true;return;\n            }\n            else if(vis[e.t]==0)dfs(e.t,min,mod);\n        }\n        vis[cur]=2;\n        if(mod)order[cur]=ord++;\n    }\n}\nclass Edge{\n    int s,t,c,id;\n    Edge(int a,int b,int c,int d){\n        s=a;t=b;this.c=c;id=d;\n    }\n}\nclass 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 boolean hasNext() throws IOException {\n        int res=tokenizer.nextToken();\n        tokenizer.pushBack();\n        return res!=tokenizer.TT_EOF;\n    }\n}", "complexity": "nlogn", "problem": "1100_E. Andrew and Taxi", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class origami {\n\tpublic static void main(String args[]){\n\t\tScanner input = new Scanner(System.in);\n\t\tdouble n = input.nextInt();\n\t\tdouble k = input.nextInt();\n\t\tdouble red = 0;\n\t\tdouble green = 0;\n\t\tdouble blue = 0;\n\t\tdouble ans = 0;\n\t\tred = (2 * n) / k;\n\t\tgreen = (5 * n) / k;\n\t\tblue = (8 * n) / k;\n\n\t\tdouble red1 = Math.ceil(red) ;\n\t\tdouble green1 = Math.ceil(green);\n\t\tdouble blue1 = Math.ceil(blue);\n\n\t\tans+=red1;\n\t\tans+=green1;\n\t\tans+=blue1;\n\t\tDouble answer = new Double(ans);\n\t\tint finished = answer.intValue();\n\t\tSystem.out.println(finished);\n\t}\n}\n", "complexity": "constant", "problem": "1080_A. Petya and Origami", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    int[][] fast(int n, int m){\n\n        int[][] ans = new int[2][n * m];\n        int c = 0;\n\n        for (int left = 1, right = m; left < right; left++, right--) {\n            for (int l = 1, r = n; l <= n && r >= 1; l++, r--) {\n                ans[0][c] = l;\n                ans[1][c++] = left;\n\n                ans[0][c] = r;\n                ans[1][c++] = right;\n            }\n        }\n\n        if (m % 2 == 1) {\n            int x = m/2 + 1;\n            for(int l = 1, r = n;l < r;l++, r--){\n                ans[0][c] = l;\n                ans[1][c++] = x;\n\n                ans[0][c] = r;\n                ans[1][c++] = x;\n                    if(n % 2 == 1 && l + 2 == r){\n                        ans[0][c] = l+1;\n                        ans[1][c++] = x;\n                    }\n            }\n        }\n\n        if(n == 1 && m % 2 == 1){\n            ans[0][c] = 1;\n            ans[1][c] = m/2 + 1;\n        }\n\n        return ans;\n    }\n\n    void stress(){\n\n        for(int i = 3;i<=5;i++){\n            for(int j = 2;j<=5;j++){\n                int[][] ans = new int[2][];\n                try{\n                    ans = fast(i, j);\n                }catch(Exception e){\n                    out.println(\"\u043e\u0448\u0438\u0431\u043a\u0430\");\n                    out.print(i + \" \" + j);\n                    return;\n                }\n\n                boolean[][] check = new boolean[i][j];\n                for(int c = 0;c<ans[0].length;c++){\n                    int x = ans[0][c] - 1;\n                    int y = ans[1][c] - 1;\n                    check[x][y] = true;\n                }\n\n                for(int c = 0;c<i;c++){\n                    for(int q = 0;q<j;q++){\n                        if(!check[c][q]){\n                            out.println(i + \" \" + j);\n                            out.println(\"\u0442\u043e\u0447\u043a\u0438\");\n                            for(int w = 0;w<ans[0].length;w++){\n                                out.println(ans[0][w] + \" \" + ans[1][w]);\n                            }\n                            return;\n                        }\n                    }\n                }\n\n                HashSet<String> set = new HashSet<>();\n                for(int c = 1;c<ans[0].length;c++){\n                    int x = ans[0][c] - ans[0][c- 1];\n                    int y = ans[1][c] - ans[1][c - 1];\n                    set.add(x + \" \" + y);\n                }\n\n                if(set.size() < i * j - 1){\n                    out.println(i + \" \" + j);\n                    out.println(\"\u0432\u0435\u043a\u0442\u043e\u0440\u0430\");\n                    for(int w = 0;w<ans[0].length;w++){\n                        out.println(ans[0][w] + \" \" + ans[1][w]);\n                    }\n                    return;\n                }\n            }\n        }\n    }\n\n    void normal(){\n        int n =readInt();\n        int m = readInt();\n        int[][] ans = fast(n, m);\n        for(int i = 0;i<ans[0].length;i++){\n            out.println(ans[0][i] + \" \" + ans[1][i]);\n        }\n    }\n\n    boolean stress = false;\n    void solve(){\n        if(stress) stress();\n        else normal();\n    }\n\n    public static void main(String[] args) {\n        new D().run();\n    }\n\n    void run(){\n        init();\n        solve();\n        out.close();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init(){\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out  = new PrintWriter(System.out);\n    }\n\n    String readLine(){\n        try{\n            return in.readLine();\n        }catch(Exception ex){\n            throw new RuntimeException(ex);\n        }\n    }\n    String readString(){\n        while(!tok.hasMoreTokens()){\n            String nextLine = readLine();\n            if(nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt(){\n        return Integer.parseInt(readString());\n    }\n\n    long readLong(){\n        return Long.parseLong(readString());\n    }\n\n    double readDouble(){\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n \n \npublic class Main {\n\t\n\tstatic InputReader in = new InputReader(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic long oo = 1000000000000L;\n\t\n\tpublic static void main(String[] args) throws IOException {\n \n\t\tint n = in.nextInt();\n\t\tint q = in.nextInt();\n\t\t\n\t\tArrayDeque<Integer> dq = new ArrayDeque<>();\n\t\tint max = -1;\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tdq.add(x);\n\t\t\tmax = Math.max(max, x);\n\t\t}\n\t\tArrayList<Pair> ans = new ArrayList<>();\n\t\twhile(dq.peekFirst() != max) {\n\t\t\tint a = dq.pollFirst();\n\t\t\tint b = dq.pollFirst();\n\t\t\tans.add(new Pair(a, b));\n\t\t\tif(a > b) {\n\t\t\t\tdq.addFirst(a);\n\t\t\t\tdq.addLast(b);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdq.addFirst(b);\n\t\t\t\tdq.addLast(a);\n\t\t\t}\n\t\t}\n\t\tArrayList<Integer> a = new ArrayList<>();\n\t\tdq.pollFirst();\n\t\tfor(int x : dq)\n\t\t\ta.add(x);\n\t\twhile(q --> 0) {\n\t\t\tlong m = in.nextLong() - 1;\n\t\t\tif(m < ans.size()) {\n\t\t\t\tSystem.out.println(ans.get((int)m).first + \" \" + ans.get((int)m).second);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint idx = (int)((m - ans.size()) % a.size());\n\t\t\t\tSystem.out.println(max + \" \" + a.get(idx));\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\t\n\t\n\tstatic long lcm(long a, long b) {\n\t\treturn a * b / gcd(a, b);\n\t}\n\t\n\tstatic boolean nextPermutation(int[] a) {\n\t\tfor(int i = a.length - 2; i >= 0; --i) {\n\t\t\tif(a[i] < a[i+1]) {\n\t\t\t\tfor(int j = a.length - 1; ; --j) {\n\t\t\t\t\tif(a[i] < a[j]) {\n\t\t\t\t\t\tint t = a[i];\n\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\tfor(i++, j = a.length - 1; i < j; ++i, --j) {\n\t\t\t\t\t\t\tt = a[i];\n\t\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\t\n\tstatic void shuffle(int[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tint t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic void shuffle(long[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tlong t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic int lower_bound(int[] a, int n, int k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\tstatic int lower_bound(long[] a, int n, long k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\t\n\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\tstatic long gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\t\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint first, second;\n \n\t\tpublic Pair(int first, int second) {\n\t\t\tsuper();\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn this.first != o.first ? this.first - o.first : this.second - o.second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + first;\n\t\t\tresult = prime * result + second;\n\t\t\treturn result;\n\t\t}\n \n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tPair other = (Pair) obj;\n\t\t\tif (first != other.first)\n\t\t\t\treturn false;\n\t\t\tif (second != other.second)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t}\n\t\n\t\n}\n \n \n \nclass InputReader {\n \n\tprivate final InputStream stream;\n\tprivate final byte[] buf = new byte[8192];\n\tprivate int curChar, snumChars;\n \n\tpublic InputReader(InputStream st) {\n\t\tthis.stream = st;\n\t}\n \n\tpublic int read() {\n\t\tif (snumChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= snumChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (snumChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n \n\tpublic int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n \n\tpublic long nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n \n\tpublic int[] nextIntArray(int n) {\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\treturn a;\n\t}\n \n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n \n\tprivate boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n \n}", "complexity": "linear", "problem": "1180_C. Valeriy and Deque", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class C {\n\n    void solve(){\n       int n = readInt();\n       int q = readInt();\n       int max = 0;\n       int[] a = new int[n];\n       Deque<Integer> deque = new ArrayDeque<>();\n       for(int i = 0;i<n;i++){\n           a[i] = readInt();\n           deque.addLast(a[i]);\n           max = Math.max(max, a[i]);\n       }\n        List<String> ans = new ArrayList<>();\n        while(deque.peekFirst() != max){\n           int one = deque.pollFirst();\n           int two = deque.pollFirst();\n           ans.add(one + \" \" + two);\n           deque.addFirst(one > two ? one : two);\n           deque.addLast(one > two ? two : one);\n           if(one == max) break;\n       }\n\n       for(int i = 0;i<n;i++){\n           a[i] = deque.pollFirst();\n       }\n\n       for(int i = 0;i<q;i++){\n          long x = readLong();\n           if(x <= ans.size()){\n               out.println(ans.get((int)x - 1));\n               continue;\n           }\n           x -= ans.size();\n           int y =(int) (x%(n - 1) - 1%(n - 1) + (n - 1)) % (n - 1) + 1;\n           out.println(max + \" \" + a[y]);\n       }\n    }\n\n    public static void main(String[] args) {\n        new C().run();\n    }\n\n    void run(){\n        init();\n        solve();\n        out.close();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init(){\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out  = new PrintWriter(System.out);\n    }\n\n    String readLine(){\n        try{\n            return in.readLine();\n        }catch(Exception ex){\n            throw new RuntimeException(ex);\n        }\n    }\n    String readString(){\n        while(!tok.hasMoreTokens()){\n            String nextLine = readLine();\n            if(nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt(){\n        return Integer.parseInt(readString());\n    }\n\n    long readLong(){\n        return Long.parseLong(readString());\n    }\n\n    double readDouble(){\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "linear", "problem": "1180_C. Valeriy and Deque", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1082D {\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[] aa = new int[n];\n\t\tint[] i1 = new int[n];\n\t\tint[] i2 = new int[n];\n\t\tint n1 = 0, n2 = 0, m2 = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = Integer.parseInt(st.nextToken());\n\t\t\taa[i] = a;\n\t\t\tif (a == 1)\n\t\t\t\ti1[n1++] = i;\n\t\t\telse {\n\t\t\t\ti2[n2++] = i;\n\t\t\t\tm2 += a;\n\t\t\t}\n\t\t}\n\t\tif (m2 < (n2 - 1) * 2 + n1) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tint m = n2 - 1 + n1;\n\t\tint d = n2 - 1 + Math.min(n1, 2);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(\"YES \" + d);\n\t\tpw.println(m);\n\t\tfor (int i = 0; i + 1 < n2; i++) {\n\t\t\tpw.println((i2[i] + 1) + \" \" + (i2[i + 1] + 1));\n\t\t\taa[i2[i]]--; aa[i2[i + 1]]--;\n\t\t}\n\t\tif (n1 > 0) {\n\t\t\twhile (n2 > 0 && aa[i2[n2 - 1]] == 0)\n\t\t\t\tn2--;\n\t\t\tpw.println((i2[n2 - 1] + 1) + \" \" + (i1[n1 - 1] + 1));\n\t\t\taa[i2[n2 - 1]]--;\n\t\t\tn1--;\n\t\t}\n\t\tfor (int i = 0, j = 0; j < n1; j++) {\n\t\t\twhile (aa[i2[i]] == 0)\n\t\t\t\ti++;\n\t\t\tpw.println((i2[i] + 1) + \" \" + (i1[j] + 1));\n\t\t\taa[i2[i]]--;\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "linear", "problem": "1082_D. Maximum Diameter Graph", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\nimport java.util.Stack;\npublic class D527A2 {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tint N = in.nextInt();\n\t\tStack<Integer> stack = new Stack<>();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint num = in.nextInt() % 2;\n\t\t\tif(stack.size() >= 1 && stack.lastElement() == num)\n\t\t\t\tstack.pop();\n\t\t\telse\n\t\t\t\tstack.add(num);\n\t\t}\n\t\t\n\t\tSystem.out.println(stack.size() <= 1 ? \"YES\" : \"NO\");\n\t}\n\t\n\t/**\n\t * Source: Matt Fontaine\n\t */\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 chars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tint read() {\n\t\t\tif (chars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= chars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tchars = 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 (chars <= 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\t}\n\n}\n/*\n5\n2 1 1 2 5\noutputCopy\nYES\ninputCopy\n3\n4 5 3\noutputCopy\nYES\ninputCopy\n2\n10 10\noutputCopy\nYES\ninputCopy\n3\n1 2 3\noutputCopy\nNO\n\n5\n2 3 2 2 3\n\nYES\n*/", "complexity": "linear", "problem": "1092_D1. Great Vova Wall (Version 1)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class tr {\n\tstatic int[][] ad;\n    static boolean []vis;\n    static int []goods;\n    static int[][]sol;\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\tint max=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=sc.nextInt();\n\t\tStack<Integer> s=new Stack<>();\n\t\tboolean f=true;\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tmax=Math.max(max,a[i]);\n\t\t\t\t\tif(!s.isEmpty() && a[i]>s.peek())\n\t\t\t\t\t\tf=false;\n\t\t\t\t\ts.push(a[i]);\n\t\t\t\t\twhile(!s.isEmpty()) {\n\t\t\t\t\t\tint high=s.pop();\n\t\t\t\t\t\tif(s.isEmpty() || s.peek()!=high) {\n\t\t\t\t\t\t\ts.push(high);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ts.pop();\n\t\t\t\t\t}\n\t\t\t\t//\tSystem.out.println(s+\" \"+max);\n\t\t\t\t}\n\t\t\t\t//System.out.println(f+\" \"+max);\n\t\t\t\tif(f && s.size()==0)\n\t\t\t\t\tout.println(\"YES\");\n\t\t\t\telse if(f && s.size()==1 && s.peek()==max)\n\t\t\t\t\tout.println(\"YES\");\n\t\t\t\telse\n\t\t\t\t\tout.println(\"NO\");\n\t\t out.flush();\n\t}\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 pair implements Comparable<pair> {\n\t\tint a;\n\t\tint b;\n\n\t\tpair(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn a + \" \" + b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\t\t\treturn  o.a-a ;\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}", "complexity": "linear", "problem": "1092_D1. Great Vova Wall (Version 1)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Equator {\n\tpublic static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static StringTokenizer st;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = intArray(n);\n\t\t\n\t\tlong s = 0;\n\t\tfor (int x : a)\n\t\t\ts += x;\n\t\t\n\t\tlong m = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tm += a[i];\n\t\t\tif (m*2 >= s) {\n\t\t\t\tSystem.out.println(i+1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static String nextLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n\n\tpublic static String nextString() 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\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static int[] intArray(int n) throws IOException {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextInt();\n\t\treturn a;\n\t}\n\n\tpublic static int[][] intArray(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\n\tpublic static long[] longArray(int n) throws IOException {\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}", "complexity": "linear", "problem": "962_A. Equator", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class LectureSleep {\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        public float nextFloat() {\n            return Float.parseFloat(next());\n        }\n\n    }\n\n    static InputReader r = new InputReader(System.in);\n    static PrintWriter pw = new PrintWriter(System.out);\n\n\n    public static void main(String[] args) {\n        int n = r.nextInt(); // duration of lecture\n        int k = r.nextInt(); // number of minutes keep mishka awake\n        int[] theorems = new int[n+1];\n        for(int i = 1; i <= n; i++){\n            theorems[i] = r.nextInt();\n        }\n        int[] mishka = new int[n+1];\n        for(int i = 1; i <= n; i++){\n            mishka[i] = r.nextInt();\n        }\n        int[] sums = new int[n+1];\n        for(int i = 1; i <= n; i++){\n            if(mishka[i] == 0){\n                sums[i] = sums[i-1] + theorems[i];\n            } else{\n                sums[i] = sums[i-1];\n            }\n        }\n        int max = 0;\n        for(int i = 1; i <= n-k+1; i++){\n            int sum = sums[i+k-1] - sums[i-1];\n            max = Math.max(max, sum);\n        }\n        int totalSum = 0;\n        for(int i = 1; i <= n; i++){\n            if(mishka[i] == 1){\n                totalSum += theorems[i];\n            }\n        }\n\n        pw.println(totalSum + max);\n\n        pw.close();\n    }\n}", "complexity": "linear", "problem": "961_B. Lecture Sleep", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: Dec 5, 2010\n * Time: 4:09:41 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class HamstersTigers {\n    private BufferedReader in;\n    private PrintWriter out;\n    private StringTokenizer st;\n\n\tint solve(String a, int k){\n\t\tint n = a.length(), ret = 0;\n\t\tint temp[] = new int[n];\n\t\tfor(int i = 0; i < n; i++) temp[(n + i - k) % n] = (a.charAt(i) == 'T') ? 1: 0;\n\t\tint left = 0, right = n - 1;\n\t\twhile(left < right){\n\t\t\twhile(temp[left] == 0) left++;\n\t\t\twhile(temp[right] == 1) right--;\n\t\t\tif(left < right){\n\t\t\t\tint t = temp[left];\n\t\t\t\ttemp[left] = temp[right];\n\t\t\t\ttemp[right] = t;\n\t\t\t\tret++;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\n    void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tString a = next();\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor(int fix = 0; fix < n; fix++){\n\t\t\tans = Math.min(ans, solve(a, fix));\n\t\t}\n\t\tout.println(ans);\n    }\n\n    HamstersTigers() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        //in  = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"C://Users/piyushd/Desktop/codeforces/sample.txt\"))));\n        out = new PrintWriter(System.out);\n\n        eat(\"\");\n\n        solve();\n\n        in.close();\n        out.close();\n    }\n\n    private void eat(String str) {\n        st = new StringTokenizer(str);\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 HamstersTigers();\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tScanner in;\n\tPrintWriter out;\n\tStreamTokenizer ST;\n\tBufferedReader br;\n\n\tint nextInt() throws IOException {\n\t\tST.nextToken();\n\t\treturn (int) ST.nval;\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\tST.nextToken();\n\t\treturn ST.nval;\n\t}\n\n\tString next() throws IOException {\n\t\tST.nextToken();\n\t\treturn ST.sval;\n\t}\n\n\tString nextLine() throws IOException {\n\t\treturn br.readLine();\n\t}\n\n\tvoid solve() throws IOException {\n\t\tbr.readLine();\n\t\tchar[]s = br.readLine().toCharArray();\n\t\tint n = s.length;\n\t\tint h=0;\n\t\tfor(int i=0;i<n;++i)if (s[i]=='H')++h;\n\t\tint res=1000000;\n\t\tfor(int i=0;i<n;++i)\n\t\t{\n\t\t\tint t=0;\n\t\t\tfor(int j=0;j<h;++j)\n\t\t\t{\n\t\t\t\tif (s[(i+j)%n]=='T')++t;\n\t\t\t}\n\t\t\tres=Math.min(res,t);\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tpublic void run() throws IOException {\n\t\t// br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tST = new StreamTokenizer(br);\n\t\tin = new Scanner(br);\n\t\tout = new PrintWriter(System.out);\n\t\t// out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n\t\tsolve();\n\t\tin.close();\n\t\tout.close();\n\t\tbr.close();\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.FileNotFoundException;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main\n{\n    static final double eps=1e-10;\n    public static void main(String[] args) throws FileNotFoundException\n    {\n        new Main().solve();\n    }\n    public void solve() throws FileNotFoundException\n    {\n        Scanner cin=new Scanner(System.in);\n        int n;\n        n=cin.nextInt();\n        String s;\n        s=cin.next();\n        int ans=Integer.MAX_VALUE;\n        int h=0,t=0;\n        for(int i=0;i<s.length();i++)\n        {\n            if(s.charAt(i)=='H')\n                h++;\n            else if(s.charAt(i)=='T')\n                t++;\n        }\n        ans=Math.min(ans,fun(s,'H',h));\n        ans=Math.min(ans,fun(s,'T',t));\n        System.out.println(ans);\n    }\n    public int fun(String s,char c,int num)\n    {\n        int ans=Integer.MAX_VALUE;\n        int ret=num;\n        for(int i=0;i<num;i++)\n        {\n            if(s.charAt(i)==c)\n            {\n                ret--;\n            }\n        }\n        ans=ret;\n        for(int i=0;i+num<s.length();i++)\n        {\n            if(s.charAt(i)!=c)\n                ret--;\n            if(s.charAt(i+num)!=c)\n            {\n                ret++;\n            }\n            ans=Math.min(ans, ret);\n        }\n        return ans;\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\t\n\tInputStreamReader  inp = new InputStreamReader(System.in);\n\tBufferedReader in = new BufferedReader(inp);\n\tboolean test = false;\n\n\tString[] inData = { \"9\",\n\"HTHTHTHHT\",\n\t\t};\n\n\tstatic int id = -1;\n\tpublic String readLine() throws IOException {\n\t\tid++;\n\t\tif(test)\n\t\t\treturn inData[id];\n\t\telse\n\t\t\treturn in.readLine();\n\t}\n\t\n\t\n\tpublic Main() throws Throwable {\n\t\t\n\t\tint animalNr = Integer.valueOf(readLine());\n\t\tString animals = readLine();\n\t\t\n\t\tboolean[] state = new boolean[animalNr];\n\t\tint tigerCount = 0;\n\t\tfor (int i = 0; i < animals.length(); i++) {\n\t\t\tif('T' == animals.charAt(i)){\n\t\t\t\tstate[i] = true;\n\t\t\t\ttigerCount++;\n\t\t\t}\n\t\t}\n\t\tint best = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < state.length; i++) {\n\t\t\tint swaps = 0;\n\t\t\tfor (int j = i; j < i+tigerCount; j++) {\n\t\t\t\tif(state[j %animalNr] == false){\n\t\t\t\t\tswaps ++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(swaps < best){\n\t\t\t\tbest = swaps;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(best);\n\t\t\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tnew Main();\n\t}\n}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.* ;\nimport java.io.* ;\nimport java.math.* ;\n/************************\n *                      *\n *    Lord Klotski      *\n *                      *\n ***********************/\npublic class C\n{\n    static int[] arr ; static int L ;\n    public static void rotate()\n    {\n        int tmp = arr[0] ;\n        for (int i = 1 ; i < L ; i ++)\n            arr[i-1] = arr[i] ;\n        arr[L-1] = tmp ;\n    }\n\n    public static void main(String[] args)\n    {\n        Scanner input = new Scanner(System.in) ;\n\n        L = input.nextInt() ; String s = input.next() ;\n        arr = new int[L]; for (int i = 0 ; i < L ; i ++) {arr[i] = s.charAt(i) == 'H' ? 1 : 0 ;}\n\n        // want to find longest sequence of 1s\n        // then rotate to head\n        int count = 99999 ;\n        for (int A = 0; A < L ; A ++)\n        {\n            int[] tmp = new int[L] ; System.arraycopy(arr, 0, tmp, 0, arr.length);\n            int ans = 0 ;\n            for (int i = 0 ; i < L ; i ++)\n            {\n                if (tmp[i] == 1) continue ;\n                for (int j = L-1 ; j > i ; j --)\n                {\n                    if (tmp[j] == 0) continue ;\n                    ans ++ ;\n                    tmp[i] = 1 ; tmp[j] = 0 ;\n                    //System.out.println(\"SWAP \" + i + \" \" + j);\n                    //for (int k = 0 ; k < L ; k ++)\n                    //    System.out.print(arr[k]);\n                    //System.out.println(\"\");\n                    break;\n                }\n            }\n            count = Math.min(count,ans) ;\n            rotate() ;\n        }\n        // rotate until j is at the front\n        System.out.println(count);\n\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class C {\n    public static void main(String[] args)\n    {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        char[] s = new char[n];\n        String line = in.next();\n        int ct=0,ht=0;\n        for(int i=0;i<n;i++) //count animals\n            if(line.charAt(i)=='T')\n                ct++;\n            else\n                ht++;\n        \n        int cnt = 1000000000;\n        int[] c = new int[2];\n        char[] cc = new char[2];\n        if(ct<ht)\n        {\n            c[0] = ct;\n            c[1] = ht;\n            cc[0] = 'T';\n            cc[1] = 'H';\n        }else{\n            c[0] = ht;\n            c[1] = ct;\n            cc[0] = 'H';\n            cc[1] = 'T';\n        }\n        \n        for(int i=0;i<n;i++)\n        {\n            int ptr = i;\n            for(int j=0;j<c[0];j++) //fill First\n            {\n                s[ptr] = cc[0];\n                ptr = (ptr+1)%n;\n            }\n            for(int j=0;j<c[1];j++) //fill Second\n            {\n                s[ptr] = cc[1];\n                ptr = (ptr+1)%n;\n            }\n            //check\n            int ch = 0;\n            for(int j=0;j<n;j++) //difference\n                if(s[j]!=line.charAt(j)&&s[j]==cc[0])\n                    ch++;\n            cnt = Math.min(cnt,ch);\n        }\n        \n        System.out.print(cnt);\n    }\n}\n\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class B {\n    private static StreamTokenizer in;\n    private static PrintWriter out;\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        out = new PrintWriter(System.out);\n    }\n    \n    public static void main(String[] args)throws Exception{\n        int n = nextInt();\n        char[] c = nextString().toCharArray();\n        \n        int tc = 0, hc = 0;\n        for(int i = 0;i<c.length; i++){\n            if(c[i] == 'T')tc++; else hc++;\n        }\n//      char g = 'T';\n//      if(tc > hc){\n//          tc = hc;\n//          g = 'H';\n//      }\n        \n        int max = -1;\n        int pos = 0;\n        for(int i = 0; i<c.length; i++){\n            int a = 0;\n            for(int j = 0; j<tc;j++){\n                int k = i+j;\n                if(k>=n)k-=n;\n                if(c[k] == 'T'){\n                    a++;\n                }\n            }\n            if(a>max){\n                max = a;\n                pos = i;\n            }\n        }\n        int min1 = tc - max;\n        \n        max = -1;\n        pos = 0;\n        for(int i = 0; i<c.length; i++){\n            int a = 0;\n            for(int j = 0; j<hc;j++){\n                int k = i+j;\n                if(k>=n)k-=n;\n                if(c[k] == 'H'){\n                    a++;\n                }\n            }\n            if(a>max){\n                max = a;\n                pos = i;\n            }\n        }\n        int min2 = hc - max;\n        \n        out.println(Math.min(min1, min2));\n        out.flush();\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Tsk1 {\n    static void metod() throws Exception {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        String s = in.next();\n        String ss = s + s;\n        int t = 0;\n        for (int i = 0; i < n; i++) {\n            if (s.charAt(i) == 'T') {\n                t++;\n            }\n        }\n        if (t == 1 || t == n - 1) {\n            System.out.println(0);\n        } else {\n            int sum = 0;\n            for (int i = 0; i < t; i++) {\n                if (s.charAt(i) == 'T') {\n                    sum++;\n                }\n            }\n            \n            int max = sum;\n            for (int i = 0; i < s.length(); i++) {\n                if (ss.charAt(i) == 'T') {\n                    if (ss.charAt(i + t) == 'H') {\n                        sum--;\n                    }\n                } else {\n                    if (ss.charAt(i + t) == 'T') {\n                        sum++;\n                        max = Math.max(max, sum);\n                    }\n                }\n            }\n            System.out.println(t - max);\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        Tsk1.metod();\n    }\n}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(new InputStreamReader(System.in));\n        int n = sc.nextInt();\n        String s = sc.next();\n        sc.close();\n        \n        int cH = 0;\n        for (int i=0; i < s.length(); i++)\n            if (s.charAt(i) == 'H')\n                cH++;\n        \n        int best = cH;\n        \n        for (int st=0; st < s.length(); st++) {\n            int cur = st;\n            int cnt = cH;\n            for (int i=0; i < cH; i++) {\n                if (s.charAt(cur) == 'H')\n                    cnt--;\n                cur++;\n                if (cur == s.length()) cur = 0;\n            }\n            best = Math.min(best, cnt);\n        }\n        \n        System.out.println(best);\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "/*\n * Hello! You are trying to hack my solution, are you? =)\n * Don't be afraid of the size, it's just a dump of useful methods like gcd, or n-th Fib number.\n * And I'm just too lazy to create a new .java for every task.\n * And if you were successful to hack my solution, please, send me this test as a message or to Abrackadabraa@gmail.com.\n * It can help me improve my skills and i'd be very grateful for that.\n * Sorry for time you spent reading this message. =)\n * Good luck, unknown rival. =)\n * */\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Abra {\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tbr.readLine();\n\t\tint h = 0, t = 0;\n\t\tString s = br.readLine();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((char)s.charAt(i) == 'H') h++; else t++;\n\t\t}\n\t\tint m = 10001;\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tint z = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i + 1 <= h) {\n\t\t\t\t\tif (s.charAt((i + j) % n) != 'H') z++;\n\t\t\t\t} else {\n\t\t\t\t\tif (s.charAt((i + j) % n) != 'T') z++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (z < m) m = z;\n\t\t}\n\t\tout.println(m / 2);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Abra().run();\n\t}\n\t\n\n\tstatic class myLib {\n\t\tlong fact(long x) {\n\t\t\tlong a = 1;\n\t\t\tfor (long i = 2; i <= x; i++) {\n\t\t\t\ta *= i;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitSum(String x) {\n\t\t\tlong a = 0;\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\ta += x.charAt(i) - '0';\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitSum(long x) {\n\t\t\tlong a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitMul(long x) {\n\t\t\tlong a = 1;\n\t\t\twhile (x > 0) {\n\t\t\t\ta *= x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint digitCubesSum(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += (x % 10) * (x % 10) * (x % 10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble pif(double ax, double ay, double bx, double by) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n\t\t}\n\n\t\tdouble pif3D(double ax, double ay, double az, double bx, double by, double bz) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by) + (az - bz) * (az - bz));\n\t\t}\n\n\t\tdouble pif3D(double[] a, double[] b) {\n\t\t\treturn Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));\n\t\t}\n\n\t\tlong gcd(long a, long b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tlong c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tlong c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint gcd(int a, int b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tint c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tint c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tlong lcm(long a, long b) 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<Integer> t = new Vector<Integer>();\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<Integer> iterator = t.iterator();\n\t\t\tfor (int i = 0; iterator.hasNext(); i++) {\n\t\t\t\tprimes[i] = iterator.next().intValue();\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint rev(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta = a * 10 + x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tclass myDate {\n\t\t\tint d, m, y;\n\n\t\t\tint[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n\t\t\tpublic myDate(int da, int ma, int ya) {\n\t\t\t\td = da;\n\t\t\t\tm = ma;\n\t\t\t\ty = ya;\n\t\t\t\tif ((ma > 12 || ma < 1 || da > ml[ma - 1] || da < 1) && !(d == 29 && m == 2 && y % 4 == 0)) {\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t\ty = 9999999;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid incYear(int x) {\n\t\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\t\ty++;\n\t\t\t\t\tif (m == 2 && d == 29) {\n\t\t\t\t\t\tm = 3;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (m == 3 && d == 1) {\n\t\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\t\tm = 2;\n\t\t\t\t\t\t\td = 29;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tboolean less(myDate x) {\n\t\t\t\tif (y < x.y) return true;\n\t\t\t\tif (y > x.y) return false;\n\t\t\t\tif (m < x.m) return true;\n\t\t\t\tif (m > x.m) return false;\n\t\t\t\tif (d < x.d) return true;\n\t\t\t\tif (d > x.d) return false;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tvoid inc() {\n\t\t\t\tif ((d == 31) && (m == 12)) {\n\t\t\t\t\ty++;\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\tml[1] = 29;\n\t\t\t\t\t}\n\t\t\t\t\tif (d == ml[m - 1]) {\n\t\t\t\t\t\tm++;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t} else\n\t\t\t\t\t\td++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint partition(int n, int l, int m) {// n - sum, l - length, m - every\n\t\t\t\t\t\t\t\t\t\t\t// part\n\t\t\t// <= m\n\t\t\tif (n < l) return 0;\n\t\t\tif (n < l + 2) return 1;\n\t\t\tif (l == 1) return 1;\n\t\t\tint c = 0;\n\t\t\tfor (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n\t\t\t\tc += partition(n - i, l - 1, i);\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint rifmQuality(String a, String b) {\n\t\t\tif (a.length() > b.length()) {\n\t\t\t\tString c = a;\n\t\t\t\ta = b;\n\t\t\t\tb = c;\n\t\t\t}\n\t\t\tint c = 0, d = b.length() - a.length();\n\t\t\tfor (int i = a.length() - 1; i >= 0; i--) {\n\t\t\t\tif (a.charAt(i) == b.charAt(i + d)) c++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tString numSym = \"0123456789ABCDEF\";\n\n\t\tString ZFromXToYNotation(int x, int y, String z) {\n\t\t\tif (z.equals(\"0\")) return \"0\";\n\t\t\tString a = \"\";\n\t\t\t// long q = 0, t = 1;\n\t\t\tBigInteger q = BigInteger.ZERO, t = BigInteger.ONE;\n\t\t\tfor (int i = z.length() - 1; i >= 0; i--) {\n\t\t\t\tq = q.add(t.multiply(BigInteger.valueOf(z.charAt(i) - 48)));\n\t\t\t\tt = t.multiply(BigInteger.valueOf(x));\n\t\t\t}\n\t\t\twhile (q.compareTo(BigInteger.ZERO) == 1) {\n\t\t\t\ta = numSym.charAt((int) (q.mod(BigInteger.valueOf(y)).intValue())) + a;\n\t\t\t\tq = q.divide(BigInteger.valueOf(y));\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble angleFromXY(int x, int y) {\n\t\t\tif ((x == 0) && (y > 0)) return Math.PI / 2;\n\t\t\tif ((x == 0) && (y < 0)) return -Math.PI / 2;\n\t\t\tif ((y == 0) && (x > 0)) return 0;\n\t\t\tif ((y == 0) && (x < 0)) return Math.PI;\n\t\t\tif (x > 0) return Math.atan((double) y / x);\n\t\t\telse {\n\t\t\t\tif (y > 0) return Math.atan((double) y / x) + Math.PI;\n\t\t\t\telse\n\t\t\t\t\treturn Math.atan((double) y / x) - Math.PI;\n\t\t\t}\n\t\t}\n\n\t\tstatic boolean isNumber(String x) {\n\t\t\ttry {\n\t\t\t\tInteger.parseInt(x);\n\t\t\t} catch (NumberFormatException ex) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tstatic boolean stringContainsOf(String x, String c) {\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\tif (c.indexOf(x.charAt(i)) == -1) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tlong pow(long a, long n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tlong k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint pow(int a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tint k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble pow(double a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tdouble k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble log2(double x) {\n\t\t\treturn Math.log(x) / Math.log(2);\n\t\t}\n\n\t\tint lpd(int[] primes, int x) {// least prime divisor\n\t\t\tint i;\n\t\t\tfor (i = 0; primes[i] <= x / 2; i++) {\n\t\t\t\tif (x % primes[i] == 0) {\n\t\t\t\t\treturn primes[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t;\n\t\t\treturn x;\n\t\t}\n\n\t\tint np(int[] primes, int x) {// number of prime number\n\t\t\tfor (int i = 0; true; i++) {\n\t\t\t\tif (primes[i] == x) return i;\n\t\t\t}\n\t\t}\n\n\t\tint[] dijkstra(int[][] map, int n, int s) {\n\t\t\tint[] p = new int[n];\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tArrays.fill(p, Integer.MAX_VALUE);\n\t\t\tp[s] = 0;\n\t\t\tb[s] = true;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i != s) p[i] = map[s][i];\n\t\t\t}\n\t\t\twhile (true) {\n\t\t\t\tint m = Integer.MAX_VALUE, mi = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (!b[i] && (p[i] < m)) {\n\t\t\t\t\t\tmi = i;\n\t\t\t\t\t\tm = p[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (mi == -1) break;\n\t\t\t\tb[mi] = true;\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif (p[mi] + map[mi][i] < p[i]) p[i] = p[mi] + map[mi][i];\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\n\t\tboolean isLatinChar(char x) {\n\t\t\tif (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z'))) return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isBigLatinChar(char x) {\n\t\t\tif (x >= 'A' && x <= 'Z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isSmallLatinChar(char x) {\n\t\t\tif (x >= 'a' && x <= 'z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isDigitChar(char x) {\n\t\t\tif (x >= '0' && x <= '9') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tclass NotANumberException extends Exception {\n\t\t\tprivate static final long serialVersionUID = 1L;\n\t\t\tString mistake;\n\n\t\t\tNotANumberException() {\n\t\t\t\tmistake = \"Unknown.\";\n\t\t\t}\n\n\t\t\tNotANumberException(String message) {\n\t\t\t\tmistake = message;\n\t\t\t}\n\t\t}\n\n\t\tclass Real {\n\t\t\tString num = \"0\";\n\t\t\tlong exp = 0;\n\t\t\tboolean pos = true;\n\n\t\t\tlong length() {\n\t\t\t\treturn num.length();\n\t\t\t}\n\n\t\t\tvoid check(String x) throws NotANumberException {\n\t\t\t\tif (!stringContainsOf(x, \"0123456789+-.eE\")) throw new NotANumberException(\"Illegal character.\");\n\t\t\t\tlong j = 0;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif ((x.charAt((int) i) == '-') || (x.charAt((int) i) == '+')) {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected sign.\");\n\t\t\t\t\t} else\n\t\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\t\tif (j == 0) j = 2;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (j == 1) j = 2;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 2)\n\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 3) j = 4;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tif (j == 4)\n\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (j == 6)\n\t\t\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected digit.\");\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\t\t\tif (j == 0) j = 3;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 1) j = 3;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 2) j = 3;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected dot.\");\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\t\t\t\tif (j == 2) j = 5;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 4) j = 5;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected exponent.\");\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"O_o.\");\n\t\t\t\t}\n\t\t\t\tif ((j == 0) || (j == 1) || (j == 3) || (j == 5)) throw new NotANumberException(\"Unexpected end.\");\n\t\t\t}\n\n\t\t\tpublic Real(String x) throws NotANumberException {\n\t\t\t\tcheck(x);\n\t\t\t\tif (x.charAt(0) == '-') pos = false;\n\t\t\t\tlong j = 0;\n\t\t\t\tString e = \"\";\n\t\t\t\tboolean epos = true;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\tif (j == 0) num += x.charAt((int) i);\n\t\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\t\tnum += x.charAt((int) i);\n\t\t\t\t\t\t\texp--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (j == 2) e += x.charAt((int) i);\n\t\t\t\t\t}\n\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\tj = 2;\n\t\t\t\t\t\tif (x.charAt((int) (i + 1)) == '-') epos = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(0) == '0'))\n\t\t\t\t\tnum = num.substring(1);\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(num.length() - 1) == '0')) {\n\t\t\t\t\tnum = num.substring(0, num.length() - 1);\n\t\t\t\t\texp++;\n\t\t\t\t}\n\t\t\t\tif (num.equals(\"0\")) {\n\t\t\t\t\texp = 0;\n\t\t\t\t\tpos = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\twhile ((e.length() > 1) && (e.charAt(0) == '0'))\n\t\t\t\t\te = e.substring(1);\n\t\t\t\ttry {\n\t\t\t\t\tif (e != \"\") if (epos) exp += Long.parseLong(e);\n\t\t\t\t\telse\n\t\t\t\t\t\texp -= Long.parseLong(e);\n\t\t\t\t} catch (NumberFormatException exc) {\n\t\t\t\t\tif (!epos) {\n\t\t\t\t\t\tnum = \"0\";\n\t\t\t\t\t\texp = 0;\n\t\t\t\t\t\tpos = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new NotANumberException(\"Too long exponent\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic Real() {\n\t\t\t}\n\n\t\t\tString toString(long mantissa) {\n\t\t\t\tString a = \"\", b = \"\";\n\t\t\t\tif (exp >= 0) {\n\t\t\t\t\ta = num;\n\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\tfor (long i = 0; i < exp; i++)\n\t\t\t\t\t\ta += '0';\n\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\tb += '0';\n\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t} else {\n\t\t\t\t\tif (exp + length() <= 0) {\n\t\t\t\t\t\ta = \"0\";\n\t\t\t\t\t\tif (mantissa == 0) {\n\t\t\t\t\t\t\treturn a;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (mantissa < -(exp + length() - 1)) {\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tif (i < -(exp + length())) b += '0';\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (i + exp >= 0) b += '0';\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tb += num.charAt((int) (i + exp + length()));\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!pos) a = \"-\";\n\t\t\t\t\t\tfor (long i = 0; i < exp + length(); i++)\n\t\t\t\t\t\t\ta += num.charAt((int) i);\n\t\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\t\tfor (long i = exp + length(); i < exp + length() + mantissa; i++)\n\t\t\t\t\t\t\tif (i < length()) b += num.charAt((int) i);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tboolean containsRepeats(int... num) {\n\t\t\tSet<Integer> s = new TreeSet<Integer>();\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\tdouble maxD(double... a) {\n\t\t\tdouble c = Double.MIN_VALUE;\n\t\t\tfor (double d : a)\n\t\t\t\tif (d > c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tdouble minD(double... a) {\n\t\t\tdouble c = Double.MAX_VALUE;\n\t\t\tfor (double d : a)\n\t\t\t\tif (d < c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint[] normalizeDice(int[] a) {\n\t\t\tint[] c = a.clone();\n\t\t\tif (c[0] != 0) if (c[1] == 0) c = rotateDice(c, 0);\n\t\t\telse\n\t\t\t\tif (c[2] == 0) c = rotateDice(c, 1);\n\t\t\t\telse\n\t\t\t\t\tif (c[3] == 0) c = rotateDice(c, 2);\n\t\t\t\t\telse\n\t\t\t\t\t\tif (c[4] == 0) c = rotateDice(c, 3);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (c[5] == 0) c = rotateDice(rotateDice(c, 0), 0);\n\t\t\twhile (c[1] != min(c[1], c[2], c[3], c[4]))\n\t\t\t\tc = rotateDice(c, 4);\n\t\t\treturn c;\n\t\t}\n\n\t\tboolean sameDice(int[] a, int[] b) {\n\t\t\tfor (int i = 0; i < 6; i++)\n\t\t\t\tif (a[i] != b[i]) return false;\n\t\t\treturn true;\n\t\t}\n\n\t\tfinal double goldenRatio = (1 + Math.sqrt(5)) / 2;\n\t\tfinal double aGoldenRatio = (1 - Math.sqrt(5)) / 2;\n\n\t\tlong Fib(int n) {\n\t\t\tif (n < 0) if (n % 2 == 0) return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\telse\n\t\t\t\treturn -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\treturn Math.round((pow(goldenRatio, n) - pow(aGoldenRatio, n)) / Math.sqrt(5));\n\t\t}\n\n\t\tclass japaneeseComparator implements Comparator<String> {\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\n\tvoid readIntArray(int[] a) throws IOException {\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = nextInt();\n\t}\n\n\tString readChars(int l) throws IOException {\n\t\tString r = \"\";\n\t\tfor (int i = 0; i < l; i++)\n\t\t\tr += (char) br.read();\n\t\treturn r;\n\t}\n\n\tStreamTokenizer in;\n\tPrintWriter out;\n\tboolean oj;\n\tBufferedReader br;\n\n\tvoid init() throws IOException {\n\t\toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tReader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\tWriter writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n\t\tbr = new BufferedReader(reader);\n\t\tin = new StreamTokenizer(br);\n\t\tout = new PrintWriter(writer);\n\t}\n\n\tlong 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\tlong beginMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n\t\tinit();\n\t\tsolve();\n\t\tlong endMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n\t\tlong endTime = System.currentTimeMillis();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(\"Memory used = \" + (endMem - beginMem));\n\t\t\tSystem.out.println(\"Total memory = \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));\n\t\t\tSystem.out.println(\"Running time = \" + (endTime - beginTime));\n\t\t}\n\t\tout.flush();\n\t}\n\n\tint nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tlong nextLong() throws IOException {\n\t\tin.nextToken();\n\t\treturn (long) in.nval;\n\t}\n\n\tString nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.nval;\n\t}\n\n\tmyLib lib = new myLib();\n\n\t/*\n\t * class cubeWithLetters { String consts = \"\u0427\u041a\u0422\u0424\u042d\u0426\"; char[][] letters = { {\n\t * '\u0410', '\u0411', '\u0413', '\u0412' }, { '\u0414', '\u0415', '\u0417', '\u0416' }, { '\u0418', '\u041b', '\u041d', '\u041c' }, {\n\t * '\u041e', '\u041f', '\u0421', '\u0420' }, { '\u0423', '\u0425', '\u0429', '\u0428' }, { '\u042b', '\u042c', '\u042f', '\u042e' } };\n\t * \n\t * char get(char x) { if (consts.indexOf(x) != -1) return x; for (int i = 0;\n\t * i < 7; i++) { for (int j = 0; j < 4; j++) { if (letters[i][j] == x) { if\n\t * (j == 0) return letters[i][3]; else return letters[i][j - 1]; } } }\n\t * return '!'; }\n\t * \n\t * void subrotate(int x) { char t = letters[x][0]; letters[x][0] =\n\t * letters[x][3]; letters[x][3] = letters[x][2]; letters[x][2] =\n\t * letters[x][1]; letters[x][1] = t; }\n\t * \n\t * void rotate(int x) { subrotate(x); char t; if (x == 0) { t =\n\t * letters[1][0]; letters[1][0] = letters[2][0]; letters[2][0] =\n\t * letters[3][0]; letters[3][0] = letters[5][2]; letters[5][2] = t;\n\t * \n\t * t = letters[1][1]; letters[1][1] = letters[2][1]; letters[2][1] =\n\t * letters[3][1]; letters[3][1] = letters[5][3]; letters[5][3] = t; } if (x\n\t * == 1) { t = letters[2][0]; letters[2][0] = letters[0][0]; letters[0][0] =\n\t * letters[5][0]; letters[5][0] = letters[4][0]; letters[4][0] = t;\n\t * \n\t * t = letters[2][3]; letters[2][3] = letters[0][3]; letters[0][3] =\n\t * letters[5][3]; letters[5][3] = letters[4][3]; letters[4][3] = t; } if (x\n\t * == 2) { t = letters[0][3]; letters[0][3] = letters[1][2]; letters[1][2] =\n\t * letters[4][1]; letters[4][1] = letters[3][0]; letters[3][0] = t;\n\t * \n\t * t = letters[0][2]; letters[0][2] = letters[1][1]; letters[1][1] =\n\t * letters[4][0]; letters[4][0] = letters[3][3]; letters[3][3] = t; } if (x\n\t * == 3) { t = letters[2][1]; letters[2][1] = letters[4][1]; letters[4][1] =\n\t * letters[5][1]; letters[5][1] = letters[0][1]; letters[0][1] = t;\n\t * \n\t * t = letters[2][2]; letters[2][2] = letters[4][2]; letters[4][2] =\n\t * letters[5][2]; letters[5][2] = letters[0][2]; letters[0][2] = t; } if (x\n\t * == 4) { t = letters[2][3]; letters[2][3] = letters[1][3]; letters[1][3] =\n\t * letters[5][1]; letters[5][1] = letters[3][3]; letters[3][3] = t;\n\t * \n\t * t = letters[2][2]; letters[2][2] = letters[1][2]; letters[1][2] =\n\t * letters[5][0]; letters[5][0] = letters[3][2]; letters[3][2] = t; } if (x\n\t * == 5) { t = letters[4][3]; letters[4][3] = letters[1][0]; letters[1][0] =\n\t * letters[0][1]; letters[0][1] = letters[3][2]; letters[3][2] = t;\n\t * \n\t * t = letters[4][2]; letters[4][2] = letters[1][3]; letters[1][3] =\n\t * letters[0][0]; letters[0][0] = letters[3][1]; letters[3][1] = t; } }\n\t * \n\t * public String toString(){ return \"  \" + letters[0][0] + letters[0][1] +\n\t * \"\\n\" + \"  \" + letters[0][3] + letters[0][2] + \"\\n\" + letters[1][0] +\n\t * letters[1][1] + letters[2][0] + letters[2][1] + letters[3][0] +\n\t * letters[3][1] + \"\\n\" + letters[1][3] + letters[1][2] + letters[2][3] +\n\t * letters[2][2] + letters[3][3] + letters[3][2] + \"\\n\" + \"  \" +\n\t * letters[4][0] + letters[4][1] + \"\\n\" + \"  \" + letters[4][3] +\n\t * letters[4][2] + \"\\n\" + \"  \" + letters[5][0] + letters[5][1] + \"\\n\" + \"  \"\n\t * + letters[5][3] + letters[5][2] + \"\\n\"; } }\n\t * \n\t * \n\t * Vector<Integer>[] a; int n, mc, c1, c2; int[] col;\n\t * \n\t * void wave(int x, int p) { for (Iterator<Integer> i = a[x].iterator();\n\t * i.hasNext(); ) { int t = i.next(); if (t == x || t == p) continue; if\n\t * (col[t] == 0) { col[t] = mc; wave(t, x); } else { c1 = x; c2 = t; } } }\n\t * \n\t * void solve() throws IOException {\n\t * \n\t * String s = \"\u0415\u041f\u041e\u0415\u042c\u0420\u0418\u0422\u0421\u0413\u0425\u0416\u0417\u0422\u042f\u041f\u0421\u0422\u0410\u041f\u0414\u0421\u0411\u0418\u0421\u0422\u0427\u041a\"; //String s =\n\t * \"\u0417\u042c\u0423\u041e\u042b\u0422\u0412\u0417\u0422\u042f\u041f\u0423\u0411\u041e\u042b\u0422\u0415\u0410\u042b\u0428\u0425\u042f\u0410\u0422\u0427\u041a\"; cubeWithLetters cube = new\n\t * cubeWithLetters(); for (int x = 0; x < 4; x++) { for (int y = x + 1; y <\n\t * 5; y++) { for (int z = y + 1; z < 6; z++) { cube = new cubeWithLetters();\n\t * out.println(cube.toString()); cube.rotate(x);\n\t * out.println(cube.toString()); cube.rotate(y);\n\t * out.println(cube.toString()); cube.rotate(z);\n\t * out.println(cube.toString()); out.print(x + \" \" + y + \" \" + z + \" = \");\n\t * for (int i = 0; i < s.length(); i++) { out.print(cube.get(s.charAt(i)));\n\t * } out.println(); } } }\n\t * \n\t * int a = nextInt(), b = nextInt(), x = nextInt(), y = nextInt();\n\t * out.print((lib.min(a / (x / lib.gcd(x, y)), b / (y / lib.gcd(x, y))) * (x\n\t * / lib.gcd(x, y))) + \" \" + (lib.min(a / (x / lib.gcd(x, y)), b / (y /\n\t * lib.gcd(x, y))) * (y / lib.gcd(x, y)))); }\n\t */\n\n}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        int len = s.nextInt();\n        s.nextLine();\n        String l = s.nextLine();\n        char[] ca = l.toCharArray();\n        int h = 0;\n        for (char c : ca)\n            h += A(c);\n        int cur = h;\n        int i;\n        for (i = 0; i < h; i++)\n            cur -= A(ca[i]);\n        int best = cur;\n        while (i != h + len) {\n            cur -= A(ca[i % len]);\n            cur += A(ca[(i - h) % len]);\n            best = best > cur ? cur : best;\n            i++;\n        }\n        System.out.println(best);\n    }\n\n    public static int A(char x) {\n        return x == 'H' ? 1 : 0;\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Homyak implements Runnable {\n    private void solve() throws IOException {\n        int n = nextInt();\n        String seq = nextToken();\n        int nh = 0;\n        int nt = 0;\n        for (int i = 0; i < n; ++i)\n            if (seq.charAt(i) == 'H')\n                ++nh;\n            else\n                ++nt;\n        int res = n;\n        for (int delta = 0; delta < n; ++delta) {\n            int changed = 0;\n            int at = delta;\n            for (int i = 0; i < nh; ++i) {\n                if (seq.charAt(at) != 'H')\n                    ++changed;\n                ++at;\n                if (at >= n)\n                    at = 0;\n            }\n            for (int i = 0; i < nt; ++i) {\n                if (seq.charAt(at) != 'T')\n                    ++changed;\n                ++at;\n                if (at >= n)\n                    at = 0;\n            }\n            res = Math.min(res, changed / 2);\n        }\n        writer.println(res);\n    }\n\n    public static void main(String[] args) {\n        new Homyak().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}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C\n{\n\tString line;\n\tStringTokenizer inputParser;\n\tBufferedReader is;\n\tFileInputStream fstream;\n\tDataInputStream in;\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\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\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\tC c = new C(filePath);\n\t}\n\t\n\tpublic C(String inputFile)\n\t{\n        openInput(inputFile);\n        \n\t\treadNextLine();\n\t\tint N=NextInt();\n\t\tboolean [] p = new boolean[N];\n\t\treadNextLine();\n\t\tint h=0;\n\t\tfor(int i=0; i<N; i++)\n\t\t{\n\t\t\tp[i]=line.charAt(i)=='H';\n\t\t\tif(p[i])h++;\n\t\t}\n\t\t\n\t\t\n\t\tint ret=N;\n\t\t\n\t\tfor(int i=0; i<N; i++)\n\t\t{\n\t\t\tint m=0;\n\t\t\tfor(int j=i; j<i+h; j++)\n\t\t\t{\n\t\t\t\tint n=j%N;\n\t\t\t\tif(!p[n])m++;\n\t\t\t}\n\t\t\tret=Math.min(ret, m);\n\t\t}\n\t\t\n\t\tSystem.out.println(ret);\n\t\tcloseInput();\n\t}\n\n\t\n\t\n}\n\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tString s = next();\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = s.charAt(i) == 'H' ? 1 : 0;\n\t\tint res = 10 * n;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = new int[n];\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\tb[j] = a[(i + j) % n];\n\t\t\tres = Math.min(res, solve(b, 0));\n\t\t\tres = Math.min(res, solve(b, 1));\n\t\t}\n\t\tout.print(res);\n\t}\n\n\tprivate int solve(int[] a, int x) {\n\t\tint n = a.length;\t\t\n\t\tint j;\n\t\tfor (j = n - 1; j >= 0; j--)\n\t\t\tif (a[j] == x)\n\t\t\t\tbreak;\n\t\tif (a[j] != x) return 0;\n\t\tint res = 0;\n\t\tfor (int i = 0; i < j; i++)\n\t\t\tif (a[i] != x) {\n\t\t\t\t--j;\n\t\t\t\twhile (j >= i && a[j] != x)\n\t\t\t\t\t--j;\n\t\t\t\t++res;\n\t\t\t}\n\t\treturn res;\n\t}\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", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Solution {\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tStreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tin.nextToken();\n\t\tint n = (int)in.nval;\n\t\tin.nextToken();\n\t\tString st = in.sval;\n\t\tchar[] a = new char[n];\n\t\tfor (int i = 0; i<n; i++)\n\t\t\ta[i] = st.charAt(i);\n\t\tint kH = 0;\n\t\tint kT = 0;\n\t\tfor (int i =0; i<n; i++)\n\t\t\tif (a[i] == 'T') kT++;\n\t\t\telse kH++;\n\t\tint kol = 0;\n\t\tint min = Integer.MAX_VALUE;\n\t\tint poz;\n\t\t\n\t\tfor (int i=0; i<n; i++)\n\t\t{\n\t\t\tkol = 0;\n\t\t\tif (a[i] == 'T') {\n\t\t\t\tfor (int j = 0; j<kT; j++){\n\t\t\t\t\tpoz = (i+j)%n;\n\t\t\t\t\tif (a[poz] == 'H') kol++;\n\t\t\t\t}\n\t\t\t\tif (kol < min) min = kol;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfor (int j = 0; j<kH; j++){\n\t\t\t\t\tpoz = (i+j)%n;\n\t\t\t\t\tif (a[poz] == 'T') kol++;\n\t\t\t\t}\n\t\t\t\tif (kol < min) min = kol;\n\t\t\t}\n\t\t}\n\t\tout.print(min);\n\t\tout.flush();\n\t}\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\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        int n = in.nextInt();\n        char[] a = in.next().toCharArray();\n        int h = 0;\n        for (int i = 0; i < a.length; i++) {\n            if (a[i] == 'H') h++;\n        }\n        char[] b = new char[2 * a.length - 1];\n        for (int i = 0; i < b.length; i++) {\n            b[i] = a[i % a.length];\n        }\n        int maxh = 0;\n        int hh = 0;\n        for (int i = 0; i < b.length - h; i++) {\n            hh = 0;\n            for (int j = 0; j < h; j++) {\n                if (b[i + j] == 'H') hh++;\n            }\n            maxh = Math.max(maxh, hh);\n        }\n        /*for (int i = 0; i < b.length; i++) {\n            out.print(b[i]);\n        }\n        out.println();*/\n        //out.println(h + \" \" + maxh);\n        out.println(h - maxh);\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            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}\n\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main { \n    public static StreamTokenizer in;\n    public static PrintStream out;\n    public static BufferedReader br;\n\n    public static String readString() throws IOException {\n        in.nextToken();\n        return  in.sval;\n        }\n\n    public static double readDouble() throws IOException {\n        in.nextToken();\n        return in.nval;\n        }\n\n    public static int readInt() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n    \n    public static String readLine() throws IOException {\n    return br.readLine();\n    }\n    \n    public static int genans(String ss) {\n    \t\n    \tint n = ss.length();\n    \tchar[] s = ss.toCharArray();\n    \tint res = 0;\n    \twhile (true) {\n    \t\tint firstT = -1;\n    \t\tfor (int i=0; i<n; i++)\n    \t\t\tif (s[i]=='T') { firstT = i; break; }\n    \t\t\n    \t\tint lastH = -1;\n    \t\tfor (int i=n-1; i>=0; i--)\n    \t\t\tif (s[i]=='H') { lastH=i; break; }\n    \t\t\n    \t\tif (firstT<lastH) {\n    \t\t\tres++;\n    \t\t\ts[firstT] = 'H';\n    \t\t\ts[lastH] = 'T';\n    \t\t} else break;\n    \t\t\n    \t}\t\n    \treturn res;\n    }\n    \n    public static void main(String[] args) throws IOException {\n\n        in = new StreamTokenizer(new InputStreamReader (System.in) );\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintStream(System.out);\n\n        readLine();\n        String s = readLine();\n        int n = s.length();\n        String kk = s;\n        int ans = n*100;\n        for (int tr=0; tr<n+2; tr++) {\n        \tString kk2 = \"\";\n        \tfor (int i=1; i<n; i++) kk2 = kk2 +kk.charAt(i);\n        \tkk2 = kk2 + kk.charAt(0);\n        \tkk = kk2;\n        \n        int cur = genans(kk);\n        //out.println(kk+\" \"+cur);\n        if (cur<ans) ans = cur;\n        }\n        \n        out.println(ans);\n\n    }\n    \n\n}\n\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main {        \n\n    void run() throws IOException {\n        int n = nint();\n        char[] s = token().toCharArray();\n        int h = 0;\n        for (int i = 0; i < n; i++) {\n            if (s[i] == 'H') h++;\n        }\n        int r = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            int t = 0;\n            for (int j = i; j < i + h; j++) {\n                if (s[j % n] == 'T') t++;\n            }\n            r = min(r, t);\n        }\n        out.println(r);\n    }\n\n    class pair implements Comparable <pair> {\n        int x, y;\n        pair(int x, int y) {\n            this.x = x;\n            this.y = y;            \n        }\n        public int compareTo (pair p) {\n            if (x != p.x) {\n                return x - p.x;\n            } else {\n                return y - p.y;\n            }\n        }\n    }\n\n//    static PrintWriter out;\n  //  static Scanner in;\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        //final String FILENAME = \"jury\"; in = new Scanner (new File (FILENAME + \".in\")); out = new PrintWriter (new File(FILENAME + \".out\"));\n    //    in = new Scanner (System.in); out = new PrintWriter (System.out);\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        st = new StringTokenizer(\" \");\n        new Main().run();\n        /*out = new PrintWriter (System.out);\n        final int NUMBER_OF_TESTS = 35;\n        for (int i = 1; i <= NUMBER_OF_TESTS; i++) {\n            Scanner test = new Scanner (new File (\"tests/\" + i + \".in\"));\n            Scanner right = new Scanner (new File (\"tests/\" + i + \".out\"));\n            String get_right = right.nextLine();\n            String get_test = new Main().run(test);\n            if (get_right.equals(get_test)) {\n                out.println(\"Test #\" + i + \": \" + \"OK!\");                \n            } else {\n                out.println(\"Test #\" + i + \": \" + \"ERROR!\");\n                out.println(\"Expected: \" + get_right);\n                out.println(\"Received: \" + get_test);\n                break;\n            }\n        }*/\n        out.close();\n    }\n\n    static BufferedReader in;\n    static PrintWriter out;\n    static StringTokenizer st;\n\n    String token() throws IOException {\n        while (!st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nint() throws IOException {\n        return Integer.parseInt(token());\n    }\n\n    long nlong() throws IOException {\n        return Long.parseLong(token());\n    }\n\n    double ndouble() throws IOException {\n        return Double.parseDouble(token());\n    }\n}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\n\npublic class C43 {\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        int n = nextInt();\n        char[] s = nextString().toCharArray();\n        int h = 0;\n        for (int i = 0; i < n; i++)\n            if (s[i] == 'H')\n                h++;\n        \n        int ans = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            int p = i, t = 0;\n            for (int j = 0; j < h; j++, p = (p+1)%n)\n                if (s[p] == 'T')\n                    t++;\n            ans = Math.min(ans, t);\n        }\n        \n        out.println(ans);\n        out.flush();\n    }\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\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 cin = new Scanner(System.in);\n\t\tint n;\n\t\tn = cin.nextInt();\n\t\tString s = cin.next();\n\t\tint ans = n;\n\t\tint cntH = 0,cntT = 0;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tif(s.charAt(i)=='H')cntH++;\n\t\t}\n\t\tcntT = n - cntH;\n\t\tfor(int i=0;i+cntH<n;i++)\n\t\t{\n\t\t\tint tmp = 0;\n\t\t\tfor(int j=i;j<i+cntH;j++)\n\t\t\t\tif(s.charAt(j)=='T')tmp++;\n\t\t\tif(ans>tmp)ans = tmp;\n\t\t}\n\t\tfor(int i=0;i+cntT<n;i++)\n\t\t{\n\t\t\tint tmp = 0;\n\t\t\tfor(int j=i;j<i+cntT;j++)\n\t\t\t\tif(s.charAt(j)=='H')tmp++;\n\t\t\tif(ans>tmp)ans = tmp;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class C implements Runnable {\n\n    private static final boolean USE_FILE_IO = false;\n    private static final String FILE_IN = \"c.in\";\n    private static final String FILE_OUT = \"c.out\";\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tokenizer = new StringTokenizer(\"\");\n\n    public static void main(String[] args) {\n        new Thread(new C()).start();\n    }\n\n    int n, h, t;\n    char[] c;\n\n    private void solve() throws IOException {\n        n = nextInt();\n        c = nextToken().toCharArray();\n        if (c.length != n) {\n            throw new IllegalStateException();\n        }\n\n        for (char l : c)\n            if (l == 'H') {\n                h++;\n            }\n        t = n - h;\n\n        if (h == 0) {\n            out.print(0);\n            return;\n        }\n\n        int answer = Integer.MAX_VALUE;\n        for (int hLo = 0; hLo < n; hLo++)\n            if (c[hLo] == 'H') {\n                int hHi = (hLo + h) % n;\n\n                int current = 0;\n                int j = hLo;\n                while (j != hHi) {\n                    if (c[j] == 'T') {\n                        current++;\n                    }\n                    j = (j + 1) % n;\n                }\n\n                answer = Math.min(answer, current);\n            }\n\n        out.print(answer);\n    }\n\n    public void run() {\n        long timeStart = System.currentTimeMillis();\n        try {\n\n            if (USE_FILE_IO) {\n                in = new BufferedReader(new FileReader(FILE_IN));\n                out = new PrintWriter(new FileWriter(FILE_OUT));\n            } else {\n                in = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(new OutputStreamWriter(System.out));\n            }\n\n            solve();\n\n            in.close();\n            out.close();\n        } catch (IOException e) {\n            throw new IllegalStateException(e);\n        }\n        long timeEnd = System.currentTimeMillis();\n        System.out.println(\"Time spent: \" + (timeEnd - timeStart) + \" ms\");\n    }\n\n    private String nextToken() throws IOException {\n        while (!tokenizer.hasMoreTokens()) {\n            String line = in.readLine();\n            if (line == null) {\n                return null;\n            }\n            tokenizer = new StringTokenizer(line);\n        }\n        return tokenizer.nextToken();\n    }\n\n    private int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    private BigInteger nextBigInt() throws IOException {\n        return new BigInteger(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}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tprivate static boolean _READ_FROM_FILE = System.getProperty(\"ONLINE_JUDGE\") == null;\n\tprivate static Scanner in;\n\tprivate static void core() {\n\t\tint n = in.nextInt();\n\t\tArrayList<Character> all = new ArrayList<Character>();\n\t\tfor (char ch : in.next().toCharArray()) {\n\t\t\tall.add(ch);\n\t\t}\n\t\t\n\t\tint res = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint now = calc(all);\n\t\t\tres = Math.min(res, now);\n\t\t\tall.add(all.get(0));\n\t\t\tall.remove(0);\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\tprivate static int calc(ArrayList<Character> all) {\n\t\tint nh = 0;\n\t\tfor (char ch: all) {\n\t\t\tif (ch == 'H')\n\t\t\t\t++nh;\n\t\t}\n\t\tint r1 = 0;\n\t\tfor (int i = 0; i < nh; i++) {\n\t\t\tif (all.get(i) != 'H')\n\t\t\t\t++r1;\n\t\t}\n\t\t\n\t\tint nt = all.size() - nh;\n\t\tint r2 = 0;\n\t\tfor (int i = 0; i < nt; i++) {\n\t\t\tif (all.get(i) != 'T')\n\t\t\t\t++r2;\n\t\t}\n\t\treturn Math.min(r1, r2);\n\t}\n\tstatic void debug(Object...os) {\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tif (_READ_FROM_FILE)\n\t\t\tSystem.setIn(new FileInputStream(\"in.in\"));\n\t\tin = new Scanner(System.in);\n\t\tcore();\n\t}\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import 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    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    String next() throws Exception {\n        in.nextToken();\n        return in.sval;\n    }\n\n    public void solve() throws Exception {\n        int n=nextInt();\n        String s=next();\n        String ss = s + s;\n        int t = 0;\n        for (int i = 0; i < n; i++) {\n            if (s.charAt(i) == 'T') {\n                t++;\n            }\n        }\n        if (t == 1 || t == n - 1) {\n            out.println(0);\n        } else {\n            int sum = 0;\n            for (int i = 0; i < t; i++) {\n                if (s.charAt(i) == 'T') {\n                    sum++;\n                }\n            }\n            \n            int max = sum;\n            for (int i = 0; i < s.length(); i++) {\n                if (ss.charAt(i) == 'T') {\n                    if (ss.charAt(i + t) == 'H') {\n                        sum--;\n                    }\n                } else {\n                    if (ss.charAt(i + t) == 'T') {\n                        sum++;\n                        max = Math.max(max, sum);\n                    }\n                }\n            }\n           out.println(t - max);\n        }\n    }\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "/*\n* Author: Nikhil Garg\n* Date:   2010-12-05\n*\n*/\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class javatemp\n{\n\tstatic String map(int a)\n\t{\n\t\tif( a == 0) return \"S\";\n\t\telse if ( a == 1 ) return \"M\";\n\t\telse if ( a == 2 ) return \"L\";\n\t\telse if ( a == 3 ) return \"XL\";\n\t\telse if ( a == 4 ) return \"XXL\";\n\t\treturn \"\";\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tBufferedReader in = new BufferedReader( new InputStreamReader(System.in));\n\t\tint ans = 1000;\n\t\tin.readLine();\n\t\tString s = in.readLine();\n\t\tint H = 0;\n\t\tfor(int i =0; i < s.length(); i++)\n\t\t\tif( s.charAt(i) == 'H') H++;\n\n\t\t\n\t\tfor(int i = 0; i < s.length(); i++)\n\t\t{\n\t\t\tint count = 0;\n\t\t\tfor(int j = 0; j < H; j++)\n\t\t\t\tif( s.charAt( (i +j) % s.length()) =='T') count ++;\n\t\t\tans = Math.min ( ans, count);\n\t\t}\n\t\tSystem.out.println(ans);\n\n\t}\n\t\n\t\n\tstatic void debug(Object...os)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t\t\t} catch (SecurityException e) {}\n\t\t\t\t\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\tint N;\n\tint[] a;\n\tint[] b;\n\tint[] c;\n\t\n\tint T, H;\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\tchar[] s = nextToken().toCharArray();\n\t\ta = new int [N];\n\t\t\n\t\tH = 0;\n\t\tT = 0;\n\t\t\n\t\tfor (int i = 0; i < s.length; i++) {\n\t\t\ta[i] = s[i] == 'T' ? 1 : 0;\n\t\t\tif (s[i] == 'T')\n\t\t\t\tT++;\n\t\t\telse\n\t\t\t\tH++;\n\t\t}\n\t\t\n\t\tif (T == 1 || H == 1) {\n\t\t\tout.println(0);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tb = Arrays.copyOf(a, a.length);\n\t\tc = Arrays.copyOf(a, a.length);\n\t\tsort(c);\n\t\t\n\t\tint ans = 100000000;\n\t\tfor (int o = 0; o < N; o++) {\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tb[(i + o) % N] = a[i];\n\t\t\tint cur = 0;\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tif (b[i] != c[i])\n\t\t\t\t\tcur++;\n\t\t\tans = min(ans, cur / 2);\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\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\t\n\t\t\tif (s == null) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class C43 implements Runnable {\n\n    public Scanner in;\n\n    public PrintWriter out;\n\n    final static String TASK_NAME = \"\";\n\n    C43() throws IOException {\n        in = new Scanner( System.in );\n        // in = new StreamTokenizer( new InputStreamReader( System.in ) );\n        out = new PrintWriter( System.out );\n    }\n\n    void close() throws IOException {\n        out.close();\n    }\n\n    public void run() {\n        try {\n            solve();\n            close();\n        } catch ( Exception e ) {\n            e.printStackTrace();\n        }\n    }\n\n    public void solve() throws IOException {\n        int n = in.nextInt();\n        char[] c = in.next().toCharArray();\n        int t = 0;\n        for ( int i = 0; i < n; i ++ ) {\n            if ( c[i] == 'T' ) {\n                t ++;\n            }\n        }\n        int ct = 0;\n        for ( int i = 0; i < t; i ++ ) {\n            if ( c[i] == 'T' ) {\n                ct ++;\n            }\n        }\n        int r = 0;\n        for ( int i = 0; i < n; i ++ ) {\n            r = Math.max( r, ct );\n            if ( c[i] == 'T' ) {\n                ct --;\n            }\n            if ( c[( i + t ) % n] == 'T' ) {\n                ct ++;\n            }\n        }\n        out.println( t - r );\n    }\n\n    public static void main( String[] args ) throws IOException {\n        new Thread( new C43() ).start();\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "//package round43;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tchar[] x = in.next().toCharArray();\n\t\tint t = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(x[i] == 'T'){\n\t\t\t\tt++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint min = 9999;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint y = 0;\n\t\t\tfor(int j = i;j < i + t;j++){\n\t\t\t\tif(x[j % n] == 'T'){\n\t\t\t\t\ty++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmin = Math.min(min, t - y);\n\t\t}\n\t\tout.println(min);\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew C().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", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n    static BufferedReader br=null;\n    static PrintWriter pw=null;\n    static StringTokenizer st=null;\n    static String FILENAME=\"\";\n    \n    void nline(){\n        try {\n            st=new StringTokenizer(br.readLine());\n        } catch (IOException e) {\n            // TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n    }\n    int ni(){\n        while(st==null || !st.hasMoreTokens()) nline();\n        return Integer.parseInt(st.nextToken());\n    }\n    long nl(){\n        while(st==null || !st.hasMoreTokens()) nline();\n        return Long.parseLong(st.nextToken());\n    }\n    double nd(){\n        while(st==null || !st.hasMoreTokens()) nline();\n        return Double.parseDouble(st.nextToken());\n    }\n    String ns(){\n        while(st==null || !st.hasMoreTokens()) nline();\n        return st.nextToken();\n    }\n    String nstr(){\n        String s=\"\";\n        try {\n            s=br.readLine();\n        } catch (IOException e) {\n            // TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n        return s;\n    }\n\n    public void solve(){\n        int n = ni();\n        String s = nstr();\n        int[] a = new int[n];\n        for (int i=0;i<n;i++)\n            a[i]=s.charAt(i)=='H'?0:1;\n        int hc = 0;\n        for (int i=0;i<n;i++)\n            if (a[i]==0) hc++;\n        int min = 1000000;\n        for (int ss=0;ss<n;ss++) {\n            int rc = 0;\n            for (int i=0;i<hc;i++)\n                if (a[(i+ss)%n]==0) rc++;\n            if (hc-rc<min) min=hc-rc;\n        }\n        pw.print(min);\n    }\n    public void run(){\n        solve();\n        pw.close();\n    }\n    public static void main(String[] args) {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            pw = new PrintWriter(System.out);\n        \n        new Solution().run();\n    }\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.util.Scanner;\n\npublic class HamstersAndTigers { //Round #XX - Hamsters and Tigers\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(new BufferedInputStream(System.in));\n\n\t\tint numAnimals = sc.nextInt();\n\t\tString positions = sc.next();\n\n\t\tint numTigers = 0;\n\t\tint numHamsters = 0;\n\t\tfor(int i = 0; i < positions.length(); i++) {\n\t\t\tif(positions.charAt(i) == 'T') {\n\t\t\t\tnumTigers++;\n\t\t\t} else {\n\t\t\t\tnumHamsters++;\n\t\t\t}\n\t\t}\n\n\t\tint minDifference = Integer.MAX_VALUE;\n\n\t\tStringBuilder tigerChars = new StringBuilder(1000);\n\t\tStringBuilder hamsterChars = new StringBuilder(1000);\n\t\tfor(int i = 0; i < numHamsters; i++) {\n\t\t\thamsterChars.append('H');\n\t\t}\n\t\tStringBuilder remainingTigerChars = new StringBuilder(1000);\n\t\tfor(int i = 0; i < numTigers; i++) {\n\t\t\tremainingTigerChars.append('T');\n\t\t}\n\n\t\tfor(int i = 0; i <= numTigers; i++) {\n\t\t\tStringBuilder generated = new StringBuilder();\n\t\t\tgenerated.append(tigerChars);\n\t\t\tgenerated.append(hamsterChars);\n\t\t\tgenerated.append(remainingTigerChars);\n\t\t\t\n\t\t\t//System.out.println(generated);\n\n\t\t\tif(remainingTigerChars.length() >= 1) {\n\t\t\t\tremainingTigerChars.deleteCharAt(remainingTigerChars.length() - 1);\n\t\t\t}\n\t\t\ttigerChars.append('T');\n\n\t\t\tint diffCount = stringDiffCount(positions, generated.toString());\n\t\t\tif(diffCount < minDifference) {\n\t\t\t\tminDifference = diffCount;\n\t\t\t}\n\t\t}\n\n\t\t//System.out.println(\"\");\n\n\t\thamsterChars = new StringBuilder(1000);\n\t\ttigerChars = new StringBuilder(1000);\n\t\tfor(int i = 0; i < numTigers; i++) {\n\t\t\ttigerChars.append('T');\n\t\t}\n\t\tStringBuilder remainingHamsterChars = new StringBuilder(1000);\n\t\tfor(int i = 0; i < numHamsters; i++) {\n\t\t\tremainingHamsterChars.append('H');\n\t\t}\n\n\t\tfor(int i = 0; i <= numHamsters; i++) {\n\t\t\tStringBuilder generated = new StringBuilder();\n\t\t\tgenerated.append(hamsterChars);\n\t\t\tgenerated.append(tigerChars);\n\t\t\tgenerated.append(remainingHamsterChars);\n\n\t\t\t//System.out.println(generated);\n\n\t\t\tif(remainingHamsterChars.length() >= 1) {\n\t\t\t\tremainingHamsterChars.deleteCharAt(remainingHamsterChars.length() - 1);\n\t\t\t}\n\t\t\thamsterChars.append('H');\n\n\t\t\tint diffCount = stringDiffCount(positions, generated.toString());\n\t\t\tif(diffCount < minDifference) {\n\t\t\t\tminDifference = diffCount;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(minDifference / 2);\n\t}\n\n\tprivate static int stringDiffCount(String strOne, String strTwo) {\n\t\tint diffCount = 0;\n\t\tfor(int i = 0; i < strOne.length(); i++) {\n\t\t\tif(strOne.charAt(i) != strTwo.charAt(i)) {\n\t\t\t\tdiffCount++;\n\t\t\t}\n\t\t}\n\t\treturn diffCount;\n\t}\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n\npublic class Main{\n    \n    public static void main(String[] args){\n        Scanner in = new Scanner(System.in);\n        int[] a=new int[1010];\n        while(in.hasNext()){\n            int n=in.nextInt();\n            String s=in.next();\n            int sum=0;\n            for(int i=0;i<n;++i){\n                if(s.charAt(i)=='H'){\n                    a[i]=1;\n                    ++sum;\n                }\n                else a[i]=0;\n            }\n            int min=10010;\n            for(int i=0;i<n-sum;++i){\n                int count=0;\n                for(int j=i+sum;j<n;++j){\n                    if(a[j]==1)++count;\n                }\n                for(int j=0;j<i;++j){\n                    if(a[j]==1)++count;\n                }\n                if(count<min)min=count;\n            }\n            sum=n-sum;\n            for(int i=0;i<n-sum;++i){\n                int count=0;\n                for(int j=i+sum;j<n;++j){\n                    if(a[j]==0)++count;\n                }\n                for(int j=0;j<i;++j){\n                    if(a[j]==0)++count;\n                }\n                if(count<min)min=count;\n            }\n            System.out.println(min);\n        }\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class ProblemC {\n\n    public static void main(String[] args) {\n        ProblemC problem = new ProblemC();\n        problem.solve();\n    }\n\n    private void solve() {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        String s = sc.next();\n        int ret = n;\n        int toth = 0;\n        int tott = 0;\n        for (int j = 0; j < n; j++) {\n            if (s.charAt(j) == 'H') {\n                toth++;\n            } else {\n                tott++;\n            }\n        }\n        for (int j = 0; j < n; j++) {\n            int cnth = 0;\n            for (int k = 0; k < toth; k++) {\n                int pos = (j + k) % n;\n                if (s.charAt(pos) == 'H') {\n                    cnth++;\n                }\n            }\n            int makeh = toth - cnth;\n            ret = Math.min(ret, makeh);\n        }\n        System.out.println(ret);\n    }\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "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    public static void main(String[] args) {\n        new Main().run();\n    }\n    Scanner sc=new Scanner(System.in);\n    void run() {\n        int n=sc.nextInt();\n        char[] cs=sc.next().toCharArray();\n        int h=0;\n        for(int i=0;i<n;i++)if(cs[i]=='H')h++;\n        int res=n;\n        for(int i=0;i<n;i++) {\n            int val=0;\n            for(int j=0;j<h;j++)if(cs[(i+j)%n]=='T')val++;\n            res=min(res,val);\n        }\n        System.out.println(res);\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "\nimport com.sun.org.apache.xpath.internal.axes.SubContextList;\nimport java.util.Scanner;\n\n/**\n *\n * @author Madi\n */\npublic class Round42CC {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = Integer.parseInt(sc.nextLine());\n        String s = sc.nextLine();\n\n        int k = 0;\n        for (int i = 0; i < n; i++) {\n            if (s.charAt(i) == 'H') {\n                k++;\n            }\n        }\n\n        s = s + s.substring(0, k);\n        String ss = \"\";\n\n        int max = 0;\n        for (int i = 0; i < s.length() - k; i++) {\n            ss = s.substring(i, i + k);\n            int count = 0;\n            for (int j = 0; j < ss.length(); j++) {\n                if (ss.charAt(j) == 'H') {\n                    count++;\n                }\n            }\n            if (count > max) {\n                max = count;\n            }\n        }\n        \n        System.out.println(k - max);\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.*;\n\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\t\t\n\t\t// 1 = H, 0 = T\n\t\t\n\t\tint n = in.nextInt();\n\t\tString line = in.next();\n\t\tint h = 0;\n\t\tfor (int i = 0; i < line.length(); i++) {\n\t\t\tif(line.charAt(i)=='H') h++;\n\t\t}\n\t\tline = line + line;\n\t\t\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint ans = 0;\n\t\t\tfor (int j = i; j < i+h; j++) {\n\t\t\t\tif(line.charAt(j)!='H') ans++;\n\t\t\t}\n\t\t\tif(min>ans) min = ans;\n\t\t}\n\t\t\n\t\tout.print(min);\n\t\t\n\t\t\n\t\t\n\t\t\n\t\tin.close();\n\t\tout.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class HamstersAndTigers\n{\n\tScanner in;\n\tPrintWriter out;\n\t\n\tHamstersAndTigers()\n\t{\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\t\n\tHamstersAndTigers(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 i = 0,\n\t\t\th = 0,\n\t\t\tn = in.nextInt();\n\t\t\n\t\tString buf = \"\";\n\t\tchar[] ht = in.next().toCharArray();\n\t\t\n\t\tfor(i = 0; i < n; ++i)\n\t\t\tif(ht[i] == 'H')\n\t\t\t\t++h;\n\t\t\n\t\tfor(i = 0; i < h; ++i)\n\t\t\tbuf += 'H';\n\t\t\n\t\tfor(i = 0; i < n - h; ++i)\n\t\t\tbuf += 'T';\n\t\t\n\t\tint diff = (1 << 28);\n\t\tfor(i = 0; i < n; ++i)\n\t\t{\n\t\t\tint tmp = 0;\n\t\t\t\n\t\t\tfor(int j = 0; j < n; ++j)\n\t\t\t\tif(buf.charAt(j) != ht[(i + j) % n])\n\t\t\t\t\t++tmp;\n\t\t\t\n\t\t\tdiff = Math.min(tmp, diff);\n\t\t}\n\t\t\n\t\tout.println(diff / 2);\n\t}\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException\n\t{\n\t\tHamstersAndTigers t = new HamstersAndTigers();\n\t\tt.solve();\n\t\tt.finalize();\n\t}\n}\n\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint size= Integer.parseInt(r.readLine());\n\t\tString line = r.readLine();\n\t\t\n\t\tint counter =0;\n\t\tfor (int i = 0; i < line.length(); i++) {\n\t\t\tif(line.charAt(i)=='H')counter++;\n\t\t}\n\t\t\n\t\tint minimum = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < line.length(); i++) {\n\t\t\tif(line.charAt(i)=='H'){\n\t\t\t\tint current = 0;\n\t\t\t\tfor (int j = i; j < i+counter; j++) {\n\t\t\t\t\tif(line.charAt(j%line.length())=='T')current++;\n\t\t\t\t}\n\t\t\t\tminimum = Math.min(current, minimum);\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(minimum);\n\t\t\n\t}\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "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\tstatic boolean local = false;\n\t\n\tpublic static void main(String [] args) throws Exception {\n\t\tif (args.length > 0) local = true;\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tvoid printExit(String s) {\n\t\tout.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 = local ? new BufferedReader(new FileReader(\"input.txt\")) : new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = local ? new PrintStream(new File(\"output.txt\")) : new PrintStream(System.out);\n\t\t\tint n = nextInt();\n\t\t\tchar [] c = in.readLine().toCharArray();\n\t\t\tint t = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (c[i] == 'T') t++;\n\n\t\t\tint ans = n;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint cnt = 0;\n\t\t\t\tfor (int j = 0; j < t; j++)\n\t\t\t\t\tif (c[(i + j) % n] == 'H')\n\t\t\t\t\t\tcnt++;\n\t\t\t\tans = min(ans, cnt);\n\t\t\t}\n\n\t\t\tout.println(ans);\n\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tboolean 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 \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 nextBigInteger() {\n \t \treturn new BigInteger(nextToken());\n \t}\n\n \tString nextToken() {\n \t \tseekForToken();\n \t \treturn st.nextToken();\n \t}\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main {        \n\n    void run() throws IOException {\n        int n = in.nextInt();\n        char[] c = in.next().toCharArray();\n        int[][] t = new int[n][n];\n        int[][] h = new int[n][n];\n        int allt = 0, allh = 0;\n        for (int i = 0; i < n; i++) {\n            if (c[i] == 'T') {\n                allt++;\n            } else {\n                allh++;\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            if (c[i] == 'T') {\n                t[i][i] = 1;\n                h[i][i] = 0;\n            } else {\n                t[i][i] = 0;\n                h[i][i] = 1;\n            }\n            for (int j = i + 1; j < n; j++) {\n                if (c[j] == 'T') {\n                    t[i][j] = t[i][j - 1] + 1;\n                    h[i][j] = h[i][j - 1];\n                } else {\n                    h[i][j] = h[i][j - 1] + 1;\n                    t[i][j] = t[i][j - 1];\n                }\n            }\n        }\n        for (int i = 1; i < n; i++) {\n            t[i][i - 1] = allt;\n            h[i][i - 1] = allh;\n            for (int j = 0; j < i - 1; j++) {\n                t[i][j] = allt - t[j + 1][i - 1];\n                h[i][j] = allh - h[j + 1][i - 1];\n            }\n        }\n        int r = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {                \n                if (h[i][j] == t[(j + 1) % n][(i - 1 + n) % n]) {\n                    r = min(r, h[i][j]);\n                }\n                if (t[i][j] == h[(j + 1) % n][(i - 1 + n) % n]) {\n                    r = min(r, t[i][j]);\n                }\n            }\n        }\n        out.println(r);\n       /* for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n               out.print(t[i][j] + \" \");\n            }\n            out.println();\n        }\n        out.println();\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                out.print(h[i][j] + \" \");\n            }\n            out.println();\n        }*/\n    }\n\n    class pair implements Comparable <pair> {\n        int x, y;\n        pair(int x, int y) {\n            this.x = x;\n            this.y = y;            \n        }\n        public int compareTo (pair p) {\n            if (x != p.x) {\n                return x - p.x;\n            } else {\n                return y - p.y;\n            }\n        }\n    }\n\n    static PrintWriter out;\n    static Scanner in;\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        //final String FILENAME = \"jury\"; in = new Scanner (new File (FILENAME + \".in\")); out = new PrintWriter (new File(FILENAME + \".out\"));\n        in = new Scanner (System.in); out = new PrintWriter (System.out);\n        new Main().run();\n        /*out = new PrintWriter (System.out);\n        final int NUMBER_OF_TESTS = 35;\n        for (int i = 1; i <= NUMBER_OF_TESTS; i++) {\n            Scanner test = new Scanner (new File (\"tests/\" + i + \".in\"));\n            Scanner right = new Scanner (new File (\"tests/\" + i + \".out\"));\n            String get_right = right.nextLine();\n            String get_test = new Main().run(test);\n            if (get_right.equals(get_test)) {\n                out.println(\"Test #\" + i + \": \" + \"OK!\");                \n            } else {\n                out.println(\"Test #\" + i + \": \" + \"ERROR!\");\n                out.println(\"Expected: \" + get_right);\n                out.println(\"Received: \" + get_test);\n                break;\n            }\n        }*/\n        out.close();\n    }\n}", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n/**\n *\n * @author igor_kz\n */\npublic class C46 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int number = in.nextInt();\n        String s = in.next();\n        int cH = 0;\n        int n = s.length();\n        for (int i = 0 ; i < n ; i++)\n            if (s.charAt(i) == 'H') cH++;\n        String ss = \"\";\n        for (int i = 0 ; i < cH ; i++)\n            ss += \"H\";\n        for (int i = 0 ; i < n - cH ; i++)\n            ss += \"T\";\n        int res = Integer.MAX_VALUE;\n        for (int i = 0 ; i < n ; i++) {\n            int cur = countDifference(ss , s);\n            res = Math.min(res , cur);\n            ss = ss.substring(1) + ss.charAt(0);\n        }\n        System.out.println(res);\n    }\n\n    public static int countDifference(String ss, String s) {\n        int cnt = 0;\n        for (int i = 0 ; i < ss.length() ; i++)\n            if (ss.charAt(i) != s.charAt(i)) cnt++;\n        return cnt / 2;\n    }\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "//package round43;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tstatic BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic String nextToken() throws IOException{\n\t\twhile (st==null || !st.hasMoreTokens()){\n\t\t\tString s = bf.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tstatic int nextInt() throws IOException{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tstatic String nextStr() throws IOException{\n\t\treturn nextToken();\n\t}\n\t\n\tstatic int f(byte s[], int n){\n\t\tint l = 0,\n\t\t\tr = n-1;\n\t\tint res = 0;\n\t\t\n\t\tdo{\n\t\t\twhile (l<n && s[l]=='H')\n\t\t\t\tl++;\n\t\t\twhile (r>=0 && s[r]=='T')\n\t\t\t\tr--;\n\t\t\t\n\t\t\tif (l < r){\n\t\t\t\tres++;\n\t\t\t}\n\t\t\tl++;\n\t\t\tr--;\n\t\t}\n\t\twhile (l < r);\n\t\t\n\t\treturn res;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tint n = nextInt();\n\t\tbyte s[] = nextStr().getBytes();\n\t\t\n\t\tint res = f(s, n);\n\t\tfor (int i=1; i<n; i++){\n\t\t\tbyte c = s[0];\n\t\t\tfor (int j=0; j<n-1; j++)\n\t\t\t\ts[j] = s[j+1];\n\t\t\ts[n-1] = c;\n\t\t\tres = Math.min(res, f(s, n));\n\t\t}\n\t\t\n\t\tout.println(res);\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "linear", "problem": "46_C. Hamsters and Tigers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class pr1073B {\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\n        int n = Integer.parseInt(br.readLine());\n\n        int[] a = new int[n];\n        int[] b = new int[n];\n\n        StringTokenizer st = new StringTokenizer(br.readLine());\n\n        for (int i = 0; i < n; i++) {\n            a[i] = Integer.parseInt(st.nextToken());\n        }\n        st = new StringTokenizer(br.readLine());\n        for (int i = 0; i < n; i++) {\n            b[i] = Integer.parseInt(st.nextToken());\n        }\n\n        solve(n, a, b, out);\n        out.flush();\n        out.close();\n    }\n\n    private static void solve(int n, int[] a, int[] b, PrintWriter out) {\n        boolean[] book = new boolean[n+1];\n        boolean f;\n        int j1 = 0, j2 = 0;\n        for (int i = 0; i < n; i++) {\n            f = false;\n            int num = b[i];\n            if(!book[num]) {\n                f = true;\n                j1 = j2;\n                for (;j2 < n; j2++) {\n                    book[a[j2]] = true;\n                    if (a[j2] == num) {\n                        j2++;\n                        break;\n                    }\n                }\n            }\n            out.print(f ? j2-j1 + \" \": 0 + \" \");\n        }\n    }\n}\n", "complexity": "linear", "problem": "1073_B. Vasya and Books", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Test { public static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nint n= sc.nextInt();\nint x= (int)Math.sqrt(n) ;\nint a[] = new int[n+5];\nfor(int i=1,o=n,j;i<=n;i+=x)\nfor(j=(int)Math.min(i+x-1,n);j>=i;a[j--]=o--);\nfor(int i=1;i<=n;i++)System.out.print(a[i]+\" \");\nSystem.out.println();\n\n\n} \n}", "complexity": "linear", "problem": "1017_C. The Phone Number", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tString s = sc.next();\n\n\t\tStringBuilder ans = new StringBuilder();\n\t\tint count = 0;\n\t\tint open = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) == '(') {\n\t\t\t\tans.append(\"(\");\n\t\t\t\tcount++;\n\t\t\t\topen++;\n\t\t\t} else {\n\t\t\t\tans.append(\")\");\n\t\t\t\topen--;\n\t\t\t}\n\t\t\tif (count == k / 2) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\twhile (open > 0) {\n\t\t\tans.append(\")\");\n\t\t\topen--;\n\t\t}\n\t\tSystem.out.println(ans.toString());\n\t}\n}", "complexity": "linear", "problem": "1023_C. Bracket Subsequence", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\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[] game=new int[n];\n        int[] bill=new int[m];\n        for (int i = 0; i <n ; i++) {\n            game[i]=scan.nextInt();\n        }\n        for (int i = 0; i <m ; i++) {\n            bill[i]=scan.nextInt();\n        }\n        int i=0;\n        int j=0;\n        int ans=0;\n        while (i<m){\n            boolean f=true;\n            for (int k = j; k <n ; k++) {\n                if (bill[i]>=game[k]){\n                    ans++;\n                    i++;\n                    j=k+1;\n                    f=false;\n                    break;\n                }\n            }\n            if (f){\n                break;\n            }\n        }\n        System.out.println(ans);\n    }\n}\n\n\n", "complexity": "linear", "problem": "1009_A. Game Shopping", "from": "CODEFORCES"}
{"src": "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            String s2[]=br.readLine().split(\" \");\n            int n=Integer.parseInt(s1[0]);\n            int m=Integer.parseInt(s1[1]);\n            int a[]=new int[n];\n            int b[]=new int[n];\n            int c[]=new int[n];\n            int d[]=new int[n];\n            HashSet<Integer> hs=new HashSet<Integer>();\n            hs.add(0);\n            hs.add(m);\n            int max=0;\n            for(int i=0;i<n;i++)\n            {\n                  a[i]=Integer.parseInt(s2[i]);\n                  if(i%2==0)\n                   b[i]=1;\n                  hs.add(a[i]);\n            }\n            \n            c[0]=a[0];\n            for(int i=1;i<n;i++)\n            {\n                  if(b[i]==0)\n                   c[i]=c[i-1];\n                  else\n                   c[i]=c[i-1]+a[i]-a[i-1];\n            }\n            \n            if(b[n-1]==0)\n             d[n-1]=m-a[n-1];\n            for(int i=n-2;i>=0;i--)\n            {\n                  if(b[i]==1)\n                   d[i]=d[i+1];\n                  else\n                   d[i]=d[i+1]+a[i+1]-a[i];\n            }\n            \n            max=c[n-1];\n            if(b[n-1]==0)\n             max+=m-a[n-1];\n            //System.out.println(max);\n            for(int i=n-1;i>=0;i--)\n            {\n                  int u=a[i]-1;\n                  int v=a[i]+1;\n                  if(!hs.contains(u))\n                  {\n                        if(b[i]==0)\n                        {\n                             int r=1+m-a[i]-d[i]+c[i-1];\n                             max=Math.max(max,r);\n                        }\n                        else\n                        {\n                              int l=0;\n                              if(i>0)\n                               l=a[i-1];\n                              int r=c[i]-1+m-a[i]-d[i];\n                              max=Math.max(max,r);\n                        }\n                  }\n                  \n                  if(!hs.contains(v))\n                  {\n                        if(b[i]==0)\n                        {\n                           if(i==n-1)\n                           {\n                              int r=c[i]+1;\n                              max=Math.max(max,r);\n                           }\n                           else\n                           {\n                               int r=c[i]+1+m-a[i+1]-d[i+1];\n                               max=Math.max(max,r);\n                           }\n                        }\n                        else\n                        {\n                                if(i==n-1)\n                                {\n                                   int r=c[i]+m-a[i]-1;\n                                   max=Math.max(max,r);\n                                }\n                                else\n                                {\n                                    int r=c[i]+m-a[i+1]-d[i+1]+a[i+1]-1-a[i];  \n                                    max=Math.max(max,r);\n                                }\n                        }\n                  }\n            }\n            \n            System.out.println(max);\n      }\n}", "complexity": "linear", "problem": "1000_B. Light It Up", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class LightItUp {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t StringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\tint previous = 0;\n\t\tint array[] = new int[n+1];\n\t\tint answer = 0;\n\t\t\n\t\tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tarray[i] = Integer.parseInt(st1.nextToken());\n\t\t\tif(i % 2 == 0){\n\t\t\t\tanswer += (array[i] - previous);\n\t\t\t}\n\t\t\tprevious = array[i];\n\t\t}\n\t\t\n\t\tif(n % 2 == 0){\n\t\t\tanswer += (m - previous);\n\t\t}\n\t\tprevious = m;\n\t\tint max = Integer.MAX_VALUE;\n\t\t\n\t\twhile(n-- != 0){\n\t\t\tint temp = array[n];\n\t\t\tif(n%2 == 0){\n\t\t\t\tarray[n] = array[n+1] - (previous - array[n]);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tarray[n] = array[n+1] + (previous - array[n]);\n\t\t\t}\n\t\t\tprevious = temp;\n\t\t\tmax = Math.min(max, array[n]);\n\t\t}\n\t\tif(max>=-1){\n\t\t\tSystem.out.println(answer);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(answer - (max+1));\n\t\t}\n\n\t}\n\n}\n", "complexity": "linear", "problem": "1000_B. Light It Up", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A\n{\n    public static int palin(String str)\n    {\n        int flag=0;\n        int l=str.length();\n        for(int i=0;i<l/2;i++)\n        {\n            if(str.charAt(i)!=str.charAt(l-i-1))\n            {\n                flag=1;\n                break;\n            }\n        }\n        if(flag==1)\n        return 0;\n        else\n        return 1;\n    }\n    public static void main(String args[])\n    {\n        Scanner sc=new Scanner(System.in);\n        String str=sc.next();\n        HashSet<Character> hs=new HashSet<>();\n        for(int i=0;i<str.length();i++)\n        {\n            hs.add(str.charAt(i));\n        }\n        if(hs.size()==1)\n        System.out.println(0);\n        else if(palin(str)==0)\n        System.out.println(str.length());\n        else\n        System.out.println(str.length()-1);\n    }\n}", "complexity": "linear", "problem": "981_A. Antipalindrome", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n\npublic class Main {\n    static int n=5;\n    static int[] arr=new int[5];\n\n    public static void main(String[] args) {\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        {\n            arr[i]=sc.nextInt();\n        }\n        for (int i=0;i<n;i++)\n        {\n            if (arr[i]>=0)\n            {\n                arr[i]=-arr[i]-1;\n            }\n        }\n        if (n%2!=0)\n        {\n            int min=0;\n            for (int i=1;i<n;i++)\n            {\n                if (arr[i]<arr[min])\n                    min=i;\n            }\n            arr[min]=-arr[min]-1;\n        }\n        for (int x:arr)\n        {\n            System.out.print(x + \" \");\n        }\n\n    }\n}", "complexity": "linear", "problem": "1180_B. Nick and Array", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class NickAndArray {\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\t int array[]=new int[n];\n\t\t int max=Integer.MAX_VALUE;\n\t\t int index=0;\n\t\t for(int i=0;i<n;i++)\n\t\t {\n\t\t\t int k=sc.nextInt();\n\t\t\t array[i]=k;\n\t\t\t if(array[i]>=0)\n\t\t\t {\n\t\t\t\t array[i]=-array[i]-1;\n\t\t\t }\n\t\t\t if(array[i]<max)\n\t\t\t {\n\t\t\t\t max=array[i];\n\t\t\t\t index=i;\n\t\t\t\t \n\t\t\t }\n\t\t }\n\t\t if(n%2!=0)\n\t\t {\n\t\t\t array[index]=-array[index]-1;\n\t\t }\n\t\t for(int i=0;i<n;i++)\n\t\t {\n\t\t\t System.out.print(array[i]+\" \" );\n\t\t }\n\t}\n\n}\n", "complexity": "linear", "problem": "1180_B. Nick and Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class round569d2b {\n\n\tpublic static void main(String args[]) {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\t\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\t\tif (n % 2 == 0) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (arr[i] >= 0) {\n\t\t\t\t\tarr[i] = -1*arr[i]-1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tint max = Integer.MIN_VALUE;\n\t\t\tint maxIndex = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint elem = arr[i];\n\t\t\t\tif (elem < 0) {\n\t\t\t\t\telem = -1*elem-1;\n\t\t\t\t}\n\t\t\t\tif (elem > max) {\n\t\t\t\t\tmax = elem;\n\t\t\t\t\tmaxIndex = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i == maxIndex) {\n\t\t\t\t\tif (arr[i] < 0) {\n\t\t\t\t\t\tarr[i] = -1*arr[i]-1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (arr[i] >= 0) {\n\t\t\t\t\t\tarr[i] = -1*arr[i]-1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < n ;i++) {\n\t\t\tsb.append(arr[i] + \" \");\n\t\t\t\n\t\t}\n\t\tSystem.out.println(sb);\n\n\t}\n\n\t// ======================================================================================\n\t// =============================== Reference Code =======================================\n\t// ======================================================================================\n\n\tstatic int greatestDivisor(int n) {\n\t\tint limit = (int) Math.sqrt(n);\n\t\tint max = 1;\n\t\tfor (int i = 2; i <= limit; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tmax = Integer.max(max, i);\n\t\t\t\tmax = Integer.max(max, n / i);\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n\n\t// Method to return all primes smaller than or equal to \n\t// n using Sieve of Eratosthenes \n\tstatic boolean[] sieveOfEratosthenes(int n) {\n\t\t// Create a boolean array \"prime[0..n]\" and initialize \n\t\t// all entries it as true. A value in prime[i] will \n\t\t// finally be false if i is Not a prime, else true. \n\t\tboolean prime[] = new boolean[n + 1];\n\t\tfor (int i = 0; i <= n; i++)\n\t\t\tprime[i] = true;\n\n\t\tprime[0] = false;\n\t\tprime[1] = false;\n\n\t\tfor (int p = 2; p * p <= n; p++) {\n\t\t\t// If prime[p] is not changed, then it is a prime \n\t\t\tif (prime[p] == true) {\n\t\t\t\t// Update all multiples of p \n\t\t\t\tfor (int i = p * p; i <= n; i += p)\n\t\t\t\t\tprime[i] = false;\n\t\t\t}\n\t\t}\n\n\t\treturn prime;\n\t}\n\n\t// Binary search for number greater than or equal to target\n\t// returns -1 if number not found\n\tprivate static int bin_gteq(int[] a, int key) {\n\t\tint low = 0;\n\t\tint high = a.length;\n\t\tint max_limit = high;\n\t\twhile (low < high) {\n\t\t\tint mid = low + (high - low) / 2;\n\t\t\tif (a[mid] < key) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else\n\t\t\t\thigh = mid;\n\t\t}\n\n\t\treturn high == max_limit ? -1 : high;\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\tif (a == 0)\n\t\t\treturn b;\n\n\t\treturn gcd(b % a, a);\n\t}\n\n\tstatic class Tuple<X, Y> {\n\t\tpublic final X x;\n\t\tpublic final Y y;\n\n\t\tpublic Tuple(X x, Y 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\t}\n\n\tstatic class Tuple3<X, Y, Z> {\n\t\tpublic final X x;\n\t\tpublic final Y y;\n\t\tpublic final Z z;\n\n\t\tpublic Tuple3(X x, Y y, Z z) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.z = z;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \",\" + y + \",\" + z + \")\";\n\t\t}\n\t}\n\n\tstatic Tuple3<Integer, Integer, Integer> gcdExtended(int a, int b, int x, int y) {\n\t\t// Base Case \n\t\tif (a == 0) {\n\t\t\tx = 0;\n\t\t\ty = 1;\n\t\t\treturn new Tuple3(0, 1, b);\n\t\t}\n\n\t\tint x1 = 1, y1 = 1; // To store results of recursive call \n\t\tTuple3<Integer, Integer, Integer> tuple = gcdExtended(b % a, a, x1, y1);\n\t\tint gcd = tuple.z;\n\t\tx1 = tuple.x;\n\t\ty1 = tuple.y;\n\n\t\t// Update x and y using results of recursive \n\t\t// call \n\t\tx = y1 - (b / a) * x1;\n\t\ty = x1;\n\n\t\treturn new Tuple3(x, y, gcd);\n\t}\n\n\t// Returns modulo inverse of a  \n\t// with respect to m using extended \n\t// Euclid Algorithm. Refer below post for details: \n\t// https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/ \n\tstatic int inv(int a, int m) {\n\t\tint m0 = m, t, q;\n\t\tint x0 = 0, x1 = 1;\n\n\t\tif (m == 1)\n\t\t\treturn 0;\n\n\t\t// Apply extended Euclid Algorithm \n\t\twhile (a > 1) {\n\t\t\t// q is quotient \n\t\t\tq = a / m;\n\n\t\t\tt = m;\n\n\t\t\t// m is remainder now, process \n\t\t\t// same as euclid's algo \n\t\t\tm = a % m;\n\t\t\ta = t;\n\n\t\t\tt = x0;\n\n\t\t\tx0 = x1 - q * x0;\n\n\t\t\tx1 = t;\n\t\t}\n\n\t\t// Make x1 positive \n\t\tif (x1 < 0)\n\t\t\tx1 += m0;\n\n\t\treturn x1;\n\t}\n\n\t// k is size of num[] and rem[]. \n\t// Returns the smallest number \n\t// x such that: \n\t// x % num[0] = rem[0], \n\t// x % num[1] = rem[1], \n\t// .................. \n\t// x % num[k-2] = rem[k-1] \n\t// Assumption: Numbers in num[] are pairwise  \n\t// coprime (gcd for every pair is 1) \n\tstatic int findMinX(int num[], int rem[], int k) {\n\t\t// Compute product of all numbers \n\t\tint prod = 1;\n\t\tfor (int i = 0; i < k; i++)\n\t\t\tprod *= num[i];\n\n\t\t// Initialize result \n\t\tint result = 0;\n\n\t\t// Apply above formula \n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint pp = prod / num[i];\n\t\t\tresult += rem[i] * inv(pp, num[i]) * pp;\n\t\t}\n\n\t\treturn result % prod;\n\t}\n\n\t/**\n\t * Source: Matt Fontaine\n\t */\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 chars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tint read() {\n\t\t\tif (chars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= chars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tchars = 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 (chars <= 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\t}\n\n}", "complexity": "linear", "problem": "1180_B. Nick and Array", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author MaxHeap\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    CBanhMi solver = new CBanhMi();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class CBanhMi {\n\n    long mod = (long) (1e9 + 7);\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n      int q = in.nextInt();\n      long[] two = new long[n + 1];\n      two[0] = 1;\n      for (int i = 1; i <= n; ++i) {\n        two[i] = (two[i - 1] * 2L);\n        two[i] %= mod;\n      }\n\n      char[] s = in.nextCharArray();\n      int[] acc = new int[n + 1];\n      for (int i = 1; i <= n; ++i) {\n        acc[i] = s[i - 1] == '0' ? 0 : 1;\n        acc[i] += acc[i - 1];\n      }\n      // 0 0 1 1 | 1: 1 1 2| 2: 2 3| 4: 5| 9\n      // 0 1 1 1| 1: 1 2 2| 2: 3 3| 5: 6| 11\n      // 0 1 1 wwqwq| 1: 1 2 2| 3: 5 3| 8: 8| 16\n      // 0 0 1 1| 1: 1 1 2| 3: 3 3| 6: 6| 12\n      // 0 0 0 1| 1: 1 1 1| 2: 2 2| 4: 4| 8\n      while (q-- > 0) {\n        int f = in.nextInt();\n        int t = in.nextInt();\n        int ones = acc[t] - acc[f - 1];\n        int zeros = (t - f + 1) - ones;\n        if (ones == 0) {\n          out.println(0);\n        } else {\n          long ans = two[t - f + 1] - (zeros > 0 ? two[zeros] : 0);\n          if (zeros == 0) {\n            --ans;\n          }\n          ans = (ans + mod) % mod;\n          out.println(ans);\n        }\n      }\n    }\n\n  }\n\n  static class InputReader implements FastIO {\n\n    private InputStream stream;\n    private static final int DEFAULT_BUFFER_SIZE = 1 << 16;\n    private static final int EOF = -1;\n    private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];\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 == EOF) {\n        throw new UnknownError();\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 ex) {\n            throw new InputMismatchException();\n          }\n\n          if (this.numChars <= 0) {\n            return EOF;\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      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      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 == EOF;\n    }\n\n    public char[] nextCharArray() {\n      return next().toCharArray();\n    }\n\n  }\n\n  static interface FastIO {\n\n  }\n}\n\n", "complexity": "linear", "problem": "1062_C. Banh-mi", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class B {\n\n\tpublic B () {\n\t\tint N = sc.nextInt();\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint [] P = sc.nextInts();\n\n\t\tTreeSet<Integer> S = new TreeSet<>();\n\t\tSet<Integer> A = new HashSet<>();\n\t\tSet<Integer> B = new HashSet<>();\n\n\t\tfor (int p : P) S.add(p);\n\t\twhile (!S.isEmpty()) {\n\t\t\tint q = S.first();\n\t\t\tint x = a - q, y = b - q;\n\t\t\tif (S.contains(x) && S.contains(y)) {\n\t\t\t\tif (x > y) {\n\t\t\t\t\tS.remove(q); S.remove(x);\n\t\t\t\t\tA.add(q); A.add(x);\n\t\t\t\t} else {\n\t\t\t\t\tS.remove(q); S.remove(y);\n\t\t\t\t\tB.add(q); B.add(y);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (S.contains(x)) {\n\t\t\t\tS.remove(q); S.remove(x);\n\t\t\t\tA.add(q); A.add(x);\n\t\t\t}\n\t\t\telse if (S.contains(y)) {\n\t\t\t\tS.remove(q); S.remove(y);\n\t\t\t\tB.add(q); B.add(y);\n\t\t\t}\n\t\t\telse\n\t\t\t\texit(\"NO\");\n\t\t}\n\n\t\tint [] res = new int[N];\n\t\tfor (int i : rep(N))\n\t\t\tif (B.contains(P[i]))\n\t\t\t\tres[i] = 1;\n\n\t\tprint(\"YES\");\n\t\texit(res);\n\t}\n\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\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 (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next() { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t\tpublic String nextLine() { line = null; return readLine(); }\n\t\t\tpublic String [] nextStrings() { return split(nextLine()); }\n\t\t\tpublic int [] nextInts() {\n\t\t\t\tString [] L = nextStrings();\n\t\t\t\tint [] res = new int [L.length];\n\t\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol() { return index == line.length; }\n\t\t\tprivate String readLine() {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine() {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split(String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build(Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim(String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static void start() { if (t == 0) t = millis(); }\n\t\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t\t} else if (o instanceof Iterable<?>)\n\t\t\t\tfor (Object p : (Iterable<?>) o)\n\t\t\t\t\tappend(b, p, delim);\n\t\t\telse {\n\t\t\t\tif (o instanceof Double)\n\t\t\t\t\to = new java.text.DecimalFormat(\"#.############\").format(o);\n\t\t\t\tb.append(delim).append(o);\n\t\t\t}\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print(Object o, Object ... A) { pw.println(build(o, A)); }\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static void exit() {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(IOUtils.time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis() { return System.currentTimeMillis(); }\n\t\tprivate static String time() { return \"Time: \" + (millis() - t) / 1000.0; }\n\t}\n\tpublic static void main (String[] args) { new B(); IOUtils.exit(); }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "/*\n * Hopefully this is AC :D\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\n\npublic class TwoSets {\n\n\tstatic ArrayList<Integer> g[];\n\tstatic boolean visited[];\n\tstatic int ans[],p[],orig[];\n\tstatic int n,a,b;\n\t\n\t@SuppressWarnings(\"unchecked\")\n\tpublic static void main(String args[] ) throws Exception {\n\t\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t    PrintWriter w = new PrintWriter(System.out);\n\t        \n\t    StringTokenizer st1 = new StringTokenizer(br.readLine());\n\t    n = ip(st1.nextToken());\n\t    a = ip(st1.nextToken());\n\t    b = ip(st1.nextToken());\n\t    \n\t    g = new ArrayList[n];\n\t    visited = new boolean[n];\n\t    ans = new int[n];\n\t    p = new int[n];\n\t    orig = new int[n];\n\t    \n\t    StringTokenizer st2 = new StringTokenizer(br.readLine());\n\t    for(int i=0;i<n;i++){\n\t    \tp[i] = ip(st2.nextToken());\n\t    \torig[i] = p[i];\n\t    \tg[i] = new ArrayList<Integer>();\n\t    }\n\t    \n\t    Arrays.sort(p);\n\t    \n\t    boolean impossible = false;\n\t    \n\t    for(int i=0;i<n;i++){\n\t    \tint i1 = Arrays.binarySearch(p, a-p[i]);\n\t    \tint i2 = Arrays.binarySearch(p, b-p[i]);\n\t    \tif(i1 < 0 || i1 >= n)\ti1 = -1;\n\t    \tif(i2 < 0 || i2 >= n)\ti2 = -1;\n\t    \t\n\t    \tif(i1 == -1 && i2 != -1) //if only (b-x) present then both must belong to set 1\n\t    \t\tg[i].add(i2);\n\t    \t\n\t    \telse if(i1 != -1 && i2 == -1) //if only (a-x) present then both must belong to set 0\n\t    \t\tg[i].add(i1);\n\t    \t\n\t    \telse if(i1 != -1 && i2 != -1){ //both present hence all 3 should be in same set,doesn't matter which\n\t    \t\tg[i].add(i1);\n\t    \t\tg[i].add(i2);\n\t    \t}\n\t    \telse{ //if none present then not possible to be in any set\n\t    \t\timpossible = true;\n\t    \t\tbreak;\n\t    \t}\n\t    }\n\t   \n\t    if(impossible){//if any element without both a-x and b-x found\n\t    \tSystem.out.println(\"NO\");\n\t    \treturn;\n\t    }\n\t    \n\t    //Edge between a and b means they must be present in same set\n\t    //ans[i] =0 or ans[i] =1 means it must be compulsory be present in that set\n\t    //ans[i] = -1 means no restrictions on it's set number\n\t    \n\t    LinkedList<Integer>\tq = new LinkedList();//Queue\n\t    for(int i=0;i<n;i++){\n\t    \t\n\t    \tif(visited[i] == false){\n\t    \t\t\n\t    \t\tArrayList<Integer>\tcurq = new ArrayList<Integer>();      //contains indices of all nodes in this connected component\n\t    \t\t\n\t    \t\tcurq.add(i);\n\t    \t\tq.add(i);\n\t    \t\tvisited[i] = true;\n\t    \n\t    \t\twhile(!q.isEmpty()){\n\t    \t\t\tint curr = q.remove();\n\t    \t\t\tint s = g[curr].size();\n\t    \t\t\tfor(int j=0;j<s;j++){\n\t    \t\t\t\tif(!visited[g[curr].get(j)]){\n\t    \t\t\t\t\tvisited[g[curr].get(j)] = true;\n\t    \t\t\t\t\tcurq.add(g[curr].get(j));\n\t    \t\t\t\t\tq.add(g[curr].get(j));\n\t    \t\t\t\t}\n\t    \t\t\t}\n\t    \t\t}\n\t    \n\t    \t\tboolean  found = true;\n\t    \t\t\n    \t\t\tint s = curq.size();\n\t    \t\tint temp[] = new int[s];\n    \t\t\tfor(int j=0;j<s;j++)\n    \t\t\t\ttemp[j] = p[curq.get(j)];\n    \t\t\tArrays.sort(temp);\n    \t\t\t\n    \t\t\tint anss = -1;\n    \t\t\t\n\t    \t\tfor(int j=0;j<s;j++){\n\t    \t\t\tint i3 = Arrays.binarySearch(temp, a - temp[j]);\n\t    \t\t\tif(i3 < 0 || i3 >= n){\n\t   \t\t\t\t\tfound = false;\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\tif(!found){\n\t    \t\t\tfound = true;\n\t    \t\t\t\t\n\t    \t\t\tfor(int j=0;j<s;j++){\n\t\t    \t\t\tint i3 = Arrays.binarySearch(temp, b - temp[j]);\n\t\t   \t\t\t\tif(i3 < 0 || i3 >= n){\n\t\t   \t\t\t\t\tfound = false;\n\t\t   \t\t\t\t\tbreak;\n\t\t   \t\t\t\t}\n\t    \t\t\t}\n\t    \t\t\t\n\t    \t\t\tif(found)\n\t    \t\t\t\tanss = 1;\n\t    \t\t\telse{\n\t    \t\t\t\timpossible = true;\n\t    \t\t\t\tbreak;\n\t    \t\t\t}\n\t    \t\t\t\t    \t\t\t\n\t    \t\t}\n\t    \t\telse\n\t    \t\t\tanss = 0;\n\t    \t\t\n\t    \t\tfor(int j=0;j<s;j++)\n\t    \t\t\tans[curq.get(j)] = anss;\n\t    \t\n\t    \t}\n\t    \t\n\t    \t\n\t    }\n\t    \n\t    if(!impossible){\n\t    \tw.println(\"YES\");\n    \t\tfor(int i=0;i<n;i++){\n    \t\t\tint i1 = Arrays.binarySearch(p, orig[i]);\n    \t\t\tif(ans[i1] == -1)\tans[i1] = 1;\n    \t\t\tw.print(ans[i1] + \" \");\n    \t\t}\n    \t\tw.println();\n    \t}\n\t    else\n\t    \tw.println(\"NO\");\n\t    \n\t    w.close(); \n\t}\n\t\n\tpublic static int ip(String s){\n\t\treturn Integer.parseInt(s);\n\t}\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.*;\nimport java.util.*;\n\n/**\n * Generated by Contest helper plug-in\n * Actual solution is at the bottom\n */\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 Task();\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 long readLong() {\n\t\treturn new BigInteger(readString()).longValue();\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 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 Task implements Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint n = in.readInt();\n\t\tint a = in.readInt();\n\t\tint b = in.readInt();\n\t\t\n\t\tif (a==b) {\n\t\t\tb = 0;\n\t\t}\n\t\t\n\t\tboolean[] where = new boolean[n];\n\t\t\n\t\tHashSet<Integer> set = new HashSet<Integer>();\n\t\tHashMap<Integer,Integer> indexmap = new HashMap<Integer,Integer>();\n\t\t\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tint x = in.readInt();\n\t\t\tindexmap.put(x, i);\n\t\t\tset.add(x);\n\t\t}\n\t\t\n\t\twhile (set.size() > 0) {\n\t\t\tint size = set.size();\n\t\t\tHashSet<Integer> todo = new HashSet<Integer>();\n\t\t\tHashSet<Integer> used = new HashSet<Integer>();\n\t\t\tfor (int x : set) {\n\t\t\t\tif (used.contains(x))\n\t\t\t\t\tcontinue;\n\t\t\t\tint ax = a-x;\n\t\t\t\tint bx = b-x;\n\t\t\t\t\n\t\t\t\tif ((set.contains(ax) && !used.contains(ax)) && (set.contains(bx) && !used.contains(bx))) {\n\t\t\t\t\ttodo.add(x);\n\t\t\t\t} else if (set.contains(ax) && !used.contains(ax)) {\n\t\t\t\t\tused.add(x);\n\t\t\t\t\tused.add(ax);\n\t\t\t\t\ttodo.remove(ax);\n\t\t\t\t\t\n\t\t\t\t\t//chain\n\t\t\t\t\tbx = b-ax;\n\t\t\t\t\twhile (set.contains(bx) && !used.contains(bx)) {\n\t\t\t\t\t\tx = bx;\n\t\t\t\t\t\tax = a-x;\n\t\t\t\t\t\tif (!set.contains(ax) || used.contains(ax)) {\n\t\t\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttodo.remove(x);\n\t\t\t\t\t\ttodo.remove(ax);\n\t\t\t\t\t\tused.add(x);\n\t\t\t\t\t\tused.add(ax);\n\t\t\t\t\t\tbx = b-ax;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t} else if (set.contains(bx) && !used.contains(bx)) {\n\t\t\t\t\tused.add(x);\n\t\t\t\t\tused.add(bx);\n\t\t\t\t\ttodo.remove(bx);\n\t\t\t\t\twhere[indexmap.get(bx)] = true;\n\t\t\t\t\twhere[indexmap.get(x)] = true;\n\t\t\t\t\t\n\t\t\t\t\t//chain\n\t\t\t\t\tax = a-bx;\n\t\t\t\t\twhile (set.contains(ax) && !used.contains(ax)) {\n\t\t\t\t\t\tx = ax;\n\t\t\t\t\t\tbx = b-x;\n\t\t\t\t\t\tif (!set.contains(bx) || used.contains(bx)) {\n\t\t\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttodo.remove(x);\n\t\t\t\t\t\ttodo.remove(bx);\n\t\t\t\t\t\tused.add(x);\n\t\t\t\t\t\tused.add(bx);\n\t\t\t\t\t\twhere[indexmap.get(bx)] = true;\n\t\t\t\t\t\twhere[indexmap.get(x)] = true;\n\t\t\t\t\t\tax = a-bx;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t} else {\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\tset = todo;\n\t\t\tif (set.size() == size) {\n\t\t\t\tSystem.out.println(\"Set size constant!!\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(\"YES\");\n\t\tfor (int i = 0; i<n; i++)\n\t\t\tif (where[i])\n\t\t\t\tSystem.out.print(\"1 \");\n\t\t\telse\n\t\t\t\tSystem.out.print(\"0 \");\n\t}\n}\n\nclass num {\n\t\n\t\n}\n\n///\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.io.FilterInputStream;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.TreeSet;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputUtil in = new InputUtil(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    HashMap<Integer, Integer> left = new HashMap<Integer, Integer>();\n\n    public void solve(int testNumber, InputUtil in, PrintWriter out) {\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n\n        int[] res = new int[n];\n        int[] arr = in.nextIntArray(n);\n\n        IntDeque[] adj = IntDeque.IntDeques(n);\n        boolean[] self = new boolean[n];\n        boolean[] assigned = new boolean[n];\n\n        for (int i = 0; i < n; i++) {\n            left.put(arr[i], i);\n        }\n        for (int i = 0; i < n; i++) {\n            int x = arr[i];\n\n            boolean canA = left.containsKey(a - x);\n            boolean canB = left.containsKey(b - x);\n            if (!canA && !canB) {\n                out.println(\"NO\");\n                return;\n            }\n\n            if (left.containsKey(a - x)) {\n                self[i] |= x == a - x;\n                if (x != a - x) {\n                    adj[i].add(left.get(a - x));\n                }\n            }\n\n            if (left.containsKey(b - x)) {\n                self[i] |= x == b - x;\n                if (x != b - x) {\n                    adj[i].add(left.get(b - x));\n                }\n            }\n        }\n\n        if (a == b) {\n            out.println(\"YES\");\n            out.println(IntArrayUtil.toString(res));\n            return;\n        }\n\n        for (int iter = 0; iter < 2; iter++) {\n            for (int i = 0; i < n; i++) {\n                if (!self[i] && !assigned[i] && (iter == 1 || adj[i].size() == 1)) {\n                    int u = i;\n                    DFS:\n                    while (true) {\n                        assigned[u] = true;\n                        if (self[u] && arr[u] == b - arr[u]) {\n                            res[u] = 1;\n                            break;\n                        }\n                        for (int v : adj[u]) {\n                            if (!assigned[v]) {\n                                assigned[v] = true;\n                                if (arr[u] == b - arr[v]) {\n                                    res[u] = res[v] = 1;\n                                }\n                                for (int newU : adj[v]) {\n                                    if (!assigned[newU]) {\n                                        u = newU;\n                                        continue DFS;\n                                    }\n                                }\n                                break DFS;\n                            }\n                        }\n                        out.println(\"NO\");\n                        return;\n                    }\n                }\n                else if (iter == 1 && !assigned[i] && adj[i].size() == 0 && arr[i] == b - arr[i]) {\n                    res[i] = 1;\n                }\n            }\n        }\n\n        out.println(\"YES\");\n        out.println(IntArrayUtil.toString(res));\n    }\n\n\n}\n\nclass InputUtil {\n\n    JoltyScanner in;\n\n    public InputUtil(InputStream istream) {\n        in = new JoltyScanner(istream);\n    }\n\n    public String next() {\n        return in.next();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    public int[] nextIntArray (int size) {\n        int[] arr = new int[size];\n        for (int i = 0; i < size; i++) {\n            arr[i] = in.nextInt();\n        }\n        return arr;\n    }\n\n}\n\nclass IntDeque implements Iterable<Integer> {\n\n    private int capacity;\n    private int size = 0;\n    private int front = 0;\n    private int back = 0;\n    private int[] deque;\n    public IntDeque() {\n        this(16);\n    }\n    public IntDeque(int capacity) {\n        this.capacity = capacity;\n        deque = new int[capacity];\n    }\n    public static IntDeque[] IntDeques(int length) {\n        IntDeque[] arr = new IntDeque[length];\n        for (int i = 0; i < length; i++) {\n            arr[i] = new IntDeque();\n        }\n        return arr;\n    }\n    public <T extends Iterable<Integer>>IntDeque(T intList) {\n        this(16);\n        addAll(intList);\n    }\n    public IntDeque(int[] intArr) {\n        this(16);\n        for (int i: intArr) {\n            addLast(i);\n        }\n    }\n    public void add(int x) {\n        addLast(x);\n    }\n    public <T extends Iterable<Integer>>void addAll(T intList) {\n        for (int i: intList) {\n            addLast(i);\n        }\n    }\n    public void addLast(int x) {\n        ensureCapacity();\n        size++;\n        deque[back++] = x;\n        if (back == capacity) {\n            back = 0;\n        }\n    }\n\n    public void ensureCapacity() {\n        if (size < capacity) {\n            return;\n        }\n        int[] newDeque = new int[capacity << 1];\n        for (int i = 0, j = front; i < size; i++, j++) {\n            if (j == capacity) {\n                j = 0;\n            }\n            newDeque[i] = deque[j];\n        }\n        deque = newDeque;\n        capacity <<= 1;\n        front = 0;\n        back = size;\n    }\n\n    public Iterator<Integer> iterator() {\n        return new Iterator<Integer>() {\n            int done = 0;\n            int curr = front;\n            public boolean hasNext() {\n                return done < size;\n            }\n            public Integer next() {\n                Integer res = deque[curr++];\n                if (curr == capacity) {\n                    curr = 0;\n                }\n                done++;\n                return res;\n            }\n            public void remove() {\n                throw new UnsupportedOperationException();\n            }\n        };\n    }\n\n    public int size() {\n        return size;\n    }\n\n    public String toString() {\n        if (size == 0) {\n            return \"\";\n        }\n        StringBuilder res = new StringBuilder();\n        for (int i: this) {\n            res.append(i);\n            res.append(\" \");\n        }\n        res.setLength(res.length() - 1);\n        return res.toString();\n    }\n}\n\nclass IntArrayUtil {\n\n    public static String toString(int[] arr) {\n        return toString(arr, \" \");\n    }\n\n    public static String toString(int[] arr, String delimiter) {\n        StringBuilder res = new StringBuilder();\n        for (int i: arr) {\n            res.append(i);\n            res.append(delimiter);\n        }\n        res.setLength(res.length() - delimiter.length());\n        return res.toString();\n    }\n\n}\n\nclass JoltyScanner {\n    public static final int BUFFER_SIZE = 1 << 16;\n\tpublic static final char NULL_CHAR = (char) -1;\n\n\tStringBuilder str = new StringBuilder();\n\tbyte[] buffer = new byte[BUFFER_SIZE];\n\tboolean EOF_FLAG = false;\n\tint bufferIdx = 0, size = 0;\n\tchar c = NULL_CHAR;\n\tBufferedInputStream in;\n\n\tpublic JoltyScanner(InputStream in) {\n\t\tthis.in = new BufferedInputStream(in, BUFFER_SIZE);\n\t}\n\n\tpublic int nextInt() {\n\t\tlong x = nextLong();\n\t\tif (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) {\n\t\t\tthrow new ArithmeticException(\"Scanned value overflows integer\");\n\t\t}\n\t\treturn (int) x;\n\t}\n\n\tpublic long nextLong() {\n\t\tboolean negative = false;\n\t\tif (c == NULL_CHAR) {\n\t\t\tc = nextChar();\n\t\t}\n\t\tfor (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar()) {\n\t\t\tif (c == '-') {\n\t\t\t\tnegative = true;\n\t\t\t}\t\t\t\t\n\t\t}\n\t\tcheckEOF();\n\t\tlong res = 0;\n\t\tfor (; c >= '0' && c <= '9'; c = nextChar()) {\n\t\t\tres = (res << 3) + (res << 1) + c - '0';\n\t\t}\n\t\treturn negative ? -res : res;\n\t}\n\n    public String next() {\n\t\tcheckEOF();\n\t\tif (c == NULL_CHAR) {\n\t\t\tc = nextChar();\n\t\t}\n\t\twhile (Character.isWhitespace(c)) {\n\t\t\tc = nextChar();\n\t\t\tcheckEOF();\n\t\t}\n\t\tstr.setLength(0);\n\t\tfor (; !EOF_FLAG && !Character.isWhitespace(c); c = nextChar()) {\n\t\t\tstr.append(c);\n\t\t}\n\t\treturn str.toString();\n\t}\n\n    public char nextChar() {\n\t\tif (EOF_FLAG) {\n\t\t\treturn NULL_CHAR;\n\t\t}\n\t\twhile (bufferIdx == size) {\n\t\t\ttry {\n\t\t\t\tsize = in.read(buffer);\n\t\t\t\tif (size == -1) {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t} catch (Exception e) {\n\t\t\t\tEOF_FLAG = true;\n\t\t\t\treturn NULL_CHAR;\n\t\t\t}\n\t\t\tif (size == -1) {\n\t\t\t\tsize = BUFFER_SIZE;\n\t\t\t}\n\t\t\tbufferIdx = 0;\n\t\t}\n\t\treturn (char) buffer[bufferIdx++];\n\t}\n\n    public void checkEOF() {\n\t\tif (EOF_FLAG) {\n\t\t\tthrow new EndOfFileException();\n\t\t}\n\t}\n\n\tpublic class EndOfFileException extends RuntimeException {\n\t}\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * 4 4\n * 1 5 3 4\n * 1 2\n * 1 3\n * 2 3\n * 3 3\n *\n *\n * @author pttrung\n */\npublic class A {\n\n    public static long Mod = (long) (1e9 + 7);\n    public static long[][] dp;\n\n    public static void main(String[] args) throws FileNotFoundException {\n\n        PrintWriter out = new PrintWriter(System.out);\n        Scanner in = new Scanner();\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] data = new int[n];\n        int[]u = new int[n];\n        int[]s = new int[n];\n        HashMap<Integer, Integer> map = new HashMap();\n        \n        for(int i = 0; i < n; i++){\n            u[i] = i;\n            data[i] = in.nextInt();\n            map.put(data[i], i);\n        }        \n        boolean ok = true;\n        boolean[]check = new boolean[n];\n        for(int i = 0; i < n; i++){\n            if(map.containsKey(a - data[i])){\n                u[find(i, u)]= u[find(map.get(a- data[i]), u)];\n                s[i] |= 1;\n            }\n            if(map.containsKey(b - data[i])){\n                u[find(i, u)]= u[find(map.get(b- data[i]), u)];\n                s[i] |= 2;\n            }\n            \n        }\n        int[]g = new int[n];\n        Arrays.fill(g,3);\n        for(int i = 0;  i< n; i++){\n            if(s[i] == 0){\n                ok = false;\n                break;\n            }\n            g[find(i, u)] &= s[i];\n            if(g[find(i,u)] == 0){\n                ok = false;\n                break;\n            }\n        }\n        //System.out.println(Arrays.toString(g));\n        if(ok){\n            out.println(\"YES\");\n            for(int i = 0; i < n; i++){\n                if((g[find(i,u)] & 1) == 0){\n                    out.print(1 + \" \");\n                }else{\n                    out.print(0 + \" \");\n                }\n            }\n        }else{\n            out.println(\"NO\");\n        }\n\n        out.close();\n    }\n    \n    static int find(int index, int[]u){\n        if(index != u[index]){\n            return u[index] = find(u[index], u);\n        }\n        return index;\n    }\n\n    public static long pow(int a, int b, long mod) {\n        if (b == 0) {\n            return 1;\n        }\n        if (b == 1) {\n            return a;\n        }\n        long v = pow(a, b / 2, mod);\n        if (b % 2 == 0) {\n            return (v * v) % mod;\n        } else {\n            return (((v * v) % mod) * a) % mod;\n        }\n    }\n\n    public static int[][] powSquareMatrix(int[][] A, long p) {\n        int[][] unit = new int[A.length][A.length];\n        for (int i = 0; i < unit.length; i++) {\n            unit[i][i] = 1;\n        }\n        if (p == 0) {\n            return unit;\n        }\n        int[][] val = powSquareMatrix(A, p / 2);\n        if (p % 2 == 0) {\n            return mulMatrix(val, val);\n        } else {\n            return mulMatrix(A, mulMatrix(val, val));\n        }\n\n    }\n\n    public static int[][] mulMatrix(int[][] A, int[][] B) {\n        int[][] result = new int[A.length][B[0].length];\n        for (int i = 0; i < result.length; i++) {\n            for (int j = 0; j < result[0].length; j++) {\n                long temp = 0;\n                for (int k = 0; k < A[0].length; k++) {\n\n                    temp += ((long) A[i][k] * B[k][j] % Mod);\n                    temp %= Mod;\n                }\n                temp %= Mod;\n                result[i][j] = (int) temp;\n            }\n        }\n\n        return result;\n    }\n\n    public static boolean nextPer(int[] data) {\n        int i = data.length - 1;\n        while (i > 0 && data[i] < data[i - 1]) {\n            i--;\n        }\n        if (i == 0) {\n            return false;\n        }\n        int j = data.length - 1;\n        while (data[j] < data[i - 1]) {\n            j--;\n        }\n        int temp = data[i - 1];\n        data[i - 1] = data[j];\n        data[j] = temp;\n        Arrays.sort(data, i, data.length);\n        return true;\n\n\n\n\n    }\n\n    static class FT {\n\n        int[] data;\n\n        FT(int n) {\n            data = new int[n];\n        }\n\n        void update(int index, int val) {\n            // System.out.println(\"UPDATE INDEX \" + index);\n            while (index < data.length) {\n                data[index] += val;\n                index += index & (-index);\n\n                //    System.out.println(\"NEXT \" +index);\n            }\n        }\n\n        int get(int index) {\n            //  System.out.println(\"GET INDEX \" + index);\n            int result = 0;\n            while (index > 0) {\n                result += data[index];\n                index -= index & (-index);\n                // System.out.println(\"BACK \" + index);\n            }\n            return result;\n        }\n    }\n\n    static long gcd(long a, long b) {\n        if (b == 0) {\n            return a;\n        } else {\n            return gcd(b, a % b);\n        }\n    }\n\n    static long pow(long a, int b) {\n        if (b == 0) {\n            return 1;\n        }\n        if (b == 1) {\n            return a;\n        }\n        long val = pow(a, b / 2);\n        if (b % 2 == 0) {\n\n            return val * val % Mod;\n        } else {\n            return (val * val % Mod) * a % Mod;\n        }\n    }\n\n//    static Point intersect(Point a, Point b, Point c) {\n//        double D = cross(a, b);\n//        if (D != 0) {\n//            return new Point(cross(c, b) / D, cross(a, c) / D);\n//        }\n//        return null;\n//    }\n//\n//    static Point convert(Point a, double angle) {\n//        double x = a.x * cos(angle) - a.y * sin(angle);\n//        double y = a.x * sin(angle) + a.y * cos(angle);\n//        return new Point(x, y);\n//    }\n    static Point minus(Point a, Point b) {\n        return new Point(a.x - b.x, a.y - b.y);\n    }\n//\n//    static Point add(Point a, Point b) {\n//        return new Point(a.x + b.x, a.y + b.y);\n//    }\n//\n\n    /**\n     * Cross product ab*ac\n     *\n     * @param a\n     * @param b\n     * @param c\n     * @return\n     */\n    static double cross(Point a, Point b, Point c) {\n        Point ab = new Point(b.x - a.x, b.y - a.y);\n        Point ac = new Point(c.x - a.x, c.y - a.y);\n        return cross(ab, ac);\n    }\n\n    static double cross(Point a, Point b) {\n        return a.x * b.y - a.y * b.x;\n    }\n\n    /**\n     * Dot product ab*ac;\n     *\n     * @param a\n     * @param b\n     * @param c\n     * @return\n     */\n    static long dot(Point a, Point b, Point c) {\n        Point ab = new Point(b.x - a.x, b.y - a.y);\n        Point ac = new Point(c.x - a.x, c.y - a.y);\n        return dot(ab, ac);\n    }\n\n    static long dot(Point a, Point b) {\n        long total = a.x * b.x;\n        total += a.y * b.y;\n        return total;\n    }\n\n    static double dist(Point a, Point b) {\n        long total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);\n        return Math.sqrt(total);\n    }\n\n    static long norm(Point a) {\n        long result = a.x * a.x;\n        result += a.y * a.y;\n        return result;\n    }\n\n    static double dist(Point a, Point b, Point x, boolean isSegment) {\n        double dist = cross(a, b, x) / dist(a, b);\n        // System.out.println(\"DIST \" + dist);\n\n        if (isSegment) {\n            Point ab = new Point(b.x - a.x, b.y - a.y);\n\n            long dot1 = dot(a, b, x);\n            long norm = norm(ab);\n            double u = (double) dot1 / norm;\n            if (u < 0) {\n                return dist(a, x);\n            }\n\n            if (u > 1) {\n                return dist(b, x);\n            }\n        }\n        return Math.abs(dist);\n\n\n\n\n    }\n\n    static long squareDist(Point a, Point b) {\n        long x = a.x - b.x;\n        long y = a.y - b.y;\n        return x * x + y * y;\n    }\n\n    static class Point {\n\n        int x, y;\n\n        public Point(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        @Override\n        public String toString() {\n            return \"Point{\" + \"x=\" + x + \", y=\" + y + '}';\n        }\n    }\n\n    static class Scanner {\n\n        BufferedReader br;\n        StringTokenizer st;\n\n        public Scanner() throws FileNotFoundException {\n            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n            br = new BufferedReader(new InputStreamReader(System.in));\n            //br = new BufferedReader(new FileReader(new File(\"A-large (2).in\")));\n        }\n\n        public String next() {\n\n\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (Exception e) {\n                    throw new RuntimeException();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public String nextLine() {\n            st = null;\n            try {\n                return br.readLine();\n            } catch (Exception e) {\n                throw new RuntimeException();\n            }\n        }\n\n        public boolean endLine() {\n            try {\n                String next = br.readLine();\n                while (next != null && next.trim().isEmpty()) {\n                    next = br.readLine();\n                }\n                if (next == null) {\n                    return true;\n                }\n                st = new StringTokenizer(next);\n                return st.hasMoreTokens();\n            } catch (Exception e) {\n                throw new RuntimeException();\n            }\n        }\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class Main {\n\t\n\tstatic int n;\n\tstatic int a;\n\tstatic int b;\n\tstatic int g;\n\tstatic int ref;\n\tstatic int refg;\n\tstatic HashSet<Integer> cgroup;\n\tstatic HashMap<Integer,Integer> indexmap;\n\tstatic HashSet<Integer> nums;\n\tstatic HashSet<Integer> used;\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tn = scan.nextInt();\n\t\ta = scan.nextInt();\n\t\tb = scan.nextInt();\n\t\t\n\t\tboolean[] where = new boolean[n];\n\t\tindexmap = new HashMap<Integer,Integer>();\n\t\tused = new HashSet<Integer>();\n\t\tnums = new HashSet<Integer>();\n\t\t\n\t\tif (a==b)\n\t\t\tb = 0;\n\t\t\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tint x = scan.nextInt();\n\t\t\tnums.add(x);\n\t\t\tindexmap.put(x,i);\n\t\t}\n\t\tscan.close();\n\t\t\n\t\tfor (int x : nums) {\n\t\t\tif (used.contains(x))\n\t\t\t\tcontinue;\n\t\t\tcgroup = new HashSet<Integer>();\n\t\t\tcgroup.add(x);\n\t\t\tg = -1;\n\t\t\trefg = -1;\n\t\t\tref = -1;\n\t\t\tused.add(x);\n\t\t\tif (!spawn(x,a,b) || !spawn(x,b,a)) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (cgroup.size()%2==1 && ref == -1) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\tboolean w = true;\n\t\t\t\tif (g == a)\n\t\t\t\t\tw = false;\n\t\t\t\tfor (int k : cgroup) {\n\t\t\t\t\twhere[indexmap.get(k)] = w;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(\"YES\");\n\t\tfor (int i = 0; i<where.length; i++)\n\t\t\tif (where[i])\n\t\t\t\tSystem.out.print(\"1 \");\n\t\t\telse\n\t\t\t\tSystem.out.print(\"0 \");\n\t\t\n\t}\n\n\tprivate static boolean spawn(int x, int ab, int abo) {\n\t\tint xab = ab-x;\n\t\tif (xab == x) {\n\t\t\tref = x;\n\t\t\trefg = ab;\n\t\t} else {\n\t\t\tif (nums.contains(xab)) {\n\t\t\t\tcgroup.add(xab);\n\t\t\t\tused.add(xab);\n\t\t\t\tspawn(xab,abo,ab);\n\t\t\t} else {\n\t\t\t\tif (g == -1)\n\t\t\t\t\tg = abo;\n\t\t\t\telse if (g != abo) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n    void solve() throws IOException {\n        in = new InputReader(\"__std\");\n        out = new OutputWriter(\"__std\");\n\n        int n = in.readInt();\n        int a = in.readInt();\n        int b = in.readInt();\n        int ma = 0;\n        int mb = 1;\n        if (a < b) {\n            int t = a; a = b; b = t;\n            t = ma; ma = mb; mb = t;\n        }\n        final int[] p = new int[n];\n        Integer id[] = new Integer[n];\n        Map<Integer, Integer> pos = new HashMap<Integer, Integer>();\n        for (int i = 0; i < n; ++i) {\n            p[i] = in.readInt();\n            id[i] = i;\n            pos.put(p[i], i);\n        }\n        Arrays.sort(id, new Comparator<Integer>() {\n            public int compare(Integer i, Integer j) {\n                return p[i] - p[j];\n            }\n        });\n        int[] mask = new int[n];\n        Arrays.fill(mask, -1);\n        boolean flag = true;\n        for (int i = 0; i < n && flag; ++i) {\n            if (mask[id[i]] == -1) {\n                if (p[id[i]] < a) {\n                    if (pos.containsKey(a - p[id[i]])) {\n                        int j = pos.get(a - p[id[i]]);\n                        if (mask[j] != mb) {\n                            mask[id[i]] = mask[j] = ma;\n                            continue;\n                        }\n                    }\n                    if (p[id[i]] < b && pos.containsKey(b - p[id[i]])) {\n                        int j = pos.get(b - p[id[i]]);\n                        if (mask[j] != ma) {\n                            mask[id[i]] = mask[j] = mb;\n                            continue;\n                        }\n                    }\n                }\n                flag = false;\n            }\n        }\n        if (flag) {\n            out.println(\"YES\");\n            for (int m : mask) {\n                out.print(m + \" \");\n            }\n        } else {\n            out.println(\"NO\");\n        }\n\n        exit();\n    }\n\n    void exit() {\n        //System.err.println((System.currentTimeMillis() - startTime) + \" ms\");\n        out.close();\n        System.exit(0);\n    }\n\n    InputReader in;\n    OutputWriter out;\n\n    //long startTime = System.currentTimeMillis();\n\n    public static void main(String[] args) throws IOException {\n        new B().solve();\n    }\n\n    class InputReader {\n\n        private InputStream stream;\n\n        private byte[] buffer = new byte[1024];\n        private int pos, len;\n\n        private int cur;\n\n        private StringBuilder sb = new StringBuilder(32);\n\n        InputReader(String name) throws IOException {\n            if (name.equals(\"__std\")) {\n                stream = System.in;\n            } else {\n                stream = new FileInputStream(name);\n            }\n            cur = read();\n        }\n\n        private int read() throws IOException {\n            if (len == -1) {\n                throw new EOFException();\n            }\n            if (pos >= len) {\n                pos = 0;\n                len = stream.read(buffer);\n                if (len == -1) return -1;\n            }\n            return buffer[pos++];\n        }\n\n        char readChar() throws IOException {\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            char res = (char) cur;\n            cur = read();\n            return res;\n        }\n\n        int readInt() throws IOException {\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            while (whitespace()) {\n                cur = read();\n            }\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            int sign = 1;\n            if (cur == '-') {\n                sign = -1;\n                cur = read();\n            }\n            int res = 0;\n            while (!whitespace()) {\n                if (cur < '0' || cur > '9') {\n                    throw new NumberFormatException();\n                }\n                res *= 10;\n                res += cur - '0';\n                cur = read();\n            }\n            return res * sign;\n        }\n\n        long readLong() throws IOException {\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            return Long.parseLong(readToken());\n        }\n\n        double readDouble() throws IOException {\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            return Double.parseDouble(readToken());\n        }\n\n        String readLine() throws IOException {\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            sb.setLength(0);\n            while (cur != -1 && cur != '\\r' && cur != '\\n') {\n                sb.append((char) cur);\n                cur = read();\n            }\n            if (cur == '\\r') {\n                cur = read();\n            }\n            if (cur == '\\n') {\n                cur = read();\n            }\n            return sb.toString();\n        }\n\n        String readToken() throws IOException {\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            while (whitespace()) {\n                cur = read();\n            }\n            if (cur == -1) {\n                throw new EOFException();\n            }\n            sb.setLength(0);\n            while (!whitespace()) {\n                sb.append((char) cur);\n                cur = read();\n            }\n            return sb.toString();\n        }\n\n        boolean whitespace() {\n            return cur == ' ' || cur == '\\t' || cur == '\\r' || cur == '\\n' || cur == -1;\n        }\n\n        boolean eof() {\n            return cur == -1;\n        }\n    }\n\n    class OutputWriter {\n\n        private PrintWriter writer;\n\n        OutputWriter(String name) throws IOException {\n            if (name.equals(\"__std\")) {\n                writer = new PrintWriter(System.out);\n            } else {\n                writer = new PrintWriter(name);\n            }\n        }\n\n        void print(String format, Object ... args) {\n            writer.print(new Formatter(Locale.US).format(format, args));\n        }\n\n        void println(String format, Object ... args) {\n            writer.println(new Formatter(Locale.US).format(format, args));\n        }\n\n        void print(Object value) {\n            writer.print(value);\n        }\n\n        void println(Object value) {\n            writer.println(value);\n        }\n\n        void println() {\n            writer.println();\n        }\n\n        void close() {\n            writer.close();\n        }\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Map;\n\n/**\n * Created by hama_du on 2014/09/21.\n */\npublic class ProblemB {\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        long a = in.nextLong();\n        long b = in.nextLong();\n        long[] x = new long[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = in.nextLong();\n        }\n\n        Map<Long,Integer> idxmap = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            idxmap.put(x[i], i);\n        }\n        if (a == b) {\n            solve1(x, a, idxmap, out);\n            return;\n        }\n\n        int[] mark = new int[n];\n        Arrays.fill(mark, -1);\n        boolean isok = true;\n        for (int i = 0 ; i < n ; i++) {\n            if (mark[i] != -1) {\n                continue;\n            }\n            long w = x[i];\n            long aw = a - w;\n            long bw = b - w;\n            if (idxmap.containsKey(aw) && idxmap.containsKey(bw)) {\n                continue;\n            } else if (idxmap.containsKey(bw)) {\n                long w1 = w;\n                long w2 = bw;\n                while (true) {\n                    if (!idxmap.containsKey(w1) || !idxmap.containsKey(w2)) {\n                        break;\n                    }\n                    int i1 = idxmap.get(w1);\n                    int i2 = idxmap.get(w2);\n                    if (mark[i1] == 0 || mark[i2] == 0) {\n                        isok = false;\n                    }\n                    mark[i1] = 1;\n                    mark[i2] = 1;\n                    if (w1 + a - b == w2) {\n                        break;\n                    }\n                    w1 += (a - b);\n                    w2 += (b - a);\n                }\n            } else if (idxmap.containsKey(aw)){\n                long w1 = w;\n                long w2 = aw;\n                while (true) {\n                    if (!idxmap.containsKey(w1) || !idxmap.containsKey(w2)) {\n                        break;\n                    }\n                    int i1 = idxmap.get(w1);\n                    int i2 = idxmap.get(w2);\n                    if (mark[i1] == 1 || mark[i2] == 1) {\n                        isok = false;\n                    }\n                    mark[i1] = 0;\n                    mark[i2] = 0;\n                    if (w1 + b - a == w2) {\n                        break;\n                    }\n                    w1 += (b - a);\n                    w2 += (a - b);\n                }\n            }\n        }\n        for (int i = 0 ; i < n ; i++) {\n            if (mark[i] == -1) {\n                isok = false;\n                break;\n            }\n        }\n        if (isok) {\n            printAnswer(mark, out);\n        } else {\n            out.println(\"NO\");\n        }\n        out.flush();\n    }\n\n    private static void printAnswer(int[] mark, PrintWriter out) {\n        out.println(\"YES\");\n        StringBuilder ln = new StringBuilder();\n        for (int m : mark) {\n            ln.append(' ').append(m);\n        }\n        out.println(ln.substring(1));\n    }\n\n    private static void solve1(long[] x, long a, Map<Long, Integer> idxmap, PrintWriter out) {\n        int[] mark = new int[x.length];\n        for (int i = 0 ; i < x.length ; i++) {\n            if (mark[i] == 1) {\n                continue;\n            }\n            long w = x[i];\n            long wp = a - w;\n            if (idxmap.containsKey(wp)) {\n                mark[i] = mark[idxmap.get(wp)] = 1;\n            }\n        }\n        boolean isok = true;\n        for (int i = 0 ; i < x.length ; i++) {\n            if (mark[i] == 0) {\n                isok = false;\n                break;\n            }\n        }\n        if (isok) {\n            printAnswer(mark, out);\n        } else {\n            out.println(\"NO\");\n        }\n        out.flush();\n    }\n\n    public static void debug(Object... o) {\n        System.err.println(Arrays.deepToString(o));\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 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 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            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", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.util.TreeMap;\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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.readInt();\n        int a = in.readInt();\n        int b = in.readInt();\n        TreeMap<Integer, Integer> mp = new TreeMap<Integer, Integer>();\n        for (int i = 0; i < n; ++i) {\n            mp.put(in.readInt(), i);\n        }\n        int aname = 0;\n        int bname = 1;\n        if (a > b) {\n            int t = a;\n            a = b;\n            b = t;\n            aname = 1;\n            bname = 0;\n        }\n        int[] res = new int[n];\n        while (mp.size() > 0) {\n            Map.Entry<Integer, Integer> e = mp.firstEntry();\n            int val = e.getKey();\n            if (mp.containsKey(b - val)) {\n                res[mp.get(val)] = res[mp.get(b - val)] = bname;\n                mp.remove(val);\n                mp.remove(b - val);\n            } else if (mp.containsKey(a - val)) {\n                res[mp.get(val)] = res[mp.get(a - val)] = aname;\n                mp.remove(val);\n                mp.remove(a - val);\n            } else {\n                break;\n            }\n        }\n        if (mp.size() > 0) {\n            out.println(\"NO\");\n        } else {\n            out.println(\"YES\");\n            for (int i = 0; i < n; ++i) {\n                if (i > 0) out.print(\" \");\n                out.print(res[i]);\n            }\n            out.println();\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        // InputMismatchException -> UnknownError\n        if (numChars == -1)\n            throw new UnknownError();\n        if (curChar >= numChars) {\n            curChar = 0;\n            try {\n                numChars = stream.read(buf);\n            } catch (IOException e) {\n                throw new UnknownError();\n            }\n            if (numChars <= 0)\n                return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public int readInt() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        } else if (c == '+') {\n            c = read();\n        }\n        int res = 0;\n        do {\n            if (c < '0' || c > '9')\n                throw new InputMismatchException();\n            res *= 10;\n            res += c - '0';\n            c = read();\n        } while (!isSpaceChar(c));\n        return res * sgn;\n    }\n\n    public static boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\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.util.HashSet;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\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    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] p = new int[n];\n        for (int i = 0; i < n; ++i)\n            p[i] = in.nextInt();\n        Map<Integer, Integer> position = new HashMap<>(n);\n        for (int i = 0; i < n; ++i)\n            position.put(p[i], i);\n        DisjointSet sets = new DisjointSet(n);\n        for (int i = 0; i < n; ++i) {\n            if (position.containsKey(a - p[i]))\n                sets.joinSet(i, position.get(a - p[i]));\n            if (position.containsKey(b - p[i]))\n                sets.joinSet(i, position.get(b - p[i]));\n        }\n        Group[] groups = new Group[n];\n        for (int i = 0; i < n; ++i)\n            if (sets.getSet(i) == i)\n                groups[i] = new Group();\n        for (int i = 0; i < n; ++i)\n            groups[sets.getSet(i)].value.add(p[i]);\n        int[] answer = new int[n];\n        for (Group group : groups) if (group != null) {\n            if (group.check(a)) {\n                for (int key : group.value)\n                    answer[position.get(key)] = 0;\n            } else if (group.check(b)) {\n                for (int key : group.value)\n                    answer[position.get(key)] = 1;\n            } else {\n                out.println(\"NO\");\n                return;\n            }\n        }\n        out.println(\"YES\");\n        for (int i = 0; i < n; ++i) {\n            if (i > 0) out.print(' ');\n            out.print(answer[i]);\n        }\n        out.println();\n    }\n\n    class Group {\n        Set<Integer> value = new HashSet<>();\n\n        boolean check(int sum) {\n            for (int key : value)\n                if (!value.contains(sum - key))\n                    return false;\n            return true;\n        }\n    }\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream), 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        return tokenizer.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n}\n\nclass DisjointSet {\n    private final int[] label;\n    private int numSets;\n    private Listener listener;\n\n    public DisjointSet(int n, Listener listener) {\n        label = new int[n];\n        Arrays.fill(label, -1);\n        numSets = n;\n        this.listener = listener;\n    }\n\n    public DisjointSet(int n) {\n        this(n, null);\n    }\n\n    public int getSet(int at) {\n        if (label[at] < 0) return at;\n        return label[at] = getSet(label[at]);\n    }\n\n    public boolean sameSet(int u, int v) {\n        return getSet(u) == getSet(v);\n    }\n\n    public boolean joinSet(int u, int v) {\n        if (sameSet(u, v)) return false;\n        u = getSet(u);\n        v = getSet(v);\n        if (label[u] < label[v]) {\n            int tmp = u;\n            u = v;\n            v = tmp;\n        }\n        label[v] += label[u];\n        label[u] = v;\n        --numSets;\n        if (listener != null) listener.joined(u, v);\n        return true;\n    }\n\n    public static interface Listener {\n        public void joined(int joinedRoot, int root);\n    }\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.Set;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\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 <aladdin3>\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    public void solve(int testNumber, InputReader jin, OutputWriter jout) {\n        int n = jin.int32();\n        int a = jin.int32();\n        int b = jin.int32();\n\n\n\n        Set<Integer> present = new HashSet<Integer>();\n        int[] arr = new int[n];\n        int[] sarr = new int[n];\n        for(int i = 0; i < n; i++) {\n            sarr[i] = arr[i] = jin.int32();\n            present.add(arr[i]);\n        }\n\n        boolean rev = b < a;\n        if(b < a) {b ^= a; a ^= b; b ^= a; }\n\n        Arrays.sort(sarr);\n\n        Set<Integer> set1 = new HashSet<Integer>();\n        Set<Integer> set2 = new HashSet<Integer>();\n\n        for(int i = 0; i < n; i++) {\n            if(set1.contains(sarr)) continue;\n            if(set2.contains(sarr)) continue;\n            int comp1 = b - sarr[i];\n            if(present.contains(comp1)) {\n                set2.add(sarr[i]);\n                set2.add(comp1);\n                present.remove(comp1);\n            } else {\n                int comp2 = a - sarr[i];\n                if(present.contains(comp2)) {\n                    set1.add(sarr[i]);\n                    set1.add(comp2);\n                    present.remove(comp2);\n                } else {\n                    jout.println(\"NO\");\n                    return;\n                }\n            }\n        }\n\n        jout.println(\"YES\");\n        for(int i = 0; i < n; i++) {\n            if(i != 0) jout.print(' ');\n            if(rev) jout.print(set2.contains(arr[i])? 0 : 1);\n            else jout.print(set1.contains(arr[i])? 0 : 1);\n        }\n    }\n}\n\nclass InputReader {\n    private static final int bufferMaxLength = 1024;\n    private InputStream in;\n    private byte[] buffer;\n    private int currentBufferSize;\n    private int currentBufferTop;\n    private static final String tokenizers = \" \\t\\r\\f\\n\";\n    \n    public InputReader(InputStream stream) {\n        this.in = stream;\n        buffer = new byte[bufferMaxLength];\n        currentBufferSize = 0;\n        currentBufferTop = 0;\n    }\n    \n    private boolean refill() {\n        try {\n            this.currentBufferSize = this.in.read(this.buffer);\n            this.currentBufferTop = 0;\n        } catch(Exception e) {}\n        return this.currentBufferSize > 0;\n    }\n    \n    \n    private Byte readChar() {\n        if(currentBufferTop < currentBufferSize) {\n            return this.buffer[this.currentBufferTop++];\n        } else {\n            if(!this.refill()) {\n                return null;\n            } else {\n                return readChar();\n            }\n        }\n    }\n\n    public String token()  {\n        StringBuffer tok = new StringBuffer();\n        Byte first;\n        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));\n        if(first == null) return null;\n        tok.append((char)first.byteValue());\n        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {\n            tok.append((char)first.byteValue());\n        }\n        return tok.toString();\n    }\n    \n    public Integer int32() throws NumberFormatException {\n        String tok = token();\n        return tok == null? null : Integer.parseInt(tok);\n    }\n\n    }\n\nclass OutputWriter {\n    private final int bufferMaxOut = 1024;\n    private PrintWriter out;\n    private StringBuilder output;\n    private boolean forceFlush = false;\n\n    public OutputWriter(OutputStream outStream) {\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outStream)));\n        output = new StringBuilder(2 * bufferMaxOut);\n    }\n\n    public OutputWriter(Writer writer) {\n        forceFlush = true;\n        out = new PrintWriter(writer);\n        output = new StringBuilder(2 * bufferMaxOut);\n    }\n\n    private void autoFlush() {\n        if(forceFlush || output.length() >= bufferMaxOut) {\n            flush();\n        }\n    }\n\n    public void print(Object... tokens) {\n        for(int i = 0; i < tokens.length; i++) {\n            if(i != 0) output.append(' ');\n            output.append(tokens[i]);\n        }\n        autoFlush();\n    }\n\n    public void println(Object... tokens) {\n        print(tokens);\n        output.append('\\n');\n        autoFlush();\n    }\n\n    public void flush() {\n        out.print(output);\n        output.setLength(0);\n    }\n\n    public void close() {\n        flush();\n        out.close();\n    }\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class CF_468B {\n    public static void main(String[] args) throws IOException {\n        new CF_468B().solve();\n    }\n    \n    int root(int[] father, int a){\n        if (father[a]==a) return a;\n        else return father[a]=root(father, father[a]);\n    }\n    void unite(int[] father, int a, int b){\n        father[root(father, a)]=root(father, b);\n    }\n    \n    \n    private void solve() throws IOException{\n        \n        InputStream in = System.in;\n        PrintStream out = System.out;\n        \n//        in = new FileInputStream(\"in.txt\");\n//        out = new PrintStream(\"out.txt\");\n        \n        long mod=1_000_000_007;\n        Scanner sc=new Scanner(in);\n        int n=sc.nextInt();\n        long a=sc.nextLong(), b=sc.nextLong();\n\n        int[] father=new int[n];\n        long[] p=new long[n];\n        HashMap<Long, Integer> pos=new HashMap<Long, Integer>();\n        for (int i=0;i<n;i++){\n            father[i]=i;\n            p[i]=sc.nextLong();\n            pos.put(p[i],i);\n        }        \n        for (int i=0;i<n;i++){\n            if (pos.containsKey(a-p[i])) unite(father,i,pos.get(a-p[i]) );\n            if (pos.containsKey(b-p[i])) unite(father,i,pos.get(b-p[i]) );\n        }\n        boolean[] canA=new boolean[n],\n                canB=new boolean[n];\n        Arrays.fill(canA,true);\n        Arrays.fill(canB,true);\n        for (int i=0;i<n;i++){\n            if (!pos.containsKey(a-p[i]) || \n                    root(father, i)!=root(father, pos.get(a-p[i]))) \n                canA[root(father, i)]=false;\n            if (!pos.containsKey(b-p[i]) || \n                    root(father, i)!=root(father, pos.get(b-p[i]))) \n                canB[root(father, i)]=false;\n            if (!canA[root(father,i)] && !canB[root(father,i)]){\n                out.println(\"NO\");\n                return;                    \n            }\n        }\n        out.println(\"YES\");\n        for (int i=0;i<n;i++)\n            if (canA[root(father, i)])\n                out.print(\"0 \");\n            else\n                out.print(\"1 \");\n            \n                \n    }\n}\n\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "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.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\tFastScanner in = new FastScanner(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\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tList<Clause> clauses = new ArrayList<Clause>();\n\t\tint[] p = new int[n];\n\t\tMap<Integer, Integer> id = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tp[i] = in.nextInt();\n\t\t\tid.put(p[i], i);\n\t\t}\n\t\t// var[i] = true means p[i] \\in A\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = p[i];\n\t\t\tInteger j = id.get(a - x);\n\t\t\tif (j == null) {\n\t\t\t\t// var[i] is false\n\t\t\t\tclauses.add(new Clause(i, i, true, false));\n\t\t\t} else {\n\t\t\t\tclauses.add(new Clause(i, j, true, true));\n\t\t\t\tclauses.add(new Clause(j, i, false, false));\n\t\t\t}\n\n\t\t\tj = id.get(b - x);\n\t\t\tif (j == null) {\n\t\t\t\t// var[i] is true\n\t\t\t\tclauses.add(new Clause(i, i, false, true));\n\t\t\t} else {\n\t\t\t\tclauses.add(new Clause(i, j, false, false));\n\t\t\t\tclauses.add(new Clause(j, i, true, true));\n\t\t\t}\n\t\t}\n\t\tSAT2Solver solver = new SAT2Solver(n);\n\t\tif (!solver.solve(clauses)) {\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tout.println(\"YES\");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i > 0) {\n\t\t\t\tout.print(\" \");\n\t\t\t}\n\t\t\tif (solver.isTrue[i]) {\n\t\t\t\tout.print(0);\n\t\t\t} else {\n\t\t\t\tout.print(1);\n\t\t\t}\n\t\t}\n\t\tout.println();\n\t}\n\n\tclass Clause {\n\t\tint v1, v2;\n\t\tboolean neg1, neg2;\n\n\t\t// Example: (x=>!y) is translated to Clause(x, y, true, false)\n\t\tClause(int v1, int v2, boolean pos1, boolean pos2) {\n\t\t\tthis.v1 = v1;\n\t\t\tthis.v2 = v2;\n\t\t\tthis.neg1 = !pos1;\n\t\t\tthis.neg2 = !pos2;\n\t\t}\n\t}\n\n\tclass SAT2Solver {\n\t\tList<Integer>[] g;\n\t\tboolean[] isTrue;\n\t\tint n;\n\n\t\tint numComps;\n\t\tint[] low;\n\t\tint[] vis;\n\t\tint[] comp;\n\t\tboolean[] onStack;\n\t\tint[] stack;\n\t\tint sp;\n\t\tint globalTime;\n\n\t\tSAT2Solver(int n) {\n\t\t\tthis.n = n;\n\t\t\tisTrue = new boolean[2 * n];\n\t\t\tvis = new int[2 * n];\n\t\t\tlow = new int[2 * n];\n\t\t\tstack = new int[2 * n];\n\t\t\tcomp = new int[2 * n];\n\t\t\tonStack = new boolean[2 * n];\n\t\t\tg = new List[2 * n];\n\t\t}\n\n\t\tpublic boolean solve(List<Clause> clauses) {\n\t\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\t\tg[i] = new ArrayList<Integer>();\n\t\t\t}\n\t\t\tfor (Clause clause : clauses) {\n\t\t\t\tint v1 = clause.v1;\n\t\t\t\tint v2 = clause.v2;\n\t\t\t\tboolean neg1 = clause.neg1;\n\t\t\t\tboolean neg2 = clause.neg2;\n\t\t\t\tif (neg1) {\n\t\t\t\t\tv1 = negate(v1);\n\t\t\t\t}\n\t\t\t\tif (neg2) {\n\t\t\t\t\tv2 = negate(v2);\n\t\t\t\t}\n\t\t\t\t//g[negate(v1, n)].add(v2);\n\t\t\t\t//g[negate(v2, n)].add(v1);\n\t\t\t\tg[v1].add(v2);\n\t\t\t}\n\t\t\tArrays.fill(vis, -1);\n\t\t\tArrays.fill(onStack, false);\n\t\t\tsp = 0;\n\t\t\tglobalTime = 0;\n\t\t\tnumComps = 0;\n\t\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\t\tif (vis[i] < 0) {\n\t\t\t\t\tdfsTarjan(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] firstInComp = new int[numComps];\n\t\t\tArrays.fill(firstInComp, -1);\n\t\t\tint[] nextSameComp = new int[2 * n];\n\t\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\t\tint c = comp[i];\n\t\t\t\tnextSameComp[i] = firstInComp[c];\n\t\t\t\tfirstInComp[c] = i;\n\t\t\t}\n\t\t\tList<Integer>[] invertedCompEdges = new List[numComps];\n\t\t\tfor (int i = 0; i < numComps; i++) {\n\t\t\t\tinvertedCompEdges[i] = new ArrayList<Integer>();\n\t\t\t}\n\t\t\tfor (int i = 0; i < 2*n; i++) {\n\t\t\t\tfor (int j : g[i]) {\n\t\t\t\t\tinvertedCompEdges[comp[j]].add(comp[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean[] compIsTrue = new boolean[numComps];\n\t\t\tArrays.fill(compIsTrue, true);\n\t\t\tfor (int c = 0; c < numComps; c++) {\n\t\t\t\tif (!compIsTrue[c]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int i = firstInComp[c]; i >= 0; i = nextSameComp[i]) {\n\t\t\t\t\tint nc = comp[negate(i)];\n\t\t\t\t\tif (c == nc) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int i = firstInComp[c]; i >= 0; i = nextSameComp[i]) {\n\t\t\t\t\tint nc = comp[negate(i)];\n\t\t\t\t\tdfsReject(nc, invertedCompEdges, compIsTrue);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\t\tisTrue[i] = compIsTrue[comp[i]];\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (isTrue[i] && isTrue[negate(i)]) {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t\tif (!isTrue[i] && !isTrue[negate(i)]) {\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 negate(int i) {\n\t\t\treturn i + (i < n ? n : -n);\n\t\t}\n\n\t\tprivate void dfsReject(int c, List<Integer>[] invertedCompEdges, boolean[] compIsTrue) {\n\t\t\tif (!compIsTrue[c]) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcompIsTrue[c] = false;\n\t\t\tfor (int p : invertedCompEdges[c]) {\n\t\t\t\tdfsReject(p, invertedCompEdges, compIsTrue);\n\t\t\t}\n\t\t}\n\n\t\tvoid dfsTarjan(int v) {\n\t\t\tvis[v] = globalTime;\n\t\t\tlow[v] = globalTime;\n\t\t\t++globalTime;\n\t\t\tstack[sp++] = v;\n\t\t\tonStack[v] = true;\n\t\t\tfor (int u : g[v]) {\n\t\t\t\tif (vis[u] < 0) {\n\t\t\t\t\tdfsTarjan(u);\n\t\t\t\t\tif (low[v] > low[u]) {\n\t\t\t\t\t\tlow[v] = low[u];\n\t\t\t\t\t}\n\t\t\t\t} else if (onStack[u] && low[v] > vis[u]) {\n\t\t\t\t\tlow[v] = vis[u];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (low[v] == vis[v]) {\n\t\t\t\twhile (true) {\n\t\t\t\t\tint u = stack[--sp];\n\t\t\t\t\tonStack[u] = false;\n\t\t\t\t\tcomp[u] = numComps;\n\t\t\t\t\tif (u == v) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++numComps;\n\t\t\t}\n\t\t}\n\n\t}\n\n\n\n}\n\nclass FastScanner {\n\n\tprivate BufferedReader in;\n\tprivate StringTokenizer st;\n\n\tpublic FastScanner(InputStream stream) {\n\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t}\n\n\tpublic String next() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tString rl = in.readLine();\n\t\t\t\tif (rl == null) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(rl);\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}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Map.Entry;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class Main {\n\n    public static void main(String[] args) {\n\n        Scanner in = new Scanner(new BufferedInputStream(System.in));\n        PrintWriter out = new PrintWriter(new BufferedWriter(\n                new OutputStreamWriter(System.out)));\n\n        while (in.hasNext()) {\n            int n = in.nextInt(), a = in.nextInt(), b = in.nextInt(), c = 0;\n            int[] p = new int[n];\n\n            TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();\n            for (int i = 0; i < n; i++) {\n                p[i] = in.nextInt();\n                map.put(p[i], i);\n            }\n            \n            if (a > b) {\n                int t = b;\n                b = a;\n                a = t;\n                c = 1;\n            }\n\n            boolean ok = true;\n            int[] cls = new int[n];\n            while (ok && map.size() > 0) {\n                Entry<Integer, Integer> last = map.lastEntry();\n                int v = last.getKey();\n                int idx = last.getValue();\n                if (map.containsKey(a - v)) {\n                    cls[idx] = 0;\n                    cls[map.get(a - v)] = 0;\n                    map.remove(v);\n                    map.remove(a -v);\n                } else if (map.containsKey(b - v)) {\n                    cls[idx] = 1;\n                    cls[map.get(b - v)] = 1;\n                    map.remove(v);\n                    map.remove(b -v);\n                } else \n                    ok = false;\n            }\n\n            if (!ok)\n                System.out.println(\"NO\");\n            else {\n                System.out.println(\"YES\");\n                for (int j = 0; j < cls.length; j++) {\n                    if (j != 0)\n                        System.out.print(\" \");\n                    System.out.print(c ^ cls[j]);\n                }\n                System.out.println();\n            }\n            out.flush();\n        }\n        in.close();\n    }\n\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "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.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\nimport java.util.concurrent.LinkedBlockingDeque;\n\nimport javax.swing.border.Border;\n\npublic class a {\n\n\tpublic static long mod = (long) Math.pow(10, 9) + 7;\n\tpublic static int k = 0;\n\n\tprivate static class node implements Comparable<node> {\n\t\tint l;\n\t\tint r;\n\t\tint index;\n\t\tint index2;\n\t\tint buffer;\n\n\t\tnode(int l, int r, int i, int b, int i2) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tindex = i;\n\t\t\tbuffer = b;\n\t\t\tindex2 = i2;\n\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(node o) {\n\t\t\tif (k == 0) {\n\t\t\t\tif (o.l < l)\n\t\t\t\t\treturn 1;\n\t\t\t\telse if (o.l > l)\n\t\t\t\t\treturn -1;\n\t\t\t\telse if (o.buffer != -1) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else\n\t\t\t\t\treturn -1;\n\t\t\t} else if (k == 1) {\n\t\t\t\tif (r != o.r)\n\t\t\t\t\treturn r - o.r;\n\t\t\t\treturn o.index - index;\n\t\t\t} else if (k == 2) {\n\t\t\t\treturn r - o.r;\n\t\t\t} else {\n\t\t\t\tif (o.index < 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\n\t\t}\n\t}\n\n\t// private static class point implements Comparable<point> {\n\t// int l;\n\t// int r;\n\t// int index;\n\t// int buffer;\n\t//\n\t// point(int l, int r, int i, int b) {\n\t// this.l = l;\n\t// this.r = r;\n\t// index = i;\n\t// buffer = b;\n\t//\n\t// }\n\t//\n\t// @Override\n\t// public int compareTo(point o) {\n\t// if (o.l < l)\n\t// return 1;\n\t// else if (o.l > l)\n\t// return -1;\n\t// else if (o.r < r)\n\t// return 1;\n\t// else if (o.r > r)\n\t// return -1;\n\t// return 0;\n\t// }\n\t//\n\t// }\n\n\tpublic static class point implements Comparable<point> {\n\t\tlong x;\n\t\tlong y;\n\n\t\tpoint(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(point o) {\n\t\t\treturn (int) (x - o.x);\n\n\t\t}\n\t}\n\n\tpublic static int ch(long y) {\n\t\tint r = Long.bitCount(y);\n\t\treturn r;\n\t}\n\n\tpublic static int gcd(int x, int y) {\n\t\tif (y == 0)\n\t\t\treturn x;\n\n\t\treturn gcd(y, x % y);\n\t}\n\n\tpublic static int min[];\n\tpublic static int max[];\n\n\tpublic static void build(int s, int e, int p, int a[]) {\n\t\tif (s == e) {\n\t\t\tmin[p] = a[s];\n\t\t\tmax[p] = a[s];\n\t\t\treturn;\n\t\t}\n\n\t\tint mid = (s + e) / 2;\n\t\tbuild(s, mid, p * 2, a);\n\t\tbuild(mid + 1, e, p * 2 + 1, a);\n\t\tmin[p] = Math.min(min[p * 2], min[p * 2 + 1]);\n\t\tmax[p] = Math.max(max[p * 2], max[p * 2 + 1]);\n\t}\n\n\tpublic static int getMin(int s, int e, int p, int from, int to) {\n\t\tif (s > to || e < from)\n\t\t\treturn Integer.MAX_VALUE;\n\t\tif (s >= from && e <= to)\n\t\t\treturn min[p];\n\t\tint mid = (s + e) / 2;\n\n\t\tint a = getMin(s, mid, p * 2, from, to);\n\t\tint b = getMin(mid + 1, e, p * 2 + 1, from, to);\n\t\treturn Math.min(a, b);\n\n\t}\n\n\tpublic static int getMax(int s, int e, int p, int from, int to) {\n\t\tif (s > to || e < from)\n\t\t\treturn Integer.MIN_VALUE;\n\t\tif (s >= from && e <= to)\n\t\t\treturn max[p];\n\t\tint mid = (s + e) / 2;\n\n\t\tint a = getMax(s, mid, p * 2, from, to);\n\t\tint b = getMax(mid + 1, e, p * 2 + 1, from, to);\n\t\treturn Math.max(a, b);\n\n\t}\n\n\tpublic static boolean ch[];\n\tpublic static ArrayList<Integer> prime;\n\tpublic static Queue<Integer> pp;\n\n\tpublic static void sieve(int k) {\n\t\tch[0] = ch[1] = true;\n\n\t\tfor (int i = 2; i <= k; i++) {\n\t\t\tif (!ch[i]) {\n\t\t\t\tprime.add(i);\n\t\t\t\tpp.add(i);\n\t\t\t\tfor (int j = i + i; j <= k; j += i) {\n\t\t\t\t\tch[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\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\tStringBuilder qq = new StringBuilder();\n\t\tPrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\tString y[] = in.readLine().split(\" \");\n\t\tint n = Integer.parseInt(y[0]);\n\t\tint a = Integer.parseInt(y[1]);\n\t\tint b = Integer.parseInt(y[2]);\n\n\t\tint arr[] = new int[n];\n\t\tHashMap<Integer, Integer> mp = new HashMap();\n\t\ty = in.readLine().split(\" \");\n\t\tboolean flag = true;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = Integer.parseInt(y[i]);\n\t\t\tif (arr[i] >= a && arr[i] >= b) {\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t\tmp.put(arr[i], i);\n\t\t}\n\n\t\tif (!flag) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tboolean ch[] = new boolean[n];\n\t\tint ans[] = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = i;\n\n\t\t\twhile (true&&!ch[k]) {\n\t\t\t\t\n\t\t\t\tif (mp.containsKey(a - arr[k]) && !ch[mp.get(a - arr[k])]\n\t\t\t\t\t\t&& mp.containsKey(b - arr[k])\n\t\t\t\t\t\t&& !ch[mp.get(b - arr[k])]) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (mp.containsKey(a - arr[k])\n\t\t\t\t\t\t&& !ch[mp.get(a - arr[k])]) {\n\t\t\t\t\t//System.out.println(arr[k]);\n\t\t\t\t\tch[k] = true;\n\t\t\t\t\tans[k] = 0;\n\t\t\t\t\tch[mp.get(a - arr[k])] = true;\n\t\t\t\t\tans[mp.get(a - arr[k])] = 0;\n\t\t\t\t\tint s = b - (a - arr[k]);\n\t\t\t\t\tif (mp.containsKey(s)) {\n\t\t\t\t\t\tk = mp.get(s);\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 if (mp.containsKey(b - arr[k])\n\t\t\t\t\t\t&& !ch[mp.get(b - arr[k])]) {\n\t\t\t\t\tans[k] = 1;\n\t\t\t\t\tans[mp.get(b - arr[k])] = 1;\n\t\t\t\t\tch[k] = true;\n\t\t\t\t\tch[mp.get(b - arr[k])] = true;\n\n\t\t\t\t\tint s = a - (b - arr[k]);\n\t\t\t\t\tif (mp.containsKey(s)) {\n\t\t\t\t\t\tk = mp.get(s);\n\t\t\t\t\t} else\n\t\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\t// System.out.println(arr[i] + \" \" + i);\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tqq.append(\"YES\\n\");\n\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\tqq.append(ans[i] + \" \");\n\t\t}\n\t\tSystem.out.println(qq);\n\n\t}\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "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<Integer> lis = new ArrayList<Integer>();\n\t// ArrayList<String> lis = new ArrayList<String>();\n\t//  PriorityQueue<P> que = new PriorityQueue<P>();\n\t// PriorityQueue<Integer> que = new PriorityQueue<Integer>();\n\t//  Stack<Integer> que = new Stack<Integer>();\n\t//HashMap<Long,Long> map = new HashMap<Long,Long>();\n    //\tstatic long sum=0;\n\t// 1000000007 (10^9+7)\n\tstatic int mod = 1000000007;\n\t//static int mod = 1000000009,r=0; ArrayList<Integer> l[]= new ArrayList[n];\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 Set<Integer> set = new HashSet<Integer>();p\n\t\n\tstatic ArrayList<Integer> cd[];\n\tstatic int K=0;\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\n\n //,a=sc.nextInt(),b=sc.nextInt();\n \t// int n=sc.nextInt(),p[]=new int[n],q[]=new int[n];\n\t//int n=sc.nextInt(),a[]=new int[n],b[]=new int[n];\n // int n=sc.nextInt(),m=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();\n\t// int r=1<<28;\n\t\n\tint n=sc.nextInt();//,k=sc.nextInt();\n    int a=sc.nextInt(),b=sc.nextInt(),d[]=new int[n];\n    HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();\n    ArrayList<Integer> A = new ArrayList<Integer>();\n    \n    \n    for (int i = 0; i < n ; i++) {\n    \n    \td[i]=sc.nextInt();\n    \tmap.put(d[i],i );\n    \t\n    }\n    \n    int c=1;\n\t if( a>b ){c--; int x=a; a=b; b=x;}\n\t \n\t int r[]=new int[n];\n\t \n\t if(a==b){\n\t\t\n\t\t  for (int i = 0; i < n; i++) {\n\t\t\t  if(d[i]>a || !map.containsKey(a-d[i]) ){System.out.println(\"NO\"); return;}\n\t\t  }\nSystem.out.println(\"YES\");\n\t\t  for (int i = 0; i < n; i++) {System.out.print(\"1 \");}\n\t\t  System.out.println();\n\t\t return;\n\t }\n\t \n       sort(d);\n\n    for (int j = 0; j < n; j++) {\n         int i=n-j-1;\n    \tint id=map.get(d[i]),idd=-1;\n    \tif(  id<0)continue;\n    \t\n    //\tdb(id,d[i]);\n    \t\n    \tif( d[i]<=a ){\n    \t\t if( map.containsKey(a-d[i]) && 0<=(idd=map.get(a-d[i]))  ){   \n    \t\tr[id]=r[idd]=(c+1)%2;  \n    \t\tmap.put(a-d[i], -1);\n    \t\t }\n    \t\t else if( map.containsKey(b-d[i]) && 0<=(idd=map.get(b-d[i])) ){ \n    \t    \t\tr[id]=r[idd]=c;\n    \t    \t\tmap.put(b-d[i], -1); }\n    \t\telse{ System.out.println(\"NO\"); return; }\n    \t\t \n    \t}\n     \n    \telse{\n    \t\t\n    \t\tif( map.containsKey(b-d[i]) && 0<=(idd=map.get(b-d[i]))   ){ \n    \t\t\tr[id]=r[idd]=c;\n    \t\tmap.put(b-d[i], -1); }\n    \t\telse{ System.out.println(\"NO\"); return; }\n    \t\t\n    \t}\n    \tmap.put(d[i], -1);\n\t\t\n    \n    }\n    \tSystem.out.println(\"YES\");\n         for (int j = 0; j < n; j++) {\n\t\t\tSystem.out.print(r[j]+\" \");\n\t\t}\n    \tSystem.out.println();\n    \n    \n    \n    \n    \n}\n\n\n  static class P implements Comparable<P>{\n//\timplements Comparable<Pair>\n\tint id; long  d; ;\n\tP(int id,long d){\n\t\tthis.id=id;\n\t\tthis.d=d;\n\t} \n\t\n\tpublic int compareTo(P x){\n\t\treturn  (-x.d+d)>=0?1:-1  ; // ascend long\n\t//\treturn   -x.d+d  ; // ascend\n\t//\t return   x.d-d  ; //descend\n\t   }\n \n}\n  \n\nstatic void db(Object... os){\n    System.err.println(Arrays.deepToString(os));\n\n}\n\n\n}\n\n\n\nclass Reader\n{ \n\tprivate BufferedReader x;\n\tprivate StringTokenizer st;\n\t\n\tpublic Reader(InputStream in)\n\t{\n\t\tx = new BufferedReader(new InputStreamReader(in));\n\t\tst = null;\n\t}\n\tpublic String nextString() throws IOException\n\t{\n\t\twhile( st==null || !st.hasMoreTokens() )\n\t\t\tst = new StringTokenizer(x.readLine());\n\t\treturn st.nextToken();\n\t}\n\tpublic int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\tpublic long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\tpublic double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "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.HashMap;\nimport java.util.HashSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class TwoSets {\n    static int n, a, b;\n    static HashSet<Integer> arr = new HashSet<Integer>();\n    static HashSet<Integer> visited = new HashSet<Integer>();\n    static HashMap<Integer, Integer> result = new HashMap<Integer, Integer>();\n\n    static void dfs(int x, int parent, int len) {\n        stack.push(x);\n        visited.add(x);\n        int children = 0;\n        if (a - x > 0) {\n            if (a - x != parent && arr.contains(a - x)) {\n                dfs(a - x, x, len + 1);\n                children++;\n            }\n        }\n        if (b - x > 0) {\n            if (b - x != parent && arr.contains(b - x)) {\n                dfs(b - x, x, len + 1);\n                children++;\n            }\n        }\n        if (children == 0) {\n            if (len % 2 == 1) {\n                System.out.println(\"NO\");\n                System.exit(0);\n            } else {\n                while (!stack.isEmpty()) {\n                    int first = stack.pop();\n                    int second = stack.pop();\n                    if (first == a - second) {\n                        result.put(first, 0);\n                        result.put(second, 0);\n                    } else {\n                        result.put(first, 1);\n                        result.put(second, 1);\n                    }\n\n                }\n            }\n        }\n    }\n\n    static Stack<Integer> stack = new Stack<Integer>();\n\n    public static void main(String[] args) {\n        InputReader r = new InputReader(System.in);\n        n = r.nextInt();\n        a = r.nextInt();\n        b = r.nextInt();\n        int[] list = new int[n];\n        for (int i = 0; i < n; i++) {\n            list[i] = r.nextInt();\n            arr.add(list[i]);\n        }\n        for (int x : arr) {\n            if (!visited.contains(x)) {\n                if (arr.contains(a - x) && arr.contains(b - x))\n                    continue;\n                if (arr.contains(a - x) || arr.contains(b - x)) {\n                    dfs(x, -1, 1);\n                } else {\n                    System.out.println(\"NO\");\n                    System.exit(0);\n                }\n            }\n        }\n        PrintWriter out = new PrintWriter(System.out);\n        out.println(\"YES\");\n        for (int i = 0; i < list.length; i++) {\n            if (result.get(list[i]) == null)\n                out.println(0);\n            else\n                out.println(result.get(list[i]));\n        }\n        out.close();\n\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n\n        public InputReader(FileReader stream) {\n            reader = new BufferedReader(stream);\n            tokenizer = null;\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n                return null;\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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport static java.lang.Integer.*;\n\npublic class BDiv1 {\nstatic int n; \nstatic int a;\nstatic int b;\nstatic HashMap<Integer,Integer> graphA=new HashMap<>();\nstatic HashMap<Integer,Integer> graphB=new HashMap<>();\nstatic int [] array;\nstatic int [] original;\nstatic boolean x=true;\n\n    public static void main(String[] args) throws Exception{\n        BufferedReader buf =new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st =new StringTokenizer(buf.readLine());\n        n=parseInt(st.nextToken());\n        a=parseInt(st.nextToken());\n        b=parseInt(st.nextToken());\n        st =new StringTokenizer(buf.readLine());\n        array=new int[n];\n        original=new int [n];\n        for (int i=0;i<n;i++){\n            array[i]=parseInt(st.nextToken());\n            original[i]=array[i];\n        }\n        Arrays.sort(array);\nfor (int i=0;i<n;i++){\n    int k= Arrays.binarySearch(array,a-array[i]);\n    if (k>=0){\n        graphA.put(array[i],array[k]);\n        graphA.put(array[k],array[i]);\n    }\n}\nfor (int i=0;i<n;i++){\n    int k= Arrays.binarySearch(array,b-array[i]);\n    if (k>=0){\n        graphB.put(array[i],array[k]);\n        graphB.put(array[k],array[i]);\n    }\n    }\n\n\nfor (int i=0;i<n;i++){\n    Integer j=graphA.get(array[i]);\n    if (j!=null){\n        if (graphB.containsKey(array[i]) && graphB.containsKey(j)){\n            graphA.remove(array[i]);\n            graphA.remove(j);\n        }\n        else if (graphB.containsKey(array[i]) && !graphB.containsKey(j)){\n            \n            graphB.remove(graphB.get(array[i]));\n            graphB.remove(array[i]);\n        }\n        else if (!graphB.containsKey(array[i]) && graphB.containsKey(j)){\n            graphB.remove(graphB.get(j));\n            graphB.remove(j);\n        }\n        \n    }\n    \n}\n\nint [] res=new int [n];\nfor (int i=0;i<n;i++){\n    if (graphA.containsKey(original[i]))res[i]=0;\n    else if (graphB.containsKey(original[i])) res[i]=1;\n    else {\n        System.out.println(\"NO\");\n        return;\n    }\n}\nSystem.out.println(\"YES\");\nfor (int k:res)System.out.print(k+\" \");\n}\n\n    }\n\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n\tstatic HashMap<Integer,Integer> hm;\n\tstatic int[] array;\n\tstatic boolean marked[];\n\tstatic int a , b ; \n\tstatic int[] ans ; \n\t\n\tpublic static void main( String args[])\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n ; \n\t\t\n\t\tn = sc.nextInt();\n\t\ta = sc.nextInt();\n\t\tb = sc.nextInt();\n\t\t\n\t\thm = new HashMap<Integer,Integer>();\n\t\tarray = new int[n];\n\t\tmarked = new boolean[n];\n\t\t\n\t\tfor( int i = 0 ; i < n ; ++i )\n\t\t{\n\t\t\tarray[i] = sc.nextInt();\n\t\t\thm.put( array[i] , i );\n\t\t}\n\t\t\n\t\tif( a == b)\n\t\t{\n\t\t\tboolean flag = true ;\n\t\t\tfor( int i = 0 ; i < n ; ++i )\n\t\t\t\tif( !hm.containsKey( a - array[i]))\n\t\t\t\t\tflag = false; \n\t\t\t\n\t\t\tif( !flag) \n\t\t\t\tSystem.out.println( \"NO\");\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tfor( int i = 0 ; i < n ; ++i)\n\t\t\t\t\tSystem.out.print(\"0 \");\n\t\t\t}\n\t\t}\n\t\t\n\t\telse\n\t\t{\n\t\t\t\n\t\t\tans = new int[n];\n\t\t\t\n\t\t\tfor( int i = 0 ; i < n ; ++i )\n\t\t\tif( marked[i] ) continue; \n\t\t\t\n\t\t\telse  // hadle odd , even and single self loops\n\t\t\t{\n\t\t\t\tif( hm.containsKey(a - array[i]) && !hm.containsKey(b - array[i]))\n\t\t\t\t{\n\t\t\t\t\tpropagateA(i);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\telse if( !hm.containsKey(a - array[i]) && hm.containsKey(b - array[i]))\n\t\t\t\t{\n\t\t\t\t\t// propagate b\n\t\t\t\t\tpropagateB(i);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\telse if(!hm.containsKey(a - array[i]) && !hm.containsKey(b - array[i]))\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\tfor( int i = 0 ; i < n ; ++i )\n\t\t\t\tif( marked[i] ) continue; \n\t\t\t\t\n\t\t\t\telse  // handle doule self loops , cycles\n\t\t\t\t{\n\t\t\t\t\t\tstart(i);\n\t\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tfor( int i = 0 ; i < n; ++i)\n\t\t\t\tSystem.out.print(ans[i] + \" \");\n\t\t\tSystem.exit(0);\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\tstatic void propagateA(int index)\n\t{\n\t\t\n\t\tint i = index;\n\t\t\n\t\twhile( !marked[i])\n\t\t{\n\t\t\t\n\t\t\t\n\t\t\t\t\tif( hm.containsKey( a - array[i]) && !marked[ hm.get( a - array[i])])\n\t\t\t\t\t{\n\t\t\t\t\t\tmarked[i] = true ; \n\t\t\t\t\t\tans [i] = 0 ; \n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\ti = hm.get( a - array[i]);\n\t\t\t\t\t\tmarked[i] = true ; \n\t\t\t\t\t\tans [i] = 0 ; \n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\tif( hm.containsKey( b - array[i]) && !marked[ hm.get( b - array[i])])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ti = hm.get( b - array[i]);\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\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\t\tSystem.exit(0);\n\t\t\t\t\t}\n\t\t\t\t\n\t\t}\n\t\t\t\n\t}\n\t\n\tstatic void propagateB(int index)\n\t{\n\t\t\n\t\tint i = index;\n\t\t\n\t\twhile( !marked[i])\n\t\t{\n\t\t\t\n\t\t\t\n\t\t\t\t\tif( hm.containsKey( b - array[i]) && !marked[ hm.get( b - array[i])])\n\t\t\t\t\t{\n\t\t\t\t\t\tmarked[i] = true ; \n\t\t\t\t\t\tans [i] = 1 ;\n\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\ti = hm.get( b - array[i]);\n\t\t\t\t\t\tmarked[i] = true ; \n\t\t\t\t\t\tans [i] = 1 ; \n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\tif( hm.containsKey( a - array[i]) && !marked[ hm.get( a - array[i])])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ti = hm.get( a - array[i]);\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\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\t\tSystem.exit(0);\n\t\t\t\t\t}\n\t\t\t\t\n\t\t}\n\t\t\t\n\t}\n\t\n\tstatic void start(int index)\n\t{\n\t\t \n\t\tint i = index ; \n\t\t\n\t\twhile( !marked[i] )\n\t\t{\n\t\t\t//System.out.println( a - array[i]);\n\t\t\tif(!marked[ hm.get( a - array[i])])\n\t\t\t{\n\t\t\t\tmarked[i] = true ; \n\t\t\t\tans [i] = 0 ; \n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\ti = hm.get( a - array[i]);\n\t\t\t\tmarked[i] = true ; \n\t\t\t\tans [i] = 0 ; \n\t\t\t\t\n\t\t\t\t\n\t\t\t\ti = hm.get( b - array[i]);\n\t\t\t\n\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t}\n\t\t\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n\npublic class B {\n\tstatic Set<Integer> A;\n\tstatic Set<Integer> B;\n\tstatic TreeSet<Integer> ts;\n\tstatic int a;\n\tstatic int b;\n\tstatic boolean noAns;\n\tpublic static void main(String[] args) throws Exception{\n\t\tint n = readInt();\n\t\ta = readInt();\n\t\tb = readInt();\n\t\tts = new TreeSet<Integer>();\n\t\tint[] table = new int[n];\n\t\tfor(int i = 0; i<n; i++){\n\t\t\ttable[i] = readInt();\n\t\t\tts.add(table[i]);\n\t\t}\n\t\tA = new HashSet<Integer>();\n\t\tB = new HashSet<Integer>();\n\t\tnoAns = false;\n\t\tfor(Integer cur:ts){\n\t\t\tboolean fitsA = false;\n\t\t\tboolean fitsB = false;\n\t\t\tif(A.contains(cur) || B.contains(cur)){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(ts.contains(a-cur)){\n\t\t\t\tfitsA = true;\n\t\t\t}\n\t\t\tif(ts.contains(b-cur)){\n\t\t\t\tfitsB = true;\n\t\t\t}\n\t\t\tif(fitsA && fitsB){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse if(!(fitsA || fitsB)){\n\t\t\t\tnoAns = true;\n\t\t\t}\n\t\t\telse if(fitsA){\n\t\t\t\ttour(cur, false);\n\t\t\t}\n\t\t\telse if(fitsB){\n\t\t\t\ttour(cur, true);\n\t\t\t}\n\t\t}\n\t\tfor(Integer cur:ts){\n\t\t\tif(A.contains(cur) || B.contains(cur)){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tA.add(cur);\n\t\t\t}\n\t\t}\n\t\tif(!noAns){\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor(int i = 0; i< n; i++){\n\t\t\t\tif(A.contains(table[i])){\n\t\t\t\t\tsb.append(\"0\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tsb.append(\"1\");\n\t\t\t\t}\n\t\t\t\tsb.append(\" \");\n\t\t\t}\n\t\t\tSystem.out.println(sb);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\n\tstatic void tour(Integer cur, boolean bb){\n\t\tif(A.contains(cur) || B.contains(cur)){\n\t\t\treturn;\n\t\t}\n\t\tif(bb){\n\t\t\tB.add(cur);\n\t\t\tB.add(b-cur);\n\t\t\t\n\t\t\tif(ts.contains(a-cur)){\n\t\t\t\tB.add(a-cur);\n\t\t\t\tif(ts.contains(b-(a-cur))){\n\t\t\t\t\ttour(b-(a-cur), true);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tnoAns = true;\n\t\t\t\t}\n\t\t\t}\t\t\t\n\t\t\tif(ts.contains(a-(b-cur))){\n\t\t\t\tB.add(a-(b-cur));\n\t\t\t\tif(ts.contains(b-(a-(b-cur)))){\n\t\t\t\t\ttour(b-(a-(b-cur)), true);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tnoAns = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tA.add(cur);\n\t\t\tA.add(a-cur);\n\t\t\tif(ts.contains(b-cur)){\n\t\t\t\tA.add(b-cur);\n\t\t\t\tif(ts.contains(a-(b-cur))){\n\t\t\t\t\ttour(a-(b-cur), false);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tnoAns = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(ts.contains(b-(a-cur))){\n\t\t\t\tA.add(b-(a-cur));\n\t\t\t\tif(ts.contains(a-(b-(a-cur)))){\n\t\t\t\t\ttour(a-(b-(a-cur)), false);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tnoAns = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st = new StringTokenizer(\" \");\n\tstatic String readString() throws Exception{\n\t\twhile(!st.hasMoreTokens()){\n\t\t\tst = new StringTokenizer(stdin.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\tstatic int readInt() throws Exception {\n\t\treturn Integer.parseInt(readString());\n\t}\n\tstatic long readLong() throws Exception {\n\t\treturn Long.parseLong(readString());\n\t}\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.text.DecimalFormat;\nimport java.io.*;\nimport java.util.*;\nimport java.lang.reflect.Array;\n\n/**\n * @author Mukesh Singh\n *\n */\n\n\npublic class AB {\n\n    private InputStream input;\n    private PrintStream output;\n    private Scanner inputSc;\n\n    public AB(InputStream input, PrintStream output) {\n        this.input = input;\n        this.output = output;\n        init();\n    }\n\n    private void init() {\n        inputSc = new Scanner(input);\n    }\n\n    static int lineToInt(String line) {\n        return Integer.parseInt(line);\n    }\n\n    static long lineToLong(String line) {\n        return Long.parseLong(line);\n    }\n    static double lineToDouble(String line) {\n        return Double.parseDouble(line);\n    }\n\n\n    public void solve() \n\t{\n            solveTestCase();\n    }\n\n/**\n * @define global / instance variables \n */\n\n\tHashMap<Integer,Integer> mat ;\n\tlong dist[] ;\n\tint vec[] ;\n\tint ar[] ;\n\tSet<Integer> st ;\n\tboolean isDone[] ;\n\tfinal long INF = 100000000000000000L ;\n/**\n * @solve test case \n */\n@SuppressWarnings(\"unchecked\")\n   private void solveTestCase() \n\t{\n\t\tint i , j  , k , n , m , d , l ,b  , p , q , r;\n\t\tlong N , M, K;\n\t\tint x1 , y1 , x2 , y2 ,x;\n\t\tint a1,a2,b1,b2,a ;\n\t\tDecimalFormat df = new DecimalFormat(\"#,###,##0.00\");\n        String str = inputSc.nextLine();\n        String delims = \"[ ]+\";\n\t\tString tokens[] = str.split(delims);\n\t\tn = lineToInt(tokens[0]);\n\t\ta = lineToInt(tokens[1]);\n\t\tb = lineToInt(tokens[2]);\n\t\tmat = new HashMap<Integer,Integer>() ;\n\t\tst = new TreeSet<Integer>();\n\t\tar = new int[n+4] ;\n\t\tvec = new int[n+4] ;\n\t\tstr = inputSc.nextLine();\n\t\ttokens = str.split(delims);\n\t\tfor( i = 1 ; i <= n ; i++ )\n\t\t{\n\t\t\tar[i] = lineToInt(tokens[i-1]);\n\t\t\tmat.put(ar[i],i) ;\n\t\t\tst.add(ar[i]);\n\t\t\tvec[i] = i ;\n\t\t}\n\t\tvec[n+1] = n+1 ;\n\t\tvec[n+2] = n+2 ;\n\t\tfor( i = 1 ; i <= n ; i++ )\n\t\t{\n\t\t\tx= ar[i];\n\t\t\n\t\t\tif(st.contains(a-x))\n\t\t\t{\n\t\t\t\tBing(mat.get(x),mat.get(a-x));\n\t\t\t}\n\t\t\telse\n\t\t\t\tBing(n+1 , mat.get(x));\n\t\t\tif(st.contains(b-x))\n\t\t\t{\n\t\t\t\tBing(mat.get(x),mat.get(b-x));\n\t\t\t}\n\t\t\telse\n\t\t\t\tBing(n+2 , mat.get(x));\n\t\t} \n\t\tif(find(n+1)==find(n+2))\n\t\t{\n\t\t\toutput.println(\"NO\");\n\t\t\treturn ;\n\t\t}\n\t\toutput.println(\"YES\");\n\t\tfor( i =1 ;  i<= n  ; i ++ )\n\t\t{\n\t\t\tif(find(i)==find(n+1))\n\t\t\t\toutput.print(\"1 \");\n\t\t\telse \n\t\t\t\toutput.print(\"0 \");\n\t\t}\n\t\toutput.println();\n\t\t\n\t}\n\tint find(int x)\n{\n\tif(x==vec[x]) return x;\n\treturn vec[x]=find(vec[x]);\n}\n\nvoid Bing(int a,int b)\n{\n\tint A=find(a);int B=find(b);\n\tif(A==B) return ;\n\tvec[B]=A;\n}\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) \n\t{\n\t\tFileInputStream in = null;\n      \tFileOutputStream out = null;\n\t\tPrintStream ps = null ;\n\t\tInputStream is = null ;\n\t\ttry \n\t\t{\n         \tis = new FileInputStream(\"file.in\");\n         \tout = new FileOutputStream(\"file.out\");\n\t\t\tps = new PrintStream(out);\n        }\n\t\tcatch ( Exception e )\n\t\t{}\n\n        AB sd = new AB(System.in, System.out);\n        sd.solve();\n\t\ttry\n\t\t{\n        if (is != null) \n\t\t{\n\t      is.close();\n\t    }\n       \tif (out != null) {\n           \tout.close();\n       \t}\n\t\tif (ps != null) {\n           \tps.close();\n         }\n      \t}catch (Exception e){}\n\n\t\t//SquareDetector sd = new SquareDetector(System.in, System.out);\n        //sd.solve();\n    }\n}\n   \n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class B {\n    public static PrintStream out = System.out;\n    public static InputReader in = new InputReader(System.in);\n    static class Node implements Comparable<Node> {\n        int res;\n        Node(int pp) {\n            p = pp;\n        }\n        int p;\n        @Override\n        public int compareTo(Node n) {\n            return Integer.compare(p, n.p);\n        }\n        @Override\n        public boolean equals(Object o) {\n            return p == ((Node) o).p;\n        }\n    }\n    public static void main(String args[]) {\n        int N, a, b;\n        N = in.nextInt();\n        int[] label;\n        a = in.nextInt();\n        b = in.nextInt();\n        if (a < b) {\n            label = new int[] {0, 1};\n        } else {\n            int tmp = a;\n            a = b;\n            b = tmp;\n            label = new int[] {1, 0};\n        }\n        Node[] nodes = new Node[N];\n        for (int i = 0; i < N; i++) {\n            nodes[i] = new Node(in.nextInt());\n        }\n        TreeSet<Node> ts = new TreeSet<>();\n        for (int i = 0; i < N; i++) {\n            ts.add(nodes[i]);\n        }\n        while (!ts.isEmpty()) {\n            Node n = ts.first();\n            Node an = new Node(a - n.p);\n            Node bn = new Node(b - n.p);\n            SortedSet<Node> ats = ts.tailSet(an);\n            SortedSet<Node> bts = ts.tailSet(bn);\n            Node an2 = ats.isEmpty() ? null : ats.first();\n            Node bn2 = bts.isEmpty() ? null : bts.first();\n            Node n2 = null;\n            int l = 0;\n            if (bn2 != null && bn2.equals(bn)) {\n                n2 = bn2;\n                l = label[1];\n            } else if (an2 != null && an2.equals(an)) {\n                n2 = an2;\n                l = label[0];\n            } else {\n                NO();\n            }\n            if (!n.equals(n2)) {\n                ts.remove(n);\n                n.res = l;\n            }\n            ts.remove(n2);\n            n2.res = l;\n        }\n        out.println(\"YES\");\n        for (int i = 0; i < nodes.length; i++) {\n            if (i != 0) out.print(\" \");\n            out.print(nodes[i].res);\n        }\n        out.println();\n    }\n    static void NO() {\n        out.println(\"NO\");\n        System.exit(0);\n    }\n}\nclass InputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n    public InputReader(InputStream stream) {\n\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\ttokenizer = null;\n    }\n    public String next() {\n\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t    try {\n\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t    } catch (IOException e) {\n\t\tthrow new RuntimeException(e);\n\t    }\n\t}\n\treturn tokenizer.nextToken();\n    }\n    public double nextDouble() {\n\treturn Double.parseDouble(next());\n    }\n    public long nextLong() {\n\treturn Long.parseLong(next());\n    }\n    public int nextInt() {\n\treturn Integer.parseInt(next());\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class ProblemB3 {\n    Map<Integer, List<int[]>> dest;\n\n    private ProblemB3() throws IOException {\n        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\n        String h = rd.readLine();\n        String[] q = h.split(\"\\\\s+\");\n        int a = Integer.parseInt(q[1]);\n        int b = Integer.parseInt(q[2]);\n        h = rd.readLine();\n        q = h.split(\" \");\n        int n = q.length;\n        int[] p = new int[n];\n        for(int i=0;i<n;i++) {\n            p[i] = Integer.parseInt(q[i]);\n        }\n        Set<Integer> pset = new HashSet<>();\n        for(int x: p) {\n            pset.add(x);\n        }\n        dest = new HashMap<>();\n        boolean res = true;\n        for(int x: p) {\n            boolean aOk = pset.contains(a-x);\n            boolean bOk = pset.contains(b-x);\n            if(!aOk && !bOk) {\n                res = false;\n                break;\n            } else {\n                if(aOk) {\n                    addEdgeAndBack(x,a-x,0);\n                }\n                if(bOk) {\n                    addEdgeAndBack(x,b-x,1);\n                }\n            }\n        }\n        Set<Integer> aSet = new HashSet<>();\n\n        if(res && a != b) {\n            for(int x: p) {\n                List<int[]> e = getEdges(x);\n                if(e.size() == 1) {\n                    int[] edge = e.get(0);\n                    boolean odd = true;\n                    int curA = edge[1];\n                    int prev = x;\n                    while(true) {\n                        int cur = edge[0];\n                        if(curA == 0 && odd) {\n                            aSet.add(prev);\n                            aSet.add(cur);\n                        }\n                        e = getEdges(cur);\n                        if(e.size() == 1) {\n                            if(!odd && e.get(0)[0] != cur) {\n                                res = false;\n                            }\n                            break;\n                        }\n                        int other = e.get(0)[0] == prev?1:0;\n                        edge = e.get(other);\n                        if(edge[1] == curA) {\n                            res = false;\n                            break;\n                        }\n                        curA = 1-curA;\n                        prev = cur;\n                        odd = !odd;\n                    }\n                    if(!res) {\n                        break;\n                    }\n                }\n            }\n        }\n        out(res?\"YES\":\"NO\");\n        if(res) {\n            StringBuilder buf = new StringBuilder();\n            for(int i=0;i<n;i++) {\n                if(i>0) {\n                    buf.append(' ');\n                }\n                buf.append(aSet.contains(p[i])?'0':'1');\n            }\n            out(buf);\n        }\n    }\n\n    private void addEdgeAndBack(int from, int to, int u) {\n        addEdge(from, to, u);\n        addEdge(to, from, u);\n    }\n\n    private void addEdge(int from, int to, int u) {\n        List<int[]> edges = getEdges(from);\n        for(int[] edge: edges) {\n            if(edge[0] == to) {\n                return;\n            }\n        }\n        edges.add(new int[]{to, u});\n    }\n\n    private List<int[]> getEdges(int from) {\n        List<int[]> ds = dest.get(from);\n        if(ds == null) {\n            ds = new ArrayList<>();\n            dest.put(from, ds);\n        }\n        return ds;\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 ProblemB3();\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class B {\t\n\tBufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter out;\n    \n\tpublic void solve() throws IOException {\t\t\t\t\n\t\tint N = nextInt();\n        int A = nextInt();\n        int B = nextInt();\n\n        int[] nsA = new int[N];\n        int[] nsB = new int[N];\n        char[] ans = new char[N];\n\n        Arrays.fill(nsA, -1);\n        Arrays.fill(nsB, -1);\n        Arrays.fill(ans, 'C');\n\n        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n        int[] P = new int[N];\n\t\tfor (int i = 0; i < N; i++) {\n            P[i] = nextInt();\n            map.put(P[i], i);\n        }\n\n        // if A == B\n        if (A == B) {\n            for (int i = 0; i < N; i++) {\n                if (!map.containsKey(A - P[i])) {\n                    out.println(\"NO\"); return;\n                }\n            }\n\n            out.println(\"YES\");\n            for (int i = 0; i < N; i++) {\n                out.print(0 + \" \");\n            }\n            out.println();\n            return;\n        }\n\n\n        for (int i = 0; i < N; i++) {\n            int oppA = A - P[i];\n            int oppB = B - P[i];\n\n            if (map.containsKey(oppA)) {\n                nsA[i] = map.get(oppA);\n            }\n\n            if (map.containsKey(oppB)) {\n                nsB[i] = map.get(oppB);\n            }\n        }\n\n        for (int i = 0; i < N; i++) {\n            if (nsA[i] == -1 && nsB[i] == -1) {\n                out.println(\"NO\");\n                return;\n            }\n        }\n\n        for (int i = 0; i < N; i++) {\n            if (ans[i] != 'C') continue;\n\n            if (nsA[i] == -1) {\n                if (!go(i, 'B', ans, nsA, nsB) ){\n                    out.println(\"NO\"); return;\n                }\n            } else if (nsB[i] == -1) {\n                if (!go(i, 'A', ans, nsA, nsB) ){\n                    out.println(\"NO\"); return;\n                }\n            }\n        }\n\n        for (int i = 0; i < N; i++) {\n            if (ans[i] != 'C') continue;\n\n            if (nsA[i] == i || nsB[i] == i) {\n                if (nsA[i] == i) {\n                    if (!go(i, 'B', ans, nsA, nsB) ){\n                        out.println(\"NO\"); return;\n                    }\n                } else {\n                    if (!go(i, 'A', ans, nsA, nsB) ){\n                        out.println(\"NO\"); return;\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < N; i++) {\n            if (ans[i] != 'C') continue;\n\n            if (!go(i, 'A', ans, nsA, nsB) ){\n                out.println(\"NO\"); return;\n            }\n        }\n\n        for (int i = 0; i < N; i++) {\n            if (ans[i] == 'C') {\n                out.println(\"NO\");\n                return;\n            }\n        }\n\n        out.println(\"YES\");\n        for (int i = 0; i < N; i++) {\n            out.print(ans[i] == 'A'? 0: 1);\n            out.print(\" \");\n        }\n        out.println();\n\t}\n\n    public boolean go(int cur, char link, char[] ans, int[] nsA, int[] nsB) {\n        while (ans[cur] == 'C') {\n            int next = link == 'A'? nsA[cur]: nsB[cur];\n\n            if (next == -1) return false;\n            if (ans[next] != 'C') return false;\n            ans[cur] = link;\n            ans[next] = link;\n\n\n            int nextNext = link == 'A'? nsB[next]: nsA[next];\n            cur = nextNext;\n\n            if (cur == -1) return true;\n\n        }\n\n        return true;\n    }\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n\t\n\tpublic void run() {\n        try {\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        } 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}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\n\n\tstatic int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tstatic long nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tstatic double nextDouble() throws NumberFormatException, 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\twriter = new PrintWriter(System.out);\n\t\tpineapple();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\n\tstatic void pineapple() throws NumberFormatException, IOException {\n\t\tint n = nextInt();\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tTreeSet<Integer> al = new TreeSet<Integer>();\n\t\tTreeMap<Integer, Integer> mp = new TreeMap<Integer, Integer>();\n\t\tint[] ans = new int[n];\n\t\tArrays.fill(ans, -1);\n\t\tTreeSet<Integer> used = new TreeSet<Integer>();\n\t\tint[] mas = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint t = nextInt();\n\t\t\tal.add(t);\n\t\t\tmas[i] = t;\n\t\t\tmp.put(t, i);\n\t\t}\n\n\t\tfor (int st : al) {\n\t\t\tif (used.contains(st))\n\t\t\t\tcontinue;\n\n\t\t\t{\n\t\t\t\tint pr = st;\n\t\t\t\tint cc = -1;\n\t\t\t\tTreeSet<Integer> u2 = new TreeSet<Integer>();\n\t\t\t\tu2.add(pr);\n\t\t\t\tif (al.contains(a - pr) && !u2.contains(a - pr))\n\t\t\t\t\tcc = a - pr;\n\t\t\t\telse if (al.contains(b - pr) && !u2.contains(a - pr))\n\t\t\t\t\tcc = b - pr;\n\t\t\t\tif (cc != -1) {\n\t\t\t\t\tu2.add(cc);\n\t\t\t\t\tboolean bGo = true;\n\t\t\t\t\twhile (bGo) {\n\t\t\t\t\t\tbGo = false;\n\t\t\t\t\t\tint nxt = -1;\n\t\t\t\t\t\tif (al.contains(a - cc) && !u2.contains(a - cc))\n\t\t\t\t\t\t\tnxt = a - cc;\n\t\t\t\t\t\telse if (al.contains(b - cc) && !u2.contains(b - cc))\n\t\t\t\t\t\t\tnxt = b - cc;\n\t\t\t\t\t\tif (nxt != -1) {\n\t\t\t\t\t\t\tbGo = true;\n\t\t\t\t\t\t\tu2.add(nxt);\n\t\t\t\t\t\t\tcc = nxt;\n\t\t\t\t\t\t\tpr = cc;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tst = cc;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint x = st;\n\t\t\twhile (x != -1) {\n\t\t\t\tint curr = x;\n\t\t\t\tused.add(curr);\n\t\t\t\tx = -1;\n\t\t\t\tint next1 = a - curr;\n\t\t\t\tif (al.contains(next1)) {\n\t\t\t\t\tif (!used.contains(next1)) {\n\t\t\t\t\t\tx = next1;\n\t\t\t\t\t\tint ci = mp.get(curr);\n\t\t\t\t\t\tint ni = mp.get(next1);\n\t\t\t\t\t\tif (ans[ci] == -1 && ans[ni] == -1) {\n\t\t\t\t\t\t\tans[ni] = 0;\n\t\t\t\t\t\t\tans[ci] = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint next2 = b - curr;\n\t\t\t\tif (al.contains(next2)) {\n\t\t\t\t\tif (!used.contains(next2)) {\n\t\t\t\t\t\tx = next2;\n\t\t\t\t\t\tint ci = mp.get(curr);\n\t\t\t\t\t\tint ni = mp.get(next2);\n\t\t\t\t\t\tif (ans[ci] == -1 && ans[ni] == -1) {\n\t\t\t\t\t\t\tans[ni] = 1;\n\t\t\t\t\t\t\tans[ci] = 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\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (ans[i] == -1) {\n\t\t\t\tif (2 * mas[i] == a) {\n\t\t\t\t\tans[i] = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (2 * mas[i] == b) {\n\t\t\t\t\tans[i] = 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\twriter.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\twriter.println(\"YES\");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\twriter.print(ans[i] + \" \");\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class CF268_TwoSets {\n\n\tpublic static void main(String[] args) {\n\n\t\tMyScanner in = new MyScanner();\n\n\t\tint N = in.nextInt();\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\n\t\tint[] vals = new int[N];\n\t\tHashMap<Integer, Integer> val2Ind = new HashMap<Integer, Integer>();\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tvals[i] = in.nextInt();\n\t\t\tval2Ind.put(vals[i], i);\n\t\t}\n\n\t\tint[] setAssignment = new int[N];\n\t\tint[] friendA = new int[N];\n\t\tint[] friendB = new int[N];\n\t\tArrays.fill(setAssignment, -1);\n\t\tArrays.fill(friendA, -1);\n\t\tArrays.fill(friendB, -1);\n\n\t\t// Mark partners\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tInteger friendAInd = val2Ind.get(a - vals[i]);\n\t\t\tif (friendAInd != null) {\n\t\t\t\tfriendA[i] = friendAInd;\n\t\t\t}\n\n\t\t\tInteger friendBInd = val2Ind.get(b - vals[i]);\n\t\t\tif (friendBInd != null) {\n\t\t\t\tfriendB[i] = friendBInd;\n\t\t\t}\n\t\t}\n\n\t\t// Find those with only one friend\n\t\tQueue<Integer> toProc = new ArrayDeque<Integer>();\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tint friends = 0;\n\t\t\tif (friendA[i] != -1) {\n\t\t\t\tfriends++;\n\t\t\t}\n\t\t\tif (friendB[i] != -1) {\n\t\t\t\tfriends++;\n\t\t\t}\n\t\t\tif (friends == 1) {\n\t\t\t\ttoProc.add(i);\n\t\t\t}\n\t\t}\n\n\t\t// Process the one frienders\n\t\twhile (!toProc.isEmpty()) {\n\n\t\t\tint ind = toProc.poll();\n\n\t\t\tif (setAssignment[ind] != -1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (friendA[ind] != -1) {\n\n\t\t\t\tint other = friendA[ind];\n\t\t\t\tif (setAssignment[other] == -1) {\n\t\t\t\t\tsetAssignment[ind] = 0;\n\t\t\t\t\tsetAssignment[other] = 0;\n\t\t\t\t\t// Check other's friend\n\t\t\t\t\tif (friendB[other] != -1) {\n\t\t\t\t\t\tint otherOther = friendB[other];\n\t\t\t\t\t\tfriendB[otherOther] = -1;\n\t\t\t\t\t\ttoProc.add(otherOther);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\telse if (friendB[ind] != -1) {\n\n\t\t\t\tint other = friendB[ind];\n\t\t\t\tif (setAssignment[other] == -1) {\n\t\t\t\t\tsetAssignment[ind] = 1;\n\t\t\t\t\tsetAssignment[other] = 1;\n\t\t\t\t\t// Check other's friend\n\t\t\t\t\tif (friendA[other] != -1) {\n\t\t\t\t\t\tint otherOther = friendA[other];\n\t\t\t\t\t\tfriendA[otherOther] = -1;\n\t\t\t\t\t\ttoProc.add(otherOther);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t}\n\t\t\n\t\t\n\t\t// Process those with two friends\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\t\n\t\t\tif(setAssignment[i] != -1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tif(friendA[i] == -1 && friendB[i] == -1) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\t// Only possibility should now be that both friends are possible\n\t\t\tsetAssignment[i] = 0;\n\t\t\tsetAssignment[friendA[i]] = 0;\n\t\t}\n\t\t\n\t\t// Print the result\n\t\tSystem.out.println(\"YES\");\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tsb.append(setAssignment[i]);\n\t\t\tsb.append(\" \");\n\t\t}\n\t\tsb.deleteCharAt(sb.length() - 1);\n\t\tSystem.out.println(sb);\n\t}\n\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\n\t}\n\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class ProblemB {\n    Map<Integer, List<int[]>> dest;\n\n    private ProblemB() throws IOException {\n        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\n        String h = rd.readLine();\n        String[] q = h.split(\"\\\\s+\");\n        int a = Integer.parseInt(q[1]);\n        int b = Integer.parseInt(q[2]);\n        h = rd.readLine();\n        q = h.split(\" \");\n        int n = q.length;\n        int[] p = new int[n];\n        for(int i=0;i<n;i++) {\n            p[i] = Integer.parseInt(q[i]);\n        }\n        Set<Integer> pset = new HashSet<>();\n        for(int x: p) {\n            pset.add(x);\n        }\n\n        if(a == b) {\n            boolean res = true;\n            for(int x: p) {\n                if(!pset.contains(a-x)) {\n                    res = false;\n                    break;\n                }\n            }\n            out(res?\"YES\":\"NO\");\n            if(res) {\n                StringBuilder buf = new StringBuilder();\n                for(int i=0;i<n;i++) {\n                    if(i > 0) {\n                        buf.append(' ');\n                    }\n                    buf.append('0');\n                }\n                out(buf);\n            }\n        } else {\n            dest = new HashMap<>();\n            boolean res = true;\n            for(int x: p) {\n                boolean aOk = pset.contains(a-x);\n                boolean bOk = pset.contains(b-x);\n                if(!aOk && !bOk) {\n                    res = false;\n                    break;\n                } else {\n                    if(aOk) {\n                        addEdgeAndBack(x,a-x,0);\n                    }\n                    if(bOk) {\n                        addEdgeAndBack(x,b-x,1);\n                    }\n                }\n            }\n            Set<Integer> aSet = new HashSet<>();\n            if(res) {\n                for(int x: p) {\n                    List<int[]> e = getEdges(x);\n                    if(e.size() == 1) {\n                        int[] edge = e.get(0);\n                        if(edge[0] == x) {\n                            if(edge[1] == 0) {\n                                aSet.add(x);\n                            }\n                        } else {\n                            boolean odd = true;\n                            int curA = edge[1];\n                            int prev = x;\n                            while(true) {\n                                int cur = edge[0];\n                                if(curA == 0 && odd) {\n                                    aSet.add(prev);\n                                    aSet.add(cur);\n                                }\n                                e = getEdges(cur);\n                                if(e.size() == 1) {\n                                    if(!odd && e.get(0)[0] != cur) {\n                                        res = false;\n                                    }\n                                    break;\n                                }\n                                int other = e.get(0)[0] == prev?1:0;\n                                edge = e.get(other);\n                                if(edge[1] == curA) {\n                                    res = false;\n                                    break;\n                                }\n                                curA = 1-curA;\n                                prev = cur;\n                                odd = !odd;\n                            }\n                            if(!res) {\n                                break;\n                            }\n                        }\n                    }\n                }\n            }\n            out(res?\"YES\":\"NO\");\n            if(res) {\n                StringBuilder buf = new StringBuilder();\n                for(int i=0;i<n;i++) {\n                    if(i>0) {\n                        buf.append(' ');\n                    }\n                    buf.append(aSet.contains(p[i])?'0':'1');\n                }\n                out(buf);\n            }\n        }\n    }\n\n    private void addEdgeAndBack(int from, int to, int u) {\n        addEdge(from, to, u);\n        addEdge(to, from, u);\n    }\n\n    private void addEdge(int from, int to, int u) {\n        List<int[]> edges = getEdges(from);\n        for(int[] edge: edges) {\n            if(edge[0] == to) {\n                return;\n            }\n        }\n        edges.add(new int[] { to, u });\n    }\n\n    private List<int[]> getEdges(int from) {\n        List<int[]> ds = dest.get(from);\n        if(ds == null) {\n            ds = new ArrayList<>();\n            dest.put(from, ds);\n        }\n        return ds;\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 ProblemB();\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n    static PrintWriter writer;\n\n    static int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    static long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    static double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    static String nextToken() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    public static void main(String[] args) throws IOException {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n        writer = new PrintWriter(System.out);\n        pineapple();\n        reader.close();\n        writer.close();\n    }\n\n    static void pineapple() throws NumberFormatException, IOException {\n        int n = nextInt();\n        int a = nextInt();\n        int b = nextInt();\n        HashSet<Integer> al = new HashSet<Integer>();\n        HashMap<Integer, Integer> mp = new HashMap<Integer, Integer>();\n        int[] ans = new int[n];\n        Arrays.fill(ans, -1);\n        HashSet<Integer> used = new HashSet<Integer>();\n        int[] mas = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            int t = nextInt();\n            al.add(t);\n            mas[i] = t;\n            mp.put(t, i);\n        }\n\n        for (int st : al) {\n            if (used.contains(st))\n                continue;\n\n            {\n                int pr = st;\n                int cc = -1;\n                HashSet<Integer> u2 = new HashSet<Integer>();\n                u2.add(pr);\n                if (!u2.contains(a - pr) && al.contains(a - pr))\n                    cc = a - pr;\n                if (!u2.contains(a - pr) && al.contains(b - pr))\n                    cc = b - pr;\n                if (cc != -1) {\n                    u2.add(cc);\n                    boolean bGo = true;\n                    while (bGo) {\n                        bGo = false;\n                        int nxt = -1;\n                        if (!u2.contains(a - cc) && al.contains(a - cc))\n                            nxt = a - cc;\n                        if (!u2.contains(b - cc) && al.contains(b - cc))\n                            nxt = b - cc;\n                        if (nxt != -1) {\n                            bGo = true;\n                            u2.add(nxt);\n                            cc = nxt;\n                            pr = cc;\n                        }\n                    }\n                    st = cc;\n                }\n            }\n\n            LinkedList<Integer> ll = new LinkedList<Integer>();\n            ll.add(st);\n            while (!ll.isEmpty()) {\n                int curr = ll.pollFirst();\n                used.add(curr);\n                int next1 = a - curr;\n                if (al.contains(next1)) {\n                    if (!used.contains(next1)) {\n                        ll.addLast(next1);\n                        if (ans[mp.get(curr)] == -1 && ans[mp.get(next1)] == -1) {\n                            ans[mp.get(next1)] = 0;\n                            ans[mp.get(curr)] = 0;\n                        }\n                    }\n                }\n                int next2 = b - curr;\n                if (al.contains(next2)) {\n                    if (!used.contains(next2)) {\n                        ll.addLast(next2);\n                        if (ans[mp.get(curr)] == -1 && ans[mp.get(next2)] == -1) {\n                            ans[mp.get(next2)] = 1;\n                            ans[mp.get(curr)] = 1;\n                        }\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (ans[i] == -1) {\n                if (2 * mas[i] == a) {\n                    ans[i] = 0;\n                    continue;\n                }\n                if (2 * mas[i] == b) {\n                    ans[i] = 1;\n                    continue;\n                }\n                writer.println(\"NO\");\n                return;\n            }\n        }\n\n        writer.println(\"YES\");\n        for (int i = 0; i < n; i++) {\n            writer.print(ans[i] + \" \");\n        }\n    }\n    }", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class b {\npublic static void main(String[] args) throws IOException\n{\n    input.init(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n    int n = input.nextInt(), a = input.nextInt(), b = input.nextInt();\n    Num[] data = new Num[n];\n    for(int i = 0; i<n; i++) data[i] = new Num(input.nextInt(), i);\n    int[] res = new int[n];\n    Arrays.fill(res,-1);\n    Arrays.sort(data);\n    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n    for(int i = 0; i<n; i++)\n        map.put(data[i].x, data[i].i);\n    boolean good = true;\n    for(int i = 0; i<n; i++)\n    {\n        if(res[data[i].i] != -1) continue;\n        int val = data[i].x;\n        if(!map.containsKey(a-val) && !map.containsKey(b-val))\n        {\n            good = false;\n            break;\n        }\n        if(!map.containsKey(a-val))\n        {\n            int other = map.get(b-val);\n            if(res[other] == 0)\n            {\n                good = false;\n                break;\n            }\n            res[other] = res[data[i].i] = 1;\n        }\n        else if(!map.containsKey(b-val))\n        {\n            int other = map.get(a-val);\n            if(res[other] == 1)\n            {\n                good = false;\n                break;\n            }\n            res[other] = res[data[i].i] = 0;\n        }\n        else\n        {\n            int cur = data[i].i;\n            int otherB = map.get(b-val), otherA = map.get(a-val);\n            if(b > a && res[otherB] != 0)\n            {\n                res[cur] = res[otherB] = 1;\n            }\n            else if(a>b && res[otherA] != 1)\n            {\n                res[cur] = res[otherA] = 0;\n            }\n            else if(b > a && res[otherA] != 1)\n            {\n                res[cur] = res[otherA] = 0;\n            }\n            else if(a > b && res[otherB] != 0)\n            {\n                res[cur] = res[otherB] = 1;\n            }\n            else if(b == a)\n            {\n                res[cur] = res[otherA] = 0;\n            }\n            else\n            {\n                good = false;\n                break;\n            }\n        }\n    }\n    if(good)\n    {\n        out.println(\"YES\");\n        for(int x: res) out.print(x+\" \");\n    }\n    else\n        out.println(\"NO\");\n    \n    out.close();\n}\nstatic class Num implements Comparable<Num>\n{\n    int x, i;\n    public Num(int xx, int ii)\n    {\n        x = xx; i = ii;\n    }\n    @Override\n    public int compareTo(Num o) {\n        // TODO Auto-generated method stub\n        return x - o.x;\n    }\n}\npublic static class input {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    /** get next word */\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n    static long nextLong() throws IOException {\n        return Long.parseLong( next() );\n    }\n}\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    \n    private PrintWriter out;\n    private Map<Integer, Integer> map;\n    \n    private int arr[], ans[];\n    int n, a, b;\n \n    class DSU {\n        private int[] p, size;\n        \n        public DSU(int n) {\n            p = new int[n];\n            size = new int[n];\n            \n            for (int i=0; i<n; i++) {\n                p[i] = i;\n                size[i] = 1;\n            }\n        }\n        \n        public int find(int i) {\n            if (p[i] == i) {\n                return i;\n            }\n            return p[i] = find(p[i]);\n        }\n        \n        public void union (int a, int b) {\n            a = find(a); b = find(b);\n            if (size[a] > size[b]) {\n                p[b] = a;\n                size[a] += size[b];\n            } else {\n                p[a] = b;\n                size[b] += size[a];\n            }\n        }\n    }\n    \n    private void solve() throws Exception {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n\n        StringTokenizer st = new StringTokenizer(in.readLine());\n        \n        n = Integer.valueOf(st.nextToken());\n        a = Integer.valueOf(st.nextToken());\n        b = Integer.valueOf(st.nextToken());\n        map = new HashMap<Integer, Integer>(n);\n        \n        String line = in.readLine();\n        StringTokenizer st1 = new StringTokenizer(line);\n        \n        arr = new int[n];\n        ans = new int[n];\n        DSU dsu = new DSU(n);\n        \n        for (int i=0; i<n; i++) {\n            arr[i] = Integer.valueOf(st1.nextToken());\n            map.put(arr[i], i);\n        }\n        in.close();\n        \n        for (int i=0; i<n; i++) {\n            boolean f = false;\n            if (map.get(a - arr[i]) != null) {\n                f = true;\n                dsu.union(i, map.get(a - arr[i]));\n            }\n            \n            if (map.get(b - arr[i]) != null) {\n                f = true;\n                dsu.union(i, map.get(b - arr[i]));\n            }\n            \n            if (!f) {\n                out.println(\"NO\");\n                out.flush();\n                return;\n            }\n        }\n        \n        for (int i=0; i<n; i++) {\n            int p = dsu.find(i);\n            if (map.get(a - arr[i]) == null) {\n                ans[p] = 1;\n            } else if (map.get(b - arr[i]) == null) {\n                ans[p] = 0;\n            }\n        }\n        \n        for (int i=0; i<n; i++) {\n            int p = dsu.find(i);\n            if (ans[p] == 0 && map.get(a - arr[i]) == null) {\n                out.println(\"NO\");\n                out.flush();\n                return;\n            } \n            \n            if (ans[p] == 1 && map.get(b - arr[i]) == null) {\n                out.println(\"NO\");\n                out.flush();\n                return;\n            }\n        }\n        \n        out.println(\"YES\");\n        for (int i=0; i<n; i++) {\n            out.print(ans[dsu.find(i)] + \" \");\n        }\n                \n        out.flush();\n        out.close();\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Main().solve();\n    }\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Pr468B {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Pr468B().run();\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\tst = new StringTokenizer(in.readLine());\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\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out, true);\n\t\tsolve();\n\t\tout.flush();\n\t}\n\n\tint[] which;\n\tboolean[] was;\n\tint[] pa;\n\tint[] pb;\n\n\tvoid dfs(int i, boolean fa) {\n\t\twas[i] = true;\n\t\tif (fa) {\n\t\t\tif (pa[i] == -1) {\n\t\t\t\tout.println(\"NO\");\n\t\t\t\tout.flush();\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\twhich[i] = 0;\n\t\t\twhich[pa[i]] = 0;\n\t\t\tif (pb[pa[i]] != -1 && !was[pb[pa[i]]]) {\n\t\t\t\tdfs(pb[pa[i]], fa);\n\t\t\t}\n\t\t} else {\n\t\t\tif (pb[i] == -1) {\n\t\t\t\tout.println(\"NO\");\n\t\t\t\tout.flush();\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\twhich[i] = 1;\n\t\t\twhich[pb[i]] = 1;\n\t\t\tif (pa[pb[i]] != -1 && !was[pa[pb[i]]]) {\n\t\t\t\tdfs(pa[pb[i]], fa);\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tint[] p = new int[n];\n\t\tHashMap<Integer, Integer> allNums = new HashMap<Integer, Integer>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tp[i] = nextInt();\n\t\t\tif (p[i] >= Math.max(a, b)) {\n\t\t\t\tout.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tallNums.put(p[i], i);\n\t\t}\n\t\tpa = new int[n];\n\t\tpb = new int[n];\n\t\tArrays.fill(pa, -1);\n\t\tArrays.fill(pb, -1);\n\t\twhich = new int[n];\n\t\tArrays.fill(which, -1);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (pa[i] == -1 && allNums.containsKey(a - p[i])) {\n\t\t\t\tpa[i] = allNums.get(a - p[i]);\n\t\t\t\tpa[pa[i]] = i;\n\t\t\t}\n\t\t\tif (pb[i] == -1 && allNums.containsKey(b - p[i])) {\n\t\t\t\tpb[i] = allNums.get(b - p[i]);\n\t\t\t\tpb[pb[i]] = i;\n\t\t\t}\n\t\t\tif (pa[i] == -1 && pb[i] == -1) {\n\t\t\t\tout.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\twas = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!was[i] && pa[i] == -1) {\n\t\t\t\tdfs(i, false);\n\t\t\t} else if (!was[i] && pb[i] == -1) {\n\t\t\t\tdfs(i, true);\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!was[i]) {\n\t\t\t\tdfs(i, true);\n\t\t\t}\n\t\t}\n\t\tout.println(\"YES\");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tout.print(which[i] + \" \");\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedInputStream;\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Map.Entry;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(new BufferedInputStream(System.in));\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(\n\t\t\t\tnew OutputStreamWriter(System.out)));\n\n\t\twhile (in.hasNext()) {\n\t\t\tint n = in.nextInt(), a = in.nextInt(), b = in.nextInt(), c = 0;\n\t\t\tint[] p = new int[n];\n\n\t\t\tTreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tp[i] = in.nextInt();\n\t\t\t\tmap.put(p[i], i);\n\t\t\t}\n\t\t\t\n\t\t\tif (a > b) {\n\t\t\t\tint t = b;\n\t\t\t\tb = a;\n\t\t\t\ta = t;\n\t\t\t\tc = 1;\n\t\t\t}\n\n\t\t\tboolean ok = true;\n\t\t\tint[] cls = new int[n];\n\t\t\twhile (ok && map.size() > 0) {\n\t\t\t\tEntry<Integer, Integer> last = map.lastEntry();\n\t\t\t\tint v = last.getKey();\n\t\t\t\tint idx = last.getValue();\n\t\t\t\tif (map.containsKey(a - v)) {\n\t\t\t\t\tcls[idx] = 0;\n\t\t\t\t\tcls[map.get(a - v)] = 0;\n\t\t\t\t\tmap.remove(v);\n\t\t\t\t\tmap.remove(a -v);\n\t\t\t\t} else if (map.containsKey(b - v)) {\n\t\t\t\t\tcls[idx] = 1;\n\t\t\t\t\tcls[map.get(b - v)] = 1;\n\t\t\t\t\tmap.remove(v);\n\t\t\t\t\tmap.remove(b -v);\n\t\t\t\t} else \n\t\t\t\t\tok = false;\n\t\t\t}\n\n\t\t\tif (!ok)\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tfor (int j = 0; j < cls.length; j++) {\n\t\t\t\t\tif (j != 0)\n\t\t\t\t\t\tSystem.out.print(\" \");\n\t\t\t\t\tSystem.out.print(c ^ cls[j]);\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tout.flush();\n\t\t}\n\t\tin.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\n// Solution is at the bottom of code\n\npublic class B implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tOutputWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new B(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tLocale.setDefault(Locale.US);\n\t\t\n\t\tif (ONLINE_JUDGE){\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new OutputWriter(System.out);\n\t\t}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new OutputWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\t////////////////////////////////////////////////////////////////\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (ONLINE_JUDGE){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t\ttime();\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tString delim = \" \";\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tok.nextToken(delim);\n\t}\n\t\n\tString readLine() throws IOException{\n\t\treturn in.readLine();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tfinal char NOT_A_SYMBOL = '\\0';\n\t\n\tchar readChar() throws IOException{\n\t\tint intValue = in.read();\n\t\t\n\t\tif (intValue == -1){\n\t\t\treturn NOT_A_SYMBOL;\n\t\t}\n\t\t\n\t\treturn (char) intValue;\n\t}\n\t\n\tchar[] readCharArray() throws IOException{\n\t\treturn readLine().toCharArray();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tint[] readIntArray(int size) throws IOException {\n\t\tint[] array = new int[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\ttry {\n\t\t\t\tarray[index] = readInt();\n\t\t\t} catch (Exception e) {\n\t\t\t\tSystem.err.println(index);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\tint[] readSortedIntArray(int size) throws IOException {\n\t\tInteger[] array = new Integer[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index) {\n\t\t\tarray[index] = readInt();\n\t\t}\n\t\tArrays.sort(array);\n\t\t\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\t\t\n\t\treturn sortedArray;\n\t}\n\t\n\tint[] readIntArrayWithDecrease(int size) throws IOException {\n\t\tint[] array = readIntArray(size);\n\t\t\n\t\tfor (int i = 0; i < size; ++i) {\n\t\t\tarray[i]--;\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tint[][] readIntMatrix(int rowsCount, int columnsCount) throws IOException {\n\t\tint[][] matrix = new int[rowsCount][];\n\t\t\n\t\tfor (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n\t\t\tmatrix[rowIndex] = readIntArray(columnsCount);\n\t\t}\n\t\t\n\t\treturn matrix;\n\t}\n\t\n\tint[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) throws IOException {\n\t\tint[][] matrix = new int[rowsCount][];\n\t\t\n\t\tfor (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n\t\t\tmatrix[rowIndex] = readIntArrayWithDecrease(columnsCount);\n\t\t}\n\t\t\n\t\treturn matrix;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tlong[] readLongArray(int size) throws IOException{\n\t\tlong[] array = new long[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readLong();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tdouble[] readDoubleArray(int size) throws IOException{\n\t\tdouble[] array = new double[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readDouble();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\t\n\tBigInteger readBigInteger() throws IOException {\n\t\treturn new BigInteger(readString());\n\t}\n\t\n\tBigDecimal readBigDecimal() throws IOException {\n\t\treturn new BigDecimal(readString());\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tPoint readPoint() throws IOException{\n\t\tint x = readInt();\n\t\tint y = readInt();\n\t\treturn new Point(x, y);\n\t}\n\t\n\tPoint[] readPointArray(int size) throws IOException{\n\t\tPoint[] array = new Point[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readPoint();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tList<Integer>[] readGraph(int vertexNumber, int edgeNumber)\n\tthrows IOException{\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tList<Integer>[] graph = new List[vertexNumber];\n\t\t\n\t\tfor (int index = 0; index < vertexNumber; ++index){\n\t\t\tgraph[index] = new ArrayList<Integer>();\n\t\t}\n\t\t\n\t\twhile (edgeNumber-- > 0){\n\t\t\tint from = readInt() - 1;\n\t\t\tint to = readInt() - 1;\n\t\t\t\n\t\t\tgraph[from].add(to);\n\t\t\tgraph[to].add(from);\n\t\t}\n\t\t\n\t\treturn graph;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tstatic class IntIndexPair {\n\t\t\n\t\tstatic Comparator<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {\n\t\t\t\tint value1 = indexPair1.value;\n\t\t\t\tint value2 = indexPair2.value;\n\t\t\t\t\n\t\t\t\tif (value1 != value2) return value1 - value2;\n\t\t\t\t\n\t\t\t\tint index1 = indexPair1.index;\n\t\t\t\tint index2 = indexPair2.index;\n\t\t\t\t\n\t\t\t\treturn index1 - index2;\n\t\t\t}\n\t\t};\n\t\t\n\t\tstatic Comparator<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) {\n\t\t\t\tint value1 = indexPair1.value;\n\t\t\t\tint value2 = indexPair2.value;\n\t\t\t\t\n\t\t\t\tif (value1 != value2) return -(value1 - value2);\n\t\t\t\t\n\t\t\t\tint index1 = indexPair1.index;\n\t\t\t\tint index2 = indexPair2.index;\n\t\t\t\t\n\t\t\t\treturn index1 - index2;\n\t\t\t}\n\t\t};\n\t\t\n\t\tint value, index;\n\n\t\tpublic IntIndexPair(int value, int index) {\n\t\t\tsuper();\n\t\t\tthis.value = value;\n\t\t\tthis.index = index;\n\t\t}\t\t\n\t\t\n\t\tpublic int getRealIndex() {\n\t\t\treturn index + 1;\n\t\t}\n\t}\n\t\n\tIntIndexPair[] readIntIndexArray(int size) throws IOException {\n\t\tIntIndexPair[] array = new IntIndexPair[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index) {\n\t\t\tarray[index] = new IntIndexPair(readInt(), index);\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tstatic class OutputWriter extends PrintWriter {\n\n\t\tfinal int DEFAULT_PRECISION = 12;\n\t\t\n\t\tprotected int precision;\n\t\tprotected String format, formatWithSpace;\n\t\t\n\t\t{\n\t\t\tprecision = DEFAULT_PRECISION;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tpublic OutputWriter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\n\t\tpublic OutputWriter(String fileName) throws FileNotFoundException {\n\t\t\tsuper(fileName);\n\t\t}\n\t\t\n\t\tpublic int getPrecision() {\n\t\t\treturn precision;\n\t\t}\n\n\t\tpublic void setPrecision(int precision) {\n\t\t\tprecision = max(0, precision);\n\t\t\tthis.precision = precision;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tprivate String createFormat(int precision){\n\t\t\treturn \"%.\" + precision + \"f\";\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void print(double d){\n\t\t\tprintf(format, d);\n\t\t}\n\t\t\n\t\tpublic void printWithSpace(double d){\n\t\t\tprintf(formatWithSpace, d);\n\t\t}\n\n\t\tpublic void printAll(double...d){\n\t\t\tfor (int i = 0; i < d.length - 1; ++i){\n\t\t\t\tprintWithSpace(d[i]);\n\t\t\t}\n\t\t\t\n\t\t\tprint(d[d.length - 1]);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void println(double d){\n\t\t\tprintlnAll(d);\n\t\t}\n\t\t\n\t\tpublic void printlnAll(double... d){\n\t\t\tprintAll(d);\n\t\t\tprintln();\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tstatic final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; \n\tstatic final int[][] steps8 = {\n\t\t\t{-1, 0}, {1, 0}, {0, -1}, {0, 1},\n\t\t\t{-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n\t};\n\t\n\tstatic final boolean check(int index, int lim){\n\t\treturn (0 <= index && index < lim);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tstatic final boolean checkBit(int mask, int bit){\n\t\treturn (mask & (1 << bit)) != 0;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tstatic final long getSum(int[] array) {\n\t\tlong sum = 0;\n\t\tfor (int value: array) {\n\t\t\tsum += value;\n\t\t}\n\t\t\n\t\treturn sum;\n\t}\n\t\n\tstatic final Point getMinMax(int[] array) {\n\t\tint min = array[0];\n\t\tint max = array[0];\n\t\t\n\t\tfor (int index = 0, size = array.length; index < size; ++index, ++index) {\n\t\t\tint value = array[index];\n\t\t\t\n\t\t\tif (index == size - 1) {\n\t\t\t\tmin = min(min, value);\n\t\t\t\tmax = max(max, value);\n\t\t\t} else {\n\t\t\t\tint otherValue = array[index + 1];\n\t\t\t\t\n\t\t\t\tif (value <= otherValue) {\n\t\t\t\t\tmin = min(min, value);\n\t\t\t\t\tmax = max(max, otherValue);\n\t\t\t\t} else {\n\t\t\t\t\tmin = min(min, otherValue);\n\t\t\t\t\tmax = max(max, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn new Point(min, max);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\t\n\t\tint a = readInt();\n\t\tint b = readInt();\n\t\t\n\t\tMap<Integer, Integer> numbers = new HashMap<>();\n\t\tint[] p = readIntArray(n);\n\t\tfor (int index = 0; index < n; ++index) {\n\t\t\tnumbers.put(p[index], index);\n\t\t}\n\t\t\n\t\tSet<Integer> used = new HashSet<Integer>();\n\t\tDeque<Integer> q = new ArrayDeque<Integer>();\n\t\t\n\t\tint[] answers = new int[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (used.contains(p[i])) continue;\n\t\t\t\n\t\t\tint leftSize = 0;\n\t\t\tfor (int number = p[i], cur = a, next = b;\n\t\t\t\t\tnumbers.containsKey(number) && !used.contains(number);\n\t\t\t\t\tnumber = cur - number, cur = (a ^ b ^ cur), next = (a ^ b ^ next)) {\n\t\t\t\tq.addFirst(number);\n\t\t\t\tused.add(number);\n\t\t\t\t\n\t\t\t\t++leftSize;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int number = b - p[i], cur = a, next = b;\n\t\t\t\t\tnumbers.containsKey(number) && !used.contains(number);\n\t\t\t\t\tnumber = cur - number, cur = (a ^ b ^ cur), next = (a ^ b ^ next)) {\n\t\t\t\tq.addLast(number);\n\t\t\t\tused.add(number);\n\t\t\t}\n\t\t\t\n\t\t\tint curColor = (leftSize & 1);\n\t\t\tif ((q.size() & 1) == 1) {\n\t\t\t\tint first = q.peekFirst();\n\t\t\t\t\n\t\t\t\t// 0 - a, 1 - b\n\t\t\t\tif (curColor == 0 && (first << 1) == b\n\t\t\t\t\t\t||\n\t\t\t\t\tcurColor == 1 && (first << 1) == a) {\n\t\t\t\t\tq.poll();\n\t\t\t\t\t\n\t\t\t\t\tcurColor ^= 1;\n\t\t\t\t\t\n\t\t\t\t\tint firstIndex = numbers.get(first);\n\t\t\t\t\tanswers[firstIndex] = curColor;\n\t\t\t\t} else {\n\t\t\t\t\tint last = q.peekLast();\n\t\t\t\t\t\n\t\t\t\t\t// 0 - b, 1 - a\n\t\t\t\t\tif (curColor == 0 && (last << 1) == a\n\t\t\t\t\t\t\t||\n\t\t\t\t\t\tcurColor == 1 && (first << 1) == b) {\n\t\t\t\t\t\tq.poll();\n\t\t\t\t\t\t\n\t\t\t\t\t\tint firstIndex = numbers.get(first);\n\t\t\t\t\t\tanswers[firstIndex] = curColor;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout.println(\"NO\");\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\t\n\t\t\twhile (q.size() > 0) {\n\t\t\t\tint first = q.poll();\n\t\t\t\tint second = q.poll();\n\t\t\t\t\n\t\t\t\tint firstIndex = numbers.get(first);\n\t\t\t\tint secondIndex = numbers.get(second);\n\t\t\t\t\n\t\t\t\tanswers[firstIndex] = curColor;\n\t\t\t\tanswers[secondIndex] = curColor;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(\"YES\");\n\t\tfor (int answer : answers) {\n\t\t\tout.print(answer + \" \");\n\t\t}\n\t\tout.println();\n\t}\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.List;\nimport 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 Nipuna Samarasekara\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    /////////////////////////////////////////////////////////////\n    static nn[] B;\n    static int n,a,b;\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n     n=in.nextInt();a=in.nextInt();b=in.nextInt();\n        int ccc=0;\n        if (a==b)ccc=1;\n     int[] A=in.readIntArray(n);\n      B=new nn[n];\n        for (int i = 0; i < n; i++) {\n            B[i]=new nn(A[i],i);\n        }\n        ArrayUtils.shuffle(B);\n        Arrays.sort(B);\n        int chk=1;\n        for (int i = 0; i < n; i++) {\n            if (B[i].assign>=0)continue;\n            int v=B[i].val;\n            int cc=0;\n            int pos1=Arrays.binarySearch(B,new nn(a-v,0));\n            if (pos1>=0&&B[pos1].assign==-1)cc++;\n           if (a!=b){\n            int pos2=Arrays.binarySearch(B,new nn(b-v,0));\n            if (pos2>=0&&B[pos2].assign==-1)cc++; }\n            if (cc==0){\n                chk=0;\n                break;\n            }\n            if (cc==1){\n            go(i);\n            }\n        }\n        if (chk==0){\n            out.println(\"NO\");\n            return;\n        }\n        int[] ans= new int[n];\n        for (int i = 0; i < n; i++) {\n            ans[B[i].pos]=B[i].assign;\n        }\n        out.println(\"YES\");\n        for (int i = 0; i < n; i++) {\n          out.print(ans[i] + \" \");\n        }\n        out.println();\n        }\n    static void go (int i){\n        int v=B[i].val;\n        int pos1=Arrays.binarySearch(B,new nn(a-v,0));\n        if (pos1>=0&&B[pos1].assign==-1){\n           B[i].assign=0;\n           B[pos1].assign=0;\n           int vv=B[pos1].val;\n           int np=Arrays.binarySearch(B,new nn(b-vv,0));\n           if (np>=0)go(np);\n\n        }\n        if (a!=b){\n        int pos2=Arrays.binarySearch(B,new nn(b-v,0));\n        if (pos2>=0&&B[pos2].assign==-1){\n            B[i].assign=1;\n            B[pos2].assign=1;\n            int vv=B[pos2].val;\n            int np=Arrays.binarySearch(B,new nn(a-vv,0));\n            if (np>=0)go(np);\n        } }\n\n    }\n\n}\n\nclass nn implements Comparable<nn> {\n        int val,pos;\n\n        public String toString() {\n            return \"nn{\" +\n                    \"val=\" + val +\n                    \", pos=\" + pos +\n                    \", assign=\" + assign +\n                    \", ct=\" + ct +\n                    '}';\n        }\n\n        int assign=-1;\n        int ct=0;\n        nn(int val, int pos) {\n            this.val = val;\n            this.pos = pos;\n        }\n\n        public int compareTo(nn o) {\n            return this.val-o.val;  //To change body of implemented methods use File | Settings | File Templates.\n        }\n\n}\n\nclass FastScanner extends BufferedReader {\n\n    public FastScanner(InputStream is) {\n        super(new InputStreamReader(is));\n    }\n\n    public int read() {\n        try {\n            int ret = super.read();\n//            if (isEOF && ret < 0) {\n//                throw new InputMismatchException();\n//            }\n//            isEOF = ret == -1;\n            return ret;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    static boolean isWhiteSpace(int c) {\n        return c >= 0 && c <= 32;\n    }\n\n    public int nextInt() {\n        int c = read();\n        while (isWhiteSpace(c)) {\n            c = read();\n        }\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        int ret = 0;\n        while (c >= 0 && !isWhiteSpace(c)) {\n            if (c < '0' || c > '9') {\n                throw new NumberFormatException(\"digit expected \" + (char) c\n                        + \" found\");\n            }\n            ret = ret * 10 + c - '0';\n            c = read();\n        }\n        return ret * sgn;\n    }\n\n    public String readLine() {\n        try {\n            return super.readLine();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    public int[] readIntArray(int n) {\n        int[] ret = new int[n];\n        for (int i = 0; i < n; i++) {\n            ret[i] = nextInt();\n        }\n        return ret;\n    }\n\n}\n\nclass FastPrinter extends PrintWriter {\n\n    public FastPrinter(OutputStream out) {\n        super(out);\n    }\n\n    public FastPrinter(Writer out) {\n        super(out);\n    }\n\n\n}\n\nclass ArrayUtils {\n\n\n    static final long seed = System.nanoTime();\n\n    static final Random rand = new Random(seed);\n\n\n    public static <T> void shuffle(T[] a) {\n        for (int i = 0; i < a.length; i++) {\n            int j = rand.nextInt(i + 1);\n            T t = a[i];\n            a[i] = a[j];\n            a[j] = t;\n        }\n    }\n\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.io.IOException;\nimport java.util.TreeMap;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.util.ArrayDeque;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Queue;\nimport java.util.Collection;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author karan173\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        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n}\n\nclass TaskB\n{\n    int val[];\n    int p[];\n    int aneigh[], bneight[], deg[];\n    public void solve(int testNumber, FastReader in, PrintWriter out)\n    {\n        int n = in.ni ();\n        val = new int[n];\n        int a = in.ni ();\n        int b = in.ni ();\n        Map<Integer, Integer> set = new TreeMap<Integer, Integer> ();\n        p = in.iArr (n);\n        for (int i = 0; i < n; i++)\n        {\n            set.put (p[i], i);\n        }\n        aneigh = new int[n];\n        bneight = new int[n];\n        deg = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            aneigh[i] = val[i] = bneight[i] = -1;\n            deg[i] = 0;\n        }\n        Queue<Integer> queue = new ArrayDeque<Integer> ();\n        for (int i = 0; i < n; i++)\n        {\n            Integer x1 = set.get (a - p[i]);\n            Integer x2 = set.get (b - p[i]);\n            if (x1 != null)\n            {\n                aneigh[i] = x1;\n                deg[i]++;\n            }\n            if (x2 != null && a != b)\n            {\n                bneight[i] = x2;\n                deg[i]++;\n            }\n            if (deg[i] == 1)\n            {\n                queue.add (i);\n            }\n        }\n\n        while (!queue.isEmpty ())\n        {\n            int idx = queue.remove ();\n            if (deg[idx] != 1)\n            {\n                continue;\n            }\n            int aa = aneigh[idx];\n            int bb = bneight[idx];\n            if (aa != -1)\n            {\n                val[idx] = val[aa] = 0;\n                deg[aa]--;\n                deg[idx]--;\n                aneigh[aa] = -1;\n                aneigh[idx] = -1;\n                if (deg[aa] == 1)\n                {\n                    int zz = bneight[aa];\n                    bneight[zz] = -1;\n                    deg[zz]--;\n                    if(deg[zz] == 1)\n                    queue.add (zz);\n                }\n            }\n            else\n            {\n                val[idx] = val[bb] = 1;\n                deg[bb]--;\n                deg[idx]--;\n                bneight[idx] = bneight[bb] = -1;\n                if (deg[bb] == 1)\n                {\n                    //queue.add (bb);\n                    int zz = aneigh[bb];\n                    aneigh[zz] = -1;\n                    deg[zz]--;\n                    if(deg[zz] == 1)\n                        queue.add (zz);\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++)\n        {\n            if (val[i] == -1 && cantBePaired(i))\n            {\n                out.println (\"NO\");\n                return;\n            }\n        }\n        //every person has two neighbours\n\n        out.println (\"YES\");\n        for (int i = 0; i < n; i++)\n        {\n            out.print (val[i] + \" \");\n        }\n        out.println ();\n    }\n\n    private boolean cantBePaired(int i)\n    {\n        int aa = aneigh[i];\n        int bb = bneight[i];\n        if (aa != -1 && val[aa] == -1)\n        {\n            return false;\n        }\n        if (bb != -1 && val[bb] == -1)\n        {\n            return false;\n        }\n        return true;\n    }\n}\n\nclass FastReader\n{\n\n    public 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    {\n        this.stream = stream;\n    }\n\n    public FastReader()\n    {\n\n    }\n\n    public int read()\n    {\n        if (numChars == -1)\n        {\n            throw new InputMismatchException ();\n        }\n        if (curChar >= 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            {\n                return -1;\n            }\n        }\n        return buf[curChar++];\n    }\n\n    public int ni()\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            {\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    {\n        if (filter != null)\n        {\n            return filter.isSpaceChar (c);\n        }\n        return isWhitespace (c);\n    }\n\n    public static boolean isWhitespace(int c)\n    {\n        return c==' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int[] iArr(int n)\n    {\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            a[i] = ni ();\n        }\n        return a;\n    }\n\n    public interface SpaceCharFilter\n    {\n        public boolean isSpaceChar(int ch);\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.io.BufferedReader;\nimport java.util.List;\nimport java.util.Map;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author shu_mj @ http://shu-mj.com\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    Scanner in;\n    PrintWriter out;\n\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        this.in = in;\n        this.out = out;\n        run();\n    }\n\n    void run() {\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] is = in.nextIntArray(n);\n        Map<Integer, Integer> id = new HashMap<Integer, Integer>();\n        for (int i = 0; i < n; i++) {\n            id.put(is[i], i);\n        }\n        SCC.V[] vs = new SCC.V[n * 2];\n        for (int i = 0; i < vs.length; i++) vs[i] = new SCC.V();\n        for (int i = 0; i < n; i++) {\n            if (id.containsKey(a - is[i])) {\n                int j = id.get(a - is[i]);\n                vs[i].add(vs[j]);\n                vs[j + n].add(vs[i + n]);\n            } else {\n                vs[i].add(vs[i + n]);\n            }\n            if (id.containsKey(b - is[i])) {\n                int j = id.get(b - is[i]);\n                vs[i + n].add(vs[j + n]);\n                vs[j].add(vs[i]);\n            } else {\n                vs[i + n].add(vs[i]);\n            }\n        }\n        SCC.scc(vs);\n        for (int i = 0; i < n; i++) {\n            if (vs[i].comp == vs[i + n].comp) {\n                out.println(\"NO\");\n                return ;\n            }\n        }\n        out.println(\"YES\");\n        for (int i = 0; i < n; i++) {\n            if (vs[i].comp > vs[i + n].comp) {\n                out.print(\"0 \");\n            } else {\n                out.print(\"1 \");\n            }\n        }\n        out.println();\n    }\n}\n\nclass Scanner {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public Scanner(InputStream in) {\n        br = new BufferedReader(new InputStreamReader(in));\n        eat(\"\");\n    }\n\n    private void eat(String s) {\n        st = new StringTokenizer(s);\n    }\n\n    public String nextLine() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    public boolean hasNext() {\n        while (!st.hasMoreTokens()) {\n            String s = nextLine();\n            if (s == null)\n                return false;\n            eat(s);\n        }\n        return true;\n    }\n\n    public String next() {\n        hasNext();\n        return st.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    public int[] nextIntArray(int n) {\n        int[] is = new int[n];\n        for (int i = 0; i < n; i++) {\n            is[i] = nextInt();\n        }\n        return is;\n    }\n\n}\n\nclass SCC {\n\n    public static int n;\n    public static V[] us;\n\n    public static int scc(V[] vs) {\n        n = vs.length;\n        us = new V[n];\n        for (V v : vs) if (!v.visit) dfs(v);\n        for (V v : vs) v.visit = false;\n        for (V u : us) if (!u.visit) dfsRev(u, n++);\n        return n;\n    }\n\n    public static void dfs(V v) {\n        v.visit = true;\n        for (V u : v.fs) if (!u.visit) dfs(u);\n        us[--n] = v;\n    }\n\n    public static void dfsRev(V v, int k) {\n        v.visit = true;\n        for (V u : v.rs) if (!u.visit) dfsRev(u, k);\n        v.comp = k;\n    }\n\n    public static class V {\n        public boolean visit;\n        public int comp;\n        public List<V> fs = new ArrayList<V>();\n        public List<V> rs = new ArrayList<V>();\n\n        public void add(V u) {\n            fs.add(u);\n            u.rs.add(this);\n        }\n    }\n}\n\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class TwoSets<V> {\n\n    private static int n;\n\n    private static int a;\n\n    private static int b;\n\n    private static List<Node<Integer>> nodes = new LinkedList<Node<Integer>>();\n\n    private static Map<Integer, Node<Integer>> datas = new HashMap<Integer, Node<Integer>>();\n\n    private static Node<Integer> first;\n\n    private static Node<Integer> second;\n\n    private static TwoSets<Integer> sets = new TwoSets<Integer>();\n\n    private static class Node<V> {\n\n\tV node;\n\n\tNode<V> parent;\n\n\tint rank;\n\n\tint color = -1;\n\n\tboolean inprogress;\n\n\tpublic Node() {\n\t    this.parent = this;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t    return String.format(\"{node: %s, parent: %s, rank: %s, color:%s}\",\n\t\t    node, parent.node, rank, color);\n\t}\n    }\n\n    public Node<V> makeSet(V x) {\n\n\tNode<V> node = new Node<V>();\n\n\tnode.node = x;\n\tnode.parent = node;\n\tnode.rank = 0;\n\n\treturn node;\n    }\n\n    public void link(Node<V> x, Node<V> y) {\n\n\tif (x.rank > y.rank) {\n\t    y.parent = x;\n\t} else {\n\t    x.parent = y;\n\t    if (x.rank == y.rank) {\n\t\ty.rank++;\n\t    }\n\t}\n    }\n\n    public Node<V> findSet(Node<V> x) {\n\n\tif (x.parent != x) {\n\t    x.parent = findSet(x.parent);\n\t}\n\n\treturn x.parent;\n    }\n\n    public void union(Node<V> x, Node<V> y) {\n\n\tNode<V> rtX = findSet(x);\n\tNode<V> rtY = findSet(y);\n\tif (rtX.parent != rtY.parent) {\n\t    link(rtX, rtY);\n\t}\n    }\n\n    public V getNode(Node<V> x) {\n\treturn x.node;\n    }\n\n    private int getColor(Node<V> node) {\n\n\tint color;\n\tNode<V> parent = findSet(node);\n\tcolor = parent.color;\n\n\treturn color;\n    }\n\n    private void setColor(Node<V> node, int color) {\n\tNode<V> parent = findSet(node);\n\tparent.color = color;\n    }\n\n    private static Node<Integer> getOrInitNode(Integer key) {\n\n\tNode<Integer> node = datas.get(key);\n\n\tif (node == null) {\n\t    node = sets.makeSet(key);\n\t    datas.put(key, node);\n\t}\n\n\treturn node;\n    }\n\n    private static void initNodes(Scanner scanner) {\n\n\tint key;\n\tNode<Integer> node;\n\tfor (int i = 0; i < n; i++) {\n\t    key = scanner.nextInt();\n\t    node = getOrInitNode(key);\n\t    nodes.add(node);\n\t}\n    }\n\n    private static void unionAll(Node<Integer> value) {\n\n\tint color = sets.getColor(value);\n\tif (color == 0) {\n\t    if (first == null) {\n\t\tfirst = value;\n\t    } else {\n\t\tsets.union(first, value);\n\t    }\n\t} else if (color == 1) {\n\t    if (second == null) {\n\t\tsecond = value;\n\t    } else {\n\t\tsets.union(second, value);\n\t    }\n\t}\n    }\n\n    private static int getKey(Node<Integer> value, int color) {\n\n\tint key = value.node;\n\n\tif (color == 0) {\n\t    key = a - key;\n\t} else {\n\t    key = b - key;\n\t}\n\n\treturn key;\n    }\n\n    private static boolean checkOpposite(Node<Integer> value, int color) {\n\n\tboolean valid;\n\n\tif (value.inprogress) {\n\t    valid = Boolean.TRUE;\n\t} else {\n\t    value.inprogress = Boolean.TRUE;\n\t    int opColor = 1 - color;\n\t    int key = getKey(value, opColor);\n\t    Node<Integer> node = datas.get(key);\n\t    valid = (value.node.equals(key)) || (node == null);\n\t    if (!valid) {\n\t\tkey = getKey(node, color);\n\t\tNode<Integer> child = datas.get(key);\n\t\tvalid = (child != null);\n\t\tif (valid) {\n\t\t    valid = checkOpposite(child, color);\n\t\t    if (valid) {\n\t\t\tsets.union(value, node);\n\t\t\tsets.union(value, child);\n\t\t\tvalue.inprogress = Boolean.FALSE;\n\t\t    }\n\t\t}\n\t    }\n\t    value.inprogress = Boolean.FALSE;\n\t}\n\n\treturn valid;\n    }\n\n    private static boolean checkNodes(Node<Integer> value, int color) {\n\n\tboolean valid;\n\n\tint key = getKey(value, color);\n\tint opColor = 1 - color;\n\tNode<Integer> node = datas.get(key);\n\tvalid = (value.node.equals(key)) || (node != null);\n\tif (valid) {\n\t    valid = checkOpposite(value, color);\n\t    if (valid) {\n\t\tsets.union(value, node);\n\t\tsets.setColor(value, color);\n\t    } else if (color == 0) {\n\t\tvalid = checkNodes(value, opColor);\n\t    }\n\t} else if (color == 0) {\n\t    valid = checkNodes(value, opColor);\n\t}\n\n\treturn valid;\n    }\n\n    private static void format(StringBuilder builder, int i) {\n\n\tif (i > 0) {\n\t    builder.append(' ');\n\t}\n    }\n\n    private static String printNodes() {\n\n\tString text;\n\n\tStringBuilder builder = new StringBuilder();\n\tIterator<Node<Integer>> iterator = nodes.iterator();\n\tint i = 0;\n\tNode<Integer> node;\n\twhile (iterator.hasNext()) {\n\t    format(builder, i);\n\t    node = iterator.next();\n\t    builder.append(sets.getColor(node));\n\t    i++;\n\t}\n\ttext = builder.toString().trim();\n\n\treturn text;\n    }\n\n    private static boolean checkNodes(int color) {\n\n\tboolean valid = Boolean.TRUE;\n\n\tfor (Node<Integer> value : nodes) {\n\t    if (sets.getColor(value) == -1) {\n\t\tvalid = checkNodes(value, color);\n\t\tif (valid) {\n\t\t    unionAll(value);\n\t\t} else {\n\t\t    break;\n\t\t}\n\t    }\n\t}\n\n\treturn valid;\n    }\n\n    private static void calculate() {\n\n\tint color = 0;\n\tboolean valid = checkNodes(color);\n\tString message = \"NO\";\n\tif (valid) {\n\t    message = \"YES\";\n\t    String array = printNodes();\n\t    System.out.println(message);\n\t    System.out.println(array);\n\t} else {\n\t    System.out.println(message);\n\t}\n    }\n\n    public static void main(String[] args) {\n\n\tScanner scanner = new Scanner(System.in);\n\ttry {\n\t    n = scanner.nextInt();\n\t    a = scanner.nextInt();\n\t    b = scanner.nextInt();\n\t    initNodes(scanner);\n\t    calculate();\n\t} finally {\n\t    scanner.close();\n\t}\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.List;\n\npublic class Main {\n    private static StringTokenizer st;\n    private static BufferedReader br;\n    public static long MOD = 1000000007;\n    public static long tenFive = 100000;\n    public static int INF = 100000;\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 void printArr(int[] 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(Collection<?> x, String space) {\n        if (x.size() == 0) return \"\";\n        StringBuilder sb = new StringBuilder();\n        boolean first = true;\n        for (Object elt : x) {\n            if (first) first = false;\n            else sb.append(space);\n            sb.append(elt);\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<Integer> nextInts(int N) throws IOException {\n        List<Integer> ret = new ArrayList<Integer>();\n        for (int i = 0; i < N; i++) {\n            ret.add(nextInt());\n        }\n        return ret;\n    }\n\n    public static void solve(int a, int b, List<Integer> orig) {\n        boolean swap = false;\n        if (a > b) {\n            swap = true;\n            int tmp = a;\n            a = b;\n            b = tmp;\n        }\n\n        List<Integer> nums = new ArrayList<Integer>(orig);\n        Collections.sort(nums);\n        Collections.reverse(nums);\n\n        Set<Integer> all = new HashSet<Integer>(nums);\n        Set<Integer> done = new HashSet<Integer>();\n        Set<Integer> inB = new HashSet<Integer>();\n        for (int x : nums) {\n            if (done.contains(x)) continue;\n            if (all.contains(a - x) && !done.contains(a - x)) {\n                done.add(x);\n                done.add(a - x);\n                //print(x + \" \" + (a - x));\n            } else if (all.contains(b - x) && !done.contains(b - x)) {\n                done.add(x);\n                done.add(b - x);\n                inB.add(x);\n                inB.add(b - x);\n            } else {\n                print(\"NO\");\n                return;\n            }\n        }\n\n        print(\"YES\");\n        List<Integer> out = new ArrayList<Integer>();\n        for (int x : orig) {\n            if (inB.contains(x) ^ swap) out.add(1);\n            else out.add(0);\n        }\n        print(join(out, \" \"));\n    }\n\n    public static void main(String[] args) throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n\n        int n = nextInt();\n        int a = nextInt();\n        int b = nextInt();\n        List<Integer> nums = nextInts(n);\n        solve(a, b, nums);\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Main2 {\n\n\tstatic List<List<Integer>> getLayers(int[] numbers, int a, int b) {\n\t\tboolean[] used = new boolean[numbers.length];\n\t\tHashSet<Integer> hs = new HashSet<Integer>();\n\t\tfor (int i = 0; i < numbers.length; i++) {\n\t\t\ths.add(numbers[i]);\n\t\t}\n\t\tHashMap<Integer, Integer> numberToIndex = new HashMap<Integer, Integer>();\n\t\tfor (int i = 0; i < numbers.length; i++) {\n\t\t\tnumberToIndex.put(numbers[i], i);\n\t\t}\n\n\t\tList<List<Integer>> ans = new ArrayList<List<Integer>>();\n\t\tfor (int i = 0; i < numbers.length; i++) {\n\t\t\tif (!used[i]) {\n\n\t\t\t\tList<Integer> ansRow = new ArrayList<Integer>();\n\t\t\t\tLinkedList<Integer> current = new LinkedList<Integer>();\n\t\t\t\tcurrent.add(numbers[i]);\n\t\t\t\twhile (!current.isEmpty()) {\n\t\t\t\t\tint c = current.removeFirst();\n\t\t\t\t\tused[numberToIndex.get(c)] = true;\n\n\t\t\t\t\tboolean found = false;\n\n\t\t\t\t\tif (hs.contains(a - c)) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tif (a - c != c)\n\t\t\t\t\t\t\tcurrent.add(a - c);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (hs.contains(b - c)) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tif (b - c != c)\n\t\t\t\t\t\t\tcurrent.add(b - c);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (found || ansRow.size() > 0)\n\t\t\t\t\t\tansRow.add(c);\n\n\t\t\t\t\ths.remove(c);\n\t\t\t\t}\n\n\t\t\t\tans.add(ansRow);\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\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 a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\n\t\tint[] numbers = new int[n];\n\t\tfor (int i = 0; i < numbers.length; i++) {\n\t\t\tnumbers[i] = sc.nextInt();\n\t\t}\n\n\t\tHashSet<Integer> hs = new HashSet<Integer>();\n\t\tfor (int i = 0; i < numbers.length; i++) {\n\t\t\ths.add(numbers[i]);\n\t\t}\n\n\t\tint[] belongs = new int[n];\n\t\tfor (int i = 0; i < belongs.length; i++) {\n\t\t\tbelongs[i] = -1;\n\t\t}\n\n\t\tHashMap<Integer, Integer> numberToIndex = new HashMap<Integer, Integer>();\n\t\tfor (int i = 0; i < numbers.length; i++) {\n\t\t\tnumberToIndex.put(numbers[i], i);\n\t\t}\n\n\t\tboolean possible = true;\n\n\t\tList<List<Integer>> layers = getLayers(numbers, a, b);\n\t\tfor (List<Integer> layer : layers) {\n\n\t\t\tif (layer.size() == 0) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint starting = -1;\n\t\t\tfor (int j = 0; j < layer.size(); j++) {\n\t\t\t\tint cur = layer.get(j);\n\n\t\t\t\tint nei = 0;\n\t\t\t\tif (hs.contains(a - cur)) {\n\t\t\t\t\tnei++;\n\t\t\t\t}\n\n\t\t\t\tif (hs.contains(b - cur)) {\n\t\t\t\t\tnei++;\n\t\t\t\t}\n\n\t\t\t\tif (nei == 1 || (a == b && nei == 2)) {\n\t\t\t\t\tstarting = j;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (starting == -1)\n\t\t\t\tthrow new Error();\n\n\t\t\tint c = layer.get(starting);\n\t\t\tHashSet<Integer> layerset = new HashSet<Integer>(layer);\n\t\t\twhile (true) {\n\n\t\t\t\tif (layerset.contains(c) && layerset.contains(a - c)) {\n\t\t\t\t\tbelongs[numberToIndex.get(c)] = 0;\n\t\t\t\t\tbelongs[numberToIndex.get(a - c)] = 0;\n\t\t\t\t\tlayerset.remove(c);\n\t\t\t\t\tlayerset.remove(a - c);\n\t\t\t\t\tc = b - (a - c);\n\t\t\t\t} else if (layerset.contains(c) && layerset.contains(b - c)) {\n\t\t\t\t\tbelongs[numberToIndex.get(c)] = 1;\n\t\t\t\t\tbelongs[numberToIndex.get(b - c)] = 1;\n\t\t\t\t\tlayerset.remove(c);\n\t\t\t\t\tlayerset.remove(b - c);\n\t\t\t\t\tc = a - (b - c);\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\n\t\tprintResult(belongs);\n\n\t}\n\n\tstatic void printResult(int[] belongs) {\n\n\t\tboolean ok = true;\n\t\tfor (int i = 0; i < belongs.length; i++) {\n\t\t\tif (belongs[i] < 0)\n\t\t\t\tok = false;\n\t\t}\n\n\t\tif (ok) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tStringBuffer sb = new StringBuffer();\n\n\t\t\tfor (int i = 0; i < belongs.length; i++) {\n\t\t\t\tsb.append(belongs[i]);\n\t\t\t\tif (i != belongs.length - 1)\n\t\t\t\t\tsb.append(\" \");\n\t\t\t}\n\n\t\t\tSystem.out.println(sb.toString());\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class B {\n\n    void solve() throws IOException {\n        int n=nextInt();\n        int a=nextInt();\n        int b=nextInt();\n        int[] p=new int[n];\n        for(int i=0;i<n;i++)p[i]=nextInt();\n//        if(n%2==1){\n//            out.println(\"NO\");\n//            return;\n//        }\n        TreeSet<Integer>[] s=new TreeSet[n];\n        for(int i=0;i<n;i++)s[i]=new TreeSet<Integer>();\n        HashMap<Integer,Integer> m=new HashMap<Integer, Integer>();\n        for(int i=0;i<n;i++)\n            m.put(p[i],i);\n        for(int i=0;i<n;i++){\n            if(m.containsKey(a-p[i])){\n                s[i].add(a-p[i]);\n                s[m.get(a-p[i])].add(p[i]);\n            }\n            if(m.containsKey(b-p[i])){\n                s[i].add(b-p[i]);\n                s[m.get(b-p[i])].add(p[i]);\n            }\n        }\n        int last=-1;\n        LinkedList<Integer> q=new LinkedList<Integer>();\n        for(int i=0;i<n;i++){\n            if(s[i].size()==0){\n                out.println(\"NO\");\n                return;\n            }\n            if(s[i].size()==1){\n                q.add(i);\n            }\n        }\n        int[] ans=new int[n];\n        while(last!=n){\n            while(!q.isEmpty()){\n                int cur=q.poll();\n                if(s[cur].size()==0)continue;\n                int x=p[cur];\n                int y=s[cur].first();\n                if(x==a-y){\n                    ans[cur]=1;\n                    ans[m.get(y)]=1;\n                }\n                else{\n                    ans[cur]=2;\n                    ans[m.get(y)]=2;\n                }\n                for(Integer u:s[m.get(y)]){\n                    int o=m.get(u);\n                    if(o!=m.get(y)) {\n                        s[o].remove(y);\n                        if (s[o].size() == 1) q.add(o);\n                    }\n                }\n                for(Integer u:s[cur]){\n                    int o=m.get(u);\n                    if(o!=m.get(y)) {\n                        s[o].remove(y);\n                        if (s[o].size() == 1) q.add(o);\n                    }\n                }\n            }\n            last++;\n            while(last!=n){\n                if(s[last].size()!=0&&ans[last]==0)break;\n                last++;\n            }\n            if(last!=n){\n                q.add(last);\n            }\n        }\n        for(int i=0;i<n;i++)\n            if(ans[i]==0){\n                out.println(\"NO\");\n                return;\n            }\n        out.println(\"YES\");\n        for(int i=0;i<n;i++)\n            out.print((ans[i]-1)+\" \");\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//      reader = new BufferedReader(new FileReader(\"input.txt\"));\n        tokenizer = null;\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n//      out = 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", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "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\n\tMap<Integer, Integer> map;\n\tint []p, rank;\n\n\tpublic void run() throws Exception{\n\t\tin =  new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tmap = new HashMap<Integer, Integer>();\n\n\t\tint n = nextInt();\n\t\tint x = nextInt(), y = nextInt();\n\t\tint []a = new int[n];\n\t\tp = new int[n];\n\t\tfor(int i = 1; i < n; ++i) p[i] = i;\n\t\trank = new int[n];\n\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\ta[i] = nextInt();\n\t\t\tmap.put(a[i], i);\n\t\t}\n\t\tint mask[] = new int[n];\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tif (map.containsKey(x - a[i])) {\n\t\t\t\tunion(map.get(x - a[i]), i);\n\t\t\t\tmask[i] |= 1;\t\n\t\t\t} \n\t\t\tif (map.containsKey(y - a[i])) {\n\t\t\t\tunion(map.get(y - a[i]), i);\n\t\t\t\tmask[i] |= 2;\n\t\t\t} \n\t\t}\n\n\t\tint []b = new int[n];\n\t\tArrays.fill(b, 3);\n\t\tfor(int i = 0; i < n; ++i) b[find(i)] &= mask[i];\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tif (b[i] == 0) {\n\t\t\t\tout.println(\"NO\");\n\t\t\t\tout.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tout.println(\"YES\");\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tout.print((b[find(i)] & 1) == 1 ? 0 : 1);\n\t\t\tif (i != n - 1) out.print(\" \");\n\t\t}\n\t\tout.println();\n\t\tout.close();\n\t}\n\n\tprivate int find(int x) {\n\t\tif (x != p[x])\n\t\t\treturn p[x] = find(p[x]);\n\t\treturn x;\n\t}\n\tprivate void union(int a, int b) {\n\t\ta = find(a);\n\t\tb = find(b);\n\t\tif (rank[a] < rank[b]) {\n\t\t\tint tmp = a;\n\t\t\ta = b;\n\t\t\tb = tmp;\n\t\t}\n\t\tp[b] = a;\n\t\tif (rank[a] == rank[b]) ++rank[a];\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.TreeMap;\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 Hamed Valizadeh (havaliza@gmail.com)\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\nclass TaskB {\n    int n, a, b;\n    Map<Integer, Integer> position;\n    int[] p;\n    int[] group;\n\n    public void solve(int testNumber, FastInputReader in, PrintWriter out) {\n        n = in.nextInt();\n        a = in.nextInt();\n        b = in.nextInt();\n\n        position = new TreeMap<Integer, Integer>();\n        p = new int[n];\n        group = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            p[i] = in.nextInt();\n            group[i] = -1;\n            position.put(p[i], i);\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (getMate(i) != -1)\n                continue;\n            out.println(\"NO\");\n            return;\n        }\n\n        for (int i = 0; i < n; i++) {\n            boolean aMate = position.containsKey(a - p[i]);\n            boolean bMate = position.containsKey(b - p[i]);\n            if (aMate && bMate)\n                continue;\n            if (group[i] != -1)\n                continue;\n            if (!solve(i)) {\n                out.println(\"NO\");\n                return;\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (group[i] != -1)\n                continue;\n            if (!solve(i)) {\n                out.println(\"NO\");\n                return;\n            }\n        }\n\n        out.println(\"YES\");\n        for (int i = 0; i < n; i++) {\n            out.print(group[i]);\n            out.print(\" \");\n        }\n        out.println();\n    }\n\n    private boolean solve(int index) {\n        int mate = getMate(index);\n        if (mate == -1)\n            return false;\n        assign(index, mate);\n        if (getMate(index) != -1)\n            return solve(getMate(index));\n        else\n            return getMate(mate) == -1 || solve(getMate(mate));\n    }\n\n    private void assign(int index, int mate) {\n        int sum = p[index] + p[mate];\n        if (sum == a) {\n            group[index] = group[mate] = 0;\n            return;\n        }\n        if (sum == b) {\n            group[index] = group[mate] = 1;\n            return;\n        }\n        throw new RuntimeException(\"Wrong assignment :(\");\n    }\n\n    private int getMate(int index) {\n        int[] possibleMates = new int[] {a - p[index], b - p[index]};\n        for (int mate: possibleMates) {\n            if (position.containsKey(mate)) {\n                int mateIndex = position.get(mate);\n                if (group[mateIndex] == -1)\n                    return mateIndex;\n            }\n        }\n        return -1;\n    }\n}\n\nclass FastInputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n\n    public FastInputReader(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", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.util.TreeMap;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.util.ArrayDeque;\nimport java.io.PrintWriter;\nimport java.util.Deque;\nimport java.math.BigInteger;\nimport java.util.Queue;\nimport java.util.Collection;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author karan173\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        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n}\n\nclass TaskB\n{\n    int val[];\n    int p[];\n    int aneigh[], bneight[], deg[];\n    Deque<Integer> mycycle;\n    boolean loops = false;\n    public void solve(int testNumber, FastReader in, PrintWriter out)\n    {\n        int n = in.ni ();\n        val = new int[n];\n        int a = in.ni ();\n        int b = in.ni ();\n        Map<Integer, Integer> set = new TreeMap<Integer, Integer> ();\n        p = in.iArr (n);\n        for (int i = 0; i < n; i++)\n        {\n            set.put (p[i], i);\n        }\n        aneigh = new int[n];\n        bneight = new int[n];\n        deg = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            aneigh[i] = val[i] = bneight[i] = -1;\n            deg[i] = 0;\n        }\n        Queue<Integer> queue = new ArrayDeque<Integer> ();\n        for (int i = 0; i < n; i++)\n        {\n            Integer x1 = set.get (a - p[i]);\n            Integer x2 = set.get (b - p[i]);\n            if (x1 != null)\n            {\n                aneigh[i] = x1;\n                deg[i]++;\n            }\n            if (x2 != null && a != b)\n            {\n                bneight[i] = x2;\n                deg[i]++;\n            }\n            if (deg[i] == 1)\n            {\n                queue.add (i);\n            }\n        }\n\n        while (!queue.isEmpty ())\n        {\n            int idx = queue.remove ();\n            if (deg[idx] != 1)\n            {\n                continue;\n            }\n            int aa = aneigh[idx];\n            int bb = bneight[idx];\n            if (aa != -1)\n            {\n                val[idx] = val[aa] = 0;\n                deg[aa]--;\n                deg[idx]--;\n                aneigh[aa] = -1;\n                aneigh[idx] = -1;\n                if (deg[aa] == 1)\n                {\n                    int zz = bneight[aa];\n                    bneight[zz] = -1;\n                    deg[zz]--;\n                    if(deg[zz] == 1)\n                    queue.add (zz);\n                }\n            }\n            else\n            {\n                val[idx] = val[bb] = 1;\n                deg[bb]--;\n                deg[idx]--;\n                bneight[idx] = bneight[bb] = -1;\n                if (deg[bb] == 1)\n                {\n                    //queue.add (bb);\n                    int zz = aneigh[bb];\n                    aneigh[zz] = -1;\n                    deg[zz]--;\n                    if(deg[zz] == 1)\n                        queue.add (zz);\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++)\n        {\n            if (val[i] == -1 && cantBePaired(i))\n            {\n                out.println (\"NO\");\n                return;\n            }\n        }\n\n        //every person has two neighbours\n\n        //cases => either cycles or linear path with loops end points\n        for (int i = 0; i < n; i++)\n        {\n            if (val[i] == -1)\n            {\n                mycycle = new ArrayDeque<Integer> ();\n                loops = false;\n                cycle (i);\n                if (loops || mycycle.size () % 2 == 0)\n                {\n                    doEvenCycle ();\n                    continue;\n                }\n\n                out.println (\"NO\");\n                return;\n            }\n        }\n        out.println (\"YES\");\n        for (int i = 0; i < n; i++)\n        {\n            out.print (val[i] + \" \");\n        }\n        out.println ();\n    }\n\n    private boolean cantBePaired(int i)\n    {\n        int aa = aneigh[i];\n        int bb = bneight[i];\n        if (aa != -1 && val[aa] == -1)\n        {\n            return false;\n        }\n        if (bb != -1 && val[bb] == -1)\n        {\n            return false;\n        }\n        return true;\n    }\n\n\n    private void doEvenCycle()\n    {\n        for (int x : mycycle)\n        {\n            val[x] = 0;\n        }\n    }\n\n    private void cycle(int i)\n    {\n        boolean aa = false;\n        int prev = i;\n        mycycle.addLast (i);\n        System.out.println (i);\n        int j = aneigh[i];\n        while (j != i)\n        {\n            if (j == prev)\n            {\n                loops = true;\n                break;\n            }\n            mycycle.addLast (j);\n            System.out.println (j);\n            prev = j;\n            j = aa ? aneigh[j] : bneight[j];\n//            if (j == -1)\n//            {\n//                System.out.println (prev + \" \" + aneigh[prev] + bneight[prev] + \" \" + deg[prev] + \" \" + val[prev] + \" \" + val[64] + \" \" + deg[64]);\n//            }\n            aa = !aa;\n        }\n\n        if (loops)\n        {\n            j = bneight[i];\n            prev = i;\n            aa = true;\n            while (prev != j)\n            {\n                mycycle.addFirst (j);\n\n                prev = j;\n                j = aa ? aneigh[j] : bneight[j];\n                aa = !aa;\n            }\n        }\n        System.out.println (\"XXX\");\n    }\n}\n\nclass FastReader\n{\n\n    public 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    {\n        this.stream = stream;\n    }\n\n    public FastReader()\n    {\n\n    }\n\n    public int read()\n    {\n        if (numChars == -1)\n        {\n            throw new InputMismatchException ();\n        }\n        if (curChar >= 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            {\n                return -1;\n            }\n        }\n        return buf[curChar++];\n    }\n\n    public int ni()\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            {\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    {\n        if (filter != null)\n        {\n            return filter.isSpaceChar (c);\n        }\n        return isWhitespace (c);\n    }\n\n    public static boolean isWhitespace(int c)\n    {\n        return c==' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int[] iArr(int n)\n    {\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            a[i] = ni ();\n        }\n        return a;\n    }\n\n    public interface SpaceCharFilter\n    {\n        public boolean isSpaceChar(int ch);\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import 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.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Main {\n\tint work(int x){\n\t\tif(x%2==0)return x+1;\n\t\telse return x-1;\n\t}\n\tstatic int N = 200050;\n\tclass Node implements Comparable <Node>{\n\t\tint x, id;\n\t\tNode(int x, int id){\n\t\t\tthis.x = x; this.id = id;\n\t\t}\n\t\tpublic int compareTo(Node o){\n\t\t\treturn Integer.compare(x, o.x);\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn id + \"=\" + x;\n\t\t}\n\t}\n\tclass Edge{\n\t\tint from, to, nex;\n\t\tEdge (int from, int to, int nex){\n\t\t\tthis.from = from;\n\t\t\tthis.to = to;\n\t\t\tthis.nex = nex;\n\t\t}\n\t}\n\tEdge[] edge = new Edge[N*10];\n\tint[] head = new int[N];\n\tint edgenum;  \n\tvoid addedge(int u, int v){  \n\t    Edge E = new Edge(u, v, head[u]);  \n\t    edge[edgenum] = E;  \n\t    head[u] = edgenum ++;  \n\t}  \n\t\n\tint n;\n\tint[] p = new int[N], ans = new int[N];\n\tint a, b, max;\n    Map<Integer, Integer> map = new HashMap();\n    boolean match(int x, int y, int col){\n    \tint P = map.get(x);\n    \tif(map.containsKey(y-x) == false)\n    \t\treturn false;\n    \tint Q = map.get(y - x);\n    \tif(ans[Q] == -1 || x * 2 == y){\n    \t\tans[Q] = ans[P] = col;\n    \t}\n    \telse {\n    \t\tif(match(a+b-2*y+x, y, col))\n    \t\t\tans[Q] = ans[P] = col; \t\t\n    \t\telse return false;\n    \t}\n    \treturn true;\n    }\n    boolean solve(){\n    \tif(max >= a && max >= b)return false;\n    \tfor(int i = 1; i <= n; i++)\n    \t\tif(ans[i] == -1)\n    \t\t{\n    \t\t\tif(match(p[i], a, 0)==false && match(p[i], b, 1) == false)\n    \t\t\t\treturn false;\n    \t\t}    \t\n    \treturn true;\n    }\n\tvoid init(){\n\t\tn = cin.nextInt();\n\t\ta = cin.nextInt(); b = cin.nextInt();\n\t\tmax = 0;\n\t\tfor(int i = 1; i <= n; i++){\n\t\t\tans[i] = -1;\n\t\t\tp[i] = cin.nextInt();\n\t\t\tmap.put(p[i], i);\n\t\t\tif(p[i] > max) max = p[i];\n\t\t}\n\t}\n\tpublic void work(){\n\t\tinit();\n\t\tif(solve()){\n\t\t\tout.println(\"YES\");\n\t\t\tfor(int i = 1; i <= n; i++)out.print(ans[i]+\" \"); out.println();\n\t\t}\n\t\telse \n\t\t\tout.println(\"NO\");\n\t}\n\tMain() {\n        cin = new Scanner(System.in);  \n        out = new PrintWriter(System.out);\n    }  \n    public static void main(String[] args) {\n        Main e = new Main();  \n        e.work();\n        out.close();\n    }\n    public Scanner cin;\n    public static PrintWriter out;\n}\n\t\t  \t \t\t   \t \t    \t \t\t  \t   \t\t", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\n\n\tstatic int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tstatic long nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tstatic double nextDouble() throws NumberFormatException, 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\twriter = new PrintWriter(System.out);\n\t\tpineapple();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\n\tstatic void pineapple() throws NumberFormatException, IOException {\n\t\tint n = nextInt();\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tTreeSet<Integer> al = new TreeSet<Integer>();\n\t\tTreeMap<Integer, Integer> mp = new TreeMap<Integer, Integer>();\n\t\tint[] ans = new int[n];\n\t\tArrays.fill(ans, -1);\n\t\tTreeSet<Integer> used = new TreeSet<Integer>();\n\t\tint[] mas = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint t = nextInt();\n\t\t\tal.add(t);\n\t\t\tmas[i] = t;\n\t\t\tmp.put(t, i);\n\t\t}\n\n\t\tfor (int st : al) {\n\t\t\tif (used.contains(st))\n\t\t\t\tcontinue;\n\n\t\t\t{\n\t\t\t\tint pr = st;\n\t\t\t\tint cc = -1;\n\t\t\t\tTreeSet<Integer> u2 = new TreeSet<Integer>();\n\t\t\t\tu2.add(pr);\n\t\t\t\tif (al.contains(a - pr) && !u2.contains(a - pr))\n\t\t\t\t\tcc = a - pr;\n\t\t\t\telse if (al.contains(b - pr) && !u2.contains(a - pr))\n\t\t\t\t\tcc = b - pr;\n\t\t\t\tif (cc != -1) {\n\t\t\t\t\tu2.add(cc);\n\t\t\t\t\tboolean bGo = true;\n\t\t\t\t\twhile (bGo) {\n\t\t\t\t\t\tbGo = false;\n\t\t\t\t\t\tint nxt = -1;\n\t\t\t\t\t\tif (al.contains(a - cc) && !u2.contains(a - cc))\n\t\t\t\t\t\t\tnxt = a - cc;\n\t\t\t\t\t\telse if (al.contains(b - cc) && !u2.contains(b - cc))\n\t\t\t\t\t\t\tnxt = b - cc;\n\t\t\t\t\t\tif (nxt != -1) {\n\t\t\t\t\t\t\tbGo = true;\n\t\t\t\t\t\t\tu2.add(nxt);\n\t\t\t\t\t\t\tcc = nxt;\n\t\t\t\t\t\t\tpr = cc;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tst = cc;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint x = st;\n\t\t\twhile (x != -1) {\n\t\t\t\tint curr = x;\n\t\t\t\tused.add(curr);\n\t\t\t\tx = -1;\n\t\t\t\tint next1 = a - curr;\n\t\t\t\tif (al.contains(next1)) {\n\t\t\t\t\tif (!used.contains(next1)) {\n\t\t\t\t\t\tx = next1;\n\t\t\t\t\t\tint ci = mp.get(curr);\n\t\t\t\t\t\tint ni = mp.get(next1);\n\t\t\t\t\t\tif (ans[ci] == -1 && ans[ni] == -1) {\n\t\t\t\t\t\t\tans[ni] = 0;\n\t\t\t\t\t\t\tans[ci] = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint next2 = b - curr;\n\t\t\t\tif (al.contains(next2)) {\n\t\t\t\t\tif (!used.contains(next2)) {\n\t\t\t\t\t\tx = next2;\n\t\t\t\t\t\tint ci = mp.get(curr);\n\t\t\t\t\t\tint ni = mp.get(next2);\n\t\t\t\t\t\tif (ans[ci] == -1 && ans[ni] == -1) {\n\t\t\t\t\t\t\tans[ni] = 1;\n\t\t\t\t\t\t\tans[ci] = 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\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (ans[i] == -1) {\n\t\t\t\tif (2 * mas[i] == a) {\n\t\t\t\t\tans[i] = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (2 * mas[i] == b) {\n\t\t\t\t\tans[i] = 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\twriter.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\twriter.println(\"YES\");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\twriter.print(ans[i] + \" \");\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\n\npublic class A{\n\n    public static void main(String args[]){\n        FastScanner in = new FastScanner(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        boolean change = false;\n        if(a > b){\n            int t = a;\n            a = b;\n            b = t;\n            change = true;\n        }\n        boolean[] inb = new boolean[n];\n        int[] numbers = new int[n];\n        TreeMap<Integer, Integer> num = new TreeMap<Integer, Integer>();\n        for(int i = 0; i < n; i++){\n            num.put(in.nextInt(), i);\n        }\n        boolean hasAns = true;\n        while(!num.isEmpty()){\n            Entry<Integer, Integer> last = num.lastEntry();\n            int key = last.getKey();\n            if(num.containsKey(a - key)){\n                num.remove(key);\n                num.remove(a - key);\n            } else if(num.containsKey(b - key)){\n                inb[num.get(key)] = true;\n                inb[num.get(b - key)] = true;\n                num.remove(key);\n                num.remove(b - key);\n            } else{\n                hasAns = false;\n                break;\n            }\n        }\n        if(hasAns){\n            out.println(\"YES\");\n            for(int i = 0; i < n && !change; i++){\n                if(inb[i]){\n                    out.print(\"1\");\n                } else{\n                    out.print(\"0\");\n                }\n                if(i != n - 1){\n                    out.print(\" \");\n                }\n            }\n            for(int i = 0; i < n && change; i++){\n                if(inb[i]){\n                    out.print(\"0\");\n                } else{\n                    out.print(\"1\");\n                }\n                if(i != n - 1){\n                    out.print(\" \");\n                }\n            }\n        } else{\n            out.println(\"NO\");\n        }\n        out.close();\n    }\n\n    static class FastScanner{\n        private BufferedReader reader;\n\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            try{\n                return reader.readLine();\n            } catch(IOException e){\n                e.printStackTrace();\n                return null;\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        public long nextLong(){\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble(){\n            return Double.parseDouble(next());\n        }\n    }\n}\n", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import 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.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Main {\n\tint work(int x){\n\t\tif(x%2==0)return x+1;\n\t\telse return x-1;\n\t}\n\tstatic int N = 200050;\n\tclass Node implements Comparable <Node>{\n\t\tint x, id;\n\t\tNode(int x, int id){\n\t\t\tthis.x = x; this.id = id;\n\t\t}\n\t\tpublic int compareTo(Node o){\n\t\t\treturn Integer.compare(x, o.x);\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn id + \"=\" + x;\n\t\t}\n\t}\n\tclass Edge{\n\t\tint from, to, nex;\n\t\tEdge (int from, int to, int nex){\n\t\t\tthis.from = from;\n\t\t\tthis.to = to;\n\t\t\tthis.nex = nex;\n\t\t}\n\t}\n\tEdge[] edge = new Edge[N*10];\n\tint[] head = new int[N];\n\tint edgenum;  \n\tvoid addedge(int u, int v){  \n\t    Edge E = new Edge(u, v, head[u]);  \n\t    edge[edgenum] = E;  \n\t    head[u] = edgenum ++;  \n\t}  \n\t\n\tint n;\n\tint[] p = new int[N], ans = new int[N];\n\tint a, b, max;\n    Map<Integer, Integer> map = new HashMap();\n    boolean match(int x, int y, int col){\n    \tint P = map.get(x);\n    \tif(map.containsKey(y-x) == false)\n    \t\treturn false;\n    \tint Q = map.get(y - x);\n    \tif(ans[Q] == -1 || x * 2 == y){\n    \t\tans[Q] = ans[P] = col;\n    \t}\n    \telse {\n    \t\tif(match(a+b-2*y+x, y, col))\n    \t\t\tans[Q] = ans[P] = col; \t\t\n    \t\telse return false;\n    \t}\n    \treturn true;\n    }\n    boolean solve(){\n    \tif(max >= a && max >= b)return false;\n    \tfor(int i = 1; i <= n; i++)\n    \t\tif(ans[i] == -1)\n    \t\t{\n    \t\t\tif(match(p[i], a, 0)==false && match(p[i], b, 1) == false)\n    \t\t\t\treturn false;\n    \t\t}    \t\n    \treturn true;\n    }\n\tvoid init(){\n\t\tn = cin.nextInt();\n\t\ta = cin.nextInt(); b = cin.nextInt();\n\t\tmax = 0;\n\t\tfor(int i = 1; i <= n; i++){\n\t\t\tans[i] = -1;\n\t\t\tp[i] = cin.nextInt();\n\t\t\tmap.put(p[i], i);\n\t\t\tif(p[i] > max) max = p[i];\n\t\t}\n\t}\n\tpublic void work(){\n\t\tinit();\n\t\tif(solve()){\n\t\t\tout.println(\"YES\");\n\t\t\tfor(int i = 1; i <= n; i++)out.print(ans[i]+\" \"); out.println();\n\t\t}\n\t\telse \n\t\t\tout.println(\"NO\");\n\t}\n\tMain() {\n        cin = new Scanner(System.in);  \n        out = new PrintWriter(System.out);\n    }  \n    public static void main(String[] args) {\n        Main e = new Main();  \n        e.work();\n        out.close();\n    }\n    public Scanner cin;\n    public static PrintWriter out;\n}\n/*\nhttp://blog.csdn.net/keshuai19940722/article/details/39528801\n\n*/", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport static java.lang.Integer.*;\n\npublic class BDiv1 {\nstatic int n; \nstatic int a;\nstatic int b;\nstatic HashMap<Integer,Integer> graphA=new HashMap<>();\nstatic HashMap<Integer,Integer> graphB=new HashMap<>();\nstatic int [] array;\nstatic int [] original;\nstatic boolean x=true;\n\n    public static void main(String[] args) throws Exception{\n        BufferedReader buf =new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st =new StringTokenizer(buf.readLine());\n        n=parseInt(st.nextToken());\n        a=parseInt(st.nextToken());\n        b=parseInt(st.nextToken());\n        st =new StringTokenizer(buf.readLine());\n        array=new int[n];\n        original=new int [n];\n        for (int i=0;i<n;i++){\n            array[i]=parseInt(st.nextToken());\n            original[i]=array[i];\n        }\n        Arrays.sort(array);\nfor (int i=0;i<n;i++){\n    int k= Arrays.binarySearch(array,a-array[i]);\n    if (k>=0){\n        graphA.put(array[i],array[k]);\n        graphA.put(array[k],array[i]);\n    }\n}\nfor (int i=0;i<n;i++){\n    int k= Arrays.binarySearch(array,b-array[i]);\n    if (k>=0){\n        graphB.put(array[i],array[k]);\n        graphB.put(array[k],array[i]);\n    }\n    }\n\n\nfor (int i=0;i<n;i++){\n    Integer j=graphA.get(array[i]);\n    if (j!=null){\n        if (graphB.containsKey(array[i]) && graphB.containsKey(j)){\n            graphA.remove(array[i]);\n            graphA.remove(j);\n        }\n        else if (graphB.containsKey(array[i]) && !graphB.containsKey(j)){\n            \n            graphB.remove(graphB.get(array[i]));\n            graphB.remove(array[i]);\n        }\n        else if (!graphB.containsKey(array[i]) && graphB.containsKey(j)){\n            graphB.remove(graphB.get(j));\n            graphB.remove(j);\n        }\n        \n    }\n    \n}\n\nint [] res=new int [n];\nfor (int i=0;i<n;i++){\n    if (graphA.containsKey(original[i]))res[i]=0;\n    else if (graphB.containsKey(original[i])) res[i]=1;\n    else {\n        System.out.println(\"NO\");\n        return;\n    }\n}\nSystem.out.println(\"YES\");\nfor (int k:res)System.out.print(k+\" \");\n}\n\n    }", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "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,ints\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    st = new StringTokenizer(f.readLine());\n    HashMap<Integer,Integer> in = new HashMap<Integer,Integer>();\n    int[][] locs = new int[n][2];\n    for (int i=0;i<n;i++) {\n      int num = Integer.parseInt(st.nextToken());\n      locs[i] = new int[]{num,i};\n      in.put(num,i);\n    }\n    \n    // use greedy\n    boolean ok = true;\n    int swap = 0;\n    if (a>b) {swap = 1;\n      int t = a;\n      a = b;\n      b = t;\n    }\n    Arrays.sort(locs,new Comparator<int[]>() {\n      public int compare(int[] a, int[] b) {\n        return (new Integer(a[0])).compareTo(b[0]);\n      }\n    });\n    int[] inB = new int[n];\n    for (int[] i: locs) {\n      if (in.containsKey(b-i[0])) {\n        inB[i[1]] = 1-swap;\n        in.remove(b-i[0]);\n      } else if (in.containsKey(a-i[0])) {\n        inB[i[1]] = swap;\n        in.remove(a-i[0]);\n      } else ok = false;\n    }\n\n    // write to out\n    StringBuffer p = new StringBuffer();\n    for (int i=0;i<n-1;i++) {\n      p.append(inB[i]);\n      p.append(\" \");\n    }\n    p.append(inB[n-1]);\n    if (ok) {\n      out.println(\"YES\");\n      out.println(p.toString());\n    } else {\n      out.println(\"NO\");\n    }\n    \n    // cleanup\n    out.close();\n    System.exit(0);\n  }\n}", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.util.TreeMap;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    ArrayList<Integer>[] G;\n    int[] st, dr;\n    boolean[] v;\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int N = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] A = new int[N];\n        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();\n        for (int i = 0; i < N; i++) {\n            A[i] = in.nextInt();\n            map.put(A[i], i);\n        }\n        G = new ArrayList[N];\n        for (int i = 0; i < N; i++) {\n            G[i] = new ArrayList<Integer>();\n        }\n\n        for (int i = 0; i < N; i++) {\n            int val = a - A[i];\n            if (map.containsKey(val)) {\n                int p = map.get(val);\n//                if (p != i) {\n                    G[i].add(p);\n                    G[p].add(i);\n//                }\n            }\n            val = b - A[i];\n            if (map.containsKey(val)) {\n                int p = map.get(val);\n//                if (p != i) {\n                    G[i].add(p);\n                    G[p].add(i);\n//                }\n            }\n        }\n\n        st = new int[N];\n        dr = new int[N];\n        Arrays.fill(st, -1);\n        Arrays.fill(dr, -1);\n        v = new boolean[N];\n\n        boolean ok = true;\n        int match = 0;\n        while (ok) {\n            ok = false;\n            Arrays.fill(v, false);\n            for (int i = 0; i < N; i++) {\n                if (dr[i] == -1) {\n                    if (pairup(i)) {\n                        ok = true;\n                        match++;\n                    }\n                }\n            }\n        }\n\n        if (match == N) {\n            out.println(\"YES\");\n            for (int i = 0; i < N; i++) {\n                if (i > 0) {\n                    out.print(\" \");\n                }\n                int other = dr[i];\n                if (A[i] == b - A[other]) {\n                    out.print(1);\n                }\n                else {\n                    out.print(0);\n                }\n            }\n        }\n        else {\n            out.println(\"NO\");\n        }\n    }\n\n    private boolean pairup(int node) {\n        if (v[node]) {\n            return false;\n        }\n        v[node] = true;\n        for (int x : G[node]) {\n            if (st[x] == -1) {\n                st[x] = node;\n                dr[node] = x;\n                return true;\n            }\n        }\n        for (int x : G[node]) {\n            if (pairup(st[x])) {\n                st[x] = node;\n                dr[node] = x;\n                return true;\n            }\n        }\n        return false;\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", "complexity": "linear", "problem": "468_B. Two Sets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\npublic class D909 {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        char[] line = br.readLine().toCharArray();\n        int n = line.length;\n\n        int l = 0;\n        ArrayList<Node> groups = new ArrayList<>();\n        Node node = new Node(line[0], 1);\n        groups.add(node);\n        for (int i = 1; i < n; i++) {\n            if (line[i] == groups.get(l).letter) {\n                groups.get(l).count++;\n            } else {\n                node = new Node(line[i], 1);\n                groups.add(node);\n                l++;\n            }\n        }\n\n        int moves = 0;\n        ArrayList<Node> temp = new ArrayList<>();\n        while (groups.size() > 1) {\n            moves++;\n\n            l = groups.size();\n            groups.get(0).count--;\n            groups.get(l - 1).count--;\n            for (int i = 1; i < l - 1; i++) {\n                groups.get(i).count -= 2;\n            }\n\n            int p;\n            for (p = 0; p < l; p++) {\n                if (groups.get(p).count > 0) {\n                    temp.add(groups.get(p));\n                    break;\n                }\n            }\n            int lTemp = temp.size();\n            for (p++; p < l; p++) {\n                if (groups.get(p).count <= 0) {\n                    continue;\n                }\n                if (groups.get(p).letter == temp.get(lTemp - 1).letter) {\n                    temp.get(lTemp - 1).count += groups.get(p).count;\n                } else {\n                    temp.add(groups.get(p));\n                    lTemp++;\n                }\n            }\n\n            groups.clear();\n            groups.addAll(temp);\n            temp.clear();\n        }\n\n        System.out.println(moves);\n    }\n\n    private static class Node {\n        char letter;\n        int count;\n\n        Node(char letter, int count) {\n            this.letter = letter;\n            this.count = count;\n        }\n    }\n}\n", "complexity": "linear", "problem": "909_D. Colorful Points", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.stream.Collectors;\n\npublic class PlayingPiano {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\t int n = scanner.nextInt();\n\t\t \n\t\t List<Integer> as = new LinkedList<>();\n\t\t int[] as2 = new int[n];\n\t\t \n\t\t for (int i = 0; i < n; i++) {\n\t\t\t int a = scanner.nextInt();\n\t\t\t as.add(a);\n\t\t\t as2[i] = a;\n\t\t }\n\t\t \n\t\t //System.out.println(solve(as));\n\t\t System.out.println(solve2(as2));\n\t\t\n\t\tscanner.close();\n\t}\n\n\tpublic static String solve(List<Integer> as) {\n\t\tList<Integer> fingers = new LinkedList<>();\n\t\t fingers.add(1);\n\t\t fingers.add(2);\n\t\t fingers.add(3);\n\t\t fingers.add(4);\n\t\t fingers.add(5);\n\t\t \n\t\t List<Integer> solution = assign(as, fingers, fingers);\n\t\t if (solution == null) {\n\t\t\t return \"-1\";\n\t\t } else {\n\t\t\t StringBuilder sb = new StringBuilder();\n\t\t\t for (int b : solution) {\n\t\t\t\t sb.append(b);\n\t\t\t\t sb.append(\" \");\n\t\t\t }\n\t\t\t sb.deleteCharAt(sb.length() - 1);\n\t\t\t return sb.toString();\n\t\t }\n\t}\n\n\tprivate static List<Integer> assign(List<Integer> as, List<Integer> fingers, List<Integer> allFingers) {\n\t\t// if fingers is empty return null\n\t\tif (fingers.isEmpty()) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t// if as size is one then return first element in fingers\n\t\tif (as.size() == 1) {\n\t\t\tList<Integer> ret = new LinkedList<>();\n\t\t\tret.add(fingers.get(0));\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\t// get sublist\n\t\tList<Integer> subList = as.subList(1, as.size());\n\t\t\n\t\tfor (int i = 0; i < fingers.size(); i++) {\n\t\t\t// recursively call with sublist and limited list of fingers\n\t\t\tList<Integer> subFingers = new LinkedList<>();\n\t\t\tfinal int j = i;\n\t\t\tif (as.get(0) < as.get(1)) {\n\t\t\t\t subFingers = allFingers.stream()\n\t\t\t\t\t    .filter(p -> p > fingers.get(j)).collect(Collectors.toList());\n\t\t\t} else if (as.get(0) > as.get(1)) {\n\t\t\t\tsubFingers = allFingers.stream()\n\t\t\t\t\t    .filter(p -> p < fingers.get(j)).collect(Collectors.toList());\n\t\t\t} else {\n\t\t\t\tsubFingers = allFingers.stream()\n\t\t\t\t\t    .filter(p -> p != fingers.get(j)).collect(Collectors.toList());\n\t\t\t}\n\t\t\t\n\t\t\tList<Integer> ret = assign(subList, subFingers, allFingers);\n\t\t\tif (ret != null) {\n\t\t\t\tList<Integer> solution = new LinkedList<>();\n\t\t\t\tsolution.add(fingers.get(i));\n\t\t\t\tsolution.addAll(ret);\n\t\t\t\treturn solution;\n\t\t\t}\n\t\t\t\n\t\t\t// if return is null, then return null, else return an array\n\t\t}\n\t\treturn null;\n\t\t\n\t}\n\t\n\tpublic static String solve2(int[] as) {\n\t\tint[] ret = new int[as.length];\n\t\t\n\t\tif (as.length == 1) return \"1\";\n\t\t\n\t\tif (as[0] < as[1]) ret[0] = 1;\n\t\telse if (as[0] == as[1])\tret[0] = 3;\n\t\telse ret[0] = 5;\n\t\t\n\t\tfor (int i = 1; i < as.length - 1; i++) {\n\t\t\tif (as[i-1] < as[i] && ret[i-1] == 5) return \"-1\";\n\t\t\tif (as[i-1] > as[i] && ret[i-1] == 1) return \"-1\";\n\t\t\t\n\t\t\tif (as[i-1] < as[i] && as[i] < as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] + 1;\n\t\t\t} else if (as[i-1] == as[i] && as[i] < as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 1 ? 2 : 1;\n\t\t\t} else if (as[i-1] > as[i] && as[i] < as[i+1]) {\n\t\t\t\tret[i] = 1;\n\t\t\t} else if (as[i-1] < as[i] && as[i] == as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] + 1;\n\t\t\t} else if (as[i-1] == as[i] && as[i] == as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 4 ? 2 : 4;\n\t\t\t} else if (as[i-1] > as[i] && as[i] == as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 2 ? 1 : 2;\n\t\t\t} else if (as[i-1] < as[i] && as[i] > as[i+1]) {\n\t\t\t\tret[i] = 5;\n\t\t\t} else if (as[i-1] == as[i] && as[i] > as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] == 5 ? 4 : 5;\n\t\t\t} else if (as[i-1] > as[i] && as[i] > as[i+1]) {\n\t\t\t\tret[i] = ret[i-1] - 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (as.length > 1) {\n\t\t\tif (as[as.length - 1] > as[as.length - 2]) {\n\t\t\t\tif (ret[as.length - 2] == 5)\n\t\t\t\t\treturn \"-1\";\n\t\t\t\tret[as.length - 1] = 5;\n\t\t\t} else if (as[as.length - 1] == as[as.length - 2]) {\n\t\t\t\tret[as.length - 1] = ret[as.length - 2] == 5 ? 4 : 5;\n\t\t\t} else {\n\t\t\t\tif (ret[as.length - 2] == 1)\n\t\t\t\t\treturn \"-1\";\n\t\t\t\tret[as.length - 1] = 1;\n\t\t\t} \n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\t for (int b : ret) {\n\t\t\t sb.append(b);\n\t\t\t sb.append(\" \");\n\t\t }\n\t\t sb.deleteCharAt(sb.length() - 1);\n\t\t return sb.toString();\n\t}\n\n}\n", "complexity": "linear", "problem": "1032_C. Playing Piano", "from": "CODEFORCES"}
{"src": "import java.util.*;\n \npublic class Main{\n    private static final int MAX_SIZE = 100005;\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        if(((m + 1) / 60 < a) || ((m + 1) / 60 == a && (m + 1) % 60 <= b)) {\n            out(0, 0);\n            System.exit(0);\n        }\n        for(int i = 2; i <= n; i++) {\n            int x = sc.nextInt();\n            int y = sc.nextInt();\n\n            int bb = b + 2 * m + 2;\n            int aa = a + bb / 60;\n            bb %= 60;\n\n            if((aa < x) || (aa == x && bb <= y)) {\n                b = b + m + 1;\n                a = a + b / 60;\n                b %= 60;\n                out(a, b);\n                System.exit(0);\n            }\n            a = x;\n            b = y;\n        }\n        b = b + m + 1;\n        a = a + b / 60;\n        b = b % 60;        \n        out(a, b);\n    }\n\n    private static void out(int a, int b) {\n        cout(a);\n        cout(\" \");\n        cout(b);\n    }\n\n    private static void cout(Object a) {\n        System.out.print(a);\n    }\n}", "complexity": "linear", "problem": "967_A. Mind the Gap", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class AnnoyingPresent {\n\n\t\n\t//UPSOLVED\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n        long n = Long.parseLong(st.nextToken()) , m = Long.parseLong(st.nextToken());\n        \n        long sum = 0;\n        \n        for(int i=0;i<m;i++){\n        \tStringTokenizer st1 = new StringTokenizer(br.readLine());\n            sum+= n* Long.parseLong(st1.nextToken());\n            Long a= Long.parseLong(st1.nextToken());\n            if(a < 0){\n                if(n % 2 == 0)\n                    sum += n*n / 4*a;\n                else{\n                    sum += (n/2) * (n/2+1) * a;\n                }\n            }\n            else\n                sum += (a*(n) * (n-1) / 2);\n            \n        }\n        System.out.println((double)sum/n);\n\t}\n\n}\n", "complexity": "linear", "problem": "1009_C. Annoying Present", "from": "CODEFORCES"}
{"src": "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 SequenceTransformation {\n    void solve() {\n        int p = 1, n = in.nextInt();\n        while (n > 0) {\n            if (n == 1) {\n                out.print(p + \" \");\n                break;\n            }\n            if (n == 2) {\n                out.print(p + \" \");\n                out.print(2 * p + \" \");\n                break;\n            }\n            if (n == 3) {\n                out.print(p + \" \");\n                out.print(p + \" \");\n                out.print(3 * p + \" \");\n                break;\n            }\n            for (int i = 0; i < (n + 1) / 2; i++) {\n                out.print(p + \" \");\n            }\n            p *= 2;\n            n /= 2;\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 SequenceTransformation().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", "complexity": "linear", "problem": "1059_C. Sequence Transformation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    private static void solve(InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n\n        List<List<Integer>> g = new ArrayList<>(n + 1);\n        for (int i = 0; i < n + 1; i++) {\n            g.add(new LinkedList<>());\n        }\n\n        int degree1 = 0, degree2 = 0, root = 0;\n        for (int i = 0; i < n - 1; i++) {\n            int a = in.nextInt();\n            int b = in.nextInt();\n\n            g.get(a).add(b);\n            g.get(b).add(a);\n\n            if (g.get(a).size() > degree1) {\n\n                if (a == root) {\n                    degree1 = g.get(a).size();\n                } else {\n                    degree2 = degree1;\n                    degree1 = g.get(a).size();\n                    root = a;\n                }\n\n            } else if (g.get(a).size() > degree2) {\n                degree2 = g.get(a).size();\n            }\n\n            if (g.get(b).size() > degree1) {\n\n                if (b == root) {\n                    degree1 = g.get(b).size();\n                } else {\n                    degree2 = degree1;\n                    degree1 = g.get(b).size();\n                    root = b;\n                }\n\n            } else if (g.get(b).size() > degree2) {\n                degree2 = g.get(b).size();\n            }\n        }\n\n        if (degree2 > 2) {\n            out.print(\"No\");\n        } else {\n            out.println(\"Yes\");\n\n            List<Integer> leaves = new LinkedList<>();\n            for (int i = 1; i <= n; i++) {\n                if (i != root) {\n                    if (g.get(i).size() == 1) {\n                        leaves.add(i);\n                    }\n                }\n            }\n\n            out.println(leaves.size());\n            for (int i : leaves) {\n                out.println(root + \" \" + i);\n            }\n        }\n    }\n\n    private static void shuffleArray(int[] array) {\n        int index;\n        Random random = new Random();\n        for (int i = array.length - 1; i > 0; i--) {\n            index = random.nextInt(i + 1);\n            if (index != i) {\n                array[index] ^= array[i];\n                array[i] ^= array[index];\n                array[index] ^= array[i];\n            }\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    private static class InputReader {\n        private BufferedReader br;\n        private 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        byte nextByte() {\n            return Byte.parseByte(next());\n        }\n\n        short nextShort() {\n            return Short.parseShort(next());\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    private 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", "complexity": "linear", "problem": "981_C. Useful Decomposition", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\nimport java.util.Scanner;\n\npublic class A1 {\n\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n\n        long size = scan.nextLong();\n        int numberOfSpecial = scan.nextInt();\n        long pageSize = scan.nextLong();\n\n        long[] specialItemsArray = new long[numberOfSpecial];\n        for (int i = 0; i < numberOfSpecial; i++) {\n            specialItemsArray[i] = scan.nextLong();\n        }\n\n        int totalRemoved = 0;\n        int step = 0;\n\n        long currentPageIndex = BigDecimal.valueOf(specialItemsArray[0]).divide(BigDecimal.valueOf(pageSize),2, RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();\n        int specialItemArrayIndex = 1;\n\n        while (specialItemArrayIndex < numberOfSpecial) {\n            long pageIndex = BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();\n            if (currentPageIndex != pageIndex) {\n                step++;\n                totalRemoved = specialItemArrayIndex;\n                currentPageIndex =  BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();\n            }\n            specialItemArrayIndex++;\n        }\n\n\n        System.out.println(step + 1);\n\n    }\n\n}\n", "complexity": "linear", "problem": "1190_A. Tokitsukaze and Discard Items", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n    \n    public static long page(long p,long k){\n        \n        return (p-1)/k;\n        \n    }\n    \n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        \n        long n = sc.nextLong();\n        int m = sc.nextInt();\n        long k = sc.nextLong();\n        long[] p = new long[m];\n        long del = 0;\n        long nb = 1;\n        int op = 0;\n        for(int i=0;i<m;i++) p[i] = sc.nextLong();\n        for(int i=1;i<m;i++){\n            if(page(p[i]-del,k)!=page(p[i-1]-del,k)){\n                \n                del += nb;\n                nb = 1;\n                op++;\n                \n            }else{\n                nb++;\n                \n            }\n        }\n        if(nb!=0) op++;\n        \n        System.out.println(op);\n        \n    }\n    \n}", "complexity": "linear", "problem": "1191_C. Tokitsukaze and Discard Items", "from": "CODEFORCES"}
{"src": "/**\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    static int n,k,left[],right[],arr[];\n    static long MOD = 1000000007,count[],dp[];\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        n = ni();\n        k = ni();\n        int stack[] = new int[1000001];\n        int top = -1;\n        arr = new int[n];\n        left = new int[n];\n        right = new int[n];\n        for(int i=0;i<n;++i) {\n            arr[i] = ni();\n            while(top>=0 && arr[stack[top]]<=arr[i])\n                top--;\n            if(top==-1)\n                left[i] = 0;\n            else left[i] = stack[top]+1;\n            stack[++top] = i;\n        }\n        top = -1;\n        for(int i=n-1;i>=0;--i) {\n            while(top>=0 && arr[stack[top]]<arr[i])\n                top--;\n            if(top==-1)\n                right[i] = n-1;\n            else right[i] = stack[top]-1;\n            stack[++top] = i;\n        }\n        //pa(\"left\", left);\n        //pa(\"right\", right);\n        dp = new long[n+1];\n        for(int i=0;i<=n;++i) {\n            if(i<k)\n              continue;\n            dp[i] = dp[i-k+1] + (i-k+1);\n        }\n        count = new long[n];\n        long ans = 0;\n        for(int i=0;i<n;++i) {\n            int len = right[i]-left[i]+1;\n            int lef = i-left[i];\n            int rig = right[i]-i;\n            long count = dp[len] - dp[lef] - dp[rig];\n            if(count>=MOD)\n              count%=MOD;\n            ans += count*arr[i];\n            if(ans>=MOD)\n                ans%=MOD;\n        }\n        pl(ans);\n        pw.flush();\n        pw.close();\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class Reader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        public Reader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public Reader(String file_name) throws IOException {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[64];\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}", "complexity": "linear", "problem": "1037_F. Maximum Reduction", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _1036_B_DiagonalWalkingV2 {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint Q = readInt();\n\t\twhile(Q-- > 0) {\n\t\t\tlong n = readLong(), m = readLong(), k = readLong();\n\t\t\tif(Math.max(n, m) > k) println(-1);\n\t\t\telse {\n\t\t\t\tlong ans = k;\n\t\t\t\tif(n%2 != k%2) ans--;\n\t\t\t\tif(m%2 != k%2) ans--;\n\t\t\t\tprintln(ans);\n\t\t\t}\n\t\t}\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", "complexity": "linear", "problem": "1036_B. Diagonal Walking v.2", "from": "CODEFORCES"}
{"src": "//package com.krakn.CF.D1159;\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        int n, k;\n        n = sc.nextInt();\n        k = sc.nextInt();\n\n        int a = (n - k) / 2;\n\n        StringBuilder s = new StringBuilder();\n\n        int i;\n        while (s.length() < n) {\n            i = 0;\n            while (i < a && s.length() < n) {\n                s.append(\"0\");\n                i++;\n            }\n            if (s.length() < n) s.append(\"1\");\n        }\n\n        System.out.println(s);\n    }\n}\n", "complexity": "linear", "problem": "1159_D. The minimal unique substring", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    private static void solve(InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n\n        if (n < 6) {\n            out.println(-1);\n        } else {\n            int m = (n - 2);\n            for (int i = 2; i <= m; i++) {\n                out.println(\"1 \" + i);\n            }\n            out.println(m + \" \" + (m + 1));\n            out.println(m + \" \" + (m + 2));\n        }\n\n        for (int i = 2; i <= n; i++) {\n            out.println(\"1 \" + i);\n        }\n    }\n\n    private static void shuffleArray(int[] array) {\n        int index;\n        Random random = new Random();\n        for (int i = array.length - 1; i > 0; i--) {\n            index = random.nextInt(i + 1);\n            if (index != i) {\n                array[index] ^= array[i];\n                array[i] ^= array[index];\n                array[index] ^= array[i];\n            }\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    private static class InputReader {\n        private BufferedReader br;\n        private 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        byte nextByte() {\n            return Byte.parseByte(next());\n        }\n\n        short nextShort() {\n            return Short.parseShort(next());\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    private 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", "complexity": "linear", "problem": "959_C. Mahmoud and Ehab and the wrong algorithm", "from": "CODEFORCES"}
{"src": " 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   CF111111\n{\n  BufferedReader in;\n  StringTokenizer as;\n  int nums[],nums2[];\n  int[] nums1[];\n  boolean con = true;\n \n  ArrayList < Integer >  ar = new ArrayList < Integer >();\n  ArrayList < Integer >  fi = new ArrayList < Integer >();\n  Map<Integer,Integer > map = new HashMap<Integer, Integer>();\n  public static void main (String[] args)\n  {\n    new CF111111  ();\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  public int LIS(int arr[])\n  {\n    int n = arr.length;\n    int sun[] = new int [n];\n    int cur = 0;\n    for(int x = 0;x<n;x++)\n    {\n      int temp = Arrays.binarySearch(sun,0,cur,arr[x]);\n      if(temp < 0)\n        temp = -temp -1;\n      sun[temp] = arr[x];\n      if(temp == cur)\n        cur++;\n    }\n    return cur;\n    \n  }\n  \n  \n  \n  \n  public CF111111  ()\n  {\n    try\n    {\n      \n      in = new BufferedReader (new InputStreamReader (System.in));\n      int a = nextInt();\n      for(int xx1 = 0;xx1<a;xx1++)\n      {\n        int b = nextInt();\n        nums = new int [b];\n        for(int x = 0;x<b;x++)\n        {\n          nums[x] = nextInt();\n        }\n         int max = 0;\n         int max2 = -1;\n         for(int x = 0;x<b;x++)\n         {\n           if(nums[x] >= max)\n           {\n             max2 = max;\n             max = nums[x];\n           }\n           else if(nums[x] >= max2)\n             max2 = nums[x];\n         }\n        System.out.println(Math.min(max2, b-1)-1);\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}", "complexity": "linear", "problem": "1197_A. DIY Wooden Ladder", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    public static void main(String[] args)throws IOException{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int t = Integer.parseInt(br.readLine());\n        StringTokenizer st;\n        for(int z=0;z<t;z++){\n            st = new StringTokenizer(br.readLine());\n            int n = Integer.parseInt(st.nextToken());\n            st = new StringTokenizer(br.readLine());\n            int min=1;\n            int max=1;\n            for(int i=0;i<n;i++){\n                int k = Integer.parseInt(st.nextToken());\n                if(max<k){\n                    min = max;\n                    max = k;\n                }else if(min<k){\n                    min = k;\n                }\n            }\n            int res = Math.min(n-2,min-1);\n            System.out.println(res);\n        }\n    }\n}\n\n", "complexity": "linear", "problem": "1197_A. DIY Wooden Ladder", "from": "CODEFORCES"}
{"src": "//package com.krakn.CF.B1159;\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        int n;\n        n = sc.nextInt();\n        int[] arr = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            arr[i] = sc.nextInt();\n        }\n\n        int min = 1000000000, temp;\n\n        for (int i = 0; i < n; i++) {\n            temp = arr[i] / Math.max(i, n - 1 - i);\n            if (temp < min)\n                min = temp;\n//            System.out.println(i + \" \" + temp);\n        }\n\n        System.out.println(min);\n    }\n}\n", "complexity": "linear", "problem": "1159_B. Expansion coefficient of the array", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args)\n    {\n        Scanner stdin = new Scanner(System.in);\n        /*int n = stdin.nextInt();\n        for(int i = 0; i < n; i++)\n        {\n        \ttest(stdin);\n        }*/\n        test(stdin);\n        stdin.close();\n    }\n    public static void test(Scanner stdin)\n    {\n    \tint n = stdin.nextInt();\n    \tint min = Integer.MAX_VALUE;\n    \tfor(int i = 0; i < n; i++)\n    \t{\n    \t\tint a = stdin.nextInt();\n    \t\tif((int)((1.0)*a/(Math.max(i, n - i - 1))) < min)\n    \t\t{ min = (int)((1.0)*a/(Math.max(i, n - i - 1))); }\n    \t}\n    \tSystem.out.println(min);\n    }\n}", "complexity": "linear", "problem": "1159_B. Expansion coefficient of the array", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF903F {\n\tstatic final int INF = 0x3f3f3f3f;\n\tstatic void fill(int[][][][] aa, int a) {\n\t\tfor (int h0 = 0; h0 <= 4; h0++)\n\t\t\tfor (int h1 = 0; h1 <= 4; h1++)\n\t\t\t\tfor (int h2 = 0; h2 <= 4; h2++)\n\t\t\t\t\tfor (int h3 = 0; h3 <= 4; h3++)\n\t\t\t\t\t\taa[h0][h1][h2][h3] = a;\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\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint a1 = Integer.parseInt(st.nextToken());\n\t\tint a2 = Integer.parseInt(st.nextToken());\n\t\tint a3 = Integer.parseInt(st.nextToken());\n\t\tint a4 = Integer.parseInt(st.nextToken());\n\t\tint[] aa = new int[10];\n\t\taa[0] = aa[1] = aa[2] = aa[3] = a1;\n\t\taa[4] = aa[5] = aa[6] = a2;\n\t\taa[7] = aa[8] = a3;\n\t\taa[9] = a4;\n\t\tint[][] ww = new int[10][4];\n\t\tww[0][0] = 1;\n\t\tww[1][1] = 1;\n\t\tww[2][2] = 1;\n\t\tww[3][3] = 1;\n\t\tww[4][0] = ww[4][1] = 2;\n\t\tww[5][1] = ww[5][2] = 2;\n\t\tww[6][2] = ww[6][3] = 2;\n\t\tww[7][0] = ww[7][1] = ww[7][2] = 3;\n\t\tww[8][1] = ww[8][2] = ww[8][3] = 3;\n\t\tww[9][0] = ww[9][1] = ww[9][2] = ww[9][3] = 4;\n\t\tchar[][] cc = new char[4][n + 8];\n\t\tfor (int k = 0; k < 4; k++) {\n\t\t\tchar[] c_ = cc[k];\n\t\t\tbr.readLine().getChars(0, n, c_, 4);\n\t\t\tc_[0] = c_[1] = c_[2] = c_[3]\n\t\t\t\t= c_[n + 4] = c_[n + 5] = c_[n + 6] = c_[n + 7] = '.';\n\t\t}\n\t\tint[][][][] dp = new int[5][5][5][5];\n\t\tint[][][][] dq = new int[5][5][5][5];\n\t\tfill(dp, INF);\n\t\tdp[4][4][4][4] = 0;\n\t\tint[] hh = new int[4];\n\t\tfor (int i = 0; i < n + 4; i++) {\n\t\t\tfor (int h0 = 0; h0 <= 4; h0++)\n\t\t\t\tfor (int h1 = 0; h1 <= 4; h1++)\n\t\t\t\t\tfor (int h2 = 0; h2 <= 4; h2++)\n\t\t\t\t\t\tfor (int h3 = 0; h3 <= 4; h3++)\n\t\t\t\t\t\t\tfor (int s = 0; s < 10; s++) {\n\t\t\t\t\t\t\t\thh[0] = h0;\n\t\t\t\t\t\t\t\thh[1] = h1;\n\t\t\t\t\t\t\t\thh[2] = h2;\n\t\t\t\t\t\t\t\thh[3] = h3;\n\t\t\t\t\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\t\t\t\t\tint h = ww[s][k];\n\t\t\t\t\t\t\t\t\tif (hh[k] < h) {\n\t\t\t\t\t\t\t\t\t\twhile (h < 4 && cc[k][i + h] == '.')\n\t\t\t\t\t\t\t\t\t\t\th++;\n\t\t\t\t\t\t\t\t\t\thh[k] = h;\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\tint x = dp[h0][h1][h2][h3] + aa[s];\n\t\t\t\t\t\t\t\tif (dp[hh[0]][hh[1]][hh[2]][hh[3]] > x)\n\t\t\t\t\t\t\t\t\tdp[hh[0]][hh[1]][hh[2]][hh[3]] = x;\n\t\t\t\t\t\t\t}\n\t\t\tfill(dq, INF);\n\t\t\tfor (int h0 = 1; h0 <= 4; h0++) {\n\t\t\t\thh[0] = h0 < 4 || cc[0][i + 4] == '*' ? h0 - 1 : 4;\n\t\t\t\tfor (int h1 = 1; h1 <= 4; h1++) {\n\t\t\t\t\thh[1] = h1 < 4 || cc[1][i + 4] == '*' ? h1 - 1 : 4;\n\t\t\t\t\tfor (int h2 = 1; h2 <= 4; h2++) {\n\t\t\t\t\t\thh[2] = h2 < 4 || cc[2][i + 4] == '*' ? h2 - 1 : 4;\n\t\t\t\t\t\tfor (int h3 = 1; h3 <= 4; h3++) {\n\t\t\t\t\t\t\thh[3] = h3 < 4 || cc[3][i + 4] == '*' ? h3 - 1 : 4;\n\t\t\t\t\t\t\tint x = dp[h0][h1][h2][h3];\n\t\t\t\t\t\t\tif (dq[hh[0]][hh[1]][hh[2]][hh[3]] > x)\n\t\t\t\t\t\t\t\tdq[hh[0]][hh[1]][hh[2]][hh[3]] = x;\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[][][][] tmp = dp; dp = dq; dq = tmp;\n\t\t}\n\t\tSystem.out.println(dp[4][4][4][4]);\n\t}\n}\n", "complexity": "linear", "problem": "903_F. Clear The Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class GFG {\n\tpublic static void main (String[] args) {\n\t    Scanner sc = new Scanner (System.in);\n\t    int n = sc.nextInt();\n\t    int a = sc.nextInt();\n\t    int b = sc.nextInt();\n\t    int c = sc.nextInt();\n\t    int ans = 0;\n\t    int t= sc.nextInt();\n\t    int arr[] = new int[n];\n\t    for(int i=0;i<n;i++){\n\t        int nn = sc.nextInt();\n\t        ans+=a;\n\t        if(b<c){\n\t            ans += (t-nn) * (c - b);\n\t        }\n\t    }\n\t    System.out.println(ans);\n\t}\n}", "complexity": "linear", "problem": "964_B. Messages", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Cf1017A {\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 result = 1;\n        int thomasSum = 0;\n        StringTokenizer stk;\n        stk = new StringTokenizer(br.readLine());\n        int first = Integer.parseInt(stk.nextToken());\n        int second = Integer.parseInt(stk.nextToken());\n        int third = Integer.parseInt(stk.nextToken());\n        int fourth = Integer.parseInt(stk.nextToken());\n        thomasSum = first + second + third + fourth;\n        int tmp;\n        for (int i = 1; i < n; i++) {\n            stk = new StringTokenizer(br.readLine());\n            first = Integer.parseInt(stk.nextToken());\n            second = Integer.parseInt(stk.nextToken());\n            third = Integer.parseInt(stk.nextToken());\n            fourth = Integer.parseInt(stk.nextToken());\n            tmp = first + second + third + fourth;\n            if (tmp > thomasSum)\n                result++;\n        }\n        System.out.println(result);\n    }\n}", "complexity": "linear", "problem": "1017_A. The Rank", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class helloWorld \n{\n\tpublic static void main(String[] args) \n\t{\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint[] ar = new int[200];\n\t\t\n\t\tString str = in.next();\n\t\tfor(int i = 0; i < str.length(); i++)\n\t\t\tar[ str.charAt(i) ]++;\n\t\t\t\n\t\tint ans = 100000;\n\t\t\n\t\tfor(int i = 'A'; i < 'A' + m; i++)\n\t\t\tans = Math.min(ans, ar[i]);\n\t\tans *= m;\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\tin.close();\n\t}\n}\n\n", "complexity": "linear", "problem": "1038_A. Equality", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class TreasureHunt {\n\t\n\tpublic static String Solve() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tsc.nextLine();\n\t\tString kuro = sc.nextLine(), shiro = sc.nextLine(), katie = sc.nextLine();\n\t\tsc.close();\n\t\tString[] output = {\"Kuro\", \"Shiro\", \"Katie\", \"Draw\"};\n\t\tif(n >= kuro.length())\n\t\t\treturn output[3];\n\t\tint[] maxArr = new int[3];\t\t\n\t\tint[][] freq = new int[3][58];\n\t\tfor(int i = 0; i < kuro.length(); i++) {\n\t\t\tmaxArr[0] = ++freq[0][kuro.charAt(i) - 65] > maxArr[0]? freq[0][kuro.charAt(i) - 65] : maxArr[0];\n\t\t\tmaxArr[1] = ++freq[1][shiro.charAt(i) - 65] > maxArr[1]? freq[1][shiro.charAt(i) - 65] : maxArr[1];\n\t\t\tmaxArr[2] = ++freq[2][katie.charAt(i) - 65] > maxArr[2]? freq[2][katie.charAt(i) - 65] : maxArr[2];\n\t\t}\n\t\tint winner = 0, max = 0;\n\t\tfor(int i = 0; i < 3; i++) {\n\t\t\tif(kuro.length() - maxArr[i] >= n)\n\t\t\t\tmaxArr[i] += n;\n\t\t\telse \n\t\t\t\tmaxArr[i] = n == 1? kuro.length() - 1: kuro.length();\n\t\t\tif(max < maxArr[i]) {\n\t\t\t\twinner = i;\n\t\t\t\tmax = maxArr[i];\n\t\t\t} else if(max == maxArr[i])\n\t\t\t\twinner = 3;\n\t\t}\n\t\t\n\t\treturn output[winner];\n\t}\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(Solve());\n\t}\n}\n", "complexity": "linear", "problem": "979_B. Treasure Hunt", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\n// _ h _ r _ t r _\n// _ t _ t _ s t _\n\n\n\n\npublic class TaskA implements Runnable {\n    long m = (int)1e9+7;\n    PrintWriter w;\n    InputReader c;\n    final int MAXN = (int)1e6 + 100;\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n\n        int n = c.nextInt(), hamming_distance = 0;\n        char[] s = c.next().toCharArray(), t = c.next().toCharArray();\n        HashMap<Character, HashSet<Character>> replace = new HashMap<>();\n        HashMap<Character, Integer> map = new HashMap<>();\n\n        for(int i=0;i<n;++i) if(s[i] != t[i]) {\n            HashSet<Character> temp;\n            if(replace.containsKey(s[i])){\n                temp = replace.get(s[i]);\n                temp.add(t[i]);\n            } else {\n                temp = new HashSet<>();\n                temp.add(t[i]);\n            }\n            map.put(s[i],i);\n            replace.put(s[i], temp);\n            hamming_distance++;\n        }\n\n        int l = -1, r = -1;\n        boolean global_check = false;\n        for(int i=0;i<n;i++) if(s[i] != t[i]) {\n            if(replace.containsKey(t[i])) {\n                HashSet<Character> indices = replace.get(t[i]);\n                int ind = map.get(t[i]);\n                l = i + 1;\n                r = ind + 1;\n                if (indices.contains(s[i])) {\n                    hamming_distance -= 2;\n                    global_check = true;\n                    break;\n                }\n            }\n            if(global_check) break;\n        }\n\n        if(!global_check && l!=-1) hamming_distance--;\n        else if(global_check){\n            for(int i=0;i<n;i++) {\n                if(t[i] == s[l-1] && s[i] == t[l-1]){\n                    r = i + 1;\n                    break;\n                }\n            }\n        }\n        w.println(hamming_distance);\n        w.println(l+\" \"+r);\n\n        w.close();\n    }\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static void sortbyColumn(int arr[][], int col){\n        Arrays.sort(arr, new Comparator<int[]>()\n        {\n            public int compare(int[] o1, int[] o2){\n                return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    public static class DJSet {\n        public int[] upper;\n\n        public DJSet(int n) {\n            upper = new int[n];\n            Arrays.fill(upper, -1);\n        }\n\n        public int root(int x) {\n            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n        }\n\n        public boolean equiv(int x, int y) {\n            return root(x) == root(y);\n        }\n\n        public boolean union(int x, int y) {\n            x = root(x);\n            y = root(y);\n            if (x != y) {\n                if (upper[y] < upper[x]) {\n                    int d = x;\n                    x = y;\n                    y = d;\n                }\n                upper[x] += upper[y];\n                upper[y] = x;\n            }\n            return x == y;\n        }\n    }\n    public static int[] radixSort(int[] f)    {\n        int[] to = new int[f.length];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n    public void printArray(int[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n){\n        int a[] = new int[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n){\n        long a[] = new long[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars==-1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                }\n                catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        public int nextInt() {\n            int c = read();\n\n            while(isSpaceChar(c))\n                c = read();\n\n            int sgn = 1;\n\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n\n            int res = 0;\n            do {\n                if(c<'0'||c>'9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskA(),\"TaskA\",1<<26).start();\n    }\n}", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.HashMap;\n\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    } \n    \n    \n    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    \n    public static void main(String args[])\n    {\n        Reader sc=new Reader();\n        PrintWriter out=new PrintWriter(System.out);\n        int n=sc.i();\n        String s1=sc.s();\n        String s2=sc.s();\n        int pos1=-1;\n        int pos2=-1;\n        int arr[][][]=new int[100][100][2];\n        for(int i=0;i<n;i++)\n        {\n            if(s1.charAt(i)!=s2.charAt(i))\n            {\n                if(arr[s2.charAt(i)-97][s1.charAt(i)-97][0]==1)\n                {\n                    pos2=i;\n                    pos1=arr[s2.charAt(i)-97][s1.charAt(i)-97][1];\n                    break;\n                }\n                arr[s1.charAt(i)-97][s2.charAt(i)-97][0]=1;\n                arr[s1.charAt(i)-97][s2.charAt(i)-97][1]=i;\n            }\n        }\n        int ham=0;\n        for(int i=0;i<n;i++)\n        {\n            if(s1.charAt(i)!=s2.charAt(i))\n            ham++;\n        }\n        if(pos1!=-1&&pos2!=-1)\n        {\n            System.out.println(ham-2);\n            System.out.println(pos1+1+\" \"+(pos2+1));\n            System.exit(0);\n        }\n        \n        int arr1[][]=new int[100][2];\n        int arr2[][]=new int[100][2];\n        for(int i=0;i<n;i++)\n        {\n            if(s1.charAt(i)!=s2.charAt(i))\n            {\n                if(arr1[s1.charAt(i)-97][0]==1)\n                {\n                    pos2=i;\n                    pos1=arr1[s1.charAt(i)-97][1];\n                    break;\n                }\n                if(arr2[s2.charAt(i)-97][0]==1)\n                {\n                    pos2=i;\n                    pos1=arr2[s2.charAt(i)-97][1];\n                    break;\n                }\n                arr1[s2.charAt(i)-97][0]=1;\n                arr1[s2.charAt(i)-97][1]=i;\n                arr2[s1.charAt(i)-97][0]=1;\n                arr2[s1.charAt(i)-97][1]=i;\n            }\n        }\n        if(pos1!=-1&&pos2!=-1)\n        {\n            System.out.println(ham-1);\n            System.out.println(pos1+1+\" \"+(pos2+1));\n            System.exit(0);\n        }\n        System.out.println(ham);\n        System.out.println(pos1+\" \"+pos2);\n    }\n}", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "\t\t\n\t\t\t\t\t\t\timport 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.InputMismatchException;\n\t\t\t\t\t\t\t\t\t\t\tpublic class Solution1 implements Runnable\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tstatic final long MAX = 1000000007L;\n\t\t\t\t\t\t\t\t\t\t\t\tstatic class InputReader\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\t\tprivate InputStream stream;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate byte[] buf = new byte[1024];\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate int curChar;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate int numChars;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate SpaceCharFilter filter;\n\t\t\t\t\t\t\t\t\t\t\t\t\tprivate BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic InputReader(InputStream stream)\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\t\tthis.stream = stream;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic int read()\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\t\tif (numChars==-1) \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\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\tif (curChar >= numChars)\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\tcurChar = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttry \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\t\t\t\t\tnumChars = stream.read(buf);\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\t\t\t\tcatch (IOException e)\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\t\t\t\t\tthrow new InputMismatchException();\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\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn -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\treturn buf[curChar++];\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\t\tpublic String nextLine()\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\t\tString str = \"\";\n\t\t\t\t\t\t\t\t\t\t\t            try\n\t\t\t\t\t\t\t\t\t\t\t            {\n\t\t\t\t\t\t\t\t\t\t\t                str = br.readLine();\n\t\t\t\t\t\t\t\t\t\t\t            }\n\t\t\t\t\t\t\t\t\t\t\t            catch (IOException e)\n\t\t\t\t\t\t\t\t\t\t\t            {\n\t\t\t\t\t\t\t\t\t\t\t                e.printStackTrace();\n\t\t\t\t\t\t\t\t\t\t\t            }\n\t\t\t\t\t\t\t\t\t\t\t            return str;\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\tpublic int nextInt()\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\t\tint c = read();\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\twhile(isSpaceChar(c)) \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tint sgn = 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\tif (c == '-') \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\tsgn = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tint res = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdo \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\tif(c<'0'||c>'9') \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\twhile (!isSpaceChar(c)); \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\treturn res * sgn;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic long nextLong() \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\t\tint c = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c == '-') \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\tsgn = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tlong res = 0;\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\tdo \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\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\twhile (!isSpaceChar(c));\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * sgn;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic double nextDouble() \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\t\tint c = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c == '-') \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\tsgn = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tdouble res = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (!isSpaceChar(c) && c != '.') \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\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\tif (c == '.') \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\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdouble m = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (!isSpaceChar(c)) \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\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tm /= 10;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn res * sgn;\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic String readString() \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\t\tint c = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdo \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\tres.appendCodePoint(c);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tc = read();\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\twhile (!isSpaceChar(c));\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\treturn res.toString();\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\t\tpublic boolean isSpaceChar(int c) \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\t\tif (filter != null)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t\t\t\t\t\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\t\tpublic String next() \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\t\treturn readString();\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\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tpublic interface SpaceCharFilter \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\t\tpublic boolean isSpaceChar(int ch);\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 \t\n\t\t\t\t\t\t\t\t\t\t\t\tpublic static void main(String args[]) throws Exception\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\t\tnew Thread(null, new Solution1(),\"Solution1\",1<<26).start();\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\tlong gcd(long a, long b)\n\t\t\t\t\t\t\t\t\t\t\t    {\n\t\t\t\t\t\t\t\t\t\t\t        if (a == 0)\n\t\t\t\t\t\t\t\t\t\t\t            return b;\n\t\t\t\t\t\t\t\t\t\t\t         \n\t\t\t\t\t\t\t\t\t\t\t        return gcd(b%a, a);\n\t\t\t\t\t\t\t\t\t\t\t    }\n\t\t\t\t\t\t\t\t\t\t\t    // method to return LCM of two numbers\n\t\t\t\t\t\t\t\t\t\t\t\t long lcm(long a, long b)\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\t        return (a*b)/gcd(a, b);\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\t int root(int a){\n\t\t\t\t\t\t\t\t\t\t\t\t\t while(arr[a] != a){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t arr[a] = arr[arr[a]];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t a = arr[a];\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\t return a;\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\t void union(int a,int b){\n\t\t\t\t\t\t\t\t\t\t\t\t\t int xroot = root(a);\n\t\t\t\t\t\t\t\t\t\t\t\t\t int yroot = root(b);\n\t\t\t\t\t\t\t\t\t\t\t\t\t if(arr[xroot] < arr[yroot]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t arr[xroot] = yroot;\n\t\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\t\t arr[yroot] = xroot;\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\t boolean find(int a,int b){\n\t\t\t\t\t\t\t\t\t\t\t\t\t int roota = root(a);\n\t\t\t\t\t\t\t\t\t\t\t\t\t int rootb = root(b);\n\t\t\t\t\t\t\t\t\t\t\t\t\t if(roota == rootb){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t return true;\n\t\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\t\t return false;\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\t int[] arr;\n\t\t\t\t\t\t\t\t\t\t\t\t final int level = 20;\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\tpublic void run()\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\t\tInputReader sc= new InputReader(System.in);\n\t\t\t\t\t\t\t\t\t\t\t\t\tPrintWriter w= new PrintWriter(System.out);\n\t\t\t\t\t\t\t\t\t\t\t\t\tint n = sc.nextInt();\n\t\t\t\t\t\t\t\t\t\t\t\t\tchar[] ch = new char[n];\n\t\t\t\t\t\t\t\t\t\t\t\t\tchar[] ch2 = new char[n];\n\t\t\t\t\t\t\t\t\t\t\t\t\tch = sc.next().toCharArray();\n\t\t\t\t\t\t\t\t\t\t\t\t\tch2 = sc.next().toCharArray();\n\t\t\t\t\t\t\t\t\t\t\t\t\tHashSet<Integer> hset[] = new HashSet[26];\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor(int i = 0;i < 26;i++){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\thset[i]  =new HashSet();\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\tint count = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor(int i = 0;i < ch.length;i++){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thset[ch[i]-97].add(ch2[i]-97);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount++;\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\tboolean flag = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint swap1 = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint swap2 = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint rem = -1;\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor(int i = 0;i < ch.length;i++){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(hset[ch2[i]-97].size() != 0){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tswap1 = i;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tflag = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(hset[ch2[i]-97].contains(ch[i]-97)){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trem = i;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount-=2;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tflag = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\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\t\t\t\t}\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\tif(flag){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount--;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println(count);\n\t\t\t\t\t\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\t\t\t\t\tif(i != swap1 && ch[i] == ch2[swap1] && ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println((swap1+1) + \" \" + (i+1));\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.close();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSystem.exit(0);\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\t\t\t}\n\t\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\t\tif(rem == -1){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println(count);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println(\"-1 -1\");\n\t\t\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\t\t\tw.println(count);\n\t\t\t\t\t\t\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\t\t\t\t\t\tif(i != rem && ch[i] == ch2[rem] && ch[rem] == ch2[i] && ch[i] != ch2[i]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.println((rem+1) + \" \" + (i+1));\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tw.close();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSystem.exit(0);\n\t\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\t\t\t\t}\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\tw.close();\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\tboolean fun(long[] prefix,long mid,long temp,long[] arr){\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(temp >= prefix[(int)mid]){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn true;\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\treturn false;\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\tstatic class Pair implements Comparable<Pair>{\n\t\t\t\t\t\t\t\t\t\t\t\t\tint x;\n\t\t\t\t\t\t\t\t\t\t\t\t\tint y;\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\tPair(){}\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tPair(int x,int y){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.x = x;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.y = y;\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\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\tpublic int compareTo(Pair p){\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\treturn Long.compare(this.x,p.x);\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}", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ErrorCorrectSystem\n{\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tString a = scan.next();\n\t\tString b = scan.next();\n\t\t\n\t\tint[][] mismatch = new int[26][26];\n\t\tfor(int i = 0; i < 26; i++) Arrays.fill(mismatch[i], -1);\n\t\tint[][] pair = new int[2][26];\n\t\tfor(int i = 0; i < 2; i++) Arrays.fill(pair[i], -1);\n\t\tint hd = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(a.charAt(i) != b.charAt(i)) {\n\t\t\t\thd++;\n\t\t\t\tmismatch[a.charAt(i)-'a'][b.charAt(i)-'a'] = i;\n\t\t\t\tpair[0][a.charAt(i)-'a'] = i;\n\t\t\t\tpair[1][b.charAt(i)-'a'] = i;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < 26; i++) {\n\t\t\tfor(int j = i+1; j < 26; j++) {\n\t\t\t\tif(mismatch[i][j] > -1 && mismatch[j][i] > -1) {\n\t\t\t\t\tSystem.out.println(hd-2);\n\t\t\t\t\tSystem.out.println((mismatch[i][j]+1)+\" \"+(mismatch[j][i]+1));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(a.charAt(i) != b.charAt(i)) {\n\t\t\t\t//try a gets b's letter\n\t\t\t\tif(pair[0][b.charAt(i)-'a'] > -1) {\n\t\t\t\t\tSystem.out.println(hd-1);\n\t\t\t\t\tSystem.out.println((i+1)+\" \"+(pair[0][b.charAt(i)-'a']+1));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(hd);\n\t\tSystem.out.println(\"-1 -1\");\n\t}\n\n}\n", "complexity": "linear", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class C {\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        int counter = 0;\n        for(int i=0; i<2*n/3; i++) System.out.println(\"0 \" + i);\n        for(int i=0; i<n-2*n/3; i++) System.out.println(\"3 \" + (2*i+1));\n\n    }\n}\n", "complexity": "linear", "problem": "1067_C. Knights", "from": "CODEFORCES"}
{"src": "\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\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n744444444747477777774\n44444447474747777777\n */\n\n/**\n *\n * @author Andy Phan\n */\npublic class b {\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        Integer[] arr = new Integer[n];\n        int numZ = 0;\n        for(int i = 0; i < n; i++) {\n            arr[i] = in.nextInt();\n            if(arr[i] == 0) numZ++;\n        }\n        \n        Arrays.sort(arr);\n        \n        \n        if(numZ > 1) {\n            System.out.println(\"cslnb\");\n            return;\n        }\n        int numDup = 0;\n        int[] arr2 = new int[n];\n        for(int i = 0; i < n; i++) {\n            arr2[i] = arr[i];\n            if(i != 0) {\n                if(arr2[i] == arr2[i-1]) {\n                    arr2[i-1]--;\n                    numDup++;\n                }\n            }\n        }\n        \n        if(numDup > 1) {\n            System.out.println(\"cslnb\");\n            return;\n        }\n        \n        \n        for(int i = 0; i < n; i++) {\n            if(i != 0) {\n                if(arr2[i] == arr2[i-1]) {\n                    System.out.println(\"cslnb\");\n                    return;\n                }\n            }\n        }\n        long num = 0;\n        if(numDup == 1) num++;\n        for(int i = 0; i < n; i++) {\n            num += arr2[i]-i;\n        }\n        \n        if(num%2 == 0) {\n            System.out.println(\"cslnb\");\n        } else {\n            System.out.println(\"sjfnb\");\n        }\n        \n\n        out.close();\n    }\n    \n    static class FS {\n\n        BufferedReader in;\n        StringTokenizer token;\n        \n        public FS(InputStream str) {\n            in = new BufferedReader(new InputStreamReader(str));\n        }\n        \n        public String next() {\n            if (token == null || !token.hasMoreElements()) {\n                try {\n                    token = new StringTokenizer(in.readLine());\n                } catch (IOException ex) {\n                }\n                return next();\n            }\n            return token.nextToken();\n        }\n        \n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n    }\n}\n", "complexity": "linear", "problem": "1191_D. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n \npublic class temp\n{\n\t\n\tvoid solve()\n\t{\n\t\tFastReader sc =new FastReader();\n\t\tint n = sc.nextInt();\n\t\t\n\t\tArrayList<String> a[] = new ArrayList[5];\n\t\t\n\t\tfor(int i=0;i<=4;i++)\n\t\t\ta[i] = new ArrayList<>();\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tString s = sc.next();\n\t\t\ta[s.length()].add(s);\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tString s = sc.next();\n\t\t\tif(a[s.length()].contains(s))\n\t\t\t\ta[s.length()].remove(new String(s));\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=4;i++)\n\t\t\tans+=a[i].size();\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n \n    public static void main(String[] args)\n    {\n        new temp().solve();\n    }\n\t\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} ", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Main {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\tprivate PrintWriter pw;\n\tprivate long mod = 1000000000 + 7;\n\n\tprivate StringBuilder ans_sb;\n\tprivate int size = 1000005;\n\tprivate long[] fact;\n\tprivate void soln() {\n\t\tint n = nextInt();\n\t\tHashMap<String, Integer>[] s1 = new HashMap[4];\n\t\tfor(int i=0;i<=3;i++) {\n\t\t\ts1[i] = new HashMap<>();\n\t\t}\n\t\tint cnt = 0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tString s = nextLine();\n\t\t\tif(s1[s.length()-1].containsKey(s)) {\n\t\t\t\ts1[s.length()-1].put(s, s1[s.length()-1].get(s)+1);\n\t\t\t}else\n\t\t\t\ts1[s.length()-1].put(s, 1);\n\t\t}\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tString s = nextLine();\n\t\t\tif(s1[s.length()-1].containsKey(s)) {\n\t\t\t\ts1[s.length()-1].put(s, s1[s.length()-1].get(s)-1);\n\t\t\t\tif(s1[s.length()-1].get(s) == 0)\n\t\t\t\t\ts1[s.length()-1].remove(s);\n\t\t\t}else {\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t\tpw.println(cnt);\n\t}\n\tprivate class Pair implements Comparable<Pair>{\n\t\tlong x, y; \n\t\tint i;\n\t\tpublic Pair(long a,long b,int c) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t\ti = c;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(\n\t\t\t\tPair o)\n\t\t{\n\t\t\treturn Long.compare(this.x, o.x);\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn \"\"+i;\n\t\t}\n\t}\n\tprivate void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tprivate 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 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\tnew Thread(null, new Runnable() {\n\t\t\t@Override\n\t\t\tpublic void run() {\n\t\t\t\tnew Main().solve();\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t\t//new Main().solve();\n\t}\n\n\tpublic StringBuilder solve() {\n\t\tInputReader(System.in);\n\t\t/*\n\t\t * try { InputReader(new FileInputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\in.txt\"));\n\t\t * } catch(FileNotFoundException e) {}\n\t\t */\n\t\tpw = new PrintWriter(System.out);\n\t\t// ans_sb = new StringBuilder();\n\t\tsoln();\n\n\t\tpw.close();\n\t\t// System.out.println(ans_sb);\n\t\treturn ans_sb;\n\t}\n\n\tpublic void InputReader(InputStream stream1) {\n\t\tstream = stream1;\n\t}\n\n\tprivate boolean isWhitespace(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\tprivate int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tprivate 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 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 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 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 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 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 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 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 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 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}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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.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 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        ACodehorsesTShirts solver = new ACodehorsesTShirts();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ACodehorsesTShirts {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            Map<String, Integer> map = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                String ch = in.next();\n                if (map.containsKey(ch)) {\n                    map.put(ch, map.get(ch) + 1);\n                } else {\n                    map.put(ch, 1);\n                }\n            }\n            int s = n;\n            for (int i = 0; i < n; i++) {\n                String ch = in.next();\n                if (map.containsKey(ch)) {\n                    if (map.get(ch) == 1) {\n                        map.remove(ch);\n                    } else {\n                        map.put(ch, map.get(ch) - 1);\n                    }\n                    s--;\n                }\n            }\n            out.println(s);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader br;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream inputStream) {\n            br = new BufferedReader(new InputStreamReader(inputStream));\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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n    static StringTokenizer tok;\n    static boolean hasNext()\n    {\n        while(tok==null||!tok.hasMoreTokens())\n            try{\n                tok=new StringTokenizer(in.readLine());\n            }\n            catch(Exception e){\n                return false;\n            }\n        return true;\n    }\n    static String next()\n    {\n        hasNext();\n        return tok.nextToken();\n    }\n    static long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n    static int nextInt()\n    {\n        return Integer.parseInt(next());\n    }\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));\n\n    public static void main(String[] args) {\n        int n = nextInt();\n        int a[] = new int[9];\n        int b[] = new int[9];\n        for(int i=0;i<n;i++){\n            String s = next();\n            if(s.equals(\"M\")){\n                a[0]++;\n            }else if (s.equals(\"L\")){\n                a[1]++;\n            }\n            else if (s.equals(\"XL\")){\n                a[2]++;\n            }\n            else if (s.equals(\"XXL\")){\n                a[3]++;\n            }\n            else if (s.equals(\"XXXL\")){\n                a[4]++;\n            }\n            else if (s.equals(\"S\")){\n                a[5]++;\n            }\n            else if (s.equals(\"XS\")){\n                a[6]++;\n            }\n            else if (s.equals(\"XXS\")){\n                a[7]++;\n            }\n            else if (s.equals(\"XXXS\")){\n                a[8]++;\n            }\n        }\n        for(int i=0;i<n;i++){\n            String s = next();\n            if(s.equals(\"M\")){\n                b[0]++;\n            }else if (s.equals(\"L\")){\n                b[1]++;\n            }\n            else if (s.equals(\"XL\")){\n                b[2]++;\n            }\n            else if (s.equals(\"XXL\")){\n                b[3]++;\n            }\n            else if (s.equals(\"XXXL\")){\n                b[4]++;\n            }\n            else if (s.equals(\"S\")){\n                b[5]++;\n            }\n            else if (s.equals(\"XS\")){\n                b[6]++;\n            }\n            else if (s.equals(\"XXS\")){\n                b[7]++;\n            }\n            else if (s.equals(\"XXXS\")){\n                b[8]++;\n            }\n        }\n\n        int ans = 0;\n        ans+=Math.abs(a[2]-b[2]);\n        ans+=Math.abs(a[3]-b[3]);\n        ans+=Math.abs(a[4]-b[4]);\n        int max = Math.abs(a[0]-b[0]);\n        max = max(max,Math.abs(a[1]-b[1]));\n        max = max(max,Math.abs(a[5]-b[5]));\n        ans+=max;\n        out.print(ans);\n        out.flush();\n    }\n    public static int max(int a,int b){\n        return a>b?a:b;\n    }\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\npublic class hackerearth {\n\n    public  static  void main(String[] args) {\n\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n\n        HashMap<String,Integer> map=new HashMap<>();\n        HashMap<String,Integer> map2=new HashMap<>();\n        for(int i=0;i<n;i++)\n        {\n            String s=sc.next();\n            if(map.containsKey(s))\n                map.put(s,map.get(s)+1);\n            else\n                map.put(s,1);\n        }\n        for(int i=0;i<n;i++)\n        {\n            String s=sc.next();\n            if(map2.containsKey(s))\n                map2.put(s,map2.get(s)+1);\n            else\n                map2.put(s,1);\n\n            if(map.containsKey(s)) {\n                int feq = map.get(s);\n                feq--;\n                if (feq <= 0)\n                    map.remove(s);\n                else\n                    map.put(s, feq);\n            }\n\n        }\n\n\n        int ans=0;\n        for(Map.Entry<String,Integer> entry:map.entrySet())\n        {\n            ans+=entry.getValue();\n        }\n        System.out.println(ans);\n\n\n    }\n\n\n\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\n\npublic class E46A\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tString[] sizes = {\"XXXS\", \"XXS\", \"XS\", \"S\", \"M\", \"L\", \"XL\", \"XXL\", \"XXXL\"};\n\t\tint n = in.nextInt();\n\t\tHashMap<String, Integer> a = new HashMap<>();\n\t\tHashMap<String, Integer> b = new HashMap<>();\n\t\tfor (String s : sizes) {\n\t\t\ta.put(s, 0);\n\t\t\tb.put(s, 0);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\ta.put(s, a.get(s) + 1);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\tb.put(s, b.get(s) + 1);\n\t\t}\n\t\tfor (String s : sizes) {\n\t\t\tint cut = Math.min(a.get(s), b.get(s));\n\t\t\ta.put(s, a.get(s) - cut);\n\t\t\tb.put(s, b.get(s) - cut);\n\t\t}\n\t\tint changes = 0;\n\t\tfor (String s : sizes)\n\t\t\tchanges += a.get(s);\n\t\tSystem.out.println(changes);\n\t}\n\t\n\t/**\n\t * Source: Matt Fontaine\n\t */\n\tpublic static class FastScanner\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 FastScanner(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tint read()\n\t\t{\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\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{\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{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String next()\n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo\n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine()\n\t\t{\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{\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}\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n// Solution\n\npublic class Main \n{    \n  public static void main (String[] argv) \n  {\n\t  new Main();\n  } \n     \n     \n  \n  boolean test = false;  \n  \n  \n  \n  public Main()  {\n\t  FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));\n\t  //FastReader in = new FastReader(new BufferedReader(new FileReader(\"Main.in\")));\n      int n = in.nextInt();\n      int nM = 0;\n      int[] nS = new int[4];\n      int[] nL = new int[4];\n      for (int i = 0; i < n; i++) {\n          String s = in.next();\n          int ns = s.length();\n          if (s.charAt(0) == 'M') nM++;\n          else if (s.charAt(ns - 1) == 'S') nS[ns-1]++;\n          else nL[ns-1]++;\n      }\n      int c = 0;\n      int[] nSr = new int[4];\n      int[] nLr = new int[4];\n      int nMr = 0;\n      for (int i = 0; i < n; i++) {\n          String s = in.next();\n          int ns = s.length();\n          if (s.charAt(0) == 'M') {\n              if (nM > 0) --nM;\n              else ++nMr;\n          }else if (s.charAt(ns - 1) == 'S') {\n              if (nS[ns-1] > 0) --nS[ns-1];\n              else ++nSr[ns-1];\n          }else {\n              if (nL[ns-1] > 0) --nL[ns-1];\n              else ++nLr[ns-1];\n          }     \n      }\n      \n      for (int i = 0; i < 4; i++) c += nS[i] + nL[i];\n      c += nM;\n      \n      System.out.println(c);\n  }\n  \n  \n  \n \n  \n  private int nBit1(int v) {\n      int v0 = v;\n      int c = 0;\n      while (v != 0) {\n          ++c;\n          v = v & (v - 1);\n      }\n      return c;\n  }\n  \n  private int common(int v) {\n      int c = 0;\n      while (v != 1) {\n          v = (v >>> 1);\n          ++c;\n      }\n      \n      return c;\n  }\n  \n  private void reverse(char[] a, int i, int j) {\n      while (i < j) {\n          swap(a, i++, j--);\n      }\n  }\n  \n  private void swap(char[] a, int i, int j) {\n      char t = a[i];\n      a[i] = a[j];\n      a[j] = t;\n  }\n  \n  \n  private long gcd(long x, long y) {\n      if (y == 0) return x;\n      return gcd(y, x % y);\n  }\n  private int max(int a, int b) {\n      return a >  b ? a : b;\n  }\n  \n  private int min(int a, int b) {\n      return a >  b ? b : a;\n  }\n  \n  \n  static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastReader(BufferedReader in)\n        {            \n            br = in;\n        }\n \n        String next()\n        {\n            while (st == null || !st.hasMoreElements())\n            {\n                try\n                {\n                    String line = br.readLine();\n                    if (line == null || line.length() == 0) return \"\";\n                    st = new StringTokenizer(line);\n                }\n                catch (IOException  e)\n                {\n                    return \"\";\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                return \"\";\n                //e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Scanner;\nimport java.lang.StringBuilder;\nimport java.util.Arrays;\nimport java.util.Stack;\nimport java.util.TreeMap;\npublic class Test11   {  \n    public static void main(String[] Args)   {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        String s0 = sc.nextLine();\n        int s = 0; // S\n        int m = 0;\n        int l = 0;\n        int s1 = 0;\n        int l1 = 0;\n        int s2 = 0;\n        int l2 = 0;\n        int s3 = 0;\n        int l3 = 0;\n        for (int i = 0; i < n; i++)  {\n            s0 = sc.nextLine();\n            if (s0.charAt(0) == 'S') s++;\n            if (s0.charAt(0) == 'M') m++;\n            if (s0.charAt(0) == 'L') l++;\n            if (s0.charAt(0) == 'X' && s0.length() == 2 && s0.charAt(s0.length() - 1) == 'S') s1++;\n            if (s0.charAt(0) == 'X' && s0.length() == 3 && s0.charAt(s0.length() - 1) == 'S') s2++;\n            if (s0.charAt(0) == 'X' && s0.length() == 4 && s0.charAt(s0.length() - 1) == 'S') s3++;\n            if (s0.charAt(0) == 'X' && s0.length() == 2 && s0.charAt(s0.length() - 1) == 'L') l1++;\n            if (s0.charAt(0) == 'X' && s0.length() == 3 && s0.charAt(s0.length() - 1) == 'L') l2++;\n            if (s0.charAt(0) == 'X' && s0.length() == 4 && s0.charAt(s0.length() - 1) == 'L') l3++;\n        }    \n        int rs = 0; // S\n        int rm = 0;\n        int rl = 0;\n        int rs1 = 0;\n        int rl1 = 0;\n        int rs2 = 0;\n        int rl2 = 0;\n        int rs3 = 0;\n        int rl3 = 0;\n        for (int i = 0; i < n; i++)  {\n            s0 = sc.nextLine();\n            if (s0.charAt(0) == 'S') rs++;\n            if (s0.charAt(0) == 'M') rm++;\n            if (s0.charAt(0) == 'L') rl++;\n            if (s0.charAt(0) == 'X' && s0.length() == 2 && s0.charAt(s0.length() - 1) == 'S') rs1++;\n            if (s0.charAt(0) == 'X' && s0.length() == 3 && s0.charAt(s0.length() - 1) == 'S') rs2++;\n            if (s0.charAt(0) == 'X' && s0.length() == 4 && s0.charAt(s0.length() - 1) == 'S') rs3++;\n            if (s0.charAt(0) == 'X' && s0.length() == 2 && s0.charAt(s0.length() - 1) == 'L') rl1++;\n            if (s0.charAt(0) == 'X' && s0.length() == 3 && s0.charAt(s0.length() - 1) == 'L') rl2++;\n            if (s0.charAt(0) == 'X' && s0.length() == 4 && s0.charAt(s0.length() - 1) == 'L') rl3++;\n        }     \n        int ans = Math.abs(s1 - rs1) + Math.abs(s2 - rs2) + Math.abs(s3 - rs3) + (Math.abs(s - rs) + Math.abs(l - rl) + Math.abs(m - rm))/2;\n        System.out.println(ans);\n            \n   }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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 Edu_46A {\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\tint nE = Integer.parseInt(reader.readLine());\n\n\t\tint[][] cnt = new int[][] { { 0, 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };\n\n\t\tfor (int i = 0; i < nE; i++) {\n\t\t\tString nxt = reader.readLine();\n\t\t\tif (nxt.equals(\"S\")) {\n\t\t\t\tcnt[0][0]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"M\")) {\n\t\t\t\tcnt[0][1]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"L\")) {\n\t\t\t\tcnt[0][2]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XS\")) {\n\t\t\t\tcnt[1][0]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XL\")) {\n\t\t\t\tcnt[1][1]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXS\")) {\n\t\t\t\tcnt[2][0]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXL\")) {\n\t\t\t\tcnt[2][1]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXXS\")) {\n\t\t\t\tcnt[3][0]++;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXXL\")) {\n\t\t\t\tcnt[3][1]++;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < nE; i++) {\n\t\t\tString nxt = reader.readLine();\n\t\t\tif (nxt.equals(\"S\")) {\n\t\t\t\tcnt[0][0]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"M\")) {\n\t\t\t\tcnt[0][1]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"L\")) {\n\t\t\t\tcnt[0][2]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XS\")) {\n\t\t\t\tcnt[1][0]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XL\")) {\n\t\t\t\tcnt[1][1]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXS\")) {\n\t\t\t\tcnt[2][0]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXL\")) {\n\t\t\t\tcnt[2][1]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXXS\")) {\n\t\t\t\tcnt[3][0]--;\n\t\t\t}\n\t\t\tif (nxt.equals(\"XXXL\")) {\n\t\t\t\tcnt[3][1]--;\n\t\t\t}\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor (int i = 1; i <= 3; i++) {\n\t\t\tans += Math.abs(cnt[i][0]);\n\t\t}\n\n\t\tint max = 0;\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tmax = Math.max(max, Math.abs(cnt[0][i]));\n\t\t}\n\t\tans += max;\n\t\tprinter.println(ans);\n\t\tprinter.close();\n\t}\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\n\npublic class CodehorsesT_shirts {\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(reader.readLine());\n        HashMap<String, Integer> map = new HashMap<String, Integer>();\n        String input;\n        for (int i = 0; i < n; i++) {\n            input = reader.readLine();\n            if (map.containsKey(input)) {\n                map.put(input, map.get(input) + 1);\n            } else {\n                map.put(input, 1);\n            }\n        }\n        int change = 0;\n        for (int i = 0; i < n; i++) {\n            input = reader.readLine();\n            if (map.containsKey(input)) {\n                map.put(input, map.get(input) - 1);\n            } else {\n                map.put(input, -1);\n            }\n        }\n        for (int x : map.values()) {\n            change += Math.abs(x);\n        }\n        System.out.println(change/2);\n    }\n\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\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\tString[] s = {\"XXXS\", \"XXS\", \"XS\", \"S\", \"M\", \"L\", \"XL\", \"XXL\", \"XXXL\"};\n\t\tint[] size = new int[9];\n\t\tfor(int i=0; i<N; i++){\n\t\t\tString c = br.readLine();\n\t\t\tfor(int j=0; j<9; j++){\n\t\t\t\tif(s[j].equals(c)){\n\t\t\t\t\tsize[j]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0; i<N; i++){\n\t\t\tString c = br.readLine();\n\t\t\tfor(int j=0; j<9; j++){\n\t\t\t\tif(s[j].equals(c)){\n\t\t\t\t\tsize[j]--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint sum = 0;\n\t\tfor(int i=0; i<9; i++){\n\t\t\tif(size[i]>0)\n\t\t\t\tsum += size[i];\n\t\t}\n\t\tSystem.out.println(sum);\n\t}\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class CodehorsesTShirt {\n\n    public static void main(String args[]) throws IOException {\n        FastReader in = new FastReader();\n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n        Task.solve(in, out);\n        out.close();\n    }\n\n    static class Task {\n\n        public static void solve(FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            HashMap<String , Integer> hm1 = new HashMap<>();\n            HashMap<String , Integer> hm2 = new HashMap<>();\n\n            for(int i=0;i<n;i++){\n                String val = in.next();\n                if(hm1.containsKey(val)){\n                    hm1.put(val, hm1.get(val)+1);\n                }else{\n                    hm1.put(val,1);\n                }\n            }\n\n            for(int i=0;i<n;i++){\n                String val = in.next();\n                if(hm1.containsKey(val)){\n                    int x = hm1.get(val);\n                    if(x==1){\n                        hm1.remove(val);\n                    }else{\n                        hm1.put(val,hm1.get(val)-1);\n                    }\n                }else{\n                    if(hm2.containsKey(val)){\n                        hm2.put(val, hm2.get(val)+1);\n                    }else{\n                        hm2.put(val,1);\n                    }\n                }\n            }\n            int ans = 0;\n            for(Map.Entry<String , Integer> row: hm1.entrySet()){\n                ans += row.getValue();\n            }\n            System.out.println(ans);\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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n/*\n * Heart 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...\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?)\n//always declare multidimensional arrays as [2][n] not [n][2]\n//it can lead to upto 2-3x diff in runtime\n//declare int/long tries with 16 array size due to object overhead :D\npublic class Main\n{\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tint n=ni();\n\t\tMap<String, Integer> hola=new HashMap<String,Integer>();\n\t\thola.put(\"S\", 0);\n\t\thola.put(\"XS\", 0);\n\t\thola.put(\"XXS\", 0);\n\t\thola.put(\"XXXS\", 0);\n\t\thola.put(\"M\", 0);\n\t\thola.put(\"L\", 0);\n\t\thola.put(\"XL\", 0);\n\t\thola.put(\"XXL\", 0);\n\t\thola.put(\"XXXL\", 0);\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tString te=ns();\n\t\t\thola.put(te,hola.get(te)+1);\n\t\t}\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tString te=ns();\n\t\t\thola.put(te,hola.get(te)-1);\n\t\t}\n\t\tint ans=0;\n\t\tfor(int te:hola.values())\n\t\t{\n\t\t\tans+=max(te,0);\n\t\t}\n\t\tpr(ans);\n\t\tSystem.out.print(output);\n\t}\n\t///////////////////////////////////////////\n\t///////////////////////////////////////////\n\t///template from here\n\tstatic int pow(int a, int b)\n\t{\n\t\tint c=1;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2!=0)\n\t\t\t\tc*=a;\n\t\t\ta*=a;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic class pair\n\t{\n\t\tint a, b;\n\t\tpair(){}\n\t\tpair(int c,int d){a=c;b=d;}\n\t}\n\tstatic interface combiner\n\t{\n\t\tpublic long combine(long a,long b);\n\t}\n\tstatic final long mod=1000000007;\n\tstatic final double eps=1e-9;\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\tstatic void reverse(int[]a){for(int i=0; i<a.length/2; i++){a[i]^=a[a.length-i-1];a[a.length-i-1]^=a[i];a[i]^=a[a.length-i-1];}}\n\tstatic void sort(int[]a)\n\t{\n\t\tint te;\n\t\tfor(int i=0; i<a.length; i+=2)\n\t\t{\n\t\t\tte=rn.nextInt(a.length);\n\t\t\tif(i!=te)\n\t\t\t{\n\t\t\t\ta[i]^=a[te];\n\t\t\t\ta[te]^=a[i];\n\t\t\t\ta[i]^=a[te];\n\t\t\t}\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tstatic void sort(long[]a)\n\t{\n\t\tint te;\n\t\tfor(int i=0; i<a.length; i+=2)\n\t\t{\n\t\t\tte=rn.nextInt(a.length);\n\t\t\tif(i!=te)\n\t\t\t{\n\t\t\ta[i]^=a[te];\n\t\t\ta[te]^=a[i];\n\t\t\ta[i]^=a[te];\n\t\t\t}\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tstatic void sort(double[]a)\n\t{\n\t\tint te;\n\t\tdouble te1;\n\t\tfor(int i=0; i<a.length; i+=2)\n\t\t{\n\t\t\tte=rn.nextInt(a.length);\n\t\t\tif(i!=te)\n\t\t\t{\n\t\t\tte1=a[te];\n\t\t\ta[te]=a[i];\n\t\t\ta[i]=te1;\n\t\t\t}\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tstatic void sort(int[][]a)\n\t{\n\t\tArrays.sort(a, new Comparator<int[]>()\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 void sort(pair[]a)\n\t{\n\t\tArrays.sort(a,new Comparator<pair>()\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\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 vectorl implements Iterable<Long>\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<Long> iterator() {\n\t\t\tIterator<Long> hola=new Iterator<Long>()\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<size;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Long next() {\n\t\t\t\t\t\t\treturn a[cur++];\n\t\t\t\t\t\t}\t\t\t\t\n\t\t\t\t\t};\n\t\t\treturn hola;\n\t\t}\n\t}\n\tstatic class vector implements Iterable<Integer>\n\t{\n\t\tint a[],size;\n\t\tvector(){a=new int[10];size=0;}\n\t\tvector(int n){a=new int[n];size=0;}\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<Integer> iterator() {\n\t\t\tIterator<Integer> hola=new Iterator<Integer>()\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<size;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Integer next() {\n\t\t\t\t\t\t\treturn a[cur++];\n\t\t\t\t\t\t}\t\t\t\t\n\t\t\t\t\t};\n\t\t\treturn hola;\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 Integer.parseInt(in.next());}\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; i++)a[i]=ni();return a;}\n\tstatic int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}\n\tstatic long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}\n\tstatic String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}\n\tstatic double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}\n\t//////////////////////////////////\n\t//some utility functions\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 m){long an=1;long c=a;while(b>0){if(b%2==1)an=(an*c)%m;c=(c*c)%m;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), 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    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskA\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew TaskA(System.in, System.out);\n\t}\n\n\tstatic class Solver implements Runnable\n\t{\n\t\tint n;\n\t\tString[] last, curr;\n\t\tBufferedReader in;\n\t\tPrintWriter out;\n\n\t\tvoid solve() throws IOException\n\t\t{\n\t\t\tn = Integer.parseInt(in.readLine());\n\t\t\tlast = new String[n];\n\t\t\tcurr = new String[n];\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlast[i] = in.readLine();\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tcurr[i] = in.readLine();\n\n\t\t\tint changes = 0;\n\t\t\tString[] sizes = new String[]{\"S\", \"M\", \"L\", \"XS\", \"XXS\", \"XXXS\", \"XL\", \"XXL\", \"XXXL\"};\n\t\t\tint[] old = count(last, sizes);\n\t\t\tint[] now = count(curr, sizes);\n\n\t\t\tfor (int i= 0; i < sizes.length; i++)\n\t\t\t{\n\t\t\t\tchanges += Math.abs(old[i] - now[i]);\n\t\t\t}\n\n\t\t\tout.println(changes / 2);\n\n/*\t\t\tif (now[0] > old[0])\n\t\t\t{\n\t\t\t\tint add = now[0] - old[0];\n\n\t\t\t\tchanges += add;\n\n\n\t\t\t}*/\n\t\t}\n\n\t\tint[] count(String[] s, String[] sizes)\n\t\t{\n\t\t\tint len = sizes.length;\n\t\t\tint[] cnt = new int[len];\n\n\t\t\tfor (int i = 0; i < len; i++)\n\t\t\t{\n\t\t\t\tfor (String str : s)\n\t\t\t\t{\n\t\t\t\t\tif (str.equals(sizes[i]))\n\t\t\t\t\t\tcnt[i]++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn cnt;\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\tpublic Solver(BufferedReader 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 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 TaskA(InputStream inputStream, OutputStream outputStream)\n\t{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tThread thread = new Thread(null, new Solver(in, out), \"TaskA\", 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\ttry\n\t\t\t{\n\t\t\t\tin.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\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\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        ACodehorsesTShirts solver = new ACodehorsesTShirts();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ACodehorsesTShirts {\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            ArrayList<String>[] arrayLists = new ArrayList[5];\n            ArrayList<String>[] arrayLists1 = new ArrayList[5];\n            for (int i = 0; i < 5; i++) {\n                arrayLists[i] = new ArrayList<>();\n                arrayLists1[i] = new ArrayList<>();\n            }\n            for (int i = 0; i < n; i++) {\n                String s = in.scanString();\n                arrayLists[s.length()].add(s);\n            }\n            for (int i = 0; i < n; i++) {\n                String s = in.scanString();\n                arrayLists1[s.length()].add(s);\n            }\n            long ans = 0;\n            for (int i = 0; i < 5; i++) {\n                for (int diff = 0; diff < 5; diff++) {\n\n                    for (int j = 0; j < arrayLists[i].size(); j++) {\n                        int min = Integer.MAX_VALUE;\n                        int index = -1;\n                        for (int k = 0; k < arrayLists1[i].size(); k++) {\n                            int tt = 0;\n                            for (int l = 0; l < i; l++)\n                                if (arrayLists[i].get(j).charAt(l) != arrayLists1[i].get(k).charAt(l)) tt++;\n                            if (tt < min) {\n                                min = tt;\n                                index = k;\n                            }\n\n                        }\n                        if (min == diff) {\n                            arrayLists1[i].remove(index);\n                            ans += min;\n                        }\n                    }\n                }\n            }\n            out.println(ans);\n\n\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*; \nimport java.text.DecimalFormat;\n\npublic class Main{\n    final long mod = (int)1e9+7, IINF = (long)1e19;\n    final int MAX = (int)1e6+1, MX = (int)1e7+1, INF = (int)1e9, root = 3;\n    DecimalFormat df = new DecimalFormat(\"0.0000000000000\");\n    double eps = 1e-9;\n    FastReader in;\n    PrintWriter out;\n    static boolean multipleTC = false, memory = false;\n\n    public static void main(String[] args) throws Exception{\n        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n        else new Main().run();\n    }\n\n    void run() throws Exception{\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n        for(int i = 1, t = (multipleTC)?ni():1; i<=t; i++)solve(i);\n        out.flush();    \n        out.close();\n    }\n    \n    void solve(int TC)throws Exception{\n        int n = ni();\n        int[] f1 = new int[9], f2 = new int[9];\n        MyHashSet<String> set = new MyHashSet<>();\n        for(int i = 0; i< n; i++){\n            String s = n();\n            set.add(s);\n            f1[s.length()]++;\n        }\n        int[] f = new int[4];\n        for(int i = 0; i< n; i++){\n            String s = n();\n            if(set.remove(s))continue;\n            else f[s.length()-1]++;\n        }\n        int ans = 0;\n        for(int i = 0; i< 4; i++)ans+=f[i];\n        pn(ans);\n    }\n    \n    class MyHashSet<T>{\n        private int size;\n        private HashMap<T, Integer> map;\n        public MyHashSet(){\n            size = 0;\n            map = new HashMap<>();\n        }\n        public int size(){return size;}\n        public void add(T t){\n            size++;\n            map.put(t, map.getOrDefault(t, 0)+1);\n        }\n        public int cnt(T t){return map.getOrDefault(t,0);}\n        public boolean remove(T t){\n            if(!map.containsKey(t))return false;\n            size--;\n            int c = map.get(t);\n            if(c==1)map.remove(t);\n            else map.put(t, c-1);\n            return true;\n        }\n    }\n    \n    int[] reverse(int[] a){\n        int[] o = new int[a.length];\n        for(int i = 0; i< a.length; i++)o[i] = a[a.length-i-1];\n        return o;   \n    }\n\n    int[] sort(int[] a){\n        if(a.length==1)return a;\n        int mid = a.length/2;\n        int[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));\n        for(int i = 0, j = 0, k = 0; i< a.length; i++){\n            if(j<b.length && k<c.length){\n                if(b[j]<c[k])a[i] = b[j++];\n                else a[i] = c[k++];\n            }else if(j<b.length)a[i] = b[j++];\n            else a[i] = c[k++];\n        }\n        return a;\n    }\n\n    long[] sort(long[] a){\n        if(a.length==1)return a;\n        int mid = a.length/2;\n        long[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));\n        for(int i = 0, j = 0, k = 0; i< a.length; i++){\n            if(j<b.length && k<c.length){\n                if(b[j]<c[k])a[i] = b[j++];\n                else a[i] = c[k++];\n            }else if(j<b.length)a[i] = b[j++];\n            else a[i] = c[k++];\n        }\n        return a;\n    }\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 bitcount(long n){return (n==0)?0:(1+bitcount(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(){return in.next();}\n    String nln(){return in.nextLine();}\n    int ni(){return Integer.parseInt(in.next());}\n    long nl(){return Long.parseLong(in.next());}\n    double nd(){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(){\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        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}      ", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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.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 programajor\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            Map<String, Integer> map = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                String x = in.next();\n                map.put(x, map.getOrDefault(x, 0) + 1);\n            }\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                String x = in.next();\n                if (map.containsKey(x)) {\n                    map.put(x, map.get(x) - 1);\n                    if (map.get(x) == 0) {\n                        map.remove(x);\n                    }\n                } else {\n                    ans++;\n                }\n            }\n            out.print(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{\n    static MyScanner scan;\n    static PrintWriter pw;\n    public static void main(String[] args) {\n        new Thread(null,null,\"_\",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        scan = new MyScanner();\n        pw = new PrintWriter(System.out, true);\n        StringBuilder sb = new StringBuilder();\n        Map<String,Integer> map = new HashMap<>();\n        map.put(\"M\",0);\n        map.put(\"L\",1);\n        map.put(\"S\",2);\n        map.put(\"XL\",3);\n        map.put(\"XS\",4);\n        map.put(\"XXL\",5);\n        map.put(\"XXS\",6);\n        map.put(\"XXXL\",7);\n        map.put(\"XXXS\",8);\n        int freqa[] = new int[9];\n        int freqb[] = new int[9];\n        int n = ni();\n        for(int i=0;i<n;++i)\n            ++freqa[map.get(ne())];\n        for(int i=0;i<n;++i)\n            ++freqb[map.get(ne())];\n        for(int i=0;i<9;++i)\n        {\n            int xx = min(freqa[i],freqb[i]);\n            freqa[i]-=xx;\n            freqb[i]-=xx;\n        }\n        long res = 0;\n        for(int i=0;i<9;++i)\n            res+=freqa[i]+freqb[i];\n        pl(res/2);\n        pw.flush();\n        pw.close();\n    }\n    static long MMI(long A,long MOD)\n    {\n        return modpow(A,MOD-2,MOD);\n    }\n    static long modpow(long x,long y,long MOD)\n    {\n        if(y==0)\n            return 1;\n        if((y&1)==0)\n            return modpow((x*x)%MOD,y>>1,MOD);\n        else return (x*modpow(x,y-1,MOD))%MOD;\n    }\n    static class Pair implements Comparable<Pair>\n    {\n        int x,y;\n        Pair(int x,int y)\n        {\n            this.x=x;\n            this.y=y;\n        }\n        public int compareTo(Pair other)\n        {\n            if(this.x!=other.x)\n                return this.x-other.x;\n            return this.y-other.y;\n        }\n        public String toString()\n        {\n            return \"{\"+x+\",\"+y+\"}\";\n        }\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static String ne() throws IOException\n    {\n        return scan.next();\n    }\n    static String nel() throws IOException\n    {\n        return scan.nextLine();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static class MyScanner\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        MyScanner()\n        {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String nextLine()throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class q1\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[] arr1=new int[9];\n\t\tint[] arr2=new int[9];\n\t\tString ss;\n\t\ts.nextLine();\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tss=s.nextLine();\n\t\t\tif(ss.equals(\"M\"))\n\t\t\t\tarr1[0]++;\n\t\t\telse if(ss.equals(\"S\"))\n\t\t\t\tarr1[1]++;\n\t\t\telse if(ss.equals(\"L\"))\n\t\t\t\tarr1[2]++;\n\t\t\telse if(ss.equals(\"XS\"))\n\t\t\t\tarr1[3]++;\n\t\t\telse if(ss.equals(\"XL\"))\n\t\t\t\tarr1[4]++;\n\t\t\telse if(ss.equals(\"XXS\"))\n\t\t\t\tarr1[5]++;\n\t\t\telse if(ss.equals(\"XXL\"))\n\t\t\t\tarr1[6]++;\n\t\t\telse if(ss.equals(\"XXXS\"))\n\t\t\t\tarr1[7]++;\n\t\t\telse if(ss.equals(\"XXXL\"))\n\t\t\t\tarr1[8]++;\n\t\t}\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tss=s.nextLine();\n\t\t\tif(ss.equals(\"M\"))\n\t\t\t\tarr2[0]++;\n\t\t\telse if(ss.equals(\"S\"))\n\t\t\t\tarr2[1]++;\n\t\t\telse if(ss.equals(\"L\"))\n\t\t\t\tarr2[2]++;\n\t\t\telse if(ss.equals(\"XS\"))\n\t\t\t\tarr2[3]++;\n\t\t\telse if(ss.equals(\"XL\"))\n\t\t\t\tarr2[4]++;\n\t\t\telse if(ss.equals(\"XXS\"))\n\t\t\t\tarr2[5]++;\n\t\t\telse if(ss.equals(\"XXL\"))\n\t\t\t\tarr2[6]++;\n\t\t\telse if(ss.equals(\"XXXS\"))\n\t\t\t\tarr2[7]++;\n\t\t\telse if(ss.equals(\"XXXL\"))\n\t\t\t\tarr2[8]++;\n\t\t}\t\n\t\tint min;\n\t\tfor(int i=0;i<9;i++)\n\t\t{\n\t\t\tif(arr1[i]<arr2[i])\n\t\t\t\tmin=arr1[i];\n\t\t\telse\n\t\t\t\tmin=arr2[i];\n\t\t\tarr1[i]-=min;\n\t\t\tarr2[i]-=min;\n\t\t}\n\t\tint sum=0;\n\t\tfor(int i=0;i<9;i++)\n\t\t{\n\t\t\tsum+=arr1[i];\n\t\t}\n\t\tSystem.out.println(sum);\n\t\t//System.out.println(Arrays.toString(arr2));\n\t}\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\npublic class A{\n    \n    static int N, M, K;\n    static String s;\n    static StringTokenizer st;\n    static int[] d;\n    \n    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        \n        PrintWriter out = new PrintWriter(System.out);\n        \n        int[][] d = new int[5][3];\n        int[][] d2 = new int[5][3];\n        \n        int N = Integer.parseInt(br.readLine());\n        for (int i = 0; i < N; i++) {\n            String r = br.readLine();\n            int len = r.length();\n            int fin = 0;\n            if(r.charAt(r.length()-1) == 'S')\n                fin = 0;\n            if(r.charAt(r.length()-1) == 'M')\n                fin = 1;\n            if(r.charAt(r.length()-1) == 'L')\n                fin = 2;\n            d[len][fin]++;\n        }\n        \n        for (int i = 0; i < N; i++) {\n            String r = br.readLine();\n            int len = r.length();\n            int fin = 0;\n            if(r.charAt(r.length()-1) == 'S')\n                fin = 0;\n            if(r.charAt(r.length()-1) == 'M')\n                fin = 1;\n            if(r.charAt(r.length()-1) == 'L')\n                fin = 2;\n            d2[len][fin]++;\n        }\n        \n        int ans = 0;\n        for (int i = 0; i < d.length; i++) {\n            int sum = 0;\n            int sum2 = 0;\n            for (int j = 0; j < d[0].length; j++) {\n                sum += d[i][j];\n                sum2 += d2[i][j];\n                ans += Math.max(0, d2[i][j] - d[i][j]);\n            }\n            \n        }\n        System.out.println(ans);\n        out.close();\n    }    \n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class A {\n    public static void main(String[] args)throws Throwable {\n        MyScanner sc=new MyScanner();\n        PrintWriter pw=new PrintWriter(System.out);\n\n        int n=sc.nextInt();\n\n        String [] s={\"M\",\"L\",\"S\",\"XL\",\"XS\",\"XXL\",\"XXS\",\"XXXL\",\"XXXS\"};\n        int [] cnt=new int [9];\n        for(int i=0;i<n;i++){\n            String t=sc.next();\n            for(int j=0;j<9;j++)\n                if(t.equals(s[j]))\n                    cnt[j]++;\n        }\n        for(int i=0;i<n;i++){\n            String t=sc.next();\n            for(int j=0;j<9;j++)\n                if(t.equals(s[j]))\n                    cnt[j]--;\n        }\n        for(int i=0;i<9;i++)\n            cnt[i]=Math.abs(cnt[i]);\n        int ans=0;\n        for(int i=0;i<9;i++)\n            ans+=cnt[i];\n        pw.println(ans/2);\n        pw.flush();\n        pw.close();\n    }\n\n    static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {while (st == null || !st.hasMoreElements()) {\n            try {st = new StringTokenizer(br.readLine());}\n            catch (IOException e) {e.printStackTrace();}}\n            return st.nextToken();}\n        int nextInt() {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}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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\n    public void run() {\n        InputReader sc = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n=sc.nextInt();\n        String a[]=new String[n];\n        String b[]=new String[n];\n        int freaa[][]=new int[5][4];\n        for (int i = 0; i <n ; i++) {\n            a[i]=sc.next();\n            int ll=a[i].length();\n            for (int j = 0; j <a[i].length() ; j++) {\n                if(a[i].charAt(j)=='X')\n                    freaa[ll][0]++;\n                if(a[i].charAt(j)=='L')\n                    freaa[ll][1]++;\n                if(a[i].charAt(j)=='M')\n                    freaa[ll][2]++;\n                if(a[i].charAt(j)=='S')\n                    freaa[ll][3]++;\n            }\n        }\n        int frebb[][]=new int[5][4];\n        for (int i = 0; i <n ; i++) {\n            b[i]=sc.next();\n            int ll=b[i].length();\n            for (int j = 0; j <b[i].length() ; j++) {\n                if(b[i].charAt(j)=='X')\n                    frebb[ll][0]++;\n                if(b[i].charAt(j)=='L')\n                    frebb[ll][1]++;\n                if(b[i].charAt(j)=='M')\n                    frebb[ll][2]++;\n                if(b[i].charAt(j)=='S')\n                    frebb[ll][3]++;\n            }\n        }\n        int ans=0;\n        for (int i = 1; i <5 ; i++) {\n            for (int j = 0; j <4 ; j++) {\n                if(freaa[i][j]<frebb[i][j]){\n                    ans+=frebb[i][j]-freaa[i][j];\n                }\n            }\n        }\n        out.println(ans);\n        out.close();\n    }\n\n\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\n\npublic class JavaApplication2 {\n\n    \n    public static void main(String[] args) throws IOException {\n     \n        BufferedReader sc= new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(sc.readLine().split(\" \")[0]);\n        ArrayList<String> tshr = new ArrayList<>(n);\n        for (int i = 0; i < n; i++) {\n            tshr.add(sc.readLine());\n        }\n        for (int i = 0; i < n; i++) {\n            tshr.remove(sc.readLine());\n        }\n        System.out.println(tshr.size());\n        \n        \n        \n        \n        \n        \n    }\n    \n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _1000_A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tHashMap<String, Integer> map1 = new HashMap<>(), map2 = new HashMap<>(); int N = readInt();\n\t\tfor(int i = 1; i<=N; i++) {\n\t\t\tString s = read(); if(!map1.containsKey(s)) map1.put(s, 1); else map1.put(s, map1.get(s)+1);\n\t\t}\n\t\tint tot = 0; for(int i = 1; i<=N; i++) {\n\t\t\tString s = read(); if(!map2.containsKey(s)) map2.put(s, 1); else map2.put(s, map2.get(s)+1);\n\t\t}\n\t\tfor(String s : map2.keySet()) {\n\t\t\ttot += Math.max(0, map2.get(s) - (map1.containsKey(s) ? map1.get(s) : 0));\n\t\t}\n\t\tprintln(tot); exit();\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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class n2{\n    public static void main(String[] args) throws Exception{\n        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n        int n=Integer.parseInt(in.readLine());\n        int[] S=new int[4];\n        int[] L=new int[4];\n        int m=0;\n        for(int i=0;i<n;i++){\n            String s=in.readLine();\n            if(s.charAt(s.length()-1)=='L'){\n                L[s.length()-1]++;\n            }\n            if(s.charAt(s.length()-1)=='S'){\n                S[s.length()-1]++;\n            }\n            if(s.charAt(s.length()-1)=='M'){\n                m++;\n            }\n        }\n        for(int i=0;i<n;i++){\n            String s=in.readLine();\n            if(s.charAt(s.length()-1)=='L'){\n                L[s.length()-1]--;\n            }\n            if(s.charAt(s.length()-1)=='S'){\n                S[s.length()-1]--;\n            }\n            if(s.charAt(s.length()-1)=='M'){\n                m--;\n            }\n        }\n        int count=0;\n        for(int i=0;i<=3;i++){\n            if(S[i]>0){\n                count+=S[i];\n            }\n            if(L[i]>0){\n                count+=L[i];\n            }\n        }\n        if(m>0){\n            count+=m;\n        }\n        System.out.println(count);\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\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\n    public static int read() throws IOException {\n        tokenizer.nextToken();\n        return (int) tokenizer.nval;\n    }\n\n    public static void main(String[] args) throws IOException {\n        Scanner scanner=new Scanner(System.in);\n        int n=scanner.nextInt();\n        ArrayList<String> list1=new ArrayList<String>();\n        ArrayList<String> list2=new ArrayList<String>();\n        for (int i=0; i<n; i++){\n            String s=scanner.next();\n            list1.add(s);\n        }\n        for (int i=0; i<n; i++){\n            String s=scanner.next();\n            list2.add(s);\n        }\n        for (int i=0; i<list1.size(); i++){\n            for (int j=0; j<list2.size(); j++){\n                if (list1.get(i).equals(list2.get(j))){\n                    list1.remove(i);\n                    list2.remove(j);\n                    i--;\n                    break;\n                }\n            }\n        }\n        System.out.println(list1.size());\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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.HashMap;\nimport java.util.Map;\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\tString[]a = new String[n], b = new String[n];\n\t\tMap<String, Integer> map = new HashMap<String, Integer>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = next();\n\t\t\tif (!map.containsKey(a[i]))\n\t\t\t\tmap.put(a[i], 0);\n\t\t\tmap.put(a[i], map.get(a[i])+1);\n\t\t}\n\t\tint  ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = next();\n\t\t\tif (!map.containsKey(b[i]))\n\t\t\t\tans++;\n\t\t\telse {\n\t\t\t\tmap.put(b[i], map.get(b[i])-1);\n\t\t\t\tif (map.get(b[i])==0)\n\t\t\t\t\tmap.remove(b[i]);\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}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "/*\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    void solve() throws IOException {\n        int n = nextInt();\n        String[] arr1 = new String[n];\n        String[] arr2 = new String[n];\n        for (int i = 0; i < n; i++) {\n            arr1[i] = nextString();\n        }\n        for (int i = 0; i < n; i++) {\n            arr2[i] = nextString();\n        }\n        Map<String, Integer> m1 = getMap(arr1);\n        Map<String, Integer> m2 = getMap(arr2);\n        int res = 0;\n        for (Map.Entry<String, Integer> entry : m2.entrySet()) {\n            String key = entry.getKey();\n            int val = entry.getValue();\n            if (m1.containsKey(key)) {\n                int v2 = m1.get(key);\n                if (val > v2) {\n                    res += val - v2;\n                }\n            }\n            else {\n                res += val;\n            }\n        }\n\n        for (Map.Entry<String, Integer> entry : m1.entrySet()) {\n            String key = entry.getKey();\n            int val = entry.getValue();\n            if (m2.containsKey(key)) {\n                int v2 = m2.get(key);\n                if (val > v2) {\n                    res += val - v2;\n                }\n            }\n            else {\n                res += val;\n            }\n        }\n\n        outln(res / 2);\n    }\n\n    Map<String, Integer> getMap(String[] arr) {\n        Map<String, Integer> res = new HashMap<>();\n        for (String str : arr) {\n            res.put(str, res.getOrDefault(str, 0) + 1);\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    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        outln(String.format(\"%.9f%n\", val));\n    }\n    public CFA() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\n    }\n    public static void main(String[] args) throws IOException {\n        new CFA();\n    }\n\n    public long[] nextLongArr(int n) throws IOException{\n        long[] res = new long[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextLong();\n        return res;\n    }\n    public int[] nextIntArr(int n) throws IOException {\n        int[] res = new int[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextInt();\n        return res;\n    }\n    public String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return null;\n            }\n        }\n        return st.nextToken();\n    }\n    public String nextString() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            eof = true;\n            return null;\n        }\n    }\n    public int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n    public long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n    public double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\n\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Test5 {\n    public static void main(String[] z){\n        StreamTokenizer st = new StreamTokenizer(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(System.out);\n        Scanner s = new Scanner(System.in);\n        int a = s.nextInt(), o=0;\n        String i = \"\";\n        ArrayList<String> l1 = new ArrayList<>(), l2 = new ArrayList<>();\n        for(int q=0; q<a; q++){\n            l1.add(s.next());\n        }\n        for(int q=0; q<a; q++){\n            i = s.next();\n            if(l1.contains(i)) l1.remove(i);\n            else l2.add(i);\n        }\n        Collections.sort(l1);\n        Collections.sort(l2);\n\n        for(int q=0; q<l1.size(); q++){\n            if(l1.get(q).charAt(l1.get(q).length()-1)!=l2.get(q).charAt(l2.get(q).length()-1)) o++;\n        }\n        System.out.println(o);\n        pw.flush();\n    }\n\n    static class PyraSort {\n\n        private static int heapSize;\n\n        public static void sort(int[] 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(int[] 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(int[] 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(int[] a, int i, int j) {\n            a[i] ^= a[j] ^= a[i];\n            a[j] ^= a[i];\n        }\n    }\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.util.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tJS in = new JS();\n\t\tint n = in.nextInt();\n\t\tint m1 = 0;\n\t\tint s1 = 0;\n\t\tint l1 = 0;\n\t\tint ss1 = 0;\n\t\tint sss1 = 0;\n\t\tint ssss1 = 0;\n\t\tint ll1 = 0;\n\t\tint lll1 = 0;\n\t\tint llll1 = 0;\n\t\t\n\t\tint m2 = 0;\n\t\tint s2 = 0;\n\t\tint l2 = 0;\n\t\tint ss2 = 0;\n\t\tint sss2 = 0;\n\t\tint ssss2 = 0;\n\t\tint ll2 = 0;\n\t\tint lll2 = 0;\n\t\tint llll2 = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\tif(s.equals(\"S\")) s1++;\n\t\t\telse if(s.equals(\"M\"))m1++;\n\t\t\telse if(s.equals(\"L\"))l1++;\n\t\t\telse if(s.equals(\"XS\")) ss1++;\n\t\t\telse if(s.equals(\"XXS\")) sss1++;\n\t\t\telse if(s.equals(\"XXXS\")) ssss1++;\n\t\t\telse if(s.equals(\"XL\")) ll1++;\n\t\t\telse if(s.equals(\"XXL\")) lll1++;\n\t\t\telse if(s.equals(\"XXXL\")) llll1++;\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\tif(s.equals(\"S\")) s2++;\n\t\t\telse if(s.equals(\"M\"))m2++;\n\t\t\telse if(s.equals(\"L\"))l2++;\n\t\t\telse if(s.equals(\"XS\")) ss2++;\n\t\t\telse if(s.equals(\"XXS\")) sss2++;\n\t\t\telse if(s.equals(\"XXXS\")) ssss2++;\n\t\t\telse if(s.equals(\"XL\")) ll2++;\n\t\t\telse if(s.equals(\"XXL\")) lll2++;\n\t\t\telse if(s.equals(\"XXXL\")) llll2++;\n\t\t}\n\t\t\n\t\tint res = 0;\n\t\tint res1 = 0;\n\n\t\t\n\t\tres1 += Math.abs(m2-m1);\n\t\tres1 += Math.abs(s2-s1);\n\t\tres1 += Math.abs(l2-l1);\n\t\tres += res1/2;\n\t\tres1 = 0;\n\t\t\n\t\tres1 += Math.abs(ss2-ss1);\n\t\tres1 += Math.abs(ll2-ll1);\n\t\tres += res1/2;\n\t\tres1 = 0;\n\t\t\n\t\tres1 += Math.abs(sss2-sss1);\n\t\tres1 += Math.abs(lll2-lll1);\n\t\tres += res1/2;\n\t\tres1 = 0;\n\t\t\n\t\tres1 += Math.abs(ssss2-ssss1);\n\t\tres1 += Math.abs(llll2-llll1);\n\t\tres += res1/2;\n\t\tres1 = 0;\n\t\tSystem.out.println(res);\n\t\t\n\t\t\n\t}\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\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}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\n//package que_a;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n    InputStream is;\n    PrintWriter out;\n    \n    long mod = (long) (1e9 + 7);\n    boolean SHOW_TIME;\n    \n    void solve() {\n        //Enter code here utkarsh\n        //SHOW_TIME = true;\n        int n = ni();\n        HashMap <String, Integer> mp = new HashMap<>();\n        mp.put(\"M\", 0);\n        mp.put(\"S\", 1); mp.put(\"XS\", 2); mp.put(\"XXS\", 3); mp.put(\"XXXS\", 4);\n        mp.put(\"L\", 5); mp.put(\"XL\", 6); mp.put(\"XXL\", 7); mp.put(\"XXXL\", 8);\n        int a[] = new int[10];\n        for(int i = 0; i < n; i++) {\n            int j = mp.get(ns());\n            a[j]++;\n        }\n        for(int i = 0; i < n; i++) {\n            int j = mp.get(ns());\n            a[j]--;\n        }\n        int ans = 0;\n        for(int i = 0; i < 10; i++) {\n            if(a[i] > 0)    ans += a[i];\n        }\n        out.println(ans);\n    }\n\n    //---------- I/O Template ----------\n    \n    public static void main(String[] args) { new utkarsh().run(); }\n    void run() { \n        is = System.in; \n        out = new PrintWriter(System.out);\n        long start = System.currentTimeMillis(); \n        solve(); \n        long end = System.currentTimeMillis();\n        if(SHOW_TIME) out.println(\"\\n\" + (end - start) + \" ms\");\n        out.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte() { \n        if(ptr >= len) { ptr = 0; \n            try { len = is.read(input); } \n            catch(IOException e) { throw new InputMismatchException(); } \n            if(len <= 0) { return -1; } \n        } return input[ptr++];\n    }\n    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n    int skip() { \n        int b = readByte(); \n        while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n        return b;\n    }\n    \n    char nc() { return (char)skip(); }\n    String ns() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    String nLine() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    int ni() { \n        int n = 0, b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        if(b == -1) { return -1; }  //no input \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n    long nl() { \n        long n = 0L;    int b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n\n    double nd() { return Double.parseDouble(ns()); }\n    float nf() { return Float.parseFloat(ns()); }\n    int[] na(int n) { \n        int a[] = new int[n]; \n        for(int i = 0; i < n; i++) { a[i] = ni(); } \n        return a;\n    }\n    char[] ns(int n) { \n        char c[] = new char[n]; \n        int i, b = skip(); \n        for(i = 0; i < n; i++) { \n            if(isSpaceChar(b)) { break; } \n            c[i] = (char)b; b = readByte(); \n        } return i == n ? c : Arrays.copyOf(c,i);\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Collections;\nimport java.util.HashSet;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tArrayList<String> s1=new ArrayList<String> ();\n\t\tArrayList<String> s2=new ArrayList<String> ();\n\t\t\tArrayList<String> s3=new ArrayList<String> ();\n\t\t\tint i;\n\t\tfor(i=0;i<n;i++)\n\t\ts1.add(sc.next());\n\t\t\n\t\tfor(i=0;i<n;i++)\n\t\ts2.add(sc.next());\n\t\ts3.addAll(s2);\n\t\tfor(i=0;i<n;i++)\n\t\t{\n\t\t\tif(s2.contains(s1.get(i)))\n\t\t\ts3.remove(s1.get(i));\n\t\t\t\n\t\t\t\n\t\t}\n\tSystem.out.println(s3.size());\n\t\t\n\t}\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\n// import java.io.FileInputStream;\n// import java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.*;\n\nimport static java.lang.Math.abs;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.copyOf;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.sort;\n// import static java.util.Collections.sort;\nimport static java.util.Comparator.comparingInt;\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    private void solve() throws IOException {\n        solveA();\n        // solveB();\n        // solveC();\n        // solveD();\n        // solveE();\n        // solveF();\n    }\n\n    private void solveA() throws IOException {\n        int n = in.nextInt();\n        TreeMap<String, Integer> map = new TreeMap<>();\n        for (int i = 0; i < n; i++) {\n            String s = in.next();\n            map.put(s, map.getOrDefault(s, 0) + 1);\n        }\n        for (int i = 0; i < n; i++) {\n            String s = in.next();\n            map.put(s, map.getOrDefault(s, 0) - 1);\n        }\n        long ans = 0;\n        for (String i : map.keySet())\n            ans += abs(map.get(i));\n        out.println(ans / 2);\n    }\n\n    private void solveB() throws IOException {\n        int n = in.nextInt();\n        int time = (int) 1e9, ans = -1;\n        for (int i = 0; i < n; i++) {\n            int a = in.nextInt() - i;\n            if ((a + (n - 1)) / n < time) {\n                time = (a + (n - 1)) / n;\n                ans = i;\n            }\n        }\n        out.println(ans + 1);\n    }\n\n    class PairC {\n        int i, j;\n\n        PairC(int i, int j) {\n            this.i = i;\n            this.j = j;\n        }\n\n        public String toString() {\n            return \"(\" + i + \", \" + j + \")\";\n        }\n    }\n\n    private void solveC() throws IOException {\n        int n = in.nextInt(), k = in.nextInt();\n        int[][] a = new int[4][n];\n        for (int i = 0; i < 4; i++)\n            for (int j = 0; j < n; j++)\n                a[i][j] = in.nextInt() - 1;\n\n        int[] empty = new int[4];\n\n        PairC[] from = new PairC[k];\n        for (int i = 1; i < 3; i++)\n            for (int j = 0; j < n; j++)\n                if (a[i][j] != -1)\n                    from[a[i][j]] = new PairC(i, j);\n                else\n                    empty[i]++;\n\n        PairC[] to = new PairC[k];\n        for (int i = 0; i < 4; i += 3)\n            for (int j = 0; j < n; j++)\n                if (a[i][j] != -1)\n                    to[a[i][j]] = new PairC(i, j);\n\n        out.println(Arrays.toString(from));\n        out.println(Arrays.toString(to));\n\n        ArrayList<int[]> ans = new ArrayList<>();\n\n        int cnt = 0;\n\n        for (int i = 0; i < k; i++) {\n            if (abs(from[i].i - to[i].i) == 1) {\n                if (from[i].j == to[i].j) {\n                    ans.add(new int[]{i, to[i].i, to[i].j});\n                    a[from[i].i][from[i].j] = 0;\n                    empty[from[i].i]++;\n                    cnt++;\n                }\n            } else if (from[i].j == to[i].j && a[(from[i].i + to[i].i) / 2][to[i].j] == 0) {\n                ans.add(new int[]{i, (from[i].i + to[i].i) / 2, to[i].j});\n                ans.add(new int[]{i, to[i].i, to[i].j});\n                a[from[i].i][from[i].j] = 0;\n                empty[from[i].i]++;\n                cnt++;\n            }\n        }\n\n        for (int i = 1; i < 3; i++) {\n            if (empty[i] > 0) {\n                for (int j = 0; j < k; j++) {\n                    if (from[j].i == i && true) {\n\n                    }\n                }\n            }\n        }\n\n\n        while (true) {\n            boolean flag = false;\n\n            for (int i = 0; i < k; i++) {\n                if (abs(from[i].i - to[i].i) == 1 && abs(from[i].j - to[i].j) <= empty[i]) {\n\n                }\n            }\n\n            if (!flag)\n                break;\n        }\n\n        if (cnt == k) {\n            out.println(ans.size());\n            for (int[] i : ans) {\n                for (int j : i)\n                    out.print(j + 1 + \" \");\n                out.println();\n            }\n        } else\n            out.println(-1);\n    }\n\n    private void solveD() throws IOException {\n        int n = in.nextInt();\n        int[] a = new int[n * 2];\n        for (int i = 0; i < n * 2; i++)\n            a[i] = in.nextInt();\n        long ans = 0;\n        for (int i = 0; i < 2 * n; i += 2) {\n            int j = i + 1;\n            while (a[i] != a[j])\n                j++;\n            ans += j - i - 1;\n            while (j > i + 1)\n                a[j] = a[--j];\n        }\n        out.println(ans);\n    }\n\n    class PairE implements Comparable<PairE> {\n        long x, y;\n        int id;\n        boolean b;\n\n        PairE(long x, long y, int id) {\n            this.x = x;\n            this.y = y;\n            this.id = id;\n            b = false;\n        }\n\n        @Override\n        public int compareTo(PairE o) {\n            return x != o.x ? Long.compare(x, o.x) : Long.compare(y, o.y);\n        }\n    }\n\n    private void solveE() throws IOException {\n        int n = in.nextInt();\n        PairE[] p = new PairE[n];\n        for (int i = 0; i < n; i++)\n            p[i] = new PairE(in.nextLong(), in.nextLong(), i);\n\n        shuffle(p);\n        sort(p);\n\n        long X = 0, Y = 0;\n        long max = 225 * (long) 1e10;\n        for (int i = 0; i < n; i++) {\n            if ((X + p[i].x) * (X + p[i].x) + (Y + p[i].y) * (Y + p[i].y) < (X - p[i].x) * (X - p[i].x) + (Y - p[i].y) * (Y - p[i].y)) {\n                p[i].b = true;\n                X += p[i].x;\n                Y += p[i].y;\n            } else {\n                p[i].b = false;\n                X -= p[i].x;\n                Y -= p[i].y;\n            }\n        }\n\n        sort(p, comparingInt(o -> o.id));\n        for (int i = 0; i < n; i++) {\n            out.print(p[i].b ? 1 : -1);\n            if (i + 1 < n)\n                out.print(\" \");\n        }\n        out.println();\n    }\n\n    void shuffle(PairE[] a) {\n        PairE b;\n        Random r = new Random();\n        for (int i = a.length - 1, j; i > 0; i--) {\n            j = r.nextInt(i + 1);\n            b = a[j];\n            a[j] = a[i];\n            a[i] = b;\n        }\n    }\n\n    private void solveF() throws IOException {\n\n    }\n\n    class FastScanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        FastScanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        String next() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n\n        boolean hasNext() throws IOException {\n            return br.ready() || (st != null && st.hasMoreTokens());\n        }\n\n        int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() throws IOException {\n            return Double.parseDouble(next().replace(',', '.'));\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n\n        boolean hasNextLine() throws IOException {\n            return br.ready();\n        }\n    }\n\n    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}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class A {\n    public static void main(String[] args) throws Exception {\n        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n        // Scanner scan = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        int n = Integer.parseInt(bf.readLine());\n        ArrayList<String> s1 = new ArrayList<String>();\n        ArrayList<String> s2 = new ArrayList<String>();\n        for(int i=0; i<n; i++) s1.add(bf.readLine());\n        for(int i=0; i<n; i++) s2.add(bf.readLine());\n\n        Map<String, Integer> mp1 = new HashMap<String, Integer>();\n        Map<String, Integer> mp2 = new HashMap<String, Integer>();\n        for(String s : s1) mp1.put(s, 0);\n        for(String s : s1) mp1.put(s, mp1.get(s)+1);\n        for(String s : s2) mp2.put(s, 0);\n        for(String s : s2) mp2.put(s, mp2.get(s)+1);\n        for(String s : mp1.keySet()) {\n          while(mp1.get(s) > 0) {\n            if(mp2.containsKey(s)) {\n\n              if(mp2.get(s) > 0) {\n                mp1.put(s, mp1.get(s)-1);\n                mp2.put(s, mp2.get(s)-1);\n              }\n              else break;\n            }\n            else break;\n          }\n\n        }\n        for(String s : mp2.keySet()) {\n          while(mp2.get(s) > 0) {\n            if(mp1.containsKey(s)) {\n\n              if(mp1.get(s) > 0) {\n                mp2.put(s, mp2.get(s)-1);\n                mp1.put(s, mp1.get(s)-1);\n              }\n              else break;\n            }\n            else break;\n          }\n\n        }\n        long sum = 0;\n        for(String s : mp1.keySet()) sum += mp1.get(s);\n        out.println(sum);\n        //out.println(mp1.keySet().size());\n      //  out.close();\n\n        // StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        // int n = Integer.parseInt(st.nextToken());\n        // int n = scan.nextInt();\n\n        out.close(); System.exit(0);\n    }\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.Writer;\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 palayutm\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        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            String[] a = new String[n];\n            String[] b = new String[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.next();\n            }\n            for (int i = 0; i < n; i++) {\n                b[i] = in.next();\n            }\n            int ans = 0;\n            for (int i = 1; i < 5; i++) {\n                int a1 = 0, b1 = 0, c1 = 0;\n                for (int j = 0; j < n; j++) {\n                    if (a[j].length() == i) {\n                        if (a[j].charAt(i - 1) == 'M') {\n                            a1++;\n                        } else if (a[j].charAt(i - 1) == 'S') {\n                            b1++;\n                        } else {\n                            c1++;\n                        }\n                    }\n                }\n                for (int j = 0; j < n; j++) {\n                    if (b[j].length() == i) {\n                        if (b[j].charAt(i - 1) == 'M') {\n                            a1--;\n                        } else if (b[j].charAt(i - 1) == 'S') {\n                            b1--;\n                        } else {\n                            c1--;\n                        }\n                    }\n                }\n                if (a1 > 0) ans += a1;\n                if (b1 > 0) ans += b1;\n                if (c1 > 0) ans += c1;\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0;\n        private int ptrbuf = 0;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int readByte() {\n            if (lenbuf == -1) throw new UnknownError();\n            if (ptrbuf >= lenbuf) {\n                ptrbuf = 0;\n                try {\n                    lenbuf = stream.read(inbuf);\n                } catch (IOException e) {\n                    throw new UnknownError();\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        public 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        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = num * 10 + (b - '0');\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n    }\n\n    static class OutputWriter extends PrintWriter {\n        public OutputWriter(OutputStream out) {\n            super(out);\n        }\n\n        public OutputWriter(Writer out) {\n            super(out);\n        }\n\n        public void close() {\n            super.close();\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Rishabhdeep Singh\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        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, OutputWriter out) {\n            int n = in.nextInt();\n            int[] cnt = new int[10];\n            Arrays.fill(cnt, 0);\n            List<String> a = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                a.add(in.readLine());\n            }\n            List<String> b = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                String temp = in.readLine();\n                if (a.contains(temp)) {\n                    a.remove(temp);\n                } else\n                    b.add(temp);\n            }\n            int[] cnta = new int[10];\n            for (int i = 0; i < a.size(); i++) {\n                cnta[a.get(i).length()]++;\n            }\n            int[] cntb = new int[10];\n            Arrays.fill(cnta, 0);\n            Arrays.fill(cntb, 0);\n            for (int i = 0; i < b.size(); i++) {\n                cntb[a.get(i).length()]++;\n            }\n            int ans = 0;\n            for (int i = 0; i < 10; i++) {\n                ans += Math.abs(cnta[i] - cntb[i]);\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        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 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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "//package jsr.codeforces;\n\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class AMatchLists {\n\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int N = in.nextInt();\n        HashMap<String, Integer> map = new HashMap<>();\n        for(int i=0; i<N; i++){\n            String str = in.next();\n            if(map.get(str)==null){\n                map.put(str, 0);\n            }\n            map.put(str, map.get(str)+1);\n        }\n\n        HashMap<String, Integer> map2 = new HashMap<>();\n        for(int i=0; i<N; i++){\n            String str = in.next();\n            if(map.get(str)!=null){\n                if(map.get(str)==1)\n                    map.remove(str);\n                else\n                    map.put(str, map.get(str)-1);\n            }\n            else{\n                if(map2.get(str)==null){\n                    map2.put(str, 0);\n                }\n                map2.put(str, map2.get(str)+1);\n            }\n        }\n        int[] count= {0};\n\n        map2.forEach((key, value)->{\n                count[0] += value;\n                });\n\n        System.out.println(count[0]);\n\n        //M, XS, XXS, XXXS, L, XL, XXl, XXXL\n    }\n\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n    void solve(){\n        int n=ni();\n        int c1[]=new int[9];\n        int c2[]=new int[9];\n        for(int i=0;i<n;i++){\n            String s=ns();\n            if(s.equals(\"M\")) c1[0]++;\n            else if(s.equals(\"S\")) c1[1]++;\n            else if(s.equals(\"L\")) c1[2]++;\n            else if(s.equals(\"XS\")) c1[3]++;\n            else if(s.equals(\"XL\")) c1[4]++;\n            else if(s.equals(\"XXS\")) c1[5]++;\n            else if(s.equals(\"XXL\")) c1[6]++;\n            else if(s.equals(\"XXXS\")) c1[7]++;\n            else if(s.equals(\"XXXL\")) c1[8]++;\n        }\n        for(int i=0;i<n;i++){\n            String s=ns();\n            if(s.equals(\"M\")) c2[0]++;\n            else if(s.equals(\"S\")) c2[1]++;\n            else if(s.equals(\"L\")) c2[2]++;\n            else if(s.equals(\"XS\")) c2[3]++;\n            else if(s.equals(\"XL\")) c2[4]++;\n            else if(s.equals(\"XXS\")) c2[5]++;\n            else if(s.equals(\"XXL\")) c2[6]++;\n            else if(s.equals(\"XXXS\")) c2[7]++;\n            else if(s.equals(\"XXXL\")) c2[8]++;\n        }\n        int ans=0;\n        for(int i=0;i<9;i++){\n            if(c2[i]<c1[i]) ans+=c1[i]-c2[i];\n        }\n        pw.println(ans);\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    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}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*; \nimport static java.util.Arrays.*;\nimport static java.lang.Character.*;\nimport static java.lang.Double.*;\n\n\npublic class A {\n\n\tScanner scan = new Scanner(System.in);\n\t\n\t\n\tvoid solve() {\n\t\tint n = scan.nextInt();\n\t\tString[]A = new String[n];\n\t\tString[]B = new String[n];\n\t\tint res =0;\n\t\tfor(int i=0;i<n;i++)A[i]=scan.next();\n\t\tfor(int i=0;i<n;i++)B[i]=scan.next();\n\t\tfor(int i=0;i<A.length;i++) {\n\t\t\tboolean fnd = false;\n\t\t\tfor(int j=0;j<B.length;j++) {\n\t\t\t\tif(A[i].equals(B[j])) {\n\t\t\t\t\tfnd = true;\n\t\t\t\t\tB[j]=\"\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!fnd)res++;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A().solve();\n\t}\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "// //package ;\nimport java.io.*;\nimport java.util.*;\n\npublic class A\n{\n\tpublic static int sol(String n,String p)\n\t{\n\t\tint sol=0;\n\t\tfor(int i=0;i<n.length();i++)\n\t\t{\n\t\t\tif(n.charAt(i)!=p.charAt(i))\n\t\t\t\tsol++;\n\t\t}\n\t\treturn sol;\n\t}\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n=sc.nextInt();\n\t\tArrayList<String>p=new ArrayList<>();\n\t\tArrayList<String>ne=new ArrayList<>();\n\t\tfor(int i=0;i<n;i++)\n\t\t\tp.add(sc.nextLine());\n\t\tfor(int i=0;i<n;i++)\n\t\t{\t\n\t\t\tString t=sc.nextLine();\n\t\t\tif(p.contains(t))\n\t\t\t\tp.remove(t);\n\t\t\telse\n\t\t\t\tne.add(t);\n\t\t}\n\t\tCollections.sort(p);\n\t\tCollections.sort(ne);\n\t\tint ans=0;\n\t\tfor(int i=0;i<ne.size();i++)\n\t\t{\n\t\t\tans+=sol(ne.get(i),p.get(i));\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tpw.close();    \n\t}\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tlong nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tdouble nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\t\tboolean hasnext() throws IOException{\n\t\t\treturn br.ready();\n\t\t}\n\t\t\n\t}\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "/* \n * UMANG PANCHAL\n * DAIICT\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.Comparator;\npublic class Main\n{\n \n\tprivate static final Comparator<? super Integer> Comparator = null;\n\tstatic LinkedList<Integer> adj[];\n\tstatic ArrayList<Integer> adj1[];\n\tstatic int[] color,visited1;\n\tstatic boolean b[],visited[],possible;\n\tstatic int level[];\n\tstatic Map<Integer,HashSet<Integer>> s;\n\tstatic int totalnodes,colored;\n\tstatic int count[];\n\tstatic long sum[];\n\tstatic int nodes;\n\tstatic long ans=0;\n\tstatic long[] as=new long[10001];\n\tstatic long c1=0,c2=0;\n\tstatic int[] a,d,k;\n\tstatic int max=100000000;\n\tstatic long MOD = 1000000007,sm=0,m=Long.MIN_VALUE;\n\tstatic boolean[] prime=new boolean[1000005];\n\tstatic int[] levl;\n    static int[] eat;\n    static int price[];\n    static int res[],par[],co[];\n    static int result=0;\n    static int[] root,size,du,dv;\n    static long p=Long.MAX_VALUE;\n    static int start,end,r=0;\n    static boolean[] vis1,vis2;\n    static int to;\n    static HashMap<Pair,Integer> hs;\n    static boolean ns;\n    static Node head;\n    static String st,t;\n    static long n;\n  \n\t// --------------------My Code Starts Here----------------------\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tin=new InputReader(System.in);\n\t    w=new PrintWriter(System.out);\n\n\t   int n=ni();\n\t   HashMap<String,Integer> hm=new HashMap<String,Integer>();\n\t   for(int i=0;i<n;i++)\n\t   {\n\t\t   String s=ns();\n\t\t   if(hm.containsKey(s))\n\t\t\t   hm.put(s,hm.get(s)+1);\n\t\t   else\n\t\t\t   hm.put(s,1);\n\t   }\n\t    \n\t   int ans=0;\n\t   for(int i=0;i<n;i++)\n\t   {\n\t\t   String s=ns();\n\t\t   if(hm.containsKey(s))\n\t\t   {\n\t\t\t   if(hm.get(s)==1)\n\t\t\t\t   hm.remove(s);\n\t\t\t   else\n\t\t\t\t   hm.put(s,hm.get(s)-1);\n\t\t   }\n\t\t   else\n\t\t   {\n\t\t\t   ans++;\n\t\t\t/*   if(s.length()==1)\n\t\t\t   {\n\t\t\t\t   if(s.equals(\"M\"))\n\t\t\t\t   {\n\t\t\t\t\t   if(hm.containsKey(\"S\"))\n\t\t\t\t\t   {\n\t\t\t\t\t\t   if(hm.get(\"S\")==1)\n\t\t\t\t\t\t\t   hm.remove(\"S\");\n\t\t\t\t\t\t   else\n\t\t\t\t\t\t\t   hm.put(s,hm.get(\"S\")-1);\n\t\t\t\t\t   }\n\t\t\t\t\t   else if(hm.containsKey(\"L\"))\n\t\t\t\t\t   {\n\t\t\t\t\t\t   if(hm.get(\"L\")==1)\n\t\t\t\t\t\t\t   hm.remove(\"L\");\n\t\t\t\t\t\t   else\n\t\t\t\t\t\t\t   hm.put(s,hm.get(\"L\")-1);\n\t\t\t\t\t   }\n\t\t\t\t   }\n\t\t\t\t   else if()\n\t\t\t\t   \n\t\t\t   }*/\n\t\t   }\n\t   }\n\t   w.print(ans);\n       w.close();\n\t}\n\t\n\t\n\t\n\t// --------------------My Code Ends Here------------------------\n\n\tpublic static void dfs(int n,boolean[] vis,int cl,int[] c)\n\t{\n\t\n\t\tvis[n]=true;\n\t\tif(c[n]!=cl)\n\t\t\tns=false;\n\t\tfor(int i:adj[n])\n\t\t{\n\t\t\tif(!vis[i])\n\t\t\t{\n\t\t\t\t dfs(i,vis,cl,c);\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\n\tstatic 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\t\n\tpublic static long kadane(long[] a,int n)\n\t{\n\t\t long max_here=0,max_so_far=-Long.MAX_VALUE;\n\t        for(int i=0;i<n;i++)\n\t        {\n\t        \t if(max_here<0)\n\t                   max_here=0;\n\t        \t\n\t        \t max_here+=a[i];\n\t          \n\t             \n\t      \n\t           if(max_here>max_so_far)\n\t                    max_so_far=max_here;\n\t          \n\t                  \n\t        }\n\t\treturn max_so_far;\n\t}\n\tpublic static class SegmentTreeRMQ\n\t{\n\t    int st[]; //array to store segment tree\n\t \n\t    // A utility function to get minimum of two numbers\n\t    int minVal(int x, int y) {\n\t        return (x < y) ? y : x;\n\t    }\n\t \n\t    // A utility function to get the middle index from corner\n\t    // indexes.\n\t    int getMid(int s, int e) {\n\t        return s + (e - s) / 2;\n\t    }\n\t \n\t    /*  A recursive function to get the minimum value in a given\n\t        range of array indexes. The following are parameters for\n\t        this function.\n\t \n\t        st    --> Pointer to segment tree\n\t        index --> Index of current node in the segment tree. Initially\n\t                   0 is passed as root is always at index 0\n\t        ss & se  --> Starting and ending indexes of the segment\n\t                     represented by current node, i.e., st[index]\n\t        qs & qe  --> Starting and ending indexes of query range */\n\t    int RMQUtil(int ss, int se, int qs, int qe, int index)\n\t    {\n\t        // If segment of this node is a part of given range, then\n\t        // return the min of the segment\n\t        if (qs <= ss && qe >= se)\n\t            return st[index];\n\t \n\t        // If segment of this node is outside the given range\n\t        if (se < qs || ss > qe)\n\t            return Integer.MIN_VALUE;\n\t \n\t        // If a part of this segment overlaps with the given range\n\t        int mid = getMid(ss, se);\n\t        return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1),\n\t                RMQUtil(mid + 1, se, qs, qe, 2 * index + 2));\n\t    }\n\t \n\t    // Return minimum of elements in range from index qs (quey\n\t    // start) to qe (query end).  It mainly uses RMQUtil()\n\t    int RMQ(int n, int qs, int qe)\n\t    {\n\t        // Check for erroneous input values\n\t        if (qs < 0 || qe > n-1 || qs > qe) {\n\t            System.out.println(\"Invalid Input\");\n\t            return 1;\n\t        }\n\t \n\t        return RMQUtil(0, n - 1, qs, qe, 0);\n\t    }\n\t \n\t    // A recursive function that constructs Segment Tree for\n\t    // array[ss..se]. si is index of current node in segment tree st\n\t    int constructSTUtil(int arr[], int ss, int se, int si)\n\t    {\n\t        // If there is one element in array, store it in current\n\t        //  node of segment tree and return\n\t        if (ss == se) {\n\t            st[si] = arr[ss];\n\t            return arr[ss];\n\t        }\n\t \n\t        // If there are more than one elements, then recur for left and\n\t        // right subtrees and store the minimum of two values in this node\n\t        int mid = getMid(ss, se);\n\t        st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1),\n\t                constructSTUtil(arr, mid + 1, se, si * 2 + 2));\n\t        return st[si];\n\t    }\n\t \n\t    /* Function to construct segment tree from given array. This function\n\t       allocates memory for segment tree and calls constructSTUtil() to\n\t       fill the allocated memory */\n\t    void constructST(int arr[], int n)\n\t    {\n\t        // Allocate memory for segment tree\n\t \n\t        //Height of segment tree\n\t        int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));\n\t \n\t        //Maximum size of segment tree\n\t        int max_size = 2 * (int) Math.pow(2, x) - 1;\n\t        st = new int[max_size]; // allocate memory\n\t \n\t        // Fill the allocated memory st\n\t        constructSTUtil(arr, 0, n - 1, 0);\n\t    }\n\t \n\t    // Driver program to test above functions\n\t\n\t}\n\t\n\tpublic static int fact(int n)\n\t{\n\t\tHashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();\n\t\tboolean ans=true;\n\t\t while (n%2==0)\n\t        {\n\t            if(hm.containsKey(2))\n\t            {\thm.put(2,hm.get(2)+1);\n\t            ans=false;\n\t            }\n\t            else\n\t            \thm.put(2,1);\n\t            n /= 2;\n\t        }\n\t \n\t        // n must be odd at this point.  So we can\n\t        // skip one element (Note i = i +2)\n\t        for (int i = 3; i <= Math.sqrt(n); i+= 2)\n\t        {\n\t            // While i divides n, print i and divide n\n\t            while (n%i == 0)\n\t            {\n\t            \t  if(hm.containsKey(i))\n\t  \t            \t{hm.put(i,hm.get(i)+1);\n\t  \t            \tans=false;\n\t  \t            \t}\n\t  \t            else\n\t  \t            \thm.put(i,1);\n\t                n /= i;\n\t            }\n\t        }\n\t \n\t        // This condition is to handle the case whien\n\t        // n is a prime number greater than 2\n\t        if (n > 2)\n\t        \t if(hm.containsKey(n))\n\t  \t            \t{hm.put(n,hm.get(n)+1);\n\t  \t            \tans=false;\n\t  \t            \t}\n\t  \t            else\n\t  \t            \thm.put(n,1);\n\t\tif(ans)\n\t\t\treturn hm.size();\n\t\telse\n\t\t\treturn -1;\n\t}\n\tpublic static int binary_search(long[] a,long k,int l,int r)\n\t{\n\t\t\n\t\twhile(l<=r)\n\t\t{\n\t\t\tint mid=(l+r)/2;\n\t\t\t if(a[mid]>=k)\n\t\t\t{\n\t\t\t\tr=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t\tl=mid+1;\n\t\t}\n\t\treturn l;\n\t}\n\n\tstatic class Pair implements Comparable<Pair>\n\t {\n\t\t Long x;\n\t\t Long y;\n\t     \n\t        Pair(long x,long y)\n\t        {\n\t            this.x=x;\n\t            this.y=y;\n\t     \n\t        }\n\t        public int compareTo(Pair p)\n\t        {\n\t            return Long.compare(this.y,p.y);\n\t        }\n\t\t\n\t}\n\t   public static void removeDuplicates()\n\t    {\n\t         Node cur=head;\n\t         while(cur!=null)\n\t         {\n\t        \t// w.println(1);\n\t             int k=cur.data;\n\t             Node p=cur.next;\n\t             Node pre=cur;\n\t             while(p!=null)\n\t             {\n\t            \t// w.println(2);\n\t                 if(p.data==k)\n\t                 {\n\t                     pre.next=p.next;\n\t                     p=pre.next;\n\t                 }\n\t                 else\n\t                 {\n\t                     p=p.next;\n\t                     pre=pre.next;\n\t                 }\n\t             }\n\t             cur=cur.next;\n\t         }\n\t     \n\t    }\n\n\tpublic static void insert_front(int x)\n\t{\n\t\tNode f=new Node(x);\n\t\tf.next=head;\n\t\thead=f;\n\t}\n\tpublic static void insert_mid(Node x,int d)\n\t{\n\t\tif(x==null)\n\t\t{\n\t\t\tw.println(\"Nothing can be shown\");\n\t\t\treturn;\n\t\t}\n\t\tNode nex=x.next;\n\t\tNode ne=new Node(d);\n\t\tx.next=ne;\n\t\tne.next=nex;\n\t}\n\tpublic static void insert_end(int x)\n\t{\n\t\tNode f=new Node(x);\n\t\tNode temp=head;\n\t\twhile(temp.next!=null)\n\t\t\ttemp=temp.next;\n\t\ttemp.next=f;\n\t\t\t\n\t}\n\tpublic static class Node\n\t{\n\t\tint data;\n\t\tNode next;\n\t\tNode(int d)\n\t\t{\n\t\t\tthis.data=d;\n\t\t\tthis.next=null;\n\t\t}\n\t}\n\n\n     \n\n\t\n\t\n\t/*\n\t *  PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>()\n  \t\t\t{\n  \t\t\t\tpublic int compare(Integer o1, Integer o2)\n  \t\t\t\t{\n  \t\t\t\t\treturn Intege\n  \t\t\t\t\tr.compare(o2,o1);\n  \t\t\t\t}\n  \t\t\t});\n\t * \n\t * \n\t */\n\t\n\tpublic static void shuffle(long[] a,int n)\n\t{\n\t\tRandom r=new Random();\n\t\tfor(int i=n-1;i>0;i--)\n\t\t{\n\t\t\tint j=r.nextInt(i);\n\t\t\tlong t=a[j];\n\t\t\ta[j]=a[i];\n\t\t\ta[i]=t;\n\t\t}\n\t}\n\tpublic static void bfs1(int u)\n\t{\n\t    Queue<Integer> q=new LinkedList();\n\t    q.add(u);\n\t    visited[u]=true;\n\t    while(!q.isEmpty())\n\t    {\n\t    \t//w.print(1);\n\t    \tint p=q.poll();\n\t      for(int i=0;i<adj[p].size();i++)\n\t     { \n\t    \t  if(!visited[adj[p].get(i)])\n\t    \t  {\n\t    \tq.add(adj[p].get(i));\n\t    \tvisited[adj[p].get(i)]=true;\n\t    \t  }\n\t    \t  levl[adj[p].get(i)]=levl[p]+1;\n\t    \t  }\n\t    }\n\t    \n\t}\n\tpublic static void bfs2(int u)\n\t{\n\t    Queue<Integer> q=new LinkedList();\n\t    q.add(u);\n\t    vis2[u]=true;\n\t    while(!q.isEmpty())\n\t    {\n\t    \tint p=q.poll();\n\t      for(int i=0;i<adj[p].size();i++)\n\t     { \n\t    \t  if(!vis2[adj[p].get(i)])\n\t    \t  {\n\t    \tdv[adj[p].get(i)]=dv[p]+1;\n\t    \tq.add(adj[p].get(i));\n\t    \t  \n\t    \tvis2[adj[p].get(i)]=true;\n\t    \t  }\n\t    \t  }\n\t    }\n\t    \n\t}\n\t public static void buildgraph(int n)\n\t {\n         adj=new LinkedList[n+1];\n         visited=new boolean[n];\n         level=new int[n];\n         par=new int[n];\n         for(int i=0;i<=n;i++)\n         \t{\n        \t adj[i]=new LinkedList<Integer>();\n         \t\n         \t}\n      \n\t }\n\t\n\t/*public static long kruskal(Pair[] p)\n\t{\n\t\tlong ans=0;\n\t\tint w=0,x=0,y=0;\n\t\tfor(int i=0;i<p.length;i++)\n\t\t{\n\t\t\tw=p[i].w;\n\t\t\tx=p[i].x;\n\t\t\ty=p[i].y;\n\t\t\tif(root(x)!=root(y))\n\t\t\t{\n\t\t\t\tans+=w;\n\t\t\t\tunion(x,y);\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}*/\n\t\n\n\t static  class npair implements Comparable<npair>\n\t {\n\t     int a,b;\n\t     \n\t\n\t\tnpair(int a,int b)\n\t\t{\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t\t//this.index=index;\n\t\t}\n\n\n\t\tpublic int compareTo(npair o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn Integer.compare(this.a,o.a);\n\t\t}\n\n\n\t\n\t\t\n\t}\n\tpublic static int root(int i)\n\t{\n\t\twhile(root[i]!=i)\n\t\t{\n\t\t\troot[i]=root[root[i]];\n\t\t\ti=root[i];\n\t\t}\n\t\treturn i;\n\t}\n\t\n\tpublic static void init(int n)\n\t{\n\t\troot=new int[n+1];\n\t\tfor(int i=1;i<=n;i++)\n\t\t\troot[i]=i;\n\t}\n\tpublic static void union(int a,int b)\n\t{\n\t    int root_a=root(a);\t\n\t    int root_b=root(b);\n\t    root[root_a]=root_b;\n\t   // size[root_b]+=size[root_a];\n\t}\n\n\n\t\n\tpublic static boolean isPrime(long n)\n\t{\n\t    // Corner cases\n\t    if (n <= 1)  return false;\n\t    if (n <= 3)  return true;\n\t \n\t    // This is checked so that we can skip \n\t    // middle five numbers in below loop\n\t    if (n%2 == 0 || n%3 == 0)\n\t    \treturn false;\n\t \n\t    for (long i=5; i*i<=n; i=i+6)\n\t        if (n%i == 0 || n%(i+2) == 0)\n\t           return false;\n\t \n\t    return true;\n\t}\n\t\n\n\t\n\tpublic static String ns()\n\t{\n\t\treturn in.nextLine();\n\t}\n\tpublic static int ni()\n\t{\n\t\treturn in.nextInt();\n\t}\n\tpublic static long nl()\n\t{\n\t\treturn in.nextLong();\n\t}\n\tpublic static int[] na(int n)\n\t{\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\ta[i]=ni();\n\t\treturn a;\n\t}\n\tpublic static long[] nla(int n)\n\t{\n\t\tlong[] a=new long[n];\n\t\tfor(int i=0;i<n;i++)\n\t\ta[i]=nl();\n\t\treturn a;\n\t}\n\tpublic static void sieve()\n\t    {\n\t       int n=prime.length;\n\t        for(int i=0;i<n;i++)\n\t            prime[i] = true;\n\t         \n\t        for(int p = 2; p*p <=n; p++)\n\t        {\n\t            if(prime[p] == true)\n\t            {\n\t                for(int i = p*2; i <n; i += p)\n\t                    prime[i] = false;\n\t            }\n\t        }\n\t    }\n\n  public static String rev(String s)\n\t{\n\t\tStringBuilder sb=new StringBuilder(s);\n\t\tsb.reverse();\n\t\treturn sb.toString();\n\t}\n\tstatic long lcm(long a, long b)\n\t{\n\t    return a * (b / gcd(a, b));\n\t}\n\tstatic long gcd(long a, long b)\n\t{\n\t    while (b > 0)\n\t    {\n\t        long temp = b;\n\t        b = a % b; // % is remainder\n\t        a = temp;\n\t    }\n\t    return a;\n\t}\n\tstatic InputReader in;\n\tstatic PrintWriter w;\nstatic class InputReader \n{\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{\n  this.stream = stream;\n}\n \npublic int snext()\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    }\n    catch (IOException e)\n    {\n      throw new InputMismatchException();\n    }\n    if (snumChars <= 0)\n      return -1;\n  }\n  return buf[curChar++];\n}\n \npublic 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  {\n    if (c < '0' || c > '9')\n      throw new InputMismatchException();\n    res *= 10;\n    res += c - '0';\n    c = snext();\n  }\n  while (!isSpaceChar(c));\n  return res * sgn;\n}\n \npublic 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  {\n    if (c < '0' || c > '9')\n      throw new InputMismatchException();\n    res *= 10;\n    res += c - '0';\n    c = snext();\n  }\n  while (!isSpaceChar(c));\n  return res * sgn;\n}\t    \npublic String readString() \n{\n  int c = snext();\n  while (isSpaceChar(c)) \n  {\n    c = snext();\n  }\n  StringBuilder res = new StringBuilder();\n  do\n  {\n    res.appendCodePoint(c);\n    c = snext();\n  }\n  while (!isSpaceChar(c));\n  return res.toString();\n}\n \npublic String nextLine() \n{\n  int c = snext();\n  while (isSpaceChar(c))\n    c = snext();\n  StringBuilder res = new StringBuilder();\n  do\n  {\n    res.appendCodePoint(c);\n    c = snext();\n  }\n  while (!isEndOfLine(c));\n  return res.toString();\n}\n \npublic 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 \nprivate boolean isEndOfLine(int c) \n{\n  return c == '\\n' || c == '\\r' || c == -1;\n}\n \npublic interface SpaceCharFilter\n{\n  public boolean isSpaceChar(int ch);\n}\n}\n\t\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Map;\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 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        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, OutputWriter out) {\n            int n = in.nextInt();\n\n\n            String[] a = new String[n];\n\n            Map<String, Integer> map = new HashMap<>();\n\n            for (int i = 0; i < n; i++) {\n                a[i] = in.next();\n                map.merge(a[i], 1, Integer::sum);\n            }\n\n            String[] b = new String[n];\n\n            for (int i = 0; i < n; i++) {\n                b[i] = in.next();\n                if (map.containsKey(b[i])) {\n                    map.put(b[i], map.get(b[i]) - 1);\n                    if (map.get(b[i]) <= 0)\n                        map.remove(b[i]);\n                }\n            }\n\n            int ans = 0;\n            for (String s : map.keySet()) {\n                ans += map.get(s);\n            }\n\n            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        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 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 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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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 prakhar897\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        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            String arr1[] = new String[n];\n            String arr2[] = new String[n];\n            int i, j, count = 0;\n            for (i = 0; i < n; i++) {\n                arr1[i] = in.nextString();\n            }\n            for (i = 0; i < n; i++) {\n                arr2[i] = in.nextString();\n                for (j = 0; j < n; j++) {\n                    if (arr2[i].equals(arr1[j])) {\n                        arr1[j] = \"\";\n                        count++;\n                        break;\n                    }\n                }\n            }\n            out.println(n - count);\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 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    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", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class cfedu46a{\n\tpublic static void main(String [] args) throws IOException{\n\t\tInputReader in = new InputReader(\"cfedu46a.in\");\n\t\t\n\t\tint [] arr = new int[9];\n\t\tint [] arr2 = new int[9];\n\t\tint [] size = {4, 3, 2, 1, 1, 1, 2, 3, 4};\n\t\tint n = in.nextInt();\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tString s = in.next();\n\t\t\tswitch(s.length()){\n\t\t\t\tcase 1: \n\t\t\t\t\tif(s.charAt(0) == 'S')\n\t\t\t\t\t\tarr[3]++;\n\t\t\t\t\tif(s.charAt(0) == 'M')\n\t\t\t\t\t\tarr[4]++;\n\t\t\t\t\tif(s.charAt(0) == 'L')\n\t\t\t\t\t\tarr[5]++;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tif(s.charAt(s.length() - 1) == 'S'){\n\t\t\t\t\t\tarr[3 - (s.length() - 1)]++;\n\t\t\t\t\t}\n\t\t\t\t\tif(s.charAt(s.length() - 1) == 'L'){\n\t\t\t\t\t\tarr[5 + (s.length() - 1)]++;\n\t\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tString s = in.next();\n\t\t\tswitch(s.length()){\n\t\t\t\tcase 1: \n\t\t\t\t\tif(s.charAt(0) == 'S')\n\t\t\t\t\t\tarr2[3]++;\n\t\t\t\t\tif(s.charAt(0) == 'M')\n\t\t\t\t\t\tarr2[4]++;\n\t\t\t\t\tif(s.charAt(0) == 'L')\n\t\t\t\t\t\tarr2[5]++;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tif(s.charAt(s.length() - 1) == 'S'){\n\t\t\t\t\t\tarr2[3 - (s.length() - 1)]++;\n\t\t\t\t\t}\n\t\t\t\t\tif(s.charAt(s.length() - 1) == 'L'){\n\t\t\t\t\t\tarr2[5 + (s.length() - 1)]++;\n\t\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tint cnt = 0;\n\t\tfor(int i = 0; i < 9; i++){\n\t\t\tif(arr[i] == arr2[i])\n\t\t\t\tcontinue;\n\t\t\telse{\n\t\t\t\tcnt += (arr2[i] - arr[i] > 0? arr2[i] - arr[i]: 0);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(cnt);\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(String s) {\n\t\t\ttry{\n\t\t\t\treader = new BufferedReader(new FileReader(s), 32768);\n\t\t\t}\n\t\t\tcatch (Exception e){\t\t\n\t\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 32768);\n\t\t\t}\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    tokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t    throw 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\t}\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "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.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Map;\nimport java.util.Map.Entry;\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        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, OutputWriter out) {\n            int n = in.nextInt();\n            HashMap<String, Integer> map = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                String next = in.next();\n                map.put(next, map.getOrDefault(next, 0) + 1);\n            }\n            int ct = 0;\n            for (int i = 0; i < n; i++) {\n                String next = in.next();\n                if (map.containsKey(next)) {\n                    map.put(next, map.get(next) - 1);\n                    if (map.get(next) <= 0) {\n                        map.remove(next);\n                    }\n                }\n            }\n            for (Map.Entry<String, Integer> entry : map.entrySet()) {\n                ct += entry.getValue();\n            }\n            out.println(ct);\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 readInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                if (Character.isValidCodePoint(c)) {\n                    res.appendCodePoint(c);\n                }\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public int nextInt() {\n            return readInt();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class CodehorsesTshirts {\n    \n    \n    \n    /************************ SOLUTION STARTS HERE ************************/\n    \n    \n    private static void solve() {\n        \n        \n        int n = nextInt();\n        \n        HashMap<String, Integer> a = new HashMap<>();\n        HashMap<String, Integer> b = new HashMap<>();\n        \n        for(int i = 0; i < n; i++)\n            a.merge(nextLine(), 1, Integer::sum);\n        \n        for(int i = 0; i < n; i++)\n            b.merge(nextLine(), 1, Integer::sum);\n        \n        b.forEach((k , v) -> {\n            if(a.containsKey(k))\n                a.put(k, a.get(k) - Math.min(v , a.get(k)));\n        });\n        \n        int cost = a.values().stream().reduce(0, Integer::sum);\n        \n        println(cost);  \n        \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<n){a[i++]=nextInt();}  return a;}\n    static long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}    \n    static int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}            \n    static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}            \n    static void   print(Object o)  { writer.print(o);  }\n    static void   println(Object o){ writer.println(o);}\n    \n    /************************ TEMPLATE ENDS HERE ************************/\n    \n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A implements Runnable {\n\n    public void run() {\n        long startTime = System.nanoTime();\n\n        int n = nextInt();\n\n        String[] all = new String[9];\n        all[0] = \"M\";\n        for (int i = 0; i < 4; i++) {\n            String s = \"\";\n            for (int j = 0; j < i; j++) {\n                s += \"X\";\n            }\n            all[2 * i + 1] = s + \"S\";\n            all[2 * i + 2] = s + \"L\";\n        }\n\n        Map<String, Integer> map1 = new HashMap<>();\n        Map<String, Integer> map2 = new HashMap<>();\n        for (String s : all) {\n            map1.put(s, 0);\n            map2.put(s, 0);\n        }\n        for (int i = 0; i < n; i++) {\n            String s = nextToken();\n            map1.put(s, map1.get(s) + 1);\n        }\n        for (int i = 0; i < n; i++) {\n            String s = nextToken();\n            map2.put(s, map2.get(s) + 1);\n        }\n\n        int res = 0;\n        for (String s : all) {\n            int a = map1.get(s);\n            int b = map2.get(s);\n\n            if (a > b) {\n                res += a - b;\n            }\n        }\n        println(res);\n\n        if (fileIOMode) {\n            System.out.println((System.nanoTime() - startTime) / 1e9);\n        }\n        out.close();\n    }\n\n    //-----------------------------------------------------------------------------------\n\n    private static boolean fileIOMode;\n    private static BufferedReader in;\n    private static PrintWriter out;\n    private static StringTokenizer tokenizer;\n\n    public static void main(String[] args) throws Exception {\n        fileIOMode = args.length > 0 && args[0].equals(\"!\");\n        if (fileIOMode) {\n            in = new BufferedReader(new FileReader(\"a.in\"));\n            out = new PrintWriter(\"a.out\");\n        } else {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n        }\n        tokenizer = new StringTokenizer(\"\");\n\n        new Thread(new A()).start();\n    }\n\n    private static String nextLine() {\n        try {\n            return in.readLine();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    private static String nextToken() {\n        while (!tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(nextLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    private static int nextInt() {\n        return Integer.parseInt(nextToken());\n    }\n\n    private static long nextLong() {\n        return Long.parseLong(nextToken());\n    }\n\n    private static double nextDouble() {\n        return Double.parseDouble(nextToken());\n    }\n\n    private static BigInteger nextBigInteger() {\n        return new BigInteger(nextToken());\n    }\n\n    private static void print(Object o) {\n        if (fileIOMode) {\n            System.out.print(o);\n        }\n        out.print(o);\n    }\n\n    private static void println(Object o) {\n        if (fileIOMode) {\n            System.out.println(o);\n        }\n        out.println(o);\n    }\n\n    private static void printf(String s, Object... o) {\n        if (fileIOMode) {\n            System.out.printf(s, o);\n        }\n        out.printf(s, o);\n    }\n}\n", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic final class CF {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        ArrayList<String> a = new ArrayList<>();\n        for(int i = 0; i<n; i++)\n            a.add(sc.next());\n        int count = 0;\n        for(int i = 0; i<n; i++) {\n            String b = sc.next();\n            int idx = a.indexOf(b);\n            if(idx!=-1)\n                a.remove(idx);\n            else\n                count++;\n        }\n        System.out.println(count);\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class algo121\n{\n    public static void main(String args[])\n    {\n        Scanner ex=new Scanner(System.in);\n        int n=ex.nextInt();\n        String a[]=new String[n];\n        String b[]=new String[n];\n        for(int i=0;i<n;i++)\n        a[i]=ex.next();\n        for(int i=0;i<n;i++)\n        b[i]=ex.next();\n        String valid[]={\"S\",\"M\",\"L\",\"XS\",\"XL\",\"XXS\",\"XXL\",\"XXXS\",\"XXXL\"};\n        int ai[]=new int[9];\n        int bi[]=new int[9];\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<9;j++)\n            {\n                if(a[i].equals(valid[j]))\n                ai[j]++;\n                if(b[i].equals(valid[j]))\n                bi[j]++;\n            }\n        }\n        int ans=0;\n        for(int i=0;i<9;i++)\n        {\n            if(ai[i]>bi[i])\n            ans=ans+ai[i]-bi[i];\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A\n{\t\n\t\n\t\n\t\tpublic static void main(String[] args) throws IOException \n\t\t{\n\t\t\t\t\n\t\t\t\tScanner sc=new Scanner(System.in);\n\t\t\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\t\t\tint n=sc.nextInt();\n\t\t\t\tString []a=new String[n];\n\t\t\t\tString []b=new String[n];\n\t\t\t\t\n\t\t\t\tTreeMap<String,Integer> map1=new TreeMap(),map2=new TreeMap();\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t{\n\t\t\t\t\tString s=sc.next();\n\t\t\t\t\tmap1.put(s, map1.getOrDefault(s, 0)+1);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t{\n\t\t\t\t\tString s=sc.next();\n\t\t\t\t\tmap2.put(s, map2.getOrDefault(s, 0)+1);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tint ans=0;\n\t\t\t\tfor(String s:map2.keySet())\n\t\t\t\t{\n\t\t\t\t\tint cnt=map1.getOrDefault(s, 0);\n\t\t\t\t\tans+=Math.max(0, map2.get(s)-cnt);\n\t\t\t\t}\n\t\t\t\tpw.println(ans);\n\t\t\t\tpw.close();\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\tstatic class Scanner\n\t\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\t\tpublic 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 Scanner(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t}\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\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\t}\n\n\t\t\n\t\t\n}", "complexity": "linear", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class GenerateLogin {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString a = scan.next();\n\t\tString b = scan.next();\n\t\tchar last = b.charAt(0);\n\t\tString ans = \"\"+a.charAt(0);\n\t\tfor(int i = 1;i<a.length();i++){\n\t\t\tif(a.charAt(i)>=last)break;\n\t\t\tans+=a.charAt(i);\n\t\t}\n\t\tans+=last;\n\t\tSystem.out.println(ans);\n\t}\n\n}\n", "complexity": "linear", "problem": "909_A. Generate Login", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class SonyaExhibition {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer tokenizer;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = nextInt();\n\t\tint[] arr = {0,1};\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tSystem.out.print(arr[i % 2]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic static String next() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\tString line = br.readLine();\n\t\t\tif (line == null)\n\t\t\t\tthrow new IOException();\n\t\t\ttokenizer = new StringTokenizer(line);\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n}\n", "complexity": "linear", "problem": "1004_B. Sonya and Exhibition", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class FirstClass {\n\t\n\tpublic static void main(String[] args)throws IOException\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n = Integer.parseInt(br.readLine());\n\t\t\n\t\tint arr[] = new int [n];\n\t\t\n\t\tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\n\t\tfor(int i = 0 ; i < n ; i++)\n\t\t{\n\t\t\tarr[i] = Integer.parseInt(st1.nextToken());\n\t\t}\n\t\t\n\t\tint max = -1;\n\t\tboolean flag = true;\n\t\t\n\t\tfor(int i = 0 ; i < n ; i++)\n\t\t{\n\t\t\tif(arr[i] > max+1)\n\t\t\t{\n\t\t\t\tflag = false;\n\t\t\t\tout.println(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmax = Math.max(max, arr[i]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(flag)\n\t\t\tout.println(-1);\n\t\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "1054_B. Appending Mex", "from": "CODEFORCES"}
{"src": "//package contese_476;\nimport java.util.*;\npublic class q1 \n{\n\tint m=(int)1e9+7;\npublic class Node\n{\n\tint a;\n\tint b;\n\tpublic void Node(int a,int b)\n\t{\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t}\n}\npublic int mul(int a ,int b)\n{\na=a%m;\nb=b%m;\nreturn((a*b)%m);\n}\npublic int pow(int a,int b)\n{\n\tint x=1;\n\twhile(b>0)\n\t{\n\t\tif(b%2!=0)\n\t\t\tx=mul(x,a);\n\t\ta=mul(a,a);\n\t\tb=b/2;\n\t}\n\treturn x;\n}\npublic static long gcd(long a,long b)\n{\n\tif(b==0)\n\t\treturn a;\n\telse\n\t\treturn gcd(b,a%b);\n}\npublic static void main(String[] args)\n{\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tHashMap<Integer,Integer> h=new HashMap();\n\t//HashMap<Integer,Integer> h1=new HashMap();\n\tint[] a=new int[n];\n\tint x=sc.nextInt();\n\tfor(int i=0;i<n;i++)\n\t{\n\t\ta[i]=sc.nextInt();\n\t\tif(h.get(a[i])==null)\n\t\t{\n\t\t\th.put(a[i], 1);\n\t\t\t//h1.put(a[i],i);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\tcontinue;\n\t\t\n\t\telse\n\t\t{\n\t\t\t\n\t\t\tSystem.out.print(1);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\th.put(num, 1);\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(2);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tSystem.out.print(-1);\n\t\n     \n}\n\n}", "complexity": "linear", "problem": "1013_B. And", "from": "CODEFORCES"}
{"src": "//package contese_476;\nimport java.util.*;\npublic class q1 \n{\n\tint m=(int)1e9+7;\npublic class Node\n{\n\tint a;\n\tint b;\n\tpublic void Node(int a,int b)\n\t{\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t}\n}\npublic int mul(int a ,int b)\n{\na=a%m;\nb=b%m;\nreturn((a*b)%m);\n}\npublic int pow(int a,int b)\n{\n\tint x=1;\n\twhile(b>0)\n\t{\n\t\tif(b%2!=0)\n\t\t\tx=mul(x,a);\n\t\ta=mul(a,a);\n\t\tb=b/2;\n\t}\n\treturn x;\n}\npublic static long gcd(long a,long b)\n{\n\tif(b==0)\n\t\treturn a;\n\telse\n\t\treturn gcd(b,a%b);\n}\npublic static void main(String[] args)\n{\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tHashMap<Integer,Integer> h=new HashMap();\n\t//HashMap<Integer,Integer> h1=new HashMap();\n\tint[] a=new int[n];\n\tint x=sc.nextInt();\n\tfor(int i=0;i<n;i++)\n\t{\n\t\ta[i]=sc.nextInt();\n\t\tif(h.get(a[i])==null)\n\t\t{\n\t\t\th.put(a[i], 1);\n\t\t\t//h1.put(a[i],i);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\tcontinue;\n\t\t\n\t\telse\n\t\t{\n\t\t\t\n\t\t\tSystem.out.print(1);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tfor(int i=0;i<n;i++)\n\t{\n\t\tint num=a[i]&x;\n\t\tif(num==a[i])\n\t\t\tcontinue;\n\t\tif(h.get(num)==null)\n\t\t\th.put(num, 1);\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(2);\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\tSystem.out.print(-1);\n\t\n     \n}\n\n}", "complexity": "linear", "problem": "1013_B. And", "from": "CODEFORCES"}
{"src": "\n// LM10: The next Ballon d'or\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport javafx.util.Pair;\npublic class Main\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;li<arr.length;++li){ arr[li]=i();}}\n        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}\n        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }\n    }\n    public static void main(String[] args)throws IOException {\n        /*\ninputCopy\n4\n2 1 2 1\noutputCopy\n4\ninputCopy\n5\n0 -1 -1 -1 -1\noutputCopy\n4\n*/\n        PrintWriter pw = new PrintWriter(System.out);\n        FastReader fr = new FastReader();\n        int n=fr.i();\n        int [] arr=new int[n];\n        fr.scanIntArr(arr);\n        int min=Integer.MAX_VALUE;\n        int max=Integer.MIN_VALUE;\n        long sum=0;\n        if(n==1)\n        {\n            pw.println(arr[0]);\n            pw.flush();\n            pw.close();\n            return;\n        }\n        for(int i=0;i<n;++i)\n        {\n            if(arr[i]<min)\n                min=arr[i];\n            if(arr[i]>max)\n                max=arr[i];\n            sum+=Math.abs(arr[i]);\n        }\n        if(min>0)\n        {\n            sum-=2*min;\n        }\n        if(max<0)\n        {\n            sum+=2*max;\n        }\n        pw.println(sum);\n        pw.flush();\n        pw.close();\n    }\n}", "complexity": "linear", "problem": "1038_D. Slime", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner() {\n            try {\n                br = new BufferedReader(new InputStreamReader(System.in));\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e){e.printStackTrace();}\n        }\n\n        public String next() {\n            if (st.hasMoreTokens()) return 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 static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int n = sc.nextInt();\n        int best = 1;\n        int bestTime = Integer.MAX_VALUE;\n        for(int i=0;i<n;i++) {\n            int time;\n            int a = sc.nextInt();\n            time = (a%n==0 || a%n<=i) ? a/n : (a+n)/n;\n            if(time < bestTime) {\n                best = i + 1;\n                bestTime = time;\n            }\n        }\n\n        pw.println(best);\n        pw.close();\n    }\n}\n", "complexity": "linear", "problem": "996_B. World Cup", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    public void solve() {\n        int n = ni();\n        int a = ni();\n        int b = ni();\n\n        long ans = 0;\n        HashMap<Long, Long> m = new HashMap<>();\n        HashMap<String, Long> s = new HashMap<>();\n\n        for (int i = 0; i < n; i++) {\n            ni();\n            long vx = ni();\n            long vy = ni();\n            long v = (long) a * vx - vy;\n            String k = vx + \"|\" + vy;\n            long cs = s.getOrDefault(k, 0L);\n            long c = m.getOrDefault(v, 0L);\n            ans += c - cs;\n            m.put(v, c + 1);\n            s.put(k, cs + 1);\n        }\n        write (ans * 2 + \"\\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}", "complexity": "linear", "problem": "975_D. Ghosts", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class MinimumDiameterTree{\n    public static void main(String[] args) {\n\tInputReader in = new InputReader (System.in);\n\tPrintWriter out = new PrintWriter (System.out);\n\n\tint n = in.nextInt();\n\tint s = in.nextInt();\n\tint deg[] = new int [n];\n\t\n\tfor (int i = 1; i < n; ++i) {\n\t    deg[in.nextInt() - 1] ++;\n\t    deg[in.nextInt() - 1] ++;\n\t}\n\n\tint l = 0;\n\tfor (int i = 0; i < n; ++i)\n\t    if (deg[i] == 1) l ++;\n\n\tout.println((double) 2 * s / l);\n\tout.close();\n    }\n\n    public static class InputReader {\n\tpublic BufferedReader reader;\n\tpublic StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t    reader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t    tokenizer = null;\n\t}\n\n\tpublic String next() {\n\t    while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\ttry {\n\t\t    tokenizer = new StringTokenizer(reader.readLine());\n\t\t} catch(IOException e) {\n\t\t    throw new RuntimeException(e);\n\t\t}\n\t    }\n\t    return tokenizer.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t    return Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "linear", "problem": "1086_B. Minimum Diameter Tree", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1027D {\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[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tcc[i] = Integer.parseInt(st.nextToken());\n\t\tst = new StringTokenizer(br.readLine());\n\t\tint[] aa = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = Integer.parseInt(st.nextToken()) - 1;\n\t\tint[] used = new int[n];\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (used[i] == 2)\n\t\t\t\tcontinue;\n\t\t\tint j = i;\n\t\t\twhile (used[j] == 0) {\n\t\t\t\tused[j] = 1;\n\t\t\t\tj = aa[j];\n\t\t\t}\n\t\t\tif (used[j] == 1) {\n\t\t\t\tint c = cc[j];\n\t\t\t\twhile (used[j] == 1) {\n\t\t\t\t\tused[j] = 2;\n\t\t\t\t\tc = Math.min(c, cc[j]);\n\t\t\t\t\tj = aa[j];\n\t\t\t\t}\n\t\t\t\tans += c;\n\t\t\t}\n\t\t\tj = i;\n\t\t\twhile (used[j] == 1) {\n\t\t\t\tused[j] = 2;\n\t\t\t\tj = aa[j];\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "linear", "problem": "1027_D. Mouse Hunt", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n//201920181\n\npublic class Polycarp{\n\n\tpublic static void main(String args[]){\n\t\tScanner s = new Scanner(System.in);\n        int rem[] = new int[3];\n\t\t\n\t\tArrays.fill(rem,-1);\n\t\trem[0] = 0;\n        char ch[] = s.next().toCharArray();\n\t\tint n = ch.length;\n \t\tlong dp[] = new long[n];\n\n        int sum = 0;\n\t\t\n        for(int i=0;i<ch.length;i++){\n\t\t   sum = sum + (ch[i]-48);\n\t\t   if(rem[sum%3] != -1)\n\t\t\t    if(i>0){\n\t\t\t\t\tdp[i] = Math.max(dp[i-1],dp[rem[sum%3]]+1);}\n\t\t\t\telse\n\t\t\t\t\tdp[i] = 1;\n\t       else\n\t\t\t   if(i>0)\n\t\t\t\t   dp[i] = dp[i-1];\n\t\t\t   \n\t\t   \n\t\t   rem[sum%3] = i;\n\t\t   sum = sum%3;\n\t\t   \n\t\t}\t\t\n\t\t \n\n            System.out.println(dp[n-1]);\t\t\t\n\t\t\n\t\t\n\t}\n}\n", "complexity": "linear", "problem": "1005_D. Polycarp and Div 3", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author Haya\n */\npublic class CommentaryBoxes {\n\n    public static void main(String[] args) {\n        \n        FastReader in = new FastReader();\n        \n        long n = in.nextLong();\n        long m = in.nextLong();\n        long a = in.nextLong();\n        long b = in.nextLong();\n        long total = 0;\n        \n        long val =(n%m);\n        if (n%m != 0){\n            \n            long x = (val)*b;\n            long y = (m-val)*a;\n            \n            total = Math.min(x, y);\n        }\n        System.out.println(Math.abs(total));\n        \n    }\n\n    public static class FastReader {\n\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() {\n            String string = \"\";\n            try {\n                string = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return string;\n        }\n\n    }\n\n}\n", "complexity": "linear", "problem": "990_A. Commentary Boxes", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class SFly {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\n\t\tint planet = Integer.parseInt(lector.readLine());\n\t\tint ini = Integer.parseInt(lector.readLine());\n\t\tdouble peso = ini;\n\t\tint[] desp = new int[planet];\n\t\tint[] ater = new int[planet];\n\t\tString[] temp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tdesp[i] = Integer.parseInt(temp[i]);\n\t\t\tif(desp[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tater[i] = Integer.parseInt(temp[i]);\n\t\t\tif(ater[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = null;\n\t\tint i=planet-1;\n\t\tpeso = (peso*ater[0])/(ater[0]-1);\n\t\twhile(i>0) {\n\t\t\tpeso = (peso*desp[i])/(desp[i]-1);\n\t\t\tpeso = (peso*ater[i])/(ater[i]-1);\n\t\t\ti--;\n\t\t}\n\t\tpeso = (peso*desp[0])/(desp[0]-1);\n\t\tpeso = peso - ini;\n\t\tSystem.out.println(peso);\n\t\tlector.close();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\n/* spar5h */\n\npublic class cf1 implements Runnable{    \n\t\n\tpublic void run() {\n\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\t\n\t\tint t = 1;\n\t\t\n\t\twhile(t-- > 0) {\n\t\t\t\n\t\t\tint n = s.nextInt(), m = s.nextInt();\n\t\t\t\n\t\t\tint[] a = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\ta[i] = s.nextInt();\n\t\t\t\n\t\t\tint[] b = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\tb[i] = s.nextInt();\n\t\t\t\n\t\t\tArrayList<Integer> list = new ArrayList<Integer>();\n\t\t\t\n\t\t\tlist.add(a[1]);\n\t\t\t\n\t\t\tfor(int i = 2; i <= n; i++) {\n\t\t\t\tlist.add(b[i]); list.add(a[i]);\n\t\t\t}\n\t\t\t\n\t\t\tlist.add(b[1]);\n\t\t\t\n\t\t\tdouble wt = m;\n\t\t\tboolean check = true;\n\t\t\t\n\t\t\tfor(int i = list.size() - 1; i >= 0; i--) {\n\t\t\t\t\n\t\t\t\tif(list.get(i) <= 1) {\n\t\t\t\t\tcheck = false; break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tdouble x = wt / (list.get(i) - 1);\n\t\t\t\t\t\t\n\t\t\t\twt += x;\n\t\t\t}\n\t\t\t\n\t\t\tif(check)\n\t\t\t\tw.println(wt - m);\n\t\t\telse\n\t\t\t\tw.println(-1);\n\t\t}\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\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new cf1(),\"cf1\",1<<26).start();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\n/* spar5h */\n\npublic class cf1 implements Runnable{    \n\t\n\tpublic void run() {\n\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\t\n\t\tint t = 1;\n\t\t\n\t\twhile(t-- > 0) {\n\t\t\t\n\t\t\tint n = s.nextInt(), m = s.nextInt();\n\t\t\t\n\t\t\tint[] a = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\ta[i] = s.nextInt();\n\t\t\t\n\t\t\tint[] b = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\tb[i] = s.nextInt();\n\t\t\t\n\t\t\tArrayList<Integer> list = new ArrayList<Integer>();\n\t\t\t\n\t\t\tlist.add(a[1]);\n\t\t\t\n\t\t\tfor(int i = 2; i <= n; i++) {\n\t\t\t\tlist.add(b[i]); list.add(a[i]);\n\t\t\t}\n\t\t\t\n\t\t\tlist.add(b[1]);\n\t\t\t\n\t\t\tdouble wt = m;\n\t\t\tboolean check = true;\n\t\t\t\n\t\t\tfor(int i = list.size() - 1; i >= 0; i--) {\n\t\t\t\t\n\t\t\t\tif(list.get(i) <= 1) {\n\t\t\t\t\tcheck = false; break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tdouble x = wt / (list.get(i) - 1);\n\t\t\t\t\t\t\n\t\t\t\twt += x;\n\t\t\t}\n\t\t\t\n\t\t\tif(check)\n\t\t\t\tw.println(wt - m);\n\t\t\telse\n\t\t\t\tw.println(-1);\n\t\t}\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\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new cf1(),\"cf1\",1<<26).start();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class SFly {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\n\t\tint planet = Integer.parseInt(lector.readLine());\n\t\tint ini = Integer.parseInt(lector.readLine());\n\t\tdouble peso = ini;\n\t\tint[] desp = new int[planet];\n\t\tint[] ater = new int[planet];\n\t\tString[] temp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tdesp[i] = Integer.parseInt(temp[i]);\n\t\t\tif(desp[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = lector.readLine().split(\" \");\t\t\n\t\tfor(int i=0; i<planet; i++) {\n\t\t\tater[i] = Integer.parseInt(temp[i]);\n\t\t\tif(ater[i] == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tlector.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttemp = null;\n\t\tint i=planet-1;\n\t\tpeso = (peso*ater[0])/(ater[0]-1);\n\t\twhile(i>0) {\n\t\t\tpeso = (peso*desp[i])/(desp[i]-1);\n\t\t\tpeso = (peso*ater[i])/(ater[i]-1);\n\t\t\ti--;\n\t\t}\n\t\tpeso = (peso*desp[0])/(desp[0]-1);\n\t\tpeso = peso - ini;\n\t\tSystem.out.println(peso);\n\t\tlector.close();\n\t}\n}", "complexity": "linear", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "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 a[]=new int[n];\n    for(int i=0;i<n;i++)\n    a[i]=sc.nextInt();\n    Arrays.sort(a);\n    //boolean \n    int t=1,c=0;\n    for(int i=1;i<n;i++){\n        if(a[i]==a[i-1])\n        {\n            if(i-2>=0&&a[i-2]==a[i-1]-1){\n                System.out.println(\"cslnb\");\n                return;\n            }\n            c++;\n        }\n        if(a[i]==a[i-1]&&a[i]==0){\n        System.out.println(\"cslnb\");\n        return;\n        }\n    }\n    if(c>1)\n    {\n        System.out.println(\"cslnb\");\n        return;\n    }\n    for(int i=0;i<n;i++){\n        if((a[i]-i)%2!=0)\n        t=t^1;\n    }\n    if(t==1)\n    System.out.println(\"cslnb\");\n    else\n    System.out.println(\"sjfnb\");\n    \n    \n    \n    }\n    \n}", "complexity": "linear", "problem": "1190_B. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C{\n    static PrintWriter out;\n    static InputReader in;\n    public static void main(String args[]){\n        out = new PrintWriter(System.out);\n        in = new InputReader();\n        new C();\n        out.flush(); out.close();\n    }   \n    C(){\n       int w = solve();\n       out.print(w == 0 ? \"sjfnb\" : \"cslnb\");\n    }\n    int n;\n    long a[];\n    int solve(){\n        n = in.nextInt(); a = new long[n];\n        long sum = 0;\n        for(int i = 0; i < n; i++)sum += a[i] = in.nextLong();\n        if(sum == 0){\n            return 1;\n        }\n        Arrays.sort(a);\n        int c = 0, c0 = 0; long p = -1, max = 0;\n        int f = 0;\n        long t = -1; int pp = -1;\n        for(int i = 0; i < n; i++){\n            if(a[i] == p){\n                c++;\n            }else{\n                if(p == 0)c0 = c;\n                if(c >= 2){f++; t = p; pp = i - 2;}\n                max = Math.max(max, c);\n                p = a[i];\n                c = 1;\n            }\n        }\n        max = Math.max(max, c);\n        sum = 0;\n        if(c >= 2){f++; t = p; pp = n - 2;}\n        if(max > 2 || c0 > 1 || f > 1)return 1;\n        if(f == 1){\n            long v = Arrays.binarySearch(a, t - 1);\n            if(v >= 0)return 1;\n            a[pp]--; sum = 1;\n        }\n\n        p = -1;\n        for(int i = 0; i < n; i++){\n            sum += a[i] - (p + 1);\n            a[i] = p + 1;\n            p = a[i];\n        }\n\n        return 1 - (int)(sum % 2);\n    }\n    public static class InputReader{\n        BufferedReader br;\n        StringTokenizer st;\n        InputReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\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        public String next(){\n            while(st == null || !st.hasMoreTokens()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch(IOException e){}\n            }\n            return st.nextToken();\n        }\n    }\n}\n        ", "complexity": "linear", "problem": "1190_B. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "    import java.util.*;\n    import java.io.*;\n    import java.lang.*;\n    import java.math.*;\n    public class B {\n        public static void main(String[] args) throws Exception {\n            BufferedReader bf = new BufferedReader(new InputStreamReader(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            Integer[] a = new Integer[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n            Arrays.sort(a);\n            int[] b = new int[n];\n            for(int i=0; i<n; i++) b[i] = a[i].intValue();\n            boolean diff = false;\n            boolean diff2 = false;\n            Set<Integer> vals = new HashSet<Integer>();\n            vals.add(b[0]);\n            int valval = 0;\n            for(int i=1; i<n; i++) {\n                vals.add(b[i]);\n                if(b[i] == b[i-1]) {\n                    if(!diff) {\n                        diff = true;\n                        valval = b[i];\n                    }\n                    else diff2 = true;\n                }\n            } \n            long sum = 0;\n            for(int i : b) sum += i;\n            sum -= 1L*n*(n-1)/2;\n\n            if(diff && !diff2) {\n                if(!vals.contains((valval-1)) && (valval > 0)) {\n                    if(sum%2 == 0) out.println(\"cslnb\"); else out.println(\"sjfnb\");\n                }\n                else out.println(\"cslnb\");\n            }\n            else if(diff2) out.println(\"cslnb\");\n            else if(sum%2 == 0) out.println(\"cslnb\"); else out.println(\"sjfnb\");\n            // int n = Integer.parseInt(st.nextToken());\n     \n            \n            out.close(); System.exit(0);\n        }\n    }", "complexity": "linear", "problem": "1190_B. Tokitsukaze, CSL and Stone Game", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class X\n{\n\tpublic static void main(String args[])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 s1 = br.readLine();\n\t\tString s2 = br.readLine();\n\t\tint i=0;\n\t\tchar c1,c2;\n\t\tint cost = 0;\n\t\twhile(i<n)\n\t\t{\n\t\t\tc1 = s1.charAt(i);\n\t\t\tc2 = s2.charAt(i);\n\t\t\tif(c1 != c2)\n\t\t\t{\n\t\t\t\tif((i+1)<n && s1.charAt(i+1) != s2.charAt(i+1) && s1.charAt(i) != s1.charAt(i+1))\n\t\t\t\t{\n\t\t\t\t\tcost +=1;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcost +=1;\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tSystem.out.println(cost);\n\t}\n}", "complexity": "linear", "problem": "1037_C. Equalize", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n\n    private FastScanner scanner = new FastScanner();\n\n    public static void main(String[] args) {\n        new Main().solve();\n    }\n\n\n    private void solve() {\n        int n = scanner.nextInt();\n\n        Map<Integer, Integer> cnt = new HashMap<>();\n\n        for (int i = 0; i < n; i++) {\n            String s = scanner.nextLine();\n\n            LinkedList<Character> st = new LinkedList<>();\n\n            for (char c : s.toCharArray()) {\n                if (c == ')' && !st.isEmpty() && st.getLast() == '(') {\n                    st.pollLast();\n                    continue;\n                }\n                st.addLast(c);\n            }\n\n            int t = st.size();\n            Set<Character> set = new HashSet<>(st);\n            if (set.size() > 1) {\n                continue;\n            }\n            if (set.isEmpty()) {\n                cnt.put(0, cnt.getOrDefault(0, 0) + 1);\n                continue;\n            }\n\n            if (st.getLast() == '(') {\n                cnt.put(t, cnt.getOrDefault(t, 0) + 1);\n            } else {\n                cnt.put(-t, cnt.getOrDefault(-t, 0) + 1);\n            }\n        }\n\n        long ans = 0;\n\n        for (int next : cnt.keySet()) {\n            if (next == 0) {\n                ans += (long) cnt.get(next) * (cnt.get(next) - 1) + cnt.get(next);\n            } else if (next > 0) {\n                int t = next * -1;\n                if (cnt.containsKey(t)) {\n                    ans += (long) cnt.get(next) * cnt.get(t);\n                }\n            }\n        }\n\n        System.out.print(ans);\n\n    }\n\n    class FastScanner {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n            tokenizer = null;\n        }\n\n        String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Integer[] nextA(int n) {\n            Integer a[] = new Integer[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = scanner.nextInt();\n            }\n            return a;\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            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "990_C. Bracket Sequences Concatenation Problem", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\npublic class Practice {\n\t\n\t   \n\n\t\tpublic static void main(String []args)\n\t\t{\n\t\t\tScanner sc=new Scanner(System.in);\n\t\t\tint n=sc.nextInt();\n\t\t\tsc.nextLine();\n\t\t\tString s=sc.nextLine();\n\t\t\t//System.out.println(s);\n\t\t\tchar c[]=s.toCharArray();\n\t\t\tArrayList a =new ArrayList();\n\t\t\t\n\t\t\tfor(int i=0;i<c.length;i++)\n\t\t\t{\n\t\t\t\t//System.out.println(c[i]);\n\t\t\t\ta.add(c[i]);\n\t\t\t}\n\t\t\n\t\t\tint x=Collections.frequency(a,'0' );\n\t\t\tint y=Collections.frequency(a,'1');\n\t\t\t\n\t\t\t//System.out.println(x+ \"  \"+y );\n\t\t\tif(y==0 || y==1)\n\t\t\t{\n\t\t\t\tSystem.out.println(s);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(y>=2)\n\t\t\t\t{\n\t\t\t\t\tString s1=\"1\";\n\t\t\t\t\tfor(int i=0;i<x;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\ts1=s1+\"0\";\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(s1);\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\n\t\t\t\n\t\t\t\n\t\t\t\n\t}\n\n}", "complexity": "linear", "problem": "976_A. Minimum Binary Number", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Waw{\n    \n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        long[] a = new long[n];\n        for(int i=0;i<n;i++) a[i] = sc.nextLong();\n        long[] p = new long[n];\n        p[n-1] = a[n-1];\n        for(int i=n-2;i>=0;i--){\n            if(a[i]<p[i+1]) p[i] = p[i+1]-1;\n            else p[i] = a[i];\n        }\n        long max = p[0];\n        long res = p[0] - a[0];\n        for(int i=1;i<n;i++){\n            if(max < p[i]) max = p[i];\n            res += max - a[i];\n        }\n        System.out.println(res);\n    }\n}", "complexity": "linear", "problem": "924_C. Riverside Curio", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class Code {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\t BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t int n = Integer.parseInt(br.readLine());\n\t\t HashMap<Double,Integer>h = new HashMap<>();\n\t\t double [] temp = new double[n];\n\t\t int m = 0;\n\t\t for(int i=0;i<n;i++) {\n\t\t\t String l = br.readLine();\n\t\t\t int[] x = new int[4];\n\t\t\t int k=0;\n\t\t\t boolean t = false;\n\t\t\t for(int j=0;j<l.length();j++) {\n\t\t\t\t if(l.charAt(j)=='(' || l.charAt(j)=='+' || l.charAt(j)==')' || l.charAt(j)=='/')\n\t\t\t\t\t x[k++] = j;\n\t\t\t }\n\t\t\t double a = Integer.parseInt(l.substring(x[0]+1,x[1]));\n\t\t\t double b = Integer.parseInt(l.substring(x[1]+1, x[2]));\n\t\t\t double c = Integer.parseInt(l.substring(x[3]+1));\n\t\t\t temp[m++] = (a+b)/c;\n\t\t\t //System.out.print((a+b)/c + \" \");\n\t\t\tif(h.containsKey((a+b)/c))\n\t\t\t\t\th.put((a+b)/c, h.get((a+b)/c)+1);\n\t\t\telse\n\t\t\t\th.put((a+b)/c, 1);\n\t\t }\n\t\t //System.out.println(h);\n\t\t for(int i=0;i<n;i++) {\n\t\t\t System.out.print(h.get(temp[i]) + \" \");\n\t\t }\n\t}\n\t}\n", "complexity": "linear", "problem": "958_D1. Hyperspace Jump (easy)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.List;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {\n            Debug debug = new Debug();\n            int n = in.nextInt();\n            int K = in.nextInt();\n\n            List<Integer>[] g = GraphUtils.nextU(in, n, n - 1, true);\n            int[] center = GraphUtils.getCenter(g);\n            if (center.length == 2) {\n                out.println(\"No\");\n                return;\n            }\n\n            int[][] pars = GraphUtils.parents3(g, center[0]);\n            int[] par = pars[0], ord = pars[1], depth = pars[2];\n            int[] deg = new int[n];\n            for (int i = 0; i < n; ++i) deg[i] = g[i].size();\n\n            if (deg[center[0]] < 3) {\n                out.println(\"No\");\n                return;\n            }\n\n            // all leaves depth = K\n            for (int i = 0; i < n; ++i) {\n                if (deg[i] == 1) {\n                    if (depth[i] != K) {\n                        out.println(\"No\");\n                        return;\n                    }\n                } else if (i != center[0]) {\n                    if (deg[i] < 4) {\n                        out.println(\"No\");\n                        return;\n                    }\n                }\n            }\n            out.println(\"Yes\");\n        }\n\n    }\n\n    static class GraphUtils {\n        public static List<Integer>[] nextU(FastReader in, int n, int m, boolean oneIndexed) {\n            int diff = oneIndexed ? 1 : 0;\n            List<Integer>[] g = new List[n];\n            for (int i = 0; i < n; ++i) g[i] = new ArrayList<>();\n            for (int i = 0; i < m; ++i) {\n                int u = in.nextInt() - diff;\n                int v = in.nextInt() - diff;\n                g[u].add(v);\n                g[v].add(u);\n            }\n            return g;\n        }\n\n        public static int[][] parents3(List<Integer>[] g, int root) {\n            int n = g.length;\n            int[] par = new int[n];\n            ArrayUtils.fill(par, -1);\n\n            int[] depth = new int[n];\n            depth[0] = 0;\n\n            int[] q = new int[n];\n            q[0] = root;\n            for (int p = 0, r = 1; p < r; p++) {\n                int cur = q[p];\n                for (int nex : g[cur]) {\n                    if (par[cur] != nex) {\n                        q[r++] = nex;\n                        par[nex] = cur;\n                        depth[nex] = depth[cur] + 1;\n                    }\n                }\n            }\n            return new int[][]{par, q, depth};\n        }\n\n        public static int[] getCenter(List<Integer>[] g) {\n            int n = g.length;\n            int[] q = new int[n];\n            int[] deg = new int[n];\n            int p = 0;\n            for (int i = 0; i < n; i++) {\n                deg[i] = g[i].size();\n                if (g[i].size() <= 1) { // < for n=1\n                    q[p++] = i;\n                }\n            }\n            int bound = p == n ? 0 : p;\n            for (int z = 0; z < p; z++) {\n                if (bound == z && p < n) bound = p;\n                int cur = q[z];\n                deg[cur]--;\n                for (int e : g[cur]) {\n                    if (--deg[e] == 1) q[p++] = e;\n                }\n            }\n            assert p == n;\n            assert bound >= n - 2 && bound < n;\n            if (bound == n - 2) {\n                return new int[]{q[n - 2], q[n - 1]};\n            } else {\n                return new int[]{q[n - 1]};\n            }\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static void fill(int[] array, int value) {\n            Arrays.fill(array, value);\n        }\n\n    }\n\n    static class Debug {\n        PrintWriter out;\n        boolean oj;\n        boolean system;\n        long timeBegin;\n        Runtime runtime;\n\n        public Debug(PrintWriter out) {\n            oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            this.out = out;\n            this.timeBegin = System.currentTimeMillis();\n            this.runtime = Runtime.getRuntime();\n        }\n\n        public Debug() {\n            system = true;\n            oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            OutputStream outputStream = System.out;\n            this.out = new PrintWriter(outputStream);\n            this.timeBegin = System.currentTimeMillis();\n            this.runtime = Runtime.getRuntime();\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1067_B. Multihedgehog", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringJoiner;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class Main {\n\n    static String S;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        S = sc.next();\n\n        System.out.println(solve());\n    }\n\n    static int solve() {\n        int ans = -1;\n        int time = 1;\n        int n = S.length();\n        for (int i = 1; i < n*2; i++) {\n            if( S.charAt((i-1)%n) != S.charAt(i%n) ) {\n                time++;\n            } else {\n                ans = Math.max(time, ans);\n                time = 1;\n            }\n        }\n        ans = Math.max(time, ans);\n\n        if( ans == n*2 ) {\n            return n;\n        } else {\n            return ans;\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++)\n                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++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n    }\n\n    static <A> void writeLines(A[] as, Function<A, String> f) {\n        PrintWriter pw = new PrintWriter(System.out);\n        for (A a : as) {\n            pw.println(f.apply(a));\n        }\n        pw.flush();\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 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 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", "complexity": "linear", "problem": "1025_C. Plasticine zebra", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n    public static void main(String str[]) throws Exception{\n        Scanner sc = new Scanner(System.in);\n        BufferedWriter output = new BufferedWriter(\n                new OutputStreamWriter(System.out));\n        int t = sc.nextInt();\n        while(t-->0){\n            int n = sc.nextInt();\n            if((n%2==0 && Math.pow(n/2,0.5)%1.0==0) || (n%4==0 && Math.pow(n/4,0.5)%1.0==0) )  output.write(\"YES\\n\");\n            else {\n                output.write(\"NO\\n\");\n            }\n        }\n        output.flush();\n    }\n\n}\n\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//package global14;\nimport java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class B {\n\tInputStream is;\n\tFastWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni();T > 0;T--)go();\n\t}\n\n\tvoid go()\n\t{\n\t\tint n = ni();\n\t\tif(n % 2 == 0){\n\t\t\tint u = (int)Math.sqrt(n/2);\n\t\t\tif(u*u == n/2){\n\t\t\t\tout.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif(n % 4 == 0){\n\t\t\tint u = (int)Math.sqrt(n/4);\n\t\t\tif(u*u == n/4){\n\t\t\t\tout.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"NO\");\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 FastWriter(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 B().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\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 char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[][] nmi(int n, int m) {\n\t\tint[][] map = new int[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\n\t\treturn map;\n\t}\n\n\tprivate int ni() { return (int)nl(); }\n\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\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\tpublic static class FastWriter\n\t{\n\t\tprivate static final int BUF_SIZE = 1<<13;\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\n\t\tprivate final OutputStream out;\n\t\tprivate int ptr = 0;\n\n\t\tprivate FastWriter(){out = null;}\n\n\t\tpublic FastWriter(OutputStream os)\n\t\t{\n\t\t\tthis.out = os;\n\t\t}\n\n\t\tpublic FastWriter(String path)\n\t\t{\n\t\t\ttry {\n\t\t\t\tthis.out = new FileOutputStream(path);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter write(byte b)\n\t\t{\n\t\t\tbuf[ptr++] = b;\n\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(char c)\n\t\t{\n\t\t\treturn write((byte)c);\n\t\t}\n\n\t\tpublic FastWriter write(char[] s)\n\t\t{\n\t\t\tfor(char c : s){\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(String s)\n\t\t{\n\t\t\ts.chars().forEach(c -> {\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t});\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(int l) {\n\t\t\tif (l >= 1000000000) return 10;\n\t\t\tif (l >= 100000000) return 9;\n\t\t\tif (l >= 10000000) return 8;\n\t\t\tif (l >= 1000000) return 7;\n\t\t\tif (l >= 100000) return 6;\n\t\t\tif (l >= 10000) return 5;\n\t\t\tif (l >= 1000) return 4;\n\t\t\tif (l >= 100) return 3;\n\t\t\tif (l >= 10) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(int x)\n\t\t{\n\t\t\tif(x == Integer.MIN_VALUE){\n\t\t\t\treturn write((long)x);\n\t\t\t}\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(long l) {\n\t\t\tif (l >= 1000000000000000000L) return 19;\n\t\t\tif (l >= 100000000000000000L) return 18;\n\t\t\tif (l >= 10000000000000000L) return 17;\n\t\t\tif (l >= 1000000000000000L) return 16;\n\t\t\tif (l >= 100000000000000L) return 15;\n\t\t\tif (l >= 10000000000000L) return 14;\n\t\t\tif (l >= 1000000000000L) return 13;\n\t\t\tif (l >= 100000000000L) return 12;\n\t\t\tif (l >= 10000000000L) return 11;\n\t\t\tif (l >= 1000000000L) return 10;\n\t\t\tif (l >= 100000000L) return 9;\n\t\t\tif (l >= 10000000L) return 8;\n\t\t\tif (l >= 1000000L) return 7;\n\t\t\tif (l >= 100000L) return 6;\n\t\t\tif (l >= 10000L) return 5;\n\t\t\tif (l >= 1000L) return 4;\n\t\t\tif (l >= 100L) return 3;\n\t\t\tif (l >= 10L) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(long x)\n\t\t{\n\t\t\tif(x == Long.MIN_VALUE){\n\t\t\t\treturn write(\"\" + x);\n\t\t\t}\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(double x, int precision)\n\t\t{\n\t\t\tif(x < 0){\n\t\t\t\twrite('-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tx += Math.pow(10, -precision)/2;\n\t\t\t//\t\tif(x < 0){ x = 0; }\n\t\t\twrite((long)x).write(\".\");\n\t\t\tx -= (long)x;\n\t\t\tfor(int i = 0;i < precision;i++){\n\t\t\t\tx *= 10;\n\t\t\t\twrite((char)('0'+(int)x));\n\t\t\t\tx -= (int)x;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(char c){\n\t\t\treturn write(c).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(int x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(double x, int precision){\n\t\t\treturn write(x, precision).writeln();\n\t\t}\n\n\t\tpublic FastWriter write(int... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(int x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(long... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(long x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln()\n\t\t{\n\t\t\treturn write((byte)'\\n');\n\t\t}\n\n\t\tpublic FastWriter writeln(int... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[] line)\n\t\t{\n\t\t\treturn write(line).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[]... map)\n\t\t{\n\t\t\tfor(char[] line : map)write(line).writeln();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(String s)\n\t\t{\n\t\t\treturn write(s).writeln();\n\t\t}\n\n\t\tprivate void innerflush()\n\t\t{\n\t\t\ttry {\n\t\t\t\tout.write(buf, 0, ptr);\n\t\t\t\tptr = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic void flush()\n\t\t{\n\t\t\tinnerflush();\n\t\t\ttry {\n\t\t\t\tout.flush();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"flush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter print(byte b) { return write(b); }\n\t\tpublic FastWriter print(char c) { return write(c); }\n\t\tpublic FastWriter print(char[] s) { return write(s); }\n\t\tpublic FastWriter print(String s) { return write(s); }\n\t\tpublic FastWriter print(int x) { return write(x); }\n\t\tpublic FastWriter print(long x) { return write(x); }\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\n\t\tpublic FastWriter println(char c){ return writeln(c); }\n\t\tpublic FastWriter println(int x){ return writeln(x); }\n\t\tpublic FastWriter println(long x){ return writeln(x); }\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\n\t\tpublic FastWriter println(String s) { return writeln(s); }\n\t\tpublic FastWriter println() { return writeln(); }\n\t}\n\n\tpublic void trnz(int... 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// print ids which are 1\n\tpublic void trt(long... o)\n\t{\n\t\tQueue<Integer> stands = new ArrayDeque<>();\n\t\tfor(int i = 0;i < o.length;i++){\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\n\t\t}\n\t\tSystem.out.println(stands);\n\t}\n\n\tpublic 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\tpublic void tf(boolean[]... b)\n\t{\n\t\tfor(boolean[] r : b) {\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\n\t\t\tSystem.out.println();\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic void tf(long[]... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long[] r : b) {\n\t\t\t\tfor (long x : r) {\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\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\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic void tf(long... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long x : b) {\n\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\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", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//2021 global14\n\n// jzzhao\n\nimport java.util.*;\nimport java.io.*;\n\npublic class Solution {\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n       \n        int tc = sc.ni();\n        for (int rep = 0; rep < tc; rep++) {\n            pw.println(solve(sc,pw));\n            //solve(sc,pw);\n        }\n        \n        \n        pw.close();\n    }\n    /*\n\n    FS Methods:\n\n    - next(): next element in string\n    - nextLine(): nextline in string\n    - ni(): next Integer\n    - nd(): next Double\n    - nl(): next Long\n    - intArray(n): \n    - longArray(n): \n    - to2di(m,n):\n    - to2dl(m,n):\n\n\n\n    */\n\n          \n    public static String solve(FastScanner sc, PrintWriter pw) {\n\n        int n = sc.ni();\n\n        long cur1 = 2;\n        long cur2 = 4;\n\n        long block = 2;\n        long block2 = 4;\n\n        int tmp = 3;\n\n        while(cur1<=n||cur2<=n){\n            if(cur1==n||cur2==n){\n                return \"YES\";\n            }\n            if(cur1<n){\n                cur1+=block*tmp;\n\n            }\n            if(cur2<n){\n                cur2+=block2*tmp;\n            }\n            tmp+=2;\n\n        }\n        return \"NO\";\n\n\n        //return \"NO\";\n\n\n    }\n\n    /*\n        - The following are helping method so pls do not do anything to them.\n    \n    */\n\n    // public static int[][] to2d(Scanner scanner, int m, int n){\n    //     int[][] ans = new int[m][n];\n    //     for(int i = 0;i<m;i++){\n    //         String[] r = scanner.nextLine().split(\"[ ]\");\n    //         for(int j = 0;j<n;j++){\n    //             ans[i][j] = stoi(r[j]);\n    //         }\n    //     }\n    //     return ans;\n    // }\n\n    // public static int[] toArray(Scanner scanner, int m){\n    //     int[] ans = new int[m];\n    //     String[] r = scanner.nextLine().split(\"[ ]\");\n    //     for(int i = 0;i<m;i++){\n    //         ans[i] = stoi(r[i]);\n    //     }\n        \n    //     return ans;\n    // }\n\n    public static void printArr(PrintWriter pw,int[] a){\n        for(int i = 0;i<a.length;i++){\n            pw.print(a[i]);\n            if(i!=a.length-1){\n                pw.print(\" \");\n            }\n        }\n        pw.println();\n    }\n\n    public static void print2d(PrintWriter pw,int[][] a){\n        for(int j=0;j<a.length;j++){\n            for(int i = 0;i<a[j].length;i++){\n                pw.print(a[j][i]);\n                if(i!=a[j].length-1){\n                    pw.print(\" \");\n                }\n            }\n            pw.println(\" \");\n        }\n        pw.println();\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    static long gcd(long a, long b) {\n        if (a == 0) return b;\n        return gcd(b % a, a);\n    }\n\n    public static int stoi(String s){\n        return Integer.parseInt(s);\n    }\n}\n\nclass FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n \n    public FastScanner() {\n        br = new BufferedReader(new InputStreamReader(System.in), 32768);\n        st = null;\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        }\n        return st.nextToken();\n    }\n \n    int ni() {\n        return Integer.parseInt(next());\n    }\n \n    int[] intArray(int N) {\n        int[] ret = new int[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = ni();\n        return ret;\n    }\n\n    int[][] to2di(int m, int n){\n        int[][] ans = new int[m][n];\n        for(int i = 0;i<m;i++){\n            String[] r = nextLine().split(\"[ ]\");\n            for(int j = 0;j<n;j++){\n                ans[i][j] = Integer.parseInt(r[j]);\n            }\n        }\n        return ans;\n    }\n\n    long[][] to2dl(int m, int n){\n        long[][] ans = new long[m][n];\n        for(int i = 0;i<m;i++){\n            String[] r = nextLine().split(\"[ ]\");\n            for(int j = 0;j<n;j++){\n                ans[i][j] = Long.parseLong(r[j]);\n            }\n        }\n        return ans;\n    }\n \n    long nl() {\n        return Long.parseLong(next());\n    }\n \n    long[] longArray(int N) {\n        long[] ret = new long[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = nl();\n        return ret;\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", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\n public  class  AA{\n\t\tpublic static void main(String[] args) {\n\t\t\tScanner sc=new Scanner(System.in);\n\t\t    int t=0;\n\t\t    if(sc.hasNextInt()) {\n\t\t    \tt=sc.nextInt();\n\t\t    }\n\t\t    while(t>0) {\n\t\t    \tt--;\n\t\t\t\t int n=sc.nextInt();\n\t\t\t\t String ans=\"NO\";\n\t\t\t\t if(n%2==0) {\n\t\t\t\t\t int p=n/2;\n\t\t\t\t\t if(Math.ceil(Math.sqrt((double)p)) == Math.floor(Math.sqrt((double)p))){\n\t\t\t\t\t\t ans=\"YES\";\n\t\t\t\t\t }\n\t\t\t\t\t else {\n\t\t\t\t\t\t if(n%4==0) {\n\t\t\t\t\t\t\t p=n/4;\n\t\t\t\t\t\t\t if(Math.ceil(Math.sqrt((double)p)) == Math.floor(Math.sqrt((double)p))){\n\t\t\t\t\t\t\t\t ans=\"YES\";\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t }\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t\t System.out.println(ans);\n\t\t    }\n\t\t}\n  }", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//package Round14Global;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class phoenixandpuzzle {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader fin = new BufferedReader(new InputStreamReader(System.in));\n\t\tint t = Integer.parseInt(fin.readLine());\n\t\tStringBuilder fout = new StringBuilder();\n\t\tHashSet<Integer> dict = new HashSet<Integer>();\n\t\tint pointer = 1;\n\t\tint area = 0;\n\t\twhile(area >= 0) {\n\t\t\tarea = (pointer * pointer) * 2;\n\t\t\tdict.add(area);\n\t\t\tpointer ++;\n\t\t}\n\t\tpointer = 1;\n\t\tarea = 0;\n\t\twhile(area >= 0) {\n\t\t\tarea = (pointer * pointer) * 4;\n\t\t\tdict.add(area);\n\t\t\tpointer ++;\n\t\t}\n\t\twhile(t-- > 0) {\n\t\t\tint n = Integer.parseInt(fin.readLine());\n\t\t\tif(dict.contains(n)) {\n\t\t\t\tfout.append(\"YES\\n\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfout.append(\"NO\\n\");\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(fout);\n\t}\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//\u0628\u0633\u0645 \u0627\u0644\u0644\u0647 \u0627\u0644\u0631\u062d\u0645\u0646 \u0627\u0644\u0631\u062d\u064a\u0645\nimport java.util.*;\nimport java.lang.*;\nimport java.nio.*;\nimport java.io.*;\npublic class as {\n\tstatic class Reader \n    { \n        final private int BUFFER_SIZE = 1 << 16; \n        private DataInputStream din; \n        private byte[] buffer; \n        private int bufferPointer, bytesRead; \n  \n        public Reader() \n        { \n            din = new DataInputStream(System.in); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public Reader(String file_name) throws IOException \n        { \n            din = new DataInputStream(new FileInputStream(file_name)); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public String readLine() throws IOException \n        { \n            byte[] buf = new byte[100000000]; // line length \n            int cnt = 0, c; \n            while ((c = read()) != -1) \n            { \n                if (c == '\\n') \n                    break; \n                buf[cnt++] = (byte) c; \n            } \n            return new String(buf, 0, cnt); \n        } \n  \n        public int nextInt() throws IOException \n        { \n            int ret = 0; \n            byte c = read(); \n            while (c <= ' ') \n                c = read(); \n            boolean neg = (c == '-'); \n            if (neg) \n                c = read(); \n            do\n            { \n                ret = ret * 10 + c - '0'; \n            }  while ((c = read()) >= '0' && c <= '9'); \n  \n            if (neg) \n                return -ret; \n            return ret; \n        } \n  \n        public long nextLong() throws IOException \n        { \n            long ret = 0; \n            byte c = read(); \n            while (c <= ' ') \n                c = read(); \n            boolean neg = (c == '-'); \n            if (neg) \n                c = read(); \n            do { \n                ret = ret * 10 + c - '0'; \n            } \n            while ((c = read()) >= '0' && c <= '9'); \n            if (neg) \n                return -ret; \n            return ret; \n        } \n  \n        public double nextDouble() throws IOException \n        { \n            double ret = 0, div = 1; \n            byte c = read(); \n            while (c <= ' ') \n                c = read(); \n            boolean neg = (c == '-'); \n            if (neg) \n                c = read(); \n  \n            do { \n                ret = ret * 10 + c - '0'; \n            } \n            while ((c = read()) >= '0' && c <= '9'); \n  \n            if (c == '.') \n            { \n                while ((c = read()) >= '0' && c <= '9') \n                { \n                    ret += (c - '0') / (div *= 10); \n                } \n            } \n  \n            if (neg) \n                return -ret; \n            return ret; \n        } \n  \n        private void fillBuffer() throws IOException \n        { \n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n            if (bytesRead == -1) \n                buffer[0] = -1; \n        } \n  \n        private byte read() throws IOException \n        { \n            if (bufferPointer == bytesRead) \n                fillBuffer(); \n            return buffer[bufferPointer++]; \n        } \n  \n        public void close() throws IOException \n        { \n            if (din == null) \n                return; \n            din.close(); \n        } \n    } \n\t/////////////////////////////////////////////////////////////\n\tpublic static void main(String[] args) throws Exception {\n\t\tReader sc=new Reader();\n\t\tStringBuilder finalAnswer=new StringBuilder();\n\t\t//finalAnswer.append(1).append('\\n');\n\t\tint t=sc.nextInt();\n\t\twhile(t-->0) {\n\t\t\tint count=0;\n\t\t\tint n=sc.nextInt();\n\t\t\tif(n==2 || n==4) {\n\t\t\t\tfinalAnswer.append(\"YES\").append('\\n');\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(n%2==0 && count==0){\n\t\t\t\tn/=2;\n\t\t\t\tif((int)Math.sqrt(n)*(int)Math.sqrt(n)==n) {\n\t\t\t\t\tfinalAnswer.append(\"YES\").append('\\n');\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tn*=2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(n%4==0 && count==0) {\n\t\t\t\tn/=4;\n\t\t\t\tif((int)Math.sqrt(n)*(int)Math.sqrt(n)==n) {\n\t\t\t\t\tfinalAnswer.append(\"YES\").append('\\n');\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(count==0){\n\t\t\t\tfinalAnswer.append(\"NO\").append('\\n');\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(finalAnswer);\n\t}\n\t/////////////////////////////////////////////////////////\n\t\n\tpublic static long gcd(long a, long b)\n\t{\n\t    while (b > 0)\n\t    {\n\t        long temp = b;\n\t        b = a % b; // % is remainder\n\t        a = temp;\n\t    }\n\t    return a;\n\t}\n\tpublic static long lcm(long a, long b)\n\t{\n\t    return a * (b / gcd(a, b));\n\t}\n\tstatic boolean containsDigit(int number, int digit)\n\t{\n\t    while (number > 0)\n\t    {\n\t        int curr_digit = number % 10;\n\t        if (curr_digit == digit) return true;\n\t        number /= 10;\n\t    }\n\n\t    return false;\n\t}\n\tstatic boolean isPalindrome(String s) {\n\t\t  int n = s.length();\n\t\t  for (int i = 0; i < (n/2); ++i) {\n\t\t     if (s.charAt(i) != s.charAt(n - i - 1)) {\n\t\t         return false;\n\t\t     }\n\t\t  }\n\n\t\t  return true;\n\t}\n\tvoid sieveOfEratosthenes(int n)\n    {\n        // Create a boolean array \n        // \"prime[0..n]\" and\n        // initialize all entries \n        // it as true. A value in\n        // prime[i] will finally be \n        // false if i is Not a\n        // prime, else true.\n        boolean prime[] = new boolean[n + 1];\n        for (int i = 0; i <= n; i++)\n            prime[i] = true;\n \n        for (int p = 2; p * p <= n; p++) \n        {\n            // If prime[p] is not changed, then it is a\n            // prime\n            if (prime[p] == true) \n            {\n                // Update all multiples of p\n                for (int i = p * p; i <= n; i += p)\n                    prime[i] = false;\n            }\n        }\n \n        // Print all prime numbers\n        for (int i = 2; i <= n; i++)\n        {\n            if (prime[i] == true)\n                System.out.print(i + \" \");\n        }\n    }\n}\n\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main {\n\n    static Scanner sc;\n    static PrintWriter out;\n\n    public static void main(String[] args) {\n        sc = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        int t = 1;\n        if (true) {\n            t = sc.nextInt();\n        }\n        for(int i=0; i<t; i++) {\n            new Main().solve();\n        }\n        out.flush();\n    }\n\n    public void solve() {\n        long n = sc.nextInt();\n        if(n % 2 == 1) {\n            out.println(\"NO\");\n            return;\n        }\n        for(long i=1; i*i*2 <= n; i++) {\n            if(i * i * 2 == n || i * i * 4 == n) {\n                out.println(\"YES\");\n                return;\n            }\n        }\n        out.println(\"NO\");\n\n    }\n\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "///package round_global_14;\n\n\nimport java.io.*;\nimport java.util.*;\n\npublic class B {\n    static class InputReader {\n        BufferedReader buffreader;\n        StringTokenizer strtokenizer;\n        public InputReader(InputStream inputstr) {\n            buffreader = new BufferedReader(new InputStreamReader(inputstr), 1000000);strtokenizer = null; }\n        //////////////////////////////////////////////////////////////////////////////////////////\n        String next() {\n            while (strtokenizer == null || !strtokenizer.hasMoreTokens()) {\n                try { strtokenizer = new StringTokenizer(buffreader.readLine()); }\n                catch (IOException e) { throw new RuntimeException(e); }\n            }\n            return strtokenizer.nextToken(); }\n        ///////////////////////////////////////////////////////////////////////////////////////////\n        public int nextInt() { return Integer.parseInt(next()); }\n        public long nextLong() { return Long.parseLong(next()); }\n        public double nextDouble() { return Double.parseDouble(next()); }\n        public int[] nextIntArr(int n){\n            int[] arr=new int[n];\n            for (int i=0;i<n;i++){arr[i]=nextInt();}\n            return arr;}\n        public long[] nextLongArr(int n){\n            long[] arr=new long[n];\n            for (int i=0;i<n;i++){arr[i]=nextLong();}\n            return arr;}\n        public String[] nextStringArr(int n){\n            String[] arr=new String[n];\n            for (int i=0;i<n;i++){arr[i]=next();}\n            return arr;}\n    }\n    static InputReader r = new InputReader(System.in);\n    static PrintWriter pw = new PrintWriter(System.out);\n    public static void main(String[] args){\n        int t=r.nextInt();\n        for (int v=0;v<t;v++){\n            int n=r.nextInt();\n            if (n%2==1){\n                pw.println(\"NO\");\n            }\n            else{\n                int x=n/2;\n                boolean check=false;\n                for (int i=1;i<=(int)Math.sqrt(x)+1;i++){\n                    if (i*i*2==x||i*i==x){\n                        pw.println(\"YES\");check=true;break;\n                    }\n                }\n                if (!check){\n                    pw.println(\"NO\");\n                }\n            }\n\n\n        }\n        pw.close();\n\n\n    }\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\n\npublic class B {\n\tint mod=1000_000_007;\n\tpublic static void main(String[] args) throws Exception {\n\t\t\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t    FastScanner fs=new FastScanner();\n\t    int t=fs.nextInt();\n\t    while(t-->0) {\n\t    \tdouble n=fs.nextInt();\n\t    \tif(isp(n/2)||isp(n/4)) {\n\t    \t\tSystem.out.println(\"YES\");\n\t    \t}\n\t    \telse System.out.println(\"NO\");\n\t    }\n\t}\n\tstatic boolean isp(double n) {\n\t\tif(n==0) return false;\n\t\tdouble a=Math.ceil(Math.sqrt(n));\n\t\tdouble b=Math.floor(Math.sqrt(n));\n\t\treturn a==b;\n\t}\n\tstatic void mysort(long[] a) {\n\t\t//suffle\n\t\tint n=a.length;\n\t\tRandom r=new Random();\n\t\tfor (int i=0; i<a.length; i++) {\n\t\t\tint oi=r.nextInt(n);\n\t\t\tlong temp=a[i];\n\t\t\ta[i]=a[oi];\n\t\t\ta[oi]=temp;\n\t\t}\n\t\t\n\t\t//then sort\n\t\tArrays.sort(a);\n\t}\n\t\n\t// Use this to input code since it is faster than a Scanner\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<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n \n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.round;\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.StringTokenizer;\n\npublic class B {\n\n\tstatic long sqr(long a) {\n\t\treturn a * a;\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tint n = scanInt();\n\t\t\tout.println(n == 2 * sqr(round(sqrt(n / 2))) || n == 4 * sqr(round(sqrt(n / 4))) ? \"YES\" : \"NO\");\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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Solution {\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader(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 FastReader() {\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        String nextLine() throws IOException {\n            return br.readLine();\n        }\n\n        long nextLong() {\n            return Long.parseLong(nextToken());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(nextToken());\n        }\n\n        float nextFloat() {\n            return Float.parseFloat(nextToken());\n        }\n    }\n\n\n    static FastReader f = new FastReader();\n    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    static StringTokenizer st;\n    static StringBuilder sb = new StringBuilder();\n    static long[] fact;\n\n    static int[] inputArray(int n) throws IOException {\n        int[] a = new int[n];\n        for(int i = 0 ; i < n ; i++) {\n//            a[i] = (int) (Math.random()*1e5 + 1);\n            a[i] = f.nextInt();\n        }\n        return a;\n    }\n    static long[] inputLongArray(int n) throws IOException {\n        long[] a = new long[n];\n        for(int i = 0 ; i < n ; i++) {\n            a[i] = f.nextLong();\n//            a[i] = (long) (Math.random() * 1e9 + 1);\n        }\n        return a;\n    }\n\n    static long gcd(long a , long b) {\n        if(a == 0 || b == 0) {\n            return Math.max(a , b);\n        }\n        //System.out.println(\"a - \" + a + \" b - \" + b);\n        if(a % b == 0) {\n            return b;\n        }\n        return gcd(b , a % b);\n    }\n\n    static void initializeFact() {\n        fact = new long[MAX_N];\n        for(int i = 0 ; i < fact.length ; i++) {\n            if(i == 0) {\n                fact[i] = 1;\n            }\n            else {\n                fact[i] = fact[i-1] * i % mod;\n            }\n        }\n    }\n\n    static long longModulus(long x , long m) {\n        if(x < m) {\n            return x;\n        }\n        long d = x / m;\n        return x - d * m;\n    }\n\n\n    static BitSet sieveOfEratosthenes(int n)\n    {\n        BitSet isPrime = new BitSet(n+1);\n        isPrime.set(0, n + 1);\n        isPrime.set(0);\n        isPrime.set(1);\n        for(int i = 2; i * i <= n ; i++)\n        {\n            if(isPrime.get(i))\n                for(int j = i * i ; j <= n; j += i)\n                    isPrime.clear(j);\n        }\n        return isPrime;\n    }\n\n    static long moduloInversePrime(long a) {\n        //System.out.println(\"modulo inverse of \" + a + \" -> \" + ans);\n        return modPow(a , mod - 2);\n    }\n\n    static long mult(long a, long b)\n    {\n        return (a * b % mod);\n    }\n\n    static long modPow(long a, int step)\n    {\n        long ans = 1;\n        while(step != 0)\n        {\n            if((step & 1) != 0)\n                ans = mult(ans , a);\n            a = mult(a , a);\n            step >>= 1;\n        }\n        return ans;\n    }\n\n    static int query(int l , int r) {\n        System.out.println(\"? \" + l + \" \" + r);\n        System.out.flush();\n        return f.nextInt();\n    }\n\n    static int sum(int n) {\n        return n * (n + 1) / 2;\n    }\n\n    private static final int mod = (int) (1e9 + 7);\n    static int MAX_N = (int) Math.sqrt(1e9);\n\n\n    public static void main(String[] args) throws IOException {\n        int test = f.nextInt();\n\n//        System.out.println(MAX_N);\n\n        TreeSet<Integer> set = new TreeSet<>();\n        for(int i = 1 ; i <= MAX_N ; i++) {\n            set.add(i*i*2);\n            set.add(i*i*4);\n        }\n\n//        System.out.println(set);\n\n        for(int t = 1 ; t <= test ; t++) {\n            int n = f.nextInt();\n            if(set.contains(n)) {\n                sb.append(\"YES\").append(\"\\n\");\n            }\n            else {\n                sb.append(\"NO\").append(\"\\n\");\n            }\n\n        }\n        System.out.println(sb);\n    }\n\n\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class p2 {\n\tfinal static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static String ss() throws IOException {return br.readLine();}\t\n\tprivate static int stoi(String x) {return Integer.parseInt(x);}\n\tprivate static int si() throws IOException {return stoi(ss());}\n\tprivate static long sl() throws IOException {return Long.parseLong(ss());}\t\n\tprivate static int[] sia(int len) throws IOException {\n\t\tint[] ret = new int[len];\n\t\tfinal StringTokenizer st = new StringTokenizer(ss());\n\t\tfor (int i = 0; i < len; ++i) {ret[i] = stoi(st.nextToken());}\n\t\treturn ret;\n\t}\n\tprivate static long[] sla(int len) throws IOException {\n\t\tlong[] ret = new long[len];\n\t\tfinal StringTokenizer st = new StringTokenizer(ss());\n\t\tfor (int i = 0; i < len; ++i) {ret[i] = Long.parseLong(st.nextToken());}\n\t\treturn ret;\n\t}\n\t\n\tpublic static void main (final String[] args) throws IOException {\n\t\t//goal is to always be higher\n\t\tSet<Integer> poss = new HashSet<>();\n\t\tfor (int i = 1; 2 * (i*i) <= 1000000000; ++i) {\n\t\t\tposs.add(2 * (i*i));\n\t\t\tposs.add(4 * (i*i));\n\t\t}\n\t\tint t = si();\n\t\tfor (int i = 0; i < t; ++i) {\n\t\t\tint n = si();\n\t\t\tif (poss.contains(n)) System.out.println(\"YES\");\n\t\t\telse System.out.println(\"NO\");\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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\n\npublic class Main{\n\n    static long MOD = 1_000_000_007L;\n    //static long MOD = 998_244_353L;\n    //static long MOD = 1_000_000_033L;\n    static long inv2 = (MOD + 1) / 2;\n\n    static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n    static long lMax = 0x3f3f3f3f3f3f3f3fL;\n    static int iMax = 0x3f3f3f3f;\n    static HashMap <Long, Long> memo = new HashMap();\n    static MyScanner sc = new MyScanner();\n    //static ArrayList <Integer> primes;\n\n    static int nn = 300000;\n    static long[] pow2;\n    static long [] fac;\n    static long [] pow;\n    static long [] inv;\n    static long [] facInv;\n    static int[] base;\n    static int[] numOfDiffDiv;\n    static int[] numOfDiv;\n    static ArrayList <Integer> primes;\n    //static int[] primes;\n    static int ptr = 0;\n    static boolean[] isPrime;\n\n    //-----------PrintWriter for faster output---------------------------------\n    public static PrintWriter out;\n    public static void main(String[] args) {\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n        // Start writing your solution here. -------------------------------------\n\n\n\n        /*fac = new long[nn + 1];\n        fac[1] = 1;\n        for(int i = 2; i <= nn; i++)\n            fac[i] = fac[i - 1] * i % MOD;*/\n\n\n        /*pow2 = new long[nn + 1];\n        pow2[0] = 1L;\n        for(int i = 1; i <= nn; i++)\n            pow2[i] = pow2[i - 1] * 2L;*/\n\n\n        /*inv = new long[nn + 1];\n        inv[1] = 1;\n        for (int i = 2; i <= nn; ++i)\n            inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/\n\n        /*facInv = new long[nn + 1];\n        facInv[0] = facInv[1] = 1;\n        for (int i = 2; i <= nn; ++i)\n            facInv[i] = facInv[i - 1] * inv[i] % MOD;*/\n\n\n        /*numOfDiffDiv = new int[nn + 1];\n        for(int i = 2; i <= nn; i++)\n            if(numOfDiffDiv[i] == 0)\n                for(int j = i; j <= nn; j += i)\n                    numOfDiv[j] ++;*/\n\n        /*numOfDiv = new int[nn + 1];\n        numOfDiv[1] = 1;\n        for(int i = 2; i <= nn; i++) {\n            for(int j = 2; j * j <= i; j++) {\n                if(i % j == 0) {\n                    numOfDiv[i] = numOfDiv[i / j] + 1;\n                    break;\n                }\n            }\n        }*/\n\n        //primes = sieveOfEratosthenes(100001);\n\n        /*\n        int t = 1;\n        //t = sc.ni();\n        while(t-- > 0) {\n            //boolean res = solve();\n            //out.println(res ? \"YES\" : \"NO\");\n            long res = solve();\n            out.println(res);\n        }*/\n\n\n        int t = 1, tt = 0;\n        t = sc.ni();\n        for(int i = 1; i <40000; i++) squares.add(i * i);\n        while(tt++ < t) {\n            boolean res = solve();\n            //out.println(\"Case #\" + tt + \": \" + res);\n            out.println(res ? \"YES\" : \"NO\");\n        }\n        out.close();\n    }\n    static HashSet <Integer> squares = new HashSet();\n\n    static boolean solve() {\n        /*String s = sc.nextLine();\n        char[] c = s.toCharArray();\n        int n = c.length;*/\n        //int n = sc.ni();\n        //long[] a =  new long[n];\n        //for(int i = 0; i < n; i++) a[i] = sc.nl();\n        long res = 0;\n        int n = sc.ni();\n        if(n % 2 == 0 && squares.contains(n / 2)) return true;\n        if(n % 4 == 0 && squares.contains(n / 4)) return true;\n        return false;\n    }\n\n    // edges to adjacency list by uwi\n    public static int[][] packU(int n, int[] from, int[] to) {\n        return packU(n, from, to, from.length);\n    }\n\n    public static int[][] packU(int n, int[] from, int[] to, int sup) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int i = 0; i < sup; i++) p[from[i]]++;\n        for (int i = 0; i < sup; i++) p[to[i]]++;\n        for (int i = 0; i < n; i++) g[i] = new int[p[i]];\n        for (int i = 0; i < sup; i++) {\n            g[from[i]][--p[from[i]]] = to[i];\n            g[to[i]][--p[to[i]]] = from[i];\n        }\n        return g;\n    }\n\n    // tree diameter by uwi\n    public static int[] diameter(int[][] g) {\n        int n = g.length;\n        int f0 = -1, f1 = -1, d01 = -1;\n        int[] q = new int[n];\n        boolean[] ved = new boolean[n];\n        {\n            int qp = 0;\n            q[qp++] = 0; ved[0] = true;\n            for(int i = 0;i < qp;i++){\n                int cur = q[i];\n                for(int e : g[cur]){\n                    if(!ved[e]){\n                        ved[e] = true;\n                        q[qp++] = e;\n                        continue;\n                    }\n                }\n            }\n            f0 = q[n-1];\n        }\n        {\n            int[] d = new int[n];\n            int qp = 0;\n            Arrays.fill(ved, false);\n            q[qp++] = f0; ved[f0] = true;\n            for(int i = 0;i < qp;i++){\n                int cur = q[i];\n                for(int e : g[cur]){\n                    if(!ved[e]){\n                        ved[e] = true;\n                        q[qp++] = e;\n                        d[e] = d[cur] + 1;\n                        continue;\n                    }\n                }\n            }\n            f1 = q[n-1];\n            d01 = d[f1];\n        }\n        return new int[]{d01, f0, f1};\n    }\n\n    public static long c(int n, int k) {\n        return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;\n    }\n\n\n    // SegmentTree range min/max query by uwi\n    public static class SegmentTreeRMQ {\n        public int M, H, N;\n        public int[] st;\n\n        public SegmentTreeRMQ(int n)\n        {\n            N = n;\n            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n            H = M>>>1;\n            st = new int[M];\n            Arrays.fill(st, 0, M, Integer.MAX_VALUE);\n        }\n\n        public SegmentTreeRMQ(int[] a)\n        {\n            N = a.length;\n            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n            H = M>>>1;\n            st = new int[M];\n            for(int i = 0;i < N;i++){\n                st[H+i] = a[i];\n            }\n            Arrays.fill(st, H+N, M, Integer.MAX_VALUE);\n            for(int i = H-1;i >= 1;i--)propagate(i);\n        }\n\n        public void update(int pos, int x)\n        {\n            st[H+pos] = x;\n            for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);\n        }\n\n        private void propagate(int i)\n        {\n            st[i] = Math.min(st[2*i], st[2*i+1]);\n        }\n\n        public int minx(int l, int r){\n            int min = Integer.MAX_VALUE;\n            if(l >= r)return min;\n            while(l != 0){\n                int f = l&-l;\n                if(l+f > r)break;\n                int v = st[(H+l)/f];\n                if(v < min)min = v;\n                l += f;\n            }\n\n            while(l < r){\n                int f = r&-r;\n                int v = st[(H+r)/f-1];\n                if(v < min)min = v;\n                r -= f;\n            }\n            return min;\n        }\n\n        public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}\n\n        private int min(int l, int r, int cl, int cr, int cur)\n        {\n            if(l <= cl && cr <= r){\n                return st[cur];\n            }else{\n                int mid = cl+cr>>>1;\n                int ret = Integer.MAX_VALUE;\n                if(cl < r && l < mid){\n                    ret = Math.min(ret, min(l, r, cl, mid, 2*cur));\n                }\n                if(mid < r && l < cr){\n                    ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));\n                }\n                return ret;\n            }\n        }\n    }\n\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;}\n\n    public static double dist(double a, double b){\n        return Math.sqrt(a * a + b * b);\n    }\n\n    public static long inv(long a){\n        return quickPOW(a, MOD - 2);\n    }\n\n    public class Interval {\n        int start;\n        int end;\n        public Interval(int start, int end) {\n            this.start = start;\n            this.end = end;\n        }\n    }\n\n    public static ArrayList<Integer> sieveOfEratosthenes(int n) {\n        boolean prime[] = new boolean[n + 1];\n        Arrays.fill(prime, true);\n        for (int p = 2; p * p <= n; p++) {\n            if (prime[p]) {\n                for (int i = p * 2; i <= n; i += p) {\n                    prime[i] = false;\n                }\n            }\n        }\n        ArrayList<Integer> primeNumbers = new ArrayList<>();\n        for (int i = 2; i <= n; i++) {\n            if (prime[i]) {\n                primeNumbers.add(i);\n            }\n        }\n        return primeNumbers;\n    }\n\n\n    public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n    public static int lowerBound(int[] a, int l, int r, int v)\n    {\n        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n        int low = l-1, high = r;\n        while(high-low > 1){\n            int h = high+low>>>1;\n            if(a[h] >= v){\n                high = h;\n            }else{\n                low = h;\n            }\n        }\n        return high;\n    }\n    public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n    public static int rlowerBound(int[] a, int l, int r, int v)\n    {\n        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n        int low = l-1, high = r;\n        while(high-low > 1){\n            int h = high+low>>>1;\n            if(a[h] <= v){\n                high = h;\n            }else{\n                low = h;\n            }\n        }\n        return high;\n    }\n    public static long C(int n, int m)\n    {\n        if(m == 0 || m == n) return 1l;\n        if(m > n || m < 0) return 0l;\n        long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;\n\n        return res;\n    }\n    public static long quickPOW(long n, long m)\n    {\n        long ans = 1l;\n        while(m > 0)\n        {\n            if(m % 2 == 1)\n                ans = (ans * n) % MOD;\n            n = (n * n) % MOD;\n            m >>= 1;\n        }\n        return ans;\n    }\n    public static long quickPOW(long n, long m, long mod)\n    {\n        long ans = 1l;\n        while(m > 0)\n        {\n            if(m % 2 == 1)\n                ans = (ans * n) % mod;\n            n = (n * n) % mod;\n            m >>= 1;\n        }\n        return ans;\n    }\n\n    public static int gcd(int a, int b)\n    {\n        if(a % b == 0) return b;\n        return gcd(b, a % b);\n    }\n    public static long gcd(long a, long b)\n    {\n        if(a % b == 0) return b;\n        return gcd(b, a % b);\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 void shuffle(long[] data) {\n            shuffle(data, 0, data.length - 1);\n        }\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 RandomWrapper.INSTANCE.nextInt(l, r);\n        }\n    }\n\n    static class RandomWrapper {\n        private Random random;\n        public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());\n\n        public RandomWrapper() {\n            this(new Random());\n        }\n\n        public RandomWrapper(Random random) {\n            this.random = random;\n        }\n\n        public int nextInt(int l, int r) {\n            return random.nextInt(r - l + 1) + l;\n        }\n\n    }\n\n\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        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 ni() {\n            return Integer.parseInt(next());\n        }\n        long nl() {\n            return Long.parseLong(next());\n        }\n        double nd() {\n            return Double.parseDouble(next());\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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \nimport java.math.*;\nimport java.awt.Point;\n \npublic class Main {\n    //static final long MOD = 1000000007L;\n    //static final long MOD2 = 1000000009L;\n    static final long MOD = 998244353L;\n    //static final long INF = 500000000000L;\n    static final int INF =   1000000005;\n    static final int NINF = -1000000005;\n    //static final long NINF = -1000000000000000000L;\n    static FastScanner sc;\n    static PrintWriter pw;\n    static final int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}};\n\n\n    public static void main(String[] args) {\n        sc = new FastScanner();\n        pw = new PrintWriter(System.out);\n        \n\n\n        int Q = sc.ni();\n        for (int q = 0; q < Q; q++) {\n            int N = sc.ni();\n            String ans = \"NO\";\n            if (N%2==0 && isSquare(N/2))\n                ans = \"YES\";\n            if (N%4==0 && isSquare(N/4))\n                ans = \"YES\";\n            pw.println(ans);\n        }\n        pw.close();\n    }\n\n    public static boolean isSquare(int x) {\n        int s = (int)Math.round(Math.sqrt(x));\n        return s*s==x;\n    }\n\n \n    public static void sort(int[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    public static void sort(long[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    //Sort an array (immune to quicksort TLE)\n    public static void sort(int[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<int[]>() {\n            @Override\n            public int compare(int[] a, int[] b) {\n                return a[0]-b[0];\n            }\n        });\n    }\n    \n    public static void sort(long[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<long[]>() {\n            @Override\n            public int compare(long[] a, long[] b) {\n                if (a[0] > b[0])\n                    return 1;\n                else if (a[0] < b[0])\n                    return -1;\n                else\n                    return 0;\n                //Ascending order.\n            }\n        });\n    }\n \n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in), 32768);\n            st = null;\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        int[][] graph(int N, int[][] edges) {\n            int[][] graph = new int[N][];\n            int[] sz = new int[N];\n            for (int[] e: edges) {\n                sz[e[0]] += 1;\n                sz[e[1]] += 1;\n            }\n            for (int i = 0; i < N; i++) {\n                graph[i] = new int[sz[i]];\n            }\n            int[] cur = new int[N];\n            for (int[] e: edges) {\n                graph[e[0]][cur[e[0]]] = e[1];\n                graph[e[1]][cur[e[1]]] = e[0];\n                cur[e[0]] += 1;\n                cur[e[1]] += 1;\n            }\n            return graph;\n        }\n \n        int[] intArray(int N, int mod) {\n            int[] ret = new int[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = ni()+mod;\n            return ret;\n        }\n \n        long nl() {\n            return Long.parseLong(next());\n        }\n \n        long[] longArray(int N, long mod) {\n            long[] ret = new long[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = nl()+mod;\n            return ret;\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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tint T=fs.nextInt();\n\t\tfor (int tt=0; tt<T; tt++) {\n\t\t\tint n=fs.nextInt();\n\t\t\tboolean isEven=n%2==0;\n\t\t\twhile (n%2==0) n/=2;\n\t\t\tif (isSquare(n) && isEven) {\n\t\t\t\tSystem.out.println(\"YES\");\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\t\n\tstatic boolean isSquare(long n) {\n\t\tlong sqrt=(long) Math.sqrt(n);\n\t\tfor (int i=(int) Math.max(1, sqrt-5); i<=sqrt+5; i++)\n\t\t\tif (i*i==n)\n\t\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tArrayList<Integer> l=new ArrayList<>();\n\t\tfor (int i:a) l.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i=0; i<a.length; i++) a[i]=l.get(i);\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\t\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class B14G {\n\n    public static void main(String[] args) throws IOException {\n        init_io();\n        int t = nint();\n        while(t-- > 0) {\n            int N = nint();\n            if (N % 2 != 0) {\n                out.println(\"NO\"); continue;\n            }\n            N /= 2;\n            int sqrt = (int)(Math.round(Math.sqrt(N)));\n            int sqrt2 = (int)(Math.round(Math.sqrt(N/2)));\n            if (sqrt * sqrt == N || sqrt2 * sqrt2 * 2 == N) {\n                out.println(\"YES\");\n            }\n            else {\n                out.println(\"NO\");\n            }\n        }\n        out.close();\n    }\n\n    static StreamTokenizer in;\n    static PrintWriter out;\n    static BufferedReader br;\n\n    static int nint() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    static void init_io() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        in = new StreamTokenizer(br);\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    }\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class B {\n    static FastScanner fs;\n    public static void main(String[] args) {\n        fs=new FastScanner();\n        int t = fs.nextInt();\n        while (t-->0)\n            solve();\n    }\n    public static void solve() {\n        int n = fs.nextInt()*2;\n        int sq = (int)Math.sqrt(n);\n        int sq2 = (int)Math.sqrt(n/2);\n        if (sq*sq==n) System.out.println(\"YES\");\n        else if (sq2*sq2==n/2.0 && sq2%2==0) System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n    }\n    static int gcd(int a, int b) {\n        if (a==0) return b;\n        return gcd(b%a, a);\n    }\n    static void ruffleSort(int[] a) {\n        int n=a.length;//shuffle, then sort\n        for (int i=0; i<n; i++) {\n            int oi=random.nextInt(n), temp=a[oi];\n            a[oi]=a[i]; a[i]=temp;\n        }\n        Arrays.sort(a);\n    }\n    static final Random random =new Random();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        int[] readArray(int n) {\n            int[] a=new int[n];\n            for (int i=0; i<n; i++) a[i]=nextInt();\n            return a;\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n\n    static int[] reverse(int[] a) {\n        int n=a.length;\n        int[] res=new int[n];\n        for (int i=0; i<n; i++) res[i]=a[n-1-i];\n        return res;\n    }\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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 lucasr\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\tBPhoenixAndPuzzle solver = new BPhoenixAndPuzzle();\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 BPhoenixAndPuzzle {\n\t\tpublic static MyScanner sc;\n\t\tpublic static PrintWriter out;\n\n\t\tpublic void solve(int testNumber, MyScanner sc, PrintWriter out) {\n\t\t\tBPhoenixAndPuzzle.sc = sc;\n\t\t\tBPhoenixAndPuzzle.out = out;\n\t\t\tlong n = sc.nextLong();\n\t\t\tboolean can = true;\n\t\t\tif (n % 2 != 0) can = false;\n\t\t\tn /= 2;\n\t\t\twhile (n > 1 && n % 2 == 0) n /= 2;\n\t\t\tlong sq = Math.round(Math.pow(n, 0.5));\n\t\t\tif (sq * sq != n) can = false;\n\n\t\t\tout.println(can ? \"YES\" : \"NO\");\n\t\t}\n\n\t}\n\n\tstatic class MyScanner {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tokenizer;\n\n\t\tpublic MyScanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\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(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.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", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class CF_1515_B{\n    //SOLUTION BEGIN\n    void pre() throws Exception{}\n    void solve(int TC) throws Exception{\n        long N = nl();\n        if(N%2 == 1){\n            pn(\"NO\");\n            return;\n        }\n        N /= 2;\n\n        boolean yes = ps(N);\n        if(N%2 == 0)yes |= ps(N/2);\n        pn(yes?\"YES\":\"NO\");\n    }\n    boolean ps(long N){\n        long T = (long)Math.sqrt(N);\n        while(T*T > N)T--;\n        while (T*T < N)T++;\n        return  (T*T == N);\n    }\n    //SOLUTION END\n    void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n    void exit(boolean b){if(!b)System.exit(0);}\n    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 = true, 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_1515_B().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, \"1\", 1 << 28).start();\n        else new CF_1515_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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\n\npublic class codeforces2 {\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n//        Scanner scan = new Scanner(System.in);\n//for (int i = 1; i <= 10; i++) {\n//    System.out.println(i + \" \" + divisors(i).toString());\n//}   \n        int tc = sc.ni();\n        for (int rep = 0; rep < tc; rep++) {\n            long n = sc.nl();\n            if (n % 2 == 1) {\n                pw.println(\"NO\");\n            }\n            else {\n                n/= 2;\n                if (perfectSquare(n)) {\n                    pw.println(\"YES\");\n                }\n                else if (n % 2 == 0 && perfectSquare(n/2)) {\n                    pw.println(\"YES\");\n                }\n                else {\n                    pw.println(\"NO\");\n                }\n            }\n        }\n        pw.close();\n    }\n    //precondition: n <= m\n    public static boolean solve(int n,int m, int k) {\n        return false;\n    }\n    public static boolean perfectSquare(long n) {\n        long lo = 0;\n        long hi = n;\n        while (lo < hi) {\n            long k = (lo + hi) / 2;\n            if (k * k < n)\n                lo = k + 1;\n            else\n                hi = k;\n        }\n        return (lo * lo == n);\n    }\n    static Set<Integer> divisors(int n) {\n        Set<Integer> set = new HashSet();\n        for (int i=1; i<=Math.sqrt(n); i++)\n        {\n            if (n%i==0)\n            {\n                // If divisors are equal, print only one\n                if (n/i == i)\n                    set.add(i);\n      \n                else {// Otherwise print both\n                    set.add(i);\n                    set.add(n / i);\n                }\n            }\n        }\n        return set;\n    }\n    static Map<Integer, Integer> primeFactorization(int x) {\n        //first divide by 2\n        Map<Integer, Integer> map = new HashMap();\n        if (x == 0) return map;\n        int count = 0;\n        while (x % 2 == 0) {\n            x /=2;\n            count++;\n        }\n        //insert 2\n        if (count > 0) map.put(2, count);\n        for (int divisor = 3; divisor * divisor <= x; divisor += 2) {\n            int cnt = 0;\n            while (x % divisor == 0) {\n                x /= divisor;\n                cnt++;\n            }\n            if (cnt > 0) map.put(divisor, cnt);\n        }\n        if (x > 1) {\n            map.put(x, 1);\n        }\n        return map;\n    }\n    static boolean isPrime(int n)\n    {\n \n        // Check if number is less than\n        // equal to 1\n        if (n <= 1)\n            return false;\n \n        // Check if number is 2\n        else if (n == 2)\n            return true;\n \n        // Check if n is a multiple of 2\n        else if (n % 2 == 0)\n            return false;\n \n        // If not, then just check the odds\n        for (int i = 3; i <= Math.sqrt(n); i += 2) \n        {\n            if (n % i == 0)\n                return false;\n        }\n        return true;\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    // method to return LCM of two numbers\n    static int lcm(int a, int b)\n    {\n        return (a / gcd(a, b)) * b;\n    }\n    public static void sort(int[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    public static void sort(long[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n    /* */\n    //printing methods\n    /* */\n    //WOW!\n    /* */\n    public static void printArr(PrintWriter pw, int[] arr) {\n        StringBuilder sb = new StringBuilder();\n        for (int x : arr) {\n            sb.append(x + \"\");\n        }\n        sb.setLength(sb.length() - 1);\n        pw.println(sb.toString());\n    }\n    public static void printArr2d(PrintWriter pw, int[][] arr) {\n        StringBuilder sb = new StringBuilder();\n        for (int[] row : arr) {\n            for (int x : row) {\n                sb.append(x + \" \");\n            }\n            sb.setLength(sb.length() - 1);\n            sb.append(\"\\n\");\n        }\n        sb.setLength(sb.length() - 1);\n        pw.println(sb.toString());\n    }\n}\nclass FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastScanner() {\n        br = new BufferedReader(new InputStreamReader(System.in), 32768);\n        st = null;\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    int[] intArray(int N) {\n        int[] ret = new int[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = ni();\n        return ret;\n    }\n\n    long nl() {\n        return Long.parseLong(next());\n    }\n\n    long[] longArray(int N) {\n        long[] ret = new long[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = nl();\n        return ret;\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}\nclass UnionFind {\n    int size;\n    private int[] id;\n    public UnionFind(int size) {\n        this.size = size;\n        id = new int[size];\n        for (int i = 0; i < id.length; i++) {\n            id[i] = i;\n        }\n    }\n    public int find(int a) {\n        if (id[a] != a) {\n            id[a] = find(id[a]);\n        }\n        return id[a];\n    }\n    public void union(int a, int b) {\n        int r1 = find(a);\n        int r2 = find(b);\n        if (r1 == r2) return;\n        size--;\n        id[r1] = r2;\n    }\n    @Override\n    public String toString() {\n        return Arrays.toString(id);\n    }\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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 Solution1515B {\n  public static void main(String[] args) {\n    InputReader in = new InputReader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n    Solver1515B solver = new Solver1515B();\n    int n = in.nextInt();\n    for (int i = 0; i < n; i++) {\n      solver.solve(i, in, out);\n    }\n    out.close();\n  }\n\n  static class Solver1515B {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n      boolean f = false;\n      if (n % 2 == 0) {\n        int s = (int) Math.sqrt(n / 2);\n        if (s * s == n / 2) {\n          f = true;\n        }\n      }\n      if (n % 4 == 0) {\n        int s = (int) Math.sqrt(n / 4);\n        if (s * s == n / 4) {\n          f = true;\n        }\n      }\n      if (f) {\n        out.println(\"YES\");\n      } else {\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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdD {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n\tpublic static void main(String[] havish) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\tint t = sc.nextInt();\n \t\tfor(int i = 0;i<t;i++){\n \t\t\tint n  =sc.nextInt();\n \t\t\tif (n%2== 1)\n \t\t\t\tout.println(\"NO\");\n \t\t\telse{\n\n \t\t\t\twhile(n%2 == 0){\n \t\t\t\t\tn/=2;\n \t\t\t\t}\n \t\t\t\tverdict(isSquare(n) || isSquare(2*n));\n \t\t\t\t\n\n \t\t\t}\n \t\t}\n \t\tout.close();\n \t\t\n \t}\n\tpublic static boolean isSquare(int n) {\n\t\tint d = (int)Math.sqrt(n);\n\t\tfor(long s = d-2;s<=d+2;s++){\n\t\t\tif (s*s == n)\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;import java.io.*;import java.math.*;\npublic class Main\n{\n    public static void process()throws IOException\n    {\n        long n=nl();\n        if(n%2==0)\n        {\n            long a1=(long)Math.sqrt(n);\n            long a2=(long)Math.sqrt(n/2);\n            if(a1*a1==n || a2*a2*2==n)\n                {pn(\"YES\");return;}\n        }\n        pn(\"NO\");\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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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        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, FastScanner in, PrintWriter out) {\n            int numTests = in.nextInt();\n            for (int test = 0; test < numTests; test++) {\n                int n = in.nextInt();\n                boolean can = false;\n                if (n % 2 == 0 && isSquare(n / 2)) {\n                    can = true;\n                }\n                if (n % 4 == 0 && isSquare(n / 4)) {\n                    can = true;\n                }\n                out.println(can ? \"YES\" : \"NO\");\n            }\n        }\n\n        private boolean isSquare(int n) {\n            int x = (int) Math.sqrt(n);\n            while (x * x > n) {\n                --x;\n            }\n            while (x * x < n) {\n                ++x;\n            }\n            return x * x == 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", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//package sept;\n \nimport java.io.*;\nimport java.util.*;\n \npublic class TimePass {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\";\n    //boolean codechef=true;\n    // String prodKey = \"Av#/lL{OyEKiLR+/Ce%(w]^J65;XZe8FVb]]<931_=80E[BVnU^@4xu*J%KG3,CRqIZrUN~JJ+*6QC*CyBd>'$;>O\"onO.bQ%{L}\";\n    boolean codechef=true;\n    \n    void solve()\n    {\n        int t=ni();\n        while(t-->0) {\n            int n=ni();\n            int root=(int)Math.sqrt(n/2);\n            int rootn = (int)Math.sqrt(n);\n            if (n==1 || n%2!=0) {\n                out.println(\"NO\");\n                continue;\n            }\n            if (root*root == n/2 || (rootn*rootn == n && rootn%2==0)) {\n                out.println(\"YES\");\n            } else {\n                out.println(\"NO\");\n            }\n        }\n    }\n    \n    static int comp(int a,int b){\n        return a+1097*b;\n    }\n    \n    static long printNcR(int n, int r)\n    {\n \n        // p holds the value of n*(n-1)*(n-2)...,\n        // k holds the value of r*(r-1)...\n        long p = 1, k = 1;\n \n        // C(n, r) == C(n, n-r),\n        // choosing the smaller value\n        if (n - r < r) {\n            r = n - r;\n        }\n \n        if (r != 0) {\n            while (r > 0) {\n                p *= n;\n                k *= r;\n \n                // gcd of p, k\n                long m = __gcd(p, k);\n \n                // dividing by gcd, to simplify\n                // product division by their gcd\n                // saves from the overflow\n                p /= m;\n                k /= m;\n \n                n--;\n                r--;\n            }\n \n            // k should be simplified to 1\n            // as C(n, r) is a natural number\n            // (denominator should be 1 ) .\n        }\n        else {\n            p = 1;\n        }\n \n        // if our approach is correct p = ans and k =1\n        return p;\n    }\n \n    static long __gcd(long n1, long n2)\n    {\n        long gcd = 1;\n \n        for (int i = 1; i <= n1 && i <= n2; ++i) {\n            // Checks if i is factor of both integers\n            if (n1 % i == 0 && n2 % i == 0) {\n                gcd = i;\n            }\n        }\n        return gcd;\n    }\n    static long[][] dp;\n    \n    static long desc(int[] a,int l,int r) {\n        if (l==r) return 0;\n        if (dp[l][r]!=-1) return dp[l][r];\n        dp[l][r] = a[r]-a[l] + Math.min(desc(a,l+1,r),desc(a,l,r-1));\n        return dp[l][r];\n    }\n    \n    static int getMax(int arr[], int n)\n    {\n        int mx = arr[0];\n        for (int i = 1; i < n; i++)\n            if (arr[i] > mx)\n                mx = arr[i];\n        return mx;\n    }\n \n    // A function to do counting sort of arr[] according to\n    // the digit represented by exp.\n    static void countSort(int arr[], int n, int exp)\n    {\n        int output[] = new int[n]; // output array\n        int i;\n        int count[] = new int[10];\n        Arrays.fill(count, 0);\n \n        // Store count of occurrences in count[]\n        for (i = 0; i < n; i++)\n            count[(arr[i] / exp) % 10]++;\n \n        // Change count[i] so that count[i] now contains\n        // actual position of this digit in output[]\n        for (i = 1; i < 10; i++)\n            count[i] += count[i - 1];\n \n        // Build the output array\n        for (i = n - 1; i >= 0; i--) {\n            output[count[(arr[i] / exp) % 10] - 1] = arr[i];\n            count[(arr[i] / exp) % 10]--;\n        }\n \n        // Copy the output array to arr[], so that arr[] now\n        // contains sorted numbers according to curent digit\n        for (i = 0; i < n; i++)\n            arr[i] = output[i];\n    }\n \n    // The main function to that sorts arr[] of size n using\n    // Radix Sort\n    static void radixsort(int arr[], int n)\n    {\n        // Find the maximum number to know number of digits\n        int m = getMax(arr, n);\n \n        // Do counting sort for every digit. Note that\n        // instead of passing digit number, exp is passed.\n        // exp is 10^i where i is current digit number\n        for (int exp = 1; m / exp > 0; exp *= 10)\n            countSort(arr, n, exp);\n    }\n \n    static int MAX=1500;\n    \n    static int prime[], countdiv[]; \n    \n    static int[] getDivisorsArray() {\n        int n=20000005;\n        int[] mind = new int[n];\n        Arrays.fill(mind, -1);\n        for(int i=2;i<n;i++){\n            if (mind[i]==-1){\n                for(int j=i;j<n;j+=i){\n                    if (mind[j]==-1){\n                        mind[j]=i;\n                    }\n                }\n            }\n        }\n        // int[] nod = new int[n];\n        // for(int i=2;i<n;i++){\n        //     int prod = i/mind[i];\n        //     if (mind[i] != mind[prod]) {\n        //         nod[i] = nod[prod] + 1;\n        //     } else {\n        //         nod[i] = nod[prod];\n        //     }\n        // }\n        return mind;\n    }\n      \n    // Simple sieve to find smallest prime factors of numbers \n    // smaller than MAX \n    void SieveOfEratosthenes() \n    { \n        for (int i = 2; i * i < MAX; ++i) \n        { \n            if (prime[i]==0) \n                for (int j = i * i; j < MAX; j += i) \n                    prime[j] = i; \n        } \n      \n        // Prime number will have same divisor \n        for (int i = 1; i < MAX; ++i) \n            if (prime[i]==0) \n                prime[i] = i; \n    } \n      \n    // Returns length of the largest subsequence \n    // with GCD more than 1. \n    int largestGCDSubsequence(int arr[], int n) \n    { \n        int ans = 0; \n        for (int i=0; i < n; ++i) \n        { \n            int element = arr[i]; \n      \n            // Fetch total unique prime divisor of element \n            while (element > 1) \n            { \n                int div = prime[element]; \n      \n                // Increment count[] of Every unique divisor \n                // we get till now \n                ++countdiv[div]; \n      \n                // Find maximum frequency of divisor \n                ans = Math.max(ans, countdiv[div]); \n      \n                while (element % div==0) \n                    element /= div; \n            } \n        } \n      \n        return ans; \n    } \n      \n    \n    static boolean check(int x)\n    {\n        char[] a=(\"\"+x).toCharArray();\n        int s=0;\n        for(int i=0;i<a.length;i++)\n        {\n            s+=a[i]-'0';\n            s%=3;\n        }\n        if(s==0)return true;\n        return false;\n    }\n    \n    \n    static int[][] packD(int n,int[] from,int[] to)\n    {\n        int[][] g=new int[n][];\n        int[] p=new int[n];\n        for(int f:from)\n        {\n            p[f]++;\n        }\n        int m=from.length;\n        for(int i=0;i<n;i++)\n        {\n            g[i]=new int[p[i]];\n        }\n        for(int i=0;i<m;i++)\n        {\n            g[from[i]][--p[from[i]]]=to[i];\n        }\n        return g;\n    }\n    \n    static class Pair3\n    {\n        int a,b,c;\n        public Pair3(int a,int b,int c)\n        {\n            this.a=a;\n            this.b=b;\n            this.c=c;\n        }\n    }\n        \n    static class Pair\n    {\n        int a,b;\n        public Pair(int a,int b)\n        {\n            this.a=a;\n            this.b=b;\n        }\n    }\n    \n    static long lcm(long a,long b)\n    {\n        long val=a;\n        val*=b;\n        return (val/gcd(a,b));\n    }\n    \n    static long gcd(long a,long b)\n    {\n        if(a==0)return b;\n        return gcd(b%a,a);\n    }\n    \n    static int pow(int a, int b, int p)\n    {\n        long ans = 1, base = a;\n        while (b!=0)\n        {\n            if ((b & 1)!=0)\n            {\n                ans *= base;\n                ans%= p;\n            }\n            base *= base;\n            base%= p;\n            b >>= 1;\n        }\n        return (int)ans;\n    }\n \n    static int inv(int x, int p)\n    {\n        return pow(x, p - 2, p);\n    }\n \n    \n    void run() throws Exception\n    {\n        if(codechef)oj=true;\n        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        out = new PrintWriter(System.out);\n        \n        long s = System.currentTimeMillis();\n        solve();\n        out.flush();\n        tr(System.currentTimeMillis()-s+\"ms\");\n    }\n    \n    public static void main(String[] args) throws Exception {new TimePass().run();}\n    \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 nd() { return Double.parseDouble(ns()); }\n    private char nc() { return (char)skip(); }\n    \n    private String ns()\n    {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n    \n    private char[] ns(int n)\n    {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while(p < n && !(isSpaceChar(b))){\n            buf[p++] = (char)b;\n            b = readByte();\n        }\n        return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n    \n    private char[][] nm(int n, int m)\n    {\n        char[][] map = new char[n][];\n        for(int i = 0;i < n;i++)map[i] = ns(m);\n        return map;\n    }\n    \n    private int[] na(int n)\n    {\n        int[] a = new int[n];\n        for(int i = 0;i < n;i++)a[i] = ni();\n        return a;\n    }\n    \n    private int ni()\n    {\n        int num = 0, b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private long nl()\n    {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\n\n\nimport java.io.*;\nimport java.math.*;\nimport static java.util.stream.Collectors.*;\nimport static java.util.Map.Entry.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\t\n\tpublic static void main (String[] args) throws IOException\n\t{\n\t\tfinal long mod=(long) (1e9+7);  \n\t\tReader s=new Reader();\n\t\t  PrintWriter pt=new PrintWriter(System.out);\n\t\t  \n//\t\t  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t  int T=s.nextInt();\n//\t\t  int T=Integer.parseInt(br.readLine());\n//\t\t  int T=1;\n\t\t  while(T-->0)\n\t\t  {\n\t\t        long n=s.nextInt();\n\t\t        long sq1=n/2;\n\t\t        \n\t\t        long sq2=n/4;\n\t\t        \n\t\t        if(isPerfectSquare(sq1)&&sq1*2==n||isPerfectSquare(sq2)&&sq2*4==n)\n\t\t        \tpt.println(\"YES\");\n\t\t        else\n\t\t        \tpt.println(\"NO\");\n\t\t        \n\t\t        \n\t\t        \n\t\t  }\n\t\t  pt.close();\n\t}\n\t\n\tstatic void divideBy2(int arr[], int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tarr[i]=arr[i]>>1;\n\t\t}\n\t}\n\t\n\tstatic boolean isEven(int arr[], int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(arr[i]%2==1)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstatic boolean isPartition(int arr[], int n) {\n\t\tint sum = 0;\n\t    int i, j;\n\t \n\t    // Calculate sum of all elements\n\t    for (i = 0; i < n; i++)\n\t        sum += arr[i];\n\t \n\t    if (sum % 2 != 0)\n\t        return false;\n\t \n\t    boolean part[][]=new boolean[sum/2+1][n+1];\n\t \n\t    // initialize top row as true\n\t    for (i = 0; i <= n; i++)\n\t        part[0][i] = true;\n\t \n\t    // initialize leftmost column, except part[0][0], as false\n\t    for (i = 1; i <= sum / 2; i++)\n\t        part[i][0] = false;\n\t \n\t    // Fill the partition table in bottom up manner\n\t    for (i = 1; i <= sum / 2; i++) {\n\t        for (j = 1; j <= n; j++) {\n\t            part[i][j] = part[i][j - 1];\n\t            if (i >= arr[j - 1])\n\t                part[i][j] = part[i][j]\n\t                             || part[i - arr[j - 1]][j - 1];\n\t        }\n\t    }\n\t    return part[sum / 2][n];\n\t}\n\t\n\tstatic int setBit(int S, int j) { return S | 1 << j; }\n\n\tstatic int clearBit(int S, int j) { return S & ~(1 << j); }\n\n\tstatic int toggleBit(int S, int j) { return S ^ 1 << j; }\n\n\tstatic boolean isOn(int S, int j) { return (S & 1 << j) != 0; }\n\n\tstatic int turnOnLastZero(int S) { return S | S + 1; }\n\t\n\tstatic int turnOnLastConsecutiveZeroes(int S) { return S | S - 1; }\n\t\n\tstatic int turnOffLastBit(int S) { return S & S - 1; }\n\t\n\tstatic int turnOffLastConsecutiveBits(int S) { return S & S + 1; }\n\n\tstatic int lowBit(int S) { return S & -S; }\n\n\tstatic int setAll(int N) { return (1 << N) - 1; }\n\n\tstatic int modulo(int S, int N) { return (S & N - 1); }\t\t //S%N, N is a power of 2\n\n\tstatic boolean isPowerOfTwo(int S) { return (S & S - 1) == 0; }\n\t\n\tstatic boolean isWithin(long x, long y, long d, long k) {\n\t\treturn x*k*x*k + y*k*y*k <= d*d;\n\t}\n\t\n\tstatic long modFact(long n, \n            long p) \n\t{ \n\t\tif (n >= p) \n\t\t return 0; \n\t\t\n\t\tlong result = 1; \n\t\tfor (int i = 1; i <= n; i++) \n\t\t result = (result * i) % p; \n\t\t\n\t\treturn result; \n\t} \n\tstatic int sum(int[] arr, int n)\n\t{\n\t    int inc[]=new int[n+1];\n\t    int dec[]=new int[n+1];\n\t    inc[0] = arr[0];\n\t    dec[0] = arr[0];\n\n\t    for (int i = 1; i < n; i++) {\n\t        for (int j = 0; j < i; j++) {\n\t            if (arr[j] > arr[i]) {\n\t                dec[i] = max(dec[i], inc[j] + arr[i]);\n\t            }\n\t            else if (arr[i] > arr[j]) {\n\t                inc[i] = max(inc[i], dec[j] + arr[i]);\n\t            }\n\t        }\n\t    }\n\t    return max(inc[n - 1], dec[n - 1]);\n\t}\n\tstatic long nc2(long a) {\n\t\treturn a*(a-1)/2;\n\t}\n\tpublic static int numberOfprimeFactors(int n) \n    { \n        // Print the number of 2s that divide n \n\t\tHashSet<Integer> hs = new HashSet<Integer>();\n        while (n%2==0) \n        { \n            hs.add(2);\n            n /= 2; \n        } \n  \n        // n must be odd at this point.  So we can \n        // skip one element (Note i = i +2) \n        for (int i = 3; i <= Math.sqrt(n); i+= 2) \n        { \n            // While i divides n, print i and divide n \n            while (n%i == 0) \n            { \n                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            hs.add(n);\n        return hs.size();\n    } \n\tstatic int gcd(int a, int b) \n    { \n      if (b == 0) \n        return a; \n      return gcd(b, a % b);  \n    } \n\n\n\n\n\t\n\n\tstatic void reverse(int arr[],int start, int end) \n\t{ \n\t\tint temp; \n\t\t   \n\t\twhile (start < end) \n\t\t{ \n\t\t    temp = arr[start];  \n\t\t    arr[start] = arr[end]; \n\t\t    arr[end] = temp; \n\t\t    start++; \n\t\t    end--; \n\t\t}  \n\t}  \n\tstatic void reverse(long arr[],int start, int end) \n\t{ \n\t\tlong temp; \n\t\t   \n\t\twhile (start < end) \n\t\t{ \n\t\t    temp = arr[start];  \n\t\t    arr[start] = arr[end]; \n\t\t    arr[end] = temp; \n\t\t    start++; \n\t\t    end--; \n\t\t}  \n\t}  \n\tstatic boolean isPrime(int n) \n    { \n        // Corner cases \n        if (n <= 1) return false; \n        if (n <= 3) return true; \n      \n        // This is checked so that we can skip  \n        // middle five numbers in below loop \n        if (n % 2 == 0 || n % 3 == 0) return false; \n      \n        for (int i = 5; i * i <= n; i = i + 6) \n            if (n % i == 0 || n % (i + 2) == 0) \n            return false; \n      \n        return true; \n    } \n\tstatic int p2(int n) {\n\t\tint k=0;\n\t\twhile(n>1) {\n\t\t\tif(n%2!=0)\n\t\t\t\treturn k;\n\t\t\tn/=2;\n\t\t\tk++;\n\t\t}\n\t\treturn k;\n\t}\n\tstatic boolean isp2(int n) {\n\t\twhile(n>1) {\n\t\t\tif(n%2==1)\n\t\t\t\treturn false;\n\t\t\tn/=2;\n\t\t}\n\t\treturn true;\n\t}\n\tstatic int binarySearch(int arr[], int first, int last, int key){  \n\t\t   int mid = (first + last)/2;  \n\t\t   while( first <= last ){  \n\t\t      if ( arr[mid] < key ){  \n\t\t        first = mid + 1;     \n\t\t      }else if ( arr[mid] == key ){  \n\t\t        return mid;  \n\t\t      }else{  \n\t\t         last = mid - 1;  \n\t\t      }  \n\t\t      mid = (first + last)/2;  \n\t\t   }  \n\t\t   return -1;\n\t\t }  \n\n\tstatic void print(int a[][]) {\n\t\tfor(int i=0;i<a.length;i++)\n\t\t{\n\t\t\tfor(int j=0;j<a[0].length;j++)\n\t\t\t\tSystem.out.print(a[i][j]+\" \");\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\tstatic int max (int x, int y) {\n\t\treturn (x > y)? x : y;\n\t} \n\tstatic int search(Pair[] p, Pair pair) {\n\t\tint l=0, r=p.length;\n\t\twhile (l <= r) { \n\t        int m = l + (r - l) / 2;\n\t        if (p[m].compareTo(pair)==0) \n\t            return m; \n\t        if (p[m].compareTo(pair)<0) \n\t            l = m + 1; \n\t        else\n\t            r = m - 1;\n\t    }\n\t    return -1;\n\t}\n\tstatic void pa(int a[])\n\t{\n\t\tfor(int i=0;i<a.length;i++)\n\t\t\tSystem.out.print(a[i]+\" \");\n\t\tSystem.out.println();\n\t\t\n\t}\n\tstatic void pa(long a[])\n\t{\n\t\tfor(int i=0;i<a.length;i++)\n\t\t\tSystem.out.print(a[i]+\" \");\n\t\tSystem.out.println();\n\t\t\n\t}\n\tstatic void reverseArray(int arr[], \n            int start, int end) \n\t{ \n\t\tint temp; \n\t\t   \n\t\twhile (start < end) \n\t\t{ \n\t\t    temp = arr[start];  \n\t\t    arr[start] = arr[end]; \n\t\t    arr[end] = temp; \n\t\t    start++; \n\t\t    end--; \n\t\t}  \n\t}     \n\tstatic boolean isPalindrome(String s) {\n\t\tint l=s.length();\n\t\tfor(int i=0;i<l/2;i++)\n\t\t{\n\t\t\tif(s.charAt(i)!=s.charAt(l-i-1))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\tstatic long nc2(long n, long m) {\n\t\treturn (n*(n-1)/2)%m;\n\t}\n\tstatic long c(long a) {\n\t\treturn a*(a+1)/2;\n\t}\n\tstatic int next(long[] arr, long target)  \n    {  \n        int start = 0, end = arr.length - 1;  \n    \n        int ans = -1;  \n        while (start <= end) {  \n            int mid = (start + end) / 2;  \n    \n            // Move to right side if target is  \n            // greater.  \n            if (arr[mid] < target) {\n                start = mid + 1;  \n            }  \n    \n            // Move left side.  \n            else {  \n                ans = mid;  \n                end = mid - 1;  \n            }  \n        }  \n        return ans;  \n    } \n\t\n\tstatic int prev(long[] arr, long target)  \n    {  \n        int start = 0, end = arr.length - 1;  \n    \n        int ans = -1;  \n        while (start <= end) {  \n            int mid = (start + end) / 2;  \n    \n            // Move to left side if target is  \n            // lesser.  \n            if (arr[mid] > target) {\n                end = mid - 1;  \n            }  \n    \n            // Move right side.  \n            else {  \n                ans = mid;  \n                start = mid + 1;  \n            }  \n        }  \n        return ans;  \n    } \n\n\tstatic long power(long x, long y, long p) \n    { \n        long res = 1; \n        x = x % p; \n                      \n        while (y > 0) \n        { \n            if (y % 2 == 1) \n                res = (res * x) % p; \n            y = y >> 1;\n            x = (x * x) % p; \n        } \n        return  res; \n    } \n    static long modInverse(long n, long p) \n    { \n        return power(n, p-2, p); \n    } \n    static long nCrModP(long n, long r, \n                                    long p) \n    { \n        if(r>n)\n        \treturn 0;\n    \tif (r == 0) \n            return 1; \n        long[] fac = new long[(int) (n+1)]; \n        fac[0] = 1; \n        for (int i = 1 ;i <= n; i++) \n            fac[i] = fac[i-1] * i % p;\n        return (fac[(int) n]* modInverse(fac[(int) r], p) \n                % p * modInverse(fac[(int) (n-r)], p) \n                                    % p) % p; \n    } \n\tstatic String reverse(String str)\n\t{\n\t\treturn new StringBuffer(str).reverse().toString();\n\t}\n\n\n\n\tstatic long fastpow(long x, long y, long m)  \n    { \n        if (y == 0) \n            return 1; \n          \n        long p = fastpow(x, y / 2, m) % m; \n        p = (p * p) % m; \n      \n        if (y % 2 == 0) \n            return p; \n        else\n            return (x * p) % m; \n    } \n\t\n\tstatic boolean isPerfectSquare(long l)\n\t{\n\t\treturn Math.pow((long)Math.sqrt(l),2)==l;\n\t}\n\t\n\t\n\tstatic void merge(long[] arr, int l, int m, int r) \n    { \n        // Find sizes of two subarrays to be merged \n        int n1 = m - l + 1; \n        int n2 = r - m; \n  \n        /* Create temp arrays */\n        long L[] = new long [n1]; \n        long R[] = new long [n2]; \n  \n        /*Copy data to temp arrays*/\n        for (int i=0; i<n1; ++i) \n            L[i] = arr[l + i]; \n        for (int j=0; j<n2; ++j) \n            R[j] = arr[m + 1+ j]; \n  \n  \n        /* Merge the temp arrays */\n  \n        // Initial indexes of first and second subarrays \n        int i = 0, j = 0; \n  \n        // Initial index of merged subarry array \n        int k = l; \n        while (i < n1 && j < n2) \n        { \n            if (L[i] <= R[j]) \n            { \n                arr[k] = L[i]; \n                i++; \n            } \n            else\n            { \n                arr[k] = R[j]; \n                j++; \n            } \n            k++; \n        } \n  \n        /* Copy remaining elements of L[] if any */\n        while (i < n1) \n        { \n            arr[k] = L[i]; \n            i++; \n            k++; \n        } \n  \n        /* Copy remaining elements of R[] if any */\n        while (j < n2) \n        { \n            arr[k] = R[j]; \n            j++; \n            k++; \n        } \n    } \n  \n    // Main function that sorts arr[l..r] using \n    // merge() \n    static void sort(int arr[], int l, int r) \n    { \n        if (l < r) \n        { \n            // Find the middle point \n            int m = (l+r)/2; \n  \n            // Sort first and second halves \n            sort(arr, l, m); \n            sort(arr , m+1, r); \n  \n            // Merge the sorted halves \n            merge(arr, l, m, r); \n        } \n    } \n\tstatic void merge(int arr[], int l, int m, int r) \n    { \n        // Find sizes of two subarrays to be merged \n        int n1 = m - l + 1; \n        int n2 = r - m; \n  \n        /* Create temp arrays */\n        int L[] = new int [n1]; \n        int R[] = new int [n2]; \n  \n        /*Copy data to temp arrays*/\n        for (int i=0; i<n1; ++i) \n            L[i] = arr[l + i]; \n        for (int j=0; j<n2; ++j) \n            R[j] = arr[m + 1+ j]; \n  \n  \n        /* Merge the temp arrays */\n  \n        // Initial indexes of first and second subarrays \n        int i = 0, j = 0; \n  \n        // Initial index of merged subarry array \n        int k = l; \n        while (i < n1 && j < n2) \n        { \n            if (L[i] <= R[j]) \n            { \n                arr[k] = L[i]; \n                i++; \n            } \n            else\n            { \n                arr[k] = R[j]; \n                j++; \n            } \n            k++; \n        } \n  \n        /* Copy remaining elements of L[] if any */\n        while (i < n1) \n        { \n            arr[k] = L[i]; \n            i++; \n            k++; \n        } \n  \n        /* Copy remaining elements of R[] if any */\n        while (j < n2) \n        { \n            arr[k] = R[j]; \n            j++; \n            k++; \n        } \n    } \n  \n    // Main function that sorts arr[l..r] using \n    // merge() \n    static void sort(long arr[], int l, int r) \n    { \n        if (l < r) \n        { \n            // Find the middle point \n            int m = (l+r)/2; \n  \n            // Sort first and second halves \n            sort(arr, l, m); \n            sort(arr , m+1, r); \n  \n            // Merge the sorted halves \n            merge(arr, l, m, r); \n        } \n    } \n    static class Pair implements Comparable<Pair>{\n        int a;\n        int b;\n        Pair(int a,int b){\n            this.a=a;\n \n            this.b=b;\n        }   \n        public int compareTo(Pair p){\n            if(a>p.a)\n                return 1;\n            if(a==p.a)\n                return (b-p.b);\n            return -1;\n        }\n    }\n\tstatic class Reader \n    { \n        final private int BUFFER_SIZE = 1 << 16; \n        private DataInputStream din; \n        private byte[] buffer; \n        private int bufferPointer, bytesRead; \n  \n        public Reader() \n        { \n            din = new DataInputStream(System.in); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public Reader(String file_name) throws IOException \n        { \n            din = new DataInputStream(new FileInputStream(file_name)); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public String readLine() throws IOException \n        { \n            byte[] buf = new byte[128]; // 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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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) 1e18 + 10;\n    static final int MOD = (int) 1e9 + 7;\n\n    static boolean isSq(int x) {\n        int sq = (int) Math.sqrt(x);\n        return sq * sq == x;\n    }\n\n    static void solve() {\n        int n = in.nextInt();\n        if ((n % 2 == 0 && isSq(n / 2)) || (n % 4 == 0 && isSq(n / 4)))\n            out.println(\"YES\");\n        else\n            out.println(\"NO\");\n\n    }\n\n    public static void main(String[] args) {\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n\n        int t = 1;\n        t = in.nextInt();\n        while (t-- > 0) {\n            solve();\n        }\n\n        out.flush();\n        out.close();\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}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//I'm Whiplash99\nimport java.io.*;\nimport java.util.*;\npublic class B\n{\n    public static void main(String[] args) throws Exception\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n        int i,N;\n\n        int T=Integer.parseInt(br.readLine().trim());\n        StringBuilder sb=new StringBuilder();\n\n        while (T-->0)\n        {\n            N=Integer.parseInt(br.readLine().trim());\n\n            boolean flag=false;\n            int sqrt=(int) Math.sqrt(N/2);\n            if(sqrt*sqrt==N/2&&N%2==0) flag = true;\n\n            sqrt=(int) Math.sqrt(N/4);\n            if(sqrt*sqrt==N/4&&N%4==0) flag = true;\n\n            sb.append(flag?\"YES\\n\":\"NO\\n\");\n        }\n        System.out.println(sb);\n    }\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class b {\n\tpublic static void main(String[] args) throws Exception {\n\t\t\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\t\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tStringTokenizer st = new StringTokenizer(f.readLine());\n\n\t\tint T = Integer.parseInt(st.nextToken());\n\t\t\n\t\tfor (int t = 0; t < T; t++) {\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\tint sqrt = (int)Math.sqrt(n);\n\t\t\tint sqrt2 = (int)Math.sqrt(n/2);\n\t\t\tif (sqrt*sqrt == n && sqrt%2 == 0) {\n\t\t\t\tout.println(\"YES\");\n\t\t\t} else if (2*sqrt2*sqrt2 == n) {\n\t\t\t\tout.println(\"YES\");\n\t\t\t} else {\n\t\t\t\tout.println(\"NO\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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        BPhoenixAndPuzzle solver = new BPhoenixAndPuzzle();\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 BPhoenixAndPuzzle {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            if (n % 2 == 1) {\n                out.println(\"NO\");\n                return;\n            }\n            n /= 2;\n            int h = (int) Math.sqrt(n + 0.5);\n            if (h * h == n) {\n                out.println(\"YES\");\n                return;\n            }\n            if (n % 2 == 1) {\n                out.println(\"NO\");\n                return;\n            }\n            n /= 2;\n            h = (int) Math.sqrt(n + 0.5);\n            if (h * h == n) {\n                out.println(\"YES\");\n            } else out.println(\"NO\");\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\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)) 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;\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 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", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\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    static FastReader s = new FastReader();\n    static PrintWriter out = new PrintWriter(System.out);\n\n    private static int[] rai(int n) {\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextInt();\n        }\n        return arr;\n    }\n\n    private static int[][] rai(int n, int m) {\n        int[][] arr = new int[n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                arr[i][j] = s.nextInt();\n            }\n        }\n        return arr;\n    }\n\n    private static long[] ral(int n) {\n        long[] arr = new long[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextLong();\n        }\n        return arr;\n    }\n\n    private static long[][] ral(int n, int m) {\n        long[][] arr = new long[n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                arr[i][j] = s.nextLong();\n            }\n        }\n        return arr;\n    }\n\n    private static int ri() {\n        return s.nextInt();\n    }\n\n    private static long rl() {\n        return s.nextLong();\n    }\n\n    private static String rs() {\n        return s.next();\n    }\n\n    static int gcd(int a,int b)\n    {\n        if(b==0)\n        {\n            return a;\n        }\n        return gcd(b,a%b);\n    }\n\n    static long gcd(long a,long b)\n    {\n        if(b==0)\n        {\n            return a;\n        }\n        return gcd(b,a%b);\n    }\n    static boolean isPrime(int n) {\n        //check if n is a multiple of 2\n        if(n==1)\n        {\n            return false;\n        }\n        if(n==2)\n        {\n            return true;\n        }\n        if (n % 2 == 0) return false;\n        //if not, then just check the odds\n        for (int i = 3; i <= Math.sqrt(n); i += 2) {\n            if (n % i == 0)\n                return false;\n        }\n        return true;\n    }\n    static boolean[] 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        boolean prime[] = new boolean[n+1];\n        for(int i=0;i<n;i++)\n            prime[i] = true;\n\n        for(int p = 2; p*p <=n; p++)\n        {\n            // If prime[p] is not changed, then it is a prime\n            if(prime[p] == true)\n            {\n                // Update all multiples of p\n                for(int i = p*p; i <= n; i += p)\n                    prime[i] = false;\n            }\n        }\n        return prime;\n    }\n\n\n    public static void main(String[] args) {\n        StringBuilder ans = new StringBuilder();\n        int t = ri();\n//        int t=1;\n        while (t-- > 0)\n        {\n            long n=rl();\n            if(n%2==1)\n            {\n                ans.append(\"NO\\n\");\n                continue;\n            }\n\n            if(n%4==0)\n            {\n                long val = n/4;\n\n                long sq = (long) Math.sqrt(val);\n                if(sq*sq == val)\n                {\n                    ans.append(\"YES\\n\");\n                    continue;\n                }\n            }\n            if(n%2==0)\n            {\n                long val = n/2;\n                long sq = (long) Math.sqrt(val);\n                if(sq*sq == val)\n                {\n                    ans.append(\"YES\\n\");\n                    continue;\n                }\n            }\n            ans.append(\"NO\\n\");\n\n        }\n        out.print(ans.toString());\n        out.flush();\n\n    }\n\n\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class B {\n    public static void main(String[] args) throws IOException {\n//        Scanner scan = new Scanner(System.in);\n        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));\n//        int t = scan.nextInt();\n        int t= Integer.parseInt(br.readLine());\n        while (t-->0)\n        {\n            String[] s1= br.readLine().split(\" \");\n            int n= Integer.parseInt(s1[0]);\n//            Integer[] a= new Integer[n];\n//            String[] s2= br.readLine().split(\" \");\n//            long sum=0;\n//            for (int i=0;i<n;i++){\n//                a[i]= Integer.parseInt(s2[i]);\n//                sum+= Math.abs(a[i]);\n//            }\n\n            int x= 1;\n            boolean ans=true;\n            while (n%2==0){\n                x*=2;\n                n/=2;\n            }\n            if (x==1) ans= false;\n            int z= (int)Math.sqrt(n);\n            if (z*z!=n) ans= false;\n\n            if (ans) System.out.println(\"YES\");\n            else System.out.println(\"NO\");\n        }\n    }\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "/*==========================================================================*/\n/*\n*\t\tAUTHOR:    RonWonWon    \n*\t\tCREATED:   02.05.2021 19:58:57\n*\t\tEMAIL:     rachitpts.2454@gmail.com                                  \n*/\n/*==========================================================================*/\nimport java.io.*;\nimport java.util.*;\n\npublic class B {\n\t\n\tpublic static void main(String[] args) {\n        FastScanner in = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        int t = in.nextInt(), tt = 0;\n        while(t-->0) { \n        \tint n = in.nextInt();\n        \tif(n%2!=0) out.println(\"NO\");\n        \telse{\n        \t\tn/=2;\n        \t\tif(Math.sqrt(n)==Math.ceil(Math.sqrt(n))) out.println(\"YES\");\n        \t\telse{\n        \t\t\tif(n%2!=0) out.println(\"NO\");\n        \t\t\telse{\n        \t\t\t\tn/=2;\n            \t\tif(Math.sqrt(n)==Math.ceil(Math.sqrt(n))) out.println(\"YES\");\n            \t\telse out.println(\"NO\");\n        \t\t\t}\n        \t\t}\n    \t    }\n    \t\t//tt++; out.println(\"Case #\"+tt+\": \"+ans);\n        }\n        out.flush();\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\t\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(IOException e) {}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tString nextLine(){\n\t\t\ttry{ return br.readLine(); } \n\t\t\tcatch(IOException e) { } return \"\";\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\tint[] readArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor(int i=0;i<n;i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n\n\tstatic final Random random = new Random();\n\n\tstatic void ruffleSort(int[] a){\n\t\tint n = a.length;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tint j = random.nextInt(n), temp = a[j];\n\t\t\ta[j] = a[i]; a[i] = temp;\n\t\t}\n\t\tArrays.sort(a); \t\n\t}\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main\n{\n\tPrintWriter out = new PrintWriter(System.out);\n\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer tok = new StringTokenizer(\"\");\n    String next() throws IOException {\n        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }\n        return tok.nextToken();\n    }\n    int ni() throws IOException { return Integer.parseInt(next()); }\n    long nl() throws IOException { return Long.parseLong(next()); }\n    \n    long mod=1000000007;\n    \n    void solve() throws IOException {\n        for (int tc=ni();tc>0;tc--) {\n            long n=ni();\n            long q=1;\n            long p=1;\n            boolean f=false;\n            while (true) {\n                if (p*2==n || p*4==n) { f=true; break; }\n                q++;\n                p=q*q;\n                if (p>n) break;\n            }\n            if (f) out.println(\"YES\");\n            else out.println(\"NO\");\n        }\n        out.flush();\n    }\n    \n    int gcd(int a,int b) { return(b==0?a:gcd(b,a%b)); }\n    long gcd(long a,long b) { return(b==0?a:gcd(b,a%b)); }\n    long mp(long a,long p) { long r=1; while(p>0) { if ((p&1)==1) r=(r*a)%mod; p>>=1; a=(a*a)%mod; } return r; }\n    \n    public static void main(String[] args) throws IOException {\n        new Main().solve();\n    }\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tpublic static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) throws IOException {\n\t\treadInput();\n\t\tout.close();\n\t}\n\n\tstatic boolean sq(long x) {\n\t\tlong l = 1;\n\t\tlong r = (int)Math.sqrt(1e16)+1;\n\t\twhile (l+1<r) {\n\t\t\tlong m = (l+r)>>1;\n\t\t\tif (m * m > x) r = m;\n\t\t\telse l = m;\n\t\t}\n\t\treturn l*l == x;\n\t}\n\t\n\tstatic boolean solve(long x) {\n\t\tif ((x&1)==1) return false;\n\t\tif ((x & (x-1)) == 0) return true;\n\t\tlong num = 2;\n\t\twhile (num < x && x % num == 0) {\n\t\t\tif (sq(x/num)) return true;\n\t\t\tnum*=2;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tpublic static void readInput() throws IOException {\n\t\t// br = new BufferedReader(new FileReader(\".in\"));\n\t\t// out = new PrintWriter(new FileWriter(\".out\"));\n\t\tint t = Integer.parseInt(br.readLine());\n\t\twhile (t-->0) {\n\t\t\tint x = Integer.parseInt(br.readLine());\n\t\t\tout.println(solve(x) ? \"YES\":\"NO\");\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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 Sandip Jana\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        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 TaskB {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long x = in.readLong();\n\n            if (x % 2 == 1) {\n                out.println(\"NO\");\n                return;\n            }\n\n            if (x % 2 == 0) {\n                long p = x / 2;\n                long square = (long) Math.sqrt(p);\n                if (square * 1L * square == p) {\n                    out.println(\"YES\");\n                    return;\n                }\n            }\n\n            if (x % 4 == 0) {\n                long p = x / 4;\n                long square = (long) Math.sqrt(p);\n                if (square * 1L * square == p) {\n                    out.println(\"YES\");\n                    return;\n                }\n            }\n\n            out.println(\"NO\");\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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 String readString() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                if (Character.isValidCodePoint(c)) {\n                    res.appendCodePoint(c);\n                }\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/**\n * @author Mubtasim Shahriar\n */\n\npublic class Cgr14 {\n\n    public static void main(String[] args) {\n\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader sc = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Solver solver = new Solver();\n\t\tint t = sc.nextInt();\n//        int t = 1;\n        while (t-- != 0) {\n            solver.solve(sc, out);\n        }\n        out.close();\n\n    }\n\n    static class Solver {\n        public void solve(InputReader sc, PrintWriter out) {\n            long n = sc.nextInt();\n            long l = 1;\n            long r = (long)1e5;\n            while(l<=r) {\n                long mid = (l+r)/2;\n                long needed = (mid*mid)*2;\n                if(needed==n) {\n                    out.println(\"YES\");\n                    return;\n                }\n                if(needed>n) {\n                    r = mid-1;\n                } else {\n                    l = mid+1;\n                }\n            }\n            l = 1;\n            r = (long)1e5;\n            while(l<=r) {\n                long mid = (l+r)/2;\n                long needed = (mid*mid)*4;\n                if(needed==n) {\n                    out.println(\"YES\");\n                    return;\n                }\n                if(needed>n) {\n                    r = mid-1;\n                } else {\n                    l = mid+1;\n                }\n            }\n            out.println(\"NO\");\n        }\n\n    }\n\n    static void sort(int[] arr) {\n        Random rand = new Random();\n        int n = arr.length;\n        for (int i = 0; i < n; i++) {\n            int idx = rand.nextInt(n);\n            if (idx == i) continue;\n            arr[i] ^= arr[idx];\n            arr[idx] ^= arr[i];\n            arr[i] ^= arr[idx];\n        }\n        Arrays.sort(arr);\n    }\n\n    static void sort(long[] arr) {\n        Random rand = new Random();\n        int n = arr.length;\n        for (int i = 0; i < n; i++) {\n            int idx = rand.nextInt(n);\n            if (idx == i) continue;\n            arr[i] ^= arr[idx];\n            arr[idx] ^= arr[i];\n            arr[i] ^= arr[idx];\n        }\n        Arrays.sort(arr);\n    }\n\n    static void sortDec(int[] arr) {\n        Random rand = new Random();\n        int n = arr.length;\n        for (int i = 0; i < n; i++) {\n            int idx = rand.nextInt(n);\n            if (idx == i) continue;\n            arr[i] ^= arr[idx];\n            arr[idx] ^= arr[i];\n            arr[i] ^= arr[idx];\n        }\n        Arrays.sort(arr);\n        int l = 0;\n        int r = n - 1;\n        while (l < r) {\n            arr[l] ^= arr[r];\n            arr[r] ^= arr[l];\n            arr[l] ^= arr[r];\n            l++;\n            r--;\n        }\n    }\n\n    static void sortDec(long[] arr) {\n        Random rand = new Random();\n        int n = arr.length;\n        for (int i = 0; i < n; i++) {\n            int idx = rand.nextInt(n);\n            if (idx == i) continue;\n            arr[i] ^= arr[idx];\n            arr[idx] ^= arr[i];\n            arr[i] ^= arr[idx];\n        }\n        Arrays.sort(arr);\n        int l = 0;\n        int r = n - 1;\n        while (l < r) {\n            arr[l] ^= arr[r];\n            arr[r] ^= arr[l];\n            arr[l] ^= arr[r];\n            l++;\n            r--;\n        }\n    }\n\n    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\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 int[] nextSortedIntArray(int n) {\n            int array[] = nextIntArray(n);\n            Arrays.sort(array);\n            return array;\n        }\n\n        public int[] nextSumIntArray(int n) {\n            int[] array = new int[n];\n            array[0] = nextInt();\n            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();\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) array[i] = nextLong();\n            return array;\n        }\n\n        public long[] nextSumLongArray(int n) {\n            long[] array = new long[n];\n            array[0] = nextInt();\n            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();\n            return array;\n        }\n\n        public long[] nextSortedLongArray(int n) {\n            long array[] = nextLongArray(n);\n            Arrays.sort(array);\n            return array;\n        }\n    }\n\n\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner();\n\t\tint T = sc.nextInt();\n\t\twhile(T-->0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tif(n % 2 == 0 && issq(n/2)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\telse if(n % 4 == 0 && issq(n/4)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic boolean issq(long x) {\n\t\tlong rx = (long)Math.sqrt(x);\n\t\treturn rx * rx == x;\n\t}\n\t\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}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\npublic class two {\n\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(\"two\"));\n\n\t\tHashSet<Integer> good = new HashSet<>();\n\t\tint i=1;\n\t\tfor (; i<= (int)(1e9);) {\n\t\t\ti <<= 1;\n\t\t\tgood.add(i);\n\t\t}\n\t\t\n\t\tfor (i=3; i*i*2 <= (int)(1e9); i++) {\n\t\t\tgood.add(i*i*2);\n\t\t}\n\t\t\n\t\tint beg = 4;\n\t\tfor (i=3; beg + i*4 <= (int)(1e9); i+=2) {\n\t\t\tgood.add(beg + i*4);\n\t\t\tbeg += i*4;\n\t\t}\n\t\t\n\t\tint t = Integer.parseInt(in.readLine());\n\t\twhile (t-- > 0) {\n\t\t\tint n = Integer.parseInt(in.readLine());\n\t\t\tif (good.contains(n)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t\t\n\t\t}\n\n\t}\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main {\n    \n    public static void main(String[] args) {\n        \n        var sc = new Scanner(System.in);\n        var pw = new PrintWriter(System.out);\n        \n        int T = Integer.parseInt(sc.next());\n        for(int t = 0; t < T; t++){\n            int n = Integer.parseInt(sc.next());\n            boolean ok = false;\n            if(n%2 == 0){\n                int a = n/2;\n                int b = (int) Math.sqrt(a);\n                if(b*b == a){\n                    ok = true;\n                }\n            }\n            if(n%4 == 0){\n                int a = n/4;\n                int b = (int) Math.sqrt(a);\n                if(b*b == a){\n                    ok = true;\n                }\n            }\n            if(ok){\n                pw.println(\"YES\");\n            }else{\n                pw.println(\"NO\");\n            }\n        }\n        pw.flush();\n    }\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class B_14 {\n\t\n\t@SuppressWarnings(\"resource\")\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint t = input.nextInt();\n\t\tfor(int test = 0; test < t; test++){\n\t\t\tint n = input.nextInt();\n\t\t\tif(n % 2 == 0){\n\t\t\t\tif(Math.sqrt(n / 2) == (int)(Math.sqrt(n / 2))){\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t}else if(n % 4 == 0 && Math.sqrt(n / 4) == (int)(Math.sqrt(n / 4))){\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(\"NO\");\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}\n\t}\n\t\t\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int t=sc.nextInt();\n        while(t-->0)\n        {\n            int n=sc.nextInt();\n            if(n%2==1)\n            {\n                System.out.println(\"NO\");\n                continue;\n            }\n            // squares of 2\n            int num=n/2;\n            int root = (int)Math.sqrt(num);\n            if(root*root==num)\n            {\n                System.out.println(\"YES\");\n                continue;\n            }\n            // squares of 4\n            if(n%4!=0)\n            {\n                System.out.println(\"NO\");\n                continue;\n            }\n            num = n/4;\n            root = (int) Math.sqrt(num);\n            if(root*root==num)\n            {\n                System.out.println(\"YES\");\n            }\n            else\n            {\n                System.out.println(\"NO\");\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//package global14;\n\nimport java.util.Scanner;\n\npublic class B {\n\n    public static void main(String[] args){\n\n        Scanner in = new Scanner(System.in);\n\n        int t = in.nextInt();\n        while(t > 0){\n            t --;\n            int n = in.nextInt();\n            if(n % 2 != 0){\n                System.out.println(\"NO\");\n                continue;\n            }\n            int a = n / 2;\n            int x = (int)Math.sqrt(a);\n            if(x * x == a || (x + 1) * (x + 1) == a){\n                System.out.println(\"YES\");\n                continue;\n            }\n            a = n / 4;\n            if(n % 4 != 0){\n                System.out.println(\"NO\");\n                continue;\n            }\n            x = (int)Math.sqrt(a);\n            if(x * x == a || (x + 1) * (x + 1) == a){\n                System.out.println(\"YES\");\n                continue;\n            }\n            System.out.println(\"NO\");\n\n\n\n        }\n\n\n    }\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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 */\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        BPhoenixAndPuzzle solver = new BPhoenixAndPuzzle();\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 BPhoenixAndPuzzle {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            if (n % 2 == 1) {\n                out.println(\"NO\");\n                return;\n            }\n            n /= 2;\n            if (n == 1 || (int) Math.sqrt(n) * (int) (Math.sqrt(n)) == n) {\n                out.println(\"YES\");\n            } else {\n                if (n % 2 == 0) {\n                    n /= 2;\n                    if ((int) Math.sqrt(n) * (int) (Math.sqrt(n)) == n) {\n                        out.println(\"YES\");\n                        return;\n                    }\n                }\n                out.println(\"NO\");\n            }\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    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void print(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n        }\n\n        public void println(Object... objects) {\n            print(objects);\n            writer.println();\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "//package codeforces;\nimport java.io.PrintWriter;\nimport java.util.*;\npublic class codeforces {\n\tpublic static void main(String[] args) {\n\t\tPrintWriter out=new PrintWriter(System.out);\n    \tScanner s=new Scanner(System.in);  \n    \tint t=s.nextInt();\n    \tfor(int tt=0;tt<t;tt++) {\n    \t\tlong n=s.nextInt();\n    \t\tlong x=(long)Math.sqrt(n/2);\n    \t\tlong y=(long)Math.sqrt(n/4);\n    \t\tif(x*x*2==n || y*y*4==n) {\n    \t\t\tout.println(\"YES\");\n    \t\t}else {\n    \t\t\tout.println(\"NO\");\n    \t\t}\n    \t}\n    \tout.close();\n\t    s.close();\n\t}\n\t\n\tstatic void sort(int[] a) {\n\t\tArrayList<Integer> l=new ArrayList<>();\n\t\tfor (int i:a) l.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i=0; i<a.length; i++) a[i]=l.get(i);\n\t}\n\t\n}\n \n\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;\nimport java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;\nimport java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;\nimport java.lang.reflect.Array;import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;\nimport java.lang.reflect.Method;import java.security.AccessControlException;import java.util.Arrays;\nimport java.util.Collection;import java.util.Comparator;import java.util.List;import java.util.Map;\nimport java.util.Objects;import java.util.TreeMap;import java.util.function.Function;\nimport java.util.stream.Collectors;import java.util.stream.IntStream;import java.util.stream.LongStream;\nimport java.util.stream.Stream;public class _B {static public void main(final String[] args) \nthrows IOException{B._main(args);}\nstatic class B extends Solver{public B(){}@Override public void solve()throws IOException\n{int n=sc.nextInt();sc.nextLine();boolean res=false;if(n%2==0){int n1=n/2;int sq\n=(int)Math.ceil(Math.sqrt(n1));if(sq*sq==n1){res=true;}else if(n%4==0){n1=n/4;sq\n=(int)Math.ceil(Math.sqrt(n1));if(sq*sq==n1){res=true;}}}pw.println(Datas.yesNo(res));\n}static public void _main(String[]args)throws IOException{new B().run();}}static class \nDatas{static class Pair<K,V>{private K k;private V v;public Pair(final K t,final \nV u){this.k=t;this.v=u;}public K getKey(){return k;}public V getValue(){return v;\n}}final static String SPACE=\" \";public static TreeMap<Integer,Integer>mapc(final \nint[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<Integer,Integer>(),\n(res,i)->{res.put(a[i],res.getOrDefault(a[i],0)+1);},Map::putAll);}public static \nTreeMap<Long,Integer>mapc(final long[]a){return IntStream.range(0,a.length).collect(\n()->new TreeMap<Long,Integer>(),(res,i)->{res.put(a[i],res.getOrDefault(a[i],0)+\n1);},Map::putAll);}public static<T>TreeMap<T,Integer>mapc(final T[]a,Comparator<T>\ncmp){return IntStream.range(0,a.length).collect(cmp!=null?()->new TreeMap<T,Integer>(cmp)\n:()->new TreeMap<T,Integer>(),(res,i)->{res.put(a[i],res.getOrDefault(a[i],0)+1);\n},Map::putAll);}public static<T>TreeMap<T,Integer>mapc(final T[]a){return mapc(a,\nnull);}public static TreeMap<Integer,Integer>mapc(final IntStream a){return a.collect(\n()->new TreeMap<Integer,Integer>(),(res,v)->{res.put(v,res.getOrDefault(v,0)+1);\n},Map::putAll);}public static TreeMap<Long,Integer>mapc(final LongStream a){return \na.collect(()->new TreeMap<Long,Integer>(),(res,v)->{res.put(v,res.getOrDefault(v,\n0)+1);},Map::putAll);}public static<T>TreeMap<T,Integer>mapc(final Stream<T>a,Comparator<T>\ncmp){return a.collect(cmp!=null?()->new TreeMap<T,Integer>(cmp):()->new TreeMap<T,\nInteger>(),(res,v)->{res.put(v,res.getOrDefault(v,0)+1);},Map::putAll);}public static\n<T>TreeMap<T,Integer>mapc(final Stream<T>a){return mapc(a,null);}public static<T>\nTreeMap<T,Integer>mapc(final Collection<T>a,Comparator<T>cmp){return mapc(a.stream(),\ncmp);}public static<T>TreeMap<T,Integer>mapc(final Collection<T>a){return mapc(a.stream());\n}public static TreeMap<Integer,List<Integer>>mapi(final int[]a){return IntStream.range(0,\na.length).collect(()->new TreeMap<Integer,List<Integer>>(),(res,i)->{if(!res.containsKey(a[i]))\n{res.put(a[i],Stream.of(i).collect(Collectors.toList()));}else{res.get(a[i]).add(i);\n}},Map::putAll);}public static TreeMap<Long,List<Integer>>mapi(final long[]a){return \nIntStream.range(0,a.length).collect(()->new TreeMap<Long,List<Integer>>(),(res,i)\n->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));\n}else{res.get(a[i]).add(i);}},Map::putAll);}public static<T>TreeMap<T,List<Integer>>\nmapi(final T[]a,Comparator<T>cmp){return IntStream.range(0,a.length).collect(cmp\n!=null?()->new TreeMap<T,List<Integer>>(cmp):()->new TreeMap<T,List<Integer>>(),\n(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));\n}else{res.get(a[i]).add(i);}},Map::putAll);}public static<T>TreeMap<T,List<Integer>>\nmapi(final T[]a){return mapi(a,null);}public static TreeMap<Integer,List<Integer>>\nmapi(final IntStream a){int[]i=new int[]{0};return a.collect(()->new TreeMap<Integer,\nList<Integer>>(),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));\n}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public static TreeMap<Long,List<Integer>>\nmapi(final LongStream a){int[]i=new int[]{0};return a.collect(()->new TreeMap<Long,\nList<Integer>>(),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));\n}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public static<T>TreeMap<T,List<Integer>>\nmapi(final Stream<T>a,Comparator<T>cmp){int[]i=new int[]{0};return a.collect(cmp\n!=null?()->new TreeMap<T,List<Integer>>(cmp):()->new TreeMap<T,List<Integer>>(),\n(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));\n}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public static<T>TreeMap<T,List<Integer>>\nmapi(final Stream<T>a){return mapi(a,null);}public static<T>TreeMap<T,List<Integer>>\nmapi(final Collection<T>a,Comparator<T>cmp){return mapi(a.stream(),cmp);}public \nstatic<T>TreeMap<T,List<Integer>>mapi(final Collection<T>a){return mapi(a.stream());\n}public static List<int[]>listi(final int[]a){return IntStream.range(0,a.length).mapToObj(i\n->new int[]{a[i],i}).collect(Collectors.toList());}public static List<long[]>listi(final \nlong[]a){return IntStream.range(0,a.length).mapToObj(i->new long[]{a[i],i}).collect(Collectors.toList());\n}public static<T>List<Pair<T,Integer>>listi(final T[]a){return IntStream.range(0,\na.length).mapToObj(i->new Pair<T,Integer>(a[i],i)).collect(Collectors.toList());\n}public static List<int[]>listi(final IntStream a){int[]i=new int[]{0};return a.mapToObj(v\n->new int[]{v,i[0]++}).collect(Collectors.toList());}public static List<long[]>listi(final \nLongStream a){int[]i=new int[]{0};return a.mapToObj(v->new long[]{v,i[0]++}).collect(Collectors.toList());\n}public static<T>List<Pair<T,Integer>>listi(final Stream<T>a){int[]i=new int[]{0};\nreturn a.map(v->new Pair<T,Integer>(v,i[0]++)).collect(Collectors.toList());}public \nstatic<T>List<Pair<T,Integer>>listi(final Collection<T>a){int[]i=new int[]{0};return \na.stream().map(v->new Pair<T,Integer>(v,i[0]++)).collect(Collectors.toList());}public \nstatic String join(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect(Collectors.joining(SPACE));\n}public static String join(final long[]a){return Arrays.stream(a).mapToObj(Long::toString).collect(Collectors.joining(SPACE));\n}public static<T>String join(final T[]a){return Arrays.stream(a).map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));\n}public static<T>String join(final T[]a,final Function<T,String>toString){return \nArrays.stream(a).map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}public \nstatic<T>String join(final Collection<T>a){return a.stream().map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));\n}public static<T>String join(final Collection<T>a,final Function<T,String>toString)\n{return a.stream().map(v->toString.apply(v)).collect(Collectors.joining(SPACE));\n}public static<T>String join(final Stream<T>a){return a.map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));\n}public static<T>String join(final Stream<T>a,final Function<T,String>toString){\nreturn a.map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}public static\n<T>String join(final IntStream a){return a.mapToObj(Integer::toString).collect(Collectors.joining(SPACE));\n}public static<T>String join(final LongStream a){return a.mapToObj(Long::toString).collect(Collectors.joining(SPACE));\n}public static List<Integer>list(final int[]a){return Arrays.stream(a).mapToObj(Integer::valueOf).collect(Collectors.toList());\n}public static List<Integer>list(final IntStream a){return a.mapToObj(Integer::valueOf).collect(Collectors.toList());\n}public static List<Long>list(final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors.toList());\n}public static List<Long>list(final LongStream a){return a.mapToObj(Long::valueOf).collect(Collectors.toList());\n}public static<T>List<T>list(final Stream<T>a){return a.collect(Collectors.toList());\n}public static<T>List<T>list(final Collection<T>a){return a.stream().collect(Collectors.toList());\n}public static<T>List<T>list(final T[]a){return Arrays.stream(a).collect(Collectors.toList());\n}public static String yesNo(final boolean res){return res?\"YES\":\"NO\";}public static \nString dump(Object obj){String res=\"\";if(obj!=null){Class cl=obj.getClass();String \ncls=cl.getName();if(cls.startsWith(\"[\")){res+=\"[\";for(int i=0;;i++){try{Object o\n=Array.get(obj,i);String s=dump(o);if(i>0){res+=\", \";}res+=s;}catch(ArrayIndexOutOfBoundsException \nex){break;}}res+=\"]\";}else if(Collection.class.isAssignableFrom(cl)){@SuppressWarnings(\"unchecked\")final \nObject s=((Collection)obj).stream().map(v->dump(v)).collect(Collectors.joining(\", \",\n\"[\",\"]\"));res+=s.toString();}else if(Map.class.isAssignableFrom(cl)){@SuppressWarnings(\"unchecked\")final \nObject s=((Map)obj).entrySet().stream().map(v->dump(v)).collect(Collectors.joining(\", \",\n\"{\",\"}\"));res+=s.toString();}else if(Character.class.isInstance(obj)|| Integer.class.isInstance(obj)\n|| Long.class.isInstance(obj)|| Float.class.isInstance(obj)|| Double.class.isInstance(obj)|| String.class.isInstance(obj)\n){res+=Objects.toString(obj);}else if(Map.Entry.class.isInstance(obj)){res+=dump(((Map.Entry)obj).getKey())\n+\"=\"+dump(((Map.Entry)obj).getValue());}else if(Stream.class.isInstance(obj)){@SuppressWarnings(\"unchecked\")\nfinal Object s=((Stream)obj).map(v->dump(v)).collect(Collectors.joining(\", \",\"[\",\n\"]\"));res+=s.toString();}else{res+=Stream.concat(Arrays.stream(obj.getClass().getFields()).map(v\n->{String name=v.getName();String val;try{Object o=v.get(obj);if(o!=null && v.isAnnotationPresent(Dump.class))\n{Dump an=v.getAnnotation(Dump.class);Class ocl=o.getClass();val=\"{\";for(String fn:an.fields())\n{try{Field f=ocl.getField(fn);val+=fn+\"=\"+dump(f.get(o))+\", \";}catch(NoSuchFieldException \nnsfex){try{@SuppressWarnings(\"unchecked\")final Method m=ocl.getMethod(fn);val+=fn+\"=\"+dump(m.invoke(o))\n+\", \";}catch(NoSuchMethodException | IllegalArgumentException | InvocationTargetException \nnsmex){}}}if(val.endsWith(\", \")){val=val.substring(0,val.length()-2);}val+=\"}\";}\nelse{val=dump(o);}}catch(IllegalAccessException ex){val=\"N/A\";}return name+\"=\"+val;\n}),Arrays.stream(obj.getClass().getMethods()).filter(m->m.isAnnotationPresent(Getter.class)).map(m\n->{String name=m.getName();String val;try{Object o=m.invoke(obj);if(o!=null && m.isAnnotationPresent(Dump.class))\n{Dump an=m.getAnnotation(Dump.class);Class ocl=o.getClass();val=\"{\";for(String fn:an.fields())\n{try{Field f=ocl.getField(fn);val+=fn+\"=\"+dump(f.get(o))+\", \";}catch(NoSuchFieldException \nnsfex){try{@SuppressWarnings(\"unchecked\")final Method m1=ocl.getMethod(fn);val+=fn+\"=\"+dump(m1.invoke(o))\n+\", \";}catch(NoSuchMethodException | IllegalArgumentException | InvocationTargetException \nnsmex){}}}if(val.endsWith(\", \")){val=val.substring(0,val.length()-2);}val+=\"}\";}else\n{val=dump(o);}}catch(IllegalAccessException | InvocationTargetException ex){val=\n\"N/A\";}return name+\"=\"+val;})).collect(Collectors.joining(\", \",\"{\"+obj.getClass().getName()\n+\": \",\"}\"));}}if(res.length()==0){res=\"<null>\";}return res;}}@Retention(RetentionPolicy.RUNTIME)\npublic @interface Dump{String[]fields();}@Retention(RetentionPolicy.RUNTIME)public @interface Getter{}static class \nMyScanner{private StringBuilder cache=new StringBuilder();int cache_pos=0;private \nint first_linebreak=-1;private int second_linebreak=-1;private StringBuilder sb=\nnew StringBuilder();private InputStream is=null;public MyScanner(final InputStream \nis){this.is=is;}public String charToString(final int c){return String.format(\"'%s'\",\nc=='\\n'?\"\\\\n\":(c=='\\r'?\"\\\\r\":String.valueOf((char)c)));}public int get(){int res\n=-1;if(cache_pos<cache.length()){res=cache.charAt(cache_pos);cache_pos++;if(cache_pos\n==cache.length()){cache.delete(0,cache_pos);cache_pos=0;}}else{try{res=is.read();\n}catch(IOException ex){throw new RuntimeException(ex);}}return res;}private void \nunget(final int c){if(cache_pos==0){cache.insert(0,(char)c);}else{cache_pos--;}}\npublic String nextLine(){sb.delete(0,sb.length());int c;boolean done=false;boolean \nend=false;while((c=get())!=-1){if(check_linebreak(c)){done=true;if(c==first_linebreak)\n{if(!end){end=true;}else{cache.append((char)c);break;}}else if(second_linebreak!=\n-1 && c==second_linebreak){break;}}if(end && c!=first_linebreak && c!=second_linebreak)\n{cache.append((char)c);break;}if(!done){sb.append((char)c);}}return sb.toString();\n}private boolean check_linebreak(int c){if(c=='\\n'|| c=='\\r'){if(first_linebreak\n==-1){first_linebreak=c;}else if(c!=first_linebreak && second_linebreak==-1){second_linebreak\n=c;}return true;}return false;}public int nextInt(){return Integer.parseInt(next());\n}public long nextLong(){return Long.parseLong(next());}public boolean hasNext(){\nboolean res=false;int c;while((c=get())!=-1){if(!check_linebreak(c)&& c!=' '&& c\n!='\\t'){res=true;unget(c);break;}}return res;}public String next(){sb.delete(0,sb.length());\nboolean started=false;int c;while((c=get())!=-1){if(check_linebreak(c)|| c==' '|| \nc=='\\t'){if(started){unget(c);break;}}else{started=true;sb.append((char)c);}}return \nsb.toString();}public int nextChar(){return get();}public boolean eof(){int c=get();\nboolean res=false;if(c!=-1){unget(c);}else{res=true;}return res;}public double nextDouble()\n{return Double.parseDouble(next());}}static abstract class Solver{protected String \nnameIn=null;protected String nameOut=null;protected boolean singleTest=false;protected \nMyScanner sc=null;protected PrintWriter pw=null;private int current_test=0;private \nint count_tests=0;protected int currentTest(){return current_test;}protected int \ncountTests(){return count_tests;}private void process()throws IOException{if(!singleTest)\n{count_tests=sc.nextInt();sc.nextLine();for(current_test=1;current_test<=count_tests;\ncurrent_test++){solve();pw.flush();}}else{count_tests=1;current_test=1;solve();}\n}abstract protected void solve()throws IOException;public void run()throws IOException\n{boolean done=false;try{if(nameIn!=null){if(new File(nameIn).exists()){try(FileInputStream \nfis=new FileInputStream(nameIn);PrintWriter pw0=select_output();){select_output();\ndone=true;sc=new MyScanner(fis);pw=pw0;process();}}else{throw new RuntimeException(\"File \"\n+new File(nameIn).getAbsolutePath()+\" does not exist!\");}}}catch(IOException | AccessControlException \nex){}if(!done){try(PrintWriter pw0=select_output();){sc=new MyScanner(System.in);\npw=pw0;process();}}}private PrintWriter select_output()throws FileNotFoundException\n{if(nameOut!=null){return new PrintWriter(nameOut);}return new PrintWriter(System.out);\n}}static abstract class Tester{static public int getRandomInt(final int min,final \nint max){return(min+(int)Math.floor(Math.random()*(max-min+1)));}static public long \ngetRandomLong(final long min,final long max){return(min+(long)Math.floor(Math.random()\n*(max-min+1)));}static public double getRandomDouble(final double min,final double \nmaxExclusive){return(min+Math.random()*(maxExclusive-min));}abstract protected void \ntestOutput(final List<String>output_data);abstract protected void generateInput();\nabstract protected String inputDataToString();private boolean break_tester=false;\nprotected void beforeTesting(){}protected void breakTester(){break_tester=true;}\npublic boolean broken(){return break_tester;}}}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "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 t = sc.nextInt();\n\t\tfor (int z = 0; z < t; ++z) {\n\t\t\tint n = sc.nextInt();\n\t\t\tif (n%2==1) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tn/=2;\n\t\t\tint sqrt = (int)Math.sqrt(n);\n\t\t\tif (sqrt*sqrt==n) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (n%2==1) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tn/=2;\n\t\t\tsqrt = (int)Math.sqrt(n);\n\t\t\tif (sqrt*sqrt==n) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class CodeChef2 {\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  \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//    \n//\tstatic class Line{\n//\t\tPoint p1;\n//\t\tPoint p2;\n//\t\n//\t\tLine(Point p1,Point p2){\n//\t\t\tthis.p1=p1;\n//\t\t\tthis.p2=p2;\n//\t\t}\n//\t\t\n//\t    static Boolean intersects(Line l1,Line l2) \n//\t    { \n//\t    \tPoint A=l1.p1, B=l1.p2,C=l2.p1,D=l2.p2;\n//\t    \t\n//\t        long a1 = B.y - A.y; \n//\t        long b1 = A.x - B.x; \n//\t        long c1 = a1*(A.x) + b1*(A.y); \n//\t       \n//\t        long a2 = D.y - C.y; \n//\t        long b2 = C.x - D.x; \n//\t        long c2 = a2*(C.x)+ b2*(C.y); \n//\t       \n//\t        long determinant = a1*b2 - a2*b1; \n//\t       \n//\t        if (determinant == 0) \n//\t        { \n//\t            return false; \n//\t        } \n//\t        else\n//\t        { \n//\t            long x = (b2*c1 - b1*c2)/determinant; \n//\t            long y = (a1*c2 - a2*c1)/determinant; \n//\t            \n//\t            if(x>=0 || x<=1) {\n//\t            \treturn true;\n//\t            }\n//\t            return false;\n//\t        } \n//\t    }\n//\t    \n//\t    static Point getSlope(Line l) {\n//\t    \tlong num=l.p1.y - l.p2.y;\n//\t    \tlong den=l.p1.x - l.p2.x;\n//\t    \t\n//\t    \tlong gcd=gcd(num,den);\n//\t    \treturn new Point(num/gcd,den/gcd);\n//\t    }\n//\n//\t\tprivate static long gcd(long a, long b) {\n//\t\t\treturn b==0?a:gcd(b,a%b);\n//\t\t}\n//\t    \n//\t}\n\t\n\tstatic class Pair{\n\t\tint x;\n\t\tlong y;\n\t\t\n\t\tPair(int x,long y, Integer integer, int i){\n\t\t\tthis.y=y;\n\t\t\tthis.x=x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x +\" \"+ y+\")\";\n\t\t} \n\t\t\n\t\t\n\t}\n\t\n\tstatic class Edge{\n\t\tint src;\n\t\tint dest;\n\t\tint cost;\n\t\tint val;\n\t\t\n\t\tEdge(int src,int dest,int cost,int val){\n\t\t\tthis.src=src;\n\t\t\tthis.dest=dest;\n\t\t\tthis.cost=cost;\n\t\t\tthis.val=val;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + src +\" \"+ dest+\": \"+ cost +\" , \"+val+\")\";\n\t\t} \n\t\t\n\t\t\n\t}\n\t\n    static class Pair2{\n    \tPair node;\n    \tint dist;\n    \t\n    \tPair2(Pair p,int dist){\n    \t\tnode=p;\n    \t\tthis.dist=dist;\n    \t}\n    }\n    \n    static long M=1000000007l;\n    static HashMap<Character,ArrayList<Character>> dirs;\n    \n    public static void main(String[] args) throws Exception {\n        FastReader sc=new FastReader();\n        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));\n        \n//        ArrayList<Integer> prime=getPrimeSieve();\n        int t=sc.nextInt();\n        int po=0;\n        \n        dirs=new HashMap<>();\n        dirs.put('U', new ArrayList<>());\n        dirs.get('U').addAll(Arrays.asList('U','R','D','L'));\n        dirs.put('L', new ArrayList<>());\n        dirs.get('L').addAll(Arrays.asList('L','U','R','D'));\n        dirs.put('D', new ArrayList<>());\n        dirs.get('D').addAll(Arrays.asList('D','L','U','R'));\n        dirs.put('R', new ArrayList<>());\n        dirs.get('R').addAll(Arrays.asList('R','D','L','U'));\n//        \n        outer:while(t-- >0) {\n        \tpo++;\n        \tint n=sc.nextInt();\n        \tint x=(int) Math.sqrt(n/2);\n        \tint y=(int) Math.sqrt(n/4);\n        \t\n        \tif(x*x*2 == n || y*y*4==n)\n        \t\tbw.append(\"YES\\n\");\n        \telse {\n        \t\tbw.append(\"NO\\n\");\n        \t}\n//        \tint x=sc.nextInt();\n//        \tInteger[] arr=new Integer[n];\n//        \tlong sum=0;\n//        \t\n//        \tfor(int i=0;i<n;i++) {\n//        \t\tarr[i]=sc.nextInt();\n//        \t\tsum+=arr[i];\n//        \t}\n//        \t\n//        \tif(sum==x) {\n//    \t\t\tbw.append(\"NO\\n\");\n//    \t\t\tcontinue outer;\n//        \t}\n//\n//        \tArrays.sort(arr,Collections.reverseOrder());\n//        \t\n//        \tsum=0;\n//        \tfor(int i=0;i<n-1;i++) {\n//        \t\tsum+=arr[i];\n//        \t\t\n//        \t\tif(sum==x) {\n//        \t\t\tint temp=arr[i];\n//        \t\t\tarr[i+1]=arr[i];\n//        \t\t\tarr[i]=temp;\n//            \t\tsum=sum-arr[i+1]+arr[i];\n//        \t\t}\n//        \t}\n//        \tbw.append(\"YES\\n\");\n        \t\n//        \tfor(int i=0;i<n;i++) {\n//        \t\tbw.append(arr[i]+\" \");\n//        \t}\n//        \tbw.append(\"\\n\");\n//        \tbw.append(\"Case #\"+po+\": \"+0+\"\\n\");\n        }\n        bw.close();\n    }\n    \n    \n    \n\tprivate static int abs(int i) {\n\t\tif(i<0) {\n\t\t\treturn -i;\n\t\t}\n\t\treturn i;\n\t}\n\n\n\n\tprivate static String getRoaring2(String s) {\n\t\tString res=\"\";\n\t\tString max=\"\";\n\t\t\n\t\tfor(int i=1;i<=s.length()/2;i++) {\n\t\t\t\n\t\t\tlong prev=Long.parseLong(s.substring(0, i));\n\t\t\tres=Long.toString(prev);\n\t\t\tlong prev1=Long.parseLong(res);\n\t\t\tlong ans=Long.parseLong(s);\n\t\t\tlong next=prev+1;\n\t\t\t\n\t\t\twhile(prev1 <= ans) {\n\t\t\t\tprev1=Long.parseLong(res+Long.toString(next));\n\t\t\t\tres+=Long.toString(next);\n\t\t\t\tnext++;\n\t\t\t}\n\t\t\tif(max.length() == 0) {\n\t\t\t\tmax=res;\n\t\t\t\tres=\"\";\n\t\t\t}else {\n\t\t\t\tLong a=Long.parseLong(max);\n\t\t\t\tlong m=Math.max(a, prev1);\n\t\t\t\tmax=Long.toString(m);\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n\n\tprivate static String getRoaring(String s) {\n\t\tint val=-1;\n\t\tfor(int i=1;i<=s.length()/2;i++) {\n\t\t\tlong prev=Long.parseLong(s.substring(0, i));\n\t\t\tint j=i,update=i;\n\t\t\t\n\t\t\twhile(j<s.length()) {\n\t\t\t\tif(numDigit(prev+1) > numDigit(prev)) {\n\t\t\t\t\tupdate++;\n\t\t\t\t}\n\t\t\t\tif(j+update > s.length()) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlong cur=Long.parseLong(s.substring(j, j+update));\n\t\t\t\tif(cur != prev+1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\t\n\t\t\t\tprev=cur;\n\t\t\t\tj+=update;\n\t\t\t}\n\t\t\t\n\t\t\tif(j>= s.length()) {\n\t\t\t\tval=i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif(val==-1) {\n\t\t\treturn \"\";\n\t\t}else {\n\t\t\tString res=\"\";\n\t\t\tlong prev=Long.parseLong(s.substring(0, val));\n\t\t\tres=Long.toString(prev+1);\n\t\t\tSystem.out.println(res+ \" \");\n\t\t\t\n\t\t\tlong prev1=Long.parseLong(res);\n\t\t\t\n\t\t\tlong ans=Long.parseLong(s);\n\t\t\t\n\t\t\tlong next=prev+1;\n\t\t\t\n\t\t\twhile(prev1 <= ans) {\n\t\t\t\tprev1=Long.parseLong(res+Long.toString(next));\n\t\t\t\tnext++;\n\t\t\t}\n\t\t\treturn Long.toString(prev1);\n\t\t}\n\t\t\n\t}\n\n\tprivate static boolean isRoaring(String s) {\n\t\tfor(int i=1;i<=s.length()/2;i++) {\n\t\t\tlong prev=Long.parseLong(s.substring(0, i));\n//\t\t\tSystem.out.println(\"prev= \"+prev+\" \");\n\t\t\tint j=i,update=i;\n\t\t\t\n\t\t\twhile(j<s.length()) {\n\t\t\t\tif(numDigit(prev+1) > numDigit(prev)) {\n\t\t\t\t\tupdate++;\n\t\t\t\t}\n\t\t\t\tif(j+update > s.length()) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlong cur=Long.parseLong(s.substring(j, j+update));\n//\t\t\t\tSystem.out.println(\"cur= \"+cur+\" \");\n\t\t\t\tif(cur != prev+1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\t\n\t\t\t\tprev=cur;\n\t\t\t\tj+=update;\n\t\t\t}\n\t\t\t\n\t\t\tif(j>= s.length()) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tprivate static long numDigit(long ans) {\n\t\tlong sum=0;\n\t\twhile(ans > 0) {\n\t\t\tsum++;\n\t\t\tans/=10;\n\t\t}\n\t\treturn sum;\n\t}\n\n\tprivate static boolean go(int i, int j, long n, long m, Integer k, HashMap<Integer, Boolean>[][] dp) {\n\t\tif(i==n && j==m && k==0) {\n\t\t\treturn true;\n\t\t}\n\t\tif(i<1 || j<1 || i>n || j>m || k<0) {\n\t\t\treturn false;\n\t\t}\n\t\tif(dp[i][j].containsKey(k)) {\n\t\t\treturn dp[i][j].get(k);\n\t\t}\n\t\t\n\t\tboolean down=go(i+1,j,n,m,k-j,dp);\n\t\tboolean left=go(i,j+1,n,m,k-i,dp);\n\t\t\n\t\tdp[i][j].put(k, left||down);\n\t\treturn left||down;\n\t}\n\n\n\tprivate static long getDigitSum(long ans) {\n\t\tlong sum=0;\n\t\twhile(ans > 0) {\n\t\t\tsum+=ans%10;\n\t\t\tans/=10;\n\t\t}\n\t\treturn sum;\n\t}\n\n\tprivate static boolean getAns2(int l, long[] prefix, long x) {\n\t\t\n\t\tfor(int i=l;i<prefix.length-1;i++) {\n\t\t\tif((x^prefix[i]) == (prefix[prefix.length-1]^prefix[i])) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate static boolean getAns(long[] prefix) {\n\t\t\n\t\tfor(int i=0;i<prefix.length-1;i++) {\n\t\t\tif(prefix[i] == (prefix[prefix.length - 1]^prefix[i])) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\n\tprivate static void rotate(ArrayList<Integer> arr, int i) {\n\t\treverse(arr,0,i-1);\n\t\treverse(arr,i,arr.size()-1);\n\t\treverse(arr,0,arr.size()-1);\n\t}\n\n\tprivate static void reverse(ArrayList<Integer> arr, int l, int m) {\n\t\twhile(l<m) {\n\t\t\tint temp=arr.get(l);\n\t\t\tarr.set(l,arr.get(m));\n\t\t\tarr.set(m, temp);\n\t\t\tl++;\n\t\t\tm--;\n\t\t}\n\t}\n\n\tstatic int modInverse(int a, int m)\n    {\n        int m0 = m;\n        int y = 0, x = 1;\n \n        if (m == 1)\n            return 0;\n \n        while (a > 1) {\n            int q = a / m;\n \n            int t = m;\n\n            m = a % m;\n            a = t;\n            t = y;\n\n            y = x - q * y;\n            x = t;\n        }\n \n        if (x < 0)\n            x += m0;\n \n        return x;\n    }\n   \n\n\tprivate static long isPerfectSquare(long num) {\n\t\tlong l=1,h=num;\n\t\t\n\t\twhile(l<=h) {\n\t\t\tlong mid=l+(h-l)/2;\n\t\t\t\n\t\t\tif(mid*mid == num) {\n\t\t\t\treturn mid;\n\t\t\t}else if(mid*mid < num) {\n\t\t\t\tl=mid+1;\n\t\t\t}else {\n\t\t\t\th=mid-1;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\n\tprivate static void rightmax(long[] arr, long n,int[] res,int[] rightmax) {\n    \t\n\t\tDeque<Integer> stack=new ArrayDeque<>();\n\t\t\n\t\tstack.clear();\n\t\tfor(int i=(int) (n-1);i>=0;i--) {\n\t\t\twhile(!stack.isEmpty() && arr[stack.peek()] <= arr[i]) {\n\t\t\t\tstack.pop();\n\t\t\t}\n\t\t\t\n\t\t\trightmax[i]=(stack.isEmpty()?Integer.MAX_VALUE:stack.peek());\n\t\t\tstack.addFirst(i);\n\t\t}\n\t}\n\t\n\t\n\n\tprivate static boolean rotatedSorted(long[] arr, int min) {\n\t\treverse(arr,0,min-1);\n\t\treverse(arr,min,arr.length-1);\n\t\treverse(arr,0,arr.length-1);\n\t\t\n\t\tif(isSorted(arr)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate static boolean isSorted(long[] arr) {\n\t\tfor(int i=1;i<arr.length;i++) {\n\t\t\tif(arr[i] < arr[i-1]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate static int countDigit(long x) {\n\t\tint count=0;\n\t\twhile(x > 0) {\n\t\t\tx/=10;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tprivate static boolean isSub(String s, String c) {\n\t\tint l=0;\n\t\t\n\t\tfor(int i=0;i<s.length();i++) {\n\t\t\tif(l < c.length() && c.charAt(l)==s.charAt(i)) {\n\t\t\t\tl++;\n\t\t\t}\n\t\t\tif(l==c.length()) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(l==c.length()) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tstatic long power(long a, long d, long n)\n\t {\n\t\t    long res = 1; \n\t\t    a = a % n;\n\t\t    if (a == 0)\n\t\t      return 0; \n\t\t \n\t\t    while (d > 0)\n\t\t    {\n\t\t \n\t\t      if ((d & 1) != 0)\n\t\t        res = (res * a) % n;\n\t\t \n\t\t      d = d >> 1;\n\t\t      a = (a * a) % n;\n\t\t    }\n\t\t    return res;\n\t\t  }\n\n\tprivate static void reverse(long[] arr,int l,int m) {\n\t\twhile(l<m) {\n\t\t\tlong temp=arr[l];\n\t\t\tarr[l]=arr[m];\n\t\t\tarr[m]=temp;\n\t\t\tl++;\n\t\t\tm--;\n\t\t}\n\t}\n\n\t\n\t static int UpperBound(ArrayList<Integer> a, int x) {// x is the key or target value\n\t\t    int l=-1,r=a.size();\n\t\t    while(l+1<r) {\n\t\t       int m=(l+r)>>>1;\n\t\t       if(a.get(m)<=x) l=m;\n\t\t       else r=m;\n\t\t    }\n\t\t    return l+1;\n\t }\n\n\tprivate static void printMat(int[][] dp) {\n\t\t\n    \tSystem.out.println(\"--------------------------------------------------------------------\");\n\t\tfor(int i=0;i<dp.length;i++) {\n    \t\tfor(int j=0;j<dp[0].length;j++) {\n    \t\t\tSystem.out.print(dp[i][j]+\" \");\n    \t\t}\n    \t\tSystem.out.println();\n    \t}\n\t\tSystem.out.println(\"--------------------------------------------------------------------\");\n\t}\n   \n\tprivate static int highestOneBit(long n) {\n\t\tlong x=Long.highestOneBit(n);\n\t\tint c=0;\n\t\twhile(x >0) {\n\t\t\tx=x/2;\n\t\t\tc++;\n\t\t}\n\t\treturn c-1;\n\t}\n\t\n\tprivate static int bitcount(long l) {\n\t\tint count=0;\n\t\t\n    \twhile(l>0) {\n\t\t\tl-=(l&(-l));\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\n\n\tprivate static void bfs(HashMap<Integer, HashSet<Integer>> tree, int start) {\n    \tQueue<Integer> q=new LinkedList<>();\n\t\tq.offer(start);\n\t\tHashSet<Integer> visited=new HashSet<>();\n\t\t\n\t\tSystem.out.print(q.peek()+\"\\n\");\n\t\t\n\t\twhile(!q.isEmpty()) {\n\t\t\tint parent=q.poll();\n\t\t\t\n\t\t\tif(visited.contains(parent)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvisited.add(parent);\n\t\t\tint flag=0;\n\n\t\t\tfor(int child:tree.get(parent)) {\n\t\t\t\tif(!visited.contains(child)) {\n\t\t\t\t\tq.offer(child);\n\t\t\t\t\tSystem.out.print(child+\" \");\n\t\t\t\t\tflag=1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(flag==0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n\tstatic int par;\n\tprivate static HashMap<Integer, HashSet<Integer>> getTreeInputLevel(StringTokenizer st) {\n\t\tQueue<Integer> q=new LinkedList<>();\n\t\t\n\t\tHashMap<Integer, HashSet<Integer>> tree=new HashMap<>();\n\t\tq.offer(Integer.parseInt(st.nextToken()));\n\t\t\n\t\tpar=q.peek();\n\t\t\n\t\twhile(!q.isEmpty()) {\n\t\t\tint parent=q.poll();\n\t\t\t\n\t\t\tif(!tree.containsKey(parent)) {\n\t\t\t\ttree.put(parent, new HashSet<Integer>());\n\t\t\t}\n\t\t\t\n\t\t\tint left=-1,right=-1;\n\t\t\t\n\t\t\tif(st.hasMoreElements())\n\t\t\t\tleft=Integer.parseInt(st.nextToken());\n\t\t\t\n\t\t\tif(st.hasMoreElements())\n\t\t\t\tright=Integer.parseInt(st.nextToken());\n\t\t\t\n\t\t\tif(left != -1) {\n\t\t\t\ttree.get(parent).add(left);\n\t\t\t\tif(!tree.containsKey(left)) {\n\t\t\t\t\ttree.put(left, new HashSet<Integer>());\n\t\t\t\t}\n\t\t\t\ttree.get(left).add(parent);\n\t\t\t\tq.offer(left);\n\t\t\t}\n\t\t\t\n\t\t\tif(right != -1) {\n\t\t\t\ttree.get(parent).add(right);\n\t\t\t\tif(!tree.containsKey(right)) {\n\t\t\t\t\ttree.put(right, new HashSet<Integer>());\n\t\t\t\t}\n\t\t\t\ttree.get(right).add(parent);\n\t\t\t\tq.offer(right);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\ttree.remove(-1);\n\t\treturn tree;\n\t}\n\n\n\n\n\n\n\tprivate static int containsString(String s1,String s2) {\n\t\tString s=s1+\"#\"+s2;\n\t\tint[] z=getZfunc(s);\n\t\t\n\t\tboolean flag=false;\n\t\tfor(int i=0;i<s.length();i++) {\n\t\t\tif(z[i]==s1.length()) {\n\t\t\t\tflag=true;\n\t\t\t}\n\t\t}\n\t\tint count=0;\n\t\t\n\t\tfor(int i=s1.length();i<z.length;i++) {\n//\t\t\tSystem.out.print(z[i]+\" \");\n\t\t\tif(z[i]==s1.length()) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println();\n\t\treturn count;\n\t}\n\n\n\tprivate static int[] getZfunc(String s) {\n\t\tint[] z=new int[s.length()];\n\t\t int l=0,r=0;\n\t\t \n\t\t for(int i=1;i<s.length();i++) {\n\t\t\t \n\t\t\t if(i <= r) {\n\t\t\t\t z[i]=Math.min( z[i-l] , r-i+1);\n\t\t\t }\n\t\t\t while(i+z[i] < s.length() && s.charAt(z[i])==s.charAt(i+z[i])) {\n\t\t\t\t z[i]++;\n\t\t\t }\n\t\t\t if(i+z[i] -1 > r) {\n\t\t\t\t l=i;\n\t\t\t\t r=i+z[i]-1;\n\t\t\t }\n\t\t\t \n\t\t }\n\t\treturn z;\n\t}\n\n\n\t\n\tprivate static long ceil(long n,long k) {\n\t\tlong ans;\n\t\tif(n%k==0) {\n\t\t\tans=n/k;\n\t\t}else {\n\t\t\tans=n/k+1;\n\t\t}\n\t\treturn ans;\n\t}\n\n\n\tstatic ArrayList<Integer> getDivisor(int n){\n    \tArrayList<Integer> div=new ArrayList<>();\n    \t\n        for (int i=1; i*i <= n; i++) \n        { \n            if (n%i==0) \n            { \n                if (n/i == i) \n                    div.add(i); \n                else { \n                    div.add(i);\n                    div.add(n/i);\n                }\n            } \n        }\n        \n        return div;\n    }\n\t\n    static long gcd(long x,long y) {\n    \treturn (y==0?x:gcd(y,x%y));\n    }\n    \n\tstatic int MAXN = 1000001;\n\tstatic int[] spf=new int[MAXN];\n\t\n    static void sieveSmallestFactor() \n    { \n        spf[1] = 1;\n        \n        for (int i=2; i<MAXN; i++) \n        \tspf[i] = i;\n        \n        for (int i=4; i<MAXN; i+=2) \n            spf[i] = 2; \n       \n        \n        for (int i=3; i*i<MAXN; i++) \n        { \n            if (spf[i] == i) \n            { \n                for (int j=i*i; j<MAXN; j+=i) \n                    if (spf[j]==j) \n                        spf[j] = i; \n            } \n        } \n    } \n    \n    \n\tprivate static HashMap<Integer,Integer> PrimeFactorizationmap(long n) {\n\t\tint count=0;\n\t\t\n\t\tHashMap<Integer,Integer> factors=new HashMap<>();\n\t\tif(n==1) {\n\t\t\tfactors.put( 1,1);\n\t\t\treturn factors;\n\t\t}else {\n\t\t\tfor(long i=2; i*i <= n ;i++) {\n\t\t\t\tlong z=n;\n\t\t\t\tif(z%i==0) {\n\t\t\t\t\tcount=0;\n\t\t\t\t\twhile(z%i==0) {\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tz=z/i;\n\t\t\t\t\t}\n\t\t\t\t\tfactors.put((int) (i+0),count);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(n>1) {\n\t\t\t\tfactors.put((int) (n+0),1);\n\t\t\t}\n\t\t}\n\t\treturn factors;\n\t}\n\t\n\n    \n    static HashMap<Integer,Integer> getprimeFactors(int n) \n    {\n        HashMap<Integer,Integer> ret = new HashMap<>();\n        while (n > 1) \n        { \n        \tif(ret.containsKey(spf[n])) {\n        \t\tret.put(spf[n],ret.get(spf[n])+1);\n        \t}else {\n        \t\tret.put(spf[(int) n],1);\n        \t}\n            n = n / spf[n]; \n        }\n        \n        return ret; \n    }\n    \n    static ArrayList<Integer> getPrimeSieve(){\n\t\tint primesieve[]=new int[1000005];\n\t\t\n\t\tArrays.fill(primesieve,0);\n\t\t\n\t\tfor(int i=2;i*i<primesieve.length;i++) {\n\t\t\tif(primesieve[i]==0)\t\n\t\t\t\tfor(int j=i*i;j<primesieve.length;j+=i) {\t\n\t\t\t\t\t\tprimesieve[j]=1;\n\t\t\t\t}\n\t\t}\n\t\t\n\t\tArrayList<Integer> prime=new ArrayList<>();\n\t\tfor(int i=2;i<primesieve.length;i++) {\n\t\t\tif(primesieve[i]==0) {\n\t\t\t\tprime.add(i);\n\t\t\t}\n\t\t}\n\t\treturn prime;\n    }\n    \n    \n    \n    \n\tprivate static boolean checkPrimeRM(long n,int k) {\n\t\tif(n<=4) {\n\t\t\treturn n==2||n==3;\n\t\t}\n\t\t\n\t\tint s=0;\n\t\tlong d=n-1;\n\t\t\n\t\twhile((d&1) != 1) {\n\t\t\td=d/2;\n\t\t\ts++;\n\t\t}\n\t\t\n\t\tfor(int i=0;i<k;i++) {\n\t\t\tlong a=2+(int)Math.random()*(n-4);\n\t\t\tif(isComposite(a,s,d,n)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate static boolean isComposite(long a, int s, long d, long n) {\n\t\tlong x=power(a,d,n);\n\t\t\n\t\tif(x==1 || x==n-1) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tfor(int i=0;i<s;i++){\n\t\t\tif(x%(n-1)==0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tx=(x*x)%n;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n    \n    public static HashSet<Long> getPrimeLtoR(int l,int r,List<Integer> prime) {\n\t\tif(l==1) l++;\n\t\t\n\t\tint[] arr=new int[r-l+1];\n\t\t\n\t\tArrays.fill(arr,0);\n\t\t\n\t\tfor(int i: prime ){\n\n\t\t\tif(i*i<=r) {\n\t\t\t\t\n\t\t\t\tint j=(l/i)*i;\n\t\t\t\tif(j<l) \n\t\t\t\t\tj+=i;\n\t\t\t\tfor(;j<=r;j+=i) {\n\t\t\t\t\tif(j!=i)\n\t\t\t\t\t\tarr[j-l]=1;\n\t\t\t\t}\n\t\t\t}else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tHashSet<Long> primeLtoR=new HashSet<>();\n\t\t\n\t\tfor(int i=0;i<arr.length;i++) {\n\t\t\tif(arr[i]==0) {\n\t\t\t\tprimeLtoR.add((i+l+0l));\n\t\t\t}\n\t\t}\n\t\treturn primeLtoR;\n\t}\n}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class B {\n    static class Scan {\n        private byte[] buf=new byte[1024];\n        private int index;\n        private InputStream in;\n        private int total;\n        public Scan()\n        {\n            in=System.in;\n        }\n        public int scan()throws IOException\n        {\n            if(total<0)\n            throw new InputMismatchException();\n            if(index>=total)\n            {\n                index=0;\n                total=in.read(buf);\n                if(total<=0)\n                return -1;\n            }\n            return buf[index++];\n        }\n        public int scanInt()throws IOException\n        {\n            int integer=0;\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            int neg=1;\n            if(n=='-')\n            {\n                neg=-1;\n                n=scan();\n            }\n            while(!isWhiteSpace(n))\n            {\n                if(n>='0'&&n<='9')\n                {\n                    integer*=10;\n                    integer+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            return neg*integer;\n        }\n        public double scanDouble()throws IOException\n        {\n            double doub=0;\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            int neg=1;\n            if(n=='-')\n            {\n                neg=-1;\n                n=scan();\n            }\n            while(!isWhiteSpace(n)&&n!='.')\n            {\n                if(n>='0'&&n<='9')\n                {\n                    doub*=10;\n                    doub+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            if(n=='.')\n            {\n                n=scan();\n                double temp=1;\n                while(!isWhiteSpace(n))\n                {\n                    if(n>='0'&&n<='9')\n                    {\n                        temp/=10;\n                        doub+=(n-'0')*temp;\n                        n=scan();\n                    }\n                    else throw new InputMismatchException();\n                }\n            }\n            return doub*neg;\n        }\n        public String scanString()throws IOException\n        {\n            StringBuilder sb=new StringBuilder();\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            while(!isWhiteSpace(n))\n            {\n                sb.append((char)n);\n                n=scan();\n            }\n            return sb.toString();\n        }\n        private boolean isWhiteSpace(int n)\n        {\n            if(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n            return true;\n            return false;\n        }\n    }\n    \n    public static void sort(int arr[],int l,int r) {    //sort(arr,0,n-1);\n        if(l==r) {\n            return;\n        }\n        int mid=(l+r)/2;\n        sort(arr,l,mid);\n        sort(arr,mid+1,r);\n        merge(arr,l,mid,mid+1,r);\n    }\n    public static void merge(int arr[],int l1,int r1,int l2,int r2) {\n        int tmp[]=new int[r2-l1+1];\n        int indx1=l1,indx2=l2;\n        //sorting the two halves using a tmp array\n        for(int i=0;i<tmp.length;i++) {\n            if(indx1>r1) {\n                tmp[i]=arr[indx2];\n                indx2++;\n                continue;\n            }\n            if(indx2>r2) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            if(arr[indx1]<arr[indx2]) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            tmp[i]=arr[indx2];\n            indx2++;\n        }\n        //Copying the elements of tmp into the main array\n        for(int i=0,j=l1;i<tmp.length;i++,j++) {\n            arr[j]=tmp[i];\n        }\n    }\n    \n    public static void sort(long arr[],int l,int r) {    //sort(arr,0,n-1);\n        if(l==r) {\n            return;\n        }\n        int mid=(l+r)/2;\n        sort(arr,l,mid);\n        sort(arr,mid+1,r);\n        merge(arr,l,mid,mid+1,r);\n    }\n    public static void merge(long arr[],int l1,int r1,int l2,int r2) {\n        long tmp[]=new long[r2-l1+1];\n        int indx1=l1,indx2=l2;\n        //sorting the two halves using a tmp array\n        for(int i=0;i<tmp.length;i++) {\n            if(indx1>r1) {\n                tmp[i]=arr[indx2];\n                indx2++;\n                continue;\n            }\n            if(indx2>r2) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            if(arr[indx1]<arr[indx2]) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            tmp[i]=arr[indx2];\n            indx2++;\n        }\n        //Copying the elements of tmp into the main array\n        for(int i=0,j=l1;i<tmp.length;i++,j++) {\n            arr[j]=tmp[i];\n        }\n    }\n    \n    public static void main(String args[]) throws IOException {\n        Scan input=new Scan();\n        StringBuilder ans=new StringBuilder(\"\");\n        int test=input.scanInt();\n//        boolean sq[]=new boolean[1000000005];\n//        for(int i=1;i*i<sq.length;i++) {\n//            sq[i*i]=true;\n//        }\n        for(int tt=1;tt<=test;tt++) {\n            int n=input.scanInt();\n            if(n%2==1) {\n                ans.append(\"NO\\n\");\n                continue;\n            }\n            n/=2;\n            double sq=Math.sqrt(n);\n            if(Math.floor(sq)==Math.ceil(sq)) {\n                ans.append(\"YES\\n\");\n                continue;\n            }\n            if(n%2==1) {\n                ans.append(\"NO\\n\");\n                continue;\n            }\n            n/=2;\n            sq=Math.sqrt(n);\n            if(Math.floor(sq)==Math.ceil(sq)) {\n                ans.append(\"YES\\n\");\n                continue;\n            }\n            ans.append(\"NO\\n\");\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _G14 {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        int t = sc.nextInt();\n        Set<Long> square = new HashSet<>();\n        for (long i = 1; i <= (long) 1e5; i++) square.add(i * i);\n        while (t-- > 0) {\n            long n = sc.nextLong();\n            if ((n % 2 ==0 && square.contains(n / 2))|| (n % 4 == 0 &&square.contains(n / 4))) {\n                out.println(\"YES\");\n            } else {\n                out.println(\"NO\");\n            }\n        }\n        out.close();\n    }\n\n\n    static void sort(int[] a) {\n        ArrayList<Integer> q = new ArrayList<>();\n        for (int i : a) q.add(i);\n        Collections.sort(q);\n        for (int i = 0; i < a.length; i++) a[i] = q.get(i);\n    }\n\n    static void sort(long[] a) {\n        ArrayList<Long> q = new ArrayList<>();\n        for (long i : a) q.add(i);\n        Collections.sort(q);\n        for (int i = 0; i < a.length; i++) a[i] = q.get(i);\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}", "complexity": "linear", "problem": "1515_B. Phoenix and Puzzle", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashSet;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.util.Set;\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        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, OutputWriter out) {\n            int n = in.nextInt();\n\n            int d = in.nextInt();\n\n            int[] a = new int[n];\n\n            Set<Integer> set = new HashSet<>();\n\n            for (int i = 0; i < n; i++) {\n                a[i] = in.nextInt();\n\n            }\n\n\n            int ans = 2;\n            for (int i = 1; i < n; i++) {\n                if (a[i] - a[i - 1] == 2 * d) {\n                    ans++;\n                } else if (a[i] - a[i - 1] > 2 * d) {\n                    ans += 2;\n                }\n            }\n\n            out.println(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 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", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic static void quickSort(int[] a, int from, int to) {\n\t\tif (to - from <= 1) {\n\t\t\treturn;\n\t\t}\n\t\tint i = from;\n\t\tint j = to - 1;\n\t\tint x = a[from + (new Random()).nextInt(to - from)];\n\t\twhile (i <= j) {\n\t\t\twhile (a[i] < x) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (a[j] > x) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i <= j) {\n\t\t\t\tint t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t\ti++;\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\t\tquickSort(a, from, j + 1);\n\t\tquickSort(a, j + 1, to);\n\t}\n\n\t\n\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tHashSet<Long> ans = new HashSet<>();\n\t\tLong d = in.nextLong();\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tlong x = a[i] - d;\n\t\t\tboolean flag = true;\n\t\t\tfor (int j = 0; j < a.length; j++) {\n\t\t\t\tif (Math.abs(a[j] - x) < d) {\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\tif (flag) {\n\t\t\t\tans.add(x);\n\t\t\t}\n\t\t\tx = a[i] + d;\n\t\t\tflag = true;\n\t\t\tfor (int j = 0; j < a.length; j++) {\n\t\t\t\tif (Math.abs(a[j] - x) < d) {\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\tif (flag) {\n\t\t\t\tans.add(x);\n\t\t\t}\n\t\t}\n\t\tout.println(ans.size());\n\t}\n\n\tpublic void run() {\n\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[] args) {\n\t\tnew A().run();\n\t}\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "/*\nKeep solving problems.\n*/\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CFA {\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n    private static final long MOD = 1000L * 1000L * 1000L + 7;\n    private static final int[] dx = {0, -1, 0, 1};\n    private static final int[] dy = {1, 0, -1, 0};\n    private static final String yes = \"Yes\";\n    private static final String no = \"No\";\n\n    void solve() throws IOException {\n        int n = nextInt();\n        long d = nextInt();\n        long[] arr = nextLongArr(n);\n        Set<Long> res = new HashSet<>();\n        for (long cur : arr) {\n            if (findMin(cur - d, arr) == d) {\n                res.add(cur - d);\n            }\n            if (findMin(cur + d, arr) == d) {\n                res.add(cur + d);\n            }\n        }\n\n        outln(res.size());\n    }\n\n    long findMin(long cur, long[] arr) {\n        long res = Long.MAX_VALUE;\n        for (long v : arr) {\n            res = Math.min(res, Math.abs(v - cur));\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    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        outln(String.format(\"%.9f%n\", val));\n    }\n    public CFA() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\n    }\n    public static void main(String[] args) throws IOException {\n        new CFA();\n    }\n\n    public long[] nextLongArr(int n) throws IOException{\n        long[] res = new long[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextLong();\n        return res;\n    }\n    public int[] nextIntArr(int n) throws IOException {\n        int[] res = new int[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextInt();\n        return res;\n    }\n    public String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return null;\n            }\n        }\n        return st.nextToken();\n    }\n    public String nextString() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            eof = true;\n            return null;\n        }\n    }\n    public int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n    public long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n    public double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt(), d = s.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tarr[i] = s.nextInt();\n\t\t}\n\t\tArrays.sort(arr);\n\t\tint count = 0;\n\t\tfor(int i = 1; i < n; i++){\n\t\t\tint dist = arr[i] - arr[i - 1];\n\t\t\tif(dist > 2 * d){\n\t\t\t\tcount += 2;\n\t\t\t}else if(dist == 2 * d){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\t\t\n\t\t}\n\t\tSystem.out.println(count + 2);\n\n\t}\n\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\npublic class Main {\n\n\n  private static void solve() {\n    int n = ni();\n    int d = ni();\n    int[] a = na(n);\n    Arrays.sort(a);\n\n    Set<Integer> set = new HashSet<>();\n    for (int i = 0; i < n; i ++) {\n      int cand1 = a[i] - d;\n      int cand2 = a[i] + d;\n      int d1 = d;\n      int d2 = d;\n      for (int j = 0; j < n; j ++) {\n        d1 = Math.min(d1, Math.abs(a[j] - cand1));\n        d2 = Math.min(d2, Math.abs(a[j] - cand2));\n      }\n      if (d1 == d) {\n        set.add(cand1);\n      }\n      if (d2 == d) {\n        set.add(cand2);\n      }\n    }\n    System.out.println(set.size());\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", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashSet;\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        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, OutputWriter out) {\n            int n = in.nextInt(), d = in.nextInt();\n            long a[] = in.parseLong1D(n);\n            int cnt = 0;\n            HashSet<Long> ans = new HashSet<>();\n            for (long v : a) {\n                long c = v - d;\n                if (isPos(a, c, d)) ans.add(c);\n                c = v + d;\n                if (isPos(a, c, d)) ans.add(c);\n            }\n            out.println(ans.size());\n        }\n\n        private boolean isPos(long a[], long c, long d) {\n            for (long v : a) {\n                if (Math.abs(v - c) < d) return false;\n            }\n            return true;\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void println(int i) {\n            writer.println(i);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        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 int nextInt() {\n            return readInt();\n        }\n\n        public long[] parseLong1D(int n) {\n            long r[] = new long[n];\n            for (int i = 0; i < n; i++) {\n                r[i] = readLong();\n            }\n            return r;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "// package CF;\n\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n\npublic class F {\n\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\tint n = sc.nextInt(), d = 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\t\t}\n\t\tArrays.sort(a);\n\t\tTreeSet<Integer> set = new TreeSet<>();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint tmp = a[i] - d;\n\t\t\tif(i == 0 || tmp > a[i-1] && tmp - a[i-1] >= d)\n\t\t\t\tset.add(tmp);\n\t\t\ttmp = a[i] + d;\n\t\t\tif(i == n-1 || tmp < a[i+1] && a[i+1] - tmp >= d)\n\t\t\t\tset.add(tmp);\n \t\t}\n\t\tout.println(set.size());\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s)\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(FileReader fileReader)\n\t\t{\n\t\t\tbr = new BufferedReader(fileReader);\n\t\t}\n\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException\n\t\t{\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic boolean ready() throws IOException\n\t\t{\n\t\t\treturn br.ready();\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "//package contests.CF495;\n\nimport java.io.*;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int n = sc.nextInt();\n        int d = sc.nextInt();\n        int[] arr = new int[n];\n        for (int i = 0; i < arr.length; i++) {\n            arr[i] = sc.nextInt();\n        }\n\n        HashSet<Integer> set = new HashSet<>();\n        for (int i = 0; i < arr.length; i++) {\n            set.add(arr[i]+d);\n            set.add(arr[i]-d);\n        }\n\n        int cnt = 0;\n        for (int loc: set) {\n            int minDist = (int)2e9;\n            for (int i = 0; i < n; i++) {\n                minDist = Math.min(minDist, Math.abs(arr[i]-loc));\n            }\n\n            if(minDist == d)\n                cnt++;\n        }\n\n        pw.println(cnt);\n\n        pw.flush();\n        pw.close();\n    }\n\n\n\n    static int[][] packD(int n, int[] from, int[] to) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int f : from) if(f != -1) p[f]++;\n        for (int i = 0; i < n; i++) g[i] = new int[p[i]];\n        for (int i = 0; i < from.length; i++) if(from[i] != -1) {g[from[i]][--p[from[i]]] = to[i];}\n        return g;\n    }\n\n    static void shuffle(int[] a)\n    {\n        int n = a.length;\n        for(int i = 0; i < n; i++)\n        {\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    static class Scanner\n    {\n        StringTokenizer st; BufferedReader br;\n        public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n        public Scanner(String s) throws FileNotFoundException {\tbr = new BufferedReader(new FileReader(new File(s)));}\n        public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}\n        public int nextInt() throws IOException {return Integer.parseInt(next());}\n        public long nextLong() throws IOException {return Long.parseLong(next());}\n        public String nextLine() throws IOException {return br.readLine();}\n        public boolean ready() throws IOException {return br.ready();}\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A6 \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tint d = in.nextInt();\n\t\tint ans=2;\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\tfor(int i=1;i<n;i++)\n\t\t{\n\t\t\tif(a[i]-a[i-1]>2*d)\n\t\t\t{\n\t\t\t\tans += 2;\n\t\t\t}\n\t\t\telse if(a[i]-a[i-1]==2*d)\n\t\t\t\tans += 1;\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    String fileName = \"<name>\";\n\n    public TreeSet<Integer> set = new TreeSet<>();\n\n    public int getLowerDist(int x) {\n        Integer higher = set.higher(x);\n        Integer lower = set.lower(x);\n        if (higher == null)\n            return lower;\n        if (lower == null)\n            return higher;\n        if (Math.abs(x - higher) < Math.abs(x - lower)) {\n            return higher;\n        } else {\n            return lower;\n        }\n    }\n\n    public void solve() throws IOException {\n        int n = nextInt();\n        int d = nextInt();\n        int[] a = new int[n];\n        Set<Integer> ans = new HashSet<>((int) 1e6, 1f);\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n            set.add(a[i]);\n        }\n        for (int i = 0; i < n; i++) {\n            int pos1 = a[i] + d;\n            int pos2 = a[i] - d;\n            if (!set.contains(pos1) && Math.abs(pos1 - getLowerDist(pos1)) == d) {\n                ans.add(pos1);\n            }\n            if (!set.contains(pos2) && Math.abs(pos2 - getLowerDist(pos2)) == d) {\n                ans.add(pos2);\n            }\n        }\n        out.print(ans.size());\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 A().run();\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Hotels {\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[] cities = new int[n];\n\t\tint d = input.nextInt();\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tcities[i] = input.nextInt();\n\t\t}\n\t\tint possibilities = 0;\n\t\tArrayList<Integer> newHotels = new ArrayList<Integer>();\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tint plusD = cities[i]+d;\n\t\t\tif (newHotels.indexOf(cities[i]+d)==-1 && minDist(plusD,cities)==d) {\n\t\t\t\tpossibilities++;\n\t\t\t\tnewHotels.add(cities[i]+d);\n\t\t\t}\n\t\t\tif (newHotels.indexOf(cities[i]-d)==-1 && minDist(cities[i]-d,cities)==d) {\n\t\t\t\tpossibilities++;\n\t\t\t\tnewHotels.add(cities[i]-d);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(possibilities);\n\t}\n\tpublic static int minDist(int a, int[] arr) {\n\t\tint minDist = Integer.MAX_VALUE;\n\t\tfor (int i=0; i<arr.length; i++) {\n\t\t\tminDist = Math.min(Math.abs(arr[i]-a), minDist);\n\t}\n\t\treturn minDist;\n\t}\n\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class main {\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        br = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(System.out);\n        int n = nextInt();\n        int d = nextInt();\n        int ans = 2;\n        int b[] = new int [n];\n        Arrays.sort(b);\n        for (int i = 0; i < n; i++) {\n            b[i] = nextInt();\n        }\n        for (int i = 1; i < n; i++) {\n            if (b[i] - b[i - 1] >= d * 2) {\n                ans++;\n            }\n            if (b[i] - b[i - 1] > d * 2) {\n                ans++;\n            }\n        }\n        pw.println(ans);\n        pw.close();\n    }\n    static BufferedReader br;\n    static StringTokenizer st = new StringTokenizer(\"\");\n\n    public static int nextInt() throws IOException {\n        if (!st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine());\n        }\n        return Integer.parseInt(st.nextToken());\n    }\n    public static String next() throws IOException {\n        if (!st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine());\n        }\n        return st.nextToken();\n    }\n    public static double nextDouble() throws IOException {\n        if (!st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine());\n        }\n        return Double.parseDouble(st.nextToken());\n    }\n    public static long nextLong() throws IOException {\n        if (!st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine());\n        }\n        return Long.parseLong(st.nextToken());\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class A {\n    public static void main(String[] args) throws Exception {\n        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n        // Scanner scan = new Scanner(System.in);\n        // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        // int n = Integer.parseInt(bf.readLine());\n        StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        int n = Integer.parseInt(st.nextToken());\n        int d = Integer.parseInt(st.nextToken());\n        st = new StringTokenizer(bf.readLine());\n        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        int ans = 2;\n        for(int i=0; i<n-1; i++) {\n          int diff = a[i+1]-a[i];\n          if(diff == 2*d) ans++;\n          else if(diff > 2*d) ans += 2;\n\n        }\n        System.out.println(ans);\n        // int n = scan.nextInt();\n\n        // out.close(); System.exit(0);\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.BigInteger;\nimport java.math.BigDecimal;\n\npublic class Main {\n\n    static class Task {\n\n        void solve(int test, FastScanner in, PrintWriter out) throws IOException {\n            int n = in.nextInt();\n            int d = 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\n            int ans = 2;\n            for (int i = 0; i < n - 1; i++) {\n                if (a[i + 1] - d > a[i] + d) {\n                    ans += 2;\n                } else if (a[i + 1] - d >= a[i] + d) {\n                    ans++;\n                }\n            }\n\n            out.println(ans);\n        }\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//        FastScanner in = new FastScanner(\"input.txt\");\n//        PrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n        new Task().solve(1, in, out);\n        out.close();\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer token;\n\n        public FastScanner(InputStream is) {\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        public String nextToken() {\n            while (token == null || !token.hasMoreTokens()) {\n                try {\n                    token = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return token.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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "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\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 d = nextInt();\n\t\tint[]x = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = nextInt();\n\t\t}\n\t\tint ans = 2;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif (x[i]-x[i-1]==2*d)\n\t\t\t\tans++;\n\t\t\telse if (x[i]-x[i-1] > 2*d)\n\t\t\t\tans += 2;\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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "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    public void run() {\n        InputReader sc = new InputReader(System.in);\n        PrintWriter w = new PrintWriter(System.out);\n \n        int n = sc.nextInt();\n        long d = sc.nextLong();\n\n        long a[] = new long[n];\n        for(int i = 0; i < n; ++i)\n            a[i] = sc.nextLong();\n\n        int ans = 0;\n\n        for(int i = 1; i < n; ++i) {\n            if(a[i] - a[i - 1] > 2 * d)\n                ans += 2;\n            else if(a[i] - a[i - 1] == 2 * d)\n                ans++;\n        }\n\n        ans += 2;\n\n        w.print(ans);\n\n        w.close();     \n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Set;\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 MaxHeap\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(1, in, out);\n    out.close();\n  }\n\n  static class TaskA {\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n      int d = in.nextInt();\n      Set<Integer> pts = new HashSet<>();\n      int[] x = in.nextIntArray(n);\n      for (int i = 0; i < n; i++) {\n        pts.add(x[i] - d);\n        pts.add(x[i] + d);\n      }\n      Set<Integer> ans = new HashSet<>();\n      for (int pt : pts) {\n        int min = (int) (1e9 + 10);\n        for (int i = 0; i < n; i++) {\n          min = Math.min(Math.abs(x[i] - pt), min);\n        }\n        if (min >= d) {\n          ans.add(pt);\n        }\n      }\n      out.println(ans.size());\n    }\n\n  }\n\n  static class InputReader {\n\n    private InputStream stream;\n    private byte[] buf = new byte[1 << 13];\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 UnknownError();\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 ex) {\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      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    public int[] nextIntArray(int n) {\n      int[] arr = new int[n];\n      for (int i = 0; i < n; i++) {\n        arr[i] = nextInt();\n      }\n      return arr;\n    }\n\n  }\n}\n\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "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        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, OutputWriter out) {\n            int n = in.nextInt();\n            int d = in.nextInt();\n            int[] x = new int[n + 1];\n\n            int ans = 2;\n\n            for (int i = 1; i <= n; i++) x[i] = in.nextInt();\n\n            for (int i = 1; i < n; i++) {\n                ans += (x[i + 1] - x[i] >= 2 * d) ? (x[i + 1] - x[i] == 2 * d ? 1 : 2) : 0;\n            }\n            out.print(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 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 interface SpaceCharFilter {\n            boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import javafx.collections.transformation.SortedList;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n\n        Scan scan = new Scan();\n        int n = scan.scanInt();\n        long d = scan.scanLong();\n        long a[]=new long[n];\n        for(int i=0;i<n;i++){\n            a[i]=scan.scanLong();\n        }\n        Arrays.sort(a);\n        int count=0;\n        for(int i=0;i<n-1;i++){\n            if((a[i+1]-d)>(a[i]+d)){\n                count+=2;\n            }else if((a[i+1]-d)==(a[i]+d)){\n                count++;\n            }\n        }\n        count+=2;\n        System.out.println(count);\n    }\n\n\n\n    static class Scan\n    {\n\n        private byte[] buf=new byte[1024];\n        private int index;\n        private InputStream in;\n        private int total;\n\n        public Scan()\n        {\n            in=System.in;\n        }\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\n\n        public char scanchar()throws IOException\n        {\n            int n=scan();\n            while(isWhiteSpace(n))\n                n=scan();\n            return (char)n;\n//            int neg=1;\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\n        public long scanLong()throws IOException\n        {\n            long lng=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                    lng*=10;\n                    lng+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            if(n=='.')\n            {\n                n=scan();\n                long temp=1;\n                while(!isWhiteSpace(n))\n                {\n                    if(n>='0'&&n<='9')\n                    {\n                        temp/=10;\n                        lng+=(n-'0')*temp;\n                        n=scan();\n                    }\n                    else throw new InputMismatchException();\n                }\n            }\n            return neg*lng;\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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "\n//package que_a;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n    InputStream is;\n    PrintWriter out;\n    \n    long mod = (long) (1e9 + 7);\n    boolean SHOW_TIME;\n    \n    void solve() {\n        //Enter code here utkarsh\n        //SHOW_TIME = true;\n        int n = ni();\n        int d = ni();\n        int a[] = na(n);\n        Arrays.sort(a);\n        int ans = 2;\n        for(int i = 0; i < n-1; i++) {\n            if(a[i+1] - a[i] == (2 * d))    ans++;\n            else if(a[i+1] - a[i] > (2 * d))    ans += 2;\n        }\n        out.println(ans);\n    }\n\n    //---------- I/O Template ----------\n    \n    public static void main(String[] args) { new utkarsh().run(); }\n    void run() { \n        is = System.in; \n        out = new PrintWriter(System.out);\n        long start = System.currentTimeMillis(); \n        solve(); \n        long end = System.currentTimeMillis();\n        if(SHOW_TIME) out.println(\"\\n\" + (end - start) + \" ms\");\n        out.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte() { \n        if(ptr >= len) { ptr = 0; \n            try { len = is.read(input); } \n            catch(IOException e) { throw new InputMismatchException(); } \n            if(len <= 0) { return -1; } \n        } return input[ptr++];\n    }\n    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n    int skip() { \n        int b = readByte(); \n        while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n        return b;\n    }\n    \n    char nc() { return (char)skip(); }\n    String ns() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    String nLine() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    int ni() { \n        int n = 0, b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        if(b == -1) { return -1; }  //no input \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n    long nl() { \n        long n = 0L;    int b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n\n    double nd() { return Double.parseDouble(ns()); }\n    float nf() { return Float.parseFloat(ns()); }\n    int[] na(int n) { \n        int a[] = new int[n]; \n        for(int i = 0; i < n; i++) { a[i] = ni(); } \n        return a;\n    }\n    char[] ns(int n) { \n        char c[] = new char[n]; \n        int i, b = skip(); \n        for(i = 0; i < n; i++) { \n            if(isSpaceChar(b)) { break; } \n            c[i] = (char)b; b = readByte(); \n        } return i == n ? c : Arrays.copyOf(c,i);\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "//package CodeforcesJava;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    public void solve(InputProvider input, PrintWriter output) throws IOException {\n        int n = input.nextInt();\n        int d = input.nextInt();\n        int count = 1;\n        int current = input.nextInt();\n        for (int i = 1; i < n; i++) {\n            int x = input.nextInt();\n            if (x - current == d * 2) {\n                count++;\n            } else if (x - current > d * 2) {\n                count += 2;\n            }\n            current = x;\n        }\n        count++;\n        output.print(count);\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}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class A {\n\tpublic static boolean ok(int []x,int d,int X)\n\t{\n\t\tfor(int i=0;i<x.length;i++)\n\t\t\tif(Math.abs(x[i]-X)<d)\n\t\t\t\treturn false;\n\t\treturn true;\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 ans=0;\n\t\tint n=sc.nextInt(),d=sc.nextInt();\n\t\tTreeSet<Integer> set=new TreeSet();\n\t\tint []x=new int [n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tx[i]=sc.nextInt();\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tint x1=x[i]+d;\n\t\t\tif (ok(x,d,x1))\n\t\t\t\tset.add(x1);\n\t\t\tx1=x[i]-d;\n\t\t\tif (ok(x,d,x1))\n\t\t\t\tset.add(x1);\n\t\t\t\n\t\t\t\n\t\t}\n\t\tpw.println(set.size());\n\t\t\t\n\t\t\n\t\tpw.close();\n\t\t\n\t}\n\t\n\t\n\tstatic class Scanner\n\t{\n\tStringTokenizer st;\n\tBufferedReader br;\n\n\tpublic Scanner(InputStream s) {\n\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t}\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\tpublic Scanner(String s) throws FileNotFoundException {\n\t\tbr = new BufferedReader(new FileReader(s));\n\t}\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(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 boolean ready() throws IOException {\n\t\treturn br.ready();\n\t}\n}\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\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 ankur\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            long k = in.nextLong();\n            HashMap<Long, Integer> hm = new HashMap<>();\n            long ar[] = in.nextLongArray(n);\n            for (int i = 0; i < n; i++) {\n                long dist = ar[i] + k;\n                long min = k;\n                for (int j = 0; j < n; j++) {\n                    min = Math.min(min, Math.abs(ar[j] - dist));\n                }\n                if (min == k) {\n                    hm.put(dist, 1);\n                }\n                dist = ar[i] - k;\n                min = k;\n                for (int j = 0; j < n; j++) {\n                    min = Math.min(min, Math.abs(ar[j] - dist));\n                }\n                if (min == k) {\n                    hm.put(dist, 1);\n                }\n            }\n            out.print(hm.size());\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            //*-*------clare------\n//remeber while comparing 2 non primitive data type not to use ==\n//remember Arrays.sort for primitive data has worst time case complexity of 0(n^2) bcoz it uses quick sort\n//again silly mistakes ,yr kb tk krta rhega ye mistakes\n//try to write simple codes ,break it into simple things\n//knowledge>rating\n        /*\n        public class Main\n        implements Runnable{\n    public static void main(String[] args) {\n        new Thread(null,new Main(),\"Main\",1<<26).start();\n\n    }\n    public void run() {\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();//chenge the name of task\n        solver.solve(1, in, out);\n        out.close();\n    }\n         */\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            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 long[] nextLongArray(int n) {\n            long a[] = new long[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextLong();\n            }\n            return a;\n        }\n\n        public boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "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.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class AA {\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 d =sc.nextInt();\n\t\tint[] hotels = new int[n];\n\t\tfor (int i = 0; i < hotels.length; i++) {\n\t\t\thotels[i] = sc.nextInt();\n\t\t}\n\t\tint count = 0;\n\t\tfor (int i = 0; i < hotels.length-1; i++) {\n\t\t\tint one = hotels[i];\n\t\t\tint two = hotels[i+1];\n\t\t\tdouble mid = (two-one)*1.0/2.0;\n\t\t\tif(mid==d) {\n\t\t\t\tcount++;\n//\t\t\t\tSystem.out.println(\"hello\"+\" \"+i+\" \"+(i+1));\n\t\t\t}\n\t\t\telse if(mid>d) {\n//\t\t\t\tSystem.out.println(\"hello2\"+\" \"+i+\" \"+(i+1));\n\t\t\t\tcount+=2;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tcount+=2;\n\t\tSystem.out.println(count);\n\t\t\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}//19 91 991 919 199\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", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskA\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew TaskA(System.in, System.out);\n\t}\n\n\tstatic class Solver implements Runnable\n\t{\n\t\tint n, d;\n\t\tlong[] arr;\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.nextInt();\n\t\t\td = in.nextInt();\n\t\t\tarr = in.nextLongArray(n);\n\n\t\t\tSet<Long> set = new HashSet<>();\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\tif (i == 0)\n\t\t\t\t\tset.add(arr[i] - d);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong left = arr[i] - d;\n\n\t\t\t\t\tif (left - arr[i - 1] >= d)\n\t\t\t\t\t\tset.add(left);\n\t\t\t\t}\n\n\t\t\t\tif (i == n - 1)\n\t\t\t\t\tset.add(arr[i] + d);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong right = arr[i] + d;\n\n\t\t\t\t\tif (arr[i + 1] - right >= d)\n\t\t\t\t\t\tset.add(right);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tout.println(set.size());\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 TaskA(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), \"TaskA\", 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\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n    public static void main(String[] args)\n    {\n        InputReader in = new InputReader(System.in);\n        OutputWriter out = new OutputWriter(System.out);\n         int n = in.nextInt();\n         int d = in.nextInt();\n         int[]a = new int[n];\n         int ans=2;\n\n         for (int i =0;i<n;i++)\n         {\n             a[i] = in.nextInt();\n\n         }\n         for (int i =0;i<n-1;i++)\n         {\n\n             if (a[i+1]-a[i]==2*d)\n                 ans++;\n             if (a[i+1]-a[i]>2*d)\n                 ans+=2;\n         }\n         out.printLine(ans);\n        out.flush();\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<Integer>[] 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\nclass InputReader {\n\n    private final InputStream stream;\n    private final byte[] buf = new byte[8192];\n    private int curChar, snumChars;\n\n    public InputReader(InputStream stream) {\n        this.stream = stream;\n    }\n\n    public int read() {\n        if (snumChars == -1)\n            throw new InputMismatchException();\n        if (curChar >= snumChars) {\n            curChar = 0;\n            try {\n                snumChars = stream.read(buf);\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            if (snumChars <= 0)\n                return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public int nextInt() {\n        int c = read();\n        while (isSpaceChar(c)) {\n            c = read();\n        }\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        int res = 0;\n        do {\n            res *= 10;\n            res += c - '0';\n            c = read();\n        } while (!isSpaceChar(c));\n        return res * sgn;\n    }\n\n    public long nextLong() {\n        int c = read();\n        while (isSpaceChar(c)) {\n            c = read();\n        }\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        long res = 0;\n        do {\n            res *= 10;\n            res += c - '0';\n            c = read();\n        } while (!isSpaceChar(c));\n        return res * sgn;\n    }\n\n    public int[] nextIntArray(int n) {\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n        }\n        return a;\n    }\n\n    public String readString() {\n        int c = read();\n        while (isSpaceChar(c)) {\n            c = read();\n        }\n        StringBuilder res = new StringBuilder();\n        do {\n            res.appendCodePoint(c);\n            c = read();\n        } while (!isSpaceChar(c));\n        return res.toString();\n    }\n\n    public String nextLine() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        StringBuilder res = new StringBuilder();\n        do {\n            res.appendCodePoint(c);\n            c = read();\n        } while (!isEndOfLine(c));\n        return res.toString();\n    }\n\n    public boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    private boolean isEndOfLine(int c) {\n        return c == '\\n' || c == '\\r' || c == -1;\n    }\n\n}\n\nclass OutputWriter {\n    private final PrintWriter writer;\n\n    public OutputWriter(OutputStream outputStream) {\n        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n    }\n\n    public OutputWriter(Writer writer) {\n        this.writer = new PrintWriter(writer);\n    }\n\n    public void print(Object... objects) {\n        for (int i = 0; i < objects.length; i++) {\n            if (i != 0)\n                writer.print(' ');\n            writer.print(objects[i]);\n        }\n    }\n\n    public void printLine(Object... objects) {\n        print(objects);\n        writer.println();\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    public void flush() {\n        writer.flush();\n    }\n\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "//package math_codet;\n\nimport java.io.*;\nimport java.util.*;\n /******************************************\n*    AUTHOR:         AMAN KUMAR SINGH        *\n*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *\n******************************************/\npublic class lets_do {\n    InputReader in;\n    PrintWriter out;\n    Helper_class h;\n    final long mod=1000000007;\n    public static void main(String[] args) throws java.lang.Exception{\n        new lets_do().run();\n    }\n    void run() throws Exception{\n        in=new InputReader();\n        out = new PrintWriter(System.out);\n        h = new Helper_class();\n        int t=1;\n        while(t-->0)\n            solve();\n        out.flush();    \n        out.close();\n    }\n    long[] arr;\n    int n;\n    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();\n    HashSet<Integer> hset=new HashSet<Integer>();\n    void solve(){\n        n=h.ni();\n        long d=h.nl();\n        int i=0;\n        arr=new long[n];\n        for(i=0;i<n;i++)\n            arr[i]=h.nl();\n        int count=2;\n        for(i=0;i<n-1;i++){\n            if(Math.abs(arr[i]-arr[i+1])>(2*d))\n                count+=2;\n            else if(Math.abs(arr[i]-arr[i+1])==(2*d))\n                count+=1;\n        }\n        h.pn(count);\n    }\n    class Helper_class{\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 bitcount(long n){return (n==0)?0:(1+bitcount(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(){return in.next();}\n        String nln(){return in.nextLine();}\n        int ni(){return Integer.parseInt(in.next());}\n        long nl(){return Long.parseLong(in.next());}\n        double nd(){return Double.parseDouble(in.next());}\n\n        long mul(long a,long b){\n            if(a>=mod)a%=mod;\n            if(b>=mod)b%=mod;\n            a*=b;\n            if(a>=mod)a%=mod;\n            return a;\n        }\n        long modPow(long a, long p){\n            long o = 1;\n            while(p>0){\n                if((p&1)==1)o = mul(o,a);\n                a = mul(a,a);\n                p>>=1;\n            }\n            return o;\n        }\n        long add(long a, long b){\n            if(a>=mod)a%=mod;\n            if(b>=mod)b%=mod;\n            if(b<0)b+=mod;\n            a+=b;\n            if(a>=mod)a-=mod;\n            return a;\n        }\n    }\n\n    class InputReader{\n        BufferedReader br;\n        StringTokenizer st;\n        public InputReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n \n        public InputReader(String s) throws Exception{\n            br = new BufferedReader(new FileReader(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        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}       ", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\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        ASonyaAndHotels solver = new ASonyaAndHotels();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ASonyaAndHotels {\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int d = in.scanInt();\n            int[] ar = new int[n];\n            int ans = 2;\n            for (int i = 0; i < n; i++) ar[i] = in.scanInt();\n            for (int i = 0; i < n - 1; i++) {\n                if (ar[i + 1] - ar[i] == 2 * d) ans++;\n                else if (ar[i + 1] - ar[i] > 2 * d) ans += 2;\n            }\n            out.println(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 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", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class R495A {\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\tint[] a=new int[n];\n\t\tfor(int i=0;i<n;i++) a[i]=scan.nextInt();\n\t\tint res=2;\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\tif(a[i+1]-a[i]>2*k) res+=2;\n\t\t\telse if(a[i+1]-a[i]==2*k) res++;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Main {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\tprivate PrintWriter pw;\n\tprivate long mod = 998244353;\n\n\tprivate StringBuilder ans_sb;\n\tprivate int sqrt;\n\tprivate void soln() {\n\t\tint n = nextInt();\n\t\tint d = nextInt();\n\t\tint[] arr = nextIntArray(n);\n\t\tint cnt = 2;\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\tint a1 = arr[i];\n\t\t\tint a2 = arr[i+1];\n\t\t\ta1 += d;\n\t\t\ta2 -= d;\n\t\t\tif(a1 < a2) {\n\t\t\t\tcnt+=2;\n\t\t\t}else if(a1==a2)\n\t\t\t\tcnt++;\n\t\t}\n\t\tpw.println(cnt);\n\t}\n\tprivate class Pair implements Comparable<Pair>{\n\t\tint x,i;\n\t\tpublic Pair(int a, int b) {\n\t\t\tx = a;\n\t\t\ti = b;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(\n\t\t\t\tPair o)\n\t\t{\n\t\t\treturn this.x - o.x;\n\t\t}\n\t}\n\tprivate int cc = 0;\nprivate void dfs(int c, int p, LinkedList<Integer>[] tree, int[] t, int[] tin, int[] tout, int[] arr) {\n\t//debug(c);\n\tt[cc] = arr[c];\n\ttin[c] = cc++;\n\tIterator<Integer> it = tree[c].listIterator();\n\twhile(it.hasNext()) {\n\t\tint x = it.next();\n\t\tif(x != p) {\n\t\t\tdfs(x, c, tree,t,tin,tout,arr);\n\t\t}\n\t}\n\ttout[c] = cc;\n}\npublic class Segment\n\t{\n\t\tprivate Node[] tree;\n\t\tprivate int[] lazy;\n\t\tprivate int size;\n\t\tprivate int n;\n\t\tprivate int[] base;\n\n\t\tprivate class Node\n\t\t{\n\t\t\tprivate int on;\n\t\t\tprivate int off;\n\t\t}\n\n\t\tpublic Segment(int n, int[] arr)\n\t\t{\n\t\t\tthis.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 Node[size];\n\t\t\tlazy = new int[size];\n\t\t\tthis.n = n;\n\t\t\t//this.set = set1;\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{\n\t\t\tif (l == r)\n\t\t\t{\n\t\t\t\ttree[id] = new Node();\n\t\t\t\tif(base[l] == 1)\n\t\t\t\t\ttree[id].on++;\n\t\t\t\telse\n\t\t\t\t\ttree[id].off++;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = ((l + r)>>1);\n\t\t\tbuild((id<<1)|1, l, mid);\n\t\t\tbuild((id<<1)+2, mid + 1, r);\n\t\t\ttree[id] = merge(tree[(id<<1)|1], tree[(id<<1)+2]);\n\t\t\t//System.out.println(l+\" \"+r+\" \"+tree[id].l+\" \"+tree[id].r+\" \"+tree[id].ans);\n\t\t}\n\t\tpublic Node merge(Node n1, Node n2) {\n\t\t\tNode ret = new Node();\n\t\t\tif(n1 == null && n2 == null)\n\t\t\t\treturn null;\n\t\t\telse if(n1 == null) {\n\t\t\t\tret.on = n2.on;\n\t\t\t\tret.off = n2.off;\n\t\t\t}\n\t\t\telse if(n2 == null) {\n\t\t\t\tret.on = n1.on;\n\t\t\t\tret.off = n1.off;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret.on = n1.on+n2.on;\n\t\t\t\tret.off = n2.off + n1.off;\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int query(int l, int r)\n\t\t{\n\t\t\tNode ret = queryUtil(l, r, 0, 0, n - 1);\n\t\t\tif(ret == null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\telse\n\t\t\t\treturn ret.on;\n\t\t}\n\n\t\tprivate Node queryUtil(int x, int y, int id, int l, int r)\n\t\t{\n\t\t\tif (l > y || x > r)\n\t\t\t\treturn null;\n\t\t\tif (x <= l && r <= y)\n\t\t\t{\n\t\t\t\t//shift(id,l,r);\n\t\t\t\treturn tree[id];\n\t\t\t}\n\t\t\tint mid = ((l + r)>>1);\n\t\t\tshift(id,l,r);\n\t\t\tNode q1 = queryUtil(x, y, (id<<1)|1, l, mid);\n\t\t\tNode q2 = queryUtil(x, y, (id<<1)+2, mid + 1, r);\n\t\t\treturn merge(q1, q2);\n\t\t}\n\t\t\n\t\tpublic void update(int x, int y, int c) {\n\t\t\tupdate1(x, y, c, 0, 0, n-1);\n\t\t}\n\t\t\n\t\tprivate void update1(int x, int y, int colour, int id, int l, int r)\n\t\t{\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\t\t\t{\n\t\t\t\tlazy[id]++;\n//\t\t\t\tlazy[id] %= 2;\n\t\t\t\tswitchNode(tree[id]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = ((l + r)>>1);\n\t\t\t//shift(id);\n\t\t\tif(y<=mid)\n\t\t\t\tupdate1(x, y, colour, (id<<1)|1, l, mid);\n\t\t\telse if(x>mid)\n\t\t\t\tupdate1(x, y, colour, (id<<1)+2, mid + 1, r);\n\t\t\telse {\n\t\t\t\tupdate1(x, y, colour, (id<<1)|1, l, mid);\n\t\t\t\tupdate1(x, y, colour, (id<<1)+2, mid + 1, r);\n\t\t\t}\n\t\t\ttree[id] = merge(tree[(id<<1)|1], tree[(id<<1)+2]);\t\n\t\t}\n\t\tprivate void shift(int id,int l, int r)\n\t\t{\n\t\t\tlazy[id] %= 2;\n\t\t\tif(lazy[id] != 0) {\n\t\t\t\tif(l != r) {\n\t\t\t\t\tlazy[(id<<1)|1] += lazy[id];\n\t\t\t\t\tlazy[(id<<1)+2] += lazy[id];\n\t\t\t\t\tswitchNode(tree[(id<<1)+2]);\n\t\t\t\t\tswitchNode(tree[(id<<1)|1]);\n\t\t\t\t}\n\t\t\t\t//switchNode(tree[(id<<1)+2]);\n\t\t\t\tlazy[id] = 0;\n\t\t\t}\n\t\t}\n\t\tprivate void switchNode(Node d) {\n\t\t\td.on ^= d.off;\n\t\t\td.off ^= d.on;\n\t\t\td.on ^= d.off;\n\t\t}\n\t}\n\n\tprivate void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tprivate 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 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\tnew Thread(null, new Runnable() {\n\t\t\t@Override\n\t\t\tpublic void run() {\n\t\t\t\tnew Main().solve();\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t\t//new Main().solve();\n\t}\n\n\tpublic StringBuilder solve() {\n\t\tInputReader(System.in);\n\t\t/*\n\t\t * try { InputReader(new FileInputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\in.txt\"));\n\t\t * } catch(FileNotFoundException e) {}\n\t\t */\n\t\tpw = new PrintWriter(System.out);\n\t\t// ans_sb = new StringBuilder();\n\t\tsoln();\n\n\t\tpw.close();\n\t\t// System.out.println(ans_sb);\n\t\treturn ans_sb;\n\t}\n\n\tpublic void InputReader(InputStream stream1) {\n\t\tstream = stream1;\n\t}\n\n\tprivate boolean isWhitespace(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\tprivate int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tprivate 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 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 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 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 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 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 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 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 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 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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*; \nimport java.text.DecimalFormat;\n\npublic class Main{\n    final long mod = (int)1e9+7, IINF = (long)1e19;\n    final int MAX = (int)5e5+1, MX = (int)1e7+1, INF = (int)1e9, root = 3;\n    DecimalFormat df = new DecimalFormat(\"0.0000000000000\");\n    double eps = 1e-9, PI = 3.141592653589793238462643383279502884197169399375105820974944;\n    static boolean multipleTC = false, memory = false;\n    FastReader in;PrintWriter out;\n    public static void main(String[] args) throws Exception{\n        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n        else new Main().run();\n    }\n\n    void run() throws Exception{\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n        for(int i = 1, T= (multipleTC)?ni():1; i<= T; i++)solve(i);\n        out.flush();\n        out.close();\n    }\n    \n    void solve(int TC) throws Exception{\n        int n = ni();\n        long d = nl();\n        long ans = 2;\n        long[] p = new long[n];\n        for(int i = 0; i< n; i++)p[i] = nl();\n        for(int i = 1; i< n; i++){\n            if(p[i]-p[i-1] == 2*d)ans++;\n            else if(p[i]-p[i-1]>2*d)ans+=2;\n        }\n        pn(ans);\n    }\n        \n    int[] reverse(int[] a){\n        int[] o = new int[a.length];\n        for(int i = 0; i< a.length; i++)o[i] = a[a.length-i-1];\n        return o;   \n    }\n\n    int[] sort(int[] a){\n        if(a.length==1)return a;\n        int mid = a.length/2;\n        int[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));\n        for(int i = 0, j = 0, k = 0; i< a.length; i++){\n            if(j<b.length && k<c.length){\n                if(b[j]<c[k])a[i] = b[j++];\n                else a[i] = c[k++];\n            }else if(j<b.length)a[i] = b[j++];\n            else a[i] = c[k++];\n        }\n        return a;\n    }\n\n    long[] sort(long[] a){\n        if(a.length==1)return a;\n        int mid = a.length/2;\n        long[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));\n        for(int i = 0, j = 0, k = 0; i< a.length; i++){\n            if(j<b.length && k<c.length){\n                if(b[j]<c[k])a[i] = b[j++];\n                else a[i] = c[k++];\n            }else if(j<b.length)a[i] = b[j++];\n            else a[i] = c[k++];\n        }\n        return a;\n    }\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 bitcount(long n){return (n==0)?0:(1+bitcount(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(){return in.next();}\n    String nln(){return in.nextLine();}\n    int ni(){return Integer.parseInt(in.next());}\n    long nl(){return Long.parseLong(in.next());}\n    double nd(){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(){\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        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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new A(), \"_cf\", 1 << 28).start();}\n\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"Go!\");\n\n\t\tint n = fs.nextInt();\n\t\tint d = fs.nextInt();\n\t\tint[] a = fs.nextIntArray(n);\n\t\tsort(a);\n\t\tlong res = 0;\n\t\tif(n == 1) {\n\t\t\tSystem.out.println(2);\n\t\t\treturn;\n\t\t}\n\n\t\tHashSet<Integer> set = new HashSet<>();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint one = a[i] - d;\n\t\t\tint min = Integer.MAX_VALUE;\n\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\tint dist = Math.abs(a[j] - one);\n\t\t\t\tmin = Math.min(min, dist);\n\t\t\t}\n\t\t\tif(min == d) set.add(one);\n\t\t\tone = a[i] + d;\n\t\t\tmin = Integer.MAX_VALUE;\n\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\tint dist = Math.abs(a[j] - one);\n\t\t\t\tmin = Math.min(min, dist);\n\t\t\t}\n\t\t\tif(min == d) set.add(one);\n\t\t}\n\t\tSystem.out.println(set.size());\n\t\tout.close();\n\t}\n\n\tvoid sort (int[] a) {\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < 50; i++) {\n\t\t\tRandom r = new Random();\n\t\t\tint x = r.nextInt(n), y = r.nextInt(n);\n\t\t\tint temp = a[x];\n\t\t\ta[x] = a[y];\n\t\t\ta[y] = temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}                \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class SonyaAndHotels {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int d = sc.nextInt();\n        int[] locs = new int[n];\n        for (int i = 0; i < n; i++) {\n            locs[i] = sc.nextInt();\n        }\n        Arrays.sort(locs);\n        int count = 2;\n        for (int i = 0; i < locs.length-1; i++) {\n            if(locs[i+1]-locs[i]==2*d){\n                count++;\n            }else if(locs[i+1]-locs[i]>2*d){\n                count+=2;\n            }\n        }\n        System.out.println(count);\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class CF495A {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        long d = s.nextLong();\n        long[] arr = new long[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextLong();\n        }\n        Arrays.sort(arr);\n        long ans  = 2;\n        for (int i = 0; i < n - 1; i++) {\n            if(arr[i + 1] - arr[i] > 2 * d){\n                ans += 2;\n            }else if(arr[i + 1] - arr[i] == 2 * d){\n                ans += 1;\n            }\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class A {\n    public static void main(String[] args)throws Throwable {\n        MyScanner sc=new MyScanner();\n        PrintWriter pw=new PrintWriter(System.out);\n\n        int n=sc.nextInt();\n        int d=sc.nextInt();\n        int [] a=new int [n];\n        for(int i=0;i<n;i++)\n            a[i]=sc.nextInt();\n        int ans=2;\n        for(int i=0;i<n-1;i++){\n            if(a[i+1]-a[i]<2*d)\n                continue;\n            if(a[i+1]-a[i]==2*d)\n                ans++;\n            else\n                ans+=2;\n        }\n        pw.println(ans);\n        pw.flush();\n        pw.close();\n    }\n\n    static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {while (st == null || !st.hasMoreElements()) {\n            try {st = new StringTokenizer(br.readLine());}\n            catch (IOException e) {e.printStackTrace();}}\n            return st.nextToken();}\n        int nextInt() {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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\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\tstatic class Task {\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint d = in.nextInt();\n\t\t\tint a[] = new int[n];\n\t\t\tint c[] = new int[2 * n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = in.nextInt();\n\t\t\t\tc[2 * i] = a[i] - d;\n\t\t\t\tc[2 * i + 1] = a[i] + d;\n\t\t\t}\n\t\t\tArrays.sort(c);\n\t\t\tint ans = 0;\n\t\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\t\tif (i != 0 && c[i] == c[i - 1]) continue;\n\t\t\t\tint mind = d + 1;\n\t\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\t\tmind = Math.min(mind, Math.abs(a[j] - c[i]));\n\t\t\t\tif (mind == d) {\n\t\t\t\t\tans += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\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 stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n\n        Scanner reader = new Scanner(System.in);\n        int n = reader.nextInt();\n        long d = reader.nextLong();\n        int[] a = new int[n];\n        for(int i = 0; i < n; i++)\n            a[i] = reader.nextInt();\n        Arrays.sort(a);\n        int ans = 2;\n        for(int i = 0; i < n - 1; i++){\n            if(a[i + 1] - a[i] > 2 * d) {\n                ans += 2;\n            }\n            else if(a[i + 1] - a[i] == 2 * d)\n                ans++;\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class q1 {\n    public static MyScanner in = new MyScanner();\n    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);\n    public static MyViewer view = new MyViewer();\n    public static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));\n    public static Random rand = new Random(System.currentTimeMillis());\n\n    public static class Pair<A, B> {\n        private final A first;\n        private final B second;\n\n        public Pair(A first, B second) {\n            super();\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 String toString() {\n            return \"(\" + first + \", \" + second + \")\";\n        }\n\n        public A getFirst() {\n            return first;\n        }\n\n        public B getSecond() {\n            return second;\n        }\n    }\n\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        private boolean randomInput = false;\n        private Random rand;\n\n        void randomInput(boolean r) {\n            randomInput = r;\n            rand = new Random(System.currentTimeMillis());\n            //rand = new Random(42);\n        }\n\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public MyScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public int nextInt(int val) {\n            return randomInput ? val : Integer.parseInt(next());\n        }\n\n        public int nextInt(int low, int high) {\n            if (randomInput) {\n                return rand.nextInt(high - low + 1) + low;\n            } else {\n                return Integer.parseInt(next());\n            }\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        long nextLong(long val) {\n            return randomInput ? val : Long.parseLong(next());\n        }\n\n        long nextLong(long low, long high) {\n            if (randomInput) {\n                return low + ((long) (rand.nextDouble() * (high - low + 1)));\n            } else {\n                return Long.parseLong(next());\n            }\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        int[] arrayInt(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextInt();\n            }\n            return a;\n        }\n\n        int[] arrayInt(int n, int low, int high) {\n            int[] a = new int[n];\n            if (randomInput) {\n                for (int i = 0; i < n; i++) {\n                    a[i] = rand.nextInt(high - low + 1) + low;\n                }\n            } else {\n                for (int i = 0; i < n; i++) {\n                    a[i] = nextInt();\n                }\n            }\n            return a;\n        }\n\n        ArrayList<Integer> list(int n) {\n            ArrayList<Integer> a = new ArrayList<Integer>(n);\n            for (int i = 0; i < n; i++) {\n                a.add(nextInt());\n            }\n            return a;\n        }\n\n        ArrayList<Integer> list(int n, int low, int high) {\n            ArrayList<Integer> a = new ArrayList<Integer>(n);\n            if (randomInput) {\n                for (int i = 0; i < n; i++) {\n                    a.add(rand.nextInt(high - low + 1) + low);\n                }\n            } else {\n                for (int i = 0; i < n; i++) {\n                    a.add(nextInt());\n                }\n            }\n            return a;\n        }\n\n        long[] arrayLong(int n) {\n            long[] a = new long[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextLong();\n            }\n            return a;\n        }\n\n        long[] arrayLong(int n, long low, long high) {\n            long[] a = new long[n];\n            if (randomInput) {\n                for (int i = 0; i < n; i++) {\n                    double r = rand.nextDouble();\n                    a[i] = (long) (r * (double) (high - low + 1)) + low;\n                    if (a[i] == 0) {\n                        out.println(\"Ouch : \" + r);\n                    }\n                }\n            } else {\n                for (int i = 0; i < n; i++) {\n                    a[i] = nextLong();\n                }\n            }\n            return a;\n        }\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n\n        void close() {\n            try {\n                br.close();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n        }\n\n        ArrayList<ArrayList<Integer>> randomTree(int n) {\n            ArrayList<ArrayList<Integer>> edges = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                edges.add(new ArrayList<>());\n            }\n\n            for (int i = 1; i < n; i++) {\n                int par = rand.nextInt(i);\n                edges.get(par).add(i);\n            }\n            return edges;\n        }\n    }\n\n    static class MyViewer {\n        private static boolean print = true;\n\n        public void on() {\n            print = true;\n        }\n\n        public void off() {\n            print = false;\n        }\n\n        public <T extends List> void list(T a) {\n            if (!print) return;\n            if (a == null) {\n                out.println(\"List: NULL\");\n                return;\n            }\n            if (a.size() == 0) {\n                out.println(\"List: []\");\n                return;\n            }\n            out.print(\"List: [\" + a.get(0));\n            for (int i = 1; i < a.size(); i++) {\n                out.print(\", \" + a.get(i));\n            }\n            out.println(\"] Len: \" + a.size());\n        }\n\n        public <T> void array(T[] a) {\n            if (!print) return;\n            if (a == null) {\n                out.println(\"Array: NULL\");\n                return;\n            }\n            if (a.length == 0) {\n                out.println(\"Array: []\");\n                return;\n            }\n            out.print(\"Array: [\" + a[0]);\n            for (int i = 1; i < a.length; i++) {\n                out.print(\", \" + a[i]);\n            }\n            out.println(\"] Len: \" + a.length);\n        }\n\n        public void array(boolean[] a) {\n            if (!print) return;\n            if (a == null) {\n                out.println(\"boolean[]: NULL\");\n                return;\n            }\n            if (a.length == 0) {\n                out.println(\"boolean[]: Len: 0\");\n                return;\n            }\n            out.print(\"boolean[] Len: \" + a.length + \" [\");\n            for (boolean x : a) {\n                out.print(x + \", \");\n            }\n            out.println(\"\\b\\b]\");\n        }\n\n        public void array(int[] a) {\n            if (!print) return;\n\n            if (a == null) {\n                out.println(\"Array: NULL\");\n                return;\n            }\n            if (a.length == 0) {\n                out.println(\"Array: []\");\n                return;\n            }\n            out.print(\"int[] Len: \" + a.length + \" [\");\n            for (int x : a) {\n                out.print(x + \", \");\n            }\n            out.println(\"\\b\\b]\");\n        }\n\n        public void array(long[] a) {\n            if (!print) return;\n            if (a == null) {\n                out.println(\"Array: NULL\");\n                return;\n            }\n            if (a.length == 0) {\n                out.println(\"Array: []\");\n                return;\n            }\n            out.print(\"long Array: [\");\n            for (long x : a) {\n                out.print(x + \", \");\n            }\n            out.println(\"\\b\\b] Len: \" + a.length);\n        }\n\n        public void matrix(int[][] a, int cutoff) {\n            if (cutoff == 0)\n                cutoff = Integer.MAX_VALUE;\n            if (a == null) {\n                out.println(\"Matrix: NULL\");\n                return;\n            }\n            for (int i = 0; i < a.length; i++) {\n                if (i < cutoff) {\n                    printMatrixRow(a[i], cutoff);\n                } else {\n                    out.println(\"     ...\");\n                    printMatrixRow(a[a.length - 1], cutoff);\n                    break;\n                }\n            }\n        }\n\n        public void matrix(long[][] a, long cutoff) {\n            if (cutoff == 0)\n                cutoff = Long.MAX_VALUE;\n            if (a == null) {\n                out.println(\"Matrix: NULL\");\n                return;\n            }\n            for (int i = 0; i < a.length; i++) {\n                if (i < cutoff) {\n                    printMatrixRow(a[i], cutoff);\n                } else {\n                    out.println(\"     ...\");\n                    printMatrixRow(a[a.length - 1], cutoff);\n                    break;\n                }\n            }\n        }\n\n        public void matrix(boolean[][] a, int cutoff) {\n            if (cutoff == 0)\n                cutoff = Integer.MAX_VALUE;\n            if (a == null) {\n                out.println(\"Matrix: NULL\");\n                return;\n            }\n            for (int i = 0; i < a.length; i++) {\n                if (i < cutoff) {\n                    printMatrixRow(a[i], cutoff);\n                } else {\n                    out.println(\"     ...\");\n                    printMatrixRow(a[a.length - 1], cutoff);\n                    break;\n                }\n            }\n        }\n\n        private void printMatrixRow(int[] a, int cutoff) {\n            for (int j = 0; j < a.length; j++) {\n                if (j < cutoff) {\n                    out.printf(\"%6d  \", a[j]);\n                } else {\n                    out.printf(\" ... %6d\", a[a.length - 1]);\n                    break;\n                }\n            }\n            out.println();\n        }\n\n        private void printMatrixRow(long[] a, long cutoff) {\n            for (int j = 0; j < a.length; j++) {\n                if (j < cutoff) {\n                    out.printf(\"%6d  \", a[j]);\n                } else {\n                    out.printf(\" ... %6d\", a[a.length - 1]);\n                    break;\n                }\n            }\n            out.println();\n        }\n\n        private void printMatrixRow(boolean[] a, int cutoff) {\n            for (int j = 0; j < a.length; j++) {\n                if (j < cutoff) {\n                    out.print(a[j] ? \"T \" : \"F \");\n                } else {\n                    out.print(\" ... \" + (a[a.length - 1] ? \"T\" : \"F\"));\n                    break;\n                }\n            }\n            out.println();\n        }\n\n    }\n\n    public static void main(String[] args) throws IOException {\n        int n = in.nextInt();\n        int d = in.nextInt();\n\n        int[] a = in.arrayInt(n);\n\n        int count = 2;\n\n        for(int i = 0 ;i < n-1; i++) {\n            if( a[i+1] - a[i] == 2 * d )\n                count += 1;\n            if( a[i+1] - a[i] > 2 * d)\n                count += 2;\n        }\n\n        out.println(count);\n\n\n\n        log.flush();\n        in.close();\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main{\n    void solve() {\n        int n=ni();\n        long d=nl();\n        long x[]=new long[n+1];\n        for(int i=1;i<=n;i++) x[i]=nl();\n        Arrays.sort(x,1,n+1);\n        int ans=2;\n        for(int i=2;i<=n;i++){\n            long x1=x[i-1]+d,x2=x[i]-d;\n            if(x[i]-x1>=d) ans++;\n            if(x2-x[i-1]>=d && x1!=x2) ans++;\n         //   pw.println(ans);\n        }\n        pw.println(ans);\n    }\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    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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Test5 {\n\n    static StreamTokenizer st = new StreamTokenizer(new InputStreamReader(System.in));\n    static int[] m;\n\n    public static void main(String[] z) throws Exception {\n        PrintWriter pw = new PrintWriter(System.out);\n        Scanner s = new Scanner(System.in);\n        int a = ni(), b=ni(), o=2;\n        m = new int[a];\n        for(int q=0; q<a; q++) m[q] = ni();\n        Arrays.sort(m);\n        for(int q=1; q<a; q++){\n            if(m[q]-m[q-1]==b*2) o++;\n            else if(m[q]-m[q-1]>b*2) o+=2;\n        }\n        System.out.println(o);\n        pw.flush();\n    }\n\n    static int ni() throws Exception{\n        st.nextToken();\n        return (int)st.nval;\n    }\n\n    static String ns() throws Exception{\n        st.nextToken();\n        return st.sval;\n    }\n\n    static long gcd(long a, long b){\n        for(; a>0 && b>0;)\n            if(a>b) a%=b;\n        else b%=a;\n        return a+b;\n    }\n\n    static class PyraSort {\n\n        private static int heapSize;\n\n        public static void sort(int[] 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(int[] 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(int[] 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(int[] a, int i, int j) {\n            a[i] ^= a[j] ^= a[i];\n            a[j] ^= a[i];\n        }\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{\n    static MyScanner scan;\n    static PrintWriter pw;\n    public static void main(String[] args) {\n        new Thread(null,null,\"_\",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        scan = new MyScanner();\n        pw = new PrintWriter(System.out, true);\n        StringBuilder sb = new StringBuilder();\n        int n = ni();\n        int d = ni();\n        int arr[] = new int[n];\n        int cnt = 2;\n        for(int i=0;i<n;++i)\n            arr[i] = ni();\n        for(int i=0;i<n-1;++i)\n        {\n            if(arr[i+1]-d==arr[i]+d)\n            {\n                ++cnt;\n                continue;\n            }\n            if(arr[i+1]-(arr[i]+d)>d)\n                ++cnt;\n            if((arr[i+1]-d)-arr[i]>d)\n                ++cnt;\n        }\n        pl(cnt);\n        pw.flush();\n        pw.close();\n    }\n    static long MMI(long A,long MOD)\n    {\n        return modpow(A,MOD-2,MOD);\n    }\n    static long modpow(long x,long y,long MOD)\n    {\n        if(y==0)\n            return 1;\n        if((y&1)==0)\n            return modpow((x*x)%MOD,y>>1,MOD);\n        else return (x*modpow(x,y-1,MOD))%MOD;\n    }\n    static class Pair implements Comparable<Pair>\n    {\n        int x,y;\n        Pair(int x,int y)\n        {\n            this.x=x;\n            this.y=y;\n        }\n        public int compareTo(Pair other)\n        {\n            if(this.x!=other.x)\n                return this.x-other.x;\n            return this.y-other.y;\n        }\n        public String toString()\n        {\n            return \"{\"+x+\",\"+y+\"}\";\n        }\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static String ne() throws IOException\n    {\n        return scan.next();\n    }\n    static String nel() throws IOException\n    {\n        return scan.nextLine();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static class MyScanner\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        MyScanner()\n        {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String nextLine()throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class ProblemA {\n\n\tString fileName = \"prizes\";\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint d = 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 = 2;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif (a[i] - a[i - 1] == 2 * d)\n\t\t\t\tans++;\n\t\t\tif (a[i] - a[i - 1] > 2 * d)\n\t\t\t\tans += 2;\n\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out, true);\n\n\t\t\t// out = new PrintWriter(fileName + \".out\");\n\t\t\t// br = new BufferedReader(new FileReader(fileName + \".in\"));\n\t\t\t// out = new PrintWriter(fileName + \".out\");\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\tBufferedReader br;\n\tStringTokenizer in;\n\tstatic PrintWriter 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 ProblemA().run();\n\t}\n\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport org.omg.CORBA.INTERNAL;\n\nimport java.awt.List;\nimport java.io.*;\nimport java.lang.*;\nimport java.lang.reflect.Array;\n\t\npublic class code1\n\t{\n\t\n\t\tpublic static long[][] cnt;\n\t\tpublic static void main(String[] args)\n\t\t{\n\t\t\tInputReader in = new InputReader(System.in);\n\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\t\n\t\t\t//Code starts..\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\tint n = in.nextInt();\n\t\t\tlong d = in.nextInt();\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i=0; i<n; i++)\n\t\t\t\ta[i] = in.nextLong();\n\t\t\t\n\t\t\t\n\t\t\tint ans = 0;\n\t\t\t//ans++;\n\t\t\tHashSet<Long> set = new HashSet<>();\n\t\t\t/*set.add(a[0]-d);\n\t\t\tif(Math.abs(a[0]+d-a[1])>=d)\n\t\t\t{\n\t\t\t\tans++;\n\t\t\t\tset.add(a[0]+d);\n\t\t\t}\n\t\t\t\n\t\t\t*/\n\t\t\tfor(int i=1; i<n; i++)\n\t\t\t{\n\t\t\t\t\n\t\t\t\t//pw.println(a[i]+\" \"+a[i-1]);\n\t\t\t\t\n\t\t\t\tlong dis = (long) Math.abs(a[i]-a[i-1]);\n\t\t\t\t//pw.println(dis);\n\t\t\t\tif(dis==2*d)\n\t\t\t\t\tans++;\n\t\t\t\t\n\t\t\t\tif(dis-(long)2*d>0)\n\t\t\t\t\tans += 2;\n\t\t\t\t\n\t\t\t\t\n\t\t\t}\n\t\t\tpw.println(ans+2);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t//Code ends....\n\t\t\t\n\t\t\tpw.flush();\n\t\t\tpw.close();\n\t\t}\n\t\t  \n\t\t\n\t\t\n\t\t\n\t\n\t\t\n\n\t\tstatic class InputReader \n\t\t{\n\t\t\t \n\t\t\tprivate final InputStream stream;\n\t\t\tprivate final byte[] buf = new byte[8192];\n\t\t\tprivate int curChar, snumChars;\n\t\t\tprivate SpaceCharFilter filter;\n\t \n\t\t\tpublic InputReader(InputStream stream) \n\t\t\t{\n\t\t\t\tthis.stream = stream;\n\t\t\t}\n\t \n\t\t\tpublic int snext() \n\t\t\t{\n\t\t\t\tif (snumChars == -1)\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tif (curChar >= snumChars) \n\t\t\t\t{\n\t\t\t\t\tcurChar = 0;\n\t\t\t\t\ttry \n\t\t\t\t\t{\n\t\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t\t} \n\t\t\t\t\tcatch (IOException e) \n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t}\n\t\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\treturn buf[curChar++];\n\t\t\t}\n\t \n\t\t\tpublic int nextInt() \n\t\t    {\n\t\t\t\tint c = snext();\n\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tc = snext();\n\t\t\t\t}\n\t\t\t\tint sgn = 1;\n\t\t\t\tif (c == '-')\n\t\t\t    {\n\t\t\t\t\tsgn = -1;\n\t\t\t\t\tc = snext();\n\t\t\t\t}\n\t\t\t\tint res = 0;\n\t\t\t\tdo \n\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\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\tc = snext();\n\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t\t}\n\t \n\t\t\tpublic long nextLong()\n\t\t    {\n\t\t\t\tint c = snext();\n\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tc = snext();\n\t\t\t\t}\n\t\t\t\tint sgn = 1;\n\t\t\t\tif (c == '-') \n\t\t\t\t{\n\t\t\t\t\tsgn = -1;\n\t\t\t\t\tc = snext();\n\t\t\t\t}\n\t\t\t\tlong res = 0;\n\t\t\t\tdo \n\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\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\tc = snext();\n\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t\t}\n\t \n\t\t\tpublic int[] nextIntArray(int n) \n\t\t\t{\n\t\t\t\tint a[] = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t\t{\n\t\t\t\t\ta[i] = nextInt();\n\t\t\t\t}\n\t\t\t\treturn a;\n\t\t\t}\n\t \n\t\t\tpublic String readString()\n\t\t    {\n\t\t\t\tint c = snext();\n\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tc = snext();\n\t\t\t\t}\n\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\tdo \n\t\t\t\t{\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\tc = snext();\n\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\treturn res.toString();\n\t\t\t}\n\t \n\t\t\tpublic String nextLine() \n\t\t\t{\n\t\t\t\tint c = snext();\n\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\tc = snext();\n\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\tdo \n\t\t\t\t{\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\tc = snext();\n\t\t\t\t} while (!isEndOfLine(c));\n\t\t\t\treturn res.toString();\n\t\t\t}\n\t \n\t\t\tpublic boolean isSpaceChar(int c) \n\t\t\t{\n\t\t\t\tif (filter != null)\n\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t}\n\t \n\t\t\tprivate boolean isEndOfLine(int c) \n\t\t\t{\n\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t}\n\t \n\t\t\tpublic interface SpaceCharFilter\n\t\t    {\n\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t}\n\t\t}\n\t\tpublic static long c = 0;\n\t\t\n\t\tpublic static long mod = 1000000007;\n\t\tpublic static int d;\n\t\tpublic static int p;\n\t\tpublic static int q;\n\t\tpublic static boolean flag;\n\t\tpublic static long INF= Long.MAX_VALUE;\n\t\t\n\t\tpublic static long fun(int[] a, int[] b, int m,int n) {\n\t\t\tlong result =0;\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{\n\t\t\t\t\tlong[] fib  = new long[Math.max(2, n+2)];\n\t\t\t\t\tfib[1] = a[i];\n\t\t\t\t\tfib[2] = b[j];\n\t\t\t\t\tfor(int k=3; k<=n; k++)\n\t\t\t\t\t\tfib[k] = (fib[k-1]%mod + fib[k-2]%mod)%mod;\n\t\t\t\t\tresult = (result%mod + fib[n]%mod)%mod;\n\t\t\t\t}\n\t\t\t\n\t\t\treturn result;\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tpublic static double slope(pair p1, pair p2)\n\t\t{\n\t\t\tdouble m = INF;\n\t\t\tif((p1.x - p2.x)!=0)\n\t\t\tm =  (p1.y - p2.y)/(p1.x - p2.x); \n\t\t\t\n\t\t\t\n\t\t\treturn Math.abs(m);\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tpublic static int count(String[] s, int f)\n\t\t{\n\t\t\tint count = 0;\n\t\t\tint n = s[0].length();\n\t\t\t\n\t\t\tif(f==1)\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<n; j++)\n\t\t\t\t{\n\t\t\t\t\tif(i%2==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(j%2==0 && s[i].charAt(j)=='0')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tif(j%2==1 && s[i].charAt(j)=='1')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\tif(i%2==1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(j%2==1 && s[i].charAt(j)=='0')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tif(j%2==0 && s[i].charAt(j)=='1')\n\t\t\t\t\t\t\tcount++;\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\telse\n\t\t\t{\n\t\t\t\n\t\t\t count = 0;\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<n; j++)\n\t\t\t\t{\n\t\t\t\t\tif(i%2==1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(j%2==0 && s[i].charAt(j)=='0')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tif(j%2==1 && s[i].charAt(j)=='1')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\tif(i%2==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(j%2==1 && s[i].charAt(j)=='0')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\tif(j%2==0 && s[i].charAt(j)=='1')\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n \n\t\t\t}\t\n\t\t\t\t\n\t\t\n\t\t\treturn count;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\t\t\n\t\tpublic static  int gcd(int p2, int p22)\n\t\t{\n\t\t    if (p2 == 0)\n\t\t        return (int) p22;\n\t\t    return gcd(p22%p2, p2);\n\t\t}\n\t\t\n\t\t\t\n\t\n\t\t\n\t\t\n\t\tpublic static int findGCD(int arr[], int n)\n\t\t{\n\t\t    int result = arr[0];\n\t\t    for (int i=1; i<n; i++)\n\t\t        result = gcd(arr[i], result);\n\t\t \n\t\t    return result;\n\t\t}\n\t\t\n\t\n \n\t\tpublic static void nextGreater(long[] a, int[] ans)\n\t\t{\n\t\t\t\n\t\t\tStack<Integer> stk = new Stack<>();\n\t\t\tstk.push(0);\n\t\t\t\n\t\t\t\n\t\t\tfor(int i=1; i<a.length; i++)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tif(!stk.isEmpty())\n\t\t\t\t{\n\t\t\t\tint s = stk.pop();\n\t\t\t\twhile(a[s]<a[i])\n\t\t\t\t{\n\t\t\t\t\tans[s] = i;\n\t\t\t\t\tif(!stk.isEmpty())\n\t\t\t\t\t\ts = stk.pop();\n\t\t\t\t\telse\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(a[s]>=a[i])\n\t\t\t\t\tstk.push(s);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstk.push(i);\n\t\t\t\t\n\t\t\t}\n\t\t\treturn;\n\t\t\t\n\t\t}\n\t\t\n\t\tpublic static void nextGreaterRev(long[] a, int[] ans)\n\t\t{\n\t\t\t\n\t\t\tint n = a.length;\n\t\t\tint[] pans = new int[n];\n\t\t\tArrays.fill(pans, -1);\n\t\t\tlong[] arev = new long[n];\n\t\t\tfor(int i=0; i<n; i++)\n\t\t\t\tarev[i] = a[n-1-i];\n\t\t\t\n\t\t\tStack<Integer> stk = new Stack<>();\n\t\t\tstk.push(0);\n\t\t\t\n\t\t\t\n\t\t\tfor(int i=1; i<n; i++)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tif(!stk.isEmpty())\n\t\t\t\t{\n\t\t\t\tint s = stk.pop();\n\t\t\t\twhile(arev[s]<arev[i])\n\t\t\t\t{\n\t\t\t\t\tpans[s] = n - i-1;\n\t\t\t\t\tif(!stk.isEmpty())\n\t\t\t\t\t\ts = stk.pop();\n\t\t\t\t\telse\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(arev[s]>=arev[i])\n\t\t\t\t\tstk.push(s);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstk.push(i);\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t//for(int i=0; i<n; i++)\n\t\t\t\t//System.out.print(pans[i]+\" \");\n\t\t\t\n\t\t\tfor(int i=0; i<n; i++)\n\t\t\t\tans[i] = pans[n-i-1];\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\treturn;\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tpublic static void nextSmaller(long[] a, int[] ans)\n\t\t{\n\t\t\t\n\t\t\tStack<Integer> stk = new Stack<>();\n\t\t\tstk.push(0);\n\t\t\t\n\t\t\t\n\t\t\tfor(int i=1; i<a.length; i++)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tif(!stk.isEmpty())\n\t\t\t\t{\n\t\t\t\tint s = stk.pop();\n\t\t\t\twhile(a[s]>a[i])\n\t\t\t\t{\n\t\t\t\t\tans[s] = i;\n\t\t\t\t\tif(!stk.isEmpty())\n\t\t\t\t\t\ts = stk.pop();\n\t\t\t\t\telse\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(a[s]<=a[i])\n\t\t\t\t\tstk.push(s);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstk.push(i);\n\t\t\t\t\n\t\t\t}\n\t\t\treturn;\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t    public static long lcm(int[] numbers) {\n\t        long lcm = 1;\n\t        int divisor = 2;\n\t        while (true) {\n\t            int cnt = 0;\n\t            boolean divisible = false;\n\t            for (int i = 0; i < numbers.length; i++) {\n\t                if (numbers[i] == 0) {\n\t                    return 0;\n\t                } else if (numbers[i] < 0) {\n\t                    numbers[i] = numbers[i] * (-1);\n\t                }\n\t                if (numbers[i] == 1) {\n\t                    cnt++;\n\t                }\n\t                if (numbers[i] % divisor == 0) {\n\t                    divisible = true;\n\t                    numbers[i] = numbers[i] / divisor;\n\t                }\n\t            }\n\t            if (divisible) {\n\t                lcm = lcm * divisor;\n\t            } else {\n\t                divisor++;\n\t            }\n\t            if (cnt == numbers.length) {\n\t                return lcm;\n\t            }\n\t        }\n\t    }\n\t\tpublic static long fact(long n) {\n\t\t\t\n\t\t\tlong factorial = 1;\n\t\t\t for(int i = 1; i <= n; i++)\n\t\t        {\n\t\t            factorial *= i;\n\t\t        }\n\t\t\t return factorial;\n\t\t}\n\t\t\npublic static void factSieve(int[] a, int n) {\n\t\t\t\n\t\t\t\n\t\t\tfor(int i=2; i<=n; i+=2)\n\t\t\t\ta[i] = 2;\n\t\t\t\n\t\t\t\n\t\t\tfor(int i=3; i<=n; i+=2)\n\t\t\t{\n\t\t\t\tif(a[i]==0)\n\t\t\t\t{\n\t\t\t\t\ta[i] = i;\n\t\t\t\t\t\n\t\t\t\t\tfor(int j=i; j*i<=n; j++)\n\t\t\t\t\t{\n\t\t\t\t\t\ta[i*j] = i;\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint k = 1000;\n\t\t\twhile(k!=1)\n\t\t\t{\n\t\t\t\tSystem.out.print(a[k]+\" \");\n\t\t\t\tk /= a[k];\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\n\t\t\n\t\tpublic static int lowerLimit(int[] a, int n) {\n\t\t\tint ans = 0;\n\t\t\t\n\t\t\tint ll = 0;\n\t\t\tint rl = a.length-1;\n\t\t//\tSystem.out.println(a[rl]+\" \"+n);\n\t\t\tif(a[0]>n)\n\t\t\t\treturn 0;\n\t\t\tif(a[0]==n)\n\t\t\t\treturn 1;\n\t\t\telse if(a[rl]<=n)\n\t\t\t\treturn rl+1;\n\t\t\n\t\t\twhile(ll<=rl)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tint mid = (ll+rl)/2;\n\t\t\t\tif(a[mid]==n)\n\t\t\t\t{\n\t\t\t\t\tans = mid + 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\telse if(a[mid]>n)\n\t\t\t\t{\n\t\t\t\t\trl = mid-1;\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\tans = mid+1;\n\t\t\t\t\tll = mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn ans; \n\t\t}\n\t\t\n\t\t\n\t\tpublic static long choose(long total, long choose){\n\t\t    if(total < choose)\n\t\t        return 0;\n\t\t    if(choose == 0 || choose == total)\n\t\t        return 1;\n\t\t    return (choose(total-1,choose-1)+choose(total-1,choose))%mod;\n\t\t}\n\t\t\n\t\tpublic static int[] suffle(int[] a,Random gen)\n\t\t{\n\t\t\tint n = a.length;\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t{\n\t\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\t\tint temp = a[ind];\n\t\t\t\ta[ind] = a[i];\n\t\t\t\ta[i] = temp;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\tpublic static long[] sort(long[] a)\n\t\t{\n\t\t\tRandom gen = new Random();\n\t\t\tint n = a.length;\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t{\n\t\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\t\tlong temp = a[ind];\n\t\t\t\ta[ind] = a[i];\n\t\t\t\ta[i] = temp;\n\t\t\t}\n\t\t\t\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\tpublic static pair[] sort(pair[] a)\n\t\t{\n\t\t\tRandom gen = new Random();\n\t\t\tint n = a.length;\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t{\n\t\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\t\tpair temp = a[ind];\n\t\t\t\ta[ind] = a[i];\n\t\t\t\ta[i] = temp;\n\t\t\t}\n\t\t\t\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\t\n\t\tpublic static int[] sort(int[] a)\n\t\t{\n\t\t\tRandom gen = new Random();\n\t\t\tint n = a.length;\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t{\n\t\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\t\tint temp = a[ind];\n\t\t\t\ta[ind] = a[i];\n\t\t\t\ta[i] = temp;\n\t\t\t}\n\t\t\t\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\tpublic static int floorSearch(int arr[], int low, int high, int x)\n\t\t{\n\t\t    if (low > high)\n\t\t        return -1;\n\t\t \n\t\t    if (x > arr[high])\n\t\t        return high;\n\t\t    int mid = (low+high)/2;\n\t\t \n\t\t \n\t\t    if (mid > 0 && arr[mid-1] < x && x < arr[mid])\n\t\t        return mid-1;\n\t\t \n\t\t    if (x < arr[mid])\n\t\t        return floorSearch(arr, low, mid-1, x);\n\t\t \n\t\t    return floorSearch(arr, mid+1, high, x);\n\t\t}\n\t\t\n\t\t\n\t\tpublic static void swap(int a, int b){\n\t\t\tint temp = a;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t}\n\t\tpublic static ArrayList<Integer> primeFactorization(int n)\n\t\t{\n\t\t\tArrayList<Integer> a =new ArrayList<Integer>();\n\t\t\tfor(int i=2;i*i<=n;i++)\n\t\t\t{\n\t\t\t\twhile(n%i==0)\n\t\t\t\t{\n\t\t\t\t\ta.add(i);\n\t\t\t\t\tn/=i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(n!=1)\n\t\t\t\ta.add(n);\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\t\n\t\tpublic static void sieve(boolean[] isPrime,int n)\n\t\t{\n\t\t\tfor(int i=1;i<n;i++)\n\t\t\t\tisPrime[i] = true;\n\t\t\t\n\t\t\tisPrime[0] = false;\n\t\t\tisPrime[1] = false;\n\t\t\t\n\t\t\tfor(int i=2;i*i<n;i++)\n\t\t\t{\n\t\t\t\tif(isPrime[i] == true)\n\t\t\t\t{\n\t\t\t\t\tfor(int j=(2*i);j<n;j+=i)\n\t\t\t\t\t\tisPrime[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic static int lowerbound(ArrayList<Long> net, long c2) {\n\t\t\tint i=Collections.binarySearch(net, c2);\n\t\t\tif(i<0)\n\t\t\t\ti = -(i+2);\n\t\t\treturn i;\n\t\t\t\n\t\t\t\n\t\t}\n\t\n\t\tpublic static int lowerboundArray(long[] psum, long c2) {\n\t\t\tint i=Arrays.binarySearch(psum, c2);\n\t\t\tif(i<0)\n\t\t\t\ti = -(i+2);\n\t\t\treturn i;\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\tpublic static int lowerboundArray(int[] psum, int c2) {\n\t\t\tint i=Arrays.binarySearch(psum, c2);\n\t\t\tif(i<0)\n\t\t\t\ti = -(i+2);\n\t\t\treturn i;\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tpublic static int uperboundArray(long[] psum, long c2) {\n\t\t\tint i=Arrays.binarySearch(psum, c2);\n\t\t\tif(i<0)\n\t\t\t\ti = -(i+1);\n\t\t\treturn i;\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tpublic static int uperbound(ArrayList<Long> net, long c2) {\n\t\t\tint i=Collections.binarySearch(net, c2);\n\t\t\tif(i<0)\n\t\t\t\ti = -(i+1);\n\t\t\treturn i;\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tpublic static 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\t\t\n\t\tpublic static long GCD(long a,long 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\t\t\n\t\tpublic static void extendedEuclid(int A,int B)\n\t\t{\n\t\t\tif(B==0)\n\t\t\t{\n\t\t\t\td = A;\n\t\t\t\tp = 1 ;\n\t\t\t\tq = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\textendedEuclid(B, A%B);\n\t\t\t\tint temp = p;\n\t\t\t\tp = q;\n\t\t\t\tq = temp - (A/B)*q;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic static long LCM(long a,long b)\n\t\t{\n\t\t\treturn (a*b)/GCD(a,b);\n\t\t}\n\t\t\n\t\tpublic static int LCM(int a,int b)\n\t\t{\n\t\t\treturn (a*b)/GCD(a,b);\n\t\t}\n\t\t\n\t\tpublic static int binaryExponentiation(int x,int n)\n\t\t{\n\t\t    int result=1;\n\t\t    while(n>0)\n\t\t    {\n\t\t        if(n % 2 ==1)\n\t\t            result=result * x;\n\t\t        x=x*x;\n\t\t        n=n/2;\n\t\t    }\n\t\t    return result;\n\t\t}\n\t\t\n\t\t\n\t\tpublic static int[] countDer(int n)\n\t    {\n\t        int der[] = new int[n + 1];\n\t     \n\t        der[0] = 1;\n\t        der[1] = 0;\n\t        der[2] = 1;\n\t     \n\t        for (int i = 3; i <= n; ++i)\n\t            der[i] = (i - 1) * (der[i - 1] + der[i - 2]);\n\t     \n\t        // Return result for n\n\t        return der;\n\t    }\n\t\t\n\t\t\n\t\t static long binomialCoeff(int n, int k)\n\t\t    {\n\t\t    long C[][] = new long[n+1][k+1];\n\t\t    int i, j;\n\t\t     \n\t\t        // Calculate  value of Binomial Coefficient in bottom up manner\n\t\t    for (i = 0; i <= n; i++)\n\t\t    {\n\t\t        for (j = 0; j <= Math.min(i, k); j++)\n\t\t        {\n\t\t            // Base Cases\n\t\t            if (j == 0 || j == i)\n\t\t                C[i][j] = 1;\n\t\t      \n\t\t            // Calculate value using previosly stored values\n\t\t            else\n\t\t                C[i][j] = C[i-1][j-1] + C[i-1][j];\n\t\t          }\n\t\t     }\n\t\t      \n\t\t    return C[n][k];\n\t\t    }\n\t\t\n\t\tpublic static long binaryExponentiation(long x,long n)\n\t\t{\n\t\t    long result=1;\n\t\t    while(n>0)\n\t\t    {\n\t\t        if(n % 2 ==1)\n\t\t            result=result * x;\n\t\t        x=(x%mod * x%mod)%mod;\n\t\t        n=n/2;\n\t\t    }\n\t\t    return result;\n\t\t}\n\t\t\n\t\tpublic static int modularExponentiation(int x,int n,int M)\n\t\t{\n\t\t    int result=1;\n\t\t    while(n>0)\n\t\t    {\n\t\t        if(n % 2 ==1)\n\t\t            result=(result * x)%M;\n\t\t        x=(x%M*x%M)%M;\n\t\t        n=n/2;\n\t\t    }\n\t\t    return result;\n\t\t}\n\t\t\n\t\tpublic static long modularExponentiation(long x,long n,long M)\n\t\t{\n\t\t    long result=1;\n\t\t    while(n>0)\n\t\t    {\n\t\t        if(n % 2 ==1)\n\t\t            result=(result %M* x%M)%M;\n\t\t        x=(x*x)%M;\n\t\t        n=n/2;\n\t\t    }\n\t\t    return result;\n\t\t}\n\t\t\n\t\tpublic static int modInverse(int A,int M)\n\t\t{\n\t\t    return modularExponentiation(A,M-2,M);\n\t\t}\n\t\t\n\t\tpublic static long modInverse(long A,long M)\n\t\t{\n\t\t    return modularExponentiation(A,M-2,M);\n\t\t}\n\t\t\n\t\t\n\t\tpublic static boolean checkYear(int year)\n\t    {\n\t\t\tif (year % 400 == 0)\n\t            return true;\n\t     \n\t        if (year % 100 == 0)\n\t            return false;\n\t     \n\t        if (year % 4 == 0)\n\t            return true;\n\t        return false;\n\t    }\n\t\t\n\t\tpublic static boolean isPrime(int n)\n\t\t{\n\t\t    \n\t\t    if (n <= 1)  return false;\n\t\t    if (n <= 3)  return true;\n\t\t    \n\t\t    if (n%2 == 0 || n%3 == 0) \n\t\t    \treturn false;\n\t\t \n\t\t    for (int i=5; i*i<=n; i=i+6)\n\t\t    {\n\t\t        if (n%i == 0 || n%(i+2) == 0)\n\t\t           return false;\n\t\t    }\n\t\t    \n\t\t    return true;\n\t\t}\n\t\t\n\t\tstatic class pair implements Comparable<pair>\n\n\t\t{\n\t\t\tLong x, y;\n\n\t\t\tpair(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\tpublic int compareTo(pair o) {\n\t\t\t\tint result = x.compareTo(o.x);\n\t\t\t\tif (result == 0)\n\t\t\t\t\tresult = y.compareTo(o.y);\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn x + \" \" + y;\n\t\t\t}\n\n\t\t\tpublic boolean equals(Object o) {\n\t\t\t\tif (o instanceof pair) {\n\t\t\t\t\tpair p = (pair) o;\n\t\t\t\t\tif(p.x-x==0 && p.y-y==0)\n\t\t\t\t\t\treturn true;\n\t\t\t\t\telse\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tpublic int hashCode() {\n\t\t\t\treturn new Long(x).hashCode() * 31 + new Long(y).hashCode();\n\t\t\t}\n\n\t\t}\n\t\t\n\t\t\n\t\tstatic class triplet implements Comparable<triplet>\n\t\t{\n\t\t\tInteger x,y;\n\t\t\tLong z;\n\t\t\ttriplet(Integer l,Integer m,long z)\n\t\t\t{\n\t\t\t\tthis.x = l;\n\t\t\t\tthis.y = m;\n\t\t\t\tthis.z = z;\n\t\t\t}\n\t\t\t\n\t\t\tpublic  int compareTo(triplet o)\n\t\t\t{\n\t\t\t\tint result = x.compareTo(o.x);\n\t\t\t\tif(result==0)\n\t\t\t\t\tresult =  y.compareTo(o.y);\n\t\t\t\tif(result==0)\n\t\t\t\t\tresult = z.compareTo(o.z);\n \n\t\t\t\treturn result;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean equlas(Object o)\n\t\t\t{\n\t\t\t\tif(o instanceof triplet)\n\t\t\t\t{\n\t\t\t\t\ttriplet p = (triplet)o;\n\t\t\t\t\treturn x==p.x && y==p.y && z==p.z;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\treturn x+\" \"+y+\" \"+z;\n\t\t\t}\n\t\t\tpublic int hashCode()\n\t\t\t{\n\t\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode() + new Long(z).hashCode(); \n\t\t\t}\n\t\t}\n\t\t\n\t\tstatic class spair implements Comparable<spair>\n\n\t\t{\n\t\t\tString x;\n\t\t\tInteger y;\n\n\t\t\tspair(String x, int y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t\tpublic int compareTo(spair o) {\n\t\t\t\t\n\t\t\t\tString s1 = x + o.x;\n\t\t\t\tString s2 = o.x + x;\n\t\t\t\tlong p1 = cnt[y][0] + cnt[o.y][0];\n\t\t\t\tlong p2 = p1;\n\t\t\t\t\n\t\t\t\tp1 += cnt[y][1] * cnt[o.y][2];\n\t\t\t\tp2 += cnt[o.y][1] * cnt[y][2];\n\t\t\t\t\n\t\t\t\tif(p1==p2)\n\t\t\t\t\t\treturn 0;\n\t\t\t\tif(p1>p2)\n\t\t\t\t\treturn -1;\n\t\t\t\t\n\t\t\t\treturn 1;\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t}\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn x + \" \" + y;\n\t\t\t}\n\n\t\t\t/*public boolean equals(Object o) {\n\t\t\t\tif (o instanceof pair) {\n\t\t\t\t\tpair p = (pair) o;\n\t\t\t\t\treturn p.x == x && p.y == y;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tpublic int hashCode() {\n\t\t\t\treturn new Long(x).hashCode() * 31 + new Long(y).hashCode();\n\t\t\t}\n\t\t\t\n\n\t\t}\n\n\t\t\n\t\t\n\t\t\n\t\n\t\t/*static class node implements Comparable<node>\n \n\t\t{\n\t\t\tInteger x, y, z;\n\t\t\tnode(int x,int y, int z)\n\t\t\t{\n\t\t\t\tthis.x=x;\n\t\t\t\tthis.y=y;\n\t\t\t\tthis.z=z;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int compareTo(pair o) {\n\t\t\t\tint result = x.compareTo(o.x);\n\t\t\t\tif(result==0)\n\t\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\tif(result==0)\n\t\t\t\t\tresult = z.compareTo(z); \n\t\t\t\treturn result;\n\t\t\t}\n \n\t\t\t@Override\n\t\t\tpublic int compareTo(node o) {\n\t\t\t\t// TODO Auto-generated method stub\n\t\t\t\treturn 0;\n\t\t\t}  \n\t\t}\n\t\t*/\n\t}\n\t}\n\t\n\t\t", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.List;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n\t// write your code here\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        String[] s = reader.readLine().split(\" \");\n        int n = Integer.parseInt(s[0]);\n        int d = Integer.parseInt(s[1]);\n\n        List<Integer> list = new ArrayList<>();\n        s = reader.readLine().split(\" \");\n        for (int i = 0; i < n; i++) {\n            list.add(Integer.parseInt(s[i]));\n        }\n\n        HashSet<Integer> set = new HashSet<>();\n        for (Integer i : list) {\n            set.add(i - d);\n            set.add(i + d);\n        }\n\n        HashSet<Integer> set2 = new HashSet<>();\n\n        for (Integer i : set) {\n            for (Integer x : list) {\n                if (Math.abs(i - x) < d) {\n                    set2.add(i);\n            }\n            }\n        }\n\n        set.removeAll(set2);\n        System.out.println(set.size());\n\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main {\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n        public Scanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public Scanner(FileReader fileReader) {\n            br = new BufferedReader(fileReader);\n        }\n\n        public String next() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        public String nextLine() throws IOException {\n            return br.readLine();\n        }\n\n        public boolean ready() throws IOException {\n            return br.ready();\n        }\n    }\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);PrintWriter pw = new PrintWriter(System.out);\n        int n=sc.nextInt(),d=sc.nextInt();int[] a = new int[n];int ans=2;a[0]=sc.nextInt();\n        for (int i=1;i<n;i++){\n            a[i]=sc.nextInt();\n            if (a[i]-a[i-1]==2*d)ans++;\n            else if (a[i]-a[i-1]>2*d)ans+=2;\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "//package round495;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.Set;\n\npublic class A {\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\tint[] a = na(n);\n\t\tSet<Long> set = new HashSet<>();\n\t\tfor(int v : a){\n\t\t\tset.add(v-(long)d);\n\t\t\tset.add(v+(long)d);\n\t\t}\n\t\tint ct = 0;\n\t\tfor(long s : set){\n\t\t\tlong min = Long.MAX_VALUE;\n\t\t\tfor(int v : a){\n\t\t\t\tmin = Math.min(min, Math.abs(s-v));\n\t\t\t}\n\t\t\tif(min == d)ct++;\n\t\t}\n\t\tout.println(ct);\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 A().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", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "/*\n * \n * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)\n * Dhirubhai Ambani Institute of Information And Communication Technology \n * \n */\n\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\npublic class Code1\n{\n\t\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\t\n\t\tint n = in.nextInt();\n\t\tlong d = in.nextLong();\n\t\tlong[]a = new long[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i] = in.nextLong();\n\t\tint ans = 1;\n\t\tfor(int i=0;i<n-1;i++)\n\t\t{\n\t\t\tlong x = a[i+1]-a[i];\n\t\t\tif(x==2*d)\n\t\t\t\tans++;\n\t\t\telse if(x>2*d)\n\t\t\t\tans+=2;\n\t\t\t//System.out.println(ans);\n\t\t}\n\t\tans++;\n\t\tpw.print(ans);\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic class InputReader \n\t{\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{\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() \n\t\t{\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) \n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() \n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t    {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong()\n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nextIntArray(int n) \n\t\t{\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String readString()\n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() \n\t\t{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) \n\t\t{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter\n\t    {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\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<n;i++)\n\t\t{\n\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\tint temp = a[ind];\n\t\t\ta[ind] = a[i];\n\t\t\ta[i] = temp;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\tpublic static void swap(int a, int b){\n\t\tint temp = a;\n\t\ta = b;\n\t\tb = temp;\n\t}\n\t\n\tpublic static HashSet<Integer> primeFactorization(int n)\n\t{\n\t\tHashSet<Integer> a =new HashSet<Integer>();\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<n;i++)\n\t\t\tisPrime[i] = true;\n\t\t\n\t\tisPrime[0] = false;\n\t\tisPrime[1] = false;\n\t\t\n\t\tfor(int i=2;i*i<n;i++)\n\t\t{\n\t\t\tif(isPrime[i] == true)\n\t\t\t{\n\t\t\t\tfor(int j=(2*i);j<n;j+=i)\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t}\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\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 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<pair>\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}", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _1004_A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint N = readInt(), D = readInt(); long arr[] = new long[N+2]; arr[0] = -3000000000L; arr[N+1] = -arr[0];\n\t\tfor(int i = 1; i<=N; i++) arr[i] = readInt();\n\t\tint cnt = 1; if(Math.abs(arr[2]-(arr[1] + D)) >= D) cnt++; for(int i = 2; i<=N; i++) {\n\t\t\tif(Math.abs(arr[i-1]-(arr[i] - D)) > D) cnt++;\n\t\t\tif(Math.abs(arr[i+1]-(arr[i] + D)) >= D) cnt++;\n\t\t}\n\t\tprintln(cnt); exit();\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", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    long b = 31;\n    String fileName = \"\";\n\n\n    //////////////////////    SOLUTION   SOLUTION  SOLUTION    //////////////////////////////\n    int INF = Integer.MAX_VALUE / 10;\n    long MODULO = 1000*1000*100;\n    void solve() throws IOException {\n        int n = readInt();\n        int d = readInt();\n        int[] arr = readIntArray(n);\n        Arrays.sort(arr);\n        int ans = 2;\n        for (int i=0; i < n - 1; ++i){\n            int cur = arr[i] + d;\n            if (arr[i+1] - d == cur) ans++;\n            if (arr[i+1] - d > cur) ans +=2;\n        }\n        out.println(ans);\n    }\n\n    class Number implements Comparable<Number>{\n        int x, cost;\n        Number(int x, int cost){\n            this.x = x;\n            this.cost = cost;\n        }\n\n        @Override\n        public int compareTo(Number o) {\n            return Integer.compare(this.cost, o.cost);\n        }\n    }\n    class Point{\n        int x, y;\n        Point(int x, int y){\n            this.x = x;\n            this.y = y;\n        }\n    }\n\n    class Vertex implements Comparable<Vertex>{\n        int num, depth, e, c;\n        Vertex(int num, int depth, int e, int c){\n            this.num = num;\n            this.e = e;\n            this.depth = depth;\n            this.c = c;\n        }\n\n        @Override\n        public int compareTo(Vertex o) {\n            return Integer.compare(this.e, o.e);\n        }\n    }\n    ///////////////////////////////////////////////////////////////////////////////////////////\n\n    class Edge{\n        int from, to, num;\n        Edge(int to, int num){\n            this.to = to;\n            this.num = num;\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<n; ++i){\n                rmq[0][i] = a[i];\n            }\n\n            for(int k=1; (1 << k) < n; ++k){\n                for(int i=0; i + (1 << k) <= n; ++i){\n                    int max1 = rmq[k - 1][i];\n                    int max2 = rmq[k-1][i + (1 << (k-1))];\n                    rmq[k][i] = Math.max(max1, max2);\n                }\n            }\n        }\n\n        int max(int l, int r){\n            int k = logTable[r - l];\n            int max1 = rmq[k][l];\n            int max2 = rmq[k][r - (1 << k) + 1];\n            return Math.max(max1, max2);\n        }\n    }\n    long checkBit(long mask, int bit){\n        return (mask >> 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<n; ++i){\n                parent[i] = i;\n            }\n        }\n        int findSet(int a){\n            if(parent[a] == a) return a;\n            parent[a] = findSet(parent[a]);\n            return parent[a];\n        }\n        void unionSets(int a, int b){\n            a = findSet(a);\n            b = findSet(b);\n            if(a!=b){\n                countSets--;\n                parent[a] = b;\n            }\n        }\n    }\n    static int checkBit(int mask, int bit) {\n        return (mask >> 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] = Math.max(delta, t[ind]);\n            }\n        }\n\n        long getMax(int r) {\n            long sum = 0;\n            for (; r >= 0; r = (r & (r + 1)) - 1) {\n                sum = Math.max(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    long gcd(long a, long b){\n        return b == 0 ? a : gcd(b, a%b);\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 Main().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    Main() 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<n; ++i){\n            a[i] = readInt();\n        }\n        return a;\n    }\n\n    Integer[] readIntegerArray (int n) throws NumberFormatException, IOException {\n        Integer[] a = new Integer[n];\n        for(int i=0; i<n; ++i){\n            a[i] = readInt();\n        }\n        return a;\n    }\n\n    long readLong() throws NumberFormatException, IOException {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "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.FileNotFoundException;\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 Asgar Javadov\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        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            int d = in.nextInt();\n            int[] a = in.readIntArray(n);\n\n            int ans = 1;\n            for (int i = 0; i < a.length - 1; ++i) {\n                int left = a[i] + d;\n                int right = a[i + 1] - d;\n                if (left < right) {\n                    ans += 2;\n                } else if (left == right)\n                    ans++;\n            }\n\n            out.println(ans + 1);\n        }\n\n    }\n\n    static class OutputWriter extends PrintWriter {\n        public OutputWriter(OutputStream outputStream) {\n            super(outputStream);\n        }\n\n        public OutputWriter(Writer writer) {\n            super(writer);\n        }\n\n        public OutputWriter(String filename) throws FileNotFoundException {\n            super(filename);\n        }\n\n        public void close() {\n            super.close();\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        public int[] readIntArray(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    }\n}\n\n", "complexity": "linear", "problem": "1004_A. Sonya and Hotels", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A\n{\n    public static void main(String args[])\n    {\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();   \n        \n        int odd = -1;\n        int even = -1;\n        int oc = 0;\n        int ec = 0;\n        \n        for(int i=0;i < n;i++)\n        {\n            if(scan.nextInt() % 2 == 0)\n            {\n                ec++;\n                even = i+1;\n            }\n            else\n            {\n                oc++;\n                odd = i+1;\n            }\n        }\n        \n        if(ec == 1)\n            System.out.println(even);\n        else\n            System.out.println(odd);\n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tList<Integer> list = new ArrayList<Integer>(), list2;\n\t\tfor (; n-- > 0;) {\n\t\t\tlist.add(scan.nextInt());\n\t\t}\n\t\tlist2 = new ArrayList<Integer>(list);\n\t\tCollections.sort(list2, new Comparator<Integer>() {\n\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\treturn o1 % 2 - o2 % 2;\n\t\t\t}\n\t\t});\n\t\tSystem.out.println(list.indexOf(list2.get(list2.get(1) % 2 > 0 ? 0\n\t\t\t\t: list2.size() - 1)) + 1);\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class A25 {\n\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tint n = Integer.parseInt(in.readLine().trim());\n\t\t\tString[] toks = in.readLine().trim().split(\"[ ]+\");\n\t\t\tint counter = 0;\n\t\t\tboolean even = true;\n\t\t\tint e = -1, o = -1;\n\t\t\tint ec = 0, oc = 0;\n\t\t\tfor (int i = 0; i < toks.length; i++) {\n\t\t\t\tint x = Integer.parseInt(toks[i]);\n\t\t\t\tif (x % 2 == 0) {\n\t\t\t\t\tec ++;\n\t\t\t\t\tif (e == -1) {\n\t\t\t\t\t\te = i+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toc ++;\n\t\t\t\t\tif (o == -1) {\n\t\t\t\t\t\to = i+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ec == 1) {\n\t\t\t\tSystem.out.println(e);\n\t\t\t}\n\t\t\telse if (oc == 1) {\n\t\t\t\tSystem.out.println(o);\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A25().run();\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class R025A {\n\tint n;\n\tint[] nums;\n\tpublic R025A() {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tn = scanner.nextInt();\n\t\tnums = new int[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tnums[i] = scanner.nextInt();\n\t\t}\n\t}\n\n\tprivate void process() {\n\t\tint[] c = new int[2];\n\t\tint[] r = new int[2];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tc[nums[i] % 2]++;\n\t\t\tif(r[nums[i] %2] == 0) {\n\t\t\t\tr[nums[i] % 2] = i+1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(r[c[0]==1 ? 0 : 1]);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew R025A().process();\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "//package;\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Vector;\nimport java.lang.*;\nimport java.io.*;\nimport java.awt.Point;\n\npublic class evenness {\n\t\n\tpublic static void main(String[] args){\n\t\n    try{\n\t\n      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n      int i, n, temp=1;\n      String str = \"\";\n      int[] arr;\n      int r;\n      \n      while (temp!= '\\n'){\n\t\ttemp = System.in.read();\n\t\t//if (temp=='\\n')\n\t\t\t//break;\n\t\tstr = str.concat(Character.toString((char)temp));\n      }\n\t  str = str.replaceAll(\"[^0-9]\", \"\");\n      n = Integer.parseInt(str);\n      temp=1;\n      str=\"\";\n      \n      arr = new int[n];\n      \n      for (i=0;i<n;i++){\n\t\twhile (temp!=' ' && temp!=-1){\n\t\t\ttemp = System.in.read();\n\t\t\t//if (temp==' ' || temp==-1)\n\t\t\t\t//break;\n\t\t\tstr = str.concat(Character.toString((char)temp));\n\t\t}\n\t\tstr = str.replaceAll(\"[^0-9]\", \"\");\n\t\tarr[i] = Integer.parseInt(str);\n\t\tstr=\"\";\n\t\ttemp=1;\n      }\n      \n\t  r=(arr[2]%2);\n      if ((arr[0]%2)==(arr[1]%2)){\n\t\tr=(arr[0]%2);\n      }\n      \n      for (i=0;i<n;i++){\n\t\tif ((arr[i]%2)!=r){\n\t\t\tSystem.out.println(i+1);\n\t\t\tbreak;\n\t\t}\n      }\n      \n\t}catch (Exception e){\n\t\tSystem.out.println(\"OH NOES \" + e);\n\t}\n  }\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class a implements Runnable {\n\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint oddcnt = 0, evencnt = 0;\n\t\tint odd = 0, even = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = nextInt();\n\t\t\tif (a % 2 == 0) {\n\t\t\t\teven = i + 1;\n\t\t\t\tevencnt++;\n\t\t\t} else {\n\t\t\t\todd = i + 1;\n\t\t\t\toddcnt++;\n\t\t\t}\n\t\t}\n\t\tif (oddcnt == 1) {\n\t\t\tSystem.out.println(odd);\n\t\t} else {\n\t\t\tSystem.out.println(even);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new a()).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}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class IQTest\n{\n    public static void main(String[] args)\n    {\n        try\n        {\n            BufferedReader in = new BufferedReader(\n                new InputStreamReader(System.in));\n            String str = in.readLine();\n            int n = Integer.parseInt(str);\n            int odd = -1, even = -1, odds = 0, evens = 0;\n            //while (n-- > 0)\n            //{\n                str = in.readLine();\n                String[] numbers = str.split(\" \");\n                int index = 1;\n                for (String number: numbers)\n                {\n                    int i = Integer.parseInt(number);\n                    if (i % 2 == 0)\n                    {\n                        ++evens;\n                        if (even == -1)\n                            even = index;\n                    }\n                    else\n                    {\n                        ++odds;\n                        if (odd == -1)\n                            odd = index;\n                    }\n                    ++index;\n                }\n            //}\n            \n            System.out.println((evens > odds ? odd : even));\n        }\n        catch (Exception e)\n        {\n            e.printStackTrace();\n        }\n    }\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "//package round25;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n\tprivate String INPUT = \"\";\n\t\n\tpublic void solve()\n\t{\n\t\tint n = ni();\n\t\tint[] u = new int[n];\n\t\tint fe = -1, fo = -1;\n\t\tint ne = -1, no = -1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tu[i] = ni();\n\t\t\tif(u[i] % 2 == 0){\n\t\t\t\tif(fe == -1){\n\t\t\t\t\tfe = i + 1;\n\t\t\t\t}else{\n\t\t\t\t\tne = i + 1;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(fo == -1){\n\t\t\t\t\tfo = i + 1;\n\t\t\t\t}else{\n\t\t\t\t\tno = i + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(ne > 0){\n\t\t\tout.println(fo);\n\t\t}else{\n\t\t\tout.println(fe);\n\t\t}\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\t\t\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew A().run();\n\t}\n\t\n\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class A {\n    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        br.readLine();\n        String[] ss = br.readLine().split(\" \");\n        int n = ss.length;\n        int[] a = new int[n];\n        for (int i = 0; i < n; ++i)\n            a[i] = Integer.parseInt(ss[i]);\n        for (int i = 0; i < n; ++i) {\n            boolean ok = true;\n            for (int j = 0; j < n; ++j)\n                if (j != i && a[j] % 2 == a[i] % 2)\n                    ok = false;\n            if (ok)\n                System.out.println(i + 1);\n        }\n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Main {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[] nums = new int[n];\n        int kisu = 0;\n        int gusu = 0;\n        for(int i = 0 ; i < n ; i++){\n            nums[i] = sc.nextInt();\n            if(nums[i] % 2 == 0)gusu++;\n            if(nums[i] % 2 == 1)kisu++;\n        }\n        int ans = -1;\n        if(gusu == 1){\n            for(int i = 0 ; i < n ; i++){\n                if(nums[i]%2 == 0){\n                    ans = i+1;\n                    break;\n                }\n            }\n        }\n        else{\n            for(int i = 0 ; i < n ; i++){\n                if(nums[i]%2 == 1){\n                    ans = i+1;\n                    break;\n                }\n            }\n            \n        }\n        System.out.println(ans);\n    }\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    int n;\n    int[] arr;\n    \n    void run(){\n        Scanner s = new Scanner(System.in);\n        n = s.nextInt();\n        arr = new int[n];\n        int even, odd;\n        even = 0;\n        odd = 0;\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextInt();\n            if(arr[i]%2==0)even++;\n            else odd++;\n        }\n        if(even>odd){\n        \n            \n            for (int i = 0; i < n; i++) {\n                if(arr[i]%2==1){\n                    System.out.println(i+1);\n                    System.exit(0);\n                }\n            }\n        }\n        \n        else{\n\n            for (int i = 0; i < n; i++) {\n                if(arr[i]%2==0){\n                    System.out.println(i+1);\n                    System.exit(0);\n                }\n            }\n\n        }\n        \n        \n    }\n    public static void main(String[] args) {\n        new A().run();\n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\n\npublic class ProblemA {\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter writer = new PrintWriter(System.out);\n\t\tint n = Integer.parseInt(reader.readLine());\n\t\tString [] split = reader.readLine().split(\"\\\\s+\");\n\t\tint value;\n\t\tint [] count = new int[2];\n\t\tint [] pos = new int[2];\n\t\tfor(int i = 0; i < split.length; i++){\n\t\t\tvalue = Integer.parseInt(split[i]);\n\t\t\tcount[value % 2] ++;\n\t\t\tpos[value % 2] = i + 1;\n\t\t}\n\t\twriter.println((count[0] == 1) ? pos[0] : pos[1]);\n\t\twriter.flush();\n\t\twriter.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Long.*;\nimport static java.util.Arrays.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        while (s.hasNext()) {\n            int n = s.nextInt();\n            int[] a = new int[n];\n            int odd = 0;\n            int even = 0;\n            int po = -1;\n            int ev = -1;\n            for(int i=0;i<n;i++){\n                a[i] = s.nextInt();\n                if(a[i] % 2 == 0) {\n                    even ++;\n                    ev = i + 1;\n                } else {\n                    odd++;\n                    po = i + 1;\n                }\n            }\n            if(odd == 1) {\n                System.out.println(po);\n            }else{\n                System.out.println(ev);\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\n\npublic class Main {\nprivate static StreamTokenizer in;\nprivate static PrintWriter out;\nprivate static int nextInt() throws Exception {\nin.nextToken();\nreturn (int)in.nval;\n}\nprivate static String nextString() throws Exception {\nin.nextToken();\nreturn in.sval;\n}\n\npublic static void main(String[] args) throws Exception {\nin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\nout = new PrintWriter(System.out);\nint n = nextInt();\nbyte f = (byte)nextInt();\nbyte s = (byte)nextInt();\nbyte t = (byte)nextInt();\nboolean bf = false;\nboolean bs = false;\nboolean bt = false;\nif((f&1) == 0){bf = true;}\nif((s&1) == 0){bs = true;}\nif((t&1) == 0){bt = true;}\n//System.out.println(bf+\"\"+bs+\"\"+bt);\nif((!bf)&&bs&&bt){System.out.println(1);return;}\nif(bf&&(!bs)&&bt){System.out.println(2);return;}\nif(bf&&bs&&(!bt)){System.out.println(3);return;}\nif(bf&&!bs&&!bt){System.out.println(1);return;}\nif(!bf&&bs&&!bt){System.out.println(2);return;}\nif(!bf&&!bs&&bt){System.out.println(3);return;}\nfor(int i = 4; i<=n; i++){\nbyte g = (byte) nextInt();\nif(((g+f)&1) == 1){System.out.println(i); return;}\n}\n\n\n\nout.flush();\n}\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.List;\nimport java.util.Queue;\nimport java.awt.*;\nimport static java.util.Arrays.fill;\n\npublic class Solution 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 Solution()).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    String nextLine() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n        }\n        return null;\n    }\n\n    private void solver() {\n        int n = ni();\n        ArrayList<Integer> ar = new ArrayList<Integer>();\n        int sum = 0;\n        for (int i = 0; i < n; i++) {\n            ar.add(ni() % 2);\n            sum += ar.get(i);\n        }\n        int flag = 0;\n        if(sum==1)flag = 1;\n            for(int i =0;i<n;i++)if(ar.get(i)==flag)System.out.println(i+1);\n        \n\n    }\n\n    void exit() {\n        System.exit(0);\n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class Main {\n\tpublic static void main (String [] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader (new InputStreamReader (System.in));\n\t\tdo {\n\t\t\tint n = Integer.parseInt (br.readLine ());\n\t\t\t//args;\n\t\t\tint [] ns = new int [(args = br.readLine ().split (\" \")).length];\n\t\t\tint evenCount = 0, oddCount = 0, evI = 1, oddI = 1;\n\t\t\tfor (int i = 0; i < ns.length; i++) {\n\t\t\t\tif ((ns [i] = Integer.parseInt (args [i])) % 2 == 0) {\n\t\t\t\t\tevenCount ++;\n\t\t\t\t\tevI = i;\n\t\t\t\t\t\n\t\t\t\t} else {\n\t\t\t\t\toddCount ++;\n\t\t\t\t\toddI = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (evenCount == 1) System.out.println (evI + 1);\n\t\t\telse System.out.println (oddI + 1);\n\t\t} while (br.ready ());\n\t}\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Saransh\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.lang.*;\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        try\n        {\n            Parserdoubt pd=new Parserdoubt(System.in);\n            int t=pd.nextInt();\n            int inde=0,indo=0,o=0,e=0;\n            for(int i=0;i<t;i++)\n            {\n                if(pd.nextInt()%2==0)\n                {\n                    inde=i;\n                    e++;\n                }\n                else\n                {\n                    o++;\n                    indo=i;\n                }\n            }\n            if(o==1)\n            {\n                System.out.println(indo+1);\n            }\n            else\n            {\n                System.out.println(inde+1);\n            }\n        }\n        catch(Exception e){}\n    }\n\n}\n\nclass Parserdoubt\n\t{\n\t   final private int BUFFER_SIZE = 1 << 17;\n\n\t   private DataInputStream din;\n\t   private byte[] buffer;\n\t   private int bufferPointer, bytesRead;\n\n\t   public Parserdoubt(InputStream in)\n\t   {\n\t      din = new DataInputStream(in);\n\t      buffer = new byte[BUFFER_SIZE];\n\t      bufferPointer = bytesRead = 0;\n\t   }\n\t   public String nextString() throws Exception\n\t   {\n\t\t   StringBuffer sb=new StringBuffer(\"\");\n\t\t   byte c = read();\n\t\t   while (c <= ' ') c = read();\n\t\t   do\n\t\t   {\n\t\t\t   sb.append((char)c);\n\t\t\t   c=read();\n\t\t   }while(c>' ');\n\t\t   return sb.toString();\n\t   }\n\t   public char nextChar() throws Exception\n\t   {\n\t\t   byte c=read();\n\t\t   while(c<=' ') c= read();\n\t\t   return (char)c;\n\t   }\n\t   public int nextInt() throws Exception\n\t   {\n\t      int ret = 0;\n\t      byte c = read();\n\t      while (c <= ' ') c = read();\n\t      boolean neg = c == '-';\n\t      if (neg) c = read();\n\t      do\n\t      {\n\t    \t  ret = ret * 10 + c - '0';\n\t         c = read();\n\t      } while (c > ' ');\n\t      if (neg) return -ret;\n\t      return ret;\n\t   }\n\t   public long nextLong() throws Exception\n\t   {\n\t      long ret = 0;\n\t      byte c = read();\n\t      while (c <= ' ') c = read();\n\t      boolean neg = c == '-';\n\t      if (neg) c = read();\n\t      do\n\t      {\n\t    \t  ret = ret * 10 + c - '0';\n\t         c = read();\n\t      } while (c > ' ');\n\t      if (neg) return -ret;\n\t      return ret;\n\t   }\n\t   private void fillBuffer() throws Exception\n\t   {\n\t      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t      if (bytesRead == -1) buffer[0] = -1;\n\t   }\n\n\t   private byte read() throws Exception\n\t   {\n\t      if (bufferPointer == bytesRead) fillBuffer();\n\t      return buffer[bufferPointer++];\n\t   }\n\t}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n  public static void main(String[] args){\n\t  Scanner in = new Scanner(System.in);\n\t  int n = in.nextInt();\n\t  int a[] = new int[100];\n\t  for (int i = 0;i<n;i++) a[i] = in.nextInt()%2;\n\t  if (a[0]==a[1] || a[0]==a[2]){\n\t\t  for (int i = 1;i<n;i++)\n\t\t\t  if (a[i] != a[0]) {\n\t\t\t\t  System.out.println(i+1);\n\t\t\t\t  break;\n\t\t\t  }\n\t  } else{\n\t\t  System.out.println(1);\n\t  }\n  }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tint n = nextInt();\n\t\tint even = 0, odd = 0, atEven = -1, atOdd = -1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (nextInt() % 2 == 0) {\n\t\t\t\tatEven = i;\n\t\t\t\t++even;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tatOdd = i;\n\t\t\t\t++odd;\n\t\t\t}\n\t\t}\n\t\tif (odd == 1)\n\t\t\tout.print(atOdd + 1);\n\t\telse\n\t\t\tout.print(atEven + 1);\n\t}\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\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", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\n\n\npublic class IQTest {\n\tpublic static void main(String args[]) throws Exception {\n\t\tBufferedReader stdin =\n\t\t\tnew BufferedReader(new InputStreamReader(System.in));\n\t\tString line;\n\t\t\tline = stdin.readLine();\n\t\t\tint n = Integer.parseInt(line);\n\t\t\tline = stdin.readLine();\n\t\t\tList even = new ArrayList();\n\t\t\tList odd = new ArrayList();\n\t\t\tString[] kk = line.split(\" \");\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tif(Integer.parseInt(kk[i])%2==0)\n\t\t\t\t\teven.add(i);\n\t\t\t\telse\n\t\t\t\t\todd.add(i);\n\t\t\t}\n\t\t\tif(even.size()==1)\n\t\t\t\tSystem.out.println((Integer)even.get(0)+1);\n\t\t\telse\n\t\t\t\tSystem.out.println((Integer)odd.get(0)+1);\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\n\npublic class A {\n\tprivate static StreamTokenizer in;\n\tprivate static PrintWriter 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\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tArrayList<Integer> p = new ArrayList<Integer>();\n\t\tArrayList<Integer> o = new ArrayList<Integer>();\n\t\t\n\t\tint n = nextInt();\n\t\tfor (int i=0; i<n; i++) {\n\t\t\tint a = nextInt();\n\t\t\tif (a % 2 == 0) p.add(i+1);\n\t\t\telse o.add(i+1);\n\t\t}\n\t\t\n\t\tif (p.size() < o.size()) out.println(p.get(0));\n\t\telse out.println(o.get(0));\n\n\t\tout.flush();\n\n\t}\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A25 {\n\n\tstatic StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t}\n\t\n\tstatic String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tint n = nextInt();\n\t\tint[] c = new int[2];\n\t\tint[] f = new int[2];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = nextInt(), p = x%2;\n\t\t\tif (c[p]++ == 0) f[p] = i+1;\n\t\t}\n\t\tout.println(c[0] == 1 ? f[0] : f[1]);\n\t\t\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Task25a {\n\n\t/**\n\t * @param args\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 a1 = 0, a2 = 0;\n\t\tint n1 = 0, n2 = 0;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tint c = sc.nextInt();\n\t\t\tif (c % 2 == 1) {\n\t\t\t\ta1 = i;\n\t\t\t\tn1++;\n\t\t\t} else {\n\t\t\t\ta2 = i;\n\t\t\t\tn2++;\n\t\t\t}\n\t\t}\n\t\tif (n1 == 1) {\n\t\t\tSystem.out.println(a1);\n\t\t} else {\n\t\t\tSystem.out.println(a2);\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class IQTest implements Runnable\n{\n  public static void main(String[] args) throws Exception\n  {\n    new IQTest().run();\n  }\n\n  private void solve() throws Exception\n  {\n    int n = nextInt();\n    int a[] = new int[n];\n    for (int i = 0; i < a.length; i++)\n    {\n      a[i] = nextInt();\n    }\n\n    int c0 = 0, c1 = 0;\n    for (int i = 0; i < a.length; i++)\n    {\n      a[i] = a[i] % 2;\n      if (a[i] == 0)\n        c0++;\n      else\n        c1++;\n    }\n\n    int f = 0;\n    if (c0 > c1)\n      f = 1;\n    else\n      f = 0;\n\n    int r = 0;\n    for (int i = 0; i < a.length; i++)\n    {\n      if (a[i] == f)\n      {\n        r = i + 1;\n        break;\n      }\n    }\n    out.println(r);\n  }\n\n  // -------------- Input/Output routines below ---------------//\n  private BufferedReader in;\n  PrintWriter out;\n  StringTokenizer tokenizer;\n\n  public void run()\n  {\n    // String problem = this.getClass().getName();\n    try\n    {\n      in = new BufferedReader(new InputStreamReader(System.in));\n      out = new PrintWriter(new BufferedOutputStream(System.out));\n      solve();\n      out.flush();\n      in.close();\n      out.close();\n    }\n    catch (Exception e)\n    {\n      e.printStackTrace();\n      // System.exit(1);\n    }\n  }\n\n  String nextToken() throws IOException\n  {\n    while (tokenizer == null || !tokenizer.hasMoreTokens())\n    {\n      tokenizer = new StringTokenizer(in.readLine());\n    }\n    return tokenizer.nextToken();\n  }\n\n  int nextInt() throws IOException\n  {\n    return Integer.parseInt(nextToken());\n  }\n\n  long nextLong() throws IOException\n  {\n    return Long.parseLong(nextToken());\n  }\n\n  double nextDouble() throws IOException\n  {\n    return Double.parseDouble(nextToken());\n  }\n\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\n\npublic class R025A {\n\tint n;\n\tint[] nums;\n\tpublic R025A() {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tn = scanner.nextInt();\n\t\tnums = new int[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tnums[i] = scanner.nextInt();\n\t\t}\n\t}\n\n\tprivate void process() {\n\t\tint odd = 0;\n\t\tint even = 0;\n\t\tint lastOdd = 0;\n\t\tint lastEven = 0;\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tif(nums[i] % 2 == 0) {\n\t\t\t\teven++;\n\t\t\t\tlastEven = i+1;\n\t\t\t} else {\n\t\t\t\todd++;\n\t\t\t\tlastOdd = i+ 1;\n\t\t\t}\n\t\t}\n\t\tif(odd == 1) System.out.println(lastOdd);\n\t\telse System.out.println(lastEven);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew R025A().process();\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Locale;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tString[] number = new String[n];\n\t\tsc.nextLine();\n\t\tString l = sc.nextLine();\n\t\tnumber = l.split(\" \");\n\t\tint oe = 1;\n\t\tif((Integer.valueOf(number[0])%2 +\n\t\t   Integer.valueOf(number[1])%2 +\n\t\t   Integer.valueOf(number[2])%2) > 1) {\n\t\t\toe = 0;\n\t\t}\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif((Integer.valueOf(number[i])%2)==oe) {\n\t\t\t\tSystem.out.println(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "//package codeforces.br25;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class ProblemA {\n    public void solve() {\n        boolean oj = true;\n\n        try {\n            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"A.in\");\n            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"A.out\");\n            BufferedReader br = new BufferedReader(reader);\n            StreamTokenizer st = new StreamTokenizer(reader);\n            PrintWriter out = new PrintWriter(writer);\n\n            int n = Integer.valueOf(br.readLine());\n            String s = br.readLine();\n            MyTokenizer tok = new MyTokenizer(s);\n            int[] a = new int[2];\n            int[] ind = new int[2];\n            int[] c = new int[2];\n\n            for(int i=0;i<n;i++) {\n                int p = (int)tok.getNum();\n                c[p%2]++;\n                a[p%2] = p;\n                ind[p%2] = i;\n            }\n            int b = ind[0];\n            if (c[0] > c[1])\n                b = ind[1];\n            out.printf(\"%d\", b + 1);\n\n            br.close();\n            out.close();\n            reader.close();\n            writer.close();\n        }\n        catch (Exception ex) {\n            ex.printStackTrace();\n        }\n        finally {\n        }\n    }\n\n\n    public static void main(String[] args) {\n        ProblemA f = new ProblemA();\n        f.solve();\n    }\n\n    private class MyTokenizer {\n        private String s;\n        private int cur;\n\n        public MyTokenizer(String s) {\n            this.s = s;\n            cur = 0;\n        }\n\n        public void skip() {\n            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\\n')) {\n                cur++;\n            }\n        }\n\n        public double getNum() {\n            skip();\n            String snum = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {\n                snum += s.charAt(cur);\n                cur++;\n            }\n            return Double.valueOf(snum);\n        }\n\n        public String getString() {\n            skip();\n            String s2 = \"\";\n            while (cur < s.length() && (((s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) || ((s.charAt(cur) >= 'A' && s.charAt(cur) <= 'Z')))) {\n                s2 += s.charAt(cur);\n                cur++;\n            }\n            return s2;\n        }\n\n        public char getCurrentChar() throws Exception {\n            if (cur < s.length())\n                return s.charAt(cur);\n            else\n                throw new Exception(\"Current character out of string length\");\n        }\n\n        public void moveNextChar() {\n            if (cur < s.length())\n                cur++;\n        }\n\n        public boolean isFinished() {\n            return cur >= s.length();\n        }\n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\t\n\tint n;\n\t\n\tvoid run()throws IOException{\n\t\tScanner sc = new Scanner(new InputStreamReader(System.in));\t\t\n\t\tn = sc.nextInt();\n\t\tint i,tmp,even,odd,e,o;\n\t\teven=odd=e=o=0;\n\t\tfor(i=1;i<=n;i++){\n\t\t\ttmp = sc.nextInt();\n\t\t\tif(tmp%2==0){\n\t\t\t\te++;\n\t\t\t\tif(even==0) even=i;\n\t\t\t} else{\n\t\t\t\to++;\n\t\t\t\tif(odd==0) odd=i;\n\t\t\t}\n\t\t}\n\t\tif(e>1) System.out.println(odd);\n\t\telse System.out.println(even);\n\t}\n\t\n\tpublic static void main(String[] args)throws IOException {\n\t\tnew A().run();\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "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\tString file = \"input\";\n\t\n\tvoid init() throws IOException\n\t{\n\t\t//input = new BufferedReader(new FileReader(file + \".in\"));\n\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t}\n\t\n\tvoid solve() throws IOException\n\t{\n\t\tint odd = 0, even = 0;\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0; i < n; i++) \n\t\t{\n\t\t\ta[i] = nextInt();\n\t\t\tif(a[i] % 2 == 0) even++;\n\t\t\telse odd++;\n\t\t}\n\t\tif(even >= 2)\n\t\t{\n\t\t\tfor(int i = 0; i < n; i++) if(a[i] % 2 == 1)\n\t\t\t{\n\t\t\t\tSystem.out.println(i + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor(int i = 0; i < n; i++) if(a[i] % 2 == 0)\n\t\t\t{\n\t\t\t\tSystem.out.println(i + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tString next() throws IOException\n\t{\n\t\twhile(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tlong nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tdouble nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tvoid print(Object... o)\n\t{\n\t\tSystem.out.println(deepToString(o));\n\t}\n\t\n\tvoid gcj(Object o)\n\t{\n\t\tString s = String.valueOf(o);\n\t\tout.println(\"Case #\" + test + \": \" + s);\n\t\tSystem.out.println(\"Case #\" + test + \": \" + s);\n\t}\n\t\n\tBufferedReader input;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tint test;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tnew Thread(null, new A(), \"\", 1 << 20).start();\n\t}\n\t\n\tpublic void run()\n\t{\n\t\ttry\n\t\t{\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\t\t\n\t\t}\n\t\tcatch(Exception e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Main \n{\n    public static void main(String []args)throws Exception\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        int n=0;\n        n=Integer.parseInt(br.readLine());\n        String inp=\"\";\n        inp=br.readLine();\n        int no[]=new int[n];\n        String tinp[]=inp.split(\" \");\n        for(int i=0;i<n;i++)\n        {\n            no[i]=Integer.parseInt(tinp[i]);\n        }\n        int eve=0,odd=0;\n        for(int i=0;i<3;i++)\n        {\n            int rem=no[i]%2;\n            if(rem==0)\n                eve++;\n            else\n                odd++;\n        }\n               if(eve>1)\n               {\n                   for(int i=0;i<n;i++)\n                   {\n                       if(no[i]%2==1)\n                       {\n                           System.out.println(i+1);\n                           break;\n                       }\n                   }\n               }\n               else\n               {\n                     for(int i=0;i<n;i++)\n                      {\n                          if(no[i]%2==0)\n                          {\n                           System.out.println(i+1);\n                           break;\n                          }\n                      }\n            \n               }\n                \n\n}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Solution {\n\n    public static void main(String args[]) {\n    Scanner scanner = new Scanner(System.in);\n    int n = scanner.nextInt();\n    int[] arr = new int[n];\n    for (int i = 0; i < n; ++i) {\n        arr[i] = scanner.nextInt();\n    }\n    boolean isOdd = false;\n    if ((arr[0] % 2 == 0 && arr[1] % 2 == 0) || (arr[0] % 2 == 0 && arr[2] % 2 == 0)\n        || (arr[1] % 2 == 0 && arr[2] % 2 == 0)) {\n        isOdd = true;\n    }\n    if (isOdd) {\n        for (int i = 0; i < n; ++i) {\n        if (arr[i] % 2 == 1) {\n            System.out.println(i + 1);\n            break;\n        }\n        }\n    } else {\n        for (int i = 0; i < n; ++i) {\n        if (arr[i] % 2 == 0) {\n            System.out.println(i + 1);\n            break;\n        }\n        }\n    }\n\n    }\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class Contest25_A {\n    \n    static int[] parity;\n    \n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        \n        int numberEntries = scan.nextInt();\n        scan.nextLine();\n        String[] numbers = scan.nextLine().split(\" \");\n        numbers = parity(numbers);\n        int evenOdd = evenOdd(parity);\n       \n        for (int i = 0; i < parity.length; i++) {\n            if (parity[i] == evenOdd) {\n                System.out.println(i + 1);\n                System.exit(0);\n            }\n        }\n            \n        \n    }\n\n    public static int evenOdd(int[] parity) {\n        /*\n         * Determines what I should be looking for\n         * Return 0 if even\n         * Return 1 if odd\n         */\n        int numberOnes = 0;\n        int numberZeroes = 0;\n        \n        int one = parity[0];\n        int two = parity[1];\n        int three = parity[2];\n        \n        if (one == 1) \n            numberOnes++;\n        else\n            numberZeroes++;\n        \n        if (two == 1) \n            numberOnes++;\n        else\n            numberZeroes++;\n        \n        if (three == 1) \n            numberOnes++;\n        else\n            numberZeroes++;\n        \n        if (numberOnes >= 2)\n            return 0;\n        else\n            return 1;\n        \n    }\n\n    public static String[] parity(String[] numbers) {\n        parity = new int[numbers.length];\n        for (int i = 0; i < numbers.length; i++) {\n            parity[i] = Integer.parseInt(numbers[i]) % 2;\n            numbers[i] = Integer.toString(parity[i]);\n        }\n        return numbers;\n    }\n    \n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n *\n * @author Ronak\n */\npublic class Main {\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        \n        Scanner in=new Scanner(System.in);\n         int n=in.nextInt();\n         \n        if(n>=3&&n<=100)\n        {\n        int num[]=new int[n];\n        for(int i=0;i<n;i++)\n        {\n            num[i]=in.nextInt();\n        }\n        int even=0,odd=0,ceven=0,codd=0;\n        for(int i=0;i<n;i++)\n        {\n            if(num[i]%2==0)\n            {\n                even++;\n                ceven=i+1;\n                \n            }\n            else\n            {\n                odd++;\n                codd=i+1;\n            }\n        }\n        if(odd==1)\n        {\n            System.out.println(\"\"+codd);\n        }\n        else\n        {\n            System.out.println(\"\"+ceven);\n        }\n        }\n    }\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\t\n\tprivate void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint ce = 0;\n\t\tint co = 0;\n\t\tint le = 0;\n\t\tint lo = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = sc.nextInt();\n\t\t\tif (x % 2 == 0) {\n\t\t\t\tce++;\n\t\t\t\tle = i + 1;\n\t\t\t} else {\n\t\t\t\tco++;\n\t\t\t\tlo = i + 1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ce == 1 ? le : lo);\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        solve();\n\n        in.close();\n        out.close();\n    }\n\n    private static void solve() throws Exception {\n        int n = nextInt();\n        int co = 0, ce = 0;\n        int[] v = new int[n];\n        for (int i = 0; i < n; i++) {\n            v[i] = nextInt();\n        }\n        for (int i = 0; i < n; i++) {\n            if (v[i] % 2 == 0) {\n                co++;\n            } else {\n                ce++;\n            }\n        }\n        if (co == 1) {\n            for (int i = 0; i < n; i++) {\n                if (v[i] % 2 == 0) {\n                    out.println(i + 1);\n                    return;\n                }\n            }\n        } else {\n            for (int i = 0; i < n; i++) {\n                if (v[i] % 2 != 0) {\n                    out.println(i + 1);\n                    return;\n                }\n            }\n        }\n    }\n\n    private static BufferedReader in;\n    private static PrintWriter out;\n    private static StringTokenizer st;\n\n    static String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    static double nextDouble() throws IOException {\n        return Double.parseDouble(nextString());\n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A_IQTest {\n\n    static int n;\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        n = s.nextInt();\n        \n        int[] nums = new int[n];\n        \n        for (int i = 0; i < n; i++) {\n            nums[i] = s.nextInt();\n        }\n        \n        \n        int ei = -1;\n        int oi = -1;\n        int ecnt = 0;\n        int ocnt = 0;\n        for (int i = 0; i < n; i++) {\n            if(nums[i] % 2 == 0){\n                ei = i;\n                ecnt++;\n            }else{\n                oi = i;\n                ocnt++;\n            }\n        }\n        if(ecnt == 1){\n            System.out.println(ei+1);\n        }else{\n            System.out.println(oi+1);\n        }\n    }\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main { \n    public static void main(String[] args) {\n        Main iq = new Main();\n        Scanner sc = new Scanner(System.in);\n        int n;\n        n = sc.nextInt();\n        int[] naturalNumbers = new int[n];\n        for (int i = 0; i < naturalNumbers.length; i++) {\n            naturalNumbers[i] = sc.nextInt();\n        }\n        System.out.println(iq.diffInEvenness(n, naturalNumbers));          \n    }\n    \n    public int diffInEvenness(int n, int[] naturalNumbers) {       \n        int even, odd, lastEvenIndex, lastOddIndex;\n        even = odd = lastEvenIndex = lastOddIndex = 0;\n        for (int i = 0; i < naturalNumbers.length; i++) {\n            if((naturalNumbers[i] % 2) == 0) {\n                even++;\n                lastEvenIndex = i + 1;\n            }\n            else {\n                odd++;\n                lastOddIndex = i + 1;\n            }\n        }\n        return (even > odd ? lastOddIndex : lastEvenIndex);     \n    }\n\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Iq {\n\n    static void metod() throws Exception {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n\n        int[] m = new int[n];\n\n        for (int i = 0; i < n; i++)\n            m[i] = in.nextInt();\n\n        byte k = 0;\n        if (m[0] % 2 == 0) {\n            if (m[1] % 2 == 0) {\n                k = 0;\n            } else {\n                if (m[2] % 2 == 0) {\n                    System.out.println(2);\n                    return;\n                } else {\n                    System.out.println(1);\n                    return;\n                }\n            }\n        } else {\n            if (m[1] % 2 == 1) {\n                k = 1;\n            } else {\n                if (m[2] % 2 == 0) {\n                    System.out.println(1);\n                    return;\n                } else {\n                    System.out.println(2);\n                    return;\n                }\n            }\n        }\n        if (k == 0) {\n            for (int i = 0; i < m.length; i++) {\n                if (m[i] % 2 == 1) {\n                    System.out.println(i + 1);\n                    break;\n                }\n            }\n        } else {\n            for (int i = 0; i < m.length; i++) {\n                if (m[i] % 2 == 0) {\n                    System.out.println(i + 1);\n                    break;\n                }\n            }\n        }\n\n    }\n\n    public static void main(String args[]) throws Exception {\n        Iq.metod();\n    }\n\n}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class IQ {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tArrayList<Integer> e=new ArrayList<Integer>();\n\t\tArrayList<Integer> o=new ArrayList<Integer>();\n\t\tint size=sc.nextInt();\n\t\tfor(int w=0;w<size;w++)\n\t\t{\n\t\t\tint x=sc.nextInt();\n\t\t\tif(x%2==0)e.add(w+1);\n\t\t\telse o.add(w+1);\n\t\t}\n\t\tif(e.size()==1)System.out.println(e.get(0));\n\t\telse System.out.println(o.get(0));\n\t\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskA implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TaskA()).start();\n//\t\tnew Template().run();\n\t}\n\n\tpublic TaskA() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//        }\n\t\tint n = in.readInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = in.readInt();\n\t\tboolean odd = a[0] % 2 + a[1] % 2 + a[2] % 2 >= 2;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i] % 2 == 1 && !odd)\n\t\t\t\tout.println(i + 1);\n\t\t\tif (a[i] % 2 == 0 && odd)\n\t\t\t\tout.println(i + 1);\n\t\t}\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9') {\n\t\t\t\t\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}", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\t\n\tprivate void eat(String line)\n\t{\n\t\tst = new StringTokenizer(line);\n\t}\n\t\n\tprivate String next() throws IOException\n\t{\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\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tpublic void run()\n\t{\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\teat(\"\");\n\t\t\t\n\t\t\tgo();\n\t\t\t\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\t\n\tpublic static void main(String[] args)\n\t{\n\t\tnew Thread(new Main()).start();\n\t}\n\t\n\tpublic void go() throws IOException\n\t{\n\t\tint n = nextInt();\n\t\tint[] v = new int[n], count = new int[2];\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tv[i] = nextInt();\n\t\t\t++count[v[i] % 2];\n\t\t}\n\t\tint residue = count[0] == 1 ? 0 : 1;\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tif(v[i] % 2 == residue)\n\t\t\t\tout.println(i + 1);\n\t}\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\n\n\npublic class Test {\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        String[] p = in.readLine().split(\" \");\n        List<Integer> a = new ArrayList<Integer>();\n        for (String k : p) {\n            a.add(Integer.parseInt(k));\n        }\n        int n = a.size();\n        int c1 = 0;\n        int c2 = 0;\n        int c1p = 0;\n        int c2p = 0;\n        for (int i = 0; i < n; i++) {\n            if (a.get(i) % 2 == 0) {\n                c1++;\n                c1p = i;\n            } else {\n                c2++;\n                c2p = i;\n            }\n        }\n        if (c1 < c2) {\n            System.out.println(c1p + 1);\n        }  else {\n            System.out.println(c2p + 1);\n        }\n    }\n    \n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n    \n    public static void main(String[] args) throws Exception {\n        int i,j,k;\n        int counter[] = new int[2];\n        int a[] = new int[200];\n        int needed;\n        \n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        \n        int N = Integer.parseInt(br.readLine());\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        \n        for (i=1;i<=N;i++) {\n            a[i] = Integer.parseInt(st.nextToken());\n            counter[a[i]%2]++;\n        }\n        \n        if (counter[0] == 1) {\n            needed = 0;\n        } else {\n            needed = 1;\n        }\n        \n        for (i=1;i<=N;i++) {\n            if (a[i]%2 == needed) {\n                System.out.println(i);\n                return;\n            }\n        }\n        \n    }\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class a {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint a[] = new int[n];\n\t\tfor(int i=0;i<n;i++) a[i] = in.nextInt()%2;\n\t\t\n\t\tint z = 0;\n\t\tfor(int i=0;i<n;i++) z+=(a[i] == 0)?1:0;\n\t\tif (z == 1) z = 0;\n\t\telse z = 1;\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t\tif (a[i] == z){\n\t\t\t\tSystem.out.println(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class IQ {\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    for(int i = 0; i < n; i++) {\n      boolean x = a[i] % 2 == 0;\n      int c = 0;\n      for(int j = 0; j < n; j++) {\n        if(x != (a[j] % 2 == 0))\n          c++;\n      }\n      if(c == n-1) {\n        System.out.println(i+1);\n        break;\n      }\n    }\n  }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class Main {\n    \n    public static void main(String[] args) throws NumberFormatException, IOException {\n        Scanner sc = new Scanner(new InputStreamReader(System.in));\n        int n = sc.nextInt(),even = 0,odd = 0,evI = 0,OdI = 0;      \n        for (int i = 0; i < n; i++) {\n            if(sc.nextInt()%2 == 1){\n                odd++;\n                OdI = i+1;\n            }else{\n                even++;\n                evI = i+1; \n            }\n        }\n        if(even < odd)\n            System.out.println(evI);\n        else\n            System.out.println(OdI);\n        \n    }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "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 * @throws NumberFormatException \n\t */\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tint nums = Integer.parseInt(reader.readLine());\n\t\t\n\t\tString line = reader.readLine();\n\t\tint[] ar = new int[nums];\n\t\tString[] par = line.split(\" \");\n\t\t\n\t\tfor(int i=0; i<nums; i++){\n\t\t\tar[i] = Integer.parseInt(par[i]);\n\t\t}\n\t\tA a = new A();\n\t\t\n\t\tSystem.out.print(a.getDif(ar));\n\t}\n\t\n\tprivate int getDif(int[] input){\n\t\tint odd = 0, even = 0, d = 0;\n\t\tint p = 0, q = 0;\n\t\t\n\t\tfor(int i=0; i<input.length; i++){\n\t\t\tint t = input[i]%2;\n\t\t\tif(t==0){\n\t\t\t\teven++;\n\t\t\t\tp = i+1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\todd++;\n\t\t\t\tq = i+1;\n\t\t\t} \n\t\t\t\n\t\t\tif(odd>0 && even>0 && (odd!=even)){\n\t\t\t\tif(even>odd)\n\t\t\t\t\treturn q;\n\t\t\t\telse\n\t\t\t\t\treturn p;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn d;\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\npublic class A {\n\tpublic static void main(String[] args) throws IOException\t{\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[] list = new int[n];\n\t\tfor(int i = 0; i < list.length; i++)\n\t\t\tlist[i] = Integer.parseInt(st.nextToken());\n\t\tint odd = 0;\n\t\tint even = 0;\n\t\tfor(int x: list)\n\t\t\tif(x%2==1)\t{\n\t\t\t\todd++;\n\t\t\t}\n\t\t\telse\t{\n\t\t\t\teven++;\n\t\t\t}\n\t\tfor(int i = 1; i <= list.length; i++)\t{\n\t\t\tif(list[i-1]%2==1 && odd == 1)\t{\n\t\t\t\tSystem.out.println(i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse if(list[i-1]%2 == 0 && even == 1){\n\t\t\t\tSystem.out.println(i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: dev_il\n * Date: 03.08.2010\n * Time: 0:59:04\n * To change this template use File | Settings | File Templates.\n */\n\n\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\nimport java.util.*;\n\npublic class IQTest implements Runnable {\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok;\n\n    public static void main(String[] args) {\n        new Thread(new IQTest()).start();\n    }\n\n    void solve() throws IOException {\n        int n = nextInt();\n        List<Integer> l1 = new ArrayList<Integer>();\n        List<Integer> l2 = new ArrayList<Integer>();\n        for (int i = 0; i < n; ++i) {\n            int k = nextInt();\n            if (k % 2 == 0) l1.add(i + 1);\n            else l2.add(i + 1);\n        }\n        if (l1.size() == 1)\n            out.println(l1.get(0));\n        else out.println(l2.get(0));\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            // in = new BufferedReader(new FileReader(new File(\"input.txt\")));\n            out = new PrintWriter(System.out);\n            // out = new PrintWriter(new File(\"output.txt\"));\n            solve();\n            out.flush();\n            out.close();\n            in.close();\n        } catch (IOException e) {\n            // TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n\n    }\n\n    String nextLine() throws IOException {\n        tok = null;\n        return in.readLine();\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    String nextToken() throws IOException {\n        while (tok == null || !tok.hasMoreTokens()) {\n            tok = new StringTokenizer(in.readLine());\n        }\n        return tok.nextToken();\n    }\n\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport org.omg.PortableServer.ForwardRequestHelper;\n\npublic class A{     \n        \n        private BufferedReader in;  \n        private StringTokenizer st;\n        \n        void solve() throws IOException{\n            \n            int n = nextInt();\n            int i = 0;\n            int[]nums = new int[n];\n            int numeven = 0;\n            int numodd = 0;\n            while(n-->0){\n                nums[i] = nextInt();\n                if(nums[i]%2==0) numeven++;\n                else numodd++;\n                i++;\n            }\n            for (int j = 0; j < nums.length; j++) {\n                if(numeven==1&&nums[j]%2==0){\n                    System.out.println(j+1); break;\n                }\n                if(numodd==1&&nums[j]%2!=0){\n                    System.out.println(j+1); break;\n                }\n            }\n            \n            \n        }\n            \n\n        A() throws IOException {\n            in = new BufferedReader(new InputStreamReader(System.in));          \n            eat(\"\");\n            solve();            \n        }\n\n        private void eat(String str) {\n            st = new StringTokenizer(str);\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 A();\n        }\n\n        int gcd(int a,int b){\n            if(b>a) return gcd(b,a);\n            if(b==0) return a;\n            return gcd(b,a%b);\n        }\n}\n", "complexity": "linear", "problem": "25_A. IQ test", "from": "CODEFORCES"}
{"src": "import java.io.DataInputStream; \nimport java.io.FileInputStream; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.Scanner; \nimport java.util.StringTokenizer;\nimport java.io.BufferedReader; \n\n import java.util.*;\npublic class Main \n{ \nstatic Graph graph[];\n\tpublic static void add_edge(int u,int v)\n\t{\n\t\tgraph[u].adj.add(graph[v]);\n\t\tgraph[v].adj.add(graph[u]);\n\t}\n\tpublic static void dfs(int index)\n\t{\n\t\tGraph z=graph[index];\n\t\tz.vis=1;Graph v;\n\t\tfor( int i=0;i<z.adj.size();i++)\n\t\t{\n\t\t\tv=z.adj.get(i);\n\t\t\tif(v.vis==0)\n\t\t\t{\n\t\t\t\tv.dist=z.dist+1;\n\t\t\t\tv.parent=z.val;\n\t\t\t\tdfs(v.val);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t}\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    public static void main(String[] args) \n    { \n        FastReader sc=new FastReader();\n\t\tint n=sc.nextInt();\n\t\tPair arr[]=new Pair[n];\n\t\tPair pref[]=new Pair[n];\n\t\tPair suff[]=new Pair[n];\n\t\tfor( int i=0;i<n;i++)\n\t\t{\n\t\t\tlong u=sc.nextLong();\n\t\t\tlong v=sc.nextLong();\n\t\t\tarr[i]=new Pair(u,v);\n\t\t\tpref[i]=new Pair(0,0);\n\t\t\tsuff[i]=new Pair(0,0);\n\t\t}\n\t\tpref[0].x=arr[0].x;\n\t\tpref[0].y=arr[0].y;\n\t\tfor( int i=1;i<n;i++)\n\t\t{\n\t\t\tpref[i].x=(long)Math.max(pref[i-1].x,arr[i].x);\n\t\t\tpref[i].y=(long)Math.min(pref[i-1].y,arr[i].y);\n\t\t}\n\t\tsuff[n-1].x=arr[n-1].x;\n\t\tsuff[n-1].y=arr[n-1].y;\n\t\tfor( int i=n-2;i>=0;i--)\n\t\t{\n\t\t\tsuff[i].x=(long)Math.max(suff[i+1].x,arr[i].x);\n\t\t\tsuff[i].y=(long)Math.min(suff[i+1].y,arr[i].y);\n\t\t}\n\t\tlong max=Long.MIN_VALUE;\n\t\tlong ans=0;\n\t\t\n\t\tfor( int i=0;i<n;i++)\n\t\t{\n\t\t\tlong val=Long.MAX_VALUE;\n\t\t\tlong val1=Long.MAX_VALUE;\n\t\t\t\n\t\t\tif(i!=0&&i!=n-1)\n\t\t\t{\n\t\t\t\t val=(long)Math.min(pref[i-1].y,suff[i+1].y)-(long)Math.max(pref[i-1].x,suff[i+1].x);\n\t\t\t\t \n\t\t\t}\n\t\t\telse if(i!=n-1)\n\t\t\t{\n\t\t\t\tval=suff[i+1].y-suff[i+1].x;\n\t\t\t}\n\t\t\telse\n\t\t\t\tval=pref[i-1].y-pref[i-1].x;\n\t\t\t\n\t\t\tans=val;\n\t\t\tif(ans<0)\n\t\t\t\tans=0;\n\t\t\tmax=(long)Math.max(ans,max);\n\t\t}\n\t\tSystem.out.println(max);\n     \n       \n\t\t\n\t\t\n\t\t\n    } \n}\nclass mycomparator implements Comparator<Graph>\n{\n\tpublic int compare(Graph a, Graph b)\n\t{\n\t\treturn b.dist-a.dist;\n\t}\n}\nclass Graph\n{\n\tint vis,col,val;int parent;int deg;int dist;\n\tArrayList<Graph> adj;\n\tGraph(int val)\n\t{\n\t\tvis=0;\n\t\tcol=-1;\n\t\tadj=new ArrayList<>();\n\t\tparent=-1;\n\t\tthis.val=val;\n\t\tdeg=0;\n\t\tdist=-1;\n\t}\n}\nclass Pair\n{\n\tlong x,y;\n\tPair( long x, long y)\n\t{\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t}\n}", "complexity": "linear", "problem": "1029_C. Maximal Intersection", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n//import java.util.Scanner;\n\n\n\n\npublic class SingleWildcard {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner input =new Scanner(System.in);\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tchar[] s1 =new char[a];\n\t\ts1 = input.next().toCharArray();\n\t\t\n\t\tchar[] s2 = new char[b];\n\t\ts2 = input.next().toCharArray();\n\t    boolean condition = false;\n\t    for(int i=0; i<a;i++){\n\t    \tif(s1[i]=='*'){\n\t    \t\tcondition= true;\n\t    \t\tbreak;\n\t    \t}\n\t    }\n\t   \n\t    if(!condition){\n\t    \tif(match(s1,s2)){\n\t    \t\tSystem.out.println(\"YES\");\n\t    \t\t\n\t    \t}\n\t    \telse\n\t    \t\tSystem.out.println(\"NO\");\n\t       return;\n\t    }\n\t    else{\n\t    \tint i=0;\n\t    \tif(s1.length-1>s2.length){\n\t    \t\tSystem.out.println(\"NO\");\n\t    \t\treturn;\n\t    \t}\n\t    \twhile(i<s1.length && i<s2.length && s1[i]==s2[i]){\n\t    \t\ti++;\n\t    \t}\n\t    \tint j=s2.length-1;\n\t    \tint k = s1.length-1;\n\t    \twhile(j>=0 && k>=0 &&  s1[k]==s2[j] && i<=j){\n\t    \t\tj--;\n\t    \t\tk--;\n\t    \t}\n\t    \t//System.out.println(i);\n\t    \tif(i==k && i>=0 && i<s1.length && s1[i]=='*' ){\n\t    \t\tSystem.out.println(\"YES\");\n\t    \t\treturn;\n\t    \t}\n\t    \tSystem.out.println(\"NO\");\n\t    }\n\t\t\n\t\t\n\t}\n\t\n\tstatic boolean match(char[] s1,char[] s2){\n\t\tif(s1.length!=s2.length)return false;\n\t\tfor(int i=0; i<s1.length;i++){\n\t\t\tif(s1[i]!=s2[i])return false;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\n}\n", "complexity": "linear", "problem": "1023_A. Single Wildcard Pattern Matching", "from": "CODEFORCES"}
{"src": "/*\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 newpackage;\nimport java.util.*;\n/**\n *\n * @author parpaorsa\n */\npublic class NewClass {\n    static Scanner in=new Scanner(System.in);\n    public static void main(String[] args) {\n        int n = in.nextInt(),ans=Integer.MAX_VALUE,t=0;\n        String x = in.next();\n        for (int i = 0; i < n; i++) {\n            if(x.charAt(i)=='-')t--;\n            else t++;\n            ans=Math.min(ans,t);\n        }\n           if(ans <= 0) \n               System.out.println(Math.abs(ans)+t);\n           else \n               System.out.println(t);\n    }\n \n}\n", "complexity": "linear", "problem": "1159_A. A pile of stones", "from": "CODEFORCES"}
{"src": "    import jdk.nashorn.internal.objects.NativeArray;\n\n    import javax.swing.JOptionPane ;\n    import javax.swing.plaf.basic.BasicInternalFrameTitlePane;\n    import java.sql.SQLSyntaxErrorException;\n    import java.util.Arrays;\n    import java.util.Scanner;\n    import java.util.Vector;\n\n\n    import static jdk.nashorn.internal.objects.NativeArray.sort;\n    import static jdk.nashorn.internal.runtime.ScriptObject.toPropertyDescriptor;\n\n    public class Dialog1 {\n        private static int n ;\n        private static String s ;\n        private static char[] a;\n        public static void main(String[] args) {\n            Scanner input = new Scanner(System.in);\n            n = input.nextInt() ;\n            s = input.next() ;\n            a = s.toCharArray();\n            for(int i = 0 ; i < 200 ; ++i) {\n                int cur = i ;\n                boolean fl = true ;\n                for(int j = 0 ; j < n ; ++j) {\n                    if(a[j] == '+')\n                        ++cur ;\n                    else\n                        --cur ;\n                    if(cur < 0)\n                        fl = false ;\n                }\n                if(fl) {\n                    System.out.print(cur);\n                    return ;\n                }\n            }\n        }\n    }", "complexity": "linear", "problem": "1159_A. A pile of stones", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\twhile(sc.hasNext()) {\n\t\t\tint n=sc.nextInt();\n\t\t\tString s=sc.next();\n\t\t\tint sum=0;\n\t\t\tfor(int i=0;i<s.length();i++) {\n\t\t\t\tif(s.charAt(i)=='+') {\n\t\t\t\t\tsum++;\n\t\t\t\t}\n\t\t\t\tif(s.charAt(i)=='-'&&sum!=0) {\n\t\t\t\t\tsum--;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1159_A. A pile of stones", "from": "CODEFORCES"}
{"src": "/*\n * Created on 17.05.2019\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * @author Wolfgang Weck\n */\npublic class C01Easy {\n\tpublic static void main(String[] args) {\n\t\ttry (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {\n\t\t\tfinal String[] line = r.readLine().split(\" \");\n\t\t\tfinal int N = Integer.parseInt(line[0]), P = Integer.parseInt(line[1]);\n\t\t\tfinal String[] numS = r.readLine().split(\" \");\n\t\t\tif (numS.length != N) throw new IllegalArgumentException();\n\t\t\tfinal int[] n = new int[N];\n\t\t\tint sum1 = 0, sum2 = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tn[i] = Integer.parseInt(numS[i]) % P;\n\t\t\t\tsum2 += n[i];\n\t\t\t\tif (sum2 >= P) sum2 -= P;\n\t\t\t}\n\t\t\tint max = sum2;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tsum1 += n[i];\n\t\t\t\tif (sum1 >= P) sum1 -= P;\n\t\t\t\tsum2 -= n[i];\n\t\t\t\tif (sum2 < 0) sum2 += P;\n\t\t\t\tfinal int s = sum1 + sum2;\n\t\t\t\tif (s > max) max = s;\n\t\t\t}\n\t\t\tSystem.out.println(max);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "958_C1. Encryption (easy)", "from": "CODEFORCES"}
{"src": "\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 madis\n */\npublic class Spreadsheet {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int N = in.nextInt();\n        in.nextLine();\n        for (int i = 0; i < N; i++) {\n            String str = in.nextLine();\n            if (str.indexOf(\"R\") == 0 && str.indexOf(\"R\") + 1 < str.indexOf(\"C\") && isNum(str.charAt(1))) {\n                int row = Integer.parseInt(str.substring(str.indexOf(\"R\") + 1, str.indexOf(\"C\")));\n                int col = Integer.parseInt(str.substring(str.indexOf(\"C\") + 1));\n                System.out.println(convertRC(row, col));\n            } else {\n                String row = \"\";\n                int j = 0;\n                while (str.charAt(j) >= 'A' && str.charAt(j) <= 'Z') {\n                    row += str.charAt(j);\n                    j++;\n                }\n                int num = Integer.parseInt(str.substring(j));\n                System.out.println(convertAB(row, num));\n            }\n        }\n    }\n\n    static String convertAB(String str, int num) {\n        String result = \"\";\n        int col = 0;\n        for (int i = 0; i < str.length(); i++) {\n            col += (int)Math.pow(26, (str.length()) - (i + 1)) * (str.charAt(i) - 'A' + 1);\n        }\n        result += \"R\" + num;\n        result += \"C\" + col;\n\n        return result;\n    }\n\n    static String convertRC(int row, int column) {\n        String result = \"\";\n        while (column > 0) {\n            int index = column % 26;\n\n            char c;\n            if (index == 0) {\n                c = 'Z';\n                column = column - 26;\n            } else {\n                c = (char) ('A' + index - 1);\n                column = column - index;\n            }\n            result += c;\n\n            column = column / 26;\n        }\n\n        String res = \"\";\n        for (int i = 0; i < result.length(); i++) {\n            res += result.charAt(result.length() - (i + 1));\n        }\n        res += row;\n        return res;\n    }\n\n    static boolean isNum(char x){\n        return x>'0'&&x<='9';\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "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() {\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}\n\t\t\t}\n\t\t}.start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\n\tint MAXDEG = 5;\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\tint n = nextInt();\n\t\tint[] sumDegs = new int[MAXDEG + 1];\n\t\tsumDegs[0] = 1;\n\t\tint deg = 1;\n\t\tfor (int i = 1; i <= MAXDEG; i++) {\n\t\t\tdeg *= 26;\n\t\t\tsumDegs[i] = sumDegs[i - 1] + deg;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = nextLine();\n\t\t\tString pref = \"\";\n\t\t\tint endPos = -1;\n\t\t\tfor (int j = 0; j < s.length(); j++) {\n\t\t\t\tif (!isLet(s.charAt(j))) {\n\t\t\t\t\tendPos = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tpref += s.charAt(j);\n\t\t\t}\n\t\t\tint num = -1;\n\t\t\ttry {\n\t\t\t\tnum = Integer.parseInt(s.substring(endPos));\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\t\tif (num != -1) {\n\t\t\t\tint col = sumDegs[pref.length() - 1];\n\t\t\t\tint val = 0;\n\t\t\t\tfor (int j = 0; j < pref.length(); j++) {\n\t\t\t\t\tval = val * 26 + (pref.charAt(j) - 'A');\n\t\t\t\t}\n\t\t\t\tcol += val;\n\t\t\t\tout.println(\"R\" + num + \"C\" + col);\n\t\t\t} else {\n\t\t\t\tint row = Integer.parseInt(s.substring(1, s.indexOf('C')));\n\t\t\t\tint col = Integer.parseInt(s.substring(s.indexOf('C') + 1));\n\t\t\t\tint len = MAXDEG;\n\t\t\t\twhile (col < sumDegs[len])\n\t\t\t\t\tlen--;\n\t\t\t\tlen++;\n\t\t\t\tcol -= sumDegs[len - 1];\n\t\t\t\tString res = \"\";\n\t\t\t\twhile (col > 0) {\n\t\t\t\t\tres = (char) (col % 26 + 'A') + res;\n\t\t\t\t\tcol /= 26;\n\t\t\t\t}\n\t\t\t\twhile (res.length() < len)\n\t\t\t\t\tres = \"A\" + res;\n\t\t\t\tout.println(res + row);\n\t\t\t}\n\t\t}\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tprivate boolean isLet(char c) {\n\t\treturn c >= 'A' && c <= 'Z';\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", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.PrintWriter;\n\n/**\n * @author Egor Kulikov (kulikov@devexperts.com)\n */\npublic class Spreadsheets implements Runnable {\n\tprivate Scanner in = new Scanner(System.in);\n\tprivate PrintWriter out = new PrintWriter(System.out);\n\tprivate String s, ans;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Spreadsheets()).start();\n\t}\n\n\tprivate void read() {\n\t\ts = in.next();\n\t}\n\n\tprivate void solve() {\n\t\tif (s.matches(\"R\\\\d+C\\\\d+\")) {\n\t\t\ts = s.replace('R', ' ').replace('C', ' ');\n\t\t\tScanner ss = new Scanner(s);\n\t\t\tint r = ss.nextInt();\n\t\t\tint c = ss.nextInt();\n\t\t\tc--;\n\t\t\tStringBuffer b = new StringBuffer();\n\t\t\tint c26 = 26;\n\t\t\tint cc = 0;\n\t\t\twhile (cc + c26 <= c) {\n\t\t\t\tcc += c26;\n\t\t\t\tc26 *= 26;\n\t\t\t}\n\t\t\tc -= cc;\n\t\t\twhile (c26 > 1) {\n\t\t\t\tc26 /= 26;\n\t\t\t\tb.append((char) (c / c26 + 'A'));\n\t\t\t\tc %= c26;\n\t\t\t}\n\t\t\tans = b.toString() + r;\n\t\t} else {\n\t\t\tint p = 0;\n\t\t\twhile (!Character.isDigit(s.charAt(p))) {\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tint c26 = 1;\n\t\t\tint cc = 0;\n\t\t\tfor (int i = 0; i < p; i++) {\n\t\t\t\tcc += c26;\n\t\t\t\tc26 *= 26;\n\t\t\t}\n\t\t\tfor (int i = 0; i < p; i++) {\n\t\t\t\tc26 /= 26;\n\t\t\t\tcc += c26 * (s.charAt(i) - 'A');\n\t\t\t}\n\t\t\tans = \"R\" + s.substring(p) + \"C\" + cc;\n\t\t}\n\t}\n\n\tprivate void write() {\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\tint n = in.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tread();\n\t\t\tsolve();\n\t\t\twrite();\n\t\t}\n\t\tout.close();\n\t}\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n//\tstatic Scanner in;\n\tstatic PrintWriter out;\n\tstatic BufferedReader in;\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 BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint n = new Integer(in.readLine());\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.readLine();\n\t\t\tint x = 0;\n\t\t\twhile (s.charAt(x) - 'A' >= 0 && s.charAt(x) - 'Z' <= 0) x++;\n\t\t\tint y = s.length() - 1;\n\t\t\twhile (s.charAt(y) - '0' >= 0 && s.charAt(y) - '9' <= 0) y--;\n\n\t\t\tif (x > y) {\n\t\t\t\tint k = 1;\n\t\t\t\tint a = 1;\n\t\t\t\tfor (int j = 1; j < x; j++) {\n\t\t\t\t\tk *= 26;\n\t\t\t\t\ta += k;\n\t\t\t\t}\n\t\t\t\tfor (int j = 0; j < x; j++) {\n\t\t\t\t\ta += k*(s.charAt(j) - 'A');\n\t\t\t\t\tk /= 26;\n\t\t\t\t}\n\t\t\t\tint b = Integer.parseInt(s.substring(x));\n\t\t\t\tout.println(\"R\" + b + \"C\" + a);\n\t\t\t} else {\n\t\t\t\twhile (s.charAt(x) - '0' >= 0 && s.charAt(x) - '9' <= 0) x++;\n\t\t\t\tint b = Integer.parseInt(s.substring(1, x));\n\t\t\t\tint a = Integer.parseInt(s.substring(x + 1));\n\t\t\t\tint num = 0;\n\t\t\t\tint k = 1;\n\t\t\t\twhile (a >= k) {\n\t\t\t\t\ta -= k;\n\t\t\t\t\tk *= 26;\n\t\t\t\t}\n\t\t\t\tk /= 26;\n\t\t\t\twhile (k > 0) {\t\n\t\t\t\t\tout.print((char)('A' + (a/k)));\n\t\t\t\t\ta %= k;\n\t\t\t\t\tk /= 26;\n\t\t\t\t}\n\t\t\t\tout.println(b);\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.lang.Character.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class B {\n\tstatic final int[] num = new int[7];\n\tstatic {\n\t\tfor(int i = 1, c = 1; i <= 6; i++, c *= 26)\n\t\t\tnum[i] = num[i-1] + c;\n\t}\n\tpublic void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\twhile(n-- > 0) {\n\t\t\tString s = sc.next();\n\t\t\tSystem.out.println(s.matches(\"R[0-9]+C[0-9]+\") ? toABdd(s) : toRC(s));\n\t\t}\n\t}\n\n\tString toRC(String s) {\n\t\tString ss = s.split(\"[0-9]+\")[0];\n\t\tString sn = s.split(\"[A-Z]+\")[1];\n\t\tint r = 0;\n\t\tfor(char c : ss.toCharArray())\n\t\t\tr = r * 26 + c - 'A';\n\t\tr += num[ss.length()];\n\t\tint c = Integer.parseInt(sn);\n\t\treturn \"R\" + c + \"C\" + r;\n\t}\n\n\tString toABdd(String s) {\n\t\tString[] ss = s.split(\"[RC]\");\n\t\tint c = Integer.parseInt(ss[1]);\n\t\tint r = Integer.parseInt(ss[2]);\n\t\tint a = 0;\n\t\twhile(r > num[++a]);\n\t\ta--;\n\t\tr -= num[a];\n\t\tchar[] cs = new char[a];\n\t\tfor(int i = 0; i < a; i++, r /= 26)\n\t\t\tcs[a-i-1] = (char) (r % 26 + 'A');\n\t\treturn new String(cs) + c;\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}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/**\n * @author def\n * @version 1.0\n */\npublic class B {\n\n    public static void main(String[] args) throws IOException {\n        new B().solve();\n    }\n\n    void solve() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        int n = Integer.parseInt(in.readLine());\n        while (n-- > 0) {\n            String s = in.readLine();\n            int pr = s.indexOf('R');\n            int pc = s.indexOf('C');\n            if (pr == 0 && pc > 1 && Character.isDigit(s.charAt(1))) {\n                int r = Integer.parseInt(s.substring(1, pc));\n                int c = Integer.parseInt(s.substring(pc + 1, s.length()));\n                out.println(i2s(c) + r);\n            } else {\n                int i = 0;\n                while (!Character.isDigit(s.charAt(i))) ++i;\n                out.println(\"R\" + Integer.parseInt(s.substring(i, s.length())) + \"C\" + s2i(s.substring(0, i)));\n            }\n        }\n\n        out.close();\n    }\n\n    int s2i(String s) {\n        int r = 0;\n        for (int i = 0; i < s.length(); ++i) {\n            r = r * 26 + (s.charAt(i) - 'A' + 1);\n        }\n        return r;\n    }\n\n    String i2s(int i) {\n        StringBuffer s = new StringBuffer();\n        while (i > 0) {\n            i -= 1;\n            s.append((char)('A' + (i % 26)));\n            i /= 26;\n        }\n        return s.reverse().toString();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StringReader;\nimport java.util.StringTokenizer;\n\n\npublic class Solution {\n\n    public static void main(String[] args) {\n        new Thread(new Runnable() {\n            \n            @Override\n            public void run() {\n                new Solution();\n            }\n        }).start();\n    }\n\n    Solution() {\n        String data = \"2\\nR1C18\\nR1\";\n        PrintWriter pw = new PrintWriter(System.out);\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        //BufferedReader in = new BufferedReader(new StringReader(data));\n        try {\n            int n = Integer.parseInt(in.readLine());\n            int[] res = new int[2];\n            for (int i = 0; i < n; i++) {\n                String s = in.readLine();\n                if (isSecondType(s, res)) {\n                    pw.println(toFirstType(res));\n                } else {\n                    pw.println(toSecondType(s));\n                }\n            }\n        } catch (IOException e) {\n        } finally {\n            pw.flush();\n            pw.close();\n        }\n    }\n\n    private String toSecondType(String s) {\n        int i = 0;\n        for (; i < s.length(); i++) {\n            if (s.charAt(i) < 'A' || s.charAt(i) > 'Z') break;\n        }\n        String first = s.substring(0, i);\n        String second = s.substring(i, s.length());\n        StringBuilder sb = new StringBuilder();\n        sb.append(\"R\");\n        sb.append(second);\n        sb.append(\"C\");\n        sb.append(stringToNum(first));\n        return sb.toString();\n    }\n\n    private int stringToNum(String first) {\n        int k = 0;\n        int res = 0;\n        int p = 1;\n        for (int i = first.length() - 1; i >= 0; i--) {\n            int v = first.charAt(i) - 'A' + k;\n            k = 1;\n            res += p * v;\n            p *= 26;\n        }\n        return res + 1;\n    }\n\n    private String toFirstType(int[] res) {\n        StringBuilder sb = new StringBuilder();\n        sb.append(numToString(res[1]));\n        sb.append(res[0]);\n        return sb.toString();\n    }\n\n    private String numToString(int num) {\n        StringBuilder sb = new StringBuilder();\n        while (num > 0) {\n            num--;\n            char c = (char) (num % 26 + 'A');\n            sb.append(c);\n            num /= 26;\n        }\n        return sb.reverse().toString();\n    }\n\n    private boolean isSecondType(String s, int[] res) {\n        try {\n            return doIsSecondType(s, res);\n        } catch (Exception e) {\n            return false;\n        }\n    }\n\n    private boolean doIsSecondType(String s, int[] res) {\n        StringTokenizer st = new StringTokenizer(s, \"RC\", true);\n        String token = st.nextToken();\n        if (!token.equals(\"R\")) return false;\n        token = st.nextToken();\n        if (!isDigit(token)) return false;\n        res[0] = Integer.parseInt(token);\n        token = st.nextToken();\n        if (!token.equals(\"C\")) return false;\n        token = st.nextToken();\n        if (!isDigit(token)) return false;\n        res[1] = Integer.parseInt(token);\n        return true;\n    }\n\n    private boolean isDigit(String token) {\n        for (int i = 0; i < token.length(); i++) {\n            if (token.charAt(i) < '0' || token.charAt(i) > '9') return false;\n        }\n        return true;\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.awt.Label;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\tprivate boolean _ReadFromFile = false;\n\tprivate boolean _WriteToFile = false;\n\tstatic final String TASK_ID = \"in\";\n\tstatic final String IN_FILE = TASK_ID + \".in\";\n\tstatic final String OUT_FILE = TASK_ID + \".out\";\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\tprivate String alphabet;\n\t\n\tprivate void core() throws Exception {\n\t\tint n = nextInt();\n\t\talphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\t\tfor (int test = 0; test < n; test++) {\n\t\t\tString input = reader.readLine();\n\t\t\tStringTokenizer st = new StringTokenizer(input, alphabet);\n\t\t\t\n\t\t\tArrayList<Integer> have = new ArrayList<Integer>();\n\t\t\twhile (st.hasMoreElements()) {\n\t\t\t\tString kString = st.nextToken();\n\t\t\t\thave.add(Integer.parseInt(kString));\n\t\t\t}\n\t\t\tif (have.size() == 2)\n\t\t\t\twriter.println(twoInts(have.get(0), have.get(1)));\n\t\t\telse {\n\t\t\t\tString row = \"\";\n\t\t\t\tint col = 0;\n\t\t\t\tfor (int i = 0; i < input.length(); i++) {\n\t\t\t\t\tif (Character.isDigit(input.charAt(i))) {\n\t\t\t\t\t\trow = input.substring(0, i);\n\t\t\t\t\t\tcol = Integer.parseInt(input.substring(i));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twriter.println(oneInt(row, col));\n\t\t\t}\n\t\t}\n\t}\n\tprivate String oneInt(String row, int col) {\n\t\treturn \"R\" + col + \"C\" + toNum(row);\n\t}\n\tprivate int toNum(String row) {\n\t\tint res = 0;\n\t\tfor (int i = 0; i < row.length(); i++) {\n\t\t\tres = res * 26 + row.charAt(i) - 'A' + 1;\n\t\t}\n\t\treturn res;\n\t}\n\tprivate String twoInts(Integer row, Integer col) {\n\t\treturn toAlpha(col) + row;\n\t}\n\tprivate String toAlpha(Integer col) {\n\t\tString res = \"\";\n\t\twhile (col > 0) {\n\t\t\tif (col % 26 > 0) {\n\t\t\t\tres = alphabet.charAt(col % 26 - 1) + res;\n\t\t\t\tcol /= 26;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tres = \"Z\" + res;\n\t\t\t\tcol -= 26;\n\t\t\t\tcol /= 26;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\tvoid debug(Object...os) {\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t//--------------------- IO stuffs ---------------------\n    public static void main(String[] args) throws InterruptedException {\n        Thread thread = new Thread(new Main());\n        thread.start();\n        thread.join();\n    }\n\tpublic void run() {\n        try {\n        \treader = _ReadFromFile ? new BufferedReader(new FileReader(IN_FILE)) : new BufferedReader(new InputStreamReader(System.in));\n        \twriter = _WriteToFile ? new PrintWriter(OUT_FILE) : new PrintWriter(new BufferedOutputStream(System.out));\n            tokenizer = null;\n            core();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n    int nextInt() throws Exception {\n        return Integer.parseInt(nextToken());\n    }\n    long nextLong() throws Exception {\n        return Long.parseLong(nextToken());\n    }\n    double nextDouble() throws Exception {\n        return Double.parseDouble(nextToken());\n    }\n    String nextToken() throws Exception {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class B implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new B()).start();\n\t}\n\n\tStringTokenizer st;\n\tPrintWriter out;\n\tBufferedReader br;\n\tboolean eof = false, in_out = false, std = false;\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\tString nextLine() {\n\t\tString ret = \"\";\n\t\ttry {\n\t\t\tret = br.readLine();\n\t\t} catch (Exception e) {\n\t\t\tret = \"\";\n\t\t}\n\t\tif (ret == null) {\n\t\t\teof = true;\n\t\t\treturn \"$\";\n\t\t}\n\t\treturn ret;\n\t}\n\n\tString nextString() {\n\t\treturn 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\n\tBigInteger nextBigInteger() {\n\t\treturn new BigInteger(nextToken());\n\t}\n\n\tpublic void run() {\n\t\t// long time = System.currentTimeMillis();\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.flush();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(111);\n\t\t}\n\t\t// System.err.println(System.currentTimeMillis() - time);\n\t}\n\n\tvoid solve() {\n\t\tint n = nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsolve2();\n\t\t}\n\t}\n\n\tvoid solve2() {\n\t\tString s = nextToken();\n\t\tboolean wasNum = false, isFirst = false;\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\twasNum = true;\n\t\t\t} else if (wasNum) {\n\t\t\t\tisFirst = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (isFirst) {\n\t\t\tStringTokenizer e = new StringTokenizer(s, \"RC\");\n\t\t\tint y = Integer.parseInt(e.nextToken());\n\t\t\tint x = Integer.parseInt(e.nextToken()) - 1;\n\t\t\tgo1(x, y);\n\t\t} else {\n\t\t\tgo2(s);\n\t\t}\n\t}\n\n\tvoid go1(int x, int y) {\n\t\tlong cur = 26;\n\t\tint len = 1;\n\t\twhile (x >= cur) {\n\t\t\tx -= cur;\n\t\t\tcur *= 26;\n\t\t\tlen++;\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tsb.append((char) ('A' + x % 26));\n\t\t\tx /= 26;\n\t\t}\n\t\tout.println(sb.reverse().toString() + y);\n\t}\n\n\tvoid go2(String s) {\n\t\tint id = -1;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) <= '9' && s.charAt(i) >= '0') {\n\t\t\t\tid = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tString s1 = s.substring(0, id);\n\t\tString s2 = s.substring(id);\n\t\tint x = 0;\n\t\tint cur = 26;\n\t\tfor (int i = 1; i < s1.length(); i++) {\n\t\t\tx += cur;\n\t\t\tcur *= 26;\n\t\t}\n\t\tint d = 0;\n\t\tfor (int i = 0; i < s1.length(); i++) {\n\t\t\td *= 26;\n\t\t\td += s1.charAt(i) - 'A';\n\t\t}\n\t\tx += d;\n\t\tout.println(\"R\" + s2 + \"C\" + (x + 1));\n\t}\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.List;\nimport java.awt.*;\n\npublic class Trains1_2 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 Trains1_2()).run();\n    }\n\n    public void run() {\n        /*\n         * try { br = new BufferedReader(new FileReader(\"knapsackfixed.in\")); pw\n         * = new PrintWriter(\"knapsackfixed.out\"); } catch\n         * (FileNotFoundException e) { e.printStackTrace(); }\n         */\n        br = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(new OutputStreamWriter(System.out));\n        solver();\n        pw.close();\n\n    }\n\n    private void nline() {\n        try {\n            if (!stk.hasMoreTokens())\n                stk = new StringTokenizer(br.readLine());\n        } catch (IOException e) {\n            throw new RuntimeException(\"KaVaBUnGO!!!\", e);\n        }\n    }\n\n    private String nstr() {\n        while (!stk.hasMoreTokens())\n            nline();\n        return stk.nextToken();\n    }\n\n    private int ni() {\n        return Integer.valueOf(nstr());\n\n    }\n\n    private long nl() {\n\n        return Long.valueOf(nstr());\n    }\n\n    private double nd() {\n        return Double.valueOf(nstr());\n\n    }\n\n    boolean isNumber(char c) {\n        if (c <= '9' && c >= '0')\n            return true;\n        return false;\n    }\n\n    String to10(String s) {\n        long ans = 0;\n        for (int i = s.length() - 1; i >= 0; i--) {\n            ans += (s.charAt(i) - 'A' + 1) * Math.pow(26, s.length() - i - 1);\n        }\n        return String.valueOf(ans);\n    }\n    \n    String to26(String s){\n        String ans=\"\";\n        int a = Integer.valueOf(s);\n        while(a>26){\n            a--;\n            int k = a%26;\n            ans=ans+(char)((int)'A'+k);\n            a/=26;\n        }\n        ans+=(char)(a+'A'-1);\n        String ans1 = \"\";\n        for(int i = ans.length()-1; i>=0; i--)ans1+=ans.charAt(i);\n        \n        return ans1;\n        \n    }\n\n    String rev(String s) {\n        String ans = \"\";\n        int format = 0;\n        int git = 0;\n        String token1 = \"\";\n        String token2 = \"\";\n        String token3 = \"\", token4 = \"\";\n        for (int i = 0; i < s.length(); i++) {\n            if (!isNumber(s.charAt(i)))\n                token1 += s.charAt(i);\n            else\n                break;\n            git++;\n        }\n        for (int i = git; i < s.length(); i++) {\n            if (isNumber(s.charAt(i)))\n                token2 += s.charAt(i);\n            else\n                break;\n            git++;\n        }\n        if (s.length() == git)\n            format = 1;\n        else {\n            format = 2;\n            \n            for (int i = git; i < s.length(); i++) {\n                if (!isNumber(s.charAt(i)))\n                    token3 += s.charAt(i);\n                else\n                    break;\n                git++;\n            }\n            for (int i = git; i < s.length(); i++)\n                if (isNumber(s.charAt(i)))\n                    token4 += s.charAt(i);\n                else\n                    break;\n        }\n\n        if (format == 1) {\n            ans += \"R\";\n            ans += token2;\n            ans += \"C\";\n            ans += to10(token1);\n\n        }else{\n            ans+=to26(token4);\n            ans+=token2;\n        }\n\n        return ans;\n    }\n\n    private void solver() {\n\n        int n = ni();\n        for (int i = 0; i < n; i++)\n            System.out.println(rev(nstr()));\n\n    }\n\n    void exit() {\n        System.exit(0);\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.text.NumberFormat;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\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\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tString sti(String s) {\n\t\tint res = 0;\n\t\tint q = 1;\n\t\tint qq = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (i > 0) qq += q;\n\t\t\tres = res * 26 + s.charAt(i) - 'A';\n\t\t\tq *= 26;\n\t\t}\n\t\treturn Integer.toString(qq + res + 1);\n\t}\n\t\n\tString its(String s) {\n\t\tint q = Integer.parseInt(s);\n\t\tString res = \"\";\n\t\tint w = 26;\n\t\tint l = 1;\n\t\twhile (q > w) {\n\t\t\tq -= w;\n\t\t\tl++;\n\t\t\tw *= 26;\n\t\t}\n\t\tq--;\n\t\tif (q == 0) return \"A\";\n\t\twhile (q > 0) {\n\t\t\tres = \"\" + (char)('A' + q % 26) + res;\n\t\t\tl--;\n\t\t\tq /= 26;\n\t\t}\n\t\tfor (; l > 0; l--) res = \"A\" + res;\n\t\treturn res;\n\t}\n\t        \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\tint j = 0;\n\t\t\twhile (!Character.isDigit(s.charAt(j))) j++;\n\t\t\tint q = j + 1;\n\t\t\twhile (q < s.length() && Character.isDigit(s.charAt(q))) q++;\n\t\t\tif (q == s.length()) {\n\t\t\t\tout.println(\"R\" + s.substring(j) + \"C\" + sti(s.substring(0, j)));\n\t\t\t} else {\n\t\t\t\tString w = s.substring(j, q);\n\t\t\t\twhile (!Character.isDigit(s.charAt(q))) q++;\n\t\t\t\tout.println(its(s.substring(q)) + w);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n//\t\t\tin = new BufferedReader(new FileReader(new File(\"input.txt\")));\n//\t\t\tout = new PrintWriter(new File(\"output.txt\"));\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 (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "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\n\tvoid solve() throws IOException {\n\t\tString s = next();\n\t\tint u = s.indexOf('R');\n\t\tint v = s.indexOf('C');\n\t\tif (u == 0 && v != -1 && u < v) {\n\t\t\tString a = s.substring(u + 1, v);\n\t\t\tString b = s.substring(v + 1);\n\t\t\ttry {\n\t\t\t\tint aa = Integer.parseInt(a);\n\t\t\t\tint bb = Integer.parseInt(b) - 1;\n\t\t\t\tint pow = 26, len = 1;\n\t\t\t\twhile (bb >= pow) {\n\t\t\t\t\tbb -= pow;\n\t\t\t\t\tpow *= 26;\n\t\t\t\t\t++len;\n\t\t\t\t}\n\t\t\t\tString r = \"\";\n\t\t\t\tfor (int i = 0; i < len; ++i) {\n\t\t\t\t\tr = ((char)(bb % 26 + 'A')) + r;\n\t\t\t\t\tbb /= 26;\n\t\t\t\t}\n\t\t\t\tout.println(r + aa);\n\t\t\t\treturn;\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t}\n\t\t}\n\t\tu = 0;\n\t\twhile (u < s.length() && Character.isLetter(s.charAt(u))) {\n\t\t\t++u;\n\t\t}\n\t\tString a = s.substring(0, u);\n\t\tString b = s.substring(u);\n\t\tout.println(\"R\" + b + \"C\" + toInt(a));\n\t}\n\n\tprivate int toInt(String a) {\n\t\tint r = 0;\n\t\tfor (int i = 0; i < a.length(); ++i) {\n\t\t\tr *= 26;\n\t\t\tr += a.charAt(i) - 'A';\n\t\t}\n\t\tint pow = 1;\n\t\tfor (int i = 0; i < a.length(); ++i) {\n\t\t\tr += pow;\n\t\t\tpow *= 26;\n\t\t}\n\t\treturn r;\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\tint tests = nextInt();\n\t\tfor (int test = 0; test < tests; ++test) {\n\t\t\tsolve();\n\t\t}\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", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main\n{\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tString s;\n\t\tint i,j;\n\t\tfor(i=0;i<n;i++)\n\t\t{\n\t\t\ts = sc.next();\n\t\t\tj = 0;\n\t\t\tboolean ok;\n                        while((s.charAt(j)>='A')&&(s.charAt(j)<='Z')) j++;\n                        while((j<s.length())&&(s.charAt(j)>='0')&&(s.charAt(j)<='9')) j++;\n                        if (j==s.length()) ok = true; else ok = false;\n                        String s1=\"\",s2=\"\";\n                        if (ok)\n                        {\n                        \tj = 0;\n                        \twhile((s.charAt(j)>='A')&&(s.charAt(j)<='Z')) \n                        \t{\n                        \t\ts1 += s.charAt(j);\n                        \t\tj++;\n                        \t}\n                        \twhile(j<s.length()) \n                        \t{\n                        \t\ts2 += s.charAt(j);\n                        \t\tj++;\n                        \t}\n                        \tint v = 0,p = 1;\n                        \tfor(j=s1.length()-1;j>=0;j--)\n                        \t{\n                        \t\tv += p*(s1.charAt(j)-'A'+1);\n                        \t\tp*=26;\n                        \t}\n                        \tSystem.out.println(\"R\"+s2+\"C\"+v);\n                        } else\n                        {\n                        \tj = 1;\n                        \twhile((s.charAt(j)>='0')&&(s.charAt(j)<='9'))\n                        \t{\n                        \t\ts1 += s.charAt(j);\n                        \t\tj++;\n                        \t}\n                        \tj++;\n                        \twhile(j<s.length())\n                        \t{\n                        \t\ts2 += s.charAt(j);\n                        \t\tj++;\n                        \t}\n\t\t\t\tInteger a = new Integer(s2);\n                        \tString s3=\"\";\n                        \tint d;\n                        \twhile(a > 0)\n                        \t{\n                        \t\td = a%26; a/=26;\n                        \t\tif (d==0) {d=26; a--;} \n                        \t\ts3 = Character.toUpperCase(Character.forDigit(9+d,36)) + s3;          \n                        \t}\n                        \tSystem.out.println(s3+s1);\n                        }\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import 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 Speadsheets {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        int n = Integer.parseInt(sc.nextLine());\n        String code = \"\";\n        \n\n    for (int i = 0; i < n; i++) {\n        long chResult = 0;\n        long chResult1 = 0;\n        long nResult = 0;\n        long nResult1 = 0;\n        boolean t = false;\n        boolean k = false;\n        code = sc.nextLine();\n\n        for (int j = 0; j < code.length(); j++) {\n            char c = code.charAt(j);\n            if (('Z' - c) < 33) {\n                if (t) {\n                    chResult1 = chResult;\n                    chResult = 0;\n                    t = false;\n                    k = true;\n                }\n                chResult = chResult * 26 + (26 - ('Z' - c));\n            } else {\n                t = true;\n                if (k) {\n                    nResult1 = nResult;\n                    nResult = 0;\n                    k = false;\n                }\n                nResult = nResult * 10 + (9 - ('9' - c));\n            }\n\n        }\n\n        if (chResult1 == 0) {\n            System.out.println(\"R\" + nResult + \"C\" + chResult);\n        } else {\n            System.out.println(convert(nResult) + nResult1);\n        }\n\n    }\n\n    }\n\n    private static String convert(long number) {\n        String [] chars = new String[]{\"Z\", \"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\"};\n        String result = \"\";\n        int rem = 0;\n        int m = 0;\n        while (number > 0) {\n        \tm = 0;\n            rem = (int) (number % 26);\n            result = chars[rem] + result;\n            /*if (number == 26) {\n            \tnumber = -1;\n            }*/\n            if (number % 26 == 0) {\n            \tm = 1;\n            }\n            number = number / 26;\n            number = number - m;\n        }\n        return result;\n    }\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.FileInputStream;\nimport java.io.InputStream;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.util.regex.Pattern;\n\n//Stephen Fulwider\n//Parser class for efficient input in Java\n//  Use just as you would Scanner.\n//  Make sure any method that uses this class throws Exception.\n//  Email any bugs or problems found to knightry@gmail.com\n\nclass Parser\n{\n    final private int BUFFER_SIZE = 1 << 16;\n\n    private java.io.DataInputStream din;\n    private byte[] buffer;\n    private int bufferPointer, bytesRead;\n\n    public Parser(java.io.InputStream in)\n    {\n        din = new java.io.DataInputStream(in);\n        buffer = new byte[BUFFER_SIZE];\n        bufferPointer = bytesRead = 0;\n    }\n\n    public int nextInt() throws Exception\n    {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        boolean neg = c == '-';\n        if (neg)\n            c = read();\n        int ret = 0;\n        do\n        {\n            ret = ret * 10 + c - '0';\n            c = read();\n        } while (c > ' ');\n        bufferPointer--;\n        if (neg)\n            return -ret;\n        return ret;\n    }\n\n    public long nextLong() throws Exception\n    {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        boolean neg = c == '-';\n        if (neg)\n            c = read();\n        long ret = 0;\n        do\n        {\n            ret = ret * 10 + c - '0';\n            c = read();\n        } while (c > ' ');\n        bufferPointer--;\n        if (neg)\n            return -ret;\n        return ret;\n    }\n\n    public double nextDouble() throws Exception\n    {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        boolean neg = c == '-';\n        if (neg)\n            c = read();\n        boolean seenDot = false;\n        double div = 1;\n        double ret = 0;\n        do\n        {\n            if (c == '.')\n                seenDot = true;\n            else\n            {\n                if (seenDot)\n                    div *= 10;\n                ret = ret * 10 + c - '0';\n            }\n            c = read();\n        } while (c > ' ');\n        bufferPointer--;\n        ret /= div;\n        if (neg)\n            return -ret;\n        return ret;\n    }\n\n    public char nextChar() throws Exception\n    {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        return (char) c;\n    }\n\n    public String next() throws Exception\n    {\n        StringBuilder ret = new StringBuilder();\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        do\n        {\n            ret.append((char) c);\n            c = read();\n        } while (c > ' ');\n        bufferPointer--;\n        return ret.toString();\n    }\n\n    // read a string into an ALREADY ALLOCATED array, returns the number of characters read\n    public int next(char[] ret) throws Exception\n    {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        int bRead = 0;\n        do\n        {\n            ret[bRead++] = (char) c;\n            c = read();\n        } while (c > ' ');\n        bufferPointer--;\n        return bRead;\n    }\n\n    public String nextLine() throws Exception\n    {\n        StringBuilder ret = new StringBuilder();\n        byte c = read();\n        while (c != '\\r' && c != '\\n' && c != -1)\n        {\n            ret.append((char) c);\n            c = read();\n        }\n        if (c == '\\r')\n            read();\n        return ret.toString();\n    }\n\n    public boolean hasNext() throws Exception\n    {\n        byte c;\n        do\n        {\n            c = read();\n            if (c == -1)\n            {\n                bufferPointer--;\n                return false;\n            }\n        } while (c <= ' ');\n        bufferPointer--;\n        return true;\n    }\n\n    private void fillBuffer() throws Exception\n    {\n        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n    }\n\n    private byte read() throws Exception\n    {\n        if (bufferPointer == bytesRead) fillBuffer();\n        if (bytesRead == -1) return -1;\n        return buffer[bufferPointer++];\n    }\n}\n\nclass Printer\n{\n    final private int BUFFER_SIZE = 1 << 16;\n\n    private java.io.DataOutputStream dout;\n    private byte[] buffer;\n    private int bufferPointer;\n\n    Printer(java.io.OutputStream out) throws Exception\n    {\n        dout = new java.io.DataOutputStream(out);\n        buffer = new byte[BUFFER_SIZE];\n        bufferPointer = 0;\n    }\n\n    public void println() throws Exception\n    {\n        write((byte) '\\n');\n    }\n\n    // print int\n    public void println(int n) throws Exception\n    {\n        print(n);\n        println();\n    }\n\n    public void print(int n) throws Exception\n    {\n        if (n >= 0)\n            print(n, true);\n        else\n        {\n            write((byte) '-');\n            print(-n, true);\n        }\n    }\n\n    private void print(int n, boolean first) throws Exception\n    {\n        if (n == 0)\n        {\n            if (first)\n                write((byte) (n + '0'));\n        }\n        else\n        {\n            print(n / 10, false);\n            write((byte) ((n % 10) + '0'));\n        }\n    }\n\n    // print long\n    public void println(long n) throws Exception\n    {\n        print(n);\n        println();\n    }\n\n    public void print(long n) throws Exception\n    {\n        if (n >= 0)\n            print(n, true);\n        else\n        {\n            write((byte) '-');\n            print(-n, true);\n        }\n    }\n\n    private void print(long n, boolean first) throws Exception\n    {\n        if (n == 0)\n        {\n            if (first)\n                write((byte) (n + '0'));\n        }\n        else\n        {\n            print(n / 10, false);\n            write((byte) ((n % 10) + '0'));\n        }\n    }\n\n    // print double\n    public void println(double d) throws Exception\n    {\n        print(d);\n        println();\n    }\n\n    public void print(double d) throws Exception\n    {\n        print(\"double printing is not yet implemented!\");\n    }\n\n    // print char\n    public void println(char c) throws Exception\n    {\n        print(c);\n        println();\n    }\n\n    public void print(char c) throws Exception\n    {\n        write((byte) c);\n    }\n\n    // print String\n    public void println(String s) throws Exception\n    {\n        print(s);\n        println();\n    }\n\n    public void print(String s) throws Exception\n    {\n        int len = s.length();\n        for (int i = 0; i < len; i++)\n            print(s.charAt(i));\n    }\n\n    public void close() throws Exception\n    {\n        flushBuffer();\n    }\n\n    private void flushBuffer() throws Exception\n    {\n        dout.write(buffer, 0, bufferPointer);\n        bufferPointer = 0;\n    }\n\n    private void write(byte b) throws Exception\n    {\n        buffer[bufferPointer++] = b;\n        if (bufferPointer == BUFFER_SIZE)\n            flushBuffer();\n    }\n}\n\npublic class Main\n{\n    public static void main(String[] args) throws Exception\n    {\n        new Main();\n    }\n\n    final int oo = (int)1e9;\n    \n//  InputStream stream = new FileInputStream(\"in\");\n    InputStream stream = System.in;\n    Parser in = new Parser(stream);\n    Printer out = new Printer(System.out);\n    Printer err = new Printer(System.err);\n    long start_time = System.nanoTime();\n    // PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    // PrintWriter err = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err)));\n    \n    int Sn;\n    char[] S = new char[1000];\n    char[] B = new char[1000];\n    \n    Main() throws Exception\n    {\n        for (int T=in.nextInt(); T-->0; )\n        {\n            Sn = in.next(S);\n            if (matchRxCy())\n                toLet();\n            else\n                toNum();\n        }\n        \n        long end_time = System.nanoTime();\n        err.println(\"Time: \" + ((end_time-start_time)/1e9) + \"(s).\");\n        if (stream instanceof FileInputStream)\n        {\n            err.println(\"~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!~~~~~~~~~~~~~~~~~~~~~~~~~~\");\n            err.println(\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~CHANGE INPUT STREAM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\");\n            err.println(\"~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!~~~~~~~~~~~~~~~~~~~~~~~~~~\");\n        }\n        out.close();\n        err.close();\n    }\n    \n    boolean matchRxCy()\n    {\n        boolean ok=S[0]=='R'&&(S[1]>='0'&&S[1]<='9');\n        if (!ok) return false;\n        int i;\n        for (i=2; i<Sn && S[i]!='C'; ++i);\n        return i<Sn;\n    }\n    \n    void toLet() throws Exception\n    {\n        int r = 0;\n        int i=1;\n        while (S[i]!='C')\n            r=r*10+S[i++]-'0';\n        int c = 0;\n        ++i;\n        while (i<Sn)\n            c=c*10+S[i++]-'0';\n                \n        int bi=0;\n        while (c>0)\n        {\n            B[bi++]=(char)((c-1)%26+'A');\n            c=(c-1)/26;\n        }\n        \n        for (int j=bi-1; j>=0; --j)\n            out.print(B[j]);\n        i=1;\n        while (S[i]!='C')\n            out.print(S[i++]);\n        out.println();\n    }\n    \n    void toNum() throws Exception // this works fine now, i think\n    {\n        int c=0;\n        int i=0;\n        int v=1;\n        while (Character.isLetter(S[i++]))\n            v*=26;\n        v/=26;\n        i=0;\n        while (Character.isLetter(S[i]))\n        {\n            c+=v*(S[i++]-'A'+1);\n            v/=26;\n        }\n        \n        int r=0;\n        while (i<Sn)\n            r=r*10+S[i++]-'0';\n        \n        out.print('R');\n        out.print(r);\n        out.print('C');\n        out.print(c);\n        out.println();\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class Round1B {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Round1B().run();\n\t}\n\n\tprivate void run() throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint tc = Integer.parseInt(sc.nextLine().trim());\n\t\twhile (tc > 0) {\n\t\t\tString s = sc.nextLine().trim();\n\t\t\tif (s.matches(\"R[0-9]+C[0-9]+\")) {\n\t\t\t\tPattern p = Pattern.compile(\"R([0-9]+)C([0-9]+)\");\n\t\t\t\tMatcher m = p.matcher(s);\n\t\t\t\tif (m.matches()) {\n\t\t\t\t\tint rows = Integer.parseInt(m.group(1));\n\t\t\t\t\tint cols = Integer.parseInt(m.group(2));\n\t\t\t\t\tString col = \"\";\n\t\t\t\t\twhile (cols > 0) {\n\t\t\t\t\t\tint mod = (cols - 1) % 26;\n\t\t\t\t\t\tcol = (char)('A' + mod) + col;\n\t\t\t\t\t\tcols = (cols - 1) / 26;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(col + rows);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tPattern p = Pattern.compile(\"([A-Z]+)([0-9]+)\");\n\t\t\t\tMatcher m = p.matcher(s);\n\t\t\t\tif (m.matches()) {\t\t\t\t\t\n\t\t\t\t\tint rows = Integer.parseInt(m.group(2));\n\t\t\t\t\tint cols = 0;\n\t\t\t\t\tint mul = 1;\n\t\t\t\t\tfor (int i = m.group(1).length() - 1; i >= 0; i--) {\n\t\t\t\t\t\tcols += mul * (m.group(1).charAt(i) - 'A' + 1);\n\t\t\t\t\t\tmul *= 26;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.printf(\"R%dC%d\\n\", rows, cols);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t} \n\t\t\ttc--;\n\t\t}\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Nick\n * Date: 08.08.2010\n * Time: 20:44:02\n * To change this template use File | Settings | File Templates.\n */\nimport java.io.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class B {\n    public static void main(String[] args) {\n        Scanner input = new Scanner (System.in);\n        Pattern rc_style = Pattern.compile(\"R[0-9]+C[0-9]+\");\n        int n = input.nextInt();\n        while(n-- > 0) {\n            String str = input.next();\n            Matcher m = rc_style.matcher(str);\n            if (m.matches()) {\n                String nums[] = str.split(\"[RC]\");\n                String row = nums[1];\n                String col = nums[2];\n                String buffer = \"\";\n                int col_num = Integer.valueOf(col);\n                while(col_num > 0) {\n                    if (col_num % 26 > 0) {\n                        buffer += (char)(col_num % 26 + 'A' - 1);\n                        col_num /= 26;\n                    } else {\n                        buffer += 'Z';\n                        col_num /= 26;\n                        col_num--;\n                    }\n                }\n                for (int i = buffer.length() - 1; i >= 0; --i) {\n                    System.out.print(buffer.charAt(i));\n                }\n                System.out.println(row);\n            } else {\n                String col = str.split(\"[0-9]+\")[0];\n                String row = str.split(\"[A-Z]+\")[1];\n\n                int col_num = 0;\n                int shift = 1;\n                for (int i = col.length() - 1; i >= 0; --i){\n                    col_num += (int)(col.charAt(i) - 'A' + 1) * shift;\n                    shift *= 26;\n                }\n                System.out.println(\"R\" + row + \"C\" + col_num);\n            }\n        }\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;         \nimport java.util.*;         \nimport java.math.*;         \nimport java.awt.geom.*;         \nimport java.util.regex.*;\npublic class Main implements Runnable  {\nStreamTokenizer ST;      \nPrintWriter out;      \nBufferedReader br;   \nint inf = 1000000000;\n\n\nint nextInt() throws IOException{      \n    ST.nextToken();      \n    return (int)ST.nval;      \n}\n\nlong nextLong() throws IOException{      \n    ST.nextToken();      \n    return (long)ST.nval;      \n}      \nString next() throws IOException{      \n    ST.nextToken();      \n    return ST.sval;      \n}      \ndouble nextD() throws IOException{      \n    ST.nextToken();      \n    return ST.nval;      \n}      \npublic static void main(String[] args) throws IOException {       \n    new Thread(new Main()).start();      \n}\n\npublic void run()  {      \n    try {          \n        br = new BufferedReader(new InputStreamReader(System.in));\n        //br = new BufferedReader(new InputStreamReader(System.in, \"ISO-8859-1\"));\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        \n        ST = new StreamTokenizer(br);      \n        solve();      \n        out.close();\n        br.close();            \n    }         \n    catch (IOException e) {        \n        throw new IllegalStateException(e);       \n    }      \n}\n\n\nString code(int x) {\n    x--;\n    StringBuilder sb = new StringBuilder();\n    while (x>0) {\n        int c = x%26;\n        if (x<10) sb.append((char)(c+'0')); else sb.append((char)('A'+c-10));\n        x /= 26;\n    }\n    if (sb.length()==0) sb.append(\"0\");\n    return sb.toString();\n}\nStringBuilder sb = new StringBuilder();\npublic void solve() throws IOException {\n    int tt = Integer.parseInt(br.readLine());\n    HashMap<String, Integer> map = new HashMap<String, Integer>();\n    for (int i=1; i<=10; i++) map.put(code(i), i);\n\n    while (tt-->0) {\n        String s = br.readLine();\n        if (s.matches(\"^[A-Z]+[0-9]+$\")) {\n            int t = 0;\n            while (Character.isLetter(s.charAt(t))) t++;\n            int r = Integer.parseInt(s.substring(t));\n            s = s.substring(0, t);\n            int res = 0;\n            for (int c:s.toCharArray()) {\n                res *= 26;\n                res += c-'A'+1;\n            }\n            out.println(\"R\"+r+\"C\"+res);\n        } else {\n            int t = s.indexOf('C');\n            int c = Integer.parseInt(s.substring(1, t));\n            int r = Integer.parseInt(s.substring(t+1));\n            //out.println(r+\" \"+c);\n            sb.setLength(0);\n            while (r>0) {\n                r--;\n                int ch = r%26;\n                sb.append((char)('A'+ch));\n                r /= 26;\n            }\n            sb = sb.reverse();\n            out.println(sb+\"\"+c);\n        }\n        \n    }\n    \n    \n}\n}\n\n\n\n\n\n\n \n\n\n\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileWriter;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.io.StringReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class B {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n\t\n\tpublic void solve()\n\t{\n\t\tString str = in.next();\n\t\t\n\t\tList<String> sp = new ArrayList<String>();\n\t\tStringBuilder sb = null;\n\t\tint kind = -1;\n\t\tfor(int i = 0;i < str.length();i++){\n\t\t\tchar c = str.charAt(i);\n\t\t\tif(c >= 'A' && c <= 'Z' && kind != 0){\n\t\t\t\tif(sb != null){\n\t\t\t\t\tsp.add(sb.toString());\n\t\t\t\t}\n\t\t\t\tsb = new StringBuilder();\n\t\t\t\tkind = 0;\n\t\t\t}\n\t\t\tif(c >= '0' && c <= '9' && kind != 1){\n\t\t\t\tif(sb != null){\n\t\t\t\t\tsp.add(sb.toString());\n\t\t\t\t}\n\t\t\t\tsb = new StringBuilder();\n\t\t\t\tkind = 1;\n\t\t\t}\n\t\t\tsb.append(c);\n\t\t}\n\t\tsp.add(sb.toString());\n\t\tif(sp.size() == 2){\n\t\t\t// BC23\n\t\t\tString bc = sp.get(0);\n\t\t\tint v = 0;\n\t\t\tfor(int i = 0;i < bc.length();i++){\n\t\t\t\tv = 26 * v + (bc.charAt(i) - 'A' + 1);\n\t\t\t}\n\t\t\t\n\t\t\tout.println(\"R\" + sp.get(1) + \"C\" + Integer.toString(v));\n\t\t}else{\n\t\t\t// R23C55\n\t\t\t\n\t\t\tint v = Integer.parseInt(sp.get(3));\n\t\t\tStringBuilder sbb = new StringBuilder();\n\t\t\tfor(;v > 0;v/=26){\n\t\t\t\tv--;\n\t\t\t\tsbb.append((char)((v % 26) + 'A'));\n\t\t\t}\n\t\t\tsbb.reverse();\n\t\t\t\n\t\t\tout.println(sbb.toString() + sp.get(1));\n\t\t}\n\t\t\n\t\tout.flush();\n\t}\n\t\n\tpublic void run() throws Exception\n\t{\n//\t\tin = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\"))));\n//\t\tout = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n//\t\tin = new Scanner(new StringReader(\"2\\nR23C55\\nR26C26\\nZ26\"));\n\t\tin = new Scanner(System.in);\n//\t\tSystem.setOut(new PrintStream(new BufferedOutputStream(System.out)));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tint n = in.nextInt();\n//\t\tint n = 1;\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\tlong t = System.currentTimeMillis();\n\t\t\tsolve();\n//\t\t\tSystem.err.printf(\"%04d/%04d %7d%n\", i, n, System.currentTimeMillis() - t);\n\t\t}\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 static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }\n\tprivate void tra(int[] a) {System.out.println(Arrays.toString(a));}\n\tprivate void tra(int[][] a)\n\t{\n\t\tfor(int[] e : a){\n\t\t\tSystem.out.println(Arrays.toString(e));\n\t\t}\n\t}\n\t\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner scn = new Scanner(System.in);\n\t\t\n\t\tint t = scn.nextInt();\n\t\twhile(t-- >0){\n\t\t\tString str = scn.next();\n\t\t\tPattern p = Pattern.compile(\"R[0-9]+C[0-9]+\");\n\t\t\tMatcher m = p.matcher(str);\n\t\t\tif (m.matches()){\n\t\t\t\tString nums[] = str.split(\"[RC]\");\n\t\t\t\tString first = nums[1];\n\t\t\t\tString second = nums[2];\n\t\t\t\t\n\t\t\t\tString ans = \"\";\n\t\t\t\tlong num = Integer.parseInt(second);\n\t\t\t\twhile(num >0){\n\t\t\t\t\tif (num % 26 > 0){\n\t\t\t\t\t\tans += (char)(num%26+'A'-1);\n\t\t\t\t\t\tnum/=26;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tans += 'Z';\n\t\t\t\t\t\tnum/=26;\n\t\t\t\t\t\tnum--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int i = ans.length()-1; i>=0;--i){\n\t\t\t\t\tSystem.out.print(ans.charAt(i));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tSystem.out.println(first);\n\t\t\t} else {\n\t\t\t\tString first = str.split(\"[0-9]+\")[0];\n\t\t\t\tString second = str.split(\"[A-Z]+\")[1];\n\t\t\t\tSystem.out.print(\"R\"+second);\n\t\t\t\t\n\t\t\t\tlong num = 0, pow = 1;\n\t\t\t\tfor (int i = first.length()-1; i>=0; --i){\n\t\t\t\t\tnum += (long)(first.charAt(i)-'A'+1) * pow;\n\t\t\t\t\tpow*=26;\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"C\"+num);\n\t\t\t}\n\t\t\t\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class b implements Runnable{\n\tPrintWriter out = null;\n\tpublic int toint(String s){\n\t\tint res = 0;\n\t\tfor (int i = 0; i < s.length(); i++){\n\t\t\tres *= 10;\n\t\t\tres += s.charAt(i)-'0';\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic void tostr(int k){\n\t\tif (k == 0) return;\n\t\ttostr((k-1)/26);\n\t\tout.print((char)(('A'+((k-1)%26))));\n\t}\n\n\tpublic int fromstr(String s){\n\t\tif (s.length() == 0) return 0;\n\t\tint r = s.charAt(s.length()-1)-'A'+1;\n\t\tr += 26*(fromstr(s.substring(0,s.length()-1)));\n\t\treturn r;\n\t}\n\n        public void run(){\n                try{\n                        Scanner in = new Scanner(System.in);\n                        out = new PrintWriter(System.out);\n                        int n = in.nextInt();\n\t\t\t\t\t\tfor (int t = 0; t < n; t++){\n\t\t\t\t\t\t\tint rp = -1;\n\t\t\t\t\t\t\tint cp = -1;\n\t\t\t\t\t\t\tString s = in.next();\n\t\t\t\t\t\t\tfor (int i = 0; i < s.length(); i++)\n\t\t\t\t\t\t\t\tif (s.charAt(i) == 'R') rp = i;\n\t\t\t\t\t\t\t\telse if (s.charAt(i) == 'C') cp = i;\n\t\t\t\t\t\t\tboolean good = true;\n\t\t\t\t\t\t\tif (rp == 0 && cp > 1){\n\t\t\t\t\t\t\t\tfor (int i = 0; i <= cp; i++)\n\t\t\t\t\t\t\t\t\tif (s.charAt(i) >= '0' && s.charAt(i) <= '9')\n\t\t\t\t\t\t\t\t\t\tgood = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (good){\n\t\t\t\t\t\t\t\tint k = 0;\n\t\t\t\t\t\t\t\tfor (;s.charAt(k) < '0' || s.charAt(k) > '9'; k++);\n\t\t\t\t\t\t\t\tint r = toint(s.substring(k,s.length()));\n\t\t\t\t\t\t\t\tint c = fromstr(s.substring(0,k));\n\t\t\t\t\t\t\t\tout.print('R');\n\t\t\t\t\t\t\t\tout.print(r);\n\t\t\t\t\t\t\t\tout.print('C');\n\t\t\t\t\t\t\t\tout.println(c);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tint r = toint(s.substring(1,cp));\n\t\t\t\t\t\t\t\tint c = toint(s.substring(cp+1,s.length()));\n\t\t\t\t\t\t\t\ttostr(c);\n\t\t\t\t\t\t\t\tout.println(r);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n                        in.close();\n                        out.close();\n                } catch(Exception e){\n                        e.printStackTrace();\n                }\n        }\n\n        public static void main(String[] args){\n                new Thread(new b()).start();\n        }\n}\n\n\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Main {\n    public static void main(String[] args) {\n\tScanner input = new Scanner(System.in);\n\tPattern rc_style = Pattern.compile(\"R[0-9]+C[0-9]+\");\n\tint n = input.nextInt();\n\n\twhile(n-- > 0) {\n\t    String str = input.next();\n\t    Matcher m = rc_style.matcher(str);\n\n\t    if(m.matches()) {\n\t\tString nums[] = str.split(\"[RC]\");\n\t\tString row = nums[1];\n\t\tString col = nums[2];\n\t\t\n\t\tString buffer = \"\";\n\t\tint col_num = Integer.valueOf(col);\n\t\twhile(col_num > 0) {\n\t\t    if(col_num % 26 > 0) {\n\t\t\tbuffer += (char)(col_num % 26 + 'A' - 1);\n\t\t\tcol_num /= 26;\n\t\t    } else {\n\t\t\tbuffer += 'Z';\n\t\t\tcol_num /= 26;\n\t\t\tcol_num--;\n\t\t    }\n\t\t}\n\n\t\tfor(int i = buffer.length() - 1; i >= 0; i--)\n\t\t    System.out.print(buffer.charAt(i));\n\t\t\n\t\tSystem.out.println(row);\n\n\t    } else {\n\t\tString col = str.split(\"[0-9]+\")[0];\n\t\tString row = str.split(\"[A-Z]+\")[1];\n\n\t\tint col_num = 0;\n\t\tint shift = 1;\n\t\tfor(int i = col.length() - 1; i >= 0; i--) {\n\t\t    col_num += (int) (col.charAt(i) - 'A' + 1) * shift;\n\t\t    shift *= 26;\n\t\t}\n\n\t\tSystem.out.println(\"R\" + row + \"C\" + col_num);\n\t    }\n\t}\n    }\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class B {\n    public static String toB(String str){\n        String row,col;\n        int i=0;\n        while(i<str.length() && str.charAt(i)<='Z'&&str.charAt(i)>='A')i++;\n        col = str.substring(0,i);\n        row = str.substring(i,str.length());\n        StringBuffer sb = new StringBuffer(col);\n        col = sb.reverse().toString();\n        int accum = 0;\n        for(i=0;i<col.length();i++){\n            int val = getValue(col.charAt(i));\n            accum+=val*Math.pow(26, i);\n            }\n        return \"R\"+row+\"C\"+accum;\n        \n    }\n    public static String toA(String str){\n        int i = str.indexOf('C');\n        String row,col,ans=\"\";\n        row = str.substring(1,i);\n        col = str.substring(i+1,str.length());\n        int colVal = Integer.parseInt(col),mod;\n        while(colVal>0){\n            mod = colVal%26;\n            if(mod==0){\n                ans+='Z';\n                colVal--;\n            }\n            else{\n                ans+=getLetter(mod);\n            }\n            colVal/=26;\n        }\n        StringBuffer sb = new StringBuffer(ans);\n        ans = sb.reverse().toString();\n        return ans+row;\n    }\n    public static int getValue(char c){\n        return c-'A'+1;\n    }\n    public static char getLetter(int n){\n        return (char)(n+'A'-1);\n    }\n    public static void main(String[] args)throws Exception{\n        Scanner in = new Scanner(System.in);\n        int cases = in.nextInt();\n        for(int i = 0;i<cases;i++){\n            String str = in.next();\n            if(str.charAt(0)=='R' && str.charAt(1)>='0'&&str.charAt(1)<='9' && str.indexOf('C')!=-1){\n                System.out.println(toA(str));\n            }\n            else System.out.println(toB(str));\n        }\n        \n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.regex.*;\n\npublic class Main {\n\n\tprivate static String encode(long rowNum) {\n\t\t\tif(rowNum<=26) {\n\t\t\t\treturn String.valueOf((char)('A'+rowNum-1));\n\t\t\t}\n\t\t\telse {\n\t\t\t\t\n\t\t\t\tif(rowNum%26==0){\n\t\t\t\t\treturn encode((long)Math.floor((double)rowNum/26)-1) \n\t\t\t\t\t+ String.valueOf((char)('A'+26-1));\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn encode((long)Math.floor((double)rowNum/26)) \n\t\t\t\t\t+ String.valueOf((char)('A'+rowNum%26-1));\n\t\t\t\t}\n\t\t\t}\n\t}\n\t\n\tprivate static long decode(String rowNum){\n\t\tlong result = 0;\n\t\tchar rowChars[] = rowNum.toCharArray();\n\t\tfor(int i=rowChars.length-1;i>=0;i--){\n\t\t\tresult+= (rowChars[i]-'A'+1) * (long)Math.pow(26,rowChars.length-i-1);\n\t\t}\n\t\treturn result;\n\t}\n\t\n\tpublic static void main(String arg[])throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint t = Integer.parseInt(in.readLine());\n\t\tPattern p1 = Pattern.compile(\"R\\\\d+C\\\\d+\");\n\t\tPattern p2 = Pattern.compile(\"\\\\d+\");\n\t\tfor(int i=0;i<t;i++){\n\t\t\tString input = in.readLine();\n\t\t\tMatcher m1 = p1.matcher(input);\n\t\t\tMatcher m2 = p2.matcher(input);\n\t\t\tif(m1.matches()){\n\t\t\t\tString result = \"\";\n\t\t\t\tif(m2.find()){\n\t\t\t\t\tresult = m2.group();\n\t\t\t\t}\n\t\t\t\tif(m2.find()){\n\t\t\t\t\tresult = encode(Long.parseLong(m2.group()))+result;\n\t\t\t\t}\n\t\t\t\tSystem.out.println(result);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tString result = \"R\";\n\t\t\t\tif(m2.find()){\n\t\t\t\t\tresult += m2.group();\n\t\t\t\t}\t\t\t\t\n\t\t\t\tresult += \"C\";\n\t\t\t\tSystem.out.println(result+decode(input.replaceAll(m2.group(),\"\")));\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class Round1B {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Round1B().run();\n\t}\n\n\tprivate void run() throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint tc = Integer.parseInt(br.readLine().trim());\n\t\twhile (tc > 0) {\n\t\t\tString s = br.readLine().trim();\n\t\t\tif (s.matches(\"R[0-9]+C[0-9]+\")) {\n\t\t\t\tPattern p = Pattern.compile(\"R([0-9]+)C([0-9]+)\");\n\t\t\t\tMatcher m = p.matcher(s);\n\t\t\t\tif (m.matches()) {\n\t\t\t\t\tint rows = Integer.parseInt(m.group(1));\n\t\t\t\t\tint cols = Integer.parseInt(m.group(2));\n\t\t\t\t\tString col = \"\";\n\t\t\t\t\twhile (cols > 0) {\n\t\t\t\t\t\tint mod = (cols - 1) % 26;\n\t\t\t\t\t\tcol = (char)('A' + mod) + col;\n\t\t\t\t\t\tcols = (cols - 1) / 26;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(col + rows);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tPattern p = Pattern.compile(\"([A-Z]+)([0-9]+)\");\n\t\t\t\tMatcher m = p.matcher(s);\n\t\t\t\tif (m.matches()) {\t\t\t\t\t\n\t\t\t\t\tint rows = Integer.parseInt(m.group(2));\n\t\t\t\t\tint cols = 0;\n\t\t\t\t\tint mul = 1;\n\t\t\t\t\tfor (int i = m.group(1).length() - 1; i >= 0; i--) {\n\t\t\t\t\t\tcols += mul * (m.group(1).charAt(i) - 'A' + 1);\n\t\t\t\t\t\tmul *= 26;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.printf(\"R%dC%d\\n\", rows, cols);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t} \n\t\t\ttc--;\n\t\t}\n\t\tbr.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.*;\n\n/*\n10\nR1C1\nA1\nR1C26\nZ1\nR1C27\nAA1\nR1C28\nAB1\nR1C52\nAZ1\n\n */\n\npublic class Main {\n\n\tScanner in;\n\tPrintWriter out;\n\n\tboolean isFirst(String line){\n\t\tint pos = 0;\n\t\twhile( pos<line.length() && Character.isLetter(line.charAt(pos))){\n\t\t\tpos++;\n\t\t}\n\t\twhile( pos<line.length() && Character.isDigit(line.charAt(pos))){\n\t\t\tpos++;\n\t\t}\n\t\treturn pos!=line.length();\n\t\t\n\t}\n\t\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tin.nextLine();\n\t\tfor (int i = 1; i<=n; i++){\n\t\t\tString line = in.nextLine();\n\t\t\tline = line.toUpperCase();\n\t\t\tif (isFirst(line)){\n\t\t\t\tint pos = 1;\n\t\t\t\tlong row = 0;\n\t\t\t\twhile(Character.isDigit(line.charAt(pos))){\n\t\t\t\t\trow*=10;\n\t\t\t\t\trow+=line.charAt(pos)-'0';\n\t\t\t\t\tpos++;\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t\tlong col = 0;\n\t\t\t\twhile(pos<line.length() && Character.isDigit(line.charAt(pos))){\n\t\t\t\t\tcol*=10;\n\t\t\t\t\tcol+=line.charAt(pos)-'0';\n\t\t\t\t\tpos++;\n\t\t\t\t}\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\twhile(col>0){\n\t\t\t\t\tsb.append((char)('A'+((col-1)%26)));\n\t\t\t\t\tcol--;\n\t\t\t\t\tcol/=26;\n\t\t\t\t}\n\t\t\t\tsb = sb.reverse();\n\t\t\t\tout.print(sb);\n\t\t\t\tout.println(row);\n\t\t\t\t// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd 1 \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t\t}else{\n\t\t\t\t// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd 2 \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t\t\tint pos = 0;\n\t\t\t\tlong col = 0;\n\t\t\t\twhile( pos<line.length() && Character.isLetter(line.charAt(pos))){\n\t\t\t\t\tcol*=26;\n\t\t\t\t\tcol+=line.charAt(pos)-'A'+1;\n\t\t\t\t\tpos++;\n\t\t\t\t}\n\t\t\t\tlong row = 0;\n\t\t\t\twhile(pos<line.length() && Character.isDigit(line.charAt(pos))){\n\t\t\t\t\trow*=10;\n\t\t\t\t\trow+=line.charAt(pos)-'0';\n\t\t\t\t\tpos++;\n\t\t\t\t}\n\t\t\t\tout.println(\"R\"+row+\"C\"+col);\n\t\t\t}\n\t\t}\n\n\t}\n\n\tvoid run() {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\ttry {\n\t\t\tsolve();\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.FileNotFoundException;\nimport java.util.Scanner;\n\n/**\n * Date: 19.02.2010\n * Time: 14:56:28\n *\n * @author Sergey Bankevich (Sergey.Bankevich@gmail.com)\n */\npublic class B1 {\n    static Scanner in;\n\n    public static void main( String[] args ) throws FileNotFoundException {\n        in = new Scanner( System.in );\n        int tn = in.nextInt();\n        for ( int i = 0; i < tn; i ++ ) {\n            String s = in.next();\n        /*for ( int i = 1; i <= 100; i ++ ) {\n            for ( int j = 1; j <= 100; j ++ ) {\n                String s = \"R\" + i + \"C\" + j;\n            for ( char j = 'A'; j <= 'Z'; j ++ ) {\n            String s = j + \"\" + i;\n                System.out.println( s );*/\n            char[] c = s.toCharArray();\n            boolean second = true;\n            second &= c[0] == 'R';\n            int r = s.indexOf( \"C\" );\n            if ( r > 0 ) {\n                second &= isNumber( s.substring( 1, r ) ) && isNumber( s.substring( r + 1 ) );\n            } else {\n                second = false;\n            }\n            if ( second ) {\n                System.out.println( toLetters( s.substring( r + 1 ) ) + s.substring( 1, r ) );\n            } else {\n                r = 0;\n                while ( c[r] >= 'A' && c[r] <= 'Z' ) {\n                    r ++;\n                }\n                System.out.println( \"R\" + s.substring( r ) + \"C\" + fromLetters( s.substring( 0, r ) ) );\n            }\n             \n        }\n    }\n\n    private static int fromLetters( String s ) {\n        int r = 0;\n        int l = s.length();\n        for ( int i = 0; i < l; i ++ ) {\n            r = r * 26 + s.charAt( i ) - 'A';\n        }\n        r ++;\n        for ( int i = 1, c = 26; i < l; i ++, c *= 26 ) {\n            r += c;\n        }\n        return r;\n    }\n\n    private static String toLetters( String s ) {\n        int x = new Integer( s ) - 1;\n        int c = 26;\n        int l = 1;\n        while ( true ) {\n            if ( x < c ) {\n                String r = \"\";\n                for ( int i = 0; i < l; i ++ ) {\n                    r = ( char ) ( 'A' + x % 26 ) + r;\n                    x /= 26;\n                }\n                return r;\n            }\n            x -= c;\n            c *= 26;\n            l ++;\n        }\n    }\n\n    private static boolean isNumber( String s ) {\n        try {\n            int x = new Integer( s );\n        } catch ( NumberFormatException e ) {\n            return false;\n        }\n        return true;\n    }\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\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.StreamTokenizer;\nimport java.util.HashMap;\n\npublic class B {\n\n\t/**\n\t * @param args\n\t * @throws IOException \n\t */\n\tstatic char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};\n\tstatic HashMap<Character, Integer> val = new HashMap<Character, Integer>();\n\tstatic HashMap<Integer, Character> ch = new HashMap<Integer, Character>();\n\tstatic StringBuffer strcol = new StringBuffer();\n\tstatic String s;\n\t\n\tstatic boolean isDigit(char a)\n\t{\n\t\tboolean found = false;\n\t\tfor (int i = 0; i < digits.length; i++)\n\t\t{\n\t\t\tif (found = a == digits[i]) break;\n\t\t}\n\t\t\n\t\treturn found;\n\t}\n    static String ABtoRC(int pos)\n\t{\n\t\tdo \n\t\t{\n\t\t\t++pos; \n\t\t} \n\t\twhile(!isDigit(s.charAt(pos)));\n\t\n\t\tint res = 0;\n\t\tfor (int i = pos - 1, pow = 1; i >= 0; i--, pow *= 26) \n\t\t{\n\t\t\tres += val.get(s.charAt(i)) * pow;\n\t\t}\n\t\t\n\t\treturn new String(\"R\" + s.substring(pos, s.length()) + \"C\" + String.valueOf(res));\n\t}\n\t\n\tstatic String RCtoAB(int cpos)\n\t{\n\t\tint col = Integer.valueOf(s.substring(cpos + 1, s.length()));\n\t\tint mod = 0;\n\t\tstrcol.delete(0, strcol.length());\n\t\t\n\t\twhile (col >= 26) \n\t\t{\n\t\t\tint tmp = col / 26;\n\t\t\tmod = col - 26 * tmp;\n\t\t\tif (mod == 0) \n\t\t\t{\n\t\t\t\tmod += 26;\n\t\t\t\ttmp -= 1;\n\t\t\t\t\n\t\t\t}\n\t\t\tcol = tmp;\n\t\t\tstrcol.append(ch.get(mod));\n\t\t}\n\t\tif(col != 0)strcol.append(ch.get(col));\n\t\tstrcol.reverse();\n\t\t\n\t\treturn strcol.toString() + s.substring(1, cpos); \n\t}\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\t// TODO Auto-generated method stub\n//\t\tBufferedReader input = new BufferedReader(new FileReader(\"input.txt\"));\n//\t\tPrintWriter output = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\tBufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter output = new PrintWriter(new OutputStreamWriter(System.out));\n\t\tStreamTokenizer in = new StreamTokenizer(input);\n\t\tin.nextToken();\n\t\tint n = (int)in.nval;\n\t\t\n\t\tfor (int i = 0; i < 26; i++) \n\t\t{\n\t\t\tval.put((char)('A' + i), i + 1);\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < 26; i++) \n\t\t{\n\t\t\tch.put(i + 1, (char)('A' + i));\n\t\t}\n\t\t\n\t\tinput.readLine();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ts = input.readLine();\n\t\t\tint cpos;\n\t\t\tif( ((cpos = s.indexOf('C')) > 1) && (isDigit(s.charAt(cpos - 1))) ) \n\t\t\t{\n\t\t\t\toutput.println(RCtoAB(cpos)); \n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\toutput.println(ABtoRC(cpos));\n\t\t\t}\n\t\t}\n\t\t\n\t\toutput.close();\n\t\tinput.close();\n\t}\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\n\npublic class RoundOneProblemB {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t\t\t\n\t\tint n=1;\n\t\t\n\t\tBufferedReader input = new BufferedReader(new InputStreamReader(System.in), 50);\n\t\t\n\t\ttry {\n\t\t\t\n\t\t\tn = Integer.valueOf(input.readLine());\n\t\t\t\n\t\t\tif (! ((1 <= n) && (n <= Math.pow(10, 5)))) {\n\t\t\t\tformatError();\n\t\t\t}\n\t\t\t\n\t\t\tPattern typeOne = Pattern.compile(\"^([A-Z]+)([0-9]+)$\");\n\t\t\tPattern typeTwo = Pattern.compile(\"^R([0-9]+)C([0-9]+)$\");\n\t\t\tfor (int i=0; i < n; i++) {\n\t\t\t\tString line = input.readLine();\n\t\t\t\tMatcher matchOne = typeOne.matcher(line);\n\t\t\t\tif (matchOne.find()) {\n\t\t\t\t\tSystem.out.println(convertOneToTwo(matchOne.group(2), matchOne.group(1)));\n\t\t\t\t} else {\n\t\t\t\t\tMatcher matchTwo = typeTwo.matcher(line);\n\t\t\t\t\tif (matchTwo.find()) {\n\t\t\t\t\t\tSystem.out.println(convertTwoToOne(matchTwo.group(1), matchTwo.group(2)));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\t\t\t\n\t\t} catch (Exception e) {\n\t\t\tformatError();\t\t\n\t\t} \n\t\t\n\t}\n\t\n\tprivate static String convertTwoToOne(String row, String col) {\n\t\tStringBuilder result = new StringBuilder();\n\t\t\n\t\tlong c = Long.parseLong(col);\n\t\twhile ( c > 0) {\n\t\t\tresult.append((char)(((c-1) % 26)+'A'));\n\t\t\tc = (c-1) / 26;\n\t\t} \n\t\tresult.reverse();\n\t\tresult.append(Long.parseLong(row));\n\t\t\n\t\treturn result.toString();\n\t}\n\t\n\tprivate static String convertOneToTwo(String row, String col) {\n\t\tStringBuilder result = new StringBuilder();\n\t\t\n\t\tint l = col.length();\n\t\tcol = col.toUpperCase();\n\t\t\n\t\tlong base = 1;\n\t\tlong c = 0;\n\t\tfor (int i=l-1; i >= 0; i--) {\n\t\t\tc = c + ((col.charAt(i) - 'A' + 1) * base);\n\t\t\tbase = base * 26;\n\t\t}\n\t\t\n\t\tresult.append(\"R\").append(Long.parseLong(row)).append(\"C\").append(c);\n\t\treturn result.toString();\n\t}\n\t\n\t/**\n\t * Exit with an error due to unexpected standard input. \n\t */\n\tprivate static void formatError() {\n\t\tSystem.out.println(\"Unexpected input\");\n\t\tSystem.exit(1);\t\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Elektronnietablici {\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer in;\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tpublic static String nextToken() throws IOException{\n\t\twhile (in == null || !in.hasMoreTokens()){\n\t\t\tin = new StringTokenizer(br.readLine());\n\t\t}\n\t\t\n\t\treturn in.nextToken();\n\t}\n\t\n\tpublic static int nextInt() throws IOException{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic static double nextDouble() throws IOException{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tint n = nextInt();\n\t\t\n\t\tString S;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tS = nextToken();\n\t\t\t\n\t\t\tint f = 0;\n\t\t\tif (S.charAt(0) == 'R' && S.charAt(1) >= '1' && S.charAt(1) <= '9'){\n\t\t\t\tfor (int j = 2; j < S.length(); j++) {\n\t\t\t\t\tif (S.charAt(j) >= 'A' && S.charAt(j) <= 'Z'){\n\t\t\t\t\t\tf = 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\t\n\t\t\tif (f == 0){\n\t\t\t\tString T1 = \"\";\n\t\t\t\tString ans = \"R\";\n\t\t\t\t\n\t\t\t\tint j;\n\t\t\t\t\n\t\t\t\tfor (j = 0; S.charAt(j) >= 'A' && S.charAt(j) <= 'Z'; j++) {\n\t\t\t\t\tT1 += S.charAt(j);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tans += S.substring(j, S.length()) + \"C\";\n\t\t\t\t\n\t\t\t\tint len = j;\n\t\t\t\t\n\t\t\t\tj--;\n\t\t\t\t\n\t\t\t\tint p = 1;\n\t\t\t\tint z = 0;\n\t\t\t\tfor (;  j >= 0; j--) {\n\t\t\t\t\tz += (S.charAt(j) - 'A') * p;\n\t\t\t\t\tp *= 26;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tp = 1;\n\t\t\t\tfor (int k = 0; k < len; k++) {\n\t\t\t\t\tz += p;\n\t\t\t\t\tp *= 26;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tans += z;\n\t\t\t\t\n\t\t\t\tout.println(ans);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tString T1 = \"\";\n\t\t\t\tString ans = \"\";\n\t\t\t\t\n\t\t\t\tint j;\n\t\t\t\tfor (j = 1; S.charAt(j) != 'C'; j++) {\n\t\t\t\t\tans += S.charAt(j);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tT1 = S.substring(j + 1, S.length());\n\t\t\t\tint z = Integer.parseInt(T1);\n\t\t\t\tint p = 1;\n\t\t\t\tint len = 0;\n\t\t\t\t\n\t\t\t\twhile (p <= z){\n\t\t\t\t\tz -= p;\n\t\t\t\t\tp *= 26;\n\t\t\t\t\tlen++;\n\t\t\t\t}\n\t\t\t\tp /= 26;\n\t\t\t\t\n\t\t\t\tT1 = \"\";\n\t\t\t\t\n\t\t\t\tfor (int k = len - 1; k >= 0; k--) {\n\t\t\t\t\tint l = z / p;\n\t\t\t\t\t\n\t\t\t\t\tT1 += (char)(z / p + 'A');\n\t\t\t\t\t\n\t\t\t\t\tz -= l * p;\n\t\t\t\t\t\n\t\t\t\t\tp /= 26;\t\n\t\t\t\t}\n\t\t\t\tans = T1 + ans;\n\t\t\t\t\n\t\t\t\tout.println(ans);\n\t\t\t}\n\t\t}\n\t\t\n\t\t//2\n\t\t//R23C55\n\t\t//BC23\n\t\t\n\t\tout.close();\n\t}\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class MSpreadSheet {\n    \n    public int toNum(String x)\n    {\n        int result = 0;\n        int pow = 0;\n        for (int i = x.length()-1; i >=0; i--)\n        {\n            result+=(x.charAt(i)-'A'+1)*Math.pow(26, pow);\n            pow++;\n        }\n        return result;\n    }\n    \n    public String toString(int x)\n    {\n        if(x<=26) return String.valueOf((char)(x+'A'-1));\n        String result = \"\";\n        while(x!=0)\n        {\n            if(x%26==0) \n            {\n                result = 'Z' + result;\n                x = x/26 - 1;\n            }\n            else\n            {\n                result = (char)((x%26)+'A'-1) + result;\n                x = x/26;\n            }           \n        }\n        return result;\n    }\n    \n    public  boolean check(String x)\n    {\n        if(x.charAt(0)!='R') return false;  //first rep\n        int in = x.indexOf('C');\n        if(in==-1) return false;\n        if(Character.isDigit(x.charAt(in-1))&&Character.isDigit(x.charAt(in+1))) return true;\n        return false;\n    }\n    \n    public void solve(String x)\n    {\n        String r=\"\";\n        String c=\"\";\n        if(check(x))\n        {\n            int in = x.indexOf('C');\n            r = x.substring(1,in);\n            c = x.substring(in+1);\n            System.out.println(toString(Integer.parseInt(c))+r);\n        }\n        else\n        {\n            int i =0;\n            while(!Character.isDigit(x.charAt(i)))\n                    c+=x.charAt(i++);\n            while(i<x.length())\n                r+=x.charAt(i++);\n            System.out.println(\"R\"+r+\"C\"+toNum(c));\n        }\n    }\n    \n    public static void main(String[] args) {\n        MSpreadSheet sh = new MSpreadSheet();\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        int i = 0;\n        while(i<n)\n        {\n            sh.solve(s.next());\n            i++;\n        }\n    }\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solution extends Thread {\n\n\tfinal static int MAXNUM = 1 << 20;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t\tint tests = nextInt();\n\t\t\tint num = 1;\n\t\t\tfor (int test = 0; test < tests; test++) {\n\t\t\t\tString s = next();\n\t\t\t\tif (s.charAt(0) == 'R' && s.charAt(1) >= '0' && s.charAt(1) <= '9' && s.indexOf('C') != -1) {\n\t\t\t\t\tString[] sp = s.split(\"[RC]\");\n\t\t\t\t\tint r = Integer.parseInt(sp[1]);\n\t\t\t\t\tint c = Integer.parseInt(sp[2]);\n\t\t\t\t\ts = \"\";\n\t\t\t\t\twhile (c > 0) {\n\t\t\t\t\t\tif (c % 26 == 0) {\n\t\t\t\t\t\t\ts = 'Z' + s;\n\t\t\t\t\t\t\tc /= 26;\n\t\t\t\t\t\t\tc --;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ts = (char)('A' + c % 26 - 1) + s;\n\t\t\t\t\t\t\tc /= 26;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\ts = s + r;\n\t\t\t\t} else {\n\t\t\t\t\tint pos = 0;\n\t\t\t\t\twhile (s.charAt(pos) < '0' || s.charAt(pos) > '9') {\n\t\t\t\t\t\tpos ++;\n\t\t\t\t\t}\n\t\t\t\t\tint r = Integer.parseInt(s.substring(pos));\n\t\t\t\t\tint c = 0;\n\t\t\t\t\ts = s.substring(0, pos);\n\t\t\t\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\t\t\t\tif (s.charAt(i) < 'Z') {\n\t\t\t\t\t\t\tc = c * 26 + (s.charAt(i) - 'A' + 1);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tc = c * 26 + 26;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\ts = \"R\" + r + \"C\" + c;\n\t\t\t\t}\n\t\t\t\tSystem.out.println(s);\n\t\t\t}\n\t\t} catch (Exception ex) {\n\t\t\tex.printStackTrace();\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\tString next() 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 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\tBufferedReader in;\n\tStringTokenizer st;\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tnew Thread(new Solution()).start();\n\t}\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class B {\n    public static void main (String[] args) throws IOException {\n        BufferedReader b = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(b.readLine());\n        while (n-- > 0) {\n            String s = b.readLine();\n            if (s.matches(\"^[A-Z]+[0-9]+$\")) {\n                System.out.println(toRC(decodeCR(s)));\n            } else {\n                System.out.println(toCR(decodeRC(s)));\n            }\n        }\n    }\n    private static String toRC(int[] a) {\n        return \"R\" + a[0] + \"C\" + a[1];\n    }\n    private static String toCR(int[] a) {\n        String r = \"\";\n        if (a[1] == 1) {\n            r = \"A\";\n        } else {\n            for (int x = a[1]; x > 0; x /= 26) {\n                r = (char)('A' + (x - 1) % 26) + r;\n                if (x % 26 == 0) x -= 26;\n            }\n        }\n        return r + a[0];\n    }\n    private static int[] decodeCR(String s) {\n        int[] a = new int[2];\n        int i = 0;\n        while (s.charAt(i) >= 'A') {\n            a[1] = a[1] * 26 + (s.charAt(i) - 'A' + 1);\n            i++;\n        }\n        a[0] = Integer.parseInt(s.substring(i));\n        // System.out.println(\"decoding CR: \" + s + \"...\" + a[0] + \", \" + a[1]);\n        return a;\n    }\n    private static int[] decodeRC(String s) {\n        assert s.charAt(0) == 'R';\n        int[] a = new int[2];\n        a[0] = Integer.parseInt(s.substring(1, s.indexOf('C')));\n        a[1] = Integer.parseInt(s.substring(s.indexOf('C') + 1));\n        // System.out.println(\"decoding RC: \" + s + \"...\" + a[0] + \", \" + a[1]);\n        return a;\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class B1 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int testCount = in.nextInt();\n        for (int test = 0; test < testCount; test++) {\n            String src = in.next();\n            if (src.matches(\"^R\\\\d+C\\\\d+$\")) {\n                Pattern p = Pattern.compile(\"\\\\d+\");\n                Matcher m = p.matcher(src);\n                m.find();\n                int r = Integer.parseInt(m.group(0));\n                m.find();\n                int c = Integer.parseInt(m.group(0));\n                System.out.println(toBase26(c) + r);\n            } else {\n                Pattern p = Pattern.compile(\"[A-Z]+\");\n                Matcher m = p.matcher(src);\n                m.find();\n                String c = m.group(0);\n                p = Pattern.compile(\"\\\\d+\");\n                m = p.matcher(src);\n                m.find();\n                int r = Integer.parseInt(m.group(0));\n                System.out.println(\"R\" + r + \"C\" + toBase10(c));\n            }\n        }\n    }\n    private static String toBase26(int n) {\n        String res = \"\";\n        do {\n            n -= 1;\n            res = (char)('A' + (n % 26)) + res;\n            n /= 26;            \n        } while (n > 0);\n        return res;\n    }\n    private static int toBase10(String x) {\n        int n = 0;\n        char[] digits = x.toCharArray();\n        for (int i = 0; i < digits.length; i++) {\n            n *= 26;\n            n += digits[i] - 'A' + 1;\n        }\n        return n;\n    }\n}\n\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class ProbB implements Runnable {\n\tprivate boolean _ReadFromFile = false;\n\tprivate boolean _WriteToFile = false;\n\tstatic final String TASK_ID = \"in\";\n\tstatic final String IN_FILE = TASK_ID + \".in\";\n\tstatic final String OUT_FILE = TASK_ID + \".out\";\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\n\tprivate static String alphabet;\n\t\n\tprivate static void core() throws Exception {\n\t\tint n = nextInt();\n\t\talphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\t\tfor (int test = 0; test < n; test++) {\n\t\t\tString input = reader.readLine();\n\t\t\tStringTokenizer st = new StringTokenizer(input, alphabet);\n\t\t\t\n\t\t\tArrayList<Integer> have = new ArrayList<Integer>();\n\t\t\twhile (st.hasMoreElements()) {\n\t\t\t\tString kString = st.nextToken();\n\t\t\t\thave.add(Integer.parseInt(kString));\n\t\t\t}\n\t\t\tif (have.size() == 2)\n\t\t\t\twriter.println(twoInts(have.get(0), have.get(1)));\n\t\t\telse {\n\t\t\t\tString row = \"\";\n\t\t\t\tint col = 0;\n\t\t\t\tfor (int i = 0; i < input.length(); i++) {\n\t\t\t\t\tif (Character.isDigit(input.charAt(i))) {\n\t\t\t\t\t\trow = input.substring(0, i);\n\t\t\t\t\t\tcol = Integer.parseInt(input.substring(i));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twriter.println(oneInt(row, col));\n\t\t\t}\n\t\t}\n\t}\n\tprivate static String oneInt(String row, int col) {\n\t\treturn \"R\" + col + \"C\" + toNum(row);\n\t}\n\tprivate static int toNum(String row) {\n\t\tint res = 0;\n\t\tfor (int i = 0; i < row.length(); i++) {\n\t\t\tres = res * 26 + row.charAt(i) - 'A' + 1;\n\t\t}\n\t\treturn res;\n\t}\n\tprivate static String twoInts(Integer row, Integer col) {\n\t\treturn toAlpha(col) + row;\n\t}\n\tprivate static String toAlpha(Integer col) {\n\t\tString res = \"\";\n\t\twhile (col > 0) {\n\t\t\tif (col % 26 > 0) {\n\t\t\t\tres = alphabet.charAt(col % 26 - 1) + res;\n\t\t\t\tcol /= 26;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tres = \"Z\" + res;\n\t\t\t\tcol -= 26;\n\t\t\t\tcol /= 26;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\tvoid debug(Object...os) {\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t//--------------------- IO stuffs ---------------------\n    public static void main(String[] args) throws InterruptedException {\n        Thread thread = new Thread(new ProbB());\n        thread.start();\n        thread.join();\n    }\n\tpublic void run() {\n        try {\n        \treader = _ReadFromFile ? new BufferedReader(new FileReader(IN_FILE)) : new BufferedReader(new InputStreamReader(System.in));\n        \twriter = _WriteToFile ? new PrintWriter(OUT_FILE) : new PrintWriter(new BufferedOutputStream(System.out));\n            tokenizer = null;\n            core();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\tstatic int nextInt() throws Exception {\n        return Integer.parseInt(nextToken());\n    }\n\tstatic long nextLong() throws Exception {\n        return Long.parseLong(nextToken());\n    }\n\tstatic double nextDouble() throws Exception {\n        return Double.parseDouble(nextToken());\n    }\n\tstatic String nextToken() throws Exception {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Round1TaskB implements Runnable {\n    static PrintWriter pw = null;\n    static BufferedReader br = null;\n    StringTokenizer st = null;\n\n    public static void main(String[] args) throws IOException {\n        pw = new PrintWriter(new OutputStreamWriter(System.out));\n        br = new BufferedReader(new InputStreamReader(System.in));\n        (new Thread(new Round1TaskB())).start();\n    }\n\n    void nline() {\n        try {\n            st = new StringTokenizer(br.readLine());\n        } catch (IOException e) {\n        }\n    }\n\n    int ni() {\n        while (st == null || !st.hasMoreTokens())\n            nline();\n        return Integer.valueOf(st.nextToken());\n    }\n\n    double nd() {\n        while (st == null || !st.hasMoreTokens())\n            nline();\n        return Double.valueOf(st.nextToken());\n    }\n\n    long nl() {\n        while (st == null || !st.hasMoreTokens())\n            nline();\n        return Long.valueOf(st.nextToken());\n    }\n\n    String nwrd() {\n        while (st == null || !st.hasMoreTokens())\n            nline();\n        return st.nextToken();\n    }\n\n    String nextLine() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n        }\n        return null;\n    }\n\n    boolean isDigit(char c) {\n        if (c <= '9' && c >= '0')\n            return true;\n        return false;\n    }\n    \n    void rec(int t, int length) {\n        if (length == 0) {\n            return;\n        }\n        rec(t / 26, length - 1);\n        pw.print((char) ('A' + (t % 26)));\n    }\n\n    void RC(int i, int j) {\n        int num = 0;\n        for (int t = i; t < j; t++) {\n            num = num * 10 + format[t] - '0';\n        }\n        int len = 0, base = 1, total = 0;\n        while (true) {\n            base *= 26;\n            total += base;\n            len++;\n            if (num <= total)\n                break;\n        }\n        num -= total / 26;\n        rec(num, len);\n    }\n\n    void BC(int i, int j) {\n        int total = 0, base = 1, rest = 0;\n        for (int k = i; k< j; k++) {\n            total += base;\n            base *= 26;\n            rest = rest * 26 + format[k] - 'A';\n        }\n        pw.print(total + rest);\n    }\n\n    char format[];\n\n    public void solve() {\n        format = nwrd().toCharArray();\n        int L = format.length;\n        for (int i = 0; i < L - 1; i++) {\n            if (isDigit(format[i]) && (format[i + 1] == 'C')) {\n                RC(i + 2, L);\n                for (int j = 1; j <= i; j++) {\n                    pw.print(format[j]);\n                }\n                pw.println();\n                return;\n            }\n        }\n        for (int i = 0; i < L; i++) {\n            if (isDigit(format[i])) {\n                pw.print('R');\n                for (int j = i; j < L; j++) {\n                    pw.print(format[j]);\n                }\n                pw.print('C');\n                BC(0, i);\n                pw.println();\n                return;\n            }\n        }\n    }\n    public void run() {\n        int n = ni();\n        while (n-- > 0) {\n            solve();\n        }\n        pw.close();\n    }\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class Task1b {\n\n\tstatic int[] fromRC (String data) {\n\t\tint pos = data.indexOf('C');\n\t\tint res[] = new int[2];\n\t\tres[0] = Integer.parseInt(data.substring(1, pos));\n\t\tres[1] = Integer.parseInt(data.substring(pos + 1));\n\t\treturn res;\n\t}\n\t\n\tstatic int[] fromXC (String data) {\n\t\tint pos = 0;\n\t\tint res[] = new int[2];\n\t\tres[0] = res[1] = 0;\n\t\twhile (data.charAt(pos) >= 'A' && data.charAt(pos) <= 'Z') {\n\t\t\tres[1] *= 26;\n\t\t\tres[1]++;\n\t\t\tres[1] += data.charAt(pos) - 'A';\n\t\t\tpos++;\n\t\t}\n\t\tres[0] = Integer.parseInt(data.substring(pos));\n\t\treturn res;\n\t}\n\t\n\tstatic String toRC (int[] data) {\n\t\treturn String.format(\"R%dC%d\", data[0], data[1]);\n\t}\n\t\n\tstatic String toXC (int[] data) {\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (data[1] > 0) {\n\t\t\tdata[1]--;\n\t\t\tsb.append((char)('A' + data[1] % 26));\n\t\t\tdata[1] /= 26;\n\t\t}\n\t\tsb = sb.reverse();\n\t\tsb.append(data[0]);\n\t\treturn sb.toString();\n\t}\n\t\n\t/**\n\t * @param args\n\t */\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\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = br.readLine();\n\t\t\tif ((s.charAt(0) == 'R') && \n\t\t\t\t(s.charAt(1) >= '0' && s.charAt(1) <= '9') &&\n\t\t\t\t(s.indexOf('C') != -1)) {\n\t\t\t\t\n\t\t\t\tSystem.out.println(toXC(fromRC(s)));\n\t\t\t} else {\n\t\t\t\tSystem.out.println(toRC(fromXC(s)));\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "// by kotb\nimport java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\n\npublic class SpreadSheet {\n\n    public void run() {\n        try {\n            Scanner s = new Scanner(System.in);\n            int tests = s.nextInt();\n            for (int i = 0; i < tests; i++) {\n                String line = s.next();\n                String regex = \"R[\\\\d]+C[\\\\d]+\";\n                Pattern pattern = Pattern.compile(regex);\n                Matcher matcher = pattern.matcher(line);\n                \n                if (matcher.matches()){\n                    int r = Integer.parseInt(line.substring(1, line.indexOf(\"C\")));\n                    int c = Integer.parseInt(line.substring(line.indexOf(\"C\") +1));\n                    System.out.println(toFormula(r, c));\n                }\n                else {\n                    int index = -1;\n                    for (int j = 0; j < line.length(); j++) {\n                        if (line.charAt(j) >= '0' && line.charAt(j) <= '9') {\n                            index = j;\n                            break;\n                        }\n                    }\n                    String c = line.substring(0, index);\n                    int r = Integer.parseInt(line.substring(index));\n                    System.out.println(fromFormula(c, r));\n                }\n            }\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n    \n    private String toFormula(int r, int c) {\n        StringBuffer buff = new StringBuffer();\n        char ch;\n        while (c != 0) {\n            int m = c%26;\n            if(m==0)\n            {\n                ch = 'Z';\n                c = c/26 - 1;\n            }\n            else\n            {\n                ch = (char)(m+'A'-1);\n                c /= 26;\n            }\n            buff.append(ch);            \n        }\n        return buff.reverse().toString() + r;\n    }\n    \n    private String fromFormula(String c, int r) {\n        int ret = 0;\n        int power = 1;\n        for (int i = c.length()-1; i >= 0; i--) {\n            ret += ((c.charAt(i) - 'A' + 1) * power);\n            power *= 26;\n        }\n        return \"R\" + r + \"C\" + ret;\n    }\n    \n    public static void main(String[] args) {\n        new SpreadSheet().run();\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.util.regex.*;\n//import java.math.*;\n//import static java.lang.Math.*;\n//import static java.util.Arrays.*;\n \npublic class Main{\n    public static void main(String[] args) throws IOException { //1-checker 2-console\n        //if (args.length==2) open(args[0], args[1], true, false); else open (\"input.txt\", \"output.txt\", true, false);\n        open (\"input.txt\", \"output.txt\", false, true);\n        char[] alph = \" ABCDEFGHIJKLMNOPQRSTUVWXYZ\".toCharArray();\n        Pattern pat = Pattern.compile(\"[A-Z]+[\\\\d]+\");\n        Matcher mat;\n        boolean b ;\n        String  s;\n        int index, coef, row, col;\n        int n = nextInt();\n        String[] tmp;\n        char[] c;\n        for (int i=0; i<n; i++)\n        {\n            s = nextLine();\n            c = s.toCharArray();\n            mat = pat.matcher(s);\n            b = mat.matches();\n            if (b)\n            {\n                \n                index = c.length-1;\n                coef = 1;\n                row = 0;\n                while (c[index]>='0' && c[index]<='9')\n                {\n                    row += (c[index]-'0')*coef;\n                    coef*=10;\n                    index--;\n                }\n                coef = 1;\n                col = 0;\n                while (index>=0)\n                {\n                    /*if (coef!=1)*/ col += (Arrays.binarySearch(alph, c[index]))*coef;\n                    //else col += (Arrays.binarySearch(alph, c[index]))*coef;\n                    coef*=26;\n                    index--;\n                }\n                out.println(\"R\"+row+\"C\"+col);\n            }\n            else\n            {\n                tmp = s.split(\"R|C\");\n                //out.print(tmp.length);\n                //row = Integer.parseInt(tmp[1]);\n                col = Integer.parseInt(tmp[2]);\n                char[] temp = new char[10];\n                int len = 0;\n                int v = 0;\n                while (col>0)\n                {\n                    index = col%26;\n                    if (index==0)\n                        { index=26;\n                          v = 1;\n                        }\n                    else v = 0;\n                    /*if (len==0)*/ temp[len]=alph[index];\n                    //else temp[len]=alph[index-1];\n                    col = (col/26) - v;\n                    len++;\n                }\n                for (int j=len-1; j>=0; j--)\n                {\n                    out.print(temp[j]);\n                }\n                out.println(tmp[1]);\n            }\n        }\n        close();\n    }\n  \n    static StringTokenizer st;\n    static StreamTokenizer strTok;\n    static BufferedReader in;\n    static PrintWriter out;\n \n    static String nextToken(boolean f) throws IOException {\n        if (f) {\n            return in.readLine();\n        } else {\n            while (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(in.readLine());\n            }\n            return st.nextToken();\n        }\n    }\n \n    static String nextLine() throws IOException {\n        return nextToken(true);\n    }\n \n    static int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken(false));\n    }\n \n    static long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken(false));\n    }\n \n    static double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken(false));\n    }\n \n    static char nextChar() throws IOException {\n        return ((char)in.read());\n    }\n \n    static void close(){\n        out.flush();\n        out.close();\n    }\n \n    static void open(String filein, String fileout, boolean flag, boolean console) throws IOException{\n        if (flag) {\n            strTok = new StreamTokenizer(new FileReader (new File(filein)));\n            in = new BufferedReader(new FileReader (new File(filein)));\n            out = new PrintWriter(new FileWriter(new File (fileout)));\n        } else {\n            if (console){\n                strTok = new StreamTokenizer(new InputStreamReader (System.in, \"ISO-8859-1\"));\n                in = new BufferedReader (new InputStreamReader (System.in, \"ISO-8859-1\"));\n                out = new PrintWriter (new OutputStreamWriter (System.out, \"ISO-8859-1\"));\n            } else {\n                strTok = new StreamTokenizer(new FileReader (new File(\"input.txt\")));\n                in = new BufferedReader(new FileReader (new File(\"input.txt\")));\n                out = new PrintWriter(new FileWriter(new File (\"output.txt\")));\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\t\tint nc = sc.nextInt();\n\t\twhile (nc-- > 0) {\n\t\t\tString s = sc.next();\n\t\t\tStringTokenizer st = new StringTokenizer(s, \"0123456789\");\n\t\t\tif (st.countTokens() > 1) {\n\t\t\t\tint k = s.indexOf('C');\n\t\t\t\tint r = Integer.parseInt(s.substring(1, k));\n\t\t\t\tint c = Integer.parseInt(s.substring(k + 1));\n\t\t\t\tint len = 1;\n\t\t\t\tint p = 26;\n\t\t\t\twhile (c > p) {\n\t\t\t\t\tc -= p;\n\t\t\t\t\tlen++;\n\t\t\t\t\tp *= 26;\n\t\t\t\t}\n\t\t\t\tString col = Integer.toString(--c, 26).toUpperCase();\n\t\t\t\twhile (col.length() < len)\n\t\t\t\t\tcol = \"0\" + col;\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor (int i = 0; i < col.length(); i++) {\n\t\t\t\t\tif (col.charAt(i) < 'A') {\n\t\t\t\t\t\tsb.append((char) (col.charAt(i) - '0' + 'A'));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsb.append((char) (col.charAt(i) + 10));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.printf(\"%s%d\\n\", sb.toString(), r);\n\t\t\t} else {\n\t\t\t\tint k = 0;\n\t\t\t\twhile (s.charAt(k) > '9')\n\t\t\t\t\tk++;\n\t\t\t\tchar[] col = s.substring(0, k).toCharArray();\n\t\t\t\tint r = Integer.parseInt(s.substring(k));\n\t\t\t\tint c = 1;\n\t\t\t\tint p = 26;\n\t\t\t\tint cnt = 1;\n\t\t\t\twhile (cnt++ < col.length) {\n\t\t\t\t\tc += p;\n\t\t\t\t\tp *= 26;\n\t\t\t\t}\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor (int i = 0; i < col.length; i++) {\n\t\t\t\t\tif (s.charAt(i) < 'K') {\n\t\t\t\t\t\tsb.append((char) ('0' + col[i] - 'A'));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsb.append((char) (col[i] - 10));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tc += Integer.parseInt(sb.toString(), 26);\n\t\t\t\tSystem.out.printf(\"R%dC%d\\n\", r, c);\n\t\t\t}\n\t\t}\n\t\tSystem.out.close();\n\t}\n\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "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\n\tint MAXDEG = 5;\n\n\tvoid gen() throws FileNotFoundException {\n\t\tPrintWriter out = new PrintWriter(\"input.txt\");\n\t\tint n = 100000;\n\t\tRandom rnd = new Random();\n\t\tout.println(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tout.println(\"R\" + (rnd.nextInt(1000000) + 1) + \"C\" + (rnd.nextInt(1000000) + 1));\n\t\t}\n\t\tout.close();\n\t}\n\n\tvoid gen2() throws FileNotFoundException {\n\t\tPrintWriter out = new PrintWriter(\"input.txt\");\n\t\tint n = 100000;\n\t\tRandom rnd = new Random();\n\t\tout.println(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint len = rnd.nextInt(MAXDEG) + 1;\n\t\t\tString pref = \"\";\n\t\t\tfor (int j = 0; j < len; j++)\n\t\t\t\tpref += (char) (rnd.nextInt(26) + 'A');\n\t\t\tout.println(pref + (rnd.nextInt(1000000) + 1));\n\t\t}\n\t\tout.close();\n\t}\n\n\tprivate void run() throws IOException {\n//\t\tgen2();\n//\t\tif (true) return;\n//\t\tSystem.setOut(new PrintStream(\"output.txt\"));\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tint n = nextInt();\n\t\tint[] sumDegs = new int[MAXDEG + 1];\n\t\tsumDegs[0] = 1;\n\t\tint deg = 1;\n\t\tfor (int i = 1; i <= MAXDEG; i++) {\n\t\t\tdeg *= 26;\n\t\t\tsumDegs[i] = sumDegs[i - 1] + deg;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = nextLine();\n\t\t\tString pref = \"\";\n\t\t\tint endPos = -1;\n\t\t\tfor (int j = 0; j < s.length(); j++) {\n\t\t\t\tif (!isLet(s.charAt(j))) {\n\t\t\t\t\tendPos = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tpref += s.charAt(j);\n\t\t\t}\n\t\t\tint num = -1;\n\t\t\ttry {\n\t\t\t\tnum = Integer.parseInt(s.substring(endPos));\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\t\tif (num != -1) {\n\t\t\t\tint col = sumDegs[pref.length() - 1];\n\t\t\t\tint val = 0;\n\t\t\t\tfor (int j = 0; j < pref.length(); j++) {\n\t\t\t\t\tval = val * 26 + (pref.charAt(j) - 'A');\n\t\t\t\t}\n\t\t\t\tcol += val;\n\t\t\t\tout.println(\"R\" + num + \"C\" + col);\n\t\t\t} else {\n\t\t\t\tint row = Integer.parseInt(s.substring(1, s.indexOf('C')));\n\t\t\t\tint col = Integer.parseInt(s.substring(s.indexOf('C') + 1));\n\t\t\t\tint len = MAXDEG;\n\t\t\t\twhile (col < sumDegs[len])\n\t\t\t\t\tlen--;\n\t\t\t\tlen++;\n\t\t\t\tcol -= sumDegs[len - 1];\n\t\t\t\tString res = \"\";\n\t\t\t\twhile (col > 0) {\n\t\t\t\t\tres = (char) (col % 26 + 'A') + res;\n\t\t\t\t\tcol /= 26;\n\t\t\t\t}\n\t\t\t\twhile (res.length() < len)\n\t\t\t\t\tres = \"A\" + res;\n\t\t\t\tout.println(res + row);\n\t\t\t}\n\t\t}\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tprivate boolean isLet(char c) {\n\t\treturn c >= 'A' && c <= 'Z';\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", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\n\npublic class SpreadSheet {\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tScanner s = new Scanner(System.in);\n\t\t\tint tests = s.nextInt();\n\t\t\tfor (int i = 0; i < tests; i++) {\n\t\t\t\tString line = s.next();\n\t\t\t\tString regex = \"R[\\\\d]+C[\\\\d]+\";\n\t\t\t\tPattern pattern = Pattern.compile(regex);\n\t\t\t\tMatcher matcher = pattern.matcher(line);\n\t\t\t\t\n\t\t\t\tif (matcher.matches()){\n\t\t\t\t\tint r = Integer.parseInt(line.substring(1, line.indexOf(\"C\")));\n\t\t\t\t\tint c = Integer.parseInt(line.substring(line.indexOf(\"C\") +1));\n\t\t\t\t\tSystem.out.println(toFormula(r, c));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tint index = -1;\n\t\t\t\t\tfor (int j = 0; j < line.length(); j++) {\n\t\t\t\t\t\tif (line.charAt(j) >= '0' && line.charAt(j) <= '9') {\n\t\t\t\t\t\t\tindex = j;\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\tString c = line.substring(0, index);\n\t\t\t\t\tint r = Integer.parseInt(line.substring(index));\n\t\t\t\t\tSystem.out.println(fromFormula(c, r));\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t\n\tprivate String toFormula(int r, int c) {\n\t\t StringBuffer buff = new StringBuffer();\n               char ch;\n               while (c != 0) {\n                       int m = c%26;\n                       if(m==0)\n                       {\n                               ch = 'Z';\n                               c = c/26 - 1;\n                       }\n                       else\n                        {\n                               ch = (char)(m+'A'-1);\n                               c /= 26;\n                       }\n                       buff.append(ch);                        \n               }\n               return buff.reverse().toString() + r;\n\t\n\t\n//\t\tString ret = \"\";\n//\t\tStringBuffer buff = new StringBuffer();\n//\t\twhile (c != 0) {\n//\t\t\tint m = c%26;\n//\t\t\tchar ch = (char)(m+'A'-1);\n//\t\t\tbuff.append(ch);\n//\t\t\tc /= 26;\n//\t\t}\n//\t\treturn buff.reverse().toString() + r;\n\t}\n\t\n\tprivate String fromFormula(String c, int r) {\n\t\tint ret = 0;\n\t\tint power = 1;\n\t\tfor (int i = c.length()-1; i >= 0; i--) {\n\t\t\tret += ((c.charAt(i) - 'A' + 1) * power);\n\t\t\tpower *= 26;\n\t\t}\n\t\treturn \"R\" + r + \"C\" + ret;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew SpreadSheet().run();\n\t}\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Problem solution template.\n * @author Andrew Porokhin, andrew.porokhin@gmail.com\n */\npublic class Problem01B implements Runnable {\n    static final long[] x10 = new long[] { 1, 26, 26*26, 26*26*26, 26*26*26*26, 26*26*26*26*26, 26*26*26*26*26*26}; \n    void solve() throws NumberFormatException, IOException {\n        // TODO: Write your code here ...\n        int n = nextInt();\n        for (int i = 0; i < n; i++) {\n            String t = nextToken().toUpperCase();\n            StringBuffer rowString = new StringBuffer(t.length());\n            StringBuffer numb1 = new StringBuffer(t.length());\n            StringBuffer numb2 = new StringBuffer(t.length());\n            int stage = 0;\n            for (int j = 0; j < t.length(); j++) {;\n                char charAt = t.charAt(j);\n                if (charAt >= 'A') {\n                    if (stage == 0) { \n                        rowString.append(charAt);\n                    } else {\n                        stage++;\n                    }\n                } else {\n                    if (stage == 0 || stage == 2) \n                        stage++;\n                    switch (stage) {\n                    case 1: numb1.append(charAt); break;\n                    case 3: numb2.append(charAt); break;\n                    }\n                }\n            }\n            \n            if (stage == 1) {\n                long result = convertString(rowString);\n                System.out.print(\"R\");\n                System.out.print(numb1.toString());\n                System.out.print(\"C\");\n                System.out.println(result);\n            } else {\n                StringBuffer tmp = convertNumber(Long.parseLong(numb2.toString()));\n                System.out.print(tmp.toString());\n                System.out.println(numb1.toString());\n            }\n        }\n    }\n    \n    public StringBuffer convertNumber(long n) {\n        StringBuffer sb2 = new StringBuffer();\n        long nmod26 = n % 26;\n        long ndiv26 = n / 26;\n        while (ndiv26 > 0 || nmod26 > 0) {\n            long tmp = 0;\n            if (nmod26 > 0) {\n                sb2.append((char) ('A' + nmod26 - 1));\n                tmp = ndiv26;\n            } else {\n                sb2.append('Z');\n                tmp = ndiv26 - 1;\n            }\n            nmod26 = tmp % 26;\n            ndiv26 = tmp / 26;\n        }\n        \n        return sb2.reverse();\n    }\n    \n    public long convertString(StringBuffer sb) {\n        long result = 0;\n        for (int i = 0; i < sb.length(); i++) {\n            long l = (sb.charAt(i) - 'A' + 1) * x10[sb.length() - i - 1];\n            result += l;\n        }\n        return result;\n    }\n    \n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n    \n    public static void main(String[] args) {\n        new Problem01B().run();\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n            solve();\n        } catch (Exception e) {\n            System.exit(9000);\n        } finally {\n            out.flush();\n            out.close();\n        }\n    }\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    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n}\n", "complexity": "linear", "problem": "1_B. Spreadsheets", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\npublic class TaxiDriversAndLyft2 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tlong n = scanner.nextLong();\n\t\tlong m = scanner.nextLong();\n\t\tlong[] people = new long[(int) (n+m)];\n\t\tint[] taxiDrivers = new int[(int) (n+m)];\n\t\t\n\t\tfor(int i = 0;i< (n+m); i++) {\n\t\t\tpeople[i] = scanner.nextLong();\n\t\t}\n\t\t\n\t\tfor(int i = 0;i< (n+m); i++) {\n\t\t\ttaxiDrivers[i] = scanner.nextInt();\n\t\t}\n\t\t\n\t\tint lastTaxiDriverIndex = -1;\n\t\tlong[] riderCountArray = new long[(int) (m)];\n\t\tlong[] a1 = new long[(int)n];\n\t\tlong[] b1 = new long[(int)m];\n\t\t\n\t\tint j=0, k=0;\n\t\tfor(int i = 0;i< (n+m); i++) {\t\n\t\t\tif(taxiDrivers[i] == 0) {\n\t\t\t\ta1[j] = people[i];\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse  {\n\t\t\t\tb1[k] = people[i];\n\t\t\t\tk++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint l = 0, q=0;\n\t\tfor(int i=0;i<j;i++) {\n\t\t\twhile ((l<m-1 && m>1) && Math.abs(a1[i] - b1[l]) > Math.abs(a1[i] - b1[l+1])) {\n\t\t\t\tl++; \n\t\t\t}\n\t\t\t\n\t\t\triderCountArray[l]++;\t\n\t\t}\n\t\t\n\t\tfor(int i = 0;i< (m); i++) {\n\t\t\tSystem.out.print(riderCountArray[i]+\" \");\n\t\t}\n\t} \n}\n", "complexity": "linear", "problem": "1075_B. Taxi drivers and Lyft", "from": "CODEFORCES"}
{"src": "\nimport 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[] P = new int[n];\n        int[] check=new int[n];\n        for (int i = 1; i < n; i++) {\n\n            P[i] = scanner.nextInt();\n            P[i]--;\n            check[P[i]]++;\n        }\n        int[] leaves = new int[n];\n\n\n        for (int i=0;i<n;i++) {\n            if(check[i]==0){\n                leaves[P[i]]++;\n            }\n        }\n\n\n        for (int i = 0; i < n; i++) {\n\n            if (check[i]>0&&leaves[i]<3) {\n                System.out.println(\"No\");\n                return;\n            }\n        }\n        System.out.println(\"Yes\");\n    }\n}\n", "complexity": "linear", "problem": "913_B. Christmas Spruce", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        HashSet<Integer> set = new HashSet<>();\n        for(int i = 0; i<n; i++){\n            int a = sc.nextInt();\n            if(a!=0){\n                set.add(a);\n            }\n        }\n        System.out.println(set.size());\n    }\n}", "complexity": "linear", "problem": "992_A. Nastya and an Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main{\npublic static void main(String[] args){\n Scanner s= new Scanner(System.in);\n int n=s.nextInt();StringBuilder sb=new StringBuilder();\n long[] a=new long[n/2];\n for(int i=0;i<n/2;i++){\n                  a[i]=s.nextLong();\n }int j=0;long[] a2=new long[n/2];long[] a1=new long[n/2];\n a1[j]=a[a.length-1]/2;\n a2[j]=a[a.length-1]-a[a.length-1]/2;\n for(int i=(n-1)/2-1;i>=0;i--){\n //    a1[j]=a[i]/2;a2[j++]=a[i]-a[i]/2;\n    long n1=a1[j];\n    if((a[i]-n1)<a2[j]){\n      a2[j+1]=a2[j++];a1[j]=a[i]-a2[j];                      \n     }else{a1[++j]=n1;a2[j]=a[i]-n1;}\n }int k=0;//int[] ans=new int[2*n];\n for(int i=(n-1)/2;i>=0;i--)\n   sb.append(a1[i]+\" \");\n  for(int i=0;i<n/2;i++)\n    sb.append(a2[i]+\" \");\n            System.out.println(sb.toString());     \n}\n}", "complexity": "linear", "problem": "1093_C. Mishka and the Last Exam", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\npublic class alex\n{\n    public static void main(String[] args)throws IOException\n    {\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();int sum=1;\n        for(int i=1;i<=n;i++)\n        {\n            sum=sum+(4*(i-1));\n        }\n        System.out.println(sum);\n    }\n}", "complexity": "linear", "problem": "1180_A. Alex and a Rhombus", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\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    int m = in.nextInt();\n    long boyMax = 0;\n    int NBoyMax = 0;\n\n    long sweets = 0;\n    TreeSet<Long> boyMember = new TreeSet<>();\n    for (int i = 0; i < n; i++) {\n      long input = in.nextLong();\n      boyMember.add(input);\n      if (boyMax < input) {\n        boyMax = input;\n        NBoyMax = 1;\n      } else if (boyMax == input) NBoyMax++;\n      sweets += (input * m);\n    }\n\n    long smallestGirl = (long) 1e8 + 1;\n    long sum = 0;\n    for (int i = 0; i < m; i++) {\n      long input = in.nextLong();\n      sum += input;\n      if (smallestGirl > input) smallestGirl = input;\n    }\n\n    if (smallestGirl < boyMember.last()) {\n      out.println(-1);\n    } else if (smallestGirl == boyMember.last()) {\n      sweets += sum - boyMember.last() * m;\n      out.println(sweets);\n    } else {\n\n      if (NBoyMax > 1) {\n        sweets += sum - boyMember.last() * m;\n        out.println(sweets);\n      } else {\n        Object[] boyList = boyMember.toArray();\n        if (boyList.length > 1) {\n          long boy = 0;\n          boy = (long)boyList[boyList.length - 2];\n          sweets += (sum - smallestGirl - boyMember.last() * (m - 1));\n          sweets += (smallestGirl - boy);\n          out.println(sweets);\n        } else {\n          out.println(-1);\n        }\n      }\n    }\n\n    in.close();\n    out.close();\n  }\n}", "complexity": "linear", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class Main {\n\tstatic Scanner sc = new Scanner (System.in);\n    public static void main(String[] args) {\n    \tint n = sc.nextInt();\n    \tint k = sc.nextInt();\n    \tchar str[][] = new char[5][n];\n        for(int i = 0;i < 4;i ++){\n        \tfor(int j = 0;j < n;j ++)\n                str[i][j] = '.';\n        }\n        if(k % 2 == 0){\n            k /= 2;\n            for(int i = 1;i <= 2;i++){\n                for(int j = 1;j <= k;j++)\n                     str[i][j] = '#'; \n            }\n        }\n        else{\n            str[1][n / 2] = '#';\n            if(k != 1){\n                int tmp = n / 2;\n                if(k <= n - 2){\n                    for(int i = 1;i<= (k - 1) / 2;i++){\n                        str[1][i] = '#';\n                        str[1][n - 1 - i] = '#';\n                    }\n                }\n                else{\n                    for(int i = 1;i <= n - 2;i++) str[1][i] = '#';\n                    k -= n - 2;\n                    for(int i = 1;i <= k/2;i++){\n                        str[2][i] = '#';\n                        str[2][n - 1 - i]='#';\n                    }\n                }\n     \n            }\n        }\n        System.out.println(\"YES\");\n        for(int i = 0;i < 4;i ++){\n        \tSystem.out.println(str[i]);\n        }\n    }\n }", "complexity": "linear", "problem": "980_B. Marlin", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\n\npublic class First {\n    StreamTokenizer in;\n    PrintWriter out;\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\n\n    void run() throws IOException {\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n    }\n\n    void solve() throws IOException {\n        int n = nextInt(), k = nextInt(), sum = 0, count = 0;\n        String str = nextString();\n        char[] arr = str.toCharArray();\n        boolean[] bool = new boolean[26];\n        for(char ch: arr){\n            bool[((int)ch)-97] = true;\n        }\n        for(int i = 0; i < 26; i++){\n            if(bool[i]){\n                sum += i+1;\n                count++;\n                i += 1;\n            }\n            if(count == k) break;\n        }\n        if(count == k) out.println(sum);\n        else out.println(-1);\n    }\n\n    public static void main(String[] args) throws IOException {\n        new First().run();\n    }\n}", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\n\npublic class First {\n    StreamTokenizer in;\n    PrintWriter out;\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\n\n    void run() throws IOException {\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n    }\n\n    void solve() throws IOException {\n        int n = nextInt(), k = nextInt(), sum = 0, count = 0;\n        String str = nextString();\n        char[] arr = str.toCharArray();\n        boolean[] bool = new boolean[26];\n        for(char ch: arr){\n            bool[((int)ch)-97] = true;\n        }\n        for(int i = 0; i < 26; i++){\n            if(bool[i]){\n                sum += i+1;\n                count++;\n                i += 1;\n            }\n            if(count == k) break;\n        }\n        if(count == k) out.println(sum);\n        else out.println(-1);\n    }\n\n    public static void main(String[] args) throws IOException {\n        new First().run();\n    }\n}", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.*;\npublic class Solution\n{\n    public static void main(String [] args) throws IOException\n    {\n        PrintWriter pw=new PrintWriter(System.out);//use pw.println() not pw.write();\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(br.readLine());\n        /*\n        inputCopy\n5 3\nxyabd\noutputCopy\n29\ninputCopy\n7 4\nproblem\noutputCopy\n34\ninputCopy\n2 2\nab\noutputCopy\n-1\ninputCopy\n12 1\nabaabbaaabbb\noutputCopy\n1\n        */\n        int n=Integer.parseInt(st.nextToken());\n        int k=Integer.parseInt(st.nextToken());\n        st=new StringTokenizer(br.readLine());\n        String str=st.nextToken();\n        char [] arr=str.toCharArray();\n        Arrays.sort(arr);\n        int weight=arr[0]-96;\n        char a=arr[0];\n        int included=1;\n        for(int i=1;i<arr.length;++i)\n        {\n            if(included==k)\n                break;\n            char c=arr[i];\n            if(c-a<2)\n                continue;\n           \n            weight+=arr[i]-96;\n            ++included;\n            a=arr[i];\n            \n        }\n        if(included==k)\n            pw.println(weight);\n        else\n            pw.println(-1);\n        pw.close();//Do not forget to write it after every program return statement !!\n    }\n}\n/*\n\u2192Judgement Protocol\nTest: #1, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n5 3\nxyabd\nOutput\n29\nAnswer\n29\nChecker Log\nok 1 number(s): \"29\"\nTest: #2, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n7 4\nproblem\nOutput\n34\nAnswer\n34\nChecker Log\nok 1 number(s): \"34\"\nTest: #3, time: 139 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nab\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #4, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 1\nabaabbaaabbb\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #5, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #6, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #7, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\na\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #8, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #9, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #10, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nuwgmkyqeiaocs\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #11, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nhzdxpbfvrltnj\nOutput\n182\nAnswer\n182\nChecker Log\nok 1 number(s): \"182\"\nTest: #12, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nn\nOutput\n14\nAnswer\n14\nChecker Log\nok 1 number(s): \"14\"\nTest: #13, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 8\nsmzeblyjqw\nOutput\n113\nAnswer\n113\nChecker Log\nok 1 number(s): \"113\"\nTest: #14, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n20 20\ntzmvhskkyugkuuxpvtbh\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #15, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #16, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #17, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #18, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 7\niuiukrxcml\nOutput\n99\nAnswer\n99\nChecker Log\nok 1 number(s): \"99\"\nTest: #19, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #20, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 6\nfwseyrarkwcd\nOutput\n61\nAnswer\n61\nChecker Log\nok 1 number(s): \"61\"\nTest: #21, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nac\nOutput\n4\nAnswer\n4\nChecker Log\nok 1 number(s): \"4\"\nTest: #22, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nc\nOutput\n3\nAnswer\n3\nChecker Log\nok 1 number(s): \"3\"\nTest: #23, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nad\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #24, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER\nInput\n2 1\nac\nOutput\n-1\nAnswer\n1\nChecker Log\nwrong answer 1st number\n*/", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.*;\npublic class Solution\n{\n    public static void main(String [] args) throws IOException\n    {\n        PrintWriter pw=new PrintWriter(System.out);//use pw.println() not pw.write();\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(br.readLine());\n        /*\n        inputCopy\n5 3\nxyabd\noutputCopy\n29\ninputCopy\n7 4\nproblem\noutputCopy\n34\ninputCopy\n2 2\nab\noutputCopy\n-1\ninputCopy\n12 1\nabaabbaaabbb\noutputCopy\n1\n        */\n        int n=Integer.parseInt(st.nextToken());\n        int k=Integer.parseInt(st.nextToken());\n        st=new StringTokenizer(br.readLine());\n        String str=st.nextToken();\n        char [] arr=str.toCharArray();\n        Arrays.sort(arr);\n        int weight=arr[0]-96;\n        char a=arr[0];\n        int included=1;\n        for(int i=1;i<arr.length;++i)\n        {\n            if(included==k)\n                break;\n            char c=arr[i];\n            if(c-a<2)\n                continue;\n           \n            weight+=arr[i]-96;\n            ++included;\n            a=arr[i];\n            \n        }\n        if(included==k)\n            pw.println(weight);\n        else\n            pw.println(-1);\n        pw.close();//Do not forget to write it after every program return statement !!\n    }\n}\n/*\n\u2192Judgement Protocol\nTest: #1, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n5 3\nxyabd\nOutput\n29\nAnswer\n29\nChecker Log\nok 1 number(s): \"29\"\nTest: #2, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n7 4\nproblem\nOutput\n34\nAnswer\n34\nChecker Log\nok 1 number(s): \"34\"\nTest: #3, time: 139 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nab\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #4, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 1\nabaabbaaabbb\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #5, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #6, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #7, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\na\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #8, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n1\nAnswer\n1\nChecker Log\nok 1 number(s): \"1\"\nTest: #9, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #10, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nuwgmkyqeiaocs\nOutput\n169\nAnswer\n169\nChecker Log\nok 1 number(s): \"169\"\nTest: #11, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n13 13\nhzdxpbfvrltnj\nOutput\n182\nAnswer\n182\nChecker Log\nok 1 number(s): \"182\"\nTest: #12, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nn\nOutput\n14\nAnswer\n14\nChecker Log\nok 1 number(s): \"14\"\nTest: #13, time: 92 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 8\nsmzeblyjqw\nOutput\n113\nAnswer\n113\nChecker Log\nok 1 number(s): \"113\"\nTest: #14, time: 78 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n20 20\ntzmvhskkyugkuuxpvtbh\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #15, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #16, time: 93 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #17, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\nOutput\n-1\nAnswer\n-1\nChecker Log\nok 1 number(s): \"-1\"\nTest: #18, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n10 7\niuiukrxcml\nOutput\n99\nAnswer\n99\nChecker Log\nok 1 number(s): \"99\"\nTest: #19, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #20, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n12 6\nfwseyrarkwcd\nOutput\n61\nAnswer\n61\nChecker Log\nok 1 number(s): \"61\"\nTest: #21, time: 109 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nac\nOutput\n4\nAnswer\n4\nChecker Log\nok 1 number(s): \"4\"\nTest: #22, time: 108 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n1 1\nc\nOutput\n3\nAnswer\n3\nChecker Log\nok 1 number(s): \"3\"\nTest: #23, time: 124 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK\nInput\n2 2\nad\nOutput\n5\nAnswer\n5\nChecker Log\nok 1 number(s): \"5\"\nTest: #24, time: 77 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER\nInput\n2 1\nac\nOutput\n-1\nAnswer\n1\nChecker Log\nwrong answer 1st number\n*/", "complexity": "linear", "problem": "1011_A. Stages", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.Scanner;\npublic class abc{\n    public static int check(StringBuilder s)\n    {\n    \tint countRemove=0;\n    \tif(!s.toString().contains(\"xxx\")) return countRemove;\n    \telse{\n    \t\t\n    \t\tfor(int i=1;i<s.length()-1;i++)\n    \t\t{\n    \t\t\tif(s.charAt(i-1)=='x' && s.charAt(i)=='x' && s.charAt(i+1)=='x')\n    \t\t\t{\n    \t\t\t\n    \t\t\t\tcountRemove++;\n    \t\t\t}\n    \t\t}\n    \t\treturn countRemove;\n    \t}\n    }\n   \n\tpublic static void main (String[] args) {\n\t\n\tScanner sc = new Scanner(System.in);\n\tint n = sc.nextInt();\n\t//sc= new Scanner(System.in);\n\tString s = sc.next();\n\tStringBuilder sb = new StringBuilder(\"\");\n\tsb.append(s);\n\t\n    System.out.println(check(sb));\n\t\n\t\n\t\n\t}\n}", "complexity": "linear", "problem": "978_B. File Name", "from": "CODEFORCES"}
{"src": "/**\n * Created by Aminul on 3/14/2019.\n */\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\nimport static java.lang.Math.max;\n\npublic class E_2 {\n    public static void main(String[] args) throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        int n = in.nextInt(), k = in.nextInt(), N = (int) 5e6 + 1;\n        int left = 0, right = 0;\n        int a[] = new int[n + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = in.nextInt();\n            if (a[i] == k) left++;\n        }\n        int f[] = new int[N + 1];\n        int ans = 0;\n        for (int i = n; i >= 1; i--) {\n            if (a[i] == k) left--;\n            f[a[i]]++;\n            f[a[i]] = max(f[a[i]], 1 + right);\n            ans = max(ans, f[a[i]] + left);\n            if (a[i] == k) right++;\n        }\n        pw.println(ans);\n        pw.close();\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n\n        public FastReader(InputStream is) {\n            this.is = is;\n        }\n\n        public 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        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = (num << 3) + (num << 1) + (b - '0');\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n    }\n}", "complexity": "linear", "problem": "1082_E. Increasing Frequency", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String args[]) {\n\t\tScanner in=new Scanner(System.in);\n\t\tString str=in.next();\n\t\tint cnt=0;\n\t\tfor(int i=0;i<str.length();++i) {\n\t\t\tif(str.charAt(i)=='1') {\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\tint i=0;\n\t\tfor(;i<str.length();++i) {\n\t\t\tif(str.charAt(i)=='0') {\n\t\t\t\tSystem.out.print(\"0\");\n\t\t\t}\n\t\t\telse if(str.charAt(i)=='2') {\n\t\t\t\twhile(cnt-->0) {//\n\t\t\t\t\tSystem.out.print(\"1\");\n\t\t\t\t}\n\t\t\t\tSystem.out.print(\"2\");\n\t\t\t}\n\t\t}\n\t\twhile(cnt-->0) {\n\t\t\tSystem.out.print(\"1\");\n\t\t}\n\t\tin.close();\n\t}\n}", "complexity": "linear", "problem": "1009_B. Minimum Ternary String", "from": "CODEFORCES"}
{"src": "/*\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.ArrayList;\nimport java.util.Scanner;\n\n/**\n *\n * @author Ahmed\n */\n\n\n\n\npublic class Watermelon {\n\n   static class Passengers {\n  \n     public int floor ;\n     public int time;\n     \n     \n     public Passengers( int floor  , int time){\n         this.floor =floor;\n         this.time =time;\n     }\n     \n}\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        \n        Scanner in = new Scanner(System.in);\n        \n        int x = in.nextInt() , y = in.nextInt();\n        \n        ArrayList<Passengers> list = new ArrayList<>();\n        \n        for(int i = 1 ; i <= x ; ++i){\n            list.add(new Passengers(in.nextInt(), in.nextInt()));\n        }\n        \n        int sum = 0 ;\n       for(int i = list.size() - 1 ; i >= 0 ; --i)\n       {\n          int s = y -  list.get(i).floor;\n          sum = sum + s ; \n          \n          if(sum < list.get(i).time)\n          {\n              sum = sum + ( list.get(i).time - sum);\n          }\n          \n          y = list.get(i).floor;\n       } \n        \n        \n       if( list.get(list.size() - 1).floor != 0){\n           sum = sum  + (list.get(0).floor);\n       }\n        System.out.println(sum);\n    }\n    \n}\n", "complexity": "linear", "problem": "608_A. Saitama Destroys Hotel", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class BOOL {\n    static char [][]ch;\n    static int n,m;\nprivate static FastReader in =new FastReader();\n    public static void main(String[] args) {\n    int n=in.nextInt();\n    int a[]=new int[1000002];\n    int dp[]=new int[1000002],ans=0;\n    for(int i=0;i<n;i++){a[in.nextInt()]=in.nextInt();}\n    dp[0]=a[0]==0?0:1;\n    for(int i=1;i<1000002;i++){\n    if(a[i]==0){dp[i]=dp[i-1];}\n    else{\n    if(a[i]>=i){dp[i]=1;}\n    else{\n    dp[i]=dp[i-a[i]-1]+1;\n    }}\n    if(dp[i]>=ans)ans=dp[i];\n    }\n        System.out.println(n-ans);\n    }}\nclass 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", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ChainReaction {\n\t\n\tpublic static void main(String [] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\tint num = kb.nextInt();\n\t\t\n\t\tint[] beacons = new int[1000002];\n\t\tfor (int i=0; i<num; i++) {\n\t\t\tbeacons[kb.nextInt()] = kb.nextInt();\n\t\t}\n\t\t\n\t\tint [] dp = new int[1000002];\n\t\tint max = 0;\n\t\tif (beacons[0] != 0)\n\t\t\tdp[0] = 1;\n\t\t\n\t\tfor (int i=1; i<dp.length; i++) {\n\t\t\tif (beacons[i] == 0) {\n\t\t\t\tdp[i] = dp[i-1];\n\t\t\t} else {\n\t\t\t\tint index = i-1-beacons[i];\n\t\t\t\tif (index<0)\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\telse\n\t\t\t\t\tdp[i] = 1 + dp[index];\n\t\t\t}\n\t\t\tmax = Math.max(max, dp[i]);\n\t\t\t//if (i<11)\n\t\t\t\t//System.out.println(i +\" is \"+dp[i]);\n\t\t}\n\t\t\n\t\tSystem.out.println(num-max);\n\t}\n\n}\n", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class codef8 {\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint num = sc.nextInt();\n\t\tint beacon[] = new int[1000001];\n\t\tint pos[] = new int[num];\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tint position = sc.nextInt();\n\t\t\tbeacon[position] = sc.nextInt();\n\t\t\tpos[i] = position;\n\t\t}\n\t\tint dp[] = new int[1000001];\n\t\tint max = 0;\n\t\tif (beacon[0] != 0)\n\t\t\tdp[0] = 1;\n\t\t\n\t\tfor (int i = 1; i <= 1000000; i++) {\n\t\t\tif (beacon[i] == 0) {\n\t\t\t\tdp[i] = dp[i-1];\n\t\t\t} \n\t\t\telse {\n\t\t\t\tint j = i - beacon[i] - 1;\n\t\t\t\tif (j < 0) {\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp[i] = dp[j] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, dp[i]);\n\t\t}\t\t\n\t\tSystem.out.println(num-max);\n\t}\n\n}\n", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class codef8 {\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint num = sc.nextInt();\n\t\tint beacon[] = new int[1000001];\n\t\tint pos[] = new int[num];\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tint position = sc.nextInt();\n\t\t\tbeacon[position] = sc.nextInt();\n\t\t\tpos[i] = position;\n\t\t}\n\t\tint dp[] = new int[1000001];\n\t\tint max = 1;\n\t\tif (beacon[0] != 0)\n\t\t\tdp[0] = 1;\n\t\t\n\t\tfor (int i = 1; i <= 1000000; i++) {\n\t\t\tif (beacon[i] == 0) {\n\t\t\t\tdp[i] = dp[i-1];\n\t\t\t} \n\t\t\telse {\n\t\t\t\tint j = i - beacon[i] - 1;\n\t\t\t\tif (j < 0) {\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp[i] = dp[j] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, dp[i]);\n\t\t}\t\t\n\t\tSystem.out.println(num-max);\n\t}\n\n}\n", "complexity": "linear", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tstatic boolean canWinFromOneMove(char []s,int k) {\n\t\tint prefix=0;\n\t\tint n=s.length;\n\t\tfor(int i=0;i<n && s[i]==s[0];i++)\n\t\t\tprefix++;\n\t\tint suffix=0;\n\t\tfor(int i=n-1;i>=0 && s[i]==s[n-1];i--)\n\t\t\tsuffix++;\n\t\t\n\t\treturn s[0]==s[n-1] && prefix+suffix+k>=n || Math.max(prefix, suffix)+k>=n;\n\t\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\tint n=sc.nextInt(),k=sc.nextInt();\n\t\tchar []s=sc.next().toCharArray();\n\t\tif(canWinFromOneMove(s, k)) {\n\t\t\tSystem.out.println(\"tokitsukaze\");\n\t\t\treturn;\n\t\t}\n\t\tint []suff=new int [n+1];\n\t\tsuff[n-1]=1;\n\t\tfor(int i=n-2;i>=0;i--) {\n\t\t\tsuff[i]=1+(s[i+1]==s[i]?suff[i+1]:0);\n\t\t}\n\t\tfor(int i=n-2;i>=0;i--)\n\t\t\tsuff[i]=Math.max(suff[i], suff[i+1]);\n\t\tint max=0,curr=0;\n\t\tboolean draw=false;\n\t\tint ones=0;\n\t\tfor(int i=0;i+k<=n;i++) {\n\t\t\t\n\t\t\t// one\n\t\t\tint prefix=ones==i?k+ones:max;\n\t\t\tint suffix=i+k==n?k:s[i+k]=='1' && suff[i+k]==n-(i+k)?k+suff[i+k]:suff[i+k];\n\t\t\tchar first=i==0?'1':s[0],last=i+k==n?'1':s[n-1];\n\t\t\tboolean zero=first==last && prefix+suffix+k>=n || Math.max(prefix, suffix)+k>=n;\n\t\t\t// zero\n\t\t\t prefix=ones==0?k+ones:max;\n\t\t\t suffix=i+k==n?k:s[i+k]=='0' && suff[i+k]==n-(i+k)?k+suff[i+k]:suff[i+k];\n\t\t\t first=i==0?'0':s[0];\n\t\t\t last=i+k==n?'0':s[n-1];\n\t\t\tboolean one=first==last && prefix+suffix+k>=n || Math.max(prefix, suffix)+k>=n;\n\t\t\tif(!zero || !one) {\n//\t\t\t\tSystem.err.println(i+1);\n\t\t\t\tdraw=true;\n\t\t\t}\n\t\t\tif(s[i]=='1')\n\t\t\t\tones++;\n\t\t\tif(i>0 && s[i]==s[i-1] )\n\t\t\t\tcurr++;\n\t\t\telse\n\t\t\t\tcurr=1;\n\t\t\tmax=Math.max(max, curr);\n\t\t}\n\t\tout.println(draw?\"once again\":\"quailty\");\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "linear", "problem": "1190_C. Tokitsukaze and Duel", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C{\n    static PrintWriter out;\n    static InputReader in;\n    public static void main(String args[]){\n        out = new PrintWriter(System.out);\n        in = new InputReader();\n        new C();\n        out.flush(); out.close();\n    }   \n    C(){\n       int a = solve();\n       out.print(a == 0 ? \"tokitsukaze\" : a == 1 ? \"quailty\" : \"once again\");\n    }\n    int n, k;\n    char ch[]; int a[], c0 = 0, c1 = 0;\n    TreeSet<Integer> ts[] = new TreeSet[2];\n    boolean check(){\n        int min = 0, max = n;\n        if(!ts[0].isEmpty()){\n            min = ts[0].first(); max = ts[0].last();\n            if(max - min + 1 > k)return true;\n        }\n        if(!ts[1].isEmpty()){\n            min = ts[1].first(); max = ts[1].last();\n            if(max - min + 1 > k)return true;   \n        }\n        return false;\n    }\n    int solve(){\n        n  = in.nextInt(); k = in.nextInt();\n        ch = in.next().trim().toCharArray(); a = new int[n];\n        for(int i = 0; i < n; i++)c1 += a[i] = ch[i] - '0';\n        c0 = n - c1;\n        for(int i = 0; i < k; i++){\n            if(a[i] == 0)c0--; else c1--;\n        }\n        if(c0 == 0 || c1 == 0)return 0;\n        for(int i = k; i < n; i++){\n            if(a[i] == 0)c0--; else c1--;\n            if(a[i - k] == 0)c0++; else c1++;\n            if(c0 == 0 || c1 == 0)return 0;\n        }\n\n        for(int i = 0; i < 2; i++)ts[i] = new TreeSet<>();\n        for(int i = 0; i < n; i++){\n            ts[a[i]].add(i);\n        }\n        for(int i = 0; i < k; i++){\n            ts[a[i]].remove(i);\n        }\n        if(check())return 2;\n        for(int i = k; i < n; i++){\n            ts[a[i]].remove(i); ts[a[i - k]].add(i - k);\n            if(check())return 2;\n        }\n        return 1;\n    }\n    public static class InputReader{\n        BufferedReader br;\n        StringTokenizer st;\n        InputReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\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        public String next(){\n            while(st == null || !st.hasMoreTokens()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch(IOException e){}\n            }\n            return st.nextToken();\n        }\n    }\n}\n        ", "complexity": "linear", "problem": "1190_C. Tokitsukaze and Duel", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.SortedSet;\nimport java.util.Set;\nimport java.util.NavigableSet;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\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        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, FastScanner in, FastPrinter out) {\n            int n = in.nextInt();\n            int k = in.nextInt();\n            char[] c = in.next().toCharArray();\n            NavigableSet<Integer> ones = new TreeSet<>();\n            NavigableSet<Integer> zeros = new TreeSet<>();\n            for (int i = 0; i < n; i++) {\n                if (c[i] == '0') zeros.add(i);\n                else ones.add(i);\n            }\n            if (ones.isEmpty() || zeros.isEmpty() || ones.last() - ones.first() + 1 <= k || zeros.last() - zeros.first() + 1 <= k) {\n                out.println(\"tokitsukaze\");\n                return;\n            }\n            if (check(ones, n, k) && check(zeros, n, k)) {\n                out.println(\"quailty\");\n                return;\n            }\n            out.println(\"once again\");\n        }\n\n        private boolean check(NavigableSet<Integer> ones, int n, int k) {\n            for (int i = 0; i + k <= n; i++) {\n                int left = ones.first();\n                int right = ones.last();\n                if (left >= i) {\n                    left = ones.higher(i + k - 1);\n                }\n                if (right < i + k) {\n                    right = ones.lower(i);\n                }\n                if (right - left + 1 > k) {\n                    return false;\n                }\n            }\n            return true;\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        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 String readLine() {\n            try {\n                return super.readLine();\n            } catch (IOException e) {\n                return null;\n            }\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "1190_C. Tokitsukaze and Duel", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n    public InputReader in;\n    public PrintWriter out;\n\n    public void solve() throws Exception {\n        // solution goes here\n        int N = in.nextInt();\n\n        int[] houses = new int[N];\n        boolean[] exist = new boolean[52];\n\n        for (int i = 0; i < N; i++) {\n            char c = in.nextChar();\n            if ('a' <= c && c <= 'z') {\n                houses[i] = 26 + (c - 'a');\n            } else {\n                houses[i] = (c - 'A');\n            }\n            exist[houses[i]] = true;\n        }\n\n        int[][] pokemons = new int[N][52];\n\n        pokemons[0][houses[0]] = 1;\n\n        for (int i = 1; i < N; i++) {\n            System.arraycopy(pokemons[i-1], 0, pokemons[i], 0, pokemons[i].length);\n            pokemons[i][houses[i]]++;\n        }\n\n        int uniques = 0;\n        for(boolean bool : exist)\n            if (bool)\n                uniques++;\n\n        if (uniques == 1) {\n            out.print(1);\n            return;\n        }\n\n\n        int last_variant = -1;\n        for (int i = 0; i < N-1; i++) {\n            if (pokemons[i][houses[i]] == pokemons[N-1][houses[i]]) {\n                last_variant = i;\n                break;\n            }\n        }\n\n        int minimum = N;\n\n        for (int i = 0; i <= last_variant; i++) {\n            if (houses[i] == houses[i+1])\n                continue;\n\n            // binary search\n\n            int low = i+1;\n            int high = N-1;\n\n            while (low < high) {\n                int mid = (low + high) / 2;\n\n                boolean allPresent = true;\n                for (int j = 0; j < 52; j++) {\n                    if (j != houses[i] && exist[j] && pokemons[mid][j] == pokemons[i][j]) {\n                        allPresent = false;\n                        break;\n                    }\n                }\n\n                if (allPresent) {\n                    high = mid; // infinite??\n                } else {\n                    low = mid + 1;\n                }\n            }\n\n            minimum = min(minimum, low - i + 1);\n\n        }\n\n        out.print(minimum);\n    }\n\n    public void run() {\n        try {\n            in = new InputReader(System.in);\n            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n            Locale.setDefault(Locale.US);\n            int tests = 1;\n            while (tests-- > 0) {\n                solve();\n            }\n            out.close();\n        } catch (Throwable e) {\n            e.printStackTrace();\n            System.exit(7);\n        }\n    }\n\n    static int abs(int x) {\n        return x < 0 ? -x : x;\n    }\n\n    static int max(int a, int b) {\n        return a > b ? a : b;\n    }\n\n    static int min(int a, int b) {\n        return a < b ? a : b;\n    }\n\n    static long abs(long x) {\n        return x < 0 ? -x : x;\n    }\n\n    static long max(long a, long b) {\n        return a > b ? a : b;\n    }\n\n    static long min(long a, long b) {\n        return a < b ? a : b;\n    }\n\n    public static void main(String args[]) {\n        new Thread(null, new Main(), \"Main\", 1 << 28).start();\n    }\n\n    static boolean OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    public void console(Object... objects) {\n        if (!OJ) {\n            out.println(Arrays.deepToString(objects));\n            out.flush();\n        }\n    }\n\n    @SuppressWarnings({\"Duplicates\", \"unused\"})\n    static class InputReader {\n\n        private InputStream stream;\n        private byte[] buf = new byte[2048];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n\n        public InputReader() {\n            this.stream = System.in;\n        }\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public InputReader(SpaceCharFilter filter) {\n            this.stream = System.in;\n            this.filter = filter;\n        }\n\n        public InputReader(InputStream stream, SpaceCharFilter filter) {\n            this.stream = stream;\n            this.filter = filter;\n        }\n\n        public int read() {\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 = read();\n            while (isSpaceChar(c))\n                c = read();\n            return (char) c;\n        }\n\n        public int nextDigit() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            return c - '0';\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? -res : res;\n        }\n\n        public int[] nextInts(int N) {\n            int[] nums = new int[N];\n            for (int i = 0; i < N; i++)\n                nums[i] = nextInt();\n            return nums;\n        }\n\n        public long[] nextLongs(int N) {\n            long[] nums = new long[N];\n            for (int i = 0; i < N; i++)\n                nums[i] = nextLong();\n            return nums;\n        }\n\n        public int nextUnsignedInt() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int res = 0;\n            do {\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res;\n        }\n\n        public final long nextLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? -res : res;\n        }\n\n        public final long nextUnsignedLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\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;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            long 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 (!(c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1 || c == '.'));\n\n            if (c != '.') {\n                return res * sgn;\n            }\n            c = read();\n\n            long aft = 0;\n            int len = 1;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                aft *= 10;\n                len *= 10;\n                aft += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n\n            return res * sgn + aft / (1.0 * len);\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 (!isEndChar(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 boolean isEndChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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 char[] nextChars() {\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\n            char[] chars = new char[res.length()];\n            res.getChars(0, chars.length, chars, 0);\n            return chars;\n        }\n\n        public int[][] nextIntMatrix(int rows, int cols) {\n            int[][] matrix = new int[rows][cols];\n            for (int i = 0; i < rows; i++)\n                for (int j = 0; j < cols; j++)\n                    matrix[i][j] = nextInt();\n            return matrix;\n        }\n\n        public long[][] nextLongMatrix(int rows, int cols) {\n            long[][] matrix = new long[rows][cols];\n            for (int i = 0; i < rows; i++)\n                for (int j = 0; j < cols; j++)\n                    matrix[i][j] = nextLong();\n            return matrix;\n        }\n\n        public char[][] nextCharMap(int rows, int cols) {\n            char[][] matrix = new char[rows][cols];\n            for (int i = 0; i < rows; i++)\n                for (int j = 0; j < cols; j++)\n                    matrix[i][j] = nextChar();\n            return matrix;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/*\n * And now I wonder if I should delete these comments cause they might throw me off. \n * Lol who cares though?\n */\n\npublic class R364C {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner s = new Scanner(System.in);\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n = Integer.parseInt(f.readLine());\n\t\tchar[] a = f.readLine().toCharArray();\n\t\tint difTypes = 0;\n\t\tTreeSet<Character> types = new TreeSet<Character>();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(!types.contains(a[i])) {\n\t\t\t\ttypes.add(a[i]);\n\t\t\t}\n\t\t}\n\t\tint i = 0, j = 0;\n\t\tdifTypes = types.size();\n\t\tint curTypes = 0;\n\t\tint min = Integer.MAX_VALUE;\n\t\tTreeSet<Character> has = new TreeSet<Character>();\n\t\tHashMap<Character, Integer> freq = new HashMap<Character, Integer>();\n\t\twhile(i < n && j < n) {\n//\t\t\tSystem.out.println(i + \" \" + j);\n\t\t\thas.add(a[j]);\n\t\t\tif(!freq.containsKey(a[j])) {\n\t\t\t\tfreq.put(a[j], 1);\n\t\t\t} else {\n\t\t\t\tfreq.put(a[j], freq.get(a[j])+1);\n\t\t\t}\n\t\t\tj++;\n\t\t\tcurTypes = has.size();\n\t\t\tif(curTypes == difTypes) min = Math.min(min, j-i);\n//\t\t\tSystem.out.println(freq.toString());\n//\t\t\tSystem.out.println(curTypes);\n//\t\t\tSystem.out.println();\n\t\t\twhile(i < n && has.size() == difTypes) {\n\t\t\t\tint Freq = freq.get(a[i]);\n//\t\t\t\tSystem.out.println(Freq);\n\t\t\t\tif(Freq - 1 == 0) {\n\t\t\t\t\thas.remove(a[i]);\n\t\t\t\t\tfreq.put(a[i], freq.get(a[i])-1);\n\t\t\t\t\ti++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfreq.put(a[i], freq.get(a[i])-1);\n\t\t\t\ti++;\n\t\t\t\tif(curTypes == difTypes) min = Math.min(min, j-i);\n\t\t\t}\n\t\t\tcurTypes = has.size();\n\t\t}\n//\t\tif(curTypes == difTypes) min = Math.min(min, j-i);\n\t\tSystem.out.println(min);\n\t}\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.lang.*;\n\npublic class Third{\n\tstatic long mod=1000000007;\n\t\n    public static void main(String[] args) throws Exception{           \t\n    \t InputReader in = new InputReader(System.in);       \n    \tPrintWriter pw=new PrintWriter(System.out);   \n    \t\n    \t\n    \t//int t=in.readInt();\n        //while(t-->0)\n        //{\n    \t\n        int n=in.readInt();\n    \t//long n=in.readLong();\n    \t/*int a[]=new int[n];\n    \tfor(int i=0;i<n;i++)\n    \t{\n    \t\ta[i]=in.readInt();\n    \t}*/\n    \tString a=in.readString();\n    \tchar c[]=a.toCharArray();\n    \tHashSet<Character>ht=new HashSet<Character>();\n    \tDeque<Character>q=new LinkedList<Character>();\n    \tHashSet<Character>hs=new HashSet<Character>();\n    \tHashMap<Character,Integer>hm=new HashMap<Character,Integer>();\n    \tfor(int i=0;i<n;i++)\n    \t{\n    \t\tht.add(c[i]);\n    \t}\n    \tint t=ht.size();\n    \tq.addLast(c[0]);\n    \ths.add(c[0]);\n    \thm.put(c[0],1);\n    \tint ans=Integer.MAX_VALUE;\n    \tif(hs.size()==t)\n\t\t{   \t\t\t\n\t\t\tans=min(ans,q.size());\n\t\t}\n    \t\n    \tfor(int i=1;i<n;i++)\n    \t{\n    \t\tq.addLast(c[i]);\n\t\t\ths.add(c[i]);\n\t\t\tif(hm.containsKey(c[i]))\n\t\t\t{\n\t\t\t\tint x=hm.get(c[i]);\n\t\t\t\thm.put(c[i],x+1);\n\t\t\t}\n\t\t\telse\n\t\t\t\thm.put(c[i],1);\n    \t\twhile(hs.size()==t)\n    \t\t{   \t\t\t\n    \t\t\tans=min(ans,q.size());\n    \t\t\tchar ch=q.peekFirst();\n    \t\t\tint x=hm.get(ch);\n    \t\t\tif(x==1)\n    \t\t\t\tbreak;\n    \t\t\telse\n    \t\t\t\t{\n    \t\t\t\thm.put(ch, x-1);\n    \t\t\t\tq.pollFirst();\n    \t\t\t\t}\n    \t\t\t\n    \t\t}\n    \t\t    \t\t\t\n    \t\t\n    \t}\n\t\tpw.println(ans);\t     \t\n    \t\n    \t//}\n    \t\n    \tpw.close();\n    }\n    \n\n\t\npublic static long gcd(long x,long y)\n{\n\tif(x%y==0)\n\t\treturn y;\n\telse\n\t\treturn gcd(y,x%y);\n}\npublic static int gcd(int x,int y)\n{\n\tif(x%y==0)\n\t\treturn y;\n\telse \n\t\treturn gcd(y,x%y);\n}\npublic static int abs(int a,int b)\n{\n\treturn (int)Math.abs(a-b);\n}\npublic static long abs(long a,long b)\n{\n\treturn (long)Math.abs(a-b);\n}\npublic static int max(int a,int b)\n{\n\tif(a>b)\n\t\treturn a;\n\telse\n\t\treturn b;\n}\npublic static int min(int a,int b)\n{\n\tif(a>b)\n\t\treturn b;\n\telse \n\t\treturn a;\n}\npublic static long max(long a,long b)\n{\n\tif(a>b)\n\t\treturn a;\n\telse\n\t\treturn b;\n}\npublic static long min(long a,long b)\n{\n\tif(a>b)\n\t\treturn b;\n\telse \n\t\treturn a;\n}\n\n\npublic static long pow(long n,long p,long m)\n{\n\t long  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    if(result>=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}\npublic 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;\t    \n\t    p >>=1;\n\t    n*=n;\t    \n\t}\n\treturn result;\n\n}\nstatic class Pair implements Comparable<Pair>\n{\n\tint a,b;\n\tPair (int a,int b)\n\t{\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t}\n\n\tpublic int compareTo(Pair o) {\n\t\t// TODO Auto-generated method stub\n\t\tif(this.a!=o.a)\n\t\treturn Integer.compare(this.a,o.a);\n\t\telse\n\t\t\treturn Integer.compare(this.b, o.b);\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.a == a && p.b == b;\n        }\n        return false;\n    }\n    public int hashCode() {\n        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();\n    }\n    \n} \n    \nstatic long sort(int a[])\n{  int n=a.length;\n\tint b[]=new int[n];\t\n\treturn mergeSort(a,b,0,n-1);}\nstatic long mergeSort(int a[],int b[],long left,long right)\n{ long c=0;if(left<right)\n {   long mid=left+(right-left)/2;\n\t c= mergeSort(a,b,left,mid);\n\t c+=mergeSort(a,b,mid+1,right);\n\t c+=merge(a,b,left,mid+1,right); }\t\n\treturn c;\t }\nstatic long merge(int a[],int  b[],long left,long mid,long right)\n{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;\nwhile(i<=(int)mid-1&&j<=(int)right)\n{ if(a[i]<=a[j]) {b[k++]=a[i++]; }\nelse\t{ b[k++]=a[j++];c+=mid-i;}}\nwhile (i <= (int)mid - 1)   b[k++] = a[i++]; \nwhile (j <= (int)right) b[k++] = a[j++];\nfor (i=(int)left; i <= (int)right; i++) \n\ta[i] = b[i];  return c;  }\n    \npublic static int[] radixSort(int[] f)\n{\n\tint[] to = new int[f.length];\n\t{\n\t\tint[] b = new int[65537];\n\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n\t\tint[] d = f; f = to;to = d;\n\t}\n\t{\n\t\tint[] b = new int[65537];\n\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n\t\tint[] d = f; f = to;to = d;\n\t}\n\treturn f;\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            if (curChar >= 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 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    }\n\n  \n//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t//StringBuilder sb=new StringBuilder(\"\");\n\t //InputReader in = new InputReader(System.in);\n\t//PrintWriter pw=new PrintWriter(System.out);\n\t//String line=br.readLine().trim();\n\t       \t\n\t//int t=Integer.parseInt(br.readLine());\n  //\twhile(t-->0)\n  \t//{\n  \t//int n=Integer.parseInt(br.readLine());\n\t//long n=Long.parseLong(br.readLine());\n\t//String l[]=br.readLine().split(\" \");\n  //int m=Integer.parseInt(l[0]);\n\t//int k=Integer.parseInt(l[1]);\n\t//String l[]=br.readLine().split(\" \");\n\t//l=br.readLine().split(\" \");\n\t/*int a[]=new int[n];\n\tfor(int i=0;i<n;i++)\n\t{\n\t\ta[i]=Integer.parseInt(l[i]);\n\t}*/\n\t   //System.out.println(\" \");\t     \t\n\t\n\t//}\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\n\npublic class C364 {\n\tstatic HashMap<Character, Integer> freq;\n\tstatic int unique = 0;\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner in = new FastScanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tint n = in.nextInt();\n\t\tchar[] s = in.next().toCharArray();\n\t\tfreq = new HashMap<Character, Integer>();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tchar c = s[i];\n\t\t\tif(!freq.containsKey(c))\n\t\t\t\tfreq.put(c, 0);\n\t\t}\n\t\t\n\t\tint k = freq.size();\n\t\tint l = 0, r = 0, best = n;\n\t\tinc(s[0]);\n\t\t\n\t\twhile(r < n) {\n\t\t\tif(unique == k) { // got all, move left\n\t\t\t\tbest = Math.min(best, r+1-l);\n\t\t\t\tdec(s[l++]);\n\t\t\t}\n\t\t\telse { // advance r\n\t\t\t\tif(++r == n)\n\t\t\t\t\tbreak;\n\t\t\t\tinc(s[r]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tpw.println(best);\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic void inc(char c) {\n\t\tint cur = freq.get(c);\n\t\tif(cur == 0)\n\t\t\tunique++;\n\t\tfreq.put(c, cur+1);\n\t}\n\t\n\tstatic void dec(char c) {\n\t\tint cur = freq.get(c);\n\t\tif(cur == 1)\n\t\t\tunique--;\n\t\tfreq.put(c, cur-1);\n\t}\n\n\tstatic class 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\t\n\t\tString next() throws Exception {\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() throws Exception {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n\tInputStream is;\n\n\tint __t__ = 1;\n\tint __f__ = 0;\n\tint __FILE_DEBUG_FLAG__ = __f__;\n\tString __DEBUG_FILE_NAME__ = \"src/C4\";\n\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint charToIndex(char c) {\n\t\tif (Character.isLowerCase(c))\n\t\t\treturn c - 'a';\n\t\telse if (Character.isUpperCase(c))\n\t\t\treturn c - 'A' + 26;\n\t\treturn -1;\n\t}\n\t\n\tint CH_NUM = 52;\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tString s = in.next();\n\t\t\n\t\tboolean[] exist = new boolean[CH_NUM];\n\t\tint typeNum = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint idx = charToIndex(s.charAt(i));\n\t\t\tif (!exist[idx]) {\n\t\t\t\texist[idx] = true;\n\t\t\t\ttypeNum++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint get = 0;\n\t\tint tail = 0, head = 0;\n\t\tint res = Integer.MAX_VALUE;\n\t\tint[] cnt = new int[CH_NUM];\n\t\twhile (tail < n || head < n) {\n\t\t\tif (head == n || typeNum == get) {\n\t\t\t\tint idx = charToIndex(s.charAt(tail++));\n\t\t\t\tif (cnt[idx] == 1) get--;\n\t\t\t\tcnt[idx]--;\n\t\t\t} else {\n\t\t\t\tint idx = charToIndex(s.charAt(head++));\n\t\t\t\tif (cnt[idx] == 0) get++; \n\t\t\t\tcnt[idx]++;\n\t\t\t}\n\t\t\tif (typeNum == get)\n\t\t\t\tres = Math.min(res, head - tail);\n\t\t}\n\t\tSystem.out.println(res);\n\t\t/*\n\t\tint[] currentRightMost = new int[CH_NUM];\n\t\tArrays.fill(currentRightMost, -1);\n\t\tint[][] next = new int[n+1][CH_NUM];\n\t\tfor (int i = 0; i < n + 1; i++) {\n\t\t\tArrays.fill(next[i], 1 << 30);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint idx = charToIndex(s.charAt(i));\n\t\t\tfor (int j = 0; j < CH_NUM; j++) if (exist[j]) {\n\t\t\t\tif (currentRightMost[j] != -1)\n\t\t\t\t\tnext[currentRightMost[j]][idx] = Math.min(next[currentRightMost[j]][idx], i);\n\t\t\t}\n\t\t\tcurrentRightMost[idx] = i;\n\t\t}\n\t\t\n\t\tint res = Integer.MAX_VALUE;\n\t\tfor (int leftMost = 0; leftMost < n; leftMost++) {\n\t\t\tint maxRightMost = 0;\n\t\t\tint idx = charToIndex(s.charAt(leftMost));\n\t\t\tfor (int j = 0; j < CH_NUM; j++) if (exist[j]) {\n\t\t\t\tif (j != idx)\n\t\t\t\t\tmaxRightMost = Math.max(maxRightMost, next[leftMost][j]);\n\t\t\t}\n\t\t\tres = Math.min(res, maxRightMost - leftMost + 1);\n\t\t}\n\t\tSystem.out.println(res);\n\t\t*/\n\t}\n\n\tpublic void run() {\n\t\tif (__FILE_DEBUG_FLAG__ == __t__) {\n\t\t\ttry {\n\t\t\t\tis = new FileInputStream(__DEBUG_FILE_NAME__);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO \u81ea\u52d5\u751f\u6210\u3055\u308c\u305f catch \u30d6\u30ed\u30c3\u30af\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\tSystem.out.println(\"FILE_INPUT!\");\n\t\t} else {\n\t\t\tis = System.in;\n\t\t}\n\t\tin = new FastScanner(is);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew C().run();\n\t}\n\n\tpublic void mapDebug(int[][] a) {\n\t\tSystem.out.println(\"--------map display---------\");\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < a[i].length; j++) {\n\t\t\t\tSystem.out.printf(\"%3d \", a[i][j]);\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\n\t\tSystem.out.println(\"----------------------------\");\n\t\tSystem.out.println();\n\t}\n\n\tpublic void debug(Object... obj) {\n\t\tSystem.out.println(Arrays.deepToString(obj));\n\t}\n\n\tclass 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\t//stream = new FileInputStream(new File(\"dec.in\"));\n\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\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tint[] nextIntArray(int n) {\n\t\t\treturn nextIntArray(n, 0);\n\t\t}\n\n\t\tint[] nextIntArray(int n, int margin) {\n\t\t\tint[] array = new int[n + margin];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarray[i + margin] = nextInt();\n\n\t\t\treturn array;\n\t\t}\n\n\t\tint[][] nextIntMap(int n, int m) {\n\t\t\tint[][] map = new int[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tmap[i] = in.nextIntArray(m);\n\t\t\t}\n\t\t\treturn map;\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\treturn nextLongArray(n, 0);\n\t\t}\n\n\t\tlong[] nextLongArray(int n, int margin) {\n\t\t\tlong[] array = new long[n + margin];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarray[i + margin] = nextLong();\n\n\t\t\treturn array;\n\t\t}\n\n\t\tlong[][] nextLongMap(int n, int m) {\n\t\t\tlong[][] map = new long[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tmap[i] = in.nextLongArray(m);\n\t\t\t}\n\t\t\treturn map;\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\treturn nextDoubleArray(n, 0);\n\t\t}\n\n\t\tdouble[] nextDoubleArray(int n, int margin) {\n\t\t\tdouble[] array = new double[n + margin];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarray[i + margin] = nextDouble();\n\n\t\t\treturn array;\n\t\t}\n\n\t\tdouble[][] nextDoubleMap(int n, int m) {\n\t\t\tdouble[][] map = new double[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tmap[i] = in.nextDoubleArray(m);\n\t\t\t}\n\t\t\treturn map;\n\t\t}\n\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\n\t\tString[] nextStringArray(int n) {\n\t\t\tString[] array = new String[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarray[i] = next();\n\n\t\t\treturn array;\n\t\t}\n\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}\n}\n\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "/**\n * Created by Omar on 7/22/2016.\n */\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CF364C {\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        int n=Integer.parseInt(br.readLine());\n        String input=br.readLine();\n        Set<Character> set = new HashSet<Character>();\n        for(int i=0;i<input.length();i++){\n            set.add(input.charAt(i));\n        }\n        StringBuilder sb= new StringBuilder();\nfor(char x:set){\n    sb.append(x);\n}\n        String substring1=sb.toString();\n//        //System.out.println(substring1);\n//        int[] count= new int[52];\n//        int[] b= new int[52];\n//\n//        char k;\n//        for(int i=0;i<substring1.length();i++){\n//            k=substring1.charAt(i);\n//            //System.out.println((int)'a');\n//            count[(k-'A')]++;\n//\n//        }\n//        for(int i=0;i<52;i++){\n//          b[i]=count[i];\n//\n//            //System.out.println(\"count \"+count[i]);\n//        }\n//        int answer=set.size();\n//\n//\n//        for(int i=0;i<input.length();i++){\n//\n//        }\n//        System.out.println(answer);\n//\n        //System.out.println(\"WAIT\");\n        System.out.println(solve(input,substring1).length());\n        pw.close();\n        br.close();\n    }\n    public static boolean isEmpty(int[] a){\n        for(int i=0;i<a.length;i++){\n            if(a[i]!=0){\n                return false;\n            }\n\n        }\n\nreturn true;\n    }\n    public static String solve(String S, String T) {\n        HashMap<Character, Integer> D = new HashMap<>();\n        HashMap<Character, Integer> GET = new HashMap<>();\n        int B,E;\n        for (int i=0; i<T.length();i++) {\n            char c=T.charAt(i);\n            if (!D.containsKey(c))\n            {\n                D.put(c, 1);\n            }\n            else\n            {\n                D.put(c, D.get(c) + 1);\n            }\n        }\n        int ccc = 0;\n       B=0; E=0;\n        int min = Integer.MAX_VALUE;\n        // int max = Integer.MIN_VALUE;\n\n        String RESULT = \"\";\n        while (E < S.length()) {\n\n            char c = S.charAt(E);\n\n            if (D.containsKey(c)) {\n\n                if (GET.containsKey(c)) {\n\n                    if (GET.get(c) < D.get(c))\n                        ccc++;\n                    //ccc--\n                    GET.put(c, GET.get(c) + 1);\n                } else {\n\n                    GET.put(c, 1);\n\n                    ccc++;\n                    //ccc--\n                }\n            }\n            if (ccc == T.length()) {\n               // if (ccc != B.length()) {\n                char test = S.charAt(B);\n                while (!GET.containsKey(test) ||\n                        GET.get(test) > D.get(test)) {\n\n                    if (GET.containsKey(test)\n                            && GET.get(test) >\n                            D.get(test))\n                       // GET.put(test, GET.get(test) - 24);\n\n                    GET.put(test, GET.get(test) - 1);\n                    //B-=B;\n                    B++;\n\n                    test = S.charAt(B);\n                    //test += S.charAt(B);\n\n                }\n                if (E - B + 1 < min) {\n                    RESULT = S.substring(B, E + 1);\n                    min = E - B + 1;\n                }\n                //}\n            }\n            E++;\n        }\n        //if(E==0)\n        return RESULT;\n    }\n\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.Set;\n\n/**\n * @author Ran Bi (ran.bi@addepar.com)\n */\npublic class C {\n\n  public static void main(String[] arg) throws IOException {\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    int n = Integer.valueOf(in.readLine());\n    char[] s = in.readLine().toCharArray();\n    int i = 0, j = 0;\n    int[] ct = new int[256];\n    Set<Character> all = new HashSet<>();\n    for (char c : s) {\n      all.add(c);\n    }\n    int total = 0, res = Integer.MAX_VALUE;\n    while (j < s.length) {\n      while (total < all.size() && j < s.length) {\n        if (ct[s[j]] == 0) {\n          total++;\n        }\n        ct[s[j]]++;\n        j++;\n      }\n      res = Math.min(res, j - i);\n      while (total == all.size() && i < s.length) {\n        ct[s[i]]--;\n        if (ct[s[i]] == 0) {\n          total--;\n        }\n        i++;\n        if (total == all.size()) {\n          res = Math.min(res, j - i);\n        }\n      }\n    }\n    System.out.println(res);\n  }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic final class round_364_c\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\tint n=sc.nextInt();char[] arr=sc.next().toCharArray();int[] sum=new int[123];int[][] pre=new int[123][n+1];\n\t\tchar[] a=new char[n+1];\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\ta[i]=arr[i-1];\n\t\t}\n\t\tboolean[] v=new boolean[123];\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tsum[a[i]]++;v[a[i]]=true;\n\t\t\tfor(int j=65;j<=90;j++)\n\t\t\t{\n\t\t\t\tpre[j][i]=sum[j];\n\t\t\t}\n\t\t\tfor(int j=97;j<=122;j++)\n\t\t\t{\n\t\t\t\tpre[j][i]=sum[j];\n\t\t\t}\n\t\t}\n\t\tlong min=Integer.MAX_VALUE;\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tint low=0,high=n-i+1;boolean got=false;\n\t\t\twhile(low<high)\n\t\t\t{\n\t\t\t\tint mid=(low+high)>>1;\n\t\t\t\tboolean curr=true;\n\t\t\t\tfor(int j=65;j<=90;j++)\n\t\t\t\t{\n\t\t\t\t\tif(v[j])\n\t\t\t\t\t{\n\t\t\t\t\t\tif(pre[j][i+mid]-pre[j][i-1]<=0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcurr=false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int j=97;j<=122;j++)\n\t\t\t\t{\n\t\t\t\t\tif(v[j])\n\t\t\t\t\t{\n\t\t\t\t\t\tif(pre[j][i+mid]-pre[j][i-1]<=0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcurr=false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(curr)\n\t\t\t\t{\n\t\t\t\t\tgot=true;\n\t\t\t\t\thigh=mid;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlow=mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(got)\n\t\t\t{\n\t\t\t\tmin=Math.min(min,(i+low)-i+1);\n\t\t\t}\n\t\t}\n\t\tout.println(min);\n\t\tout.close();\n\t}\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}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.Integer;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class Main {\n\n    final boolean ONLINE_JUDGE = !new File(\"input.txt\").exists();\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init() throws FileNotFoundException {\n        if (ONLINE_JUDGE) {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n        } else {\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\n        }\n    }\n\n    String readString() throws IOException {\n        while (!tok.hasMoreTokens()) {\n            tok = new StringTokenizer(in.readLine());\n        }\n        return tok.nextToken();\n    }\n\n    int readInt() throws IOException {\n        return Integer.parseInt(readString());\n    }\n\n    long readLong() throws IOException {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() throws IOException {\n        return Double.parseDouble(readString());\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n\n    public void run() {\n        try {\n            long t1 = System.currentTimeMillis();\n            init();\n            solve();\n            out.close();\n            long t2 = System.currentTimeMillis();\n            System.err.println(\"Time = \" + (t2 - t1));\n        } catch (Exception e) {\n            e.printStackTrace(System.err);\n            System.exit(-1);\n        }\n    }\n\n    class LOL implements Comparable<LOL> {\n        int x;\n        int y;\n\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            if (o.x != x)\n                return (int) (o.x - x); // ---->\n            return (int) (y - o.y); // <----\n        }\n\n    }\n\n    long modulo = 1000 * 1000 * 1000 + 7;\n    long binPow (long a, long b) {\n        if(b == 0) return 1;\n        long c = binPow(a, b / 2);\n        long ans = (c * c) % modulo;\n        if(b % 2 == 1) ans = (ans * a) % modulo;\n        return ans;\n    }\n\n\n\n    int[] gcd (int a, int b) {\n        int[] res = new int[3];\n        if (a == 0) {\n            res[0] = b; res[1] = 0; res[2] = -1;\n            return res;\n        }\n        res = gcd (b%a, a);\n        int x = -(res[2] + (b / a) * res[1]);\n        int y = - res[1];\n        res[1] = x;\n        res[2] = y;\n        return res;\n    }\n\n\n    public void solve() throws IOException {\n        int n = readInt();\n        HashMap<Character,Integer> mapa = new HashMap<>();\n\n        char[] s = readString().toCharArray();\n\n        for(int i = 0; i < n; i++) {\n            if(mapa.containsKey(s[i])) {\n                int x = mapa.get(s[i]);\n                mapa.replace(s[i], x + 1);\n            }\n            else mapa.put(s[i], 1);\n        }\n\n        int sz = mapa.size();\n        mapa = new HashMap<>();\n        int i = 0;\n        while (mapa.size() < sz) {\n            if(mapa.containsKey(s[i])) {\n                int x = mapa.get(s[i]);\n                mapa.replace(s[i], x + 1);\n            }\n            else mapa.put(s[i], 1);\n            i++;\n        }\n        int ans = i;\n\n        int left = 0;\n        int right = i - 1;\n\n        while(right < n) {\n            while(left < right) {\n                int y = mapa.get(s[left]);\n                if(y == 1) mapa.remove(s[left]);\n                else mapa.replace(s[left], y - 1);\n                if(mapa.size() == sz) {\n                    ans = Math.min(ans, right - left);\n                    left++;\n                }\n                else {\n                    left++;\n                    break;\n                }\n            }\n\n            right++;\n            if(right < n) {\n                if (mapa.containsKey(s[right])) {\n                    int x = mapa.get(s[right]);\n                    mapa.replace(s[right], x + 1);\n                } else mapa.put(s[right], 1);\n            }\n\n        }\n\n        out.print(ans);\n\n    }\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.util.Vector;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\n\n\npublic class C364C {\n\n\tstatic StringTokenizer st;\n\tstatic BufferedReader br;\n\tstatic PrintWriter pw;\n\n\tstatic int n;\n\tstatic int[] a;\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\tn = nextInt();\n\t\tint ans = n, cc, cur = 0;\n\t\ta = new int [52];\n\t\tchar[] c = next().toCharArray();\n\t\tint l = 0, len = 0;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (Character.isUpperCase(c[i])) {\n\t\t\t\tcur = 26 + c[i] - 'A';\n\t\t\t} else\n\t\t\t\tcur = c[i] - 'a';\n\t\t\tif (a[cur] == 0) {\n\t\t\t\ta[cur]++;\n\t\t\t\tlen++;\n\t\t\t\tans = i - l + 1;\n\t\t\t} else {\n\t\t\t\ta[cur]++;\n\t\t\t\tfor (; l < i; ++l) {\n\t\t\t\t\tif (Character.isUpperCase(c[l])) {\n\t\t\t\t\t\tcc = 26 + c[l] - 'A';\n\t\t\t\t\t} else\n\t\t\t\t\t\tcc = c[l] - 'a';\n\t\t\t\t\t\n\t\t\t\t\tif (a[cc] > 1) {\n\t\t\t\t\t\t--a[cc];\n\t\t\t\t\t} else break;\n\t\t\t\t}\n\t\t\t\tif (i - l + 1 < ans) {\n\t\t\t\t\tans = i - l + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\n\t\t/*int l = 0, r = n - 1;\n\t\tfor (l = 0; l < n; ++l) {\n\t\t\tif (Character.isUpperCase(c[l])) {\n\t\t\t\tif (a[26 + c[l] - 'A'] > 1) {\n\t\t\t\t\ta[26 + c[l] - 'A']--;\n\t\t\t\t} else break;\n\t\t\t} else {\n\t\t\t\tif (a[c[l] - 'a'] > 1) {\n\t\t\t\t\ta[c[l] - 'a']--;\n\t\t\t\t} else break;\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tfor (r = n - 1; r >= 0; --r) {\n\t\t\tif (Character.isUpperCase(c[r])) {\n\t\t\t\tif (a[26 + c[r] - 'A'] > 1) {\n\t\t\t\t\ta[26 + c[r] - 'A']--;\n\t\t\t\t} else break;\n\t\t\t} else {\n\t\t\t\tif (a[c[r] - 'a'] > 1) {\n\t\t\t\t\ta[c[r] - 'a']--;\n\t\t\t\t} else break;\n\t\t\t\t\n\t\t\t}\n\t\t}*/\n\t\tpw.print(ans);\n\t\tpw.close();\n\t}\n\t\n\tprivate static int sumf(int[] fen, int id) {\n\t\tint summ = 0;\n\t\tfor (; id >= 0; id = (id & (id + 1)) - 1) \n \t\t\tsumm += fen[id];\n\t\treturn summ;\n\t}\n\n\tprivate static void addf(int[] fen, int id) {\n\t\tfor (; id < fen.length; id |= id + 1) \n\t\t\tfen[id]++;\n\t}\n\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}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "/*\n * Code Author: Akshay Miterani\n * DA-IICT\n */\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n \npublic class A {\n \n\tstatic double eps=(double)1e-15;\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\tint n=in.nextInt();\n\t\tint l=0,r=0;\n\t\tString s=in.nextLine();\n\t\tHashSet<Character> size=new HashSet<>();\n\t\tfor(int i=0;i<n;i++){\n\t\t\tchar p=s.charAt(i);\n\t\t\tsize.add(p);\n\t\t}\n\t\tint chk=size.size();\n\t\tHashMap<Character, Integer> hm=new HashMap<>();\n\t\tint ans=Integer.MAX_VALUE;\n\t\twhile(l<n){\n\t\t\tif(hm.size()<chk && r<n){\n\t\t\t\tchar p=s.charAt(r);\n\t\t\t\tif(hm.containsKey(p)){\n\t\t\t\t\thm.put(p, hm.get(p)+1);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\thm.put(p, 1);\n\t\t\t\t}\n\t\t\t\tr++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tchar p=s.charAt(l);\n\t\t\t\tif(hm.get(p)==1){\n\t\t\t\t\thm.remove(p);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\thm.put(p, hm.get(p)-1);\n\t\t\t\t}\n\t\t\t\tl++;\n\t\t\t}\n\t\t\tif(hm.size()==chk){\n\t\t\t\tans=Math.min(ans, r-l);\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t\t//---------------The End------------------\n \n\t}\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint u;\n\t\tint v;\n \n\t\tpublic Pair(int u, int v) {\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t}\n \n\t\tpublic int hashCode() {\n\t\t\tint hu = (int) (u ^ (u >>> 32));\n\t\t\tint hv = (int) (v ^ (v >>> 32));\n\t\t\treturn 31 * hu + hv;\n\t\t}\n \n\t\tpublic boolean equals(Object o) {\n\t\t\tPair other = (Pair) o;\n\t\t\treturn u == other.u && v == other.v;\n\t\t}\n \n\t\tpublic int compareTo(Pair other) {\n\t\t\treturn Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);\n\t\t}\n \n\t\tpublic String toString() {\n\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t}\n\t}\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tstatic long modulo(long a,long b,long c) {\n\t\tlong x=1;\n\t\tlong y=a;\n\t\twhile(b > 0){\n\t\t\tif(b%2 == 1){\n\t\t\t\tx=(x*y)%c;\n\t\t\t}\n\t\t\ty = (y*y)%c; // squaring the base\n\t\t\tb /= 2;\n\t\t}\n\t\treturn  x%c;\n\t}\n\tstatic long gcd(long x, long y)\n\t{\n\t\tif(x==0)\n\t\t\treturn y;\n\t\tif(y==0)\n\t\t\treturn x;\n\t\tlong r=0, a, b;\n\t\ta = (x > y) ? x : y; // a is greater number\n\t\tb = (x < y) ? x : y; // b is smaller number\n\t\tr = b;\n\t\twhile(a % b != 0)\n\t\t{\n\t\t\tr = a % b;\n\t\t\ta = b;\n\t\t\tb = r;\n\t\t}\n\t\treturn r;\n\t}\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n \n\t\tpublic InputReader(InputStream inputstream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(inputstream));\n\t\t\ttokenizer = null;\n\t\t}\n \n\t\tpublic String nextLine(){\n\t\t\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tfullLine=reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}  \n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedInputStream;\nimport java.util.Scanner;\n\npublic class Main{\n\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(new BufferedInputStream(System.in));\n\tint n=in.nextInt();\n\tchar b[]=in.next().toCharArray();\n\tint bb[]=new int [b.length];\n\n\tint Mark[]=new int [26*2+1];\n\tint Mark1[]=new int [26*2+1];\n\n\tint ans=0;\n\tfor(int i=0;i<b.length;i++){\n\t\tchar f=b[i];\n\t\tint a;\n\t\tif(f>='a'&&f<='z')\n\t\t\ta=f-'a';\n\t\telse  a=f-'A'+26;\n\t\tbb[i]=a;\n\t\tif(Mark1[a] == 0){\n\t\t\tans++;\n\t\t\tMark1[a]=1;}\n\t \n}\n//\tSystem.out.println(ans);\n\tint i;\n    // int L ,R ,nowsum ,Ans;\n   int  L = 0 ,nowsum = 0 ,Ans = n,R = 0;\n     //\u627e\u5230LR\n     for(i = 0 ;i < n ;i ++)\n     {\n         if(Mark[bb[i]]==0) nowsum ++;\n           Mark[bb[i]] ++;\n           if(nowsum == ans) \n           {\n              R = i;\n              break;\n           }\n        \n     }\n//     System.out.println(\"r\"+R);\n     Ans = R - L + 1; \n     for(i = L ;i < n ;i ++)\n     {\n       \n        if((--Mark[bb[i]])==0)\n        {\n           int ok = 0;\n           for(int j = R + 1 ;j < n ;j ++)\n           {\n              \n          \n                 Mark[bb[j]] ++;\n                 if(bb[j] == bb[i])\n                 {\n                    ok = 1;\n                    R = j;\n                    break;\n                 }\n              \n           }\n           if(ok==0) break;\n        }\n        if(Ans > R - i) Ans = R - i;\n     }\n    \t System.out.println(Ans);\n\t \n\n\n\t}\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "//package baobab;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n\n    public static void main(String[] args) {\n        CIO io = new CIO();\n        try {\n            Csolver solver = new Csolver(io);\n            solver.solve();\n        } finally {\n            io.close();\n        }\n    }\n\n}\n\nclass Csolver {\n    CIO io;\n\n    public Csolver(CIO io) {\n        this.io = io;\n    }\n\n    public void solve() {\n        int n = io.nextInt();\n        String input = io.next();\n        int[] count = new int[1000];\n        int pokemonsInRange = 0;\n        int answer = Integer.MAX_VALUE;\n        int a = 0;\n        int b = 0;\n        for (; b < n ; b++) {\n            char end = input.charAt(b);\n            if (count[end] == 0) {\n                pokemonsInRange++;\n                answer = Integer.MAX_VALUE;\n            }\n            count[end]++;\n            while (count[input.charAt(a)] > 1) {\n                count[input.charAt(a)]--;\n                a++;\n            }\n            answer = Math.min(answer, b-a+1);\n        }\n        io.println(answer);\n    }\n\n    private static class Pair implements Comparable<Pair> {\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    private List<Integer>[] toGraph(CIO io, int n) {\n        List<Integer>[] g = new ArrayList[n+1];\n        for (int i=1; i<=n; i++) g[i] = new ArrayList<>();\n        for (int i=1; i<=n-1; i++) {\n            int a = io.nextInt();\n            int b = io.nextInt();\n            g[a].add(b);\n            g[b].add(a);\n        }\n        return g;\n    }\n}\n\nclass CIO 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 CIO() {\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}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\n\npublic class theyareeverywhere {\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter w = new PrintWriter(System.out);\n\n        //SWEEP LINE BABYY\n        \n        int n = Integer.parseInt(r.readLine());\n        \n        char[] pokemans = r.readLine().toCharArray();\n        \n        int[] counts = new int[52];\n        boolean[] exists = new boolean[52];\n        \n        for (int i = 0; i < pokemans.length; i++) {\n            exists[index(pokemans[i])] = true;\n        }\n        \n        int left = 0, right = 0;\n        counts[index(pokemans[0])] = 1;\n        \n        int answer = 1000000000;\n        \n        while (left < n && right < n) {\n            if (!valid(counts, exists)) {\n                //move right\n                right++;\n                if (right < n)\n                counts[index(pokemans[right])]++;\n            } else {\n                answer = Math.min(answer, right - left + 1);\n                left++;\n                if (left - 1 >= 0)\n                counts[index(pokemans[left - 1])]--;\n            }\n        }\n        \n        w.println(answer);\n        w.flush();\n    }\n    \n    public static boolean valid(int[] counts, boolean[] exists) {\n        for (int i = 0; i < counts.length; i++) {\n            if (exists[i] && counts[i] == 0) return false;\n        }\n        return true;\n    }\n    \n    public static int index(char c) {\n        if (c >= 'a' && c <= 'z') {\n            return c - 'a';\n        } else {\n            return c - 'A' + 26;\n        }\n    }\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "/**\n * Created by ankeet on 7/22/16.\n */\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C701 {\n\n    static FastReader in = null;\n    static PrintWriter out = null;\n\n    public static void solve()\n    {\n        int n = in.nint();\n        String pk = in.next();\n        boolean[] occ = new boolean[52];\n        for(int i=0; i<n; i++)\n        {\n            char c = pk.charAt(i);\n            int val = Character.isUpperCase(c)?  (int)(c-'A') : (int)(c-'a'+26);\n            occ[val] = true;\n        }\n        int[][] next = new int[n][52];\n        for(int i=0; i<n; i++) for(int j=0; j<52; j++) next[i][j] = -1;\n\n        for(int i= n-1; i>=0; i--) {\n\n            char c = pk.charAt(i);\n            int val = Character.isUpperCase(c)?  (int)(c-'A') : (int)(c-'a'+26);\n            next[i][val] = i;\n            if(i<n-1)\n            for(int j=0; j<52; j++)\n            {\n                if(j!=val)\n                {\n                    next[i][j] = next[i+1][j];\n                }\n            }\n\n        }\n\n        int min = Integer.MAX_VALUE;\n        for(int i=0; i<n; i++)\n        {\n            int maxd = 0;\n            boolean endearly = false;\n            for(int j=0; j<52; j++)\n            {\n                if(occ[j] && next[i][j] == -1)\n                {\n                    endearly = true;\n                    break;\n                }\n                else if(occ[j])\n                {\n                    maxd = Math.max(maxd, next[i][j]-i+1);\n                }\n            }\n\n            if(endearly) break;\n            min = Math.min(min, maxd);\n        }\n\n        out.println(min);\n\n\n    }\n\n    public static void main(String[] args)\n    {\n        in = new FastReader(System.in);\n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n        out.close();\n\n    }\n\n    static class FastReader {\n\n        BufferedReader read;\n        StringTokenizer tokenizer;\n\n        public FastReader(InputStream in)\n        {\n            read = new BufferedReader(new InputStreamReader(in));\n        }\n\n        public String next()\n        {\n            while(tokenizer == null || !tokenizer.hasMoreTokens())\n            {\n                try{\n                    tokenizer = new StringTokenizer(read.readLine());\n                }catch(Exception e){\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nint()\n        {\n            return Integer.parseInt(next());\n        }\n        public long nlong()\n        {\n            return Long.parseLong(next());\n        }\n        public double ndouble()\n        {\n            return Double.parseDouble(next());\n        }\n\n        public int[] narr(int n)\n        {\n            int[] a = new int[n];\n            for(int i=0; i<n; ++i)\n            {\n                a[i] = nint();\n            }\n            return a;\n        }\n\n        public long[] nlarr(int n)\n        {\n            long[] a = new long[n];\n            for(int i=0; i<n; ++i)\n            {\n                a[i] = nlong();\n            }\n            return a;\n        }\n    }\n\n\n}\n\n\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\n\npublic class Main\n{\n    /********************************************** a list of common variables **********************************************/\n    private MyScanner scan = new MyScanner();\n    private PrintWriter out = new PrintWriter(System.out);\n    private final double PI = Math.PI;\n    private final int INF = (int)(1e9);\n    private final double EPS = 1e-6;\n    private final int SIZEN = (int)(1e7);\n    private final int MOD = (int)(1e9 + 7);\n    private final long MODH = 10000000007L, BASE = 10007;\n    private final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};\n    int n;\n    int[] sum;\n    int[][] a;\n\n    public void foo1() {\n        int n = scan.nextInt();\n        int sum = 0;\n        int[] a = new int[n];\n        for (int i = 0;i < n;++i) {\n            a[i] = scan.nextInt();\n            sum += a[i];\n        }\n        int avg = sum * 2 / n;\n        for (int i = 0;i < n;++i) {\n            if (a[i] == 0) {\n                continue;\n            }\n            for (int j = i + 1;j < n;++j) {\n                if (a[i] + a[j] == avg) {\n                    a[j] = 0;\n                    System.out.println((i + 1) + \" \" + (j + 1));\n                    break;\n                }\n            }\n        }\n    }\n\n    public void foo2() {\n        int n = scan.nextInt();\n        int m = scan.nextInt();\n        HashSet<Integer> row = new HashSet<Integer>();\n        HashSet<Integer> col = new HashSet<Integer>();\n        for (int i = 0;i < m;++i) {\n            int x = scan.nextInt();\n            int y = scan.nextInt();\n            row.add(x);\n            col.add(y);\n            out.print((long) (n - row.size()) * (n - col.size()) + \" \");\n        }\n    }\n\n    public int getId(char c) {\n        return (c >= 'a' && c <= 'z') ? c - 'a': c - 'A' + 26;\n    }\n\n    public boolean isOk(int len) {\n        for (int i = 0;i + len <= n;++i) {\n            boolean flag = true;\n            for (int j = 0;j < 52;++j) {\n                if (a[i + len][j] - a[i][j] == 0 && sum[j] != 0) {\n                    flag = false;\n                    break;\n                }\n            }\n            if (flag) {\n                return true;\n            }\n        }\n        return false;\n    }\n\n    public void foo() {\n        n = scan.nextInt();\n        char[] s = scan.next().toCharArray();\n        a = new int[n + 1][52];\n        sum = new int[52];\n        for (int i = 0;i < n;++i) {\n            for (int j = 0;j < 52;++j) a[i + 1][j] = a[i][j];\n            ++a[i + 1][getId(s[i])];\n            ++sum[getId(s[i])];\n        }\n        int left = 1, right = n, ans = n;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            if (isOk(mid)) {\n                ans = mid;\n                right = mid - 1;\n            } else {\n                left = mid + 1;\n            }\n        }\n        out.println(ans);\n    }\n\n    public static void main(String[] args)\n    {\n        Main m = new Main();\n        m.foo();\n        m.out.close();\n    }\n\n    /********************************************** a list of common algorithms **********************************************/\n    /**\n     * 1---Get greatest common divisor\n     * @param a :\tfirst number\n     * @param b :\tsecond number\n     * @return\t\tgreatest common divisor\n     */\n    public long gcd(long a, long b)\n    {\n        return 0 == b ? a : gcd(b, a % b);\n    }\n\n    /**\n     * 2---Get the distance from a point to a line\n     * @param x1\tthe x coordinate of one endpoint of the line\n     * @param y1\tthe y coordinate of one endpoint of the line\n     * @param x2\tthe x coordinate of the other endpoint of the line\n     * @param y2\tthe y coordinate of the other endpoint of the line\n     * @param x\t\tthe x coordinate of the point\n     * @param y\t\tthe x coordinate of the point\n     * @return\t\tthe distance from a point to a line\n     */\n    public double getDist(long x1, long y1, long x2, long y2, long x, long y)\n    {\n        long a = y2 - y1;\n        long b = x1 - x2;\n        long c = y1 * (x2 - x1) - x1 * (y2 - y1);\n        return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);\n    }\n\n    /**\n     * 3---Get the distance from one point to a segment (not a line)\n     * @param x1\tthe x coordinate of one endpoint of the segment\n     * @param y1\tthe y coordinate of one endpoint of the segment\n     * @param x2\tthe x coordinate of the other endpoint of the segment\n     * @param y2\tthe y coordinate of the other endpoint of the segment\n     * @param x\t\tthe x coordinate of the point\n     * @param y\t\tthe y coordinate of the point\n     * @return\t\tthe distance from one point to a segment (not a line)\n     */\n    public double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)\n    {\n        double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);\n        if(cross <= 0)\n        {\n            return (x - x1) * (x - x1) + (y - y1) * (y - y1);\n        }\n        double d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);\n        if(cross >= d)\n        {\n            return (x - x2) * (x - x2) + (y - y2) * (y - y2);\n        }\n        double r = cross / d;\n        double px = x1 + (x2 - x1) * r;\n        double py = y1 + (y2 - y1) * r;\n        return (x - px) * (x - px) + (y - py) * (y - py);\n    }\n\n    /**\n     * 4---KMP match, i.e. kmpMatch(\"abcd\", \"bcd\") = 1, kmpMatch(\"abcd\", \"bfcd\") = -1.\n     * @param t:\tString to match.\n     * @param p:\tString to be matched.\n     * @return\t\tif can match, first index; otherwise -1.\n     */\n    public int kmpMatch(char[] t, char[] p)\n    {\n        int n = t.length;\n        int m = p.length;\n        int[] next = new int[m + 1];\n        next[0] = -1;\n        int j = -1;\n        for(int i = 1;i < m;++i)\n        {\n            while(j >= 0 && p[i] != p[j + 1])\n            {\n                j = next[j];\n            }\n            if(p[i] == p[j + 1])\n            {\n                ++j;\n            }\n            next[i] = j;\n        }\n        j = -1;\n        for(int i = 0;i < n;++i)\n        {\n            while(j >= 0 && t[i] != p[j + 1])\n            {\n                j = next[j];\n            }\n            if(t[i] == p[j + 1])\n            {\n                ++j;\n            }\n            if(j == m - 1)\n            {\n                return i - m + 1;\n            }\n        }\n        return -1;\n    }\n\n    /**\n     * 5---Get the hash code of a String\n     * @param\ts:\tinput string\n     * @return\thash code\n     */\n    public long hash(String s)\n    {\n        long key = 0, t = 1;\n        for(int i = 0;i < s.length();++i)\n        {\n            key = (key + s.charAt(i) * t) % MODH;\n            t = t * BASE % MODH;\n        }\n        return key;\n    }\n\n    /**\n     * 6---Get x ^ n % MOD quickly.\n     * @param\tx:\tbase\n     * @param \tn:\ttimes\n     * @return\tx ^ n % MOD\n     */\n    public long quickMod(long x, long n)\n    {\n        long ans = 1;\n        while(n > 0)\n        {\n            if(1 == n % 2)\n            {\n                ans = ans * x % MOD;\n            }\n            x = x * x % MOD;\n            n >>= 1;\n        }\n        return ans;\n    }\n\n    /**\n     * 7---judge if a point is located inside a polygon\n     * @param x0\tthe x coordinate of the point\n     * @param y0\tthe y coordinate of the point\n     * @return true if it is inside the polygon, otherwise false\n     */\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\n    /**\n     * 8---judge if a point is located on the segment\n     * @param\tx1\tthe x coordinate of one point of the segment\n     * @param\ty1\tthe y coordinate of one point of the segment\n     * @param \tx2\tthe x coordinate of another point of the segment\n     * @param \ty2\tthe y coordinate of another point of the segment\n     * @param\tx\tthe x coordinate of the point\n     * @param \ty\tthe y coordinate of the point\n     * @return\ttrue if it is located on the segment, otherwise false\n     */\n    public boolean isOnSeg(long x1, long y1, long x2, long y2, long x, long y)\n    {\n        return (x - x1) * (y2 - y1) == (x2 - x1) * (y - y1) &&\n                x >= Math.min(x1, x2) && x <= Math.max(x1, x2) &&\n                y >= Math.min(y1, y2) && y <= Math.max(y1, y2);\n    }\n\n    /**\n     * 9---get the cross product\n     * @param \tp1\tpoint A\n     * @param \tp2\tpoint B\n     * @param \tp\tpoint O\n     * @return\tcross product of OA x OB\n     */\n\t/*public 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\n    /**\n     * 10---implement topsort and tell if it is possible\n     * @return true if it is possible to implement topsort, otherwise false\n     */\n\t/*public boolean topsort()\n\t{\n\t\tQueue<Integer> q = new LinkedList<Integer>();\n\t\tStringBuilder ans = new StringBuilder();\n\t\tint[] in = new int[26];\n\t\tfor(int i = 0;i < 26;++i)\n\t\t{\n\t\t\tif(0 == in[i]) \n\t\t\t{\n\t\t\t\tans.append((char)('a' + i));\n\t\t\t\tq.add(i);\n\t\t\t}\n\t\t}\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tint u = q.poll();\n\t\t\tfor(int i = 0;i < 26;++i)\n\t\t\t{\n\t\t\t\tif(map[u][i])\n\t\t\t\t{\n\t\t\t\t\t--in[i];\n\t\t\t\t\tif(0 == in[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tans.append((char)('a' + i));\n\t\t\t\t\t\tq.add(i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 26 == ans.length();\n\t}*/\n\n    class MyScanner\n    {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        BufferedInputStream bis = new BufferedInputStream(System.in);\n\n        public int read()\n        {\n            if (-1 == numChars)\n            {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars)\n            {\n                curChar = 0;\n                try\n                {\n                    numChars = bis.read(buf);\n                }\n                catch (IOException e)\n                {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                {\n                    return -1;\n                }\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                if (c < '0' || c > '9')\n                {\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        {\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                if (c < '0' || c > '9')\n                {\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 double nextDouble()\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            double res = 0;\n            while (!isSpaceChar(c) && c != '.')\n            {\n                if (c == 'e' || c == 'E')\n                {\n                    return res * Math.pow(10, nextInt());\n                }\n                if (c < '0' || c > '9')\n                {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c & 15;\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                    {\n                        return res * Math.pow(10, nextInt());\n                    }\n                    if (c < '0' || c > '9')\n                    {\n                        throw new InputMismatchException();\n                    }\n                    m /= 10;\n                    res += (c & 15) * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String next()\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        private boolean isSpaceChar(int c)\n        {\n            return ' ' == c || '\\n' == c || '\\r' == c || '\\t' == c || -1 == c;\n        }\n    }\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\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<ArrayList<Integer>> adjList;\n    public static int[] dr = {-1, 0, 1, 0, -1, 1, 1, -1};\n    public static int[] dc = {0, 1, 0, -1, 1, 1, -1, -1};\n\n    public static void main(String[] args) throws Exception{\n        int N = Integer.parseInt(br.readLine());\n        char[] A = br.readLine().toCharArray();\n\n        HashSet<Character> cndD = new HashSet<Character>();\n        for(int i = 0; i < N; i++){\n            cndD.add(A[i]);\n        }\n\n        int cnt = cndD.size();\n\n        int a = 0;\n        int b = 0;\n\n        int ans = (1 << 30);\n        HashMap<Character, Integer> d = new HashMap<Character, Integer>();\n        while(b < N){\n            if(d.containsKey(A[b])){\n                if(A[a] == A[b]){\n                    a++;\n                    while(d.get(A[a]) > 1){\n                        d.put(A[a], d.get(A[a])-1);\n                        a++;\n                    }\n                } else{\n                    d.put(A[b], d.get(A[b])+1);\n                }\n            } else{\n                d.put(A[b], 1);\n            }\n            if(d.size() == cnt){\n                ans = Math.min(b-a+1, ans);\n            }\n            b++;\n        }\n\n        pw.print(ans + \"\\n\");\n        pw.close();\n        br.close();\n    }\n}\n\nclass Pair implements Comparable<Pair>{\n    public int a, b;\n\n    Pair(int a, int b){\n        this.a = a;\n        this.b = b;\n    }\n\n    @Override\n    public int compareTo(Pair P){\n        if(P.b != this.b){\n            return b - P.b;\n        } else if(P.a == this.a){\n            return a - P.a;\n        } else{\n            return 0;\n        }\n    }\n\n    public String toString(){\n        return a + \" \" + b;\n    }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            char[] poks = in.next().toCharArray();\n            boolean[] was = new boolean[52];\n            for (int i = 0; i < n; i++) {\n                if (Character.isLowerCase(poks[i])) {\n                    was[poks[i] - 'a'] = true;\n                } else {\n                    was[poks[i] - 'A' + 26] = true;\n                }\n            }\n            int count = 0;\n            for (int i = 0; i < 52; i++) {\n                count += was[i] ? 1 : 0;\n            }\n            int[] vis = new int[52];\n            int pre = 0;\n            int chr = 0;\n            int ans = Integer.MAX_VALUE;\n            for (int i = 0; i < n; i++) {\n                int pos = poks[i] - 'a';\n                if (Character.isUpperCase(poks[i])) {\n                    pos = poks[i] - 'A' + 26;\n                }\n\n                if (vis[pos] == 0) {\n                    chr++;\n                }\n                vis[pos]++;\n                while (chr == count) {\n                    ans = Math.min(ans, i - pre + 1);\n                    pos = poks[pre] - 'a';\n                    if (Character.isUpperCase(poks[pre])) {\n                        pos = poks[pre] - 'A' + 26;\n                    }\n                    vis[pos]--;\n                    if (vis[pos] == 0) chr--;\n                    pre++;\n                }\n            }\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            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", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\n\n/**\n * Created by pallavi on 22/7/16.\n */\npublic class C701 {\n    public static int f(char c) {\n        if (c >= 'a' && c <= 'z') {\n            return c - 'a';\n        } else {\n            return 26 + c - 'A';\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n        int n = Integer.parseInt(reader.readLine());\n        char[] ch = reader.readLine().toCharArray();\n\n        LinkedList<Integer>[] p = new LinkedList[52];\n\n        for (int i = 0; i < 52; i++) {\n            p[i] = new LinkedList<>();\n        }\n\n        int[] fc = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            int cc = f(ch[i]);\n            p[cc].add(i);\n            fc[i] = cc;\n        }\n        int en = 0;\n        for (int i = 0; i < 52; i++) {\n            if (p[i].size() > 0) en = Math.max(en, p[i].poll());\n        }\n\n        int mx = en + 1;\n\n        for (int i = 0; i < n; i++) {\n            if (p[fc[i]].size() == 0) break;\n            en = Math.max(en, p[fc[i]].poll());\n            mx = Math.min(mx, en - i);\n        }\n\n        System.out.println(mx);\n    }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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 C {\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\tchar[]a = next().toCharArray();\n\t\tint[]cnt = new int[256];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcnt[a[i]]++;\n\t\t}\n\t\tint alldiff = 0;\n\t\tfor (int i = 0; i < 256; i++) {\n\t\t\tif (cnt[i] > 0)\n\t\t\t\talldiff++;\n\t\t}\n\t\tArrays.fill(cnt, 0);\n\t\tint diff = 0, right = -1, ans = n+5;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (right < i) {\n\t\t\t\tcnt[a[i]]++;\n\t\t\t\tdiff = 1;\n\t\t\t\tright = i;\n\t\t\t}\n\t\t\twhile (right < n-1 && diff < alldiff) {\n\t\t\t\tright++;\n\t\t\t\tcnt[a[right]]++;\n\t\t\t\tif (cnt[a[right]]==1)\n\t\t\t\t\tdiff++;\n\t\t\t}\n\t\t\tif (diff==alldiff && right-i+1 < ans) {\n\t\t\t\tans = right-i+1;\n\t\t\t}\n\t\t\tcnt[a[i]]--;\n\t\t\tif (cnt[a[i]]==0)\n\t\t\t\tdiff--;\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}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    static final String FILE = \"\";\n\n    public void solve() {\n        int n = in.nextInt();\n        TreeMap<Character, Integer> map = new TreeMap<>();\n        ArrayList<Integer> list = new ArrayList<>();\n        String s = in.next();\n        for (int i = 0; i < n; i++) {\n            char ch = s.charAt(i);\n            if (!map.containsKey(ch))\n                map.put(ch, map.size());\n            list.add(map.get(ch));\n        }\n\n        int l = 0;\n        int ans = Integer.MAX_VALUE;\n        int nad = map.size();\n        int cnt[] = new int[n];\n\n        for (int i = 0; i < list.size(); i++) {\n            if (cnt[list.get(i)] == 0)\n                nad--;\n            cnt[list.get(i)]++;\n\n            if (nad == 0) {\n                ans = min(ans, i - l + 1);\n                while (true) {\n                    if (cnt[list.get(l)] == 1) {\n                        ans = min(ans, i - l + 1);\n                        cnt[list.get(l)]--;\n                        l++;\n                        nad++;\n                        break;\n                    } else {\n                        cnt[list.get(l)]--;\n                        l++;\n                    }\n                }\n            }\n        }\n\n        out.print(ans);\n    }\n\n    public void run() {\n        if (FILE.equals(\"\")) {\n            in = new FastScanner(System.in);\n            out = new PrintWriter(System.out);\n        } else {\n            try {\n                in = new FastScanner(new FileInputStream(FILE +\n                        \".in\"));\n                out = new PrintWriter(new FileOutputStream(FILE +\n                        \".out\"));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n        solve();\n        out.close();\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        public FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public String nextLine() {\n            st = null;\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n                return \"\";\n            }\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public float nextFloat() {\n            return Float.parseFloat(next());\n        }\n    }\n\n    class Pair<A extends Comparable<A>, B extends Comparable<B>>\n            implements Comparable<Pair<A, B>> {\n        public A a;\n        public B b;\n\n        public Pair(A a, B b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public int compareTo(Pair<A, B> o) {\n            if (o == null || o.getClass() != getClass())\n                return 1;\n            int cmp = a.compareTo(o.a);\n            if (cmp == 0)\n                return b.compareTo(o.b);\n            return cmp;\n        }\n\n        @Override\n        public boolean equals(Object o) {\n            if (this == o) return true;\n            if (o == null || getClass() != o.getClass()) return false;\n\n            Pair<?, ?> pair = (Pair<?, ?>) o;\n\n            if (a != null ? !a.equals(pair.a) : pair.a != null) return\n                    false;\n            return !(b != null ? !b.equals(pair.b) : pair.b != null);\n        }\n    }\n\n    class PairInt extends Pair<Integer, Integer> {\n        public PairInt(Integer u, Integer v) {\n            super(u, v);\n        }\n    }\n\n    class PairLong extends Pair<Long, Long> {\n        public PairLong(Long u, Long v) {\n            super(u, v);\n        }\n    }\n\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class TheyAreEverywhere {\n    static StringTokenizer st;\n    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in), 325678);\n    static int[] id = new int[100000];\n\n    public static void main(String[] args) throws IOException {\n        int n = in();\n        String s = next();\n        int total = 0;\n        int[] seq = new int[n];\n        boolean[] c = new boolean[100000];\n        for (int i = 0; i < n; i++) {\n            seq[i] = s.charAt(i);\n            if (!c[seq[i]]) {\n                total++;\n                c[seq[i]] = true;\n            }\n        }\n\n        Arrays.fill(id, -1);\n        int best = Integer.MAX_VALUE;\n        TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>() {\n            @Override\n            public int compare(Integer o1, Integer o2) {\n                return id[o1] - id[o2];\n            }\n        });\n        for (int i = 0; i < n; i++) {\n            q.remove(seq[i]);\n            id[seq[i]] = i;\n            q.add(seq[i]);\n            if (q.size() == total) {\n                //System.out.println(\"best: i=\" + i + \" id=\" + id[q.first()]);\n                best = Math.min(best, i - id[q.first()] + 1);\n            }\n            //System.out.println(\"i=\"+i+\" \" +q.toString());\n        }\n\n        System.out.println(best);\n\n    }\n\n    public static int in() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    public static long inl() throws IOException {\n        return Long.parseLong(next());\n    }\n\n    public static String next() throws IOException {\n        if (st == null || !st.hasMoreTokens())\n            st = new StringTokenizer(bf.readLine());\n        return st.nextToken();\n    }\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Round364_div2_C {\n\n    public static void main(String[] args) throws IOException {\n        FastReader in = new FastReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        solve(in, out);\n        out.flush();\n    }\n\n\n    public static void solve(FastReader in, PrintWriter out) {\n        int n = in.readInt();\n        String s = in.readString();\n\n        int totalCnt = (int) s.chars().distinct().count();\n\n        Map<Character, Integer> curCnts = new HashMap<>();\n\n        int solution = s.length();\n        int i = 0;\n        for (int j = 0 ; j < s.length() ; j++) {\n            // add s_j\n            char sj = s.charAt(j);\n            curCnts.put(sj, curCnts.getOrDefault(sj, 0) + 1);\n\n            // contract s_i\n            while (curCnts.getOrDefault(s.charAt(i), 0) > 1) {\n                char si = s.charAt(i);\n                int siCnt = curCnts.get(si);\n                if (siCnt > 1) {\n                    curCnts.put(si, siCnt - 1);\n                } else {\n                    curCnts.remove(si);\n                }\n                i++;\n            }\n\n            if (curCnts.size() == totalCnt) {\n                solution = Math.min(solution, j - i + 1);\n            }\n        }\n\n        out.println(solution);\n    }\n\n\n    /**\n     * Custom buffered reader. Faster than Scanner and BufferedReader + StringTokenizer.\n     */\n    static class FastReader {\n        private final InputStream stream;\n        private int current;\n        private int size;\n        private byte[] buffer = new byte[1024 * 8];\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n            current = 0;\n            size = 0;\n        }\n\n        public int readInt() {\n            int sign = 1;\n            int abs = 0;\n            int c = readNonEmpty();\n            if (c == '-') {\n                sign = -1;\n                c = readAny();\n            }\n            do {\n                if (c < '0' || c > '9') {\n                    throw new IllegalStateException();\n                }\n                abs = 10 * abs + (c - '0');\n                c = readAny();\n            } while (!isEmpty(c));\n            return sign * abs;\n        }\n\n        public int[] readIntArray(int n) {\n            int[] array = new int[n];\n            for (int i = 0 ; i < n ; i++) {\n                array[i] = readInt();\n            }\n            return array;\n        }\n\n        public char readChar() {\n            return (char) readNonEmpty();\n        }\n\n        public String readString() {\n            StringBuffer sb = new StringBuffer();\n            int c;\n            do {\n                c = readAny();\n            } while (isEmpty(c));\n            do {\n                sb.append((char) c);\n                c = readAny();\n            } while (!isEmpty(c));\n            return sb.toString();\n        }\n\n        private int readAny() {\n            try {\n                if (current >= size) {\n                    current = 0;\n                    size = stream.read(buffer);\n                    if (size < 0) {\n                        return -1;\n                    }\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(\"Failed to readAny next byte\", e);\n            }\n            return buffer[current++];\n        }\n\n        private int readNonEmpty() {\n            int result;\n            do {\n                result = readAny();\n            } while (isEmpty(result));\n            return result;\n        }\n\n        private static boolean isEmpty(int c) {\n            return c == ' ' || c == '\\t' || c == '\\n' || c == '\\r' || c == -1;\n        }\n    }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C{\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\tSolver solver = new Solver();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n\n\tstatic class Solver{\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tString s = in.next();\n\t\t\tHashMap<Character, Integer> map = new HashMap<>();\n\t\t\tfor (int i = 0; i < n; ++ i) {\n\t\t\t\tmap.put(s.charAt(i), 0);\n\t\t\t}\n\t\t\tint l = 0, r = 0, cnt = 0, ans = n;\n\t\t\tchar c;\n\t\t\twhile (l < n) {\n\t\t\t\twhile (r < n && cnt < map.size()) {\n\t\t\t\t\tc = s.charAt(r);\n\t\t\t\t\tmap.put(c, map.get(c) + 1);\n\t\t\t\t\tif (map.get(c) == 1) ++cnt;\n\t\t\t\t\t++r;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (cnt == map.size() && r-l < ans)\n\t\t\t\t\tans = r-l;\n\t\t\t\t\n\t\t\t\tc = s.charAt(l);\n\t\t\t\tmap.put(c, map.get(c)-1);\n\t\t\t\tif (map.get(c) == 0) --cnt;\n\t\t\t\t++l;\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic InputReader (InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\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\t}\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Q3a {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tin.nextLine();\n\t\tString s = in.nextLine();\n\n\t\tHashMap<Integer, Integer> seen = new HashMap<>();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tCharacter c = s.charAt(i);\n\t\t\tint ci = (int) c.charValue();\n\t\t\t// System.out.println(ci);\n\t\t\tseen.put(ci, seen.get(ci) == null ? 1 : seen.get(ci) + 1);\n\t\t}\n\n\t\tHashMap<Integer, Integer> sub = new HashMap<Integer, Integer>();\n\t\tint start = 0;\n\t\tint min = 10000000;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tCharacter c = s.charAt(i);\n\t\t\tint ci = (int) c.charValue();\n\n\t\t\tsub.put(ci, sub.get(ci) == null ? 1 : sub.get(ci) + 1);\n\t\t\t\n\t\t\twhile(sub.size() == seen.size()) {\n\t\t\t\tmin = Math.min(min, i - start + 1);\n\t\t\t\tc = s.charAt(start);\n\t\t\t\tstart ++;\n\t\t\t\tci = (int) c.charValue();\n\t\t\t\tif( sub.get(ci) == 1) \n\t\t\t\t\tsub.remove(ci);\n\t\t\t\telse\n\t\t\t\t\tsub.put(ci, sub.get(ci) - 1);\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.print(min);\n\n\t\t// System.out.println( seen_all_at - begin + 1);\n\n\t\tin.close();\n\t}\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\n\n\n\npublic class TestClass11 {\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\tInputReader in=new InputReader(System.in);\n\t\tOutputWriter out=new OutputWriter(System.out);\n\t\tint n=in.readInt();\n\t\tString s=in.readString();\n\t\tint low[]=new int[26];\n\t\tint upper[]=new int[26];\n\t\tboolean islow[]=new boolean[26];\n\t\tboolean isupper[]=new boolean[26];\n\t\tArrays.fill(low,Integer.MAX_VALUE);\n\t\tArrays.fill(upper, Integer.MAX_VALUE);\n\t\t\n\t\tint ans[]=new int[n];\n\t\tint finalsans=Integer.MAX_VALUE;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tint c=s.charAt(i);\n\t\t\tif(c>='a'&&c<='z'){\n\t\t\t\tislow[c-'a']=true;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tisupper[c-'A']=true;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tfor(int i=n-1;i>=0;i--){\n\t\t\tint c=s.charAt(i);\n\t\t\t\n\t\t\tif(c>='a'&&c<='z'){\n\t\t\t\tlow[c-'a']=i;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tupper[c-'A']=i;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfor(int j=0;j<26;j++){\n\t\t\t\tif(islow[j]==true){\n\t\t\t\t\tans[i]=Math.max(ans[i], low[j]);\n\t\t\t\t}\n\t\t\t}\n          for(int j=0;j<26;j++){\n        \t  if(isupper[j]==true){\n        \t\t  ans[i]=Math.max(ans[i], upper[j]);\n\t\t\t\t}\n\t\t\t}\n          \n          finalsans=Math.min(ans[i]-i+1, finalsans);\n\t\t}\n\t\t\n\n\t\tSystem.out.println(finalsans);\n\t\t\n\t\t\n\t}\n\n}\n\nclass InputReader {\n\t \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 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 c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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 \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\tpublic void flush() {\n\t\twriter.flush();\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", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tpublic static void main(String[] args) throws IOException {\n\t\tFile inputFile = new File(\"entradaC\");\n\t\tif (inputFile.exists())\n\t\t\tSystem.setIn(new FileInputStream(inputFile));\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringBuilder out = new StringBuilder();\n\t\tString line = \"\";\n\t\twhile ((line = in.readLine()) != null) {\n\t\t\tint n = Integer.parseInt(line);\n\t\t\tchar[] p = in.readLine().toCharArray();\n\t\t\tHashMap<Character, Integer> dif = new HashMap<>();\n\t\t\tfor (int i = 0; i < p.length; i++)\n\t\t\t\tdif.put(p[i], 0);\n\t\t\tint ndif = dif.size();\n\t\t\tint head = 0, tail = 0, cnt = 0, ans = Integer.MAX_VALUE, cur;\n\t\t\twhile (head < n) {\n\t\t\t\tcur = dif.get(p[head]);\n\t\t\t\tif (cur == 0)\n\t\t\t\t\tcnt++;\n\t\t\t\tdif.put(p[head], cur + 1);\n\t\t\t\thead++;\n\t\t\t\tif (cnt == ndif)\n\t\t\t\t\tans = Math.min(ans, head - tail);\n\t\t\t\twhile (tail < head && cnt == ndif) {\n\t\t\t\t\tcur = dif.get(p[tail]);\n\t\t\t\t\tif (cur == 1)\n\t\t\t\t\t\tcnt--;\n\t\t\t\t\tdif.put(p[tail], cur - 1);\n\t\t\t\t\ttail++;\n\t\t\t\t\tif (cnt == ndif)\n\t\t\t\t\t\tans = Math.min(ans, head - tail);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ndif == 1)\n\t\t\t\tans = 1;\n\t\t\tout.append(ans + \"\\n\");\n\n\t\t}\n\t\tSystem.out.print(out);\n\t}\n\n\tstatic int[] readInts(String line) {\n\t\tStringTokenizer st = new StringTokenizer(line.trim());\n\t\tint a[] = new int[st.countTokens()], index = 0;\n\t\twhile (st.hasMoreTokens())\n\t\t\ta[index++] = Integer.parseInt(st.nextToken());\n\t\treturn a;\n\t}\n\n\tstatic long[] readLongs(String line) {\n\t\tStringTokenizer st = new StringTokenizer(line.trim());\n\t\tlong a[] = new long[st.countTokens()];\n\t\tint index = 0;\n\t\twhile (st.hasMoreTokens())\n\t\t\ta[index++] = Long.parseLong(st.nextToken());\n\t\treturn a;\n\t}\n\n\tstatic double[] readDoubles(String line) {\n\t\tStringTokenizer st = new StringTokenizer(line.trim());\n\t\tdouble a[] = new double[st.countTokens()];\n\t\tint index = 0;\n\t\twhile (st.hasMoreTokens())\n\t\t\ta[index++] = Double.parseDouble(st.nextToken());\n\t\treturn a;\n\t}\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class Round364C {\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\tk = 0;\n\t\t\n\t\tString line = sc.nextLine();\n\t\t\n\t\tArrayList<Character> poks = new ArrayList<Character>();\n\t\tboolean ex[] = new boolean[256];\n\t\t\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tif(!ex[line.charAt(i)])\n\t\t\t{\n\t\t\t\tex[line.charAt(i)] = true;\n\t\t\t\tpoks.add(line.charAt(i));\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tint l = 0;\n\t\tint r = 0;\n\t\tint dist = 1;\n\t\tint occ[] = new int[256];\n\t\tocc[line.charAt(0)] = 1;\n\t\t\n\t\tint min = n;\n\t\twhile(r < n)\n\t\t{\n\t\t\tif(dist == poks.size())\n\t\t\t\tmin = Math.min(min, r - l + 1);\n\t\t\tif(l < r && dist == poks.size())\n\t\t\t{\n\t\t\t\t\n\t\t\t\tocc[line.charAt(l)]--;\n\t\t\t\tif(occ[line.charAt(l)] == 0)\n\t\t\t\t\tdist--;\n\t\t\t\tl++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(r < n-1){\n\t\t\t\tocc[line.charAt(r+1)]++;\n\t\t\t\tif(occ[line.charAt(r+1)] == 1)\n\t\t\t\t\tdist++;\n\t\t\t}\n\t\t\tr++;\n\t\t}\n\t\tSystem.out.println(min);\n\t\t\n\t}\n\t\n\tstatic int n,k;\n\tstatic int dp[][][];\n\t\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(FileReader f) {\n\t\t\tbr = new BufferedReader(f);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tScanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\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 NumberFormatException, 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\t}\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import com.sun.org.apache.xml.internal.utils.StringComparable;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.text.DecimalFormat;\nimport java.text.NumberFormat;\nimport java.util.*;\n\npublic class Main {\n    public static void main(String[] args) {\n//     Test.testing();\n        ConsoleIO io = new ConsoleIO();\n        new Main(io).solve();\n        io.close();\n    }\n\n    ConsoleIO io;\n\n    Main(ConsoleIO io) {\n        this.io = io;\n    }\n\n    ArrayList<ArrayList<Integer>> gr;\n    boolean[] visit;\n\n    class Edge {\n        public Edge(int u, int v, int c) {\n            this.u = u;\n            this.v = v;\n            this.c = c;\n        }\n\n        public int u;\n        public int v;\n        public int c;\n    }\n\n    long MOD = 1_000_000_007;\n    int N, M, K;\n    double[][] map;\n\n    public void solve() {\n        String s = io.readLine();\n        N = Integer.parseInt(s);\n        char[] a = io.readLine().toCharArray();\n        int[] look = new int[256];\n        Arrays.fill(look, 10000);\n        int k = 0;\n        for (int i = 0; i < a.length; i++) {\n            if (look[a[i]] == 10000) {\n                look[a[i]] = k;\n                k++;\n            }\n        }\n        int res = N;\n        long need = (1L << k) - 1;\n        long mask = 0;\n        int head = 0;\n        int tail = 0;\n        int[] c = new int[k];\n        while (head < a.length) {\n            while (head < a.length && mask != need) {\n                int v = look[a[head]];\n                if (c[v] == 0)\n                    mask |= (1L << v);\n                c[v]++;\n                head++;\n            }\n            while (tail < head && mask == need) {\n                res = Math.min(res, head - tail);\n\n                int v = look[a[tail]];\n                c[v]--;\n                if (c[v] == 0)\n                    mask ^= (1L << v);\n\n\n                tail++;\n            }\n        }\n        io.writeLine(res + \"\");\n    }\n\n\n    long gcd(long a, long b) {\n        if (a < b) return gcd(b, a);\n        if (b == 0) return a;\n        return gcd(b, a % b);\n    }\n}\n\nclass ConsoleIO {\n    BufferedReader br;\n    PrintWriter out;\n    public ConsoleIO(){br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}\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 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 readLong() {\n        return Long.parseLong(this.readLine());\n    }\n    public long[] readLongArray() {\n        String[]n=this.readLine().trim().split(\"\\\\s+\");long[]r=new long[n.length];\n        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);\n        return r;\n    }\n    public int[] readIntArray() {\n        String[]n=this.readLine().trim().split(\"\\\\s+\");int[]r=new int[n.length];\n        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);\n        return r;\n    }\n    public int[] readIntArray(int n) {\n        int[] res = new int[n];\n        char[] all = this.readLine().toCharArray();\n        int cur = 0;boolean have = false;\n        int k = 0;\n        boolean neg = false;\n        for(int i = 0;i<all.length;i++){\n            if(all[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 readInt() {\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 void writeIntArray(int[] a) {\n        StringBuilder sb = new StringBuilder();\n        for (int i = 0; i < a.length; i++) {if (i > 0) sb.append(' ');sb.append(a[i]);}\n        this.writeLine(sb.toString());\n    }\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 Tri {\n    public Tri(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}\nclass PairLL {\n    public PairLL(long a, long b) {this.a = a;this.b = b;}\n    public long a;\n    public long b;\n}\n\n\n\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class C{\n\tstatic String s;\n\tstatic long val[];\n\tstatic int N,size;\n\tstatic int index(char c){\n\t\tif(c <= 'Z'){\n\t\t\treturn c - 'A';\n\t\t}else{\n\t\t\treturn c - 'a' + ('Z' - 'A' + 1);\n\t\t}\n\t}\n\n\tstatic int l(int i){\n\t\treturn (i<<1)+1;\n\t}\n\tstatic int r(int i){\n\t\treturn (i<<1)+2;\n\t}\n\n\tstatic void setup(int l, int r, int i){\n\t\tif(l==r){\n\t\t\tval[i] = (1L<<index(s.charAt(l)));\n\t\t}else{\n\t\t\tint mid = (l+r)/2;\n\t\t\tsetup(l,mid,l(i));\n\t\t\tsetup(mid+1,r,r(i));\n\t\t\tval[i] = val[l(i)] | val[r(i)];\n\t\t}\n\t}\n\n\tstatic long query(int min, int max, int l, int r, int i){\n\t\tif(min <= l && r <= max){\n\t\t\treturn val[i];\n\t\t}\n\t\tif(max < l || r < min)\n\t\t\treturn 0;\n\t\tint mid = (l+r)/2;\n\t\treturn query(min,max,l,mid,l(i)) | query(min,max,mid+1,r,r(i));\n\t}\n\tstatic long query(int min, int max){\n\t\treturn query(min,max,0,N-1,0);\n\t}\n\n\tstatic int binarySearch(int start, long toFind){\n\t\tint max = N-1;\n\t\tint min = start;\n\t\tif(query(start,max) != toFind)\n\t\t\treturn 1<<29;\n\t\tif(query(start,start) == toFind){\n\t\t\treturn 1;\n\t\t}\n\t\tint ret = max - min + 1;\n\t\twhile(min + 1 < max){\n\t\t\tint mid = (min+max)/2;\n\t\t\tif(query(start,mid) == toFind){\n\t\t\t\tmax = mid;\n\t\t\t}else{\n\t\t\t\tmin = mid;\n\t\t\t}\n\t\t}\n\t\treturn max-start+1;\n\t}\n\n\tpublic static void main(String args[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\tN = sc.nextInt();\n\t\ts = sc.next();\n\t\tint size = 1;\n\t\twhile(size <= N) size*=2;\n\t\tval = new long[size*2];\n\t\tsetup(0,N-1,0);\n\n\t\tlong toFind = query(0,N-1,0,N-1,0);\n\t\tlong ans = 1L<<29;\n\t\tfor(int i = 0; i < N; i++)\n\t\t\tans = Math.min(ans,binarySearch(i,toFind));\n\t\tSystem.out.println(ans);\n\t}\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.HashMap;\nimport java.util.HashSet;\n\n\npublic class C {\n\n\tprivate static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static PrintStream out = System.out;\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tint n = Integer.parseInt(in.readLine());\n\t\tchar[] s = in.readLine().toCharArray();\n\t\tHashSet<Character> all = new HashSet<Character>();\n\t\tfor (char c : s)\n\t\t\tall.add(c);\n\t\tint totalCount = all.size();\n\t\tHashMap<Character, Integer> cnts = new HashMap<Character, Integer>();\n\t\tint ans = Integer.MAX_VALUE;\n\t\tint x = 0;\n\t\tfor (int y = 0; y < n; ++y) {\n\t\t\tif (!cnts.containsKey(s[y]))\n\t\t\t\tcnts.put(s[y], 0);\n\t\t\tcnts.put(s[y], cnts.get(s[y]) + 1);\n\t\t\tif (cnts.size() < totalCount)\n\t\t\t\tcontinue;\n\t\t\twhile (cnts.get(s[x]) > 1) {\n\t\t\t\tcnts.put(s[x], cnts.get(s[x]) - 1);\n\t\t\t\t++x;\n\t\t\t}\n\t\t\tans = Math.min(ans, y - x + 1);\n\t\t}\n\t\tout.println(ans);\n\t}\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * Created by Daniil on 5/29/2016.\n */\npublic class TaskB {\n\n\n    public static int strIndex;\n    public static void main(String[] args) throws IOException {\n\n        Scanner scanner = new Scanner(System.in);\n\n        int n = scanner.nextInt();\n\n        char[] s = scanner.next().toCharArray();\n\n        int[][] r = new int[n][54];\n\n        Set<Character> chars = new HashSet<>();\n\n        for (int i= 0 ;i < n; ++ i)chars.add(s[i]);\n\n        List<Character> all = new ArrayList<>();\n\n        for (Character c: chars)all.add(c);\n\n        for (int i = n - 1; i >= 0; -- i){\n            for (int j = 0;j < 54; ++ j){\n                if (i == n - 1){\n                    r[i][j] = -1;\n                }else {\n                    r[i][j] = r[i + 1][j];\n                }\n            }\n            r[i][getCode(s[i])] = i;\n        }\n\n        int res = n;\n\n\n        for (int i =0; i < n; ++ i){\n            int mx = 1;\n            boolean fl = false;\n            for (Character c: all){\n                if (r[i][getCode(c)] == -1){\n                    fl = true;\n                    break;\n                }\n                mx = Math.max(mx, r[i][getCode(c)] - i + 1);\n            }\n            if (fl){\n                System.out.println(res);\n                return;\n            }\n            res = Math.min(res, mx);\n        }\n        System.out.println(res);\n\n        scanner.close();\n        //reader.close();\n    }\n\n    public static int getCode(char a){\n        if (Character.isUpperCase(a))return a - 'A';\n        return (a - 'a') + 26;\n    }\n\n    public static int getLetter(int n){\n        if (n > 25)return (char)((n - 26) + 'a');\n        return (char)((n) + 'A');\n    }\n\n\n\n    static class IO{\n\n\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n        PrintWriter writer;\n\n        public void init() {\n            try {\n                reader = new BufferedReader(new InputStreamReader(System.in),8*1024);\n                writer = new PrintWriter(System.out);\n            } catch (Exception e) {\n                e.printStackTrace();\n                System.exit(261);\n            }\n        }\n\n        void destroy() {\n            writer.close();\n            System.exit(0);\n        }\n\n        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        void println(Object... objects) {\n            print(objects);\n            writer.println();\n        }\n\n        String nextLine() throws IOException {\n            return reader.readLine();\n        }\n\n        String nextToken() throws IOException {\n            while (tokenizer == null || !tokenizer.hasMoreTokens())\n                tokenizer = new StringTokenizer(nextLine());\n            return tokenizer.nextToken();\n        }\n\n        int nextInt() throws NumberFormatException, IOException {\n            return Integer.parseInt(nextToken());\n        }\n\n        long nextLong() throws NumberFormatException, IOException {\n            return Long.parseLong(nextToken());\n        }\n\n        double nextDouble() throws NumberFormatException, IOException {\n            return Double.parseDouble(nextToken());\n        }\n    }\n\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\n@SuppressWarnings(\"unchecked\")\npublic class P701A {\n\n  Map<Character, Integer> cc = new HashMap(72);\n\n  void add(char c) {\n    cc.put(c, cc.getOrDefault(c, 0) + 1);\n  }\n\n  void rem(char c) {\n    Integer cnt = cc.get(c) - 1;\n    if (cnt != 0) {\n      cc.put(c, cnt);\n    } else {\n      cc.remove(c);\n    }\n  }\n\n  public void run() throws Exception {\n    int n = nextInt();\n\n    char [] s = next().toCharArray();\n    BitSet bs = new BitSet();\n    for (char c : s) {\n      bs.set(c);\n    }\n\n    int t = bs.cardinality();\n    \n    int m = Integer.MAX_VALUE;\n    for (int i = 0, j = 0; i < n; i++) {\n      while ((j < n) && (cc.size() < t)) {\n        add(s[j]);\n        j++;\n      }\n      \n      if (cc.size() == t) {\n        m = Math.min(m, j - i);\n      }\n      \n      rem(s[i]);\n    }\n    \n    println(m);\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 P701A().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}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashSet;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t// TODO Auto-generated method stub\n\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(in.readLine());\n\t\tString in1 = in.readLine();\n\t\tString store = \"\";\n\t\tHashSet<Character> contain = new HashSet<Character>();\n\t\tfor(int i = 0; i < n;i++){\n\t\t\tif(!contain.contains(in1.charAt(i))){\n\t\t\t\tstore += in1.charAt(i);\n\t\t\t\tcontain.add(in1.charAt(i));\n\t\t\t}\n\t\t}\n\t\tint[] index = new int[store.length()];\n\t\tfor(int i = 0; i < store.length(); i++){\n\t\t\tindex [i] = -1;\n\t\t}\n\t\tHashSet<Integer> index2 = new HashSet<Integer>();\n\t\tArrayList<Integer> index3 = new ArrayList<Integer>();\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tint index4 = store.indexOf(in1.charAt(i));\n\t\t\tif(index[index4] == -1){\n\t\t\t\tindex[index4] = i;\n\t\t\t\tindex2.add(i);\n\t\t\t\tindex3.add(i);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tindex2.remove(index[index4]);\n\t\t\t\tindex2.add(i);\n\t\t\t\tindex3.add(i);\n\t\t\t\tindex[index4] = i;\n\t\t\t}\n\t\t\tif(index2.size() == index.length){\n\t\t\t\twhile(!index2.contains(index3.get(0))){\n\t\t\t\t\tindex3.remove(0);\n\t\t\t\t}\n\t\t\t\tmin = Math.min(min, i - index3.get(0)+ 1);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.println(min);\n\t}\n\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.* ;\nimport java.util.* ;\npublic class Codeshefcode {\n\tfinal static long r = 1000000007 ;\n\tstatic FasterScanner ip = new FasterScanner() ;\n\tstatic PrintWriter op = new PrintWriter(System.out) ;\n\tpublic static void main(String[] args) throws IOException{\n\t    int n = ip.i() ;\n\t    TreeMap<Character,Integer> map = new TreeMap<Character,Integer>() ;\n\t    TreeSet<Character> set = new TreeSet<Character>() ;\n\t    char c[] = ip.S().toCharArray() ;\n\t    for(char t : c)\n\t    \tset.add(t) ;\n\t    int size = set.size() ;\n\t    for(int i=0 ; i<size ; i++)\n\t    \tmap.put(set.pollFirst(),i) ;\n\t    int a[] = new int[n] ;\n\t    for(int i=0 ; i<n ; i++)\n\t    \ta[i]=map.get(c[i]) ;\n\t    int erl[][] = new int[size][n] ;\n\t    for(int i=0 ; i<size ; i++)\n\t    \tfor(int j=n-1 ; j>=0 ; j--)\n\t    \t\terl[i][j]=(a[j]==i) ? j : (j==n-1 ? -1 : erl[i][j+1]) ;\n\t    long min = Long.MAX_VALUE ;\n\t    for(int i=0 ; i<n ; i++){\n\t    \tlong maxt = Long.MIN_VALUE ;\n\t    \tfor(int j=0 ; j<size ; j++)\t\t\n\t    \t\tif(erl[j][i]!=-1)\n\t    \t\t\tmaxt = Long.max(maxt,(erl[j][i]-i+1)) ;\n\t    \t\telse{\n\t    \t\t\tmaxt = Long.MAX_VALUE ;\n\t    \t\t\tbreak ;\n\t    \t\t}\n\t    \tmin = Long.min(min,maxt) ;\t    \t\n\t    }\n\t    op.print(min) ;\n\t\tFinish() ;\n\t}\n\tstatic void Finish(){\n\t   op.flush(); \n\t   op.close();\n    }\t\n}\n@SuppressWarnings(\"serial\") \nclass MyList extends ArrayList<Long>{\n\t\n}\nclass pair {\n\tprivate int x  ;\n\tprivate int y ;\n\tpair(int a,int b){\n\t\tx=a ;\n\t\ty=b ;\t\t\n\t}\n\tpublic int x(){\n\t\treturn x ;\n\t}\n\tpublic int y(){\n\t\treturn y ;\n\t}\n}\nclass FasterScanner { \n    private InputStream mIs;\n    private byte[] buf = new byte[1024];\n    private int curChar;\n    private int numChars; \n    public FasterScanner() {\n        this(System.in);\n    } \n    public FasterScanner(InputStream is) {\n        mIs = is;\n    } \n    public int read() {\n        if (numChars == -1) \n            throw new InputMismatchException();    \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        return buf[curChar++];\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    public String S(){\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    public long l(){\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 int i(){\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        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    } \n    public boolean isEndOfLine(int c) {\n        return c == '\\n' || c == '\\r' || c == -1;\n    } \n} ", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.Random;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        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.readInt();\n            char[] str = IOUtils.readCharArray(in, n);\n            for (int i = 0; i < n; i++) {\n                if (str[i] <= 'Z') {\n                    str[i] = (char) (str[i] - 'A');\n                } else {\n                    str[i] = (char) (str[i] - 'a' + 26);\n                }\n            }\n\n            IntHashSet set = new IntHashSet();\n            for (char c : str) {\n                set.add(c);\n            }\n            int max = 26 + 26;\n            int[][] next = new int[max][n];\n            ArrayUtils.fill(next, -1);\n\n            for (int i = n - 2; i >= 0; i--) {\n                for (int ch = 0; ch < max; ch++) {\n                    next[ch][i] = next[ch][i + 1];\n                }\n                next[str[i + 1]][i] = i + 1;\n            }\n\n            int ans = (int) 1e9;\n            final int tagetCnt = set.size();\n            for (int s = 0; s < n; s++) {\n                boolean[] used = new boolean[max];\n                used[str[s]] = true;\n                int cnt = 1;\n                int pos = s;\n                while (cnt < tagetCnt) {\n                    int nextPos = n;\n                    for (int ch = 0; ch < max; ch++) {\n                        if (!used[ch]) {\n                            if (next[ch][pos] == -1) {\n                                continue;\n                            }\n                            nextPos = Math.min(nextPos, next[ch][pos]);\n                        }\n                    }\n\n                    pos = nextPos;\n                    if (nextPos == n) {\n                        break;\n                    }\n                    ++cnt;\n                    used[str[nextPos]] = true;\n                }\n                if (pos == n) {\n                    break;\n                }\n                ans = Math.min(ans, pos - s + 1);\n            }\n            out.printLine(ans);\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 interface IntStream extends Iterable<Integer>, Comparable<IntStream> {\n        public IntIterator intIterator();\n\n        default public Iterator<Integer> iterator() {\n            return new Iterator<Integer>() {\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 IntHashSet extends IntAbstractStream implements IntSet {\n        private static final Random RND = new Random();\n        private static final int[] SHIFTS = new int[4];\n        private static final byte PRESENT_MASK = 1;\n        private static final byte REMOVED_MASK = 2;\n        private int size;\n        private int realSize;\n        private int[] values;\n        private byte[] present;\n        private int step;\n        private int ratio;\n\n        static {\n            for (int i = 0; i < 4; i++) {\n                SHIFTS[i] = RND.nextInt(31) + 1;\n            }\n        }\n\n        public IntHashSet() {\n            this(3);\n        }\n\n        public IntHashSet(int capacity) {\n            capacity = Math.max(capacity, 3);\n            values = new int[capacity];\n            present = new byte[capacity];\n            ratio = 2;\n            initStep(capacity);\n        }\n\n        public IntHashSet(IntCollection c) {\n            this(c.size());\n            addAll(c);\n        }\n\n        public IntHashSet(int[] arr) {\n            this(new IntArray(arr));\n        }\n\n        private void initStep(int capacity) {\n            step = RND.nextInt(capacity - 2) + 1;\n            while (IntegerUtils.gcd(step, capacity) != 1) {\n                step++;\n            }\n        }\n\n\n        public IntIterator intIterator() {\n            return new IntIterator() {\n                private int position = size == 0 ? values.length : -1;\n\n                public int value() throws NoSuchElementException {\n                    if (position == -1) {\n                        advance();\n                    }\n                    if (position >= values.length) {\n                        throw new NoSuchElementException();\n                    }\n                    if ((present[position] & PRESENT_MASK) == 0) {\n                        throw new IllegalStateException();\n                    }\n                    return values[position];\n                }\n\n                public boolean advance() throws NoSuchElementException {\n                    if (position >= values.length) {\n                        throw new NoSuchElementException();\n                    }\n                    position++;\n                    while (position < values.length && (present[position] & PRESENT_MASK) == 0) {\n                        position++;\n                    }\n                    return isValid();\n                }\n\n                public boolean isValid() {\n                    return position < values.length;\n                }\n\n                public void remove() {\n                    if ((present[position] & PRESENT_MASK) == 0) {\n                        throw new IllegalStateException();\n                    }\n                    present[position] = REMOVED_MASK;\n                }\n            };\n        }\n\n\n        public int size() {\n            return size;\n        }\n\n\n        public void add(int value) {\n            ensureCapacity((realSize + 1) * ratio + 2);\n            int current = getHash(value);\n            while (present[current] != 0) {\n                if ((present[current] & PRESENT_MASK) != 0 && values[current] == value) {\n                    return;\n                }\n                current += step;\n                if (current >= values.length) {\n                    current -= values.length;\n                }\n            }\n            while ((present[current] & PRESENT_MASK) != 0) {\n                current += step;\n                if (current >= values.length) {\n                    current -= values.length;\n                }\n            }\n            if (present[current] == 0) {\n                realSize++;\n            }\n            present[current] = PRESENT_MASK;\n            values[current] = value;\n            size++;\n        }\n\n        private int getHash(int value) {\n            int hash = IntHash.hash(value);\n            int result = hash;\n            for (int i : SHIFTS) {\n                result ^= hash >> i;\n            }\n            result %= values.length;\n            if (result < 0) {\n                result += values.length;\n            }\n            return result;\n        }\n\n        private void ensureCapacity(int capacity) {\n            if (values.length < capacity) {\n                capacity = Math.max(capacity * 2, values.length);\n                rebuild(capacity);\n            }\n        }\n\n        private void rebuild(int capacity) {\n            initStep(capacity);\n            int[] oldValues = values;\n            byte[] oldPresent = present;\n            values = new int[capacity];\n            present = new byte[capacity];\n            size = 0;\n            realSize = 0;\n            for (int i = 0; i < oldValues.length; i++) {\n                if ((oldPresent[i] & PRESENT_MASK) == PRESENT_MASK) {\n                    add(oldValues[i]);\n                }\n            }\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 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 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 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 IntHash {\n        private IntHash() {\n        }\n\n        public static int hash(int c) {\n            return c;\n        }\n\n    }\n\n    static interface IntReversableCollection extends IntCollection {\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 IntArray extends IntAbstractStream implements IntList {\n        private int[] data;\n\n        public IntArray(int[] arr) {\n            data = arr;\n        }\n\n        public int size() {\n            return data.length;\n        }\n\n        public int get(int at) {\n            return data[at];\n        }\n\n        public void addAt(int index, int value) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void removeAt(int index) {\n            throw new UnsupportedOperationException();\n        }\n\n    }\n\n    static interface IntSet extends IntCollection {\n    }\n\n    static class IOUtils {\n        public static char[] readCharArray(InputReader in, int size) {\n            char[] array = new char[size];\n            for (int i = 0; i < size; i++) {\n                array[i] = in.readCharacter();\n            }\n            return array;\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 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\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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.TreeSet;\nimport java.io.File;\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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public int[] parse(FastScanner in, int n) {\n            String s = in.next();\n            int[] temp = new int[n];\n            for (int i = 0; i < n; ++i) {\n                temp[i] = s.charAt(i) - 'A';\n            }\n            return temp;\n        }\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] s = parse(in, n);\n\n            Map<Integer, TreeSet<Integer>> map = new HashMap<>();\n            for (int i = 0; i < n; ++i) {\n                if (map.containsKey(s[i])) {\n                    map.get(s[i]).add(i);\n                } else {\n                    TreeSet<Integer> temp = new TreeSet<>();\n                    temp.add(i);\n                    map.put(s[i], temp);\n                }\n            }\n            int ans = Integer.MAX_VALUE;\n            for (int i = 0; i < n; ++i) {\n                int finalI = i;\n                final Int integer = new Int();\n                integer.x = i;\n                map.forEach((Integer x, TreeSet set) -> {\n                    if (x != s[finalI]) {\n                        Integer temp = (Integer) set.higher(finalI);\n                        if (temp == null) {\n                            integer.x = -2;\n                        } else {\n                            if (integer.x != -2)\n                                integer.x = Integer.max(integer.x, temp);\n                        }\n                    } else {\n                    }\n                });\n\n                if (integer.x != -2) {\n                    ans = Integer.min(ans, integer.x - i + 1);\n                }\n            }\n\n            out.print(ans);\n        }\n\n        public class Int {\n            int x;\n\n            public Int() {\n                x = -1;\n            }\n\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader br;\n        private 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 inputStream) {\n            br = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n\n\tBufferedReader in;\n\tStringTokenizer str = null;\n\tPrintWriter out;\n\t\n\tprivate String next() throws Exception{\n\t\twhile (str == null || !str.hasMoreElements())\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\treturn str.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate long nextLong() throws Exception{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate double nextDouble() throws Exception{\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tfinal int oo = Integer.MAX_VALUE;\n\t\n\tint [][]s;\n\tint n, ALL;\n\tpublic void run() throws Exception{\n\t\tin =  new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tn = nextInt();\n\t\tchar []a = next().toCharArray();\n\t\ts = new int[n][52];\n\t\tboolean []set = new boolean[52];\n\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tint pos = get(a[i]);\n\t\t\tif (!set[pos]) {\n\t\t\t\t++ALL;\n\t\t\t\tset[pos] = true;\n\t\t\t}\n\t\t\tfor(int j = 0; j < 52; ++j) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\ts[i][j] += s[i-1][j];\t\n\t\t\t\t}\n\t\t\t\tif (j == pos) {\n\t\t\t\t\ts[i][j]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint ret = oo;\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tret = Math.min(ret, get(i));\n\t\t}\n\n\t\tout.println(ret);\n\t\tout.close();\n\t}\n\n\tprivate int get(int i) {\n\t\tint lo = i - 1, hi = n;\n\t\twhile(hi - lo > 1) {\n\t\t\tint m = lo + (hi - lo) / 2;\n\t\t\tint c = 0;\n\t\t\tfor(int j = 0; j < 52; ++j) {\n\t\t\t\tif (sum(j, i, m) > 0) {\n\t\t\t\t\t++c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (c < ALL) {\n\t\t\t\tlo = m;\n\t\t\t} else {\n\t\t\t\thi = m;\n\t\t\t}\n\t\t}\n\n\t\tif (hi != n) {\n\t\t\treturn hi - i + 1;\n\t\t}\n\t\treturn oo;\n\t}\n\n\tprivate int sum(int pos, int l, int r) {\n\t\tint ret = s[r][pos];\n\t\tif (l > 0) ret -= s[l - 1][pos];\n\t\treturn ret;\n\t}\n\n\tprivate int get(char x) {\n\t\tif ('a' <= x && x <= 'z') return (int)(x - 'a');\n\t\treturn (int)(x - 'A' + 26);\n\t}\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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.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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int N = in.nextInt();\n            String word = in.next();\n\n            int cnt[] = new int[1000];\n\n            int let = 0;\n            Set<Character> set = new TreeSet<>();\n            for (int i = 0; i < word.length(); i++) {\n                set.add(word.charAt(i));\n            }\n            int uniq = set.size();\n            int i = 0, j = -1;\n            int ans = Integer.MAX_VALUE;\n            while (i < N && j < N) {\n                while (j + 1 < N && let < uniq) {\n                    j++;\n                    if (cnt[word.charAt(j)] == 0) {\n                        let++;\n                    }\n                    cnt[word.charAt(j)]++;\n                }\n                if (let == uniq)\n                    ans = Math.min(ans, j - i + 1);\n                cnt[word.charAt(i)]--;\n                if (cnt[word.charAt(i)] == 0) let--;\n                i++;\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\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n    public static void main(String[] args) throws IOException {\n\tBufferedReader in =\n\t    new BufferedReader(new InputStreamReader(System.in));\n\tint n = Integer.parseInt(in.readLine());\n\tchar[] ps = in.readLine().toCharArray();\n\tHashMap<Character, TreeSet<Integer>> locs =\n\t    new HashMap<Character, TreeSet<Integer>>();\n\tHashSet<Character> poks = new HashSet<Character>();\n\tint lastNew = n;\n\tfor (int i = 0; i < n; i++) {\n\t    if (!poks.contains(ps[i])) {\n\t\tpoks.add(ps[i]);\n\t\tlocs.put(ps[i], new TreeSet<Integer>());\n\t\tlastNew = i;\n\t    }\n\t    locs.get(ps[i]).add(i);\n\t}\n\tint max = lastNew;\n\tint minRange = max+1;\n\tfor (int min = 0; min < n; min++) {\n\t    char pAtMin = ps[min];\n\t    Integer nextInd = locs.get(pAtMin).higher(min);\n\t    if (nextInd == null) break;\n\t    max = Math.max(max, nextInd);\n\t    minRange = Math.min(minRange, max-min);\n\t}\n\tSystem.out.println(minRange);\n    }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Random;\n\npublic class ProblemC {\n  \n  public static void main(String[] args) throws IOException {\n    init();\n    new ProblemC().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<L, R> {\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  \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 void sort(int[] a) {\n    Random rnd = new Random();\n    for (int i = a.length - 1; i > 0; i--) {\n      int index = rnd.nextInt(i);\n      a[i] ^= a[index];\n      a[index] ^= a[i];\n      a[i] ^= a[index];\n    }\n    Arrays.sort(a);\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  int K, L, M, N, P;\n  \n  private void solve() throws IOException {\n    int[] countChars = new int['z' + 1];\n    boolean[] gotIt = new boolean['z' + 1];\n    int N = nextInt();\n    int fullCount = 0;\n    char[] chars = next().toCharArray();\n    for (int i = 0; i < N; i++) {\n      if (countChars[chars[i]] == 0) fullCount++;\n      countChars[chars[i]]++;\n    }\n//    out.println(fullCount);\n    \n    countChars = new int['z' + 1];\n    int answer = N;\n    int start = 0, finish = 0;\n    countChars[chars[start]]++;\n    fullCount--;\n    \n    while (finish+1 < N){\n      finish++;\n      if (countChars[chars[finish]] == 0) {\n        fullCount--;\n      }\n      countChars[chars[finish]]++;\n      while (countChars[chars[start]] > 1){\n        countChars[chars[start]]--;\n        start++;\n      }\n      while (fullCount == 0){\n//        out.println(\"start = \" + (start+1));\n//        out.println(\"finish = \" + (finish+1));\n        answer = Math.min(answer, finish-start+1);\n        countChars[chars[start]]--;\n        if (countChars[chars[start]] == 0) fullCount++;\n        start++;\n      }\n    }\n    \n    out.println(answer);\n  }\n  \n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author xwchen\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            int n = in.nextInt();\n            String s = in.next();\n\n            int[] cnt = new int[26];\n            int[] cnt2 = new int[26];\n            int j = 0;\n            int res = n;\n            HashSet<Character> set = new HashSet<Character>();\n            for (char c : s.toCharArray()) {\n                set.add(c);\n            }\n            int m = set.size();\n\n            for (int i = 0; i < n; ++i) {\n                if (Character.isLowerCase(s.charAt(i))) {\n                    cnt[s.charAt(i) - 'a']++;\n                } else {\n                    cnt2[s.charAt(i) - 'A']++;\n                }\n                while (isOK(cnt, cnt2, m)) {\n                    res = Math.min(res, i - j + 1);\n                    if (Character.isLowerCase(s.charAt(j))) {\n                        cnt[s.charAt(j) - 'a']--;\n                    } else {\n                        cnt2[s.charAt(j) - 'A']--;\n                    }\n                    ++j;\n                }\n            }\n            out.println(res);\n        }\n\n        boolean isOK(int[] cnt, int[] cnt2, int m) {\n            int c = 0;\n            for (int i = 0; i < 26; ++i) {\n                if (cnt[i] > 0) {\n                    ++c;\n                }\n            }\n            for (int i = 0; i < 26; ++i) {\n                if (cnt2[i] > 0) {\n                    ++c;\n                }\n            }\n            return c >= m;\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.InputMismatchException;\n\n\npublic class Cf2207C {\n\n    private static InputReader in = new InputReader(System.in);\n    private static OutputWriter out = new OutputWriter(System.out);\n\n    private static void solve() throws Exception {\n        int n = in.readInt();\n        String s = in.readString();\n        int[] count = new int[200];\n        boolean[] flag = new boolean[200];\n        for(int i=0; i<n; ++i){\n            flag[s.charAt(i)] = true;\n        }\n        int ref = 0;\n        for(int i=0; i<200; ++i){\n            if(flag[i]){\n                ref++;\n            }\n        }\n\n        int total = 0;\n        int min  = Integer.MAX_VALUE;\n        int j = 0;\n        for(int i=0; i<n; ++i){\n            if((j==n)&&(total<ref)){\n                break;\n            }\n            if(total==ref){\n                min = Math.min(min,j-i);\n                count[s.charAt(i)]--;\n                if(count[s.charAt(i)]==0){\n                    total--;\n                }\n                continue;\n            }\n            for(;j<n; ++j){\n                count[s.charAt(j)]++;\n                if(count[s.charAt(j)]==1){\n                    total++;\n                }\n                if(total==ref){\n                    min = Math.min(min,j-i+1);\n                    j++;\n                    break;\n                }\n            }\n\n            count[s.charAt(i)]--;\n            if(count[s.charAt(i)]==0){\n                total--;\n            }\n\n        }\n        out.println(min);\n    }\n\n    public static void main(String[] args) throws Exception {\n        solve();\n        out.close();\n    }\n\n    private static class InputReader {\n        private InputStream stream;\n        private byte[] buffer;\n        private int currentIndex;\n        private int bytesRead;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n            buffer = new byte[16384];\n        }\n\n        public InputReader(InputStream stream, int bufferSize) {\n            this.stream = stream;\n            buffer = new byte[bufferSize];\n        }\n\n        private int read() throws IOException {\n            if (currentIndex >= bytesRead) {\n                currentIndex = 0;\n                bytesRead = stream.read(buffer);\n                if (bytesRead <= 0) {\n                    return -1;\n                }\n            }\n            return buffer[currentIndex++];\n        }\n\n        public String readString() throws IOException {\n            int c = read();\n            while (!isPrintable(c)) {\n                c = read();\n            }\n            StringBuilder result = new StringBuilder();\n            do {\n                result.appendCodePoint(c);\n                c = read();\n            } while (isPrintable(c));\n            return result.toString();\n        }\n\n        public int readInt() throws Exception {\n            int c = read();\n            int sign = 1;\n            while (!isPrintable(c)) {\n                c = read();\n            }\n            if (c == '-') {\n                sign = -1;\n                c = read();\n            }\n            int result = 0;\n            do {\n                if ((c < '0') || (c > '9')) {\n                    throw new InputMismatchException();\n                }\n                result *= 10;\n                result += (c - '0');\n                c = read();\n            } while (isPrintable(c));\n            return sign * result;\n        }\n\n        public long readLong() throws Exception {\n            int c = read();\n            int sign = 1;\n            while (!isPrintable(c)) {\n                c = read();\n            }\n            if (c == '-') {\n                sign = -1;\n                c = read();\n            }\n            long result = 0;\n            do {\n                if ((c < '0') || (c > '9')) {\n                    throw new InputMismatchException();\n                }\n                result *= 10;\n                result += (c - '0');\n                c = read();\n            } while (isPrintable(c));\n            return sign * result;\n        }\n\n        public double readDouble() throws Exception {\n            int c = read();\n            int sign = 1;\n            while (!isPrintable(c)) {\n                c = read();\n            }\n            if (c == '-') {\n                sign = -1;\n                c = read();\n            }\n            boolean fraction = false;\n            double multiplier = 1;\n            double result = 0;\n            do {\n                if ((c == 'e') || (c == 'E')) {\n                    return sign * result * Math.pow(10, readInt());\n                }\n                if ((c < '0') || (c > '9')) {\n                    if ((c == '.') && (!fraction)) {\n                        fraction = true;\n                        c = read();\n                        continue;\n                    }\n                    throw new InputMismatchException();\n                }\n                if (fraction) {\n                    multiplier /= 10;\n                    result += (c - '0') * multiplier;\n                    c = read();\n                } else {\n                    result *= 10;\n                    result += (c - '0');\n                    c = read();\n                }\n            } while (isPrintable(c));\n            return sign * result;\n        }\n\n        private boolean isPrintable(int c) {\n            return ((c > 32) && (c < 127));\n        }\n    }\n\n    private static class OutputWriter {\n        private 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 flush() {\n            writer.flush();\n        }\n    }\n\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.BufferedOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.HashSet;\npublic class C {\n\tpublic static void main(String args[]) {\n\t\tKattio sc = new Kattio(System.in);\n\t\tint n = sc.getInt();\n\t\tString s = sc.getWord();\n\t\tint[] found = new int['z' + 1];\n\t\tint amount = 0;\n\t\tfor(int i = 0; i<s.length(); i++) {\n\t\t\tchar c = s.charAt(i);\n\t\t\tif(found[c] == 0) amount++;\n\t\t\tfound[c]++;\n\t\t}\n\t\tint contains[] = new int['z' + 1];\n\t\tint min = n;\n\t\tint start = 0;\n\t\tint end = 0;\n\t\tint in = 0;\n\t\twhile(true) {\n\t\t\tif(in<amount) {\n\t\t\t\tif(end == n) break;\n\t\t\t\tchar c = s.charAt(end);\n\t\t\t\tif(contains[c] == 0) in++;\n\t\t\t\tcontains[c]++;\n\t\t\t\tend++;\n\t\t\t} else {\n\t\t\t\tif(min>end-start) min = end-start;\n\t\t\t\tchar c = s.charAt(start);\n\t\t\t\tif(contains[c] == 1) in--;\n\t\t\t\tcontains[c]--;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(min);\n\n\n\t}\n}\nclass Kattio extends PrintWriter {\n    public Kattio(InputStream i) {\n\tsuper(new BufferedOutputStream(System.out));\n\tr = new BufferedReader(new InputStreamReader(i));\n    }\n    public Kattio(InputStream i, OutputStream o) {\n\tsuper(new BufferedOutputStream(o));\n\tr = new BufferedReader(new InputStreamReader(i));\n    }\n\n    public boolean hasMoreTokens() {\n\treturn peekToken() != null;\n    }\n\n    public int getInt() {\n\treturn Integer.parseInt(nextToken());\n    }\n\n    public double getDouble() { \n\treturn Double.parseDouble(nextToken());\n    }\n\n    public long getLong() {\n\treturn Long.parseLong(nextToken());\n    }\n\n    public String getWord() {\n\treturn nextToken();\n    }\n\n\n\n    private BufferedReader r;\n    private String line;\n    private StringTokenizer st;\n    private String token;\n\n    private String peekToken() {\n\tif (token == null) \n\t    try {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t    line = r.readLine();\n\t\t    if (line == null) return null;\n\t\t    st = new StringTokenizer(line);\n\t\t}\n\t\ttoken = st.nextToken();\n\t    } catch (IOException e) { }\n\treturn token;\n    }\n\n    private String nextToken() {\n\tString ans = peekToken();\n\ttoken = null;\n\treturn ans;\n    }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * @author grozhd\n */\npublic class P3 {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt();\n\n        String s = \"\";\n        while (s.length() == 0) {\n            s = sc.nextLine();\n        }\n        char[] pokemons = s.toCharArray();\n\n        Set<Character> pokemonTypes = new HashSet<>();\n        for (int i = 0; i < n; i++) {\n            pokemonTypes.add(pokemons[i]);\n        }\n\n        int types = pokemonTypes.size();\n\n        int l = 0;\n        int r = 0;\n        int min = n;\n        Map<Character, Integer> currentPokemons = new HashMap<>();\n\n\n        while (r < n) {\n            while (currentPokemons.size() < types && r < n) {\n                char pokemon = pokemons[r++];\n                currentPokemons.merge(pokemon, 1, (a, b) -> a + b);\n            }\n            min = Math.min(r - l, min);\n\n            while (currentPokemons.size() == types) {\n                char pokemon = pokemons[l++];\n                if (currentPokemons.get(pokemon) == 1) {\n                    currentPokemons.remove(pokemon);\n                } else {\n                    min = Math.min(r - l, min);\n                    currentPokemons.put(pokemon, currentPokemons.get(pokemon) - 1);\n                }\n            }\n        }\n\n        min = Math.min(min, r - l + 1);\n        min = Math.max(min, types);\n\n        System.out.println(min);\n\n    }\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\n    void change(int [] all, char c, int val) {\n        if (Character.isUpperCase(c))\n            all[c - 'A' + 26] += val;\n        else\n            all[c - 'a'] += val;\n    }\n\n    int countDistinct(int [] a) {\n        int res = 0;\n        for (int i = 0 ; i< a.length ; i++) {\n            if (a[i] > 0)\n                res ++;\n        }\n        return res;\n    }\n    public void solve() throws IOException {\n        int n = nextInt();\n        String s = next();\n\n        int [] all = new int[52];\n        for (int i = 0 ; i < s.length() ; i++) {\n            char c = s.charAt(i);\n            change(all, c, 1);\n        }\n        int distinct = countDistinct(all);\n\n        int [] window = new int[52];\n        int best = n;\n        for (int i = 0, j = 0 ; i < s.length() ; i++) {\n\n            if (i > 0) {\n                change(window, s.charAt(i-1), -1);\n            }\n            while (j < s.length()) {\n                if (countDistinct(window) == distinct)\n                    break;\n\n                change(window, s.charAt(j), 1);\n                j ++;\n            }\n            if (countDistinct(window) < distinct)\n                break;\n\n            best = Math.min(best, j - i);\n        }\n        out.println(best);\n    }\n\n    \n\n    \n    \n    BufferedReader bf;\n    StringTokenizer st;\n    PrintWriter out;\n    \n    public String next() throws IOException {\n        while (st == null || !st.hasMoreTokens()) \n            st = new StringTokenizer(bf.readLine());\n        return st.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 Main() throws IOException {\n        bf = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\t\t\n        solve();\n        bf.close();\n        out.close();\n    }\n    \n    public static void main(String args[]) throws IOException {\n        new Main();\n    }\n}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n\npublic class Main {\n\tprivate static Scanner in = new Scanner(System.in);\n\tpublic static void main(String args[]){\n\t\tint n = in.nextInt();\n\t\tString s = in.next();\n\t\tif(n==1)\n\t\t\tSystem.out.println(\"1\");\n\t\telse{\n\t\t\tint j=0,i=1,ans=s.length();\n\t\t\tint h[]=new int[128];\n\t\t\th[(int)s.charAt(0)]=1;\n\t\t\twhile(i<n){\n\t\t\t\tif(h[(int)s.charAt(i)]==0)\n\t\t\t\t\tans = i-j+1;\n\t\t\t\th[(int) s.charAt(i)]++;\n\t\t\t\twhile(j<i && h[(int)s.charAt(j)]>1){\n\t\t\t\t\th[(int)s.charAt(j)]--;\n\t\t\t\t\tj++;\n\t\t\t\t\tans = Math.min(ans, i-j+1);\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class CTask {\n\n\n    public static void main(String[] args) throws IOException {\n        MyInputReader in = new MyInputReader(System.in);\n        HashMap<Character, Integer> m = new HashMap<Character, Integer>();\n        int n = in.nextInt();\n        char[] s = in.next().toCharArray();\n\n        for (int i = 0; i < n; i++) {\n            m.put(s[i], 0);\n        }\n        int mx = m.size();\n        int start = 0;\n        int end = 0;\n        int min = Integer.MAX_VALUE;\n        int cur = 0;\n        while (end < n) {\n            while (end < n && cur != mx) {\n                int x = m.get(s[end]);\n                if (x == 0) {\n                    cur += 1;\n                }\n                m.put(s[end], x + 1);\n                end += 1;\n            }\n            while (start <= end && cur == mx) {\n                int x = m.get(s[start]);\n                m.put(s[start], x - 1);\n                if (x - 1 == 0) {\n                    cur -= 1;\n                }\n                start += 1;\n            }\n            min = Math.min(min, end - start + 1);\n        }\n        System.out.println(min);\n    }\n\n\n    static class Pair {\n\n        long x;\n        long y;\n\n        public Pair(long x, long 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 == null || getClass() != o.getClass()) return false;\n\n            Pair pair = (Pair) o;\n\n            if (x != pair.x) return false;\n            return y == pair.y;\n\n        }\n\n        @Override\n        public int hashCode() {\n            int result = (int) (x ^ (x >>> 32));\n            result = 31 * result + (int) (y ^ (y >>> 32));\n            return result;\n        }\n    }\n\n    static class MyInputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public MyInputReader(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}", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "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.HashMap;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Rene\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            int n = in.nextInt();\n            String s = in.next();\n            HashMap<Character, Integer> indexMap = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                char c = s.charAt(i);\n                if (!indexMap.containsKey(c)) {\n                    indexMap.put(c, indexMap.size());\n                }\n            }\n            int[] last = new int[indexMap.size()];\n            Arrays.fill(last, -1_000_000);\n            int answer = n;\n            for (int i = 0; i < n; i++) {\n                int index = indexMap.get(s.charAt(i));\n                last[index] = i;\n                int first = i;\n                for (int a : last) first = Math.min(first, a);\n                int visits = i - first + 1;\n                answer = Math.min(answer, visits);\n            }\n            out.println(answer);\n        }\n\n    }\n}\n\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.Hashtable;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\npublic class Main3 {\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        int N = sc.nextInt();\n        String S = sc.next();\n        HashSet<Character> unique = new HashSet<>();\n        for(char c : S.toCharArray()){\n            unique.add(c);\n        }\n        int number = unique.size();\n\n        Hashtable<Character, Integer> indexes = new Hashtable<>();\n        TreeSet<Integer> tree = new TreeSet<>();\n\n        int min = N+1;\n        int total = 0;\n        for(int i = 0; i<N; i++){\n            char c = S.charAt(i);\n            if(!indexes.containsKey(c)){\n                total++;\n                indexes.put(c, i);\n                tree.add(i);\n            }\n            else{\n                int old = indexes.get(c);\n                indexes.put(c, i);\n                tree.remove(old);\n                tree.add(i);\n            }\n\n            if(total == number){\n                int dist = tree.last() - tree.first() + 1;\n                min = Math.min(dist, min);\n            }\n        }\n\n        System.out.println(min);\n    }\n}\n", "complexity": "linear", "problem": "701_C. They Are Everywhere", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1009E {\n\tstatic final int MD = 998244353;\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[] aa = new int[1 + n];\n\t\tfor (int i = 1, a = 0; i <= n; i++)\n\t\t\taa[i] = a = (a + Integer.parseInt(st.nextToken())) % MD;\n\t\tint[] pp = new int[n];\n\t\tpp[0] = 1;\n\t\tfor (int i = 1, p = 1; i < n; i++) {\n\t\t\tpp[i] = p;\n\t\t\tp = p * 2 % MD;\n\t\t}\n\t\tint d = 0;\n\t\tlong ans = 0;\n\t\tfor (int i = n - 1; i >= 0; i--) {\t// rest at i\n\t\t\td = (d * 2 % MD + aa[n - 1 - i]) % MD;\t// rest again before n\n\t\t\tans = (ans + (long) (d + aa[n - i]) * pp[i]) % MD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "linear", "problem": "1009_E. Intercity Travelling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n\t{\t\n\t\tclass node{\n\t\tint data;\n\t\tnode next;\n\t\tpublic node(int val){\n\t\t\tdata=val;\n\t\t\tnext=null;\n\t\t}\n\t}\n\tclass linkedlist{\n\t\tnode start;\n\t\tnode end;\n\t\tint size;\n\t\tint turn;\n\t\tpublic linkedlist(){\n\t\t\tstart=null;\n\t\t\tend=null;\n\t\t\tsize=0;\n\t\t}\n\t\tvoid add(int val){\n\t\t\tif(size==0){\n\t\t\t\tnode t=new node(val);\n\t\t\t\tstart=t;\n\t\t\t\tend=t;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnode t=new node(val);\n\t\t\t\tend.next=t;\n\t\t\t\tend=end.next;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t}\n\t\tvoid myfunc(){\n\t\t\tif(start.data>start.next.data){\n\t\t\t\t// System.out.println(\"me ni hu\");\n\t\t\t\tnode t=new node(start.next.data);\n\t\t\t\tstart.next=start.next.next;\n\t\t\t\tend.next=t;\n\t\t\t\tend=end.next;\n\t\t\t}\n\t\t\telse{\n\t\t\t\t// System.out.println(\"me hu\");\n\t\t\t\tint t=start.data;\n\t\t\t\tstart=start.next;\n\t\t\t\tadd(t);\n\t\t\t\tsize--;\n\t\t\t}\n\t\t}\n\t\tint findmax(){\n\t\t\tint m=0;\n\t\t\tnode temp=start;\n\t\t\tfor(int i=0;i<size;i++){\n\t\t\t\tif(temp.data>m){\n\t\t\t\t\tm=temp.data;\n\t\t\t\t}\n\t\t\t\ttemp=temp.next;\n\t\t\t}\n\t\t\treturn m;\n\t\t}\n\t\tvoid display(){\n\t\t\tnode temp=start;\n\t\t\tfor(int i=0;i<size;i++){\n\t\t\t\tSystem.out.print(temp.data+\" \");\n\t\t\t\ttemp=temp.next;\n\t\t\t}\n\t\t\tSystem.out.println(\"\");\n\t\t}\n\t}\n\tlinkedlist l;\n\tpublic Main(){\n\t\tl=new linkedlist();\n\t}\n\tpublic static void main(String [] argv) throws IOException\n\t{\n\t\tBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\t\tMain ma=new Main();\n\t\tString[] l1=in.readLine().split(\" \");\n\t\tint n=Integer.parseInt(l1[0]);\n\t\tint q=Integer.parseInt(l1[1]);\n\t\tString[] ar=in.readLine().split(\" \");\n\t\tint a1=Integer.parseInt(ar[0]);\n\t\tint b1=Integer.parseInt(ar[1]);\n\t\tfor(int i=0;i<n;i++){\n\t\t\tma.l.add(Integer.parseInt(ar[i]));\n\t\t}\n\t\tint m=ma.l.findmax();\n\t\tint[][] pair=new int[n][2];\n\t\tint t=0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(ma.l.start.data==m)\n\t\t\t\tbreak;\n\t\t\tma.l.myfunc();\n\t\t\tpair[t][0]=ma.l.start.data;\n\t\t\tpair[t][1]=ma.l.start.next.data;\n\t\t\tt++;\n\t\t}\n\t\tint rl[]=new int[n];\n\t\tnode temp=ma.l.start;\n\t\tfor(int i=0;i<n;i++){\n\t\t\trl[i]=temp.data;\n\t\t\ttemp=temp.next;\n\t\t}\n\t\tfor(int i=0;i<q;i++){\n\t\t\tlong a=Long.parseLong(in.readLine());\n\t\t\tif(a==1){\n\t\t\t\tSystem.out.println(a1 + \" \" + b1);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(a<=t+1){\n\t\t\t\t\tSystem.out.println(pair[(int)(a-2)][0]+\" \"+pair[(int)(a-2)][1]);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif((a-t)%(n-1)==0){\n\t\t\t\t\t\tSystem.out.println(rl[0]+\" \"+rl[n-1]);\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tSystem.out.println(rl[0]+\" \"+rl[(int)((a-t)%(n-1))]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1179_A. Valeriy and Deque", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\npublic class D999 {\n    public static void main(String args[])throws IOException\n    {\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        int m=sc.nextInt();\n        int req=n/m;\n        int arr[]=new int[n+1];\n        int size[]=new int[m];\n        List<Integer> list[]=new ArrayList[m];\n        for(int i=0;i<m;i++)\n        {\n            list[i]=new ArrayList<>();\n        }\n        for(int i=1;i<=n;i++)\n        {\n            arr[i]=sc.nextInt();\n            size[arr[i]%m]++;\n            list[arr[i]%m].add(i);\n        }\n        long tot=0;int x=0,y=0;\n        List<Integer> idx=new ArrayList<>();\n        for(int i=0;i < 2*m;i++)\n        {\n            //System.out.println(i+\" \"+size[i%m]);\n            if(size[i%m]>req)\n            {\n                for(int j=0;j<size[i%m]-req;j++)\n                {\n                    idx.add(list[i%m].get(j));\n                    y++;\n                    \n                }\n                size[i%m]=req;\n                //System.out.println(i+\" \"+x+\" \"+y);\n            }\n            else if(size[i%m]<req)\n            {\n                //System.out.println(idx+\" \"+i);\n                while(x!=y && size[i%m]<req)\n                {\n                    int num=arr[idx.get(x)];\n                    int gg=i-num%m;\n                    tot+=gg;\n                    arr[idx.get(x)]+=gg;\n                    x++;\n                    size[i%m]++;\n                }\n            }\n        }\n        System.out.println(tot);\n        for(int i=1;i<=n;i++)\n        {\n            System.out.print(arr[i]+\" \");\n        }\n    }\n}", "complexity": "linear", "problem": "999_D. Equalize the Remainders", "from": "CODEFORCES"}
{"src": "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 EhabAndAComponentChoosingProblem {\n    \n    long INF = (long) 1e18;\n    \n    int n;\n    int[] a;\n    \n    int[][] G;\n    \n    void solve() {\n        n = in.nextInt();\n        a = new int[n];\n        for (int i = 0; i < n; i++) a[i] = in.nextInt();\n        int[] fr = new int[n - 1], to = new int[n - 1];\n        for (int i = 0; i < n - 1; i++) {\n            fr[i] = in.nextInt() - 1;\n            to[i] = in.nextInt() - 1;\n        }\n        G = build_graph(n, fr, to);\n        \n        int[][] ret = bfs(G, 0);\n        int[] par = ret[0], ord = ret[2];\n        \n        long best = -INF;\n        long[] dp = new long[n];\n        for (int i = n - 1; i >= 0; i--) {\n            int u = ord[i];\n            dp[u] = a[u];\n            for (int v : G[u]) {\n                if (v != par[u]) {\n                    if (dp[v] > 0) dp[u] += dp[v];\n                }\n            }\n            best = Math.max(best, dp[u]);\n        }\n        \n        int k = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            int u = ord[i];\n            dp[u] = a[u];\n            for (int v : G[u]) {\n                if (v != par[u]) {\n                    if (dp[v] > 0) dp[u] += dp[v];\n                }\n            }\n            if (dp[u] == best) {\n                dp[u] = -INF;\n                k++;\n            }\n        }\n        \n        out.printf(\"%d %d%n\", best * k, k);\n    }\n    \n    int[][] bfs(int[][] G, int root) {\n        int n = G.length;\n        \n        int[] par = new int[n];\n        Arrays.fill(par, -1);\n        \n        int[] dep = new int[n];\n        dep[root] = 0;\n        \n        int[] qu = new int[n];\n        qu[0] = root;\n        for (int l = 0, r = 1; l < r; l++) {\n            int u = qu[l];\n            for (int v : G[u]) {\n                if (v != par[u]) {\n                    qu[r++] = v;\n                    par[v] = u;\n                    dep[v] = dep[u] + 1;\n                }\n            }\n        }\n        \n        return new int[][]{par, dep, qu};\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            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]]] = to[i];\n            G[to[i]][--cnt[to[i]]] = from[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 EhabAndAComponentChoosingProblem().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", "complexity": "linear", "problem": "1088_E. Ehab and a component choosing problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tboolean[] p = new boolean[n + 1];\n\t\tArrays.fill(p, true);\n\t\tList<Integer> primes = new ArrayList<Integer>();\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tif (p[i]) {\n\t\t\t\tprimes.add(i);\n\t\t\t\tfor (int j = i + i; j <= n; j += i)\n\t\t\t\t\tp[j] = false;\n\t\t\t}\n\t\tboolean[] ok = new boolean[n + 1];\n\t\tfor (int i = 0; i < primes.size() - 1; i++) {\n\t\t\tint x = primes.get(i);\n\t\t\tint y = primes.get(i + 1);\n\t\t\tif (x + y + 1 <= n)\n\t\t\t\tok[x + y + 1] = true;\n\t\t}\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tif (p[i] && ok[i]) {\n\t\t\t\t--k;\t\t\t\t\n\t\t\t}\t\t\n\t\tout.println(k <= 0 ? \"YES\" : \"NO\");\n\t}\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\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", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\t\t\n\tvoid solve() throws IOException {\n\t\tint n=ni();\n\t\tint k=ni();\n\t\tboolean[] t = new boolean[n+1];\n\t\tfor(int i=2;i<=n;i++){\n\t\tt[i]=false;\n\t\t}\n\t\tint p=2;\n\t\t\n\t\twhile(true){\n\t\t\tint pointer=2;\n\t\twhile(pointer*p<=n){\n\t\t\tt[pointer*p]=true;\n\t\t\tpointer++;\n\t\t}\n\n\t\tboolean flag=false;\n\t\tfor(int i=p+1;i<=n;i++){\n\t\t\tif(!t[i]){p=i;flag=true;break;}\n\t\t}\n\t\tif(!flag)break;\n\t\t}\n\t\tList<Integer> lst=new ArrayList<Integer>();\n\n\t\tint countN=0;\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tif(!t[i]){lst.add(i);countN++; }\n\t\t}\n\t\tint count=0;\n\t\t\n\t\tString resulPO=\"NO\";\n\t\tfor(int i=2;i<countN;i++){\n\t\t\t\n\t\t\tboolean result=false;\n\t\t\tfor(int j=0;j<i;j++){\n\t\t\t\tif(lst.get(j)+lst.get(j+1)+1==lst.get(i)){\n\t\t\t\t\tresult=true;\n\t\t\t\t\t//out.println(lst.get(j)+\"+\"+lst.get(j+1)+\"+\"+1+\"==\"+lst.get(i));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(result)count++;\n\t\t}\n\t\tif(count>=k)resulPO=\"YES\";\n\t\telse resulPO=\"NO\";\n\t\tout.print(resulPO);\n\t\t\n\t}\n\t\n\tpublic Main() throws IOException {\n\t\tLocale.setDefault(Locale.US);\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\tString ns() 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\n\tint ni() throws IOException {\n\t\treturn Integer.valueOf(ns());\n\t}\n\n\tlong nl() throws IOException {\n\t\treturn Long.valueOf(ns());\n\t}\n\n\tdouble nd() throws IOException {\n\t\treturn Double.valueOf(ns());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main();\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class a {\n\t\n\tboolean[] isp;\n\tArrayList<Integer> primes;\n\n\tprivate void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint cnt = 0;\n\t\tprimes = new ArrayList<Integer>();\n\t\tisp = new boolean[n + 1];\n\t\tArrays.fill(isp, true);\n\t\tfor (int i = 2; i <= n; ++i) {\n\t\t\tfor (int j = 2; j * j <= i; ++j)\n\t\t\t\tif (i % j == 0)\n\t\t\t\t\tisp[i] = false;\n\t\t\tif (isp[i])\n\t\t\t\tprimes.add(i);\n\t\t}\n\t\tfor (int i = 2; i <= n; ++i)\n\t\t\tif (isp[i]) {\n\t\t\t\tboolean can = false;\n\t\t\t\tfor (int j = 0; j < primes.size() - 1; ++j) {\n\t\t\t\t\tint sum = primes.get(j) + primes.get(j + 1) + 1;\n\t\t\t\t\tif (i == sum)\n\t\t\t\t\t\tcan = true;\n\t\t\t\t}\n\t\t\t\tif (can)\n\t\t\t\t\t++cnt;\n\t\t\t}\n\t\tif (cnt >= k)\n\t\t\tout.print(\"YES\");\n\t\telse\n\t\t\tout.print(\"NO\");\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 a(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 a() {\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 a().run();\n\t}\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "//package round17;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A {\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\tstatic boolean prime(int n){\n\t\tint j = 2;\n\t\twhile (j*j <= n)\n\t\t\tif (n%j == 0) return false;\n\t\t\telse j++;\n\t\t\n\t\treturn true;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tint n = nextInt(),\n\t\t\tk = nextInt(),\n\t\t\ta[] = new int[n];\n\n\t\tint s = 0;\n\t\tfor (int i=2; i<=n; i++)\n\t\t\tif (prime(i))\n\t\t\t\ta[s++] = i;\n\t\t\n\t\tint m = 0;\n\t\tfor (int i=2; i<s; i++)\n\t\t\tfor (int j=i-1; j>0; j--)\n\t\t\t\tif (a[i] == a[j]+a[j-1]+1){\n\t\t\t\t\tm++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\n\t\tif (m >= k) out.println(\"YES\");\n\t\telse out.println(\"NO\");\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.BitSet;\nimport java.util.Scanner;\n\npublic class A {\n\tstatic Scanner sc = new Scanner(System.in);\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tBitSet primes = primes(1001);\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tint count = 0;\n\t\tfor (int i = 2; i <= N; ++i) {\n\t\t\tif (!primes.get(i)) continue;\n\t\t\tint res = i - 1;\n\t\t\tboolean found = false;\n\t\t\tfor (int j = 2; j <= i / 2; ++j) {\n\t\t\t\tif (primes.get(j) && primes.nextSetBit(j + 1) == res - j) {\n\t\t\t\t\tfound = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (found) {\n\t\t\t\t++count;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count >= K ? \"YES\" : \"NO\");\n\t}\n\n\tpublic static BitSet primes(int max) {\n\t\tBitSet primeSet = new BitSet(max + 1);\n\t\tif (max < 2) {\n\t\t\treturn primeSet;\n\t\t}\n\t\tint limit = (int) Math.sqrt(max + 1);\n\t\tprimeSet.set(2);\n\t\tfor (int i = 3; i < max + 1; i += 2) {\n\t\t\tprimeSet.set(i);\n\t\t}\n\t\tfor (int i = 3; i <= limit; i += 2) {\n\t\t\tif (!primeSet.get(i)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = i * i; j < max; j += i) {\n\t\t\t\tprimeSet.clear(j);\n\t\t\t}\n\t\t}\n\t\treturn primeSet;\n\t}\n\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static java.lang.Integer.parseInt;\nimport static java.util.AbstractMap.*;\nimport static java.lang.System.*;\nimport static java.lang.Math.*;\nimport java.awt.geom.*;\nimport java.util.*;\nimport java.text.*;\nimport java.io.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tboolean submit = true;\t\t\n\t\tScanner sc = submit ? new Scanner(System.in) : new Scanner(new File(\"A.in\"));\n\t\twhile(sc.hasNext()) {\n\t\t\tint n = sc.nextInt(), k = sc.nextInt();\n\t\t\tboolean p[] = sieveOfEratosthenes(1001);\n\t\t\tArrayList<Integer> nolds = new ArrayList<Integer>();\n\t\t\t\t\t\n\t\t\tfor(int i = 0, prev = 0; i < p.length; i++) {\n\t\t\t\tif(p[i]) {\n\t\t\t\t\tnolds.add(prev+i + 1);\n\t\t\t\t\tprev = i;\n\t\t\t\t}\t\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t//System.out.println(nolds);\n\t\t\t\n\t\t\tint c = 0;\n\t\t\tfor(int i : nolds)\n\t\t\t\tif(i >= 2 && i <= n && p[i])\n\t\t\t\t\tc++;\n\t\t\t\n\t\t\tSystem.out.println(c >= k ? \"YES\" : \"NO\");\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\n\t}\n\t\n\t//prime[i] = true iff i is prime, prime[0] = prime[1] = false and i can be from 0 to n (both inclusive)\n    static boolean[] sieveOfEratosthenes(int n) {\n        boolean prime[] = new boolean[n+1];\n        fill(prime, 2, n, true);\n        for(int i = 2; i <= n; i++)\n            if(prime[i])\n                for(int j = i*i; j <= n; j+=i) //check for i*i overflow\n                    prime[j] = false;\n        return prime;\n    }\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n    StreamTokenizer in;\n    PrintWriter out;\n    public static void main(String[] args) throws IOException\n    {\n        new Main().run();\n    }\n    public void run() throws IOException\n    {\n    //\tin =new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));\n    //  out = new PrintWriter(new FileWriter(\"output.txt\"));\n\n        in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t   out = new PrintWriter(new OutputStreamWriter(System.out));\n             solve();\n        out.flush();\n        \n    }\n    public int nextInt() throws IOException\n    {\n        in.nextToken();\n        return (int) in.nval;\n    }\n    boolean pr(int i)\n    {\n    \tif(i<4) return true;\n    \tfor(int j=2;j<Math.sqrt(i)+1;j++)\n    \t\tif(i%j==0)\n    \t\t\treturn false;\n    \treturn true;\n    }\n    public void solve() throws IOException\n    {\n    \tint n=nextInt(),k=nextInt();\n    \tint prost[]=new int[1000];\n    \tboolean now[]=new boolean[10000];\n    \tint a=0;\n    \tfor(int i=2;i!=1000;i++)\n    \t\tif(pr(i))\n    \t\t\tprost[a++]=i;\n    \tfor(int i=0;i!=a-1;i++)\n    \t{\n    \t\tif(pr(prost[i]+prost[i+1]+1))\n    \t\t\tnow[prost[i]+prost[i+1]+1]=true;\n    \t}\n    \tint answ=0;\n    \tfor(int i=0;i!=n+1;i++)\n    \t\tif(now[i])\n    \t\t\tansw++;\n    \tif(answ>=k)\n    \t\tout.print(\"YES\");\n    \telse\n    \t\tout.print(\"NO\");\n    }\n\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A\n{\n\tpublic static void main(String args[])\n\t{\n\t\tboolean[] b = new boolean[11000];\n\t\tArrays.fill(b, true);\n\t\tb[0] = b[1] = false;\n\n\t\tfor(int i=2;i < b.length;i++)\n\t\t{\n\t\t\tif(!b[i])\n\t\t\t\tcontinue;\n\n\t\t\tfor(int j=2;i*j<b.length;j++)\n\t\t\t\tb[i*j] = false;\n\t\t}\n\n\t\tint[] p = new int[11000];\n\t\tint pn = 0;\n\n\t\tfor(int i=0;i < b.length;i++)\n\t\t{\n\t\t\tif(b[i])\n\t\t\t\tp[pn++] = i;\n\t\t}\n\n\t\tScanner scan = new Scanner(System.in);\n\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt();\n\n\t\tint rtn = 0;\n\n\t\t\n\t\tfor(int j=0;p[j] <= n;j++)\n\t\t{\n\t\t\t//Try to make sum\n\t\t\tfor(int h=0;h <= j;h++)\n\t\t\t{\n\t\t\t\tif(p[h] + p[h+1] + 1 == p[j])\n\t\t\t\t{\n\t\t\t\t\trtn++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(rtn >= k ? \"YES\" : \"NO\");\n\t\t\n\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class A {\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\n        int[] primes = getPrimesFast(N);\n        Set<Integer> ints = new HashSet<Integer>();\n        for(int i=0;i<primes.length;i++) {\n            ints.add(primes[i]);\n        }\n\n        for(int i=1;i<primes.length;i++) {\n            ints.remove(primes[i] + primes[i-1]+1);\n        }\n\n        boolean res = primes.length - ints.size() >= K;\n        System.out.print(res?\"YES\":\"NO\");\n        \n    }\n\n    public static int[] getPrimesFast(int n) {\n    if (n <= 1) {\n      return new int[0];\n    }\n    boolean[] b = new boolean[n + 1];\n    int m = n - 1;\n    for (int i = 2; i * i <= n; i++) {\n      if (!b[i]) {\n        for (int j = i + i; j <= n; j += i) {\n          if (!b[j]) {\n            m--;\n            b[j] = true;\n          }\n        }\n      }\n    }\n    int[] primes = new int[m];\n    int j = 0;\n    for (int i = 2; i <= n; i++) {\n      if (!b[i]) {\n        primes[j++] = i;\n      }\n    }\n    return primes;\n  }\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\n\n\npublic class primes {\n\npublic static void main(String []  args){\n\nArrayList<Integer> numb=new ArrayList<Integer>();\nScanner br1 = new Scanner(System.in);\nint n=br1.nextInt();\nint steps=br1.nextInt();\n//if(n>2)numb.add(2);\nif(n>=3)numb.add(3);\nfor(int j=4;j<=n;j++){\nif(chekprime(j)==0){\n\nnumb.add(j);\n//System.out.println(j);\n}\n\n}\nint counter =0;\nfor(int give=0;give<numb.size();give++)\n{if(\"YES\".equals(sumup(numb, 2, numb.get(give)))){\n counter++;\n// System.out.println(numb.get(give)+\"ksjdfskldfgaskldfgasklfgaskldfgaklsfgasdklfgaskldfgaskldfgasdklfg\");\n }\n\n\n\n}\n\n//System.out.println(counter);\nif(counter>=steps)System.out.println(\"YES\");\nelse System.out.println(\"NO\");\n\n\n}\n\npublic static String sumup(ArrayList<Integer> list,int number,int NUM){\n\nString ret=\"NO\";\n    ArrayList<Integer> result=new ArrayList<Integer>();\n\nArrayList<Integer>[] arList=new ArrayList[number];\nfor(int i=0;i<number;i++){\narList[i]=new ArrayList<Integer>();\narList[i]=(ArrayList<Integer>)list.clone();\nfor(int k=0;k<i;k++){\narList[i].add(0,arList[i].remove(arList[i].size()-1));\n}\n\n}\n\n\n    int [] temp=new int[list.size()];\n    \nfor(int z=0;z<list.size();z++){\n    for(int count=0;count<number;count++){\n        \ntemp[z]+=arList[count].get(z);\n//System.out.println(arList[count].get(z));\n    }\n\nresult.add(temp[z]);\n\n}\n\nif(result.contains(NUM-1))\n{    //System.out.println(NUM-1);\nret=\"YES\";\n}\nreturn ret;\n}\n\n\n\npublic static int chekprime(int n){\nint flag=0;\n\nfor(int i=2;i<=Math.sqrt(n)+1;i++)\n{\nif(n%i==0){\nflag=1;\nbreak;\n}\n\n} \n\nreturn flag;\n\n}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        \n        int n = nextInt(), k = nextInt();\n        int[] primes = new int[n + 1];\n        for (int i = 2; i <= n; i++) {\n            if (primes[i] == 0) {\n                primes[i] = 1;\n                for (int j = i * 2; j <= n; j += i)\n                    primes[j] = 2;\n            }\n        }\n        ArrayList<Integer> res = new ArrayList<Integer>();\n        HashSet<Integer> p = new HashSet<Integer>(), v = new HashSet<Integer>();\n        for (int i = 2; i <= n; i++) {\n            if (primes[i] == 1) {\n                res.add(i);\n                p.add(i);\n            }\n        }\n        int c = 0;\n        if (res.size() >= 3) {\n            for (int i = 2; i < res.size(); i++) {\n                int zz = res.get(i - 2) + res.get(i - 1) + 1;\n                if (p.contains(zz))\n                    v.add(zz);\n            }\n            c = v.size();\n        }\n        if (c >= k) {\n            out.println(\"YES\");\n        } else {\n            out.println(\"NO\");\n        }\n        in.close();\n        out.close();\n    }\n\n    static BufferedReader in;\n    static PrintWriter out;\n    static StringTokenizer st;\n\n    static String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    static int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    static double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tScanner in;\n\tPrintWriter out;\n\n\tboolean isPrime(int 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\t\treturn true;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tin = new Scanner(System.in);\n\t\t//in = new Scanner(new FileReader(\"input.txt\"));\n\t\tout = new PrintWriter(System.out);\n\t\tint N = in.nextInt();\n\t\tint K = in.nextInt();\n\t\tList<Integer> primes = new ArrayList<Integer>();\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}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int i = 2; i <= N; ++i) {\n\t\t\tif (!isPrime(i)) continue;\n\t\t\tfor (int j = 0; j + 1 < primes.size(); ++j) {\n\t\t\t\tint p1 = primes.get(j);\n\t\t\t\tint p2 = primes.get(j + 1);\n\t\t\t\tif (p1 + p2 + 1 == i) {\n\t\t\t\t\t++c;\n\t\t\t\t\t//out.println(i);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (c >= K) out.println(\"YES\");\n\t\telse out.println(\"NO\");\n\t\tout.close();\t\t\n\t}\n\n\tpublic static void main(String args[]) throws IOException {\n\t\tnew Solution().solve();\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Noldbach\n{\n\tpublic Scanner in = new Scanner(System.in);\n\tpublic PrintStream out = System.out;\n\n\tpublic boolean[] yes;\n\tpublic int n, k;\n\t\n\tpublic void main()\n\t{\n\t\tn = in.nextInt();\n\t\tk = in.nextInt();\n\t\t\n\t\tgenPrime();\n\t\tint i;\n\t\t\n\t\tyes = new boolean[n+1];\n\t\t\n\t\tint x;\n\t\tfor(i=0;i+1<prime.length;++i)\n\t\t{\n\t\t\tx = prime[i]+prime[i+1]+1;\n\t\t\tif(x <= n && fac[x] == x) yes[x] = true;\n\t\t}\n\t\t\n\t\tint count = 0;\n\t\tfor(i=0;i<yes.length;++i) if(yes[i]) ++count;\n\t\t\n\t\tout.println((count>=k?\"YES\":\"NO\"));\n\t}//end public void main()\n\n\t//Generating Primes\n\tpublic int N = 100000+100;\n\tpublic int[] fac, rest;\n\tpublic int[] prime;\n\n\tpublic void genPrime()\n\t{\n\t\tArrayList<Integer> ap = new ArrayList<Integer>();\n\t\tfac = new int[N];\n\t\trest = new int[N];\n\t\t\n\t\tint x,y;\n\t\tfor(x=0;x<N;++x)\n\t\t{\n\t\t\tfac[x] = x;\n\t\t\trest[x] = 1;\n\t\t}\n\t\t\n\t\tfor(x=2;x<N;++x)\n\t\tif(fac[x]==x)\n\t\t{\n\t\t\tap.add(x);\n\t\t\tfor(y=x+x;y<N;y+=x)\n\t\t\tif(fac[y]==y)\n\t\t\t{\n\t\t\t\tfac[y] = x;\n\t\t\t\trest[y] = y/x;\n\t\t\t}\n\t\t}\n\t\t\n\t\tprime = new int[ap.size()];\n\t\tfor(int i=0;i<prime.length;++i) prime[i] = ap.get(i);\n\t}\n\t\n\t\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\t(new Noldbach()).main();\n\t}\n}\n\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class A implements Runnable\n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tnew Thread(null, new A(), \"\", 1 << 20).start();\n\t}\n\t\n\tString file = \"input\";\n\tBufferedReader input;\n\tPrintWriter out;\n\t\n\tpublic void run() \n\t{\n\t\ttry\n\t\t{\n\t\t\t//input = new BufferedReader(new FileReader(file + \".in\"));\n\t\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\tsolve();\n\t\t\tinput.close();\n\t\t\tout.close();\n\t\t}\n\t\tcatch(Exception e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tvoid solve() throws IOException\n\t{\n\t\tArrayList<Integer> p = new ArrayList<Integer>();\n\t\tStringTokenizer st = tokens();\n\t\tint n = nextInt(st), k = nextInt(st);\n\t\tfor(int i = 2; i <= n; i++)\n\t\t\tif(prime(i)) p.add(i);\n\t\t\n\t\tint count = 0;\n\t\tfor(int x = 2; x <= n; x++)\n\t\t{\n\t\t\tif(!prime(x)) continue;\n\t\t\tfor(int i = 0; i + 1 < p.size(); i++)\n\t\t\t{\n\t\t\t\tint p1 = p.get(i);\n\t\t\t\tint p2 = p.get(i + 1);\n\t\t\t\tint P = p1 + p2 + 1;\n\t\t\t\tif(P == x) \n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(P > x) break;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count >= k ? \"YES\" : \"NO\");\n\t\t\t\t\n\t}\n\t\n\tboolean prime(int n)\n\t{\n\t\tfor(int i = 2; i * i <= n; i++)\n\t\t\tif(n % i == 0) return false;\n\t\treturn true;\n\t}\n\n\tStringTokenizer tokens() throws IOException\n\t{\n\t\treturn new StringTokenizer(input.readLine());\n\t}\n\t\n\tString next(StringTokenizer st)\n\t{\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(input.readLine());\n\t}\n\t\n\tint nextInt(StringTokenizer st)\n\t{\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(input.readLine());\n\t}\n\t\n\tdouble nextDouble(StringTokenizer st)\n\t{\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\t\n\tvoid print(Object... o)\n\t{\n\t\tout.println(deepToString(o));\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport javax.script.*;\n\npublic class Noldbach {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint k=sc.nextInt();\n\t\tboolean[] sieve=new boolean[1001];\n\t\tsieve[2]=false;\n\t\tArrayList<Integer> primes=new ArrayList<Integer>();\n\t\tfor(int x=2;x<1001;x++)\n\t\t\tif(!sieve[x])\n\t\t\t{\n\t\t\t\tprimes.add(x);\n\t\t\t\tfor(int y=x;y<1001;y+=x)\n\t\t\t\t\tsieve[y]=true;\n\t\t\t}\n\t\tint sum=0;\n\t\tfor(int x=2;x<=n;x++)\n\t\t{\n\t\t\tif(primes.contains(x))\n\t\t\t{\n\t\t\tint need=x-1;\n\t\t\tfor(int y=0;y<primes.size()-1;y++)\n\t\t\t{\n\t\t\t\tif(primes.get(y)+primes.get(y+1)==need)\n\t\t\t\t{\n\t\t\t\t\tsum++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t}\n\t\t\tif(sum==k)break;\n\t\t}\n\t\tif(sum==k)System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t\t\n\t}\n\t\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\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\tvoid solve() throws Exception {\n\t\tboolean[] r = new boolean[1010];\n\t\tArrays.fill(r, true);\n\t\tr[0] = r[1] = false;\n\t\tfor (int i = 2; i < 1010; i++) {\n\t\t\tif (r[i]) {\n\t\t\t\tfor (int j = i + i; j < 1010; j += i) {\n\t\t\t\t\tr[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] pr = new int[1010];\n\t\tint l = 0;\n\t\tfor (int i = 2; i < 1010; i++) if (r[i]) pr[l++] = i;\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint ans = 0;\n\t\tint j = 0;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tif (r[i]) {\n\t\t\tfor (; j < l - 1; j++) {\n\t\t\t\tif (i == pr[j] + pr[j + 1] + 1) {\n\t\t\t\t\tans++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (i < pr[j] + pr[j + 1] + 1) break;\n\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (ans >= k) out.println(\"YES\"); else out.println(\"NO\");\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\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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    final String filename=\"\";\n    \n    public void solve() throws Exception {\n        int n = iread(), k = iread();\n        boolean[] f = new boolean[10000];\n        int prev = -1;\n        cycle:for (int i=2; i<=n; i++)\n        {\n            for (int j=2; j*j<=i; j++)\n                if (i%j==0)\n                    continue cycle;\n            if (prev!=-1)\n                f[i+prev+1] = true;\n            if (f[i])\n                k--;\n            prev = i;\n        }\n        if (k<=0)\n            out.write(\"YES\\n\");\n        else out.write(\"NO\\n\");\n    }\n    \n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new BufferedWriter(new OutputStreamWriter(System.out));\n//          in = new BufferedReader(new FileReader(filename+\".in\"));\n//          out = new BufferedWriter(new FileWriter(filename+\".out\"));\n            solve();\n            out.flush();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n    \n    public int iread() throws Exception {\n        return Integer.parseInt(readword());\n    }\n\n    public double dread() throws Exception {\n        return Double.parseDouble(readword());\n    }\n\n    public long lread() throws Exception {\n        return Long.parseLong(readword());\n    }\n\n    BufferedReader in;\n\n    BufferedWriter out;\n\n    public String readword() throws IOException {\n        StringBuilder b = new StringBuilder();\n        int c;\n        c = in.read();\n        while (c >= 0 && c <= ' ')\n            c = in.read();\n        if (c < 0)\n            return \"\";\n        while (c > ' ') {\n            b.append((char) c);\n            c = in.read();\n        }\n        return b.toString();\n    }\n    public static void main(String[] args) {\n        try{\n            Locale.setDefault(Locale.US);\n        } catch (Exception e)\n        {\n            \n        }\n        new Thread(new Main()).start();\n        //new Thread(null, new Main(), \"1\", 1<<25).start();\n    }\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main\n{\n\tstatic int MAX = 1000;\n\t\n\tstatic BitSet P = new BitSet(MAX + 1);\n\t\t\n\tpublic static boolean Noldbach(int n)\n\t{\n\t\tn--;\n\t\t\n\t\tint j;\n\t\t\n\t\tfor(int i=2; i<=n; i++)\n\t\t{\n\t\t\tif(!P.get(i))\n\t\t\t{\n\t\t\t\tj = i + 1;\n\t\t\t\t\n\t\t\t\twhile(P.get(j))\n\t\t\t\t\tj++;\n\t\t\t\t\n\t\t\t\tif(i+j == n)\n\t\t\t\t{\n\t\t\t\t\tif(!P.get(i+j+1))\n\t\t\t\t\t{\n\t\t\t\t\t\t//System.out.println((n+1)+\" = \"+i+\" + \"+(n-i)+\" + 1\");\n\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner lee = new Scanner(System.in);\t\n\n\t\tfor(int i=2; i*i<=MAX; i++)\n\t\t{\n\t\t    if(!P.get(i))\n\t\t    {\n\t\t    \tfor(int j=i+i; j<=MAX; j+=i)\n\t\t    \t\tP.set(j);\n\t\t    }\n\t\t}\n\t\t\n\t\tint n, k, c;\n\t\t\n\t\tn = lee.nextInt();\n\t\tk = lee.nextInt();\n\t\t\n\t\tc = 0;\n\t\t\n\t\tfor(int i=2; i<=n; i++)\n\t\t{\n\t\t\tif(Noldbach(i))\n\t\t\t\tc++;\n\t\t\t\n\t\t\tif(c == k)\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif(c == k)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskA implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TaskA()).start();\n//\t\tnew Template().run();\n\t}\n\n\tpublic TaskA() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//        }\n\t\tint n = in.readInt();\n\t\tint k = in.readInt();\n\t\tint last = 2;\n\t\tfor (int i = 3; i + last < n; i++) {\n\t\t\tboolean good = true;\n\t\t\tfor (int j = 2; j * j <= i; j++) {\n\t\t\t\tif (i % j == 0) {\n\t\t\t\t\tgood = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (good) {\n\t\t\t\tint p = i + last + 1;\n\t\t\t\tfor (int j = 2; j * j <= p; j++) {\n\t\t\t\t\tif (p % j == 0) {\n\t\t\t\t\t\tgood = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (good)\n\t\t\t\t\tk--;\n\t\t\t\tlast = i;\n\t\t\t}\n\t\t}\n\t\tif (k <= 0)\n\t\t\tout.println(\"YES\");\n\t\telse\n\t\t\tout.println(\"NO\");\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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() {\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}\n\t\t\t}\n\t\t}.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\t\n\t\tboolean[] pr = new boolean[1001];\n\t\tfor (int i = 2; i <= 1000; i++)\n\t\t\tif (!pr[i]) {\n\t\t\t\tint l = 2 * i;\n\t\t\t\twhile (l <= 1000) {\n\t\t\t\t\tpr[l] = true;\n\t\t\t\t\tl += i;\n\t\t\t\t}\n\t\t\t}\n\t\tSet<Integer> set = new HashSet<Integer>();\n\t\tfor (int i = 2; i < 1000; i++) {\n\t\t\tfor (int j = i + 1; j <= 1000; j++) {\n\t\t\t\tif (!pr[j]) {\n\t\t\t\t\tset.add(j + i + 1);\n\t\t\t\t\ti = j - 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint res = 0;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tif (set.contains(i) && !pr[i])\n\t\t\t\tres++;\n\t\t}\n\t\tif (res >= k)\n\t\t\tout.println(\"YES\");\n\t\telse\n\t\t\tout.println(\"NO\");\n\t\t\n\t\tin.close();\n\t\tout.close();\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", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main {\n    StreamTokenizer in;\n    //BufferedReader in;\n    PrintWriter out;\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n    int ni() throws IOException {\n        in.nextToken(); return (int)in.nval;\n    }\n    void run() throws IOException {\n        //in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n        //out = new PrintWriter(new FileWriter(\"output.txt\"));\n        int cprime = 0;\n        int[] prime = new int[1000];\n        for(int i = 2; i < 1001; i++) {\n            boolean f = false;\n            for(int j = 2; j*j <= i; j++)\n                if(i % j == 0) {\n                    f = true; break;\n                }\n            if(!f) prime[cprime++] = i;\n        }\n        int n = ni(), k = ni();\n        int last = 0;\n        int count = 0;\n        for(int i = 0; i < cprime && prime[i] <= n; i++) {\n            for(int j = 0; j < cprime - 1; j++)\n                if(prime[j] + prime[j + 1] + 1 == prime[i]) {\n                    count++; break;\n                }\n                else if(prime[j] + prime[j + 1] + 1 > prime[i]) break;\n        }\n        if(count >= k) out.print(\"YES\");\n        else out.print(\"NO\");\n        out.flush();\n    }\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class Main {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        Scanner entrada = new Scanner (System.in);\n        int Primos []= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,\n                71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,\n                151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,\n                233,239,\n                241,\n                251,\n                257,\n                263,\n                269,\n                271,\n                277,\n                281,\n                283,\n                293,\n                307,\n                311,\n                313,\n                317,\n                331,\n                337,\n                347,\n                349,\n                353,\n                359,\n                367,\n                373,\n                379,\n                383,\n                389,\n                397,\n                401,\n                409,\n                419,\n                421,\n                431,\n                433,\n                439,\n                443,\n                449,\n                457,\n                461,\n                463,\n                467,\n                479,\n                487,\n                491,\n                499,\n                503,\n                509,\n                521,\n                523,\n                541,\n                547,\n                557,\n                563,\n                569,\n                571,\n                577,\n                587,\n                593,\n                599,\n                601,\n                607,\n                613,\n                617,\n                619,\n                631,\n                641,\n                643,\n                647,\n                653,\n                659,\n                661,\n                673,\n                677,\n                683,\n                691,\n                701,\n                709,\n                719,\n                727,\n                733,\n                739,\n                743,\n                751,\n                757,\n                761,\n                769,\n                773,\n                787,\n                797,\n                809,\n                811,\n                821,\n                823,\n                827,\n                829,\n                839,\n                853,\n                857,\n                859,\n                863,\n                877,\n                881,\n                883,\n                887,\n                907,\n                911,\n                919,\n                929,\n                937,\n                941,\n                947,\n                953,\n                967,\n                971,\n                977,\n                983,\n                991,\n                997\n                };\n        boolean sw=true;\n        int Indices [] = new int [Primos.length];\n        int cantidad = 0;\n        for(int i=0;i<Primos.length-1 && sw;i++)\n        {\n            int suma=Primos[i]+Primos[i+1]+1;\n            int posicion = Arrays.binarySearch(Primos,suma);\n            if(posicion>-1)\n                Indices[posicion]=1;\n        }\n        while(entrada.hasNextInt())\n        {\n            int N = entrada.nextInt();\n            int K = entrada.nextInt();\n            int contador=0;\n            for(int i=0;Primos[i]<=N && i<Primos.length-1;i++)\n                contador+=Indices[i];\n            if(contador>=K)\n                System.out.println(\"YES\");\n            else\n                System.out.println(\"NO\");\n        }\n    }\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tprivate void run() {\n\t\tScanner sc =new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tsc.close();\n\t\tboolean[] isp = new boolean[n + 1];\n\t\tArrays.fill(isp, true);\n\t\tisp[1] = false;\n\t\tint[] primes = new int[n];\n\t\tint pc = 0;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tif (isp[i]) {\n\t\t\t\tprimes[pc++] = i;\n\t\t\t\tfor (int j = i * i; j <= n; j+= i) {\n\t\t\t\t\tisp[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\tfor (int i = 0; i < pc; i++) {\n\t\t\tfor (int j = 1; j < i; j++)\t\t\t\t\n\t\t\t\t\tif (primes[i] == primes[j] + primes[j - 1] + 1)\n\t\t\t\t\t\tres++;\n\t\t}\n\t\tSystem.out.println(res >= k ? \"YES\" : \"NO\");\n\t}\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n/**\n * Created by HREN_VAM.\n */\n\npublic class A implements Runnable{\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n    public static final String filename = \"\";\n\n    public void solve() throws IOException{\n\n        int n = nextInt();\n\n        int[] a = new int[n + 1];\n        ArrayList<Integer> pr = new ArrayList<Integer>();\n        \n        for(int i = 2;i < n + 1;i ++){\n            if(a[i] != 0)continue;\n            pr.add(i);\n            for(int j = 2 * i;j < n + 1;j += i){\n                a[j] = 1;\n            }\n        }\n\n        int k = nextInt();\n        for(int i = 2;i < n + 1;i ++){\n            if(a[i] != 0)continue;\n            for(int j = 1;j < pr.size();j ++){\n                if(i == pr.get(j) + pr.get(j - 1) + 1){\n                    k --;\n                    break;\n                }\n            }\n        }\n        if(k > 0){\n            out.println(\"NO\");\n            return;\n        }\n        out.println(\"YES\");\n    }\n\n    public void run(){\n        try{\n            Locale.setDefault(Locale.US);\n            in = new BufferedReader(new InputStreamReader(System.in));\n            //in = new BufferedReader(new FileReader(filename + \".in\"));\n            out = new PrintWriter(System.out);\n            //out = new PrintWriter(new FileWriter(filename + \".out\"));\n            st = new StringTokenizer(\"\");\n            solve();\n            out.close();\n        } catch(IOException e){\n            throw new RuntimeException(e);\n        }\n    }\n\n    public static void main(String[] args){\n        new Thread(new A()).start();\n    }\n\n    public String nextToken() throws IOException{\n        while(!st.hasMoreTokens()){\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.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}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in;\n\tstatic PrintWriter out;\n//\tstatic final String PROBLEM = \"\";\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\t\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\n\t\tboolean[] p = new boolean[n + 5];\n\t\tint[] pp = new int[n + 5];\n\t\tint ind = 0;\n\t\tArrays.fill(p, true);\n\t\tp[0] = false;\n\t\tp[1] = false;\n\t\tfor (int i = 2; i < n + 5; i++)\n\t\t\tif (p[i]) {\n\t\t\t\tpp[ind++] = i;\n\t\t\t\tfor (int j = 2*i; j < n + 5; j += i) p[j] = false;\n\t\t\t}\n//\t    for (int i = 0; i < 30; i++) if (p[i]) out.println(i);\n\t\t\n\t\tboolean[] b = new boolean[n + 1];\n\t\tfor (int i = 0; i < ind - 1; i++)\n\t\t\tif (pp[i] + pp[i + 1] + 1 <= n && p[pp[i] + pp[i + 1] + 1]) b[pp[i] + pp[i + 1] + 1] = true;\n\t\t\n\t\tint kol = 0;\n\t\tfor (int i = 2; i <= n; i++)\t\n\t\t\tif (b[i]) kol++;\n\n\t\tif (kol >= k) out.println(\"YES\");\n\t\telse out.println(\"NO\");\n\n\t\tout.close();\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Answer17A{\n    public static void main(String[] args){\n\ttry{\n\t    BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));\n\t    String[] tmp=reader.readLine().split(\" \");\n\t    int n=Integer.parseInt(tmp[0]);\n\t    int k=Integer.parseInt(tmp[1]);\n\t    boolean[] m=getPrime(n);\n\t    ArrayList<Integer> prime=new ArrayList<Integer>();\n\t    for(int i=0;i<m.length;i++){\n\t\tif(m[i])prime.add(i);\n\t    }\n\t    int sum=0;\n\t    for(int i=2;i<=n;i++){\n\t\tif(m[i]){\n\t\t    for(int j=0;j<prime.size()-1;j++){\n\t\t\tif(i==prime.get(j)+prime.get(j+1)+1){\n\t\t\t    sum++;\n\t\t\t    break;\n\t\t\t}\n\t\t    }\n\t\t}\n\t    }\n\t    if(sum>=k){\n\t\tSystem.out.println(\"YES\");\n\t    }else{\n\t\tSystem.out.println(\"NO\");\n\t    }\n\t}catch(IOException e){\n\t    e.printStackTrace();\n\t}\n    }\n    public static boolean[] getPrime(int N){\n\tboolean[] memo=new boolean[N+1];\n\tArrays.fill(memo,true);\n\tmemo[0]=false;\n\tmemo[1]=false;\n\tfor(int i=2;i*i<=N;i++){\n\t    if(memo[i]){\n\t\tfor(int j=i*i;j<=N;j+=i){\n\t\t    memo[j]=false;\n\t\t}\n\t    }\n\t}\n\treturn memo;\n    }\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class A{\n\n    void exe(){\n        LinkedList<Integer> list=new LinkedList<Integer>();\n        for(int i=2;i<=1000;i++)\n            if(isPrime(i))\n                list.add(i);\n        Object[] primes=list.toArray();\n        \n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        int k=sc.nextInt();\n        int cnt=0;\n        for(int c=2;c<=n;c++){\n            if(!isPrime(c))\n                continue;\n            for(int i=0;i<primes.length-1;i++){\n                int p1=(Integer)primes[i];\n                int p2=(Integer)primes[i+1];\n                if(c==1+p1+p2){\n//                  System.out.println(\"c=\"+c+\", i=\"+p1+\", j=\"+p2);\n                    cnt++;\n                }\n            }\n        }\n        if(cnt>=k){\n            System.out.println(\"YES\");\n        }else{\n            System.out.println(\"NO\");\n        }\n    }\n\n    boolean isPrime(int n){\n        if(n<=1)return false;\n        if(n==2)return true;\n        if(n%2==0)return false;\n        int m=(int)Math.sqrt(n)+1;\n        for(int i=3;i<=m;i+=2)\n            if(n%i==0)\n                return false;\n        return true;\n    }\n    \n    public static void main(String[] args){\n        Locale.setDefault(Locale.US);\n        new A().exe();\n    }\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\n/**\n * Problem solution template.\n * @author Andrew Porokhin, andrew.porokhin@gmail.com\n */\npublic class Problem17A implements Runnable {\n    void solve() throws NumberFormatException, IOException {\n        \n        \n        \n        int n = nextInt();\n        int k = nextInt();\n\n        ArrayList<Integer> primes = new ArrayList<Integer>(n + 1); \n        boolean[] simplePrime = new boolean[n + 1];\n        Arrays.fill(simplePrime, 0, simplePrime.length, true);\n        simplePrime[0] = simplePrime[1] = false;\n        \n        for (int i = 2; i <= n; i++) {\n            if (simplePrime[i]) {\n                for (int j = i + i; j <= n; j += i) {\n                    simplePrime[j] = false;\n                }\n                \n                primes.add(i);\n            }\n        }\n        \n        \n        int actualK = 0;\n        for (int i = 1; i < primes.size(); i++) {\n            int val = primes.get(i - 1) + primes.get(i) + 1;\n            if (val <= n) {\n                if (simplePrime[val]) {\n                    // System.out.printf(\"%d + %d + 1 = %d%n\", primes.get(i - 1), primes.get(i), val);\n                    actualK++;\n                }\n            } else {\n                break;\n            }\n        }\n        // System.out.printf(\"req: %d actual: %d%n\", k, actualK);\n        System.out.println((k <= actualK ? \"YES\" : \"NO\"));\n    }\n\n    \n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n    \n    public static void main(String[] args) {\n        new Problem17A().run();\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n            solve();\n        } catch (Exception e) {\n            e.printStackTrace();\n        } finally {\n            out.flush();\n            out.close();\n        }\n    }\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    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n\n    int n, k;\n\n    boolean[] prime;\n    int[] primes;\n\n    void sieve() {\n        prime = new boolean[n + 1];\n        Arrays.fill(prime, true);\n        prime[0] = prime[1] = false;\n        int cnt = 0;\n        for (int i = 2; i <= n; ++i)\n            if (prime[i]) {\n                ++cnt;\n                for (int j = i + i; j <= n; j += i)\n                    prime[j] = false;\n            }\n        primes = new int[cnt];\n        cnt = 0;\n        for (int i = 0; i <= n; ++i)\n            if (prime[i])\n                primes[cnt++] = i;\n    }\n\n    void solve() throws IOException {\n        n = ni();\n        k = ni();\n        sieve();\n        int cnt = 0;\n        for (int i = 2; i <= n; ++i) {\n            if (!prime[i])\n                continue;\n            boolean ok = false;\n            for (int j = 0; j < primes.length - 1; ++j)\n                if (primes[j] + primes[j + 1] + 1 == i) {\n                    ok = true;\n                    break;\n                }\n            if (ok)\n                ++cnt;\n        }\n        if (cnt >= k)\n            out.println(\"YES\");\n\n        else\n            out.println(\"NO\");\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", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemaNoldbaha implements Runnable{\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(new ProblemaNoldbaha()).start();\n\t}\n\t\n\tBufferedReader br;\n\tStringTokenizer in;\n\tPrintWriter out;\n\t\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\t\n\t\treturn in.nextToken();\n\t}\n\t\n\tpublic int nextInt() throws IOException{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws IOException{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tpublic void solve() throws IOException{\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\t\n\t\tint[] prime = new int[1000];\n\t\t\n\t\tint l = 0;\n\t\t\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tboolean f = false;\n\t\t\tfor (int j = 2; j < i; j++) {\n\t\t\t\tif (i % j == 0){\n\t\t\t\t\tf = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (!f){\n\t\t\t\tprime[l] = i;\n\t\t\t\tl++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint count = 0;\n\t\tfor (int i = 2; i < l; i++) {\n\t\t\tboolean f = false;\n\t\t\tfor (int j = 0; j < l - 1; j++) {\n\t\t\t\tif (prime[j] + prime[j + 1] + 1 == prime[i]){\n\t\t\t\t\tf = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (f) count++;\n\t\t}\n\t\t\n\t\tif (count >= k){\n\t\t\tout.println(\"YES\");\n\t\t}\n\t\telse{\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\t\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\t\t\t\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t}\n\t\tcatch(IOException e){\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    private static Scanner sc = new Scanner(new InputStreamReader(System.in));\n    public static void main (String[] args) throws IOException {\n        BitSet b = new BitSet(1001);\n        BitSet p = primes(1001);\n        for (int i = 0; i < ps.length - 1; i++) {\n            b.set(ps[i] + ps[i+1] + 1);\n        }\n        int n = sc.nextInt(), k = sc.nextInt();\n        for (int x = 0; x <= n; x++) {\n            if (b.get(x) && p.get(x)) k--;\n        }\n        System.out.println(k > 0 ? \"NO\" : \"YES\");\n    }\n\n    private static BitSet primes (int n) {\n        BitSet b = new BitSet(n+1);\n        b.set(2, n);\n        for (int p = 2; p <= n; p++) {\n            if (b.get(p)) {\n                for (int x = p * 2; x <= n; x += p) {\n                    b.clear(x);\n                }\n            }\n        }\n        return b;\n    }\n        private static int [] ps = new int[] {2,\n                3,\n                5,\n                7,\n                11,\n                13,\n                17,\n                19,\n                23,\n                29,\n                31,\n                37,\n                41,\n                43,\n                47,\n                53,\n                59,\n                61,\n                67,\n                71,\n                73,\n                79,\n                83,\n                89,\n                97,\n                101,\n                103,\n                107,\n                109,\n                113,\n                127,\n                131,\n                137,\n                139,\n                149,\n                151,\n                157,\n                163,\n                167,\n                173,\n                179,\n                181,\n                191,\n                193,\n                197,\n                199,\n                211,\n                223,\n                227,\n                229,\n                233,\n                239,\n                241,\n                251,\n                257,\n                263,\n                269,\n                271,\n                277,\n                281,\n                283,\n                293,\n                307,\n                311,\n                313,\n                317,\n                331,\n                337,\n                347,\n                349,\n                353,\n                359,\n                367,\n                373,\n                379,\n                383,\n                389,\n                397,\n                401,\n                409,\n                419,\n                421,\n                431,\n                433,\n                439,\n                443,\n                449,\n                457,\n                461,\n                463,\n                467,\n                479,\n                487,\n                491,\n                499};\n}\n\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists()) {\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t}\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\t\n\t\tnew Main().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\t\n\tboolean[] erat = new boolean [1000 + 1];\n\tint[] primes = new int [1000 + 1];\n\tint pNum = 0;\n\t\n\tvoid run() throws IOException {\n\t\t\n\t\tfor (int i = 2; i <= 1000; i++) {\n\t\t\tif (!erat[i]) {\n\t\t\t\tprimes[pNum++] = i;\n\t\t\t\tfor (int j = i * i; j <= 1000; j += i)\n\t\t\t\t\terat[j] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] cnt = new int [1000 + 1];\n\t\tcnt[2] = 0;\n\t\t\n\t\tfor (int i = 3; i <= 1000; i++) {\n\t\t\tcnt[i] = cnt[i - 1];\n\t\t\tif (!erat[i]) {\n\t\t\t\tint r = i - 1;\n\t\t\t\tfor (int j = 1; j < pNum; j++) {\n\t\t\t\t\tif (r == primes[j - 1] + primes[j]) {\n\t\t\t\t\t\tcnt[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\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\t\n\t\tout.println(k <= cnt[n] ? \"YES\" : \"NO\");\n\t\t\n\t\tout.close();\n\t}\n\t\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\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", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Naldbah implements Runnable {\n\n    boolean isLocalMode = false;\n\n    public static void main(String[] args) {\n        new Naldbah().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\n    public void run() {\n        try {\n            reader = new BufferedReader(getReader());\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            //do job\n            doJob();\n\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    private void doJob() throws IOException {\n        int n = nextInt();\n        int k = nextInt();\n        boolean[] primes = sieve(n + 1);\n\n        for(int i=n;i>=2;i--){\n            if(primes[i]){\n                int solve = i-1;\n                int sn=getNextD(primes,solve);\n                int en = getNextD(primes,n);\n                while(en!=-1&&sn+en>=solve){\n                    if((sn+en)==solve)k--;\n                    sn=en;\n                    en=getNextD(primes,en);\n                }\n            }\n        }\n        writer.write(k<=0?\"YES\":\"NO\");\n    }\n\n    private int getNextD(boolean[] primes, int i) {\n        for(int p = i-1;p>=2;p--){\n            if(primes[p])return p;\n        }\n        return -1;\n    }\n\n    public boolean[] sieve(int n)\n    {\n       boolean[] prime=new boolean[n+1];\n       Arrays.fill(prime,true);\n       prime[0]=false;\n       prime[1]=false;\n       int m= (int) Math.sqrt(n);\n\n       for (int i=2; i<=m; i++)\n          if (prime[i])\n             for (int k=i*i; k<=n; k+=i)\n                prime[k]=false;\n\n       return prime;\n    }\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    public Reader getReader() throws FileNotFoundException {\n        if (isLocalMode) {\n            return new FileReader(\"input.txt\");\n        } else {\n            return new InputStreamReader(System.in);\n        }\n    }\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew A().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\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\tboolean isPrime(int 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\tvoid solve() {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tArrayList<Integer> primes = new ArrayList<Integer>();\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}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < primes.size(); i++) {\n\t\t\tfor (int j = 0; j < i - 1; j++) {\n\t\t\t\tif (primes.get(j) + primes.get(j + 1) + 1 == primes.get(i)\n\t\t\t\t\t\t.intValue()) {\n\t\t\t\t\tans++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (ans >= k) {\n\t\t\tout.println(\"YES\");\n\n\t\t} else {\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main\n{\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n                int n = sc.nextInt(), k = sc.nextInt(), kol = 0, prev;\n                boolean ok;\n                ArrayList<Integer> al = new ArrayList<Integer>();\n                al.add(2);\n                prev = 2;\n                for(int i=3;i<=n;i+=2)\n                {\n                \tok = true;\n                \tfor(Integer x: al) \n                \tif (i%x == 0)\n                \t{\n                \t\tok = false;\n                \t\tbreak;\n                \t}\n                \tif (ok) \n                \t{\n                \t\tfor(Integer x: al)\n                \t\tif (ok) \n                \t\t{\n                \t\t\tprev = x; \n                \t\t\tok = false;\n                \t\t} else\n                \t\t{\n\t                \t\tif (x + prev + 1 == i) \n\t                \t\t{\n\t                \t\t\tkol++;\n\t                \t\t\tbreak;\n\t                \t\t}\n\t                \t\tif (x + prev + 1 > i) break;\n\t                \t\tprev = x;\n                \t\t}\n                \t\tal.add(i);\n                \t}\n                }\n                if (kol >= k) System.out.print(\"YES\"); else System.out.print(\"NO\");\n\t}\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt()-1;\n\t\tPrimeGen p = new PrimeGen(n);\n\t\tList<Integer> prims = new ArrayList<Integer>();\n\t\tfor(int i = 2; i <= n; i++){\n\t\t\tif(p.isPrime(i)>0){\n\t\t\t\tprims.add(i);\n\t\t\t}\n\t\t}\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < prims.size() - 1; i++){\n\t\t\tint c = prims.get(i) + prims.get(i+1) + 1;\n\t\t\tif(c <= n && p.isPrime(c)>0){\n\t\t\t\tsum ++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(sum>=k?\"YES\":\"NO\");\n\t}\n\n\tstatic int sum(List<Integer> is) {\n\t\tint c = 0;\n\t\tfor (int i : is)\n\t\t\tc += i;\n\t\treturn c;\n\t}\n\t\n\tstatic class PrimeGen {\n\t\tpublic PrimeGen(int m) {\n\t\t\tm = (int) Math.sqrt(m);\n\t\t\tdouble max = 0;\n\t\t\tint r = 1;\n\t\t\tfor (int i = 0; i < 4;) {\n\t\t\t\tmax += r * m / Math.pow(Math.log1p(m), ++i);\n\t\t\t\tr *= i;\n\t\t\t}\n\t\t\tp = new int[(int) max];\n\t\t\tfor (int i = 0, e = 2; i < p.length; i++) {\n\t\t\t\tfor (; isPrime(e) < 1; e++)\n\t\t\t\t\t;\n\t\t\t\tp[i] = e++;\n\t\t\t}\n\t\t\tthis.m = p[p.length - 1];\n\t\t\tthis.m = this.m * this.m;\n\t\t}\n\n\t\tint isPrime(int n) {\n\t\t\tfor (int e : p)\n\t\t\t\tif (e < 1)\n\t\t\t\t\tbreak;\n\t\t\t\telse if (n != e && n % e < 1)\n\t\t\t\t\treturn 0;\n\t\t\treturn 1;\n\t\t}\n\n\t\tint max() {\n\t\t\treturn m;\n\t\t}\n\n\t\tint[] p;\n\t\tint m;\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "//package codeforces.br17;\n\nimport java.io.*;\nimport java.text.DecimalFormat;\n\npublic class ProblemA {\n    public void solve() {\n        boolean oj = true;\n\n        try {\n            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"A.in\");\n            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"A.out\");\n            BufferedReader br = new BufferedReader(reader);\n            PrintWriter out = new PrintWriter(writer);\n\n            MyTokenizer tok = new MyTokenizer(br.readLine());\n\n            int n = (int)tok.getNum();\n            int k = (int)tok.getNum();\n\n            boolean[] isPrime = new boolean[n + 1];\n            for(int i=1;i<=n;i++)\n                isPrime[i] = true;\n            isPrime[1] = false;\n            isPrime[2] = true;\n            for(int i=2;i*i<=n;i++)\n                for(int j=2*i;j<=n;j+=i)\n                    isPrime[j] = false;\n            int[] primes = new int[n];\n            int cur = 0;\n            for(int i=2;i<=n;i++)\n                if (isPrime[i]) {\n                    primes[cur] = i;\n                    cur++;\n                }\n            int count = 0;\n            for(int i=0;i<cur-1;i++) {\n                if (primes[i] + primes[i+1] + 1 <= n && isPrime[primes[i] + primes[i+1] + 1])\n                    count++;\n            }\n            if (count >= k)\n                out.printf(\"YES\");\n            else\n                out.printf(\"NO\");\n\n            \n            br.close();\n            out.close();\n            reader.close();\n            writer.close();\n        }\n        catch (Exception ex) {\n            ex.printStackTrace();\n        }\n        finally {\n        }\n    }\n\n    public static void main(String[] args) {\n        ProblemA f = new ProblemA();\n        f.solve();\n    }\n\n    private class MyTokenizer {\n        private String s;\n        private int cur;\n\n        public MyTokenizer(String s) {\n            this.s = s;\n            cur = 0;\n        }\n\n        public void skip() {\n            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\\n')) {\n                cur++;\n            }\n        }\n\n        public double getNum() {\n            skip();\n            String snum = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.')) {\n                snum += s.charAt(cur);\n                cur++;\n            }\n            return Double.valueOf(snum);\n        }\n\n        public String getString() {\n            skip();\n            String s2 = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) {\n                s2 += s.charAt(cur);\n                cur++;\n            }\n            return s2;\n        }\n\n        public char getCurrentChar() throws Exception {\n            if (cur < s.length())\n                return s.charAt(cur);\n            else\n                throw new Exception(\"Current character out of string length\");\n        }\n\n        public void moveNextChar() {\n            if (cur < s.length())\n                cur++;\n        }\n\n        public boolean isFinished() {\n            return cur >= s.length();\n        }\n    }\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n\tBufferedReader in;  \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\t void 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\tint n = nextInt();\n\t\t\tint k = nextInt();\n\t\t\tint max = 5000;\n\t\t\tArrayList <Integer> primes = new ArrayList <Integer> ();\n\t\t\tboolean [] p = new boolean [max];\n\t\t\tArrays.fill(p, true);\n\t\t\tfor (int i = 2; i < max; i++) {\n\t\t\t\tif (p[i]) {\n\t\t\t\t\tprimes.add(i);\n\t\t\t\t\tfor (int j = i * i; j < max; j += i)\n\t\t\t\t\t\tp[j] = false;\n\t\t\t\t}\t\t\n\t\t\t\t\n\t\t\t}\n\n\t\t\tHashSet <Integer> good = new HashSet <Integer> ();\n\t\t\tfor (int i = 0; i < primes.size() - 1; i++) {\n\t\t\t\tgood.add(primes.get(i) + primes.get(i + 1) + 1);\n\t\t\t}\n\n\t\t\tint have = 0, pos = 0;\n\t\t\twhile (true) {\n\t\t\t\tint i = primes.get(pos);     \n\t\t\t\tif (i > n) break;\n\t\t\t\tif (good.contains(i)) have++;\n\t\t\t\tpos++;\n\t\t\t}\n\t\t\tSystem.out.println(have >= k ? \"YES\" : \"NO\");\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", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.util.Arrays.deepToString;\n\npublic class A {\n\n\tprivate static int[] prime = new int[] {\n\t\t    2,     3,     5,     7,    11,    13,    17,    19,    23,    29,    31,    37,    41,    43,\n\t\t   47,    53,    59,    61,    67,    71,    73,    79,    83,    89,    97,   101,   103,   107,\n\t\t  109,   113,   127,   131,   137,   139,   149,   151,   157,   163,   167,   173,   179,   181,\n\t\t  191,   193,   197,   199,   211,   223,   227,   229,   233,   239,   241,   251,   257,   263,\n\t\t  269,   271,   277,   281,   283,   293,   307,   311,   313,   317,   331,   337,   347,   349,\n\t\t  353,   359,   367,   373,   379,   383,   389,   397,   401,   409,   419,   421,   431,   433,\n\t\t  439,   443,   449,   457,   461,   463,   467,   479,   487,   491,   499,   503,   509,   521,\n\t\t  523,   541,   547,   557,   563,   569,   571,   577,   587,   593,   599,   601,   607,   613,\n\t\t  617,   619,   631,   641,   643,   647,   653,   659,   661,   673,   677,   683,   691,   701,\n\t\t  709,   719,   727,   733,   739,   743,   751,   757,   761,   769,   773,   787,   797,   809,\n\t\t  811,   821,   823,   827,   829,   839,   853,   857,   859,   863,   877,   881,   883,   887,\n\t\t  907,   911,   919,   929,   937,   941,   947,   953,   967,   971,   977,   983,   991,   997\t\t\t\t\n\t};\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\t\n\t\tfor (int i=0;i<prime.length-1;i++) {\n\t\t\tif ((prime[i]+prime[i+1]+1) > n || k == 0)\n\t\t\t\tbreak;\n\t\t\tif (isPrime(prime[i]+prime[i+1]+1))\n\t\t\t\tk--;\n\t\t}\n\t\t\n\t\tif (k == 0)\n\t\t\toutnl(\"YES\");\n\t\telse\n\t\t\toutnl(\"NO\");\n\t}\n\t\n\tpublic static boolean isPrime(int x) {\n\t\tint i=0;\n\t\twhile (i<prime.length)\n\t\t\tif (prime[i++] == x)\n\t\t\t\treturn true;\n\t\treturn false;\n\t}\n\t\n\tprivate static void debug(Object... os) { System.out.println(deepToString(os)); }\n\tprivate static void outnl(String out) { System.out.println(out); } \n\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport javax.script.*;\n\npublic class Noldbach {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint k=sc.nextInt();\n\t\tboolean[] sieve=new boolean[1001];\n\t\tsieve[2]=false;\n\t\tArrayList<Integer> primes=new ArrayList<Integer>();\n\t\tfor(int x=2;x<1001;x++)\n\t\t\tif(!sieve[x])\n\t\t\t{\n\t\t\t\tprimes.add(x);\n\t\t\t\tfor(int y=x;y<1001;y+=x)\n\t\t\t\t\tsieve[y]=true;\n\t\t\t}\n\t\tint sum=0;\n\t\tfor(int x=2;x<=n;x++)\n\t\t{\n\t\t\tif(primes.contains(x))\n\t\t\t{\n\t\t\tint need=x-1;\n\t\t\tfor(int y=0;y<primes.size()-1;y++)\n\t\t\t{\n\t\t\t\tif(primes.get(y)+primes.get(y+1)==need)\n\t\t\t\t{\n\t\t\t\t\tsum++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t}\n\t\t\tif(sum==k)break;\n\t\t}\n\t\tif(sum==k)System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t\t\n\t}\n\t\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;         \nimport java.util.*;         \nimport java.math.*;         \n\n \npublic class Main  implements Runnable {\n//public static final String FileName = \"test\";\nStreamTokenizer ST;      \nPrintWriter out;      \nBufferedReader br;   \nScanner in;\nstatic final int inf = 1000000000;\n \nint nextInt() throws IOException{      \n    ST.nextToken();      \n    return (int)ST.nval;      \n}\nlong nextLong() throws IOException{      \n    ST.nextToken();      \n    return (long)ST.nval;      \n}      \nString next() throws IOException{      \n    ST.nextToken();      \n    return ST.sval;      \n}      \ndouble nextD() throws IOException{      \n    ST.nextToken();      \n    return ST.nval;      \n}      \npublic static void main(String[] args) throws IOException {       \n   new Thread(new Main()).start();\n//  new Main().run();\n}\n \npublic void run()  {      \n    try {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));      \n        //br = new BufferedReader(new FileReader(new File(FileName+\".in\")));\n        //out = new PrintWriter(new BufferedWriter(new FileWriter(FileName+\".out\")));\n        in = new Scanner(br);\n        ST = new StreamTokenizer(br);      \n        solve();      \n        out.close();\n        //in.close();\n        br.close();   \n    }         \n    catch (IOException e) {       \n        e.printStackTrace();\n        throw new IllegalStateException(e);  \n    }      \n}\n\n\npublic void solve() throws IOException {\n    int n = nextInt();\n    int K = nextInt();\n    boolean[] f = new boolean[n+1];\n    Arrays.fill(f, true);\n    Vector<Integer> P = new Vector<Integer>();\n    for (int i=2; i<=n; i++)\n        if (f[i]) {\n            for (int j=2*i; j<=n; j+=i) \n                f[j] = false;\n            P.add(i);\n        }\n    for (int i=0; i<P.size()-1; i++) {\n        int x = P.elementAt(i)+P.elementAt(i+1)+1;\n        if (x<=n && f[x]) K--;\n    }\n    if (K<=0) out.println(\"YES\"); else out.println(\"NO\");\n    //for (int x:P) out.print(x+\" \");\n    \n}\n  \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n  ", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\npublic class A {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = new String(in.readLine());\n        String[] t=s.split(\" \");\n        int n = Integer.parseInt(t[0]);\n        int k = Integer.parseInt(t[1]);\n        boolean[] prime=new boolean[n+1];\n        for (int i=2;i<Math.sqrt(n);i++) {\n        \tfor (int j=i+i;j<=n;j=j+i) {\n        \t\tprime[j]=true;\n        \t}\n        }\n        int size=0;\n        for (int i=2;i<=n;i++) {\n        \tif (!prime[i]) {\n        \t\tsize++;\n        \t}\n        }\n        int[] pn=new int[size];\n        int index=0;\n        for (int i=2;i<=n;i++) {\n        \tif (!prime[i]) {\n        \t\tpn[index]=i;\n        \t\tindex++;\n        \t}        \t\n        }\n        for (int i=2;i<size;i++) {\n        \tfor (int j=0;j<i;j++) {\n        \t\tif (pn[i]==pn[j]+pn[j+1]+1) {\n//       \t\t\tSystem.out.println(pn[i]+\"=\"+pn[j]+\"+\"+pn[j+1]+\"+1\");\n        \t\t\tk--;\n        \t\t}\n        \t}\n        }\n        if (k<=0) {\n        \tSystem.out.println(\"YES\");\n        } else {\n        \tSystem.out.println(\"NO\");\n        }\n\t}\n\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.HashSet;\n\npublic class E17 {\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\t\t\n\t\tint n = nextInt(), k = nextInt();\n\t\tint MAX = n, nprimes = 0;\n\t\tint[] primes = new int[MAX];\n\t\tboolean[] isPrime = new boolean[MAX+1];\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = false;\n\t\tisPrime[1] = false;\n\t\tfor (int i = 2; i <= MAX; i++) if (isPrime[i]) {\n\t\t\tprimes[nprimes++] = i;\n\t\t\tfor (int j = i + i; j <= MAX; j += i) isPrime[j] = false;\n\t\t}\n\t\tprimes[nprimes] = Integer.MAX_VALUE;\n\t\t\n\t\tHashSet<Integer> h = new HashSet<Integer>();\n\t\tfor (int i = 1; i < nprimes; i++) {\n\t\t\tint x = primes[i-1] + primes[i] + 1;\n\t\t\tif (x > n) break;\n\t\t\tif (isPrime[x]) h.add(x);\n\t\t}\n\t\t\n\t\tout.println(h.size() >= k ? \"YES\" : \"NO\");\n\t\t\n\t\tout.flush();\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt()-1;\n\t\tPrimeGen p = new PrimeGen(n);\n\t\tList<Integer> prims = new ArrayList<Integer>();\n\t\tfor(int i = 2; i <= n; i++){\n\t\t\tif(p.isPrime(i)>0){\n\t\t\t\tprims.add(i);\n\t\t\t}\n\t\t}\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < prims.size() - 1; i++){\n\t\t\tint c = prims.get(i) + prims.get(i+1) + 1;\n\t\t\tif(c <= n && p.isPrime(c)>0){\n\t\t\t\tsum ++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(sum>=k?\"YES\":\"NO\");\n\t}\n\n\tstatic int sum(List<Integer> is) {\n\t\tint c = 0;\n\t\tfor (int i : is)\n\t\t\tc += i;\n\t\treturn c;\n\t}\n\t\n\tstatic class PrimeGen {\n\t\tpublic PrimeGen(int m) {\n\t\t\tm = (int) Math.sqrt(m);\n\t\t\tdouble max = 0;\n\t\t\tint r = 1;\n\t\t\tfor (int i = 0; i < 4;) {\n\t\t\t\tmax += r * m / Math.pow(Math.log1p(m), ++i);\n\t\t\t\tr *= i;\n\t\t\t}\n\t\t\tp = new int[(int) max];\n\t\t\tfor (int i = 0, e = 2; i < p.length; i++) {\n\t\t\t\tfor (; isPrime(e) < 1; e++)\n\t\t\t\t\t;\n\t\t\t\tp[i] = e++;\n\t\t\t}\n\t\t\tthis.m = p[p.length - 1];\n\t\t\tthis.m = this.m * this.m;\n\t\t}\n\n\t\tint isPrime(int n) {\n\t\t\tfor (int e : p)\n\t\t\t\tif (e < 1)\n\t\t\t\t\tbreak;\n\t\t\t\telse if (n != e && n % e < 1)\n\t\t\t\t\treturn 0;\n\t\t\treturn 1;\n\t\t}\n\n\t\tint max() {\n\t\t\treturn m;\n\t\t}\n\n\t\tint[] p;\n\t\tint m;\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tArrayList<Integer> ps = new ArrayList<Integer>();\n\t\tboolean[] prime = new boolean[n + 1];\n\t\tArrays.fill(prime, true);\n\t\tprime[0] = prime[1] = false;\n\t\tfor (int i = 2; i <= n; ++i) {\n\t\t\tif (prime[i]) {\n\t\t\t\tps.add(i);\n\t\t\t\tfor (int j = 2 * i; j <= n; j += i) {\n\t\t\t\t\tprime[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < ps.size() - 1; ++i) {\n\t\t\tint t = ps.get(i) + ps.get(i + 1) + 1;\n\t\t\tif (t <= n && prime[t]) {\n\t\t\t\t--k;\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(k);\n\t\tout.println(k <= 0 ? \"YES\" : \"NO\");\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", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.regex.*;\nimport java.text.*;\nimport java.math.*;\npublic class Main\n{\n    Scanner cin;\n    int []prime;\n    int top;\n    void work()\n    {\n        cin=new Scanner(System.in); \n        int n=cin.nextInt();\n        int k=cin.nextInt();\n        top=0;\n        prime=new int[2000];\n        for(int i=2;i<=n;i++)\n        {\n        \tif(isprime(i))\n        \t\tprime[top++]=i;\n        }\n        int cnt=0;\n        for(int i=0;i<top;i++)\n        {\n        \tif(cando(prime[i]))\n        \t\tcnt++;\n        }\n        if(cnt>=k) System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n    }\n    boolean cando(int n)\n    {\n    \tfor(int i=0;i<top-1;i++)\n    \t{\n    \t\tif(prime[i]+prime[i+1]+1==n) return true;\n    \t}\n    \treturn false;\n    }\n    boolean isprime(int n)\n    {\n    \tfor(int i=2;i*i<=n;i++)\n    \t\tif(n%i==0)return false;\n    \treturn true;\n    }\n  public static void main(String args[]) throws Exception \n  { \n   \n   new Main().work();\n  } \n\n\n}  \n\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Beta17PA {\n\n\tboolean[] isPrime = new boolean[1001];\n\tint[] prime = new int[200];\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tnew Beta17PA().solve();\n\t}\n\n\tpublic void solve() {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n, k;\n\t\tn = scan.nextInt();\n\t\tk = scan.nextInt();\n\t\tinit();\n\t\tint m = 0;\n\t\tfor(int i=2; i<=n; i++) {\n\t\t\tif(check(i)) m ++;\n\t\t}\n\t\tif(m>=k) System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t}\n\n\tprivate boolean check(int n) {\n\t\tif(n<6||!isPrime[n]) return false;\n\t\tint d = n-1;\n\t\tfor(int i=0; i<199&&prime[i]+prime[i+1]<=d; i++) {\n\t\t\tif(prime[i]+prime[i+1]==d) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate void init() {\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = isPrime[1] = false;\n\t\tfor(int i=2; i<1001; i++) {\n\t\t\tif(!isPrime[i]) continue;\n\t\t\tfor(int j=i+i; j<1001; j+=i) {\n\t\t\t\tisPrime[j] = false;\n\t\t\t}\n\t\t}\n\t\tint count = 0;\n\t\tfor(int i=2; i<1001; i++) {\n\t\t\tif(isPrime[i]) prime[count++] = i;\n\t\t}\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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 A {\n    BufferedReader in;\n    StringTokenizer st;\n    PrintWriter out;\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int k = nextInt();\n        boolean[] sieve = new boolean[n + 1];\n        List<Integer> primes = new ArrayList<Integer>();\n        for (int i = 2; i <= n; ++i) {\n            if (!sieve[i]) {\n                primes.add(i);\n                for (int j = 2 * i; j <= n; j += i) {\n                    sieve[j] = true;\n                }\n            }\n        }\n        int count = 0;\n        for (int i = 0; i + 1 < primes.size(); ++i) {\n            int v = primes.get(i) + primes.get(i + 1) + 1;\n            if (v <= n && !sieve[v]) {\n                ++count;\n            }\n        }\n//        System.err.println(count);\n        out.println(count >= k ? \"YES\" : \"NO\");\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 A().run();\n    }\n}", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution implements Runnable{\n    private static BufferedReader br = null;\n    private static PrintWriter out = null;\n    private static StringTokenizer stk = null;\n    \n    public static void main(String[] args) {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        (new Thread(new Solution())).start();\n    }\n    \n    private void loadLine() {\n        try {\n            stk = new StringTokenizer(br.readLine());\n        }\n        catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    private String nextLine() {\n        try {\n            return br.readLine();\n        }\n        catch (IOException e) {\n            e.printStackTrace();\n        }\n        return null;\n    }\n    \n    private Integer nextInt() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Integer.parseInt(stk.nextToken());\n    }\n    \n    private Long nextLong() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Long.parseLong(stk.nextToken());\n    }\n    \n    private String nextWord() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return (stk.nextToken());\n    }\n    \n    private Double nextDouble() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Double.parseDouble(stk.nextToken());\n    }\n    \n    public void run() {\n        int n = nextInt();\n        int k = nextInt();\n        \n        boolean[] isP = new boolean[2*n];\n        Arrays.fill(isP, true);\n        isP[0] = isP[1] = false;\n        \n        for (int i = 0; i <= n; ++i) {\n            if (isP[i]) {\n                for (int j = i+i; j <= n; j+=i) {\n                    isP[j] = false;\n                }\n            }\n        }\n        \n        ArrayList<Integer> p = new ArrayList<Integer>();\n        for (int i = 0; i <= n; ++i) {\n            if (isP[i]) {\n                p.add(i);\n            }\n        }\n        \n        int cnt = 0;\n        for (int i = 0; i < p.size(); ++i) {\n            int num = p.get(i) - 1;\n            \n            for (int j = 0; j < p.size() - 1; ++j) {\n                if (p.get(j) + p.get(j+1) == num) {\n                    ++cnt;\n                    break;\n                }\n            }\n        }\n        \n        if (cnt >= k) {\n            out.println(\"YES\");\n        }\n        else {\n            out.println(\"NO\");\n        }\n        out.flush();\n    }\n}\n\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Primes\n{\n\tstatic Scanner in = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) );\n\n\tpublic static void main( String[] args )\n\t{\n\t\tint n = in.nextInt(), k = in.nextInt(), count = 0;\n\t\tboolean[] isP = new boolean[n+1];\n\t\tfor( int i = 2; i <= n; i++ ) isP[i] = true;\n\t\tArrayList<Integer> primes = new ArrayList<Integer>();\n\t\tfor( int i = 2; i <= n; i++ ) if( isP[i] )\n\t\t{\n\t\t\tprimes.add(i);\n\t\t\tif( i <= Math.sqrt(n) ) for( int j = 2*i; j <= n; j += i ) isP[j] = false;\n\t\t}\n\t\tfor( int i = 0; i < primes.size()-1; i++ )\n\t\t{\n\t\t\tint sum = primes.get(i)+primes.get(i+1)+1;\n\t\t\tif( sum<=n && isP[sum] ) count++;\n\t\t}\n\t\tif( count>=k ) System.out.println( \"YES\" );\n\t\telse System.out.println( \"NO\" );\n\t}\n}\n", "complexity": "linear", "problem": "17_A. Noldbach problem", "from": "CODEFORCES"}
{"src": "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.HashSet;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tstatic ArrayList<Integer> [] adj;\n\tstatic int [] num;\n\tstatic int dfs(int u, int p){\n\t\tint cnt = 0;\n\t\tfor(int v:adj[u]){\n\t\t\tif(v != p)\n\t\t\t\tcnt += dfs(v, u);\n\t\t}\n\t\tif(adj[u].size() == 1 && u != 0 || u == 0 && adj[0].size() == 0)\n\t\t\tcnt++;\n\t\tnum[cnt]++;\n\t\treturn cnt;\n\t}\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tadj = new ArrayList[n];\n\t\tfor (int i = 0; i < adj.length; ++i) {\n\t\t\tadj[i] = new ArrayList<>();\n\t\t}\n\t\tfor (int i = 1; i < n; ++i) {\n\t\t\tint p = sc.nextInt()-1;\n\t\t\tadj[p].add(i);\n\t\t\tadj[i].add(p);\n\t\t}\n\t\tnum = new int[n+1];\n\t\tdfs(0, -1);\n\t\tfor (int i = 1; i < num.length; ++i) {\n\t\t\tnum[i] += num[i-1];\n\t\t}\n\t\tint cur = 1;\n\t\tfor (int i = 0; i < num.length; ++i) {\n\t\t\twhile(cur <= num[i]){\n\t\t\t\tout.print(i + \" \");\n\t\t\t\t++cur;\n\t\t\t}\t\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\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\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "1056_D. Decorate Apple Tree", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.min;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic void solve() throws Exception {\n\t\tint n = scanInt();\n\t\tlong l[] = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tl[i] = scanLong();\n\t\t}\n\t\tlong e1 = 0, e2 = 0, ans = 0;\n\t\tboolean water = false;\n\t\tString types = scanString();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong li = l[i], cur;\n\t\t\tswitch (types.charAt(i)) {\n\t\t\tcase 'G':\n\t\t\t\tcur = min(e1, li);\n\t\t\t\te1 -= cur;\n\t\t\t\tli -= cur;\n\t\t\t\te2 += 2 * cur;\n\t\t\t\tans += 2 * cur;\n\t\t\t\te2 += li;\n\t\t\t\tans += 3 * li;\n\t\t\t\tbreak;\n\t\t\tcase 'W':\n\t\t\t\twater = true;\n\t\t\t\te1 += li;\n\t\t\t\tans += 2 * li;\n\t\t\t\tbreak;\n\t\t\tcase 'L':\n\t\t\t\tcur = min(e1, li);\n\t\t\t\te1 -= cur;\n\t\t\t\tli -= cur;\n\t\t\t\tans += 2 * cur;\n\t\t\t\tcur = min(e2, li);\n\t\t\t\te2 -= cur;\n\t\t\t\tli -= cur;\n\t\t\t\tans += 3 * cur;\n\t\t\t\tans += (water ? 4 : 6) * li;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "1091_F. New Year and the Mallard Expedition", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\n    static final long mod=(int)1e9+7;\n    public static void main(String[] args) throws Exception\n    {\n    \tFastReader in=new FastReader();\n    \tPrintWriter pw=new PrintWriter(System.out);\n    \tint n=in.nextInt();\n    \tlong ans=0;\n    \tfor(int i=2;2*i<=n;i++)\n    \t{\n    \t\tans+=i*(n/i-1);\n    \t}\n    \tans*=4;\n    \tpw.print(ans);\n    \tpw.flush();\n    }\n}\n\nclass pair\n{\n\tint f,s;\n}\n\nclass FastReader\n{\n    BufferedReader br;\n    StringTokenizer st;\n \n    public FastReader()\n    {\n        br=new BufferedReader(new InputStreamReader(System.in));\n    }\n \n    public String next() throws IOException\n    {\n        if(st==null || !st.hasMoreElements())\n        {\n            st=new StringTokenizer(br.readLine());\n        }\n        return st.nextToken();\n    }\n \n    public int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n \n    public long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n}", "complexity": "linear", "problem": "1062_D. Fun with Integers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class C {\n\n\tpublic static int mod = 1000000000 + 7;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tString n = br.readLine();\n\t\tint k = Integer.parseInt(br.readLine());\n\t\tint l = n.length();\n\t\t\n\t\tif(k == 0) {\n\t\t\tSystem.out.println(1);\n\t\t}else {\n\t\t\tint max = 1000;\n\t\t\tif (l <= 10) {\n\t\t\t\tmax = Integer.min(1000, Integer.parseInt(n, 2));\n\t\t\t}\n\n\t\t\tint[] steps = new int[max + 1];\n\t\t\t\t\t\n\t\t\tfor (int i = 2; i <= max; i++) {\n\t\t\t\tint ones = numberOfOnes(i);\n\t\t\t\tsteps[i] = 1 + steps[ones];\n\t\t\t}\n\n\t\t\tif (l <= 10) {\n\t\t\t\tint ans = 0;\n\t\t\t\tfor (int i = 1; i <= max; i++) {\n\t\t\t\t\tif (steps[i] == k) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.println(ans);\n\t\t\t} else {\n\t\t\t\tint[][] C = binomial(max);\n\n\t\t\t\tint ans = 0;\n\t\t\t\tint count = 0;\n\n\t\t\t\tfor (int i = 0; i < l; i++) {\n\t\t\t\t\tif (n.charAt(i) == '1') {\n\t\t\t\t\t\tfor (int j = count; j < max; j++) {\n\t\t\t\t\t\t\tif (steps[j] == k - 1) {\n\t\t\t\t\t\t\t\tans = (ans + C[l - i - 1][j - count]) % mod;\n\t\t\t\t\t\t\t\tif (i == 0 && k == 1) {\n\t\t\t\t\t\t\t\t\tans = (ans + mod - 1) % 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\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tint ones = 0;\n\t\t\t\tfor (int i = 0; i < l; i++) {\n\t\t\t\t\tif (n.charAt(i) == '1') {\n\t\t\t\t\t\tones++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (steps[ones] == k-1) {\n\t\t\t\t\tans = (ans + 1) % mod;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static int numberOfOnes(int x) {\n\t\tchar[] s = Integer.toBinaryString(x).toCharArray();\n\t\tint count = 0;\n\t\tfor (char c : s) {\n\t\t\tif (c == '1') {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n\n\tpublic static int[][] binomial(int n) {\n\t\tint[][] C = new int[n + 1][n + 1];\n\n\t\tfor (int i = 0; i <= n; 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] % mod) + (C[i - 1][j] % mod)) % mod;\n\t\t\t}\n\t\t}\n\n\t\treturn C;\n\t}\n\n}\n", "complexity": "linear", "problem": "914_C. Travelling Salesman and Special Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class A{\n       \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 = 1; i <= n; i++){\n                     ans += ((i*2) <= n) ? i : n-i+1;\n              }\n              System.out.println(ans);\n       }\n}", "complexity": "linear", "problem": "909_B. Segments", "from": "CODEFORCES"}
{"src": "import java.util.*;\n \npublic class Main {\n  public static void main(String[] args) {\n    Scanner sc = new Scanner(System.in);\n\t int[][] x = new int [200010][10];\n     String a = sc.nextLine(); \n     String b = sc.nextLine(); \n \t  int n = a.length();\n\t  int m = b.length();\n       for (int i = 1; i <= m; i++) {\n         for (int j = 0; j < 2; j++) {\n           x[i][j] = x[i - 1][j];\n         }\n         ++x[i][b.charAt(i - 1) - '0'];\n       }\n       long res = 0;\n        for (int i = 0, c; i < n; i++) {\n          c = a.charAt(i) - '0';\n           for (int j = 0; j < 2; j++) {\n             res += Math.abs(c - j) * (x[m - n + i + 1][j] - x[i][j]);\n           }\n        }\n         System.out.println(res);\n  }\n}", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\npublic class TaskB implements Runnable {\n    boolean prime[] = new boolean[(int)1e6+10];\n    InputReader c;\n    PrintWriter w;\n\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n\n        char a[] = c.next().toCharArray(), b[] = c.next().toCharArray();\n        int n = a.length, m = b.length;\n\n        int[][] prefix = new int[m][2];\n        for(int i=0;i<m;i++){\n            if(i!=0) {\n                prefix[i][0] = prefix[i-1][0];\n                prefix[i][1] = prefix[i-1][1];\n            }\n            prefix[i][b[i] - '0']++;\n            //w.println(prefix[i][0]+\" \"+prefix[i][1]);\n        }\n\n        long res = 0;\n        for(int i=0;i<n;i++){\n            int temp = a[i] - '0';\n\n            res += prefix[m - n + i][temp^1];\n            if(i!=0) res -= prefix[i-1][temp^1];\n        }\n\n        w.println(res);\n\n        w.close();\n    }\n\n    void sieveOfEratosthenes(int n) {\n        for(int i=0;i<n;i++)\n            prime[i] = true;\n\n        for(int p = 2; p*p <=n; p++)\n        {\n            if(prime[p] == true)\n            {\n                for(int i = p*p; i <= n; i += p)\n                    prime[i] = false;\n            }\n        }\n    }\n    class pair implements Comparable<pair>{\n        char ch;\n        int ind;\n\n        @Override\n        public String toString() {\n            return \"pair{\" +\n                    \"ch=\" + ch +\n                    \", ind=\" + ind +\n                    '}';\n        }\n\n        public pair(char ch, int ind) {\n            this.ch = ch;\n            this.ind = ind;\n        }\n        public int compareTo(pair car) {\n            if(this.ch==car.ch)\n                return this.ind - car.ind;\n            return this.ch - car.ch;\n        }\n    }\n    public static void sortbyColumn(int arr[][], int col){\n        Arrays.sort(arr, new Comparator<int[]>()\n        {\n            public int compare(int[] o1, int[] o2){\n                return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    static long gcd(long a, long b){\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static class DJSet {\n        public int[] upper;\n        public DJSet(int n) {\n            upper = new int[n];\n            Arrays.fill(upper, -1);\n        }\n\n        public int root(int x) {\n            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n        }\n\n        public boolean equiv(int x, int y) {\n            return root(x) == root(y);\n        }\n\n        public boolean union(int x, int y) {\n            x = root(x);\n            y = root(y);\n            if (x != y) {\n                if (upper[y] < upper[x]) {\n                    int d = x;\n                    x = y;\n                    y = d;\n                }\n                upper[x] += upper[y];\n                upper[y] = x;\n            }\n            return x == y;\n        }\n    }\n    public static int[] radixSort(int[] f) {\n        int[] to = new int[f.length];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n    public void printArray(int[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n){\n        int a[] = new int[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n){\n        long a[] = new long[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars==-1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                }\n                catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        public int nextInt() {\n            int c = read();\n\n            while(isSpaceChar(c))\n                c = read();\n\n            int sgn = 1;\n\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n\n            int res = 0;\n            do {\n                if(c<'0'||c>'9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskB(),\"TaskB\",1<<26).start();\n    }\n}\n\n\n\n", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class HammingDistancesSum {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString  a = sc.nextLine(), b = sc.nextLine();\n\t\tlong sum = 0;\n\t\tint frequency[][] = new int[200010][2];\n\t\tfor (int i = 1; i <= b.length(); i++) {\n\t        for (int j = 0; j < 2; j++)\n\t            frequency[i][j] = frequency[i - 1][j];\n\t        frequency[i][Character.getNumericValue((b.charAt(i - 1)))]++;\n\t    }\n\t   \n\t    for (int i = 0; i < a.length(); i++) {\n\t        int c = Character.getNumericValue(a.charAt(i));\n\t        for (int j = 0; j < 2; j++) {\n\t        \tint flippingTerm = Math.abs(c - j);\n\t        \tint endOfWindowValue = frequency[b.length() - a.length() + i + 1][j];\n\t        \tint startOfWindowOffset = frequency[i][j];\n\t            sum += flippingTerm * (endOfWindowValue - startOfWindowOffset);\n\t        }\n\t    }\n\t\tSystem.out.println(sum);\n\t\tsc.close();\n\t}\n}\n", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "/* 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\tstatic int check(int temp)\n\t{\n\t\tint count1 = 0; \n    while (temp>0) \n    { \n        if(temp % 2 != 0) \n        count1++; \n        temp/= 2; \n    } \n    return count1;\n\t}\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\tString a=sc.next();\n\t\tString b=sc.next();\n\t\tint m=a.length();\n\t\tint n=b.length();\n\t\tint[] zero=new int[n];\n\t\tint[] one=new int[n];\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tif(i==0)\n\t\t\t{\n\t\t\t\tif(b.charAt(i)=='0')\n\t\t\t\tzero[i]++;\n\t\t\t\telse\n\t\t\t\tone[i]++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tzero[i]=zero[i-1];\n\t\t\t\tone[i]=one[i-1];\n\t\t\t\tif(b.charAt(i)=='0')\n\t\t\t\tzero[i]++;\n\t\t\t\telse\n\t\t\t\tone[i]++;\n\t\t    }\n\t\t}\n\t\t\n\n\t\tlong res=0;\n\t\tfor(int i=0;i<m;i++)\n\t\t{\n\t\tint x=n-m+i;\n\t\tif(a.charAt(i)=='0')\n\t\tres+=one[x];\n\t\telse\n\t\tres+=zero[x];\n\t\tif(i>0)\n\t\t{\n\t\t\tif(a.charAt(i)=='0')\n\t\t\tres-=one[i-1];\n\t\t\telse\n\t\t\tres-=zero[i-1];\n\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(res);\n\t}\n}", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Long.*;\nimport static java.lang.Math.*;\nimport static java.lang.System.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class Main {\n\n    Main() throws IOException {\n        String a = nextLine();\n        String b = nextLine();\n        long ans = 0;\n        int s = 0;\n        for (int i = 0; i < b.length() - a.length(); ++i) {\n            s += b.charAt(i) == '1' ? 1 : 0;\n        }\n\n        for (int i = 0; i < a.length(); ++i) {\n            s += b.charAt(i + b.length() - a.length()) == '1' ? 1 : 0;\n            ans += a.charAt(i) == '1' ? b.length() - a.length() + 1 - s : s;\n            s -= b.charAt(i) == '1' ? 1 : 0;\n        }\n        out.println(ans);\n    }\n\n\n    //////////////////////////////\n    PrintWriter out = new PrintWriter(System.out, false);\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer stok = null;\n    String nextLine() throws IOException {\n        while (stok == null || !stok.hasMoreTokens()) {\n            stok = new StringTokenizer(in.readLine());\n        }\n        return stok.nextToken();\n    }\n\n\n    public static void main(String args[]) throws IOException {\n        if (args.length > 0) {\n            setIn(new FileInputStream(args[0] + \".inp\"));\n            setOut(new PrintStream(args[0] + \".out\"));\n        }\n        Main solver = new Main();\n        solver.out.flush();  //  could be replace with a method, but nah, this is just competitive programming :p\n    }\n}\n", "complexity": "linear", "problem": "608_B. Hamming Distance Sum", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\n\npublic class B {\n\t\n\t// -- DEBUG switch --\n\tstatic final boolean DBG = false;\n\tstatic StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\tstatic PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\tstatic int[] e = new int[100001];\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = i(), k = i(), cnt = 0;\n\t\tint[] a = new int[n+1];\n\t\tfor (int i=1; i<=n; i++){\n\t\t\ta[i] = i();\n\t\t\tif (e[a[i]] == 0)\n\t\t\t\tcnt++;\n\t\t\te[a[i]]++;\n\t\t}\n\t\tif (k > cnt){\n\t\t\tpw.println(\"-1 -1\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif (cnt == n){\n\t\t\tpw.print(\"1 \" + k);\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif (k == 1){\n\t\t\tpw.println(\"1 1\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tArrays.fill(e, 0);\n\t\tint i = 1, j = 0, unik = 0, start = 0, end = 0, len = n, m = 0;\n\n\n\t\tif (e[a[i]] == 0){\n\t\t\tunik++;\n\t\t}\n\t\te[a[i]]++;\n\t\twhile (i+1<=n && a[i+1] == a[i]){\n\t\t\ti = i+1;\n\t\t}\t\t\n\t\t\n\t\tj = i+1;\n\t\t\n\t\twhile (j <= n){\n\t\t\tif (e[a[j]] == 0){\n\t\t\t\tunik++;\n\t\t\t\tif (unik == k){\n\t\t\t\t\twhile (e[a[i]] > 1){\n\t\t\t\t\t\te[a[i]]--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\twhile (i+1<=n && a[i+1] == a[i]){\n\t\t\t\t\t\t\ti = i+1;\n\t\t\t\t\t\t}\t\n\t\t\t\t\t}\n\t\t\t\t\tm = j - i + 1;\n\t\t\t\t\tif (m < len){\n\t\t\t\t\t\tstart = i; end = j; len = m;\n\t\t\t\t\t\tif (m == k)\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\twhile (i <=n && unik == k){\n\t\t\t\t\t\te[a[i]]--;\n\t\t\t\t\t\tif (e[a[i]] == 0)\n\t\t\t\t\t\t\tunik--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\n\t\t\t\t\t\twhile (i+1<=n && a[i+1] == a[i]){\n\t\t\t\t\t\t\ti = i+1;\n\t\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t}\n\t\t\te[a[j]]++;\n\t\t\twhile (j+1<=n && a[j+1] == a[j]){\n\t\t\t\tj++;\n\t\t\t}\t\t\t\n\t\t\tj++;\n\n\t\t}\n\t\tpw.println(start + \" \" + end);\t\n\t\tpw.close();\n\t}\n\t\n\tstatic int i() throws IOException{\n\t\tst.nextToken();\n\t\treturn (int)st.nval;\n\t}\n\t\n\tstatic long l() throws IOException {\n\t\tst.nextToken();\n\t\treturn (long)st.nval;\n\t}\n\n\tstatic double d() throws IOException {\n\t\tst.nextToken();\n\t\treturn st.nval;\n\t}\n\tstatic String s() throws IOException{\n\t\tst.nextToken();\n\t\treturn st.sval;\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Array {\n\t\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();\n\t\t/*\n\t\tif ( k == 1 ){ \n\t\t\tSystem.out.println(\"1 1\"); return;\n\t\t}\n\t\t*/\n\t\tint last[] = new int[100001];\n\t\tint distinct = 0;\n\t\tfor ( int i = 0 ; i < n ; ++i ) {\n\t\t\tint t = in.nextInt();\n\t\t\tif ( last[t] == 0 ) ++distinct;\n\t\t\tlast[t] = i+1;\n\t\t\tif ( distinct == k ) {\n\t\t\t\tint min = i+1;\n\t\t\t\tfor ( int j = 0 ; j < last.length ; ++j ) {\n\t\t\t\t\tif ( last[j] != 0 ) min = min>last[j]?last[j]:min;\n\t\t\t\t}\n\t\t\t\tSystem.out.println(min+\" \"+(i+1)); return;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"-1 -1\"); \n\t}\n\t\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\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.Set;\nimport java.util.StringTokenizer;\n\n\npublic class C_138B {\n\tprivate static BufferedReader in;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter out;\n\t\n\t\n\tstatic String nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tstatic int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tst = new StringTokenizer(\"\");\n\t\tout = new PrintWriter(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\tSet<Integer> set = new HashSet<Integer>();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tset.add(a[i]);\n\t\t\tif(set.size()==k){\n\t\t\t\tSet<Integer> set2 = new HashSet<Integer>();\n\t\t\t\tfor (int j = i; j >= 0; j--) {\n\t\t\t\t\tset2.add(a[j]);\n\t\t\t\t\tif(set2.size()==k){\n\t\t\t\t\t\tout.print((j+1)+\" \"+(i+1));\n\t\t\t\t\t\tout.close();\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.print(\"-1 -1\");\t\t\n\t\tout.close();\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Array {\n\n    void run() {\n        try {\n            BufferedReader bfd = new BufferedReader(new InputStreamReader(\n                    System.in));\n            StringTokenizer tk = new StringTokenizer(bfd.readLine());\n            int n = Integer.parseInt(tk.nextToken());\n            int k = Integer.parseInt(tk.nextToken()), i;\n            int arr[] = new int[n];\n            tk = new StringTokenizer(bfd.readLine());\n            for(i=0;i<n;++i)\n                arr[i] = Integer.parseInt(tk.nextToken());\n            int dist=0,l=0,r=0;\n            HashSet<Integer> hs = new HashSet<Integer>();\n            for(i=0; i<n; ++i) {\n                if(!hs.contains(arr[i])){\n                    hs.add(arr[i]);\n                    dist++;\n                }\n                if(dist==k) break;\n                r++;\n            }\n            int freq[] = new int[100010];\n            if(hs.size()<k) System.out.println(\"-1 -1\");\n            else {\n                while(l<arr.length-1 && l<r && arr[l]==arr[l+1])\n                    ++l;\n                while(r>=1 && r>l && arr[r]==arr[r-1])\n                    --r;\n                for(i=l;i<=r;++i)\n                    freq[arr[i]]++;\n                while(freq[arr[l]]>1){\n                    freq[arr[l]]--;\n                    l++;\n                }\n                while(freq[arr[r]]>1){\n                    freq[arr[r]]--;\n                    r--;\n                }\n                System.out.println((l+1)+\" \" +(r+1));\n            }\n        } catch (Exception e) {\n\n        }\n    }\n    public static void main(String[] args) {\n        new Array().run();\n    }\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B implements Runnable {\n\n\tvoid Solution() throws IOException {\n\t\tint n = nextInt(), k = nextInt();\n\t\tint[] mas = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmas[i] = nextInt();\n\t\tint l = 0, r = 0;\n\t\tHashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n\t\tmap.put(mas[l], 1);\n\t\tint cur = 1;\n\t\twhile (true) {\n\t\t\tif (cur == k) {\n\t\t\t\tprint(l + 1, r + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tr++;\n\t\t\tif (r >= n)\n\t\t\t\tbreak;\n\t\t\tint kol = map.containsKey(mas[r]) ? map.remove(mas[r]) : 0;\n\t\t\tif (kol == 0) {\n\t\t\t\tcur++;\n\t\t\t\tmap.put(mas[r], 1);\n\t\t\t} else\n\t\t\t\tmap.put(mas[r], kol + 1);\n\t\t\twhile (true) {\n\t\t\t\tkol = map.remove(mas[l]);\n\t\t\t\tif (kol == 1) {\n\t\t\t\t\tmap.put(mas[l], 1);\n\t\t\t\t\tbreak;\n\t\t\t\t} else\n\t\t\t\t\tmap.put(mas[l++], kol - 1);\n\t\t\t}\n\t\t}\n\t\tprint(-1, -1);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tSolution();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\n\tvoid print(Object... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tout.print(\" \");\n\t\t\tout.print(obj[i]);\n\t\t}\n\t}\n\n\tvoid println(Object... obj) {\n\t\tprint(obj);\n\t\tout.println();\n\t}\n\n\tvoid halt() {\n\t\tout.close();\n\t\tSystem.exit(0);\n\t}\n\n\tString nextLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n\n\tString next() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class B {\n\tstatic int i(String s) { return Integer.parseInt(s); }\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] arr = in.readLine().split(\" \");\n\t\tint n = i(arr[0]);\n\t\tint k = i(arr[1]);\n\t\tint[] A = new int[n];\n\t\tarr = in.readLine().split(\" \");\n\t\tfor(int i=0; i<n; i++)\n\t\t\tA[i] = i(arr[i]);\n\t\t\n\t\tint st = 0;\n\t\tint cnt = 0;\n\t\tint[] cnts = new int[100*100*10+1];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tcnts[A[i]]++;\n\t\t\tif(cnts[A[i]] == 1) cnt++;\n\t\t\telse while(cnts[A[st]] > 1) {\n\t\t\t\tcnts[A[st]]--;\n\t\t\t\tst++;\n\t\t\t}\n\t\t\tif(cnt == k) {\n\t\t\t\tSystem.out.println((st+1)+\" \"+(i+1));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(-1+\" \"+-1);\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class B {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int distinct = sc.nextInt();\n        HashMap<Integer, Integer> set = new HashMap<Integer, Integer>();\n        int[] ar = new int[n];\n        for (int i = 0; i < n; i++) {\n            ar[i] = sc.nextInt();\n            if (set.containsKey(ar[i])) {\n                set.put(ar[i], set.get(ar[i])+1);\n            } else {\n                set.put(ar[i], 1);\n            }\n            if (set.size() == distinct) {\n                int st = 0;\n                for (int j = 0; j < i; j++) {\n                    st=j;\n                    if (set.get(ar[j]) > 1) {\n                        set.put(ar[j], set.get(ar[j]) - 1);\n                    } else {\n                        break;\n                    }\n                }\n                System.out.println((st + 1) + \" \" + (i + 1));\n                return;\n            }\n        }\n        System.out.println(\"-1 -1\");\n    }\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class B {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner scr = new Scanner(System.in);\n\t\tint n = scr.nextInt();\n\t\tint k = scr.nextInt();\n\t\t\n\t\tint[] a = new int[n+1];\t\t\n\t\tint[] d = new int[100001];\n\t\t\n\t\tint tk = 0;\n\t\tint l = 1;\n\t\tint r = -1;\n\t\tboolean find = false;\n\t\tfor (int i = 1; i <= n; i++){\n\t\t\ta[i] = scr.nextInt();\n\t\t\tif (d[a[i]] == 0){\n\t\t\t\td[a[i]] = 1;\n\t\t\t\ttk++;\n\t\t\t\tif ((!find) && (tk == k)){\n\t\t\t\t\tfind = true;\n\t\t\t\t\tr = i;\n\t\t\t\t} // if \n\t\t\t} // if\n\t\t} // for\n\t\t\n\t\t\n\t\tif (r > 0) {\n\t\t\tint[] cd = new int[100001];\n\t\t\ttk = 0;\n\t\t\tfind = false;\n\t\t\tfor (int j = r; j >= l; j--){\n\t\t\t\tif(cd[a[j]] == 0){\n\t\t\t\t\tcd[a[j]] = 1;\n\t\t\t\t\ttk++;\n\t\t\t\t\tif ((!find) && (tk == k)){\n\t\t\t\t\t\tfind = true;\n\t\t\t\t\t\tl = j;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} // if\n\t\t\t\t} // if\n\t\t\t} // for\n\t\t\tSystem.out.println(l + \" \" + r);\n\t\t} // if\n\t\telse {\n\t\t\tSystem.out.println(\"-1 -1\");\n\t\t}\t\t\t\n\n\t}\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class B {\n\tpublic void solve() throws IOException {\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[] num = new int[n];\n\t\tSet<Integer> set = new HashSet<Integer>();\n\t\tint s = -1;\n\t\tint l = -1;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tset.add(a[i]);\n\t\t\tnum[i] = set.size();\n\t\t\tif( num[i] == k ){\n\t\t\t\tl = i+1;\n\t\t\t\tset = new HashSet<Integer>();\n\t\t\t\tfor(int j = i; j >= 0; j--){\n\t\t\t\t\tset.add(a[j]);\n\t\t\t\t\tif( set.size() == k ){\n\t\t\t\t\t\ts = j+1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriter.println(s + \" \" + l);\n \t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew B().run();\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tpublic void run() throws IOException {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\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 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}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class PrB {\n\n\tpublic static long time;\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\ttime = System.currentTimeMillis();\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tn = Integer.parseInt(st.nextToken());\n\t\tk = Integer.parseInt(st.nextToken());\n\t\ta = new int[n];\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor(int i = 0; i < n; i++) \n\t\t\ta[i] = Integer.parseInt(st.nextToken());\n\t\tint end = end();\n\t\tif(end < 0) System.out.println(\"-1 -1\");\n\t\telse System.out.println((start(end) + 1) + \" \" + (end + 1));\n\t\tbr.close();\n\t\tSystem.exit(0);\n\t}\n\t\n\tstatic int n, k;\n\tstatic int[] a;\n\n\tpublic static int end() throws Exception {\n\t\tboolean[] reached = new boolean[100002];\n\t\tint rem = k;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(!reached[a[i]]) {\n\t\t\t\trem--;\n\t\t\t\tif(rem == 0) return i;\n\t\t\t}\n\t\t\treached[a[i]] = true;\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic static int start(int end) throws Exception {\n\t\tboolean[] reached = new boolean[100002];\n\t\tint rem = k;\n\t\tfor(int i = end; i >= 0; i--) {\n\t\t\tif(!reached[a[i]]) {\n\t\t\t\trem--;\n\t\t\t\tif(rem == 0) return i;\n\t\t\t}\n\t\t\treached[a[i]] = true;\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic static void checkTime() {\n\t\tSystem.out.println(System.currentTimeMillis() - time);\n\t\ttime = System.currentTimeMillis();\n\t}\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n    static BufferedReader in;\n    static StringTokenizer st;\n\n    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    static int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    public static void main(String[] args) throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        int n = nextInt();\n        int k = nextInt();\n        int[] a = new int[n + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = nextInt();\n        }\n        Set<Integer> set_1 = new HashSet<Integer>();\n        for (int i = 1; i <= n; i++) {\n            set_1.add(a[i]);\n            if (set_1.size() == k) {\n                Set<Integer> set_2 = new HashSet<Integer>();\n                for (int j = i; j >= 1; j--) {\n                    set_2.add(a[j]);\n                    if (set_2.size() == k) {\n                        out.print(j + \" \" + i);\n                        out.close();\n                        return;\n                    }\n                }\n            }\n        }\n        out.print(\"-1 -1\");\n        out.close();\n\n    }\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class B {\n    public static void main(String[] args) throws Exception {\n        new B().solve();\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        \n        String[] sp = in.readLine().split(\" \");\n        \n        int n = Integer.parseInt(sp[0]);\n        int k = Integer.parseInt(sp[1]);\n        int[] a = new int[n];\n        sp = in.readLine().split(\" \");\n        for (int i = 0; i < n; i++) {\n            a[i] = Integer.parseInt(sp[i]);\n        }\n        \n        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n        int r = 0;\n        map.put(a[r], 1);\n        while (map.size() < k) {\n            r++;\n            if (r == n) {\n                // ng\n                System.out.println(\"-1 -1\");\n                return;\n            }\n            if (map.containsKey(a[r])) {\n                map.put(a[r], map.get(a[r]) + 1);\n            } else {\n                map.put(a[r], 1);\n            }\n        }\n        int l = 0;\n        while (map.get(a[l]) > 1) {\n            map.put(a[l], map.get(a[l]) - 1);\n            l++;\n        }\n        System.out.println((l + 1) + \" \" + (r + 1));\n    }\n}\n\n\n\n\n//\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n    static StringTokenizer st;\n    static PrintWriter out = new PrintWriter(System.out,true);\n    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n    public static int nextInt() throws Exception {\n        if(st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());\n        return Integer.parseInt(st.nextToken());\n    }\n\n    public static long nextLong() throws Exception {\n        if(st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());\n        return Long.parseLong(st.nextToken());\n    }\n\n    public static void main(String[] args) throws Exception {\n        HashSet<Integer> set = new HashSet<>();\n        int n = nextInt();\n        int k = nextInt();\n        int[] m = new int[n];\n        int[] d = new int[n];\n        for(int i = 0;i < n;i++) m[i] = nextInt();\n        int l = -1;\n        int r = -1;\n        for(int i = 0;i < n;i++) {\n            set.add(m[i]);\n            d[i] = set.size();\n            if(d[i] == k) {\n                r = i;\n                break;\n            }\n        }\n        if(r == -1) {\n            out.println(\"-1 -1\");\n            return;\n        }\n\n        for(int i = r;i >= 0;i--) {\n            set.remove(m[i]);\n            if(set.size() == 0) {\n                l = i;\n                break;\n            }\n        }\n        out.println((l+1)+\" \"+(r+1));\n    }\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n    static BufferedReader in;\n    static StringTokenizer st;\n\n    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    static int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    public static void main(String[] args) throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        int n = nextInt();\n        int k = nextInt();\n        int[] a = new int[n + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = nextInt();\n        }\n        Set<Integer> set_1 = new HashSet<Integer>();\n        for (int i = 1; i <= n; i++) {\n            set_1.add(a[i]);\n            if (set_1.size() == k) {\n                Set<Integer> set_2 = new HashSet<Integer>();\n                for (int j = i; j >= 1; j--) {\n                    set_2.add(a[j]);\n                    if (set_2.size() == k) {\n                        out.print(j + \" \" + i);\n                        out.close();\n                        return;\n                    }\n                }\n            }\n        }\n        out.print(\"-1 -1\");\n        out.close();\n\n    }\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "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 {\n\n    private void solve() throws IOException {\n        int n = nextInt();\n        int k = nextInt();\n        \n        int[] a = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = nextInt();\n        \n        int[] f = new int[100000 + 2];\n        \n        int min = Integer.MAX_VALUE;\n        int cur = 0;\n        int start = 0;\n        int from = -1, to = -1;\n        \n        for (int i = 0; i < n; i++) {\n            f[a[i]]++;\n            if (f[a[i]] == 1) cur++;\n            if (cur == k) {\n                while (f[a[start]] > 1) {\n                    f[a[start]]--;\n                    start++;\n                }\n                if (i - start + 1 < min) {\n                    min = i - start + 1;\n                    from = start;\n                    to = i;\n                }\n            }\n        }\n        pl(from == -1 ? \"-1 -1\" : ((1 + from) + \" \" + (1 + to)));\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 InputStreamReader(System.in));\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            solve();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(nextToken());\n    }\n\n    String nextToken() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    void p(Object... objects) {\n        for (int i = 0; i < objects.length; i++) {\n            if (i != 0)\n                writer.print(' ');\n            writer.flush();\n            writer.print(objects[i]);\n            writer.flush();\n        }\n    }\n\n    void pl(Object... objects) {\n        p(objects);\n        writer.flush();\n        writer.println();\n        writer.flush();\n    }\n\n    int cc;\n\n    void pf() {\n        writer.printf(\"Case #%d: \", ++cc);\n        writer.flush();\n    }\n\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class B138 {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int a[] = new int[100004];\n        int b[] = new int[100004];\n        int n, m, ans = 0, dau, cuoi=-1;\n        n = sc.nextInt();\n        m = sc.nextInt();\n        for(int i=0;i<100004;i++) a[i] = 0;\n        for(int i=0;i<n;i++){\n            b[i] = sc.nextInt();\n            if(a[b[i]]==0){\n                a[b[i]] = 1;\n                ans++;\n                if(ans==m){\n                    cuoi = i+1;\n                    break;\n                }\n            }\n        }\n        for(int i=cuoi-1;i>=00;i--){\n            if(a[b[i]]==1){\n                a[b[i]] = 0;\n                ans--;\n                if(ans==0){\n                    System.out.println((i+1)+\" \"+cuoi);\n                    System.exit(0);\n                }\n            }\n        }\n        System.out.println(\"-1 -1\");\n    }\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "        import java.io.*;\n        import java.math.BigInteger;\n        import java.util.*;\n        \n        public class Main {\n         \n            static final double eps = 1e-8;\n            \n            public static void main(String[] args) throws IOException {\n                try {\n                    \n                       int n = nextInt();\n                       int k = nextInt();\n                       int[] a = new int[n];\n                       int[] d = new int[n];\n                       int[] dr = new int[n];\n                       boolean used[] = new boolean[100001];\n                       a[0] = nextInt();\n                       used[ a[0] ] = true;\n                       d[0] = 1;\n                       for(int i = 1; i < n; i++)\n                       {\n                           a[i] = nextInt();\n                           if(!used[ a[i] ])\n                           {\n                               used[ a[i] ] = true;\n                               d[i] = d[i - 1] + 1;\n                           }\n                           else\n                           {\n                               d[i] = d[i - 1];\n                           }\n                       }\n                       Arrays.fill(used, false);\n\n                       \n                       int r = Arrays.binarySearch(d, k);\n                       \n                       if(r < 0)\n                       {\n                           pw.println(\"-1 -1\");\n                           return;\n                       }\n        \n                       while( r > 0 && d[r] == d[r - 1] )\n                           r--;\n                       \n                       used[ a[r] ] = true;\n                       dr[r] = 1;\n                       for(int i = r - 1; i >= 0; i--)\n                       {\n                           if(!used[ a[i] ])\n                           {\n                               used[ a[i] ] = true;\n                               dr[i] = dr[i + 1] + 1;\n                           }\n                           else\n                           {\n                               dr[i] = dr[i + 1];\n                           }\n                       }\n        \n                       \n                       \n                       int l = 0;\n        \n                       while(l < n - 1 && dr[l] == dr[l + 1] && r - l >= k)\n                           l++;\n                       \n                       \n                       pw.println(l + 1 + \" \" + (r + 1));\n                }\n                finally {\n                    pw.close();\n                }\n            }\n        \n        \n            static Scanner sc = new Scanner(System.in);\n            static PrintWriter pw = new PrintWriter(System.out);\n            static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n            static StringTokenizer st ;\n            static int nextInt() throws IOException {\n                in.nextToken();\n                return (int) in.nval;\n            }\n            static long nextLong() throws IOException {\n                in.nextToken();\n                return (long) in.nval;\n            }\n            static double nextDouble() throws IOException {\n                in.nextToken();\n                return in.nval;\n            }\n            static String next() throws IOException {\n                in.nextToken();\n                return in.sval;\n            }\n            static void outArray(int[] O) {\n                for(int i = 0; i < O.length - 1; i++)\n                    pw.print(O[i] + \" \");\n                pw.println(O[O.length - 1]);\n            }\n        }", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.FileReader;\nimport java.io.BufferedWriter;\nimport java.util.Set;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.File;\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 jarek\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        int n = in.nextInt(), k = in.nextInt();\n        int[] a = IOUtils.readIntArray(in, n);\n        Set<Integer> cnt = new HashSet<Integer>();\n        int i = 0;\n        while (i < n && cnt.size() < k) {\n            cnt.add(a[i]);\n            if (cnt.size() < k)\n                ++i;\n        }\n        if (cnt.size() < k)\n            out.print(\"-1 -1\");\n        else {\n            int r = i;\n            cnt = new HashSet<Integer>();\n            while (i >= 0 && cnt.size() < k) {\n                cnt.add(a[i]);\n                if (cnt.size() < k) --i;\n            }\n            out.print(i + 1, r + 1);\n        }\n    }\n}\n\nclass InputReader {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public InputReader(File f) {\n        try {\n            br = new BufferedReader(new FileReader(f));\n        } catch (FileNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n\n    public InputReader(InputStream f) {\n        br = new BufferedReader(new InputStreamReader(f));\n    }\n\n    public String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\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 close() {\n        writer.close();\n    }\n}\n\nclass 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.nextInt();\n        return array;\n    }\n\n    }\n\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "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.util.HashSet;\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\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\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n=in.nextInt(),k=in.nextInt();\n        int a[]=new int[n];\n        int i;\n        for(i=0;i<n;i++)\n            a[i]=in.nextInt();\n        HashSet<Integer> hs=new HashSet<Integer>();\n        boolean status=false;\n        int index=-1;\n        for(i=0;i<n;i++)\n        {\n            \n            hs.add(a[i]);\n            if(hs.size()==k)\n            {\n                index=i;\n                status=true;\n                break;\n            }\n        }\n        if(!status)\n        {\n            out.println(-1+\" \"+ -1);\n            return;\n        }\n        HashSet<Integer> hash=new HashSet<Integer>();\n        for(i=index;i>=0;i--)\n        {\n\n            hash.add(a[i]);\n            if(hash.size()==k)\n            {\n                break;\n            }\n        }\n        out.println((i+1)+\" \"+(index+1));\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", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\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.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws NumberFormatException,\n            IOException {\n        Solver solver = new Solver();\n        solver.open();\n        long time = System.currentTimeMillis();\n        solver.solve();\n        if (!\"true\".equals(System.getProperty(\"ONLINE_JUDGE\"))) {\n            System.out.println(\"Spent time: \"\n                    + (System.currentTimeMillis() - time));\n        }\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    public void solve() throws NumberFormatException, IOException {\n        int n = nextInt();\n        int k = nextInt();\n        \n        int[] ar = new int[n];\n        int[] ex = new int[100005];\n        int dif = 0;\n        \n        for(int i=0;i<n;i++){\n            int tmp = nextInt();\n            ar[i] = tmp;\n            if (ex[tmp]++==0){\n                dif++;          \n            }           \n        }\n        \n        if (dif<k){\n            out.println(\"-1 -1\");\n            return;\n        }\n        \n        Arrays.fill(ex, 0);\n        dif = 0;\n        int right = 0;\n        while(dif<k){\n            int tmp = ar[right];\n            if(ex[tmp]++==0){       \n                dif++;\n            }\n            right++;\n        }\n        \n        int left = 0;\n        while (ex[ar[left]]-- > 1) left++;\n        \n        out.println((left+1)+\" \"+right);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n    static final long MOD = 1000000007L;\n    \n    public static void main(String[] args) throws Exception {\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        int k = scan.nextInt();\n        int res = -1;\n        int[] arr = new int[n];\n        for (int i = 0; i < arr.length; i++) {\n            arr[i] = scan.nextInt();\n        }\n        BitSet bits = new BitSet();\n        int count = 0;\n        int end = -1;\n        for (int i = 0; i < arr.length; i++) {\n            if (!bits.get(arr[i])) {\n                bits.set(arr[i]);\n                count++;\n                if (count == k) {\n                    end = i;\n                    break;\n                }\n            }\n        }\n        if (end == -1) {\n            System.out.print(\"-1 -1\");\n            return;\n        }\n        bits = new BitSet();\n        count = 0;\n        int start = end;\n        while (start >= 0) {\n            if (!bits.get(arr[start])) {\n                bits.set(arr[start]);\n                count++;\n                if (count == k) {\n                    break;\n                }\n            }\n            start--;\n        }\n        System.out.println((start + 1) + \" \" + (end + 1));\n    }\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tboolean eof;\n\n\tpublic String nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn \"-1\";\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tint NOD(int a, int b) {\n\t\twhile (a * b > 0) {\n\t\t\tif (a > b) {\n\t\t\t\ta %= b;\n\t\t\t} else {\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tvoid solve() {\n\t\tint n = nextInt(), k= nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\ta[i] = nextInt() - 1;\n\t\t}\n\t\tint[] b = new int[100000];\n\t\tint p = 0;\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\t++b[a[i]];\n\t\t\tif (b[a[i]] == 1){\n\t\t\t\t++p;\n\t\t\t}\n\t\t\tif (k == p){\n\t\t\t\tint j;\n\t\t\t\tfor (j = 0; j <= i; ++j){\n\t\t\t\t\tif (b[a[j]] > 1){\n\t\t\t\t\t\t--b[a[j]];\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}\n\t\t\t\tout.print((j + 1) + \" \" + (i + 1));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.print(\"-1 -1\");\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\n\t\t\t// br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\tsolve();\n\t\t\tbr.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\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\nimport java.io.BufferedWriter;\nimport java.util.Locale;\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.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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        int[] a = in.nextIntArray(n);\n        if (k == 1) {\n            out.println(\"1 1\");\n            return;\n        }\n        int left = -1, right = -1;\n        Counter<Integer> counter = new Counter<Integer>();\n        while (true) {\n            right++;\n            if (right == n) {\n                out.println(\"-1 -1\");\n                return;\n            }\n            counter.add(a[right]);\n            if (counter.size() >= k)\n                break;\n        }\n        while (true) {\n            left++;\n            if (counter.get(a[left]) == 1)\n                break;\n            counter.add(a[left], -1);\n        }\n        out.printLine(left + 1, right + 1);\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 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 & 15;\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    public int[] nextIntArray(int count) {\n        int[] result = new int[count];\n        for (int i = 0; i < count; i++) {\n            result[i] = nextInt();\n        }\n        return result;\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 print(Object obj) {\n        writer.print(obj);\n    }\n\n    public void println() {\n        writer.println();\n    }\n\n    public void println(String x) {\n        writer.println(x);\n    }\n\n    public void print(char c) {\n        writer.print(c);\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    public void printItems(Object... items) {\n        for (int i = 0; i < items.length; i++) {\n            if (i != 0) {\n                print(' ');\n            }\n            print(items[i]);\n        }\n    }\n\n    public void printLine(Object... items) {\n        printItems(items);\n        println();\n    }\n\n}\n\nclass Counter<T> extends HashMap<T, Long> {\n    public void add(T obj, long count) {\n        put(obj, get(obj) + count);\n    }\n\n    public void add(T obj) {\n        put(obj, get(obj) + 1L);\n    }\n\n    public Long get(Object key) {\n        return containsKey(key) ? super.get(key) : 0L;\n    }\n}\n\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import 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.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n\n\npublic class Main {\n\tstatic class MyReader{\n\t    private BufferedReader reader = null;\n\t    private StringTokenizer tokenizer = null;\n\t    MyReader(Reader r) throws IOException{\n\t        reader = new BufferedReader(r);\n\t    }\n\t    public int nextInt() throws IOException {\n\t        return Integer.parseInt(nextToken());\n\t    }\n\t    public String nextToken() throws IOException {\n\t        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t            tokenizer = new StringTokenizer(reader.readLine());\n\t        }\n\t        return tokenizer.nextToken();\n\t    }\n\t}\n\tpublic static void main(String []args) throws IOException{\n\t\tPrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));\n\t\tMyReader reader = new MyReader(new InputStreamReader(System.in));\n\t\tint n = reader.nextInt();\n\t\tint k = reader.nextInt();\n\t\tint []a = new int[n];\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\ta[i] = reader.nextInt();\n\t\tint j = 0;\n\t\tHashMap<Integer,Integer> map = new HashMap<>();\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tif (map.containsKey(a[i]))\n\t\t\t\tmap.put(a[i], map.get(a[i])+1);\n\t\t\telse{\n\t\t\t\tmap.put(a[i], 1);\n\t\t\t\tif (map.size()==k) { j = i+1; break; }\n\t\t\t}\n\t\t}\n\t\tif (map.size()<k){\n\t\t\tSystem.out.println(\"-1 -1\");\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tif (map.get(a[i])==1){\n\t\t\t\tSystem.out.println(i+1 + \" \" + j);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tmap.put(a[i], map.get(a[i])-1);\n\t\t}\n\t}\n\t\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n\npublic class B {\n\t\n\tstatic class Scanner\n\t{\n\t\tBufferedReader rd;\n\t\tStringTokenizer tk;\n\t\tpublic Scanner() throws IOException\n\t\t{\n\t\t\trd=new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttk=new StringTokenizer(rd.readLine());\n\t\t}\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\twhile(!tk.hasMoreTokens())\n\t\t\t\ttk=new StringTokenizer(rd.readLine());\n\t\t\treturn tk.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws NumberFormatException, IOException\n\t\t{\n\t\t\treturn Integer.valueOf(this.next());\n\t\t}\n\t}\n\t\n\tstatic int N,K;\n\tstatic int[] array=new int[100010];\n\t\n\tpublic static void main(String args[]) throws IOException{\n\t\tScanner sc=new Scanner();\n\t\tN=sc.nextInt();\n\t\tK=sc.nextInt();\n\t\tfor(int i=0;i<N;i++)\n\t\t\tarray[i]=sc.nextInt();\n\t\tTreeMap<Integer,Integer> map=new TreeMap<Integer,Integer>();\n\t\tboolean flag=false;\n\t\tfor(int i=0;i<N;i++){\n\t\t\tif (!map.containsKey(array[i])){\n\t\t\t\tmap.put(array[i], i);\n\t\t\t\tif (map.size()==K){\n\t\t\t\t\tflag=true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t\tmap.put(array[i], i);\n\t\t}\n\t\tif (!flag)\n\t\t\tSystem.out.println(\"-1 -1\");\n\t\telse{\n\t\t\tSet<Integer> s=map.keySet();\n\t\t\tint l=Integer.MAX_VALUE;\n\t\t\tint r=Integer.MIN_VALUE;\n\t\t\tfor(int k: s){\n\t\t\t\tint tmp=map.get(k);\n\t\t\t\tl=Math.min(l, tmp);\n\t\t\t\tr=Math.max(r, tmp);\n\t\t\t}\n\t\t\tSystem.out.println((l+1)+\" \"+(r+1));\n\t\t}\n\t}\n\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CodeForces {\n    static boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    void runCase(int caseNum) throws IOException {\n        int n = nextInt();\n        int k = nextInt();\n        int[] nums = new int[n];\n        int distinct = 0;\n        int L = -1, R = -1;\n        int minLen = Integer.MAX_VALUE;\n        int maxNum = 0;\n\n        for (int i = 0; i < n; ++i) {\n            nums[i] = nextInt();\n            maxNum = Math.max(maxNum,  nums[i]);\n        }\n        int[] count = new int[maxNum + 1];\n        int j = 0;\n\n        for (int i = 0; i < n; ++i) {\n            ++count[nums[i]];\n            if (count[nums[i]] == 1) {\n                ++distinct;\n                if (distinct >= k) {\n                    for (; j <= i; ++j) {\n                        --count[nums[j]];\n                        if (count[nums[j]] <= 0) {\n                            --distinct;\n                            if (distinct < k) {\n                                if (i - j < minLen) {\n                                    minLen = i - j;\n                                    L = j + 1;\n                                    R = i + 1;\n                                }\n                                break;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        out.print(L + \" \" + R);\n    }\n\n\n    public static void main(String[] args) 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        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\n        out.flush();\n    }\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Created with IntelliJ IDEA.\n * User: Alexey\n * Date: 16.09.12\n * Time: 19:29\n * To change this template use File | Settings | File Templates.\n */\npublic class stub implements Runnable {\n    public static void main(String[] args) {\n        new stub().run();\n    }\n\n    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    PrintWriter out = new PrintWriter(System.out);\n    StringTokenizer st;\n\n    public String nextToken() 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(nextToken());\n    }\n\n    private void solve() throws IOException {\n        int[] cnt = new int[(int) 1e6];\n        int n = nextInt();\n        int k = nextInt();\n        int[] a = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n        }\n\n        int cur = 0;\n        int left = 0;\n        int i = left;\n        while (i < n && cur != k) {\n            if (cnt[a[i]] == 0) {\n                cur++;\n            }\n            cnt[a[i]]++;\n            i++;\n        }\n        i--;\n        if (cur != k) {\n            out.println(\"-1 -1\");\n            return;\n        }\n        int right = i;\n        while (cnt[a[left]] > 1) {\n            cnt[a[left]]--;\n            left++;\n        }\n        out.println((left + 1) + \" \" + (right + 1));\n    }\n\n    public void run() {\n        try {\n            solve();\n            out.close();\n            br.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\n\n\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\n\npublic class Main{\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tParser p = new Parser(System.in);\n\t\tPrintWriter pw= new PrintWriter(System.out);\n\n\t\tint n = p.nextInt();\n\t\tint k = p.nextInt();\n\n\t\tint[] a = p.nextIntArray(n);\n\t\tint [] pos = new int[100001];\n\t\tArrays.fill(pos,-1);\n\t\tint cnt = 0;\n\t\tfor(int i=0; i<n; ++i){\n\t\t\tint e = a[i];\n\t\t\tif( pos[e] == -1 ){\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\tpos[e] = i;\n\t\t\tif( cnt == k){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif( cnt < k){\n\t\t\tpw.println(\"-1 -1\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tint min = 1000000;\n\t\tint max = -1;\n\t\tfor(int i=0; i<100001; ++i){\n\t\t\tif(pos[i] != -1 && pos[i] < min ){\n\t\t\t\tmin = pos[i];\n\t\t\t}\n\t\t\tif( pos[i] > max){\n\t\t\t\tmax = pos[i];\n\t\t\t}\n\t\t}\n\t\t++min;\n\t\t++max;\n\n\t\tpw.println(min+\" \"+max);\n\t\tpw.close();\n\t}\n\t\n\t\n\n\n\n\n\n\tstatic class Parser{\n\t\t\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Parser(InputStream is){\n\t\t\tthis.br = new BufferedReader( new InputStreamReader(is));\n\t\t\t\n\t\t}\n\t\t\n\t\tpublic int nextInt(){\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\t\t\n\t\tpublic double nextDouble(){\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t\t\n\t\tpublic String nextString(){\n\t\t\treturn nextToken();\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int s){\n\t\t\tint[] a = new int[s];\n\t\t\tfor(int i=0; i<s; ++i){\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\tpublic int[][] nextIntTable(int r, int c){\n\t\t\tint[][] a = new int[r][c];\n\t\t\tfor(int i=0; i<r; ++i){\n\t\t\t\ta[i] = nextIntArray(c);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\n\t\tprivate String nextToken() {\n\t\t\tif( 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\t\t\n\t}\n}\n\n\n\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n\n    void run(){\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt(), k = sc.nextInt();\n        int[] a = new int[n+1];\n        for(int i=1;i<=n;i++)a[i]=sc.nextInt();\n        int[] c = new int[100001];\n        int num = 0;\n        int ri = -1, rj = -1;\n        int s = 1, t = 0;\n        while(t<n){\n            t++;\n            if(c[a[t]]==0){\n                num++;\n            }\n            c[a[t]]++;\n            for(;k<=num;s++){\n                if(ri==-1 || rj-ri+1>t-s+1){\n                    ri = s; rj = t;\n                }\n                c[a[s]]--;\n                if(c[a[s]]==0){\n                    num--;\n                }\n            }\n        }\n        System.out.println(ri+\" \"+rj);\n    }\n    \n    void debug(Object...o){\n        System.out.println(Arrays.deepToString(o));\n    }\n    \n    public static void main(String[] args) {\n        new B().run();\n    }\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "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 * @author Sunits789\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    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n=in.nextInt();\n        int k=in.nextInt();\n        int arr[]=new int[n];\n        in.getArray(arr);\n        int ansl=-1;\n        int ansr=n;\n        int occ[]=new int[100100];\n        boolean f[]=new boolean[n];\n        Arrays.fill(occ,0);\n        Arrays.fill(f,true);\n        int pk=0;\n        for (int l=0,r=0;r<n&&l<n;){\n            int num=arr[r];\n            if(f[r]){\n                f[r]=false;\n                occ[num]++;\n                if(occ[num]==1){\n                    pk++;\n                }\n            }\n            //System.out.println(l+\" \"+r+\" \"+pk+\" \"+k);\n            if(pk<k){\n                r++;\n            }\n            else if (pk==k){\n                if((r-l)<=(ansr-ansl)){\n                    ansl=l+1;\n                    ansr=r+1;\n                }\n                num=arr[l];\n                occ[num]--;\n                if(occ[num]==0){\n                    pk--;\n                }\n                l++;\n            }\n            else {\n                num=arr[l];\n                occ[num]--;\n                if(occ[num]==0){\n                    pk--;\n                }\n                l++;\n            }\n        }\n        if(ansl==-1){\n            ansr=-1;\n        }\n        out.println(ansl+\" \"+ansr);\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    public String next(){\n        while (tokenizer == null||!tokenizer.hasMoreTokens()){\n            try{\n                tokenizer = new StringTokenizer(reader.readLine());\n            }\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 void getArray(int arr[]){\n        for(int i=0;i<arr.length;i++){\n            arr[i]=nextInt();\n        }\n    }\n\n    }\n\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int a[] = new int[100004];\n        int b[] = new int[100004];\n        int n, m, ans = 0, dau, cuoi=-1;\n        n = sc.nextInt();\n        m = sc.nextInt();\n        for(int i=0;i<100004;i++) a[i] = 0;\n        for(int i=0;i<n;i++){\n            b[i] = sc.nextInt();\n            if(a[b[i]]==0){\n                a[b[i]] = 1;\n                ans++;\n                if(ans==m){\n                    cuoi = i+1;\n                    break;\n                }\n            }\n        }\n        for(int i=cuoi-1;i>=00;i--){\n            if(a[b[i]]==1){\n                a[b[i]] = 0;\n                ans--;\n                if(ans==0){\n                    System.out.println((i+1)+\" \"+cuoi);\n                    System.exit(0);\n                }\n            }\n        }\n        System.out.println(\"-1 -1\");\n    }\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n\tpublic void solve(int testNumber, StreamInputReader in, PrintWriter out) {\n        int N = in.readInt();\n        int K = in.readInt();\n        int[] A = new int[N];\n        for(int i = 0; i < N; i++)\n            A[i] = in.readInt();\n\n        int num = 0;\n        int left = 0;\n        int right = 0;\n        int[] seen = new int[100005];\n        while(right < N && num < K) {\n            if(seen[A[right]] == 0)\n                num++;\n            seen[A[right]]++;\n            right++;\n        }\n        right--;\n\n        if(num == K) {\n            while(seen[A[left]] > 1) {\n                seen[A[left]]--;\n                left++;\n            }\n\n            out.print((left + 1) + \" \" + (right + 1));\n            return;\n        }\n        out.print(\"-1 -1\");\n\t}\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    }\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 readInt() {\n        return Integer.parseInt(readString());\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    }\n\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class CF224B {\n    \n    public static void main(String[] args) throws Exception {\n        new CF224B().solve();\n    }\n\n    private void solve() throws Exception {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int k = sc.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = sc.nextInt();\n        }\n        final int MAX_A = 100000;\n        int[] freq = new int[MAX_A+1];\n        int numDistinct = 0;\n        int r = -1;\n        for (int i = 0; i < n; i++) {\n            int t = a[i];\n            freq[t]++;\n            if (freq[t] == 1) {\n                numDistinct++;\n            }\n            if (numDistinct == k) {\n                r = i;\n                break;\n            }\n        }\n        if (r == -1) {\n            System.out.println(\"-1 -1\");\n            return;\n        }\n        int l;\n        for (l = 0; l < r; l++) {\n            int t = a[l];\n            freq[t]--;\n            if (freq[t] == 0) {\n                break;\n            }\n        }\n        System.out.println((l+1) + \" \" + (r+1));\n    }\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class B {\n\n    static Scanner in;\n\n    static void put(TreeMap<Integer, Integer> m, int key) {\n        if (m.containsKey(key)) {\n            m.put(key, m.get(key) + 1);\n        } else {\n            m.put(key, 1);\n        }\n    }\n\n    static void remove(TreeMap<Integer, Integer> m, int key) {\n        if (!m.containsKey(key))\n            return;\n        m.put(key, m.get(key) - 1);\n        if (m.get(key) == 0) {\n            m.remove(key);\n        }\n    }\n\n    public static void main(String[] args) {\n        in = new Scanner(System.in);\n        int n = in.nextInt();\n        int k = in.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n        int i = 0;\n        while (i + 1 < n && a[i + 1] == a[0]) {\n            i++;\n        }\n        int left = i;\n        TreeMap<Integer, Integer> used = new TreeMap<Integer, Integer>();\n        for (; i < n; i++) {\n            put(used, a[i]);\n            if (used.size() == k) {\n                while (used.get(a[left]) > 1) {\n                    remove(used, a[left]);\n                    left++;\n                }\n                System.out.println(left + 1 + \" \" + (i + 1));\n                return;\n            }\n        }\n        System.out.println(\"-1 -1\");\n    }\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Code implements Runnable {\n\n    public static void main(String[] args) throws IOException {\n        new Thread(new Code()).start();\n    }\n\n    private void solve() throws IOException {\n        taskB();\n    }\n\n    private void taskB() throws IOException {\n        int n = nextInt(), k = nextInt();\n        int[] arr = new int[n];\n\n        for(int i = 0; i < n; ++i)  arr[i] = nextInt();\n\n        int i = 0;\n        while(i < n - 1 && arr[i] == arr[i + 1])    ++i;\n\n        if(k == 1)\n            writer.println(1 + \" \" + 1);\n        else if(k == 2 && i == n - 2)\n            writer.println(n - 1 + \" \" + n);\n        else {\n            if(i == n - 1)\n                writer.println(-1 + \" \" + -1);\n            else {\n                int l = i;\n                Map<Integer, Integer> set = new HashMap<Integer, Integer>(n);\n                while(i < n && set.size() < k) {\n                    if(set.containsKey(arr[i])) set.put(arr[i], set.get(arr[i]) + 1);\n                    else    set.put(arr[i], 1);\n                    i += 1;\n                }\n                if(set.size() < k)  writer.println(-1 + \" \" + -1);\n                else {\n                    while(l < i && i - l > k && set.get(arr[l]) > 1) {\n                        set.put(arr[l], set.get(arr[l]) - 1);\n                        l += 1;\n                    }\n                    writer.println((l + 1) + \" \" + i);\n                }\n            }\n        }\n    }\n\n    private class Pair<E extends Comparable, V extends Comparable> implements Comparable<Pair<E, V>> {\n        public Pair(E first, V second) {\n            this.first = first;\n            this.second = second;\n        }\n\n        @Override\n        public int compareTo(Pair<E, V> obj) {\n            if(first.equals(obj.first))  return second.compareTo(obj.second);\n            return first.compareTo(obj.first);\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            Pair other = (Pair)obj;\n            return first.equals(other.first) && second.equals(other.second);\n        }\n\n        public E first;\n        public V second;\n    }\n\n    @Override\n    public void run() {\n        try {\n            if(in.equals(\"\"))   reader = new BufferedReader(new InputStreamReader(System.in));\n            else    reader = new BufferedReader(new FileReader(in));\n\n            if(out.equals(\"\"))  writer = new PrintWriter(new OutputStreamWriter(System.out));\n            else    writer = new PrintWriter(new FileWriter(out));\n            solve();\n        } catch(IOException e) {\n            e.printStackTrace();\n        } finally {\n            try {\n                reader.close();\n                writer.close();\n            } catch(IOException e) {\n                e.printStackTrace();\n            }\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 double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    private float nextFloat() throws IOException {\n        return Float.parseFloat(nextToken());\n    }\n\n    private String nextToken() throws IOException {\n        while(st == null || !st.hasMoreTokens())    st = new StringTokenizer(reader.readLine());\n        return st.nextToken();\n    }\n\n    private String in = \"\", out = \"\";\n    private BufferedReader reader;\n    private PrintWriter writer;\n    private StringTokenizer st;\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.*;\n\n\npublic class B\n{\n\tBufferedReader in;\n\tPrintStream out;\n\tStringTokenizer tok;\n\tpublic B() throws NumberFormatException, IOException\n\t{\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t//in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\tout = System.out;\n\t\trun();\n\t}\n\tvoid run() throws NumberFormatException, IOException\n\t{\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint[] num = new int[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tnum[i] = nextInt();\n\t\tint[] cant = new int[100001];\n\t\tint cnt = 0;\n\t\tint r = 0;\n\t\tfor(; r < n; r++)\n\t\t{\n\t\t\tif(cant[num[r]]==0)cnt++;\n\t\t\tcant[num[r]]++;\n\t\t\tif(cnt==k) break;\n\t\t}\n\t\tif(cnt<k)\n\t\t{\n\t\t\tout.println(\"-1 -1\");\n\t\t\treturn;\n\t\t}\n\t\tint l = 0;\n\t\tfor(; l < r; l++)\n\t\t{\n\t\t\tcant[num[l]]--;\n\t\t\tif(cant[num[l]]==0)cnt--;\n\t\t\tif(cnt<k) break;\n\t\t}\n\t\tout.println((l+1)+\" \"+(r+1));\n\t}\n\tpublic static void main(String[] args) throws NumberFormatException, IOException \n\t{\n\t\tnew B();\n\t}\n\tString nextToken() throws IOException\n\t{\n\t\tif(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());\n\t\treturn tok.nextToken();\n\t}\n\tint nextInt() throws NumberFormatException, IOException\n\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws NumberFormatException, IOException\n\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws NumberFormatException, IOException\n\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C138B\n{\n\n    private 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     * @param args\n     */\n    public static void main(String[] args) throws IOException\n    {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        nextLine(br);\n        int n = nextInt();\n        int k = nextInt();\n        int[] a = new int[n];\n        nextLine(br);\n        for (int i = 0; i < n; i++) a[i] = nextInt();\n        \n        int bp = 0, fp = 0, count = 0;\n        boolean good = false;\n        int[] mark = new int[100001];\n        for (fp = 0; fp < n; fp++)\n        {\n            if (mark[a[fp]] == 0)\n            {\n                count++;\n            }\n            mark[a[fp]]++;\n            if (count == k)\n            {\n                good = true;\n                break;\n            }\n        }\n        if (!good)\n        {\n            System.out.println(\"-1 -1\");\n            return;\n        }\n        for (bp = 0; bp < fp; bp++)\n        {\n            if (mark[a[bp]] > 1)\n            {\n                mark[a[bp]]--;\n            }\n            else break;\n        }\n        System.out.println((bp+1) + \" \" + (fp+1));\n    }\n    \n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class B {\n    public static void main(String[] args) throws IOException {\n        InputReader in = new InputReader();\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        if (k > n) {\n            System.out.println(-1 + \" \" + -1);\n            return;\n        }\n        int[] v = new int[100010];\n        int cnt = 0;\n        for (int i = 0; i < k; i++) {\n            if (v[a[i]] == 0) {\n                cnt++;\n            }\n            v[a[i]]++;\n\n        }\n        int i = k;\n        while (cnt < k && i < n) {\n            if (v[a[i]] == 0) {\n                cnt++;\n            }\n            v[a[i]]++;\n            i++;\n        }\n        if (cnt != k) {\n            System.out.println(-1 + \" \" + -1);\n        } else {\n            int st = 0;\n            while (st < n && st < i && v[a[st]] > 1) {\n                v[a[st]]--;\n                st++;\n            }\n            System.out.println((st+1) + \" \" + (i));\n        }\n    }\n\n    static class InputReader {\n        BufferedReader in;\n        StringTokenizer st;\n\n        public InputReader() throws IOException {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            st = new StringTokenizer(in.readLine());\n        }\n\n        public String next() throws IOException {\n            while (!st.hasMoreElements())\n                st = new StringTokenizer(in.readLine());\n            return st.nextToken();\n        }\n\n        public int nextInt() throws NumberFormatException, IOException {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() throws NumberFormatException, IOException {\n            return Long.parseLong(next());\n        }\n    }\n\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class BB {\npublic static void main(String[] args) {\n    Scanner sc=new Scanner(System.in);\n    int n=sc.nextInt();\n    int k=sc.nextInt();\n    int a[]=new int[n+1];\n    boolean used[]=new boolean[100009];\n    for (int i = 1; i <=n; i++) {\n        a[i]=sc.nextInt();\n    }\n    int cnt=0;\n    int id=0;\n    for (int i = 1; i <=n; i++) {\n        if(!used[a[i]]){\n            cnt++;\n        used[a[i]]=true;\n        }\n        if(cnt==k){\n            id=i;\n            break;\n        }\n    }\n    boolean x[]=new boolean[100005];\n    int y=0;\n    int id1=0;\n    if(id==0){\n        System.out.println(-1+\" \"+-1);\n            return;\n    }\n    for (int i =id; i >=1; i--) {\n        if(!x[a[i]]){\n            y++;\n            x[a[i]]=true;\n        }\n        if(y==k){\n            id1=i;\n            break;\n        }\n    }\n    System.out.println(id1+\" \"+id);\n}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\n\n\npublic class B {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) throws Exception {\n//\t\tSystem.setIn(new FileInputStream(\"b.in\"));\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString[] parts = bf.readLine().trim().split(\"[ ]+\");\n\t\tint N = Integer.parseInt(parts[0]);\n\t\tint K = Integer.parseInt(parts[1]);\n\t\t\n\t\tint[] nums = new int[N];\n\t\tint idx = 0;\n\t\t\n\t\tString line = bf.readLine();\n\t\tfor(int i = 0; i < line.length(); i++) {\n\t\t\tchar c = line.charAt(i);\n\t\t\tif(c == ' ') idx++;\n\t\t\telse {\n\t\t\t\tint d = c - '0';\n\t\t\t\tnums[idx] = 10 * nums[idx] + d;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint from = -1, to = -1;\n\t\tHashMap<Integer, Integer> count = new HashMap<Integer, Integer>();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tInteger q = count.get(nums[i]);\n\t\t\t\n\t\t\tif(q == null) count.put(nums[i], 1);\n\t\t\telse count.put(nums[i], q + 1);\n\t\t\t\n\t\t\tif(count.size() == K) {\n\t\t\t\tto = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(count.size() < K) {\n\t\t\tSystem.out.println(\"-1 -1\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor(from = 0; from <= to; from++) {\n\t\t\tInteger q = count.get(nums[from]);\n\t\t\t\n\t\t\tif(q == 1) count.remove(nums[from]);\n\t\t\telse count.put(nums[from], q - 1);\n\t\t\t\n\t\t\tif(count.size() < K) break;\n\t\t}\n\t\t\n\t\tSystem.out.println((from + 1) + \" \" + (to + 1));\n\n\t}\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class BT {\n\n    static BufferedReader in = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer str;\n    static String SK;\n\n    static 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    static int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    public static void main(String[] args) throws IOException {\n        int n, k;\n        n = nextInt();\n        k = nextInt();\n        HashSet<Integer> hs = new HashSet<Integer>();\n        HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();\n\n        int[] ar = new int[n];\n        int ii = 0, jj = -1;\n        for (int i = 0; i < n; i++) {\n            ar[i] = nextInt();\n\n            Integer iii = hm.get(ar[i]);\n            if(iii!=null)\n            hm.put(ar[i], ++iii); else hm.put(ar[i], 1);\n            hs.add(ar[i]);\n            if (hs.size() == k) {\n                jj = i;\n                break;\n            }\n        }\n        if (jj == -1) {\n            System.out.println(-1 + \" \" + (-1));\n            System.exit(0);\n        }\n        for (int i = 0; i < ar.length; i++) {\n            Integer iii = hm.get(ar[i]);\n            if (iii != null && iii - 1 > 0) {\n                hm.put(ar[i], --iii);\n                ii++;\n            } else {\n                break;\n            }\n        }\n        System.out.println((ii+1) + \" \" + (jj+1));\n\n    }\n\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Iterator;\nimport java.util.StringTokenizer;\nimport java.util.Vector;\n\npublic class B {\n\tstatic Vector<Integer> primes;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader myScanner = new InputReader();\n\t\tint n = myScanner.nextInt(), k = myScanner.nextInt();\n\t\tmyScanner.hasNext();\n\t\tint all[] = new int[n];\n\t\tboolean numbers[] = new boolean[100100];\n\t\tint diff[] = new int[n];\n\t\tall[0] = myScanner.nextInt();\n\t\tdiff[0] = 1;\n\t\tnumbers[all[0]] = true;\n\t\tint r = -1;\n\t\tif (k == 1)\n\t\t\tr = 1;\n\t\tfor (int i = 1; i < all.length; i++) {\n\t\t\tall[i] = myScanner.nextInt();\n\t\t\tdiff[i] = diff[i - 1];\n\t\t\tif (!numbers[all[i]]) {\n\t\t\t\tif (r == -1 && diff[i] + 1 == k)\n\t\t\t\t\tr = i + 1;\n\t\t\t\tnumbers[all[i]] = true;\n\t\t\t\tdiff[i]++;\n\t\t\t}\n\t\t}\n\t\tif (r == -1)\n\t\t\tSystem.out.println(-1 + \" \" + -1);\n\t\telse {\n\t\t\tnumbers = new boolean[100010];\n\t\t\tint l = 0, cnt = 1;\n\t\t\tnumbers[all[r - 1]] = true;\n\t\t\tif (k == 1)\n\t\t\t\tSystem.out.println(1 + \" \" + 1);\n\t\t\telse {\n\t\t\t\tfor (int i = r - 2; i >= 0; i--) {\n\t\t\t\t\tif (!numbers[all[i]]) {\n\t\t\t\t\t\tnumbers[all[i]] = true;\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t\tif (cnt == k) {\n\t\t\t\t\t\tl = i + 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tSystem.out.println(l + \" \" + r);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tBufferedReader buff;\n\t\tStringTokenizer tok;\n\t\tString cur;\n\n\t\tpublic InputReader() throws IOException {\n\t\t\tbuff = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttok = new StringTokenizer(cur = buff.readLine());\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\tif (!tok.hasMoreElements()) {\n\t\t\t\tcur = buff.readLine();\n\t\t\t\tif (cur == null)\n\t\t\t\t\treturn false;\n\t\t\t\ttok = new StringTokenizer(cur);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (!tok.hasMoreElements())\n\t\t\t\ttok = new StringTokenizer(cur = buff.readLine());\n\n\t\t\treturn tok.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws NumberFormatException, IOException {\n\t\t\twhile (!tok.hasMoreElements())\n\t\t\t\ttok = new StringTokenizer(cur = buff.readLine());\n\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.DataInputStream;\nimport java.io.InputStream;\nimport java.util.Scanner;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class B {\n\n    \n    public static void main(String[] args) throws Exception {\n        Parserdoubt2333 s = new Parserdoubt2333(System.in);\n        \n        int n = s.nextInt();\n        int k = s.nextInt();\n        int a[] = new int[n];\n        for (int i = 0; i < a.length; i++) {\n            a[i] = s.nextInt();\n            \n        }\n        \n        TreeMap<Integer, Integer> tree = new TreeMap<Integer,Integer>();\n        \n        int left = 0;\n        int right = 0;\n        \n        for (right = 0; right < a.length; right++) {\n            if(tree.containsKey(a[right]))\n                tree.put(a[right], tree.get(a[right]) + 1);\n            else \n                tree.put(a[right],1);\n            if(tree.size() == k)\n                break;\n        }\n        \n        if(tree.size() < k){\n            System.out.println(\"-1 -1\");\n            return ;\n        }\n//      System.out.println(right);\n        for (left = 0; left < a.length; left++) {\n            int val = tree.get(a[left]);\n            val--;\n            if(val > 0)\n                tree.put(a[left],val);\n            if(val == 0)\n                break;\n            \n        }\n        left++;\n        right++;\n        System.out.println(left + \" \"+right);\n    }\n\n}\n\n\n\nclass Parserdoubt2333\n{\n   final private int BUFFER_SIZE = 1 << 18;\n \n   private DataInputStream din;\n   private byte[] buffer;\n   private int bufferPointer, bytesRead;\n \n   public Parserdoubt2333(InputStream in)\n   {\n      din = new DataInputStream(in);\n      buffer = new byte[BUFFER_SIZE];\n      bufferPointer = bytesRead = 0;\n   }\n   public String nextString() throws Exception\n   {\n       StringBuffer sb=new StringBuffer(\"\");\n       byte c = read();\n       while (c <= ' ') c = read();\n       do\n       {\n           sb.append((char)c);\n           c=read();\n       }while(c>' ');\n       return sb.toString();\n   }\n   public char nextChar() throws Exception\n   {\n       byte c=read();\n       while(c<=' ') c= read();\n       return (char)c;\n   }\n   public int nextInt() throws Exception\n   {\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      {\n          ret = ret * 10 + c - '0';\n         c = read();\n      } while (c > ' ');\n      if (neg) return -ret;\n      return ret;\n   }\n   public long nextLong() throws Exception\n   {\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      {\n          ret = ret * 10 + c - '0';\n         c = read();\n      } while (c > ' ');\n      if (neg) return -ret;\n      return ret;\n   }\n   private void fillBuffer() throws Exception\n   {\n      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n      if (bytesRead == -1) buffer[0] = -1;\n   }\n \n   private byte read() throws Exception\n   {\n      if (bufferPointer == bytesRead) fillBuffer();\n      return buffer[bufferPointer++];\n   }\n} ", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class TaskB {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        \n        int n = s.nextInt();\n        int k = s.nextInt();\n        int[] nums = new int[100000 + 10];\n        \n        int first = -1, last = -1;\n        Set<Integer> dif = new TreeSet<Integer>();\n        \n        s.nextLine();\n        for (int i = 0; i < n; i++) {\n            nums[i] = s.nextInt();\n            dif.add(nums[i]);\n            if (dif.size() == k) {\n                last = i;\n                break;\n            }\n        }\n\n        dif.clear();\n\n        for (int i = last; i >= 0; i--) {\n            dif.add(nums[i]);\n            if (dif.size() == k) {\n                first = i;\n                break;\n            }\n        }\n        \n        if (last == -1)\n            System.out.print(\"-1 -1\");\n        else\n            System.out.print(Integer.toString(first + 1) + \" \"  + Integer.toString(last + 1));\n    }\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n\t/**\n\t * @param args\n\t * @throws IOException \n\t */\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n//\t\tScanner scan = new Scanner(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\tst = new StringTokenizer(br.readLine());\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0 ; i  <n;i++)\n\t\t\ta[i] = Integer.parseInt(st.nextToken());\n\t\t\n\t\tint l = 0, r = 0;\n\t\tint[] t = new int[100001];\n\t\tint kk = 0;\n\t\tint min = 1 << 25 , ll =-1 , rr = -1;\n\t\twhile(r < n)\n\t\t{\n\t\t\tint x = a[r++];\n\t\t\tt[x]++;\n\t\t\tif(t[x] == 1)\n\t\t\t\tkk++;\n\t\t\twhile(r < n && kk < k)\n\t\t\t{\n\t\t\t\tx = a[r++];\n\t\t\t\tt[x]++;\n\t\t\t\tif(t[x] == 1)\n\t\t\t\t\tkk++;\n\t\t\t}\n\t\t\twhile(kk == k && l < r)\n\t\t\t{\n\t\t\t\tx = a[l];\n\t\t\t\tif(t[x] == 1)\n\t\t\t\t\tbreak;\n\t\t\t\tt[x]--;\n\t\t\t\tl++;\n\t\t\t}\n\t\t\tif(kk == k)\n\t\t\t{\n\t\t\t\tint m = r-l+1;\n\t\t\t\tif(m < min)\n\t\t\t\t{\n\t\t\t\t\tll = l+1;\n\t\t\t\t\trr = r;\n\t\t\t\t\tmin = m;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ll +\" \"+rr);\n\t}\n\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class b {\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int n = input.nextInt(), k = input.nextInt();\n    int[] data = new int[n];\n    for(int i = 0; i<n; i++)\n        data[i] = input.nextInt();\n    int[] freq = new int[100001];\n    int count = 0;\n    for(int i = 0; i<n; i++)\n    {\n        if(freq[data[i]] == 0)\n            count++;\n        freq[data[i]]++;\n    }\n    if(count<k)\n        System.out.println(\"-1 -1\");\n    \n    else\n    {\n        int start = 0;\n        for(int i = 0; i<n; i++)\n        {\n            //System.out.println(i + \" \" + count + \" \" + freq[data[i]]);\n            if(count > k)\n            {\n                freq[data[i]]--;\n                if(freq[data[i]] == 0)\n                    count--;\n            }\n            else\n            {\n                if(freq[data[i]] > 1)\n                {\n                    freq[data[i]]--;\n                }\n                else\n                {\n                    start = i;\n                    break;\n                }\n            }\n        }\n        int end = n-1;\n        for(int i = n-1; i>=0; i--)\n        {\n            if(freq[data[i]] == 1)\n            {\n                end = i;\n                break;\n            }\n            else\n                freq[data[i]]--;\n\n        }\n        start++;\n        end++;\n        if(start<= end)\n        System.out.println(start + \" \" + end);\n        else\n            System.out.println(-1 + \" \" + -1);\n    }\n}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\n\nimport 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.Map;\nimport java.util.Vector;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\n\n/**\n *\n * @author Tibor\n */\npublic class test{\n\n//   static java.io.InputStreamReader converter = new java.io.InputStreamReader(System.in);\n//    static java.io.BufferedReader in = new java.io.BufferedReader(converter);\n//\n//    public static String readLine() {\n//        String s = \"\";\n//        try {\n//\n//            s = in.readLine();\n//        } catch (Exception e) {\n//            System.out.println(\"Error! Exception: \" + e);\n//        }\n//        return s;\n//    }\n    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(\n            new InputStreamReader(System.in)));\n    static PrintWriter out = new PrintWriter(System.out);\n\n//    static {\n//        in.ordinaryChars('-', '-');\n//        in.ordinaryChars('+', '+');\n//        in.wordChars('-', '-');\n//        in.wordChars('+', '+');\n//    }\n    static int nextInt() {\n        try {\n            in.nextToken();\n        } catch (IOException ex) {\n            Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);\n        }\n        return (int) in.nval;\n    }\n\n    static String nextString() {\n        try {\n            in.nextToken();\n        } catch (IOException ex) {\n            Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);\n        }\n        return in.sval;\n    }\n\n    public static void main(String args[]) throws Exception {\n        int n = nextInt();\n        long k = nextInt();\n        long a[] = new long[n + 1];\n        Map<Long, Long> drb = new HashMap<Long, Long>();\n        int elso = 1;\n        long sk = 0;\n        long sm = 0;\n        long minjo = Long.MAX_VALUE;\n        long minjoh = Long.MAX_VALUE;\n        Vector<long[]> ret = new Vector<long[]>();\n        for (int i = 1; i <= n; i++) {\n            a[i] = nextInt();\n            if (/*a[i - 1] <= a[i]*/true) {\n                sm += a[i];\n                if (drb.containsKey(a[i])) {\n                    drb.put(a[i], drb.get(a[i]) + 1);\n                } else {\n                    drb.put(a[i], (long) 1);\n                    sk++;\n                }\n                while (sk > k || drb.get(a[elso]) > 1) {\n                    long s = drb.get(a[elso]);\n                    if (s == 1) {\n                        drb.remove(a[elso]);\n                        sk--;\n                    } else {\n                        drb.put(a[elso], s - 1);\n                    }\n                    sm -= a[elso];\n                    elso++;\n                }\n                if (sk == k) {\n                    if (minjo > sm) {\n                        minjo = sm;\n                        ret.clear();\n                        minjoh = i - elso;\n                    }\n                    if (minjo == sm) {\n                        if (minjoh > i - elso) {\n                            ret.clear();\n                            minjoh = i - elso;\n                        }\n                        ret.add(new long[]{elso, i});\n                    }\n                }\n            } else {\n                elso = i;\n                drb.clear();\n                drb.put(a[i], (long) 1);\n                sk = 1;\n                sm = a[i];\n                if (k == 1) {\n                    if (minjo > sm) {\n                        minjo = sm;\n                        ret.clear();\n                    }\n                    if (minjo == sm) {\n                        ret.add(new long[]{elso, i});\n                    }\n                }\n            }\n        }\n\n        for (long[] r : ret) {\n            System.out.print(r[0] + \" \");\n            System.out.print(r[1] + \" \");\n            break;\n        }\n        if (ret.size() == 0) {\n            System.out.print(-1 + \" \");\n            System.out.print(-1 + \" \");\n        }\n    }\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "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  test{\n\t\n\t// ArrayList<Integer> lis = new ArrayList<Integer>();\n\t// ArrayList<String> lis = new ArrayList<String>();\n\t//\n    //\tstatic long sum=0;\n\t// int a,b,c;\n\t// 1000000007 (10^9+7)\n\t//static int mod = 1000000007;\n    //static int dx[]={1,-1,0,0};\n\t//static int dy[]={0,0,1,-1};\n    //static long H,L;\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\tReader sc = new Reader(System.in);\n  // while( ){\n\t   int  n=sc.nextInt(),m=sc.nextInt(),a[]=new int[n];\n\t   int b[]=new int[100000+1], r=n+1;\n\tfor(int i=0;i<n;i++)a[i]=sc.nextInt(); \n\t\t// db(a);\n\t\tint s=0,t=-1, sum=0;\n\t\tint as=0,at=0;\n\tfor(;;){\n\t\twhile(t<n-1 && sum<m){\n\t\t\tt++;\n\t\t\tif( b[ a[t] ]<1 ){sum++; }\n\t\t\t b[a[t]]++;\n\t}\n\t\tdb(s,t,sum);\n\t\tif( sum<m )break;\n\t\tas=s;at=t;\n\t\tr=min(r,t-s+1);\n\t\tif( b[ a[s] ]==1 ){sum--; }\n\t//\tif(t==n-1)break;\n\t\t b[a[s]]--;\n\t\t s++;\n\t}\n\t\n\tif( n<r )System.out.println(\"-1 -1\");\n\telse System.out.println(as+1+\" \"+(at+1));\n}\n\nstatic void db(Object... os){\n    System.err.println(Arrays.deepToString(os));\n\n}\n\n}\n\n\n/*\nclass P implements Comparable<P>{\n//\timplements Comparable<P>\n    \n\tint x;\n\tboolean b;\n\tP(int x,boolean b){\n\t\tthis.x=x;\n\t\tthis.b=b;\n\t} \n\n\t   public int compareTo(P y){\n         \n\t\t  return  x-y.x;\n\t\t   \n\t\t   }\t\n\t\n}\n//*/\nclass Reader\n{\n\tprivate BufferedReader x;\n\tprivate StringTokenizer st;\n\t\n\tpublic Reader(InputStream in)\n\t{\n\t\tx = new BufferedReader(new InputStreamReader(in));\n\t\tst = null;\n\t}\n\tpublic String nextString() throws IOException\n\t{\n\t\twhile( st==null || !st.hasMoreTokens() )\n\t\t\tst = new StringTokenizer(x.readLine());\n\t\treturn st.nextToken();\n\t}\n\tpublic int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\tpublic long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\tpublic double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n}\n", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Array224B {\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 n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\tint[] array = new int[n];\n\t\tint[] visited = new int[100002];\n\t\tst = new StringTokenizer(f.readLine());\n\t\tfor(int i=0;i<n;i++){\n\t\t\tarray[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tint count = 0;\n\t\tint begin = array[0];\n\t\twhile(count<n && array[count] == begin){\n\t\t\tcount++;\n\t\t}\n\t\tcount--;\n\t\tint kcount = 1;\n\t\tvisited[array[count]]++;\n\t\tint bindex = count;\n\t\tboolean good=true;\n\t\tcount++;\n\t\twhile(kcount<k){\n\t\t\tif(count==n){\n\t\t\t\tSystem.out.println(\"-1 -1\");\n\t\t\t\tgood=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(visited[array[count]]==0){\n\t\t\t\tkcount++;\n\t\t\t}\n\t\t\tvisited[array[count]]++;\n\t\t\tcount++;\n\t\t}\n\t\tif(good&&k!=1){\n\t\tfor(int i=bindex;i<count;i++){\n\t\t\tif(visited[array[i]]==1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbindex++;\n\t\t\tvisited[array[i]]--;\n\t\t}\n\t\tfor(int i=count-1;i>bindex;i--){\n\t\t\tif(visited[array[i]]==1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcount--;\n\t\t\tvisited[array[i]]--;\n\t\t}\n\t\t}\n\t\tif(k==1){\n\t\t\tSystem.out.println(\"1 1\");\n\t\t}\n\t\telse if(good){\n\t\t\tSystem.out.println(bindex+1+\" \"+count);\n\t\t}\n\t}\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.HashMap;\nimport java.util.Locale;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Array implements Runnable {\n\n    void solve() throws IOException {\n        int n = readInt();\n        int k = readInt();\n        int a[] = new int[n];\n        int startIdx = 0;\n        int endIdx = -1;\n        Map<Integer,Integer> map = new HashMap<Integer,Integer>();\n        for(int i = 0; i < n; i ++) {\n            a[i] = readInt();\n            if(map.containsKey(a[i]))\n                map.put(a[i], map.get(a[i]) + 1);\n            else\n                map.put(a[i], 1);\n            if(map.size() == k && endIdx == -1) {\n                endIdx = i;\n                break;\n            }\n        }\n\n        if(endIdx != -1) {\n            while(startIdx < n && map.get(a[startIdx])>1) {\n                map.put(a[startIdx], map.get(a[startIdx]) - 1);\n                startIdx ++;\n            }\n            startIdx ++;\n            endIdx   ++;\n        } else\n            startIdx = -1;\n\n        out.println((startIdx)+\" \"+(endIdx));\n\n\n    }\n\n\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    public static void main(String[] args) {\n        new Array().run();\n    }\n\n    public void run() {\n        try {\n            long t1 = System.currentTimeMillis();\n            if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n                in = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(System.out);\n            } else {\n                in = new BufferedReader(new FileReader(\"/Users/shenchen/input.txt\"));\n                out = new PrintWriter(\"/Users/shenchen/output.txt\");\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\n}", "complexity": "linear", "problem": "224_B. Array", "from": "CODEFORCES"}
{"src": "\nimport 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.Scanner;\nimport java.util.StringTokenizer;\n\npublic class CF_1029E_Tree_with_Small_Distances {\n\tstatic ArrayList<Integer> adj[];\n\tstatic int dist[];\n\tstatic boolean visitParent[];\n\tstatic int ans=0;\n public static void main(String[] args) throws IOException {\n\tScanner sc = new Scanner(System.in);\n\tint n  =sc.nextInt();\n\tadj=new ArrayList[n+1];\n\tdist = new int[n+1];\n\tvisitParent = new boolean[n+1];\n\tfor(int i=0;i<=n;i++) adj[i]=new ArrayList<Integer>();\n\tint max=0;\n\t//first contribution\n\tfor(int i=1;i<n;i++){\n\t\tint u = sc.nextInt(),v=sc.nextInt();\n\t\tadj[u].add(v);\n\t\tadj[v].add(u);\n\t}\n\tdist[1]=0;\n\tdfs(1,1);\n System.out.println(ans);\n \n \n }\nprivate static void dfs(int i , int j) {\n\t// TODO Auto-generated method stub\n\tboolean f = false;\n\tfor(int k=0;k<adj[i].size();k++){\n\t\tint x = adj[i].get(k);\n\t\tif(x!=j){\n\t\t\tdist[x]=dist[i]+1;\n\t\t\tdfs(x,i);\n\t\t\tif(visitParent[x])\n\t\t\t\tf=true;\n\t\t}\n\t}\n\t//System.out.println(Arrays.toString(dist));\n\tif(dist[i]>2&&!visitParent[j]&&!f&&!visitParent[i]){\n\t\tvisitParent[j]=true;\n\t\tans++;\n\t\tfor(int v=0;v<adj[i].size();v++){\n\t\t\t\n\t\t}\n\t}\n\t\n}\nstatic class Scanner \n{\n    StringTokenizer st;\n    BufferedReader br;\n\n    public Scanner(InputStream s){  br = 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 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\n    public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n    public long nextLong() throws IOException {return Long.parseLong(next());}\n\n    public String nextLine() throws IOException {return br.readLine();}\n\n    public boolean ready() throws IOException {return br.ready(); }\n\n\n}\n\t\n}\n\n", "complexity": "linear", "problem": "1029_E. Tree with Small Distances", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class CF1197B {\n    public static void main(String[] args) {\n        FastReader input = new FastReader();\n        int n = input.nextInt();\n        int[] arr = new int[n];\n        int max = 0;\n        int maxIndex = 0;\n        for(int i = 0;i < n;i++){\n            arr[i] = input.nextInt();\n            if(arr[i] > max){\n                max = arr[i];\n                maxIndex = i;\n            }\n        }\n        int j = maxIndex - 1;\n        int k = maxIndex + 1;\n        while (j >= 0 && k < n){\n            if(arr[j] > arr[k]){\n                if(arr[j] < max){\n                    max = arr[j];\n                    j--;\n                }\n                else {\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n            else{\n                if(arr[k] < max){\n                    max = arr[k];\n                    k++;\n                }\n                else{\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if(j >= 0){\n            while (j >= 0){\n                if(arr[j] < max){\n                    max = arr[j];\n                    j--;\n                }\n                else{\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if(k < n){\n            while (k < n){\n                if(arr[k] < max){\n                    max = arr[k];\n                    k++;\n                }\n                else{\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if(j == -1 && k == n){\n            System.out.println(\"YES\");\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}", "complexity": "linear", "problem": "1197_B. Pillars", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n \npublic class pillar {\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[200005];\n\t\tfor (int i=1;i<=n;i++) \n\t\ta[i]=sc.nextInt();\n\t\tfor (int i=2;i<n;i++) \n\t\tif (a[i-1]>a[i]&&a[i]<a[i+1]) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(\"YES\");\n\t}\n}\n\n", "complexity": "linear", "problem": "1197_B. Pillars", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    public static void main(String[] args)throws IOException{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        int[] a = new int[n];\n        for(int i=0;i<n;i++) a[i] = Integer.parseInt(st.nextToken());\n        int ind = 0;\n        for(int i=0;i<n;i++){\n            if(a[i]==n){\n                ind = i;\n                break;\n            }\n        }\n        boolean ok = true;\n        for(int i=ind+1;i<n;i++) if(a[i]>a[i-1]) ok = false;\n        for(int i=ind-1;i>=0;i--) if(a[i]>a[i+1]) ok = false;\n        if(ok) System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n        \n    }\n}\n\n", "complexity": "linear", "problem": "1197_B. Pillars", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.io.ObjectInputStream.GetField;\nimport java.security.KeyStore.Entry;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\nimport javax.swing.JLabel;\n\npublic class codeforcesreturn {\n\tstatic class edge {\n\t\tint u;\n\t\tint v;\n\n\t\tpublic edge(int u, int v) {\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t}\n\n\t}\n\n\tstatic ArrayList<Integer>[] adjlist;\n\tstatic int[][] adjmatrix;\n\tstatic int[][] adjmatrix2;\n\tstatic boolean[] vis;\n\tstatic boolean[] intialvis;\n\tstatic boolean[] vis2;\n\tstatic int[] counter;\n\tstatic int V, E;\n\tstatic Stack<Integer> st;\n\tstatic ArrayList<Integer> arrylist;\n\tstatic boolean flag;\n\tstatic int[] dx = new int[] { 1, -1, 0, 0 };\n\tstatic int[] dy = new int[] { 0, 0, 1, -1 };\n\tstatic int[] Arr;\n\tstatic PrintWriter pw;\n\tstatic boolean ans = true;;\n\n\tpublic static long gcd(long u, long v) {\n\t\tif (u == 0)\n\t\t\treturn v;\n\t\treturn gcd(v % u, u);\n\t}\n\n\tpublic static void bib(int u) {\n\n\t\tvis[u] = true;\n\t\tfor (int v : adjlist[u]) {\n\t\t\tif (!vis[v]) {\n\t\t\t\tcounter[v] = 1 ^ counter[u];\n\t\t\t\tbib(v);\n\t\t\t} else if (counter[v] != (1 ^ counter[u]))\n\t\t\t\tans = false;\n\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\t// FileWriter f = new FileWriter(\"C:\\\\Users\\\\Hp\\\\Desktop\\\\out.txt\");\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint sum = n;\n\n\t\tfor (long i = 0; i < 1e5; i++) {\n\t\t\tif (i * (i + 1) / 2 - (n - i) == k) {\n\t\t\t\tSystem.out.println(n - i);\n\t\t\t\tbreak;\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 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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\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        int n = sc.nextInt(), k = sc.nextInt();\n        long rhs = 2l * (n + k);\n        for (int x = 1; ; x++) {\n            long lhs = 1l * x * x + 3l * x;\n            if (rhs == lhs) {\n                out.println(n - x);\n                break;\n            }\n        }\n        out.flush();\n        out.close();\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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\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\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 sc = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Task solver = new Task();\n        solver.solve(1, sc, out);\n        out.close();\n    }\n\n    static class Task {\n        public void solve(int testNumber, InputReader sc, PrintWriter out) {\n            double n=sc.nextInt();\n            double k=sc.nextInt();\n            \n            double ans=n-(-1.5+Math.sqrt(9.0/4+2*(n+k)));\n            out.printf(\"%.0f\\n\",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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class B {\n    static long n, k;\n\n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextLong();\n        k = in.nextLong();\n        long ans = n - TernarySearch(0, n);\n        pw.println(ans);\n        pw.close();\n    }\n\n    static long cal(long m) {\n        long x = (m * (m + 1)) / 2;\n        long y = x - (n - m);\n        return abs(k - y);\n    }\n\n    static long TernarySearch(long l, long r) {\n        long m1, m2;\n        while (r - l > 5) {\n            m1 = (2 * l + r) / 3;\n            m2 = (l + 2 * r) / 3;\n            if (cal(m1) > cal(m2)) l = m1;\n            else r = m2;\n        }\n        long min = cal(l), i = l;\n        for (; l <= r; l++) {\n            long t = cal(l);\n            if (t < min) {\n                min = t;\n                i = l;\n            }\n        }\n        return i;\n    }\n\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "//never leave a uncompleted question in this file, always remove the code after submitting it.\n\nimport java.io.*;\nimport java.util.*;\n\npublic class run{\n    public static void main(String args[]){\n        Scanner in = new Scanner(System.in);\n        long n = in.nextInt();\n        long k = in.nextInt();\n        long ans = (-3 + (long)Math.sqrt(9+8*(n+k)))/2;\n        System.out.println(n-ans);\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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 Vaibhav Pulastya\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        BSportMafia solver = new BSportMafia();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BSportMafia {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long n = in.nextInt();\n            long k = in.nextInt();\n            long d = 9 + 4 * (2 * n + 2 * k);\n            double smh = Math.sqrt(d);\n            double ans = (-3 + smh) / 2;\n            out.println(n - (int) 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 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    }\n}\n\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Jaynil\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        BSportMafia solver = new BSportMafia();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BSportMafia {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long n = in.nextLong();\n            long k = in.nextLong();\n            long b = 2 * n + 3;\n            long c = n * n - 2 * k + n;\n            long d = b * b - 4 * c;\n            long val = (b - (long) Math.sqrt(d)) / 2;\n\n            out.println(val);\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.StringTokenizer;\n\npublic class CF1195B {\n\n    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    private static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));\n    private static StringTokenizer st;\n\n    public static void main(String[] args) throws Exception {\n        st = new StringTokenizer(reader.readLine());\n        long n = Long.parseLong(st.nextToken());\n        long k = Long.parseLong(st.nextToken());\n        long put = (-3 + (long)Math.sqrt((long)9 + 8 * k + 8 * n)) / 2;\n        long eat = n - put;\n        writer.write(Long.toString(eat));\n        writer.newLine();\n        writer.flush();\n    }\n\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class cf5722{\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\tlong n=Long.parseLong(st.nextToken());\n\t\tlong k=Long.parseLong(st.nextToken());\n\t\t\n\t\tlong ans=((-3-(long)Math.sqrt(9+4*(1*2*(n+k))))/2);\n\t\tlong ans1=((-3+(long)Math.sqrt(9+4*(1*2*(n+k))))/2);\n\t\tif(ans>0)\n\t\t\tSystem.out.println(n-ans);\n\t\telse{\n\t\t\tSystem.out.println(n-ans1);\n\t\t}\n\n\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.Math; \n\npublic class Main{   \n\t\n\tpublic static void main(String[] args){ \n\t\tScanner ak=new Scanner(System.in);\n\t\tlong n,k,x;\n\t\tn=ak.nextLong();\n\t\tk=ak.nextLong();\n\t\tx=(long)((-3+Math.sqrt(9+8*(n+k)))/2);\n\t\tSystem.out.println(n-x);\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class candies {\n\tpublic void run() throws Exception {\n\t\tScanner file = new Scanner(System.in);\n\t\tint actions = file.nextInt();\n\t\tint left = file.nextInt();\n\t\tint start = 0;\n\t\tint c = 1;\n\t\twhile (true) {\n\t\t\tstart += c;\n\t\t\tif (c + (start - left) == actions) break;\n\t\t\tc++;\n\t\t}\n\t\tSystem.out.println(start - left);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew candies().run();\n\t}\n\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.net.Inet4Address;\nimport java.util.*;\nimport java.lang.*;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\npublic class templ implements Runnable{\n    static class pair implements Comparable\n    {\n        int f;\n        int s;\n        pair(int fi,int se)\n        {\n            f=fi;\n            s=se;\n        }\n        public int compareTo(Object o)//ascending order\n        {\n            pair pr=(pair)o;\n            if(s>pr.s)\n                return 1;\n            if(s==pr.s)\n            {\n                if(f>pr.f)\n                    return 1;\n                else\n                    return -1;\n            }\n            else\n                return -1;\n        }\n        public boolean equals(Object o)\n        {\n            pair ob=(pair)o;\n            int ff;\n            int ss;\n            if(o!=null)\n            {\n                ff=ob.f;\n                ss=ob.s;\n                if((ff==this.f)&&(ss==this.s))\n                    return true;\n            }\n            return false;\n        }\n        public int hashCode()\n        {\n            return (this.f+\" \"+this.s).hashCode();\n        }\n    }\n    public class triplet implements Comparable\n    {\n        int f,t;\n        int s;\n        triplet(int f,int s,int t)\n        {\n            this.f=f;\n            this.s=s;\n            this.t=t;\n        }\n        public boolean equals(Object o)\n        {\n            triplet ob=(triplet)o;\n            int ff;\n            int ss;\n            int tt;\n            if(o!=null)\n            {\n                ff=ob.f;\n                ss=ob.s;\n                tt=ob.t;\n                if((ff==this.f)&&(ss==this.s)&&(tt==this.t))\n                    return true;\n            }\n            return false;\n        }\n        public int hashCode()\n        {\n            return (this.f+\" \"+this.s+\" \"+this.t).hashCode();\n        }\n        public int compareTo(Object o)//ascending order\n        {\n            triplet tr=(triplet)o;\n            if(t>tr.t)\n                return 1;\n            else\n                return -1;\n        }\n    }\n    void merge1(int arr[], int l, int m, int r)\n    {\n        int n1 = m - l + 1;\n        int n2 = r - m;\n        int L[] = new int [n1];\n        int R[] = new int [n2];\n        for (int i=0; i<n1; ++i)\n            L[i] = arr[l + i];\n        for (int j=0; j<n2; ++j)\n            R[j] = arr[m + 1+ j];\n        int i = 0, j = 0;\n        int k = l;\n        while (i < n1 && j < n2)\n        {\n            if (L[i]<=R[j])\n            {\n                arr[k] = L[i];\n                i++;\n            }\n            else\n            {\n                arr[k] = R[j];\n                j++;\n            }\n            k++;\n        }\n        while (i < n1)\n        {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n        while (j < n2)\n        {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n    void sort1(int arr[], int l, int r)\n    {\n        if (l < r)\n        {\n            int m = (l+r)/2;\n            sort1(arr, l, m);\n            sort1(arr , m+1, r);\n            merge1(arr, l, m, r);\n        }\n    }\n    public static void main(String args[])throws Exception\n    {\n        new Thread(null,new templ(),\"templ\",1<<27).start();\n    }\n    public void run()\n    {\n        try\n        {\n            InputReader in = new InputReader(System.in);\n            PrintWriter out = new PrintWriter(System.out);\n            int n=in.ni();\n            int x=in.ni();\n            long l=1,r=n;\n            while(l<=r)\n            {\n                long mid=(l+r)/2;\n                long k=(mid*(mid+1))/2-(n-mid);\n                if(k==x)\n                {\n                    out.println((n-mid));\n                    break;\n                }\n                else if(k<x)\n                    l=mid+1;\n                else\n                    r=mid-1;\n            }\n            out.close();\n        }\n        catch(Exception e){\n            return;\n        }\n    }\n    static class InputReader {\n\n        private final InputStream stream;\n        private final byte[] buf = new byte[8192];\n        private int curChar, snumChars;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (snumChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= snumChars) {\n                curChar = 0;\n                try {\n                    snumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (snumChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int ni() {\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 nl() {\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] = ni();\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}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "// CodeForces Round #914 B train done\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\n\npublic class SportMafia {\n\t\n\tint n,k;\n\tint nCand;\n\n\tprivate void readData(BufferedReader bin) throws IOException {\n\t\tString s = bin.readLine();\n\t\tString []ss = s.split(\" \");\n\t\tn = Integer.parseInt(ss[0]);\n\t\tk = Integer.parseInt(ss[1]);\n\t}\n\n\tvoid printRes() {\n\t\tSystem.out.println(nCand);\n\t}\t\n\t\n\tprivate void calculate() {\n\t\t// count napitki\n\t\tdouble p;\n\t\tp = -1.5 + Math.sqrt(2.25 + 2.0*(n+k));\n\t\tnCand = (int)Math.round(n-p);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t// BufferedReader bin = new BufferedReader(new FileReader(\"cactus.in\"));\n\t\tBufferedReader bin = new BufferedReader(\n\t\t\t\tnew InputStreamReader(System.in));\n\t\tSportMafia l = new SportMafia();\n\t\tl.readData(bin);\n\t\tl.calculate();\n\t\tl.printRes();\n\t}\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n    static int inf = (int) 1e9;\n    public static void main(String[] args) throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n        int n = nextInt();\n        int k = nextInt();\n        long l = -1;\n        long r = 100000;\n        while(l != r - 1) {\n            long mid = (l + r) / 2;\n            if (mid * (mid + 1) / 2 - (n - mid) > k) r = mid;\n            else l = mid;\n        }\n        pw.println(n - l);\n        pw.close();\n    }\n\n    static BufferedReader br;\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static PrintWriter pw;\n\n    static String next() throws IOException {\n        while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\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    static Double nextDouble() throws IOException {\n        return Double.parseDouble(next());\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\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\n    long res = solve(n, k);\n    System.out.println(res);\n  }\n\n  private static long solve(long n, long k) {\n    return solveEq(1, -3 - 2 * n, n * n + n - 2 * k);\n  }\n\n  private static long solveEq(long a, long b, long c) {\n    long delta = b * b - 4 * a * c;\n    return (-b - (long)Math.sqrt(delta)) / (2 * a);\n  }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.util.*; \n\n\npublic class b{\n\t\n\tstatic class FastReader{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t}\n\n\tpublic static void main(String[] args) \n\t{ \n        FastReader sc = new FastReader(); \n        //PrintWriter out = new PrintWriter(System.out); \n        double n = (double)sc.nextLong();\n        double k = (double)sc.nextLong();\n        \n        double div = 9+8*n+8*k;\n        double ss = Math.sqrt(div);\n        //System.out.println(ss);\n\n        ss =  (ss-3)/2;\n        System.out.println( (int)(n-ss) );\n\t}\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n    static int n, k;\n\n    public static void main(String[] args) throws IOException {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n        n = sc.nextInt();\n        k = sc.nextInt();\n        long l = 0;\n        long r = n + 1;\n        while (l + 1 != r) {\n            long m = (r + l) / 2;\n            if (check(m))\n                l = m;\n            else\n                r = m;\n        }\n        pw.print(l * (l + 1L) / 2L - k);\n        pw.close();\n    }\n\n    public static boolean check(long m) {\n        return m * (m + 1) / 2 - (n - m) <= k;\n    }\n}\n\nclass FastScanner {\n    static BufferedReader br;\n    static StringTokenizer st = new StringTokenizer(\"\");\n\n    public FastScanner() {\n        br = new BufferedReader(new InputStreamReader(System.in));\n    }\n\n    public String next() throws IOException {\n        while (!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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\npublic class B1195 {\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 x =sc.nextInt();\n\t\tlong y =sc.nextInt();\n\t\tlong m = (-3+Math.round(Math.sqrt(9+8*(x+y))))/2;\n\t\tlong e = x-m;\n\t\tpw.println(e);\n\t\tpw.flush();\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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 Rustam Musin (t.me/musin_acm)\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        BSportivnayaMafiya solver = new BSportivnayaMafiya();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BSportivnayaMafiya {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.readInt();\n            int k = in.readInt();\n            int have = 0;\n            for (int x = 1; ; x++) {\n                have += x;\n                if (have < k) {\n                    continue;\n                }\n                if (have - (n - x) == k) {\n                    out.print(n - x);\n                    return;\n                }\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int 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 close() {\n            writer.close();\n        }\n\n        public void print(int i) {\n            writer.print(i);\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tstatic FastReader scan;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tSolver solver = new Solver();\n\t\tscan = new FastReader();\n\t\tout = new PrintWriter(System.out);\n\t\tint testCases = 1;\n\t\tfor(int i = 1; i <= testCases; i++) {\n//\t\t\tout.print(\"Case #\" + i + \": \");\n\t\t\tsolver.solve();\t\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class Solver {\n\t\t\n\t\tvoid solve() {\n\t\t\tlong n = scan.nextLong(), k = scan.nextLong();\n\t\t\tlong low = 0, high = n;\n\t\t\twhile(true) {\n\t\t\t\tlong mid = (low+high)/2;\n\t\t\t\tlong s = sum(n-mid);\n\t\t\t\tif(s - mid == k) {\n\t\t\t\t\tout.println(mid);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if(s - mid < k) {\n\t\t\t\t\thigh = mid-1;\n\t\t\t\t}\n\t\t\t\telse low = mid+1;\n\t\t\t\t//out.println(s-mid + \" \" + mid);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tstatic long sum(long a) {\n\t\t\tif(a == 0) return 0;\n\t\t\treturn (a+1)*a/2;\n\t\t}\n\t\t\n\t}\n\n\t// Sathvik's Template Stuff BELOW!!!!!!!!!!!!!!!!!!!!!!\n\n\tstatic class DSU {\n\t\tint[] root, size;\n\t\tint n;\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\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}\n\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)\n\t\t\t\treturn 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++)\n\t\t\t\taa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++)\n\t\t\t\ta[i] = aa[i];\n\t\t}\n\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++)\n\t\t\t\taa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++)\n\t\t\t\ta[i] = aa[i];\n\t\t}\n\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++)\n\t\t\t\taa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++)\n\t\t\t\ta[i] = aa[i];\n\t\t}\n\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++)\n\t\t\t\taa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++)\n\t\t\t\ta[i] = aa[i];\n\t\t}\n\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\n\t\tstatic long lcm(long a, long b) {\n\t\t\treturn a * (b / gcd(a, b));\n\t\t}\n\n\t\tstatic boolean isPrime(long n) {\n\t\t\tif (n <= 1)\n\t\t\t\treturn false;\n\t\t\tif (n <= 3)\n\t\t\t\treturn true;\n\t\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\t\treturn false;\n\t\t\tfor (long i = 5; i * i <= n; i = i + 6) {\n\t\t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\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\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\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\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main\n{\n\tPrintWriter out = new PrintWriter(System.out);\n\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer tok = new StringTokenizer(\"\");\n    String next() throws IOException {\n        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }\n        return tok.nextToken();\n    }\n    int ni() throws IOException { return Integer.parseInt(next()); }\n    long nl() throws IOException { return Long.parseLong(next()); }\n  \n    void solve() throws IOException {\n        int n=ni(),k=ni();\n        int puts=(int)Math.sqrt(2*k);\n        int t=(puts*(puts+1))/2;\n        puts++;\n        while (t<k) { t+=puts; puts++; }\n        \n        int turns=puts-1;\n        while (t-k!=n-turns) {\n            t+=puts;\n            puts++;\n            turns++;\n        }\n        System.out.println(t-k);\n    }\n    \n    public static void main(String[] args) throws IOException {\n        new Main().solve();\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class R574B\n{\n\n\tpublic static void main(String[] args)\n\t{\n\t\tJS scan = new JS();\n\t\tlong n = scan.nextInt();\n\t\tlong put = 1;\n\t\tlong k = scan.nextInt();\n\t\tlong have = 0;\n\t\tlong moves = 0;\n\t\twhile(have < k) {\n\t\t\thave += put;\n\t\t\tput++;\n\t\t\tmoves++;\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tmoves += have-k;\n\t\tans += have-k;\n\t\tlong lo = 0;\n\t\tlong hi = n-moves;\n\t\tlong bs = 0;\n\t\twhile(lo <= hi) {\n\t\t\t//could she have eaten mid candies?\n\t\t\tlong mid = (lo+hi)/2;\n\t\t\tlong left = (n-moves)-mid+put-1;\n\t\t\tlong rr = tri(left)-tri(put);\n\t\t\t\n\t\t\tif(rr <= mid) {\n\t\t\t\tbs = mid;\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\tSystem.out.println(ans+bs);\n\t}\n\t\n\tstatic long tri(long n) {\n\t\treturn n*(n-1)/2;\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\n\t\tpublic JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic JS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}\t\t\t\t\n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\npublic class submitting {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tStringTokenizer st = new StringTokenizer(sc.nextLine());\n\t\tlong n = Integer.parseInt(st.nextToken());\n\t\tlong k = Integer.parseInt(st.nextToken());\n\t\tlong put = n / 2;\n\t\tlong lower = 0;\n\t\tlong upper = n;\n\t\twhile (put * (put + 1) / 2 - (n - put) != k) {\n\t\t\tif (put * (put + 1) / 2 - (n - put) > k) {\n\t\t\t\tupper = put - 1;\n\t\t\t\tput = (lower + upper) / 2;\n\t\t\t} else {\n\t\t\t\tlower = put + 1;\n\t\t\t\tput = (lower + upper) / 2;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(n - put);\n\n\t\tsc.close();\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\n\n\nimport java.util.*;\n\npublic class Temppp {\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       \n        long ans = (long) ((java.lang.Math.sqrt((9+(8*(n+k))))-3)/2);\n        System.out.println(n-ans);\n        \n    }\n    \n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.*;\n \npublic class Main {\n    \n    public static void main(String[] args) throws Exception{\n        FastReader sc=new FastReader(); \n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n        Main mm=new Main();\n        long n=sc.nextLong();\n        long k=sc.nextLong();\n        long l=0;\n        long r=1000000000;\n        long ans=-1;\n        while(l<=r) {\n            long mid=(l+r)/2;\n            if(n-mid<=0) {\n                r=mid-1;\n            }\n            else {\n                long temp=(n-mid)*(n-mid+1)-(2*mid);\n                if(temp==2*k) {\n                    ans=mid;\n                    break;\n                }\n                else if(temp<2*k) {\n                    r=mid-1;\n                }\n                else if(temp>2*k) {\n                    l=mid+1;\n                }\n            }\n        }\n        System.out.println(ans);\n    }  \n}\n\n\nclass 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} ", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class B {\n    final int INF = 1_000_000_000;\n    void solve() {\n        int n = readInt();\n        int k = readInt();\n        long l = 0;\n        long r = INF;\n        while(r - l > 1){\n            long m = (r + l) >> 1;\n            if(m * (m + 1) / 2 + m >= k + n) r = m;\n            else l = m;\n        }\n        out.print(n - r);\n    }\n\n    public static void main(String[] args) {\n        new B().run();\n    }\n\n    private void run() {\n        try {\n            init();\n            solve();\n            out.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(-1);\n        }\n    }\n\n    private BufferedReader in;\n    private StringTokenizer tok = new StringTokenizer(\"\");\n\n    private PrintWriter out;\n\n    private void init() {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n//        try {\n//            in = new BufferedReader(new FileReader(\"absum.in\"));\n//            out = new PrintWriter(new File(\"absum.out\"));\n//        } catch (FileNotFoundException e) {\n//            e.printStackTrace();\n//        }\n    }\n\n    private String readLine() {\n        try {\n            return in.readLine();\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    private String readString() {\n        while (!tok.hasMoreTokens()) {\n            String nextLine = readLine();\n            if (nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n\n        return tok.nextToken();\n    }\n\n    private int readInt() {\n        return Integer.parseInt(readString());\n    }\n\n    private long readLong() {\n        return Long.parseLong(readString());\n    }\n\n    int[] readIntArray(int n){\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[] readLongArray(int n){\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    int[] castInt(List<Integer> list){\n        int[] res = new int[list.size()];\n        for(int i = 0;i<list.size();i++){\n            res[i] = list.get(i);\n        }\n        return res;\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        long n = scan.nextLong();\n        long k = scan.nextLong();\n        long D = 9 + 4 * (2 * k + 2 * n);\n        long y = (- 3 + (long)Math.sqrt(D)) / 2;\n        System.out.println(n - y);\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "/**\n * @Author Tran Quang Loc (darkkcyan)\n * BEFORE READING CODE:\n * Java is really lengthy (at least for Java 8). So I used the advantage of initialization block.\n * Basically, every initialization block run before the constructor and they run in the declaration order.\n * And as I understand, every properties (or global variables) is also counted as initialization block.\n */\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.*;\nimport static java.lang.System.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class Main {\n    PrintWriter out = new PrintWriter(System.out, false);\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer stok = null;\n    String next() {\n        while (stok == null || !stok.hasMoreTokens())\n            try {\n                stok = new StringTokenizer(in.readLine());\n            } catch (IOException e) { throw new RuntimeException(e); }\n        return stok.nextToken();\n    }\n\n    public static void main(String args[]) throws IOException {\n        if (args.length > 0) {\n            setIn(new FileInputStream(args[0] + \".inp\"));\n            setOut(new PrintStream(args[0] + \".out\"));\n        }\n        Main solver = new Main();\n        solver.out.flush();  //  could be replace with a method, but nah, this is just competitive programming :p\n    }\n\n    ///// Actual solution below /////\n\n    long n = parseLong(next()), k = parseLong(next());\n    long delta = 9 + 8 * (n + k);\n    long a = (-3 + (long)sqrt(delta)) / 2;\n    long b = n - a;\n    {\n        out.println(b);\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Alpha_Round {\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));\n        String[] in = reader.readLine().split(\" \");\n        long n = Long.parseLong(in[0]);\n        long k = Long.parseLong(in[1]);\n        long D = 9 + 8*k + 8*n;\n        long m = (long) ((-3 + Math.sqrt(D))/2);\n        writer.write((n - m) + \"\");\n        writer.close();\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class B {\n\t\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader();\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\t\n\t\tlong numCandies = 1;\n\t\tint turns = 1, add = 2;\n\t\twhile (numCandies < k) {\n\t\t\t++turns;\n\t\t\tnumCandies += add++;\n\t\t}\n\t\tint res = 0;\n\t\tif (numCandies > k) {\n\t\t\tturns += (numCandies-k);\n\t\t\tres += (numCandies-k);\n\t\t\tnumCandies = k;\n\t\t}\n\t\t\n\t\tif (turns == n) {\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\telse {\n\t\t\twhile (turns != n) {\n\t\t\t\tres += add;\n\t\t\t\tturns += add++ + 1;\n\t\t\t}\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\t\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader br;\n\t\tpublic StringTokenizer st;\n\t\t\n\t\tpublic InputReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = null;\n\t\t}\n\t\t\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\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 n = in.nextLong();\n        long k = in.nextLong();\n        long val = 2 * n + 2 * k;\n        long D = 9 + 4 * val;\n        long sqrtD = (long)Math.sqrt((double)D);\n        double r1 = (-3 + sqrtD) / 2;\n        long r1DAsh = (long)r1;\n        System.out.println(n - r1DAsh);\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<Integer> primeFactorisation(int n)\n    {\n        ArrayList<Integer> 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<bString.length();i++)\n        {\n            d = (d * d) % n;\n            if(bString.charAt(i) == '1')\n                d = (d * a) % n;\n        }\n        return d;\n    }\n}\nclass Name\n{\n    long d;\n    long x;\n    long y;\n\n    public Name(long d, long x, long y)\n    {\n        this.d = d;\n        this.x = x;\n        this.y = y;\n    }\n}\nclass SuffixArray\n{\n    int ALPHABET_SZ = 256, N;\n    int[] T, lcp, sa, sa2, rank, tmp, c;\n\n    public SuffixArray(String str)\n    {\n        this(toIntArray(str));\n    }\n\n    private static int[] toIntArray(String s)\n    {\n        int[] text = new int[s.length()];\n        for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i);\n        return text;\n    }\n\n    public SuffixArray(int[] text)\n    {\n        T = text;\n        N = text.length;\n        sa = new int[N];\n        sa2 = new int[N];\n        rank = new int[N];\n        c = new int[Math.max(ALPHABET_SZ, N)];\n        construct();\n        kasai();\n    }\n\n    private void construct()\n    {\n        int i, p, r;\n        for (i = 0; i < N; ++i) c[rank[i] = T[i]]++;\n        for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];\n        for (i = N - 1; 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<Integer> 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<Integer> 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<pattern.length;)\n        {\n            if(pattern[i] == pattern[index])\n            {\n                lps[i] = index + 1;\n                index++;\n                i++;\n            }\n            else\n            {\n                if(index != 0)\n                {\n                    index = lps[index - 1];\n                }\n                else\n                {\n                    lps[i] = 0;\n                    i++;\n                }\n            }\n        }\n        return lps;\n    }\n\n    public ArrayList<Integer> 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<Integer> 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<n;i++)\n        {\n            powers[i] = (powers[i - 1] * p) % m;\n        }\n        return powers;\n    }\n    public long computeHash(String s)\n    {\n        long p = 31;\n        long m = 1_000_000_009;\n        long hashValue = 0L;\n        long[] powers = computePowers(p, s.length(), m);\n        for(int i=0;i<s.length();i++)\n        {\n            char ch = s.charAt(i);\n            hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m;\n        }\n        return hashValue;\n    }\n}\nclass BasicFunctions\n{\n    public long min(long[] A)\n    {\n        long min = Long.MAX_VALUE;\n        for(int i=0;i<A.length;i++)\n        {\n            min = Math.min(min, A[i]);\n        }\n        return min;\n    }\n    public long max(long[] A)\n    {\n        long max = Long.MAX_VALUE;\n        for(int i=0;i<A.length;i++)\n        {\n            max = Math.max(max, A[i]);\n        }\n        return max;\n    }\n}\nclass Matrix\n{\n    long a;\n    long b;\n    long c;\n    long d;\n\n    public Matrix(long a, long b, long c, long d)\n    {\n        this.a = a;\n        this.b = b;\n        this.c = c;\n        this.d = d;\n    }\n}\nclass MergeSortInt\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        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n\n        /* Create temp arrays */\n        int L[] = new int[n1];\n        int R[] = new int[n2];\n\n        /*Copy data to temp arrays*/\n        for (int i = 0; i < n1; ++i)\n            L[i] = arr[l + i];\n        for (int j = 0; j < n2; ++j)\n            R[j] = arr[m + 1 + j];\n\n\n        /* Merge the temp arrays */\n\n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n\n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2) {\n            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        /* Copy remaining elements of L[] if any */\n        while (i < n1) {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n\n        /* Copy remaining elements of R[] if any */\n        while (j < n2) {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n\n    // Main function that sorts arr[l..r] using\n    // merge()\n    void sort(int arr[], int l, int r) {\n        if (l < r) {\n            // Find the middle point\n            int m = (l + r) / 2;\n\n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr, m + 1, r);\n\n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n\n}\nclass MergeSortLong\n{\n    // Merges two subarrays of arr[].\n    // First subarray is arr[l..m]\n    // Second subarray is arr[m+1..r]\n    void merge(long arr[], int l, int m, int r) {\n        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n\n        /* Create temp arrays */\n        long L[] = new long[n1];\n        long R[] = new long[n2];\n\n        /*Copy data to temp arrays*/\n        for (int i = 0; i < n1; ++i)\n            L[i] = arr[l + i];\n        for (int j = 0; j < n2; ++j)\n            R[j] = arr[m + 1 + j];\n\n\n        /* Merge the temp arrays */\n\n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n\n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2) {\n            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        /* Copy remaining elements of L[] if any */\n        while (i < n1) {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n\n        /* Copy remaining elements of R[] if any */\n        while (j < n2) {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n\n    // Main function that sorts arr[l..r] using\n    // merge()\n    void sort(long arr[], int l, int r) {\n        if (l < r) {\n            // Find the middle point\n            int m = (l + r) / 2;\n\n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr, m + 1, r);\n\n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n}\nclass Node\n{\n    String a;\n    String b;\n    Node(String s1,String s2)\n    {\n        this.a = s1;\n        this.b = s2;\n    }\n    @Override\n    public boolean equals(Object ob)\n    {\n        if(ob == null)\n            return false;\n        if(!(ob instanceof Node))\n            return false;\n        if(ob == this)\n            return true;\n        Node obj = (Node)ob;\n        if(this.a.equals(obj.a) && this.b.equals(obj.b))\n            return true;\n        return false;\n    }\n\n    @Override\n    public int hashCode()\n    {\n        return (int)this.a.length();\n    }\n}\nclass 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}\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<segmentTree.length;i++)\n            segmentTree[i] = Integer.MIN_VALUE;\n\n        constructSegmentTree(segmentTree,input,0,input.length-1,0);\n        return segmentTree;\n\n    }\n    private void constructSegmentTree(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        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);\n        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);\n        segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);\n    }\n    public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len)\n    {\n        return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0);\n    }\n    private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos)\n    {\n        if(qlow <= low && qhigh >= 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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Double.*;\nimport java.lang.Math.*;\n\npublic class B {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew B().run();\n\t}\n\n\tpublic void run() throws Exception {\n\t\tFastIO file = new FastIO();\n\t\tlong n = file.nextLong();\n\t\tlong k = file.nextLong();\n\t\tlong lo = 1;\n\t\tlong hi = n;\n\t\tlong ans = 0;\n\t\twhile (lo <= hi) {\n\t\t\tlong mi = lo + (hi - lo) / 2;\n\t\t\tlong q = mi * (mi + 1) / 2 - (n - mi);\n\t\t\tif (q == k) {\n\t\t\t\tans = (n - mi);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (q < k) {\n\t\t\t\tlo = mi + 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\thi = mi - 1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n\tpublic static class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastIO() {\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 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 / 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 / 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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n \npublic class Main {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc =new Scanner(System.in);\n\t\tlong n = sc.nextLong(), k = sc.nextLong();\n\t\tlong ans = 0, sum = 0;\n\t\twhile(ans < n) {\n\t\t\tif(sum - (n-ans) == k) break;\n\t\t\tans++;\n\t\t\tsum += ans;\n\t\t}\n\t\tsc.close();\n\t\tSystem.out.println(n-ans);\n\t}\n    \n   \n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tFastReader fr =new FastReader();\n\n\t\tPrintWriter op =new PrintWriter(System.out);\n\n\t\tlong n =fr.nextLong() ,k =fr.nextLong() ,d =(long)Math.sqrt(9l+8l*(n+k)) ;\n\n\t\td -= 3l ;\td /=2l ;op.println(n-d) ;\n\n\t\top.flush();\top.close();\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{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tst =new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch(IOException e)\n\t\t\t\t{\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str =\"\";\n\n\t\t\ttry\n\t\t\t{\n\t\t\t\tstr =br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\n\t\t\treturn str;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next()) ;\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n=sc.nextInt(),k=sc.nextInt();\n\t\tfor(int x=0;;x++) {\n\t\t\tif(2*1L*x+x*1L*(x+1)==2L*(k+n)) {\n\t\t\t\tout.println(n-x);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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 *\n * @author Aman Kumar Singh\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        BSportMafia solver = new BSportMafia();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BSportMafia {\n        int MAXN = 200005;\n        PrintWriter out;\n        InputReader in;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            this.out = out;\n            this.in = in;\n            long n = nl();\n            long k = nl();\n            long i = 0;\n            k += n;\n            for (i = 0; i < MAXN; i++) {\n                long x = (i * (i + 3)) / 2;\n                if (k == x) {\n                    pn(n - i);\n                    return;\n                }\n            }\n\n        }\n\n        long nl() {\n            return in.nextLong();\n        }\n\n        void pn(long zx) {\n            out.println(zx);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new UnknownError();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new UnknownError();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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            }\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class TaskB {\n\n    void run() {\n        FastReader in = new FastReader(System.in);\n//        FastReader in = new FastReader(new FileInputStream(\"input.txt\"));\n        PrintWriter out = new PrintWriter(System.out);\n//        PrintWriter out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\n\n        long n = in.nextLong();\n        long k = in.nextLong();\n\n        long a = 1;\n        long b = -(2 * n + 3);\n        long c = n * n + n - 2 * k;\n\n        long d = b * b - 4 * a * c;\n        long ans1 = (-b + (long) Math.sqrt(d)) / 2;\n        long ans2 = (-b - (long) Math.sqrt(d)) / 2;\n\n        if (ans1 >= 0 && ans1 <= n) {\n            out.println(ans1);\n        } else {\n            out.println(ans2);\n        }\n\n\n        out.close();\n    }\n\n    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\n    public static void main(String[] args) {\n        new TaskB().run();\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "//package learning;\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\npublic class NitsLocal {\n    static ArrayList<String> s1;\n    static boolean[] prime;\n    static int n = (int)1e7;\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];\nsieve();\n                prime[1] = false;\n         \n          \n             long n = sc.nl();\n             long k = sc.nl();\n             long b = 2*n + 3;\n             long c = n*n - 2*k + n;\n             long q1 = (b + (long)Math.sqrt(b*b - 4*c))/2;\n             long q2 = (b - (long)Math.sqrt(b*b - 4*c))/2;\n             if(q1 >= q2 && q1 <= n)\n                 w.println(q1);\n             else\n                 w.println(q2);\n                 \n                \n       \n             \n       w.close();\n        \n    }\n    static int nextPowerOf2(int n) \n    { \n        int count = 0; \n  \n        // First n in the below  \n        // condition is for the  \n        // case where n is 0 \n        if (n > 0 && (n & (n - 1)) == 0) \n            return n; \n  \n        while(n != 0) \n        { \n            n >>= 1; \n            count += 1; \n        } \n  \n        return 1 << count; \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;i+=2)\n        {\n            int num = (int) (c[i] - 48);\n            num += a;\n            num%=10;\n            c[i] = (char) (num+48);\n        }\n        return new String(c);\n    }\n    static String move(String s,int h,int n)\n    {\n        h%=n;\n        char []c = s.toCharArray();\n        char []temp = new char[n];\n        for(int i=0;i<n;i++)\n        {\n            temp[(i+h)%n] = c[i];\n        }\n        return new String(temp);\n    }\n    \n     public static int ip(String s){\nreturn Integer.parseInt(s);\n}\n     static class multipliers implements Comparator<Long>{\n  \n         \n  public int compare(Long a,Long b) {\n   if(a<b)\n    return 1;\n   else if(b<a)\n    return -1;\n   else\n    return 0;\n  }\n }\n     static class multipliers1 implements Comparator<Student>{\n  \n  public int compare(Student a,Student b) {\n   if(a.y<b.y)\n    return 1;\n   else if(b.y<a.y)\n    return -1;\n   else\n   {\n       if(a.id < b.id)\n           return 1;\n       else if(b.id<a.id)\n           return -1;\n       else\n           return 0;\n           \n    //return 0;\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 Student\n    {\n        int id;\n        //int x;\n       \n        int y;\n        //long z;\n        \n        Student(int id,int y)\n        {\n            this.id = id;\n            //this.x = x;\n            //this.s = s;\n            this.y = y;\n           // this.z = z;\n            \n            \n            \n        }\n        \n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\n// **** B. Sport Mafia ****\n\npublic class B {\n\tstatic char [] in = new char [1000000];\n\tpublic static void main (String [] arg) throws Throwable {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\t\n\t\tlong ate = 0;\n\t\tlong ans = -1;\n\t\tfor (long i = 1; ans < 0; ++i) {\n\t\t\tlong test = (i * (i+1)) / 2;\n\t\t\tif (test < k) continue;\n\t\t\t\n\t\t\tlong adding_moves = i;\n\t\t\tlong eating_moves = n-i;\n\t\t\tif (test - eating_moves == k) ans = eating_moves;\n\t\t}\n\t\tSystem.out.println(ans);\n\t\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\n\t/************** HELPER CLASSES ***************/\n    //static class HS extends HashSet<Integer>{public HS(){super();}public HS(int a){super(a);}};\n\t//static class AL extends ArrayList<Integer>{public AL(){super();}public AL(int a){super (a);}};\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint i,j;long L; public Pair(int xx, int yy, long LL){i=xx;j=yy;L=LL;} \n\t\tpublic int compareTo(Pair p) { return (this.L < p.L) ? -1 : ((this.L == p.L && this.i < p.i) ? -1 : 1);}\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<LIM; ++i) if (!b[i]) {count++; for (int j = i<<1; j<LIM; j+=i) b[j] = true;}\n\t\tint [] primes = new int[count];\n\t\tfor (i = 2,count=0;i<LIM;++i) if (!b[i]) primes[count++] = i;\n\t\treturn primes;\n\t}\n\tpublic static int[] numPrimeFactors(int LIM) {\n\t\tint i,count = 0;\n\t\tint [] b = new int [LIM];\n\t\tfor (i = 2;i<LIM; ++i) if (b[i] == 0) {count++; for (int j = i; j<LIM; j+=i) b[j]++;}\n\t\treturn b;\n\t}\n\tpublic static StringBuilder stringFromArray(int [] a) {\n\t\tStringBuilder b = new StringBuilder(9*a.length);\n\t\tfor (int i = 0; i<a.length; ++i) {\n\t\t\tif (i != 0) b = b.append(' ');\n\t\t\tb = b.append(a[i]);\n\t\t}\n\t\treturn b;\n\t}\n\tpublic static long modPow (long a, long n, long MOD) { long S = 1; for (;n > 0; n>>=1, a=(a*a)%MOD) if ((n & 1) != 0) S = (a*S) % MOD; return S;}\n}\n\n/* Full Problem Text:\n  \nEach evening after the dinner the SIS's students gather together to play the game of Sport Mafia.\nFor the tournament, Alya puts candies into the box, which will serve as a prize for a winner.\nTo do that, she performs n actions.\nThe first action performed is to put a single candy into the box.\nFor each of the remaining moves she can choose from two options:\n \n the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it.\nThis way the number of candies in the box decreased by 1; \n the second option is to put candies in the box.\nIn this case, Alya will 1 more candy, than she put in the previous time.\nThus, if the bank is empty, then it can only use the second option.\nFor example, one possible sequence of Alya's actions look as follows:\n \n put one candy into the box; \n put two candies into the box; \n eat one candy from the box; \n eat one candy from the box; \n put three candies into the box; \n eat one candy from the box; \n put four candies into the box; \n eat one candy from the box; \n put five candies into the box; \nThis way she will perform 9 actions, the of candies at the end will be 11, while Alya will eat 4 candies in total.\nYou know the total number of actions n and the number of candies at the end k.\nYou need to find the total number of sweets Alya ate.\nThat is the number of moves of the second option.\nIt's guaranteed, that for the given n and k the answer always exists.\nPlease note, that during an action of the first option, Alya takes out and eats exactly one candy.\n\n */", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    static class FastScanner {\n        private BufferedReader bufferedReader;\n        private StringTokenizer stringTokenizer;\n\n        public FastScanner(InputStream inputStream) {\n            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        public String next() {\n            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n                try {\n                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n                } catch (IOException ignored) {\n                }\n            }\n            return stringTokenizer.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 class Node implements Comparable {\n        Node left;\n        Node right;\n        private int value;\n\n        Node(Node left, Node right, int value) {\n            this.left = left;\n            this.right = right;\n            this.value = value;\n        }\n\n        @Override\n        public int compareTo(Object o) {\n            return Integer.compare(this.value, ((Node) o).value);\n        }\n    }\n\n    private static int fib(int n, int m) {\n        if (n < 2) return n;\n        int a = 0;\n        int b = 1;\n        for (int i = 0; i < n - 2; i++) {\n            int c = (a + b) % m;\n            a = b;\n            b = c;\n        }\n        return (a + b) % m;\n    }\n\n    static long gcd(long a, long b) {\n        if (b == 0) return a;\n        return gcd(b, a % b);\n    }\n\n    static long lcm(long a, long b) {\n        return Math.abs(a * b) / gcd(a, b);\n    }\n\n    static class DSU {\n        private int[] p;\n        private int[] r;\n\n        DSU(int n) {\n            p = new int[n];\n            r = new int[n];\n            Arrays.fill(p, -1);\n            Arrays.fill(r, 0);\n        }\n\n        int find(int x) {\n            if (p[x] < 0) {\n                return x;\n            }\n            return p[x] = find(p[x]);\n        }\n\n        void union(int a, int b) {\n            a = find(a);\n            b = find(b);\n            if (a == b) return;\n            if (r[a] < r[b]) {\n                p[a] = b;\n            } else {\n                p[b] = a;\n            }\n            if (r[a] == r[b]) {\n                r[a]++;\n            }\n        }\n    }\n\n    private static boolean isPrime(long n) {\n        for (int i = 2; i < n; i++) {\n            if (n % i == 0) return false;\n        }\n        return true;\n    }\n\n    private static double med(Integer[] a) {\n        Arrays.sort(a);\n        if (a.length % 2 == 0) {\n            int r = a.length / 2;\n            int l = r - 1;\n            double s = a[l] + a[r];\n            return s / 2.0;\n        }\n        int m = a.length / 2;\n        return a[m];\n    }\n\n    static Map<Integer, ArrayList<Integer>> g;\n    static Map<Integer, Integer> color;\n\n    static void dfs(int v, int c) {\n        color.put(v, c);\n        for (int i = 0; i < g.get(v).size(); i++) {\n            int u = g.get(v).get(i);\n            if (!color.containsKey(u)) {\n                dfs(u, c);\n            }\n        }\n    }\n\n    static void reverse(Integer[] a) {\n        Collections.reverse(Arrays.asList(a));\n    }\n\n    static boolean next(Integer[] a) {\n        int i = a.length - 1;\n        while (a[i] == 0) i--;\n        int c = 0;\n        while (i >= 0 && a[i] == 1) {\n            c++;\n            i--;\n        }\n        if (i < 0) return false;\n        a[i] = 1;\n        for (int j = i + 1; j < a.length; j++) {\n            a[j] = 0;\n        }\n        c--;\n        for (int j = 0; j < c; j++) {\n            a[a.length - 1 - j] = 1;\n        }\n        return true;\n    }\n\n    private static int bin(Integer[] a, int l, int r, int x) {\n        if (l >= r) return l;\n        int m = (l + r) / 2;\n        if (a[m] > x) {\n            return bin(a, l, m, x);\n        } else if (a[m] < x || (m < a.length - 1 && a[m + 1] == x)) {\n            return bin(a, m + 1, r, x);\n        }\n        return m + 1;\n    }\n\n    private static class SegmentTree {\n        private long[] d;\n        private long[] a;\n\n        SegmentTree(int n) {\n            a = new long[n];\n            d = new long[5 * n];\n        }\n\n        void update(int v, int l, int r, int pos, long val) {\n            if (l == r) {\n                d[v] += val;\n                a[l] += val;\n            } else {\n                int mid = (l + r) / 2;\n                if (pos <= mid) {\n                    update(v * 2, l, mid, pos, val);\n                } else {\n                    update(v * 2 + 1, mid + 1, r, pos, val);\n                }\n                d[v] = d[v * 2] + d[v * 2 + 1];\n            }\n        }\n\n        int find(int v, int l, int r, long w) {\n            if (v >= d.length) return -1;\n            int mid = (l + r) / 2;\n            if (d[v] <= w) return r;\n            long o = w - d[v * 2];\n            if (mid + 1 < a.length && o >= a[mid + 1]) {\n                return find(v * 2 + 1, mid + 1, r, o);\n            }\n            if (w >= a[l])\n                return find(v * 2, l, mid, w);\n            return -1;\n        }\n\n        int iterFind(long w) {\n            if (a[0] > w) return -1;\n            int l = 0, r = a.length - 1;\n            int v = 1;\n            while (d[v] > w) {\n                int mid = (l + r) / 2;\n                long o = w - d[v * 2];\n                if (mid + 1 < a.length && o >= a[mid + 1]) {\n                    l = mid + 1;\n                    v = v * 2 + 1;\n                    w = o;\n                } else {\n                    v = v * 2;\n                    r = mid;\n                }\n            }\n            return r;\n        }\n\n        int get(int v, int vl, int vr, long w) {\n            // cout << t[v] << \"  \"<< v << \" \" << vl << \" \" << vr<<\" \" << w << endl;\n            if (d[v] < w) return -1;\n            if (vl > vr) return -1;\n            if (vl == vr) {\n                if (d[v] > w) return vl - 1;\n                else return -1;\n            }\n            if (d[v * 2] > w) return get(v * 2, vl, (vl + vr) / 2, w);\n            else return get(v * 2 + 1, (vl + vr + 2) / 2, vr, w - d[v * 2]);\n        }\n    }\n\n    private static class FenwickTree {\n        long[] t;\n\n        FenwickTree(int n) {\n            t = new long[n];\n        }\n\n        long sum(int r) {\n            long result = 0;\n            for (; r >= 0; r = (r & (r + 1)) - 1)\n                result += t[r];\n            return result;\n        }\n\n        void inc(int i, long delta) {\n            int n = t.length;\n            for (; i < n; i = (i | (i + 1)))\n                t[i] += delta;\n        }\n    }\n\n    void insert(List<Long> list, Long element) {\n        int index = Collections.binarySearch(list, element);\n        if (index < 0) {\n            index = -index - 1;\n        }\n        list.add(index, element);\n    }\n\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner(System.in);\n        PrintWriter printer = new PrintWriter(System.out);\n        long n = scanner.nextLong();\n        long k = scanner.nextLong();\n        long l = 1;\n        long r = n;\n        while(true){\n            long m = (l + r) / 2;\n            long x = (m * (m + 1)) / 2;\n            x -= n - m;\n            if (x == k) {\n                printer.println(n - m);\n                break;\n            } else if (x < k) {\n                l = m + 1;\n            } else {\n                r = m - 1;\n            }\n        }\n        printer.flush();\n        printer.close();\n    }\n}\n/*\n4 2\n1 1 4\n0 2 3\n\n5 3\n1 2 4\n0 4 5\n0 3 5\n\n4 3\n1 2 3\n1 1 2\n0 1 3\nNO\n */", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n \n \npublic class q5 {\n\t\n\t\n\t\n    \n  \n\t\n \n\tpublic static void main(String[] args) throws IOException {\n\t\n\tReader.init(System.in);\n\tPrintWriter out=new PrintWriter(System.out);\n\tlong n=Reader.nextInt();\n\tlong k=Reader.nextLong();\n\tlong v=8*n+8*k+4;\n\tlong v2=(long) Math.sqrt(v);\n\tlong v3=2*n+2;\n\t//long v4=(v3+v2)/2;\n\tlong v5=(v3-v2)/2;\n\tout.println(v5);\n\t\n\t\n\t\n\t\n\t\n\tout.flush();\n\t}\n}\n\n\n\n\n \n \n \nclass Reader {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n    /** call this method to initialize reader for InputStream */\n    static void init() throws IOException {\n    \t reader = new BufferedReader(\n                 new FileReader(\"detect.in\"));\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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\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 = Integer.parseInt(st.nextToken());\n        long k = Integer.parseInt(st.nextToken());\n        long l = 0;\n        long r = n;\n        while(l <= r){\n            long min = (l + r) / 2;\n            if((min * (min + 1) / 2 - (n - min) == k)){\n                System.out.println(n - min);\n                return;\n            }\n            else if((min * (min + 1) / 2 - (n - min) > k)){\n                r = min - 1;\n            }\n            else{\n                l = min + 1;\n            }\n        }\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class  zz{\n\tstatic int mod=(int)1e9+7;\n    public static void main(String[] args) throws Exception{\n        //MScanner sc = new MScanner(\"chess.in\");\n        MScanner sc = new MScanner(System.in);\n        PrintWriter pw=new PrintWriter(System.out);\n        int n=sc.nextInt();\n        //int[]in=new int[n];for(int i=0;i<n;i++)in[i]=sc.nextInt();\n        int k=sc.nextInt();\n        int x=(-3+(int)Math.sqrt(9+4*1.0*(2*k*1.0+2*n*1.0)))/2;\n        pw.println(n-x);\n        pw.flush();\n    }\n    static class pair implements Comparable<pair>{\n    \tString t;int d;int idx;\n    \tpair(String x,int y,int i){\n    \t\tt=x;d=y;idx=i;\n    \t}\n    \t@Override\n    \tpublic int compareTo(pair o) {\n    \t\tif(t.compareTo(o.t)!=0) {\n    \t\t\treturn t.compareTo(o.t);\n    \t\t}\n    \t\treturn o.d-d;\n    \t}\n    \t \n    \tpublic boolean equals(pair o) {\n    \t\tif(this.compareTo(o)==0)return true;\n    \t\treturn false;\n    \t}\n    \tpublic String toString() {\n    \t\treturn \"(\"+t+\" \"+d+\")\";\n    \t}\n    }\n    static class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n \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 \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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Scanner;\n\npublic class Main {\n\tstatic StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(System.in));\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tstatic PrintWriter pr = new PrintWriter(new BufferedOutputStream(System.out));\n\tstatic Scanner sc = new Scanner(System.in);\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint i = 0;\n\t\tint cont = 0;\n\t\twhile(cont<b) {\n\t\t\ti++;\n\t\t\tcont+=i;\n\t\t}\n\t\t\n\t\tif(i+cont-b==a) {\n\t\t\tSystem.out.println(cont-b);\n\t\t}else {\n\t\t\twhile(i+cont-b!=a) {\n\t\t\t\ti++;\n\t\t\t\tcont+=i;\n\t\t\t}\n\t\t\tSystem.out.println(cont-b);\n\t\t}\n\t}\n\n\tprivate static int nextInt() {\n\t\ttry {\n\t\t\tst.nextToken();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn (int) st.nval;\n\t}\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "// Working program using Reader Class\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Main2\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\n    public static void main(String[] args) throws IOException\n    {\n        Reader z = new Reader();\n        long n=z.nextLong(), k=z.nextLong(), x;\n        x=9L+8L*(k+n);\n        x=(long) Math.sqrt(x);\n        x=(x-3)/2;\n        System.out.println(n-x);\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class CFEdu66 {\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 k = in.nextLong();\n\t\tdouble tmp = Math.sqrt(9 + 8*(n+k));\n\t\tif(Math.ceil(tmp)-tmp<0.001)\n\t\t\ttmp = Math.ceil(tmp);\n\t\t\n\t\tlong root = (long)tmp;\n\t\tlong x = (-3+root)/2;\n\t\tSystem.out.println(n-x);\n\t\t\n\t}\n\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main{\n  public static void main(String[] args) {\n    long  n,k;\n    Scanner s= new Scanner(System.in);\n\tn=s.nextInt();\n\tk=s.nextInt();\n\tSystem.out.println((int)(n-((-3+Math.sqrt(9+8*(n+k)))/2)));  \n  }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner s=new Scanner(System.in);\n\t\t\n\t\tdouble n=s.nextLong();\n\t\tdouble k=s.nextLong();\n\t\t\n\t\tdouble num=(-3+Math.sqrt(9+8*(n+k)))/2;\n\t\t\n\t\tSystem.out.println((long)(n-num));\n\t\t\n\t}\n\t\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class B {\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tstatic PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tString[] split = br.readLine().split(\" \");\n\t\t\n\t\tlong n = Long.parseLong(split[0]);\n\t\tlong k = Long.parseLong(split[1]);\n\t\t\n\t\tlong left = -1;\n\t\tlong right = n + 1;\n\t\t\n\t\twhile(right - left >= 2) {\n\t\t\tlong mid = (left + right) / 2; // 10\n\t\t\t// if(mid > n) {\n\t\t\t\t// right = mid;\n\t\t\t\t// continue;\n\t\t\t// }\n\t\t\t\n\t\t\tlong newN = n - mid; //-5\n\t\t\tlong temp = newN * (newN + 1) / 2; //10\n\t\t\t\n\t\t\tlong eh = temp - k - mid;\n\t\t\t\n\t\t\tif(eh == 0) {\n\t\t\t\tpw.println(mid);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if(eh < 0)\n\t\t\t\tright = mid;\n\t\t\telse\n\t\t\t\tleft = mid;\n\t\t}\n\t\t\n\t\tpw.close();\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n\npublic class Solution{\n \n\tpublic static Integer INT(String s){\n\t\treturn Integer.parseInt(s);\n\t}\n \n\tpublic static Long LONG(String s){\n\t\treturn Long.parseLong(s);\n\t}\n \n\t//====================================================================================================================\n \n \n \t\n\n\tpublic static void main(String args[])throws IOException{\n \n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\tScanner in=new Scanner(System.in);\tStringBuilder out=new StringBuilder();\n \n\t\tlong n=in.nextLong(),\n\t\t\t k=in.nextLong();\n\n\t\tlong a=1,\n\t\t\t b=3,\n\t\t\t c=-2*(n+k);\n\t\t\n\t\tlong r1=(-b+(long)Math.sqrt(b*b-4*a*c))/(2*a);\n\t\tlong r2=(-b-(long)Math.sqrt(b*b-4*a*c))/(2*a);\n\n\t\tSystem.out.println(n-Math.max(r1, r2));\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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\t// your code goes here\n\t\tFastReader sc=new FastReader();\n\t\tlong n=sc.L();\n\t\tlong k=sc.L();\n\t\tlong x=8*(n+k);\n\t\tx+=9;\n\t\tx=(long)Math.sqrt(x)-3;\n\t\tx/=2;\n\t\t\n\t\tSystem.out.println(n-x);\n\t }\n\t static int binarysearch(int x,int[] b,int n)\n\t {\n\t     int l=0,r=n-1,m=(l+r)/2;\n\t     if(x<b[0]||x>b[r])\n\t     return -1;\n\t     while(l<=r)\n\t     {\n\t         m=(l+r)/2;\n\t         if(b[m]==x)\n\t         return m;\n\t         if(b[m]>x)\n\t         r=m-1;\n\t         else\n\t         l=m+1;\n\t     }\n\t     return -1;\n\t }\n\t static int lower(int x,int b[],int n)\n\t {\n\t     if(x<b[0])\n\t     return -1;\n\t     else if(x==b[0])\n\t     return 0;\n\t     if(x>=b[n-1])\n\t     return n-1;\n\t     int l=0,r=n-1,m=(l+r)/2;\n\t     while(l<=r)\n\t     {\n\t         m=(l+r)/2;\n\t         if(b[m]<=x&&b[m+1]>x)\n\t         return m;\n\t         else if(b[m]>x&&b[m-1]<=x)\n\t         return m-1;\n\t         if(b[m]>x)\n\t         r=m-1;\n\t         else if(b[m]<x)\n\t         l=m+1;\n\t     }\n\t     return -1;\n\t }\n\t static int upper(int x,int b[],int n)\n\t {\n\t     if(x<=b[0])\n\t     return 0;\n\t     else if(x==b[n-1])\n\t     return n-1;\n\t     if(x>b[n-1])\n\t     return -1;\n\t     int l=0,r=n-1,m=(l+r)/2;\n\t     while(l<=r)\n\t     {\n\t         m=(l+r)/2;\n\t         if(b[m]<x&&b[m+1]>=x)\n\t         return m+1;\n\t         else if(b[m]>=x&&b[m-1]<x)\n\t         return m;\n\t         if(b[m]>x)\n\t         r=m-1;\n\t         else if(b[m]<x)\n\t         l=m+1;\n\t     }\n\t     return -1;\n\t }\n\t \n\t static long power(long x, long y, long p) \n    { \n        // Initialize result \n        long res = 1;      \n         \n        // Update x if it is more   \n        // than or equal to p \n        x = x % p;  \n      \n        while (y > 0) \n        { \n            // If y is odd, multiply x \n            // with result \n            if((y & 1)==1) \n                res = (res * x) % p; \n      \n            // y must be even now \n            // y = y / 2 \n            y = y >> 1;  \n            x = (x * x) % p;  \n        } \n        return res; \n    } \n\t  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 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 a,int b)\n    {\n        long result=1;\n        if(b==0)\n        return 1;\n        long x=a;\n        while(b>0)\n        {\n            if(b%2!=0)\n            result*=x;\n            \n            x=x*x;\n            b=b/2;\n        }\n        return result;\n    }\n    \n    static ArrayList<Integer> sieveOfEratosthenes(int n) \n    { \n        ArrayList<Integer> arr=new ArrayList<Integer>();\n        boolean prime[] = new boolean[n+1]; \n        for(int i=2;i<n;i++) \n            prime[i] = true; \n          \n        for(int p = 2; p*p <=n; p++) \n        { \n            if(prime[p] == true) \n            { \n                arr.add(p);\n                for(int i = p*p; i <= n; i += p) \n                    prime[i] = false; \n            } \n        } \n        return arr;\n    } \n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n    public static void main(String[] args) {\n        new Thread(null, new Runnable() {\n            public void run() {\n                new Main().solve();\n            }\n        }, \"1\", 1 << 26).start();\n    }\n\n    void solve() {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        ScanReader in = new ScanReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        BSportMafia solver = new BSportMafia();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BSportMafia {\n        public long findsqrt(long a) {\n            long b = (long) Math.sqrt(a);\n            for (long tt = Math.max(0, b - 10); tt <= b + 10; tt++) if (tt * tt == a) return tt;\n            return -1;\n        }\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            long n = in.scanInt();\n            long k = in.scanInt();\n            out.println(n - (-3 + findsqrt(9 + 8 * (k + n))) / 2);\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static PrintWriter pw = new PrintWriter(System.out);\n\n    public static String next() throws IOException {\n        while (!st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine());\n        }\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 void main(String[] args) throws IOException {\n        new Main().run();\n    }\n\n    void run() throws IOException {\n        long n = nextInt();\n        long k = nextInt();\n        long d = 9 + 8 * (n + k);\n        pw.print(n - (-3 + (int)Math.sqrt(d)) / 2);\n        pw.close();\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class B {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tlong n = sc.nextInt(), k = sc.nextInt();\n\t\t\n\t\t\n\t\tlong start = 1, end = n;\n\t\t\n\t\twhile(start <= end) {\n\t\t\tlong mid = (start + end) >> 1;\n\t\t\tif(calc(mid) - (n - mid) == k) {\n\t\t\t\tSystem.out.println(n - mid);\n\t\t\t\treturn;\n\t\t\t} else if (calc(mid) - (n - mid) > k) {\n\t\t\t\tend = mid - 1;\n\t\t\t} else {\n\t\t\t\tstart = mid + 1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static long calc(long n) {\n\t\treturn (n * n + n) / 2;\n\t}\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.nio.CharBuffer;\nimport java.util.NoSuchElementException;\n\npublic class P1195B {\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 k = scanner.nextInt();\n        int l = 0;\n        int r = n;\n        int ans = 0;\n        while (l <= r) {\n            int eat = (l + r) >> 1;\n            int lastPut = n - eat;\n            long totalPut = (long) (lastPut + 1) * lastPut / 2;\n            long remain = totalPut - eat;\n            if (remain == k) {\n                ans = eat;\n                break;\n            } else if (remain > k)\n                l = eat + 1;\n            else\n                r = eat - 1;\n        }\n        writer.println(ans);\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        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        void checkEof() {\n            if (eof)\n                throw new NoSuchElementException();\n        }\n\n        char nextChar() {\n            checkEof();\n            char b = read();\n            checkEof();\n            return b;\n        }\n\n        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        int nextInt() {\n            return Integer.valueOf(next());\n        }\n\n        long nextLong() {\n            return Long.valueOf(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class CodeForces {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\tint n = sc.nextInt();\n\tint k = sc.nextInt();\n        int ans = 0;\n        long x = n;\n        x = x*(x+1)/2;\n        while (x!=k) {\n            x-=n;\n            n--;\n            ans++;\n            k++;\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.ThreadLocalRandom;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class Main2 {\n\n    static int mod = 1000000007;\n    static FastScanner scanner;\n\n    public static void main(String[] args) {\n        scanner = new FastScanner();\n        long n = scanner.nextInt();\n        long k = scanner.nextInt();\n\n        if (sum(n) == k) {\n            System.out.println(0);\n            return;\n        }\n\n        long s = 0;\n        long e = n + 1;\n        while (s < e - 1) {\n            long m = (s + e) / 2;\n            long put = sum(n - m);\n            long candiesLeft = put - m;\n            if (candiesLeft == k) {\n                System.out.println(m);\n                return;\n            }\n            if (candiesLeft > k) {\n                s = m;\n            } else {\n                e = m;\n            }\n        }\n    }\n\n    static long sum(long n) {\n        long last = 1 + n - 1;\n        return ((1 + last) * n) / 2;\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "/*\nRoses are red\nMemes are neat\nAll my test cases time out\nLmao yeet\n*/\nimport java.util.*;\nimport java.io.*;\n\n   public class B\n   {\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 K = Integer.parseInt(st.nextToken());\n         //bin search\n         //ugh I'm shafting\n         long x = (long)N;\n         long low = 0L;\n         long high = N;\n         while(low != high)\n         {\n            x = (low+high+1)/2;\n            long add = (x*(x+1))/2;\n            long y = N-x;\n            if(add-y > K)\n               high = x;\n            else if(add-y == K)\n            {\n               System.out.println(y);\n               break;\n            }\n            else\n               low = x;\n         }\n         //run time?\n      }\n      public static void sort(int[] arr)\n      {\n         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();\n         for(int a: arr)\n            pq.add(a);\n         for(int i=0; i < arr.length; i++)\n            arr[i] = pq.poll();\n      }\n   }", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "    import java.util.*;\n    import java.io.*;\n    import java.lang.*;\n    import java.math.*;\n    public class D {\n        public static void main(String[] args) throws Exception {\n            BufferedReader bf = new BufferedReader(new InputStreamReader(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 n = Integer.parseInt(st.nextToken());\n            int k = Integer.parseInt(st.nextToken());\n            \n            for(int i=0; i<100000; i++) {\n              long mult = 1L*i*(i+1)/2;\n              long b = 1L*mult - k;\n              if(i+b == n*1L) {\n                out.println(b);\n                out.close(); System.exit(0);\n              }\n            }\n            //out.println(count);\n            out.close(); System.exit(0);\n        }\n    }\n\n    // a(a+1)/2 - b = k;   a+b = n   ", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Random;\n\n\npublic class CFContest {\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\n        public void solve() {\n            int n = io.readInt();\n            int k = io.readInt();\n            int l = 0;\n            int r = n;\n            while (l < r) {\n                int m = (l + r + 1) >> 1;\n                if (when(n, m) < k) {\n                    r = m - 1;\n                } else {\n                    l = m;\n                }\n            }\n\n            io.cache.append(l);\n        }\n\n        public long when(int n, int t) {\n            long put = n - t;\n            return (put + 1) * put / 2 - t;\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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n    public static void main(String[] args) {\n        new Thread(null, new Main(), \"Check2\", 1 << 28).start();// to increse stack size in java\n    }\n    static long mod = (long) (1e9 + 7);\n    public void run() {\n        InputReader in = new InputReader(System.in);\n        PrintWriter w = new PrintWriter(System.out);\n\n\n        long  n = in.nextLong();\n        long k = in.nextLong();\n        long ans= 0;\n        for (long i=1;i<=Math.min(100000,n);i++){\n            long left = i;\n            long right = n-i;\n            long sum = left * (left + 1);\n            sum /= 2;\n            if (sum - right ==k){\n                ans = right;\n            }\n        }\n        w.println(ans);\n\n        w.close();\n    }\n    void debug(Object...args) {\n        System.out.println(Arrays.deepToString(args));\n    }\n    static class pair implements Comparable<pair>{\n\n        int a;\n        int b;\n\n        pair(int a,int b){\n            this.a = a;\n            this.b = b;\n        }\n        public int compareTo(pair o){\n            if(this.b != o.b)return this.b - o.b;\n            return this.a - o.a;\n        }\n\n    }\n    long modinv(long a,long b) {\n        long p=power(b,mod-2,mod);\n\n        p=a%mod*p%mod;\n        p%=mod;\n\n        return p;\n\n    }\n    long power(long x,long y,long mod){\n        if(y==0)return 1%mod;\n        if(y==1)return x%mod;\n        long res=1;\n        x=x%mod;\n        while(y>0)\n        {\n            if((y%2)!=0){\n                res=(res*x)%mod;\n            }\n            y=y/2;\n            x=(x*x)%mod;\n        }\n        return res;\n    }\n    long gcd(long a,long b){\n\n        if(b==0)return a;\n        return gcd(b,a%b);\n    }\n    void sev(int a[],int n){\n\n        for(int i=2;i<=n;i++)a[i]=i;\n        for(int i=2;i<=n;i++){\n\n            if(a[i]!=0){\n                for(int j=2*i;j<=n;){\n\n                    a[j]=0;\n                    j=j+i;\n                }\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                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 stock = \"\";\n            try\n            {\n                stock = br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return stock;\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Cf2 {\n\n    static boolean ok(long n, long k, long eatten) {\n        long moves = n-eatten;\n        long ans = moves*(moves+1)/2;\n        ans -= eatten;\n        return ans <= k;\n    }\n\n    public static void main(String[] args) {\n        FastReader in = new FastReader();\n        long n = in.nextInt();\n        long k = in.nextInt();\n        long left = 0, right = n;\n        while (left <= right) {\n            long middle = (left+right)/2;\n            if (ok(n, k, middle)) right = middle-1;\n            else left=middle+1;\n        }\n        System.out.println(left);\n    }\n\n    static class FastReader\n    {\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        {\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class SportMafia {\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 k = sc.nextInt();\n\t\t\n\t\tint next = 1;\n\t\tint current = 0;\n\t\tint result = 0;\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(current < k) {\n\t\t\t\tcurrent += next++;\n\t\t\t} else {\n\t\t\t\tcurrent--;\n\t\t\t\tresult++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(result);\n\t\t\n\t\tsc.close();\n\t}\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class algo_1802\n{\n    public static void main(String args[])\n    {\n        Scanner ex=new Scanner(System.in);\n        int n=ex.nextInt();\n        int k=ex.nextInt();\n        int x=(int)((Math.sqrt(9.0+8.0*((double)n+(double)k))-3.0)/2.0);\n        System.out.println(n-x);\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tFastReader reader = new FastReader();\n\t\tPrintWriter writer = new PrintWriter(System.out);\n\n\t\tlong n = reader.nextLong();\n\t\tlong k = reader.nextLong();\n\n\t\tlong s=0;\n\t\tlong e=n;\n\n\t\tlong ans = -1;\n\t\twhile (s<=e) {\n\t\t\tlong m = (s+e)/2;\n\t\t\tlong temp = ((n-m)*(n-m+1))/2 - m;\n\n\t\t\tif (temp < k) \n\t\t\t\te = m-1;\n\t\t\telse if (temp > k)\n\t\t\t\ts = m+1;\n\t\t\telse {\n\t\t\t\tans = m;\n\t\t\t\tbreak;\n\t\t\t} \n\t\t}\n\n\t\twriter.println(ans);\n\t\twriter.close();\n\t}\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 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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class B {\n\n    public void solve() throws IOException {\n        long n = nextInt(), k = nextInt();\n        long c = 2 * (n + k);\n        long l = -1, r = 200000;\n        while (r - l > 1) {\n            long m = l + (r - l) / 2;\n            if (m * m + 3 * m >= c) {\n                r = m;\n            } else {\n                l = m;\n            }\n        }\n        out.print(n - r);\n    }\n\n    public void run() {\n        try {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n\n            solve();\n\n            out.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    BufferedReader br;\n    StringTokenizer in;\n    PrintWriter out;\n\n    public String nextToken() throws IOException {\n        while (in == null || !in.hasMoreTokens()) {\n            in = new StringTokenizer(br.readLine());\n        }\n        return in.nextToken();\n    }\n\n    public int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    public long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public int[] nextArr(int n) throws IOException {\n        int[] res = new int[n];\n        for (int i = 0; i < n; i++) {\n            res[i] = nextInt();\n        }\n        return res;\n    }\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        new B().run();\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "// Created by Whiplash99\nimport java.io.*;\nimport java.util.*;\npublic class A\n{\n    public static void main(String[] args) throws IOException\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n        long N,K,tmp,ans=0;\n\n        String s[]=br.readLine().trim().split(\" \");\n        N=Long.parseLong(s[0]);\n        K=Long.parseLong(s[1]);\n\n        long l=1,r=N,mid;\n\n        while(l<=r)\n        {\n            mid=(l+r)/2;\n\n            tmp=mid*(mid+1)/2;\n            tmp-=N;\n            tmp+=mid;\n\n            if(tmp==K)\n            {\n                ans=N-mid;\n                break;\n            }\n            else if(tmp>K)\n                r=mid-1;\n            else\n                l=mid+1;\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\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        long disc = (long)(Math.sqrt(9 - 4 * (-2 * n - 2 * k)));\n        long x = (-3 + disc) / 2;\n        System.out.println(n - x);\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());\n        int n = Integer.parseInt(tokenizer.nextToken());\n        int k = Integer.parseInt(tokenizer.nextToken());\n        System.out.println((int)(n-(-3.0+Math.sqrt(9.0+8.0*(n+k)))/2.0));\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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 cunbidun\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        BSportMafia solver = new BSportMafia();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BSportMafia {\n        private InputReader in;\n        private OutputWriter out;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            this.in = in;\n            this.out = out;\n            long n = in.nextInt();\n            long k = in.nextInt();\n            for (long i = 1; i * (i + 1) / 2 + i <= n + k; i++) {\n                if (i * (i + 1) / 2 + i == n + k) {\n                    out.println(n - i);\n                    return;\n                }\n            }\n        }\n\n    }\n\n    static class InputReader extends InputStream {\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            }\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            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        private static boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter out;\n\n        public OutputWriter(OutputStream outputStream) {\n            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.out = new PrintWriter(writer);\n        }\n\n        public void close() {\n            out.close();\n        }\n\n        public void println(long i) {\n            out.println(i);\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Codeforces {\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    public static void main(String[] args) {\n        FastReader input = new FastReader();\n        long n = input.nextLong();\n        long K = input.nextLong();\n        long root = (long) Math.sqrt(8 * (K+n) + 9);\n        if (root * root != 8 * (K+n) + 9){\n            root++;\n            if (root * root != 8 * (K+n) + 9) root -= 2;\n        }\n        System.out.println(n - (root - 3) / 2);\n        \n        \n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Comparator.*;\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    private void solve() throws IOException {\n        solveB();\n    }\n\n    private void solveA() throws IOException {\n        int n = in.nextInt(), k = in.nextInt();\n        int[] cnt = new int[k];\n        for (int i = 0; i < n; i++)\n            cnt[in.nextInt() - 1] ^= 1;\n        int ans = 0;\n        for (int i = 0; i < k; i++)\n            ans += cnt[i];\n        out.println(n - ans + (ans + 1) / 2);\n    }\n\n    private void solveB() throws IOException {\n        long n = in.nextLong();\n        long c = (n + in.nextLong()) * 2;\n        long l = 0, r = (long) 1e9;\n        while (l + 1 < r) {\n            long m = (l + r) / 2;\n            if (m * m + 3 * m >= c)\n                r = m;\n            else\n                l = m;\n        }\n        out.println(n-r);\n    }\n\n    private void solveC() throws IOException {\n    }\n\n    private void solveD() throws IOException {\n    }\n\n    private void solveE() throws IOException {\n    }\n\n    class FastScanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        FastScanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        String next() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n\n        boolean hasNext() throws IOException {\n            return br.ready() || (st != null && st.hasMoreTokens());\n        }\n\n        int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n\n        boolean hasNextLine() throws IOException {\n            return br.ready();\n        }\n    }\n\n    private void run() throws IOException {\n        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(\".in\"));\n        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(\".out\"));\n\n        for (int t = 1; t-- > 0; )\n            solve();\n\n        out.flush();\n        out.close();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\n\npublic class Main {\n\n\n\n\n    public static void main(String[] args) throws IOException {\n\n        InputStreamReader r = new InputStreamReader(System.in);\n        BufferedReader f = new BufferedReader(r);\n\n        Scanner sc = new Scanner(System.in);\n        long n=sc.nextLong();\n        long m=sc.nextLong();\n        long sum=0;\n        if(n==1){\n\n        }else {\n            for (long i = 1; i <= n; i++) {\n                sum += i;\n                if (sum - (n - i) == m) {\n                    sum = n - i;\n                    break;\n                }\n            }\n        }\n        System.out.println(sum);\n\n\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class l {\n    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    static int mod = (int) (1e9 + 7);\n    // static int n;\n    static StringBuilder sol;\n\n    static class pair implements Comparable<pair> {\n        int left, type;\n        double w;\n        public pair(int x, double y) {\n            left = x;\n            w = y;\n            type= 0;\n        }\n\n        public int compareTo(pair o) {\n            return Double.compare(w,o.w);\n        }\n\n        public String toString() {\n            return left + \" \" + w;\n        }\n    }\n\n    static class tri implements Comparable<tri> {\n        int st, end,len, side;\n\n        tri(int a, int b, int c,int d) {\n            st = a;\n            end = b;\n            len = c;\n            side=d;\n        }\n\n        public int compareTo(tri o) {\n            if (st == o.st) return end - o.end;\n            return st - o.st;\n        }\n\n        public String toString() {\n            return st + \" \" + end ;\n        }\n    }\n\n\n    static ArrayList<pair>[]adj;\n\n\n    static int n;\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        //FileWriter f = new FileWriter(\"C:\\\\Users\\\\Ibrahim\\\\out.txt\");\n        PrintWriter pw = new PrintWriter(System.out);\n        int n = sc.nextInt();\n        int k = sc.nextInt();\n        int lo=0;\n        int hi=n;\n        int ans=0;\n        while (lo<=hi){\n            int mid=lo+hi>>1;\n            long rem= n-mid;\n            rem*=(rem+1);\n            rem/=2;\n            rem-=mid;\n            //pw.println(rem+\" \"+mid+\" \"+k);\n            if (rem==k){\n                ans=mid;\n                break;\n            }\n            else if (rem>k){\n                lo=mid+1;\n            }\n            else hi=mid-1;\n        }\n        pw.println(ans);\n        pw.flush();\n    }\n    static long gcd(long a ,long b){\n        if (a==0)return b;\n        return gcd(b%a,a);\n    }\n\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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "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 Xinyi Tao\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        TaskBR574D2 solver = new TaskBR574D2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskBR574D2 {\n        public void solve(int testNumber, Scanner in, PrintWriter out) {\n            long n = in.nextLong();\n            long k = in.nextLong();\n            long r = (long) (Math.sqrt(9 + 8 * (n + k)) - 3) / 2;\n            out.println(n - r);\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\n\timport java.io.IOException;\n\timport java.io.InputStream;\n\timport java.io.OutputStream;\n\timport java.io.OutputStreamWriter;\n\timport java.io.PrintWriter;\n\timport java.io.Writer;\n\timport java.util.Arrays;\n\timport java.util.InputMismatchException;\n\timport java.util.*;\n\timport java.io.*;\n\timport java.math.*;\n\tpublic class Main7{\n\n\tstatic class Pair\n\t\t{ \n\t\t\tint x;\n\t\t\tint y;\n\t\t\tpublic Pair(int x,int y) \n\t\t\t{\t \n\t\t\t\tthis.x= x; \n\t\t\t\tthis.y= y;\n\t\t\t}\t \n\t\t\t\n\t\t\t@Override\n\t\t\t\t\tpublic int hashCode() \n\t\t\t\t\t{ \n\t\t\t\t\t\tfinal int temp = 14; \n\t\t\t\t\t\tint ans = 1; \n\t\t\t\t\t\tans =x*31+y*13; \n\t\t\t\t\t\treturn ans; \n\t\t\t\t\t} \n\t\t\t  \n\t\t\t\t\t// Equal objects must produce the same \n\t\t\t\t\t// hash code as long as they are equal \n\t\t\t\t@Override\n\t\t\t\tpublic boolean equals(Object o) \n\t\t\t\t{ \n\t\t\t\t\tif (this == o) { \n\t\t\t\t\t\treturn true; \n\t\t\t\t\t} \n\t\t\t\t\tif (o == null) { \n\t\t\t\t\t\treturn false; \n\t\t\t\t\t} \n\t\t\t\t\tif (this.getClass() != o.getClass()) { \n\t\t\t\t\t\treturn false; \n\t\t\t\t\t} \n\t\t\t\t\tPair other = (Pair)o; \n\t\t\t\t\tif (this.x != other.x || this.y!=other.y) { \n\t\t\t\t\t\treturn false; \n\t\t\t\t\t} \n\t\t\t\t\treturn true; \n\t\t\t\t} \n\t\t\t\t\t\n\t\t} \n\t\tstatic class Pair1\n\t\t{\n\t\t\tString x;\n\t\t\tint y;\n\t\t\tint z;\n\t\t\t\n\t\t}\n\t\tstatic class Compare\n\t\t{ \n\t\t\t/*static void compare(Pair arr[], int n) \n\t\t\t{ \n\t\t\t\t// Comparator to sort the pair according to second element \n\t\t\t\tArrays.sort(arr, new Comparator<Pair>() { \n\t\t\t\t\t@Override public int compare(Pair p1, Pair p2) \n\t\t\t\t\t{ \n\t\t\t\t\t\tif(p1.start>p2.start)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(p1.start==p2.start)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn 0;\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\treturn -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\t*/\n\t\t}\n\t\t\n\t\t\n\t\tpublic static long pow(long a, long b)\n\t\t{\n\t\t\tlong result=1;\n\t\t\twhile(b>0)\n\t\t\t{\n\t\t\t\tif (b % 2 != 0)\n\t\t\t\t{\n\t\t\t\t\tresult=(result*a)%mod;\n\t\t\t\t\tb--;\n\t\t\t\t} \n\t\t\t\ta=(a*a)%mod;\n\t\t\t\tb /= 2;\n\t\t\t}   \n\t\t\treturn result;\n\t\t}\n\t\tpublic static long fact(long num)\n\t\t{\n\t\t\t\t\tlong value=1;\n\t\t\t\t\tint i=0;\n\t\t\t\t\tfor(i=2;i<num;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue=((value%mod)*i%mod)%mod;\n\t\t\t\t\t}\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t\tpublic static int gcd(int a, int b)\n\t\t\t\t{\n\t\t\t\t\tif (a == 0)\n\t\t\t\t\t\treturn b;\n\t\t\t\t\treturn gcd(b%a, a);\n\t\t\t\t}\n\t\t\t\t\n\t\t/*\t\tpublic static long lcm(long a,long b)\n\t\t\t\t{\n\t\t\t\t\treturn a * (b / gcd(a, b));\n\t\t\t\t}\n\t\t\t*/\tpublic static long sum(int h)\n\t\t\t\t{\n\t\t\t\t\treturn (h*(h+1)/2);\n\t\t\t\t}\n\t\t\t\t/*public static void dfs(int parent,boolean[] visited)\n\t\t\t\t{\n\t\t\t\t\tTreeSet<Integer> arr=new TreeSet<Integer>();\n\t\t\t\t\tarr=graph.get(parent);\n\t\t\t\t\tvisited[parent]=true;\n\t\t\t\t\tif(a[parent]==1)\n\t\t\t\t\t{\n\t\t\t\t\t\tflag=1;\n\t\t\t\t\t}\n\t\t\t\t\tif(a[parent]==2)\n\t\t\t\t\t{\n\t\t\t\t\t\tflag1=1;\n\t\t\t\t\t}\n\t\t\t\t\tif(flag==1 && flag1==1)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tIterator itr=arr.iterator();\n\t\t\t\t\twhile(itr.hasNext())\n\t\t\t\t\t{\n\t\t\t\t\t\tint num=(int)itr.next();\n\t\t\t\t\t\tif(visited[num]==false)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdfs(num,visited);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tx1x`\n\t\t\t\t}*/\n\t\t\t//\tstatic int flag1=0;\n\t\t\t\tstatic int[] dis;\n\t\t\t\tstatic int mod=1000000007;\n\t\t\t\tstatic ArrayList<ArrayList<Integer>> graph;\n\t\t\t\t\n\t\t\t\tpublic static void bfs(int num,int size)\n\t\t\t\t{\n\t\t\t\t\tboolean[] visited=new boolean[size+1];\n\t\t\t\t\tQueue<Integer> q=new LinkedList<>();\n\t\t\t\t\tq.add(num);\n\t\t\t\t\tans[num]=1;\n\t\t\t\t\tvisited[num]=true;\n\t\t\t\t\twhile(!q.isEmpty())\n\t\t\t\t\t{\n\t\t\t\t\t\tint x=q.poll();\n\t\t\t\t\t\tArrayList<Integer> al=graph.get(x);\n\t\t\t\t\t\tfor(int i=0;i<al.size();i++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint y=al.get(i);\t\n\t\t\t\t\t\t\tif(visited[y]==false)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tq.add(y);\n\t\t\t\t\t\t\t\tans[y]=ans[x]+1;\n\t\t\t\t\t\t\t\tvisited[y]=true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstatic int[] ans;\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t//\tstatic int[] a;\t\t\t  \n\t\t\t\t\n\t\t\t\tpublic static int[] sort(int[] a)\n\t\t\t\t{\n\t\t\t\t\tint n=a.length;\n\t\t\t\t\tArrayList<Integer> ar=new ArrayList<>();\n\t\t\t\t\tfor(int i=0;i<a.length;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tar.add(a[i]);\n\t\t\t\t\t}\n\t\t\t\t\tCollections.sort(ar);\n\t\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\ta[i]=ar.get(i);\n\t\t\t\t\t}\n\t\t\t\t\treturn a;\n\t\t\t\t}\n\t\t\t//\tstatic int flag=1;\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\tstatic public void main(String args[])throws IOException\n\t\t\t\t{\n\t\t//\t\t    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t/*\tboolean[] prime=new boolean[1000001];\n\t\t\t\t\tfor(int i=2;i*i<=1000000;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(prime[i]==false)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor(int j=2*i;j<=1000000;j+=i)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tprime[j]=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\t*/\n\t\t\t\t\tint n=i();\n\t\t\t\t\tint k=i();\n\t\t\t\t\tlong low=0;\n\t\t\t\t\tlong high=k;\n\t\t\t\t\tlong fin=0;\n\t\t\t\t\tlong ans=0;\n\t\t\t\t\tfor(int i=1;i<=n;i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tans+=i;\n\t\t\t\t\t\tif(Math.abs(ans-k)+i==n && ans>=k)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfin=Math.abs(ans-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\tpln(fin+\"\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t/**/\n\t\t\t\tstatic InputReader in=new InputReader(System.in);\n\t\t\t\t\tstatic OutputWriter out=new OutputWriter(System.out);\n\t\t\t\t\tpublic static long l()\n\t\t\t\t\t{\n\t\t\t\t\t\tString s=in.String();\n\t\t\t\t\t\treturn Long.parseLong(s);\n\t\t\t\t\t}\n\t\t\t\t\tpublic static void pln(String value)\n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.println(value);\n\t\t\t\t\t}\n\t\t\t\t\tpublic static int i()\n\t\t\t\t\t{\n\t\t\t\t\t\treturn in.Int();\n\t\t\t\t\t}\n\t\t\t\t\tpublic static String s()\n\t\t\t\t\t{\n\t\t\t\t\t\treturn in.String();\n\t\t\t\t\t}\n\t\t}\n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\tclass InputReader {\n\t\t\t\t \n\t\t\t\tprivate InputStream stream;\n\t\t\t\tprivate byte[] buf = new byte[1024];\n\t\t\t\tprivate int curChar;\n\t\t\t\tprivate int numChars;\n\t\t\t\tprivate SpaceCharFilter filter;\n\t\t\t \n\t\t\t\tpublic InputReader(InputStream stream) {\n\t\t\t\t\tthis.stream = stream;\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic int read() {\n\t\t\t\t\tif (numChars== -1)\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tif (curChar >= numChars) {\n\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (numChars <= 0)\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic int Int() {\n\t\t\t\t\tint c = read();\n\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\tc = read();\n\t\t\t\t\tint sgn = 1;\n\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = read();\n\t\t\t\t\t}\n\t\t\t\t\tint res = 0;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\tc = read();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res * sgn;\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic String String() {\n\t\t\t\t\tint c = read();\n\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\tc = read();\n\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\tdo {\n\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\tc = read();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res.toString();\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic boolean isSpaceChar(int c) {\n\t\t\t\t\tif (filter != null)\n\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic String next() {\n\t\t\t\t\treturn String();\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic interface SpaceCharFilter {\n\t\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t\t}\n\t\t\t}\n\t\t\t \n\t\t\tclass OutputWriter {\n\t\t\t\tprivate final PrintWriter writer;\n\t\t\t \n\t\t\t\tpublic OutputWriter(OutputStream outputStream) {\n\t\t\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic OutputWriter(Writer writer) {\n\t\t\t\t\tthis.writer = new PrintWriter(writer);\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic void print(Object...objects) {\n\t\t\t\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\t\t\t\tif (i != 0)\n\t\t\t\t\t\t\twriter.print(' ');\n\t\t\t\t\t\twriter.print(objects[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic void printLine(Object...objects) {\n\t\t\t\t\tprint(objects);\n\t\t\t\t\twriter.println();\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic void close() {\n\t\t\t\t\twriter.close();\n\t\t\t\t}\n\t\t\t \n\t\t\t\tpublic void flush() {\n\t\t\t\t\twriter.flush();\n\t\t\t\t}\n\t\t\t \n\t\t\t\t}\n\t\t\t \n\t\t\t\tclass IOUtils {\n\t\t\t \n\t\t\t\tpublic static int[] readIntArray(InputReader in, int size) {\n\t\t\t\t\tint[] array = new int[size];\n\t\t\t\t\tfor (int i = 0; i < size; i++)\n\t\t\t\t\t\tarray[i] = in.Int();\n\t\t\t\t\treturn array;\n\t\t\t\t}\n\t\t\t \n\t\t\t\t} ", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class B_574 {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String[] input = br.readLine().split(\" \");\n        int N = Integer.valueOf(input[0]);\n        int K = Integer.valueOf(input[1]);\n        long sum = 0;\n        for(int i = 0; i < N; i++){\n            if(sum - (N - i) == K){\n                System.out.println(Integer.valueOf(N-i));\n                return;\n            }\n            sum += (i+1);\n        }\n        System.out.println(\"0\");\n    }\n}\n", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class template {\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tlong left = 0;\n\t\tlong right = n;\n\t\tlong mid = left+right/2;\n\t\twhile(left<=right) {\n\t\t\tmid = (left+(right))/2;\n\t\t\tif(((mid+1)*mid)/2-(n-mid)==k) {\n\t\t\t\tpw.println(n-mid);\n\t\t\t\tpw.close();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if(((mid+1)*mid)/2-(n-mid)>k) {\n\t\t\t\tright = mid-1;\n\t\t\t}\n\t\t\telse left = mid+1;\n\t\t}\n\t}\n}\n@SuppressWarnings(\"all\")\nclass 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}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\npublic class Main{\n    static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n    static BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));\n    static Scanner sc=new Scanner(System.in);\n    static PrintWriter out=new PrintWriter(System.out);\n    //static InputReader sc=new InputReader(System.in);\n    static final int inf=10000000;\n    public static void main(String args[])throws Exception {\n        double n,k;\n        n=sc.nextDouble();\n        k=sc.nextDouble();\n        double ans=0;\n        ans=Math.sqrt(2.25+2*(n+k))-1.5;\n        System.out.printf(\"%.0f\\n\",n-ans);\n    }\n    static void ssort(int arr[]){\n        int len=arr.length;\n        for(int i=0;i<len;i++){\n            int t=(int)(len*Math.random());\n            int temp=arr[t];\n            arr[t]=arr[i];\n            arr[i]=temp;\n        }\n        Arrays.sort(arr);\n    }\n    static int getInt()throws Exception{\n        in.nextToken();\n        return  (int)in.nval;\n    }\n}\n\nclass 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\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/*\n\n\n\n\n */", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class B {\n    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n    static MyScanner sc;\n\n    static {\n        try {\n            sc = new MyScanner();\n        } catch (FileNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n\n    public static void main(String[] args) {\n        doTask();\n        out.flush();\n    }\n\n    public static void doTask(){\n        long n = sc.nextInt();\n        long k = sc.nextInt();\n        long c = -2*(n+k);\n        long d =  9 - 4*c;\n        double result = n - (-3 + Math.sqrt(1.0*d))/2;\n        out.println(Math.round(result));\n    }\n\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public MyScanner() throws FileNotFoundException {\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", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class B\n{\n\tstatic long sumN(long n)\n\t{\n\t\treturn n * (n + 1) / 2;\n\t}\n\n\tstatic int binSearchPuts(int n, int k)\n\t{\n\t\tint L = 1;\n\t\tint U = n;\n\t\tint M = (L + U) / 2;\n\n\t\twhile(L <= U)\n\t\t{\n\t\t\tlong left = sumN(M) - (n - M);\n\t\t\t\n\t\t\tif(left < k)\n\t\t\t{\n\t\t\t\tL = M + 1;\n\t\t\t}\n\t\t\telse if(left > k)\n\t\t\t{\n\t\t\t\tU = M;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tM = (L + U) / 2;\n\t\t}\n\n\t\treturn M;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner(System.in);\n\n\t\tint n = input.nextInt();\n\t\tint k = input.nextInt();\n\n\t\tlong ate = n - binSearchPuts(n, k);\n\t\tSystem.out.println(ate);\n\t}\n}", "complexity": "logn", "problem": "1195_B. Sport Mafia", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\nimport java.lang.management.*;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\nimport static java.lang.Math.sqrt;\nimport static java.lang.Integer.signum;\n\n@SuppressWarnings(\"unchecked\")\npublic class P1177B {\n\n  public void run() throws Exception {\n    for (long k = nextLong() - 1, d = 1, dc = 9, sv = 1; true; k -= dc, d++, sv *= 10, dc = sv * d * 9) {\n      if (k <= dc) {\n        println(Long.toString(sv + k / d).charAt((int)(k % d)));\n        break;\n      }\n    }\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 P1177B().run();\n    br.close();\n    pw.close();\n    System.err.println(\"\\n[Time : \" + (System.currentTimeMillis() - startTime) + \" ms]\");\n    long gct = 0, gcc = 0;\n    for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {\n      gct += garbageCollectorMXBean.getCollectionTime();\n      gcc += garbageCollectorMXBean.getCollectionCount();\n    }\n    System.err.println(\"[GC time : \" + gct + \" ms, count = \" + gcc + \"]\");\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 printsp(int [] a) { for (int i = 0, n = a.length; i < n; print(a[i] + \" \"), i++); }\n  void print(String s) { pw.print(s); }\n  void println() { println(\"\"); }\n  void println(byte b) { println(\"\" + b); }\n  void println(int i) { println(\"\" + i); }\n  void println(long l) { println(\"\" + l); }\n  void println(double d) { println(\"\" + d); }\n  void println(char c) { println(\"\" + c); }\n  void println(Object o) { print(o); println(); }\n  void println(String s) { pw.println(s); }\n  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n  long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n  char nextChar() throws IOException { return (char) (br.read()); }\n  String next() throws IOException { return nextToken(); }\n  String nextLine() throws IOException { return br.readLine(); }\n  int [] readInt(int size) throws IOException {\n    int [] array = new int [size];\n    for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n    return array;\n  }\n  long [] readLong(int size) throws IOException {\n    long [] array = new long [size];\n    for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n    return array;\n  }\n  double [] readDouble(int size) throws IOException {\n    double [] array = new double [size];\n    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n    return array;\n  }\n  String [] readLines(int size) throws IOException {\n    String [] array = new String [size];\n    for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n    return array;\n  }\n\n  int gcd(int a, int b) {\n    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n    a = Math.abs(a); b = Math.abs(b);\n    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);\n    a >>>= az; b >>>= bz;\n    while (a != b) {\n      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }\n            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }\n    }\n    return (a << Math.min(az, bz));\n  }\n\n  long gcd(long a, long b) {\n    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n    a = Math.abs(a); b = Math.abs(b);\n    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);\n    a >>>= az; b >>>= bz;\n    while (a != b) {\n      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }\n            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }\n    }\n    return (a << Math.min(az, bz));\n  }\n\n  void shuffle(int [] a) { // RANDOM shuffle\n    Random r = new Random();\n    for (int i = a.length - 1, j, t; i >= 0; j = r.nextInt(a.length), t = a[i], a[i] = a[j], a[j] = t, i--);\n  }\n\n  void shuffle(int [] a, int m) { // QUICK shuffle\n    for (int i = 0, n = a.length, j = m % n, t; i < n; t = a[i], a[i] = a[j], a[j] = t, i++, j = (i * m) % n);\n  }\n\n  void shuffle(long [] a) {\n    Random r = new Random();\n    for (int i = a.length - 1; i >= 0; i--) {\n      int j = r.nextInt(a.length);\n      long t = a[i]; a[i] = a[j]; a[j] = t;\n    }\n  }\n\n  void shuffle(Object [] a) {\n    Random r = new Random();\n    for (int i = a.length - 1; i >= 0; i--) {\n      int j = r.nextInt(a.length);\n      Object t = a[i]; a[i] = a[j]; a[j] = t;\n    }\n  }\n\n  int [] sort(int [] a) {\n    final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;\n    int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];\n    for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);\n    for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);\n    for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);\n    int [] t = a; a = ta; ta = t;\n    ai = new int [SIZE];\n    for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);\n    for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);\n    for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);\n    return ta;\n  }\n\n  void flush() {\n    pw.flush();\n  }\n\n  void pause() {\n    flush(); System.console().readLine();\n  }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        FastScanner in = new FastScanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        new Main().run(in, out);\n        out.close();\n    }\n\n    public static long mod = 17352642619633L;\n\n    void run(FastScanner in, PrintWriter out) {\n        // kth digit\n        long K = in.nextLong();\n\n        // which number encompasses the Kth digit\n\n        long lo = 1;\n        long hi = (long)1e12+1;\n\n        while (lo < hi) {\n            long m = (lo+hi)>>1;\n            long d = numDigitsLte(m);\n            if (d <= K) {\n                lo = m+1;\n            } else {\n                hi = m;\n            }\n        }\n\n        // 123[1]1391 = m digits\n        long numDigits = numDigitsLte(lo);\n        if (numDigitsLte(lo-1) == K) {\n            out.println((((lo-1)%10)+10)%10);\n        } else {\n            int offset = (int)(numDigits-K);\n\n            // out.print(lo + \" \");\n            List<Long> digits = new ArrayList<>();\n            while (lo > 0) {\n                digits.add(lo%10);\n                lo /= 10;\n            }\n            // backwards\n            // before : 1[2]3456\n            // in list: 6543[2]1\n            // offset = 4\n            out.println(digits.get(offset));\n\n        }\n    }\n\n    static long[] dig = new long[15];\n    static {\n        for (int i = 1; i < dig.length; i++) {\n            dig[i] = 9 * (long)Math.pow(10, i-1) * i;\n        }\n\n        for (int i = 1; i < dig.length; i++) {\n            dig[i] += dig[i-1];\n        }\n    }\n\n    long numDigitsLte(long m) {\n        if (m <= 9) return m;\n\n        int numDigits = 0;\n        long M = m;\n        while (M > 0) {\n            numDigits++;\n            M /= 10;\n        }\n\n        long ret = dig[numDigits-1];\n        ret += (m-(long)Math.pow(10, numDigits-1)+1)*numDigits;\n        return ret;\n\n        // digits below\n        // 9 + 90 + 900\n        // [1-9], [10-99], [100-999]\n        // 9, 90*2, 900*3, ...\n        // 9999..\n\n        // 9138\n        // [1-1000), [1000,9138]\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            st = null;\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}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class global{\n\tpublic static void main(String s[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\t\tlong n = sc.nextLong();\n\t\t\tString st = String.valueOf(n);\n\t\t\tif(st.length()==1){\n\t\t\t\tSystem.out.println(n);\n\t\t\t}else{\n\t\t\t\tlong val = 1;\n\t\t\t\tlong prev=9;\n\t\t\t\tlong total=9;\n\t\t\t\tlong late=9;\n\t\t\t\tfor(int i=2;i<=12;i++){\n\t\t\t\t\tval*=10;\n\t\t\t\t\t\n\t\t\t\t\ttotal+=i*(val*9);\n\t\t\t\t\tif(n<=total){\n\t\t\t\t\t\tlong diff = n-late;\n\t\t\t\t\t\tlong div = diff/i;\n\t\t\t\t\t\tlong mod = diff%i;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(mod==0){\n\t\t\t\t\t\t\tprev+=div;\n\t\t\t\t\t\t\tSystem.out.println((prev)%10);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tprev+=div+1;\n\t\t\t\t\t\t\tString fg = String.valueOf(prev);\n\t\t\t\t\t\t\tSystem.out.println(fg.charAt((int)mod-1));\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\tprev+=(9*val);\n\t\t\t\t\tlate=total;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\t\t\t\n\t\t\n\t\t}\n\t}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class P1177A {\n\n    public static void main(String[] args) throws FileNotFoundException {\n\n        Scanner in = new Scanner(System.in);\n        // Scanner in = new Scanner(new File(\"input.txt\"));\n        System.out.println(solve(in.nextLong()));\n\n    }\n\n    private static String solve(long k) {\n\n        long digitCnt = 1;\n        long nine = 9;\n\n        while (k > nine * digitCnt) {\n            k -= nine * digitCnt;\n            nine *= 10;\n            digitCnt++;\n        }\n\n        long num = nine / 9 - 1 + (k - 1) / digitCnt + 1;\n        return String.valueOf(String.valueOf(num).charAt((int) ((k - 1) % digitCnt)));\n\n    }\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Solution {\n    public static void main(String[] args) {\n        long b=0;long p=1;\n        Scanner s=new Scanner(System.in);\n        long m=s.nextLong();\n        long x=1;\n        do{\n            p=(m+b)/x;\n            b=10*b+10;\n            x++;\n        }while(p/(long)Math.pow(10, x-1)!=0);\n        rest :\n        x--;b=b/10-1;\n        b=x*p-b;\n        b=m-b;\n        b=x-b-1;\n        p/=(long)Math.pow(10, b);\n        p%=10;\n        System.out.println(p);\n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t    Scanner sc =new Scanner(System.in);\n\t    long n=sc.nextLong();\n\t    long x=1;\n\t    long ar=0;\n\t    tag:for(long i=1;;i++)\n\t    {\n\t        ar+=9*i*x;\n\t        if(ar>=n)\n\t        {\n\t            long d = n - (ar-9*i*x);\n\t            long ans = x+d/i;\n\t            long p=d%i;\n\t            if(p==0)\n\t            {\n\t                p=i;\n\t                ans--;\n\t            }\n\t            p=i-p;\n\t            p++;\n\t            long fns=0;\n\t            //System.out.println(ans);\n\t            while(p!=0)\n\t            {\n\t                fns=ans%10;\n\t                ans/=10;\n\t                p--;\n\t            }\n\t            System.out.println(fns);\n\t            \n\t            break tag;\n\t        }\n\t        x*=10;\n\t    }\n\t}\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "// Change Of Plans BABY.... Change Of Plans //\nimport java.io.*;\nimport java.util.*;\nimport java.util.Queue;\nimport static java.lang.Math.*;\n\npublic class digitSequence {\n\n    static void MainSolution() {\n        long k = nl() - 1;\n\n        for (int i = 1; ; i++) {\n            long temp=9L*i*fastPow(10,i-1);\n            if(k<temp){\n                long x=k/i;\n                long y=k%i;\n                long ans=(x+fastPow(10,i-1))/fastPow(10,i-y-1);\n                pl(ans%10);\n                break;\n            }\n            k-=temp;\n        }\n    }\n\n    static long fastPow(long b, long e) {\n        if (e == 0) return 1;\n        if ((e & 1) == 1) return b * fastPow(b, e >> 1) * fastPow(b, e >> 1);\n        return fastPow(b, e >> 1) * fastPow(b, e >> 1);\n    }\n\n    /*----------------------------------------------------------------------------------------------------------------*/\n    //THE DON'T CARE ZONE BEGINS HERE...\\\\\n    static int mod9 = 1_000_000_007;\n    static int n, m, l, k, t;\n    static AwesomeInput input = new AwesomeInput(System.in);\n    static PrintWriter pw = new PrintWriter(System.out, true);\n\n    // The Awesome Input Code is a fast IO method //\n    static class AwesomeInput {\n        private InputStream letsDoIT;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n\n        private AwesomeInput(InputStream incoming) {\n            this.letsDoIT = incoming;\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 = letsDoIT.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 long ForLong() {\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            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        private String ForString() {\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 interface SpaceCharFilter {\n            boolean isSpaceChar(int ch);\n        }\n    }\n\n    // functions to take input//\n    static int ni() {\n        return (int) input.ForLong();\n    }\n\n    static String ns() {\n        return input.ForString();\n    }\n\n    static long nl() {\n        return input.ForLong();\n    }\n\n    static double nd() throws IOException {\n        return Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine());\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    // Fast Sort is Radix Sort\n    public static int[] fastSort(int[] f) {\n        int n = f.length;\n        int[] to = new int[n];\n        {\n            int[] b = new int[65537];\n            for (int i = 0; i < n; i++) b[1 + (f[i] & 0xffff)]++;\n            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];\n            for (int i = 0; i < n; i++) to[b[f[i] & 0xffff]++] = f[i];\n            int[] d = f;\n            f = to;\n            to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for (int i = 0; i < n; i++) b[1 + (f[i] >>> 16)]++;\n            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];\n            for (int i = 0; i < n; i++) to[b[f[i] >>> 16]++] = f[i];\n            int[] d = f;\n            f = to;\n            to = d;\n        }\n        return f;\n    }\n\n    public static void main(String[] args) {      //threading has been used to increase the stack size.\n\n        new Thread(null, null, \"Vengeance\", 1 << 25)  //the last parameter is stack size desired.\n        {\n            public void run() {\n                try {\n                    double s = System.currentTimeMillis();\n                    MainSolution();\n                    //pl((\"\\nExecution Time : \" + ((double) System.currentTimeMillis() - s) / 1000) + \" s\");\n                    pw.flush();\n                    pw.close();\n                } catch (Exception e) {\n                    e.printStackTrace();\n                    System.exit(1);\n                }\n            }\n        }.start();\n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "/**\n * @(#)DigitSequence.java\n *\n *\n * @author\n * @version 1.00 2019/6/1\n */\nimport java.io.*;\nimport java.util.*;\npublic class DigitSequence {\n\n    /**\n     * Creates a new instance of <code>DigitSequence</code>.\n     */\n    public DigitSequence() {\n    }\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        long k=in.nextLong();\n        long[] end=new long[12];\n        end[0]=-1;\n        for (int i=1; i<end.length; i++) {\n        \tend[i]=(i*(long)(Math.pow(10,i)));\n        \tend[i]-=(((long)(Math.pow(10,i))-1)/9);\n        }\n        //System.out.println(Arrays.toString(end));\n        int st=0;//st=1 {0,9}; st=2 {10, 189}; st=3 {190-2889}; st=4 {2890-38889}\n       \tfor (int i=1; i<end.length; i++) {\n       \t\tif (k>=end[i-1]+1 && k<=end[i]) st=i;\n       \t}\n       \t//System.out.println(\"st \" + st);\n       \tlong diff=k-end[st-1];\n       \tlong mod=((diff+st-1)%st);\n       \t//System.out.println(mod);\n       \tlong digit=-1;\n\n       \tint addOn=0;\n       \tif (mod==0) addOn=1;\n       \tif (mod==st-1) addOn=-1;\n       \tdigit=(diff/(st*(long)(Math.pow(10,st-1-mod))));\n       \tdigit+=addOn;\n       \tdigit%=10;\n       \tSystem.out.println(digit);\n       \t//98888888889\n       \t//98888888879\n       \t//1088888888889\n       \t//1088888888878\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A1177 {\n    public static long exponential(long a, long b){\n        long result = 1;\n        for(int i=0;i<b;i++){\n            result *= a;\n        }\n        return result;\n    }\n    public static void main(String args[]){\n        Scanner scanner = new Scanner(System.in);\n        long  k = scanner.nextLong();\n        //int k =21;\n        long sum = 0;\n        long i=1;\n        while(true){\n            long interval = 9 * exponential(10,i-1) * i;\n            if(sum + interval >= k){\n                break;\n            } else {\n                i++;\n                sum += interval;\n            }\n        }\n        long t = k-sum;\n        long targetNumber = exponential(10, i-1) + (t-1)/i;\n        String s = \"\" + targetNumber;\n        int hedef = (int)((t-1)%i);\n        System.out.println(s.charAt(hedef));\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class P1177A {\n\t\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\ttry (Scanner sc = new Scanner(System.in)) {\n\t\t\t\n\t\t\tlong k = sc.nextLong();\n\t\t\tint pow = 1;\n\t\t\t\n\t\t\twhile ((long) ((Math.pow(10, pow) - Math.pow(10, pow - 1)) * pow) < k) {\n\t\t\t\tk -= (long) ((Math.pow(10, pow) - Math.pow(10, pow - 1)) * pow);\n\t\t\t\tpow++;\n\t\t\t}\n\t\t\t// System.out.println(k + \" \" + pow);\n\t\t\t\n\t\t\tk--;\n\t\t\tlong n = (long) Math.pow(10, pow - 1) + k / pow;\n\t\t\tk %= pow;\n\t\t\t// System.out.println(k + \" \" + n);\n\t\t\t\n\t\t\tSystem.out.println(String.valueOf(n).charAt((int) k));\n\t\t\t\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.math.BigInteger;\nimport java.util.*;\n  \npublic class Main {\n    public static void main(String[] args) throws IOException {\n        FastScanner sc=new FastScanner();\n        long K = sc.nextLong();\n        long nums = 9;\n        int digits = 1;\n        while (K > nums*digits) {\n        \tK -= nums*digits;\n        \tnums *= 10;\n        \tdigits++;\n        }\n        long removal = (K-1)/digits;\n        int pos = (int)((K-1)%digits);\n        long base = (long)Math.pow(10,digits-1);\n        String num = Long.toString(base+removal);\n        System.out.println(num.charAt(pos));\n    }\n    \n    static class FastScanner\n    { \n        BufferedReader br; \n        StringTokenizer st; \n  \n        public FastScanner() \n        { \n            br = new BufferedReader(new\n                     InputStreamReader(System.in)); \n        } \n  \n        String next() \n        { \n            while (st == null || !st.hasMoreElements()) \n            { \n                try\n                { \n                    st = new StringTokenizer(br.readLine()); \n                } \n                catch (IOException  e) \n                { \n                    e.printStackTrace(); \n                } \n            } \n            return st.nextToken(); \n        } \n  \n        int nextInt() \n        { \n            return Integer.parseInt(next()); \n        } \n  \n        long nextLong() \n        { \n            return Long.parseLong(next()); \n        } \n  \n        double nextDouble() \n        { \n            return Double.parseDouble(next()); \n        } \n  \n        String nextLine() \n        { \n            String str = \"\"; \n            try\n            { \n                str = br.readLine(); \n            } \n            catch (IOException e) \n            { \n                e.printStackTrace(); \n            } \n            return str; \n        } \n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n\npublic class Main {\n\n\tstatic class Task {\n\t\t\n\t\tint NN = 1000001;\n\t\tint MOD = 1000000007;\n\t\tint INF = 2000000000;\n\t\tlong INFINITY = 2000000000000000000L;\n\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tlong k = in.nextLong();\n\t\t\tfor(long mul = 1,d=1;;mul*=10,++d) {\n\t\t\t\tif(k > 9*mul*d) {\n\t\t\t\t\tk -= 9*mul*d;\n\t\t\t\t} else {\n\t\t\t\t\tfor(long i=1;i<=9;++i) {\n\t\t\t\t\t\tif(k > mul*d) {\n\t\t\t\t\t\t\tk -= mul*d;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t--k;\n\t\t\t\t\t\t\tlong num = k / d;\n\t\t\t\t\t\t\tk %= d;\n\t\t\t\t\t\t\tString str = String.valueOf(num);\n\t\t\t\t\t\t\twhile(str.length() < d - 1) {\n\t\t\t\t\t\t\t\tstr = \"0\" + str;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tstr = String.valueOf(i) + str;\n\t\t\t\t\t\t\tout.println(str.charAt((int) k));return;\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}\n\t\n\tstatic void prepareIO(boolean isFileIO) {\n\t\t//long t1 = System.currentTimeMillis();\n\t\tTask solver = new Task();\n\t\t// Standard IO\n\t\tif(!isFileIO) { \n\t\t\tInputStream inputStream = System.in;\n\t        OutputStream outputStream = System.out;\n\t        InputReader in = new InputReader(inputStream);\n\t        PrintWriter out = new PrintWriter(outputStream);\n\t        solver.solve(in, out);\n\t        //out.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        out.close();\n\t\t}\n        // File IO\n\t\telse {\n\t\t\tString IPfilePath = System.getProperty(\"user.home\") + \"/Downloads/ip.in\";\n\t        String OPfilePath = System.getProperty(\"user.home\") + \"/Downloads/op.out\";\n\t        InputReader fin = new InputReader(IPfilePath);\n\t        PrintWriter fout = null;\n\t        try {\n\t\t\t\tfout = new PrintWriter(new File(OPfilePath));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t        solver.solve(fin, fout);\n\t        //fout.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        fout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n        prepareIO(false);\n\t}\n\t\n\tstatic class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n        \n        public InputReader(String filePath) {\n        \tFile file = new File(filePath);\n            try {\n\t\t\t\treader = new BufferedReader(new FileReader(file));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n            tokenizer = null;\n        }\n        \n        public String nextLine() {\n        \tString str = \"\";\n        \ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n        \treturn str;\n        }\n        \n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n        \treturn Double.parseDouble(next());\n        }\n        \n    }\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n    static class LeftOver {\n        int a;\n        long b;\n        long c;\n        LeftOver(int a, long b, long c) {\n            this.a = a;\n            this.b = b;\n            this.c = c;\n        }\n    }\n\n    private static long pow(long base, long coe) {\n        if (coe == 0)\n            return 1;\n        if (coe == 1)\n            return base;\n        long res = pow(base, coe / 2);\n        if (coe % 2 == 0) {\n            return res * res;\n        } else {\n            return res * res * base;\n        }\n    }\n\n    private static void getLen(long n) {\n        long tmp = 0;\n        int cnt = 0;\n        while(tmp < n) {\n            ++cnt;\n            tmp += cnt * 9 * pow(10, cnt - 1);\n        }\n        if (tmp == n)\n            System.out.println(\"9\");\n        else {\n            tmp -= cnt * 9 * pow(10, cnt - 1);\n            long ans = (n - tmp - 1) / cnt + pow(10, cnt - 1);\n            System.out.println(String.valueOf(ans).charAt((int) ((n - tmp - 1) % cnt)));\n        }\n    }\n\n\n    public static void main(String[] args) {\n\n        Scanner sc = new Scanner(System.in);\n\n        long n = sc.nextLong();\n\n        getLen(n);\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class BDigitSequence {\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        long k = scan.nextLong();\n\n        long digits = 1;\n        long counter = 9L;\n\n        while(k > counter * digits) {\n            k -= counter * digits;\n            counter *= 10;\n            digits++;\n        }\n\n        long num = (long)(Math.ceil((double)k/digits));\n        String s = String.valueOf((long)Math.pow(10,digits-1) - 1 + num );\n\n        System.out.println(s.charAt((int)((k+digits-1)%digits)));\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class digits {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        long k = Long.parseLong(br.readLine());\n        long temp = 9 * (int)Math.pow(10,0);\n        int count = 0;\n        long initial = 0;\n        while(k > temp) {\n            count++;\n            initial = temp;\n            temp += 9 * (long)Math.pow(10,count)*(count+1);\n        }\n        long index = (k-initial-1)%(count+1);\n        long num = (long)Math.pow(10,count) + (k-initial-1)/(count+1);\n        System.out.println((num+\"\").charAt((int)index));\n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\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 t = 1;\n        long l = 1;\n        if(k <= 9) {\n            System.out.print(k);\n            System.exit(0);\n        }\n        long x = 9;\n        while(true) {\n            ++l;\n            t *= 10;\n            x += 9 * l * t;\n            if(x >= k) {\n                break;\n            }\n        }\n        if(x == k) {\n            System.out.print(9);\n            System.exit(0);\n        }\n        x -= 9 * l * t;\n        long a = (k - x) / l;\n        if((k - x) % l == 0) {\n            x = t + a - 1;\n            System.out.print(x % 10);\n        } else {\n            k -= (x + a * l);\n            x = t + a;\n            String s = Long.toString(x);\n            System.out.print(s.charAt((int)k - 1));\n        }\n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.util.*;\n\npublic class Main {\n  static int len(long n) {\n    int res = 0;\n    while (n > 0) {\n      n /= 10;\n      res++;\n    }\n    return res;\n  }\n  static long big(int len) {\n    long p = 1;\n    while (len-- > 0) p *= 10;\n    return p - 1;\n  }\n  static long small(int len) {\n    return big(len - 1) + 1;\n  }\n  static long cnt(long n) {\n    int len = len(n);\n    long cnt = 0;\n    for (int l = 1; l < len; l++)\n      cnt += 1l * l * (big(l) - small(l) + 1);\n    cnt += 1l * len * (n - small(len));\n    return cnt;\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\n    long k = sc.nextLong();\n    if (k == 1) {\n      System.out.println(1);\n      return;\n    }\n    long lo = 1, hi = k, res = 1;\n    while(lo <= hi) {\n      long mid = lo + hi >> 1L;\n      if(cnt(mid) < k) {\n        res = mid;\n        lo = mid + 1;\n      } else {\n        hi = mid - 1;\n      }\n    }\n\n    ArrayList<Integer> digits = new ArrayList<>();\n    long tmp = res;\n    while (tmp > 0) {\n      digits.add((int)(tmp % 10));\n      tmp /= 10;\n    }\n//    System.err.println(\"RES \" + res);\n//    System.err.println(\"DIGITS \" + digits);\n//    System.err.println(\"Cnt Res \" + cnt(res));\n    Collections.reverse(digits);\n    out.println(digits.get((int)(k - cnt(res) - 1)));\n    out.flush();\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() 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", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class DigitsSequence2 {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        long index = scanner.nextLong();\n        solution1(index);\n\n    }\n\n    static void solution1(Long index){\n        int i = 1;  // group number\n        long len = 9;    // the max length\n        long max = 9;    // the max integer\n        while(len < index){\n            long tmp = 9 * (long) Math.pow(10, i);\n            i++;\n            len += i * tmp;\n            max += tmp;\n        }\n        long diff = len - index; // the digit number between index and len\n        long laterCount = diff / i;  // the number after index\n        int remainder = (int) (diff % i);\n        long current = max - laterCount; // the number of the index\n        int k = i - 1 - remainder;\n        System.out.println(String.valueOf(current).charAt(k));\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class _v14 {\n\n    public static void main(String args[]){\n\n        PrintWriter out = new PrintWriter(System.out);\n        Reader in = new Reader();\n        long k = in.nextLong();\n        if(k<10){\n            System.out.println(k);\n            return;\n        }\n        long sum = 0;\n        long cur = 9;\n        long prev = 0;\n        int count = 1;\n        while(k>cur){\n            k= k - cur;\n            sum  = sum + cur/count;\n            prev = cur;\n            cur = 9*(count+1)*(long)Math.pow(10,count);\n            count++;\n        }\n\n        long num = k/(count);\n        sum = sum + num;\n\n        if(k%count == 0){\n            System.out.println(sum%10);\n        }\n        else{\n            sum++;\n            k = k%(count);\n            String str = String.valueOf(sum);\n            System.out.println(str.charAt((int)k-1));\n        }\n\n\n\n\n\n\n        out.flush();\n        out.close();\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\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.Queue;\nimport java.util.LinkedList;\nimport java.util.Stack;\n\npublic class Main\n{\n      @SuppressWarnings(\"unchecked\")\n      public static void main(String args[])throws IOException\n    {\n         Reader ob=new Reader();\n        Writer out=new Writer(System.out);\n        Random oo=new Random();\n        long k=ob.nL(),ans=0,p=9,num=0;\n        for(int i=1;i<18;i++)\n        {\n            if(num+i*p<k)\n            {\n                num+=i*p;p*=10;\n                ans=0;\n                for(int j=0;j<i;j++)\n                ans=9+ans*10;\n            }\n            else\n            {\n                long left=k-num;\n                long r=left/i;\n                left-=r*i;\n                ans+=r;\n                if(left>0)\n                {\n                 String s=Long.toString(ans+1);\n                \n                out.pln(s.charAt((int)left-1));\n            }\n            else\n            {\n                \n                String s=Long.toString(ans);\n                \n                out.pln(s.charAt(i-1-(int)left));\n            }\n                break;\n            }\n            \n        }\nout.flush();\n}\nstatic void sort(int a[])\n{\n    RA(a);\n    Arrays.sort(a);\n}\n public static Pairs[] RA(Pairs [] array){\n\t\tRandom rgen = new Random();  // Random number generator\t\t\t\n \n\t\tfor (int i=0; i<array.length; i++) {\n\t\t    int randomPosition = rgen.nextInt(array.length);\n\t\t    Pairs temp = array[i];\n\t\t    array[i] = array[randomPosition];\n\t\t    array[randomPosition] = temp;\n\t\t}\n \n\t\treturn array;\n\t}\n\t\n public static int[] RA(int [] array){\n\t\tRandom rgen = new Random();  // Random number generator\t\t\t\n \n\t\tfor (int i=0; i<array.length; i++) {\n\t\t    int randomPosition = rgen.nextInt(array.length);\n\t\t    int temp = array[i];\n\t\t    array[i] = array[randomPosition];\n\t\t    array[randomPosition] = temp;\n\t\t}\n \n\t\treturn array;\n\t}\n\tstatic void sort(long a[])\n{\n    RA(a);\n    Arrays.sort(a);\n}\n public static long[] RA(long [] array){\n\t\tRandom rgen = new Random();  // Random number generator\t\t\t\n \n\t\tfor (int i=0; i<array.length; i++) {\n\t\t    int randomPosition = rgen.nextInt(array.length);\n\t\t    long temp = array[i];\n\t\t    array[i] = array[randomPosition];\n\t\t    array[randomPosition] = temp;\n\t\t}\n \n\t\treturn array;\n\t}\n\tstatic void sort(String a[])\n{\n    RA(a);\n    Arrays.sort(a);\n}\n public static String[] RA(String [] array){\n\t\tRandom rgen = new Random();  // Random number generator\t\t\t\n \n\t\tfor (int i=0; i<array.length; i++) {\n\t\t    int randomPosition = rgen.nextInt(array.length);\n\t\t    String temp = array[i];\n\t\t    array[i] = array[randomPosition];\n\t\t    array[randomPosition] = temp;\n\t\t}\n \n\t\treturn array;\n\t}\nstatic long inverse(long x, long p)\n    {\n        return pow(x, p - 2, p);\n    }\nstatic boolean isPrime(long n)\n{\n    long h=(long)Math.sqrt(n);\n    for(long i=2;i<=h;i++)\n    if(n%i==0)\n    return false;\n    return true&&n!=1;\n}\n    static long gcd(long a,long b)\n    {\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    static long pow(long a,long b,long mod){\n\t\tif(b == 0)\treturn 1;\n\t\tlong t = pow(a,b>>1,mod);\n\t\tt = (t * t) % mod;\n\t\tif((b & 1) == 1)\tt = (t * a);\n\t\tif(t >= mod)\tt %= mod;\n\t\treturn t;\n}\n    static long pow(long a,long b){\n\t\tif(b == 0)\treturn 1;\n\t\tlong t = pow(a,b>>1);\n\t\tt = (t * t);\n\t\tif((b & 1) == 1)\tt = (t * a);\n\t\treturn t;\n}\n    static void seive(int n,int prime[])//1 for prime -1 for not prime\n    {\n        for(int i=2;i<=n;i++)\n            if(prime[i]==0)\n            {\n                prime[i]=1;\n                for(int j=2;j*i<=n;j++)\n                prime[j*i]=-1;\n            }\n    }\n    static int max(int ...a)\n    {\n        int m=a[0];\n        for(int i=0;i<a.length;i++)\n        m=Math.max(m,a[i]);\n        return m;\n        \n    }\n    static long max(long ...a)\n    {\n        long m=a[0];\n        for(int i=0;i<a.length;i++)\n        m=Math.max(m,a[i]);\n        return m;\n    }\n    static int min(int ...a)\n    {\n        int m=a[0];\n        for(int i=0;i<a.length;i++)\n        m=Math.min(m,a[i]);\n        return m;\n    }\n    static long min(long ...a)\n    {\n        long m=a[0];\n        for(int i=0;i<a.length;i++)\n        m=Math.min(m,a[i]);\n        return m;\n    }\n    static class Pair<T1,T2>\n    {\n        T1 x;T2 y;\n        Pair(T1 xx,T2 yy)\n        {\n            x=xx;\n            y=yy;\n        }\n    }\n    \n\tstatic class Writer {\n\t\tprivate final PrintWriter p;\n\t\tWriter(OutputStream o) {\n\t\t\tp = new PrintWriter(new BufferedWriter(new OutputStreamWriter(o)));\n\t\t}\n\t\tvoid p(Object... o1) {\n\t\t\tfor (Object o11 : o1) {\n\t\t\t\tp.print(o11 + \"\" );\n\t\t\t}\n\t\t}\n\t\t<T>void pa(T a[])\n\t\t{\n\t\t    for(T i:a)\n\t\t    System.out.print(i+\" \");\n\t\t    System.out.println();\n\t\t  }\n\t\tvoid p(String s) {\n\t\t\tp.print(s);\n\t\t}\n\t\tvoid pln(Object... o1) {\n\t\t\tp(o1);\n\t\t\tp.println();\n\t\t}\n\t\tvoid flush() {\n\t\t\tp.flush();\n\t\t}\n\t\tvoid close() {\n\t\t\tp.close();\n\t\t}\n\t}\n    static class Reader {\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int snumChars;\n\t\tint flag=0;\n\t\tFileReader file;\n\t\tReader()\n\t\t{\n\t\t  }\n\t\t  Reader(String x)throws IOException\n\t\t  {\n\t\t      flag=1;\n\t\t      file=new FileReader(x);\n\t\t  }\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\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\t\tpublic String nl() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\tpublic String n() {\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 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 - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\tpublic int 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 - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\tpublic int[] NIA(int n) //nextINtArray\n\t\t{\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nI();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t\tpublic int[] NIA1(int n) //nextINtArray\n\t\t{\n\t\t\tint[] arr = new int[n+1];\n\t\t\tfor (int i = 1; i <=n; i++) {\n\t\t\t\tarr[i] = nI();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t\t\n\t\tpublic long[] NLA(int n) //nextLongArray\n\t\t{\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nL();\n\t\t\t}\n\t\t\treturn arr;\n}\n\t\tpublic long[] NLA1(int n) //nextLongArray\n\t\t{\n\t\t\tlong[] arr = new long[n+1];\n\t\t\tfor (int i = 1; i <=n; i++) {\n\t\t\t\tarr[i] = nL();\n\t\t\t}\n\t\t\treturn arr;\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\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\t}\nstatic class DSU\n{\n    int a[],size[],c=1,m;\n    HashMap<String,Integer> hm=new HashMap<String,Integer>();\n    DSU(int n)\n    {\n        a=new int[n+1];\n        m=n;\n        size=new int[n+1];\n        for(int i=1;i<=n;i++)\n    {\n        a[i]=i;\n        size[i]=1;\n    }\n    }\n    void add(String x,int i)\n    {\n        hm.put(x,i);\n    }\n    int find(int n)\n    {\n        while(a[n]!=n)\n        {\n            a[n]=a[a[n]];\n        n=a[n];\n    }\n        return n;\n    }\n    int[] eval()\n    {\n       int y[]=new int[m+1];\n       for(int i=1;i<=m;i++)\n       y[find(i)]++;\n       return y;\n    }\n    void union(int a1,int b)\n    {\n        int x=find(a1);\n        int y=find(b);\n        if(size[x]>size[y])\n    {\n        a[y]=x;\n        size[x]+=size[y];\n    }\n    else\n    {\n       a[x]=y;\n       size[y]+=size[x];\n    }\n}\n        //System.out.println(Arrays.toString(a));\n}\nclass Segment\n{\n    int sum[];\n    void build(int a[],int v,int l,int r)\n    {\n        if(l==r)\n        sum[v]=a[l];\n        else\n        {\n            int m=(l+r)/2;\n            build(a,v*2,l,m);\n            build(a,2*v+1,m+1,r);\n            sum[v]=sum[v*2]+sum[2*v+1];\n        }\n    }\n    void update(int a[],int l,int r,int x,int v,int y)\n    {\n        if(l==r&&r==y)\n            sum[v]+=x;\n        else if(l>y||y>r)\n        return;\n        else\n        {\n            int m=(l+r)/2;\n            update(a,l,m,x,2*v,y);\n            update(a,m+1,r,x,2*v+1,y);\n            sum[v]=sum[2*v]+sum[2*v+1];\n        }\n    }\n    int query(int v,int l,int r,int x,int y)\n    {\n        if(x>r||y<l)\n        return 0;\n        else if(x<=l&&r<=y)\n        return sum[v];\n        else\n        {\n            int m=(l+r)/2;\n        return query(2*v,l,m,x,y)+query(2*v+1,m+1,r,x,y);  \n    }\n}\n}\n\nstatic class Trie\n  {\n      Trie child[]=new Trie[26];\n      int count=0;\n    }\n   /* void insert(String a)\n    {\n        Trie tmp=root;\n        for(int i=0;i<a.length();i++)\n        {\n            int v=a.charAt(i)-'a';\n            if(tmp.child[v]==null)\n            {\n                tmp.child[v]=new Trie();\n                \n            }\n                tmp=tmp.child[v];\n            }\n            if(tmp.count==0)\n            r++;\n            tmp.count=1;\n        }*/\n    }\n    class Pairs implements Comparable<Pairs>\n    {\n        int x,y;String z;\n        Pairs(int a,int b)\n        {\n            x=a;y=b;\n        }\n        @Override\n         public int compareTo(Pairs a)\n            {\n            \n            if(a.x>this.x||(a.x==this.x&&a.y<this.y)||(a.x==this.x&&a.y==this.y&&(a.z).equals(\"BhayanakMaut\")))\n            return 1;\n            else\n            return -1;\n        }\n    }", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport static java.lang.Long.bitCount;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        FastScanner in = new FastScanner();\n        long []a = new long[16];\n        a[0] = 0;\n        for(int i=1; i<16; ++i)\n            a[i] = a[i-1]+((9*(long)Math.pow(10, i-1))*i);\n        long N = in.nextLong();\n        int pos = 0;\n        for(int i=0; i<16; ++i){\n            if(N<=a[i]){\n                pos = i;\n                break;\n            }\n        }\n        if(pos==1){\n            System.out.println(N);\n            System.exit(0);\n        }\n        long prev = a[pos-1];\n        long curr = N;\n        long rem = curr - prev;\n        long ans = 0;\n        for(int i=1; i<pos; ++i){\n            ans = ans*10 + 9;\n        }\n        long g = (rem+(pos-1))/pos;\n        long take = (rem+(pos-1))%pos;\n        long number = ans + g;\n        String str = Long.toString(number);\n        System.out.println(str.charAt((int)take));\n    }\n\n    static void sort(int[] a) {\n        ArrayList<Integer> l=new ArrayList<>();\n        for (int i:a) l.add(i);\n        Collections.sort(l);\n        for (int i=0; i<a.length; i++) a[i]=l.get(i);\n    }\n\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        int[] readArray(int n) {\n            int[] a=new int[n];\n            for (int i=0; i<n; i++) a[i]=nextInt();\n            return a;\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class DigitsSequence {\n    public static void main(String[] args){\n\n        Scanner sc=new Scanner(System.in);\n        long k,c,n,d;\n        c=1;\n        d=9;\n        n=1;\n        k= sc.nextLong();\n        while(k>(c*d)) {\n            k-=(c*d);\n            n*=10;\n            d*=10;\n            c++;\n        }\n        n+=(k-1)/c;\n        char[] num = String.valueOf(n).toCharArray();\n        System.out.println(num[(int)((k-1)%c)]);\n    }\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "//package codeforces;\nimport java.util.*;\nimport java.math.BigInteger;\npublic class test_round_B {\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\tBigInteger k=sc.nextBigInteger();\n\t\t\n\t\t\n\t\tBigInteger i=new BigInteger(\"0\");\n\t\tint d=0;\n\t\t\n\t\tBigInteger a=new BigInteger(\"0\");\n\t\twhile(i.compareTo(k)!=1)\n\t\t{\n\t\t\tif(i.compareTo(k)==0)\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\td++;\n\t\t\t\tBigInteger temp=new BigInteger(\"0\");\n\t\t\t\tfor(int j=0;j<d;j++)\n\t\t\t\t{\n\t\t\t\t\ttemp=temp.multiply(new BigInteger(\"10\")).add(new BigInteger(\"9\"));\n\t\t\t\t}\n\t\t\t\ti=i.add(new BigInteger(Integer.toString(d)).multiply(temp.subtract(a)));\n\t\t\t\t//i=i+d*(temp-a);\n\t\t\t\ta=temp;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t//System.out.println(a) ;\n\t\tBigInteger b=a.divide(new BigInteger(\"10\"));\n\t\tBigInteger t=b;\n\t\tBigInteger l=t;\n\t\t//System.out.println(b);\n\t\tint dig=0;\n\t\n\t\tif(b.equals(new BigInteger(\"0\")))\n\t\t{\n\t\t\tdig=0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\twhile(b.compareTo(new BigInteger(\"0\"))==1)\n\t\t\t{\n\t\t\t\tdig++;\n\t\t\t\tb=b.divide(new BigInteger(\"10\"));\n\t\t\t}\n\t\t}\n\t\t\n\t\t//System.out.println(dig);\n\t\tint flag=dig+1;\n\t\tBigInteger num=new BigInteger(\"0\");\n\t\tb=t;\n\t\twhile(b.compareTo(new BigInteger(\"0\"))==1)\n\t\t{\n\t\t\t//System.out.println(\"sun\");\n\t\t\tBigInteger rev=b.divide(new BigInteger(\"10\"));\n\t\t\tnum=num.add(new BigInteger(Integer.toString(dig)).multiply(b.subtract(rev)));\n\t\t\t//num+=(b-rev)*dig;\n\t\t\tb=b.divide(new BigInteger(\"10\"));\n\t\t\tdig--;\n\t\t\t\n\t\t}\n\t\t//System.out.println(num);\n\t\t//System.out.println(t);\n\t\tBigInteger net=k.subtract(num);\n\t\tBigInteger div=net.divide(new BigInteger(Integer.toString(flag)));\n\t\tint q;\n\t\tif(net.mod(new BigInteger(Integer.toString(flag))).equals(new BigInteger(\"0\")))\n\t\t{\n\t\t\t//System.out.println(\"s\");\n\t\t\t//System.out.println();\n\t\t\tq=0;\n\t\t\tt=t.add(div);\n\t\t\tSystem.out.println(t.mod(new BigInteger(\"10\")));\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//System.out.println(div);\n\t\t\t//System.out.println(flag);\n\t\t\t//System.out.println(net);\n\t\t\tBigInteger r=div.multiply(new BigInteger(Integer.toString(flag)));\n\t\t\tr=net.subtract(r);\n\t\t\t//q=Integer.toString(net%flag).length();\n\t\t\t\n\t\t\t//System.out.println(q);\n\t\t\t//System.out.println(t);\n\t\t\t//System.out.println(pig);\n\t\t\t//System.out.println(w);\n\t\t\tt=t.add(div.add(new BigInteger(\"1\")));\n\t\t\t//System.out.println(r);\n\t\t\tl=t;\n\t\t\tint pig=0;\n\t\t\twhile(t.compareTo(new BigInteger(\"0\"))==1)\n\t\t\t{\n\t\t\t\tpig++;\n\t\t\t\tt=t.divide(new BigInteger(\"10\"));\n\t\t\t}\n\t\t\t//System.out.println(pig);\n\t\t\tBigInteger p=new BigInteger(Integer.toString(pig));\n\t\t\tBigInteger rem=p.subtract(r);\n\t\t\t//System.out.println(l);\n\t\t\twhile(rem.compareTo(new BigInteger(\"0\"))==1)\n\t\t\t{\n\t\t\t\tl=l.divide(new BigInteger(\"10\"));\n\t\t\t\trem=rem.subtract(new BigInteger(\"1\"));\n\t\t\t}\n\t\t\t//System.out.println(l);\n\t\t\t//System.out.println(r);\n\t\t\t//System.out.println(c);\n\t\t\t//int f=t/w;\n\t\t\t//System.out.println(f);\n\t\t\tSystem.out.println(l.mod(new BigInteger(\"10\")));\n\t\t}\n\t\t\n\t\t\n\t\t\n\n\t}\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "    import java.util.Scanner;\n     \n    public class ABC {\n        public static void main(String[] args){\n     \n            Scanner sc=new Scanner(System.in);\n            long k,c,n,d;\n            c=1;\n            d=9;\n            n=1;\n            k= sc.nextLong();\n            while(k>(c*d)) {\n                k-=(c*d);\n                n*=10;\n                d*=10;\n                c++;\n            }\n            n+=(k-1)/c;\n            char[] num = String.valueOf(n).toCharArray();\n            System.out.println(num[(int)((k-1)%c)]);\n        }\n     \n    }\n\n\n\t\t\t\t \t     \t\t \t \t\t\t   \t \t  \t  \t", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.util.stream.Collectors;\n\npublic class P1177A {\n    public static void main(String[] args) throws Exception {\n        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n        long n = Long.parseLong(r.readLine());\n        if (n < 10) {\n            System.out.print(n);\n            return;\n        }\n        \n        int len = 1;\n        long edge = 10;\n        long prev = 0;\n        long prepow = 0;\n        while (edge - 1 < n) {\n            prepow = (long)Math.pow(10, len);\n            long pow = prepow * 10;\n            prev = edge;\n            edge = edge + (pow - prepow) * (len + 1);\n            len += 1;\n        }\n\n        long b = n - prev;\n        long c = b / len;\n        int rem = (int)(b % len);\n        String s = Long.toString(prepow + c).charAt(rem) + \"\";\n\n        System.out.print(s);\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class DigitSeq {\n\n\tstatic class FastReader { \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException  e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tFastReader sc = new FastReader();\n\t\tOutputStream outputstream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputstream);\n\n\t\tlong n = sc.nextLong();\n\t\tlong[] arr = new long[14];\n\t\tfor(int i = 1; i <= 13; i++){\n\t\t\tarr[i] = (long)Math.pow(10, i)-(long)Math.pow(10, i-1);\n\t\t}\n\t\tlong total = 0;\n\t\tfor(int i = 1; i <= 13; i++){\n\t\t\tif(total+(long)i*arr[i]>=n){\n\t\t\t\tlong ans = n-total;\n\t\t\t\tlong rest = ans;\n\t\t\t\tif(ans%i!=0){\n\t\t\t\t\tans /= i;\n\t\t\t\t\tans++;\n\t\t\t\t} else {\n\t\t\t\t\tans /= i;\n\t\t\t\t}\n\t\t\t\tans += (long)Math.pow(10, i-1)-1;\n\t\t\t\tString str = Long.toString(ans);\n\t\t\t\tint ind = (rest%i==0) ? i-1 : (int)(rest%i)-1;\n\t\t\t\tout.println(str.charAt(ind));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ttotal = total+(long)i*arr[i];\n\t\t}\n\t\tout.close();\n\t}\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class DD {\n    public static void main(String args[]) throws IOException {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        long k=Long.parseLong(br.readLine());\n        long ans=9*(int)Math.pow(10,0);\n        int c=0;\n        long start=0;\n        while(k>ans) {\n            c++;\n            start=ans;\n            ans+=9*(long)Math.pow(10,c)*(c+1);\n\n        }\n        long ms=(k-start-1)%(c+1);\n        long a=(long)Math.pow(10,c)+(k-start-1)/(c+1);\n        System.out.println((a+\"\").charAt((int)ms));\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class DigitSequence \n{\n    public static PrintWriter out;\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) throws IOException \n    {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer token = new StringTokenizer(\"\");\n        String temp[] = br.readLine().split(\" \");\n        long pos = Long.parseLong(temp[0]);\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n        if (pos<10)\n        {\n            out.println(pos);\n        }\n        else\n        {\n            out.println(findDigitSequence(pos));\n        }\n        out.close();\n    }\n\n    private static char findDigitSequence(long pos) \n    {\n        //long result = 0;\n        long min = 0;\n        long max = 9;\n        long dig = 1;\n        while (pos>max)\n        {\n            dig++;\n            min = max+1;\n            max=(long) (max+9*Math.pow(10, dig-1)*dig);\n        }\n        pos = pos-min;\n        long num = (long) (pos/dig+Math.pow(10, dig-1));\n        String st = String.valueOf(num);\n        if (dig==1)\n        {\n            return st.charAt(0);\n        }\n        char result = st.charAt((int) (pos%dig));\n        return result;\n    } \n    \n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \npublic class digits {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        long k = Long.parseLong(br.readLine());\n        long temp = 9 * (int)Math.pow(10,0);\n        int count = 0;\n        long initial = 0;\n        while(k > temp) {\n            count++;\n            initial = temp;\n            temp += 9 * (long)Math.pow(10,count)*(count+1);\n        }\n        long index = (k-initial-1)%(count+1);\n        long num = (long)Math.pow(10,count) + (k-initial-1)/(count+1);\n        System.out.println((num+\"\").charAt((int)index));\n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\nimport java.lang.management.*;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\nimport static java.lang.Math.sqrt;\nimport static java.lang.Integer.signum;\n\n@SuppressWarnings(\"unchecked\")\npublic class P1177B {\n\n  public void run() throws Exception {\n    for (long k = nextLong() - 1, d = 1, dc = 9, sv = 1; true; k -= dc, d++, sv *= 10, dc = (sv * 10 - sv) * d) {\n      if (k <= dc) {\n        println(Long.toString(sv + k / d).charAt((int)(k % d)));\n        break;\n      }\n    }\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 P1177B().run();\n    br.close();\n    pw.close();\n    System.err.println(\"\\n[Time : \" + (System.currentTimeMillis() - startTime) + \" ms]\");\n    long gct = 0, gcc = 0;\n    for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {\n      gct += garbageCollectorMXBean.getCollectionTime();\n      gcc += garbageCollectorMXBean.getCollectionCount();\n    }\n    System.err.println(\"[GC time : \" + gct + \" ms, count = \" + gcc + \"]\");\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 printsp(int [] a) { for (int i = 0, n = a.length; i < n; print(a[i] + \" \"), i++); }\n  void print(String s) { pw.print(s); }\n  void println() { println(\"\"); }\n  void println(byte b) { println(\"\" + b); }\n  void println(int i) { println(\"\" + i); }\n  void println(long l) { println(\"\" + l); }\n  void println(double d) { println(\"\" + d); }\n  void println(char c) { println(\"\" + c); }\n  void println(Object o) { print(o); println(); }\n  void println(String s) { pw.println(s); }\n  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n  long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n  char nextChar() throws IOException { return (char) (br.read()); }\n  String next() throws IOException { return nextToken(); }\n  String nextLine() throws IOException { return br.readLine(); }\n  int [] readInt(int size) throws IOException {\n    int [] array = new int [size];\n    for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n    return array;\n  }\n  long [] readLong(int size) throws IOException {\n    long [] array = new long [size];\n    for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n    return array;\n  }\n  double [] readDouble(int size) throws IOException {\n    double [] array = new double [size];\n    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n    return array;\n  }\n  String [] readLines(int size) throws IOException {\n    String [] array = new String [size];\n    for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n    return array;\n  }\n\n  int gcd(int a, int b) {\n    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n    a = Math.abs(a); b = Math.abs(b);\n    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);\n    a >>>= az; b >>>= bz;\n    while (a != b) {\n      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }\n            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }\n    }\n    return (a << Math.min(az, bz));\n  }\n\n  long gcd(long a, long b) {\n    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n    a = Math.abs(a); b = Math.abs(b);\n    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);\n    a >>>= az; b >>>= bz;\n    while (a != b) {\n      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }\n            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }\n    }\n    return (a << Math.min(az, bz));\n  }\n\n  void shuffle(int [] a) { // RANDOM shuffle\n    Random r = new Random();\n    for (int i = a.length - 1, j, t; i >= 0; j = r.nextInt(a.length), t = a[i], a[i] = a[j], a[j] = t, i--);\n  }\n\n  void shuffle(int [] a, int m) { // QUICK shuffle\n    for (int i = 0, n = a.length, j = m % n, t; i < n; t = a[i], a[i] = a[j], a[j] = t, i++, j = (i * m) % n);\n  }\n\n  void shuffle(long [] a) {\n    Random r = new Random();\n    for (int i = a.length - 1; i >= 0; i--) {\n      int j = r.nextInt(a.length);\n      long t = a[i]; a[i] = a[j]; a[j] = t;\n    }\n  }\n\n  void shuffle(Object [] a) {\n    Random r = new Random();\n    for (int i = a.length - 1; i >= 0; i--) {\n      int j = r.nextInt(a.length);\n      Object t = a[i]; a[i] = a[j]; a[j] = t;\n    }\n  }\n\n  int [] sort(int [] a) {\n    final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;\n    int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];\n    for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);\n    for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);\n    for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);\n    int [] t = a; a = ta; ta = t;\n    ai = new int [SIZE];\n    for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);\n    for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);\n    for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);\n    return ta;\n  }\n\n  void flush() {\n    pw.flush();\n  }\n\n  void pause() {\n    flush(); System.console().readLine();\n  }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class Cses {\n\tpublic static void main(String[] args) {\n\t\tFastReader sc = new FastReader();\n\t\t// int t = sc.nextInt();\n\t\t// while (t-- > 0) {\n\t\tlong n = sc.nextLong();\n\n\t\tif (n < 10) {\n\t\t\tSystem.out.println(n);\n\t\t\treturn;\n\t\t} else {\n\t\t\tlong sum = 0;\n\t\t\tlong cur = 9;\n\t\t\tlong prev = 0;\n\t\t\tint count = 1;\n\n\t\t\twhile (n > cur) {\n\t\t\t\tn -= cur ;\n\t\t\t\tsum += cur / count;\n\t\t\t\tprev = cur;\n\t\t\t\tcur = 9 * (count + 1) * (long)Math.pow(10, count);\n\t\t\t\tcount ++;\n\t\t\t}\n\n\t\t\tsum = sum + (n / count);\n\n\t\t\tif (n % count == 0) {\n\t\t\t\tSystem.out.println(sum % 10);\n\t\t\t} else {\n\t\t\t\tsum++;\n\t\t\t\tn = n % count;\n\t\t\t\tString s = String.valueOf(sum);\n\t\t\t\tSystem.out.println(s.charAt((int)n - 1));\n\t\t\t}\n\t\t\t// }\n\t\t}\n\t}\n\n\tpublic static boolean isSafe(int[][] chess, int row, int col) {\n\t\tfor (int i = row - 1, j = col; i >= 0; i--) {\n\t\t\tif (chess[i][j] == 1) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = col - 1, j = row - 1; i >= 0 && j >= 0; i--, j--) {\n\t\t\tif (chess[i][j] == 1) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = col - 1, j = row + 1; i >= 0 && j < chess.length; i--, j++) {\n\t\t\tif (chess[i][j] == 1) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tstatic String swap(String str, int i, int j) {\n\t\tchar temp;\n\t\tchar[] ch = str.toCharArray();\n\t\ttemp = ch[i];\n\t\tch[i] = ch[j];\n\t\tch[j] = temp;\n\n\t\treturn String.valueOf(ch);\n\t}\n\n\tstatic String rev(String str) {\n\t\tStringBuilder sb = new StringBuilder(str);\n\t\tfor (int i = str.length() - 1; i >= 0; i--) {\n\t\t\tsb.append(str.charAt(i));\n\t\t}\n\t\tString s = sb.toString();\n\t\treturn s;\n\t}\n\n\tstatic int swap(int a, int b) {\n\t\treturn a;\n\t}\n\n\tstatic class pair {\n\t\tint first;\n\t\tint second;\n\t\tpublic pair(int first, int second) {\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n\t}\n\n\tpublic static long power(long a, long b) {\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) != 0) {\n\t\t\t\tres = (res * a) % 1000000007;\n\t\t\t}\n\t\t\ta = (a * a) % 1000000007;\n\t\t\tb = b >> 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static int pow(int a, int b) {\n\t\tint res = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) != 0) {\n\t\t\t\tres = (res * a);\n\t\t\t}\n\t\t\ta = a * a;\n\t\t\tb = b >> 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static String catoString(char[] ch) {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < ch.length; i++) {\n\t\t\tsb.append(ch[i]);\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tpublic static boolean isPrime(long n) {\n\t\tif (n < 2) return false;\n\t\tfor (int i = 2; i * i <= n; i++) {\n\t\t\tif (n % i == 0) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic 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\tpublic static long lcm(long a, long b) {\n\t\tlong d = gcd(a, b);\n\t\treturn (a * b) / d;\n\t}\n\n\tstatic boolean isPowerOfTwo(long n) {\n\t\treturn (long)(Math.ceil(Math.log(n) / Math.log(2)))\n\t\t       == (long)(Math.floor(Math.log(n) / Math.log(2)));\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \" \";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class CodeForces {\n    class Pair<K, V> {\n        K first;\n        V second;\n        public Pair(K k, V v) {\n            first = k;\n            second = v;\n        }\n    }\n    private boolean contain(int set, int i) {\n        return (set & (1<<i)) > 0;\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 long pow(long a, long p) {\n        if (p == 0) return 1;\n        long b = pow(a, p/2);\n        b = b * b;\n        if (p % 2 == 1) b *= a;\n        return b % mod;\n    }\n    \n    private static boolean isSame(double a, double b) {\n        return Math.abs(a - b) < 1e-10;\n    }\n\n    private static void swapBoolean(boolean[] p, int i, int j) {\n        boolean tmp = p[i];\n        p[i] = p[j];\n        p[j] = tmp;\n    }\n\n    private static void swap(int[] p, int i, int j) {\n        int tmp = p[i];\n        p[i] = p[j];\n        p[j] = tmp;\n    }\n    private static int countOne(int a) {\n        if (a == 0) return 0;\n        return countOne(a & (a-1)) + 1;\n    }\n\n    private static int sdiv(int a, int b) {\n        return (a +b -1) / b;\n    }\n\n    private int[] retran(int index) {\n        int[] res = new int[2];\n        res[0] = index / M;\n        res[1] = index % M;\n        return res;\n    }\n\n    private int tran(int x, int y) {\n        return x * M + y;\n    }\n\n    private boolean inTable(int x, int y) {\n        return x>=0 && x< N && y >= 0 && y < M;\n    }\n\n    int N;\n    int R;\n    int[][] C = new int[10][10];\n    int M;\n    int mod = 1_000_000_007;\n    long IMPO;\n    int ans;\n\n    int[] dx = new int[]{1,0, -1, 0};\n    int[] dy = new int[]{0, -1, 0, 1};\n    Map<String, Boolean> dp = new HashMap<>();\n\n    class Edge {\n        int u;\n        int v;\n        int start;\n        int duration;\n        public Edge(int u, int v, int l, int d) {\n            this.u = u;\n            this.v = v;\n            this.start = l;\n            this.duration = d;\n        }\n    }\n    List<List<Integer>> graph = new ArrayList<>();\n    List<Edge> edges = new ArrayList<>();\n    int[] parent;\n    boolean[] visited;\n    public void run(Scanner scanner) throws IOException {\n\n        long k = scanner.nextLong();\n        int len = 1;\n        long number = 9;\n        for (int i = 0; true; i++) {\n            if (len * number < k) {\n                k -= len * number;\n                len ++;\n                number *= 10;\n            } else {\n                break;\n            }\n        }\n\n        number /= 9;\n        StringBuilder sb = new StringBuilder();\n        for (int i = 1; i <= 9; i++) {\n            if (len * number < k) {\n                k -= len * number;\n            } else {\n                sb.append(i);\n                break;\n            }\n        }\n\n        for (int i = 1; i < len; i++) {\n            number /= 10;\n            for (int j = 0; j <= 9; j++) {\n                if (len * number < k) {\n                    k -= len * number;\n                } else {\n                    sb.append(j);\n                    break;\n                }\n            }\n        }\n        System.out.println(sb.charAt((int) k - 1));\n    }\n\n    public static void main(String[] args) throws NumberFormatException, IOException {\n        \n//      String fileName = \"C://Users/user/eclipse-workspace/algo/example.txt\";\n//      String outFile = \"C://Users/user/eclipse-workspace/algo/example-out.txt\";\n//      String fileName = \"C://Users/user/eclipse-workspace/algo/A-small-practice.in\";\n//      String outFile = \"C://Users/user/eclipse-workspace/algo/A-small-out.txt\";\n//      String fileName = \"C://Users/user/eclipse-workspace/algo/A-large-practice.in\";\n//      String outFile = \"C://Users/user/eclipse-workspace/algo/A-large-out.txt\";\n//      String fileName = \"/Users/mobike/IdeaProjects/algo/B-small-practice.in\";\n//      String outFile = \"/Users/mobike/IdeaProjects/algo/B-small-out.txt\";\n//      String fileName = \"/Users/mobike/IdeaProjects/algo/B-large-practice.in\";\n//      String outFile = \"/Users/mobike/IdeaProjects/algo/B-large-out.txt\";\n//      String fileName = \"C://Users/user/eclipse-workspace/algo/C-small-practice.in\";\n//      String outFile = \"C://Users/user/eclipse-workspace/algo/C-small-out.txt\";\n//      String fileName = \"C://Users/user/eclipse-workspace/algo/D-small-practice.in\";\n//      String outFile = \"C://Users/user/eclipse-workspace/algo/D-small-out.txt\";\n//      String fileName = \"C://Users/user/eclipse-workspace/algo/D-large-practice.in\";\n//      String outFile = \"C://Users/user/eclipse-workspace/algo/D-large-out.txt\";\n\n        Scanner scanner = new Scanner(System.in);\n\n//        int T = scanner.nextInt();\n//        for (int i = 1; i <= T; i++) {\n            CodeForces jam = new CodeForces();\n            jam.run(scanner);\n//        }\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\n\npublic class B1177 {\n\n\tpublic static void main(String[] args) throws Exception {\n//\t\tBufferedReader br = new BufferedReader(new FileReader(\"F:/books/input.txt\"));\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tLong n = Long.parseLong(br.readLine());\n\t\tlong[] p = new long[15];\n\t\tint i;\n\t\tp[0]=1;\n\t\tfor(i=1;i<15;p[i]=p[i-1]*10,i++);\n\t\tfor(i=1;i*p[i-1]*9L<n;n-=i*p[i-1]*9L,i++);\n\t\tn--;\n\t\tint v = (int) (n%i);\n\t\tn/=i;\n\t\tn+=p[i-1];\n\t\tString s = n.toString();\n\t\tSystem.out.println(s.charAt(v));\n\t}\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tstatic final int MAX_N = 1000010;\n\tstatic final int INF = 0x3f3f3f3f;\n\tstatic final int mod = 1000000007;\n\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tinitReader(System.in);\n\n\n//\t\tint T = nextInt();\n//\t\tfor (int i = 1; i <= T; i++)\n\t\t\tsolve();\n\n\t\tpw.flush();\n\t}\n\n\n\t/*******************************************************************************************************************************/\n\n\n\tpublic static void solve() throws IOException {\n\t\twhile (hasNext()) {\n\t\t\tlong n = nextLong() - 1;\n\n\t\t\tlong k = 1, x = 9;\n\t\t\twhile (n - k * x >= 0) {\n\t\t\t\tn -= k * x;\n\t\t\t\tk += 1;\n\t\t\t\tx *= 10;\n\t\t\t}\n\n\t\t\tif (n == 0)\n\t\t\t\tpw.println(1);\n\t\t\telse {\n\t\t\t\tlong num = x / 9 + n / k;\n\t\t\t\tString s = String.valueOf(num);\n\t\t\t\tpw.println(s.charAt((int) (n % k)));\n\t\t\t}\n\t\t}\n\t}\n\n\n\n\n\t/*******************************************************************************************************************************/\n\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter pw;\n\n\tpublic static void initReader(InputStream input) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n//\t\treader = new BufferedReader(new FileReader(\"ate.in\"));\n//\t\ttokenizer = new StringTokenizer(\"\");\n//\t\tprintWriter = new PrintWriter(new BufferedWriter(new FileWriter(\"ate.out\")));\n\t}\n\n\tpublic static boolean hasNext() {\n\t\ttry {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic static String nextLine() {\n\t\ttry {\n\t\t\treturn reader.readLine();\n\t\t} catch (Exception e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic static long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic static double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static char nextChar() throws IOException {\n\t\treturn next().charAt(0);\n\t}\n\n\tstatic class Pair {\n\t\tchar first;\n\t\tboolean second;\n\n\t\tpublic Pair(char first, boolean second) {\n\t\t\t// TODO Auto-generated constructor stub\n\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn \"(\" + this.first + \", \" + this.second + \")\";\n\t\t}\n\t}\n}\n\n\n\t  \t \t \t   \t \t      \t \t\t \t  \t \t", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main{\n  final int mod = 1000000007;\n  final int maxn = -1;\n  final double eps = 1e-9;\n\n  long digits(long n){\n    if(n == 0) return 0;\n    int p = (int)Math.log10(n);\n    return (p + 1) * (n - (long)Math.pow(10, p) + 1) + digits((long)Math.pow(10, p) - 1);\n  }\n\n  void solve(){\n    // freopen(\"in\");\n    String s = \"\";\n    long k = nextLong();\n    long i = 1;\n    long j = k;\n    while(i < j){\n      long m = (i + j) / 2;\n      if(digits(m) < k){\n        i = m + 1;\n      }\n      else{\n        j = m;\n      }\n    }\n    if(digits(i) >= k) --i;\n    printf(\"%c\\n\", String.valueOf(i + 1).charAt((int)(k - digits(i) - 1)));\n  }\n\n  final double pi = Math.acos(-1.0);\n  final long infl = 0x3f3f3f3f3f3f3f3fl;\n  final int inf = 0x3f3f3f3f;\n  final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n  boolean zero(double x){ return x < eps; }\n\n  /** io **/\n  PrintWriter out;\n  BufferedReader reader;\n  StringTokenizer tokens;\n\n  Main(){\n    long s = System.currentTimeMillis();\n    tokens = new StringTokenizer(\"\");\n    reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);\n    out = new PrintWriter(System.out);\n    Locale.setDefault(Locale.US);     // imprime double com ponto\n    solve();\n    out.close();\n    debug(\"Time elapsed: %dms\", System.currentTimeMillis() - s);\n  }\n\n  void freopen(String s){\n    try{ reader = new BufferedReader(new InputStreamReader(new FileInputStream(s)), 1 << 15); }\n    catch(FileNotFoundException e){ throw new RuntimeException(e); }\n  }\n\n  /** input -- sup\u00f5e que n\u00e3o chegou no EOF **/\n  int nextInt(){ return Integer.parseInt(next()); }\n  long nextLong(){ return Long.parseLong(next()); }\n  double nextDouble(){ return Double.parseDouble(next()); }\n\n  String next(){ readTokens(); return tokens.nextToken(); }\n  String nextLine(){ readTokens(); return tokens.nextToken(\"\\n\"); }\n\n  boolean readTokens(){\n    while(!tokens.hasMoreTokens()){             // l\u00ea os dados, ignorando linhas vazias\n      try{\n        String line = reader.readLine();\n        if(line == null) return false;          // EOF\n        tokens = new StringTokenizer(line);\n      }\n      catch(IOException e){ throw new RuntimeException(e); }\n    }\n    return true;\n  }\n\n  /** output **/\n  void printf(String s, Object... o){ out.printf(s, o); }\n  void debug(String s, Object... o){ if(!ONLINE_JUDGE) System.err.printf((char)27 + \"[91m\" + s + (char)27 + \"[0m\", o); }\n\n  public static void main(String[] args){ new Main(); }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class prob1177b {\n    public static void main(String[] args){\n\n        Scanner sc=new Scanner(System.in);\n        long k,c,n,d;\n        c=1;\n        d=9;\n        n=1;\n        k= sc.nextLong();\n        while(k>(c*d)) {\n            k-=(c*d);\n            n*=10;\n            d*=10;\n            c++;\n        }\n        n+=(k-1)/c;\n        char[] num = String.valueOf(n).toCharArray();\n        System.out.println(num[(int)((k-1)%c)]);\n    }\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Digits_Sequence_Hard_Edition_Kamel {\n\tpublic static void main(String [] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong k = sc.nextLong();\n\t\tgetResult(k);\n\t\tsc.close();\n\t}\n\t\n\tstatic void getResult(long k) {\n\t\tlong val = 0;;\n\t\tlong ten = 1;\n\t\tint i = 1;\n\t\twhile(true) {\n\t\t\tval = 9l*ten*i;\n\t\t\tif(k<=val) {\n\t\t\t\tdecompose(k, ten, i);\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tk-=val;\n\t\t\t\tten = ten*10l;\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic void decompose(long offset, long ten, int size) {\n\t\tlong val = ten - 1 +(long) Math.ceil((double)offset/size);\n\t\tint digit = (int)(((offset%size))-1 + size)%size;\n\t\t\n\t\tString result = String.valueOf(val).substring(digit, digit+1);\n\t\tSystem.out.print(result);\n\t}\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class prob1177b {\n    public static void main(String[] args){\n\n        Scanner sc=new Scanner(System.in);\n        long k,c,n,d;\n        c=1;\n        d=9;\n        n=1;\n        k= sc.nextLong();\n        while(k>(c*d)) {\n            k-=(c*d);\n            n*=10;\n            d*=10;\n            c++;\n        }\n        n+=(k-1)/c;\n        char[] num = String.valueOf(n).toCharArray();\n        System.out.println(num[(int)((k-1)%c)]);\n    }\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        long K = Long.valueOf(br.readLine());\n        long n = 0;\n        long k = 0; //len * Math.pow(10, len) * 0.9;\n        long len = 0;\n        while(true){\n            len++;\n            long preK = k;\n            long preN = n;\n            k += len * Math.pow(10, len) * 0.9;\n            n += Math.pow(10, len) * 0.9;\n            if(K < k) {\n                k = preK;\n                n = preN;\n                break;\n            }\n        }\n        long step = len - 1;\n        while(true){\n            while(k <= K){\n                long preK = k;\n                long preN = n;\n                if(step == 0){\n                    k += len;\n                    n++;\n                }else{\n                    k += len * Math.pow(10, step) * 0.9;\n                    n += Math.pow(10, step) * 0.9;\n                }\n                if(k == K || (k >= K && k - K < len)){\n                    //System.out.println(k);\n                    //System.out.println(n);\n                    String nStr = Long.toString(n);\n                    System.out.println(nStr.charAt(nStr.length() - (int)(k-K) - 1));\n                    return;\n                }\n                if(K < k){\n                    k = preK;\n                    n = preN;\n                    break;\n                }\n            }\n            step--;\n        }\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "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.FileInputStream;\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        Reader in = new Reader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        BDigitsSequenceHardEdition solver = new BDigitsSequenceHardEdition();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BDigitsSequenceHardEdition {\n        public void solve(int testNumber, Reader in, PrintWriter out) {\n            long k = in.nextLong();\n            long start = 1;\n            long nDigit = 1;\n            while (true) {\n                long curr = start * 9 * nDigit;\n                if (curr >= k) break;\n                start *= 10;\n                nDigit += 1;\n                k -= curr;\n            }\n            if (k % nDigit == 0) {\n                start += (k / nDigit - 1);\n                out.println(start % 10);\n            } else {\n                long n = start + ((k / nDigit));\n                int off = (int) (k % nDigit);\n                out.println(Long.toString(n).charAt(off - 1));\n            }\n        }\n\n    }\n\n    static class Reader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer;\n        private int bytesRead;\n\n        public Reader(InputStream in) {\n            din = new DataInputStream(in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public Reader(String file_name) {\n            try {\n                din = new DataInputStream(new FileInputStream(file_name));\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public long nextLong() {\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        private void fillBuffer() {\n            try {\n                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n                if (bytesRead == -1) {\n                    buffer[0] = -1;\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        private byte read() {\n            if (bufferPointer == bytesRead) {\n                fillBuffer();\n            }\n            return buffer[bufferPointer++];\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n    public static void main(String[] args) {\n       Scanner sc = new Scanner(System.in);\n       long n = sc.nextLong();\n       long itrIdx = 0;\n       long itr = 0;\n       long num = 0;\n       while(itrIdx < n){\n           itrIdx += (itr+1)*(Math.pow(10,itr+1) - Math.pow(10,itr));\n           num+= (Math.pow(10,itr+1) - Math.pow(10,itr));\n           itr++;\n       }\n\n        itrIdx -= itr*(Math.pow(10,itr)-Math.pow(10,itr-1));\n        num -= (Math.pow(10,itr)-Math.pow(10,itr-1));\n        long lastNum = num + ((n-itrIdx)/itr);\n        long lastNumIndex = itrIdx + (itr* (lastNum-num));\n\n        if(lastNumIndex == n){\n            lastNumIndex = lastNumIndex-itr;\n            lastNum -=1;\n        }\n\n        String nextNum = String.valueOf(lastNum+=1);\n        System.out.println(nextNum.charAt((int) (n-lastNumIndex-1)));\n\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n \npublic class Main {\n\tpublic static void main(String args[]) {new Main().run();}\n\t\n\tScanner in = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tvoid run(){\n\t    work();\n\t    out.flush();\n\t}\n\tvoid work() {\n\t    long r=in.nextLong();\n\t    long b=0;\n\t    for(;;b++){\n\t        long num=9*(long)Math.pow(10,(double)b)*(b+1);\n\t        if(r-num<=0){\n\t            break;\n\t        }\n\t        r-=num;\n\t    }\n\t    long base=(long)Math.pow(10,(double)b);\n\t    long c=(r-1)/(b+1);\n\t    int m=(int)((r-1)%(b+1));\n\t    base+=c;\n\t    \n\t    String str=base+\"\";\n\t    out.println(str.charAt(m));\n\t}\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n\n    public static void main(String[] args) {\n       Scanner sc = new Scanner(System.in);\n       long n = sc.nextLong();\n       long itrIdx = 0;\n       long itr = 0;\n       long num = 0;\n       while(itrIdx < n){\n           itrIdx += (itr+1)*(Math.pow(10,itr+1) - Math.pow(10,itr));\n           num+= (Math.pow(10,itr+1) - Math.pow(10,itr));\n           itr++;\n       }\n\n        itrIdx -= itr*(Math.pow(10,itr)-Math.pow(10,itr-1));\n        num -= (Math.pow(10,itr)-Math.pow(10,itr-1));\n        long lastNum = num + ((n-itrIdx)/itr);\n        long lastNumIndex = itrIdx + (itr* (lastNum-num));\n\n        if(lastNumIndex == n){\n            lastNumIndex = lastNumIndex-itr;\n            lastNum -=1;\n        }\n\n        String nextNum = String.valueOf(lastNum+=1);\n        System.out.println(nextNum.charAt((int) (n-lastNumIndex-1)));\n\n    }\n}\n\n\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import 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.Queue;\nimport java.util.StringTokenizer;\n\npublic class Berland{\n\t\n\tpublic static void main(String[] args) throws NumberFormatException, IOException\n\t{\n\t\tnew Berland().run();\n\t}\n\t\n\tpublic void run() throws NumberFormatException, IOException\n\t{\n\t\tBufferedReader file = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong N = Long.parseLong(file.readLine());\n\t\tlong[] cutoff = new long[13];\n\t\tcutoff[0] = 0;\n\t\tfor(int i = 1;i<=12;i++)\n\t\t{\n\t\t\tcutoff[i] = cutoff[i-1] + (long)(9*Math.pow(10,i-1))*i;\n\t\t}\n\t\tint dig = -1;\n\t\tfor(int i = 0;i<12;i++)\n\t\t{\n\t\t\tif(cutoff[i]>=N)\n\t\t\t{\n\t\t\t\tdig = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tlong sub = N - cutoff[dig-1]-1;\n\t\tlong num = (sub)/dig;\n\t\tlong number = (long)Math.pow(10,dig-1)+num;\n\t\tint pos = (int)(sub % dig);\n\t\tSystem.out.println((number+\"\").charAt(pos));\n\t}\t\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "// package name;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner s = new Scanner(System.in);\n\t\tlong k = s.nextLong();\n\t\t\n\t\tlong dp[] = new long[13];\n\t\tlong x = 9; int i = 1;\n\t\t\n\t\tlong ansx = 0; int ansi = 0;\n\t\tfor(; i < 13; i++) {\n\t\t\tdp[i] = dp[i - 1] + x * i;\n\t\t\tx *= 10;\n\t\t\tif(k <= dp[i]) {\n\t\t\t\tansx = x;\n\t\t\t\tansi = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif(dp[i] > 1000000000000l) break;\n\t\t}\n\t\t\n\t\tif(ansi < 2) {\n\t\t\tSystem.out.println(k);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tk -= dp[ansi - 1];\n\t\t\n\t\t//System.out.println(k);\n\t\t\n\t\tlong st = (long)Math.pow(10, ansi - 1);\n\t\t\n\t\tlong div = (k / ansi);\n\t\tif(k % ansi == 0) div--;\n\t\t\n\t\tk -= div * ansi;\n\t\t\n\t\t//System.out.println(k);\n\t\tSystem.out.println(findKthDigit(st + div, k));\n\t\t\n\t}\n\n\tprivate static Long findKthDigit(long xx, long k) {\n\t\tint z = (int) k;\n\t\tArrayList<Long> arr = new ArrayList();\n\t\twhile(xx > 0) {\n\t\t\tarr.add(xx % 10);\n\t\t\txx /= 10;\n\t\t}\n\t\treturn arr.get(arr.size() - z);\n\t}\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class digits\n{\n\tpublic static void main(String[] args) \n\t{\n\t\tlong k = (new Scanner(System.in)).nextLong();\n\n\t\t//k = 56\n\t\t//League 1: 0 - 9\n\t\t//League 2: 10 - 99\n\t\t//League 3: 100 - 999..\n\t\t//System.out.println(\"k = \"+k);\n\t\tlong league = 1;\n\t\tlong irrelevancy = 0;\n\t\twhile(true)\n\t\t{\t\n\t\t\tirrelevancy += league * (Math.pow(10, league) - Math.pow(10, league-1));\n\t\t\tif(k > irrelevancy)\n\t\t\t\tleague ++;\n\t\t\t//league = 1 : k = 56 > 9\n\t\t\t//league = 2 : k = 56 < 99\n\t\t\t//therefore league = 2\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\t\t//System.out.println(\"League = \"+league);\n\t\tirrelevancy = 0;\n\t\tfor(long i=1; i<league; i++)\n\t\t\tirrelevancy += i * (Math.pow(10, i) - Math.pow(10, i-1));\n\n\t\t//irrelevancy = 1 * (10^1 - 10^0) = 9\n\n\t\tlong modified_k = k - irrelevancy;\n\n\t\t//modified_k = 56 - 9 = 47\n\t\t//System.out.println(\"modified k = \"+ modified_k);\n\t\tlong number = (long)(Math.pow(10, league-1)) - 1 + modified_k / league;\n\t\t//System.out.println(\"number = \"+number);\n\n\t\tif(modified_k % league == 0)\n\t\t\tSystem.out.println(number % 10);\n\t\telse\n\t\t{\n\t\t\tnumber ++;\n\t\t\tlong position_of_digit = (long)(modified_k % league);\n\t\t\t//System.out.println(position_of_digit);\n\t\t\t//number = 24\n\t\t\t//position_of_digit = 47 % 2 = 1\n\t\t\tSystem.out.println((Long.toString(number)).charAt((int)position_of_digit-1));\n\t\t}\n\t}\n\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tstatic final int MAX_N = 1000010;\n\tstatic final int INF = 0x3f3f3f3f;\n\tstatic final int mod = 1000000007;\n\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tinitReader(System.in);\n\n\n//\t\tint T = nextInt();\n//\t\tfor (int i = 1; i <= T; i++)\n\t\t\tsolve();\n\n\t\tpw.flush();\n\t}\n\n\n\t/*******************************************************************************************************************************/\n\n\n\tpublic static void solve() throws IOException {\n\t\twhile (hasNext()) {\n\t\t\tlong n = nextLong() - 1;\n\n\t\t\tlong k = 1, x = 9;\n\t\t\twhile (n - k * x >= 0) {\n\t\t\t\tn -= k * x;\n\t\t\t\tk += 1;\n\t\t\t\tx *= 10;\n\t\t\t}\n\n\t\t\tif (n == 0)\n\t\t\t\tpw.println(1);\n\t\t\telse {\n\t\t\t\tlong num = x / 9 + n / k;\n\t\t\t\tString s = String.valueOf(num);\n\t\t\t\tpw.println(s.charAt((int) (n % k)));\n\t\t\t}\n\t\t}\n\t}\n\n\n\n\n\t/*******************************************************************************************************************************/\n\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter pw;\n\n\tpublic static void initReader(InputStream input) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n//\t\treader = new BufferedReader(new FileReader(\"ate.in\"));\n//\t\ttokenizer = new StringTokenizer(\"\");\n//\t\tprintWriter = new PrintWriter(new BufferedWriter(new FileWriter(\"ate.out\")));\n\t}\n\n\tpublic static boolean hasNext() {\n\t\ttry {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic static String nextLine() {\n\t\ttry {\n\t\t\treturn reader.readLine();\n\t\t} catch (Exception e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic static long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic static double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static char nextChar() throws IOException {\n\t\treturn next().charAt(0);\n\t}\n\n\tstatic class Pair {\n\t\tchar first;\n\t\tboolean second;\n\n\t\tpublic Pair(char first, boolean second) {\n\t\t\t// TODO Auto-generated constructor stub\n\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn \"(\" + this.first + \", \" + this.second + \")\";\n\t\t}\n\t}\n}\n\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "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            long k=Long.parseLong(br.readLine());\n            long l=1,h=1000000000000l;\n            long p[]=new long[13];\n            for(int i=1;i<=12;i++)\n            {\n                  long ll=9*i;\n                  p[i]=ll*(long)Math.pow(10,i-1);\n                  p[i]+=p[i-1];\n            }\n            while(h-l>1)\n            {\n                  long mid=(l+h)/2;\n                  long num=(long)(Math.log(mid)/Math.log(10));\n                  long l1=p[(int)num]+(num+1)*(mid-(long)Math.pow(10,num));\n                  long l2=p[(int)num]+(num+1)*(mid-(long)Math.pow(10,num)+1);\n                  if(k<=l1)\n                   h=mid;\n                  else if(k>l2)\n                   l=mid;\n                  else\n                  { l=mid; h=mid; }\n            }\n            \n            if(h-l==1)\n            { \n                long num=(long)(Math.log(h)/Math.log(10));\n                long l1=p[(int)num]+(num+1)*(h-(long)Math.pow(10,num));\n                long l2=p[(int)num]+(num+1)*(h-(long)Math.pow(10,num)+1);\n                if(k>l1 && k<=l2)\n                { l=h; }\n            }\n            \n            long n=(long)(Math.log(l)/Math.log(10));\n            long u=p[(int)n]+(n+1)*(l-(long)Math.pow(10,n));\n            k-=u;\n            String ss=String.valueOf(l);\n            //System.out.println(l+\" \"+k);\n            System.out.println(ss.charAt((int)(k-1)));\n      }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class Tests {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tlong inputNum = 0;\n\t\tString finalResult = \"\";\n\n\t\tinputNum = scanner.nextLong();\n\t\tlong upperLimitResult = 0;\n\t\tlong lowerLimitResult = 0;\n\t\tint multiplier = 0;\n\t\tdo {\n\t\t\tmultiplier++;\n\t\t\tlowerLimitResult = upperLimitResult;\n\t\t\tupperLimitResult += 9 * Math.pow(10, multiplier - 1) * (multiplier);\n\t\t} while (inputNum > upperLimitResult);\n\t\tlong remainderFromLowerRange = inputNum - lowerLimitResult;\n\t\tlong repititions = 0;\n\t\tif (multiplier > 1)\n\t\t\trepititions = (remainderFromLowerRange - 1 > 0 ? remainderFromLowerRange - 1 : 0) / multiplier;\n\t\tlong currentNumber = (long) (Math.pow(10, multiplier - 1) + repititions);\n\t\tremainderFromLowerRange = remainderFromLowerRange - repititions * multiplier;\n\t\tlong digitIndex = remainderFromLowerRange < multiplier ? multiplier - remainderFromLowerRange\n\t\t\t\t: remainderFromLowerRange % multiplier;\n\n\t\tif (multiplier == 1) {\n\t\t\tfinalResult = (remainderFromLowerRange % 10) + \"\";\n\t\t} else {\n\t\t\tint charToGet = (int) ((multiplier - 1) - digitIndex);\n\t\t\tfinalResult = (currentNumber + \"\").charAt(charToGet) + \"\";\n\t\t}\n\t\tSystem.out.print(finalResult);\n\t\tscanner.close();\n\t}\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main {\n    public static void main(String args[])\n    {\n        FastReader input=new FastReader();\n        PrintWriter out=new PrintWriter(System.out);\n        int T=1;\n        while(T-->0)\n        {\n            long k=input.nextLong();\n            long v=9;\n            long s=0;\n            int x=1;\n            while(true)\n            {\n                if(s+v*x>k)\n                {\n                    break;\n                }\n                s+=v*x;\n                v*=10;\n                x++;\n            }\n            if(s==k)\n            {\n                out.println(9);\n            }\n            else\n            {\n                long d=k-s;\n                long u=d/x;\n                long rem=d%x;\n                long nu=(long)Math.pow(10,x-1);\n                nu+=u;\n                if(rem==0)\n                {\n                    nu--;\n                    out.println(nu%10);\n                }\n                else\n                {\n                    String str=String.valueOf(nu);\n                    out.println(str.charAt((int)(rem-1)));\n                }\n            }\n        }\n        out.close();\n    }\n    static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastReader()\n        {\n            br = new BufferedReader(new 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        int nextInt()\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong()\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble()\n        {\n            return Double.parseDouble(next());\n        }\n        String nextLine()\n        {\n            String str = \"\";\n            try\n            {\n                str = br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1177b {\n\n    public static void main(String[] args) throws IOException {\n        long k = rl(), n = -1;\n        for (long l = 0, r = k; l <= r; ) {\n            long m = l + (r - l) / 2;\n            if (f(m) < k) {\n                n = m + 1;\n                l = m + 1;\n            } else {\n                r = m - 1;\n            }\n        }\n        k -= f(n - 1);\n        char[] s = Long.toString(n).toCharArray();\n        prln(s[(int) k - 1]);\n        close();\n    }\n\n    static long f(long x) {\n        if (x < 10) {\n            return x;\n        }\n        long pow10 = 1, cnt = 1;\n        while (x >= pow10 * 10) {\n            pow10 *= 10;\n            ++cnt;\n        }\n        return cnt * (x - pow10 + 1) + f(pow10 - 1);\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<List<Integer>> g(int n) {List<List<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n    static List<Set<Integer>> sg(int n) {List<Set<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n    static void c(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n    static void cto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);}\n    static void dc(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n    static void dcto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);}\n    // input\n    static void r() throws IOException {input = new StringTokenizer(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<List<Integer>> rg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n    static void rg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n    static List<List<Integer>> rdg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n    static void rdg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n    static List<Set<Integer>> rsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n    static void rsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n    static List<Set<Integer>> rdsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n    static void rdsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n    // output\n    static void pr(int i) {__out.print(i);}\n    static void prln(int i) {__out.println(i);}\n    static void pr(long l) {__out.print(l);}\n    static void prln(long l) {__out.println(l);}\n    static void pr(double d) {__out.print(d);}\n    static void prln(double d) {__out.println(d);}\n    static void pr(char c) {__out.print(c);}\n    static void prln(char c) {__out.println(c);}\n    static void pr(char[] s) {__out.print(new String(s));}\n    static void prln(char[] s) {__out.println(new String(s));}\n    static void pr(String s) {__out.print(s);}\n    static void prln(String s) {__out.println(s);}\n    static void pr(Object o) {__out.print(o);}\n    static void prln(Object o) {__out.println(o);}\n    static void prln() {__out.println();}\n    static void pryes() {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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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();}}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class P_1177B {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong k = scan.nextLong();\n\t\tlong k2 = k - 10;\n\t\tint cont = 1, pos;\n\t\tString out; //System.out.println(getString((int)k));\n\t\t\n\t\tif(k <= 9)\n\t\t\tSystem.out.println(k);\n\t\telse {\n\t\t\tcont++;\n\t\t\twhile(k2 >= cont*(long)(Math.pow(10, cont)-Math.pow(10, cont-1))) {\n\t\t\t\tk2 -= cont*(long)(Math.pow(10, cont)-Math.pow(10, cont-1));\n\t\t\t\tcont++;\n\t\t\t}\n\t\t\tpos = (int)(k2%cont);\n\t\t\tk2 /= cont;\n\t\t\tk2 += (long)Math.pow(10, cont-1);\n\t\t\tout = String.valueOf(k2);\n\t\t\tSystem.out.println(out.charAt(pos));\n\t\t}\t\n\t}\n\t\n\t/*public static String getString(int number) {\n\t\tint contador = 1;\n\t\tString salida = \"\";\n\t\twhile(salida.length() <= number) {\n\t\t\tsalida += contador;\n\t\t\tcontador++;\n\t\t}\n\t\treturn salida.substring(0, number);\n\t}*/\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.prefs.BackingStoreException;\n\npublic class answertillD {\n\tstatic ArrayList<Integer>[] adjlist;\n\tstatic int[][] adjmatrix;\n\tstatic int[][] adjmatrix2;\n\tstatic boolean[] vis;\n\tstatic boolean[] intialvis;\n\tstatic boolean[] vis2;\n\tstatic int[] counter;\n\tstatic int V, E;\n\tstatic Stack<Integer> st;\n\tstatic ArrayList<Integer> arrylist;\n\tstatic boolean flag;\n\tstatic int[] dx = new int[] { 1, -1, 0, 0 };\n\tstatic int[] dy = new int[] { 0, 0, 1, -1 };\n\tstatic int[] Arr;\n\tstatic PrintWriter pw;\n\n\tpublic static long gcd(long u, long v) {\n\t\tif (u == 0)\n\t\t\treturn v;\n\t\treturn gcd(v % u, u);\n\t}\n\n\tpublic static int dfs(int u) {\n\t\tvis[u] = true;\n\t\tint a = 0;\n\t\tfor (int v : adjlist[u])\n\t\t\tif (!vis[v])\n\t\t\t\ta += dfs(v);\n\n\t\treturn 1 + a;\n\t}\n\n\tpublic static void dfs(int u, int num) {\n\t\tvis2[u] = true;\n\t\tcounter[u] = num;\n\t\tfor (int v : adjlist[u])\n\t\t\tif (!vis2[v])\n\t\t\t\tdfs(v, num);\n\t}\nstatic long diff=Long.MAX_VALUE;\n\tstatic boolean check(long num, long k) {\n\t\tint n=(num+\"\").length()-1;\n\t\tlong m=1;\n\t\tlong sum=0;int i=1;\n\t\twhile(n-->0)\n\t\t{\n\t\tsum+=9*m*(i++)\t;\n\t\tm*=10;\n\t\t}\n\t\tsum+=(num-m)*i+1;\n\t\tif(sum<=k)\n\t\t\tdiff=Math.min(diff, k-sum);\n\t\treturn sum<=k;\n\t}\n\t\t\n\n\tstatic long bin(long k) {\n\t\tlong left = 1;\n\t\tlong right = k+1;\n\t\tlong mid;\n\t\tlong ans = 1;\n\t\twhile (left <= right) {\n\t\t\tmid = (left + right) / 2;\n\n\t\t\tif (check(mid, k)) {\n\t\t\t\tans = mid;\n\t\t\t\tleft = mid + 1;\n\t\t\t\t\n\t\t\t} else\n\t\t\t\tright = mid - 1;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static long power(long x, int i) {\n\t\tlong r = 1;\n\t\twhile (i-- > 0) {\n\t\t\tif (r > 1e18 / x)\n\t\t\t\treturn (long) (1e18 + 5);\n\t\t\tr = r * x;\n\t\t}\n\t\treturn r;\n\t}\n\n\tstatic int m;\n\n\tstatic int calculate(int[] Arrs, int[] Arre, int index, boolean left, boolean targetleft) {\n\t\tint ans = 0;\n\t\tint n = m + 2;\n\t\t\n\t\tif (left) {\n\t\t\tans = Arre[index - 1];\n\t\t\tif ((index != E + 1))\n\t\t\t\tans += (targetleft) ? Arre[index - 1] : n - Arre[index - 1] - 1;\n\n\t\t} else {\n\t\t\tans = n - Arrs[index - 1] - 1;\n\t\t\tif ((index != E + 1))\n\t\t\t\tans += ((targetleft) ? Arrs[index - 1] : n - Arrs[index - 1] - 1);\n\t\t}\n\t\treturn ans;\n\t}\n\n\tstatic int min = Integer.MAX_VALUE;\n\n\tstatic void backtrack(int[] Arrs, int[] Arre, int soFarMin, int index, boolean left) {\n\t\tif (index == E) {\n\t\t\tmin = Math.min(min, soFarMin - 1);\n\t\t\treturn;\n\t\t}\n\n\t\tint newmin1 = calculate(Arrs, Arre, index, left, left);\n\t\tint newmin2 = calculate(Arrs, Arre, index, left, !left);\n\t\tbacktrack(Arrs, Arre, soFarMin + newmin1 + 1, index - 1, left);\n\t\tbacktrack(Arrs, Arre, soFarMin + newmin2 + 1, index - 1, !left);\n\n\t}\n\tpublic static String add(String str1,String str2){\n\t\tStack<String>st=new Stack<String>();\n\t\tint n=str1.length();\n\t\tint m=str2.length();\t\t\n\t\tint max=Math.max(n, m);\n\t\tint sum=0,carry=0;\n\t\tfor(int i=0;i<max;i++){\n\t\t\tint num1=0,num2=0;\n\t\t\tif(n>=i)\n\t\t\t num1 = Integer.parseInt(str1.charAt(n-i) + \"\");\n\t\t\tif(m>=i)\n\t\t\t num2 = Integer.parseInt(str2.charAt(m-i) + \"\");\n\t\t\tint z = num1 + num2 + carry;\n\t\t\tif (z >= 10) {\n\t\t\t\tsum = z / 10;\n\t\t\t\tcarry = z % 10;\n\t\t\t} else {\n\t\t\t\tsum = z;\n\t\t\t\tcarry=0;\n\t\t\t}\n\t\t\tst.add(sum+\"\");\n\t\t}\n\t\tStringBuilder sb=new StringBuilder();\n\t\twhile(!st.isEmpty()){\n\t\t\tsb.append(st.pop());\n\t\t}\n\t\treturn sb+\"\";\n\t}\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong k=sc.nextLong();\n\t\tlong bi=bin(k);\n\t\tString str=bi+\"\";\n\t\tSystem.out.println(str.charAt((int) diff));\n\t\t\n\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 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", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "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            long n = in.nextLong();\n            long st = 1, en = n, ans = 0, len = 0;\n            while (st <= en) {\n                long mid = (st + en) / 2;\n                long have = 0;\n                int curLen = Long.toString(mid).length();\n                long bef = 0;\n                for (int i = 1; i < curLen; i++) {\n                    long cur = 0;\n                    for (int j = 1; j <= i; j++) {\n                        cur *= 10;\n                        cur += 9;\n                    }\n                    have += i * (cur - bef);\n                    bef = cur;\n                }\n                have += curLen * (mid - bef);\n                if (have < n) {\n                    ans = mid;\n                    len = have;\n                    st = mid + 1;\n                } else\n                    en = mid - 1;\n            }\n            String s = Long.toString(ans + 1);\n            for (int i = 0; i < s.length(); i++) {\n                if (len + i + 1 == n) {\n                    out.print(s.charAt(i));\n                    return;\n                }\n            }\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Training {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        long index = in.nextLong();\n        if (index < 10) {\n            //one digit\n            System.out.println(index);\n        } else if (index < 190) {\n            //two digits\n            solve(2, index, 10, 10);\n\n        } else if (index < 2890) {\n            //three digits \n            solve(3, index, 190, 100);\n\n        } else if (index < 38890) {\n            //four digits \n            solve(4, index, 2890, 1000);\n\n            //start changing ------------------------------------------------------------\n        } else if (index < 488890) {\n            //five digits \n            solve(5, index, 38890, 10000);\n\n        } else if (index < 5888890) {\n            //six digits \n            solve(6, index, 488890, 100000);\n\n        } else if (index < 68888890) {\n            //seven digits \n            solve(7, index, 5888890, 1000000);\n\n        } else if (index < 788888890) {\n            //eight digits \n            solve(8, index, 68888890, 10000000);\n\n        } else if (index < 8888888890l) {\n            //nign digits \n            solve(9, index, 788888890, 100000000);\n\n        } else if (index < 98888888890l) {\n            //ten digits \n            solve(10, index, 8888888890l, 1000000000);\n\n        } else {\n            solve(11, index, 98888888890l, 10000000000l);\n\n        }\n\n    }\n\n    static void solve(int length, long index, long lastPoint, long num) {\n        String s = \"\";\n        num += (index - lastPoint) / length;\n        s += num;\n        int mod = (int) ((index - lastPoint) % length);\n        System.out.println(s.charAt(mod));\n    }\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\n\npublic class DigitSequenceA {\n    public static void main(String[] args) throws IOException{\n        FastReader in = new FastReader();\n        double digit = in.nextDouble();\n        double temp = digit;\n        long[] seq = new long[13];\n        for(int i = 1; i<13; i++){\n            seq[i] = (9* (long)Math.pow(10,i-1)) * (i) +seq[i-1];\n        }\n        int power = 0;\n        for(int i = 0; i< 13; i++){\n            if(temp-seq[i] >0){\n                continue;\n            }\n            else{\n                power = i;\n                break;\n            }\n        }\n        long place = (long) Math.ceil(digit - seq[power-1]);\n        place = (long)Math.ceil(place/power);\n        if((digit - seq[power-1])%power>0){\n            place++;\n        }\n\n        long num = (long) (place + Math.pow(10,power-1)-1);\n        String num2 = Long.toString(num);\n        long end =  seq[power-1] + place*power;\n        long answer = (long)(power-(end - digit));\n        //System.out.println(\"Digit is at the \" + power + \" power\");\n        //System.out.println(\"Digit is at the \" + place + \" number of the sequence\");\n        //System.out.println(\"Number is \" + num);\n        //System.out.println(\"Digit is at the \" + answer+  \" in that number\");\n        //System.out.println(\"Answer is \" + num2.charAt((int)answer-1));\n        System.out.println(num2.charAt((int)answer-1));\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\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class DigitQueries {\n    public static void main(String[] args) throws IOException {\n\n        FastReader in = new FastReader();\n\n        int q = 1;\n\n        while (q-- > 0) {\n            long k;\n            k = in.nextLong();\n            Query(k);\n        }\n\n    }\n   \n    static void Query(long k){\n        long x=0;\n        long sum=0;\n        while(sum<k){\n            sum+=9*Math.pow(10, x)*(x+1);\n            if(sum>k){\n                sum-=9*Math.pow(10, x)*(x+1);\n                break;\n            }\n            x++;\n        }\n     \n        long y = (k-sum);\n        long last = 0;\n        last = (long)Math.pow(10,x)+ (long)y/(x+1)-1;\n        long z =y%(x+1);\n        if(z!=0){\n            last=(long)(last+1)/(long)Math.pow(10,x+1-z);\n        }\n        System.out.println(last%10);\n    }\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n\n    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        {\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(\n                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                if (c == '\\n') {\n                    if (cnt != 0) {\n                        break;\n                    }\n                    else {\n                        continue;\n                    }\n                }\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            }\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        public long nextLong() throws IOException\n        {\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        {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n \n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n \n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        private void fillBuffer() throws IOException\n        {\n            bytesRead = din.read(buffer, bufferPointer = 0,\n                                 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    \n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class Main {\n    //SOLUTION BEGIN\n    //Into the Hardware Mode\n    void pre() throws Exception{}\n    void solve(int TC) throws Exception {\n        long K = nl();\n        K--;\n        int sz = 1;long pw = 1;\n        while(K >= pw){\n            long npw = pw*10;\n            long dig = sz*(npw-pw);\n            if(K >= dig){\n                K -= dig;\n                sz++;pw *= 10;\n            }else break;\n        }\n        long num = pw+K/sz;\n        int dig = sz-(int)(K%sz)-1;\n        while(dig-->0)num /= 10;\n        pn(num%10);\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 debug(Object... o){System.err.println(Arrays.deepToString(o));}\n    final long IINF = (long)2e18;\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 Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n        else new Main().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){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}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.Scanner;\npublic class Test {\n\tpublic static int digit(long number){\n\t\tint i = 1;\n\t\tlong exp = 1;\n\t\twhile(number > i * 9 * exp){\n\t\t\tnumber -= i * 9 * exp;\n\t\t\ti++;\n\t\t\texp *= 10;\n\t\t}\n\t\treturn i;\n\t}\n\tpublic static int result(long number){\n\t\tint digit = digit(number);\n\t\tlong exp = 1;\n\t\tfor(int i = 0; i < (digit - 1); i++){\n\t\t\tnumber -= (i+1) * 9 * exp;\n\t\t\texp *= 10;\n\t\t}\n\t\tlong b = number / digit;\n\t\tint c = (int)(number % digit);\n\t\tif(c > 0){\n\t\t\tString d = Long.toString(exp + b);\n\t\t\treturn d.charAt(c - 1) - '0';\n\t\t}\n\t\telse{\n\t\t\tString d = Long.toString(exp + b - 1);\n\t\t\treturn d.charAt(d.length() - 1) - '0';\n\t\t}\n\n\t}\n\tpublic static void main(String[] args){\n\t\tScanner input = new Scanner(System.in);\n\t\tlong k = input.nextLong();\n\t\tSystem.out.println(result(k));\n\t}\n}\n\n\n\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Codechef\n{   \n     static class FastScanner {\n        BufferedReader br;\n        StringTokenizer stok;\n        FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n        String next() 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        int ni() throws IOException {\n            return Integer.parseInt(next());\n        }\n        long nl() throws IOException {\n            return Long.parseLong(next());\n        }\n        double nd() throws IOException {\n            return Double.parseDouble(next());\n        }\n        char nc() throws IOException {\n            return (char) (br.read());\n        }\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n        \n        int[] niArray(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        long[] nlArray(int n) throws IOException {\n            long a[] = new long[n];\n            for (int i = 0; i < n; i++)\n                a[i] = nl();\n            return a;\n        }\n        \n        double[] ndArray(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    }\n    \n    \n    \n        \n    \n\t\n\t\n\tstatic long mod=Long.MAX_VALUE;\n\tstatic PrintWriter out=new PrintWriter(System.out);\n\tstatic FastScanner in = new FastScanner(System.in);\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{   int i,j;\n\t\tlong flag,flag1,flag2,temp,temp2,temp1,count,counter,l;\n\t\tHashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();\n\t\t/*\n\t\t    if(hm.containsKey(z))\n\t\t        hm.put(z,hm.get(z)+1);\n\t\t    else\n\t\t        hm.put(z,1);\n\t\t */       \n        ArrayList<Integer> arr=new ArrayList<Integer>();\n        HashSet<Integer> set=new HashSet<Integer>();\n        PriorityQueue<Integer> pq=new PriorityQueue<Integer>();\n        \n        \n       //for(i=1;i<200;i++)\n       //{\n        long k=in.nl();\n\t\ttemp=9;l=1;temp2=0;\n\t\twhile(true)\n\t\t{   if(k<=temp2+temp*l)\n\t\t        {k-=temp2;break;}\n\t\t    else\n\t\t    {   temp2+=temp*l;\n\t\t        temp*=10;\n\t\t        l++;\n\t\t    }      \n\t\t}\n\t\tlong z=((k-1)/l);\n\t\t//out.println(i+\":- \"+l+\" \"+((k-1)/l)+\"  \"+(k%l==0?l:k%l));\n\t\tlong no=(long)Math.pow(10,(l-1))+z;\n\t\t//out.println(no);\n\t\tint index=(int)(k%l==0?l:k%l)-1;\n\t\tString p=Long.toString(no);\n\t\t//out.println(p+\" \"+index);\n\t\tout.println(p.charAt(index));\n       //}\n\t\tout.close();\n\t}\n\tstatic long gcd(long a,long b)\n\t{   if(b==0)\n\t        return a;\n\t    return gcd(b,a%b);    \n\t}\n\tstatic long exponent(long a,long n)\n\t{   long ans=1;\n\t    while(n!=0)\n\t    {   if(n%2==0)\n\t            ans=(ans*a)%mod;\n\t       a=(a*a)%mod;\n\t       n=n>>1;\n\t    }\n\t    return ans;\n\t}\n\tstatic int binarySearch(int a[], int item, int low, int high) \n    {   if (high <= low) \n            return (item > a[low])?  (low + 1): low; \n        int mid = (low + high)/2; \n        if(item == a[mid]) \n            return mid+1; \n        if(item > a[mid]) \n            return binarySearch(a, item, mid+1, high); \n        return binarySearch(a, item, low, mid-1); \n    } \n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class cf_contest_1177_problem_B {\n    public static void main(String[] args) {\n\n        Scanner s = new Scanner(System.in);\n        long k = s.nextLong();\n        if (k<=9)\n            System.out.println(k);\n        else\n        {\n\n            int c = 1;\n            while(k>c*((Math.pow(10,c)) - Math.pow(10,c-1)))\n            {\n                k-=c*((Math.pow(10,c)) - Math.pow(10,c-1));\n//                System.out.println(k + \" hello \" + c);\n                c++;\n            }\n//            System.out.println(\"k is \" + k);\n            long mo = k%c;\n\n//            System.out.println(\"mo is \" + mo);\n            k = k/c;\n\n            if (mo == 0) {\n                mo = c;\n                k--;\n            }\n            mo--;\n//            k = Math.max(k-1,0);\n//            System.out.println(\"k/c is \" + k);\n            long j = (long) (Math.pow(10,c-1) + k);\n\n            String j1 = \"\" + j;\n//            System.out.println(\"j1 is \" + j1);\n//            System.out.println(\"final ans= \" + j1.charAt((int)mo));\n//            System.out.println();\n            System.out.println(j1.charAt((int)mo));\n        }\n\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class DigitalSequence {\n\n    public static void print(String s) {\n        System.out.println(s);\n    }\n\n    public static void main(String[] args) {\n        long k = new Scanner(System.in).nextLong();\n        long i = 1,t=0, c = 9,digits = 0,l=0,k2=k;\n        while(t<k){\n            l = t;\n            t += i*c;\n            i++;\n            c*=10;\n            digits++;\n        }\n        k = k-l;\n        long lastNumber = (long)Math.pow(10,digits-1)-1;\n        long p = k/digits,q=k%digits;\n        long finalNumber =lastNumber+p;\n        if(q!=0){\n            finalNumber++;\n        }\n            k = k-digits*p;\n            if(k<=0)\n                k+=digits;\n        String ans = \"\"+finalNumber;\n        int index = (int)(k-1);\n        print(\"\"+ans.charAt(index));\n    }   \n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class DigitSeq {\n\n\tstatic class FastReader { \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException  e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tFastReader sc = new FastReader();\n\t\tOutputStream outputstream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputstream);\n\n\t\tlong n = sc.nextLong();\n\t\tlong[] arr = new long[14];\n\t\tfor(int i = 1; i <= 13; i++){\n\t\t\tarr[i] = (long)Math.pow(10, i)-(long)Math.pow(10, i-1);\n\t\t}\n\t\tlong total = 0;\n\t\t/*for(int i = 1; i <= 13; i++) out.print(arr[i] + \" \");\n\t\tout.println();*/\n\t\tfor(int i = 1; i <= 13; i++){\n\t\t\tif(total+(long)i*arr[i]>=n){\n\t\t\t\tlong ans = n-total;\n\t\t\t\tlong rest = ans;\n\t\t\t\t//System.out.println(rest);\n\t\t\t\tif(ans%i!=0){\n\t\t\t\t\tans /= i;\n\t\t\t\t\tans++;\n\t\t\t\t} else {\n\t\t\t\t\tans /= i;\n\t\t\t\t}\n\t\t\t\tans += (long)Math.pow(10, i-1)-1;\n\t\t\t\tString str = Long.toString(ans);\n\t\t\t\tint ind = (rest%i==0) ? i-1 : (int)(rest%i)-1;\n\t\t\t\t//System.out.println(ind);\n\t\t\t\tout.println(str.charAt(ind));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ttotal = total+(long)i*arr[i];\n\t\t\t//System.out.println(total);\n\t\t}\n\t\tout.close();\n\t}\n\n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class A {\n    void solve(){\n        long k = readLong();\n\n       long x = 9;\n       long y = 1;\n       while(k > x * y){\n           k -= x * y;\n           x *= 10;\n           y++;\n       }\n\n\n       long w = k / y + (k % y == 0 ? 0 : 1);\n       long e = (k % y - 1 % y + y) % y;\n\n       long num = x/9 + w - 1;\n       String s = Long.toString(num);\n       out.print(s.charAt((int) e) - '0');\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n\n    void run(){\n        init();\n        solve();\n        out.close();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init(){\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out  = new PrintWriter(System.out);\n    }\n\n    String readLine(){\n        try{\n            return in.readLine();\n        }catch(Exception ex){\n            throw new RuntimeException(ex);\n        }\n    }\n    String readString(){\n        while(!tok.hasMoreTokens()){\n            String nextLine = readLine();\n            if(nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt(){\n        return Integer.parseInt(readString());\n    }\n\n    long readLong(){\n        return Long.parseLong(readString());\n    }\n\n    double readDouble(){\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\n\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(System.out);\n\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            long k=Long();\n            Solution sol=new Solution(out);\n            sol.solution(k);\n        }\n        out.flush();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n    long f[]=new long[15];\n    public void solution(long k){\n        f[0]=9;\n        for(int i=1;i<f.length;i++){\n            f[i]=10*f[i-1];\n        }\n        for(int i=1;i<f.length;i++){\n            f[i]*=(i+1);\n        }\n\n        long l=1,r=1000000000000l;\n        long res=-1;\n        long count=0;\n        while(l<=r){\n            long mid=l+(r-l)/2;\n            long cnt=get(mid);\n            if(cnt>=k){\n                res=mid;\n                count=cnt;\n                r=mid-1;\n            }\n            else{\n                l=mid+1;\n            }\n        }\n\n        int extra=(int)(count-k);\n        String s=res+\"\";\n        out.println(s.charAt(s.length()-1-extra));\n    }\n\n    public long get(long n){\n        long res=0;\n        long base=0;\n        int i=0;\n        while(true){\n            if(n<=base*10+9){\n                res=res+(i+1)*(n-base);\n                break;\n            }\n            res+=(f[i]);\n            i++;\n            base=base*10+9;\n        }\n        return res;\n    }\n\n\n\n\n\n\n\n\n\n\n\n}\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n\n\n\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "//package test_1177a;\n\nimport java.util.Scanner;\n\n\nimport java.util.Scanner;\n\n    public class test1177b{\n        public  static  void main(String[] args){\n            Scanner sc = new Scanner(System.in);\n            long k =  sc.nextLong();\n            long k1 =0,k2 = 0;\n            long p = 1;\n            String str=\"\";\n            for (int i=1; i<=12;i++){\n                if (k>= k1 && k <= k1 + p * 9 *i){\n                    // \u041d\u0430\u0448\u043b\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a\n                    long kk = ((k - k1) % i);\n\n                    k2 = p  + (k - k1) / i -1;\n                    if (kk != 0) k2 ++;\n                    str =\"\"+ k2;\n                    if(str.length() > i) {\n                        k2--;\n                        str =\"\"+ k2;\n                        kk =0;\n                    }\n                    if(kk > 0){\n                        System.out.println(str.charAt((int)kk-1));\n                    }else{\n                        System.out.println(str.charAt(i-1));\n                    }\n                    break;\n                }else {\n                    k1 += p * 9 *i;\n                    p = p * 10;\n                }\n            }\n\n        }\n    }\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class CodeForces1177B {\n\t\n\tpublic static char custBinSearch(long lower, long upper, long lowIndex, int ten, long position) {\n\t\tlong half = Math.round((lower + upper) / 2.0);\n\t\t\n\t\tlong lowBound = lowIndex + (half - lower)*(ten + 1);\n\t\tlong upBound = lowBound + ten;\n\t\t\n\t\tif(position < lowBound) { //Less than the lowest index of half\n\t\t\treturn custBinSearch(lower, half - 1, lowIndex, ten, position);\n\t\t\t\n\t\t} else if (position > upBound) { //Remember to update lowIndex here.\n\t\t\tlowIndex += (half + 1 - lower)*(ten + 1);\n\t\t\treturn custBinSearch(half + 1, upper, lowIndex, ten, position);\n\t\t\t\n\t\t} else {\n\t\t\treturn Long.toString(half).charAt((int) (position - lowBound)); //The final number will at max be 11 characters long, thus it is safe to convert and cast.\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException  {\n\t\tBufferedReader inputs = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tlong indexPosition = Long.parseLong(inputs.readLine());\n\t\t\n\t\tinputs.close();\n\t\t\n\t\t//Isolate possible combinations so that all further numbers will have the same length.\n\t\tint tenFactor = 0;\n\t\tlong lowerBound = 1;\n\t\tlong upperBound = (long) (Math.pow(10, 12));\n\t\tlong lowerIndexBound = 1;\n\t\tlong redIndex = 0;\n\t\tredIndex += indexPosition;\n\t\t\n\t\twhile(redIndex > 0) {\n\t\t\tredIndex -= (long) (9*Math.pow(10, tenFactor)*(tenFactor + 1));\n\t\t\tif(redIndex <= 0) { //Stage 1: Completed Successfully.\n\t\t\t\tlowerBound = (long) (Math.pow(10, tenFactor));\n\t\t\t\tupperBound = (long) (Math.pow(10, tenFactor + 1) - 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tlowerIndexBound += (long) (9*Math.pow(10, tenFactor)*(tenFactor + 1));\n\t\t\ttenFactor++;\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(custBinSearch(lowerBound, upperBound, lowerIndexBound, tenFactor, indexPosition));\n\t\t\n\t}\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n \npublic class Main {\n \n\tpublic static Character solve(long a, long b, long c) {\n\t\tlong min = a;\n\t\tlong max;\n\t\tlong xth = 0;\n\t\tlong index;\n \n\t\tfor (index = String.valueOf(a).length() - 1;; index++) {\n\t\t\tlong numOfDigits = 0;\n\t\t\tmax = (long) Math.pow(10, index + 1) - 1;\n\t\t\tlong count = (max - min) / b + 1;\n\t\t\tnumOfDigits += count * (index + 1);\n \n\t\t\tif (c - numOfDigits <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tc -= numOfDigits;\n\t\t\tmin = min + count * b;\n \n\t\t}\n \n\t\t// find xth\n\t\tif (c % (index + 1) == 0) {\n\t\t\txth = c / (index + 1);\n\t\t} else {\n\t\t\txth = c / (index + 1) + 1;\n\t\t}\n\t\tlong lastNum = min + b * (xth - 1);\n \n\t\tint pos = (int) (c % (index + 1));\n \n\t\t// here is the output\n\t\tif (pos == 0) {\n\t\t\treturn String.valueOf(lastNum).charAt((int) index);\n\t\t} else {\n\t\t\treturn String.valueOf(lastNum).charAt(pos - 1);\n\t\t}\n\t}\n \n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong tc;\n\t\ttc = sc.nextLong();\n\t\tSystem.out.println(solve(1, 1, tc));\n\t\t}\n \n}", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class B1177 {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        long N = in.nextLong();\n        long answer = solve(N, 0, 1, 1);\n        System.out.println(answer);\n    }\n\n    static long solve(long N, long offset, long start, int digits) {\n        long thisSection = digits*start*9;\n        long fromOffset = N-offset;\n        if (fromOffset > thisSection) {\n            return solve(N, offset+thisSection, 10*start, digits+1);\n        }\n        long number = start + (fromOffset-1)/digits;\n        long posInNumber = digits - 1 - (fromOffset-1)%digits;\n        while (posInNumber > 0) {\n            posInNumber--;\n            number /= 10;\n        }\n        return number%10;\n    }\n\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Solution {\n    public static void main(String[] args) {\n        long b=0;long p=1;\n        Scanner s=new Scanner(System.in);\n        long m=s.nextLong();\n        long x=1;\n        do{\n            p=(m+b)/x;\n            b=10*b+10;\n            x++;\n        }while(p/(long)Math.pow(10, x-1)!=0);\n        rest :\n        x--;b=b/10-1;\n        b=x*p-b;\n        b=m-b;\n        b=x-b-1;\n        p/=(long)Math.pow(10, b);\n        p%=10;\n        System.out.println(p);\n    }\n}\n", "complexity": "logn", "problem": "1177_B. Digits Sequence (Hard Edition)", "from": "CODEFORCES"}
{"src": "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\tint q=in.nextInt();\n\t\tfor(int i=0;i<q;i++) {\n\t\t\twork();\n\t\t}\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\tvoid work() {\n\t\tlong n=in.nextLong();\n\t\tlong k=in.nextLong();\n\t\tif(k==0) {\n\t\t\tout.println(\"YES\"+\" \"+n);\n\t\t}\n\t\tlong a=0,b=0,c=1,d=1;\n\t\twhile(--n>=0&&a<=k) {\n\t\t\tb+=c;\n\t\t\tc*=4;\n\t\t\ta+=d;\n\t\t\td=d*2+1;\n\t\t\tlong t=count(c-d,n);\n\t\t\tif(a<=k&&b>=k-t) {\n\t\t\t\tout.println(\"YES\"+ \" \"+n);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"NO\");\n\t}\n\tprivate long count(long l, long n) {\n\t\tif(n==0)return 0;\n\t\tn--;\n\t\tlong ret=l;\n\t\tfor(int i=1;i<=n;i++) {\n\t\t\tlong t=ret;\n\t\t\tret*=4;\n\t\t\tif(ret/4!=t)return Long.MAX_VALUE;\n\t\t}\n\t\treturn ret;\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}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "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\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastScanner in = new FastScanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        D solver = new D();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class D {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int T = in.ni();\n            for (int t = 0; t < T; t++) {\n                long n = in.nl(), k = in.nl();\n                if (n == 2 && k == 3) {\n                    out.println(\"NO\");\n                    continue;\n                }\n\n                boolean possible = false;\n                long size = n;\n                long rem = k;\n                for (int i = 0; i <= 31 && size > 0 && rem > 0; i++) {\n                    long splits = 1L << (i * 2);\n                    //System.out.println(\"splits = \" + splits);\n                    rem -= splits;\n                    size--;\n                }\n                if (rem > 0) {\n                    //System.out.println(\"rem = \" + rem);\n                    out.println(\"NO\");\n                    continue;\n                }\n                long path = 1;\n                long i = 0;\n                size = n;\n                long ans = 0;\n\n                while (path <= k && size > 0) {\n                    //System.out.printf(\"path=%d k=%d size=%d%n\", path, k, size);\n                    k -= path;\n                    path = (1L << i + 2) - 1;\n                    size--;\n                    i++;\n                }\n\n                //System.out.printf(\"size=%d k=%d%n\", size, k);\n                out.println(\"YES \" + size);\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 ns() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(ns());\n        }\n\n        public long nl() {\n            return Long.parseLong(ns());\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "public class D {\n\n\tpublic Object solve() {\n\t\tlong N = sc.nextLong(), K = sc.nextLong() - 1;\n\t\tif (N >= 32)\n\t\t\treturn print(\"YES\", N-1);\n\n\t\tlong A = 1L << (N-1), C = 4, T = (A*A - 1) / 3;\n\n\t\twhile (A > 1 && K > T) {\n\t\t\tA /= 2;\n\t\t\tK -= (C-1);\n\t\t\tC *= 2;\n\t\t\tT += (C-3) * (A*A - 1) / 3;\n\t\t}\n\n\t\tif (K >= 0 && K <= T)\n\t\t\treturn print(\"YES\", Long.numberOfTrailingZeros(A));\n\t\telse\n\t\t\treturn print(\"NO\");\n\t}\n\n\tprivate static final boolean ONE_TEST_CASE = false;\n\n\tprivate static void init() {\n\t}\n\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<Object> f, java.util.function.Consumer<Object> 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) { \n\t\t\tpw.println(build(o, A));\n\t\t\tif (DEBUG)\n\t\t\t\tSystem.err.println(build(o, A));\n\t\t\t return null;\n\t\t}\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static boolean PRINT, DEBUG;\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 {\n\t\t\t\tDEBUG = System.getProperties().containsKey(\"DEBUG\");\n\t\t\t\tPRINT = System.getProperties().containsKey(\"PRINT\");\n\t\t\t}\n\t\t\tcatch (Throwable t) {}\n\n\t\t\tfor (int n = 1; n <= N; ++n) {\n\t\t\t\tObject res = new D().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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "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        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        long maxk = (long) 1e18;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int t = in.nextInt();\n\n            long maxn = 1;\n            long val = 0;\n            for (long i = 1; ; i++) {\n                val = 1 + 4 * val;\n                if (val >= maxk) {\n                    maxn = i;\n                    break;\n                }\n            }\n\n            long[] vala = new long[(int) maxn + 1];\n\n            vala[1] = 1;\n\n            for (int i = 2; i <= maxn; i++) {\n                vala[i] = 1 + 4 * vala[i - 1];\n            }\n\n            o:\n            while (t-- > 0) {\n                long n = in.nextInt();\n                long k = in.nextLong();\n\n                if (n - 1 >= maxn) {\n                    out.println(\"YES \" + (n - 1));\n                    continue;\n                }\n\n                k--;\n\n                if (k <= vala[(int) n - 1]) {\n                    out.println(\"YES \" + (n - 1));\n                    continue;\n                }\n\n                long cs = n - 1;\n                long cc = 3;\n                int ind = 2;\n\n                long end = -1;\n                while (k > 0) {\n                    if (k >= cc && cs > 0) {\n                        k -= cc;\n                        cc += (1l << ind);\n                        cs--;\n                        ind++;\n                    } else {\n//                    if (cs > 0 && k < cc) {\n//                        out.println(\"YES \" + cs);\n//                        continue o;\n//                    }\n                        end = ind;\n                        break;\n                    }\n                }\n\n                long fcs = cs;\n\n                if (k == 0) {\n                    out.println(\"YES \" + cs);\n                    continue;\n                }\n\n                k -= vala[(int) n - 1];\n\n                cs = n - 1;\n                cc = 3;\n                ind = 2;\n\n                long rv = 5;\n\n                long sind = 3;\n\n                while (k > 0 && ind < end) {\n                    k -= rv * vala[(int) cs - 1];\n                    rv += (1l << sind);\n                    sind++;\n                    cs--;\n                    ind++;\n                }\n\n                if (k <= 0) {\n                    out.println(\"YES \" + fcs);\n                } else {\n                    out.println(\"NO\");\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 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 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 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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import javafx.util.*;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n\npublic class Test4 {\n\n    PrintWriter pw = new PrintWriter(System.out); InputStream is = System.in;\n    Random rnd = new Random();\n    int a;\n\n    void run(){\n        a = ni();\n        for(int q=0; q<a; q++){\n            long nj = ni(), kj = nl();\n            BigInteger n = BigInteger.valueOf(nj), k = BigInteger.valueOf(kj);\n            if((nj<40 && (k.compareTo(BigInteger.valueOf(2).pow(2*(int)nj).divide(BigInteger.valueOf(3)))>0))){\n                System.out.println(\"NO\");\n                continue;\n            }\n            if(nj>=40){\n                System.out.println(\"YES \"+(nj-1));\n                continue;\n            }\n            long log=nj;\n            BigInteger maxop = BigInteger.valueOf(2).pow(2*(int)nj).divide(BigInteger.valueOf(3)), pth = BigInteger.ONE;\n            for(BigInteger c = BigInteger.ONE; log>0; log--, c=c.multiply(BigInteger.valueOf(2)).add(BigInteger.ONE)){\n                if(k.compareTo(c)<0) break;\n                pth = c.multiply(BigInteger.valueOf(2)).add(BigInteger.ONE);\n                k=k.subtract(c);\n                maxop=maxop.subtract(c);\n            }\n            maxop = maxop.subtract(pth.multiply(BigInteger.valueOf(2).pow(2*(int)log).divide(BigInteger.valueOf(3))));\n            if(k.compareTo(maxop)<=0) System.out.println(\"YES \"+log);\n            else System.out.println(\"NO\");\n        }\n        pw.flush();\n    }\n\n    static class PyraSort {\n\n        private static int heapSize;\n\n        public static void sort(int[] 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(int[] 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(int[] 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(int[] 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 Test4().run();\n    }\n\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 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 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}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Main {\n\n    static ArrayList<BigInteger> bs = new ArrayList<>();\n\n    static void getBs(int n, BigInteger k) {\n        BigInteger four = BigInteger.valueOf(4);\n        BigInteger tmp4 = BigInteger.valueOf(1);\n        BigInteger sum = BigInteger.ZERO;\n        for (int i = 1; i <= n; i++) {\n            sum = sum.add(tmp4);\n            bs.add(sum);\n            if (sum.compareTo(k) >= 0) break;\n            tmp4 = tmp4.multiply(four);\n        }\n    }\n\n    static int ss(int n, BigInteger k) {\n        bs = new ArrayList<>();\n        BigInteger two = BigInteger.valueOf(2);\n        BigInteger s1;\n        BigInteger ts = BigInteger.ZERO;\n        getBs(n - 1, k);\n        int idx = bs.size() - 1;\n        BigInteger tx = BigInteger.valueOf(-1);\n        int ans = -1;\n        for (int i = 1; i <= n; i++) {\n            two = two.shiftLeft(1);\n            s1 = two.add(BigInteger.valueOf(-i - 2));\n            if (idx >= 0) {\n                tx = tx.add(BigInteger.ONE).multiply(BigInteger.valueOf(2)).add(BigInteger.ONE);\n                ts = ts.add(tx.multiply(bs.get(idx--)));\n            }\n            if (k.compareTo(s1) >= 0) {\n                if (k.subtract(s1).compareTo(ts) <= 0) {\n                    ans = n - i;\n                    break;\n                }\n            }\n        }\n        return ans;\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int T = sc.nextInt();\n        while (T-- > 0) {\n            int n = sc.nextInt();\n            BigInteger k = sc.nextBigInteger();\n            int ans = ss(n, k);\n            if (ans == -1) {\n                System.out.println(\"NO\");\n            } else {\n                System.out.println(\"YES \" + ans);\n            }\n        }\n    }\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\n/**\n * Created by timur on 28.03.15.\n */\n\npublic class TaskD {\n    boolean eof;\n    BufferedReader br;\n    StringTokenizer st;\n    PrintWriter out;\n\n    public static void main(String[] args) throws IOException {\n        new TaskD().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    long md(long x, long y, long x1, long y1) {\n        return Math.abs(x - x1) + Math.abs(y - y1);\n    }\n    \n    double md(double x, double y, double x1, double y1) {\n        return Math.abs(x - x1) + Math.abs(y - y1);\n    }\n\n    double ed(double x, double y, double x1, double y1) {\n        return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));\n    }\n\n    void solve() {\n        int t = nextInt();\n        long n, k;\n        int m = 34;\n        long[] res = new long[m];\n        res[1] = 0;\n        res[2] = 1;\n        for (int i = 3; i < m; i++) {\n            res[i] = res[i - 1] * 4L;\n        }\n        long[] l = new long[m];\n        long[] r = new long[m];\n        l[0] = 0;\n        l[1] = 1;\n        r[0] = 0;\n        r[1] = 1;\n        for (int i = 2; i < m; i++) {\n            l[i] = l[i - 1] * 2 + 1;\n            r[i] = r[i - 1] * 4;\n        }\n\n        long[] mi = new long[m];\n        long[] ma = new long[m];\n        for (int i = 1; i < m; i++) {\n            mi[i] = mi[i - 1] + l[i];\n            ma[i] = ma[i - 1] + r[i];\n        }\n\n//        for (int i = 0; i < m - 1; i++) {\n//            for (int j = 0; j <= i; j++) {\n//                out.println(i + \" \" + j + \" \" + mi[(int)i - j] + \" \" + (ma[(int)i] - l[(int)i - j + 1] * ma[j]));\n//            }\n//        }\n\n        for (int i = 0; i < t; i++) {\n            n = nextLong();\n            k = nextLong();\n            if (n >= 32) {\n                out.println(\"YES \" + (n - 1));\n            } else {\n                if (k > ma[(int)n]) {\n                    out.println(\"NO\");\n                } else {\n                    for (int j = 0; j <= n; j++) {\n                        if (mi[(int)n - j] <= k && ma[(int)n] - l[(int)n - j + 1] * ma[j] >= k) {\n                            out.println(\"YES \" + j);\n                            break;\n                        }\n                        if (j == n - 1) {\n                            out.println(\"NO\");\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.math.*;\nimport java.text.*;\nimport java.util.*;\npublic class Main {\n\n    public static void main(String args[]) {\n        Scanner sca = new Scanner(System.in);\n        long k,n;\n        long ans;\n        long[] pw = new long[33];\n        pw[1]=4;\n        pw[0]=1;\n        for(int i=2;i<=31;i++)\n            pw[i]=pw[i-1]<<2;\n        int t;\n        t = sca.nextInt();\n        for(int cas=1;cas<=t;cas++) {\n            n = sca.nextLong();\n            k = sca.nextLong();\n            ans = n;\n            long last, path = 1;\n            for (int i = 0; ; i++) {\n                if ((pw[i + 1] - 1) / 3 > k) {\n                    ans -= i;\n                    last = k - (pw[i] - 1) / 3;\n                    break;\n                }\n                path *= 2;\n            }\n            long sp = path * 2 - 1;\n            if (ans < 0 || (ans == 0 && last > 0)) {\n                System.out.println(\"NO\");\n                continue;\n            }\n            BigInteger sq = BigInteger.valueOf(path).multiply(BigInteger.valueOf(path)).subtract(BigInteger.valueOf(sp));\n            if (ans == 1 && sq.compareTo(BigInteger.valueOf(last))==-1 && last < sp) {\n                System.out.println(\"NO\");\n                continue;\n            } else if (ans == 1 && last >= sp) {\n                ans--;\n            }\n            System.out.println(\"YES \"+ans);\n        }\n\n    }\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    void run() {\n        in = new FastScanner();\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\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 s) {\n            try {\n                br = new BufferedReader(new FileReader(s));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        public String nextToken() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\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 Main().run();\n    }\n\n    void solve() {\n        int t = in.nextInt();\n\n        for (int sdfsdf = 0; sdfsdf < t; sdfsdf++) {\n            long n = in.nextLong();\n            long k = in.nextLong();\n\n            if (n == 1) {\n                if (k == 1)  {\n                    out.println(\"YES 0\");\n                } else {\n                    out.println(\"NO\");\n                }\n                continue;\n            }\n\n            if (k == 3) {\n                if (n == 2) {\n                    out.println(\"NO\");\n                } else {\n                    out.println(\"YES \" + (n - 1));\n                }\n                continue;\n            }\n\n            long cuts = 1;\n            long squares = 4;\n            int zoom = 1;\n\n            while (k > cuts + squares) {\n                cuts += squares;\n                squares *= 4;\n                zoom++;\n            }\n\n            if (zoom > n) {\n                out.println(\"NO\");\n                continue;\n            }\n\n            if (zoom == n && k > cuts) {\n                out.println(\"NO\");\n                continue;\n            }\n\n            long current_cuts = k - cuts;\n\n            if (current_cuts > squares - (2L * Math.sqrt(squares) - 1L)) {\n                out.println(\"YES \" + (n - zoom - 1L));\n            } else {\n                out.println(\"YES \" + (n - zoom));\n            }\n        }\n    }\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.awt.List;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.TreeSet;\n\n\npublic final class CF_524_D2_D {\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;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\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\n\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\n\tstatic long mod=1000000007;\n\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\t\tlong mymax=1L<<62;\n\t\tlog(mymax);\n\n\n\t\tlong cut=0;\n\t\tint it=0;\n\t\tlong squares=1;\n\t\tint GX=32;\n\t\tlong[] maxgen=new long[GX];\n\t\twhile (cut<2000000000000000000L){\n\t\t\tmaxgen[it]=cut;\n\t\t\t//log(\"squares:\"+squares+\" cut:\"+cut+\" it:\"+it+\" size:\"+(1L<<it));\n\t\t\tit++;\n\t\t\tcut=1+4*cut;\n\t\t\tsquares*=4;\n\t\t\t\n\t\t}\n\t\t//log(maxgen);\n\t\t\n\t\t\n\t\tint T=reader.readInt();\n\t\tfor (int t=0;t<T;t++){\n\t\t\tint n=reader.readInt();\n\t\t\tlong k=reader.readLong();\n\t\n\t\t\tif (n>=GX){\n\t\t\t\toutput(\"YES \"+(n-1));\n\t\t\t} else {\n\t\t\t\t// do first cut\n\t\t\t\tlong pieces=3;\n\t\t\t\tlong minc=1;\n\t\t\t\tint size=n-1;\n\t\t\t\tlong maxc=1+maxgen[size];\n\t\t\t\twhile (size>0 && maxc<k){\n\t\t\t\t\tminc+=pieces;\n\t\t\t\t\tmaxc+=pieces+maxgen[size-1]*(2*pieces-1);\n\t\t\t\t\tsize--;\n\t\t\t\t\tpieces=2*pieces+1;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tif (minc<=k && maxc>=k){\n\t\t\t\t\toutput(\"YES \"+size);\n\t\t\t\t} else {\n\t\t\t\t\toutput(\"NO\");\n\t\t\t\t\t//log(\"//check:\"+maxc+\" \"+maxgen[n]);\n\t\t\t\t}\n\t\t\t\t//log(\"size:\"+size+\" minc:\"+minc+\" maxc:\"+maxc);\n\t\t\t}\n\n\n\n\n\t\t}\n\n\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}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "//package round524;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tlong I = 4000000000000000007L;\n\t\n\tvoid solve()\n\t{\n\t\t// 1 5 13 \n\t\touter:\n\t\tfor(int T = ni();T > 0;T--){\n\t\t\tlong n = nl(), K = nl();\n\t\t\tlong inf = 0;\n\t\t\tlong sup = 0;\n\t\t\tfor(int d = 1;d <= n;d++){\n\t\t\t\tinf += pow(2,d)-1;\n\t\t\t\tif(inf >= I)inf = I;\n\t\t\t\tsup += pow(2,d)-1 + mul(pow(2,d+1)-3, (pow(4,n-d)-1)/3);\n\t\t\t\tif(sup >= I)sup = I;\n//\t\t\t\ttr(d, inf, sup);\n\t\t\t\tif(inf <= K && K <= sup){\n\t\t\t\t\tout.println(\"YES \" + (n-d));\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\t\n\tlong mul(long a, long b)\n\t{\n\t\tif((double)a*b > I)return I;\n\t\treturn a*b;\n\t}\n\t\n\tlong pow(int b, long d)\n\t{\n\t\tlong v = 1;\n\t\tfor(int i = 1;i <= d;i++){\n\t\t\tif((double)v*b > I)return I;\n\t\t\tv = v * b;\n\t\t}\n\t\treturn v;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new D().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class D {\n    public static void main(String[] args) throws IOException {\n        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {\n            long[] s = new long[40];\n            for (int i = 1; i < s.length; i++) {\n                s[i] = 1 + 4 * s[i - 1];\n                if (i >= 32) {\n                    s[i] = Long.MAX_VALUE;\n                }\n            }\n            Function<Integer, Long> getS = (i) -> (i < s.length) ? s[i] : Long.MAX_VALUE;\n            int t = input.nextInt();\n            testCase:\n            for (int tt = 0; tt < t; tt++) {\n                int n = input.nextInt();\n                long k = input.nextLong();\n                long kk = 1;\n                BigInteger maxDivisions = BigInteger.ZERO;\n                for (int division = 1; division <= n; division++) {\n                    long needToDivide = (1L << division) - 1;\n                    if (needToDivide > k) {\n                        writer.println(\"NO\");\n                        continue testCase;\n                    }\n                    k -= needToDivide;\n                    maxDivisions = maxDivisions.add(BigInteger.valueOf(kk).multiply(BigInteger.valueOf(getS.apply(n - division))));\n                    if (maxDivisions.compareTo(BigInteger.valueOf(k)) >= 0) {\n                        writer.println(\"YES \" + (n - division));\n                        continue testCase;\n                    }\n                    kk += (1L << division + 1);\n                }\n                writer.println(\"NO\");\n            }\n        }\n    }\n\n    interface Input extends Closeable {\n        String next() throws IOException;\n\n        default int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        default long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n    }\n\n    private static class StandardInput implements Input {\n        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n        private StringTokenizer stringTokenizer;\n\n        @Override\n        public void close() throws IOException {\n            reader.close();\n        }\n\n        @Override\n        public String next() throws IOException {\n            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n                stringTokenizer = new StringTokenizer(reader.readLine());\n            }\n            return stringTokenizer.nextToken();\n        }\n    }\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.*;\nimport java.util.*;\nimport java.util.LinkedList;\nimport java.math.*;\nimport java.lang.*;\nimport java.util.PriorityQueue;\nimport static java.lang.Math.*;\n@SuppressWarnings(\"unchecked\")\npublic class Solution 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 long min(long a,long b)\n    {\n        if(a>b)\n        {\n            return b;\n        }\n        return a;\n    }\n    public static int min(int a,int b)\n    {\n        if(a>b)\n        {\n            return b;\n        }\n        return a;\n    }\n    public static long max(long a,long b)\n    {\n        if(a>b)\n        {\n            return a;\n        }\n        return b;\n    }\n    public static int max(int a,int b)\n    {\n        if(a>b)\n        {\n            return a;\n        }\n        return b;\n    }\n    static class pair\n    {\n      long x;\n      long y;\n      pair(long x,long y)\n      {\n        this.x = x;\n        this.y = y;\n      }\n      public String toString()\n      {\n        return x+\" \"+y;\n      }\n    }\n    public static int gcd(int a,int b)\n    {\n        if(a==0)\n        return b;\n        if(b==0)\n        return a;\n        while((a%=b)!=0&&(b%=a)!=0);\n        return a^b;\n    }\n    static int num = (int)1e6;\n    public static int random(int min,int max)\n    {\n      return min+(int)((max-min)*Math.random());\n    }\n    float min(float a,float b)\n    {\n        if(a>b)\n        {\n            return b;\n        }\n        return a;\n    }\n    float dist(float x1,float y1,float x2,float y2)\n    {\n        return (float)Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));\n    }\n    float mod(float x)\n    {\n        if(x>0)\n        {\n            return x;\n        }\n        return -x;\n    }\n    public static long pow(long n,int pow)\n    {\n        long res = 1;\n        while(pow!=0)\n        {\n            if((pow&1)==1)\n            {\n                res *= n;\n            }\n            n *= n;\n            pow = pow>>1;\n        }\n        return res;\n    }\n    public static int bsearch(int n,long k)\n    {\n        int l = 1;\n        int r = n;\n        while(r>l)\n        {\n            int mid = (l+r+1)>>1;\n            if(pow(2,mid+1)-mid-2<=k)\n            {\n                l = mid;\n            }\n            else\n            {\n                r = mid-1;\n            }\n        }\n        if(pow(2,l+1)-l-2==0&&pow(2,l+1)-l-2==k)\n        {\n            return 0;\n        }\n        else if(pow(2,l+1)-l-2<=k)\n        {\n            return l;\n        }\n        return 0;\n    }\n    public static boolean valid(int n,long k,int steps)\n    {\n        long total_max = (pow(4,n)-1)/3;\n        long cant_be = ((pow(4,n-steps)-1)/3)*(pow(2,steps+1)-1);\n        long available = total_max-cant_be;\n        if(available>=k)\n        {\n            return true;\n        }\n        return false;\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new Solution(),\"Main\",1<<26).start();\n    }    public void run() {\n      InputReader sc  = new InputReader(System.in);\n      PrintWriter out = new PrintWriter(System.out);\n      int t1 = sc.nextInt();\n      while(t1-->0)\n      {\n        int n = sc.nextInt();\n        long k = sc.nextLong();\n        if(n>31)\n        {\n            out.println(\"YES \"+(n-1));\n            continue;\n        }\n        int steps = bsearch(n,k);\n        if(steps==0)\n        {\n            if(k==0)\n                out.println(\"YES \"+n);\n            else\n                out.println(\"NO\");\n        }\n        if(valid(n,k,steps))\n        {\n            out.println(\"YES \"+(n-steps));\n        }\n        else\n        {\n            out.println(\"NO\");\n        }\n      }\n      out.close();\n  }\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n\npublic class Main {\n\n\tstatic class Task {\n\t\t\n\t\tint NN = 500005;\n\t\tint MOD = 1000000007;\n\t\tint INF = 2000000000;\n\t\tlong INFINITY = 2000000000000000000L;\n\t\t\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint t = in.nextInt();\n\t\t\twhile(t-->0) {\n\t\t\t\tlong n = in.nextLong();\n\t\t\t\tlong k = in.nextLong();\n\t\t\t\tif(n < 32 && k > ((1L<<(2L*n))-1L)/3L) {\n\t\t\t\t\tout.println(\"NO\");continue;\n\t\t\t\t}\n\t\t\t\tif(n == 2 && k == 3) {\n\t\t\t\t\tout.println(\"NO\");continue;\n\t\t\t\t}\n\t\t\t\tif(n >= 32) {\n\t\t\t\t\tout.println(\"YES \"+ (n-1));continue;\n\t\t\t\t}\n\t\t\t\tboolean done = false;\n\t\t\t\tfor(long i=1;i<=n;++i) {\n\t\t\t\t\tif(k < (1L<<(i+2L))-i-3L) {\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tout.println(\"YES \" + (n - i));break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(!done) {\n\t\t\t\t\tout.println(\"YES 0\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tstatic void prepareIO(boolean isFileIO) {\n\t\t//long t1 = System.currentTimeMillis();\n\t\tTask solver = new Task();\n\t\t// Standard IO\n\t\tif(!isFileIO) { \n\t\t\tInputStream inputStream = System.in;\n\t        OutputStream outputStream = System.out;\n\t        InputReader in = new InputReader(inputStream);\n\t        PrintWriter out = new PrintWriter(outputStream);\n\t        solver.solve(in, out);\n\t        //out.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        out.close();\n\t\t}\n        // File IO\n\t\telse {\n\t\t\tString IPfilePath = System.getProperty(\"user.home\") + \"/Downloads/ip.in\";\n\t        String OPfilePath = System.getProperty(\"user.home\") + \"/Downloads/op.out\";\n\t        InputReader fin = new InputReader(IPfilePath);\n\t        PrintWriter fout = null;\n\t        try {\n\t\t\t\tfout = new PrintWriter(new File(OPfilePath));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t        solver.solve(fin, fout);\n\t        //fout.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        fout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n        prepareIO(false);\n\t}\n\t\n\tstatic class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n        \n        public InputReader(String filePath) {\n        \tFile file = new File(filePath);\n            try {\n\t\t\t\treader = new BufferedReader(new FileReader(file));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n            tokenizer = null;\n        }\n        \n        public String nextLine() {\n        \tString str = \"\";\n        \ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n        \treturn str;\n        }\n        \n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n        \treturn Double.parseDouble(next());\n        }\n        \n    }\n\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class OlyaAndMagicalSquare {\n\tpublic static void solveCase(FastIO io) {\n\t\tint N = io.nextInt();\n\t\tlong K = io.nextLong();\n\n\t\tCountMap cm = new CountMap();\n\t\tcm.increment(N, BigInteger.ONE);\n\t\tlong rem = K;\n\t\tint moves = 1;\n\t\tint sqSize = N;\n\t\twhile (sqSize > 0) {\n\t\t\tlong need = (1L << moves) - 1;\n\t\t\tBigInteger biNeed = BigInteger.valueOf(need);\n\t\t\tcm.decrement(sqSize, biNeed);\n\t\t\tif (need > rem) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcm.increment(sqSize - 1, biNeed.multiply(BigInteger.valueOf(4)));\n\t\t\trem -= need;\n\t\t\t++moves;\n\t\t\t--sqSize;\n\t\t}\n\n\t\tBigInteger biRem = BigInteger.valueOf(rem);\n\t\tfor (int i = N; i > 0; --i) {\n\t\t\tBigInteger have = cm.getCount(i);\n\t\t\tif (have.compareTo(biRem) >= 0) {\n\t\t\t\tbiRem = BigInteger.ZERO;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbiRem = biRem.subtract(have);\n\t\t\tcm.decrement(i, have);\n\t\t\tcm.increment(i - 1, have.multiply(BigInteger.valueOf(4)));\n\t\t}\n\t\tif (biRem.equals(BigInteger.ZERO)) {\n\t\t\tio.printf(\"YES %d\\n\", sqSize);\n\t\t} else {\n\t\t\tio.println(\"NO\");\n\t\t}\n\t}\n\n\tprivate static class CountMap extends HashMap<Integer, BigInteger> {\n\t\tpublic void increment(int k, BigInteger v) {\n\t\t\tput(k, getCount(k).add(v));\n\t\t}\n\n\t\tpublic void decrement(int k, BigInteger v) {\n\t\t\tBigInteger next = getCount(k).subtract(v);\n\t\t\tif (next.equals(BigInteger.ZERO)) {\n\t\t\t\tremove(k);\n\t\t\t} else {\n\t\t\t\tput(k, next);\n\t\t\t}\n\t\t}\n\n\t\tpublic BigInteger getCount(int k) {\n\t\t\treturn getOrDefault(k, BigInteger.ZERO);\n\t\t}\n\t}\n\n\tpublic static void solve(FastIO io) {\n\t\tint T = io.nextInt();\n\n\t\tfor (int t = 0; t < T; ++t) {\n\t\t\tsolveCase(io);\n\t\t}\n\t}\n\n\tpublic static class FastIO {\n\t\tprivate InputStream reader;\n\t\tprivate PrintWriter writer;\n\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FastIO(InputStream r, OutputStream w) {\n\t\t\treader = r;\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));\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 = reader.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\t// TODO: read this byte-by-byte like the other read functions.\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(nextString());\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\treturn nextIntArray(n, 0);\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n, int off) {\n\t\t\tint[] arr = new int[n + off];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i + off] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\treturn nextLongArray(n, 0);\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n, int off) {\n\t\t\tlong[] arr = new long[n + off];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i + off] = nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\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}\n\n\t\tpublic void println(Object... objects) {\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void printArray(int[] arr) {\n\t\t\tfor (int i = 0; i < arr.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(arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void printArray(long[] arr) {\n\t\t\tfor (int i = 0; i < arr.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(arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void printlnArray(int[] arr) {\n\t\t\tprintArray(arr);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void printlnArray(long[] arr) {\n\t\t\tprintArray(arr);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void printf(String format, Object... args) {\n\t\t\tprint(String.format(format, args));\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\twriter.flush();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tFastIO io = new FastIO(System.in, System.out);\n\t\tsolve(io);\n\t\tio.flush();\n\t}\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "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 Rustam Musin (t.me/musin_acm)\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        DOlyaIMagicheskiiKvadrat solver = new DOlyaIMagicheskiiKvadrat();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DOlyaIMagicheskiiKvadrat {\n        long inf = (long) 1e18 + 1;\n        long[] maxLen;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            maxLen = new long[100];\n            maxLen[1] = 0;\n            for (int i = 1; i < maxLen.length; i++) {\n                maxLen[i] = Math.min(inf, maxLen[i - 1] * 4 + 1);\n            }\n            if (false) {\n                for (int n = 1; n <= 3; n++) {\n                    for (int k = 1; k <= maxSplitCount(n) + 20; k++) {\n                        out.print(n + \" \" + k + \" \");\n                        int res = solve(n, k);\n                        if (res == -1) {\n                            out.printLine(\"NO\");\n                        } else {\n                            out.printLine(\"YES \" + res);\n                        }\n                    }\n                }\n                return;\n            }\n            int q = in.readInt();\n            while (q-- > 0) {\n                int n = in.readInt();\n                long k = in.readLong();\n                int res = solve(n, k);\n                if (res == -1) {\n                    out.printLine(\"NO\");\n                    continue;\n                }\n                out.printLine(\"YES \" + res);\n            }\n        }\n\n        long maxSplitCount(int n) {\n            if (n >= maxLen.length) {\n                return inf;\n            }\n            return maxLen[n];\n        }\n\n        int solve(int n, long k) {\n            if (maxSplitCount(n) < k) {\n                return -1;\n            }\n            int at = 0;\n            while (maxSplitCount(at + 1) <= k) {\n                at++;\n            }\n            int curSideLog = n - at;\n            k -= maxSplitCount(at);\n            double sideLen = Math.pow(2, n - curSideLog);\n            double pathLen = sideLen * 2 - 1;\n            if (curSideLog > 0 && pathLen <= k) {\n                return curSideLog - 1;\n            }\n            double area = sideLen * sideLen;\n            double otherArea = area - pathLen;\n            if (otherArea * (double) maxSplitCount(curSideLog) >= k) {\n                return curSideLog;\n            }\n            return -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 long readLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class 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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "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 *\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        DOlyaAndMagicalSquare solver = new DOlyaAndMagicalSquare();\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 DOlyaAndMagicalSquare {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.NextInt();\n            long k = in.NextLong();\n            if (k == 0) {\n                out.println(\"YES \" + n);\n                return;\n            }\n            long operationTillNow = 0, numberOfCubeOnTheSide = 1;\n            ArrayList<CubeCount> cubes = new ArrayList<>();\n\n            for (int i = n - 1; i >= 0; i--) {\n                cubes.add(new CubeCount(i, (numberOfCubeOnTheSide - 1) * 2 * 2 + 1));\n                operationTillNow = operationTillNow + 2 * numberOfCubeOnTheSide - 1;\n                numberOfCubeOnTheSide *= 2;\n                long operationLeft = k - operationTillNow;\n                if (operationLeft == 0) {\n                    out.println(\"YES \" + i);\n                    return;\n                } else if (operationLeft < 0) {\n                    out.println(\"NO\");\n                    return;\n                }\n                for (CubeCount c : cubes) {\n                    if (!c.hasLessThen(operationLeft)) {\n                        out.println(\"YES \" + i);\n                        return;\n                    } else {\n                        operationLeft = c.removeMeFrom(operationLeft);\n                    }\n                }\n                if (operationLeft <= 0) {\n                    out.println(\"YES \" + i);\n                    return;\n                }\n            }\n            out.println(\"NO\");\n            return;\n        }\n\n        class CubeCount {\n            int sideSizeLogScale;\n            long repeats;\n\n            public CubeCount(int sideSizeLogScale, long repeats) {\n                this.repeats = repeats;\n                this.sideSizeLogScale = sideSizeLogScale;\n            }\n\n            public boolean hasLessThen(long k) {\n                return hasLessThen(k, sideSizeLogScale, repeats);\n            }\n\n            private boolean hasLessThen(long k, int sideLog, long repeats) {\n                while (true) {\n                    if (k <= 0) return false;\n                    if (sideLog == 0) return true;\n                    k -= repeats;\n                    sideLog--;\n                    repeats *= 4;\n                }\n            }\n\n            public long removeMeFrom(long k) {\n                return removeMeFrom(k, sideSizeLogScale, repeats);\n            }\n\n            private long removeMeFrom(long k, int sideLog, long repeats) {\n                while (true) {\n                    if (sideLog == 0) return k;\n                    k -= repeats;\n                    sideLog--;\n                    repeats *= 4;\n                }\n            }\n\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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n//        System.err.println(f(1));\n\n\n//        System.err.println(f(4));\n        int tc = sc.nextInt();\n        out: while(tc-->0){\n            long n = sc.nextInt();\n\n            long k = sc.nextLong();\n            if(n >= 32){\n                pw.println(\"YES \" + (n-1));\n                continue;\n            }\n\n            long steps = 0;\n            for (int i = 1;; i++) {\n                long cnt = ((1l<<(i+1))-1);\n                steps += ((1l<<(i))-1);\n                if(steps > k)\n                    break;\n                if(steps > f(n))\n                    break;\n//                long rem = k-((1<<i)-1);\n                long rem = k-steps;\n//                System.err.println(\"steps:\" + steps + \" cnt:\" + cnt + \" f:\"  + f(n-i));\n//                System.err.println(\"rem: \" + (f(n) - steps - cnt*f(n-i)));\n                if(rem <= f(n) - steps - cnt*f(n-i)){\n                    pw.println(\"YES \" + (n-i));\n                    continue out;\n                }\n            }\n\n            pw.println(\"NO\");\n        }\n\n\n        pw.flush();\n        pw.close();\n    }\n\n\n    static long f(long n){\n        if(n == 0)\n            return 0;\n        long ans = 0;\n        for (int i = 0; i < n; i++) {\n            ans += 1l<<(2*i);\n        }\n        return ans;\n    }\n\n    static int[][] matMul(int[][] A, int[][] B, int p, int q, int r)\t//C(p x r) = A(p x q) x (q x r) -- O(p x q x r)\n    {\n        int[][] C = new int[p][r];\n        for(int i = 0; i < p; ++i)\n            for(int j = 0; j < r; ++j)\n                for(int k = 0; k < q; ++k)\n                    C[i][j] += A[i][k] * B[k][j];\n        return C;\n    }\n\n    /*\n     * 4. Square Matrix Exponentiation\n     */\n    static int[][] matPow(int[][] base, int p)\n    {\n        int n = base.length;\n        int[][] ans = new int[n][n];\n        for(int i = 0; i < n; i++)\n            ans[i][i] = 1;\n        while(p != 0)\n        {\n            if((p & 1) == 1)\n                ans = matMul(ans, base, n, n, n);\n            base = matMul(base, base, n, n, n);\n            p >>= 1;\n        }\n\n        return ans;\n    }\n\n\n    static int[][] packU(int n, int[] from, int[] to) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int f : from)\n            p[f]++;\n        for (int t : to)\n            p[t]++;\n        for (int i = 0; i < n; i++)\n            g[i] = new int[p[i]];\n        for (int i = 0; i < from.length; i++) {\n            g[from[i]][--p[from[i]]] = to[i];\n            g[to[i]][--p[to[i]]] = from[i];\n        }\n        return g;\n    }\n    static int pow(int n, int p){\n        int ans = 1;\n        for (int i = 0; i < p; i++) {\n            ans *= n;\n        }\n        return ans;\n    }\n\n    static int[][] packD(int n, int[] from, int[] to) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int f : from) if(f != -1) p[f]++;\n        for (int i = 0; i < n; i++) g[i] = new int[p[i]];\n        for (int i = 0; i < from.length; i++) if(from[i] != -1) {g[from[i]][--p[from[i]]] = to[i];}\n        return g;\n    }\n\n    static void shuffle(int[] a)\n    {\n        int n = a.length;\n        for(int i = 0; i < n; i++)\n        {\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    static class Scanner\n    {\n        StringTokenizer st; BufferedReader br;\n        public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n        public Scanner(String s) throws FileNotFoundException {\tbr = new BufferedReader(new FileReader(new File(s)));}\n        public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}\n        public int nextInt() throws IOException {return Integer.parseInt(next());}\n        public long nextLong() throws IOException {return Long.parseLong(next());}\n        public String nextLine() throws IOException {return br.readLine();}\n        public boolean ready() throws IOException {return br.ready();}\n    }\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class OlyaAndMagicalSquare {\n\tpublic static void solveCase(FastIO io) {\n\t\tint N = io.nextInt();\n\t\tlong K = io.nextLong();\n\n\t\tCountMap cm = new CountMap();\n\t\tcm.increment(N, BigInteger.ONE);\n\t\tlong rem = K;\n\t\tint moves = 1;\n\t\tint sqSize = N;\n\t\twhile (sqSize > 0) {\n\t\t\tlong need = (1L << moves) - 1;\n\t\t\tBigInteger biNeed = BigInteger.valueOf(need);\n\t\t\tcm.decrement(sqSize, biNeed);\n\t\t\tif (need > rem) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcm.increment(sqSize - 1, biNeed.multiply(BigInteger.valueOf(4)));\n\t\t\trem -= need;\n\t\t\t++moves;\n\t\t\t--sqSize;\n\t\t}\n\n\t\tBigInteger biRem = BigInteger.valueOf(rem);\n\t\tfor (int i = N; i > 0; --i) {\n\t\t\tBigInteger have = cm.getCount(i);\n\t\t\tif (have.compareTo(biRem) >= 0) {\n\t\t\t\tbiRem = BigInteger.ZERO;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbiRem = biRem.subtract(have);\n\t\t\tcm.decrement(i, have);\n\t\t\tcm.increment(i - 1, have.multiply(BigInteger.valueOf(4)));\n\t\t}\n\t\tif (biRem.equals(BigInteger.ZERO)) {\n\t\t\tio.printf(\"YES %d\\n\", sqSize);\n\t\t} else {\n\t\t\tio.println(\"NO\");\n\t\t}\n\n\t\t// long N = io.nextLong();\n\t\t// long K = io.nextLong();\n\n\t\t// // io.println(1L << 62);\n\n\t\t// boolean good;\n\t\t// if (N >= 31) {\n\t\t// \tgood = true;\n\t\t// } else {\n\t\t// \tgood = ((1L << (N << 1)) / 3 >= K);\n\t\t// }\n\n\t\t// if (!good) {\n\t\t// \tio.println(\"NO\");\n\t\t// \treturn;\n\t\t// }\n\n\t\t// int split = getMaxSplit(K);\n\n\t\t// if (N >= 40) {\n\t\t// \tio.printf(\"YES %d\\n\", N - split);\n\t\t// \treturn;\n\t\t// }\n\n\t\t// long used = (1L << split) - 1;\n\t\t// long rem = K - used;\n\n\t}\n\n\tprivate static class CountMap extends HashMap<Integer, BigInteger> {\n\t\tpublic void increment(int k, BigInteger v) {\n\t\t\tput(k, getCount(k).add(v));\n\t\t}\n\n\t\tpublic void decrement(int k, BigInteger v) {\n\t\t\tBigInteger next = getCount(k).subtract(v);\n\t\t\tif (next.equals(BigInteger.ZERO)) {\n\t\t\t\tremove(k);\n\t\t\t} else {\n\t\t\t\tput(k, next);\n\t\t\t}\n\t\t}\n\n\t\tpublic BigInteger getCount(int k) {\n\t\t\treturn getOrDefault(k, BigInteger.ZERO);\n\t\t}\n\t}\n\n\tprivate static int getMaxSplit(long k) {\n\t\tfor (int i = 1;; ++i) {\n\t\t\tif ((1L << (i + 1)) - 2 - i > k) {\n\t\t\t\treturn i - 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static void solve(FastIO io) {\n\t\tint T = io.nextInt();\n\n\t\tfor (int t = 0; t < T; ++t) {\n\t\t\tsolveCase(io);\n\t\t}\n\t}\n\n\tpublic static class FastIO {\n\t\tprivate InputStream reader;\n\t\tprivate PrintWriter writer;\n\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FastIO(InputStream r, OutputStream w) {\n\t\t\treader = r;\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));\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 = reader.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\t// TODO: read this byte-by-byte like the other read functions.\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(nextString());\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\treturn nextIntArray(n, 0);\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n, int off) {\n\t\t\tint[] arr = new int[n + off];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i + off] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\treturn nextLongArray(n, 0);\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n, int off) {\n\t\t\tlong[] arr = new long[n + off];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i + off] = nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\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}\n\n\t\tpublic void println(Object... objects) {\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void printArray(int[] arr) {\n\t\t\tfor (int i = 0; i < arr.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(arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void printArray(long[] arr) {\n\t\t\tfor (int i = 0; i < arr.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(arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void printlnArray(int[] arr) {\n\t\t\tprintArray(arr);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void printlnArray(long[] arr) {\n\t\t\tprintArray(arr);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void printf(String format, Object... args) {\n\t\t\tprint(String.format(format, args));\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\twriter.flush();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tFastIO io = new FastIO(System.in, System.out);\n\t\tsolve(io);\n\t\tio.flush();\n\t}\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Solution {\n    public static void main(String[] args) {\n        Solution solution = new  Solution();\n        solution.solve();\n    }\n\n    private void solve() {\n        Scanner in = new Scanner(System.in);\n        int t = in.nextInt();\n        while (t -- > 0) {\n            long n = in.nextLong();\n            long k = in.nextLong();\n\n            System.out.println(solve(n, k));\n        }\n    }\n\n    private String solve(long n, long k) {\n        if (n > 31) return \"YES \" + (n - 1);\n        if (k > f(n)) return \"NO\";\n\n        long square = 1;\n        long splitDone = 0;\n        long size = n;\n        long splitLeft = 0;\n        \n        while (splitDone + square <= k && size > 0) {\n            splitDone += square;\n            --size;\n            splitLeft += (square * 2 - 1) * f(size);\n            square = square * 2 + 1;\n        }\n//        System.out.println(square + \" \" + splitDone + \" \" + size + \" \" + splitLeft);\n        if (k > splitDone + splitLeft) return \"NO\";\n        else return \"YES \" + size;\n    }\n\n    private long f(long x) {\n        return ((1L << (2 * x)) - 1) / 3;\n    }\n}\n", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n// Solution\n\npublic class Main \n{    \n  public static void main (String[] argv)\n  {\n\t  new Main();\n  } \n     \n     \n  \n  boolean test = false;  \n  \n  final int MOD = 998244353;\n  \n  \n  \n  \n  public Main()   {\n\t FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));\n\t //FastReader in = new FastReader(new BufferedReader(new FileReader(\"Main.in\")));\n     final int N = 50; //big enough \n     long[] f = new long[N];\n     int maxN = 50;\n     f[0] = 0;\n     for (int i = 1; i < N; i++) {\n         if (Long.MAX_VALUE / 4 <= f[i-1]) {\n             maxN = i - 1;\n             break;\n         }\n         f[i] = f[i-1] * 4 + 1;\n     }\n     \n     long[] a = new long[N];\n     long[] b = new long[N];\n          \n     int nt = in.nextInt();     \n     \n     for (int ii = 1; ii <= nt; ii++) {\n         int n = in.nextInt(); \n         long k = in.nextLong(); \n         \n         if (k == 0) {\n             System.out.println(\"YES \" + n);\n             continue;\n         }\n         \n         if (n - 1> maxN || k <= 1 + f[n-1]) {\n             System.out.println(\"YES \" + (n - 1));\n             continue;\n         }\n         if (n - 1 == maxN) {\n             System.out.println(\"YES \" + (n - 2));\n             continue;\n         }\n         \n         // now: n <= maxN\n         if (k > f[n]) {\n             System.out.println(\"NO\");             \n             continue;\n         }                 \n         \n         if (n == 2) {\n             if (k==3) System.out.println(\"NO\");\n             else System.out.println(\"YES 0\");             \n             continue;\n         }\n         \n         a[1] = 1;\n         b[1] = f[n-1];\n         int ret = 0;\n         for (int i = 2; i <= n; i++) {\n             a[i] = a[i-1] + (1L << i) - 1;\n             b[i] = b[i-1] + (2 * (1L << i) - 3) * f[n-i];\n             if (a[i] + b[i] >= k) {\n                 ret = n - i;\n                 break;\n             }\n         }\n         System.out.println(\"YES \" + ret);\n     }\n  }\n  \n  \n  private int dist(int x, int y, int xx, int yy) {\n      return abs(x - xx) + abs(y - yy);\n  }\n  \n  private boolean less(int x, int y, int xx, int yy) {\n      return x < xx || y > yy;\n  }\n  \n  private int mul(int x, int y) {\n      return (int)(1L * x * y % MOD);\n  }\n  \n  private int add(int x, int y) {\n      return (x + y) % MOD;\n  }\n  \n \n  \n  private int nBit1(int v) {\n      int v0 = v;\n      int c = 0;\n      while (v != 0) {\n          ++c;\n          v = v & (v - 1);\n      }\n      return c;\n  }\n  \n  private long abs(long v) {\n      return v > 0 ? v : -v;\n  }\n  \n  private int abs(int v) {\n      return v > 0 ? v : -v;\n  }\n  \n  private int common(int v) {\n      int c = 0;\n      while (v != 1) {\n          v = (v >>> 1);\n          ++c;\n      }\n      \n      return c;\n  }\n  \n  private void reverse(char[] a, int i, int j) {\n      while (i < j) {\n          swap(a, i++, j--);\n      }\n  }\n  \n  private void swap(char[] a, int i, int j) {\n      char t = a[i];\n      a[i] = a[j];\n      a[j] = t;\n  }\n  \n  private int gcd(int x, int y) {\n      if (y == 0) return x;\n      return gcd(y, x % y);\n  }\n  private long gcd(long x, long y) {\n      if (y == 0) return x;\n      return gcd(y, x % y);\n  }\n  private int max(int a, int b) {\n      return a >  b ? a : b;\n  }\n  \n  private long max(long a, long b) {\n      return a >  b ? a : b;\n  }\n  \n  private int min(int a, int b) {\n      return a >  b ? b : a;\n  }\n  \n  private long min(long a, long b) {\n      return a >  b ? b : a;\n  }\n  \n  static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastReader(BufferedReader in)\n        {            \n            br = in;\n        }\n \n        String next()\n        {\n            while (st == null || !st.hasMoreElements())\n            {\n                try\n                {\n                    String line = br.readLine();\n                    if (line == null || line.length() == 0) return \"\";\n                    st = new StringTokenizer(line);\n                }\n                catch (IOException  e)\n                {\n                    return \"\";\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                return \"\";\n                //e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "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 OlyaAndMagicalSquare {\n    void solve() {\n        long[] dp = new long[32];\n        dp[0] = 0;\n        for (int i = 1; i < 32; i++) {\n            dp[i] = 4 * dp[i - 1] + 1;\n        }\n        \n        int T = in.nextInt();\n        L:\n        while (T-- > 0) {\n            int n = in.nextInt(); long k = in.nextLong();\n            \n            if (n > 31) {\n                out.println(\"YES \" + (n - 1));\n                continue;\n            }\n            \n            long tot = 0;\n            for (int a = n - 1; a >= 0; a--) {\n                k -= (1L << (n - a)) - 1;\n                if (k < 0) break;\n                if (k == 0) {\n                    out.println(\"YES \" + a);\n                    continue L;\n                }\n                long limit = (1L << (n + 1 - a)) - 3;\n                if (k <= tot || dp[a] > 0 && (k - tot + dp[a] - 1) / dp[a] <= limit) {\n                    out.println(\"YES \" + a);\n                    continue L;\n                }\n                tot += dp[a] * limit;\n            }\n            out.println(\"NO\");\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 OlyaAndMagicalSquare().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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "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<List<Integer>> gr = new ArrayList<>();\n\n    long MOD = 1_000_000_007;\n\n    public void solve() {\n        StringBuilder sb = new StringBuilder();\n        int q = io.ri();\n        for(int i = 0; i < q; i++){\n            long n = io.readLong();\n            long k = io.readLong();\n            if(i>0)sb.append(System.lineSeparator());\n            boolean done = false;\n\n            if(n==2 && k == 3){\n                sb.append(\"NO\");\n                done = true;\n            }\n\n            for(int p = 0;n>0 && !done;p++, n--){\n                long count = (1L << (p*2));\n                if(k>count){\n                    k-=count;\n                }else{\n\n                    long path = p==0?1:(1L<<(p-1))*2+((1L<<(p-1))-1)*2+1;\n\n                    if(k<path){\n                        sb.append(\"YES \" + n);\n                    }else{\n                        sb.append(\"YES \" + (n-1));\n                    }\n                    done = true;\n                }\n            }\n\n\n            if(!done){\n                sb.append(\"NO\");\n            }\n\n        }\n        io.writeLine(sb.toString());\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<n.length;i++)r[i]=Long.parseLong(n[i]);\n        return r;\n    }\n    public int[] readIntArray() {\n        String[]n=this.readLine().trim().split(\"\\\\s+\");int[]r=new int[n.length];\n        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);\n        return r;\n    }\n    public int[] readIntArray(int n) {\n        int[] res = new int[n];\n        char[] all = this.readLine().toCharArray();\n        int cur = 0;boolean have = false;\n        int k = 0;\n        boolean neg = false;\n        for(int i = 0;i<all.length;i++){\n            if(all[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", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "/*\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 x1080D\n   {\n      public static void main(String hi[]) throws Exception\n      {\n         long[] dp = new long[32];\n         for(int i=1; i <= 31; i++)\n            dp[i] = 1+4*dp[i-1];\n         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int T = Integer.parseInt(st.nextToken());\n         StringBuilder sb = new StringBuilder();\n         matcha:while(T-->0)\n         {\n            st = new StringTokenizer(infile.readLine());\n            int N = Integer.parseInt(st.nextToken());\n            long K = Long.parseLong(st.nextToken());\n            if(N >= 32 || K == 1)\n               sb.append(\"YES \"+(N-1)+\"\\n\");\n            else if(dp[N] == K)\n               sb.append(\"YES 0\\n\");\n            else if(dp[N] < K)\n               sb.append(\"NO\\n\");\n            else\n            {\n               long total = 3L;\n               long length = 2;\n               for(int res=N-1; res >= 0; res--)\n               {\n                  long min = 1+3*dp[N-1-res];\n                  long max = min+dp[N-1];\n                  long cansplit = total-2*length+1;\n                  max += dp[res]*cansplit;\n                  if(min <= K && K <= max)\n                  {\n                     sb.append(\"YES \"+res+\"\\n\");\n                     continue matcha;\n                  }\n                  length <<= 1;\n                  total *= 4;\n               }\n               sb.append(\"NO\\n\");\n            }\n         }\n         System.out.print(sb);\n      }\n   }", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "//package que_a;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n    InputStream is;\n    PrintWriter out;\n    \n    long mod = (long)(1e9 + 7), inf = (long)(3e18);\n    \n    void solve() {\n        //SZ = sieve(); //SZ = 1000001;\n        int q = ni();\n        while(q-- > 0) {\n            long n = nl(), k = nl();\n            if(n <= 31) {\n                long m = (long)(Math.pow(4, n));\n                long x = (m - 1) / 3;\n                if(k > x) {\n                    out.println(\"NO\");  continue;\n                }\n                long b = 0, p = 1, d = 1; x = 2;\n                while(k > b) {\n                    n--;\n                    k -= p;\n                    m /= 4;     if(m == 0)  break;\n                    b += d * (m - 1) / 3;\n                    p += x;\n                    x <<= 1;\n                    d += x;\n                }\n                out.println((n >= 0 && k >= 0 && k <= b) ? (\"YES \"+ n) : \"NO\");\n            } else {\n                out.println(\"YES \"+ (n-1));\n            }\n        }\n    }\n\n    long mp(long b, long e, long mod) {\n        b %= mod;\n        long r = 1;\n        while(e > 0) {\n            if((e & 1) == 1) {\n                r *= b; r %= mod;\n            }\n            b *= b; b %= mod;\n            e >>= 1;\n        }\n        return r;\n    }\n\n    //---------- I/O Template ----------\n    \n    public static void main(String[] args) { new utkarsh().run(); }\n    void run() { \n        is = System.in; \n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte() { \n        if(ptr >= len) { ptr = 0; \n            try { len = is.read(input); } \n            catch(IOException e) { throw new InputMismatchException(); } \n            if(len <= 0) { return -1; } \n        } return input[ptr++];\n    }\n    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n    int skip() { \n        int b = readByte(); \n        while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n        return b;\n    }\n    \n    char nc() { return (char)skip(); }\n    String ns() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    String nLine() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    int ni() { \n        int n = 0, b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        if(b == -1) { return -1; }  //no input \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n    long nl() { \n        long n = 0L;    int b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n\n    double nd() { return Double.parseDouble(ns()); }\n    float nf() { return Float.parseFloat(ns()); }\n    int[] na(int n) { \n        int a[] = new int[n]; \n        for(int i = 0; i < n; i++) { a[i] = ni(); } \n        return a;\n    }\n    char[] ns(int n) { \n        char c[] = new char[n]; \n        int i, b = skip(); \n        for(i = 0; i < n; i++) { \n            if(isSpaceChar(b)) { break; } \n            c[i] = (char)b; b = readByte(); \n        } return i == n ? c : Arrays.copyOf(c,i);\n    }\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\t\n\tlong oo = (long)2e18;\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\tint t = fs.nextInt();\n\t\twhile(t-->0) {\n\t\t\tint n = fs.nextInt();\n\t\t\tlong k = fs.nextLong();\n\t\t\tlong toCut = 1, numSquares = 1, free = 0;\n\t\t\tint cuts = 0;\n\t\t\twhile(true) {\n\t\t\t\tif(cuts >= n) {\n\t\t\t\t\tk = oo;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tk -= toCut;\n\t\t\t\tif(k < 0) {\n\t\t\t\t\tk = oo;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcuts++;\n\t\t\t\ttry {\n\t\t\t\t\tfree = Math.addExact(free, Math.multiplyExact(numSquares, getVal(n-cuts)));\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tk = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(free >= k) {\n\t\t\t\t\tk = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ttoCut += (1L<<cuts);\n\t\t\t\tnumSquares += (1L<<(cuts+1));\n\t\t\t}\n\t\t\tif(k == 0) {\n\t\t\t\tout.printf(\"YES %d\\n\", n-cuts);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tout.printf(\"NO\\n\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\tlong getVal(int n) {\n\t\tif(n > 31) return oo;\n\t\tlong last = 0, cur = 0;\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tcur = 1 + 4*last;\n\t\t\tlast = cur;\n\t\t}\n\t\treturn cur;\n\t}\n\t\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}                \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n\t\n}", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class code {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint q = sc.nextInt();\n\t\tlong[] d = new long[30];\n\t\td[0] = 1;\n\t\tfor(int i=1;i<30;i++) d[i] = d[i-1]*4;\n\t\tfor(int z=0;z<q;z++){\n\t\t    long r = 0;\n\t\t    long n = sc.nextLong();\n\t\t    long k = sc.nextLong();\n\t\t    long c = 1;\n\t\t    while(k>0&&n>=1){\n\t\t        if(k<=r) {\n\t\t            k=0;\n\t\t            break;\n\t\t        }\n\t\t        n--;\n\t\t        k-=c;\n\t\t        if(k<=0) break;\n\t\t        \n\t\t        \n\t\t        if(n>30) {\n\t\t            k=0;\n\t\t            break;\n\t\t        }\n\t\t        for(int i=0;i<(int)n;i++){\n\t\t            r += d[i]*(c*2-1);\n\t\t            if(k<=r) {\n\t\t                k=0;\n\t\t                break;\n\t\t            }\n\t\t        }\n\t\t        if(k<=r) {\n\t\t            k=0;\n\t\t            break;\n\t\t        }\n\t\t        c*=2;\n\t\t        c++;\n\t\t    }\n\t\t    if(k==0) System.out.println(\"YES \"+n);\n\t\t    else System.out.println(\"NO\");\n\t\t}\n\t}\n}\n\n\n/*\nNO\nYES 0\nYES 0\nNO\nNO\nYES 999999942\nYES 59\nYES 63\nYES 2\nNO\nYES 1\nYES 1\nNO\nNO\nYES 0\nYES 0*/", "complexity": "logn", "problem": "1080_D. Olya and magical square", "from": "CODEFORCES"}
{"src": "//package round503;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\n\npublic class B2 {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\t// 12123432\n\t// 12343212\n\t\n\tint qc = 0;\n\tint n;\n\t\n\tint[] table;\n\t\n\tint val(int x)\n\t{\n\t\tif(table[x] != Integer.MIN_VALUE)return table[x];\n\t\tif(qc > 60)throw new RuntimeException();\n\t\tout.println(\"? \" + (x+1));\n\t\tout.flush();\n\t\ttable[x] = ni();\n\t\t\n\t\tif(table[x] == table[(x+table.length/2) % table.length]){\n\t\t\tif(x >= n/2)x -= n/2;\n\t\t\tout.println(\"! \" + (x+1));\n\t\t\tout.flush();\n\t\t\tthrow new IllegalStateException();\n\t\t}\n\t\treturn table[x];\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tn = ni();\n\t\tif(n % 4 != 0){\n\t\t\tout.println(\"! -1\");\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n\t\ttable = new int[n];\n\t\tArrays.fill(table, Integer.MIN_VALUE);\n\t\tRandom gen = new Random(1);\n\t\ttry{\n\t\t\touter:\n\t\t\twhile(true){\n\t\t\t\tint pu = gen.nextInt(n);\n\t\t\t\tint pd = (pu+n/2)%n;\n\t\t\t\tint pl = (pu + gen.nextInt(n/2-1)+1)%n;\n\t\t\t\tint pr = (pl+n/2)%n;\n\t\t\t\t\n\t\t\t\tint vu = val(pu), vd = val(pd);\n\t\t\t\tint vl = val(pl), vr = val(pr);\n\t\t\t\tif(cross(vu, vl, vd, vr)){\n\t\t\t\t}else if(cross(vu, vr, vd, vl)){\n\t\t\t\t\tint npu = pr, npl = pu;\n\t\t\t\t\tint npd = pl, npr = pd;\n\t\t\t\t\tpu = npu; pl = npl;\n\t\t\t\t\tpd = npd; pr = npr;\n\t\t\t\t\tvu = val(pu);\n\t\t\t\t\tvl = val(pl);\n\t\t\t\t\tvd = val(pd);\n\t\t\t\t\tvr = val(pr);\n\t\t\t\t}else{\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t\t// u-l d-r\n\t\t\t\twhile(true){\n\t\t\t\t\tint pul = h(pu, pl, n);\n\t\t\t\t\tint vul = val(pul);\n\t\t\t\t\tint pdr = h(pd, pr, n);\n\t\t\t\t\tint vdr = val(pdr);\n\t\t\t\t\tif(cross(vul, vu, vdr, vd)){\n\t\t\t\t\t\tpl = pul; vl = vul;\n\t\t\t\t\t\tpr = pdr; vr = vdr;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tpu = pul; vu = vul;\n\t\t\t\t\t\tpd = pdr; vd = vdr;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}catch(IllegalStateException e)\n\t\t{\n\t\t}\n\t}\n\t\n\tint h(int a, int b, int n)\n\t{\n\t\tif(a > b){\n\t\t\tb += n;\n\t\t}\n\t\tint u = (a+b)/2;\n\t\tif(u >= n)u -= n;\n\t\treturn u;\n\t}\n\t\n\tboolean cross(int a, int b, int c, int d)\n\t{\n\t\treturn Integer.signum(c-a) != Integer.signum(d-b);\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 B2().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// \n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class B {\n    public static PrintWriter out;\n    public static BufferedReader bf;\n    public static int n;\n    public static int[] a;\n    public static void main(String[] args) throws Exception {\n        bf = new BufferedReader(new InputStreamReader(System.in));\n        // Scanner scan = new Scanner(System.in);\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n        n = Integer.parseInt(bf.readLine());\n        a = new int[n];\n        Arrays.fill(a, Integer.MAX_VALUE);\n        if((n/2) % 2 != 0) {\n          out.println(\"! \" + (-1));\n          out.flush();\n          out.close(); System.exit(0);\n        }\n\n        ask(0);\n        ask(opp(0));\n\n        int low = 0;\n        int high = opp(0);\n        while(true) {\n          int test = (low + high)/2;\n          ask(test);\n          ask(opp(test));\n          int l_1 = a[low];\n          int l_2 = a[test];\n          int r_1 = a[opp(low)];\n          int r_2 = a[opp(test)];\n          if(1L*(l_1 - r_1)*(l_2 - r_2) < 0L) {\n            high = test;\n          }\n          else low = test;\n        }\n\n        // StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        // int n = Integer.parseInt(st.nextToken());\n        // int n = scan.nextInt();\n\n        //out.close(); System.exit(0);\n    }\n    public static int ask(int i) throws Exception { // 0 thru n-1;\n      out.println(\"? \" + (i+1));\n      out.flush();\n      int k = Integer.parseInt(bf.readLine());\n      a[i] = k;\n      if(a[i] == a[opp(i)]) {\n        out.println(\"! \" + (i+1));\n        out.flush();\n        out.close(); System.exit(0);\n      }\n\n      return k;\n    }\n    public static int opp(int k) {\n      return ((k + n/2) % n);\n    }\n}\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class CFB {\n    static int n;\n    static FastScanner in;\n    public static void main(String[] args) throws Exception {\n        in = new FastScanner(System.in);\n        n = in.nextInt();\n        int a = query(1);\n        if(((a % 2)+2) % 2== 1){\n            System.out.println(\"! -1\");\n            return;\n        }\n        if(a == 0){\n            System.out.println(\"! 1\");\n            return;\n        }\n        bins(1 , n/2 + 1 , a , -a);\n    }\n    static void bins(int lo , int hi , int losign , int hisign){\n        int mid = (lo + hi)/2;\n        int k = query(mid);\n        if(k == 0){\n            System.out.println(\"! \" + mid);\n            System.exit(0);\n        }\n        if(k > 0 && losign > 0 || k < 0 && losign < 0){\n            bins(mid , hi , k , hisign);\n        }\n        else {\n            bins(lo , mid , losign , k);\n        }\n\n    }\n    static int query(int i){\n        System.out.println(\"? \" + i);\n        int a1 = in.nextInt();\n        System.out.println(\"? \" + ((i + (n/2)) > n ? (i - (n/2)) : (i + (n/2))));\n        int a2 = in.nextInt();\n        return a1 - a2;\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) 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", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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        BTheHat solver = new BTheHat();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BTheHat {\n        InputReader in;\n        OutputWriter out;\n        int n;\n\n        int ask(int student) {\n            student %= n;\n            out.println(\"? \" + (student + 1));\n            out.flush();\n            return in.nextInt();\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            this.in = in;\n            this.out = out;\n\n            n = in.nextInt();\n            int a = ask(0), b = ask(n / 2);\n            if ((a + b) % 2 != 0) {\n                out.println(\"! -1\");\n                out.flush();\n                return;\n            }\n            if (a == b) {\n                out.println(\"! 1\");\n                out.flush();\n                return;\n            }\n\n            int lo = 0, hi = n / 2;\n            while (lo < hi) {\n                int mid = (lo + hi) / 2;\n                int f1 = ask(mid), f2 = ask(mid + n / 2);\n                if (f1 == f2) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if ((a > b) == (f1 > f2)) {\n                    lo = mid + 1;\n                } else {\n                    hi = mid - 1;\n                }\n            }\n            out.println(\"! \" + (lo + 1));\n            out.flush();\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 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 flush() {\n            writer.flush();\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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.io.Reader;\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        MyInput in = new MyInput(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        int n;\n        MyInput in;\n        PrintWriter out;\n\n        public void solve(int testNumber, MyInput in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n\n            n = in.nextInt();\n\n            if (n / 2 % 2 == 1) {\n                answer(-1);\n                return;\n            }\n\n            int low = 0, high = n / 2;\n            int diff = query(low + n / 2) - query(low);\n            while (diff != 0) {\n                int mid = (low + high) / 2;\n                int d = query(mid + n / 2) - query(mid);\n                if (d == 0 || diff > 0 == d > 0) {\n                    diff = d;\n                    low = mid;\n                } else {\n                    high = mid;\n                }\n            }\n            answer(low);\n        }\n\n        int query(int i) {\n            out.println(\"? \" + (i % n + 1));\n            out.flush();\n            return in.nextInt();\n        }\n\n        void answer(int i) {\n            out.println(\"! \" + (i < 0 ? i : (i % n + 1)));\n        }\n\n    }\n\n    static class MyInput {\n        private final BufferedReader in;\n        private static int pos;\n        private static int readLen;\n        private static final char[] buffer = new char[1024 * 8];\n        private static char[] str = new char[500 * 8 * 2];\n        private static boolean[] isDigit = new boolean[256];\n        private static boolean[] isSpace = new boolean[256];\n        private static boolean[] isLineSep = new boolean[256];\n\n        static {\n            for (int i = 0; i < 10; i++) {\n                isDigit['0' + i] = true;\n            }\n            isDigit['-'] = true;\n            isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n            isLineSep['\\r'] = isLineSep['\\n'] = true;\n        }\n\n        public MyInput(InputStream is) {\n            in = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public int read() {\n            if (pos >= readLen) {\n                pos = 0;\n                try {\n                    readLen = in.read(buffer);\n                } catch (IOException e) {\n                    throw new RuntimeException();\n                }\n                if (readLen <= 0) {\n                    throw new MyInput.EndOfFileRuntimeException();\n                }\n            }\n            return buffer[pos++];\n        }\n\n        public int nextInt() {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(len, isSpace);\n            int i = 0;\n            int ret = 0;\n            if (str[0] == '-') {\n                i = 1;\n            }\n            for (; i < len; i++) ret = ret * 10 + str[i] - '0';\n            if (str[0] == '-') {\n                ret = -ret;\n            }\n            return ret;\n        }\n\n        public char nextChar() {\n            while (true) {\n                final int c = read();\n                if (!isSpace[c]) {\n                    return (char) c;\n                }\n            }\n        }\n\n        int reads(int len, boolean[] accept) {\n            try {\n                while (true) {\n                    final int c = read();\n                    if (accept[c]) {\n                        break;\n                    }\n                    if (str.length == len) {\n                        char[] rep = new char[str.length * 3 / 2];\n                        System.arraycopy(str, 0, rep, 0, str.length);\n                        str = rep;\n                    }\n                    str[len++] = (char) c;\n                }\n            } catch (MyInput.EndOfFileRuntimeException e) {\n            }\n            return len;\n        }\n\n        static class EndOfFileRuntimeException extends RuntimeException {\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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        BTheHat solver = new BTheHat();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BTheHat {\n        PrintWriter out;\n        InputReader in;\n        int n;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            this.out = out;\n            this.in = in;\n            n = in.NextInt();\n            int desiredPair = -1;\n            int result = query(1);\n            if (result != 0) {\n                int l = 2, r = 1 + n / 2;\n                while (l < r) {\n                    int m = (l + r) / 2;\n                    int mRes = query(m);\n                    if (mRes == 0) {\n                        desiredPair = m;\n                        break;\n                    } else if (mRes == result) {\n                        l = m + 1;\n                    } else {\n                        r = m;\n                    }\n                }\n            } else {\n                desiredPair = 1;\n            }\n            out.println(\"! \" + desiredPair);\n        }\n\n        private int query(int i) {\n            int iV = queryValue(i);\n            int iN2V = queryValue(i + n / 2);\n            if (iV < iN2V) {\n                return -1;\n            } else if (iV > iN2V) {\n                return 1;\n            }\n            return 0;\n        }\n\n        private int queryValue(int i) {\n            out.println(\"? \" + i);\n            out.flush();\n            return in.NextInt();\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", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        FastReader in;\n        PrintWriter out;\n        int n;\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.nextInt();\n            if (n % 4 != 0) {\n                out.println(\"! -1\");\n                return;\n            }\n            int low = 0;\n            int high = n >> 1;\n            int fSign = Integer.signum(BValue(low));\n            if (fSign == 0) {\n                out.println(\"! \" + (low + 1));\n                return;\n            }\n            while (high - low > 1) {\n                int mid = (high + low) >> 1;\n                int mSign = Integer.signum(BValue(mid));\n                if (mSign == 0) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if (mSign == -fSign) {\n                    high = mid;\n                } else {\n                    low = mid;\n                }\n            }\n            out.println(\"! -1\");\n        }\n\n        public int BValue(int index) {\n            out.println(\"? \" + (index + 1));\n            out.flush();\n            int f = in.nextInt();\n            out.println(\"? \" + (index + 1 + (n >> 1)));\n            out.flush();\n            int s = in.nextInt();\n            return f - s;\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic FS in;\n\t\n\tstatic int N;\n\tstatic final boolean debug = false;\n\tstatic int inp[] = new int[] {1,2,3,2,1,0};\n\tpublic static void main(String[] args) {\n\t\tin = new FS();\n\t\tif(!debug) N = in.nextInt();\n\t\telse N = inp.length;\n\t\tint x = solve(0, N/2-1, N/2, N-1);\n\t\tout.println(\"! \"+(x+1));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\t\n\tstatic int solve(int l1, int r1, int l2, int r2) {\n\t\tint sz = r1-l1+1;\n\t\tif(sz <= 0) return -2;\n\t\tint a1 = query(l1);\n\t\tint a2 = query(l2);\n\t\tif(a1 == a2) return l1;\n\t\t\n\t\tif(sz == 1) return -2;\n\t\t\n\t\tint b1 = query(l1+sz/2);\n\t\tint b2 = query(l2+sz/2);\n\t\tif(b1 == b2) return l1 + sz/2;\n\t\t\n\t\tif(sz == 2) return -2;\n\t\t\n\t\tint d1 = a2-a1;\n\t\tint d2 =  b2-b1;\n\t\tif((d1 < 0 && d2 > 0) || (d1 > 0 && d2 < 0)) {\n\t\t\treturn solve(l1+1, l1 + sz/2 - 1, l2+1, l2 + sz/2 - 1);\n\t\t}\n\t\telse {\n\t\t\treturn solve(l1 + sz/2 + 1, r1, l2 + sz/2 + 1, r2);\n\t\t}\n\t}\n\t\n\tstatic int query(int a) {\n\t\tout.println(\"? \"+(a+1));\n\t\tout.flush();\n\t\tif(debug) return inp[a];\n\t\telse return in.nextInt();\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", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class B {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tMyScanner sc = new MyScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tif (N / 2 % 2 == 1) {\n\t\t\toutput(-1, out);\n\t\t} else {\n\t\t\tint half = N / 2;\n\t\t\tint l = 1, r = half;\n\t\t\tint first = query(half, out, sc);\n\t\t\tint next = query(2 * half, out, sc);\n\t\t\tif (first == next) {\n\t\t\t\toutput(half, out);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tboolean less = first < next;\n\t\t\twhile (l + 1 < r) {\n\t\t\t\tint med = (l + r) / 2;\n\t\t\t\tfirst = query(med, out, sc);\n\t\t\t\tnext = query(med + half, out, sc);\n\t\t\t\tif (first == next) {\n\t\t\t\t\toutput(med, out);\n\t\t\t\t\treturn;\n\t\t\t\t} else if (first < next == less) {\n\t\t\t\t\tr = med;\n\t\t\t\t} else {\n\t\t\t\t\tl = med + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\toutput(l, out);\n\t\t}\n\t}\n\t\n\tstatic int query(int pos, PrintWriter out, MyScanner sc) {\n\t\tout.println(\"? \" + pos);\n\t\tout.flush();\n\t\treturn sc.nextInt();\n\t}\n\t\n\tstatic void output(int pos, PrintWriter out) {\n\t\tout.println(\"! \" + pos);\n\t\tout.flush();\n\t}\n\t\n\tstatic class MyScanner {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tokenizer;\n\t\t\n\t\tpublic MyScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\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\ttokenizer = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 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\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\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\tstatic class Task {\n\t\tint n = 0;\n\t\tint query(int p, InputReader in) {\n\t\t\tp %= n;\n\t\t\tif (p <= 0) p += n;\n\t\t\tSystem.out.println(\"? \" + p);\n\t\t\tSystem.out.flush();\n\t\t\tint x = in.nextInt();\n\t\t\treturn x;\n\t\t}\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tn = in.nextInt();\n\t\t\tif (n % 4 != 0) {\n\t\t\t\tout.println(\"! -1\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint p = query(0, in);\n\t\t\tint q = query(n / 2, in);\n\t\t\tint l = 0;\n\t\t\tint r = n / 2;\n\t\t\tif (p == q) {\n\t\t\t\tout.println(\"! \" + (n / 2));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twhile (l + 1 < r) {\n\t\t\t\tint mid = (l + r) / 2;\n\t\t\t\tint u = query(mid, in);\n\t\t\t\tint v = query(mid + n / 2, in);\n\t\t\t\tif (u == v) {\n\t\t\t\t\tout.println(\"! \" + (mid + n / 2));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ((p < q) == (u < v)) {\n\t\t\t\t\tl = mid;\n\t\t\t\t} else {\n\t\t\t\t\tr = mid;\n\t\t\t\t}\n\t\t\t}\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 stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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        int N;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            N = in.nextInt();\n            int low = 1;\n            int lowVal = getval(1, out, in);\n            int high = N / 2 + 1;\n            int highVal = -lowVal;\n            if (Math.abs(lowVal) % 2 == 1) {\n                out.println(\"! -1\");\n                out.flush();\n            } else {\n                while (low < high) {\n                    int mid = (low + high) / 2;\n                    int a = getval(mid, out, in);\n                    if (Integer.signum(a) == 0) {\n                        out.println(\"! \" + mid);\n                        out.flush();\n                        return;\n                    } else {\n                        if (Integer.signum(a) == Integer.signum(lowVal)) {\n                            low = mid + 1;\n                        } else {\n                            high = mid;\n                        }\n                    }\n                }\n                out.println(\"! \" + low);\n                out.flush();\n            }\n        }\n\n        int getval(int i, PrintWriter out, InputReader in) {\n            out.println(\"? \" + i);\n            out.flush();\n            int a = in.nextInt();\n            out.println(\"? \" + (i + N / 2));\n            out.flush();\n            int b = in.nextInt();\n            return a - b;\n        }\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            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", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main {\n\tfinal static int MAXN = 100005;\n\tstatic int n;\n\tstatic Scanner cin;\n\tstatic int[] a;\n\tstatic boolean[] used;\n\tpublic static int Query(int x) {\n\t\tSystem.out.print(\"? \");\n\t\tSystem.out.println(x);\n\t\tSystem.out.flush();\n\t\tint a = cin.nextInt();\n\t\treturn a;\n\t}\n\tpublic static int Q(int x) {\n\t\tif(used[x]) return a[x];\n\t\tused[x] = true;\n\t\ta[x] = Query(x) - Query(x + n / 2);\n\t\tif(a[x] == 0) {\n\t\t\tSystem.out.print(\"! \");\n\t\t\tSystem.out.println(x);\n\t\t\tSystem.out.flush();\n\t\t\tcin.close();\n\t\t\tSystem.exit(0);\n\t\t}\n\t\treturn a[x];\n\t}\n\tpublic static void main(String[] args) {\n\t\tcin = new Scanner(System.in);\n\t\tn = cin.nextInt();\n\t\ta = new int[MAXN];\n\t\tused = new boolean[MAXN];\n\t\tif(n % 4 != 0) {\n\t\t\tSystem.out.println(\"! -1\\n\");\n\t\t\tSystem.out.flush();\n\t\t\tcin.close();\n\t\t\treturn;\n\t\t}\n\t\tint l = 1, r = n / 2, mid;\n\t\twhile(l <= r) {\n\t\t\tmid = (l + r) / 2;\n\t\t\tint x = Q(mid);\n\t\t\tif(Q(l) * x < 0) {\n\t\t\t\tr = mid - 1;\n\t\t\t} else if(x * Q(r) < 0) {\n\t\t\t\tl = mid + 1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"! -1\\n\");\n\t\tSystem.out.flush();\n\t\tcin.close();\n\t}\n}\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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           //       |    \\   /        \\  |    |   -----   -------\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        System.out.println(\"? \"+1);\n        int a=sc.i();\n        System.out.println(\"? \"+(1+n/2));\n        int b=sc.i();\n        if(a==b)\n        {\n            System.out.println(\"! \"+1);\n            System.exit(0);\n        }\n        int inv=0;\n        if(a>b)\n        inv=1;\n        \n        int low=2;\n        int high=n/2;\n        int q=0;\n        while(low<=high)\n        {\n            if(q==60)\n            break;\n            int mid=(low+high)/2;\n            System.out.println(\"? \"+mid);\n            a=sc.i();\n            System.out.println(\"? \"+(mid+n/2));\n            b=sc.i();\n            if(a==b)\n            {\n                System.out.println(\"! \"+mid);\n                System.exit(0);\n            }\n            else if(a<b)\n            {\n                if(inv==0)\n                low=mid+1;\n                else\n                high=mid-1;\n            }\n            \n            else\n            {\n                if(inv==0)\n                high=mid-1;\n                else\n                low=mid+1;\n            }\n            q++;\n        }\n        System.out.println(\"! -1\");\n        out.flush();\n    }\n}", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        FastReader in;\n        PrintWriter out;\n        int n;\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.nextInt();\n            if (n % 4 != 0) {\n                out.println(\"! -1\");\n                return;\n            }\n            int low = 0;\n            int high = n >> 1;\n            if (BValue(low) == 0) {\n                out.println(\"! \" + (low + 1));\n                return;\n            }\n            int fSign = Integer.signum(BValue(low));\n            while (high - low > 1) {\n                int mid = (high + low) >> 1;\n                int mSign = Integer.signum(BValue(mid));\n                if (mSign == 0) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if (mSign == -fSign) {\n                    high = mid;\n                } else {\n                    low = mid;\n                }\n            }\n            out.println(\"! -1\");\n        }\n\n        public int BValue(int index) {\n            out.println(\"? \" + (index + 1));\n            out.flush();\n            int f = in.nextInt();\n            out.println(\"? \" + (index + 1 + (n >> 1)));\n            out.flush();\n            int s = in.nextInt();\n            return f - s;\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Div1_503B {\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\tint N = Integer.parseInt(reader.readLine());\n\t\tprinter.println(\"? 1\");\n\t\tprinter.flush();\n\t\tint v1 = Integer.parseInt(reader.readLine());\n\n\t\tprinter.println(\"? \" + (1 + N / 2));\n\t\tprinter.flush();\n\t\tint v2 = Integer.parseInt(reader.readLine());\n\n\t\tif ((v1 + v2) % 2 != 0) {\n\t\t\tprinter.println(\"! -1\");\n\t\t\tprinter.close();\n\t\t\treturn;\n\t\t}\n\n\t\tif (v1 == v2) {\n\t\t\tprinter.println(\"! 1\");\n\t\t\tprinter.close();\n\t\t\treturn;\n\t\t}\n\t\tboolean less = v1 < v2;\n\n\t\tint low = 1;\n\t\tint high = (1 + N / 2);\n\n\t\twhile (low != high) {\n\t\t\tint mid = (low + high) >> 1;\n\n\t\t\tprinter.println(\"? \" + mid);\n\t\t\tprinter.flush();\n\t\t\tint r1 = Integer.parseInt(reader.readLine());\n\n\t\t\tint q2 = (mid + N / 2);\n\t\t\tif (q2 > N) {\n\t\t\t\tq2 -= N;\n\t\t\t}\n\t\t\tprinter.println(\"? \" + q2);\n\t\t\tprinter.flush();\n\t\t\tint r2 = Integer.parseInt(reader.readLine());\n\n\t\t\tif (r1 == r2) {\n\t\t\t\tprinter.println(\"! \" + mid);\n\t\t\t\tprinter.close();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (r1 < r2 == less) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\tprinter.println(\"! \" + low);\n\t\tprinter.close();\n\t\treturn;\n\t}\n}\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "//package contests.CF1019;\n\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int n = sc.nextInt();\n        int half = n/2;\n        pw.println(\"? 1\");\n        pw.flush();\n        int a = sc.nextInt();\n        pw.println(\"? \" + (1+half));\n        pw.flush();\n        int b = sc.nextInt();\n        if(a - b == 0){\n            pw.println(\"! 1\");\n        }\n        else\n        if((a - b)%2 != 0)\n        {\n            pw.println(\"! -1\");\n        }else{\n            boolean greater = a > b;\n            int lo = 1;\n            int hi = half;\n\n            boolean ans = false;\n            while(lo <= hi){\n                int mid = (lo + hi) /2;\n                pw.println(\"? \" + mid);\n                pw.flush();\n                a = sc.nextInt();\n                pw.println(\"? \" + (mid+half));\n                pw.flush();\n                b = sc.nextInt();\n\n                if(a == b){\n                    pw.println(\"! \" + mid);\n                    ans = true;\n                    break;\n                }\n\n                if(a > b != greater){\n                    hi = mid-1;\n                }else{\n                    lo = mid+1;\n                    greater = a>b;\n                }\n            }\n\n            if(!ans){\n                pw.println(\"! -1\");\n            }\n\n        }\n\n        pw.flush();\n        pw.close();\n    }\n\n\n\n    static int[][] packD(int n, int[] from, int[] to) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int f : from) if(f != -1) p[f]++;\n        for (int i = 0; i < n; i++) g[i] = new int[p[i]];\n        for (int i = 0; i < from.length; i++) if(from[i] != -1) {g[from[i]][--p[from[i]]] = to[i];}\n        return g;\n    }\n\n    static void shuffle(int[] a)\n    {\n        int n = a.length;\n        for(int i = 0; i < n; i++)\n        {\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    static class Scanner\n    {\n        StringTokenizer st; BufferedReader br;\n        public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n        public Scanner(String s) throws FileNotFoundException {\tbr = new BufferedReader(new FileReader(new File(s)));}\n        public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}\n        public int nextInt() throws IOException {return Integer.parseInt(next());}\n        public long nextLong() throws IOException {return Long.parseLong(next());}\n        public String nextLine() throws IOException {return br.readLine();}\n        public boolean ready() throws IOException {return br.ready();}\n    }\n}\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Solution{\n\t\n\tstatic FastScanner fs = new FastScanner();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic int n, d;\n\t\n\t\n    public static void main(String[] args) throws IOException {\n    \t\n\t\t\n//    \tFastScanner fs = new FastScanner();\n//    \tPrintWriter out = new PrintWriter(System.out);\n    \t\t\n    \tint tt = 1;\n    \twhile(tt-->0) {\n    \t\t\n    \t\n    \t\tn = fs.nextInt();\n    \t\tint l = 1, r = 1 + n/2;\n    \t\t\n    \t\td = getB(l);\n    \t\tif(d%2!=0) {\n    \t\t\tout.println(\"! -1\");\n    \t\t\tout.flush();\n    \t\t\treturn;\n    \t\t}\n    \t\t\n    \t\tif(d==0) {\n    \t\t\tout.println(\"! 1\");\n    \t\t\tout.flush();\n    \t\t\treturn;\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\twhile(l<r) {\n    \t\t\tint mid = (l+r)/2;\n    \t\t\tif(check(mid)) {\n    \t\t\t\tl = mid + 1;\n    \t\t\t}\n    \t\t\telse {\n    \t\t\t\tr = mid;\n    \t\t\t}\n    \t\t\tint f = 1;\n    \t\t}\n    \t\t\n    \t\t\n    \t\tout.println(\"! \"+l);\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    \t\n    \tout.close();\n    \t\t\n    }\n    \n    \n    static boolean check(int i) {\n    \tint k = getB(i);\n    \tif(sig(d)==sig(k)) {\n    \t\treturn true;\n    \t}\n    \treturn false;\n    }\n    \n    \n    static int getB(int i) {\n    \tout.println(\"? \"+i);\n    \tout.flush();\n    \tint x1 = fs.nextInt();\n    \tint j = i + n/2;\n    \tif(j>n) j -= n;\n    \tout.println(\"? \"+j);\n    \tout.flush();\n    \tint x2 = fs.nextInt();\n    \treturn x1 - x2;\n    }\n    \n    \n    static int sig(int x) {\n    \tif(x>0) return 1;\n    \telse if(x<0) return -1;\n    \treturn 0;\n    }\n    \n    \n    \n   \n    \n    \n    \n    \n    \n    static final Random random=new Random();\n    \n    static <T> void shuffle(T[] arr) {\n    \tint n = arr.length;\n    \tfor(int i=0;i<n;i++\t) {\n    \t\tint k = random.nextInt(n);\n    \t\tT temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;\n    \t}\n    }\n    \n    \t\n    static void ruffleSort(int[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); int temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n    \n    static void ruffleSort(long[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); long temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n   \n  \n    \n    static void reverse(int[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tint temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    static void reverse(long[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tlong temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    \n    static <T> void reverse(T[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++) {\n    \t\tT temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \t\n    \t\n    static class FastScanner{\n    \tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    \tStringTokenizer st = new StringTokenizer(\"\");\n     \n    \tpublic String next(){\n    \t\twhile(!st.hasMoreElements()){\n    \t\t\ttry{\n    \t\t\t\tst = new StringTokenizer(br.readLine());\n    \t\t\t} catch(IOException e){\n    \t\t\t\te.printStackTrace();\n    \t\t\t}\n    \t\t}\n    \t\treturn st.nextToken();\n    \t}\n    \t\t\n    \tpublic String nextLine() throws IOException {\n    \t\treturn br.readLine();\n    \t}\n    \t\t\n    \tpublic int nextInt(){\n    \t\treturn Integer.parseInt(next());\n    \t}\n     \n    \tpublic int[] readArray(int n){\n    \t\tint[] a = new int[n];\n    \t\tfor(int i=0;i<n;i++)\n    \t\t\ta[i] = nextInt();\n    \t\treturn a;\n    \t}\n    \t\t\n    \tpublic long nextLong() {\n    \t\treturn Long.parseLong(next());\n    \t}\n    \t\t\n    \tpublic char nextChar() {\n    \t\treturn next().toCharArray()[0];\n    \t}\n    }\n   \t\n}\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.stream.IntStream;\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(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\n        Solver solver = new Solver();\n        solver.solve(in, out);\n        out.close();\n    }\n\n    static class Solver {\n        int n;\n        int n2;\n        InputReader in;\n        PrintWriter out;\n\n        public void solve(InputReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.readInt();\n            n2 = n/2;\n\n            int res = find();\n            out.print(\"! \");\n            out.println(res);\n        }\n\n        public int find() {\n            if (n%4 != 0) return -1;\n            int c = compare(0);\n            if (c == 0) return 1;\n            int s = 1;\n            int f = n2-1;\n            if (c > 0) {\n                s = n2+1;\n                f = n-1;\n            }\n            while (s <= f) {\n                int m = (s+f)/2;\n                int v = compare(m);\n                if (v == 0) return m+1;\n                else if (v < 0) s = m+1;\n                else f = m-1;\n            }\n            return -1;\n        }\n\n        public int compare(int z) {\n            out.print(\"? \");\n            out.println(z+1);\n            out.flush();\n            int r1 = in.readInt();\n            out.print(\"? \");\n            out.println((z+n2)%n+1);\n            out.flush();\n            int r2 = in.readInt();\n            return r1-r2;\n        }\n\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            this.reader = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String read() {\n            try {\n                if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                }\n            } catch (IOException ex) {\n                throw new RuntimeException(ex);\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int readInt() {\n            return Integer.parseInt(read());\n        }\n\n        public long readLong() {\n            return Long.parseLong(read());\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\n}", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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 ilyakor\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    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\n    int n;\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n      n = in.nextInt();\n      int base = calc(in, out, 0);\n      if (base == 0) {\n        out.printLine(\"! 1\");\n        out.flush();\n        return;\n      }\n      if (Math.abs(base) % 2 != 0) {\n        out.printLine(\"! -1\");\n        out.flush();\n        return;\n      }\n      int down = 0, up = n / 2;\n      int sdown = base < 0 ? -1 : 1;\n      int sup = up < 0 ? -1 : 1;\n      while (up - down > 1) {\n        int t = (up + down) / 2;\n        int cur = calc(in, out, t);\n        if (cur == 0) {\n          out.printLine(\"! \" + (t + 1));\n          out.flush();\n          return;\n        }\n        int scur = cur < 0 ? -1 : 1;\n        if (scur == sdown) {\n          down = t;\n        } else {\n          up = t;\n        }\n      }\n      throw new RuntimeException();\n    }\n\n    private int calc(InputReader in, OutputWriter out, int val) {\n      out.printLine(\"? \" + (val + 1));\n      out.flush();\n      int res1 = in.nextInt();\n      out.printLine(\"? \" + ((val + n / 2) % n + 1));\n      out.flush();\n      int res2 = in.nextInt();\n      return res1 - res2;\n    }\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    public void flush() {\n      writer.flush();\n    }\n\n  }\n\n  static class InputReader {\n\n    private InputStream stream;\n    private byte[] buffer = new byte[10000];\n    private int cur;\n    private int count;\n\n    public InputReader(InputStream stream) {\n      this.stream = stream;\n    }\n\n    public static boolean isSpace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int read() {\n      if (count == -1) {\n        throw new InputMismatchException();\n      }\n      try {\n        if (cur >= count) {\n          cur = 0;\n          count = stream.read(buffer);\n          if (count <= 0) {\n            return -1;\n          }\n        }\n      } catch (IOException e) {\n        throw new InputMismatchException();\n      }\n      return buffer[cur++];\n    }\n\n    public int readSkipSpace() {\n      int c;\n      do {\n        c = read();\n      } while (isSpace(c));\n      return c;\n    }\n\n    public int nextInt() {\n      int sgn = 1;\n      int c = readSkipSpace();\n      if (c == '-') {\n        sgn = -1;\n        c = read();\n      }\n      int res = 0;\n      do {\n        if (c < '0' || c > '9') {\n          throw new InputMismatchException();\n        }\n        res = res * 10 + c - '0';\n        c = read();\n      } while (!isSpace(c));\n      res *= sgn;\n      return res;\n    }\n\n  }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    private static final long MOD = 998244353;\n\n    static int[] readArray(int size, InputReader in, boolean subOne) {\n        int[] a = new int[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = in.nextInt() + (subOne ? -1 : 0);\n        }\n        return a;\n    }\n\n    static long[] readLongArray(int size, InputReader in) {\n        long[] a = new long[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = in.nextLong();\n        }\n        return a;\n    }\n\n    static void sortArray(int[] a) {\n        Random random = new Random();\n\n        for (int i = 0; i < a.length; i++) {\n            int randomPos = random.nextInt(a.length);\n            int t = a[i];\n            a[i] = a[randomPos];\n            a[randomPos] = t;\n        }\n        Arrays.sort(a);\n    }\n\n\n    public static void main(String[] args) throws FileNotFoundException {\n//        InputReader in = new InputReader(new FileInputStream(\"input.txt\"));\n//        PrintWriter out = new PrintWriter(new BufferedOutputStream(new FileOutputStream(\"milkvisits.out\")));\n//\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n        int n = in.nextInt();\n        if (n / 2 % 2 != 0) {\n            out.println(\"! -1\");\n            out.flush();\n            out.close();\n            return;\n        }\n\n        int[] a = new int[n];\n        Arrays.fill(a, Integer.MAX_VALUE);\n\n        int l1 = 0;\n        int r1 = l1 + n / 2;\n\n        int l2 = r1;\n        int r2 = n;\n\n        int ans = -1;\n\n        while (true) {\n            getValue(in, out, a, l1);\n            getValue(in, out, a, r1);\n\n            getValue(in, out, a, l2);\n            getValue(in, out, a, r2 % n);\n\n            if (a[l1] == a[l2]) {\n                ans = l1;\n                break;\n            }\n            if (a[r1] == a[r2 % n]) {\n                ans = r1;\n                break;\n            }\n\n            int m1 = (l1 + r1) / 2;\n            getValue(in, out, a, m1);\n\n            int m2 = (l2 + r2) / 2;\n            getValue(in, out, a, m2);\n\n            if (a[m1] == a[m2]) {\n                ans = m1;\n                break;\n            }\n\n            if ((a[l1] <= a[m1] && a[l2] <= a[m2]) || (a[l1] >= a[m1] && a[l2] >= a[m2])) {\n                if (a[l1] <= a[l2] && a[m1] >= a[m2]) {\n                    r1 = m1;\n                    r2 = m2;\n                    continue;\n                }\n\n                if (a[l1] >= a[l2] && a[m1] <= a[m2]) {\n                    r1 = m1;\n                    r2 = m2;\n                    continue;\n                }\n            }\n\n            if (a[l1] <= a[m1] && a[l2] >= a[m2] && a[l1] <= a[l2] && a[m1] >= a[m2]){\n                r1 = m1;\n                r2 = m2;\n                continue;\n            }\n\n            if (a[l1] >= a[m1] && a[l2] <= a[m2] && a[l1] >= a[l2] && a[m1] <= a[m2]){\n                r1 = m1;\n                r2 = m2;\n                continue;\n            }\n\n            l1 = m1;\n            l2 = m2;\n        }\n        out.println(\"! \" + (ans + 1));\n\n        out.close();\n    }\n\n    private static void getValue(InputReader in, PrintWriter out, int[] a, int l) {\n        if (a[l] == Integer.MAX_VALUE) {\n            out.println(\"? \" + (l + 1));\n            out.flush();\n            a[l] = in.nextInt();\n        }\n    }\n\n\n    private static boolean check(long x, long s, long a, List<Long> divA) {\n        int ind = binSearchRight(divA, x, 0, divA.size());\n        if (ind >= 0 && ind < divA.size()) {\n            long y = a / divA.get(ind);\n            return y <= s / x;\n        }\n        return false;\n    }\n\n    static int binSearchRight(List<Long> list, long key, int start, int end) {\n        int l = start - 1;\n        int r = end;\n        while (l < r - 1) {\n            int m = (l + r) / 2;\n            if (list.get(m) <= key) {\n                l = m;\n            } else {\n                r = m;\n            }\n        }\n        return l;\n    }\n\n    private static void outputArray(int[] ans, PrintWriter out, boolean addOne) {\n        StringBuilder str = new StringBuilder();\n        for (int i = 0; i < ans.length; i++) {\n            long an = ans[i] + (addOne ? 1 : 0);\n            str.append(an).append(' ');\n        }\n        out.println(str);\n    }\n\n    private static void outputArray(List<Integer> ans, PrintWriter out, boolean addOne) {\n        StringBuilder str = new StringBuilder();\n        for (int j = 0; j < ans.size(); j++) {\n            long i = ans.get(j);\n            long an = i + (addOne ? 1 : 0);\n            str.append(an);\n            if (j < ans.size() - 1) {\n                str.append(' ');\n            }\n        }\n        out.println(str);\n//        out.flush();\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 double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public char nextChar() {\n            return next().charAt(0);\n        }\n\n        public String nextWord() {\n            return next();\n        }\n\n        private List<Integer>[] readTree(int n) {\n            return readGraph(n, n - 1);\n        }\n\n        private List<Integer>[] readGraph(int n, int m) {\n            List<Integer>[] result = new ArrayList[n];\n            for (int i = 0; i < n; i++) {\n                result[i] = new ArrayList<>();\n            }\n            for (int i = 0; i < m; i++) {\n                int u = nextInt() - 1;\n                int v = nextInt() - 1;\n                result[u].add(v);\n                result[v].add(u);\n            }\n            return result;\n        }\n\n        private Map<Integer, Long>[] readWeightedGraph(int n, int m) {\n            Map<Integer, Long>[] result = new HashMap[n];\n            for (int i = 0; i < n; i++) {\n                result[i] = new HashMap<>();\n            }\n            for (int i = 0; i < m; i++) {\n                int u = nextInt() - 1;\n                int v = nextInt() - 1;\n                long w = nextLong();\n                result[u].put(v, Math.min(w, result[u].getOrDefault(v, Long.MAX_VALUE)));\n                result[v].put(u, Math.min(w, result[v].getOrDefault(u, Long.MAX_VALUE)));\n            }\n            return result;\n        }\n\n    }\n}", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        FastReader in;\n        PrintWriter out;\n        int n;\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            n = in.nextInt();\n            if (n % 4 != 0) {\n                out.println(\"! -1\");\n                return;\n            }\n            int low = 0;\n            int high = n >> 1;\n            if (BValue(low) == 0) {\n                out.println(\"! \" + (low + 1));\n                return;\n            }\n            boolean value = BValue(low) > 0;\n            while (high - low > 1) {\n                int mid = (high + low) >> 1;\n                int BVal = BValue(mid);\n                if (BVal == 0) {\n                    out.println(\"! \" + (mid + 1));\n                    return;\n                }\n                if (value) {\n                    if (BVal < 0) {\n                        high = mid;\n                    } else {\n                        low = mid;\n                    }\n                } else {\n                    if (BVal > 0) {\n                        high = mid;\n                    } else {\n                        low = mid;\n                    }\n                }\n            }\n            out.println(\"! -1\");\n        }\n\n        public int BValue(int index) {\n            out.println(\"? \" + (index + 1));\n            out.flush();\n            int f = in.nextInt();\n            out.println(\"? \" + (index + 1 + (n >> 1)));\n            out.flush();\n            int s = in.nextInt();\n            return f - s;\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "1019_B. The hat", "from": "CODEFORCES"}
{"src": "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 Liavontsi Brechka\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        DEhabIEsheOdnaOcherednayaZadachaNaXor solver = new DEhabIEsheOdnaOcherednayaZadachaNaXor();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DEhabIEsheOdnaOcherednayaZadachaNaXor {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int c = 0;\n            int d = 0;\n\n            int prevSign = 0;\n            int nextSign;\n            boolean zeroOut = true;\n            for (int i = 29; i >= 0; i--) {\n                if (zeroOut) {\n                    print(c, d, out);\n                    prevSign = read(in);\n                }\n\n                print((1 << i) | c, (1 << i) | d, out);\n                nextSign = read(in);\n\n                if (prevSign == nextSign) {\n                    zeroOut = false;\n\n                    print((1 << i) | c, d, out);\n                    nextSign = read(in);\n\n                    if (nextSign < 0) {\n                        c = (1 << i) | c;\n                        d = (1 << i) | d;\n                    }\n                } else {\n                    zeroOut = true;\n\n                    if (nextSign < 0) c = (1 << i) | c;\n                    else d = (1 << i) | d;\n                }\n            }\n\n            out.printf(\"! %d %d\", c, d);\n            out.flush();\n        }\n\n        private void print(int c, int d, PrintWriter out) {\n            out.printf(\"? %d %d\\n\", c, d);\n            out.flush();\n        }\n\n        private int read(InputReader in) {\n            return in.nextInt();\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", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class mad{\n    \n    public static void main(String[] args){\n        Scanner sc = new Scanner(System.in);\n        int cura = 0,curb = 0;\n        int ver;\n        System.out.println(\"? 0 0\");\n        System.out.flush();\n        ver = sc.nextInt();\n        for(int i=29;i>=0;i--){\n            System.out.println(\"? \"+(cura+(1<<i))+\" \"+curb);\n            System.out.flush();\n            int temp1 = sc.nextInt();\n            System.out.println(\"? \"+cura+\" \"+(curb+(1<<i)));\n            System.out.flush();\n            int temp2 = sc.nextInt();\n            if(temp1!=temp2){\n                if(temp2==1){\n                    cura += (1<<i);\n                    curb += (1<<i);\n                }\n            }\n            else{\n                if(ver==1) cura += (1<<i);\n                if(ver==-1) curb += (1<<i);\n                \n                ver = temp1;\n            }\n        }\n        System.out.println(\"! \"+cura+\" \"+curb);\n    }\n    \n}", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class code{\n    public static void main(String[] args) throws IOException{\n        Scanner sc = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int ok,ok2;\n        int va,vb;\n        va = 0;\n        vb = 0;\n        out.println(\"? \"+va+\" \"+vb);\n        out.flush();\n        ok = sc.nextInt();\n        for(int i=29;i>=0;i--){\n            if(ok==0){\n                va += (1<<i);\n                out.println(\"? \"+va+\" \"+vb);\n                out.flush();\n                ok2 = sc.nextInt();\n                if(ok2==1){\n                    va -= (1<<i);\n                }else{\n                    vb += (1<<i);\n                }\n            }else{\n                va += (1<<i);\n                vb += (1<<i);\n                out.println(\"? \"+va+\" \"+vb);\n                out.flush();\n                ok2 = sc.nextInt();\n                if(ok==ok2){\n                    vb -= (1<<i);\n                    out.println(\"? \"+va+\" \"+vb);\n                    out.flush();\n                    ok2 = sc.nextInt();\n                    if(ok2==1){\n                        va -= (1<<i);\n                    }else{\n                        vb += (1<<i);\n                    }\n                }else{\n                    if(ok==1){\n                        vb -= (1<<i);\n                        out.println(\"? \"+va+\" \"+vb);\n                        out.flush();\n                        ok = sc.nextInt();\n                    }\n                    else {\n                        va -= (1<<i);\n                        out.println(\"? \"+va+\" \"+vb);\n                        out.flush();\n                        ok = sc.nextInt();\n                    }\n                }\n            }\n        }\n        out.println(\"! \"+va+\" \"+vb);\n        out.flush();\n    }\n}", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ehab4 {\n    public static void main( String[] args ) {\n        Scanner in = new Scanner( System.in );\n\tint a = 0, b = 0;\n\tSystem.out.println( \"? 0 0 \" );\n\tSystem.out.flush();\n\tint c = in.nextInt();\n\tfor ( int i = 29; i >= 0; i-- ) {\n\t    System.out.println( \"? \" + ( a + ( 1 << i ) ) + \" \" + b );\n\t    System.out.flush();\n\t    int q1 = in.nextInt();\n\t    System.out.println( \"? \" + a + \" \" + ( b + ( 1 << i ) ) );\n\t    System.out.flush();\n\t    int q2 = in.nextInt();\n\t    if ( q1 == q2 ) {\n\t\tif ( c == 1 )\n\t\t    a += ( 1 << i );\n\t\telse if ( c == -1 )\n\t\t    b += ( 1 << i );\n\t\tc = q1;\n\t    }\n\t    else if ( q1 == -1 ) {\n\t\ta += ( 1 << i );\n\t\tb += ( 1 << i );\n\t    }\n\t    else if ( q1 == -2 )\n\t\treturn;\n\t}\n\tSystem.out.println( \"! \" + a + \" \" + b );\n\tSystem.out.flush();\n    }\n}\n", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ehab4 {\n    public static void main( String[] args ) {\n        Scanner in = new Scanner( System.in );\n\tint a = 0, b = 0;\n\tSystem.out.println( \"? 0 0 \" );\n\tSystem.out.flush();\n\tint c = in.nextInt();\n\tfor ( int i = 29; i >= 0; i-- ) {\n\t    System.out.println( \"? \" + ( a + ( 1 << i ) ) + \" \" + b );\n\t    System.out.flush();\n\t    int q1 = in.nextInt();\n\t    System.out.println( \"? \" + a + \" \" + ( b + ( 1 << i ) ) );\n\t    System.out.flush();\n\t    int q2 = in.nextInt();\n\t    if ( q1 == q2 ) {\n\t\tif ( c == 1 )\n\t\t    a += ( 1 << i );\n\t\telse if ( c == -1 )\n\t\t    b += ( 1 << i );\n\t\tc = q1;\n\t    }\n\t    else if ( q1 == -1 ) {\n\t\ta += ( 1 << i );\n\t\tb += ( 1 << i );\n\t    }\n\t    else if ( q1 == -2 )\n\t\treturn;\n\t}\n\tSystem.out.println( \"! \" + a + \" \" + b );\n\tSystem.out.flush();\n    }\n}\n", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class EhabAndAnotherAnotherXorProblem implements Closeable {\n\n  private InputReader in = new InputReader(System.in);\n  private PrintWriter out = new PrintWriter(System.out);\n\n  public void solve() {\n    int initial = ask(0, 0);\n    int a = 0, b = 0;\n    if (initial == 0) {\n      for (int i = 0; i < 30; i++) {\n        int response = ask(1 << i, 0);\n        if (response == -1) {\n          a |= (1 << i);\n        }\n      }\n      b = a;\n    } else {\n      for (int i = 29; i >= 0; i--) {\n        int response = ask(a | (1 << i), b | (1 << i));\n        if (response != initial) {\n          if (response == 1) {\n            b |= (1 << i);\n          } else {\n            a |= (1 << i);\n          }\n          initial = ask(a, b);\n        } else {\n          response = ask(a | (1 << i), b);\n          if (response == -1) {\n            a |= (1 << i);\n            b |= (1 << i);\n          }\n        }\n        \n      }\n    }\n    answer(a, b);\n  }\n\n  private int ask(int c, int d) {\n    out.printf(\"? %d %d\\n\", c, d);\n    out.flush();\n    return in.ni();\n  }\n\n  private void answer(int a, int b) {\n    out.printf(\"! %d %d\\n\", a, b);\n    out.flush();\n  }\n\n  @Override\n  public void close() throws IOException {\n    in.close();\n    out.close();\n  }\n\n  static class InputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n      reader = new BufferedReader(new InputStreamReader(stream), 32768);\n      tokenizer = null;\n    }\n\n    public String next() {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n        try {\n          tokenizer = new StringTokenizer(reader.readLine());\n        } catch (IOException e) {\n          throw new RuntimeException(e);\n        }\n      }\n      return tokenizer.nextToken();\n    }\n\n    public int ni() {\n      return Integer.parseInt(next());\n    }\n\n    public long nl() {\n      return Long.parseLong(next());\n    }\n\n    public void close() throws IOException {\n      reader.close();\n    }\n  }\n\n  public static void main(String[] args) throws IOException {\n    try (EhabAndAnotherAnotherXorProblem instance = new EhabAndAnotherAnotherXorProblem()) {\n      instance.solve();\n    }\n  }\n}\n", "complexity": "logn", "problem": "1088_D. Ehab and another another xor problem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\npublic class ReallyBigNumbers817c {\n     static long sd(String s) {\n        long c = 0;\n        for (int i = 0; i < s.length(); i++) {\n            c += s.charAt(i);\n        }\n        return c - s.length() * 0x30;\n    }\n     \n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        long n = in.nextLong();\n        long s = in.nextLong(); // number\n         // level -- > (n + 8) / 9 * 9; --- > s\n        long i = (s/10+1)*10 ;\n        if (n<10||n-sd(n+\"\")<s) {\n            System.out.println(0);\n            return;\n        }\n        while(!(i-sd(i+\"\")>=s)){\n        i+=10;\n        \n        }\n        System.out.println(n-i+1);\n       \n    }\n    \n\t}\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class ReallyBigNumbers1 \n{\n    \n    public static void main(String[] args) throws IOException \n    {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        PrintWriter out = new PrintWriter(System.out);\n        long n = Long.parseLong(st.nextToken());\n        long s = Long.parseLong(st.nextToken());\n        \n        int r = 0 ;\n        \n        long l = 0L ;\n        long u = n ;\n        \n        if(  (l-sumDigits(l)< s )  && (u-sumDigits(u)< s ) )\n        {\n            out.println(0);\n            out.flush();\n            out.close();\n            return ;\n        }\n        \n        long specified = 0L ;\n        while( true )\n        {\n            long m = (l + u) / 2L ;\n            \n            if( ( m - sumDigits(m) ) >= s && ( (m-1) - sumDigits(m-1) ) < s  )\n            {\n                specified = m ;\n                break ;\n            }\n            \n            if( l > u  )\n                break ;\n            \n            else\n            {\n                if( ( m - sumDigits(m) ) >= s )\n                    u = m-1 ;\n                else\n                    l = m+1 ;\n            }\n        }\n        \n        out.println( n-specified+1 );\n        out.flush();\n        out.close();\n        \n    }\n    \n    public static int sumDigits(long n)\n    {\n        char [] a = (n+\"\").toCharArray();\n        int sum = 0 ;\n        for(int k = 0 ; k < a.length ; k++)\n        {\n            sum += Integer.parseInt(a[k]+\"\") ;\n        }\n        return sum ;\n    }\n    \n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Edu23 {\n\n\tpublic static int sum(String s){\n\t\tint tot=0;\n\t\tfor(int i =0; i<s.length();i++){\n\t\t\ttot+=(s.charAt(i)-'0');\n\t\t}\n\t\treturn tot;\n\t}\n\tpublic static BigInteger comb(int n, int k){\n\t\tif(k==0)\n\t\t\treturn new BigInteger(\"1\");\n\t\telse\n\t\t\treturn comb(n,k-1).multiply(new BigInteger(n-k+1+\"\")).divide(new BigInteger(k+\"\"));\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tlong s = sc.nextLong();\n\t\tlong i;\n\t\tfor(i =s ; i-sum(i+\"\")<s;i++)\n\t\t\tif(i%10==0)i+=9;\n\t\tSystem.out.println(Math.max(0, n-i+1));\n\t\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 Scanner(String f) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArray1(int n) throws IOException {\n\t\t\tint[] a = new int[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] shuffle(int[] a, int n) {\n\t\t\tint[] b = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tb[i] = a[i];\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 = b[i];\n\t\t\t\tb[i] = b[j];\n\t\t\t\tb[j] = t;\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tpublic int[] nextIntArraySorted(int n) throws IOException {\n\t\t\tint[] a = nextIntArray(n);\n\t\t\ta = shuffle(a, n);\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray1(int n) throws IOException {\n\t\t\tlong[] a = new long[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArraySorted(int n) throws IOException {\n\t\t\tlong[] a = nextLongArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tlong t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n/**\n * \n * \u4f5c\u8005\uff1a\u5f20\u5b87\u7fd4 \u521b\u5efa\u65e5\u671f\uff1a2017\u5e746\u670816\u65e5 \u4e0a\u53489:00:48 \u63cf\u8ff0\uff1a\u5199\u5b57\u697c\u91cc\u5199\u5b57\u95f4\uff0c\u5199\u5b57\u95f4\u91cc\u7a0b\u5e8f\u5458\uff1b \u7a0b\u5e8f\u4eba\u5458\u5199\u7a0b\u5e8f\uff0c\u53c8\u62ff\u7a0b\u5e8f\u6362\u9152\u94b1\u3002\n * \u9152\u9192\u53ea\u5728\u7f51\u4e0a\u5750\uff0c\u9152\u9189\u8fd8\u6765\u7f51\u4e0b\u7720\uff1b \u9152\u9189\u9152\u9192\u65e5\u590d\u65e5\uff0c\u7f51\u4e0a\u7f51\u4e0b\u5e74\u590d\u5e74\u3002 \u4f46\u613f\u8001\u6b7b\u7535\u8111\u95f4\uff0c\u4e0d\u613f\u97a0\u8eac\u8001\u677f\u524d\uff1b \u5954\u9a70\u5b9d\u9a6c\u8d35\u8005\u8da3\uff0c\u516c\u4ea4\u81ea\u884c\u7a0b\u5e8f\u5458\u3002\n * \u522b\u4eba\u7b11\u6211\u5fd2\u75af\u766b\uff0c\u6211\u7b11\u81ea\u5df1\u547d\u592a\u8d31\uff1b \u4e0d\u89c1\u6ee1\u8857\u6f02\u4eae\u59b9\uff0c\u54ea\u4e2a\u5f52\u5f97\u7a0b\u5e8f\u5458\uff1f\n */\n\npublic class Main {\n\n\tprivate final static int Max = (int) (1e5 + 10);\n\tprivate static long n,s;\n\n\tpublic static void main(String[] args) {\n\t\tInitData();\n\t\tGetAns();\n\t}\n\n\tprivate static void InitData() {\n\t\tScanner cin = new Scanner(System.in);\n\t\tn=cin.nextLong();\n\t\ts=cin.nextLong();\n\t};\n\tprivate static void GetAns() {\n\t\tlong i;\n\t\tlong ans=0;\n\t\tfor(i=s;i<=n;i++){\n\t\t\t\n\t\t\tlong k=i-sum(i);\n\t\t\tif(k>=s){\n\t\t\t\tif(i%10==9){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\tif(n>=s){\n\t\t\tSystem.out.println(ans-i+n+1);\n\t\t}else{\n\t\t\tSystem.out.println(0);\n\t\t}\n\t};\n\tprivate static long sum(long ans){\n\t\tlong sum=0;\n\t\twhile(ans>0){\n\t\t\tsum+=(ans%10);\n\t\t\tans/=10;\n\t\t}\n\t\treturn sum;\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C {\n\t\n\tpublic static void main(String[] args) {\n\t\tnew C();\n\t}\n\n\tC() {\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tlong n = in.nextLong(), s = in.nextLong();\n\t\tlong lo = 1, hi = 1000000000000000000L;\n\t\t\n\t\twhile(lo<hi){\n\t\t\t//System.out.println(lo+\" \"+hi);\n\t\t\t//STUPID STUPID DUMB\n\t\t\tlong mid = (lo+hi)/2;\n\t\t\tif(reallyBig(mid,s))\n\t\t\t\thi = mid;\n\t\t\telse\n\t\t\t\tlo = mid+1;\n\t\t}\n\t\t\n\t\t//System.out.println(lo+\" \"+hi);\n\t\tif(!reallyBig(lo,s))\n\t\t\tSystem.out.println(0);\n\t\telse\n\t\t\tSystem.out.println(Math.max(n-lo+1,0));\n\t\t\t\n\t\t//System.out.println(reallyBig(100000000000000009L,100000000000000000L));\n\n\t\tin.close();\n\n\t}\n\t\n\tboolean reallyBig(long n, long s){\n\t\tint sum = 0;\n\t\tlong temp = n;\n\t\twhile(temp>0){\n\t\t\tsum += temp%10;\n\t\t\ttemp/=10;\n\t\t}\n\t\treturn n-sum>=s;\n\t}\n\t\n}\n\n/*\n\n12 1\n\n25 20\n\n10 9\n\n1000000000000000000 1000000000000000000\n\n1000000000000000000 100000000000000000\n\n */\n\n\n\n\n\n\n\n\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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        atskb solver = new atskb();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class atskb {\n        long s;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long n = in.nextLong();\n            s = in.nextLong();\n            long ans = binarysearch(0, (long) Math.pow(10, 18) + 20 * 9);\n            if (ans > n) {\n                out.print(0);\n            } else {\n                out.print(n - ans + 1);\n            }\n\n        }\n\n        public long binarysearch(long l, long r) {\n            if (l == r) {\n                if (check(l))\n                    return l;\n                return -1;\n\n            }\n            if (l - r == -1) {\n                if (check(l))\n                    return l;\n                if (check(r)) {\n                    return r;\n                }\n\n                //return -1;\n            }\n            long mid = l + (r - l) / 2;\n            if (check(mid))\n                return binarysearch(l, mid);\n            return binarysearch(mid + 1, r);\n        }\n\n        public boolean check(long m) {\n            String str = m + \"\";\n            long sum = 0;\n            for (int i = 0; i < str.length(); i++) {\n                sum += str.charAt(i) - '0';\n            }\n            if (sum + s <= m)\n                return true;\n            return false;\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 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 boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/**\n * Road to 1600 raiting\n */\npublic class Main {\n    static class Task {\n        PrintWriter out;\n\n        int[] num = new int[3];\n\n        public void solve(MyScanner in, PrintWriter out) {\n            this.out = out;\n\n            long n = in.nextLong();\n            long s = in.nextLong();\n\n            long l = 1;\n\n            long r = n;\n\n            while (r - l > 5) {\n                long x = (l + r) / 2;\n\n                long ans = ans(x);\n\n                if (ans >= s) {\n                    r = x;\n                } else {\n                    l = x;\n                }\n            }\n\n            for (long i = l; i <= r; i++) {\n                if (ans(i) >= s) {\n                    out.println((n - i + 1));\n                    return;\n                }\n            }\n\n            out.println(0);\n\n        }\n\n        long ans(long n) {\n            long res = n;\n\n            while (n > 9) {\n                res -= n % 10;\n                n /= 10;\n            }\n\n            res -= n;\n\n            return res;\n        }\n\n    }\n\n    public static void main(String[] args) {\n        MyScanner in = new MyScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        Task solver = new Task();\n        solver.solve(in, out);\n        out.close();\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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic 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\tlong n = scanner.nextLong();\n\t\tlong s = scanner.nextLong();\n\t\tlong l = 1;\n\t\tlong r = Long.MAX_VALUE;\n\t\tlong index = 0;\n\t\twhile(l <= r) {\n\t\t\tlong mid = (l + r) / 2;\n\t\t\tif(mid - get(mid) >= s) {\n\t\t\t\tindex = mid;\n\t\t\t\tr = mid - 1;\n\t\t\t}else{\n\t\t\t\tl = mid + 1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(Math.max(0, n-index+1));\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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 C {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tlong n = sc.nextLong();\n\t\tLong S = sc.nextLong();\n\t\t\n\t\tlong l = 0;\n\t\tlong h = n;\n\t\t\n\t\tlong ans = n;\n\t\t\n\t\twhile(l <= h) {\n\t\t\tlong mid = (l + h) / 2;\n\t\t\tlong t = mid;\n\t\t\tlong sum = 0;\n\t\t\t\n\t\t\twhile(t > 0) {\n\t\t\t\tsum += t % 10;\n\t\t\t\tt /= 10;\n\t\t\t}\n\t\t\t\n\t\t\tif(mid - sum < S) {\n\t\t\t\tans = mid;\n\t\t\t\tl = mid + 1;\n\t\t\t}else\n\t\t\t\th = mid - 1;\n\t\t}\n\t\t\n\t\tout.println(n - ans);\n\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\n\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\n\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\npublic class C {\n    \n    public static void main(String[] args)\n    {\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextLong();\n        long s = sc.nextLong();\n        \n        BigInteger k = findFirst(BigInteger.valueOf(s));\n        if (BigInteger.valueOf(n).compareTo(k) >= 0)\n        {\n            System.out.println(n - k.longValue() + 1);\n        }\n        else\n        {\n            System.out.println(\"0\");\n        }\n    }\n    \n    public static BigInteger findFirst(BigInteger s) // first number where sum of digs >= s\n    {\n        BigInteger b = BigInteger.ZERO;\n        while (cd(b).compareTo(b.subtract(s)) > 0)\n        {\n            BigInteger c = BigInteger.ONE;\n            while (cd(b.add(c)).compareTo(b.add(c).subtract(s)) > 0) {\n                c = c.multiply(BigInteger.TEN);\n            }\n            // possibly overshot\n            c = c.divide(BigInteger.TEN);\n            if (c.compareTo(BigInteger.TEN) < 0) c = BigInteger.TEN; // always add at least 10\n            b = b.add(c);\n        }\n        return b;\n    }\n    \n    public static BigInteger cd(BigInteger n)\n    {\n        BigInteger t = BigInteger.ZERO;\n        while (n.compareTo(BigInteger.ZERO) > 0)\n        {\n            t = t.add(n.mod(BigInteger.TEN));\n            n = n.divide(BigInteger.TEN);\n        }\n        return t;\n    }\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ReallyBigNumbers {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tlong s  = sc.nextLong();\n\t\t\n\t\tlong m = s;\n\t\t\n\t\twhile(m-digitAdd(m)<s && m<=n){\n\t\t\tm++;\n\t\t}\n\t\tSystem.out.println(Math.max(n-m+1, 0));\n\t}\n\t\n\tprivate static int digitAdd(long s){\n\t\tint sum = 0;\n\t\t\n\t\tfor(long i = 0,j=1L;i<(int)Math.log10(s)+1; i++,j*=10){\n\t\t\tsum += (s/j)%10;\n\t\t}\n\t\t\n\t\treturn sum;\n\t}\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Test {\n\t\n\tprivate static long sum(long value) {\n\t\tlong ans = 0;\n\t\twhile (value > 0) {\n\t\t\tans += value % 10;\n\t\t\tvalue /= 10;\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n , s , ans = 0;\n\t\tn = scan.nextLong();\n\t\ts = scan.nextLong();\n\t\tlong current = s;\n\t\twhile (current <= n && current <= s + 20 * 9) {\n\t\t\t// current - sum(current) >= s\n\t\t\tlong temp = sum(current);\n\t\t\tif (current - temp >= s) {\n\t\t\t\tans ++;\n\t\t\t}\n\t\t\tcurrent ++;\n\t\t}\n\t\tif (current <= n) {\n\t\t\tans += (n - current + 1);\n\t\t}\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\t\n\t\t\n}\n\t\n\t\n\t\n\t\n\t\n\n\n\n\n\n\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tpublic static void main(String[] args)throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tlong n = Long.parseLong(st.nextToken());\n\t\tlong s = Long.parseLong(st.nextToken());\n\t\tlong posible = binarySearch(n,s);\n\t\tlong dig, answer;\n\t\tlong i, cmed;\n\t\tfor (i = posible; i >= 0; i--) {\n\t\t\tdig = 0;\n\t\t\tcmed = i;\n\t\t\twhile (cmed > 0) {\n\t\t\t\tdig = dig+cmed%10;\n\t\t\t\tcmed/=10;\n\t\t\t}\n\t\t\tif (i-dig < s) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tanswer = n-i;\n\t\tSystem.out.println(answer);\n\t}\n\tprivate static  long binarySearch(long n, long s){\n\t\tlong med=n, l = 0, r = n, cmed, dig;\n\t\twhile(l<=r){\n\t\t\tmed = (l+r)/2;\n\t\t\tcmed = med;\n\t\t\tdig = 0;\n\t\t\twhile (cmed > 0) {\n\t\t\t\tdig = dig+cmed%10;\n\t\t\t\tcmed/=10;\n\t\t\t}\n\t\t\tif (med-dig == s) {\n\t\t\t\tbreak;\n\t\t\t}else {\n\t\t\t\tif (med-dig > s) {\n\t\t\t\t\tr = med-1;\n\t\t\t\t}else {\n\t\t\t\t\tl = med+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//System.out.println(med);\n\t\t}\n\t\treturn med;\n\t}\n\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ReallyBigNumbers817c {\n\n    static long sd(String s) {\n        long c = 0;\n        for (int i = 0; i < s.length(); i++) {\n            c += s.charAt(i);\n        }\n        return c - s.length() * 0x30;\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(in.readLine());\n        long n = Long.parseLong(st.nextToken());\n        long s = Long.parseLong(st.nextToken());\n        long i = (s / 10 + 1) * 10;\n        if (n < 10 || n - sd(n + \"\") < s) {\n            System.out.println(0);\n            return;\n        }\n        while (!(i - sd(\"\"+i) >= s)) {\n            i += 10;\n        }\n        System.out.println(n - i + 1);\n    }\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.math.BigDecimal;\nimport java.util.Scanner;\n\npublic class ReallyBigNumbers {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tlong s = scan.nextLong();\n\t\tlong ans = 0;\n\t\tlong l = 0;\n        long r = n;\n        while (l <= r) {\n            // Key is in a[lo..hi] or not present.\n            long mid = l + (r - l) / 2;\n            if(isReallyBig(mid, s)){\n            \tans = mid;\n            \tr = mid-1;\n            }\n            else l = mid+1;\n        }\n        if(ans == 0) System.out.println(ans);\n        else\n        \tSystem.out.println(n-ans+1);\n\t}\n\t\n\tstatic boolean isReallyBig(long m, long s){\n\t\tString x = m+\"\";\n\t\tlong sum = 0;\n\t\tfor(int i = 0; i < x.length(); i++){\n\t\t\tsum += x.charAt(i)-'0';\n\t\t}\n\t\tif(m-sum >= s) return true;\n\t\treturn false;\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.security.KeyStore.Entry;\nimport java.util.*;\n\n\n public class Main {\n\tprivate InputStream is;\n\tprivate PrintWriter out;\n\tint time = 0, dp[][], DP[][], start[], parent[], end[], val[], black[], MOD = (int)(1e9+7), arr[], arr1[];\n\tint MAX = 10000000, N, K, p;\n\tArrayList<Integer>[] amp, amp1;\n\tboolean b[], b1[];\n\tPair prr[];\n\tchar ch[][];\n\tHashSet<Integer> hs = new HashSet<>();\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Thread(null, new Runnable() {\n\t\tpublic void run() {\n\t\t\ttry {\n\n\t\t//new Main().soln();\n\t\t} catch (Exception e) {\n\t\t\t\tSystem.out.println(e);\n\t\t\t}\n\t\t}\n\t}, \"1\", 1 << 26).start();\n\t\tnew Main().soln();\n\t}\n\tvoid solve() {\n\t\tlong n = nl(), s = nl();\n\t\tlong low = 1, high = n+1;\n\t\tlong ans = high;\n\t\twhile(low<=high){\n\t\t\tlong mid = (high+low)/2;\n\t\t\tif((mid - getSum(mid))>=s){\n\t\t\t\thigh = mid-1;\n\t\t\t\tans = mid;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlow = mid+1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(Math.max(0, n-ans+1));\n\t}\n\tint getSum(long s){\n\t\tString str = Long.toString(s);\n\t\tint ans = 0;\n\t\tfor(char ch : str.toCharArray()) ans += (ch-'0');\n\t\treturn ans;\n\t}\n\tint recur(int x){\n\t\t//System.out.println(x);\n\t\tint ans = 0;\n\t\tb[x] = true;\n\t\tfor(int i : amp[x]){\n\t\t\tif(!b[i]){\n\t\t\t\tb[i] = true;\n\t\t\t\tans = Math.max(recur(i), ans);\n\t\t\t\tb[i] = false;\n\t\t\t}\n\t\t}\n\t\treturn 1+ans;\n\t}\n\tint max = 0;\n\tint getParent(int x){\n\t\t//System.out.println(x+\" \"+parent[x]);\n\t\tif(parent[x]!=x){\n\t\t\tparent[x] = getParent(parent[x]);\n\t\t}\n\t\treturn parent[x];\n\t}\n\tint bfs(int x){\n\t\tb[x] = true;\n\t\tQueue<Integer> q =  new LinkedList<>();\n\t\tq.add(x);\n\t\twhile(!q.isEmpty()){\n\t\t\tint y = q.poll();\n\t\t\tfor(int i : amp[y]){\n\t\t\t\tif(!b[i]){\n\t\t\t\t\tb[i] = true;\n\t\t\t\t\tval[i] = val[y]+1;\n\t\t\t\t\tmax = Math.max(val[i], max);\n\t\t\t\t\tq.add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n\tclass Pair implements Comparable<Pair>{\n\t\tint u, v, r;\n\t\tPair(int u, int v){\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t}public int hashCode() {\n\t\t\treturn Objects.hash();\n\t\t}\n\t\tpublic boolean equals(Object o) {\n\t\t\tPair other = (Pair) o;\n\t\t\treturn ((u == other.u && v == other.v));// || (v == other.u && u == other.v));\n\t\t}\n\t\tpublic int compareTo(Pair other) {\n\t\t\t//return Integer.compare(other.r, r);\n\t\t\treturn Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(other.v,v));\n\t\t}\t\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t}\n\t}\n\tint min(int x,int y){\n\t\tif(x<y) return x;\n\t\treturn y;\n\t}\n\tint max(int x,int y){\n\t\tif(x>y) return x;\n\t\treturn y;\n\t}\n\tvoid dfs(int x){\n\t\tb[x] = true;\n\t\tfor(int i : amp[x]){\n\t\t\tif(!b[i]){\n\t\t\t\tdfs(i);\n\t\t\t}\n\t\t}\n\t}\n\tvoid buildGraph(int m){\n\t\twhile(m-->0)\n\t\t{\n\t\t\tint x = ni()-1, y = ni()-1;\n\t\t\tamp[x].add(y);\n\t\t\tamp[y].add(x);\n\t\t}\n\t}\n\tlong modInverse(long a, long mOD2){\n        return  power(a, mOD2-2, mOD2);\n\t}\n\tlong power(long x, long y, long m)\n\t{\n\t\tif (y == 0)\n    return 1;\n\tlong p = power(x, y/2, m) % m;\n\tp = (p * p) % m;\n\n\treturn (y%2 == 0)? p : (x * p) % m;\n\t}\n\tboolean isPrime(int x){\n\t\tfor(int i = 2;i*1L*i<=x;i++) if(x%i==0) return false;\n\t\treturn true;\n\t}\n\tpublic long gcd(long a, long b){\n\t\tif(b==0) return a;\n\t\treturn gcd(b,a%b);\n\t}\n\tvoid failFn(String str, int arr[]){\n\t\tint len = 0;\n\t\tarr[0] = 0;\n\t\tint i = 1;\n\t\twhile(i<arr.length){\n\t\t\tif(str.charAt(i)==str.charAt(len)){\n\t\t\t\tarr[i++] = ++len;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(len == 0){\n\t\t\t\tarr[i] = len;\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(str.charAt(i)!=str.charAt(len)){\n\t\t\t\tlen = arr[len-1];\n\t\t\t}\n\t\t}\n\t}\n\tstatic class ST1{\n\t\tint arr[], st[], size;\n\t\tST1(int a[]){\n\t\t\tarr = a.clone();\n\t\t\tsize = 10*arr.length;\n\t\t\tst = new int[size];\n\t\t\tbuild(0,arr.length-1,1);\n\t\t}\n\t\tvoid build(int ss, int se, int si){\n\t\t\tif(ss==se){\n\t\t\t\tst[si] = arr[ss];\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (ss+se)/2;\n\t\t\tint val = 2*si;\n\t\t\tbuild(ss,mid,val); build(mid+1,se,val+1);\n\t\t\tst[si] = (st[val]+ st[val+1]);\n\t\t}\n\t\tint get(int ss, int se, int l, int r, int si){\n\t\t\tif(l>se || r<ss || l>r) return Integer.MAX_VALUE;\n\t\t\tif(l<=ss && r>=se) return st[si];\n\t\t\tint mid = (ss+se)/2;\n\t\t\tint val = 2*si;\n\t\t\treturn (get(ss,mid,l,r,val)+ get(mid+1,se,l,r,val+1));\n\t\t}\n\t}\n\tstatic class ST{\n\t\tint arr[],lazy[],n;\n\t\tST(int a){\n\t\t\tn = a;\n\t\t\tarr = new int[10*n];\n\t\t\tlazy = new int[10*n];\n\t\t}\n\t\tvoid up(int l,int r,int val){\n\t\t\tupdate(0,n-1,0,l,r,val);\n\t\t}\n\t\tvoid update(int l,int r,int c,int x,int y,int val){\n\t\t\tif(lazy[c]!=0){\n\t\t\t\tlazy[2*c+1]+=lazy[c];\n\t\t\t\tlazy[2*c+2]+=lazy[c];\n\t\t\t\tif(l==r)\n\t\t\t\t\tarr[c]+=lazy[c];\n\t\t\t\tlazy[c] = 0;\n\t\t\t}\n\t\t\tif(l>r||x>y||l>y||x>r)\n\t\t\t\treturn;\n\t\t\tif(x<=l&&y>=r){\n\t\t\t\tlazy[c]+=val;\n\t\t\t\treturn ;\n\t\t\t}\n\t\t\tint mid = l+r>>1;\n\t\t\tupdate(l,mid,2*c+1,x,y,val);\n\t\t\tupdate(mid+1,r,2*c+2,x,y,val);\n\t\t\tarr[c] = (arr[2*c+1]+ arr[2*c+2]);\n\t\t}\n\t\tint an(int ind){\n\t\t\treturn ans(0,n-1,0,ind);\n\t\t}\n\t\tint ans(int l,int r,int c,int ind){\n\t\t\tif(lazy[c]!=0){\n\t\t\t\tlazy[2*c+1]+=lazy[c];\n\t\t\t\tlazy[2*c+2]+=lazy[c];\n\t\t\t\tif(l==r)\n\t\t\t\t\tarr[c]+=lazy[c];\n\t\t\t\tlazy[c] = 0;\n\t\t\t}\n\t\t\tif(l==r)\n\t\t\t\treturn arr[c];\n\t\t\tint mid = l+r>>1;\n\t\t\tif(mid>=ind)\n\t\t\t\treturn ans(l,mid,2*c+1,ind);\n\t\t\treturn ans(mid+1,r,2*c+2,ind);\n\t\t}\n\t}\n\tpublic static class FenwickTree {\n\t\t\n\t    int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates\n\n\t    public FenwickTree(int size) {\n\t        array = new int[size + 1];\n\t    }\n\t    public int rsq(int ind) {\n\t        assert ind > 0;\n\t        int sum = 0;\n\t        while (ind > 0) {\n\t            sum += array[ind];\n\t            //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number\n\t            ind -= ind & (-ind);\n\t        }\n\t        return sum;\n\t    }\n\t    public int rsq(int a, int b) {\n\t        assert b >= a && a > 0 && b > 0;\n\t        return rsq(b) - rsq(a - 1);\n\t    }\n\t    public void update(int ind, int value) {\n\t        assert ind > 0;\n\t        while (ind < array.length) {\n\t            array[ind] += value;\n\t            //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number\n\t            ind += ind & (-ind);\n\t        }\n\t    }\n\t    public int size() {\n\t        return array.length - 1;\n\t    }\n\t}\n\tpublic static int[] shuffle(int[] a, Random gen){\n\t\tfor(int i = 0, n = a.length;i < n;i++)\n\t\t{ \n\t\t\tint ind = gen.nextInt(n-i)+i; \n\t\t\tint d = a[i]; \n\t\t\ta[i] = a[ind];\n\t\t\ta[ind] = d; \n\t\t} \n\treturn a; \n\t}\n\tlong power(long x, long y, int mod){\n\t\tlong ans = 1;\n\t\twhile(y>0){\n\t\t\tif(y%2==0){\n\t\t\t\tx = (x*x)%mod;\n\t\t\t\ty/=2;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tans = (x*ans)%mod;\n\t\t\t\ty--;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tvoid soln() {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\t//out.close();\n\t\tout.flush();\n\t\t//tr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\n\t// To Get Input\n\t// Some Buffer Methods\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\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 && !(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\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n\tprivate void tr(Object... o) {\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class  ER23C {\n    static long s;\n    public static void main (String[] args) throws java.lang.Exception {\n        InputReader in = new InputReader(System.in);\n        PrintWriter w = new PrintWriter(System.out);\n        long n = in.nextLong();\n        s = in.nextLong();\n        long l = 0, h = n;\n        while (l < h) {\n            long mid = (l + h ) / 2;\n           // System.out.println(\"mid is : \" + mid);\n           // System.out.println(\"high is : \" + h);\n            //System.out.println(\"low is : \" + l);\n            if (Ok(mid))\n                h = mid;\n            else\n                l = mid + 1;\n        }\n        if (Ok(h))\n            w.println(n - h + 1);\n        else\n            w.println(n - h);\n\n        w.close();\n\n    }\n    static boolean Ok(long n) {\n        int sum = 0;\n        long temp = n;\n        while (n > 0) {\n            sum += (n % 10);\n            n = n / 10;\n        }\n        //System.out.println(\"n is :\" + n + \" sum is : \" + sum);\n        return (temp - sum >= s);\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 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 void skip(int x) {\n            while (x-- > 0)\n                read();\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 nextString() {\n            return 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 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\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 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        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        public boolean hasNext() {\n            int value;\n            while (isSpaceChar(value = peek()) && value != -1)\n                read();\n            return value != -1;\n        }\n\n        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n    boolean[] b;\n    int[] r;\n    ArrayList<ArrayList<Integer>> q;\n\n    public void dfs(int u, int p) {\n        for (int i = 0; i < q.get(u).size(); i++) {\n            int v = q.get(u).get(i);\n            if (v != p) {\n                r[v] = r[u] + 1;\n                if (b[u]) {\n                    b[v] = b[u];\n                }\n                dfs(v, u);\n            }\n        }\n    }\n\n    public void solve() throws IOException {\n        long n = nextLong();\n        long s = nextLong();\n        long t = 0;\n        if(s + 200 < n){\n            t = n - s - 200;\n        }\n        for(long i = s; i <= Math.min(s + 200,n); i++){\n            long p = 0;\n            long u = i;\n            while (u > 0){\n                p += u % 10;\n                u /= 10;\n            }\n            if(i - p >= s){\n                t++;\n            }\n        }\n        out.print(t);\n    }\n\n    BufferedReader br;\n    StringTokenizer sc;\n    PrintWriter out;\n\n    public String nextToken() throws IOException {\n        while (sc == null || !sc.hasMoreTokens()) {\n            try {\n                sc = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                return 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 static void main(String[] args) throws IOException {\n        try {\n            Locale.setDefault(Locale.US);\n        } catch (Exception e) {\n        }\n        new Main().run();\n    }\n\n    public void run() {\n        try {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n//            br = new BufferedReader(new FileReader(\"lesson.in\"));\n//            out = new PrintWriter(new File(\"lesson.out\"));\n            solve();\n            out.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class C817{\n\n\tvoid solve()\n\t{\n\t\tlong n = nl(), s = nl();\n\t\tlong l = 0, r = n;\n\t\twhile(l < r)\n\t\t{\n\t\t\tlong mid = (l + r)/2;\n\t\t\tif(mid - digSum(mid) < s)\n\t\t\t\tl = mid + 1;\n\t\t\telse\n\t\t\t\tr = mid;\n\t\t}\n\t\tout.println(l - digSum(l) >= s ? (n - l + 1) : 0);\n\t}\n\t\n\tint digSum(long k)\n\t{\n\t\tint sum = 0;\n\t\twhile(k != 0)\n\t\t{\n\t\t\tsum += k % 10;\n\t\t\tk /= 10;\n\t\t}\n\t\treturn sum;\n\t}\n\t\n\tpublic static void main(String[] args){new C817().run();}\n\t\n\tprivate byte[] bufferArray = new byte[1024];\n\tprivate int bufLength = 0;\n\tprivate int bufCurrent = 0;\n\tInputStream inputStream;\n\tPrintWriter out;\n\t\n\tpublic void run()\n\t{\n\t\tinputStream = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\tint nextByte()\n\t{\n\t\tif(bufLength==-1)\n\t\t\tthrow new InputMismatchException();\n\t\tif(bufCurrent>=bufLength)\n\t\t{\n\t\t\tbufCurrent = 0;\n\t\t\ttry\n\t\t\t{bufLength = inputStream.read(bufferArray);}\n\t\t\tcatch(IOException e)\n\t\t\t{ throw new InputMismatchException();}\n\t\t\tif(bufLength<=0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn bufferArray[bufCurrent++];\n\t}\n\t\n\tboolean isSpaceChar(int x)\n\t{return (x<33 || x>126);}\n\t\n\tboolean isDigit(int x)\n\t{return (x>='0' && x<='9');}\n\t\n\tint nextNonSpace()\n\t{\n\t\tint x;\n\t\twhile((x=nextByte())!=-1 && isSpaceChar(x));\n\t\treturn x;\n\t}\n\t\n\tint ni()\n\t{\n\t\tlong ans = nl();\n\t\tif ( Integer.MIN_VALUE <= ans && ans <= Integer.MAX_VALUE )\n\t\t\treturn (int)ans;\n\t\tthrow new InputMismatchException();\n\t}\n\t\n\tlong nl()\n\t{\n\t\tlong ans = 0;\n\t\tboolean neg = false;\n\t\tint x = nextNonSpace();\n\t\tif(x=='-') \n\t\t{\n\t\t\tneg = true;\n\t\t\tx = nextByte();\n\t\t}\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tif(isDigit(x))\n\t\t\t{\n\t\t\t\tans = ans*10 + x -'0';\n\t\t\t\tx = nextByte();\n\t\t\t}\n\t\t\telse\n\t\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\treturn neg ? -ans:ans;\n\t}\n\t\n\tString ns()\n\t{\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint x = nextNonSpace();\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tsb.append((char)x);\n\t\t\tx = nextByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tchar nc()\n\t{ return (char)nextNonSpace();}\n\t\n\tdouble nd()\n\t{ return (double)Double.parseDouble(ns()); }\n\t\n\tchar[] ca()\n\t{ return ns().toCharArray();}\n\t\n\tchar[] ca(int n)\n\t{\n\t\tchar[] ans = new char[n];\n\t\tint p =0;\n\t\tint x = nextNonSpace();\n\t\twhile(p<n)\n\t\t{\n\t\t\tans[p++] = (char)x;\n\t\t\tx = nextByte();\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tint[] ia(int n)\n\t{\n\t\tint[] ans = new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tans[i]=ni();\n\t\treturn ans;\n\t}\n\t\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Ds {\n\t\n\tstatic long lim;\n\t\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString[] line = in.readLine().split(\"\\\\s+\");\n\t\t\n\t\tlong n = Long.parseLong(line[0]);\n\t\t\n\t\tlim = Long.parseLong(line[1]);\n\t\n\t\t\n\t\tlong pos = -1;\n\t\t\n\t\tfor(int i=61; i>=0; i--) {\n\t\t\t\n\t\t\tlong shift = (long) Math.pow(2, i);\n\t\t\t\n\t\t\tif(pos + shift - sumOfDigits(pos + shift) < lim) {\n\t\t\t\tpos += shift;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpos++;\n\t\t\n\t\tif(pos <= n && pos- sumOfDigits(pos) >= lim) {\n\t\t\tSystem.out.println(n - pos + 1);\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(0);\n\t\t}\n\t\t\n\t}\n\n\tprivate static long sumOfDigits(long d) {\n\t\t\n\t\tlong sum = 0;\n\t\tlong num = d;\n\t\t\n\t\twhile(num != 0) {\n\t\t\tsum += (num%10);\n\t\t\tnum /= 10;\n\t\t}\n\t\t\n\t\treturn sum;\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author Jishnu_T\n */\npublic class ReallyBigNums {\n    \n    private static long[] factorArray(long s)\n    {\n        int d=0;\n        long n=s;\n        long f=1;\n        while(n>0)\n        {\n            n=n/10;\n            d++;\n            f = f*10;\n        }\n        \n        long[] fact = new long[d+1];\n        n=s;\n        for(int i=d;i>=0;i--)\n        {\n            if(f==1)\n                fact[i] = n;\n            else\n            {\n                fact[i] = n/(f-1);\n                n = n%(f-1);\n                f=f/10;\n            }\n        }\n        int carry=0;\n        for(int i=0;i<=d;i++)\n        {\n            fact[i] = fact[i]+carry;\n            if(fact[i]>9 || (i==0 && fact[i]>0))\n            {\n                fact[i] = 0;\n                carry = 1;\n                for(int j=i-1;j>=0;j--)\n                {\n                    fact[j] =0;\n                }\n            }\n            else\n            {\n                carry = 0;\n            }\n        }\n        \n        return fact;\n    }\n    \n    private static long bigNumCount(long n, long s)\n    {\n        if(s>=n)\n            return 0;\n        if(s==0)\n            return n;\n        long[] fact = factorArray(s);\n        \n        long startNum = 0;\n        int len = fact.length;\n        long tenPow = 1;\n        for(int i=0;i<len;i++)\n        {\n            startNum = startNum+tenPow*fact[i];\n            tenPow = tenPow*10;\n        }\n        \n        return(Math.max(0,n-startNum+1));\n    }\n    private 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 args[])\n    {\n        FastReader r = new FastReader();\n        long n = r.nextLong();\n        long s=  r.nextLong();\n        System.out.println(bigNumCount(n,s));\n    }\n    \n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\t\npublic \tclass a {\n\t\tpublic static void main(String args[])throws IOException{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tOutputStream out=new BufferedOutputStream(System.out);\n\t\tString s[]=br.readLine().trim().split(\"\\\\ \");\n\t\tBigInteger a1=new BigInteger(s[0]);\n\t\tBigInteger a=new BigInteger(s[0]);\n\t\tString q=a.toString();\n\t\tString q1=q.substring(q.length()-1, q.length());\n\t\ta=a.subtract(new BigInteger(q1));\n\t\t//System.out.println(a.toString());\n\t\tBigInteger c=new BigInteger(\"1\");\n\t\tBigInteger b=new BigInteger(s[1]);\n\t\tint z=check(a,a.toString(),b);\n\t\tif(z==1)\n\t\t{\n\t\t\tout.write(\"0\".getBytes());\n\t\t\tout.flush();\n\t\t\t//System.out.println(\"jwefcyuwe\");\n\t\t\treturn;\n\t\t}\n\t\twhile(a.compareTo(c)>0)\n\t\t{\n\t\t\tBigInteger d=a;\n\t\t\tif(d.subtract(c).compareTo(new BigInteger(\"9\"))==-1)\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\tBigInteger mid=a;\n\t\t\t\tmid=mid.add(c);\n\t\t\t\tmid=mid.divide(new BigInteger(\"2\"));\n\t\t\t\t//System.out.println(mid.toString());\n\t\t\t\tif(check(mid,mid.toString(),b)==1)\n\t\t\t\t{\n\t\t\t\t\tc=mid;\n\t\t\t\t\tc=c.add(new BigInteger(\"1\"));\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ta=mid;\n\t\t\t\t\t\n\t\t\t\t\t//System.out.println(a.toString());\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t q=a.toString();\n\t\t q1=q.substring(q.length()-1, q.length());\n\t\ta=a.subtract(new BigInteger(q1));\n\t\tBigInteger ans=a1.subtract(a);\n\t\tans=ans.add(new BigInteger(\"1\"));\n\t\tout.write(ans.toString().getBytes());\n\t\t//System.out.print(\"sfvlksfv\");\n\t\t\n\t\t\n\t\tout.flush();\n\t}\n\t\t\n\t\tstatic int check(BigInteger a,String s,BigInteger b)\n\t\t{\n\t\t\tint l=s.length();\n\t\t\tlong z=0;\n\t\t\tfor(int i=0;i<l;i++)\n\t\t\t{\n\t\t\t\tz+=Long.parseLong(s.substring(i,i+1));\n\t\t\t}\n\t\t\tBigInteger c=a.subtract(new BigInteger(Long.toString(z)));\n\t\t\t//System.out.println(c.toString());\n\t\t\treturn -1*c.compareTo(b);\n\t\t}\n\t}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n    public static void main (String[] args) throws java.lang.Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        long n = Long.parseLong(st.nextToken()),\n            s = Long.parseLong(st.nextToken());\n        long m = s;\n        while (m-f(m)<s && m<=n) m++;\n        System.out.println(Math.max(n-m+1, 0));\n    }\n    \n    public static int f(long n) {\n        int sum = 0;\n        for (long i=0, j=1L ; i<(int)Math.log10(n)+1 ; i++, j*=10) {\n            sum += (n/j)%10;\n        }\n        return sum;\n    }\n    \n}\n\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "//package educational.round23;\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 C3 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tlong n = nl();\n\t\tlong S = nl();\n\t\tlong ret = Math.max(0, n-S+1);\n\t\tfor(long i = S;i <= S + 300 && i <= n;i++){\n\t\t\tlong b = i;\n\t\t\tfor(long x = i;x > 0;x /= 10){\n\t\t\t\tb -= x % 10;\n\t\t\t}\n\t\t\tif(b < S)ret--;\n\t\t}\n\t\tout.println(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 C3().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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] in = br.readLine().split(\" \");\n\t\tlong n = Long.parseLong(in[0]), s = Long.parseLong(in[1]);\n\t\tSolver solver = new Solver(n, s);\n\t\tSystem.out.println(solver.solve());\n\n\t}\n\n}\n\nclass Solver {\n\n\tprivate long n, s;\n\n\tSolver(long n, long s) {\n\t\tthis.n = n;\n\t\tthis.s = s;\n\t}\n\n\tpublic long solve() {\n\t\tlong low = 1, high = n;\n\t\tfor (int i = 0; i < 72; ++i) {\n\t\t\tlong x = low + (high - low) / 2;\n\t\t\tif (check(x))\n\t\t\t\thigh = x - 1;\n\t\t\telse\n\t\t\t\tlow = x + 1;\n\t\t}\n\t\treturn n - high;\n\t}\n\n\tprivate boolean check(long x) {\n\n\t\tlong tmp = x;\n\t\tint sum = 0;\n\t\twhile (tmp > 0) {\n\t\t\tsum += tmp % 10;\n\t\t\ttmp /= 10;\n\t\t}\n\t\treturn x - sum >= s;\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\t\n\tpublic static boolean realbig (long num, long s) {\n\t\tString str = num + \"\";\n\t\tString[] digs = str.split(\"\");\n\t\tint sum = 0;\n\t\tfor(String dig : digs) {\n\t\t\tsum+= Integer.parseInt(dig);\n\t\t}\n\t\tif(num-sum < s) {\n\t\t\treturn false;\n\t\t} else {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t\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 s = sc.nextLong();\n\t\tsc.close();\n\t\tlong count = 0;\n\t\tlong i = s;\n\t\tfor(; i < s+200 && i <= n; i++) {\n\t\t\tif(realbig(i,s)) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tif(i <= n) {\n\t\t\tcount+=n-i+1;\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\n\npublic class ques3 {\n\tstatic 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 static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n \n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                        numChars = stream.read(buf);\n                } catch (IOException e) {\n                        throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                        return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n \n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n \n        public interface SpaceCharFilter {\n \n            public boolean isSpaceChar(int ch);\n        }\n \n        public String next() {\n            return nextString();\n        }\n        \n        public char nextChar(){\n        \tint c=read();\n        \twhile (isSpaceChar(c)) {\n                c = read();\n            }\n        \treturn (char)c;\n        }\n \n        public String nextString() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n \n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n \n        public Long nextLong() {\n            return Long.parseLong(nextString());\n        }\n \n        public Double nextDouble() {\n            return Double.parseDouble(nextString());\n        }\n    }\n\n\tpublic static void main(String[] args) {\n\t\tInputReader sc=new InputReader(System.in);\n\t\tlong n=sc.nextLong();\n\t\tlong s=sc.nextLong();\n\t\t\n\t\tlong start=0,end=n;\n\t\twhile(start<end)\n\t\t{\n\t\t\tlong mid=(start+end)/2;\n\t\t\tif(func(mid)>=s)\n\t\t\t\tend=mid;\n\t\t\telse \n\t\t\t\tstart=mid+1;\n\t\t}\n\t\tif(func(start)>=s)\n\t\t\tSystem.out.println(n-start+1);\n\t\telse\n\t\t\tSystem.out.println(0);\n\t}\n\t\n\tpublic static long func(long n)\n\t{\n\t\tlong temp=n;\n\t\tint sum=0;\n\t\twhile(temp>0)\n\t\t{\n\t\t\tsum+=temp%10;\n\t\t\ttemp/=10;\n\t\t}\n\t\treturn n-sum;\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "//package educational.round23;\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 C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tlong n = nl();\n\t\tlong S = nl();\n\t\tlong d = 1000000000000000000L;\n\t\tout.println(dfs(d, n, S));\n\t}\n\t\n\tlong dfs(long d, long n, long S)\n\t{\n\t\tif(d == 0)return 0L;\n\t\tlong ret = 0;\n\t\tfor(int i = 0;i <= n/d;i++){\n\t\t\tif(S <= 0){\n\t\t\t\tret += Math.min(n-i*d+1, d);\n\t\t\t}else if(S < d){\n\t\t\t\tret += dfs(d/10, i == n/d ? n%d : d-1, S);\n\t\t\t}\n\t\t\tS -= d-1;\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 C().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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class b817 {\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\n\t\tlong n = scn.nextLong();\n\t\tlong s = scn.nextLong();\n\n\t\tlong lo = 0;\n\t\tlong hi = n ;\n\t\twhile(lo<=hi)\t\n\t\t{\n\t\t\tlong mid=(lo+hi)/2; \n\t\t\tif(check(mid, s))// no's greater thn this grtr\n\t\t\t{\n\t\t\t\thi=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tif(check(lo, s))\n\t\t{\n\t\tSystem.out.println(n-lo+1);\n\t\t}\n\t\telse // could check initially too\n\t\t{\n\t\t\tSystem.out.println(\"0\");\n\t\t\t\n\t\t}\n\t}\n\n\tpublic static boolean check(long n, long s) {\n\t\tlong sum=0;\n\t\tlong a=n;\n\t\twhile(n>0)\n\t\t{\n\t\t\n\t\tsum=sum+(n%10);\n\t\tn=n/10;\n\t\t}\n\t\tif(a-sum>=s)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\n\t}\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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        int digitsum(long n) {\n            int ans = 0;\n            while (n > 0) {\n                ans += n % 10;\n                n /= 10;\n            }\n            return ans;\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long n = in.nextLong();\n            long s = in.nextLong();\n\n            if (s >= n) {\n                out.println(0);\n                return;\n            }\n\n            long ans = s;\n            while (ans < s + digitsum(ans)) {\n                ans++;\n            }\n\n            if (n >= ans) {\n                out.println(n - ans + 1);\n            } else {\n                out.println(0);\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 long nextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class P817C\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tlong s = scan.nextLong();\n\t\tlong ans = 0;\n\t\tif (s > n)\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif (n > s+200)\n\t\t{\n\t\t\tans += n-(s+200);\n\t\t\tn = s+200;\n\t\t}\n\t\tfor (long i = s; i <= n; i++)\n\t\t{\n\t\t\tchar[] num = (\"\"+i).toCharArray();\n\t\t\tint sum = 0;\n\t\t\tfor (int j = 0; j < num.length; j++)\n\t\t\t\tsum += num[j] - '0';\n\t\t\tif (i - sum >= s)\n\t\t\t\tans++;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.Math.*;\n\npublic class Main{\n\tstatic long s;\n\tstatic boolean check(long n){\n\t\tint sum = 0;\n\t\tlong storen=n;\n\t\twhile(n>0){\n\t\t\tint k = (int)(n%10);\n\t\t\tn /=10;\n\t\t\tsum+=k;\n\t\t}\n\t\treturn storen-(long)sum >= s;\n\t}\n\tpublic static void main(String args[]){\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tInputReader ip=new InputReader(System.in);\n\t\t\n\t\tlong n;\n\t\tn=ip.nextLong();\n\t\ts=ip.nextLong();\n\n\t\tif(s>n){\n\t\t\tpw.println(\"0\");\n\t\t}\n\t\telse{\n\t\t\tlong l=0,r=n;\n\t\t\tboolean possible=false;\n\t\t\tlong mid=0;\n\t\t\tint it=100;\n\t\t\twhile(it-->0){\n\t\t\t\tmid = (l+r)/2;\n\t\t\t\tif(check(mid)){\n\t\t\t\t\tr=mid;\n\t\t\t\t\tpossible = true;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tl=mid+1;\n\t\t\t\t}\n\t\t//\t\tpw.println(mid);\n\t\t//\t\tpw.println(l+\" \"+r);\n\t\t\t}\n\t\t\tif(possible){\n\t\t\t\tpw.println(n-l+1);\n\t\t\t}\t\n\t\t\telse{\n\t\t\t\tpw.println(\"0\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tpw.close();\n\t}\n\tstatic 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\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 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}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tlong n = scanner.nextLong();\n\t\tlong s = scanner.nextLong();\n\t\tlong l = 0, r = n + 1;\n\t\twhile(r - l > 1) {\n\t\t\tlong mid = (l + r) / 2;\n\t\t\tlong k = mid, sum = 0;\n\t\t\twhile(k != 0) {\n\t\t\t\tsum += k % 10;\n\t\t\t\tk /= 10;\n\t\t\t}\n\t\t\tif(mid - sum >= s) r = mid; else l = mid;\n\t\t}\n\t\tSystem.out.print(n - r + 1);\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class CFEdu23C \n{\n\tstatic long sum(long n)\n\t{\n\t\tlong ans=0;\n\t\twhile(n>0)\n\t\t{\n\t\t\tans+=(n%10);\n\t\t\tn/=10;\n\t\t}\n\t\treturn ans;\n\t}\n\tstatic long BS(long l,long h,long s)\n\t{\n\t\tif(l<=h)\n\t\t{\n\t\t\tlong m=(l+h)/2l;\n\t\t\tif(m-sum(m)>=s && (m==1 || (m-1)-sum(m-1)<s))\n\t\t\t\treturn m;\n\t\t\telse if(m-sum(m)>=s)\n\t\t\t\treturn BS(l, m-1, s);\n\t\t\telse\n\t\t\t\treturn BS(m+1, h, s);\n\t\t}\n\t\treturn (h+1);\n\t}\n\tpublic static void main(String args[]) {\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\t/*------------------------------My Code starts here------------------------------*/\n\t\tlong n=in.nextLong(),s=in.nextLong();\n\t\tlong x=BS(0,n,s);\n\t\tout.print(n-x+1);\n\t\tout.close();\n\t\t/*------------------------------The End------------------------------------------*/\n\t}\n\n\tpublic static final long l = (int) (1e9 + 7);\n\n\tprivate static int[] nextIntArray(InputReader in, int n) {\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\treturn a;\n\t}\n\n\tprivate static long[] nextLongArray(InputReader in, int n) {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = in.nextLong();\n\t\treturn a;\n\t}\n\n\tprivate static int[][] nextIntMatrix(InputReader in, int n, int m) {\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] = in.nextInt();\n\t\t}\n\t\treturn a;\n\t}\n\n\tprivate static void show(int[] a) {\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\tSystem.out.print(a[i] + \" \");\n\t\tSystem.out.println();\n\t}\n\n\tprivate static void show2DArray(char[][] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < a[0].length; j++)\n\t\t\t\tSystem.out.print(a[i][j]);\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n\tstatic class Pair {\n\t\tprivate int first;\n\t\tprivate int second;\n\n\t\tpublic Pair(int i, int j) {\n\t\t\tthis.first = i;\n\t\t\tthis.second = j;\n\t\t}\n\n\t\tpublic int getFirst() {\n\t\t\treturn first;\n\t\t}\n\n\t\tpublic int getSecond() {\n\t\t\treturn second;\n\t\t}\n\n\t\tpublic void setFirst(int k) {\n\t\t\tthis.first = k;\n\t\t}\n\n\t\tpublic void setSecond(int k) {\n\t\t\tthis.second = k;\n\t\t}\n\t}\n\n\tstatic int modPow(int a, int b, int p) {\n\t\tint result = 1;\n\t\ta %= p;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) != 0)\n\t\t\t\tresult = (result * a) % p;\n\t\t\tb = b >> 1;\n\t\t\ta = (a * a) % p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void SieveOfEratosthenes(int n) {\n\t\tboolean[] prime = new boolean[n + 1];\n\t\tArrays.fill(prime, true);\n\t\tprime[1] = false;\n\t\tint i, j;\n\t\tfor (i = 2; i * i <= n; i++) {\n\t\t\tif (prime[i]) {\n\t\t\t\tfor (j = i; j <= n; j += i) {\n\t\t\t\t\tif (j != i)\n\t\t\t\t\t\tprime[j] = false;\n\t\t\t\t}\n\t\t\t}\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\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 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\t}\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Main {\n    private static Reader in;\n    private static PrintWriter out;\n    public static void main(String args[]) throws IOException {\n        in = new Reader();\n        out = new PrintWriter(System.out);\n        long n = in.nextLong();\n        long s = in.nextLong();\n        long low = 0, mid = 0, high = n;\n        while (low <= high) {\n            mid = (low + high) / 2;\n            if (func(mid, s)) {\n                high = mid - 1;\n            }\n            else {\n                low = mid + 1;\n            }\n        }\n        out.println(n - low + 1);\n        out.close();\n    }\n\n    private static boolean func(long num, long s) {\n        long sum = 0, temp =  num;\n        while (temp > 0) {\n            sum += (temp) % 10;\n            temp /= 10;\n        }\n        return ((num - sum) >= s);\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\n\n        public String next() throws IOException {\n            byte[] buf = new byte[64]; // line length\n            int cnt = 0, c;\n            while ((c = read()) != -1)\n            {\n                if (c == ' ' || c == '\\n')\n                    break;\n                buf[cnt++] = (byte) c;\n            }\n            return new String(buf, 0, cnt);\n        }\n\n        public String nextLine() 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}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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    static ArrayList <Integer> adj[];\n    static int co=0,f=0;\n\n    static void Check2(int n){\n        adj=new ArrayList[n+1];\n        for(int i=0;i<=n;i++){\n            adj[i]=new ArrayList<>();\n        }\n\n    }\n    static void add(int i,int j){\n\n        adj[i].add(j);\n        adj[j].add(i);\n    }\n    public static void main(String[] args)  {\n        new Thread(null, new main(), \"Check2\", 1<<26).start();// to increse stack size in java\n    }\n    static long mod=(long)(1e9+7);\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\n        InputReader in = new InputReader(System.in);\n        PrintWriter w = new PrintWriter(System.out);\n\n\n\n       long n=in.nextLong();\n        long s=in.nextLong();\n        \n        long l=1;\n        long r=(long)(n);\n       long ans=-1;\n        while(l<=r){\n            \n            long mid=(l+r)/2;\n            if(ch(mid,s)){\n                ans=mid;\n                r=mid-1;\n            }\n            else\n            {\n                l=mid+1;\n            }\n            \n        }\n        if(ans==-1)w.println(0);\n        else\n            w.println(n-ans+1);\n        w.close();\n    }\n        public boolean ch(long a,long s){\n            \n            long p=0;\n            long val=a;\n            while(val>0){\n                p=p+val%10;\n                val=val/10;\n            }\n            if(a-p>=s)return true;\n            return false;\n            \n        }\n    public boolean rec(int a,int b,int x,int y,int c,int d,int co){\n\n        if(a>x|b>y)return false;\n\n        if(a<-100000||b<-100000||co>100000)return false;\n\n        if(a==x&&b==y)return true;\n\n\n\n        return (rec(a+c,b+d,x,y,c,d,co+1)||rec(a+c,b-d,x,y,c,d,co+1)||rec(a-c,b+d,x,y,c,d,co+1)||rec(a-c,b-d,x,y,c,d,co+1));\n\n\n\n    }\n\n\n\n    static  int gcd(int a,int b){\n\n        if(b==0)return a;\n        return gcd(b,a%b);\n    }\n    static  void dfs(int i,int v[],int val,int b[]){\n\n\n        if(v[i]==1)return ;\n\n        v[i]=1;\n        b[i]=val;\n\n        Iterator <Integer> it=adj[i].iterator();\n        while(it.hasNext()){\n            int q=it.next();\n            dfs(q,v,val,b);\n        }\n\n\n\n\n\n    }\n\n    static  void sev(int a[],int n){\n\n        for(int i=2;i<=n;i++)a[i]=i;\n        for(int i=2;i<=n;i++){\n\n            if(a[i]!=0){\n                for(int j=2*i;j<=n;){\n\n                    a[j]=0;\n                    j=j+i;\n                }\n            }\n\n        }\n\n    }\n\n    static class pair implements Comparable<pair> {\n\n        int x,y;\n        pair(int c,int d){\n            x=c;\n            y=d;\n        }\n\n        public int compareTo(pair o){\n\n            return (this.x-o.x);   //sort in incrementing order w.r.t to c\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  void rec(String s,int a,int b,int n){\n\n        if(b==n){\n            System.out.println(s);\n            return ;\n        }\n        String p=s;\n        if(a>b){\n            s=p+\")\" ;\n            rec(s,a,b+1,n);\n        }\n        if(a<n){\n            s=p+\"(\";\n            rec(s,a+1,b,n);\n        }\n\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\n\n\n\n\n\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main{\n\n  public static boolean check(BigInteger a, BigInteger b){\n    long  n = 0;\n    String aStr = a.toString();\n    for (int i=0; i < aStr.length() ;i++ ) {\n      n += Long.valueOf(aStr.charAt(i)-'0');\n    }\n    return a.subtract(BigInteger.valueOf(n)).compareTo(b) >= 0;\n  }\n\n  public static void main(String[] args) {\n    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){\n      String[] str = in.readLine().split(\" \");\n      BigInteger n = new BigInteger(str[0]);\n      BigInteger s = new BigInteger(str[1]);\n\n      BigInteger left = BigInteger.ONE;\n      BigInteger right = new BigInteger(n.toString()).add(BigInteger.TEN);\n\n      BigInteger TWO = BigInteger.ONE.add(BigInteger.ONE);\n\n      BigInteger t;\n\n      while(right.subtract(left).compareTo(BigInteger.ONE)>0){\n        t = left.add(right.subtract(left).divide(TWO));\n        if(check(t, s)){\n          right = t;\n        }else{\n          left = t;\n        }\n      }\n      BigInteger result = n.subtract(right).add(BigInteger.ONE);\n      if (result.compareTo(BigInteger.ZERO)<=0) {\n        System.out.println(0);\n      }else{\n        System.out.println(result);\n      }\n\n    }catch (IOException e) {\n      e.printStackTrace();\n    }\n  }\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "/**\n * DA-IICT\n * Author : Savaliya Sagar\n */\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class C817 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tlong n = nl();\n\t\tlong s = nl();\n\t\tlong l = 1;\n\t\tlong r = n;\n\t\tlong ans = 0;\n\t\twhile(l<=r){\n\t\t\tlong mid = (l+r)/2;\n\t\t\tlong sum = 0;\n\t\t\tlong temp = mid;\n\t\t\twhile(temp!=0){\n\t\t\t\tsum += temp%10;\n\t\t\t\ttemp/=10;\n\t\t\t}\n\t\t\tif(mid-sum<s){\n\t\t\t\tans = mid;\n\t\t\t\tl = mid+1;\n\t\t\t}else\n\t\t\t\tr = mid - 1;\n\t\t}\n\t\tout.println(n-ans);\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 Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tnew C817().run();\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\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=\n\t\t\t\t\t\t\t\t\t\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 && !(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\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate void tr(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class P {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong N = sc.nextLong(), S = sc.nextLong();\n\t\tlong lo = 0, hi = N;\n\t\tlong pivot = 0;\n\t\twhile (lo <= hi) {\n\t\t\tlong mid = lo + (hi - lo) / 2;\n\t\t\tint sumOfDigits = 0;\n\t\t\tlong saveMid = mid;\n\t\t\twhile (saveMid > 0) {\n\t\t\t\tsumOfDigits += saveMid % 10;\n\t\t\t\tsaveMid /= 10;\n\t\t\t}\n\t\t\tif (mid - sumOfDigits < S) {\n\t\t\t\tpivot = mid;\n\t\t\t\tlo = mid + 1;\n\t\t\t} else\n\t\t\t\thi = mid - 1;\n\t\t}\n\n\t\tSystem.out.println(N - pivot);\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String f) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArray1(int n) throws IOException {\n\t\t\tint[] a = new int[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] shuffle(int[] a, int n) {\n\t\t\tint[] b = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tb[i] = a[i];\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 = b[i];\n\t\t\t\tb[i] = b[j];\n\t\t\t\tb[j] = t;\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tpublic int[] nextIntArraySorted(int n) throws IOException {\n\t\t\tint[] a = nextIntArray(n);\n\t\t\ta = shuffle(a, n);\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray1(int n) throws IOException {\n\t\t\tlong[] a = new long[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArraySorted(int n) throws IOException {\n\t\t\tlong[] a = nextLongArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tlong t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t}\n\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "/*\n * DA-IICT\n * Author: Jugal Kalal\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.DecimalFormat;\npublic class Practice{\n\tstatic long MOD=(long)Math.pow(10,9)+7;\n\tpublic static void main(String args[]) {\n        new Thread(null, new Runnable() {\n            public void run() {\n                try{\n                    solve();\n                    w.close();\n                }\n                catch(Exception e){\n                    e.printStackTrace();\n                }\n            }\n        }, \"1\", 1 << 26).start();\n\t}\n\tstatic InputReader in;\n    static PrintWriter w;\n    static void solve(){\n        in = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n        long n=in.nextLong();\n        long s=in.nextLong();\n        long low=1,high=n,ans=-1;\n        while(low<=high){\n        \tlong mid=(low+high)/2;\n        \tif(check(mid,s)){\n        \t\tans=mid;\n        \t\thigh=mid-1;\n        \t}else{\n        \t\tlow=mid+1;\n        \t}\n        }\n        if(ans==-1){\n        \tw.println(0);\n        }else\n        \tw.println(n-ans+1);\n    }\n    static boolean check(long n,long s){\n    \tlong temp=n;\n    \tlong sum=0;\n    \twhile(temp>0){\n    \t\tsum+=temp%10;\n    \t\ttemp=temp/10;\n    \t}\n    \tif(n-sum>=s){\n    \t\treturn true;\n    \t}\n    \treturn false;\n    }\n    static int adj[][];\n//    static ArrayList<Integer> adj[]; //Adjacency Lists\n    static int V;   // No. of vertices\n    // Constructor\n    static void Graph(int v){\n        V = v;\n        adj=new int[v][v];\n//        adj = new ArrayList[v];\n//        for (int i=0; i<v; ++i){\n//        \tadj[i] = new ArrayList();\n//        }\n    }\n    // Function to add an edge into the graph\n    static void addEdge(int u,int v,int w){\n//\t\tadj[u].add(v);\n//\t\tadj[v].add(u);\n    \tadj[u][v]=w;\n    }\n//    static void bfs(int s,int n){\n//    \tboolean visited[]=new boolean[n];\n//    \tLinkedList<Integer> queue=new LinkedList<Integer>();\n//    \tqueue.add(s);\n//    \tvisited[s]=true;\n//    \twhile(!queue.isEmpty()){\n//    \t\tint num=queue.pop();\n////    \t\tSystem.out.println(ans.toString());\n//    \t\tfor(int i=0;i<adj[num].size();i++){\n//    \t\t\tif(!visited[adj[num].get(i)]){\n//    \t\t\t\tvisited[adj[num].get(i)]=true;\n//    \t\t\t\tqueue.add(adj[num].get(i));\n//    \t\t\t}\n//    \t\t}\n//    \t}\n//    }\n    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    static long power(long base, long exponent, long modulus){\n\t    long result = 1L;\n\t    while (exponent > 0) {\n\t        if (exponent % 2L == 1L)\n\t            result = (result * base) % modulus;\n\t        exponent = exponent >> 1;\n\t        base = (base * base) % modulus;\n\t    }\n\t    return result;\n\t}\n    static HashMap<Long,Long> primeFactors(long n){\n        HashMap<Long,Long> ans=new HashMap<Long,Long>();\n    \t// Print the number of 2s that divide n\n        while (n%2L==0L)\n        {\n            if(ans.containsKey(2L)){\n            \tans.put(2L,ans.get(2L)+1L);\n            }else{\n            \tans.put(2L,1L);\n            }\n            n /= 2L;\n        }\n \n        // n must be odd at this point.  So we can\n        // skip one element (Note i = i +2)\n        for (long i = 3; i <= Math.sqrt(n); i+= 2L)\n        {\n            // While i divides n, print i and divide n\n            while (n%i == 0)\n            {\n            \tif(ans.containsKey(i)){\n                \tans.put(i,ans.get(i)+1L);\n                }else{\n                \tans.put(i,1L);\n                }\n                n /= i;\n            }\n        }\n \n        // This condition is to handle the case whien\n        // n is a prime number greater than 2\n        if (n > 2)\n            ans.put(n,1L);\n        return ans;\n    }\n////for marking all prime numbers greater than 1 and less than equal to N\n\tstatic void sieve(int N) {\n\t boolean isPrime[]=new boolean[N+1];\n\t isPrime[0] = true;\n\t isPrime[1] = true;\n\t for(int i = 2; i * i <= N; ++i) {\n\t      if(isPrime[i] == false) {//Mark all the multiples of i as composite numbers\n\t          for(int j = i * i; j <= N ;j += i)\n\t              isPrime[j] = true;\n\t     }\n\t }\n\t}\n//  //if  str2 (pattern) is subsequence of str1 (Text) or not\n//\tstatic boolean function(String str1,String str2){\n//\t     str2 = str2.replace(\"\", \".*\");  //returns .*a.*n.*n.*a.\n//\t     return (str1.matches(str2));  // returns true\n//\t}\n    static int Arr[];\n    static long size[];\n  //modified initialize function:\n    static void initialize(int N){\n    \tArr=new int[N];\n    \tsize=new long[N];\n        for(int i = 0;i<N;i++){\n        \tArr[ i ] = i ;\n        \tsize[ i ] = 1;\n        }\n    }\n    static boolean find(int A,int B){\n        if( root(A)==root(B) )       //if A and B have same root,means they are connected.\n        return true;\n        else\n        return false;\n    }\n // modified root function.\n    static void weighted_union(int A,int B,int n){\n        int root_A = root(A);\n        int root_B = root(B);\n        if(size[root_A] < size[root_B ]){\n        \tArr[ root_A ] = Arr[root_B];\n        \tsize[root_B] += size[root_A];\n        }\n        else{\n        \tArr[ root_B ] = Arr[root_A];\n        \tsize[root_A] += size[root_B];\n        }\n    }\n    static int root (int i){\n        while(Arr[ i ] != i){\n            Arr[ i ] = Arr[ Arr[ i ] ] ; \n            i = Arr[ i ]; \n        }\n        return i;\n    }\n    \n \n\tstatic boolean isPrime(long n) {\n\t\tif(n < 2L) return false;\n\t\tif(n == 2L || n == 3L) return true;\n\t\tif(n%2L == 0 || n%3L == 0) return false;\t\n\t\tlong sqrtN = (long)Math.sqrt(n)+1L;\n\t\tfor(long i = 6L; i <= sqrtN; i += 6L) {\n\t\t\tif(n%(i-1) == 0 || n%(i+1) == 0) return false;\n\t\t}\n\t\treturn true;\n\t}\n//\tstatic HashMap<Integer,Integer> level;;\n//\tstatic HashMap<Integer,Integer> parent;\n\tstatic int maxlevel=0;\n\t\n//\tstatic boolean T[][][];\n//\tstatic void subsetSum(int input[], int total, int count) {\n//        T = new boolean[input.length + 1][total + 1][count+1];\n//        for (int i = 0; i <= input.length; i++) {\n//        \tT[i][0][0] = true;\n//        \tfor(int j = 1; j<=count; j++){\n//        \t\tT[i][0][j] = false;\n//        \t}\n//        }\n//        int sum[]=new int[input.length+1];\n//        for(int i=1;i<=input.length;i++){\n//            sum[i]=sum[i-1]+input[i-1];\n//        }\n//        for (int i = 1; i <= input.length; i++) {\n//            for (int j = 1; j <= (int)Math.min(total,sum[i]); j++) {\n//            \tfor (int k = 1; k <= (int)Math.min(i,count); k++){\n//            \t\t if (j >= input[i - 1]) {//Exclude and Include\n//                         T[i][j][k] = T[i - 1][j][k] || T[i - 1][j - input[i - 1]][k-1];\n//                     } else {\n//                         T[i][j][k] = T[i-1][j][k];\n//                     }\n//            \t}\n//            }\n//        }\n//    }\n//\tstatic <K,V extends Comparable<? super V>>\n//\tSortedSet<Map.Entry<K,V>> entriesSortedByValues(Map<K,V> map) {\n//\t    SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<Map.Entry<K,V>>(\n//\t        new Comparator<Map.Entry<K,V>>() {\n//\t            @Override public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2) {\n//\t                int res = e2.getValue().compareTo(e1.getValue());\n//\t                return res != 0 ? res : 1;\n//\t            }\n//\t        }\n//\t    );\n//\t    sortedEntries.addAll(map.entrySet());\n//\t    return sortedEntries;\n//\t}\n\t\n \n\t \n\t//minimum prime factor of all the numbers less than n\n    static int minPrime[];\n\tstatic void minimumPrime(int n){\n\t\tminPrime=new int[n+1];\n\t\tminPrime[1]=1;\n        for (int i = 2; i * i <= n; ++i) {\n            if (minPrime[i] == 0) {         //If i is prime\n                for (int j = i * i; j <= n; j += i) {\n                    if (minPrime[j] == 0) {\n                        minPrime[j] = i;\n                    }\n                }\n            }\n        }\n        for (int i = 2; i <= n; ++i) {\n            if (minPrime[i] == 0) {\n                minPrime[i] = i;\n            }\n        }\n\t}\n\tstatic long modInverse(long A, long M)\n\t{\n\t\tlong x=extendedEuclid(A,M)[0];\n\t\treturn (x%M+M)%M;    //x may be negative\n\t}\n\tstatic long[] extendedEuclid(long A, long B) {\n\t\tif(B == 0) {\n\t\t\tlong d = A;\n\t\t\tlong x = 1;\n\t\t\tlong y = 0;\n\t\t\treturn new long[]{x,y,d};\n\t\t}\n\t\telse {\n\t\t\tlong arr[]=extendedEuclid(B, A%B);\n\t\t\tlong temp = arr[0];\n\t\t\tarr[0] = arr[1];\n\t\t\tarr[1] = temp - (A/B)*arr[1];\n\t\t\treturn arr;\n\t\t}\n\t}\n \n\tstatic class InputReader {\n        private final InputStream stream;\n        private final byte[] buf = new byte[8192];\n        private int curChar, numChars;\n        private SpaceCharFilter filter;\n \n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n        \n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n \n        public String nextLine() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isEndOfLine(c));\n            return res.toString();\n        }\n \n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n \n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n \n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n \n        public int[] nextIntArray(int n) {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n            return arr;\n        }\n \n        public long[] nextLongArray(int n) {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n            return arr;\n        }\n \n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n \n        private boolean isEndOfLine(int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class CodeforcesC {\n\n\tpublic static void main(String[] args) {\n\t\tScanner ob = new Scanner(System.in);\n\t\tlong n = ob.nextLong();\n\t\tlong s = ob.nextLong();\n\t\tlong l = 1;\n\t\tlong r = n;\n\t\twhile(l<=r){\n\t\t\tlong mid = (l + r)/2;\n\t\t\tif(reallybignumber(mid,s)){\n\t\t\t\tr = mid-1;\n\t\t\t}else{\n\t\t\t\tl = mid +1;\n\t\t\t}\n\t\t}\n\t\t/******long l1 = l;\n\t\t***while(l1<=n) {\n\t\t\tSystem.out.print(l1 + \" \");\n\t\t\tl1++;\n\t\t}*/////////\n\t\tSystem.out.println(n-l+1);\n\n\t}\n\n\tprivate static boolean reallybignumber(long n,long s) {\n\t\tlong m = n;\n\t\tlong sum=0;\n\t\tint d=1;\n\t\twhile(m>0){\n\t\t\tlong rem = m % 10;\n\t\t\tsum =   rem * d + sum;\n\t\t\tm = m / 10;\n\t\t}\n\t\tif(n-sum >= s) return true;\n\t\telse return false;\n\t}\n\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\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_Edu_Round_23 {\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        long n = in.nextLong();\n        long s = in.nextLong();\n        if (s == 0) {\n            out.println(n);\n        } else {\n            String N = \"\" + n;\n            dp = new long[N.length()][163][2][2];\n            long re = 0;\n            for (int i = 1; i < 163 && i <= n; i++) {\n                long tmp = s + i;\n                if (tmp <= n) {\n                    String S = \"\" + tmp;\n                    while(S.length() < N.length()){\n                        S = '0' + S;\n                    }\n                    for (long[][][] a : dp) {\n                        for (long[][] b : a) {\n                            for (long[] c : b) {\n                                Arrays.fill(c, -1);\n                            }\n                        }\n                    }\n                    re += cal(0, i, 0, 0, N, S);\n                }\n            }\n            out.println(re);\n        }\n        out.close();\n    }\n\n    public static long cal(int index, int left, int lessThanN, int largerThanS, String n, String s) {\n        if (index == n.length()) {\n            if (left == 0) {\n                return 1;\n            }\n            return 0;\n        }\n        if (dp[index][left][lessThanN][largerThanS] != -1) {\n            return dp[index][left][lessThanN][largerThanS];\n        }\n        int x = n.charAt(index) - '0';\n        int y = s.charAt(index) - '0';\n        long re = 0;\n        for (int i = 0; i < 10 && i <= left; i++) {\n            if (i <= x || lessThanN == 1) {\n                if (i >= y || largerThanS == 1) {\n                    re += cal(index + 1, left - i, i < x ? 1 : lessThanN, i > y ? 1 : largerThanS, n, s);\n                }\n            }\n        }\n        return dp[index][left][lessThanN][largerThanS] = re;\n    }\n\n    public static int[] KMP(String val) {\n        int i = 0;\n        int j = -1;\n        int[] result = new int[val.length() + 1];\n        result[0] = -1;\n        while (i < val.length()) {\n            while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n                j = result[j];\n            }\n            j++;\n            i++;\n            result[i] = j;\n        }\n        return result;\n\n    }\n\n    public static boolean nextPer(int[] data) {\n        int i = data.length - 1;\n        while (i > 0 && data[i] < data[i - 1]) {\n            i--;\n        }\n        if (i == 0) {\n            return false;\n        }\n        int j = data.length - 1;\n        while (data[j] < data[i - 1]) {\n            j--;\n        }\n        int temp = data[i - 1];\n        data[i - 1] = data[j];\n        data[j] = temp;\n        Arrays.sort(data, i, data.length);\n        return true;\n    }\n\n    public static int digit(long n) {\n        int result = 0;\n        while (n > 0) {\n            n /= 10;\n            result++;\n        }\n        return result;\n    }\n\n    public static double dist(long a, long b, long x, long y) {\n        double val = (b - a) * (b - a) + (x - y) * (x - y);\n        val = Math.sqrt(val);\n        double other = x * x + a * a;\n        other = Math.sqrt(other);\n        return val + other;\n\n    }\n\n    public static class Point implements Comparable<Point> {\n\n        int x, y;\n\n        public Point(int start, int end) {\n            this.x = start;\n            this.y = end;\n        }\n\n        @Override\n        public int hashCode() {\n            int hash = 5;\n            hash = 47 * hash + this.x;\n            hash = 47 * hash + this.y;\n            return hash;\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            if (obj == null) {\n                return false;\n            }\n            if (getClass() != obj.getClass()) {\n                return false;\n            }\n            final Point other = (Point) obj;\n            if (this.x != other.x) {\n                return false;\n            }\n            if (this.y != other.y) {\n                return false;\n            }\n            return true;\n        }\n\n        @Override\n        public int compareTo(Point o) {\n            return Integer.compare(x, o.x);\n        }\n    }\n\n    public static class FT {\n\n        long[] data;\n\n        FT(int n) {\n            data = new long[n];\n        }\n\n        public void update(int index, long value) {\n            while (index < data.length) {\n                data[index] += value;\n                index += (index & (-index));\n            }\n        }\n\n        public long get(int index) {\n            long result = 0;\n            while (index > 0) {\n                result += data[index];\n                index -= (index & (-index));\n            }\n            return result;\n\n        }\n    }\n\n    public static long gcd(long a, long b) {\n        if (b == 0) {\n            return a;\n        }\n        return gcd(b, a % b);\n    }\n\n    public static long pow(long a, 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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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 Amine L\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastInput in = new FastInput(inputStream);\n        FastOutput out = new FastOutput(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, FastInput in, FastOutput out) {\n\n            long n = in.nextLong();\n            long s = in.nextLong();\n            long cnt = 0;\n            long res = 0;\n\n            for (long i = s; i <= Math.min(s + 200, n); i++) {\n                long d = i;\n                int sum = 0;\n                while (d > 0) {\n                    long l = d % 10;\n                    sum += l;\n                    d /= 10;\n                }\n                if ((i - sum) >= s) {\n                    cnt++;\n                }\n            }\n            long tmp = n - Math.min(n, s + 200);\n            if (tmp < 0) tmp = 0;\n            cnt += tmp;\n            out.println(cnt);\n\n\n        }\n\n    }\n\n    static class FastInput {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private FastInput.SpaceCharFilter filter;\n\n        public FastInput(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class FastOutput {\n        private final PrintWriter writer;\n\n        public FastOutput(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public FastOutput(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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\n public class Main {\n\tprivate InputStream is;\n\tprivate PrintWriter out;\n\tint time = 0, dp[][], DP[][], start[], parent[], end[], val[], black[], MOD = (int)(1e9+7), arr[], arr1[];\n\tint MAX = 10000000, N, K, p;\n\tArrayList<Integer>[] amp, amp1;\n\tboolean b[], b1[];\n\tPair prr[];\n\tchar ch[][];\n\tHashSet<Integer> hs = new HashSet<>();\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Thread(null, new Runnable() {\n\t\tpublic void run() {\n\t\t\ttry {\n\n\t\t//new Main().soln();\n\t\t} catch (Exception e) {\n\t\t\t\tSystem.out.println(e);\n\t\t\t}\n\t\t}\n\t}, \"1\", 1 << 26).start();\n\t\tnew Main().soln();\n\t}\n\tvoid solve() {\n\t\tlong n = nl(), s = nl();\n\t\tlong low = 1, high = n+1;\n\t\tlong ans = high;\n\t\twhile(low<=high){\n\t\t\tlong mid = (high+low)/2;\n\t\t\tif((mid - getSum(mid))>=s){\n\t\t\t\thigh = mid-1;\n\t\t\t\tans = mid;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlow = mid+1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(Math.max(0, n-ans+1));\n\t}\n\tint getSum(long s){\n\t\tString str = Long.toString(s);\n\t\tint ans = 0;\n\t\tfor(char ch : str.toCharArray()) ans += (ch-'0');\n\t\treturn ans;\n\t}\n\tint recur(int x){\n\t\t//System.out.println(x);\n\t\tint ans = 0;\n\t\tb[x] = true;\n\t\tfor(int i : amp[x]){\n\t\t\tif(!b[i]){\n\t\t\t\tb[i] = true;\n\t\t\t\tans = Math.max(recur(i), ans);\n\t\t\t\tb[i] = false;\n\t\t\t}\n\t\t}\n\t\treturn 1+ans;\n\t}\n\tint max = 0;\n\tint getParent(int x){\n\t\t//System.out.println(x+\" \"+parent[x]);\n\t\tif(parent[x]!=x){\n\t\t\tparent[x] = getParent(parent[x]);\n\t\t}\n\t\treturn parent[x];\n\t}\n\tint bfs(int x){\n\t\tb[x] = true;\n\t\tQueue<Integer> q =  new LinkedList<>();\n\t\tq.add(x);\n\t\twhile(!q.isEmpty()){\n\t\t\tint y = q.poll();\n\t\t\tfor(int i : amp[y]){\n\t\t\t\tif(!b[i]){\n\t\t\t\t\tb[i] = true;\n\t\t\t\t\tval[i] = val[y]+1;\n\t\t\t\t\tmax = Math.max(val[i], max);\n\t\t\t\t\tq.add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n\tclass Pair implements Comparable<Pair>{\n\t\tint u, v, r;\n\t\tPair(int u, int v){\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t}public int hashCode() {\n\t\t\treturn Objects.hash();\n\t\t}\n\t\tpublic boolean equals(Object o) {\n\t\t\tPair other = (Pair) o;\n\t\t\treturn ((u == other.u && v == other.v));// || (v == other.u && u == other.v));\n\t\t}\n\t\tpublic int compareTo(Pair other) {\n\t\t\t//return Integer.compare(other.r, r);\n\t\t\treturn Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(other.v,v));\n\t\t}\t\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t}\n\t}\n\tint min(int x,int y){\n\t\tif(x<y) return x;\n\t\treturn y;\n\t}\n\tint max(int x,int y){\n\t\tif(x>y) return x;\n\t\treturn y;\n\t}\n\tvoid dfs(int x){\n\t\tb[x] = true;\n\t\tfor(int i : amp[x]){\n\t\t\tif(!b[i]){\n\t\t\t\tdfs(i);\n\t\t\t}\n\t\t}\n\t}\n\tvoid buildGraph(int m){\n\t\twhile(m-->0)\n\t\t{\n\t\t\tint x = ni()-1, y = ni()-1;\n\t\t\tamp[x].add(y);\n\t\t\tamp[y].add(x);\n\t\t}\n\t}\n\tlong modInverse(long a, long mOD2){\n        return  power(a, mOD2-2, mOD2);\n\t}\n\tlong power(long x, long y, long m)\n\t{\n\t\tif (y == 0)\n    return 1;\n\tlong p = power(x, y/2, m) % m;\n\tp = (p * p) % m;\n\n\treturn (y%2 == 0)? p : (x * p) % m;\n\t}\n\tboolean isPrime(int x){\n\t\tfor(int i = 2;i*1L*i<=x;i++) if(x%i==0) return false;\n\t\treturn true;\n\t}\n\tpublic long gcd(long a, long b){\n\t\tif(b==0) return a;\n\t\treturn gcd(b,a%b);\n\t}\n\tvoid failFn(String str, int arr[]){\n\t\tint len = 0;\n\t\tarr[0] = 0;\n\t\tint i = 1;\n\t\twhile(i<arr.length){\n\t\t\tif(str.charAt(i)==str.charAt(len)){\n\t\t\t\tarr[i++] = ++len;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(len == 0){\n\t\t\t\tarr[i] = len;\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(str.charAt(i)!=str.charAt(len)){\n\t\t\t\tlen = arr[len-1];\n\t\t\t}\n\t\t}\n\t}\n\tstatic class ST1{\n\t\tint arr[], st[], size;\n\t\tST1(int a[]){\n\t\t\tarr = a.clone();\n\t\t\tsize = 10*arr.length;\n\t\t\tst = new int[size];\n\t\t\tbuild(0,arr.length-1,1);\n\t\t}\n\t\tvoid build(int ss, int se, int si){\n\t\t\tif(ss==se){\n\t\t\t\tst[si] = arr[ss];\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (ss+se)/2;\n\t\t\tint val = 2*si;\n\t\t\tbuild(ss,mid,val); build(mid+1,se,val+1);\n\t\t\tst[si] = (st[val]+ st[val+1]);\n\t\t}\n\t\tint get(int ss, int se, int l, int r, int si){\n\t\t\tif(l>se || r<ss || l>r) return Integer.MAX_VALUE;\n\t\t\tif(l<=ss && r>=se) return st[si];\n\t\t\tint mid = (ss+se)/2;\n\t\t\tint val = 2*si;\n\t\t\treturn (get(ss,mid,l,r,val)+ get(mid+1,se,l,r,val+1));\n\t\t}\n\t}\n\tstatic class ST{\n\t\tint arr[],lazy[],n;\n\t\tST(int a){\n\t\t\tn = a;\n\t\t\tarr = new int[10*n];\n\t\t\tlazy = new int[10*n];\n\t\t}\n\t\tvoid up(int l,int r,int val){\n\t\t\tupdate(0,n-1,0,l,r,val);\n\t\t}\n\t\tvoid update(int l,int r,int c,int x,int y,int val){\n\t\t\tif(lazy[c]!=0){\n\t\t\t\tlazy[2*c+1]+=lazy[c];\n\t\t\t\tlazy[2*c+2]+=lazy[c];\n\t\t\t\tif(l==r)\n\t\t\t\t\tarr[c]+=lazy[c];\n\t\t\t\tlazy[c] = 0;\n\t\t\t}\n\t\t\tif(l>r||x>y||l>y||x>r)\n\t\t\t\treturn;\n\t\t\tif(x<=l&&y>=r){\n\t\t\t\tlazy[c]+=val;\n\t\t\t\treturn ;\n\t\t\t}\n\t\t\tint mid = l+r>>1;\n\t\t\tupdate(l,mid,2*c+1,x,y,val);\n\t\t\tupdate(mid+1,r,2*c+2,x,y,val);\n\t\t\tarr[c] = (arr[2*c+1]+ arr[2*c+2]);\n\t\t}\n\t\tint an(int ind){\n\t\t\treturn ans(0,n-1,0,ind);\n\t\t}\n\t\tint ans(int l,int r,int c,int ind){\n\t\t\tif(lazy[c]!=0){\n\t\t\t\tlazy[2*c+1]+=lazy[c];\n\t\t\t\tlazy[2*c+2]+=lazy[c];\n\t\t\t\tif(l==r)\n\t\t\t\t\tarr[c]+=lazy[c];\n\t\t\t\tlazy[c] = 0;\n\t\t\t}\n\t\t\tif(l==r)\n\t\t\t\treturn arr[c];\n\t\t\tint mid = l+r>>1;\n\t\t\tif(mid>=ind)\n\t\t\t\treturn ans(l,mid,2*c+1,ind);\n\t\t\treturn ans(mid+1,r,2*c+2,ind);\n\t\t}\n\t}\n\tpublic static class FenwickTree {\n\t\t\n\t    int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates\n\n\t    public FenwickTree(int size) {\n\t        array = new int[size + 1];\n\t    }\n\t    public int rsq(int ind) {\n\t        assert ind > 0;\n\t        int sum = 0;\n\t        while (ind > 0) {\n\t            sum += array[ind];\n\t            //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number\n\t            ind -= ind & (-ind);\n\t        }\n\t        return sum;\n\t    }\n\t    public int rsq(int a, int b) {\n\t        assert b >= a && a > 0 && b > 0;\n\t        return rsq(b) - rsq(a - 1);\n\t    }\n\t    public void update(int ind, int value) {\n\t        assert ind > 0;\n\t        while (ind < array.length) {\n\t            array[ind] += value;\n\t            //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number\n\t            ind += ind & (-ind);\n\t        }\n\t    }\n\t    public int size() {\n\t        return array.length - 1;\n\t    }\n\t}\n\tpublic static int[] shuffle(int[] a, Random gen){\n\t\tfor(int i = 0, n = a.length;i < n;i++)\n\t\t{ \n\t\t\tint ind = gen.nextInt(n-i)+i; \n\t\t\tint d = a[i]; \n\t\t\ta[i] = a[ind];\n\t\t\ta[ind] = d; \n\t\t} \n\treturn a; \n\t}\n\tlong power(long x, long y, int mod){\n\t\tlong ans = 1;\n\t\twhile(y>0){\n\t\t\tif(y%2==0){\n\t\t\t\tx = (x*x)%mod;\n\t\t\t\ty/=2;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tans = (x*ans)%mod;\n\t\t\t\ty--;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tvoid soln() {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\t//out.close();\n\t\tout.flush();\n\t\t//tr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\n\t// To Get Input\n\t// Some Buffer Methods\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\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 && !(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\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n\tprivate void tr(Object... o) {\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C {\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\n\t\tlong n = scan.nextLong();\n\t\tlong s = scan.nextLong();\n\t\tlong low = 0;\n\t\tlong high = n + 1;\n\t\twhile (high-low>1) {\n\t\t\tlong sum = 0;\n\t\t\tlong mid = (high + low) / 2;\n\t\t\tlong value = findSum(mid, sum);\n\t\t\tif (mid - value >= s)\n\t\t\t\thigh = mid;\n\t\t\telse\n\t\t\t\tlow = mid;\n\t\t}\n\t\t\n\t\tSystem.out.println(n - high + 1);\n\n\t\tscan.close();\n\t}\n\n\tpublic static long findSum(long n, long sum) {\n\t\tif (n == 0)\n\t\t\treturn sum;\n\t\treturn findSum(n / 10, sum + n % 10);\n\t}\n\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.util.*;\n\npublic class ed817Q3 {\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\tint t = 1;\n\t\tfor(int zxz=0;zxz<t;zxz++){\n\t\t\t// my code starts here\n\t\t\tlong n = in.nextLong();\n\t\t\tlong s = in.nextLong();\n\t\t\tlong start=0,end=n;\n\t\t\tlong ans=n+1;\n\t\t\twhile(start<=end){\n\t\t\t\tlong mid = start+(end-start)/2;\n\t\t\t\tif(mid-digitSum(mid)>=s){\n\t\t\t\t\tans = mid;\n\t\t\t\t\tend = mid-1;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstart=mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(n-ans+1);\n\t\t\t// my code ends here\n\t\t}\n\t}\n\tstatic int digitSum(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\tstatic class InputReader {\n\t\t \n        private InputStream stream;\n        private 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            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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF817C {\n\tstatic long count(long x) {\n\t\treturn x < 10 ? x : count(x / 10) + x % 10;\n\t}\n\tstatic boolean check(long x, long s) {\n\t\treturn x - count(x) >= s;\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\tlong n = Long.parseLong(st.nextToken());\n\t\tlong s = Long.parseLong(st.nextToken());\n\t\tint d = 9 * 18;\n\t\tlong cnt;\n\t\tif (n >= s + d) {\n\t\t\tcnt = n - s - d;\n\t\t\tfor (long x = s; x <= s + d; x++)\n\t\t\t\tif (check(x, s))\n\t\t\t\t\tcnt++;\n\t\t} else {\n\t\t\tcnt = 0;\n\t\t\tfor (long x = s; x <= n; x++)\n\t\t\t\tif (check(x, s))\n\t\t\t\t\tcnt++;\n\t\t}\n\t\tSystem.out.println(cnt);\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n@SuppressWarnings(\"Duplicates\")\npublic class C817 {\n    private FastScanner in;\n    private PrintWriter out;\n\n    private long calcSum(long x) {\n        int ans = 0;\n        while (x > 0) {\n            ans += x % 10;\n            x /= 10;\n        }\n        return ans;\n    }\n\n    private long calcDiff(long x) {\n        return x - calcSum(x);\n    }\n\n    private long binSearch(long n, long s) {\n        long l = 0;\n        long r = n + 1;\n\n        while (r - l > 1) {\n            long m = (r + l) >> 1;\n            if (calcDiff(m) >= s) {\n                r = m;\n            } else {\n                l = m;\n            }\n        }\n        return l;\n    }\n\n    private void solve() throws IOException {\n        long n = in.nextLong();\n        long s = in.nextLong();\n\n        long ans = binSearch(n, s);\n\n        out.println(n - ans);\n    }\n\n    private 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        FastScanner(File f) {\n            try {\n                br = new BufferedReader(new FileReader(f));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n\n    public static void main(String[] arg) {\n        new C817().run();\n    }\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main\n{\n\n    public static void main(String[] args)\n    {\n        setup();\n        xuly();\n    }\n\n    private static long dp[][] = new long[20][170];\n\n    private static void setup() {\n        dp[0][0] = 1;\n        for (int i = 1; i < 20; i ++)\n            for (int j = 0; j < 170; j ++)\n                for (int k = Math.max(j - 9, 0); k <= j; k ++)\n                    dp[i][j] += dp[i - 1][k];\n    }\n\n    private static int sumD(long x) {\n        int ret = 0;\n        while(x > 0) {\n            ret += x % 10;\n            x /= 10;\n        }\n        return ret;\n    }\n\n    private static long numSatisfy(long limit, int sumDigit) {\n        long ret = 0;\n        int curSum = sumD(limit);\n        if (curSum == sumDigit)\n            ret ++;\n\n        for (int i = 0; i < 20; i ++) {\n            int bound = (int) (limit % 10);\n            curSum -= bound;\n            for (int d = 0; d < bound && curSum + d <= sumDigit; d ++)\n                ret += dp[i][sumDigit - curSum - d];\n            limit /= 10;\n        }\n\n        return ret;\n    }\n\n    private static void xuly() {\n        Scanner scanner = new Scanner(System.in);\n        long n = scanner.nextLong();\n        long s = scanner.nextLong();\n        long ans = 0;\n        for (int sum = 1; sum < 170; sum ++)\n            if (n >= s + sum)\n                ans += numSatisfy(n, sum) - numSatisfy(s + sum - 1, sum);\n        System.out.print(ans);\n    }\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _817C {\n\n    static long sum = 0;\n\n    static long BSearch2(long st, long end, long lim) {\n\n        if (st > end) return 0;\n        long mid = (st + end) >> 1;\n        if (mid - sumDigit(mid) >= lim) {\n            sum = mid;\n            return BSearch2(st, mid - 1, lim);\n        }\n        if (mid - sumDigit(mid) < lim)\n            return BSearch2(mid + 1, end, lim);\n        return 0;\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(in.readLine());\n        long s = Long.parseLong(st.nextToken());\n        long n = Long.parseLong(st.nextToken());\n        BSearch2(1, s, n);\n        if (sum == 0) System.out.println(\"0\");\n        else System.out.println(s - sum + 1);\n\n    }\n\n    static long sumDigit(long z) {\n        String s = \"\" + z;\n        int c = 0;\n        for (int i = 0; i < s.length(); i++) c += s.charAt(i);\n        return c - s.length() * 0x30;\n    }\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tpublic static void main(String[] args) throws InterruptedException{\n\t\tFastScanner scan = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tlong n = scan.nextLong(), s = scan.nextLong();\n\t\tlong lo = 1, hi = n+1;\n\t\tfor(int bs = 0; bs < 100; bs++) {\n\t\t\tlong mid = (lo+hi)>>1;\n\t\t\tlong mid2 = mid;\n\t\t\tlong c = 0;\n\t\t\twhile(mid > 0) {\n\t\t\t\tc += mid%10;\n\t\t\t\tmid /= 10;\n\t\t\t}\n\t\t\tif(mid2-c < s) lo = mid2;\n\t\t\telse hi = mid2;\n\t\t}\n\t\tout.println(n-lo);\n\t\tout.close();\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\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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport javax.swing.Painter;\n\nimport java.io.*;\n\npublic class C {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\t\n\tpublic static class Pair implements Comparable<Pair> {\n\t\tint x;\n\t\tint y;\n\t\tpublic Pair(int x, int y) {\n\t\t\tsuper();\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void quickSort(long[] a, int from, int to) {\n\t\tif (to - from <= 1) {\n\t\t\treturn;\n\t\t}\n\t\tint i = from;\n\t\tint j = to - 1;\n\t\tlong x = a[from + (new Random()).nextInt(to - from)];\n\t\twhile (i <= j) {\n\t\t\twhile (a[i] < x) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (a[j] > x) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i <= j) {\n\t\t\t\tlong t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t\ti++;\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\t\tquickSort(a, from, j + 1);\n\t\tquickSort(a, j + 1, to);\n\t}\n\t\n\tpublic static long check(long x) {\n\t\tlong sum = 0;\n\t\tlong k = x;\n\t\twhile (x > 0) {\n\t\t\tsum += x % 10;\n\t\t\tx /= 10;\n\t\t}\n\t\treturn k - sum;\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tlong n = in.nextLong();\n\t\tlong s = in.nextLong();\n\t\tlong ans = 0;\n\t\tfor (long i = s; i <= Math.min(n, s + 10000L); i++) {\n\t\t\tif (check(i) >= s) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\tans += (n - Math.min(n, s + 10000L));\n\t\tSystem.out.println(ans);\n\t}\n\n\tpublic void run() throws IOException {\n\t\tif (systemIO) {\n\t\t\tin = new FastScanner(System.in);\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new FastScanner(new File(\"input.txt\"));\n\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t}\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\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) throws IOException {\n\t\tnew C().run();\n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\n/**\n *\n * @author Fuad\n */\npublic class Codeforces {\n\n    private static boolean greater(long mid, long s) {\n\n        int sum = 0;\n        long num = mid;\n\n        while (num != 0) {\n            sum += (num % 10);\n            num /= 10;\n\n        }\n\n        return mid - sum >= s;\n    }\n\n    static class pair {\n\n        int first;\n        int second;\n\n        pair(int f, int s) {\n            first = f;\n            second = s;\n        }\n\n        pair() {\n\n        }\n\n    }\n\n    public static void main(String[] args) throws Exception {\n        // TODO code application logic here\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        long n, s;\n\n        String arr[] = br.readLine().split(\" \");\n\n        n = Long.parseLong(arr[0]);\n        s = Long.parseLong(arr[1]);\n\n        long l = 1;\n        long h = n;\n\n        while (l < h) {\n            long mid = (l + h) / 2;\n            if (greater(mid, s)) {\n                h = mid;\n            } else {\n                l = mid + 1;\n            }\n        }\n\n        System.out.println(greater(h, s) ? n - h + 1 : 0);\n\n    }\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\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.Iterator;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n\npublic class Solution {\n\t\n\tlong sum(long n){\n\t\tlong sm = 0;\n\t\t\n\t\twhile(n!=0){\n\t\t\tsm+=(n%10);\n\t\t\tn/=10;\n\t\t}\n\t\t\n\t\treturn sm;\n\t\t\n\t}\n\t\n\tvoid solve() throws IOException{\n\t\t\n\t\tlong n = in.nextLong();\n\t\tlong s = in.nextLong();\n\t\t\n\t\tlong l = 0;\n\t\tlong h = n+1;\n\t\tlong ans = -1;\n\t\t\n\t\twhile(l<h){\n\t\t\t long mid = (l + h)/2;\n\t\t\t \n\t\t\t long sum = sum(mid);\n\t\t\t \n\t\t\t if(mid - sum >= s){\n\t\t\t\t ans = mid;\n\t\t\t\t h = mid;\n\t\t\t }\n\t\t\t else\n\t\t\t\t l = mid+1;\n\t\t\t \n\t\t\t// System.out.println(mid);\n\t\t\t \n\t\t\t// ans = (mid+1);\n\t\t\t\n\t\t}\n\t\t\n\t//\tSystem.out.println(ans);\n\t\t\n\t\tif(ans==-1)\n\t\t\tout.println(\"0\");\n\t\telse\n\t\t\tout.println(n+1-ans);\n\t\t\n\t\t\n\t\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} // solve\n\n\tclass FastScanner{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\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\t\n\t\tpublic int nextInt() throws IOException{\n\t\t\t if(st.hasMoreTokens())\n\t\t\t\treturn Integer.parseInt(st.nextToken());\n\t\t\telse{\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\treturn nextInt();\n\t\t\t}\t\t\t\n\t\t}\n\t\t\n\t\tpublic long nextLong() throws IOException{\n\t\t\t if(st.hasMoreTokens())\n\t\t\t\treturn Long.parseLong(st.nextToken());\n\t\t\telse{\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\treturn nextLong();\n\t\t\t}\t\t\t\n\t\t}\n\t\t\n\t\tpublic String readLine() throws IOException{\n\t\t\treturn br.readLine();\n\t\t}\n\t}\n\t\n\tFastScanner in = new FastScanner();\n\tstatic PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); \n\t\n\t\n\tpublic static void main(String args[])throws IOException{\n\t\t new Solution().solve();\n\t\t out.close();\n\t}\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tstatic int[] UPPER = new int[64], LOWER = new int[64];\n\tstatic long[][][] memo;\n\t\n\tstatic long dp(int bit, int lims, int digs)\n\t{\n\t\tif(bit == -1)\n\t\t\treturn digs == 0 ? 1 : 0;\n\t\tif(memo[lims][bit][digs] != -1)\n\t\t\treturn memo[lims][bit][digs];\n\t\tlong ret = 0;\n\t\tfor(int d = 0, end = digs < 10 ? digs + 1 : 10; d < end; ++d)\n\t\t\tif(((lims & 1) == 1 || d >= LOWER[bit]) && ((lims & 2) == 2 || d <= UPPER[bit]))\n\t\t\t\tret += dp(bit - 1, lims | (d > LOWER[bit] ? 1 : 0) | (d < UPPER[bit] ? 2 : 0), digs - d);\n\t\treturn memo[lims][bit][digs] = ret;\n\t}\n\t\n\tstatic void create(int[] x, long n)\n\t{\n\t\tfor(int i = 0; i < 64; ++i)\n\t\t{\n\t\t\tx[i] = (int) (n % 10);\n\t\t\tn /= 10;\n\t\t}\n\t}\n\t\n\tstatic void prepMemo(int sod)\n\t{\n\t\tmemo = new long[4][64][sod + 1];\n\t\tfor(long[][] x: memo)\n\t\t\tfor(long[] y: x)\n\t\t\t\tArrays.fill(y, -1);\n\t}\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\tlong n = sc.nextLong(), s = sc.nextLong();\n\t\tcreate(UPPER, n);\n\t\tlong ans = 0;\n\t\tfor(int sod = 1; sod <= 162; ++sod)\n\t\t{\n\t\t\tcreate(LOWER, s + sod);\n\t\t\tprepMemo(sod);\n\t\t\tans += dp(63, 0, sod);\n\t\t}\n\t\t\n\t\t\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic Scanner(String s) throws FileNotFoundException{\tbr = new BufferedReader(new FileReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.util.*;\n\npublic class ed817Q3 {\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\tint t = 1;\n\t\tfor(int zxz=0;zxz<t;zxz++){\n\t\t\t// my code starts here\n\t\t\tlong n = in.nextLong();\n\t\t\tlong s = in.nextLong();\n\t\t\tlong start=s,end=n;\n\t\t\tlong ans=n+1;\n\t\t\twhile(start<=end){\n\t\t\t\tlong mid = start+(end-start)/2;\n\t\t\t\tif(mid-digitSum(mid)>=s){\n\t\t\t\t\tans = mid;\n\t\t\t\t\tend = mid-1;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tstart=mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(n-ans+1);\n\t\t\t// my code ends here\n\t\t}\n\t}\n\tstatic int digitSum(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\tstatic class InputReader {\n\t\t \n        private InputStream stream;\n        private 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            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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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        public void solve(int testNumber, Scanner in, PrintWriter out) {\n            long n = in.nextLong();\n            long s = in.nextLong();\n            long ans = 0;\n            long i = 0;\n            for (i = s; i <= n; i++) {\n                long t = i - sum(i);\n                if (t >= s) {\n                    if (i % 10 == 9) {\n                        break;\n                    }\n                    ans++;\n                }\n            }\n            if (n >= s) {\n                out.println(ans - i + n + 1);\n            } else {\n                out.println(0);\n            }\n        }\n\n        static long sum(long a) {\n            long sum = 0;\n            while (a != 0) {\n                sum += (a % 10);\n                a /= 10;\n            }\n            return sum;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    class IOManager {\n        BufferedReader reader;\n        PrintWriter writer;\n        StringTokenizer tokenizer;\n\n        IOManager() {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            writer = new PrintWriter(new BufferedOutputStream(System.out));\n        }\n\n        IOManager(String file) throws FileNotFoundException {\n            reader = new BufferedReader(new FileReader(file));\n            writer = new PrintWriter(new BufferedOutputStream(System.out));\n        }\n\n        String next() throws IOException {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                String line = reader.readLine();\n                if (line == null)\n                    throw new IOException(\"No lines left.\");\n                tokenizer = new StringTokenizer(line);\n            }\n            return tokenizer.nextToken();\n        }\n\n        public Integer 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 void writeSpace(Object obj) {\n            writer.print(obj.toString() + \" \");\n        }\n\n        public void writeLine(Object obj) {\n            writer.println(obj.toString());\n        }\n\n        public void writeDouble(Double x, int n) {\n            String format = \"%.\" + n + \"f\";\n            writer.printf(format, x);\n        }\n\n        public void write(Object obj) {\n            writer.print(obj.toString());\n        }\n\n        public void close() {\n            writer.close();\n        }\n    }\n\n    class Pair implements Comparable {\n        public long u, v;\n\n        public Pair(long u, long v) {\n            this.u = u;\n            this.v = v;\n        }\n\n        @Override\n        public int compareTo(Object o) {\n            Pair that = (Pair) o;\n            if (Long.compare(u, that.u) != 0)\n                return Long.compare(u, that.u);\n            return Long.compare(v, that.v);\n        }\n    }\n\n    class Graph {\n        public int n, m;\n        public List<Integer>[] adj;\n\n        public Graph(int n, int m) {\n            this.n = n;\n            this.m = m;\n            adj = new List[n + 1];\n            for (int i = 0; i <= n; ++i) {\n                adj[i] = new ArrayList<>();\n            }\n        }\n\n        public void add(int u, int v) {\n            adj[u].add(v);\n        }\n\n        public void add2Ways(int u, int v) {\n            add(u, v);\n            add(v, u);\n        }\n\n        public void dfs(int i, boolean fr[]) {\n            fr[i] = false;\n            for (int j: adj[i]) {\n                if (fr[j]) {\n                    dfs(j, fr);\n                }\n            }\n        }\n\n        public boolean isConnected() {\n            boolean fr[] = new boolean[n + 1];\n            Arrays.fill(fr, true);\n            dfs(1, fr);\n            for (int i = 2; i <= n; ++i) {\n                if (fr[i])\n                    return false;\n            }\n            return true;\n        }\n\n        public boolean hasEuclideanPath() {\n            if (!isConnected())\n                return false;\n            int cnt = 0;\n            for (int i = 1; i <= n; ++i) {\n                if (adj[i].size() % 2 == 1)\n                    cnt++;\n            }\n            return cnt <= 2;\n        }\n\n        public boolean dfsHamiltonian(int i, boolean[] fr, int reached) {\n            fr[i] = false;\n            reached++;\n            if (reached == n)\n                return true;\n            for (int j: adj[i]) {\n                if (fr[j]) {\n                    if (dfsHamiltonian(j, fr, reached))\n                        return true;\n                }\n            }\n            fr[i] = true;\n            return false;\n        }\n\n        public boolean hasHamiltonianPathFrom(int st) {\n            boolean fr[] = new boolean[n + 1];\n            Arrays.fill(fr, true);\n            return dfsHamiltonian(st, fr, 0);\n        }\n    }\n\n    // Actually rooted forest\n    class Tree extends Graph {\n\n        public Tree(int n, int m) {\n            super(n, m);\n        }\n\n        public int getHeight(int i) {\n            int res = 0;\n            for (Integer j: adj[i]) {\n                res = Math.max(res, getHeight(j) + 1);\n            }\n            return res;\n        }\n    }\n\n    class FenwickTree {\n        int n;\n        int tree[];\n\n        public FenwickTree() {\n\n        }\n\n        public FenwickTree(int maxn) {\n            n = maxn;\n            tree = new int[maxn + 10];\n        }\n\n        public void add(int i, int x) {\n            while (i <= n) {\n                tree[i] += x;\n                i += i & (-i);\n            }\n        }\n\n        public void add(int i) {\n            add(i, 1);\n        }\n\n        public int get(int i) {\n            int res = 0;\n            while (i > 0) {\n                res += tree[i];\n                i -= i & (-i);\n            }\n            return res;\n        }\n    }\n\n    IOManager ioManager;\n\n    Main() {\n        ioManager = new IOManager();\n    }\n\n    Main(String file) throws FileNotFoundException {\n        ioManager = new IOManager(file);\n    }\n\n    long n, s;\n    int m, a[], sum[];\n    long pow[];\n    long f[][];\n\n    void doi(long n) {\n        m = 0;\n        while (n > 0) {\n            a[m++] = (int) (n % 10L);\n            n /= 10L;\n        }\n    }\n\n    int getsum(long n) {\n        int res = 0;\n        while (n > 0) {\n            res += (int) (n % 10L);\n            n /= 10L;\n        }\n        return res;\n    }\n\n    void solve() throws IOException {\n        n = ioManager.nextLong();\n        s = ioManager.nextLong();\n        a = new int[100];\n        pow = new long[100];\n        pow[0] = 1;\n        for (int i = 1; i < 100; ++i) {\n            pow[i] = pow[i - 1] * 10L;\n        }\n        doi(n);\n        sum = new int[m + 1];\n        sum[m] = 0;\n        for (int i = m - 1; i >= 0; --i)\n            sum[i] = sum[i + 1] + a[i];\n\n\n        long first = -1;\n        for (long i = s + 1; i <= n; ++i) {\n            if (i - getsum(i) >= s) {\n                first = i;\n                break;\n            }\n        }\n        if (first == -1) {\n            ioManager.writeLine(0);\n            return;\n        }\n        ioManager.writeLine(n - first + 1);\n    }\n\n    void close() {\n        ioManager.close();\n    }\n\n    public static void main(String args[]) throws IOException {\n        Main solver;\n        if (!\"true\".equals(System.getProperty(\"ONLINE_JUDGE\"))) {\n            solver = new Main(\"input.txt\");\n        } else {\n            solver = new Main();\n        }\n        solver.solve();\n        solver.close();\n    }\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "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\n\npublic class C {\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\tlong n = nextLong();\n\t\tlong s = nextLong();\n\t\tlong ans = 0;\n\t\tif (s+200 <= n)\n\t\t\tans += n - (s+200) + 1;\n\t\tfor (long i = s; i < s+200; i++) {\n\t\t\tif (i <= n && i-sumDigits(i) >= s) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tpw.close();\n\t}\n\tprivate static long sumDigits(long n) {\n\t\tlong sum = 0;\n\t\twhile (n > 0) {\n\t\t\tsum += n % 10;\n\t\t\tn /= 10;\n\t\t}\n\t\treturn sum;\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}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n \npublic class TestClass implements Runnable\n{\n\t/*int x,y;\n\tpublic TestClass(int x,int y)\n\t{\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t}*/\n\tpublic static void main(String args[])\n\t{\n\t\tnew Thread(null, new TestClass(),\"TESTCLASS\",1<<18).start();\n\t}\n\tpublic void run()\n\t{\n\t\t//Scanner scan=new Scanner(System.in);\n\t\tInputReader hb=new InputReader(System.in);\n\t\tPrintWriter w=new PrintWriter(System.out);\n\t\t\n\t\tlong n=hb.nextLong();\n\t\tlong s=hb.nextLong();\n\t\t\n\t\tlong start=0;\n\t\tlong end=n;\n\t\tlong ans=0;\n\t\twhile(start<=end)\n\t\t{\n\t\t\tlong mid=(start+end)/2;\n\t\t\tif(mid-get(mid)>=s)\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t\tans=mid;\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}\n\t\tif(ans<1)\n\t\t\tw.print(0);\n\t\telse\n\t\t\tw.print(n-ans+1);\n\t\tw.close();\n\t}\n\t\n\tpublic long get(long a)\n\t{\n\t\tString str = Long.toString(a);\n\t\tint ans = 0;\n\t\tfor(char ch : str.toCharArray())\n\t\t\tans += (ch-'0');\n\t\treturn ans;\n\t}\n\t\n\t\n\tprivate void shuffle(int[] arr)\n\t{\n\t\tRandom ran = new Random();\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tint i1 = ran.nextInt(arr.length);\n\t\t\tint i2 = ran.nextInt(arr.length);\n\n\t\t\tint temp = arr[i1];\n\t\t\tarr[i1] = arr[i2];\n\t\t\tarr[i2] = temp;\n\t\t}\n\t}\n\t\n\tstatic class DSU\n\t{\n\t\tint parent[];\n\t\tint sizeParent[];\n\t\tDSU(int n)\n\t\t{\n\t\t\tparent=new int[n];\n\t\t\tsizeParent=new int[n];\n\t\t\tArrays.fill(sizeParent,1);\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\tparent[i]=i;\n\t\t}\n\t\t\n\t\tint find(int x)\n\t\t{\n\t\t\tif(x!=parent[x])\n\t\t\t\tparent[x]=find(parent[x]);\n\t\t\treturn parent[x];\n\t\t}\n\t\t\n\t\tvoid union(int x,int y)\n\t\t{\n\t\t\tx=find(x);\n\t\t\ty=find(y);\n\t\t\tif(sizeParent[x]>=sizeParent[y])\n\t\t\t{\n\t\t\t\tif(x!=y)\n\t\t\t\t\tsizeParent[x]+=sizeParent[y];\n\t\t\t\tparent[y]=x;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(x!=y)\n\t\t\t\t\tsizeParent[y]+=sizeParent[x];\n\t\t\t\tparent[x]=y;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class InputReader\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n\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\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n\tstatic class Pair implements Comparable<Pair>\n\t{\n\t\tint a;\n\t\tint b;\n\t\tString str;\n\t\tpublic Pair(int a,int b)\n\t\t{\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t\tstr=min(a,b)+\" \"+max(a,b);\n\t\t}\n \n\t\tpublic int compareTo(Pair pair)\n\t\t{\n\t\t\tif(Integer.compare(a,pair.a)==0)\n\t\t\t\treturn Integer.compare(b,pair.b);\n \n\t\t\treturn Integer.compare(a,pair.a);\n\t\t}\n\t}\n \n\t\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n public class Q1 {\n\n\tstatic ArrayList<Integer> adj[],adj2[];\n\tstatic int color[],cc;\n\tstatic long mod=1000000007;\n\tstatic TreeSet<Integer> ts[];\n\tstatic boolean b[],visited[],possible,ans1,ans2;\n\tstatic Stack<Integer> s;\n\tstatic int totalnodes,colored,min,minc;\n\tstatic int c[];\n\tstatic long sum[];\n\tstatic HashMap<Integer,Integer> hm;\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\t//Scanner sc=new Scanner(System.in);\n\t\tin=new InputReader(System.in);\n\t\tout=new PrintWriter(System.out);\n\t\tString n1=in.readString();\n\t\tString s1=in.readString();\n\t\tlong s=Long.parseLong(s1);\n\t\tlong n=Long.parseLong(n1);\n\t\t\n\t\tlong l=s-1;\n\t\tlong r=n+1;\n\t\tHashSet<Long> hset=new HashSet<>();\n\t\tlong last=-1;\n\t\twhile(l<r)\n\t\t{\n\t\t\tlong mid=(l+r)/2;\n\t\t\tlong sum=0;\n\t\t\tif(hset.contains(mid))\n\t\t\t\tbreak;\n\t\t\tString d=String.valueOf(mid);\n\t\t\tfor(int i=0;i<d.length();i++)\n\t\t\t{\n\t\t\t\tsum=sum+(d.charAt(i)-'0');\n\t\t\t}\n\t\t\t//debug(sum);\n\t\t\thset.add(mid);\n\t\t\t\n\t\t\tif(mid-sum>=s)\n\t\t\t{\n\t\t\t\tlast=mid;\n\t\t\t\tr=mid;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tl=mid;\n\t\t\t}\n\t\t}\n\t\tif(last==-1)\n\t\t\tout.println(\"0\");\n\t\telse\n\t\t{\n\t\t\tout.println(n-last+1);\n\t\t}\n\t\tout.close();\n\t\t}\n\t\n\tstatic InputReader in;\n\tstatic PrintWriter out;\n \tstatic void dfs(int i,int parent)\n\t{\n \t\tif(color[i]!=cc)\n \t\t\tans1= false;\n \t\tfor(int j:adj[i])\n \t\t{\n \t\t\tif(j!=parent)\n \t\t\t{\n \t\t\t\tdfs(j,i);\n \t\t\t}\n \t\t}\n\t\t\n\t}\n\t/*public static void seive(long n){\n\t\tb = new boolean[(int) (n+1)];\n\tArrays.fill(b, true);\n\t\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<Pair> {\n\t\tint i;\n\t\tint j;\n\t\tint index;\n\t\tpublic Pair(){\n\t\t\t\n\t\t}\n\t\tpublic Pair(int u, int v,int index) {\n\t\t\tthis.i = u;\n\t\t\tthis.j= v;\n\t\t\tthis.index=index;\n\t\t}\n\t\tpublic int compareTo(Pair other) {\n\t\t\t\n\t\t\t\n\t\t\t\treturn this.i-other.i;\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<Integer> parent = new ArrayList<>();\n\t\tHashMap<Integer, Integer> 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.data<y) return n;\n\t\t\telse if(n.data<x && n.data<y) return getSomething(x,y,n.right);\n\t\t\telse return getSomething(x,y,n.left);\n\t\t}\n\t\tpublic Node2 search(int x,Node2 n){\n\t\t\tif(x==n.data){\n\t\t\t\tmax = Math.max(max, n.data);\n\t\t\t\treturn n;\n\t\t\t}\n\t\t\tif(x>n.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\nstatic long gcd(long a, long b)\n{\n    while (b > 0)\n    {\n        long temp = b;\n        b = a % b; // % is remainder\n        a = temp;\n    }\n    return a;\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}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        InputStream inputStream = System.in;\n//        InputStream inputStream = new FileInputStream(\"dijkstra.in\");\n        OutputStream outputStream = System.out;\n//        OutputStream outputStream = new FileOutputStream(\"dijkstra.out\");\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Answer solver = new Answer();\n        solver.solve(in, out);\n        out.close();\n    }\n}\n\nclass Answer {\n    private int sumd(long x) {\n        int sum = 0;\n        while (x != 0) {\n            sum += x % 10;\n            x /= 10;\n        }\n        return sum;\n    }\n\n    private long bin(long l, long r, long s) {\n        if (l > r) {\n            return -1;\n        }\n        long x = (l + r) >> 1;\n        int sum = sumd(x);\n        if (x - sum < s) {\n            return bin(x + 1, r, s);\n        }\n        long t = bin(l, x - 1, s);\n        if (t != -1) {\n            return t;\n        }\n        return x;\n    }\n\n    public void solve(InputReader in, PrintWriter out) throws IOException {\n        long n = in.nextLong();\n        long s = in.nextLong();\n        long t = bin(1, n, s);\n        if (t == -1) {\n            out.print(\"0\");\n        } else {\n            long ans = n - t + 1;\n            out.print(ans);\n        }\n    }\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream), 32768);\n        tokenizer = null;\n    }\n\n    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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\nimport java.util.ArrayList;\n\npublic class C{\n\t\n\tstatic long s;\n\tpublic static void main(String[] args)throws IOException {\n\t\tReader.init(System.in);\n\t\tlong n=Reader.nextLong();\n\t\ts=Reader.nextLong();\n\t\tlong lo=1,hi=n,mid;\n\t\twhile(lo<hi){\n\t\t\tmid=(lo+hi)/2;\n\t\t\tif(diff(mid)>=s)\n\t\t\t\thi=mid;\n\t\t\telse\n\t\t\t\tlo=mid+1;\n\t\t}\n\t\tif(diff(lo)>=s)\n\t\t\tSystem.out.println(n-lo+1);\n\t\telse\n\t\t\tSystem.out.println(0);\n\t}\n\t\n\tstatic long diff(long n){\n\t\tString s=String.valueOf(n);\n\t\tint sum=0;\n\t\t\n\t\tfor(int i=0;i<s.length();i++){\n\t\t\t\n\t\t\tsum+=Integer.parseInt(s.valueOf(s.charAt(i)));\n\t\t}\n\t\treturn (n-sum);\n\t}\n\t\t\n\t\t\n}\n\n\n\t\t\n/** Class for buffered reading int and double values */\nclass Reader {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    /** get next word */\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static long nextLong() throws IOException {\n        return Long.parseLong( next() );\n    }\n\t\n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class TestClass {\n    static PrintWriter out = new PrintWriter(System.out);\n    public static void main(String args[] ) throws Exception {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    \tString s[] = in.readLine().split(\" \");\n    \tlong n = Long.parseLong(s[0]);\n    \tlong k = Long.parseLong(s[1]);\n    \tlong x = bs(n,k);\n    \tout.println(n-x+1);\n        out.close();\n    }\n    public static long bs(long n,long k)\n    {\n    \tlong l=0,h=n;\n    \twhile(l<=h)\n    \t{\n    \t\tlong mid = l + (h-l)/2;\n    \t\tlong x = mid - sum(mid);\n    \t\tif(x>=k)\n    \t\t{\n    \t\t\th = mid-1;\n    \t\t}\n    \t\telse\n    \t\t{\n    \t\t\tl = mid+1;\n    \t\t}\n    \t}\n    \treturn l;\n    }\n    public static long sum(long x)\n    {\n    \tlong ans=0;\n    \twhile(x>0)\n    \t{\n    \t\tans += x%10;\n    \t\tx=x/10;\n    \t}\n    \treturn ans;\n    }\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = Long.parseLong(in.next());\n\t\tlong s = Long.parseLong(in.next());\n\t\tif(!check(n, s)){\n\t\t\tSystem.out.println(0);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong min = 1;\n\t\t\tlong max = n;\n\t\t\twhile(min != max)\n\t\t\t{\n\t\t\t\tlong mid = (min + max) / 2;\n\t\t\t\tif(check(mid, s))\n\t\t\t\t{\n\t\t\t\t\tmax = mid;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmin = mid + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//System.out.println(\"found: \" + min);\n\t\t\tSystem.out.println((n - min + 1));\n\t\t}\n\t}\n\tpublic static boolean check(long x, long s)\n\t{\n\t\tif(x - sumd(x) < s)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\tpublic static long sumd(long x)\n\t{\n\t\tlong sum = 0;\n\t\twhile(x != 0)\n\t\t{\n\t\t\tsum += x % 10;\n\t\t\tx /= 10;\n\t\t}\n\t\treturn sum;\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class ReallyBigNumbers1 \n{\n    \n    public static void main(String[] args) \n    {\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextLong();\n        long s = sc.nextLong();\n        \n        int r = 0 ;\n        \n        long l = 0L ;\n        long u = n ;\n        \n        if(  (l-sumDigits(l)< s )  && (u-sumDigits(u)< s ) )\n        {\n            System.out.println(0);\n            return ;\n        }\n        \n        long specified = 0L ;\n        while( true )\n        {\n            long m = (l + u) / 2L ;\n            \n            if( ( m - sumDigits(m) ) >= s && ( (m-1) - sumDigits(m-1) ) < s  )\n            {\n                specified = m ;\n                break ;\n            }\n            \n            if( l > u  )\n                break ;\n            \n            else\n            {\n                if( ( m - sumDigits(m) ) >= s )\n                    u = m-1 ;\n                else\n                    l = m+1 ;\n            }\n        }\n        \n        System.out.println( n-specified+1 );\n        \n        \n    }\n    \n    public static int sumDigits(long n)\n    {\n        char [] a = (n+\"\").toCharArray();\n        int sum = 0 ;\n        for(int k = 0 ; k < a.length ; k++)\n        {\n            sum += Integer.parseInt(a[k]+\"\") ;\n        }\n        return sum ;\n    }\n    \n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n\tclass IO {\n\t\tBufferedReader reader;\n\t\tPrintWriter writer;\n\t\tStringTokenizer tokenizer;\n\n\t\tIO() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\twriter = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tIO(String file) throws FileNotFoundException {\n\t\t\treader = new BufferedReader(new FileReader(file));\n\t\t\twriter = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\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\ttokenizer = new StringTokenizer(line);\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic Integer 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\t\tpublic void write(Object obj) {\n\t\t\twriter.print(obj.toString());\n\t\t}\n\n\t\tpublic void writeSpace(Object obj) {\n\t\t\twriter.print(obj.toString() + \" \");\n\t\t}\n\n\t\tpublic void writeLine(Object obj) {\n\t\t\twriter.println(obj.toString());\n\t\t}\n\n\t\tpublic void close() {\n\t\t\twriter.close();\n\t\t}\n\t}\n\n\tIO io;\n\n\tMain() {\n\t\tio = new IO();\n\t}\n\n\tMain(String file) throws FileNotFoundException {\n\t\tio = new IO(file);\n\t}\n\n\tvoid solve() throws IOException {\n\t\tlong n = io.nextLong(), s = io.nextLong();\n\t\tlong min = s;\n\t\twhile (true) {\n\t\t\tmin++;\n\t\t\tlong sum = 0, tem = min;\n\t\t\twhile (tem > 0) {\n\t\t\t\tsum += tem % 10;\n\t\t\t\ttem /= 10;\n\t\t\t}\n\t\t\tif (min - sum >= s) break;\n\t\t}\n\t\tio.write(Math.max(0, n - min + 1));\n\t}\n\n\tvoid close() {\n\t\tio.close();\n\t}\n\n\tpublic static void main(String args[]) throws IOException {\n\t\t// Main solver = new Main(\"input.txt\");\n\t\tMain solver = new Main();\n\t\tsolver.solve();\n\t\tsolver.close();\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "\t        \t\t\t/*\n\t        \t\t     * Author- Priyam Vora\n\t        \t\t     * BTech 2nd Year DAIICT\n\t        \t\t     */\n\t     \n\t     \n\t        \t\t    import java.awt.Checkbox;\n\timport java.awt.Point;\n\timport java.io.*;\n\t        \t\t    import java.math.*;\n\t        \t\t    import java.util.*;\n\timport java.util.Map.Entry;\n\t\n\timport javax.print.attribute.SetOfIntegerSyntax;\n\t\n\t     \n\t        \t\t    public class Main{\n\t        \t\t  \tprivate static InputStream stream;\n\t        \t\t    \tprivate static byte[] buf = new byte[1024];\n\t        \t\t    \tprivate static int curChar;\n\t        \t\t    \tprivate static int numChars;\n\t        \t\t    \tprivate static SpaceCharFilter filter;\n\t        \t\t    \tprivate static PrintWriter pw;\n\t        \t\t    \tprivate static long count = 0,mod=1000000007;\n\t        \t\t    //\tprivate static TreeSet<Integer> ts=new TreeSet[200000];\n\t        \t\t    \tpublic final static int INF = (int) 1E9;\n\t\n\t        \t\t        \n\t        \t\t        public static void main(String[] args) {\n\t        \t\t        \tInputReader(System.in);\n\t        \t\t    \t\tpw = new PrintWriter(System.out); \n\t        \t\t            new Thread(null ,new Runnable(){\n\t        \t\t               public void run(){\n\t        \t\t                   try{\n\t        \t\t                       solve();\n\t        \t\t                       pw.close();\n\t        \t\t                   } catch(Exception e){\n\t        \t\t                       e.printStackTrace();\n\t        \t\t                   }\n\t        \t\t               }\n\t        \t\t           },\"1\",1<<26).start();\n\t        \t\t       }\n\t        \t\t        public static void test(){\n\t        \t\t        \tint t=nextInt();\n\t        \t\t        \twhile(t-->0){\n\t        \t\t        \t\tsolve();\n\t        \t\t        \t}\n\t        \t\t        }\n\t        \t\t        public static long pow(long n, long p,long mod) {\n\t        \t\t\t\t\tif(p==0)\n\t        \t\t\t\t\t\treturn 1;\n\t        \t\t\t\t\tif(p==1)\n\t        \t\t\t\t\t\treturn n%mod;\n\t        \t\t\t\t\tif(p%2==0){\n\t        \t\t\t\t\t\tlong temp=pow(n, p/2,mod);\n\t        \t\t\t\t\treturn (temp*temp)%mod;\n\t        \t\t\t\t\t}else{\n\t        \t\t\t\t\t\t \tlong temp=pow(n,p/2,mod);\n\t        \t\t\t\t\t\t \ttemp=(temp*temp)%mod;\n\t        \t\t\t\t\t\t \treturn(temp*n)%mod;\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        public static long pow(long n, long p) {\n\t        \t\t\t\t\tif(p==0)\n\t        \t\t\t\t\t\treturn 1;\n\t        \t\t\t\t\tif(p==1)\n\t        \t\t\t\t\t\treturn n;\n\t        \t\t\t\t\tif(p%2==0){\n\t        \t\t\t\t\t\tlong temp=pow(n, p/2);\n\t        \t\t\t\t\treturn (temp*temp);\n\t        \t\t\t\t\t}else{\n\t        \t\t\t\t\t\t \tlong temp=pow(n,p/2);\n\t        \t\t\t\t\t\t \ttemp=(temp*temp);\n\t        \t\t\t\t\t\t \treturn(temp*n);\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        public static void Merge(long a[],int p,int r){\n\t        \t\t            if(p<r){\n\t        \t\t                int q = (p+r)/2;\n\t        \t\t                Merge(a,p,q);\n\t        \t\t                Merge(a,q+1,r);\n\t        \t\t                Merge_Array(a,p,q,r);\n\t        \t\t            }\n\t        \t\t        }\n\t        \t\t        public static void Merge_Array(long a[],int p,int q,int r){\n\t        \t\t           long b[] = new long[q-p+1];\n\t        \t\t            long c[] = new long[r-q];\n\t        \t\t            for(int i=0;i<b.length;i++)\n\t        \t\t                b[i] = a[p+i];\n\t        \t\t            for(int i=0;i<c.length;i++)\n\t        \t\t                c[i] = a[q+i+1];\n\t        \t\t            int i = 0,j = 0;\n\t        \t\t            for(int k=p;k<=r;k++){\n\t        \t\t                if(i==b.length){\n\t        \t\t                    a[k] = c[j];\n\t        \t\t                    j++;\n\t        \t\t                }\n\t        \t\t                else if(j==c.length){\n\t        \t\t                    a[k] = b[i];\n\t        \t\t                    i++;\n\t        \t\t                }\n\t        \t\t                else if(b[i]<c[j]){\n\t        \t\t                    a[k] = b[i];\n\t        \t\t                    i++;\n\t        \t\t                }\n\t        \t\t                else{\n\t        \t\t                    a[k] = c[j];\n\t        \t\t                    j++;\n\t        \t\t                }\n\t        \t\t            }\n\t        \t\t        }\n\t        \t\t    \tpublic static long gcd(long x, long y) {\n\t        \t\t    \t\tif (x == 0)\n\t        \t\t    \t\t\treturn y;\n\t        \t\t    \t\telse\n\t        \t\t    \t\t\treturn gcd( y % x,x);\n\t        \t\t    \t}\tpublic static boolean isPrime(int n) {\n\t        \t\t    \t// Corner cases\n\t\t\t\t    \t\tif (n <= 1)\n\t\t\t\t    \t\t\treturn false;\n\t\t\t\t    \t\tif (n <= 3)\n\t\t\t\t    \t\t\treturn true;\n\t\t\t\t     \n\t\t\t\t    \t\t// This is checked so that we can skip \n\t\t\t\t    \t\t// middle five numbers in below loop\n\t\t\t\t    \t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\t\t    \t\t\treturn false;\n\t\t\t\t     \n\t\t\t\t    \t\tfor (int i = 5; i * i <= n; i = i + 6)\n\t\t\t\t    \t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t\t    \t\t\t\treturn false;\n\t\t\t\t     \n\t\t\t\t    \t\treturn true;\n\t\t\t\t    \t}\n\t        \t\t        static LinkedList<Integer> adj[];\n\t        \t\t        static boolean Visited[];\n\t        \t\t        static HashSet<Integer> exc;\n\t        \t\t        static long oddsum[]=new long[1000001];\n\t        \t\t        static int co=0,ans=0;\n\t        \t\t       \n\t        \t\t        static int n,m;\n\t        \t\t        static String s[];\n\t        \t\t        static int ind;\n\t        \t\t        public static void solve() {\n\t        \t\t  \n\t        \t\t    \t\n\t        \t\n\t        \t\t        \tlong n=nextLong();\n\t        \t\t        \tlong s=nextLong();\n\t        \t\t        \tlong low=1,high=n,ans=-1;\n\t        \t\t        \twhile(low<=high){\n\t        \t\t        \t\tlong mid=(low+high)/2;\n\t        \t\t        \t\tif(check(mid,s)){\n\t        \t\t        \t\t\tans=mid;\n\t        \t\t        \t\t\thigh=mid-1;\n\t        \t\t        \t\t}else\n\t        \t\t        \t\t{\n\t        \t\t        \t\t\tlow=mid+1;\n\t        \t\t        \t\t}\n\t        \t\t        \t\t\t\t\n\t        \t\t        \t}\n\t        \t\t        \tif(ans==-1)\n\t        \t\t        \t\tpw.println(0);\n\t        \t\t        \telse\n\t        \t\t        \t\tpw.println(n-ans+1);\n\t        \t\n\t        \t\t        }\n\t        \t\t        private static boolean check(long mid,long s){\n\t        \t\t        \tlong n=mid;\n\t        \t\t        \tint sum=0;\n\t        \t\t        \twhile(mid>0){\n\t        \t\t        \t\tsum+=(mid%10);\n\t        \t\t        \t\tmid/=10;\n\t        \t\t        \t}\n\t        \t\t        \tif(n-sum >=s)\n\t        \t\t        \t\treturn true;\n\t        \t\t        \treturn false;\n\t        \t\t        \t\t\t\t\n\t        \t\t        }\n\t        \t\t        \n\t        \t\t        static int[] levl;\n\t        \t\t        static int h_max=0;\n\t        \t\t     public static void dfs(int curr,int lev){\n\t        \t\t    \t Visited[curr]=true;\n\t        \t\t    \t levl[curr]=lev;\n\t        \t\t    \t h_max=Math.max(h_max, levl[curr]);\n\t        \t\t    \t for(int x:adj[curr]){\n\t        \t\t    \t\t if(!Visited[x]){\n\t        \t\t    \t\t\t dfs(x,lev+1);\n\t        \t\t    \t\t }\n\t        \t\t    \t }\n\t        \t\t     }\n\t        \t\t       \n\t        \t\t        public static String reverseString(String s) {\n\t        \t\t\t\t\tStringBuilder sb = new StringBuilder(s);\n\t        \t\t\t\t\tsb.reverse();\n\t        \t\t\t\t\treturn (sb.toString());\n\t        \t\t\t\t}\n\t        \t\t        \n\t        \t\t        \n\t        \t\t        private static void BFS(int sou,int dest){\n\t        \t\t        \tQueue<Integer> q=new LinkedList<Integer>();\n\t        \t\t        \tq.add(sou);\n\t        \t\t        \tVisited[sou]=true;\n\t        \t\t        \twhile(!q.isEmpty()){\n\t        \t\t        \t\tint top=q.poll();\n\t        \t\t        \t\t\n\t        \t\t        \t\tfor(int i:adj[top]){\n\t        \t\t        \t\t\t//pw.println(i+\" \"+top);\n\t        \t\t        \t\t\tif(!Visited[i])\n\t        \t\t        \t\t\t{\n\t        \t\t        \t\t\t\t\n\t        \t\t        \t\t\t\tq.add(i);\n\t        \t\t        \t\t\t}\n\t        \t\t        \t\t\t\n\t        \t\t        \t\t\tVisited[i]=true;\n\t        \t\t        \t\t\tif(i==dest){\n\t        \t\t        \t\t\t\tpw.println(\"Yes\");\n\t        \t\t        \t\t\treturn;\t\n\t        \t\t        \t\t\t}\n\t        \t\t        \t\t}\n\t        \t\t        \t}\n\t        \t\t        \tpw.println(\"No\");\n\t        \t\t        \t\n\t        \t\t        \t\n\t        \t\t        }\n\t        \t\t        \n\t        \t\t        private static long ncr(int n,int k){\n\t    \t\t\t\t    \tif (k < 0 || k > n) return 0;\n\t    \t\t\t\t        if (n-k < k) k = n-k;\n\t    \t\t\t\n\t    \t\t\t\t        BigInteger x = BigInteger.ONE;\n\t    \t\t\t\t        for (int i = 1; i <= k; i++) {\n\t    \t\t\t\t            x = x.multiply(new BigInteger(\"\"+(n-i+1)));\n\t    \t\t\t\t            x = x.divide(new BigInteger(\"\"+i));\n\t    \t\t\t\t        }\n\t    \t\t\t\n\t    \t\t\t\treturn x.longValue();\n\t    \t\t\t\t    }\n\t        \t\t       private  static long fact(long count){\n\t        \t\t        \tlong ans=1;\n\t        \t\t        \tfor(int i=1;i<=count;i++){\n\t        \t\t        \t\tans*=i;\n\t        \t\t        \t}\n\t        \t\t        \treturn ans;\n\t        \t\t        }\n\t        \t\t        \n\t        \t\t        \n\t        \t\t        static int state=1;\n\t        \t\t        static long no_exc=0,no_vert=0;\n\t        \t\t      static Stack<Integer> st;\n\t        \t\t      static HashSet<Integer> inset;\n\t        \t\t        private static void topo(int curr){\n\t        \t\t        \t\n\t        \t\t        \tVisited[curr]=true;\n\t        \t\t        \tinset.add(curr);\n\t        \t\t        \tfor(int x:adj[curr]){\n\t        \t\t        \t\tif(adj[x].contains(curr) || inset.contains(x)){\n\t        \t\t        \t\t\tstate=0;\n\t        \t\t        \t\t\treturn;\n\t        \t\t        \t\t}\n\t        \t\t        \t\tif(state==0)\n\t        \t\t        \t\t\treturn;\n\t        \t\t        \t\t\n\t        \t\t        \t}\n\t        \t\t        \tst.push(curr);\n\t        \t\t        \t\n\t        \t\t        \tinset.remove(curr);\n\t        \t\t        }\n\t        \t\t        static HashSet<Integer> hs;\n\t        \t\t       \n\t        \t\t     \tprivate static void buildgraph(int n){\n\t        \t\t    \t\tadj=new LinkedList[n+1];\n\t        \t\t    \t\tVisited=new boolean[n+1];\n\t        \t\t    \t\t\n\t        \t\t    \t\tfor(int i=0;i<=n;i++){\n\t        \t\t    \t\t\tadj[i]=new LinkedList<Integer>();\n\t        \t\t    \t\t\n\t        \t\t    \t\t}\n\t     \n\t     \n\t        \t\t    \t}\n\t        \t\t     \t\n\t        \t\t    \t// To Get Input\n\t        \t\t    \t// Some Buffer Methods\n\t     \n\t        \t\t     \tpublic static void sort(long a[]){\n\t        \t\t     \t\tMerge(a, 0, a.length-1);\n\t        \t\t     \t}\n\t        \t\t    \tpublic static void InputReader(InputStream stream1) {\n\t        \t\t    \t\tstream = stream1;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static boolean isWhitespace(int c) {\n\t        \t\t    \t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static boolean isEndOfLine(int c) {\n\t        \t\t    \t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static int read() {\n\t        \t\t    \t\tif (numChars == -1)\n\t        \t\t    \t\t\tthrow new InputMismatchException();\n\t        \t\t    \t\tif (curChar >= numChars) {\n\t        \t\t    \t\t\tcurChar = 0;\n\t        \t\t    \t\t\ttry {\n\t        \t\t    \t\t\t\tnumChars = stream.read(buf);\n\t        \t\t    \t\t\t} catch (IOException e) {\n\t        \t\t    \t\t\t\tthrow new InputMismatchException();\n\t        \t\t    \t\t\t}\n\t        \t\t    \t\t\tif (numChars <= 0)\n\t        \t\t    \t\t\t\treturn -1;\n\t        \t\t    \t\t}\n\t        \t\t    \t\treturn buf[curChar++];\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static int nextInt() {\n\t        \t\t    \t\tint c = read();\n\t        \t\t    \t\twhile (isSpaceChar(c))\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\tint sgn = 1;\n\t        \t\t    \t\tif (c == '-') {\n\t        \t\t    \t\t\tsgn = -1;\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\t}\n\t        \t\t    \t\tint res = 0;\n\t        \t\t    \t\tdo {\n\t        \t\t    \t\t\tif (c < '0' || c > '9')\n\t        \t\t    \t\t\t\tthrow new InputMismatchException();\n\t        \t\t    \t\t\tres *= 10;\n\t        \t\t    \t\t\tres += c - '0';\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\t} while (!isSpaceChar(c));\n\t        \t\t    \t\treturn res * sgn;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static long nextLong() {\n\t        \t\t    \t\tint c = read();\n\t        \t\t    \t\twhile (isSpaceChar(c))\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\tint sgn = 1;\n\t        \t\t    \t\tif (c == '-') {\n\t        \t\t    \t\t\tsgn = -1;\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\t}\n\t        \t\t    \t\tlong res = 0;\n\t        \t\t    \t\tdo {\n\t        \t\t    \t\t\tif (c < '0' || c > '9')\n\t        \t\t    \t\t\t\tthrow new InputMismatchException();\n\t        \t\t    \t\t\tres *= 10;\n\t        \t\t    \t\t\tres += c - '0';\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\t} while (!isSpaceChar(c));\n\t        \t\t    \t\treturn res * sgn;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static String nextToken() {\n\t        \t\t    \t\tint c = read();\n\t        \t\t    \t\twhile (isSpaceChar(c))\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\tStringBuilder res = new StringBuilder();\n\t        \t\t    \t\tdo {\n\t        \t\t    \t\t\tres.appendCodePoint(c);\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\t} while (!isSpaceChar(c));\n\t        \t\t    \t\treturn res.toString();\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static String nextLine() {\n\t        \t\t    \t\tint c = read();\n\t        \t\t    \t\twhile (isSpaceChar(c))\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\tStringBuilder res = new StringBuilder();\n\t        \t\t    \t\tdo {\n\t        \t\t    \t\t\tres.appendCodePoint(c);\n\t        \t\t    \t\t\tc = read();\n\t        \t\t    \t\t} while (!isEndOfLine(c));\n\t        \t\t    \t\treturn res.toString();\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static int[] nextIntArray(int n) {\n\t        \t\t    \t\tint[] arr = new int[n];\n\t        \t\t    \t\tfor (int i = 0; i < n; i++) {\n\t        \t\t    \t\t\tarr[i] = nextInt();\n\t        \t\t    \t\t}\n\t        \t\t    \t\treturn arr;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static long[][] next2dArray(int n, int m) {\n\t        \t\t    \t\tlong[][] arr = new long[n][m];\n\t        \t\t    \t\tfor (int i = 0; i < n; i++) {\n\t        \t\t    \t\t\tfor (int j = 0; j < m; j++) {\n\t        \t\t    \t\t\t\tarr[i][j] = nextLong();\n\t        \t\t    \t\t\t}\n\t        \t\t    \t\t}\n\t        \t\t    \t\treturn arr;\n\t        \t\t    \t}\n\t        \t\t    \tprivate static char[][] nextCharArray(int n,int m){\n\t        \t\t    \t\tchar [][]c=new char[n][m];\n\t        \t\t    \t\tfor(int i=0;i<n;i++){\n\t        \t\t    \t\t\tString s=nextLine();\n\t        \t\t    \t\t\tfor(int j=0;j<s.length();j++){\n\t        \t\t    \t\t\t\tc[i][j]=s.charAt(j);\n\t        \t\t    \t\t\t}\n\t        \t\t    \t\t}\n\t        \t\t    \t\treturn c;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static long[] nextLongArray(int n) {\n\t        \t\t    \t\tlong[] arr = new long[n];\n\t        \t\t    \t\tfor (int i = 0; i < n; i++) {\n\t        \t\t    \t\t\tarr[i] = nextLong();\n\t        \t\t    \t\t}\n\t        \t\t    \t\treturn arr;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static void pArray(int[] arr) {\n\t        \t\t    \t\tfor (int i = 0; i < arr.length; i++) {\n\t        \t\t    \t\t\tpw.print(arr[i] + \" \");\n\t        \t\t    \t\t}\n\t        \t\t    \t\tpw.println();\n\t        \t\t    \t\treturn;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static void pArray(long[] arr) {\n\t        \t\t    \t\tfor (int i = 0; i < arr.length; i++) {\n\t        \t\t    \t\t\tpw.print(arr[i] + \" \");\n\t        \t\t    \t\t}\n\t        \t\t    \t\tpw.println();\n\t        \t\t    \t\treturn;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static void pArray(boolean[] arr) {\n\t        \t\t    \t\tfor (int i = 0; i < arr.length; i++) {\n\t        \t\t    \t\t\tpw.print(arr[i] + \" \");\n\t        \t\t    \t\t}\n\t        \t\t    \t\tpw.println();\n\t        \t\t    \t\treturn;\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate static boolean isSpaceChar(int c) {\n\t        \t\t    \t\tif (filter != null)\n\t        \t\t    \t\t\treturn filter.isSpaceChar(c);\n\t        \t\t    \t\treturn isWhitespace(c);\n\t        \t\t    \t}\n\t     \n\t        \t\t    \tprivate interface SpaceCharFilter {\n\t        \t\t    \t\tpublic boolean isSpaceChar(int ch);\n\t        \t\t    \t}\n\t     \n\t     \n\t    }\n\t        \t\t    \n\t        \t\t           \t\t    class Node{\n\t        \t\t    \tint to;\n\t        \t\t    \tlong dist;\n\t        \t\t    \tNode(int to,long dist){\n\t        \t\t    \t\tthis.to=to;\n\t        \t\t    \t\tthis.dist=dist;\n\t        \t\t    \t}\n\t        \t\t    \t\n\t        \t\t    }\n\t        \t\t   /* class Pair implements Comparable<Pair>{\n\t        \t\t\t\t\n\t    \t\t\t\t\t\n\t    \t\t\t\t\tint ele,ind;\n\t    \t\t\t\t\tPair(int ele,int ind){\n\t    \t\t\t\t\t\n\t    \t\t\t\t\t\tthis.ele=ele;\n\t    \t\t\t\t\t\tthis.ind=ind;\n\t    \t\t\t\t\t\n\t    \t\t\t\t\t}\n\t    \t\t\t\t\t@Override\n\t    \t\t\t\t\tpublic int compareTo(Pair o) {\n\t    \t\t\t\t\n\t    \t\t\t\t\t\t\t\n\t    \t\t\t\t\t\t\treturn ele-o.ele;\n\t    \t\t\t\t\t}\n\t    \t\t\t\t\tpublic int hashCode() {\n\t    \t\t\t\t\t\t\t//int hu = (int) (x ^ (x >>> 32));\n\t    \t\t\t\t\t\t\t//int hv = (int) (y ^ (y >>> 32));\n\t    \t\t\t\t\t\t\t//int hw = (int) (mass ^ (mass >>> 32));\n\t    \t\t\t\t\t\t\t//return 31 * hu + hv ;\n\t    \t\t\t\t\t\treturn 0;\n\t    \t\t\t\t\t\t}\n\t    \t\t\t\t\t\tpublic boolean equals(Object o) {\n\t    \t\t\t\t\t\t\tPair other = (Pair) o;\n\t    \t\t\t\t\t\t//\treturn x == other.x && y == other.y;\n\t    \t\t\t\t\t\treturn false;\n\t    \t\t\t\t\t\t}\n\t    \t\t\t\t}  */class Dsu{\n\t\t    \t\t    \tprivate int rank[], parent[] ,n;\n\t\t    \t\t    \tprivate static int[] parent1;\n\t\t    \t\t    \tDsu(int size){\n\t\t    \t\t    \t\tthis.n=size+1;\n\t\t    \t\t    \t\trank=new int[n];\n\t\t    \t\t    \t\t//parent=new int[n];\n\t\t    \t\t    \t\tparent=new int[n];\n\t\t    \t\t    \tmakeSet();\n\t\t    \t\t\n\t\t    \t\t    \t}\n\t\t    \t\t    \t\n\t\t    \t\t    \tvoid makeSet(){\n\t\t    \t\t    \t\tfor(int i=0;i<n;i++){\n\t\t    \t\t    \t\t\tparent[i]=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    \tint find(int x){\n\t\t    \t\t    \t\tif(parent[x]!=x){\n\t\t    \t\t    \t\t\t\n\t\t    \t\t    \t\t\tparent[x]=find(parent[x]);\n\t\t    \t\t    \t\t}\n\t\t    \t\t    \t\treturn parent[x];\n\t\t    \t\t    \t}\n\t\t    \t\t    \n\t\t    \t\t    \t\n\t\t    \t\t    \tboolean union(int x,int y){\n\t\t    \t\t    \t\tint xRoot=find(x);\n\t\t    \t\t    \t\tint yRoot=find(y);\n\t\t    \t\t    \t\t\n\t\t    \t\t    \t\tif(xRoot==yRoot)\n\t\t    \t\t    \t\t\treturn false;\n\t\t    \t\t    \t\tif(rank[xRoot]<rank[yRoot]){\n\t\t    \t\t    \t\tparent[xRoot]=yRoot;\t\n\t\t    \t\t    \t\t}else if(rank[yRoot]<rank[xRoot]){\n\t\t    \t\t    \t\t\tparent[yRoot]=xRoot;\n\t\t    \t\t    \t\t}else{\n\t\t    \t\t    \t\t\tparent[yRoot]=xRoot;\n\t\t    \t\t    \t\t\trank[xRoot]++;\n\t\t    \t\t    \t\t}\n\t\t    \t\t    \t\treturn true;\n\t\t    \t\t    \t}\n\t\n\t\t    \t\t     \n\t\t    \t\t    }", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\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\t\n\tpublic static void main(String[] args) {\n\n\t\tlong n = in.nextLong();\n\t\tlong s = in.nextLong();\n\t\t\n\t\tif(diff(n) < s) {\n\t\t\tSystem.out.println(0);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong lo = 1;\n\t\tlong hi = n;\n\t\twhile(lo < hi) {\n\t\t\tlong mid = lo + (hi - lo) / 2;\n\t\t\tif(diff(mid) >= s)\n\t\t\t\thi = mid;\n\t\t\telse\n\t\t\t\tlo = mid + 1;\n\t\t}\n\t\tSystem.out.println(n - lo + 1);\n\t\t\n\t\tout.close();\n\t}\n\n\tstatic long diff(long n) {\n\t\tchar[] ca = (n + \"\").toCharArray();\n\t\tint sum = 0;\n\t\tfor(char c : ca)\n\t\t\tsum += (c - '0');\n\t\treturn n - sum;\n\t}\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}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class c {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tlong s = scan.nextLong();\n\t\tscan.close();\n\t\tlong start = s - s % 10;\n\t\twhile (start <= n && !isBig(start, s)) {\n\t\t\tstart += 10;\n\t\t}\n\t\tif (start > n) {\n\t\t\tSystem.out.println(0);\n\t\t} else {\n\t\t\tSystem.out.println(n - start + 1);\n\t\t}\n\t}\n\n\tprivate static boolean isBig(long a, long s) {\n\t\tchar[] digits = (\"\" + a).toCharArray();\n\t\tint counter = 0;\n\t\tfor (int i = 0; i < digits.length; i++) {\n\t\t\tcounter += digits[i] - '0';\n\t\t}\n\t\treturn a - counter >= s;\n\t}\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\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 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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long n = in.nextLong();\n            long s = in.nextLong();\n\n            if (n - digitSum(n) < s) {\n                out.println(0);\n                return;\n            }\n\n            long left = 0;\n            long right = n;\n            while (left < right) {\n                long mid = left + (right - left) / 2;\n                if (mid - digitSum(mid) >= s) { // if condition(mid) == true\n                    right = mid;\n                } else {\n                    left = mid + 1;\n                }\n            }\n            out.println(n - left + 1);\n        }\n\n        long digitSum(long a) {\n            long result = 0;\n            while (a > 0) {\n                result += a % 10;\n                a /= 10;\n            }\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 long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public String next() {\n            try {\n                while (tok == null || !tok.hasMoreTokens()) {\n                    tok = new StringTokenizer(in.readLine());\n                    //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", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\nimport java.util.*;\n\npublic class Solution {\n\n    public static void main(String[] args) {\n       Scanner scanner = new Scanner(System.in);\n\n       long n =   scanner.nextLong();\n       long s =   scanner.nextLong();\n       long myLong = s;\n       long count =0;\n      while(true){\n    \t  if(myLong>n){\n    \t\t  break;\n    \t  }\n    \t  char[] num = (\"\"+myLong).toCharArray();\n\t\tint sum = 0;\n\t\t\tfor (int j = 0; j < num.length; j++)\n\t\t\t\tsum += num[j] - '0';\n    \t\n    \t  if(myLong- sum>=s){\n    \t\t  //count++;\n    \t\t  break;\n    \t  }\n    \t  \n    \t  myLong++;\n      }\n      System.out.println(Math.max(n-myLong+1,0));\n        scanner.close();\n    }\n}", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ReallyBigNumbers {\n\tpublic static void main(String[] args) {\n\t\t@SuppressWarnings(\"resource\")\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong(); // max\n\t\tlong s = sc.nextLong(); // differential\n\t\tlong bigNums = 0;\n\t\tlong inARow = 0;\n\t\tfor (long i = s; i <= n; i++) {\n\t\t\tif (inARow == 9) {\n\t\t\t\tbigNums += (n - i+1);\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (i >= s + digitSum(i)) {\n\t\t\t\t\tbigNums++;\n\t\t\t\t\tinARow++;\n\t\t\t\t} else {\n\t\t\t\t\tinARow = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(bigNums);\n\t}\n\n\tpublic static long digitSum(long a) {\n\t\tlong sum = a % 10;\n\t\tif (9 < a) {\n\t\t\ta /= 10;\n\t\t\tsum += digitSum(a);\n\t\t}\n\t\treturn sum;\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class P817C\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tlong s = scan.nextLong();\n\t\tlong ans = 0;\n\t\tif (s > n)\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif (n > s+200)\n\t\t{\n\t\t\tans += n-(s+200);\n\t\t\tn = s+200;\n\t\t}\n\t\tfor (long i = s; i <= n; i++)\n\t\t{\n\t\t\tchar[] num = (\"\"+i).toCharArray();\n\t\t\tint sum = 0;\n\t\t\tfor (int j = 0; j < num.length; j++)\n\t\t\t\tsum += num[j] - '0';\n\t\t\tif (i - sum >= s)\n\t\t\t\tans++;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Scanner;\n\npublic class C {\n\n  private static final String REGEX = \" \";\n  private static final Boolean DEBUG = false;\n  private static final String FILE_NAME = \"input.txt\";\n\n\n  public static void main(String[] args) throws IOException {\n    if (DEBUG) {\n      generate();\n    }\n    Solver solver = new Solver();\n    solver.readData();\n    solver.solveAndPrint();\n  }\n\n  private static void generate() throws IOException {\n//    FileWriter writer = new FileWriter(\"input.txt\");\n//    writer.close();\n  }\n\n  private static class Solver {\n\n    long n, s;\n\n    void readData() throws IOException {\n      InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;\n      Scanner scanner = new Scanner(in);\n      n = scanner.nextLong();\n      s = scanner.nextLong();\n      scanner.close();\n    }\n\n    void solveAndPrint() {\n      long cur = s + 1;\n      long sum = getSum(cur);\n      long res = 0;\n      while (cur <= n) {\n        if (cur - sum >= s) {\n          System.out.println(n - cur + 1);\n          return;\n        }\n        cur++;\n        if (cur % 10 != 0) {\n          sum++;\n        } else {\n          sum = getSum(cur);\n        }\n      }\n      System.out.println(0);\n    }\n\n    long getSum(long cur) {\n      long res = 0;\n      while (cur > 0) {\n        res += cur % 10;\n        cur /= 10;\n      }\n      return res;\n    }\n\n\n    @SuppressWarnings(\"SameParameterValue\")\n    int[] splitInteger(String string, int n) {\n      final String[] split = string.split(REGEX, n);\n      int[] result = new int[split.length];\n      for (int i = 0; i < n; ++i) {\n        result[i] = Integer.parseInt(split[i]);\n      }\n      return result;\n    }\n\n    public int[] splitInteger(String string) {\n      return splitInteger(string, 0);\n    }\n\n\n    @SuppressWarnings(\"SameParameterValue\")\n    long[] splitLong(String string, int n) {\n      final String[] split = string.split(REGEX, n);\n      long[] result = new long[split.length];\n      for (int i = 0; i < n; ++i) {\n        result[i] = Long.parseLong(split[i]);\n      }\n      return result;\n    }\n\n    public long[] splitLong(String string) {\n      return splitLong(string, 0);\n    }\n\n    @SuppressWarnings(\"SameParameterValue\")\n    double[] splitDouble(String string, int n) {\n      final String[] split = string.split(REGEX, n);\n      double[] result = new double[split.length];\n      for (int i = 0; i < n; ++i) {\n        result[i] = Double.parseDouble(split[i]);\n      }\n      return result;\n    }\n\n    public double[] splitDouble(String string) {\n      return splitDouble(string, 0);\n    }\n\n    @SuppressWarnings(\"SameParameterValue\")\n    String[] splitString(String string, int n) {\n      return string.split(REGEX, n);\n    }\n\n    public String[] splitString(String string) {\n      return splitString(string, 0);\n    }\n\n    public int max(int a, int b) {\n      return Math.max(a, b);\n    }\n\n    public long max(long a, long b) {\n      return Math.max(a, b);\n    }\n\n    public int min(int a, int b) {\n      return Math.min(a, b);\n    }\n\n    public long min(long a, long b) {\n      return Math.min(a, b);\n    }\n\n    public double max(double a, double b) {\n      return Math.max(a, b);\n    }\n\n    public double min(double a, double b) {\n      return Math.min(a, b);\n    }\n\n    private final static int MOD = 1000000009;\n\n    int multMod(int a, int b) {\n      return ((a % MOD) * (b % MOD)) % MOD;\n    }\n\n    int sumMod(int a, int b) {\n      return ((a % MOD) + (b % MOD)) % MOD;\n    }\n\n    long multMod(long a, long b) {\n      return ((a % MOD) * (b % MOD)) % MOD;\n    }\n\n    long sumMod(long a, long b) {\n      return ((a % MOD) + (b % MOD)) % MOD;\n    }\n  }\n\n\n}\n", "complexity": "logn", "problem": "817_C. Really Big Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n    \n    final static long Mod = 1000000009;\n    static long n, m, k, t, l, u, ans;\n    static Scanner cin = new Scanner(System.in); \n    \n    static long multi_mod(long base, long cur) {\n        long res = 1;\n        while(cur > 0) {\n            if(cur % 2 == 1) res = (res * base) % Mod;\n            cur >>= 1;\n            base = (base * base) % Mod;\n        }\n        return res;\n    }\n    \n    public static void main(String[] args) {\n        n = cin.nextLong(); m = cin.nextLong(); k = cin.nextLong();\n        l = (k - 1)*(n / k) + n % k;\n        if(m <= l) {\n            System.out.println(m);\n        }\n        else {\n            t = n / k;\n            u = m - l;\n            ans = (0 + (t - u) * (k - 1) + n % k) % Mod;\n            ans = (ans + ((k)*((multi_mod(2, u + 1) - 2 + Mod) % Mod)) % Mod) % Mod;\n            System.out.println(ans);\n        }\n    }\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class C {\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong s=0,mod=1000000009;\n\t\tint n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt(),c=n/k;\n\t\tif(m<=c*(k-1)+(n%k))System.out.println(m);\n\t\telse {\n\t\t\tint a=m-c*(k-1)-(n%k);\n\t\t\tlong l=0,pase=0;\n\t\t\t//System.out.println(a);\n\t\t\tlong pot=BigInteger.valueOf(2).modPow(BigInteger.valueOf(a), BigInteger.valueOf(mod)).longValue();\n\t\t\tpot=(2*(pot-1))%mod;\n\t\t\t/*System.out.println(pot);\n\t\t\tSystem.out.println(k);*/\n\t\t\tSystem.out.println(((pot*k)%mod+(m-a*k))%mod);\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Main {\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\tnew TaskC().solve(in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\t\n\tstatic final long mod=1000000009;\n\t\n\tpublic void solve(InputReader in,PrintWriter out) {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tint k=in.nextInt();\n\t\t\n\t\tint l=0,r=m/k;\n\t\twhile(l<r) {\n\t\t\tint mid=(l+r)>>>1;\n\t\t\tif(good(n,m,k,mid)){\n\t\t\t\tr=mid;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tl=mid+1;\n\t\t\t}\n\t\t}\n\t\tMat u=new Mat();\n\t\tu.set(k,1,0,0);\n\t\tMat v=new Mat();\n\t\tv.set(2,0,k,1);\n\t\tu=u.mul(v.powMat(l));\n\t\tout.println((u.e[0][0]-k+(m-l*k)+mod)%mod);\n\t}\n\n\tprivate boolean good(int n, int m, int k, int mid) {\n\t\tn-=mid*k;\n\t\tm-=mid*k;\n\t\tint ans=n/k*(k-1)+n%k;\n\t\tif(ans>=m)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\t\n\tprivate static class Mat {\n\t\tlong[][] e=new long[2][2];\n\t\t\n\t\tMat mul(Mat u) {\n\t\t\tMat s=new Mat();\n\t\t\ts.set(0,0,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\tfor(int k=0;k<2;k++){\n\t\t\t\t\t\ts.e[i][j]=(s.e[i][j]+e[i][k]*u.e[k][j])%mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn s;\n\t\t}\n\t\t\n\t\tMat powMat(int k) {\n\t\t\tMat u=this;\n\t\t\tMat s=new Mat();\n\t\t\ts.set(1,0,0,1);\n\t\t\twhile(k!=0) {\n\t\t\t\tif(k%2==1) {\n\t\t\t\t\ts=s.mul(u);\n\t\t\t\t}\n\t\t\t\tu=u.mul(u);\n\t\t\t\tk/=2;\n\t\t\t}\n\t\t\treturn s;\n\t\t}\n\n\t\tvoid set(long i, long j, long k, long l) {\n\t\t\te[0][0]=i;\n\t\t\te[0][1]=j;\n\t\t\te[1][0]=k;\n\t\t\te[1][1]=l;\n\t\t}\n\t}\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}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class CFFF {\n\tstatic PrintWriter out;\n\tstatic final int oo = 987654321;\n\tstatic final long mod = (long)(1e9)+9;\n\tpublic static void main(String[] args) {\n\t\tMScanner sc = new MScanner();\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong N = sc.nextLong();\n\t\tlong M = sc.nextLong();\n\t\tlong K = sc.nextLong();\n\t\t\n\t\tif(M<=N-N/K)\n\t\t\tout.println(M);\n\t\telse{\n\t\t\tlong ans = (fastModExpo(2,M-(N-N%K)/K*(K-1)-N%K+1,mod)-2)*K+M-(M-(N-N%K)/K*(K-1)-N%K)*K;\n\t\t\tout.println((mod+ans)%mod);\n\t\t}\t\t\n\t\tout.close();\n\t}\n\tstatic long fastModExpo(int base, long pow, long mod) {\n\t\tif (pow == 0) \n\t\t\treturn 1L;\n\t\tif ((pow & 1) == 1)\n\t\t\treturn (base*fastModExpo(base, pow - 1,mod))%mod;\n\t\tlong temp = fastModExpo(base, pow / 2, mod);\n\t\treturn (temp*temp)%mod;\n\t}\n\n\tstatic class MScanner {\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 MScanner() {\n\t\t\tstream = System.in;\n\t\t\t// stream = new FileInputStream(new File(\"dec.in\"));\n\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\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tint[] nextInt(int N) {\n\t\t\tint[] ret = new int[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextInt();\n\t\t\treturn ret;\n\t\t}\n\n\t\tint[][] nextInt(int N, int M) {\n\t\t\tint[][] ret = new int[N][M];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextInt(M);\n\t\t\treturn ret;\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tlong[] nextLong(int N) {\n\t\t\tlong[] ret = new long[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextLong();\n\t\t\treturn ret;\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tdouble[] nextDouble(int N) {\n\t\t\tdouble[] ret = new double[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextDouble();\n\t\t\treturn ret;\n\t\t}\n\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\n\t\tString[] next(int N) {\n\t\t\tString[] ret = new String[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = next();\n\t\t\treturn ret;\n\t\t}\n\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\n\t\tString[] nextLine(int N) {\n\t\t\tString[] ret = new String[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextLine();\n\t\t\treturn ret;\n\t\t}\n\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Scanner;\n\n/**\n * @author pvasilyev\n * @since 8/16/13\n */\npublic class ProblemC {\n\n    public static final String FILE_IN = \"std.in\";\n    public static final String FILE_OUT = \"std.out\";\n    private static boolean debugMode = true;\n    private static final long MOD = 1000 * 1000 * 1000 + 9;\n\n    public static void main(String[] args) throws IOException {\n\n        final Scanner reader = new Scanner(new InputStreamReader(debugMode ? System.in : new FileInputStream(FILE_IN)));\n        final PrintWriter writer = new PrintWriter(debugMode ? System.out : new FileOutputStream(FILE_OUT));\n\n//        final long start = System.currentTimeMillis();\n        solveTheProblem(reader, writer);\n//        System.out.println(System.currentTimeMillis() - start);\n\n        reader.close();\n        writer.close();\n    }\n\n    private static void solveTheProblem(final Scanner reader, final PrintWriter writer) {\n\n        final long n = reader.nextLong();\n        final long m = reader.nextLong();\n        final long k = reader.nextLong();\n\n        if (n - n/k >= m) {\n            writer.println(m);\n            return;\n        } else {\n            long sum = 1;\n            long maxK = m - n + n/k;\n            sum = fastPow(2, maxK);\n            sum = 2 * (sum - 1);\n            sum = sum % MOD;\n            sum *= k;\n            sum += m - maxK * k;\n            writer.println(sum % MOD);\n        }\n\n    }\n\n    private static long fastPow(final int exp, final long deg) {\n        if (deg == 0) {\n            return 1;\n        } else if (deg == 1) {\n            return exp;\n        } else if (deg % 2 == 0) {\n            long temp = fastPow(exp, deg / 2);\n            temp = (temp * temp) % MOD;\n            return temp;\n        } else {\n            long temp = fastPow(exp, deg / 2);\n            temp = (temp * temp) % MOD;\n            return (temp * exp) % MOD;\n        }\n    }\n\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Quiz {\n    public static int mod = 1000000009;\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        long n = Long.parseLong(st.nextToken());\n        long m = Long.parseLong(st.nextToken());\n        long k = Long.parseLong(st.nextToken());\n        long d = n-m;\n        n -= d*k;\n        if (n <= 0)\n        {\n            System.out.println(m);\n            return;\n        }\n        long sum = (n%k) + d*(k-1);\n        sum += 2*k*(pow(2,n/k)-1);\n        sum %= mod;\n        System.out.println(sum);\n    }\n    \n    public static long pow(long a, long n)\n    {\n        if (n == 0)\n            return 1;\n        long pow = pow(a,n/2);\n        pow = pow*pow % mod;\n        if (n % 2 == 1)\n            pow = pow*a % mod;\n        return pow;\n    }\n}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.util.Arrays.*;\n\npublic class A {\n    private static final int mod = (int)1e9+9;\n\n    final IOFast io = new IOFast();\n    \n    long k;\n    \n    boolean ok(long n, long m, long x) {\n        long u = k * x;\n        long val = u;\n        val += (m - u) / (k - 1) * k;\n        \n        if((m - u) % (k - 1) == 0) val -= 1;\n        else val += (m - u) % (k - 1);\n        \n        return val <= n;\n    }\n    \n    long rec(long n, long m, long cur) {\n        long pow = 1;\n        long p = 1000;\n        for(int i = 0; i < p; i++) pow = pow * 2 % mod;\n        while(true) {\n            if(ok(n, m, 0)) { return (m + cur) % mod; }\n            if(!ok(n - p * k, m - p * k, p)) {\n                n -= p * k;\n                m -= p * k;\n                cur = cur * pow % mod;\n                cur += (pow - 1) * 2 * k % mod;\n                cur %= mod;\n                continue;\n            }\n            n -= k;\n            m -= k;\n            cur += k;\n            cur = cur * 2 % mod;\n//          System.err.println(cur);\n        }\n    }\n    \n    public void run() throws IOException {\n        long n = io.nextLong();\n        long m = io.nextLong();\n        k = io.nextLong();\n        io.out.println(rec(n, m, 0));\n        if(true) return;\n        \n        long low = -1, high = m / k + 1;\n        while(high - low > 1) {\n            long mid = (low + high) / 2;\n            \n            if(!ok(n, m, mid)) {\n                low = mid;\n            }\n            else {\n                high = mid;\n            }\n//          System.err.println(mid + \" \" + (u + (m - u - k) / (k - 1) * k + k - 1 + (m - u) % (k - 1)) + \" \" + n);\n        }\n\n        long pow = powmod(2, high, mod);\n        long score = m - high * k;\n        score = (score + (pow - 1) * 2 * k) % mod;\n        io.out.println(score);\n    }\n\n    \n    static long powmod(long n, long r, int m) {\n        long res = 1;\n        for(; r != 0; r >>>= 1, n = n * n % m) {\n            if((r&1) == 1) {\n                res = res * n;\n                if(res >= m) {\n                    res %= m;\n                }\n            }\n        }\n        return res;\n    }\n\n    void main() throws IOException {\n        //      IOFast.setFileIO(\"rle-size.in\", \"rle-size.out\");\n        try {\n            run();\n        }\n        catch (EndOfFileRuntimeException e) { }\n        io.out.flush();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new A().main();\n    }\n    \n    static class EndOfFileRuntimeException extends RuntimeException {\n        private static final long serialVersionUID = -8565341110209207657L; }\n\n    static\n    public class IOFast {\n        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        private PrintWriter out = new PrintWriter(System.out);\n\n        void setFileIO(String ins, String outs) throws IOException {\n            in = new BufferedReader(new FileReader(ins));\n            out = new PrintWriter(new FileWriter(outs));\n        }\n\n        //      private static final int BUFFER_SIZE = 50 * 200000;\n        private static int pos, readLen;\n        private static final char[] buffer = new char[1024 * 8];\n        private static final char[] str = new char[500000*8*2];\n        private static boolean[] isDigit = new boolean[256];\n        private static boolean[] isSpace = new boolean[256];\n        private static boolean[] isLineSep = new boolean[256];\n\n        static {\n            for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }\n            isDigit['-'] = true;\n            isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n            isLineSep['\\r'] = isLineSep['\\n'] = true;\n        }\n\n        public int read() throws IOException {\n            if(pos >= readLen) {\n                pos = 0;\n                readLen = in.read(buffer);\n                if(readLen <= 0) { throw new EndOfFileRuntimeException(); }\n            }\n            return buffer[pos++];\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(nextString());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(nextString());\n        }\n\n        public char nextChar() throws IOException {\n            while(true) {\n                final int c = read();\n                if(!isSpace[c]) { return (char)c; }\n            }\n        }\n        \n        int reads(char[] cs, int len, boolean[] accept) throws IOException {\n            try {\n                while(true) {\n                    final int c = read();\n                    if(accept[c]) { break; }\n                    str[len++] = (char)c;\n                }\n            }\n            catch(EndOfFileRuntimeException e) { ; }\n            \n            return len;\n        }\n\n        public char[] nextLine() throws IOException {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(str, len, isLineSep);\n            \n            try {\n                if(str[len-1] == '\\r') { len--; read(); }\n            }\n            catch(EndOfFileRuntimeException e) { ; }\n            \n            return Arrays.copyOf(str, len);\n        }\n\n        public String nextString() throws IOException {\n            return new String(next());\n        }\n\n        public char[] next() throws IOException {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(str, len, isSpace);\n            return Arrays.copyOf(str, len);\n        }\n\n        public double nextDouble() throws IOException {\n            return Double.parseDouble(nextString());\n        }\n\n    }\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class A {\t\n\tBufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter out;\n    \n    long MOD = 1000000009;\n    public long mod_add(long n1, long n2){\n    \treturn (n1 + n2) % MOD;\n    }    \n    public long mod_time(long n1, long n2){\n    \treturn (n1 * n2) % MOD;\n    }\n    public long mod_power(long a, int k) {\n        if (k == 0) return 1;\n        if (k % 2 == 0) return mod_power(a * a % MOD, k / 2);\n        return a * mod_power(a, k - 1) % MOD;\n\t}\n    \n\tpublic void solve() throws IOException {\t\t\t\t\n\t\tint N = nextInt();\n\t\tint M = N - nextInt(); //wrong\n\t\tint K = nextInt();\n\t\t\n\t\tint full = N/K - M;\t\n\t\tif( full < 0){\n\t\t\tout.println( N - M );return;\n\t\t}\n\t\tlong ans = mod_time( K * 2, mod_power(2, full) - 1 );\n//\t\tout.println( full + \", \" + ans );\n\t\t\n\t\tans = mod_add(ans, N-M-full*K );\n\t\t\n\t\tout.println( ans );\n\t}\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\t\n\tpublic void run() {\n        try {\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        } 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}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tint n=nextInt();\n\t\tint m=nextInt();\n\t\tint k=nextInt();\n\t\tint wa=n-m;\n\t\tif(n/k<=wa){\n\t\t\tSystem.out.println(m);\n\t\t}else{\n\t\t\tint notFull=wa;\n\t\t\tint full=n/k-wa;\n\t\t\tlong res=1;\n\t\t\tint power=full+1;\n\t\t\tint mod=1000000009;\n\t\t\tlong powTwo=2;\n\t\t\twhile(power>0){\n\t\t\t\tif((power&1)==1){\n\t\t\t\t\tres=(res*powTwo)%mod;\n\t\t\t\t}\n\t\t\t\tpower>>=1;\n\t\t\t\tpowTwo=(powTwo*powTwo)%mod;\n\t\t\t}\n\t\t\tres=(((res-2+mod)%mod)*k)%mod;\n\t\t\tres=((res+notFull*(k-1))%mod+n%k)%mod;\n\t\t\tSystem.out.println(res);\n\t\t}\n\t}\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\tstatic StringTokenizer tokenizer = new StringTokenizer(\"\");\n\n\tstatic int nextInt() throws Exception {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic String next() throws Exception {\n\t\twhile (true) {\n\t\t\tif (tokenizer.hasMoreTokens()) {\n\t\t\t\treturn tokenizer.nextToken();\n\t\t\t}\n\t\t\tString s = br.readLine();\n\t\t\tif (s == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\ttokenizer = new StringTokenizer(s);\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A implements Runnable {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\tstatic Random rnd;\n\n\tfinal long MODULO = 1000000009;\n\n\tprivate void solve() throws IOException {\n\t\tint moves = nextInt(), rightMoves = nextInt(), sequence = nextInt();\n\t\tlong answer = solveSmart(moves, rightMoves, sequence);\n\t\tout.println(answer);\n\t\t// for (int moves = 2; moves <= 50; moves++) {\n\t\t// for (int rightMoves = 2; rightMoves <= moves; rightMoves++) {\n\t\t// for (int sequence = 2; sequence <= moves; sequence++) {\n\t\t// if (solveDumb(moves, rightMoves, sequence) != solveSmart(\n\t\t// moves, rightMoves, sequence)) {\n\t\t// out.println(moves + \" \" + rightMoves + \" \" + sequence);\n\t\t// out.flush();\n\t\t// }\n\t\t// }\n\t\t// }\n\t\t// }\n\t}\n\n\t// private long solveDumb(int moves, int rightMoves, int sequence) {\n\t// long[][][] d = new long[moves + 1][rightMoves + 1][sequence];\n\t// long inf = Integer.MAX_VALUE;\n\t// for (int i = 0; i <= moves; i++)\n\t// for (int j = 0; j <= rightMoves; j++)\n\t// Arrays.fill(d[i][j], inf);\n\t// d[0][0][0] = 0;\n\t//\n\t// for (int i = 0; i < moves; i++) {\n\t// for (int j = 0; j <= rightMoves; j++) {\n\t// for (int k = 0; k < sequence; k++) {\n\t// // right move\n\t// if (j < rightMoves) {\n\t// // last move\n\t// if (k + 1 == sequence) {\n\t// d[i + 1][j + 1][0] = Math.min(d[i + 1][j + 1][0],\n\t// (d[i][j][k] + 1) * 2);\n\t// } else {\n\t// d[i + 1][j + 1][k + 1] = Math.min(\n\t// d[i + 1][j + 1][k + 1], d[i][j][k] + 1);\n\t// }\n\t// }\n\t//\n\t// // bad move\n\t// d[i + 1][j][0] = Math.min(d[i + 1][j][0], d[i][j][k]);\n\t// }\n\t//\n\t// }\n\t// }\n\t//\n\t// long result = inf;\n\t// for (int i = 0; i < sequence; i++)\n\t// result = Math.min(result, d[moves][rightMoves][i]);\n\t// return result;\n\t// }\n\n\tprivate long solveSmart(long moves, long rightMoves, long sequence) {\n\t\tlong fullSequences = moves / sequence;\n\t\tlong canReset = Math.min(fullSequences, moves - rightMoves);\n\t\tlong remainSequences = fullSequences - canReset;\n\t\tlong answer = (rightMoves - remainSequences * sequence)\n\t\t\t\t+ getAnswerSequences(remainSequences, sequence);\n\t\tanswer %= MODULO;\n\t\treturn answer;\n\t}\n\n\tprivate long getAnswerSequences(long count, long length) {\n\t\tlong first = (getPow(2, count + 1) - 2) % MODULO;\n\t\tlong result = first * length;\n\t\tresult %= MODULO;\n\t\tresult += MODULO;\n\t\tresult %= MODULO;\n\t\treturn result;\n\t}\n\n\tprivate int getPow(int n, long p) {\n\t\treturn BigInteger.valueOf(2)\n\t\t\t\t.modPow(BigInteger.valueOf(p), BigInteger.valueOf(MODULO))\n\t\t\t\t.intValue();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().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}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Quiz\n{\n\tpublic static final int MOD = 1000000009;\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tlong n = in.nextInt();\n\t\tlong m = in.nextInt();\n\t\tlong k = in.nextInt();\n\t\t\n\t\tlong low = Math.min(n - (k * (n - m)), m);\n\t\t\n\t\tif(low < 0)\n\t\t{\n\t\t\tlow = 0;\n\t\t}\n\t\t\n\t\tlong result = 0;\n\t\tif(low >= k)\n\t\t{\n\t\t\tlong b = low / k;\n\t\t\t\n\t\t\tresult += fastExp(2, b + 1);\n\t\t\tresult -= 2;\n\t\t\tif(result < 0)\n\t\t\t{\n\t\t\t\tresult += MOD;\n\t\t\t}\n\t\t\t\n\t\t\tresult *= k;\n\t\t\tresult %= MOD;\n\t\t}\n\t\t\n\t\tresult += low % k;\n\t\tresult %= MOD;\n\t\t\n\t\tresult += m - low;\n\t\tresult %= MOD;\n\t\t\n//\t\tSystem.out.println(low);\n\t\t\n\t\tSystem.out.println(result);\n\t}\n\t\n\tpublic static long fastExp(int x, long pow)\n\t{\n\t\tif(pow == 0)\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t\tlong result = fastExp(x, pow / 2);\n\t\tresult *= result;\n\t\tresult %= MOD;\n\t\t\n\t\tif(pow % 2 == 1)\n\t\t{\n\t\t\tresult *= x;\n\t\t\tresult %= MOD;\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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 << 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            AQuiz solver = new AQuiz();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class AQuiz {\n        int mod = (int) 1e9 + 9;\n        Power pow = new Power(mod);\n\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.ri();\n            int m = in.ri();\n            int k = in.ri();\n            long mayPut = (long) (n - m) * (k - 1);\n            if (mayPut >= m) {\n                out.println(m);\n                return;\n            }\n\n            long ans = dup(m - mayPut, k);\n            ans += mayPut;\n            ans %= mod;\n            out.println(ans);\n        }\n\n        public long dup(long n, long k) {\n            long r = n % k;\n            n -= r;\n            long m = n / k;\n            long ans = k * (pow.pow(2, m + 1) - 2);\n            ans += r;\n            ans = DigitUtils.mod(ans, mod);\n            return ans;\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 append(long 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('\\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    static class FastInput {\n        private final InputStream is;\n        private byte[] buf = new byte[1 << 13];\n        private int bufLen;\n        private int bufOffset;\n        private int next;\n\n        public FastInput(InputStream is) {\n            this.is = is;\n        }\n\n        private int read() {\n            while (bufLen == bufOffset) {\n                bufOffset = 0;\n                try {\n                    bufLen = is.read(buf);\n                } catch (IOException e) {\n                    bufLen = -1;\n                }\n                if (bufLen == -1) {\n                    return -1;\n                }\n            }\n            return buf[bufOffset++];\n        }\n\n        public void skipBlank() {\n            while (next >= 0 && next <= 32) {\n                next = read();\n            }\n        }\n\n        public int ri() {\n            return readInt();\n        }\n\n        public int readInt() {\n            int sign = 1;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                sign = next == '+' ? 1 : -1;\n                next = read();\n            }\n\n            int val = 0;\n            if (sign == 1) {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 + next - '0';\n                    next = read();\n                }\n            } else {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 - next + '0';\n                    next = read();\n                }\n            }\n\n            return val;\n        }\n\n    }\n\n    static interface InverseNumber {\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    }\n\n    static class Power implements InverseNumber {\n        int mod;\n\n        public Power(int mod) {\n            this.mod = mod;\n        }\n\n        public int pow(int x, long n) {\n            if (n == 0) {\n                return 1 % mod;\n            }\n            long r = pow(x, n >> 1);\n            r = r * r % mod;\n            if ((n & 1) == 1) {\n                r = r * x % mod;\n            }\n            return (int) r;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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 coderbd\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 static long MOD = 1000000009L;\n\n    public long pow(long n, long p) {\n        if (p == 0)\n            return 1L;\n        if (p == 1)\n            return n;\n        long ret = 1L;\n        if (p % 2L != 0)\n            ret = n;\n        long tmp = pow(n, p / 2L);\n        ret = (ret * tmp) % MOD;\n        ret = (ret * tmp) % MOD;\n        return ret;\n    }\n\n    public long func(long n, long k) {\n        long times = n / k;\n        long ret = n - times * k;\n        ret += ((pow(2L, times + 1L) + MOD - 2L) % MOD) * k % MOD;\n        return ret;\n    }\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        long n = in.readLong();\n        long m = in.readLong();\n        long k = in.readLong();\n        long wrong = n - m;\n        long wow = n / k;\n        long ans;\n        if (wrong >= wow)\n            ans = m;\n        else\n            ans = (func(n - wrong * k, k) + (k - 1L) * wrong % MOD) % MOD;\n\n        out.printLine(ans);\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            }\n            catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            if (numChars <= 0)\n                return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public long readLong() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        long res = 0L;\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\nclass 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            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", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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    private final long MOD = 1000000009;\n\n    long power(long a, long b)\n    {\n        long res = 1;\n        while (b > 0) {\n            if ((b & 1) == 1) {\n                res *= a;\n                if (res >= MOD)\n                    res %= MOD;\n            }\n            a *= a;\n            if (a >= MOD)\n                a %= MOD;\n            b >>= 1;\n        }\n        return res;\n    }\n\n    void runCase(int caseNum) throws IOException {\n        long n = nextLong();\n        long m = nextLong();\n        long k = nextLong();\n\n        if (n - m >= n / k) {\n            System.out.println(m);\n            return;\n        }\n        long res = 0;\n        long rem = (k - 1) * (n - m);\n        m -= rem;\n        long bound = m / k;\n        res = (power(2, bound + 1) + MOD - 2) % MOD;\n        res *= k;\n        res %= MOD;\n//        for (long i = 0; i < bound; ++i) {\n//            res += k;\n//            res <<= 1;\n//            if (res >= MOD)\n//                res %= MOD;\n//        }\n        res += rem;\n        res += m % k;\n        res %= MOD;\n        System.out.println(res);\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    static int pos;\n    static String curInput = \"\";\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", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        InputReader in = new InputReader(System.in);\n        int n = in.readInt();\n        int m = in.readInt();\n        int k = in.readInt();\n        long wrong = n - m;\n        long c = wrong * (k) + k - 1;\n        long xk = n - c;\n        if (xk <= 0)\n            System.out.println((n - wrong) % 1000000009);\n        else {\n            long x = (long) Math.ceil(xk / (k * 1.0));\n            long power = Long.parseLong((BigInteger.valueOf(2).modPow(\n                    BigInteger.valueOf(x + 1), BigInteger.valueOf(1000000009))\n                    .subtract(BigInteger.valueOf(2))) + \"\");\n            power += 1000000009;\n            power %= 1000000009;\n            long first = (power * k) % 1000000009;\n            // System.out.println(first);\n            first += (n - x * k - wrong);\n            System.out.println(first % 1000000009);\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", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.util.Arrays.*;\n\npublic class A {\n    private static final int mod = (int)1e9+9;\n\n    final IOFast io = new IOFast();\n    \n    long k;\n    \n    long rec(long n, long m, long cur) {\n        long pow = 1;\n        long margin = 10;\n        long p = 1000;\n        for(int i = 0; i < p; i++) pow = pow * 2 % mod;\n        while(true) {\n            if(n + 1 >= (m / (k - 1) * k + m % (k - 1)) || m < k) { return (m + cur) % mod; }\n            long q = (p + margin) * k;\n            if(n - q + 1 < ((m - q) / (k - 1) * k + (m - q) % (k - 1)) && m >= q) {\n                n -= p * k;\n                m -= p * k;\n                cur = cur * pow % mod;\n                cur += (pow - 1) * 2 * k % mod;\n                cur %= mod;\n                continue;\n            }\n            n -= k;\n            m -= k;\n            cur += k;\n            cur = cur * 2 % mod;\n//          System.err.println(cur);\n        }\n    }\n    \n    public void run() throws IOException {\n        long n = io.nextLong();\n        long m = io.nextLong();\n        k = io.nextLong();\n//      io.out.println(rec(n, m, 0));\n//      if(true) return;\n        \n        long low = -1, high = m / k + 1;\n        while(high - low > 1) {\n            long mid = (low + high) / 2;\n            long u = mid * k;\n            if(m < u) { high = mid; continue; }\n            long val = u;\n            val += (m - u) / (k - 1) * k;\n            if((m - u) % (k - 1) == 0) val -= 1;\n            else val += (m - u) % (k - 1);\n            \n            if(val > n) {\n                low = mid;\n            }\n            else {\n                high = mid;\n            }\n//          System.err.println(mid + \" \" + (u + (m - u - k) / (k - 1) * k + k - 1 + (m - u) % (k - 1)) + \" \" + n);\n        }\n\n        long pow = powmod(2, high, mod);\n        long score = m - high * k;\n        score = (score + (pow - 1) * 2 * k) % mod;\n        io.out.println(score);\n    }\n\n    \n    static long powmod(long n, long r, int m) {\n        long res = 1;\n        for(; r != 0; r >>>= 1, n = n * n % m) {\n            if((r&1) == 1) {\n                res = res * n;\n                if(res >= m) {\n                    res %= m;\n                }\n            }\n        }\n        return res;\n    }\n\n    void main() throws IOException {\n        //      IOFast.setFileIO(\"rle-size.in\", \"rle-size.out\");\n        try {\n            run();\n        }\n        catch (EndOfFileRuntimeException e) { }\n        io.out.flush();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new A().main();\n    }\n    \n    static class EndOfFileRuntimeException extends RuntimeException {\n        private static final long serialVersionUID = -8565341110209207657L; }\n\n    static\n    public class IOFast {\n        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        private PrintWriter out = new PrintWriter(System.out);\n\n        void setFileIO(String ins, String outs) throws IOException {\n            in = new BufferedReader(new FileReader(ins));\n            out = new PrintWriter(new FileWriter(outs));\n        }\n\n        //      private static final int BUFFER_SIZE = 50 * 200000;\n        private static int pos, readLen;\n        private static final char[] buffer = new char[1024 * 8];\n        private static final char[] str = new char[500000*8*2];\n        private static boolean[] isDigit = new boolean[256];\n        private static boolean[] isSpace = new boolean[256];\n        private static boolean[] isLineSep = new boolean[256];\n\n        static {\n            for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }\n            isDigit['-'] = true;\n            isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n            isLineSep['\\r'] = isLineSep['\\n'] = true;\n        }\n\n        public int read() throws IOException {\n            if(pos >= readLen) {\n                pos = 0;\n                readLen = in.read(buffer);\n                if(readLen <= 0) { throw new EndOfFileRuntimeException(); }\n            }\n            return buffer[pos++];\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(nextString());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(nextString());\n        }\n\n        public char nextChar() throws IOException {\n            while(true) {\n                final int c = read();\n                if(!isSpace[c]) { return (char)c; }\n            }\n        }\n        \n        int reads(char[] cs, int len, boolean[] accept) throws IOException {\n            try {\n                while(true) {\n                    final int c = read();\n                    if(accept[c]) { break; }\n                    str[len++] = (char)c;\n                }\n            }\n            catch(EndOfFileRuntimeException e) { ; }\n            \n            return len;\n        }\n\n        public char[] nextLine() throws IOException {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(str, len, isLineSep);\n            \n            try {\n                if(str[len-1] == '\\r') { len--; read(); }\n            }\n            catch(EndOfFileRuntimeException e) { ; }\n            \n            return Arrays.copyOf(str, len);\n        }\n\n        public String nextString() throws IOException {\n            return new String(next());\n        }\n\n        public char[] next() throws IOException {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(str, len, isSpace);\n            return Arrays.copyOf(str, len);\n        }\n\n        public double nextDouble() throws IOException {\n            return Double.parseDouble(nextString());\n        }\n\n    }\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "//package cf196;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class A {\n\tFastScanner in;\n\tPrintWriter out;\n\tfinal long mod = (long) 1e9 + 9 ; \n\tpublic void solve() throws IOException {\n\t\tlong n = in.nextInt();\n\t\tlong m = in.nextInt();\n\t\tlong k = in.nextInt();\n\t\tlong l = n / k;\n\t\tlong c = n - m;\n\t\tlong mul2 = Math.max(0, l - c);\n\t\tif (mul2 == 0) {\n\t\t\tout.println(m);\n\t\t\treturn;\n\t\t}\n\t\tlong ans = power(2, mul2 + 1, mod);\n\t\tans = (ans + mod - 2) % mod;\n\t\tans = (ans * k) % mod;\n\t\tlong z = mul2 * k;\n\t\tlong r = m - z;\n\t\tans = (ans + r) % mod;\n\t\tout.print(ans);\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\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\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew A().run();\n\t}\n}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputStreamReader in = new InputStreamReader(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\n    int MOD = 1000000009;\n\n    public void solve(int testNumber, InputStreamReader inSt, PrintWriter out) {\n        InputReader in = new InputReader(inSt);\n        long n = in.nextInt();\n        long m = in.nextInt();\n        long k = in.nextInt();\n\n        long t = find(n, m, k);\n\n        long twoPow = binPow(2, (int) t);\n        twoPow--;\n\n        long result = (2 * (k * twoPow % MOD)) % MOD;\n\n        result += (m - t * k);\n        result = result % MOD;\n\n        out.println(result);\n    }\n\n    int binPow(int a, int n) {\n        if (n == 0) {\n            return 1;\n\n        }\n\n        if (n % 2 == 1) {\n            return (int) ((binPow(a, n - 1) * (a+ 0l)) % MOD);\n        } else {\n            int b = (binPow(a, n / 2)) % MOD;\n\n            return (int) (((b+0l) * b) % MOD);\n        }\n    }\n\n\n    long find(long n, long m, long k) {\n        long l = 0;\n        long r = m / k;\n        while (l < r) {\n            long mid = (l + r) / 2;\n\n            long m1 = m - mid * k;\n            long n1 = n - mid * k;\n\n\n            if (isPossible(n1, m1, k)) {\n                r = mid;\n            } else {\n                l = mid + 1;\n            }\n        }\n\n        return l;\n    }\n\n    boolean isPossible(long n, long m, long k) {\n        long r = m / (k - 1);\n        long q = m - (k - 1) * r;\n\n        if (q == 0) {\n            return r * (k - 1) + r - 1 <= n;\n        }\n\n        return r * (k - 1) + q + r <= n;\n    }\n\n    class InputReader {\n        public BufferedReader reader;\n        private String[] currentArray;\n        int curPointer;\n\n        public InputReader(InputStreamReader inputStreamReader) {\n            reader = new BufferedReader(inputStreamReader);\n        }\n\n        public String next() {\n            try {\n                currentArray = null;\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public void nextChars(char[] t) {\n            try {\n                currentArray = null;\n                reader.read(t);\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public char nextChar() {\n            try {\n                currentArray = null;\n                return (char) reader.read();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public int nextInt() {\n            if ((currentArray == null) || (curPointer >= currentArray.length)) {\n                try {\n                    currentArray = reader.readLine().split(\" \");\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                curPointer = 0;\n            }\n            return Integer.parseInt(currentArray[curPointer++]);\n        }\n\n        public long nextLong() {\n            if ((currentArray == null) || (curPointer >= currentArray.length)) {\n                try {\n                    currentArray = reader.readLine().split(\" \");\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                curPointer = 0;\n            }\n            return Long.parseLong(currentArray[curPointer++]);\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF338A extends PrintWriter {\n\tCF338A() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF338A o = new CF338A(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 1000000009;\n\tlong 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\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint z = n - m;\n\t\tif (z >= (n + k - 1) / k) {\n\t\t\tprintln(m);\n\t\t\treturn;\n\t\t}\n\t\tint d = (n - z * k) / k;\n\t\tprintln(((power(2, d + 1) - 2 + MD) * k + m - d * k) % MD);\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Template {\n\tpublic static void main(String[] args) throws IOException {\n\t\tst = new StringTokenizer(rd.readLine());\n\t\tn = Long.parseLong(st.nextToken());\n\t\tm = Long.parseLong(st.nextToken());\n\t\tk = Long.parseLong(st.nextToken());\n\t\tlong s = n - m;\n\t\ts = Math.min(s, m / (k - 1));\n\t\ts = Math.min(s, n / k);\n\t\tlong score = 0;\n\t\tscore = (s * (k - 1))%P;\n\t\tlong n1 = n - k * s, m1 = m - (k - 1) * s;\n\t\tsc = 0;\n\t//\trec(n, m);\n\t//\tSystem.out.println(sc);\n\t\tif (m1 == n1) {\n\t\t\tscore = (score + full(m1)) % P;\n\t\t\tSystem.out.println(score);\n\t\t\treturn;\n\t\t}\n\t\t\tscore = (score + m1) % P;\n\t\t\tSystem.out.println(score);\n\t}\n\n\tstatic long full(long N) {\n\t\tlong x = N / k, r = N - x * k;\n\t\tlong powTwo = powMod(2, x + 1) - 2 + 2*P;\n\t\tpowTwo %= P;\n\t\tpowTwo = (powTwo * k) % P;\n\t\tpowTwo = (powTwo + r) % P;\n\t\treturn powTwo;\n\t}\n\t\n\tstatic long sc = 0;\n\t\n\tstatic void rec(long N, long M){\n\t\tif(N==M){ sc = (sc + full(N))%P; return; }\n\t\tif(N>=k && M>=k-1){\n\t\t\tsc = (sc + (k-1))%P;\n\t\t\trec(N-k, M-(k-1));\n\t\t\treturn;\n\t\t}\n\t\tsc = (sc + M)%P;\n\t}\n\n\tstatic long powMod(long a, long p) {\n\t\tif (p == 0)\n\t\t\treturn 1L;\n\t\tlong h = powMod(a, (p >> 1));\n\t\th = (h * h) % P;\n\t\treturn p % 2 == 0 ? h : (a * h) % P;\n\t}\n\n\tstatic long n, m, k;\n\n\tstatic long P = 1000000009;\n\n\tstatic StringTokenizer st;\n\tstatic BufferedReader rd = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class Quiz {\n    public static long pow(long base, long power) {\n        if (power == 0)\n            return 1;\n        long half = pow(base, power / 2) % mod;\n        half *= half;\n        half %= mod;\n        if (power % 2 == 1)\n            half *= base;\n        return half % mod;\n    }\n\n    static long mod = (long) (1e9 + 9);\n\n    public static void main(String[] args) {\n        InputReader r = new InputReader(System.in);\n        int n = r.nextInt();\n        int m = r.nextInt();\n        int k = r.nextInt();\n        int buckets = n / k;\n        int rem = n - buckets * k;\n        long low = 0, high = buckets, itr = 30;\n        while (itr-- > 0) {\n            long mid = (low + high) / 2;\n            long correct = mid * k + rem + (buckets - mid) * (k - 1);\n            if (correct < m)\n                low = mid;\n            else\n                high = mid;\n        }\n        long pow = (pow(2, high + 1) - 2 + mod) % mod;\n        pow *= k;\n        pow %= mod;\n        long res = m - (high * k) + pow + 10 * mod;\n        res %= mod;\n        System.out.println(res);\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n\n        public InputReader(FileReader stream) {\n            reader = new BufferedReader(stream);\n            tokenizer = null;\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n                return null;\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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class a {\n    static long mod = 1000000009;\n    static ArrayList<Integer>[] g;\npublic static void main(String[] args) throws IOException\n{\n    //Scanner input = new Scanner(new File(\"input.txt\"));\n    //PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n  input.init(System.in);\n  PrintWriter out  = new PrintWriter((System.out));\n  \n  int n = input.nextInt(), m = input.nextInt(), k = input.nextInt();\n  long border = n-n/k;\n  if(m<=border) out.println(m);\n  else\n  {\n      long count = m- border;\n      long first = ((pow(2, count+1) + mod - 2)*k)%mod;\n      first += m - k*count;\n      out.println(first%mod);\n  }\n  \n  out.close();\n}\nstatic long pow(long x, long p)\n{\n    if(p==0) return 1;\n    if((p&1) > 0)\n    {\n        return (x*pow(x, p-1))%mod;\n    }\n    long sqrt = pow(x, p/2);\n    return (sqrt*sqrt)%mod;\n}\nstatic long gcd(long a, long b)\n{\n    if(b==0) return a;\n    return gcd(b, a%b);\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  \n  static double nextDouble() throws IOException {\n      return Double.parseDouble( next() );\n  }\n  static long nextLong() throws IOException {\n      return Long.parseLong( next() );\n  }\n  static String nextLine() throws IOException {\n    return reader.readLine();\n  }\n}\n}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author RiaD\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tReader in = new Reader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\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, Reader in, OutputWriter out) {\n        long answer = 0;\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int k = in.nextInt();\n\n        long l = -1;\n        long r = n + 1;\n\n        while (l + 1 < r) {\n            long c = (l + r) / 2;\n            if(n < c * k || canAchieve(n - c * k, k) >= m - c * k) {\n                r = c;\n            }\n            else\n                l = c;\n        }\n\n        //out.println(r);\n\n        long c = r;\n\n        answer = ((IntegerUtils.power(2, c + 1, MOD) - 2 + MOD) % MOD) * k % MOD;\n\n        n -= k * c;\n        m -= k * c;\n        answer += m;\n        answer %= MOD;\n\n        out.println(answer);\n    }\n\n    private long canAchieve(long n, long k) {\n        return n - n / k;\n    }\n}\n\nclass Reader {\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    public Reader(BufferedReader reader) {\n        this.reader = reader;\n    }\n\n    public Reader(InputStream stream) {\n        this(new BufferedReader(new InputStreamReader(stream)));\n    }\n\n    public String nextString() {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextString());\n    }\n\n    private String readLine() {\n        try {\n            return reader.readLine();\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        }\n    }\n}\n\nclass OutputWriter extends PrintWriter {\n\n\tpublic OutputWriter(OutputStream out) {\n\t\tsuper(out);\n\t}\n\n\tpublic OutputWriter(java.io.Writer writer){\n\t\tsuper(writer);\n\t}\n\n\t}\n\nclass IntegerUtils {\n\n\tpublic static long power(long base, long power, long mod) {\n\t\tlong result = 1 % mod;\n\t\tbase %= mod;\n\t\twhile (power > 0) {\n\t\t\tif (power % 2 == 1) {\n\t\t\t\tresult *= base;\n\t\t\t\tresult %= mod;\n\t\t\t}\n\t\t\tbase *= base;\n\t\t\tbase %= mod;\n\t\t\tpower >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\t}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Date: 23.06.13 at 15:29\n *\n * @author Nickolay Polyarniy aka PolarNick\n */\npublic class ProblemA {\n\n    private static long MOD = 1000000009;\n\n    public void solve() throws Exception {\n        long n = nextInt();\n        long m = nextInt();\n        long k = nextInt();\n        long tmp = 1024 * 1024;\n        long res = 0;\n\n        long nTmp = n;\n        long mTmp = m;\n        while (tmp > 0) {\n            while (mTmp >= (k - 1) * tmp && nTmp - k * tmp >= mTmp - (k - 1) * tmp) {\n                nTmp -= k * tmp;\n                mTmp -= (k - 1) * tmp;\n//                res = (res + (k - 1) * tmp) % MOD;\n            }\n            tmp /= 2;\n        }\n        long fullC = mTmp / k;\n//        out.println(\"mTmp=\" + mTmp + \"Full: \" + fullC);\n\n        long pow2 = getPow(2, fullC + 1, MOD);\n        res = (((res + pow2 + MOD - 2) % MOD) * k) % MOD;\n\n//        out.println(\"After full: \" + res);\n\n        mTmp = mTmp % k;\n        res = (res + mTmp) % MOD;\n\n        nTmp = n;\n        mTmp = m - fullC * k - mTmp;\n        tmp = 1024 * 1024;\n        while (tmp > 0) {\n            while (mTmp >= (k - 1) * tmp && nTmp - k * tmp >= mTmp - (k - 1) * tmp) {\n                nTmp -= k * tmp;\n                mTmp -= (k - 1) * tmp;\n                res = (res + (k - 1) * tmp) % MOD;\n            }\n            tmp /= 2;\n        }\n        out.println(res);\n    }\n\n    static long[] pows = new long[1000000];\n\n    public static long getPow(long base, long pow, long mod) {\n        if (pow < pows.length && pows[(int) pow] != 0) {\n            return pows[(int) pow];\n        }\n        if (pow == 0) {\n            pows[0] = 1;\n            return 1;\n        }\n        if (pow == 1) {\n            pows[1] = base;\n            return base;\n        }\n        long res = getPow(base, pow / 2, mod);\n        res = (res * res) % mod;\n        res = (res * getPow(base, pow % 2, mod)) % mod;\n        if (pow < pows.length) {\n            pows[(int) pow] = res;\n        }\n        return res;\n    }\n\n    public static void main(String[] args) throws Exception {\n        ProblemA problem = new ProblemA();\n        problem.solve();\n        problem.close();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n    String curLine;\n    StringTokenizer tok;\n    final String delimeter = \" \";\n    final String endOfFile = \"\";\n\n    public ProblemA(BufferedReader in, PrintWriter out) throws Exception {\n        this.in = in;\n        this.out = out;\n        curLine = in.readLine();\n        if (curLine == null || curLine == endOfFile) {\n            tok = null;\n        } else {\n            tok = new StringTokenizer(curLine, delimeter);\n        }\n    }\n\n    public ProblemA() throws Exception {\n        this(new BufferedReader(new InputStreamReader(System.in)),\n                new PrintWriter(System.out));\n    }\n\n    public ProblemA(String filename) throws Exception {\n        this(new BufferedReader(new FileReader(filename + \".in\")),\n                new PrintWriter(filename + \".out\"));\n    }\n\n    public boolean hasMore() throws Exception {\n        if (tok == null || curLine == null) {\n            return false;\n        } else {\n            while (!tok.hasMoreTokens()) {\n                curLine = in.readLine();\n                if (curLine == null || curLine.equalsIgnoreCase(endOfFile)) {\n                    tok = null;\n                    return false;\n                } else {\n                    tok = new StringTokenizer(curLine);\n                }\n            }\n            return true;\n        }\n    }\n\n    public String nextWord() throws Exception {\n        if (!hasMore()) {\n            return null;\n        } else {\n            return tok.nextToken();\n        }\n    }\n\n    public int nextInt() throws Exception {\n        return Integer.parseInt(nextWord());\n    }\n\n    public long nextLong() throws Exception {\n        return Long.parseLong(nextWord());\n    }\n\n    public int[] readIntArray(int n) throws Exception {\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 void close() throws Exception {\n        in.close();\n        out.close();\n    }\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class A\n{\n\tprivate static final long MOD = 1000000009L;\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t    long n = in.nextInt();\n\t\tlong m = in.nextInt();\n\t\tlong k = in.nextInt();\n\n\t\tlong w = n-m;\n\n\t\tlong c = w*k;\n\t\tif(c >= n)\n\t\t{\n\t\t\tSystem.out.println(m);\n\t\t\treturn;\n\t\t}\n\n\t\tlong rem = n-c;\n\t\tlong h = rem/k;\n\n\t\tlong p = power(2, h+1);\n\t\tp -= 2;\n\t\tp += MOD;\n\t\tp %= MOD;\n\t\tp *= k;\n\t\tp %= MOD;\n\n\t\tlong point = p + m - (h*k) % MOD;\n\t\tpoint += MOD;\n\t\tpoint %= MOD;\n\n\t\tSystem.out.println(point);\n\n\n\n\t}\n\n\tprivate static long power(int num, long power)\n\t{\n\t\tif(power == 0)\n\t\t\treturn 1;\n\t\tlong res = power(num, power/2);\n\t\tres = (res*res)%MOD;\n\t\tif(power % 2 != 0)\n\t\t\tres *= num;\n\n\t\tres%=MOD;\n\n\t\treturn res;\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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 * @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        OutputWriter out = new OutputWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n}\n\nclass TaskA {\n    int mod = 1000000009;\n\n    public void solve(int testNumber, Parser in, OutputWriter out) {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int k = in.nextInt();\n\n        int o = m;\n        m -= n - (n/k);\n        if (m < 0) m = 0;\n\n        long temp = n/k;\n        long ans;\n        if (m == 0) ans = 0;\n        else {\n            ans = (MathUtils.modpow(2, m+1, mod) + mod - 2) % mod;\n            ans = (ans * k) % mod;\n        }\n\n        out.println((ans + (o - m*k)) % mod);\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\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 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    }\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\npublic class A338 {\n\n\tpublic static void main (String args[]){\n\t\t\n\t\tScanner in= new Scanner(System.in);\n\t\tlong n = in.nextInt();\n\t\tlong m=in.nextInt();\n\t\tlong k=in.nextInt();\n\t\t\n\t\tlong x = n-m;\n\t\tlong y=n/k;\n\t\tif(x>=y)\n\t\t\tSystem.out.println(m);\n\t\telse\n\t\t{\n\t\t\tlong t= y-x;\n\t\t\tlong ans=0;\n\t\t\tans+=k*(pow(t+1)-2);\n\t\t\tans%=1000000009;\n\t\t\tans+=m-t*k;\n\t\t\tans%=1000000009;\n\t\t\tif(ans<0)\n\t\t\t\tans+=1000000009;\n\t\t\tSystem.out.println(ans);\n\t\t\t\n\t\t}\n\t\t\t\n\t\t\n\t\t\n\t}\n\t\n\tpublic static long pow(long m ){\n\t\t\n\t\tif(m==1)\n\t\t\treturn 2;\n\t\tlong x = pow(m/2);\n\t\t\n\t\tx%=1000000009;\n\t\tx*=x;\n\t\tif(m%2!=0)\n\t\t\tx*=2;\n\t\tx%=1000000009;\n\t\treturn (x);\n\t\t\n\t}\n\t\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tint tot = nextInt();\n\t\tint ok = nextInt();\n\t\t\n\t\tint k = nextInt();\n\t\t\n\t\tint maxBad = tot / k;\n\t\tif (tot - maxBad >= ok) {\n\t\t\tout.println(ok);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t\n\t\tint\tdbl = ok + tot / k - tot;\n\n\t\t\n\t\tint dblPoints = pow(2, dbl + 1) - 2;\n\t\twhile (dblPoints < 0)\n\t\t\tdblPoints += MOD;\n\t\t\n\t\tdblPoints = (int)((long)dblPoints * k % MOD);\n\t\t\n\t\tint rest = ok - dbl * k;\n\t\t\n\t\tint ans = dblPoints + rest;\n\t\t\n\t\tif (ans >= MOD)\n\t\t\tans -= MOD;\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tstatic int pow(int a, int b) {\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 % 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\t\n\tstatic final int MOD = 1000000009;\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}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\tlong mod = (long)(1e+9+9);\n\tlong pow(long a,long b) {\n\t\tlong mul = a;\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif (b %2 == 1) {\n\t\t\t\tres = (res*mul)%mod;\n\t\t\t}\n\t\t\tmul = (mul*mul)%mod;\n\t\t\tb/=2;\n\t\t}\n\t\treturn res;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tlong m = nextLong();\n\t\tlong k = nextLong();\n\t\tlong l = -1;\n\t\tlong r = m / k;\n\t\twhile (l < r - 1) {\n\t\t\tlong mid = (l+r)/2;\n\t\t\tlong leftOk = m - mid*k;\n\t\t\tlong leftPos = n - mid*k;\n\t\t\tlong cgroups = (leftOk + (k-2)) / (k-1);\n\t\t\tlong positions = leftOk+cgroups-1;\n\t\t\tif (positions <= leftPos) {\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\tlong res = pow(2,r+1);\n\t\tres = (res - 2 + mod) %mod;\n\t\tres = (res*k) % mod;\n\t\tres = (res+m-r*k) %mod;\n\t\tout.println(res);\n\t\t\n\t\t\n\t\t\n\t\t\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 A().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString temp = in.readLine();\n\t\t\tif (temp == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tst = new StringTokenizer(temp);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\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}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemA {\n    InputReader in; PrintWriter out;\n\n    long power(long a, long b, long mod) {\n        long ret = 1;\n        long mul = a;\n        while (b > 0) {\n            if (b % 2 == 1) {\n                ret = (ret * mul % mod);                \n            }\n            mul = (mul * mul) % mod;\n            b = b / 2;\n        }\n        return ret;\n    }\n    \n    void solve() {\n        long n = in.nextLong();\n        long m = in.nextLong();\n        long k = in.nextLong();\n        long mod = 1000000009;\n        long x = m - (n - n / k);\n        if (x <= 0) {\n            out.println(m);\n        }\n        else {\n            long score = 1;\n            score = power(2, x + 1, mod);\n            score = (score + mod - 2) % mod;\n//          out.println(score);\n            long ans = ((score * k) + m - x * k + mod) % mod;\n            out.println(ans);\n        }\n    }\n    \n    ProblemA(){\n        boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        try {\n            if (oj) {\n                in = new InputReader(System.in);\n                out = new PrintWriter(System.out);\n            }\n            else {\n                Writer w = new FileWriter(\"output.txt\");\n                in = new InputReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(w);\n            }\n        } catch(Exception e) {\n            throw new RuntimeException(e);\n        }\n        solve();\n        out.close();\n    }\n    public static void main(String[] args){\n        new ProblemA();\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 InputReader(FileReader fr) {\n        reader = new BufferedReader(fr);\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    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}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n\npublic class A2 {\n/*\n\n\n\n */\n    public static void main(String[] args) throws Exception {\n        uu.s1();\n        uu.out.close();\n    }\n    public static class uu {\n        public static BR in = new BR();\n        public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        public static boolean bg = true;\n        public static MOD m1 = new MOD(1000000000+9);\n        public static long mod = 1000000000+9;\n        public static void s1() throws Exception {\n            long n = in.ni();\n            long m = in.ni();\n            long k = in.ni();\n            long lose = n - m;\n            long aval = m / (k - 1l);\n            long times1 = Math.min(lose, aval);\n            long notused = times1 * (k - 1l);\n            long used = m - notused;\n            long blocks = used / k;\n            long left = used % k;\n            long k1 = 0;\n            if (blocks != 0){\n                k1 = m1.pow(2, blocks+1);\n                k1 = m1.s(k1, 2);\n            }\n            long ans = (m1.t(k, k1)+left + notused)%mod;\n            pn(ans);\n        }\n        public static void geom(long f1){\n        }\n        \n        public static void s2() throws Exception {\n            \n        }\n        public static void s3() throws Exception {\n            \n        }\n        \n        private static void pn(Object... o1) {\n            for (int i = 0; i < o1.length; i++){\n                if (i!= 0) out.print(\" \");\n                out.print(o1[i]);\n            }\n            out.println();\n        }\n\n        public static boolean allTrue(boolean ... l1){\n            for (boolean e: l1) if (!e) return false;\n            return true;\n        }\n        public static boolean allFalse(boolean ... l1){\n            for (boolean e: l1) if (e) return false;\n            return true;\n        }\n    }\n    private static class MOD {\n        public long mod = -1;\n\n        public MOD(long k1) {\n            mod = k1;\n        }\n\n        public long cl(long n1){\n            long fin = n1%mod;\n            if (fin<0) fin+= mod;\n            return fin;\n        }\n        \n        public long s(long n1, long n2) {\n            long k1 = (n1 - n2) % mod;\n            if (k1 < 0)\n                k1 += mod;\n            return k1;\n        }\n\n        public long t(long n1, long n2) {\n            long k1 = (n1 * n2) % mod;\n            if (k1 < 0)\n                k1 += mod;\n            return k1;\n        }\n\n        public static long xgcd(long n1, long n2) {\n            long k1 = n1;\n            long k2 = n2;\n            long[] l1 = { 1, 0 };\n            long[] l2 = { 0, 1 };\n            for (;;) {\n                long f1 = k1 / k2;\n                long f2 = k1 % k2;\n                if (f2 == 0)\n                    break;\n\n                long[] l3 = { 0, 0 };\n                l3[0] = l1[0] - f1 * l2[0];\n                l3[1] = l1[1] - f1 * l2[1];\n                l1 = l2;\n                l2 = l3;\n\n                k1 = k2;\n                k2 = f2;\n            }\n            long fin = l2[1] % n1;\n            if (fin < 0) {\n                fin += n1;\n            }\n            return fin;\n        }\n\n        public long pow(long n1, long pow) {\n            if (pow == 0)\n                return 1;\n            else if (pow == 1)\n                return t(1l, n1);\n            else if ((pow & 1) == 0) {\n                long half = pow(n1, pow >> 1);\n                return t(half, half);\n            } else {\n                long half = pow(n1, pow >> 1);\n                return t(half, t(half, n1));\n            }\n        }\n\n        public long factorial(long k1, long n1) {\n            long fin = 1;\n            long q1 = k1;\n            for (int i = 0; i < n1; i++) {\n                fin = t(fin, q1);\n                q1--;\n                if (q1 <= 0)\n                    break;\n            }\n            return cl(fin);\n        }\n\n    }\n    \n    private static class BR {\n        BufferedReader k1 = null;\n        StringTokenizer k2 = null;\n\n        public BR() {\n            k1 = new BufferedReader(new InputStreamReader(System.in));\n        }\n        public String nx() throws Exception {\n            for (;;) {\n                if (k2 == null || !k2.hasMoreTokens()) {\n                    String temp = k1.readLine();\n                    if (temp == null)\n                        return null;\n                    k2 = new StringTokenizer(temp);\n                }\n                else\n                    break;\n            }\n\n            return k2.nextToken();\n        }\n\n        public int ni() throws Exception {\n            return Integer.parseInt(nx());\n        }\n    }\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.awt.Rectangle;\nimport java.awt.geom.Rectangle2D;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C\n{\n\tString line;\n\tStringTokenizer inputParser;\n\tBufferedReader is;\n\tFileInputStream fstream;\n\tDataInputStream in;\n\tString FInput=\"\";\n\t\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\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\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\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\tlong NextLong()\n    {\n            String n = inputParser.nextToken();\n            \n            long val = Long.parseLong(n);\n            \n            return val;\n    }\n\t\n\tpublic static void main(String [] argv)\n\t{\n\t\t//String filePath=\"input.txt\";\n        String filePath=null;\n        if(argv.length>0)filePath=argv[0];\n\t\tnew C(filePath);\n\t}\n\tfinal int MOD = 1000000009;\n\tpublic C(String inputFile)\n\t{\n\t\topenInput(inputFile);\n\t\tStringBuilder sb = new StringBuilder();\n\t\treadNextLine();\n    \tint N=NextInt(), M=NextInt(), K=NextInt();\n    \t\n    \tif((N/K)<=(N-M))\n    \t{\n    \t\tsb.append(M);\n    \t}\n    \telse\n    \t{\n    \t\tint x=(N/K)-(N-M);\n    \t\tlong ret=(pow(2, x) -1 );\n    \t\t\n    \t\t\n    \t\tret *=K;\n    \t\tret%=MOD;\n    \t\tret *= 2;\n    \t\tret%=MOD;\n    \t\t/*\n    \t\tret+=pow(K, x+1);\n    \t\tret%=MOD;*/\n    \t\tret+=(M-x*K);\n    \t\tret%=MOD;\n    \t\tsb.append(ret+\"\\n\");\n    \t\t\n    \t\t\n    \t}\n\t\t\n    \tSystem.out.println(sb);\n\t\tcloseInput();\t\t\n\t}\n\n\tlong pow(long b, long exponent)\n\t{\n\t    long ret = 1;\n\t    while(exponent > 0)\n\t    {\n\t        if (exponent%2 == 1)\n\t           ret = (ret * b) % MOD;\n\t        exponent = exponent >> 1;\n\t        b = (b * b) % MOD;\n\t    }\n\t    return ret;\n\t}\n\n\t\n}\n\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.math.MathContext;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n}\n\nclass TaskA {\n\n    public static final long mod = 1000L * 1000L * 1000L + 9L;\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        long n = in.nextLong();\n        long m = in.nextLong();\n        long k = in.nextLong();\n        long z = n - m;\n        long left = m - z * (k - 1L);\n        if (left < 0) left = 0;\n        long res = IntegerUtlis.pow(2L, left / k, mod) - 1L;\n        res *= 2L * k;\n        res %= mod;\n        res += left % k;\n        res %= mod;\n        res += m - left;\n        res %= mod;\n        res += mod;\n        res %= mod;\n        out.printLine(res);\n    }\n}\n\nclass InputReader {\n    private InputStream stream;\n    private byte[] buffer = new byte[10000];\n    private int cur;\n    private int count;\n\n    public InputReader(InputStream stream) {\n        this.stream = stream;\n    }\n\n    public static boolean isSpace(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int read() {\n        if (count == -1) {\n            throw new InputMismatchException();\n        }\n        try {\n            if (cur >= count) {\n                cur = 0;\n                count = stream.read(buffer);\n                if (count <= 0)\n                    return -1;\n            }\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n        return buffer[cur++];\n    }\n\n    public int readSkipSpace() {\n        int c;\n        do {\n            c = read();\n        } while (isSpace(c));\n        return c;\n    }\n\n    public long nextLong() {\n        long sgn = 1;\n        int c = readSkipSpace();\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        long res = 0;\n        do {\n            if (c < '0' || c > '9') {\n                throw new InputMismatchException();\n            }\n            res = res * 10L + (long)(c - '0');\n            c = read();\n        } while (!isSpace(c));\n        res *= sgn;\n        return res;\n    }\n\n    }\n\nclass OutputWriter {\n    private final PrintWriter writer;\n\n    public OutputWriter(OutputStream outputStream) {\n        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n    }\n\n    public OutputWriter(Writer writer) {\n        this.writer = new PrintWriter(writer);\n    }\n\n    public void print(Object... objects) {\n        for (int i = 0; i < objects.length; i++) {\n            if (i != 0) {\n                writer.print(' ');\n            }\n            writer.print(objects[i]);\n        }\n    }\n\n    public void printLine(Object... objects) {\n        print(objects);\n        writer.println();\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    }\n\nclass IntegerUtlis {\n\n    public static long pow(long x, long y, long mod) {\n        x %= mod;\n        long res = 1;\n        while (y > 0) {\n            if (y % 2 == 1) {\n                --y;\n                res = BigInteger.valueOf(res).multiply(BigInteger.valueOf(x)).mod(BigInteger.valueOf(mod)).longValue();\n            } else {\n                y /= 2;\n                x = BigInteger.valueOf(x).multiply(BigInteger.valueOf(x)).mod(BigInteger.valueOf(mod)).longValue();\n            }\n        }\n        return res % mod;\n    }\n\n    }\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tlong n = nextLong();\n\t\tlong m = nextLong();\n\t\tlong k = nextLong();\n\t\tlong numBlocks = Math.min(Math.min(n / k, n - m), m / (k - 1));\n\t\tn -= numBlocks * k;\n\t\tm -= numBlocks * (k - 1);\n\t\tlong numFullBlocks = m / k;\n\t\tlong rem = m % k;\n\t\tlong res = 0;\n\t\tres = (res + ((p2(numFullBlocks + 1) + MOD - 2) % MOD) * k) % MOD;\n\t\tres = (res + rem) % MOD;\n\t\tres = (res + numBlocks * (k - 1)) % MOD;\n\t\tout.println(res);\n\t}\n\n\tfinal int MOD = 1000000009;\n\tprivate long p2(long s) {\n\t\tlong res = 1;\n\t\tlong x = 2;\n\t\twhile (s > 0) {\n\t\t\tif (s % 2 == 1) {\n\t\t\t\tres = res * x % MOD;\n\t\t\t}\n\t\t\tx = x * x % MOD;\n\t\t\ts /= 2;\n\t\t}\n\t\treturn res;\n\t}\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tprivate String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString rl = in.readLine();\n\t\t\tif (rl == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(rl);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.UK);\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//in = new BufferedReader(new FileReader(\"a.in\"));\n\t\t\t//out = new PrintWriter(new FileWriter(\"a.out\"));\n\n\t\t\t_main();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(202);\n\t\t}\n\t}\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n    StreamTokenizer in;\n    PrintWriter out;\n    //deb////////////////////////////////////////////////\n\n    public static void deb(String n, Object n1) {\n        System.out.println(n + \" is : \" + n1);\n    }\n\n    public static void deb(int[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(long[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(BigInteger[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(int[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\n\n    public static void deb(long[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\n\n    public static void deb(String[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\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    class Pair<X, Y> {\n\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 void setX(X x) {\n            this.x = x;\n        }\n\n        public void setY(Y y) {\n            this.y = y;\n        }\n    }\n\n    boolean inR(int x, int y) {\n        return (x >= 0) && (x < nn) && (y >= 0) && (y < nn);\n    }\n    static int nn;\n\n    void run() throws IOException {\n        //  in = new StreamTokenizer(new BufferedReader(new FileReader(\"circles.in\")));\n        //  out = new PrintWriter(new FileWriter(\"circles.out\"));\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    static long MOD=1000000009;\nstatic long modPow(long a, int pow) {\n        long res = 1;\n        while (pow > 0) {\n            if ((pow & 1) != 0) {\n                res = res * a % MOD;\n            }\n            pow >>= 1;\n            a = a * a % MOD;\n        }\n        return res;\n    }\n\n    void solve() throws IOException {\n        //   BufferedReader re= new BufferedReader(new FileReader(\"C:\\\\Users\\\\ASELA\\\\Desktop\\\\A.in\"));\n       // BufferedReader re = new BufferedReader(new InputStreamReader(System.in));\n        int n=nextInt(),m=nextInt(),k=nextInt();\n        int an=(n/k)*(k-1)+n%k;\n        long ans=0;\n        if(an>=m){\n            System.out.println(m);\n            return;\n        }\n        int rem=m-an;\n        ans=modPow(2, rem+1)-2;\n        ans*=k;\n        ans+=m-rem*k;\n        ans%=MOD;\n       // System.out.println(\"sjkd\"+rem);\n        if(ans<0)ans+=MOD;\n        System.out.println(ans);\n    }\n}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\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 BSRK Aditya\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        long numQuestions = in.nextInt();\n        long numCorrectlyAnsweredQuestions = in.nextInt();\n        long sizeForDoublingScore = in.nextInt();\n\n        long score = 0;\n\n        long numIncorrectlyAnsweredQuestions = numQuestions - numCorrectlyAnsweredQuestions;\n\n        long numDoublings = Math.max(numQuestions / sizeForDoublingScore - numIncorrectlyAnsweredQuestions, 0);\n        score += 2*sizeForDoublingScore*Long.parseLong(new BigInteger(\"2\").modPow(new BigInteger(String.valueOf(numDoublings)), new BigInteger(\"1000000009\")).subtract(BigInteger.ONE).toString());\n        score += numCorrectlyAnsweredQuestions - sizeForDoublingScore*numDoublings;\n        score %= 1000000009;\n\n        out.println(score);\n    }\n}\n\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\n\n\npublic class A {\n\t\n\tprivate long pow(long num, long pow, long mod) {\n\t\tif (pow <= 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif ((pow & 1) != 0) {\n\t\t\treturn (num * pow(num, pow-1, mod)) % mod;\n\t\t}\n\t\telse {\n\t\t\tlong tmp = pow(num, pow>>1, mod) % mod;\n\t\t\treturn (tmp*tmp)%mod;\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\tlong MOD = 1000000009;\n\t\tlong n = nextInt();\n\t\tlong m = nextInt();\n\t\tlong k = nextInt();\n\t\t\n\t\tlong critical = n/k;\n\t\tif (n-critical >= m) {\n\t\t\tout.println(m);\n\t\t}\n\t\telse {\n\t\t\tlong doubles = m - (n-critical);\n\t\t\tlong ans = (pow(2, doubles + 1, MOD) - 2 + MOD)%MOD;\n\t\t\tans = (ans * k)%MOD;\n\t\t\tans = (ans + (m-(doubles*k)))%MOD;\n\t\t\tout.println(ans);\n\t\t}\n\t\tout.flush();\n\t}\n\t\n\tprivate static BufferedReader br = null;\n\tprivate static StringTokenizer stk = null;\n\tprivate static PrintWriter out = null;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t(new A()).run();\n\t}\n\t\n\tprivate void loadLine() {\n\t\ttry {\n\t\t\tstk = new StringTokenizer(br.readLine());\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t\n\tprivate int nextInt() {\n\t\twhile (stk==null || !stk.hasMoreElements()) loadLine();\n\t\treturn Integer.parseInt(stk.nextToken());\n\t}\n\t\n\tprivate long nextLong() {\n\t\twhile (stk==null || !stk.hasMoreElements()) loadLine();\n\t\treturn Long.parseLong(stk.nextToken());\n\t}\n\t\n\tprivate double nextDouble() {\n\t\twhile (stk==null || !stk.hasMoreElements()) loadLine();\n\t\treturn Double.parseDouble(stk.nextToken());\n\t}\n\t\n\tprivate String nextWord() {\n\t\twhile (stk==null || !stk.hasMoreElements()) loadLine();\n\t\treturn (stk.nextToken());\n\t}\n\t\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Quiz{\n\tstatic int MOD = (int)1e9 + 9;\n\tpublic static void main(String[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tlong n = reader.nextInt();\n\t\tlong m = reader.nextInt();\n\t\tlong k = reader.nextInt();\n\t\t\n\t\tlong r = (n + k - 1)/k;\n\t\t\n\t\tlong longDrops = n%k;\n\t\t\n\t\tif(longDrops == 0){\n\t\t\tlong d = m - (r * (k-1));\n\t\t\t\n\t\t\tif(d <= 0){\n\t\t\t\tSystem.out.println(m);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tlong sum = (fastExpo(2,d+1)-2) * k + (m - d*k);\n\t\t\tSystem.out.println((sum+MOD)%MOD);\n\t\t}else{\n\t\t\tlong d = (m-longDrops*r) - (r-1)*(k-longDrops-1);\n\t\t\t\n\t\t\tif(d <= 0){\n\t\t\t\tSystem.out.println(m);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tlong sum = (fastExpo(2,d+1)-2) * k + (m - d*k);\n\t\t\tSystem.out.println((sum+MOD)%MOD);\n\t\t}\n\t}\n\t\n\tpublic static long fastExpo(long b, long p){\n\t\tif(p == 0)\n\t\t\treturn 1;\n\t\tif(p % 2 == 1)\n\t\t\treturn (b * fastExpo(b, p-1))%MOD;\n\t\tlong x = fastExpo(b, p/2);\n\t\treturn (x * x)%MOD;\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class cf337c {\n  static long mod,n,m,k;\n  public static void main(String[] args) {\n    FastIO in = new FastIO(), out = in;\n    n = in.nextLong();\n    m = in.nextLong();\n    k = in.nextLong();\n    mod = (long)1e9 + 9;\n    long x = m - (n-n%k)/k * (k-1) - n%k;\n    if(x < 0) x = 0;\n    long ans = (pow(2,x+1)-2)*k + m-x*k;\n    ans = ((ans%mod)+mod)%mod;\n    out.println(ans);\n    out.close();\n  }\n  static long pow(long x, long p) {\n    if(p == 0) return 1%mod;\n    long ans = pow(x,p/2);\n    ans = (ans*ans)%mod;\n    if(p%2 == 1) ans = (ans*x)%mod;\n    return ans;\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    public FastIO(InputStream in, OutputStream out) {\n      super(new BufferedWriter(new OutputStreamWriter(out)));\n      br = new BufferedReader(new InputStreamReader(in));\n      scanLine();\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    public int numTokens() {\n      if(!st.hasMoreTokens()) {\n        scanLine();\n        return numTokens();\n      }\n      return st.countTokens();\n    }\n    public String next() {\n      if(!st.hasMoreTokens()) {\n        scanLine();\n        return next();\n      }\n      return st.nextToken();\n    }\n    public double nextDouble() {\n      return Double.parseDouble(next());\n    }\n    public long nextLong() {\n      return Long.parseLong(next());\n    }\n    public int nextInt() {\n      return Integer.parseInt(next());\n    }\n  }\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\tprivate static Scanner in;\n\t\n\tfinal int M = 1000000009;\n\n\tpublic void run() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint z = n - m;\n\t\tif (z >= n / k) {\n\t\t\tSystem.out.println(m);\n\t\t\treturn;\n\t\t}\n\t\tint f = n - k * z;\n\t\tint ans = BigInteger.ONE.shiftLeft(f / k + 1).remainder(BigInteger.valueOf(M)).intValue();\n\t\tSystem.out.println(((ans + M - 2L) * k + (f % k + (k - 1) * z)) % M);\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 A().run();\n\t\tin.close();\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tlong mod = (long) 1e9 + 9;\n\n\tclass Pair {\n\t\tlong a, b;\n\n\t\tpublic Pair(long a, long b) {\n\t\t\tsuper();\n\t\t\tthis.a = a % mod;\n\t\t\tthis.b = b % mod;\n\t\t}\n\n\t}\n\n\tint k;\n\n\tlong pow(long n, long k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tlong m1 = pow(n, k / 2);\n\t\tm1 = (m1 * m1) % mod;\n\t\tif (k % 2 != 0)\n\t\t\tm1 = (m1 * n) % mod;\n\t\treturn m1;\n\t}\n\n\tlong st(int n, int m, int k) {\n\t\tint parts = n / k;\n\t\tint used = n - m;\n\t\tif (parts > n - m) {\n\t\t\tlong cur = 0;\n\t\t\tint counter = 0;\n\t\t\tint need = parts - (n - m);\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tif (counter + 1 == k && need <= 0) {\n\t\t\t\t\tcounter = 0;\n\t\t\t\t\tused--;\n\t\t\t\t} else {\n\t\t\t\t\tcounter++;\n\t\t\t\t\tcur++;\n\t\t\t\t\tif (counter == k) {\n\t\t\t\t\t\tcounter = 0;\n\t\t\t\t\t\tcur = (cur * 2) % mod;\n\t\t\t\t\t\tneed--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (used < 0)\n\t\t\t\tthrow new AssertionError();\n\t\t\treturn cur;\n\t\t} else {\n\t\t\treturn m;\n\t\t}\n\t}\n\n\tlong mysol(int n, int m, int k) {\n\t\tthis.k = k;\n\t\tint parts = n / k;\n\t\tif (parts > n - m) {\n\t\t\tlong ost = n - (n - m) * k;\n\t\t\tlong power = ost / k;\n\t\t\tlong res = pow(2, power + 1);\n\t\t\tlong cur = ((res - 2 + mod) % mod) * k;\n\t\t\tcur %= mod;\n\t\t\tcur += Math.max(0, m - power * k);\n\t\t\tcur %= mod;\n\t\t\treturn cur;\n\t\t} else {\n\t\t\treturn m;\n\t\t}\n\t}\n\n\tvoid realSolve() throws IOException {\n\t\t int n = in.nextInt();\n\t\t int m = in.nextInt();\n\t\t k = in.nextInt();\n\t\t out.println(mysol(n, m, k));\n\t\t/*Random rnd = new Random(123);\n\t\tfor (int t = 0; t < 10000; t++) {\n\t\t\tSystem.err.println(t);\n\t\t\tint n = rnd.nextInt(100) + 2;\n\t\t\tint m = rnd.nextInt(n + 1);\n\t\t\tint k = rnd.nextInt(n - 1) + 2;\n\n\t\t\tif (t == 16) {\n\t\t\t\tSystem.err.println(\"!\");\n\t\t\t}\n\t\t\tlong r1 = mysol(n, m, k);\n\t\t\tlong r2 = st(n, m, k);\n\t\t\tif (r1 != r2)\n\t\t\t\tthrow new AssertionError(r1 + \" \" + r2);\n\n\t\t}*/\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 solveIO() throws IOException {\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\tvoid solve() throws IOException {\n\t\tin = new InputReader(new File(\"input.txt\"));\n\t\tout = new PrintWriter(new File(\"output.txt\"));\n\n\t\trealSolve();\n\n\t\tout.close();\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew CF().solveIO();\n\t}\n}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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 A{\n\tScanner sc=new Scanner(System.in);\n\n\tint INF=1<<28;\n\tdouble EPS=1e-9;\n\n\tint mod=(int)1e9+9;\n\n\tlong n, m, k;\n\n\tvoid run(){\n\t\tn=sc.nextLong();\n\t\tm=sc.nextLong();\n\t\tk=sc.nextLong();\n\t\tsolve();\n\t}\n\n\tvoid solve(){\n\t\tlong ans=0;\n\t\tlong s=n-m;\n\t\tlong remain=max(n-s*k, 0);\n//\t\tdebug(\"remain\", remain);\n\t\tans=m-remain;\n//\t\tdebug(\"ans\", ans);\n\t\tlong r=remain%k;\n\t\tans=(ans+r)%mod;\n\t\tremain-=r;\n//\t\tdebug(\"remain2\", remain);\n\t\tlong a=remain/k;\n\t\tlong add=(powMod(2, a, mod)-1)*k%mod*2%mod;\n//\t\tdebug(\"add\", add);\n\t\tans=(ans+add)%mod;\n//\t\tdebug(ans);\n\t\tprintln(ans+\"\");\n\t}\n\n\tlong powMod(long x, long k, long mod){\n\t\tif(k==0){\n\t\t\treturn 1%mod;\n\t\t}else if(k%2==0){\n\t\t\treturn powMod(x*x%mod, k/2, mod);\n\t\t}else{\n\t\t\treturn x*powMod(x, k-1, mod)%mod;\n\t\t}\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew A().run();\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "//package round196;\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 A {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tpublic static long pow(long a, long n, long mod)\n\t{\n//\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)ret = ret * a % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), K = ni();\n\t\tif(m <= n/K*(K-1)+n%K){\n\t\t\tout.println(m);\n\t\t}else{\n\t\t\tint mod = 1000000009;\n\t\t\tint f = m - (n/K*(K-1)+n%K);\n\t\t\tout.println(((pow(2, f+1, mod) + mod - 2) * K + (m - f*K)) % mod);\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 A().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", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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\npublic class C {\n    private static BufferedReader in;\n    private static StringTokenizer st;\n    private static PrintWriter out;\n    \n    public static void main(String[] args) throws NumberFormatException, IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        st = new StringTokenizer(\"\");\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        int mod = (int) (1e9+9);\n        int correct = n - n / k;\n        int carry = n % k;\n        long ans;\n        if(correct >= m){\n            ans = m;\n        }else{\n            m -= correct;\n            int block = n / k;\n            BigInteger pow = BigInteger.valueOf(2).modPow(BigInteger.valueOf(m + 1), BigInteger.valueOf(mod));\n            ans = (pow.longValue() - 2 + mod) % mod;\n            ans = (ans * (long) k) % mod;\n            ans = (ans + (long)(block - m)* (long)(k-1) + carry) % mod;\n        }\n        System.out.println(ans);\n        \n    }\n\n    static String next() throws IOException{\n        while(!st.hasMoreTokens()){\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n    static int nextInt() throws NumberFormatException, IOException{\n        return Integer.parseInt(next());\n    }\n    static long nextLong() throws NumberFormatException, IOException{\n        return Long.parseLong(next());\n    }\n    \n    static double nextDouble() throws NumberFormatException, IOException{\n        return Double.parseDouble(next());\n    }\n\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class History {\n\tstatic final int INF = (int)1E9;\n\tstatic final double EPS = 1E-9;\n\tstatic final long MOD = INF + 9;\n\t\n\tstatic long powmod(long p) {\n\t\tlong res = 1;\n\t\tlong d = 2;\n\t\twhile (p > 0) {\n\t\t\tif (p % 2 == 1) {\n\t\t\t\tres = (res * d) % MOD;\n\t\t\t\tp--;\n\t\t\t}\n\t\t\telse {\n\t\t\t\td = (d * d) % MOD;\n\t\t\t\tp /= 2;\n\t\t\t}\n\t\t}\n\t\treturn res % MOD;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader(System.in);\n\t\tlong n = in.nextLong();\n\t\tlong m = in.nextLong();\n\t\tlong k = in.nextLong();\n\t\t\n\t\tlong ans = 0;\n\t\t\n\t\tlong t = (k - 1) * (n - m);\n\t\t\n\t\tif (t <= m) {\n\t\t\tn -= k * (n - m);\n\t\t\t\n\t\t\tlong g = n / k;\n\t\t\t\n\t\t\tans = 2 * k * (powmod(g) - 1) + n % k;\n\t\t\t\n\t\t\tans = (ans + t) % MOD;\n\t\t}\n\t\telse {\n\t\t\tans = m;\n\t\t}\n\t\t\n\t\tSystem.out.println(ans % MOD);\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));\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}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\n/**\n * Created by hama_du on 15/09/10.\n */\npublic class A {\n    private static final long MOD = 1000000009;\n\n    public static void main(String[] args) {\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        long n = in.nextInt();\n        long correct = in.nextInt();\n        long k = in.nextInt();\n        long wrong = n - correct;\n        long set = wrong * k + k - 1;\n        if (set >= n) {\n            out.println(correct);\n        } else {\n            long needExtraCorrect = n - (wrong * k + k - 1);\n            long firstSet = needExtraCorrect + k - 1;\n            long otherSet = correct - firstSet;\n\n            long firstDouble = firstSet / k;\n            otherSet += firstSet % k;\n            long[][] mat = new long[][]{ {2, 2*k}, {0, 1}};\n            long[][] A = pow(mat, firstDouble, MOD);\n            long score = (A[0][1] + otherSet) % MOD;\n            out.println(score);\n        }\n        out.flush();\n    }\n\n    public static long[][] pow(long[][] a, long n, long mod) {\n        long i = 1;\n        long[][] res = E(a.length);\n        long[][] ap = mul(E(a.length), a, mod);\n        while (i <= n) {\n            if ((n & i) >= 1) {\n                res = mul(res, ap, mod);\n            }\n            i *= 2;\n            ap = mul(ap, ap, mod);\n        }\n        return res;\n    }\n\n    public static long[][] E(int n) {\n        long[][] a = new long[n][n];\n        for (int i = 0 ; i < n ; i++) {\n            a[i][i] = 1;\n        }\n        return a;\n    }\n\n    public static long[][] mul(long[][] a, long[][] b, long mod) {\n        long[][] c = new long[a.length][b[0].length];\n        if (a[0].length != b.length) {\n            System.err.print(\"err\");\n        }\n        for (int i = 0 ; i < a.length ; i++) {\n            for (int j = 0 ; j < b[0].length ; j++) {\n                long sum = 0;\n                for (int k = 0 ; k < a[0].length ; k++) {\n                    sum = (sum + a[i][k] * b[k][j]) % mod;\n                }\n                c[i][j] = sum;\n            }\n        }\n        return c;\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", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class A {\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\t\tfinal int mod = 1000*1000*1000+9;\n\t\tlong n = readInt();\n\t\tlong m = readInt();\n\t\tlong k = readInt();\n\t\tlong fail = n-m;\n\t\tlong posl = n / k ;\n\t\tif(n % k != 0) {\n\t\t\tposl++;\n\t\t}\n\t\tif(posl <= fail) {\n\t\t\tout.println(m);\n\t\t} else {\n\t\t\tlong d = fail - posl;\n\t\t\tlong res = (k-1) * fail;\n\t\t\tm -= (k-1) * fail;\n\t\t\tlong z = m / k;\n\t\t\tres += m % k;\n\t\t\tres %= mod;\n\t\t\tlong x = binpow(2, z+1, mod);\n\t\t\tx -= 2;\n\t\t\tx += mod;\n\t\t\tx %= mod;\n\t\t\tx *= k;\n\t\t\tres += x;\n\t\t\tres %= mod;\n\t\t\tout.println(res);\n\t\t}\n    }\n\n\tlong binpow (long a, long n, long mod) {\n\t\tlong res = 1;\n\t\twhile (n != 0)\n\t\t\tif ((n & 1) != 0) {\n\t\t\t\tres *= a;\n\t\t\t\tres = res % mod;\n\t\t\t\t--n;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ta *= a;\n\t\t\t\ta = a % mod;\n\t\t\t\tn >>= 1;\n\t\t\t}\n\t\treturn res;\n\t}\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 A().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}", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "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\npublic class A {\n\t\n\tstatic StringTokenizer st;\n\tstatic BufferedReader in;\n\tstatic PrintWriter pw;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n//\t\tlong a = 2;\n//\t\tint q = nextInt();\n//\t\tlong sum = a;\n//\t\tint s = q;\n//\t\tfor (int i = 2; i <= s; i++) {\n//\t\t\ta = a*2+2;\n//\t\t\tsum += a;\n//\t\t}\n//\t\tSystem.out.println(sum);\n//\t\tSystem.out.println((4*((long)Math.pow(2, s)-1)-2*s));\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint k = nextInt();\n\t\tlong t = (long)(n-m) * k;\n\t\tint mod = (int) (1e9+9);\n\t\tlong ans = 0;\n\t\tint x = m / (k-1);\n\t\tif (m % (k-1) != 0)\n\t\t\tx++;\n\t\tif (n-m < x-1) {\n\t\t\tint s = (int) (n - t);\n\t\t\tint cnt = s / k;\n\t\t\tans = BigInteger.valueOf(2).modPow(BigInteger.valueOf(cnt+1), BigInteger.valueOf(mod)).longValue();\n\t\t\tans = (ans-2+mod) % mod;\n//\t\t\tans = ans * 4 % mod;\n//\t\t\tans = (ans-2*cnt+2*mod) % mod;\n\t\t\tans = ans * k % mod;\n\t\t\tans = (ans+(long)(k-1) * (n-m) % mod) % mod;\n\t\t\tans = (ans+s % k) % mod;\n\t\t}\n\t\telse\n\t\t\tans = m;\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\t\n\tprivate static long nextLong() throws IOException{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate static double nextDouble() throws IOException{\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tprivate 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", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\n// Solution is at the bottom of code\n\npublic class _____A implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tOutputWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new _____A(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tLocale.setDefault(Locale.US);\n\t\t\n\t\tif (ONLINE_JUDGE){\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new OutputWriter(System.out);\n\t\t}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new OutputWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\t////////////////////////////////////////////////////////////////\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (ONLINE_JUDGE){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t\ttime();\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tString delim = \" \";\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tok.nextToken(delim);\n\t}\n\t\n\tString readLine() throws IOException{\n\t\treturn in.readLine();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tfinal char NOT_A_SYMBOL = '\\0';\n\t\n\tchar readChar() throws IOException{\n\t\tint intValue = in.read();\n\t\t\n\t\tif (intValue == -1){\n\t\t\treturn NOT_A_SYMBOL;\n\t\t}\n\t\t\n\t\treturn (char) intValue;\n\t}\n\t\n\tchar[] readCharArray() throws IOException{\n\t\treturn readLine().toCharArray();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tint[] readIntArray(int size) throws IOException{\n\t\tint[] array = new int[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readInt();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tlong[] readLongArray(int size) throws IOException{\n\t\tlong[] array = new long[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readLong();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tdouble[] readDoubleArray(int size) throws IOException{\n\t\tdouble[] array = new double[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readDouble();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tPoint readPoint() throws IOException{\n\t\tint x = readInt();\n\t\tint y = readInt();\n\t\treturn new Point(x, y);\n\t}\n\t\n\tPoint[] readPointArray(int size) throws IOException{\n\t\tPoint[] array = new Point[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readPoint();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tList<Integer>[] readGraph(int vertexNumber, int edgeNumber)\n\tthrows IOException{\n\t\tList<Integer>[] graph = new List[vertexNumber];\n\t\t\n\t\tfor (int index = 0; index < vertexNumber; ++index){\n\t\t\tgraph[index] = new ArrayList<Integer>();\n\t\t}\n\t\t\n\t\twhile (edgeNumber-- > 0){\n\t\t\tint from = readInt() - 1;\n\t\t\tint to = readInt() - 1;\n\t\t\t\n\t\t\tgraph[from].add(to);\n\t\t\tgraph[to].add(from);\n\t\t}\n\t\t\n\t\treturn graph;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tclass OutputWriter extends PrintWriter{\n\n\t\tfinal int DEFAULT_PRECISION = 12;\n\t\t\n\t\tint precision;\n\t\tString format, formatWithSpace;\n\t\t\n\t\t{\n\t\t\tprecision = DEFAULT_PRECISION;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tpublic OutputWriter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\n\t\tpublic OutputWriter(String fileName) throws FileNotFoundException {\n\t\t\tsuper(fileName);\n\t\t}\n\t\t\n\t\tpublic int getPrecision() {\n\t\t\treturn precision;\n\t\t}\n\n\t\tpublic void setPrecision(int precision) {\n\t\t\tthis.precision = precision;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tprivate String createFormat(int precision){\n\t\t\treturn \"%.\" + precision + \"f\";\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void print(double d){\n\t\t\tprintf(format, d);\n\t\t}\n\t\t\n\t\tpublic void printWithSpace(double d){\n\t\t\tprintf(formatWithSpace, d);\n\t\t}\n\n\t\tpublic void printAll(double...d){\n\t\t\tfor (int i = 0; i < d.length - 1; ++i){\n\t\t\t\tprintWithSpace(d[i]);\n\t\t\t}\n\t\t\t\n\t\t\tprint(d[d.length - 1]);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void println(double d){\n\t\t\tprintlnAll(d);\n\t\t}\n\t\t\n\t\tpublic void printlnAll(double... d){\n\t\t\tprintAll(d);\n\t\t\tprintln();\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tint[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; \n\tint[][] steps8 = {\n\t\t\t{-1, 0}, {1, 0}, {0, -1}, {0, 1},\n\t\t\t{-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n\t};\n\t\n\tboolean check(int index, int lim){\n\t\treturn (0 <= index && index < lim);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tboolean checkBit(int mask, int bitNumber){\n\t\treturn (mask & (1 << bitNumber)) != 0;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tlong md = (1000 * 1000 * 1000 + 9);\n\t\n\tvoid solve() throws IOException{\n\t\tint n = readInt();\n\t\tint m = readInt();\n\t\tint k = readInt();\n\t\t\n\t\tlong count = n / k;\n\t\tlong mod = n % k;\n\t\t\n\t\tlong maxM = count * (k - 1) + mod;\n\t\tif (maxM >= m) {\n\t\t\tout.println(m % md);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong d = m - maxM;\n\t\tlong mul = (binpow(2, d) - 1 + md) % md * 2 % md;\n\t\t\n\t\tlong ans = (mul * k) % md;\n\t\tans = (ans + ((count - d) * (k - 1) % md + md) % md + mod) % md;\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tlong binpow(long a, long n) {\n\t\tif (n == 0) return 1;\n\t\tif ((n & 1) == 0) {\n\t\t\tlong b = binpow(a, n >> 1);\n\t\t\treturn (b * b) % md;\n\t\t} else {\n\t\t\treturn binpow(a, n - 1) * a % md;\n\t\t}\n\t}\n}\n\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\tprivate static Scanner in;\n\t\n\tfinal int M = 1000000009;\n\n\tpublic void run() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint z = n - m;\n\t\tif (z >= n / k) {\n\t\t\tSystem.out.println(m);\n\t\t\treturn;\n\t\t}\n\t\tint f = n - k * z;\n\t\tint last = f % k + (k - 1) * z;\n\t\tf /= k;\n\t\tint ans = BigInteger.ONE.shiftLeft(f + 1).remainder(BigInteger.valueOf(M)).intValue();\n\t\tSystem.out.println(((ans + M - 2L) * k + last) % M);\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 A().run();\n\t\tin.close();\n\t}\n}\n", "complexity": "logn", "problem": "338_A. Quiz", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class CFC {\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() throws IOException {\n        long x = nextLong();\n        long k = nextLong();\n        if (x == 0) {\n            outln(0);\n            return;\n        }\n        x %= MOD;\n        long two = powMod(2, k, MOD);\n        long res = two;\n        res *= 2;\n        res %= MOD;\n        res *= x;\n        res %= MOD;\n        res -= two - 1;\n        while (res < 0) {\n            res += MOD;\n        }\n        while (res >= MOD) {\n            res -= MOD;\n        }\n\n        outln(res);\n    }\n\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    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    private void outln(Object o) {\n        out.println(o);\n    }\n    private void out(Object o) {\n        out.print(o);\n    }\n    public CFC() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\n    }\n    public static void main(String[] args) throws IOException {\n        new CFC();\n    }\n\n    public long[] nextLongArr(int n) throws IOException{\n        long[] res = new long[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextLong();\n        return res;\n    }\n    public int[] nextIntArr(int n) throws IOException {\n        int[] res = new int[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextInt();\n        return res;\n    }\n    public String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return null;\n            }\n        }\n        return st.nextToken();\n    }\n    public String nextString() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            eof = true;\n            return null;\n        }\n    }\n    public int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n    public long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n    public double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class R489C {\n\tstatic long MOD=(long)1e9+7;\n\tpublic static void main(String[] args) {\n\t\tScanner scan=new Scanner(System.in);\n\t\tlong n=scan.nextLong(), k=scan.nextLong();\n\t\tif(n==0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong x=2*n-1;\n\t\tlong e=exp(2,k);\n\t\tSystem.out.println((x%MOD*e%MOD+1)%MOD);\n\t}\n\tpublic static long exp(long x, long e) {\n\t\tlong res=1;     \n\n\t\twhile (e>0)\t{\n\t\t\tif(e%2==1) res=(res*x)%MOD;\n\t\t\t\n\t\t\te/=2;\n\t\t\tx=(x*x)%MOD;\n\t\t}\n\t\treturn res;\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tlong n = scn.nextLong(), k = scn.nextLong(), mod = (int)1e9 + 7;\n\t\tif(n == 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tn %= mod;\n\t\tlong x = (pow(2, k + 1, mod) * n) % mod;\n\t\tlong y = (pow(2, k, mod) + mod - 1) % mod;\n\t\t\n\t\tlong ans = ((x - y) % mod + mod) % mod;\n\t\tout.println(ans);\n\t}\n\t\n\tlong pow(long a, long x, long m) {\n\t\tif(x == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong p = pow(a, x / 2, m);\n\t\tp *= p;\n\t\tp %= m;\n\t\tif(x % 2 == 1) {\n\t\t\tp *= a;\n\t\t\tp %= m;\n\t\t}\n\t\treturn p;\n\t}\n\t\n\tlong gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tvoid run() throws Exception {\n\t\tboolean onlineJudge = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tout = new PrintWriter(System.out);\n\t\tscn = new FastReader(onlineJudge);\n\t\tlong time = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!onlineJudge) {\n\t\t\tSystem.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + \" ms\" }));\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tclass FastReader {\n\t\tInputStream is;\n\n\t\tpublic FastReader(boolean onlineJudge) {\n\t\t\tis = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\t}\n\n\t\tbyte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\t\tint readByte() {\n\t\t\tif (lenbuf == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (ptrbuf >= lenbuf) {\n\t\t\t\tptrbuf = 0;\n\t\t\t\ttry {\n\t\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (lenbuf <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn inbuf[ptrbuf++];\n\t\t}\n\n\t\tboolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tint skip() {\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t\t;\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tchar nextChar() {\n\t\t\treturn (char) skip();\n\t\t}\n\n\t\tString next() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\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[] nextArray(int n, boolean isOneInd) {\n\t\t\tint k = isOneInd ? 1 : 0;\n\t\t\tint[] a = new int[n + k];\n\t\t\tfor (int i = k; i < n + k; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tint[] shuffle(int[] arr) {\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 1, j; i < arr.length; i++) {\n\t\t\t\tj = r.nextInt(i);\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t\tarr[j] = arr[i] ^ arr[j];\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/**\n * Created by aditya on 5/3/17.\n */\npublic class Main3 {\n\n    static long x, k;\n    static long MOD = (long)1e9 + 7;\n\n    public static void main(String args[]) throws Exception{\n        FastInput fi = new FastInput(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        x = fi.nextLong();\n        k = fi.nextLong();\n\n        if(x == 0) {\n            System.out.println(0);\n            return;\n        }\n\n//        System.out.println(pow(2, k+1));\n        long q1 = (pow(2, k+1) * (x%MOD)) % MOD;\n        long q2 = pow(2, k);\n        long q3 = 1;\n//        System.out.println(q1);\n//        System.out.println(q2);\n//        System.out.println(q3);\n\n\n        long exp = (q1-q2 + MOD + MOD)%MOD;\n        exp = (exp + q3)%MOD;\n\n//        exp = (exp*2)%MOD;\n\n        pw.println(exp);\n\n        pw.close();\n    }\n\n    static long pow(long n, long k) {\n        if(k == 0)\n            return 1;\n        if(k == 1)\n            return n;\n        long ret = pow(n, k/2)%MOD;\n        ret = (ret*ret)%MOD;\n        if(k%2 == 1)\n            ret = (ret*n)%MOD;\n\n        return ret;\n    }\n\n    static class FastInput {\n\n        private Reader in;\n        private BufferedReader br;\n        private StringTokenizer st;\n\n        public FastInput(Reader in) {\n            this.in=in;\n            br = new BufferedReader(in);\n        }\n\n        public String nextString() {\n\n            while(st==null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                }\n                catch (IOException e) {\n                    System.out.println(e.getStackTrace());\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(nextString());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(nextString());\n        }\n\n        public double nextDouble() {\n\n            return Double.parseDouble(nextString());\n        }\n\n    }\n\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n    public static void main(String[] args) throws IOException {\n        init(System.in);\n        BigInteger x = new BigInteger(next());\n        if (x.compareTo(BigInteger.ZERO) == 0) {\n            System.out.println(0);\n            return;\n        }\n        BigInteger k = new BigInteger(next());\n        BigInteger mod = new BigInteger(\"1000000007\");\n        BigInteger two = BigInteger.ONE.add(BigInteger.ONE);\n        BigInteger ans = two.modPow(k, mod);\n        ans = ans.multiply(two.multiply(x).subtract(BigInteger.ONE)).add(BigInteger.ONE).mod(mod);\n        System.out.println(ans);\n    }\n\n    //Input Reader\n    private static BufferedReader reader;\n    private static StringTokenizer tokenizer;\n\n    private static void init(InputStream inputStream) {\n        reader = new BufferedReader(new InputStreamReader(inputStream));\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    private static String next() throws IOException {\n        String read;\n        while (!tokenizer.hasMoreTokens()) {\n            read = reader.readLine();\n            if (read == null || read.equals(\"\"))\n                return \"-1\";\n            tokenizer = new StringTokenizer(read);\n        }\n\n        return tokenizer.nextToken();\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//    //    Get a whole line.\n//    private static String line() throws IOException {\n//        return reader.readLine();\n//    }\n//\n//    private static double nextDouble() throws IOException {\n//        return Double.parseDouble(next());\n//    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class C {\n    String fileName = \"<name>\";\n\n    public static final int MOD = (int) (1e9 + 7);\n\n    public void solve() throws IOException {\n        long x = nextLong();\n        if (x == 0) {\n            out.print(0);\n            return;\n        }\n        long k = nextLong();\n        BigInteger power = BigInteger.valueOf(2)\n                .modPow(BigInteger.valueOf(k), BigInteger.valueOf(MOD));\n        BigInteger r = BigInteger.valueOf(x).multiply(power);\n        BigInteger l = r.subtract(power).add(BigInteger.ONE);\n        out.print(l.add(r).mod(BigInteger.valueOf(MOD)));\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 C().run();\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class test {\n    static boolean DEBUG_FLAG = false;\n    int INF = (int)1e9;\n    long MOD = 1000000007;\n    \n    static void debug(String s) {\n        if(DEBUG_FLAG) {\n            System.out.print(s);\n        }\n    }\n    \n    long pow(long a, long n, long mod) {\n        if (n == 0) {\n            return 1;\n        }\n        long rs = 1;\n        while (n != 0) {\n            if (n % 2 == 1) {\n                rs *= a;\n            }\n            rs %= mod;\n            n >>= 1;\n            a *= a;\n            a %= mod;\n        }\n        return rs;\n    }\n    \n    void solve(InputReader in, PrintWriter out) throws IOException {\n        long x = in.nextLong();\n        long k = in.nextLong();\n        if(x==0) {\n            out.println(0);\n            return;\n        }\n        long a = (2 * x - 1) % MOD;\n        long b = pow(2, k, MOD);\n        a = (a * b) % MOD;\n        a += 1;\n        a %= MOD;\n        out.println(a);\n    }\n    \n    \n    public static void main(String[] args) throws IOException {\n        if(args.length>0 && args[0].equalsIgnoreCase(\"d\")) {\n            DEBUG_FLAG = true;\n        }\n        InputReader in = new InputReader();\n        PrintWriter out = new PrintWriter(System.out);\n        int t = 1;//in.nextInt();\n        long start = System.nanoTime();\n        while(t-- >0) {\n            new test().solve(in, out);\n        }\n        long end = System.nanoTime();\n        debug(\"\\nTime: \" + (end-start)/1e6 + \" \\n\\n\");\n        out.close();\n    }\n    \n    static class InputReader {\n        static BufferedReader br;\n        static StringTokenizer st;\n    \n        public InputReader() {\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Dummy {\n  private static long mod = 1000000007;\n  public static void main(String[] args) throws IOException {\n    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    String[] strs = reader.readLine().split(\" \");\n    long x = Long.parseLong(strs[0]);\n    long k = Long.parseLong(strs[1]);\n    long twoPK = modPow(2, k);\n    long twoPK_1 = (twoPK * 2) % mod;\n    long res = ((twoPK_1 * (x % mod)) % mod - (twoPK - 1) + mod) % mod;\n    System.out.println(x == 0? x: res);\n  }\n\n  private static long modPow(long base, long pow) {\n    long res = 1;\n    while(pow != 0) {\n      if((pow & 1) != 0) {\n        res = (res % mod * base % mod)%mod;\n      }\n      base = (base % mod * base % mod) % mod;\n      pow >>= 1;\n    }\n    return res;\n  }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A992{\n\t\n\tlong mod = 1000000007L;\n\t\n\tprivate void solve() throws Exception {\n\t\tlong x = nextLong();\n\t\tlong k = nextLong();\n\t\tif(x == 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tx = x%mod;\n\t\tlong res = (((x*pow(2,k+1))%mod + (mod-pow(2,k))%mod)%mod+1)%mod;    \n\t\tout.println(res);\n\t}\n\t\n\tlong pow(long m, long n){\n\t    long res = 1;\n\t    while(n > 0){\n\t        if(n % 2 == 1)res = (res*m)%mod;\n\t        m = (m*m)%mod;\n\t        n = n/2;\n\t    }\n\t    return res;\n\t} \n\t\n\tpublic static void main(String[] args) {\n\t\t(new A992()).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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "//package CF489; //comment this line\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class B\n{\n    private static long MOD=1000000007;\n    private static BigInteger m=new BigInteger(1000000007+\"\");\n    \n    private static long pow(long x, long a)\n    {\n        if(a==0)\n        return 1;\n        \n        long ans=pow(x,a/2);\n        \n        ans=(ans*ans)%MOD;\n        \n        if(a%2==1)\n        ans=(ans*x)%MOD;\n        \n        return ans%MOD;\n    }\n    public static void main(String args[]) throws IOException\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        \n        long N,K,ans;\n        \n        //System.out.println(); //comment this line\n        String s[]=br.readLine().trim().split(\" \");\n        \n        N=Long.parseLong(s[0]);\n        K=Long.parseLong(s[1]);\n        \n        BigInteger bi=new BigInteger(N+\"\");\n        BigInteger a=new BigInteger(N+\"\");\n        BigInteger two=new BigInteger(2+\"\");\n        \n        if(N==0)\n        {\n            System.out.println(0);\n            System.exit(0);\n        }\n        if(K==0)\n        {\n            a=a.multiply(two);\n            a=a.mod(m);\n            \n            System.out.println(a);\n            System.exit(0);\n        }\n        \n        long p=pow(2,K);\n        \n        BigInteger p2=new BigInteger(p+\"\");\n        BigInteger tmp=p2.subtract(BigInteger.ONE);\n        tmp=tmp.mod(m);\n        \n        p2=p2.multiply(two);\n        p2=p2.mod(m);\n        \n        a=a.multiply(p2);\n        a=a.mod(m);\n        \n        a=a.subtract(tmp);\n        a=a.mod(m);\n        \n        if(!(a.signum()==1)&&!(a.signum()==0))\n        a.add(m);\n        \n        System.out.println(a);\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic static void quickSort(int[] a, int from, int to) {\n\t\tif (to - from <= 1) {\n\t\t\treturn;\n\t\t}\n\t\tint i = from;\n\t\tint j = to - 1;\n\t\tint x = a[from + (new Random()).nextInt(to - from)];\n\t\twhile (i <= j) {\n\t\t\twhile (a[i] < x) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (a[j] > x) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i <= j) {\n\t\t\t\tint t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t\ti++;\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\t\tquickSort(a, from, j + 1);\n\t\tquickSort(a, j + 1, to);\n\t}\n\n\tlong mod = 1000000007;\n\n\tpublic long pow(long k) {\n\t\tif (k == 0) {\n\t\t\treturn 1L;\n\t\t}\n\t\tif (k == 1) {\n\t\t\treturn 2L;\n\t\t}\n\t\tif (k % 2 == 1) {\n\t\t\treturn (2L * pow(k - 1)) % mod;\n\t\t}\n\t\tlong x = pow(k / 2);\n\t\treturn (x * x) % mod;\n\t}\n\n\tpublic void solve() {\n\t\tlong x = in.nextLong();\n\t\tif (x == 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tx %= mod;\n\t\tlong k = in.nextLong();\n\t\tlong pow = pow(k);\n\t\tlong ans = 1;\n\t\tans = (ans - pow + mod) % mod;\n\t\tans = (ans + (((2 * pow) % mod) * x) % mod) % mod;\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (systemIO) {\n\t\t\t\tin = new FastScanner(System.in);\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t} else {\n\t\t\t\tin = new FastScanner(new File(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t\t}\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tFastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString nextLine() {\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t}\n\n\t// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n\tpublic static void main(String[] args) {\n\t\tnew C().run();\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\n/*\n * Author    : joney_000[jaswantsinghyada007@gmail.com]\n * Algorithm : N/A\n * Platform  : Codeforces\n * Ref       : \n */\n\npublic class A{ \n  \n  private InputStream inputStream ;\n  private OutputStream outputStream ;\n  private FastReader in ;\n  private PrintWriter out ;\n  \n  private final int BUFFER = 100005;\n  private final long mod = 1000000000+7;\n  private final int  INF  = Integer.MAX_VALUE;\n  private final long INF_L  = Long.MAX_VALUE / 10;\n\n  public A(){}\n  public A(boolean stdIO)throws FileNotFoundException{\n    // stdIO = false;\n    if(stdIO){\n      inputStream = System.in;\n      outputStream = System.out;\n    }else{\n      inputStream = new FileInputStream(\"input.txt\");\n      outputStream = new FileOutputStream(\"output.txt\");\n    }\n    in = new FastReader(inputStream);\n    out = new PrintWriter(outputStream);\n  }\n  \n  void run()throws Exception{\n    long x = l(); long k = l();\n    if(x == 0){\n      out.write(\"0\");\n      return;\n    }\n    x %= mod;\n    long a = (x * pow(2L, k, mod) + mod)%mod;\n    long b = (a - pow(2L, k, mod) + 1 + mod)%mod;\n    long res = (a + b + mod )%mod;\n    out.write(\"\"+res+\"\\n\");\n  }\n\n  long gcd(long a, long b){\n    if(b == 0)return a;\n    return gcd(b, a % b);\n  }\n\n  long lcm(long a, long b){\n    if(a == 0 || b == 0)return 0;\n    return (a * b)/gcd(a, b);\n  }\n\n  long mulMod(long a, long b, long mod){\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\n  long pow(long a, long b, long mod){\n    if(b == 0)return 1;\n    if(b == 1)return a;\n    long ans = pow(a, b/2, mod);\n    ans = (ans * ans);\n    if(ans >= mod)ans %= mod;\n\n    if(b % 2 == 1)ans = (a * ans);\n    if(ans >= mod)ans %= mod;\n\n    return ans;\n  }\n\n  // 20*20   nCr Pascal Table\n  long[][] ncrTable(){\n    long ncr[][] = new long[21][21];\n\n    for(int i = 0; i <= 20; i++){\n      ncr[i][0] = ncr[i][i] = 1L;\n    }\n\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\n    return ncr;\n  }\n\n  int i()throws Exception{\n    return in.nextInt();\n  }\n\n  long l()throws Exception{\n    return in.nextLong();\n  }\n\n  double d()throws Exception{\n    return in.nextDouble();\n  }\n\n  char c()throws Exception{\n    return in.nextCharacter();\n  }\n\n  String s()throws Exception{\n    return in.nextLine();\n  }\n\n  BigInteger bi()throws Exception{\n    return in.nextBigInteger();\n  }\n\n  private void closeResources(){\n    out.flush();\n    out.close();\n    return;\n  }\n\n//  IMP: roundoff upto 2 digits \n//  double roundOff = Math.round(a * 100.0) / 100.0;\n//                    or\n//  System.out.printf(\"%.2f\", val);\n\n//  print upto 2 digits after decimal\n//  val = ((long)(val * 100.0))/100.0;    \n\n  public static void main(String[] args) throws java.lang.Exception{\n  \n    A driver = new A(true);\n    driver.run();\n    driver.closeResources();\n  }\n}\n\nclass FastReader{\n\n  private boolean finished = false;\n\n  private InputStream stream;\n  private byte[] buf = new byte[4 * 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\nclass Pair implements Comparable<Pair>{\n  public int a;\n  public int b;\n  public int c;\n\n  public Pair(){\n    this.a = 0;\n    this.b = 0;\n    this.c = 0;\n  }\n\n  public Pair(int a,int b, int c){\n    this.a = a;\n    this.b = b;\n    this.c = c;\n  }\n\n  public int compareTo(Pair p){\n   return this.c - p.c; \n  }\n\n  @Override\n  public String toString(){\n    return \"a = \" + this.a + \" b = \" + this.b + \" c = \"+this.c;\n  }\n} ", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 modulo = new BigInteger(\"1000000007\");\n        BigInteger ans = two.modPow(k.add(one),modulo);\n        ans = ans.multiply(x);\n        ans = ans.subtract(two.modPow(k,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        ", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\n//package que_a;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n    InputStream is;\n    PrintWriter out;\n    \n    long mod = (long) (1e9 + 7);\n    boolean SHOW_TIME;\n    \n    void solve() {\n        //Enter code here utkarsh\n        //SHOW_TIME = true;\n        long X = nl();\n        BigInteger x = BigInteger.valueOf(X);\n        long K = nl();\n        BigInteger k = BigInteger.valueOf(K);\n        BigInteger MOD = BigInteger.valueOf(mod);\n        \n        if(X == 0) {\n            out.println(0); return;\n        }\n        if(k.compareTo(BigInteger.ZERO) == 0) {\n            out.println((x.add(x)).mod(MOD));   return;\n        }\n        \n        BigInteger p = BigInteger.valueOf(modpow(2, K, mod));\n        BigInteger ans = x.multiply(p);\n        ans = ans.add(ans);\n        ans = ans.subtract(p).add(BigInteger.ONE);\n        ans = ans.add(MOD);\n        out.println(ans.mod(MOD));\n    }\n    \n    long modpow(long b, long e, long mod) {\n        b %= mod;\n        long r = 1;\n        while(e > 0) {\n            if((e & 1) == 1) {\n                r *= b; r %= mod;\n            }\n            b *= b; b %= mod;\n            e >>= 1;\n        }\n        return r;\n    }\n\n    //---------- I/O Template ----------\n    \n    public static void main(String[] args) { new utkarsh().run(); }\n    void run() { \n        is = System.in; \n        out = new PrintWriter(System.out);\n        long start = System.currentTimeMillis(); \n        solve(); \n        long end = System.currentTimeMillis();\n        if(SHOW_TIME) out.println(\"\\n\" + (end - start) + \" ms\");\n        out.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte() { \n        if(ptr >= len) { ptr = 0; \n            try { len = is.read(input); } \n            catch(IOException e) { throw new InputMismatchException(); } \n            if(len <= 0) { return -1; } \n        } return input[ptr++];\n    }\n    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n    int skip() { \n        int b = readByte(); \n        while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n        return b;\n    }\n    \n    char nc() { return (char)skip(); }\n    String ns() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    String nLine() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    int ni() { \n        int n = 0, b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        if(b == -1) { return -1; }  //no input \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n    long nl() { \n        long n = 0L;    int b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n\n    double nd() { return Double.parseDouble(ns()); }\n    float nf() { return Float.parseFloat(ns()); }\n    int[] na(int n) { \n        int a[] = new int[n]; \n        for(int i = 0; i < n; i++) { a[i] = ni(); } \n        return a;\n    }\n    char[] ns(int n) { \n        char c[] = new char[n]; \n        int i, b = skip(); \n        for(i = 0; i < n; i++) { \n            if(isSpaceChar(b)) { break; } \n            c[i] = (char)b; b = readByte(); \n        } return i == n ? c : Arrays.copyOf(c,i);\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new C(), \"_cf\", 1 << 28).start();}\n\n\tlong MOD = (long)1e9+7;\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\tlong x = fs.nextLong();\n\t\tlong k = fs.nextLong();\n\t\tif(x == 0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif(k == 0) {\n\t\t\tSystem.out.println(mult(x, 2));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong max = mult(x, power(2, k, MOD));\n\t\tlong min = sub(max, power(2, k, MOD));\n\t\tlong total = 0;\n\t\tif(min <= max) {\n\t\t\ttotal = sub(summ(max), summ(min));\n\t\t}\n\t\telse {\n\t\t\ttotal = summ(max);\n\t\t\ttotal = add(total, sub(summ(MOD-1), summ(min)));\n\t\t}\n\t\ttotal = mult(total, 2);\n\t\ttotal = div(total, power(2, k, MOD));\n\t\tout.println(total);\n\t\tout.close();\n\t}\n\t\n\tlong summ(long x) {\n\t\tx *= x+1;\n\t\tx /= 2;\n\t\tx %= MOD;\n\t\treturn x;\n\t}\n\n\tlong add(long a, long b) {\n\t\ta %= MOD;\n\t\tb %= MOD;\n\t\ta += b;\n\t\ta %= MOD;\n\t\treturn a;\n\t}\n\t\n\tlong sub(long a, long b) {\n\t\ta %= MOD;\n\t\tb %= MOD;\n\t\ta -= b;\n\t\twhile(a < 0) a += MOD;\n\t\ta %= MOD;\n\t\treturn a;\n\t}\n\t\n\tlong mult(long a, long b) {\n\t\ta %= MOD;\n\t\tb %= MOD;\n\t\ta *= b;\n\t\ta %= MOD;\n\t\treturn a;\n\t}\n\t\n\tlong div(long a, long b) {\n\t\ta %= MOD;\n\t\tb %= MOD;\n\t\ta *= inv(b);\n\t\ta %= MOD;\n\t\treturn a;\n\t}\n\t\n\tlong inv(long x) {\n\t\tlong res = power(x, MOD-2, MOD);\n\t\twhile(res < 0) res += MOD;\n\t\tres %= MOD;\n\t\treturn res;\n\t}\n\t\n\tlong power (long x, long y, long m) {\n    \tlong res = 1;\n    \tx %= m;\n    \twhile(y > 0) {\n    \t\tif(y % 2 == 1) {\n    \t\t\tres = (res * x) % m;\n    \t\t}\n    \t\ty >>= 1L;\n    \t\tx = (x * x) % m;\n    \t}\n    \treturn res;\n    }\n\t\n\tvoid sort (int[] a) {\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < 50; i++) {\n\t\t\tRandom r = new Random();\n\t\t\tint x = r.nextInt(n), y = r.nextInt(n);\n\t\t\tint temp = a[x];\n\t\t\ta[x] = a[y];\n\t\t\ta[y] = temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}                \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\n\npublic class C {\n\n    private static Solver solver = new Solver();\n\n    private static long m = 1000000000L + 7L;\n\n    public static void main(String[] args) throws IOException {\n        solver.withProcedure(() -> {\n            String[] input = solver.readString().split(\" \");\n            BigInteger x = new BigInteger(input[0]);\n            BigInteger k = new BigInteger(input[1]);\n\n            if (x.compareTo(BigInteger.ZERO) == 0) {\n                solver.println(\"\" + 0);\n                return;\n            }\n\n            BigInteger two = BigInteger.valueOf(2);\n\n            BigInteger mm = BigInteger.valueOf(m);\n            BigInteger binpowedK = two.modPow(k, mm);\n            BigInteger binpowedKPlusOne = two.modPow(k.add(BigInteger.ONE), mm);\n\n            BigInteger res = binpowedKPlusOne.multiply(x).subtract(binpowedK.subtract(BigInteger.ONE)).mod(mm);\n\n            if (res.compareTo(BigInteger.ZERO) < 0) {\n                res = BigInteger.ZERO;\n            }\n\n            solver.println(\"\" + res);\n        }).solve();\n    }\n\n    private static long binpow(long a, long n) {\n        a = a % m;\n\n        long res = 1L;\n        while (n > 0) {\n            if ((n & 1L) != 0)\n                res = (res * a) % m;\n\n            a = (a * a) % m;\n            n >>= 1L;\n        }\n\n        return res;\n    }\n\n\n    @FunctionalInterface\n    private interface Procedure {\n        void run() throws IOException;\n    }\n\n    private static class Solver {\n        private Procedure procedure;\n\n        private StreamTokenizer in;\n        private PrintWriter out;\n        private BufferedReader bufferedReader;\n\n        Solver() {\n            try {\n                boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\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\n                bufferedReader = new BufferedReader(reader);\n                in = new StreamTokenizer(bufferedReader);\n                out = new PrintWriter(writer);\n            } catch (Exception e) {\n                throw new RuntimeException(\"Initialization has failed\");\n            }\n        }\n\n        void solve() throws IOException {\n            procedure.run();\n        }\n\n        int readInt() throws IOException {\n            in.nextToken();\n            return (int) in.nval;\n        }\n\n        long readLong() throws IOException {\n            in.nextToken();\n            return (long) in.nval;\n        }\n\n        String readString() throws IOException {\n            return bufferedReader.readLine();\n        }\n\n        char readChar() throws IOException {\n            in.nextToken();\n            return in.sval.charAt(0);\n        }\n\n        void println(String str) {\n            out.println(str);\n            out.flush();\n        }\n\n        void print(String str) {\n            out.print(str);\n            out.flush();\n        }\n\n        Solver withProcedure(Procedure procedure) {\n            this.procedure = procedure;\n\n            return this;\n        }\n    }\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class R489C {\n\t\n\tstatic long m = (long)(1e9+7);\n\t/*\n\t1000000000000000000\n\t */\n\n\tpublic static void main(String[] args) {\n\t\tJS scan = new JS();\n\t\tlong n = scan.nextLong();\n\t\tlong k = scan.nextLong();\n\t\tif(n == 0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif(k == 0) {\n\t\t\tlong ans = (n%m)*(2%m)%m;\n\t\t\tSystem.out.println(ans%m);\n\t\t\treturn;\n\t\t}\n\t\t//System.out.println(2+\" \"+(k+1)+\" \"+m);\n\t\tlong coeff = power(2L, k+1, m);\n\t\t//System.out.println(coeff);\n\t\tlong r = (coeff%m)*(n%m)%m;\n\t\t//System.out.println(r);\n\t\tlong x = power(2L, k, m)%m-1;\n\t\tif(x < 0) x += m;\n\t\tlong ans = r-x;\n\t\tif(ans < 0) ans += m;\n\t\tSystem.out.println(ans%m);\n\t}\n\t\n\tstatic long power(long x, long y, long p){\n        // Initialize result\n\t\tlong res = 1;     \n       \n        // Update x if it is more  \n        // than or equal to p\n        x = x % p; \n    \n        while (y > 0){\n            // If y is odd, multiply x\n            // with result\n            if((y & 1)==1)\n                res = (res%p * x%p) % p;\n    \n            // y must be even now\n            // y = y / 2\n            y = y >> 1; \n            x = (x%p * x%p) % p; \n        }\n        return res;\n    }\n\t\n\t/*\n\t1000000000000000000 1000000000000000000\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\n\t\tpublic JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic JS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}\t\t\t\t\n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\npublic class Solution1 {\n\n    private void solve() throws IOException {\n        long MOD = 1_000_000_007;\n        long x = in.nextLong();\n        long k = in.nextLong();\n        if (x == 0) {\n            System.out.println(0);\n            return;\n        }\n        long val = binpow(2, k + 1, MOD) % MOD;\n        long kek = (binpow(2, k, MOD) - 1 + MOD) % MOD;\n        x = (val % MOD) * (x % MOD) % MOD;\n        long ans = (x % MOD - kek % MOD + MOD) % MOD;\n        System.out.println(ans % MOD);\n    }\n\n    private long binpow(long a, long n, long mod) {\n        long res = 1;\n        while (n > 0) {\n            if (n % 2 == 1)\n                res = (res % mod) * (a % mod) % mod;\n            a = (a % mod) * (a % mod) % mod;\n            n >>= 1;\n        }\n        return res % mod;\n    }\n\n\n\n    private PrintWriter out;\n    private 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        }\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 Solution1().run();\n    }\n}\n\n\n\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "/**\n * Created by Baelish on 6/18/2018.\n */\n\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 C_3 {\n    public static void main(String[] args) throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n\n        long mod = (long) 1e9 + 7;\n\n        long xx = in.nextLong(), kk = in.nextLong();\n\n        if(xx == 0){\n            pw.println(0); pw.close();\n            return;\n        }\n\n        BigInteger x = BigInteger.valueOf(xx), k = BigInteger.valueOf(kk);\n\n       // long a = bigMod(2, k+1, mod );long b = bigMod(2, k, mod);\n\n        BigInteger MOD = BigInteger.valueOf(mod);\n        BigInteger a = BigInteger.valueOf(2).modPow(BigInteger.valueOf(kk+1), MOD);\n        BigInteger b = BigInteger.valueOf(2).modPow(BigInteger.valueOf(kk), MOD);\n\n\n        BigInteger s = (a.multiply(x)).mod(MOD);\n        s = s.subtract(b.mod(MOD));\n        s = s.add(BigInteger.ONE);\n        s = s.mod(MOD);\n        s = s.add(MOD);\n        s = s.mod(MOD);\n\n       // debug(a, b, x);\n\n       // long s = ((a * x) % mod - b % mod + 1 + mod) % mod;\n\n        pw.println(s);\n\n\n        pw.close();\n    }\n\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        static final int ints[] = new int[128];\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n\n        public FastReader(InputStream is) {\n            for (int i = '0'; i <= '9'; i++) ints[i] = i - '0';\n            this.is = is;\n        }\n\n        public 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        public boolean isSpaceChar(int c) {\n            return !(c >= 33 && c <= 126);\n        }\n\n        public int skip() {\n            int b;\n            while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n            return b;\n        }\n\n        public String next() {\n            int b = skip();\n            StringBuilder sb = new StringBuilder();\n            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n                sb.appendCodePoint(b);\n                b = readByte();\n            }\n            return sb.toString();\n        }\n\n        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = (num << 3) + (num << 1) + ints[b];\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public long nextLong() {\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 << 3) + (num << 1) + ints[b];\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n       /* public char nextChar() {\n            return (char)skip();\n        }*/\n\n        public 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        /*private char buff[] = new char[1005];\n        public char[] nextCharArray(){\n            int b = skip(), p = 0;\n            while(!(isSpaceChar(b))){\n                buff[p++] = (char)b;\n                b = readByte();\n            }\n            return Arrays.copyOf(buff, p);\n        }*/\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class A{\n\tstatic long mod = 1000000000+7;\n\tstatic int arr[];\n\tstatic HashMap<Long,Long> map = new HashMap<>();\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong x = scan.nextLong();\n\t\tlong k = scan.nextLong();\n\t\tif(x == 0)\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tx = x%mod;\n\t\tlong power = pow(2,k + 1)%mod;\n\t\tpower = (power*x)%mod;\n\t\tlong num = (pow(2,k) - 1 + mod)%mod;\n\t\tlong ans = (power - num + mod)%mod;\n\t\tSystem.out.println((ans));\n\t}\n\tpublic static long pow(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\tlong x1,x2;\n\t\tif(map.containsKey(b - b/2))\n\t\t\tx1 = map.get(b - b/2);\n\t\telse\n\t\t{\n\t\t\tx1 = pow(a,b - b/2)%mod;\n\t\t\tmap.put(b - b/2,x1);\n\t\t}\n\t\tif(map.containsKey(b/2))\n\t\t\tx2 = map.get(b/2);\n\t\telse\n\t\t{\n\t\t\tx2 = pow(a,b/2)%mod;\n\t\t\tmap.put(b/2,x2);\n\t\t}\n\t\treturn (x1*x2)%mod;\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n \n/* spar5h */\n\npublic class cf3 implements Runnable{    \n\t\n\tfinal static long mod = (long)1e9 + 7; \n\t\n\tstatic long modExp(long x, long pow) {\n\t\t\n\t\tx = x % mod;\n\t\t\n\t    long res = 1;      \n\t \n\t    while (pow > 0) {\n\t   \n\t        if (pow % 2 == 1)\n\t            res = res * x % mod;\n\t \n\t        pow = pow / 2;\n\t        x = x * x % mod;  \n\t    }\n\t    \n\t    return res;\n\t}\n\t\n\tpublic void run() {\n\t    \n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\t\n\t\tint t = 1; \n\t\t\n\t\twhile(t-- > 0) {\n\t\t\t\n\t\t\tlong x = s.nextLong(), k = s.nextLong();\n\t\t\t\n\t\t\tif(x == 0) {\n\t\t\t\tw.println(0); continue;\n\t\t\t}\n\t\t\t\n\t\t\tx = x % mod;\n\t\t\t\n\t\t\tlong res = (modExp(2, k + 1) * x % mod + 1) % mod;\n\t\t\tres = (res + mod - modExp(2, k)) % mod;\n\t\t\t\n\t\t\tw.println(res);\n\t\t}\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\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new cf3(),\"cf3\",1<<26).start();\n\t}\n}   \n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        _992C solver = new _992C();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class _992C {\n        static int mod = (int) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            long x = in.nextLong();\n            long k = in.nextLong();\n\n            if (x == 0) {\n                out.println(0);\n                return;\n            }\n\n            long[][] base = new long[][]{{2, 0}, {1, 1}};\n\n            _992C.Matrix.N = 2;\n\n            base = _992C.Matrix.matrixPower(base, base, k);\n\n            x %= mod;\n            long ans = 2 * base[0][0] * x - base[1][0];\n\n            ans %= mod;\n\n            if (ans < 0)\n                ans += mod;\n\n            out.println(ans);\n        }\n\n        static public class Matrix {\n            static int N;\n            static long[][] id = new long[][]{{1, 0}, {0, 1}};\n\n            static long[][] matrixPower(long[][] mat, long[][] base, long pow) {\n                if (pow == 0) {\n                    return id;\n                }\n                if (pow == 1) {\n                    return base;\n                }\n\n                long[][] t = matrixPower(mat, base, pow / 2);\n\n                t = multiplyMatrix(t, t);\n                if (pow % 2 == 1) {\n                    t = multiplyMatrix(t, base);\n                }\n\n                return t;\n            }\n\n            static long[][] multiplyMatrix(long[][] m, long[][] m2) {\n                long[][] ans = new long[N][N];\n\n                for (int i = 0; i < N; i++)\n                    for (int j = 0; j < N; j++) {\n                        ans[i][j] = 0;\n                        for (int k = 0; k < N; k++) {\n                            ans[i][j] += m[i][k] * m2[k][j];\n                            ans[i][j] %= mod;\n                        }\n                    }\n\n                return ans;\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        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 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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C\n{\t\n\tstatic long mod=(long)(1e9+7);\n\tpublic static long powMod(long e,long b)\n\t{\n\t\t/*e=e%mod;*/\n\t\tlong res=1;\n\t\t\n\t\twhile(e>0)\n\t\t{\n\t\t\tif(e%2==1)\n\t\t\t\tres=res*b%mod;\n\t\t\te/=2;\n\t\t\tb=b*b%mod;\n\t\t}\n\t\treturn res;\n\t}\n\n\t\tpublic static void main(String[] args) throws IOException \n\t\t{\n\t\t\tScanner sc=new Scanner(System.in);\n\t\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\t\tlong x=sc.nextLong(),k=sc.nextLong();\n\t\t\tif(x==0)\n\t\t\t{\n\t\t\t\tSystem.out.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif(k==0)\n\t\t\t{\n\t\t\t\tpw.println((2*x)%mod);\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tpw.close();return;\n\t\t\t}\n\t\t\t\n\t\t\tlong ans=2*x-1;\n\t\t\tans=ans%mod;\n\t\t\t\n\t\t\tlong b=powMod(k,2);\n\t\t\tans=((ans*b)+1)%mod;\n\t\t\t\n\t\t\t\n\t\t\tpw.println(ans);\n\t\t\t\n\t\t\tpw.close();\n\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\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\tbr = new BufferedReader(new InputStreamReader(s));\n\t\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\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\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\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class C{\n\tpublic static void main (String[] args) throws java.lang.Exception{\n\t\tScanner scan=new Scanner(System.in);\n\t\tlong x=scan.nextLong(), k=scan.nextLong();\n\t\tlong MOD = 1000000007;\n\t\tif(x==0){\n\t\t\tSystem.out.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\tx %= MOD;\n\t\tlong ans= (((new myC()).fastPow(2L, k+1)*x)%MOD - (new myC()).fastPow(2L, k) + MOD + 1)% MOD;\n\t\tans %= MOD;\n\t\tSystem.out.println(ans);\n\t}\n}\n\nclass myC{\n\tlong MOD = 1000000007;\n\tlong fastPow(long x, long k){\n\t\tlong bb=x%MOD, ans=1;\n\t\twhile(k > 0){\n\t\t\tif((k&1)==1){\n\t\t\t\tans=(ans*bb)%MOD;\n\t\t\t}\n\t\t\tbb=(bb*bb)%MOD;\n\t\t\tk>>=1;\n\t\t}\n\t\treturn ans;\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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_489C {\n\n\tstatic final long MOD = 1_000_000_007;\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\tlong st = Long.parseLong(inputData.nextToken());\n\t\tif(st == 0) {\n\t\t\tprinter.println(0);\n\t\t\tprinter.close();\n\t\t\treturn;\n\t\t}\n\t\tst %= MOD;\n\t\tlong years = Long.parseLong(inputData.nextToken());\n\t\tlong[][] res = exp(years);\n\t\tlong ans = (res[0][0] * st % MOD * 2 % MOD + res[0][1] * (-1 + MOD) % MOD) % MOD;\n\t\tprinter.println(ans);\n\t\tprinter.close();\n\t}\n\n\tstatic long[][] exp(long pow) {\n\t\tlong[][] cBase = base;\n\t\tlong[][] res = { { 1, 0 }, { 0, 1 } };\n\n\t\twhile (pow != 0) {\n\t\t\tif ((pow & 1) != 0) {\n\t\t\t\tres = mult(res, cBase);\n\t\t\t}\n\t\t\tcBase = mult(cBase, cBase);\n\t\t\tpow >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long[][] base = { { 2, 1 }, { 0, 1 } };\n\n\tstatic long[][] mult(long[][] a, long[][] b) {\n\t\tlong[][] res = 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\tres[i][j] = (a[i][0] * b[0][j] % MOD + a[i][1] * b[1][j] % MOD) % MOD;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        int mod = (int) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long x = in.readLong();\n            long k = in.readLong();\n            if (x == 0) {\n                out.println(0);\n                return;\n            }\n            long ans = (BigInteger.valueOf(MathUtil.pow(2, k + 1, mod)).multiply(BigInteger.valueOf(x))).mod(BigInteger.valueOf(mod)).longValue();\n            long sub = (mod + MathUtil.pow(2, k, mod) - 1) % mod;\n            out.println((mod + ans - sub) % mod);\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            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public long readLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class MathUtil {\n        public static long pow(long a, long b, long mod) {\n            long ans = 1;\n            while (b > 0) {\n                if (b % 2 == 1) ans = (ans * a) % mod;\n                a = (a * a) % mod;\n                b /= 2;\n            }\n            return ans;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "//package baobab;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n\n    public static void main(String[] args) {\n        Solver solver = new Solver();\n    }\n\n    static class Solver {\n        IO io;\n\n        public Solver() {\n            this.io = new IO();\n            try {\n                solve();\n            } catch (RuntimeException e) {\n                if (!e.getMessage().equals(\"Clean exit\")) {\n                    throw e;\n                }\n            } finally {\n                io.close();\n            }\n        }\n\n        /****************************** START READING HERE ********************************/\n\n        void solve() {\n            long x = io.nextLong();\n            long k = io.nextLong();\n            if (x==0) done(0);\n            long ans = pow(2,k) * ((2*x - 1)%MOD) + 1;\n            io.println(ans%MOD);\n        }\n\n        long pow(long base, long exp) {\n            if (exp == 0) return 1L;\n            long x = pow(base, exp/2);\n            long ans = x * x;\n            ans %= MOD;\n            if (exp % 2 != 0) {\n                ans *= base;\n                ans %= MOD;\n            }\n            return ans;\n        }\n\n        void solve2() {\n            long x = io.nextLong();\n            long k = io.nextLong();\n            if (x==0) done(0);\n\n            // TODO how to exclude from counts cases where dresses are negative?\n\n            long checkPointA = min(10000, k);\n            double count = x;\n            long i=0;\n            for (; i<checkPointA; i++) {\n                count *= 2;\n                count -= 0.5;\n                count %= MOD;\n            }\n            List<Double> bah = new ArrayList<>();\n            List<Long> meh = new ArrayList<>();\n            while (true) {\n                bah.add(count);\n                meh.add(i);\n                long j = 2*i;\n                if (j > k || j < 0) break;\n                i = j;\n                count *= count;\n                count %= MOD;\n            }\n            while (!bah.isEmpty()) {\n                long muller = meh.get(meh.size()-1);\n                long cand = i + muller;\n                if (cand > k || cand < 0) {\n                    meh.remove(meh.size()-1);\n                    bah.remove(bah.size()-1);\n                    continue;\n                }\n                i = cand;\n                count *= meh.get(meh.size()-1);\n                count %= MOD;\n            }\n            for (; i<k; i++) {\n                count *= 2;\n                count -= 0.5;\n                count %= MOD;\n            }\n            // last month no eating\n            count *= 2;\n            count %= MOD;\n            io.println(Math.round(count));\n        }\n\n        /************************** UTILITY CODE BELOW THIS LINE **************************/\n\n        long MOD = (long)1e9 + 7;\n\n        boolean closeToZero(double v) {\n            // Check if double is close to zero, considering precision issues.\n            return Math.abs(v) <= 0.0000000000001;\n        }\n\n        class DrawGrid {\n\n            void draw(boolean[][] d) {\n                System.out.print(\"  \");\n                for (int x=0; x<d[0].length; x++) {\n                    System.out.print(\" \" + x + \" \");\n                }\n                System.out.println(\"\");\n                for (int y=0; y<d.length; y++) {\n                    System.out.print(y + \" \");\n                    for (int x=0; x<d[0].length; x++) {\n                        System.out.print((d[y][x] ? \"[x]\" : \"[ ]\"));\n                    }\n                    System.out.println(\"\");\n                }\n            }\n\n            void draw(int[][] d) {\n                int max = 1;\n                for (int y=0; y<d.length; y++) {\n                    for (int x=0; x<d[0].length; x++) {\n                        max = Math.max(max, (\"\" + d[y][x]).length());\n                    }\n                }\n                System.out.print(\"  \");\n                String format = \"%\" + (max+2) + \"s\";\n                for (int x=0; x<d[0].length; x++) {\n                    System.out.print(String.format(format, x) + \" \");\n                }\n                format = \"%\" + (max) + \"s\";\n                System.out.println(\"\");\n                for (int y=0; y<d.length; y++) {\n                    System.out.print(y + \" \");\n                    for (int x=0; x<d[0].length; x++) {\n                        System.out.print(\" [\" + String.format(format, (d[y][x])) + \"]\");\n                    }\n                    System.out.println(\"\");\n                }\n            }\n\n        }\n\n        class IDval implements Comparable<IDval> {\n            int id;\n            long val;\n\n            public IDval(int id, long val) {\n                this.val = val;\n                this.id = id;\n            }\n\n            @Override\n            public int compareTo(IDval o) {\n                if (this.val < o.val) return -1;\n                if (this.val > o.val) return 1;\n                return this.id - o.id;\n            }\n        }\n\n        private class ElementCounter {\n            private HashMap<Long, Integer> elements;\n\n            public ElementCounter() {\n                elements = new HashMap<>();\n            }\n\n            public void add(long element) {\n                int count = 1;\n                Integer prev = elements.get(element);\n                if (prev != null) count += prev;\n                elements.put(element, count);\n            }\n\n            public void remove(long element) {\n                int count = elements.remove(element);\n                count--;\n                if (count > 0) elements.put(element, count);\n            }\n\n            public int get(long element) {\n                Integer val = elements.get(element);\n                if (val == null) return 0;\n                return val;\n            }\n\n            public int size() {\n                return elements.size();\n            }\n        }\n\n        class StringCounter {\n            HashMap<String, Integer> elements;\n\n            public StringCounter() {\n                elements = new HashMap<>();\n            }\n\n            public void add(String identifier) {\n                int count = 1;\n                Integer prev = elements.get(identifier);\n                if (prev != null) count += prev;\n                elements.put(identifier, count);\n            }\n\n            public void remove(String identifier) {\n                int count = elements.remove(identifier);\n                count--;\n                if (count > 0) elements.put(identifier, count);\n            }\n\n            public long get(String identifier) {\n                Integer val = elements.get(identifier);\n                if (val == null) return 0;\n                return val;\n            }\n\n            public int size() {\n                return elements.size();\n            }\n        }\n\n        class DisjointSet {\n            /** Union Find / Disjoint Set data structure. */\n            int[] size;\n            int[] parent;\n            int componentCount;\n\n            public DisjointSet(int n) {\n                componentCount = n;\n                size = new int[n];\n                parent = new int[n];\n                for (int i=0; i<n; i++) parent[i] = i;\n                for (int i=0; i<n; i++) size[i] = 1;\n            }\n\n            public void join(int a, int b) {\n                /* Find roots */\n                int rootA = parent[a];\n                int rootB = parent[b];\n                while (rootA != parent[rootA]) rootA = parent[rootA];\n                while (rootB != parent[rootB]) rootB = parent[rootB];\n\n                if (rootA == rootB) {\n                    /* Already in the same set */\n                    return;\n                }\n\n                /* Merge smaller set into larger set. */\n                if (size[rootA] > size[rootB]) {\n                    size[rootA] += size[rootB];\n                    parent[rootB] = rootA;\n                } else {\n                    size[rootB] += size[rootA];\n                    parent[rootA] = rootB;\n                }\n                componentCount--;\n            }\n\n        }\n\n        class Trie {\n            int N;\n            int Z;\n            int nextFreeId;\n            int[][] pointers;\n            boolean[] end;\n\n            /** maxLenSum = maximum possible sum of length of words */\n            public Trie(int maxLenSum, int alphabetSize) {\n                this.N = maxLenSum;\n                this.Z = alphabetSize;\n                this.nextFreeId = 1;\n                pointers = new int[N+1][alphabetSize];\n                end = new boolean[N+1];\n            }\n\n            public void addWord(String word) {\n                int curr = 0;\n                for (int j=0; j<word.length(); j++) {\n                    int c = word.charAt(j) - 'a';\n                    int next = pointers[curr][c];\n                    if (next == 0) {\n                        next = nextFreeId++;\n                        pointers[curr][c] = next;\n                    }\n                    curr = next;\n                }\n                end[curr] = true;\n            }\n\n            public boolean hasWord(String word) {\n                int curr = 0;\n                for (int j=0; j<word.length(); j++) {\n                    int c = word.charAt(j) - 'a';\n                    int next = pointers[curr][c];\n                    if (next == 0) return false;\n                    curr = next;\n                }\n                return end[curr];\n            }\n\n        }\n\n        private static class Prob {\n\n            /** For heavy calculations on probabilities, this class\n             *  provides more accuracy & efficiency than doubles.\n             *  Math explained: https://en.wikipedia.org/wiki/Log_probability\n             *  Quick start:\n             *      - Instantiate probabilities, eg. Prob a = new Prob(0.75)\n             *      - add(), multiply() return new objects, can perform on nulls & NaNs.\n             *      - get() returns probability as a readable double */\n\n            /** Logarithmized probability. Note: 0% represented by logP NaN. */\n            private double logP;\n\n            /** Construct instance with real probability. */\n            public Prob(double real) {\n                if (real > 0) this.logP = Math.log(real);\n                else this.logP = Double.NaN;\n            }\n\n            /** Construct instance with already logarithmized value. */\n            static boolean dontLogAgain = true;\n            public Prob(double logP, boolean anyBooleanHereToChooseThisConstructor) {\n                this.logP = logP;\n            }\n\n            /** Returns real probability as a double. */\n            public double get() {\n                return Math.exp(logP);\n            }\n\n            @Override\n            public String toString() {\n                return \"\"+get();\n            }\n\n            /***************** STATIC METHODS BELOW ********************/\n\n            /** Note: returns NaN only when a && b are both NaN/null. */\n            public static Prob add(Prob a, Prob b) {\n                if (nullOrNaN(a) && nullOrNaN(b)) return new Prob(Double.NaN, dontLogAgain);\n                if (nullOrNaN(a)) return copy(b);\n                if (nullOrNaN(b)) return copy(a);\n\n                double x = Math.max(a.logP, b.logP);\n                double y = Math.min(a.logP, b.logP);\n                double sum = x + Math.log(1 + Math.exp(y - x));\n                return new Prob(sum, dontLogAgain);\n            }\n\n            /** Note: multiplying by null or NaN produces NaN (repping 0% real prob). */\n            public static Prob multiply(Prob a, Prob b) {\n                if (nullOrNaN(a) || nullOrNaN(b)) return new Prob(Double.NaN, dontLogAgain);\n                return new Prob(a.logP + b.logP, dontLogAgain);\n            }\n\n            /** Returns true if p is null or NaN. */\n            private static boolean nullOrNaN(Prob p) {\n                return (p == null || Double.isNaN(p.logP));\n            }\n\n            /** Returns a new instance with the same value as original. */\n            private static Prob copy(Prob original) {\n                return new Prob(original.logP, dontLogAgain);\n            }\n        }\n\n        class Binary implements Comparable<Binary> {\n\n            /**\n             * Use example: Binary b = new Binary(Long.toBinaryString(53249834L));\n             *\n             * When manipulating small binary strings, instantiate new Binary(string)\n             * When just reading large binary strings, instantiate new Binary(string,true)\n             * get(int i) returns a character '1' or '0', not an int.\n             */\n\n            private boolean[] d;\n            private int first; // Starting from left, the first (most remarkable) '1'\n            public int length;\n\n\n            public Binary(String binaryString) {\n                this(binaryString, false);\n            }\n            public Binary(String binaryString, boolean initWithMinArraySize) {\n                length = binaryString.length();\n                int size = Math.max(2*length, 1);\n                first = length/4;\n                if (initWithMinArraySize) {\n                    first = 0;\n                    size = Math.max(length, 1);\n                }\n                d = new boolean[size];\n                for (int i=0; i<length; i++) {\n                    if (binaryString.charAt(i) == '1') d[i+first] = true;\n                }\n            }\n\n            public void addFirst(char c) {\n                if (first-1 < 0) doubleArraySize();\n                first--;\n                d[first] = (c == '1' ? true : false);\n                length++;\n            }\n\n            public void addLast(char c) {\n                if (first+length >= d.length) doubleArraySize();\n                d[first+length] = (c == '1' ? true : false);\n                length++;\n            }\n\n            private void doubleArraySize() {\n                boolean[] bigArray = new boolean[(d.length+1) * 2];\n                int newFirst = bigArray.length / 4;\n                for (int i=0; i<length; i++) {\n                    bigArray[i + newFirst] = d[i + first];\n                }\n                first = newFirst;\n                d = bigArray;\n            }\n\n            public boolean flip(int i) {\n                boolean value = (this.d[first+i] ? false : true);\n                this.d[first+i] = value;\n                return value;\n            }\n\n            public void set(int i, char c) {\n                boolean value = (c == '1' ? true : false);\n                this.d[first+i] = value;\n            }\n\n            public char get(int i) {\n                return (this.d[first+i] ? '1' : '0');\n            }\n\n            @Override\n            public int compareTo(Binary o) {\n                if (this.length != o.length) return this.length - o.length;\n                int len = this.length;\n                for (int i=0; i<len; i++) {\n                    int diff = this.get(i) - o.get(i);\n                    if (diff != 0) return diff;\n                }\n                return 0;\n            }\n\n            @Override\n            public String toString() {\n                StringBuilder sb = new StringBuilder();\n                for (int i=0; i<length; i++) {\n                    sb.append(d[i+first] ? '1' : '0');\n                }\n                return sb.toString();\n            }\n\n\n        }\n\n        /************************** Range queries **************************/\n\n        class FenwickMin {\n            long n;\n            long[] original;\n            long[] bottomUp;\n            long[] topDown;\n\n            public FenwickMin(int n) {\n                this.n = n;\n                original = new long[n+2];\n                bottomUp = new long[n+2];\n                topDown = new long[n+2];\n            }\n\n            public void set(int modifiedNode, long value) {\n                long replaced = original[modifiedNode];\n                original[modifiedNode] = value;\n                // Update left tree\n                int i = modifiedNode;\n                long v = value;\n                while (i <= n) {\n                    if (v > bottomUp[i]) {\n                        if (replaced == bottomUp[i]) {\n                            v = Math.min(v, original[i]);\n                            for (int r=1 ;; r++) {\n                                int x = (i&-i)>>>r;\n                                if (x == 0) break;\n                                int child = i-x;\n                                v = Math.min(v, bottomUp[child]);\n                            }\n                        } else break;\n                    }\n                    if (v == bottomUp[i]) break;\n                    bottomUp[i] = v;\n                    i += (i&-i);\n                }\n                // Update right tree\n                i = modifiedNode;\n                v = value;\n                while (i > 0) {\n                    if (v > topDown[i]) {\n                        if (replaced == topDown[i]) {\n                            v = Math.min(v, original[i]);\n                            for (int r=1 ;; r++) {\n                                int x = (i&-i)>>>r;\n                                if (x == 0) break;\n                                int child = i+x;\n                                if (child > n+1) break;\n                                v = Math.min(v, topDown[child]);\n                            }\n                        } else break;\n                    }\n                    if (v == topDown[i]) break;\n                    topDown[i] = v;\n                    i -= (i&-i);\n                }\n            }\n\n            public long getMin(int a, int b) {\n                long min = original[a];\n                int prev = a;\n                int curr = prev + (prev&-prev); // parent right hand side\n                while (curr <= b) {\n                    min = Math.min(min, topDown[prev]); // value from the other tree\n                    prev = curr;\n                    curr = prev + (prev&-prev);;\n                }\n                min = Math.min(min, original[prev]);\n                prev = b;\n                curr = prev - (prev&-prev); // parent left hand side\n                while (curr >= a) {\n                    min = Math.min(min,bottomUp[prev]); // value from the other tree\n                    prev = curr;\n                    curr = prev - (prev&-prev);\n                }\n                return min;\n            }\n\n        }\n\n        class FenwickSum {\n            public long[] d;\n\n            public FenwickSum(int n) {\n                d=new long[n+1];\n            }\n\n            /** a[0] must be unused. */\n            public FenwickSum(long[] a) {\n                d=new long[a.length];\n                for (int i=1; i<a.length; i++) {\n                    modify(i, a[i]);\n                }\n            }\n\n            /** Do not modify i=0. */\n            void modify(int i, long v) {\n                while (i<d.length) {\n                    d[i] += v;\n                    // Move to next uplink on the RIGHT side of i\n                    i += (i&-i);\n                }\n            }\n\n            /** Returns sum from a to b, *BOTH* inclusive. */\n            long getSum(int a, int b) {\n                return getSum(b) - getSum(a-1);\n            }\n\n            private long getSum(int i) {\n                long sum = 0;\n                while (i>0) {\n                    sum += d[i];\n                    // Move to next uplink on the LEFT side of i\n                    i -= (i&-i);\n                }\n                return sum;\n            }\n        }\n\n        class SegmentTree {\n            /** Query sums with log(n) modifyRange */\n            int N;\n            long[] p;\n\n            public SegmentTree(int n) {\n                /* TODO: Test that this works. */\n                for (N=2; N<n; N++) N *= 2;\n                p = new long[2*N];\n            }\n\n            public void modifyRange(int a, int b, long change) {\n                muuta(a, change);\n                muuta(b+1, -change);\n            }\n\n            void muuta(int k, long muutos) {\n                k += N;\n                p[k] += muutos;\n                for (k /= 2; k >= 1; k /= 2) {\n                    p[k] = p[2*k] + p[2*k+1];\n                }\n            }\n\n            public long get(int k) {\n                int a = N;\n                int b = k+N;\n                long s = 0;\n                while (a <= b) {\n                    if (a%2 == 1) s += p[a++];\n                    if (b%2 == 0) s += p[b--];\n                    a /= 2;\n                    b /= 2;\n                }\n                return s;\n            }\n\n        }\n\n        /***************************** Graphs *****************************/\n\n        List<Integer>[] toGraph(IO io, int n) {\n            List<Integer>[] g = new ArrayList[n+1];\n            for (int i=1; i<=n; i++) g[i] = new ArrayList<>();\n            for (int i=1; i<=n-1; i++) {\n                int a = io.nextInt();\n                int b = io.nextInt();\n                g[a].add(b);\n                g[b].add(a);\n            }\n            return g;\n        }\n\n        class Graph {\n            HashMap<Long, List<Long>> edges;\n\n            public Graph() {\n                edges = new HashMap<>();\n            }\n\n            List<Long> getSetNeighbors(Long node) {\n                List<Long> neighbors = edges.get(node);\n                if (neighbors == null) {\n                    neighbors = new ArrayList<>();\n                    edges.put(node, neighbors);\n                }\n                return neighbors;\n            }\n\n            void addBiEdge(Long a, Long b) {\n                addEdge(a, b);\n                addEdge(b, a);\n            }\n\n            void addEdge(Long from, Long to) {\n                getSetNeighbors(to); // make sure all have initialized lists\n                List<Long> neighbors = getSetNeighbors(from);\n                neighbors.add(to);\n            }\n\n            // topoSort variables\n            int UNTOUCHED = 0;\n            int FINISHED = 2;\n            int INPROGRESS = 1;\n            HashMap<Long, Integer> vis;\n            List<Long> topoAns;\n            List<Long> failDueToCycle = new ArrayList<Long>() {{ add(-1L); }};\n\n            List<Long> topoSort() {\n                topoAns = new ArrayList<>();\n                vis = new HashMap<>();\n                for (Long a : edges.keySet()) {\n                    if (!topoDFS(a)) return failDueToCycle;\n                }\n                Collections.reverse(topoAns);\n                return topoAns;\n            }\n\n            boolean topoDFS(long curr) {\n                Integer status = vis.get(curr);\n                if (status == null) status = UNTOUCHED;\n                if (status == FINISHED) return true;\n                if (status == INPROGRESS) {\n                    return false;\n                }\n                vis.put(curr, INPROGRESS);\n                for (long next : edges.get(curr)) {\n                    if (!topoDFS(next)) return false;\n                }\n                vis.put(curr, FINISHED);\n                topoAns.add(curr);\n                return true;\n            }\n\n        }\n\n        public class StronglyConnectedComponents {\n\n            /** Kosaraju's algorithm */\n\n            ArrayList<Integer>[] forw;\n            ArrayList<Integer>[] bacw;\n\n            /** Use: getCount(2, new int[] {1,2}, new int[] {2,1}) */\n            public int getCount(int n, int[] mista, int[] minne) {\n                forw = new ArrayList[n+1];\n                bacw = new ArrayList[n+1];\n                for (int i=1; i<=n; i++) {\n                    forw[i] = new ArrayList<Integer>();\n                    bacw[i] = new ArrayList<Integer>();\n                }\n                for (int i=0; i<mista.length; i++) {\n                    int a = mista[i];\n                    int b = minne[i];\n                    forw[a].add(b);\n                    bacw[b].add(a);\n                }\n                int count = 0;\n                List<Integer> list = new ArrayList<Integer>();\n                boolean[] visited = new boolean[n+1];\n                for (int i=1; i<=n; i++) {\n                    dfsForward(i, visited, list);\n                }\n                visited = new boolean[n+1];\n                for (int i=n-1; i>=0; i--) {\n                    int node = list.get(i);\n                    if (visited[node]) continue;\n                    count++;\n                    dfsBackward(node, visited);\n                }\n                return count;\n            }\n\n            public void dfsForward(int i, boolean[] visited, List<Integer> list) {\n                if (visited[i]) return;\n                visited[i] = true;\n                for (int neighbor : forw[i]) {\n                    dfsForward(neighbor, visited, list);\n                }\n                list.add(i);\n            }\n\n            public void dfsBackward(int i, boolean[] visited) {\n                if (visited[i]) return;\n                visited[i] = true;\n                for (int neighbor : bacw[i]) {\n                    dfsBackward(neighbor, visited);\n                }\n            }\n        }\n\n        class LCAFinder {\n\n            /* O(n log n) Initialize: new LCAFinder(graph)\n             * O(log n) Queries: find(a,b) returns lowest common ancestor for nodes a and b */\n\n            int[] nodes;\n            int[] depths;\n            int[] entries;\n            int pointer;\n            FenwickMin fenwick;\n\n            public LCAFinder(List<Integer>[] graph) {\n                this.nodes = new int[(int)10e6];\n                this.depths = new int[(int)10e6];\n                this.entries = new int[graph.length];\n                this.pointer = 1;\n                boolean[] visited = new boolean[graph.length+1];\n                dfs(1, 0, graph, visited);\n                fenwick = new FenwickMin(pointer-1);\n                for (int i=1; i<pointer; i++) {\n                    fenwick.set(i, depths[i] * 1000000L + i);\n                }\n            }\n\n            private void dfs(int node, int depth, List<Integer>[] graph, boolean[] visited) {\n                visited[node] = true;\n                entries[node] = pointer;\n                nodes[pointer] = node;\n                depths[pointer] = depth;\n                pointer++;\n                for (int neighbor : graph[node]) {\n                    if (visited[neighbor]) continue;\n                    dfs(neighbor, depth+1, graph, visited);\n                    nodes[pointer] = node;\n                    depths[pointer] = depth;\n                    pointer++;\n                }\n            }\n\n            public int find(int a, int b) {\n                int left = entries[a];\n                int right = entries[b];\n                if (left > right) {\n                    int temp = left;\n                    left = right;\n                    right = temp;\n                }\n                long mixedBag = fenwick.getMin(left, right);\n                int index = (int) (mixedBag % 1000000L);\n                return nodes[index];\n            }\n        }\n\n        /**************************** Geometry ****************************/\n\n        class Point {\n            int y;\n            int x;\n\n            public Point(int y, int x) {\n                this.y = y;\n                this.x = x;\n            }\n        }\n\n        boolean segmentsIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {\n            // Returns true if segment 1-2 intersects segment 3-4\n\n            if (x1 == x2 && x3 == x4) {\n                // Both segments are vertical\n                if (x1 != x3) return false;\n                if (min(y1,y2) < min(y3,y4)) {\n                    return max(y1,y2) >= min(y3,y4);\n                } else {\n                    return max(y3,y4) >= min(y1,y2);\n                }\n            }\n            if (x1 == x2) {\n                // Only segment 1-2 is vertical. Does segment 3-4 cross it? y = a*x + b\n                double a34 = (y4-y3)/(x4-x3);\n                double b34 = y3 - a34*x3;\n                double y = a34 * x1 + b34;\n                return y >= min(y1,y2) && y <= max(y1,y2) && x1 >= min(x3,x4) && x1 <= max(x3,x4);\n            }\n            if (x3 == x4) {\n                // Only segment 3-4 is vertical. Does segment 1-2 cross it? y = a*x + b\n                double a12 = (y2-y1)/(x2-x1);\n                double b12 = y1 - a12*x1;\n                double y = a12 * x3 + b12;\n                return y >= min(y3,y4) && y <= max(y3,y4) && x3 >= min(x1,x2) && x3 <= max(x1,x2);\n            }\n            double a12 = (y2-y1)/(x2-x1);\n            double b12 = y1 - a12*x1;\n            double a34 = (y4-y3)/(x4-x3);\n            double b34 = y3 - a34*x3;\n            if (closeToZero(a12 - a34)) {\n                // Parallel lines\n                return closeToZero(b12 - b34);\n            }\n            // Non parallel non vertical lines intersect at x. Is x part of both segments?\n            double x = -(b12-b34)/(a12-a34);\n            return x >= min(x1,x2) && x <= max(x1,x2) && x >= min(x3,x4) && x <= max(x3,x4);\n        }\n\n        boolean pointInsideRectangle(Point p, List<Point> r) {\n            Point a = r.get(0);\n            Point b = r.get(1);\n            Point c = r.get(2);\n            Point d = r.get(3);\n            double apd = areaOfTriangle(a, p, d);\n            double dpc = areaOfTriangle(d, p, c);\n            double cpb = areaOfTriangle(c, p, b);\n            double pba = areaOfTriangle(p, b, a);\n            double sumOfAreas = apd + dpc + cpb + pba;\n            if (closeToZero(sumOfAreas - areaOfRectangle(r))) {\n                if (closeToZero(apd) || closeToZero(dpc) || closeToZero(cpb) || closeToZero(pba)) {\n                    return false;\n                }\n                return true;\n            }\n            return false;\n        }\n\n        double areaOfTriangle(Point a, Point b, Point c) {\n            return 0.5 * Math.abs((a.x-c.x)*(b.y-a.y)-(a.x-b.x)*(c.y-a.y));\n        }\n\n        double areaOfRectangle(List<Point> r) {\n            double side1xDiff = r.get(0).x - r.get(1).x;\n            double side1yDiff = r.get(0).y - r.get(1).y;\n            double side2xDiff = r.get(1).x - r.get(2).x;\n            double side2yDiff = r.get(1).y - r.get(2).y;\n            double side1 = Math.sqrt(side1xDiff * side1xDiff + side1yDiff * side1yDiff);\n            double side2 = Math.sqrt(side2xDiff * side2xDiff + side2yDiff * side2yDiff);\n            return side1 * side2;\n        }\n\n        boolean pointsOnSameLine(double x1, double y1, double x2, double y2, double x3, double y3) {\n            double areaTimes2 = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2);\n            return (closeToZero(areaTimes2));\n        }\n\n        class PointToLineSegmentDistanceCalculator {\n\n            // Just call this\n            double minDistFromPointToLineSegment(double point_x, double point_y, double x1, double y1, double x2, double y2) {\n                return Math.sqrt(distToSegmentSquared(point_x, point_y, x1, y1, x2, y2));\n            }\n\n            private double distToSegmentSquared(double point_x, double point_y, double x1, double y1, double x2, double y2) {\n                double l2 = dist2(x1,y1,x2,y2);\n                if (l2 == 0) return dist2(point_x, point_y, x1, y1);\n                double t = ((point_x - x1) * (x2 - x1) + (point_y - y1) * (y2 - y1)) / l2;\n                if (t < 0) return dist2(point_x, point_y, x1, y1);\n                if (t > 1) return dist2(point_x, point_y, x2, y2);\n\n                double com_x = x1 + t * (x2 - x1);\n                double com_y = y1 + t * (y2 - y1);\n                return dist2(point_x, point_y, com_x, com_y);\n            }\n\n            private double dist2(double x1, double y1, double x2, double y2) {\n                return Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2);\n            }\n\n        }\n\n        /****************************** Math ******************************/\n\n\n\n        long gcd(long... v) {\n            /** Chained calls to Euclidean algorithm. */\n            if (v.length == 1) return v[0];\n            long ans = gcd(v[1], v[0]);\n            for (int i=2; i<v.length; i++) {\n                ans = gcd(ans, v[i]);\n            }\n            return ans;\n        }\n\n        long gcd(long a, long b) {\n            /** Euclidean algorithm. */\n            if (b == 0) return a;\n            return gcd(b, a%b);\n        }\n\n        int[] generatePrimesUpTo(int last) {\n            /* Sieve of Eratosthenes. Practically O(n). Values of 0 indicate primes. */\n            int[] div = new int[last+1];\n            for (int x=2; x<=last; x++) {\n                if (div[x] > 0) continue;\n                for (int u=2*x; u<=last; u+=x) {\n                    div[u] = x;\n                }\n            }\n            return div;\n        }\n\n        long lcm(long a, long b) {\n            /** Least common multiple */\n            return a * b / gcd(a,b);\n        }\n\n        class BaseConverter {\n\n            /* Palauttaa luvun esityksen kannassa base */\n            public String convert(Long number, int base) {\n                return Long.toString(number, base);\n            }\n\n            /* Palauttaa luvun esityksen kannassa baseTo, kun annetaan luku Stringin\u00e4 kannassa baseFrom */\n            public String convert(String number, int baseFrom, int baseTo) {\n                return Long.toString(Long.parseLong(number, baseFrom), baseTo);\n            }\n\n            /* Tulkitsee kannassa base esitetyn luvun longiksi (kannassa 10) */\n            public long longify(String number, int baseFrom) {\n                return Long.parseLong(number, baseFrom);\n            }\n        }\n\n        class BinomialCoefficients {\n            /** Total number of K sized unique combinations from pool of size N (unordered)\n             N! / ( K! (N - K)! )   */\n\n            /** For simple queries where output fits in long. */\n            public long biCo(long n, long k) {\n                long r = 1;\n                if (k > n) return 0;\n                for (long d = 1; d <= k; d++) {\n                    r *= n--;\n                    r /= d;\n                }\n                return r;\n            }\n\n            /** For multiple queries with same n, different k. */\n            public long[] precalcBinomialCoefficientsK(int n, int maxK) {\n                long v[] = new long[maxK+1];\n                v[0] = 1; // nC0 == 1\n                for (int i=1; i<=n; i++) {\n                    for (int j=Math.min(i,maxK); j>0; j--) {\n                        v[j] = v[j] + v[j-1]; // Pascal's triangle\n                    }\n                }\n                return v;\n            }\n\n            /** When output needs % MOD. */\n            public long[] precalcBinomialCoefficientsK(int n, int k, long M) {\n                long v[] = new long[k+1];\n                v[0] = 1; // nC0 == 1\n                for (int i=1; i<=n; i++) {\n                    for (int j=Math.min(i,k); j>0; j--) {\n                        v[j] = v[j] + v[j-1]; // Pascal's triangle\n                        v[j] %= M;\n                    }\n                }\n                return v;\n            }\n        }\n\n        /**************************** Strings ****************************/\n\n        class Zalgo {\n\n            public int pisinEsiintyma(String haku, String kohde) {\n                char[] s = new char[haku.length() + 1 + kohde.length()];\n                for (int i=0; i<haku.length(); i++) {\n                    s[i] = haku.charAt(i);\n                }\n                int j = haku.length();\n                s[j++] = '#';\n                for (int i=0; i<kohde.length(); i++) {\n                    s[j++] = kohde.charAt(i);\n                }\n                int[] z = toZarray(s);\n                int max = 0;\n                for (int i=haku.length(); i<z.length; i++) {\n                    max = Math.max(max, z[i]);\n                }\n                return max;\n            }\n\n            public int[] toZarray(char[] s) {\n                int n = s.length;\n                int[] z = new int[n];\n                int a = 0, b = 0;\n                for (int i = 1; i < n; i++) {\n                    if (i > b) {\n                        for (int j = i; j < n && s[j - i] == s[j]; j++)  z[i]++;\n                    }\n                    else {\n                        z[i] = z[i - a];\n                        if (i + z[i - a] > b) {\n                            for (int j = b + 1; j < n && s[j - i] == s[j]; j++) z[i]++;\n                            a = i;\n                            b = i + z[i] - 1;\n                        }\n                    }\n                }\n                return z;\n            }\n\n            public List<Integer> getStartIndexesWhereWordIsFound(String haku, String kohde) {\n                // this is alternative use case\n                char[] s = new char[haku.length() + 1 + kohde.length()];\n                for (int i=0; i<haku.length(); i++) {\n                    s[i] = haku.charAt(i);\n                }\n                int j = haku.length();\n                s[j++] = '#';\n                for (int i=0; i<kohde.length(); i++) {\n                    s[j++] = kohde.charAt(i);\n                }\n                int[] z = toZarray(s);\n                List<Integer> indexes = new ArrayList<>();\n                for (int i=haku.length(); i<z.length; i++) {\n                    if (z[i] < haku.length()) continue;\n                    indexes.add(i);\n                }\n                return indexes;\n            }\n\n        }\n\n        class StringHasher {\n\n            class HashedString {\n                long[] hashes;\n                long[] modifiers;\n\n                public HashedString(long[] hashes, long[] modifiers) {\n                    this.hashes = hashes;\n                    this.modifiers = modifiers;\n                }\n            }\n\n            long P;\n            long M;\n\n            public StringHasher() {\n                initializePandM();\n            }\n\n            HashedString hashString(String s) {\n                int n = s.length();\n                long[] hashes = new long[n];\n                long[] modifiers = new long[n];\n                hashes[0] = s.charAt(0);\n                modifiers[0] = 1;\n                for (int i=1; i<n; i++) {\n                    hashes[i] = (hashes[i-1] * P + s.charAt(i)) % M;\n                    modifiers[i] = (modifiers[i-1] * P) % M;\n                }\n                return new HashedString(hashes, modifiers);\n            }\n\n            /**\n             * Indices are inclusive.\n             */\n            long getHash(HashedString hashedString, int startIndex, int endIndex) {\n                long[] hashes = hashedString.hashes;\n                long[] modifiers = hashedString.modifiers;\n                long result = hashes[endIndex];\n                if (startIndex > 0) result -= (hashes[startIndex-1] * modifiers[endIndex-startIndex+1]) % M;\n                if (result < 0) result += M;\n                return result;\n            }\n\n            // Less interesting methods below\n\n\n\n            /**\n             * Efficient for 2 input parameter strings in particular.\n             */\n            HashedString[] hashString(String first, String second) {\n                HashedString[] array = new HashedString[2];\n                int n = first.length();\n                long[] modifiers = new long[n];\n                modifiers[0] = 1;\n\n                long[] firstHashes = new long[n];\n                firstHashes[0] = first.charAt(0);\n                array[0] = new HashedString(firstHashes, modifiers);\n\n                long[] secondHashes = new long[n];\n                secondHashes[0] = second.charAt(0);\n                array[1] = new HashedString(secondHashes, modifiers);\n\n                for (int i=1; i<n; i++) {\n                    modifiers[i] = (modifiers[i-1] * P) % M;\n                    firstHashes[i] = (firstHashes[i-1] * P + first.charAt(i)) % M;\n                    secondHashes[i] = (secondHashes[i-1] * P + second.charAt(i)) % M;\n                }\n                return array;\n            }\n\n            /**\n             * Efficient for 3+ strings\n             * More efficient than multiple hashString calls IF strings are same length.\n             */\n            HashedString[] hashString(String... strings) {\n                HashedString[] array = new HashedString[strings.length];\n                int n = strings[0].length();\n                long[] modifiers = new long[n];\n                modifiers[0] = 1;\n                for (int j=0; j<strings.length; j++) {\n                    // if all strings are not same length, defer work to another method\n                    if (strings[j].length() != n) {\n                        for (int i=0; i<n; i++) {\n                            array[i] = hashString(strings[i]);\n                        }\n                        return array;\n                    }\n\n                    // otherwise initialize stuff\n                    long[] hashes = new long[n];\n                    hashes[0] = strings[j].charAt(0);\n                    array[j] = new HashedString(hashes, modifiers);\n                }\n                for (int i=1; i<n; i++) {\n                    modifiers[i] = (modifiers[i-1] * P) % M;\n                    for (int j=0; j<strings.length; j++) {\n                        String s = strings[j];\n                        long[] hashes = array[j].hashes;\n                        hashes[i] = (hashes[i-1] * P + s.charAt(i)) % M;\n                    }\n                }\n                return array;\n            }\n\n            void initializePandM() {\n                ArrayList<Long> modOptions = new ArrayList<>(20);\n                modOptions.add(353873237L);\n                modOptions.add(353875897L);\n                modOptions.add(353878703L);\n                modOptions.add(353882671L);\n                modOptions.add(353885303L);\n                modOptions.add(353888377L);\n                modOptions.add(353893457L);\n                P = modOptions.get(new Random().nextInt(modOptions.size()));\n\n                modOptions.clear();\n                modOptions.add(452940277L);\n                modOptions.add(452947687L);\n                modOptions.add(464478431L);\n                modOptions.add(468098221L);\n                modOptions.add(470374601L);\n                modOptions.add(472879717L);\n                modOptions.add(472881973L);\n                M = modOptions.get(new Random().nextInt(modOptions.size()));\n\n            }\n        }\n\n        /*************************** Technical ***************************/\n\n        private class IO extends PrintWriter {\n            private InputStreamReader r;\n            private static final int BUFSIZE = 1 << 15;\n            private char[] buf;\n            private int bufc;\n            private int bufi;\n            private StringBuilder sb;\n\n            public IO() {\n                super(new BufferedOutputStream(System.out));\n                r = new InputStreamReader(System.in);\n\n                buf = new char[BUFSIZE];\n                bufc = 0;\n                bufi = 0;\n                sb = new StringBuilder();\n            }\n\n            /** Print, flush, return nextInt. */\n            private int queryInt(String s) {\n                io.println(s);\n                io.flush();\n                return nextInt();\n            }\n\n            /** Print, flush, return nextLong. */\n            private long queryLong(String s) {\n                io.println(s);\n                io.flush();\n                return nextLong();\n            }\n\n            /** Print, flush, return next word. */\n            private String queryNext(String s) {\n                io.println(s);\n                io.flush();\n                return next();\n            }\n\n            private void fillBuf() throws IOException {\n                bufi = 0;\n                bufc = 0;\n                while(bufc == 0) {\n                    bufc = r.read(buf, 0, BUFSIZE);\n                    if(bufc == -1) {\n                        bufc = 0;\n                        return;\n                    }\n                }\n            }\n\n            private boolean pumpBuf() throws IOException {\n                if(bufi == bufc) {\n                    fillBuf();\n                }\n                return bufc != 0;\n            }\n\n            private boolean isDelimiter(char c) {\n                return c == ' ' || c == '\\t' || c == '\\n' || c == '\\r' || c == '\\f';\n            }\n\n            private void eatDelimiters() throws IOException {\n                while(true) {\n                    if(bufi == bufc) {\n                        fillBuf();\n                        if(bufc == 0) throw new RuntimeException(\"IO: Out of input.\");\n                    }\n\n                    if(!isDelimiter(buf[bufi])) break;\n                    ++bufi;\n                }\n            }\n\n            public String next() {\n                try {\n                    sb.setLength(0);\n\n                    eatDelimiters();\n                    int start = bufi;\n\n                    while(true) {\n                        if(bufi == bufc) {\n                            sb.append(buf, start, bufi - start);\n                            fillBuf();\n                            start = 0;\n                            if(bufc == 0) break;\n                        }\n\n                        if(isDelimiter(buf[bufi])) break;\n                        ++bufi;\n                    }\n\n                    sb.append(buf, start, bufi - start);\n\n                    return sb.toString();\n                } catch(IOException e) {\n                    throw new RuntimeException(\"IO.next: Caught IOException.\");\n                }\n            }\n\n            public int nextInt() {\n                try {\n                    int ret = 0;\n\n                    eatDelimiters();\n\n                    boolean positive = true;\n                    if(buf[bufi] == '-') {\n                        ++bufi;\n                        if(!pumpBuf()) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n                        positive = false;\n                    }\n\n                    boolean first = true;\n                    while(true) {\n                        if(!pumpBuf()) break;\n                        if(isDelimiter(buf[bufi])) {\n                            if(first) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n                            break;\n                        }\n                        first = false;\n\n                        if(buf[bufi] >= '0' && buf[bufi] <= '9') {\n                            if(ret < -214748364) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n                            ret *= 10;\n                            ret -= (int)(buf[bufi] - '0');\n                            if(ret > 0) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n                        } else {\n                            throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n                        }\n\n                        ++bufi;\n                    }\n\n                    if(positive) {\n                        if(ret == -2147483648) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n                        ret = -ret;\n                    }\n\n                    return ret;\n                } catch(IOException e) {\n                    throw new RuntimeException(\"IO.nextInt: Caught IOException.\");\n                }\n            }\n\n            public long nextLong() {\n                try {\n                    long ret = 0;\n\n                    eatDelimiters();\n\n                    boolean positive = true;\n                    if(buf[bufi] == '-') {\n                        ++bufi;\n                        if(!pumpBuf()) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n                        positive = false;\n                    }\n\n                    boolean first = true;\n                    while(true) {\n                        if(!pumpBuf()) break;\n                        if(isDelimiter(buf[bufi])) {\n                            if(first) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n                            break;\n                        }\n                        first = false;\n\n                        if(buf[bufi] >= '0' && buf[bufi] <= '9') {\n                            if(ret < -922337203685477580L) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n                            ret *= 10;\n                            ret -= (long)(buf[bufi] - '0');\n                            if(ret > 0) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n                        } else {\n                            throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n                        }\n\n                        ++bufi;\n                    }\n\n                    if(positive) {\n                        if(ret == -9223372036854775808L) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n                        ret = -ret;\n                    }\n\n                    return ret;\n                } catch(IOException e) {\n                    throw new RuntimeException(\"IO.nextLong: Caught IOException.\");\n                }\n            }\n\n            public double nextDouble() {\n                return Double.parseDouble(next());\n            }\n\n        }\n\n        void print(Object output) {\n            io.println(output);\n        }\n\n        void done(Object output) {\n            print(output);\n            done();\n        }\n\n        void done() {\n            io.close();\n            throw new RuntimeException(\"Clean exit\");\n        }\n\n        long min(long... v) {\n            long ans = v[0];\n            for (int i=1; i<v.length; i++) {\n                ans = Math.min(ans, v[i]);\n            }\n            return ans;\n        }\n\n        double min(double... v) {\n            double ans = v[0];\n            for (int i=1; i<v.length; i++) {\n                ans = Math.min(ans, v[i]);\n            }\n            return ans;\n        }\n\n        int min(int... v) {\n            int ans = v[0];\n            for (int i=1; i<v.length; i++) {\n                ans = Math.min(ans, v[i]);\n            }\n            return ans;\n        }\n\n        long max(long... v) {\n            long ans = v[0];\n            for (int i=1; i<v.length; i++) {\n                ans = Math.max(ans, v[i]);\n            }\n            return ans;\n        }\n\n        double max(double... v) {\n            double ans = v[0];\n            for (int i=1; i<v.length; i++) {\n                ans = Math.max(ans, v[i]);\n            }\n            return ans;\n        }\n\n        int max(int... v) {\n            int ans = v[0];\n            for (int i=1; i<v.length; i++) {\n                ans = Math.max(ans, v[i]);\n            }\n            return ans;\n        }\n\n    }\n\n}\n\n\n\n\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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    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    long mod = (long)1e9 + 7;\n    public void run() {\n        InputReader sc = new InputReader(System.in);\n        PrintWriter w = new PrintWriter(System.out);\n\n        long x = sc.nextLong();\n        long k = sc.nextLong();\n\n        if(x == 0) {\n            w.print(\"0\");\n            w.close();\n            return;\n        }\n\n        x = x % mod;\n\n        long pkp1 = fast_pow(2, k + 1L);\n        long pk = fast_pow(2, k);\n\n        long sub = (pk - 1 + mod) % mod * pk % mod;\n        long add = x * pkp1 % mod * pk % mod;\n        long num = (add - sub + mod) % mod;\n        long deninv = fast_pow(pk, mod - 2);\n        long ans = num * deninv % mod;\n        w.print(ans);\n\n        w.close();      \n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class main {\n\tInputStream is;\n\tPrintWriter out;\n\tstatic long mod=pow(10,9)+7;\n\tint dx[]= {0,0,1,-1},dy[]={+1,-1,0,0};\n\tvoid solve()\n\t{\n\t\tlong x=nl();\n\t\tlong k=nl();\n\t\tif(x==0)\n\t\t{\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong term=(pow(2,k,mod))%mod;\n\t\tlong last=((x%mod)*pow(2,k+1,mod))%mod;\n\t\tlong sumdom=((2*last)%mod+(((term-1+mod)%mod)*((-2+mod)%mod))%mod)%mod;\n\t\tsumdom=(sumdom*term)%mod;\n\t\tsumdom=(sumdom*pow(2,mod-2,mod))%mod;\n\t\tsumdom=(sumdom*pow(term,mod-2,mod))%mod;\n\t\tout.println(sumdom);\n\t\t\t\t\n\t}\n\tint bsdown(ArrayList<Integer> al,int l) {\n\t\tint low=0,high=al.size()-1,ans=-1;\n\t\twhile(low<=high) {\n\t\t\tint mid=low+(high-low)/2;\n\t\t\tif(al.get(mid)<=l) {\n\t\t\t\tlow=mid+1;\n\t\t\t\tans=mid;\n\t\t\t}else\n\t\t\t\thigh=mid-1;\t\t\t\n\t\t}\n\t\treturn ans;\n\t}\n\tArrayList<Integer>al [];\n\tvoid take(int n,int m)\n\t{\n\t\tal=new ArrayList[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tal[i]=new ArrayList<Integer>();\n\t\tfor(int i=0;i<m;i++)\n\t\t{\n\t\t\tint x=ni()-1;\n\t\t\tint y=ni()-1;\n\t\t\tal[x].add(y);\n\t\t\tal[y].add(x);\n\t\t\t\n\t\t}\n\t}\n\tint arr[][];\n\tint small[];\n\tvoid pre(int n)\n\t{\n\t\tsmall=new int[n+1];\n\t\tfor(int i=2;i*i<=n;i++)\n\t\t{\n\t\t\tfor(int j=i;j*i<=n;j++)\n\t\t\t{\n\t\t\t\tif(small[i*j]==0)\n\t\t\t\t\tsmall[i*j]=i;\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<=n;i++)\n\t\t{\n\t\t\tif(small[i]==0)\n\t\t\t\tsmall[i]=i;\n\t\t}\n\t}\n\tpublic static int count(long x)\n\t{\n\t\tint num=0;\n\t\twhile(x!=0)\n\t\t{\n\t\t\tx=x&(x-1);\n\t\t\tnum++;\n\t\t}\n\t\treturn num;\n\t}\n\tstatic long d, x, y;\n\tvoid extendedEuclid(long A, long B) {\n\t    if(B == 0) {\n\t        d = A;\n\t        x = 1;\n\t        y = 0;\n\t    }\n\t    else {\n\t        extendedEuclid(B, A%B);\n\t        long temp = x;\n\t        x = y;\n\t        y = temp - (A/B)*y;\n\t    }\n\t}\n\tlong modInverse(long A,long M) //A and M are coprime\n\t{\n\t    extendedEuclid(A,M);\n\t    return (x%M+M)%M;    //x may be negative\n\t}\n\tpublic static void mergeSort(int[] arr, int l ,int r){\n\t\tif((r-l)>=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 ;i<n1;i++) left[i] = arr[l+i];\n\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\tint i =0, j =0, k = l;\n\t\twhile(i<n1 && j<n2){\n\t\t\tif(left[i]>right[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<n1) arr[k++] = left[i++];\n\t\twhile(j<n2) arr[k++] = right[j++];\n\t}\n\tpublic static void mergeSort(long[] arr, int l ,int r){\n\t\tif((r-l)>=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 ;i<n1;i++) left[i] = arr[l+i];\n\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\tint i =0, j =0, k = l;\n\t\twhile(i<n1 && j<n2){\n\t\t\tif(left[i]>right[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<n1) arr[k++] = left[i++];\n\t\twhile(j<n2) arr[k++] = right[j++];\n\t}\n\t static class Pair implements Comparable<Pair>{\n\t\t \n\t      long x;\n\t      long y,k;\n\t      int i,h;\n\t      String s;\n\t\tPair (long x,long y,int i){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t\tthis.i=i;\n\t\t}\n\t        \n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(this.x!=o.x)\n\t\t\t\treturn Long.compare(this.x,o.x);\n\t\t\treturn Long.compare(this.y,o.y);\n\t\t}\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (o instanceof Pair) {\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\tpublic int hashCode() {\n\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode() ;\n\t\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(x%y==0)\n\t\t\treturn y;\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\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 main().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\n\t\t}\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\t\n\t\tprivate long[] nl(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] = nl();\n\t\t\treturn a;\n\t\t}\n\t\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "/*\n * \n * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)\n * Dhirubhai Ambani Institute of Information And Communication Technology \n * \n */\n\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\npublic class Code3\n{\n\t\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\t\n\t\tlong x = in.nextLong();\n\t\tlong k = in.nextLong();\n\t\t\n\t\tif(x==0)\n\t\t\tpw.println(0);\n\t\telse\n\t\t{\n\t\t\tlong mul = modularExponentiation(2L, k, mod);\n\t\t\tx = (x%mod * 2L%mod)%mod;\n\t\t\tx = (x%mod - 1L%mod + mod)%mod;\n\t\t\tx = (x%mod * mul%mod)%mod;\n\t\t\tx = (x%mod + 1%mod)%mod; \n\t\t\tpw.print(x);\n\t\t}\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic class InputReader \n\t{\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{\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() \n\t\t{\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) \n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() \n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t    {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong()\n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nextIntArray(int n) \n\t\t{\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String readString()\n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() \n\t\t{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) \n\t\t{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter\n\t    {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\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<n;i++)\n\t\t{\n\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\tint temp = a[ind];\n\t\t\ta[ind] = a[i];\n\t\t\ta[i] = temp;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\tpublic static void swap(int a, int b){\n\t\tint temp = a;\n\t\ta = b;\n\t\tb = temp;\n\t}\n\t\n\tpublic static HashSet<Integer> primeFactorization(int n)\n\t{\n\t\tHashSet<Integer> a =new HashSet<Integer>();\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<n;i++)\n\t\t\tisPrime[i] = true;\n\t\t\n\t\tisPrime[0] = false;\n\t\tisPrime[1] = false;\n\t\t\n\t\tfor(int i=2;i*i<n;i++)\n\t\t{\n\t\t\tif(isPrime[i] == true)\n\t\t\t{\n\t\t\t\tfor(int j=(2*i);j<n;j+=i)\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t}\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\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 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<pair>\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n\n    long mod = (long) (1e9 + 7);\n\n    void solve() throws Throwable {\n        long x = readLong(), k = readLong();\n        if (x == 0) {\n            System.out.println(0);\n            return;\n        }\n        long r = solveFast(x, k);\n        //long r2 = solveSlow(x, k) % mod;\n        System.out.println(r);\n        //System.out.println(r2);\n    }\n\n    private long solveSlow(long x, long k) {\n        List<Long> a = new ArrayList<>();\n        a.add(x);\n        for (int i = 0; i < k; i++) {\n            dodouble(a);\n            a = eat(a);\n        }\n        dodouble(a);\n        long sum = 0;\n        for (Long v : a) {\n            sum = (sum + v) % mod;\n        }\n        return sum * rev(a.size(), mod) % mod;\n    }\n\n    private List<Long> eat(List<Long> a) {\n        List<Long> r = new ArrayList<>();\n        for (Long v : a) {\n            r.add(v);\n            r.add((v - 1 + mod) % mod);\n        }\n        return r;\n    }\n\n    private void dodouble(List<Long> a) {\n        for (int i = 0; i < a.size(); i++) {\n            a.set(i, a.get(i) * 2 % mod);\n        }\n    }\n\n    private long solveFast(long x, long k) {\n        long n = binpow(2, k, mod);\n        long ma = (binpow(2, k + 1, mod) * (x % mod)) % mod;\n        long mi = (ma - n * 2 + 2 + mod * 100) % mod;\n        return ((ma + mi) * rev(2, mod)) % mod;\n    }\n\n    private long rev(long a, long mod) {\n        return binpow(a, mod - 2, mod);\n    }\n\n    //-------------------------------------------------\n\n    final boolean ONLINE_JUDGE = !new File(\"input.txt\").exists();\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok;\n\n    public void run() {\n        Runnable run = () -> {\n            try {\n                long startTime = System.currentTimeMillis();\n                Locale.setDefault(Locale.US);\n                if (ONLINE_JUDGE) {\n                    in = new BufferedReader(new InputStreamReader(System.in));\n                    out = new PrintWriter(System.out);\n                } else {\n                    in = new BufferedReader(new FileReader(\"input.txt\"));\n                    out = new PrintWriter(\"output.txt\");\n                }\n                tok = new StringTokenizer(\"\");\n                solve();\n                in.close();\n                out.close();\n                long endTime = System.currentTimeMillis();\n                long totalMemory = Runtime.getRuntime().totalMemory();\n                long freeMemory = Runtime.getRuntime().freeMemory();\n                System.err.println();\n                System.err.println(\"Time = \" + (endTime - startTime) + \" ms\");\n                //System.err.println(\"Memory = \" + ((totalMemory - freeMemory) / 1024) + \" KB\");\n            } catch (Throwable e) {\n                e.printStackTrace(System.err);\n                System.exit(-1);\n            }\n        };\n        new Thread(null, run, \"run\", 256 * 1024 * 1024).start();\n        min(0, 0);\n    }\n\n    String readString() {\n        while (!tok.hasMoreTokens()) {\n            String line;\n            try {\n                line = in.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n            if (line == null) return null;\n            tok = new StringTokenizer(line);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt() {\n        return Integer.parseInt(readString());\n    }\n\n    long readLong() throws IOException {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() throws IOException {\n        return Double.parseDouble(readString());\n    }\n\n    void debug(Object... o) {\n        if (!ONLINE_JUDGE) {\n            System.err.println(Arrays.deepToString(o));\n        }\n    }\n\n    /*long binpow(long a, long n) {\n        long r = 1;\n        while (n > 0) {\n            if ((n & 1) > 0) {\n                r *= a;\n            }\n            a *= a;\n            n /= 2;\n        }\n        return r;\n    }/**/\n\n    long binpow(long a, long n, long mod) {\n        long r = 1;\n        while (n > 0) {\n            if ((n & 1) > 0) {\n                r = (r * a) % mod;\n            }\n            a = (a * a) % mod;\n            n /= 2;\n        }\n        return r;\n    }/**/\n\n    static long gcd(long x, long y) {\n        return y == 0 ? x : gcd(y, x % y);\n    }\n\n    private long[] readLongArray(int n) throws IOException {\n        long[] a = new long[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = readLong();\n        }\n        return a;\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 kanak893\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\tstatic class TaskC {\n\t\tpublic void solve(int testNumber, InputReader fi, PrintWriter out) {\n\t\t\tlong n, k;\n\t\t\tn = fi.nextLong();\n\t\t\tk = fi.nextLong();\n\t\t\tlong ans = 2 * n;\n\t\t\tlong mod = (long) Math.pow(10, 9) + 7;\n\n\t\t\tif (k > 0) {\n\t\t\t\tans = (modulus(modulus(pow(2, k + 1, mod), mod) * modulus(n, mod), mod));\n\t\t\t\tlong temp = modulus(pow(2, k, mod) - 1, mod);\n\t\t\t\tans = modulus(modulus(ans, mod) - modulus(temp, mod), mod);\n\n\t\t\t}\n\t\t\tif (n == 0) {\n\t\t\t\tans = 0;\n\t\t\t}\n\t\t\tans=ans%mod;\n\t\t\tout.println(ans);\n\t\t}\n\n\t\tstatic long pow(long x, long y, long mod) {\n\t\t\tif (y == 0) return 1 % mod;\n\t\t\tif (y == 1) return x % mod;\n\t\t\tlong res = 1;\n\t\t\tx = x % mod;\n\t\t\twhile (y > 0) {\n\t\t\t\tif ((y % 2) != 0) {\n\t\t\t\t\tres = (res * x) % mod;\n\t\t\t\t}\n\t\t\t\ty = y / 2;\n\t\t\t\tx = (x * x) % mod;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tstatic long modulus(long a, long mod) {\n\t\t\treturn (a % mod + mod) % mod;\n\t\t}\n\n\t}\n\n\tstatic class InputReader {\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 InputReader.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 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 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\n\t\t}\n\n\t}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import sun.rmi.transport.DGCImpl_Stub;\n\nimport java.io.*;\nimport java.nio.file.ClosedWatchServiceException;\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\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<List<Integer>> gr = new ArrayList<>();\n    long MOD = 1_000_000_007;\n\n    public void solve() {\n        long x = io.readLong(), k = io.readLong();\n        if(x==0){\n            io.writeLine(\"0\");\n            return;\n        }\n\n        long res = ((pow(2, k+1, MOD) * (x % MOD)) % MOD - pow(2, k, MOD) % MOD + 1 + MOD) % MOD;\n        io.writeLine(res+\"\");\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\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 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<n.length;i++)r[i]=Long.parseLong(n[i]);\n        return r;\n    }\n    public int[] readIntArray() {\n        String[]n=this.readLine().trim().split(\"\\\\s+\");int[]r=new int[n.length];\n        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);\n        return r;\n    }\n    public int[] readIntArray(int n) {\n        int[] res = new int[n];\n        char[] all = this.readLine().toCharArray();\n        int cur = 0;boolean have = false;\n        int k = 0;\n        boolean neg = false;\n        for(int i = 0;i<all.length;i++){\n            if(all[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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner scan=new Scanner(System.in);\n\t\tlong x=scan.nextLong();\n\t\tlong k=scan.nextLong();\n\t\tlong MOD=1000000007;\n\t\tif(x==0){System.out.println(0);return;}\n\t\tx%=MOD;\n\t\tlong a=(new Num()).pow(2L,k+1);\n\t\tlong b=(new Num()).pow(2L,k);\n\t\tlong res=(a*x)%MOD-b+1;\n\t\tif(res<0){res+=MOD;}\n\t\tSystem.out.println(res%MOD);\n\t}\n}\n\nclass Num{\n\tlong MOD=1000000007;\n\tlong pow(long x,long k){\n\t\tlong base=x%MOD;\n\t\tlong res=1;\n\t\twhile(k>0){\n\t\t\tif((k&1)==1){\n\t\t\t\tres=(res*base)%MOD;\n\t\t\t}\n\t\t\tbase=(base*base)%MOD;\n\t\t\tk>>=1;\n\t\t}\n\t\treturn res;\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\tstatic BigInteger tow=new BigInteger(\"2\"),mod=new BigInteger(\"1000000007\");\n\tstatic BigInteger pow(BigInteger a,BigInteger b) {\n\t\tif(b.equals(BigInteger.ZERO))return BigInteger.ONE;\n\t\tBigInteger x=pow(a,b.divide(tow));\n\t\tif(b.mod(tow).equals(BigInteger.ZERO)) \n\t\t\treturn x.mod(mod).multiply(x.mod(mod)).mod(mod);\n\t\telse \n\t\t\treturn x.mod(mod).multiply(x.mod(mod)).mod(mod).multiply(a).mod(mod);\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBigInteger x=in.RB(),k=in.RB();\n\t\tif(k.equals(BigInteger.ZERO))System.out.println(x.multiply(tow).mod(mod));\n\t\telse if(x.equals(BigInteger.ZERO))System.out.println(0);\n\t\telse {\n\t\t\tBigInteger x1=tow.multiply(x).subtract(BigInteger.ONE);\n\t\t\tx1=x1.mod(mod);\n\t\t\tBigInteger x2=pow(tow,k);\n\t\t\tx2=x2.mod(mod);\n\t\t\tSystem.out.println(x1.multiply(x2).add(BigInteger.ONE).mod(mod));\n\t\t\t\n\t\t}\n\t}\n}\n\n\nclass in{\n\tstatic StringTokenizer st=new StringTokenizer(\"\");\n\tstatic BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n\tstatic String next() throws IOException {\n\t\twhile(!st.hasMoreTokens())st=new StringTokenizer(bf.readLine());\n\t\treturn st.nextToken();\n\t}\n\tstatic int RI() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\tstatic BigInteger RB() throws IOException {\n\t\treturn new BigInteger(next());\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n    static StringTokenizer tok;\n    static boolean hasNext()\n    {\n        while(tok==null||!tok.hasMoreTokens())\n            try{\n                tok=new StringTokenizer(in.readLine());\n            }\n            catch(Exception e){\n                return false;\n            }\n        return true;\n    }\n    static String next()\n    {\n        hasNext();\n        return tok.nextToken();\n    }\n    static long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n    static int nextInt()\n    {\n        return Integer.parseInt(next());\n    }\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));\n\n    public static void main(String args []){\n        long x = nextLong();\n        long a = 2, b = nextLong(), c = 1000000000+7;\n        long res = 1;\n        a %= c;\n        if (x==0){\n            out.println(0);\n            out.flush();\n            return;\n        }\n        for (; b != 0; b /= 2) {\n            if (b % 2 == 1)\n                res = (res * a) % c;\n            a = (a * a) % c;\n        }\n        BigInteger r = new BigInteger(String.valueOf(res));\n        BigInteger y = new BigInteger(String.valueOf(x));\n        BigInteger ans = y.multiply(new BigInteger(\"2\")).subtract(new BigInteger(\"1\")).multiply(r).add(new BigInteger(\"1\")).mod(new BigInteger(String.valueOf(c)));\n        out.println(ans);\n        out.flush();\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\n\npublic class Main {\n\t\n\tstatic long MOD = (long) 1e9 + 7;\n\tstatic long[][] identity = {{1, 0}, {0, 1}};\n\t\n\tpublic static void main(String[] args) {\n\t\tFastScanner input = new FastScanner(System.in);\n\t\t\n\t\tlong x = input.nextLong();\n\t\tlong k = input.nextLong();\n\t\t\n\t\tlong[][] matrix = {\n\t\t\t{2, MOD - 1},\n\t\t\t{0, 1}\n\t\t};\n\t\t\n\t\tif (x == 0)\n\t\t\tSystem.out.println(0);\n\t\telse if (k == 0) {\n\t\t\tSystem.out.println((x * 2) % MOD);\n\t\t} else {\n\t\t\tx %= MOD;\n\t\t\tmatrix = matrixexpo(k, matrix);\n\t\t\tlong low = (x * matrix[0][0] + matrix[0][1]) % MOD;\n\t\t\tlong hi = x * mathpow(k, 2) % MOD;\n\t\t\tSystem.out.println((low + hi) % MOD);\n\t\t}\n\t}\n\t\n\tstatic long mathpow(long k, long x) {\n\t\tif (k == 0)\n\t\t\treturn 1L;\n\t\telse return mathpow(k / 2, (x * x) % MOD) * (k % 2 == 1 ? x : 1) % MOD;\n\t}\n\t\n\tstatic long[][] matrixexpo(long k, long[][] matrix) { \n\t\tif (k == 0)\n\t\t\treturn identity;\n\t\tif (k % 2 == 0)\n\t\t\treturn matrixexpo(k / 2, multiply(matrix, matrix));\n\t\telse\n\t\t\treturn multiply(matrix, matrixexpo(k / 2, multiply(matrix, matrix)));\n\t}\n\t\n\tstatic long[][] multiply(long[][] arr, long[][] brr) { \n\t\tint n = arr.length, m = arr[0].length, p = brr[0].length;\n\t\t\n\t\tlong[][] product = new long[n][p];\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < p; j++)\n\t\t\t\tfor (int k = 0; k < m; k++)\n\t\t\t\t\tproduct[i][j] = (product[i][j] + arr[i][k] * brr[k][j]) % MOD;\n\t\treturn product;\n\t}\n\t\n\t// Matt Fontaine's Fast IO\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\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\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 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\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}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\n\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.io.*;\n\npublic class Test5{\n\n    static long mod=1000000007;\n\n    public static void main(String[] z) throws Exception{\n        Scanner s = new Scanner(System.in);\n        long a = s.nextLong(), b=s.nextLong(), c=(a*2-1)%mod, i=binpow(2,b)%mod;\n        System.out.println(a<1 ? a : (c*i+1)%mod);\n    }\n\n    static long binpow(long c, long step){\n        if(step==0) return 1;\n        if(step==1) return c%mod;\n        if(step%2<1){\n            return binpow(((c%mod)*(c%mod))%mod, step/2)%mod;\n        }\n        else{\n            return (c%mod)*(binpow(c%mod, step-1)%mod);\n        }\n    }\n\n    static class PyraSort {\n\n        private static int heapSize;\n\n        public static void sort(int[] 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(int[] 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(int[] 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(int[] a, int i, int j) {\n            a[i] ^= a[j] ^= a[i];\n            a[j] ^= a[i];\n        }\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 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        CNastyaAndAWardrobe solver = new CNastyaAndAWardrobe();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class CNastyaAndAWardrobe {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            long mod = (long) (1e9 + 7);\n            long n = in.nextLong();\n            long k = in.nextLong();\n            if (n == 0) {\n                out.println(0);\n                return;\n            }\n            long c = (((2 * n - 1) % mod) * pow(2L, k, mod)) % mod + 1;\n            c %= mod;\n            out.println(c);\n        }\n\n        public long pow(long a, long b, long mod) {\n            long result = 1;\n            while (b > 0) {\n                if (b % 2 != 0) {\n                    result *= a;\n                    result %= mod;\n                    b--;\n                }\n                a *= a;\n                a %= mod;\n                b /= 2;\n            }\n\n            return result % mod;\n\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader br;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream inputStream) {\n            br = new BufferedReader(new InputStreamReader(inputStream));\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 long nextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class prob\n{\n\t\t\n\tpublic static long ans(long x, long y, long p)\n    {\n        long r = 1;     \n        x = x % p;\n        while (y > 0)\n        {\n            if((y & 1)==1)\n                r = (r * x) % p;\n            y = y >> 1; \n            x = (x * x) % p; \n        }\n        return r;\n    }\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong x = scan.nextLong();\n\t\tlong k = scan.nextLong();\n\t\tlong v = 1000000007L;\n\t\tif(x>0){\n\t\t\tlong p = ((2*x)-1)%v;\n\t\t\tlong a = ans(2L,k,v);\n\t\t\tlong b = (p*a)%v;\n\t\t\tSystem.out.println((b+1)%v);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(0);\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n/**\n * Created by artur on 18/06/18\n */\npublic class A\n{\n    private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    private StringTokenizer tokenizer = null;\n\n    long mod = 1000000007;\n\n    public static void main(String[] args) throws IOException\n    {\n        new A().solve();\n    }\n\n    private void solve() throws IOException\n    {\n        long x = nl();\n        long k = nl();\n\n        if (x == 0)\n        {\n            System.out.println(0);\n            System.exit(0);\n        }\n\n        if (k == 0)\n        {\n            System.out.println((x * 2) % mod);\n            System.exit(0);\n        }\n\n//        for (int sx = 0; sx < 100; sx++)\n//        {\n//            for (int sk = 0; sk < 100; sk++)\n//            {\n//                BigInteger n = BigInteger.valueOf(2)\n//                        .modPow(BigInteger.valueOf(k + 1), BigInteger.valueOf(mod))\n//                        .multiply(BigInteger.valueOf(x))\n//                        .add(BigInteger.ONE)\n//                        .subtract(BigInteger.valueOf(2)\n//                                .modPow(BigInteger.valueOf(k), BigInteger.valueOf(mod)))\n//                        .mod(BigInteger.valueOf(mod));\n//                long res = n.longValue();\n//\n//                long aux = aux(sx, sk);\n//                if ((res % mod) != aux) {\n//                    System.out.println(sx + \" \" + sk + \": \" + res + \" \" + aux);\n//                }\n//            }\n//        }\n\n        BigInteger n = BigInteger.valueOf(2)\n                .modPow(BigInteger.valueOf(k + 1), BigInteger.valueOf(mod))\n                .multiply(BigInteger.valueOf(x))\n                .add(BigInteger.ONE)\n                .subtract(BigInteger.valueOf(2)\n                        .modPow(BigInteger.valueOf(k), BigInteger.valueOf(mod)))\n                .mod(BigInteger.valueOf(mod));\n\n        System.out.println(n.toString());\n    }\n\n    long aux(long x, long k) {\n        long p1 = 2 * x;\n        long p2 = 2 * x - 1;\n\n        for (int i = 0; i < k - 1; i++)\n        {\n            p1 = (p1 * 2) % mod;\n            p2 = (p2 * 2 - 1) % mod;\n        }\n\n        return ((p1 + p2) % mod);\n    }\n\n    void debug(Object... os)\n    {\n        System.out.println(Arrays.deepToString(os));\n    }\n\n    int ni() throws IOException\n    {\n        return Integer.parseInt(ns());\n    }\n\n    long nl() throws IOException\n    {\n        return Long.parseLong(ns());\n    }\n\n    double nd() throws IOException\n    {\n        return Double.parseDouble(ns());\n    }\n\n    String ns() throws IOException\n    {\n        while (tokenizer == null || !tokenizer.hasMoreTokens())\n            tokenizer = new StringTokenizer(br.readLine());\n        return tokenizer.nextToken();\n    }\n\n    String nline() throws IOException\n    {\n        tokenizer = null;\n        return br.readLine();\n    }\n\n    private static long gcd(long a, long b)\n    {\n        while (b > 0)\n        {\n            long temp = b;\n            b = a % b; // % is remainder\n            a = temp;\n        }\n        return a;\n    }\n\n    private static long lcm(long a, long b)\n    {\n        return a * (b / gcd(a, b));\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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.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 ArrayList<Long> xx ;\t\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tScanner sc =  new Scanner(System.in) ;\n\n\t\tlong x = sc.nextLong() ; \n\t\tlong k = sc.nextLong() ; \n\t\tif(x==0)\n\t\t{System.out.println(0); return ;}\n\t\tif(k==0)\n\t\t{System.out.println((2l*x)%mod);return ;}\t\n\n\n\t\tlong m=pow(2,k);\n\n\n\t\tlong a = 2l*(x%mod)*(m%mod);\n\n\n\t\ta = a-m+1 ;\n\n\t\ta=a%mod ; \n\t\tif(a<0)a=(a%mod + mod) % mod;\n\n\t\tSystem.out.println(a);\n\n\n\n\n\n\t}\n\n\t// method to print the divisors\n\tstatic ArrayList<Long> divisors(long n)\n\t{\n\t\tArrayList<Long> arr =  new ArrayList<Long>() ; \n\t\t// Note that this loop runs till square root\n\t\tfor (int i=1; i<=Math.sqrt(n); i++)\n\t\t{\n\t\t\tif (n%i==0)\n\n\t\t\t\t// If divisors are equal, print only one\n\t\t\t\tif (n/i == i)\n\t\t\t\t{arr.add(1l*i);arr.add(1l*i);}\n\n\t\t\t\telse // Otherwise print both\n\t\t\t\t{arr.add(1l*i); arr.add(1l*n/i);}\n\n\t\t}\t\n\n\t\treturn arr ;\n\n\t}\n\n\tpublic static void generate(long current)\n\t{\n\t\tif(current>10000000000l)\n\t\t\treturn ; \n\n\t\txx.add(current) ; \n\t\tgenerate((10*current) +4); \n\t\tgenerate((10*current) +7);\n\n\n\t}\n\n\tpublic static int neededFromLeft(String x)\n\t{\n\t\tStack<Character> st = new Stack<Character>() ; \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<Character> st = new Stack<Character>() ; \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<Character> st = new Stack<Character>() ;\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<Character> st = new Stack<Character>() ; \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, long k) {\n\t\tlong res = 1;\n\t\twhile(k > 0) {\n\t\t\tif(k % 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\tk /= 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<pair> 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;i<n;i++)\n\t\t\tfor(int j=0 ; j<i; j++)\n\t\t\t\tif (a[i]>a[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<n ; i++)\n\t\t\tif (max < lis[i])\n\t\t\t\tmax = lis[i] ;\n\t\treturn (max);\n\n\t\t//\t\t\tArrayList<Integer> s = new ArrayList<Integer>() ;\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<Long> getDiv(Long n)\n\t{\n\t\tArrayList<Long>  f = new ArrayList<Long>() ; \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<Vertix> 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<Vertix> () ;\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<pair> {\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<pair2>{\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<point>\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+(y%2) ;\n\t\t}\n\n\n\n\t}\n\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static final class TaskC {\n        private static final int MODULO = 1_000_000_000 + 7;\n\n        public void solve(int __, InputReader in, PrintWriter out) {\n            long qty = in.nextLong();\n            long months = in.nextLong();\n            if (qty == 0) {\n                out.println(0);\n                return;\n            }\n            qty %= MODULO;\n            long pow = pow(2, months + 1);\n            qty = (qty * pow) % MODULO;\n            long sub = (pow - 2 + MODULO) % MODULO * pow(2, MODULO - 2) % MODULO;\n            qty = (qty - sub + MODULO) % MODULO;\n            out.println(qty);\n        }\n\n        private long pow(long base, long power) {\n            long result = 1;\n            while (power > 0) {\n                if ((power & 1) != 0) {\n                    result = (result * base) % MODULO;\n                }\n                base = (base * base) % MODULO;\n                power >>>= 1;\n            }\n            return result;\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 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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class C {\n    public static void main(String[] args) throws Exception {\n        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n        // Scanner scan = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        // int n = Integer.parseInt(bf.readLine());\n        StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n\n        long n = Long.parseLong(st.nextToken());\n        long k = Long.parseLong(st.nextToken());\n        int mod = 1000000007;\n\n        if(n == 0) {\n          out.println(0);\n          out.close(); System.exit(0);\n        }\n        n %= mod;\n\n        long ans = exp(2, (int)((k+1) % (mod-1)), mod);\n        ans = (1L*ans * n) % mod;\n        ans = ans + mod + 1 - exp(2, (int)((k) % (mod-1)), mod);\n        ans %= mod;\n        out.println(ans);\n        // int n = scan.nextInt();\n\n        out.close(); System.exit(0);\n    }\n    public static int exp(int base, int e, int mod) {\n      if(e == 0) return 1;\n      if(e == 1) return base;\n      int val = exp(base, e/2, mod);\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}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\nimport java.util.*;\n\n\n\npublic class ModifyLongest {\n\n    InputStream is;\n\n    PrintWriter out;\n\n    String INPUT = \"\";\n\n    //boolean codechef=true;\n\n    boolean codechef=true;\n\n    void solve()\n    {\n        /*\n        long l=ni(),r=ni(),x=ni(),y=ni();\n        long prod=x;\n        prod*=y;\n        int cnt=0;\n        if(l==r && r==x && x==y && x==1)\n        {\n            System.out.println(1);\n            return;\n        }\n        //HashSet<Long> set=new HashSet<>();\n        for(long i=2;i<=Math.sqrt(prod);i++)\n        {\n            if(prod%i==0)\n            {\n                if(Math.min(i,prod/i)>=l && Math.max(i,prod/i)<=r && gcd(i,prod/i)==x)\n                {\n                    //set.add(fnc2(i,prod/i));\n                    //set.add(fnc2(prod/i,i));\n                    if(i!=prod/i)cnt+=2;\n                    else cnt++;\n                }\n            }\n        }\n        ArrayList<Long> factors=new ArrayList<>();\n        while(prod!=1)\n        {\n            long currF=PollardRho(prod);\n            while(prod%currF!=0)\n            {\n                prod/=currF;\n                factors.add(currF);\n            }\n\n        }\n\n        if(l==1)\n        {\n            System.out.println((cnt+2));\n        }\n        else\n        {\n            System.out.println(cnt);\n        }\n\n*/\n        long mod=1000000007;\n        long x=nl(),k=nl();\n        if(x==0)\n        {\n            System.out.println(0);\n            return;\n        }\n        long val=calc((pow(2,k,mod)*(x%mod))%mod);\n        val-=calc(((pow(2,k,mod)*(x%mod))%mod-(pow(2,k,mod)-1)-1+mod)%mod);\n        //val*=2;\n\n        val=(val+mod)%mod;\n        val=(val*inv(pow(2,k,mod),mod))%mod;\n        System.out.println(val);\n\n    }\n\n    static long calc(long a)\n    {\n        long b=(a*(a+1))%1000000007;\n        return b;\n    }\n\n\n    /* method to return prime divisor for n */\n    long PollardRho(long n)\n    {\n        /* initialize random seed */\n        //srand (time(NULL));\n\n        /* no prime divisor for 1 */\n        if (n==1) return n;\n\n        /* even number means one of the divisors is 2 */\n        if (n % 2 == 0) return 2;\n        Random r=new Random();\n        /* we will pick from the range [2, N) */\n        long x = (r.nextLong()%(n-2))+2;\n        long y = x;\n\n        /* the constant in f(x).\n         * Algorithm can be re-run with a different c\n         * if it throws failure for a composite. */\n        long c = (r.nextLong()%(n-1))+1;\n\n        /* Initialize candidate divisor (or result) */\n        long d = 1;\n\n    /* until the prime factor isn't obtained.\n       If n is prime, return n */\n        while (d==1)\n        {\n            /* Tortoise Move: x(i+1) = f(x(i)) */\n            x = (pow(x, 2, n) + c + n)%n;\n\n            /* Hare Move: y(i+1) = f(f(y(i))) */\n            y = (pow(y, 2, n) + c + n)%n;\n            y = (pow(y, 2, n) + c + n)%n;\n\n            /* check gcd of |x-y| and n */\n            d = gcd(Math.abs(x-y), n);\n\n            /* retry if the algorithm fails to find prime factor\n             * with chosen x and c */\n            if (d==n) return PollardRho(n);\n        }\n\n        return d;\n    }\n\n    static HashMap<Long,HashSet<Long>> globalSet;\n\n\n\n\n\n    static long fnc(int a,int b)\n\n    {\n\n        long val=Math.min(a,b)*1000000007;\n\n        val+=Math.max(a,b);\n\n        return val;\n\n    }\n\n\n\n    static long fnc2(long a,long b)\n\n    {\n\n        long val=a*1000000007;\n\n        val+=b;\n\n        return val;\n\n    }\n\n\n\n\n\n    static class Pair\n\n    {\n\n        int a,b;\n\n        public Pair(int a,int b)\n\n        {\n\n            this.a=a;\n\n            this.b=b;\n\n        }\n\n    }\n\n\n\n    static int bit[];\n\n\n\n    static void add(int x,int d,int n)\n\n    {\n\n        for(int i=x;i<=n;i+=i&-i)bit[i]+=d;\n\n    }\n\n\n\n    static int query(int x)\n\n    {\n\n        int ret=0;\n\n        for(int i=x;i>0;i-=i&-i)\n\n            ret+=bit[i];\n\n        return ret;\n\n    }\n\n\n\n    static long lcm(int a,int b)\n\n    {\n\n        long val=a;\n\n        val*=b;\n\n        return (val/gcd(a,b));\n\n    }\n\n\n\n    static long gcd(long a,long b)\n\n    {\n\n        if(a==0)return b;\n\n        return gcd(b%a,a);\n\n    }\n\n\n\n    static long pow(long a, long b, long p)\n\n    {\n\n        long ans = 1, base = a;\n\n        while (b!=0)\n\n        {\n\n            if ((b & 1)!=0)\n\n            {\n\n                ans *= base;\n\n                ans%= p;\n\n            }\n\n            base *= base;\n\n            base%= p;\n\n            b >>= 1;\n\n        }\n\n        return ans;\n\n    }\n\n\n\n    static long inv(long x,long p)\n\n    {\n\n        return pow(x, (int)p - 2, p);\n\n    }\n\n\n\n\n\n    void run() throws Exception\n\n    {\n\n        if(codechef)oj=true;\n\n        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\n        out = new PrintWriter(System.out);\n\n\n\n        long s = System.currentTimeMillis();\n\n        solve();\n\n        out.flush();\n\n        tr(System.currentTimeMillis()-s+\"ms\");\n\n    }\n\n\n\n    public static void main(String[] args) throws Exception {new ModifyLongest().run();}\n\n\n\n    private byte[] inbuf = new byte[1024];\n\n    public int lenbuf = 0, ptrbuf = 0;\n\n\n\n    private int readByte()\n\n    {\n\n        if(lenbuf == -1)throw new InputMismatchException();\n\n        if(ptrbuf >= lenbuf){\n\n            ptrbuf = 0;\n\n            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\n            if(lenbuf <= 0)return -1;\n\n        }\n\n        return inbuf[ptrbuf++];\n\n    }\n\n\n\n    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\n    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n\n\n    private double nd() { return Double.parseDouble(ns()); }\n\n    private char nc() { return (char)skip(); }\n\n\n\n    private String ns()\n\n    {\n\n        int b = skip();\n\n        StringBuilder sb = new StringBuilder();\n\n        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\n            sb.appendCodePoint(b);\n\n            b = readByte();\n\n        }\n\n        return sb.toString();\n\n    }\n\n\n\n    private char[] ns(int n)\n\n    {\n\n        char[] buf = new char[n];\n\n        int b = skip(), p = 0;\n\n        while(p < n && !(isSpaceChar(b))){\n\n            buf[p++] = (char)b;\n\n            b = readByte();\n\n        }\n\n        return n == p ? buf : Arrays.copyOf(buf, p);\n\n    }\n\n\n\n    private char[][] nm(int n, int m)\n\n    {\n\n        char[][] map = new char[n][];\n\n        for(int i = 0;i < n;i++)map[i] = ns(m);\n\n        return map;\n\n    }\n\n\n\n    private int[] na(int n)\n\n    {\n\n        int[] a = new int[n];\n\n        for(int i = 0;i < n;i++)a[i] = ni();\n\n        return a;\n\n    }\n\n\n\n    private int ni()\n\n    {\n\n        int num = 0, b;\n\n        boolean minus = false;\n\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\n        if(b == '-'){\n\n            minus = true;\n\n            b = readByte();\n\n        }\n\n\n\n        while(true){\n\n            if(b >= '0' && b <= '9'){\n\n                num = num * 10 + (b - '0');\n\n            }else{\n\n                return minus ? -num : num;\n\n            }\n\n            b = readByte();\n\n        }\n\n    }\n\n\n\n    private long nl()\n\n    {\n\n        long num = 0;\n\n        int b;\n\n        boolean minus = false;\n\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\n        if(b == '-'){\n\n            minus = true;\n\n            b = readByte();\n\n        }\n\n\n\n        while(true){\n\n            if(b >= '0' && b <= '9'){\n\n                num = num * 10 + (b - '0');\n\n            }else{\n\n                return minus ? -num : num;\n\n            }\n\n            b = readByte();\n\n        }\n\n    }\n\n\n\n    private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tprivate void solve() throws IOException {\n\n\t\tout.println(solve(nl()));\n\t\tout.close();\n\n\t}\n\n\tprivate long solve(long n) throws IOException {\n\t\tif (n > 0) {\n\t\t\tn <<= 1;\n\t\t\tlong k = nl();\n\t\t\tn--;\n\t\t\tint M = 1000000007;\n\t\t\tlong p = power(2, k, M);\n\t\t\t// Helper.tr(n * p + 1);\n\t\t\tn = (n % M * p + 1) % M;\n\t\t}\n\t\treturn n;\n\t}\n\n\tlong power(long a, long b, long mod) {\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\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tprivate int[][] na(int n) throws IOException {\n\t\tint[][] a = new int[n][2];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i][0] = ni();\n\t\t\ta[i][1] = i;\n\t\t}\n\t\treturn a;\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\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\n\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.util.HashMap;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.Iterator;\nimport java.util.Vector;\n\n\n\n\n\npublic class con67 {\n\t\n\n\t\n\t\n\tpublic static void main(String[] args) throws IOException \n\t{\n//\tSystem.out.println(power(2,9,1000000007));\n\tlong x=l();\n\tlong k=l();\nif(x!=0)\n{\n\tlong f=x%1000000007;\n\tlong s=(f*power(2,k+1,1000000007))%1000000007;\n\t//out.println(s);\n\tlong e=\t(power(2,k,1000000007)-1)%1000000007;\n\t//out.println(e);\n\tlong ans=(s-e+1000000007)%1000000007;\n\t\n\tout.println(ans);\n\t\n}\nelse\n{\n\tout.println(0);\n}\n\tout.close();\n\t}\n\t \n\tstatic long power(long x, long y, long p)\n    {\n        // Initialize result\n        long res = 1;     \n        \n        // Update x if it is more  \n        // than or equal to p\n        x = x % p; \n     \n        while (y > 0)\n        {\n            // If y is odd, multiply x\n            // with result\n            if((y & 1)==1)\n                res = (res * x) % p;\n     \n            // y must be even now\n            // y = y / 2\n            y = y >> 1; \n            x = (x * x) % p; \n        }\n        return res;\n    }\n\t  \n\t static InputReader in = new InputReader(System.in);\n\t    static OutputWriter out = new OutputWriter(System.out);\n\t    \n\t    static int i()\n\t    {\n\t    \treturn in.readInt();\n\t    }\n\t    \n\t    static long l()\n\t    {\n\t    \treturn in.readLong();\n\t    }\n\t    \n\t    static double d()\n\t    {\n\t    \treturn in.readDouble();\n\t    }\n\t    \n\t    static String s()\n\t    {\n\t    \treturn in.readString();\n\t    }\n\t    \n\t    static void Iarr( int[] array, int no )\n\t    {\n\t    \tfor( int i=0 ; i<no ; i++ )\n\t    \t{\n\t    \t\tarray[i] = i(); \n\t    \t}\n\t    }\n\t    \n\t    static void Larr( long[] array, int no )\n\t    {\n\t    \tfor( int i=0 ; i<no ; i++ )\n\t    \t{\n\t    \t\tarray[i] = l(); \n\t    \t}\n\t    }\n\t    \n\t    static void Darr( double[] array, int no )\n\t    {\n\t    \tfor( int i=0 ; i<no ; i++ )\n\t    \t{\n\t    \t\tarray[i] = d(); \n\t    \t}\n\t    }\n\t    \n\t    static void Sarr( String[] array, int no )\n\t    {\n\t    \tfor( int i=0 ; i<no ; i++ )\n\t    \t{\n\t    \t\tarray[i] = s(); \n\t    \t}\n\t    }\n\t    \n\t    private static class InputReader\n\t    {\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\t \n\t        public InputReader(InputStream stream)\n\t        {\n\t            this.stream = stream;\n\t        }\n\t \n\t        \n\t        \n\t        \n\t        \n\t        \n\t        \n\t        public int read()\n\t        {\n\t            if (numChars == -1)\n\t                throw new InputMismatchException();\n\t            if (curChar >= numChars)\n\t            {\n\t                curChar = 0;\n\t                try\n\t                {\n\t                    numChars = stream.read(buf);\n\t                } catch (IOException e)\n\t                {\n\t                    throw new InputMismatchException();\n\t                }\n\t                if (numChars <= 0)\n\t                    return -1;\n\t            }\n\t            return buf[curChar++];\n\t        }\n\t \n\t        public int readInt()\n\t        {\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            {\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                    throw new InputMismatchException();\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 String readString()\n\t        {\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            {\n\t                res.appendCodePoint(c);\n\t                c = read();\n\t            } while (!isSpaceChar(c));\n\t            return res.toString();\n\t        }\n\t        public double readDouble() {\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, readInt());\n\t                if (c < '0' || c > '9')\n\t                    throw new InputMismatchException();\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, readInt());\n\t                    if (c < '0' || c > '9')\n\t                        throw new InputMismatchException();\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\t        public long readLong() {\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                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        public boolean isSpaceChar(int c)\n\t        {\n\t            if (filter != null)\n\t                return filter.isSpaceChar(c);\n\t            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t        }\n\t \n\t        public String next()\n\t        {\n\t            return readString();\n\t        }\n\t \n\t        public interface SpaceCharFilter\n\t        {\n\t            public boolean isSpaceChar(int ch);\n\t        }\n\t    }\n\t \n\t    private static class OutputWriter\n\t    {\n\t        private final PrintWriter writer;\n\t \n\t        public OutputWriter(OutputStream outputStream)\n\t        {\n\t            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t        }\n\t \n\t        public OutputWriter(Writer writer)\n\t        {\n\t            this.writer = new PrintWriter(writer);\n\t        }\n\t \n\t        public void print(Object... objects)\n\t        {\n\t            for (int i = 0; i < objects.length; i++)\n\t            {\n\t                if (i != 0)\n\t                    writer.print(' ');\n\t                writer.print(objects[i]);\n\t            }\n\t        }\n\t \n\t        public void println(Object... objects)\n\t        {\n\t            print(objects);\n\t            writer.println();\n\t        }\n\t \n\t        public void close()\n\t        {\n\t            writer.close();\n\t        }\n\t \n\t        public void flush()\n\t        {\n\t            writer.flush();\n\t        }\n\t     }\n\t\n\t \n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static final class TaskC {\n        private static final int MODULO = 1_000_000_000 + 7;\n\n        public void solve(int __, InputReader in, PrintWriter out) {\n            long qty = in.nextLong();\n            long months = in.nextLong();\n            if (qty == 0) {\n                out.println(0);\n                return;\n            }\n            qty %= MODULO;\n            long pow = pow(2, months + 1);\n            qty = (qty * pow) % MODULO;\n            long sub = (pow - 2 + MODULO) % MODULO * pow(2, MODULO - 2) % MODULO;\n            qty = (qty - sub + MODULO) % MODULO;\n            out.println(qty);\n        }\n\n        private long pow(long base, long power) {\n            long result = 1;\n            while (power > 0) {\n                if ((power & 1) != 0) {\n                    result = (result * base) % MODULO;\n                }\n                base = (base * base) % MODULO;\n                power >>>= 1;\n            }\n            return result;\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 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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class C\n{\n\n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    \n    public static void main(String[] args)\n    {\n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out);    \n        \n        long x = in.nextLong();\n        long k = in.nextLong();\n        \n        if(x == 0){\n            out.println(0);\n        }\n        else{\n        \n        long mul = pow(2, k + 1, mod);\n        x %= mod;\n        mul = (mul * x) % mod;\n        long sub = pow(2, k, mod);\n        sub = (sub - 1 + mod) % mod;\n        mul = (mul - sub + mod) % mod;\n        out.println(mul);\n        }\n        \n        out.close(); \n    }\n    \n    static class Pair implements Comparable<Pair>\n    {\n\n        int x,y;\n        int i;\n        \n        Pair (int x,int y)\n        {\n                this.x = x;\n                this.y = y;\n        }\n\n        Pair (int x,int y, int i)\n        {\n                this.x = x;\n                this.y = y;\n                this.i = i;\n        }\n\n        public int compareTo(Pair o)\n        {\n            return Integer.compare(this.x, o.x);\n        }\n\n        public boolean equals(Object o)\n        {\n            if (o instanceof Pair)\n            {\n                Pair p = (Pair)o;\n                return p.x == x && p.y==y;\n            }\n            return false;\n        }\n\n        @Override\n        public String toString()\n        {\n            return x + \" \"+ y + \" \"+i;\n        }\n\n        /*public int hashCode()\n        {\n            return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n        }*/\n\n    } \n\n    \n    static String rev(String s){\n        StringBuilder sb=new StringBuilder(s);\n        sb.reverse();\n        return sb.toString();\n    }\n    \n    static long gcd(long x,long y)\n    {\n        if(y==0)\n                return x;\n        else\n                return gcd(y,x%y);\n    }\n\n    static int gcd(int x,int y)\n    {\n        if(y==0)\n                return x;\n        else \n                return gcd(y,x%y);\n    }\n\n    static long pow(long n,long p,long m)\n    {\n         long  result = 1;\n          if(p==0){\n            return 1;\n          }\n          \n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\n            if(result >= m)\n               result %= m;\n            p >>=1;\n            n*=n;\n            if(n >= m)\n                n%=m;\n        }\n        \n        return result;\n    }\n\n    static long pow(long n,long p)\n    {\n        long  result = 1;\n          if(p==0)\n            return 1;\n\n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\t    \n            p >>=1;\n            n*=n;\t    \n        }\n        return result;\n    }\n\n    static void debug(Object... o)\n    {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "//package round489;\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 C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint[][] M = {\n\t\t\t\t{2, mod-1},\n\t\t\t\t{0, 1}\n\t\t};\n\t\tlong n = nl();\n\t\tif(n == 0){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tn = n*2%mod;\n\t\tlong K = nl();\n\t\tint[] v = new int[]{(int)n, 1};\n\t\tout.println(pow(M, v, K)[0]);\n\t}\n\t\n\t///////// begin\n\tpublic static final int mod = 1000000007;\n\tpublic static final long m2 = (long)mod*mod;\n\tpublic static final long BIG = 8L*m2;\n\t\n\t// A^e*v\n\tpublic static int[] pow(int[][] A, int[] v, long e)\n\t{\n\t\tfor(int i = 0;i < v.length;i++){\n\t\t\tif(v[i] >= mod)v[i] %= mod;\n\t\t}\n\t\tint[][] MUL = A;\n\t\tfor(;e > 0;e>>>=1) {\n\t\t\tif((e&1)==1)v = mul(MUL, v);\n\t\t\tMUL = p2(MUL);\n\t\t}\n\t\treturn v;\n\t}\n\t\n\t// int matrix*int vector\n\tpublic static int[] mul(int[][] A, int[] v)\n\t{\n\t\tint m = A.length;\n\t\tint n = v.length;\n\t\tint[] w = new int[m];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tlong sum = 0;\n\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\tsum += (long)A[i][k] * v[k];\n\t\t\t\tif(sum >= BIG)sum -= BIG;\n\t\t\t}\n\t\t\tw[i] = (int)(sum % mod);\n\t\t}\n\t\treturn w;\n\t}\n\t\n\t// int matrix^2 (be careful about negative value)\n\tpublic static int[][] p2(int[][] A)\n\t{\n\t\tint n = A.length;\n\t\tint[][] C = new int[n][n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tlong[] sum = new long[n];\n\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\tsum[j] += (long)A[i][k] * A[k][j];\n\t\t\t\t\tif(sum[j] >= BIG)sum[j] -= BIG;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\tC[i][j] = (int)(sum[j] % mod);\n\t\t\t}\n\t\t}\n\t\treturn C;\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 C().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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static long power(long a, long b, long c){\n\t\tif(b == 0){\n\t\t\treturn 1;\n\t\t}\n\t\ta %= c;\n\t\tif(b % 2 == 0){\n\t\t\treturn power((a % c * a % c) % c, b / 2, c);\n\t\t}else{\n\t\t\treturn (a % c * power((a % c * a % c) % c, b / 2, c) % c) % c;\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tlong x = s.nextLong(), k = s.nextLong() + 1, mod = (long)Math.pow(10, 9) + 7;\n\t\tlong ans;\n\t\tif(x == 0){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n//\t\tif(x != 0){\n\t\t\tans = ((power(2, k % (mod - 1), mod) % mod) * (x % mod)) % mod; \n\t/*\t}else{\n\t\t\tans = 0;\n\t\t}\n\t\t*/ans = (ans - power(2, (k - 1) % (mod - 1), mod) % mod + 2 * mod) % mod;\n\t\tSystem.out.println((ans + 1) % mod);\n\n\t}\n\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        CNastyaAndAWardrobe solver = new CNastyaAndAWardrobe();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class CNastyaAndAWardrobe {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long x = in.nextLong(), k = in.nextLong();\n            if (x != 0) {\n                long m = (int) 1e9 + 7;\n                x = x % m;\n                long res = in.fastPowerMod(2, k, m);\n                long res1 = (2 * res) % m;\n                long ans = ((res1 * x) % m - (res - 1) % m) % m;\n                ans = (ans + m) % m;\n                out.println(ans);\n            } else {\n                out.println(0);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public long fastPowerMod(long x, long y, long m) {\n            long res = 1;\n            x = x % m;\n            while (y > 0) {\n                if ((y & 1) == 1) {\n                    res = (x * res) % m;\n                }\n                x = (x * x) % m;\n                y = y >> 1;\n            }\n            return res % m;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\nimport java.io.*;\n\npublic class Contest {\n\n\tpublic static void main(String[] args)throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String[] s=br.readLine().split(\" \");\n\t\tBigInteger x = new BigInteger(s[0]);\n\t\tBigInteger k = new BigInteger(s[1]);\n\n\t\tBigInteger mod = new BigInteger(String.valueOf((int) (Math.pow(10, 9) + 7)));\n\n\t\tBigInteger two = new BigInteger(\"2\");\n\t\tBigInteger interm = two.modPow(k, mod);\n\n\t\tBigInteger res = interm.multiply(two.multiply(x).subtract(BigInteger.ONE)).add(BigInteger.ONE).mod(mod);\n\n\t\tif(x.equals(BigInteger.ZERO)) {\n\t\t\tSystem.out.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long MOD = MathExtentions.DEFAULT_MOD;\n            long x = in.NextLong();\n            long k = in.NextLong();\n            if (x == 0) {\n                out.println(0);\n                return;\n            }\n            x %= MOD;\n            long res = x * MathExtentions.powerMod(2, k + 1, MOD);\n            res %= MOD;\n            res -= MathExtentions.powerMod(2, k, MOD) - 1;\n            res %= MOD;\n            while (res < 0) res += MOD;\n            while (res >= MOD) res -= MOD;\n            out.println(res);\n\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 long NextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n\n    static class MathExtentions {\n        public static final long DEFAULT_MOD = 1_000_000_007;\n\n        public static long powerMod(final long x, final long y, final long m) {\n            if (y == 0)\n                return 1;\n\n            long p = powerMod(x, y / 2, m) % m;\n            p = (p * p) % m;\n\n            if (y % 2 == 0)\n                return p;\n            else\n                return (x * p) % m;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        int MOD = 1000000007;\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            long x = in.nextLong();\n            long k = in.nextLong();\n            if (x == 0) {\n                out.print(0);\n                return;\n            }\n            long b = fast_expo(2, k);\n            long a = (b * 2) % MOD;\n\n            long u = ((x % MOD) * a) % MOD;\n            long v = (b - 1 + MOD) % MOD;\n            out.print((u - v + MOD) % MOD);\n        }\n\n        private long fast_expo(long a, long b) {\n            long res = 1L;\n            a = a % MOD;\n            while (b > 0) {\n                if ((b & 1) != 0) {\n                    res = (res * a) % MOD;\n                }\n                b = b >> 1;\n                a = (a * a) % MOD;\n            }\n            return res % MOD;\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader bufferedReader;\n        private StringTokenizer stringTokenizer;\n\n        public FastScanner(InputStream inputStream) {\n            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        public 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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 ankur\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 mod = (long) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long x = in.nextLong();\n            long k = in.nextLong();\n            if (x == 0) {\n                out.print(0);\n                return;\n            }\n            long n = pow(2, k);\n            long l = (n * ((x % mod)) % mod);\n            l = l % mod;\n            long ans = 2 * l - n + 1;\n            ans = ans % mod;\n            if (ans < 0)\n                ans += mod;\n            out.print(ans);\n        }\n\n        long pow(long a, long val) {\n            if (val == 0) {\n                return 1;\n            }\n            if (val % 2 == 0) {\n                long ans = pow(a, val / 2);\n                return (ans * ans) % mod;\n            }\n            return ((a % mod) * (pow(a, val - 1))) % mod;\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            //*-*------clare------\n//remeber while comparing 2 non primitive data type not to use ==\n//remember Arrays.sort for primitive data has worst time case complexity of 0(n^2) bcoz it uses quick sort\n//again silly mistakes ,yr kb tk krta rhega ye mistakes\n//try to write simple codes ,break it into simple things\n//knowledge>rating\n        /*\n        public class Main\n        implements Runnable{\n    public static void main(String[] args) {\n        new Thread(null,new Main(),\"Main\",1<<26).start();\n\n    }\n    public void run() {\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();//chenge the name of task\n        solver.solve(1, in, out);\n        out.close();\n    }\n         */\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 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 boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Jenish\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        C489 solver = new C489();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class C489 {\n        int mod = 1000000007;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            long x = in.scanLong();\n            long k = in.scanLong();\n            if (x == 0) {\n                out.println(0);\n                return;\n            }\n            long p = CodeX.power(2, k, mod);\n            long ans = (2 * p * (x % mod)) % mod;\n            ans = (ans + 1) % mod;\n            ans = (ans - p + mod) % mod;\n            out.println(ans);\n        }\n\n    }\n\n    static class CodeX {\n        public static long power(long x, long y, long p) {\n            long res = 1;\n            x = x % p;\n            while (y > 0) {\n                if ((y & 1) != 0)\n                    res = (res * x) % p;\n                y = y >> 1;\n                x = (x * x) % p;\n            }\n            return res;\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        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n        public long scanLong() {\n            long I = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    I *= 10;\n                    I += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * I;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/** Built using CHelper plug-in Actual solution is at the top */\npublic class Main {\n  public static void main(String[] args) {\n    InputStream inputStream = System.in;\n    OutputStream outputStream = System.out;\n    Scanner in = new Scanner(inputStream);\n    PrintWriter out = new PrintWriter(outputStream);\n    TaskC solver = new TaskC();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class TaskC {\n    static final long MODULO = (int) (1e9 + 7);\n\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n      long x = in.nextLong();\n      long k = in.nextLong();\n\n      if (x == 0) {\n        out.println(0);\n      } else {\n        long e = modPow(2, k, MODULO);\n        long y = 2 * x - 1;\n        long w = ((e % MODULO) * (y % MODULO)) % MODULO;\n        long z = (w + 1) % MODULO;\n        out.println(z);\n      }\n    }\n\n    private long modPow(long a, long b, long m) {\n      if (b == 0) return 1 % m;\n      if (b == 1) return a % m;\n      long res = modPow(a, b / 2, m);\n      res = (res * res) % m;\n      if (b % 2 == 1) res = (res * a) % m;\n      return res;\n    }\n  }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        new Solver().run(1);\n    }\n}\n\nclass Solver {\n\n    private BufferedReader reader = null;\n    private StringTokenizer st = null;\n\n    private static final long MOD = (long)1e9 + 7;\n    private long x, k;\n\n    public void run(int inputType) throws Exception {\n        if (inputType == 0)\n            reader = new BufferedReader(new FileReader(\"input.txt\"));\n        else\n            reader = new BufferedReader(new InputStreamReader(System.in));\n\n        st = new StringTokenizer(reader.readLine());\n        x = Long.parseLong(st.nextToken());\n        k = Long.parseLong(st.nextToken());\n\n        if (x == 0) {\n            System.out.println(0);\n            return;\n        }\n\n        long pow = binpow(2, k);\n        long m = (2 * x) % MOD;\n\n        m = (m - 1 < 0) ? MOD - 1 : m - 1;\n\n        m = (m * pow) % MOD;\n        m = (m + 1) % MOD;\n\n        System.out.println(m);\n\n        reader.close();\n    }\n\n    long binpow(long v, long p) {\n        long res = 1L;\n        while(p > 0) {\n\n            if ((p & 1) > 0)\n                res = (res * v) % MOD;\n\n            v = (v * v) % MOD;\n            p /= 2;\n        }\n\n        return res;\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class TaskC {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tBigInteger x = new BigInteger(sc.next());\n\t\tBigInteger k = new BigInteger(sc.next());\n\n\t\tBigInteger mod = new BigInteger(String.valueOf((int) (Math.pow(10, 9) + 7)));\n\n\t\tBigInteger two = new BigInteger(\"2\");\n\t\tBigInteger interm = two.modPow(k, mod);\n\n\t\tBigInteger res = interm.multiply(x).add(interm.multiply(x)).subtract(interm).add(BigInteger.ONE).mod(mod);\n\n\t\tif(x.equals(BigInteger.ZERO)) {\n\t\t\tSystem.out.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\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 Allen Li\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        Nas solver = new Nas();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class Nas {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            long x = in.nextLong();\n            if (x == 0) {\n                out.println(0);\n                return;\n            }\n            BigInteger n1 = BigInteger.valueOf(x);\n            BigInteger n2 = BigInteger.valueOf(in.nextLong());\n            BigInteger mod = BigInteger.valueOf(1000000007);\n            BigInteger a = BigInteger.valueOf(2).modPow(n2.add(BigInteger.ONE), mod);\n            a = a.multiply(n1);\n            a = a.mod(mod);\n            BigInteger b = BigInteger.valueOf(2).modPow(n2, mod).subtract(BigInteger.ONE);\n            a = a.subtract(b);\n            a = a.add(mod);\n            a = a.mod(mod);\n            out.println(a);\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 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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*; \nimport java.text.DecimalFormat;\n\npublic class Main{\n    final long mod = (int)1e9+7, IINF = (long)1e19;\n    final int MAX = (int)1e6+1, MX = (int)1e7+1, INF = (int)1e9;\n    DecimalFormat df = new DecimalFormat(\"0.0000000000000\");\n    FastReader in;\n    PrintWriter out;\n    static boolean multipleTC = false, memory = false;\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 << 26).start();\n        else new Main().run();\n    }\n\n    void run() throws Exception{\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n        for(int i = 1, t = (multipleTC)?ni():1; i<=t; i++)solve(i);\n        out.flush();    \n        out.close();\n    }\n\n    void solve(int TC) throws Exception{\n        long x = nl(), k = nl();\n        if(x==0)pn(0);\n        else {\n            x%=mod;\n            long p = modPow(2,k);\n            long b = mul((x-1+mod)%mod,p), e = mul(x,p);\n            long ans = c(e)%mod;\n            ans -= c(b)%mod;\n            ans%=mod;\n            if(ans<0)ans+=mod;\n            ans = mul(ans, 2);\n            ans = mul(ans, modPow(p, mod-2));\n            pn(ans);\n        }\n    }\n    long modPow(long a, long p){\n        long o = 1;\n        while(p>0){\n            if((p&1)==1)o = mul(a,o);\n            a = mul(a,a);\n            p>>=1;\n        }\n        return o;\n    }\n    \n    \n    long mul(long a, long b){\n        if(a>=mod)a%=mod;\n        if(b>=mod)b%=mod;\n        a*=b;\n        if(a>=mod)a%=mod;\n        return a;\n    }\n    \n    long c(long c){\n        return (c*c+c)/2;\n    }\n    \n    int[] reverse(int[] a){\n        int[] o = new int[a.length];\n        for(int i = 0; i< a.length; i++)o[i] = a[a.length-i-1];\n        return o;   \n    }\n\n    int[] sort(int[] a){\n        if(a.length==1)return a;\n        int mid = a.length/2;\n        int[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));\n        for(int i = 0, j = 0, k = 0; i< a.length; i++){\n            if(j<b.length && k<c.length){\n                if(b[j]<c[k])a[i] = b[j++];\n                else a[i] = c[k++];\n            }else if(j<b.length)a[i] = b[j++];\n            else a[i] = c[k++];\n        }\n        return a;\n    }\n\n    long[] sort(long[] a){\n        if(a.length==1)return a;\n        int mid = a.length/2;\n        long[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));\n        for(int i = 0, j = 0, k = 0; i< a.length; i++){\n            if(j<b.length && k<c.length){\n                if(b[j]<c[k])a[i] = b[j++];\n                else a[i] = c[k++];\n            }else if(j<b.length)a[i] = b[j++];\n            else a[i] = c[k++];\n        }\n        return a;\n    }\n\n    int[] ia(int ind,int n){\n        int[] out = new int[ind+n];\n        for(int i = 0; i< n; i++)out[ind+i] = ni();\n        return out;\n    }\n\n    long[] la(int ind, int n){\n        long[] out = new long[ind+n];\n        for(int i = 0; i< n; i++)out[ind+i] = nl();\n        return out;\n    }\n\n    double[] da(int ind, int n){\n        double[] out = new double[ind+n];\n        for(int i = 0; i< n; i++)out[ind+i] = nd();\n        return out;\n    }\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 bitcount(long n){return (n==0)?0:(1+bitcount(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(){return in.next();}\n    String nln(){return in.nextLine();}\n    int ni(){return Integer.parseInt(in.next());}\n    long nl(){return Long.parseLong(in.next());}\n    double nd(){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(){\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        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}      ", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Tester\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 long mod = 1000000007;\n    public static void main(String[] args) {\n    \t\n    \tsolveQ3();\n    \n    }\n\n\tprivate static void solveQ3() {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tFastReader sc = new FastReader();\n\t\t\n\t\tlong x = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\t\n\t\tif(x == 0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong ans = modExp(2, k);\n\t\tx = (2*x)%mod;\n\t\tx = (x - 1 + mod)%mod;\n\t\tans = (ans*x)%mod;\n\t\tans = (ans + 1)%mod;\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\t\n\tprivate static long modExp(long a, long n) {\n\t\t\n\t\tif(n == 0)\n\t\t\treturn 1;\n\t\tif(n%2 == 0)\n\t\t\treturn modExp((a*a)%mod, n/2);\n\t\telse\n\t\t\treturn (a*modExp((a*a)%mod, n/2))%mod;\n\t\t\n\t}\n\n\tprivate static void solveQ2() {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tFastReader sc = new FastReader();\n\t\tlong l = sc.nextLong();\n\t\tlong r = sc.nextLong();\n\t\t\n\t\tlong x = sc.nextLong();\n\t\tlong y = sc.nextLong();\n\t\t\n\t\tlong n = x*y;\n\t\tlong count = 0;\n\t\t\n\t\tfor(long i=l; (i<=Math.sqrt(n)) && (n/i<=r); i++) {\n\t\t\t\n\t\t\tif((n%i == 0) && (gcd(i, n/i)==x)) {\n\t\t\t\t\n\t\t\t\tif(i*i != n)\n\t\t\t\t\tcount += 2;\n\t\t\t\telse\n\t\t\t\t\tcount += 1;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t\t\n\t\t\n\t}\n\t\n\tpublic static long gcd(long a, long b) {\n\t\t\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn gcd(b, a%b);\n\t\t\n\t}\n\n\tprivate static void solveQ1() {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tFastReader sc = new FastReader();\n\t\tint n = sc.nextInt();\n\t\t\n\t\tHashSet<Integer> hs = new HashSet<Integer>();\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tint x = sc.nextInt();\n\t\t\tif(x != 0) {\n\t\t\t\ths.add(x);\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(hs.size());\n\t\t\t\t\n\t\t\n\t}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "//package pack;\n\nimport java.util.*;\n\npublic class first\n{\n\tpublic static long power(long x, long y, long p)\n    {\n        long res = 1;\n        x = x % p; \n        while (y > 0)\n        {\tif((y & 1)==1)\n                res = (res * x) % p;\n            y = y >> 1; \n            x = (x * x) % p; \n        }\n        return res;\n    }\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong x=sc.nextLong();\n\t\tlong k=sc.nextLong();\n\t\tlong mod=1000000007;\n\t\tif(k==0 || x==0)\n\t\t\tSystem.out.println((2*x)%mod);\n\t\telse\n\t\t{\tlong answer=1;\n\t\t\tanswer+=(power(2,k,mod))*(((2*x)-1)%mod);\n\t\t\tSystem.out.println(answer%mod);\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n \npublic class Main\n{\t\n\t\n\tlong mod = 1000000007;\n\t\n\tlong pow(long x,long y)\n\t{\n\t\tif(y==0)\n\t\t\treturn 1;\n\t\telse if(y==1)\n\t\t\treturn x%mod;\n\t\telse if(y%2==0)\n\t\t\treturn pow((x*x)%mod,y/2)%mod;\n\t\telse\n\t\t\treturn (x*pow((x*x)%mod,y/2)%mod)%mod;\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tFastReader sc =new FastReader();\n\t\tlong x = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\t\n\t\tif(x == 0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong ans = pow(2, k);\n\t\tx = (2*x)%mod;\n\t\tx = (x - 1 + mod)%mod;\n\t\tans = (ans*x)%mod;\n\t\tans = (ans + 1)%mod;\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n\n    public static void main(String[] args)\n    {\n        new Main().solve();\n    }\n\t\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\npublic class C992 \n{\n    static class Scanner\n    {\n        BufferedReader br;\n        StringTokenizer tk=new StringTokenizer(\"\");\n        public Scanner(InputStream is) \n        {\n            br=new BufferedReader(new InputStreamReader(is));\n        }\n        public int nextInt() throws IOException\n        {\n            if(tk.hasMoreTokens())\n                return Integer.parseInt(tk.nextToken());\n            tk=new StringTokenizer(br.readLine());\n            return nextInt();\n        }\n        public long nextLong() throws IOException\n        {\n            if(tk.hasMoreTokens())\n                return Long.parseLong(tk.nextToken());\n            tk=new StringTokenizer(br.readLine());\n            return nextLong();\n        }\n        public String next() throws IOException\n        {\n            if(tk.hasMoreTokens())\n                return (tk.nextToken());\n            tk=new StringTokenizer(br.readLine());\n            return next();\n        }\n        public String nextLine() throws IOException\n        {\n            tk=new StringTokenizer(\"\");\n            return br.readLine();\n        }\n        public double nextDouble() throws IOException\n        {\n            if(tk.hasMoreTokens())\n                return Double.parseDouble(tk.nextToken());\n            tk=new StringTokenizer(br.readLine());\n            return nextDouble();\n        }\n        public char nextChar() throws IOException\n        {\n            if(tk.hasMoreTokens())\n                return (tk.nextToken().charAt(0));\n            tk=new StringTokenizer(br.readLine());\n            return nextChar();\n        }\n        public int[] nextIntArray(int n) throws IOException\n        {\n            int a[]=new int[n];\n            for(int i=0;i<n;i++)\n                a[i]=nextInt();\n            return a;\n        }\n        public long[] nextLongArray(int n) throws IOException\n        {\n            long a[]=new long[n];\n            for(int i=0;i<n;i++)\n                a[i]=nextLong();\n            return a;\n        }\n        public int[] nextIntArrayOneBased(int n) throws IOException\n        {\n            int a[]=new int[n+1];\n            for(int i=1;i<=n;i++)\n                a[i]=nextInt();\n            return a;\n        }\n        public long[] nextLongArrayOneBased(int n) throws IOException\n        {\n            long a[]=new long[n+1];\n            for(int i=1;i<=n;i++)\n                a[i]=nextLong();\n            return a;\n        }\n    \n    \n    }\n    static long mod=1000000007;\n    static long mod_exp(long base,long exp)\n    {\n        long ans=1;\n        base%=mod;\n        while(exp>0)\n        {\n            if(exp%2==1)\n            {\n                ans*=base;\n                ans%=mod;\n            }\n            exp/=2;\n            base*=base;\n            base%=mod;\n        }\n        return ans;\n    }\n    public static void main(String args[]) throws IOException\n    {\n        Scanner in=new Scanner(System.in);\n        PrintWriter out=new PrintWriter(System.out);\n        long x=in.nextLong();\n        long k=in.nextLong();\n        \n        long ans=mod_exp(2,k+1);\n        ans*=(x%mod);\n        ans%=mod;\n        ans-=mod_exp(2,k);\n        ans%=mod;\n        ans++;\n        ans%=mod;\n        if(ans<0)\n            ans+=mod;\n        if(x==0)\n            ans=0;\n        out.println(ans);\n        out.close();\n    }\n\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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        CNastyaAndAWardrobe solver = new CNastyaAndAWardrobe();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class CNastyaAndAWardrobe {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            long x = in.nextLong();\n            long k = in.nextLong();\n            if (x == 0) {\n                out.println(0);\n            } else {\n                long mod = (long) (1e9 + 7);\n                long ans = (((((2 * x - 1) % mod)) * power(2, k, mod)) % mod) + 1;\n                ans %= mod;\n                out.println(ans);\n            }\n\n        }\n\n        long power(long x, long y, long p) {\n            long res = 1;\n            x = x % p;\n            while (y > 0) {\n                if ((y & 1) > 0)\n                    res = (res * x) % p;\n                y = y >> 1;\n                x = (x * x) % p;\n            }\n            return res;\n        }\n\n    }\n\n    static class FastScanner {\n        private final InputStream stream;\n        private final 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            }\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        boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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            }\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}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\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        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        int mod = 1_000_000_007;\n        public long pow(long a, long b) {\n            if (b == 0) return 1L;\n            if (b % 2 == 0) return pow(a * a % mod, b >> 1);\n            return a * pow(a * a % mod, b >> 1) % mod;\n        }\n        public void solve(Scanner sc, PrintWriter pw) throws IOException {\n            long T = sc.nextLong();\n            long k = sc.nextLong();\n            if (T == 0) {\n                pw.println(0);\n                return;\n            }\n            long a1 = pow(2, k + 1);\n            long a2 = pow(2, k);\n            long s = a1 * (T % mod) % mod;\n            long t = ((1 - a2) + mod) % mod;\n            long y = (s + t) % mod;\n            pw.println((y + 5L * mod) % mod);\n        }\n\n\n\n\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n    void solve() {\n        long x=nl(),k=nl();\n        if(x==0) {\n            pw.println(0);\n            return;\n        }\n        long d=modpow(2,k,M);\n        long ans=mul(2,d,M);\n        ans=mul(ans,x,M)%M;\n        ans++;\n        ans%=M;\n        ans=(ans-d+M)%M;\n\n        pw.println(ans);\n\n\n    }\n//    long mul(long a, long b,long M)\n//    {\n//        return (a*1L*b)%M;\n//    }\n    long mul(long x, long y, long m) {\n        long ans = 0;\n        while (y>0) {\n            if ((y & 1)>0) {\n                ans += x;\n                if (ans >= m) ans -= m;\n            }\n            x = x + x;\n            if (x >= m) x -= m;\n            y >>= 1;\n        }\n        return ans;\n    }\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 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\n    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.util.*;\n\npublic class C {\n\n\tstatic long x, k;\n\tstatic long mod = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tJS in = new JS();\n\t\tx = in.nextLong();\n\t\tk = in.nextLong();\n\t\t\n\t\tif(x==0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong c = pow(2,k);\n\t\tif(c==0) c = mod;\n\t\tlong sub = c-1;\n\t\t\n\t\tlong low = ((c*(x%mod))%mod - sub);\n\t\twhile(low < 0) low += mod;\n\t\tlong res = ((low*2)%mod + sub)%mod;\n\t\t\n\t\tSystem.out.println(res);\n\t\t\n\t\t\n\t}\n\t\n\tstatic long pow(long a, long p) {\n\t\tif(p==0) return 1;\n\t\tif(p==1) return a;\n\t\tif(p%2==0) {\n\t\t\tlong res = pow(a,p/2)%mod;\n\t\t\treturn (res*res)%mod;\n\t\t}\n\t\telse {\n\t\t\treturn (pow(a,p-1)*a)%mod;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic class JS{\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\t\t\n\t\tpublic JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\t\t\n\t\tpublic JS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\t\t\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}\t\t\t\t\n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\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}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tstatic final int M = 1000000007;\t\n\t\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\t\n\t\tlong x = Long.parseLong(st.nextToken());\n\t\tif(x == 0){\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tfinal long k = Long.parseLong(st.nextToken());\t\n\t\tx = x%M;\n\t\t\n\t\tlong ans = (exp(2, k+1)*x - (exp(2, k) - 1))%M;\n\t\tif(ans < 0) ans += M;\n\t\tSystem.out.println(ans);\n\t\t/*\n\t\tfor(long i = 1234567890; i < 1234567999; i++){\n\t\t\tans = (exp(2, i+1)*x - (exp(2, i) - 1))%M;\n\t\t\tif(ans < 0) ans += M;\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t\t/*\n\t\tSystem.out.println((k-1)/2);\n\t\tSystem.out.println(x);\n\t\tSystem.out.println(exp(2, k));\n\t\tSystem.out.println(exp(2, k+1));\n\t\t*/\n\t}\n\t\n\tpublic static long exp(long a, long n){\n\t\tif(n == 0) return 1;\n\t\tif(n == 1) return a%M;\n\t\tif(n%2 == 0) return exp((a*a)%M, n/2);\n\t\telse return (a*exp((a*a)%M, (n-1)/2))%M;\n\t}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            long x = in.nextLong();\n            long k = in.nextLong();\n            long max2 = (((x % 1_000_000_007) * (pb(k))) % 1_000_000_007) % 1_000_000_007;\n            long min2 = ((((x - 1) % 1_000_000_007) * pb(k)) % 1_000_000_007 + 1) % 1_000_000_007;\n            if (x == 0) min2 = 0;\n            out.println((max2 + min2) % 1_000_000_007);\n        }\n\n        long pb(long a) {\n            if (a == 0) return 1;\n            if (a == 1) return 2;\n            long tmp = pb(a / 2);\n            if (a % 2 == 0) return (tmp * tmp) % 1_000_000_007;\n            return (((tmp * tmp) % 1_000_000_007) * 2) % 1_000_000_007;\n        }\n\n    }\n\n    static class InputReader {\n        private StringTokenizer tokenizer;\n        private BufferedReader reader;\n\n        public InputReader(InputStream inputStream) {\n            reader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        private void fillTokenizer() {\n            if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (Exception e) {\n                    throw new RuntimeException(e);\n                }\n            }\n        }\n\n        public String next() {\n            fillTokenizer();\n            return tokenizer.nextToken();\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class Solution {\n    \n    private static final long MODULUS = 1000000007;\n    private static final boolean DEBUG = false;\n\n    private static long modularPow(long base, long exponent, long modulus) {\n        long result = 1;\n        while (exponent > 0) {\n            if (exponent % 2 == 1) {\n               result = (result * base) % modulus;\n            }\n            exponent >>= 1;\n            base = (base * base) % modulus;\n        }\n        return result;\n    }\n\n    public static void main(String[] args) throws FileNotFoundException {\n        long beginTime = System.nanoTime();\n        InputStream is = DEBUG ? new FileInputStream(\"resources/codeforcesedu43/ProblemC-1.in\") : System.in;\n        try (Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(is)))) {\n            long x = scanner.nextLong();\n            long k = scanner.nextLong();\n            if (x != 0) {\n                x = (2 * x - 1) % MODULUS;\n                long twoPowK = modularPow(2, k, MODULUS);\n                x = (x * twoPowK + 1) % MODULUS;\n            }\n            System.out.println(x % 1000000007);\n        }\n        System.err.println( \"Done in \" + ((System.nanoTime() - beginTime) / 1e9) + \" seconds.\");\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\nimport java.io.*;\n\npublic class Contest {\n\n\tpublic static void main(String[] args)throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String[] s=br.readLine().split(\" \");\n\t\tBigInteger x = new BigInteger(s[0]);\n\t\tBigInteger k = new BigInteger(s[1]);\n\n\t\tBigInteger mod = new BigInteger(String.valueOf((int) (Math.pow(10, 9) + 7)));\n\n\t\tBigInteger two = new BigInteger(\"2\");\n\t\tBigInteger interm = two.modPow(k, mod);\n\n\t\tBigInteger res = interm.multiply(x).add(interm.multiply(x)).subtract(interm).add(BigInteger.ONE).mod(mod);\n\n\t\tif(x.equals(BigInteger.ZERO)) {\n\t\t\tSystem.out.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import javax.swing.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        long x = scanner.nextLong();\n        long k = scanner.nextLong();\n        if (x==0) {\n            System.out.println(\"0\");\n            return;\n        }\n        BigInteger M = BigInteger.valueOf(1000_000_000L+7);\n        BigInteger modus = BigInteger.valueOf(x).multiply(BigInteger.valueOf(2)).subtract(BigInteger.ONE).mod(M);\n        BigInteger operandi = BigInteger.valueOf(2).modPow(BigInteger.valueOf(k), M);\n        BigInteger result = modus.multiply(operandi).mod(M).add(BigInteger.ONE).mod(M);\n        System.out.println(result);\n    }\n\n    public static long gcd(long a, long b) {\n        if (b == 0) return a;\n        return gcd(b, a % b);\n    }\n\n    public static long lcm(long a, long b, long gcd) {\n        return a * (b / gcd);\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 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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.awt.List;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class main {\n\t\n\tstatic long d,x,y;\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner();\n\t    \n\t\tlong x = in.nextLong(), k = in.nextLong();\n\t\t\n\t\tlong mod = 1000000007;\n\t\t\n\t\tlong one = pow(2,k,mod);\n\t\t\n\t\tone %= mod;\n\t\t\n\t\tlong two = (2*x)%mod-1;\n\t\t\n\t\ttwo %= mod;\n\t\t\n\t\tlong ans = (one*two)%mod+1;\n\t\t\n\t\tans %= mod;\n\t\t\n\t\tif(ans<0)\n\t\t\tans += mod;\n\t\t\n\t\tif(x==0)\n\t\t\tSystem.out.println(\"0\");\n\t\telse\n\t\t\tSystem.out.println(ans);\n\t        \n\t}\n\tprivate static long pow(long a, long b, long mod) {\n\t\tif(b==0) return 1;\n\t\t\n\t\tif(b==1)\n\t\t\treturn a;\n\t\t\n\t\tif(b%2==0)\n\t\t\treturn pow((a*a)%mod,b/2,mod);\n\t\telse\n\t\t\treturn (a*pow((a*a)%mod,(b-1)/2,mod))%mod;\n\t\t\n\t}\n\t\n\t\n\n\t\n\n}\n\n\n\n\n\n\n\n\n\n\nclass FastScanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n\t\n\tpublic FastScanner() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\t\n\tString next() {\n\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tlong nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class CF489_C {\n\tstatic long mod = 1000000007;\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tlong x = s.nextLong(), k = s.nextLong();\n\t\tif (x == 0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong max = x % mod;\n\t\tlong temp = power(2, k, mod);\n\t\ttemp %= mod;\n\t\tmax = (max % mod) * (temp % mod);\n\t\tmax %= mod;\n\t\tlong min = max % mod;\n\t\tmin = mod(min - (temp - 1));\n\t\tmin %= mod;\n\t\tlong num = mod(max - min + 1);\n\t\tlong n = num % mod;\n\t\tn = (n % mod) * (min % mod + max % mod);\n\t\tn = n % mod;\n\t\tn %= mod;\n\t\tlong ans = n % mod * modInverse(num, mod);\n\t\tSystem.out.println(ans % mod);\n\n\t}\n\n\tstatic long modInverse(long a, long m) {\n\t\tlong m0 = m;\n\t\tlong y = 0, x = 1;\n\n\t\tif (m == 1)\n\t\t\treturn 0;\n\n\t\twhile (a > 1) {\n\t\t\t// q is quotient\n\t\t\tlong q = a / m;\n\t\t\tlong t = m;\n\n\t\t\t// m is remainder now, process same as\n\t\t\t// Euclid's algo\n\t\t\tm = a % m;\n\t\t\ta = t;\n\t\t\tt = y;\n\n\t\t\t// Update y and x\n\t\t\ty = x - q * y;\n\t\t\tx = t;\n\t\t}\n\n\t\t// Make x positive\n\t\tif (x < 0)\n\t\t\tx += m0;\n\n\t\treturn x;\n\t}\n\n\tstatic long mod(long val) {\n\t\tval %= mod;\n\t\tif (val < 0)\n\t\t\tval += mod;\n\t\treturn val;\n\t}\n\n\tstatic long power(long x, long y, long p) {\n\t\t// Initialize result\n\t\tlong res = 1;\n\n\t\t// Update x if it is more\n\t\t// than or equal to p\n\t\tx = x % p;\n\n\t\twhile (y > 0) {\n\t\t\t// If y is odd, multiply x\n\t\t\t// with result\n\t\t\tif ((y & 1) == 1)\n\t\t\t\tres = (res * x) % p;\n\n\t\t\t// y must be even now\n\t\t\t// y = y / 2\n\t\t\ty = y >> 1;\n\t\t\tx = (x * x) % p;\n\t\t}\n\t\treturn res;\n\t}\n\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n    static final int MOD = (int)1e9 + 7;\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        long x = sc.nextLong(), k = sc.nextLong();\n        if(x == 0)\n            out.println(0);\n        else\n            out.println(((x % MOD * 2 - 1 + MOD) % MOD * modPow(2, k) % MOD + 1) % MOD);\n        out.close();\n    }\n\n    static long modPow(long b, long e) {\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\n        return res;\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 double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n        public String nextLine() throws IOException {return br.readLine();}\n\n        public boolean ready() throws IOException { return br.ready(); }\n\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 Rishabhdeep Singh\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        int MOD = (int) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            long x = in.nextLong(), k = in.nextLong();\n            long res = Utilities.mul(x, Utilities.power(2, k + 1, MOD), MOD) % MOD - Utilities.power(2, k, MOD) + 1;\n            while (res < 0) res += MOD;\n            out.println(x == 0 ? 0 : res);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void println(long i) {\n            writer.println(i);\n        }\n\n    }\n\n    static class Utilities {\n        public static long mul(long x, long y, long mod) {\n            return (x % mod) * (y % mod) % mod;\n        }\n\n        public static long power(long a, long k, long m) {\n            long res = 1;\n            while (k > 0) {\n                if ((k & 1) != 0) {\n                    res = mul(res, a, m);\n                }\n                a = mul(a, a, m);\n                k >>= 1;\n            }\n            return res;\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 Rishabhdeep Singh\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        int MOD = (int) 1e9 + 7;\n\n        long power(long a, long k) {\n            long res = 1;\n            while (k > 0) {\n                if ((k & 1) != 0) {\n                    res = res * a % MOD;\n                }\n                a = a * a % MOD;\n                k /= 2;\n            }\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            long x = in.nextLong(), k = in.nextLong();\n            if (x == 0) {\n                out.println(0);\n                return;\n            }\n            long res = ((power(2, k + 1) % MOD) * (x % MOD)) % MOD;\n            long temp = power(2, k);\n            res = res - temp + 1;\n            while (res < 0) res += MOD;\n            out.println(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 println(long i) {\n            writer.println(i);\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 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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n// Solution\n\npublic class Main \n{    \n  public static void main (String[] argv) \n  {\n\t  new Main();\n  } \n     \n     \n  \n  boolean test = false;  \n  int n;\n  \n  long mod = 1000000007;\n  public Main() {\n\t  FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));\n\t  //FastReader in = new FastReader(new BufferedReader(new FileReader(\"Main.in\")));\n      long x = in.nextLong();\n      long k = in.nextLong();\n      \n      if (x == 0) {\n          System.out.println(0);\n          return;\n      }\n      \n      if (k == 0) {\n          x %= mod;\n          System.out.println((2*x%mod));\n          return;\n      }\n      \n      x %= mod;\n      \n      long f = pow(2, k);\n      long ans = ((2 * f * x % mod - f + 1) % mod + mod) % mod;\n      \n      System.out.println(ans);\n     \n  }\n  \n  private long pow(long x, long y) {\n      long ans = 1;\n      while (y > 0) {\n          if (y % 2 == 1) \n              ans = ans * x % mod;\n          x = x * x % mod;\n          y /= 2;\n      }\n      return ans;\n  }\n  \n  private long gcd(long x, long y) {\n      if (y == 0) return x;\n      return gcd(y, x % y);\n  }\n  private int max(int a, int b) {\n      return a >  b ? a : b;\n  }\n  \n  private int min(int a, int b) {\n      return a >  b ? b : a;\n  }\n  \n  \n  static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastReader(BufferedReader in)\n        {            \n            br = in;\n        }\n \n        String next()\n        {\n            while (st == null || !st.hasMoreElements())\n            {\n                try\n                {\n                    String line = br.readLine();\n                    if (line == null || line.length() == 0) return \"\";\n                    st = new StringTokenizer(line);\n                }\n                catch (IOException  e)\n                {\n                    return \"\";\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                return \"\";\n                //e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n/*\n * Heart 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...\n */\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tlong x=nl(),k=nl();\n\t\tif(x==0)\n\t\t{\n\t\t\tpr(0);\n\t\t\texit();\n\t\t}\n\t\tx%=mod;\n\t\tpr((((x*powm(2,k+1,mod))%mod-powm(2,k,mod)+1)%mod+mod)%mod);\n\t\tSystem.out.print(output);\n\t}\n\t///////////////////////////////////////////\n\t///////////////////////////////////////////\n\t///template from here\n\tstatic class pair\n\t{\n\t\tlong a, b;\n\t\tpair(){}\n\t\tpair(long c,long d){a=c;b=d;}\n\t}\n\tstatic interface combiner\n\t{\n\t\tpublic long combine(long a, long b);\n\t}\n\tstatic final int mod=1000000007;\n\tstatic final double eps=1e-9;\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\tstatic void reverse(int[]a){for(int i=0; i<a.length/2; i++){a[i]^=a[a.length-i-1];a[a.length-i-1]^=a[i];a[i]^=a[a.length-i-1];}}\n\tstatic void sort(int[]a)\n\t{\n\t\tint te;\n\t\tfor(int i=0; i<a.length; i+=2)\n\t\t{\n\t\t\tte=rn.nextInt(a.length);\n\t\t\tif(i!=te)\n\t\t\t{\n\t\t\t\ta[i]^=a[te];\n\t\t\t\ta[te]^=a[i];\n\t\t\t\ta[i]^=a[te];\n\t\t\t}\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tstatic void sort(long[]a)\n\t{\n\t\tint te;\n\t\tfor(int i=0; i<a.length; i+=2)\n\t\t{\n\t\t\tte=rn.nextInt(a.length);\n\t\t\tif(i!=te)\n\t\t\t{\n\t\t\ta[i]^=a[te];\n\t\t\ta[te]^=a[i];\n\t\t\ta[i]^=a[te];\n\t\t\t}\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tstatic void sort(double[]a)\n\t{\n\t\tint te;\n\t\tdouble te1;\n\t\tfor(int i=0; i<a.length; i+=2)\n\t\t{\n\t\t\tte=rn.nextInt(a.length);\n\t\t\tif(i!=te)\n\t\t\t{\n\t\t\tte1=a[te];\n\t\t\ta[te]=a[i];\n\t\t\ta[i]=te1;\n\t\t\t}\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tstatic void sort(int[][]a)\n\t{\n\t\tArrays.sort(a, new Comparator<int[]>()\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 void sort(pair[]a)\n\t{\n\t\tArrays.sort(a,new Comparator<pair>()\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 vector implements Iterable<Integer>\n\t{\n\t\tint a[],size;\n\t\tvector(){a=new int[10];size=0;}\n\t\tvector(int n){a=new int[n];size=0;}\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<Integer> iterator() {\n\t\t\tIterator<Integer> hola=new Iterator<Integer>()\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<size;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Integer next() {\n\t\t\t\t\t\t\treturn a[cur++];\n\t\t\t\t\t\t}\t\t\t\t\n\t\t\t\t\t};\n\t\t\treturn hola;\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 Integer.parseInt(in.next());}\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; i++)a[i]=ni();return a;}\n\tstatic int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}\n\tstatic long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}\n\tstatic String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}\n\tstatic double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}\n\t//////////////////////////////////\n\t//some utility functions\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 m)\n\t{long an=1;long c=a;while(b>0)\n\t{if(b%2==1)an=(an*c)%m;c=(c*c)%m;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), 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    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\npublic class Main {\n\n\n  private static void solve() {\n    long x = nl();\n    long k = nl();\n    long mod = 1000000000 + 7;\n    \n    if (x == 0) {\n      System.out.println(0);\n    } else if (k == 0) {\n      System.out.println(x * 2 % mod);\n      \n    } else {\n      //x > 0, n > 0\n      x %= mod;\n\n      long a;\n      a = (x - 1 + mod) * pow(2, k, mod) + 1;\n      a %= mod;\n\n      long b = x * pow(2, k, mod);\n      b %= mod;\n      \n      System.out.println((a + b) % mod);\n    }\n  }\n\n  public static long pow(long a, long n, long mod)\n  {\n//    a %= mod;\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  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", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "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 n = nl(), k = nl();\n\t\t\tif(n==0){\n\t\t\t\tpw.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlong MOD = 1000000007;\n\t\t\tlong pow1 = pow(2,k,MOD), pow2 = pow(2,k+1,MOD);\n\t\t\tpw.println(((((n%MOD)*pow2)%MOD) - (pow1-1+MOD)%MOD + 2*MOD)%MOD);\n\t\t\tpw.close();\t\n\t\t}\n\t\tlong pow(long x, long y, long mod){\n\t\t\tlong ans = 1;\n\t\t\twhile(y>0){\n\t\t\t\tif(y%2==0) {\n\t\t\t\t\tx *= x;\n\t\t\t\t\tx %= mod;\n\t\t\t\t\ty/=2;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tans *= x;\n\t\t\t\t\tans %= mod;\n\t\t\t\t\ty-=1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ans;\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<y)?x:y;\n\t}\n\tstatic class Pair implements Comparable<Pair>{\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}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class C extends PrintWriter {\n\n    final long mod = 1_000_000_007;\n\n    long pow(long n, long p) {\n        long r = 1;\n\n        while (p > 0) {\n            if (p % 2 == 1) {\n                r = (r * n) % mod;\n            }\n            n = (n * n) % mod;\n            p /= 2;\n        }\n\n        return r;\n    }\n\n    long solve(long n, long k) {\n\n        if (k == 0) {\n            return (2 * n) % mod;\n        }\n\n        if (n == 0) {\n            return 0;\n        }\n\n        long m = pow(2, k);\n\n        long a = 2;\n\n        a = (a * n) % mod;\n        a = (a * m) % mod;\n\n        long b = (m + mod - 1) % mod;\n\n        return ((a - b + mod) % mod);\n    }\n\n    void run() {\n        long n = nextLong();\n        long k = nextLong();\n\n        println(solve(n, k));\n    }\n\n    boolean skip() {\n        while (hasNext()) {\n            next();\n        }\n        return true;\n    }\n\n    int[][] nextMatrix(int n, int m) {\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] = nextInt();\n        return matrix;\n    }\n\n    String next() {\n        while (!tokenizer.hasMoreTokens())\n            tokenizer = new StringTokenizer(nextLine());\n        return tokenizer.nextToken();\n    }\n\n    boolean hasNext() {\n        while (!tokenizer.hasMoreTokens()) {\n            String line = nextLine();\n            if (line == null) {\n                return false;\n            }\n            tokenizer = new StringTokenizer(line);\n        }\n        return true;\n    }\n\n    int[] nextArray(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    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 reader.readLine();\n        } catch (IOException err) {\n            return null;\n        }\n    }\n\n    public C(OutputStream outputStream) {\n        super(outputStream);\n    }\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer = new StringTokenizer(\"\");\n    static Random rnd = new Random();\n    static boolean OJ;\n\n    public static void main(String[] args) throws IOException {\n        OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n        C solution = new C(System.out);\n        if (OJ) {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            solution.run();\n        } else {\n            reader = new BufferedReader(new FileReader(new File(C.class.getName() + \".txt\")));\n            long timeout = System.currentTimeMillis();\n            while (solution.hasNext()) {\n                solution.run();\n                solution.println();\n                solution.println(\"----------------------------------\");\n            }\n            solution.println(\"time: \" + (System.currentTimeMillis() - timeout));\n        }\n        solution.close();\n        reader.close();\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.*;\nimport java.util.StringTokenizer;\npublic class Main{   \n    public long power(long x, long y, long p)\n    {\n\n        long res = 1;     \n  \n     \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    public static void main(String[] args) throws IOException{\n        // TODO Auto-generated method stub\n        Scanner sc=new Scanner(System.in);  \n        Main mm=new Main(); \n        long x=sc.nextLong();\n            long k=sc.nextLong();\n            if(x==0) {\n                System.out.println(0);\n            }\n            else {\n            long temp=mm.power(2, k, 1000000007);\n            long temp1=(2*x-1)%(1000000007);\n            long temp3=(temp1*temp)%(1000000007);\n            System.out.println((temp3+1)%1000000007);\n            }\n    }\n }\n    \nclass trienode{\n    trienode[] next=new trienode[26];\n    int count;\n    char value;\n    boolean last;\n    trienode() {\n        this.value='0';\n        this.count=0;\n    }\n    trienode(char x) {\n        this.value=x;\n        this.count=1;\n    }\n \n}\nclass trie{\n    trienode root=new trienode();\n    public void insert(String s) {\n        trienode temp=root;\n        int length=s.length();\n        for(int i=0;i<length;i++) {\n            char c=s.charAt(i);\n            int index=c-'a';\n            if(temp.next[index]==null) {\n                temp.next[index]=new trienode(c);\n            }\n            else {\n                temp.next[index].count++;\n            }\n            if(i==length-1) {\n                temp.next[index].last=true;\n            }\n            temp=temp.next[index];\n \n        }\n \n    }\n    public String find(String s) {\n        trienode temp=root;\n        String ans=\"\";\n        int pos=0;\n        char c=s.charAt(pos);\n        int index=c-'a';\n        while(temp.next[index]!=null) {\n            temp=temp.next[index];\n            ans+=temp.value;\n            if(pos==s.length()-1) {\n                break;\n            }\n            c=s.charAt(++pos);\n            index=c-'a';\n            \n        }\n        while(temp.last!=true) {\n            int position=-1;\n            for(int i=0;i<26;i++) {\n            if(temp.next[i]!=null) {\n                ans+=temp.next[i].value;\n                position=i+0;\n                break;\n            }\n                \n        }\n            temp=temp.next[position];\n        }\n        return ans;\n    }\n}\nclass node{\n    int index;\n    int a;\n    int b;\n    node(int index,int a,int b){\n        this.a=a;\n        this.b=b;this.index=index;\n        \n    }\n}\nclass comp implements Comparator<node>{\n    public int compare(node n1,node n2) {\n        if(n1.b>n2.b) {\n            return 1;\n        }\n        else if(n1.b<n2.b) {\n            return -1;\n        }\n        else {\n            return 0;\n        }\n    }\n}\nclass cc implements Comparator<node>{\n    public int compare(node n1,node n2) {\n        if(n1.index>n2.index) {\n            return 1;\n        }\n        else if(n1.index<n2.index) {\n            return -1;\n        }\n        else {\n            return 0;\n        }\n    }\n}\n\n \n \n \n/** Class for buffered reading int and double values */\nclass Reader {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n \n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n \n    /** get next word */\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n \n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class virtual1{\n\n    static InputReader in = new InputReader();\n    static PrintWriter out = new PrintWriter(System.out);\n    \n    public static void main(String[] args) {\n            long x = in.nextLong();\n            long k = in.nextLong();\n            long mod = (long)1e9+7l;\n            //out.println(mod);\n            long mul1 = 1;\n            long mul2 = 2*x-1;\n            mul2 = mul2%mod;\n            long pow = k;\n            long to = 2;\n            while(pow>0l){\n                if(pow%2l==1l){\n                    mul1 = mul1*to;\n                    mul1%=mod;\n                }\n                to=to*to;\n                to%=mod;\n                pow = pow/2l;\n            }\n            mul1 = mul1*mul2;\n            mul1%=mod;\n            mul1+=1;\n            if(x!=0)\n            out.println(mul1%mod);\n            else\n            out.println(0);\n        \n        out.close();    \n    }\n\n    static class InputReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public InputReader()\n        {\n            br = new BufferedReader(new\n                     InputStreamReader(System.in));\n        }\n \n        String next()\n        {\n            while (st == null || !st.hasMoreElements())\n            {\n                try\n                {\n                    st = new StringTokenizer(br.readLine());\n                }\n                catch (IOException  e)\n                {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n \n        int nextInt()\n        {\n            return Integer.parseInt(next());\n        }\n \n        long nextLong()\n        {\n            return Long.parseLong(next());\n        }\n \n        double nextDouble()\n        {\n            return Double.parseDouble(next());\n        }\n \n        String nextLine()\n        {\n            String str = \"\";\n            try\n            {\n                str = br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class algo93\n{\n    public static void main(String args[])\n    {\n        Scanner ex=new Scanner(System.in);\n        long x=ex.nextLong();\n        long k=ex.nextLong();\n        long mod=1000000007;\n        if(k==0)\n        System.out.println((2*x)%mod);\n        else if(x==0)\n        System.out.println(\"0\");\n        else\n        {\n            long pow=power(2,k);\n            long pow1=(2*pow)%mod;\n            long ans=(pow1*(x%mod))-pow+1;\n            if(ans<0)\n            ans=ans+mod;\n            ans=ans%mod;\n            System.out.println(ans);\n        }\n    }\n    public static long power(long x,long y)\n    {\n        if (y == 0)\n        return 1;\n        long mod=1000000007;\n        long pow=power(x,y/2);\n        pow=(pow*pow)%mod;\n        if(y%2==0)\n        return pow;\n        else\n        return ((x%mod)*pow)%mod;\n    }\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Test {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1024 * 48);\n        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n        String str = br.readLine();\n        StringTokenizer st = new StringTokenizer(str, \" \");\n        long x = Long.parseLong(st.nextToken());\n        long k = Long.parseLong(st.nextToken());\n        if (x == 0) {\n            bw.write(0 + \"\\n\");\n        } else {\n            int power = power(k, 1000000007);\n            long answer = (((power * 2) % 1000000007) * (x % 1000000007)) % 1000000007;\n            answer -= power - 1;\n            answer = (answer + 1000000007) % 1000000007;\n            bw.write(answer + \"\\n\");\n        }\n        bw.flush();\n    }\n\n    public static int power(long a, int m) {\n        if (a == 0) {\n            return 1;\n        }\n        long pow = power(a / 2, m);\n        if (a % 2 == 1) {\n            return (int)(((pow * pow) % m) * 2) % m;\n        } else {\n            return (int)((pow * pow) % m);\n        }\n    }\n}\n", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main\n{\n\tstatic long MOD=1000000007;\n\tpublic static long pow(long x,long k){\n\t\tlong base=x%MOD;\n\t\tlong res=1;\n\t\twhile(k>0){\n\t\t\tif((k&1)==1){\n\t\t\t\tres=(res*base)%MOD;\n\t\t\t}\n\t\t\tbase=(base*base)%MOD;\n\t\t\tk>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner scan=new Scanner(System.in);\n\t\tlong x=scan.nextLong();\n\t\tlong k=scan.nextLong();\n\t\tlong MOD=1000000007;\n\t\tif(x==0){System.out.println(0);return;}\n\t\tx %= MOD;\n\t\tlong a=pow(2L,k+1);\n\t\tlong b=pow(2L,k);\n\t\tlong res=(a*x)%MOD-b+1;\n\t\tif(res<0){res+=MOD;}\n\t\tSystem.out.println(res%MOD);\n\t}\n}", "complexity": "logn", "problem": "992_C. Nastya and a Wardrobe", "from": "CODEFORCES"}
{"src": "\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_371_Div1 {\n\n    public static long MOD = 1000000007;\n    static int c = 0;\n\n    public static void main(String[] args) throws FileNotFoundException {\n        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n        // \"output.txt\")));\n\n        Scanner in = new Scanner();\n        int n = in.nextInt();\n        int minX = -1;\n        int start = 1;\n        int end = n;\n        c = 0;\n        while (start <= end) {\n            int mid = (start + end) >> 1;\n            c = increaseC(c);\n            System.out.println(\"? \" + mid + \" 1 \" + n + \" \" + n);\n            System.out.flush();\n\n            int v = in.nextInt();\n            if (v == 2) {\n                minX = mid;\n                start = mid + 1;\n            } else {\n                end = mid - 1;\n            }\n        }\n        //System.out.println(\"Minx \" + minX);\n        int maxX = -1;\n        start = minX;\n        end = n;\n        while (start <= end) {\n            int mid = (start + end) >> 1;\n            c = increaseC(c);\n            System.out.println(\"? \" + minX + \" 1 \" + mid + \" \" + n);\n            System.out.flush();\n            int v = in.nextInt();\n            if (v == 2) {\n                maxX = mid;\n                end = mid - 1;\n            } else {\n                start = mid + 1;\n            }\n        }\n        // System.out.println(\"Maxx \" + maxX);\n        int minY = -1;\n        start = 1;\n        end = n;\n        while (start <= end) {\n            int mid = (start + end) >> 1;\n            c = increaseC(c);\n            System.out.println(\"? \" + minX + \" \" + mid + \" \" + maxX + \" \" + n);\n            System.out.flush();\n\n            int v = in.nextInt();\n            if (v == 2) {\n                minY = mid;\n                start = mid + 1;\n            } else {\n                end = mid - 1;\n            }\n        }\n        // System.out.println(\"MinY \" + minY);\n        int maxY = -1;\n        start = minY;\n        end = n;\n        while (start <= end) {\n            int mid = (start + end) >> 1;\n            c = increaseC(c);\n            System.out.println(\"? \" + minX + \" \" + minY + \" \" + maxX + \" \" + mid);\n            System.out.flush();\n\n            int v = in.nextInt();\n            if (v == 2) {\n                maxY = mid;\n                end = mid - 1;\n            } else {\n                start = mid + 1;\n            }\n        }\n        // System.out.println(\"MaxY \" + maxY);\n        int middleMinX = maxX;\n        start = minX;\n        end = maxX;\n        while (start <= end) {\n            int mid = (start + end) >> 1;\n            c = increaseC(c);\n            System.out.println(\"? \" + minX + \" \" + minY + \" \" + mid + \" \" + maxY);\n            System.out.flush();\n\n            int v = in.nextInt();\n            if (v == 1) {\n                middleMinX = mid;\n                end = mid - 1;\n            } else {\n                start = mid + 1;\n            }\n        }\n        //System.out.println(\"MiddleMinX \" + middleMinX);\n        int middleMaxX = -1;\n        start = middleMinX + 1;\n        end = maxX;\n        while (start <= end) {\n            int mid = (start + end) >> 1;\n            c = increaseC(c);\n            System.out.println(\"? \" + mid + \" \" + minY + \" \" + maxX + \" \" + maxY);\n            System.out.flush();\n\n            int v = in.nextInt();\n            if (v == 1) {\n                middleMaxX = mid;\n                start = mid + 1;\n            } else {\n                end = mid - 1;\n            }\n        }\n\n        // System.out.println(\"MiddleMaxX \" + middleMaxX);\n        if (middleMaxX == -1) {\n            int middleMinY = -1;\n            start = minY;\n            end = maxY;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + minY + \" \" + maxX + \" \" + mid);\n                System.out.flush();\n\n                int v = in.nextInt();\n                if (v == 1) {\n                    middleMinY = mid;\n                    end = mid - 1;\n                } else {\n                    start = mid + 1;\n                }\n            }\n            //System.out.println(\"MiddleMinY \" + middleMinY);\n            int middleMaxY = -1;\n            start = middleMinY + 1;\n            end = maxY;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + mid + \" \" + maxX + \" \" + maxY);\n                System.out.flush();\n\n                int v = in.nextInt();\n                if (v == 1) {\n                    middleMaxY = mid;\n                    start = mid + 1;\n                } else {\n                    end = mid - 1;\n                }\n            }\n            //System.out.println(\"MiddleMaxY \" + middleMaxY);\n            if (minX == maxX) {\n                System.out.println(\"! \" + minX + \" \" + minY + \" \" + maxX + \" \" + middleMinY + \" \" + minX + \" \" + middleMaxY + \" \" + maxX + \" \" + maxY);\n                System.out.flush();\n            } else {\n                int[] a = calX(minX, maxX, minY, middleMinY, in);\n                int[] b = calX(minX, maxX, middleMaxY, maxY, in);\n                check(a);\n                check(b);\n                System.out.println(\"! \" + a[0] + \" \" + minY + \" \" + a[1] + \" \" + middleMinY + \" \" + b[0] + \" \" + middleMaxY + \" \" + b[1] + \" \" + maxY);\n                System.out.flush();\n            }\n        } else if (minY == maxY) {\n            System.out.println(\"! \" + minX + \" \" + minY + \" \" + middleMinX + \" \" + maxY + \" \" + middleMaxX + \" \" + minY + \" \" + maxX + \" \" + maxY);\n            System.out.flush();\n        } else {\n            int[] a = calY(minX, middleMinX, minY, maxY, in);\n            int[] b = calY(middleMaxX, maxX, minY, maxY, in);\n            check(a);\n            check(b);\n            System.out.println(\"! \" + minX + \" \" + a[0] + \" \" + middleMinX + \" \" + a[1] + \" \" + middleMaxX + \" \" + b[0] + \" \" + maxX + \" \" + b[1]);\n            System.out.flush();\n        }\n\n    }\n\n    static void check(int[] v) {\n        if (v[0] == -1 || v[1] == -1) {\n            throw new NullPointerException();\n        }\n    }\n\n    static int increaseC(int c) {\n        if (c == 200) {\n            throw new NullPointerException();\n        }\n        return c + 1;\n    }\n\n    public static int[] calY(int minX, int maxX, int minY, int maxY, Scanner in) {\n        c = increaseC(c);\n        System.out.println(\"? \" + minX + \" \" + minY + \" \" + maxX + \" \" + (maxY - 1));\n        System.out.flush();\n        int v = in.nextInt();\n        c = increaseC(c);\n        System.out.println(\"? \" + minX + \" \" + (minY + 1) + \" \" + maxX + \" \" + maxY);\n        System.out.flush();\n        int o = in.nextInt();\n        if (v == 1 && o == 1) {\n            int a = -1;\n            int start = minY;\n            int end = maxY;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + minY + \" \" + maxX + \" \" + mid);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    a = mid;\n                    end = mid - 1;\n                } else {\n                    start = mid + 1;\n                }\n            }\n            int b = -1;\n            start = minY;\n            end = a;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + mid + \" \" + maxX + \" \" + a);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    b = mid;\n                    start = mid + 1;\n                } else {\n                    end = mid - 1;\n                }\n            }\n            return new int[]{b, a};\n        } else if (v == 1) {\n            int a = -1;\n            int start = minY;\n            int end = maxY;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + minY + \" \" + maxX + \" \" + mid);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    a = mid;\n                    end = mid - 1;\n                } else {\n                    start = mid + 1;\n                }\n            }\n            return new int[]{minY, a};\n        } else if (o == 1) {\n            int b = -1;\n            int start = minY;\n            int end = maxY;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + mid + \" \" + maxX + \" \" + maxY);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    b = mid;\n                    start = mid + 1;\n                } else {\n                    end = mid - 1;\n                }\n            }\n            return new int[]{b, maxY};\n        } else {\n            return new int[]{minY, maxY};\n        }\n    }\n\n    public static int[] calX(int minX, int maxX, int minY, int maxY, Scanner in) {\n        c = increaseC(c);\n        System.out.println(\"? \" + minX + \" \" + minY + \" \" + (maxX - 1) + \" \" + maxY);\n        System.out.flush();\n        int v = in.nextInt();\n        c = increaseC(c);\n        System.out.println(\"? \" + (minX + 1) + \" \" + minY + \" \" + maxX + \" \" + maxY);\n        System.out.flush();\n        int o = in.nextInt();\n        if (v == 1 && o == 1) {\n            int a = -1;\n            int start = minX;\n            int end = maxX;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + minY + \" \" + mid + \" \" + maxY);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    a = mid;\n                    end = mid - 1;\n                } else {\n                    start = mid + 1;\n                }\n            }\n            int b = -1;\n            start = minX;\n            end = a;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + mid + \" \" + minY + \" \" + a + \" \" + maxY);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    b = mid;\n                    start = mid + 1;\n                } else {\n                    end = mid - 1;\n                }\n            }\n            return new int[]{b, a};\n        } else if (v == 1) {\n            int a = -1;\n            int start = minX;\n            int end = maxX;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + minX + \" \" + minY + \" \" + mid + \" \" + maxY);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    a = mid;\n                    end = mid - 1;\n                } else {\n                    start = mid + 1;\n                }\n            }\n            return new int[]{minX, a};\n        } else if (o == 1) {\n            int b = -1;\n            int start = minX;\n            int end = maxX;\n            while (start <= end) {\n                int mid = (start + end) >> 1;\n                c = increaseC(c);\n                System.out.println(\"? \" + mid + \" \" + minY + \" \" + maxX + \" \" + maxY);\n                System.out.flush();\n                if (in.nextInt() == 1) {\n                    b = mid;\n                    start = mid + 1;\n                } else {\n                    end = mid - 1;\n                }\n            }\n            return new int[]{b, maxX};\n        } else {\n            return new int[]{minX, maxX};\n        }\n    }\n\n    public static int[] KMP(String val) {\n        int i = 0;\n        int j = -1;\n        int[] result = new int[val.length() + 1];\n        result[0] = -1;\n        while (i < val.length()) {\n            while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n                j = result[j];\n            }\n            j++;\n            i++;\n            result[i] = j;\n        }\n        return result;\n\n    }\n\n    public static boolean nextPer(int[] data) {\n        int i = data.length - 1;\n        while (i > 0 && data[i] < data[i - 1]) {\n            i--;\n        }\n        if (i == 0) {\n            return false;\n        }\n        int j = data.length - 1;\n        while (data[j] < data[i - 1]) {\n            j--;\n        }\n        int temp = data[i - 1];\n        data[i - 1] = data[j];\n        data[j] = temp;\n        Arrays.sort(data, i, data.length);\n        return true;\n    }\n\n    public static int digit(long n) {\n        int result = 0;\n        while (n > 0) {\n            n /= 10;\n            result++;\n        }\n        return result;\n    }\n\n    public static double dist(long a, long b, long x, long y) {\n        double val = (b - a) * (b - a) + (x - y) * (x - y);\n        val = Math.sqrt(val);\n        double other = x * x + a * a;\n        other = Math.sqrt(other);\n        return val + other;\n\n    }\n\n    public static class Point implements Comparable<Point> {\n\n        int x, y;\n\n        public Point(int start, int end) {\n            this.x = start;\n            this.y = end;\n        }\n\n        @Override\n        public int hashCode() {\n            int hash = 5;\n            hash = 47 * hash + this.x;\n            hash = 47 * hash + this.y;\n            return hash;\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            if (obj == null) {\n                return false;\n            }\n            if (getClass() != obj.getClass()) {\n                return false;\n            }\n            final Point other = (Point) obj;\n            if (this.x != other.x) {\n                return false;\n            }\n            if (this.y != other.y) {\n                return false;\n            }\n            return true;\n        }\n\n        @Override\n        public int compareTo(Point o) {\n            return Integer.compare(x, o.x);\n        }\n    }\n\n    public static class FT {\n\n        long[] data;\n\n        FT(int n) {\n            data = new long[n];\n        }\n\n        public void update(int index, long value) {\n            while (index < data.length) {\n                data[index] += value;\n                index += (index & (-index));\n            }\n        }\n\n        public long get(int index) {\n            long result = 0;\n            while (index > 0) {\n                result += data[index];\n                index -= (index & (-index));\n            }\n            return result;\n\n        }\n    }\n\n    public static long gcd(long a, long b) {\n        if (b == 0) {\n            return a;\n        }\n        return gcd(b, a % b);\n    }\n\n    public static long pow(long a, 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}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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.Scanner;\nimport java.util.InputMismatchException;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.util.ArrayList;\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 ilyakor\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        ArrayList<PointInt[]> al;\n        TaskB.Interactor interactor;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            //for (int itt = 0; itt < 100; ++itt) {\n            interactor = new TaskB.IOInteractor(new Scanner(in.getStream()), out.getWriter());//new TestInteractor(n);\n            Assert.assertTrue(interactor.query(1, 1, n, n) == 2);\n            int lx = 1, rx = n, ly = 1, ry = n;\n            for (int it = 0; it < 20; ++it) {\n                int tx = (lx + rx) / 2;\n                if (interactor.query(1, 1, tx, n) >= 1)\n                    rx = tx;\n                else\n                    lx = tx;\n                int ty = (ly + ry) / 2;\n                if (interactor.query(1, 1, n, ty) >= 1)\n                    ry = ty;\n                else\n                    ly = ty;\n            }\n            al = new ArrayList<>();\n            if (interactor.query(1, 1, lx, n) == 1 && interactor.query(lx + 1, 1, n, n) == 1) {\n                dfs(1, 1, lx, n);\n                dfs(lx + 1, 1, n, n);\n            } else if (interactor.query(1, 1, rx, n) == 1 && interactor.query(rx + 1, 1, n, n) == 1) {\n                dfs(1, 1, rx, n);\n                dfs(rx + 1, 1, n, n);\n            } else if (interactor.query(1, 1, n, ly) == 1 && interactor.query(1, ly + 1, n, n) == 1) {\n                dfs(1, 1, n, ly);\n                dfs(1, ly + 1, n, n);\n            } else if (interactor.query(1, 1, n, ry) == 1 && interactor.query(1, ry + 1, n, n) == 1) {\n                dfs(1, 1, n, ry);\n                dfs(1, ry + 1, n, n);\n            } else {\n                throw new RuntimeException(\"WTF\");\n            }\n            Assert.assertTrue(al.size() == 2);\n            interactor.answer(al.get(0)[0].x, al.get(0)[0].y, al.get(0)[1].x, al.get(0)[1].y, al.get(1)[0].x, al.get(1)[0].y, al.get(1)[1].x, al.get(1)[1].y);\n            //}\n        }\n\n        private void dfs(int x1, int y1, int x2, int y2) {\n            int t;\n            t = x1;\n            for (int i = 0; i < 20; ++i) {\n                int x = (t + x2) / 2;\n                if (interactor.query(x1, y1, x, y2) == 1)\n                    x2 = x;\n                else\n                    t = x;\n            }\n            if (interactor.query(x1, y1, t, y2) == 1)\n                x2 = t;\n            t = x2;\n            for (int i = 0; i < 20; ++i) {\n                int x = (t + x1) / 2;\n                if (interactor.query(x, y1, x2, y2) == 1)\n                    x1 = x;\n                else\n                    t = x;\n            }\n            if (interactor.query(t, y1, x2, y2) == 1)\n                x1 = t;\n            t = y1;\n            for (int i = 0; i < 20; ++i) {\n                int y = (t + y2) / 2;\n                if (interactor.query(x1, y1, x2, y) == 1)\n                    y2 = y;\n                else\n                    t = y;\n            }\n            if (interactor.query(x1, y1, x2, t) == 1)\n                y2 = t;\n            t = y2;\n            for (int i = 0; i < 20; ++i) {\n                int y = (t + y1) / 2;\n                if (interactor.query(x1, y, x2, y2) == 1)\n                    y1 = y;\n                else\n                    t = y;\n            }\n            if (interactor.query(x1, t, x2, y2) == 1)\n                y1 = t;\n\n            al.add(new PointInt[]{new PointInt(x1, y1), new PointInt(x2, y2)});\n        }\n\n        interface Interactor {\n            int query(int x1, int y1, int x2, int y2);\n\n            void answer(int x11, int y11, int x12, int y12,\n                        int x21, int y21, int x22, int y22);\n\n        }\n\n        static class Query {\n            int x1;\n            int y1;\n            int x2;\n            int y2;\n\n            public Query(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\n            public boolean equals(Object o) {\n                if (this == o) return true;\n                if (o == null || getClass() != o.getClass()) return false;\n\n                TaskB.Query query = (TaskB.Query) o;\n\n                if (x1 != query.x1) return false;\n                if (y1 != query.y1) return false;\n                if (x2 != query.x2) return false;\n                return y2 == query.y2;\n\n            }\n\n\n            public int hashCode() {\n                int result = x1;\n                result = 31 * result + y1;\n                result = 31 * result + x2;\n                result = 31 * result + y2;\n                return result;\n            }\n\n        }\n\n        static class IOInteractor implements TaskB.Interactor {\n            Scanner in;\n            PrintWriter out;\n            HashMap<TaskB.Query, Integer> cache;\n\n            public IOInteractor(Scanner in, PrintWriter out) {\n                this.in = in;\n                this.out = out;\n                cache = new HashMap<>();\n            }\n\n\n            public int query(int x1, int y1, int x2, int y2) {\n                TaskB.Query q = new TaskB.Query(x1, y1, x2, y2);\n                if (cache.containsKey(q))\n                    return cache.get(q);\n                if (x1 > x2 || y1 > y2)\n                    return 0;\n                Assert.assertTrue(x1 >= 1 && y1 >= 1);\n                out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n                out.flush();\n                int res = in.nextInt();\n                cache.put(q, res);\n                return res;\n            }\n\n\n            public void answer(int x11, int y11, int x12, int y12, int x21, int y21, int x22, int y22) {\n                out.println(\"! \" + x11 + \" \" + y11 + \" \" + x12 + \" \" + y12 + \" \" + x21 + \" \" + y21 + \" \" + x22 + \" \" + y22);\n                out.flush();\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buffer = new byte[10000];\n        private int cur;\n        private int count;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public static boolean isSpace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public int read() {\n            if (count == -1) {\n                throw new InputMismatchException();\n            }\n            try {\n                if (cur >= count) {\n                    cur = 0;\n                    count = stream.read(buffer);\n                    if (count <= 0)\n                        return -1;\n                }\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            return buffer[cur++];\n        }\n\n        public int readSkipSpace() {\n            int c;\n            do {\n                c = read();\n            } while (isSpace(c));\n            return c;\n        }\n\n        public int nextInt() {\n            int sgn = 1;\n            int c = readSkipSpace();\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res = res * 10 + c - '0';\n                c = read();\n            } while (!isSpace(c));\n            res *= sgn;\n            return res;\n        }\n\n        public InputStream getStream() {\n            return stream;\n        }\n\n    }\n\n    static class PointInt {\n        public int x;\n        public int y;\n\n        public PointInt(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        public PointInt() {\n            x = 0;\n            y = 0;\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public PrintWriter getWriter() {\n            return writer;\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n\n    static class Assert {\n        public static void assertTrue(boolean flag) {\n//        if (!flag)\n//        while (true);\n            if (!flag)\n                throw new AssertionError();\n        }\n\n    }\n}\n\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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 << 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            BSearchingRectangles solver = new BSearchingRectangles();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class BSearchingRectangles {\n        FastInput in;\n        FastOutput out;\n        int n;\n\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            this.in = in;\n            this.out = out;\n            n = in.readInt();\n\n            IntBinarySearch upDown = new IntBinarySearch() {\n\n                public boolean check(int mid) {\n                    return query(1, n, 1, mid) >= 1;\n                }\n            };\n\n            IntBinarySearch leftRight = new IntBinarySearch() {\n\n                public boolean check(int mid) {\n                    return query(1, mid, 1, n) >= 1;\n                }\n            };\n            int threshold = upDown.binarySearch(1, n);\n            int[] r1;\n            int[] r2;\n            if (query(1, n, 1, threshold) == 1 &&\n                    query(1, n, threshold + 1, n) == 1) {\n                r1 = find(1, n, 1, threshold);\n                r2 = find(1, n, threshold + 1, n);\n            } else {\n                threshold = leftRight.binarySearch(1, n);\n                r1 = find(1, threshold, 1, n);\n                r2 = find(threshold + 1, n, 1, n);\n            }\n\n            out.append(\"! \");\n            output(r1);\n            output(r2);\n            out.flush();\n        }\n\n        public void output(int[] ans) {\n            for (int x : ans) {\n                out.append(x).append(' ');\n            }\n        }\n\n        public int[] find(int l, int r, int d, int u) {\n            IntBinarySearch downIBS = new IntBinarySearch() {\n\n                public boolean check(int mid) {\n                    return query(l, r, mid, u) == 0;\n                }\n            };\n            int y1 = downIBS.binarySearch(d, u);\n            if (query(l, r, y1, u) == 0) {\n                y1--;\n            }\n\n            IntBinarySearch upIBS = new IntBinarySearch() {\n\n                public boolean check(int mid) {\n                    return query(l, r, d, mid) >= 1;\n                }\n            };\n            int y2 = upIBS.binarySearch(d, u);\n\n            IntBinarySearch leftIBS = new IntBinarySearch() {\n\n                public boolean check(int mid) {\n                    return query(mid, r, d, u) == 0;\n                }\n            };\n            int x1 = leftIBS.binarySearch(l, r);\n            if (query(x1, r, d, u) == 0) {\n                x1--;\n            }\n\n            IntBinarySearch rightIBS = new IntBinarySearch() {\n\n                public boolean check(int mid) {\n                    return query(l, mid, d, u) >= 1;\n                }\n            };\n            int x2 = rightIBS.binarySearch(l, r);\n\n            return new int[]{x1, y1, x2, y2};\n        }\n\n        public int query(int l, int r, int d, int u) {\n            if (l > r || d > u) {\n                return 0;\n            }\n            out.printf(\"? %d %d %d %d\", l, d, r, u).println().flush();\n            return in.readInt();\n        }\n\n    }\n\n    static class DigitUtils {\n        private DigitUtils() {\n        }\n\n        public static int floorAverage(int x, int y) {\n            return (x & y) + ((x ^ y) >> 1);\n        }\n\n    }\n\n    static abstract class IntBinarySearch {\n        public abstract boolean check(int mid);\n\n        public int binarySearch(int l, int r) {\n            if (l > r) {\n                throw new IllegalArgumentException();\n            }\n            while (l < r) {\n                int mid = DigitUtils.floorAverage(l, r);\n                if (check(mid)) {\n                    r = mid;\n                } else {\n                    l = mid + 1;\n                }\n            }\n            return l;\n        }\n\n    }\n\n    static class FastInput {\n        private final InputStream is;\n        private byte[] buf = new byte[1 << 13];\n        private int bufLen;\n        private int bufOffset;\n        private int next;\n\n        public FastInput(InputStream is) {\n            this.is = is;\n        }\n\n        private int read() {\n            while (bufLen == bufOffset) {\n                bufOffset = 0;\n                try {\n                    bufLen = is.read(buf);\n                } catch (IOException e) {\n                    bufLen = -1;\n                }\n                if (bufLen == -1) {\n                    return -1;\n                }\n            }\n            return buf[bufOffset++];\n        }\n\n        public void skipBlank() {\n            while (next >= 0 && next <= 32) {\n                next = read();\n            }\n        }\n\n        public int readInt() {\n            int sign = 1;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                sign = next == '+' ? 1 : -1;\n                next = read();\n            }\n\n            int val = 0;\n            if (sign == 1) {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 + next - '0';\n                    next = read();\n                }\n            } else {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 - next + '0';\n                    next = read();\n                }\n            }\n\n            return val;\n        }\n\n    }\n\n    static class FastOutput implements AutoCloseable, Closeable, Appendable {\n        private StringBuilder cache = new StringBuilder(10 << 20);\n        private final Writer os;\n\n        public FastOutput append(CharSequence csq) {\n            cache.append(csq);\n            return this;\n        }\n\n        public FastOutput append(CharSequence csq, int start, int end) {\n            cache.append(csq, start, end);\n            return this;\n        }\n\n        public FastOutput(Writer os) {\n            this.os = os;\n        }\n\n        public FastOutput(OutputStream os) {\n            this(new OutputStreamWriter(os));\n        }\n\n        public FastOutput append(char c) {\n            cache.append(c);\n            return this;\n        }\n\n        public FastOutput append(int c) {\n            cache.append(c);\n            return this;\n        }\n\n        public FastOutput 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\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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 l1 = 1;\n\t\tint r1 = n;\n\t\tint b1 = 1;\n\t\tint t1 = n;\n\t\tint min = b1;\n\t\tint max = t1;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max)/2;\n\t\t\tSystem.out.println(\"? \"+l1+\" \"+b1+\" \"+r1+\" \"+mid);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmax = mid;\n\t\t\telse\n\t\t\t\tmin = mid+1;\n\t\t}\n\t\tt1 = min;\n\t\tmin = l1;\n\t\tmax = r1;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max)/2;\n\t\t\tSystem.out.println(\"? \"+l1+\" \"+b1+\" \"+mid+\" \"+t1);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmax = mid;\n\t\t\telse\n\t\t\t\tmin = mid+1;\n\t\t}\n\t\tr1 = min;\n\t\tmin = b1;\n\t\tmax = t1;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max+1)/2;\n\t\t\tSystem.out.println(\"? \"+l1+\" \"+mid+\" \"+r1+\" \"+t1);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmin = mid;\n\t\t\telse\n\t\t\t\tmax = mid-1;\n\t\t}\n\t\tb1 = min;\n\t\tmin = l1;\n\t\tmax = r1;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max+1)/2;\n\t\t\tSystem.out.println(\"? \"+mid+\" \"+b1+\" \"+r1+\" \"+t1);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmin = mid;\n\t\t\telse\n\t\t\t\tmax = mid-1;\n\t\t}\n\t\tl1 = min;\n\t\tint l2 = 1;\n\t\tint r2 = n;\n\t\tint b2 = 1;\n\t\tint t2 = n;\n\t\tmin = b2;\n\t\tmax = t2;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max+1)/2;\n\t\t\tSystem.out.println(\"? \"+l2+\" \"+mid+\" \"+r2+\" \"+t2);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmin = mid;\n\t\t\telse\n\t\t\t\tmax = mid-1;\n\t\t}\n\t\tb2 = min;\n\t\tmin = l2;\n\t\tmax = r2;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max+1)/2;\n\t\t\tSystem.out.println(\"? \"+mid+\" \"+b2+\" \"+r2+\" \"+t2);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmin = mid;\n\t\t\telse\n\t\t\t\tmax = mid-1;\n\t\t}\n\t\tl2 = min;\n\t\tmin = b2;\n\t\tmax = t2;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max)/2;\n\t\t\tSystem.out.println(\"? \"+l2+\" \"+b2+\" \"+r2+\" \"+mid);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmax = mid;\n\t\t\telse\n\t\t\t\tmin = mid+1;\n\t\t}\n\t\tt2 = min;\n\t\tmin = l2;\n\t\tmax = r2;\n\t\twhile (min != max) {\n\t\t\tint mid = (min+max)/2;\n\t\t\tSystem.out.println(\"? \"+l2+\" \"+b2+\" \"+mid+\" \"+t2);\n\t\t\tSystem.out.flush();\n\t\t\tif (sc.nextInt() >= 1)\n\t\t\t\tmax = mid;\n\t\t\telse\n\t\t\t\tmin = mid+1;\n\t\t}\n\t\tr2 = min;\n\t\tSystem.out.println(\"! \"+l1+\" \"+b1+\" \"+r1+\" \"+t1+\" \"+l2+\" \"+b2+\" \"+r2+\" \"+t2);\n\t\tSystem.out.flush();\n\t}\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Main {\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 String join(Collection<?> x, String space) {\n        if (x.size() == 0) return \"\";\n        StringBuilder sb = new StringBuilder();\n        boolean first = true;\n        for (Object elt : x) {\n            if (first) first = false;\n            else sb.append(space);\n            sb.append(elt);\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\n    // Finds smallest rectangle containing something along 1 dimension.\n    public static long[] search(long[] none, long[] some) throws IOException {\n        long[] med = new long[4];\n        for (int i = 0; i < 4; i++) {\n            if (Math.abs(none[i] - some[i]) == 1) {\n                return some;\n            }\n            med[i] = (none[i] + some[i]) / 2;\n        }\n\n        int ans = query(med);\n\n        if (ans > 0) return search(none, med);\n        else return search(med, some);\n    }\n\n    public static int query(long[] query) throws IOException {\n        print(\"? \" + arr(query));\n        System.out.flush();\n\n        int ans = nextInt();\n        if (contains(query)) ans -= 1;\n\n        return ans;\n    }\n\n    public static boolean contains(long[] search) {\n        if (rect1 == null) return false;\n        if (search[0] > rect1[0]) return false;\n        if (search[1] > rect1[1]) return false;\n        if (search[2] < rect1[2]) return false;\n        if (search[3] < rect1[3]) return false;\n        return true;\n    }\n\n    public static String arr(long[] x) {\n        return x[0] + \" \" + x[1] + \" \" + x[2] + \" \" + x[3];\n    }\n    public static long[] find() throws IOException {\n        long[] d0 = {1, 1, 1, 1};\n        long[] some = {1, 1, n, n};\n        if (query(d0) > 0) {\n            return d0;\n        }\n//        print(\"   \" + arr(some));\n        long[] none = {1, 1, n, 1};\n        if (query(none) > 0) some = none;\n        else some = search(none, some);\n\n//        print(\"   \" + arr(some));\n        none = new long[] {1, 1, 1, some[3]};\n        if (query(none) > 0) some = none;\n        else some = search(none, some);\n\n//        print(\"   \" + arr(some));\n        none = new long[] {1, some[3], some[2], some[3]};\n        if (query(none) > 0) some = none;\n        else some = search(none, some);\n\n//        print(\"   \" + arr(some));\n        none = new long[] {some[2], some[1], some[2], some[3]};\n        if (query(none) > 0) some = none;\n        else some = search(none, some);\n        return some;\n    }\n\n    public static long[] rect1 = null;\n    public static long[] rect2 = null;\n    public static long n;\n\n    public static void main(String[] args) throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n\n        n = nextLong();\n\n        rect1 = find();\n        rect2 = find();\n        print(\"! \" + arr(rect1) + \" \"\n                   + arr(rect2));\n        System.out.flush();\n    }\n}\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class B implements Runnable {\n\n    private static final boolean ONLINE_JUDGE = true;//System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    private BufferedReader in;\n    private PrintWriter out;\n    private StringTokenizer tok = new StringTokenizer(\"\");\n\n    private void init() throws FileNotFoundException {\n        Locale.setDefault(Locale.US);\n        String fileName = \"\";\n        if (ONLINE_JUDGE && fileName.isEmpty()) {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n        } else {\n            if (fileName.isEmpty()) {\n                in = new BufferedReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(\"output.txt\");\n            } else {\n                in = new BufferedReader(new FileReader(fileName + \".in\"));\n                out = new PrintWriter(fileName + \".out\");\n            }\n        }\n    }\n\n    String readString() {\n        while (!tok.hasMoreTokens()) {\n            try {\n                tok = new StringTokenizer(in.readLine());\n            } catch (Exception e) {\n                return null;\n            }\n        }\n        return tok.nextToken();\n    }\n\n    int readInt() {\n        return Integer.parseInt(readString());\n    }\n\n    long readLong() {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() {\n        return Double.parseDouble(readString());\n    }\n\n    int[] readIntArray(int size) {\n        int[] a = new int[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = readInt();\n        }\n        return a;\n    }\n\n    public static void main(String[] args) {\n        //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n        new B().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            int n = readInt();\n            int[] rect1 = solve1(n);\n            int[] rect2 = solve2(n, rect1);\n\n            out.printf(\"! %s %s %s %s %s %s %s %s\\n\", rect1[0], rect1[1], rect1[2], rect1[3],\n                    rect2[0], rect2[1], rect2[2], rect2[3]);\n            out.flush();\n            out.close();\n            time();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(-1);\n        }\n    }\n\n    int ask(int x1, int y1, int x2, int y2) {\n        out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n        out.flush();\n        return readInt();\n    }\n\n    int ask(int x1, int y1, int x2, int y2, int[] rect) {\n        out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n        out.flush();\n        int res = readInt();\n        if (rect[0] >= x1 && rect[2] <= x2 && rect[1] >= y1 && rect[3] <= y2) {\n            res--;\n        }\n        return res;\n    }\n\n    int[] dropTopAndLeft1(int x2, int y2) {\n        int x1 = x2, y1 = y2;\n        int left = 1, right = x2;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(mid, 1, x2, y2);\n            if (count >= 1) {\n                x1 = mid;\n                left = mid + 1;\n            }\n            if (count == 0) {\n                right = mid - 1;\n            }\n        }\n        left = 1;\n        right = y2;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(x1, mid, x2, y2);\n            if (count >= 1) {\n                y1 = mid;\n                left = mid + 1;\n            }\n            if (count == 0) {\n                right = mid - 1;\n            }\n        }\n        return new int[]{x1, y1, x2, y2};\n    }\n\n    private int[] solve1(int n) {\n\n        int x = -1;\n        int left = 1, right = n;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(1, 1, mid, n);\n            if (count >= 1) {\n                x = mid;\n                right = mid - 1;\n            }\n            if (count == 0) {\n                left = mid + 1;\n            }\n        }\n\n        left = 1;\n        right = n;\n        int y = -1;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(1, 1, x, mid);\n            if (count >= 1) {\n                y = mid;\n                right = mid - 1;\n            }\n            if (count == 0) {\n                left = mid + 1;\n            }\n        }\n\n        return dropTopAndLeft1(x, y);\n    }\n\n    private int[] solve2(int n, int[] rect) {\n\n        int x = -1;\n        int left = 1, right = n;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(mid, 1, n, n, rect);\n            if (count >= 1) {\n                x = mid;\n                left = mid + 1;\n            }\n            if (count == 0) {\n                right = mid - 1;\n            }\n        }\n\n        left = 1;\n        right = n;\n        int y = -1;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(x, mid, n, n, rect);\n            if (count >= 1) {\n                y = mid;\n                left = mid + 1;\n            }\n            if (count == 0) {\n                right = mid - 1;\n            }\n        }\n\n        return dropTopAndLeft2(x, y, n, rect);\n    }\n\n    int[] dropTopAndLeft2(int x1, int y1, int n, int[] rect) {\n        int x2 = x1, y2 = y1;\n        int left = x1, right = n;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(x1, y1, mid, n, rect);\n            if (count >= 1) {\n                x2 = mid;\n                right = mid - 1;\n            }\n            if (count == 0) {\n                left = mid + 1;\n            }\n        }\n        left = y1;\n        right = n;\n        while (left <= right) {\n            int mid = (left + right) >> 1;\n            int count = ask(x1, y1, x2, mid, rect);\n            if (count == 1) {\n                y2 = mid;\n                right = mid - 1;\n            }\n            if (count == 0) {\n                left = mid + 1;\n            }\n        }\n        return new int[]{x1, y1, x2, y2};\n    }\n}\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "\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\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\n\t\tTask task = new Task();\n\t\ttask.solve(in, out);\n\t\tout.close();\n\n\t}\n\t\n\tstatic class Rectangle {\n\t\tint x1, y1;\n\t\tint x2, y2;\n\t}\n\t\n\tstatic class Task {\n\t\t/**\n\t\t * BEFORE SUBMITTING!!!\n\t\t * MAKE SURE IT IS RIGHT!!!!!\n\t\t * LONG!!\n\t\t * Check if m,n aren't misused\n\t\t * Make sure the output format is right (YES/NO vs Yes/No, newlines vs spaces)\n\t\t * Run with n = 1 or n = 0\n\t\t * Make sure two ints aren't multiplied to get a long\n\n\t\t *\n\t\t */\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\t\n\t\t\t//ideas: procurar linha que os divide e procurar dentro desses sub-retangulos\n\t\t\t// procurar at\u00e9 ser 1\n\t\t\t\n\t\t\t//corner cases: se procurar at\u00e9 ser 1 e n\u00e3o verificar se tem 1 do outro lado posso chegar a 1,2...not good\n\t\t\t// tenho que procurar 1,1\n\t\t\t\n\t\t\tint l = 1;\n\t\t\tint r = n;\n\t\t\t\n\t\t\tint ans = 0;\n\t\t\t\n\t\t\t\n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\tif(ask(in,out,1,1,mid, n) == 0) {\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tans = mid;\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//par 1,1\n\t\t\t//FDS ISTO\n\t\t\tif(ans < n && ask(in,out,ans + 1, 1,n,n) == 1) {\n\t\t\t\tRectangle r1 = find(in,out,1,1,ans,n,n);\n\t\t\t\tRectangle r2 = find(in,out,ans + 1,1,n,n,n);\n\t\t\t\tSystem.out.printf(\"! %d %d %d %d %d %d %d %d\\n\", r1.x1, r1.y1, r1.x2, r1.y2, r2.x1, r2.y1, r2.x2, r2.y2);\n\t\t\t} else {\n\t\t\t\tl = 1;\n\t\t\t\tr = n;\n\t\t\t\t\n\t\t\t\tans = 0;\n\t\t\t\t\n\t\t\t\t\n\t\t\t\twhile(r >= l) {\n\t\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\tif(ask(in,out,1,1,n, mid) == 0) {\n\t\t\t\t\t\tl = mid + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tans = mid;\n\t\t\t\t\t\tr = mid - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tRectangle r1 = find(in,out,1,1,n,ans,n);\n\t\t\t\tRectangle r2 = find(in,out,1,ans + 1,n,n,n);\n\t\t\t\tSystem.out.printf(\"! %d %d %d %d %d %d %d %d\\n\", r1.x1, r1.y1, r1.x2, r1.y2, r2.x1, r2.y1, r2.x2, r2.y2);\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\t//HASDFDSJGHDFJKSGDFJSGJDFSGJDSFGJF\n\t\t//FKING WORK\n\t\tpublic Rectangle find(InputReader in, PrintWriter out,int x1, int y1, int x2, int y2, int n) {\n\t\t\tRectangle rec = new Rectangle();\n\t\t\t\n\t\t\tint ansx1 = x1;\n\t\t\tint ansx2 = x2;\n\t\t\tint ansy1 = y1;\n\t\t\tint ansy2 = y2;\n\n\t\t\tint l = x1;\n\t\t\tint r = x2;\n\t\t\t\n\n\t\t\t// quero o minimo v >= x2 \n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,x1,y1,mid,y2) == 1) {\n\t\t\t\t\tansx2 = mid;\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"x2 = %d\", ansx2);\n\t\t\t\n\t\t\t\n\n\t\t\tr = x2;\n\t\t\tl = x1;\n\t\t\t\n\t\t\t// quero o maximo v <= x1\n\t\t\t\n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,mid,y1,x2,y2) == 1) {\n\t\t\t\t\tansx1 = mid;\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"x1 = %d\", ansx1);\n\t\t\t\n\t\t\t\n\t\t\tl = y1;\n\t\t\tr = y2;\n\t\t\t\n\t\t\t// quero o minimo v >= y2 \n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,x1,y1,x2,mid) == 1) {\n\t\t\t\t\tansy2 = mid;\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"y2 = %d\", ansy2);\n\t\t\t\n\n\t\t\t\n\t\t\t\n\n\t\t\tr = y2;\n\t\t\tl = y1;\n\t\t\t\n\n\t\t\t// quero o maximo v <= y1\n\t\t\t\n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,x1,mid,x2,y2) == 1) {\n\t\t\t\t\tansy1 = mid;\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"y1 = %d\", ansy1);\n\t\t\t\n\n\n\t\t\t\n\t\t\trec.x1 = ansx1;\n\t\t\trec.x2 = ansx2;\n\t\t\trec.y1 = ansy1;\n\t\t\trec.y2 = ansy2;\n\n\t\t\t\n\t\t\t\n\t\t\treturn rec;\n\t\t}\n\t\t\n\t\tpublic int ask(InputReader in, PrintWriter out, int x1, int y1, int x2, int y2) {\n\t\t\tSystem.out.printf(\"? %d %d %d %d\\n\",x1,y1,x2,y2);\n\t\t\tSystem.out.flush();\n\t\t\treturn in.nextInt();\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 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\t\t\n\t\tpublic 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            try {\n                return reader.readLine();\n               \n            } catch (IOException e) {\n            }\n            return null;\n        }\n\n\n\t}\n}\n\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "\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\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\n\t\tTask task = new Task();\n\t\ttask.solve(in, out);\n\t\tout.close();\n\n\t}\n\t\n\tstatic class Rectangle {\n\t\tint x1, y1;\n\t\tint x2, y2;\n\t}\n\t\n\tstatic class Task {\n\t\t/**\n\t\t * BEFORE SUBMITTING!!!\n\t\t * MAKE SURE IT IS RIGHT!!!!!\n\t\t * LONG!!\n\t\t * Check if m,n aren't misused\n\t\t * Make sure the output format is right (YES/NO vs Yes/No, newlines vs spaces)\n\t\t * Run with n = 1 or n = 0\n\t\t * Make sure two ints aren't multiplied to get a long\n\n\t\t *\n\t\t */\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\t\n\t\t\t//ideas: procurar linha que os divide e procurar dentro desses sub-retangulos\n\t\t\t// procurar at\u00e9 ser 1\n\t\t\t\n\t\t\t//corner cases: se procurar at\u00e9 ser 1 e n\u00e3o verificar se tem 1 do outro lado posso chegar a 1,2...not good\n\t\t\t// tenho que procurar 1,1\n\t\t\t\n\t\t\tint l = 1;\n\t\t\tint r = n;\n\t\t\t\n\t\t\tint ans = 0;\n\t\t\t\n\t\t\t\n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\tif(ask(in,out,1,1,mid, n) == 0) {\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tans = mid;\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//par 1,1\n\t\t\t//FDS ISTO\n\t\t\tif(ans < n && ask(in,out,ans + 1, 1,n,n) == 1) {\n\t\t\t\tRectangle r1 = find(in,out,1,1,ans,n,n);\n\t\t\t\tRectangle r2 = find(in,out,ans + 1,1,n,n,n);\n\t\t\t\tSystem.out.printf(\"! %d %d %d %d %d %d %d %d\\n\", r1.x1, r1.y1, r1.x2, r1.y2, r2.x1, r2.y1, r2.x2, r2.y2);\n\t\t\t} else {\n\t\t\t\tl = 1;\n\t\t\t\tr = n;\n\t\t\t\t\n\t\t\t\tans = 0;\n\t\t\t\t\n\t\t\t\t\n\t\t\t\twhile(r >= l) {\n\t\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\tif(ask(in,out,1,1,n, mid) == 0) {\n\t\t\t\t\t\tl = mid + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tans = mid;\n\t\t\t\t\t\tr = mid - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tRectangle r1 = find(in,out,1,1,n,ans,n);\n\t\t\t\tRectangle r2 = find(in,out,1,ans + 1,n,n,n);\n\t\t\t\tSystem.out.printf(\"! %d %d %d %d %d %d %d %d\\n\", r1.x1, r1.y1, r1.x2, r1.y2, r2.x1, r2.y1, r2.x2, r2.y2);\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\t//HASDFDSJGHDFJKSGDFJSGJDFSGJDSFGJF\n\t\t//FKING WORK\n\t\tpublic Rectangle find(InputReader in, PrintWriter out,int x1, int y1, int x2, int y2, int n) {\n\t\t\tRectangle rec = new Rectangle();\n\t\t\t\n\t\t\tint ansx1 = x1;\n\t\t\tint ansx2 = x2;\n\t\t\tint ansy1 = y1;\n\t\t\tint ansy2 = y2;\n\n\t\t\tint l = x1;\n\t\t\tint r = x2;\n\t\t\t\n\n\t\t\t// quero o minimo v >= x2 \n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,x1,y1,mid,y2) == 1) {\n\t\t\t\t\tansx2 = mid;\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"x2 = %d\", ansx2);\n\t\t\t\n\t\t\t\n\n\t\t\tr = x2;\n\t\t\tl = x1;\n\t\t\t\n\t\t\t// quero o maximo v <= x1\n\t\t\t\n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,mid,y1,x2,y2) == 1) {\n\t\t\t\t\tansx1 = mid;\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"x1 = %d\", ansx1);\n\t\t\t\n\t\t\t\n\t\t\tl = y1;\n\t\t\tr = y2;\n\t\t\t\n\t\t\t// quero o minimo v >= y2 \n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,x1,y1,x2,mid) == 1) {\n\t\t\t\t\tansy2 = mid;\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"y2 = %d\", ansy2);\n\t\t\t\n\n\t\t\t\n\t\t\t\n\n\t\t\tr = y2;\n\t\t\tl = y1;\n\t\t\t\n\n\t\t\t// quero o maximo v <= y1\n\t\t\t\n\t\t\twhile(r >= l) {\n\t\t\t\tint mid = (r + l) / 2;\n\t\t\t\t\n\t\t\t\tif(ask(in,out,x1,mid,x2,y2) == 1) {\n\t\t\t\t\tansy1 = mid;\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tr = mid - 1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t//out.printf(\"y1 = %d\", ansy1);\n\t\t\t\n\n\n\t\t\t\n\t\t\trec.x1 = ansx1;\n\t\t\trec.x2 = ansx2;\n\t\t\trec.y1 = ansy1;\n\t\t\trec.y2 = ansy2;\n\n\t\t\t\n\t\t\t\n\t\t\treturn rec;\n\t\t}\n\t\t\n\t\tpublic int ask(InputReader in, PrintWriter out, int x1, int y1, int x2, int y2) {\n\t\t\tSystem.out.printf(\"? %d %d %d %d\\n\",x1,y1,x2,y2);\n\t\t\tSystem.out.flush();\n\t\t\treturn in.nextInt();\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 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\t\t\n\t\tpublic 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            try {\n                return reader.readLine();\n               \n            } catch (IOException e) {\n            }\n            return null;\n        }\n\n\n\t}\n}\n\n     \t\t   \t \t \t\t\t  \t  \t\t\t   \t\t\t", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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//\tint X1, Y1, X2, Y2;\n//\tint X3, Y3, X4, Y4;\n//\t{\n//\t\tX1 = 1;\n//\t\tY1 = 2;\n//\t\tX2 = 3;\n//\t\tY2 = 4;\n//\t\t\n//\t\tX3 = 5;\n//\t\tY3 = 1;\n//\t\tX4 = 5;\n//\t\tY4 = 5;\n//\t}\n\n\tint ask(int x1, int y1, int x2, int y2) throws IOException {\n\t\tout.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n\t\tout.flush();\n\t\treturn nextInt();\n\t}\n\t\n\tint inside(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {\n\t\treturn inside(x1, x2, x3, x4) & inside(y1, y2, y3, y4);\n\t}\n\t\n\tint inside(int x1, int x2, int y1, int y2) {\n\t\treturn (x1 <= y1 && y2 <= x2) ? 1 : 0;\n\t}\n\t\n//\tint ask(int x1, int y1, int x2, int y2) throws IOException {\n//\t\treturn inside(x1, y1, x2, y2, X1, Y1, X2, Y2) + inside(x1, y1, x2, y2, X3, Y3, X4, Y4); \n//\t}\n\n\tint askFlipped(int x1, int y1, int x2, int y2) throws IOException {\n\t\treturn ask(y1, x1, y2, x2);\n\t}\n\t\n\tboolean check(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) throws IOException {\n\t\tif (x1 > x2 || y1 > y2 || x3 > x4 || y3 > y4) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (Math.max(x1, x3) <= Math.min(x2, x4) && Math.max(y1, y3) <= Math.min(y2, y4)) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn check(x1, y1, x2, y2) && check(x3, y3, x4, y4);\n\t}\n\t\n\tboolean check(int x1, int y1, int x2, int y2) throws IOException {\n\t\tif (ask(x1, y1, x2, y2) != 1) {\n\t\t\treturn false;\n\t\t}\n\t\tif (x1 != x2) {\n\t\t\tif (ask(x1 + 1, y1, x2, y2) != 0 || ask(x1, y1, x2 - 1, y2) != 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (y1 != y2) {\n\t\t\tif (ask(x1, y1 + 1, x2, y2) != 0 || ask(x1, y1, x2, y2 - 1) != 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\n\t\tint low = 0; // 0\n\t\tint high = n; // >0\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = ask(1, 1, mid, n);\n\t\t\tif (ret == 0) {\n\t\t\t\tlow = mid;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\n\t\tint minX2 = high;\n\n\t\tlow = 0; // <2\n\t\thigh = n; // 2\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = ask(1, 1, mid, n);\n\t\t\tif (ret == 2) {\n\t\t\t\thigh = mid;\n\t\t\t} else {\n\t\t\t\tlow = mid;\n\t\t\t}\n\t\t}\n\n\t\tint maxX2 = high;\n\n\t\tlow = 1; // >0\n\t\thigh = n + 1; // 0\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = ask(mid, 1, n, n);\n\t\t\tif (ret == 0) {\n\t\t\t\thigh = mid;\n\t\t\t} else {\n\t\t\t\tlow = mid;\n\t\t\t}\n\t\t}\n\n\t\tint maxX1 = low;\n\n\t\tlow = 1; // 2\n\t\thigh = n + 1; // <2\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = ask(mid, 1, n, n);\n\t\t\tif (ret == 2) {\n\t\t\t\tlow = mid;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\tint minX1 = low;\n\n\t\t// / NOW Y\n\n\t\tlow = 0; // 0\n\t\thigh = n; // >0\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = askFlipped(1, 1, mid, n);\n\t\t\tif (ret == 0) {\n\t\t\t\tlow = mid;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\n\t\tint minY2 = high;\n\n\t\tlow = 0; // <2\n\t\thigh = n; // 2\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = askFlipped(1, 1, mid, n);\n\t\t\tif (ret == 2) {\n\t\t\t\thigh = mid;\n\t\t\t} else {\n\t\t\t\tlow = mid;\n\t\t\t}\n\t\t}\n\n\t\tint maxY2 = high;\n\n\t\tlow = 1; // >0\n\t\thigh = n + 1; // 0\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = askFlipped(mid, 1, n, n);\n\t\t\tif (ret == 0) {\n\t\t\t\thigh = mid;\n\t\t\t} else {\n\t\t\t\tlow = mid;\n\t\t\t}\n\t\t}\n\n\t\tint maxY1 = low;\n\n\t\tlow = 1; // 2\n\t\thigh = n + 1; // <2\n\t\twhile (high - low > 1) {\n\t\t\tint mid = (low + high) >> 1;\n\t\t\tint ret = askFlipped(mid, 1, n, n);\n\t\t\tif (ret == 2) {\n\t\t\t\tlow = mid;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\tint minY1 = low;\n\n\t\tint[] x1s = { minX1, maxX1 };\n\t\tint[] x2s = { minX2, maxX2 };\n\t\tint[] y1s = { minY1, maxY1 };\n\t\tint[] y2s = { minY2, maxY2 };\n\t\t\n\t\tfor (int mask = 0; mask < 8; mask++) {\n\t\t\tint x1 = x1s[0];\n\t\t\tint x3 = x1s[1];\n\t\t\t\n\t\t\tint x2 = x2s[get(mask, 0)];\n\t\t\tint x4 = x2s[get(mask, 0) ^ 1];\n\t\t\t\n\t\t\tint y1 = y1s[get(mask, 1)];\n\t\t\tint y3 = y1s[get(mask, 1) ^ 1];\n\t\t\t\n\t\t\tint y2 = y2s[get(mask, 2)];\n\t\t\tint y4 = y2s[get(mask, 2) ^ 1];\n\t\t\t\n\t\t\tif (check(x1, y1, x2, y2, x3, y3, x4, y4)) {\n\t\t\t\tout.printf(\"! %d %d %d %d %d %d %d %d\\n\", x1, y1, x2, y2, x3, y3, x4, y4);\n\t\t\t\tout.flush();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint get(int mask, int i) {\n\t\treturn (mask >> i) & 1;\n\t}\n\n\tB() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew B();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic int mod = (int) 1e9 + 7;\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tFasterScanner s = new FasterScanner();\n\t\tint test = 1;\n\t\ttestloop: while (test-- > 0) {\n\t\t\tint n = s.nextInt();\n\t\t\tint left = 1;\n\t\t\tint right = n;\n\t\t\tint x[][] = new int[2][2];\n\t\t\tint y[][] = new int[2][2];\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right) / 2;\n\t\t\t\tquery(1, mid, 1, n);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 2) {\n\t\t\t\t\tleft = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tright = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tx[0][0] = left;\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right) / 2;\n\t\t\t\tquery(1, mid, 1, n);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 1) {\n\t\t\t\t\tleft = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tright = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tx[0][1] = left;\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right + 1) / 2;\n\t\t\t\tquery(mid, n, 1, n);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 2) {\n\t\t\t\t\tright = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tleft = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tx[1][0] = left;\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right + 1) / 2;\n\t\t\t\tquery(mid, n, 1, n);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 1) {\n\t\t\t\t\tright = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tleft = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tx[1][1] = left;\n\t\t\t// System.out.println(Arrays.deepToString(x));\n\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right) / 2;\n\t\t\t\tquery(1, n, 1, mid);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 2) {\n\t\t\t\t\tleft = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tright = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\ty[0][0] = left;\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right) / 2;\n\t\t\t\tquery(1, n, 1, mid);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 1) {\n\t\t\t\t\tleft = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tright = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\ty[0][1] = left;\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right + 1) / 2;\n\t\t\t\tquery(1, n, mid, n);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 2) {\n\t\t\t\t\tright = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tleft = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\ty[1][0] = left;\n\t\t\tleft = 1;\n\t\t\tright = n;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right + 1) / 2;\n\t\t\t\tquery(1, n, mid, n);\n\t\t\t\tint ans = s.nextInt();\n\t\t\t\tif (ans < 1) {\n\t\t\t\t\tright = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tleft = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\ty[1][1] = left;\n//\t\t\tSystem.out.println(Arrays.deepToString(x));\n//\t\t\tSystem.out.println(Arrays.deepToString(y));\n\t\t\t\n\t\t\tint x11 = 0, x12 = 0, y11 = 0, y12 = 0;\n\t\t\tint x21 = 0, x22 = 0, y21 = 0, y22 = 0;\n\t\t\tfor (int x1 = 0; x1 < 2; x1++) {\n\t\t\t\tx11 = x[1][x1];\n\t\t\t\tx21 = x[1][1 - x1];\n\t\t\t\tfor (int x2 = 0; x2 < 2; x2++) {\n\t\t\t\t\tx12 = x[0][x2];\n\t\t\t\t\tx22 = x[0][1 - x2];\n\t\t\t\t\tif (x11 > x12)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif (x21 > x22)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int y1 = 0; y1 < 2; y1++) {\n\t\t\t\t\t\ty11 = y[1][y1];\n\t\t\t\t\t\ty21 = y[1][1 - y1];\n\t\t\t\t\t\tfor (int y2 = 0; y2 < 2; y2++) {\n\t\t\t\t\t\t\ty12 = y[0][y2];\n\t\t\t\t\t\t\ty22 = y[0][1 - y2];\n\t\t\t\t\t\t\tif (y11 > y12)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tif (y21 > y22)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tquery(x11, x12, y11, y12);\n\t\t\t\t\t\t\tint ans1 = s.nextInt();\n\n\t\t\t\t\t\t\tquery(x21, x22, y21, y22);\n\t\t\t\t\t\t\tint ans2 = s.nextInt();\n\t\t\t\t\t\t\tif (ans1 == 1 && ans2 == 1) {\n\t\t\t\t\t\t\t\tSystem.out.println(\"! \" + x11 + \" \" + y11 + \" \" + x12 + \" \" + y12 + \" \" + x21 + \" \"\n\t\t\t\t\t\t\t\t\t\t+ y21 + \" \" + x22 + \" \" + y22);\n\t\t\t\t\t\t\t\tSystem.out.flush();\n\t\t\t\t\t\t\t\tbreak testloop;\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}\n\t}\n\n\tpublic static void query(int x1, int x2, int y1, int y2) {\n\t\t System.out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n\t\t System.out.flush();\n//\t\tint count = 0;\n//\t\tif (x1 <= 2 && y1 <= 2 && x2 >= 2 && y2 >= 2)\n//\t\t\tcount++;\n//\n//\t\tif (x1 <= 3 && y1 <= 4 && x2 >= 3 && y2 >= 5)\n//\t\t\tcount++;\n//\t\tSystem.out.println(count);\n\t}\n\n\tpublic static void set(int[] t, int i, int value) {\n\t\ti += t.length / 2;\n\t\tt[i] = value;\n\t\tfor (; i > 1; i >>= 1)\n\t\t\tt[i >> 1] = Math.max(t[i], t[i ^ 1]);\n\t}\n\n\t// max[a, b]\n\tpublic static int max(int[] t, int a, int b) {\n\t\tint res = 0;\n\t\tfor (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {\n\t\t\tif ((a & 1) != 0)\n\t\t\t\tres = Math.max(res, t[a]);\n\t\t\tif ((b & 1) == 0)\n\t\t\t\tres = Math.max(res, t[b]);\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static int[] generateDivisorTable(int n) {\n\t\tint[] divisor = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tdivisor[i] = i;\n\t\tfor (int i = 2; i * i <= n; i++)\n\t\t\tif (divisor[i] == i)\n\t\t\t\tfor (int j = i * i; j <= n; j += i)\n\t\t\t\t\tif (divisor[j] == j)\n\t\t\t\t\t\tdivisor[j] = i;\n\t\treturn divisor;\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\tstatic 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 FasterScanner {\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int snumChars;\n\n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = System.in.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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    int n;\n\n    private void solve() {\n        this.query = 0;\n\n        this.n = readInt();\n\n        int left1 = 0;\n\n        int l = 1, r = n;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(m, 1, n, n);\n\n            if (answer < 2) {\n                r = m - 1;\n            } else {\n                left1 = m;\n                l = m + 1;\n            }\n        }\n\n        int left2 = left1;\n\n        l = left1 + 1;\n        r = n;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(m, 1, n, n);\n\n            if (answer < 1) {\n                r = m - 1;\n            } else {\n                left2 = m;\n                l = m + 1;\n            }\n        }\n\n        int right2 = n + 1;\n\n        l = 1;\n        r = n;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(1, 1, m, n);\n\n            if (answer < 2) {\n                l = m + 1;\n            } else {\n                right2 = m;\n                r = m - 1;\n            }\n        }\n\n        int right1 = right2;\n\n        l = 1;\n        r = right2 - 1;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(1, 1, m, n);\n\n            if (answer < 1) {\n                l = m + 1;\n            } else {\n                right1 = m;\n                r = m - 1;\n            }\n        }\n\n        int bottom1 = 0;\n\n        l = 1;\n        r = n;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(1, m, n, n);\n\n            if (answer < 2) {\n                r = m - 1;\n            } else {\n                bottom1 = m;\n                l = m + 1;\n            }\n        }\n\n        int bottom2 = bottom1;\n\n        l = bottom1 + 1;\n        r = n;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(1, m, n, n);\n\n            if (answer < 1) {\n                r = m - 1;\n            } else {\n                bottom2 = m;\n                l = m + 1;\n            }\n        }\n\n        int top2 = n + 1;\n\n        l = 1;\n        r = n;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(1, 1, n, m);\n\n            if (answer < 2) {\n                l = m + 1;\n            } else {\n                top2 = m;\n                r = m - 1;\n            }\n        }\n\n        int top1 = top2;\n\n        l = 1;\n        r = top2 - 1;\n        while (l <= r) {\n            int m = (l + r) / 2;\n            int answer = getAnswer(1, 1, n, m);\n\n            if (answer < 1) {\n                l = m + 1;\n            } else {\n                top1 = m;\n                r = m - 1;\n            }\n        }\n\n        int ansLeftRightMask = -1, ansBottomTopMask = -1;\n        long answerS = 2L * n * n;\n\n        for (int leftRightMask = 0; leftRightMask < 4; ++leftRightMask) {\n            int left = (checkBit(leftRightMask, 0) ? left1 : left2);\n            int right = (checkBit(leftRightMask, 1) ? right1 : right2);\n\n            for (int bottomTopMask = 0; bottomTopMask < 4; ++bottomTopMask) {\n                int bottom = (checkBit(bottomTopMask, 0) ? bottom1 : bottom2);\n                int top = (checkBit(bottomTopMask, 1) ? top1 : top2);\n\n                int curTry = getAnswer(left, bottom, right, top);\n                if (curTry == 1) {\n                    long s = (right - left + 1L) * (top - bottom + 1L);\n                    if (s < answerS) {\n                        answerS = s;\n                        ansLeftRightMask = leftRightMask;\n                        ansBottomTopMask = bottomTopMask;\n                    }\n                }\n            }\n        }\n\n        int left = (checkBit(ansLeftRightMask, 0) ? left1 : left2);\n        int right = (checkBit(ansLeftRightMask, 1) ? right1 : right2);\n        int bottom = (checkBit(ansBottomTopMask, 0) ? bottom1 : bottom2);\n        int top = (checkBit(ansBottomTopMask, 1) ? top1 : top2);\n\n        printAnswer(left, bottom, right, top,\n                left1 + left2 - left, bottom1 + bottom2 - bottom,\n                right1 + right2 - right, top1 + top2 - top);\n    }\n\n    private void printAnswer(int... values) {\n        printQuery(\"!\", values);\n    }\n\n    private void printQuery(String sign, int... values) {\n        out.print(sign);\n        for (int value : values) {\n            out.print(\" \" + value);\n        }\n        out.println();\n        out.flush();\n    }\n\n    int query = 0;\n    final int MAX_QUERY = 200;\n\n    private int getAnswer(int left, int bottom, int right, int top) {\n        if (left < 1 || right > n) {\n            while (true);\n        }\n\n        if (bottom < 1 || top > n) {\n            throw new RuntimeException();\n        }\n\n        if (left > right || bottom > top) {\n            return 0;\n        }\n\n        if (query == MAX_QUERY) {\n            throw new RuntimeException();\n        }\n\n        ++query;\n\n        printQuery(\"?\",  left, bottom, right, top);\n\n        int answer = readInt();\n        return answer;\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private final static boolean FIRST_INPUT_STRING = false;\n    private final static boolean MULTIPLE_TESTS = true;\n    private final static boolean INTERACTIVE = 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 (INTERACTIVE || 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<Integer>[] readGraph(int vertexNumber, int edgeNumber) {\n        @SuppressWarnings(\"unchecked\")\n        List<Integer>[] graph = new List[vertexNumber];\n\n        for (int index = 0; index < vertexNumber; ++index){\n            graph[index] = new ArrayList<Integer>();\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<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {\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<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {\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<KeyType> extends HashMap<KeyType, Integer> {\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", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    String readString() throws IOException {\n        while (!tok.hasMoreTokens()) {\n            try {\n                tok = new StringTokenizer(in.readLine(), \" :\");\n            } catch (Exception e) {\n                return null;\n            }\n        }\n        return tok.nextToken();\n    }\n\n    int readInt() throws IOException {\n        return Integer.parseInt(readString());\n    }\n\n    int[] readIntArray(int size) throws IOException {\n        int[] res = new int[size];\n        for (int i = 0; i < size; i++) {\n            res[i] = readInt();\n        }\n        return res;\n    }\n\n    long readLong() throws IOException {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() throws IOException {\n        return Double.parseDouble(readString());\n    }\n\n    <T> List<T>[] createGraphList(int size) {\n        List<T>[] list = new List[size];\n        for (int i = 0; i < size; i++) {\n            list[i] = new ArrayList<>();\n        }\n        return list;\n    }\n\n    public static void main(String[] args) {\n        new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n    }\n\n    long timeBegin, timeEnd;\n\n    void time() {\n        timeEnd = System.currentTimeMillis();\n        System.err.println(\"Time = \" + (timeEnd - timeBegin));\n    }\n\n    long memoryTotal, memoryFree;\n\n    void memory() {\n        memoryFree = Runtime.getRuntime().freeMemory();\n        System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n                + \" KB\");\n    }\n\n    public void run() {\n        try {\n            timeBegin = System.currentTimeMillis();\n            memoryTotal = Runtime.getRuntime().freeMemory();\n            init();\n            solve();\n            out.close();\n            if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n                time();\n                memory();\n            }\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(-1);\n        }\n    }\n\n    int fx = -1;\n    int sx = -1;\n    int fy = -1;\n    int sy = -1;\n\n    int query(int x1, int y1, int x2, int y2) throws IOException {\n        out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n        out.flush();\n        int res = readInt();\n        if (fx >= x1 && sx <= x2 && fy >= y1 && sy <= y2) res--;\n        return res;\n    }\n\n    int[] bs(int n) throws IOException {\n        int l = 1;\n        int r = n;\n\n        int lx = 0, rx = 0, ly = 0, ry = 0;\n        while (l <= r) {\n            int mid = (l + r) >> 1;\n            if (query(1, 1, mid, n) > 0) {\n                rx = mid;\n                r = mid - 1;\n            } else {\n                l = mid + 1;\n            }\n        }\n\n        l = 1;\n        r = rx;\n        while (l <= r) {\n            int mid = (l + r) >> 1;\n            if (query(mid, 1, rx, n) > 0) {\n                lx = mid;\n                l = mid + 1;\n            } else {\n                r = mid - 1;\n            }\n        }\n\n        l = 1;\n        r = n;\n        while (l <= r) {\n            int mid = (l + r) >> 1;\n            if (query(lx, mid, rx, n) > 0) {\n                ly = mid;\n                l = mid + 1;\n            } else {\n                r = mid - 1;\n            }\n        }\n\n        l = ly;\n        r = n;\n        while (l <= r) {\n            int mid = (l + r) >> 1;\n            if (query(lx, ly, rx, mid) > 0) {\n                ry = mid;\n                r = mid - 1;\n            } else {\n                l = mid + 1;\n            }\n        }\n        fx = lx;\n        sx = rx;\n        fy = ly;\n        sy = ry;\n        return new int[] {lx, ly, rx, ry};\n    }\n\n    void solve() throws IOException {\n        int n = readInt();\n        int[] a = bs(n);\n        int[] b = bs(n);\n\n        out.print(\"! \");\n        for (int i : a) out.print(i + \" \");\n        for (int i : b) out.print(i + \" \");\n    }\n\n\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class B {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner qwe = new Scanner(System.in);\n\t\t\n\t\tint n = qwe.nextInt();\n\t\t\n\t\t//! x11 y11 x12 y12 x21 y21 x22 y22\" \n\t\t\n\t\t\n\t\t\n\t\tint x11 = bins(true,1,2,n,qwe,true);\n\t\tint y11 = bins(true,1,2,n,qwe,false);\n\t\tint x12 = bins(false,0,1,n,qwe,true);\n\t\tint y12 = bins(false,0,1,n,qwe,false);\n\t\tint x21 = bins(true,0,1,n,qwe,true);\n\t\tint y21 = bins(true,0,1,n,qwe,false);\n\t\tint x22 = bins(false,1,2,n,qwe,true);\n\t\tint y22 = bins(false,1,2,n,qwe,false);\n\t\t\n\t\tint[] xsl = {x11,x21};\n\t\tint[] xsr = {x12,x22};\n\t\tint[] ysl = {y11,y21};\n\t\tint[] ysr = {y12,y22};\n\t\t\n\t\t\n\t\tint[] ans = new int[8];\n\t\t\n\t\tfor(int xpl = 0; xpl < 2; xpl++){\n\t\t\tfor(int xpr = 0; xpr < 2; xpr++)\n\t\t\t\tfor(int ypl = 0; ypl < 2; ypl++){\n\t\t\t\t\tfor(int ypr = 0; ypr < 2; ypr++){\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(xsl[xpl] <= xsr[xpr] && xsl[1-xpl] <= xsr[1-xpr] && ysl[ypl] <= ysr[ypr] && ysl[1-ypl] <= ysr[1-ypr]){\n\t\t\t\t\t\t\tSystem.out.printf(\"? %d %d %d %d\",xsl[xpl],ysl[ypl],xsr[xpr],ysr[ypr]);\n\t\t\t\t\t\t\tSystem.out.println();\n\t\t\t\t\t\t\tSystem.out.flush();\n\t\t\t\t\t\t\tint response1 = qwe.nextInt();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tSystem.out.printf(\"? %d %d %d %d\",xsl[1-xpl],ysl[1-ypl],xsr[1-xpr],ysr[1-ypr]);\n\t\t\t\t\t\t\tSystem.out.println();\n\t\t\t\t\t\t\tSystem.out.flush();\n\t\t\t\t\t\t\tint response2 = qwe.nextInt();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif(response1 == 1 && response2 == 1){\n\t\t\t\t\t\t\t\tans = new int[]{xsl[xpl],ysl[ypl],xsr[xpr],ysr[ypr],xsl[1-xpl],ysl[1-ypl],xsr[1-xpr],ysr[1-ypr]};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tSystem.out.printf(\"! %d %d %d %d %d %d %d %d\",ans[0],ans[1],ans[2],ans[3],ans[4],ans[5],ans[6],ans[7]);\n\t\tSystem.out.println();\n\t\tSystem.out.flush();\n\t\t\n\t\tqwe.close();\n\t}\n\t\n\tstatic int bins(boolean leftbound, int small, int big, int n, Scanner qwe, boolean isx){\n\t\t\n\t\tint min = 0;\n\t\tint max = n;\n\t\t\n\t\tif(leftbound){\n\t\t\tmin++;\n\t\t\tmax++;\n\t\t}\n\t\t\n\t\tint y1 = 1;\n\t\tint y2 = n;\n\t\tint x1 = 1;\n\t\tint x2 = n;\n\t\t//\"? x1 y1 x2 y2\"\n\t\twhile(min+1 < max){\n\t\t\t\n\t\t\tint med = (min+max)/2;\n\t\t\tif(isx){\n\t\t\t\tif(!leftbound) x2 = med;\n\t\t\t\telse x1 = med;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(!leftbound) y2 = med;\n\t\t\t\telse y1 = med;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.printf(\"? %d %d %d %d\",x1,y1,x2,y2);\n\t\t\tSystem.out.println();\n\t\t\tSystem.out.flush();\n\t\t\t\n\t\t\tint response = qwe.nextInt();\n\t\t\tif(leftbound){\n\t\t\t\tif(response >= big) min = med;\n\t\t\t\telse max= med;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(response < big){\n\t\t\t\t\tmin = med;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tmax = med;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(leftbound) max--;\n\t\t\n\t\treturn max;\n\t\t\n\t}\n\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.function.IntPredicate;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    static final String FILE = \"\";\n\n    public static final int TEST = 0;\n\n    class Interact {\n        Rect a, b;\n\n        public Interact(int x11, int y11, int x12, int y12, int x21, int y21, int x22, int y22) {\n            a = new Rect(x11, y11, x12, y12);\n            b = new Rect(x21, y21, x22, y22);\n        }\n\n        int query(int x1, int y1, int x2, int y2) {\n            int ans = 0;\n            if (x1 <= a.x1 && x2 >= a.x2 && y1 <= a.y1 && y2 >= a.y2)\n                ans++;\n            if (x1 <= b.x1 && x2 >= b.x2 && y1 <= b.y1 && y2 >= b.y2)\n                ans++;\n            return ans;\n        }\n    }\n    Interact interact;\n\n    class Rect {\n        int x1, y1, x2, y2;\n\n        public Rect() {\n        }\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    int calls;\n\n    int query(int x1, int y1, int x2, int y2, Rect rect) {\n        calls++;\n        if (calls >= 190)\n            throw new RuntimeException();\n\n        if (TEST == 0) {\n            out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n            out.flush();\n            int ans = in.nextInt();\n            if (x1 <= rect.x1 && x2 >= rect.x2 && y1 <= rect.y1 && y2 >= rect.y2)\n                ans--;\n            return ans;\n        } else {\n            int ans = interact.query(x1, y1, x2, y2);\n            if (x1 <= rect.x1 && x2 >= rect.x2 && y1 <= rect.y1 && y2 >= rect.y2)\n                ans--;\n            return ans;\n        }\n    }\n\n    static int binarySearchFirstTrue(IntPredicate predicate, int fromInclusive, int toInclusive) {\n        int a = fromInclusive, b = toInclusive;\n        while (a != b) {\n            int la = a, lb = b;\n            int mid = (a + b) / 2;\n            if (predicate.test(mid))\n                b = mid;\n            else\n                a = mid;\n            if (la == a && lb == b) {\n                if (predicate.test(a))\n                    b = a;\n                else\n                    a = b;\n            }\n        }\n        return a;\n    }\n\n    static int binarySearchLastTrue(IntPredicate predicate, int fromInclusive, int toInclusive) {\n        int a = fromInclusive, b = toInclusive;\n        while (a != b) {\n            int la = a, lb = b;\n            int mid = (a + b) / 2;\n            if (predicate.test(mid))\n                a = mid;\n            else\n                b = mid;\n            if (la == a && lb == b) {\n                if (predicate.test(b))\n                    a = b;\n                else\n                    b = a;\n            }\n        }\n        return a;\n    }\n\n    static Rect rect;\n\n    void test() {\n        Random random = new Random(13);\n        for (int test = 0; test < 1000; test++) {\n\n        }\n    }\n\n    void solve() {\n        rect = new Rect();\n\n        if (TEST == 0) {\n            int n = in.nextInt();\n            List<Rect> list = new ArrayList<>();\n            for (int r = 0; r < 2; r++) {\n                int x2 = binarySearchFirstTrue(i -> query(1, 1, i, n, rect) >= 1, 1, n);\n                int x1 = binarySearchLastTrue(i -> query(i, 1, x2, n, rect) >= 1, 1, x2);\n                int y2 = binarySearchFirstTrue(i -> query(x1, 1, x2, i, rect) >= 1, 1, n);\n                int y1 = binarySearchLastTrue(i -> query(x1, i, x2, y2, rect) >= 1, 1, y2);\n                rect = new Rect(x1, y1, x2, y2);\n                list.add(rect);\n            }\n            out.println(\"! \" + list.get(0) + \" \" + list.get(1));\n            out.flush();\n        } else {\n            int n = in.nextInt();\n            int x11 = in.nextInt(), y11 = in.nextInt(), x12 = in.nextInt(), y12 = in.nextInt();\n            int x21 = in.nextInt(), y21 = in.nextInt(), x22 = in.nextInt(), y22 = in.nextInt();\n            interact = new Interact(x11, y11, x12, y12, x21, y21, x22, y22);\n            List<Rect> list = new ArrayList<>();\n            for (int r = 0; r < 2; r++) {\n                int x2 = binarySearchFirstTrue(i -> query(1, 1, i, n, rect) >= 1, 1, n);\n                int x1 = binarySearchLastTrue(i -> query(i, 1, x2, n, rect) >= 1, 1, x2);\n                int y2 = binarySearchFirstTrue(i -> query(x1, 1, x2, i, rect) >= 1, 1, n);\n                int y1 = binarySearchLastTrue(i -> query(x1, i, x2, y2, rect) >= 1, 1, y2);\n                rect = new Rect(x1, y1, x2, y2);\n                list.add(rect);\n            }\n            out.println(\"! \" + list.get(0) + \" \" + list.get(1));\n            out.flush();\n        }\n    }\n\n    public void run() {\n        if (FILE.equals(\"\")) {\n            in = new FastScanner(System.in);\n            out = new PrintWriter(System.out);\n        } else {\n            try {\n                in = new FastScanner(new FileInputStream(FILE +\n                        \".in\"));\n                out = new PrintWriter(new FileOutputStream(FILE +\n                        \".out\"));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n        solve();\n        out.close();\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        public FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public String nextLine() {\n            st = null;\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n                return null;\n            }\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public float nextFloat() {\n            return Float.parseFloat(next());\n        }\n    }\n\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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.io.BufferedWriter;\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    TaskB solver = new TaskB();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class TaskB {\n    static boolean LOCAL = false;\n    static int TEST_CASE = 10000;\n    QuickScanner in;\n    QuickWriter out;\n    int n;\n    Server server;\n\n    public void solve(int testNumber, QuickScanner in, QuickWriter out) {\n      this.in = in;\n      this.out = out;\n      n = LOCAL ? 1 << 16 : in.nextInt();\n      server = new Server();\n      for (int remCases = LOCAL ? TEST_CASE : 1; remCases > 0; --remCases) {\n        server.init(n);\n        Rect[] rects = split(0);\n        if (rects == null) {\n          rects = split(1);\n        }\n        rects[0] = shrink(rects[0]);\n        rects[1] = shrink(rects[1]);\n        server.answer(rects[0], rects[1]);\n      }\n    }\n\n    Rect[] split(int dim) {\n      int lower = 1, upper = n - 1, res = 0;\n      Rect fullRect = new Rect(1, 1, n, n);\n      while (lower <= upper) {\n        int medium = (lower + upper) >> 1;\n        if (server.ask(fullRect.update(1, dim, medium)) == 0) {\n          res = medium;\n          lower = medium + 1;\n        } else {\n          upper = medium - 1;\n        }\n      }\n      Rect[] rects = new Rect[]{\n          fullRect.update(1, dim, res + 1),\n          fullRect.update(0, dim, res + 2)};\n      return server.ask(rects[0]) == 1\n          && server.ask(rects[1]) == 1\n          ? rects : null;\n    }\n\n    Rect shrink(Rect rect) {\n      rect = shrink(rect, 0);\n      rect = shrink(rect, 1);\n      return rect;\n    }\n\n    Rect shrink(Rect rect, int dim) {\n      int lower, upper, res;\n      // lower\n      lower = rect.getValue(0, dim) + 1;\n      upper = rect.getValue(1, dim);\n      res = lower - 1;\n      while (lower <= upper) {\n        int medium = (lower + upper) >> 1;\n        if (server.ask(rect.update(0, dim, medium)) == 1) {\n          res = medium;\n          lower = medium + 1;\n        } else {\n          upper = medium - 1;\n        }\n      }\n      rect = rect.update(0, dim, res);\n      // upper\n      lower = rect.getValue(0, dim);\n      upper = rect.getValue(1, dim) - 1;\n      res = upper + 1;\n      while (lower <= upper) {\n        int medium = (lower + upper) >> 1;\n        if (server.ask(rect.update(1, dim, medium)) == 1) {\n          res = medium;\n          upper = medium - 1;\n        } else {\n          lower = medium + 1;\n        }\n      }\n      return rect.update(1, dim, res);\n    }\n\n    class Server {\n      Rect rect1;\n      Rect rect2;\n\n      Server() {\n        rect1 = new Rect();\n        rect2 = new Rect();\n      }\n\n      void init(int n) {\n        if (LOCAL) {\n          do {\n            rect1.initRandom(n);\n            rect2.initRandom(n);\n          } while (!rect1.valid(rect2));\n          //rect1 = new Rect(2, 2, 2, 2);\n          //rect2 = new Rect(3, 4, 3, 5);\n        }\n      }\n\n      int ask(Rect rect) {\n        out.print(\"? \");\n        rect.print();\n        out.println();\n        out.flush();\n        if (LOCAL) {\n          return (rect1.in(rect) ? 1 : 0)\n              + (rect2.in(rect) ? 1 : 0);\n        } else {\n          return in.nextInt();\n        }\n      }\n\n      void answer(Rect rect1, Rect rect2) {\n        out.print(\"! \");\n        rect1.print();\n        out.print(' ');\n        rect2.print();\n        out.println();\n        out.flush();\n        if (LOCAL) {\n          if ((rect1.equals(this.rect1) && rect2.equals(this.rect2))\n              || (rect2.equals(this.rect1) && rect1.equals(this.rect2))) {\n            System.out.println(\"AC!\");\n          } else {\n            System.out.println(\"WA!\");\n            throw new IllegalArgumentException();\n          }\n        }\n      }\n\n    }\n\n    class Rect {\n      final Random random = new Random();\n      int x1;\n      int y1;\n      int x2;\n      int y2;\n\n      Rect() {\n      }\n\n      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      void initRandom(int n) {\n        x1 = random.nextInt(n);\n        x2 = random.nextInt(n - x1) + x1 + 1;\n        ++x1;\n        y1 = random.nextInt(n);\n        y2 = random.nextInt(n - y1) + y1 + 1;\n        ++y1;\n      }\n\n      int getValue(int idx1, int idx2) {\n        switch ((idx1 << 1) | idx2) {\n          case 0:\n            return x1;\n          case 1:\n            return y1;\n          case 2:\n            return x2;\n          case 3:\n            return y2;\n        }\n        throw new IllegalArgumentException();\n      }\n\n      Rect update(int idx1, int idx2, int value) {\n        switch ((idx1 << 1) | idx2) {\n          case 0:\n            return new Rect(value, y1, x2, y2);\n          case 1:\n            return new Rect(x1, value, x2, y2);\n          case 2:\n            return new Rect(x1, y1, value, y2);\n          case 3:\n            return new Rect(x1, y1, x2, value);\n        }\n        return null;\n      }\n\n      boolean valid(Rect o) {\n        if (x2 < o.x1) return true;\n        if (y2 < o.y1) return true;\n        if (o.x2 < x1) return true;\n        if (o.y2 < y1) return true;\n        return false;\n      }\n\n      boolean in(Rect o) {\n        return o.x1 <= x1 && x2 <= o.x2\n            && o.y1 <= y1 && y2 <= o.y2;\n      }\n\n      boolean equals(Rect o) {\n        return x1 == o.x1 && y1 == o.y1\n            && x2 == o.x2 && y2 == o.y2;\n      }\n\n      void print() {\n        out.printf(\"%d %d %d %d\", x1, y1, x2, y2);\n      }\n\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 currentPostion;\n    private int numberOfChars;\n\n    public QuickScanner(InputStream stream) {\n      this.stream = stream;\n      this.buffer = new byte[BUFFER_SIZE];\n      this.currentPostion = 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 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 (currentPostion >= numberOfChars) {\n        currentPostion = 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[currentPostion++];\n    }\n\n    public boolean isSpaceChar(int c) {\n      return c == ' '\n          || c == '\\n'\n          || c == '\\r'\n          || c == '\\t'\n          || c < 0;\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.print('\\n');\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\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "//make sure to make new file!\nimport java.io.*;\nimport java.util.*;\n\npublic class B713{\n   \n   public static BufferedReader f;\n   public static PrintWriter out; \n   \n   public static void main(String[] args)throws IOException{\n      f = new BufferedReader(new InputStreamReader(System.in));\n      out = new PrintWriter(System.out);\n      \n      int n = Integer.parseInt(f.readLine());\n      \n      \n      int l;\n      int r;\n      int mid;\n      int ans;\n      \n      \n      l = 1;\n      r = n;\n      ans = -1;\n      //see if you can draw vertical line between them\n      \n      while(l <= r){\n         mid = l + (r-l)/2;\n         if(mid == n) break;\n         \n         int il = query(1,1,n,mid);\n         int ir = query(1,mid+1,n,n);\n         \n         if(il == 1 && ir == 1){\n            ans = mid;\n            break;\n         }\n         \n         if(il > ir){\n            r = mid-1;\n         } else {\n            l = mid+1;\n         }\n      }\n      \n      int x11 = -1;\n      int y11 = -1;\n      int x12 = -1;\n      int y12 = -1;\n      int x21 = -1;\n      int y21 = -1;\n      int x22 = -1;\n      int y22 = -1;\n      if(ans == -1){\n         //find horizontal line\n         l = 1;\n         r = n;\n         ans = -1;\n      \n         while(l <= r){\n            mid = l + (r-l)/2;\n         \n         \n            int il = query(1,1,mid,n);\n            int ir = query(mid+1,1,n,n);\n         \n            if(il == 1 && ir == 1){\n               ans = mid;\n               break;\n            }\n         \n            if(il > ir){\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n      \n         int bar = ans;\n         \n                  //find top line of top block\n         l = 1;\n         r = bar;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(mid,1,bar,n);\n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         x11 = ans;\n         \n         //find bottom line of top block\n         l = 1;\n         r = bar;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,1,mid,n);\n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         x12 = ans;\n         \n         //find left of top block\n         \n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,mid,bar,n);\n            \n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         y11 = ans;\n         \n         //find right of top block\n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,1,bar,mid);\n            \n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         y12 = ans;\n         \n         \n         \n         \n         \n         //find top line of bottom block\n         l = bar+1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(mid,1,n,n);\n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         x21 = ans;\n         \n         //find bottom line of bottom block\n         l = bar+1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(bar+1,1,mid,n);\n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         x22 = ans;\n         \n         //find left of bottom block\n         \n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(bar+1,mid,n,n);\n            \n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         y21 = ans;\n         \n         //find right of bottom block\n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(bar+1,1,n,mid);\n            \n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         y22 = ans;\n         \n         \n         \n         \n         \n       \n      } else {\n         //ans is the vertical line between\n         int bar = ans;\n         //find left line of left block\n         l = 1;\n         r = bar;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,mid,n,bar);\n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         y11 = ans;\n         \n         //find right line of left block\n         l = 1;\n         r = bar;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,1,n,mid);\n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         y12 = ans;\n         \n         //find top of left block\n         \n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(mid,1,n,bar);\n            \n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         x11 = ans;\n         \n         //find bottom of left block\n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,1,mid,bar);\n            \n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         x12 = ans;\n         \n         \n         \n         \n         \n         //find left line of right block\n         l = bar+1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,mid,n,n);\n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         y21 = ans;\n         \n         //find right line of right block\n         l = bar+1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,bar+1,n,mid);\n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         y22 = ans;\n         \n         //find top of right block\n         \n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(mid,bar+1,n,n);\n            \n            if(i == 1){\n               ans = mid;\n               l = mid+1;\n            } else {\n               r = mid-1;\n            }\n         }\n         \n         x21 = ans;\n         \n         //find bottom of right block\n         l = 1;\n         r = n;\n         ans = -1;\n         while(l <= r){\n            mid = l + (r-l)/2;\n            \n            int i = query(1,bar+1,mid,n);\n            \n            if(i == 1){\n               ans = mid;\n               r = mid-1;\n            } else {\n               l = mid+1;\n            }\n         }\n         \n         x22 = ans;\n         \n      \n      }\n      \n      out.println(\"! \" + x11 + \" \" + y11 + \" \" + x12 + \" \" + y12 + \" \" + x21 + \" \" + y21 + \" \" + x22 + \" \" + y22);\n      \n      \n      \n      \n      out.close();\n   }\n   \n   public static int query(int a,int b, int c, int d)throws IOException{\n      out.println(\"? \" + a + \" \" + b + \" \" + c + \" \" + d);\n      out.flush();\n      \n      return Integer.parseInt(f.readLine());\n   }\n   \n      \n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "//package round371;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class BT {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\t\n\tint q(int r1, int c1, int r2, int c2)\n\t{\n\t\tout.printf(\"? %d %d %d %d\\n\", r1+1, c1+1, r2+1, c2+1);\n\t\tout.flush();\n\t\treturn ni();\n\t}\n\t\n\tvoid e(int r1, int c1, int r2, int c2, int r3, int c3, int r4, int c4)\n\t{\n\t\tout.printf(\"! %d %d %d %d %d %d %d %d\\n\", \n\t\t\t\tr1+1, c1+1, r2+1, c2+1,\n\t\t\t\tr3+1, c3+1, r4+1, c4+1\n\t\t\t\t);\n\t\tout.flush();\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint cu = -1, cv = -1;\n\t\t{\n\t\t\tint low = -1, high = n-1;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(0, 0, n-1, h) >= 2){\n\t\t\t\t\thigh = h;\n\t\t\t\t}else{\n\t\t\t\t\tlow = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcu = high;\n\t\t}\n\t\t{\n\t\t\tint low = -1, high = n-1;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(0, 0, n-1, h) >= 1){\n\t\t\t\t\thigh = h;\n\t\t\t\t}else{\n\t\t\t\t\tlow = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcv = high;\n\t\t}\n\t\t\n\t\tint du = -1, dv = -1;\n\t\t{\n\t\t\tint low = 0, high = n;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(0, h, n-1, n-1) >= 2){\n\t\t\t\t\tlow = h;\n\t\t\t\t}else{\n\t\t\t\t\thigh = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdu = low;\n\t\t}\n\t\t{\n\t\t\tint low = 0, high = n;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(0, h, n-1, n-1) >= 1){\n\t\t\t\t\tlow = h;\n\t\t\t\t}else{\n\t\t\t\t\thigh = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdv= low;\n\t\t}\n\t\t\n\t\tint eu = -1, ev = -1;\n\t\t{\n\t\t\tint low = -1, high = n-1;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(0, 0, h, n-1) >= 2){\n\t\t\t\t\thigh = h;\n\t\t\t\t}else{\n\t\t\t\t\tlow = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\teu = high;\n\t\t}\n\t\t{\n\t\t\tint low = -1, high = n-1;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(0, 0, h, n-1) >= 1){\n\t\t\t\t\thigh = h;\n\t\t\t\t}else{\n\t\t\t\t\tlow = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tev = high;\n\t\t}\n\t\t\n\t\tint fu = -1, fv = -1;\n\t\t{\n\t\t\tint low = 0, high = n;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(h, 0, n-1, n-1) >= 2){\n\t\t\t\t\tlow = h;\n\t\t\t\t}else{\n\t\t\t\t\thigh = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfu = low;\n\t\t}\n\t\t{\n\t\t\tint low = 0, high = n;\n\t\t\twhile(high - low > 1){\n\t\t\t\tint h = high+low>>1;\n\t\t\t\tif(q(h, 0, n-1, n-1) >= 1){\n\t\t\t\t\tlow = h;\n\t\t\t\t}else{\n\t\t\t\t\thigh = h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfv= low;\n\t\t}\n\t\t\n\t\t// cv <= cu\n\t\t// du <= dv\n\t\tint[][][] canc = {\n\t\t\t\t{{du, cu}, {dv, cv}},\n\t\t\t\t{{du, cv}, {dv, cu}}\n\t\t};\n\t\tint[][][] canr = {\n\t\t\t\t{{fu, eu}, {fv, ev}},\n\t\t\t\t{{fu, ev}, {fv, eu}}\n\t\t};\n\t\tfor(int[][] cr : canr){\n\t\t\tif(cr[0][0] > cr[0][1])continue;\n\t\t\tif(cr[1][0] > cr[1][1])continue;\n\t\t\tfor(int[][] cc : canc){\n\t\t\t\tif(cc[0][0] > cc[0][1])continue;\n\t\t\t\tif(cc[1][0] > cc[1][1])continue;\n\t\t\t\tfor(int z = 0;z < 2;z++){\n\t\t\t\t\tif(\n\t\t\t\t\t\t\tq(cr[0][0], cc[0^z][0], cr[0][1], cc[0^z][1]) == 1 &&\n\t\t\t\t\t\t\tq(cr[1][0], cc[1^z][0], cr[1][1], cc[1^z][1]) == 1){\n\t\t\t\t\t\te(cr[0][0], cc[0^z][0], cr[0][1], cc[0^z][1], cr[1][0], cc[1^z][0], cr[1][1], cc[1^z][1]);\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\tthrow new RuntimeException();\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 BT().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", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import javax.crypto.AEADBadTagException;\nimport 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.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author AlexFetisov\n */\npublic class TaskB_AF {\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_cf371 solver = new TaskB_cf371();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB_cf371 {\n        List<Rectangle> rects;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n\n            int xLeft = 1, xRight = n;\n            int xSeparate = -1;\n            while (xLeft <= xRight) {\n                int e = (xLeft + xRight) / 2;\n                int t = makeRequest(in, out, 1, 1, e, n);\n                if (t == 1) {\n                    xSeparate = e;\n                    xRight = e - 1;\n                } else if (t == 0) {\n                    xLeft = e + 1;\n                } else {\n                    xRight = e - 1;\n                }\n            }\n            rects = new ArrayList<Rectangle>();\n            if (xSeparate != -1 && makeRequest(in, out, xSeparate + 1, 1, n, n) == 1) {\n                detectRectangle(in, out, 1, 1, xSeparate, n);\n                detectRectangle(in, out, xSeparate + 1, 1, n, n);\n\n                out.print(\"! \");\n                for (Rectangle r : rects) {\n                    out.print(r.toString() + \" \");\n                }\n                out.println();\n                out.flush();\n                return;\n            }\n\n            int yLeft = 1, yRight = n;\n            int ySeparate = -1;\n            while (yLeft <= yRight) {\n                int e = (yLeft + yRight) / 2;\n                int t = makeRequest(in, out, 1, 1, n, e);\n                if (t == 1) {\n                    ySeparate = e;\n                    yRight = e - 1;\n                } else if (t == 0) {\n                    yLeft = e + 1;\n                } else {\n                    yRight = e - 1;\n                }\n            }\n\n            if (ySeparate != -1) {\n                detectRectangle(in, out, 1, 1, n, ySeparate);\n                detectRectangle(in, out, 1, ySeparate + 1, n, n);\n\n                out.print(\"! \");\n                for (Rectangle r : rects) {\n                    out.print(r.toString() + \" \");\n                }\n                out.println();\n                out.flush();\n                return;\n            }\n            throw new AssertionError(\"!\");\n        }\n\n        private void detectRectangle(InputReader in, PrintWriter out, int xMin, int yMin, int xMax, int yMax) {\n            int xLeft = -1, xRight = -1, yLeft = -1, yRight = -1;\n\n            int left = xMin, right = xMax;\n            while (left <= right) {\n                int e = (left + right) / 2;\n                if (makeRequest(in, out, xMin, yMin, e, yMax) == 1) {\n                    xRight = e;\n                    right = e - 1;\n                } else {\n                    left = e + 1;\n                }\n            }\n\n            left = xMin;\n            right = xRight;\n            while (left <= right) {\n                int e = (left + right) / 2;\n                if (makeRequest(in, out, e, yMin, xRight, yMax) == 1) {\n                    xLeft = e;\n                    left = e + 1;\n                } else {\n                    right = e - 1;\n                }\n            }\n\n            left = yMin;\n            right = yMax;\n            while (left <= right) {\n                int e = (left + right) / 2;\n                if (makeRequest(in, out, xLeft, yMin, xRight, e) == 1) {\n                    yRight = e;\n                    right = e - 1;\n                } else {\n                    left = e + 1;\n                }\n            }\n\n            left = yMin;\n            right = yRight;\n            while (left <= right) {\n                int e = (left + right) / 2;\n                if (makeRequest(in, out, xLeft, e, xRight, yRight) == 1) {\n                    yLeft = e;\n                    left = e + 1;\n                } else {\n                    right = e - 1;\n                }\n            }\n            rects.add(new Rectangle(xLeft, yLeft, xRight, yRight));\n        }\n\n        private int makeRequest(InputReader in, PrintWriter out, int x1, int y1, int x2, int y2) {\n            out.print(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n            out.println();\n            out.flush();\n            return in.nextInt();\n        }\n\n        class Rectangle {\n            int x1;\n            int x2;\n            int y1;\n            int y2;\n\n            public Rectangle(int x1, int y1, int x2, int y2) {\n                this.x1 = x1;\n                this.x2 = x2;\n                this.y1 = y1;\n                this.y2 = y2;\n            }\n\n\n            public String toString() {\n                StringBuilder b = new StringBuilder(\"\");\n                b.append(x1).append(' ');\n                b.append(y1).append(' ');\n                b.append(x2).append(' ');\n                b.append(y2);\n                return b.toString();\n            }\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 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", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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        int[][] dr = new int[][]{{0, 0, 0, -1}, {0, 0, -1, 0}, {0, 1, 0, 0}, {1, 0, 0, 0}};\n        int[][] dd = new int[][]{{1, 3}, {0, 2}, {1, 3}, {0, 2}};\n        PrintWriter out;\n        InputReader in;\n        int[] re1;\n        int[] re2;\n        int N;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            N = in.nextInt();\n            int r[] = new int[]{1, 1, N, N};\n\n            this.out = out;\n            this.in = in;\n\n            re1 = new int[]{1, 1, 1, 1};\n            re2 = new int[]{2, 1, 2, 1};\n\n            //probuje najpierw lewa sciane\n\n            int fr[] = moveSide(r, dr[2], dd[2]);\n            int sr[] = subtract(r, fr);\n            if (!validSeparation(sr)) {\n                fr = moveSide(r, dr[1], dd[1]);\n                sr = subtract(r, fr);\n            }\n\n            fr = boundary(fr);\n            sr = boundary(sr);\n\n            out.println(String.format(\"! %d %d %d %d %d %d %d %d\", fr[0], fr[1], fr[2], fr[3], sr[0], sr[1], sr[2], sr[3]));\n        }\n\n        private boolean validSeparation(int[] sr) {\n            if (!validRectangle(sr)) return false;\n            out.println(String.format(\"? %d %d %d %d\", sr[0], sr[1], sr[2], sr[3]));\n            out.flush();\n            return in.nextInt() == 1;\n        }\n\n        private boolean validRectangle(int[] sr) {\n            for (int i = 0; i < 4; i++) {\n                if (sr[i] < 1 || sr[i] > N) return false;\n            }\n            return true;\n        }\n\n        private int[] boundary(int[] r) {\n            for (int d = 0; d < 4; d++) {\n                r = moveSide(r, dr[d], dd[d]);\n            }\n            return r;\n        }\n\n        private int[] subtract(final int[] r, final int[] fr) {\n            if (r[1] == fr[1]) {\n                //jesli lewy dolny taki sam to ucieto horyzontalnie od gory\n                return new int[]{fr[2] + 1, r[1], r[2], r[3]};\n            }\n            //else ucieto wertykalnie od lewej\n            return new int[]{r[0], r[1], r[2], fr[1] - 1};\n        }\n\n        private int[] moveSide(final int[] rect, final int[] factors, final int[] widths) {\n            int width = Math.abs(rect[widths[0]] - rect[widths[1]]);\n\n            int lo = -1, hi = width + 1;\n\n            while (lo + 1 < hi) {\n                int m = lo + (hi - lo) / 2;\n                int qr[] = new int[4];\n                for (int d = 0; d < 4; d++) qr[d] = rect[d] + factors[d] * m;\n                int ans = query(qr);\n                if (ans != 0) {\n                    lo = m;\n                } else {\n                    hi = m;\n                }\n            }\n\n            int ans_rect[] = new int[4];\n            for (int d = 0; d < 4; d++) ans_rect[d] = rect[d] + factors[d] * lo;\n\n            return ans_rect;\n        }\n\n        private int query(final int[] qr) {\n            int ans = 0;\n            out.println(String.format(\"? %d %d %d %d\", qr[0], qr[1], qr[2], qr[3]));\n            out.flush();\n\n            ans = in.nextInt();\n\n//        if (contains(qr, re1)) ans++;\n//        if (contains(qr, re2)) ans++;\n            return 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\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\tstatic BufferedReader br;\n\tstatic int[] ans;\n\tpublic static void main(String[] args) throws Exception{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tans = new int[8];\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tSystem.out.println(\"?\"+\"1 1 \"+n+\" \"+n);\n\t\tSystem.out.flush();\n\t\tint q = Integer.parseInt(br.readLine());\n\t\tcut(n);\n\t\tSystem.out.print(\"! \");\n\t\tfor(int i=0 ; i<8 ; i++)\tSystem.out.print(ans[i]+\" \");\n\t\tSystem.out.println();\n\t}\n\t\n\tpublic static void solve(int x1, int y1, int x2, int y2, int t) throws Exception{\n\t\tint l=x1, r=x2;\n\t\tint xx1,yy1,xx2,yy2;\n\t\twhile(l<r){\n\t\t\tint mid = (l+r)/2;\n\t\t\tif(query(x1,y1,mid,y2)==1)\tr=mid;\n\t\t\telse\tl=mid+1;\n\t\t}\n\t\txx2 = l;\n\t\tl=x1; r=x2;\n\t\twhile(r>l){\n\t\t\tint mid = (l+r+1)/2;\n\t\t\tif(query(mid,y1,x2,y2)==1)\tl = mid;\n\t\t\telse r=mid-1;\n\t\t}\n\t\txx1 = l;\n\t\tl=y1; r=y2;\n\t\twhile(l<r){\n\t\t\tint mid = (l+r)/2;\n\t\t\tif(query(x1,y1,x2,mid)==1)\tr=mid;\n\t\t\telse\tl=mid+1;\n\t\t}\n\t\tyy2=l;\n\t\tl=y1;r=y2;\n\t\twhile(r>l){\n\t\t\tint mid = (l+r+1)/2;\n\t\t\tif(query(x1,mid,x2,y2)==1)\tl=mid;\n\t\t\telse\tr=mid-1;\n\t\t}\n\t\tyy1 = l;\n\t\tans[t] = xx1;\tans[t+1] = yy1 ; ans[t+2] = xx2;\tans[t+3] = yy2;\n\t//\tSystem.out.println(\"!\"+xx1+\" \"+yy1+\" \"+xx2+\" \"+yy2);\n\t}\n\tpublic static void cut(int n) throws Exception{\n\t\tint l=1, r=n;\n\t\twhile(l<r){\n\t\t\tint mid = (l+r)/2;\n\t\t\tif(query(1,1,n,mid)==0)\tl=mid+1;\n\t\t\telse\tr = mid;\n\t\t}\n\t\tif(query(1,1,n,l)==1 && query(1,l+1,n,n)==1){\n\t\t\tsolve(1,1,n,l,0);\n\t\t\tsolve(1,l+1,n,n,4);\n\t\t\treturn;\n\t\t}\n\t\tl=1;r=n;\n\t\twhile(l<r){\n\t\t\tint mid = (l+r)/2;\n\t\t\tif(query(1,1,mid,n)==0)\tl=mid+1;\n\t\t\telse\tr=mid;\n\t\t}\n\t\tsolve(1,1,l,n,0);\n\t\tsolve(l+1,1,n,n,4);\n\t}\n\tpublic static int query(int x1, int y1, int x2, int y2) throws Exception{\n\t\tSystem.out.println(\"?\"+x1+\" \"+y1+\" \"+x2+\" \"+y2);\n\t\tSystem.out.flush();\n\t\tint q = Integer.parseInt(br.readLine());\n\t\treturn q;\n\t}\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        int stage;\n        int n;\n        OutputWriter out;\n        InputReader in;\n\n        void query(int end) {\n            switch (stage) {\n            case 0:\n                out.printLine('?', 1, 1, end, n);\n                break;\n            case 1:\n                out.printLine('?', 1, 1, n, end);\n                break;\n            case 2:\n                out.printLine('?', n + 1 - end, 1, n, n);\n                break;\n            case 3:\n                out.printLine('?', 1, n + 1 - end, n, n);\n                break;\n            }\n            out.flush();\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            this.out = out = new OutputWriter(System.out);\n            this.in = in = new InputReader(System.in);\n            n = in.readInt();\n            int[] endx = new int[2];\n            int[] endy = new int[2];\n            int[] stx = new int[2];\n            int[] sty = new int[2];\n            find(endx);\n            stage++;\n            find(endy);\n            stage++;\n            find(stx);\n            for (int i = 0; i < 2; i++) {\n                stx[i] = n + 1 - stx[i];\n            }\n            stage++;\n            find(sty);\n            for (int i = 0; i < 2; i++) {\n                sty[i] = n + 1 - sty[i];\n            }\n            for (int i = 0; i < 8; i++) {\n                if (stx[i & 1] > endx[i >> 2 & 1] || sty[i >> 1 & 1] > endy[0]) {\n                    continue;\n                }\n                if (stx[1 - (i & 1)] > endx[1 - (i >> 2 & 1)] || sty[1 - (i >> 1 & 1)] > endy[1]) {\n                    continue;\n                }\n                out.printLine('?', stx[i & 1], sty[i >> 1 & 1], endx[i >> 2 & 1], endy[0]);\n                out.flush();\n                if (in.readInt() == 0) {\n                    continue;\n                }\n                out.printLine('?', stx[1 - (i & 1)], sty[1 - (i >> 1 & 1)], endx[1 - (i >> 2 & 1)], endy[1]);\n                out.flush();\n                if (in.readInt() != 0) {\n                    out.printLine(\"!\", stx[i & 1], sty[i >> 1 & 1], endx[i >> 2 & 1], endy[0], stx[1 - (i & 1)],\n                            sty[1 - (i >> 1 & 1)], endx[1 - (i >> 2 & 1)], endy[1]);\n                    out.flush();\n                    return;\n                }\n            }\n        }\n\n        private void find(int[] endx) {\n            int left = 1;\n            int right = n;\n            while (left < right) {\n                int middle = (left + right) >> 1;\n                query(middle);\n                if (in.readInt() == 2) {\n                    right = middle;\n                } else {\n                    left = middle + 1;\n                }\n            }\n            endx[0] = left;\n            left = 0;\n            right--;\n            while (left < right) {\n                int middle = (left + right + 1) >> 1;\n                query(middle);\n                if (in.readInt() == 0) {\n                    left = middle;\n                } else {\n                    right = middle - 1;\n                }\n            }\n            endx[1] = left + 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 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    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", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class DTask {\n\n    static Scanner in;\n    static int[] first = new int[4];\n    static int[] second = new int[4];\n    static PrintWriter out;\n    static int n;\n\n    public static void main(String[] args) throws IOException {\n        in = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        n = in.nextInt() + 1;\n        first = new int[]{0, 0, n, n};\n        second = new int[]{0, 0, n, n};\n        for (int i = 0; i < first.length; i++) {\n            boolean inc = i < 2;\n            search(first, i, inc, false);\n            if (!inc) {\n                first[i] += 1;\n            }\n        }\n\n        for (int i = 0; i < second.length; i++) {\n            boolean inc = i < 2;\n            search(second, i, inc, true);\n            if (!inc) {\n                second[i] += 1;\n            }\n        }\n        String s = \"!\";\n        for (int i = 0; i < 4; i++) {\n            s += \" \" + second[i];\n        }\n        for (int i = 0; i < 4; i++) {\n            s += \" \" + first[i];\n        }\n        out.println(s);\n        out.flush();\n    }\n\n    static void search(int arr[], int i, boolean inc, boolean cond) {\n        int start = 0;\n        int end = n;\n        while (true) {\n            if (end - start <= 1) {\n                arr[i] = start;\n                return;\n            }\n            int mid = (start + end) / 2;\n            arr[i] = mid;\n            int n = ask(arr, cond);\n            if (n > 0) {\n                if (inc) {\n                    start = mid;\n                } else {\n                    end = mid;\n                }\n            } else {\n                if (inc) {\n                    end = mid;\n                } else {\n                    start = mid;\n                }\n            }\n        }\n    }\n\n    static int ask(int arr[], boolean cond) {\n        if (arr[1] > arr[3] || arr[0] > arr[2]) {\n            return 0;\n        }\n        arr = Arrays.copyOf(arr, 4);\n        String q = \"\";\n        q += \"?\";\n        for (int i = 0; i < arr.length; i++) {\n            int x = Math.min(arr[i], n - 1);\n            x = Math.max(x, 1);\n            q += \" \" + x;\n        }\n        out.println(q);\n        out.flush();\n        int x = in.nextInt();\n        if (cond) {\n            x -= within(arr, first) ? 1 : 0;\n        }\n        return x;\n        /*if (arr[1] > arr[3] || arr[0] > arr[2]) {\n            return 0;\n        }\n        int[] check = new int[]{1, 1, 10, 1};\n        int[] check1 = new int[]{5, 5, 5, 10};\n        int result = within(arr, check) ? 1 : 0;\n        result += within(arr, check1) ? 1 : 0;\n        if (cond) {\n            result -= within(arr, first) ? 1 : 0;\n        }\n        return result;*/\n\n\n    }\n\n    static boolean within(int outer[], int inner[]) {\n        return (outer[0] <= inner[0] && outer[1] <= inner[1] && outer[2] >= inner[2] && outer[3] >= inner[3]);\n    }\n\n    static class MyInputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public MyInputReader(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\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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 B {\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 left = 0, right = n;\n\t\tint x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+1+\" \"+1+\" \"+mid+\" \"+n);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans==2)\n\t\t\t\tright = mid;\n\t\t\telse\n\t\t\t\tleft = mid;\n\t\t}\n\t\tx4 = right;\n\t\tleft = 0;\n\t\tright = n;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+1+\" \"+1+\" \"+mid+\" \"+n);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans >= 1)\n\t\t\t\tright = mid;\n\t\t\telse\n\t\t\t\tleft = mid;\n\t\t}\n\t\tx2 = right;\n\t\tleft = 1;\n\t\tright = n+1;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+mid+\" \"+1+\" \"+n+\" \"+n);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans >= 1)\n\t\t\t\tleft = mid;\n\t\t\telse\n\t\t\t\tright = mid;\n\t\t}\n\t\tx3 = left;\n\t\tleft = 1;\n\t\tright = n+1;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+mid+\" \"+1+\" \"+n+\" \"+n);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans >= 2)\n\t\t\t\tleft = mid;\n\t\t\telse\n\t\t\t\tright = mid;\n\t\t}\n\t\tx1 = left;\n\t\t\n\t\tleft = 0;\n\t\tright = n;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+1+\" \"+1+\" \"+n+\" \"+mid);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans>=2)\n\t\t\t\tright = mid;\n\t\t\telse\n\t\t\t\tleft = mid;\n\t\t}\n\t\ty4 = right;\n\t\tleft = 0;\n\t\tright = n;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+1+\" \"+1+\" \"+n+\" \"+mid);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans >= 1)\n\t\t\t\tright = mid;\n\t\t\telse\n\t\t\t\tleft = mid;\n\t\t}\n\t\ty2 = right;\n\t\tleft = 1;\n\t\tright = n+1;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+1+\" \"+mid+\" \"+n+\" \"+n);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans >= 1)\n\t\t\t\tleft = mid;\n\t\t\telse\n\t\t\t\tright = mid;\n\t\t}\n\t\ty3 = left;\n\t\tleft = 1;\n\t\tright = n+1;\n\t\twhile (right-left > 1) {\n\t\t\tint mid = (left+right) >> 1;\n\t\t\tSystem.out.println(\"? \"+1+\" \"+mid+\" \"+n+\" \"+n);\n\t\t\tint ans = nextInt();\n\t\t\tif (ans >= 2)\n\t\t\t\tleft = mid;\n\t\t\telse\n\t\t\t\tright = mid;\n\t\t}\n\t\ty1 = left;\n\t\tif (y3 <= y2 && x3 <= x2) {\n\t\t\tSystem.out.println(\"! \"+x3+\" \"+y3+\" \"+x2+\" \"+y2+\" \"+x1+\" \"+y1+\" \"+x4+\" \"+y4);\n\t\t\treturn;\n\t\t}\n\n\t\tSystem.out.println(\"? \"+x1+\" \"+y1+\" \"+x2+\" \"+y2);\n\t\tint ans1 = nextInt();\n\t\tSystem.out.println(\"? \"+x3+\" \"+y3+\" \"+x4+\" \"+y4);\n\t\tint ans2 = nextInt();\n\t\tif (ans1==1 && ans2==1) {\n\t\t\tSystem.out.println(\"! \"+x1+\" \"+y1+\" \"+x2+\" \"+y2+\" \"+x3+\" \"+y3+\" \"+x4+\" \"+y4);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println(\"? \"+x1+\" \"+y3+\" \"+x2+\" \"+y4);\n\t\tans1 = nextInt();\n\t\tSystem.out.println(\"? \"+x3+\" \"+y1+\" \"+x4+\" \"+y2);\n\t\tans2 = nextInt();\n\t\tif (ans1==1 && ans2==1) {\n\t\t\tSystem.out.println(\"! \"+x1+\" \"+y3+\" \"+x2+\" \"+y4+\" \"+x3+\" \"+y1+\" \"+x4+\" \"+y2);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println(\"? \"+x1+\" \"+y1+\" \"+x4+\" \"+y2);\n\t\tans1 = nextInt();\n\t\tSystem.out.println(\"? \"+x3+\" \"+y3+\" \"+x2+\" \"+y4);\n\t\tans2 = nextInt();\n\t\tif (ans1==1 && ans2==1) {\n\t\t\tSystem.out.println(\"! \"+x1+\" \"+y1+\" \"+x4+\" \"+y2+\" \"+x3+\" \"+y3+\" \"+x2+\" \"+y4);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println(\"? \"+x1+\" \"+y3+\" \"+x2+\" \"+y2);\n\t\tans1 = nextInt();\n\t\tSystem.out.println(\"? \"+x3+\" \"+y1+\" \"+x4+\" \"+y4);\n\t\tans2 = nextInt();\n\t\tif (ans1==1 && ans2==1) {\n\t\t\tSystem.out.println(\"! \"+x1+\" \"+y3+\" \"+x2+\" \"+y2+\" \"+x3+\" \"+y1+\" \"+x4+\" \"+y4);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t\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}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.StringTokenizer;\nimport java.util.Scanner;\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 Wolfgang Beyer\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        int found = 0;\n        int queryCount = 0;\n        int[] result = new int[8];\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            //int n = 100;\n            //int n = 65536;\n\n\n            int left = 1;\n            int right = n + 1;\n            while (left + 1 < right) {\n                int middle = (left + right) / 2;\n                int res = query(middle, 1, n, n);\n                if (res == 2) left = middle;\n                else if (res == 1) {\n                    //System.out.println(\"Searching single: \");\n                    findSingle(middle, 1, n, n);\n                    found++;\n                    break;\n                } else {\n                    right = middle;\n                }\n            }\n\n            int top = 1;\n            int bottom = n + 1;\n            while (top + 1 < bottom) {\n                int middle = (top + bottom) / 2;\n                int res = query(1, middle, n, n);\n                if (res == 2) top = middle;\n                else if (res == 1) {\n                    if ((found == 0) || (!containsRect(1, middle, n, n, result[0], result[1], result[2], result[3]))) {\n                        //System.out.println(\"Searching single: \");\n                        findSingle(1, middle, n, n);\n                        found++;\n                    }\n                    break;\n                } else {\n                    bottom = middle;\n                }\n            }\n\n            if (found < 2) {\n                //System.out.println(\"Dia 3: \");\n                left = 0;\n                right = n;\n                while (left + 1 < right) {\n                    int middle = (left + right) / 2;\n                    int res = query(1, 1, middle, n);\n                    if (res == 2) right = middle;\n                    else if (res == 1) {\n                        if ((found == 0) || (!containsRect(1, 1, middle, n, result[0], result[1], result[2], result[3]))) {\n                            //System.out.println(\"Searching single: \");\n                            findSingle(1, 1, middle, n);\n                            found++;\n                        }\n                        break;\n                    } else {\n                        left = middle;\n                    }\n                }\n            }\n\n            if (found < 2) {\n                //System.out.println(\"Dia 4:\");\n                top = 0;\n                bottom = n;\n                while (top + 1 < bottom) {\n                    int middle = (top + bottom) / 2;\n                    int res = query(1, 1, n, middle);\n                    if (res == 2) bottom = middle;\n                    else if (res == 1) {\n                        if ((found == 0) || (!containsRect(1, 1, n, middle, result[0], result[1], result[2], result[3]))) {\n                            //System.out.println(\"Searching single: \");\n                            findSingle(1, 1, n, middle);\n                            found++;\n                        }\n                        break;\n                    } else {\n                        top = middle;\n                    }\n                }\n            }\n\n            System.out.print(\"! \");\n            for (int i = 0; i < 8; i++) System.out.print(result[i] + \" \");\n            //System.out.println(\"\\n\" + queryCount + \" queries used\");\n        }\n\n        public boolean containsRect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {\n            if ((x1 <= x3) && (y1 <= y3) && (x2 >= x4) && (y2 >= y4)) return true;\n            return false;\n        }\n\n        public void findSingle(int x1, int y1, int x2, int y2) {\n            x1 = findTopX(x1, y1, x2, y2);\n            y1 = findTopY(x1, y1, x2, y2);\n            x2 = findBottomX(x1, y1, x2, y2);\n            y2 = findBottomY(x1, y1, x2, y2);\n            //System.out.println(\"x1: \" + x1 + \", y1: \" + y1 + \", x2: \" + x2 + \", y2: \" + y2);\n            result[0 + 4 * found] = x1;\n            result[1 + 4 * found] = y1;\n            result[2 + 4 * found] = x2;\n            result[3 + 4 * found] = y2;\n        }\n\n        public int findTopX(int x1, int y1, int x2, int y2) {\n            int left = x1;\n            int right = x2;\n            while (left + 1 < right) {\n                int mid = (left + right) / 2;\n                if (query(mid, y1, x2, y2) == 1) {\n                    left = mid;\n                } else {\n                    right = mid;\n                }\n            }\n            while (query(right, y1, x2, y2) == 0) right--;\n            return right;\n        }\n\n        public int findTopY(int x1, int y1, int x2, int y2) {\n            int left = y1;\n            int right = y2;\n            while (left + 1 < right) {\n                int mid = (left + right) / 2;\n                if (query(x1, mid, x2, y2) == 1) {\n                    left = mid;\n                } else {\n                    right = mid;\n                }\n            }\n            while (query(x1, right, x2, y2) == 0) right--;\n            return right;\n        }\n\n        public int findBottomX(int x1, int y1, int x2, int y2) {\n            int left = x1;\n            int right = x2;\n            while (left + 1 < right) {\n                int mid = (left + right) / 2;\n                if (query(x1, y1, mid, y2) == 1) {\n                    right = mid;\n                } else {\n                    left = mid;\n                }\n            }\n            while (query(x1, y1, left, y2) == 0) left++;\n            return left;\n        }\n\n        public int findBottomY(int x1, int y1, int x2, int y2) {\n            int left = y1;\n            int right = y2;\n            while (left + 1 < right) {\n                int mid = (left + right) / 2;\n                if (query(x1, y1, x2, mid) == 1) {\n                    right = mid;\n                } else {\n                    left = mid;\n                }\n            }\n            while (query(x1, y1, x2, left) == 0) left++;\n            return left;\n        }\n\n        public int query(int x1, int y1, int x2, int y2) {\n            queryCount++;\n\n            System.out.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n            System.out.flush();\n            Scanner sc = new Scanner(System.in);\n            return sc.nextInt();\n\n\n        /*int ret = 0;\n        //if(x1 <= 17 && 57 <= x2 && y1 <= 80 && 80 <= y2) ++ret;\n\t    //if(x1 <= 25 && 88 <= x2 && y1 <= 51 && 61 <= y2) ++ret;\n        if(x1 <= 10 && 10 <= x2 && y1 <= 11 && 11 <= y2) ++ret;\n        //if(x1 <= 11 && 11 <= x2 && y1 <= 10 && 10 <= y2) ++ret;\n        if(x1 <= 10 && 10 <= x2 && y1 <= 15 && 15 <= y2) ++ret;\n        //System.out.println(x1 + \", \" + y1 + \", \" + x2 + \", \" + y2 + \": \" + ret);\n\t    return ret;*/\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", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskB {\n\t\tint n;\n\t\tint sepX;\n\t\tint sepY;\n\t\tint x1;\n\t\tint y1;\n\t\tint x2;\n\t\tint y2;\n\t\tFastScanner in;\n\t\tPrintWriter out;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tthis.in = in;\n\t\t\tthis.out = out;\n\t\t\tn = in.nextInt();\n\n\t\t\tint x11, x12, y11, y12;\n\t\t\tint x21, x22, y21, y22;\n\t\t\tfindSeparatingX();\n\t\t\tfindSeparatingY();\n\n\t\t\tif (sepX >= 0) {\n\t\t\t\tlocate(0, 0, sepX, n);\n\t\t\t\tx11 = x1;\n\t\t\t\ty11 = y1;\n\t\t\t\tx12 = x2;\n\t\t\t\ty12 = y2;\n\t\t\t\tlocate(sepX, 0, n, n);\n\t\t\t\tx21 = x1;\n\t\t\t\ty21 = y1;\n\t\t\t\tx22 = x2;\n\t\t\t\ty22 = y2;\n\t\t\t} else {\n\t\t\t\tlocate(0, 0, n, sepY);\n\t\t\t\tx11 = x1;\n\t\t\t\ty11 = y1;\n\t\t\t\tx12 = x2;\n\t\t\t\ty12 = y2;\n\t\t\t\tlocate(0, sepY, n, n);\n\t\t\t\tx21 = x1;\n\t\t\t\ty21 = y1;\n\t\t\t\tx22 = x2;\n\t\t\t\ty22 = y2;\n\t\t\t}\n\n\t\t\t++x11;\n\t\t\t++x21;\n\t\t\t++y11;\n\t\t\t++y21;\n\t\t\tout.println(\"! \" + x11 + \" \" + y11 + \" \" + x12 + \" \" + y12 + \" \" + +x21 + \" \" + y21 + \" \" + x22 + \" \" + y22);\n\t\t\tout.flush();\n\t\t}\n\n\t\tvoid locate(int x1, int y1, int x2, int y2) {\n\t\t\tfor (int step = 15; step >= 0; step--) {\n\t\t\t\tint h = 1 << step;\n\t\t\t\tif (query(x1 + h, y1, x2, y2) > 0) {\n\t\t\t\t\tx1 += h;\n\t\t\t\t}\n\t\t\t\tif (query(x1, y1, x2 - h, y2) > 0) {\n\t\t\t\t\tx2 -= h;\n\t\t\t\t}\n\t\t\t\tif (query(x1, y1 + h, x2, y2) > 0) {\n\t\t\t\t\ty1 += h;\n\t\t\t\t}\n\t\t\t\tif (query(x1, y1, x2, y2 - h) > 0) {\n\t\t\t\t\ty2 -= h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.x1 = x1;\n\t\t\tthis.y1 = y1;\n\t\t\tthis.x2 = x2;\n\t\t\tthis.y2 = y2;\n\t\t}\n\n\t\tprivate void findSeparatingX() {\n\t\t\tint l = 0;\n\t\t\tint r = n;\n\t\t\twhile (r - l > 1) {\n\t\t\t\tint m = (l + r) / 2;\n\t\t\t\tif (query(0, 0, m, n) == 0) {\n\t\t\t\t\tl = m;\n\t\t\t\t} else {\n\t\t\t\t\tr = m;\n\t\t\t\t}\n\t\t\t}\n\t\t\tsepX = -1;\n\t\t\tif (query(0, 0, r, n) == 1 && query(r, 0, n, n) == 1) {\n\t\t\t\tsepX = r;\n\t\t\t}\n\t\t}\n\n\t\tprivate void findSeparatingY() {\n\t\t\tint l = 0;\n\t\t\tint r = n;\n\t\t\twhile (r - l > 1) {\n\t\t\t\tint m = (l + r) / 2;\n\t\t\t\tif (query(0, 0, n, m) == 0) {\n\t\t\t\t\tl = m;\n\t\t\t\t} else {\n\t\t\t\t\tr = m;\n\t\t\t\t}\n\t\t\t}\n\t\t\tsepY = -1;\n\t\t\tif (query(0, 0, n, r) == 1 && query(0, r, n, n) == 1) {\n\t\t\t\tsepY = r;\n\t\t\t}\n\t\t}\n\n\t\tint query(int x1, int y1, int x2, int y2) {\n\t\t\tif (x1 >= x2 || y1 >= y2) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t++x1;\n\t\t\t++y1;\n\t\t\tout.println(\"? \" + x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n\t\t\tout.flush();\n\t\t\treturn in.nextInt();\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n}\n\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "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        private int n;\n        private InputReader in;\n        private PrintWriter out;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            this.in = in;\n            this.out = out;\n            query(new Point(1, 1), new Point(n, n), new Rectangle());\n        }\n\n        private boolean query(Point bottomLeft, Point topRight, Rectangle rectangle) {\n            if (bottomLeft.r > topRight.r || bottomLeft.c > topRight.c)\n                return false;\n\n            // Find the column of the right edge.\n            int low = bottomLeft.c, high = topRight.c;\n            while (low < high) {\n                int mid = low + (high - low) / 2;\n                int answer = ask(bottomLeft.r, bottomLeft.c, topRight.r, mid);\n                if (answer > 0)\n                    high = mid;\n                else\n                    low = mid + 1;\n            }\n            int rightCol = low;\n\n            // Find the column of the left edge.\n            low = bottomLeft.c;\n            high = topRight.c;\n            while (low < high) {\n                int mid = low + (high - low + 1) / 2;\n                int answer = ask(bottomLeft.r, mid, topRight.r, topRight.c);\n                if (answer > 0)\n                    low = mid;\n                else\n                    high = mid - 1;\n            }\n            int leftCol = low;\n\n            // Find the topmost row.\n            low = bottomLeft.r;\n            high = topRight.r;\n            while (low < high) {\n                int mid = low + (high - low) / 2;\n                int answer = ask(bottomLeft.r, bottomLeft.c, mid, topRight.c);\n                if (answer > 0)\n                    high = mid;\n                else\n                    low = mid + 1;\n            }\n            int topRow = low;\n\n            // Find the bottommost row.\n            low = bottomLeft.r;\n            high = topRight.r;\n            while (low < high) {\n                int mid = low + (high - low + 1) / 2;\n                int answer = ask(mid, bottomLeft.c, topRight.r, topRight.c);\n                if (answer > 0)\n                    low = mid;\n                else\n                    high = mid - 1;\n            }\n            int bottomRow = low;\n\n            if (leftCol > rightCol) {\n                Rectangle first = new Rectangle();\n                query(new Point(1, leftCol), new Point(n, n), first);\n                Rectangle second = new Rectangle();\n                query(new Point(1, 1), new Point(n, rightCol), second);\n                out.printf(\"! %d %d %d %d %d %d %d %d\\n\",\n                        first.bottomLeft.r, first.bottomLeft.c, first.topRight.r, first.topRight.c,\n                        second.bottomLeft.r, second.bottomLeft.c, second.topRight.r, second.topRight.c);\n                return true;\n            }\n\n            if (bottomRow > topRow) {\n                Rectangle first = new Rectangle();\n                query(new Point(bottomRow, 1), new Point(n, n), first);\n                Rectangle second = new Rectangle();\n                query(new Point(1, 1), new Point(topRow, n), second);\n                out.printf(\"! %d %d %d %d %d %d %d %d\\n\",\n                        first.bottomLeft.r, first.bottomLeft.c, first.topRight.r, first.topRight.c,\n                        second.bottomLeft.r, second.bottomLeft.c, second.topRight.r, second.topRight.c);\n                return true;\n            }\n\n            rectangle.bottomLeft.r = bottomRow;\n            rectangle.bottomLeft.c = leftCol;\n            rectangle.topRight.r = topRow;\n            rectangle.topRight.c = rightCol;\n            return true;\n        }\n\n        private int ask(int r1, int c1, int r2, int c2) {\n            out.printf(\"? %d %d %d %d\\n\", r1, c1, r2, c2);\n            out.flush();\n            return in.nextInt();\n        }\n\n        private class Point {\n            private int r;\n            private int c;\n\n            public Point(int r, int c) {\n                this.r = r;\n                this.c = c;\n            }\n\n        }\n\n        private class Rectangle {\n            private Point bottomLeft;\n            private Point topRight;\n\n            public Rectangle() {\n                bottomLeft = new Point(-1, -1);\n                topRight = new Point(-1, -1);\n            }\n\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(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}\n\n", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class Main {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\" ;\n    boolean local = false;\n    int inf=0x7FFFFFFF;\n    int MOD=(int)(1e9+7);\n    double eps=1e-5;\n    double PI=Math.acos(-1);\n    void solve() {\n        long maxn=nl();\n        long L=1,R=maxn,ans=-1;\n        while (L<=R){\n            long mid=(L+R)/2;\n            if(ask(1,1,mid,maxn)<1)L=mid+1;\n            else{\n                R=mid-1;\n                ans=mid;\n            }\n        }\n        if(ask(1,1,ans,maxn)==1 && ask(ans+1,1,maxn,maxn)==1){\n            Yts1999 a1=gao(1,1,ans,maxn);\n            Yts1999 a2=gao(ans+1,1,maxn,maxn);\n            answer(a1,a2);\n        }else{\n            L=1;R=maxn;ans=-1;\n            while (L<=R){\n                long mid=(L+R)/2;\n                if(ask(1,1,maxn,mid)<1)L=mid+1;\n                else{\n                    R=mid-1;\n                    ans=mid;\n                }\n            }\n            Yts1999 a1=gao(1,1,maxn,ans);\n            Yts1999 a2=gao(1,ans+1,maxn,maxn);\n            answer(a1,a2);\n        }\n    }\n    void answer(Yts1999 a1,Yts1999 a2){\n        out.print(\"!\");\n        a1.print();\n        a2.print();\n        out.flush();\n    }\n    int ask(long a,long b,long c,long d){\n        out.printf(\"? %d %d %d %d\",a,b,c,d);\n        out.println();\n        out.flush();\n        return ni();\n    }\n    Yts1999 gao(long x1,long x2,long y1,long y2){\n        long a1=0,a2=0,a3=0,a4=0;\n        long L,R;\n        L=x1;R=y1;\n        while(L<=R){\n            long mid=(L+R)/2;\n            if(ask(mid,x2,y1,y2)==1){\n                a1=mid;\n                L=mid+1;\n            }else R=mid-1;\n        }\n        L=x1;R=y1;\n        while(L<=R){\n            long mid=(L+R)/2;\n            if(ask(x1,x2,mid,y2)==1){\n                a3=mid;\n                R=mid-1;\n            }else L=mid+1;\n        }\n        L=x2;R=y2;\n        while(L<=R){\n            long mid=(L+R)/2;\n            if(ask(x1,mid,y1,y2)==1){\n                a2=mid;\n                L=mid+1;\n            }else R=mid-1;\n        }\n        L=x2;R=y2;\n        while(L<=R){\n            long mid=(L+R)/2;\n            if(ask(x1,x2,y1,mid)==1){\n                a4=mid;\n                R=mid-1;\n            }else L=mid+1;\n        }\n        return new Yts1999(a1,a2,a3,a4);\n    }\n    public class Yts1999 implements Comparable{\n        public long a,b,c,d;\n        public Yts1999(long a,long b,long c,long d){\n            this.a=a;\n            this.b=b;\n            this.c=c;\n            this.d=d;\n        }\n        public int compareTo(Object o) {\n            Yts1999 to=(Yts1999)o;\n            if(this.d<to.d) return 1;\n            else if(this.d==to.d) return 0;\n            else return -1;\n        }\n        public void print(){\n            out.printf(\" %d %d %d %d\",a,b,c,d);\n        }\n    }\n    long[] exgcd(long a, long b) {\n        if (b == 0) return new long[]{1,0,a};\n        long[] res = exgcd(b, a%b);\n        long t = res[0]; res[0] = res[1]; res[1] = t;\n        res[1] -= a/b*res[0];\n        return res;\n    }\n    long gcd(long a,long b){\n        return b==0?a:gcd(b,a%b);\n    }\n    long lcm(long a,long b){\n        return a*b/gcd(a,b);\n    }\n    private void run() {\n        is = local? new ByteArrayInputStream(INPUT.getBytes()):System.in;\n        out = new PrintWriter(System.out);\n        long s = System.currentTimeMillis();\n        solve();\n        out.flush();\n        tr(System.currentTimeMillis()-s+\"ms\");\n    }\n    public static void main(String[] args) throws Exception { new Main().run(); }\n    private byte[] inbuf = new byte[1024];\n    public int lenbuf = 0, ptrbuf = 0;\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    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 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    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    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    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    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        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 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    private void tr(Object... o) { if(local)System.out.println(Arrays.deepToString(o)); }\n}", "complexity": "logn", "problem": "713_B. Searching Rectangles", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport java.security.SecureRandom;\nimport static java.util.Arrays.*;\nimport java.util.*;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\nimport sun.misc.Regexp;\nimport java.awt.geom.*;\nimport sun.net.www.content.text.plain;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n    StreamTokenizer in;\n    PrintWriter out;\n//deb////////////////////////////////////////////////\n\n    public static void deb(String n, Object n1) {\n        System.out.println(n + \" is : \" + n1);\n    }\n\n    public static void deb(int[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(boolean[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(double[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(String[] A) {\n\n        for (Object oo : A) {\n            System.out.print(oo + \" \");\n        }\n        System.out.println(\"\");\n    }\n\n    public static void deb(int[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\n\n    public static void deb(double[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\n\n    public static void deb(long[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\n\n    public static void deb(String[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            for (Object oo : A[i]) {\n                System.out.print(oo + \" \");\n            }\n            System.out.println(\"\");\n        }\n\n    }\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    void run() throws IOException {\n//          in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));\n        // out = new PrintWriter(new FileWriter(\"output.txt\"));\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//boolean inR(int x,int y){\n//return (x<=0)&&(x<4)&&(y<=0)&&(y<4);\n//}\n    @SuppressWarnings(\"unchecked\")\n    void solve() throws IOException {\n        //   BufferedReader re= new BufferedReader(new FileReader(\"C:\\\\Users\\\\ASELA\\\\Desktop\\\\PROBLEMSET\\\\input\\\\F\\\\10.in\"));\n           BufferedReader re= new BufferedReader(new InputStreamReader(System.in));\n     Scanner sc= new Scanner(System.in);\n     long n=sc.nextLong(),k=sc.nextLong();\n     if(k*(k-1)/2<n-1)\n            System.out.println(\"-1\");\n     else{\n     long ff=k*(k-1)/2;\n     ff=-2*(n-1-ff);\n     //    System.out.println(ff);\n    long up=k,dw=0;\n    while(up-dw>1){\n    long c=(up+dw)/2;\n    if(c*(c-1)<=ff)dw=c;\n    else up=c;\n    \n    }\n    if(n==1)\n    {   System.out.println(\"0\");\n    return;\n    }\n         System.out.println(k-dw);\n     }\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tBufferedReader in;\n\tStringTokenizer str = null;\n\tPrintWriter out;\n\t\n\tprivate String next() throws Exception{\n\t\tif (str == null || !str.hasMoreElements())\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\treturn str.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate long nextLong() throws Exception{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate double nextDouble() throws Exception{\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tpublic void run() throws Exception{\n\t\tin =  new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong n = nextLong();\n\t\tif (n == 1) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong k = nextLong();\n\t\tlong t = 1-(k-1) + k*(k+1)/2-1;\n\t\tif (t < n){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\n\t\tlong l = 0;\n\t\tlong r = k;\n\n\t\twhile(r - l > 1) {\n\t\t\tlong m = (r + l)/2;\n\t\t\tlong s = 1 - m + k*(k+1)/2 - (k-m)*(k-m+1)/2;\n\t\t\t//System.out.println(m + \" \" + s + \" \" + n);\n\t\t\tif (s >= n){\n\t\t\t\tr = m;\n\t\t\t}else{\n\t\t\t\tl = m;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(r);\n\t\tout.close();\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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\tlong n = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tif ((k - 1) * k / 2 + 1 < n) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tlong left = 0;\n\t\tlong right = k;\n\t\twhile (left < right) {\n\t\t\tlong m = (left + right) / 2;\n\t\t\tif (k * (k - 1)/2 - (k - m) * (k - m - 1) / 2 +1 < n)\n\t\t\t\tleft = m + 1;\n\t\t\telse\n\t\t\t\tright = m;\n\t\t}\n\t\tSystem.out.println(left);\n\t}\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class B {\n\tstatic long sum(long from, long to){\n\t\tfinal long d = to - from;\n\t\treturn (d*(d + 1))/2 + (d + 1)*from;\n\t}\n\tstatic long howMany(long n, long k){\n\t\tif (n == 1){\n\t\t\treturn 0;\n\t\t}\n\t\tif (n > (k*(k - 1))/2 + 1){\n\t\t\treturn -1;\n\t\t}\n\t\tlong hi = k - 1;\n\t\tlong lo = 1;\n\t\twhile (lo < hi){\n\t\t\tfinal long mi = (lo + hi + 1) >> 1;\n\t\t\tfinal long sum = sum(mi, k - 1);\n\t\t\tif (n - 1 - sum < mi){\n\t\t\t\tlo = mi;\n\t\t\t}else{\n\t\t\t\thi = mi - 1;\n\t\t\t}\n\t\t}\n\t\tlong res = k - lo;\n\t\tfinal long sum = sum(lo, k - 1);\n\t\tif (n - 1 - sum > 0){\n\t\t\tres++;\n\t\t}\n\t\treturn res;\n\t}\n\tpublic static void main(String [] args){\n\t\ttry (Scanner s = new Scanner(System.in)){\n\t\t\tfinal long n = s.nextLong();\n\t\t\tfinal long k = s.nextLong();\n\t\t\tSystem.out.println(howMany(n, k));\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\t(new Main()).solve();\n\t}\n\n\tpublic Main() {\n\t}\n\t\n\tMyReader in = new MyReader();\n\tPrintWriter out = new PrintWriter(System.out);\n\t\n\tvoid solve() throws IOException {\n\t\t// BufferedReader in = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n\t\t// Scanner in = new Scanner(System.in);\n\n\t\t//Scanner in = new Scanner(new FileReader(\"forbidden-triples.in\"));\n\t\t//PrintWriter out = new PrintWriter(\"forbidden-triples.out\");\n\t\tlong n = in.nextLong();\n\t\tlong k = in.nextLong();\n\t\tlong sum = 1;\n\t\tlong count = 0;\n\t\t\n\t\tlong index = k - 1;\n\t\t\n\t\tlong[] delta = {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1, 0};\n\t\t\n\t\twhile (index > 0) {\n\t\t\tif (index + sum <= n) {\n\t\t\t\tfor (int d = 0; d < delta.length; d++) {\n\t\t\t\t\tif (delta[d] < index) {\n\t\t\t\t\t\tlong m = (2 * index - delta[d])*(delta[d] + 1)/2;\n\t\t\t\t\t\tif (m + sum <= n) {\n\t\t\t\t\t\t\tsum += m;\n\t\t\t\t\t\t\tindex -= (delta[d] + 1);\n\t\t\t\t\t\t\tcount += (delta[d] + 1);\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\tindex = n - sum;\n\t\t\t}\n\t\t}\n\t\tif (sum == n) {\n\t\t\tout.println(count);\n\t\t} else {\n\t\t\tout.println(-1);\n\t\t}\n\t\t\n\t\t\n\t\tout.close();\n\t}\t\n\n};\n\nclass MyReader {\n\tprivate BufferedReader in;\n\tString[] parsed;\n\tint index = 0;\n\n\tpublic MyReader() {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\tif (parsed == null || parsed.length == index) {\n\t\t\tread();\n\t\t}\n\t\treturn Integer.parseInt(parsed[index++]);\n\t}\n\n\tpublic long nextLong() throws NumberFormatException, IOException {\n\t\tif (parsed == null || parsed.length == index) {\n\t\t\tread();\n\t\t}\n\t\treturn Long.parseLong(parsed[index++]);\n\t}\n\t\n\tpublic String nextString() throws IOException {\n\t\tif (parsed == null || parsed.length == index) {\n\t\t\tread();\n\t\t}\n\t\treturn parsed[index++];\n\t}\n\n\tprivate void read() throws IOException {\n\t\tparsed = in.readLine().split(\" \");\n\t\tindex = 0;\n\t}\n\n\tpublic String readLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n};", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Problem2 implements Runnable {\n    public void run() {\n        Scanner scanner = new Scanner(System.in);\n        PrintWriter writer = new PrintWriter(System.out);\n\n        long n = scanner.nextLong();\n        long k = scanner.nextLong();\n\n        long count = 1;\n\n\n        if (n == 1) {\n            writer.println(0);\n            writer.close();\n            return;\n        }\n\n        if (k >= n) {\n            writer.println(1);\n            writer.close();\n            return;\n        }\n\n        long answer = 0;\n\n        while (k > 1) {\n            if (k > 2000) {\n                if (count + k <= n) {\n                    if (count + (k - 1 + k - 1000) * 500 <= n) {\n                        count += (k - 1 + k - 1000) * 500;\n                        k -= 1000;\n                        answer += 1000;\n                    }\n                }\n            }\n            if ((count + k - 1) <= n) {\n                    count += (k - 1);\n                    answer++;\n\n            }\n\n            if (count + k - 100000000000000000l > n) {\n                k -= 99999999999999999l;\n            }\n            if (count + k - 10000000000000000l > n) {\n                k -= 9999999999999999l;\n            }\n            if (count + k - 1000000000000000l > n) {\n                k -= 999999999999999l;\n            }\n            if (count + k - 100000000000000l > n) {\n                k -= 99999999999999l;\n            }\n            if (count + k - 10000000000000l > n) {\n                k -= 9999999999999l;\n            }\n            if (count + k - 1000000000000l > n) {\n                k -= 999999999999l;\n            }\n            if (count + k - 100000000000l > n) {\n                k -= 99999999999l;\n            }\n            if (count + k - 10000000000l > n) {\n                k -= 9999999999l;\n            }\n            if (count + k - 1000000000l > n) {\n                k -= 999999999l;\n            }\n            if (count + k - 100000000l > n) {\n                k -= 99999999l;\n            }\n            if (count + k - 10000000l > n) {\n                k -= 9999999l;\n            }\n            if (count + k - 1000000l > n) {\n                k -= 999999l;\n            }\n            if (count + k - 100000l > n) {\n                k -= 99999l;\n            }\n            if (count + k - 10000l > n) {\n                k -= 9999l;\n            }\n            if (count + k - 1000l > n) {\n                k -= 999l;\n            }\n            if (count + k - 100l > n) {\n                k -= 99l;\n            }\n\n\n            if (n - count + 1 < k) {\n                k = n - count + 1;\n            } else {\n                k--;\n            }\n\n        }\n\n\n        if (count == n) {\n            writer.println(answer);\n        } else {\n            writer.println(-1);\n        }\n        writer.close();\n    }\n    public static void main(String[] args) {\n        new Problem2().run();\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class My {\n  public static void main(String[] args) {\n    new My().go();\n  }\n\n  \n  void go() {\n    Scanner in = new Scanner(System.in);\n    long n = in.nextLong();\n    int k = in.nextInt();\n    int mn = 0, mx = k + 1;\n    while (mn < mx) {\n      int mid = (mn + mx) / 2;\n      if (works(n, k, mid)) {\n        mx = mid;\n      } else {\n        mn = mid + 1;\n      }\n    }\n    if (mn > k) {\n      pl(\"-1\");\n    } else {\n      pl((mn - 1) + \"\");\n    }\n  }\n  \n  boolean works(long n, int k, int use) {\n    return 1 + T(k - 1) - T(k - use) >= n;\n  }\n  \n  long T(int n) {\n    return n * (long)(n + 1) / 2;\n  }\n  \n  void p(String s) {\n    System.out.print(s);\n  }\n\n  void pl(String s) {\n    System.out.println(s);\n  }\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.*;\n\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tlong N = sc.nextLong();\n\t\tlong K = sc.nextLong();\n\n\t\tif (N == 1) {\n\t\t\tout.println(0);\n\t\t} else if (N <= K) {\n\t\t\tout.println(1);\n\t\t} else if (N > ((K - 1) * (K)) / 2 + 1) {\n\t\t\tout.println(-1);\n\t\t} else {\n\n\t\t\tlong lo = 1;\n\t\t\tlong hi = Math.max(K - 2, 1);\n\n\t\t\tlong big = ((K - 2) * (K - 1)) / 2;\n\n\t\t\tlong prevmid = -1;\n\n\t\t\tfor (int i = 0; i < 10000; i++) {\n\t\t\t\tlong mid = (lo + hi) / 2;\n\n\t\t\t\t// K = 5\n\t\t\t\t// Start = K-2;\n\t\t\t\t// 1 = K-2;\n\t\t\t\t// 2 = K-3... etc.\n\n\t\t\t\tlong tmp = ((K - 2 - mid) * (K - 2 - mid + 1)) / 2;\n\t\t\t\t//System.out.println(mid + \" \" + big + \" \" + tmp);\n\n\t\t\t\tif (K + big - tmp > N) {\n\t\t\t\t\thi = mid;\n\t\t\t\t} else if (K + big - tmp < N) {\n\t\t\t\t\tlo = mid;\n\t\t\t\t\tif (prevmid == mid)\n\t\t\t\t\t\tlo++;\n\t\t\t\t\tlo = Math.min(lo, hi);\n\t\t\t\t\tprevmid = mid;\n\t\t\t\t} else {\n\t\t\t\t\tlo = mid;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println((long) lo + 1);\n\t\t}\n\t\tsc.close();\n\t\tout.close();\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n/**\n * Created with IntelliJ IDEA.\n * User: horikawa\n * Date: 3/23/13\n * Time: 1:29 AM\n * To change this template use File | Settings | File Templates.\n */\npublic class B {\n    public static void main (String[] argv) {\n        Scanner in = new Scanner(System.in);\n        long n = in.nextLong();\n        long k = in.nextLong();\n        long max = ((k*(k-1))/2L)+1L;\n        long ans = -1;\n        if (n == 1) {\n            System.out.println(0);\n            return;\n        }\n        if (max < n) {\n            ans = -1;\n        } else if (max == n) {\n            ans = k-1;\n        } else {\n            if (k >= n) {\n                ans = 1;\n            } else {\n                long low = 1;\n                long high = k-1;\n                while (high > low+1) {\n                    long mid = (low+high)/2;\n                    long sum = (((mid+(k-1)) * (k-mid)) / 2) + 1;\n                    if (sum >= n) {\n                        low = mid;\n                    } else {\n                        high = mid;\n                    }\n                }\n                ans = (k - low);\n            }\n        }\n        System.out.println(ans);\n        return;\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tdoIt();\n\t}\n\n\tstatic void doIt() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tlong n = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tlong msum = (k - 1) * k / 2 + 1;\n\t\tlong u = k;\n\t\tlong l = 0;\n\t\tlong m = (u + l) / 2;\n\t\twhile(l < u){\n\t\t\tm = (u + l) / 2 + (u + l) % 2;\n\t\t\tlong sum = (m - 1) * m / 2;\n\t\t\tif(n <= msum - sum) l = m;\n\t\t\telse u = m - 1;\n\t\t}\n\t\tm = (u + l) / 2 + (u + l) % 2;\n\t\tif(msum - (m - 1) * m / 2 < n) System.out.println(-1);\n\t\telse System.out.println(k - m);\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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 */\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\nclass TaskB {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        long n=in.nextLong();\n        long k=in.nextInt();\n        if(n==1){\n            out.println(0);\n            return;\n        }\n        long max=k*(k-1)/2+1;\n        if(max<n){\n            out.println(\"-1\");\n            return;\n        }\n\n        long low=1,high=k-1;\n        long ans=k-1;\n        while (low<=high){\n            long mid=(low+high)/2;\n            long val=mid*mid-mid*(2*k-1)+2*n-2;\n            if(val>0){\n                low=mid+1;\n            }\n            else {\n                ans=mid;\n                high=mid-1;\n            }\n        }\n        out.println(ans);\n\n    }\n}\n\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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 P287B{\n\tScanner sc=new Scanner(System.in);\n\n\tint INF=1<<28;\n\tdouble EPS=1e-9;\n\n\tlong n, k;\n\n\tvoid run(){\n\t\tn=sc.nextLong();\n\t\tk=sc.nextLong();\n\t\tsolve();\n\t}\n\n\tvoid solve(){\n\t\tlong left=-1, right=k+1;\n\t\tfor(; right-left>1;){\n\t\t\tlong m=(left+right)/2;\n\t\t\tlong lb=k*(k+1)/2-(k-m)*(k-m+1)/2-(m-1);\n\t\t\tif(lb>=n){\n\t\t\t\tright=m;\n\t\t\t}else{\n\t\t\t\tleft=m;\n\t\t\t}\n\t\t}\n//\t\tdebug(left, right);\n\t\tprintln(\"\"+(right>k?-1:right));\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\n\t}\n\n\tvoid debug(Object... os){\n\t\tSystem.err.println(deepToString(os));\n\t}\n\n\tpublic static void main(String[] args){\n\t\tLocale.setDefault(Locale.US);\n\t\tnew P287B().run();\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "/**\n * Created with IntelliJ IDEA.\n * User: yuantian\n * Date: 3/24/13\n * Time: 2:18 AM\n * Copyright (c) 2013 All Right Reserved, http://github.com/tyuan73\n */\n\nimport java.util.*;\n\npublic class Pipeline {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n\n        long n = in.nextLong();\n        long k = in.nextLong();\n\n        if (n == 1) {\n            System.out.println(0);\n            return;\n        }\n        if (k >= n) {\n            System.out.println(1);\n            return;\n        }\n\n        long total = (k + 2) * (k - 1) / 2 - (k - 2);\n        if (total < n) {\n            System.out.println(-1);\n            return;\n        }\n\n        int i = 2, j = (int) k;\n        while (i <= j) {\n            int m = (i + j) / 2;\n            total = (k + m) * (k - m + 1) / 2 - (k - m);\n            if (total == n) {\n                System.out.println(k - m + 1);\n                return;\n            }\n            if (total < n)\n                j = m - 1;\n            else\n                i = m + 1;\n        }\n        System.out.println(k-i+2);\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class b {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextLong() - 1, k = sc.nextLong() - 1;\n\n        int a = 0;\n        if ((k + 1) * k / 2 < n) {\n            System.out.println(-1);\n            return;\n        }\n        while (n > 0 && k > 0) {\n            long min = go(n, k);\n            a += (k - min + 1);\n            n -= (k + min) * (k - min + 1) / 2;\n            k = Math.min(min - 1, n);\n        }\n\n        if (n == 0)\n            System.out.println(a);\n        else\n            System.out.println(-1);\n\n    }\n\n    static long go(long n, long k) {\n        long low = 1, high = k;\n\n        while (low + 1 < high) {\n            long mid = (low + high) / 2;\n\n            if ((k + mid) * (k - mid + 1) / 2 <= n) {\n                high = mid;\n            } else\n                low = mid;\n\n        }\n        return high;\n    }\n\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Pipeline {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tsc.close();\n\n\t\tif (k * (k - 1) / 2 + 1 < n) {\n\t\t\tSystem.out.println(-1);\n\t\t} else {\n\t\t\tlong l = -1, r = k;\n\t\t\twhile (r - l > 1) {\n\t\t\t\tlong m = (r + l) / 2;\n\t\t\t\tif (cantidadPosible(k, m) >= n) {\n\t\t\t\t\tr = m;\n\t\t\t\t} else {\n\t\t\t\t\tl = m;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(r);\n\t\t}\n\n\t}\n\n\tprivate static long cantidadPosible(long k, long usadas) {\n\t\treturn (k * (k - 1) / 2 + 1 - (k - usadas) * (k - usadas - 1) / 2);\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.math.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tlong k = scan.nextLong();\n\t\tlong total = k * (k - 1) / 2 + 1;\n\t\tif (total < n) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong left = total - n;\n\t\tlong low = 1;\n\t\tlong high = k - 1;\n\t\twhile (low < high) {\n\t\t\tlong mid = (low + high) / 2;\n\t\t\tlong temp = mid * (mid + 1) / 2;\n\t\t\tif (temp < left) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\tlong temp = low * (low + 1) / 2;\n\t\tif (temp == left) {\n\t\t\tSystem.out.println(k - 1 - low);\n\t\t} else {\n\t\t\tSystem.out.println(k - low);\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.ArrayList;\npublic class Main {\n\n    static int d[][];\n    static int N;\n    static boolean used[];\n    static class point\n    {\n        int x = 0;\n        int y = 0;\n    }\n    static point dats[];\n     \n    public static void main(String[] args) \n    {\n        Scanner scan = new Scanner(System.in);\n        \n        \n        long n = scan.nextLong();\n        long k = scan.nextLong();\n        if(n==1)\n        {\n            System.out.print(\"0\");\n            return;\n        }\n        if(n<=k) \n        {\n            System.out.print(\"1\");\n            return;\n        }\n        long d = 9-4*(2*n-k*k+k);\n        if(d<0) \n        {\n            System.out.print(\"-1\");\n            return;\n        }\n        double a = ((3+Math.sqrt(d)) / 2) ;\n            if(a>=1)\n                System.out.println(Math.max(2, k-(long)a+1));\n            else\n            System.out.println(-1);\n        \n        \n    }\n    \n\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "\n\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class B {\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        if (n == 1) {\n            System.out.println(0);\n        } else if (n <= k) {\n            System.out.println(1);\n        } else {\n            n--;\n            k--;\n            BigInteger K = BigInteger.valueOf(k);\n            BigInteger N = BigInteger.valueOf(n);\n            BigInteger high = BigInteger.valueOf(k + 1);\n            BigInteger low = BigInteger.valueOf(1);\n            BigInteger mid;\n            while (low.compareTo(high) < 0) {\n                mid = low.add(high.subtract(low).shiftRight(1));\n                BigInteger elemCnt = K.subtract(mid).add(BigInteger.ONE);\n                BigInteger sum = elemCnt.multiply(\n                        mid.shiftLeft(1).add(elemCnt.subtract(BigInteger.ONE)))\n                        .shiftRight(1);\n                if (sum.compareTo(N) > 0) {\n                    low = mid.add(BigInteger.valueOf(1));\n                } else {\n                    high = mid;\n                }\n            }\n            BigInteger elemCnt = K.subtract(low).add(BigInteger.ONE);\n            BigInteger sum = elemCnt.multiply(\n                    low.shiftLeft(1).add(elemCnt.subtract(BigInteger.ONE)))\n                    .shiftRight(1);\n            BigInteger rem = N.subtract(sum);\n            if (rem.equals(BigInteger.ZERO)) {\n                System.out.println(elemCnt);\n            } else if (rem.compareTo(low) < 0) {\n                System.out.println(elemCnt.add(BigInteger.ONE));\n            } else {\n                System.out.println(-1);\n            }\n        }\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class B176 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(new BufferedInputStream(System.in));\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        long n = in.nextLong() - 1;\n        long k = in.nextLong() - 1;\n        if (k * (k + 1) / 2 < n) out.println(-1);\n        else if (n == 0) out.println(0);\n        else if (n < k) out.println(1);\n        else {\n            long t = binSearch(n, k, 1, k);\n            long ans = k - t + 1;\n            if (k * (k + 1) / 2 - t * (t - 1) / 2 != n) ans++;\n            out.println(ans);\n        }\n        out.close();\n    }\n\n    private static long binSearch(long n, long k, long from, long to) {\n        if (from == to) return from;\n        long mid = (from + to) / 2;\n        if (k * (k + 1) / 2 - mid * (mid - 1) / 2 > n) return binSearch(n, k, mid + 1, to);\n        else return binSearch(n, k, from, mid);\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\t\n\t\t\tString[] param = br.readLine().split(\" \");\n\t\t\tlong n = Long.parseLong(param[0])-1;\n\t\t\tlong k = Long.parseLong(param[1])-1;\n\t\t\tlong max = k*(k+1)/2;\n\t\t\tlong answer;\n\t\t\tif (n > max) answer = -1;\n\t\t\telse {\n\t\t\t\tlong margin = max - n;\n\t\t\t\tlong m = Math.max(0,(long)Math.floor((1.0+Math.sqrt(1+8*margin))/2.0)-1);\n\t\t\t\tlong min = m*(m+1)/2;\n\t\t\t\twhile (min <= margin) { m++; min = m*(m+1)/2; }\n\t\t\t\tanswer = k - m + 1;\n\t\t\t}\n\t\t\tpw.println(answer);\n\t\t\t\n\t\t\tpw.close();\n\t\t\tbr.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\treturn;\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long N = in.nextLong();\n        long K = in.nextLong();\n\n        if(N == 1) {\n            out.println(0);\n            return;\n        }\n        if(N <= K) {\n            out.println(1);\n            return;\n        }\n\n        long st = 1;\n        long dr = K - 1;\n        long m;\n        long ans = -1;\n\n        while(st <= dr) {\n            m = (st + dr) / 2;\n\n            if(get(m, K) <= N) {\n                ans = m;\n                st = m + 1;\n            }\n            else dr = m - 1;\n        }\n\n        N -= get(ans, K);\n\n        if(ans == -1 || (ans == K - 1 && N > 0) ) {\n            out.println(-1);\n            return;\n        }\n        if(N > 0)\n            ans++;\n\n        out.println(ans);\n    }\n\n    private long get(long p, long K) {\n        long sum = (K - p + 1 + K) * p / 2;\n        long extra = p - 1;\n        return sum - extra;\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 long nextLong() {\n        return Long.parseLong(nextString());\n    }\n\n    public String nextString() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        StringBuffer res = new StringBuffer();\n        do {\n            res.appendCodePoint(c);\n            c = read();\n        } while (!isSpaceChar(c));\n        return res.toString();\n    }\n\n    private boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    }\n\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.util.Scanner;\n\n/**\n *\n * @author 111\n */\npublic class JavaApplication4 {\n\n    /**\n     * @param args the command line arguments\n     */\n    static long k, n, ans;\n    static private long binsearch(long l, long r)\n    {\n        if(l==r) return l;\n        long m=(l+r)/2;\n        long res=(m*(k+k-m+1)/2);\n        if(res>=n)\n            return binsearch(l, m);\n        else\n            return binsearch(m+1, r);\n    }\n    public static void main(String[] args) {\n        Scanner in=new Scanner(System.in);\n        n=in.nextLong();\n        k=in.nextLong();\n        n--;\n        k--;\n        if(k*(k+1)/2<n)\n            ans=-1;\n        else\n            ans=binsearch(0, k);\n        System.out.println(ans);            \n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class B {\n\n\t/**\n\t * @param args\n\t * @throws IOException\n\t * @throws NumberFormatException\n\t */\n\tpublic static void main(String[] args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong(), k = sc.nextLong();\n\t\t// BufferedReader rd = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n\t\t// StringTokenizer t = new StringTokenizer(rd.readLine(), \" \");\n\t\t// int n = Integer.parseInt(rd.readLine());\n\t\tif (n == 1) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif (n <= k) {\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}\n\t\tlong seg = (((k + 1) * (k) / 2) - 1);\n\t\tseg += (2 - k);\n\t\tif (seg < n) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t// long sum = k;\n\t\t// long out = 0l;\n\t\tlong s = 1, f = k;\n\t\tlong mid = (s + f) / 2;\n\t\twhile (s + 1 < f) {\n\t\t\tlong seg_m = (((mid + k - 1) * (k - mid) / 2));\n\t\t\t// seg += (2 - mid);\n\t\t\t// long sum_m = seg - seg_m;\n\t\t\tif (seg_m >= n - 1) {\n\t\t\t\t// if (n - mid < out || out == 0) {\n\t\t\t\t// out = n - mid - 1;\n\t\t\t\t// }\n\t\t\t\ts = mid;\n\t\t\t} else\n\t\t\t\tf = mid;\n\t\t\tmid = (s + f) / 2;\n\t\t}\n\t\t// for (long i = k - 1; sum < n && i >= 2; i--) {\n\t\t// sum += i - 1;\n\t\t// out++;\n\t\t// // if (sum >= n)\n\t\t// // break;\n\t\t// }\n\t\tSystem.out.println(k - s);\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class PipelineRedo {\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tlong n = sc.nextLong() - 1;\n\t\tlong k = sc.nextInt() - 1;\n\t\t\n\t\tif(n==0){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}else if(n <= k){\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}else if(n > k*(k+1)/2){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t//n > k, and there exists a subset (1..k) = n\n\t\t//goal : sum( subset of (1...k) ) = n\n\t\t//obs: if exists a soln, it's always possible to push everything to the right-> t + left...k\n\t\t//so that t + left...k = n, so we just have to find the smallest left such that left..k <= n\n\t\tlong rightSum = k*(k+1)/2;\n\t\tlong lo = 1;\n\t\tlong hi = k;\n\t\twhile(lo < hi){\n\t\t\tlong mid = lo + (hi-lo+1)/2;\n\t\t\tlong val = rightSum - mid*(mid-1)/2;\n\t\t\t\n\t\t\tif(val <= n){\n\t\t\t\thi = mid -1;\n\t\t\t}else{\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t}\n\t\t//now lo points to the greatest left for which left..k > n\n\t\t//so lo+1 points to the smallest left for which left..k <= n\n\t\t//we still have an extra 't' to the left\n\t\tif(rightSum - (lo+1)*(lo)/2 == n){\n\t\t\tSystem.out.println(k - (lo+1) + 1);\n\t\t}else{\n\t\t\tSystem.out.println(1 + (k - (lo+1) + 1));\n\t\t}\n\t}\n\t\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", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B\n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tScanner in = new Scanner(System.in);\n\n\t\tlong n = in.nextLong();\n\t\tlong k = in.nextLong();\n\t\tif(n == 1)\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif(n <= k)\n\t\t{\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}\n\n\t\tlong lb = 2, ub = k;\n\t\tlong sum = ((k)*(k-1))/2;\n\t\tif(sum+1 < n)\n\t\t{\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\twhile(ub - lb > 1)\n\t\t{\n\t\t\tlong mid = (lb+ub)/2;\n\t\t\tlong s = ((mid-1)*(mid-2))/2;\n\t\t\tif(n - (sum-s+1) < 0)\n\t\t\t\tlb = mid;\n\t\t\telse\n\t\t\t\tub = mid;\n\t\t}\n\n\t\tlong rem = n - (sum - ((ub-1)*(ub-2))/2 + 1);\n\t\tlong res = k - ub + 1;\n\t\tif(rem == 0)\n\t\t{\n\t\t\tSystem.out.println(res);\n\t\t\treturn;\n\t\t}\n\t\trem++;\n\t\tif(!(rem >= 2 && rem < ub))\n\t\t{\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(res+1);\n\n\n\t}\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\npublic class palin {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner scan = new Scanner(System.in);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tlong n = in.nextLong() - 1;\n\t\tlong k = in.nextLong() - 1;\n\t\tif (n == 0) {\n\t\t\tout.print(\"0\");\n\t\t} else {\n\t\t\tif (k >= n) {\n\t\t\t\tout.print(\"1\");\n\t\t\t} else {\n\t\t\t\tif (k * (k + 1) / 2 < n) {\n\t\t\t\t\tout.print(\"-1\");\n\t\t\t\t} else {\n\t\t\t\t\tlong t = binsearch(n, k, 1, k);\n\t\t\t\t\tlong ans = k - t + 1;\n\t\t\t\t\tif (k * (k + 1) / 2 - t * (t - 1) / 2 != n)\n\t\t\t\t\t\tans++;\n\t\t\t\t\tSystem.out.println(ans);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static long binsearch(long n, long k, long from, long to) {\n\t\tif (from == to) {\n\t\t\treturn from;\n\t\t}\n\t\tlong mid = (from + to) / 2;\n\t\tif ((k * (k + 1)) / 2 - (mid * (mid - 1)) / 2 > n)\n\t\t\treturn binsearch(n, k, mid + 1, to);\n\t\telse\n\n\t\t\treturn binsearch(n, k, from, mid);\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}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class B implements Runnable {\n\n    // leave empty to read from stdin/stdout\n    private static final String TASK_NAME_FOR_IO = \"\";\n\n    // file names\n    private static final String FILE_IN = TASK_NAME_FOR_IO + \".in\";\n    private static final String FILE_OUT = TASK_NAME_FOR_IO + \".out\";\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tokenizer = new StringTokenizer(\"\");\n\n    public static void main(String[] args) {\n        new Thread(new B()).start();\n    }\n\n    private void solve() throws IOException {\n        long n = nextLong();\n        long k = nextLong();\n\n        n--;\n        k--;\n        long answer = 0;\n        while (n > 0 && k >= 1) {\n\n            if (k > 2000) {\n                long step1000 = (k + (k - 999)) * 500;\n                if (n - step1000 >= 0) {\n                    n -= step1000;\n                    answer += 1000;\n                    k -= 1000;\n                    continue;\n                }\n            }\n\n            if (n - k >= 0) {\n                n -= k;\n                answer++;\n            }\n\n            k--;\n            k = Math.min(n, k);\n        }\n\n        if (n == 0) {\n            out.println(answer);\n        } else {\n            out.println(-1);\n        }\n    }\n\n    public void run() {\n        long timeStart = System.currentTimeMillis();\n\n        boolean fileIO = TASK_NAME_FOR_IO.length() > 0;\n        try {\n\n            if (fileIO) {\n                in = new BufferedReader(new FileReader(FILE_IN));\n                out = new PrintWriter(new FileWriter(FILE_OUT));\n            } else {\n                in = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(new OutputStreamWriter(System.out));\n            }\n\n            solve();\n\n            in.close();\n            out.close();\n        } catch (IOException e) {\n            throw new IllegalStateException(e);\n        }\n        long timeEnd = System.currentTimeMillis();\n\n        if (fileIO) {\n            System.out.println(\"Time spent: \" + (timeEnd - timeStart) + \" ms\");\n        }\n    }\n\n    private String nextToken() throws IOException {\n        while (!tokenizer.hasMoreTokens()) {\n            String line = in.readLine();\n            if (line == null) {\n                return null;\n            }\n            tokenizer = new StringTokenizer(line);\n        }\n        return tokenizer.nextToken();\n    }\n\n    private int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    private BigInteger nextBigInt() throws IOException {\n        return new BigInteger(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}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\npublic class ehsan \n{\n\tpublic static BigInteger f(BigInteger m,BigInteger n){\n\t\tBigInteger s,l;\n\t\ts=n.multiply(m.add(BigInteger.valueOf(1)));\n\t\tl=m.multiply(m.add(BigInteger.valueOf(1)));\n\t\tl=l.divide(BigInteger.valueOf(2));\n\t\ts=s.subtract(l);\n\t\ts=s.subtract(m);\n\t\treturn s;\n\t}\n\tpublic static BigInteger bs(BigInteger a,BigInteger b,BigInteger n,BigInteger d){\n\t\tBigInteger c,e;\n\t\tc=a.add(b);\n\t\tc=c.divide(BigInteger.valueOf(2));\n\t\te=f(c,n);\n\t\tif(e.equals(d))\n\t\t\treturn c.add(BigInteger.valueOf(1));\n\t\tif(a.equals(b.add(BigInteger.valueOf(-1))))\n\t\t\treturn b.add(BigInteger.valueOf(1));\n\t\tif(e.compareTo(d)>0)\n\t\t\treturn bs(a,c,n,d);\n\t\treturn bs(c,b,n,d);\n\t}\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner sc = new Scanner(System.in);\n  \t\tBigInteger bi1 = sc.nextBigInteger();\n  \t\tBigInteger bi2 = sc.nextBigInteger();\n\t\tBigInteger i,n=bi2;\n\t\tBigInteger i2=BigInteger.valueOf(1);\n\t\tBigInteger sum=BigInteger.valueOf(0);\n\t\tif(bi1.compareTo(bi2)<0){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\telse if( bi1.compareTo(bi2) == 0 )\n\t\t{\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}\n\t\tbi2=((n.multiply(n.add(BigInteger.valueOf(1)))).divide(BigInteger.valueOf(2))).subtract(n.subtract(BigInteger.valueOf(1)));\n\t\tif(bi1.compareTo(bi2)>0)\n\t\t\tSystem.out.println(-1);\n\t\telse{\n\t\t\tSystem.out.println(bs(BigInteger.valueOf(0),n.add(BigInteger.valueOf(-2)),n,bi1));\n\t\t}\n  }\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class B {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tPipes pipes = new Pipes();\n\t\tpipes.solve();\n\t\tpipes.print();\n\t}\n\n}\n\nclass Pipes {\n\t\n\tPipes() {\n\t\tScanner scr = new Scanner(System.in);\n\t\tn = scr.nextLong();\n\t\tk = scr.nextLong();\n\t}\n\t\n\tlong bs(long nb, long nk) {\n\t\t\n\t\tlong left = 2;\n\t\tlong ls = (nk - left + 1) * (nk + left) / 2 - (nk - left);\n\t\tlong right = nk;\n\t\tlong rs = nk;\n\t\t\n\t\tif (nb > ls) {\n\t\t\treturn -1;\n\t\t}\n\t\t\t\t\n\t\tlong mid = left;\n\t\t\n\t\twhile (rs < ls){\n\t\t\tmid = (left + right)/2;\n\t\t\tlong ms = (nk - mid + 1) * (nk + mid) / 2 - (nk - mid);\n\t\t\tif (nb > ms) {\n\t\t\t\tright = mid;\n\t\t\t\trs = ms;\n\t\t\t}\n\t\t\telse if (nb < ms){\n\t\t\t\tleft = mid+1;\n\t\t\t\tls = (nk - left + 1) * (nk + left) / 2 - (nk - left);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tleft = mid;\n\t\t\t\tbreak;\n\t\t\t} \n\t\t\t\n\t\t}\n\t\t\n\t\treturn left;\n\t\t\n\t}\n\t\n\tvoid solve() {\n\t\tlong nn = n;\n\t\tlong kk = k; \n\t\tans = 0;\n\t\tlong ps = 1;\n\t\tlong add;\n\t\t\n\t\tif (n == 1) {\n\t\t\tans = 0;\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tnn = n - (ps - 1);\n\t\twhile (nn > kk){\n\t\t\tadd = bs(nn, kk);\n\t\t\tif (add == -1) {\n\t\t\t\tans = -1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tans = ans + (kk - add + 1);\n\t\t\t}\n\t\t\t\t\t\t\n\t\t\tlong addn = (kk - add + 1) * (kk + add) / 2 - (kk - add); \n\t\t\tps = ps - 1 + addn;\n\t\t\tif (ps == n)\n\t\t\t\treturn;\n\t\t\tnn = nn - (ps - 1);\n\t\t\tkk = add - 1;\n\t\t}\n\t\t\n\t\tif (nn > 0) {\n\t\t\tans++;\n\t\t}\n\t\t\n\t}\n\t\n\t\n\tvoid print() {\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tlong ans;\n\tlong n;\n\tlong k;\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n\tstatic long n, k;\n\n\tstatic long sum(long mid) {\n\t\tlong tmpSum = k * (k + 1) / 2;\n\t\tlong nsum = (mid - 1) * (mid) / 2;\n\t\treturn tmpSum - nsum;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tStringTokenizer sc = new StringTokenizer(br.readLine());\n\t\tn = Long.parseLong(sc.nextToken()) - 1;\n\t\tk = Long.parseLong(sc.nextToken()) - 1;\n\t\tif (n == 0)\n\t\t\tout.println(0);\n\t\telse if (sum(1) < n)\n\t\t\tout.println(-1);\n\t\telse {\n\t\t\tlong lo = 1;\n\t\t\tlong hi = k;\n\t\t\tlong mid;\n\t\t\twhile (lo < hi) {\n\t\t\t\tmid = (lo + hi) / 2;\n\t\t\t\tlong sum = sum(mid);\n\t\t\t\tif (n - sum < 0)\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\telse if (n - sum < mid) {\n\t\t\t\t\thi = mid;\n\t\t\t\t} else\n\t\t\t\t\thi = mid - 1;\n\t\t\t}\n\t\t\tout.println((k - lo + 1) + (n - sum(lo) == 0 ? 0 : 1));\n\t\t}\n\t\tbr.close();\n\t\tout.close();\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class B {\n\tpublic static BufferedReader in;\n\tpublic static PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tboolean showLineError = true;\n\t\tif (showLineError) {\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tsolve();\n\t\t\t} catch (Exception e) {\n\t\t\t} finally {\n\t\t\t\tout.close();\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic void debug(Object... os) {\n\t\tout.println(Arrays.deepToString(os));\n\t}\n\n\tprivate static void solve() throws IOException {\n\t\tString[] line = in.readLine().split(\" \");\n\t\tlong n = Long.parseLong(line[0]) - 1;\n\t\tlong k = Long.parseLong(line[1]) - 1;\n\t\tif (f(1, k) < n) {\n\t\t\tout.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (n == 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong lo = 0l;\n\t\tlong hi = k;\n\t\twhile (lo + 1l < hi) {\n\t\t\tlong m = (lo + hi) / 2l;\n\t\t\tlong f = f(k - m + 1, k);\n\t\t\tif (f < n) {\n\t\t\t\tlo = m;\n\t\t\t} else {\n\t\t\t\thi = m;\n\t\t\t}\n\t\t}\n\t\tout.println(hi);\n\n\t}\n\n\tprivate static long f(long lo, long hi) {\n\t\treturn (lo + hi) * (hi - lo + 1l) / 2l;\n\t}\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n//package pipeline;\n\nimport java.util.Scanner;\n\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        // TODO code application logic here\n        Scanner scan=new Scanner(System.in);\n        long n=scan.nextLong(),k=scan.nextLong();\n        if(n>((k-2)*(k-1))/2+k){\n            System.out.println(\"-1\");\n        }\n else if(n==1){\n            System.out.println(\"0\");\n\n }\n else if(n<=k&&n>1){\n            System.out.println(\"1\");\n }\n else{\n            n-=k;\n            long start=k-2;\n            long x;\n            long left=1,right=k-2;\n           // System.out.println(left+\" \"+right);\n            while(left<=right){\n            x=(left+right)/2;\n            //    System.out.println(x);\n                \n            if(n>cumSum(x, start)){\n            left=x+1;\n          //  System.out.println(\"if\");\n            }\n else if(n<cumSum(x-1, start)){\n right=x-1;\n            //    System.out.println(\"else if\");\n }\n else{\n                System.out.println(1+x);\n                break;\n }\n            }\n\n\n }\n\n    }\n    public static long cumSum(long x,long start){\n    return (x*(2*start+1-x))/2;\n    }\n\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n    public static void main (String[] args) throws IOException {\n        boolean online = \"true\".equals(System.getProperty(\"ONLINE_JUDGE\"));\n        if (online) {\n            in = new InputReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n        }\n        else {\n            in = new InputReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(new File(\"output.txt\"));\n        }\n        \n        new Solution().run();\n        \n        out.close();\n    }\n    \n    long sum (int x) {\n        return x * 1l * (x+1) / 2;\n    }\n    \n    int bins (long n, int k) {\n        int l = 1,\n            r = k;\n        while (l < r) {\n            int w = (l+r)/2;\n            long s = sum(k) - sum(w-1);\n            if (s == n)\n                return w;\n            if (s < n)\n                r = w;\n            else\n                l = w+1;\n        }\n        return l;\n    }\n    \n    private void run () {\n        long n = in.nextLong();\n        int k = in.nextInt();\n        if (n == 1) {\n            out.println(0);\n            return;\n        }\n        if (1 + sum(k-1) < n) {\n            out.println(-1);\n            return;\n        }\n        int c = bins(n-1,k-1);\n        if (1 + sum(k-1) - sum(c-1) == n)\n            out.println(k-c);\n        else\n            out.println(k-c+1);\n    }\n    \n    private static InputReader in;\n    private static PrintWriter out;\n}\n\nclass InputReader {\n    public InputReader (Reader r) {\n        buff = new BufferedReader(r);\n        try {\n            str = new StringTokenizer(buff.readLine());\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    public String next () {\n        while (!str.hasMoreTokens())\n            try {\n                str = new StringTokenizer(buff.readLine());\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n        return str.nextToken();\n    }\n    \n    public int nextInt () {\n        return Integer.parseInt(this.next());\n    }\n    \n    public long nextLong () {\n        return Long.parseLong(this.next());\n    }\n    \n    private static BufferedReader buff;\n    private static StringTokenizer str;\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main\n    {\n    public static void main(String args[]) throws IOException\n        {\n        Scanner c=new Scanner(System.in);\n        PrintWriter out=new PrintWriter(System.out);\n        long N=c.nextLong()-1;\n        long K=c.nextLong()-1;\n        long tot=(K*(K+1))/2;\n        //System.out.println(tot);\n        if(N>tot)\n            {\n            System.out.println(-1);\n            return;\n            }\n        long lo=1;\n        long hi=K;\n        while(hi-lo>=10)\n            {\n            long mid=(hi+lo)/2;\n            //maximum outlets using mid pipes\n            long sum=(mid*(mid-1))/2;\n            long left=mid*K-sum;\n            if(left>=N)\n                hi=mid+1;\n            else\n                lo=mid-1;\n            }\n        for(int num=(int)lo-1000;num<lo+1000;num++)\n            {\n            if(num>=0)\n                {\n                long sum=((long)num*(num-1))/2;\n                long left=(long)num*K-sum;\n                if(left>=N)\n                    {\n                    System.out.println(num);\n                    return;\n                    }\n                }\n            }\n        out.close();\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        {\n        this.stream=stream;\n        }\n\n    public int read()\n        {\n        if(numChars==-1)\n            throw new InputMismatchException();\n        if(curChar>=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 boolean isSpaceChar(int c)\n        {\n        if(filter!=null)\n            return filter.isSpaceChar(c);\n        return isWhitespace(c);\n        }\n\n    public static boolean isWhitespace(int c)\n        {\n        return c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n        }\n\n    public char readCharacter()\n        {\n        int c=read();\n        while (isSpaceChar(c))\n            c=read();\n        return (char) c;\n        }\n\n    public interface SpaceCharFilter\n        {\n        public boolean isSpaceChar(int ch);\n        }\n    }\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\npublic class Main {\n\n   long k;\n\n   private void solve() throws IOException {\n      long n = nl();\n      k = nl();\n\n      if (n == 1) {\n         prln(0);\n         return;\n      }\n\n      if (n <= k) {\n         prln(1);\n         return;\n      }\n\n      long l = 1, r = k - 1;\n      long mid = (l + r + 1) / 2;\n      long old = -1;\n\n      while (old != mid) {\n         old = mid;\n\n         if (take(mid) >= n)\n            r = mid;\n         if (take(mid) < n)\n            l = mid;\n\n         mid = (l + r + 1) / 2;\n      }\n\n      if (mid >= k || mid <= 0) {\n         prln(-1);\n         return;\n      }\n\n      if (take(mid) == n) {\n         prln(mid);\n         return;\n      }\n\n      if (mid == k - 1)\n         prln(-1);\n      else\n         if (take(mid) < n)\n            prln(mid + 1);\n         else\n            prln(mid);\n\n   }\n\n   long take(long t) {\n      return k * t - t * (t - 1) / 2 - (t - 1);\n   }\n\n   public static void main(String[] args) {\n      new Main().run();\n   }\n\n   public void run() {\n      try {\n         if (isFileIO) {\n            pw = new PrintWriter(new File(\"output.out\"));\n            br = new BufferedReader(new FileReader(\"input.in\"));\n         } else {\n            pw = new PrintWriter(System.out);\n            br = new BufferedReader(new InputStreamReader(System.in));\n         }\n         solve();\n         pw.close();\n         br.close();\n      } catch (IOException e) {\n         System.err.println(\"IO Error\");\n      }\n   }\n\n   private int[] nia(int n) throws IOException {\n      int arr[] = new int[n];\n      for (int i = 0; i < n; ++i)\n         arr[i] = Integer.parseInt(nextToken());\n      return arr;\n   }\n\n   private int[] niam1(int n) throws IOException {\n      int arr[] = new int[n];\n      for (int i = 0; i < n; ++i)\n         arr[i] = Integer.parseInt(nextToken()) - 1;\n      return arr;\n   }\n\n   private long[] nla(int n) throws IOException {\n      long arr[] = new long[n];\n      for (int i = 0; i < n; ++i)\n         arr[i] = Long.parseLong(nextToken());\n      return arr;\n   }\n\n   private void pr(Object o) {\n      pw.print(o);\n   }\n\n   private void prln(Object o) {\n      pw.println(o);\n   }\n\n   private void prln() {\n      pw.println();\n   }\n\n   int ni() throws IOException {\n      return Integer.parseInt(nextToken());\n   }\n\n   long nl() throws IOException {\n      return Long.parseLong(nextToken());\n   }\n\n   double nd() throws IOException {\n      return Double.parseDouble(nextToken());\n   }\n\n   private String nextToken() throws IOException {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n         tokenizer = new StringTokenizer(br.readLine());\n      }\n\n      return tokenizer.nextToken();\n   }\n\n   // private void qsort(int a[]) {\n   // Random rand = new Random(271828182l);\n   // qsort(a, 0, a.length, rand);\n   // }\n   //\n   // private void qsort(int a[], int l, int r, Random rand) {\n   // if (r - l <= 1)\n   // return;\n   //\n   // if (r - l == 2) {\n   // if (a[r - 1] < a[l]) {\n   // int t = a[r - 1];\n   // a[r - 1] = a[l];\n   // a[l] = t;\n   // }\n   //\n   // return;\n   // }\n   //\n   // int x = a[rand.nextInt(r - l) + l];\n   // int i = l, j = r - 1;\n   // while (i < j) {\n   // while (a[i] < x)\n   // ++i;\n   // while (a[j] > x)\n   // --j;\n   // if (i < j) {\n   // int t = a[i];\n   // a[i] = a[j];\n   // a[j] = t;\n   // ++i;\n   // --j;\n   // }\n   // }\n   //\n   // qsort(a, l, j + 1, rand);\n   // qsort(a, i, r, rand);\n   // }\n\n   private BufferedReader br;\n   private StringTokenizer tokenizer;\n   private PrintWriter pw;\n   private final boolean isFileIO = false;\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class B2 {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        Scanner scan = new Scanner(System.in);\n        BigInteger n = new BigInteger(scan.next());\n        BigInteger k = new BigInteger(scan.next());\n        BigInteger a = k.subtract(bi(1));\n        BigInteger lim = k.multiply(a).divide(bi(2));\n        lim = lim.add(bi(1));\n        //System.out.println(\"lim: \"+lim);\n        if (n.compareTo(lim)>0){\n            System.out.println(-1);\n        }\n        else {\n            if (n.equals(1)){\n                System.out.println(0);\n            }\n            else {\n                BigInteger remain2 = lim.subtract(n).add(bi(1));\n                remain2 = remain2.multiply(bi(2));\n                //System.out.println(remain2);\n                double temp = remain2.doubleValue();\n                //System.out.println(temp);\n                long flr = (long)Math.sqrt(temp);\n                //System.out.println(flr);\n                BigInteger flr2 = bi(flr);\n                BigInteger rnd2 = remain2.subtract(flr2.multiply(flr2));\n                long rnd = remain2.longValue()-flr*flr;\n                //System.out.println(\"rnd \"+rnd);\n                /*\n                if (rnd<=flr){\n                    System.out.println(k.intValue()-flr);\n                }\n                else {\n                    System.out.println(k.intValue()-(flr+1));\n                }\n                */\n                if (rnd2.compareTo(flr2)<=0){\n                    System.out.println(k.subtract(flr2) );\n                }\n                else {\n                    System.out.println(k.subtract(flr2.add(bi(1) ) ) );\n                }\n            }\n        }\n    }\n    public static BigInteger bi(int n1){\n        return new BigInteger(\"\"+n1);\n    }\n    public static BigInteger bi(long n1){\n        return new BigInteger(\"\"+n1);\n    }\n\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class B2 {\n\tpublic static void main (String args[]){\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tlong k = in.nextLong();\n\t\tlong upn = k;\n\t\tlong tmp=upn;\n\t\tif(n==1){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif(n<=k){\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}\n\t\t//---\n\t\tif(!bS(n, k, upn)){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tboolean flag = false;\n\t\t\twhile(bS(n, k, upn)){\n\t\t\t\ttmp = upn;\n\t\t\t\tflag = true;\n\t\t\t\tupn=5*upn/6;\n\t\t\t\tif(tmp==upn)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlong ans = tmp;\n\t\t\tif(!flag)\n\t\t\t\tupn=0;\n\t\t\tfor(int i = (int)tmp;i>=upn;i--){\n\t\t\t\tif(bS(n, k, i)){\n\t\t\t\t\tans=i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t}\n\t\n\tstatic boolean bS(long key,long k ,long n) \n\t    {\n\t\tlong pipe = (n * (k-n+k+1))/2;\n\t\tpipe = pipe - n+1;\n\t         if(pipe>=key){\n\t        \t return true;\n\t         }\n\t         else\n\t        \t return false;\n\t   }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n\tlong sum ( long n ) { return (n*(n+1))/2; }\n\n\tpublic void solve ( ) throws Exception\n\t{\n\t\tScanner in = new Scanner ( System.in );\n\t\tlong n = in.nextLong()-1;\n\t\tlong k = in.nextLong()-1;\n\t\t\n\t\tlong lo = 0, hi = k, mi;\n\t\twhile ( lo < hi )\n\t\t{\n\t\t\tmi = ( lo + hi ) / 2;\n\t\t\tif ( sum(k)-sum(k-mi-1) <= n ) lo = mi+1;\n\t\t\telse hi = mi;\n\t\t}\n\t\t\n\t\tlong ans = lo;\n\t\tn -= ( sum(k) - sum(k-ans) );\n\t\tk -= ans;\n\n\t\tif ( n > k ) println ( \"-1\" );\n\t\telse if ( n == 0 ) println ( ans );\n\t\telse println ( (ans+1) );\n\t}\n\t\n\tpublic static void main ( String[] args ) throws Exception { (new Main()).solve(); }\n\tpublic static void print ( Object o ) { System.out.print ( o ); }\n\tpublic static void println ( Object o ) { System.out.println ( o ); }\n\tpublic static void println ( ) { System.out.println ( ); }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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 dy\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\nclass TaskB {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        long N = in.nextLong();\n        int K = in.nextInt();\n        long pipes = 1;\n        if(N == 1){\n            out.println(0);return;\n        }\n        long left = 0, right = K - 1, find = -1;\n        while (left <= right){\n            long mid = (left + right) / 2;\n            if(mid * mid + (1 - 2 * K) * mid + 2 * (N - 1) <= 0){\n                find = mid;\n                right = mid - 1;\n            }\n            else\n                left = mid + 1;\n        }\n        out.println(find);\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class B{\n    public static void main(String args[]){\n        Scanner input = new Scanner(System.in);\n        long n = input.nextLong();\n        long k = input.nextLong();\n        System.out.println(solve(n, k));\n        input.close();\n    }\n    \n    public static long solve(long n, long k){\n        long dis = n - k;\n        if(n == 1)\n            return 0;\n        if((((k - 2) * ((k - 2) + 1)) / 2) + 1 <= dis)\n            return -1;\n        if(k >= n)\n            return 1;\n        //\n        long ans = 2;\n        long now = (((k - 2) * ((k - 2) + 1)) / 2) + 1 + k;\n        long dist = Math.abs(now - n);\n        long delta = 1 + 8 * dist;\n        double ret = (1 + Math.sqrt(delta)) / 2;\n        //\n        now = (((k - 2) * ((k - 2) + 1)) / 2) + 1 + k;\n        dist = Math.abs(now - k);\n        delta = 1 + 8 * dist;\n        double nret = (1 + Math.sqrt(delta)) / 2;\n        //\n        double back = nret - ret;\n        ans = (long) back;\n        return ans + 2;\n    }\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        String s = sc.nextLine();\n        String[] info = s.split(\" \");\n        long n = Long.parseLong(info[0]);\n        long k = Long.parseLong(info[1]);\n        sc.close();\n\n        long maximum = k * (k - 1) / 2 + 1;\n        if (n == 1)\n            System.out.println(0);\n        else if (n > maximum)\n            System.out.println(-1);\n        else {\n            long left = 0, right = k - 1;\n            while (left + 1 < right) {\n                long mid = (right + left) / 2;\n                if (mid * (k - 1 + k - mid) / 2 + 1 >= n)\n                    right = mid;\n                else\n                    left = mid;\n            }\n            System.out.println(right);\n        }\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class SolutionB {\n   BufferedReader in;\n   StringTokenizer str;\n   PrintWriter out;\n   String SK;\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   int nextInt() throws IOException {\n      return Integer.parseInt(next());\n   }\n   double nextDouble() throws IOException {\n      return Double.parseDouble(next());\n   }\n   long nextLong() throws IOException {\n      return Long.parseLong(next());\n   }\n   char[] charArray() throws IOException{\n      return next().toCharArray();\n   }\n   public static void main(String[] args) throws IOException {\n      new SolutionB().run();\n   }\n   void run() throws IOException {\n      in = new BufferedReader(new InputStreamReader(System.in));\n      out = new PrintWriter(System.out);\n      //in = new BufferedReader(new FileReader(\"input.txt\"));\n      //out = new PrintWriter(\"output.txt\");\n      solve();\n      out.close();\n   }\n   void solve() throws IOException {\n      //out.println(Long.MAX_VALUE);\n      long n = nextLong();\n      long k = nextLong();\n      long m=num1(k);\n      if(m<n){\n         out.println(-1);\n         return;\n      }\n      if(m==n){\n         out.println(k-1);\n         return;\n      }\n      long ans=binS(n,k);\n      out.println(k-ans);\n   }\n   long num1(long k){\n      long r=k*(k+1)/2-1;\n      r=r-(k-2);\n      return r;\n   }\n   long num2(long k){\n      return num1(k)-1;\n   }\n   long binS(long n, long k) {\n      long start, end, mid;\n      start = 2;\n      end = k;\n      long ret=-1;\n      while (start <= end) {\n         mid = (start + end) / 2;\n         if (num1(k)-num2(mid) == n) {\n            return mid;\n         } else if (num1(k)-num2(mid) < n) {\n            end = mid - 1;\n         } else {\n            ret=mid;\n            start = mid + 1;\n         }\n      }\n      return ret;\n   }\n}\n   \n\n\n\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class TaskB {\n    static BufferedReader in = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer str;\n    static String SK;\n\n    static 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    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    public static void main(String[] args) throws IOException {\n        long n = nextLong();\n        int k = nextInt();\n        if (n == 1) {\n            System.out.println(0);\n            return;\n        }\n        long sum = (((2 + (long) k)) * ((long) k - 1)) / 2 - ((long) k - 2);\n        if (n > sum) {\n            System.out.println(-1);\n            return;\n        } else if (n <= k) {\n            System.out.println(1);\n            return;\n        }\n\n        long cnt = 0;\n        long sum2 = 0;\n        int index = binSearch(2, k, k, n);\n\n        sum2 = (((long) (index) + k) * (long) (k - index + 1)) / 2 - (long) (k - index);\n        cnt = k - index + 1;\n        if (sum2 == n) {\n            System.out.println(cnt);\n            return;\n        }\n        if (sum2 > n)\n            for (int kk = index; kk <= k; kk++) {\n                sum2 = (((long) (kk) + k) * (long) (k - kk + 1)) / 2 - (long) (k - kk);\n                cnt--;\n                if (sum2 <= n) {\n                    System.out.println(cnt + 1);\n                    return;\n                }\n            }\n        else {\n            for (int kk = index - 1; kk >= 2; kk--) {\n                sum2 = (((long) (kk) + k) * (long) (k - kk + 1)) / 2 - (long) (k - kk);\n                cnt++;\n                if (sum2 >= n) {\n                    System.out.println(cnt);\n                    return;\n                }\n            }\n        }\n        System.out.println(-1);\n        return;\n    }\n\n    static int binSearch(int l, int r, int k, long n) {\n        while (true) {\n            int mid = l + (r - l) / 2;\n            long sum2 = (((long) (mid) + k) * (long) (k - mid + 1)) / 2 - (long) (k - mid);\n            if (l >= r || sum2 == n) {\n                return mid;\n            } else if (sum2 > n) {\n                l = mid + 1;\n            } else if (sum2 < n) {\n                r = mid;\n            }\n        }\n    }\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Contest176B {\n    public static void main(String[] args) throws IOException{\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextLong();\n        int k = sc.nextInt();\n        \n        if( ((long)k * (long)(k + 1))/2 - 1 - (k - 2) < n){\n            System.out.println(-1);\n            return;\n        }\n        \n        if(n == 1) {\n            System.out.println(0);\n            return;\n        }\n        \n        if(n <= k) {\n            System.out.println(1);\n            return;\n            \n        }\n        \n        int ans = rek(2, k, n, k);\n        \n        System.out.println(ans);\n    }\n    \n    private static int rek(int s, int e, long n, int k){\n        //System.out.println(s + \" \" + e );\n        if(s == e){\n            return k - s + 1;\n        }\n        if(s + 1 == e){\n            if(sum(e, k) >= n) return k - e + 1;\n            return k - s + 1;\n        }\n\n        int m = (s + e)/2;\n        \n        long ans = sum(m, k);\n        \n        if(ans == n) return k - m + 1;\n        if(ans < n) return rek(s, m - 1, n, k);\n        else return rek(m , e, n, k); \n        \n        \n    }\n    private static long sum(int a, int b ){\n        long sum1 = ((long)a * (long)(a - 1))/2;\n        long sum2 = ((long)b * (long)(b + 1))/2;\n        int numelement = b - a + 1;\n        \n        return sum2 - sum1 - (numelement - 1);\n    }\n    \n\n    \n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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 Saul\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\nclass TaskB {\n  public void solve(int testNumber, Scanner in, PrintWriter out) {\n    long n = in.nextLong() ;\n    int k = in.nextInt();\n    long top = 1L * k * (k+1) / 2L - k + 1;\n\n    if ( n == 1L ){\n      out.print(0);\n      return;\n    }\n\n    if ( n > top ){\n      out.print(-1);\n      return;\n    }\n\n    int ans = 0;\n    if ( n > 0 ){\n      ++ans;\n      n -= k;\n      k -= 2;\n    }\n\n    while ( n > 0 ){\n      ++ans;\n      n -= k;\n      k--;\n    }\n    out.print(ans);\n  }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\n/**\n * Created with IntelliJ IDEA.\n * User: ira\n * Date: 3/23/13\n * Time: 12:19 PM\n */\npublic class B2 {\n\n        public static void main(String[] args) throws IOException {\n            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n            String line = reader.readLine();\n            StringTokenizer tokenizer = new StringTokenizer(line);\n            long n = Long.parseLong(tokenizer.nextToken());\n            long k = Long.parseLong(tokenizer.nextToken());\n            if (n == 1){\n                System.out.println(\"0\");\n                return;\n            }\n\n            if (n <= k){\n                System.out.println(\"1\");\n                return;\n            }\n            long first = 0;\n            long end  = k;\n            long mid;\n\n            while (first < end){\n                mid = first + (end - first)/2;\n                if (is_exist(n, k , mid - 1)){\n                    end = mid;\n                } else {\n                    first = mid + 1;\n                }\n            }\n            if (is_exist(n, k, end - 1)){\n                System.out.println((end ));\n                return;\n            }\n            System.out.println(\"-1\");\n            return;\n\n        }\n\n    static boolean is_exist(long n, long k, long x){\n        long res = n - (k - 1 + k - x)* (k - 1 - (k - x) + 1)/2;\n        if (res <= k - x ){\n            return true;\n        }\n        return false;\n    }\n\n\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class CodeforcesRound176B {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner  kde =new Scanner (System.in);\n\t\tLong n = kde.nextLong(); //\u0434\u043e\u043c\u0430  \u0438 \u043a\u043e\u043b \u0442\u0440\u0443\u0431 \n\t\tLong k = kde.nextLong();  // \u0440\u0430\u0437\u0432\u0435\u0442\u043b\u0438\u0442\u0435\u043b\u0438 \n\t\tif(((k-1)*(k-2)+2*k)<(n*(long)2))\n\t\t{\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\t\n\t\tLong a,b;\n\t\t if(n==1)\n\t\t {\n\t\t\t System.out.println(0);\n\t\t\t return;\n\t\t }\n\t\t\n\t\t if(k>=n)\n\t\t {\n\t\t\t System.out.println(1);\n\t\t\t return;\n\t\t }\n\t\t else\n\t\t {\n\t\t\ta=(long)2;\n\t\t\tb=k-1;  \n\t\t }\t \n\t\t boolean flag =false;\n\t\twhile(true)\n\t\t{\n\t\t\tif(a>=b)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\n\t\t\t}\n\t\t\t long\tc =(a+b)/2;\n\t\t\t if(2*(k-c+1)+(k-1+k-c+1)*(c-1)<(n*2)) \n\t\t\t {\n\t\t\t\t a=c+1;\n\t\t\t }\n\t\t\t else\n\t\t\t {\n\t\t\t\t b=c;\n\t\t\t }\t\n\t\t\t flag=true;\n\t\t}\n\t\tif(flag==true )\n\t\t{\n\t\t\tSystem .out.println(a);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem .out.println(a);\t\n\t\t}\t\n\n\t\t\n\t\t\n\t}\n\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\npublic class ehsan \n{\n\tpublic static BigInteger f(BigInteger m,BigInteger n){\n\t\tBigInteger s,l;\n\t\ts=n.multiply(m.add(BigInteger.valueOf(1)));\n\t\tl=m.multiply(m.add(BigInteger.valueOf(1)));\n\t\tl=l.divide(BigInteger.valueOf(2));\n\t\ts=s.subtract(l);\n\t\ts=s.subtract(m);\n\t\treturn s;\n\t}\n\tpublic static BigInteger bs(BigInteger a,BigInteger b,BigInteger n,BigInteger d){\n\t\tBigInteger c,e;\n\t\tc=a.add(b);\n\t\tc=c.divide(BigInteger.valueOf(2));\n\t\te=f(c,n);\n\t\tif(e.equals(d))\n\t\t\treturn c.add(BigInteger.valueOf(1));\n\t\tif(a.equals(b.add(BigInteger.valueOf(-1))))\n\t\t\treturn b.add(BigInteger.valueOf(1));\n\t\tif(e.compareTo(d)>0)\n\t\t\treturn bs(a,c,n,d);\n\t\treturn bs(c,b,n,d);\n\t}\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner sc = new Scanner(System.in);\n  \t\tBigInteger bi1 = sc.nextBigInteger();\n  \t\tBigInteger bi2 = sc.nextBigInteger();\n\t\tBigInteger i,n=bi2;\n\t\tBigInteger i2=BigInteger.valueOf(1);\n\t\tBigInteger sum=BigInteger.valueOf(0);\n\t\tif(bi1.compareTo(bi2)<0){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif(bi1.compareTo(bi2)==0){\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}\n\t\tbi2=((n.multiply(n.add(BigInteger.valueOf(1)))).divide(BigInteger.valueOf(2))).subtract(n.subtract(BigInteger.valueOf(1)));\n\t\tif(bi1.compareTo(bi2)>0)\n\t\t\tSystem.out.println(-1);\n\t\telse{\n\t\t\tSystem.out.println(bs(BigInteger.valueOf(0),n.add(BigInteger.valueOf(-2)),n,bi1));\n\t\t}\n  }\n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "/**\n * Created with IntelliJ IDEA.\n * User: yuantian\n * Date: 3/24/13\n * Time: 2:18 AM\n * Copyright (c) 2013 All Right Reserved, http://github.com/tyuan73\n */\n\nimport java.util.*;\n\npublic class Pipeline {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n\n        long n = in.nextLong();\n        long k = in.nextLong();\n\n        if (n == 1) {\n            System.out.println(0);\n            return;\n        }\n        if (k >= n) {\n            System.out.println(1);\n            return;\n        }\n\n        long total = (k + 2) * (k - 1) / 2 - (k - 2);\n        if (total < n) {\n            System.out.println(-1);\n            return;\n        }\n\n        /**\n         * non-binary search version, O(n)\n         * it will failed because of \"over time limit erro\" on this case:\n         *  499999998500000001 1000000000   => 999955279\n         *\n         total = 1;\n         for(int i = (int)k; i >= 2; i--) {\n         total += i - 1;\n         if(total >= n) {\n         System.out.println(k-i+1);\n         return;\n         }\n         }\n         */\n\n        /**\n         * binary search search version. O(lgn)\n         */\n        int i = 2, j = (int) k;\n        while (i < j) {\n            int m = (i + j + 1) / 2;\n            total = (k + m) * (k - m + 1) / 2 - (k - m);\n            if (total < n)\n                j = m - 1;\n            else\n                i = m;\n        }\n        System.out.println(k - i + 1);\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Scanner;\n\npublic class TC\n{\n    static long N;\n    static int k;\n    static long WHOLESUM;\n    \n    static long SUM( long k )\n    {\n        long res=k*( k+1 )/2;\n        return res-1;\n    }\n    \n    static long returnPipes( int mid )\n    {\n        long not=SUM( mid-1 );\n        long totpipes=WHOLESUM-not;\n        int number=k-mid+1;\n        long res=totpipes-number+1;\n        return res;\n    }\n    \n    static long binarySearch( int lo, int hi )\n    {\n        int res=Integer.MAX_VALUE;\n        int val=0;\n        while( lo <= hi )\n        {\n            int mid=( lo+hi )/2;\n            long cnt=returnPipes( mid );\n            val=k-mid+1;;\n          \n            if( cnt  < N )\n            {\n                hi=mid-1;\n                continue;\n            }\n            else\n            {\n                res=Math.min( val, res );\n                lo=mid+1;\n            }\n        }\n        \n        if( res==Integer.MAX_VALUE )\n            return -1;\n        else\n            return res;\n        \n    }\n    \n\n    public static void main( String[] args ) throws IOException\n    {\n        Scanner s=new Scanner( System.in );\n        N=s.nextLong();\n        k=s.nextInt();\n        WHOLESUM=SUM( k );\n        if( N<=1 )\n            System.out.println(0 );\n        else\n            System.out.println( binarySearch( 2, k ) );\n    }\n    \n    \n}", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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 Dzmitry Paulenka\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\nclass TaskB {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        long n = in.nextLong();\n        long k = in.nextLong();\n        if (n == 1) {\n            out.println(0);\n            return;\n        }\n        if (k * (k - 1) < 2 * (n - 1)) {\n            out.println(-1);\n            return;\n        }\n\n        long sq2 = 4 * k * k - 4 * k + 1 - 4 * (2 * n - 2);\n        long km = Math.max(2, (long) ((Math.sqrt(sq2) + 3) / 2.0) - 3);\n        while (((km + k - 2)*(k - km + 1) >= 2*(n-1))) {\n            ++km;\n        }\n        out.println(k - km + 2);\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.util.Locale;\nimport java.util.Scanner;\n\npublic class PipelineSolver {\n\n    private long n;\n\n    private long k;\n\n    public static void main(String[] args) {\n        PipelineSolver solver = new PipelineSolver();\n\n        solver.readData();\n        int solution = solver.solve();\n        solver.print(solution);\n    }\n\n    private int gcd(int a, int b) {\n        return b == 0 ? a : gcd(b, a % b);\n    }\n\n    private int lcm(int a, int b) {\n        return a * b / gcd(a, b);\n    }\n\n    private void print(int[] values) {\n        StringBuilder builder = new StringBuilder();\n\n        for (int value : values) {\n            builder.append(value);\n            builder.append(\" \");\n        }\n\n        print(builder);\n    }\n\n    private void print(Object value) {\n        System.out.println(value);\n    }\n\n    private void print(boolean value) {\n        System.out.println(value ? \"YES\" : \"NO\");\n    }\n\n    private void print(int value) {\n        System.out.println(value);\n    }\n\n    private void print(long value) {\n        System.out.println(value);\n    }\n\n    private void print(double value) {\n        System.out.printf(Locale.ENGLISH, \"%.10f\", value);\n    }\n\n    private int[] getDigits(int number) {\n        int[] digits = new int[10];\n        int index = digits.length - 1;\n        int digitsCount = 0;\n\n        while (number > 0) {\n            digits[index] = number % 10;\n            number /= 10;\n            index--;\n            digitsCount++;\n        }\n\n        int[] result = new int[digitsCount];\n\n        System.arraycopy(digits, digits.length - digitsCount, result, 0, digitsCount);\n\n        return result;\n    }\n\n    private int[] readArray(Scanner scanner, int size) {\n        int[] result = new int[size];\n\n        for (int i = 0; i < size; i++) {\n            result[i] = scanner.nextInt();\n        }\n\n        return result;\n    }\n\n    private void readData() {\n        Scanner scanner = new Scanner(System.in);\n\n        n = scanner.nextLong();\n        k = scanner.nextLong();\n    }\n\n    private int solve() {\n\n        if (n == 1) {\n            return 0;\n        }\n        if (n <= k) {\n            return 1;\n        }\n        int result;\n        long l;\n\n        long d = (5 - 2 * k) * (5 - 2 * k) - 4 * (2 * n - 4 * k + 4);\n        if (d < 0)\n        {\n            result = -1;\n        } else {\n            l = Math.min(Math.max((int)((2 * k - 3 - Math.sqrt(d)) / 2), 0), Math.max((int)((2 * k - 3 + Math.sqrt(d)) / 2), 0));\n\n            long difference = n - k * (l + 1) + l * (l + 3) / 2;\n\n            if (l > k - 2) {\n                result = -1;\n            } else if (l == k - 2) {\n                result = difference == 0 ? (int) (l + 1) : -1;\n            } else {\n                result = (int) (l + 1 + (difference == 0 ? 0 : 1));\n            }\n        }\n\n        return result;\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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 Dzmitry Paulenka\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\nclass TaskB {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        long n = in.nextLong();\n        long k = in.nextLong();\n        if (n == 1) {\n            out.println(0);\n            return;\n        }\n        if (k * (k - 1) < 2 * (n - 1)) {\n            out.println(-1);\n            return;\n        }\n\n        long sq2 = 4 * k * k - 4 * k + 1 - 4 * (2 * n - 2);\n        double sqrt = Math.sqrt(sq2);\n        long sq = (long) sqrt;\n        if ((sq + 1) * (sq + 1) == sq2) {\n            sq = sq + 1;\n        } else if ((sq - 1) * (sq - 1) == sq2) {\n            sq = sq - 1;\n        }\n\n        if (sq*sq == sq2) {\n            long kmin = (sq + 3) / 2;\n            out.println(k - kmin + 1);\n        } else {\n            long km = Math.max(2, (long) ((sqrt + 3) / 2.0) - 2);\n            while (((km + k - 2)*(k - km + 1) >= 2*(n-1))) {\n                ++km;\n            }\n            out.println(k - km + 2);\n        }\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Long.*;\nimport static java.lang.Character.*;\n\n@SuppressWarnings(\"unused\")\npublic class round176B {\n    static BufferedReader br = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer st = new StringTokenizer(\"\");\n\n    static int nextInt() throws Exception {\n        return Integer.parseInt(next());\n    }\n\n    static String next() throws Exception {\n        while (true) {\n            if (st.hasMoreTokens()) {\n                return st.nextToken();\n            }\n            String s = br.readLine();\n            if (s == null) {\n                return null;\n            }\n            st = new StringTokenizer(s);\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        long n = parseLong(next());\n        long k = parseLong(next());\n        if(n == 1){\n            System.out.println(0);\n            return;\n        }\n        if (n <= k) {\n            System.out.println(1);\n            return;\n        }\n        if ((((k * (k + 1)) / 2) - 1) - (k - 2) < n) {\n            System.out.println(-1);\n        } else {\n            long lo = 1;\n            long hi = k + 1;\n            int best = Integer.MAX_VALUE;\n            while (lo < hi) {\n                long mid = lo + ((hi - lo) / 2);\n                long first = ((mid * (2 + (2 + (mid - 1)))) / 2) - (mid - 1);\n                long last = ((mid * (k - mid + 1 + k)) / 2) - (mid - 1);                \n                if (n < first) {\n                    hi = mid;\n                } else {\n                    if (n >= first && n <= last) {\n                        hi = mid;\n                        best = min(best, (int) mid);\n                    } else\n                        lo = mid + 1;\n                }\n            }\n            System.out.println(best);\n        }\n    }\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "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\n// Pipeline\n// 2013/03/23\npublic class P287B{\n\tScanner sc=new Scanner(System.in);\n\n\tlong n, k;\n\n\tvoid run(){\n\t\tn=sc.nextLong();\n\t\tk=sc.nextLong();\n\t\tsolve();\n\t}\n\n\tvoid solve(){\n\t\tlong left=-1, right=k+1;\n\t\tfor(; right-left>1;){\n\t\t\tlong m=(left+right)/2;\n\t\t\tlong ub=k*(k+1)/2-(k-m)*(k-m+1)/2-(m-1);\n\t\t\tif(ub>=n){\n\t\t\t\tright=m;\n\t\t\t}else{\n\t\t\t\tleft=m;\n\t\t\t}\n\t\t}\n\t\tprintln(\"\"+(right>k?-1:right));\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tpublic static void main(String[] args){\n\t\tLocale.setDefault(Locale.US);\n\t\tnew P287B().run();\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tlong n = sc.nextLong();\n\t\tint k = sc.nextInt();\n\t\t\n\t\tif(n==1){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tn=n-1;\n\t\tint count = 0;\n\t\tlong nextK = k-1;\n\t\twhile(true){\n\t\t\t//System.out.println(\"n = \" + n);\n\t\t\t\n\t\t\tif(nextK < 1 || (nextK <= 1 && n >1)){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tnextK = Math.min(n, nextK);\n\t\t\tif(n==nextK){\n\t\t\t\tSystem.out.println(count+1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t//System.out.println(\"nextK = \" + nextK);\n\t\t\t\n\t\t\t//search for a of a...nextK \n\t\t\tlong bSum = nextK * (nextK+1)/2;\n\t\t\tlong a = nextK;\n\t\t\tlong decrement = 1;\n\t\t\twhile(bSum - (a-1)*a/2 <= n && a>=1){\n\t\t\t\ta-= decrement;\n\t\t\t\tdecrement *= 2;\n\t\t\t}\n\t\t\ta+=decrement/2;\n\t\t\t\n\t\t\t//System.out.println(\"a = \" + a);\n\t\t\t\n\t\t\tcount += nextK-a+1;\n\t\t\t//System.out.println(\"count = \" + count);\n\t\t\tlong nDecr = bSum-a*(a-1)/2;\n\t\t\t//System.out.println(\"bSum = \" + bSum);\n\t\t\t//System.out.println(\"nDecr = \" + nDecr);\n\t\t\tn -= nDecr;\n\t\t\tnextK = a-1;\n\t\t\tif(n==0){\n\t\t\t\tSystem.out.println(count);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t\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", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "import\tjava.util.*;\npublic\tclass\tMain{\n\tpublic\tstatic\tvoid\tmain(String[]args){\n\t\tScanner\tcin=new\tScanner(System.in);\n\t\tlong\tz=cin.nextLong()-1<<1,n=cin.nextInt(),l=-1,r=1+n,m;\n\t\twhile(l<(m=l+r>>1))\tif(z>(m+n-1)*(n-m))\tr=m;else\tl=m;\n\t\tif(0<l)\tl=n-l;\n\t\tSystem.out.print(l);\n\t}\n}\n", "complexity": "logn", "problem": "287_B. Pipeline", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF256B extends PrintWriter {\n\tCF256B() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF256B o = new CF256B(); o.main(); o.flush();\n\t}\n\n\tlong count(int n, int x, int y, int r) {\n\t\tlong a = 2L * r * r + 2 * r + 1;\n\t\tint w;\n\t\tif ((w = 1 - (x - r)) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = 1 - (y - r)) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = (x + r) - n) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = (y + r) - n) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = r - 1 - (x - 1) - (y - 1)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\tif ((w = r - 1 - (x - 1) - (n - y)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\tif ((w = r - 1 - (n - x) - (y - 1)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\tif ((w = r - 1 - (n - x) - (n - y)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\treturn a;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint lower = -1, upper = c;\n\t\twhile (upper - lower > 1) {\n\t\t\tint r = (lower + upper) / 2;\n\t\t\tif (count(n, x, y, r) >= c)\n\t\t\t\tupper = r;\n\t\t\telse\n\t\t\t\tlower = r;\n\t\t}\n\t\tprintln(upper);\n\t}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tfinal String filename = new String(\"B\").toLowerCase();\n\n\tint n;\n\tint r, c;\n\n\tvoid solve() throws Exception {\n\t\tn = nextInt();\n\n\t\tr = nextInt() - 1;\n\t\tc = nextInt() - 1;\n\t\tlong count = nextLong();\n\n\t\tlong left = -1, right = n * 2L;\n\n\t\twhile (left < right - 1) {\n\t\t\tlong mid = (left + right) / 2;\n\n\t\t\tif (getSq(n, r, c, mid) >= count) {\n\t\t\t\tright = mid;\n\t\t\t} else {\n\t\t\t\tleft = mid;\n\t\t\t}\n\t\t}\n\t\t\n//\t\tfor (int i = 0; i <= 10; i++) {\n//\t\t\tSystem.err.println(getSq(n, r, c, i));\n//\t\t}\n\t\t\n\t\tout.println(right);\n\t}\n\t\n\tlong getSq(int n, int x, int y, long size) {\n\t\tlong cur = (size + 1) * (size + 1) + size * size;\n\t\t\n\t\tcur -= get(x + size - (n - 1));\n\t\tcur -= get(y + size - (n - 1));\n\t\tcur -= get(-(x - size));\n\t\tcur -= get(-(y - size));\n\t\t\n\t\tcur += getCorner((x + 1) + (y + 1) - (size + 1));\n\t\tcur += getCorner((x + 1) + (n - y) - (size + 1));\n\t\tcur += getCorner((n - x) + (y + 1) - (size + 1));\n\t\tcur += getCorner((n - x) + (n - y) - (size + 1));\n\t\t\n\t\treturn cur;\n\t}\n\t\n\tprivate long getCorner(long min) {\n\t\tif (min >= 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tmin = -min;\n\t\treturn min * (min + 1) / 2;\n\t}\n\n\tlong get(long a) {\n\t\tif (a <= 0) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn a * a;\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Problem {\n    \n    public static void main(String[] args) throws Exception {\n        Scanner input = new Scanner(System.in);\n        int side = input.nextInt()-1;\n        int x = input.nextInt()-1;\n        int y = input.nextInt()-1;\n        long target = input.nextLong();\n        \n        \n        int[] to_sides = {y, side - x, side - y, x};\n        int[] to_corners = {(y+1)+(side-x+1),(side-x+1)+(side-y+1),(side-y+1)+(x+1),\n            (x+1)+(y+1)};\n        int min = Math.min(Math.min(y, x), Math.min(side - x, side - y));\n        int[] after_pass = {1, 1, 1, 1};\n        int[] corner_share = {1,1,1,1};\n        int steps = 0 , i;\n        long init = 1 ;\n        int grown = 4;\n        while (init < target) {\n            init += grown;\n            steps++;\n            if (steps >= min) {\n                for (i = 0; i < 4; i++) {\n                    if (steps > to_sides[i]) {\n                        init -= after_pass[i];\n                        after_pass[i] += 2;\n                    }\n                    if (steps >= to_corners[i]){\n                        init += corner_share[i]++;\n                        //corner_share[i]++;\n                    }\n                }\n            }\n            grown += 4;\n        }\n        System.out.println(steps);\n    }\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class B {\n\tpublic static final boolean DEBUG = false;\n\tScanner sc;\n\t\n\tpublic void debug(Object o) {\n\t\tif (DEBUG) {\n\t\t\tint ln = Thread.currentThread().getStackTrace()[2].getLineNumber();\n\t\t\tString fn = Thread.currentThread().getStackTrace()[2].getFileName();\n\t\t\tSystem.out.println(\"(\" + fn + \":\" + ln+ \"): \" + o);\n\t\t}\n\t}\n\t\n\tpublic void pln(Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\tlong getNumber(int x, int y, int n, int m) {\n\t\tint n1 = Math.max(0, x + m - n);\n\t\tint n2 = Math.max(0, y + m - n);\n\t\tint n3 = Math.max(0, 1 - (x - m));\n\t\tint n4 = Math.max(0, 1 - (y - m));\n\t\t\n\t\tint n12 = Math.max(0, n1 + n2 - m - 1);\n\t\tint n23 = Math.max(0, n2 + n3 - m - 1);\n\t\tint n34 = Math.max(0, n3 + n4 - m - 1);\n\t\tint n41 = Math.max(0, n4 + n1 - m - 1);\n\t\t\n//\t\tdebug(n1 + \" \" + n2 + \" \" + n3 + \" \" + n4);\n//\t\tdebug(n12 + \" \" + n23 + \" \" + n34 + \" \" + n41);\n\t\t\n\t\tint m1 = m+1;\n\t\tlong nr = 1 + ((long)m1)*m1*2 - m1*2;\n\t\tnr -= ((long)n1)*n1 + ((long)n2)*n2 + ((long)n3)*n3 + ((long)n4)*n4;\n\t\tnr += ((long)n12)*(n12+1)/2 + ((long)n23)*(n23+1)/2 + ((long)n34)*(n34+1)/2 + ((long)n41)*(n41+1)/2;\n\t\t\n\t\treturn nr;\n\t}\n\tpublic void run() {\n//\t\tpln(getNumber(1, 1, 10000, 10000000));\n//\t\tpln(getNumber(1000, 1000, 1000, 1000000));\n//\t\tif (true) return;\n\n\t\tsc = new Scanner(System.in);\t\t\n\t\tint n = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\t\n\t\tif (c <= 1) {\n\t\t\tpln(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint ll = 0;\n\t\tint rr = 2*n+20;\n\t\t\n\t\twhile(true) {\n\t\t\tint m = (ll+rr) / 2;\n\t\t\tif (getNumber(x, y, n, m) >= c) {\n\t\t\t\trr = m;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tll = m;\n\t\t\t}\n//\t\t\tdebug(ll + \" \" + rr);\n\t\t\t\n\t\t\tif (rr - ll < 3) {\n\t\t\t\tfor (int m2=ll; m2<=rr; m2++) {\n\t\t\t\t\tif (getNumber(x, y, n, m2) >= c) {\n\t\t\t\t\t\tpln(m2);\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}\n\tpublic static void main(String[] args) {\n\t\tB t = new B();\n\t\tt.run();\n\t}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "//package codeforces.cf156;\nimport java.io.*;\nimport java.util.Arrays;\n\npublic class ProblemB {\n    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));\n\n    long[] readInts() throws IOException {\n        String[] strings = reader.readLine().split(\" \");\n        long[] ints = new long[strings.length];\n        for(int i = 0; i < ints.length; i++) {\n            ints[i] = Long.parseLong(strings[i]);\n        }\n        return ints;\n    }\n\n    long foo(long a) {\n        return a > 0 ? a * a : 0;\n    }\n    long boo(long a) {\n        return a <= 0 ? 0 : a * (a + 1) / 2;\n    }\n\n    void solve() throws IOException {\n        long[] tt = readInts();\n        long n = tt[0];\n        long x = tt[1];\n        long y = tt[2];\n        long c = tt[3];\n        long lo = -1, hi = 2 * 1000 * 1000 * 1000 + 2;\n//        hi = 5;\n        while(hi - lo > 1) {\n            long m = (lo + hi) / 2;\n            long s = 2 * m * m + 2 * m + 1;\n            s -= foo(m - x + 1) + foo(m - y + 1) + foo(x + m - n) + foo(y + m - n);\n            s += boo(m + 1 - (n + 1 + n + 1 - x - y)) + boo(m + 1 - (n + 1 - x + y)) + boo(m + 1 - (n + 1 - y + x))\n                    + boo(m + 1 - (x + y));\n            if(s < c) lo = m;\n            else hi = m;\n        }\n        writer.println(hi);\n        writer.flush();\n    }\n\n    public static void main(String[] args) throws IOException{\n        new ProblemB().solve();\n    }\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class bender {\n    static long[] dx = new long[]{0, 1, 0, -1};\n    static long[] dy = new long[]{-1, 0, 1, 0};\n    static long n, x, y, c;\n    \n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        //BufferedReader in = new BufferedReader(new FileReader(\"bender.in\"));\n        \n        StringTokenizer dxdync = new StringTokenizer(in.readLine());\n        n = Long.parseLong(dxdync.nextToken());\n        x = Long.parseLong(dxdync.nextToken());\n        y = Long.parseLong(dxdync.nextToken());\n        c = Long.parseLong(dxdync.nextToken());\n        \n        long a = 0;\n        long b = c;\n        \n        while(a < b){\n            long m = (a + b)/2;\n            \n            long[] dxn = new long[4];\n            long[] dyn = new long[4];\n            \n            for(int d = 0; d < 4; d++){\n                dxn[d] = x + dx[d] * m;\n                dyn[d] = y + dy[d] * m;\n            }\n            \n            long ret = (m+1)*(m+1) + m*m;\n            \n            ret -= h(1 - dyn[0]);\n            ret -= h(dyn[2] - n);\n            ret -= h(dxn[1] - n);\n            ret -= h(1 - dxn[3]);\n            \n            ret += q(1 - dyn[0] - (n-x+1));\n            ret += q(1 - dyn[0] - x);\n            ret += q(dyn[2] - n - (n - x + 1));\n            ret += q(dyn[2] - n - (x));\n            \n            if (ret < c) a = m + 1;\n            else b = m;\n        }\n        \n        System.out.println(a);\n    }\n    \n    public static long h(long x) {\n        if (x <= 0) return 0;\n        return 2*q(x) - x;\n    }\n    private static long q(long x){\n        if (x <= 0) return 0;\n        return x*(x+1)/2;\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "//package code;\n\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.io.BufferedInputStream;\nimport java.io.FileInputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\n\n/**\n *\n * @author malek\n */\n\npublic class MainA {\n\n    public static void main(String[] args) throws Exception {\n        //String cwd = System.getProperty(\"user.dir\") + \"\\\\\";\n        Scanner in = new Scanner(new BufferedInputStream(System.in));\n        PrintStream out = new PrintStream(System.out);\n        //Scanner in = new Scanner(new BufferedInputStream(new FileInputStream(cwd + \"src\\\\code\\\\in.in\")));\n        //PrintStream out = new PrintStream(cwd + \"src\\\\code\\\\out.out\");\n        //=======================\n        Solution solution = new Solution(in, out);\n        solution.solve();\n        //=======================\n        in.close();\n        out.close();\n    }\n    static private class Solution {\n        final int inf = (int)1e9;\n        //final int MAX_N = 1000 * 1000 + 100;\n        int n, x, y, c;\n\n        int f(int u, int r, int sec){\n            if(u == 0 && r == 0)\n                return 0;\n            if(u == 0){\n                return r - 1;\n            }\n            if(r == 0){\n                return u - 1;\n            }\n            return Math.min(sec - 1, u - 1 + r - 1);\n        }\n\n        boolean isok(int sec){\n            int up = x - 1;\n            int down = n - x;\n            int right = n - y;\n            int left = y - 1;\n            int u = 0, d = 0, r = 0, l = 0;\n            int total = 1;\n            int add = 4;\n            for(int i = 1; i <= sec; i++){\n                int cc = 0;\n                if(i > up && ++cc > 0) u++;\n                if(i > down && ++cc > 0) d++;\n                if(i > right && ++cc > 0) r++;\n                if(i > left && ++cc > 0) l++;\n                total += add - cc;\n                total -= Math.max(0, f(u, r, i));\n                total -= Math.max(0, f(u, l, i));\n                total -= Math.max(0, f(d, r, i));\n                total -= Math.max(0, f(d, l, i));\n                if(total >= c) return true;\n                add += 4;\n            }\n            return false;\n        }\n\n        public void solve() {\n            n = in.nextInt();\n            x = in.nextInt();\n            y = in.nextInt();\n            c = in.nextInt();\n            if(c == 1){\n                out.println(0);\n                return;\n            }\n            int lo = 0, hi = 60000;\n            while(lo < hi){\n                int mid = (lo + hi)/2;\n                if(isok(mid)){\n                    hi = mid;\n                }\n                else{\n                    lo = mid + 1;\n                }\n            }\n            out.println(lo);\n        }\n\n        public Solution(Scanner in, PrintStream out) {\n            this.in = in;\n            this.out = out;\n        }\n\n        Scanner in;\n        PrintStream out;\n    }\n}\n\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class B {\n    public static void main(String[] args) throws Exception {\n        new B().solve(System.in, System.out);\n        // new FileInputStream(new File(\"input.txt\")),\n        // new PrintStream(new FileOutputStream(new File(\"output.txt\"))));\n    }\n\n    void solve(InputStream _in, PrintStream out) throws IOException {\n        // BufferedReader in = new BufferedReader(new InputStreamReader(_in));\n        // String[] sp;\n        Scanner sc = new Scanner(_in);\n\n        long n = sc.nextLong();\n        long x = sc.nextLong() - 1;\n        long y = sc.nextLong() - 1;\n        long c = sc.nextLong();\n\n        long ub = 2 * n;\n        long lb = -1;\n        while (lb + 1 < ub) {\n            long k = (lb + ub) / 2;\n\n            long l, u, r, d;\n            l = Math.max(0, x - k);\n            u = Math.max(0, y - k);\n            r = Math.min(n - 1, x + k);\n            d = Math.min(n - 1, y + k);\n\n            long ss = 0;\n            // lu\n            long lu = x - (k - (y - u));\n            if (l < lu) {\n                long a = lu - l;\n                ss += a * (a + 1) / 2;\n            }\n            // ld\n            long ld = x - (k - (d - y));\n            if (l < ld) {\n                long a = ld - l;\n                ss += a * (a + 1) / 2;\n            }\n            // ru\n            long ru = x + (k - (y - u));\n            if (ru < r) {\n                long a = r - ru;\n                ss += a * (a + 1) / 2;\n            }\n            // rd\n            long rd = x + (k - (d - y));\n            if (rd < r) {\n                long a = r - rd;\n                ss += a * (a + 1) / 2;\n            }\n\n            long cc = (r + 1 - l) * (d + 1 - u) - ss;\n\n            if (c <= cc) {\n                // ok\n                ub = k;\n            } else {\n                // ng\n                lb = k;\n            }\n        }\n        out.println(ub);\n    }\n}\n\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author BSRK Aditya (bsrkaditya@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\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\n    long n,x,y,c;\n\n\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n        n = in.readInt();\n        x = in.readInt();\n        y = in.readInt();\n        c = in.readInt();\n\n        int lo = -1;\n        int hi = (int)c;\n\n        while(lo+1<hi) {\n            int mi = (lo+hi)/2;\n            if(P(mi)) hi = mi; else lo = mi;\n        }\n        out.printLine(hi);\n\t}\n\n    private boolean P(int t) {\n        if(t == -1) return false;\n\n        int ans = 0;\n        for(long i = Math.max(1,y-t); i <= Math.min(y+t,n); ++i) {\n            long a = Math.abs(y - i);\n            ans += D(Math.max(1,x-t+a), Math.min(n,x+t-a));\n            if(ans >= c) return true;\n        }\n\n        return false;\n    }\n\n    private long D(long a, long b) {\n        return b - a + 1;\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\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\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", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n    static 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    static PrintWriter out;\n\n    public static long count(long k, long x, long y, long n) {\n        long sum = 2*k*(k+1)+1;\n        if (k >= x-1) {\n            sum -= (k-x+1)*(k-x+1);\n        }\n        if (k >= y-1) {\n            sum -= (k-y+1)*(k-y+1);\n        }\n        if (k + x >= n) {\n            sum -= (k+x-n)*(k+x-n);\n        }\n        if (k + y >= n) {\n            sum -= (k+y-n)*(k+y-n);\n        }\n\n        if (k > x+y-1) {\n            sum += ((k+1-x-y)*(k+1-x-y+1))/2;\n        }\n\n        if (k > n-x+y) {\n            sum += ((k+x-n-y)*(k+x-n-y+1))/2;\n        }\n\n        if (k > n-y+x) {\n\n            sum += ((k+y-n-x)*(k+y-n-x+1))/2;\n        }\n\n        if (k > 2*n-x-y+1) {\n\n            sum += ((k-2*n+x+y-1)*(k-2*n+x+y))/2;\n        }\n        return sum;\n    }\n\n    public static void main(String[] args) throws Exception {\n        in = 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        out = new PrintWriter(System.out);\n\n        long n = in.nextLong(), x = in.nextLong(), y = in.nextLong(), c = in.nextLong();\n\n        long res = 0;\n        while (count(res, x, y, n) < c) res++;\n        out.println(res);\n\n\n        out.println();\n        out.close();\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class Main implements Runnable {\n    private BufferedReader br;\n    private StringTokenizer tok;\n    private PrintWriter out;\n\n    static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    int[] a;\n    int[] b;\n    int[] p;\n\n    int getCeils(int id, int step) {\n        if (step > a[id] + b[id] - 1) {\n            return 0;\n        }\n        if (a[id] < b[id]) {\n            if (step < a[id]) {\n                return step;\n            }\n            if (step >= a[id] && step <= b[id]) {\n                return a[id];\n            }\n            ++p[id];\n            return a[id] - p[id];\n        } else {\n            if (step < b[id]) {\n                return step;\n            }\n            if (step >= b[id] && step <= a[id]) {\n                return b[id];\n            }\n            ++p[id];\n            return b[id] - p[id];\n        }\n    }\n\n    void solve() throws IOException {\n        int n = nextInt(), x = nextInt(), y = nextInt(), c = nextInt();\n        long s = 1;\n        int step = 0;\n        a = new int[4];\n        b = new int[4];\n        p = new int[4];\n        a[0] = x - 1; b[0] = n - y;\n        a[1] = x - 1; b[1] = y - 1;\n        a[2] = n - x; b[2] = y - 1;\n        a[3] = n - x; b[3] = n - y;\n        int xf = x + 1, xb = x - 1, yf = y + 1, yb = y - 1;\n        while (s < c) {\n            ++step;\n            if (xf <= n) {\n                ++s;\n                ++xf;\n            }\n            if (xb > 0) {\n                ++s;\n                --xb;\n            }\n            if (yf <= n) {\n                ++s;\n                ++yf;\n            }\n            if (yb > 0) {\n                ++s;\n                --yb;\n            }\n            if (step == 1) {\n                continue;\n            }\n            for (int i = 0; i < 4; ++i) {\n                s += getCeils(i, step - 1);\n            }\n        }\n        out.println(step);\n    }\n\n    public void run() {\n        try {\n            if (ONLINE_JUDGE) {\n                br = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(System.out);\n            } else {\n                br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n                out = new PrintWriter(new File(\"output.txt\"));\n            }\n            solve();\n            br.close();\n            out.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n\n    String nextToken() throws IOException {\n        while (tok == null || !tok.hasMoreTokens())\n            tok = new StringTokenizer(br.readLine());\n        return tok.nextToken();\n    }\n\n    String nextString() throws IOException {\n        return 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    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(nextToken());\n    }\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class P {\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();\n\t\tlong C = sc.nextLong();\n\n\t\tint lo = 0, hi = (int) (1e6);\n\t\tint answer = -1;\n\t\twhile (lo <= hi) {\n\t\t\tint L = lo + (hi - lo) / 2;\n\t\t\tlong area = 0;\n\t\t\tfor (int steps = 0; steps <= L; ++steps) { // L + 1 steps to right\n\t\t\t\tif (y + steps > N)\n\t\t\t\t\tbreak;\n\t\t\t\tlong up = Math.min(x, 1 + L - steps), down = Math.min(N - x, L - steps);\n\t\t\t\tarea += up + down;\n\t\t\t}\n\n\t\t\tfor (int steps = 1; steps <= L; ++steps) { // L steps to left\n\t\t\t\tif (y - steps < 1)\n\t\t\t\t\tbreak;\n\t\t\t\tlong up = Math.min(x, 1 + L - steps), down = Math.min(N - x, L - steps);\n\t\t\t\tarea += up + down;\n\t\t\t}\n\t\t\tif (area >= C) {\n\t\t\t\tanswer = L;\n\t\t\t\thi = L - 1;\n\t\t\t} else\n\t\t\t\tlo = L + 1;\n\t\t}\n\t\tout.println(answer);\n\n\t\tout.flush();\n\t\tout.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\tScanner(String file) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(file));\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\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint x = nextInt();\n\t\tint y = nextInt();\n\t\tint c = nextInt();\n\t\t\n\t\tint lux = x;\n\t\tint luy = y + 1;\n\t\t\n\t\tint rux = x + 1;\n\t\tint ruy = y;\n\t\t\n\t\tint ldx = x - 1;\n\t\tint ldy = y;\n\t\t\n\t\tint rdx = x;\n\t\tint rdy = y - 1;\n\t\t\n\t\tint k = 1;\n\t\tint res = 0;\n\t\twhile (k < c) {\n\t\t\tlux--;\n\t\t\tluy--;\n\t\t\trux--;\n\t\t\truy++;\n\t\t\trdx++;\n\t\t\trdy++;\n\t\t\tldx++;\n\t\t\tldy--;\n\t\t\tint p = 0;\n\t\t\tp += lu(x - 1, luy, lux, y, n);\n\t\t\tp += ru(x, ruy, rux, y + 1, n);\n\t\t\tp += ld(x, ldy, ldx, y - 1, n);\n\t\t\tp += rd(x + 1, rdy, rdx, y, n);\n\t\t\tk += p;\n\t\t\tres++;\n\t\t}\n\t\t\n\t\tprintln(res);\n\t}\n\t\n\tprivate int lu(int x1, int y1, int x2, int y2, int n) {\n\t\tif (y1 > 0 && x2 > 0) {\n\t\t\treturn x1 - x2 + 1;\n\t\t} else if (y1 > 0 && x2 < 1) {\n\t\t\treturn x1;\n\t\t} else if (y1 < 1 && x2 > 0) {\n\t\t\treturn y2;\n\t\t} else if (x1 - (1 - y1) > 0) {\n\t\t\treturn lu(x1 - (1 - y1), 1, x2, y2, n);\n\t\t} else {\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tprivate int ru(int x1, int y1, int x2, int y2, int n) {\n\t\tif (y1 <= n && x2 > 0) {\n\t\t\treturn x1 - x2 + 1;\n\t\t} else if (y1 <= n && x2 < 1) {\n\t\t\treturn x1;\n\t\t} else if (y1 > n && x2 > 0) {\n\t\t\treturn n - y2 + 1;\n\t\t} else if (x1 - (y1 - n) > 0) {\n\t\t\treturn ru(x1 - (y1 - n), n, x2, y2, n);\n\t\t} else {\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tprivate int ld(int x1, int y1, int x2, int y2, int n) {\n\t\tif (y1 > 0 && x2 <= n) {\n\t\t\treturn x2 - x1 + 1;\n\t\t} else if (y1 > 0 && x2 > n) {\n\t\t\treturn n - x1 + 1;\n\t\t} else if (y1 < 1 && x2 <= n) {\n\t\t\treturn y2;\n\t\t} else if (x1 + (1 - y1) <= n) {\n\t\t\treturn ld(x1 + (1 - y1), 1, x2, y2, n);\n\t\t} else {\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tprivate int rd(int x1, int y1, int x2, int y2, int n) {\n\t\tif (y1 <= n && x2 <= n) {\n\t\t\treturn x2 - x1 + 1;\n\t\t} else if (y1 <= n && x2 > n) {\n\t\t\treturn n - x1 + 1;\n\t\t} else if (y1 > n && x2 <= n) {\n\t\t\treturn n - y2 + 1;\n\t\t} else if (x1 + (y1 - n) <= n) {\n\t\t\treturn rd(x1 + (y1 - n), n, x2, y2, n);\n\t\t} else {\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tprivate String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tprivate void println(Object o) {\n\t\twriter.println(o);\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tprivate void print(Object o) {\n\t\twriter.print(o);\n\t}\n\n\tprivate BufferedReader reader;\n\tprivate PrintWriter writer;\n\tprivate StringTokenizer st;\n\n\tprivate void run() throws IOException {\n\t\tlong time = System.currentTimeMillis();\n\t\tLocale.setDefault(Locale.US);\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\twriter = new PrintWriter(System.out);\n\t\tsolve();\n\t\twriter.close();\n\t\tSystem.err.println(System.currentTimeMillis() - time);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().run();\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\t\n\tstatic Scanner cin = new Scanner(System.in);\n\tstatic int n, x, y;\n\tstatic long c;\n\t\n\tprivate static long f(int mid) {\n\t\tlong block = 1 + 4 * (long)(mid + 1) * mid / 2;\n\t\tint l = y - mid;\n\t\tint r = y + mid;\n\t\tint u = x - mid;\n\t\tint d = x + mid;\n\t\tif(l <= 0)\n\t\t\tblock -= (long)(1 - l) * (1 - l);\n\t\tif(r > n)\n\t\t\tblock -= (long)(r - n) * (r - n);\n\t\tif(u <= 0)\n\t\t\tblock -= (long)(1 - u) * (1 - u);\n\t\tif(d > n)\n\t\t\tblock -= (long)(d - n) * (d - n);\n\t\tif(u <= 0 && 1 - u > n - y + 1) {\n\t\t\tint t = (1 - u) - (n - y + 1);\n\t\t\tblock += (long)t * (1 + t) / 2;\n\t\t}\n\t\tif(u <= 0 && (1 - u) > y) {\n\t\t\tint t = (1 - u) - y;\n\t\t\tblock += (long)t * (1 + t) / 2;\n\t\t}\n\t\tif(d > n && d - n > n - y + 1) {\n\t\t\tint t = (d - n) - (n - y + 1);\n\t\t\tblock += (long)t * (1 + t) / 2;\n\t\t}\n\t\tif(d > n && d - n > y) {\n\t\t\tint t = (d - n) - y;\n\t\t\tblock += (long)t * (1 + t) / 2;\n\t\t}\n//\t\tSystem.out.println(block);\n\t\treturn block;\n\t}\n\t\n\tpublic static void main(String args[]) {\n\t\t\n\t\tn = cin.nextInt();\n\t\tx = cin.nextInt();\n\t\ty = cin.nextInt();\n\t\tc = cin.nextLong();\n\t\t\n\t\tint low = 0, high = 1000000000;\n\t\tint ans = -1;\n\t\twhile(low <= high) { \n\t\t\tint mid = (low + high) / 2;\n//\t\t\tSystem.out.println(mid + \" \" + f(mid));\n\t\t\tif(f(mid) >= c) {\n\t\t\t\tans = mid;\n\t\t\t\thigh = mid - 1;\n\t\t\t} else {\n\t\t\t\tlow = mid + 1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.math.BigInteger;\nimport java.io.*;\n\npublic class Main{\n\n\t/**\n\t * @param args\n\t */\n\tstatic BigInteger n, x, y, c;\n\tstatic BigInteger mk[] = new BigInteger[8];\n\tpublic static BigInteger f(BigInteger t) {\n\t\treturn t.multiply(t);\n\t}\n\t\n\tpublic static BigInteger g(BigInteger t) {\n\t\treturn t.multiply(t.add(BigInteger.ONE)).shiftRight(1);\n\t}\n\t\n\tpublic static int solve(BigInteger z) {\n\t\tBigInteger ret = z.multiply(z.add(BigInteger.ONE)).shiftLeft(1);\n\t\tret = ret.add(BigInteger.ONE);\n\t\t//System.out.println(z + \" \" + ret);\n\t\tfor(int i = 0; i < 8; i += 2) {\n\t\t\tif(z.compareTo(mk[i]) > 0) {\n\t\t\t\tret = ret.subtract(f(z.subtract(mk[i])));\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i < 8; i += 2) {\n\t\t\tif(z.compareTo(mk[i]) > 0) {\n\t\t\t\tret = ret.add(g(z.subtract(mk[i])));\n\t\t\t}\n\t\t}\n\t\t//System.out.println(z + \" \" + ret);\n\t\tif(ret.compareTo(c) >= 0) return 1;\n\t\treturn 0;\n\t}\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner cin = new Scanner(System.in);\n\t\twhile(cin.hasNext()) {\n\t\t\tn = cin.nextBigInteger();\n\t\t\tx = cin.nextBigInteger();\n\t\t\ty = cin.nextBigInteger();\n\t\t\tc = cin.nextBigInteger();\n\t\t\tmk[0] = x.subtract(BigInteger.ONE);\n\t\t\tmk[2] = n.subtract(y);\n\t\t\tmk[4] = n.subtract(x);\n\t\t\tmk[6] = y.subtract(BigInteger.ONE);\n\t\t\tmk[1] = mk[0].add(mk[2]).add(BigInteger.ONE);\n\t\t\tmk[3] = mk[2].add(mk[4]).add(BigInteger.ONE);\n\t\t\tmk[5] = mk[4].add(mk[6]).add(BigInteger.ONE);\n\t\t\tmk[7] = mk[6].add(mk[0]).add(BigInteger.ONE);\n\t\t\tBigInteger beg = BigInteger.ZERO, end = mk[0], mid;\n\t\t\tfor(int i = 1; i < 8; ++i) if(end.compareTo(mk[i]) < 0) end = mk[i];\n\t\t\twhile(beg.compareTo(end) < 0) {\n\t\t\t\tmid = beg.add(end).shiftRight(1);\n\t\t\t\tif(solve(mid) == 1) end = mid;\n\t\t\t\telse beg = mid.add(BigInteger.ONE);\n\t\t\t}\n\t\t\tSystem.out.println(end);\n\t\t}\n\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\tstatic long[] dx = new long[]{0, 1, 0, -1};\n\tstatic long[] dy = new long[]{-1, 0, 1, 0};\n\tpublic static void main(String[] args) {\n\t\tScanner r = new Scanner(System.in);\n\t\t\n\t\tlong N = r.nextLong();\n\t\tlong X = r.nextLong();\n\t\tlong Y = r.nextLong();\n\t\tlong C = r.nextLong();\n\t\t\n\t\tlong lo = 0, hi = N * 2;\n\t\t\n\t\twhile(lo < hi){\n\t\t\tlong T = (lo + hi) / 2;\n\t\t\t\n\t\t\tlong[] NX = new long[4];\n\t\t\tlong[] NY = new long[4];\n\t\t\t\n\t\t\tfor(int d = 0; d < 4; d++){\n\t\t\t\tNX[d] = X + dx[d] * T;\n\t\t\t\tNY[d] = Y + dy[d] * T;\n\t\t\t}\n\t\t\t\n\t\t\tlong ret = (T + 1) * (T + 1) + T * T;\n\t\t\t\n\t\t\tret -= half(1 - NY[0]);\n\t\t\tret -= half(NY[2] - N);\n\t\t\tret -= half(NX[1] - N);\n\t\t\tret -= half(1 - NX[3]);\n\t\t\t\n\t\t\tret += quarter(1 - NY[0] - (N - X + 1));\n\t\t\tret += quarter(1 - NY[0] - (X));\n\t\t\tret += quarter(NY[2] - N - (N - X + 1));\n\t\t\tret += quarter(NY[2] - N - (X));\n\t\t\t\n\t\t\tif(ret < C)lo = T + 1;\n\t\t\telse hi = T;\n\t\t}\n\t\t\n\t\tSystem.out.println(lo);\n\t\t\n\t}\n\tprivate static long half(long x) {\n\t\tif(x <= 0)return 0;\n\t\telse return 2 * quarter(x) - x;\n\t}\n\tprivate static long quarter(long x){\n\t\tif(x <= 0)return 0;\n\t\treturn x * (x + 1) / 2;\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class cf256b {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tlong x = in.nextLong()-1;\n\t\tlong y = in.nextLong()-1;\n\t\tlong c = in.nextLong();\n\t\t\n\t\tlong lo = 0, hi = 2*n+10;\n\t\twhile(hi - lo > 2) {\n\t\t\tlong mid = (hi+lo)/2;\n\t\t\tif(calc(n,x,y,mid) >= c)\n\t\t\t\thi = mid;\n\t\t\telse\n\t\t\t\tlo = mid;\n\t\t}\n\t\twhile(calc(n,x,y,lo) < c) lo++;\n\t\tSystem.out.println(lo);\n\t}\n\tstatic long calc(long n, long x, long y, long t) {\n\t\tlong ans = (2*t)*(t+1)+1;\n\t\t\n\t\tlong top = Math.max(0,t-x);\n\t\tlong bottom = Math.max(0,t-(n-1-x));\n\t\tlong left = Math.max(0,t-y);\n\t\tlong right = Math.max(0,t-(n-1-y));\n\t\tans -= top*top + bottom*bottom + left*left + right*right;\n\t\t\n\t\tlong tl = Math.max(0, t - (x+y+1));\n\t\tlong tr = Math.max(0, t - (x+(n-1-y)+1));\n\t\tlong bl = Math.max(0, t - ((n-1-x)+y+1));\n\t\tlong br = Math.max(0, t - ((n-1-x) + (n-1-y) + 1));\n\t\t\n\t\tans += (tl*tl+tl)/2 + (tr*tr+tr)/2 + (bl*bl+bl)/2 + (br*br+br)/2;\n\t\treturn ans;\n\t}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.BigInteger;\n\nimport javax.naming.BinaryRefAddr;\n\npublic class acm\n{\n    public static BigInteger n;\n    public static BigInteger TWO = new BigInteger(\"2\");\n    public static BigInteger solve(BigInteger x, BigInteger y, BigInteger c)\n    {\n        BigInteger res = (c.add(BigInteger.ONE)).multiply(c.add(BigInteger.ONE));\n        res = res.add(c.multiply(c));\n        BigInteger k;\n        \n        //up\n        k = c.subtract(x.subtract(BigInteger.ONE)); \n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.subtract(k.multiply(k));\n\n        //left\n        k = c.subtract(y.subtract(BigInteger.ONE)); \n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.subtract(k.multiply(k));\n\n        //down\n        k = c.subtract(n.subtract(x)); \n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.subtract(k.multiply(k));\n\n\n        //right\n        k = c.subtract(n.subtract(y));\n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.subtract(k.multiply(k));\n\n\n        //upleft\n        k = c.subtract(x.add(y).subtract(BigInteger.ONE));\n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));\n\n\n        //upright\n        k = c.subtract(x.add(n).subtract(y));\n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));\n\n\n        //dwleft\n        k = c.subtract(y.add(n).subtract(x));\n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));\n\n\n        //dwleft\n        k = c.subtract(n.subtract(x).add(n.subtract(y)).add(BigInteger.ONE));\n        if(k.compareTo(BigInteger.ZERO) > 0)\n            res = res.add(k.multiply(k.add(BigInteger.ONE)).divide(TWO));\n\n\n\n        return res;\n    }\n    \n    public static void main(String[] args)\n    {TWO = new BigInteger(\"2\");\n        Scanner in = new Scanner(System.in);\n        n = new BigInteger(in.next());\n        BigInteger x = new BigInteger(in.next());\n        BigInteger y = new BigInteger(in.next());\n        BigInteger c = new BigInteger(in.next());\n\n        \n        BigInteger left = new BigInteger(\"0\");\n        BigInteger right = new BigInteger(\"1000000000000\");\n        while(left.compareTo(right) < 0)\n        {\n            BigInteger val = left.add(right).divide(TWO);\n\n            if(solve(x, y, val).compareTo(c) >= 0)\n                right = val;\n            else\n                left = val.add(BigInteger.ONE);\n        }\n\n        System.out.println(left);\n    } \n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\n\npublic class ProblemB {\n\npublic static void main(String[] args) throws IOException {\n\t\t\n\t\tProblemB solver = new ProblemB();\n\t\tsolver.init();\n\t\tsolver.solve();\n\t}\n\t\n\tprivate void init() {\n\t\t\n\t}\n\n\tprivate void solve() throws IOException {\n\t\t \n\t\tReader in = new Reader(System.in);\n\t\tPrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\n\t\tint n = in.nextInt();\n\t\tint x = in.nextInt();\n\t\tint y = in.nextInt();\n\t\tint c = in.nextInt();\n\t\t\n\t\tlong lo = 0;\n\t\tlong hi = 2 * n;\n\t\t\n\t\twhile (lo < hi) {\n\t\t\tlong mid = (lo + hi)/2;\n\t\t\tlong r = count(n, x , y, mid);\n\t\t\tif (r < c) {\n\t\t\t\tlo = mid + 1;\n\t\t\t} else {\n\t\t\t\thi = mid;;\n\t\t\t}\n\t\t}\n\t\tout.println(lo);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\t\n\tprivate long count(int n, int x, int y, long steps) {\n\t\tlong r = 1  + 2 * steps * (1 + steps);\n\t\tr -= countWall(x - 1 - steps);\n\t\tr -= countWall(y - 1 - steps);\n\t\tr -= countWall(n - (x + steps));\n\t\tr -= countWall(n - (y + steps));\n\t\tr += countCorner(steps - (x - 1) - (y - 1) - 1);\n\t\tr += countCorner(steps - (y - 1) - (n - x) - 1);\n\t\tr += countCorner(steps - (n - x) - (n - y) - 1);\n\t\tr += countCorner(steps - (x - 1) - (n - y) - 1);\n\t\t\n\t\treturn r;\n\t}\n\n\tprivate long countCorner(long x) {\n\t\tif (x <= 0) return 0;\n\t\treturn x * ( x + 1) / 2;\n\t}\n\n\tprivate long countWall(long x) {\n\t\tif (x >= 0) return 0;\n\t\treturn x * x;\n\t}\n\n\tprivate static class Reader {\n\t    BufferedReader reader;\n\t    StringTokenizer tokenizer;\n\n\t    /** call this method to initialize reader for InputStream */\n\t    Reader(InputStream input) {\n\t        reader = new BufferedReader(\n\t                     new InputStreamReader(input) );\n\t        tokenizer = new StringTokenizer(\"\");\n\t    }\n\n\t    /** get next word */\n\t    public String next() throws IOException {\n\t        while ( ! tokenizer.hasMoreTokens() ) {\n\t            //TODO add check for eof if necessary\n\t            tokenizer = new StringTokenizer(\n\t                   reader.readLine() );\n\t        }\n\t        return tokenizer.nextToken();\n\t    }\n\n\t    public int nextInt() throws IOException {\n\t        return Integer.parseInt( next() );\n\t    }\n\t    \n\t    public double nextDouble() throws IOException {\n\t        return Double.parseDouble( next() );\n\t    }\n\t    \n\t    public long nextLong() throws IOException {\n\t    \treturn Long.parseLong(next());\n\t    }\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Example {\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    long n, x, y, c;\n\n    boolean check(long z) {\n        long res = 1 + 2 * z * (z + 1);\n        long bx1 = z - x + 1;\n        long by1 = z - y + 1;\n        long bxn = z - n + x;\n        long byn = z - n + y;\n\n        if (bx1 > 0) {\n            res -= bx1 * bx1;\n        }\n        if (bxn > 0) {\n            res -= bxn * bxn;\n        }\n        if (by1 > 0) {\n            res -= by1 * by1;\n        }\n        if (byn > 0) {\n            res -= byn * byn;\n        }\n\n        if (z > x + y - 1) {\n            long m = z - x - y + 1;\n            res += m * (m + 1) / 2;\n        }\n        if (z > x + n - y) {\n            long m = z - x - n + y;\n            res += m * (m + 1) / 2;\n        }\n        if (z > n - x + y) {\n            long m = z - n - y + x;\n            res += m * (m + 1) / 2;\n        }\n        if (z > n - x + n - y + 1) {\n            long m = z - 2 * n + x + y - 1;\n            res += m * (m + 1) / 2;\n        }\n        \n        return res >= c;\n    }\n\n    public void solve() throws Exception {\n        n = nextLong();\n        x = nextLong();\n        y = nextLong();\n        c = nextLong();\n        long l = 0;\n        long r = 2 * n;\n        while (r > l) {\n            long mid = (r + l) / 2;\n            if (check(mid)) {\n                r = mid;\n            } else {\n                l = mid + 1;\n            }\n        }\n        out.println(r);\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Example().run();\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\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.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\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\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n        \n        long n = in.nextLong();\n        long x = in.nextLong();\n        long y = in.nextLong();\n        long c = in.nextLong();\n        \n        long tl, tr, tt = -1, t;\n        tl = 0;\n        tr = (long) 4e9;\n        while(tl<tr){\n            t = (tl+tr)>>1;\n            \n            long cc = f(n, t, x, y);\n            if(cc>=c){\n                tt = t;\n                tr = t;\n            }else tl = t+1;\n        }\n        \n        out.writeln(tt);\n\t}\n    \n    \n    public static long f(long n, long t, long x, long y){\n        \n        long res = (t*t+t)/2 * 4 + 1;\n        long s;\n        \n        if(x-t<1){\n            s = t-x+1;\n            res -= s*s;\n        }\n        if(y-t<1){\n            s = t-y+1;\n            res -= s*s;\n        }\n        if(x+t>n){\n            s = x+t-n;\n            res -= s*s;\n        }\n        if(y+t>n){\n            s = y+t-n;\n            res -= s*s;\n        }\n\n        s = t-(Math.abs(x-1)+Math.abs(y-1))-1;\n        if(s>0) res+=(s*s+s)/2;\n\n        s = t-(Math.abs(x-1)+Math.abs(n-y))-1;\n        if(s>0) res+=(s*s+s)/2;\n\n        s = t-(Math.abs(n-x)+Math.abs(n-y))-1;\n        if(s>0) res+=(s*s+s)/2;\n\n        s = t-(Math.abs(n-x)+Math.abs(y-1))-1;\n        if(s>0) res+=(s*s+s)/2;\n        \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    \n    }\n\nclass OutputWriter{\n    private PrintWriter out;\n\n    public OutputWriter(Writer out){\n        this.out = new PrintWriter(out);\n    }\n\n    public OutputWriter(OutputStream out){\n        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));\n    }\n\n    public void write(Object ... o){\n        for(Object x : o) out.print(x);\n    }\n\n    public void writeln(Object ... o){\n        write(o);\n        out.println();\n    }\n\n    public void close(){\n        out.close();\n    }\n}\n\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Alex\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskB {\n        int n;\n        int startrow;\n        int startcol;\n        long want;\n\n        boolean check(long time) {\n            long max = (long) 2 * time * (time + 1) + 1;\n            long highest = startrow - time;\n            if(highest < 0) {\n                max -= Math.abs(highest) * Math.abs(highest);\n            }\n            long lowest = startrow + time;\n            if(lowest >= n) {\n                max -= Math.abs(lowest - n + 1) * Math.abs(lowest - n + 1);\n            }\n            long leftmost = startcol - time;\n            if(leftmost < 0) {\n                max -= Math.abs(leftmost) * Math.abs(leftmost);\n            }\n            long rightmost = startcol + time;\n            if(rightmost >= n) {\n                max -= Math.abs(rightmost - n + 1) * Math.abs(rightmost - n + 1);\n            }\n            long upperright = time - (startrow + 1) - (n - startcol);\n            if(upperright >= 0) {\n                max += (upperright + 1) * (upperright + 2) / 2;\n            }\n            long lowerright = time - (n - startrow) - (n - startcol);\n            if(lowerright >= 0) {\n                max += (lowerright + 1) * (lowerright + 2) / 2;\n            }\n            long upperleft = time - (startrow + 1) - (startcol + 1);\n            if(upperleft >= 0) {\n                max += (upperleft + 1) * (upperleft + 2) / 2;\n            }\n            long lowerleft = time - (n - startrow) - (startcol + 1);\n            if(lowerleft >= 0) {\n                max += (lowerleft + 1) * (lowerleft + 2) / 2;\n            }\n            return max >= want;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.readInt();\n            startrow = in.readInt() - 1;\n            startcol = in.readInt() - 1;\n            want = in.readLong();\n            long low = 0, high = 2 * n;\n            while(low < high) {\n                long mid = (low + high) / 2;\n                if(check(mid)) high = mid;\n                else low = mid + 1;\n            }\n            out.printLine(low);\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 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    }\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\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\npublic class b2 {\npublic static void main(String[] args) throws IOException\n{\n    input.init(System.in);\n    int n = input.nextInt(), x = input.nextInt(), y = input.nextInt(),  c = input.nextInt();\n    long lo = 0, hi = 2*n;\n    while(hi > lo+1)\n    {\n        long mid = (hi+lo)/2;\n        long covered = go(n, x, y, mid);\n        if(covered < c)\n            lo = mid;\n        else hi = mid;\n    }\n    if(go(n, x, y, lo) < c) lo++;\n    System.out.println(lo);\n    \n}\npublic static long go(int n, int x, int y, long d)\n{\n    long res = d*d + (d+1)*(d+1);\n    long maxLeft = d - x;\n    if(maxLeft >= 0) res -= (maxLeft+1)*(maxLeft+1);\n    long maxTop = d - y;\n    if(maxTop >= 0) res -= (maxTop+1)*(maxTop+1);\n    long maxRight = d - (n+1-x);\n    if(maxRight >= 0) res -= (maxRight+1)*(maxRight+1);\n    long maxBot = d - (n+1-y);\n    if(maxBot >= 0) res -= (maxBot+1)*(maxBot+1);\n    long maxTopLeft = d - (x+y);\n    if(maxTopLeft >= 0) res += (maxTopLeft+1)*(maxTopLeft+2)/2;\n    long maxTopRight = d - ((n+1-x)+y);\n    if(maxTopRight >= 0) res += (maxTopRight+1)*(maxTopRight+2)/2;\n    long maxBotLeft = d - (x+(n+1-y));\n    if(maxBotLeft >= 0) res += (maxBotLeft+1)*(maxBotLeft+2)/2;\n    long maxBotRight = d - ((n+1-x)+(n+1-y));\n    if(maxBotRight >= 0) res += (maxBotRight+1)*(maxBotRight+2)/2;\n    return res;\n\n}\npublic static class input {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    /** get next word */\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemB {\n    InputReader in; PrintWriter out;\n    void solve() {\n        int n = in.nextInt();\n        int x = in.nextInt();\n        int y = in.nextInt();\n        int c = in.nextInt();\n        int cur = 1;\n        for (int k = 1; k <= c; k++) {\n//          out.println(k + \" \" + cur);\n            if (cur >= c) {\n                out.println(k - 1);\n                return;\n            }\n            //x + i; y + k - i;\n            int iLess = n - x;\n            int iMore = y + k - n;\n            if (iLess > k)\n                iLess = k;\n            if (iMore < 0)\n                iMore = 0;\n//          out.println(\"iless == \" + iLess + \" imore == \" + iMore);\n            int add = iLess - iMore + 1;\n            if (add < 0)\n                add = 0;\n//          out.println(\"add == \" + add);\n            cur += add;\n            //x + i; y - k + i;\n            iLess = n - x;\n            iMore = 1 + k - y;\n            if (iLess > k)\n                iLess = k;\n            if (iMore < 0)\n                iMore = 0;          \n//          out.println(\"iless == \" + iLess + \" imore == \" + iMore);\n            add = iLess - iMore + 1;\n            if (add < 0)\n                add = 0;\n//          out.println(\"add == \" + add);\n            cur += add;\n            //x - i; y - k + i;\n            iLess = x - 1;\n            iMore = 1 + k - y;\n            if (iLess > k)\n                iLess = k;\n            if (iMore < 0)\n                iMore = 0;\n//          out.println(\"iless == \" + iLess + \" imore == \" + iMore);\n            add = iLess - iMore + 1;\n            if (add < 0)\n                add = 0;\n//          out.println(\"add == \" + add);\n            cur += add;\n            //x - i; y + k - i;\n            iLess = x - 1;\n            iMore = y + k - n;\n            if (iLess > k)\n                iLess = k;\n            if (iMore < 0)\n                iMore = 0;\n//          out.println(\"iless == \" + iLess + \" imore == \" + iMore);\n            add = iLess - iMore + 1;\n            if (add < 0)\n                add = 0;\n//          out.println(\"add == \" + add);\n            cur += add;\n//          out.println(\"cur == \" + cur);\n            //delete double\n            if (x + k <= n)\n                cur--;\n            if (y - k >= 1)\n                cur--;\n            if (x - k >= 1)\n                cur--;\n            if (y + k <= n)\n                cur--;\n        }\n//      throw new RuntimeException();\n    }\n    \n    ProblemB(){\n        boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        try {\n            if (oj) {\n                in = new InputReader(System.in);\n                out = new PrintWriter(System.out);\n            }\n            else {\n                Writer w = new FileWriter(\"output.txt\");\n                in = new InputReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(w);\n            }\n        } catch(Exception e) {\n            throw new RuntimeException(e);\n        }\n        solve();\n        out.close();\n    }\n    public static void main(String[] args){\n        new ProblemB();\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 InputReader(FileReader fr) {\n        reader = new BufferedReader(fr);\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    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}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.concurrent.LinkedBlockingQueue;\n\n\npublic class D {\n\n    static long n;\n    static long x;\n    static long y;\n    static long c;\n    static long f(long t){\n        long s=0;\n        if(t==0)\n            s=1;\n        else{\n            s=(4+4*t)/2*t+1;\n        }\n        if(x+t>n){\n            long c=x+t-n;\n            s-=c*c;\n        }\n        if(x-t<=0){\n            long c=t-x+1;\n            s-=c*c;\n        }\n        if(y+t>n){\n            long c=y+t-n;\n            s-=c*c;\n        }\n        if(y-t<=0){\n            long c=t-y+1;\n            s-=c*c;\n        }\n        if(t>x+y-1){\n            long m=t-x-y+1;\n            s+=m*(m+1)/2;\n        }\n        if (t>x+n-y) {\n            long m=t-x-n+y;\n            s+=m*(m+1)/2;\n        }\n        if (t>n-x+y) {\n            long m=t-n-y+x;\n            s+=m*(m+1)/2;\n        }\n        if (t>n-x+n-y+1) {\n            long m=t-2*n+x+y-1;\n            s+=m*(m+1)/2;\n        }\n        return s;\n    }\n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        Scanner in=new Scanner(new InputStreamReader(System.in));\n        PrintWriter out=new PrintWriter(System.out);\n        \n        n=in.nextLong();\n        x=in.nextLong();\n        y=in.nextLong();\n        c=in.nextLong();\n        \n        \n        \n        \n        long l=0;\n        long r=2*n;\n        while(l<r){\n            long m=(l+r)/2;\n            long ff=f(m);\n            if(ff<c){\n                l=m+1;\n            }\n            else{\n                r=m;\n            }\n        }\n        out.println(l);\n        out.close();\n    }\n\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "//package round156;\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 B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), x = ni(), y = ni();\n\t\tlong c = nl();\n\t\tint l = x-1, r = n-x;\n\t\tint u = y-1, d = n-y;\n\t\tlong low = -1, high = 2*n+3;\n\t\twhile(high - low > 1){\n\t\t\tlong t = (high + low) / 2;\n\t\t\tlong num = diag(t, l, u) + diag(t, r, u) + diag(t, l, d) + diag(t, r, d)\n\t\t\t\t\t+ hor(t, l) + hor(t, r) + hor(t, u) + hor(t, d) + 1;\n\t\t\tif(num >= c){\n\t\t\t\thigh = t;\n\t\t\t}else{\n\t\t\t\tlow = t;\n\t\t\t}\n\t\t}\n\t\tout.println(high);\n\t}\n\t\n\tlong hor(long t, int n)\n\t{\n\t\treturn Math.min(t, n);\n\t}\n\t\n\tlong diag(long t, long r, long u)\n\t{\n\t\tif(t > 2+r+u-2){\n\t\t\treturn r*u;\n\t\t}\n\t\t\n\t\tlong ret = t*(t-1)/2;\n\t\tif(t > r)ret -= (t-r)*(t-r-1)/2;\n\t\tif(t > u)ret -= (t-u)*(t-u-1)/2;\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 B().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", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*; \nimport java.io.*; \nimport java.util.*; \n\npublic class A {\n\tBufferedReader in; \n\tPrintWriter out;\n\tStringTokenizer st; \n\n\n\tpublic String 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\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next()); \n\t}\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tboolean bit(int m, int i) {\n\t\treturn (m & (1 << i)) > 0; \n\t}\n\n\tint n, x, y, c;  \n \n \tlong cnt(int m) {\n \t\tlong ret=0;\n \t\tfor (int i=max(1, y-m); i<=min(n, y+m); i++) {\n \t\t\tint x1 = max(1, x - (m - abs(i - y)));\n \t\t\tint x2 = min(n, x + (m - abs(i - y)));\n \t\t\tret += x2 - x1 + 1; \n \t\t}\n \t\treturn ret;\n \t}\n\n\tpublic void run() {\n\t\tin  = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tn = nextInt(); \n\t\tx = nextInt(); \n\t\ty = nextInt(); \n\t\tc = nextInt();\n\n\t\tint l = 0, r = 1000000;\n\t\tint ans=0;\n\t\twhile (l <= r) {\n\t\t\tint m = (l+r) / 2; \n\t\t\tif (cnt(m) >= c) {\n\t\t\t\tans = m; \n\t\t\t\tr = m-1; \n\t\t\t} else l=m+1; \n\t\t} \n\n\t\tout.println(ans);\n\n\t\tout.close(); \n\t}\n\n\tclass Pair implements Comparable<Pair> {\n\t\tlong x,y; \n\t\tpublic Pair(long x, long y) {\n\t\t\tthis.x=x; \n\t\t\tthis.y=y; \n\t\t}\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (x != o.x) return sign(o.x - x); \n\t\t\treturn sign(y - o.y); \n\t\t}\n\t}\n\n\tint sign(long x) {\n\t\tif (x < 0) return -1; \n\t\tif (x > 0) return 1; \n\t\treturn 0;\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew A().run(); \t\t\n\t}\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MrBenderAndSquare {\n\t\n\tstatic long n, x, y, c;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tKattio io = new Kattio(System.in);\n\t\tn = io.getLong();\n\t\tx = io.getLong();\n\t\ty = io.getLong();\n\t\tc = io.getLong();\n//\t\tfor (int i = 0; i < 10; i++) io.println(f(i));\n//\t\tio.println();\n\t\tlong lo = 0;\n\t\tlong hi = c;\n\t\twhile (lo < hi) {\n\t\t\tlong mid = lo + (hi - lo) / 2;\n\t\t\tif (f(mid) >= c) {\n\t\t\t\thi = mid;\n\t\t\t} else {\n\t\t\t\tlo = mid + 1;\n\t\t\t}\n\t\t}\n\t\tio.println(lo);\n\t\tio.close();\n\t}\n\t\n\tstatic long f(long t) {\n\t\tlong res = 0;\n\t\t// Sides\n\t\tlong left = Math.max(0, t - (x - 1));\n\t\tres -= left*left;\n\t\tlong right = Math.max(0, t - (n - x));\n\t\tres -= right*right;\n\t\tlong up = Math.max(0, t - (y - 1));\n\t\tres -= up*up;\n\t\tlong down = Math.max(0, t - (n - y));\n\t\tres -= down*down;\n\t\t// Middle\n\t\tres += 1 + 2*t*(t+1);\n\t\t// Corners\n\t\tlong upLeft = Math.max(0, t - (x + y) + 1);\n\t\tlong upRight = Math.max(0, t - (n - x + 1 + y) + 1);\n\t\tlong downLeft = Math.max(0, t - (x + n - y + 1) + 1);\n\t\tlong downRight = Math.max(0, t - (n - x + 1 + n - y + 1) + 1);\n\t\tres += upLeft * (upLeft + 1) / 2;\n\t\tres += upRight * (upRight + 1) / 2;\n\t\tres += downLeft * (downLeft + 1) / 2;\n\t\tres += downRight * (downRight + 1) / 2;\n\t\treturn res;\n\t}\n\n\tstatic class Kattio extends PrintWriter {\n\t\tpublic Kattio(InputStream i) {\n\t\t\tsuper(new BufferedOutputStream(System.out));\n\t\t\tr = new BufferedReader(new InputStreamReader(i));\n\t\t}\n\t\tpublic Kattio(InputStream i, OutputStream o) {\n\t\t\tsuper(new BufferedOutputStream(o));\n\t\t\tr = new BufferedReader(new InputStreamReader(i));\n\t\t}\n\n\t\tpublic boolean hasMoreTokens() {\n\t\t\treturn peekToken() != null;\n\t\t}\n\n\t\tpublic int getInt() {\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tpublic double getDouble() { \n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\n\t\tpublic long getLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tpublic String getWord() {\n\t\t\treturn nextToken();\n\t\t}\n\n\n\n\t\tprivate BufferedReader r;\n\t\tprivate String line;\n\t\tprivate StringTokenizer st;\n\t\tprivate String token;\n\n\t\tprivate String peekToken() {\n\t\t\tif (token == null) \n\t\t\t\ttry {\n\t\t\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\t\t\tline = r.readLine();\n\t\t\t\t\t\tif (line == null) return null;\n\t\t\t\t\t\tst = new StringTokenizer(line);\n\t\t\t\t\t}\n\t\t\t\t\ttoken = st.nextToken();\n\t\t\t\t} catch (IOException e) { }\n\t\t\t\treturn token;\n\t\t}\n\n\t\tprivate String nextToken() {\n\t\t\tString ans = peekToken();\n\t\t\ttoken = null;\n\t\t\treturn ans;\n\t\t}\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint side = in.readInt();\n\t\tint row = in.readInt() - 1;\n\t\tint column = in.readInt() - 1;\n\t\tint required = in.readInt();\n\t\tlong left = 0;\n\t\tlong right = 2 * side - 2;\n\t\twhile (left < right) {\n\t\t\tlong current = (left + right) / 2;\n\t\t\tlong result = calculate(row, column, current) + calculate(column, side - row - 1, current) +\n\t\t\t\tcalculate(side - row - 1, side - column - 1, current) + calculate(side - column - 1, row, current) + 1;\n\t\t\tif (result >= required)\n\t\t\t\tright = current;\n\t\t\telse\n\t\t\t\tleft = current + 1;\n\t\t}\n\t\tout.printLine(left);\n\t}\n\n\tprivate long calculate(int row, int column, long current) {\n\t\tcolumn++;\n\t\tlong total = 0;\n\t\tlong mn = Math.min(row, column);\n\t\tlong mx = Math.max(row, column);\n\t\tif (current <= mn)\n\t\t\treturn current * (current + 1) / 2;\n\t\ttotal += mn * (mn + 1) / 2;\n\t\tcurrent -= mn;\n\t\tmx -= mn;\n\t\tif (current <= mx)\n\t\t\treturn total + mn * current;\n\t\ttotal += mn * mx;\n\t\tcurrent -= mx;\n\t\tif (current < mn)\n\t\t\treturn total + (mn - 1) * mn / 2 - (mn - current - 1) * (mn - current) / 2;\n\t\treturn total + (mn - 1) * mn / 2;\n\t}\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n    public void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Main{\n\n    public static long howMany(long n, long x, long y, long s){\n        long res = 0;\n        int cnt = 0;\n        long[] px = new long[9];\n        long[] py = new long[9];\n        if(x - s < 1){\n            px[cnt] = 1;\n            py[cnt++] = y-x+s+1 <= n ? y-x+s+1 : n;\n            px[cnt] = 1;\n            py[cnt++] = x+y-s-1 > 0? x+y-s-1: 1;\n            res += 6;\n        }else{\n            px[cnt] = x-s;\n            py[cnt++] = y;\n            res += 2;\n        }\n        \n        if(y - s < 1){\n            py[cnt] = 1;\n            px[cnt++] = x+y-s-1 > 0 ? x+y-s-1 : 1;\n            py[cnt] = 1;\n            px[cnt++] = x-(y-s)+1 <= n ? x-y+s+1: n;\n            res += 6;\n        }else{\n            px[cnt] = x;\n            py[cnt++] = y-s;\n            res += 2;\n        }\n        \n        if(x + s > n){\n            px[cnt] = n;\n            py[cnt++] = y-(x+s)+n > 0 ? y-(x+s)+n : 1;\n            px[cnt] = n;\n            py[cnt++] = x+s+y - n <= n ? x+s+y-n : n;\n            res += 6;\n        }else{\n            px[cnt] = x+s;\n            py[cnt++] = y;\n            res += 2;\n        }\n        \n        if(y + s > n){\n            py[cnt] = n;\n            px[cnt++] = x+y+s-n <= n? x+y+s-n : n;\n            py[cnt] = n;\n            px[cnt++] = n-(y+s-x) > 0 ? n-(y+s-x) :1;\n            res += 6;\n        }else{\n            px[cnt] = x;\n            py[cnt++] = y+s;\n            res += 2;\n        }\n        \n        px[cnt] = px[0];\n        py[cnt] = py[0];\n        \n        long ret = 0;\n        long sum = 0;\n        for(int i = 0; i < cnt; i++){\n            ret += px[i]*py[i+1]-py[i]*px[i+1];\n            sum += Math.max(Math.abs(px[i]-px[i+1]), Math.abs(py[i]-py[i+1]))+1;\n        }\n        return (4*ret + 4*sum - res)/8;\n    }\n    \n    public static void main(String[] args) throws Exception{\n        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer str = new StringTokenizer(r.readLine());\n        int n = Integer.parseInt(str.nextToken());\n        int x = Integer.parseInt(str.nextToken());\n        int y = Integer.parseInt(str.nextToken());\n        long c = Long.parseLong(str.nextToken());\n        if(c == 1){\n            System.out.println(0);\n            return;\n        }\n        long high = 1;\n        while(howMany(n, x, y, high) < c){\n            high <<= 1;\n        }\n        long low = high>>1;\n        while(high - low > 1){\n            long med = (high+low)/2;\n            if(howMany(n, x, y, med) < c){\n                low = med;\n            }else{\n                high = med;\n            }\n        }\n        System.out.println(high);\n    }\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class taskB {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws NumberFormatException,\n            IOException {\n        taskB solver = new taskB();\n        solver.open();\n        long time = System.currentTimeMillis();\n        solver.solve();\n        if (!\"true\".equals(System.getProperty(\"ONLINE_JUDGE\"))) {\n            System.out.println(\"Spent time: \"\n                    + (System.currentTimeMillis() - time));\n            System.out.println(\"Memory: \"\n                    + (Runtime.getRuntime().totalMemory() - Runtime\n                    .getRuntime().freeMemory()));\n        }\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            String line = in.readLine();\n            if (line == null)\n                return null;\n            st = new StringTokenizer(line);\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    long n, x, y, c;\n\n    long sq(long n) {\n        if (n <= 0) return 0;\n        return n * n;\n    }\n\n    long lrsp(long len, long max) {\n        long cnt = Math.min(len, max);\n        long arpr = (1 + cnt) * cnt / 2;\n        if (len > max) arpr += (len - max) * max;\n        return arpr;\n    }\n\n    long onn(long len) {\n        long up, down, left, right;\n        long toup = x - 1, todown = n - x, toleft = y - 1, toright = n - y;\n        left = Math.min(toleft, len);\n        right = Math.min(toright, len);\n        down = up = sq(len);\n        up -= sq(len - toup);\n        down -= sq(len - todown);\n        len--;\n        if (toright < len) {\n            up -= lrsp(len - toright, toup);\n            down -= lrsp(len - toright, todown);\n        }\n        if (toleft < len) {\n            up -= lrsp(len - toleft, toup);\n            down -= lrsp(len - toleft, todown);\n        }\n\n        return 1 + up + down + left + right;\n    }\n\n    public void solve() throws NumberFormatException, IOException {\n        n = nextInt();\n        x = nextInt();\n        y = nextInt();\n        c = nextInt();\n        long down = 0, up = 2 * n + 13;\n        while (up - down > 2) {\n            long tmp = (up + down) / 2;\n            if (onn(tmp) >= c) up = tmp;\n            else down = tmp;\n        }\n        if (onn(down) >= c) out.println(down);\n        else if (onn(down + 1) >= c) out.println(down + 1);\n        else if (onn(down + 2) >= c) out.println(down + 2);\n        else out.println(down + 3);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Solution\n{\n    static long n, x, y, c;\n\n    static boolean can (long len)\n    {\n        BigInteger blen = BigInteger.valueOf(len);\n        \n        //BigInteger sum = blen.multiply(blen.add(BigInteger.ONE)).multiply(blen.shiftLeft(1).add(BigInteger.ONE)).divide(BigInteger.valueOf(6));\n        BigInteger sum = BigInteger.ONE;\n        sum = sum.add(blen.multiply(blen.add(BigInteger.ONE)).shiftLeft(1));\n        \n        long a1 = Math.max(0, len - x);\n        sum = sum.subtract(BigInteger.valueOf(a1).multiply(BigInteger.valueOf(a1)));\n        \n        long a2 = Math.max(0, len - y);\n        sum = sum.subtract(BigInteger.valueOf(a2).multiply(BigInteger.valueOf(a2)));\n\n        long a3 = Math.max(0, len - (n - 1 - x));\n        sum = sum.subtract(BigInteger.valueOf(a3).multiply(BigInteger.valueOf(a3)));\n        \n        long a4 = Math.max(0, len - (n - 1 - y));\n        sum = sum.subtract(BigInteger.valueOf(a4).multiply(BigInteger.valueOf(a4)));\n        \n        if (y - a1 + 1 < 0)\n        {\n            long b1 = Math.abs(y - a1 + 1);\n            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));\n        }\n        \n        if (y - a3 + 1 < 0)\n        {\n            long b1 = Math.abs(y - a3 + 1);\n            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));\n        }\n        \n        if (y + a1 - 1 >= n)\n        {\n            long b1 = y + a1 - n;\n            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));\n        }\n        \n        if (y + a3 - 1 >= n)\n        {\n            long b1 = y + a3 - n;\n            sum = sum.add(BigInteger.valueOf(b1).multiply(BigInteger.valueOf(b1 + 1)).shiftRight(1));\n        }\n        \n        return sum.compareTo(BigInteger.valueOf(c)) >= 0;\n    }\n\n    public static void main (String argv[])\n    {\n        Scanner in = new Scanner(System.in);\n        \n        n = in.nextLong();\n        x = in.nextLong();\n        y = in.nextLong();\n        c = in.nextLong();\n        x--; y--;\n        \n        long lf = 0, rg = 2 * 1000 * 1000 * 1000 + 3;\n        \n        while (lf != rg)\n        {\n            long mid = (lf + rg) >> 1;\n            \n            if (can(mid))\n                rg = mid;\n            else\n                lf = mid + 1;\n        }\n        \n        System.out.println(lf);\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Solution {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong fang(int s, int x, int y) {\n\t\tif (x > y) { int t = x; x = y; y = t; }\n\t\tif (s + 1 <= x) {\n\t\t\treturn (long)(s + 1) * (s + 2) / 2;\n\t\t}\n\t\tif (s + 1 <= y) {\n\t\t\treturn (long)x * (x + 1) / 2 + (long)(s + 1 - x) * x;\n\t\t}\n\t\tif (s + 1 >= x + y - 1) {\n\t\t\treturn (long)x * y;\n\t\t}\n\t\tlong q = x + y - 1 - s - 1;\n\t\treturn (long)x * y - q * (q + 1) / 2;\n\t}\n\t\n\tlong f(int s, int n, int x, int y) {\n\t\tlong ans = fang(s, n - x + 1, n - y + 1) + fang(s, n - x + 1, y) + fang(s, x, n - y + 1) + fang(s, x, y);\n\t\tans -= Math.min(s + 1, n - x + 1) + Math.min(s + 1, x) + Math.min(s + 1, n - y + 1) + Math.min(s + 1, y);\n\t\treturn ans + 1;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint x = nextInt(), y = nextInt();\n\t\tlong c = nextInt();\n\t\tif (c == 1) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint bg = 0, ed = 2 * n;\n\t\twhile (ed > bg + 1) {\n\t\t\tint mm = (bg + ed) / 2;\n\t\t\tif (f(mm, n, x, y) >= c) ed = mm; else bg = mm;\n\t\t}\n\t\tout.println(ed);\n\t}\n\t\n\tvoid run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n//\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n//\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tnew Solution().run();\n\t}\n\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.util.TreeSet;\n\npublic class B {\n\tpublic static void main(String[] args) {\n\t\tMScanner sc = new MScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tlong N = sc.nextLong();\n\t\tlong X = sc.nextLong();\n\t\tlong Y = sc.nextLong();\n\t\tlong C = sc.nextLong();\n\n\t\tlong low = 0;\n\t\tlong high = N*2;\n\t\tlong mid = 0;\n\t\tlong ans = 0;\n\t\twhile (low <= high) {\n\t\t\tmid = (low + high) >> 1;\n\t\t\tlong painted = F(mid, X-1, Y-1, N);\n\t\t\tif (painted < C) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\tans = mid;\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tprivate static long F(long mid, long x, long y, long n) {\n\t\tlong base = 2 * mid * (mid + 1) + 1;\n\t\tbase -= excess(mid - x);\n\t\tbase -= excess(mid - y);\n\t\tbase -= excess(mid - (n-1-x));\n\t\tbase -= excess(mid - (n-1-y));\n\t\tbase += corner(mid - (x + y + 1));\n\t\tbase += corner(mid - (x + (n - y - 1) + 1));\n\t\tbase += corner(mid - ((n - x - 1) + y + 1));\n\t\tbase += corner(mid - (1 + (n - 1 - y) + (n - 1 - x)));\n\t\treturn base;\n\t}\n\n\tprivate static long corner(long a) {\n\t\tif (a < 0)return 0;\n\t\treturn (a * a + a) >> 1;\n\t}\n\n\tprivate static long excess(long thing) {\n\t\tif(thing<0)return 0;\n\t\treturn thing * thing;\n\t}\n\n\tstatic class MScanner {\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 MScanner() {\n\t\t\tstream = System.in;\n\t\t\t// stream = new FileInputStream(new File(\"dec.in\"));\n\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\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tint[] nextInt(int N) {\n\t\t\tint[] ret = new int[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextInt();\n\t\t\treturn ret;\n\t\t}\n\n\t\tint[][] nextInt(int N, int M) {\n\t\t\tint[][] ret = new int[N][M];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextInt(M);\n\t\t\treturn ret;\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tlong[] nextLong(int N) {\n\t\t\tlong[] ret = new long[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextLong();\n\t\t\treturn ret;\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tdouble[] nextDouble(int N) {\n\t\t\tdouble[] ret = new double[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextDouble();\n\t\t\treturn ret;\n\t\t}\n\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\n\t\tString[] next(int N) {\n\t\t\tString[] ret = new String[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = next();\n\t\t\treturn ret;\n\t\t}\n\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\n\t\tString[] nextLine(int N) {\n\t\t\tString[] ret = new String[N];\n\t\t\tfor (int a = 0; a < N; a++)\n\t\t\t\tret[a] = nextLine();\n\t\t\treturn ret;\n\t\t}\n\n\t}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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\t\n\tint n;\n\t\n\tboolean inBound (int x, int y) {\n\t\treturn x >= 1 && y >= 1 && x <= n && y <= n;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tn = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\t\n\t\tint yu = y;\n\t\tint yd = y;\n\t\tint xl = x;\n\t\tint xr = x; \n\t\t\n\t\tint current = 1;\n\t\tint time = 0;\n\t\twhile (current < c) {\n\t\t\ttime++;\n\t\t\tyu--;\n\t\t\tyd++;\n\t\t\txl--;\n\t\t\txr++;\n\t\t\t// left - up\n\t\t\t{\n\t\t\t\tint cur = time - 1;\n\t\t\t\tif (yu < 1) {\n\t\t\t\t\tcur -= (-yu);\n\t\t\t\t}\n\t\t\t\tif (xl < 1) {\n\t\t\t\t\tcur -= (-xl);\n\t\t\t\t}\n\t\t\t\tif (cur > 0) {\n\t\t\t\t\tcurrent += cur;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// right - up\n\t\t\t{\n\t\t\t\tint cur = time - 1;\n\t\t\t\tif (yu < 1) {\n\t\t\t\t\tcur -= (-yu);\n\t\t\t\t}\n\t\t\t\tif (xr > n) {\n\t\t\t\t\tcur -= (xr - n - 1);\n\t\t\t\t}\n\t\t\t\tif (cur > 0) {\n\t\t\t\t\tcurrent += cur;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// left - down\n\t\t\t{\n\t\t\t\tint cur = time - 1;\n\t\t\t\tif (yd > n) {\n\t\t\t\t\tcur -= (yd - n - 1);\n\t\t\t\t}\n\t\t\t\tif (xl < 1) {\n\t\t\t\t\tcur -= (-xl);\n\t\t\t\t}\n\t\t\t\tif (cur > 0) {\n\t\t\t\t\tcurrent += cur;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// right - down\n\t\t\t{\n\t\t\t\tint cur = time - 1;\n\t\t\t\tif (yd > n) {\n\t\t\t\t\tcur -= (yd - n - 1);\n\t\t\t\t}\n\t\t\t\tif (xr > n) {\n\t\t\t\t\tcur -= (xr - n - 1);\n\t\t\t\t}\n\t\t\t\tif (cur > 0) {\n\t\t\t\t\tcurrent += cur;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (inBound(x, yd)) current++;\n\t\t\tif (inBound(x, yu)) current++;\n\t\t\tif (inBound(xl, y)) current++;\n\t\t\tif (inBound(xr, y)) current++;\n\t\t}\n\t\t\n\t\tout.println(time);\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\n\tstatic Throwable uncaught;\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\tMain.uncaught = 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 t = new Thread(null, new Main(), \"\", (1 << 26));\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\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\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\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}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t//System.out.println(f(1,100,30));\n\t\tString S[]=br.readLine().split(\" \");\n\t\tint N=Integer.parseInt(S[0]);\n\t\tint x=Integer.parseInt(S[1]);\n\t\tint y=Integer.parseInt(S[2]);\n\t\tint c=Integer.parseInt(S[3]);\n\t\tint lo=0;\n\t\t//System.out.println(Long.MAX_VALUE);\n\t\tint hi=1000000000;\n\t\twhile(hi-lo>=10)\n\t\t\t{\n\t\t\tint steps=(hi+lo)/2;\n\t\t\t//System.out.println(\"checking \"+steps+\" hi= \"+hi+\" lo = \"+lo);\n\t\t\tlong total=f(x,y,steps)+f(N-x+1,y,steps)+f(N-x+1,N-y+1,steps)+f(x,N-y+1,steps);\n\t\t\t//System.out.println(f(x,y,steps)+\" \"+f(N-x+1,y,steps)+\" \"+f(N-x+1,N-y+1,steps)+\" \"+f(x,N-y+1,steps));\n\t\t\ttotal-=3;\t\t\t//x,y\n\t\t\ttotal-=Math.min(steps,x-1);\t\t\t//left\n\t\t\ttotal-=Math.min(steps,y-1);\t\t\t//down\n\t\t\ttotal-=Math.min(steps,N-x);\t\t\t//right\n\t\t\ttotal-=Math.min(steps,N-y);\t\t\t//up\n\t\t\t//System.out.println(\"total = \"+total);\n\t\t\tif(total>=c)\n\t\t\t\thi=steps+1;\n\t\t\telse\n\t\t\t\tlo=steps-1;\n\t\t\t}\n\t\tfor(int steps=lo;steps<=hi;steps++)\n\t\t\t{\n\t\t\t//System.out.println(\"checking \"+steps);\n\t\t\tlong total=f(x,y,steps)+f(N-x+1,y,steps)+f(N-x+1,N-y+1,steps)+f(x,N-y+1,steps);\n\t\t\ttotal-=3;\t\t\t//x,y\n\t\t\ttotal-=Math.min(steps,x-1);\t\t\t//left\n\t\t\ttotal-=Math.min(steps,y-1);\t\t\t//down\n\t\t\ttotal-=Math.min(steps,N-x);\t\t\t//right\n\t\t\ttotal-=Math.min(steps,N-y);\t\t\t//up\n\t\t\t//System.out.println(\"total = \"+total);\n\t\t\tif(total>=c)\n\t\t\t\t{\n\t\t\t\tSystem.out.println(steps);\n\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tpublic static long f(long a, long b, long steps)\n\t\t{\n\t\t//System.out.println(\"f(\"+a+\",\"+b+\",\"+steps+\")\");\n\t\tsteps++;\n\t\tlong A=Math.min(a,b);\n\t\tlong B=Math.max(a,b);\n\t\tlong ans=0;\n\t\tif(steps>=(A+B))\n\t\t\t{\n\t\t\t//System.out.println(\"case 1\");\n\t\t\tans= A*B;\n\t\t\t}\n\t\telse if(steps<=A)\n\t\t\t{\n\t\t\t//System.out.println(\"case 2\");\n\t\t\tans= (steps*(steps+1))/2;\n\t\t\t}\n\t\telse if(steps>A&&steps<=B)\n\t\t\t{\n\t\t\t//System.out.println(\"case 3\");\n\t\t\tans= (A*(A+1))/2+(steps-A)*A;\n\t\t\t}\n\t\telse if(steps>B)\n\t\t\t{\n\t\t\t//System.out.println(\"case 4\");\n\t\t\tans= (A*(A+1))/2+(B-A)*A+(steps-B)*A-((steps-B)*(steps-B+1))/2;\n\t\t\t}\n\t\t//System.out.println(\"\\treturning \"+ans);\n\t\treturn ans;\n\t\t}\n\t}\n\n//must declare new classes here", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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           //       |    \\   /        \\  |    |   -----   -------\n    \n    public static long check(long mid,long x,long y,long n)\n    {\n        long ans=2*mid*mid+2*mid+1;\n        long uleft=Math.max(0,mid-x+1);\n        long dleft=Math.max(0,mid-(n-x));\n        long lleft=Math.max(0,mid-y+1);\n        long rleft=Math.max(0,mid-(n-y));\n        ans-=uleft*uleft+dleft*dleft+lleft*lleft+rleft*rleft;\n        \n        ans+=(Math.max(0,mid-(x+y-1))*(Math.max(0,mid-(x+y-1))+1))/2;\n        ans+=(Math.max(0,mid-(x+n-y))*(Math.max(0,mid-(x+n-y))+1))/2;\n        ans+=(Math.max(0,mid-(y+n-x))*(Math.max(0,mid-(y+n-x))+1))/2;\n        ans+=(Math.max(0,mid-(n-x+n-y+1))*(Math.max(0,mid-(n-x+n-y+1))+1))/2;\n        return ans;\n    }\n    public static void main(String[] args)throws IOException\n    {\n        PrintWriter out= new PrintWriter(System.out);\n        Reader sc=new Reader();\n        long n=sc.l();\n        long x=sc.l();\n        long y=sc.l();\n        long c=sc.l();\n        long low=0;\n        long high=(long)Math.pow(10,9);\n        while(low<high)\n        {\n            long mid=(low+high)/2;\n            if(check(mid,x,y,n)>=c)\n            high=mid;\n            else\n            low=mid+1;\n        }\n        out.println(low);\n        out.flush();\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long n = in.nextInt();\n        long x = in.nextInt();\n        long y = in.nextInt();\n        long c = in.nextInt();\n        if (c == 1) {\n            out.println(0);\n            return;\n        }\n\n        long left = 1, right = 2 * n, middle, res = -1;\n        long val = getNumberOfCells(x, y, n, 2);\n\n        while (left <= right) {\n            middle = (left + right) / 2;\n            long numberOfCells = getNumberOfCells(x, y, n, middle);\n            if (numberOfCells < c) {\n                left = middle + 1;\n            } else {\n                res = middle;\n                right = middle - 1;\n            }\n        }\n        out.println(res);\n    }\n\n    private long getNumberOfCells(long x, long y, long n, long middle) {\n        long res = 0;\n        res += calc(x, y, middle + 1);\n        res += calc(n - x + 1, y, middle + 1);\n        res += calc(x, n - y + 1, middle + 1);\n        res += calc(n - x + 1, n - y + 1, middle + 1);\n        res -= calcX(x, n, middle);\n        res -= calcX(y, n, middle);\n        --res;\n        return res;\n    }\n\n    private long calcX(long x, long n, long size) {\n        long left = x - size;\n        long right = x + size;\n        left = Math.max(left, 1);\n        right = Math.min(right, n);\n        if (left <= right) {\n            return right - left + 1;\n        }\n        return 0;\n    }\n\n    private long calc(long x, long y, long size) {\n        if (size <= Math.min(x, y)) {\n            return (1 + size) * size / 2;\n        }\n        if (size >= x + y - 1) {\n            return x * y;\n        }\n        if (size > Math.max(x, y)) {\n            return x * y - calc(x, y, x + y - 1 - size);\n        }\n        long min = Math.min(x, y);\n        long res = (1 + min) * min / 2;\n        long rest = size - min;\n        res += rest * min;\n        return res;\n    }\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer stt;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n    }\n\n    public String nextLine() {\n        try {\n            return reader.readLine();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    public String nextString() {\n        while (stt == null || !stt.hasMoreTokens()) {\n            stt = new StringTokenizer(nextLine());\n        }\n        return stt.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextString());\n    }\n\n}\n\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class BBi implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new BBi()).run();\n\t}\n\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer in;\n\tPrintWriter out = new PrintWriter(System.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\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\tint n, x, y;\n\n\tpublic long count(long z) {\n\t\tlong total = 0;\n\n\t\tlong[][] c = new long[][] { { x, y }, { y, n - x + 1 },\n\t\t\t\t{ n - x + 1, n - y + 1 }, { n - y + 1, x } };\n\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tlong inside = z;\n\n\t\t\tfor (int j = 0; j < c[i].length; j++) {\n\t\t\t\tif (z > c[i][j]) {\n\t\t\t\t\ttotal += Math.min(z - c[i][j], c[i][1 - j]) * c[i][j];\n\t\t\t\t\tinside -= (z - c[i][j]);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (z > c[i][0] && z > c[i][1]) {\n\t\t\t\ttotal -= Math.min(z - c[i][0], c[i][1])\n\t\t\t\t\t\t* Math.min(z - c[i][1], c[i][0]);\n\t\t\t}\n\n\t\t\tif (inside > 0)\n\t\t\t\ttotal += inside * (inside + 1) / 2;\n\t\t}\n\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\ttotal -= Math.min(z, c[i][0]);\n\t\t}\n\n\t\treturn total + 1;\n\t}\n\n\tpublic long solve(int n, int x, int y, long c) throws IOException {\n\t\tthis.n = n;\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\t\n\t\tlong l = 0;\n\t\tlong r = 2L * n + 2;\n\t\twhile (r - l > 1) {\n\t\t\tlong z = (l + r) / 2;\n\n\t\t\tif (c <= count(z)) {\n\t\t\t\tr = z;\n\t\t\t} else {\n\t\t\t\tl = z;\n\t\t\t}\n\t\t}\n\n\t\treturn r - 1;\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tout.println(solve(nextInt(), nextInt(), nextInt(), nextLong()));\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", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class B {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic B () {\n\t\tlong N = sc.nextInt();\n\t\tlong X = sc.nextInt() - 1;\n\t\tlong Y = sc.nextInt() - 1;\n\t\tlong C = sc.nextInt();\n\n\t\tlong [] A1 = new long [] { X, Y };\n\t\tlong [] A2 = new long [] { X, Y };\n\t\tlong [] B1 = new long [] { X, Y };\n\t\tlong [] B2 = new long [] { X, Y };\n\t\tlong [] C1 = new long [] { X, Y };\n\t\tlong [] C2 = new long [] { X, Y };\n\t\tlong [] D1 = new long [] { X, Y };\n\t\tlong [] D2 = new long [] { X, Y };\n\t\t\n\t\tlong cnt = 1, T = 0;\n\t\t\n\t\twhile (cnt < C) {\n\t\t\tif (A1[0] > 0) --A1[0]; else --A1[1];\n\t\t\tif (A2[0] > 0) --A2[0]; else ++A2[1];\n\t\t\t\n\t\t\tif (B1[1] > 0) --B1[1]; else --B1[0];\n\t\t\tif (B2[1] > 0) --B2[1]; else ++B2[0];\n\t\t\t\n\t\t\tif (C1[0] < N-1) ++C1[0]; else --C1[1];\n\t\t\tif (C2[0] < N-1) ++C2[0]; else ++C2[1];\n\t\t\t\n\t\t\tif (D1[1] < N-1) ++D1[1]; else --D1[0];\n\t\t\tif (D2[1] < N-1) ++D2[1]; else ++D2[0];\n\t\t\t\t\t\t\n\t\t\tlong [] Z = { B1[0] - A1[0],\n\t\t\t\t\t\t  C1[0] - B2[0],\n\t\t\t\t\t\t  C2[0] - D2[0],\n\t\t\t\t\t\t  D1[0] - A2[0] };\n\t\t\t\n\t\t\tfor (long z : Z)\n\t\t\t\tif (z >= 0)\n\t\t\t\t\tcnt += (z+1);\n\t\t\t\n\t\t\tif (Arrays.equals(A1, A2)) --cnt;\n\t\t\tif (Arrays.equals(B1, B2)) --cnt;\n\t\t\tif (Arrays.equals(C1, C2)) --cnt;\n\t\t\tif (Arrays.equals(D1, D2)) --cnt;\n\t\t\t\n\t\t\t++T;\n\t\t}\n\t\t\n\t\texit(T);\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic MyScanner sc;\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print (Object o, Object... a) {\n\t\tpw.println(build(o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tfor (Object o : a)\n\t\t\tappend(b, o);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i));\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p);\n\t\t} else\n\t\t\tb.append(\" \").append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tsc = new MyScanner ();\n\t\tnew B();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class ProblemB {\n    \n    public static void main(String[] args) throws IOException {\n        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(System.out);\n\n        String[] line = s.readLine().split(\" \");\n        long n = Long.valueOf(line[0]);\n        long y = Long.valueOf(line[1]);\n        long x = Long.valueOf(line[2]);\n        long c = Long.valueOf(line[3]);\n        \n        long min = 0;\n        long max = n*2L+20;\n        for (int cnt = 0 ; cnt < 300 ; cnt++) {\n            long med = (min+max) / 2L;\n            long ct = isok(med, n, x, y, c); \n            if (ct >= c) {\n                max = med;\n            } else {\n                min = med+1;\n            }\n        }\n        \n        long lst = max;\n        for (long d = -2 ; d <= 2 ; d++) {\n            if (max+d >= 0 && isok(max+d, n, x, y, c) >= c) {\n                lst = Math.min(lst, max+d);\n            }\n        }\n        \n        out.println(lst);\n        out.flush();\n    }\n    \n\n    private static long isok(long time, long n, long x, long y, long c) {\n        long total = time * 2 * (time + 1) + 1;\n        long top = y - time;\n        if (top <= 0) {\n            long dy = Math.abs(top)+1;\n            total -= dy*dy;\n            long over = dy - x;\n            if (over >= 1) {\n                total += (1L + over) * over / 2; \n            }\n            over = dy - ((n + 1) - x);\n            if (over >= 1) {\n                total += (1L + over) * over / 2; \n            }\n        }\n        \n        long bottom = y + time;\n        if (bottom > n) {\n            long dy = Math.abs(bottom-n);\n            total -= dy*dy;\n            long over = dy - x;\n            if (over >= 1) {\n                total += (1L + over) * over / 2; \n            }\n            over = dy - ((n + 1) - x);\n            if (over >= 1) {\n                total += (1L + over) * over / 2; \n            }\n        }\n        \n        long left = x - time;\n        if (left <= 0) {\n            long dy = Math.abs(left)+1;\n            total -= dy*dy;\n        }\n\n        long right = x + time;\n        if (right > n) {\n            long dy = Math.abs(right-n);\n            total -= dy*dy;\n        }\n        return total;\n    }\n\n    public static void debug(Object... os){\n        System.err.println(Arrays.deepToString(os));\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws NumberFormatException,\n            IOException {\n        Solver solver = new Solver();\n        solver.open();\n        solver.solve();\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            String line = in.readLine();\n            if (line == null)\n                return null;\n            st = new StringTokenizer(line);\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    int n;\n\n    class Otr {\n        int x1, y1, x2, y2;\n        int dx, dy;\n\n        public Otr(int x, int y, int dx, int dy) {\n            super();\n            this.x1 = x;\n            this.y1 = y;\n            this.x2 = x;\n            this.y2 = y;\n            this.dx = dx;\n            this.dy = dy;\n        }\n\n        int getAns() {\n            if (x1 == x2 && y1 == y2) {\n                int nx1 = x1 + dx;\n                int ny2 = y2 + dy;\n\n                if ((nx1 <= 0 || nx1 > n) && (ny2 <= 0 || ny2 > n)) {\n                    return 0;\n                }\n            }\n\n            x1 += dx;\n            if (x1 <= 0) {\n                x1 = 1;\n                y1 += dy;\n            }\n            if (x1 > n) {\n                x1 = n;\n                y1 += dy;\n            }\n\n            y2 += dy;\n            if (y2 <= 0) {\n                y2 = 1;\n                x2 += dx;\n            }\n            if (y2 > n) {\n                y2 = n;\n                x2 += dx;\n            }\n\n            return Math.abs(x1 - x2) + 1;\n        }\n\n        @Override\n        public String toString() {\n            return \"(\" + x1 + \",\" + y1 + \")->(\" + x2 + \",\" + y2 + \")\";\n        }\n    }\n\n    int[] dxs = { -1, -1, 1, 1 };\n    int[] dys = { -1, 1, -1, 1 };\n\n    public void solve() throws NumberFormatException, IOException {\n        n = nextInt();\n        int x = nextInt();\n        int y = nextInt();\n        long c = nextLong();\n        long now = 1;\n\n        Otr[] otr = new Otr[4];\n        for (int i = 0; i < 4; i++) {\n            otr[i] = new Otr(x, y, dxs[i], dys[i]);\n        }\n\n        int result = 0;\n\n        while (now < c) {\n            for (int i = 0; i < 4; i++) {\n                now += otr[i].getAns();\n            }\n\n            for (int i = 0; i < 3; i++) {\n                for (int j = i + 1; j < 4; j++) {\n                    Otr o1 = otr[i];\n                    Otr o2 = otr[j];\n\n                    if (o1.x1!=o1.x2 || o1.y1!=o1.y2){\n                        if (o2.x1!=o2.x2 || o2.y1!=o2.y2){\n                            if (o1.x1 == o2.x1 && o1.y1 == o2.y1) {\n                                now--;\n                            }\n                            if (o1.x1 == o2.x2 && o1.y1 == o2.y2) {\n                                now--;\n                            }\n                            if (o1.x2 == o2.x1 && o1.y2 == o2.y1) {\n                                now--;\n                            }\n                            if (o1.x2 == o2.x2 && o1.y2 == o2.y2) {\n                                now--;\n                            }\n                        }else{\n                            if (o1.x1 == o2.x1 && o1.y1 == o2.y1) {\n                                now--;\n                            }\n                            if (o1.x2 == o2.x1 && o1.y2 == o2.y1) {\n                                now--;\n                            }\n                        }\n                    }else{\n                        if (o2.x1!=o2.x2 || o2.y1!=o2.y2){\n                            if (o1.x2 == o2.x1 && o1.y2 == o2.y1) {\n                                now--;\n                            }\n                            if (o1.x2 == o2.x2 && o1.y2 == o2.y2) {\n                                now--;\n                            }\n                        }else{\n                            if (o1.x1 == o2.x1 && o1.y1 == o2.y1) {\n                                now--;\n                            }\n                        }\n                    }\n                    \n                    \n                }\n            }\n\n            result++;\n        }\n\n        out.println(result);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "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 s = 1;\n\n    while (s < c) {\n      t++;\n\n      s += (t * 4) + ((t >= x + y) ? (t - x - y + 1) : 0)\n           - ((t >= x) ? (t - x) * 2 + 1 : 0)\n           - ((t >= y) ? (t - y) * 2 + 1 : 0)\n           + ((t >= x + n - y + 1) ? (t - x - n + y) : 0)\n           + ((t >= n - x + 1 + y) ? (t - n + x - y) : 0)\n           - ((t >= n - x + 1) ? (t - n + x - 1) * 2 + 1 : 0)\n           - ((t >= n - y + 1) ? (t - n + y - 1) * 2 + 1 : 0);\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}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nipuna Samarasekara\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n    /////////////////////////////////////////////////////////////\n long n,x,y,c;\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n     n=in.nextLong();\n x=in.nextLong();\ny=in.nextLong();\nc=in.nextLong();\n  long td=-1,tup=2*(n-1);\n     while(Math.abs(td-tup)>1){\n      long mid=(td+tup)/2;\n       if(chk(mid))tup=mid;\n         else td=mid;\n     }\n        out.println(tup);\n\n    }\n\n    private boolean chk(long t) {\n     long ct=-3;\n        long d=x,w=y;\n        if(w>d){\n            long tt=w;\n            w=d;d=tt;\n        }\n\n        if(t>=d+w-2) ct+=d*w;\n        else if(t<w&&t<d) {\n          //  long k=w;\n            ct+=(t+1)*(t+2)/2;\n        }\n        else if(t>=w&&t<d) {\n           // long k=w;\n            ct+=w*(w+1)/2;\n            long k=t-(w-1);\n            ct+=k*w;\n        }\n        else if(t>=w&&t>=d) {\n            // long k=w;\n\n            ct+=w*d;\n            long k=w-2-(t-d);\n            ct-=k*(k+1)/2;\n        }\n        ////\n        w=x;d=n+1-y;\n        if(w>d){\n            long tt=w;\n            w=d;d=tt;\n        }\n\n        if(t>=d+w-2) ct+=d*w;\n        else if(t<w&&t<d) {\n            //  long k=w;\n            ct+=(t+1)*(t+2)/2;\n        }\n        else if(t>=w&&t<d) {\n            // long k=w;\n            ct+=w*(w+1)/2;\n            long k=t-(w-1);\n            ct+=k*w;\n        }\n        else if(t>=w&&t>=d) {\n            // long k=w;\n\n            ct+=w*d;\n            long k=w-2-(t-d);\n            ct-=k*(k+1)/2;\n        }\n\n        w=n+1-x;d=y;\n        if(w>d){\n            long tt=w;\n            w=d;d=tt;\n        }\n\n        if(t>=d+w-2) ct+=d*w;\n        else if(t<w&&t<d) {\n            //  long k=w;\n            ct+=(t+1)*(t+2)/2;\n        }\n        else if(t>=w&&t<d) {\n            // long k=w;\n            ct+=w*(w+1)/2;\n            long k=t-(w-1);\n            ct+=k*w;\n        }\n        else if(t>=w&&t>=d) {\n            // long k=w;\n\n            ct+=w*d;\n            long k=w-2-(t-d);\n            ct-=k*(k+1)/2;\n        }\n        w=n+1-x;d=n+1-y;\n        if(w>d){\n            long tt=w;\n            w=d;d=tt;\n        }\n\n        if(t>=d+w-2) ct+=d*w;\n        else if(t<w&&t<d) {\n            //  long k=w;\n            ct+=(t+1)*(t+2)/2;\n        }\n        else if(t>=w&&t<d) {\n            // long k=w;\n            ct+=w*(w+1)/2;\n            long k=t-(w-1);\n            ct+=k*w;\n        }\n        else if(t>=w&&t>=d) {\n            // long k=w;\n\n            ct+=w*d;\n            long k=w-2-(t-d);\n            ct-=k*(k+1)/2;\n        }\n        ct-=Math.min(t,x-1);\n        ct-=Math.min(t,y-1);\n        ct-=Math.min(t,n-x);\n        ct-=Math.min(t,n-y);\n       // System.out.println(t+\" \"+ct);\n        if(ct>=c)return true;\n        else\n        return false;\n    }\n\n}\n\nclass FastScanner extends BufferedReader {\n\n    public FastScanner(InputStream is) {\n        super(new InputStreamReader(is));\n    }\n\n    public int read() {\n        try {\n            int ret = super.read();\n//            if (isEOF && ret < 0) {\n//                throw new InputMismatchException();\n//            }\n//            isEOF = ret == -1;\n            return ret;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    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 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", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tlong f(int x, int y, int sz) {\n\t\tif (x > y) {\n\t\t\tint tmp = x;\n\t\t\tx = y;\n\t\t\ty = tmp;\n\t\t}\n\t\tif (sz <= x)\n\t\t\treturn (long) sz * (sz + 1) / 2;\n\t\tif (sz >= x + y - 1)\n\t\t\treturn (long) x * y;\n\t\tlong val = x * (x + 1) / 2;\n\t\tif (sz <= y)\n\t\t\treturn val + (long) (sz - x) * x;\n\n\t\tlong rest = x + y - 1 - sz;\n\t\treturn (long) x * y - (long) rest * (rest + 1) / 2;\n\t}\n\n\tlong count(int x, int y, int n, int time) {\n\t\tlong DL = f(x + 1, y + 1, time + 1);\n\t\tlong DR = f(n - x, y + 1, time + 1);\n\t\tlong UL = f(x + 1, n - y, time + 1);\n\t\tlong UR = f(n - x, n - y, time + 1);\n//\t\tif (time == 1)\n//\t\t\tSystem.err.println(DL + \" \" + DR + \" \" + UL + \" \" + UR);\n\t\tlong L = Math.min(x + 1, time + 1);\n\t\tlong R = Math.min(n - x, time + 1);\n\t\tlong U = Math.min(n - y, time + 1);\n\t\tlong D = Math.min(y + 1, time + 1);\n//\t\tif (time == 1)\n//\t\t\tSystem.err.println(L + \" \" + R + \" \" + U + \" \" + D);\n\t\treturn DL + DR + UL + UR - L - R - U - D + 1;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint x = nextInt() - 1;\n\t\tint y = nextInt() - 1;\n\t\tlong need = nextLong();\n\n\t\tif (need == 1) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tint low = 0;\n\t\tint high = Math.max(x, n - 1 - x) + Math.max(y, n - 1 - y);\n\t\t\n//\t\tfor (int i = 0; i <= 100; i++)\n//\t\t\tSystem.err.println(count(x, y, n, i));\n\n\t\twhile (low < high - 1) {\n\t\t\tint mid = (int) (((long) low + high) / 2);\n\t\t\tif (count(x, y, n, mid) >= need)\n\t\t\t\thigh = mid;\n\t\t\telse\n\t\t\t\tlow = mid;\n\t\t}\n\n\t\tout.println(high);\n\n\t}\n\n\tB() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew B();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF256B extends PrintWriter {\n\tCF256B() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF256B o = new CF256B(); o.main(); o.flush();\n\t}\n\n\tlong count(int n, int x, int y, int r) {\n\t\tlong a = 2L * r * r + 2 * r + 1;\n\t\tint w;\n\t\tif ((w = 1 - (x - r)) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = 1 - (y - r)) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = (x + r) - n) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = (y + r) - n) > 0)\n\t\t\ta -= (long) w * w;\n\t\tif ((w = r - 1 - (x - 1) - (y - 1)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\tif ((w = r - 1 - (x - 1) - (n - y)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\tif ((w = r - 1 - (n - x) - (y - 1)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\tif ((w = r - 1 - (n - x) - (n - y)) > 0)\n\t\t\ta += (long) w * (w + 1) / 2;\n\t\treturn a;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint lower = -1, upper = c;\n\t\twhile (upper - lower > 1) {\n\t\t\tint r = (lower + upper) / 2;\n\t\t\tif (count(n, x, y, r) >= c)\n\t\t\t\tupper = r;\n\t\t\telse\n\t\t\t\tlower = r;\n\t\t}\n\t\tprintln(upper);\n\t}\n}\n", "complexity": "logn", "problem": "256_B. Mr. Bender and Square", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Proj implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer str;\n\n\tpublic void solve() throws IOException {\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n                int g = 0;\n\t\tlong x = l ^ r;\n\t\tlong i = 1;\n\t\twhile (x >= i) {\n\t\t\ti = i * 2;\n\t\t}\n\t\tif (x >= i) {\n\t\t\tout.println(x);\n\t\t} else\n\t\t\tout.println(i - 1);\n\t}\n\n\tpublic String nextToken() throws IOException {\n\t\twhile (str == null || !str.hasMoreTokens()) {\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn str.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 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\tin.close();\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Proj()).start();\n\t}\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "/**\n * Created with IntelliJ IDEA.\n * User: brzezinsky\n * Date: 12/16/12\n * Time: 7:44 PM\n * To change this template use File | Settings | File Templates.\n */\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.StringTokenizer;\n\npublic class E extends Thread {\n    public E(String inputFileName, String outputFileName) {\n        try {\n            if (inputFileName != null) {\n                this.input = new BufferedReader(new FileReader(inputFileName));\n            } else {\n                this.input = new BufferedReader(new InputStreamReader(System.in));\n            }\n            if (outputFileName != null) {\n                this.output = new PrintWriter(outputFileName);\n            } else {\n                this.output = new PrintWriter(System.out);\n            }\n            this.setPriority(Thread.MAX_PRIORITY);\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            e.printStackTrace();\n            System.exit(666);\n        }\n    }\n\n    private void solve() throws Throwable {\n        long l = nextLong(), r = nextLong();\n        output.println(Math.max(Long.highestOneBit(l ^ r) * 2 - 1, 0L));\n    }\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.close();\n        }\n    }\n\n    public static void main(String... args) {\n        new E(null, null).start();\n    }\n\n    private int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    private double nextDouble() throws IOException {\n        return Double.parseDouble(next());\n    }\n\n    private long nextLong() throws IOException {\n        return Long.parseLong(next());\n    }\n\n    private String next() throws IOException {\n        while (tokens == null || !tokens.hasMoreTokens()) {\n            tokens = new StringTokenizer(input.readLine());\n        }\n        return tokens.nextToken();\n    }\n\n    private StringTokenizer tokens;\n    private BufferedReader input;\n    private PrintWriter output;\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Long.*;\nimport static java.lang.Character.*;\nimport static java.lang.String.*;\n@SuppressWarnings(\"unused\")\n\npublic class round169D {\n    static PrintWriter out = new PrintWriter(System.out);\n    static BufferedReader br = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static int nextInt() throws Exception {\n        return Integer.parseInt(next());\n    }\n    static String next() throws Exception {\n        while (true) {\n            if (st.hasMoreTokens()) {\n                return st.nextToken();\n            }\n            String s = br.readLine();\n            if (s == null) {\n                return null;\n            }\n            st = new StringTokenizer(s);\n        }\n    }\n    public static void main(String[] args)throws Exception {        \n        long l = parseLong(next());\n        long r = parseLong(next());\n        long [] min = new long [61];\n        for(int i = 1 ; i <= 60 ; ++i){//(2^i)-1 is obtained by min[i]^min[i]+1\n            min[i] = (long) pow(2, i - 1) - 1;          \n        }\n        for(int i = 60 ; i >= 0 ; --i){//try to get 2^i-1 as answer.                \n            if(min[i] >= r)\n                continue;\n            if(min[i] >= l && min[i] + 1 <= r){             \n                out.println((1L << i) - 1);\n                out.flush();\n                return;\n            }\n            if(min[i] < l){\n                long one_jump = (long) pow(2, i);\n                long  jumps = (long) ceil((l - min[i]) / (one_jump * 1.0));             \n                long cur = min[i] + (jumps * one_jump);\n                if(cur >= l && cur + 1 <= r){                                       \n                    out.println((1L << i) - 1);\n                    out.flush();\n                    return;\n                }               \n            }\n        }\n        out.println(0);\n        out.flush();\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\npublic class D {\n    static long max;\n\n    public static long[] getOneRange(long min, long max,int bit) {\n        long st=(min&(((1l<<63)-1)&~((1l<<(bit+1))-1)))|(1l<<bit);\n        long end=st|((1l<<(bit+1))-1);\n        long interSt=Math.max(st,min);\n        long interEnd=Math.min(end, max);\n        if(interSt>interEnd) return null;\n        return new long[]{interSt,interEnd};\n    }\n\n    public static long[] getZeroRange(long min, long max,int bit) {\n        long st=min&(((1l<<63)-1)&~((1l<<(bit+1))-1));\n        long end=st|((1l<<bit)-1);\n        long interSt=Math.max(st,min);\n        long interEnd=Math.min(end, max);\n        if(interSt>interEnd) return null;\n        return new long[]{interSt,interEnd};\n    }\n\n    public static void solve(int bitPosition, long min1, long max1, long min2,\n            long max2, long curNum) {\n        if (bitPosition == -1) {\n            max = Math.max(max, curNum);\n            return;\n        }\n        long[] firZeroRange = getZeroRange(min1, max1,bitPosition);\n        long[] secZeroRange = getZeroRange(min2, max2,bitPosition);\n        long[] firOneRange = getOneRange(min1, max1,bitPosition);\n        long[] secOneRange = getOneRange(min2, max2,bitPosition);\n        if ((firOneRange != null && secZeroRange != null)\n                || (firZeroRange != null && secOneRange != null)) {\n            long newNum = curNum | (1l << bitPosition);\n            if (firOneRange != null && secZeroRange != null&&\n                    (firOneRange[1]-firOneRange[0]+1)==1l<<bitPosition&&\n                    (secZeroRange[1]-secZeroRange[0]+1)==1l<<bitPosition) {\n                solve(bitPosition - 1, firOneRange[0], firOneRange[1],\n                        secZeroRange[0], secZeroRange[1], newNum);\n                return;\n            }\n            if (firZeroRange != null && secOneRange != null&&\n                    (firZeroRange[1]-firZeroRange[0]+1)==1l<<bitPosition&&\n                    (secOneRange[1]-secOneRange[0]+1)==1l<<bitPosition) {\n                solve(bitPosition - 1, firZeroRange[0], firZeroRange[1],\n                        secOneRange[0], secOneRange[1], newNum);\n                return;\n            }\n            if (firOneRange != null && secZeroRange != null) {\n                solve(bitPosition - 1, firOneRange[0], firOneRange[1],\n                        secZeroRange[0], secZeroRange[1], newNum);\n            }\n            if (firZeroRange != null && secOneRange != null) {\n                solve(bitPosition - 1, firZeroRange[0], firZeroRange[1],\n                        secOneRange[0], secOneRange[1], newNum);\n            }\n        } else {\n            solve(bitPosition - 1, min1, max1, min2, max2, curNum);\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        long l = sc.nextLong();\n        long r = sc.nextLong();\n        max = 0;\n        solve(62, l, r, l, r, 0);\n        System.out.println(max);\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class a {\npublic static void main(String[] args) throws IOException\n{\n    \n    //Scanner input = new Scanner(new File(\"input.txt\"));\n    //PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n    PrintWriter out = new PrintWriter(System.out);\n    input.init(System.in);\n    long a = input.nextLong(), b = input.nextLong();\n    if(a==b)\n    {\n        out.println(0);\n        out.close();\n        return;\n    }\n    long res = 0;\n    for(int i = 0; i<63; i++)\n    {\n        if(a%(1l<<i) >= b%(1l<<i))\n            res += (1l<<i);\n        else if(b/((1l<<i)) > a/((1l<<i)))\n            res += (1l<<i);\n    }\n    out.println(res);\n    out.close();\n}\npublic static long gcd(long a, long b)\n{\nif(b == 0) return a;\nreturn gcd(b, a%b);\n}\npublic static class input {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    /** get next word */\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n    static long nextLong() throws IOException {\n        return Long.parseLong( next() );\n    }\n}\nstatic class IT\n{\n    int[] left,right, val, a, b;\n    IT(int n)\n    {\n        left = new int[3*n];\n        right = new int[3*n];\n        val = new int[3*n];\n        a = new int[3*n];\n        b = new int[3*n];\n        init(0,0, n);\n    }\n    int init(int at, int l, int r)\n    {\n        a[at] = l;\n        b[at] = r;\n        if(l==r)\n            left[at] = right [at] = -1;\n        else \n        {\n            int mid = (l+r)/2;\n            left[at] = init(2*at+1,l,mid);\n            right[at] = init(2*at+2,mid+1,r);\n        }\n        return at++;\n    }\n    //return the sum over [x,y]\n    int get(int x, int y)\n    {\n        return go(x,y, 0);\n    }\n    int go(int x,int y, int at)\n    {\n        if(at==-1) return 0;\n        if(x <= a[at] && y>= b[at]) return val[at];\n        if(y<a[at] || x>b[at]) return 0;\n        return go(x, y, left[at]) + go(x, y, right[at]);\n    }\n    //add v to elements x through y\n    void add(int x, int y, int v)\n    {\n        go3(x, y, v, 0);\n    }\n    void go3(int x, int y, int v, int at)\n    {\n        if(at==-1) return;\n        if(y < a[at] || x > b[at]) return;\n        val[at] += (Math.min(b[at], y) - Math.max(a[at], x) + 1)*v;\n        go3(x, y, v, left[at]);\n        go3(x, y, v, right[at]);\n    }\n}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "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.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\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        out.println(solve(in.nextLong(), in.nextLong()));\n        /*for (long l = 1; l < 500; l++) {\n            for (long r = l; r < 500; r++) {\n                if (badSolve(l, r) != solve(l, r)) {\n                    out.println(l + \" \" + r);\n                    return;\n                }\n            }\n        }\n        out.println(\"OK\");*/\n    }\n\n    long solve(long l, long r) {\n        if (l == r)\n            return 0;\n        long ans = l ^ (l + 1);\n\n        for (int i = 0; i < 62; i++) {\n            l |= (1l << i);\n            if (l + 1 <= r)\n                ans = (1l << (i + 2l)) - 1;\n        }\n\n        return ans;\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        if (!tok.hasMoreTokens()) {\n            try {\n                String newLine = in.readLine();\n                if (newLine == null)\n                    throw new InputMismatchException();\n                tok = new StringTokenizer(newLine);\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            return nextToken();\n        }\n\n        return tok.nextToken();\n    }\n\n    public long nextLong() {\n        return Long.parseLong(nextToken());\n    }\n\n    }\n\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\t\n\tString toStr(long a) {\n\t\tString s = Long.toBinaryString(a);\n\t\twhile (s.length() < 64)\n\t\t\ts = \"0\" + s;\n\t\treturn s;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tlong a = nextLong();\n\t\tlong b = nextLong();\n\t\t\n\t\tString sa = toStr(a);\n\t\tString sb = toStr(b);\n\t\t\n\t\tint i = 0;\n\t\twhile (i < 64 && sa.charAt(i) == sb.charAt(i))\n\t\t\ti++;\n\t\t\n\t\tint left = 64 - i;\n\t\tout.println((1L << left) - 1);\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}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class D {\n\tpublic static void main(String [] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tlong a = in.nextLong();\n\t\tlong b = in.nextLong();\n\t\tString sa = Long.toBinaryString(a);\n\t\tString sb = Long.toBinaryString(b);\n\t\tlong ans = 0;\n\t\tif(sb.length()-sa.length()>0){\n\t\t\tfor(int i = 0 ; i < sb.length() ; i++){\n\t\t\t\tans += 1l<<i;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t\telse{\n\t\t\tint num = -1 ;\n\t\t\tfor(int i = 62 ; i >= 0 ; i--){\n\t\t\t\tif((b & 1l << i) != 0 && ((~a) & (1l << i)) != 0){\n\t\t\t\t\tnum = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans = 0;\n\t\t\tif(num!=-1) for(int i = 0 ; i <= num ; i ++){\n\t\t\t\tans += 1l<<i;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t}\n\t}\n\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main3 {\n\n    \n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        \n        long l = s.nextLong();\n        long r = s.nextLong();\n        \n        String a = Long.toBinaryString(l);\n        String b = Long.toBinaryString(r);\n        while(a.length() < b.length()) a = \"0\" + a;\n        while(b.length() < a.length()) b = \"0\" + b;\n        \n        String ans = \"\";\n        \n        int ix = -1;\n        for (int i = 0; i < a.length(); i++) {\n            \n            if(a.charAt(i) != b.charAt(i)){\n                break;\n            }\n            ans += a.charAt(i);\n            ix++;\n        }\n//      System.out.println(a);\n//      System.out.println(b);\n        for (int i = ix + 1; i < a.length(); i++) {\n            int c1 = a.charAt(i) - '0';\n            int c2 = b.charAt(i) - '0';\n            if(c1 == 0 && c2 == 0) ans += \"1\";\n            else if(c1 == 1 && c2 == 1) ans += \"0\";\n            else ans += (char)(c1 + '0');\n        }\n        long a1 = Long.parseLong(ans, 2);\n        long a2 = Long.parseLong(b,2);\n//      System.out.println(ans);\n//      System.out.println(b);\n//      System.out.println();\n        long xor = a1 ^ a2;\n        System.out.println(xor);\n    }\n\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class d_169 {\npublic static void main(String[] args) {\n\tScanner  sc = new Scanner(System.in);\n\tlong x=sc.nextLong();\n\tlong y=sc.nextLong();\n\tString s=Long.toBinaryString(x);\n\tString p=Long.toBinaryString(y);\n\tint id=p.length()-s.length();\n\tfor (int i =1; i <=id; i++) {\n\t\ts=\"0\"+s;\n\t}\n\tif(x==y){\n\t\tSystem.out.println(0);\n\t\treturn;\n\t}\n\tfor (int i = 0; i <p.length(); i++) {\n\t\tif(s.charAt(i)!=p.charAt(i)){\n\t\t\tSystem.out.println((long)Math.pow(2, s.length()-i)-1);\n\t\t\treturn;\n\t}\n}\n}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.*;\n\npublic class D {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic D () {\n\t\tlong L = sc.nextLong();\n\t\tlong R = sc.nextLong();\n\t\t\n\t\tfor (int i = 60; i >= 0; --i) {\n\t\t\tlong b = (1L << i);\n\t\t\tlong A = (L & b), B = (R & b);\n\t\t\tif (A != B)\n\t\t\t\texit(2*b-1);\n\t\t}\n\t\texit(0);\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print(Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint(Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n    public static void main(String[] args) throws IOException {\n        new D().solve();\n    }\n\n    void solve() throws IOException {\n        Scanner sc = new Scanner(System.in);\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String[] sp;\n\n        long L = sc.nextLong();\n        long R = sc.nextLong();\n        if (L == R) {\n            System.out.println(0);\n        } else {\n            System.out.println(Long.highestOneBit(R ^ L) * 2 - 1);\n        }\n    }\n}\n\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "\n// @author Sanzhar\nimport java.io.*;\nimport java.util.*;\nimport java.awt.Point;\n\npublic class Template {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n\n    String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(in.readLine());\n            } catch (Exception e) {\n            }\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    double nextDouble() {\n        return Double.parseDouble(next());\n    }\n\n    public void run() throws Exception {\n        //in = new BufferedReader(new FileReader(\"input.txt\"));\n        //out = new PrintWriter(new FileWriter(\"output.txt\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        solve();\n        out.flush();\n        out.close();\n        in.close();\n    }\n\n    public void solve() throws Exception {\n        long l = nextLong();\n        long r = nextLong();\n        long[] x = new long[100];\n        int kx = 0;\n        while (r > 0) {\n            x[kx++] = r % 2;\n            r /= 2;\n        }\n        long[] y = new long[100];\n        int ky = 0;\n        while (l > 0) {\n            y[ky++] = l % 2;\n            l /= 2;\n        }\n        long[] ans = new long[100];\n        boolean ok = false;\n        for (int k = kx - 1; k >= 0; k--) {\n            if (ok) {\n                ans[k] = 1;\n                continue;\n            }\n            if (x[k] > y[k]) {\n                ans[k] = 1;\n                ok = true;\n            }\n        }\n        long a = 0;\n        long p2 = 1;\n        for (int i = 0; i < kx; i++) {\n            a += p2 * ans[i];\n            p2 *= 2;\n        }\n        out.println(a);\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Template().run();\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.UnsupportedEncodingException;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\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\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, InputReader in, PrintWriter out) {\n    long l = in.readLong(), r = in.readLong();\n    int pow = 62;\n    long mask = 1L << pow;\n    while (((r | l) & mask) == 0){\n      pow--;\n      mask = 1L << pow;\n    }\n    while (true) {\n      if (((r ^ l) & mask) == mask || pow < 0) {\n        break;\n      }\n      mask >>= 1;\n      l = l & ~(1L << pow);\n      r = r & ~(1L << pow);\n      pow--;\n    }\n    pow++;\n    out.print((1L << pow) - 1);\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 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 static boolean isSpaceChar(int c) {\n    return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n  }\n\n  }\n\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class D {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        long l = s.nextLong();\n        long r = s.nextLong();\n        long a = l ^ r;\n        long b = a;\n        while (b != 0) {\n            a = b;\n            b = (b-1) & b;\n        }\n        if (a != 0) {\n            a = (a << 1) - 1;\n        }\n        System.out.println(a);\n    }\n\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Dj {\n\n\tpublic static long run(long l, long r) {\n\t\tif(l == r) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong[] sq2 = new long[62];\n\t\tsq2[0] = 1;\n\t\tfor(int i = 1; i < 62; i++) sq2[i] = sq2[i-1]*2;\n\n\t\t//System.out.println(sq2[61]);\n\n\t\tfor(int i = sq2.length - 1; i >= 0; i--) {\n\t\t\t//log(\"L = \" + l + \" R = \" + r + \" 2^\" + i + \"=\" + sq2[i]);\n\t\t\tif(l >= sq2[i] && r >= sq2[i]) {\n\t\t\t\tl -= sq2[i];\n\t\t\t\tr -= sq2[i];\n\t\t\t} else if(l < sq2[i] && sq2[i] <= r) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(int i = sq2.length - 1; i >= 0; i--) {\n\t\t\t//log(\"L = \" + l + \" R = \" + r + \" 2^\" + i + \"=\" + sq2[i]);\n\t\t\tif(l < sq2[i] && sq2[i] <= r) {\n\t\t\t\treturn sq2[i+1]-1;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\tpublic static void log(String str) {\n\t\tSystem.out.println(str);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tlong l = sc.nextLong();\n\t\tlong r = sc.nextLong();\n\n\t\tSystem.out.println(run(l, r));\n\t\t//System.out.println(run(9999999999998l, 9999999999999l));\n\n\t}\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n\n\npublic class LittleGirlAndXor {\n    static long L, R;\n    static Long[][][][][] dp = new Long[64][2][2][2][2];\n    public static long go(int index, int low1, int high1, int low2, int high2) {\n        if (index == -1) {\n            return 0;\n        }\n        if (dp[index][low1][high1][low2][high2] != null)\n            return dp[index][low1][high1][low2][high2];\n        int bit1 = (L & (1L << index)) == 0 ? 0 : 1;\n        int bit2 = (R & (1L << index)) == 0 ? 0 : 1;\n        long res = 0;\n        for (int i = 0; i < 2; i++) {\n            for (int j = 0; j < 2; j++) {\n                int nl1 = low1, nh1 = high1, nl2 = low2, nh2 = high2;\n                boolean can = true;\n                if (low1 == 0) {\n                    if (i == bit1) {\n                        nl1 = 0;\n                    } else if (i < bit1) {\n                        can = false;\n                    } else if (i > bit1) {\n                        nl1 = 1;\n                    }\n                }\n                if (high1 == 0) {\n                    if (i == bit2) {\n                        nh1 = 0;\n                    } else if (i < bit2) {\n                        nh1 = 1;\n                    } else if (i > bit2) {\n                        can = false;\n                    }\n                }\n                if (low2 == 0) {\n                    if (j == bit1) {\n                        nl2 = 0;\n                    } else if (j < bit1) {\n                        can = false;\n                    } else if (j > bit1) {\n                        nl2 = 1;\n                    }\n                }\n                if (high2 == 0) {\n                    if (j == bit2) {\n                        nh2 = 0;\n                    } else if (j < bit2) {\n                        nh2 = 1;\n                    } else if (j > bit2) {\n                        can = false;\n                    }\n                }\n                if (can){\n                    long xor = i^j;\n                    res = Math.max(res, (xor<<index)+go(index - 1, nl1, nh1, nl2, nh2));\n                }\n            }\n        }\n        return dp[index][low1][high1][low2][high2] = res;\n    }\n    public static void main(String[] args) {\n        InputReader r = new InputReader(System.in);\n        L = r.nextLong();\n        R = r.nextLong();\n        System.out.println(go(63,0,0,0,0));\n    }\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n                return null;\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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.text.*;\n\npublic class cf276d {\n\n    static BufferedReader br;\n    static Scanner sc;\n    static PrintWriter out;\n\n    public static void initA() {\n        try {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            //br = new BufferedReader(new FileReader(\"input.txt\"));\n            sc = new Scanner(System.in);\n            //out = new PrintWriter(\"output.txt\");\n            out = new PrintWriter(System.out);\n        } catch (Exception e) {\n        }\n    }\n\n    public static void initB() {\n        try {\n\n            br = new BufferedReader(new FileReader(\"input.txt\"));\n            sc = new Scanner(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\n\n        } catch (Exception e) {\n        }\n    }\n\n    public static String getString() {\n        try {\n            return br.readLine();\n        } catch (Exception e) {\n        }\n        return \"\";\n    }\n\n    public static Integer getInt() {\n        try {\n            return Integer.parseInt(br.readLine());\n        } catch (Exception e) {\n        }\n        return 0;\n    }\n\n    public static Integer[] getIntArr() {\n        try {\n            StringTokenizer temp = new StringTokenizer(br.readLine());\n            int n = temp.countTokens();\n            Integer temp2[] = new Integer[n];\n            for (int i = 0; i < n; i++) {\n                temp2[i] = Integer.parseInt(temp.nextToken());\n            }\n            return temp2;\n        } catch (Exception e) {\n        }\n        return null;\n    }\n\n    public static Long[] getLongArr() {\n        try {\n            StringTokenizer temp = new StringTokenizer(br.readLine());\n            int n = temp.countTokens();\n            Long temp2[] = new Long[n];\n            for (int i = 0; i < n; i++) {\n                temp2[i] = Long.parseLong(temp.nextToken());\n            }\n            return temp2;\n        } catch (Exception e) {\n        }\n        return null;\n    }\n\n    public static String[] getStringArr() {\n        try {\n            StringTokenizer temp = new StringTokenizer(br.readLine());\n            int n = temp.countTokens();\n            String temp2[] = new String[n];\n            for (int i = 0; i < n; i++) {\n                temp2[i] = (temp.nextToken());\n            }\n            return temp2;\n        } catch (Exception e) {\n        }\n        return null;\n    }\n\n    public static int getMax(Integer[] ar) {\n        int t = ar[0];\n        for (int i = 0; i < ar.length; i++) {\n            if (ar[i] > t) {\n                t = ar[i];\n            }\n        }\n        return t;\n    }\n\n    public static void print(Object a) {\n        out.println(a);\n    }\n\n    public static int nextInt() {\n        return sc.nextInt();\n    }\n\n    public static double nextDouble() {\n        return sc.nextDouble();\n    }\n\n    public static void main(String[] ar) {\n        initA();\n        solve();\n        out.flush();\n    }\n    public static void print2(Object o){System.out.println(o);}\n\n    public static void solve() {\n        Long xx[] = getLongArr();\n        long l = xx[0];\n        long r = xx[1];\n        BigInteger a = BigInteger.valueOf(l);\n        BigInteger b = BigInteger.valueOf(r);\n        \n        if(l==r){\n            print(0);return;\n        }\n\n        String a2 = a.toString(2);\n        String b2 = b.toString(2);\n\n        int selisihpjg = Math.abs(a2.length() - b2.length());\n\n        while (selisihpjg-- > 0) {\n            a2 = \"0\" + a2;\n            //print2(\"wewe\");\n        }\n        \n        //print2(a2);\n        //print2(b2);\n        String out = \"\";\n\n        for (int i = 0; i < b2.length(); i++) {\n            //print2(\"i=\"+i);\n            if (a2.charAt(i) != b2.charAt(i)) {\n                \n                for (int ii = i; ii < b2.length(); ii++) {\n                    out += \"1\";\n                }\n                //print2(out);\n                print2(new BigInteger(out, 2));\n                return;\n            }\n        }\n\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "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    \n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.System.*;\n\npublic class D276 {\n    Scanner sc = new Scanner(in);\n\n\n    public void run() {\n        long l=sc.nextLong(),r=sc.nextLong();\n\n        long tes=l^r;\n\n        int d=0;\n        while(tes!=0){\n            tes/=2;\n            d++;\n        }\n        ln((1L<<d)-1);\n    }\n\n\n    public static void main(String[] _) {\n        new D276().run();\n    }\n\n    public static void pr(Object o) {\n        out.print(o);\n    }\n    public static void ln(Object o) {\n        out.println(o);\n    }\n    public static void ln() {\n        out.println();\n    }\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Scanner;\n\npublic class CodeForces {\n\n    //private static MyScanner sc;\n    private static MyPrinter out;\n\n    public static void solve() throws IOException {\n        Scanner sc = new Scanner(System.in);\n        long l = sc.nextLong();\n        long r = sc.nextLong();\n        String ls = Long.toBinaryString(l);\n        String rs = Long.toBinaryString(r);\n        while (ls.length() < rs.length()) {\n            ls = \"0\" + ls;\n        }\n        String res = \"\";\n        boolean ok = false;\n        for (int i = 0; i < ls.length(); i++) {\n            if (ok) {\n                res += \"1\";\n            } else {\n                if (ls.charAt(i) != rs.charAt(i)) {\n                    res += \"1\";\n                    ok = true;\n                }\n            }\n        }\n        long all = 0;\n        for (int i = 0; i < res.length(); i++) {\n            all += (long) Math.pow((long) 2, (long) res.length() - 1 - i);\n        }\n        System.out.println(all);\n    }\n\n    public static void main(String[] args) throws IOException {\n        //sc = new MyScanner(System.in);\n        out = new MyPrinter(System.out);\n        solve();\n        out.close();\n    }\n}\n\nclass MyScanner {\n\n    private StreamTokenizer st;\n\n    public MyScanner(InputStream is) {\n        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));\n    }\n\n    public MyScanner(File f) throws FileNotFoundException {\n        st = new StreamTokenizer(new BufferedReader(new FileReader(f)));\n    }\n\n    public int nextInt() throws IOException {\n        st.nextToken();\n        return ((int) st.nval);\n    }\n\n    public double nextDouble() throws IOException {\n        st.nextToken();\n        return (st.nval);\n    }\n\n    public String nextString() throws IOException {\n        st.nextToken();\n        if (st.ttype == StreamTokenizer.TT_WORD) {\n            return (st.sval);\n        } else {\n            return (\"not found\");\n        }\n    }\n}\n\nclass MyPrinter {\n\n    private BufferedWriter out;\n\n    public MyPrinter(OutputStream os) {\n        out = new BufferedWriter(new PrintWriter(os));\n    }\n\n    public MyPrinter(File f) throws IOException {\n        out = new BufferedWriter(new FileWriter(f));\n    }\n\n    public void println(int i) throws IOException {\n        out.write(Integer.toString(i));\n        out.newLine();\n    }\n\n    public void println(double d) throws IOException {\n        out.write(Double.toString(d));\n        out.newLine();\n    }\n\n    public void println(long l) throws IOException {\n        out.write(Long.toString(l));\n        out.newLine();\n    }\n\n    public void println(String s) throws IOException {\n        out.write(s);\n        out.newLine();\n    }\n\n    public void println(char c) throws IOException {\n        out.write(Character.toString(c));\n        out.newLine();\n    }\n\n    public void print(int i) throws IOException {\n        out.write(Integer.toString(i));\n    }\n\n    public void print(double d) throws IOException {\n        out.write(Double.toString(d));\n    }\n\n    public void print(long l) throws IOException {\n        out.write(Long.toString(l));\n    }\n\n    public void print(String s) throws IOException {\n        out.write(s);\n    }\n\n    public void print(char c) throws IOException {\n        out.write(Character.toString(c));\n    }\n\n    public void close() throws IOException {\n        out.flush();\n        out.close();\n    }\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tBufferedReader in;\n\tStringTokenizer str = null;\n\t\n\tprivate String next() throws Exception{\n\t\tif (str == null || !str.hasMoreElements())\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\treturn str.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate long nextLong() throws Exception{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate double nextDouble() throws Exception{\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tpublic void run() throws Exception{\n\t\tin =  new BufferedReader(new InputStreamReader(System.in));\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n\n\t\tint bit = 63;\n\t\twhile(bit >= 0 && (hasBit(l, bit) == hasBit(r, bit))) {\n\t\t\tbit--;\n\t\t}\n\t\tSystem.out.println((1L<<bit+1)-1);\n\t}\n\n\tprivate boolean hasBit(long x, int i){\n\t\treturn (x & (1L<<i)) > 0;\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "/* 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\tvoid solve() throws IOException  {\n\t\t\n\t\tlong leftBorder = nextLong();\n\t\tlong rightBorder = nextLong();\n\n\t\tlong[][][][][] dp = new long [64][2][2][2][2];\n\t\tfor (long[][][][] a : dp) for (long[][][] b : a) for (long[][] c : b) for (long[] d : c) fill(d, -1L);\n\t\t\n\t\tdp[63][0][0][0][0] = 0L;\n\t\t\n\t\tfor (int lastBit = 63; lastBit > 0; lastBit--) {\n\t\t\t\n\t\t\tint curBit = lastBit - 1;\n\t\t\t\n\t\t\tint leftBit = (int) ((leftBorder >> curBit) & 1L);\n\t\t\tint rightBit = (int) ((rightBorder >> curBit) & 1L);\n\t\t\t\n\t\t\tfor (int agl = 0; agl < 2; agl++) {\n\t\t\t\t\n\t\t\t\tfor (int alr = 0; alr < 2; alr++) {\n\t\t\t\t\t\t\n\t\t\t\t\tfor (int bgl = 0; bgl < 2; bgl++) {\n\t\t\t\t\t\n\t\t\t\t\t\tfor (int blr = 0; blr < 2; blr++) {\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tlong prvXor = dp[lastBit][agl][alr][bgl][blr];\n\t\t\t\t\t\t\tif (prvXor < 0L) continue;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfor (int ab = 0; ab < 2; ab++) {\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tint nagl = left(agl, leftBit, ab);\n\t\t\t\t\t\t\t\tint nalr = right(alr, rightBit, ab);\n\t\t\t\t\t\t\t\tif (nagl < 0 || nalr < 0) continue;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tfor (int bb = 0; bb < 2; bb++) {\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tint nbgl = left(bgl, leftBit, bb);\n\t\t\t\t\t\t\t\t\tint nblr = right(blr, rightBit, bb);\n\t\t\t\t\t\t\t\t\tif (nbgl < 0 || nblr < 0) continue;\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tlong setBit = ab ^ bb;\n\t\t\t\t\t\t\t\t\tdp[curBit][nagl][nalr][nbgl][nblr] = max(dp[curBit][nagl][nalr][nbgl][nblr], prvXor | (setBit << curBit));\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}\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\t\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\tlong answer = -1L;\n\t\t\n\t\tfor (int agl = 0; agl < 2; agl++) {\n\t\t\t\n\t\t\tfor (int alr = 0; alr < 2; alr++) {\n\t\t\t\t\t\n\t\t\t\tfor (int bgl = 0; bgl < 2; bgl++) {\n\t\t\t\t\n\t\t\t\t\tfor (int blr = 0; blr < 2; blr++) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tanswer = max(answer, dp[0][agl][alr][bgl][blr]);\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\tSystem.err.println(Long.toBinaryString(leftBorder));\n//\t\tSystem.err.println(Long.toBinaryString(rightBorder));\n//\t\tSystem.err.println(Long.toBinaryString(answer));\n\t\t\n\t\tout.println(answer);\n\t}\n\n\tint left(int gl, int leftBit, int b) {\n\t\t\n\t\tif (gl == 0) {\n\t\t\t\n\t\t\tif (b < leftBit) return -1;\n\t\t\tif (b == leftBit) return 0;\n\t\t\tif (b > leftBit) return 1;\n\t\t\t\n\t\t}\n\t\t\n\t\treturn 1;\n\t}\n\t\n\tint right(int lr, int rightBit, int b) {\n\t\t\n\t\tif (lr == 0) {\n\t\t\tif (b < rightBit) return 1;\n\t\t\tif (b == rightBit) return 0;\n\t\t\tif (b > rightBit) return -1;\n\t\t}\n\t\t\n\t\treturn 1;\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", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Long.*;\nimport static java.lang.Character.*;\nimport static java.lang.String.*;\n@SuppressWarnings(\"unused\")\n\npublic class round169D {\n    static PrintWriter out = new PrintWriter(System.out);\n    static BufferedReader br = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static int nextInt() throws Exception {\n        return Integer.parseInt(next());\n    }\n    static String next() throws Exception {\n        while (true) {\n            if (st.hasMoreTokens()) {\n                return st.nextToken();\n            }\n            String s = br.readLine();\n            if (s == null) {\n                return null;\n            }\n            st = new StringTokenizer(s);\n        }\n    }\n    public static void main(String[] args)throws Exception {        \n        long l = parseLong(next());\n        long r = parseLong(next());\n        long [] min = new long [61];\n        for(int i = 1 ; i <= 60 ; ++i){//(2^i)-1 is obtained by min[i]^min[i]+1\n            min[i] = (long) pow(2, i - 1) - 1;          \n        }\n        for(int i = 60 ; i >= 0 ; --i){//try to get 2^i-1 as answer.                \n            if(min[i] >= r)\n                continue;\n            if(min[i] >= l && min[i] + 1 <= r){             \n                out.println((long) pow(2, i) - 1);\n                out.flush();\n                return;\n            }\n            if(min[i] < l){\n                long one_jump = (long) pow(2, i);\n                long  jumps = (long) ceil((l - min[i]) / (one_jump * 1.0));             \n                long cur = min[i] + (jumps * one_jump);\n                if(cur >= l && cur + 1 <= r){                                       \n                    out.println((long) pow(2, i) - 1);\n                    out.flush();\n                    return;\n                }               \n            }\n        }\n        out.println(0);\n        out.flush();\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import\tjava.util.*;\npublic\tclass\tMain{\n\tpublic\tstatic\tvoid\tmain(String[]args){\n\t\tfor(Scanner\tcin=new\tScanner(System.in);cin.hasNextLong();System.out.println(Math.max(0,(Long.highestOneBit(cin.nextLong()^cin.nextLong())<<1)-1)));\n\t}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "//package round169;\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\tlong L = nl(), R = nl();\n\t\tout.println(Math.max(0, Long.highestOneBit(L^R)*2-1));\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new D2().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", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "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 ocelopilli\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    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long LL = in.nextLong();\n        long RR = in.nextLong();\n\n        long L = LL;\n        long R = RR;\n        long ans = 0L;\n        long X = Long.highestOneBit( R );\n        while ( X > 0L && (L & X) == (R & X) ) X >>= 1;\n        while ( X > 0L )\n        {\n            long a = L & X;\n            long b = R & X;\n            if ( (a ^ b) == X ) ans |= X;\n            else\n            {\n                if ( b == 0L )\n                {\n                    if ( (R | X) <= RR )\n                    {\n                        R |= X;\n                        ans |= X;\n                    }\n                    else if ( (L | X) <= RR )\n                    {\n                        L |= X;\n                        ans |= X;\n                    }\n                }\n                else\n                {\n                    if ( (L ^ X) >= LL )\n                    {\n                        L ^= X;\n                        ans |= X;\n                    }\n                    else if ( (R ^ X) >= LL )\n                    {\n                        R ^= X;\n                        ans |= X;\n                    }\n                }\n            }\n            X >>= 1;\n        }\n        out.println( ans );\n    }\n}\n\nclass InputReader {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public InputReader(InputStream in)\n    {\n        br = new BufferedReader(new InputStreamReader(in));\n        st = null;\n    }\n\n    public String next()\n    {\n        while (st==null || !st.hasMoreTokens())\n        {\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 long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long left = in.nextLong();\n        long right = in.nextLong();\n\n        long ans = go(left, right);\n        out.println(ans);\n    }\n\n    private long go(long A, long B) {\n        int bA = -1;\n        for(int i = 62; i >= 0; i--)\n            if((A & (1L << i)) > 0) {\n                bA = i;\n                break;\n            }\n        int bB = -1;\n        for(int i = 62; i >= 0; i--)\n            if((B & (1L << i)) > 0) {\n                bB = i;\n                break;\n            }\n\n        if(bB == -1)\n            return 0;\n        if(bA < bB)\n            return allOne(bB);\n        else\n            return go(A ^ (1L << bA), B ^ (1L << bB));\n    }\n\n    private long allOne(int bits) {\n        long ret = 0;\n        for(int i = 0; i <= bits; i++)\n            ret |= (1L << i);\n        return ret;\n    }\n}\n\nclass InputReader {\n    private InputStream stream;\n    private byte[] buf = new byte[1024];\n    private int curChar;\n    private int numChars;\n\n    public InputReader(InputStream stream) {\n        this.stream = stream;\n    }\n\n    public int read() {\n        if (numChars == -1)\n            throw new InputMismatchException();\n        if (curChar >= numChars) {\n            curChar = 0;\n            try {\n                numChars = stream.read(buf);\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            if (numChars <= 0)\n                return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public long nextLong() {\n        return Long.parseLong(nextString());\n    }\n\n    public String nextString() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        StringBuffer res = new StringBuffer();\n        do {\n            res.appendCodePoint(c);\n            c = read();\n        } while (!isSpaceChar(c));\n        return res.toString();\n    }\n\n    private boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    }\n\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class Main {\n\n\tpublic static void main(String [] args ) {\n\t\ttry{\n\t\t\tString str;\t\t\t\n\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tBufferedOutputStream bos = new BufferedOutputStream(System.out);\n\t\t\tString eol = System.getProperty(\"line.separator\");\n\t\t\tbyte [] eolb = eol.getBytes();\n\t\t\tbyte[] spaceb= \" \".getBytes();\n\t\t\n\t\t\tstr  = br.readLine();\n\t\t\tint blank = str.indexOf( \" \");\n\t\t\tlong l = Long.parseLong(str.substring(0,blank));\n\t\t\tlong r = Long.parseLong(str.substring(blank+1));\n\t\t\tString one = \"\";\n\t\t\tString two = \"\";\n\t\t\twhile(l>0) {\n\t\t\t\tif((l%2)==0) {\n\t\t\t\t\tone = \"0\".concat(one);\n\t\t\t\t} else {\n\t\t\t\t\tone = \"1\".concat(one);\n\t\t\t\t}\n\t\t\t\tl/=2;\n\t\t\t}\n\t\t\twhile(r>0) {\n\t\t\t\tif((r%2)==0) {\n\t\t\t\t\ttwo = \"0\".concat(two);\n\t\t\t\t} else {\n\t\t\t\t\ttwo = \"1\".concat(two);\n\t\t\t\t}\n\t\t\t\tr/=2;\n\t\t\t}\n\t\t\twhile(one.length()<60) {\n\t\t\t\tone = \"0\".concat(one);\n\t\t\t}\n\t\t\twhile(two.length()<60) {\n\t\t\t\ttwo = \"0\".concat(two);\n\t\t\t}\n\t\t\tint iter = 0;\n\t\t\tString xor = \"\";\n\t\t\tboolean big = false;\n\t\t\tboolean small = false;\n\t\t\twhile(one.charAt(iter) == two.charAt(iter)) {\n\t\t\t\txor = xor.concat(\"0\");\n\t\t\t\titer++;\n\t\t\t\tif(iter==60) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = iter ; i < 60 ; i++) {\n\t\t\t\txor = xor.concat(\"1\");\n\t\t\t}\n\t\t\tbos.write(new BigInteger(xor,2).toString().getBytes());\n\t\t\tbos.write(eolb);\n\t\t\tbos.flush();\n\t\t}  catch(IOException ioe) {\n\t\t\tioe.printStackTrace();\n\t\t}\n\t}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CFDiv1 {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tboolean canBe(int from, long curVal, long l, long r) {\n\t\tif (curVal > r)\n\t\t\treturn false;\n\t\tfor (int i = 0; i <= from; i++)\n\t\t\tcurVal += 1L << i;\n\t\tif (curVal >= l)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tlong stupid(long l, long r) {\n\t\tlong ans = 0;\n\t\tfor (long i = l; i <= r; i++)\n\t\t\tfor (long j = l; j <= r; j++)\n\t\t\t\tans = Math.max(ans, i ^ j);\n\t\treturn ans;\n\t}\n\n\tlong solve2(long l, long r) {\n\t\tlong min = 0;\n\t\tlong max = 0;\n\t\tfor (int i = 62; i >= 0; i--) {\n\t\t\tboolean max0 = canBe(i - 1, max, l, r);\n\t\t\tboolean max1 = canBe(i - 1, max | (1L << i), l, r);\n\t\t\tboolean min0 = canBe(i - 1, min, l, r);\n\t\t\tboolean min1 = canBe(i - 1, min | (1L << i), l, r);\n\t\t\tif (max0 && min1 && max > min) {\n\t\t\t\tmin = min | (1L << i);\n\t\t\t} else {\n\t\t\t\tif (max1 && min0) {\n\t\t\t\t\tmax |= (1L << i);\n\t\t\t\t} else {\n\t\t\t\t\tif (max1 && min1) {\n\t\t\t\t\t\tmax |= (1L << i);\n\t\t\t\t\t\tmin |= 1L << i;\n\t\t\t\t\t} else {\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn min ^ max;\n\t}\n\n\tvoid solve() {\n\t\tout.println(solve2(in.nextLong(), in.nextLong()));\n//\t\tSystem.err.println(solve2(4, 9));\n//\t\tRandom rnd = new Random(312);\n//\t\tfor (int test = 0; test < 10000; test++) {\n//\t\t\tSystem.err.println(test);\n//\t\t\tint l = rnd.nextInt(100);\n//\t\t\tint r = rnd.nextInt(100) + l;\n//\t\t\tlong v1 = stupid(l, r);\n//\t\t\tlong v2 = solve2(l, r);\n//\t\t\tif (v1 != v2) {\n//\t\t\t\tSystem.err.println(v1 + \" \" + v2);\n//\t\t\t\tSystem.err.println(l + \" \" + r);\n//\t\t\t\tthrow new AssertionError();\n//\t\t\t}\n//\t\t}\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"test.in\"));\n\t\t\tout = new PrintWriter(new File(\"test.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 CFDiv1().runIO();\n\t}\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "/**\n * Created with IntelliJ IDEA.\n * User: brzezinsky\n * Date: 12/16/12\n * Time: 7:44 PM\n * To change this template use File | Settings | File Templates.\n */\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.StringTokenizer;\n\npublic class E extends Thread {\n    public E(String inputFileName, String outputFileName) {\n        try {\n            if (inputFileName != null) {\n                this.input = new BufferedReader(new FileReader(inputFileName));\n            } else {\n                this.input = new BufferedReader(new InputStreamReader(System.in));\n            }\n            if (outputFileName != null) {\n                this.output = new PrintWriter(outputFileName);\n            } else {\n                this.output = new PrintWriter(System.out);\n            }\n            this.setPriority(Thread.MAX_PRIORITY);\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            e.printStackTrace();\n            System.exit(666);\n        }\n    }\n\n\n\n\n    private void solve() throws Throwable {\n        long l = nextLong(), r = nextLong();\n        int []bitL = new int[63];\n        int []bitR = new int[63];\n        int szL = doit(l, bitL);\n        int szR = doit(r, bitR);\n        int ret = szR;\n        while (ret >= 0 && bitL[ret] == bitR[ret]) --ret;\n        if (ret < 0) {\n            output.println(0);\n        } else {\n            output.println((1L << (ret + 1)) - 1);\n        }\n    }\n\n    static final int doit(long q, int []a) {\n        int sz = 0;\n        while (q != 0L) {\n            a[sz++] = (int)(q &1L);\n            q >>= 1;\n        }\n        return sz;\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.close();\n        }\n    }\n\n    public static void main(String... args) {\n        new E(null, null).start();\n    }\n\n    private int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    private double nextDouble() throws IOException {\n        return Double.parseDouble(next());\n    }\n\n    private long nextLong() throws IOException {\n        return Long.parseLong(next());\n    }\n\n    private String next() throws IOException {\n        while (tokens == null || !tokens.hasMoreTokens()) {\n            tokens = new StringTokenizer(input.readLine());\n        }\n        return tokens.nextToken();\n    }\n\n    private StringTokenizer tokens;\n    private BufferedReader input;\n    private PrintWriter output;\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author emotionalBlind\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    int[] lo;\n    int[] hi;\n\n    long[][][][][] dp;\n    long[] posVal;\n\n    long go(int pos, int isAGreaterLo, int isALessHi, int isBGreaterLo, int isBLessHi) {\n        if (pos == 63) {\n            return 0;\n        }\n        if (dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi] != -1) {\n            return dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi];\n        }\n        // range a\n        int ua = 0;\n        int va = 1;\n        if (isALessHi == 0 && hi[pos] == 0) {\n            va = 0;\n        }\n        if (isAGreaterLo == 0 && lo[pos] == 1) {\n            ua = 1;\n        }\n        // range b;\n        int ub = 0;\n        int vb = 1;\n        if (isBLessHi == 0 && hi[pos] == 0) {\n            vb = 0;\n        }\n        if (isBGreaterLo == 0 && lo[pos] == 1) {\n            ub = 1;\n        }\n        long res = 0;\n        dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi] = 0;\n        for (int i = ua; i <= va; ++i) {\n            int newIsAGreaterLo = isAGreaterLo;\n            int newIsALessHi = isALessHi;\n            if (i < hi[pos]) newIsALessHi = 1;\n            if (i > lo[pos]) newIsAGreaterLo = 1;\n            for (int j = ub; j <= vb; ++j) {\n                int newIsBGreaterLo = isBGreaterLo;\n                int newIsBLessHi = isBLessHi;\n                if (j < hi[pos]) newIsBLessHi = 1;\n                if (j > lo[pos]) newIsBGreaterLo = 1;\n                long val = 0;\n                if (i != j) val = posVal[pos];\n                val += go(pos + 1, newIsAGreaterLo, newIsALessHi, newIsBGreaterLo, newIsBLessHi);\n                res = Math.max(res, val);\n            }\n        }\n        dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi] = res;\n        return res;\n    }\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        lo = new int[63];\n        hi = new int[63];\n        long a = in.readLong();\n        long b = in.readLong();\n        Binary.convertBinary(a, lo);\n        Binary.convertBinary(b, hi);\n        posVal = new long[63];\n        posVal[62] = 1;\n        for (int i = 61; i >= 0; --i) {\n            posVal[i] = posVal[i + 1] * 2;\n        }\n        dp = new long[65][2][2][2][2];\n        for (long[][][][] a1 : dp) {\n            for (long[][][] a2 : a1) {\n                for (long[][] a3 : a2) {\n                    for (long[] a4 : a3) {\n                        Arrays.fill(a4, -1);\n                    }\n                }\n            }\n        }\n        long res = go(0, 0, 0, 0, 0);\n        out.printLine(res);\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        // InputMismatchException -> UnknownError\n        if (numChars == -1)\n            throw new UnknownError();\n        if (curChar >= numChars) {\n            curChar = 0;\n            try {\n                numChars = stream.read(buf);\n            } catch (IOException e) {\n                throw new UnknownError();\n            }\n            if (numChars <= 0)\n                return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public 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 static boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\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\nclass Binary {\n    public static void convertBinary(long val, int[] a) {\n        int last = a.length - 1;\n        Arrays.fill(a, 0);\n        while (val > 0) {\n            a[last] = (int) (val % 2);\n            last--;\n            val /= 2;\n        }\n    }\n}\n\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * @author Abhimanyu Singh\n *\n */\npublic class LittleGirlAndMaximumXOR {\n\n    private InputStream input;\n    private PrintStream output;\n    private Scanner inputSc;\n    static final boolean ONE = true;\n    static final boolean ZERO = false;\n    char dp[][][];\n\n    public LittleGirlAndMaximumXOR(InputStream input, PrintStream output) {\n        this.input = input;\n        this.output = output;\n        init();\n    }\n\n    private void init() {\n        inputSc = new Scanner(input);\n    }\n\n    static int lineToInt(String line) {\n        return Integer.parseInt(line);\n    }\n\n    public void solve() {\n        solveTestCase(1);\n    }\n\n    void fill(char a[], long value) {\n        String str = Long.toBinaryString(value);\n        char array[] = str.toCharArray();\n        int len = array.length;\n        int index = 63;\n        while (len > 0) {\n            a[index] = array[len - 1];\n            len--;\n            index--;\n        }\n    }\n\n    void init(char a[]) {\n        for (int i = 0; i < 64; i++) {\n            a[i] = '0';\n        }\n    }\n\n    /*\n     char[] getMax0(char lBit[], char rBit[], int lIndex, int rIndex) {\n     char ans[]=new char[64];\n     if(lIndex)\n     }\n    \n\n     char[] getMax(char lBit[], char rBit[], int lIndex, int rIndex) {\n     }*/\n    private void solveTestCase(int testN) {\n        long l = inputSc.nextLong();\n        long r = inputSc.nextLong();\n        char lBit[] = new char[64];\n        char rBit[] = new char[64];\n        init(lBit);\n        init(rBit);\n        fill(lBit, l);\n        fill(rBit, r);\n        int i = 0;\n        char ansBit[] = new char[64];\n        char a[] = new char[64];\n        char b[] = new char[64];\n        init(a);\n        init(b);\n        init(ansBit);\n        for (; i < 64; i++) {\n            if (lBit[i] == '0' && rBit[i] == '0') {\n            } else if (lBit[i] == '1' && rBit[i] == '0') {\n                throw new RuntimeException(\"Wrong Input\");\n            } else if (lBit[i] == '0' && rBit[i] == '1') {\n                a[i] = '0';\n                b[i] = '1';\n                break;\n            } else {\n                a[i] = '1';\n                b[i] = '1';\n            }\n        }\n        boolean aLessB = true;\n        boolean aBig = false;\n        boolean bSmall = false;\n        for (; i < 64; i++) {\n            if (lBit[i] == '0' && rBit[i] == '0') {\n                a[i] = '1';\n                b[i] = '0';\n                aBig = true;\n            } else if (lBit[i] == '1' && rBit[i] == '0') {\n                a[i] = '1';\n                b[i] = '0';\n            } else if (lBit[i] == '0' && rBit[i] == '1') {\n                a[i] = '0';\n                b[i] = '1';\n            } else {\n                a[i] = '1';\n                b[i] = '0';\n                bSmall = true;\n            }\n        }\n        for (i = 0; i < 64; i++) {\n            if (a[i] == '0' && b[i] == '0') {\n                ansBit[i] = '0';\n            } else if (a[i] == '1' && b[i] == '0') {\n                ansBit[i] = '1';\n            } else if (a[i] == '0' && b[i] == '1') {\n                ansBit[i] = '1';\n            } else {\n                ansBit[i] = '0';\n            }\n        }\n        String ansStr = new String(ansBit);\n        long ansValue = Long.parseLong(ansStr, 2);\n        output.println(ansValue);\n    }\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\n        LittleGirlAndMaximumXOR lgamx = new LittleGirlAndMaximumXOR(System.in, System.out);\n        lgamx.solve();\n    }\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    static BufferedReader f;\n    static StringTokenizer st;\n    public static void main (String [] args) throws Exception {\n        \n        // Use BufferedReader rather than RandomAccessFile; it's much faster\n        f = new BufferedReader(new java.io.InputStreamReader(System.in));\n        \n        long unixTime = System.currentTimeMillis();\n        \n        long l=nextLong();\n        long r=nextLong();\n        \n        String ll=Long.toBinaryString(l);\n        String rr=Long.toBinaryString(r);\n        \n        System.err.println(ll);\n        System.err.println(rr);\n        \n        System.err.println(Long.parseLong(rr,2));\n        \n        int len=0;\n        if(ll.length()!=rr.length()){\n            len=Math.max(ll.length(),rr.length());\n        }else{\n            //same\n            for(int i=0;i<ll.length();i++){\n                if(ll.charAt(i)!=rr.charAt(i)){\n                    len=ll.length()-i;\n                    break;\n                }\n            }\n        }\n        System.err.println(len);\n        //long out=0;\n        StringBuffer s=new StringBuffer();\n        for(int i=0;i<len;i++){\n            //out+=Math.pow(2, i);\n            s.append(1);\n        }\n        \n        if(len==0){\n            System.out.println(0);\n        }else{\n            System.out.println(Long.parseLong(s.toString(),2));\n        }\n        \n//      System.out.println(\"Time elapsed (ms): \"+(System.currentTimeMillis()-unixTime));\n        \n        System.exit(0);                               // don't omit this!\n      }\n    \n    //Library\n\n    static long nextLong() throws Exception{\n        return Long.parseLong(next());\n    }\n    static int nextInt() throws Exception {\n         return Integer.parseInt(next());\n     }\n    \n    static String next() throws Exception {\n             while (st == null || !st.hasMoreTokens()) {\n                     st = new StringTokenizer(f.readLine());\n             }\n             return st.nextToken();\n     }\n    \n}\nclass ii{\n    int a;\n    int b;\n    public ii(int a, int b){\n        this.a=a;\n        this.b=b;\n    }\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.*;\n\npublic class D {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic D () {\n\t\tlong L = sc.nextLong();\n\t\tlong R = sc.nextLong();\n\t\t\n\t\tint Z = 64 - Long.numberOfLeadingZeros(L ^ R);\n\t\tlong res = (1L << Z) - 1;\n\t\texit(res);\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print(Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint(Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "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\tlong L = sc.nextLong();\n\t\tlong R = sc.nextLong();\n\t\tlong res = Math.max(2 * Long.highestOneBit(L ^ R) - 1, 0);\n\t\tSystem.out.println(res);\n\t}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Comparator;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\n/**\n * @author Polyarniy Nickolay\n */\npublic class ProblemD {\n\n    private BufferedReader in;\n    private PrintWriter out;\n    private StringTokenizer tok;\n    private final String DELIMETER = \" \";\n    private final boolean ENABLE_MULTITEST = false;\n    private final boolean DEBUG = true;\n    private final String FILENAME = null;//if FILENAME = null, then works with console\n\n    public void run() throws Exception {\n        initInputOutput();\n        do {\n            init();\n            solve();\n        } while (hasMoreTokens() && ENABLE_MULTITEST);\n        finish();\n    }\n\n    private void init() throws Exception {\n    }\n\n    private void solve() throws Exception {\n        String a = Long.toBinaryString(nextLong());\n        String b = Long.toBinaryString(nextLong());\n        while (a.length() < 64) {\n            a = \"0\" + a;\n        }\n        while (b.length() < 64) {\n            b = \"0\" + b;\n        }\n//        out.println(a);\n//        out.println(b);\n        char[] res = new char[a.length()];\n        int cur = 0;\n        while (cur < a.length() && a.charAt(cur) == b.charAt(cur)) {\n            res[cur] = '0';\n            cur++;\n        }\n        while (cur < res.length) {\n            res[cur] = '1';\n            cur++;\n        }\n\n        out.println(Long.valueOf(new String(res), 2));\n    }\n\n    public static void main(String[] args) throws Exception {\n        ProblemD solution = new ProblemD();\n        solution.run();\n    }\n\n    private void initInputOutput() throws Exception {\n        if (FILENAME == null) {\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    private void shuffleArray(Object[] arr) {\n        Random r = new Random();\n        for (int i = 0; i < arr.length; ++i) {\n            Object tmp = arr[i];\n            int j = r.nextInt(arr.length);\n            arr[i] = arr[j];\n            arr[j] = tmp;\n        }\n    }\n\n    private void shuffleArray(int[] arr) {\n        Random r = new Random();\n        for (int i = 0; i < arr.length; ++i) {\n            int tmp = arr[i];\n            int j = r.nextInt(arr.length);\n            arr[i] = arr[j];\n            arr[j] = tmp;\n        }\n    }\n\n    private int[] nextArrayInt(int n) throws Exception {\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 String nextWord() throws Exception {\n        if (updateTokenizer()) {\n            return null;\n        } else {\n            return tok.nextToken();\n        }\n    }\n\n    private boolean hasMoreTokens() throws Exception {\n        return !updateTokenizer();\n    }\n\n    private boolean updateTokenizer() throws Exception {\n        while (tok == null || !tok.hasMoreTokens()) {\n            String nextLine = in.readLine();\n            if (nextLine == null || nextLine.isEmpty()) {\n                return true;\n            }\n            tok = new StringTokenizer(nextLine, DELIMETER);\n        }\n        return false;\n    }\n\n    private int nextInt() throws Exception {\n        return Integer.parseInt(nextWord());\n    }\n\n    private long nextLong() throws Exception {\n        return Long.parseLong(nextWord());\n    }\n\n    private void finish() throws Exception {\n        in.close();\n        out.close();\n    }\n\n    private void print(String s) {\n        if (DEBUG) {\n            System.out.print(s);\n        }\n    }\n\n    private void println(String s) {\n        if (DEBUG) {\n            System.out.println(s);\n        }\n    }\n\n    private void println() {\n        if (DEBUG) {\n            System.out.println();\n        }\n    }\n\n    private long[] getFirstSimpleNums(int n) {\n        boolean[] notPr = new boolean[n];\n        int res = n;\n        notPr[0] = true;\n        res--;\n        notPr[1] = true;\n        res--;\n        for (int i = 2; i < n; ++i) {\n            if (!notPr[i]) {\n                for (int j = i + i; j < n; j += i) {\n                    if (!notPr[j]) {\n                        notPr[j] = true;\n                        res--;\n                    }\n                }\n            }\n        }\n        long[] resA = new long[res];\n        int next = 0;\n        for (int i = 0; i < n; i++) {\n            if (!notPr[i]) {\n                resA[next] = i;\n                next++;\n            }\n        }\n        return resA;\n    }\n\n    private static class Pair {\n\n        int a;\n        int b;\n\n        public Pair(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n        public static final Comparator<Pair> comparator = new Comparator<Pair>() {\n\n            @Override\n            public int compare(Pair pair1, Pair pair2) {\n                return (pair1.a - pair2.a) != 0 ? (pair1.a - pair2.a) : (pair1.b - pair2.b);\n            }\n        };\n\n        @Override\n        public String toString() {\n            return \"{\" + a + \"|\" + b + '}';\n        }\n    }\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "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\n\npublic class D {\n\t\n\tstatic StringTokenizer st;\n\tstatic BufferedReader in;\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tlong L = nextLong();\n\t\tlong R = nextLong();\n\t\tif (L==R) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tString s1 = Long.toBinaryString(L), s2 = Long.toBinaryString(R);\n\t\twhile (s1.length() != s2.length())\n\t\t\ts1 = \"0\"+s1;\n\t\tfor (int i = 0; i < s1.length(); i++) {\n\t\t\tif (s1.charAt(i) != s2.charAt(i)) {\n\t\t\t\tint pow = s1.length()-i;\n\t\t\t\tSystem.out.println((long)Math.pow(2, pow)-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n\tprivate static int nextInt() throws IOException{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate static long nextLong() throws IOException{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate static double nextDouble() throws IOException{\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tprivate 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", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class con169_D {\n\n\tprivate static final boolean DEBUG = false;\n\n\tpublic static void main( final String[] args ) throws Exception {\n\t\tfinal BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );\n\t\tfinal String line = br.readLine();\n\t\tfinal StringTokenizer tok = new StringTokenizer( line );\n\n\t\tfinal long L = Long.parseLong( tok.nextToken() );\n\t\tfinal long R = Long.parseLong( tok.nextToken() );\n\n\t\tSystem.out.println( solve( L, R ) );\n\t}\n\n\tpublic static long solve( final long L, final long R ) {\n\t\tif ( L == R ) return L ^ R;\n\t\tif ( DEBUG ) System.out.printf( \"L=%d (%s), R=%d (%s)\\n\", L, Long.toBinaryString( L ), R,\n\t\t\t\tLong.toBinaryString( R ) );\n\n\t\tfinal int ld = length( L );\n\t\tfinal int ldm1 = ld - 1;\n\t\tfinal int rd = length( R );\n\n\t\tif ( ld < rd ) {\n\t\t\tlong max = 1;\n\t\t\twhile ( length( max ) < rd ) {\n\t\t\t\tmax <<= 1;\n\t\t\t}\n\t\t\tlong min = 1;\n\t\t\twhile ( length( min ) < rd - 1 ) {\n\t\t\t\tmin <<= 1;\n\t\t\t\t++min;\n\t\t\t}\n\t\t\tif ( DEBUG ) System.out.printf( \"min=%d (%s), max=%d (%s)\\n\", min, Long.toBinaryString( min ), max,\n\t\t\t\t\t\tLong.toBinaryString( max ) );\n\t\t\treturn min ^ max;\n\t\t} else {\n\t\t\tfinal char[] minStr = Long.toBinaryString( L ).toCharArray();\n\t\t\tfinal char[] maxStr = Long.toBinaryString( R ).toCharArray();\n\t\t\tfinal char[] res = new char[minStr.length];\n\t\t\tArrays.fill( res, '0' );\n\t\t\t{\n\t\t\t\tint i = 0;\n\t\t\t\twhile ( i < res.length ) {\n\t\t\t\t\tif ( minStr[ i ] == maxStr[ i ] ) {\n\t\t\t\t\t\tres[ i ] = '0';\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\t++i;\n\t\t\t\t}\n\t\t\t\tif ( DEBUG ) System.out.println( \"diff at pos: \" + i );\n\t\t\t\tif ( minStr[ i ] == '0' ) {\n\t\t\t\t\tres[ i++ ] = '1';\n\t\t\t\t\tfor ( int j = i; j < res.length; ++j ) {\n\t\t\t\t\t\tres[ j ] = '1';\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Long.parseLong( new String( res ), 2 );\n\t\t}\n\t}\n\n\tprivate static int length( long l ) {\n\t\tint res = 0;\n\t\twhile ( l > 0 ) {\n\t\t\t++res;\n\t\t\tl >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Codeforces\n{\n  public StreamTokenizer st;\n  public PrintWriter pw;\n  public static final int modulo = 1000000009; \n  \n  static class Point\n  {\n    public int x, y;\n    Point(int _x, int _y)\n    {\n      x = _x;\n      y = _y;\n    }\n  }\n  \n  void init(String in, String out) \n  {\n    if (in.isEmpty())\n      st = new StreamTokenizer(System.in);\n    else\n    {\n      try\n      {\n        st = new StreamTokenizer(new BufferedReader(new FileReader(in)));\n      }\n      catch(FileNotFoundException e)\n      {\n        \n      }\n    }\n    \n    if (out.isEmpty())\n      pw = new PrintWriter(System.out);\n    else\n    {\n      try\n      {\n        pw = new PrintWriter(new FileWriter(out));\n      }\n      catch(IOException e)\n      {\n        \n      }\n    }\n  }\n  \n  private void close()\n  {\n    pw.close();\n  }\n  \n  private int nI()\n  {\n    try{\n      st.nextToken();\n    }\n    catch(IOException e)\n    {\n      \n    }\n    return (int)st.nval;\n  }\n  \n  private double nD()\n  {\n    try{\n      st.nextToken();\n    }\n    catch(IOException e)\n    {\n      \n    }\n    return st.nval;\n  }\n  \n  private String nS()\n  {\n    try{\n      st.nextToken();\n    }\n    catch(IOException e)\n    {\n      \n    }\n    return st.sval;\n  }\n   \n  private long nL()\n  {\n    try{\n      st.nextToken();\n    }\n    catch(IOException e)\n    {\n      \n    }\n    return (long)st.nval;\n  }\n  \n  public static void qSort(int[] A, int low, int high) {\n    int i = low;                \n    int j = high;\n    int x = A[(low+high)/2];  \n    do {\n        while(A[i] < x) ++i;  \n        while(A[j] > x) --j;  \n        if(i <= j){           \n            \n            int temp = A[i];\n            A[i] = A[j];\n            A[j] = temp;\n       \n            i++; j--;\n        }\n    } while(i < j);\n    if(low < j) \n      qSort(A, low, j);\n    if(i < high) \n      qSort(A, i, high);\n    \n}\n  \n  public static void main(String[] aslkdjlkgja) throws IOException\n  {\n    Codeforces z = new Codeforces();\n    z.init(\"\", \"\");\n   \n    long l = z.nL();\n    long r = z.nL();\n    if ( l == r)\n    {\n      System.out.println(0);\n      z.close();\n      return;\n    }\n    \n    List<Boolean> R = new ArrayList<Boolean>();\n    List<Boolean> L = new ArrayList<Boolean>();\n    \n    long temp = r;\n    while (temp != 0)\n    {\n      if (temp % 2 == 1)\n        R.add(true);\n      else\n        R.add(false);\n      temp /= 2;\n    }\n    \n    Collections.reverse(R);\n    \n    temp = l;\n    while (temp != 0)\n    {\n      if (temp % 2 == 1)\n        L.add(true);\n      else\n        L.add(false);\n      temp /= 2;\n    }    \n    \n    int n = R.size() - L.size();\n    while (n!=0)\n    {\n      L.add(false);\n      --n;\n    }\n    Collections.reverse(L);\n    \n    List<Boolean> res = new ArrayList<Boolean>();\n   // for (int i = 0 ; i < R.size(); ++i)\n     // res.add(false);\n    \n    int it = 0;\n    \n    while (R.get(0) == L.get(0))\n    {\n      res.add(false);\n      R.remove(0);\n      L.remove(0);\n    }\n    \n    for (int i = 0; i< R.size(); ++i)\n      res.add(true);\n    \n    long out = 0;\n    it = 0;\n    long add = 1;\n    Collections.reverse(res);\n    while (it < res.size())\n    {\n      if (res.get(it))\n        out += add;\n      add *= 2;\n      ++it;\n    }\n    System.out.println(out);\n  }\n  \n  \n  \n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class pr169D implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer str;\n\n\tpublic void solve() throws IOException {\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n\t\tlong x = l ^ r;\n\t\tlong i = 1;\n\t\twhile (x >= i)\n\t\t\ti *= 2;\n\t\tout.println(x > i ? x : i - 1);\n\t}\n\n\tpublic String nextToken() throws IOException {\n\t\twhile (str == null || !str.hasMoreTokens()) {\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn str.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 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\tin.close();\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new pr169D()).start();\n\t}\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class A {\n\tpublic static BufferedReader in;\n\tpublic static PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tboolean showLineError = true;\n\t\tif (showLineError) {\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tsolve();\n\t\t\t} catch (Exception e) {\n\t\t\t} finally {\n\t\t\t\tout.close();\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic void debug(Object... os) {\n\t\tout.println(Arrays.deepToString(os));\n\t}\n\n\tprivate static void solve() throws IOException {\n\t\tString[] line = in.readLine().split(\" \");\n\t\tString l = Long.toBinaryString(Long.parseLong(line[0]));\n\t\tString r = Long.toBinaryString(Long.parseLong(line[1]));\n\t\tif(l.equals(r)){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint dif = r.length()-l.length();\n\t\tfor(int i =0;i<dif;i++)\n\t\t\tl= \"0\"+l;\n\t\tint index=0;\n\t\tfor(;index<r.length();index++){\n\t\t\tif(l.charAt(index)!=r.charAt(index))\n\t\t\t\tbreak;\n\t\t}\n\t\tlong ret=1;\n\t\tfor(int i=0;i<l.length()-index;i++)\n\t\t\tret+=ret;\n\t\tret--;\n\t\tout.println(ret);\n\t\t\n\t}\n\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.StringTokenizer;\n\npublic class SolutionD {\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   void run() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        //in = new BufferedReader(new FileReader(\"input.txt\"));\n        //out = new PrintWriter(\"output.txt\");\n        solve();\n        out.close();\n   }\n\n   public static void main(String[] args) throws IOException {\n      new SolutionD().run();\n   }\n   void solve() throws IOException {\n        long l=Long.parseLong(next());\n        long r=Long.parseLong(next());\n        String low=Long.toBinaryString(l);\n        String up=Long.toBinaryString(r);\n        \n        int n=low.length();\n        int m=up.length();\n        for(int i=0;i<m-n;i++){\n             low=\"0\"+low;\n        }\n        String ret=\"\";\n        boolean fu=false;\n        boolean fd=false;\n        boolean su=false;\n        boolean sd=false;\n        if(m>n){\n             su=true;\n             fd=true;\n        }\n        for(int i=0;i<m;i++){\n           if(low.charAt(i)==up.charAt(i)){\n                if(low.charAt(i)=='1'){\n                     if(fd){\n                          ret+=\"1\";\n                          fu=true;\n                     }\n                     else if(sd){\n                          ret+=\"1\";\n                          su=true;\n                     }\n                     else ret+=\"0\";\n                }\n                else{\n                     if(fu){\n                          ret+=\"1\";\n                          fd=true;\n                     }\n                     else if(su){\n                          ret+=\"1\";\n                          sd=true;\n                     }\n                     else ret+=\"0\";\n                }\n           }else{\n                if(up.charAt(i)=='1'){\n                     su=true;\n                     fd=true;\n                }\n                \n                ret+=\"1\";\n           }\n        }\n        \n        out.println(Long.parseLong(ret, 2));\n        \n        \n      \n         \n   }\n \n\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        Scanner scn = new Scanner(System.in);\n        long a,b;\n        a = scn.nextLong();\n        b = scn.nextLong();\n        long diff = b -a , tot = 0;\n        int ind = 0;\n        while(true) {\n            long res = (long)Math.pow(2.0, ind);\n            if (res > b) break;\n            if (((a>>ind) != (b>>ind)) || diff >= res)\n                tot += res;\n            ind++;\n        }\n        System.out.println(tot);\n    }                                                                                                                                                                                                                          \n\n}\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class D {\n\tstatic long l, r;\n\tstatic long[][][][][] dp;\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader in = new InputReader();\n\t\tl = in.nextLong();\n\t\tr = in.nextLong();\n\t\tdp = new long[65][2][2][2][2];\n\t\tfor(int i = 0 ; i < 65;i++)\n\t\tfor(int j = 0 ; j < 2;j++)\n\t\tfor(int k = 0 ; k < 2;k++)\n\t\tfor(int a = 0 ; a<2;a++)\n\t\tdp[i][j][k][a][0]=dp[i][j][k][a][1]=-1;\n\t\tSystem.out.println(go(63, 0, 0, 0, 0));\n\t}\n\n\tpublic static long go(int i, int a1, int a2, int b1, int b2) {\n\t\tif(i==-1)return 0;\n\t\tif(dp[i][a1][a2][b1][b2]!=-1)\n\t\t\treturn dp[i][a1][a2][b1][b2];\n\t\t\n\t\tint f1 = 3, f2 = 3;\n\t\tint bl = (int) ((l >> i)) & 1, br = (int) ((r >> i) & 1);\n\t\tif (a2 == 0 && br==0)\n\t\t\tf1 &= 1;\n\t\tif(a1 == 0 && bl==1)\n\t\t\tf1 &= 2;\n\t\tif (b2 == 0 && br==0)\n\t\t\tf2 &= 1;\n\t\tif(b1 == 0 && bl==1)\n\t\t\tf2 &= 2;\n\t\tlong res = 0;\n\t\tfor(int x = 0 ; x<2;x++){\n\t\t\tfor(int y = 0 ; y<2;y++){\n\t\t\t\tif(((f1>>x)&1) == 1 &&((f2>>y)&1) == 1){\n\t\t\t\t\tres = Math.max(res, (((long)(x^y))<<i)+go(i-1,x>bl||a1==1?1:0,x<br||a2==1?1:0,y>bl||b1==1?1:0,y<br||b2==1?1:0));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[i][a1][a2][b1][b2]=res;\n\t}\n\n\tstatic class InputReader {\n\t\tBufferedReader in;\n\t\tStringTokenizer st;\n\n\t\tpublic InputReader() throws IOException {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (!st.hasMoreElements())\n\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class D {\n\t\n\tpublic static void main(String [] args){\n\t\tScanner cin = new Scanner(System.in);\n\t\tPrintWriter cout = new PrintWriter(System.out);\n\t\tlong l = cin.nextLong(), r = cin.nextLong(), k = 1;\n\t\tif (l == r)cout.println(0);\n\t\telse {\n\t\t\twhile (((r>>k)<<k)>l)k++;k--;\n\t\t\tcout.println(((r>>k)<<k)^(((r>>k)<<k)-1));\n\t\t}\n\t\tcout.flush();\n\t}\n\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "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 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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long l = in.nextLong();\n        long r = in.nextLong();\n        /*\n        long max = 1;\n        boolean good = false;\n        for (int i = 0; i < 62; ++i) {\n            max <<= 1;\n            if (max > r) {\n                max >>= 1;\n                if (max >= l) {\n                    good = true;\n                }\n                break;\n            }\n        }\n        if (good) {\n            if (max - 1 >= l)\n                out.println(max ^ (max - 1));\n            else\n                out.println(max ^ r);\n            return;\n        }\n        */\n        boolean[][] answer = new boolean[2][100];\n        int cur = 0;\n        while (r > 0) {\n            answer[0][cur] = (r % 2 != 0);\n            ++cur;\n            r >>= 1;\n        }\n        cur = 0;\n        while (l > 0) {\n            answer[1][cur] = (l % 2 != 0);\n            ++cur;\n            l >>= 1;\n        }\n        int old = -1;\n        for (int i = 63; i >= 0; --i) {\n            if (answer[0][i] && !answer[1][i]) {\n                old = i;\n                break;\n            }\n        }\n        if (old == -1) {\n            out.println(0);\n            return;\n        }\n        long a = 1;\n        for (int i = 0; i < old; ++i) {\n            a <<= 1;\n            a += 1;\n        }\n        out.println(a);\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 long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    }\n\n", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main2 {\n\t\n    public static void main(String args[]){\n        Scanner input = new Scanner(System.in);\n        long s = input.nextLong();\n        long e = input.nextLong();\n        System.out.println(count(s,e));\n    }\n    \n    public static long count(long s,long e){\n    \tint ncount = 0;\n    \tlong es = e;\n    \twhile(es != 0){\n    \t\tes /= 2;\n    \t\tncount++;\n    \t}\n    \twhile(ncount >= 0){\n    \t\tif(((s>>ncount-1)&1) == 1 && ((e>>ncount-1)&1) == 0 || ((s>>ncount-1)&1) == 0 && ((e>>ncount-1)&1) == 1){\n    \t\t\tbreak;\n    \t\t}\n    \t\tncount--;\n    \t}\n    \tif(ncount >= 0){\n    \t\treturn (long)Math.pow(2, ncount)-1;\n    \t}else{\n    \t\treturn 0;\n    \t}\n    }\n\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n\n\npublic class Code {\n\tpublic Code(){}\n\tpublic static void main(String args[]){\n\t\tScanner QQQ=new Scanner(System.in);\n\t\tlong l=QQQ.nextLong();\n\t\tlong r=QQQ.nextLong();\n\t\tlong ans=l^r;\n\t\tint a[]=new int [70];\n\t\tint b[]=new int [70];\n\t\tint n=0,m=0;\n\t\twhile (l!=0){\n\t\t\ta[m]=(int)(l%2);\n\t\t\tl/=2;\n\t\t\tm++;\n\t\t}\n\t\twhile (r!=0){\n\t\t\tb[n]=(int)(r%2);\n\t\t\tr/=2;\n\t\t\tn++;\n\t\t}\n\t\tm--;n--;\n\t\tlong deg[]=new long [70];\n\t\tdeg[0]=1;\n\t\tfor (int i=1;i<=62;i++) deg[i]=deg[i-1]*2;\n\t\tfor (int i=n;i>=0;i--) \n\t\t\tif (b[i]==1&&a[i]==0){\n\t\t\t\tSystem.out.println(deg[i+1]-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemD {\n    InputReader in; PrintWriter out;\n    void solve() {\n        long l = in.nextLong();\n        long r = in.nextLong();\n        long ans = 0;\n        boolean add = false;\n        for (int k = 62; k >= 0; k--) {\n            long cb = (1L << k);\n            if ((l & cb) != (r & cb))\n                add = true;\n            if (add)\n                ans += (1L << k);\n        }\n        out.println(ans);\n    }\n    \n    ProblemD(){\n        boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        try {\n            if (oj) {\n                in = new InputReader(System.in);\n                out = new PrintWriter(System.out);\n            }\n            else {\n                Writer w = new FileWriter(\"output.txt\");\n                in = new InputReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(w);\n            }\n        } catch(Exception e) {\n            throw new RuntimeException(e);\n        }\n        solve();\n        out.close();\n    }\n    public static void main(String[] args){\n        new ProblemD();\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 InputReader(FileReader fr) {\n        reader = new BufferedReader(fr);\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    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}", "complexity": "logn", "problem": "276_D. Little Girl and Maximum XOR", "from": "CODEFORCES"}
{"src": "//Author: Patel Rag\n//Java version \"1.8.0_211\"\nimport java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n  static class FastReader\n  {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastReader(){ br = new BufferedReader(new 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 nextInt() { return Integer.parseInt(next()); }\n\n    long nextLong(){ return Long.parseLong(next()); }\n\n    double nextDouble(){ return Double.parseDouble(next()); }\n\n    float nextFloat() { return Float.parseFloat(next()); }\n\n    boolean nextBoolean() { return Boolean.parseBoolean(next()); }\n\n    String nextLine()\n    {\n      String str = \"\";\n      try\n      {\n        str = br.readLine();\n      }\n      catch (IOException e)\n      {\n        e.printStackTrace();\n      }\n      return str;\n    }\n  }\n  static long modExp(long x, long n, long mod)    //binary Modular exponentiation\n  {\n    long result = 1;\n    while(n > 0)\n    {\n        if(n % 2 == 1)\n            result = (result%mod * x%mod)%mod;\n        x = (x%mod * x%mod)%mod;\n        n=n/2;\n    }\n    return result;\n  }\n  static long gcd(long a, long b)\n  {\n    if(a==0) return b;\n    return gcd(b%a,a);\n  }\n  public static void main(String[] args)\n  throws IOException\n  {\n    FastReader fr = new FastReader();\n    int n = fr.nextInt();\n    int q = fr.nextInt();\n    long[] a = new long[n];\n    long[] k = new long[q];\n    for(int i = 0; i < n; i++) a[i] = fr.nextLong();\n    for(int i = 0; i < q; i++) k[i] = fr.nextLong();\n    long[] pre = new long[n];\n    pre[0] = a[0];\n    for(int i = 1; i < n; i++) pre[i] = pre[i-1] + a[i];\n    long pd = 0;\n    for(int i = 0; i < q; i++)\n    {\n      int l = 0;\n      int r = n - 1;\n      while(r > l)\n      {\n        int mid = (l + r) >> 1;\n\n        if(pre[mid] - pd < k[i])\n        {\n          l = mid + 1;\n        }\n        else if(pre[mid] - pd > k[i])\n        {\n          r = mid - 1;\n        }\n        else\n        {\n          l = r = mid;\n        }\n      }\n      int ans = 0;\n      if(pre[l] - pd <= k[i])\n      {\n        ans = n - l - 1;\n      }\n      else\n      {\n        ans = n - l;\n      }\n      if(ans == 0) ans  = n;\n      pd = pd + k[i];\n      if(pd >= pre[n-1]) pd = 0;\n      System.out.println(ans);\n    }\n  }\n}\nclass pair\n{\n  public int first;\n  public int second;\n  public pair(int first,int second)\n  {\n    this.first = first;\n    this.second = second;\n  }\n  public pair(pair p)\n  {\n    this.first = p.first;\n    this.second = p.second;\n  }\n  public int first() { return first; }\n  public int second() { return second; }\n  public void setFirst(int first) { this.first = first; }\n  public void setSecond(int second) { this.second = second; }\n}\nclass myComp implements Comparator<pair>\n{\n  public int compare(pair a,pair b)\n  {\n    if(a.first != b.first) return (a.first - b.first);\n    return (b.second - a.second);\n  }\n}\nclass BIT       //Binary Indexed Tree aka Fenwick Tree\n{\n  public long[] m_array;\n\n  public BIT(long[] dat)\n  {\n    m_array = new long[dat.length + 1];\n    Arrays.fill(m_array,0);\n    for(int i = 0; i < dat.length; i++)\n    {\n      m_array[i + 1] = dat[i];\n    }\n    for(int i = 1; i < m_array.length; i++)\n    {\n      int j = i + (i & -i);\n      if(j < m_array.length)\n      {\n        m_array[j] = m_array[j] + m_array[i];\n      }\n    }\n  }\n\n  public final long prefix_query(int i)\n  {\n    long result = 0;\n    for(++i; i > 0; i = i - (i & -i))\n    {\n      result = result + m_array[i];\n    }\n    return result;\n  }\n\n  public final long range_query(int fro, int to)\n  {\n    if(fro == 0)\n    {\n      return prefix_query(to);\n    }\n    else\n    {\n      return (prefix_query(to) - prefix_query(fro - 1));\n    }\n  }\n\n  public void update(int i, long add)\n  {\n    for(++i; i < m_array.length; i = i + (i & -i))\n    {\n      m_array[i] = m_array[i] + add;\n    }\n  }\n}\n", "complexity": "nlogn", "problem": "975_C. Valhalla Siege", "from": "CODEFORCES"}
{"src": "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.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 \\/\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            int n = in.nextInt();\n            int m = in.nextInt();\n\n            TaskC.pair[] songs = new TaskC.pair[n];\n            long sum = 0;\n            for (int i = 0; i < n; i++) {\n                songs[i] = new TaskC.pair(in.nextInt(), in.nextInt());\n                sum += songs[i].a;\n            }\n            Arrays.sort(songs);\n\n            int res = 0;\n            int idx = n - 1;\n            while (sum > m) {\n                if (idx < 0) {\n                    break;\n                }\n                sum -= (songs[idx].a - songs[idx].b);\n\n                res++;\n                idx--;\n            }\n\n            if (sum > m) {\n                out.println(-1);\n            } else {\n                out.println(res);\n            }\n        }\n\n        static class pair implements Comparable<TaskC.pair> {\n            int a;\n            int b;\n\n            pair(int a, int b) {\n                this.a = a;\n                this.b = b;\n            }\n\n            public int compareTo(TaskC.pair p) {\n                return (this.a - this.b) - (p.a - p.b);\n            }\n\n        }\n\n    }\n\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public Scanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public Scanner(String s) {\n            try {\n                br = new BufferedReader(new FileReader(s));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "1015_C. Songs Compression", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CoveredPointsCount {\n\t\n\t//UPSOLVE\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        \n\t\tint n = Integer.parseInt(st.nextToken());\n\t     \n\t\tlong[] myArray = new long[2 * n];\n\t        \n\t\t\tfor (int i = 0; i < n; i++)  {\n\t        \tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t        \tmyArray[2 * i] = Long.parseLong(st1.nextToken()) * 2;\n\t        \tmyArray[2 * i + 1] = Long.parseLong(st1.nextToken()) * 2 + 1;\n\t        }  \n\t        \n\t        Arrays.sort(myArray);\n\t        long[] ans = new long[n + 1];\n\t        int cnt = 0;\n\t       \n\t        for (int i = 0; i < 2 * n - 1; i++)   {\n\t            if (myArray[i] % 2 == 0) cnt++; else cnt--;\n\t            ans[cnt] += (myArray[i + 1] + 1) / 2 - (myArray[i] + 1) / 2;\n\t        }   \n\t        \n\t        StringBuilder answer = new StringBuilder();\n\t        \n\t        for (int i = 1; i < n + 1; i++) {\n\t        \tanswer.append(ans[i]);\n\t        \tanswer.append(\" \");\n\t        }  \n\t        \n\t        System.out.println(answer);\n\n\t}\n\n}\n", "complexity": "nlogn", "problem": "1000_C. Covered Points Count", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CoveredPointsCount {\n\t\n\t//UPSOLVE\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        \n\t\tint n = Integer.parseInt(st.nextToken());\n\t     \n\t\tlong[] myArray = new long[2 * n];\n\t        \n\t\t\tfor (int i = 0; i < n; i++)  {\n\t        \tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t        \tmyArray[2 * i] = Long.parseLong(st1.nextToken()) * 2;\n\t        \tmyArray[2 * i + 1] = Long.parseLong(st1.nextToken()) * 2 + 1;\n\t        }  \n\t        \n\t        Arrays.sort(myArray);\n\t        long[] ans = new long[n + 1];\n\t        int cnt = 0;\n\t       \n\t        for (int i = 0; i < 2 * n - 1; i++)   {\n\t            if (myArray[i] % 2 == 0) cnt++; else cnt--;\n\t            ans[cnt] += (myArray[i + 1] + 1) / 2 - (myArray[i] + 1) / 2;\n\t        }   \n\t        \n\t        StringBuilder answer = new StringBuilder();\n\t        \n\t        for (int i = 1; i < n + 1; i++) {\n\t        \tanswer.append(ans[i]);\n\t        \tanswer.append(\" \");\n\t        }  \n\t        \n\t        System.out.println(answer);\n\n\t}\n\n}\n", "complexity": "nlogn", "problem": "1000_C. Covered Points Count", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class A {\n    static int[] parent;\n\n    public static int find(int x) {\n        if (x == parent[x])\n            return x;\n        return parent[x] = find(parent[x]);\n    }\n\n    public static void union(int x, int y) {\n        int px = find(x);\n        int py = find(y);\n        if (px != py) {\n            parent[py] = px;\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        int numCnt = (int) nextLong();\n        long k = nextLong();\n        parent = new int[numCnt];\n        for (int i = 0; i < parent.length; i++) {\n            parent[i] = i;\n        }\n        HashMap<Long, Integer> map = new HashMap<Long, Integer>();\n        long[] ar = new long[numCnt];\n        for (int i = 0; i < numCnt; i++) {\n            ar[i] = nextLong();\n            map.put(ar[i] * 10007 + ar[i] / 13, i);\n        }\n        for (int i = 0; i < ar.length; i++) {\n            long req = ar[i] * k;\n            Integer idx=map.get(req * 10007 + req / 13);\n            if (idx!=null) {\n                union(i, idx);\n            }\n        }\n        int[] count = new int[numCnt];\n        for (int i = 0; i < parent.length; i++) {\n            count[find(i)]++;\n        }\n        int res = 0;\n        for (int i = 0; i < numCnt; i++) {\n            res += (int) ((count[i] + 1) / 2.0);\n        }\n        System.out.println(res);\n    }\n\n    static BufferedReader br = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer tokenizer = new StringTokenizer(\"\");\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    static String next() throws Exception {\n        while (true) {\n            if (tokenizer.hasMoreTokens()) {\n                return tokenizer.nextToken();\n            }\n            String s = br.readLine();\n            if (s == null) {\n                return null;\n            }\n            tokenizer = new StringTokenizer(s);\n        }\n    }\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\n// @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        int k = nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n        }\n        boolean[] ok = new boolean[n];\n        Arrays.fill(ok, true);\n        Arrays.sort(a);\n        if (k != 1) {\n            for (int i = 0; i < n; i++) {\n                if (a[i] % k == 0) {\n                    int x = a[i] / k;\n                    int ind = Arrays.binarySearch(a, x);\n                    if (ind >= 0 && ok[ind]) {\n                        ok[i] = false;\n                    }\n                }\n            }\n        }\n        int ans = 0;\n        for (int i = 0; i < n; i++) {\n            if (ok[i]) {\n                ans++;\n            }\n        }\n        out.println(ans);\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Template().run();\n    }\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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\tBufferedReader c=new BufferedReader(new InputStreamReader(System.in));\n\t\tString S[]=c.readLine().split(\" \");\n\t\tint N=Integer.parseInt(S[0]);\n\t\tint K=Integer.parseInt(S[1]);\n\t\tint A[]=parseArray(c.readLine(),N);\n\t\tshuffle(A);\n\t\tArrays.sort(A);\n\t\t\n\t\tTreeMap<Long,Long> T=new TreeMap<Long, Long>();\n\t\tint ans=0;\n\t\tfor(int i=0;i<N;i++)\n\t\t\tT.put((long)A[i],1L);\n\t\t//System.out.println(Arrays.toString(A));\n\t\tif(K==1)\n\t\t\t{\n\t\t\tSystem.out.println(N);\n\t\t\treturn;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tfor(int i=0;i<N;i++)\n\t\t\t\t{\n\t\t\t\tif(A[i]%K==0&&T.containsKey((long)A[i]/K))\t\t//A[i] is not start of a chain\n\t\t\t\t\tcontinue;\n\t\t\t\t//System.out.println(\"considering \"+A[i]);\n\t\t\t\tint chainSize=0;\n\t\t\t\tlong init=A[i];\n\t\t\t\twhile(T.containsKey(init))\n\t\t\t\t\t{\n\t\t\t\t\tchainSize++;\n\t\t\t\t\tinit=init*K;\n\t\t\t\t\t}\n\t\t\t\t//System.out.println(\"\\t\"+chainSize);\n\t\t\t\tans+=(chainSize+1)/2;\n\t\t\t\t}\n\t\t\t}\n\t\tSystem.out.println(ans);\n\t\t}\n\t/** \n\t * Knuth's shuffle. Generate a random permutation of an array\n\t */\n\tpublic static int[] shuffle(int A[])\n\t\t{\n\t\tint N=A.length;\n\t\tfor(int i=1;i<N;i++)\n\t\t\t{\n\t\t\tint j=(int) (Math.random()*100000)%(i+1); // 0<=j<=i;\n\t\t\tint temp=A[i];\n\t\t\tA[i]=A[j];\n\t\t\tA[j]=temp;\n\t\t\t}\n\t\treturn A;\n\t\t}\n\t// Parse an integer array of size N from a string s\n\tpublic static int[] parseArray(String s,int N)\n\t\t{\n\t\tint A[]=new int[N];\n\t\tStringTokenizer st=new StringTokenizer(s);\n\t\tfor(int i=0;i<N;i++)\n\t\t\tA[i]=Integer.parseInt(st.nextToken());\n\t\treturn A;\n\t\t}\n\t}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\n\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n//basically tried to understand ping's greedy alg\npublic class kMultRedo {\n\tstatic int n;\n\tstatic int k;\n\tpublic static void main(String[] args){\n\t\t\n\t\t//lol what?? If use HashSet timeout, but if use tree set, not?\n\t\t//even with super high initialize capacty = 100,000,where max 100000\n\t\tSet<Integer> set = new HashSet<Integer>(1000000);\n\t\tFastScanner s = new FastScanner();\n\t\tn = s.nextInt();\n\t\tk = s.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] = s.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\t\n\t\tfor(int i=0; i<n; i++){\n\t\t\tif(a[i]%k !=0){\n\t\t\t\tset.add(a[i]);\n\t\t\t}else{\n\t\t\t\tif(!set.contains(a[i]/k)){\n\t\t\t\t\tset.add(a[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(set.size());\n\t}\n\t\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Set;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\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 Zakhar Voit\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int k = in.nextInt();\n\n        Integer[] a = new Integer[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n\n        Set <Integer> vis = new TreeSet<Integer>();\n        Arrays.sort(a);\n        int ans = 0;\n        for (int i = 0; i < n; i++) {\n            if (!(a[i] % k == 0 && vis.contains(a[i] / k))) {\n                ++ans;\n                vis.add(a[i]);\n            }\n        }\n\n        out.println(ans);\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        if (!tok.hasMoreTokens()) {\n            try {\n                String newLine = in.readLine();\n                if (newLine == null)\n                    throw new InputMismatchException();\n                tok = new StringTokenizer(newLine);\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            return nextToken();\n        }\n\n        return tok.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextToken());\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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    static StringTokenizer st;\n    static BufferedReader in;\n    public static void main(String[] args) throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int n = nextInt();\n        int k = nextInt();\n        Integer[]a = new Integer[n+1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = nextInt();\n        }\n        if (k==1) {\n            System.out.println(n);\n            return;\n        }\n        Arrays.sort(a, 1, n+1);\n        Set<Integer> set = new HashSet<Integer>();\n        int ans = 0;\n        int INF = (int) 1e9;\n        for (int i = 1; i <= n; i++) {\n            if (set.contains(a[i]))\n                continue;\n            int t = a[i];\n            int s = 1;\n            while ((long)t*k <= INF) {\n                t *= k;\n                if (Arrays.binarySearch(a, 1, n+1,  t) >= 0) {\n                    set.add(t);\n                    s++;\n                }\n                else\n                    break;\n            }\n            if (s % 2==0)\n                ans += s/2;\n            else\n                ans += s/2+1;\n        }\n        System.out.println(ans);\n        pw.close();\n    }\n    private static int nextInt() throws IOException{\n        return Integer.parseInt(next());\n    }\n    \n    private static long nextLong() throws IOException{\n        return Long.parseLong(next());\n    }\n    \n    private static double nextDouble() throws IOException{\n        return Double.parseDouble(next());\n    }\n    \n    private static String next() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n\npublic class CFJava {\n    private static void println(Integer n) {\n        System.out.println(n);\n    }\n\n    private static void println(String s) {\n        System.out.println(s);\n    }\n\n    private static void print(Integer n) {\n        System.out.print(n);\n    }\n\n    private static void print(String s) {\n        System.out.print(s);\n    }\n\n\n    public static void main(String[] args) throws IOException {\n        MyScanner scanner = new MyScanner();\n        int n = scanner.nextInt();\n        int k = scanner.nextInt();\n        Integer[] a = scanner.getIntArray(n);\n        Arrays.sort(a);\n        TreeSet<Integer> res = new TreeSet<Integer>();\n        for (Integer i: a){\n            if (!res.contains(i/k)||(i%k!=0))\n                res.add(i);\n        }\n        println(res.size());\n    }\n}\n\nclass Pair {\n    public int x;\n    public int y;\n\n    Pair(int x, int y) {\n        this.x = x;\n        this.y = y;\n    }\n}\n\nclass MyScanner {\n    private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    private String[] buffer;\n    private int pos = 0;\n\n    public Integer nextInt() throws IOException {\n        if (buffer == null) {\n            buffer = in.readLine().split(\" \");\n            pos = 0;\n        }\n        if (buffer.length <= pos) {\n            buffer = in.readLine().split(\" \");\n            pos = 0;\n        }\n        pos++;\n        return Integer.parseInt(buffer[pos - 1]);\n    }\n\n    public String nextString() throws IOException {\n        if (buffer == null) {\n            buffer = in.readLine().split(\" \");\n            pos = 0;\n        }\n        if (buffer.length <= pos) {\n            buffer = in.readLine().split(\" \");\n            pos = 0;\n        }\n        pos++;\n        return buffer[pos - 1];\n    }\n\n    public ArrayList<Integer> getIntList(Integer n) throws IOException {\n        ArrayList<Integer> result = new ArrayList<Integer>(n);\n        for (int i = 0; i < n; i++)\n            result.add(nextInt());\n        return result;\n    }\n\n    public Integer[] getIntArray(Integer n) throws IOException {\n        Integer[] result = new Integer[n];\n        for (int i = 0; i < n; i++)\n            result[i]= (nextInt());\n        return result;\n    }\n\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class A {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic A () {\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tLong [] A = sc.nextLongs();\n\n\t\tsort(A);\n\t\tSet<Long> S = new HashSet<Long>();\n\t\t\n\t\tfor (long a : A) {\n\t\t\tif (a % K == 0 && S.contains(H(a/K)))\n\t\t\t\tcontinue;\n\t\t\tS.add(H(a));\n\t\t}\n\t\t\n\t\tint res = S.size();\n\t\texit(res);\n\t}\n\n\tlong P = probablePrime(60, new Random()).longValue();\n\tlong Q = probablePrime(60, new Random()).longValue();\n\t\n\tlong H(long x) {\n\t\treturn P*x + Q;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print(Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint(Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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\tvoid run() {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = in.nextInt(), k = 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\tArrays.sort(a);\n\t\tint ret = 0, it = 0;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint val = a[i] % k == 0 ? a[i] / k : -1;\n\t\t\twhile (it < i && a[it] < val) ++it;\n\t\t\tif (it == i || a[it] != val) {\n\t\t\t\t++ret;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ta[i] = 0;\n\t\t\t}\n\t\t}\n\t\tout.println(ret);\n\n\t\tout.close();\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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.util.HashSet;\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\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        HashSet<Integer> set = new HashSet<Integer>();\n        int a[] = new int[n];\n        for (int i = 0; i < n; ++i) {\n            a[i] = in.nextInt();\n        }\n        Arrays.sort(a);\n        int ans = 0;\n        int ptr = -1;\n        boolean chosen[] = new boolean[n];\n        for (int i = 0; i < n; ++i) {\n            while (ptr + 1 < i && a[ptr + 1] * (long)k <= a[i]) {\n                ++ptr;\n            }\n\n            if (a[i] % k != 0 || ptr == -1 || !chosen[ptr] || a[ptr] * (long)k != a[i]) {\n                ++ans;\n                chosen[i] = true;\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    public static void main(String[] args) throws Exception {\n        new A().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 InputStreamReader(System.in));\n        // Scanner sc = new Scanner(System.in);\n        String[] sp;\n\n\n        sp = in.readLine().split(\" \");\n        int n = Integer.parseInt(sp[0]);\n        long k = Integer.parseInt(sp[1]);\n        Long[] a = new Long[n];\n        sp = in.readLine().split(\" \");\n        for (int i = 0; i < n; i++) {\n            a[i] = (long) Integer.parseInt(sp[i]);\n        }\n\n        Arrays.sort(a);\n        TreeSet<Long> set = new TreeSet<Long>();\n        for (int i = 0; i < n; i++) {\n            long x = a[i];\n            if (!set.contains(x)) {\n                set.add(x * k);\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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  test{\n\t\n\t// ArrayList<Integer> lis = new ArrayList<Integer>();\n\t// ArrayList<String> lis = new ArrayList<String>();\n\t//  PriorityQueue<P> que = new PriorityQueue<P>();\n\t// PriorityQueue<Integer> que = new PriorityQueue<Integer>();\n\t//  Stack<Integer> que = new Stack<Integer>();\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<Integer> set = new HashSet<Integer>();\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(),r=0;long k=sc.nextInt();\n    Integer x[]=new Integer[n];\n\t boolean b[]=new boolean[n];\n   \n   for(int i=0;i<n;i++){\n\t   x[i]=sc.nextInt();\n  }\n   if( k==1 ){System.out.println(n); return;}\n   sort(x);\n   \n   for(int i=0;i<n;i++){\n\t if( b[i] )continue;\n\t r++;\n\t long p=x[i],pr=x[i];\n\t while( p*k<=x[n-1] ) {p*=k;\n\t \n\t int up=n,dw=0,mid=(up+dw)/2;\n\t boolean f=false;\n\t while( up-dw!=1 ){\n\t\t //db(p,x[mid]);\n\t\t if( x[mid]==p ){f=true;break;}\n\t\t if( p<x[mid] ){ up=mid; mid=(up+dw)/2; }\n\t\t else { dw=mid; mid=(up+dw)/2; }\n\t }\n\t  if( f ){ if(pr*k!=p){r++; pr=p;}   b[mid]=true;  } \n\t  }\n\t\n\t \n  }\n\n    System.out.println(r);\n\t   \n}\n\nstatic void db(Object... os){\n    System.err.println(Arrays.deepToString(os));\n\n}\n\n\n}\n\nclass Reader\n{\n\tprivate BufferedReader x;\n\tprivate StringTokenizer st;\n\t\n\tpublic Reader(InputStream in)\n\t{\n\t\tx = new BufferedReader(new InputStreamReader(in));\n\t\tst = null;\n\t}\n\tpublic String nextString() throws IOException\n\t{\n\t\twhile( st==null || !st.hasMoreTokens() )\n\t\t\tst = new StringTokenizer(x.readLine());\n\t\treturn st.nextToken();\n\t}\n\tpublic int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\tpublic long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\tpublic double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n}\n\n/*\n\nclass P implements Comparable<P>{\n\tint x,y;\n\tP(int x,int y){ this.x=x; this.y=y;  }\n\t\n\tpublic int compareTo(P z) {\n\t if( x-z.x!=0)   return  x-z.x ;  //ascend \n\t else return  y-z.y ; \n\t}\n}\n//*/\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class a {\npublic static void main(String[] args) throws IOException\n{\n    input.init(System.in);\n    int n = input.nextInt(), k = input.nextInt();\n    TreeSet<Integer> ts = new TreeSet<Integer>();\n    int[] data = new int[n];\n    for(int i = 0; i<n; i++)\n    {\n        data[i] = input.nextInt();\n    }\n    Arrays.sort(data);\n    if(n>1 && k==1.*data[n-1]/data[0])\n        System.out.println(n-1);\n    else\n    {\n    for(int i = 0; i<n; i++)\n    {\n        if(data[i]%k != 0)\n            ts.add(data[i]);\n        else\n        {\n            if(!ts.contains(data[i]/k))\n                ts.add(data[i]);\n        }\n    }\n    System.out.println(ts.size());\n    }\n}\npublic static class input {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    /** get next word */\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n    static long nextLong() throws IOException {\n        return Long.parseLong( next() );\n    }\n}\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tpublic static void main(String [] args ) {\n\t\ttry{\n\t\t\tString str;\t\t\t\n\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tBufferedOutputStream bos = new BufferedOutputStream(System.out);\n\t\t\tString eol = System.getProperty(\"line.separator\");\n\t\t\tbyte [] eolb = eol.getBytes();\n\t\t\tbyte[] spaceb= \" \".getBytes();\n\t\t\t\n\t\t\t\n\t\t\tstr  = br.readLine();\n\t\t\tint blank = str.indexOf( \" \");\n\t\t\tint n = Integer.parseInt(str.substring(0,blank));\n\t\t\tint m = Integer.parseInt(str.substring(blank+1));\n\t\t\tlong [] num = new long[n];\n\t\t\tint j=0;\n\t\t\tint s=0;\n\t\t\tint k =0;\n\t\t\tstr = br.readLine();\n\t\t\tint length = str.length();\n\t\t\twhile(j<length) {\n\t\t\t\twhile(j<length) {\n\t\t\t\t\tif(str.charAt(j) == ' ') {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}else {\n\t\t\t\t\t\tj++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnum[k] = Long.parseLong(str.substring(s,j)) ;\n\t\t\t\tk++;\n\t\t\t\tj++;\n\t\t\t\ts=j;\t\t\t\n\t\t\t}\n\t\t\tArrays.sort(num);\n\t\t\tint count = 0;\n\t\t\tif(m==1) {\n\t\t\t\tcount = 1;\n\t\t\t\tfor(int i = 1 ; i < n ; i++) {\n\t\t\t\t\tif(num[i]!=num[i-1]) {\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t} \n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tTreeSet<Long> take = new TreeSet<Long>();\n\t\t\t\tTreeSet<Long> notTake = new TreeSet<Long>();\n\t\t\t\tfor(int i = 0 ; i < n ; i++) {\n\t\t\t\t\tlong temp = num[i];\n\t\t\t\t\tif(!notTake.contains(temp)){\n\t\t\t\t\t\ttake.add(temp);\n\t\t\t\t\t\ttemp *= ((long)m);\n\t\t\t\t\t\tnotTake.add(temp);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tcount = take.size();\n\t\t\t}\n\t\t\tbos.write(new Integer(count).toString().getBytes());\n\t\t\tbos.write(eolb);\n\t\t\tbos.flush();\n\t\t}  catch(IOException ioe) {\n\t\t\tioe.printStackTrace();\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Locale;\nimport java.io.OutputStream;\nimport java.util.RandomAccess;\nimport java.io.PrintWriter;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.IOException;\nimport java.math.BigDecimal;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.TreeMap;\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 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\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        int n = in.nextInt();\n        long k = in.nextInt();\n        if (k == 1) {\n            out.println(n);\n            return;\n        }\n        long[] a = in.nextLongArray(n);\n        ArrayUtils.safeSort(a);\n        Map<Long, Integer> map = new TreeMap<Long, Integer>();\n        for (int i = 0; i < n; i++) {\n            map.put(a[i], i);\n        }\n        int answer = 0;\n        boolean[] visited = new boolean[n];\n        for (int i = 0; i < n; i++) {\n            if (!visited[i]) {\n                visited[i] = true;\n                int count = 1;\n                long cur = a[i];\n                while (true) {\n                    cur *= k;\n                    Integer index = map.get(cur);\n                    if (index == null)\n                        break;\n                    visited[index] = true;\n                    count++;\n                }\n                answer += NumberUtils.upDiv(count, 2);\n            }\n        }\n        out.println(answer);\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 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 & 15;\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    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    public long[] nextLongArray(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    }\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(int i) {\n        writer.println(i);\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    }\n\nclass ArrayUtils {\n\n\n\n    public static List<Long> asList(long[] array) {\n        return new LongList(array);\n    }\n\n    private static class LongList extends AbstractList<Long> implements RandomAccess {\n        long[] array;\n\n        private LongList(long[] array) {\n            this.array = array;\n        }\n\n        public Long set(int index, Long element) {\n            long result = array[index];\n            array[index] = element;\n            return result;\n        }\n\n        public Long get(int index) {\n            return array[index];\n        }\n\n        public int size() {\n            return array.length;\n        }\n    }\n\n    public static void safeSort(long[] array) {\n        Collections.shuffle(asList(array));\n        Arrays.sort(array);\n    }\n\n    }\n\nclass NumberUtils {\n    public static int upDiv(int a, int b) {\n        return a % b == 0 ? (a / b) : (a / b + 1);\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tClass<?> here = new Object(){}.getClass().getEnclosingClass();\n\t\ttry {\n\t\t\tString packageName = here.getPackage().getName();\n\t\t\tpackageName = \"src/\" + packageName.replaceAll(\"\\\\.\", \"/\") + \"/\";\n\t\t\tSystem.setIn(new FileInputStream(packageName + \"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(packageName + \"output.txt\")));\n\t\t} catch (FileNotFoundException e) {\n\t\t} catch (NullPointerException e) {\n\t\t}\n\n\t\tObject o = Class.forName(here.getName()).newInstance();\n\t\to.getClass().getMethod(\"run\").invoke(o);\n\t}\n\n\tstatic void tr(Object... os) {\n\t\tSystem.err.println(deepToString(os));\n\t}\n\n\n\tMyScanner sc = null;\n\tPrintWriter out = null;\n\tpublic void run() throws Exception {\n\t\tsc = new MyScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tfor (;sc.hasNext();) {\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t}\n\t\tout.close();\n\t}\n\n\tvoid solve() {\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\n\t\tTreeSet<Integer> at = new TreeSet<Integer>();\n\t\tfor (int i = 0; i < n; i++) at.add(sc.nextInt());\n\t\tInteger[] ai = at.toArray(new Integer[0]);\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) a[i] = ai[i];\n\n\t\tif (k == 1) {\n\t\t\tout.println(n);\n\t\t\treturn;\n\t\t}\n\n\t\tboolean[] invalid = new boolean[n];\n\n\t\ttr(a);\n\t\tint ans = 0;\n\t\tfor (int i = 0, j = 0; i < n; i++) if (!invalid[i]) {\n\t\t\t++ans;\n\t\t\tlong kx = (long)k * a[i];\n\t\t\twhile (j < n && a[j] < kx) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (j < n && kx == a[j]) {\n\t\t\t\tinvalid[j] = true;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\n\t}\n\n\n\tvoid print(int[] a) {\n\t\tout.print(a[0]);\n\t\tfor (int i = 1; i < a.length; i++) out.print(\" \" + a[i]);\n\t\tout.println();\n\t}\n\n\tclass MyScanner {\n\t\tString line;\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic MyScanner(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic void eat() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tline = reader.readLine();\n\t\t\t\t\tif (line == null) {\n\t\t\t\t\t\ttokenizer = null;\n\t\t\t\t\t\treturn;\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\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\teat();\n\t\t\treturn tokenizer.nextToken();\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\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\teat();\n\t\t\treturn (tokenizer != null && tokenizer.hasMoreElements());\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\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class A {\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\t\tint n = readInt();\n\t\tlong k = readInt();\n\t\tLong[] a = new Long[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\ta[i] = readLong();\n\t\t}\n\t\tArrays.sort(a);\n\t\tTreeSet<Long> set = new TreeSet<Long>();\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tset.add(a[i]);\n\t\t}\n\t\tif(k == 1) {\n\t\t\tout.println(n);\n\t\t\treturn;\n\t\t}\n\t\tint res = 0;\n\t\tTreeSet<Long> used = new TreeSet<Long>();\n\t\tfor(Long cur: set){\n\t\t\tif(!used.contains(cur)){\n\t\t\t\tint num = 1;\n\t\t\t\tused.add(cur);\n\t\t\t\tLong temp = cur * 1;\n\t\t\t\t\n\t\t\t\twhile(true){\n\t\t\t\t\tif(set.contains(k*temp)){\n\t\t\t\t\t\tnum++;\n\t\t\t\t\t\tused.add(k*temp);\n\t\t\t\t\t\ttemp *= k;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tres += (num+1)/2;\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\tout.println(res);\n\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 A().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}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class solve {\n\tScanner in;\n\tPrintWriter out;\n\n\tpublic void solve() throws IOException {\n\t\tint n = in.nextInt();\n\t\tlong k = in.nextLong();\n\t\tint[] a = new int[n];\n\t\tSet<Long> b = new TreeSet<Long>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint ans = 0;\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tif (!b.contains((long) k * a[i])) {\n\t\t\t\tans++;\n\t\t\t\tb.add((long) a[i]);\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new Scanner(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\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 solve().run();\n\t}\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.DataInputStream;\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\n\n\npublic class div168C {\n\npublic static void main(String[] args) throws Exception{\n        \n    div168C a=new div168C();\n        Parserdoubt pd=a.new Parserdoubt(System.in);\n        StringBuffer sb = new StringBuffer();\n        \n        ArrayList<Integer> arr=new ArrayList<Integer>();\n        int max=0;\n        int n=pd.nextInt();\n        int k=pd.nextInt();\n        for(int i=0;i<n;i++){\n            arr.add(pd.nextInt());\n            max=Math.max(max, arr.get(i));\n        }\n        Collections.sort(arr);\n    \n        int count=0;\n        int[] mat=new int[n+1];\n        for(int i=n-1;i>=0;i--){\n            if(mat[i]!=1){\n                int x=arr.get(i);\n                if(x%k==0){\n                int ans=Collections.binarySearch(arr, x/k);\n                \n            //  System.out.println(\"index \"+ans);\n                \n                if(ans>=0&&arr.get(ans)==(x/k)){\n                    count++;\n                    mat[ans]=1;\n                }\n                else{\n                    count++;\n                }\n                }\n                else{\n                    count++;\n                }\n            }\n        }\n        /*for(int i=0;i<arr.size();i++){\n            System.out.print(arr.get(i)+\" \");\n        }\n        System.out.println();\n        */\n        if(n==1)\n            count=1;\n        System.out.println(count);\n        \n}\n    \nclass Parserdoubt\n{\n   final private int BUFFER_SIZE = 1 << 17;\n\n   private DataInputStream din;\n   private byte[] buffer;\n   private int bufferPointer, bytesRead;\n\n   public Parserdoubt(InputStream in)\n   {\n      din = new DataInputStream(in);\n      buffer = new byte[BUFFER_SIZE];\n      bufferPointer = bytesRead = 0;\n   }\n   public String nextString() throws Exception\n   {\n       StringBuffer sb=new StringBuffer(\"\");\n       byte c = read();\n       while (c <= ' ') c = read();\n       do\n       {\n           sb.append((char)c);\n           c=read();\n       }while(c>' ');\n       return sb.toString();\n   }\n   public char nextChar() throws Exception\n   {\n       byte c=read();\n       while(c<=' ') c= read();\n       return (char)c;\n   }\n   public int nextInt() throws Exception\n   {\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      {\n          ret = ret * 10 + c - '0';\n         c = read();\n      } while (c > ' ');\n      if (neg) return -ret;\n      return ret;\n   }\n   public long nextLong() throws Exception\n   {\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      {\n          ret = ret * 10 + c - '0';\n         c = read();\n      } while (c > ' ');\n      if (neg) return -ret;\n      return ret;\n   }\n   private void fillBuffer() throws Exception\n   {\n      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n      if (bytesRead == -1) buffer[0] = -1;\n   }\n\n   private byte read() throws Exception\n   {\n      if (bufferPointer == bytesRead) fillBuffer();\n      return buffer[bufferPointer++];\n   }\n}   \n\n    \n    \n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class A {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic A () {\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tLong [] A = sc.nextLongs();\n\n\t\tsort(A);\n\t\tSet<Long> S = new HashSet<Long>();\n\t\t\n\t\tfor (long a : A) {\n\t\t\tif (a % K == 0 && S.contains(H(a/K)))\n\t\t\t\tcontinue;\n\t\t\tS.add(H(a));\n\t\t}\n\t\t\n\t\tint res = S.size();\n\t\texit(res);\n\t}\n\n\tlong P = probablePrime(60, new Random()).longValue();\n\tlong Q = probablePrime(60, new Random()).longValue();\n\t\n\tlong H(long x) {\n\t\treturn (P*x) % Q;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print(Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint(Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\n// Solution is at the bottom of code\n\npublic class _AAAA implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tOutputWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new _AAAA(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tLocale.setDefault(Locale.US);\n\t\t\n\t\tif (ONLINE_JUDGE){\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new OutputWriter(System.out);\n\t\t}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new OutputWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\t////////////////////////////////////////////////////////////////\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (ONLINE_JUDGE){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t\ttime();\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tString delim = \" \";\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tok.nextToken(delim);\n\t}\n\t\n\tString readLine() throws IOException{\n\t\treturn in.readLine();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tfinal char NOT_A_SYMBOL = '\\0';\n\t\n\tchar readChar() throws IOException{\n\t\tint intValue = in.read();\n\t\t\n\t\tif (intValue == -1){\n\t\t\treturn NOT_A_SYMBOL;\n\t\t}\n\t\t\n\t\treturn (char) intValue;\n\t}\n\t\n\tchar[] readCharArray() throws IOException{\n\t\treturn readLine().toCharArray();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tint[] readIntArray(int size) throws IOException{\n\t\tint[] array = new int[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readInt();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tlong[] readLongArray(int size) throws IOException{\n\t\tlong[] array = new long[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readLong();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tdouble[] readDoubleArray(int size) throws IOException{\n\t\tdouble[] array = new double[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readDouble();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tPoint readPoint() throws IOException{\n\t\treturn new Point(readInt(), readInt());\n\t}\n\t\n\tPoint[] readPointArray(int size) throws IOException{\n\t\tPoint[] array = new Point[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readPoint();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tclass OutputWriter extends PrintWriter{\n\n\t\tfinal int DEFAULT_PRECISION = 12;\n\t\t\n\t\tint precision;\n\t\tString format, formatWithSpace;\n\t\t\n\t\t{\n\t\t\tprecision = DEFAULT_PRECISION;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tpublic OutputWriter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\n\t\tpublic OutputWriter(String fileName) throws FileNotFoundException {\n\t\t\tsuper(fileName);\n\t\t}\n\t\t\n\t\tpublic int getPrecision() {\n\t\t\treturn precision;\n\t\t}\n\n\t\tpublic void setPrecision(int precision) {\n\t\t\tthis.precision = precision;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tprivate String createFormat(int precision){\n\t\t\treturn \"%.\" + precision + \"f\";\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void print(double d){\n\t\t\tprintf(format, d);\n\t\t}\n\t\t\n\t\tpublic void printWithSpace(double d){\n\t\t\tprintf(formatWithSpace, d);\n\t\t}\n\n\t\tpublic void printAll(double...d){\n\t\t\tfor (int i = 0; i < d.length - 1; ++i){\n\t\t\t\tprintWithSpace(d[i]);\n\t\t\t}\n\t\t\t\n\t\t\tprint(d[d.length - 1]);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void println(double d){\n\t\t\tprintlnAll(d);\n\t\t}\n\t\t\n\t\tpublic void printlnAll(double... d){\n\t\t\tprintAll(d);\n\t\t\tprintln();\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tint[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; \n\t\n\tboolean check(int index, int lim){\n\t\treturn (0 <= index && index < lim);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid solve() throws IOException{\n\t\tint n = readInt();\n\t\tint k = readInt();\n\t\t\n\t\tMap<Long, Integer> map = new TreeMap<Long, Integer>();\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tmap.put(readLong(), i);\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tboolean[] used = new boolean[n];\n\t\tfor (Map.Entry<Long, Integer> e: map.entrySet()){\n\t\t\tif (used[e.getValue()]) continue;\n\t\t\tlong value = e.getKey() * k;\n\t\t\tInteger index = map.get(value);\n\t\t\t\n\t\t\tif (index != null){\n\t\t\t\tused[index] = true;\n\t\t\t}\n\t\t\t\n\t\t\t++ans;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n}\n\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.DataInputStream;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.TreeSet;\n\npublic class Main{\n\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tParserdoubt3 s = new Parserdoubt3(System.in);\n\t\tint n = s.nextInt();\n\t\tlong k = s.nextInt();\n\t\tLong a[] = new Long[n];\n\t\tTreeSet<Long> tree = new TreeSet<Long>();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = s.nextLong();\n\t\t\ttree.add(a[i]);\n\t\t}\n\t\tArrays.sort(a);\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif(tree.contains(a[i])){ \n\t\t\t\tans++;\n\t\t\t\tlong next = a[i] * k;\n\t\t\t\tif(tree.contains(next)) tree.remove(next);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n}\n\nclass Parserdoubt3 {\n\tfinal private int BUFFER_SIZE = 1 << 17;\n\n\tprivate DataInputStream din;\n\tprivate byte[] buffer;\n\tprivate int bufferPointer, bytesRead;\n\n\tpublic Parserdoubt3(InputStream in) {\n\t\tdin = new DataInputStream(in);\n\t\tbuffer = new byte[BUFFER_SIZE];\n\t\tbufferPointer = bytesRead = 0;\n\t}\n\n\tpublic String nextString() throws Exception {\n\t\tStringBuffer sb = new StringBuffer(\"\");\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\tdo {\n\t\t\tsb.append((char) c);\n\t\t\tc = read();\n\t\t} while (c > ' ');\n\t\treturn sb.toString();\n\t}\n\n\tpublic char nextChar() throws Exception {\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic int nextInt() throws Exception {\n\t\tint ret = 0;\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = c == '-';\n\t\tif (neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t\tc = read();\n\t\t} while (c > ' ');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tpublic long nextLong() throws Exception {\n\t\tlong ret = 0;\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = c == '-';\n\t\tif (neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t\tc = read();\n\t\t} while (c > ' ');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tprivate void fillBuffer() throws Exception {\n\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\tif (bytesRead == -1)\n\t\t\tbuffer[0] = -1;\n\t}\n\n\tprivate byte read() throws Exception {\n\t\tif (bufferPointer == bytesRead)\n\t\t\tfillBuffer();\n\t\treturn buffer[bufferPointer++];\n\t}\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n \t\n\tpublic void solve () throws Exception {\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\t\n\t\tTreeSet<Integer> bad = new TreeSet<>();\n\t\tint a [] = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextInt();\n\t\t\n\t\tArrays.sort(a);\n\t\t\n\t\tint result = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!bad.contains(a[i])) {\n\t\t\t\tresult++;\n\t\t\t\tlong next = (long) a[i] * k;\n\t\t\t\tif (next <= 1000000000)\n\t\t\t\t\tbad.add((int) next);\n\t\t\t}\n\t\t}\n\t\tout.println(result);\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\n\tstatic Throwable uncaught;\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.uncaught = 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 t = new Thread(null, new Solution(), \"\", (1 << 26));\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\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\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\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}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Hashtable;\nimport java.util.Scanner;\n\n\npublic class f {\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\tHashtable<Long, Boolean> d = new Hashtable<Long, Boolean>();\n\t\tint n = in.nextInt(), k = in.nextInt(), size = 0, a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) a[i] = in.nextInt();\n\t\tArrays.sort(a);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong x = a[i];\n\t\t\tif (!d.containsKey(x)) {\n\t\t\t\td.put(x * k, true);\n\t\t\t\tsize++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(size);\n\t}\n\n}\n\n  \t \t\t   \t\t\t\t\t\t\t  \t\t \t  \t \t", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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\tvoid run() {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = in.nextInt(), k = 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\tArrays.sort(a);\n\t\tint ret = 0, it = 0;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint val = a[i] % k == 0 ? a[i] / k : -1;\n\t\t\twhile (it < i && a[it] < val) ++it;\n\t\t\tif (it == i || a[it] != val) {\n\t\t\t\t++ret;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ta[i] = 0;\n\t\t\t}\n\t\t}\n\t\tout.println(ret);\n\n\t\tout.close();\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Main {\n\t\n\tScanner in;\n\tstatic PrintWriter out;\n\t\n\t\n\tstatic class Scanner {\n\t\tStreamTokenizer in;\n\t\t\n\t\tScanner(InputStream is) {\n\t\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));\n\t\t\tin.resetSyntax();\n\t\t\tin.whitespaceChars(0, 32);\n\t\t\tin.wordChars(33, 255);\n\t\t}\n\t\t\n\t\tString readLine() {\n\t\t\ttry {\n\t\t\t\tin.nextToken();\n\t\t\t\tasserT(in.ttype == StreamTokenizer.TT_WORD);\n\t\t\t\treturn in.sval;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new Error();\n\t\t\t}\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(readLine());\t\t\t\n\t\t}\n\t}\n\t\n\t\n\t\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tlong k = in.nextInt();\n\t\tint ar[] = new int[n];\n\t\tTreeMap <Integer, Integer> nums = new TreeMap<Integer, Integer>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tar[i] = in.nextInt();\n\t\t\tnums.put(ar[i], i);\n\t\t}\n\t\t\n\t\tif (k == 1) {\n\t\t\tout.println(n);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint next[] = new int[n];\n\t\tArrays.fill(next, -1);\n\t\t\n\t\tint count = 0;\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong val = ar[i] * k;\n\t\t\tint intVal = (int)val;\n\t\t\tif (intVal == val) {\n\t\t\t\tif (nums.containsKey(intVal)) {\n\t\t\t\t\tint idx = nums.get(intVal);\n\t\t\t\t\tnext[i] = idx;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (ar[i] % k == 0) {\n\t\t\t\tintVal = ar[i] / (int)k;\n\t\t\t\t\n\t\t\t\tif (nums.containsKey(intVal)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tcount++;\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint curr = nums.pollFirstEntry().getValue();\n\t\t\tboolean odd = false;\n\t\t\twhile (next[curr] != -1) {\n\t\t\t\tif (!odd) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tint to = next[curr];\n\t\t\t\tnext[curr] = -1;\n\t\t\t\tcurr = to;\n\t\t\t\todd = !odd;\n\t\t\t\t\n\t\t\t\tif (next[curr] == -1) {\n\t\t\t\t\tif (!odd) {\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(count);\n\t}\n\t\n\tstatic void asserT(boolean e) {\n\t\tif (!e) {\n\t\t\tthrow new Error();\n\t\t}\n\t}\n\t\n\t\n\tpublic void run() {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\ttry {\n\t\t\tsolve();\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n} ", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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.Set;\n\npublic class ProblemA {\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[] data = s.readLine().split(\" \");\n\t\tint n = Integer.valueOf(data[0]);\n\t\tint k = Integer.valueOf(data[1]);\n\t\t\n\t\t\n\t\tlong[] a = new long[n];\n\t\tString[] ai = s.readLine().split(\" \");\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\ta[i] = Integer.valueOf(ai[i]);\n\t\t}\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tint tm = (int)(Math.random() * n);\n\t\t\tlong tmp = a[tm];\n\t\t\ta[tm] = a[i];\n\t\t\ta[i] = tmp;\n\t\t}\n\t\tArrays.sort(a);\n\n\t\tSet<Long> invalid = new HashSet<Long>();\n\t\tint cnt = 0;\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tif (!invalid.contains(a[i])) {\n\t\t\t\tcnt++;\n\t\t\t\tinvalid.add(a[i] * k);\n\t\t\t}\n\t\t}\n\t\tout.println(cnt);\n\t\tout.flush();\n\t}\n\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader in = new InputReader();\n\t\tint n = in.nextInt();\n\t\tlong k = in.nextInt();\n\t\tLong[] a = new Long[n];\n\t\tfor(int i = 0 ; i < n;i++)a[i]=in.nextLong();\n\t\tif(k==1)System.out.println(n);\n\t\telse{\n\t\t\tint res = 0;\n\t\t\tArrays.sort(a);\n\t\t\tboolean[] v = new boolean[n];\n\t\t\tfor(int i = 0 ; i < n;i++){\n\t\t\t\tif(!v[i]){\n\t\t\t\t\tlong cur = a[i];\n\t\t\t\t\tint cnt = 1;\n\t\t\t\t\twhile(true){\n\t\t\t\t\t\tint idx = Arrays.binarySearch(a, cur*k);\n\t\t\t\t\t\tif(idx<0){\n\t\t\t\t\t\t\tres+= cnt/2 + cnt%2;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tv[idx]=true;\n\t\t\t\t\t\tcur = a[idx];\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\tSystem.out.println(res);\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tBufferedReader in;\n\t\tStringTokenizer st;\n\n\t\tpublic InputReader() throws IOException {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (!st.hasMoreElements())\n\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.HashSet;\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 NAO93\n */\npublic class a {\n    public static void main(String[] args) {\n        Scanner in = new  Scanner(System.in);\n        int n = in.nextInt();\n        long k = in.nextLong();\n        Long []a = new Long[n];\n        for (int i = 0; i<n; i++)\n            a[i] = in.nextLong();\n        HashSet<Long> hash = new HashSet<Long>();\n        Arrays.sort(a);\n        for (int i = 0; i<n; i++)\n            if (!hash.contains(a[i])){\n                hash.add(a[i] * k);\n            }\n        System.out.println(hash.size());\n    }\n\n}\n\n\t \t\t \t\t\t \t \t \t   \t\t   \t\t\t\t", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport static java.lang.Math.*;\n\npublic class P274A {\n    public static int i(String s) { return Integer.parseInt(s); }\n    public static void main(String[] args) throws Exception {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String[] arr = in.readLine().split(\" \");\n        int n = i(arr[0]);\n        long k = i(arr[1]);\n        long[] A = new long[n];\n        arr = in.readLine().split(\" \");\n        for(int i=0; i<n; i++)\n            A[i] = i(arr[i]);\n        shuffle(A);\n        Arrays.sort(A);\n\n        Set<Long> BAN = new HashSet<Long>();\n        int ans = 0;\n        for(int i=0; i<n; i++) {\n            if(!BAN.contains(A[i])) {\n                ans++;\n                BAN.add(A[i]*k);\n            }\n        }\n        System.out.println(ans);\n    }\n    public static void shuffle(long[] array) {\n        for (int i = array.length; i > 1; i--) {\n            long temp = array[i - 1];\n            int randIx = (int) (Math.random() * i);\n            array[i - 1] = array[randIx];\n            array[randIx] = temp;\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\n\n\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class A {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic A () {\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tLong [] A = sc.nextLongs();\n\n\t\tsort(A);\n\t\tTreeSet<Long> S = new TreeSet<Long>();\n\t\t\n\t\tfor (long a : A) {\n\t\t\tif (a % K == 0 && S.contains(a/K))\n\t\t\t\tcontinue;\n\t\t\tS.add(a);\n\t\t}\n\t\t\n\t\tint res = S.size();\n\t\texit(res);\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print(Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint(Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "/* 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\tvoid solve() throws IOException  {\n\t\t\n\t\tint n = nextInt();\n\t\tlong k = nextLong();\n\t\tint[] a = nextIntArray(n);\n\n\t\tSet<Long> bad = new TreeSet<Long>();\n\t\t\n\t\tsort(a);\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\tfor (int x : a) {\n\t\t\tif (!bad.contains((long) x)) {\n\t\t\t\tbad.add(x * k);\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t\t\n\t}\n\t\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "//package round168;\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 A {\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\tint[] a = na(n);\n\t\tif(K == 1){\n\t\t\tout.println(n);\n\t\t\treturn;\n\t\t}\n\t\ta = radixSort(a);\n\t\tboolean[] dead = new boolean[n];\n\t\tint ct = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(!dead[i]){\n\t\t\t\tct++;\n\t\t\t\tif((long)a[i]*K<=1000000000){\n\t\t\t\t\tint ind = Arrays.binarySearch(a, a[i]*K);\n\t\t\t\t\tif(ind >= 0){\n\t\t\t\t\t\tdead[ind] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ct);\n\t}\n\t\n\tpublic static int[] radixSort(int[] f)\n\t{\n\t\tint[] to = new int[f.length];\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n\t\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n\t\t\tint[] d = f; f = to;to = d;\n\t\t}\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor(int i = 0;i < f.length;i++)b[1+(f[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 < f.length;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\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 A().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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class Main\n{\n    static Input in;\n    static Output out;\n\n    public static void main(String[] args) throws IOException\n    {\n        in = new Input(System.in);\n        out = new Output(System.out);\n        run();\n        out.close();\n        System.exit(0);\n    }\n\n    private static void run() throws IOException\n    {\n        int n = in.nextInt(), k = in.nextInt();\n        int[] A = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            A[i] = in.nextInt();\n        }\n        Arrays.sort(A);\n        int count = n;\n        boolean[] hash = new boolean[n];\n        for (int i = n-1; i > 0; i--)\n        {\n            if(!hash[i])\n            {\n                int a = A[i];\n                if(a % k == 0)\n                {\n                    int p = a / k;\n                    int j = Arrays.binarySearch(A, p);\n                    if(j >= 0 && j < i)\n                    {\n                        hash[j] = true;\n                        count--;\n                    }\n                }\n            }\n        }\n        out.print(count);\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    private int read() throws IOException\n    {\n        if (total == -1) return -1;\n        if (current >= total)\n        {\n            current = 0;\n            total = in.read(buf);\n            if (total <= 0) return -1;\n        }\n        return buf[current++];\n    }\n\n    private void advance() throws IOException\n    {\n        while (true)\n        {\n            if (last == -1) return;\n            if (!isValidChar(last)) last = read();\n            else break;\n        }\n    }\n\n    private boolean isValidChar(int c)\n    {\n        return c > 32 && c < 127;\n    }\n\n    public boolean isEOF() throws IOException\n    {\n        advance();\n        return last == -1;\n    }\n\n    public String nextString() throws IOException\n    {\n        advance();\n        if (last == -1) throw new EOFException();\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    public String nextLine() throws IOException\n    {\n        if (last == -1) throw new EOFException();\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) throws IOException\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() throws IOException\n    {\n        advance();\n        if (last == -1) throw new EOFException();\n        int n = 0, s = 1;\n        if (last == '-')\n        {\n            s = -1;\n            last = read();\n            if (last == -1) throw new EOFException();\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() throws IOException\n    {\n        advance();\n        if (last == -1) throw new EOFException();\n        int s = 1;\n        if (last == '-')\n        {\n            s = -1;\n            last = read();\n            if (last == -1) throw new EOFException();\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() throws IOException\n    {\n        return new BigInteger(nextString());\n    }\n\n    public char nextChar() throws IOException\n    {\n        advance();\n        return (char) last;\n    }\n\n    public double nextDouble() throws IOException\n    {\n        advance();\n        if (last == -1) throw new EOFException();\n        int s = 1;\n        if (last == '-')\n        {\n            s = -1;\n            last = read();\n            if (last == -1) throw new EOFException();\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            if (last == -1) throw new EOFException();\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() throws IOException\n    {\n        return new BigDecimal(nextString());\n    }\n\n    public void close() throws IOException\n    {\n        in.close();\n        in = null;\n    }\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    void flushBuffer() throws IOException\n    {\n        if (nextChar == 0) return;\n        out.write(cb, 0, nextChar);\n        nextChar = 0;\n    }\n\n    void write(int c) throws IOException\n    {\n        if (nextChar >= nChars) flushBuffer();\n        cb[nextChar++] = (char) c;\n    }\n\n    void write(String s, int off, int len) throws IOException\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) throws IOException\n    {\n        write(s, 0, s.length());\n    }\n\n    public void print(Object obj) throws IOException\n    {\n        write(String.valueOf(obj));\n    }\n\n    public void println(Object obj) throws IOException\n    {\n        write(String.valueOf(obj));\n        write(lineSeparator);\n    }\n\n    public void printf(String format, Object... obj) throws IOException\n    {\n        write(String.format(format, obj));\n    }\n\n    public void close() throws IOException\n    {\n        flushBuffer();\n        out.close();\n        out = null;\n    }\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A implements Runnable {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\tstatic Random rnd;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tlong k = nextLong();\n\n\t\tif (k == 1) {\n\t\t\tout.println(n);\n\t\t} else {\n\n\t\t\tTreeMap<Long, ArrayList<Integer>> numbers = new TreeMap<Long, ArrayList<Integer>>();\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong m = nextLong();\n\t\t\t\tint howMuch = 0;\n\n\t\t\t\twhile (m % k == 0) {\n\t\t\t\t\tm /= k;\n\t\t\t\t\t++howMuch;\n\t\t\t\t}\n\n\t\t\t\tif (!numbers.containsKey(m)) {\n\t\t\t\t\tnumbers.put(m, new ArrayList<Integer>());\n\t\t\t\t}\n\n\t\t\t\tnumbers.get(m).add(howMuch);\n\t\t\t}\n\n\t\t\tint res = 0;\n\n\t\t\tfor (ArrayList<Integer> oneGroup : numbers.values()) {\n\t\t\t\tres += parseOneGroup(oneGroup);\n\t\t\t}\n\n\t\t\tout.println(res);\n\t\t}\n\t}\n\n\tprivate int parseOneGroup(ArrayList<Integer> oneGroup) {\n\t\tCollections.sort(oneGroup);\n\n\t\tint res = 0, prevValue = Integer.MIN_VALUE;\n\n\t\tfor (int i = 0; i < oneGroup.size(); i++) {\n\t\t\tint curValue = oneGroup.get(i);\n\n\t\t\tif (prevValue + 1 != curValue) {\n\t\t\t\t++res;\n\t\t\t\tprevValue = curValue;\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\n\t\t\trnd = new Random();\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(42);\n\t\t}\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\n\t\t\tif (line == null)\n\t\t\t\treturn null;\n\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class Main {\n\n    //http://www.codeforces.com/contest/275/problem/C\n\n    public static void main(String[] args) throws NumberFormatException, IOException {\n\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine(), \" \");\n\n        int num = Integer.parseInt(st.nextToken());\n        int k = Integer.parseInt(st.nextToken());\n\n        st = new StringTokenizer(br.readLine(), \" \");\n\n        if (k == 1) System.out.println(num); \n        else {\n            Set<Integer> set = new TreeSet<Integer>();\n            Set<Integer> bad = new TreeSet<Integer>();\n            int sel;\n            \n            int[] arr = new int[num];\n            for (int i = 0; i < num; i++) {\n                arr[i] = Integer.parseInt((st.nextToken()));\n            }\n\n            shuffle(arr);\n            Arrays.sort(arr);\n\n            for (int i = 0; i < num; i++) {\n                sel = arr[i];\n                if (sel % k != 0) {\n                    set.add(sel);\n                    bad.add(sel * k);\n                }\n                if (!bad.contains(sel) && !set.contains(sel / k)) {\n                    bad.add(sel * k);\n                    set.add(sel);\n                }\n            }\n\n            System.out.println(set.size()); \n        }\n    }\n\n    public static void shuffle(int[] arr) {\n        Random rand = new Random();\n        for (int i = arr.length - 1; i >= 0; --i) {\n            int pos = rand.nextInt(i + 1);\n            int aux = arr[i];\n            arr[i] = arr[pos];\n            arr[pos] = aux;\n        }\n    }\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class CF274A {\n\n    public static void main(String[] args) throws Exception {\n        new CF274A().solve();\n    }\n\n    private void solve() throws Exception {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        long k = sc.nextInt();\n        Integer[] a = new Integer[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = sc.nextInt();\n        }\n        Arrays.sort(a);\n        HashSet<Integer> used = new HashSet<>(n);\n        int count = 0;\n        for (int i = 0; i < n; i++) {\n            Integer v = a[i];\n            if (!used.contains(v)) {\n                count++;\n                long next = v * k;\n                if (next <= 1000000000) used.add((int) next);\n            }\n        }\n        System.out.println(count);\n    }\n\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        long k = in.nextLong();\n        long[] a = new long[n];\n        for (int i = 0; i < n; ++i) a[i] = in.nextLong();\n        Arrays.sort(a);\n        boolean[] take = new boolean[n];\n        Arrays.fill(take, true);\n        int j = 0;\n        int res = n;\n        for (int i = 0; i < n; ++i) {\n            while (j < i && a[j] * k < a[i]) ++j;\n            if (j < i && take[j] && a[j] * k == a[i]) {\n                take[i] = false;\n                --res;\n            }\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    public long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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 Point implements Comparable<Point> {\n\t\tint x, 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\tpublic int compareTo(Point o) {\n\t\t\treturn x-o.x; \n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y; \n\t\t}\n\t}\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\t\t\tint n = nextInt(); \n\t\t\tlong k = nextLong(); \n\n\t\t\tlong[] a = new long[n]; \n\t\t\tTreeMap<Long, Integer> st  = new TreeMap<Long, Integer>(); \n\n\t\t\tfor (int i=0; i<n; i++) {\n\t\t\t\ta[i] = nextLong(); \n\t\t\t\tst.put(a[i], 1);\n\t\t\t}\n\n\t\t\tArrays.sort(a); \n\n\t\t\tfor (int i=0; i<n; i++) {\n\t\t\t\tif (a[i] % k == 0) {\n\t\t\t\t\tlong x = a[i] / k; \n\t\t\t\t\tif (st.containsKey(x)) {\n\t\t\t\t\t\tint y = st.get(x); \n\t\t\t\t\t\tst.remove(a[i]); \n\t\t\t\t\t\tst.put(a[i], y + 1); \n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\n\t\t\tint ans = 0; \n\t\t\tfor (int i=0; i<n; i++) {\n\t\t\t\t//System.err.println(a[n-i-1] + \" \" + st.get(a[n-i-1])); \n\t\t\t\tans+=(st.get(a[n-i-1]) + 1) / 2; \n\t\t\t\tif (a[n-i-1] % k == 0) {\n\t\t\t\t\tlong x = a[n-i-1] / k; \n\t\t\t\t\tif (st.containsKey(x)) {\n\t\t\t\t\t\t//System.err.println(x); \n\t\t\t\t\t\tst.remove(x); \n\t\t\t\t\t\tst.put(x, 0); \n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tout.println(ans); \n\n\t\tLong end = System.currentTimeMillis();\n\t\tout.close(); \n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Template().run(); \n\t}\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class A {\n    static int[] parent;\n\n    public static int find(int x) {\n        if (x == parent[x])\n            return x;\n        return parent[x] = find(parent[x]);\n    }\n\n    public static void union(int x, int y) {\n        int px = find(x);\n        int py = find(y);\n        if (px != py) {\n            parent[py] = px;\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        int numCnt = (int) nextLong();\n        long k = nextLong();\n        parent = new int[numCnt];\n        for (int i = 0; i < parent.length; i++) {\n            parent[i] = i;\n        }\n        Long[] ar=new Long[numCnt];\n        for (int i = 0; i < numCnt; i++) {\n            ar[i] = nextLong();\n        }\n        Arrays.sort(ar);\n        for (int i = 0; i < ar.length; i++) {\n            long req = ar[i] * k;\n            int l=0,h=ar.length,mid;\n            while(l<h){\n                mid=l+(h-l)/2;\n                if(ar[mid]<req){\n                    l=mid+1;\n                }else{\n                    h=mid;\n                }\n            }\n            if(l<ar.length&&ar[l]==req){\n                union(i,l);\n            }\n        }\n        int[] count = new int[numCnt];\n        for (int i = 0; i < parent.length; i++) {\n            count[find(i)]++;\n        }\n        int res = 0;\n        for (int i = 0; i < numCnt; i++) {\n            res += (int) ((count[i] + 1) / 2.0);\n        }\n        System.out.println(res);\n    }\n\n    static BufferedReader br = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer tokenizer = new StringTokenizer(\"\");\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    static String next() throws Exception {\n        while (true) {\n            if (tokenizer.hasMoreTokens()) {\n                return tokenizer.nextToken();\n            }\n            String s = br.readLine();\n            if (s == null) {\n                return null;\n            }\n            tokenizer = new StringTokenizer(s);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.InputMismatchException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author emotionalBlind\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        int N = in.readInt();\n        long K = in.readLong();\n        long[] a = new long[N];\n        for (int i = 0; i < N; ++i) {\n            a[i] = in.readLong();\n        }\n        ArrayShuffler s = new ArrayShuffler();\n        s.shuffle(a);\n        Arrays.sort(a);\n        boolean[] taken = new boolean[N];\n        Arrays.fill(taken, true);\n        int i = 0;\n        int j = i + 1;\n        int res = N;\n        while (i < a.length) {\n            if (taken[i] == false) {\n                i++;\n                if (j <= i) j = i + 1;\n                continue;\n            }\n            while (j < a.length && a[j] < a[i] * K) {\n                j++;\n            }\n            if (j < a.length) {\n                if (a[j] == a[i] * K) {\n                    taken[j] = false;\n                    res--;\n                }\n            }\n            i++;\n            if (j <= i) j = i + 1;\n        }\n        out.printLine(res);\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        // InputMismatchException -> UnknownError\n        if (numChars == -1)\n            throw new UnknownError();\n        if (curChar >= numChars) {\n            curChar = 0;\n            try {\n                numChars = stream.read(buf);\n            } catch (IOException e) {\n                throw new UnknownError();\n            }\n            if (numChars <= 0)\n                return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public int readInt() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        } else if (c == '+') {\n            c = read();\n        }\n        int res = 0;\n        do {\n            if (c < '0' || c > '9')\n                throw new InputMismatchException();\n            res *= 10;\n            res += c - '0';\n            c = read();\n        } while (!isSpaceChar(c));\n        return res * sgn;\n    }\n\n    public 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 static boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\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\nclass ArrayShuffler {\n    static Random random = new Random(7428429L);\n\n    public void shuffle(long[] p) {\n        for (int i = 0; i < p.length; ++i) {\n            int j = i + random.nextInt(p.length - i);\n            long temp = p[i];\n            p[i] = p[j];\n            p[j] = temp;\n        }\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.FileInputStream;\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.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.List;\nimport java.util.Random;\nimport java.util.TreeSet;\n\n/**\n * Actual solution is at the top, in class Solver\n */\nfinal public class Main implements Runnable {\n\tprivate static String[] args;\n\n\tpublic static void main(String[] args) {\n\t\tMain.args = args;\n\t\tnew Thread(null, new Main(), \"MyRunThread\", 1 << 27).start();\n\t}\n\n\t//@Override\n\tpublic void run() {\n\t\tlong time_beg = -1;\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tif (args.length > 0 && args[0].equals(\"outside\")) {\n\t\t\ttime_beg = System.currentTimeMillis();\n\t\t\ttry {\n\t\t\t\tinputStream = new FileInputStream(\"IO/in.txt\");\n//\t\t\t\toutputStream = new FileOutputStream(\"IO/out.txt\");\n\t\t\t} catch (Exception e) {\n\t\t\t\tSystem.err.println(e);\n\t\t\t\tSystem.exit(1);\n\t\t\t}\n\t\t} else {\n\t\t\ttry {\n//\t\t\t\tinputStream = new FileInputStream(\"IO/in.txt\");\n//\t\t\t\toutputStream = new FileOutputStream(\"IO/out.txt\");\n\t\t\t} catch (Exception e) {\n\t\t\t\tSystem.err.println(e);\n\t\t\t\tSystem.exit(1);\n\t\t\t}\n\t\t}\n\n\t\tSolver s = new Solver();\n\t\ts.in = new InputReader(inputStream);\n\t\ts.out = new OutputWriter(outputStream);\n\t\tif (args.length > 0 && args[0].equals(\"outside\")) {\n\t\t\ts.dout = new DebugWriter(s.out);\n\t\t}\n\n\t\ts.solve();\n\n\t\tif (args.length > 0 && args[0].equals(\"outside\")) {\n\t\t\ts.dout.printFormat(\"*** Total time: %.3f ***\\n\", (System.currentTimeMillis() - time_beg) / 1000.0);\n\t\t}\n\n\t\ts.out.close();\n\t}\n}\n\n\nfinal class Solver {\n\tInputReader in;\n\tOutputWriter out;\n\tDebugWriter dout;\n\n\tpublic void solve() {\n\t\tint n = in.readInt();\n\t\tint k = in.readInt();\n\n\n\t\tTreeSet<Integer> q = new TreeSet<Integer>();\n\t\tint[] mas = new int[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tmas[i] = in.readInt();\n\t\t\tif (mas[i] % k != 0)\n\t\t\t\tq.add(mas[i]);\n\t\t}\n\n//\t\tSequenceUtils.quickSort(mas);\n\t\tArrays.sort(mas);\n\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tif (mas[i] % k == 0 && !q.contains(mas[i] / k))\n\t\t\t\tq.add(mas[i]);\n\n\t\tout.printLine(q.size());\n\t}\n}\n\n\nfinal class InputReader {\n\tprivate boolean finished = false;\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1 << 10];\n\tprivate int curChar;\n\tprivate int numChars;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tprivate int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int peek() {\n\t\tif (numChars == -1)\n\t\t\treturn -1;\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\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\tprivate String readLine0() {\n\t\tStringBuilder buf = new StringBuilder();\n\t\tint c = read();\n\t\twhile (c != '\\n' && c != -1) {\n\t\t\tif (c != '\\r')\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}\n\t\treturn buf.toString();\n\t}\n\n\tpublic String readLine() {\n\t\tString s = readLine0();\n\t\twhile (s.trim().length() == 0)\n\t\t\ts = readLine0();\n\t\treturn s;\n\t}\n\n\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\tif (ignoreEmptyLines)\n\t\t\treturn readLine();\n\t\telse\n\t\t\treturn readLine0();\n\t}\n\n\tpublic BigInteger readBigInteger() {\n\t\ttry {\n\t\t\treturn new BigInteger(readString());\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isExhausted() {\n\t\tint value;\n\t\twhile (isSpaceChar(value = peek()) && value != -1)\n\t\t\tread();\n\t\treturn value == -1;\n\t}\n}\n\nfinal class OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 1 << 10));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\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 printFormat(String format, Object... objects) {\n\t\twriter.printf(format, objects);\n\t}\n\n\n\tpublic void print(char[] objects) {\n\t\twriter.print(objects);\n\t}\n\n\tpublic void printLine(char[] objects) {\n\t\twriter.println(objects);\n\t}\n\n\tpublic void printLine(char[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(int[] 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(int[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(int[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(short[] 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(short[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(short[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(long[] 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(long[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(long[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(double[] 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(double[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(double[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(byte[] 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(byte[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(byte[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(boolean[] 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(boolean[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(boolean[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void flush() {\n\t\twriter.flush();\n\t}\n}\n\nfinal class DebugWriter {\n\tprivate final OutputWriter writer;\n\n\tpublic DebugWriter(OutputWriter writer) {\n\t\tthis.writer = writer;\n\t}\n\n\tprivate void printDebugMessage() {\n\t\twriter.print(\"DEBUG:\\t\");\n\t}\n\n\n\tpublic void printLine(Object... objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printFormat(String format, Object... objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printFormat(format, objects);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(char[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(char[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(double[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(double[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(int[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(int[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(short[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(short[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(long[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(long[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(byte[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(byte[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(boolean[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(boolean[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void flush() {\n\t\twriter.flush();\n\t}\n}\n\n\ninterface Graph {\n\t// add vertexes\n\tpublic void addVertexes(int amount);\n\n\t// add edge\n\tpublic void addEdge(int source, int destination, boolean directed);\n\n\tpublic void addEdge(int source, int destination, boolean directed, long weight);\n\n\tpublic void addEdge(int source, int destination, long capacity);\n\n\tpublic void addEdge(int source, int destination, long weight, long capacity);\n\n\t// iterate through incident edges\n\tpublic int getFirstEdge(int source);\n\n\tpublic boolean hasNextEdge(int id);\n\n\tpublic int getNextEdge(int id);\n\n\t// graph info\n\tpublic int getVertexCount();\n\n\tpublic int getEdgeCount();\n\n\tpublic void show(DebugWriter writer);\n\n\t// simple edge info\n\tpublic int getSource(int id);\n\n\tpublic int getDestination(int id);\n\n\tpublic int getColor(int id);\n\n\tpublic void setColor(int id, int color);\n\n\tpublic boolean hasReverseEdge(int id);\n\n\tpublic int getReverseEdge(int id);\n\n\tpublic String edgeToString(int id);\n\n\t// weighted edge info\n\tpublic long getWeight(int id);\n\n\tpublic void setWeight(int id, long weight);\n\n\t// flow edge info\n\tpublic long getCapacity(int id);\n\n\tpublic void addCapacity(int id, long capacity);\n\n\tpublic long getFlow(int id);\n\n\tpublic void pushFlow(int id, long flow);\n}\n\nclass GraphSimple implements Graph {\n\tprotected int[] firstEdge;\n\tprotected int[] nextEdge;\n\tprotected int vertexCount = 0;\n\tprotected int edgeCount = 0;\n\n\tprotected int[] reverseEdge;\n\tprotected int[] source;\n\tprotected int[] destination;\n\tprotected int[] color;\n\n\tpublic GraphSimple() {\n\t\tthis(16, 16);\n\t}\n\n\tpublic GraphSimple(int vertexCapacity, int edgeCapacity) {\n\t\tfirstEdge = new int[vertexCapacity];\n\t\tnextEdge = new int[edgeCapacity];\n\n\t\treverseEdge = new int[edgeCapacity];\n\t\tsource = new int[edgeCapacity];\n\t\tdestination = new int[edgeCapacity];\n\t\tcolor = new int[edgeCapacity];\n\t}\n\n\tprotected void ensureVertexCapacity(int size) {\n\t}\n\n\tprotected void ensureEdgeCapacity(int size) {\n\t}\n\n\t// add vertexes\n\t@Override\n\tpublic void addVertexes(int amount) {\n\t\tensureVertexCapacity(vertexCount + amount);\n\t\tfor (int i = 0; i < amount; ++i)\n\t\t\tfirstEdge[i + vertexCount] = -1;\n\t\tvertexCount += amount;\n\t}\n\n\t// add edge\n\t@Override\n\tpublic void addEdge(int source, int destination, boolean directed) {\n\t\tif (source >= vertexCount || destination >= vertexCount)\n\t\t\tthrow new ArrayIndexOutOfBoundsException(\"wrong vertex's number\");\n\n\t\tensureEdgeCapacity(edgeCount + 2);\n\t\tnextEdge[edgeCount] = firstEdge[source];\n\t\tfirstEdge[source] = edgeCount;\n\n\t\tthis.source[edgeCount] = source;\n\t\tthis.destination[edgeCount] = destination;\n\t\tthis.color[edgeCount] = -1;\n\n\t\tif (directed) reverseEdge[edgeCount++] = -1;\n\t\telse {\n\t\t\treverseEdge[edgeCount] = edgeCount + 1;\n\t\t\t++edgeCount;\n\n\t\t\tnextEdge[edgeCount] = firstEdge[destination];\n\t\t\tfirstEdge[destination] = edgeCount;\n\n\t\t\tthis.source[edgeCount] = destination;\n\t\t\tthis.destination[edgeCount] = source;\n\t\t\tthis.color[edgeCount] = -1;\n\n\t\t\treverseEdge[edgeCount] = edgeCount - 1;\n\t\t\t++edgeCount;\n\t\t}\n\t}\n\n\t@Override\n\tpublic void addEdge(int source, int destination, boolean directed, long weight) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic void addEdge(int source, int destination, long capacity) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic void addEdge(int source, int destination, long weight, long capacity) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t// iterate through incident edges\n\t@Override\n\tpublic int getFirstEdge(int source) {\n\t\tif (source >= vertexCount)\n\t\t\tthrow new ArrayIndexOutOfBoundsException(\"wrong vertex's number\");\n\t\treturn firstEdge[source];\n\t}\n\n\t@Override\n\tpublic boolean hasNextEdge(int id) {\n\t\treturn id != -1;\n\t}\n\n\t@Override\n\tpublic int getNextEdge(int id) {\n\t\treturn nextEdge[id];\n\t}\n\n\t// graph info\n\t@Override\n\tpublic int getVertexCount() {\n\t\treturn vertexCount;\n\t}\n\n\t@Override\n\tpublic int getEdgeCount() {\n\t\treturn edgeCount;\n\t}\n\n\t@Override\n\tpublic void show(DebugWriter writer) {\n\t\twriter.printLine(\"Graph:\");\n\t\tfor (int i = 0; i < getVertexCount(); ++i) {\n\t\t\twriter.printLine(\"\\tincident to vertex [\" + i + \"]: \");\n\t\t\tfor (int id = getFirstEdge(i); hasNextEdge(id); id = getNextEdge(id))\n\t\t\t\twriter.printLine(\"\\t\\t\" + edgeToString(id));\n\t\t}\n\t}\n\n\t// simple edge info\n\t@Override\n\tpublic int getSource(int id) {\n\t\treturn source[id];\n\t}\n\n\t@Override\n\tpublic int getDestination(int id) {\n\t\treturn destination[id];\n\t}\n\n\t@Override\n\tpublic int getColor(int id) {\n\t\treturn color[id];\n\t}\n\n\t@Override\n\tpublic void setColor(int id, int color) {\n\t\tthis.color[id] = color;\n\t}\n\n\t@Override\n\tpublic boolean hasReverseEdge(int id) {\n\t\treturn reverseEdge[id] != -1;\n\t}\n\n\t@Override\n\tpublic int getReverseEdge(int id) {\n\t\tif (reverseEdge[id] == -1)\n\t\t\tthrow new NoSuchFieldError();\n\t\treturn reverseEdge[id];\n\t}\n\n\t@Override\n\tpublic String edgeToString(int id) {\n\t\treturn \"<(\" + getSource(id) + \" -> \" + getDestination(id) + \") color : \" + getColor(id) + \">\";\n\t}\n\n\t// weighted edge info\n\t@Override\n\tpublic long getWeight(int id) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic void setWeight(int id, long weight) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t// flow edge info\n\t@Override\n\tpublic long getCapacity(int id) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic void addCapacity(int id, long capacity) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic long getFlow(int id) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic void pushFlow(int id, long flow) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n}\n\n\nabstract class SequenceUtils {\n\t// swap\n\tpublic final static <T> void swap(List<T> sequence, int j, int i) {\n\t\tT tmp = sequence.get(j);\n\t\tsequence.set(j, sequence.get(i));\n\t\tsequence.set(i, tmp);\n\t}\n\n\tpublic final static <T> void swap(T[] sequence, int j, int i) {\n\t\tT tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(int[] sequence, int j, int i) {\n\t\tint tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(long[] sequence, int j, int i) {\n\t\tlong tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(char[] sequence, int j, int i) {\n\t\tchar tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(double[] sequence, int j, int i) {\n\t\tdouble tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(boolean[] sequence, int j, int i) {\n\t\tboolean tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(short[] sequence, int j, int i) {\n\t\tshort tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\tpublic final static void swap(byte[] sequence, int j, int i) {\n\t\tbyte tmp = sequence[j];\n\t\tsequence[j] = sequence[i];\n\t\tsequence[i] = tmp;\n\t}\n\n\t// reverse\n\tpublic final static <T> void reverse(List<T> sequence) {\n\t\tfor (int left = 0, right = sequence.size() - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static <T> void reverse(T[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(int[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(long[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(char[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(double[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(boolean[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(short[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\tpublic final static void reverse(byte[] sequence) {\n\t\tfor (int left = 0, right = sequence.length - 1; left < right; ++left, --right)\n\t\t\tswap(sequence, left, right);\n\t}\n\n\t// next permutation\n\tpublic final static <T extends Comparable<T>> boolean nextPermutation(List<T> sequence) {\n\t\tfor (int j = sequence.size() - 2; j >= 0; --j) {\n\t\t\tif (sequence.get(j).compareTo(sequence.get(j + 1)) < 0) {\n\t\t\t\treverse(sequence.subList(j + 1, sequence.size()));\n\t\t\t\tfor (int i = j + 1; i < sequence.size(); ++i)\n\t\t\t\t\tif (sequence.get(j).compareTo(sequence.get(i)) < 0) {\n\t\t\t\t\t\tswap(sequence, j, i);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic final static <T> boolean nextPermutation(List<T> sequence, Comparator<T> comparator) {\n\t\tfor (int j = sequence.size() - 2; j >= 0; --j) {\n\t\t\tif (comparator.compare(sequence.get(j), sequence.get(j + 1)) < 0) {\n\t\t\t\treverse(sequence.subList(j + 1, sequence.size()));\n\t\t\t\tfor (int i = j + 1; i < sequence.size(); ++i)\n\t\t\t\t\tif (comparator.compare(sequence.get(j), sequence.get(i)) < 0) {\n\t\t\t\t\t\tswap(sequence, j, i);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// random shuffle\n\tpublic final static <T> void shuffle(List<T> sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.size(); ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static <T> void shuffle(T[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(int[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(long[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(char[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(double[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(boolean[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(short[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\tpublic final static void shuffle(byte[] sequence) {\n\t\tRandom random = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tswap(sequence, random.nextInt(i + 1), i);\n\t}\n\n\t// merge sort\n\tpublic final static <T extends Comparable<T>> void mergeSort(List<T> sequence) {\n\t\tint n = sequence.size();\n\t\tT[] tmp = (T[]) new Object[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence.get(i);\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static <T extends Comparable<T>> void merge(List<T> sequence, T[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence.set(i, tmp[pRight++]);\n\t\t\telse if (pRight > right) sequence.set(i, tmp[pLeft++]);\n\t\t\telse if (tmp[pLeft].compareTo(tmp[pRight]) <= 0) sequence.set(i, tmp[pLeft++]);\n\t\t\telse sequence.set(i, tmp[pRight++]);\n\t}\n\n\n\tpublic final static <T> void mergeSort(List<T> sequence, Comparator<T> comparator) {\n\t\tint n = sequence.size();\n\t\tT[] tmp = (T[]) new Object[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence.get(i);\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1), comparator);\n\t\t}\n\t}\n\n\tprivate final static <T> void merge(List<T> sequence, T[] tmp, int left, int mid, int right, Comparator<T> comparator) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence.set(i, tmp[pRight++]);\n\t\t\telse if (pRight > right) sequence.set(i, tmp[pLeft++]);\n\t\t\telse if (comparator.compare(tmp[pLeft], tmp[pRight]) <= 0) sequence.set(i, tmp[pLeft++]);\n\t\t\telse sequence.set(i, tmp[pRight++]);\n\t}\n\n\n\tpublic final static void mergeSort(int[] sequence) {\n\t\tint n = sequence.length;\n\t\tint[] tmp = new int[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(int[] sequence, int[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (tmp[pLeft] <= tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\n\tpublic final static void mergeSort(long[] sequence) {\n\t\tint n = sequence.length;\n\t\tlong[] tmp = new long[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(long[] sequence, long[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (tmp[pLeft] <= tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\n\tpublic final static void mergeSort(char[] sequence) {\n\t\tint n = sequence.length;\n\t\tchar[] tmp = new char[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(char[] sequence, char[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (tmp[pLeft] <= tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\n\tpublic final static void mergeSort(double[] sequence) {\n\t\tint n = sequence.length;\n\t\tdouble[] tmp = new double[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(double[] sequence, double[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (tmp[pLeft] <= tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\n\tpublic final static void mergeSort(boolean[] sequence) {\n\t\tint n = sequence.length;\n\t\tboolean[] tmp = new boolean[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(boolean[] sequence, boolean[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (!tmp[pLeft] || tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\n\tpublic final static void mergeSort(short[] sequence) {\n\t\tint n = sequence.length;\n\t\tshort[] tmp = new short[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(short[] sequence, short[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (tmp[pLeft] <= tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\n\tpublic final static void mergeSort(byte[] sequence) {\n\t\tint n = sequence.length;\n\t\tbyte[] tmp = new byte[n];\n\t\tfor (int step = 1; step < n; step *= 2) {\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\ttmp[i] = sequence[i];\n\t\t\tfor (int i = 0; i + step < n; i += 2 * step)\n\t\t\t\tmerge(sequence, tmp, i, i + step - 1, Math.min(i + step * 2 - 1, n - 1));\n\t\t}\n\t}\n\n\tprivate final static void merge(byte[] sequence, byte[] tmp, int left, int mid, int right) {\n\t\tint pLeft = left;\n\t\tint pRight = mid + 1;\n\t\tfor (int i = left; i <= right; ++i)\n\t\t\tif (pLeft > mid) sequence[i] = tmp[pRight++];\n\t\t\telse if (pRight > right) sequence[i] = tmp[pLeft++];\n\t\t\telse if (tmp[pLeft] <= tmp[pRight]) sequence[i] = tmp[pLeft++];\n\t\t\telse sequence[i] = tmp[pRight++];\n\t}\n\n\t// quick sort\n\tpublic final static <T> void quickSort(List<T> sequence, Comparator<T> comparator) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.size() - 1, comparator);\n\t}\n\n\tprivate final static <T> void quickSortImplementation(List<T> sequence, int left, int right, Comparator<T> comparator) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tT value = sequence.get(left);\n\n\t\twhile (i <= greaterThen) {\n\t\t\tint cmp = comparator.compare(sequence.get(i), value);\n\t\t\tif (cmp < 0) swap(sequence, i++, lessThen++);\n\t\t\telse if (cmp > 0) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1, comparator);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right, comparator);\n\t}\n\n\n\tpublic final static <T extends Comparable<T>> void quickSort(List<T> sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.size() - 1);\n\t}\n\n\tprivate final static <T extends Comparable<T>> void quickSortImplementation(List<T> sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tT value = sequence.get(left);\n\n\t\twhile (i <= greaterThen) {\n\t\t\tint cmp = sequence.get(i).compareTo(value);\n\t\t\tif (cmp < 0) swap(sequence, i++, lessThen++);\n\t\t\telse if (cmp > 0) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(int[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(int[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tint value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (sequence[i] < value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] > value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(long[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(long[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tlong value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (sequence[i] < value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] > value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(char[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(char[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tchar value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (sequence[i] < value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] > value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(double[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(double[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tdouble value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (sequence[i] < value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] > value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(boolean[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(boolean[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tboolean value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (!sequence[i] && value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] && !value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(short[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(short[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tshort value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (sequence[i] < value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] > value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\n\tpublic final static void quickSort(byte[] sequence) {\n\t\tshuffle(sequence);\n\t\tquickSortImplementation(sequence, 0, sequence.length - 1);\n\t}\n\n\tprivate final static void quickSortImplementation(byte[] sequence, int left, int right) {\n\t\tif (left >= right) return;\n\n\t\tint lessThen = left;\n\t\tint greaterThen = right;\n\t\tint i = left;\n\t\tbyte value = sequence[left];\n\n\t\twhile (i <= greaterThen) {\n\t\t\tif (sequence[i] < value) swap(sequence, i++, lessThen++);\n\t\t\telse if (sequence[i] > value) swap(sequence, i, greaterThen--);\n\t\t\telse ++i;\n\t\t}\n\n\t\tquickSortImplementation(sequence, left, lessThen - 1);\n\t\tquickSortImplementation(sequence, greaterThen + 1, right);\n\t}\n\n\t// unique\n\tpublic static <T> ArrayList<T> unique(ArrayList<T> sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.size(); ++i)\n\t\t\tif (!sequence.get(i).equals(sequence.get(i - 1)))\n\t\t\t\t++size;\n\n\t\tArrayList<T> newSequence = new ArrayList<T>(size);\n\t\tnewSequence.add(sequence.get(0));\n\n\t\tfor (int i = 1; i < sequence.size(); ++i)\n\t\t\tif (!sequence.get(i).equals(sequence.get(i - 1)))\n\t\t\t\tnewSequence.add(sequence.get(i));\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static <T> T[] unique(T[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (!sequence[i].equals(sequence[i - 1]))\n\t\t\t\t++size;\n\n\t\tT[] newSequence = (T[]) new Object[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (!sequence[i].equals(sequence[i - 1]))\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static int[] unique(int[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tint[] newSequence = new int[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static long[] unique(long[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tlong[] newSequence = new long[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static char[] unique(char[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tchar[] newSequence = new char[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static double[] unique(double[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tdouble[] newSequence = new double[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static boolean[] unique(boolean[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tboolean[] newSequence = new boolean[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static short[] unique(short[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tshort[] newSequence = new short[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n\n\tpublic static byte[] unique(byte[] sequence) {\n\t\tint size = 1;\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\t++size;\n\n\t\tbyte[] newSequence = new byte[size];\n\t\tnewSequence[0] = sequence[0];\n\t\tsize = 0;\n\n\t\tfor (int i = 1; i < sequence.length; ++i)\n\t\t\tif (sequence[i] != sequence[i - 1])\n\t\t\t\tnewSequence[++size] = sequence[i];\n\n\t\treturn newSequence;\n\t}\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class C {\n\t\n\tpublic static final long MAX = 1000000000L;\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\tStringTokenizer tok1 = new StringTokenizer(br.readLine());\n\t\tfinal int n = Integer.parseInt(tok1.nextToken());\n\t\tfinal long k = Integer.parseInt(tok1.nextToken());\n\t\t\n\t\tStringTokenizer tok2 = new StringTokenizer(br.readLine());\n\t\tint[] array = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tarray[i] = Integer.parseInt(tok2.nextToken());\n\t\t}\n\t\t\n\t\tint size = n;\n\t\t\n\t\tArrays.sort(array);\n\t\t\n\t\tboolean[] skip = new boolean[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tif(skip[i]){\n\t\t\t\tsize--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tlong input = array[i];\n\t\t\tinput *= k;\n\t\t\tif(input > MAX){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfinal int pos = Arrays.binarySearch(array, (int)(input));\n\t\t\tif(pos >= 0 && !skip[pos]){\n\t\t\t\tskip[pos] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(size);\n\t}\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\nimport java.util.Arrays;\n\npublic class Main {\n    public static void main(String args[]) {\n        Scanner input = new Scanner(System.in);\n        int n = input.nextInt();\n        long k = input.nextInt();\n        long[] nums = new long[n];\n        for (int i = 0; i < n; i++) {\n            nums[i] = input.nextInt();\n        }\n        Arrays.sort(nums);\n        Set<Long> wrong = new TreeSet<Long>();\n        long ans = 0;\n        for (int i = 0; i < n; i++) {\n            if (!wrong.contains(nums[i])) {\n                try {\n                    wrong.add(nums[i] * k);\n                } catch (Exception e) {\n                }\n                ans++;\n            }\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new A(), \"\", 64*1024*1024).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = 0, t2 = 0, m1 = 0, m2 = 0;\n\t\t\tif (LOCAL) {\n\t\t\t\tt1 = System.currentTimeMillis();\n\t\t\t\tm1 = Runtime.getRuntime().freeMemory();\n\t\t\t}\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tif (LOCAL) {\n\t\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\t} else {\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\ttok = new StringTokenizer(\"\");\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t\tif (LOCAL) {\n\t\t\t\tt2 = System.currentTimeMillis();\n\t\t\t\tm2 = Runtime.getRuntime().freeMemory();\n\t\t\t\tSystem.err.println(\"Time = \" + (t2 - t1) + \" ms.\");\n\t\t\t\tSystem.err.println(\"Memory = \" + ((m1 - m2) / 1024) + \" KB.\");\n\t\t\t}\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) return null;\n\t\t\ttok = new StringTokenizer(line);\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\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tstatic class Mergesort {\n\n\t\tprivate Mergesort() {}\n\n\t\tpublic static void sort(int[] a) {\n\t\t\tmergesort(a, 0, a.length - 1);\n\t\t}\n\n\t\tpublic static void sort(long[] a) {\n\t\t\tmergesort(a, 0, a.length - 1);\n\t\t}\n\n\t\tpublic static void sort(double[] a) {\n\t\t\tmergesort(a, 0, a.length - 1);\n\t\t}\n\n\t\tprivate static final int MAGIC_VALUE = 42;\n\n\t\tprivate static void mergesort(int[] a, int leftIndex, int rightIndex) {\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 mergesort(long[] a, int leftIndex, int rightIndex) {\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 mergesort(double[] a, int leftIndex, int rightIndex) {\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, int 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++] : rightArray[j++];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void merge(long[] a, int leftIndex, int middleIndex, int rightIndex) {\n\t\t\tint length1 = middleIndex - leftIndex + 1;\n\t\t\tint length2 = rightIndex - middleIndex;\n\t\t\tlong[] leftArray = new long[length1];\n\t\t\tlong[] rightArray = new long[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++] : rightArray[j++];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void merge(double[] a, int leftIndex, int middleIndex, int rightIndex) {\n\t\t\tint length1 = middleIndex - leftIndex + 1;\n\t\t\tint length2 = rightIndex - middleIndex;\n\t\t\tdouble[] leftArray = new double[length1];\n\t\t\tdouble[] rightArray = new double[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++] : 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\n\t\tprivate static void insertionSort(long[] a, int leftIndex, int rightIndex) {\n\t\t\tfor (int i = leftIndex + 1; i <= rightIndex; i++) {\n\t\t\t\tlong 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\n\t\tprivate static void insertionSort(double[] a, int leftIndex, int rightIndex) {\n\t\t\tfor (int i = leftIndex + 1; i <= rightIndex; i++) {\n\t\t\t\tdouble 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\n\t}\n\t\n\tvoid debug(Object... o) {\n\t\tif (LOCAL) {\n\t\t\tSystem.err.println(Arrays.deepToString(o));\n\t\t}\n\t}\n\t\n\tfinal static boolean LOCAL = System.getProperty(\"ONLINE_JUDGE\") == null;\n\t\n//------------------------------------------------------------------------------\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tlong k = readLong();\n\t\tif (k == 1) {\n\t\t\tout.println(n);\n\t\t\treturn;\n\t\t}\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = readLong();\n\t\t}\n\t\tMergesort.sort(a);\n\t\tint ans = 0;\n\t\tboolean[] processed = new boolean[n];\n\t\tdebug(a);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (processed[i]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprocessed[i] = true;\n\t\t\tlong cur = a[i];\n\t\t\tans++;\n\t\t\tint index = Arrays.binarySearch(a, cur * k);\n\t\t\tif (index >= 0) {\n\t\t\t\tprocessed[index] = true;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n \t\n\tpublic void solve () throws Exception {\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\t\n\t\tTreeSet<Integer> bad = new TreeSet<>();\n\t\tint a [] = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextInt();\n\t\t\n\t\tRandom rnd = new Random();\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = rnd.nextInt(i + 1);\n\t\t\tint t = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = t;\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\t\n\t\tint result = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!bad.contains(a[i])) {\n\t\t\t\tresult++;\n\t\t\t\tlong next = (long) a[i] * k;\n\t\t\t\tif (next <= 1000000000)\n\t\t\t\t\tbad.add((int) next);\n\t\t\t}\n\t\t}\n\t\tout.println(result);\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\n\tstatic Throwable uncaught;\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.uncaught = 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 t = new Thread(null, new Solution(), \"\", (1 << 26));\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\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\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\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}", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n//basically tried to understand ping's greedy alg\npublic class kMultRedo {\n\tstatic int n;\n\tstatic int k;\n\tpublic static void main(String[] args){\n\t\tSet<Integer> set = new TreeSet<Integer>();\n\t\tFastScanner s = new FastScanner();\n\t\tn = s.nextInt();\n\t\tk = s.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] = s.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\t\n\t\tfor(int i=0; i<n; i++){\n\t\t\tif(a[i]%k !=0){\n\t\t\t\tset.add(a[i]);\n\t\t\t}else{\n\t\t\t\tif(!set.contains(a[i]/k)){\n\t\t\t\t\tset.add(a[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(set.size());\n\t}\n\t\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", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "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 * @author ocelopilli\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 n = in.nextInt();\n        long k = in.nextLong();\n        long[] a = new long[n];\n        for (int i=0; i<n; i++) a[i] = in.nextInt();\n        Arrays.sort( a );\n        boolean[] ok = new boolean[ n ];\n        Arrays.fill( ok, true );\n        if (k > 1) for (int i=0; i<n; i++)\n        {\n            if ( ok[i] == false ) continue;\n            int pos = Arrays.binarySearch( a, a[i]*k );\n            if ( pos >= 0 )\n            {\n                //out.println( a[i]+\" \"+a[pos] );\n                ok[ pos ] = false;\n            }\n        }\n        int ans = 0;\n        for (boolean x : ok) if ( x ) ans++;\n        out.println( ans );\n    }\n}\n\nclass InputReader {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public InputReader(InputStream in)\n    {\n        br = new BufferedReader(new InputStreamReader(in));\n        st = null;\n    }\n\n    public String next()\n    {\n        while (st==null || !st.hasMoreTokens())\n        {\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    {\n        return Integer.parseInt(next());\n    }\n\n    public long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A274 {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n    \n        Scanner in= new Scanner(System.in);\n        int n=in.nextInt();\n        int k=in.nextInt();\n        \n        Long a[] =new Long[n];\n        Hashtable<Long, Boolean> hash= new Hashtable<Long, Boolean>();\n        \n        \n        for (int i=0;i< n;i++){\n            a[i]=in.nextLong();\n            \n        }\n        Arrays.sort(a);\n        \n        for (int i=0;i<n;i++){\n            if (!hash.containsKey(a[i]) ){\n                hash.put(a[i]*k, true);\n            }\n            \n        }\n        System.out.println(hash.size());\n        \n        \n    }\n\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class A {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic A () {\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tLong [] A = sc.nextLongs();\n\n\t\tsort(A);\n\t\tSet<Long> S = new HashSet<Long>();\n\t\t\n\t\tfor (long a : A) {\n\t\t\tif (a % K == 0 && S.contains(P * (a/K)))\n\t\t\t\tcontinue;\n\t\t\tS.add(P*a);\n\t\t}\n\t\t\n\t\tint res = S.size();\n\t\texit(res);\n\t}\n\n\tlong P = probablePrime(50, new Random()).longValue();\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print(Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint(Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "nlogn", "problem": "274_A. k-Multiple Free Set", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class P220A\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        List<Integer> b = new ArrayList<Integer>(n);\n        for (int i = 0; i < n; i++)\n        {\n            a[i] = sc.nextInt();\n            b.add(a[i]);\n        }\n        Collections.sort(b);\n        int c = 0;\n        for (int i = 0; i < n; i++)\n        {\n            if (a[i] != b.get(i)) c++;\n        }\n        if (c == 0 || c == 2)\n        {\n            System.out.println(\"YES\");\n        }\n        else\n        {\n            System.out.println(\"NO\");\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n\t\n\tvoid randomShuffle(int[] arr) {\n\t\tRandom rnd = new Random();\n\t\tfor (int i = arr.length - 1; i >= 0; i--) {\n\t\t\tint pos = rnd.nextInt(i + 1);\n\t\t\tint temp = arr[pos];\n\t\t\tarr[pos] = arr[i];\n\t\t\tarr[i] = temp;\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = sc.nextInt();\n\t\tint[] a = new int[n];\n\t\tint[] ac = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = ac[i] = sc.nextInt();\n\t\t}\n\t\trandomShuffle(ac);\n\t\tArrays.sort(ac);\n\t\tint diff = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i] != ac[i]) {\n\t\t\t\tdiff++;\n\t\t\t}\n\t\t}\n\t\tif (diff <= 2) {\n\t\t\tout.println(\"YES\");\n\t\t} else {\n\t\t\tout.println(\"NO\");\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\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}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Locale;\nimport java.io.OutputStream;\nimport java.util.RandomAccess;\nimport java.io.PrintWriter;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.IOException;\nimport java.math.BigDecimal;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\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 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\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();\n        int[] a = in.nextIntArray(n);\n        int[] b = a.clone();\n        Collections.sort(ArrayUtils.asList(b));\n        int diff = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i] != b[i])\n                diff++;\n        }\n        out.println(diff <= 2 ? \"YES\" : \"NO\");\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 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 & 15;\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    public int[] nextIntArray(int count) {\n        int[] result = new int[count];\n        for (int i = 0; i < count; i++) {\n            result[i] = nextInt();\n        }\n        return result;\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(String x) {\n        writer.println(x);\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    }\n\nclass ArrayUtils {\n\n    public static List<Integer> asList(int[] array) {\n        return new IntList(array);\n    }\n\n    private static class IntList extends AbstractList<Integer> implements RandomAccess {\n\n        int[] array;\n\n        private IntList(int[] array) {\n            this.array = array;\n        }\n\n        public Integer get(int index) {\n            return array[index];\n        }\n\n        public Integer set(int index, Integer element) {\n            int result = array[index];\n            array[index] = element;\n            return result;\n        }\n\n        public int size() {\n            return array.length;\n        }\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tint[] b = a.clone();\n\t\tArrays.sort(b);\n\t\tint diff = 0;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (a[i] != b[i]) {\n\t\t\t\tdiff++;\n\t\t\t}\n\t\t}\n\t\tout.println(diff <= 2 ? \"YES\" : \"NO\");\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}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class A implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\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}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new A(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tlong memoryTotal, memoryFree;\n\t\n\n\tvoid memory(){\n\t\tmemoryFree = Runtime.getRuntime().freeMemory();\n\t\tSystem.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10) + \" KB\");\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (DEBUG){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tmemoryTotal = Runtime.getRuntime().freeMemory();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\ttime();\n\t\t\tmemory();\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\tboolean DEBUG = false;\n\t\n\tvoid solve() throws IOException{\n\t\tint n = readInt();\n\t\t\n\t\tint[] a = new int[n];\n\t\tInteger[] b = new Integer[n];\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\ta[i] = readInt();\n\t\t\tb[i] = a[i];\n\t\t}\n\t\t\n\t\tArrays.sort(b);\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tif (a[i] != b[i]){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (count == 2 || count == 0){\n\t\t\tout.println(\"YES\");\n\t\t}else{\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n}\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\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        int testCount = 1;\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n}\n\nclass Task {\n    int n;\n    int[] a;\n    int[] b;\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        n = in.readInt();\n        a = new int[n];\n        b = new int[n];\n        for (int i = 0; i < n; ++i)\n            a[i] = b[i] = in.readInt();\n        sort(0, n - 1);\n        int different = 0;\n        for (int i = 0; i < n; ++i)\n            if (a[i] != b[i])\n                ++different;\n        out.println(different <= 2 ? \"YES\" : \"NO\");\n    }\n\n    public void sort(int lo, int hi) {\n        if (lo < hi) {\n            int mid = (lo + hi) / 2;\n            sort(lo, mid);\n            sort(mid + 1, hi);\n            merge(lo, mid, hi);\n        }\n    }\n\n    public void merge(int lo, int mid, int hi) {\n        int n1 = mid - lo + 1;\n        int n2 = hi - (mid + 1) + 1;\n        int[] x = new int[n1 + 1];\n        int[] y = new int[n2 + 1];\n        for (int i = 0; i < n1; ++i)\n            x[i] = b[lo + i];\n        for (int j = 0; j < n2; ++j)\n            y[j] = b[mid + 1 + j];\n        x[n1] = y[n2] = Integer.MAX_VALUE;\n        for (int k = lo, i = 0, j = 0; k <= hi; ++k)\n            b[k] = x[i] < y[j] ? x[i++] : y[j++];\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 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    public Long readLong() {\n        return Long.parseLong(readString());\n    }\n\n    public Double readDouble() {\n        return Double.parseDouble(readString());\n    }\n\n    public static boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n\npublic class Main {\n\n    \n    public static void main(String[] args) {\n        Scanner in=new Scanner(new InputStreamReader(System.in));\n        PrintWriter out=new PrintWriter(System.out);\n        int n=in.nextInt();\n        Vector<Integer> mas=new Vector<Integer>();\n        Vector<Integer> mas2=new Vector<Integer>();\n        int index=-1;\n        boolean res=false;\n        for(int i=0; i<n; i++){\n            mas.add(in.nextInt());\n            if(i!=0 && mas.get(i)<mas.get(i-1)){\n                index=i-1;\n                break;\n            }\n        }\n        if(index==-1) res=true;\n        else{\n            int min=mas.get(index+1);\n            int minIndex=index+1;\n            for(int i=index+2; i<n; i++){\n                mas.add(in.nextInt());\n                if(mas.get(i)<=min){\n                    min=mas.get(i);\n                    minIndex=i;\n                    \n                }\n            }\n            \n            mas2.addAll(mas);\n            mas.set(minIndex, mas.get(index));\n            mas.set(index, min);\n            int o=mas.hashCode();\n            Collections.sort(mas);\n            int nw=mas.hashCode();\n            res=nw==o;\n        }\n        if(!res){\n            mas=mas2;\n            for(int i=n-1; i>=0; i--){\n                if(i!=n-1 && mas.get(i)>mas.get(i+1)){\n                    index=i+1;\n                    break;\n                }\n            }\n            if(index==-1) res=true;\n            else{\n                int max=mas.get(index-1);\n                int maxIndex=index-1;\n                for(int i=index-1; i>=0; i--){\n                    if(mas.get(i)>=max){\n                        max=mas.get(i);\n                        maxIndex=i;\n                    }\n                }\n                mas.set(maxIndex, mas.get(index));\n                mas.set(index, max);\n                int o=mas.hashCode();\n                Collections.sort(mas);\n                int nw=mas.hashCode();\n                res=res||nw==o;\n            }\n        }\n        if(res) out.println(\"YES\");\n        else out.println(\"NO\");\n        out.close();\n    }\n\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.DataInputStream;\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;\n\n\npublic class Main{\n\n    public static void main(String[] args) throws Exception {\n        Parserdoubt12 s = new Parserdoubt12(System.in);\n        \n        int n = s.nextInt();\n        \n        int a[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = s.nextInt();\n        }\n        \n        int copy[] = a.clone();\n        Arrays.sort(a);\n        int count = 0;\n        for (int i = 0; i < copy.length; i++) {\n            if(a[i] != copy[i]) count++;\n        }\n        if(count <= 2) System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n    }\n    \n    \n}\n\n\nclass Parserdoubt12\n{\n   final private int BUFFER_SIZE = 1 << 17;\n \n   private DataInputStream din;\n   private byte[] buffer;\n   private int bufferPointer, bytesRead;\n \n   public Parserdoubt12(InputStream in)\n   {\n      din = new DataInputStream(in);\n      buffer = new byte[BUFFER_SIZE];\n      bufferPointer = bytesRead = 0;\n   }\n   public String nextString() throws Exception\n   {\n       StringBuffer sb=new StringBuffer(\"\");\n       byte c = read();\n       while (c <= ' ') c = read();\n       do\n       {\n           sb.append((char)c);\n           c=read();\n       }while(c>' ');\n       return sb.toString();\n   }\n   public char nextChar() throws Exception\n   {\n       byte c=read();\n       while(c<=' ') c= read();\n       return (char)c;\n   }\n   public int nextInt() throws Exception\n   {\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      {\n          ret = ret * 10 + c - '0';\n         c = read();\n      } while (c > ' ');\n      if (neg) return -ret;\n      return ret;\n   }\n   public long nextLong() throws Exception\n   {\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      {\n          ret = ret * 10 + c - '0';\n         c = read();\n      } while (c > ' ');\n      if (neg) return -ret;\n      return ret;\n   }\n   private void fillBuffer() throws Exception\n   {\n      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n      if (bytesRead == -1) buffer[0] = -1;\n   }\n \n   private byte read() throws Exception\n   {\n      if (bufferPointer == bytesRead) fillBuffer();\n      return buffer[bufferPointer++];\n   }\n} ", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\n\t\t// long start = System.currentTimeMillis();\n\t\t// long end = System.currentTimeMillis();\n\t\t// System.out.println(\" Execution time was \"+(end-start)+\" ms.\");\n\n\t\tScanner kb = new Scanner(System.in);\n\t\tint n = kb.nextInt();\n\t\tint a[] = new int[n];\n\t\tint b[] = new int[n];\n\t\tfor(int i = 0;i<n;i++){\n\t\t\ta[i]=kb.nextInt();\n\t\t\tb[i]=a[i];\n\t\t}\n\t\tArrays.sort(a);\n\t\tint count = 0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(a[i]!=b[i])count++;\n\t\t}\n\t\tif(count<=2)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\n\t}\n\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\tstatic Random  rnd;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\n\t\tint[] arr = new int[n];\n\t\tInteger[] arrCopy = new Integer[n];\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = arrCopy[i] = nextInt();\n\n\t\tArrays.sort(arrCopy);\n\n\t\tint bad = 0;\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif (arr[i] != arrCopy[i])\n\t\t\t\t++bad;\n\n\t\tboolean fail = bad > 2;\n\n\t\tout.println(!fail ? \"YES\" : \"NO\");\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\n\t\t\trnd = new Random();\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(42);\n\t\t}\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\n\t\t\tif (line == null)\n\t\t\t\treturn null;\n\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.regex.*;\nimport static java.lang.Math.*;\npublic class A {\n\n    public A() throws Exception {\n        int n = in.nextInt();\n        int[] arr = new int[n];\n        for (int i=0; i<n; i++) arr[i] = in.nextInt();\n        int[] arr2 = arr.clone();\n        Arrays.sort(arr2);\n        int diff = 0;\n        for (int i=0; i<n; i++) {\n            if (arr2[i]!=arr[i]) diff++;\n        }\n        if (diff<=2) System.out.println(\"YES\");\n        else System.out.println(\"NO\"); \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    public static class Scanner { // {{{\n        BufferedReader br;\n        String line;\n        StringTokenizer st;\n        public Scanner(InputStream in) {\n            br = new BufferedReader(new InputStreamReader(in));\n        }\n        public boolean hasNext() throws IOException {\n            while ((st==null||!st.hasMoreTokens())&&(line=br.readLine())!=null)\n                st = new StringTokenizer(line);\n            return st.hasMoreTokens();\n        }\n        public String next() throws IOException {\n            if (hasNext()) return st.nextToken();\n            throw new NoSuchElementException();\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 double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n    } // }}}\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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\tint fu(int[] a, int l) {\n\t\tfor (int i = l; i < a.length - 1; i++) {\n\t\t\tif (a[i] > a[i + 1]) return i;\n\t\t}\n\t\treturn a.length;\n\t}\n\t\n\tvoid swap(int[] a, int q, int w) {\n\t\tint t = a[q]; a[q] = a[w]; a[w] = t;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) a[i] = nextInt();\n\t\tint q = fu(a, 0);\n\t\tif (q == n) out.println(\"YES\"); else {\n\t\t\tint w = fu(a, q + 1);\n\t\t\tif (w < n) {\n\t\t\t\tboolean ans = false;\n\t\t\t\tswap(a, q, w);\n\t\t\t\tans |= fu(a, 0) == n;\n\t\t\t\tswap(a, q, w);\n\t\t\t\tif (q < n - 1) {\n\t\t\t\t\tswap(a, q + 1, w);\n\t\t\t\t\tans |= fu(a, 0) == n;\n\t\t\t\t\tswap(a, q + 1, w);\n\t\t\t\t}\n\t\t\t\tif (w < n - 1) {\n\t\t\t\t\tswap(a, q, w + 1);\n\t\t\t\t\tans |= fu(a, 0) == n;\n\t\t\t\t\tswap(a, q, w + 1);\n\t\t\t\t}\n\t\t\t\tif (q < n - 1 && w < n - 1) {\n\t\t\t\t\tswap(a, q + 1, w + 1);\n\t\t\t\t\tans |= fu(a, 0) == n;\n\t\t\t\t\tswap(a, q + 1, w + 1);\n\t\t\t\t}\n\t\t\t\tif (ans) out.println(\"YES\"); else out.println(\"NO\");\n\t\t\t} else {\n\t\t\t\tint j = q + 1;\n\t\t\t\twhile (j < n && a[j] == a[q + 1]) j++;\n\t\t\t\tj--;\n\t\t\t\tswap(a, q, j);\n\t\t\t\tif (fu(a, 0) == n) out.println(\"YES\"); else {\n\t\t\t\t\tswap(a, q, j);\n\t\t\t\t\tq++;\n\t\t\t\t\tj = q - 1;\n\t\t\t\t\twhile (j >= 0 && a[j] == a[q - 1]) j--;\n\t\t\t\t\tj++;\n\t\t\t\t\tswap(a, q, j);\n\t\t\t\t\tif (fu(a, 0) == n) out.println(\"YES\"); else out.println(\"NO\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.UK);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// new Thread(null, new Solution(), \"1\", 1 << 28).start();\n\t\t(new Solution()).run();\n\t}\n\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.List;\nimport 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.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 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\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, FastScanner in, FastPrinter 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        int[] b = a.clone();\n        ArrayUtils.sort(b);\n        int count = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i] != b[i]) {\n                ++count;\n            }\n        }\n        out.println(count <= 2 ? \"YES\" : \"NO\");\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\nclass ArrayUtils {\n\n    public static void sort(int[] a) {\n        Random rand = new Random(System.nanoTime());\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        Arrays.sort(a);\n    }\n\n\n    }\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.Line2D;\nimport java.awt.Point;\nimport static java.lang.reflect.Array.*;\n\npublic class LittleElephantAndProblem {\n\n    boolean DEBUG = true;\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringBuilder out = new StringBuilder();\n    StringTokenizer st = null;\n\n    String s() throws IOException {\n        if (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int i() throws IOException {\n        return Integer.parseInt(s());\n    }\n\n    int i(String s) throws IOException {\n        return Integer.parseInt(s);\n    }\n\n    long l() throws IOException {\n        return Long.parseLong(s());\n    }\n\n    long l(String s) throws IOException {\n        return Long.parseLong(s);\n    }\n\n    double d() throws IOException {\n        return Double.parseDouble(s());\n    }\n\n    double d(String s) throws IOException {\n        return Double.parseDouble(s);\n    }\n\n    void D(Object a) {\n        if (DEBUG) {\n            int len = getLength(a);\n            for (int i = 0; i < len; ++i) {\n                System.out.print(get(a, i) + \" \");\n            }\n            System.out.println();\n        }\n    }\n\n    void D(Object[] a) {\n        if (DEBUG) {\n            int R = getLength(a), C = getLength(get(a, 0));\n            for (int i = 0; i < R; ++i) {\n                for (int j = 0; j < C; ++j) {\n                    System.out.print(get(get(a, i), j) + \" \");\n                }\n                System.out.println();\n            }\n        }\n    }\n\n    void D(String args) {\n        if (DEBUG) {\n            System.out.print(args);\n        }\n    }\n\n    void D(String format, Object... args) {\n        if (DEBUG) {\n            System.out.printf(format, args);\n        }\n    }\n\n    void fl() {\n        System.out.print(out);\n    }\n    int n = i();\n\n    public LittleElephantAndProblem() throws IOException {\n        List<Integer> a = new ArrayList<Integer>();\n        List<Integer> b = new ArrayList<Integer>();\n        for (int i = 0; i < n; ++i) {\n            int x = i();\n            a.add(x);\n            b.add(x);\n        }\n        sort(b);\n        int d = 0;\n        for (int i = 0; i < n; ++i) {\n            if ((int)a.get(i) != (int)b.get(i)) {\n                ++d;\n            }\n        }\n        if (d > 2) {\n            out.append(\"NO\\n\");\n        } else {\n            out.append(\"YES\\n\");\n        }\n        fl();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new LittleElephantAndProblem();\n    }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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 A {\n\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tInteger[] a = new Integer[n];\n\t\tInteger[] b = new Integer[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = b[i] = nextInt();\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\tint k = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!a[i].equals(b[i])) {\n\t\t\t\tk++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (k <= 2) {\n\t\t\tprintln(\"YES\");\n\t\t} else {\n\t\t\tprintln(\"NO\");\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 A().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}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tInteger[] a = new Integer[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tInteger[] b = a.clone();\n\t\tArrays.sort(b);\n\t\tint d = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!a[i].equals(b[i])) d++;\n\t\t}\n\t\tout.println(d > 2? \"NO\" : \"YES\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.UK);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// new Thread(null, new Solution(), \"1\", 1 << 28).start();\n\t\t(new Solution()).run();\n\t}\n\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author 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        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        int count = in.readInt();\n        int[] array = IOUtils.readIntArray(in, count);\n        int[] sorted = array.clone();\n        ArrayUtils.sort(sorted, IntComparator.DEFAULT);\n        int differs = 0;\n        for (int i = 0; i < count; i++) {\n            if (array[i] != sorted[i])\n                differs++;\n        }\n        if (differs <= 2)\n            out.printLine(\"YES\");\n        else\n            out.printLine(\"NO\");\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\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\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 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\nclass ArrayUtils {\n    private static int[] tempInt = new int[0];\n\n    public static int[] sort(int[] array, IntComparator comparator) {\n        return sort(array, 0, array.length, comparator);\n    }\n\n    public static int[] sort(int[] array, int from, int to, IntComparator comparator) {\n        ensureCapacityInt(to - from);\n        System.arraycopy(array, from, tempInt, 0, to - from);\n        sortImpl(array, from, to, tempInt, 0, to - from, comparator);\n        return array;\n    }\n\n    private static void ensureCapacityInt(int size) {\n        if (tempInt.length >= size)\n            return;\n        size = Math.max(size, tempInt.length << 1);\n        tempInt = new int[size];\n    }\n\n    private static void sortImpl(int[] array, int from, int to, int[] temp, int fromTemp, int toTemp, IntComparator comparator) {\n        if (to - from <= 1)\n            return;\n        int middle = (to - from) >> 1;\n        int tempMiddle = fromTemp + middle;\n        sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle, comparator);\n        sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);\n        int index = from;\n        int index1 = fromTemp;\n        int index2 = tempMiddle;\n        while (index1 < tempMiddle && index2 < toTemp) {\n            if (comparator.compare(temp[index1], temp[index2]) <= 0)\n                array[index++] = temp[index1++];\n            else\n                array[index++] = temp[index2++];\n        }\n        if (index1 != tempMiddle)\n            System.arraycopy(temp, index1, array, index, tempMiddle - index1);\n        if (index2 != toTemp)\n            System.arraycopy(temp, index2, array, index, toTemp - index2);\n    }\n\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    public int compare(int first, int second);\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class A implements Runnable\n{\n    String file = \"input\";\n    \n    boolean TEST = System.getProperty(\"ONLINE_JUDGE\") == null;\n    \n    void solve() throws IOException\n    {\n        int n = nextInt();\n        int[] a = new int[n];\n        for(int i = 0; i < n; i++) a[i] = nextInt();\n        int[] b = a.clone();\n        sortInt(b);\n        int count = 0;\n        for(int i = 0; i < a.length; i++)\n            if(a[i] != b[i]) count++;\n        if(count == 0 || count == 2) out.println(\"YES\");\n        else out.println(\"NO\");\n    }\n    \n    Random rnd = new Random();\n    \n    void sortInt(int[] a)\n    {\n        sortInt(a, 0, a.length - 1);\n    }\n    \n    void sortInt(int[] a, int from, int to)\n    {\n        if(from >= to) return;\n        int i = from - 1;\n        int p = rnd.nextInt(to - from + 1) + from;\n        int t = a[p]; a[p] = a[to]; a[to] = t;\n        for(int j = from; j < to; j++)\n            if(a[j] <= a[to])\n            {\n                i++;\n                t = a[i]; a[i] = a[j]; a[j] = t;\n            }\n        t = a[i + 1]; a[i + 1] = a[to]; a[to] = t;\n        sortInt(a, i + 2, to);\n        while(i >= 0 && a[i] == a[i + 1]) i--;\n        sortInt(a, from, i);\n        \n    }\n    \n    String next() throws IOException\n    {\n        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n        return st.nextToken();\n    }\n    \n    int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n    \n    long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n    \n    double nextDouble() throws IOException\n    {\n        return Double.parseDouble(next());\n    }\n    \n    void print(Object... o)\n    {\n        System.out.println(deepToString(o));\n    }\n    \n    void gcj(Object o)\n    {\n        String s = String.valueOf(o);\n        out.println(\"Case #\" + test + \": \" + s);\n        System.out.println(\"Case #\" + test + \": \" + s);\n    }\n    \n    BufferedReader input;\n    PrintWriter out;\n    StringTokenizer st;\n    int test;\n    \n    void init() throws IOException\n    {\n        if(TEST) input = new BufferedReader(new FileReader(file + \".in\")); \n        else input = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n    }\n    \n    public static void main(String[] args) throws IOException\n    {\n        new Thread(null, new A(), \"\", 1 << 22).start();\n    }\n    \n    public void run()\n    {\n        try\n        {\n            init();\n            if(TEST) \n            {\n                int runs = nextInt();\n                for(int i = 0; i < runs; i++) solve();\n            }\n            else solve();\n            out.close();        \n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\tstatic Random rnd;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\n\t\tint[] arr = new int[n];\n\t\tInteger[] arrCopy = new Integer[n];\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = arrCopy[i] = nextInt();\n\n\t\tArrays.sort(arrCopy);\n\n\t\tint bad = 0;\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif (arr[i] != arrCopy[i])\n\t\t\t\t++bad;\n\n\t\tboolean fail = bad > 2;\n\n\t\tout.println(!fail ? \"YES\" : \"NO\");\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\n\t\t\trnd = new Random();\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(42);\n\t\t}\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\n\t\t\tif (line == null)\n\t\t\t\treturn null;\n\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class A implements Runnable\n{\n    String file = \"input\";\n    \n    boolean TEST = System.getProperty(\"ONLINE_JUDGE\") == null;\n    \n    void solve() throws IOException\n    {\n        int n = nextInt();\n        int[] a = new int[n];\n        for(int i = 0; i < n; i++) a[i] = nextInt();\n        int[] b = a.clone();\n        qsort(b);\n        //sortInt(b);\n        int count = 0;\n        for(int i = 0; i < a.length; i++)\n            if(a[i] != b[i]) count++;\n        if(count == 0 || count == 2) out.println(\"YES\");\n        else out.println(\"NO\");\n    }\n    \n    void qsort(int[] a)\n    {\n        List<Integer> as = new ArrayList<Integer>();\n        for(int x : a) as.add(x);\n        Collections.shuffle(as);\n        for(int i = 0; i < a.length; i++) a[i] = as.get(i);\n        sort(a);\n    }\n    \n    Random rnd = new Random();\n    \n    void sortInt(int[] a)\n    {\n        sortInt(a, 0, a.length - 1);\n    }\n    \n    void sortInt(int[] a, int from, int to)\n    {\n        if(from >= to) return;\n        int i = from - 1;\n        int p = rnd.nextInt(to - from + 1) + from;\n        int t = a[p]; a[p] = a[to]; a[to] = t;\n        for(int j = from; j < to; j++)\n            if(a[j] <= a[to])\n            {\n                i++;\n                t = a[i]; a[i] = a[j]; a[j] = t;\n            }\n        t = a[i + 1]; a[i + 1] = a[to]; a[to] = t;\n        sortInt(a, i + 2, to);\n        while(i >= 0 && a[i] == a[i + 1]) i--;\n        sortInt(a, from, i);\n        \n    }\n    \n    String next() throws IOException\n    {\n        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n        return st.nextToken();\n    }\n    \n    int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n    \n    long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n    \n    double nextDouble() throws IOException\n    {\n        return Double.parseDouble(next());\n    }\n    \n    void print(Object... o)\n    {\n        System.out.println(deepToString(o));\n    }\n    \n    void gcj(Object o)\n    {\n        String s = String.valueOf(o);\n        out.println(\"Case #\" + test + \": \" + s);\n        System.out.println(\"Case #\" + test + \": \" + s);\n    }\n    \n    BufferedReader input;\n    PrintWriter out;\n    StringTokenizer st;\n    int test;\n    \n    void init() throws IOException\n    {\n        if(TEST) input = new BufferedReader(new FileReader(file + \".in\")); \n        else input = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n    }\n    \n    public static void main(String[] args) throws IOException\n    {\n        new Thread(null, new A(), \"\", 1 << 22).start();\n    }\n    \n    public void run()\n    {\n        try\n        {\n            init();\n            if(TEST) \n            {\n                int runs = nextInt();\n                for(int i = 0; i < runs; i++) solve();\n            }\n            else solve();\n            out.close();        \n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\npublic class A {\n\n    static StreamTokenizer st;\n    static class Sort implements Comparable<Sort> {\n        int val;\n        public int compareTo(Sort o) {\n            return this.val-o.val;\n        }\n    }\n    public static void main(String[] args) throws IOException{\n        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int n = nextInt();\n        Sort[]a = new Sort[n+1];\n        int[]b = new int[n+1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = new Sort();\n            a[i].val = nextInt();\n            b[i] = a[i].val;\n        }\n        Arrays.sort(a, 1, n+1);\n        int k1 = 0, k2 = 0;\n        for (int i = 1; i <= n; i++) {\n            if (b[i] != a[i].val) {\n                if (k1==0)\n                    k1 = i;\n                else if (k2==0)\n                    k2 = i;\n                else {\n                    System.out.println(\"NO\");\n                    return;\n                }\n            }\n        }\n        if (k1==0)\n            System.out.println(\"YES\");\n        else if (k2==0)\n            System.out.println(\"NO\");\n        else {\n            if (b[k1]==a[k2].val && b[k2]==a[k1].val)\n                System.out.println(\"YES\");\n            else\n                System.out.println(\"NO\");\n        }\n        pw.close();\n    }\n\n    private static int nextInt() throws IOException{\n        st.nextToken();\n        return (int) st.nval;\n    }\n\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\n\npublic class A {\n    public void run() throws IOException {\n        final int n = IOFast.nextInt();\n        int[] xs = new int[n];\n        for(int i = 0; i < n; i++) {\n            xs[i] = IOFast.nextInt();\n        }\n        int[] ys = xs.clone();\n        Random random = new Random();\n        for(int i = 0; i < n; i++) {\n            final int j = random.nextInt(i + 1);\n            final int t = ys[j]; ys[j] = ys[i]; ys[i] = t;\n        }\n        Arrays.sort(ys);\n        \n        int diff = 0;\n        for(int i = 0; i < ys.length; i++) {\n            if(xs[i] != ys[i]) {\n                diff++;\n            }\n        }\n        \n        IOFast.out.println(diff > 2 ? \"NO\" : \"YES\");\n    }\n    \n    public static void main(String[] args) throws IOException {\n        new A().run();\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 int pos, readLen;\n        private static final char[] buffer = new char[1024 * 8];\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 read() throws IOException {\n            if(readLen == -1) {\n                return -1;\n            }\n            \n            if(pos >= readLen) {\n                readLen = in.read(buffer);\n                pos = 0;\n                \n                if(readLen <= 0) {\n                    return -1;\n                }\n            }\n            \n            return buffer[pos++];\n        }\n\n        private static int nextInt() throws IOException {\n            boolean plus = false;\n            int ret = 0;\n            while(true) {\n                final int c = 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 = 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 = 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 = 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 char nextChar() throws IOException {\n            while(true) {\n                final int c = read();\n                \n                if(c == -1) {\n                    endInput = true;\n                    return '\\0';\n                }\n                \n                if(!isSpace[c]) {\n                    return (char)c;\n                }\n            }\n        }\n\n        private static int next(char[] cs) throws IOException {\n            int n = 0;\n            while(true) {\n                final int c = read();\n                \n                if(c == -1) {\n                    endInput = true;\n                    return n;\n                }\n                \n                if(!isSpace[c]) {\n                    cs[n++] = (char)c;\n                    break;\n                }\n            }\n            \n            while(true) {\n                final int c = read();\n                \n                if(c == -1 || isSpace[c]) {\n                    break;\n                }\n                cs[n++] = (char)c;\n            }\n            \n            return n;\n        }\n\n        private static String next() throws IOException {\n            buf.setLength(0);\n\n            while(true) {\n                final int c = 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 = 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", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author 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\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint count = in.readInt();\n\t\tint[] array = IOUtils.readIntArray(in, count);\n\t\tint[] sorted = array.clone();\n\t\tArrayUtils.sort(sorted, IntComparator.DEFAULT);\n\t\tint differs = 0;\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tif (array[i] != sorted[i])\n\t\t\t\tdiffers++;\n\t\t}\n\t\tif (differs <= 2)\n\t\t\tout.printLine(\"YES\");\n\t\telse\n\t\t\tout.printLine(\"NO\");\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\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\nclass ArrayUtils {\n    private static int[] tempInt = new int[0];\n\n\tpublic static int[] sort(int[] array, IntComparator comparator) {\n        return sort(array, 0, array.length, comparator);\n    }\n\n    public static int[] sort(int[] array, int from, int to, IntComparator comparator) {\n        ensureCapacityInt(to - from);\n        System.arraycopy(array, from, tempInt, 0, to - from);\n        sortImpl(array, from, to, tempInt, 0, to - from, comparator);\n        return array;\n    }\n\n    private static void ensureCapacityInt(int size) {\n        if (tempInt.length >= size)\n            return;\n        size = Math.max(size, tempInt.length << 1);\n        tempInt = new int[size];\n    }\n\n    private static void sortImpl(int[] array, int from, int to, int[] temp, int fromTemp, int toTemp, IntComparator comparator) {\n        if (to - from <= 1)\n            return;\n        int middle = (to - from) >> 1;\n        int tempMiddle = fromTemp + middle;\n        sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle, comparator);\n        sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);\n        int index = from;\n        int index1 = fromTemp;\n        int index2 = tempMiddle;\n        while (index1 < tempMiddle && index2 < toTemp) {\n            if (comparator.compare(temp[index1], temp[index2]) <= 0)\n                array[index++] = temp[index1++];\n            else\n                array[index++] = temp[index2++];\n        }\n        if (index1 != tempMiddle)\n            System.arraycopy(temp, index1, array, index, tempMiddle - index1);\n        if (index2 != toTemp)\n            System.arraycopy(temp, index2, array, index, toTemp - index2);\n    }\n\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    public int compare(int first, int second);\n}\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class A implements Runnable\n{\n    String file = \"input\";\n    \n    boolean TEST = System.getProperty(\"ONLINE_JUDGE\") == null;\n    \n    void solve() throws IOException\n    {\n        int n = nextInt();\n        int[] a = new int[n];\n        for(int i = 0; i < n; i++) a[i] = nextInt();\n        int[] b = a.clone();\n        qsort(b);\n        //sortInt(b);\n        int count = 0;\n        for(int i = 0; i < a.length; i++)\n            if(a[i] != b[i]) count++;\n        if(count == 0 || count == 2) out.println(\"YES\");\n        else out.println(\"NO\");\n    }\n    \n    void qsort(int[] a)\n    {\n        List<Integer> as = new ArrayList<Integer>();\n        for(int x : a) as.add(x);\n        Collections.shuffle(as);\n        int j = 0;\n        for(int x : as) a[j++] = x;\n        sort(a);\n    }\n    \n    Random rnd = new Random();\n    \n    void sortInt(int[] a)\n    {\n        sortInt(a, 0, a.length - 1);\n    }\n    \n    void sortInt(int[] a, int from, int to)\n    {\n        if(from >= to) return;\n        int i = from - 1;\n        int p = rnd.nextInt(to - from + 1) + from;\n        int t = a[p]; a[p] = a[to]; a[to] = t;\n        for(int j = from; j < to; j++)\n            if(a[j] <= a[to])\n            {\n                i++;\n                t = a[i]; a[i] = a[j]; a[j] = t;\n            }\n        t = a[i + 1]; a[i + 1] = a[to]; a[to] = t;\n        sortInt(a, i + 2, to);\n        while(i >= 0 && a[i] == a[i + 1]) i--;\n        sortInt(a, from, i);\n        \n    }\n    \n    String next() throws IOException\n    {\n        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n        return st.nextToken();\n    }\n    \n    int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n    \n    long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n    \n    double nextDouble() throws IOException\n    {\n        return Double.parseDouble(next());\n    }\n    \n    void print(Object... o)\n    {\n        System.out.println(deepToString(o));\n    }\n    \n    void gcj(Object o)\n    {\n        String s = String.valueOf(o);\n        out.println(\"Case #\" + test + \": \" + s);\n        System.out.println(\"Case #\" + test + \": \" + s);\n    }\n    \n    BufferedReader input;\n    PrintWriter out;\n    StringTokenizer st;\n    int test;\n    \n    void init() throws IOException\n    {\n        if(TEST) input = new BufferedReader(new FileReader(file + \".in\")); \n        else input = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n    }\n    \n    public static void main(String[] args) throws IOException\n    {\n        new Thread(null, new A(), \"\", 1 << 22).start();\n    }\n    \n    public void run()\n    {\n        try\n        {\n            init();\n            if(TEST) \n            {\n                int runs = nextInt();\n                for(int i = 0; i < runs; i++) solve();\n            }\n            else solve();\n            out.close();        \n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer st = null;\n\tPrintWriter out;\n\n\tpublic void solution() throws IOException {\n\t\tint n = nextInt();\n\t\tint a[] = new int[n];\n\t\tint b[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tb[i] = a[i];\n\t\t}\n\t\tArrays.sort(a);\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i] != b[i]) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\n\t\tif (ans == 2 || ans == 0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\t}\n\n\tpublic String nextToken() throws IOException {\n\t\tif (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(bf.readLine());\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\n\tpublic void print(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\tpublic static void main(String args[]) throws IOException {\n\t\tnew C().solution();\n\t}\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tfinal String filename = new String(\"C\").toLowerCase();\n\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tif (isSorted(a)) {\n\t\t\tout.println(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\tint pos1 = -1;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tif (a[i] > a[i + 1]) {\n\t\t\t\tint j = i;\n\t\t\t\twhile (j >= 0 && a[j] == a[i]) {\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t\tpos1 = j + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t}\n\t\tint pos2 = -1;\n\t\tfor (int i = n - 2; i >= 0; i--) {\n\t\t\tif (a[i] > a[i + 1]) {\n\t\t\t\tint j = i + 1;\n\t\t\t\twhile (j < n && a[j] == a[i + 1]) {\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t\tpos2 = j - 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tint tmp = a[pos1];\n\t\ta[pos1] = a[pos2];\n\t\ta[pos2] = tmp;\n\t\tif (isSorted(a)) {\n\t\t\tout.println(\"YES\");\n\t\t} else {\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\n\tboolean isSorted(int[] a) {\n\t\tfor (int i = 0; i < a.length - 1; i++) {\n\t\t\tif (a[i] > a[i + 1]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\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    class IO {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(System.out);\n        StringTokenizer st;\n        Random rnd = new Random();;\n        String nextToken() throws IOException {\n            while (st == null || !st.hasMoreTokens()) {\n                String line = in.readLine();\n                if (line == null)\n                    return null;\n                st = new StringTokenizer(line);\n            }\n            return st.nextToken();\n        }\n        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    }\n    \n    void run() throws IOException{\n        IO read=new IO();\n        int n=read.nextInt();\n        int a[]=new int[n],b[]=new int[n];\n        for(int i=0;i<n;i++)\n            a[i]=b[i]=read.nextInt();\n        Arrays.sort(b);\n        int cnt=0;\n        for(int i=0;i<n;i++)\n            if(a[i]!=b[i])\n                cnt++;\n        if(cnt==0||cnt==2)\n            read.out.println(\"YES\");\n        else\n            read.out.println(\"NO\");\n        read.out.close();\n    }\n    public static void main(String[] args) throws IOException {\n        new c().run();\n    }\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "//package round136;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class A {\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 = new int[n];\n\t\tint[] b = new int[n];\n\t\tfor(int i = 0;i < n;i++)b[i] = a[i] = ni();\n\t\t\n\t\tArrays.sort(b);\n\t\tint ct = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(a[i] != b[i])ct++;\n\t\t}\n\t\tif(ct <= 2){\n\t\t\tout.println(\"YES\");\n\t\t}else{\n\t\t\tout.println(\"NO\");\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 A().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", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\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.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\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        \n        \n        int n = in.nextInt();\n        int a[] = in.nextIntArray(n);\n        int i,j,k;\n\n        int b[] = a.clone();\n        ArrayUtils.randomShuffle(a);\n        Arrays.sort(a);\n        \n        int c[] = new int[n];\n        k=0;\n        for(i=0;i<n;++i) if(a[i]!=b[i]) c[k++] = i;\n        \n        String res = \"NO\";\n        if(k==0){\n            res = \"YES\";\n        }else\n        if(k==1){\n           \n        }else\n        if(k==2){\n            i = c[0]; j = c[1];\n            if(a[i]==b[j] && a[j]==b[i]) res = \"YES\";\n        }\n        \n        out.writeln(res);\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(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 int[] nextIntArray(int size){\n        int array[] = new int[size];\n        for(int i=0; i<size; ++i) array[i] = nextInt();\n        return array;\n    }\n}\n\nclass OutputWriter{\n    private PrintWriter out;\n    \n    public OutputWriter(Writer out){\n        this.out = new PrintWriter(out);\n    }\n\n    public OutputWriter(OutputStream out){\n        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));\n    }\n    \n    public void close(){\n        out.flush();\n        out.close();\n    }\n\n    public void writeln(Object ... o){\n        for(Object x : o) out.print(x);\n        out.println();\n    }\n}\n\nclass ArrayUtils{\n    private final static Random random = new Random(System.nanoTime());\n    \n    public static void randomShuffle(int a[]){\n        int n = a.length;\n        for(int i=0;i<n;++i){\n            int j = random.nextInt(n-i);\n            int t = a[i]; a[i] = a[j]; a[j] = t;\n        }\n    }\n}\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Locale;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.RandomAccess;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.List;\nimport java.io.IOException;\nimport java.math.BigDecimal;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\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 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\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();\n        int[] a = in.nextIntArray(n);\n        int[] b = a.clone();\n        ArrayUtils.safeSort(b);\n        int diff = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i] != b[i])\n                diff++;\n        }\n        out.println(diff <= 2 ? \"YES\" : \"NO\");\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 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 & 15;\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    public int[] nextIntArray(int count) {\n        int[] result = new int[count];\n        for (int i = 0; i < count; i++) {\n            result[i] = nextInt();\n        }\n        return result;\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(String x) {\n        writer.println(x);\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    }\n\nclass ArrayUtils {\n\n\n\n    public static List<Integer> asList(int[] array) {\n        return new IntList(array);\n    }\n\n    private static class IntList extends AbstractList<Integer> implements RandomAccess {\n\n        int[] array;\n\n        private IntList(int[] array) {\n            this.array = array;\n        }\n\n        public Integer get(int index) {\n            return array[index];\n        }\n\n        public Integer set(int index, Integer element) {\n            int result = array[index];\n            array[index] = element;\n            return result;\n        }\n\n        public int size() {\n            return array.length;\n        }\n    }\n\n    public static void safeSort(int[] array) {\n        Collections.shuffle(asList(array));\n        Arrays.sort(array);\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A {\n\n    final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    class Pointd implements Comparable<Pointd>{\n        int x, in;\n\n        @Override\n        public int compareTo(Pointd o) {\n            if(x > o.x) return 1;\n            if(x < o.x) return -1;\n            if(in < o.in) return -1;\n            if(in > o.in) return 1;\n            return 0;\n        }\n\n        public Pointd(int x, int in) {\n            super();\n            this.x = x;\n            this.in = in;\n        }\n    }\n    \n    void solve() throws IOException {\n        int n = readInt();\n        Pointd[] a = new Pointd[n];\n        for(int i = 0; i < n; i++){\n            a[i] = new Pointd(readInt(), i);\n        }\n        Arrays.sort(a);\n        \n        int count = 0;\n        for(int i = 0; i < n; i++){\n            if(a[i].x != a[a[i].in].x) count++;\n        }\n        if(count == 0 || count == 2) out.println(\"YES\");\n        else out.println(\"NO\");\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 A().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}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\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        int testCount = 1;\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n}\n\nclass Task {\n    int n;\n    int[] a;\n    int[] b;\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        n = in.readInt();\n        a = new int[n];\n        b = new int[n];\n        for (int i = 0; i < n; ++i)\n            a[i] = b[i] = in.readInt();\n        sort(0, n - 1);\n        int different = 0;\n        for (int i = 0; i < n; ++i)\n            if (a[i] != b[i])\n                ++different;\n        out.println(different <= 2 ? \"YES\" : \"NO\");\n    }\n\n    public void sort(int lo, int hi) {\n        if (lo < hi) {\n            int mid = (lo + hi) / 2;\n            sort(lo, mid);\n            sort(mid + 1, hi);\n            merge(lo, mid, hi);\n        }\n    }\n\n    public void merge(int lo, int mid, int hi) {\n        int n1 = mid - lo + 1;\n        int n2 = hi - (mid + 1) + 1;\n        int[] x = new int[n1 + 1];\n        int[] y = new int[n2 + 1];\n        for (int i = 0; i < n1; ++i)\n            x[i] = b[lo + i];\n        for (int j = 0; j < n2; ++j)\n            y[j] = b[mid + 1 + j];\n        x[n1] = y[n2] = Integer.MAX_VALUE;\n        for (int k = lo, i = 0, j = 0; k <= hi; ++k)\n            b[k] = x[i] < y[j] ? x[i++] : y[j++];\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 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    public Long readLong() {\n        return Long.parseLong(readString());\n    }\n\n    public Double readDouble() {\n        return Double.parseDouble(readString());\n    }\n\n    public static boolean isSpaceChar(int c) {\n        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class r220a {\n\tpublic static void main(String args[]) {\n\t\tScanner in =new Scanner(System.in);\n\t\tint N = in.nextInt();\n\t\tArrayList<Integer> list = new ArrayList<Integer>();\n\t\tArrayList<Integer> sort = new ArrayList<Integer>();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint k = in.nextInt();\n\t\t\tlist.add(k);\n\t\t\tsort.add(k);\n\t\t}\n\t\t\n\t\tCollections.sort(sort);\n\t\t\n\t\tint count = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tif(sort.get(i).intValue() != list.get(i).intValue())\n\t\t\t\tcount++;\n\t\t}\n\t\tif(count != 2 && count != 0)\n\t\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t\tSystem.out.println(\"YES\");\n\t}\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\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.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Iterator;\nimport java.util.NoSuchElementException;\nimport java.util.Random;\nimport java.util.TreeSet;\n\n/**\n * Actual solution is at the top, in class Solver\n */\npublic class Main implements Runnable {\n\tprivate static String[] args;\n\n\tpublic static void main(String[] args) {\n\t\tMain.args = args;\n\t\tnew Thread(null, new Main(), \"MyRunThread\", 1 << 26).start();\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\tlong time_beg = -1;\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tif (args.length > 0 && args[0].equals(\"outside\")) {\n\t\t\ttime_beg = System.currentTimeMillis();\n\t\t\ttry {\n\t\t\t\tinputStream = new FileInputStream(\"IO/in.txt\");\n//\t\t\t\toutputStream = new FileOutputStream(\"IO/out.txt\");\n\t\t\t} catch (Exception e) {\n\t\t\t\tSystem.err.println(e);\n\t\t\t\tSystem.exit(1);\n\t\t\t}\n\t\t} else {\n\t\t\ttry {\n//\t\t\t\tinputStream = new FileInputStream(\"file_name\");\n//\t\t\t\toutputStream = new FileOutputStream(\"file_name\");\n\t\t\t} catch (Exception e) {\n\t\t\t\tSystem.err.println(e);\n\t\t\t\tSystem.exit(1);\n\t\t\t}\n\t\t}\n\n\t\tSolver s = new Solver();\n\t\ts.in = new InputReader(inputStream);\n\t\ts.out = new OutputWriter(outputStream);\n\t\tif (args.length > 0 && args[0].equals(\"outside\")) {\n\t\t\ts.debug = new DebugWriter(s.out);\n\t\t}\n\n\t\ts.solve();\n\t\ts.out.close();\n\n\t\tif (args.length > 0 && args[0].equals(\"outside\")) {\n\t\t\ts.debug.close();\n\t\t\tSystem.err.printf(\"*** Total time: %.3f ***\\n\", (System.currentTimeMillis() - time_beg) / 1000.0);\n\t\t}\n\t}\n}\n\nfinal class Solver {\n\tInputReader in;\n\tOutputWriter out;\n\tDebugWriter debug;\n\n\tpublic void solve() {\n\t\tint n = in.readInt();\n\t\tint[] mas = new int[n];\n\t\tint[] sorted = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tsorted[i] = mas[i] = in.readInt();\n\n\t\tRandom rnd = new Random(System.nanoTime());\n\t\tfor (int i = 1; i < n; ++i) {\n\t\t\tint j = rnd.nextInt(i);\n\t\t\tint tmp = sorted[j];\n\t\t\tsorted[j] = sorted[i];\n\t\t\tsorted[i] = tmp;\n\t\t}\n\n\t\tArrays.sort(sorted);\n\n\t\tint id1 = -1;\n\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tif (mas[i] != sorted[i]) {\n\t\t\t\tid1 = i;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\tint id2 = -1;\n\n\t\tfor (int i = n - 1; i >= 0; --i)\n\t\t\tif (mas[i] != sorted[i]) {\n\t\t\t\tid2 = i;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\tif (id1 != -1 && id2 != -1 && id1 != id2) {\n\t\t\tint tmp = mas[id1];\n\t\t\tmas[id1] = mas[id2];\n\t\t\tmas[id2] = tmp;\n\t\t}\n\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tif (mas[i] != sorted[i]) {\n\t\t\t\tout.printLine(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\tout.printLine(\"YES\");\n\t}\n}\nclass InputReader {\n\tprivate boolean finished = false;\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tprivate int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int peek() {\n\t\tif (numChars == -1)\n\t\t\treturn -1;\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\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\tprivate String readLine0() {\n\t\tStringBuilder buf = new StringBuilder();\n\t\tint c = read();\n\t\twhile (c != '\\n' && c != -1) {\n\t\t\tif (c != '\\r')\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}\n\t\treturn buf.toString();\n\t}\n\n\tpublic String readLine() {\n\t\tString s = readLine0();\n\t\twhile (s.trim().length() == 0)\n\t\t\ts = readLine0();\n\t\treturn s;\n\t}\n\n\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\tif (ignoreEmptyLines)\n\t\t\treturn readLine();\n\t\telse\n\t\t\treturn readLine0();\n\t}\n\n\tpublic BigInteger readBigInteger() {\n\t\ttry {\n\t\t\treturn new BigInteger(readString());\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isExhausted() {\n\t\tint value;\n\t\twhile (isSpaceChar(value = peek()) && value != -1)\n\t\t\tread();\n\t\treturn value == -1;\n\t}\n}\n\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 printFormat(String format, Object... objects) {\n\t\twriter.printf(format, objects);\n\t}\n\n\n\tpublic void print(char[] objects) {\n\t\twriter.print(objects);\n\t}\n\n\tpublic void printLine(char[] objects) {\n\t\twriter.println(objects);\n\t}\n\n\tpublic void printLine(char[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(int[] 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(int[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(int[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(long[] 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(long[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(long[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(double[] 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(double[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(double[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(byte[] 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(byte[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(byte[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\n\n\tpublic void print(boolean[] 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(boolean[] objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(boolean[][] objects) {\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t}\n\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 DebugWriter {\n\tprivate final OutputWriter writer;\n\n\tpublic DebugWriter(OutputWriter writer) {\n\t\tthis.writer = writer;\n\t}\n\n\tprivate void printDebugMessage() {\n\t\twriter.print(\"debug:\\t\");\n\t}\n\n\n\tpublic void printLine(Object... objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printFormat(String format, Object... objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printFormat(format, objects);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(char[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(char[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(double[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(double[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(int[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(int[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(long[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(long[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(byte[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(byte[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void printLine(boolean[] objects) {\n\t\tflush();\n\t\tprintDebugMessage();\n\t\twriter.printLine(objects);\n\t\tflush();\n\t}\n\n\tpublic void printLine(boolean[][] objects) {\n\t\tflush();\n\t\tfor (int i = 0; i < objects.length; ++i)\n\t\t\tprintLine(objects[i]);\n\t\tflush();\n\t}\n\n\n\tpublic void flush() {\n\t\twriter.flush();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\n\n\n    void solve()throws Exception\n    {\n\n        int n=nextInt();\n\n        int[]a=new int[n];\n        for(int i=0;i<n;i++)\n            a[i]=nextInt();\n\n        ArrayList<Integer>list=new ArrayList<Integer>();\n        for(int i=0;i<n;i++)\n            list.add(a[i]);\n        Collections.shuffle(list);\n        int[]b=new int[n];\n        for(int i=0;i<n;i++)\n            b[i]=list.get(i);\n        Arrays.sort(b);\n        int cnt=0;\n        for(int i=0;i<n;i++)\n            if(a[i]!=b[i])\n                cnt++;\n        if(cnt<=2)\n            System.out.println(\"YES\");\n        else\n            System.out.println(\"NO\");\n\n    }\n\n    private void mySort(int[] a) {\n        if(a.length<=1)\n            return;\n        int n=a.length;\n        int[]left=new int[n/2];\n        int[]right=new int[n-n/2];\n        for(int i=0;i<n;i++)\n            if(i<left.length)\n                left[i]=a[i];\n            else\n                right[i-left.length]=a[i];\n        mySort(left);\n        mySort(right);\n        int i=0;\n        int j=0;\n        while (i<left.length || j<right.length)\n        {\n            if(i==left.length)\n                a[i+j]=right[j++];\n            else if(j==right.length)\n                a[i+j]=left[i++];\n            else if(left[i]<right[j])\n                a[i+j]=left[i++];\n            else\n                a[i+j]=right[j++];\n        }\n\n    }\n\n    ////////////\n    BufferedReader reader;\n    PrintWriter writer;\n    StringTokenizer stk;\n    void run()throws Exception\n    {\n\n        reader=new BufferedReader(new InputStreamReader(System.in));\n        // reader=new BufferedReader(new FileReader(\"input.txt\"));\n        stk=null;\n        //writer=new PrintWriter(new PrintWriter(System.out));\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 Solution().run();\n    }\n\n\n\n\n\n\n\n\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class test1\n{\n\n    public static void main(String[] args)\n    {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int a[]=new int[n];\n        int b[]=new int[n];\n        for(int i=0;i<n;i++)\n        {\n            a[i]=in.nextInt();\n            b[i]=a[i];\n        }\n        Arrays.sort(b);\n        int count=0;\n        for(int i=0;i<n;i++)\n            if(a[i]!=b[i])\n                count++;\n        if(count<=2)\n            System.out.println(\"YES\");\n        else\n            System.out.println(\"NO\");\n    }\n    \n \n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Problem220A {\n    static int[] numbers;\n    static int[] numbersCopy;\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        int i = Integer.parseInt(in.readLine());\n        numbers = new int[i];\n        numbersCopy = new int[i];\n        StringTokenizer stringTokenizer = new StringTokenizer(in.readLine());\n        int numOutOfPlace = 0;\n        for (int j = 0; j < i; j++) {\n            numbers[j] = Integer.parseInt(stringTokenizer.nextToken());\n            numbersCopy[j] = numbers[j];\n        }\n        Arrays.sort(numbers);\n        for (int j = 0; j < i; j++) {\n            if (numbers[j] != numbersCopy[j]) {\n                numOutOfPlace++;\n                if (numOutOfPlace > 2) {\n                    break;\n                }\n            }\n        }\n        if (numOutOfPlace == 0 || numOutOfPlace == 2) {\n            System.out.println(\"YES\");\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class LittleElephant {\n\tpublic static void main(String[] args){\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt(); \n\t\tint temp;\n\t\tArrayList<Integer> a2 = new ArrayList<Integer>();\n\t\tArrayList<Integer> a1 = new ArrayList<Integer>();\n\t\tint count = 0;\n\t\tint temp1,temp2;\n\t\t\n\t\tfor(int i= 0; i < n ; i++){\n\t\t\ttemp = input.nextInt();\n\t\t\ta2.add(temp);\n\t\t\ta1.add(temp);\n\t\t}\n\t\tCollections.sort(a2);\n\t\tinput.close();\n\t\tfor(int i = 0; i < n; i++){\n\t\t\ttemp1 = a2.get(i);\n\t\t\ttemp2 = a1.get(i);\n\t\t\tif(temp1 != temp2){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tif(count==2 || count==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}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\n\n\nimport java.util.*;\n\npublic class Solution{\n\n\n    void solve()throws Exception\n    {\n\n        int n=nextInt();\n\n        int[]a=new int[n];\n        for(int i=0;i<n;i++)\n            a[i]=nextInt();\n        int[]b=a.clone();\n        Arrays.sort(b);\n        int cnt=0;\n        for(int i=0;i<n;i++)\n            if(a[i]!=b[i])\n                cnt++;\n        if(cnt<=2)\n            System.out.println(\"YES\");\n        else\n            System.out.println(\"NO\");\n\n\n\n\n\n\n    }\n\n    private boolean sorted(int[] a) {\n        for(int i=0;i+1<a.length;i++)\n            if(a[i]>a[i+1])\n                return false;\n        return true;\n    }\n\n\n    ////////////\n    BufferedReader reader;\n    PrintWriter writer;\n    StringTokenizer stk;\n    void run()throws Exception\n    {\n\n        reader=new BufferedReader(new InputStreamReader(System.in));\n        // reader=new BufferedReader(new FileReader(\"input.txt\"));\n        stk=null;\n        writer=new PrintWriter(new PrintWriter(System.out));\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 Solution().run();\n    }\n\n\n\n\n\n\n\n\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n   static class Scanner {\n      StreamTokenizer in;\n      boolean forceMode = false;\n\n      Scanner(InputStream is, String codePage, boolean forceMode) {\n         in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));\n         if (!forceMode) {\n            in.resetSyntax();\n            in.wordChars(33, 255);\n            in.whitespaceChars(0, 32);\n         }\n      }\n\n      Scanner(InputStream is, String codePage) {\n         in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));\n         if (!forceMode) {\n            in.resetSyntax();\n            in.wordChars(33, 255);\n            in.whitespaceChars(0, 32);\n         }\n      }\n\n      String next() {\n         try {\n            in.nextToken();\n            return in.sval;\n         } catch (Exception e) {\n            throw new Error();\n         }\n      }\n\n      int nextInt() {\n         if (forceMode) {\n            try {\n               in.nextToken();\n               return (int) in.nval;\n            } catch (Exception e) {\n               throw new Error();\n            }\n         } else {\n            return Integer.parseInt(next());\n         }\n      }\n\n      long nextLong() {\n         if (forceMode) {\n            throw new Error(\"No long at force mod!\");\n         } else {\n            return Long.parseLong(next());\n         }\n\n      }\n\n      double nextDouble() {\n         if (forceMode) {\n            try {\n               in.nextToken();\n               return in.nval;\n            } catch (Exception e) {\n               throw new Error();\n            }\n         } else {\n            return Double.parseDouble(next());\n         }\n      }\n   }\n\n   static class Assertion {\n      static void checkRE(boolean e) {\n         if (!e) {\n            throw new Error();\n         }\n      }\n\n      static void checkTL(boolean e) {\n         if (!e) {\n            int idx = 1;\n            while (idx > 0) {\n               idx++;\n            }\n         }\n      }\n   }\n\n   Scanner in;\n   PrintWriter out;\n\n   class Int implements Comparable<Int> {\n      int value;\n      int pos;\n\n      public Int(int value, int pos) {\n         this.value = value;\n         this.pos = pos;\n      }\n\n      @Override\n      public int compareTo(Int second) {\n         if (this.value == second.value) {\n            return this.pos - second.pos;\n         } else {\n            return this.value - second.value;\n         }\n      }\n   }\n\n   void solve() {\n      int n = in.nextInt();\n      Int ar[] = new Int[n];\n      for (int i = 0; i < ar.length; i++) {\n         ar[i] = new Int(in.nextInt(), i);\n      }\n      Arrays.sort(ar);\n      int cnt = 0;\n      for (int i = 0; i < ar.length; i++) {\n         if (ar[i].value!=ar[ar[i].pos].value) {\n            cnt++;\n         }\n      }\n      if (cnt == 2 || cnt == 0) {\n         out.println(\"YES\");\n      } else {\n         out.println(\"NO\");\n      }\n\n   }\n\n   final static String fileName = \"\";\n\n   void run() {\n      // try {\n      // in = new Scanner(new FileInputStream(fileName + \".in\"), \"ISO-8859-1\");\n      // out = new PrintWriter(fileName + \".out\", \"ISO-8859-1\");\n      // } catch (FileNotFoundException e) {\n      // throw new Error(e);\n      //\n      // } catch (UnsupportedEncodingException e) {\n      // throw new Error(e);\n      // }\n      in = new Scanner(System.in, \"\");\n      out = new PrintWriter(System.out);\n      try {\n         solve();\n      } catch (Exception e) {\n         throw new Error(e);\n      } finally {\n         out.close();\n      }\n   }\n\n   public static void main(String[] args) {\n      new Main().run();\n   }\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n    static BufferedReader in;\n    static PrintWriter out;\n    static StringTokenizer st;\n    static Random rnd;\n\n    void solve() throws IOException {\n        int n = nextInt();\n\n        int[] arr = new int[n];\n        Integer[] arrCopy = new Integer[n];\n\n        for (int i = 0; i < n; i++)\n            arr[i] = arrCopy[i] = nextInt();\n\n        Arrays.sort(arrCopy);\n\n        int bad = 0;\n\n        for (int i = 0; i < n; i++)\n            if (arr[i] != arrCopy[i])\n                ++bad;\n\n        boolean fail = bad > 2;\n\n        out.println(!fail ? \"YES\" : \"NO\");\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n\n            rnd = new Random();\n\n            solve();\n\n            out.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n            System.exit(42);\n        }\n    }\n\n    String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            String line = in.readLine();\n\n            if (line == null)\n                return null;\n\n            st = new StringTokenizer(line);\n        }\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}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import 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;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.List;\n\n/*\n * @author Ivan Pryvalov (ivan.pryvalov@gmail.com)\n */\npublic class Codeforces_R136_Div1_A implements Runnable{\n\t\n\tprivate void solve() throws IOException {\n\t\tint n = scanner.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = scanner.nextInt();\n\t\t}\n\t\t\n\t\tboolean sorted = true;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif (!isOk(a, i)){\n\t\t\t\tsorted = false;\n\t\t\t}\n\t\t}\n\t\tif (sorted){\n\t\t\tout.println(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tList<Integer> idx = new ArrayList<Integer>();\t\t\n\t\tfor(int i=0; i<n; i++){\n\t\t\tif (!isOk(a, i)){\t\t\n\t\t\t\tidx.add(i);\t\t\t\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (idx.size() > 6){\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor(int i=0; i<idx.size(); i++){\n\t\t\tfor(int j=0; j<n; j++){\n\t\t\t\tswap(a, idx.get(i), j);\n\t\t\t\tif (isOk(a, idx) && isOk(a, j)){\n\t\t\t\t\tout.println(\"YES\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tswap(a, idx.get(i), j);\n\t\t\t}\n\t\t}\n\t\tout.println(\"NO\");\t\t\t\t\n\t}\n\n\tprivate boolean isOk(int[] a, int i) {\t\t\n\t\tboolean ordered = true; \n\t\tif (i>0 && !(a[i-1] <= a[i])){\n\t\t\tordered = false;\n\t\t}\n\t\tif (i<a.length-1 && !(a[i]<=a[i+1])){\n\t\t\tordered = false;\n\t\t}\n\t\treturn ordered;\n\t}\n\n\tprivate boolean isOk(int[] a, List<Integer> idx) {\n\t\tfor(int i : idx){\n\t\t\tif (!isOk(a, i))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate void swap(int[] a, int i, int j) {\n\t\tint tmp = a[i];\n\t\ta[i] = a[j];\n\t\ta[j] = tmp;\n\t}\n\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.<br>\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.<br>\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            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<totalBytes; i++){\n\t\t\t\tnum*=10;\n\t\t\t\tnum+=byteBuf[i]-ZERO;\n\t\t\t}\n\t\t\treturn sign?-num:num;\n\t\t}\n\t\t\n\t\tpublic long nextLong() throws IOException{\n\t\t\treadToken();\n\t\t\tlong num=0;\n\t\t\tint 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<totalBytes; i++){\n\t\t\t\tnum*=10;\n\t\t\t\tnum+=byteBuf[i]-ZERO;\n\t\t\t}\n\t\t\treturn sign?-num:num;\n\t\t}\n\t\t\n\t\t/*\n\t\t//TODO test Unix/Windows formats\n\t\tpublic void toNextLine() throws IOException{\n\t\t\twhile ((ch=nextChar())!='\\n');\n\t\t}\n\t\t*/\n\t\t\n\t\tpublic double nextDouble() throws IOException{\n\t\t\treadToken();\n\t\t\tchar[] token = new char[totalBytes];\n\t\t\tfor (int i = 0; i < totalBytes; i++) {\n\t\t\t\ttoken[i] = (char)byteBuf[i];\n\t\t\t}\n\t\t\treturn Double.parseDouble(new String(token));\n\t\t}\n\t    \n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Codeforces_R136_Div1_A().run();\n\t}\n\t\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.util.Collection;\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\nclass TaskA {\n    public void solve(int testNumber, MyScanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int[] as = new int[n];\n        for (int i = 0; i < n; i++) as[i] = in.nextInt();\n        int[] sorted = as.clone();\n        ArrayUtils.sort(sorted);\n        int diff = 0;\n        for (int i = 0; i < n; i++)if(as[i]!=sorted[i])diff++;\n        if(diff<=2)out.println(\"YES\");\n        else out.println(\"NO\");\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        try{\n            int c=in.read();\n            if(c==-1) return c;\n            while(c!='-'&&(c<'0'||'9'<c)){\n                c=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=in.read();\n            }while('0'<=c&&c<='9');\n            return res;\n        }catch(Exception e){\n            return -1;\n        }\n    }\n\n\n    }\n\nclass ArrayUtils {\n\n    public static void swap(int[] is, int i, int j) {\n        int t = is[i];\n        is[i] = is[j];\n        is[j] = t;\n    }\n\n    public static void shuffle(int[] S) {\n        Random rnd = r == null ? (r = new Random()) : r;\n        shuffle(S, rnd);\n    }\n\n    private static Random r;\n    private static void shuffle(int[] S, Random rnd) {\n        for (int i = S.length; i > 1; i--)\n            swap(S, i - 1, rnd.nextInt(i));\n    }\n\n\n    public static void sort(int[] a) {\n        shuffle(a);\n        Arrays.sort(a);\n    }\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "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 Sunits789\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n=in.nextInt();\n        int arr[]=new int[n];\n        in.getArray(arr);\n        int arrc[]=new int[n];\n        for(int i=0;i<n;i++){\n            arrc[i]=arr[i];\n        }\n        Library.sort(arrc);\n        int c=0;\n        for(int i=0;i<n;i++){\n            if(arrc[i]!=arr[i]){\n                c++;\n            }\n        }\n        if(c>2){\n            out.println(\"NO\");\n        }\n        else{\n            out.println(\"YES\");\n        }\n\t}\n}\n\nclass InputReader{\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream){\n        reader = new BufferedReader(new InputStreamReader(stream));\n        tokenizer = null;\n    }\n    public String next(){\n        while (tokenizer == null||!tokenizer.hasMoreTokens()){\n            try{\n                tokenizer = new StringTokenizer(reader.readLine());\n            }\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 void getArray(int arr[]){\n        for(int i=0;i<arr.length;i++){\n            arr[i]=nextInt();\n        }\n    }\n\n    }\n\nclass Library{\n    public static void sort(int n[]){\n        int len=n.length;\n        int l1=len/2;\n        int l2=len-l1;\n        int n1[]=new int[l1];\n        int n2[]=new int[l2];\n        for(int i=0;i<l1;i++){\n            n1[i]=n[i];\n        }\n        for(int i=0;i<l2;i++){\n            n2[i]=n[i+l1];\n        }\n        if(l1!=0){\n            sort(n1);\n            sort(n2);\n        }\n        int ind1=0;\n        int ind2=0;\n        int ind=0;\n        for(int i=0;i<len&&ind1<l1&&ind2<l2;i++){\n            if(n1[ind1]<n2[ind2]){\n                n[i]=n1[ind1];\n                ind1++;\n            }\n            else{\n                n[i]=n2[ind2];\n                ind2++;\n            }\n            ind++;\n        }\n        if(ind1<l1){\n            for(int i=ind1;i<l1;i++){\n                n[ind]=n1[i];\n                ind++;\n            }\n        }\n        if(ind2<l2){\n            for(int i=ind2;i<l2;i++){\n                n[ind]=n2[i];\n                ind++;\n            }\n        }\n    }\n    \n    }\n\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A {\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tint[] b = a.clone();\n\t\tArrays.sort(b);\n\t\tint k = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i] != b[i]) {\n\t\t\t\tk++;\n\t\t\t}\n\t\t}\n\t\tif (k <= 2) {\n\t\t\tout.println(\"YES\");\n\t\t} else {\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\t// br = new BufferedReader(new FileReader(\"G.in\"));\n\t\t\t// out = new PrintWriter(\"G.out\");\n\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 A().run();\n\t}\n\n\tpublic String nextToken() 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(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}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\n\n\n    void solve()throws Exception\n    {\n\n        int n=nextInt();\n\n        int[]a=new int[n];\n        for(int i=0;i<n;i++)\n            a[i]=nextInt();\n\n        int[]b=a.clone();\n        mySort(b);\n        int cnt=0;\n        for(int i=0;i<n;i++)\n            if(a[i]!=b[i])\n                cnt++;\n        if(cnt<=2)\n            System.out.println(\"YES\");\n        else\n            System.out.println(\"NO\");\n\n    }\n\n    private void mySort(int[] a) {\n        if(a.length<=1)\n            return;\n        int n=a.length;\n        int[]left=new int[n/2];\n        int[]right=new int[n-n/2];\n        for(int i=0;i<n;i++)\n            if(i<left.length)\n                left[i]=a[i];\n            else\n                right[i-left.length]=a[i];\n        mySort(left);\n        mySort(right);\n        int i=0;\n        int j=0;\n        while (i<left.length || j<right.length)\n        {\n            if(i==left.length)\n                a[i+j]=right[j++];\n            else if(j==right.length)\n                a[i+j]=left[i++];\n            else if(left[i]<right[j])\n                a[i+j]=left[i++];\n            else\n                a[i+j]=right[j++];\n        }\n\n    }\n\n    ////////////\n    BufferedReader reader;\n    PrintWriter writer;\n    StringTokenizer stk;\n    void run()throws Exception\n    {\n\n        reader=new BufferedReader(new InputStreamReader(System.in));\n        // reader=new BufferedReader(new FileReader(\"input.txt\"));\n        stk=null;\n        //writer=new PrintWriter(new PrintWriter(System.out));\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 Solution().run();\n    }\n\n\n\n\n\n\n\n\n}", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "//package round136;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class A2 {\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 = new int[n];\n\t\tint[] b = new int[n];\n\t\tfor(int i = 0;i < n;i++)b[i] = a[i] = ni();\n\t\t\n\t\tb = radixSort(b);\n\t\tint ct = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(a[i] != b[i])ct++;\n\t\t}\n\t\tif(ct <= 2){\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 static int[] radixSort(int[] f)\n\t{\n\t\tint[] to = new int[f.length];\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n\t\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n\t\t\tint[] d = f; f = to;to = d;\n\t\t}\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor(int i = 0;i < f.length;i++)b[1+(f[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 < f.length;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\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 A2().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", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\t\n\tScanner in;\n\tstatic PrintWriter out;\n\t\n\tstatic class Scanner {\n\t\tStreamTokenizer in;\n\t\t\n\t\tScanner(InputStream is) {\n\t\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));\n\t\t\t  in.resetSyntax();\n\t\t         in.whitespaceChars(0, 32);\n\t\t         in.wordChars(33, 255);\n\t\t     \n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\ttry {\n\t\t\t\tin.nextToken();\n\t\t\t\treturn Integer.parseInt(in.sval);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new Error();\n\t\t\t}\n\t\t}\n\t\t\n\t\tString next() {\n\t\t\ttry {\n\t\t\t\tin.nextToken();\n\t\t\t\treturn in.sval;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new Error();\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\t\n\tstatic class Value implements Comparable <Value> {\n\t\tint x;\n\t\tint pos;\n\t\t\n\t\tValue(int x, int pos) {\n\t\t\tthis.x = x;\n\t\t\tthis.pos = pos;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Value second) {\n\t\t\tif (this.x == second.x) {\n\t\t\t\treturn this.pos - second.pos;\n\t\t\t} else {\n\t\t\t\treturn this.x - second.x;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\t\n\t\tValue ar[] = new Value[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tar[i] = new Value(in.nextInt(), i);\n\t\t}\n\t\tArrays.sort(ar);\n\t\tint cnt = 0;\n\t\t//LinkedList <Integer> gavno = new LinkedList<Integer>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (ar[i].pos != i && ar[ar[i].pos].x != ar[i].x) {\n\t\t\t\tcnt++;\n\t\t\t\t//gavno.add(i);\n\t\t\t}\n\t\t}\n\t\tif (cnt > 2) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t}\n\t}\n\t\n\tstatic void asserT(boolean e) {\n\t\tif (!e) {\n\t\t\tthrow new Error();\n\t\t}\n\t}\n\t\n\t\n\tpublic void run() {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\ttry {\n\t\t\tsolve();\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n} ", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport static java.lang.Math.*;\n\npublic class CF220A {\n    public static void main(String[] args) throws Exception {\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        Integer[] B = new Integer[n];\n        for(int i=0; i<n; i++) {\n            A[i] = Integer.parseInt(st.nextToken());\n            B[i] = A[i];\n        }\n        Collections.sort(Arrays.asList(B));\n\n        int cnt = 0;\n        for(int i=0; i<n; i++)\n            if(A[i] != B[i])\n                cnt++;\n        System.out.println(cnt <= 2 ? \"YES\" : \"NO\");\n    }\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * User: serparamon\n */\npublic class Codeforces_2012_08_31_A {\n\n    public static void main(String[] args) throws IOException {\n        //Scanner in = new Scanner(System.in);\n        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        PrintWriter out = new PrintWriter(System.out);\n        in.nextToken();\n        int n = (int) in.nval;\n        int[] a = new int[n];\n        for (int i=0; i<n; i++) {\n            in.nextToken();\n            a[i] = (int) in.nval;\n        }\n        int[] b = Arrays.copyOf(a, n);\n        Arrays.sort(a);\n        int k = 0;\n        for (int i=0; i<n; i++) {\n            if (a[i] != b[i]) k++;\n        }\n        if (k==0 || k==2)\n            out.println(\"YES\");\n        else\n            out.println(\"NO\");\n        out.flush();\n        out.close();\n    }\n\n}\n", "complexity": "nlogn", "problem": "220_A. Little Elephant and Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n    static int n;\n     static long TotalTime;\n    static Problem[] problems;\n    static StringBuilder sb;\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        sb = new StringBuilder();\n        n = sc.nextInt();\n        TotalTime = sc.nextLong();\n        problems = new Problem[n];\n        for (int i = 0; i < n; i++) {\n            problems[i] = new Problem (sc.nextInt(), sc.nextLong(), i);\n        }\n        Arrays.sort(problems);\n        long num = -1;\n        long high = n;\n        long low = 0;\n        int iter = 0;\n        while (high - low > 1) {\n            num = (high + low) / 2;\n            if (test(num, false)) {\n                low = num;\n            }\n            else {\n                high = num;\n            }\n        }\n        if (test(high, false))\n            num = high;\n        else\n            num = low;\n        test(num, true);\n        System.out.print(sb);\n    }\n\n    public static boolean test (long num, boolean print) {\n        int count = 0;\n        long sum = 0L;\n        if (print) sb.append(num + \"\\n\" + num + \"\\n\");\n        for (int i = 0; i < n && count < num; i++) {\n            if (problems[i].a >= num) {\n                count++;\n                sum += problems[i].t;\n                if (print) sb.append((problems[i].index + 1) + \" \");\n            }\n        }\n        return (count == num) && (sum <= TotalTime);\n    }\n\n    public static class Problem implements Comparable<Problem>  {\n        int a;\n        long t;\n        int index;\n        \n        public int compareTo(Problem o) {\n          return Long.compare(t, o.t);\n        }\n        public Problem (int a, long t, int index) {\n            this.a = a;\n            this.t = t;\n            this.index = index;\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}", "complexity": "nlogn", "problem": "913_D. Too Easy Problems", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigInteger;\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 p1096f {\n    static long MOD = 998244353;\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        BIT invert = new BIT(n+5);\n        BIT neg = new BIT(n+5);\n        long res = 0;\n        int[] arr = new int[n];\n        boolean[] has = new boolean[n+1];\n        long num1 = 0;\n        for(int i = 0; i < n; i++) {\n            arr[i] = in.nextInt();\n            if(arr[i] != -1) {\n                res += invert.read(n+5)-invert.read(arr[i]);\n                res %= MOD;\n                invert.update(arr[i], 1);\n                has[arr[i]] = true;\n            } else num1++;\n        }\n        if(num1 == 0) {\n            System.out.println(res);\n            return;\n        }\n        for(int i = 1; i <= n; i++) if(!has[i]) neg.update(i, 1);\n        long invertNum1 = modInv(num1, MOD);\n        res += ((num1*(num1-1))%MOD)*modInv(4, MOD);\n        res %= MOD;\n        long cnt = 0;\n        for(int i = 0; i < n; i++) {\n            if(arr[i] == -1) {\n                cnt++;\n                continue;\n            }\n            res += (((neg.read(n+5)-neg.read(arr[i]))*cnt)%MOD)*invertNum1;\n            res %= MOD;\n        }\n        cnt = 0;\n        for(int i = n-1; i >= 0; i--) {\n            if(arr[i] == -1) {\n                cnt++;\n                continue;\n            }\n            res += (((neg.read(arr[i]))*cnt)%MOD)*invertNum1;\n            res %= MOD;\n        }\n        System.out.println(res);\n    }\n    \n    //@\n    static class BIT {\n            int n;\n            int[] tree;\n            public BIT(int n) {\n                    this.n = n;\n                    tree = new int[n + 1];\n            }\n\n            int read(int i) {\n                    int sum = 0;\n                    while (i > 0) {\n                            sum += tree[i];\n                            i -= i & -i;\n                    }\n                    return sum;\n            }\n\n            void update(int i, int val) {\n                    while (i <= n) {\n                            tree[i] += val;\n                            i += i & -i;\n                    }\n            }\n            //$\n    }\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        return (BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod))).longValue();\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    \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", "complexity": "nlogn", "problem": "1096_F. Inversion Expectation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n    public static void main(String[] args){\n        try {\n            new Main().solve();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n    ArrayList<Edge>[]edge;\n    int n,m,cnt=0;\n    int ord;\n    int[]order;int[]vis;\n    Edge[] e;\n    private void solve() throws Exception{\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        n=in.nextInt();m=in.nextInt();\n        edge=new ArrayList[n+1];\n        e=new Edge[m];\n        vis=new int[n+1];\n        order=new int[n+1];\n        for(int i=1;i<=n;i++){\n            edge[i]=new ArrayList<>();\n        }\n        for(int i=1;i<=m;i++){\n            int s=in.nextInt(),t=in.nextInt(),c=in.nextInt();\n            edge[s].add(new Edge(s,t,c,i));\n        }\n        int l=0,r=1000000000;\n        while (l<r){\n            int mid=(l+r)>>>1;\n            if(judge(mid,false))r=mid;\n            else l=mid+1;\n        }\n        out.print(l+\" \");\n        judge(l,true);\n        Arrays.sort(e,0,cnt,Comparator.comparingInt(x->x.id));\n        int ans=0;\n        int[]a=new int[m];\n        for(int i=0;i<cnt;i++){\n            if(order[e[i].s]<order[e[i].t])a[ans++]=e[i].id;\n        }\n        out.println(ans);\n        for(int i=0;i<ans;i++){\n            out.print(a[i]+\" \");\n        }\n        out.println();\n        out.flush();\n    }\n    boolean judge(int min,boolean mod){\n        Arrays.fill(vis,0);\n        cycle=false;\n        for(int i=1;i<=n;i++){\n            if(vis[i]==0){\n                dfs(i,min,mod);\n                if(cycle)return false;\n            }\n        }\n        return true;\n    }\n    boolean cycle=false;\n    void dfs(int cur,int min,boolean mod){\n        if(cycle)return;\n        vis[cur]=1;\n        for(Edge e:edge[cur]){\n            if(e.c<=min){\n                if(mod)this.e[cnt++]=e;\n                continue;\n            }\n            if(vis[e.t]==1){\n                cycle=true;return;\n            }\n            else if(vis[e.t]==0)dfs(e.t,min,mod);\n        }\n        vis[cur]=2;\n        if(mod)order[cur]=ord++;\n    }\n}\nclass Edge{\n    int s,t,c,id;\n    Edge(int a,int b,int c,int d){\n        s=a;t=b;this.c=c;id=d;\n    }\n}\nclass 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 boolean hasNext() throws IOException {\n        int res=tokenizer.nextToken();\n        tokenizer.pushBack();\n        return res!=tokenizer.TT_EOF;\n    }\n}", "complexity": "nlogn", "problem": "1100_E. Andrew and Taxi", "from": "CODEFORCES"}
{"src": "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.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        ReaderFastIO in = new ReaderFastIO(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        DConcatenatedMultiples solver = new DConcatenatedMultiples();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DConcatenatedMultiples {\n        public void solve(int testNumber, ReaderFastIO in, PrintWriter out) {\n\n            Map<Integer, Integer>[] mapMods = new HashMap[11];\n\n            int n = in.nextInt();\n            int k = in.nextInt();\n            int[] a = in.readArrayInt(n);\n\n            for (int i = 0; i < 11; i++) {\n                mapMods[i] = new HashMap<>();\n            }\n\n            for (int i = 0; i < n; i++) {\n                int pot = getPot(a[i]);\n                mapMods[pot].put(a[i] % k, mapMods[pot].getOrDefault(a[i] % k, 0) + 1);\n            }\n\n            long ct = 0;\n\n            for (int i = 0; i < n; i++) {\n\n                int ownPot = getPot(a[i]);\n                long suffix = a[i] * 10L;\n                for (int j = 1; j <= 10; j++) {\n\n                    int mod = (int) (suffix % k);\n                    int comMod = (k - mod) % k;\n                    int qt = mapMods[j].getOrDefault(comMod, 0);\n\n                    if (j == ownPot && (a[i] % k) == comMod) {\n                        qt--;\n                    }\n\n                    ct += qt;\n\n                    suffix = (suffix * 10L) % k;\n                }\n\n            }\n\n            out.println(ct);\n        }\n\n        public int getPot(int x) {\n\n            int ct = 0;\n\n            while (x != 0) {\n                x /= 10;\n                ct++;\n            }\n\n            return ct;\n        }\n\n    }\n\n    static class ReaderFastIO {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public ReaderFastIO() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public ReaderFastIO(InputStream input) {\n            br = new BufferedReader(new InputStreamReader(input));\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        public int[] readArrayInt(int n) {\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\n", "complexity": "nlogn", "problem": "1029_D. Concatenated Multiples", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\npublic class Main {\n    \n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int N = sc.nextInt();\n        long dest = sc.nextLong();\n        long max = (long)N * ((long)N + 1L) / 2L;\n        if (dest < 2 * N - 1 || dest > max) {\n            out.println(\"No\");\n            out.close();\n            return;\n        }\n        int[] d = new int[N + 1];\n        int[] f = new int[N + 1];\n        int K = 1;\n        for (; K <= N; K++) {\n            long dep = 1L, cnt = 1L, c = 1L;\n            long t = 1L;\n            while (cnt < N) {\n                c = c * K;\n                dep++;\n                t += (dep * Math.min(c, N - cnt));\n                cnt += c;\n            }\n            if (t <= dest) break;\n        }\n        out.println(\"Yes\");\n        int dep = 1; long cnt = 1L, c = 1L;\n        long t = 1L;\n        d[1] = 1;\n        while (cnt < N) {\n            dep++; c = c * K; \n            long x = (long)N - cnt;\n            int min;\n            if (c >= x) min = (int)x;\n            else min = (int)c;\n            d[dep] = min;\n            t += (dep * Math.min(c, (long)N - cnt)); cnt += c;\n        }\n        dest -= t;\n        int curDep = dep; int nextDep = dep + 1;\n        while (dest > 0) {\n            if (d[curDep] <= 1) curDep--;\n            d[curDep]--;\n            long next = Math.min(nextDep++, dest + curDep);\n            dest -= ((int)next - curDep);\n            d[(int)next]++;\n        }\n        int first = 1;\n        for (int i = 2; i < nextDep; i++) {\n            int p = 0, fn = first - d[i - 1] + 1;\n            for (int j = first + 1; j <= first + d[i]; j++) {\n                if (p == K) {\n                    fn++; p = 0;\n                }\n                p++; f[j] = fn;\n            }\n            first += d[i];\n        }\n        for (int i = 2; i <= N; i++)\n            out.format(\"%d \", f[i]);\n        out.close();\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                } 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 int[] nextIntArray(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; ++i) {\n                a[i] = nextInt();\n            }\n            return a;\n        }\n        \n        public long[] nextLongArray(int n) {\n            long[] a = new long[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextLong();\n            }\n            return a;\n        }*/\n    }\n}", "complexity": "nlogn", "problem": "1098_C. Construct a tree", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        int[] arr = new int[n];\n        HashMap<Integer, Integer> map = new HashMap<>();\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        for (int i = 0; i < n; i++) {\n            int x = Integer.parseInt(st.nextToken());\n            arr[i] = x;\n            if (!map.containsKey(x)) {\n                map.put(x, 1);\n            } else {\n                map.replace(x, map.get(x) + 1);\n            }\n        }\n        int[] power = new int[31];\n        for (int i = 0; i < 31; i++) {\n            power[i] = 1 << i; // 0 100=4 1000=8 10000=16\n        }\n        int c = 0;\n        for (int i = 0; i < n; i++) {\n        boolean f = false;\n        for (int j = 0; j <= 30; j++) {\n        int check = power[j] - arr[i];\n                if ((map.containsKey(check) && check != arr[i])) {\n                f = true; break;}\n                if((map.containsKey(check) && check == arr[i] && map.get(check) >=2)) {\n                    f = true; break;\n                }\n            }\n            if (!f) {\n                c++;\n            }\n        }\n        System.out.println(c);\n    }\n}", "complexity": "nlogn", "problem": "1005_C. Summarize to the Power of Two", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\n\n\npublic class pr988B {\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\n        int n = Integer.parseInt(br.readLine());\n\n        ArrayList<String> a = new ArrayList<>();\n\n        for (int i = 0; i < n; i++) {\n            a.add(br.readLine());\n        }\n\n        if(solve(n, a)){\n            out.println(\"YES\");\n            for (String s : a) {\n                out.println(s);\n            }\n        }\n        else\n            out.println(\"NO\");\n\n        out.flush();\n        out.close();\n    }\n\n    private static boolean solve(int n, ArrayList<String> a) {\n        a.sort(Comparator.comparingInt(String::length));\n        for (int i = 0; i < n - 1; i++) {\n            if(!a.get(i+1).contains(a.get(i))) return false;\n        }\n        return true;\n    }\n}\n", "complexity": "nlogn", "problem": "988_B. Substrings Sort", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n    static int[] a;\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        a = sc.nextIntArray(n);\n        long inversions = divide(0, n - 1);\n//        out.println(inversions);\n//        System.err.println(Arrays.toString(a));\n        if (n == 5) out.println(\"Petr\");\n        else {\n            if (n % 2 == 0) out.println(inversions % 2 == 0 ? \"Petr\" : \"Um_nik\");\n            else out.println(inversions % 2 != 0 ? \"Petr\" : \"Um_nik\");\n        }\n        out.flush();\n        out.close();\n    }\n\n    static long divide(int b, int e) {\n        if (b == e) return 0;\n        long cnt = 0;\n        int mid = b + e >> 1;\n        cnt += divide(b, mid);\n        cnt += divide(mid + 1, e);\n        cnt += merge(b, mid, e);\n        return cnt;\n    }\n\n    static long merge(int b, int mid, int e) {\n        long cnt = 0;\n        int len = e - b + 1;\n        int[] tmp = new int[len];\n        int i = b, j = mid + 1;\n        for (int k = 0; k < len; k++) {\n            if (i == mid + 1 || (j != e + 1 && a[i] > a[j])) {\n                tmp[k] = a[j++];\n                cnt += (mid + 1 - i);\n            } else tmp[k] = a[i++];\n        }\n        for (int k = 0; k < len; k++)\n            a[b + k] = tmp[k];\n        return cnt;\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\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}", "complexity": "nlogn", "problem": "986_B. Petr and Permutations", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n    static class Data{\n        int x,i;\n        Data(int x,int i){\n            this.x = x;\n            this.i = i;\n        }\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(\"\\\\s\");\n        int N = Integer.parseInt(s[0]);\n        int K = Integer.parseInt(s[1]);\n        s = br.readLine().split(\"\\\\s\");\n        int[] arr = new int[N];\n        for(int i=0;i<N;++i) arr[i] = Integer.parseInt(s[i]);\n        solve(N,K,arr);   \n    }\n    \n    private static void solve(int N,int K,int[] arr){\n       PriorityQueue<Data> pq = new PriorityQueue<Data>(2000,(a,b) -> a.x - b.x == 0 ? b.i - a.i : b.x - a.x);\n       for(int i=0;i<arr.length;++i){\n           pq.offer(new Data(arr[i],i));\n       }\n       \n       int tot_sum = 0;\n       List<Integer> ls = new ArrayList<>();\n       Set<Integer> set = new HashSet<>();\n       \n       for(int i=1;i<=K;++i){\n           Data t = pq.poll();\n           tot_sum += t.x;\n           set.add(t.i);\n       }\n       int last = -1;\n       for(int i =0;i<arr.length;++i){\n           if(set.contains(i)){\n               K--;\n               //System.out.println(i);\n               if(K == 0) ls.add(arr.length-last-1);\n               else ls.add(i-last);\n               last = i;\n           }\n       }\n       \n       System.out.println(tot_sum);\n       int size = ls.size();\n       for(int i=0;i<size;++i){\n           System.out.print(ls.get(i) + \" \");\n       }\n    }\n}", "complexity": "nlogn", "problem": "1006_B. Polycarp's Practice", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class D {\n\n\tstatic final boolean stdin = true;\n\tstatic final String filename = \"\";\n\tstatic FastScanner br;\n\tstatic PrintWriter pw;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tif (stdin) {\n\t\t\tbr = new FastScanner();\n\t\t\tpw = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t} else {\n\t\t\tbr = new FastScanner(filename + \".in\");\n\t\t\tpw = new PrintWriter(new FileWriter(filename + \".out\"));\n\t\t}\n\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(br, pw);\n\t}\n\n\tstatic class Solver {\n\t\tstatic long mod = (long) (1e10);\n\n\t\tpublic void solve(FastScanner br, PrintWriter pw) throws IOException {\n\t\t\tint n = br.ni();\n\t\t\tInteger[] in = br.nIa(n);\n\t\t\tTreeSet<Integer> ts = new TreeSet<Integer>();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tts.add(in[i]);\n\t\t\t}\n\t\t\tString twoSol = \"\";\n\t\t\tfor (int i = 0; i <= 30; i++) {\n\t\t\t\tfor (int j : in) {\n\t\t\t\t\tif (ts.contains(j + (int) Math.pow(2, i))) {\n\t\t\t\t\t\tif (ts.contains(j - (int) Math.pow(2, i))) {\n\t\t\t\t\t\t\tpw.println(3);\n\t\t\t\t\t\t\tpw.println(j + \" \" + (j + (int) Math.pow(2, i)) + \" \" + (j - (int) Math.pow(2, i)));\n\t\t\t\t\t\t\tpw.close();\n\t\t\t\t\t\t\tSystem.exit(0);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\ttwoSol = (j + \" \" + (j + (int) Math.pow(2, i)));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (twoSol.isEmpty()) {\n\t\t\t\tpw.println(1);\n\t\t\t\tpw.println(in[0]);\n\t\t\t} else {\n\t\t\t\tpw.println(2);\n\t\t\t\tpw.println(twoSol);\n\t\t\t}\n\t\t\tpw.close();\n\t\t}\n\n\t\tstatic long gcd(long a, long b) {\n\t\t\tif (a > b)\n\t\t\t\treturn gcd(b, a);\n\t\t\tif (a == 0)\n\t\t\t\treturn b;\n\t\t\treturn gcd(b % a, a);\n\t\t}\n\n\t\tstatic long lcm(long a, long b) {\n\t\t\treturn a * (b / gcd(a, b));\n\t\t}\n\n\t\tstatic long pow(long a, long b) {\n\t\t\tif (b == 0)\n\t\t\t\treturn 1L;\n\t\t\tlong val = pow(a, b / 2);\n\t\t\tif (b % 2 == 0)\n\t\t\t\treturn val * val % mod;\n\t\t\telse\n\t\t\t\treturn val * val % mod * a % mod;\n\t\t}\n\n\t}\n\n\tstatic class Point implements Comparable<Point> {\n\t\tint a;\n\t\tint b;\n\n\t\tPoint(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn this.a - o.a;\n\t\t}\n\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(String s) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tArrayList<Integer>[] ng(int n, int e) {\n\t\t\tArrayList<Integer>[] adj = new ArrayList[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tadj[i] = new ArrayList<Integer>();\n\t\t\t}\n\t\t\tfor (int i = 0; i < e; i++) {\n\t\t\t\tint a = ni() - 1;\n\t\t\t\tint b = ni() - 1;\n\t\t\t\tadj[a].add(b);\n\t\t\t\tadj[b].add(a);\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\n\t\tInteger[] nIa(int n) {\n\t\t\tInteger[] arr = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = ni();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tint[] nia(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = ni();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tLong[] nLa(int n) {\n\t\t\tLong[] arr = new Long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nl();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] nla(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nl();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tString[] nsa(int n) {\n\t\t\tString[] arr = new String[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tString nt() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint ni() {\n\t\t\treturn Integer.parseInt(nt());\n\t\t}\n\n\t\tlong nl() {\n\t\t\treturn Long.parseLong(nt());\n\t\t}\n\n\t\tdouble nd() {\n\t\t\treturn Double.parseDouble(nt());\n\t\t}\n\n\t}\n}", "complexity": "nlogn", "problem": "988_D. Points and Powers of Two", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Chores\n{\n\tpublic static void main(String args[])throws IOException \n\t{\n\t\tInputStreamReader isr = new InputStreamReader(System.in);\n\t\tBufferedReader  br = new BufferedReader(isr);\n\t\tString[] line = br.readLine().split(\"\\\\W\");\n\n\t\tint n = Integer.parseInt(line[0]);\n\t\tint a = Integer.parseInt(line[1]);\n\t\tint b = Integer.parseInt(line[2]);\n\n\t\tint[] num = new int[n];\n\t\tline = br.readLine().split(\"\\\\W\");\n\n\t\tfor(int i=0;i<n;i++) num[i] = Integer.parseInt(line[i]);\n\n\t\tArrays.sort(num);\n\t\t\n\t\tSystem.out.println(num[b]-num[b-1]);\n\t}\t\n}\n\t\t\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\n    public static void main(String[] args) {\n        A problem = new A();\n        problem.solve();\n    }\n\n    private void solve() {\n        Scanner sc = new Scanner(System.in);\n            \n        int n = sc.nextInt();\n        \n        int p = sc.nextInt();\n        int v = sc.nextInt();\n        \n        long a[] = new long[n];\n        \n        for (int i = 0; i < n; i++) {\n            a[i] = sc.nextLong();\n        }\n        \n        long aux;\n        for(int i = 0; i < n -1; i++){  \n            for(int j = i + 1; j < n; j++){  \n\n                if((a[i]) > (a[j])){  \n                    aux = a[j];  \n                    a[j] = a[i];  \n                    a[i] = aux;\n\n                }  \n            }  \n        }\n        \n        System.out.println(a[v]-a[v-1]);\n        \n        \n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        HomeWorks hw = new HomeWorks();\n        hw.sol();\n        hw.print();\n    }\n\n}\n\nclass HomeWorks {\n    HomeWorks(){\n        Scanner scr = new Scanner(System.in);\n        \n        n = scr.nextInt();\n        a = scr.nextInt();\n        b = scr.nextInt();\n        h = new int[n];\n        \n        for (int i = 0; i < n; i++){\n            h[i] = scr.nextInt();\n        }\n        scr.close();\n    }\n    \n    void sol() {\n        Arrays.sort(h);\n        int Vasya = h[b-1];\n        int Petya = h[b]; \n        \n        ans = Petya - Vasya;\n        if (ans < 0){\n            ans = 0;\n        }\n        \n    }\n    \n    void print(){\n        PrintWriter pw = new PrintWriter(System.out);\n        pw.println(ans);\n        pw.flush();\n        pw.close();\n    }\n    \n    int ans;\n    \n    int[] h;\n    \n    int n;\n    int a;\n    int b;\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\n\npublic class A {\n    \n    public static void main(String[] args) throws Exception {\n        int n = nextInt(), b = nextInt(), a = nextInt();\n        \n        int[] mas = new int[n];\n        for(int i = 0; i<n; i++) {\n            mas[i] = nextInt();\n        }\n        Arrays.sort(mas);\n        \n        if(mas[a - 1] == mas[a]) {\n            exit(0);\n        }\n        \n        println(mas[a] - mas[a-1]);\n    }\n    \n    /////////////////////////////////////////////////////////////////\n    // IO\n    /////////////////////////////////////////////////////////////////\n    private static StreamTokenizer in;\n    private static PrintWriter out;\n    private static BufferedReader inB;\n    \n    private static boolean FILE=false;\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        try {\n            out = new PrintWriter(FILE ? (new FileOutputStream(\"output.txt\")) : System.out);\n            inB = new BufferedReader(new InputStreamReader(FILE ? new FileInputStream(\"input.txt\") : System.in));\n        } catch(Exception e) {e.printStackTrace();}\n        in = new StreamTokenizer(inB);\n    }\n    /////////////////////////////////////////////////////////////////\n    \n    /////////////////////////////////////////////////////////////////\n    // pre - written\n    /////////////////////////////////////////////////////////////////\n    private static void println(Object o) throws Exception {\n        out.println(o);\n        out.flush();\n    }\n    private static void exit(Object o) throws Exception {\n        println(o);\n        exit();\n    }\n    private static void exit() {\n        System.exit(0);\n    }\n    private static final int  INF = Integer.MAX_VALUE;\n    private static final int MINF = Integer.MIN_VALUE;\n    //////////////////////////////////////////////////////////////////\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "\n/**\n * Write a description of class VK2A here.\n * \n * @author (your name) \n * @version (a version number or a date)\n */\nimport java.util.*;\npublic class VK2A\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[] A = new int[n];\n        for(int i = 0; i < n; i++)\n            A[i] = S.nextInt();\n        for(int i = 0; i < n; i++)\n            for(int j = 0; j < n - i - 1; j++)\n            {\n                if(A[j] < A[j + 1])\n                {\n                    int temp = A[j];\n                    A[j] = A[j + 1];\n                    A[j + 1] = temp;\n                }\n            }\n        \n            System.out.println(A[a - 1] - A[a]);\n        }\n \n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\n    private void solve() throws IOException {\n        int n = nextInt();\n        int a = nextInt();\n        int b = nextInt();\n        \n        int[] h = new int[n];\n        \n        for (int i = 0; i < n; i++)\n            h[i] = nextInt();\n        \n        Arrays.sort(h);\n        \n        int fstB = h[h.length - a];\n        int lstA = h[h.length - a - 1];\n        \n        pl((fstB - lstA) > 0 ? (fstB - lstA) : 0);\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\n    public void run() {\n        try {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            solve();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(nextToken());\n    }\n\n    String nextToken() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    void p(Object... objects) {\n        for (int i = 0; i < objects.length; i++) {\n            if (i != 0)\n                writer.print(' ');\n            writer.flush();\n            writer.print(objects[i]);\n            writer.flush();\n        }\n    }\n\n    void pl(Object... objects) {\n        p(objects);\n        writer.flush();\n        writer.println();\n        writer.flush();\n    }\n\n    int cc;\n\n    void pf() {\n        writer.printf(\"Case #%d: \", ++cc);\n        writer.flush();\n    }\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\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 a=in.nextInt();\n        int b=in.nextInt();\n        int []deals=new int[n];\n        for(int i=0; i<n; i++){\n            deals[i]=in.nextInt();\n        }\n        Arrays.sort(deals);\n        System.out.println(deals[b]-deals[b-1]);\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\n\npublic class Main {\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        PrintWriter out=new PrintWriter(System.out);\n        int mod=1000000007;\n        String[] input=in.readLine().split(\" \");\n        int n=Integer.parseInt(input[0]);\n        int a=Integer.parseInt(input[1]);\n        int b=Integer.parseInt(input[2]);\n        String[] h=in.readLine().split(\" \");\n        int[] mas=new int[n];\n        for(int i=0; i<n; i++){\n            mas[i]=Integer.parseInt(h[i]);\n        }\n        Arrays.sort(mas);\n        int l=mas[b-1];\n        int r=mas[b];\n        int count=0;\n        if(l==r) count=0;\n        else count=r-l;\n        out.println(count);\n        out.close();\n    }\n\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n\npublic class VKRound2Div2Task1 {\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 br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString str = br.readLine();\n\t\tString[] strs = str.split(\" \");\n\t\tint n = Integer.parseInt(strs[0]);\n\t\tint a = Integer.parseInt(strs[1]);\n\t\tint b = Integer.parseInt(strs[2]);\n\t\tstr = br.readLine();\n\t\tString[] hs = str.split(\" \");\n\t\tint[] h = new int[hs.length];\n\t\tfor(int i=0;i<hs.length;i++){\n\t\t\th[i] = Integer.parseInt(hs[i]);\n\t\t}\n\t\tArrays.sort(h);\n\t\tif(h[b-1]==h[b]){\n\t\t\tSystem.out.println(0);\n\t\t}else{\n\t\t\tSystem.out.println(h[b]-h[b-1]);\n\t\t}\n\t\t\n\t}\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n// VK Cup 2012 Round2 Unofficial Div2 Edition\npublic class Main {\n\t\n\tvoid A(){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint[] h = new int[n];\n\t\tfor(int i=0; i<n; i++){\n\t\t\th[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(h);\n\t\tSystem.out.println(h[b]-h[b-1]);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Main().A();\n\t}\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class r114 {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int a = sc.nextInt();\n        int b = sc.nextInt();\n        \n        ArrayList<Integer> l = new ArrayList<Integer>();\n        for (int i = 0 ; i < n; i++) {\n            l.add(sc.nextInt());\n        }\n        Collections.sort(l);\n        \n        int pet = l.get(n - a);\n        int vas = l.get(b - 1);\n        \n        if (pet <= vas) {\n            System.out.println(0);\n        }\n        else System.out.println(pet - vas);     \n        \n        sc.close();\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Main{\n\n\tpublic static void main(String[] args) throws Exception {\n\t\t\n\t\tint n = nextInt();\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tint[] tasks = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\ttasks[i] = nextInt();\n\t\t}\n\t\tArrays.sort(tasks);\n\t\texit(tasks[b] - tasks[b-1]);\n\t\t\n\t}\n\t\n\tprivate static PrintWriter out;\n\tprivate static BufferedReader inB;\n\tprivate static boolean FILE = false; \n\t\n\tstatic {\n\t\ttry {\n\t\t\tout = new PrintWriter(FILE ? (new FileOutputStream(\"output.txt\")) : System.out);\n\t\t\tinB = new BufferedReader(new InputStreamReader(FILE ? new FileInputStream(\"input.txt\") : System.in));\n\t\t} catch(Exception e) {e.printStackTrace();}\n\t}\n\t\n\tprivate static StreamTokenizer in = new StreamTokenizer(inB);\n\t\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 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} ", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Success {\n\n\t/**\n\t * @param args\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 a = scan.nextInt();\n\t\tint b=scan.nextInt();\n\t\tint[] t=new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tt[i]=scan.nextInt();\n\t\t}\n\t\tArrays.sort(t);\n\t\tSystem.out.println(t[b]-t[b-1]);\n\t\t}\n\t\t\n\n\t}\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class test\n{\n\n\tpublic static void main(String[] args)\n\t{\n\t\tnew test().run();\n\t}\n\n\tPrintWriter out = null;\n\n\tvoid run()\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\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\n\t\tint[] h = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\th[i] = in.nextInt();\n\n\t\tArrays.sort(h);\n\n\t\tif (h[b] == h[b - 1])\n\t\t\tout.println(0);\n\t\telse\n\t\t\tout.println(h[b] - h[b - 1]);\n\t\tout.close();\n\t}\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by IntelliJ IDEA.\n * User: \u041c\u0438\u0445\u0430\u0438\u043b\n * Date: 25.03.12\n * Time: 19:03\n * To change this template use File | Settings | File Templates.\n */\npublic class ProblemOne {\n    public static void main(String [] args) {\n        Scanner scanner = new Scanner(System.in);\n        int problemCount = scanner.nextInt();\n        int petrCount = scanner.nextInt();\n        int vasCount = scanner.nextInt();\n        int [] problems = new int[problemCount];\n        for (int i = 0; i < problemCount; i++) {\n            problems[i] = scanner.nextInt();\n            \n\n        }\n        Arrays.sort(problems);\n        System.out.println(-problems[vasCount - 1] + problems[vasCount]);\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by IntelliJ IDEA.\n * User: Mirza\n * Date: 25.03.12\n * Time: 18:51\n * To change this template use File | Settings | File Templates.\n */\npublic class main {\n        static Scanner in; static int next() throws Exception {return in.nextInt();};\n    //static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n    //  static BufferedReader in;\n    static PrintWriter out;\n\n    public static void main(String[] args) throws Exception {\n        in = new Scanner(System.in);\n//      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n//      in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        int n = next();\n        int a = next();\n        int b = next();\n        int k = 0;\n        int i;\n        int[] ar = new int[n];\n        for(i=0;i<n;i++)\n            ar[i]=next();\n        Arrays.sort(ar);\n        k = ar[n-a]-ar[b-1];\n        if(k<0)\n            out.print(0);\n        else out.print(k);\n        out.close();\n\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport 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        PrintWriter pw = new PrintWriter(System.out);\n        int n = sc.nextInt();\n        int a = sc.nextInt();\n        int b = sc.nextInt();\n        int[] h = new int[n];\n        for (int i = 0; i < n; i++)\n            h[i] = sc.nextInt();\n\n        Arrays.sort(h);\n        \n        pw.print(h[b]-h[b-1]);\n        pw.close();\n    }\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author hheng\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] chores = new int[n];\n        for (int i=0; i<n; i++) chores[i] = in.nextInt();\n        Arrays.sort(chores);\n        out.println(chores[b]-chores[b-1]);\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Contest169ProblemA implements Runnable {\n\n    void solve() throws NumberFormatException, IOException {\n        int n = nextInt(), a = nextInt(), b = nextInt();\n\n        ArrayList<Integer> tasks= new ArrayList<Integer>();\n        \n        for (int i = 0; i < n; ++i){\n            tasks.add(nextInt());\n        }\n        Collections.sort(tasks);\n\n        int l1 = tasks.get(b-1);\n        int l2 = tasks.get(b);\n\n        if (l2 - l1 >= 0){\n            out.print(l2-l1);\n        } else {\n            out.print(l2-l1);\n        }\n\n    }\n\n\n    StringTokenizer st;\n\n    BufferedReader in;\n\n    PrintWriter out;\n\n\n    public static void main(String[] args) {\n\n        new Thread(new Contest169ProblemA()).start();\n    }\n\n\n    public void run() {\n\n        try {\n            if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n                in = new BufferedReader(new InputStreamReader(System.in));\n            } else {\n                in = new BufferedReader(new FileReader(\"input.txt\"));\n            }\n\n            out = new PrintWriter(System.out);\n\n\n            solve();\n\n\n        } catch (Exception e) {\n\n            e.printStackTrace();\n            System.out.print(e);\n            System.exit(9000);\n\n\n        } finally {\n\n\n            out.flush();\n\n            out.close();\n\n        }\n\n    }\n\n    //\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d\n\n    String nextToken() throws IOException {\n\n        while (st == null || !st.hasMoreTokens()) {\n\n            st = new StringTokenizer(in.readLine());\n\n        }\n\n        return st.nextToken();\n\n    }\n\n\n    int nextInt() throws NumberFormatException, IOException {\n\n        return Integer.parseInt(nextToken());\n\n    }\n\n\n    long nextLong() throws NumberFormatException, IOException {\n\n        return Long.parseLong(nextToken());\n\n    }\n\n\n    double nextDouble() throws NumberFormatException, IOException {\n\n        return Double.parseDouble(nextToken());\n\n    }\n\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class Main {\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 br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[]parts = br.readLine().split(\"\\\\s+\");\n\t\tint n = Integer.parseInt(parts[0]);\n\t\tint a = Integer.parseInt(parts[1]);\n\t\tint b = Integer.parseInt(parts[2]);\n\t\tparts = br.readLine().split(\"\\\\s+\");\n\t\tint[]hard = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\thard[i] = Integer.parseInt(parts[i]);\n\t\t}\n\t\tArrays.sort(hard);\n\t\tSystem.out.println(hard[b]-hard[b-1]);\n\t}\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class A {\n\n    int INF = 1 << 28;\n\n    void run() {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int a = sc.nextInt();\n        int b = sc.nextInt();\n        long[] chores = new long[n];\n        for(int i=0;i<n;i++) chores[i] = sc.nextLong();\n        sort(chores);\n        System.out.println(chores[b]-chores[b-1]);\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/**\n * @author Vaibhav Mittal\n */\n\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int testCases = 1;\n        Task solver = new Task();\n        for (int i = 1; i <= testCases; ++i)\n            solver.solve(in, out);\n\n        out.close();\n    }\n}\n\nclass Task {\n    public void solve(Scanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] complexity = new int[n];\n        for (int i = 0; i < n; ++i)\n            complexity[i] = in.nextInt();\n        Arrays.sort(complexity);\n        out.println(complexity[b] - complexity[b - 1]);\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\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 a = in.nextInt();\n        int b = in.nextInt();\n        \n        int[] h = new int[3000];\n        \n        for(int i = 0; i<n; i++)\n            h[i] = in.nextInt();\n        \n        int l = 0, r = 1000000000, m = 0;\n        int ansl = 0, ansr = 0;\n        \n        while(l<=r){\n            m = (l+r)/2;\n            \n            int ca=0;\n            \n            for(int i = 0;i<n;i++)\n                if (h[i]>m) ca++;\n            \n            if (ca == a) ansl=m;\n            if (ca <= a) r=m-1; else l=m+1;\n        }\n        l = 0; r = 1000000000;\n        while(l<=r){\n            m = (l+r)/2;\n            \n            int ca=0;\n            \n            for(int i = 0;i<n;i++)\n                if (h[i]>m) ca++;\n            \n            if (ca == a) ansr=m;\n            if (ca < a) r=m-1; else l=m+1;\n        }\n        if (ansl == 0 || ansr==0) System.out.print(0); else\n        System.out.print(ansr-ansl+1);\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n    //<editor-fold desc=\"input parse\" defaultstate=\"collapsed\">\n\n    private static StringTokenizer st;\n    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n    private static long nextLong() {\n        return Long.parseLong(st.nextToken());\n    }\n\n    private static int nextInt() {\n        return Integer.parseInt(st.nextToken());\n    }\n\n    private static double nextDouble() {\n        return Double.parseDouble(st.nextToken());\n    }\n\n    private static short nextShort() {\n        return Short.parseShort(st.nextToken());\n    }\n\n    private static byte nextByte() {\n        return Byte.parseByte(st.nextToken());\n    }\n\n    private static void initTokenizer() throws Exception {\n        st = new StringTokenizer(reader.readLine());\n    }\n\n    //</editor-fold>\n\n    public static void main(String[] args) throws Exception {\n        initTokenizer();\n\n        int n = nextInt();\n        int a = nextInt();\n        int b = nextInt();\n\n        int[] h = new int[n];\n\n        initTokenizer();\n\n        for (int i = 0; i < n; i++) {\n            h[i] = nextInt();\n        }\n\n        Arrays.sort(h);\n\n        System.out.print(h[b] - h[b - 1]);\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n        StringTokenizer st;\n\n        st = new StringTokenizer(in.readLine());\n        \n        int n = Integer.parseInt(st.nextToken()),\n            a = Integer.parseInt(st.nextToken()),\n            b = Integer.parseInt(st.nextToken());\n        \n        st = new StringTokenizer(in.readLine());\n        \n        ArrayList<Integer> A = new ArrayList<Integer>();\n        \n        for (int i = 0 ; i < n ; i++) {\n            A.add(Integer.parseInt(st.nextToken()));\n        }\n        \n        Collections.sort(A);\n        \n        System.out.println(A.get(b) - A.get(b - 1));\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Start {\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 Start().run();\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 = 50;\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<LoL> {\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 arg0) {\n            if (arg0.x == x) {\n                return y - arg0.y;\n            }\n            return arg0.x - x;\n        }\n\n    }\n\n    public void solve() throws IOException {\n        \n        int n =  readInt();\n        int a = readInt()-1;\n        int b = readInt()-1;\n        int [] d = new int [n];\n        for (int i = 0; i <n; i++){\n            d[i] = readInt();\n        }\n        mergeSort(d);\n        out.print(d[b+1]-d[b]);\n    }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author codeKNIGHT\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n=in.nextInt(),a=in.nextInt(),b=in.nextInt(),i,c=0;\n        int ar[]=new int[n];\n        for(i=0;i<n;i++)\n            ar[i]=in.nextInt();\n        Arrays.sort(ar);\n        out.println(ar[b]-ar[b-1]);\n\t}\n}\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "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    \n    \n    public void solve() throws Exception {\n        \n        int n = sc.nextInt();\n        int a = sc.nextInt();\n        int b = sc.nextInt();\n        long h[] = new long[n];\n        \n        for (int i = 0;i < n; ++ i) {\n            h[i] = sc.nextLong();\n        }\n        Arrays.sort(h);\n        long l = h[n - a];\n        long r = h[n - a - 1];\n        out.println(l - r);\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}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class test {\n\n    public static void main(String[] args) {\n        Scanner kb = new Scanner(System.in);\n        int n = kb.nextInt();\n        int a = kb.nextInt();\n        int b = kb.nextInt();\n        int array[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            array[i] = kb.nextInt();\n        }\n        Arrays.sort(array);\n        int k = 0;\n        int t1 = 0;\n        int t2 = 0;\n        for (int i = 0; i < b; i++) {\n            t1= array[i];\n            if(i<n-1){\n                t2=array[i+1];\n                k=t2-t1;\n            }\n            else k=0;\n        }\n        System.out.println(k);\n\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author @zhendeaini6001\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] input = IOUtils.readIntArray(in, n);\n        Arrays.sort(input);\n        int x = input[b-1];\n        int y = input[b];\n        out.println(y - x);\n    }\n}\n\nclass IOUtils {\n\n    public static int[] readIntArray(Scanner in, int size) {\n        int[] array = new int[size];\n        for (int i = 0; i < size; i++)\n            array[i] = in.nextInt();\n        return array;\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class VkR2A{\n    static BufferedReader br;\n    public static void main(String args[])throws Exception{\n        br=new BufferedReader(new InputStreamReader(System.in));\n\n        int nm[] = toIntArray();\n        int n = nm[0];\n        int a = nm[1];\n        int b = nm[2];\n        nm=toIntArray();\n        Arrays.sort(nm);\n        int k=nm[b-1];\n        int res=nm[b]-k;\n        System.out.println(res);\n\n    }\n\n\n    /****************************************************************/\n    public static int[] toIntArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       int k[]=new int[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Integer.parseInt(str[i]);\n       }\n       return k;\n    }\n    public static int toInt()throws Exception{\n       return Integer.parseInt(br.readLine());\n    }\n    public static long[] toLongArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       long k[]=new long[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Long.parseLong(str[i]);\n       }\n       return k;\n    }\n    public static long toLong()throws Exception{\n       return Long.parseLong(br.readLine());\n    }\n    public static double[] toDoubleArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       double k[]=new double[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Double.parseDouble(str[i]);\n       }\n       return k;\n    }\n    public static double toDouble()throws Exception{\n       return Double.parseDouble(br.readLine());\n    }\n    public static String toStr()throws Exception{\n       return br.readLine();\n    }\n    public static String[] toStrArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       return str;\n    }\n    /****************************************************************/\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n    public static void main(String[] args)throws Exception {\n        File _=new File(\"chores.in\");\n        BufferedReader br=_.exists()? new BufferedReader(new FileReader(_)):new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st;\n        String str;\n        \n        st=new StringTokenizer(br.readLine());\n        int n,a,b;\n        n=Integer.parseInt(st.nextToken());\n        a=Integer.parseInt(st.nextToken());\n        b=Integer.parseInt(st.nextToken());\n        \n        ArrayList<Integer> chores=new ArrayList<Integer>();\n        int k;\n        st=new StringTokenizer(br.readLine());\n        for (int i = 0; i < n; i++) {\n            k=Integer.parseInt(st.nextToken());\n            chores.add(k);\n        }\n        Collections.sort(chores);\n        \n        System.out.println(chores.get(b)-chores.get(b-1));\n        \n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class problemA {\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[] hs = new int[n];\n        for(int i = 0; i < n; i++){\n            hs[i] = sc.nextInt();\n        }\n        Arrays.sort(hs);\n        System.out.println(hs[b]-hs[b-1]);\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class A2 {\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        int n = next(), a = next(), b = next();\n        int h[] = new int[n];\n\n        for (int i = 0;i < n;i++) h[i] = next();\n\n        Arrays.sort(h);\n\n        int res = h[b] - h[b-1];\n\n        out.println(res);\n\n        out.println();\n\t\tout.close();\n\t}\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\npublic class ProblemA {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n        String[] data = s.readLine().split(\" \");\n        int n =  Integer.valueOf(data[0]);\n        int a =  Integer.valueOf(data[1]);\n        int b =  Integer.valueOf(data[2]);\n\n        long[] h = new long[n];\n        String[] line = s.readLine().split(\" \");\n        for (int i = 0 ; i < n ; i++) {\n            h[i] = Integer.valueOf(line[i]);\n        }\n        Arrays.sort(h);\n        \n        System.out.println(h[b] - h[b-1]);\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R2_D2_A {\n    public static void main(String[] args) {\n        // BufferedReader in = new BufferedReader(new\n        // InputStreamReader(System.in));\n        InputReader in = new InputReader(System.in);\n        int n = in.readInt();\n        int a = in.readInt();\n        int b = in.readInt();\n        Integer[] inp = new Integer[n];\n        for (int i = 0; i < inp.length; i++) {\n            inp[i] = in.readInt();\n        }\n        Arrays.sort(inp);\n        int petya = inp[inp.length-a];\n        int next = inp[inp.length-a-1];\n        int diff = petya - next;\n        System.out.println(diff);\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", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Train_A {\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 [] h = new int[n]; \n        for (int i = 0; i < n; i++) {\n            h[i]  = sc.nextInt(); \n        }\n        Arrays.sort(h);\n        System.out.println(h[n-a] - h[b-1]);\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n   private static IO io;\n\n   public static void main(String[] args) throws IOException {\n       new Main().run();\n   }\n\n   private void run() throws IOException {\n       io = new IO(System.getProperty(\"ONLINE_JUDGE\")!=null);\n       solve();\n       io.flush();\n   }\n   \n   private void solve() throws IOException {\n       int n = io.nI(), a = io.nI(), b = io.nI(), h[] = new int[n], i;\n       for(i = 0; i<n; i++)h[i] = io.nI(); Arrays.sort(h);\n       io.wln(h[b]-h[b-1]);\n   }//2.2250738585072012e-308\n   \n   private int gcd(int a, int b) {\n       while(b>0) b^=a^=b^=a%=b;\n       return a;\n   }\n   \n   @SuppressWarnings(\"unused\")\n   private class IO{\n       StreamTokenizer in; PrintWriter out; BufferedReader br; Reader reader; Writer writer;\n       public IO(boolean oj) throws IOException{\n           Locale.setDefault(Locale.US);\n           reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n           writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n           br = new BufferedReader(reader);\n           in = new StreamTokenizer(br);\n           out = new PrintWriter(writer);\n       }\n       public void wln(){out.println();}\n       public void wln(int arg){out.println(arg);}\n       public void wln(long arg){out.println(arg);}\n       public void wln(double arg){out.println(arg);}\n       public void wln(String arg){out.println(arg);}\n       public void wln(boolean arg){out.println(arg);}\n       public void wln(char arg){out.println(arg);}\n       public void wln(float arg){out.println(arg);}\n       public void wln(Object arg){out.println(arg);}\n       public void w(int arg){out.print(arg);}\n       public void w(long arg){out.print(arg);}\n       public void w(double arg){out.print(arg);}\n       public void w(String arg){out.print(arg);}\n       public void w(boolean arg){out.print(arg);}\n       public void w(char arg){out.print(arg);}\n       public void w(float arg){out.print(arg);}\n       public void w(Object arg){out.print(arg);}\n       public void wf(String format, Object...args){out.printf(format, args);}\n       public void flush(){out.flush();}\n       public int nI() throws IOException {in.nextToken(); return(int)in.nval;}\n       public long nL() throws IOException {in.nextToken(); return(long)in.nval;}\n       public String nS() throws IOException {in.nextToken(); return in.sval;}\n       public double nD() throws IOException {in.nextToken(); return in.nval;}\n       public float nF() throws IOException {in.nextToken(); return (float)in.nval;}\n       public void wc(char...a){for(char c : a){in.ordinaryChar(c);in.wordChars(c, c);}}\n       public void wc(char c1, char c2){in.ordinaryChars(c1, c2); in.wordChars(c1, c2);}\n   }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class SolA {\n\n\tprivate static InputReader in;\n\tprivate static PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\trun();\n\t\tout.close();\n\t}\n\n\tpublic static void run() {\n\t\tint n = in.readInt();\n\t\tint a = in.readInt();\n\t\tint b = in.readInt();\n\t\tint[] h = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\th[i] = - in.readInt();\n\t\t}\n\t\tArrays.sort(h);\n\t\t\n\t\tint base = -h[a-1];\n\t\tint base1 = -h[a];\n\t\tout.print(-(base1 - base));\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 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 String next() {\n\t\treturn readString();\n\t}\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "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.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n    \n    public long result = 0;\n    public int k = 0;\n\n    public static void main(String[] args) throws NumberFormatException,\n            IOException {\n        Solver solver = new Solver();\n        solver.open();\n        solver.solve();\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    public void solve() throws NumberFormatException, IOException {\n        int n = nextInt();\n        int a = nextInt();\n        int b = nextInt();\n        \n        int[] ar = new int[n];\n        \n        for(int i=0;i<n;i++){\n            ar[i] = nextInt();\n        }\n        \n        Arrays.sort(ar);\n        \n        out.println(ar[b]-ar[b-1]);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int a = in.nextInt();\n        int b = in.nextInt();\n        int[] ar = new int[n];\n        for (int i = 0; i < n; i++)\n            ar[i] = in.nextInt();\n        Arrays.sort(ar);\n        int x1 = ar[b-1];\n        int x2 = ar[b];\n        System.out.println(x2-x1);\n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class CF_Chores {\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 = s.nextInt();\n        int b = s.nextInt();\n        \n        long ar[] = new long[n];\n        for (int i = 0; i < n; i++) {\n            ar[i]=s.nextLong();\n        }\n        Arrays.sort(ar);\n        \n        long ret = 0;\n//      System.out.println(Arrays.toString(ar));\n        if(ar[b]==ar[b-1])\n            System.out.println(\"0\");\n        else {\n            ret = ar[b]-ar[b-1];\n            System.out.println(ret);\n        }\n        \n    }\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\npublic class Main\n\t{\n\tpublic static void main(String args[])\tthrows IOException\n\t\t{\n\t\tScanner c=new Scanner(System.in);\n\t\tint n=c.nextInt();\n\t\tint a=c.nextInt();\t\t//higher\n\t\tint b=c.nextInt();\t\t//lower\n\t\tint C[]=new int[n];\n\t\tfor(int i=0;i<n;i++) \n\t\t\tC[i]=c.nextInt();\n\t\tArrays.sort(C);\n\t\t//System.out.println(Arrays.toString(C));\n\t\tint petya=C[n-a];\n\t\tSystem.out.println((C[n-a]-C[n-a-1]));\n\t\t}\n\t}\n\n//must declare new classes here", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer tokenizer=null;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tnew Main().execute();\n\t}\n\t\n\tvoid debug(Object...os)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t\n\tint ni() throws IOException\n\t{\n\t\treturn Integer.parseInt(ns());\n\t}\n\t\n\tlong nl() throws IOException \n\t{\n\t\treturn Long.parseLong(ns());\n\t}\n\t\n\tdouble nd() throws IOException \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\t\n\tString ns() throws IOException \n\t{\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n\t\t\ttokenizer = new StringTokenizer(br.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tString nline() throws IOException\n\t{\n\t\ttokenizer=null;\n\t\treturn br.readLine();\n\t}\n\t\t\n\t\n\n\t//Main Code starts Here\n\tint totalCases, testNum;\t\n\tint n,a,b;\n\tlong arr[];\n\n\tvoid execute() throws IOException\n\t{\n\t\ttotalCases = 1;\n\t\tfor(testNum = 1; testNum <= totalCases; testNum++)\n\t\t{\n\t\t\tif(!input())\n\t\t\t\tbreak;\n\t\t\tsolve();\n\t\t}\n\t}\n\n\tvoid solve() throws IOException\n\t{\n\t\tArrays.sort(arr);\n\t\tlong x1 = arr[b-1];\n\t\tlong x2 = arr[b];\n\t\t\n\t\tSystem.out.println(x2-x1);\n\t}\n\n\tboolean input() throws IOException\n\t{\n\t\tn = ni();\n\t\ta = ni();\n\t\tb = ni();\n\t\tarr = new long[n];\n\t\tfor(int i = 0;i<n;i++)\n\t\t{\n\t\t\tarr[i] = nl();\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\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 = sc.nextInt();\n        int b = sc.nextInt();\n        int[] ar = new int[n];\n        for (int i = 0; i < n; i++) {\n            ar[i] = sc.nextInt();\n        }\n        Arrays.sort(ar);\n        if (ar[b-1] == ar[b ]) {\n            System.out.println(0);\n        } else {\n            System.out.println(ar[b ] - ar[b-1]);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution\n{\n    public static void main(String[] args) throws IOException\n    {\n        new Solution().run();\n    }\n    StreamTokenizer in; \n    Scanner ins;\n    PrintWriter out;\n    \n    int nextInt() throws IOException\n    {\n        in.nextToken();      \n        return (int)in.nval;\n    }\n   \n\n    void run() throws IOException\n    {\n\n        if(System.getProperty(\"ONLINE_JUDGE\")!=null)\n        {\n            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            ins = new Scanner(System.in);\n            out = new PrintWriter(System.out);\n        }\n        else\n        {           \n            in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));             \n            ins = new Scanner(new FileReader(\"input.txt\"));\n            out = new PrintWriter(new FileWriter(\"output.txt\"));\n        }\n        int n = nextInt(),a = nextInt(),b = nextInt();\n        b--;\n        int [] A = new int[n];\n        for(int i = 0; i < n ;i++)\n        {\n            A[i] = nextInt();\n        }\n        Arrays.sort(A);\n        if(A[b] == A[b+1])\n            out.print(0);\n        else\n            out.print(A[b+1]- A[b]);\n        out.close();\n    }\n    \n    \n    class Team implements Comparable\n    {\n        public int p,t;\n        public int compareTo(Object obj)\n        {\n            Team a = (Team) obj;\n            if(p>a.p || p==a.p && t<a.t)                          \n                return -1;\n            else                \n                if(p==a.p && t==a.t)\n                    return 0;\n                else\n                    return 1;\n        }\n        \n    }\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        int n = input.nextInt();\n        int a = input.nextInt();\n        int b = input.nextInt();\n        int x[] = new int[n];\n        for (int i=0; i<n; i++) x[i]=input.nextInt();\n        Arrays.sort(x);\n        int y[] = new int[n];\n        for (int i=0; i<n; i++) y[i]=x[n-i-1];\n        System.out.println(y[a-1]-y[a]);\n    }\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class A {\n\t@SuppressWarnings(\"unchecked\")\n\tprivate static void solve() throws IOException {\n\t\tArrayList<Num> c = new ArrayList<Num>();\n\t\tn = nextInt();\n\t\ta = nextInt();\n\t\tb = nextInt();\n\t\tfor(int i = 0;  i < n; i++) {\n\t\t\tint next = nextInt();\n\t\t\tboolean found = false;\n\t\t\tfor(int j = 0; j < c.size(); j++) {\n\t\t\t\tif(c.get(j).num == next) {\n\t\t\t\t\tc.get(j).freq++;\n\t\t\t\t\tfound = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!found)\n\t\t\t\tc.add(new Num(next));\n\t\t}\n\t\tCollections.sort(c);\n\t\tint below = 0;\n\t\tint above = n;\n\t\tboolean f = false;\n\t\tfor(int i = 0; i < c.size(); i++) {\n\t\t\tbelow += c.get(i).freq;\n\t\t\tabove -= c.get(i).freq;\n\t\t\tif(below == b && above == a) {\n\t\t\t\tif(i == c.size())\n\t\t\t\t\tbreak;\n\t\t\t\tSystem.out.println(c.get(i+1).num - c.get(i).num);\n\t\t\t\tf = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(!f)\n\t\t\tSystem.out.println(0);\n\t}\n\t\n\tstatic int n;\n\tstatic int a;\n\tstatic int b;\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}\nclass Num implements Comparable<Num> {\n\tint num;\n\tint freq;\n\tNum(int n) {\n\t\tnum = n;\n\t\tfreq = 1;\n\t}\n\tpublic int compareTo(Num other) {\n\t\treturn this.num - other.num;\n\t}\n}", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "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.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\tA solver = new A();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass A {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.readInt();\n        int a = in.readInt();\n        int b = in.readInt();\n        int[] hs = new int[n];\n        for (int i=0;i<n;i++){\n            hs[i]=in.readInt();\n        }\n        Arrays.sort(hs);\n        out.println(hs[b]-hs[b-1]);\n\t}\n}\n\nclass InputReader {\n    BufferedReader in;\n\n    public InputReader(InputStream stream) {\n        in = new BufferedReader(new InputStreamReader(stream));\n    }\n\n    public int skipSpace() {\n        int c;\n        try {\n            while (true) {\n                c = in.read();\n                if (c < 0) {\n                    throw new InputMismatchException();\n                }\n                if (c > 32) {\n                    break;\n                }\n            }\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n        return c;\n    }\n\n    public int readInt() {\n        int res = 0;\n        boolean sign = false;\n        int c = skipSpace();\n        try {\n            if (c == '-') {\n                sign = true;\n                c = in.read();\n            }\n            while (true) {\n                if (c >= '0' && c <= '9') {\n                    res = res * 10 + c - '0';\n                } else {\n                    throw new InputMismatchException();\n                }\n                c = in.read();\n                if (c <= 32) {\n                    break;\n                }\n            }\n            if (sign) {\n                res = -res;\n            }\n            return res;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "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\tnew 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\t\n\t\treadNextLine();\n\t\tint n=NextInt();\n    \tint a=NextInt();\n    \tint b=NextInt();\n\t\tint ret=0;\n\t\treadNextLine();\n\t\tint [] p = new int[n];\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tp[i]=NextInt();\n\t\t}\n\t\tArrays.sort(p);\n\t\tint id=0,cnt=0;\n\t\twhile(id<n&&cnt<b)\n\t\t{\n\t\t\tcnt++;\n\t\t\tid++;\n\t\t}\n\t\tif(id<n)\n\t\t{\n\t\t\tret=p[id]-p[id-1];\n\t\t}\n\t\t\n\t\tSystem.out.print(ret);\n        closeInput();\t\t\n\t}\n\t\n\n}\n", "complexity": "nlogn", "problem": "169_A. Chores", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ayyyyyy\n{\n\tpublic static void main(String[] args) { new ayyyyyy(); }\n\tScanner in = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\t\n\tint t, n;\n\tint[] a;\n\t\n\tayyyyyy()\n\t{\n\t\tt = in.nextInt();\n\t\twhile (t --> 0)\n\t\t{\n\t\t\ta = new int[n = in.nextInt()];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = in.nextInt();\n\t\t\tshuffle(a);\n\t\t\tArrays.sort(a);\n\t\t\tout.println(Math.min(n-2, a[n-2]-1));\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\tvoid shuffle(int[] x)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tint swp = (int)(n*Math.random());\n\t\t\tint tmp = x[swp];\n\t\t\tx[swp] = x[i];\n\t\t\tx[i] = tmp;\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "1197_A. DIY Wooden Ladder", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n    static MyScanner sc;\n    static PrintWriter pw;\n\n    public static void main(String[] args) throws Throwable {\n        sc = new MyScanner();\n        pw = new PrintWriter(System.out);\n\n        n = sc.nextInt();\n        T = sc.nextLong();\n        p = new int[n];\n        l = new int[n];\n        x = new int[n];\n        t = new int[n];\n        adj = new ArrayList[n];\n\n        for (int i = 0; i < n; i++)\n            x[i] = sc.nextInt();\n        for (int i = 0; i < n; i++)\n            t[i] = sc.nextInt();\n        adj[0] = new ArrayList<>();\n        for (int i = 1; i < n; i++) {\n            adj[i] = new ArrayList<>();\n            p[i] = sc.nextInt() - 1;\n            l[i] = sc.nextInt();\n            adj[p[i]].add(i);\n        }\n\n        ftCnt = new long[N];\n        ftSum = new long[N];\n        ans = new long[n];\n\n        dfs(0);\n        pw.println(ans[0]);\n\n        pw.flush();\n        pw.close();\n    }\n\n    static int n;\n    static long T;\n    static int[] p, l, x, t;\n    static ArrayList<Integer>[] adj;\n\n    static long[] ans;\n\n    static void dfs(int u) {\n        update(t[u], x[u], 1L * x[u] * t[u]);\n        ans[u] = getMaxCnt();\n        long[] vals = {-1, -1, -1};\n        for (int v : adj[u]) {\n            T -= 2 * l[v];\n            dfs(v);\n            vals[0] = ans[v];\n            Arrays.sort(vals);\n            T += 2 * l[v];\n        }\n        if (u != 0) {\n            if (vals[1] != -1)\n                ans[u] = Math.max(ans[u], vals[1]);\n        } else {\n            if (vals[2] != -1)\n                ans[u] = Math.max(ans[u], vals[2]);\n        }\n        update(t[u], -x[u], -1L * x[u] * t[u]);\n    }\n\n    static int N = (int) 1e6 + 2;\n    static long[] ftCnt, ftSum;\n\n    static void update(int idx, long cnt, long val) {\n        while (idx < N) {\n            ftCnt[idx] += cnt;\n            ftSum[idx] += val;\n            idx += (idx & -idx);\n        }\n    }\n\n    static long getSum(int idx) {\n        long ret = 0;\n        while (idx > 0) {\n            ret += ftSum[idx];\n            idx -= (idx & -idx);\n        }\n        return ret;\n    }\n\n    static long getCnt(int idx) {\n        long ret = 0;\n        while (idx > 0) {\n            ret += ftCnt[idx];\n            idx -= (idx & -idx);\n        }\n        return ret;\n    }\n\n    static long getMaxCnt() {\n        int start = 1, end = N - 1, ans = N - 1;\n        while (start <= end) {\n            int mid = (start + end) / 2;\n            if (getSum(mid) >= T) {\n                ans = mid;\n                end = mid - 1;\n            } else\n                start = mid + 1;\n        }\n        long remT = T - (ans > 1 ? getSum(ans - 1) : 0);\n        long cnt = (ans > 1 ? getCnt(ans - 1) : 0);\n        long cntOfVal = getCnt(ans) - cnt;\n        cnt += Math.min(cntOfVal, remT / ans);\n        return cnt;\n    }\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}", "complexity": "nlogn", "problem": "1099_F. Cookies", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class Split {\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 k= sc.nextInt();\n\t\tint a[] = new int[n];\n\t\tint d[] = new int[n-1];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i] = sc.nextInt();\n\t\t\tif(i>0)\n\t\t\t\td[i-1] = a[i-1] - a[i];\n\t\t}\n\t\tArrays.sort(d);\n\t\tint t = 0;\n\t\tfor(int i=0;i<k-1;i++)\n\t\t\tt += d[i];\n\t\tSystem.out.println(a[n-1]-a[0]+t);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "1197_C. Array Splitting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport javax.lang.model.util.ElementScanner6;\npublic class codef\n{\n    public static void main(String ar[]) throws IOException\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer nk=new StringTokenizer(br.readLine());\n        int n=Integer.parseInt(nk.nextToken());\n        int k=Integer.parseInt(nk.nextToken());\n        String st[]=br.readLine().split(\" \");\n        \n        int ans[]=new int[n];\n        int a[]=new int[n];\n        for(int i=0;i<n;i++)\n            ans[i]=Integer.parseInt(st[i]);  \n\n        for(int i=1;i<n;i++)\n            a[i]=ans[i]-ans[i-1];\n        a[0]=-1;\n\n        Arrays.sort(a);\n        int count=0,sum=0;\n        for(int i=0;i<n;i++)\n            if(a[i]<0)\n                count++;\n            else\n                sum=sum+a[i];\n        \n        k=k-count;\n        int i=n-1;\n        while(k>0 && i>=0)\n        {\n            if(a[i]>-1)\n            {\n                sum=sum-a[i];\n                k--;\n            }\n            i--;\n        }\n        System.out.println(sum);\n    }\n}", "complexity": "nlogn", "problem": "1197_C. Array Splitting", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic 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 k = 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\tfor(int i = n-1; i > 0; i--)\n\t\t\tarr[i] -= arr[i-1];\n\t\tarr[0] = 0;\n\t\tArrays.sort(arr);\n\t\tlong sum = 0;\n\t\tfor(int i = n-k; i >= 0; i--)\n\t\t\tsum += arr[i];\n\t\tSystem.out.println(sum);\n\t}\n}", "complexity": "nlogn", "problem": "1197_C. Array Splitting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.System.out;\n\npublic class Main {\n\n    private FastScanner scanner = new FastScanner();\n\n    public static void main(String[] args) {\n        new Main().solve();\n    }\n\n    private List<Integer>[] gr = new ArrayList[1000_000+5];\n    private int dp[][] = new int[21][1000_000+5];\n    private boolean used[] = new boolean[1000_000+5];\n\n    void init(int v, int p) {\n        Stack<Integer> st = new Stack<>();\n        st.push(v);\n        st.push(p);\n        while (!st.isEmpty()) {\n            p = st.pop();\n            v = st.pop();\n            used[v] = true;\n\n            dp[0][v] =  p;\n            for (int i = 1; i <= 20; i++) {\n                if (dp[i - 1][v] != -1) {\n                    dp[i][v] = dp[i - 1][dp[i - 1][v]];\n                }\n            }\n\n            for (int next : gr[v]) {\n                if (!used[next]) {\n                    st.push(next);\n                    st.push(v);\n                }\n            }\n\n        }\n    }\n\n\n    private void solve() {\n        int n = scanner.nextInt(), k = scanner.nextInt();\n        boolean[] ans = new boolean[1000_000 + 5];\n\n        for (int i = 0; i < n; i++) {\n            gr[i] = new ArrayList<>();\n        }\n\n        for (int i = 0; i < n - 1; i ++) {\n            int u = scanner.nextInt() - 1, v = scanner.nextInt() - 1;\n            gr[u].add(v);\n            gr[v].add(u);\n        }\n\n        k = n - k - 1;\n        ans[n - 1] = true;\n\n        init(n - 1 , n - 1);\n\n        int t, d, next;\n        for (int i = n - 2; i >= 0; i--) {\n            t = i;\n            d = 1;\n            if (ans[i]) {\n                continue;\n            }\n            for (int j = 20; j >= 0; j--){\n                next = dp[j][t];\n                if (next != -1 && !ans[next]) {\n                    t = next;\n                    d +=  1 << j;\n                }\n            }\n\n            if (d <= k) {\n                k -=d;\n                t = i;\n\n                while (!ans[t]) {\n                    ans[t] = true;\n                    t = dp[0][t];\n                }\n            }\n            if (k == 0) {\n                break;\n            }\n        }\n        StringBuilder sb = new StringBuilder(\"\");\n        for (int i = 0; i < n; i++) {\n            if (!ans[i]) {\n                sb.append(i + 1).append(\" \");\n            }\n        }\n        System.out.println(sb.toString());\n    }\n\n    class FastScanner {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "nlogn", "problem": "980_E. The Number Games", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class a {\n  static long mod = 1000000007;\n  static boolean[][] blacks;\npublic static void main(String[] args) throws IOException\n{\n  input.init(System.in);\n  PrintWriter out = new PrintWriter(new PrintStream(System.out));\n  //Scanner input = new Scanner(new File(\"input.txt\"));\n  //PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\n  int n = input.nextInt(), t = input.nextInt();\n  int res = 2;\n  Cottage[] data = new Cottage[n];\n  int[] xs = new int[n], as = new int[n];\n  for(int i = 0; i<n; i++)\n  {\n    data[i] = new Cottage(input.nextInt(), input.nextInt());\n  }\n  Arrays.sort(data);\n  for(int i = 0; i<n; i++)\n  {\n    xs[i] = data[i].x;\n    as[i] = data[i].a;\n  }\n  for(int i = 0; i<n-1; i++)\n  {\n    if(2*(xs[i+1]-xs[i]) == 2*t+as[i]+as[i+1]) res++;\n    else if(2*(xs[i+1]-xs[i]) > 2*t+as[i]+as[i+1]) res+=2;\n  }\n  out.println(res);\n\n  out.close();\n}\nstatic class Cottage implements Comparable<Cottage>\n{\n\n  /* (non-Javadoc)\n   * @see java.lang.Comparable#compareTo(java.lang.Object)\n   */\n  int x, a;\n  public Cottage(int xx, int aa)\n  {\n    x = xx; a = aa;\n  }\n  @Override\n  public int compareTo(Cottage o) {\n    // TODO(mkirsche): Auto-generated method stub\n    return this.x - o.x;\n  }\n\n}\nstatic long pow(long a, long p)\n{\n  if(p==0) return 1;\n  if((p&1) == 0)\n  {\n    long sqrt = pow(a, p/2);\n    return (sqrt*sqrt)%mod;\n  }\n  else\n    return (a*pow(a,p-1))%mod;\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}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Random;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.PrintWriter;\nimport java.io.InputStreamReader;\nimport java.io.File;\n\npublic class Task{\n\t\n\tstatic final boolean readFromFile = false;\n\tstatic final String fileInputName = \"input.txt\",\n\t\t\t\t\t\tfileOutputName = \"output.txt\";\n\t\n\tpublic static void main(String args[]){\n\t\tFileInputStream fileInputStream;\n\t\tFileOutputStream fileOutputStream;\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tif (readFromFile){\n\t\t\ttry{\n\t\t\t\tfileInputStream = new FileInputStream(new File(fileInputName));\n\t\t\t\tfileOutputStream = new FileOutputStream(new File(fileOutputName));\n\t\t\t}catch (FileNotFoundException e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\tPrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);\n\t\tInputReader in  = new InputReader((readFromFile)?fileInputStream:inputStream);\n\t\t\n\t\tSolver s = new Solver(in, out);\n\t\ts.solve();\n\t\t\n\t\tout.close();\n\t}\n}\n\nclass Solver{\n\tprivate PrintWriter out;\n\tprivate InputReader in;\n\t\n\tpublic void solve(){\n\t\tint n = in.nextInt();\n\t\tdouble t = in.nextDouble(),\n\t\t\ta[] = new double[n],\n\t\t\tx[] = new double[n];\n\t\tfor (int i=0;i<n;i++){\n\t\t\tx[i] = in.nextDouble();\n\t\t\ta[i] = in.nextDouble();\n\t\t}\n\t\tint ans = 2;\n\t\tfor (int i=0;i<n-1;i++)\n\t\t\tfor (int j=i+1;j<n;j++)\n\t\t\t\tif (x[j]<x[i]){\n\t\t\t\t\tdouble buf = x[i];x[i]=x[j];x[j]=buf;\n\t\t\t\t\tbuf = a[i]; a[i]=a[j];a[j]=buf;\n\t\t\t\t}\n\t\t\n\t\tfor (int i=0;i<n-1;i++){\n\t\t\tif (x[i]+a[i]/2+t<x[i+1]-a[i+1]/2)\n\t\t\t\tans += 2;\n\t\t\tif (x[i]+a[i]/2+t==x[i+1]-a[i+1]/2)\n\t\t\t\tans++;\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tSolver(InputReader in, PrintWriter out){\n\t\tthis.in = in;\n\t\tthis.out = out;\n\t}\n}\n\nclass InputReader{\n\tStringTokenizer tok;\n\tBufferedReader buf;\n\t\n\tInputReader(InputStream in){\n\t\ttok = null;\n\t\tbuf = new BufferedReader(new InputStreamReader(in));\n\t}\n\n\tInputReader(FileInputStream in){\n\t\ttok = null;\n\t\tbuf = new BufferedReader(new InputStreamReader(in));\n\t}\n\t\n\tpublic String next(){\n\t\twhile (tok==null || !tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(buf.readLine());\n\t\t\t}catch (IOException e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\t\n\tpublic int nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n\tpublic double nextDouble(){\n\t\treturn Double.parseDouble(next());\n\t}\n\tpublic float nextFloat(){\n\t\treturn Float.parseFloat(next());\n\t}\n\tpublic String nextLine(){\n\t\ttry{\n\t\t\treturn buf.readLine();\n\t\t}catch (IOException e){\n\t\t\treturn null;\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "    import java.awt.Point;\nimport java.io.*;\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            Pair<Double,Double>[] p;\n            int n, t;\n            \n            int find() {\n                int count = 2;\n                \n                for(int i = 0; i < n-1; ++i) {\n                    double dif = p[i+1].a-p[i].b;\n                    int comp = Double.compare(dif,t);\n                    \n                    if(comp==0)\n                        count+=1;\n                    else\n                        if(comp>0)\n                            count+=2;\n                }\n                \n                return count;\n            }\n            \n            @Override\n            public void run() {\n                n = nextInt();\n                t = nextInt();\n                \n                p = new Pair[n];\n                for(int i = 0; i < n; ++i) {\n                    int x = nextInt()+1000;\n                    int a = nextInt();\n                    \n                    double h = a/(double)2;\n                    p[i] = new Pair<Double,Double>(x-h,x+h);\n                }\n                \n                Arrays.sort(p, new PComparator());\n                print(find());\n                close();\n            }\n            \n            class PComparator implements Comparator<Pair<Double,Double>> {\n                @Override\n                public int compare(Pair<Double, Double> o1,\n                        Pair<Double, Double> o2) {\n                    \n                    return Double.compare(o1.a, o2.a);\n                }\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<A, B> {\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<A, B> p) {\n                a = p.f();\n                b = p.s();\n            }\n            \n            @Override\n            public String toString() {\n                return a+\" \"+b;\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    }", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n\npublic class A {\n\t\n\tpublic static double EPS = .001;\n\t\n\tpublic class House implements Comparable<House> {\n\t\tint x;\n\t\tint a;\n\t\t\n\t\tpublic House(int mx, int ma) {\n\t\t\tx = mx;\n\t\t\ta = ma;\n\t\t}\n\n\t\tpublic int compareTo(House o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t\t\n\t\tpublic double right() {\n\t\t\treturn (double)x + ((double)a)/2.0;\n\t\t}\n\t\t\n\t\tpublic double left() {\n\t\t\treturn (double)x - ((double)a)/2.0;\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew A().solve();\n\t}\n\t\n\t\n\tpublic void solve() {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tint t = in.nextInt();\n\t\t\n\t\tArrayList<House> houses = new ArrayList<House>();\n\t\t\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint x = in.nextInt();\n\t\t\tint a = in.nextInt();\n\t\t\thouses.add(new House(x,a));\n\t\t}\n\t\t\n\t\tCollections.sort(houses);\n\t\t\n\t\t\n\t\tint total = 2;\n\t\t\n\t\tfor(int i=0;i<houses.size()-1;i++) {\n\t\t\tHouse me = houses.get(i);\n\t\t\tHouse next = houses.get(i+1);\n\t\t\tdouble meright = me.right();\n\t\t\tdouble nextleft = next.left();\n\t\t\tdouble diff = nextleft - meright;\n\t\t\tif(diff-EPS > ((double)t)) {\n\t\t\t\ttotal += 2;\n\t\t\t}\n\t\t\telse if(diff+EPS > ((double)t)) {\n\t\t\t\ttotal += 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(total);\n\t}\n\t\n}\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Village {\n\tprivate class House implements Comparable<House>{\n\t\tDouble Coordinate;\n\t\tDouble Sidelength;\n\t\tpublic House(double coordinate, double sidelength) {\n\t\t\tCoordinate = coordinate;\n\t\t\tSidelength = sidelength;\n\t\t}\n\t\tpublic int compareTo(House o) {\n\t\t\treturn Coordinate.compareTo(o.Coordinate);\n\t\t}\n\t}\n\t\n\t\n\tpublic static void main(String args[]) {\n\t\tVillage v = new Village();\n\t\tv.solve();\n\t}\n\tpublic void solve() {\n\tScanner in = new Scanner(System.in);\n\tint numhouse = in.nextInt();\n\tdouble requireside = in.nextDouble();\n\t//System.out.println(numhouse);\n\t//System.out.println(requireside);\t\t\n\tArrayList<House> coordinate = new ArrayList<House>();\n\tArrayList<Double> sidelength = new ArrayList<Double>();\t\n\twhile (in.hasNext()) {\n\t\tdouble coo = in.nextDouble();\n\t\tdouble side = in.nextDouble();\n\t\t//System.out.println(coo);\n\t\t//System.out.println(side);\n\t\tcoordinate.add(new House(coo,side));\n\t\tsidelength.add(side);\n\t\t}\n\tCollections.sort(coordinate);\n\tArrayList<Double> edges = new ArrayList<Double>();\n\tint count = 2;\n\tfor (int i = 0; i < coordinate.size();i++) {\n\t\tedges.add(coordinate.get(i).Coordinate - (double)coordinate.get(i).Sidelength/(double)2);\n\t\tedges.add(coordinate.get(i).Coordinate + (double)coordinate.get(i).Sidelength/(double)2);\n\t}\n\tArrayList<Double> difference = new ArrayList<Double>();\n\tfor (int i = 1; i < edges.size() - 1; i++) {\n\t\tdifference.add(Math.abs(edges.get(i) - edges.get(i+1)));\n\t}\n\tfor (int i = 0; i < difference.size(); i+=2) {\n\t\tif (difference.get(i) == requireside) count++;\n\t\telse if (difference.get(i) > requireside) count+=2;\n\t}\n\tSystem.out.println(count);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A15 {\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\t\t\n\t\tint n = nextInt(), t = nextInt();\n\t\t\n\t\tint[] x = new int[n];\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = nextInt();\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tboolean left = true, right = true;\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\tif (x[j] < x[i] && a[i] + 2*t + a[j] >= 2*Math.abs(x[i] - x[j])) left = false;\n\t\t\t\telse if (x[j] > x[i] && a[i] + 2*t + a[j] > 2*Math.abs(x[i] - x[j])) right = false;\n\t\t\tif (left) ans++;\n\t\t\tif (right) ans++;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t\t\n\t\tout.flush();\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\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 CottageTown {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        String[] in = sc.nextLine().split(\" \");\n        int n = Integer.parseInt(in[0]);\n        int t = Integer.parseInt(in[1]);\n\n        int[] coor = new int[n];\n        int[] side = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            in = sc.nextLine().split(\" \");\n            coor[i] = Integer.parseInt(in[0]);\n            side[i] = Integer.parseInt(in[1]);\n        }\n\n        quickSort(coor, 0, n - 1, side);\n\n        int count = 2;\n        double dist;\n        for (int i = 0; i < n - 1; i++) {\n            dist = (coor[i + 1] - coor[i]) - (double)(side[i + 1] + side[i]) / 2.0;\n            if (dist > t) {\n                count += 2;\n            } else if (dist == t) {\n                count += 1;\n            }\n        }\n\n        System.out.println(count);\n\n    }\n\n    private static int partition(int[] arr, int left, int right, int[] temp) {\n        int i = left, j = right;\n        int tmp;\n        int pivot = arr[(left + right) / 2];\n\n        while (i <= j) {\n            while (arr[i] < pivot) {\n                i++;\n            }\n            while (arr[j] > pivot) {\n                j--;\n            }\n            if (i <= j) {\n                tmp = arr[i];\n                arr[i] = arr[j];\n                arr[j] = tmp;\n\n                tmp = temp[i];\n                temp[i] = temp[j];\n                temp[j] = tmp;\n\n                i++;\n                j--;\n            }\n        }\n\n        return i;\n    }\n\n    private static void quickSort(int[] arr, int left, int right, int[] temp) {\n        int index = partition(arr, left, right, temp);\n        if (left < index - 1) {\n            quickSort(arr, left, index - 1, temp);\n        }\n        if (index < right) {\n            quickSort(arr, index, right, temp);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class Flatwile {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int t = sc.nextInt();\n        int[] c = new int[n];\n        int[] a = new int[n];\n        for (int i=0; i<n; i++){\n            c[i] = sc.nextInt();\n            a[i] = sc.nextInt();\n        }\n        sort(c, a);\n        int res = 1;\n        double prev = Integer.MIN_VALUE;\n        for(int i=0; i<c.length; i++){\n            if (c[i]-a[i]/2d - prev >=t){\n                res++;\n            }\n            if (i!=c.length-1 && c[i+1]-a[i+1]/2d-(c[i]+a[i]/2d)>t ){\n                res++;\n            }\n            prev = c[i] +a[i]/2d;\n        }\n        System.out.println(res);\n    }\n\n    private static void sort(int[] a, int[] b){\n        for(int i=0; i<a.length; i++){\n            for(int j=i+1; j<a.length; j++){\n                if (a[i]>a[j]){\n                    swap(a, i, j);\n                    swap(b, i, j);\n                }\n            }\n        }\n    }\n\n    private 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", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        new A().solve();\n    }\n    \n    public void solve() {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int t = sc.nextInt();\n        float[] left = new float[n];\n        float[] right = new float[n];\n        for (int i=0; i<n; ++i) {\n            int c = sc.nextInt();\n            int w = sc.nextInt();\n            left[i] = (float) (c - (float) w * 1.0 / 2);\n            right[i] = (float) (c + (float) w * 1.0 / 2);\n        }\n        for (int i=0; i<n; ++i)\n            for (int j=i+1; j<n; ++j)\n                if (left[j] < left[i]) {\n                    float tmp = left[i];\n                    left[i] = left[j];\n                    left[j] = tmp;\n                    tmp = right[i];\n                    right[i] = right[j];\n                    right[j] = tmp;\n                }\n        int res = 2;\n        for (int i=1; i<n; ++i) {\n            float dis = left[i] - right[i-1];\n            if (Math.abs(dis - t) < 0.000001)\n                res ++;\n            if ((dis - t) > 0.000001)\n                res += 2;\n        }\n        System.out.println(res);\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Houses implements Runnable {\n    private void solve() throws IOException {\n        int n = nextInt();\n        int t = nextInt();\n        int[] x = new int[n];\n        int[] a = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt() * 2;\n            a[i] = nextInt();\n        }\n        Set<Integer> res = new HashSet<Integer>();\n        for (int i = 0; i < n; ++i) {\n            if (valid(n, t, x, a, x[i] + a[i] + t))\n                res.add(x[i] + a[i] + t);\n            if (valid(n, t, x, a, x[i] - a[i] - t))\n                res.add(x[i] - a[i] - t);\n        }\n        writer.println(res.size());\n    }\n\n    private boolean valid(int n, int t, int[] x, int[] a, int pos) {\n        for (int i = 0; i < n; ++i) {\n            if (Math.abs(pos - x[i]) < a[i] + t)\n                return false;\n        }\n        return true;\n    }\n\n    public static void main(String[] args) {\n        new Houses().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}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class C15A {\n    public static void main(String args[]){\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        int t=sc.nextInt();\n        double nm[][]=new double[n][2];\n        int a=0;\n        int b=0;\n        for(int i=0;i<n;i++){\n            a=sc.nextInt();\n            b=sc.nextInt();\n            nm[i][0]=a-(double)b/2;\n            nm[i][1]=a+(double)b/2;\n        }\n\n\n        Arrays.sort(nm, new ArrayColumnComparator(1));\n\n        int sum=0;\n        for(int i=0;i<n-1;i++){\n            if(nm[i+1][0]-nm[i][1]==t)\n                sum++;\n            else if(nm[i+1][0]-nm[i][1]>t){\n                sum+=2;\n            }\n\n        }\n\n        System.out.println(sum+2);\n    }\n\n}\nclass ArrayColumnComparator implements Comparator {\n    private int cm = 0;\n    ArrayColumnComparator(int cm) {\n        this.cm = cm;\n    }\n    public int compare(Object o1, Object o2) {\n        double[] row1 = (double[])o1;\n        double[] row2 = (double[])o2;\n        int i;\n        if (row1[cm]>row2[cm])\n            i=1;\n        else if(row1[cm]<row2[cm])\n            i=-1;\n        else i=0;\n        return i;\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main{\n  public static void main(String[] args){\n    new Main().run();\n  }\n  \n  void run(){\n    Scanner sc = new Scanner(System.in);\n    int n = sc.nextInt();\n    int t = sc.nextInt() * 2;\n    H[] tbl = new H[n];\n    for(int i = 0; i < n; i++)tbl[i] = new H(sc.nextInt()*2, sc.nextInt()*2);\n    Arrays.sort(tbl);\n    TreeSet<Integer> cand = new TreeSet<Integer>();\n    //cand.add(tbl[0].x - tbl[0].len / 2);\n    for(int i = 0; i < n; i++){\n      int left = tbl[i].x - tbl[i].len / 2 - t / 2;\n      if(!cand.contains(left)){\n        if(i > 0 && tbl[i-1].x + tbl[i-1].len/2 > left - t/2){\n          \n        }else{\n          cand.add(left);\n        }\n      }\n      int right = tbl[i].x + tbl[i].len / 2 + t/2;\n      if(!cand.contains(right)){\n        if(i < n-1 && tbl[i+1].x - tbl[i+1].len/2 < right + t/2){\n          \n        }else{\n          cand.add(right);\n        }\n      }\n    }\n    System.out.println(cand.size());\n  }\n  \n  class H implements Comparable<H>{\n    int x, len;\n    H(int a, int b){\n      x = a;\n      len = b;\n    }\n    public int compareTo(H h){\n      return this.x - h.x;\n    }\n  }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class j\n{\npublic static void main(String a[])throws IOException\n{\nBufferedReader b=new BufferedReader(new InputStreamReader(System.in));\nint k=0,i=0,j=0,n=0,p=0,t=0;\nString s;\ns=b.readLine();\nStringTokenizer c=new StringTokenizer(s);\nn=Integer.parseInt(c.nextToken());\nk=Integer.parseInt(c.nextToken());\nint d[]=new int[n];\nint e[]=new int[n];\nfor(i=0;i<n;i++)\n{\ns=b.readLine();\nStringTokenizer z=new StringTokenizer(s);\nd[i]=Integer.parseInt(z.nextToken());\ne[i]=Integer.parseInt(z.nextToken());\n}\nfor(i=0;i<n-1;i++)\n{\nfor(j=i+1;j<n;j++)\n{\nif(d[j]<d[i])\n{\nt=d[j];\nd[j]=d[i];\nd[i]=t;\nt=e[j];\ne[j]=e[i];\ne[i]=t;\n}\n}\n}\nfor(i=0;i<n-1;i++)\n{\nif(((d[i+1]-e[i+1]/2.0)-(d[i]+e[i]/2.0))>k)\np+=2;\nif(((d[i+1]-e[i+1]/2.0)-(d[i]+e[i]/2.0))==k)\np++;\n}\nSystem.out.print(p+2);\n}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.*;\nimport java.util.*;\n\npublic class CottageVillage {\n\n\tstatic BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st;\n\n\tstatic String LINE() throws Exception { return stdin.readLine(); }\n\tstatic String TOKEN() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE());\n\t\treturn st.nextToken();\n\t}\n\tstatic int INT() throws Exception {return Integer.parseInt(TOKEN());}\n\tstatic long LONG() throws Exception {return Long.parseLong(TOKEN());}\n\tstatic double DOUBLE() throws Exception {return Double.parseDouble(TOKEN());}\n\n\tstatic DecimalFormat DF = new DecimalFormat(\"0.000\",new DecimalFormatSymbols(Locale.ENGLISH));\n\t\n\tpublic static final double EPSILON = 1E-9;\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tint N = INT(), T = INT();\n\t\tHouse[] list = new House[N];\n\t\tfor(int i = 0;i<N;i++) {\n\t\t\tlist[i] = new House(INT(),INT());\n\t\t}\n\t\tArrays.sort(list);\n\t\tint cnt = 2;\n\t\tfor(int i = 1;i<N;i++) {\n\t\t\tint room = list[i].center-list[i-1].center;\n\t\t\tif(2*T<2*room-list[i].side-list[i-1].side)cnt += 2;\n\t\t\telse if(2*T==2*room-list[i].side-list[i-1].side)cnt++;\n\t\t}\n\t\tSystem.out.println(cnt);\n\t\t\n\t}\n\t\n\tprivate static class House implements Comparable<House> {\n\t\tint center, side;\n\t\tHouse(int c, int s) {\n\t\t\tthis.center = c;\n\t\t\tthis.side = s;\n\t\t}\n\t\tpublic int compareTo(House h) {\n\t\t\treturn this.center-h.center;\n\t\t}\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class A {\n\n    static class Entity implements Comparable {\n\n        public Entity(int x, int a) {\n            this.x = x;\n            this.a = a;\n        }\n        public int x, a;\n\n        public int compareTo(Object t) {\n            Entity o = (Entity) t;\n            return x == o.x ? 0 : x < o.x ? -1 : 1;\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt(), t = 2 * scanner.nextInt();\n        if (1 == n) {\n            System.out.println(2);\n        } else {\n            int rez = 2;\n            ArrayList<Entity> list = new ArrayList<Entity>();\n            for (int i = 0; i < n; i++) {\n                list.add(new Entity(scanner.nextInt(), scanner.nextInt()));\n            }\n            Collections.sort(list);\n            for (int i = 1; i < n; i++) {\n                int num = 2 * (list.get(i).x - list.get(i - 1).x)\n                        - list.get(i).a - list.get(i - 1).a;\n                if (t < num) {\n                    rez += 2;\n                } else if (t == num) {\n                    rez++;\n                }\n            }\n            System.out.println(rez);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "/*\n * Hello! You are trying to hack my solution, are you? =)\n * Don't be afraid of the size, it's just a dump of useful methods like gcd, or n-th Fib number.\n * And I'm just too lazy to create a new .java for every task.\n * And if you were successful to hack my solution, please, send me this test as a message or to Abrackadabraa@gmail.com.\n * It can help me improve my skills and i'd be very grateful for that.\n * Sorry for time you spent reading this message. =)\n * Good luck, unknown rival. =)\n * */\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Abra {\n\t// double d = 2.2250738585072012e-308;\n\tvoid solve() throws IOException {\n\t\t int n = nextInt(), t = nextInt();\n\t\t TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();\n\t\t for (int i = 0; i < n; i++)\n\t\t\t tm.put(nextInt(), nextInt());\n\t\t double tx = -1e9;\n\t\t int c = 2;\n\t\t for (Map.Entry<Integer, Integer> m : tm.entrySet()) {\n\t\t\t if (tx == -1e9) {\n\t\t\t\t tx = m.getKey() + m.getValue() / 2.0 + t;\n\t\t\t\t continue;\n\t\t\t }\n\t\t\t if (m.getKey() - m.getValue() / 2.0 >= tx) c++;\n\t\t\t if (m.getKey() - m.getValue() / 2.0 > tx) c++;\n\t\t\t tx = m.getKey() + m.getValue() / 2.0 + t;\n\t\t }\n\t\t out.print(c);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Abra().run();\n\t}\n\n\tStreamTokenizer in;\n\tPrintWriter out;\n\tboolean oj;\n\tBufferedReader br;\n\n\tvoid init() throws IOException {\n\t\toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tReader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\tWriter writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n\t\tbr = new BufferedReader(reader);\n\t\tin = new StreamTokenizer(br);\n\t\tout = new PrintWriter(writer);\n\t}\n\n\tlong beginTime;\n\t\n\tvoid run() throws IOException {\n\t\tbeginTime = System.currentTimeMillis();\n\t\tlong beginMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n\t\tinit();\n\t\tsolve();\n\t\tlong endMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n\t\tlong endTime = System.currentTimeMillis();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(\"Memory used = \" + (endMem - beginMem));\n\t\t\tSystem.out.println(\"Total memory = \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));\n\t\t\tSystem.out.println(\"Running time = \" + (endTime - beginTime));\n\t\t}\n\t\tout.flush();\n\t}\n\n\tint nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tlong nextLong() throws IOException {\n\t\tin.nextToken();\n\t\treturn (long) in.nval;\n\t}\n\n\tString nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.nval;\n\t}\n\n\tmyLib lib = new myLib();\n\t\n\tvoid time() {\n\t\tSystem.out.print(\"It's \");\n\t\tSystem.out.println(System.currentTimeMillis() - beginTime);\n\t}\n\n\tstatic class myLib {\n\t\tlong fact(long x) {\n\t\t\tlong a = 1;\n\t\t\tfor (long i = 2; i <= x; i++) {\n\t\t\t\ta *= i;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitSum(String x) {\n\t\t\tlong a = 0;\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\ta += x.charAt(i) - '0';\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitSum(long x) {\n\t\t\tlong a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitMul(long x) {\n\t\t\tlong a = 1;\n\t\t\twhile (x > 0) {\n\t\t\t\ta *= x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint digitCubesSum(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += (x % 10) * (x % 10) * (x % 10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble pif(double ax, double ay, double bx, double by) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n\t\t}\n\n\t\tdouble pif3D(double ax, double ay, double az, double bx, double by, double bz) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by) + (az - bz) * (az - bz));\n\t\t}\n\n\t\tdouble pif3D(double[] a, double[] b) {\n\t\t\treturn Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));\n\t\t}\n\n\t\tlong gcd(long a, long b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tlong c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tlong c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint gcd(int a, int b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tint c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tint c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tlong lcm(long a, long b) {\n\t\t\treturn a * b / gcd(a, b);\n\t\t}\n\n\t\tint lcm(int a, int b) {\n\t\t\treturn a * b / gcd(a, b);\n\t\t}\n\n\t\tint countOccurences(String x, String y) {\n\t\t\tint a = 0, i = 0;\n\t\t\twhile (true) {\n\t\t\t\ti = y.indexOf(x);\n\t\t\t\tif (i == -1) break;\n\t\t\t\ta++;\n\t\t\t\ty = y.substring(i + 1);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint[] findPrimes(int x) {\n\t\t\tboolean[] forErato = new boolean[x - 1];\n\t\t\tList<Integer> t = new Vector<Integer>();\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<Integer> iterator = t.iterator();\n\t\t\tfor (int i = 0; iterator.hasNext(); i++) {\n\t\t\t\tprimes[i] = iterator.next().intValue();\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint rev(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta = a * 10 + x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tclass myDate {\n\t\t\tint d, m, y;\n\n\t\t\tint[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n\t\t\tpublic myDate(int da, int ma, int ya) {\n\t\t\t\td = da;\n\t\t\t\tm = ma;\n\t\t\t\ty = ya;\n\t\t\t\tif ((ma > 12 || ma < 1 || da > ml[ma - 1] || da < 1) && !(d == 29 && m == 2 && y % 4 == 0)) {\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t\ty = 9999999;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid incYear(int x) {\n\t\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\t\ty++;\n\t\t\t\t\tif (m == 2 && d == 29) {\n\t\t\t\t\t\tm = 3;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (m == 3 && d == 1) {\n\t\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\t\tm = 2;\n\t\t\t\t\t\t\td = 29;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tboolean less(myDate x) {\n\t\t\t\tif (y < x.y) return true;\n\t\t\t\tif (y > x.y) return false;\n\t\t\t\tif (m < x.m) return true;\n\t\t\t\tif (m > x.m) return false;\n\t\t\t\tif (d < x.d) return true;\n\t\t\t\tif (d > x.d) return false;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tvoid inc() {\n\t\t\t\tif ((d == 31) && (m == 12)) {\n\t\t\t\t\ty++;\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\tml[1] = 29;\n\t\t\t\t\t}\n\t\t\t\t\tif (d == ml[m - 1]) {\n\t\t\t\t\t\tm++;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t} else\n\t\t\t\t\t\td++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint partition(int n, int l, int m) {// n - sum, l - length, m - every\n\t\t\t\t\t\t\t\t\t\t\t// part\n\t\t\t// <= m\n\t\t\tif (n < l) return 0;\n\t\t\tif (n < l + 2) return 1;\n\t\t\tif (l == 1) return 1;\n\t\t\tint c = 0;\n\t\t\tfor (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n\t\t\t\tc += partition(n - i, l - 1, i);\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint rifmQuality(String a, String b) {\n\t\t\tif (a.length() > b.length()) {\n\t\t\t\tString c = a;\n\t\t\t\ta = b;\n\t\t\t\tb = c;\n\t\t\t}\n\t\t\tint c = 0, d = b.length() - a.length();\n\t\t\tfor (int i = a.length() - 1; i >= 0; i--) {\n\t\t\t\tif (a.charAt(i) == b.charAt(i + d)) c++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tString numSym = \"0123456789ABCDEF\";\n\n\t\tString ZFromXToYNotation(int x, int y, String z) {\n\t\t\tif (z.equals(\"0\")) return \"0\";\n\t\t\tString a = \"\";\n\t\t\t// long q = 0, t = 1;\n\t\t\tBigInteger q = BigInteger.ZERO, t = BigInteger.ONE;\n\t\t\tfor (int i = z.length() - 1; i >= 0; i--) {\n\t\t\t\tq = q.add(t.multiply(BigInteger.valueOf(z.charAt(i) - 48)));\n\t\t\t\tt = t.multiply(BigInteger.valueOf(x));\n\t\t\t}\n\t\t\twhile (q.compareTo(BigInteger.ZERO) == 1) {\n\t\t\t\ta = numSym.charAt((int) (q.mod(BigInteger.valueOf(y)).intValue())) + a;\n\t\t\t\tq = q.divide(BigInteger.valueOf(y));\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble angleFromXY(int x, int y) {\n\t\t\tif ((x == 0) && (y > 0)) return Math.PI / 2;\n\t\t\tif ((x == 0) && (y < 0)) return -Math.PI / 2;\n\t\t\tif ((y == 0) && (x > 0)) return 0;\n\t\t\tif ((y == 0) && (x < 0)) return Math.PI;\n\t\t\tif (x > 0) return Math.atan((double) y / x);\n\t\t\telse {\n\t\t\t\tif (y > 0) return Math.atan((double) y / x) + Math.PI;\n\t\t\t\telse\n\t\t\t\t\treturn Math.atan((double) y / x) - Math.PI;\n\t\t\t}\n\t\t}\n\n\t\tstatic boolean isNumber(String x) {\n\t\t\ttry {\n\t\t\t\tInteger.parseInt(x);\n\t\t\t} catch (NumberFormatException ex) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tstatic boolean stringContainsOf(String x, String c) {\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\tif (c.indexOf(x.charAt(i)) == -1) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tlong pow(long a, long n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tlong k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint pow(int a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tint k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble pow(double a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tdouble k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble log2(double x) {\n\t\t\treturn Math.log(x) / Math.log(2);\n\t\t}\n\n\t\tint lpd(int[] primes, int x) {// least prime divisor\n\t\t\tint i;\n\t\t\tfor (i = 0; primes[i] <= x / 2; i++) {\n\t\t\t\tif (x % primes[i] == 0) {\n\t\t\t\t\treturn primes[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t;\n\t\t\treturn x;\n\t\t}\n\n\t\tint np(int[] primes, int x) {// number of prime number\n\t\t\tfor (int i = 0; true; i++) {\n\t\t\t\tif (primes[i] == x) return i;\n\t\t\t}\n\t\t}\n\n\t\tint[] dijkstra(int[][] map, int n, int s) {\n\t\t\tint[] p = new int[n];\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tArrays.fill(p, Integer.MAX_VALUE);\n\t\t\tp[s] = 0;\n\t\t\tb[s] = true;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i != s) p[i] = map[s][i];\n\t\t\t}\n\t\t\twhile (true) {\n\t\t\t\tint m = Integer.MAX_VALUE, mi = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (!b[i] && (p[i] < m)) {\n\t\t\t\t\t\tmi = i;\n\t\t\t\t\t\tm = p[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (mi == -1) break;\n\t\t\t\tb[mi] = true;\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif (p[mi] + map[mi][i] < p[i]) p[i] = p[mi] + map[mi][i];\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\n\t\tboolean isLatinChar(char x) {\n\t\t\tif (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z'))) return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isBigLatinChar(char x) {\n\t\t\tif (x >= 'A' && x <= 'Z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isSmallLatinChar(char x) {\n\t\t\tif (x >= 'a' && x <= 'z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isDigitChar(char x) {\n\t\t\tif (x >= '0' && x <= '9') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tclass NotANumberException extends Exception {\n\t\t\tprivate static final long serialVersionUID = 1L;\n\t\t\tString mistake;\n\n\t\t\tNotANumberException() {\n\t\t\t\tmistake = \"Unknown.\";\n\t\t\t}\n\n\t\t\tNotANumberException(String message) {\n\t\t\t\tmistake = message;\n\t\t\t}\n\t\t}\n\n\t\tclass Real {\n\t\t\tString num = \"0\";\n\t\t\tlong exp = 0;\n\t\t\tboolean pos = true;\n\n\t\t\tlong length() {\n\t\t\t\treturn num.length();\n\t\t\t}\n\n\t\t\tvoid check(String x) throws NotANumberException {\n\t\t\t\tif (!stringContainsOf(x, \"0123456789+-.eE\")) throw new NotANumberException(\"Illegal character.\");\n\t\t\t\tlong j = 0;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif ((x.charAt((int) i) == '-') || (x.charAt((int) i) == '+')) {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected sign.\");\n\t\t\t\t\t} else\n\t\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\t\tif (j == 0) j = 2;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (j == 1) j = 2;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 2)\n\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 3) j = 4;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tif (j == 4)\n\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (j == 6)\n\t\t\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected digit.\");\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\t\t\tif (j == 0) j = 3;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 1) j = 3;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 2) j = 3;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected dot.\");\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\t\t\t\tif (j == 2) j = 5;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 4) j = 5;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected exponent.\");\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"O_o.\");\n\t\t\t\t}\n\t\t\t\tif ((j == 0) || (j == 1) || (j == 3) || (j == 5)) throw new NotANumberException(\"Unexpected end.\");\n\t\t\t}\n\n\t\t\tpublic Real(String x) throws NotANumberException {\n\t\t\t\tcheck(x);\n\t\t\t\tif (x.charAt(0) == '-') pos = false;\n\t\t\t\tlong j = 0;\n\t\t\t\tString e = \"\";\n\t\t\t\tboolean epos = true;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\tif (j == 0) num += x.charAt((int) i);\n\t\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\t\tnum += x.charAt((int) i);\n\t\t\t\t\t\t\texp--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (j == 2) e += x.charAt((int) i);\n\t\t\t\t\t}\n\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\tj = 2;\n\t\t\t\t\t\tif (x.charAt((int) (i + 1)) == '-') epos = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(0) == '0'))\n\t\t\t\t\tnum = num.substring(1);\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(num.length() - 1) == '0')) {\n\t\t\t\t\tnum = num.substring(0, num.length() - 1);\n\t\t\t\t\texp++;\n\t\t\t\t}\n\t\t\t\tif (num.equals(\"0\")) {\n\t\t\t\t\texp = 0;\n\t\t\t\t\tpos = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\twhile ((e.length() > 1) && (e.charAt(0) == '0'))\n\t\t\t\t\te = e.substring(1);\n\t\t\t\ttry {\n\t\t\t\t\tif (e != \"\") if (epos) exp += Long.parseLong(e);\n\t\t\t\t\telse\n\t\t\t\t\t\texp -= Long.parseLong(e);\n\t\t\t\t} catch (NumberFormatException exc) {\n\t\t\t\t\tif (!epos) {\n\t\t\t\t\t\tnum = \"0\";\n\t\t\t\t\t\texp = 0;\n\t\t\t\t\t\tpos = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new NotANumberException(\"Too long exponent\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic Real() {\n\t\t\t}\n\n\t\t\tString toString(long mantissa) {\n\t\t\t\tString a = \"\", b = \"\";\n\t\t\t\tif (exp >= 0) {\n\t\t\t\t\ta = num;\n\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\tfor (long i = 0; i < exp; i++)\n\t\t\t\t\t\ta += '0';\n\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\tb += '0';\n\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t} else {\n\t\t\t\t\tif (exp + length() <= 0) {\n\t\t\t\t\t\ta = \"0\";\n\t\t\t\t\t\tif (mantissa == 0) {\n\t\t\t\t\t\t\treturn a;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (mantissa < -(exp + length() - 1)) {\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tif (i < -(exp + length())) b += '0';\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (i + exp >= 0) b += '0';\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tb += num.charAt((int) (i + exp + length()));\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!pos) a = \"-\";\n\t\t\t\t\t\tfor (long i = 0; i < exp + length(); i++)\n\t\t\t\t\t\t\ta += num.charAt((int) i);\n\t\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\t\tfor (long i = exp + length(); i < exp + length() + mantissa; i++)\n\t\t\t\t\t\t\tif (i < length()) b += num.charAt((int) i);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tboolean containsRepeats(int... num) {\n\t\t\tSet<Integer> s = new TreeSet<Integer>();\n\t\t\tfor (int d : num)\n\t\t\t\tif (!s.contains(d)) s.add(d);\n\t\t\t\telse\n\t\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\n\t\tint[] rotateDice(int[] a, int n) {\n\t\t\tint[] c = new int[6];\n\t\t\tif (n == 0) {\n\t\t\t\tc[0] = a[1];\n\t\t\t\tc[1] = a[5];\n\t\t\t\tc[2] = a[2];\n\t\t\t\tc[3] = a[0];\n\t\t\t\tc[4] = a[4];\n\t\t\t\tc[5] = a[3];\n\t\t\t}\n\t\t\tif (n == 1) {\n\t\t\t\tc[0] = a[2];\n\t\t\t\tc[1] = a[1];\n\t\t\t\tc[2] = a[5];\n\t\t\t\tc[3] = a[3];\n\t\t\t\tc[4] = a[0];\n\t\t\t\tc[5] = a[4];\n\t\t\t}\n\t\t\tif (n == 2) {\n\t\t\t\tc[0] = a[3];\n\t\t\t\tc[1] = a[0];\n\t\t\t\tc[2] = a[2];\n\t\t\t\tc[3] = a[5];\n\t\t\t\tc[4] = a[4];\n\t\t\t\tc[5] = a[1];\n\t\t\t}\n\t\t\tif (n == 3) {\n\t\t\t\tc[0] = a[4];\n\t\t\t\tc[1] = a[1];\n\t\t\t\tc[2] = a[0];\n\t\t\t\tc[3] = a[3];\n\t\t\t\tc[4] = a[5];\n\t\t\t\tc[5] = a[2];\n\t\t\t}\n\t\t\tif (n == 4) {\n\t\t\t\tc[0] = a[0];\n\t\t\t\tc[1] = a[2];\n\t\t\t\tc[2] = a[3];\n\t\t\t\tc[3] = a[4];\n\t\t\t\tc[4] = a[1];\n\t\t\t\tc[5] = a[5];\n\t\t\t}\n\t\t\tif (n == 5) {\n\t\t\t\tc[0] = a[0];\n\t\t\t\tc[1] = a[4];\n\t\t\t\tc[2] = a[1];\n\t\t\t\tc[3] = a[2];\n\t\t\t\tc[4] = a[3];\n\t\t\t\tc[5] = a[5];\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint min(int... a) {\n\t\t\tint c = Integer.MAX_VALUE;\n\t\t\tfor (int d : a)\n\t\t\t\tif (d < c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint max(int... a) {\n\t\t\tint c = Integer.MIN_VALUE;\n\t\t\tfor (int d : a)\n\t\t\t\tif (d > c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint pos(int x) {\n\t\t\tif (x > 0) return x;\n\t\t\telse\n\t\t\t\treturn 0;\n\t\t}\n\n\t\tlong pos(long x) {\n\t\t\tif (x > 0) return x;\n\t\t\telse\n\t\t\t\treturn 0;\n\t\t}\n\n\t\tdouble maxD(double... a) {\n\t\t\tdouble c = Double.MIN_VALUE;\n\t\t\tfor (double d : a)\n\t\t\t\tif (d > c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tdouble minD(double... a) {\n\t\t\tdouble c = Double.MAX_VALUE;\n\t\t\tfor (double d : a)\n\t\t\t\tif (d < c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint[] normalizeDice(int[] a) {\n\t\t\tint[] c = a.clone();\n\t\t\tif (c[0] != 0) if (c[1] == 0) c = rotateDice(c, 0);\n\t\t\telse\n\t\t\t\tif (c[2] == 0) c = rotateDice(c, 1);\n\t\t\t\telse\n\t\t\t\t\tif (c[3] == 0) c = rotateDice(c, 2);\n\t\t\t\t\telse\n\t\t\t\t\t\tif (c[4] == 0) c = rotateDice(c, 3);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (c[5] == 0) c = rotateDice(rotateDice(c, 0), 0);\n\t\t\twhile (c[1] != min(c[1], c[2], c[3], c[4]))\n\t\t\t\tc = rotateDice(c, 4);\n\t\t\treturn c;\n\t\t}\n\n\t\tboolean sameDice(int[] a, int[] b) {\n\t\t\tfor (int i = 0; i < 6; i++)\n\t\t\t\tif (a[i] != b[i]) return false;\n\t\t\treturn true;\n\t\t}\n\n\t\tfinal double goldenRatio = (1 + Math.sqrt(5)) / 2;\n\t\tfinal double aGoldenRatio = (1 - Math.sqrt(5)) / 2;\n\n\t\tlong Fib(int n) {\n\t\t\tif (n < 0) if (n % 2 == 0) return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\telse\n\t\t\t\treturn -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\treturn Math.round((pow(goldenRatio, n) - pow(aGoldenRatio, n)) / Math.sqrt(5));\n\t\t}\n\n\t\tclass japaneeseComparator implements Comparator<String> {\n\t\t\t@Override\n\t\t\tpublic int compare(String a, String b) {\n\t\t\t\tint ai = 0, bi = 0;\n\t\t\t\tboolean m = false, ns = false;\n\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') m = true;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') m = true;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\ta += \"!\";\n\t\t\t\tb += \"!\";\n\t\t\t\tint na = 0, nb = 0;\n\t\t\t\twhile (true) {\n\t\t\t\t\tif (a.charAt(ai) == '!') {\n\t\t\t\t\t\tif (b.charAt(bi) == '!') break;\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (b.charAt(bi) == '!') {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (m) {\n\t\t\t\t\t\tint ab = -1, bb = -1;\n\t\t\t\t\t\twhile (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\t\t\tif (ab == -1) ab = ai;\n\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\t\t\tif (bb == -1) bb = bi;\n\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm = !m;\n\t\t\t\t\t\tif (ab == -1) {\n\t\t\t\t\t\t\tif (bb == -1) continue;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (bb == -1) return -1;\n\t\t\t\t\t\twhile (a.charAt(ab) == '0' && ab + 1 != ai) {\n\t\t\t\t\t\t\tab++;\n\t\t\t\t\t\t\tif (!ns) na++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (b.charAt(bb) == '0' && bb + 1 != bi) {\n\t\t\t\t\t\t\tbb++;\n\t\t\t\t\t\t\tif (!ns) nb++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (na != nb) ns = true;\n\t\t\t\t\t\tif (ai - ab < bi - bb) return -1;\n\t\t\t\t\t\tif (ai - ab > bi - bb) return 1;\n\t\t\t\t\t\tfor (int i = 0; i < ai - ab; i++) {\n\t\t\t\t\t\t\tif (a.charAt(ab + i) < b.charAt(bb + i)) return -1;\n\t\t\t\t\t\t\tif (a.charAt(ab + i) > b.charAt(bb + i)) return 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tm = !m;\n\t\t\t\t\t\twhile (true) {\n\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a' && b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') {\n\t\t\t\t\t\t\t\tif (a.charAt(ai) < b.charAt(bi)) return -1;\n\t\t\t\t\t\t\t\tif (a.charAt(ai) > b.charAt(bi)) return 1;\n\t\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a') return 1;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') return -1;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (na < nb) return 1;\n\t\t\t\tif (na > nb) return -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tRandom random = new Random();\n\t}\n\n\tvoid readIntArray(int[] a) throws IOException {\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = nextInt();\n\t}\n\n\tString readChars(int l) throws IOException {\n\t\tString r = \"\";\n\t\tfor (int i = 0; i < l; i++)\n\t\t\tr += (char) br.read();\n\t\treturn r;\n\t}\n\n\tclass myFraction {\n\t\tlong num = 0, den = 1;\n\n\t\tvoid reduce() {\n\t\t\tlong d = lib.gcd(num, den);\n\t\t\tnum /= d;\n\t\t\tden /= d;\n\t\t}\n\n\t\tmyFraction(long ch, long zn) {\n\t\t\tnum = ch;\n\t\t\tden = zn;\n\t\t\treduce();\n\t\t}\n\n\t\tmyFraction add(myFraction t) {\n\t\t\tlong nd = lib.lcm(den, t.den);\n\t\t\tmyFraction r = new myFraction(nd / den * num + nd / t.den * t.num, nd);\n\t\t\tr.reduce();\n\t\t\treturn r;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn num + \"/\" + den;\n\t\t}\n\t}\n\n\tclass myPoint {\n\t\tmyPoint(int a, int b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\n\t\tint x, y;\n\n\t\tboolean equals(myPoint a) {\n\t\t\tif (x == a.x && y == a.y) return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \":\" + y;\n\t\t}\n\t}\n\n\t/*\n\t * class cubeWithLetters { String consts = \"\u0427\u041a\u0422\u0424\u042d\u0426\"; char[][] letters = { {\n\t * '\u0410', '\u0411', '\u0413', '\u0412' }, { '\u0414', '\u0415', '\u0417', '\u0416' }, { '\u0418', '\u041b', '\u041d', '\u041c' }, {\n\t * '\u041e', '\u041f', '\u0421', '\u0420' }, { '\u0423', '\u0425', '\u0429', '\u0428' }, { '\u042b', '\u042c', '\u042f', '\u042e' } };\n\t * \n\t * char get(char x) { if (consts.indexOf(x) != -1) return x; for (int i = 0;\n\t * i < 7; i++) { for (int j = 0; j < 4; j++) { if (letters[i][j] == x) { if\n\t * (j == 0) return letters[i][3]; else return letters[i][j - 1]; } } }\n\t * return '!'; }\n\t * \n\t * void subrotate(int x) { char t = letters[x][0]; letters[x][0] =\n\t * letters[x][3]; letters[x][3] = letters[x][2]; letters[x][2] =\n\t * letters[x][1]; letters[x][1] = t; }\n\t * \n\t * void rotate(int x) { subrotate(x); char t; if (x == 0) { t =\n\t * letters[1][0]; letters[1][0] = letters[2][0]; letters[2][0] =\n\t * letters[3][0]; letters[3][0] = letters[5][2]; letters[5][2] = t;\n\t * \n\t * t = letters[1][1]; letters[1][1] = letters[2][1]; letters[2][1] =\n\t * letters[3][1]; letters[3][1] = letters[5][3]; letters[5][3] = t; } if (x\n\t * == 1) { t = letters[2][0]; letters[2][0] = letters[0][0]; letters[0][0] =\n\t * letters[5][0]; letters[5][0] = letters[4][0]; letters[4][0] = t;\n\t * \n\t * t = letters[2][3]; letters[2][3] = letters[0][3]; letters[0][3] =\n\t * letters[5][3]; letters[5][3] = letters[4][3]; letters[4][3] = t; } if (x\n\t * == 2) { t = letters[0][3]; letters[0][3] = letters[1][2]; letters[1][2] =\n\t * letters[4][1]; letters[4][1] = letters[3][0]; letters[3][0] = t;\n\t * \n\t * t = letters[0][2]; letters[0][2] = letters[1][1]; letters[1][1] =\n\t * letters[4][0]; letters[4][0] = letters[3][3]; letters[3][3] = t; } if (x\n\t * == 3) { t = letters[2][1]; letters[2][1] = letters[4][1]; letters[4][1] =\n\t * letters[5][1]; letters[5][1] = letters[0][1]; letters[0][1] = t;\n\t * \n\t * t = letters[2][2]; letters[2][2] = letters[4][2]; letters[4][2] =\n\t * letters[5][2]; letters[5][2] = letters[0][2]; letters[0][2] = t; } if (x\n\t * == 4) { t = letters[2][3]; letters[2][3] = letters[1][3]; letters[1][3] =\n\t * letters[5][1]; letters[5][1] = letters[3][3]; letters[3][3] = t;\n\t * \n\t * t = letters[2][2]; letters[2][2] = letters[1][2]; letters[1][2] =\n\t * letters[5][0]; letters[5][0] = letters[3][2]; letters[3][2] = t; } if (x\n\t * == 5) { t = letters[4][3]; letters[4][3] = letters[1][0]; letters[1][0] =\n\t * letters[0][1]; letters[0][1] = letters[3][2]; letters[3][2] = t;\n\t * \n\t * t = letters[4][2]; letters[4][2] = letters[1][3]; letters[1][3] =\n\t * letters[0][0]; letters[0][0] = letters[3][1]; letters[3][1] = t; } }\n\t * \n\t * public String toString(){ return \"  \" + letters[0][0] + letters[0][1] +\n\t * \"\\n\" + \"  \" + letters[0][3] + letters[0][2] + \"\\n\" + letters[1][0] +\n\t * letters[1][1] + letters[2][0] + letters[2][1] + letters[3][0] +\n\t * letters[3][1] + \"\\n\" + letters[1][3] + letters[1][2] + letters[2][3] +\n\t * letters[2][2] + letters[3][3] + letters[3][2] + \"\\n\" + \"  \" +\n\t * letters[4][0] + letters[4][1] + \"\\n\" + \"  \" + letters[4][3] +\n\t * letters[4][2] + \"\\n\" + \"  \" + letters[5][0] + letters[5][1] + \"\\n\" + \"  \"\n\t * + letters[5][3] + letters[5][2] + \"\\n\"; } }\n\t * \n\t * \n\t * Vector<Integer>[] a; int n, mc, c1, c2; int[] col;\n\t * \n\t * void wave(int x, int p) { for (Iterator<Integer> i = a[x].iterator();\n\t * i.hasNext(); ) { int t = i.next(); if (t == x || t == p) continue; if\n\t * (col[t] == 0) { col[t] = mc; wave(t, x); } else { c1 = x; c2 = t; } } }\n\t * \n\t * void solve() throws IOException {\n\t * \n\t * String s = \"\u0415\u041f\u041e\u0415\u042c\u0420\u0418\u0422\u0421\u0413\u0425\u0416\u0417\u0422\u042f\u041f\u0421\u0422\u0410\u041f\u0414\u0421\u0411\u0418\u0421\u0422\u0427\u041a\"; //String s =\n\t * \"\u0417\u042c\u0423\u041e\u042b\u0422\u0412\u0417\u0422\u042f\u041f\u0423\u0411\u041e\u042b\u0422\u0415\u0410\u042b\u0428\u0425\u042f\u0410\u0422\u0427\u041a\"; cubeWithLetters cube = new\n\t * cubeWithLetters(); for (int x = 0; x < 4; x++) { for (int y = x + 1; y <\n\t * 5; y++) { for (int z = y + 1; z < 6; z++) { cube = new cubeWithLetters();\n\t * out.println(cube.toString()); cube.rotate(x);\n\t * out.println(cube.toString()); cube.rotate(y);\n\t * out.println(cube.toString()); cube.rotate(z);\n\t * out.println(cube.toString()); out.print(x + \" \" + y + \" \" + z + \" = \");\n\t * for (int i = 0; i < s.length(); i++) { out.print(cube.get(s.charAt(i)));\n\t * } out.println(); } } }\n\t * \n\t * int a = nextInt(), b = nextInt(), x = nextInt(), y = nextInt();\n\t * out.print((lib.min(a / (x / lib.gcd(x, y)), b / (y / lib.gcd(x, y))) * (x\n\t * / lib.gcd(x, y))) + \" \" + (lib.min(a / (x / lib.gcd(x, y)), b / (y /\n\t * lib.gcd(x, y))) * (y / lib.gcd(x, y)))); }\n\t */\n\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class AA {\n\n\tstatic class Pair implements Comparable<Pair> {\n\t\tpublic int x, y;\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\tpublic int compareTo(Pair p) {\n\t\t\tif (p.x != x)\n\t\t\t\treturn x - p.x;\n\t\t\treturn y - p.y;\n\t\t}\n\t}\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 t = in.nextInt() * 2;\n\t\tList<Pair> l = new ArrayList<Pair>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint c = in.nextInt() * 2;\n\t\t\tint a = in.nextInt();\n\t\t\tl.add(new Pair(c - a, c + a));\n\t\t}\n\t\tCollections.sort(l);\n\t\tint ret = 2;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif (l.get(i).x - l.get(i-1).y > t)\n\t\t\t\tret += 2;\n\t\t\telse if (l.get(i).x - l.get(i-1).y == t)\n\t\t\t\tret += 1;\n\t\t}\n\t\tSystem.out.println(ret);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists()) {\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t}\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\t\n\t\tnew Main().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\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\tint N = nextInt();\n\t\tint T = nextInt();\n\n\t\tPair[] p = new Pair [N];\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tp[i] = new Pair(nextInt(), nextInt());\n\t\tsort(p);\n\t\tint ans = 2;\n\t\tfor (int i = 1; i < N; i++) {\n\t\t\tint dif = (2 * p[i].x - p[i].a) - (2 * p[i - 1].x + p[i - 1].a);\n\t\t\tif (dif == 2 * T)\n\t\t\t\tans++;\n\t\t\telse if (dif > 2 * T)\n\t\t\t\tans += 2;\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tclass Pair implements Comparable<Pair> {\n\t\tint x, a;\n\t\t\n\t\tpublic Pair(int xx, int aa) {\n\t\t\tx = xx;\n\t\t\ta = aa;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Pair p) {\n\t\t\treturn x < p.x ? -1 : 1;\n\t\t}\n\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\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", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport static java.lang.Math.*;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class CodeforcesA implements Runnable {\n\tpublic static final String taskname = \"A\";\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new CodeforcesA()).start();\n\t}\n\t\n\tstatic class Square implements Comparable<Square>{\n\t\tint x, a;\n\t\tpublic Square(int x, int a) {\n\t\t\tthis.x = x;\n\t\t\tthis.a = a;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Square o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t\t\n\t\tint distance(Square a, int t) {\n\t\t\tdouble dist = a.x - x - this.a / 2.0 - a.a / 2.0;\n\t\t\tif(dist > t) return 2;\n\t\t\telse if(abs(dist - t) < 1e-9) return 1;\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + a;\n\t\t}\n\t}\n\t\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt(), t = nextInt();\n\t\tSquare[] x = new Square[n];\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tx[i] = new Square(nextInt(), nextInt());\n\t\t}\n\t\tArrays.sort(x);\n\t\tlong res = 2;\n\t\tfor(int i = 0; i < n - 1; ++i) {\n\t\t\tres += x[i].distance(x[i + 1], t);\n\t\t}\n\t\tout.println(res);\n\t\t\t\n\t}\n\n\t@Override\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(new File(\"input.txt\")));\n\t\t\t out = new PrintWriter(System.out);\n\t\t\t//out = new PrintWriter(new File(\"output.txt\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t\tin.close();\n\t\t} catch (IOException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\n\t}\n\n\tString nextLine() throws IOException {\n\t\ttok = null;\n\t\treturn in.readLine();\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\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 (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class CottageVillage {\n    \n    class cl {\n        int x=0;\n        int a=0;\n        \n        cl(int x, int a){\n            this.x=x; \n            this.a=a;\n        }\n    }\n    \n    class cmp implements Comparator<cl> {\n        public int compare(cl d1, cl d2) {\n            return d1.x<d2.x ? -1 : 1;\n        }\n    }\n    \n    public CottageVillage() {\n        Scanner sc = new Scanner(System.in);\n        \n        int n = sc.nextInt();\n        int k = sc.nextInt();\n        \n        cl[] w = new cl[n];\n        for(int i=0; i<n; i++)\n            w[i] = new cl(sc.nextInt(), sc.nextInt());\n        Arrays.sort(w, new cmp());\n        \n        int cnt=2, diff=0; \n        for(int i=1; i<n; i++) {\n            diff = Math.abs(2*w[i].x-2*w[i-1].x-w[i].a-w[i-1].a)-2*k; \n            if (diff>0) cnt+=2;\n            else if (diff==0) cnt++;\n        }\n        System.out.println(cnt);\n    }\n    \n    public static void main(String... args) {\n        new CottageVillage();\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\npublic class A {\n\tpublic static void main(String[] args) throws IOException\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 t = Integer.parseInt(st.nextToken());\n\t\tState[] s = new State[n];\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\ts[i] = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));\n\t\t}\n\t\tArrays.sort(s);\n\t\tint num = 2;\n\t\tfor(int i = 1; i < s.length; i++)\t{\n\t\t\tint dist = s[i].x - s[i-1].x;\n\t\t\tdist *= 2;\n\t\t\tint size = s[i].d + s[i-1].d;\n\t\t\tsize += 2 * t;\n\t\t\tif(dist == size)\n\t\t\t\tnum++;\n\t\t\telse if(dist > size)\n\t\t\t\tnum += 2;\n\t\t}\n\t\tSystem.out.println(num);\n\t}\n\tstatic class State implements Comparable<State> {\n\t\tpublic int x,d;\n\t\tpublic State(int a, int b)\t{\n\t\t\tx=a;\n\t\t\td=b;\n\t\t}\n\t\tpublic int compareTo(State s)\t{\n\t\t\treturn x - s.x;\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Task15a {\n\n\tpublic static class House implements Comparable<House>{\n\t\tint x, s;\n\n\t\tpublic House(int x, int s) {\n\t\t\tsuper();\n\t\t\tthis.x = x;\n\t\t\tthis.s = s;\n\t\t}\n\n\t\tpublic int compareTo(House o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t\t\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 t = sc.nextInt() * 2;\n\t\tHouse[] hs = new House[n];\n\t\tfor (int i = 0; i < n; i++){\n\t\t\ths[i] = new House(sc.nextInt()*2, sc.nextInt());\n\t\t}\n\t\tArrays.sort(hs);\n\t\tint res = 2;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tint curr = hs[i+1].x - hs[i].x - hs[i+1].s - hs[i].s;\n\t\t\tif (curr > t) res += 2;\n\t\t\tif (curr == t) res += 1;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class _P015A{\n    Scanner sc=new Scanner(System.in);\n\n    int INF=1<<28;\n    double EPS=1e-9;\n\n    int n, t;\n    int[][] a;\n\n    void run(){\n        n=sc.nextInt();\n        t=sc.nextInt();\n        a=new int[n][2];\n        for(int i=0; i<n; i++){\n            a[i][0]=sc.nextInt();\n            a[i][1]=sc.nextInt();\n        }\n        solve();\n    }\n\n    void solve(){\n        sort(a, new Comparator<int[]>(){\n            @Override\n            public int compare(int[] a0, int[] a1){\n                return a0[0]-a1[0];\n            }\n        });\n        int ans=2;\n        for(int i=0; i<n-1; i++){\n            int s=(a[i+1][0]*2-a[i+1][1])-(a[i][0]*2+a[i][1]);\n            if(s>t*2){\n                ans+=2;\n            }else if(s==t*2){\n                ans++;\n            }\n        }\n        println(ans+\"\");\n    }\n\n    void println(String s){\n        System.out.println(s);\n    }\n\n    void print(String s){\n        System.out.print(s);\n    }\n\n    void debug(Object... os){\n        System.err.println(Arrays.deepToString(os));\n    }\n\n    public static void main(String[] args){\n        new _P015A().run();\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ProblemA {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner s = new Scanner(System.in);\n\t\t\n\t\tint n = s.nextInt();\n\t\tint t = s.nextInt();\n\t\tTreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();\n\t\t\n//\t\tint x = 0 ;\n\t\twhile(s.hasNextInt())\n\t\t{\n\t\t\tint i = s.nextInt();\n\t\t\tint j = s.nextInt();\n\t\t\tmap.put(i,j);\n//\t\t\tx++;\n//\t\t\tif(x == 2)\n//\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tint count = 0;\n\t\tdouble left = -100000;\n\t\tdouble right;\n\t\tint size;\n\t\tfor(Integer i : map.keySet())\n\t\t{\n\t\t\tsize = map.get(i);\n\t\t\tright = (double)i - (double)size/2.0;\n\t\t\t\n\t\t\tif(right - left > t)\n\t\t\t{\n\t\t\t\tcount+=2;\n\t\t\t}\n\t\t\tif(right - left == t)\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\t\n\t\t\tleft = (double)i + (double)size/2.0;\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t}\n\n}\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class CottageVillage {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint size=sc.nextInt();\n\t\tint side=sc.nextInt();\n\t\tArrayList<Pair> lis=new ArrayList<Pair>();\n\t\tfor(int x=0;x<size;x++)\n\t\t{\n\t\t\tlis.add(new Pair(sc.nextInt(), sc.nextInt()));\n\t\t\t\n\t\t}\n\t\tCollections.sort(lis);\n\t\tint count=2;\n\t\tfor(int x=0;x<lis.size()-1;x++)\n\t\t{\n\t\t\tPair a=lis.get(x);\n\t\t\tPair b=lis.get(x+1);\n\t\t\tdouble na=a.x+a.len/2;\n\t\t\tdouble nb=b.x-b.len/2;\n\t\t\t//System.out.println(na+\" \"+nb);\n\t\t\tif(na<nb)\n\t\t\t{\n\t\t\t\tdouble dif=Math.abs(nb-na);\n\t\t\t\tif(dif==side)count++;\n\t\t\t\telse if(dif>side)count+=2;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\nclass Pair implements Comparable<Pair>\n{\n\tint x;\n\tdouble len;\n\n\tpublic Pair(int a,int b)\n\t{\n\t\tx=a;\n\t\tlen=b;\n\t}\n\tpublic int compareTo(Pair o) {\n\t\treturn x-o.x;\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "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\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\n\t\tint n = next();\n\t\tint t = 2*next();\n\n\t\tint[] x = new int[n];\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = 2* next() + 2000;\n\t\t\ta[i] = next();\n\t\t}\n\n\t\tint[] srt = new int[n];\n\t\tfor (int i = 0; i < n; i++) srt[i] = 10000 * x[i] + a[i];\n\t\tArrays.sort(srt);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = srt[i] / 10000;\n\t\t\ta[i] = srt[i] % 10000;\n\t\t}\n\n\t\tint answ = 2;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tif (x[i + 1] - x[i] > a[i] + a[i + 1] + t) answ++;\n\t\t\tif (x[i + 1] - x[i] >= a[i] + a[i + 1] + t) answ++;\n\t\t}\n\n\t\tout.println(answ);\n\n\t\tout.close();\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Beta15PA {\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\tBeta15PA temp = new Beta15PA();\n\t\ttemp.solve();\n\t}\n\t\n\tpublic void solve() {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt(), t = scan.nextInt();\n\t\tHouse[]\thouses = new House[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\thouses[i] = new House(scan.nextInt(), scan.nextInt());\n\t\t}\n\t\tArrays.sort(houses);\n\t\tint res = 2;\n\t\tfor(int i=0; i<n-1; i++) {\n\t\t\tdouble cnt = houses[i+1].coordinate - houses[i].coordinate;\n\t\t\tcnt -= 1.0*(houses[i+1].side+houses[i].side)/2;\n\t\t\tif(cnt>t) res += 2;\n\t\t\telse if(Math.abs(cnt-t)<1e-7) res += 1;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\t\n\tpublic class House implements Comparable<House> {\n\t\tpublic int coordinate, side;\n\n\t\tpublic House(int coordinate, int side) {\n\t\t\tthis.coordinate = coordinate;\n\t\t\tthis.side = side;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(House arg0) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn this.coordinate - arg0.coordinate;\n\t\t}\n\t\t\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "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.Set;\n\npublic class ProblemA {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tString[] line = s.readLine().split(\" \");\n\t\tint n = Integer.valueOf(line[0]);\n\t\tint ht = Integer.valueOf(line[1]);\n\t\t\n\t\tint[][] house = new int[n][2];\n\t\tSet<Integer> candidates = new HashSet<Integer>(); \n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tString[] data = s.readLine().split(\" \");\n\t\t\thouse[i][0] = Integer.valueOf(data[0]) * 2;\n\t\t\thouse[i][1] = Integer.valueOf(data[1]);\n\t\t\tcandidates.add(house[i][0] - house[i][1] - ht);\n\t\t\tcandidates.add(house[i][0] + house[i][1] + ht);\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor (int p : candidates) {\n\t\t\tint f = p - ht;\n\t\t\tint t = p + ht;\n\t\t\tboolean isok = true;\n\t\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\t\tif (house[i][0] + house[i][1] <= f) {\n\t\t\t\t} else if (house[i][0] - house[i][1] >= t) {\n\t\t\t\t} else {\n\t\t\t\t\tisok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (isok) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tout.println(ans);\n\t\tout.flush();\n\t}\n\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\n/**\n *\n * @author camoroh13\n */\npublic class Solution {\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n //       Scanner sc = new Scanner(new FileInputStream(\"/home/camoroh13/NetBeansProjects/JavaApplication1/src/input.txt\"));\n        int n = sc.nextInt();\n        int t = sc.nextInt();\n//        int[][] h = new int[n][2];\n        TreeMap<Integer, Integer> h = new TreeMap<Integer, Integer>();\n        for (int i=0; i < n; i++) {\n            int key = sc.nextInt();\n            h.put(key, sc.nextInt());\n        }\n\n        int ans = 2;\n        Integer lastKey = h.firstKey();\n        Integer last = h.get(lastKey);\n        h.remove(lastKey);\n        for (int i=1; i < n; i++) {\n            int key = h.firstKey();\n            int val = h.get(key);\n            //System.out.println(Math.abs(key-val*1.0/2 - (lastKey + last*1.0/2)) + \"-\" + key + \"-\"+val);\n            if (Math.abs(key-val*1.0/2 - (lastKey + last*1.0/2)) == t) {\n                ans++;\n            } else if (Math.abs(key-val*1.0/2 - (lastKey + last*1.0/2))  > t) {\n                ans += 2;\n            }\n            lastKey = key;\n            last = val;\n            h.remove(lastKey);\n        }\n\n        System.out.println(ans);\n        \n        sc.close();\n    }\n\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n \npublic class Solution15A {\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 Solution15A().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        class Square implements Comparable<Square>{\n        \tpublic Square(int x, int a){\n        \t\tthis.x = x;\n        \t\tthis.a = a;\n        \t}\n        \t\n        \t@Override\n\t\t\tpublic int compareTo(Square o) {\n\t\t\t\tif(this.x > o.x) return 1;\n\t\t\t\tif(this.x < o.x) return -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tpublic int a, x;\n        }\n        \n        \n        void solve() throws IOException{\n        \tint n = readInt();\n        \tint t = readInt();\n        \tSquare[] houses = new Square[n];\n        \tfor(int i = 0; i < n; i++){\n        \t\tint a = readInt();\n        \t\tint b = readInt();\n        \t\thouses[i] = new Square(a, b);\n        \t}\n        \tArrays.sort(houses);\n        \tint count = 0;\n        \tfor(int i = 0; i < n; i++){\n        \t\tif(i == 0) count++;\n        \t\telse{\n        \t\t\tif(houses[i].x - houses[i].a/2.0 - t > houses[i-1].x + houses[i-1].a/2.0)\n        \t\t\t\tcount++;\n        \t\t}\n        \t\tif(i == n - 1) count++;\n        \t\telse{\n        \t\t\tif(houses[i].x + houses[i].a/2.0 + t <= houses[i+1].x - houses[i+1].a/2.0)\n        \t\t\t\tcount++;\n        \t\t}\n        \t}\n        \tout.println(count);\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}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * @author Son-Huy TRAN\n * \n */\npublic class P15A_CottageVillage {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tint n = scanner.nextInt();\n\t\tint t = scanner.nextInt();\n\t\tscanner.nextLine();\n\n\t\tint[] x = new int[n];\n\t\tint[] a = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = scanner.nextInt();\n\t\t\ta[i] = scanner.nextInt();\n\t\t\tscanner.nextLine();\n\t\t}\n\n\t\tscanner.close();\n\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (x[i] > x[j]) {\n\t\t\t\t\tswap(x, i, j);\n\t\t\t\t\tswap(a, i, j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint countPositions = 2;\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tdouble left = x[i - 1] + a[i - 1] * 1.0 / 2;\n\t\t\tdouble right = x[i] - a[i] * 1.0 / 2;\n\t\t\tdouble length = right - left;\n\n\t\t\tif (length == (double) t) {\n\t\t\t\tcountPositions++;\n\t\t\t} else if (length > t) {\n\t\t\t\tcountPositions += 2;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(countPositions);\n\t}\n\n\tprivate static void swap(int[] numbers, int i, int j) {\n\t\tint temp = numbers[i];\n\t\tnumbers[i] = numbers[j];\n\t\tnumbers[j] = temp;\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class p15a {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int t = in.nextInt();\n        if(n == 1) {\n            System.out.println(2);\n            return;\n        }\n        house[] all = new house[n];\n        for (int i = 0; i < all.length; i++) {\n            all[i] = new house(in.nextInt(),in.nextInt());\n        }\n        Arrays.sort(all);\n        \n        int count = 0;\n        for (int i = 0; i < all.length; i++) {\n            double left = all[i].center - (all[i].side*1.0/2);\n            double right = all[i].center + (all[i].side*1.0/2);\n            if(i == 0) {\n                count++;\n                double left2 = all[i+1].center - (all[i+1].side*1.0/2);\n                if(right+t<left2) {\n                    count++;\n                }\n                continue;\n                \n            }\n            if(i == all.length-1) {\n                count++;\n                double right2 = all[i-1].center + (all[i-1].side*1.0/2);\n                if(left-t>= right2) {\n                    count++;\n                }\n                continue;\n            }\n            double left2 = all[i+1].center - (all[i+1].side*1.0/2);\n            double right2 = all[i-1].center + (all[i-1].side*1.0/2);\n            \n            if(right+t<left2) {\n                count++;\n            }\n            if(left-t>=right2)\n                count++;\n        }\n        System.out.println(count);\n        \n    }\n}\nclass house implements Comparable<house>{\n    int center;\n    int side;\n    public house(int a , int b) {\n        center = a;\n        side = b;\n    }\n    public int compareTo(house o) {\n        return center-o.center;\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class P015A {\n\n    public static void main(String[] args) {\n        Scanner inScanner = new Scanner(System.in);\n        int n = inScanner.nextInt();\n        int t = inScanner.nextInt();\n        House[] houses = new House[n];\n        for (int i = 0; i < n; i++)\n            houses[i] = new House(inScanner.nextInt(), inScanner.nextInt());\n        Arrays.sort(houses);\n        int sum = 2;\n        for (int i = 1; i < n; i++) {\n            double space = houses[i].leftX - houses[i - 1].rightX;\n            if (space >= t)\n                sum++;\n            if (space > t)\n                sum++;\n        }\n        System.out.println(sum);\n    }\n\n    private static class House implements Comparable<House> {\n\n        int x;\n        double leftX;\n        double rightX;\n\n        public House(int x, int size) {\n            super();\n            this.x = x;\n            leftX = x - (double) size / 2;\n            rightX = x + (double) size / 2;\n        }\n\n        @Override\n        public int compareTo(House o) {\n            return x - o.x;\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A015 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt(), t = in.nextInt();\n\t\tint[] centers = new int[n], sides = new int[n];\n\t\tfor (int x = 0; x < n; x++) {\n\t\t\tcenters[x] = in.nextInt();\n\t\t\tsides[x] = in.nextInt();\n\t\t}\n\t\tint count = 0;\n\n\t\tbig: for (int x = -4000; x <= 4000; x++) {\n\t\t\tboolean touch = false;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint d = 2*centers[i] - x;\n\t\t\t\td = d > 0 ? d : -d;\n\t\t\t\tint s = t + sides[i];\n\t\t\t\tif (s == d) {\n\t\t\t\t\ttouch = true;\n\t\t\t\t} else if (s > d) {\n\t\t\t\t\tcontinue big;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (touch)\n\t\t\t\tcount++;\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "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 t = sc.nextInt();\n        double [] left = new double[n];\n        double [] right = new double[n];\n        for (int i = 0; i<n; i++){\n            int x = sc.nextInt();\n            int a = sc.nextInt();\n            double l = x - (double)a/2;\n            double r = x + (double)a/2;\n            left[i] = l;\n            right[i] = r;\n        }\n        int answer = 2;\n        quickSort(left, right, 0, n-1);\n        for (int i = 0; i<n-1; i++){\n            if (left[i+1] - right[i] == t){\n                answer++;   \n            }\n            if (left[i+1] - right[i] > t){\n                answer += 2;\n            }\n        }\n        System.out.println(answer);\n    }\n    \n////////////////////////////////////////////////////////////////    \n    int partition(double arr[], int left, int right)\n    {\n          int i = left, j = right;\n          double tmp;\n          double pivot = arr[(left + right) / 2];\n          while (i <= j) {\n                while (arr[i] < pivot)\n                      i++;\n                while (arr[j] > pivot)\n                      j--;\n                if (i <= j) {\n                      tmp = arr[i];\n                      arr[i] = arr[j];\n                      arr[j] = tmp;\n                      i++;\n                      j--;\n                }\n          };\n          return i;\n    }\n    void quickSort(double arr[], int left, int right) {\n          int index = partition(arr, left, right);\n          if (left < index - 1)\n                quickSort(arr, left, index - 1);\n          if (index < right)\n                quickSort(arr,index, right);\n    }\n/////////////////////////////////////////////////////////////////////\n    static int partition(double arr[], double arr2[], int left, int right)\n    {\n          int i = left, j = right;\n          double tmp; double tmp2;\n          double pivot = arr[(left + right) / 2];\n\n          while (i <= j) {\n                while (arr[i] < pivot)\n                      i++;\n                while (arr[j] > pivot)\n                      j--;\n                if (i <= j) {\n                      tmp = arr[i];\n                      arr[i] = arr[j];\n                      arr[j] = tmp;\n                      tmp2 = arr2[i];\n                      arr2[i] = arr2[j];\n                      arr2[j] = tmp2;\n                      i++;\n                      j--;\n                }\n          };\n          return i;\n    }\n    static void quickSort(double arr[], double[]arr2, int left, int right) {\n          int index = partition(arr, arr2, left, right);\n          if (left < index - 1)\n                quickSort(arr, arr2, left, index - 1);\n          if (index < right)\n                quickSort(arr, arr2, index, right);\n    }\n    ////////////////////////////////////////////////////////////////////////\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CottageVillage {\n\t\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\twhile(scan.hasNext()){\n\t\t\tint counter = 0;\n\t\t\tint numbCottages = scan.nextInt();\n\t\t\tint t = scan.nextInt();\n\t\t\tHouse[] cottages = new House[numbCottages];\n\t\t\tfor(int i =0; i<numbCottages; i++){\n\t\t\t\tint centre = scan.nextInt();\n\t\t\t\tint length = scan.nextInt();\n\t\t\t\tdouble beginning = centre - ((double)length)/2;\n\t\t\t\tdouble end = centre + ((double)length)/2;\n\t\t\t\tcottages[i]= new House(beginning, end);\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tArrays.sort(cottages);\n\t\t\t\n\t\t\t//check righthand side of first cottage\n\t\t\t\n\t\t\t/*\n\t\t\tif(cottages[0].end + t < cottages[1].beginning)\n\t\t\t\tcounter++;\n\t\t\t//check lefthand side of last cottage\n\t\t\t\n\t\t\tif(cottages[numbCottages-1].beginning -t > cottages[numbCottages-2].end)\n\t\t\t\tcounter++;\n\t\t\t\t\n\t\t\t\t*/\n\t\t\t\n\t\t\tfor(int i =0; i<numbCottages-1; i++){\n\t\t\t\t\n\t\t\t\tif(cottages[i].end + t <= cottages[i+1].beginning){\n\t\t\t\t\tcounter++;\n//\t\t\t\t\tSystem.out.println(counter + \"left hand\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (cottages[i+1].beginning - t >= cottages[i].end){\n\t\t\t\t\tcounter++;\n//\t\t\t\t\tSystem.out.println(counter + \"right hand\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (Math.abs((cottages[i].end + t - cottages[i+1].beginning)) < 1e-8){\n\t\t\t\t\tcounter--;\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t\n\t\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(counter+2);\n\t\t\t\n\t\t}\n\t}\n\t\n\tstatic class House implements Comparable<House>{\n\t\tdouble beginning;\n\t\tdouble end;\n\t\tHouse(double _beginning, double _end){\n\t\t\tbeginning = _beginning;\n\t\t\tend = _end;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(House house) {\n//\t\t\tif(this.beginning<house.beginning){\n//\t\t\t\treturn -1;\n//\t\t\t}\n//\t\t\telse if(this.beginning==house.beginning){\n//\t\t\t\treturn 0;\n//\t\t\t}\n//\t\t\telse{\n//\t\t\t\treturn 1;\n//\t\t\t}\n\t\t\treturn Double.valueOf(beginning).compareTo(house.beginning);\n\t\t}\n\t\t\n\t\t\n\t}\n\n}\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Scanner;\n\n/**\n *\n * @author epiZend\n */\npublic class Cottage {\n    \n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int t = sc.nextInt();\n        List<Point> houses = new ArrayList<Point>();\n        for (int i = 0; i < n; i++) {\n            int x = sc.nextInt();\n            int a = sc.nextInt();\n            houses.add(new Point(x, a));\n        }\n        Collections.sort(houses, new Comparator<Point>() {\n            \n            @Override\n            public int compare(Point o1, Point o2) {\n                return ((Integer) o1.x).compareTo(o2.x);\n            }\n        });\n        int pos = 2;\n        for (int i = 0; i < n - 1; i++) {\n            double end = houses.get(i).x + (houses.get(i).y+0.0)/2;\n            double start = houses.get(i+1).x - (houses.get(i+1).y+0.0)/2;\n            //System.out.println(\"end \"+end+\" start \"+start);\n            double diff = start-end;\n            //System.out.println(\"diff\");\n            if (Math.abs(diff-t) < 0.0000001) {\n                pos++;\n            }\n            if (diff > t) {\n                pos += 2;\n            }\n        }\n        System.out.println(pos);\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n\n    static class Pair implements Comparable<Pair> {\n        int x, a;\n\n        Pair(int x, int a) {\n            this.x = x;\n            this.a = a;\n        }\n\n        @Override\n        public int compareTo(Pair o) {\n            // TODO Auto-generated method stub\n            return 0;\n        }\n    }\n\n    boolean isCross(double l1, double r1, double l2, double r2) {\n        double r = min(r1, r2);\n        double l = max(l1, l2);\n        return r > l;\n    }\n\n    boolean check(double xl, double xr, double[] l, double[] r, int n) {\n        boolean ok = false;\n        for (int j = 0; j < n; ++j)\n            ok |= isCross(xl, xr, l[j], r[j]);\n        return ok;\n    }\n\n    void solve() throws IOException {\n        int n = ni();\n        double t = ni();\n        double[] l = new double[n];\n        double[] r = new double[n];\n        for (int i = 0; i < l.length; i++) {\n            double x = ni();\n            double len = ni();\n            l[i] = x - len / 2.0;\n            r[i] = x + len / 2.0;\n        }\n        HashSet<Double> set = new HashSet<Double>();\n        for (int i = 0; i < n; ++i) {\n            double xl = l[i] - t;\n            double xr = l[i];\n            boolean ok = check(xl, xr, l, r, n);\n            if (!ok)\n                set.add(xl);\n            xl = r[i];\n            xr = r[i] + t;\n            ok = check(xl, xr, l, r, n);\n            if (!ok)\n                set.add(xl);\n\n        }\n        out.println(set.size());\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", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class a {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tdouble w = in.nextDouble();\n\t\tint tot = 2;\n\t\tInterval[] houses = new Interval[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tdouble center = in.nextDouble();\n\t\t\tdouble wid = in.nextDouble();\n\t\t\thouses[i] = new Interval(center-wid/2,center+wid/2);\n\t\t}\n\t\tArrays.sort(houses);\n\t\tfor(int i=1; i<n; i++) {\n\t\t\tdouble dist = houses[i].s - houses[i-1].e;\n\t\t\tif(dist+1e-6 >= w) {\n\t\t\t\ttot+=2;\n\t\t\t\tif(Math.abs(w-dist) < 1e-6)\n\t\t\t\t\ttot--;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(tot);\n\t}\n}\nclass Interval implements Comparable<Interval> {\n\tdouble s, e;\n\tInterval(double a, double b) {\n\t\ts=a;\n\t\te=b;\n\t}\n\tpublic int compareTo(Interval i) {\n\t\treturn (int)Math.signum(s-i.s);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.text.ChoiceFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint t = scan.nextInt();\n\t\tList<Double> coords = new ArrayList<Double>();\n\t\twhile (n-- > 0) {\n\t\t\tdouble x = scan.nextDouble();\n\t\t\tdouble a = scan.nextDouble() / 2;\n\t\t\tcoords.add(x - a);\n\t\t\tcoords.add(x + a);\n\t\t}\n\t\tCollections.sort(coords);\n\t\tint count = 2;\n\t\tChoiceFormat f = new ChoiceFormat(\"-1#0|0#1|0<2\");\n\t\tfor (int i = 1; i < coords.size()-2; i+=2) {\n\t\t\tcount += new Integer(f.format(coords.get(i+1)-coords.get(i)-t));\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "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.Set;\nimport java.util.StringTokenizer;\n\npublic class A {\n    BufferedReader in;\n    StringTokenizer st;\n    PrintWriter out;\n\n    static class House implements Comparable<House> {\n        final int x, a;\n\n        House(int x, int a) {\n            this.x = x;\n            this.a = a;\n        }\n\n        public int compareTo(House h) {\n            return x - h.x;\n        }\n    }\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int t = nextInt();\n        House[] h = new House[n];\n        for (int i = 0; i < n; ++i) {\n            h[i] = new House(2 * nextInt(), nextInt());\n        }\n        Arrays.sort(h);\n        int ans = 2;\n        for (int i = 1; i < n; ++i) {\n            House prev = h[i - 1];\n            House curr = h[i];\n            int diff = 2 * t + curr.a + prev.a;\n            if (curr.x - prev.x == diff) {\n                ++ans;\n            } else if (curr.x - prev.x > diff) {\n                ans += 2;\n            }\n        }\n        out.println(ans);\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 A().run();\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.Set;\n\n\npublic class R015A {\n    final double EPS = 1e-9;    \n    boolean isEqual(double x, double y) {\n        return Math.abs(x-y) <= EPS * Math.max(Math.abs(x), Math.abs(y));\n    }\n    class Pair implements Comparable<Pair>{\n        double left;\n        double right;\n        Pair(double left, double right) {\n            this.left = left;\n            this.right = right;\n        }\n        public String toString() {\n            return \"(\" + left + \",\" + right + \")\";\n        }\n        public int hashCode() {\n            return (int)(left * 17 + right * 31);\n        }\n        public boolean equals(Object o) {\n            if(!(o instanceof Pair)) return false;\n            Pair that = (Pair)o;\n            return isEqual(this.left, that.left) && isEqual(this.right, that.right);\n        }\n        public int compareTo(Pair that) {\n            if(this.left != that.left)\n                return (int)(this.left - that.left);\n            return (int)(this.right - that.right);\n        }\n    }\n    public R015A() {\n    }\n    \n    private void process() {\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt();\n        int t = scanner.nextInt();\n        int[] x = new int[n];\n        int[] a = new int[n];\n        for(int i=0; i<n; i++) {\n            x[i] = scanner.nextInt();\n            a[i] = scanner.nextInt();\n        }\n        List<Pair> pairs = new ArrayList<Pair>();\n        for(int i=0; i<n; i++) {\n            double left = x[i] - a[i] / 2.0;\n            double right= x[i] + a[i] / 2.0;\n            pairs.add(new Pair(left, right));\n        }\n        Collections.sort(pairs);\n        Set<Pair> newPairs = new HashSet<Pair>();\n        newPairs.add(new Pair(pairs.get(0).left - t, pairs.get(0).left));\n        for(int i=0; i<pairs.size()-1; i++) {\n            if(pairs.get(i+1).left - pairs.get(i).right >= t) {\n                newPairs.add(new Pair(pairs.get(i).right, pairs.get(i).right + t));\n                newPairs.add(new Pair(pairs.get(i+1).left - t, pairs.get(i+1).left));\n            }\n        }\n        newPairs.add(new Pair(pairs.get(pairs.size()-1).right, pairs.get(pairs.size()-1).right + t));\n        System.out.println(newPairs.size());\n    }\n    \n    public static void main(String[] args) {\n        new R015A().process();\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class ProblemA {\n\n    static ArrayList<Point2> houses = new ArrayList<Point2>();\n    \n    public static void main(String[] args) {\n        ProblemA a = new ProblemA();\n        Scanner in = new Scanner(System.in);\n        while(in.hasNextInt()){\n            int n = in.nextInt();\n            double t = in.nextDouble();\n            for (int k=0;k<n;k++){\n                houses.add(a.new Point2(in.nextDouble(),in.nextDouble()));\n            }\n            Collections.sort(houses);\n            int ans = 2;\n            for (int k=0;k<n-1;k++){\n                Point2 cur = houses.get(k);\n                Point2 next = houses.get(k+1);\n                double dist = (next.x - next.y/2) - (cur.x + cur.y/2);\n                if (dist == t) ans ++;\n                if (dist > t ) ans+=2;\n            }\n            System.out.println(ans);\n        }\n    }\n    \n    public class Point2 implements Comparable<Point2>{\n        public double x;\n        public double y;\n        public Point2(double one, double two){\n            x = one;\n            y = two;\n        }\n        \n        public int compareTo(Point2 other){\n            if (x - other.x > 0) return 1;\n            if (x - other.x < 0) return -1;\n            return 0;\n        }\n        \n        public String toString(){\n            return \"x:\" + x + \" y:\" + y;\n        }\n    }\n}\n\n\n\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class House {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint t = sc.nextInt();\n\t\tArrayList<HS> list = new ArrayList<HS>();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlist.add(new HS(sc.nextInt(),sc.nextInt()));\n\t\t}\n\t\t\n\t\tCollections.sort(list);\n\t\t\n\t\tint count = 0;\n\t\t\n\t\tif(n >= 1)\n\t\t\tcount = 2;\n\t\t\n\t\tfor(int i = 0; i < list.size() - 1; i++){\n\t\t\tdouble d = Math.abs(list.get(i + 1).x - list.get(i).x);\n\t\t\td -= ((1.0*list.get(i).a/2.0) + (1.0*list.get(i + 1).a/2.0));\n\t\t\tif ((d >= t)&& ((d-t) <= 0.00000001)){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\telse if(d > t){\n\t\t\t\tcount+= 2;\n\t\t\t} \n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n\nclass HS implements Comparable<HS> {\n\tpublic int x;\n\tpublic int a;\n\n\tpublic HS(int x, int a) {\n\t\tthis.x = x;\n\t\tthis.a = a;\n\t}\n\n\tpublic int compareTo(HS o) {\n\t\treturn x - o.x;\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main  {\n    \n    Scanner in;\n    PrintWriter out;\n    \n    static class House implements Comparable <House>{\n        int len;\n        int pos;\n        \n        House(Scanner in){\n            pos = in.nextInt() * 2;\n            len = in.nextInt() * 2;         \n        }\n        \n        public int compareTo(House arg0) {\n            return this.pos-arg0.pos;\n        }\n        \n    }\n            \n    void solve(){\n        int n = in.nextInt();\n        int size = in.nextInt();\n        House []h = new House[n];\n        for (int i = 0; i < h.length; i++){\n            h[i] = new House(in);\n        }\n        Arrays.sort(h);\n        int ans = 2;\n        for (int i = 0; i < h.length - 1; i++){\n            int next = i + 1;\n            int sz = h[next].pos - h[i].pos - (h[next].len + h[i].len) / 2;\n            if (sz == size * 2) {\n                ans ++;\n            } else if (sz > size * 2) {\n                ans += 2;\n            }\n        }\n        out.println(ans);\n    }\n    \n    public void run(){\n        in = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        \n        try {\n            solve();\n        } finally {\n            out.close();\n        }\n    }\n    \n    void asserT(boolean e){\n        if (!e){\n            throw new Error();\n        }\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Map;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class CottageVillage {\n    \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        \n        TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();\n        while (n-->0) {\n            tm.put(sc.nextInt(), sc.nextInt());\n        }\n        \n        int cnt=2, x=0, a=0; \n        double diff=0;\n        for(Map.Entry<Integer, Integer> e : tm.entrySet()) {\n            if (x!=0 || a!=0) {\n                diff = Math.abs(e.getKey()-x-e.getValue()*0.5-a*0.5); \n                if (diff-k>0) cnt+=2;\n                else if (diff-k==0) cnt++;\n            }\n            x=e.getKey();\n            a=e.getValue();\n        }\n        System.out.println(cnt);\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n    StreamTokenizer in;\n    PrintWriter out;\n    static public void main(String[] args) throws IOException {\n        new Main().run();\n    }\n    int ni() throws IOException {\n        in.nextToken(); return (int) in.nval;\n    }\n    void run() throws IOException {\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n\n        int n = ni(), t = ni();\n        if(n == 0) {\n            out.println(0); out.flush(); return;\n        }\n        House[] h = new House[n];\n        for(int i = 0; i < n; i++) {\n            h[i] = new House();\n            h[i].x = ni(); h[i].a = ni();\n        }\n        Arrays.sort(h);\n        int ret = 2;\n        for(int i = 0; i < n - 1; i++) {\n            if(2*(h[i + 1].x - h[i].x) - h[i].a - h[i + 1].a > 2*t) ret+=2;\n            else if(2*(h[i + 1].x - h[i].x) - h[i].a - h[i + 1].a == 2*t) ret++;\n        }\n        out.println(ret);\n\n        out.flush();\n    }\n    void run1() throws IOException {\n            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            out = new PrintWriter(new OutputStreamWriter(System.out));\n\n            int t = ni();\n            long n = ni(), m = ni();\n            long x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni();\n        long tx1 = Math.min(x1, x2), tx2 = x1 + x2 - tx1;\n        long ty1 = Math.min(y1, y2), ty2 = y1 + y2 - ty1;\n        long dx = tx2 - tx1;\n        long dy = ty2 - ty1;\n        \n    }\n\n    class House implements Comparable<House> {\n        int x, a;\n        public int compareTo(House h) {\n            return x < h.x ? -1 : 1;\n        }\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n    static class Cottage implements Comparable<Cottage> {\n        public int x;\n        public double a;\n\n        public Cottage(int x, int a) {\n            this.x = x;\n            this.a = a;\n        }\n\n        public int compareTo(Cottage c) {\n            return x - c.x;\n        }\n    }\n\n    static final double e = 1e-9;\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 n = in.nextInt();\n        int t = in.nextInt();\n        Cottage[] cottages = new Cottage[n];\n\n        for (int i = 0; i < n; i++)\n            cottages[i] = new Cottage(in.nextInt(), in.nextInt());\n\n        Arrays.sort(cottages);\n\n        int ans = 2;\n\n        for (int i = 1; i < cottages.length; i++) {\n            double diff = cottages[i].x - cottages[i - 1].x - cottages[i - 1].a / 2 - cottages[i].a / 2;\n            ans = Math.abs(diff - t) < e ? ans + 1 : diff - t < -e ? ans : ans + 2;\n        }\n\n        out.print(ans);\n        out.close();\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n/**\n * Created by HREN_VAM.\n */\n\npublic class A implements Runnable{\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n    public static final String filename = \"a\";\n\n    class I implements Comparable<I>{\n\n        int x;\n        int a;\n\n        I(int x, int a){\n            this.x = x;\n            this.a = a;\n        }\n\n        public int compareTo(I o){\n            return Double.compare(x, o.x);\n        }\n    }\n\n    public void solve() throws IOException{\n        int n = nextInt();\n        int t = nextInt();\n\n        I[] a = new I[n];\n\n        for(int i = 0;i < n;i ++){\n            a[i] = new I(nextInt(), nextInt());\n        }\n\n        int res = 2;\n\n        Arrays.sort(a);\n        for(int i = 1;i < n;i ++){\n            if((a[i].x - a[i - 1].x - 1.0 * (a[i].a + a[i - 1].a) / 2) >= t)res ++;\n            if((a[i].x - a[i - 1].x - 1.0 * (a[i].a + a[i - 1].a) / 2) > t)res ++;\n        }\n        out.println(res);\n    }\n\n    public void run(){\n        try{\n            Locale.setDefault(Locale.US);\n            in = new BufferedReader(new InputStreamReader(System.in));\n            //in = new BufferedReader(new FileReader(filename + \".in\"));\n            out = new PrintWriter(System.out);\n            //out = new PrintWriter(new FileWriter(filename + \".out\"));\n            st = new StringTokenizer(\"\");\n            solve();\n            out.close();\n        } catch(IOException e){\n            throw new RuntimeException(e);\n        }\n    }\n\n    public static void main(String[] args){\n        new Thread(new A()).start();\n    }\n\n    public String nextToken() throws IOException{\n        while(!st.hasMoreTokens()){\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.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}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n    private BufferedReader in;\n    private PrintWriter out;\n    private StringTokenizer st;\n    \n    private void eat(String line)\n    {\n        st = new StringTokenizer(line);\n    }\n    \n    private String next() throws IOException\n    {\n        while(!st.hasMoreTokens()) {\n            String line = in.readLine();\n            if(line == null)\n                return null;\n            eat(line);\n        }\n        return st.nextToken();\n    }\n    \n    private int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n    \n    public void run()\n    {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(new OutputStreamWriter(System.out));\n            eat(\"\");\n            \n            go();\n            \n            out.close();\n        } catch(Exception e) {\n            e.printStackTrace();\n            System.exit(-1);\n        }\n    }\n    \n    public static void main(String[] args)\n    {\n        new Thread(new Main()).start();\n    }\n    \n    public void go() throws IOException\n    {\n        int n = nextInt(), t = nextInt();\n        int[] x = new int[n], a = new int[n];\n        for(int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            a[i] = nextInt();\n        }\n        out.println(new Algo().solve(n, t, x, a));\n    }\n}\n\nfinal class Algo {\n    public int solve(int n, int t, final int[] x, final int[] a)\n    {\n        Integer[] order = new Integer[n];\n        for(int i = 0; i < n; ++i)\n            order[i] = i;\n        Arrays.sort(order, new Comparator<Integer>() {\n            public int compare(Integer a, Integer b)\n            {\n                return x[a] - x[b];\n            }\n        });\n        int result = 2;\n        for(int i = 0; i + 1 < n; ++i) {\n            int u = order[i], v = order[i + 1];\n            int dist = 2 * (x[v] - x[u]) - (a[v] + a[u]);\n            if(dist > 2 * t)\n                result += 2;\n            else if(dist == 2 * t)\n                ++result;\n        }\n        return result;\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Village{\n\tstatic class House implements Comparable<House>{\n\t\tpublic double center, length;\n\n\t\tpublic House(double center, double  length){\n\t\t\tthis.center = center;\n\t\t\tthis.length = length;\n\t\t}\n\t\tpublic double getRight(){\n\t\t\treturn center + length/2;\n\t\t}\n\t\tpublic double getLeft(){\n\t\t\treturn center - length/2;\n\t\t}\n\t\tpublic int compareTo(House h){\n\t\t\treturn this.center < h.center ? -1 : this.center == h.center ? 0 : 1;\n\t\t}\n\n\t}\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tString[] fline = in.nextLine().split(\"\\\\s+\");\n\t\tint N = Integer.parseInt(fline[0]);\n\t\tint T = Integer.parseInt(fline[1]);\n\n\t\tHouse[] houses = new House[N];\n\t\tfor (int i = 0; i < N; i++){\n\t\t\tString[] house = in.nextLine().split(\"\\\\s+\");\n\t\t\thouses[i] = new House(Double.parseDouble(house[0]), Double.parseDouble(house[1]));\n\t\t}\n\t\tArrays.sort(houses);\n\t\tint count = 2;\n\t\tfor (int i = 0; i < houses.length - 1; i++){\n\t\t\t//how many positions between house i and house i + 1 can we fit in?\n\t\t\tdouble diff = houses[i+1].getLeft() - houses[i].getRight();\n\t\t\tif (diff < T) continue;\n\t\t\tif (Math.abs(diff - T) < 1E-12) count++;\n\t\t\telse count+=2;\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n\t\n\tpublic Main() {\n\t\tsuper();\n\t}\n\t\n\tpublic static void main(String... args) {\n\t\tMain main = new Main();\n\t\tmain.start();\n\t}\n\t\n\t\n\tpublic void start() {\n\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\tint n = in.nextInt();\n\t\tint t = in.nextInt();\n\t\tHouse list[] = new House[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = in.nextInt();\n\t\t\tint a = in.nextInt();\n\t\t\tlist[i] = new House(x, a);\n\t\t}\n\t\tArrays.sort(list);\n\t\tint c = 2;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tfloat d = list[i].left - list[i - 1].right;\n\t\t\tif (d == t) c++;\n\t\t\telse if (d > t) c += 2;\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n}\n\n\nclass House implements Comparable<House> {\n\tpublic int x;\n\tpublic float left, right;\n\tpublic House(int x, int a) {\n\t\tthis.x = x;\n\t\tfloat h = a / 2f;\n\t\tthis.left = x - h;\n\t\tthis.right = x + h;\n\t}\n\t\n\tpublic int compareTo(House h) {\n\t\treturn this.x == h.x ? 0 : this.x < h.x ? -1 : 1;\n\t}\n\t\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.awt.*;\n\npublic class A\n{\n\tstatic Comparator<Point> cmp = new Comparator<Point>()\n\t{\n\t\tpublic int compare(Point a, Point b)\n\t\t{\n\t\t\tif(a.x < b.x)\n\t\t\t\treturn -1;\n\t\t\telse if(a.x > b.x)\n\t\t\t\treturn 1;\n\n\t\t\treturn 0;\n\t\t}\n\t};\n\n\tpublic static void main(String args[])\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\n\t\twhile(scan.hasNextInt())\n\t\t{\n\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt();\n\n\t\tPoint[] a = new Point[n];\n\n\t\tfor(int i=0;i < n;i++)\n\t\t{\n\t\t\ta[i] = new Point();\n\t\t\ta[i].x = scan.nextInt();\n\t\t\ta[i].y = scan.nextInt();\n\t\t}\n\n\t\tArrays.sort(a, cmp);\n\n\t\tint rtn = 0;\n\n\t\tArrayList<Double> ans = new ArrayList<Double>();\n\n\t\tfor(int i=0;i < n;i++)\n\t\t{\n\t\t\t//Left\n\t\t\tdouble lb = a[i].x - (a[i].y / 2.0) - k;\n\t\t\tdouble pos = lb + (k/2.0);\n\t\t\tboolean good = true;\n\n\t\t\tfor(int j=0;j < ans.size();j++)\n\t\t\t\tif(Math.abs(ans.get(j) - pos) < 0.0000001)\n\t\t\t\t\tgood = false;\n\n\n\t\t\tif(good && (i == 0 || a[i-1].x + (a[i-1].y / 2.0) <= lb))\n\t\t\t{\n\t\t\t\trtn++;\n\t\t\t\tans.add(pos);\n\t\t\t}\n\n\t\t\tdouble rb = a[i].x + (a[i].y / 2.0) + k;\n\t\t\tpos = rb - (k/2.0);\n\t\t\tgood = true;\n\n\t\t\tfor(int j=0;j < ans.size();j++)\n\t\t\t\tif(Math.abs(ans.get(j) - pos) < 0.0000001)\n\t\t\t\t\tgood = false;\n\n\t\t\tif(good && (i == n-1 || a[i+1].x - (a[i+1].y / 2.0) >= rb))\n\t\t\t{\n\t\t\t\trtn++;\n\t\t\t\tans.add(pos);\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(rtn);\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\t\n\tclass Segment {\n\t\tint l, r;\n\t\tSegment(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tSegment o = (Segment)obj;\n\t\t\treturn l == o.l && r == o.r;\n\t\t}\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\treturn 1000 * l + r;\n\t\t}\n\t}\n\n\tpublic void _main() throws IOException {\n\t\tint n = nextInt();\n\t\tint t = nextInt();\n\t\tint[] x = new int[n];\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = nextInt();\n\t\t\ta[i] = nextInt();\n\t\t}\t\t\n\t\tSet<Segment> set = new HashSet<Segment>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint l = 2 * x[i] + a[i];\n\t\t\tint r = 2 * x[i] + a[i] + 2 * t;\n\t\t\tboolean ok = true;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (i == j) continue;\n\t\t\t\tint L = Math.max(l, 2 * x[j] - a[j]);\n\t\t\t\tint R = Math.min(r, 2 * x[j] + a[j]);\t\t\t\t\n\t\t\t\tif (L < R) {\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t\tset.add(new Segment(l, r));\n\t\t\t\n\t\t\tl = 2 * x[i] - a[i] - 2 * t;\n\t\t\tr = 2 * x[i] - a[i];\t\t\t\n\t\t\tok = true;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (i == j) continue;\n\t\t\t\tint L = Math.max(l, 2 * x[j] - a[j]);\n\t\t\t\tint R = Math.min(r, 2 * x[j] + a[j]);\n\t\t\t\tif (L < R) {\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t\tset.add(new Segment(l, r));\n\t\t}\n\t\tout.print(set.size());\n\t}\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\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", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class test \n{  \n    public static void main(String[] args) \n    {\n        Scanner in=new Scanner(System.in);\n        int n=in.nextInt();\n        int t=in.nextInt();\n        \n        House[] houses=new House[n];\n        \n        for(int i=0;i<n;i++)\n        {\n            houses[i]=new House(in.nextInt(),in.nextInt());\n        }\n        \n        Arrays.sort(houses);\n        \n        int count=2;\n        \n        for(int i=0;i<n-1;i++)\n        {\n            double start=houses[i].x+(double)houses[i].a/2;\n            double end=houses[i+1].x-(double)houses[i+1].a/2;\n            \n            if(end-start==t)\n        \tcount++;\n            if(end-start>t)\n        \tcount+=2;\n        }\n        \n        System.out.println(count);\n \n    }\n}\n\nclass House implements Comparable<House>\n{\n    int x;\n    int a;\n    \n    public House(int _x, int _a)\n    {\n\tx=_x;\n\ta=_a;\n    }\n\n    @Override\n    public int compareTo(House o) {\n\treturn x-o.x;\n    }\n    \n}\n\n\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n/**\n * @author Alexander Grigoryev\n *         Created on 28.07.2011\n */\npublic\nclass Main {\n    static Scanner in = new Scanner(System.in);\n\n    public static\n    void main(String[] args) {\n        int n = in.nextInt();\n        int t = in.nextInt();\n\n        List<Integer> v = new ArrayList<Integer>(n);\n        for(int i = 0; i < n; i++) {\n            int a = in.nextInt();\n            int b = in.nextInt();\n            v.add(2 * a - b);\n            v.add(2 * a + b);\n        }\n        Collections.sort(v);\n        int ans = 2;\n        for(int i = 2; i < v.size(); i += 2) {\n            if(v.get(i) - v.get(i - 1) > 2 * t) ans += 2;\n            if(v.get(i) - v.get(i - 1) == 2 * t) ans++;\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Village\n{\n\tstatic Scanner in = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) );\n\n\tpublic static void main( String[] args )\n\t{\n\t\tint n = in.nextInt(), t = 2*in.nextInt(), h[][] = new int[n][2], ans = 2;\n\t\tfor( int i = 0; i < n; i++ )\n\t\t{\n\t\t\th[i][0] = 2*in.nextInt();\n\t\t\th[i][1] = in.nextInt();\n\t\t}\n\t\tArrays.sort( h, new Comp() );\n\t\tfor( int i = 1; i < n; i++ )\n\t\t{\n\t\t\tint d = (h[i][0]-h[i][1])-(h[i-1][0]+h[i-1][1]);\n\t\t\tif( d > t ) ans += 2;\n\t\t\telse if( d == t ) ans++;\n\t\t}\n\t\tSystem.out.println( ans );\n\t}\n\n\tstatic class Comp implements Comparator<int[]> { public int compare( int[] a, int[] b ) { return a[0]-b[0]; } }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\n/**\n * \n */\n\n/**\n * @author burdakovd\n * \n */\npublic class A {\n\n\tstatic class House {\n\t\tint x, a;\n\t}\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(final String[] args) {\n\t\tfinal Scanner in = new Scanner(System.in);\n\t\tfinal PrintWriter out = new PrintWriter(System.out);\n\n\t\ttry {\n\t\t\tfinal int n = in.nextInt();\n\t\t\tfinal int t = in.nextInt();\n\n\t\t\tfinal House[] h = new House[n];\n\t\t\tfor (int i = 0; i < h.length; ++i) {\n\t\t\t\th[i] = new House();\n\t\t\t\th[i].x = in.nextInt();\n\t\t\t\th[i].a = in.nextInt();\n\t\t\t}\n\n\t\t\tArrays.sort(h, new Comparator<House>() {\n\n\t\t\t\t@Override\n\t\t\t\tpublic int compare(final House o1, final House o2) {\n\t\t\t\t\treturn Integer.valueOf(o1.x).compareTo(o2.x);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tint ans = 2;\n\t\t\tfor (int i = 1; i < n; ++i) {\n\t\t\t\tfinal int dspace = 2 * h[i].x - h[i].a\n\t\t\t\t\t\t- (2 * h[i - 1].x + h[i - 1].a);\n\t\t\t\tif (dspace == 2 * t) {\n\t\t\t\t\t++ans;\n\t\t\t\t} else if (dspace > 2 * t) {\n\t\t\t\t\tans += 2;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tout.println(ans);\n\n\t\t} finally {\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\n\npublic class Main {\n\tprivate static StreamTokenizer in;\n\tprivate static PrintWriter out;\n\t\n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t}\n\t\n\tprivate static String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tint n = nextInt(), t = nextInt() * 2;\n\t\tint[][] a = new int[n][2];\n\t\tfor (int i=0; i<n; i++) {\n\t\t\ta[i][0] = nextInt() * 2;\n\t\t\ta[i][1] = nextInt() * 2;\n\t\t}\n\t\t\n\t\tArrays.sort(a, new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\treturn a[0]>b[0]?1:a[1]<b[1]?-1:0;\n\t\t\t}\n\t\t});\n\t\t\n\t\tint s = 2;\n\t\t\n\t\tfor (int i=0; i<n-1; i++) {\n\t\t\tint g = (a[i+1][0]-a[i][0])-(a[i+1][1]+a[i][1])/2;\n\t\t\tif (g > t) s += 2;\n\t\t\tif (g == t) s+= 1;\n\t\t}\n\t\tout.println(s);\n\t\t\n\t\t\n\t\tout.flush();\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Collections;\n\npublic class A {\n\t\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\n\t\t\tString[] s = in.readLine().split(\" \");\n\t\t\tint n = Integer.parseInt(s[0]);\n\t\t\tint t = Integer.parseInt(s[1]) * 2;\n\t\t\t\n\t\t\tint[] walls = new int[n*2]; \n\t\t\t\n\t\t\tfor (int i=0; i<n; i++)\n\t\t\t{\n\t\t\t\ts = in.readLine().split(\" \");\n\t\t\t\tint x = Integer.parseInt(s[0]) * 2;\n\t\t\t\tint a = Integer.parseInt(s[1]);\n\t\t\t\twalls[i*2] = x-a;\n\t\t\t\twalls[i*2+1] = x+a;\n\t\t\t}\n\t\t\t\n\t\t\tArrays.sort(walls);\n\t\t\t\n\t\t\tint count = 2;\n\t\t\t\n\t\t\tfor (int i=1; i<n*2-2; i+=2) {\n\t\t\t\tint space = walls[i+1] - walls[i]; \n\t\t\t\tif ( space == t)\n\t\t\t\t\tcount += 1;\n\t\t\t\telse if ( space > t)\n\t\t\t\t\tcount += 2;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println (count);\n\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class village {\n    static int[] X, A;\n    public void solve()\n    {\n        Scanner in = new Scanner(System.in);\n        int N = in.nextInt(), T = in.nextInt();\n        X = new int[N];\n        A = new int[N];\n\n        for(int i = 0; i < N; i++) {\n            X[i] = in.nextInt(); A[i] = in.nextInt();\n        }\n\n        if(N == 1) {\n            System.out.println(\"2\");\n            return; \n        }\n\n        List<Integer> x = new ArrayList<Integer>();\n        for(int i = 0; i < N; i++) {\n            x.add(i);\n        }\n\n        Collections.sort(x, new Comp());\n\n        int places = 0;\n        for(int i = 0; i < N-1; i++) {\n            double space = (X[x.get(i+1)]-X[x.get(i)]-A[x.get(i+1)]/2.0-A[x.get(i)]/2.0);\n            if(space < T) {\n                continue;\n            } if(space - T < 1e-9) {\n                places++;\n            } else if(space > T) {\n                places+=2;\n            }\n        }\n        System.out.println(places+2);\n    }\n\n    public class Comp implements Comparator<Integer> {\n            public int compare(Integer i1, Integer i2) {\n                return X[i1]-X[i2];\n            }\n    }\n\n    public static void main(String[] args)\n    {\n        new village().solve();\n    }\n}\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class A implements Runnable\n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tnew Thread(null, new A(), \"\", 1 << 20).start();\n\t}\n\t\n\tString file = \"input\";\n\tBufferedReader input;\n\tPrintWriter out;\n\t\n\tpublic void run() \n\t{\n\t\ttry\n\t\t{\n\t\t\t//input = new BufferedReader(new FileReader(file + \".in\"));\n\t\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\tsolve();\n\t\t\tinput.close();\n\t\t\tout.close();\n\t\t}\n\t\tcatch(Exception e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\tint N, T;\n\tvoid solve() throws IOException\n\t{\n\t\tStringTokenizer st = tokens();\n\t\tN = nextInt(st); T = nextInt(st);\n\t\tT *= 2;\n\t\tArrayList<Pair> list = new ArrayList<Pair>();\n\t\tfor(int i = 0; i < N; i++)\n\t\t{\n\t\t\tst = tokens();\n\t\t\tint c = nextInt(st), L = nextInt(st);\n\t\t\tc *= 2; L *= 2;\n\t\t\tlist.add(new Pair(c - L / 2, c + L / 2));\n\t\t}\n\t\tCollections.sort(list);\n\t\tHashSet<Integer> set = new HashSet<Integer>();\n\t\tfor(int i = 0; i < list.size(); i++)\n\t\t{\n\t\t\tif(i == 0 || list.get(i).x - list.get(i - 1).y >= T)\n\t\t\t{\n\t\t\t\tset.add(list.get(i).x - T / 2);\n\t\t\t}\n\t\t\tif(i == list.size() - 1 || list.get(i + 1).x - list.get(i).y >= T)\n\t\t\t{\n\t\t\t\tset.add(list.get(i).y + T / 2);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(set.size());\n\t}\n\tclass Pair implements Comparable<Pair>\n\t{\n\t\tint x, y;\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\tpublic int compareTo(Pair p)\n\t\t{\n\t\t\tif(x != p.x) return x - p.x;\n\t\t\treturn y - p.y;\n\t\t}\n\t}\n\n\tStringTokenizer tokens() throws IOException\n\t{\n\t\treturn new StringTokenizer(input.readLine());\n\t}\n\t\n\tString next(StringTokenizer st)\n\t{\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(input.readLine());\n\t}\n\t\n\tint nextInt(StringTokenizer st)\n\t{\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(input.readLine());\n\t}\n\t\n\tdouble nextDouble(StringTokenizer st)\n\t{\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\t\n\tvoid print(Object... o)\n\t{\n\t\tout.println(deepToString(o));\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A {\n    static class Sort implements Comparable<Sort> {\n        int x,a;\n        public int compareTo(Sort o) {\n            if (this.x==o.x)\n                return this.a-o.a;\n            return this.x-o.x;\n        }\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int t = sc.nextInt();\n        Sort[]a = new Sort[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = new Sort();\n            a[i].x = sc.nextInt();\n            a[i].a = sc.nextInt();\n        }\n        Arrays.sort(a);\n        int ans = 2;\n        for (int i = 1; i < n; i++) {\n            double d = a[i].x-a[i].a / 2.0-a[i-1].x-a[i-1].a / 2.0;\n            if (d==t)\n                ans++;\n            else if (d > t)\n                ans += 2;\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.security.KeyException;\nimport java.util.HashMap;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class P15A\n{\n    public static void main (String [] args)\n    {\n\n        Scanner scan = new Scanner(System.in);\n\n        int n = scan.nextInt(), t = scan.nextInt();\n\n        TreeMap<Integer,Integer> hm = new TreeMap<Integer, Integer>();\n\n        for (int i = 0; i < n; i++) hm.put(scan.nextInt(),scan.nextInt());\n\n        int _x = 0, _a = 0, res = 2;\n\n        boolean started = false;\n\n        for (Integer key : hm.keySet())\n        {\n\n            if (!started)\n            {\n                _x = key;\n                _a = hm.get(_x);\n                started = true;\n                continue;\n            }\n\n            if (key - _x - ((Integer)hm.get(key) + _a)/2.0 > t) res +=2;\n            else if (key - _x - ((Integer)hm.get(key) + _a)/2.0 == t) res++;\n\n            _x = key;\n            _a = hm.get(_x);\n\n        }\n\n        System.out.println(res);\n\n\n    }\n\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n    static InputStreamReader in = new InputStreamReader(System.in);\n    static BufferedReader bf = new BufferedReader(in);\n    static StreamTokenizer st = new StreamTokenizer(bf);\n    static Scanner sc = new Scanner(System.in);\n\n    static class Sort implements Comparable<Sort> {\n        int x, a;\n\n        public int compareTo(Sort arg0) {\n            if (this.x > arg0.x)\n                return 1;\n            return 0;\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        int n = nextInt();\n        double t = nextInt();\n        Sort[] p = new Sort[n];\n\n        for (int i = 0; i < n; i++) {\n            p[i] = new Sort();\n            p[i].x = nextInt();\n            p[i].a = nextInt();\n        }\n        int ans = 2;\n        Arrays.sort(p);\n        for (int i = 1; i < p.length; i++) {\n            double k = p[i].x - p[i].a / 2.0 - p[i - 1].x - p[i - 1].a / 2.0;\n            if (t == k)\n                ans++;\n            else if (k > t)\n                ans += 2;\n        }\n        System.out.println(ans);\n    }\n\n    private static String nextString() throws IOException {\n        st.nextToken();\n        return st.sval;\n    }\n\n    private static int nextInt() throws IOException {\n        st.nextToken();\n        return (int) st.nval;\n    }\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class CottageVillage\n{\n\tpublic Scanner in = new Scanner(System.in);\n\tpublic PrintStream out = System.out;\n\n\tpublic int n, t;\n\tpublic Pair[] v;\n\t\n\tpublic void main()\n\t{\n\t\tn = in.nextInt();\n\t\tt = in.nextInt();\n\t\t\n\t\tint i;\n\t\tv = new Pair[n];\n\t\tfor(i=0;i<n;++i) v[i] = new Pair(in.nextInt() * 2, in.nextInt());\n\t\t\n\t\tArrays.sort(v);\n\t\t\n\t\tint res = 2;\n\t\tfor(i=0;i+1<n;++i)\n\t\t{\n\t\t\tif(v[i].x + v[i].y + 2*t == v[i+1].x - v[i+1].y) ++res;\n\t\t\telse if(v[i].x+v[i].y+2*t < v[i+1].x-v[i+1].y) res +=2;\n\t\t}\n\t\t\n\t\tout.println(res);\n\t}//end public void main()\n\n\t//int pair\n\tprivate class Pair implements Comparable<Pair>\n\t{\n\t\tpublic int x, y;\n\t\tpublic Pair(int xx, int yy) { x = xx; y = yy; }\n\n\t\tpublic int compareTo(Pair u)\n\t\t{\n\t\t\tif(x!=u.x) return x-u.x;\n\t\t\treturn y-u.y;\n\t\t}\n\n\t\tpublic String toString() { return \"(\" + x + \",\" + y + \")\"; }\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\t(new CottageVillage()).main();\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.awt.geom.Point2D;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A\n{\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tint t=in.nextInt();\n\t\tpt[] P=new pt[n];\n\t\tfor (int i=0; i<n; ++i)\n\t\t\tP[i]=new pt(in.nextInt(), in.nextInt());\n\t\tArrays.sort(P);\n\t\tint res=2;\n\t\tfor (int i=0; i+1<n; ++i)\n\t\t{\n\t\t\tdouble d=P[i+1].x-P[i].x-P[i+1].a/2.-P[i].a/2.;\n\t\t\tif (Math.abs(d-t) <= 1e-11)\n\t\t\t\t++res;\n\t\t\telse if (d>t)\n\t\t\t\tres+=2;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n\t\n}\n\nclass pt implements Comparable<pt>\n{\n\tint x,a;\n\tpt(int x, int a)\n\t{\n\t\tthis.x=x;\n\t\tthis.a=a;\n\t}\n\t\n\tpublic int compareTo(pt o)\n\t{\n\t\treturn x-o.x;\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class a {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint t = sc.nextInt();\n\t\tint[][] xa = new int[n][2];\n\t\tfor(int i=0; i<n; ++i) {\n\t\t\txa[i][0] = sc.nextInt();\n\t\t\txa[i][1] = sc.nextInt();\n\t\t}\n\t    Arrays.sort(xa, new Comparator<int[]>(){\n            @Override\n            public int compare(int[] a0, int[] a1){\n                return a0[0]-a1[0];\n            }\n        });\n\t\t  int ans=2;\n\t        for(int i=0; i<n-1; i++){\n\t            int s=(xa[i+1][0]*2-xa[i+1][1])-(xa[i][0]*2+xa[i][1]);\n\t            if(s>t*2){\n\t                ans+=2;\n\t            }else if(s==t*2){\n\t                ans++;\n\t            }\n\t        }\n\t        System.out.println(ans+\"\");\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport static java.lang.System.out;\n\npublic class Flatville\n{\n    public static void main( String args[] )\n    {\n        class SquareHouse implements Comparable<SquareHouse>\n        {\n            public SquareHouse( double posLeft, double sideLen )\n            { \n                _posLeft = posLeft;\n                _sideLen = sideLen;\n            }\n\n            public double posLeft()\n            { return _posLeft; }\n\n            public double posRight()\n            { return _posLeft + _sideLen; }\n\n            public int compareTo( SquareHouse house )\n            {\n                double dist = _posLeft - house.posLeft();\n                if ( dist < 0 )\n                    return -1;\n                else if ( dist > 0 )\n                    return 1;\n                else return 0;\n            }\n\n            private double _posLeft;\n            private double _sideLen;\n        }\n\n        Scanner scanner = new Scanner( System.in );\n\n        // Read the header\n        final int nHouses    = scanner.nextInt();\n        final double sideLen = scanner.nextDouble();\n\n        ArrayList<SquareHouse> houses = new ArrayList<SquareHouse>();\n\n        // Read the houses\n        for ( int iHouse = 0; iHouse < nHouses; ++iHouse )\n        {\n            double pos  = scanner.nextDouble();\n            double size = scanner.nextDouble();\n            double posLeft = pos - size / 2.0;\n            houses.add( new SquareHouse( posLeft, size ) );\n        }\n\n        // Sort the houses\n        Collections.sort( houses );\n\n        int nPositions = 2;\n        for ( int iHouse = 0; iHouse < nHouses - 1; ++iHouse )\n        {\n            double space = houses.get( iHouse + 1 ).posLeft() - houses.get( iHouse ).posRight();\n            if ( sideLen < space )\n                nPositions += 2;\n            else if ( sideLen == space )\n                nPositions++;\n        }\n\n        out.println( nPositions );\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskA implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TaskA()).start();\n//\t\tnew Template().run();\n\t}\n\n\tpublic TaskA() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//\t\t\tout.print(\"Case #\" + (testNumber + 1) + \": \");\n//        }\n\t\tint n = in.readInt();\n\t\tint t = in.readInt();\n\t\tfinal int[] x = new int[n];\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = in.readInt();\n\t\t\ta[i] = in.readInt();\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<Integer>() {\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 ans = 2;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint d = x[o[i]] - x[o[i - 1]];\n\t\t\td = 2 * d - a[o[i]] - a[o[i - 1]] - 2 * t;\n\t\t\tif (d > 0)\n\t\t\t\tans += 2;\n\t\t\telse if (d == 0)\n\t\t\t\tans++;\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Date 22.11.2011\n * Time 17:49:45\n * Author Woodey\n * $\n */\n\npublic class A15 {\n\t\n\tfinal double eps = 10e-9;\n\t\n\tclass Pair implements Comparable<Pair>{\n\t\tint x;\n\t\tint length;\n\t\t\n\t\tPair(int x, int length) {\n\t\t\tthis.x = x;\n\t\t\tthis.length = length;\n\t\t}\n\n\t\tpublic int compareTo(Pair p) {\n\t\t\treturn x - p.x;\n\t\t}\n\t}\n\t\n\tprivate void Solution() throws IOException {\n\t\tint n = nextInt(), t = nextInt(), ans = 2;\n\t\tPair[] pairs = new Pair[n];\n\t\tfor (int i = 0; i < n; i ++) {\n\t\t\tint x = nextInt(), length = nextInt();\n\t\t\tpairs[i] = new Pair(x, length);\n\t\t}\n\t\tArrays.sort(pairs);\n\t\tfor (int i = 0; i < n-1; i ++) {\n\t\t\tdouble place = pairs[i+1].x - pairs[i].x - (double) pairs[i+1].length/2 - (double) pairs[i].length/2;\n\t\t\tif (place > t)\n\t\t\t\tans += 2; else\n\t\t\t\t\tif ((int) (place+eps) == t)\n\t\t\t\t\t\tans ++;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A15().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", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class Prob015A\n{\n    public static void main( String[] Args )\n    {\n        Scanner scan = new Scanner( System.in );\n        int numHouses = scan.nextInt();\n        int side = scan.nextInt() * 2;\n\n        ArrayList<Integer> sides = new ArrayList<Integer>();\n        for ( int x = 0; x < numHouses; x++ )\n        {\n            int c = scan.nextInt() * 2;\n            int s = scan.nextInt();\n\n            int l = c - s;\n            int r = c + s;\n\n            int li = Collections.binarySearch( sides, l );\n            int ri = Collections.binarySearch( sides, r );\n\n            if ( li >= 0 && ri >= 0 )\n            {\n                sides.remove( li );\n                sides.remove( li );\n            }\n            else if ( li >= 0 )\n                sides.set( li, r );\n            else if ( ri >= 0 )\n                sides.set( ri, l );\n            else\n            {\n                sides.add( -li - 1, r );\n                sides.add( -li - 1, l );\n            }\n        }\n\n        int possibilities = 2;\n        for ( int x = 1; x < sides.size() - 1; x += 2 )\n            if ( sides.get( x + 1 ) - sides.get( x ) > side )\n                possibilities += 2;\n            else if ( sides.get( x + 1 ) - sides.get( x ) == side )\n                possibilities += 1;\n\n        System.out.println( possibilities );\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "//package round15;\n\n\nimport java.io.BufferedOutputStream;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.io.StringReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n\t\n\tpublic void solve()\n\t{\n\t\tint n = ni();\n\t\tint t = ni();\n\t\tPair[] p = new Pair[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tp[i] = new Pair();\n\t\t\tp[i].x = ni();\n\t\t\tp[i].a = ni();\n\t\t}\n\t\tArrays.sort(p);\n\t\t\n\t\tint ct = 2;\n\t\tfor(int i = 0;i < n - 1;i++){\n\t\t\tfloat d = p[i + 1].x - (float)p[i + 1].a / 2 - p[i].x - (float)p[i].a / 2;\n\t\t\tif(Math.abs(d - t) < EPS){\n\t\t\t\tct++;\n\t\t\t}else if(d > t){\n\t\t\t\tct += 2;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ct);\n\t}\n\n\tdouble EPS = 0.0001;\n\t\n\tprivate static class Pair implements Comparable<Pair>\n\t{\n\t\tpublic int x;\n\t\tpublic int a;\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\t\n\tpublic void run() throws Exception\n\t{\n//\t\tin = new Scanner(new StringReader(\"2 3 0 4 5 2\"));\n\t\tin = new Scanner(System.in);\n\t\tSystem.setOut(new PrintStream(new BufferedOutputStream(System.out)));\n\t\tout = new PrintWriter(System.out);\n\t\t\n//\t\tint n = in.nextInt();\n\t\tint n = 1;\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\tlong t = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\tout.flush();\n//\t\t\tSystem.err.printf(\"%04d/%04d %7d%n\", i, n, System.currentTimeMillis() - t);\n\t\t}\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew A().run();\n\t}\n\t\n\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "//package round15;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A {\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 n = nextInt(),\n\t\t\tt = nextInt(),\n\t\t\tx[] = new int[n],\n\t\t\ta[] = new int[n];\n\t\t\n\t\tfor (int i=0; i<n; i++){\n\t\t\tx[i] = nextInt();\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\t\n\t\tfor (int i=0; i<n-1; i++)\n\t\t\tfor (int j=i+1; j<n; j++)\n\t\t\t\tif (x[i] > x[j]){\n\t\t\t\t\tint p = x[i]; x[i] = x[j]; x[j] = p;\n\t\t\t\t\t\tp = a[i]; a[i] = a[j]; a[j] = p;\n\t\t\t\t}\n\t\t\n\t\tdouble l[] = new double[n];\n\t\tdouble r[] = new double[n];\n\t\tfor (int i=0; i<n; i++){\n\t\t\tl[i] = x[i]-a[i]/2.0;\n\t\t\tr[i] = x[i]+a[i]/2.0;\n\t\t}\n\t\t\n\t\tint res = 2;\n\t\tfor (int i=1; i<n; i++){\n\t\t\tif (Math.abs(l[i]-r[i-1]-t) < 0.000001) res++;\n\t\t\telse if (l[i]-r[i-1] > t) res += 2;\n\t\t}\n\t\t\n\t\tout.println(res);\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "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\n\tstatic class House implements Comparable<House> {\n\t\tint x, a;\n\n\t\t@Override\n\t\tpublic int compareTo(House o) {\n\t\t\treturn x - o.x;\n\t\t}\n\n\t\tpublic House(int x, int a) {\n\t\t\tthis.x = x;\n\t\t\tthis.a = a;\n\t\t}\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint t = nextInt();\n\t\tHouse[] hs = new House[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ths[i] = new House(nextInt(), nextInt());\n\t\t}\n\t\tArrays.sort(hs);\n\t\tint ans = 2;\n\t\tfor (int i = 0; i < n - 1; ++i) {\n\t\t\tif (hs[i].a + hs[i + 1].a + 2 * t < 2 * (hs[i + 1].x - hs[i].x)) {\n\t\t\t\tans += 2;\n\t\t\t} else if (hs[i].a + hs[i + 1].a + 2 * t == 2 * (hs[i + 1].x - hs[i].x)) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\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", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n    static double eps = 1e-8;\n    public static void main(String[] args) {\n        Scanner r = new Scanner(System.in);\n        \n        int n = r.nextInt();\n        int t = r.nextInt();\n        \n        House[] a = new House[n];\n        for(int i = 0; i < n; i++){\n            double c = r.nextInt();\n            double l = r.nextInt();\n            a[i] = new House(c-l/2, l);\n        }\n        \n        Arrays.sort(a);\n        \n        int res = 0;\n        for(int i = 0; i < n-1; i++){\n            double dist = a[i+1].s - (a[i].s+a[i].l);\n            \n            if(Math.abs(dist - t) < eps)res++;\n            else if(dist > t)res += 2;\n        }\n        \n        System.out.println(res+2);\n    }\n}\n\nclass House implements Comparable<House>{\n    double s, l;\n    public House(double si, double li){\n        s = si;\n        l = li;\n    }\n    @Override\n    public int compareTo(House b) {\n        if(s < b.s)return -1;\n        else return 1;\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "//~ 22:04:48\nimport java.io.*;\nimport java.util.*;\n\npublic class Main{\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\tString out = \"\";\n\t\tString[] p = br.readLine().split(\"[ ]\");\n\t\tint n = Integer.valueOf(p[0]);\n\t\tdouble t = Double.valueOf(p[1]);\n\t\t\n\t\tint offset = 5000;\n\t\tboolean[] flags = new boolean[offset+5000];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tint[] q = toIntArray(br.readLine());\n\t\t\tint c = 2*q[0];\n\t\t\tfor(int j=-q[1];j<q[1];j++){\n\t\t\t\tflags[c+offset+j] = true;\n\t\t\t\t//~ System.out.println(c+offset+j);\n\t\t\t}\n\t\t}\n\t\tint buf = 0;\n\t\tint last = -1;\n\t\tint index = 0;\n\t\tfor(;index<flags.length;index++){\n\t\t\tif(flags[index]){\n\t\t\t\tif(last==-1){\n\t\t\t\t\tbuf++;\n\t\t\t\t}else{\n\t\t\t\t\t//~ System.out.println(last);\n\t\t\t\t\t//~ System.out.println(index);\n\t\t\t\t\tif(Math.abs(index-last-(2*t+1))<1e-10) buf++;\n\t\t\t\t\telse if(index-last>2*t+1) buf+=2;\n\t\t\t\t}\n\t\t\t\tlast = index;\n\t\t\t}\n\t\t}\n\t\tbuf ++;\n\t\tout = \"\"+buf+\"\\r\\n\";\n\t\tbw.write(out,0,out.length());\n\t\tbr.close();\n\t\tbw.close();\n\t}\n\tstatic int[] toIntArray(String line){\n\t\tString[] p = line.trim().split(\"\\\\s+\");\n\t\tint[] out = new int[p.length];\n\t\tfor(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]);\n\t\treturn out;\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class CottageVillage\n{\n\tScanner in;\n\tPrintWriter out;\n\t\n\tCottageVillage()\n\t{\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\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\tint ans(House a, House b, int t)\n\t{\n\t\tint diff = b.cordl - a.cordr;\n\t\t\n\t\tif(diff < t) return 0;\n\t\tif(diff == t) return 1;\n\t\treturn 2;\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tint\n\t\t\tn = in.nextInt(),\n\t\t\tt = in.nextInt() * 2;\n\t\tHouse[] hs = new House[n];\n\t\t\n\t\tfor(int i = 0; i < n; ++i)\n\t\t{\n\t\t\tint\n\t\t\t\tc = in.nextInt(),\n\t\t\t\tl = in.nextInt();\n\t\t\ths[i] = new House(2 * c - l, 2 * c + l);\n\t\t}\n\t\t\n\t\tArrays.sort(hs);\n\t\t\n\t\t//atleast 2 possible configs\n\t\tint co = 2;\n\t\tfor(int i = 0; i < n - 1; ++i)\n\t\t\tco += ans(hs[i], hs[i + 1], t);\n\t\t\n\t\tout.println(co);\n\t}\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException\n\t{\n\t\tCottageVillage t = new CottageVillage();\n\t\tt.solve();\n\t\tt.finalize();\n\t}\n}\n\nclass House implements Comparable<House>\n{\n\tpublic int cordl, cordr;\n\t\n\tpublic House(int c, int l)\n\t{\n\t\tcordl = c;\n\t\tcordr = l;\n\t}\n\t\n\t@Override\n\tpublic int compareTo(House h)\n\t{\n\t\treturn cordl - h.cordl;\n\t}\n}\n\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\tclass House implements Comparable<House> {\n\t\tint x;\n\t\tint a;\n\n\t\tpublic House(int x, int a) {\n\t\t\tthis.x = x;\n\t\t\tthis.a = a;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(House other) {\n\t\t\treturn x - other.x;\n\t\t}\n\t}\n\n\t// private void solution() throws IOException {\n\t// int t = in.nextInt();\n\t// while (t-- > 0) {\n\t// int n =in.nextInt();\n\t// int m = in.nextInt();\n\t// int x1 = in.nextInt();\n\t// int y1 = in.nextInt();\n\t// int x2 = in.nextInt();\n\t// int y2 = in.nextInt();\n\t//\t\t\t\n\t// }\n\t// }\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint t = in.nextInt();\n\t\tHouse[] h = new House[n];\n\t\tfor (int i = 0; i < h.length; ++i) {\n\t\t\th[i] = new House(in.nextInt(), in.nextInt());\n\t\t}\n\t\tArrays.sort(h);\n\t\tint res = 2;\n\t\tfor (int i = 0; i < h.length - 1; ++i) {\n\t\t\tdouble dist = h[i + 1].x - h[i + 1].a / 2.0 - (h[i].x + h[i].a / 2.0);\n\t\t\tif (dist >= t) {\n\t\t\t\tif (dist == t) {\n\t\t\t\t\t++res;\n\t\t\t\t} else {\n\t\t\t\t\tres += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class a {\n\n\tprivate void solve() throws Exception {\n\t\tint n = nextInt(), t = nextInt();\n\t\tint[] x = new int[n], a = new int[n];\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tx[i] = nextInt();\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tfor (int j = 0; j < n - 1; ++j){\n\t\t\t\tif (x[j] > x[j + 1]){\n\t\t\t\t\tint tmp = x[j];\n\t\t\t\t\tx[j] = x[j + 1];\n\t\t\t\t\tx[j + 1] = tmp;\n\t\t\t\t\t\n\t\t\t\t\ttmp = a[j];\n\t\t\t\t\ta[j] = a[j + 1];\n\t\t\t\t\ta[j + 1] = tmp;\n\t\t\t\t}\n\t\t\t}\n\t\tint res = 2;\n\t\tfor (int i = 1; i < n; ++i){\n\t\t\tint betw = (x[i] - x[i - 1]) * 2 - a[i] - a[i - 1];\n\t\t\tif (betw == t * 2)\n\t\t\t\t++res;\n\t\t\telse if (betw > t * 2)\n\t\t\t\tres += 2;\n\t\t}\n\t\tout.print(res);\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 a(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 a() {\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\tnew a().run();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n    \n        \n    void solve() throws IOException {\n        int n=ni();//have bult yet\n        int t=ni();//new house\n        \n        int[] center=new int[n];\n        int[] width=new int[n];\n        for(int i=0;i<n;i++){\n            center[i]=ni();\n            width[i]=ni();\n        }\n        for(int i=0;i<n;i++){\n            for(int j=i;j<n;j++){\n                if(center[i]>center[j]){\n                    int cent=center[i];\n                    int wid=width[i];\n                    center[i]=center[j];\n                    width[i]=width[j];\n                    center[j]=cent;\n                    width[j]=wid;\n                }\n            }\n        }\n        int count=2;\n        for(int i=0;i<n-1;i++){\n            //min way\n            double ideal=(double)width[i]/2+(double)width[i+1]/2+t;\n\n            //real way\n            double real=center[i+1]-center[i];\n            //out.println(ideal);\n            //out.println(real);\n            if(ideal==real)count++;\n            else{\n                if(ideal<real)count=count+2;\n            }\n        }\n        out.println(count);\n        \n    }\n    \n    public Main() 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 Main();\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemA_15 {\n    \n    final boolean ONLINE_JUDGE=System.getProperty(\"ONLINE_JUDGE\")!=null;\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok=new StringTokenizer(\"\");\n    \n    void init() throws FileNotFoundException{\n        if (ONLINE_JUDGE){\n            in=new BufferedReader(new InputStreamReader(System.in));\n            out =new PrintWriter(System.out);\n        }\n        else{\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\n        }\n    }\n    \n    String readString() throws IOException{\n        while(!tok.hasMoreTokens()){\n            tok=new StringTokenizer(in.readLine());\n        }\n        return tok.nextToken();\n    }\n    \n    int readInt() throws IOException{\n        return Integer.parseInt(readString());\n    }\n    \n    public static void main(String[] args){\n        new ProblemA_15().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    void solve() throws IOException{\n        int n=readInt();\n        int t=readInt();\n        Point[] a=new Point[n];\n        for (int i=0; i<n; i++){\n            a[i]=new Point(readInt(), readInt());\n        }\n        int count=2;\n        Arrays.sort(a, new Comparator<Point>(){\n\n            @Override\n            public int compare(Point p1, Point p2) {\n                return p1.x-p2.x;\n            }\n            \n        });\n        for (int i=1; i<n; i++){\n            double li=a[i-1].x+(double)a[i-1].y/2;\n            double ri=a[i].x-(double)a[i].y/2;\n            if (ri-li>t){\n                count+=2;\n            }\n            if (ri-li==t){\n                count++;\n            }\n        }\n        out.print(count);\n    }       \n}\n\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer split = new StringTokenizer(in.readLine());\n        int n = Integer.parseInt(split.nextToken());\n        double t = Double.parseDouble(split.nextToken());\n\n        House[] xaxis = new House[n];\n\n        for (int i = 0; i < n; i++) {\n            split = new StringTokenizer(in.readLine());\n            xaxis[i] = new House(Double.parseDouble(split.nextToken()), Double.parseDouble(split.nextToken()));\n        }\n        Arrays.sort(xaxis);\n        int count = 2;\n        for (int i = 0; i < xaxis.length - 1; i++) {\n            double free = (xaxis[i + 1].getX() - xaxis[i + 1].getSize() / 2.0) - (xaxis[i].getX() + xaxis[i].getSize() / 2.0);\n            if (free / t == 1.0) {\n                count++;\n            } else if (free / t > 1.0) {\n                count += 2;\n            }\n        }\n\n        System.out.println(count);\n    }\n}\n\nclass House implements Comparable<House> {\n\n    private double x;\n    private double size;\n\n    public House(double x, double size) {\n        this.x = x;\n        this.size = size;\n    }\n\n    public double getX() {\n        return x;\n    }\n\n    public double getSize() {\n        return size;\n    }\n\n    public int compareTo(House o) {\n        if (this.x > o.getX()) {\n            return 1;\n        } else if (this.x == o.getX()) {\n            return 0;\n        }\n        return -1;\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n    private static Node[] node;\n\n    public static void main(String[] args) {\n    Scanner cin = new Scanner(System.in);\n    int ret = 2, del;\n    int n = cin.nextInt();\n    int t = cin.nextInt() * 2;\n    node = new Node[n];\n    for (int i = 0; i < n; i++) {\n        int x = cin.nextInt();\n        int a = cin.nextInt();\n        node[i] = new Node(x * 2 - a, x * 2 + a);\n    }\n    Arrays.sort(node);\n    for (int i = 1; i < n; i++) {\n        del = node[i].l - node[i - 1].r;\n        if (del > t) {\n        ret += 2;\n        } else if (del == t) {\n        ret++;\n        }\n    }\n    System.out.println(ret);\n    }\n\n    private static class Node implements Comparable<Node> {\n    public int l;\n    public int r;\n\n    public Node(int l, int r) {\n        // TODO Auto-generated constructor stub\n        this.l = l;\n        this.r = r;\n    }\n\n    @Override\n    public int compareTo(Node arg0) {\n        // TODO Auto-generated method stub\n        return l - arg0.l;\n    }\n    }\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main\n{\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in/*new File(\"input.txt\")*/);\n\t\tint n = sc.nextInt(), t = sc.nextInt(), x, a, kol = 2;\n\t\tArrayList<Double> al = new ArrayList<Double>();\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tx = sc.nextInt();\n\t\t\ta = sc.nextInt();\n\t\t\tal.add(x - a/2.);\n\t\t\tal.add(x + a/2.);\t\n\t\t}\n\t\tCollections.sort(al);\n\t\tdouble d0 = 0; int k = 0, kn = al.size();\n\t\tfor(Double d: al)\n\t\t{\n\t\t\tif (k == 2)\n\t\t\t{\n\t\t\t\tif (d-d0>t) kol+=2; else\n\t\t\t\tif (d-d0==t) kol++;\n\t\t\t\td0 = d;\n\t\t\t\tk = 1;\t\t\n\t\t\t} else \n\t\t\t{\n\t\t\t\tk++;\n\t\t\t\td0 = d;\n\t\t\t}\t\t\t\n\t\t} \n\t\tSystem.out.print(kol);\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound15_A implements Runnable {\n\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tvoid init() throws IOException {\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new BetaRound15_A()).start();\n\t}\n\n\tclass House implements Comparable<House> {\n\t\tint left, right;\n\t\tHouse(int left, int right) {\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(House h) {\n\t\t\treturn this.left - h.left;\n\t\t}\n\t}\n\t\n\tint getAns(House h1, House h2, int t) {\n\t\tint d = h2.left - h1.right;\n\t\tif (d < t) return 0;\n\t\tif (d == t) return 1;\n\t\treturn 2;\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint t = readInt() * 2;\n\t\tHouse[] h = new House[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint c = readInt() * 2;\n\t\t\tint b = readInt();\n\t\t\th[i] = new House(c - b, c + b);\n\t\t}\n\t\tArrays.sort(h);\n\t\tint ans = 2;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tans += getAns(h[i - 1], h[i], t);\n\t\t}\n\t\tout.print(ans);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.awt.*;\n\npublic class A\n{\n\tstatic Comparator<Point> cmp = new Comparator<Point>()\n\t{\n\t\tpublic int compare(Point a, Point b)\n\t\t{\n\t\t\tif(a.x < b.x)\n\t\t\t\treturn -1;\n\t\t\telse if(a.x > b.x)\n\t\t\t\treturn 1;\n\n\t\t\treturn 0;\n\t\t}\n\t};\n\n\tpublic static void main(String args[])\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\n\t\twhile(scan.hasNextInt())\n\t\t{\n\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt();\n\n\t\tPoint[] a = new Point[n];\n\n\t\tfor(int i=0;i < n;i++)\n\t\t{\n\t\t\ta[i] = new Point();\n\t\t\ta[i].x = scan.nextInt();\n\t\t\ta[i].y = scan.nextInt();\n\t\t}\n\n\t\tArrays.sort(a, cmp);\n\n\t\tint rtn = 0;\n\n\t\tArrayList<Double> ans = new ArrayList<Double>();\n\n\t\tfor(int i=0;i < n;i++)\n\t\t{\n\t\t\t//Left\n\t\t\tdouble lb = a[i].x - (a[i].y / 2.0) - k;\n\t\t\tdouble pos = lb + (k/2.0);\n\t\t\tboolean good = true;\n\n\t\t\tfor(int j=0;j < ans.size();j++)\n\t\t\t\tif(Math.abs(ans.get(j) - pos) < 0.0000001)\n\t\t\t\t\tgood = false;\n\n\n\t\t\tif(good && (i == 0 || a[i-1].x + (a[i-1].y / 2.0) <= lb))\n\t\t\t{\n\t\t\t\trtn++;\n\t\t\t\tans.add(pos);\n\t\t\t}\n\n\t\t\tdouble rb = a[i].x + (a[i].y / 2.0) + k;\n\t\t\tpos = rb - (k/2.0);\n\t\t\tgood = true;\n\n\t\t\tfor(int j=0;j < ans.size();j++)\n\t\t\t\tif(Math.abs(ans.get(j) - pos) < 0.0000001)\n\t\t\t\t\tgood = false;\n\n\t\t\tif(good && (i == n-1 || a[i+1].x - (a[i+1].y / 2.0) >= rb))\n\t\t\t{\n\t\t\t\trtn++;\n\t\t\t\tans.add(pos);\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(rtn);\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.text.*;\nimport java.util.*;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint t = scan.nextInt();\n\t\tList<Double> coords = new ArrayList<Double>();\n\t\twhile (n-- > 0) {\n\t\t\tdouble x = scan.nextDouble();\n\t\t\tdouble a = scan.nextDouble() / 2;\n\t\t\tcoords.add(x - a);\n\t\t\tcoords.add(x + a);\n\t\t}\n\t\tCollections.sort(coords);\n\t\tint count = 2;\n\t\tChoiceFormat f = new ChoiceFormat(\"-1#0|0#1|0<2\");\n\t\tfor (int i = 1; i < coords.size()-2; i+=2) {\n\t\t\tcount += new Integer(f.format(coords.get(i+1)-coords.get(i)-t));\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.awt.geom.Point2D;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int t = in.nextInt() * 2;\n        Point[] A = new Point[n];\n        for (int i = 0; i < n; i++) {\n            int center = in.nextInt() * 2;\n            int side = in.nextInt();\n            A[i] = new Point(center - side, center + side);\n        }\n        Arrays.sort(A, new Comparator<Point>() {\n            public int compare(Point x, Point y) {\n                return x.x - y.x;\n            }\n        });\n        int ans = 2;\n        for (int i = 1; i < n; i++) {\n            if (A[i].x - A[i - 1].y > t)\n                ans += 2;\n            else if (A[i].x - A[i - 1].y == t)\n                ans++;\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class main {\n    \n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int houses = sc.nextInt();\n        int size = sc.nextInt();\n        hizzy[] array = new hizzy[houses];\n        long total =2;\n        for(int a=0;a<houses;a++)array[a]=new hizzy(sc.nextInt(),sc.nextInt());\n        Arrays.sort(array);\n        for(int a=0;a<houses-1;a++){\n            double L = array[a].loc+array[a].size/2;\n            double R = array[a+1].loc-array[a+1].size/2;\n            if(R-L>size)total+=2;\n            else if((R-L)==size)total++;\n        }\n        System.out.println(total);\n    }   \n\n}\nclass hizzy implements Comparable{\n    double loc;\n    double size;\n    hizzy(double l, double s){\n        this.loc=l;\n        this.size=s;\n    }\n    \n    public int compareTo(Object o) {\n        hizzy other = (hizzy) o;\n        return (int) (this.loc-other.loc);\n    }\n    \n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Village {\n\t\n\tprivate class House implements Comparable<House> {\n\t\tDouble Coordinate;\n\t\tDouble Sidelength;\n\n\t\tprivate House(double coordinate, double sidelength) {\n\t\t\tCoordinate = coordinate;\n\t\t\tSidelength = sidelength;\n\t\t}\n\n\t\tpublic int compareTo(House o) {\n\t\t\treturn Coordinate.compareTo(o.Coordinate);\n\t\t}\n\t}\n\n\tprivate void solve() {\n\t\tScanner in = new Scanner(System.in);\n\t\tin.next();\n\t\tdouble requireside = in.nextDouble();\n\t\tArrayList<House> coordinate = new ArrayList<House>();\n\t\twhile (in.hasNext()) {\n\t\t\tdouble coo = in.nextDouble();\n\t\t\tdouble side = in.nextDouble();\n\t\t\tcoordinate.add(new House(coo, side));\n\t\t}\n\t\tCollections.sort(coordinate);\n\t\tArrayList<Double> edges = new ArrayList<Double>();\n\t\tint count = 2;\n\t\tfor (int i = 0; i < coordinate.size(); i++) {\n\t\t\tedges.add(coordinate.get(i).Coordinate\n\t\t\t\t\t- (double) coordinate.get(i).Sidelength / (double) 2);\n\t\t\tedges.add(coordinate.get(i).Coordinate\n\t\t\t\t\t+ (double) coordinate.get(i).Sidelength / (double) 2);\n\t\t}\n\t\tArrayList<Double> difference = new ArrayList<Double>();\n\t\tfor (int i = 1; i < edges.size() - 1; i++) {\n\t\t\tdifference.add(Math.abs(edges.get(i) - edges.get(i + 1)));\n\t\t}\n\t\tfor (int i = 0; i < difference.size(); i += 2) {\n\t\t\tif (difference.get(i) == requireside)\n\t\t\t\tcount++;\n\t\t\telse if (difference.get(i) > requireside)\n\t\t\t\tcount += 2;\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tVillage v = new Village();\n\t\tv.solve();\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class A\n{\n   public static void main(String[] args)\n   {\n      new A(new Scanner(System.in));\n   }\n\n   public A(Scanner in)\n   {\n      int n = in.nextInt();\n      int t = in.nextInt();\n      int tt = 2*t;\n\n      rect[] rs = new rect[n];\n      for (int i=0; i<n; i++)\n         rs[i] = new rect(in.nextInt(), in.nextInt());\n      \n      Arrays.sort(rs);\n\n      int res = 2;\n      for (int i=1; i<n; i++)\n      {\n         rect a = rs[i-1];\n         rect b = rs[i];\n         int d = b.p-a.p;\n         int dd = a.t+b.t;\n         int tv = 2*d-dd;\n         if (tt == tv)\n            res++;\n         if (tv > tt)\n            res+=2;\n      }\n      System.out.printf(\"%d%n\", res);\n   }\n}\n\nclass rect implements Comparable<rect>\n{\n   int p;\n   int t;\n\n   public rect(int pp, int tt)\n   {\n      p = pp;\n      t = tt;\n   }\n\n   public int compareTo(rect rhs)\n   {\n      return p-rhs.p;\n   }\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n\n    class Home implements Comparable<Home> {\n        @Override\n        public int compareTo(Home arg0) {\n            return st - arg0.st;\n        }\n\n        int st, end;\n        \n    }\n    \n    public void solve() throws IOException {\n        int n = nextInt(), t = nextInt() * 2;\n        Home[] h = new Home[n];\n        for(int i = 0; i < n; ++i) {\n            int x = nextInt() * 2, a = nextInt() * 2;\n            h[i] = new Home();\n            h[i].st = x - a / 2;\n            h[i].end = x + a / 2;           \n        }             \n        Arrays.sort(h);\n        int ans = 2;\n        for(int i = 0; i + 1 < n; ++i) {\n            int delta = h[i + 1].st - h[i].end;\n            if (delta == t)\n                ans++;\n            if (delta > t)\n                ans += 2;\n        }\n        pw.println(ans);\n    }\n    \n    static final String filename = \"A\";\n    static final boolean fromConsole = true;\n\n    public void run() {\n        try {\n            if (!fromConsole) {\n                in = new BufferedReader(new FileReader(filename + \".in\"));\n                pw = new PrintWriter(filename + \".out\");\n            } else {\n                in = new BufferedReader(new InputStreamReader(System.in));\n                pw = new PrintWriter(System.out);\n            }\n            st = new StringTokenizer(\"\");\n            long st = System.currentTimeMillis();\n            solve();            \n            //pw.printf(\"\\nWorking time: %d ms\\n\", System.currentTimeMillis() - st);            \n            pw.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(-1);\n        } \n    }\n    \n    private StringTokenizer st;\n    private BufferedReader in;\n    private PrintWriter pw; \n    \n    boolean hasNext() throws IOException {\n        while (!st.hasMoreTokens()) {\n            String line = in.readLine();\n            if (line == null) {\n                return false;\n            }\n            st = new StringTokenizer(line);\n        }\n        return st.hasMoreTokens();\n    }\n    \n    String next() throws IOException {\n        return hasNext() ? st.nextToken() : null;\n    }\n    \n    int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n    \n    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(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) {\n        new Thread(new Main()).start();\n    }   \n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\tScanner in = new Scanner(System.in);\n\t\n\tpublic class Houses implements Comparable<Houses>{\n\t\tdouble x;\n\t\tdouble a;\n\t\t\n\t\tpublic Houses(double xVal, double aVal){\n\t\t\tx = xVal-aVal/2;\n\t\t\ta = aVal;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Houses o) {\n\t\t\treturn (int) (x - o.x);\n\t\t}\t\n\t}\n\t\n\tpublic void solve2(ArrayList<Houses> list,int t){\n\t\tCollections.sort(list);\n\t\tint count = 2; //beginning and end\n\t\t\n\t\tfor(int f = 0; f < list.size()-1; f++){\n\n\t\t\tif(list.get(f+1).x-list.get(f).x-list.get(f).a > t){\n\t\t\t\tcount+=2;\n\t\t\t}\n\t\t\telse if(list.get(f+1).x-list.get(f).x-list.get(f).a == t){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t}\n\t\n\tpublic void solve(){\n\t\tArrayList<Houses> list = new ArrayList<Houses>();\n\t\tint n = in.nextInt();\n\t\tint t = in.nextInt();\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tlist.add(new Houses(in.nextDouble(),in.nextDouble()));\n\t\t}\n\t\t\n\t\tsolve2(list,t);\n\t}\n\t\n\tpublic static void main(String[] args){\n\t\tA p = new A();\n\t\tp.solve();\n\t}\n}\n ", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Village\n{\n\tstatic Scanner in = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) );\n\n\tpublic static void main( String[] args )\n\t{\n\t\tint n = in.nextInt(), t = 2*in.nextInt(), h[][] = new int[n][2], ans = 2;\n\t\tfor( int i = 0; i < n; i++ )\n\t\t{\n\t\t\th[i][0] = 2*in.nextInt();\n\t\t\th[i][1] = in.nextInt();\n\t\t}\n\t\tArrays.sort( h, new Comp() );\n\t\tfor( int i = 1; i < n; i++ )\n\t\t{\n\t\t\tint d = (h[i][0]-h[i][1])-(h[i-1][0]+h[i-1][1]);\n\t\t\tif( d>t ) ans += 2;\n\t\t\tif( d==t ) ans++;\n\t\t}\n\t\tSystem.out.println( ans );\n\t}\n\n\tstatic class Comp implements Comparator<int[]>\n\t{\n\t\tpublic int compare( int[] a, int[] b ) { return a[0]-b[0]; }\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew A().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\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\tclass House {\n\t\tint x, t;\n\n\t\tpublic House(int x, int t) {\n\t\t\tthis.x = x;\n\t\t\tthis.t = t;\n\t\t}\n\n\t}\n\n\tvoid solve() {\n\t\tint n = nextInt();\n\t\tint t = nextInt();\n\t\tHouse[] h = new House[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\th[i] = new House(nextInt(), nextInt());\n\t\t}\n\t\tArrays.sort(h, new Comparator<House>() {\n\t\t\t@Override\n\t\t\tpublic int compare(House o1, House o2) {\n\t\t\t\treturn o1.x < o2.x ? -1 : o1.x > o2.x ? 1 : 0;\n\t\t\t}\n\t\t});\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i == 0\n\t\t\t\t\t|| (h[i].x - h[i - 1].x) * 2 - h[i].t - h[i - 1].t >= 2 * t) {\n\t\t\t\t++ans;\n\t\t\t}\n\t\t\tif (i == n - 1\n\t\t\t\t\t|| (h[i + 1].x - h[i].x) * 2 - h[i + 1].t - h[i].t > 2 * t) {\n\t\t\t\t++ans;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.text.ChoiceFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint t = scan.nextInt();\n\t\tList<List<Double>> coords = new ArrayList<List<Double>>();\n\t\twhile (n-- > 0) {\n\t\t\tdouble x = scan.nextDouble();\n\t\t\tdouble a = scan.nextDouble() / 2;\n\t\t\tcoords.add(Arrays.asList(x - a, x + a));\n\t\t}\n\t\tCollections.sort(coords, new Comparator<List<Double>>() {\n\t\t\t@Override\n\t\t\tpublic int compare(List<Double> o1, List<Double> o2) {\n\t\t\t\treturn o1.get(0).compareTo(o2.get(0));\n\t\t\t}\n\t\t});\n\t\tint count = 2;\n\t\tChoiceFormat f = new ChoiceFormat(\"-1#0|0#1|0<2\");\n\t\tfor (int i = 0; i < coords.size()-1; i++) {\n\t\t\tdouble l = coords.get(i+1).get(0)-coords.get(i).get(1)-t;\n\t\t\tcount += new Integer(f.format(l));\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution  implements Runnable{\n    private static BufferedReader br = null;\n    private static PrintWriter out = null;\n    private static StringTokenizer stk = null;\n    \n    public static void main(String[] args) {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n       (new Thread(new Solution())).start();\n    }\n    \n    private void loadLine() {\n        try {\n            stk = new StringTokenizer(br.readLine());\n        }\n        catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    private String nextLine() {\n        try {\n            return br.readLine();\n        }\n        catch (IOException e) {\n            e.printStackTrace();\n        }\n        return null;\n    }\n    \n    private Integer nextInt() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Integer.parseInt(stk.nextToken());\n    }\n    \n    private Long nextLong() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Long.parseLong(stk.nextToken());\n    }\n    \n    private String nextWord() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return (stk.nextToken());\n    }\n    \n    private Double nextDouble() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Double.parseDouble(stk.nextToken());\n    }\n    \n    public void run() {\n        int n = nextInt();\n        int t = nextInt();\n        \n        double[] d = new double[2*n];\n        for (int i = 0; i < n; ++i) {\n            double x = nextDouble();\n            double a = nextDouble();\n            d[2*i] = x-a/2;\n            d[2*i+1] = x+a/2;\n        }\n        \n        Arrays.sort(d);\n        int res = 2;\n        for (int i = 1; i < 2*n-1; i+=2) {\n            if (d[i+1] - d[i] >= t) {\n                ++res;\n            }\n            if (d[i+1] - d[i] > t) {\n                ++res;\n            }\n        }\n        \n        out.println(res);\n        out.flush();\n    }\n}\n\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CodeForces {\n\n\tpublic void solve() throws IOException {\n\t\tint n=nextInt();\n\t\tint t=nextInt();\n\t\tdouble larr[]=new double [n];\n\t\tdouble rarr[]=new double [n];\t\t\n\t\tfor(int i=0;i<n;i++){\n\t\t\tdouble x=nextDouble();\n\t\t\tdouble r=nextDouble();\n\t\t\tlarr[i]=x-r/2;\n\t\t\trarr[i]=x+r/2;\n\t\t}\n\t\tArrays.sort(larr);\n\t\tArrays.sort(rarr);\n\t\t\n\t\tint counter=2;\n\t\tfor(int i=1;i<n;i++){\n\t\t\tif(larr[i]-rarr[i-1]>t){\n\t\t\t\tcounter+=2;\n\t\t\t} else if(larr[i]-rarr[i-1]==t){\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t}\n\t\t\n\t\twriter.print(counter);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CodeForces().run();\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t//reader = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\ttokenizer = null;\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\t//writer = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\t\t\t// long t=new Date().getTime();\n\t\t\tsolve();\n\t\t\t// writer.println(t-new Date().getTime());\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\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}", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "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.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\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\tclass Dom implements Comparable<Dom>{\n\t\tint x, a;\n\n\t\tpublic int compareTo(Dom o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint t = nextInt() * 2;\n\t\tDom[] a = new Dom[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Dom();\n\t\t\ta[i].x = nextInt() * 2;\n\t\t\ta[i].a = nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint ans = 2;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tif (t < a[i + 1].x - a[i + 1].a - a[i].x - a[i].a) ans += 2;\n\t\t\tif (t == a[i + 1].x - a[i + 1].a - a[i].x - a[i].a) ans += 1;\n\t\t}\n\t\tout.print(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\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "15_A. Cottage Village", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringJoiner;\nimport java.util.StringTokenizer;\nimport java.util.concurrent.ThreadLocalRandom;\nimport java.util.function.Function;\n\npublic class Main {\n\n    static int T;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        T = sc.nextInt();\n\n        PrintWriter pw = new PrintWriter(System.out);\n        for (int i = 0; i < T; i++) {\n            int n = sc.nextInt();\n            int[] a = sc.nextIntArray(n);\n            int[] ans = solve(n, a);\n            StringJoiner j = new StringJoiner(\" \");\n            for (int each : ans) {\n                j.add(String.valueOf(each));\n            }\n            pw.println(j.toString());\n        }\n        pw.flush();\n    }\n\n    static int[] solve(int N, int[] A) {\n        // a/b \u304c1\u306b\u8fd1\u3044\u3082\u306e\u3092\u63a2\u3059\n        shuffle(A);\n        Arrays.sort(A);\n        int cur = A[0];\n        int time = 1;\n        double r = 0;\n        int prev = -1;\n        int a = -1;\n        int b = -1;\n        for (int i = 1; i < N; i++) {\n            if( cur == A[i] ) {\n                time++;\n\n                if( time == 2 ) {\n                    if( prev != -1 ) {\n                        double r1 = (double)prev/cur;\n                        if( r1 > r ) {\n                            r = r1;\n                            a = prev;\n                            b = cur;\n                        }\n                    }\n                    prev = cur;\n                }\n\n                if( time == 4 ) {\n                    return new int[]{cur, cur, cur, cur};\n                }\n\n            } else {\n                time = 1;\n                cur = A[i];\n            }\n        }\n\n        return new int[]{a, a, b, b};\n    }\n\n    static void shuffle(int[] a) {\n        Random r = ThreadLocalRandom.current();\n        for (int i = a.length-1; i >= 0; i--) {\n            int j = r.nextInt(i+1);\n            int t = a[i];\n            a[i] = a[j];\n            a[j] = t;\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++)\n                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++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n    }\n\n    static <A> void writeLines(A[] as, Function<A, String> f) {\n        PrintWriter pw = new PrintWriter(System.out);\n        for (A a : as) {\n            pw.println(f.apply(a));\n        }\n        pw.flush();\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 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 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", "complexity": "nlogn", "problem": "1027_C. Minimum Value Rectangle", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Sockets {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n = in.nextInt(), m = in.nextInt(), socket = in.nextInt();\n        int[] filters = new int[n];\n\n        for (int i = 0; i < n; i++ ) {\n            filters[i] = in.nextInt();\n        }\n        Arrays.sort(filters);\n\n        int result = 0, index = n - 1;\n        while ( m > socket && index >= 0) {\n            socket += filters[index] - 1;\n            result += 1;\n            index -= 1;\n        }\n\n        out.println(m > socket ? -1 : result);\n        out.close();\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A implements Runnable {\n\n\tfinal boolean LOCAL = System.getProperty(\"ONLINE_JUDGE\") == null;\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new A(), \"\", 256*1024*1024).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = 0, t2 = 0, m1 = 0, m2 = 0;\n\t\t\tif (LOCAL) {\n\t\t\t\tt1 = System.currentTimeMillis();\n\t\t\t\tm1 = Runtime.getRuntime().freeMemory();\n\t\t\t}\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tif (LOCAL) {\n\t\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\t} else {\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\ttok = new StringTokenizer(\"\");\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t\tif (LOCAL) {\n\t\t\t\tt2 = System.currentTimeMillis();\n\t\t\t\tm2 = Runtime.getRuntime().freeMemory();\n\t\t\t\tSystem.err.println(\"Time = \" + (t2 - t1) + \" ms.\");\n\t\t\t\tSystem.err.println(\"Memory = \" + ((m1 - m2) / 1024) + \" KB.\");\n\t\t\t}\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) return null;\n\t\t\ttok = new StringTokenizer(line);\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\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tstatic class Mergesort {\n\n\t\tprivate Mergesort() {}\n\n\t\tpublic static void sort(int[] a) {\n\t\t\tmergesort(a, 0, a.length - 1);\n\t\t}\n\n\t\tpublic static void sort(long[] a) {\n\t\t\tmergesort(a, 0, a.length - 1);\n\t\t}\n\n\t\tpublic static void sort(double[] a) {\n\t\t\tmergesort(a, 0, a.length - 1);\n\t\t}\n\n\t\tprivate static final int MAGIC_VALUE = 42;\n\n\t\tprivate static void mergesort(int[] a, int leftIndex, int rightIndex) {\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 mergesort(long[] a, int leftIndex, int rightIndex) {\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 mergesort(double[] a, int leftIndex, int rightIndex) {\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, int 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++] : rightArray[j++];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void merge(long[] a, int leftIndex, int middleIndex, int rightIndex) {\n\t\t\tint length1 = middleIndex - leftIndex + 1;\n\t\t\tint length2 = rightIndex - middleIndex;\n\t\t\tlong[] leftArray = new long[length1];\n\t\t\tlong[] rightArray = new long[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++] : rightArray[j++];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void merge(double[] a, int leftIndex, int middleIndex, int rightIndex) {\n\t\t\tint length1 = middleIndex - leftIndex + 1;\n\t\t\tint length2 = rightIndex - middleIndex;\n\t\t\tdouble[] leftArray = new double[length1];\n\t\t\tdouble[] rightArray = new double[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++] : 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\n\t\tprivate static void insertionSort(long[] a, int leftIndex, int rightIndex) {\n\t\t\tfor (int i = leftIndex + 1; i <= rightIndex; i++) {\n\t\t\t\tlong 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\n\t\tprivate static void insertionSort(double[] a, int leftIndex, int rightIndex) {\n\t\t\tfor (int i = leftIndex + 1; i <= rightIndex; i++) {\n\t\t\t\tdouble 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\n\t}\n\t\n\tvoid debug(Object... o) {\n\t\tif (LOCAL) {\n\t\t\tSystem.err.println(Arrays.deepToString(o));\n\t\t}\n\t}\n\t\n//------------------------------------------------------------------------------\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint m = readInt();\n\t\tint k = readInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = readInt();\n\t\t}\n\t\tMergesort.sort(a);\n\t\tfor (int need = 0; need <= n; need++) {\n\t\t\tint cnt = k;\n\t\t\tfor (int i = 0; i < need; i++) {\n\t\t\t\tcnt += a[n - i - 1] - 1;\n\t\t\t}\n\t\t\tif (cnt >= m) {\n\t\t\t\tout.println(need);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(-1);\n\t}\n\t\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\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\t//String filePath=\"input.txt\";\n\t\t//String filePath=\"D:\\\\_d\\\\learn\\\\coursera\\\\algorithms and design II\\\\data\\\\knapsack2.txt\";\n        String filePath=null;\n\t\tif(argv.length>0)filePath=argv[0];\n\t\tnew 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\treadNextLine();\n\t\tint N=NextInt(), M=NextInt(), K=NextInt();\n\t\tint [] v = new int[N];\n\t\treadNextLine();\n\t\tfor(int i=0; i<N; i++)\n\t\t{\n\t\t\t\n\t\t\tv[i]=NextInt();\n\t\t\t\n\t\t}\n\t\tArrays.sort(v);\n\t\tM-=(K-1);\n\t\tint id=N-1;\n\t\tint ret=0;\n\t\twhile(M>1&&id>=0)\n\t\t{\n\t\t\tM++;\n\t\t\tM-=v[id--];\n\t\t\tret++;\n\t\t}\n\t\tif(id<0&&M>1)ret=-1;\n\t\tSystem.out.println(ret);\n\t\tcloseInput();\t\t\t\n\t}\n\t\n\n\tpublic static void out(Object s)\n\t{\n\t\ttry\n\t\t{\n\t\t    FileWriter fstream = new FileWriter(\"output.txt\");\n\t\t\tBufferedWriter out = new BufferedWriter(fstream);\n\t\t\tout.write(s.toString());\n\t\t\tout.close();\n\t\t}catch (Exception e){\n\t\t\tSystem.err.println(\"Error: \" + e.getMessage());\n\t\t}\n\t}\n\t\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "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 A {\n    \n    static StringTokenizer st;\n    static BufferedReader in;\n    public static void main(String[] args) throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        int[]a = new int[n+1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = nextInt();\n        }\n        if (k >= m) {\n            System.out.println(0);\n            return;\n        }\n        Arrays.sort(a, 1, n+1);\n        int ans = 0;\n        for (int i = n; i >= 1; i--) {\n            ans++;\n            k--;\n            k += a[i];\n            if (k >= m) {\n                System.out.println(ans);\n                return;\n            }\n        }\n        System.out.println(-1);\n        pw.close();\n    }\n    private static int nextInt() throws IOException{\n        return Integer.parseInt(next());\n    }\n    \n    private static long nextLong() throws IOException{\n        return Long.parseLong(next());\n    }\n    \n    private static double nextDouble() throws IOException{\n        return Double.parseDouble(next());\n    }\n    \n    private static String next() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Sockets {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n    \n    String nextToken() throws Exception {\n        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());\n        return st.nextToken();\n    }\n    \n    int nextInt() throws Exception {\n        return Integer.parseInt(nextToken());\n    }\n    \n    void solve() throws Exception {\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        List<Integer> fs = new ArrayList<Integer>();\n        for (int i = 0; i < n; i++)\n            fs.add(nextInt());\n        Collections.sort(fs);\n        Collections.reverse(fs);\n        int c = k;\n        for (int i = 0; i < fs.size(); i++) {\n            if (c >= m) {\n                out.println(i);\n                return;\n            }\n            c += (fs.get(i)-1);\n        }\n        if (c>=m)\n            out.println(fs.size());\n        else\n            out.println(-1);\n    }\n    \n    void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n//            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(System.out);\n            solve();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        } finally {\n            out.close();\n        }\n    }\n    \n    public static void main(String[] args) {\n        new Sockets().run();\n    }\n\n}\n\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\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 c0der\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 n = in.nextInt();\n        int m = in.nextInt();\n        int k = in.nextInt();\n        int[] a = new int[ n ];\n        for (int i=0; i<n; i++) a[i] = in.nextInt();\n\n        if ( m <= k ) out.println( 0 );\n        else\n        {\n            m -= k - 1;\n            Arrays.sort( a );\n            int ans = 0;\n            for (int i=n-1; i>=0; i--)\n            {\n                ans++;\n                //out.println(m+\" \"+a[i]);\n                m -= a[ i ];\n                if ( m <= 0 ) break;\n                m++;\n            }\n            if ( m > 0 ) out.println( -1 );\n            else out.println( ans );\n        }\n    }\n}\n\nclass InputReader {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public InputReader(InputStream in)\n    {\n        br = new BufferedReader(new InputStreamReader(in));\n        st = null;\n    }\n\n    public String next()\n    {\n        while (st==null || !st.hasMoreTokens())\n        {\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    {\n        return Integer.parseInt(next());\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.*;\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 TaskB();\n        solver.solve(1, in, out);\n        Exit.exit(in, out);\n    }\n}\n\nabstract class InputReader {\n    private boolean finished = false;\n\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 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 void setFinished(boolean finished) {\n        this.finished = finished;\n    }\n\n    public abstract void close();\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    }\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 void close() {\n        try {\n            stream.close();\n        } catch (IOException ignored) {\n        }\n    }\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\ninterface Solver {\n    public void solve(int testNumber, InputReader in, PrintWriter out);\n}\n\nclass TaskB implements Solver \n{\n    public void solve(int testNumber, InputReader in, PrintWriter out) \n    {\n        int n = in.readInt();\n        int m = in.readInt();\n        int k = in.readInt();\n        int[] a = new int[n];\n        for(int i=0;i<n;i++) a[i] = in.readInt();\n        Arrays.sort(a);\n        if(k>=m)\n        {\n            out.println(0);\n        }\n        else\n        {\n            for(int i=n-1;i>=0;i--)\n            {\n                k += (a[i]-1);\n                if(k>=m) \n                {\n                    out.println(n-i);\n                    return;\n                }\n            }\n            if(k<m) out.println(-1);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\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(), s = 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\tArrays.sort(a);\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tif (s>=k)\n\t\t\t{\n\t\t\t\tout.println(i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\ts += -a[i];\n\t\t\ts--;\n\t\t}\n\t\tif (s<k)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(n);\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\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 A().run();\n\t}\n\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "//package Round_159;\n\nimport java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class a {\n\n\tvoid solve() throws Exception {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i<n; i++){\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint sum = 0;\n\t\tif (k >= m){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tsum = a[n-1] + k - 1;\n\t\tint j = 1;\n\t\tfor (int i = n-2; i >=0 && sum < m; i--, j++){\n\t\t\tsum += a[i] - 1;\n\t\t}\n\t\tif (sum < m){\n\t\t\tout.println(-1);\n\t\t}else{\n\t\t\tout.println(j);\n\t\t}\n\t}\n\n\tFastScanner in;\n\tPrintWriter out;\n\n\tString input = \"\";\n\tString output = \"\";\n\n\tvoid run() {\n\t\ttry {\n\t\t\tif (input.length() > 0) {\n\t\t\t\tin = new FastScanner(new BufferedReader(new FileReader(input)));\n\t\t\t} else\n\t\t\t\tin = new FastScanner(new BufferedReader(new InputStreamReader(\n\t\t\t\t\t\tSystem.in)));\n\t\t\tif (output.length() > 0)\n\t\t\t\tout = new PrintWriter(new FileWriter(output));\n\t\t\telse\n\t\t\t\tout = new PrintWriter(System.out);\n\n\t\t\tsolve();\n\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t} catch (Exception ex) {\n\t\t\tex.printStackTrace();\n\t\t\tout.flush();\n\t\t\tout.close();\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 a().run();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader bf;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(BufferedReader bf) {\n\t\t\tthis.bf = bf;\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(bf.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 String nextLine() throws IOException {\n\t\t\treturn bf.readLine();\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\t}\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author coderbd\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        int m, n, k;\n        n = in.readInt();\n        m = in.readInt();\n        k = in.readInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = in.readInt() - 1;\n        Arrays.sort(a);\n        int ans = -1;\n        if (k >= m)\n            ans = 0;\n        else for (int i = 0; i < n; i++) {\n            k += a[n-i-1];\n            if (k >= m) {\n                ans = i + 1;\n                break;\n            }\n        }\n        System.out.println(ans);\n    }\n}\n\nclass InputReader {\n    private boolean finished = false;\n\n    private InputStream stream;\n    private byte[] buf = new byte[1024];\n    private int curChar;\n    private int numChars;\n\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            }\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            }\n            catch (IOException e) {\n                return -1;\n            }\n            if (numChars <= 0)\n                return -1;\n        }\n        return buf[curChar];\n    }\n\n    public int readInt() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        int res = 0;\n        do {\n            if (c < '0' || c > '9')\n                throw new InputMismatchException();\n            res *= 10;\n            res += c - '0';\n            c = read();\n        } while (!isSpaceChar(c));\n        return res * sgn;\n    }\n\n    public long readLong() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        long res = 0L;\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    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        }\n        catch (NumberFormatException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    public char readCharacter() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        return (char) c;\n    }\n\n    public double readDouble() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        double res = 0;\n        while (!isSpaceChar(c) && c != '.') {\n            if (c == 'e' || c == 'E')\n                return res * Math.pow(10, readInt());\n            if (c < '0' || c > '9')\n                throw new InputMismatchException();\n            res *= 10;\n            res += c - '0';\n            c = read();\n        }\n        if (c == '.') {\n            c = read();\n            double m = 1;\n            while (!isSpaceChar(c)) {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, readInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                m *= 10;\n                res += (c - '0') * m;\n                c = read();\n            }\n        }\n        return res * sgn;\n    }\n\n    public boolean isExhausted() {\n        int value;\n        while (isSpaceChar(value = peek()) && value != -1)\n            read();\n        return value == -1;\n    }\n\n    public String next() {\n        return readString();\n    }\n}\n\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 printLine(char[] array) {\n        writer.print(array);\n    }\n\n    public void printFormat(String format, Object...objects) {\n        writer.printf(format, objects);\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    public void flush() {\n        writer.flush();\n    }\n}\n\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\n\nimport static java.lang.Math.*;\n\npublic class Start {\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 Start().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 = 50;\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<LOL> {\n        int x;\n        int y;\n        int num;\n\n        public LOL(int x, int y,int num) {\n            this.x = x;\n            this.y = y;\n            this.num = num;\n        }\n\n        @Override\n        public int compareTo(LOL o) {\n            return x - o.x; // ---->\n            // return o.x - x; // <----\n            // return o.y-y;\n        }\n\n    }\n    \n    \n    \n    public void solve() throws IOException {\n    \n        int n = readInt();\n        int m = readInt();\n        int k = readInt();\n        \n        int [] a = new int [n];\n        for (int i = 0; i < n; i++){\n            a[i] = readInt();\n        }\n        mergeSort(a);\n        \n        if (k>=m){\n            out.print(0);\n             return;\n        }\n        \n        int ans = 0;\n        k--;\n        for (int i = n-1; i >=0; i--){\n            ans += a[i];\n            if (ans +  k >= m){\n                out.print(n-i);\n                return;\n            }\n            else {\n                k--;\n            }\n\n        }\n        out.print(-1);\n        \n        \n    }\n    \n    \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    \n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        \n        int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) a[i] = in.nextInt();\n        Arrays.sort(a);\n        int ans = 0, r = k, p = n-1;\n        while (r < m && p >= 0) {\n            r = r - 1 + a[p];\n            p--;\n            ans++;\n        }\n        if (r < m) out.println(\"-1\");\n        else out.println(ans);\n        \n        out.flush();\n    }\n    \n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\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        int k = s.nextInt();\n        \n        int a[] = new int [n];\n        for (int i = 0; i < a.length; i++) {\n            a[i] = s.nextInt();\n        }\n        int ans = 0;\n        \n        while(k < m){\n            k--;\n            int max = -1;\n            int ix = -1;\n            for (int i = 0; i < a.length; i++) {\n                if(a[i] > max){\n                    max = a[i];\n                    ix = i;\n                }\n            }\n            if(ix == -1){\n                System.out.println(\"-1\");\n                return ;\n            }\n            k += a[ix];\n            a[ix] = -1;\n            ans++;\n        }\n        System.out.println(ans);\n    }\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "//package round159;\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 A {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), K = ni();\n\t\tint[] a = na(n);\n\t\ta = radixSort(a);\n\t\t\n\t\tif(K >= m){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint p = 1;\n\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\tK += a[i]-1;\n\t\t\tif(K >= m){\n\t\t\t\tout.println(p);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tp++;\n\t\t}\n\t\tout.println(-1);\n\t}\n\t\n\tpublic static int[] radixSort(int[] f)\n\t{\n\t\tint[] to = new int[f.length];\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n\t\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n\t\t\tint[] d = f; f = to;to = d;\n\t\t}\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor(int i = 0;i < f.length;i++)b[1+(f[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 < f.length;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\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 A().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", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "//package A;\n\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n    public static void main(String args[]) throws IOException {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int m = 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        Arrays.sort(a);\n        \n        int res = 0, p = n - 1;\n        while (k < m && p >= 0) {\n            ++res;\n            k += a[p] - 1;\n            --p;\n        }\n        if (k >= m)\n            System.out.println(res);\n        else\n            System.out.println(\"-1\");\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main2 {\n\t\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        int k = input.nextInt();\n        int[] num = new int[n];\n        for(int i = 0 ; i < n ; i++){\n        \tnum[i] = input.nextInt();\n        }\n        \n        System.out.println(str(n,m,k,num));\n    }\n\n\tstatic int str(int n,int m,int k,int[] num){\n\t\tArrays.sort(num);\n\t\tint total = k;\n\t\tint count = 0;\n\t\twhile(k < m){\n\t\t\tif(count == num.length)return -1;\n\t\t\tk += num[num.length-count-1]-1;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\t\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] in = br.readLine().split(\" \");\n\t\t\n\t\tint n=Integer.parseInt(in[0]),m=Integer.parseInt(in[1]),k=Integer.parseInt(in[2]);\n\t\t\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint[] caps = new int[n];\n\t\tfor (int i = 0; i < caps.length; i++) {\n\t\t\tcaps[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tArrays.sort(caps);\n\t\t\n\t\tint curSockets=k, neededLines=0;\n\t\tint i = n-1;\n\t\twhile(curSockets<m && i>=0){\n\t\t\tcurSockets+=caps[i]-1;\n\t\t\tneededLines++;\n\t\t\ti--;\n\t\t}\n\t\tif(curSockets>=m)\n\t\t\tSystem.out.println(neededLines);\n\t\telse\n\t\t\tSystem.out.println(-1);\n\t}\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class Main {\n\n  public static void main(String[] args) {\n    Scanner cin=new Scanner(new BufferedInputStream(System.in));\n    \n    int n=cin.nextInt(),\n        m=cin.nextInt(),\n        k=cin.nextInt();\n    int[] a=new int[51];\n    \n    for (int i=0;i<n;i++) {\n      a[i]=-cin.nextInt();\n    }\n    Arrays.sort(a);\n    \n    if (m<=k) {\n        System.out.println(0);\n        return;\n    }\n    for (int i=0;i<Math.min(k,n);i++) {\n      m+=a[i];\n      if (m-(k-1-i)<=0) {\n        System.out.println(i+1);\n        return;\n      }\n    }\n    for (int i=k;i<n;i++) {\n      m+=a[i]+1;\n      if (m<=0) {\n        System.out.println(i+1);\n        return;\n      }\n    }\n    System.out.println(-1);\n    \n    cin.close();\n  }\n\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class CFTest6 {\n\n\tstatic BufferedReader br;\n\n\tpublic static void main(String[] args) {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\n\t\ttry {\n\n\t\t\tint[] a1 = readIntArr();\n\t\t\tint[] a2 = readIntArr();\n\t\t\tbr.close();\n\t\t\tint f = a1[0];\n\t\t\tint d = a1[1];\n\t\t\tint s = a1[2];\n\t\t\tArrays.sort(a2);\n\n\t\t\tif (d <= s)\n\t\t\t\tSystem.out.println(0);\n\n\t\t\telse {\n\t\t\t\tint cur = d - s + 1;\n\n\t\t\t\t\n\t\t\t\tint num=0;\n\t\t\t\tfor(int i=0;i<f;i++){\n\t\t\t\t\tnum++;\n\t\t\t\t\tcur-=a2[f-i-1];\n\t\t\t\t\tif(cur<=0)break;\n\t\t\t\t\tcur++;\n\t\t\t\t}\n\t\t\t\tif (cur > 0)\n\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\telse{\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\tSystem.out.println(num);\n\t\t\t\t}\n\t\t\t}\n\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t}\n\n\tstatic public String readLine() throws IOException {\n\t\treturn br.readLine();\n\n\t}\n\n\tstatic public String readString() throws IOException {\n\t\treturn br.readLine();\n\n\t}\n\n\tstatic public long readlong() throws IOException {\n\t\treturn Long.parseLong(br.readLine());\n\t}\n\n\tstatic public int readInt() throws IOException {\n\t\treturn Integer.parseInt(br.readLine());\n\t}\n\n\tstatic public int[] readIntArr() throws IOException {\n\t\tString[] str = br.readLine().split(\" \");\n\t\tint arr[] = new int[str.length];\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = Integer.parseInt(str[i]);\n\t\treturn arr;\n\t}\n\n\tstatic public double[] readDoubleArr() throws IOException {\n\t\tString[] str = br.readLine().split(\" \");\n\t\tdouble arr[] = new double[str.length];\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = Double.parseDouble(str[i]);\n\t\treturn arr;\n\t}\n\n\tstatic public long[] readLongArr() throws IOException {\n\t\tString[] str = br.readLine().split(\" \");\n\t\tlong arr[] = new long[str.length];\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = Long.parseLong(str[i]);\n\t\treturn arr;\n\t}\n\n\tstatic public double readDouble() throws IOException {\n\t\treturn Double.parseDouble(br.readLine());\n\t}\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\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 */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n=in.nextInt();\n        int m=in.nextInt();\n        int k=in.nextInt();\n        Integer []cap=new Integer[n];\n        for(int i=0;i<n;i++) {\n            cap[i]=in.nextInt();\n        }\n        Arrays.sort(cap, Collections.reverseOrder());\n        int count=0;\n\n        while(k<m && count<cap.length) {\n            k+=(cap[count]-1);\n            ++count;\n        }\n        if(k>=m) {\n            out.println(count);\n        } else {\n            out.println(-1);\n        }\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", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Main {\n       \n    static InputReader in;\n    \n    public static void main(String[] args) throws IOException{        \n        \n        File file = new File(\"input.txt\");\n        if(file.exists())in = new InputReader( new FileInputStream(file) );\n        else in = new InputReader( System.in );\n        \n        int n=in.nextInt(), m=in.nextInt(), k=in.nextInt();\n        int a[]=new int[n];\n        for( int i=0; i<n; i++ ) a[i]=in.nextInt();\n        Arrays.sort( a );\n        int i=n-1, ans=0;\n        while( k<m && i>=0 ) {\n            k+=a[i]-1;\n            i--;\n            ans++;\n        }\n        if( m<=k ) System.out.println( ans );\n        else System.out.println(\"-1\");\n    } \n    \n    // IO utilities:\n    \n    static void out(Object ...o){ \n        System.out.println(Arrays.deepToString(o)); \n    } \n    \n    static class InputReader {\n        \n        private BufferedInputStream inp;\n\tprivate int offset;\n\tprivate final int size=5120000;\n        private byte buff[];\n \n        InputReader( InputStream in ) throws IOException {\n\t\tinp = new BufferedInputStream( in );\n                buff=new byte[size];\n                offset=0;\n\t\tinp.read( buff, 0, size );\n\t}\n \n\tint nextInt() throws IOException {\n            \n            int parsedInt=0;\n            int i=offset;\n            if( buff[i]==0 ) throw new IOException(); //EOF\n            // skip any non digits\n            while ( i<size && ( buff[i]<'0' || buff[i]>'9' ) ) i++;\n            // read digits and parse number\n            while( i<size && buff[i]>='0' && buff[i]<='9') {\n                parsedInt*=10;\n                parsedInt+=buff[i]-'0';\n                i++;\n            }\n            // check if we reached end of buffer\n            if ( i==size ) {\n                // copy leftovers to buffer start\n\t\tint j = 0;\n\t\tfor ( ; offset<buff.length; j++, offset++ ) \n                        buff[j] = buff[offset];\n\t\t// and now fill the buffer\n\t\tinp.read( buff, j, size - j );\n\t\t// and attempt to parse int again\n\t\toffset = 0;\n\t\tparsedInt = nextInt();\n            } else offset=i;\n            return parsedInt;\n\t}\n        \n        long nextLong() throws IOException{\n            \n            long parsedLong=0;\n            int i=offset;\n            if( buff[i]==0 ) throw new IOException(); //EOF\n            // skip any non digits\n            while( i<size && ( buff[i]<'0' || buff[i]>'9' ) ) i++;\n            // read digits and parse number\n            while( i<size && buff[i]>='0' && buff[i]<='9') {\n                parsedLong*=10L;\n                parsedLong+=buff[i]-'0';\n                i++;\n            }\n            // check if we reached end of buffer\n            if ( i==size ) {\n                // copy leftovers to buffer start\n\t\tint j = 0;\n\t\tfor ( ; offset<buff.length; j++, offset++ ) \n                        buff[j] = buff[offset];\n\t\t// and now fill the buffer\n\t\tinp.read( buff, j, size - j );\n\t\t// and attempt to parse int again\n\t\toffset = 0;\n\t\tparsedLong = nextLong();\n            } else offset=i;\n            return parsedLong;\n        }\n        \n        String next() throws IOException {\n            \n            StringBuilder token=new StringBuilder();\n            int i=offset;\n            if( buff[i]==0 ) throw new IOException(); //EOF\n            // skip any non chars\n            while( i<size && ( buff[i]=='\\n' || buff[i]==' ' || buff[i]=='\\r' ||\n                    buff[i]=='\\t' ) ) i++;\n            // read chars\n            while( i<size && buff[i]!='\\n' && buff[i]!=' ' && buff[i]!='\\r' &&\n                    buff[i]!='\\t' && buff[i]!=0 ) {\n                token.append( (char)buff[i] );\n                i++;\n            }\n            // check if we reached end of buffer\n            if ( i==size ) {\n                // copy leftovers to buffer start\n\t\tint j = 0;\n\t\tfor ( ; offset<buff.length; j++, offset++ ) \n                        buff[j] = buff[offset];\n\t\t// and now fill the buffer\n\t\tinp.read( buff, j, size - j );\n\t\t// and attempt to parse int again\n\t\toffset = 0;\n\t\treturn next();\n            } else offset=i;\n            return token.toString();\n        }\n        \n        String nextLine() throws IOException {\n            \n            StringBuilder line=new StringBuilder();\n            int i=offset;\n            if( buff[i]==0 ) throw new IOException(); //EOF\n            // read chars\n            while( i<size && buff[i]!='\\n' && buff[i]!=0 ) {\n                line.append( (char)buff[i] );\n                i++;\n            }\n            if( i<size && buff[i]=='\\n' ) i++;\n            // check if we reached end of buffer\n            if ( i==size ) {\n                // copy leftovers to buffer start\n\t\tint j = 0;\n\t\tfor ( ; offset<buff.length; j++, offset++ ) \n                        buff[j] = buff[offset];\n\t\t// and now fill the buffer\n\t\tinp.read( buff, j, size - j );\n\t\t// and attempt to parse int again\n\t\toffset = 0;\n\t\treturn nextLine();\n            } else offset=i;\n            line.deleteCharAt( line.length()-1 );\n            return line.toString();\n        }\n        \n    }\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author oleksiys\n */\npublic class A {\n    public static void main(String [] args){\n        try(Scanner s = new Scanner(System.in)){\n            final int n = s.nextInt();\n            final int m = s.nextInt();\n            final int k = s.nextInt();\n            final int [] a = new int [n];\n            for (int i = 0; i < a.length; ++i){\n                a[i] = s.nextInt();\n            }\n            Arrays.sort(a);\n            int i = a.length - 1;\n            int available = k;\n            int filters = 0;\n            while (available < m && i >= 0){\n                available -= 1;\n                available += a[i];\n                filters++;\n                i--;\n            }\n            if (available < m){\n                System.out.println(-1);\n            }else{\n                System.out.println(filters);\n            }\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A {\n\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint m = readInt();\n\t\tint k = readInt();\n\t\tint[] a = readArr(n);\n\t\tArrays.sort(a);\n\t\tfor(int i = 0; i <= n; i++){\n\t\t\tint curR = k;\n\t\t\tfor(int j = n-1; j >= n-i; j--){\n\t\t\t\tcurR += a[j];\n\t\t\t}\n\t\t\tcurR -= i;\n\t\t\tif(curR >= m){\n\t\t\t\tout.println(i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(-1);\n\t}\n\n\tvoid init() throws FileNotFoundException {\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\n\tint[] readArr(int n) throws IOException {\n\t\tint[] res = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = readInt();\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong[] readArrL(int n) throws IOException {\n\t\tlong[] res = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = readLong();\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "//package codeforces.contests.cf159;\n\nimport java.io.*;\nimport java.util.Arrays;\n\npublic class ProblemA {\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    void solve() throws IOException {\n        int[] tt = readInts();\n        int n = tt[0];\n        int m = tt[1];\n        int k = tt[2];\n        int[] a = readInts();\n        Arrays.sort(a);\n        for(int i = 0, j = a.length - 1; i < j; i++, j--) {\n            int t = a[i];\n            a[i] = a[j];\n            a[j] = t;\n        }\n        int ix = 0;\n        while(k < m && ix < n) {\n            k += a[ix++] - 1;\n        }\n        if(k < m) {\n            writer.println(-1);\n        }\n        else {\n            writer.println(ix);\n        }\n        writer.flush();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new ProblemA().solve();\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\n\npublic class A {\n\n\tfinal int MOD = (int)1e9 + 7;\n\tfinal double eps = 1e-12;\n\tfinal int INF = (int)1e9;\n\t\n\tpublic A () {\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\t\n\t\tInteger [] S = sc.nextInts();\n\t\tsort(S, reverseOrder()); \n\t\t\n\t\tint cnt = K, res;\n\t\tfor (res = 0; res < N && cnt < M; ++res)\n\t\t\tcnt += S[res] - 1;\n\t\t\n\t\texit(cnt < M ? -1 : res);\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic MyScanner sc;\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next().toCharArray();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i = 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\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print (Object o, Object... a) {\n\t\tpw.println(build(o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit () {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tvoid NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build(Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tfor (Object o : a)\n\t\t\tappend(b, o);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, Array.get(o, i));\n\t\t} else if (o instanceof Iterable<?>) {\n\t\t\tfor (Object p : (Iterable<?>)o)\n\t\t\t\tappend(b, p);\n\t\t} else\n\t\t\tb.append(\" \").append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) {\n\t\tsc = new MyScanner ();\n\t\tnew A();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "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.Collection;\nimport java.util.Collections;\nimport java.util.List;\n\n\npublic class Round159ProblemA {\n\n\tpublic static void main(String[] args) {\n\t\tReader r = new Reader();\n\t\tint filters = r.nextInt();\n\t\tint devices = r.nextInt();\n\t\tint sockets = r.nextInt();\n\t\t\n\t\tList<Integer> filtery = new ArrayList<>();\n\t\tfor (int i = 0; i < filters; i++) {\n\t\t\tfiltery.add(r.nextInt()-1);\n\t\t}\n\t\t\n\t\t//System.out.println(filtery);\n\t\t\n\t\tif(devices <= sockets){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}else{\n\t\t\tCollections.shuffle(filtery);\n\t\t\tCollections.sort(filtery);\n\t\t\tdevices -= sockets;\n\t\t\tint act = filtery.size()-1;\n\t\t\tint result = 0;\n\t\t\twhile(devices > 0){\n\t\t\t\t//System.out.println(devices + \" \" + act);\n\t\t\t\tif(act < 0){\n\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tdevices -= filtery.get(act);\n\t\t\t\tact--;\n\t\t\t\tresult++;\n\t\t\t}\n\t\t\tSystem.out.println(result);\n\t\t}\n\t}\n\n\tstatic class Reader {\n\t\tStreamTokenizer in;\n\n\t\tpublic Reader() {\n\t\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(\n\t\t\t\t\tSystem.in)));\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\ttry {\n\t\t\t\tin.nextToken();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn (int) in.nval;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\ttry {\n\t\t\t\tin.nextToken();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn (long) in.nval;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\ttry {\n\t\t\t\tin.nextToken();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn in.sval;\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\n\npublic class Main\n{\n    public static void main (String[] args) throws java.lang.Exception\n    {\n        Scanner sc = new Scanner(System.in);\n        int numSupply = sc.nextInt();\n        int dev = sc.nextInt();\n        int socket = sc.nextInt();\n        int[] sockInSu = new int[numSupply];\n        for (int i = 0; i< sockInSu.length; i++) {\n            sockInSu[i] = sc.nextInt();\n        }\n        \n        Arrays.sort(sockInSu);\n        \n        if (socket >= dev) {\n            System.out.println(0);\n        }else {\n            int count = 0;\n            for (int i = sockInSu.length-1; i >= 0; i--) {\n                socket+= sockInSu[i]-1;\n                count++;\n                if (socket >= dev) {\n                    System.out.println(count);\n                    break;\n                }\n            }\n            if (socket < dev)\n                System.out.println(-1);\n        }\n    }\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n   public static void main(String[] args) throws IOException\n   {\n      new Main().run();\n   }\n\n   StreamTokenizer in;\n   PrintWriter out;\n\n   int nextInt() throws IOException\n   {\n      in.nextToken();\n      return (int)in.nval;\n   }\n   long nextLong() throws IOException\n   {\n      in.nextToken();\n      return (long)in.nval;\n   }\n   void run() throws IOException\n   {\n     // in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));\n     // out = new PrintWriter(new FileWriter(\"output.txt\"));\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   void solve() throws IOException\n   {\n      int N=nextInt();\n      int m=nextInt();\n      int k=nextInt();\n     //  System.out.println(\"k \"+k);\n      ArrayList<Integer> ts= new ArrayList<Integer>();\n       for (int i = 0; i < N; i++) {\n           ts.add(nextInt());\n       }\n       int count=0,pos=0;\n       Collections.sort(ts);\n       int jj=ts.size()-1;\n      while(m>k){\n         \n      if((jj<0)||(k==0))\n      {pos=1;break;}\n      else{\n        //  System.out.println(k);\n      k+=ts.get(jj) -1;\n      jj--;\n      count++;\n      }\n      \n      }\n      if(pos==0)\n           out.println(count);\n      else\n           out.println(\"-1\");\n      \n   }\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\t\n\tstatic class Scanner{\n\t\tBufferedReader br=null;\n\t\tStringTokenizer tk=null;\n\t\tpublic Scanner(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tpublic String next() throws IOException{\n\t\t\twhile(tk==null || !tk.hasMoreTokens())\n\t\t\t\ttk=new StringTokenizer(br.readLine());\n\t\t\treturn tk.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws NumberFormatException, IOException{\n\t\t\treturn Integer.valueOf(next());\n\t\t}\n\t\tpublic double nextDouble() throws NumberFormatException, IOException{\n\t\t\treturn Double.valueOf(next());\n\t\t}\n\t}\n\t\n\tpublic static void main(String args[]) throws NumberFormatException, IOException{\n\t\tScanner sc=new Scanner();\n\t\tint N=sc.nextInt();\n\t\tint M=sc.nextInt();\n\t\tint K=sc.nextInt();\n\t\tint[] array=new int[N];\n\t\tfor(int i=0;i<N;i++)\n\t\t\tarray[i]=sc.nextInt();\n\t\tArrays.sort(array);\n\t\tint val=K;\n\t\tint index=N - 1;\n\t\twhile(index>=0 && val<M){\n\t\t\tval--;\n\t\t\tval+=array[index];\n\t\t\tindex--;\n\t\t}\n\t\tif (val<M)\n\t\t\tSystem.out.println(\"-1\");\n\t\telse\n\t\t\tSystem.out.println((N - 1) - index);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint[] fs = IOUtils.readIntArray(in, n);\n\t\tArrays.sort(fs);\n\t\tint ptr = fs.length - 1;\n\t\tint res = 0;\n\t\twhile (ptr >= 0 && k < m) {\n\t\t\tk += fs[ptr--] - 1;\n\t\t\tres++;\n\t\t}\n\t\tif (k < m) out.println(-1);\n\t\telse out.println(res);\n\t}\n}\n\nclass IOUtils {\n    public static int[] readIntArray(Scanner in, int size) {\n        int[] array = new int[size];\n        for (int i = 0; i < size; i++)\n            array[i] = in.nextInt();\n        return array;\n    }\n\n    }\n\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author Natasha\n */\npublic class Main{\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int produzeni = in.nextInt();\n        int devices = in.nextInt();\n        int stekovi = in.nextInt();\n        int [] filter = new int[produzeni];\n        for(int i = 0; i<produzeni; i++){\n            filter[i] = in.nextInt();\n        }\n        Arrays.sort(filter);\n        int filt_no = filter.length-1;\n        if(devices<=stekovi) {\n            System.out.println(\"0\");\n            return;\n        }\n        int used = 0;\n        while(devices>stekovi){\n            try{\n            stekovi+=filter[filt_no--]-1;\n            }\n            catch(Exception e){\n                System.out.println(\"-1\");\n                return;\n            }\n        }\n        \n        System.out.println(filter.length - filt_no-1);\n        \n        \n        \n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class a {\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int n = input.nextInt(), m = input.nextInt(), k = input.nextInt();\n    int[] data = new int[n];\n    for(int i = 0; i<n; i++)\n        data[i] = input.nextInt();\n    Arrays.sort(data);\n    m -= k;\n    int at = n-1;\n    int count = 0;\n    while(at>=0 && m>0)\n    {\n        count++;\n        m++;\n        m -= data[at];\n        at--;\n    }\n    if(m>0)\n        System.out.println(-1);\n    else\n        System.out.println(count);\n}\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class TaskA {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tnew TaskA().solve(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tprivate void solve(Scanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint answer = 0;\n\t\tint counter = k;\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\tArrays.sort(a);\n\t\tint[] b = Arrays.copyOf(a, a.length);\n\t\tfor (int i = 0; i < n; ++i) \n\t\t\ta[i] = b[n - i - 1];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (counter < m) {\n\t\t\t\tcounter += a[i] - 1;\n\t\t\t\t++answer;\n\t\t\t} else\n\t\t\t\tbreak;\n\t\t}\n\t\tif (counter < m)\n\t\t\tout.println(\"-1\");\n\t\telse\n\t\t\tout.println(answer);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class round159A {\n    static BufferedReader br = new BufferedReader(new InputStreamReader(\n            System.in));\n    static StringTokenizer st = new StringTokenizer(\"\");\n\n    static int nextInt() throws Exception {\n        return Integer.parseInt(next());\n    }\n\n    static String next() throws Exception {\n        while (true) {\n            if (st.hasMoreTokens()) {\n                return st.nextToken();\n            }\n            String s = br.readLine();\n            if (s == null) {\n                return null;\n            }\n            st = new StringTokenizer(s);\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        int[] supply = new int[n];\n        for (int i = 0; i < n; ++i)\n            supply[i] = nextInt();\n        if (m <= k) {\n            System.out.println(0);\n        } else {\n            int have = k;\n            Arrays.sort(supply);\n            for(int i = n - 1 ; i >= 0 ; --i){\n                have--;\n                have += supply[i];\n                if(have >= m){\n                    System.out.println(n - i);\n                    return;\n                }\n            }\n            System.out.println(-1);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemA {\n    InputReader in; PrintWriter out;\n    void solve() {\n        int n = in.nextInt();\n        int m = 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        Arrays.sort(a);\n        int d = k;\n        int cur = n - 1;\n        int ans = 0;\n        while (d < m && cur >= 0) {\n            d += a[cur] - 1;\n            cur--;\n            ans++;\n        }\n        if (d >= m)\n            out.println(ans);\n        else\n            out.println(\"-1\");\n    }\n    \n    ProblemA(){\n        boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        try {\n            if (oj) {\n                in = new InputReader(System.in);\n                out = new PrintWriter(System.out);\n            }\n            else {\n                Writer w = new FileWriter(\"output.txt\");\n                in = new InputReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(w);\n            }\n        } catch(Exception e) {\n            throw new RuntimeException(e);\n        }\n        solve();\n        out.close();\n    }\n    public static void main(String[] args){\n        new ProblemA();\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 InputReader(FileReader fr) {\n        reader = new BufferedReader(fr);\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    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}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n\tvoid solve() throws Exception {\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\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tif (k >= m) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint sum = k;\n\t\tfor (int j = n - 1; j >= 0; j--) {\n\t\t\tsum--;\n\t\t\tsum += a[j];\n\t\t\tif (sum >= m) {\n\t\t\t\tout.println((n - j));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(-1);\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\n\tstatic Throwable uncaught;\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.uncaught = 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 t = new Thread(null, new Solution(), \"\", (1 << 26));\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\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\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\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}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class A {\n    \n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int k = in.nextInt();\n        int so[]= new int[n];\n        for(int i=0;i<n;i++) so[i]=in.nextInt();\n        Arrays.sort(so);\n        if(m<=k) {\n            System.out.println(\"0\");\n            return;\n        }\n        int sum=0;\n        int socUsed=0;\n        int cont=0;\n        for(int i=n-1;i>=0;i--){\n            cont++;\n            sum+=so[i]; \n            if(sum>=m || sum+(k-1)>=m){\n                System.out.println(cont);\n                return;\n            }   \n            sum--;  \n        }   \n        System.out.println(\"-1\");\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n    void run() throws IOException {\n        int n = ni();\n        int m = ni();\n        int k = ni();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = ni() - 1;\n        Arrays.sort(a);\n        int ans = 0;\n        if (m > k) {\n            m -= k - 1;\n            for (int i = n - 1; i >= 0; i--) {\n                ans++;\n                m -= a[i];          \n                if (m < 2)\n                    break;\n\n            }\n            if (m > 1)\n                ans = -1;\n        }\n        pw.print(ans);\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 ni() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    String nl() throws IOException {\n        return br.readLine();\n    }\n\n    PrintWriter pw;\n    BufferedReader br;\n    StringTokenizer st;\n\n    public static void main(String[] args) throws IOException {\n        long timeout = System.currentTimeMillis();\n        boolean CF = System.getProperty(\"ONLINE_JUDGE\") != null;\n        PrintWriter _pw = new PrintWriter(System.out);\n        BufferedReader _br = new BufferedReader(CF ? new InputStreamReader(System.in) : new FileReader(new File(\"in.txt\")));\n        new A(_br, _pw).run();\n        if (!CF) {\n            _pw.println();\n            _pw.println(System.currentTimeMillis() - timeout);\n        }\n        _br.close();\n        _pw.close();\n    }\n\n    public A(BufferedReader _br, PrintWriter _pw) {\n        br = _br;\n        pw = _pw;\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\tint n, m, k;\n\tint[] a;\n\t\n\tvoid run()throws IOException{\n//\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\tScanner sc = new Scanner(new InputStreamReader(System.in));\n\t\tn = sc.nextInt();\n\t\tm = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\ta = new int[n];\n\t\tfor(int i=0;i<n; i++) a[i] = sc.nextInt();\n\t\tArrays.sort(a);\n\t\t\n\t\tif(m<=k){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint cnt = k;\n\t\tint ind = a.length-1;\n\t\tint ret = 0;\n\t\twhile(cnt<m && ind>=0){\n\t\t\tcnt += a[ind]-1;\n\t\t\t--ind;\n\t\t\tret++;\n\t\t\t\n\t\t}\n\t\t\n\t\tif(cnt>=m) System.out.println(ret);\n\t\telse System.out.println(-1);\n\t}\n\n\tpublic static void main(String[] args)throws IOException {\n\t\tnew A().run();\n\t}\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF159DIV2 {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = 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\tArrays.sort(a);\n\t\tfor (int i = 0; i < a.length / 2; i++) {\n\t\t\tint tmp = a[i];\n\t\t\ta[i] = a[n - i - 1];\n\t\t\ta[n - i - 1] = tmp;\n\t\t}\n\t\tint need = m;\n\t\tint have = k;\n\t\tint ans = 0;\n\t\tint it = 0;\n\t\twhile (have < need) {\n\t\t\thave += a[it++] - 1;\n\t\t\tans++;\n\t\t\tif (it >= n) break;\n\t\t}\n\t\tif (have >= need) {\n\t\t\tout.println(ans);\n\t\t} else {\n\t\t\tout.println(-1);\n\t\t}\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\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 CF159DIV2().runIO();\n\t}\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main (String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader (new InputStreamReader (System.in));\n\t\tString[] splitted = reader.readLine().split(\" \");\n\t\tint n = Integer.parseInt(splitted[0]);\n\t\tint m = Integer.parseInt(splitted[1]);\n\t\tint k = Integer.parseInt(splitted[2]);\n\t\tPriorityQueue<Integer> queue = new PriorityQueue<Integer> (1000, Collections.reverseOrder());\n\t\tsplitted = reader.readLine().split(\" \");\n\t\tfor (int ii = 0; ii < splitted.length; ii++) {\n\t\t\tqueue.add(Integer.parseInt(splitted[ii]));\n\t\t}\n\t\t\n\t\tint counter = 0;\n\t\tint spot = k;\n\t\twhile (spot < m && !queue.isEmpty()) {\n\t\t\tspot = spot + queue.poll() - 1;\n\t\t\tcounter++;\n\t\t}\n\t\tif (spot < m) {\n\t\t\tSystem.out.println(\"-1\");\n\t\t} else {\n\t\t\tSystem.out.println(counter);\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n    //<editor-fold desc=\"input parse\" defaultstate=\"collapsed\">\n\n    private static StringTokenizer st;\n    private static java.io.BufferedReader reader;\n    private static java.io.BufferedWriter writer;\n\n    private static long nextLong() {\n        return Long.parseLong(st.nextToken());\n    }\n\n    private static int nextInt() {\n        return Integer.parseInt(st.nextToken());\n    }\n\n    private static double nextDouble() {\n        return Double.parseDouble(st.nextToken());\n    }\n\n    private static short nextShort() {\n        return Short.parseShort(st.nextToken());\n    }\n\n    private static byte nextByte() {\n        return Byte.parseByte(st.nextToken());\n    }\n\n    private static void initTokenizer() throws Exception {\n        st = new StringTokenizer(reader.readLine());\n    }\n\n    //</editor-fold>\n    \n\n    public static void main(String[] args) throws Exception {\n\treader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in), 1 << 20);\n\twriter = new java.io.BufferedWriter(new java.io.OutputStreamWriter(System.out));\n\t//reader = new java.io.BufferedReader(new java.io.FileReader(\"input.txt\"), 1 << 20);\n\t//writer = new java.io.BufferedWriter(new java.io.FileWriter(\"output.txt\"));\n\t\n\tinitTokenizer();\n\tint n = nextInt();\n\tint m = nextInt();\n\tint k = nextInt();\n\t\n\tinitTokenizer();\n\tint[] a = new int[n];\n\t\n\tfor (int i = 0; i < n; i++) {\n\t    a[i] = nextInt();\n\t}\n\t\n\tArrays.sort(a);\n\t\n\tint total = k;\n\tint cnt = 0;\n\t\n\twhile (total < m && cnt < a.length) {\n\t    total += a[a.length - 1 - cnt] - 1;\n\t    cnt++;\n\t}\n\t\n\tif (total >= m) System.out.println(cnt);\n\telse System.out.println(-1);\n    }\n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\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\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        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();\n        int ans=-1;\n        int i;\n        int a[]=new int[n];\n        for(i=0;i<n;i++)\n            a[i]=in.nextInt();\n        Arrays.sort(a);\n        int p=k,c=0;\n        for(i=n-1;i>=0;i--)\n        {\n            if(p>=m)\n                break;\n            p+=a[i]-1;\n            c++;\n        }\n        if(p>=m)\n            out.printLine(c);\n        else out.printLine(-1);\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\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", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\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\tScanner sc = new Scanner(System.in);\n\t\t// BufferedReader rd = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n\t\t// StringTokenizer t = new StringTokenizer(rd.readLine(), \" \");\n\t\tint n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();\n\t\tint pl[] = new int[n];\n\t\tif (k >= m) {\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tm -= k;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tpl[i] = sc.nextInt() - 1;\n\t\t}\n\t\tArrays.sort(pl);\n\t\tint out = 0;\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tm -= pl[i];\n\t\t\tout++;\n\t\t\tif (m <= 0)\n\t\t\t\tbreak;\n\t\t}\n\t\tif (m <= 0)\n\t\t\tSystem.out.println(out);\n\t\telse\n\t\t\tSystem.out.println(-1);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        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 n = in.nextInt();\n        int m = 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        Arrays.sort(a);\n        if (k >= m) {\n            out.println(0);\n            return;\n        }\n        for (int i = 1; i <= n; i++) {\n            int sockets = k - 1;\n            for (int j = 0; j < i; j++)\n                sockets += a[n - j - 1];\n            sockets -= i - 1;\n            if (sockets >= m) {\n                out.println(i);\n                return;\n            }\n        }\n        out.println(-1);\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 int nextInt() {\n        return Integer.parseInt(next());\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", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class CodeforcesRound159 {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) \n    {\n\tScanner kde = new Scanner(System.in);\n\tint n =kde.nextInt();  //\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\tint m =kde.nextInt();  //\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\tint k =kde.nextInt(); //\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\tArrayList<Integer> count = new ArrayList<Integer>();\n\tfor (int i=0; i<n; i++  )\n\t{\n\t    count.add(kde.nextInt()) ; \n\t}\n\t\n\tCollections.sort(count);\n\tCollections.reverse(count);\n\tif(m<=k)\n\t{\n\t    System.out.println(\"0\"); \n\t    return;\n\t}\n\t\n\tm=m-k+1;\n\t\n\t\n\t\n\t\n\t   int  res=0;\n\tfor(int i=0; i<n; i++ ) \n\t{\n\t    if(i!=0)\n\t    {\n\t    res+=count.get(i)-1;\n\t    }\n\t    else \n\t    {\n\t    res+=count.get(i);\n\t    }\n\t  \n\t    if(res>=m)\n\t    {\n\t\t   System.out.println(i+1);\n\t\t   return;\n\t    }\n\t    \n\t}\n\t\n\t    \n\t\n\t  \n\t\n\t\n\tSystem.out.println(\"-1\");\n\t\n\n    }\n\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int m = 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        Arrays.sort(A);\n        int cnt = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            if (k >= m) {\n                System.out.println(cnt);\n                return;\n            }\n            cnt++;\n            k += A[i] - 1;\n        }\n        if (k >= m)\n            System.out.println(cnt);\n        else\n            System.out.println(-1);\n    }\n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class a{\n    static int a;\n    static Scanner sc = new Scanner(System.in);\n    public static void main(String[] args) throws IOException{\n        int n = sc.nextInt();\n        int p = n;\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            a[i] = sc.nextInt() - 1;\n        }\n        Arrays.sort(a);\n        int j =0;\n        for(int i=0; i<n; i++){\n            if(m > k){\n                k = k + a[n-i-1];\n                j++;\n            }\n        }\n        if(m > k)\n            System.out.println(-1);\n        else\n            System.out.println(j);\n    }\n    \n}", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\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 *\n * @author AndresFelipe\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;\n        st = new StringTokenizer(br.readLine());\n        int n=Integer.valueOf(st.nextToken());\n        int m=Integer.valueOf(st.nextToken());\n        int k=Integer.valueOf(st.nextToken());\n        st = new StringTokenizer(br.readLine());\n        int sock[] = new int[n];\n        \n        for (int i=0;i<n;i++){\n            sock[i]= Integer.valueOf(st.nextToken());\n        }\n        Arrays.sort(sock);\n        m-=k;\n        int count=0;\n        int index=sock.length-1;\n        while(m>0){\n            if(index<0){\n                System.out.println(\"-1\");\n                return;\n            }\n            m++;\n            m-=sock[index];\n            index--;\n            count++;\n        }\n        System.out.println(count);\n    }\n    \n}\n", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author BSRK Aditya (bsrkaditya@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\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        int n = in.readInt();\n        int m = in.readInt();\n        int k = in.readInt();\n\n\n        int [] filters = new int[n];\n        for(int i = 0; i < n; ++i) filters[i] = in.readInt();\n\n        Arrays.sort(filters);\n\n        int nS = 0, tN = k;\n\n        while(tN < m && nS < n) {\n            tN += filters[n-1-nS] - 1;\n            nS++;\n        }\n\n        if(tN >= m) out.printLine(nS);\n        else out.printLine(-1);\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\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\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", "complexity": "nlogn", "problem": "257_A. Sockets", "from": "CODEFORCES"}
{"src": "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        TaskG solver = new TaskG();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG {\n        static int[][] g;\n        static int n;\n        static int[] a;\n        static int[][] edges;\n        static long[] dp;\n        static long[] dpPathToRootWithDetours;\n        static int time = 0;\n        static int[] appearance;\n        static int[] firstAppearance;\n        static int[] depth;\n\n        public static void dfs(int i, int parE) {\n            firstAppearance[i] = time;\n            appearance[time++] = i;\n            dp[i] = a[i];\n            for (int eIndex : g[i]) {\n                if (eIndex == parE) continue;\n                int child = i ^ edges[eIndex][0] ^ edges[eIndex][1];\n                dfs(child, eIndex);\n                appearance[time++] = i;\n                dp[i] += Math.max(dp[child] - edges[eIndex][2] * 2, 0);\n            }\n        }\n\n        public static void dfs2(int i, int parE) {\n            if (i == 0) {\n                dpPathToRootWithDetours[i] = dp[i];\n            } else {\n                int par = i ^ edges[parE][0] ^ edges[parE][1];\n                depth[i] = depth[par] + 1;\n                dpPathToRootWithDetours[i] = dpPathToRootWithDetours[par] - Math.max(0, dp[i] - edges[parE][2] * 2);\n                dpPathToRootWithDetours[i] -= edges[parE][2];\n                dpPathToRootWithDetours[i] += dp[i];\n\n                long myPathWeight = Math.max(dp[i] - edges[parE][2] * 2, 0);\n                long change = dp[par] - myPathWeight - edges[parE][2] * 2;\n                change = Math.max(change, 0);\n                dp[i] += change;\n            }\n            for (int eIndex : g[i]) {\n                if (eIndex == parE) continue;\n                dfs2(i ^ edges[eIndex][0] ^ edges[eIndex][1], eIndex);\n            }\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.NextInt();\n            int q = in.NextInt();\n            a = in.NextIntArray(n);\n            edges = new int[n - 1][3];\n            {\n                long[] count = new long[n];\n                for (int i = 0; i < n - 1; i++) {\n                    int u = in.NextInt() - 1;\n                    int v = in.NextInt() - 1;\n                    int w = in.NextInt();\n                    edges[i][0] = u;\n                    edges[i][1] = v;\n                    edges[i][2] = w;\n                    count[u]++;\n                    count[v]++;\n                }\n\n                g = new int[n][];\n                for (int i = 0; i < n; i++) {\n                    g[i] = new int[(int) count[i]];\n                }\n                for (int i = 0; i < n - 1; i++) {\n                    for (int j = 0; j < 2; j++) {\n                        g[edges[i][j]][(int) --count[edges[i][j]]] = i;\n                    }\n                }\n            }\n            dp = new long[n];\n            dpPathToRootWithDetours = new long[n];\n            depth = new int[n];\n            firstAppearance = new int[n];\n            appearance = new int[(n - 1) * 2 + 1];\n            dfs(0, -1);\n            dfs2(0, -1);\n            GraphLowestCommonAncestor.LCA lca = GraphLowestCommonAncestor.createLCA(appearance, firstAppearance, depth);\n            firstAppearance = null;\n            depth = null;\n            appearance = null;\n            edges = null;\n            g = null;\n            for (int i = 0; i < q; i++) {\n                int u = in.NextInt() - 1;\n                int v = in.NextInt() - 1;\n                int lcaI = lca.getLCA(u, v);\n                long res = dpPathToRootWithDetours[u] + dpPathToRootWithDetours[v] - 2 * dpPathToRootWithDetours[lcaI] + dp[lcaI];\n                out.println(res);\n            }\n        }\n\n    }\n\n    static class MinRangeSparseTable implements ISearchInRange {\n        private final int[][] sparseTables;\n        private final long[] array;\n        private final boolean reverseOrdered;\n\n        public MinRangeSparseTable(long[] array, boolean reverseOrdered) {\n            this.reverseOrdered = reverseOrdered;\n            this.array = array;\n            int LCALength = IntegerExtension.getNumberOfBits(array.length);\n            sparseTables = new int[LCALength][];\n            sparseTables[0] = new int[array.length];\n            for (int i = 0; i < array.length; i++) {\n                sparseTables[0][i] = i;\n            }\n            for (int i = 1; i < LCALength; i++) {\n                int size = 1 << i;\n                int jumpSize = 1 << (i - 1);\n                sparseTables[i] = new int[sparseTables[0].length - size + 1];\n                for (int j = 0; j < sparseTables[i].length; j++) {\n                    sparseTables[i][j] = min(sparseTables[i - 1][j], sparseTables[i - 1][j + jumpSize]);\n                }\n            }\n        }\n\n        private int min(int a, int b) {\n            return ((array[a] < array[b]) ^ reverseOrdered) ? a : b;\n        }\n\n\n        public Pair<Long, Long> queryIndexValueInRange(long l, long r) {\n            int size = (int) (r - l + 1);\n            int LCAIndex = IntegerExtension.getNumberOfBits(size) - 1;\n            int sizeNeeded = 1 << LCAIndex;\n            int res = min(sparseTables[LCAIndex][(int) l], sparseTables[LCAIndex][(int) (r - sizeNeeded + 1)]);\n            return new Pair<>((long) res, array[res]);\n        }\n\n        public MinRangeSparseTable(long[] array) {\n            this(array, false);\n        }\n\n    }\n\n    static class GraphLowestCommonAncestor {\n        public static GraphLowestCommonAncestor.LCA createLCA(int[] appearances, final int[] firstAppearance, final int[] depth) {\n            return new GraphLowestCommonAncestor.LCA_MinRangeSparseTable(appearances, firstAppearance, depth);\n        }\n\n        public interface LCA {\n            int getLCA(int a, int b);\n\n        }\n\n        private static class LCA_MinRangeSparseTable implements GraphLowestCommonAncestor.LCA {\n            private final MinRangeSparseTable minRangeSparseTable;\n            private final int[] firstAppearance;\n            private final int[] indexToNode;\n\n            public LCA_MinRangeSparseTable(int[] appearances, final int[] firstAppearance, final int[] depth) {\n                this.firstAppearance = firstAppearance;\n                this.indexToNode = appearances;\n                long[] depthOrder = new long[appearances.length];\n                for (int i = 0; i < depthOrder.length; i++) {\n                    depthOrder[i] = depth[appearances[i]];\n                }\n                minRangeSparseTable = new MinRangeSparseTable(depthOrder);\n            }\n\n\n            public int getLCA(int a, int b) {\n                a = firstAppearance[a];\n                b = firstAppearance[b];\n                int l = Math.min(a, b), r = Math.max(a, b);\n                return indexToNode[(int) (long) minRangeSparseTable.queryIndexValueInRange(l, r).first];\n            }\n\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 int[] NextIntArray(int n) {\n            return NextIntArray(n, 0);\n        }\n\n        public int[] NextIntArray(int n, int offset) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = NextInt() + offset;\n            }\n            return a;\n        }\n\n    }\n\n    static interface ISearchInRange {\n    }\n\n    static class Pair<T1, T2> {\n        public T1 first;\n        public T2 second;\n\n        public Pair(T1 f, T2 s) {\n            first = f;\n            second = s;\n        }\n\n    }\n\n    static class IntegerExtension {\n        public static int getNumberOfBits(long i) {\n            return 64 - Long.numberOfLeadingZeros(i);\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "1000_G. Two-Paths", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\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\n        long totalBlocks = 0;\n        long a[] = new long[n];\n        for(int i = 0; i < n; ++i) {\n            a[i] = sc.nextLong();\n            totalBlocks += a[i];\n        }\n\n        Arrays.sort(a);\n\n        long selected = 0;\n        for(int i = 0; i < n; ++i) {\n            if(a[i] > selected)\n                selected++;\n        }\n\n        long leftCols = a[n - 1] - selected;\n        long remBlocks = totalBlocks - leftCols - n;\n\n        System.out.print(remBlocks);\n    }\n}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\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\n        long totalBlocks = 0;\n        long a[] = new long[n];\n        for(int i = 0; i < n; ++i) {\n            a[i] = sc.nextLong();\n            totalBlocks += a[i];\n        }\n\n        Arrays.sort(a);\n\n        long selected = 0;\n        for(int i = 0; i < n; ++i) {\n            if(a[i] > selected)\n                selected++;\n        }\n\n        long leftCols = a[n - 1] - selected;\n        long remBlocks = totalBlocks - leftCols - n;\n\n        System.out.print(remBlocks);\n    }\n}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "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 m=Integer.parseInt(s1[1]);\n            int a[]=new int[n];\n            String s2[]=br.readLine().split(\" \");\n            long S=0;\n            for(int i=0;i<n;i++)\n            { a[i]=Integer.parseInt(s2[i]);  S+=(long)a[i]; }\n            \n            Arrays.sort(a);\n            m=a[n-1];\n            int last=1;\n            int t=1;\n            for(int i=1;i<n-1;i++)\n            {\n                  if(a[i]==last)\n                   t++;\n                  else\n                  {\n                        t++;\n                        last=last+1;\n                  }\n            }\n            if(last<m)\n            { t+=m-last; }\n            else\n             t++;\n            System.out.println(S-t);\n      }\n}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class test{\npublic static void main(String args[])\n{\nScanner s=new Scanner(System.in);\nint n=s.nextInt();\nint m=s.nextInt();\nint arr[]=new int[n];\nint max = Integer.MIN_VALUE;\n        long sum = 0;\n        for(int i=0;i<n;i++)\n        {\n            arr[i] = s.nextInt();\n            sum = sum + arr[i];\n            max = Math.max(max,arr[i]);\n        }\n        Arrays.sort(arr);\n        int i = 0;\n        int count = 0;\n        int d = 0;\n        for(i=0; i<n; i++)\n        {\n            if(arr[i] > d)\n            {\n                count++;\n                d++;\n            }\n            else if(arr[i] == d && arr[i] > 0)\n            {\n                count++;\n            }\n        }\n        //System.out.println(count + \" \" + max);\n        if(max - d > 0)\n        {\n            count = count + max - d;\n        }\n        System.out.println(sum - count);}}", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\npublic class stacks {\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\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\t\n\t\tlong remove = 0;\n\t\t\n\t\tint[] heights = new int[n+1];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\theights[i] = sc.nextInt();\n\t\t\tremove += heights[i];\n\t\t}\n\t\t\n\t\tArrays.sort(heights);\n\t\t//System.out.println(Arrays.toString(heights));\n\t\tlong keep = 0;\n\t\tfor(int i = n; i> 0; i--) {\n\t\t\tif(heights[i-1] >= heights[i]) {\n\t\t\t\theights[i-1] = heights[i]-1;\n\t\t\t}\n\t\t\tkeep += heights[i] - heights[i-1];\n\t\t}\n\t\t//System.out.println(Arrays.toString(heights));\n\t\t\n\t\tpw.println(remove - keep);\n\t\tpw.close();\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", "complexity": "nlogn", "problem": "1061_B. Views Matter", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[] wide = new int[n], sta = new int[n];\n        HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();\n        for (int i = 0; i < n; i++) {\n        \twide[i] = sc.nextInt();\n        \thm.put(wide[i], i + 1);\n        }\n        Util.sort(wide);\n        sc.nextLine();\n        String s = sc.nextLine();\n        int tp = 0, pos = 0;\n        StringBuilder out = new StringBuilder();\n        for (int i = 0; i < s.length(); i++) {\n        \tint t;\n        \tif (s.charAt(i) == '0') {\n        \t\tt = wide[pos++];\n        \t\tsta[tp++] = t;\n        \t} else t = sta[--tp];\n        \tout.append(hm.get(t) + \" \");\n        }\n        System.out.println(out.toString());\n        sc.close();\n    }\n    public static class Util {\n    \t\n    \tpublic static <T extends Comparable<T> > void merge_sort(T[] a) {\n    \t\tObject[] aux = new Object[a.length];\n    \t\tmerge_sort0(a, aux, 0, a.length);\n    \t}\n    \t\n    \tpublic static <T extends Comparable<T> > void merge_sort(T[] a, int l, int r) {\n    \t\tObject[] aux = new Object[a.length];\n    \t\tmerge_sort0(a, aux, l, r);\n    \t}\n    \t\n    \t@SuppressWarnings(\"unchecked\")\n    \tprivate static <T extends Comparable<T> > void merge_sort0(T[] a, Object[] temp, int l, int r) {\n    \t\tif (l + 1 == r) return;\n    \t\tint mid = (l + r) >> 1;\n    \t\tmerge_sort0(a, temp, l, mid);\n    \t\tmerge_sort0(a, temp, mid, r);\n    \t\tint x = l, y = mid, c = l;\n    \t\twhile (x < mid || y < r) {\n    \t\t\tif (y == r || (x < mid && a[x].compareTo(a[y]) <= 0)) temp[c++] = a[x++];\n    \t\t\telse temp[c++] = a[y++];\n    \t\t}\n    \t\tfor (int i = l; i < r; i++) a[i] = (T)temp[i];\n    \t}\n    \t\n    \tstatic final Random RAN = new Random();\n    \t\n    \tpublic static <T extends Comparable<T> > void quick_sort(T[] a) {\n    \t\tquick_sort0(a, 0, a.length);\n    \t}\n    \t\n    \tpublic static <T extends Comparable<T> > void quick_sort(T[] a, int l, int r) {\n    \t\tquick_sort0(a, l, r);\n    \t}\n    \t\n    \tprivate static <T extends Comparable<T> > void quick_sort0(T[] a, int l, int r) {\n    \t\tif (l + 1 >= r) return;\n    \t\tint p = l + RAN.nextInt(r - l);\n    \t\tT t = a[p]; a[p] = a[l]; a[l] = t;\n    \t\tint x = l, y = r - 1;\n    \t\twhile (x < y) {\n    \t\t\twhile (x < y && a[y].compareTo(t) > 0) --y;\n    \t\t\twhile (x < y && a[x].compareTo(t) < 0) ++x;\n    \t\t\tif (x < y) {\n    \t\t\t\tT b = a[x]; a[x] = a[y]; a[y] = b;\n    \t\t\t\t++x; --y;\n    \t\t\t}\n    \t\t}\n    \t\tquick_sort0(a, l, y + 1);\n    \t\tquick_sort0(a, x, r);\n    \t}\n    \t\n    \tstatic final int BOUND = 8;\n    \t\n    \tpublic static void bucket_sort(int[] a) {\n    \t\tbucket_sort(a, 0, a.length);\n    \t}\n    \t\n    \tpublic static void bucket_sort(int[] a, int l, int r) {\n    \t\tint[] cnt = new int[1 << BOUND], b = new int[r - l + 1];\n    \t\tint y = 0;\n    \t\tfor (int i = l; i < r; i++) ++cnt[a[i] & (1 << BOUND) - 1];\n    \t\twhile (y < Integer.SIZE) {\n    \t\t\tfor (int i = 1; i < 1 << BOUND; i++) cnt[i] += cnt[i - 1];\n    \t\t\tfor (int i = r - 1; i >= l; i--) b[--cnt[a[i] >> y & (1 << BOUND) - 1]] = a[i];\n    \t\t\ty += BOUND;\n    \t\t\tArrays.fill(cnt, 0);\n    \t\t\tfor (int i = l; i < r; i++) {\n    \t\t\t\ta[i] = b[i - l];\n    \t\t\t\t++cnt[a[i] >> y & (1 << BOUND) - 1];\n    \t\t\t}\n    \t\t}\n    \t}\n    \t\n    \tpublic static void bucket_sort(long[] a) {\n    \t\tbucket_sort(a, 0, a.length);\n    \t}\n    \t\n    \tpublic static void bucket_sort(long[] a, int l, int r) {\n    \t\tint[] cnt = new int[1 << BOUND];\n    \t\tlong[] b = new long[r - l + 1];\n    \t\tint y = 0;\n    \t\twhile (y < Long.SIZE) {\n    \t\t\tArrays.fill(cnt, 0);\n    \t\t\tfor (int i = l; i < r; i++) ++cnt[(int) (a[i] >> y & (1 << BOUND) - 1)];\n    \t\t\tfor (int i = 1; i < 1 << BOUND; i++) cnt[i] += cnt[i - 1];\n    \t\t\tfor (int i = r - 1; i >= l; i--) b[--cnt[(int) (a[i] >> y & (1 << BOUND) - 1)]] = a[i];\n    \t\t\tfor (int i = l; i < r; i++) a[i] = b[i - l];\n    \t\t\ty += BOUND;\n    \t\t}\n    \t}\n    \t\n    \tpublic static void sort(int[] a) {\n    \t\tif (a.length <= 1 << BOUND) {\n    \t\t\tInteger[] b = new Integer[a.length];\n    \t\t\tfor (int i = 0; i < a.length; i++) b[i] = a[i];\n    \t\t\tquick_sort(b);\n    \t\t\tfor (int i = 0; i < a.length; i++) a[i] = b[i];\n    \t\t} else bucket_sort(a);\n    \t}\n\n    \tpublic static void sort(long[] a) {\n    \t\tif (a.length <= 1 << BOUND) {\n    \t\t\tLong[] b = new Long[a.length];\n    \t\t\tfor (int i = 0; i < a.length; i++) b[i] = a[i];\n    \t\t\tquick_sort(b);\n    \t\t\tfor (int i = 0; i < a.length; i++) a[i] = b[i];\n    \t\t} else bucket_sort(a);\n    \t}\n    \t\n    \tpublic static <T extends Comparable<T> > void sort(T[] a) {\n    \t\tquick_sort(a);\n    \t}\n    \t\n    \tpublic static void shuffle(int[] a) {\n    \t\tRandom ran = new Random();\n    \t\tfor (int i = 0; i < a.length; i++) {\n    \t\t\tint p = ran.nextInt(i + 1);\n    \t\t\tint q = a[p]; a[p] = a[i]; a[i] = q; \n    \t\t}\n    \t}\n    \t\n    \tpublic static void shuffle(long[] a) {\n    \t\tRandom ran = new Random();\n    \t\tfor (int i = 0; i < a.length; i++) {\n    \t\t\tint p = ran.nextInt(i + 1);\n    \t\t\tlong q = a[p]; a[p] = a[i]; a[i] = q; \n    \t\t}\n    \t}\n    \t\n    \tpublic static <T> void shuffle(T[] a) {\n    \t\tRandom ran = new Random();\n    \t\tfor (int i = 0; i < a.length; i++) {\n    \t\t\tint p = ran.nextInt(i + 1);\n    \t\t\tT q = a[p]; a[p] = a[i]; a[i] = q; \n    \t\t}\n    \t}\n    \t\n    }\n}", "complexity": "nlogn", "problem": "982_B. Bus of Characters", "from": "CODEFORCES"}
{"src": "/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License.  You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.StringJoiner;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class Test {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        String[] line = reader.readLine().split(\" \");\n        int w = Integer.valueOf(line[0]);\n        int h = Integer.valueOf(line[1]);\n        int n = Integer.valueOf(line[2]);\n\n        Request[] requests = new Request[n];\n\n        for (int i = 0; i < n; i++) {\n            line = reader.readLine().split(\" \");\n            requests[i] = new Request(line[0], Integer.valueOf(line[1]));\n        }\n\n        for (long e : solve(h, w, requests))\n            System.out.println(e);\n\n//        int w = 200000, h = 200000, n = 400000;\n//        Request[] requests = generate(w, h, n);\n//\n//        long start = System.currentTimeMillis();\n//        solve(h, w, requests);\n//        long end = System.currentTimeMillis();\n//\n//        System.out.println(\"Time: \" + (end - start) + \" ms\");\n    }\n\n    private static Request[] generate(int w, int h, int n) {\n        Request[] requests = new Request[n];\n        Random rnd = new Random();\n\n        for (int i = 0; i < n; i++) {\n            requests[i] = rnd.nextBoolean() ? new Request(\"V\", rnd.nextInt(w)) : new Request(\"H\", rnd.nextInt(h));\n        }\n\n        return requests;\n    }\n\n    private static long[] solve(int h, int w, Request[] requests) {\n        TreeSet<Integer> hTree = new TreeSet<>();\n        TreeSet<Integer> wTree = new TreeSet<>();\n\n        Queue<CoordinateWithSize> hHeap = new PriorityQueue<>();\n        Queue<CoordinateWithSize> wHeap = new PriorityQueue<>();\n\n        hTree.add(0);\n        hTree.add(h);\n        wTree.add(0);\n        wTree.add(w);\n\n        hHeap.add(new CoordinateWithSize(0, h));\n        wHeap.add(new CoordinateWithSize(0, w));\n\n        long[] res = new long[requests.length];\n        for (int i = 0; i < requests.length; i++) {\n            Request request = requests[i];\n\n            switch (request.type) {\n                case \"H\": {\n                    if (!hTree.contains(request.coordinate)) {\n                        int higher = hTree.higher(request.coordinate);\n                        int lower = hTree.lower(request.coordinate);\n\n                        hHeap.add(new CoordinateWithSize(lower, request.coordinate - lower));\n                        hHeap.add(new CoordinateWithSize(request.coordinate, higher - request.coordinate));\n\n                        hTree.add(request.coordinate);\n                    }\n\n                    break;\n                }\n                case \"V\": {\n                    if (!wTree.contains(request.coordinate)) {\n                        int higher = wTree.higher(request.coordinate);\n                        int lower = wTree.lower(request.coordinate);\n\n                        wHeap.add(new CoordinateWithSize(lower, request.coordinate - lower));\n                        wHeap.add(new CoordinateWithSize(request.coordinate, higher - request.coordinate));\n\n                        wTree.add(request.coordinate);\n                    }\n\n                    break;\n                }\n                default:\n                    throw new IllegalStateException(\"Unknown type [type=\" + request.type + \"]\");\n            }\n\n            while (true) {\n                CoordinateWithSize c = hHeap.peek();\n                if (hTree.higher(c.coordinate) - c.coordinate == c.size)\n                    break;\n                hHeap.remove();\n            }\n\n            while (true) {\n                CoordinateWithSize c = wHeap.peek();\n                if (wTree.higher(c.coordinate) - c.coordinate == c.size)\n                    break;\n                wHeap.remove();\n            }\n\n            res[i] = 1L * hHeap.peek().size * wHeap.peek().size;\n        }\n\n        return res;\n    }\n\n    private static class CoordinateWithSize implements Comparable<CoordinateWithSize> {\n\n        private final int coordinate;\n\n        private final int size;\n\n        public CoordinateWithSize(int coordinate, int size) {\n            this.coordinate = coordinate;\n            this.size = size;\n        }\n\n        @Override public int compareTo(CoordinateWithSize o) {\n            return Integer.compare(o.size, size);\n        }\n    }\n\n    private static class Request {\n\n        private final String type;\n\n        private final int coordinate;\n\n        public Request(String type, int coordinate) {\n            this.type = type;\n            this.coordinate = coordinate;\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "527_C. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\nimport java.util.Map;\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 Ribhav\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        CGlassCarving solver = new CGlassCarving();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class CGlassCarving {\n        public void solve(int testNumber, FastReader s, PrintWriter out) {\n            TreeMap<Long, Integer> mapH = new TreeMap<>();\n            TreeMap<Long, Integer> mapV = new TreeMap<>();\n            TreeMap<Long, Integer> hDiff = new TreeMap<>();\n            TreeMap<Long, Integer> vDiff = new TreeMap<>();\n            long width = s.nextInt();\n            long height = s.nextInt();\n            mapH.put(0L, 1);\n            mapV.put(0L, 1);\n            mapV.put(width, 1);\n            mapH.put(height, 1);\n            vDiff.put(width, 1);\n            hDiff.put(height, 1);\n            long maxV = height;\n            long maxH = width;\n            int n = s.nextInt();\n            for (int i = 0; i < n; i++) {\n                char ch = s.nextCharacter();\n                long cut = s.nextInt();\n                if (ch == 'H') {\n                    Long next = mapH.higherKey(cut);\n                    Long prev = mapH.lowerKey(cut);\n                    Long diff = next - prev;\n                    int freq = hDiff.get(diff);\n                    if (freq == 1) {\n                        hDiff.remove(diff);\n                    } else {\n                        hDiff.put(diff, freq - 1);\n                    }\n                    hDiff.put(next - cut, hDiff.getOrDefault(next - cut, 0) + 1);\n                    hDiff.put(cut - prev, hDiff.getOrDefault(cut - prev, 0) + 1);\n                    mapH.put(cut, mapH.getOrDefault(cut, 0) + 1);\n                } else {\n                    Long next = mapV.higherKey(cut);\n                    Long prev = mapV.lowerKey(cut);\n                    Long diff = next - prev;\n                    int freq = vDiff.get(diff);\n                    if (freq == 1) {\n                        vDiff.remove(diff);\n                    } else {\n                        vDiff.put(diff, freq - 1);\n                    }\n                    vDiff.put(next - cut, vDiff.getOrDefault(next - cut, 0) + 1);\n                    vDiff.put(cut - prev, vDiff.getOrDefault(cut - prev, 0) + 1);\n                    mapV.put(cut, mapV.getOrDefault(cut, 0) + 1);\n                }\n\n                out.println(hDiff.lastKey() * vDiff.lastKey());\n            }\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private FastReader.SpaceCharFilter filter;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public char nextCharacter() {\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\n", "complexity": "nlogn", "problem": "527_C. Glass Carving", "from": "CODEFORCES"}
{"src": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.net.Inet4Address;\nimport java.util.*;\n\npublic class l {\n    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    static long mod = (int) (1e9 + 7);\n    static int n;\n    static StringBuilder sol;\n\n    static class pair implements Comparable<pair> {\n        int L,R;\n        public pair( int x,int y) {\n            L=x;R=y;\n        }\n\n\n        public int compareTo(pair o) {\n            if (L!=o.L)return L-o.L;\n            return o.R-R;\n        }\n        public String toString(){\n            return L+\" \"+R;\n        }\n    }\n    static boolean is;\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        //FileWriter f = new FileWriter(\"C:\\\\Users\\\\Ibrahim\\\\out.txt\");\n        PrintWriter pw = new PrintWriter(System.out);\n        int m = sc.nextInt();\n        int n = sc.nextInt();\n        int q = sc.nextInt();\n        TreeSet<Integer>length= new TreeSet<>();\n        length.add(0);\n        length.add(n);\n        TreeSet<Integer>width= new TreeSet<>();\n        width.add(0);\n        width.add(m);\n        TreeMap<Integer,Integer>len= new TreeMap<>();\n        len.put(n,1);\n        TreeMap<Integer,Integer>wid= new TreeMap<>();\n        wid.put(m,1);\n        while (q-->0){\n            String t= sc.next();\n            if (t.equals(\"H\")) {\n                int x = sc.nextInt();\n                int k1 = length.ceiling(x);\n                int k2 = length.floor(x);\n                if (x != k1) {\n                    int s = k1 - k2;\n                    int con = len.get(s);\n                    if (con == 1) len.remove(s);\n                    else len.put(s, con - 1);\n                    len.put((k1 - x), len.getOrDefault((k1 - x), 0) + 1);\n                    len.put((x - k2), len.getOrDefault((x - k2), 0) + 1);\n                    length.add(x);\n                }\n            }\n            else {\n                int x = sc.nextInt();\n                int k1 = width.ceiling(x);\n                int k2 = width.floor(x);\n                if (x != k1) {\n                    int s = k1 - k2;\n                    //System.out.println(s+\" \"+k1+\" \"+k2);\n                    int con = wid.get(s);\n                    if (con == 1) wid.remove(s);\n                    else wid.put(s, con - 1);\n                    wid.put((k1 - x), wid.getOrDefault((k1 - x), 0) + 1);\n                    wid.put((x - k2), wid.getOrDefault((x - k2), 0) + 1);\n                    width.add(x);\n                }\n            }\n            pw.println(1l*len.lastKey()*wid.lastKey());\n        }\n\n        pw.flush();\n    }\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\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        public boolean ready() throws IOException {\n            return br.ready();\n        }\n\n\n    }\n\n}", "complexity": "nlogn", "problem": "527_C. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.*;\nimport java.security.SecureRandom;\n\npublic class WCS {\n\t\n\tpublic static class Vector implements Comparable <Vector>  {\n\t\tlong x, y;\n\t\tint position;\n\t\tVector first, second;\n\t\tboolean toReverse;\n\t\t\n\t\tpublic Vector(long xx, long yy, int p) {\n\t\t\tx = xx;\n\t\t\ty = yy;\n\t\t\tposition = p;\n\t\t\tfirst = null;\n\t\t\tsecond = null;\n\t\t\ttoReverse = false;\n\t\t}\n\t\t\n\t\tpublic Vector negate() {\n\t\t\tVector vv = new Vector(-x, -y, position);\n\t\t\tvv.first = first;\n\t\t\tvv.second = second;\n\t\t\tvv.toReverse = !toReverse;\n\t\t\treturn vv;\n\t\t}\n\t\t\n\t\tpublic Vector add(Vector v) {\n\t\t\tVector sum = new Vector(this.x + v.x, this.y + v.y, position);\n\t\t\tsum.first = this;\n\t\t\tsum.second = v;\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tpublic Vector subtract(Vector v) {\n\t\t\treturn this.add(v.negate());\n\t\t}\n\t\t\n\t\tpublic double euclideanNorm() {\n\t\t\treturn Math.sqrt(x * x + y * y);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Vector v) {\n\t\t\tdouble thisa = Math.atan2(this.y, this.x);\n\t\t\tdouble va = Math.atan2(v.y, v.x);\n\t\t\tif(thisa < 0)\n\t\t\t\tthisa += 2 * Math.PI;\n\t\t\tif(va < 0)\n\t\t\t\tva += 2 * Math.PI;\n\t\t\tif(thisa < va)\n\t\t\t\treturn -1;\n\t\t\tif(thisa > va)\n\t\t\t\treturn 1;\n\t\t\treturn Integer.compare(this.position, v.position);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y;\n\t\t}\n\t}\n\t\n\tpublic static void dfs(Vector curr, int[] ans) {\n\t\tif(curr.first == null) {\n\t\t\tans[curr.position] = curr.toReverse ? -1 : 1;\n\t\t\treturn;\n\t\t}\n\t\tcurr.first.toReverse ^= curr.toReverse;\n\t\tcurr.second.toReverse ^= curr.toReverse;\n\t\tdfs(curr.first, ans);\n\t\tdfs(curr.second, ans);\n\t}\n\t\n\tpublic static boolean ok(Vector v1, Vector v2) {\n\t\treturn v1.add(v2).euclideanNorm() <= Math.max(v1.euclideanNorm(), v2.euclideanNorm());\n\t}\n\t\n\tpublic static void stop(long k) {\n\t\tlong time = System.currentTimeMillis();\n\t\twhile(System.currentTimeMillis() - time < k);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = in.nextInt();\n\t\tTreeSet <Vector> vectors = new TreeSet <> ();\n\t\tfor(int i = 0; i < n; i ++) {\n\t\t\tVector v = new Vector(in.nextLong(), in.nextLong(), i);\n\t\t\tvectors.add(v);\n\t\t}\n\t\twhile(vectors.size() > 2) {\n\t\t\t//System.out.println(vectors);\n\t\t\t//stop(500);\n\t\t\t\n\t\t\tTreeSet <Vector> support = new TreeSet <> ();\n\t\t\t\n\t\t\twhile(vectors.size() > 0) {\n\t\t\t\tVector curr = vectors.pollFirst();\n\t\t\t\tVector next1 = vectors.higher(curr);\n\t\t\t\tVector next2 = vectors.lower(curr.negate());\n\t\t\t\tVector next3 = vectors.higher(curr.negate());\n\t\t\t\tVector next4 = vectors.lower(curr);\n\t\t\t\t\n\t\t\t\t//System.out.println(\"CURR: \" + curr + \"\\n\" + next1 + \"\\n\" + next2);\n\t\t\t\t\n\t\t\t\tif(next1 != null) {\n\t\t\t\t\tif(ok(curr, next1)) {\n\t\t\t\t\t\tsupport.add(curr.add(next1));\n\t\t\t\t\t\tvectors.remove(next1);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next1 != null) {\n\t\t\t\t\tif(ok(curr, next1.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next1));\n\t\t\t\t\t\tvectors.remove(next1);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next2 != null) {\n\t\t\t\t\tif(ok(curr, next2)) {\n\t\t\t\t\t\tsupport.add(curr.add(next2));\n\t\t\t\t\t\tvectors.remove(next2);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next2 != null) {\n\t\t\t\t\tif(ok(curr, next2.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next2));\n\t\t\t\t\t\tvectors.remove(next2);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next3 != null) {\n\t\t\t\t\tif(ok(curr, next3)) {\n\t\t\t\t\t\tsupport.add(curr.add(next3));\n\t\t\t\t\t\tvectors.remove(next3);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next3 != null) {\n\t\t\t\t\tif(ok(curr, next3.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next3));\n\t\t\t\t\t\tvectors.remove(next3);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next4 != null) {\n\t\t\t\t\tif(ok(curr, next4)) {\n\t\t\t\t\t\tsupport.add(curr.add(next4));\n\t\t\t\t\t\tvectors.remove(next4);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(next4 != null) {\n\t\t\t\t\tif(ok(curr, next4.negate())) {\n\t\t\t\t\t\tsupport.add(curr.subtract(next4));\n\t\t\t\t\t\tvectors.remove(next4);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tsupport.add(curr);\n\t\t\t}\n\t\t\t\n\t\t\tvectors = support;\n\t\t}\n\t\t\n\t\tif(vectors.size() == 2) {\n\t\t\tVector curr = vectors.pollFirst();\n\t\t\tVector next = vectors.pollFirst();\n\t\t\tVector add = curr.add(next);\n\t\t\tVector sub = curr.subtract(next);\n\t\t\tif(sub.euclideanNorm() <= add.euclideanNorm())\n\t\t\t\tvectors.add(sub);\n\t\t\telse\n\t\t\t\tvectors.add(add);\n\t\t}\n\t\t\n\t\t//System.out.println(vectors.first().euclideanNorm());\n\t\t\n\t\tStringBuilder buffer = new StringBuilder();\n\t\tint[] ans = new int[n];\n\t\tdfs(vectors.pollFirst(), ans);\n\t\tfor(int i = 0; i < n; i ++)\n\t\t\tbuffer.append(ans[i] + \" \");\n\t\tSystem.out.println(buffer);\n\t}\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                }\n                catch (IOException  e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n \n        BigInteger nextBigInteger() {\n        \treturn new BigInteger(in.next());\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        char nextChar() {\n            return in.next().charAt(0);\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            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n    \n    static FastReader in = new FastReader();\n    static OutputStream out = new BufferedOutputStream(System.out);\n    \n    public static byte[] toByte(Object o) {\n        return String.valueOf(o).getBytes();\n    }\n    \n    public static void sop(Object o) {\n        System.out.print(o);\n    }\n}", "complexity": "nlogn", "problem": "995_C. Leaving the Bar", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class Main {\n    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(System.out);\n        //Scanner sc = new Scanner();\n        Reader in = new Reader();\n        Main solver = new Main();\n        solver.solve(out, in);\n        out.flush();\n        out.close();\n \n    }\n \n    static int INF = (int)1e5*4*4+5;\n    static int maxn = (int)1e5*2+1;\n    static int mod=(int)1e9+7 ;\n    static int n,m,k,t,q,x,a,b,y;\n    \n    static ArrayList<Integer> adj[];\n    static int[] dist,parent,back;\n    static boolean[] vis,vist;\n    static int root=0,ans=1;\n    \n    \n    void solve(PrintWriter out, Reader in) throws IOException{\n        n = in.nextInt();\n\n\n        if(n==1) {out.println(1);return;}\n        adj = new ArrayList[n+1];\n        for(int i=1;i<=n;i++) \n            adj[i] = new ArrayList<Integer>();\n        \n        int u,v;\n        for(int i=0;i<n-1;i++){\n            u = in.nextInt();\n            v = in.nextInt();\n             \n            adj[u].add(v);\n            adj[v].add(u);\n        }\n        \n        vist = new boolean[n+1];\n        vis = new boolean[n+1];\n        vist[1] =true;\n        makeroot(1);\n        \n        parent = new int[n+1];\n        dist = new int[n+1];\n        back = new int[n+1];\n        \n        dfs(root,0);\n        calcdist(root);\n        \n        vist = new boolean[n+1];\n        vis = new boolean[n+1];\n        vist[root] =true;\n        \n        \n\n        PriorityQueue<Node> pq = new PriorityQueue<Node>();\n        for(int i=1;i<=n;i++){\n            if(i!=root) pq.add(new Node(i,dist[i]));\n        }\n        \n        Node elm;\n        int rt = root;\n        out.print(1);\n        \n        makeroot(root);\n        removeNodes(root,rt);\n        ans+=dist[rt];\n        out.print(\" \"+ans);\n        int itr=2;\n        for(int i=2;i<=n;i++){\n            \n            elm = pq.remove();\n            if(vis[elm.idx]) continue;\n            removeNodes(back[elm.idx],elm.idx);\n            ans += elm.dist+1;\n            out.print(\" \"+ans);\n            itr++;\n        }\n        for(int i=itr;i<n;i++)\n            out.print(\" \"+ans);\n        out.println();\n    }\n    \n    //<>\n    \n    static class Node implements Comparable<Node>{\n        int dist,idx;\n        \n        Node(int idx,int dist){\n            this.idx = idx;\n            this.dist = dist;\n        }\n        \n        public int compareTo(Node o) {\n            return o.dist-this.dist;\n        }\n    }\n    \n    static void removeNodes(int s,int e){\n        vis[s]=true;\n        while(s!=e){\n            vis[s] = true;\n            s = parent[s];\n        }\n        vis[s]=true;\n        return;\n    }\n    \n    static int calcdist(int s){\n        int res=0;\n        int tmp=0;\n        for(int e:adj[s]){\n            if(e!=parent[s]){\n                tmp= calcdist(e);\n                if(1+tmp>res){\n                    res = 1+tmp;\n                    back[s] = back[e];\n                }\n            }\n        }\n        \n        if(res==0) back[s]=s;\n        return dist[s] = res;\n    }\n    \n    static void dfs(int s,int p){\n        for(int e:adj[s]){\n            if(e!=p){\n                parent[e]=s;\n                dfs(e,s);\n            }\n        }\n        return;\n    }\n    \n    static void makeroot(int s){\n        Queue<Integer> q = new LinkedList<>();\n        q.add(s);\n        \n        int elm=0;\n        while(q.size()!=0){\n            elm = q.remove();\n            for(int e:adj[elm]){\n                if(!vist[e]){\n                    vist[e]=true;\n                    q.add(e);\n                    root = e;\n                }\n            }\n        }\n        return;\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}", "complexity": "nlogn", "problem": "958_B2. Maximum Control (medium)", "from": "CODEFORCES"}
{"src": "// discussed with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF915E {\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\tint n = Integer.parseInt(br.readLine());\n\t\tint q = Integer.parseInt(br.readLine());\n\t\tTreeMap<Integer, Integer> mp = new TreeMap<>();\n\t\tint ans = 0;\n\t\twhile (q-- > 0) {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tint l = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tint r = Integer.parseInt(st.nextToken());\n\t\t\tint t = Integer.parseInt(st.nextToken());\n\t\t\tMap.Entry<Integer, Integer> e;\n\t\t\tint l_, r_;\n\t\t\tif (t == 1) {\n\t\t\t\tif ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) >= l) {\n\t\t\t\t\tl_ = e.getKey();\n\t\t\t\t\tans -= r_ - l_;\n\t\t\t\t\tl = l_;\n\t\t\t\t\tr = Math.max(r, r_);\n\t\t\t\t}\n\t\t\t\twhile ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) <= r) {\n\t\t\t\t\tr_ = e.getValue();\n\t\t\t\t\tans -= r_ - l_;\n\t\t\t\t\tr = Math.max(r, r_);\n\t\t\t\t\tmp.remove(l_);\n\t\t\t\t}\n\t\t\t\tans += r - l;\n\t\t\t\tmp.put(l, r);\n\t\t\t} else {\n\t\t\t\tr_ = l;\n\t\t\t\tif ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) > l) {\n\t\t\t\t\tl_ = e.getKey();\n\t\t\t\t\tif (l_ < l)\n\t\t\t\t\t\tmp.put(l_, l);\n\t\t\t\t\telse\n\t\t\t\t\t\tmp.remove(l_);\n\t\t\t\t\tans -= r_ - l;\n\t\t\t\t}\n\t\t\t\twhile ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) < r) {\n\t\t\t\t\tr_ = e.getValue();\n\t\t\t\t\tmp.remove(l_);\n\t\t\t\t\tans -= r_ - l_;\n\t\t\t\t}\n\t\t\t\tif (r_ > r) {\n\t\t\t\t\tmp.put(r, r_);\n\t\t\t\t\tans += r_ - r;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(n - ans);\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "nlogn", "problem": "915_E. Physical Education Lessons", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.ListIterator;\nimport java.util.Collection;\nimport java.util.AbstractList;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Deque;\nimport java.util.ArrayDeque;\nimport java.util.NoSuchElementException;\nimport java.util.ConcurrentModificationException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author cunbidun\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        DPairOfLines solver = new DPairOfLines();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DPairOfLines {\n        private static final int INF = (int) 2e9 + 7;\n        private InputReader in;\n        private PrintWriter out;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            int n = in.nextInt();\n            if (n <= 4) {\n                out.println(\"YES\");\n                return;\n            }\n            TreeList<PairII> list = new TreeList<>();\n            PairII[] a = new PairII[n + 1];\n            for (int i = 1; i <= n; i++) {\n                a[i] = (new PairII(in.nextInt(), in.nextInt()));\n                list.add(a[i]);\n            }\n            PairII pos1 = new PairII(INF, INF);\n            PairII pos2 = new PairII(INF, INF);\n            for (int i = 1; i <= 5; i++) {\n                for (int j = i + 1; j <= 5; j++) {\n                    for (int k = j + 1; k <= 5; k++) {\n                        int x1 = a[i].first;\n                        int y1 = a[i].second;\n                        int x2 = a[j].first;\n                        int y2 = a[j].second;\n                        int x = a[k].first;\n                        int y = a[k].second;\n                        long s = (long) (y2 - y1) * x + (long) (x1 - x2) * y + ((long) x2 * y1 - (long) x1 * y2);\n                        if (s == 0) {\n                            pos1 = a[i];\n                            pos2 = a[j];\n                        }\n                    }\n                }\n            }\n\n            if (pos1.equals(new PairII(INF, INF))) {\n                out.println(\"NO\");\n                return;\n            }\n            int x1 = pos1.first;\n            int y1 = pos1.second;\n            int x2 = pos2.first;\n            int y2 = pos2.second;\n            for (int i = 0; i < list.size(); i++) {\n                int x = list.get(i).first;\n                int y = list.get(i).second;\n                long s = (long) (y2 - y1) * x + (long) (x1 - x2) * y + ((long) x2 * y1 - (long) x1 * y2);\n                if (s == 0) {\n                    list.remove(i);\n                    i--;\n                }\n            }\n            if (list.size() <= 2) {\n                out.println(\"YES\");\n                return;\n            }\n            x1 = list.get(0).first;\n            y1 = list.get(0).second;\n            x2 = list.get(1).first;\n            y2 = list.get(1).second;\n            for (int i = 0; i < list.size(); i++) {\n                int x = list.get(i).first;\n                int y = list.get(i).second;\n                long s = (long) (y2 - y1) * x + (long) (x1 - x2) * y + ((long) x2 * y1 - (long) x1 * y2);\n                if (s == 0) {\n                    list.remove(i);\n                    i--;\n                }\n            }\n            if (list.size() == 0) {\n                out.println(\"YES\");\n            } else out.println(\"NO\");\n        }\n\n    }\n\n    static interface OrderedIterator<E> extends Iterator<E> {\n    }\n\n    static class PairII implements Comparable<PairII> {\n        public int first;\n        public int second;\n\n        public PairII(int 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            PairII pair = (PairII) o;\n\n            return first == pair.first && second == pair.second;\n        }\n\n        public String toString() {\n            return \"(\" + first + \",\" + second + \")\";\n        }\n\n        public int compareTo(PairII o) {\n            int value = Integer.compare(first, o.first);\n            if (value != 0) {\n                return value;\n            }\n            return Integer.compare(second, o.second);\n        }\n\n    }\n\n    static class TreeList<E> extends AbstractList<E> {\n        private TreeList.AVLNode<E> root;\n        private int size;\n\n        public TreeList() {\n            super();\n        }\n\n        public TreeList(final Collection<? extends E> coll) {\n            super();\n            if (!coll.isEmpty()) {\n                root = new TreeList.AVLNode<>(coll);\n                size = coll.size();\n            }\n        }\n\n        public E get(final int index) {\n            return root.get(index).getValue();\n        }\n\n        public int size() {\n            return size;\n        }\n\n        public Iterator<E> iterator() {\n            // override to go 75% faster\n            return listIterator(0);\n        }\n\n        public ListIterator<E> listIterator() {\n            // override to go 75% faster\n            return listIterator(0);\n        }\n\n        public ListIterator<E> listIterator(final int fromIndex) {\n            return new TreeList.TreeListIterator<>(this, fromIndex);\n        }\n\n        public int indexOf(final Object object) {\n            // override to go 75% faster\n            if (root == null) {\n                return -1;\n            }\n            return root.indexOf(object, root.relativePosition);\n        }\n\n        public boolean contains(final Object object) {\n            return indexOf(object) >= 0;\n        }\n\n        public Object[] toArray() {\n            final Object[] array = new Object[size()];\n            if (root != null) {\n                root.toArray(array, root.relativePosition);\n            }\n            return array;\n        }\n\n        public void add(final int index, final E obj) {\n            modCount++;\n            if (root == null) {\n                root = new TreeList.AVLNode<>(index, obj, null, null);\n            } else {\n                root = root.insert(index, obj);\n            }\n            size++;\n        }\n\n        public boolean addAll(final Collection<? extends E> c) {\n            if (c.isEmpty()) {\n                return false;\n            }\n            modCount += c.size();\n            final TreeList.AVLNode<E> cTree = new TreeList.AVLNode<>(c);\n            root = root == null ? cTree : root.addAll(cTree, size);\n            size += c.size();\n            return true;\n        }\n\n        public E set(final int index, final E obj) {\n            final TreeList.AVLNode<E> node = root.get(index);\n            final E result = node.value;\n            node.setValue(obj);\n            return result;\n        }\n\n        public E remove(final int index) {\n            modCount++;\n            final E result = get(index);\n            root = root.remove(index);\n            size--;\n            return result;\n        }\n\n        public void clear() {\n            modCount++;\n            root = null;\n            size = 0;\n        }\n\n        static class AVLNode<E> {\n            private TreeList.AVLNode<E> left;\n            private boolean leftIsPrevious;\n            private TreeList.AVLNode<E> right;\n            private boolean rightIsNext;\n            private int height;\n            private int relativePosition;\n            private E value;\n\n            private AVLNode(final int relativePosition, final E obj,\n                            final TreeList.AVLNode<E> rightFollower, final TreeList.AVLNode<E> leftFollower) {\n                this.relativePosition = relativePosition;\n                value = obj;\n                rightIsNext = true;\n                leftIsPrevious = true;\n                right = rightFollower;\n                left = leftFollower;\n            }\n\n            private AVLNode(final Collection<? extends E> coll) {\n                this(coll.iterator(), 0, coll.size() - 1, 0, null, null);\n            }\n\n            private AVLNode(final Iterator<? extends E> iterator, final int start, final int end,\n                            final int absolutePositionOfParent, final TreeList.AVLNode<E> prev, final TreeList.AVLNode<E> next) {\n                final int mid = start + (end - start) / 2;\n                if (start < mid) {\n                    left = new TreeList.AVLNode<>(iterator, start, mid - 1, mid, prev, this);\n                } else {\n                    leftIsPrevious = true;\n                    left = prev;\n                }\n                value = iterator.next();\n                relativePosition = mid - absolutePositionOfParent;\n                if (mid < end) {\n                    right = new TreeList.AVLNode<>(iterator, mid + 1, end, mid, this, next);\n                } else {\n                    rightIsNext = true;\n                    right = next;\n                }\n                recalcHeight();\n            }\n\n            E getValue() {\n                return value;\n            }\n\n            void setValue(final E obj) {\n                this.value = obj;\n            }\n\n            TreeList.AVLNode<E> get(final int index) {\n                final int indexRelativeToMe = index - relativePosition;\n\n                if (indexRelativeToMe == 0) {\n                    return this;\n                }\n\n                final TreeList.AVLNode<E> nextNode = indexRelativeToMe < 0 ? getLeftSubTree() : getRightSubTree();\n                if (nextNode == null) {\n                    return null;\n                }\n                return nextNode.get(indexRelativeToMe);\n            }\n\n            int indexOf(final Object object, final int index) {\n                if (getLeftSubTree() != null) {\n                    final int result = left.indexOf(object, index + left.relativePosition);\n                    if (result != -1) {\n                        return result;\n                    }\n                }\n                if (value == null ? value == object : value.equals(object)) {\n                    return index;\n                }\n                if (getRightSubTree() != null) {\n                    return right.indexOf(object, index + right.relativePosition);\n                }\n                return -1;\n            }\n\n            void toArray(final Object[] array, final int index) {\n                array[index] = value;\n                if (getLeftSubTree() != null) {\n                    left.toArray(array, index + left.relativePosition);\n                }\n                if (getRightSubTree() != null) {\n                    right.toArray(array, index + right.relativePosition);\n                }\n            }\n\n            TreeList.AVLNode<E> next() {\n                if (rightIsNext || right == null) {\n                    return right;\n                }\n                return right.min();\n            }\n\n            TreeList.AVLNode<E> previous() {\n                if (leftIsPrevious || left == null) {\n                    return left;\n                }\n                return left.max();\n            }\n\n            TreeList.AVLNode<E> insert(final int index, final E obj) {\n                final int indexRelativeToMe = index - relativePosition;\n\n                if (indexRelativeToMe <= 0) {\n                    return insertOnLeft(indexRelativeToMe, obj);\n                }\n                return insertOnRight(indexRelativeToMe, obj);\n            }\n\n            private TreeList.AVLNode<E> insertOnLeft(final int indexRelativeToMe, final E obj) {\n                if (getLeftSubTree() == null) {\n                    setLeft(new TreeList.AVLNode<>(-1, obj, this, left), null);\n                } else {\n                    setLeft(left.insert(indexRelativeToMe, obj), null);\n                }\n\n                if (relativePosition >= 0) {\n                    relativePosition++;\n                }\n                final TreeList.AVLNode<E> ret = balance();\n                recalcHeight();\n                return ret;\n            }\n\n            private TreeList.AVLNode<E> insertOnRight(final int indexRelativeToMe, final E obj) {\n                if (getRightSubTree() == null) {\n                    setRight(new TreeList.AVLNode<>(+1, obj, right, this), null);\n                } else {\n                    setRight(right.insert(indexRelativeToMe, obj), null);\n                }\n                if (relativePosition < 0) {\n                    relativePosition--;\n                }\n                final TreeList.AVLNode<E> ret = balance();\n                recalcHeight();\n                return ret;\n            }\n\n            private TreeList.AVLNode<E> getLeftSubTree() {\n                return leftIsPrevious ? null : left;\n            }\n\n            private TreeList.AVLNode<E> getRightSubTree() {\n                return rightIsNext ? null : right;\n            }\n\n            private TreeList.AVLNode<E> max() {\n                return getRightSubTree() == null ? this : right.max();\n            }\n\n            private TreeList.AVLNode<E> min() {\n                return getLeftSubTree() == null ? this : left.min();\n            }\n\n            TreeList.AVLNode<E> remove(final int index) {\n                final int indexRelativeToMe = index - relativePosition;\n\n                if (indexRelativeToMe == 0) {\n                    return removeSelf();\n                }\n                if (indexRelativeToMe > 0) {\n                    setRight(right.remove(indexRelativeToMe), right.right);\n                    if (relativePosition < 0) {\n                        relativePosition++;\n                    }\n                } else {\n                    setLeft(left.remove(indexRelativeToMe), left.left);\n                    if (relativePosition > 0) {\n                        relativePosition--;\n                    }\n                }\n                recalcHeight();\n                return balance();\n            }\n\n            private TreeList.AVLNode<E> removeMax() {\n                if (getRightSubTree() == null) {\n                    return removeSelf();\n                }\n                setRight(right.removeMax(), right.right);\n                if (relativePosition < 0) {\n                    relativePosition++;\n                }\n                recalcHeight();\n                return balance();\n            }\n\n            private TreeList.AVLNode<E> removeMin() {\n                if (getLeftSubTree() == null) {\n                    return removeSelf();\n                }\n                setLeft(left.removeMin(), left.left);\n                if (relativePosition > 0) {\n                    relativePosition--;\n                }\n                recalcHeight();\n                return balance();\n            }\n\n            private TreeList.AVLNode<E> removeSelf() {\n                if (getRightSubTree() == null && getLeftSubTree() == null) {\n                    return null;\n                }\n                if (getRightSubTree() == null) {\n                    if (relativePosition > 0) {\n                        left.relativePosition += relativePosition;\n                    }\n                    left.max().setRight(null, right);\n                    return left;\n                }\n                if (getLeftSubTree() == null) {\n                    right.relativePosition += relativePosition - (relativePosition < 0 ? 0 : 1);\n                    right.min().setLeft(null, left);\n                    return right;\n                }\n\n                if (heightRightMinusLeft() > 0) {\n                    // more on the right, so delete from the right\n                    final TreeList.AVLNode<E> rightMin = right.min();\n                    value = rightMin.value;\n                    if (leftIsPrevious) {\n                        left = rightMin.left;\n                    }\n                    right = right.removeMin();\n                    if (relativePosition < 0) {\n                        relativePosition++;\n                    }\n                } else {\n                    // more on the left or equal, so delete from the left\n                    final TreeList.AVLNode<E> leftMax = left.max();\n                    value = leftMax.value;\n                    if (rightIsNext) {\n                        right = leftMax.right;\n                    }\n                    final TreeList.AVLNode<E> leftPrevious = left.left;\n                    left = left.removeMax();\n                    if (left == null) {\n                        // special case where left that was deleted was a double link\n                        // only occurs when height difference is equal\n                        left = leftPrevious;\n                        leftIsPrevious = true;\n                    }\n                    if (relativePosition > 0) {\n                        relativePosition--;\n                    }\n                }\n                recalcHeight();\n                return this;\n            }\n\n            private TreeList.AVLNode<E> balance() {\n                switch (heightRightMinusLeft()) {\n                    case 1:\n                    case 0:\n                    case -1:\n                        return this;\n                    case -2:\n                        if (left.heightRightMinusLeft() > 0) {\n                            setLeft(left.rotateLeft(), null);\n                        }\n                        return rotateRight();\n                    case 2:\n                        if (right.heightRightMinusLeft() < 0) {\n                            setRight(right.rotateRight(), null);\n                        }\n                        return rotateLeft();\n                    default:\n                        throw new RuntimeException(\"tree inconsistent!\");\n                }\n            }\n\n            private int getOffset(final TreeList.AVLNode<E> node) {\n                if (node == null) {\n                    return 0;\n                }\n                return node.relativePosition;\n            }\n\n            private int setOffset(final TreeList.AVLNode<E> node, final int newOffest) {\n                if (node == null) {\n                    return 0;\n                }\n                final int oldOffset = getOffset(node);\n                node.relativePosition = newOffest;\n                return oldOffset;\n            }\n\n            private void recalcHeight() {\n                height = Math.max(\n                        getLeftSubTree() == null ? -1 : getLeftSubTree().height,\n                        getRightSubTree() == null ? -1 : getRightSubTree().height) + 1;\n            }\n\n            private int getHeight(final TreeList.AVLNode<E> node) {\n                return node == null ? -1 : node.height;\n            }\n\n            private int heightRightMinusLeft() {\n                return getHeight(getRightSubTree()) - getHeight(getLeftSubTree());\n            }\n\n            private TreeList.AVLNode<E> rotateLeft() {\n                final TreeList.AVLNode<E> newTop = right; // can't be faedelung!\n                final TreeList.AVLNode<E> movedNode = getRightSubTree().getLeftSubTree();\n\n                final int newTopPosition = relativePosition + getOffset(newTop);\n                final int myNewPosition = -newTop.relativePosition;\n                final int movedPosition = getOffset(newTop) + getOffset(movedNode);\n\n                setRight(movedNode, newTop);\n                newTop.setLeft(this, null);\n\n                setOffset(newTop, newTopPosition);\n                setOffset(this, myNewPosition);\n                setOffset(movedNode, movedPosition);\n                return newTop;\n            }\n\n            private TreeList.AVLNode<E> rotateRight() {\n                final TreeList.AVLNode<E> newTop = left;\n                final TreeList.AVLNode<E> movedNode = getLeftSubTree().getRightSubTree();\n\n                final int newTopPosition = relativePosition + getOffset(newTop);\n                final int myNewPosition = -newTop.relativePosition;\n                final int movedPosition = getOffset(newTop) + getOffset(movedNode);\n\n                setLeft(movedNode, newTop);\n                newTop.setRight(this, null);\n\n                setOffset(newTop, newTopPosition);\n                setOffset(this, myNewPosition);\n                setOffset(movedNode, movedPosition);\n                return newTop;\n            }\n\n            private void setLeft(final TreeList.AVLNode<E> node, final TreeList.AVLNode<E> previous) {\n                leftIsPrevious = node == null;\n                left = leftIsPrevious ? previous : node;\n                recalcHeight();\n            }\n\n            private void setRight(final TreeList.AVLNode<E> node, final TreeList.AVLNode<E> next) {\n                rightIsNext = node == null;\n                right = rightIsNext ? next : node;\n                recalcHeight();\n            }\n\n            private TreeList.AVLNode<E> addAll(TreeList.AVLNode<E> otherTree, final int currentSize) {\n                final TreeList.AVLNode<E> maxNode = max();\n                final TreeList.AVLNode<E> otherTreeMin = otherTree.min();\n\n                // We need to efficiently merge the two AVL trees while keeping them\n                // balanced (or nearly balanced). To do this, we take the shorter\n                // tree and combine it with a similar-height subtree of the taller\n                // tree. There are two symmetric cases:\n                //   * this tree is taller, or\n                //   * otherTree is taller.\n                if (otherTree.height > height) {\n                    // CASE 1: The other tree is taller than this one. We will thus\n                    // merge this tree into otherTree.\n\n                    // STEP 1: Remove the maximum element from this tree.\n                    final TreeList.AVLNode<E> leftSubTree = removeMax();\n\n                    // STEP 2: Navigate left from the root of otherTree until we\n                    // contains a subtree, s, that is no taller than me. (While we are\n                    // navigating left, we store the nodes we encounter in a stack\n                    // so that we can re-balance them in step 4.)\n                    final Deque<TreeList.AVLNode<E>> sAncestors = new ArrayDeque<>();\n                    TreeList.AVLNode<E> s = otherTree;\n                    int sAbsolutePosition = s.relativePosition + currentSize;\n                    int sParentAbsolutePosition = 0;\n                    while (s != null && s.height > getHeight(leftSubTree)) {\n                        sParentAbsolutePosition = sAbsolutePosition;\n                        sAncestors.push(s);\n                        s = s.left;\n                        if (s != null) {\n                            sAbsolutePosition += s.relativePosition;\n                        }\n                    }\n\n                    // STEP 3: Replace s with a newly constructed subtree whose root\n                    // is maxNode, whose left subtree is leftSubTree, and whose right\n                    // subtree is s.\n                    maxNode.setLeft(leftSubTree, null);\n                    maxNode.setRight(s, otherTreeMin);\n                    if (leftSubTree != null) {\n                        leftSubTree.max().setRight(null, maxNode);\n                        leftSubTree.relativePosition -= currentSize - 1;\n                    }\n                    if (s != null) {\n                        s.min().setLeft(null, maxNode);\n                        s.relativePosition = sAbsolutePosition - currentSize + 1;\n                    }\n                    maxNode.relativePosition = currentSize - 1 - sParentAbsolutePosition;\n                    otherTree.relativePosition += currentSize;\n\n                    // STEP 4: Re-balance the tree and recalculate the heights of s's ancestors.\n                    s = maxNode;\n                    while (!sAncestors.isEmpty()) {\n                        final TreeList.AVLNode<E> sAncestor = sAncestors.pop();\n                        sAncestor.setLeft(s, null);\n                        s = sAncestor.balance();\n                    }\n                    return s;\n                }\n                otherTree = otherTree.removeMin();\n\n                final Deque<TreeList.AVLNode<E>> sAncestors = new ArrayDeque<>();\n                TreeList.AVLNode<E> s = this;\n                int sAbsolutePosition = s.relativePosition;\n                int sParentAbsolutePosition = 0;\n                while (s != null && s.height > getHeight(otherTree)) {\n                    sParentAbsolutePosition = sAbsolutePosition;\n                    sAncestors.push(s);\n                    s = s.right;\n                    if (s != null) {\n                        sAbsolutePosition += s.relativePosition;\n                    }\n                }\n\n                otherTreeMin.setRight(otherTree, null);\n                otherTreeMin.setLeft(s, maxNode);\n                if (otherTree != null) {\n                    otherTree.min().setLeft(null, otherTreeMin);\n                    otherTree.relativePosition++;\n                }\n                if (s != null) {\n                    s.max().setRight(null, otherTreeMin);\n                    s.relativePosition = sAbsolutePosition - currentSize;\n                }\n                otherTreeMin.relativePosition = currentSize - sParentAbsolutePosition;\n\n                s = otherTreeMin;\n                while (!sAncestors.isEmpty()) {\n                    final TreeList.AVLNode<E> sAncestor = sAncestors.pop();\n                    sAncestor.setRight(s, null);\n                    s = sAncestor.balance();\n                }\n                return s;\n            }\n\n        }\n\n        static class TreeListIterator<E> implements ListIterator<E>, OrderedIterator<E> {\n            private final TreeList<E> parent;\n            private TreeList.AVLNode<E> next;\n            private int nextIndex;\n            private TreeList.AVLNode<E> current;\n            private int currentIndex;\n            private int expectedModCount;\n\n            private TreeListIterator(final TreeList<E> parent, final int fromIndex) throws IndexOutOfBoundsException {\n                super();\n                this.parent = parent;\n                this.expectedModCount = parent.modCount;\n                this.next = parent.root == null ? null : parent.root.get(fromIndex);\n                this.nextIndex = fromIndex;\n                this.currentIndex = -1;\n            }\n\n            private void checkModCount() {\n                if (parent.modCount != expectedModCount) {\n                    throw new ConcurrentModificationException();\n                }\n            }\n\n            public boolean hasNext() {\n                return nextIndex < parent.size();\n            }\n\n            public E next() {\n                checkModCount();\n                if (!hasNext()) {\n                    throw new NoSuchElementException(\"No element at index \" + nextIndex + \".\");\n                }\n                if (next == null) {\n                    next = parent.root.get(nextIndex);\n                }\n                final E value = next.getValue();\n                current = next;\n                currentIndex = nextIndex++;\n                next = next.next();\n                return value;\n            }\n\n            public boolean hasPrevious() {\n                return nextIndex > 0;\n            }\n\n            public E previous() {\n                checkModCount();\n                if (!hasPrevious()) {\n                    throw new NoSuchElementException(\"Already at start of list.\");\n                }\n                if (next == null) {\n                    next = parent.root.get(nextIndex - 1);\n                } else {\n                    next = next.previous();\n                }\n                final E value = next.getValue();\n                current = next;\n                currentIndex = --nextIndex;\n                return value;\n            }\n\n            public int nextIndex() {\n                return nextIndex;\n            }\n\n            public int previousIndex() {\n                return nextIndex() - 1;\n            }\n\n            public void remove() {\n                checkModCount();\n                if (currentIndex == -1) {\n                    throw new IllegalStateException();\n                }\n                parent.remove(currentIndex);\n                if (nextIndex != currentIndex) {\n                    // remove() following next()\n                    nextIndex--;\n                }\n                // the AVL node referenced by next may have become stale after a remove\n                // reset it now: will be retrieved by next call to next()/previous() via nextIndex\n                next = null;\n                current = null;\n                currentIndex = -1;\n                expectedModCount++;\n            }\n\n            public void set(final E obj) {\n                checkModCount();\n                if (current == null) {\n                    throw new IllegalStateException();\n                }\n                current.setValue(obj);\n            }\n\n            public void add(final E obj) {\n                checkModCount();\n                parent.add(nextIndex, obj);\n                current = null;\n                currentIndex = -1;\n                nextIndex++;\n                expectedModCount++;\n            }\n\n        }\n\n    }\n\n    static class InputReader extends InputStream {\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 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                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        private static boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "961_D. Pair Of Lines", "from": "CODEFORCES"}
{"src": "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            long x=Long.parseLong(s1[1]);\n            long y=Long.parseLong(s1[2]);\n            long S=0;\n            long mod=1000000007;\n            B a[]=new B[n];\n            TreeMap<Long,Long> tm=new TreeMap<Long,Long>();\n            long ans[]=new long[n];\n            for(int i=0;i<n;i++)\n            {\n              String s2[]=br.readLine().split(\" \");\n              long l=Long.parseLong(s2[0]);\n              long r=Long.parseLong(s2[1]);\n              B b1=new B(l,r);\n              a[i]=b1;\n            }\n            Arrays.sort(a,new The_Comp());\n            \n            for(int i=0;i<n;i++)\n            {\n                  long l=a[i].x;\n                  long r=a[i].y;\n                  if(tm.floorKey(l-1)!=null)\n                  {\n                        long u=tm.floorKey(l-1);\n                        long v=l;\n                        if((v-u)*y<x)\n                        { ans[i]=((r-u)*y)%mod; \n                          if(tm.get(u)>1)\n                           tm.put(u,tm.get(u)-1);\n                          else\n                          tm.remove(u); \n                        }\n                        else\n                        { ans[i]=(x+(r-l)*y)%mod; }\n                  }\n                  else\n                   ans[i]=(x+(r-l)*y)%mod;\n                  S=(S+ans[i])%mod;\n                  if(tm.containsKey(r))\n                   tm.put(r,1+tm.get(r));\n                  else\n                   tm.put(r,(long)1);\n            }\n            System.out.println(S);\n      }\n}\n\n\nclass The_Comp implements Comparator<B>\n{\n      public int compare(B b1,B b2)\n      {\n            if(b1.x>b2.x)\n             return 1;\n            else if(b1.x==b2.x)\n            {\n            if(b1.y>b2.y)\n             return 1;\n            else if(b1.y==b2.y)\n             return 0;\n            else\n             return -1;\n            }\n            else\n             return -1;\n      }\n}\nclass B\n{\n      long x=(long)1;\n      long y=(long)1;\n      public B(long l1,long l2)\n      { x=l1;  y=l2; }\n}", "complexity": "nlogn", "problem": "1061_D. TV Shows", "from": "CODEFORCES"}
{"src": "import org.omg.PortableServer.AdapterActivator;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.net.CookieHandler;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.util.concurrent.LinkedBlockingDeque;\n\nimport static java.lang.Math.*;\n\npublic class TaskA implements Runnable {\n    long m = (int)1e9+7;\n    PrintWriter w;\n    InputReader c;\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n        int n = c.nextInt();\n        int a[] = scanArrayI(n);\n        int maxtime = Integer.MAX_VALUE,ind = -1;\n        for(int i=0;i<n;i++){\n            int time = Integer.MAX_VALUE;\n            if(a[i]<i+1)\n                time = i;\n            else{\n                time = (int)ceil((a[i] - i)/(double)n) * n + i;\n            }\n            if(time<maxtime){\n                maxtime = time;\n                ind = i;\n            }\n        }\n        w.println(ind+1);\n        w.close();\n    }\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static void sortbyColumn(int arr[][], int col){\n        Arrays.sort(arr, new Comparator<int[]>()\n        {\n            public int compare(int[] o1, int[] o2){\n                return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    public static class DJSet {\n        public int[] upper;\n\n        public DJSet(int n) {\n            upper = new int[n];\n            Arrays.fill(upper, -1);\n        }\n\n        public int root(int x) {\n            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n        }\n\n        public boolean equiv(int x, int y) {\n            return root(x) == root(y);\n        }\n\n        public boolean union(int x, int y) {\n            x = root(x);\n            y = root(y);\n            if (x != y) {\n                if (upper[y] < upper[x]) {\n                    int d = x;\n                    x = y;\n                    y = d;\n                }\n                upper[x] += upper[y];\n                upper[y] = x;\n            }\n            return x == y;\n        }\n    }\n    public static int[] radixSort(int[] f)    {\n        int[] to = new int[f.length];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n            int[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n    public void printArray(int[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n){\n        int a[] = new int[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n){\n        long a[] = new long[n];\n        for(int i=0;i<n;i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a){\n        for(int i=0;i<a.length;i++)\n            w.print(a[i]+\" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars==-1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                }\n                catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        public int nextInt() {\n            int c = read();\n\n            while(isSpaceChar(c))\n                c = read();\n\n            int sgn = 1;\n\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n\n            int res = 0;\n            do {\n                if(c<'0'||c>'9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            }\n            while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskA(),\"TaskA\",1<<26).start();\n    }\n}", "complexity": "nlogn", "problem": "996_B. World Cup", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tComp c1 = getComp(scanner);\n\t\tComp c2 = getComp(scanner);\n\t\tc1.sortByPrice();\n\t\tc2.sortByPrice();\t\n\t\tint i = 0;\n\t\tint j = 0;\n\t\twhile(i < c1.num || j < c2.num) {\n\t\t\tElem xi = (i < c1.num) ? c1.elems.get(i) : null;\n\t\t\tElem yj = (j < c2.num) ? c2.elems.get(j) : null;\n\t\t\tif(xi != null && yj != null) {\n\t\t\t\tif(xi.price >= yj.price) {\n\t\t\t\t\tif(!c2.resultSet.contains(xi)) {\n\t\t\t\t\t\tc1.resultSet.add(xi);\n\t\t\t\t\t}\n\t\t\t\t\ti++;\n\t\t\t\t} else {\n\t\t\t\t\tif(!c1.resultSet.contains(yj)) {\n\t\t\t\t\t\tc2.resultSet.add(yj);\n\t\t\t\t\t}\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t} else\n\t\t\tif(xi != null) {\n\t\t\t\tif(!c2.resultSet.contains(xi)) {\n\t\t\t\t\tc1.resultSet.add(xi);\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t} else {\n\t\t\t\tif(!c1.resultSet.contains(yj)) {\n\t\t\t\t\tc2.resultSet.add(yj);\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\t\t\t\t\n\t\t}\n\t\t\n\t\tlong result = c1.getResultPrice() + c2.getResultPrice();\n\t\tSystem.out.println(result);\n   }\n   \n   private static Comp getComp(Scanner scanner) {\n\t   Comp c = new Comp();\n\t   c.num = scanner.nextInt();\n\t   for(int i = 0; i < c.num; i++) {\n\t\t   c.addElem(scanner.nextLong(), scanner.nextLong());\n\t   }\n\t   return c;\n   }\n}\n\nclass Comp {\n\tint num;\n\tList<Elem> elems = new ArrayList<>();\n\tSet<Elem> resultSet = new HashSet<>();\n\t\n\tvoid addElem(long el, long pr) {\n\t\tElem elem = new Elem(el, pr);\n\t\telems.add(elem);\n\t}\n\t\n\tvoid sortByPrice() {\n\t\tCollections.sort(elems);\n\t}\n\t\n\tlong getResultPrice() {\n\t\tlong sumPrice = 0;\n\t\tfor(Elem elem : resultSet) {\n\t\t\tsumPrice += elem.price;\n\t\t}\n\t\t\n\t\treturn sumPrice;\n\t}\n}\n\nclass Elem implements Comparable<Elem> {\n\tlong elem;\n\tlong price;\n\t\n\tpublic Elem(long el, long pr) {\n\t\tthis.elem = el;\n\t\tthis.price = pr;\n\t}\n\t\n\tpublic int compareTo(Elem other) {\n\t\treturn (int) (other.price - price);\n\t}\n\t\n\tpublic boolean equals(Object o) {\n\t\tif(!(o instanceof Elem)) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tElem other = (Elem) o;\n\t\treturn (other.elem == elem);\n\t}\n\t\n\tpublic int hashCode() {\n\t\treturn (int) elem;\n\t}\n\t\n\tpublic String toString() {\n\t\treturn \"(\" + elem + \", \" + price + \")\";\n\t}\n}\n", "complexity": "nlogn", "problem": "981_B. Businessmen Problems", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\n\npublic class Div1_526C {\n\n\tstatic int nV;\n\n\tstatic ArrayList<Integer>[] chldn;\n\n\tstatic int root;\n\n\tstatic int[][] anc;\n\tstatic int[] depth;\n\n\tstatic int[] num;\n\n\tstatic int[] nLoc;\n\n\tstatic int[][] tree;\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\tnV = Integer.parseInt(reader.readLine());\n\n\t\tchldn = new ArrayList[nV];\n\t\tfor (int i = 0; i < nV; i++) {\n\t\t\tchldn[i] = new ArrayList<>();\n\t\t}\n\n\t\tanc = new int[nV][21];\n\t\tdepth = new int[nV];\n\n\t\tnum = new int[nV];\n\t\tnLoc = new int[nV];\n\t\ttree = new int[nV * 4][2];\n\t\tfor (int[] a : tree) {\n\t\t\ta[0] = a[1] = -1;\n\t\t}\n\n\t\troot = 0;\n\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 0; i < nV; i++) {\n\t\t\tnum[i] = Integer.parseInt(inputData.nextToken());\n\t\t\tnLoc[num[i]] = i;\n\t\t}\n\n\t\tinputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 1; i < nV; i++) {\n\t\t\tanc[i][0] = Integer.parseInt(inputData.nextToken()) - 1;\n\t\t\tchldn[anc[i][0]].add(i);\n\t\t}\n\n\t\tpreprocess();\n\n\t\tbuild(1, 0, nV - 1);\n\n\t\tint nQ = Integer.parseInt(reader.readLine());\n\n\t\twhile (nQ-- > 0) {\n\t\t\tinputData = new StringTokenizer(reader.readLine());\n\t\t\tif (inputData.nextToken().equals(\"1\")) {\n\t\t\t\tint a = Integer.parseInt(inputData.nextToken()) - 1;\n\t\t\t\tint b = Integer.parseInt(inputData.nextToken()) - 1;\n\n\t\t\t\tint temp = num[a];\n\t\t\t\tnum[a] = num[b];\n\t\t\t\tnum[b] = temp;\n\n\t\t\t\tnLoc[num[a]] = a;\n\t\t\t\tnLoc[num[b]] = b;\n\n\t\t\t\tupdate(1, 0, nV - 1, num[a]);\n\t\t\t\tupdate(1, 0, nV - 1, num[b]);\n\t\t\t} else {\n\t\t\t\tprinter.println(query(1, 0, nV - 1, nLoc[0], nLoc[0]) + 1);\n\t\t\t}\n\t\t}\n\t\tprinter.close();\n\t}\n\n\tstatic void build(int nI, int cL, int cR) {\n\t\tif (cL == cR) {\n\t\t\ttree[nI][0] = nLoc[cL];\n\t\t\ttree[nI][1] = nLoc[cL];\n\t\t} else {\n\t\t\tint mid = (cL + cR) >> 1;\n\t\t\tbuild(nI * 2, cL, mid);\n\t\t\tbuild(nI * 2 + 1, mid + 1, cR);\n\t\t\tif (tree[nI * 2][0] != -1 && tree[nI * 2 + 1][0] != -1) {\n\t\t\t\tmerge(tree[nI * 2][0], tree[nI * 2][1], tree[nI * 2 + 1][0], tree[nI * 2 + 1][1]);\n\t\t\t\ttree[nI][0] = mResp[0];\n\t\t\t\ttree[nI][1] = mResp[1];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int query(int nI, int cL, int cR, int e1, int e2) {\n\t\tif (cL == cR) {\n\t\t\tmerge(e1, e2, nLoc[cL], nLoc[cL]);\n\t\t\tif (mResp[0] != -1) {\n\t\t\t\treturn cL;\n\t\t\t} else {\n\t\t\t\treturn cL - 1;\n\t\t\t}\n\t\t}\n\t\tint mid = (cL + cR) >> 1;\n\n\t\tmerge(tree[nI * 2][0], tree[nI * 2][1], e1, e2);\n\t\tif (mResp[0] != -1) {\n\t\t\treturn query(nI * 2 + 1, mid + 1, cR, mResp[0], mResp[1]);\n\t\t}\n\t\treturn query(nI * 2, cL, mid, e1, e2);\n\t}\n\n\tstatic void update(int nI, int cL, int cR, int uI) {\n\t\tif (cL == cR) {\n\t\t\ttree[nI][0] = nLoc[cL];\n\t\t\ttree[nI][1] = nLoc[cL];\n\t\t} else {\n\t\t\tint mid = (cL + cR) >> 1;\n\t\t\tif (uI <= mid) {\n\t\t\t\tupdate(nI * 2, cL, mid, uI);\n\t\t\t} else {\n\t\t\t\tupdate(nI * 2 + 1, mid + 1, cR, uI);\n\t\t\t}\n\t\t\tmerge(tree[nI * 2][0], tree[nI * 2][1], tree[nI * 2 + 1][0], tree[nI * 2 + 1][1]);\n\t\t\ttree[nI][0] = mResp[0];\n\t\t\ttree[nI][1] = mResp[1];\n\t\t}\n\t}\n\n\tstatic int[] mResp = new int[2];\n\n\tstatic void merge1(int... a) {\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tif (a[i] == -1) {\n\t\t\t\tmResp[0] = mResp[1] = -1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif (onPath(a[0], a[1], a[2])) {\n\t\t\tmResp[0] = a[0];\n\t\t\tmResp[1] = a[1];\n\t\t\treturn;\n\t\t}\n\t\tif (onPath(a[0], a[2], a[1])) {\n\t\t\tmResp[0] = a[0];\n\t\t\tmResp[1] = a[2];\n\t\t\treturn;\n\t\t}\n\t\tif (onPath(a[1], a[2], a[0])) {\n\t\t\tmResp[0] = a[1];\n\t\t\tmResp[1] = a[2];\n\t\t\treturn;\n\t\t}\n\t\tmResp[0] = mResp[1] = -1;\n\t}\n\n\tstatic void merge(int... a) {\n\t\tmerge1(a[0], a[1], a[2]);\n\t\tmerge1(mResp[0], mResp[1], a[3]);\n\t}\n\n\tstatic boolean onPath(int a, int b, int c) {\n\t\tif (a == c || b == c) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (depth[a] > depth[c]) {\n\t\t\ta = jump(a, depth[a] - depth[c] - 1);\n\t\t}\n\t\tif (depth[b] > depth[c]) {\n\t\t\tb = jump(b, depth[b] - depth[c] - 1);\n\t\t}\n\t\tif (a == b) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (anc[a][0] == c || anc[b][0] == c) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t// good for depth of up to 1_048_576 = 2^20\n\n\tstatic void preprocess() {\n\t\tanc[root][0] = root;\n\t\tfParent(root);\n\n\t\tfor (int k = 1; k <= 20; k++) {\n\t\t\tfor (int i = 0; i < nV; i++) {\n\t\t\t\tanc[i][k] = anc[anc[i][k - 1]][k - 1];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void fParent(int cV) {\n\t\tfor (int aV : chldn[cV]) {\n\t\t\tanc[aV][0] = cV;\n\t\t\tdepth[aV] = depth[cV] + 1;\n\t\t\tfParent(aV);\n\t\t}\n\t}\n\n\tstatic int fLCA(int a, int b) {\n\t\tif (depth[a] > depth[b]) {\n\t\t\tint temp = b;\n\t\t\tb = a;\n\t\t\ta = temp;\n\t\t}\n\t\tb = jump(b, depth[b] - depth[a]);\n\t\tif (a == b) {\n\t\t\treturn a;\n\t\t}\n\t\tfor (int i = 20; i >= 0; i--) {\n\t\t\tif (anc[a][i] != anc[b][i]) {\n\t\t\t\ta = anc[a][i];\n\t\t\t\tb = anc[b][i];\n\t\t\t}\n\t\t}\n\t\treturn anc[a][0];\n\t}\n\n\tstatic int jump(int cV, int d) {\n\t\tfor (int i = 0; i <= 20; i++) {\n\t\t\tif ((d & (1 << i)) != 0) {\n\t\t\t\tcV = anc[cV][i];\n\t\t\t}\n\t\t}\n\t\treturn cV;\n\t}\n\n\tstatic Comparator<Integer> BY_DEPTH = new Comparator<Integer>() {\n\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\treturn -Integer.compare(depth[o1], depth[o2]); // greatest depth first\n\t\t}\n\t};\n}", "complexity": "nlogn", "problem": "1084_F. Max Mex", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Vector;\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        int m = sc.nextInt();\n        int a[] = new int[n];\n        int b[] = new int[n];\n        for (int i = 0; i < n; i++) a[i] = sc.nextInt();\n        for (int i = 0; i < n; i++) b[i] = sc.nextInt();\n        int c[] = new int[2 * n];\n        c[0] = a[0];\n        for (int i = 1; i < n; i++) {\n            c[i * 2] = a[i];\n            c[i * 2 - 1] = b[i];\n            if (a[i] == 1 || b[i] == 1) {\n                System.out.print(-1);\n                System.exit(0);\n            }\n        }\n        c[2 * n - 1] = b[0];\n        if (a[0] == 1 || b[0] == 1) {\n            System.out.print(-1);\n            System.exit(0);\n        }\n        System.out.println(bin_search(c, m));\n    }\n\n    private static double bin_search(int[] c, int m) {\n        double start = 0;\n        double end = Integer.MAX_VALUE;\n        double mid;\n        while (start + 0.0000001 < end) {\n            mid = (start + end) / 2;\n            if (test(mid, m, c)) end = mid;\n            else start = mid;\n        }\n        return end;\n    }\n\n    private static boolean test(double fuel, int m, int[] c) {\n        for (int i = 0; i < c.length; i++) {\n            fuel -= (m + fuel) / c[i];\n            if (fuel < 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n", "complexity": "nlogn", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Vector;\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        int m = sc.nextInt();\n        int a[] = new int[n];\n        int b[] = new int[n];\n        for (int i = 0; i < n; i++) a[i] = sc.nextInt();\n        for (int i = 0; i < n; i++) b[i] = sc.nextInt();\n        int c[] = new int[2 * n];\n        c[0] = a[0];\n        for (int i = 1; i < n; i++) {\n            c[i * 2] = a[i];\n            c[i * 2 - 1] = b[i];\n            if (a[i] == 1 || b[i] == 1) {\n                System.out.print(-1);\n                System.exit(0);\n            }\n        }\n        c[2 * n - 1] = b[0];\n        if (a[0] == 1 || b[0] == 1) {\n            System.out.print(-1);\n            System.exit(0);\n        }\n        System.out.println(bin_search(c, m));\n    }\n\n    private static double bin_search(int[] c, int m) {\n        double start = 0;\n        double end = Integer.MAX_VALUE;\n        double mid;\n        while (start + 0.0000001 < end) {\n            mid = (start + end) / 2;\n            if (test(mid, m, c)) end = mid;\n            else start = mid;\n        }\n        return end;\n    }\n\n    private static boolean test(double fuel, int m, int[] c) {\n        for (int i = 0; i < c.length; i++) {\n            fuel -= (m + fuel) / c[i];\n            if (fuel < 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n", "complexity": "nlogn", "problem": "1010_A. Fly", "from": "CODEFORCES"}
{"src": "import com.sun.org.apache.xpath.internal.operations.Bool;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        MyScanner scan = new MyScanner();\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n\n        int n = scan.nextInt();\n        int[] vals = new int[n];\n        for (int i = 0; i < n; i++) {\n            vals[i] = scan.nextInt();\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (solve(i, vals)) {\n                out.print('A');\n            } else {\n                out.print('B');\n            }\n        }\n\n        out.close();\n    }\n\n    static HashMap<Integer, Boolean> dpResult = new HashMap<>();\n\n    private static boolean solve(int pos, int[] vals) {\n        if (dpResult.containsKey(pos)) return dpResult.get(pos);\n        int val = vals[pos];\n        boolean hasLose = false;\n        for (int i = pos; i < vals.length; i += val) {\n            if (i == pos) continue;\n            if (vals[i] <= vals[pos]) continue;\n            if (hasLose) break;\n            if (!solve(i, vals)) {\n                hasLose = true;\n            }\n        }\n        for (int i = pos; i >= 0; i -= val) {\n            if (i == pos) continue;\n            if (vals[i] <= vals[pos]) continue;\n            if (hasLose) break;\n            if (!solve(i, vals)) {\n                hasLose = true;\n            }\n        }\n        dpResult.put(pos, hasLose);\n        return hasLose;\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}", "complexity": "nlogn", "problem": "1033_C. Permutation Game", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashMap;\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\tint n = scan.nextInt();\n\t\tlong[] a = scan.nextLongArray(n);\n\t\tBigInteger res = BigInteger.ZERO;\n\t\tfor (int i = n-1; i >= 0; i--) res = res.add(BigInteger.valueOf(i*a[i] - (n-1-i)*a[i]));\n\t\tHashMap<Long, Long> map = new HashMap<>();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tres = res.subtract(BigInteger.valueOf(map.getOrDefault(a[i]-1, 0L)));\n\t\t\tres = res.add(BigInteger.valueOf(map.getOrDefault(a[i]+1, 0L)));\n\t\t\tmap.put(a[i], map.getOrDefault(a[i], 0L)+1);\n\t\t}\n\t\tout.println(res);\n\t\tout.close();\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}\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class ProblemE\n{\n\n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    \n    static class SegmentTree {\n        long st[];\n \n        SegmentTree(int n)  {\n            st = new long[4*n];\n            build(0, n - 1, 1);\n        }\n        \n        int getMid(int s, int e) {\n            return (s+e)>>1;\n        }\n\n        long merge(long a,long b){\n            return a+b;\n        }\n        \n        void update(int s, int e, int x, int y, long c, int si){\n            if(s == x && e == y){\n                st[si] += c;\n            }\n            else{\n                int mid = getMid(s, e);\n                if(y <= mid)    \n                    update(s, mid, x, y, c, 2*si);\n                else if(x > mid)\n                    update(mid + 1, e, x ,y ,c ,2*si + 1);\n                else{\n                    update(s, mid, x, mid, c, 2*si);\n                    update(mid + 1, e, mid + 1, y, c, 2*si + 1);\n                }\n                st[si] = merge(st[2*si],st[2*si+1]);\n            }\n        }\n\n        long  get(int s, int e, int x, int y, int si){\n\n            if(s == x && e == y){\n                return st[si];\n            }\n            int mid = getMid(s, e);\n            if(y <= mid)\n                return get(s, mid, x, y, 2*si);\n            else if(x > mid)\n                return get(mid + 1, e, x, y, 2*si + 1);\n            return merge(get(s, mid, x, mid, 2*si), get(mid + 1, e, mid + 1, y, 2*si + 1));\n        }\n\n        void build(int ss, int se, int si){\n            if (ss == se) {\n                st[si] = 0;\n                return;\n            }\n\n            int mid = getMid(ss, se);\n            build(ss, mid, si * 2 );\n            build(mid + 1, se, si * 2 + 1);\n            st[si] = merge(st[2*si],st[2*si+1]);\n        }\n        \n    }\n\n    \n    public static void main(String[] args) throws FileNotFoundException\n    {\n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out);            \n        \n        int n = in.nextInt();\n        int[] arr = in.nextIntArray(n);\n        ArrayList<Integer>list = new ArrayList<>();\n        HashMap<Integer,Integer> map = new HashMap<>();\n        \n        for(int i = 0; i < n; i++){\n            list.add(arr[i]);\n            list.add(arr[i] + 1);\n            list.add(arr[i] - 1);\n        }\n        Collections.sort(list);\n        int j = 1;\n        for(int k : list){\n            if(map.containsKey(k)) continue;\n            map.put(k, j++);\n        }\n        \n        SegmentTree seg = new SegmentTree(j + 1);\n        SegmentTree seg1 = new SegmentTree(j + 1);\n        BigInteger ans = BigInteger.ZERO;\n        BigInteger sum = BigInteger.ZERO;\n//        long ans = 0;\n//        long sum = 0;\n        for(int i = 0; i < n; i++){\n            long x = seg.get(0, j - 1, map.get(arr[i] - 1), map.get(arr[i] + 1), 1);\n            long y = seg1.get(0, j - 1, map.get(arr[i] - 1), map.get(arr[i] + 1), 1);\n            ans = ans.add(new BigInteger(\"\"+x));\n            ans = ans.subtract(sum);\n            ans = ans.add(new BigInteger(\"\"+((arr[i] * 1l *(i - y)))));\n//              ans += arr[i] * 1l * (i - y) - sum + x;\n            \n            seg.update(0, j - 1, map.get(arr[i]), map.get(arr[i]), arr[i], 1);\n            seg1.update(0, j - 1, map.get(arr[i]), map.get(arr[i]), 1, 1);\n            sum = sum.add(new BigInteger(arr[i] + \"\"));\n        }\n        \n        out.println(ans);\n        out.close();\n    }\n\n    static class Pair implements Comparable<Pair>\n    {\n\n        int x,y;\n        int i;\n        \n        Pair (int x,int y)\n        {\n                this.x = x;\n                this.y = y;\n        }\n\n        Pair (int x,int y, int i)\n        {\n                this.x = x;\n                this.y = y;\n                this.i = i;\n        }\n\n        public int compareTo(Pair o)\n        {\n            return Long.compare(this.i,o.i);\n                //return 0;\n        }\n\n        public boolean equals(Object o)\n        {\n            if (o instanceof Pair)\n            {\n                Pair p = (Pair)o;\n                return p.x == x && p.y==y;\n            }\n            return false;\n        }\n\n        @Override\n        public String toString()\n        {\n            return x + \" \"+ y + \" \"+i;\n        }\n\n        /*public int hashCode()\n        {\n            return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n        }*/\n\n    } \n\n    static long gcd(long x,long y)\n    {\n        if(y==0)\n                return x;\n        else\n                return gcd(y,x%y);\n    }\n\n    static int gcd(int x,int y)\n    {\n        if(y==0)\n                return x;\n        else \n                return gcd(y,x%y);\n    }\n\n    static long pow(long n,long p,long m)\n    {\n         long  result = 1;\n          if(p==0){\n            return n;\n          }\n          \n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\n            if(result >= m)\n               result %= m;\n            p >>=1;\n            n*=n;\n            if(n >= m)\n                n%=m;\n        }\n        \n        return result;\n    }\n\n    static long pow(long n,long p)\n    {\n        long  result = 1;\n          if(p==0)\n            return 1;\n\n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\t    \n            p >>=1;\n            n*=n;\t    \n        }\n        return result;\n    }\n\n    static void debug(Object... o)\n    {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "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.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.Collections;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class D {\n\t\n\tpublic static class BIT {\n\t\tlong[] dat;\n\t\t\n\t\tpublic BIT(int n){\n\t\t\tdat = new long[n + 1];\n\t\t}\n\t\t\n\t\tpublic void add(int k, long a){ // k : 0-indexed\n\t\t\tfor(int i = k + 1; i < dat.length; i += i & -i){\n\t\t\t\tdat[i] += a;\t\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic long sum(int s, int t){ // [s, t)\n\t\t\tif(s > 0) return sum(0, t) - sum(0, s);\n\t\t\t\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = t; i > 0; i -= i & -i) {\n\t\t\t\tret += dat[i];\n\t\t\t}\n\t\t\treturn ret;\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 int n = sc.nextInt();\n\t\t\t\n\t\t\tlong[] array = new long[n];\n\t\t\tfor(int i = 0; i < n; i++){ array[i] = sc.nextLong(); }\n\t\t\t\n\t\t\tTreeSet<Long> value_set = new TreeSet<Long>();\n\t\t\tfor(int i = 0; i < n; i++){ value_set.add(array[i]); }\n\t\t\tArrayList<Long> value_list = new ArrayList<Long>(value_set);\n\t\t\t\n\t\t\tBigInteger answer = BigInteger.ZERO;\n\t\t\tfinal int bit_n = value_list.size();\n\t\t\tBIT cnt_bit = new BIT(bit_n);\n\t\t\tBIT val_bit = new BIT(bit_n);\n\t\t\t\n\t\t\tfor(int i = n - 1; i >= 0; i--){\n\t\t\t\tfinal long value = array[i];\n\t\t\t\tfinal int value_index = Collections.binarySearch(value_list, value);\n\t\t\t\t\n\t\t\t\tint upper_pos = Collections.binarySearch(value_list, value + 2);\n\t\t\t\tif(upper_pos < 0){ upper_pos = (-upper_pos) - 1; }\n\t\t\t\tif(0 <= upper_pos && upper_pos < bit_n){\n\t\t\t\t\tfinal long upper_sum = val_bit.sum(upper_pos, bit_n) - cnt_bit.sum(upper_pos, bit_n) * value;\n\t\t\t\t\tanswer = answer.add(BigInteger.valueOf(upper_sum));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint lower_pos = Collections.binarySearch(value_list, value - 2);\n\t\t\t\tif(lower_pos < 0){ lower_pos = (-lower_pos) - 2; }\n\t\t\t\tif(0 <= lower_pos && lower_pos < bit_n){\n\t\t\t\t\tfinal long lower_sum = val_bit.sum(0, lower_pos + 1) - cnt_bit.sum(0, lower_pos + 1) * value;\n\t\t\t\t\tanswer = answer.add(BigInteger.valueOf(lower_sum));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tcnt_bit.add(value_index, 1);\n\t\t\t\tval_bit.add(value_index, value);\n\t\t\t\t//System.out.println(answer);\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(answer);\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", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Main {\n    protected static final double EPS = 1e-11;\n    private static StreamTokenizer in;\n    private static Scanner ins;\n    private static PrintWriter out;\n    protected static final Double[] BAD = new Double[]{null, null};\n    private boolean[][] layouts;\n    private int c;\n    private int b;\n    private int a;\n    private String word;\n\n    public static void main(String[] args) {\n\n        try {\n            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            ins = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n            out = new PrintWriter(System.out);\n            try {\n                if (System.getProperty(\"xDx\") != null) {\n                    in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));\n                    ins = new Scanner(new FileReader(\"input.txt\"));\n                    out = new PrintWriter(new FileWriter(\"output.txt\"));\n                }\n            } catch (Exception e) {\n                in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n                ins = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n                out = new PrintWriter(System.out);\n            }\n            new Main().run();\n        } catch (Throwable e) {\n//            e.printStackTrace();\n            throw new RuntimeException(e);\n        } finally {\n            out.close();\n        }\n    }\n\n    private int nextInt() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    private long nextLong() throws IOException {\n        in.nextToken();\n        return (long) in.nval;\n    }\n\n    private double nextDouble() throws IOException {\n        in.nextToken();\n        return in.nval;\n    }\n\n    private String nextString() throws IOException {\n        in.nextToken();\n        return in.sval;\n    }\n\n    private char nextChar() throws IOException {\n        in.nextToken();\n        return (char) in.ttype;\n    }\n\n    private void run() throws Exception {\n        /*int t = nextInt();\n        for (int i = 0; i < t; i++) {\n            out.printf(Locale.US, \"Case #%d: %d\\n\", i + 1, solve());\n        }*/\n        solve();\n    }\n\n    private void solve() 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        }\n\n        Map<Long, Integer> map = new HashMap<>();\n\n        BigInteger res = BigInteger.ZERO;\n        long sum = 0;\n        long amount = 0;\n\n        for (int i = n - 1; i >= 0; i--) {\n            long cur = a[i];\n            Pair same = getZeroAmount(cur, map);\n\n            res = res.add(BigInteger.valueOf((sum - same.sum) - cur * (amount - same.amount)));\n            amount++;\n            sum += cur;\n            map.put(cur, map.getOrDefault(cur, 0) + 1);\n        }\n\n        out.println(res);\n    }\n\n    class Pair {\n        long amount;\n        long sum;\n\n        public Pair(long amount, long sum) {\n            this.amount = amount;\n            this.sum = sum;\n        }\n    }\n\n    private Pair getZeroAmount(long cur, Map<Long, Integer> map) {\n        long amount = 0;\n        long sum = 0;\n        for (long i = cur - 1; i <= cur + 1; i++) {\n            long amountI = map.getOrDefault(i, 0);\n            amount += amountI;\n            sum += amountI * i;\n        }\n        return new Pair(amount, sum);\n    }\n\n    private List<Integer> iterate(List<Integer> a) {\n        ArrayList<Integer> b = new ArrayList<>();\n        int prev = -1;\n        for (int x : a) {\n            if (x == prev) {\n                b.add(x);\n            } else {\n                prev = x;\n            }\n        }\n        return b;\n    }\n\n    private long gcd(long a, long b) {\n        while (a > 0 && b > 0) {\n            long k = a % b;\n            a = b;\n            b = k;\n        }\n\n        return a | b;\n    }\n\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "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.math.BigInteger;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Liavontsi Brechka\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\n    @SuppressWarnings(\"Duplicates\")\n    class TaskD {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            long[] a = in.nextLongArray(n);\n            HashMap<Integer, Integer> count = new HashMap<>();\n\n            BigInteger res = BigInteger.ZERO;\n            long prev = 0;\n            count.put((int) a[0], 1);\n\n            long temp;\n            long nextRes;\n            for (int i = 1; i < n; i++) {\n                temp = ((a[i] - a[i - 1]) * i + prev);\n                nextRes = temp - count.getOrDefault((int) a[i] - 1, 0) + count.getOrDefault((int) a[i] + 1, 0);\n                res = res.add(new BigInteger(String.valueOf(nextRes)));\n                count.put((int) a[i], count.getOrDefault((int) a[i], 0) + 1);\n                prev = temp;\n            }\n\n            out.print(res);\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", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "//Educational Codeforces Round 34\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class TaskD {\n\n    public static void main (String[] args) throws IOException {\n        FastScanner fs = new FastScanner(System.in);\n        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n\n        int n = fs.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = fs.nextInt();\n        }\n        \n        HashMap<Integer,Integer> h = new HashMap<Integer,Integer>(n);\n\n        BigInteger s = new BigInteger(\"\"+a[0]);\n        BigInteger x = new BigInteger(\"0\");\n        h.put(a[0], 1);\n        for (int i = 1; i < n; i++) {                        \n            x = x.add(new BigInteger(\"\"+(((long)i)*((long)a[i]))));\n            x = x.subtract(s);\n            s = s.add(new BigInteger(\"\"+a[i]));\n            Integer q = null;\n            q = h.get(a[i]-1);            \n            if (q != null) {\n                x = x.subtract(new BigInteger(\"\"+q));\n            }\n            q = h.get(a[i]+1);            \n            if (q != null) {\n                x = x.add(new BigInteger(\"\"+q));\n            }\n            q = h.get(a[i]);            \n            if (q != null) {\n                h.put(a[i], q + 1);\n            } else {\n                h.put(a[i], 1);\n            }\n        }\n\n        pw.println(x);\n\n        pw.close();\n    }\n\n    static class FastScanner {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n        FastScanner(InputStream i) {\n            reader = new BufferedReader(new InputStreamReader(i));\n            tokenizer = new StringTokenizer(\"\");\n        }\n        String next() throws IOException {\n            while(!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine());\n            return tokenizer.nextToken();\n        }\n        int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n    }\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "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 CFD {\n\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n    final long MOD = 1000L * 1000L * 1000L + 7;\n    int[] dx = {0, -1, 0, 1};\n    int[] dy = {1, 0, -1, 0};\n\n\n    void solve() throws IOException {\n        int n = nextInt();\n        long[] arr = nextLongArr(n);\n        long[] diff = new long[n];\n        long presum = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            diff[i] = presum - (n - i - 1) * arr[i];\n            presum += arr[i];\n        }\n\n        BigInteger pairs = new BigInteger(\"0\");\n        for (long s : diff) {\n            pairs = pairs.add(new BigInteger(Long.toString(s)));\n        }\n\n        BigInteger need = new BigInteger(\"0\");\n        Map<Long, Long> hm = new HashMap<>();\n        for (int i = n - 1; i >= 0; i--) {\n            long v1 = hm.getOrDefault(arr[i] - 1, 0L) * (-1);\n            need = need.add(new BigInteger(Long.toString(v1)));\n            long v2 = hm.getOrDefault(arr[i] + 1, 0L);\n            need = need.add(new BigInteger(Long.toString(v2)));\n\n            hm.put(arr[i], hm.getOrDefault(arr[i], 0L) + 1);\n        }\n        BigInteger res = pairs.subtract(need);\n        out(res.toString());\n    }\n\n    void shuffle(long[] a) {\n        int n = a.length;\n        for(int i = 0; i < n; i++) {\n            int r = i + (int) (Math.random() * (n - i));\n            long tmp = a[i];\n            a[i] = a[r];\n            a[r] = tmp;\n        }\n    }\n    private void outln(Object o) {\n        out.println(o);\n    }\n    private void out(Object o) {\n        out.print(o);\n    }\n    public CFD() 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 CFD();\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", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class DD {\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();\n\t\tint [] a=new int [n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=sc.nextInt();\n\t\t\n\t\tTreeMap<Integer, Integer> map=new TreeMap<Integer, Integer>();\n\t\tBigInteger ans=new BigInteger(\"0\");\n\t\tlong sum=0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tsum+=a[i];\n\t\t\tmap.put(a[i], map.getOrDefault(a[i], 0)+1);\n\t\t\tint cntSame=map.get(a[i]);\n\t\t\tint cntLess=map.getOrDefault(a[i]-1, 0);\n\t\t\tint cntMore=map.getOrDefault(a[i]+1, 0);\n\t\t\tlong sum2=sum;\n\t\t\tsum2-=1L*cntSame*a[i];\n\t\t\tsum2-=1L*cntLess*(a[i]-1);\n\t\t\tsum2-=1L*cntMore*(a[i]+1);\n\t\t\tint cnt=i+1-(cntSame+cntLess+cntMore);\n\t\t\tans = ans.subtract(BigInteger.valueOf(sum2));\n\t\t\tans= ans.add(BigInteger.valueOf(1L*cnt*a[i]));\n\t\t\t\n\t\t}\n\t\tpw.println(ans);\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic 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() {while (st == null || !st.hasMoreElements()) {\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (IOException e) {e.printStackTrace();}}\n\t\treturn st.nextToken();}\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\tString nextLine(){String str = \"\";\n\t\ttry {str = br.readLine();}\n\t\tcatch (IOException e) {e.printStackTrace();}\n\t\treturn str;}\n\t}\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\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 D {\n\n\tstatic HashMap<Long, Integer> comp = new HashMap<Long, Integer>();\n\tstatic HashMap<Integer, Long> rev = new HashMap<Integer, Long>();\n\tstatic long freq[];\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner();\n\t\tint n = in.nextInt();\n\t\tlong a[] = new long[n];\n\t\tlong copy[] = new long[n];\n\t\tlong sum = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\ta[i] = in.nextLong();\n\t\t\tcopy[i] = a[i];\n\t\t\tsum+=a[i];\n\t\t}\n\t\tArrays.sort(copy);\n\t\tfor(int i = 0; i < n; i++)\t//Compress values to be 1-indexed\n\t\t\tif(!comp.containsKey(copy[i])){\n\t\t\t\tcomp.put(copy[i],  (comp.size()+1));\n\t\t\t\t//rev.put(comp.get(copy[i]), copy[i]);\n\t\t\t}\n\t\t\t\n\t//\tBIT bit = new BIT(n);\n\t\t\n\t\tfreq = new long[n+1];\n\t\tArrays.fill(freq, 0);\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tint v = comp.get(a[i]);\n\t\t\tfreq[v]++;\n\t\t}\n\t\t\n\t\tlong res = 0;\n\t\tBigInteger res2 = new BigInteger(\"0\");\n\t\tfor(int i = 0; i < n; i++){\t//Go through each element in the array\n\t\t\tlong x = a[i];\n\t\t\t//freq[comp.get(x)]--;\n\t\t\t//Find the amount of values equal to (x-1), x, and (x+1);\n\t\t\tlong below = getFreq(x-1);\n\t\t\tlong eq = getFreq(x);\n\t\t\tlong above = getFreq(x+1);\n\t\t\tlong other = (n-i)-below-eq-above;\n\t\t\t\n\t\t//\tSystem.out.println(\"x= \"+x+\" b:\"+below+\"  e:\"+eq+\"  a:\"+above);\n\t\t\t\n\t\t\tlong leaveOut = below*(x-1) + eq*(x) + above*(x+1);\n\t\t\tlong cur = (sum-leaveOut)-(x*other);\n\n\t//\t\tSystem.out.println(\"sum:\"+sum+\"  leave:\"+leaveOut+\"  oth:\"+other+\"   cur:\"+cur+\"\\n\");\n\t\t\tres2 = res2.add(new BigInteger(\"\"+cur));\n\t\t\tres += cur;\n\t\t\tsum -= x;\n\t\t\tfreq[comp.get(x)]--;\n\t\t\t\n\t\t}\n\t\tSystem.out.println(res2);\n\t}\n\t\n\tstatic long getFreq(long n){\n\t\tif(!comp.containsKey(n)) return 0;\n\t\telse return freq[comp.get(n)];\n\t}\n\t\n\t\n\t\n\n\tstatic class FastScanner{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(String s) {\n\t\t\ttry{\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t}\n\t\t\tcatch(FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\tpublic FastScanner(){\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\n\t\tString nextToken()\t{\n\t\t\twhile(st == null ||!st.hasMoreElements()){\n\t\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\t\t\t\n\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(nextToken());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t\tString next() {\n\t\t\treturn nextToken();\n\t\t}\n\t\t\n\t}\n\t\n\t\n}\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class D {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\t\n\t\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tHashMap<Long, Integer> map = new HashMap();\n\t\tBigInteger sum = BigInteger.ZERO;\n\t\tBigInteger ans = BigInteger.valueOf(0);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong x = in.nextLong();\n\t\t\tans = ans.add(BigInteger.valueOf(i * x));\n\t\t\tif (map.containsKey(x + 1)) {\n\t\t\t\tans = ans.add(BigInteger.valueOf(map.get(x + 1)));\n\t\t\t}\n\t\t\tif (map.containsKey(x - 1)) {\n\t\t\t\tans = ans.subtract(BigInteger.valueOf(map.get(x - 1)));\n\t\t\t}\n\t\t\tif (map.containsKey(x)) {\n\t\t\t\tmap.put(x, map.get(x) + 1);\n\t\t\t} else {\n\t\t\t\tmap.put(x, 1);\n\t\t\t}\n\t\t\tans = ans.subtract(sum);\n\t\t\tsum = sum.add(BigInteger.valueOf(x));\n\t\t}\n\t\tout.print(ans.toString());\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(\"segments.in\"));\n\t\t\t\tout = new PrintWriter(new File(\"segments.out\"));\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 D().run();\n\t}\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "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 n = nextInt();\n    \tPair[] ps = new Pair[n];\n    \tfor (int i = 0; i < n; i++) {\n    \t\tps[i] = new Pair(nextInt(), i + 1);\n    \t}\n    \tsort(ps, new Comparator<Pair>() {\n    \t\tpublic int compare(Pair a, Pair b) {\n    \t\t\treturn a.x - b.x;\n    \t\t}\n    \t});\n    \tBigInteger res = find(ps, n);\n    \tfor (int i = 0; i * 2 < n; i++) {\n    \t\tPair t = ps[i];\n    \t\tps[i] = ps[n - i - 1];\n    \t\tps[n - i - 1] = t;\n    \t}\n    \tres = res.add(find(ps, n));\n    \tout.println(res);\n    }\n    \n    BigInteger find(Pair[] ps, int n) {\n    \tBigInteger res = ZERO;\n    \tint i = 0;\n    \tFenwickTree ft = new FenwickTree(n + 1);\n    \tboolean[] added = new boolean[n + 1];\n    \tfor (int j = 0; j < n; j++) {\n    \t\tif (abs(ps[j].x - ps[i].x) <= 1) continue;\n    \t\twhile (abs(ps[j].x - ps[i].x) > 1) {\n    \t\t\tif (!added[ps[i].i]) ft.add(ps[i].i, 1);\n    \t\t\tadded[ps[i].i] = true;\n    \t\t\ti++;\n    \t\t}\n    \t\ti--;\n    \t\tlong total = ft.sum(n);\n    \t\tlong left = ft.sum(ps[j].i - 1);\n    \t\tlong right = total - left;\n    \t\tres = res.add(valueOf(ps[j].x).multiply(valueOf(left)));\n    \t\tres = res.add(valueOf(-ps[j].x).multiply(valueOf(right)));\n    \t}\n    \treturn res;\n    }\n    \n    class Pair implements Comparable<Pair> {\n    \tint x, i;\n    \t\n    \tPair(int x, int i) {\n    \t\tthis.x = x;\n    \t\tthis.i = i;\n    \t}\n    \t\n    \tpublic int compareTo(Pair p) {\n    \t\treturn x - p.x;\n    \t}\n    \t\n    \tpublic String toString() {\n    \t\treturn \"(\" + x + \", \" + i + \")\";\n    \t}\n    }\n    \n    class FenwickTree {\n    \tint n;\n    \tint[] tree;\n    \t\t\t\n    \tpublic FenwickTree(int n) {\n    \t\tthis.n = n;\n    \t\ttree = new int[n];\n    \t}\n    \t\t\t\n    \tpublic int sum(int id) {\n    \t\tint res = 0;\n    \t\twhile (id > 0) {\n    \t\t\tres += tree[id];\n    \t\t\tid -= id & -id;\n    \t\t}\n    \t\treturn res;\n    \t}\n    \t\t\t\n    \tpublic void add(int id, int v) {\n    \t\twhile (id < n) {\n    \t\t\ttree[id] += v;\n    \t\t\tid += id & -id;\n    \t\t}\n    \t}\n\n    \tint findkth(int k) {\n    \t\tint low = 1, high = n;\n    \t\twhile (low < high) {\n    \t\t\tint mid = (low + high) / 2;\n    \t\t\tint val = sum(mid);\n    \t\t\tif(val < k) low = mid + 1;\n    \t\t\telse high = mid;\n    \t\t}\n    \t\treturn low;\n    \t}\n    }\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        //out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.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}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class main\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\tprivate PrintWriter pw;\n\tprivate long mod = 1000000000 + 7;\n\n\tprivate StringBuilder ans_sb;\n\tprivate ArrayList<Integer> primes;\n\tprivate long ans;\n\n\tprivate void soln()\n\t{\n\t\tint n = nextInt();\n\t\tlong[] arr = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = nextLong();\n\t\tSegment tree = new Segment(n, arr);\n\t\tlong[] ans = new long[n];\n\t\tBigInteger fa = BigInteger.ZERO;\n\t\tHashMap<Long, Integer> map = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tans[i] = ((long) i + 1) * arr[i] - tree.query(0, i);\n\t\t\tif (map.containsKey(arr[i] - 1))\n\t\t\t{\n\t\t\t\tlong tmp = map.get(arr[i] - 1);\n\t\t\t\tans[i] -= tmp;\n\t\t\t}\n\t\t\tif (map.containsKey(arr[i] + 1))\n\t\t\t{\n\t\t\t\tlong tmp = map.get(arr[i] + 1);\n\t\t\t\tans[i] += tmp;\n\t\t\t}\n\n\t\t\tif (!map.containsKey(arr[i]))\n\t\t\t\tmap.put(arr[i], 0);\n\t\t\tmap.put(arr[i], map.get(arr[i]) + 1);\n\t\t\tfa = fa.add(new BigInteger(Long.toString(ans[i])));\n\t\t}\n\t\t// debug(ans);\n\t\t/*\n\t\t * Node[] nn = new Node[n]; for(int i=0;i<n;i++) { nn[i] = new Node();\n\t\t * nn[i].node = i; nn[i].dist = arr[i]; } //debug(fa); Arrays.sort(nn);\n\t\t * //debug(nn); for(int i=0;i<n-1;i++) { if(nn[i].dist + 1 == nn[i+1].dist) {\n\t\t * System.out.println(nn[i].node +\" \"+nn[i+1].node); if(nn[i].node >\n\t\t * nn[i+1].node) { fa++; }else fa--; } }\n\t\t */\n\t\tpw.println(fa.toString());\n\t\t// int k = nextInt();\n\t\t// int n = nextInt();\n\t\t// String[] arr = new String[k];\n\t\t// for(int i=0;i<k;i++)\n\t\t// arr[i] = nextLine();\n\t\t// HashSet<String> set1 = new HashSet<>();\n\t\t// for(int i=0;i<k;i++)\n\t\t// set1.add(arr[i]);\n\t\t// if(set1.size() == 1) {\n\t\t// String s = arr[0];\n\t\t// pw.print(s.charAt(1));\n\t\t// pw.print(s.charAt(0));\n\t\t// for(int i=2;i<n;i++)\n\t\t// pw.print(s.charAt(i));\n\t\t// }else {\n\t\t// String s1 = arr[0];\n\t\t// set1.remove(arr[0]);\n\t\t// HashSet<Integer>[] aa = new HashSet[set1.size()];\n\t\t// ArrayList<String> set = new ArrayList<>();\n\t\t// for(String s:set1)\n\t\t// set.add(s);\n\t\t// int k1 = 0;\n\t\t// boolean f1 = false;\n\t\t// for(String s:set) {\n\t\t// aa[k1] = new HashSet<>();\n\t\t// for(int i=0;i<n;i++)\n\t\t// if(s1.charAt(i) != s.charAt(i))\n\t\t// aa[k1].add(i);\n\t\t// if(aa[k1].size() > 4) {\n\t\t// pw.println(-1);\n\t\t// f1 = true;\n\t\t// }\n\t\t// k1++;\n\t\t// }\n\t\t// //debug(set);\n\t\t// char[] ch = s1.toCharArray();\n\t\t//\n\t\t// boolean[] f11 = new boolean[set.size()];\n\t\t// int k2 = 0;\n\t\t// for(String s:set) {\n\t\t// int[] freq = new int[26];\n\t\t// for(int i=0;i<n;i++)\n\t\t// freq[s.charAt(i)-'a']++;\n\t\t// boolean kuu = false;\n\t\t// for(int i=0;i<26;i++)\n\t\t// if(freq[i] >= 2) {\n\t\t// kuu = true;\n\t\t// break;\n\t\t// }\n\t\t// f11[k2] = true;\n\t\t// k2++;\n\t\t// }\n\t\t// // debug(f11);\n\t\t//\n\t\t// for(int i=0;i<n;i++) {\n\t\t// if(f1)\n\t\t// break;\n\t\t// for(int j=i+1;j<n;j++) {\n\t\t// if(f1)\n\t\t// break;\n\t\t// //System.out.println(i+\" \"+j);\n\t\t// char tmp = ch[i];\n\t\t// ch[i] = ch[j];\n\t\t// ch[j] = tmp;\n\t\t// k1 = 0;\n\t\t// HashSet<Integer> haha = new HashSet<>();\n\t\t// boolean f = true;\n\t\t// for(String s:set) {\n\t\t// HashSet<Integer> indi = aa[k1];\n\t\t// boolean h1 = false;\n\t\t// boolean h2 = false;\n\t\t// if(!indi.contains(i)) {\n\t\t// indi.add(i);\n\t\t// h1 = true;\n\t\t// }\n\t\t// if(!indi.contains(j)) {\n\t\t// indi.add(j);\n\t\t// h2 = true;\n\t\t// }\n\t\t// int cnt = 0;\n\t\t// for(int ii:indi) {\n\t\t// if(s.charAt(ii) != ch[ii])\n\t\t// cnt++;\n\t\t// }\n\t\t// /*if(i==1 && j==3) {\n\t\t// System.out.println(cnt+\" \"+i+\" \"+j+\" \"+s);\n\t\t// debug(indi);\n\t\t// }*/\n\t\t// if(cnt > 2 ) {\n\t\t// f = false;\n\t\t// break;\n\t\t// }\n\t\t// if(cnt ==1 && !f11[k1]) {\n\t\t// f = false;\n\t\t// break;\n\t\t// }\n\t\t// if(h1)\n\t\t// indi.remove(i);\n\t\t// if(h2)\n\t\t// indi.remove(j);\n\t\t// k1++;\n\t\t//\n\t\t// }\n\t\t// if(f) {\n\t\t// for(int i1=0;i1<n;i1++) {\n\t\t// pw.print(ch[i1]);\n\t\t// }\n\t\t// f1 = true;\n\t\t// break;\n\t\t// }\n\t\t// tmp = ch[i];\n\t\t// ch[i] = ch[j];\n\t\t// ch[j] = tmp;\n\t\t// }\n\t\t// }\n\t\t// if(!f1)\n\t\t// pw.println(-1);\n\t\t// }\n\t}\n\n\tpublic class Segment\n\t{\n\t\tprivate Node[] tree;\n\t\tprivate boolean[] lazy;\n\t\tprivate int size;\n\t\tprivate int n;\n\t\tprivate long[] base;\n\n\t\tprivate class Node\n\t\t{\n\t\t\tprivate int l;\n\t\t\tprivate int r;\n\t\t\tprivate long ans;\n\t\t\tprivate long ans2;\n\t\t}\n\n\t\tpublic Segment(int n, long[] arr)\n\t\t{\n\t\t\tthis.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 Node[size];\n\t\t\tlazy = new boolean[size];\n\t\t\tthis.n = n;\n\t\t\t// this.set = set1;\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{\n\t\t\tif (l == r)\n\t\t\t{\n\t\t\t\ttree[id] = new Node();\n\t\t\t\ttree[id].l = l;\n\t\t\t\ttree[id].r = r;\n\t\t\t\ttree[id].ans = base[l];\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] = merge(tree[2 * id + 1], tree[2 * id + 2], l, r);\n\t\t\t// System.out.println(l+\" \"+r+\" \"+tree[id].l+\" \"+tree[id].r+\" \"+tree[id].ans);\n\t\t}\n\n\t\tpublic Node merge(Node n1, Node n2, int l, int r)\n\t\t{\n\t\t\tNode ret = new Node();\n\t\t\tif (n1 == null && n2 == null)\n\t\t\t\treturn null;\n\t\t\telse if (n1 == null)\n\t\t\t{\n\t\t\t\tret.ans = n2.ans;\n\t\t\t}\n\n\t\t\telse if (n2 == null)\n\t\t\t{\n\t\t\t\tret.ans = n1.ans;\n\t\t\t} else\n\t\t\t{\n\n\t\t\t\tret.ans = n1.ans + n2.ans;\n\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long query(int l, int r)\n\t\t{\n\t\t\tNode ret = queryUtil(l, r, 0, 0, n - 1);\n\t\t\tif (ret == null)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t} else\n\t\t\t\treturn ret.ans;\n\t\t}\n\n\t\tprivate Node queryUtil(int x, int y, int id, int l, int r)\n\t\t{\n\t\t\tif (l > y || x > r)\n\t\t\t\treturn null;\n\t\t\tif (x <= l && r <= y)\n\t\t\t{\n\t\t\t\treturn tree[id];\n\t\t\t}\n\t\t\tint mid = l + (r - l) / 2;\n\t\t\t// shift(id);\n\t\t\tNode q1 = queryUtil(x, y, 2 * id + 1, l, mid);\n\t\t\tNode q2 = queryUtil(x, y, 2 * id + 2, mid + 1, r);\n\n\t\t\treturn merge(q1, q2, Math.max(l, x), Math.min(r, y));\n\t\t}\n\n\t\tpublic void update(int x, int y, int c)\n\t\t{\n\t\t\tupdate1(x, y, c, 0, 0, n - 1);\n\t\t}\n\n\t\tprivate void update1(int x, int y, int colour, int id, int l, int r)\n\t\t{\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\t\t\t{\n\t\t\t\tif (colour != -1)\n\t\t\t\t{\n\t\t\t\t\ttree[id] = new Node();\n\t\t\t\t\ttree[id].ans = 1;\n\t\t\t\t} else\n\t\t\t\t\ttree[id] = null;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = l + (r - l) / 2;\n\t\t\t// shift(id);\n\t\t\tif (y <= mid)\n\t\t\t\tupdate1(x, y, colour, 2 * id + 1, l, mid);\n\t\t\telse if (x > mid)\n\t\t\t\tupdate1(x, y, colour, 2 * id + 2, mid + 1, r);\n\t\t\telse\n\t\t\t{\n\t\t\t\tupdate1(x, y, colour, 2 * id + 1, l, mid);\n\t\t\t\tupdate1(x, y, colour, 2 * id + 2, mid + 1, r);\n\t\t\t}\n\t\t\ttree[id] = merge(tree[2 * id + 1], tree[2 * id + 2], l, r);\n\n\t\t}\n\n\t\tpublic void print(int l, int r, int id)\n\t\t{\n\t\t\tif (l == r)\n\t\t\t{\n\t\t\t\tif (tree[id] != null)\n\t\t\t\t\tSystem.out.println(l + \" \" + r + \" \" + tree[id].l + \" \" + tree[id].r + \" \" + tree[id].ans + \" \"\n\t\t\t\t\t\t\t+ tree[id].ans2);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = l + (r - l) / 2;\n\t\t\tprint(l, mid, 2 * id + 1);\n\t\t\tprint(mid + 1, r, 2 * id + 2);\n\t\t\tif (tree[id] != null)\n\t\t\t\tSystem.out.println(\n\t\t\t\t\t\tl + \" \" + r + \" \" + tree[id].l + \" \" + tree[id].r + \" \" + tree[id].ans + \" \" + tree[id].ans2);\n\t\t}\n\n\t\tpublic void shift(int id)\n\t\t{\n\n\t\t}\n\t}\n\n\tprivate class Node implements Comparable<Node>\n\t{\n\t\tint node;\n\t\tlong dist;\n\n\t\t@Override\n\t\tpublic int compareTo(Node arg0)\n\t\t{\n\t\t\tif (this.dist != arg0.dist)\n\t\t\t\treturn (int) (this.dist - arg0.dist);\n\t\t\treturn this.node - arg0.node;\n\t\t}\n\n\t\tpublic boolean equals(Object o)\n\t\t{\n\t\t\tif (o instanceof Node)\n\t\t\t{\n\t\t\t\tNode c = (Node) o;\n\t\t\t\treturn this.node == c.node && this.dist == c.dist;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.node + \", \" + this.dist;\n\t\t}\n\t}\n\n\tprivate void debug(Object... o)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tprivate long pow(long a, long b, long c)\n\t{\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 long gcd(long n, long l)\n\t{\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{\n\t\tnew Thread(null, new Runnable()\n\t\t{\n\t\t\t@Override\n\t\t\tpublic void run()\n\t\t\t{\n\t\t\t\tnew main().solve();\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t}\n\n\tpublic StringBuilder solve()\n\t{\n\t\tInputReader(System.in);\n\t\t/*\n\t\t * try { InputReader(new FileInputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\in.txt\"));\n\t\t * } catch(FileNotFoundException e) {}\n\t\t */\n\t\tpw = new PrintWriter(System.out);\n\t\tans_sb = new StringBuilder();\n\t\tsoln();\n\n\t\tpw.close();\n\t\t// System.out.println(ans_sb);\n\t\treturn ans_sb;\n\t}\n\n\tpublic void InputReader(InputStream stream1)\n\t{\n\t\tstream = stream1;\n\t}\n\n\tprivate boolean isWhitespace(int c)\n\t{\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tprivate boolean isEndOfLine(int c)\n\t{\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n\n\tprivate int read()\n\t{\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\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} catch (IOException e)\n\t\t\t{\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 int nextInt()\n\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{\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\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} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate long nextLong()\n\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{\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\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 String nextToken()\n\t{\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} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate String nextLine()\n\t{\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} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate int[] nextIntArray(int n)\n\t{\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tarr[i] = nextInt();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate long[] nextLongArray(int n)\n\t{\n\t\tlong[] arr = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tarr[i] = nextLong();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate void pArray(int[] arr)\n\t{\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t{\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate void pArray(long[] arr)\n\t{\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t{\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate boolean isSpaceChar(int c)\n\t{\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tprivate char nextChar()\n\t{\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{\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class D implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new D(), \"_cf\", 1 << 28).start();}\n\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"Go!\");\n\t\t\n\t\tint n = fs.nextInt();\n\t\tPair[] a = new Pair[n], b = new Pair[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ta[i] = new Pair(fs.nextInt(), i+1);\n\t\t\tb[i] = new Pair(a[i].val, a[i].id);\n\t\t}\n\t\tArrays.sort(a);\n\t\t\n\t\tFenwick_Tree ft = new Fenwick_Tree(n), ftFreq = new Fenwick_Tree(n);\n\t\tBigInteger res = BigInteger.ZERO;\n\t\tint[] update = new int[n];\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < n; i++) {\n//\t\t\tSystem.out.println(sum + \" \" + a[i].val);\n\t\t\tif(i + 1 == n || (i + 1 < n && a[i+1].val != a[i].val)) {\n\t\t\t\tupdate[i] = sum+1;\n\t\t\t\tsum = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsum++;\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(Arrays.toString(update));\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint pos = a[i].id;\n\t\t\tlong val = a[i].val;\n\t\t\tlong right = ft.sum(n) - ft.sum(pos);\n\t\t\tlong freq = ftFreq.sum(n) - ftFreq.sum(pos);\n\t\t\t\n//\t\t\tSystem.out.println(a[i].val + \" \" + a[i].id + \" \" + right + \" \" + freq);\n\t\t\t\n\t\t\tres = add(res, right - (val * freq));\n//\t\t\tres += right - (val * freq);\n\t\t\t\n\t\t\tlong left = ft.sum(pos);\n\t\t\tfreq = ftFreq.sum(pos);\n\t\t\tres = add(res, (val * freq) - left);\n//\t\t\tres += (val * freq) - left;\n\t\t\t\n//\t\t\tSystem.out.println(a[i].val + \" \" + a[i].id + \" \" + left + \" \" + freq);\n//\t\t\tSystem.out.println();\n\t\t\t\n\t\t\tif(update[i] > 0) {\n\t\t\t\tft.update(pos, val);\n\t\t\t\tftFreq.update(pos, 1);\n\t\t\t\tint ptr = i-1;\n\t\t\t\twhile(ptr >= 0 && update[ptr] == 0) {\n\t\t\t\t\tft.update(a[ptr].id, val);\n\t\t\t\t\tftFreq.update(a[ptr].id, 1);\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tHashMap<Integer, Integer> freq = new HashMap<>();\n\t\tfor(int i = n-1; i >= 0; i--) {\n\t\t\tif(!freq.containsKey(b[i].val+1)) {\n\t\t\t\tif(!freq.containsKey(b[i].val)) freq.put(b[i].val, 0);\n\t\t\t\tfreq.put(b[i].val, freq.get(b[i].val)+1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong fr = freq.get(b[i].val+1);\n//\t\t\tSystem.out.println(i + \" \" + b[i].val + \" \" + fr);\n\t\t\tres = sub(res, fr * (b[i].val+1) - (fr * (b[i].val)));\n//\t\t\tres -= (fr*(b[i].val+1)) - (fr*b[i].val);\n\t\t\tif(!freq.containsKey(b[i].val)) freq.put(b[i].val, 0);\n\t\t\tfreq.put(b[i].val, freq.get(b[i].val)+1);\n \t\t}\n\t\t\n//\t\tSystem.out.println(res);\n\t\tfreq.clear();\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(!freq.containsKey(b[i].val+1)) {\n\t\t\t\tif(!freq.containsKey(b[i].val)) freq.put(b[i].val, 0);\n\t\t\t\tfreq.put(b[i].val, freq.get(b[i].val)+1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong fr = freq.get(b[i].val+1);\n//\t\t\tSystem.out.println(i + \" \" + b[i].val + \" \" + fr);\n\t\t\tres = add(res, (fr*(b[i].val+1)) - (fr*b[i].val));\n//\t\t\tres += (fr*(b[i].val+1)) - (fr*b[i].val);\n\t\t\tif(!freq.containsKey(b[i].val)) freq.put(b[i].val, 0);\n\t\t\tfreq.put(b[i].val, freq.get(b[i].val)+1);\n \t\t}\n\t\t\n\t\tout.println(res);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tBigInteger add (BigInteger a, long b) {\n\t\tBigInteger res = a.add(BigInteger.valueOf(b));\n\t\treturn res;\n\t}\n\t\n\tBigInteger sub (BigInteger a, long b) {\n\t\tBigInteger res = a.subtract(BigInteger.valueOf(b));\n\t\treturn res;\n\t}\n\t\n\tclass Pair implements Comparable<Pair> {\n\t\tint val, id;\n\t\tPair (int a, int b) {\n\t\t\tval = a;\n\t\t\tid = b;\n\t\t}\n\t\t\n\t\tpublic int compareTo (Pair o) {\n\t\t\tif(val == o.val) return Integer.compare(id, o.id);\n\t\t\treturn Integer.compare(o.val, val);\n\t\t}\n\t}\n\t\n\tclass Fenwick_Tree {\n\t\t\n\t\tlong[] bit;\n\t\tint n;\n\t\t\n\t\tpublic Fenwick_Tree(int a) {\n\t\t\tn = a + 1;\n\t\t\tbit = new long[n];\n\t\t}\n\t\t\n\t\t//Remember that when querying a sum to query the 1-based index of the value.\n\t\t\n\t\tvoid update (int index, long val) {\n\t\t\twhile(index < n) {\n\t\t\t\tbit[index] += val;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong sum (int index) {\n\t\t\tlong sum = 0;\n\t\t\twhile(index > 0) {\n\t\t\t\tsum += bit[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t}\n\n\t\n\tvoid sort (int[] a) {\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < 1000; 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\t\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner() {\n\t\t\ttry\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t//\t\t\t\tbr = new BufferedReader(new FileReader(\"cases.in\"));\n\t\t\t\tst = new StringTokenizer(\"\");\n\t\t\t} catch (Exception e){e.printStackTrace();}\n\t\t}\n\t\tpublic String next() {\n\t\t\tif (st.hasMoreTokens())\treturn st.nextToken();\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\t\tpublic long nextLong() {return Long.parseLong(next());}\n\t\tpublic double nextDouble() {return Double.parseDouble(next());}\n\n\t\tpublic String nextLine() {\n\t\t\tString line = \"\";\n\t\t\ttry {line = br.readLine();}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn line;\n\t\t}\n\t\tpublic Integer[] nextIntegerArray(int n) {\n\t\t\tInteger[] a = new Integer[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tpublic char[] nextCharArray() {return nextLine().toCharArray();}\n\t}\n\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.math.BigInteger;\nimport java.util.HashMap;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author khokharnikunj8\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        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, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            BigInteger ans = new BigInteger(\"0\");\n            long val, index, index1, index2;\n            long sum[] = new long[n];\n            val = in.scanInt();\n            HashMap<Long, Integer> hs = new HashMap<>();\n            hs.put(val, 1);\n            sum[0] = val;\n            for (int i = 1; i < n; i++) {\n                val = in.scanInt();\n                sum[i] += sum[i - 1];\n                sum[i] += val;\n                if (!hs.containsKey(val)) hs.put(val, 0);\n                hs.put(val, hs.get(val) + 1);\n\n                ans = ans.add(BigInteger.valueOf(((i + 1) * val) - sum[i]));\n                index = (hs.containsKey(val + 1)) ? hs.get(val + 1) : 0;\n                index1 = (hs.containsKey(val - 1)) ? hs.get(val - 1) : 0;\n                index2 = (hs.containsKey(val)) ? hs.get(val) : 0;\n                ans = ans.subtract(BigInteger.valueOf(((index + index1 + index2) * val) - ((index * (val + 1)) + (index1 * (val - 1)) + (index2 * (val)))));\n            }\n            out.println(ans);\n\n\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class d {\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 n=0;n<N;n++){\n\t\t\tarr[n] = in.nextInt();\n\t\t}\n\t\t\n\t\tWavelet waveyMcWaveFace = new Wavelet(arr);\n\t\t\n\t\tBigInteger bigSum = BigInteger.ZERO;\n\t\tfor(int n=0;n<N;n++){\n\t\t\t// calculate the amount added for all j = n all at once\n\t\t\t// it's a[j] - a[i]\n\t\t\t\n\t\t\t// step one\n\t\t\t// positive part\n\t\t\tlong amtPlus = arr[n] * (long)(waveyMcWaveFace.numValsBtwn(1, arr[n] - 2, 0, n)\n\t\t\t\t\t\t\t\t\t\t+ waveyMcWaveFace.numValsBtwn(arr[n] + 2, 2147483647, 0, n));\n\t\t\t\n\t\t\t// step two\n\t\t\t// negative part\n\t\t\tlong amtMinus = waveyMcWaveFace.sumOfValsBtwn(1, arr[n] - 2, 0, n)\n\t\t\t\t\t\t\t+ waveyMcWaveFace.sumOfValsBtwn(arr[n] + 2, 2147483647, 0, n);\n\t\t\t\n//\t\t\tSystem.out.println(amtPlus+\" \"+amtMinus);\n\t\t\tbigSum = bigSum.add(new BigInteger(\"\"+(amtPlus - amtMinus)));\n\t\t}\n\t\t\n\t\tSystem.out.println(bigSum);\n\t}\n\tstatic class Wavelet{\n\t\tint l = 2147483647, h = -2147483648;\n\t\tint[] arr, ldex, hdex;\n\t\tlong[] sum;\n\t\tWavelet low = null, high = null;\n\t\tWavelet(int[] arr){\n\t\t\tthis.arr = arr;\n\t\t\tfor(int i : arr){\n\t\t\t\tl = Math.min(l, i);\n\t\t\t\th = Math.max(h, i);\n\t\t\t}\n\t\t\tldex = new int[arr.length + 1];\n\t\t\thdex = new int[arr.length + 1];\n\t\t\tsum = new long[arr.length + 1];\n\t\t\tint mid = l + (h - l) / 2;\n\t\t\tfor(int n = 0; n < arr.length; n++){\n\t\t\t\tsum[n+1] = sum[n] + arr[n];\n\t\t\t\tif(arr[n] > mid){\n\t\t\t\t\tldex[n+1] = ldex[n];\n\t\t\t\t\thdex[n+1] = hdex[n] + 1;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tldex[n+1] = ldex[n] + 1;\n\t\t\t\t\thdex[n+1] = hdex[n];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(l == h) return;\n\t\t\tint[] larr = new int[ldex[arr.length]];\n\t\t\tint[] harr = new int[hdex[arr.length]];\n\t\t\tfor(int n=0;n<arr.length;n++){\n\t\t\t\tif(hdex[n] == hdex[n+1]){\n\t\t\t\t\tlarr[ldex[n]] = arr[n];\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tharr[hdex[n]] = arr[n];\n\t\t\t\t}\n\t\t\t}\n\t\t\tlow = new Wavelet(larr);\n\t\t\thigh = new Wavelet(harr);\n\t\t}\n\t\t// range [ll, rr)\n\t\tint kthLowest(int k, int ll, int rr){\n\t\t\tif(l == h){\n\t\t\t\treturn arr[ll + k-1];\n\t\t\t}\n\t\t\tif(ldex[rr] - ldex[ll] >= k){\n\t\t\t\treturn low.kthLowest(k, ldex[ll], ldex[rr]);\n\t\t\t}\n\t\t\treturn high.kthLowest(k - ldex[rr] + ldex[ll], hdex[ll], hdex[rr]);\n\t\t}\n\t\t// number of values in between [lo, hi] in range [ll, rr)\n\t\tint numValsBtwn(int lo, int hi, int ll, int rr){\n\t\t\tif(hi < lo) return 0;\n\t\t\tif(lo <= l && h <= hi){\n\t\t\t\treturn rr - ll;\n\t\t\t}\n\t\t\tif(l == h) return 0;\n\t\t\tif(hi < high.l){\n\t\t\t\treturn low.numValsBtwn(lo, hi, ldex[ll], ldex[rr]);\n\t\t\t}\n\t\t\tif(low.h < lo){\n\t\t\t\treturn high.numValsBtwn(lo, hi, hdex[ll], hdex[rr]);\n\t\t\t}\n\t\t\treturn low.numValsBtwn(lo, hi, ldex[ll], ldex[rr])\n\t\t\t\t\t+ high.numValsBtwn(lo, hi, hdex[ll], hdex[rr]);\n\t\t}\n\t\t// sum of values between [lo, hi] in range [ll, rr)\n\t\tlong sumOfValsBtwn(int lo, int hi, int ll, int rr){\n\t\t\tif(lo <= l && h <= hi){\n\t\t\t\treturn sum[rr] - sum[ll];\n\t\t\t}\n\t\t\tif(l == h) return 0;\n\t\t\tif(hi < high.l){\n\t\t\t\treturn low.sumOfValsBtwn(lo, hi, ldex[ll], ldex[rr]);\n\t\t\t}\n\t\t\tif(low.h < lo){\n\t\t\t\treturn high.sumOfValsBtwn(lo, hi, hdex[ll], hdex[rr]);\n\t\t\t}\n\t\t\treturn low.sumOfValsBtwn(lo, hi, ldex[ll], ldex[rr])\n\t\t\t\t\t+ high.sumOfValsBtwn(lo, hi, hdex[ll], hdex[rr]);\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "/*\n * PDPM IIITDM Jabalpur\n * Asutosh Rana\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main\n{\n    long MOD = 1000000007;\n    InputReader in;BufferedReader br;PrintWriter out;\n    public static void main (String[] args) throws java.lang.Exception\n    {\n        Main solver = new Main();\n        solver.in = new InputReader(System.in);\n        solver.br = new BufferedReader(new InputStreamReader(System.in));\n        solver.out = new PrintWriter(System.out);\n        solver.solve();\n        solver.out.flush();\n        solver.out.close();\n    }\n\n    public void solve(){\n        \n        int tc = 1;//in.readInt();\n        \n        for(int cas=1;cas<=tc;cas++){\n            int N = in.readInt();\n            int[] A = new int[N];\n            in.readInt(A);\n            \n            HashMap<Integer, Integer> H = new HashMap<>();\n            long sum = A[0], count = 1;\n            BigInteger B = BigInteger.ZERO;\n            H.put(A[0], 1);\n            for(int i=1;i<N;i++){\n                // res = res + (count*A[i] - sum);\n                B = B.add(BigInteger.valueOf(count*A[i]-sum));\n                if(!H.containsKey(A[i]))\n                    H.put(A[i], 0);\n                H.put(A[i], H.get(A[i])+1);\n\n                if(H.containsKey(A[i]-1)){\n                    int k = H.get(A[i]-1);\n                    // res = res + (k*(A[i]-1) - k*A[i]);\n                    B = B.add(BigInteger.valueOf((k*(A[i]-1) - k*A[i])));\n                }\n                if(H.containsKey(A[i]+1)){\n                    int k = H.get(A[i]+1);\n                    B = B.add(BigInteger.valueOf((k*(A[i]+1) - k*A[i])));\n                    // res = res + (k*(A[i]+1) - k*A[i]);\n                }\n                // out.println(res);\n                sum+=A[i];count++;\n            }\n            // out.println(\"-1\");\n            out.println(B);\n\n\n        }\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    private SpaceCharFilter filter;\n\n    public InputReader(InputStream stream){this.stream = stream;}\n    public int read(){\n        if (numChars==-1) throw new InputMismatchException();\n        if (curChar >= numChars){\n            curChar = 0;\n            try {numChars = stream.read(buf);}\n            catch (IOException e){throw new InputMismatchException();}\n            if(numChars <= 0) return -1;\n        }\n        return buf[curChar++];\n    }\n\n    public int readInt(){\n        int c = read();\n        while(isSpaceChar(c)) c = read();\n        int sgn = 1;\n        if (c == '-') {sgn = -1;c = read();}\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        }\n        while (!isSpaceChar(c)); return res * sgn;\n    }\n\n    public void readInt(int[] A){\n        for(int i=0;i<A.length;i++)\n            A[i] = readInt();\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        }\n        while (!isSpaceChar(c));\n        return res * sgn;\n    }\n\n    public void readLong(long[] A){\n        for(int i=0;i<A.length;i++)\n            A[i] = readLong();\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 char[] readCharA(){\n        return readString().toCharArray();\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 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}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\n    static Map<BigInteger, BigInteger> mp = new HashMap<BigInteger, BigInteger>();\n\n    public static void main(String[] args) {\n        mp.clear();\n        Scanner cin = new Scanner(new BufferedInputStream(System.in));\n        BigInteger n = cin.nextBigInteger();\n        BigInteger x = cin.nextBigInteger();\n        mp.put(x, BigInteger.ONE);\n        BigInteger sum = x;\n        BigInteger ans = BigInteger.ZERO;\n        for (int i = 2;i <= n.intValue(); i++) {\n            x=cin.nextBigInteger();\n            BigInteger tmp = x.multiply(BigInteger.valueOf(i-1)).subtract(sum);\n            if (mp.containsKey(x.subtract(BigInteger.ONE))) tmp = tmp.subtract(mp.get(x.subtract(BigInteger.ONE)));\n            if (mp.containsKey(x.add(BigInteger.ONE))) tmp = tmp.add(mp.get(x.add(BigInteger.ONE)));\n            ans = ans.add(tmp);\n            sum = sum.add(x);\n            BigInteger xx;\n            if (mp.containsKey(x)) xx = mp.get(x);\n            else xx = BigInteger.ZERO;\n            mp.put(x, xx.add(BigInteger.ONE));\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.math.BigInteger;\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 darkhan imangaliyev\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        MyReader in = new MyReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        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, MyReader 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            Map<Integer, Integer> map = new HashMap<>();\n            for (int i = 0; i < n; ++i) {\n                if (map.containsKey(a[i])) {\n                    map.put(a[i], map.get(a[i]) + 1);\n                } else {\n                    map.put(a[i], 1);\n                }\n            }\n            List<Integer> compressed = new ArrayList<>();\n            compressed.add(-1);\n            compressed.add(Integer.MAX_VALUE);\n            compressed.addAll(map.keySet());\n            Collections.sort(compressed);\n            //        System.out.println(compressed);\n            int N = compressed.size() + 10;\n            BIT count = new BIT(N);\n            BIT sum = new BIT(N);\n\n            BigInteger ret = BigInteger.ZERO;\n            for (int i = n - 1; i >= 0; --i) {\n                int l = findLeft(compressed, a[i] - 2);\n                int r = findRight(compressed, a[i] + 2);\n                long left = sum.sum(0, l);\n                long countLeft = count.sum(0, l);\n                long right = sum.sum(r, N);\n                long countRight = count.sum(r, N);\n                //            System.out.println(\"b[i] = \" + b[i]);\n                //            System.out.println(\"l = \" + l + \", r = \" + r);\n                //            System.out.println(\"left = \" + left + \", right = \" + right);\n                //            System.out.println(\"countLeft = \" + countLeft + \", countRight = \" + countRight);\n                //            System.out.println();\n                long t = (left - countLeft * a[i]) + (right - a[i] * countRight);\n                ret = ret.add(BigInteger.valueOf(t));\n                int x = Collections.binarySearch(compressed, a[i]);\n                sum.update(x, a[i]);\n                count.update(x, 1);\n            }\n            out.println(ret);\n        }\n\n        private int findLeft(List<Integer> a, int t) {\n            int lo = -1, hi = a.size();\n            while (hi - lo > 1) {\n                int m = lo + (hi - lo) / 2;\n                if (a.get(m) <= t) {\n                    lo = m;\n                } else {\n                    hi = m;\n                }\n            }\n            return lo;\n        }\n\n        private int findRight(List<Integer> a, int t) {\n            int lo = -1, hi = a.size();\n            while (hi - lo > 1) {\n                int m = lo + (hi - lo) / 2;\n                if (a.get(m) < t) {\n                    lo = m;\n                } else {\n                    hi = m;\n                }\n            }\n            return hi;\n        }\n\n        class BIT {\n            long[] tree;\n\n            public BIT(int n) {\n                tree = new long[n + 1];\n            }\n\n            public void update(int x, long d) {\n                while (x < tree.length) {\n                    tree[x] += d;\n                    x += x & -x;\n                }\n            }\n\n            public long sum(int l, int r) {\n                return sum(r) - sum(l - 1);\n            }\n\n            public long sum(int x) {\n                long sum = 0;\n                while (x > 0) {\n                    sum += tree[x];\n                    x -= x & -x;\n                }\n                return sum;\n            }\n\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", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.math.BigInteger;\nimport java.util.HashMap;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author ZYCSwing\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            int[] a = new int[n];\n\n            BigInteger sum = new BigInteger(\"0\");\n            for (int i = 0; i < n; ++i) {\n                a[i] = in.nextInt();\n                long tmp = ((long) (2 * i + 1 - n)) * a[i];\n                sum = sum.add(BigInteger.valueOf(tmp));\n            }\n\n            Map<Integer, Integer> cnt = new HashMap<>();\n\n            for (int i = n - 1; i >= 0; --i) {\n                if (cnt.containsKey(a[i] + 1)) {\n                    sum = sum.subtract(BigInteger.valueOf(cnt.get(a[i] + 1)));\n                }\n                if (cnt.containsKey(a[i] - 1)) {\n                    sum = sum.add(BigInteger.valueOf(cnt.get(a[i] - 1)));\n                }\n                if (cnt.containsKey(a[i])) {\n                    cnt.put(a[i], cnt.get(a[i]) + 1);\n                } else {\n                    cnt.put(a[i], 1);\n                }\n            }\n\n            out.println(sum);\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.*;\n     \n     \n     \n     \n    import java.math.*;\n    import java.util.*;    \n          public class Main1\n           {\n            private InputStream is;\n            private PrintWriter out;\n            static int MOD = (int)(1e9+7);\n            ArrayList<Integer>[] 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<Integer>[] g;\n            static ArrayList<Integer> ar[];\n            static long ok[];    \n            static int phi[]=new int[500005];\n            void solve()\n            {\n            \tint n=ni();\n                int a[]=na(n);\n                long sum=0;\n                HashMap<Integer,Integer> hm=new HashMap();\n                BigInteger ans=(BigInteger.ZERO);\n                int count=0;\n                for(int i=n-1;i>=0;i--)\n                {\n               \t int tmp1=0;\n               \t int tmp2=0;\n               \t int tmp3=0;\n               \t if(hm.containsKey(a[i]))\n               \t\t tmp1=hm.get(a[i]);\n               \t if(hm.containsKey(a[i]+1))\n               \t\t tmp2=hm.get(a[i]+1);\n               \t if(hm.containsKey(a[i]-1))\n               \t\t tmp3=hm.get(a[i]-1);\n               \t long lol=sum;\n               \t lol-=((long)tmp1*(long)a[i]);\n               \t lol-=((long)tmp2*(long)(a[i]+1));\n               \t lol-=((long)tmp3*(long)(a[i]-1));\n               \t int fr=(count)-tmp1-tmp2-tmp3;\n               \t long fuck=(lol)-((long)fr*(long)a[i]);\n               \t ans=ans.add(BigInteger.valueOf(fuck));\n               \t if(!hm.containsKey(a[i]))\n               \t\t hm.put(a[i],1);\n               \t else\n               \t\t hm.put(a[i],hm.get(a[i])+1);\n               \t sum+=(long)a[i];\n               \t count++;\n               \t// System.out.println(ans+\" \"+tmp1+\" \"+tmp2+\" \"+tmp3+\" \"+lol);\n                }\n                out.println(ans);\n            }\n           public static long multiply(long a)\n            {\n            \treturn a*10;\n            }\n            public static long query1(int v,int start,int end,int l,int r,int x)\n            {\n            \tif(r < start || end < l)\n                {\n                    return Long.MAX_VALUE;\n                }\n                if(l <= start && end <= r)\n                {\n                    return (tre[v]);\n                }\n                int mid = (start + end) / 2;\n                long p1 = query1(2*v, start, mid, l, r,x);\n                long p2 = query1(2*v+1, mid+1, end, l, r,x);\n                return Math.min(p1, p2);\t\n            }\n            public static void update1(int v,int tl,int tr,int index,long a2)\n            {\n            \tif(tl==tr)\n                {\n                    tre[v]=a2;\n                }\n                else\n                {\n                    int mid=(tl+tr)/2;\n                    if(tl <= index &&index <= mid)\n                    {\n                        update1(2*v,tl, mid, index, a2);\n                    }\n                    else\n                    {\n                        update1(2*v+1,mid+1,tr, index, a2);\n                    }\n                    tre[v]=(Math.min(tre[2*v],tre[2*v+1]));\n                }\n            }\n\t\t\tstatic boolean visited[][];\n\t\t\tstatic int a[][];\n            public static long query(int v,int start,int end,int l,int r,int x)\n            {\n            \tif(r < start || end < l)\n                {\n                    return 0;\n                }\n                if(l <= start && end <= r)\n                {\n                    return (tre[v]);\n                }\n                int mid = (start + end) / 2;\n                long p1 = query(2*v, start, mid, l, r,x);\n                long p2 = query(2*v+1, mid+1, end, l, r,x);\n                return Math.max(p1, p2);\t\n            }\n            public static void update(int v,int tl,int tr,int index,long a2)\n            {\n            \tif(tl==tr)\n                {\n                    tre[v]=a2;\n                }\n                else\n                {\n                    int mid=(tl+tr)/2;\n                    if(tl <= index &&index <= mid)\n                    {\n                        update(2*v,tl, mid, index, a2);\n                    }\n                    else\n                    {\n                        update(2*v+1,mid+1,tr, index, a2);\n                    }\n                    tre[v]=(Math.max(tre[2*v],tre[2*v+1]));\n                }\n            }\n            static long tre[]=new long[400005];\n          /* public static int find(int v,int start,int end,int l,int r)\n            {\n                if(r < start || end < l)\n                {\n                    return Integer.MIN_VALUE;\n                }\n                if(l <= start && end <= r)\n                {\n                    return (tre[v]);\n                }\n                int mid = (start + end) / 2;\n                int p1 = find(2*v, start, mid, l, r);\n                int p2 = find(2*v+1, mid+1, end, l, r);\n                return Math.max(p1, p2);          \n            }\n            static int tre[]=new int[4000005];\n            public static void Update(int v,int tl,int tr,int index,int val)\n            {\n                if(tl==tr)\n                {\n                    tre[v]=val;\n                }\n                else\n                {\n                    int mid=(tl+tr)/2;\n                    if(tl <= index &&index <= mid)\n                    {\n                        Update(2*v,tl, mid, index, val);\n                    }\n                    else\n                    {\n                        Update(2*v+1,mid+1,tr, index, val);\n                    }\n                    tre[v]=(Math.max(tre[2*v],tre[2*v+1]));\n                }\n            }\n            */\n            boolean isPrime(int x)\n                {\n                if(x==0||x==1)\n                    return false;\n                for(int i = 2;i*1L*i<=x;i++) if(x%i==0) return false;\n                return true;\n            }\n            int  p ;\n            long modInverse(long a, long mOD2){\n                return  power(a, mOD2-2, mOD2);\n            }\n            long power(long x, long y, long m)\n            {\n            if (y == 0)\n            return 1;\n            long p = power(x, y/2, m) % m;\n            p = (p * p) % m;\n        \n            return (y%2 == 0)? p : (x * p) % m;\n            }\n            public static long gcd(long a, long b){\n                if(b==0) return a;\n                return gcd(b,a%b);\n            }\n            class Pair1 implements Comparable<Pair1>{\n                long a;\n                long b;\n                long c;\n                Pair1(long x,long y,long z){\n                this.a=x;\n                this.b=y;\n                this.c=z;\n                }\n                public int hashCode() {\n                    return Objects.hash();\n                }\n                \n                @Override\n                public int compareTo(Pair1 arg0) {\n                    return (int)(arg0.c-c);\n                }    \n            }\n            long power(long x, long y, int mod){\n                long ans = 1;\n                while(y>0){\n                    if(y%2==0){\n                        x = (x*x)%mod;\n                        y/=2;\n                    }\n                    else{\n                        ans = (x*ans)%mod;\n                        y--;\n                    }\n                }\n                return ans;\n            }\n            void soln() {\n                is = System.in;\n                out = new PrintWriter(System.out);\n                long s = System.currentTimeMillis();\n                solve();\n                out.flush();\n            }\n             private byte[] inbuf = new byte[1024];\n            public int lenbuf = 0, ptrbuf = 0;\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(inbuf);\n                    } catch (IOException e) {\n                        throw new InputMismatchException();\n                    }\n                    if (lenbuf <= 0)\n                        return -1;\n                }\n                return inbuf[ptrbuf++];\n            }\n            private boolean isSpaceChar(int c) {\n                return !(c >= 33 && c <= 126);\n            }\n            private int skip() {\n                int b;\n                while ((b = readByte()) != -1 && isSpaceChar(b))\n                    ;\n                return b;\n            }\n            private double nd() {\n                return Double.parseDouble(ns());\n            }\n            private char nc() {\n                return (char) skip();\n            }\n            private String ns() {\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            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            private int[][] nm(int n, int m) {\n                int[][] map = new int[n][m];\n                for (int i = 0; i < n; i++)\n                {\n                    for(int j=0;j<m;j++)\n                        map[i][j]=ni();\n                }\n                return map;\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                return a;\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                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 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                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) {\n                if (!oj)\n                    System.out.println(Arrays.deepToString(o));\n            }\n        }  ", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "//package educational.round34;\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;\nimport java.util.Random;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tint[] xs = new int[3*n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\txs[3*i] = a[i];\n\t\t\txs[3*i+1] = a[i]-1;\n\t\t\txs[3*i+2] = a[i]+1;\n\t\t}\n\t\txs = shuffle(xs, new Random());\n\t\tint[] imap = shrinkX(xs);\n\t\t\n\t\tBigInteger ans = BigInteger.valueOf(0L);\n\n\t\t{\n\t\t\tint[] ft = new int[3*n+3];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tint y = Arrays.binarySearch(imap, a[i]);\n\t\t\t\tint num = \n\t\t\t\t\t\ti - sumFenwick(ft, y + 1) + sumFenwick(ft, y - 2);\n\t\t\t\tans = ans.add(BigInteger.valueOf((long)a[i] * num));\n\t\t\t\taddFenwick(ft, y, 1);\n\t\t\t}\n\t\t}\n\t\t\n\t\t{\n\t\t\tint[] ft = new int[3*n+3];\n\t\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\t\tint y = Arrays.binarySearch(imap, a[i]);\n\t\t\t\tint num = \n\t\t\t\t\t\tn-1-i - sumFenwick(ft, y + 1) + sumFenwick(ft, y - 2);\n\t\t\t\tans = ans.subtract(BigInteger.valueOf((long)a[i] * num));\n\t\t\t\taddFenwick(ft, y, 1);\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int sumFenwick(int[] ft, int i)\n\t{\n\t\tint sum = 0;\n\t\tfor(i++;i > 0;i -= i&-i)sum += ft[i];\n\t\treturn sum;\n\t}\n\t\n\tpublic static void addFenwick(int[] ft, int i, int v)\n\t{\n\t\tif(v == 0 || i < 0)return;\n\t\tint n = ft.length;\n\t\tfor(i++;i < n;i += i&-i)ft[i] += v;\n\t}\n\n\t\n\tpublic static int[] shuffle(int[] a, Random gen){ for(int i = 0, n = a.length;i < n;i++){ int ind = gen.nextInt(n-i)+i; int d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; }\n\n\t\n\tpublic static int[] shrinkX(int[] a) {\n\t\tint n = a.length;\n\t\tlong[] b = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tb[i] = (long) a[i] << 32 | i;\n\t\tArrays.sort(b);\n\t\tint[] ret = new int[n];\n\t\tint p = 0;\n\t\tret[0] = (int) (b[0] >> 32);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) {\n\t\t\t\tp++;\n\t\t\t\tret[p] = (int) (b[i] >> 32);\n\t\t\t}\n\t\t\ta[(int) b[i]] = p;\n\t\t}\n\t\treturn Arrays.copyOf(ret, p + 1);\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 D().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.SplittableRandom;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = in.nextIntArray(n);\n            int[] b = a.clone();\n            b = Arrays.copyOf(b, a.length + 2);\n            b[a.length] = 0;\n            b[a.length + 1] = (int) 2e9;\n            ArrayUtils.sort(b);\n            b = ArrayUtils.uniqueArray(b);\n            SegmentTreeSumL segmentTreeSumL = new SegmentTreeSumL(b.length + 1);\n            SegmentTreeSumL size = new SegmentTreeSumL(b.length + 1);\n            for (int i = 0; i < n; ++i) {\n                segmentTreeSumL.update(Arrays.binarySearch(b, a[i]), a[i]);\n                size.update(Arrays.binarySearch(b, a[i]), 1);\n            }\n            Debug debug = new Debug(out);\n            BigInteger sum = new BigInteger(\"0\");\n            for (int i = 0; i < n; ++i) {\n                segmentTreeSumL.update(Arrays.binarySearch(b, a[i]), -a[i]);\n                size.update(Arrays.binarySearch(b, a[i]), -1);\n                int indG = ArrayUtils.LowerBound(b, a[i] + 2);\n                indG = Math.min(indG, b.length);\n                long s1 = size.getRangeSum(indG, b.length);\n                long sum1 = segmentTreeSumL.getRangeSum(indG, b.length);\n                //debug.tr(\"1\", s1, sum1);\n                sum = sum.add(BigInteger.valueOf(sum1 - s1 * a[i]));\n                int indL = ArrayUtils.LowerBound(b, a[i] - 1) - 1;\n                indL = Math.max(0, indL);\n                long s2 = size.getRangeSum(0, indL);\n                long sum2 = segmentTreeSumL.getRangeSum(0, indL);\n                //debug.tr(\"2\", s2, sum2);\n                sum = sum.add(BigInteger.valueOf(sum2 - s2 * a[i]));\n            }\n            out.println(sum.toString());\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static int LowerBound(int[] a, int v) {\n            int high = a.length;\n            int low = -1;\n            while (high - low > 1) {\n                int mid = (high + low) >>> 1;\n                if (a[mid] >= v) {\n                    high = mid;\n                } else {\n                    low = mid;\n                }\n            }\n            return high;\n        }\n\n        public static int[] sort(int[] a) {\n            a = shuffle(a, new SplittableRandom());\n            Arrays.sort(a);\n            return a;\n        }\n\n        public static int[] shuffle(int[] a, SplittableRandom gen) {\n            for (int i = 0, n = a.length; i < n; i++) {\n                int ind = gen.nextInt(n - i) + i;\n                int d = a[i];\n                a[i] = a[ind];\n                a[ind] = d;\n            }\n            return a;\n        }\n\n        public static int[] uniqueArray(int[] a) {\n            int n = a.length;\n            int p = 0;\n            for (int i = 0; i < n; i++) {\n                if (i == 0 || a[i] != a[i - 1]) a[p++] = a[i];\n            }\n            return Arrays.copyOf(a, p);\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    static class SegmentTreeSumL {\n        long[] lazy;\n        long[] seg;\n        long[] a;\n        int size;\n        int N;\n\n        public SegmentTreeSumL(long[] a) {\n            this.N = a.length;\n            size = 4 * N;\n            seg = new long[size];\n            lazy = new long[size];\n            this.a = a;\n            build(0, N - 1, 0);\n        }\n\n        public SegmentTreeSumL(int n) {\n            this.N = n;\n            size = 4 * N;\n            seg = new long[size];\n            lazy = new long[size];\n        }\n\n        private void build(int s, int e, int c) {\n            if (s == e) {\n                seg[c] = a[s];\n                return;\n            }\n            int m = (s + e) >>> 1;\n            build(s, m, 2 * c + 1);\n            build(m + 1, e, 2 * c + 2);\n            seg[c] = seg[2 * c + 1] + seg[2 * c + 2];\n        }\n\n        public void update(int index, int value) {\n            update(0, N - 1, 0, index, value);\n        }\n\n        private void update(int s, int e, int c, int index, int value) {\n            if (s == e) {\n                seg[c] += value;\n                return;\n            }\n            int m = (s + e) >>> 1;\n            if (index <= m) {\n                update(s, m, 2 * c + 1, index, value);\n            } else {\n                update(m + 1, e, 2 * c + 2, index, value);\n            }\n            seg[c] = seg[2 * c + 1] + seg[2 * c + 2];\n        }\n\n        public long getRangeSum(int l, int r) {\n            return getRangeSum(0, N - 1, 0, l, r);\n        }\n\n        private long getRangeSum(int s, int e, int c, int l, int r) {\n            if (s > e || l > r || l > e || r < s) return 0;\n            if (lazy[c] != 0) {\n                if (s != e) {\n                    lazy[2 * c + 1] += lazy[c];\n                    lazy[2 * c + 2] += lazy[c];\n                }\n                seg[c] += (e - s + 1) * (1L) * lazy[c];\n                lazy[c] = 0;\n            }\n            if (s == e) {\n                return seg[c];\n            }\n            if (s >= l && e <= r) {\n                return seg[c];\n            }\n            int m = (s + e) >>> 1;\n            return getRangeSum(s, m, 2 * c + 1, l, r)\n                    + getRangeSum(m + 1, e, 2 * c + 2, l, r);\n        }\n\n    }\n\n    static class Debug {\n        PrintWriter out;\n        boolean oj;\n\n        public Debug(PrintWriter out) {\n            oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            this.out = out;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class D {\n  public static void main(String[] args) {\n    init();\n\n    int n = in.nextInt();\n\n    long total = 0L;\n\n\n\n    int arr[] = new int[n+5];\n\n    Map<Integer, Integer> freq = new HashMap<>();\n    Map<Integer, Integer> kiri = new HashMap<>();\n\n    for (int i = 1; i <= n; ++i){\n     arr[i] = in.nextInt();\n      if (freq.containsKey(arr[i])) {\n        freq.put(arr[i], freq.get(arr[i])+1);\n      } else {\n        freq.put(arr[i], 1);\n        kiri.put(arr[i], 0);\n      }\n      total += (long)arr[i];\n    }\n\n    BigInteger ans = BigInteger.valueOf(0L);\n\n    for (int i = 1; i <= n - 1; ++i) {\n      kiri.put(arr[i], kiri.get(arr[i])+1);\n      total -= arr[i];\n\n      int cnt_kanan = n - i;\n      long temp = total;\n      int cnt_sama = freq.get(arr[i]) - kiri.get(arr[i]);\n      temp -= (cnt_sama)*(long)arr[i];\n      cnt_kanan -= (cnt_sama);\n      if (freq.containsKey(arr[i]-1)) {\n        int cnt_kurang = freq.get(arr[i]-1) - kiri.get(arr[i]-1);\n        cnt_kanan -= cnt_kurang;\n        temp -= (long) cnt_kurang * (long)(arr[i]-1);\n      }\n      if (freq.containsKey(arr[i]+1)) {\n        int cnt_lebih = freq.get(arr[i]+1) - kiri.get(arr[i]+1);\n        cnt_kanan -= cnt_lebih;\n        temp -= (long)(cnt_lebih) * (long)(arr[i]+1);\n      }\n      temp -= (long)cnt_kanan * (long)arr[i];\n      ans = ans.add(BigInteger.valueOf(temp));\n    }\n\n    out.println(ans.toString());\n    out.close();\n  }\n\n  /* PrintWriter and BufferedReader Template from Codeforces */\n  public static MyScanner in;\n  public static PrintWriter out;\n\n  public static void init() {\n    in = new MyScanner();\n    out = new PrintWriter(new BufferedOutputStream(System.out));\n  }\n\n  public static class MyScanner {\n    BufferedReader br;\n    StringTokenizer st;\n\n    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}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashMap;\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        D903 solver = new D903();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class D903 {\n        int N;\n        long ripple;\n        BigInteger tot;\n        long[] nums;\n        BigInteger[] cs;\n\n        public void solve(int testNumber, FastScanner s, PrintWriter out) {\n            N = s.nextInt();\n            nums = s.nextLongArray(N);\n            tot = new BigInteger(\"0\");\n            cs = new BigInteger[N + 1];\n            cs[0] = new BigInteger(\"0\");\n            ripple = 0;\n            for (int i = 1; i <= N; i++)\n                cs[i] = cs[i - 1].add(new BigInteger(\"\" + nums[i - 1]));\n\n            for (int i = 1; i <= N; i++) {\n                long cur = nums[i - 1];\n//            out.printf(\"%d: cs %d, minus %d%n\", i, (cs[N] - cs[i]), cur * (N - i));\n                tot = tot.add(cs[N].subtract(cs[i])).subtract(new BigInteger(\"\" + (cur * (N - i))));\n            }\n\n            HashMap<Long, Integer> seen = new HashMap<>();\n            for (long i : nums) {\n                Integer lo = seen.get(i - 1);\n                Integer hi = seen.get(i + 1);\n                if (lo != null)\n                    tot = tot.subtract(new BigInteger(\"\" + lo));\n                if (hi != null)\n                    tot = tot.add(new BigInteger(\"\" + hi));\n\n                if (!seen.containsKey(i))\n                    seen.put(i, 0);\n                seen.put(i, seen.get(i) + 1);\n            }\n\n            out.println(tot);\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        public long[] nextLongArray(int N) {\n            long[] ret = new long[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = this.nextLong();\n            return ret;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class d {\n\n\n    public static void main(String[] args) throws IOException {\n        FastScanner in = new FastScanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        \n        int n = in.nextInt();\n        long[] arr = new long[n];//in.nextLongArray(n);\n        for (int i = 0; i < n; i++) {\n            //if (i < n / 2) arr[i] = 1;\n            //else arr[i] = 1000000000;\n            arr[i] = in.nextLong();\n        }\n        long sum = 0;\n        long count = 0;\n        \n        TreeSet<Long> ts = new TreeSet<>();\n        ts.add(1L);\n        long oo = 1000000000 + 100;\n        ts.add(oo);\n        for (long a : arr) {\n            a += 10;\n            ts.add(a);\n            ts.add(a - 2);\n            ts.add(a + 2);\n        }\n        \n        long[] inds = new long[ts.size()];\n        int idx = 0;\n        for (long a : ts) {\n            inds[idx++] = a;\n        }\n        \n        SuperBIT bit1 = new SuperBIT(inds);\n        SuperBIT bit2 = new SuperBIT(inds);\n        BigInteger ans = BigInteger.valueOf(0);\n        \n        for (long a : arr) {\n            a += 10;\n            \n            long countLess = bit1.queryCompr(1, a - 2);\n            long sumLess = bit2.queryCompr(1, a - 2);\n            \n            long countMore = bit1.queryCompr(a + 2, oo);\n            long sumMore = bit2.queryCompr(a  + 2, oo);\n            \n            //System.out.println(a + \"  \" + countLess + \"  \" + sumLess + \"  \" + countMore + \"  \" + sumMore);\n            bit1.updateCompr(a, 1);\n            bit2.updateCompr(a, a);\n            \n            long tmp = 0;\n            tmp += countLess * a - sumLess;\n            tmp -= sumMore - countMore * a;\n            ans = ans.add(BigInteger.valueOf(tmp));\n        }\n        \n        out.println(ans);\n        \n        \n        out.close();\n    }\nstatic class SuperBIT {\n  long[] dataMul, dataAdd;\n  SuperBIT(int n) {\n    dataMul = new long[n];\n    dataAdd = new long[n];\n  }\n  void update(int left, int right, long val) {\n    internalUpdate(left, val, -val * (left-1));\n    internalUpdate(right, -val, val * right);\n  }\n  void internalUpdate(int at, long mul, long add) {\n    while (at < dataMul.length) {\n      dataMul[at] += mul;\n      dataAdd[at] += add;\n      at |= (at + 1);\n    }\n  }\n  long query(int at) {\n    long mul = 0;\n    long add = 0;\n    int start = at;\n    while(at >= 0) {\n      mul += dataMul[at];\n      add += dataAdd[at];\n      at = (at & (at + 1)) -1;\n    }\n    return mul * start + add;\n  }\n  long query(int left, int right) {\n    if (left > right) {\n      int temp = left;\n      left = right;\n      right = temp;\n    }\n    return query(right) - (left > 0 ? query(left-1) : 0);\n  }\n  long[] indices; // Used for compressed BIT\n  // Compressed BIT constructor\n  // A BIT that only stores the values that will be updated. \n  // indices is a sorted array of all the unique indices \n  // that would be used for this BIT.\n  public SuperBIT(long[] indices) {\n    this.indices = indices;\n    dataMul = new long[indices.length];\n    dataAdd = new long[indices.length];\n  }\n \n  // Search for the index in the array. If the index was not found, \n  // return the first index lower than the search index.\n  int binSearch(long ind) {\n    int low = 0;\n    int high = dataMul.length-1;\n    while(low < high) {\n      int mid = (low + high+1)/2;\n      if(indices[mid] == ind)\n        return mid;\n      else if(indices[mid] < ind) \n        low = mid;\n      else if(indices[mid] > ind) \n        high = mid-1;\n    }\n    if(indices[low] > ind)\n      --low;\n    return low;\n  }\n  \n  // Read the largest index less than or equal to the given index.\n  long queryCompr(long index) {\n    return query(binSearch(index));\n  }\n  long queryCompr(long left, long right) {\n    return query(binSearch(left), binSearch(right));\n  }\n  // Update a specific index by a value. If the index is not in this \n  // compressed BIT, the index below will be updated.\n  void updateCompr(long index, long val) {\n    int ind = binSearch(index);\n    update(ind, ind, val);\n  }\n  void updateCompr(long left, long right, long val) {\n    update(binSearch(left), binSearch(right), val);\n  } \n}\n    static Random rand = new Random();\n    static void sort(int[] a) {\n        int n = a.length;\n        for (int i = a.length - 1; i > 0; i--) {\n            int j = rand.nextInt(i + 1);\n            int tmp = a[i];\n            a[i] = a[j];\n            a[j] = tmp;\n        }\n        Arrays.sort(a);\n    }\n    static void sort(long[] a) {\n        int n = a.length;\n        for (int i = a.length - 1; i > 0; i--) {\n            int j = rand.nextInt(i + 1);\n            long tmp = a[i];\n            a[i] = a[j];\n            a[j] = tmp;\n        }\n        Arrays.sort(a);\n    }\n    static void sort(double[] a) {\n        int n = a.length;\n        for (int i = a.length - 1; i > 0; i--) {\n            int j = rand.nextInt(i + 1);\n            double tmp = a[i];\n            a[i] = a[j];\n            a[j] = tmp;\n        }\n        Arrays.sort(a);\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    static long[] eEuclid(long a, long b) {\n        if (b == 0) return new long[] { a, 1, 0 };\n        long[] ans = eEuclid(b, a % b);\n        long temp = ans[1] - ans[2] * (a / b);\n        ans[1] = ans[2];  ans[2] = temp;\n        return ans;\n    }\n    static long modInverse(long a, long m) {\n        return ((eEuclid(a, m)[1] % m) + m) % m;\n    }\n    static class IntList {\n        static int[] EMPTY = {};\n        int[] a = EMPTY;\n        int n = 0;\n        void add(int v) {\n            if (n >= a.length)\n                a = Arrays.copyOf(a, (n << 2) + 8);\n            a[n++] = v;\n        }\n        int get(int idx) {\n            return a[idx];\n        }\n        int size() {\n            return n;\n        }\n    }\n    static class DisjointSet {\n        int[] s, r;\t\n\tpublic DisjointSet(int n) {\n            s = new int[n]; r = new int[n];\n            for (int i = 0; i < n; i++) s[i] = i;\n        }\t\n        public int find(int i) { return s[i] == i ? i : (s[i] = find(s[i])); }\n\tpublic void union(int a, int b) {\n            if(r[a = find(a)] == r[b = find(b)]) r[a]++;\n            if(r[a] >= r[b]) s[b] = a; else s[a] = b;\n        }\n    }\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastScanner(InputStream i) {\n            br = new BufferedReader(new InputStreamReader(i));\n            st = new StringTokenizer(\"\");\n        }\n        public String next() throws IOException {\n            if(st.hasMoreTokens())\n                return st.nextToken();\n            else\n                st = new StringTokenizer(br.readLine());\n            return next();\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 double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n        public int[] nextOffsetIntArray(int n) throws IOException {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++)\n                arr[i] = nextInt() - 1;\n            return arr;\n        }\n        public int[] nextIntArray(int n) throws IOException {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++)\n                arr[i] = nextInt();\n            return arr;\n        }\n        public int[][] nextIntArray(int n, int m) throws IOException {\n            int[][] arr = new int[n][m];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    arr[i][j] = nextInt();\n            return arr;\n        }\n        public long[] nextLongArray(int n) throws IOException {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++)\n                arr[i] = nextLong();\n            return arr;\n        }\n        public long[][] nextLongArray(int n, int m) throws IOException {\n            long[][] arr = new long[n][m];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    arr[i][j] = nextLong();\n            return arr;\n        }\n        public double[] nextDoubleArray(int n) throws IOException {\n            double[] arr = new double[n];\n            for (int i = 0; i < n; i++)\n                arr[i] = nextDouble();\n            return arr;\n        }\n        public double[][] nextDoubleArray(int n, int m) throws IOException {\n            double[][] arr = new double[n][m];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    arr[i][j] = nextDouble();\n            return arr;\n        }\n        public char[][] nextCharArray(int n, int m) throws IOException {\n            char[][] arr = new char[n][];\n            for (int i = 0; i < n; i++)\n                arr[i] = next().toCharArray();\n            return arr;\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "/**\n * Created by Aminul on 12/12/2017.\n */\n\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class CF903D {\n    public static void main(String[] args) throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        int n = in.nextInt();\n        int a[] = new int[n+1];\n        int b[] = new int[n+1];\n        TreeSet<Integer> set = new TreeSet<>();\n        for(int i = 1; i <= n; i++){\n            a[i] = in.nextInt();\n            set.add(a[i]);\n        }\n        int k = 0;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        int last = set.first();\n        for(int i : set){\n            if(i - last > 1) k += 2;\n            else k += 1;\n            map.put(i, k);\n            last = i;\n        }\n\n        for(int i = 1; i <= n; i++){\n            b[i] = map.get(a[i]);\n        }\n\n        BinaryIndexTree bit = new BinaryIndexTree(k);\n        BinaryIndexTree freq = new BinaryIndexTree(k);\n\n\n        BigInteger res = BigInteger.ZERO;\n\n        for(int i = n; i >= 1; i--){\n            long l = bit.query(1, b[i]-2), r = bit.query(b[i]+2, k);\n            long lf = freq.query(1, b[i]-2), rf = freq.query(b[i]+2, k);\n\n            res = res.add(BigInteger.valueOf(r));\n            res = res.add(BigInteger.valueOf(l));\n            res = res.subtract(BigInteger.valueOf(rf*a[i]));\n            res = res.subtract(BigInteger.valueOf(lf*a[i]));\n            \n            bit.add(b[i], a[i]);\n            freq.add(b[i], 1);\n        }\n\n        pw.println(res);\n\n        pw.close();\n    }\n\n    static class BinaryIndexTree{\n        public long bit[];\n        int n, len;\n\n        public BinaryIndexTree(int nn){\n            n = nn;\n            bit = new long[n+1];\n            len = bit.length;\n        }\n\n        public void add(int index, long value){\n            for(; index < len;index = index + ( index & -index)){\n                bit[index] += value;\n            }\n        }\n\n        public long sum(int index){\n            if(index <= 0) return 0;\n            long sum = 0;\n            for(; index > 0;index = index - (index & -index)){\n                sum += bit[index];\n            }\n            return sum;\n        }\n\n        public long query(int i, int j){\n            if(j < i) return 0;\n            return sum(j) - sum(i-1);\n        }\n\n\n\n    }\n\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n        static final int ints[] = new int[128];\n\n        public FastReader(InputStream is) {\n            for (int i = '0'; i <= '9'; i++) ints[i] = i - '0';\n            this.is = is;\n        }\n\n        public 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        public boolean isSpaceChar(int c) {\n            return !(c >= 33 && c <= 126);\n        }\n\n        public int skip() {\n            int b;\n            while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n            return b;\n        }\n\n        public String next() {\n            int b = skip();\n            StringBuilder sb = new StringBuilder();\n            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n                sb.appendCodePoint(b);\n                b = readByte();\n            }\n            return sb.toString();\n        }\n\n        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = (num << 3) + (num << 1) + ints[b];\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public long nextLong() {\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 << 3) + (num << 1) + ints[b];\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n       /* public char nextChar() {\n            return (char)skip();\n        }*/\n\n        public 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        /*private char buff[] = new char[1005];\n        public char[] nextCharArray(){\n            int b = skip(), p = 0;\n            while(!(isSpaceChar(b))){\n                buff[p++] = (char)b;\n                b = readByte();\n            }\n            return Arrays.copyOf(buff, p);\n        }*/\n    }\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class D\n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tBigInteger ans = BigInteger.ZERO;\n\t\tint n = sc.nextInt();\n\t\tint arr[] = new int[n];\n\t\tlong cum[] = new long[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = sc.nextInt();\n\t\t\n//\t\tint n=(int)2e5;\n//\t\tfor(int i=0;i<n;i++){\n//\t\t\tarr[i]=1;\n//\t\t\tif(i>n/2)\n//\t\t\t\tarr[i]=(int)1e9;\n//\t\t}\n\t\t\n\t\tfor (int i = 0; i < cum.length; i++)\n\t\t{\n\t\t\tcum[i] = arr[i];\n\t\t\tif(i > 0)\n\t\t\t\tcum[i] += cum[i-1];\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tans = ans.add(BigInteger.valueOf((1l*(i+1)*arr[i] - cum[i])));\n\t\t\n\t\tHashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tans =  ans.subtract(BigInteger.valueOf(map.getOrDefault(arr[i]-1, 0)));\n\t\t\tans = ans.add(BigInteger.valueOf(map.getOrDefault(arr[i]+1, 0)));\n\t\t\tmap.put(arr[i], map.getOrDefault(arr[i], 0)+1);\n\t\t}\n\t\t\n\t\tpw.println(ans);\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\t\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", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.math.BigDecimal;\nimport java.util.*;\nimport java.math.BigInteger;\npublic class Main {\n    static Long[] a = new Long[205000];\n    static Long[] postfix=new Long[205000];\n    static HashMap<Long,Long> check=new HashMap<Long,Long>();\n    public static void main(String args[]) {\n        Scanner cin = new Scanner(System.in);\n        long k, j, p,sum,equal,bigone,lessone,cnt;\n        BigInteger ans;\n        int i,n;\n        while (cin.hasNext()) {\n            n=cin.nextInt();\n            check.clear();\n            for(i=1;i<=n;i++)\n            {\n                a[i]=cin.nextLong();\n            }\n            postfix[n+1]=0L;\n            for(i=n;i>=1;i--) {\n                postfix[i] = postfix[i + 1] + a[i];\n                if (check.containsKey(a[i]) == true) {\n                    Long v = check.get(a[i]);\n                    v += 1;\n                    check.put(a[i], v);\n                }\n                else\n                    check.put(a[i],1L);\n            }\n            ans=BigInteger.ZERO;\n            for(i=1;i<n;i++){\n                Long v=check.get(a[i]);\n                v--;\n                check.put(a[i],v);\n                equal=check.get(a[i]);\n                bigone=0L;\n                lessone=0L;\n                if(check.containsKey(a[i]+1L)==true)\n                bigone=check.get(a[i]+1L);\n                if(check.containsKey(a[i]-1L)==true)\n                lessone=check.get(a[i]-1L);\n                sum=postfix[i]-bigone*(a[i]+1L)-lessone*(a[i]-1L)-equal*a[i]-a[i];\n                cnt=n-i-bigone-lessone-equal;\n                ans=ans.add(BigInteger.valueOf(a[i]*cnt).subtract(BigInteger.valueOf(sum)));\n            }\n            System.out.println(ans.multiply(BigInteger.valueOf(-1)));\n        }\n    }\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Main {\n    protected static final double EPS = 1e-11;\n    private static StreamTokenizer in;\n    private static Scanner ins;\n    private static PrintWriter out;\n    protected static final Double[] BAD = new Double[]{null, null};\n    private boolean[][] layouts;\n    private int c;\n    private int b;\n    private int a;\n    private String word;\n\n    public static void main(String[] args) {\n\n        try {\n            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            ins = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n            out = new PrintWriter(System.out);\n            try {\n                if (System.getProperty(\"xDx\") != null) {\n                    in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));\n                    ins = new Scanner(new FileReader(\"input.txt\"));\n                    out = new PrintWriter(new FileWriter(\"output.txt\"));\n                }\n            } catch (Exception e) {\n                in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n                ins = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n                out = new PrintWriter(System.out);\n            }\n            new Main().run();\n        } catch (Throwable e) {\n//            e.printStackTrace();\n            throw new RuntimeException(e);\n        } finally {\n            out.close();\n        }\n    }\n\n    private int nextInt() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    private long nextLong() throws IOException {\n        in.nextToken();\n        return (long) in.nval;\n    }\n\n    private double nextDouble() throws IOException {\n        in.nextToken();\n        return in.nval;\n    }\n\n    private String nextString() throws IOException {\n        in.nextToken();\n        return in.sval;\n    }\n\n    private char nextChar() throws IOException {\n        in.nextToken();\n        return (char) in.ttype;\n    }\n\n    private void run() throws Exception {\n        /*int t = nextInt();\n        for (int i = 0; i < t; i++) {\n            out.printf(Locale.US, \"Case #%d: %d\\n\", i + 1, solve());\n        }*/\n        solve();\n    }\n\n    private void solve() throws IOException {\n        int n = ins.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = ins.nextInt();\n        }\n\n        Map<Long, Integer> map = new HashMap<>();\n\n        BigInteger res = BigInteger.ZERO;\n        long sum = 0;\n        long amount = 0;\n\n        for (int i = n - 1; i >= 0; i--) {\n            long cur = a[i];\n            Pair same = getZeroAmount(cur, map);\n\n            res = res.add(BigInteger.valueOf((sum - same.sum) - cur * (amount - same.amount)));\n            amount++;\n            sum += cur;\n            map.put(cur, map.getOrDefault(cur, 0) + 1);\n        }\n\n        out.println(res);\n    }\n\n    class Pair {\n        long amount;\n        long sum;\n\n        public Pair(long amount, long sum) {\n            this.amount = amount;\n            this.sum = sum;\n        }\n    }\n\n    private Pair getZeroAmount(long cur, Map<Long, Integer> map) {\n        long amount = 0;\n        long sum = 0;\n        for (long i = cur - 1; i <= cur + 1; i++) {\n            long amountI = map.getOrDefault(i, 0);\n            amount += amountI;\n            sum += amountI * i;\n        }\n        return new Pair(amount, sum);\n    }\n\n    private List<Integer> iterate(List<Integer> a) {\n        ArrayList<Integer> b = new ArrayList<>();\n        int prev = -1;\n        for (int x : a) {\n            if (x == prev) {\n                b.add(x);\n            } else {\n                prev = x;\n            }\n        }\n        return b;\n    }\n\n    private long gcd(long a, long b) {\n        while (a > 0 && b > 0) {\n            long k = a % b;\n            a = b;\n            b = k;\n        }\n\n        return a | b;\n    }\n\n}", "complexity": "nlogn", "problem": "903_D. Almost Difference", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tstatic void insert(TreeMap<Integer, Integer>map,int v,int d)\n\t{\n\t\tif(!map.containsKey(v))map.put(v, 0);\n\t\tmap.put(v, d+map.get(v));\n\t\tif(map.get(v)==0)map.remove(v);\n\t}\n\t\n\tstatic void cut(TreeSet<Integer> cuts, TreeMap<Integer, Integer>segments,int v)\n\t{\n\t\tint upper = cuts.higher(v) , lower = cuts.lower(v);\n\t\tinsert(segments, upper-lower, -1);\n\t\tinsert(segments, upper-v, 1);\n\t\tinsert(segments, v-lower, 1);\n\t\tcuts.add(v);\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint w = sc.nextInt(), h = sc.nextInt() , n = sc.nextInt();\n\t\tTreeSet<Integer> vCuts = new TreeSet<>() , hCuts = new TreeSet<>();\n\t\tTreeMap<Integer, Integer> vSegments = new TreeMap<>() , hSegments = new TreeMap<>();\n\t\tvCuts.add(0);vCuts.add(w);\n\t\thCuts.add(0);hCuts.add(h);\n\t\tinsert(vSegments, w, 1);\n\t\tinsert(hSegments, h, 1);\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(n-->0)\n\t\t{\n\t\t\tif(sc.next().equals(\"H\"))\n\t\t\t\tcut(hCuts, hSegments, sc.nextInt());\n\t\t\telse\n\t\t\t\tcut(vCuts, vSegments, sc.nextInt());\n\t\t\tsb.append(1l*hSegments.lastKey() * vSegments.lastKey() + \"\\n\");\n\t\t}\n\t\tSystem.out.println(sb);\n\t}\n\t\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic Scanner(InputStream s) {br = new BufferedReader(new InputStreamReader(s));}\n\t\tpublic Scanner(String file) throws FileNotFoundException {br = new BufferedReader(new FileReader(file));}\n\t\tpublic String next() throws IOException {while (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\tpublic 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\t\tpublic int[] nexIntArray() throws Throwable {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint[] a = new int[st.countTokens()];\n\t\t\tfor (int i = 0; i < a.length; i++)a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}", "complexity": "nlogn", "problem": "528_A. Glass Carving", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport 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        PrintWriter pw = new PrintWriter(System.out);\n        int n = sc.nextInt();\n        int[] a = new int[n];\n        int sum = 0;\n        for (int i = 0; i < n; i++) {\n            a[i] = sc.nextInt();\n            sum += a[i];\n        }\n\n        for (int i = 0; i < n; i++)\n            a[i] *= -1;\n        Arrays.sort(a);\n        for (int i = 0; i < n; i++)\n            a[i] *= -1;\n\n        int ans = 0;\n        int sum1 = 0;\n        for (int i = 0; i < n; i++) {\n            sum1 += a[i];\n            sum -= a[i];\n            ans++;\n            if (sum1 > sum)\n                break;\n        }\n\n        pw.print(ans);\n        pw.close();\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\n    private void solve() 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        }\n        Arrays.sort(a);\n        int sum = 0;\n        for (int i = a.length - 1; i >= 0; i--) {\n            sum += a[i];\n            int k = 0;\n            for (int j = 0; j < i; j++)\n                k += a[j];\n            if (sum > k) {\n                pl(a.length - i);\n                return;\n            }\n        }\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\n    public void run() {\n        try {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            solve();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(nextToken());\n    }\n\n    String nextToken() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    void p(Object... objects) {\n        for (int i = 0; i < objects.length; i++) {\n            if (i != 0)\n                writer.print(' ');\n            writer.flush();\n            writer.print(objects[i]);\n            writer.flush();\n        }\n    }\n\n    void pl(Object... objects) {\n        p(objects);\n        writer.flush();\n        writer.println();\n        writer.flush();\n    }\n\n    int cc;\n\n    void pf() {\n        writer.printf(\"Case #%d: \", ++cc);\n        writer.flush();\n    }\n\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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 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\ttokenizer = null;\n\t\twriter = new PrintWriter(System.out);\n\t\tsolve();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\n\tprivate static void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] mas = new int[n];\n\t\tint sum=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tmas[i]=nextInt();\n\t\t\tsum+=mas[i];\n\t\t}\n\t\tArrays.sort(mas);\n\t\tint cs=0;\n\t\tint res=0;\n\t\tfor(int i=n-1;i>=0;i--)\n\t\t{\n\t\t\tcs+=mas[i];\n\t\t\tsum-=mas[i];\n\t\t\tres++;\n\t\t\tif(cs>sum)\n\t\t\t\tbreak;\n\t\t}\n\t\twriter.println(res);\t\t\n\t}\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint n = sc.nextInt(), sum = 0;\n\t\t\n\t\tInteger[] A = new Integer[n];\n\t\t\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tA[i] = sc.nextInt();\n\t\t\tsum += A[i];\n\t\t}\n\t\t\n\t\tArrays.sort(A, Collections.reverseOrder());\n\t\t\n\t\tint c = 0, ans = 0;\n\t\t\n\t\twhile (ans <= sum) {\n\t\t\tans += A[c];\n\t\t\tsum -= A[c];\n\t\t\tc++;\n\t\t}\n\t\t\n\t\tSystem.out.println(c);\n\t}\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\nimport static java.lang.Math.*;\n\npublic class a111 {\n    public static void debug(Object... obs) {\n        System.out.println(Arrays.deepToString(obs));\n    }\n\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        \n        int n=sc.nextInt();\n        int[]a=new int[n];\n        \n        int su=0;\n        for(int i=0;i<n;i++)\n        {\n            a[i]=-sc.nextInt();\n            su+=-1*a[i];\n        }\n        Arrays.sort(a);\n        \n        \n        int ss=0;\n        for(int i=0;i<n;i++)\n        {\n            ss+=-1*a[i];\n            su-=-1*a[i];\n            if(ss > su)\n            {\n                System.out.println(i+1);\n                return;\n            }\n        }\n        \n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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.Arrays;\n\n/**\n * Works good for CF\n * \n * @author cykeltillsalu\n */\npublic class A111_div2 {\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\tprivate void solve() throws Throwable {\n\n\t\tint n = iread();\n\t\t\n\t\tint[] vals = new int[n];\n\t\tdouble tot = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint value = iread();\n\t\t\tvals[i] = value;\n\t\t\ttot += value;\n\t\t}\n\t\t\n\t\tArrays.sort(vals);\n\t\tint pick = 0;\n\t\tint worth = 0;\n\t\tfor (int i = vals.length - 1; i >= 0; i--) {\n\t\t\tworth += vals[i];\n\t\t\tpick ++;\n\t\t\tif(worth > tot/2.0d){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.write(pick + ENDL);\n\t\tout.flush();\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 A111_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 A111_div2().solve();\n\t\t}\n\t\tout.close();\n\t}\n\n\tpublic A111_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}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class AAA {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint[] array = new int[n];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarray[i] = sc.nextInt();\n\t\t\tsum += array[i];\n\t\t}\n\n\t\tint counter = 0;\n\t\tArrays.sort(array);\n\t\tint first = 0;\n\t\tfor (int j = n - 1; j >= 0; j--) {\n\t\t\tfirst += array[j];\n\t\t\tsum -= array[j];\n\t\t\tcounter++;\n\t\t\tif (first > sum) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(counter);\n\t}\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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    \n    \n    public void solve() throws Exception {\n        int n = sc.nextInt();\n        int a[] = new int[n];\n        int s = 0;\n        for (int i = 0;i < n; ++ i) {\n            a[i] = sc.nextInt();\n            s += a[i];\n        }\n        Arrays.sort(a);\n        int s2 = 0;\n        for (int i = n - 1;i >= 0; -- i) {\n            s2 += a[i];\n            if (s2 > s - s2) {\n                out.println(n - i);\n                break;\n            }\n        }\n        \n    }\n    \n    class Pair implements Comparable<Pair> {\n        \n        int x;\n        int y;\n        \n        public Pair() {\n            \n        }\n        \n        public Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        @Override\n        public int compareTo(Pair arg0) {\n            if (x == arg0.x)\n                return y - arg0.y;\n            return x - arg0.x;\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}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author @listen\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint [] input = new int[n];\n\t\tint total = 0;\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tinput[i] = in.nextInt();\n\t\t\ttotal +=input[i];\n\t\t}\n\t\tArrays.sort(input);\n\t\tint res = 0;\n\t\tint now = 0;\n\t\tfor (int i = n - 1; i >= 0; --i){\n\t\t\tnow += input[i];\n\t\t\tint left = total - now;\n\t\t\t++res;\n\t\t\tif (now > left){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t\treturn;\n\t}\n}\n\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class a implements Comparable<a>{\n    \n    int x, y, id;\n    \n    //static BufferedReader in;\n    //static StringTokenizer st;\n    \n    public a(int x1, int y1, int id1){\n        this.x = x1; this.y = y1; this.id = id1;\n    }\n    \n    public int compareTo(a o) {\n        return x - o.x;\n    }\n    \n    static int n;\n    static int arr[];\n    \n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        //in = new BufferedReader(new InputStreamReader(System.in));\n        //st = new StringTokenizer(\"\",\" \");\n        int n = in.nextInt();\n        arr = new int[n];\n        int sum = 0;\n        for (int i=0; i<n; i++){\n            arr[i] = in.nextInt();\n            sum +=arr[i];\n        }\n        Arrays.sort(arr);\n        int sum2= 0;\n        int ans = 0;\n        for (int i=n-1; i>=0; i--){\n            sum2+=arr[i];\n            //System.out.println(sum2 + \" \" + sum);\n            if (sum2>sum-sum2){\n                ans = n - i;\n                break;\n            }\n        }\n        System.out.println(ans);\n    }\n}\n\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class SolA {\n\n\tstatic Scanner in;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tnew SolA().run();\n\n\t\tin.close();\n\t\tout.close();\n\n\t}\n\n\tprivate void run() {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t\tsum+=a[i];\n\t\t}\n\t\tArrays.sort(a);\n\t\tint cs = 0;\n\t\tint kol = 0;\n\t\tfor(int i = n - 1; i>=0; i--) {\n\t\t\tcs+=a[i];\n\t\t\tkol++;\n\t\t\tif (cs > sum - cs) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.print(kol);\n\t}\n\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class A\n{\n    public A()\n    {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        Integer mas[] = new Integer[n];\n        int b = 0;\n        for (int i = 0 ; i < n ; i ++)\n        {\n            mas[i] = sc.nextInt();\n            b+=mas[i];\n        }\n        Arrays.sort(mas, new Comparator<Integer>()\n        {\n\n            @Override\n            public int compare(Integer o1, Integer o2)\n            {\n                if(o1>o2)\n                    return -1;\n                else if(o1==o2)\n                    return  0;\n                else \n                    return 1;\n            }      \n        });\n        int N = 0; int g = 0;\n        for (int i = 0 ; i < n ; i ++)\n        {\n              g+=mas[i];\n              if(g>(int)(b/2))\n              {\n                  System.out.println(i+1);\n                  return;\n              }\n        }\n        System.out.println(n);\n    }\n    public static void main(String[] args)\n    {\n        new A();      \n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.FileNotFoundException;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class D {\n    public static void main(String[] args) throws FileNotFoundException {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int[] a = new int[n];\n        int[] p = new int[n];\n        for (int i = 0; i < a.length; i++)\n            a[i] = p[i] = in.nextInt();\n        Arrays.sort(a);\n\n        int sum = 0;\n        int t = 0;\n        for (int i = 0; i < a.length; i++)\n            t += a[i];\n        int cnt = 0;\n        for (int i = a.length - 1; i >= 0; i--) {\n            cnt++;\n            sum += a[i];\n            if (t - sum < sum)\n                break;\n        }\n        System.out.println(cnt);\n    }\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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\tnew 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\t\n\t\treadNextLine();\n\t\tint n=NextInt();\n\t\t\n\t\tint ret=0;\n\t\tint [] p = new int [n];\n\t\treadNextLine();\n\t\tint sum=0;\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tint a=NextInt();\n\t\t\tp[i]=a;\n\t\t\tsum+=a;\n\t\t}\n\t\tArrays.sort(p);\n\n\t\tint my=0;\n\t\n\t\tfor(int i=n-1; i>=0; i--)\n\t\t{\n\t\t\tmy+=p[i];\n\t\t\tret++;\n\t\t\tif(my*2>sum)break;\n\t\t}\n\t\t\n\t\tSystem.out.println(ret);\n        closeInput();\t\t\n\t}\n\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R111_D2_A {\n\n    public static void main(String[] args) {\n        InputReader in = new InputReader(System.in);\n        // BufferedReader in = new BufferedReader(new\n        // InputStreamReader(System.in));\n        int n = in.readInt();\n        int[] inp = new int[n];\n        for (int i = 0; i < inp.length; i++) {\n            inp[i] = in.readInt();\n        }\n        Arrays.sort(inp);\n        int sum1 = 0;\n        int res = 0;\n        for (int i = inp.length - 1; i >= 0; i--) {\n            sum1 += inp[i];\n            res++;\n            int sum2 = 0;\n            for (int j = 0; j < i; j++) {\n                sum2 += inp[j];\n            }\n            if (sum1 > sum2) {\n                break;\n            }\n        }\n        System.out.println(res);\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", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "\timport java.util.*;\n\tpublic class A {\n\tpublic static void main(String args[]){\n    Scanner in = new Scanner(System.in);\n int n=in.nextInt(),s=0;\n int[] a= new int[n];\n for (int i=0;i<n;i++) {a[i]=in.nextInt(); s+=a[i];}\n Arrays.sort(a); int k=0,ans=0;\n for (int i=n-1;i>=0;i--)\n\t if (k<=s/2) {k+=a[i];ans++;}\n System.out.println(ans);\n \n\t\t\n\t    \t}\n\t\t}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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.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 Nova\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        int n = 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        Arrays.sort(a);\n        int res = 0;\n        int mySum = 0;\n        int hisSum = sum;\n        for (int i = n - 1; i >= 0; i--) {\n            mySum += a[i];\n            hisSum -= a[i];\n            res++;\n            if (mySum > hisSum) break;\n        }\n        out.println(res);\n    }\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n        tokenizer = null;\n    }\n\n    public String next() {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            try {\n                tokenizer = new StringTokenizer(reader.readLine());\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return tokenizer.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n    \n    }\n\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            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", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "//coded by : ariefianto17 | Reza Ariefianto\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n\tpublic static void main (String[]args)\n\t{\n\t\tScanner read = new Scanner (new BufferedInputStream (System.in));\n\t\tint n = read.nextInt();\n\t\tint[]arr = new int[n];\n\t\tint sum=0;\n\t\tint sum2=0;\n\t\tint coin=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tarr[i] = read.nextInt();\n\t\t\tsum+=arr[i];\n\t\t}\n\t\tArrays.sort(arr);\n\t\tfor(int i=n-1;i>=0;i--)\n\t\t{\n\t\t\tsum2+=arr[i];\n\t\t\tsum-=arr[i];\n\t\t\tcoin++;\n\t\t\tif(sum2>sum)\n\t\t\t\tbreak;\n\n\t\t}\n\t\tSystem.out.println(coin);\n\t}\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class solver {\n    FastScanner in = new FastScanner(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n    \n    \n    public static void main(String[] args) {\n        new solver().solve();\n    }\n    \n    public void solve() {\n    \n        int n = in.nextInt();\n        int[]tab = new int[n];\n        \n        int sum = 0;\n        \n        for (int i = 0; i < n; i++) {\n            tab[i] = in.nextInt();\n            sum += tab[i];\n        }\n        \n        Arrays.sort(tab);\n        int v1 = 0;\n        int count = 0;\n        \n        for (int i = tab.length - 1; i >= 0; i--) {\n            v1 += tab[i];\n            count++;\n            if (v1 > getSum(i, tab)) {\n                break;\n            }\n        }\n        \n        out.println(count);\n        \n        in.close();\n        out.close();\n    }\n    \n    public int getSum(int index, int[]tab) {\n        int sum = 0;\n        for (int i = 0; i < index; i++) sum += tab[i];\n        return sum;\n    }\n    \n    public int max(int a, int b) {\n        if (a > b) return a;\n        else return b;\n    }\n}\n\n\nclass FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n\n    FastScanner(InputStream in) {\n        br = new BufferedReader(new InputStreamReader(in));\n    }\n\n    String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (IOException e) {\n                System.err.println(e);\n                return \"\";\n            }\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    double nextDouble() {\n        return Double.parseDouble(next());\n    }\n\n    float nextFloat() {\n        return Float.parseFloat(next());\n    }\n\n    BigInteger nextBigInt() {\n        return new BigInteger(next());\n    }\n\n    void close() {\n        try {\n            br.close();\n        } catch (IOException e) {\n        }\n    }\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\npublic class Main\n\t{\n\tpublic static void main(String args[])\tthrows IOException\n\t\t{\n\t\tScanner c=new Scanner(System.in);\n\t\tint N=c.nextInt();\n\t\tint A[]=new int[N];\n\t\tfor(int i=0;i<N;i++) \n\t\t\t{\n\t\t\tA[i]=c.nextInt();\n\t\t\t}\n\t\tArrays.sort(A);\n\t\tint sum=0;\n\t\tfor(int i=0;i<N;i++) \n\t\t\t{\n\t\t\tsum+=A[i];\n\t\t\t}\n\t\tint my=0;\n\t\tint coins=0;\n\t\tfor(int i=N-1;i>=0;i--) \n\t\t\t{\n\t\t\tcoins++;\t\t\t//include coin i\n\t\t\tmy+=A[i];\n\t\t\tif(my>sum-my)\n\t\t\t\t{\n\t\t\t\tSystem.out.println(coins);\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n//must declare new classes here", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int[] 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        Arrays.sort(A);\n        int cnt = 0;\n        int temp = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            temp += A[i];\n            sum -= A[i];\n            cnt++;\n            if (temp > sum)\n                break;\n        }\n        System.out.println(cnt);\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CF_111_A {\n\n    public static void main(String[] args){\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt(), sum = 0, sum2 = 0;\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++){\n            a[i] = in.nextInt();\n            sum += a[i];\n        }\n        \n        Arrays.sort(a);\n        \n        for (int i = n - 1; i >=0; i--){\n            sum2 +=a[i];\n            if (sum2 * 2 > sum){\n                System.out.println(n - 1 - i + 1);\n                System.exit(0);             \n            }\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A {\n\n    int n;\n    int[] a;\n    public void run() throws IOException{\n        Scanner s = new Scanner(new InputStreamReader(System.in));\n        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        n = s.nextInt();\n        a =  new int[n];\n        long sum = 0;\n        for (int i = 0; i < n; i++) {\n            a[i] = s.nextInt();\n            sum+=a[i];\n        }\n        \n        Arrays.sort(a);\n        \n        long mysum = 0;\n        int count = 0;\n        for (int i = n-1; i > -1; i--) {\n            if (mysum > sum)\n                break;\n            \n            count++;\n            mysum+=a[i];\n            sum-=a[i];\n        }\n        \n        \n        System.out.println(count);\n        \n    }\n    \n    public static void main(String[] args) throws IOException {\n        (new A()).run();\n    }\n\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = nextInt();\n        \n        Arrays.sort(a);\n        \n        int sum = 0;\n        for (int i = 0; i < n; i++)\n            sum += a[i];\n        \n        int cur = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            cur += a[i];\n            if (cur > sum - cur) {\n                out.println(n - i);\n                return;\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 A().inp();\n    }\n\n    String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return \"0\";\n            }\n        }\n        return st.nextToken();\n    }\n\n    String nextString() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return \"0\";\n            }\n        }\n        return st.nextToken(\"\\n\");\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer tokenizer=null;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tnew Main().execute();\n\t}\n\t\n\tvoid debug(Object...os)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t\n\tint ni() throws IOException\n\t{\n\t\treturn Integer.parseInt(ns());\n\t}\n\t\n\tlong nl() throws IOException \n\t{\n\t\treturn Long.parseLong(ns());\n\t}\n\t\n\tdouble nd() throws IOException \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\t\n\tString ns() throws IOException \n\t{\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n\t\t\ttokenizer = new StringTokenizer(br.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tString nline() throws IOException\n\t{\n\t\ttokenizer=null;\n\t\treturn br.readLine();\n\t}\n\t\t\n\t\n\n\t//Main Code starts Here\n\tint totalCases, testNum;\t\n\tint sum;\n\tint n;\n\tint arr[];\n\n\tvoid execute() throws IOException\n\t{\n\t\ttotalCases = 1;\n\t\tfor(testNum = 1; testNum <= totalCases; testNum++)\n\t\t{\n\t\t\tif(!input())\n\t\t\t\tbreak;\n\t\t\tsolve();\n\t\t}\n\t}\n\n\tvoid solve() throws IOException\n\t{\n\t\tArrays.sort(arr);\n\t\tint count = 0;\n\t\tint ans = 0;\n\t\tfor(int i = n-1;i>=0;i--)\n\t\t{\n\t\t\tcount+= arr[i];\n\t\t\tif(count>sum-count)\n\t\t\t{\n\t\t\t\tans = n-i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\t\n\n\tboolean input() throws IOException\n\t{\n\t\tn = ni();\n\t\tsum = 0;\n\t\tarr = new int[n];\n\t\tfor(int i = 0;i<n;i++)\n\t\t{\n\t\t\tarr[i] = ni();\n\t\t\tsum = sum+arr[i];\n\t\t}\n\t\treturn true;\n\t}\n\n\n}\n\n\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor(int i=0;i<n;i++) a[i] = s.nextInt();\n\t\tint r = 0, an = 0;\n\t\tArrays.sort(a);\n\t\tint t = 0;\n\t\tfor(int z : a) t += z;\n\t\tfor(int i=a.length-1;i>=0;i--){\n\t\t\tr += a[i];\n\t\t\tan++;\n\t\t\tif (r > t - r) break;\n\t\t}\n\t\tSystem.out.println(an);\n\t}\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\t(new Thread(null, new Solution(), \"1\", 1l << 28)).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n//\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n//\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = null;\n\t\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t//if (!in.ready()) return null;\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\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < n; i++) sum += (a[i] = nextInt());\n\t\tArrays.sort(a);\n\t\tint ans = 0;\n\t\tint s = 0;\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\ts += a[i]; ans++;\n\t\t\tif (2 * s > sum) break;\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class A {\n\n    public void solve() throws Exception {\n        \n        int n = nextInt();\n        int[] p = nextArr(n);\n        Arrays.sort(p);\n        int sum = 0;\n        for (int i=0; i<n; ++i) sum+=p[i];\n        int curr = 0;\n        for (int i=n-1; i>=0; --i) {\n            curr += p[i];\n            if (curr>sum-curr) halt(n-i);\n        }\n        \n    }\n\n    \n\n    ////////////////////////////////////////////////////////////////////////////\n    \n    boolean showDebug = true;\n    static boolean useFiles = false;\n    static String inFile = \"input.txt\";\n    static String outFile = \"output.txt\";\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 num) {\n        return num<0 ? 0:num;\n    }\n    long absPos(long num) {\n        return num<0 ? 0:num;\n    }\n    double absPos(double num) {\n        return num<0 ? 0:num;\n    }\n    \n    int min(int... nums) {\n        int r = Integer.MAX_VALUE;\n        for (int i: nums)\n            if (i<r) r=i;\n        return r;\n    }\n    int max(int... nums) {\n        int r = Integer.MIN_VALUE;\n        for (int i: nums)\n            if (i>r) r=i;\n        return r;\n    }\n    long minL(long... nums) {\n        long r = Long.MAX_VALUE;\n        for (long i: nums)\n            if (i<r) r=i;\n        return r;\n    }\n    long maxL(long... nums) {\n        long r = Long.MIN_VALUE;\n        for (long i: nums)\n            if (i>r) r=i;\n        return r;\n    }\n    double minD(double... nums) {\n        double r = Double.MAX_VALUE;\n        for (double i: nums)\n            if (i<r) r=i;\n        return r;\n    }\n    double maxD(double... nums) {\n        double r = Double.MIN_VALUE;\n        for (double i: nums)\n            if (i>r) 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<<pos))>0;\n    }\n\n    long binpow(long 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    boolean charIn(String chars, String s) {\n        if (s==null) return false;\n        if (chars==null || chars.equals(\"\")) return true;\n        for (int i=0; i<s.length(); ++i)\n            for (int j=0; j<chars.length(); ++j)\n                if (chars.charAt(j)==s.charAt(i)) return true;\n        return false;\n    }\n    \n    String stringn(String s, int n) {\n        if (n<1 || s==null) return \"\";\n        StringBuilder sb = new StringBuilder(s.length()*n);\n        for (int i=0; i<n; ++i) sb.append(s);\n        return sb.toString();\n    }\n    String str(Object o) {\n        if (o==null) return \"\";\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 class InputReader {\n        private byte[] buf;\n        private int bufPos = 0, bufLim = -1;\n        private InputStream stream;\n        public InputReader(InputStream stream, int size) {\n            buf = new byte[size];\n            this.stream = stream;\n        }\n        private void fillBuf() throws IOException {\n            bufLim = stream.read(buf);\n            bufPos = 0;\n        }\n        char read() throws IOException {\n            if (bufPos>=bufLim) fillBuf(); \n            return (char)buf[bufPos++];\n        }\n        boolean hasInput() throws IOException {\n            if (bufPos>=bufLim) fillBuf();\n            return bufPos<bufLim;\n        }\n    }\n    \n    static InputReader inputReader;\n    static BufferedWriter outputWriter;\n\n    char nextChar() throws IOException {\n        return inputReader.read();\n    }\n    char nextNonWhitespaceChar() throws IOException {\n        char c = inputReader.read();\n        while (c<=' ') c=inputReader.read();\n        return c;\n    }\n    String nextWord() throws IOException {\n        StringBuilder sb = new StringBuilder();\n        char c = inputReader.read();\n        while (c<=' ') c=inputReader.read();\n        while (c>' ') {\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<size; ++i)\n            arr[i] = nextInt();\n        return arr;\n    }\n    long[] nextArrL(int size) throws NumberFormatException, IOException {\n        long[] arr = new long[size];\n        for (int i=0; i<size; ++i)\n            arr[i] = nextLong();\n        return arr;\n    }\n    double[] nextArrD(int size) throws NumberFormatException, IOException {\n        double[] arr = new double[size];\n        for (int i=0; i<size; ++i)\n            arr[i] = nextDouble();\n        return arr;\n    }\n    String[] nextArrS(int size) throws NumberFormatException, IOException {\n        String[] arr = new String[size];\n        for (int i=0; i<size; ++i)\n            arr[i] = nextWord();\n        return arr;\n    }\n    char[] nextArrCh(int size) throws IOException {\n        char[] arr = new char[size];\n        for (int i=0; i<size; ++i)\n            arr[i] = nextNonWhitespaceChar();\n        return arr;\n    }\n    char[][] nextArrCh(int rows, int columns) throws IOException {\n        char[][] arr = new char[rows][columns];\n        for (int i=0; i<rows; ++i)\n            for (int j=0; j<columns; ++j)\n                arr[i][j] = nextNonWhitespaceChar();\n        return arr;\n    }\n    char[][] nextArrChBorders(int rows, int columns, char border) throws IOException {\n        char[][] arr = new char[rows+2][columns+2];\n        for (int i=1; i<=rows; ++i)\n            for (int j=1; j<=columns; ++j)\n                arr[i][j] = nextNonWhitespaceChar();\n        for (int i=0; i<columns+2; ++i) {\n            arr[0][i] = border;\n            arr[rows+1][i] = border;\n        }\n        for (int i=0; i<rows+2; ++i) {\n            arr[i][0] = border;\n            arr[i][columns+1] = border;\n        }\n        return arr;\n    }\n\n    void printf(String format, Object... args) throws IOException {\n        outputWriter.write(String.format(format, args));\n    }\n    void print(Object o) throws IOException {\n        outputWriter.write(o.toString());\n    }\n    void println(Object o) throws IOException {\n        outputWriter.write(o.toString());\n        outputWriter.newLine();\n    }\n    void print(Object... o) throws IOException {\n        for (int i=0; i<o.length; ++i) {\n            if (i!=0) outputWriter.write(' ');\n            outputWriter.write(o[i].toString());\n        }\n    }\n    void println(Object... o) throws IOException {\n        print(o);\n        outputWriter.newLine();\n    }\n    void printn(Object o, int n) throws IOException {\n        String s = o.toString();\n        for (int i=0; i<n; ++i) {\n            outputWriter.write(s);\n            if (i!=n-1) outputWriter.write(' ');\n        }\n    }\n    void printnln(Object o, int n) throws IOException {\n        printn(o, n);\n        outputWriter.newLine();\n    }\n    void printArr(int[] arr) throws IOException {\n        for (int i=0; i<arr.length; ++i) {\n            if (i!=0) outputWriter.write(' ');\n            outputWriter.write(Integer.toString(arr[i]));\n        }\n    }\n    void printArr(long[] arr) throws IOException {\n        for (int i=0; i<arr.length; ++i) {\n            if (i!=0) outputWriter.write(' ');\n            outputWriter.write(Long.toString(arr[i]));\n        }\n    }\n    void printArr(double[] arr) throws IOException {\n        for (int i=0; i<arr.length; ++i) {\n            if (i!=0) outputWriter.write(' ');\n            outputWriter.write(Double.toString(arr[i]));\n        }\n    }\n    void printArr(String[] arr) throws IOException {\n        for (int i=0; i<arr.length; ++i) {\n            if (i!=0) outputWriter.write(' ');\n            outputWriter.write(arr[i]);\n        }\n    }\n    void printArr(char[] arr) throws IOException {\n        for (char c: arr) outputWriter.write(c);\n    }\n    void printlnArr(int[] arr) throws IOException {\n        printArr(arr);\n        outputWriter.newLine();\n    }\n    void printlnArr(long[] arr) throws IOException {\n        printArr(arr);\n        outputWriter.newLine();\n    }\n    void printlnArr(double[] arr) throws IOException {\n        printArr(arr);\n        outputWriter.newLine();\n    }\n    void printlnArr(String[] arr) throws IOException {\n        printArr(arr);\n        outputWriter.newLine();\n    }\n    void printlnArr(char[] arr) throws IOException {\n        printArr(arr);\n        outputWriter.newLine();\n    }\n    void halt(Object... o) throws IOException {\n        if (o.length!=0) println(o);\n        outputWriter.flush(); outputWriter.close();\n        System.exit(0);\n    }\n    \n    void debug(Object... o) {\n        if (showDebug) System.err.println(Arrays.deepToString(o));\n    }\n\n\n    public static void main(String[] args) throws Exception {\n        Locale.setDefault(Locale.US);\n        if (!useFiles) {\n            inputReader = new InputReader(System.in, 1<<16);\n            outputWriter = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);\n        } else {\n            inputReader = new InputReader(new FileInputStream(new File(inFile)), 1<<16);\n            outputWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outFile))), 1<<16);\n        }\n        new A().solve();\n        outputWriter.flush(); outputWriter.close();\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "//Edwin Lunando template for online algorithm contest\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n//  class node implements Comparable<node> {\n//\n//    public int a;\n//    public int b;\n//\n//    public int compareTo(node a) {\n//      if (a.b == this.b) {\n//        return a.a - this.a;\n//      } else {\n//        return a.b - this.b;\n//      }\n//    }\n//\n//    public node(int a, int b) {\n//      this.a = a;\n//      this.b = b;\n//    }\n//  }\n\n  private void solve() throws IOException {\n    int n = nextInt();\n    int[] arr = new int[n];\n    int count = 0;\n    for (int x = 0; x < n; x++) {\n      arr[x] = nextInt();\n      count+= arr[x];\n    }\n    Arrays.sort(arr);\n    count /=2;\n    int result = 0, sum = 0;\n    for (int x = arr.length - 1; x >= 0; x--) {\n      sum += arr[x];\n      result++;\n      if (sum > count) {\n        break;\n      }\n    }\n    System.out.println(result);\n  } \n\n  public static void main(String[] args) {\n    try {\n      br = new BufferedReader(new InputStreamReader(System.in));\n      //br = new BufferedReader(new FileReader(\"input.txt\"));\n      out = new PrintWriter(System.out);\n      //out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n      new Main().solve();\n      out.close();\n    } catch (Throwable e) {\n      System.out.println(e);\n      System.exit(239);\n    }\n  }\n  static BufferedReader br;\n  static StringTokenizer st;\n  static PrintWriter out;\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  static int nextInt() throws IOException {\n    return Integer.parseInt(nextToken());\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[] nextIntArray(int n) throws IOException {\n    int[] temp = new int[n];\n    for (int x = 0; x < n; x++) {\n      temp[x] = nextInt();\n    }\n    return temp;\n  }\n\n  static long[] nextLongArray(int n) throws IOException {\n    long[] temp = new long[n];\n    for (int x = 0; x < n; x++) {\n      temp[x] = nextLong();\n    }\n    return temp;\n  }\n\n  static String[] nextArray(int n) throws IOException {\n    String[] temp = new String[n];\n    for (int x = 0; x < n; x++) {\n      temp[x] = nextToken();\n    }\n    return temp;\n  }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n    private MyScanner in;\n    private PrintWriter out;\n\n    private void solve() {\n        int n = in.nextInt();\n        int[] a = new int[n];\n        int all = 0;\n        for (int i = 0; i < n; ++i) {\n            a[i] = in.nextInt();\n            all += a[i];\n        }\n        Arrays.sort(a);\n        int sum = 0, ans = 0;\n        for (int i = n - 1; i >= 0; --i) {\n            sum += a[i];\n            ++ans;\n            if (sum > all - sum) {\n                break;\n            }\n        }\n        out.println(ans);\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        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                    return null;\n                }\n            }\n            return st.nextToken();\n        }\n\n        public String nextLine() {\n            try {\n                st = null;\n                return br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n                return null;\n            }\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public boolean hasNext() {\n            if (st != null && st.hasMoreTokens()) {\n                return true;\n            }\n            try {\n                while (br.ready()) {\n                    st = new StringTokenizer(br.readLine());\n                    if (st != null && st.hasMoreTokens()) {\n                        return true;\n                    }\n                }\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return false;\n        }\n    }\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class codeee {\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        if(n==1){System.out.println(1); return;}\n        int []mas=new int[n];\n        int sum=0;\n        for (int i = 0; i < n; i++) {\n            mas[i]=sc.nextInt();\n            sum+=mas[i];\n        }\n        Arrays.sort(mas);\n        int sum1=0;\n        int ans=0;\n        for(int i=0;i<n;i++){\n            sum1+=mas[n-i-1];\n            if(sum1>(sum-sum1)){\n                ans=i;\n                break;\n            }\n        }\n        System.out.println(ans+1);\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author codeKNIGHT\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n=in.nextInt(),i,sum=0;\n        int a[]=new int[n];\n        for(i=0;i<n;i++)  {\n\n            a[i]=in.nextInt();\n            sum+=a[i];\n        }\n        Arrays.sort(a);\n        int s=0,c=0;\n        for(i=n-1;i>=0;i--)\n        {\n            if(s>sum)\n                break;\n            s+=a[i];\n            sum-=a[i];\n            \n                        c++;\n        }\n        out.println(c);\n\t}\n}\n\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main implements Runnable {\n    PrintWriter out;\n    BufferedReader in;\n    StringTokenizer st;\n    \n    void solve() throws Exception {\n        int n = nextInt();\n        int[] a = new int[n];\n        int sum = 0;\n        for(int i = 0; i < n; ++i) {\n            a[i] = nextInt();\n            sum += a[i];\n        }\n        Arrays.sort(a);\n        int ans = 0, csum = 0;\n        for(int i = n - 1; csum <= sum - csum && i >= 0; i--) {\n            csum += a[i];\n            ans++;\n        }\n        out.println(ans);\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n//          in = new BufferedReader(new FileReader(\"input.txt\"));\n//          out = new PrintWriter(\"output.txt\");\n            solve();\n            out.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n    \n    static public void main(String args[]) throws Exception {\n        (new Main()).run();\n    }\n    \n    int nextInt() {\n        return Integer.parseInt(nextToken());\n    }\n    \n    double nextDouble() {\n        return Double.parseDouble(nextToken());\n    }\n    \n    String nextToken() {\n        while(st == null || !st.hasMoreTokens()) {\n            try {\n                String line = in.readLine();\n                st = new StringTokenizer(line);\n            } catch(Exception e) {\n                return null;\n            }\n        }\n        return st.nextToken();\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Solution {\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        int i;\n        int s = 0;\n        for (i = 0; i < n; i++) {\n            a[i] = scan.nextInt();\n            s += a[i];\n        }\n        Arrays.sort(a);\n        int sum = 0;\n        for (i = n - 1; i > -1; i--) {\n            sum += a[i];\n            if (s - sum < sum) {\n                System.out.println(n - i);\n                return;\n            }\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": " import java.io.BufferedReader;\n    import java.io.IOException;\n    import java.io.InputStreamReader;\n    import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\n    public class Test {\n            static BufferedReader reader;\n            static StringTokenizer tokenizer;\n            static PrintWriter writer;\n\n            static int nextInt() throws IOException {\n                    return Integer.parseInt(nextToken());\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 String nextToken() throws IOException {\n                    while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                            tokenizer = new StringTokenizer(reader.readLine());\n                    }\n                    return tokenizer.nextToken();\n            }\n\n            public static void main(String[] args) throws IOException {\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            }\n\n            private static void solve() throws IOException {\n                int n=nextInt();\n                int[] a=new int[n];\n                int first=0;\n                for (int i=0;i<n;i++)\n                {\n                    a[i]=nextInt();\n                    first+=a[i];\n                }\n                Arrays.sort(a);\n                int ans=1;\n                int last=a[n-1];\n                first-=a[n-ans];\n                while (true)\n                {\n                    if (first<last)\n                        break;\n                    ans++;\n                    last+=a[n-ans];\n                    first-=a[n-ans];\n                }\n                writer.print(ans);\n            }\n\n\n    }", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\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.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class AA implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new AA()).run();\n\n\t}\n\n\tstatic 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\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer str = new StringTokenizer(\"\");\n\tPrintWriter pw;\n\n\tpublic Integer ni() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic Double nd() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic Long nl() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic boolean EOF() {\n\t\ttry {\n\t\t\tif (!br.ready() && !str.hasMoreTokens()) {\n\t\t\t\treturn true;\n\t\t\t}\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 false;\n\t}\n\n\tpublic String nextToken() {\n\t\twhile (!str.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\tstr = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\treturn str.nextToken();\n\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t// try {\n\t\t// br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t// } catch (FileNotFoundException e) {\n\t\t// e.printStackTrace();\n\t\t// }\n\t\t// try {\n\t\t// pw = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t// } catch (IOException e) {\n\t\t// // TODO Auto-generated catch block\n\t\t// e.printStackTrace();\n\t\t// }\n\t\tsolve();\n\t\tpw.close();\n\t}\n\n\tpublic void solve() {\n\n\t\tint n = ni();\n\t\tint[] a = new int[n];\n\t\tint total = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = ni();\n\t\t\ttotal+=a[i];\n\t\t}\n\t\tArrays.sort(a);\n\t\tint c =0;\n\t\tint left=0;\n\t\tfor(int i=n-1; i>=0;i--){\n\t\t\tif (left<=total){\n\t\t\t\tc++;\n\t\t\t\tleft+=a[i];\n\t\t\t\ttotal-=a[i];\n\t\t\t}\n\t\t}\n\t\tpw.print(c);\n\t}\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Round111A {\n\n    public static void main(String[] args) throws IOException {\n        new Round111A().run();\n    }\n\n    public void run() throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        Scanner scanner = new Scanner(reader);\n        PrintWriter writer = new PrintWriter(System.out);\n\n        int n = scanner.nextInt();\n        int sum = 0;\n        Integer[] a = new Integer[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = scanner.nextInt();\n            sum += a[i];\n        }\n        Arrays.sort(a, Collections.reverseOrder());\n\n        int s = 0;\n        int i = 0;\n        while (i < n && (s <= sum / 2)) {\n            s += a[i];\n            i++;\n        }\n\n        writer.print(i);\n\n        scanner.close();\n        writer.close();\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class C111A{\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 nm[] = toIntArray();\n        double a=0.0;\n        double sum=0;\n        for(int i=0;i<n;i++){\n            sum+=nm[i];\n        }\n        a=sum/2;\n        Arrays.sort(nm);\n        int cur=0;\n        int count=0;\n        for(int i=nm.length-1;i>=0;i--){\n            cur+=nm[i];\n            count++;\n            if(cur>a){\n                break;\n            }\n        }\n        System.out.println(count);\n\n\n    }\n\n\n    /****************************************************************/\n    public static int[] toIntArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       int k[]=new int[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Integer.parseInt(str[i]);\n       }\n       return k;\n    }\n    public static int toInt()throws Exception{\n       return Integer.parseInt(br.readLine());\n    }\n    public static long[] toLongArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       long k[]=new long[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Long.parseLong(str[i]);\n       }\n       return k;\n    }\n    public static long toLong()throws Exception{\n       return Long.parseLong(br.readLine());\n    }\n    public static double[] toDoubleArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       double k[]=new double[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Double.parseDouble(str[i]);\n       }\n       return k;\n    }\n    public static double toDouble()throws Exception{\n       return Double.parseDouble(br.readLine());\n    }\n    public static String toStr()throws Exception{\n       return br.readLine();\n    }\n    public static String[] toStrArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       return str;\n    }\n    /****************************************************************/\n\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tpublic A () throws IOException {\n\t\tint N = sc.nextInt();\n\t\tint [] A = new int [N];\n\t\tfor (int n = 0; n < N; ++n)\n\t\t\tA[n] = sc.nextInt();\n\t\tsolve(N, A);\n\t}\n\t\n\tpublic void solve (int N, int [] A) {\n\t\t//start();\n\t\tArrays.sort(A);\n\t\tint S1 = 0;\n\t\tfor (int n = 0; n < N; ++n)\n\t\t\tS1 += A[n];\n\t\t\n\t\tint S2 = 0;\n\t\tfor (int n = N - 1; n >= 0; --n) {\n\t\t\tS2 += A[n];\n\t\t\tif (S2 > S1 - S2)\n\t\t\t\texit(N - n);\n\t\t}\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 A();\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\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\tnewLine();\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", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "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 Solver {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws NumberFormatException, IOException {\n        Solver solver = new Solver();\n        solver.open();\n        solver.solve();\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    public void solve() throws NumberFormatException, IOException {\n        int n = nextInt();\n        \n        int[] ar = new int[n];\n        int sum = 0;\n        \n        for (int i=0;i<n;i++){\n            ar[i]=nextInt();\n            sum+=ar[i];            \n        }\n        \n        Arrays.sort(ar);\n        \n        int me = 0;\n        int k = 0;\n        while (me<=sum){\n            k++;\n            int coin = ar[ar.length-k];\n            me += coin;\n            sum -= coin;\n        }\n        \n        out.println(k);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A implements Runnable {\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\t\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong startTime = System.currentTimeMillis();\n\t\t\tif (ONLINE_JUDGE) {\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\ttok = new StringTokenizer(\"\");\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 endTime = System.currentTimeMillis();\n\t\t\tlong totalMemory = Runtime.getRuntime().totalMemory();\n\t\t\tlong freeMemory = Runtime.getRuntime().freeMemory();\n\t\t\tSystem.err.println(\"Time = \" + (endTime - startTime) + \" ms\");\n\t\t\tSystem.err.println(\"Memory = \" + ((totalMemory - freeMemory) / 1024) + \" KB\");\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\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\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tvoid debug(Object... o) {\n\t\tif (!ONLINE_JUDGE) {\n\t\t\tSystem.err.println(Arrays.deepToString(o));\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new A(), \"\", 256 * 1024 * 1024).start();\n\t}\n\n\tstatic class Utils {\n\n\t\tprivate Utils() {}\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, int 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++] : 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\n\t}\n\t\n//------------------------------------------------------------------------------\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint[] a = new int[n];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = readInt();\n\t\t\tsum += a[i];\n\t\t}\n\t\tUtils.mergeSort(a);\n\t\tint s = 0, c = 0;\n\t\tfor (int i = n-1; i >= 0; i--) {\n\t\t\ts += a[i];\n\t\t\tc++;\n\t\t\tif (2 * s > sum) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(c);\n\t\t\n\t}\n\t\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class con111_A {\n\n    public static void main( final String[] args ) throws IOException {\n        final BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );\n        final int n = Integer.parseInt( br.readLine() );\n        final int[] a = new int[n];\n        final String[] parts = br.readLine().split( \" \" );\n        for ( int i = 0; i < n; ++i ) {\n            a[ i ] = Integer.parseInt( parts[ i ] );\n        }\n        System.out.println( solve( n, a ) );\n    }\n\n    private static int solve( final int n, final int[] a ) {\n        Arrays.sort( a );\n        int sum = 0;\n        for ( int i = 0; i < n; ++i ) {\n            sum += a[ i ];\n        }\n        int res = 0;\n        int ms = 0;\n        for ( int i = n - 1; i >= 0; --i ) {\n            if ( ms > sum / 2 ) {\n                break;\n            } else {\n                ms += a[ i ];\n                ++res;\n            }\n        }\n        return res;\n    }\n\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Twins {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int[] val = new int[n];\n        for (int i=0; i<n; i++)\n            val[i] = in.nextInt();\n        Arrays.sort(val);\n        int sum = 0, count = 0;\n        for (int i=n-1; i>=0; i--)  {\n            count++;\n            sum += val[i];\n            int his = 0;\n            for (int j=0; j<i; j++) his += val[j];\n            if (his < sum)  break;\n        }\n        System.out.println(count);\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Round111ProbA {\n\n    \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        int s =0;\n        for(int i =0 ; i < n;i++)\n        {\n            a[i] = in.nextInt();\n            s += a[i];\n        }\n        Arrays.sort(a);\n        int x =0;\n        int c =0;\n        for(int i =n-1 ; i >-1;i-- )\n        {\n            x +=a[i];\n            s -= a[i];\n            c++;\n            if(x > s)break;\n        }\n        System.out.println(c);\n    }\n    \n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.Math.*;\npublic class A111\n{\n     public static void main(String args[])throws Exception\n     {\n         Scanner in=new Scanner(System.in);\n         // br=new BufferedReader(new InputStreamReader(System.in));\n         PrintWriter pw=new PrintWriter(System.out);\n         int n,i,j,k=0,l;\n         n=in.nextInt();\n         int a[]=new int[n];\n         int sum=0,sum1=0;\n         for(i=0;i<n;i++)\n         {\n            a[i]=in.nextInt(); \n            sum+=a[i];\n            }\n            Arrays.sort(a);\n         for(j=n-1;j>=0;j--)\n         {\n             sum1+=a[j];\n             k++;\n             if(sum1*2>sum)\n             break;\n            }\n            pw.println(k);\n         pw.flush();\n     }\n}", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class round111A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int [] coins = new int [n];\n        for(int i = 0 ; i < n ; ++i)\n            coins[i] = sc.nextInt();\n        Arrays.sort(coins);\n        int ans = (int)1e9;\n        for(int i = 1 ; i <= n ; ++i){\n            int sum1 = 0;\n            int c = 0;\n            int j = n - 1;\n            for(j = n - 1 ; j >= 0 && c < i ; --j, ++c){\n                sum1 += coins[j];\n            }\n            int sum2 = 0;\n            for(int k = 0 ; k <= j ; ++k)\n                sum2 += coins[k];\n            if(sum1 > sum2){\n                System.out.println(i);\n                return;\n            }\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class TaskA {\n\n    public static void main(String[] args) throws Exception {\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt();\n        scanner.nextLine();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = scanner.nextInt();\n        }\n\n        Arrays.sort(a);\n\n        int sum = 0;\n        for (int i = 0; i < n; i++) {\n            sum += a[i];\n        }\n\n        int take = 0, num = 0;\n\n        for (int i = n - 1; i > -1; i--) {\n            num++;\n            take += a[i];\n            sum -= a[i];\n            if (take > sum) {\n                break;\n            }\n        }\n\n        System.out.println(num);\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class nA {\n\n    Scanner in;\n    PrintWriter out;\n\n    void solve() {\n        int n = 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        Arrays.sort(a);\n        int nowsum = 0;\n        int kol = 0;\n        for(int i = n - 1; i >= 0; i--){\n            if(nowsum <= sum / 2){\n                nowsum+=a[i];\n                kol++;\n            }else{\n                break;\n            }\n        }\n        out.println(kol);\n    }\n\n    void run() {\n        in = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        try {\n            solve();\n        } finally {\n            out.close();\n        }\n    }\n\n    public static void main(String[] args) {\n        new nA().run();\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "\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\n/**\n * @author Andrew Porokhin, andrew.porokhin@gmail.com\n */\npublic class Problem111A implements Runnable {\n    void solve() throws NumberFormatException, IOException {\n        // TODO: Write your code here ...\n        final int n = nextInt();\n        final int[] a = new int[n];\n        \n        long sum = 0;\n        for (int i = 0; i < n; i++) {\n            final int nextInt = nextInt();\n            sum += nextInt;\n            a[i] = nextInt;\n        }\n\n        Arrays.sort(a);\n        int currSum = 0;\n        int maxCoins = 0;\n        for (int j = a.length - 1; j >= 0; j--) {\n            currSum += a[j];\n            maxCoins++;\n            if (sum - currSum < currSum) {\n                break;\n            }\n        }\n        System.out.println(maxCoins);\n    }\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) {\n        // Introduce thread in order to increase stack size\n        new Problem111A().run();\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n            solve();\n        } catch (Exception e) {\n            System.exit(9000);\n        } finally {\n            out.flush();\n            out.close();\n        }\n    }\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    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n}\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Testt {\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 Testt().run();\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 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,\n            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++]\n                        : 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    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\n    public void solve() throws IOException {\n        \n        int n  = readInt();\n        int [] a = new int [n];\n        for (int i = 0; i < n; i++){\n            a[i] = readInt();\n        }\n        mergeSort(a);\n        \n        int sum = 0;\n        for (int i = 0; i <n; i++){\n            sum+=a[i];\n        }\n        int sum2 = 0;\n        int ans = 0;\n        for (int i = n-1; i >=0; i-- ){\n            sum2+=a[i];\n            sum-=a[i];\n            ans++;\n            if (sum2>sum){\n                break;\n            }\n        }\n        \n        out.print(ans);\n    }\n/*  for (int i =0; i<n; i++){\n        out.print(a[i]+\" \");\n    }*/\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "complexity": "nlogn", "problem": "160_A. Twins", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.util.Map.*;\npublic class codeforces {\n     static int count =0;\n     static boolean f=false;\n     static int [] arr;\n\tstatic \tPrintWriter pw=new PrintWriter(System.out);\n\tstatic void solve(int index , int mask) {\n\t\tif(index==arr.length) {\n\t\t\tint sum1=0; int sum2=0;\n\t\t\tfor(int i=0;i<arr.length;i++) {\n\t\t\t\tif((mask & 1<<i)!=0) sum1+=arr[i];\n\t\t\t\t\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tsolve(index+1, mask | 1<<index);\n\t\tsolve(index+1, mask);\n\t}\n\tpublic static void main(String [] args) throws IOException, InterruptedException {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint x=sc.nextInt();\n\t\tint y=sc.nextInt();\n\t\tpair [] arr=new pair[x];\n\t\tfor(int i=0;i<x;i++) arr[i]=new pair(i, sc.nextInt(),0);\n\t\tfor(int i=0;i<x;i++) arr[i].y=sc.nextInt();\n\t\tArrays.sort(arr);\n\t\tPriorityQueue<Integer> qq=new PriorityQueue<>();\n\t\t//pw.println(Arrays.toString(arr));\n\t\tLong [] list=new Long [x];\n\t\tlong sum=0; \n\t\tfor(int i=0;i<x;i++) {\n\t\t\tpair w=arr[i];\n\t\t\tif(qq.size()<y) {\n\t\t\t\tqq.add(w.y);\n\t\t\t\tsum+=w.y;\n\t\t\t\tlist[w.i]=sum;\n\n\t\t\t}else if(!qq.isEmpty()) {\n\t\t\t\tsum+=w.y;\n\t\t\t\tlist[w.i]=sum;\n\t\t\t\tint first=qq.poll();\n\t\t\t\tif(w.y>first) {\n\t\t\t\t\tsum-=first;\n\t\t\t\t\tqq.add(w.y);\n\t\t\t\t}else {\n\t\t\t\t\tqq.add(first);\n\t\t\t\t\tsum-=w.y;\n\t\t\t\t}\n\t\t\t} else list[w.i]=(long) w.y;\n\t\t\t//pw.println(qq);\n\t\t}\n\t\tfor(Long w:list) pw.print(w+\" \"); \n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\t\n\tstatic class pair implements Comparable<pair>{\n\t\tString  name; int x,y,i ;\n\t\tpublic pair(String name , int x) {\n\t\t\tthis.name=name; this.x=x;\n\t\t}\n\t\t\n\t\tpublic pair (int i,int x,int y) {\n\t\t\tthis.i=i; this.x=x; this.y=y; \n\t\t}\n\t\tpublic int compareTo(pair o) {\n\t\t\treturn x-o.x;\n\t\t}\n\t\tpublic int compareTo1(pair o) {\n\t\t\tif(!name.equals(o.name))\n\t\t\t\treturn name.compareTo(o.name);\n\t\t\treturn x-o.x;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn i+\" \"+x+\" \"+y;\n\t\t}\n\t}\n\n   static 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\t}", "complexity": "nlogn", "problem": "994_B. Knights of a Polygonal Table", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\npublic class Main {\n\tstatic StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\tpublic static void main(String[] args) {\n\t\tint n=nextInt();\n\t\tint m=nextInt();\n\t\tlong b[]=new long[n];\n\t\tlong g[]=new long[m];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tb[i]=nextInt();\n\t\tfor(int i=0;i<m;i++)\n\t\t\tg[i]=nextInt();\n\t\tArrays.sort(b);\n\t\tArrays.sort(g);\n\t\tif(b[n-1]>g[0])\n\t\t\tSystem.out.println(\"-1\");\n\t\telse if(b[n-1]==g[0]){\n\t\t\tlong sum=0;\n\t\t\tfor(int i=0;i<m;i++)\n\t\t\t\tsum+=g[i];\n\t\t\tfor(int i=0;i<n-1;i++){\n\t\t\t\tsum+=(m*b[i]);\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}else{\n\t\t\tlong sum=0;\n\t\t\tfor(int i=0;i<m;i++)\n\t\t\t\tsum+=g[i];\n\t\t\tsum+=b[n-1];\n\t\t\tsum+=(b[n-2]*(m-1));\n\t\t\tfor(int i=0;i<n-2;i++){\n\t\t\t\tsum+=(m*b[i]);\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n\tstatic int nextInt(){\n\t\ttry {\n\t\t\tst.nextToken();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn (int)st.nval;\n\t}\n}\n", "complexity": "nlogn", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new PrintStream(System.out));\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        int n = Integer.parseInt(st.nextToken());\n        int m = Integer.parseInt(st.nextToken());\n        long[] arrB = new long[n];\n        long[] arrG = new long[m];\n        st=new StringTokenizer(f.readLine());\n        for(int i=0;i<n;i++){\n            arrB[i]=Long.parseLong(st.nextToken());\n        }\n        st=new StringTokenizer(f.readLine());\n        for(int j=0;j<m;j++){\n            arrG[j]=Long.parseLong(st.nextToken());\n        }\n        Arrays.sort(arrB);\n        Arrays.sort(arrG);\n        long ans = 0;\n//        for (int i = 0; i < n; i++) ans += arrB[i] * m;\n//        for (int i = 0; i < m - 1; i++) ans += arrG[i] - arrB[0];\n//        if (arrB[m - 1] != arrB[0]) {\n//            if (arrB.length == 1) {\n//                ans=-1;\n//            }\n//            else ans += arrG[m - 1] - arrB[1];\n//        }\n//        if (arrG[m-1] < arrB[0]) {\n//            ans=-1;\n//        }\n        for(int i=0;i<n;i++){\n            ans+=arrB[i]*(long)m;\n        }\n        for(int i=1;i<m;i++){\n            ans+=arrG[i]-arrB[n-1];\n        }\n        if(arrB[n-1]!=arrG[0]){\n            if(n==1){\n                ans=-1;\n            }\n            else{\n                //smallest g goes to second to last\n                ans+=arrG[0]-arrB[n-2];\n            }\n        }\n        if(arrB[n-1]>arrG[0]){\n            ans=-1;\n        }\n        System.out.println(ans);\n        f.close();\n        out.close();\n    }\n}", "complexity": "nlogn", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "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.LinkedList;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Set;\n\npublic class Main {\n\tprivate static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tString[] s = br.readLine().trim().split(\" \");\n\t\tint n = Integer.parseInt(s[0]);\n\t\tint m = Integer.parseInt(s[1]);\n\t\tlong b[] = new long[n];\n\t\ts = br.readLine().trim().split(\" \");\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tb[i] = Integer.parseInt(s[i]);\n\t\t}\n\t\tlong g[] = new long[m];\n\t\ts = br.readLine().trim().split(\" \");\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tg[i] = Integer.parseInt(s[i]);\n\t\t}\n\t\tArrays.sort(b);\n\t\tArrays.sort(g);\n\t\tif(g[0] < b[n-1]) {\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t\telse if(g[0] == b[n-1]){\n\t\t\tlong ans = 0;\n\t\t\tfor(int i = 0; i < m; i++) {\n\t\t\t\tans += g[i];\n\t\t\t}\n\t\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\t\tans += (m)*b[i];\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\n\t\t}\n\t\telse {\n\t\t\tlong ans = 0;\n\t\t\tfor(int i = 0; i < m; i++) {\n\t\t\t\tans += g[i];\n\t\t\t}\n\t\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\t\tans += (m)*b[i];\n\t\t\t}\n\t\t\tans += b[n-1]-b[n-2];\n\t\t\tSystem.out.println(ans);\n\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "1159_C. The Party and Sweets", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main2 {\n\n    private FastScanner scanner = new FastScanner();\n\n    public static void main(String[] args) {\n        new Main2().solve();\n    }\n\n    private void solve() {\n\n        int n = scanner.nextInt();\n\n\n        int a[][] = new int[n][3];\n\n        for (int i = 0; i < n; i++) {\n            a[i][0] = scanner.nextInt();\n            a[i][1] = scanner.nextInt();\n            a[i][2] = i;\n        }\n\n        int l = -1, r = -1;\n\n        Arrays.sort(a, (o1, o2) -> {\n            if (o1[0] != o2[0]) {\n                return o1[0] - o2[0];\n            } else {\n                return o2[1] - o1[1];\n            }\n        });\n\n        int maxr = -1, maxi = -1;\n        for (int i = 0; i < n; i++) {\n            if (a[i][1] <= maxr) {\n                l = a[i][2] + 1;\n                r = maxi + 1;\n                break;\n            }\n            if (a[i][1] > maxr) {\n                maxi = a[i][2];\n                maxr = a[i][1];\n            }\n        }\n\n        System.out.println(l + \" \" + r);\n\n\n    }\n\n    boolean check(int cnt[][], int[] tcnt, int mid) {\n        boolean ok = true;\n\n        for (int j = 0; j < 27; j++) {\n            if (cnt[mid][j] < tcnt[j]) {\n                ok = false;\n            }\n        }\n        return ok;\n    }\n\n    class Pair {\n        int c, f;\n    }\n\n    class FastScanner {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 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\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Integer[] nextA(int n) {\n            Integer a[] = new Integer[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = scanner.nextInt();\n            }\n            return a;\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            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "nlogn", "problem": "976_C. Nested Segments", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int k = in.nextInt();\n        team[] t = new team[n];\n        for (int i = 0; i < n; i++)\n            t[i] = new team(in.nextInt(), in.nextInt());\n        Arrays.sort(t);\n        int cnt = 0;\n        team tm = t[t.length - k];\n        for (int i = t.length - 1; i >= 0; i--)\n            if (tm.equal(t[i]))\n                cnt++;\n        System.out.println(cnt);\n    }\n\n    static class team implements Comparable<team> {\n        int p, t;\n\n        public team(int pp, int tt) {\n            p = pp;\n            t = tt;\n        }\n\n        @Override\n        public int compareTo(team o) {\n            if (p == o.p)\n                return o.t - t;\n            return p - o.p;\n        }\n\n        public boolean equal(team a) {\n            return a.p == p && a.t == t;\n        }\n    }\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int k = in.nextInt() - 1;\n        Point[] A = new Point[n];\n        for (int i = 0; i < n; i++)\n            A[i] = new Point(in.nextInt(), in.nextInt());\n        Arrays.sort(A, new Comparator<Point>() {\n            public int compare(Point o1, Point o2) {\n                if (o1.x != o2.x)\n                    return o2.x - o1.x;\n                if (o1.y != o2.y)\n                    return o1.y - o2.y;\n                return 0;\n            }\n        });\n        int i = k;\n        int j = k;\n        while (i >= 0 && A[i].x == A[k].x && A[i].y == A[k].y)\n            i--;\n        while (j < n && A[j].x == A[k].x && A[j].y == A[k].y)\n            j++;\n        System.out.println(j - i - 1);\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class CF113_Div2_A implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\t\n\tfinal boolean ONLINE_JUDGE = (System.getProperty(\"ONLINE_JUDGE\") != null);\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new CF113_Div2_A(), \"\", 256 * (1L << 20)).start();\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong startTime = System.currentTimeMillis();\n\t\t\tif (ONLINE_JUDGE) {\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\ttok = new StringTokenizer(\"\");\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t\tlong endTime = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (endTime - startTime));\n\t\t\tlong freeMemory = Runtime.getRuntime().freeMemory();\n\t\t\tlong totalMemory = Runtime.getRuntime().totalMemory();\n\t\t\tSystem.err.println(\"Memory = \" + ((totalMemory - freeMemory) >> 10));\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/** http://pastebin.com/j0xdUjDn */\n\tstatic class Utils {\n\n\t\tprivate Utils() {}\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 final int MAGIC_VALUE = 50;\n\n\t\tprivate static void mergeSort(int[] a, int leftIndex, int rightIndex) {\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, int 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++] : 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\n\t}\n\t\n\tvoid debug(Object... o) {\n\t\tif (!ONLINE_JUDGE) {\n\t\t\tSystem.err.println(Arrays.deepToString(o));\n\t\t}\n\t}\n\n\t// solution\n\n\tclass Team implements Comparable<Team>{\n\t\tint cnt, time;\n\n\t\tpublic Team(int cnt, int time) {\n\t\t\tthis.cnt = cnt;\n\t\t\tthis.time = time;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Team x) {\n\t\t\tif (cnt == x.cnt) return time - x.time;\n\t\t\treturn x.cnt - cnt;\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 + cnt;\n\t\t\tresult = prime * result + time;\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\tTeam other = (Team) obj;\n\t\t\tif (!getOuterType().equals(other.getOuterType()))\n\t\t\t\treturn false;\n\t\t\tif (cnt != other.cnt)\n\t\t\t\treturn false;\n\t\t\tif (time != other.time)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\tprivate CF113_Div2_A getOuterType() {\n\t\t\treturn CF113_Div2_A.this;\n\t\t}\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint k = readInt();\n\t\tk--;\n\t\tTeam[] a = new Team[n];\n\t\tfor (int i =0 ; i < n; i++) {\n\t\t\ta[i] = new Team(readInt(), readInt());\n\t\t}\n\t\tArrays.sort(a);\n\t\tint res = 1;\n\t\tfor (int i = k-1; i >= 0; i--) {\n\t\t\tif (a[k].equals(a[i])) res++;\n\t\t}\n\t\tfor (int i = k+1; i < n; i++) {\n\t\t\tif (a[k].equals(a[i])) res++;\n\t\t}\n\t\tout.print(res);\n\t\t\n\t}\n\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class R113A {\n\n    public static void main(String[] args){\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt(), k = in.nextInt();\n        int[] ind = new int[n];\n        int[] p = new int[n];\n        int[] t = new int[n];\n        for (int i = 0; i < n; i++){\n            ind[i] = i;\n            p[i] = in.nextInt();\n            t[i] = in.nextInt();\n        }\n        //System.out.println(\"erwer\");\n        for (int i = 0; i < n - 1; i++)\n         for (int j = i + 1; j < n; j++){\n             if (p[i] < p[j] || (p[i] == p[j] && t[i] > t[j])){\n                 int tmp = p[i];\n                 p[i] = p[j];\n                 p[j] = tmp;\n                 tmp = t[i];\n                 t[i] = t[j];\n                 t[j] = tmp;\n             }\n         }\n        \n        int i = k - 1;\n//      System.out.println(i+\" \"+p[i]);\n        while (i > 0 && p[i] == p[i - 1] && t[i] == t[i - 1]) i--;\n    //  System.out.println(i);\n        int j = 0;\n        while (i < n - 1 && p[i] == p[i + 1] && t[i] == t[i + 1]) {\n            i++;\n            j++;\n        }\n//      System.out.println(i);\n        System.out.println(j + 1);\n        \n        \n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\n    FastScanner in = new FastScanner(System.in);\n//    FastScanner in = new FastScanner(new File(\"test.txt\"));\n    \n    PrintWriter out = new PrintWriter(System.out);\n\n    public static void main (String[]args) {\n        Main task = new Main();\n        task.solve();\n        task.close();\n    }\n\n    public void close () {\n        in.close();\n        out.close();\n    }\n    \n    public void solve() {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        \n        Team[]teams = new Team[n];\n        \n        for (int i = 0; i < n; i++) {\n            Team t = new Team();\n            t.tasks = in.nextInt();\n            t.penalty = in.nextInt();\n            teams[i] = t;\n        }\n        \n        Arrays.sort(teams);\n        \n        Team t = teams[k - 1];\n        int ans = 0;\n        for (int i = 0; i < teams.length; i++) {\n            if (teams[i].equals(t)) ans++;\n        }\n         \n        System.out.println(ans);\n            \n        \n    }\n    class Team implements Comparable<Team>{\n        int tasks;\n        int penalty;\n        @Override\n        public int hashCode() {\n            final int prime = 31;\n            int result = 1;\n            result = prime * result + getOuterType().hashCode();\n            result = prime * result + penalty;\n            result = prime * result + tasks;\n            return result;\n        }\n        @Override\n        public boolean equals(Object obj) {\n            if (this == obj)\n                return true;\n            if (obj == null)\n                return false;\n            if (getClass() != obj.getClass())\n                return false;\n            Team other = (Team) obj;\n            if (!getOuterType().equals(other.getOuterType()))\n                return false;\n            if (penalty != other.penalty)\n                return false;\n            if (tasks != other.tasks)\n                return false;\n            return true;\n        }\n        @Override\n        public int compareTo(Team o) {\n            if (this.tasks > o.tasks) return -1;\n            else if (this.tasks == o.tasks) {\n                if (this.penalty <= o.penalty) return -1;\n                else return 1;\n            }\n            else return 1;\n        }\n        private Main getOuterType() {\n            return Main.this;\n        }\n        \n    }\n    \n    public int max (int a, int b) {\n        if (a > b) return a;\n        else return b;\n    }\n    \n    \n}\n\n\nclass Algebra {\n    /****\n     *       Number of co-prime numbers on [1, n].\n     *       Number a is Co-prime if gcd (a, n) == 1\n     *       O (sqrt(n))\n     ****/\n    public static int phi(int n) {\n        int result = n;\n        for (int i = 2; i*i <= n; ++i) {\n            if (n % i == 0) {\n                while (n % i == 0) {\n                    n /= i;\n                }\n                result -= result / i;\n            }\n        }\n        if (n > 1) {\n            result -= result / n;\n        }\n        return result;\n    }\n\n    /****\n     *       Raise number a to power of n.\n     *       O (log n)\n     ****/\n    public static int binpow (int a, int n) {\n        int res = 1;\n        while (n != 0) {\n            if ((n & 1) == 1)\n                res *= a;\n            a *= a;\n            n >>= 1;\n        }\n        return res;\n    }\n\n    /****\n     *       Finding the greatest common divisor of two numbers.\n     *       O (log min(a, b))\n     ****/\n    public static int gcd (int a, int b) {\n        return (b != 0) ? gcd (b, a % b) : a;\n    }\n\n    /****\n     *       Finding the lowest common multiple of two numbers.\n     *       O (log min(a, b))\n     ****/\n    public static int lcm (int a, int b) {\n        return a / gcd (a, b) * b;\n    }\n\n    /****\n     *       Eratosthenes Sieve of numbers - [0..n]. True - simple, False - not simple.\n     *       O (n log log n)\n     ****/\n    public static boolean[] sieveOfEratosthenes (int n) {\n        boolean [] prime = new boolean[n + 1];\n        Arrays.fill(prime, true);\n        prime[0] = prime[1] = false;\n        for (int i=2; i<=n; ++i) {\n            if (prime[i]) {\n                if (i * 1L * i <= n) {\n                    for (int j=i*i; j<=n; j+=i) {\n                        prime[j] = false;\n                    }\n                }\n            }\n        }\n        return prime;\n    }    \n}\n\nclass FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n    \n    FastScanner(File f) {\n        try {\n            br = new BufferedReader(new FileReader(f));\n        } catch (FileNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    FastScanner(InputStream in) {\n        br = new BufferedReader(new InputStreamReader(in));\n    }\n    \n    String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (IOException e) {\n                System.err.println(e);\n                return \"\";\n            }\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    double nextDouble() {\n        return Double.parseDouble(next());\n    }\n\n    float nextFloat() {\n        return Float.parseFloat(next());\n    }\n    BigInteger nextBigInt() {\n        return new BigInteger(next());\n    }\n\n    void close() {\n        try {\n            br.close();\n        }\n        catch (IOException e) {\n        }\n    }\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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    \n    \n    class Pair implements Comparable<Pair> {\n\n        int col;\n        int time;\n        int place;\n        \n        public Pair() {\n            \n        }\n        \n        public Pair(int col, int time) {\n            this.col = col;\n            this.time = time;\n        }\n        \n        @Override\n        public int compareTo(Pair arg0) {\n            if (col == arg0.col) {\n                return time - arg0.time;\n            }\n            return arg0.col - col;\n        }\n        \n        \n    }\n    \n    public void solve() throws Exception {\n        int n = sc.nextInt();\n        int k = sc.nextInt();\n        \n        ArrayList<Pair> a = new ArrayList<Pair>();\n        \n        for (int i = 0;i < n; ++ i) {\n            a.add(new Pair(sc.nextInt(), sc.nextInt()));\n        }\n        Collections.sort(a);\n        \n        int place = 1;\n        int placex = 0;\n        int ans2 = 0;\n        int ans1 = 0;\n        \n        for (int i = 0;i < n; ++ i) {\n            if (i > 0 && a.get(i).compareTo(a.get(i - 1)) != 0) {\n                ++ place;\n                ++ placex;\n            } else {\n                ++ placex;\n            }\n            a.get(i).place = place;\n            if (placex == k) {\n                ans1 = place;\n            }\n        }\n        \n        for (int i = 0;i < n; ++ i) {\n            if (a.get(i).place == ans1) {\n                ++ ans2;\n            }\n        }\n        \n        out.println(ans2);      \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}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Solution\n{\n    public static void main(String[] args) throws IOException\n    {\n        new Solution().run();\n    }\n    StreamTokenizer in; \n    Scanner ins;\n    PrintWriter out;\n    \n    int nextInt() throws IOException\n    {\n        in.nextToken();      \n        return (int)in.nval;\n    }\n\n    \n    void run() throws IOException\n    {\n\n        if(System.getProperty(\"ONLINE_JUDGE\")!=null)\n        {\n            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            ins = new Scanner(System.in);\n            out = new PrintWriter(System.out);\n        }\n        else\n        {           \n            in = new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));             \n            ins = new Scanner(new FileReader(\"input.txt\"));\n            out = new PrintWriter(new FileWriter(\"output.txt\"));\n        }\n        int n = nextInt(),k = nextInt();\n        Team[] A = new Team[n];\n        for(int i = 0; i < n; i++)\n        {\n            A[i] = new Team();\n            A[i].p = nextInt(); A[i].t = nextInt();\n        }\n        Arrays.sort(A);\n        \n        \n        k--;\n        int sum = 0;\n        for(int i = 0; i < n; i++)\n            if(A[k].compareTo(A[i])==0)\n                sum++;\n        \n        out.print(sum);\n        out.close();\n    }\n    \n    \n    class Team implements Comparable\n    {\n        public int p,t;\n        public int compareTo(Object obj)\n        {\n            Team a = (Team) obj;\n            if(p>a.p || p==a.p && t<a.t)                          \n                return -1;\n            else                \n                if(p==a.p && t==a.t)\n                    return 0;\n                else\n                    return 1;\n        }\n        \n    }\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\n\npublic class ProblemA {\n\n    private final BufferedReader in;\n    private final PrintStream out;\n    private StringTokenizer tok = new StringTokenizer(\"\");\n    private String nextLine = null;\n\n    public static void main(String[] args) throws Exception {\n        new ProblemA();\n    }\n\n    private ProblemA() throws Exception {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = System.out;\n        start();\n        end();\n    }\n\n    private int nextInt() {\n        return Integer.parseInt(nextWord());\n    }\n\n    private String nextWord() {\n        if (tok.hasMoreTokens()) {\n            return tok.nextToken();\n        } else {\n            while (!tok.hasMoreTokens()) {\n                try {\n                    nextLine = in.readLine();\n                    if (nextLine == null) {\n                        return null;\n                    } else {\n                        tok = new StringTokenizer(nextLine);\n                    }\n                } catch (IOException ex) {\n                    Logger.getLogger(ProblemA.class.getName()).log(Level.SEVERE, null, ex);\n                }\n            }\n            return tok.nextToken();\n        }\n    }\n\n    private void start() {\n        int n = nextInt();\n        int k = nextInt();\n        T[] ts = new T[n];\n        for (int i = 0; i < n; i++) {\n            ts[i] = new T(nextInt(), nextInt());\n        }\n        Arrays.sort(ts, new Comparator<T>() {\n\n            @Override\n            public int compare(T o1, T o2) {\n                if (o1.p > o2.p) {\n                    return -1;\n                }\n                if (o1.p < o2.p) {\n                    return 1;\n                }\n                if (o1.t < o2.t) {\n                    return -1;\n                }\n                if (o1.t > o2.t) {\n                    return 1;\n                }\n                return 0;\n            }\n        });\n        int t = ts[k - 1].t;\n        int p = ts[k - 1].p;\n        int res = 0;\n        for (int i = 0; i < n; i++) {\n            if (ts[i].p == p && ts[i].t == t) {\n                res++;\n            }\n        }\n        out.println(res);\n    }\n\n    class T {\n\n        int p;\n        int t;\n\n        public T(int p, int t) {\n            this.p = p;\n            this.t = t;\n        }\n    }\n\n    private void end() {\n        out.close();\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer tokenizer=null;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tnew Main().execute();\n\t}\n\t\n\tvoid debug(Object...os)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t\n\tint ni() throws IOException\n\t{\n\t\treturn Integer.parseInt(ns());\n\t}\n\t\n\tlong nl() throws IOException \n\t{\n\t\treturn Long.parseLong(ns());\n\t}\n\t\n\tdouble nd() throws IOException \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\t\n\tString ns() throws IOException \n\t{\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n\t\t\ttokenizer = new StringTokenizer(br.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tString nline() throws IOException\n\t{\n\t\ttokenizer=null;\n\t\treturn br.readLine();\n\t}\n\t\t\n\t\n\t//Main Code starts Here\n\tint totalCases, testNum;\t\n\tint k,n;\n\t\n\tvoid execute() throws IOException\n\t{\n\t\ttotalCases = 1;\n\t\tfor(testNum = 1; testNum <= totalCases; testNum++)\n\t\t{\n\t\t\tinput();\n\t\t\tsolve();\n\t\t}\n\t}\n\n\tvoid solve()\n\t{\n\t\tint a = arr[k-1].a;\n\t\tint b = arr[k-1].b;\n\t\t//debug(a,b);\n\t\tint count = 0;\n\t\tfor(int i = 0;i<n;i++)\n\t\t{\n\t\t\tif(arr[i].a == a && arr[i].b == b)\n\t\t\t\tcount++;\n\t\t}\n\t\tSystem.out.println(count);\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\t\n\tclass Pair implements Comparable<Pair>\n{\t\n\tint a,b;\n\tPair(int _a,int _b)\n\t{\n\t\ta=_a;\n\t\tb=_b;\n\t}\n\t\n\tpublic int compareTo(Pair x)\n\t{\n\t\tif(a == x.a) return b-x.b;\n\t\treturn -(a-x.a);\n\t}\n\t\t\n\tpublic boolean equals(Pair x)\n\t{\n\t\treturn a==x.a && b==x.b;\n\t}\n}\n\n\tPair[] arr;\n\tboolean input() throws IOException\n\t{\n\t\tn = ni();\n\t\tk = ni();\n\t\tarr = new Pair[n];\n\t\tfor(int i = 0 ;i<n;i++)\n\t\t{\n\t\t\tPair p =new Pair(ni(),ni());\n\t\t\tarr[i]  = p;\n\t\t}\n\t\tArrays.sort(arr);\n\t\t//debug(arr);\n\t\treturn true;\n\t}\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\nimport static java.lang.Math.*;\n\npublic class Start {\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 Start().run();\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 = 50;\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<Lol>{\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 arg0) {\n                if (arg0.x == x) {\n                    return y-arg0.y;\n                }\n                return arg0.x-x;\n            }\n        \n    }\n\n    public void solve() throws IOException {\n        \n        int n = readInt();\n        int k = readInt();\n        k--;\n        Lol [] a = new Lol [n];\n                \n        for (int i  = 0 ; i  <n; i++){\n            int x = readInt();\n            int y = readInt();\n            a[i] = new Lol(x, y);\n        }\n        Arrays.sort(a);\n        int ans = 1; \n        for (int i =k+1; i>-1; i++){\n            if (i==n) break;\n            if (a[i].x==a[k].x && a[i].y == a[k].y){\n                ans++;\n            }\n            else break;\n        }\n        if (k!=0){\n            for (int i =k-1; i>=0; i--){\n                if (a[i].x==a[k].x && a[i].y == a[k].y){\n                    ans++;\n                }\n                else break;\n            }\n        }\n        out.print(ans);\n        \n        \n        \n    }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.*;\npublic class C{\n\t\tpublic static void main(String args[]) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n=in.nextInt(),key=in.nextInt(),ans=0;\n\t\tint[] a = new int[101], b = new int[101];\n\t\tfor (int i=1;i<=n;i++) {a[i]=in.nextInt();b[i]=in.nextInt();}\n\t\tfor (int i=1;i<n;i++)\n\t\t\tfor (int j=i+1;j<=n;j++)\n\t\t\t\tif (a[i]<a[j] || (a[i]==a[j] && b[i]>b[j])) {\n\t\tint yed = a[i];a[i]=a[j];\t\t\ta[j]=yed;\n\t\tyed = b[i];b[i]=b[j];b[j]=yed;\n\t\t\t\t}\n\t\tint k=0;\n\t\t\n\t\t\n\t\tfor (int i=1;i<=n;i++) {\n\t\t\tif (a[i]==a[i-1] && b[i]==b[i-1]) k++; else \n\t\t\t\t{if (i>key && ans==0) ans = k;k=1;}\n\t\t\t\n\t\t}\n\t\tif (ans == 0) ans = k;\n\t\tSystem.out.println(ans);\n\t\t\n\t\t}\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner r = new Scanner(System.in);\n        int N = r.nextInt();\n        int K = r.nextInt() - 1;\n        \n        T[] a = new T[N];\n        for(int i = 0; i < N; i++)\n            a[i] = new T(r.nextInt(), r.nextInt());\n        \n        Arrays.sort(a, new Comparator<T>() {\n\n            @Override\n            public int compare(T x, T y) {\n                if(x.p > y.p)return -1;\n                else if(x.p == y.p){\n                    if(x.t < y.t)return -1;\n                    else if(x.t == y.t)return 0;\n                    else return 1;\n                }else return 1;\n            }\n        });\n        \n        int ret = 0;\n        for(int i = 0; i < N; i++)\n            if(a[i].p == a[K].p && a[i].t == a[K].t)ret++;\n        \n        System.out.println(ret);\n    }\n}\n\nclass T{\n    int p, t;\n    public T(int pi, int ti){\n        p = pi;\n        t = ti;\n    }\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\npublic class ProblemA {\n    public static class Team {\n        int solved;\n        int penalty;\n        Team(int s, int p) {\n            solved = s;\n            penalty = p;\n        }\n    }\n    \n    public static void main(String[] args) throws IOException {\n        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n        String[] data = s.readLine().split(\" \");\n        int n =  Integer.valueOf(data[0]);\n        int k =  Integer.valueOf(data[1]);\n\n        \n        Team[] t = new Team[n];\n        for (int i = 0 ; i < n ; i++) {\n            String[] line = s.readLine().split(\" \");\n            t[i] = new Team(Integer.valueOf(line[0]), Integer.valueOf(line[1]));\n        }\n        Arrays.sort(t, new Comparator<Team>(){\n            public int compare(Team arg0, Team arg1) {\n                if (arg0.solved != arg1.solved) {\n                    return arg1.solved - arg0.solved;\n                }\n                return arg0.penalty - arg1.penalty;\n            }\n        });\n        \n        \n        int idx = k - 1;\n        int ksol = t[idx].solved;\n        int kpen = t[idx].penalty;\n        int count = 0;\n        for (int i = 0 ; i < n ; i++) {\n            if (t[i].solved == ksol && t[i].penalty == kpen) {\n                count++;\n            }\n        }\n        System.out.println(count);\n    }\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A\n{\n\tstatic class T\n\t{\n\t\tpublic int s,p;\n\t}\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tInputReader sc=new InputReader(System.in);\n\t\tint n=sc.readInt(),k=sc.readInt(),i,j,z;\n\t\tT m[]=new T[n];\n\t\tfor(i=0;i<n;i++) {m[i]=new T();m[i].s=sc.readInt();m[i].p=sc.readInt();}\n\t\tfor(i=0;i<n;i++) for(j=i+1;j<n;j++)\tif(m[i].s<m[j].s){z=m[i].s;m[i].s=m[j].s;m[j].s=z;z=m[i].p;m[i].p=m[j].p;m[j].p=z;}\n\t\tfor(i=0;i<n;i++) for(j=i+1;j<n;j++)\tif(m[i].s==m[j].s&&m[i].p>m[j].p){z=m[i].s;m[i].s=m[j].s;m[j].s=z;z=m[i].p;m[i].p=m[j].p;m[j].p=z;}\n\t\tk--;int s=m[k].s,p=m[k].p,res=0;\n\t\tfor(i=0;i<n;i++){if(m[i].s==s&&m[i].p==p)res++;}\n\t\tSystem.out.println(res);\n\t}\n}\nclass InputReader {\n\tprivate boolean finished = false;\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 int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\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\tprivate String readLine0() {\n\t\tStringBuffer buf = new StringBuffer();\n\t\tint c = read();\n\t\twhile (c != '\\n' && c != -1) {\n\t\t\tif (c != '\\r')\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}\n\t\treturn buf.toString();\n\t}\n\n\tpublic String readLine() {\n\t\tString s = readLine0();\n\t\twhile (s.trim().length() == 0)\n\t\t\ts = readLine0();\n\t\treturn s;\n\t}\n\n\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\tif (ignoreEmptyLines)\n\t\t\treturn readLine();\n\t\telse\n\t\t\treturn readLine0();\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isExhausted() {\n\t\tint value;\n\t\twhile (isSpaceChar(value = peek()) && value != -1)\n\t\t\tread();\n\t\treturn value == -1;\n\t}\n\n\tpublic String next() {\n\t\treturn readString();\n\t}\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class AA {\n\tstatic class O implements Comparable<O> {\n\t\tint problems;\n\t\tint penalty;\n\n\t\tpublic O(int p, int pp) {\n\t\t\tproblems = p;\n\t\t\tpenalty = pp;\n\t\t}\n\n\t\tpublic int compareTo(O arg0) {\n\t\t\tif (problems == arg0.problems) {\n\t\t\t\treturn penalty - arg0.penalty;\n\t\t\t}\n\t\t\treturn -(problems - arg0.problems);\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = r.readLine();\n\t\tString[] sp = s.split(\"[ ]+\");\n\t\tint n = new Integer(sp[0]), k = new Integer(sp[1]) - 1;\n\t\tO[] arr = new O[n];\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\ts = r.readLine();\n\t\t\tsp = s.split(\"[ ]+\");\n\t\t\tarr[i] = new O(new Integer(sp[0]), new Integer(sp[1]));\n\t\t}\n\t\tArrays.sort(arr);\n\n\t\tint res = 1;\n\n\t\tint i = k + 1;\n\t\twhile (i < arr.length && arr[i].problems == arr[k].problems\n\t\t\t\t&& arr[i].penalty == arr[k].penalty) {\n\t\t\ti++;\n\t\t\tres++;\n\t\t}\n\n\t\ti = k - 1;\n\t\twhile (i >= 0 && arr[i].problems == arr[k].problems\n\t\t\t\t&& arr[i].penalty == arr[k].penalty) {\n\t\t\ti--;\n\t\t\tres++;\n\t\t}\n\t\tSystem.out.println(res);\n\n\t}\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R113_D2_A {\n\n    public static void main(String[] args) throws NumberFormatException,\n            IOException {\n        // BufferedReader in = new BufferedReader(new\n        // InputStreamReader(System.in));\n        InputReader4 in = new InputReader4(System.in);\n        int n = in.readInt();\n        int k = in.readInt();\n        p[] inp = new p[n];\n        for (int i = 0; i < inp.length; i++) {\n            inp[i] = new p(in.readInt(), in.readInt());\n        }\n        Arrays.sort(inp);\n        for (int i = 0; i < inp.length;) {\n            int j = i + 1;\n            while (j < inp.length && inp[i].x == inp[j].x\n                    && inp[i].y == inp[j].y) {\n                j++;\n            }\n            int num = j - i;\n            if (k <= num) {\n                System.out.println(num);\n                return;\n            } else\n                k -= num;\n            i = j;\n        }\n    }\n\n    static class p implements Comparable<p> {\n        int x;\n        int y;\n\n        public p(int a, int b) {\n            x = a;\n            y = b;\n        }\n\n        public int compareTo(p o) {\n            if (x > o.x)\n                return -1;\n            if (x < o.x)\n                return 1;\n            return y - o.y;\n        }\n\n    }\n\n    static class InputReader4 {\n        private InputStream stream;\n        private byte[] buf = new byte[1000];\n        private int curChar, numChars;\n\n        public InputReader4(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", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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\tnew 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\t\n\t\treadNextLine();\n\t\tint n=NextInt();\n    \tint k=NextInt()-1;\n\t\tint ret=0;\n\t\tTeam [] t = new Team[n];\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\treadNextLine();\n\t\t\tt[i]=new Team(NextInt(), NextInt());\n\t\t}\n\t\tArrays.sort(t);\n\t\tint ti=t[k].t, p=t[k].p;\n\t\t\n\t\tfor(int i=0; i<n; i++)\n\t\t\tif(t[i].t==ti&&t[i].p==p)ret++;\n\t\t\n\t\t\n\t\t\n\t\t\n\t\tSystem.out.print(ret);\n        closeInput();\t\t\n\t}\n\t\n\tprivate class Team implements Comparable<Team>\n\t{\n\t\tint p,t;\n\t\tTeam(int p, int t)\n\t\t{\n\t\t\tthis.p=p;\n\t\t\tthis.t=t;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Team d)\n\t\t{\n\t\t\treturn 10000*(d.p-p)+t-d.t;\n\t\t}\n\t}\n\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class C113A{\n    static BufferedReader br;\n    public static void main(String args[])throws Exception{\n        br=new BufferedReader(new InputStreamReader(System.in));\n        int nm[]=toIntArray();\n        int n=nm[0];\n        int k=nm[1];\n        Pai p[]=new Pai[n];\n        for(int i=0;i<n;i++){\n            nm=toIntArray();\n            p[i]=new Pai(nm[0],nm[1]);\n        }\n        Arrays.sort(p);\n        int count=0;\n        for(int i=0;i<n;i++){\n            if(p[k-1].first==p[i].first && p[k-1].second==p[i].second){\n                count++;\n            }\n        }\n        System.out.println(count);\n\n    }\n\n\n    /****************************************************************/\n    public static int[] toIntArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       int k[]=new int[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Integer.parseInt(str[i]);\n       }\n       return k;\n    }\n    public static int toInt()throws Exception{\n       return Integer.parseInt(br.readLine());\n    }\n    public static long[] toLongArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       long k[]=new long[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Long.parseLong(str[i]);\n       }\n       return k;\n    }\n    public static long toLong()throws Exception{\n       return Long.parseLong(br.readLine());\n    }\n    public static double[] toDoubleArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       double k[]=new double[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Double.parseDouble(str[i]);\n       }\n       return k;\n    }\n    public static double toDouble()throws Exception{\n       return Double.parseDouble(br.readLine());\n    }\n    public static String toStr()throws Exception{\n       return br.readLine();\n    }\n    public static String[] toStrArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       return str;\n    }\n    /****************************************************************/\n\n}\nclass Pai implements Comparable<Pai> {\n\n    int first;\n    int second;\n\n    public Pai(int f, int s) {\n        first = f;\n        second = s;\n    }\n\n    public int compareTo(Pai p) {\n        int ret = 0;\n        if (first < p.first) {\n            ret = 1;\n\n        } else if (first > p.first) {\n            ret = -1;\n\n        } else {\n            if(second<p.second){\n                ret=-1;\n            }\n            else if(second>p.second){\n                ret=1;\n            }\n            else ret=0;\n        }\n        return ret;\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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    class Team implements Comparable<Team>{\n        int ac;\n        int penalty;\n        \n        public Team(int ac, int penalty) {\n            this.ac = ac;\n            this.penalty = penalty;\n        }\n\n        @Override\n        public int compareTo(Team o) {\n            if (ac != o.ac)\n                return ac > o.ac ? -1 : 1;\n            return (penalty == o.penalty) ? 0 : (penalty < o.penalty ? -1 : 1);\n        }\n        \n    }\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int k = nextInt() - 1;\n        \n        Team[] a = new Team[n];\n        for (int i = 0; i < n; i++)\n            a[i] = new Team(nextInt(), nextInt());\n        \n        Arrays.sort(a);\n        for (int i = 0; i < n;) {\n            int j = i;\n            while (j < n && a[j].compareTo(a[i]) == 0)\n                j++;\n            if (i <= k && k < j) {\n                out.println(j - i);\n                return;\n            }\n            i = j;\n        }\n    }\n\n    void inp() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new A().inp();\n    }\n\n    String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return null;\n            }\n        }\n        return st.nextToken();\n    }\n\n    String nextString() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            eof = true;\n            return null;\n        }\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport static java.lang.Math.*;\n\npublic class P166A {\n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int k = in.nextInt();\n        Point[] P = new Point[n];\n        for(int i=0; i<n; i++)\n            P[i] = new Point(in.nextInt(), in.nextInt());\n        Arrays.sort(P, new Comparator<Point>() {\n            public int compare(Point A, Point B) {\n                if(A.x != B.x) return B.x-A.x;\n                return A.y - B.y;\n            }\n        });\n        int cnt = 0;\n        Point ans = P[k-1];\n        for(int i=0; i<n; i++) {\n            if(P[i].x == ans.x && P[i].y==ans.y)\n                cnt++;\n        }\n        System.out.println(cnt);\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] argv) {\n\t\tnew Main().run();\n\t}\n\n\tvoid run() {\n\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\ttry {\n\t\t\tsolve();\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tPrintWriter out;\n\tScanner in;\n\n\tclass Pair {\n\t\tint x;\n\t\tint y;\n\n\t\tPair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y;\n\t\t}\n\t}\n\n\tint[] readArr(int size) {\n\t\tint[] a = new int[size];\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\treturn a;\n\t}\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tPair[] a = new Pair[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Pair(in.nextInt(), in.nextInt());\n\t\t}\n\t\tArrays.sort(a, new Comparator<Pair>() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Pair p1, Pair p2) {\n\t\t\t\tif (p2.x != p1.x) {\n\t\t\t\t\treturn p2.x - p1.x;\n\t\t\t\t}\n\t\t\t\treturn p1.y - p2.y;\n\t\t\t}\n\t\t});\n\t\tint cnt = 1;\n\t\tint ans = 0;\n\t\tint[] res = new int[n];\n\t\tres[0] = 1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif (!(a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)) {\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t\tres[i] = cnt;\n\t\t\t//out.println(a[i] + \" * \" + cnt);\n\t\t}\n\t\tint el = res[k - 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (res[i] == el) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\n\t}\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\n\npublic class A {\n\n    static StreamTokenizer st;\n    static PrintWriter pw;\n    static class Sort implements Comparable<Sort> {\n        int x,y;\n        public int compareTo(Sort arg0) {\n            if (this.x==arg0.x)\n                return this.y-arg0.y;\n            return -(this.x-arg0.x);\n        }\n    }\n    public static void main(String[] args) throws IOException{\n        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int n = nextInt();\n        int k = nextInt();\n        Sort[]a = new Sort[n+1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = new Sort();\n            a[i].x = nextInt();\n            a[i].y = nextInt();\n        }\n        Arrays.sort(a,1, n+1);\n//      for (int i = 1; i <= n; i++) {\n//          System.out.println(a[i].x+\" \"+a[i].y);\n//      }\n//      int plase = 1;\n//      if (k==1) {\n//          int ans = 0;\n//          for (int j = 1; j <= n; j++) {\n//              if (a[j].x==a[1].x && a[j].y ==a[1].y) {\n//                  ans++;\n//              }\n//          }\n//          System.out.println(ans);\n//          return;\n//      }\n//      for (int i = 2; i <= n; i++) {\n//          if (a[i].x==a[i-1].x && a[i].y==a[i-1].y) {\n//              \n//          }\n//          else {\n//              plase++;\n//              if (plase==k) {\n//                  int ans = 0;\n//                  for (int j = 1; j <= n; j++) {\n//                      if (a[j].x==a[i].x && a[j].y ==a[i].y) {\n//                          ans++;\n//                      }\n//                  }\n//                  System.out.println(ans);\n//                  return;\n//              }\n//          }\n//      }\n        int ans = 0;\n        for (int i = 1; i <= n; i++) {\n            if (a[i].x==a[k].x && a[i].y==a[k].y)\n                ans++;\n        }\n        System.out.println(ans);\n        pw.close();\n    }\n    private static int nextInt() throws IOException{\n        st.nextToken();\n        return (int) st.nval;\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n  = scan.nextInt();\n\t\tint k = scan.nextInt()-1;\n\t\tteam[] t = new team[n];\n\t\tfor(int i = 0 ;i  < n ; i++)\n\t\t\tt[i] = new team(scan.nextInt(), scan.nextInt());\n\t\tArrays.sort(t);\n\t\tint a =0;\n\t\tint b = 0;\n\t\twhile(k+a < t.length-1 && t[k+a+1].compareTo(t[k]) == 0)\n\t\t\ta++;\n\t\twhile(k-b > 0 && t[k-b-1].compareTo(t[k]) == 0)\n\t\t\tb++;\n\t\tSystem.out.println(a+b+1);\n\t}\n\n}\nclass team implements Comparable<team>\n{\n\tint p;\n\tint t;\n\tpublic team(int pp , int tt)\n\t{\n\t\tp = pp;\n\t\tt= tt;\n\t}\n\t@Override\n\tpublic String toString()\n\t{\n\t\treturn p+\" \"+t;\n\t}\n\t@Override\n\tpublic int compareTo(team e)\n\t{\n\t\tint a = e.p-p;\n\t\tif(a == 0)\n\t\t{\n\t\t\treturn  t-e.t;\n\t\t}else\n\t\t\treturn a;\n\t}\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        int n = input.nextInt();\n        int k = input.nextInt() - 1 ;\n        int a[][] = new int[n][2];\n        for (int i = 0;i <n; i++) {\n            a[i][0]=input.nextInt();\n            a[i][1]=input.nextInt();\n        }\n        for (int i = 0; i<n; i++) {\n            for (int j=i+1; j<n; j++) {\n                if (a[i][0]<a[j][0]) {\n                    int x=a[i][0];\n                    int y=a[i][1];\n                    a[i][0]=a[j][0];\n                    a[i][1]=a[j][1];\n                    a[j][0]=x;\n                    a[j][1]=y;\n                    \n                }\n            }\n        }\n        for (int i = 0; i<n; i++) {\n            for (int j=i+1; j<n; j++) {\n                if ((a[i][1]>a[j][1])&&(a[i][0]==a[j][0])) {\n                    int x=a[i][0];\n                    int y=a[i][1];\n                    a[i][0]=a[j][0];\n                    a[i][1]=a[j][1];\n                    a[j][0]=x;\n                    a[j][1]=y;\n                    \n                }\n            }\n        }\n        int x = a[k][0];\n        int y = a[k][1];\n        int s = 0;\n        for (int i = 0; i<n; i++) {\n            if ((a[i][0]==x)&&(a[i][1]==y)) {\n                s++;\n            }\n        }\n        System.out.println(s);\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "//package codeforces;\n\nimport java.util.*;\n\npublic class Main {\n    class team implements Comparable<team>{\n        int pro,time;\n\n        public int compareTo(team oth) {\n            if(pro>oth.pro)\n                return -1;\n            if(pro==oth.pro&&time<oth.time)\n                return -1;\n            // TODO Auto-generated method stub\n            return 1;\n        }\n        \n    }\n    Scanner scan=new Scanner(System.in);\n    void run(){\n        int n=scan.nextInt();\n        int k=scan.nextInt()-1;\n        team tm[]=new team[n];\n        for(int i=0;i<n;i++){\n            tm[i]=new team();\n            tm[i].pro=scan.nextInt();\n            tm[i].time=scan.nextInt();\n        }\n        Arrays.sort(tm);\n        int sum=0;\n        \n        for(int i=k;i>=0;i--)\n            if(tm[i].pro==tm[k].pro&&tm[i].time==tm[k].time)\n                sum++;\n        for(int i=k;i<n;i++)\n            if(tm[i].pro==tm[k].pro&&tm[i].time==tm[k].time)\n                sum++;\n        System.out.println(sum-1);\n    }\n    public static void main(String args[]) {\n         \n        new Main().run();\n    }\n\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.MathContext;\n\n\npublic class Main {\n\n    private void solve() {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        final int[] p = new int[n];\n        final int[] t = new int[n];\n        for(int i =0 ; i < n; ++i) {\n            p[i] = in.nextInt();\n            t[i] = in.nextInt();\n        }\n        Integer[] ord = new Integer[n];\n        for(int i = 0; i < n; ++i)\n            ord[i] = i;\n        for(int i = 0; i < n; ++i) {\n            for(int j = 0; j < n - 1; ++j) {\n                if (Less(ord[j], ord[j + 1], p, t)) {\n                    Integer tx = ord[j];\n                    ord[j] = ord[j + 1];\n                    ord[j + 1] = tx;\n                }\n            }\n        }\n        \n        \n        \n        for(int i = 0, j = 0; i < n; i = j) {\n            for(j = i; j < n && p[ord[i]] == p[ord[j]] && t[ord[i]] == t[ord[j]]; ++j) ;\n            int first = i+1;\n            int second = j;\n            if (first <= k && k <= second) {\n                out.print(j - i);\n                return ;\n            }\n        }\n        out.print(0);\n    }\n    private boolean Less(Integer i, Integer j, int[] p, int[] t) {\n        return p[i] < p[j] || p[i] == p[j] && t[i] > t[j];\n    }\n    private void run() {\n        try {\n            in = new FastScanner();\n            out = new PrintWriter(new OutputStreamWriter(System.out));\n            solve();\n            out.flush();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n    \n    public static void main(String[] args) {\n        new Main().run();\n    }\n    FastScanner in;\n    PrintWriter out;\n    class FastScanner {\n        public BufferedReader reader;\n        private StringTokenizer tokenizer;\n        public FastScanner(String file) {\n            try {\n                reader = new BufferedReader(new FileReader(new File(file)));\n                tokenizer = null;\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n        \n        public FastScanner() {\n            try {\n                reader = new BufferedReader(new InputStreamReader(System.in));\n                tokenizer = null;\n            } catch (Exception e) {\n                e.printStackTrace();\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}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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.Locale;\nimport java.util.StringTokenizer;\n\npublic class A {\n\t\n\tprivate class Pair {\n\t\tpublic final int prob;\n\t\tpublic final int time;\n\t\t\n\t\tpublic Pair(int prob, int time) {\n\t\t\tthis.prob = prob;\n\t\t\tthis.time = time;\n\t\t}\n\t}\n\t\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\t\n\t\tPair[] p = new Pair[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tp[i] = new Pair(nextInt(), nextInt());\n\t\t}\n\t\t\n\t\tArrays.sort(p, new Comparator<Pair>() {\n\t\t\t@Override\n\t\t\tpublic int compare(Pair o1, Pair o2) {\n\t\t\t\tif (o1.prob == o2.prob) {\n\t\t\t\t\treturn o1.time - o2.time;\n\t\t\t\t}\n\t\t\t\treturn o2.prob - o1.prob;\n\t\t\t}\n\t\t});\n\t\t\n\t\tint time = p[k - 1].time;\n\t\tint prob = p[k - 1].prob;\n\t\tint res = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (p[i].time == time && p[i].prob == prob) {\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\tprintln(res);\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 A().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}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Round113_A {\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() - 1;\n        Obe[] a = new Obe[n];\n        for (int i = 0; i < n; i++)\n            a[i] = new Obe(in.nextInt(), in.nextInt());\n\n        Arrays.sort(a);\n        int c = 0;\n\n        int p = 0, d = 0;\n        if (k > -1 && k < n) {\n            c = 1;\n            p = a[k].p;\n            d = a[k].d;\n        } else {\n            System.out.println(c);\n            return;\n        }\n        for (int i = k + 1; i < n; i++) {\n            if (a[i].p == p && a[i].d == d)\n                c++;\n        }\n        for (int i = k - 1; i > -1; i--) {\n            if (a[i].p == p && a[i].d == d)\n                c++;\n        }\n        System.out.println(c);\n    }\n\n}\n\nclass Obe implements Comparable<Obe> {\n\n    int p, d;\n\n    public Obe(int pe, int de) {\n        p = pe;\n        d = de;\n    }\n\n    @Override\n    public int compareTo(Obe o) {\n        int x = new Integer(o.p).compareTo(this.p);\n        if (x != 0)\n            return x;\n        return new Integer(this.d).compareTo(o.d);\n    }\n\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.List;\nimport java.util.Scanner;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\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 @zhendeaini6001\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n     class Pair{\n\t\tpublic int a;\n\t\tpublic int b;\n\t\tpublic Pair(int a, int b) {\n\t\t\t// TODO Auto-generated constructor stub\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\t}\n\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int k = in.nextInt();  --k;\n        ArrayList<Pair> list = new ArrayList<Pair>();\n\t\tfor (int i = 1; i <= n; ++i){\n            int num = in.nextInt();\n            int pen = in.nextInt();\n\t\t\tPair t = new Pair(num, pen);\n\t\t    list.add(t);\n        }\n        Collections.sort(list, new Comparator<Pair>(){\n\t\t\t\tpublic int compare(Pair o1, Pair o2){\n\t\t\t\t\tif (o1.a != o2.a){\n\t\t\t\t\t\treturn (o2.a - o1.a);\n\t\t\t\t\t}\n\t\t\t\t\treturn (o1.b - o2.b);\n\t\t\t\t}\n\t\t});\n\n        int res = 1;\n        Pair compare = list.get(k);\n        int i = k - 1;\n        while (i >= 0){\n            Pair t = list.get(i);\n            if (t.a == compare.a && t.b == compare.b){\n                --i;\n                ++res;\n                continue;\n            }else{\n                break;\n            }\n        }\n       i = k + 1;\n        while (i < list.size()){\n            Pair t = list.get(i);\n            if (t.a == compare.a && t.b == compare.b){\n                ++res; ++i;\n                continue;\n            }else{\n                break;\n            }\n        }\n        out.println(res);\n       return;\n    }\n}\n\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class P113A {\n\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        PrintStream out = System.out;\n        //CODING TAIM\n\n        int n = sc.nextInt();\n        int k = sc.nextInt();\n        List<Team> l = new ArrayList<Team>();\n        for (int i = 0; i < n; i++) {\n            l.add(new Team(sc.nextInt(), sc.nextInt()));\n        }\n        Collections.sort(l, new Comparator<Team>() {\n                public int compare(Team a, Team b) {\n                    if (a.s == b.s)\n                        return a.t - b.t;\n                    return b.s - a.s;\n                }\n                });\n        int f = k - 1;\n        int la = k - 1;\n        Team p = l.get(k - 1);\n        while (la < n && l.get(la).s == p.s && l.get(la).t == p.t) la++;\n        while ( f >= 0 && l.get(f).s == p.s && l.get(f).t == p.t) f--;\n        out.println(la - f - 1);\n    }\n\n  static   class Team {\n        int s;\n        int t;\n        public Team(int a, int b) { s = a; t = b; }\n    }\n\n\n\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class A\n{\n    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer st = null;\n\n    private void solve() throws IOException\n    {\n        int n = nextInt();\n        int k = nextInt();\n        int p[] = new int[n];\n        int t[] = new int[n];\n        for(int i = 0; i < n; i++)\n        {\n            p[i] = nextInt();\n            t[i] = nextInt();\n        }\n        \n        for(int i = 0; i < n; i++)\n        {\n            for(int j = i + 1; j < n; j++)\n            {\n                if(p[i] < p[j] || (p[i] == p[j] && t[i] > t[j]))\n                {\n                    int tmp = p[i];\n                    p[i] = p[j];\n                    p[j] = tmp;\n                    tmp = t[i];\n                    t[i] = t[j];\n                    t[j] = tmp;\n                }\n            }\n            \n        }\n        \n        int pN = p[k - 1];\n        int tN = t[k - 1];\n        int counter = 0;\n        for(int i = 0; i < n; i++)\n        {\n            if(p[i] == pN && t[i] == tN)\n            {\n                counter++;\n            }\n            \n        }\n        \n        System.out.println(counter);\n    }\n\n    String nextToken() throws IOException\n    {\n        if (st == null || !st.hasMoreTokens())\n        {\n            st = new StringTokenizer(bf.readLine());\n        }\n        \n        return st.nextToken();\n    }\n\n    int nextInt() throws IOException\n    {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException\n    {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException\n    {\n        return Double.parseDouble(nextToken());\n    }\n\n    public static void main(String args[]) throws IOException\n    {\n        new A().solve();\n    }\n    \n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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.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 Nova\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\n    class Team implements Comparable<Team> {\n        int solved = 0;\n        int penalty = 0;\n\n        Team(int solved, int penalty) {\n            this.solved = solved;\n            this.penalty = penalty;\n        }\n\n        public int compareTo(Team o) {\n            return this.solved == o.solved ? this.penalty - o.penalty : -(this.solved - o.solved);\n        }\n\n        public boolean equals(Object obj) {\n            if (obj instanceof Team) {\n                Team o = (Team) obj;\n                return ((this.solved == o.solved) && (this.penalty == o.penalty));\n            }\n            return false;\n        }\n    }\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        Team[] teams = new Team[n];\n        for (int i = 0; i < n; i++)\n            teams[i] = new Team(in.nextInt(), in.nextInt());\n        Arrays.sort(teams);\n\n        int[] top = new int[n];\n        int[] map = new int[n];\n        int cur = -1;\n        for (int i = 0; i < n; i++) {\n            if (i == 0 || !teams[i].equals(teams[i - 1])) cur = i;\n            top[cur]++;\n            map[i] = cur;\n        }\n        out.println(top[map[k - 1]]);\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\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            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", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\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(), k = in.nextInt();\n        int x[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            int p = in.nextInt(), t = in.nextInt();\n            x[i] = (50 - p) * 100 + t;\n        }\n        Arrays.sort(x);\n        int cnt = 0;\n        for (int q: x)\n            if (q == x[k - 1]) cnt++;\n        System.out.println(cnt);\n    }\n\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n    static class Team implements Comparable<Team> {\n        int pr;\n        int time;\n        int id;\n\n        public Team(int P, int T, int I) {\n            pr = P;\n            time = T;\n            id = I;\n        }\n\n        @Override\n        public int compareTo(Team t) {\n            return pr != t.pr ? t.pr - pr : time != t.time ? time - t.time : id - t.id;\n        }\n\n    }\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(System.out);\n\n        StringTokenizer st = new StringTokenizer(in.readLine());\n        int n = Integer.parseInt(st.nextToken());\n\n        int k = Integer.parseInt(st.nextToken());\n\n        Team[] a = new Team[n];\n        int[] c = new int[n + 1];\n\n        for (int i = 0; i < n; i++) {\n            st = new StringTokenizer(in.readLine());\n            int p = Integer.parseInt(st.nextToken());\n            int t = Integer.parseInt(st.nextToken());\n\n            a[i] = new Team(p, t, i);\n        }\n\n        Arrays.sort(a);\n        int prev = 1;\n        c[1]++;\n\n        for (int i = 1; i < n; i++) {\n            if (a[i].pr == a[i - 1].pr && a[i].time == a[i - 1].time)\n                for (int j = i + 1; j >= prev; j--)\n                    c[j] = i + 2 - prev;\n            else {\n                prev = i + 1;\n                c[prev] = 1;\n            }\n        }\n\n        out.println(c[k]);\n        out.close();\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Teams {\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n    Random rnd;\n    \n    class Pair implements Comparable<Pair> {\n        int a, b;\n\n        public Pair(int 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 -(a - p.a);\n            }\n            \n            return (b - p.b);\n        }\n    }\n\n    void solve() throws IOException {\n        int n = nextInt(), k = nextInt();\n        \n        Pair[] ps = new Pair[n];\n        \n        for(int i = 0; i < n; i++)\n            ps[i] = new Pair(nextInt(), nextInt());\n        \n        Arrays.sort(ps);\n        \n        int curPlace = 1, res = 0;\n        \n        int[] places = new int[n];\n        \n        for(int i = 0; i < n; i++) {\n            if(i - 1 >= 0 && ps[i].compareTo(ps[i - 1]) != 0)\n                ++curPlace;\n            \n            places[i] = curPlace;\n        }\n        \n        for(int i = 0; i < n; i++) {\n            if(places[i] == places[k - 1])\n                ++res;\n        }\n        \n        out.println(res);\n    }\n\n    public static void main(String[] args) {\n        new Teams().run();\n    }\n\n    public void run() {\n        try {\n            final String className = this.getClass().getName().toLowerCase();\n\n            try {\n                in = new BufferedReader(new FileReader(className + \".in\"));\n                out = new PrintWriter(new FileWriter(className + \".out\"));\n            } catch (FileNotFoundException e) {\n                in = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(System.out);\n            }\n\n            rnd = new Random();\n\n            solve();\n\n            out.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n            System.exit(42);\n        }\n    }\n\n    String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            String line = in.readLine();\n\n            if (line == null)\n                return null;\n\n            st = new StringTokenizer(line);\n        }\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}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class A2 {\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        int n = next(), k = next()-1;\n        int x[] = new int[n];\n        for (int i = 0;i < n;i++) x[i] = (100-next())*100+next();\n        Arrays.sort(x);\n        int res = 0, t = x[k];\n        for (int i = 0;i < n;i++) if (t == x[i]) res++;\n\n        out.println(res);\n\n\n        out.println();\n\t\tout.close();\n\t}\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A113 {\n\n    public static void main(String[] args) {\n        new A113().run();\n    }\n    \n    public void run() {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int k = in.nextInt();\n        Team[] teams = new Team[n];\n        for (int i = 0; i < teams.length; i++) {\n            teams[i] = new Team(in.nextInt(), in.nextInt());\n        }\n        Arrays.sort(teams);\n        int counter = 1;\n        int index = k-2;\n        while (index >= 0 && teams[index].p == teams[k-1].p && teams[index].t == teams[k-1].t) {\n            index--;\n            counter++;\n        }\n        index = k;\n        while (index < n && teams[index].p == teams[k-1].p && teams[index].t == teams[k-1].t) {\n            index++;\n            counter++;\n        }\n        System.out.println(counter);\n    }\n    \n    private class Team implements Comparable<Team> {\n        int p;\n        int t;\n        \n        public Team(int pp, int tt) {\n            p = pp; t = tt;\n        }\n\n        @Override\n        public int compareTo(Team o) {\n            if (o.p - this.p == 0)\n                return this.t - o.t;\n            return o.p - this.p;\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author codeKNIGHT\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n        int n=in.nextInt(),k=in.nextInt()-1,i;\n        scores a[]=new scores[n];\n        for(i=0;i<n;i++)\n            a[i]=new scores(in.nextInt(),in.nextInt());\n        Arrays.sort(a);\n        \n        int c=1;\n        for(i=k-1;i>=0;i--)\n        {\n            if(a[i].p==a[k].p&&a[i].t==a[k].t)\n                c++;\n            else break;\n        }\n        for(i=k+1;i<n;i++)\n        {\n            if(a[i].p==a[k].p&&a[i].t==a[k].t)\n                c++;\n            else break;\n        }\n        out.println(c);\n\n\t}\n    class scores implements Comparable<scores>\n    {\n        int p,t;\n        public scores(int p,int t)\n        {\n            this.p=p;\n            this.t=t;\n        }\n        public int compareTo(scores a)\n        {\n            if(a.p>this.p)\n                return 1;\n            if(a.p==this.p&&a.t<this.t)\n                return 1;\n            return -1;\n        }\n    }\n}\n\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class P166A \n{\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner myScanner = new Scanner(System.in);\n\t\tint n = myScanner.nextInt();\n\t\tint k = myScanner.nextInt();\n\t\tTeam[] queue = new Team[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tqueue[i] = new Team(myScanner.nextInt(), myScanner.nextInt());\n\t\t}\n\t\tArrays.sort(queue);\n\t\t\n\t\tint counter = 0;\n\t\tint i = 0;\n\t\tint p = -1;\n\t\tint t = -1;\n\t\tfor (; i < k; i++)\n\t\t{\n\t\t\tif (p == queue[i].problems && t == queue[i].penalty)\n\t\t\t\tcounter++;\n\t\t\telse\n\t\t\t{\n\t\t\t\tp = queue[i].problems;\n\t\t\t\tt = queue[i].penalty;\n\t\t\t\tcounter = 1;\n\t\t\t}\n\t\t}\n\t\tfor (; i < n; i++)\n\t\t{\n\t\t\tif (p == queue[i].problems && t == queue[i].penalty)\n\t\t\t\tcounter++;\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\t\tSystem.out.println(counter);\n\t}\n\n\tstatic class Team implements Comparable<Team>\n\t{\n\t\tint problems;\n\t\tint penalty;\n\t\t\n\t\tpublic Team(int problems, int penalty)\n\t\t{\n\t\t\tthis.problems = problems;\n\t\t\tthis.penalty = penalty;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Team t)\n\t\t{\n\t\t\tif (problems > t.problems) return -1;\n\t\t\telse if (problems < t.problems) return 1;\n\t\t\telse if (penalty > t.penalty) return 1;\n\t\t\telse if (penalty < t.penalty) return -1;\n\t\t\telse return 0;\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport 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.StringTokenizer;\n\npublic class A {\n\n    private void solve() throws IOException {\n        int n = nextInt();\n        int k = nextInt();\n        Point[] p = new Point[n];\n        for (int i = 0; i < n; i++)\n            p[i] = new Point(nextInt(), nextInt());\n        Arrays.sort(p, new Comparator<Point>() {\n\n            @Override\n            public int compare(Point o1, Point o2) {\n                if (o1.x == o2.x) return o1.y - o2.y;\n                return o2.x - o1.x;\n            }\n        });\n        \n        Point cur = p[k - 1];\n        int res = 0;\n        for (int i = 0; i < p.length; i++) {\n            if (p[i].x == cur.x && p[i].y == cur.y) res++;\n        }\n        pl(res);\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\n    public void run() {\n        try {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            solve();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(nextToken());\n    }\n\n    String nextToken() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    void p(Object... objects) {\n        for (int i = 0; i < objects.length; i++) {\n            if (i != 0)\n                writer.print(' ');\n            writer.flush();\n            writer.print(objects[i]);\n            writer.flush();\n        }\n    }\n\n    void pl(Object... objects) {\n        p(objects);\n        writer.flush();\n        writer.println();\n        writer.flush();\n    }\n\n    int cc;\n\n    void pf() {\n        writer.printf(\"Case #%d: \", ++cc);\n        writer.flush();\n    }\n\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\n\n\npublic class A {\n\t\n\t\n\tstatic class team implements Comparable<team>\n\t{\n\t\tint problems;\n\t\tint penalty;\n\t\tpublic team(int problems,int penalty)\n\t\t{\n\t\t\tthis.penalty=penalty;\n\t\t\tthis.problems=problems;\n\t\t}\n\t\tpublic int compareTo(team a) {\n\t\t\tif (a.problems==this.problems)\n\t\t\t\treturn this.penalty - a.penalty;\n\t\t\treturn a.problems - this.problems;\n\t\t}\n\t\t\n\t\tpublic boolean igual(team a)\n\t\t{\n\t\t\tif (this.problems!=a.problems)\n\t\t\t\treturn false;\n\t\t\treturn (this.penalty==a.penalty);\n\t\t}\n\t}\n\t\n\tstatic class Scanner\n\t{\n\t\tBufferedReader rd;\n\t\tStringTokenizer tk;\n\t\tpublic Scanner() throws IOException\n\t\t{\n\t\t\trd=new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttk=new StringTokenizer(rd.readLine());\n\t\t}\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\tif (!tk.hasMoreTokens())\n\t\t\t{\n\t\t\t\ttk=new StringTokenizer(rd.readLine());\n\t\t\t\treturn tk.nextToken();\n\t\t\t}\n\t\t\treturn tk.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws NumberFormatException, IOException\n\t\t{\n\t\t\treturn Integer.valueOf(this.next());\n\t\t}\n\t}\n\t\n\t\n\tstatic team[] array=new team[100];\n\tstatic int N,K;\n\t\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tScanner sc=new Scanner();\n\t\tN=sc.nextInt();\n\t\tK=sc.nextInt();\n\t\tfor(int i=0;i<N;i++)\n\t\t{\n\t\t\tarray[i]=new team(sc.nextInt(),sc.nextInt());\n\t\t}\n\t\tArrays.sort(array,0,N);\n\t\t/*\n\t\tfor(int i=0;i<N;i++)\n\t\t\tSystem.out.println(array[i].problems);*/\n\t\t\n\t\tint shared=0;\n\t\tfor(int i=K-1;i>=0 && array[K-1].igual(array[i]);i--,shared++);\n\t\tfor(int i=K;i<N && array[K-1].igual(array[i]);i++,shared++);\n\t\tSystem.out.println(shared);\n\t}\n\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.util.Vector;\n\npublic class Solution {\n\t\n\tclass Q implements Comparable<Q> {\n\t\tint p, t;\n\t\tQ(int q, int w) {\n\t\t\tp = q; t = w;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Q arg0) {\n\t\t\tif (p == arg0.p) return t - arg0.t; \n\t\t\treturn arg0.p - p;\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint k = nextInt() - 1;\n\t\tQ[] a = new Q[n];\n\t\tfor (int i = 0; i < n; i++) a[i] = new Q(nextInt(), nextInt());\n\t\tArrays.sort(a);\n\t\tint ans = 1;\n\t\tfor (int i = k - 1; i >= 0; i--) if (a[i].compareTo(a[k]) == 0) ans++; else break;\n\t\tfor (int i = k + 1; i < n; i++) if (a[i].compareTo(a[k]) == 0) ans++; else break;\n\t\tout.println(ans);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\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\t\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null) return null;\n\t\t\tst = new StringTokenizer(s);\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\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tclass Team implements Comparable<Team>{\n\t\tint p, t;\n\t\tpublic Team(int p, int t) {\n\t\t\tthis.p = p;\n\t\t\tthis.t = t;\n\t\t}\n\t\tpublic int compareTo(Team other) {\n\t\t\tif (this.p != other.p) return other.p - this.p;\n\t\t\treturn this.t - other.t;\n\t\t}\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint K = nextInt() - 1;\n\t\tTeam[] team = new Team[n];\n\t\tfor (int i = 0; i < n; i++) \n\t\t\tteam[i] = new Team(nextInt(), nextInt());\n\t\t\n\t\tArrays.sort(team);\n\t\tint ans = -1;\n\t\tint pre = 0;\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tif (team[i].compareTo(team[i - 1]) != 0) {\n\t\t\t\tif (K >= pre && K < i) {\n\t\t\t\t\tans = i - pre;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tpre = i;\n\t\t\t}\n\t\tif (ans == -1) ans = n - pre;\n\t\twriter.println(ans);\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tnew A().run();\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong tbegin = System.currentTimeMillis();\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t//reader = new BufferedReader(new InputStreamReader(new FileInputStream(\"test.inp\")));\n\t\t\ttokenizer = null;\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\t//writer = new PrintWriter(new FileOutputStream(\"test.out\"));\n\t\t\tsolve();\n\t\t\t//reader.close();\n\t\t\t//System.out.println(System.currentTimeMillis() - tbegin + \"ms\");\n\t\t\twriter.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\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}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class cf166a {\n\tprivate static boolean[][] matrix;\n\tprivate static int n;\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t// long l = sc.nextLong();\n\t\t// int i = sc.nextInt();\n\t\t// String input = sc.nextLine();\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint[] p = new int[n];\n\t\tint[] t = new int[n];\n\t\tint[] score = new int[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tp[i] = sc.nextInt();\n\t\t\tt[i] = sc.nextInt();\n\t\t\tscore[i] = p[i] * 100 + (50 - t[i]);\n\t\t}\n\t\tboolean[] called = new boolean[n];\n\t\tint x = 0;\n\t\tboolean check = false;\n\t\twhile(true){\n\t\t\tint max = 0;\n\t\t\tint y = 0;\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tif(called[i]==false&&score[i]>max){max=score[i];}\n\t\t\t}\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tif(max==score[i]){\n\t\t\t\t\tcalled[i] = true;\n\t\t\t\t\tx++;\n\t\t\t\t\ty++;\n\t\t\t\t\tif(x==k){check=true;}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(check){\n\t\t\t\tSystem.out.println(y);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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\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\t\tint count = in.readInt();\n\t\tint place = in.readInt() - 1;\n\t\tfinal int[] points = new int[count];\n\t\tfinal int[] time = new int[count];\n\t\tIOUtils.readIntArrays(in, points, time);\n\t\tComparator<Integer> comparator = new Comparator<Integer>() {\n\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\tif (points[o1] != points[o2])\n\t\t\t\t\treturn points[o2] - points[o1];\n\t\t\t\treturn time[o1] - time[o2];\n\t\t\t}\n\t\t};\n\t\tInteger[] order = ArrayUtils.order(count, comparator);\n\t\tint answer = 0;\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tif (comparator.compare(order[place], order[i]) == 0)\n\t\t\t\tanswer++;\n\t\t}\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 readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic static boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\t}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(outputStream);\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\nclass IOUtils {\n\n\tpublic static void readIntArrays(InputReader in, int[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readInt();\n\t\t}\n\t}\n\n\t}\n\nclass ArrayUtils {\n\tpublic static Integer[] generateOrder(int size) {\n\t\tInteger[] order = new Integer[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\torder[i] = i;\n\t\treturn order;\n\t}\n\n\tpublic static Integer[] order(int size, Comparator<Integer> comparator) {\n\t\tInteger[] order = generateOrder(size);\n\t\tArrays.sort(order, comparator);\n\t\treturn order;\n\t}\n\n\t}\n\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n    \n    \n    public static void main(String[] args) throws Exception{\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        int k = scan.nextInt() - 1;\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++) {\n            int p = scan.nextInt();\n            int t = scan.nextInt();\n            arr[i] = -p * 10000 + t;\n        }\n        Arrays.sort(arr);\n        int count = 0;\n        for (int i = 0; i < n; i++) {\n            if (arr[i] == arr[k]) {\n                count++;\n            }\n        }\n        System.out.println(count);\n    }\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "//package round113;\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 A {\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\tint[][] d = new int[n][2];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\td[i][0] = ni();\n\t\t\td[i][1] = ni();\n\t\t}\n\t\t\n\t\tArrays.sort(d, new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\tif(a[0] - b[0] != 0)return -(a[0] - b[0]);\n\t\t\t\treturn a[1] - b[1];\n\t\t\t}\n\t\t});\n\t\t\n\t\tint b;\n\t\tfor(b = k-1;b >= 0 && d[k-1][0] == d[b][0] && d[k-1][1] == d[b][1];b--);\n\t\tb++;\n\t\tint a;\n\t\tfor(a = k-1;a < n && d[k-1][0] == d[a][0] && d[k-1][1] == d[a][1];a++);\n\t\ta--;\n\t\tout.println(a-b+1);\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew A().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", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author hheng\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, Scanner in, PrintWriter out) {\n        int N = in.nextInt();\n        int k = in.nextInt();\n        Team[] t = new Team[N];\n        for (int i=0; i<N; i++) t[i] = new Team(in.nextInt(), in.nextInt());\n        Arrays.sort(t);\n        int p_k = t[k-1].p, t_k = t[k-1].t;\n        int count = 0;\n        for (int i=0; i<N; i++) if (t[i].p==p_k && t[i].t ==t_k) count++;\n        out.println(count);\n\t}\n}\n\nclass Team implements Comparable<Team>{\n    int p, t;\n    Team(int a, int b) { p=a; t=b;}\n    public int compareTo(Team g) {\n        if (p < g.p) return 1;\n        if (p > g.p) return -1;\n        if (t < g.t) return -1;\n        if (t > g.t) return 1;\n        return 0;\n    }\n    \n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "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 Solver {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws NumberFormatException, IOException {\n        Solver solver = new Solver();\n        solver.open();\n        solver.solve();\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    public class result implements Comparable{\n        public int t = 0;\n        public int p = 0;\n        \n        public result(int p,int t){\n            this.t = t;\n            this.p = p;\n        }\n\n        @Override\n        public int compareTo(Object o) {\n            result r = (result)o;\n            int out = r.p-p;\n            if (out==0) out = t-r.t;\n            return out;\n        }\n        \n        \n    }\n    \n    public void solve() throws NumberFormatException, IOException {\n        int n = nextInt();\n        int k = nextInt();\n        \n        result[] table = new result[n];\n        \n        for (int i=0;i<n;i++){\n            int p = nextInt();\n            int t = nextInt();\n            \n            table[i] = new result(p,t);\n        }\n        \n        Arrays.sort(table);\n        \n        int result = 1;\n        k--;\n        \n        for (int i=k-1;i>=0 && table[i].p==table[k].p && table[i].t==table[k].t;i--){\n            result++;\n        }\n        for (int i=k+1;i<n && table[i].p==table[k].p && table[i].t==table[k].t;i++){\n            result++;\n        }\n        out.println(result);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n\n}", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\n\n/**\n * @author piuspratik (Piyush Das)\n */\npublic class TaskA {\n\n    class Contest implements Comparable<Contest>\n\n    {\n        int problems;\n        int penalty;\n\n        Contest (int problems, int penalty) {\n            this.problems = problems;\n            this.penalty = penalty;\n        }\n\n        public int compareTo(Contest contest) {\n            if(problems != contest.problems) return contest.problems - problems;\n            return penalty - contest.penalty;\n\n\n        }\n    }\n\n    void run(){\n        int n = nextInt(), k = nextInt();\n        Contest[] c = new Contest[n];\n        for(int i = 0; i < n; i++) {\n            c[i] = new Contest(nextInt(), nextInt());\n        }\n\n        Arrays.sort(c);\n        int cproblem = c[k - 1].problems, cpenalty = c[k - 1].penalty;\n\n        int ans = 0;\n        for(int i = 0; i < n; i++) {\n            if(c[i].problems == cproblem && c[i].penalty == cpenalty) ans++;\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 TaskA().run();\n    }\n\n}\n", "complexity": "nlogn", "problem": "166_A. Rank List", "from": "CODEFORCES"}
{"src": "//package fourninetysixDiv3;\nimport java.util.HashMap;\nimport java.util.Scanner;\npublic class Median_Segments_general {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint m = s.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = s.nextInt();\n\t\t}\n\t\tSystem.out.println(func(n, m, arr)-func(n, m+1, arr));\n\t}\n\tpublic static long func(int n,int m,int[] arr) {\n\t\tHashMap<Long, Integer> map = new HashMap<>();\n\t\tmap.put((long) 0, 1);\n\t\tlong sum = 0;\n\t\tlong res = 0;\n\t\tlong add=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(arr[i]<m) {\n\t\t\t\tsum--;\n\t\t\t\tif(map.containsKey(sum)) {\n\t\t\t\t\tadd-=map.get(sum);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif(map.containsKey(sum)) {\n\t\t\t\t\tadd+=map.get(sum);\n\t\t\t\t}\n\t\t\t\tsum++;\n\t\t\t}\n\t\t\tres+=add;\n\t\t\tif(map.containsKey(sum)) {\n\t\t\t\tmap.put(sum, map.get(sum)+1);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmap.put(sum,1);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}\n", "complexity": "nlogn", "problem": "1005_E1. Median on Segments (Permutations Edition)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n    static StringTokenizer tok;\n    static boolean hasNext()\n    {\n        while(tok==null||!tok.hasMoreTokens())\n            try{\n                tok=new StringTokenizer(in.readLine());\n            }\n            catch(Exception e){\n                return false;\n            }\n        return true;\n    }\n    static String next()\n    {\n        hasNext();\n        return tok.nextToken();\n    }\n    static long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n    static int nextInt()\n    {\n        return Integer.parseInt(next());\n    }\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));\n\n    public static void main(String[] args) {\n        Map<Integer,Integer> map = new HashMap();\n        map.put(0,1);\n        int n = nextInt();\n        int m = nextInt();\n        int index = -1;\n        int a[] = new int[n];\n        for(int i=0;i<n;i++){\n            a[i]=nextInt();\n            if(a[i]==m)\n                index=i;\n        }\n        int sum = 0;\n        for(int i=0;i<index;i++){\n            if (a[i]<m)\n                sum--;\n            else\n                sum++;\n            if (map.containsKey(sum)){\n                map.put(sum,map.get(sum)+1);\n            }else {\n                map.put(sum,1);\n            }\n        }\n        long ans = 0;\n        for(int i=index;i<n;i++){\n            if (a[i]<m)\n                sum--;\n            else if(a[i]>m)\n                sum++;\n            if (map.containsKey(sum))\n                ans+=map.get(sum);\n            if (map.containsKey(sum-1))\n                ans+=map.get(sum-1);\n        }\n        out.print(ans);\n        out.flush();\n    }\n}\n", "complexity": "nlogn", "problem": "1005_E1. Median on Segments (Permutations Edition)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.function.Function;\n\npublic class Main {\n\n    static int N;\n    static int[] U, V;\n    static int[] A;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner(System.in);\n        N = sc.nextInt();\n        U = new int[N-1];\n        V = new int[N-1];\n        for (int i = 0; i < N - 1; i++) {\n            U[i] = sc.nextInt()-1;\n            V[i] = sc.nextInt()-1;\n        }\n        A = sc.nextIntArray(N, -1);\n\n        System.out.println(solve() ? \"Yes\" : \"No\");\n    }\n\n    static boolean solve() {\n        if( A[0] != 0 ) return false;\n\n        int[][] G = adjB(N, U, V);\n\n        Map<Integer, Integer> parents = new HashMap<>();\n        for (Node node : orderFromRoot(N, G, 0)) {\n            parents.put(node.a, node.parent);\n        }\n        ArrayDeque<Integer> q = new ArrayDeque<>();\n        for (int next : G[0]) {\n            q.add(0);\n        }\n\n        int idx = 1;\n        while(!q.isEmpty()) {\n            int p = q.poll();\n            int a = A[idx++];\n            if( parents.get(a) != p ) {\n                return false;\n            }\n\n            for (int next : G[a]) {\n                if( next == p ) continue;\n\n                q.add(a);\n            }\n        }\n        return true;\n    }\n\n    static int[][] adjB(int n, int[] from, int[] to) {\n        int[][] adj = new int[n][];\n        int[] cnt = new int[n];\n        for (int f : from) {\n            cnt[f]++;\n        }\n        for (int t : to) {\n            cnt[t]++;\n        }\n        for (int i = 0; i < n; i++) {\n            adj[i] = new int[cnt[i]];\n        }\n        for (int i = 0; i < from.length; i++) {\n            adj[from[i]][--cnt[from[i]]] = to[i];\n            adj[to[i]][--cnt[to[i]]] = from[i];\n        }\n        return adj;\n    }\n\n    static Node[] orderFromRoot(int N, int[][] G, int root) {\n        ArrayDeque<Node> q = new ArrayDeque<>();\n        Node[] ret = new Node[N];\n        int idx = 0;\n        q.add(new Node(-1, root));\n        while(!q.isEmpty()) {\n            Node n = q.poll();\n            ret[idx++] = n;\n            for (int next : G[n.a]) {\n                if( next == n.parent ) continue;\n\n                q.add(new Node(n.a, next));\n            }\n        }\n        return ret;\n    }\n\n    static class Node {\n        int parent, a;\n\n        public Node(int parent, int a) {\n            this.parent = parent;\n            this.a = a;\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++)\n                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++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n    }\n\n    static <A> void writeLines(A[] as, Function<A, String> f) {\n        PrintWriter pw = new PrintWriter(System.out);\n        for (A a : as) {\n            pw.println(f.apply(a));\n        }\n        pw.flush();\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 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 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", "complexity": "nlogn", "problem": "1037_D. Valid BFS?", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class MicroWorld {\n\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\t\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\t\n\t\tint[] temp = new int[1000001];\n\t\t\n\t\tStringTokenizer st1 = new StringTokenizer(br.readLine());\n\t\t\n\t\tfor (int i = 0; i < n; i++){\n\t\t\t\n\t\t\ttemp[Integer.parseInt(st1.nextToken())]++;\n\t\t}\n\t\t\n\t\tint b = k + 1;\n\t\t\n\t\tfor (int i = 1000000; i > 0; i--){\n\t\t\t\n\t\t\tif (temp[i] > 0){\n\t\t\t\tif (b <= k){\n\t\t\t\t\tn -= temp[i];\n\t\t\t\t}\n\t\t\t\tb = 1;\n\t\t\t}else{\n\t\t\t\tb++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(n);\n\t\t\n\t}\n\n}\n", "complexity": "nlogn", "problem": "990_B. Micro-World", "from": "CODEFORCES"}
{"src": "/*\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 long MOD = 1000L * 1000L * 1000L + 7;\n    private static final int[] dx = {0, -1, 0, 1};\n    private static final int[] dy = {1, 0, -1, 0};\n    private static final String yes = \"Yes\";\n    private static final String no = \"No\";\n\n    int n;\n    int m;\n    char[][] mat;\n    long base = 397;\n    void solve() throws IOException {\n        n = nextInt();\n        m = nextInt();\n        mat = new char[n][m];\n        for (int i = 0; i < n; i++) {\n            mat[i] = nextString().toCharArray();\n        }\n\n        int alpha = 26;\n        long[] pow = new long[alpha];\n        pow[0] = 1;\n        for (int i = 1; i < alpha; i++) {\n            pow[i] = pow[i - 1] * base % MOD;\n        }\n\n        long res = 0;\n        for (int l = 0; l < m; l++) {\n            //[l, r]\n            long[] hash = new long[n];\n            long[] mask = new long[n];\n            for (int r = l; r < m; r++) {\n                for (int i = 0; i < n; i++) {\n                    hash[i] += pow[mat[i][r] - 'a'];\n                    hash[i] %= MOD;\n                    mask[i] = mask[i] ^ (1L << (mat[i][r] - 'a'));\n                }\n\n                int start = 0;\n                while (start < n) {\n                    if ((mask[start] & (mask[start] - 1)) != 0) {\n                        start++;\n                        continue;\n                    }\n\n                    int end = start;\n                    List<Long> l1 = new ArrayList<>();\n                    while (end < n && (mask[end] & (mask[end] - 1)) == 0) {\n                        l1.add(hash[end]);\n                        end++;\n                    }\n\n                    start = end;\n                    res += manacher(l1);\n                }\n            }\n        }\n\n        outln(res);\n    }\n\n    long manacher(List<Long> arr) {\n        int len = arr.size();\n        long[] t = new long[len * 2 + 3];\n        t[0] = -1;\n        t[len * 2 + 2] = -2;\n        for (int i = 0; i < len; i++) {\n            t[2 * i + 1] = -3;\n            t[2 * i + 2] = arr.get(i);\n        }\n\n        t[len * 2 + 1] = -3;\n        int[] p = new int[t.length];\n        int center = 0, right = 0;\n        for (int i = 1; i < t.length - 1; i++) {\n            int mirror = 2 * center - i;\n            if (right > i) {\n                p[i] = Math.min(right - i, p[mirror]);\n            }\n\n            // attempt to expand palindrome centered at i\n            while (t[i + (1 + p[i])] == t[i - (1 + p[i])]) {\n                p[i]++;\n            }\n\n            // if palindrome centered at i expands past right,\n            // adjust center based on expanded palindrome.\n            if (i + p[i] > right) {\n                center = i;\n                right = i + p[i];\n            }\n        }\n\n        long res = 0;\n        for (int i = 0; i < 2 * len; i++) {\n            int parLength = p[i + 2];\n            if (i % 2 == 0) {\n                res += (parLength + 1) / 2;\n            }\n            else {\n                res += parLength / 2;\n            }\n        }\n\n        return res;\n    }\n\n    void shuffle(int[] a) {\n        int n = a.length;\n        for(int i = 0; i < n; i++) {\n            int r = i + (int) (Math.random() * (n - i));\n            int tmp = a[i];\n            a[i] = a[r];\n            a[r] = tmp;\n        }\n    }\n    long gcd(long a, long b) {\n        while(a != 0 && b != 0) {\n            long c = b;\n            b = a % b;\n            a = c;\n        }\n        return a + b;\n    }\n    private void outln(Object o) {\n        out.println(o);\n    }\n    private void out(Object o) {\n        out.print(o);\n    }\n    private void formatPrint(double val) {\n        outln(String.format(\"%.9f%n\", val));\n    }\n    public 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}", "complexity": "nlogn", "problem": "1080_E. Sonya and Matrix Beauty", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StringWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.io.InputStream ;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\n\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(System.out);\n        //Scanner sc = new Scanner();\n        Reader in = new Reader();\n        Main solver = new Main();\n        solver.solve(out, in);\n        out.flush();\n        out.close();\n\n    }\n    \n    \n    void solve(PrintWriter out, Reader in) throws IOException{   \n        int n = in.nextInt();\n        int m = in.nextInt();\n        \n        \n        \n        int[] vert = new int[n+1];\n        for(int i=0 ;i<n ;i++) vert[i] = in.nextInt();\n        vert[n] = (int)1e9;\n        \n        int cnt=0,x,y;\n        ArrayList<Integer> arr = new ArrayList<>();\n        for(int i=0 ;i<m ;i++) {\n            x = in.nextInt();\n            y = in.nextInt();\n            in.nextInt();\n            \n            if(x==1) arr.add(y);\n        }\n        \n        horz = new int[arr.size()];\n        for(int i=0 ;i<arr.size();i++) horz[i] = arr.get(i);\n        \n        Arrays.sort(horz);\n        Arrays.sort(vert);\n        \n        int ans = 2*(int)1e5+10;\n        for(int i=0 ;i<=n ;i++){\n            int lesshorz = bs(vert[i],horz.length);\n            ans = Math.min(ans,i+horz.length-lesshorz-1);\n        }\n        out.println(ans);\n    }\n    \n    static int[] horz;\n    \n    static int bs(int num,int m){\n        int mid,lo=0,hi=m-1,r=-1;\n        \n        while(lo<=hi){\n            mid = (lo+hi)/2;\n            if(horz[mid]<num){\n                lo = mid+1;\n                r = mid;\n            }else{\n                hi =mid-1;\n            }\n        }\n        return r;\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        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n     \n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n     \n        public boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n     \n        public boolean isEndOfLine(int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n \n    }\n}\n", "complexity": "nlogn", "problem": "1075_C. The Tower is Going Home", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\n\npublic class Main {\n\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt(), m = scanner.nextInt();\n        int[] vertical = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            vertical[i] = scanner.nextInt();\n        }\n\n        Arrays.sort(vertical);\n\n\n        ArrayList<Integer> horisontal = new ArrayList<>();\n        int amount = 0;\n        for (int i = 0; i < m; i++) {\n            int x1 = scanner.nextInt(), x2 = scanner.nextInt(), y = scanner.nextInt();\n            if (x1 == 1) {\n                amount++;\n                horisontal.add(x2);\n            }\n        }\n\n        Collections.sort(horisontal);\n\n\n        if (amount == 0) {\n            System.out.println(0);\n            return;\n        }\n\n\n        int minVal = amount, horSize = horisontal.size(), verLen = vertical.length;\n        int h = 0, v = 0;\n\n        for (; v < verLen && h < horSize; ) {\n\n           while (h < horSize && horisontal.get(h) < vertical[v]){\n               h++;\n               amount--;\n           }\n           minVal = Math.min(minVal, amount + v);\n\n            while (h < horSize && v < verLen && horisontal.get(h) >= vertical[v]){\n                minVal = Math.min(minVal, amount + v);\n                v++;\n            }\n\n        }\n\n        if(horisontal.get(horSize - 1) < 1E9){\n            minVal = Math.min(minVal, v);\n        }\n\n\n\n        System.out.println(minVal);\n\n    }\n}\n", "complexity": "nlogn", "problem": "1075_C. The Tower is Going Home", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A4 {\n\n    public BufferedReader input;\n    public PrintWriter output;\n    public StringTokenizer stoken = new StringTokenizer(\"\");\n\n    public static void main(String[] args) throws IOException {\n        new A4();\n    }\n\n    A4() throws IOException {\n        input = new BufferedReader(new InputStreamReader(System.in));\n        output = new PrintWriter(System.out);\n        run();\n        input.close();\n        output.close();\n    }\n\n    private void run() throws IOException {\n        int n = Math.toIntExact(nextLong());\n        int m = Math.toIntExact(nextLong());\n        int[] coor = new int[n + 1];\n        int[] ss = new int[n + 1];\n        for (int i = 0; i < n; i++) {\n            coor[i] = Math.toIntExact(nextLong());\n        }\n        coor[n] = 1000000000;\n        Arrays.sort(coor);\n        for (int i = 0; i < m; i++) {\n            long x1 = nextLong();\n            long x2 = nextLong();\n            nextLong();\n            if (x1 == 1 && x2 >= coor[0]) {\n                int l = 0;\n                int r = n + 1;\n                while (r - l > 1) {\n                    int mi = (r + l) / 2;\n                    if (coor[mi] > x2) {\n                        r = mi;\n                    } else {\n                        l = mi;\n                    }\n                }\n                ss[l]++;\n            }\n        }\n        long[] ans = new long[n + 1];\n        ans[n] = ss[n] + n;\n        long min = ans[n];\n        for (int i = n - 1; i > -1; i--) {\n            ans[i] = ans[i + 1] - 1 + ss[i];\n            if (ans[i] < min) {\n                min = ans[i];\n            }\n        }\n        System.out.println(min);\n    }\n\n    private Long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    private String nextString() throws IOException {\n        while (!stoken.hasMoreTokens()) {\n            String st = input.readLine();\n            stoken = new StringTokenizer(st);\n        }\n        return stoken.nextToken();\n    }\n}", "complexity": "nlogn", "problem": "1075_C. The Tower is Going Home", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class loser\n{\n    static class InputReader {\n        public BufferedReader br;\n        public StringTokenizer token;\n        public InputReader(InputStream stream)\n        {\n            br=new BufferedReader(new InputStreamReader(stream),32768);\n            token=null;\n        }\n\n        public String next()\n        {\n            while(token==null || !token.hasMoreTokens())\n            {\n                try\n                {\n                    token=new StringTokenizer(br.readLine());\n                }\n                catch(IOException e)\n                {\n                    throw new RuntimeException(e);\n                }\n            }\n            return token.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    static class card{\n        int l;\n        int r;\n        public card(int ch,int i)\n        {\n            this.l=ch;\n            this.r=i;\n        }\n    }\n    static class sort implements Comparator<card>\n    {\n        public int compare(card o1,card o2)\n        {\n            if(o1.l!=o2.l)\n                return (int)(o1.l-o2.l);\n            else\n                return (int)(o1.r-o2.r);\n        }\n    }\n    static void shuffle(long a[])\n    {\n        List<Long> l=new ArrayList<>();\n        for(int i=0;i<a.length;i++)\n            l.add(a[i]);\n        Collections.shuffle(l);\n        for(int i=0;i<a.length;i++)\n            a[i]=l.get(i);\n    }\n\n    /*static long gcd(long a,long b)\n    {\n    if(b==0)\n    return a;\n    else\n    return gcd(b,a%b);\n    }\n    static int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE,ans3=Integer.MAX_VALUE,ans4=Integer.MAX_VALUE;\n    static boolean v[]=new boolean[101];\n    static void dfs(Integer so,Set<Integer> s[]){\n    if(!v[so.intValue()])\n    {\n    v[so]=true;\n    for(Integer h:s[so.intValue()])\n    {\n    if(!v[h.intValue()])\n    dfs(h,s);\n    }\n    }\n    }\n    static class Print{\n    public PrintWriter out;\n    Print(OutputStream o)\n    {\n    out=new PrintWriter(o);\n    }\n    }\n    static int CeilIndex(int A[], int l, int r, int key) \n    { \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\n    return r; \n    } \n\n    static int LongestIncreasingSubsequenceLength(int A[], int size) \n    { \n    // Add boundary case, when array size is one \n    int[] tailTable = new int[size]; \n    int len; // always points empty slot \n    tailTable[0] = A[0]; \n    len = 1; \n    for (int i = 1; i < size; i++) { \n    if (A[i] < tailTable[0]) \n    // new smallest value \n    tailTable[0] = A[i]; \n\n    else if (A[i] > tailTable[len - 1]) \n    // A[i] wants to extend largest subsequence \n    tailTable[len++] = A[i]; \n\n    else\n    // A[i] wants to be current end candidate of an existing \n    // subsequence. It will replace ceil value in tailTable \n    tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; \n    } \n    return len; \n    }*/\n    /*static int binary(int n)\n    {\n    int s=1;\n    while(n>0)\n    {\n    s=s<<1;\n    n--;\n    }\n    return s-1;\n    }\n    static StringBuilder bin(int i,int n)\n    {\n    StringBuilder s=new StringBuilder();\n    while(i>0)\n    {\n    s.append(i%2);\n    i=i/2;\n    }\n    while(s.length()!=n)\n    {\n    s.append(0);\n    }\n    return s.reverse();\n    }*/\n    static boolean valid(int i,int j,int n,int m)\n    {\n        if(i<n && i>=0 && j<m && j>=0)\n            return true;\n        else\n            return false;\n    }\n\n    public static void main(String[] args) \n    {\n        InputReader sc=new InputReader(System.in);\n        int n=sc.nextInt();\n        int s=sc.nextInt();\n        card c[]=new card[n];\n        for(int i=0;i<n;i++)\n        {\n            int x=sc.nextInt();\n            int y=sc.nextInt();\n            c[i]=new card(x,y);\n        }\n        Arrays.sort(c,new sort());\n        int time=0;\n        for(int i=n-1;i>=0;i--)\n        {\n            time+=s-c[i].l;\n            if((c[i].r-time)>0)\n            time+=c[i].r-time;\n            s=c[i].l;\n        }\n        if(c[0].l!=0)\n        time+=c[0].l;\n        System.out.println(time);\n    }\n}", "complexity": "nlogn", "problem": "608_A. Saitama Destroys Hotel", "from": "CODEFORCES"}
{"src": "import javafx.util.Pair;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Beacon8 {\n    public static void main(String[] args) throws IOException {\n//        int[] arr = {1, 3, 7, 18};\n//        int bIndex = Arrays.binarySearch(arr, 4);\n//        System.out.println(bIndex);\n\n\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        Map<Integer, Integer> beacons = new TreeMap<>();\n\n        for (int i = 0; i < n; i++) {\n            int index = scan.nextInt();\n            int power = scan.nextInt();\n            beacons.put(index, power);\n        }\n        int[] indicesArr = new int[n];\n        int arrInd = 0;\n        for (int index : beacons.keySet()) {\n            indicesArr[arrInd] = index;\n            arrInd++;\n        }\n       // Integer[] indicesArr = ((Integer[])beacons.keySet().toArray());\n        int[] nDestroys = new int[n];\n        for (int i = 0; i < n; i++) {\n            int bIndex = Arrays.binarySearch(indicesArr, indicesArr[i] - beacons.get(indicesArr[i]));\n            if (bIndex < 0)\n                bIndex = -(bIndex + 1);\n            nDestroys[i] = i - bIndex;\n        }\n        int[] totalBeacons = new int[n];\n        int maxBeacons = 1;\n        totalBeacons[0] = 1;\n        for (int i = 1; i < n; i++) {\n            if (nDestroys[i] == 0)\n                totalBeacons[i] = totalBeacons[i - 1] + 1;\n            else {\n                if ((i - nDestroys[i] - 1) >= 0)\n                    totalBeacons[i] = totalBeacons[i - nDestroys[i] - 1] + 1;\n                else\n                    totalBeacons[i] = 1;\n            }\n               // totalBeacons[i] = totalBeacons[i - nDestroys[i]] + 1;\n            //totalBeacons[i] = i - nDestroys[i] + totalBeacons[i - nDestroys[i]] + 1;\n            if(totalBeacons[i] > maxBeacons)\n                maxBeacons = totalBeacons[i];\n        }\n//        System.out.println(\"\\ntotalBeacons array\");\n//        for (int i = 0; i < n; i++) {\n//            System.out.print(totalBeacons[i] + \" \");\n//        }\n//        if (maxBeacons == -1)\n//            System.out.println(n);\n        System.out.println(n - maxBeacons);\n    }\n\n}\n", "complexity": "nlogn", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class ChainReaction implements Closeable {\n\n  private InputReader in = new InputReader(System.in);\n  private PrintWriter out = new PrintWriter(System.out);\n  \n  private class Beacon implements Comparable<Beacon> {\n    private int position, range, score;\n\n    private Beacon(int position, int range) {\n      this.position = position;\n      this.range = range;\n    }\n\n    public void setScore(int score) {\n      this.score = score;\n    }\n\n    @Override\n    public int compareTo(Beacon o) {\n      return Integer.compare(this.position, o.position);\n    }\n  }\n\n  public void solve() {\n    int n = in.ni();\n    if (n == 1) {\n      out.println(0);\n      return;\n    }\n    beacons = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n      beacons.add(new Beacon(in.ni(), in.ni()));\n    }\n    beacons.sort(Comparator.naturalOrder());\n    for (int i = 1; i < n; i++) {\n      int left = 0, right = i - 1, position = beacons.get(i).position, range = beacons.get(i).range;\n      int leftmost = i;\n      while (left <= right) {\n        int mid = left + (right - left) / 2;\n        if (position - range <= beacons.get(mid).position) {\n          leftmost = Math.min(leftmost, mid);\n          right = mid - 1;\n        } else {\n          left = mid + 1;\n        }\n      }\n      beacons.get(i).setScore(i - leftmost);\n    }\n    dp = new Integer[n];\n    int ans = Integer.MAX_VALUE;\n    for (int i = n - 1; i >= 0; i--) {\n      ans = Math.min(n - 1 - i + recurse(i), ans);\n    }\n    out.println(ans);\n  }\n  \n  private List<Beacon> beacons;\n  private Integer[] dp;\n  \n  private int recurse(int idx) {\n    if (idx <= 0) return 0;\n    \n    if (dp[idx] != null) return dp[idx];\n    \n    int destroyed = beacons.get(idx).score;\n    int ans = destroyed + recurse(idx - destroyed - 1);\n    return dp[idx] = ans;\n  }\n  \n  @Override\n  public void close() throws IOException {\n    in.close();\n    out.close();\n  }\n\n  static class InputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n      reader = new BufferedReader(new InputStreamReader(stream), 32768);\n      tokenizer = null;\n    }\n\n    public String next() {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n        try {\n          tokenizer = new StringTokenizer(reader.readLine());\n        } catch (IOException e) {\n          throw new RuntimeException(e);\n        }\n      }\n      return tokenizer.nextToken();\n    }\n\n    public int ni() {\n      return Integer.parseInt(next());\n    }\n\n    public long nl() {\n      return Long.parseLong(next());\n    }\n\n    public void close() throws IOException {\n      reader.close();\n    }\n  }\n\n  public static void main(String[] args) throws IOException {\n    try (ChainReaction instance = new ChainReaction()) {\n      instance.solve();\n    }\n  }\n}\n", "complexity": "nlogn", "problem": "608_C. Chain Reaction", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.System.in;\n\npublic class Main {\n    public static void main(String[] args)throws IOException{\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[][] point = new int[n][];\n        for(int i=0;i<n;i++) point[i] = new int[]{sc.nextInt(),sc.nextInt()};\n        Arrays.sort(point,(a,b)->((a[0]-a[1])-(b[0]-b[1])));\n        TreeMap<Integer,Integer> tm = new TreeMap<>();\n        int ans = 0;\n        for(int i=n-1;i>=0;i--){\n            int x = point[i][0], w = point[i][1];\n            Map.Entry<Integer,Integer> cur =  tm.ceilingEntry(x+w);\n            int curRes;\n            if(cur==null) curRes = 1;\n            else curRes = cur.getValue()+1;\n            ans = Math.max(ans,curRes);\n            Map.Entry<Integer,Integer> upper = tm.ceilingEntry(x-w);\n            if(upper==null||upper.getValue()<curRes) tm.put(x-w,curRes);\n            //Integer key = tm.\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "nlogn", "problem": "528_B. Clique Problem", "from": "CODEFORCES"}
{"src": "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 */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            TaskD.Pair[] p = new TaskD.Pair[n];\n            for (int i = 0; i < n; ++i) {\n                p[i] = new TaskD.Pair(in.nextLong(), in.nextLong());\n            }\n            Arrays.sort(p);\n            int last = 0;\n            int ans = 1;\n            for (int i = 1; i < n; ++i) {\n                if (p[i].x - p[i].w >= p[last].x + p[last].w) {\n                    last = i;\n                    ++ans;\n                }\n            }\n            out.println(ans);\n        }\n\n        static class Pair implements Comparable<TaskD.Pair> {\n            long x;\n            long w;\n\n            public Pair(long x, long w) {\n                this.x = x;\n                this.w = w;\n            }\n\n            public int compareTo(TaskD.Pair o) {\n                return Long.compare(x + w, o.x + o.w);\n            }\n\n            public String toString() {\n                return x + \" \" + w;\n            }\n\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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 long nextLong() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = pread();\n            }\n            long res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = pread();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "528_B. Clique Problem", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author aryssoncf\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        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            try {\n                int n = in.readInt();\n                int[] x = new int[n], w = new int[n];\n                in.readIntArrays(x, w);\n                int[] begin = new int[n], end = new int[n];\n                Arrays.setAll(begin, i -> x[i] - w[i]);\n                Arrays.setAll(end, i -> x[i] + w[i]);\n                int m = ArrayUtils.compress(begin, end).length;\n                int[] dp = new int[m + 1], order = ArrayUtils.order(end);\n                int idx = 0;\n                for (int i = 0; i < m; i++) {\n                    if (i > 0) {\n                        dp[i] = dp[i - 1];\n                    }\n                    while (idx < n && end[order[idx]] == i) {\n                        dp[i] = Math.max(dp[i], dp[begin[order[idx]]] + 1);\n                        idx++;\n                    }\n                }\n                int res = dp[m - 1];\n                out.printLine(res);\n            } catch (Exception e) {\n                e.printStackTrace();\n            }\n        }\n\n    }\n\n    static class Sorter {\n        private static final int INSERTION_THRESHOLD = 16;\n\n        private Sorter() {\n        }\n\n        public static void sort(IntList list, IntComparator comparator) {\n            quickSort(list, 0, list.size() - 1, (Integer.bitCount(Integer.highestOneBit(list.size()) - 1) * 5) >> 1,\n                    comparator);\n        }\n\n        private static void quickSort(IntList list, int from, int to, int remaining, IntComparator comparator) {\n            if (to - from < INSERTION_THRESHOLD) {\n                insertionSort(list, from, to, comparator);\n                return;\n            }\n            if (remaining == 0) {\n                heapSort(list, from, to, comparator);\n                return;\n            }\n            remaining--;\n            int pivotIndex = (from + to) >> 1;\n            int pivot = list.get(pivotIndex);\n            list.swap(pivotIndex, to);\n            int storeIndex = from;\n            int equalIndex = to;\n            for (int i = from; i < equalIndex; i++) {\n                int value = comparator.compare(list.get(i), pivot);\n                if (value < 0) {\n                    list.swap(storeIndex++, i);\n                } else if (value == 0) {\n                    list.swap(--equalIndex, i--);\n                }\n            }\n            quickSort(list, from, storeIndex - 1, remaining, comparator);\n            for (int i = equalIndex; i <= to; i++) {\n                list.swap(storeIndex++, i);\n            }\n            quickSort(list, storeIndex, to, remaining, comparator);\n        }\n\n        private static void heapSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = (to + from - 1) >> 1; i >= from; i--) {\n                siftDown(list, i, to, comparator, from);\n            }\n            for (int i = to; i > from; i--) {\n                list.swap(from, i);\n                siftDown(list, from, i - 1, comparator, from);\n            }\n        }\n\n        private static void siftDown(IntList list, int start, int end, IntComparator comparator, int delta) {\n            int value = list.get(start);\n            while (true) {\n                int child = ((start - delta) << 1) + 1 + delta;\n                if (child > end) {\n                    return;\n                }\n                int childValue = list.get(child);\n                if (child + 1 <= end) {\n                    int otherValue = list.get(child + 1);\n                    if (comparator.compare(otherValue, childValue) > 0) {\n                        child++;\n                        childValue = otherValue;\n                    }\n                }\n                if (comparator.compare(value, childValue) >= 0) {\n                    return;\n                }\n                list.swap(start, child);\n                start = child;\n            }\n        }\n\n        private static void insertionSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = from + 1; i <= to; i++) {\n                int value = list.get(i);\n                for (int j = i - 1; j >= from; j--) {\n                    if (comparator.compare(list.get(j), value) <= 0) {\n                        break;\n                    }\n                    list.swap(j, j + 1);\n                }\n            }\n        }\n\n    }\n\n    static interface IntList extends IntReversableCollection {\n        public abstract int get(int index);\n\n        public abstract void set(int index, int value);\n\n        public abstract void addAt(int index, int value);\n\n        public abstract void removeAt(int index);\n\n        default public void swap(int first, int second) {\n            if (first == second) {\n                return;\n            }\n            int temp = get(first);\n            set(first, get(second));\n            set(second, temp);\n        }\n\n        default public IntIterator intIterator() {\n            return new IntIterator() {\n                private int at;\n                private boolean removed;\n\n                public int value() {\n                    if (removed) {\n                        throw new IllegalStateException();\n                    }\n                    return get(at);\n                }\n\n                public boolean advance() {\n                    at++;\n                    removed = false;\n                    return isValid();\n                }\n\n                public boolean isValid() {\n                    return !removed && at < size();\n                }\n\n                public void remove() {\n                    removeAt(at);\n                    at--;\n                    removed = true;\n                }\n            };\n        }\n\n        default public void add(int value) {\n            addAt(size(), value);\n        }\n\n        default public IntList sort(IntComparator comparator) {\n            Sorter.sort(this, comparator);\n            return this;\n        }\n\n        default IntList unique() {\n            int last = Integer.MIN_VALUE;\n            IntList result = new IntArrayList();\n            int size = size();\n            for (int i = 0; i < size; i++) {\n                int current = get(i);\n                if (current != last) {\n                    result.add(current);\n                    last = current;\n                }\n            }\n            return result;\n        }\n\n        default public IntList subList(final int from, final int to) {\n            return new IntList() {\n                private final int shift;\n                private final int size;\n\n                {\n                    if (from < 0 || from > to || to > IntList.this.size()) {\n                        throw new IndexOutOfBoundsException(\"from = \" + from + \", to = \" + to + \", size = \" + size());\n                    }\n                    shift = from;\n                    size = to - from;\n                }\n\n                public int size() {\n                    return size;\n                }\n\n                public int get(int at) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    return IntList.this.get(at + shift);\n                }\n\n                public void addAt(int index, int value) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void removeAt(int index) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void set(int at, int value) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    IntList.this.set(at + shift, value);\n                }\n\n                public IntList compute() {\n                    return new IntArrayList(this);\n                }\n            };\n        }\n\n    }\n\n    static interface IntComparator {\n        IntComparator DEFAULT = Integer::compare;\n\n        int compare(int first, int second);\n\n    }\n\n    static class Range {\n        public static IntList range(int from, int to) {\n            int[] result = new int[Math.abs(from - to)];\n            int current = from;\n            if (from <= to) {\n                for (int i = 0; i < result.length; i++) {\n                    result[i] = current++;\n                }\n            } else {\n                for (int i = 0; i < result.length; i++) {\n                    result[i] = current--;\n                }\n            }\n            return new IntArray(result);\n        }\n\n    }\n\n    static interface IntReversableCollection extends IntCollection {\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 interface IntStream extends Iterable<Integer>, Comparable<IntStream> {\n        IntIterator intIterator();\n\n        default Iterator<Integer> iterator() {\n            return new Iterator<Integer>() {\n                private IntIterator it = intIterator();\n\n                public boolean hasNext() {\n                    return it.isValid();\n                }\n\n                public Integer next() {\n                    int result = it.value();\n                    it.advance();\n                    return result;\n                }\n            };\n        }\n\n        default int compareTo(IntStream c) {\n            IntIterator it = intIterator();\n            IntIterator jt = c.intIterator();\n            while (it.isValid() && jt.isValid()) {\n                int i = it.value();\n                int j = jt.value();\n                if (i < j) {\n                    return -1;\n                } else if (i > j) {\n                    return 1;\n                }\n                it.advance();\n                jt.advance();\n            }\n            if (it.isValid()) {\n                return 1;\n            }\n            if (jt.isValid()) {\n                return -1;\n            }\n            return 0;\n        }\n\n    }\n\n    static 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 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 int[] toArray() {\n            int size = size();\n            int[] array = new int[size];\n            int i = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                array[i++] = it.value();\n            }\n            return array;\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 IntArray extends IntAbstractStream implements IntList {\n        private int[] data;\n\n        public IntArray(int[] arr) {\n            data = arr;\n        }\n\n        public int size() {\n            return data.length;\n        }\n\n        public int get(int at) {\n            return data[at];\n        }\n\n        public void addAt(int index, int value) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void removeAt(int index) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void set(int index, int value) {\n            data[index] = value;\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static int[] range(int from, int to) {\n            return Range.range(from, to).toArray();\n        }\n\n        public static int[] createOrder(int size) {\n            return range(0, size);\n        }\n\n        public static int[] sort(int[] array, IntComparator comparator) {\n            return sort(array, 0, array.length, comparator);\n        }\n\n        public static int[] sort(int[] array, int from, int to, IntComparator comparator) {\n            if (from == 0 && to == array.length) {\n                new IntArray(array).sort(comparator);\n            } else {\n                new IntArray(array).subList(from, to).sort(comparator);\n            }\n            return array;\n        }\n\n        public static int[] order(final int[] array) {\n            return sort(createOrder(array.length), (first, second) -> Integer.compare(array[first], array[second]));\n        }\n\n        public static int[] unique(int[] array) {\n            return new IntArray(array).unique().toArray();\n        }\n\n        public static int[] compress(int[]... arrays) {\n            int totalLength = 0;\n            for (int[] array : arrays) {\n                totalLength += array.length;\n            }\n            int[] all = new int[totalLength];\n            int delta = 0;\n            for (int[] array : arrays) {\n                System.arraycopy(array, 0, all, delta, array.length);\n                delta += array.length;\n            }\n            sort(all, IntComparator.DEFAULT);\n            all = unique(all);\n            for (int[] array : arrays) {\n                for (int i = 0; i < array.length; i++) {\n                    array[i] = Arrays.binarySearch(all, array[i]);\n                }\n            }\n            return all;\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 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        public void set(int index, int value) {\n            if (index >= size) {\n                throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n            }\n            data[index] = value;\n        }\n\n        public int[] toArray() {\n            return Arrays.copyOf(data, size);\n        }\n\n    }\n\n    static abstract class IntAbstractStream implements IntStream {\n        public String toString() {\n            StringBuilder builder = new StringBuilder();\n            boolean first = true;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                if (first) {\n                    first = false;\n                } else {\n                    builder.append(' ');\n                }\n                builder.append(it.value());\n            }\n            return builder.toString();\n        }\n\n        public boolean equals(Object o) {\n            if (!(o instanceof IntStream)) {\n                return false;\n            }\n            IntStream c = (IntStream) o;\n            IntIterator it = intIterator();\n            IntIterator jt = c.intIterator();\n            while (it.isValid() && jt.isValid()) {\n                if (it.value() != jt.value()) {\n                    return false;\n                }\n                it.advance();\n                jt.advance();\n            }\n            return !it.isValid() && !jt.isValid();\n        }\n\n        public int hashCode() {\n            int result = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                result *= 31;\n                result += it.value();\n            }\n            return result;\n        }\n\n    }\n}\n\n", "complexity": "nlogn", "problem": "528_B. Clique Problem", "from": "CODEFORCES"}
{"src": "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        TreeSet<Integer> v = new TreeSet<Integer>();\n        for(int i=0;i<n;i++) v.add(sc.nextInt());\n        Iterator<Integer> it = v.iterator();\n        it.next();\n        it.remove();\n        System.out.println(v.isEmpty() ? \"NO\" : v.iterator().next());\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Seq2 {\n\n    static void metod() {\n        Scanner in = new Scanner(System.in);\n        int n = 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 min = a[0];\n        for (int i = 1; i < a.length; i++) {\n            if (a[i] < min)\n                min = a[i];\n        }\n        \n        int min2 = min;\n        boolean t = false;\n        for (int i = 0; i < a.length; i++) {\n            if (a[i] != min) {\n                if (!t) {\n                    min2 = a[i];\n                    t = true;\n                } else {\n                    if (min2 > a[i])\n                        min2 = a[i];\n                }\n            }\n        }\n\n        System.out.println((min == min2) ? \"NO\" : min2);        \n    }\n\n    public static void main(String[] args) {\n        Seq2.metod();\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n    private static Parser in;\n    private static PrintWriter out;\n    \n    public static void main(String[] args) {\n        in = new Parser(System.in);\n        out = new PrintWriter(System.out);\n        \n        int n= in.nextInt();\n        int min = 101;\n        boolean b = false;\n        int pmin = 101;\n        int t= 0 ;\n        for(int i=0; i<n; i++){\n            t = in.nextInt();\n            \n            if (t<min){if(min != pmin)b=true; if(b) pmin = min;  min = t;  continue;}\n            if (t>min && t<pmin){b=true; pmin = t;  continue;}\n            if (t>min && !b){b=true; pmin = t;  continue;}\n            //if (b){if(t<pmin){pmin = t; continue;}}\n            //out.print(min);\n            //out.print(pmin);\n        }\n        if (b) System.out.println(pmin); else System.out.println(\"NO\");\n        //out.flush();\n    }\n}\n\n\nclass Parser {\n    final private int BUFFER_SIZE = 1 << 16;\n    private DataInputStream din;\n    private byte[] buffer;\n    private int bufferPointer, bytesRead;\n \n    public Parser(InputStream in) {\n            din = new DataInputStream(in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n    }\n    public String nextString(int size) { \n        byte[] ch = new byte[size];\n        int point = 0;\n        try {\n            byte c = read();\n            while (c == ' ' || c == '\\n' || c=='\\r')\n                c = read();\n            while (c != ' ' && c != '\\n' && c!='\\r') {\n                ch[point++] = c;\n                c = read();\n            }\n        } catch (Exception e) {}\n        return new String(ch,0,point);\n        }\n    public int nextInt() { \n    int ret = 0;\n    boolean neg;\n    try {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        neg = c == '-';\n        if (neg)\n            c = read();\n        do {\n            ret = ret * 10 + c - '0';\n            c = read();\n        } while (c > ' ');\n    \n    if (neg) return -ret;\n    } catch (Exception e) {}\n    return ret;\n    }\n    public long nextLong() { \n        long ret = 0;\n        boolean neg;\n        try {\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            neg = c == '-';\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n                c = read();\n            } while (c > ' ');\n        \n        if (neg) return -ret;\n        } catch (Exception e) {}\n        return ret;\n        }\n    private void fillBuffer() {\n        try {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n        } catch (Exception e) {}\n        if (bytesRead == -1) buffer[0] = -1;\n    }\n \n    private byte read() {\n        if (bufferPointer == bytesRead) fillBuffer();\n        return buffer[bufferPointer++];\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A\n{\n    public static void main(String args[])\n    {\n        Scanner scan = new Scanner(System.in);\n        \n        int n = scan.nextInt();\n        \n        int[] a = new int[n];\n        \n        for(int i=0;i < n;i++)\n            a[i] = scan.nextInt();\n            \n        Arrays.sort(a);\n        \n        int min = a[0];\n        \n        for(int i=1;i < n;i++)\n        {\n            if(a[i] > min)\n            {\n                System.out.println(a[i]);\n                return;\n            }\n        }\n        \n        System.out.println(\"NO\");\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class A {\n    public static void main(String[] args) throws IOException {\n        new A().run();\n    }\n\n    BufferedReader br;\n    StringTokenizer st = new StringTokenizer(\"\");\n\n    private void run() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        int n = nextInt();\n        Set<Integer> set = new TreeSet<Integer>();\n\n        for (int i = 0; i < n; i++) {\n            set.add(nextInt());\n        }\n        set.remove(set.iterator().next());\n        PrintWriter pw = new PrintWriter(System.out);\n        if (set.isEmpty()) {\n            pw.println(\"NO\");\n        } else {\n            pw.println(set.iterator().next());\n        }\n        pw.close();\n    }\n\n    int nextInt() throws IOException {\n        while (!st.hasMoreElements()) {\n            st = new StringTokenizer(br.readLine());\n        }\n        return Integer.parseInt(st.nextToken());\n    }\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main{\n\n        BufferedReader in;\n        StringTokenizer str = null;\n        PrintWriter out;\n\n        private String next() throws Exception{\n                if (str == null || !str.hasMoreTokens())\n                        str = new StringTokenizer(in.readLine());\n                return str.nextToken();\n        }\n        \n        private int nextInt() throws Exception{\n                return Integer.parseInt(next());\n        }\n        \n        private long nextLong() throws Exception{\n                return Long.parseLong(next());\n        }\n        \n        private double nextDouble() throws Exception{\n                return Double.parseDouble(next());\n        }\n\n        public void run() throws Exception{\n                in = new BufferedReader(new InputStreamReader(System.in));//new FileReader();\n                out = new PrintWriter(System.out);//new File();\n                int n = nextInt();\n                HashSet<Integer> hs = new HashSet<Integer>();\n                for(int i=0;i<n;i++) hs.add(nextInt());\n                if (hs.size() == 1){\n                  out.println(\"NO\");\n                  out.close();\n                  return;\n                }\n                int a[] = new int[hs.size()];\n                int yk = 0;\n                for(int i:hs) a[yk++] = i;\n                Arrays.sort(a);\n                out.println(a[1]);\n                out.close();\n        }\n\n        public static void main(String args[]) throws Exception{\n                new Main().run();\n        }\n}\n \n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*; \n \npublic class Main{ \n        public static void main(String[] args){ \n                Scanner sc = new Scanner(System.in); \n                int n = sc.nextInt(); \n                TreeSet<Integer> set = new TreeSet<Integer>(); \n \n                for(int i=0;i<n;i++){ \n                        set.add(sc.nextInt()); \n                } \n \n                if(set.size() >= 2) \n                        System.out.println(set.toArray()[1]); \n                else \n                        System.out.println(\"NO\"); \n        } \n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskA implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\n\tpublic static void main(String[] args) {\n//\t\tnew Thread(new Template()).start();\n\t\tnew TaskA().run();\n\t}\n\n\tpublic TaskA() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//\t\t\tout.print(\"Case \" + (testNumber + 1) + \": \");\n//        }\n\t\tint n = in.readInt();\n\t\tint min = 101;\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmin = Math.min(min, a[i] = in.readInt());\n\t\tint ans = 101;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i] > min)\n\t\t\t\tans = Math.min(ans, a[i]);\n\t\t}\n\t\tif (ans == 101)\n\t\t\tout.println(\"NO\");\n\t\telse\n\t\t\tout.println(ans);\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class VtoraiaStat implements Runnable {\n\n    boolean isLocalMode = false;\n\n\n    private void doJob() throws Exception {\n       int n  = nextInt();\n        int[] r = new int[n];\n        for(int i =0;i<n;i++){\n            r[i]=nextInt();\n        }\n\n        Arrays.sort(r);\n        int m = r[0];\n        for(int i=0;i<n;i++){\n            if(r[i]!=m){\n                writer.write(\"\"+r[i]);\n                return;\n            }\n        }\n        writer.write(\"NO\");\n    }\n\n\n    public static void main(String[] args) {\n        new VtoraiaStat().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\n    public void run() {\n        try {\n            reader = new BufferedReader(getReader());\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            //do job\n            doJob();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\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    public Reader getReader() throws FileNotFoundException {\n        if (isLocalMode) {\n            return new FileReader(\"input.txt\");\n        } else {\n            return new InputStreamReader(System.in);\n        }\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        // TODO code application logic here\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int iTotTerm, i, j, iSml = 0, iPos = 0;\n        iTotTerm = Integer.parseInt(br.readLine());\n        String seq[];\n        seq = br.readLine().split(\" \");\n        int iSeq[] = new int[iTotTerm];\n        for (i = 0; i < iTotTerm; i++) {\n            iSeq[i] = Integer.parseInt(seq[i]);\n        }\n        for (i = 0; i < iTotTerm; i++) {\n            iSml = iSeq[i];\n            iPos = i;\n            for (j = i; j < iTotTerm; j++) {\n                if (iSeq[j] < iSml) {\n                    iSml = iSeq[j];\n                    iPos = j;\n                }\n            }\n            iSeq[iPos] = iSeq[i];\n            iSeq[i] = iSml;\n            if (i != 0 && iSeq[i - 1] != iSeq[i]) {\n                break;\n            }\n        }\n        if (iSml != iSeq[0]) {\n            System.out.print(iSml);\n        } else {\n            System.out.print(\"NO\");\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tpublic static void main(String []args){\n\t\tScanner cin = new Scanner( System.in );\n\t\tint n  = cin.nextInt();\n\t\tint [] num = new int [ n ];\n\t\t\n\t\tfor (int i=0; i<n; i++)\n\t\t\tnum[i] = cin.nextInt();\n\t\t\n\t\tArrays.sort( num );\n\t\t\n\t\tint i = 0;\n\t\twhile ( i < n ){\n\t\t\tif ( num[i] != num[0] ) break;\n\t\t\ti++;\n\t\t}\n\t\t\n\t\tif ( i == n ) System.out.println(\"NO\");\n\t\telse System.out.println(num[i]);\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Blah\n{\n    public static void main(String args[])\n    {\n\tScanner c = new Scanner(System.in);\n\tString number = c.nextLine();\n\tint i = Integer.parseInt(number);\n\tif (i == 1)\n\t    {\n\t\tSystem.out.println(\"NO\");\n\t\treturn;\n\t    }\n\tString line = c.nextLine();\n\tString[] arr = line.split(\" \");\n\tint[] array = new int[i];\n\tfor (int j = 0; j < i; j++)\n\t    {\n\t\tarray[j] = Integer.parseInt(arr[j]);\n\t    }\n        int min = array[0];\n\tint second = 0;\n\tboolean thing = false;\n\tfor (int j = 0; j < i; j++)\n\t    {\n\t\tif (!thing && array[j] > min)\n\t\t    {\n\t\t\tsecond = array[j];\n\t\t\tthing = true;\n\t\t    }\n\t\tif (array[j] < min)\n\t\t    {\n\t\t\tsecond = min;\n\t\t\tmin = array[j];\n\t\t\tthing = true;\n\t\t    }\n\t\telse if (thing && array[j] > min && array[j] < second)\n\t\t    second = array[j];\n\t    }\n\tif (!thing)\n\t    System.out.println(\"NO\");\n\telse\n\t    System.out.println(second);\n\treturn;\t     \n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class prob1 {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tif(n == 1)\n\t\t{\n//\t\t\tthrow new RuntimeException();\n\t\t\tint m = input.nextInt();\n\t\t\tSystem.out.println(\"NO\");\n//\t\t\tSystem.out.println(input.next());\n\t\t\treturn;\n\t\t}\n\t\tint[] num = new int[n];\n\t\tboolean flag  = false;\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tnum[i] = input.nextInt();\n\t\t\tif(num[i] != num[0])\n\t\t\t\tflag = true;\n\t\t}\n\t\tif(!flag)\n\t\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tif(num[i] < min)\n\t\t\t\tmin = num[i];\n\t\tint min2 = Integer.MAX_VALUE;\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tif(num[i] <= min2 && num[i] > min)\n\t\t\t\tmin2 = num[i];\n\t\tSystem.out.println(min2);\n\t\t\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "//package codeforces.br22;\n\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\n\n/**\n * User: Kandy\n * Date: 29.06.2010\n * Time: 21:07:24\n */\npublic class ProblemA {\n    public void solve() {\n        boolean oj = true;\n\n        try {\n            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"A.in\");\n            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"A.out\");\n            BufferedReader br = new BufferedReader(reader);\n            StreamTokenizer st = new StreamTokenizer(reader);\n            PrintWriter out = new PrintWriter(writer);\n\n            MyTokenizer tok = new MyTokenizer(br.readLine());\n            int n = (int)tok.getNum();\n            tok =new MyTokenizer(br.readLine());\n            List<Integer> a = new ArrayList<Integer>();\n            for(int i=0;i<n;i++) {\n                int r = (int)tok.getNum();\n                if (!a.contains(r)) {\n                    a.add(r);\n                }\n            }\n            Collections.sort(a);\n            if (a.size() < 2) {\n                out.printf(\"NO\");\n            } else {\n                out.printf(\"%d\", a.get(1));\n            }\n\n            br.close();\n            out.close();\n            reader.close();\n            writer.close();\n        }\n        catch (Exception ex) {\n            ex.printStackTrace();\n        }\n        finally {\n        }\n    }\n\n\n    public static void main(String[] args) {\n        ProblemA f = new ProblemA();\n        f.solve();\n    }\n\n    private class MyTokenizer {\n        private String s;\n        private int cur;\n\n        public MyTokenizer(String s) {\n            this.s = s;\n            cur = 0;\n        }\n\n        public void skip() {\n            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\\n')) {\n                cur++;\n            }\n        }\n\n        public double getNum() {\n            skip();\n            String snum = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {\n                snum += s.charAt(cur);\n                cur++;\n            }\n            return Double.valueOf(snum);\n        }\n\n        public String getString() {\n            skip();\n            String s2 = \"\";\n            while (cur < s.length() && (((s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) || ((s.charAt(cur) >= 'A' && s.charAt(cur) <= 'Z')))) {\n                s2 += s.charAt(cur);\n                cur++;\n            }\n            return s2;\n        }\n\n        public char getCurrentChar() throws Exception {\n            if (cur < s.length())\n                return s.charAt(cur);\n            else\n                throw new Exception(\"Current character out of string length\");\n        }\n\n        public void moveNextChar() {\n            if (cur < s.length())\n                cur++;\n        }\n\n        public boolean isFinished() {\n            return cur >= s.length();\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main2 {\n    public static void main(String[] args) throws Exception {\n        new Main2().run();\n    }\n\n    public void solve() throws Exception {\n        n = nextInt();\n        int a[]= new int[n], pos = 1;\n        for(int i=0; i<n; i++)\n            a[i] = nextInt();\n        Arrays.sort(a);\n        if(n == 1){\n            out.println(\"NO\"); return;\n        }\n        boolean has = false;\n        for(; pos<n; pos++){\n            if(a[pos] != a[0]){\n                has = true;\n                break;\n            }\n        }\n        if(!has){\n            out.println(\"NO\");\n        }\n        else{\n            out.println(a[pos]);\n        }\n    }\n    public int n, m;\n\n    public void run() throws Exception {\n        inter = new StreamTokenizer(new BufferedReader(new InputStreamReader(\n                System.in)));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n        solve();\n        out.flush();\n    }\n    public BufferedReader in;\n    public StreamTokenizer inter;\n    public PrintWriter out;\n\n    public int nextInt() throws Exception {\n        inter.nextToken();\n        return (int) inter.nval;\n    }\n    public String nextLine() throws Exception{\n        return in.readLine();\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n        int first = Integer.MAX_VALUE, second = Integer.MAX_VALUE;\n\n        for (int i = 0, x; i < N; ++i) {\n            x = sc.nextInt();\n            if (x < first) {\n                second = first;\n                first = x;\n            } else if (x > first && x < second) {\n                second = x;\n            }\n        }\n\n        if (second == Integer.MAX_VALUE)\n            System.out.println(\"NO\");\n        else\n            System.out.println(second);\n    }\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class A {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        HashSet<Integer> set = new HashSet<Integer>();\n        \n        for ( int i = 0 ; i < n ; ++i ) {\n            set.add(sc.nextInt());\n        } // for i\n        \n        ArrayList<Integer> list = new ArrayList<Integer>(set);\n        Collections.sort(list);\n        if(list.size() > 1)\n        System.out.println(list.get(1));\n        else\n            System.out.println(\"NO\");\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(new InputStreamReader(System.in));\n\t\tint n = s.nextInt();\t\n\t\tint [] ar = new int[n];\n\t\tfor (int i = 0; i < n ; i++) {\n\t\t\tar[i] = s.nextInt();\n\t \t}\n\t\tif(ar.length == 1){\n\t\t\tSystem.out.println(\"NO\");\n\t\t}else{\n\t\t\tArrays.sort(ar);\n\t\t\tint num = ar[0];\n\t\t\tboolean flag = false;\n\t\t\tfor (int i = 1; i < ar.length; i++) {\n\t\t\t\tif(ar[i]!= num){\n\t\t\t\t\tSystem.out.println(ar[i]);\n\t\t\t\t\tflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!flag)\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\t}\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(in.readLine());\n\t\t\n\t\tint nums[] = new int[n];\n\t\tStringTokenizer tokenizer = new StringTokenizer(in.readLine(), \" \");\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnums[i] = Integer.parseInt(tokenizer.nextToken());\n\t\t}\n\t\t\n\t\tArrays.sort(nums);\n\t\tint min = nums[0];\n\t\tint so = -200;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif(nums[i] != min) {\n\t\t\t\tso = nums[i];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(so != -200)\n\t\tSystem.out.println(so);\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextInt();\n\t\tArrays.sort(a);\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tif (a[i] != a[0]) {\n\t\t\t\tout.print(a[i]);\n\t\t\t\treturn;\n\t\t\t}\n\t\tout.print(\"NO\");\n\t}\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\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", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.sort;\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.SortedSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class SecondOrderStatistics implements Runnable\n{\n  public static void main(String[] args) throws Exception\n  {\n    new SecondOrderStatistics().run();\n  }\n\n  private void solve() throws Exception\n  {\n    int n = nextInt();\n    SortedSet<Integer> sset = new TreeSet<Integer>();\n    for (int i = 0; i < n; i++)\n    {\n      int a = nextInt();\n      sset.add(a);\n    }\n\n    if (sset.size() < 2)\n      out.println(\"NO\");\n    else\n    {\n      Integer v[] = (Integer[]) sset.toArray(new Integer[sset.size()]);\n      sort(v);\n      out.println(v[1]);\n    }\n  }\n\n  // -------------- Input/Output routines below ---------------//\n  private BufferedReader in;\n  PrintWriter out;\n  StringTokenizer tokenizer;\n\n  public void run()\n  {\n    // String problem = this.getClass().getName();\n    try\n    {\n      in = new BufferedReader(new InputStreamReader(System.in));\n      out = new PrintWriter(new BufferedOutputStream(System.out));\n      solve();\n      out.flush();\n      in.close();\n      out.close();\n    }\n    catch (Exception e)\n    {\n      e.printStackTrace();\n      // System.exit(1);\n    }\n  }\n\n  String nextToken() throws IOException\n  {\n    while (tokenizer == null || !tokenizer.hasMoreTokens())\n    {\n      tokenizer = new StringTokenizer(in.readLine());\n    }\n    return tokenizer.nextToken();\n  }\n\n  int nextInt() throws IOException\n  {\n    return Integer.parseInt(nextToken());\n  }\n\n  long nextLong() throws IOException\n  {\n    return Long.parseLong(nextToken());\n  }\n\n  double nextDouble() throws IOException\n  {\n    return Double.parseDouble(nextToken());\n  }\n\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Date;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t    Scanner s = new Scanner(System.in);\n\t    int n = s.nextInt();\n\t    int[] a = new int[n];\n\t    for(int i=0;i<n;i++)\n\t        a[i] = s.nextInt();\n\t    Arrays.sort(a);\n\t    int min = a[0];\n\t    if (a[0] == a[n-1]){\n\t        System.out.println(\"NO\");\n\t    }else{\n\t        for(int i=1;;i++){\n\t            if (a[i] > min) {\n\t                System.out.println(a[i]);\n\t                break;\n\t            }\n\t        }\n\t    }\n\t}\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n\n    void solve() throws IOException {\n        int n = ni();\n        int[] v = new int[n];\n        for (int i = 0; i < n; ++i)\n            v[i] = ni();\n        Arrays.sort(v);\n        int mn = v[0];\n        for (int i = 1; i < n; ++i)\n            if (v[i] > mn) {\n                out.println(v[i]);\n                return;\n            }\n        out.println(\"NO\");\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", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "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 A22 {\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\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextInt();\n\t\t\n\t\tArrays.sort(a);\n\t\tint f = a[0], q = 1;\n\t\twhile (q < n && a[q] == f) q++;\n\t\t\n\t\tout.println(q < n ? a[q] : \"NO\");\n\t\t\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "\n\n/**\n *\n * @author ishani\n */\nimport java.util.*;\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n\n        TreeSet<Integer> set = new TreeSet<Integer>();\n\n        for(int i=0;i<N;i++){\n            int a = sc.nextInt();\n            set.add(a);\n        }\n\n        if(set.size()==1)System.out.println(\"NO\");\n        else{\n            set.remove(set.first());\n            System.out.println(set.first());\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\npublic class CF22_1 {\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int num=sc.nextInt();\n    if(num!=1)\n    {\n        ArrayList<Integer>data=new ArrayList<Integer>();\n        for (int i=0;i<num;i++){\n            data.add(sc.nextInt());\n            \n        }\n        Collections.sort(data);\n        \n        int ind=1;\n    \n        while( data.get(ind-1)==data.get(ind) )\n            {\n            ind++;\n            if(ind ==data.size())\n                break;\n            }\n        \n        if(data.size()>ind)\n        System.out.println(data.get(ind));\n        else\n            System.out.println(\"NO\");\n        \n        \n    }\n    else\n        System.out.println(\"NO\");\n    }\n    \n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*; \n \npublic class Main \n{ \n public static void main(String[] args) \n { \n  Scanner keyboard = new Scanner(System.in); \n  int size = keyboard.nextInt(); \n  int[] arr = new int[size]; \n  int i = 0; \n  while( size != 0 ) \n  {  \n   arr[i] = keyboard.nextInt(); \n   size--;  \n   i++; \n  } \n   //System.out.print(\"size \" + arr.length );\n   Arrays.sort(arr); \n \n   int index = 0; \n   boolean val = false; \n   int ans = 0; \n   for ( i = 0; i< arr.length-1 ; i++ ) \n   { \n    //System.out.print(\" arr[i] \" + arr[i] + \" arr[i+1] \" + arr[i+1] + \"\\n\" );\n    if( arr[i] != arr[i+1] ) \n    { \n     val = true; \n     //System.out.print(\"Changed val to true\");\n     index = i+1; \n      System.out.println(arr[index]); \n      return; \n    } \n   } \n     \n    if (size == 1 || ( val == false))\n    { \n        System.out.println(\"NO\");    \n    } \n \n    \n } \n  \n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n    void run()throws IOException{\n        Scanner sc = new Scanner(new InputStreamReader(System.in));\n        int n = sc.nextInt();\n        int i;\n        int[] ar = new int[n];\n        for(i=0; i<n; i++){\n            ar[i] = sc.nextInt();\n        }\n        Arrays.sort(ar);\n        int min = ar[0];\n        for(i=1;i<n;i++){\n            if(ar[i]>min) break;\n        }\n        if(i<n) System.out.println(ar[i]);\n        else System.out.println(\"NO\");\n    }\n    \n    public static void main(String[] args)throws IOException {\n        new A().run();\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Beta22PA {\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 scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint minimum = 200, second = 200;\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tint temp = scan.nextInt();\n\t\t\tif(temp<minimum) {\n\t\t\t\tsecond = minimum;\n\t\t\t\tminimum = temp;\n\t\t\t} else if(temp>minimum&&temp<second) {\n\t\t\t\tsecond = temp;\n\t\t\t}\n\t\t}\n\t\tif(second>100) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t} else {\n\t\t\tSystem.out.println(second);\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "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.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n\npublic class order {\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(new BufferedWriter(\n\t\t\t\tnew OutputStreamWriter(System.out)));\n\t\tint n=Integer.parseInt(in.readLine());\n\t\tSet<Integer> set = new TreeSet<Integer>();\n\t\tStringTokenizer st= new StringTokenizer(in.readLine());\n\t\tint a;\n\t\tList<Integer> list =new LinkedList<Integer>();\n\t\twhile(st.hasMoreTokens()){\n\t\t\ta= Integer.parseInt(st.nextToken());\n\t\t\tif(!set.contains(a)){\n\t\t\t\tlist.add(a);\n\t\t\t\tset.add(a);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tif(list.size()==1){\n\t\t\tout.println(\"NO\");\n\t\t}else{\n\t\t\tCollections.sort(list);\n\t\t\tout.println(list.get(1));\n\t\t}\n\t\tout.close();\n\t\tSystem.exit(0);\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n/**\n *\n * @author Izhari Ishak Aksa\n */\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        Hashtable<Integer, Integer> hi = new Hashtable<Integer, Integer>();\n        for (int i = 0; i < n; i++) {\n            int m = sc.nextInt();\n            hi.put(m, 1);\n        }\n        Set<Integer> set = hi.keySet();\n        Integer[] key = set.toArray(new Integer[set.size()]);\n        Arrays.sort(key);\n        try {\n            System.out.println(key[1]);\n        } catch (Exception e) {\n            System.out.println(\"NO\");\n        }\n    }\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.StreamTokenizer;\nimport java.lang.reflect.Array;\nimport java.util.Arrays;\n\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\t//BufferedReader input = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t//BufferedWriter output = new BufferedWriter(new FileWriter(\"output.txt\"));\n\t\tBufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tStreamTokenizer in = new StreamTokenizer(input);\n\t\t\n\t\tin.nextToken();\n\t\tint n = (int)in.nval;\n\t\tint[] mas = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tin.nextToken();\n\t\t\tmas[i] = (int)in.nval;\n\t\t}\n\t\t\n\t\tArrays.sort(mas);\n\t\tint min = mas[0];\n\t\tint i = 1;\n\t\t\n\t\twhile ((i < n)&&(min == mas[i])) {\n\t\t\ti++;\n\t\t}\n\t\t\n\t\tif (i < n) {\n\t\t\toutput.write(Integer.toString(mas[i]));\n\t\t}\n\t\telse {\n\t\t\toutput.write(\"NO\");\n\t\t}\n\t\tinput.close();\n\t\toutput.close();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Test \n{\n    public static void main(String[] args) \n    {\n    \tScanner t = new Scanner(System.in);\n    \tint n=t.nextInt();\n    \tint a[]= new int[n];\n    \tfor(int i=0; i<n; i++)\n    \t\ta[i]=t.nextInt();\n    \tArrays.sort(a);\n    \tint r=a[0];\n    \tfor(int i=1; i<n; i++)\n    \t\t\tif(a[i]!=r)\n    \t\t\t{\n    \t\t\t\tSystem.out.println(a[i]);\n    \t\t\t\tSystem.exit(0);\n    \t\t\t}\n    \tSystem.out.println(\"NO\");       \t\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n//package a_vtoray_poriadkovay_statistika;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author kal1sha\n */\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 hereSc\n        int n, i;\n        boolean status = false;\n        int answer;\n        Scanner in = new Scanner(System.in);\n        n = in.nextInt();\n        int a[] = new int[n];\n        for (i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n        Arrays.sort(a);\n        answer = a[0];\n        for (i = 1; i < n; i++) {\n            if (a[i] != answer) {\n                answer = a[i];\n                status = true;\n                i = n + 1;\n            }\n        }\n        if (status) {\n            System.out.println(answer);\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tprivate void 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\t\tArrays.sort(a);\n\t\tint i = 0;\n\t\twhile (i < n && a[i] == a[0])\n\t\t\ti++;\n\t\tif (i < n)\n\t\t\tSystem.out.println(a[i]);\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\tsc.close();\n\t}\n\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "//package timus;\n\nimport 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.Arrays;\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\n    void init() throws IOException {\n        oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\n                \"input.txt\");\n        Writer writer = oj ? new OutputStreamWriter(System.out)\n                : new FileWriter(\"output.txt\");\n        // Writer writer = new OutputStreamWriter(System.out);\n        in = new StreamTokenizer(new BufferedReader(reader));\n        out = new PrintWriter(writer);\n    }\n\n    void run() throws IOException {\n        long beginTime = System.currentTimeMillis();\n        init();\n        solve();\n        out.flush();\n    }\n\n    void printMem() {\n        if (!oj) {\n            System.out.println(\"Memory used = \"\n                    + (Runtime.getRuntime().totalMemory() - Runtime\n                            .getRuntime().freeMemory()));\n        }\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    long deg(long x, long y) {\n        long a = x;\n        for (long i = 2; i <= y; i++) {\n            a *= x;\n        }\n        return a;\n    }\n\n    long fact(long x) {\n        long a = 1;\n        for (long i = 2; i <= x; i++) {\n            a *= i;\n        }\n        return a;\n    }\n\n    long digitSum(String x) {\n        long a = 0;\n        for (int i = 0; i < x.length(); i++) {\n            a += x.codePointAt(i) - 48;\n        }\n        return a;\n    }\n\n    long digitSum(long x) {\n        long a = 0;\n        while (x > 0) {\n            a += x % 10;\n            x /= 10;\n        }\n        return a;\n    }\n\n    long digitMul(long x) {\n        long a = 1;\n        while (x > 0) {\n            a *= x % 10;\n            x /= 10;\n        }\n        return a;\n    }\n\n    double pif(double ax, double ay, double bx, double by) {\n        return Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n    }\n\n    double getPosPart(double x) {\n        if (x <= 0)\n            return 0;\n        else\n            return x;\n    }\n\n    double max(double x, double y) {\n        if (x > y)\n            return x;\n        else\n            return y;\n    }\n\n    long gcd(long a, long b) {\n        if (a < b) {\n            long c = b;\n            b = a;\n            a = c;\n        }\n        while (a % b != 0) {\n            a = a % b;\n            if (a < b) {\n                long c = b;\n                b = a;\n                a = c;\n            }\n        }\n        return b;\n    }\n\n    int gcd(int a, int b) {\n        if (a < b) {\n            int c = b;\n            b = a;\n            a = c;\n        }\n        while (a % b != 0) {\n            a = a % b;\n            if (a < b) {\n                int c = b;\n                b = a;\n                a = c;\n            }\n        }\n        return b;\n    }\n\n    long lcm(long a, long b) throws IOException {\n        return a * b / gcd(a, b);\n    }\n\n    int lcm(int a, int b) throws IOException {\n        return a * b / gcd(a, b);\n    }\n\n    int countOccurences(String x, String y) {\n        int a = 0, i = 0;\n        while (true) {\n            i = y.indexOf(x);\n            if (i == -1)\n                break;\n            a++;\n            y = y.substring(i + 1);\n        }\n        return a;\n    }\n\n    int[] primes;\n\n    int findPrimes(int x) {\n        boolean[] forErato = new boolean[x];\n        primes = new int[x];\n        int l = 0, j = 0;\n        for (int i = 2; i < x; i++) {\n            if (forErato[i])\n                continue;\n            l++;\n            primes[l] = i;\n            j = i * 2;\n            while (j < x) {\n                forErato[j] = true;\n                j += i;\n            }\n        }\n        return l;\n    }\n\n    int rev(int x) {\n        int a = 0;\n        while (x > 0) {\n            a = a * 10 + x % 10;\n            x /= 10;\n        }\n        return a;\n    }\n\n    class myDate {\n        int d, m, y;\n\n        public myDate(int da, int ma, int ya) {\n            d = da;\n            m = ma;\n            y = ya;\n        }\n\n        int[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n        void inc() {\n            if ((d == 31) && (m == 12)) {\n                y++;\n                d = 1;\n                m = 1;\n            } else {\n                if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n                    ml[1] = 29;\n                }\n                if (d == ml[m - 1]) {\n                    m++;\n                    d = 1;\n                } else\n                    d++;\n            }\n        }\n    }\n\n    int partition(int n, int l, int m) {// n - sum, l - length, m - every part\n        // <= m\n        if (n < l)\n            return 0;\n        if (n < l + 2)\n            return 1;\n        if (l == 1)\n            return 1;\n        int c = 0;\n        for (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n            c += partition(n - i, l - 1, i);\n        }\n        return c;\n    }\n\n    void solve() 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        }\n        Arrays.sort(a);\n        int min = a[0];\n        for (int i = 1; i < n; i++) {\n            if (a[i] != min) {\n                out.print(a[i]);\n                return;\n            }\n        }\n        out.print(\"NO\");\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n        int first = Integer.MAX_VALUE, second = Integer.MAX_VALUE;\n\n        for (int i = 0, x; i < N; ++i) {\n            x = sc.nextInt();\n            if (x < first) {\n                second = first;\n                first = x;\n            } else if (x > first && x < second) {\n                second = x;\n            }\n        }\n\n        if (second == Integer.MAX_VALUE)\n            System.out.println(\"NO\");\n        else\n            System.out.println(second);\n    }\n\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main {\n    public static void main (String [] args) throws IOException {\n        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        int [] nums = new int[n];\n        args = br.readLine().split(\" \");\n        for (int i = 0; i < n; i++) {\n            nums[i] = Integer.parseInt(args[i]);\n        }\n        Arrays.sort(nums);\n        int min = nums[0];\n        for (int i = 1; i < n; i++) {\n            if (nums[i]>min) {\n                System.out.println(nums[i]); return;\n            }\n        }\n        System.out.println(\"NO\");\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class CDF22_A {\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n        int[] A = new int[N];\n        for (int i=0; i<N; i++)\n            A[i] = sc.nextInt();\n        Arrays.sort(A);\n        int i = 0;\n        while (i < A.length && A[i] == A[0]) i++;\n        System.out.println(i == A.length ? \"NO\" : A[i]);\n        sc.close();\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(new InputStreamReader(System.in));\n        int n = s.nextInt();\n        if (n == 1) {\n            System.out.println(\"NO\");\n            System.exit(0);\n        }\n        int[] nums = new int[n];\n        for (int i = 0; i < n; i++) {\n            nums[i] = s.nextInt();\n        }\n        Arrays.sort(nums);\n        int x = 1;\n        while (x < n && nums[x] == nums[x - 1])\n            x++;\n        if (x == n) {\n            System.out.println(\"NO\");\n            System.exit(0);\n        } else {\n            System.out.println(nums[x]);\n            System.exit(0);\n        }\n\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        solve();\n\n        in.close();\n        out.close();\n    }\n\n    private static void solve() throws Exception {\n        int n = nextInt();\n        boolean[] use = new boolean[500];\n        ArrayList<Integer> a = new ArrayList<Integer>();\n        for (int i = 0; i < n; i++) {\n            int v = nextInt();\n            if (!use[250 + v]) {\n                use[250 + v] = true;\n                a.add(v);\n            }\n        }\n        Collections.sort(a);\n        if (a.size() < 2) {\n            out.println(\"NO\");\n        } else {\n            out.println(a.get(1));\n        }\n    }\n\n    static BufferedReader in;\n    static PrintWriter out;\n    static StringTokenizer st;\n\n    static String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    static double nextDouble() throws IOException {\n        return Double.parseDouble(nextString());\n    }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;   \n   \npublic class Main   \n{   \n public static void main(String[] args)   \n {   \n  Scanner keyboard = new Scanner(System.in);   \n  int size = Integer.parseInt(keyboard.nextLine());   \n  int[] arr = new int[size];   \n  int i = 0;   \n  while( size != 0 )   \n  {    \n   arr[i] = keyboard.nextInt();   \n   size--;    \n   i++;   \n  }   \n   \n  if( arr.length == 1 )    \n  {   \n   System.out.println(\"NO\");   \n  }   \n  else   \n  {   \n   Arrays.sort(arr);   \n   boolean val = false;   \n   int ans = 0;   \n   for ( i = 0; i< arr.length-1 ; i++ )   \n   {   \n    if( arr[i] != arr[i+1] )   \n    {   \n     val = true;   \n     ans = arr[i+1];   \n     System.out.println(ans);   \n     i = arr.length;   \n    }    \n    else if( i == arr.length-2 ) //val == false  \n    {   \n     System.out.println(\"NO\");      \n    }   \n   }   \n  }\n }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew A().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\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\tvoid solve() {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint i = 1;\n\t\twhile (i < n && a[i] == a[i - 1]) {\n\t\t\t++i;\n\t\t}\n\t\tif (i >= n) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(a[i]);\n\t\t}\n\t}\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "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\n/* Template for TopCoder and ACMonline. */\npublic class A {\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        new A().solve();\n        out.flush();\n    }\n    \n    public void solve() throws IOException {\n        int n = nextInt();\n        int min = Integer.MAX_VALUE;\n        int res = Integer.MAX_VALUE;\n        for (int i=0; i<n; ++i) {\n            int d = nextInt();\n            if (d<min) {\n                res = min;\n                min = d;\n            } else if (d>min && d<res)\n                res = d;\n        }\n        if (res == Integer.MAX_VALUE)\n            out.println(\"NO\");\n        else\n            out.println(res);\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\tpublic void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ta[i] = in.nextInt();\n\t\t\tif (a[i] < min) {\n\t\t\t\tmin = a[i];\n\t\t\t}\n\t\t}\n\t\tint res = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (a[i] != min && a[i] < res) {\n\t\t\t\tres = a[i];\n\t\t\t}\n\t\t}\n\t\tif (res == Integer.MAX_VALUE) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(res);\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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\tprivate class Scanner {\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\n\n\npublic class Main {\n\tprivate static StreamTokenizer in;\n\tprivate static PrintWriter out;\n\t\n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t}\n\t\n\tprivate static String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i=0; i<n; i++)\n\t\t\ta[i] = nextInt();\n\t\tArrays.sort(a);\n\t\tint u = a[0];\n\t\tfor (int i=0; i<n; i++)\n\t\t\tif (a[i]>u) {\n\t\t\t\tout.println(a[i]);\n\t\t\t\tout.flush();\n\t\t\t\treturn;\n\t\t\t}\n\t\tout.println(\"NO\");\n\t\tout.flush();\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "//package round22;\n\n\nimport java.io.PrintWriter;\nimport java.io.StringReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n//\tprivate String INPUT = \"5 1 2 3 1 1\";\n\tprivate String INPUT = \"\";\n\t\n\tpublic void solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\ta[i] = ni();\n\t\t}\n\t\tArrays.sort(a);\n\t\tfor(int i = 1;i < n;i++){\n\t\t\tif(a[i] > a[i - 1]){\n\t\t\t\tout.println(a[i]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"NO\");\n\t}\n\t\n\tpublic void run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new StringReader(INPUT));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew A().run();\n\t}\n\t\n\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class Main{\n\n    Scanner sc=new Scanner(System.in);\n    \n    void run(){\n        int n = sc.nextInt();\n        \n        int x[] = new int [n];\n        \n        for (int i=0;i<n;i++) \n            x[i] = sc.nextInt();\n        \n        java.util.Arrays.sort(x);\n        \n        int i = 0;\n        \n        for(i=0;i<n-1;i++) {\n            if (x[i] != x[i+1]) {\n                System.out.println( x[i+1] );\n                return;\n            }\n        }\n\n        System.out.println(\"NO\");\n        \n        return;\n        \n    }\n    \n    public static void main(String[] args){\n        new Main().run();\n    }\n}", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "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 n = sc.nextInt();\n\t\tTreeSet<Integer> set = new TreeSet<Integer>();\n\n\t\tfor(int i=0;i<n;i++){\n\t\t\tset.add(sc.nextInt());\n\t\t}\n\n\t\tif(set.size() >= 2)\n\t\t\tSystem.out.println(set.toArray()[1]);\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\n\npublic class One {\n\tInputStreamReader inp = new InputStreamReader(System.in);\n\tBufferedReader in = new BufferedReader(inp);\n\tboolean test = false;\n\n\t// String[] inData = { \"4\", \"A\", \"B\", \"C\", \"D\", \"A-B 1:1\", \"A-C 2:2\",\n\t// \"A-D 1:0\", \"B-C 1:0\", \"B-D 0:3\", \"C-D 0:3\" };\n\tString[] inData = { \"4\",\"1 1 2\" };\n\n\tstatic int id = -1;\n\n\tpublic String readLine() throws IOException {\n\t\tid++;\n\t\tif (test)\n\t\t\treturn inData[id];\n\t\telse\n\t\t\treturn in.readLine();\n\t}\n\n\tpublic void solve() throws Exception {\n\t\treadLine();\n\t\tString readLine = readLine();\n\t\t\n\t\tString[] split = readLine.split(\" \");\n\t\tList<Integer> ints = new ArrayList<Integer>();\n\t\t\n\t\tfor (int i = 0; i < split.length; i++) {\n\t\t\tints.add(Integer.valueOf(split[i]));\n\t\t}\n\t\t\n\t\tCollections.sort(ints);\n\t\tInteger object = ints.get(0);\n\t\tfor (int i = 0; i < split.length; i++) {\n\t\t\tif(ints.get(i).compareTo(object) > 0){\n\t\t\t\tSystem.out.println(ints.get(i));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tnew One().solve();\n\n\t}\n}\n", "complexity": "nlogn", "problem": "22_A. Second Order Statistics", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class Main {\n\t\n\t// static int INF=1<<28;\n\t//int x,y;\n\tstatic int sum=0;\n    //static ArrayList<Integer> lis = new ArrayList<Integer>();\n\t\n\tpublic static void main(String[] args)throws Exception{\n\t//\tScanner sc =new Scanner(new File(\"input.txt\"));\n\t\tScanner sc =new Scanner(System.in);\n     // File file = new File(\"prime2.txt\");\n\t//\tPrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));\n\t//\tsc.useDelimiter(\"(\\\\s)+|[,]\");\n\t//\tArrayList<Integer> lis = new ArrayList<Integer>();\n\t//ArrayList<String> lis = new ArrayList<String>();\n\t//System.out.println();\n    //  for(int i=0;i<;i++)\n\t\t\n   while(sc.hasNext()){\n\t \n\t int n=ni(sc),x[]=new int[n+1];\n\t for(int i=1;i<=n;i++)x[i]=ni(sc);\n\t sort(x);\n\t if(x[n]==1){x[n]=2;for(int i=1;i<=n;i++)System.out.print(x[i]+\" \");}\n\t else{x[0]=1;\n\t for(int i=0;i<n;i++)System.out.print(x[i]+\" \");\n\t }\n      \n   }\n\t \n\t   \n\t  \n\t}\n\t\n\t\n\t\n\tstatic void db(Object... os){\n\t         System.err.println(Arrays.deepToString(os));\n\t}\n\t\n\n\tstatic int ni(Scanner in){\n\t\treturn in.nextInt();  \n\t}\n\t\t\n}\n\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class TaskA {\n\tvoid Run() throws IOException {\n\t\tint n=ReadInt();\n\t\tint[] arr=new int[n];\n\t\tfor(int i=0;i<n;++i)\n\t\t\tarr[i]=ReadInt();\n\t\tArrays.sort(arr);\n\t\tboolean one=true;\n\t\tfor(int x : arr)\n\t\t\tif(x!=1) {\n\t\t\t\tone=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif(one) {\n\t\t\tfor(int i=1;i<n;++i)\n\t\t\t\toutput.print(\"1 \");\n\t\t\toutput.print(\"2\");\n\t\t\treturn;\n\t\t}\n\t\tint prev=1;\n\t\tfor(int x : arr)\n\t\t\tif(x==prev) {\n\t\t\t\toutput.print(prev);\n\t\t\t\toutput.print(\" \");\n\t\t\t} else {\n\t\t\t\toutput.print(prev);\n\t\t\t\toutput.print(\" \");\n\t\t\t\tprev=x;\n\t\t\t}\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 TaskA().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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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      int n=nextInt();\n      int[]a=new int[n];\n        for(int i=0;i<n;i++)\n            a[i]=nextInt();\n        Arrays.sort(a);\n        int[]res=new int[n];\n        for(int i=0;i<n;i++)\n        {\n            if(i==0)\n                res[i]=1;\n            else\n                res[i]=a[i-1];\n        }\n        if(a[n-1]==1)\n            res[n-1]=2;\n        for(int i=0;i<n;i++)\n        {\n            if(i==n-1)\n                writer.println(res[i]);\n            else\n                writer.print(res[i]+\" \");\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 InputStreamReader(System.in));\n        stk=null;\n        writer=new PrintWriter(new PrintWriter(System.out));\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}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n//created at 6:06 PM 12/9/11 by Abrackadabra\n\npublic class A {\n    int IOMode = 0; //0 - consoleIO, 1 - <taskName>.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        int[] a = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = nextInt();\n        Arrays.sort(a);\n        int z = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i] != 1) z++;\n        }\n        if (z == 0 && n > 1) a[n - 2] = 2;\n        if (n == 1 && a[0] == 1) {\n            out.println(2);\n            return;\n        }\n        out.print(\"1 \");\n        for (int i = 0; i < n - 1; i++)\n            out.print(a[i] + \" \");\n    }\n\n    public static void main(String[] args) throws IOException {\n        if (args.length > 0 && args[0].equals(\"Abra\")) debugMode = true;\n        new A().run();\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 output:\");\n        }\n        solve();\n        finishTime = System.nanoTime();\n        finishMem = Runtime.getRuntime().totalMemory();\n        out.flush();\n        if (debugMode) {\n            int maxSymbols = 1000, c = 0;\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();\n                con.println(\"File input:\");\n                con.print(a);\n            }\n            boolean left = true;\n            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;\n            if (left) con.println(\"...\");\n            else con.println();\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();\n                con.println(\"File output:\");\n                con.print(a);\n            }\n            left = true;\n            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;\n            if (left) con.println(\"...\");\n            else con.println();\n            con.println(\"Time passed:  \" + (finishTime - startTime) / 1000000000.0 + \" sec\");\n            con.println(\"Memory used:  \" + (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) {\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    void printTime() {\n        con.println((System.nanoTime() - tempTime) + \" nanos passed\");\n        tempTime = System.nanoTime();\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}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class c {\n\tpublic static void main(String[] args)\n\t\t\tthrows IOException {\n\t\tBufferedReader r =\t\n\t\t\t\tnew BufferedReader(new InputStreamReader(System.in), 1);\n\t\tString s = r.readLine();\n\t\tint n = Integer.parseInt(s);\n\t\tString s2 = r.readLine();\n\t\tStringTokenizer st = new StringTokenizer(s2,\" \");\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = Integer.parseInt(st.nextToken());\n\t\tArrays.sort(a);\n\t\tif (a[n - 1] == 1) a[n - 1] = 2;\n\t\telse {a[n - 1] = 1; Arrays.sort(a);}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tSystem.out.println(a[i]);\n\t}\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tpublic A () throws IOException {\n\t\tString input = r.readLine();\n\t\tint N = Integer.parseInt(input);\n\t\tint [] A = new int [N];\n\t\tinput = r.readLine();\n\t\tString [] S = input.split(\" \");\n\t\tfor (int i = 0; i < N; ++i)\n\t\t\tA[i] = Integer.parseInt(S[i]);\n\t\tsolve(N, A);\n\t}\n\t\n\tpublic void solve (int N, int [] A) {\n\t\tt = millis();\n\t\tArrays.sort(A);\n\t\tif (A[N-1] > 1) A[N-1] = 1;\n\t\telse A[N-1] = 2;\n\t\tArrays.sort(A);\n\t\tSystem.out.print(A[0]);\n\t\tfor (int i = 1; i < N; ++i)\n\t\t\tSystem.out.print(\" \" + A[i]);\n\t\tSystem.out.println();\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic BufferedReader r;\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\tr = new BufferedReader(new InputStreamReader(System.in));\n\t\tnew A();\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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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\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\tint n = nextInt();\n\t\tint m[] = new int[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tm[i] = nextInt();\n\t\tsort(m);\n\t\tm[n - 1] = m[n - 1] != 1 ? 1 : 2;\n\t\tsort(m);\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tif(i != 0) out.print(\" \");\n\t\t\tout.print(m[i]);\n\t\t}\n\t\tout.println();\n\t\tin.close();\n\t\tout.close();\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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class A135 {\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(r.readLine());\n\n\t\tint[] ar = new int[n];\n\t\tStringTokenizer st = new StringTokenizer(r.readLine());\n\t\tfor (int x = 0; x < n; x++) {\n\t\t\tar[x] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tArrays.sort(ar);\n\t\tif (n == 1) {\n\n\t\t\tSystem.out.println(ar[0]==1?\"2\":\"1\");\n\t\t\treturn;\n\t\t}\n\t\tif (ar[n - 1] == 1) {\n\t\t\tar[n - 2] = 2;\n\t\t}\n\t\tSystem.out.print(\"1\");\n\t\tfor (int x = 0; x < n - 1; x++) {\n\t\t\tSystem.out.print(\" \" + ar[x]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: mac\n * Date: 11-12-9\n * Time: \u4e0b\u534810:48\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class A {\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();\n        int[] a = new int[n];\n        for (int i = 0; i < a.length; i++) {\n            a[i] = nextInt();\n        }\n        Arrays.sort(a);\n        if (a[a.length - 1] == 1) {\n            for (int i = 0; i < a.length - 1; i++) {\n                writer.print(1 + \" \");\n            }\n            writer.println(2 + \"\");\n            return;\n        }\n        for (int i = 0; i < a.length; i++) {\n            if (i == 0)\n                writer.print(1 + \" \");\n            else\n                writer.print(a[i - 1] + \" \");\n        }\n        writer.println();\n    }\n\n    static public void main(String[] args) {\n        new A().run();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class A implements Runnable{\n    \n    final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\")!=null;\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n    \n    void init() throws 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 Thread(null, new A(), \"\", 256 * (1L << 20)).start();\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    void solve() throws IOException{\n        int n = readInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++){\n            a[i] = readInt();\n        }\n        Arrays.sort(a);\n        a[n-1] = a[n-1] == 1? 2:1;\n        Arrays.sort(a);\n        for (int i = 0; i < n; i++){\n            out.print(a[i] + \" \");\n        }\n    }\n}\n\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.deepToString;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class A {\n\n\tstatic int [] solve(int [] a) {\n\t\tint n = a.length;\n\t\tArrays.sort(a);\n\t\ta[n - 1] = (a[n - 1] > 1 ? 1 : 2);\n\t\tint [] b = Arrays.copyOf(a, n);\n\t\tArrays.sort(b);\n\t\treturn b;\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\t\n\t\tint n = nextInt();\n\t\tint [] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tint [] b = solve(a);\n\t\tfor (int v: b) {\n\t\t\twriter.print(v + \" \");\n\t\t}\n\t\t\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}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\npublic class Main {\n    \n    public static void main(String[] args) throws Exception {\n        int n = nextInt();\n        \n        int[] mas = new int[n];\n        \n        for(int i = 0; i<n; i++) {\n            mas[i] = nextInt();\n        }\n        \n        Arrays.sort(mas);\n        \n        if(mas[n-1] == 1) {\n            for(int i = 0; i<n-1; i++) {\n                out.print(1 + \" \");\n            }\n            out.println(2);\n            out.flush();\n            exit();\n        }\n        \n        out.print(\"1 \");\n        \n        for(int i = 0; i<n-1; i++) {\n            out.print(mas[i] + \" \");\n        }\n        \n        out.println();\n        out.flush();\n    }\n    \n    /////////////////////////////////////////////////////////////////\n    // IO\n    /////////////////////////////////////////////////////////////////\n    private static StreamTokenizer in;\n    private static PrintWriter out;\n    private static BufferedReader inB;\n    \n    private static boolean FILE=false;\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        try {\n            out = new PrintWriter(FILE ? (new FileOutputStream(\"output.txt\")) : System.out);\n            inB = new BufferedReader(new InputStreamReader(FILE ? new FileInputStream(\"input.txt\") : System.in));\n        } catch(Exception e) {e.printStackTrace();}\n        in = new StreamTokenizer(inB);\n    }\n    /////////////////////////////////////////////////////////////////\n    \n    /////////////////////////////////////////////////////////////////\n    // pre - written\n    /////////////////////////////////////////////////////////////////\n    private static void println(Object o) throws Exception {\n        out.println(o);\n        out.flush();\n    }\n    private static void exit(Object o) throws Exception {\n        println(o);\n        exit();\n    }\n    private static void exit() {\n        System.exit(0);\n    }\n    private static final int  INF = Integer.MAX_VALUE;\n    private static final int MINF = Integer.MIN_VALUE;\n    //////////////////////////////////////////////////////////////////\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.* ;\nimport java.util.*;\n\nimport static java.lang.Math.* ;\nimport static java.util.Arrays.* ;\n\npublic class A {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tnew A().solveProblem();\n\t\t\n\t\tout.close();\n\t}\n\n\tstatic Scanner in = new Scanner(new InputStreamReader(System.in));\n\t//static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\tstatic PrintStream out = new PrintStream(new BufferedOutputStream(System.out));\n\t\n\t\n\tpublic void solveProblem() {\t\t\n\n\t\tint n = in.nextInt() ;\n\t\tE[] get = new E[n] ;\n\t\tfor( int i = 0 ; i < n ; i++ ){\n\t\t\tget[i] = new E(i,in.nextInt()) ;\n\t\t}\n\t\t\n\t\tsort(get) ;\n\t\t\n\t\n\t\tif( get[n-1].g == 1){\n\t\t\tget[n-1].g = 2 ;\n\t\t}else{\n\t\t\tget[n-1].g = 1 ;\n\t\t\t\n\t\t}\n\t\tsort(get) ;\n\t\tfor( int i = 0 ; i < n - 1 ; i++ )\n\t\t\tout.print(get[i].g  +\" \" ) ;\n\t\tout.println(get[n-1].g) ;\n\t\t\n\t}\n\t\n\tclass E implements Comparable<E>{\n\t\tint g ;\n\t\tint index ;\n\t\t\n\t\tpublic E( int index, int g){\n\t\t\tthis.g = g ;\n\t\t\tthis.index = index ;\n\t\t}\n\t\t\n\t\tpublic int compareTo( E e){\n\t\t\treturn g - e.g ;\n\t\t}\n\t}\n\n\tstatic int[] readGet( int n ){\n\t  \tint[] get = new int[n] ;\n\t  \tfor( int i = 0 ; i < n ; i++ )\n\t  \t\tget[i] = in.nextInt();\n\t  \treturn get ;\n\t}\n\t\n       \n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A_135 {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n\n        Scanner in=new Scanner(System.in);\n        \n        int n=in.nextInt();\n        \n        int[] mas=new int[n];\n        \n        for(int i=0;i<n;i++){\n            mas[i]=in.nextInt();\n        }\n        \n        Arrays.sort(mas);\n        \n        PrintWriter out=new PrintWriter(System.out);\n        \n        boolean isEd=true;\n        for(int i=0;i<n;i++)\n            if(mas[i]!=1){\n                isEd=false;\n                break;\n            }\n        \n        if(!isEd)\n            out.print('1');\n        \n        for(int i=0;i<n-1;i++){\n            out.print(' ');\n            out.print(mas[i]);\n        }\n        \n        if(isEd)\n            out.print(\" 2\");\n        \n        out.flush();\n    }\n\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class CodeForce {\n    \n    private void solve() throws IOException {\n        final int N = nextInt();\n        int []A = new int[N];\n        for(int i = 0; i < N; i++) A[i] = nextInt();\n        Arrays.sort(A);\n        if(A[N-1] == 1) A[N-1] = 2;\n        else            A[N-1] = 1;\n        Arrays.sort(A);\n        for(int i = 0; i < N; i++)\n            System.out.print(A[i] + \" \");\n    }\n    \n    public static void main(String[] args) {\n        new CodeForce().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(new FileOutputStream(new File(\"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 nextLine() throws IOException {\n        return reader.readLine();\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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n\n    public static void main(String... args) {\n        Scanner sc = new Scanner(System.in);\n        \n        int n = sc.nextInt();\n        sc.nextLine();\n        int[] x = new int[n];\n        \n        int max=0, pos=-1;\n        for(int i=0; i<n; i++) {\n            x[i]=sc.nextInt();\n            if (max<x[i]) {\n                max=x[i];\n                pos=i;\n            }\n        }\n        x[pos] = (max==1) ? 2 : 1;\n        \n        Arrays.sort(x);\n\n        for(int i=0; i<n; i++) \n            System.out.print(x[i]+\" \");\n    }\n    \n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskA {\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer stok;\n\n\tString nextToken() throws IOException {\n\t\twhile (stok == null || !stok.hasMoreTokens()) {\n\t\t\tString s = br.readLine();\n\t\t\tif (s == null) {\n\t\t\t\treturn \"-1\";\n\t\t\t}\n\t\t\tstok = new StringTokenizer(s);\n\t\t}\n\t\treturn stok.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() throws IOException {\n\t\treturn (char) (br.read());\n\t}\n\n\tString nextLine() throws IOException {\n\t\treturn br.readLine();\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\ta[n - 1] = a[n - 1] == 1 ? 2 : 1;\n\t\tArrays.sort(a);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tout.print(a[i]);\n\t\t\tout.print(' ');\n\t\t}\n\t}\n\n\tvoid run() throws IOException {\n\t\t// br = new BufferedReader(new FileReader(\"taska.in\"));\n\t\t// out = new PrintWriter(\"taska.out\");\n\t\t// br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t// out = new PrintWriter(\"output.txt\");\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tbr.close();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// Locale.setDefault(Locale.US);\n\t\tnew TaskA().run();\n\t}\n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.prefs.NodeChangeEvent;\nimport java.math.*;\n\npublic class Main implements Runnable {\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\tprivate Random rnd;\n\t\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\t\n\t\tint[] a = new int[n];\n\t\tint max = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tif(a[i] > a[max]) max = i;\n\t\t}\n\t\t\n\t\tint value = 1;\n\t\t\n\t\tif(a[max] == 1) value = 2;\n\t\t\n\t\ta[max] = value;\n\t\t\n\t\tArrays.sort(a);\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tout.print(a[i]);\n\t\t\tout.print(' ');\n\t\t}\n\t}\n\t\t\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t} \n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tin = new BufferedReader(new FileReader(\"INPUT.TXT\"));\n\t\t\t\tout = new PrintWriter(new FileWriter(\"OUTPUT.TXT\"));\n\t\t\t} catch(FileNotFoundException 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\t\n\t\t\tst = null;\n\t\t\trnd = new Random();\n\t\t\t\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t} catch(IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\t\n\t}\n\t\n\tprivate String nextToken() throws IOException, NullPointerException {\n\t\twhile(st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.math.*;\npublic class codeforces {\n\t public static void main(String[] args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint[] data=new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tdata[i]=sc.nextInt();\n\t\tArrays.sort(data);\n\t\tif(data[n-1]!=1)\n\t\t\tdata[n-1]=1;\n\t\telse\n\t\t\tdata[n-1]=2;\n\t\tArrays.sort(data);\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tSystem.out.print(data[i]);\n\t\t\tif(i!=n-1)\n\t\t\t\tSystem.out.print(\" \");\n\t\t}\n\t\t\t\n\t\t\n\t\treturn;\n\t}\n\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A {\n\tstatic int [] reverse = new int [257];\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 [n];\n\t\tfor (int i = 0; i<A.length; ++i) A[i] = sc.nextInt();\n\t\tArrays.sort(A);\n\t\tif (n == 1) {\n\t\t\tSystem.out.println( (A[0] == 1) ? \"2\" : \"1\");\n\t\t\treturn;\n\t\t} else if (A[0] == A[A.length-1] && A[0] == 1) {\n\t\t\tSystem.out.print(\"1\");\n\t\t\tfor (int i = 1; i<n-1; ++i) System.out.print(\" \" + A[i]);\n\t\t\tSystem.out.println(\" 2\");\n\t\t\treturn;\n\t\t} else if (A[0] == A[A.length-1]) {\n\t\t\tSystem.out.print(\"1\");\n\t\t\tfor (int i = 1; i<n; ++i) System.out.print(\" \" + A[i]);\n\t\t\tSystem.out.println();\n\t\t\treturn;\n\t\t} \n\t\t\n\t\tfor (int i = 0; i<A.length; ++i) {\n\t\t\tint prev = (i == 0) ? Integer.MAX_VALUE : A[i-1];\n\t\t\tint next = (i == A.length-1) ? Integer.MAX_VALUE : A[i+1];\n\t\t\tint ans = Math.min(prev, Math.min(next, A[i]));\n\t\t\tif (i == 0) ans = 1;\n\t\t\t\n\t\t\tSystem.out.print((i == 0) ? \"\" + ans : \" \" + ans);\n\t\t}\n\t\tSystem.out.println();\n\t\t\n\t\t\n\t}\n\t\n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class C {\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        String[] S = in.readLine().split(\" \");\n        int[] A = new int[n];\n        boolean allOnes = true;\n        for (int i = 0; i < n; i++) {\n            A[i] = Integer.parseInt(S[i]);\n            allOnes &= A[i] == 1;\n        }\n        Arrays.sort(A);\n        if (A[A.length - 1] > 1)\n            A[A.length - 1] = 1;\n        else\n            A[A.length - 1] = 2;\n        Arrays.sort(A);\n        for (int i = 0; i < A.length; i++)\n            System.out.print(A[i] + \" \");\n        System.out.println();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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\npublic class C implements Runnable {\n\n\tprivate void Solution() throws IOException {\n\t\tint n = nextInt(), max = 0, maxi = 0;\n\t\tArrayList<Integer> mas = new ArrayList<Integer>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint num = nextInt();\n\t\t\tif (num > max) {\n\t\t\t\tmax = num;\n\t\t\t\tmaxi = i;\n\t\t\t}\n\t\t\tmas.add(num);\n\t\t}\n\t\tmas.remove(maxi);\n\t\tmas.add(max == 1 ? 2 : 1);\n\t\tCollections.shuffle(mas);\n\t\tCollections.sort(mas);\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tSystem.out.print(mas.get(i) + \" \");\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew C().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}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main\n{\n    BufferedReader reader;\n    FastScanner sc;\n    \n    void solve() throws Exception\n    {\n        int n = sc.nextInt();\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = sc.nextInt();\n        }\n        Arrays.sort(arr);\n        if (arr[n - 1] == 1)\n            arr[n - 1] = 2;\n        else\n            arr[n - 1] = 1;\n        Arrays.sort(arr);\n        for (int i = 0; i < n; i++)\n        {\n            System.out.print(arr[i] + \" \");\n        }\n        System.out.println();\n    }\n        \n    public static void main(String[] args) throws Exception\n    {\n        new Main().solve();\n    }\n    \n    Main() throws Exception\n    {\n        if (System.getProperty(\"ONLINE_JUDGE\") == null)\n        {\n            //System.setIn(new FileInputStream(\"input.txt\"));\n            //System.setOut(new PrintStream(\"output.txt\"));\n        }\n        \n        reader = new BufferedReader(new InputStreamReader(System.in));\n        sc = new FastScanner(reader);\n    }\n}\n\nclass FastScanner\n{\n    BufferedReader reader;\n    StringTokenizer strTok;\n    \n    public FastScanner(BufferedReader reader)\n    {\n        this.reader = reader;\n    }\n    \n    public String nextToken() throws IOException\n    {\n        if (strTok == null || !strTok.hasMoreTokens())\n        {\n            strTok = new StringTokenizer(reader.readLine());\n        }\n        return strTok.nextToken();\n    }\n    \n    public int nextInt() throws IOException\n    {\n        return Integer.parseInt(nextToken());\n    }\n    \n    public long nextLong() throws IOException\n    {\n        return Long.parseLong(nextToken());\n    }\n    \n    public double nextDouble() throws IOException\n    {\n        return Double.parseDouble(nextToken());\n    }\n    \n    public BigInteger nextBigInteger() throws IOException\n    {\n        return new BigInteger(nextToken());\n    }\n    \n    public BigDecimal nextBigDecimal() throws IOException\n    {\n        return new BigDecimal(nextToken());\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer st = null;\n\n\tprivate void solution() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] mas = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tmas[i] = nextInt();\n\t\t}\n\n\t\tArrays.sort(mas);\n\n\t\tif (mas[n - 1] == 1) {\n\t\t\tmas[n - 1] = 2;\n\t\t} else {\n\t\t\tmas[n - 1] = 1;\n\t\t}\n\t\tArrays.sort(mas);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tSystem.out.print(mas[i] + \" \");\n\t\t}\n\n\t}\n\n\tString nextToken() throws IOException {\n\t\tif (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(bf.readLine());\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\n\tpublic static void main(String args[]) throws IOException {\n\t\tnew C().solution();\n\t}\n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.regex.*;\nimport static java.lang.Math.*;\npublic class A {\n\n    public A() throws Exception {\n        int n = in.nextInt();\n        int[] arr = new int[n];\n        for (int i=0;i<n;i++) \n            arr[i] = in.nextInt();\n\n        if (n==1&&arr[0]==1) {\n            System.out.println(2); \n            return;\n        } \n\n        Arrays.sort(arr);\n        if (arr[n-1]==1)\n            arr[n-2] = 2;\n        buf.append(1);\n        for (int i=0;i<n-1;i++) \n            buf.append(' ').append(arr[i]);\n        buf.append('\\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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author 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\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint size = in.readInt();\n\t\tint[] array = IOUtils.readIntArray(in, size);\n\t\tArrays.sort(array);\n\t\tif (array[size - 1] == 1)\n\t\t\tarray[size - 1] = 2;\n\t\telse\n\t\t\tarray[size - 1] = 1;\n\t\tArrays.sort(array);\n\t\tout.printLine(Array.wrap(array).toArray());\n\t}\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic static boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\t}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(outputStream);\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\nclass IOUtils {\n\n\tpublic static 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\nabstract class Array<T> extends AbstractList<T> {\n\n\tpublic static List<Integer> wrap(int...array) {\n\t\treturn new IntArray(array);\n\t}\n\n\tprotected static class IntArray extends Array<Integer> {\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\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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\n\tpublic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint a [] = new int [n];\n\t\tfor (int i = 0 ;i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tif (n == 1) {\n\t\t\tif (a[0] == 1) {\n\t\t\t\tout.print(2);\n\t\t\t} else {\n\t\t\t\tout.print(1);\n\t\t\t}\n\t\t} else {\n\t\t\tout.print(1);\n\t\t\tfor (int i = 1; i < n; i++) {\n\t\t\t\tif (i == n-1 && a[i] == 1) {\n\t\t\t\t\tout.print(\" \"+2);\n\t\t\t\t} else {\n\t\t\t\t\tout.print(\" \"+a[i-1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\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\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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n = in.nextInt();\n        int[] a = new int[n];\n        boolean has_more_than_one = false;\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n            if (a[i] > 1)\n                has_more_than_one = true;\n        }\n\n        Arrays.sort(a);\n\n        if (n == 1) {\n            if (a[0] == 1)\n                out.print(2);\n            else\n                out.print(1);\n        } else {\n            out.print(1 + \" \");\n            for (int i = 1; i < n; i++) {\n                if (has_more_than_one || i < n - 1)\n                    out.print(a[i - 1] + \" \");\n                else\n                    out.println(2);\n            }\n        }\n\n        out.close();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n    private MyScanner in;\n    private PrintWriter out;\n\n    private void solve() {\n        int n = in.nextInt();\n        int[] a = new int[n];\n        int max = -1, maxp = -1;\n        for (int i = 0; i < n; ++i) {\n            a[i] = in.nextInt();\n            if (a[i] > max) {\n                max = a[i];\n                maxp = i;\n            }\n        }\n        if (max == 1) {\n            for (int i = 0; i < n - 1; ++i) {\n                out.print(1 + \" \");\n            }\n            out.println(2);\n            return;\n        }\n        a[maxp] = 1;\n        Arrays.sort(a);\n        for (int i = 0; i < n; ++i) {\n            out.print(a[i] + \" \");\n        }\n        out.println();\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                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}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A implements Runnable{\n    \n    \n    public void run() {\n        int n = nextInt();\n        int[] arr = new int[n];\n        boolean allOne = true;\n        for (int i = 0; i < n; ++i) {\n            arr[i] = nextInt();\n            if (arr[i] != 1) {\n                allOne = false;\n            }\n        }\n        Arrays.sort(arr);\n        if (!allOne) {\n            out.print(\"1 \");\n        }\n        for (int i = 0; i < n-1; ++i) {\n            out.print(arr[i] + \" \");\n        }\n        if (allOne) {\n            out.print(\"2\");\n        }\n        out.println();\n        out.flush();\n    }\n    \n    private static BufferedReader br = null;\n    private static PrintWriter out = null;\n    private static StringTokenizer stk = null;\n    \n    public static void main(String[] args) {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        (new Thread(new A())).start();\n    }\n    \n    private void loadLine() {\n        try {\n            stk = new StringTokenizer(br.readLine());\n        }\n        catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    private String nextLine() {\n        try {\n            return br.readLine();\n        }\n        catch (IOException e) {\n            e.printStackTrace();\n        }\n        return null;\n    }\n    \n    private Integer nextInt() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Integer.parseInt(stk.nextToken());\n    }\n    \n    private Long nextLong() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Long.parseLong(stk.nextToken());\n    }\n    \n    private String nextWord() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return (stk.nextToken());\n    }\n    \n    private Double nextDouble() {\n        while (stk==null||!stk.hasMoreTokens()) loadLine();\n        return Double.parseDouble(stk.nextToken());\n    }\n    \n    \n}\n\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class AAA {\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 < n; i++)\n            a[i] = in.nextInt();\n        int max = a[0];\n        int ind = 0;\n        for (int k = 1; k < n; k++) {\n            if (a[k] > max) {\n                max = a[k];\n                ind = k;\n            }\n        }\n        if (max != 1) {\n            a[ind] = 1;\n            Arrays.sort(a);\n            for (int i = 0; i < a.length - 1; i++)\n                System.out.print(a[i] + \" \");\n            System.out.println(a[a.length - 1]);\n        } else {\n            a[0] = 2;\n            Arrays.sort(a);\n            for (int i = 0; i < a.length - 1; i++)\n                System.out.print(a[i] + \" \");\n            System.out.println(a[a.length - 1]);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A135 {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextInt();\n        }\n        Arrays.sort(arr);\n        int[] ans = new int[n];\n        \n        if (arr[n-1] == 1) {\n            for (int i = 0 ;i < n; i++) {\n                ans[i] = arr[i];\n            }\n            ans[n-1] = 2;\n        } else {\n            ans[0] = 1;\n            for (int i = 1; i < n; i++) {\n                ans[i] = arr[i-1];\n            }\n        }\n        StringBuffer buf = new StringBuffer();\n        for (int i = 0; i < n; i++) {\n            buf.append(ans[i]);\n            if (i != n-1) buf.append(' ');\n        }\n        System.out.print(buf.toString());\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n        \n        int n = Integer.parseInt(r.readLine());\n        \n        String[] line = r.readLine().split(\"[ ]+\");\n        \n        int[] a = new int[n];\n        for(int i = 0; i < n; i++)\n            a[i] = Integer.parseInt(line[i]);\n        \n        \n        Arrays.sort(a);\n        \n        boolean found = false;\n        for(int i = 0; i < n && !found; i++)\n            if(a[i] != 1)found = true;\n        \n        \n        if(found){\n            System.out.println(1);\n            for(int i = 1; i < n; i++)\n                System.out.println(a[i-1]);\n        }else{\n            for(int i = 0; i < n-1; i++)\n                System.out.println(1);\n            System.out.println(2);\n        }\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n    BufferedReader in;\n    StringTokenizer st;\n    PrintWriter out;\n\n    String next() throws IOException {\n        while (st == null || !st.hasMoreTokens())\n            st = new StringTokenizer(in.readLine());\n        return st.nextToken();\n    }\n\n    int nextInt() throws Exception {\n        return Integer.parseInt(next());\n    }\n\n    long nextLong() throws Exception {\n        return Long.parseLong(next());\n    }\n\n    double nextDouble() throws Exception {\n        return Double.parseDouble(next());\n    }\n\n    void solve() throws Exception {\n        // int min = 1;\n        // int max = 1000000000;\n        int n = nextInt();\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = nextInt();\n\n        Arrays.sort(a);\n\n        if (a[n - 1] == 1) {\n            for (int i = 1; i < n; i++)\n                out.print(\"1 \");\n            out.print(2);\n            return;\n        }\n\n        // a[0]=max;\n\n        Arrays.sort(a);\n        out.print(1);\n        for (int i = 1; i < n; i++)\n            out.print(\" \" + a[i-1]);\n\n    }\n\n    void run() {\n        try {\n            Locale.setDefault(Locale.US);\n            boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            Reader reader = oj ? new InputStreamReader(System.in)\n                    : new FileReader(\"input.txt\");\n            Writer writer = oj ? new OutputStreamWriter(System.out)\n                    : new FileWriter(\"output.txt\");\n            in = new BufferedReader(reader);\n            out = new PrintWriter(writer);\n\n            solve();\n            out.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n\n    }\n\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Beta97B {\n\n    static Scanner in;\n    static StreamTokenizer st;\n    static int n;\n    static int[] a;\n    static int max = 1;\n\n    public static void main(String[] args) throws IOException {\n        // in = new Scanner(System.in);\n        st = new StreamTokenizer(new InputStreamReader(System.in));\n        n = nextInt();\n        a = new int[n];\n        int ind = 0;\n        for (int i = 0; i < n; ++i) {\n            a[i] = nextInt();\n            if (a[i] > max) {\n                max = a[i];\n                ind = i;\n            }\n        }\n        if (max == 1) {\n            a[0] = 2;\n        } else {\n            a[ind] = 1;\n        }\n        Arrays.sort(a);\n        for (int i = 0; i < n; ++i)\n            System.out.print(a[i] + \" \");\n    }\n\n    private static int nextInt() throws IOException {\n        st.nextToken();\n        return (int) st.nval;\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "//package round97;\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 A {\n\n\tstatic BufferedReader bf = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic String nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString s = bf.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\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 String nextStr() throws IOException {\n\t\treturn nextToken();\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = nextInt();\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\t\n\t\tfor (int q = 0; q < n; q++) {\n\t\t\tif (a[q] != 1) {\n\t\t\t\tout.print(\"1\");\n\t\t\t\tfor (int i = 1; i < n; i++) {\n\t\t\t\t\tout.print(\" \" + a[i - 1]);\n\t\t\t\t}\n\t\t\t\tout.flush();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tout.print(\"1 \");\n\t\t}\n\t\tout.println(\"2\");\n\t\tout.flush();\n\t\t\n\t\t\n\t}\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\n    void run(){\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[] a = new int[n];\n        boolean dif = false;\n        for(int i=0;i<n;i++)a[i]=sc.nextInt();\n        Arrays.sort(a);\n        if(n==1){\n            System.out.println(a[0]==1?2:1);return;\n        }\n        int[] m = new int[n];\n        for(int i=1;i<n;i++)if(a[i]!=a[i-1])dif=true;\n        m[0] = 1;\n        for(int i=1;i<n;i++)m[i]=a[i-1];\n        if(!dif&&a[0]==1)m[n-1]++;\n        \n        for(int i=0;i<n;i++)System.out.print(m[i]+(i==n-1?\"\\n\":\" \"));\n    }\n    \n    public static void main(String[] args) {\n        new A().run();\n    }\n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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.Scanner;\n\n\npublic class ProblemA {\n\n\tprivate void solve() throws IOException {\n\t\tScanner stdin = new Scanner(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        \n        int n = Integer.valueOf(stdin.nextInt());\n        int[] p = new int[n];\n        for (int i = 0; i < n; i++) {\n        \tp[i] = stdin.nextInt();\n        }\n        \n        Arrays.sort(p);\n        if (p[n-1] == 1) {\n        \tp[n-1] = 2;\n        } else {\n        \tp[n-1] = 1;\n        \tout.print(p[n-1] + \" \");\n        \tn--;\n        }\n        \n        for (int i = 0; i < n; i++) {\n        \tout.print(p[i] + \" \");\n        }\n        \n        \n        out.flush();\n        out.close();\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tProblemA solver = new ProblemA();\n        solver.solve();\n\t}\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class A{\n    public static void main(String[] args) throws Exception{\n        new A().run();\n    }\n\n    void run() throws Exception{\n        //Scanner sc = new Scanner(System.in);\n        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(sc.readLine());\n        ArrayList<Integer> a = new ArrayList<Integer>();\n        //a.add(1);\n        StringTokenizer st = new StringTokenizer(sc.readLine(), \" \");\n        boolean allOne = true;\n        for(int i = 0; i < n; i++){\n            int val = Integer.parseInt(st.nextToken());\n            if(val!=1)allOne = false;\n            a.add(val);\n        }\n        if(allOne){a.remove(n-1); a.add(2);}\n        else a.add(1);\n        Collections.sort(a);\n        System.out.print(a.get(0));\n        for(int i = 1; i < n; i++)\n            System.out.print(\" \" + a.get(i));\n        System.out.println();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tfinal String filename = new String(\"A\").toLowerCase();\n\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tint m = -1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tif (m == -1 || a[i] > a[m]) {\n\t\t\t\tm = i;\n\t\t\t}\n\t\t}\n\t\tif (a[m] == 1)\n\t\t\ta[m] = 2;\n\t\telse\n\t\t\ta[m] = 1;\n\t\tArrays.sort(a);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tout.print(a[i] + \" \");\n\t\t}\n\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\n\npublic class ProblemA {\n\n    private final BufferedReader in;\n    private final PrintStream out;\n    private StringTokenizer tok = new StringTokenizer(\"\");\n    private String nextLine = null;\n\n    public static void main(String[] args) throws Exception {\n        new ProblemA();\n    }\n\n    private ProblemA() throws Exception {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = System.out;\n        start();\n        end();\n    }\n\n    private int nextInt() {\n        return Integer.parseInt(nextWord());\n    }\n\n    private String nextWord() {\n        if (tok.hasMoreTokens()) {\n            return tok.nextToken();\n        } else {\n            while (!tok.hasMoreTokens()) {\n                try {\n                    nextLine = in.readLine();\n                    if (nextLine == null) {\n                        return null;\n                    } else {\n                        tok = new StringTokenizer(nextLine);\n                    }\n                } catch (IOException ex) {\n                    Logger.getLogger(ProblemA.class.getName()).log(Level.SEVERE, null, ex);\n                }\n            }\n            return tok.nextToken();\n        }\n    }\n\n    private void start() {\n        int n = nextInt();\n        int[] a = new int[n];\n        boolean allOne = true;\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n            if (a[i] != 1) {\n                allOne = false;\n            }\n        }\n        Arrays.sort(a);\n        int[] res = new int[n];\n        res[0] = 1;\n        for (int i = 1; i < n; i++) {\n            res[i] = a[i - 1];\n        }\n        if (allOne) {\n            for (int i = 0; i < n - 1; i++) {\n                out.print(a[i] + \" \");\n            }\n            out.print(2);\n        } else {\n            for (int i = 0; i < n; i++) {\n                out.print(res[i] + \" \");\n            }\n        }\n    }\n\n    private void end() {\n        out.close();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\n  public static void main(String args[]) {\n    (new Main()).solve();\n  }\n\n  void solve() {\n\n    Scanner cin = new Scanner(System.in);\n\n    while( cin.hasNextInt() ) {\n\n      int n = cin.nextInt();\n      int arr[] = new int[n];\n      for(int i=0; i<n; ++i) {\n        arr[i] = cin.nextInt();\n      }\n\n      Arrays.sort(arr);\n\n      int ret[] = new int[n];\n      ret[0] = 1;\n      for(int i=0; i<n-1; ++i) { ret[i + 1] = arr[i]; }\n      if( arr[n - 1] == 1 ) { ret[n - 1] = 2; }\n\n      String glue = \"\";\n      for(int i=0; i<n; ++i) {\n        System.out.print(glue + ret[i]);\n        glue = \" \";\n      }\n\n      System.out.println();\n\n    }\n\n  }\n\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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 n = nextInt();\n    \tint[] arr = new int[n];\n    \tfor (int i = 0; i < n;i++) {\n    \t\tarr[i] = nextInt();\n    \t}\n    \tArrays.sort(arr);\n    \tif (arr[n-1] != 1) arr[n-1] = 1;\n    \telse arr[n-1] = 2;\n    \tArrays.sort(arr);\n    \tfor (int i = 0; i < n; i++) {\n    \t\tout.print(arr[i]+\" \");\n    \t}\n    \tout.println();\n    \tout.flush();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "//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 A {\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 = new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\ta[i] = ni();\n\t\t}\n\t\tArrays.sort(a);\n\t\tif(a[n-1] > 1){\n\t\t\ta[n-1] = 1;\n\t\t\tArrays.sort(a);\n\t\t}else{\n\t\t\ta[n-1] = 2;\n\t\t}\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(i > 0)out.print(\" \");\n\t\t\tout.print(a[i]);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew A().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", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\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 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 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        \n       \n        void solve() throws IOException{\n        \tint n = readInt();\n        \tint[] a = new int[n];\n        \tfor(int i = 0; i < n; i++){\n        \t\ta[i] = readInt();\n        \t}\n        \tboolean c = true;\n        \tfor(int i = 0; i < n; i++){\n        \t\tif(a[i] != 1){\n        \t\t\tc = false;\n        \t\t\tbreak;\n        \t\t}\n        \t}\n        \tif(c){\n        \t\tfor(int i = 0; i < n-1; i++){\n        \t\t\tout.print(a[i] + \" \");\n        \t\t}\n        \t\tout.println(2);\n        \t\treturn;\n        \t}\n        \tUtils.mergeSort(a);\n        \tout.print(1 + \" \");\n        \tfor(int i = 1; i < n; i++){\n        \t\tout.print(a[i-1] + \" \");\n        \t}\n        }\n        \n        int[] zFunction(char[] s){\n        \tint[] z = new int[s.length];\n        \tz[0] = 0;\n        \tfor (int i=1, l=0, r=0; i<s.length; ++i) {\n        \t\tif (i <= r)\n        \t\t\tz[i] = min (r-i+1, z[i-l]);\n        \t\twhile (i+z[i] < s.length && s[z[i]] == s[i+z[i]])\n        \t\t\t++z[i];\n        \t\tif (i+z[i]-1 > r){\n        \t\t\tl = i; \n        \t\t\tr = i+z[i]-1;\n        \t\t}\n        \t}\t\n        \treturn z;\n        }\n        \n        int[] prefixFunction(char[] s){\n        \tint[] pr = new int[s.length];\n        \tfor (int i = 1; i< s.length; ++i) {\n        \t\tint j = pr[i-1];\n        \t\twhile (j > 0 && s[i] != s[j])\n        \t\t\tj = pr[j-1];\n        \t\tif (s[i] == s[j])  ++j;\n        \t\tpr[i] = j;\n        \t}\n        \treturn pr;\n        }\n        \n        int ModExp(int a, int n, int mod){\n        \tint res = 1;\n        \twhile (n!=0)\n        \t\tif ((n & 1) != 0) {\n        \t\t\tres = (res*a)%mod;\n        \t\t\t--n;\n        \t\t}\n        \t\telse {\n        \t\t\ta = (a*a)%mod;\n        \t\t\tn >>= 1;\n        \t\t}\n        \treturn res;\n        }\n        \n        \n        static class Utils {\n \n                private Utils() {}\n \n                public static void mergeSort(int[] a) {\n                        mergeSort(a, 0, a.length - 1);\n                }\n \n                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n                        final int MAGIC_VALUE = 50;\n                        if (leftIndex < rightIndex) {\n                                if (rightIndex - leftIndex <= MAGIC_VALUE) {\n                                        insertionSort(a, leftIndex, rightIndex);\n                                } else {\n                                        int middleIndex = (leftIndex + rightIndex) / 2;\n                                        mergeSort(a, leftIndex, middleIndex);\n                                        mergeSort(a, middleIndex + 1, rightIndex);\n                                        merge(a, leftIndex, middleIndex, rightIndex);\n                                }\n                        }\n                }\n \n                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {\n                        int length1 = middleIndex - leftIndex + 1;\n                        int length2 = rightIndex - middleIndex;\n                        int[] leftArray = new int[length1];\n                        int[] rightArray = new int[length2];\n                        System.arraycopy(a, leftIndex, leftArray, 0, length1);\n                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n                                if (i == length1) {\n                                        a[k] = rightArray[j++];\n                                } else if (j == length2) {\n                                        a[k] = leftArray[i++];\n                                } else {\n                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];\n                                }\n                        }\n                }\n \n                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n                        for (int i = leftIndex + 1; i <= rightIndex; i++) {\n                                int current = a[i];\n                                int j = i - 1;\n                                while (j >= leftIndex && a[j] > current) {\n                                        a[j + 1] = a[j];\n                                        j--;\n                                }\n                                a[j + 1] = current;\n                        }\n                } \n        }\n        \n       \n        \n        boolean isPrime(int a){\n        \tfor(int i = 2; i <= sqrt(a); i++)\n        \t\tif(a % i == 0) return false;\n        \treturn true;\n        }\n        \n        static double distance(long x1, long y1, long x2, long y2){\n        \treturn Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));\n        }\n        \n        static long gcd(long a, long b){\n        \tif(min(a,b) == 0) return max(a,b);\n        \treturn gcd(max(a, b) % min(a,b), min(a,b));\n        }\n        \n        static long lcm(long a, long b){\n        \treturn a * b /gcd(a, b);\n        }\n}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A {\n    static final Scanner sc = new Scanner(System.in);\n    \n    void run() {\n        int n = sc.nextInt();\n        int[] xs = new int[n];\n        for(int i = 0; i < n; i++) {\n            xs[i] = sc.nextInt();\n        }\n        Arrays.sort(xs);\n        xs[n-1] = xs[n-1] == 1 ? 2 : 1;\n        Arrays.sort(xs);\n        for(int i = 0; i < n; i++)\n            System.out.print(xs[i] + \" \");\n    }\n    \n    public static void main(String[] args) {\n        new A().run();\n    }\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class Replacement {\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));\t\n\t\tString s=r.readLine();\n\t\tint n=new Integer(s);\n\t\tint[]arr=new int[n];\n\t\tString[]sp=r.readLine().split(\"[ ]+\");\n\t\tfor (int i = 0; i < sp.length; i++) {\n\t\t\tarr[i]=new Integer(sp[i]);\n\t\t}\n\t\tArrays.sort(arr);\n\t\tif(arr[arr.length-1]==1){\n\t\t\tarr[arr.length-1]=2;\n\t\t\tArrays.sort(arr);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif(i==n-1){\n\t\t\t\t\tSystem.out.println(arr[i]);\n\t\t\t\t}else\n\t\t\t\tSystem.out.print(arr[i]+\" \");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tarr[arr.length-1]=1;\n\t\tArrays.sort(arr);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif(i==n-1){\n\t\t\t\tSystem.out.println(arr[i]);\n\t\t\t}else\n\t\t\tSystem.out.print(arr[i]+\" \");\n\t\t}\n\t}\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "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[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = iread();\n\t\tArrays.sort(a);\n\t\tboolean test = true;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i] != 1)\n\t\t\t\ttest = false;\n\t\t\tint min = (i == 0) ? 1 : a[i - 1];\n\t\t\tif (test && i == n - 1)\n\t\t\t\tout.write((min + 1) + \"\");\n\t\t\telse\n\t\t\t\tout.write(min + \"\");\n\t\t\tif (i == n - 1)\n\t\t\t\tout.write(\"\\n\");\n\t\t\telse\n\t\t\t\tout.write(\" \");\n\t\t}\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}", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int[] a = new int[n];\n\n        boolean onlyOnes = true;\n\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n            if (a[i] != 1)\n                onlyOnes = false;\n        }\n\n        Arrays.sort(a);\n        if (onlyOnes) {\n            for (int i = 0; i < n - 1; i++)\n                out.print(\"1 \");\n            out.print(2);\n        } else {\n            out.print(\"1 \");\n            for (int i = 0; i < n - 1; i++)\n                out.print(a[i] + \" \");\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 A().inp();\n    }\n\n    String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return \"0\";\n            }\n        }\n        return st.nextToken();\n    }\n\n    String nextString() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return \"0\";\n            }\n        }\n        return st.nextToken(\"\\n\");\n    }\n\n    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/*\n * Raudel Ravelo Suarez\n * Problem: \n */\n\npublic class C \n{\n\tScanner sc;\n\tBufferedReader in;\n\tPrintStream out;\n\tStringTokenizer tok;\n\t\n\tpublic C() throws NumberFormatException, IOException\n\t{\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\t//in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\tout = System.out;\n\t\trun();\n\t}\n\tvoid run() throws NumberFormatException, IOException\n\t{\n\t\t//Add your code here\n\t\tint[] array;\n\t\tint n = nextInt();\n\t\tarray = new int[n];\n\t\tint max = 0;\n\t\tint pos = 0;\n\t\tfor(int i = 0; i <n; i++)\n\t\t{\n\t\t\tint l = nextInt();\n\t\t\tif(l > max)\n\t\t\t{\n\t\t\t\tpos = i;\n\t\t\t\tmax = l;\n\t\t\t}\n\t\t\tarray[i] = l;\n\t\t}\n\t\tif(max == 1)array[pos] = 2;\n\t\telse array [pos] = 1;\n\t\tArrays.sort(array);\n\t\tout.print(array[0]);\n\t\tfor(int i = 1; i < n; i++)\n\t\t\tout.print(\" \" + array[i]);\n\t\tout.println();\n\t}\n\tpublic static void main(String[] args) throws NumberFormatException, IOException \n\t{\n\t\tnew C();\n\t}\n\tString nextToken() throws IOException\n\t{\n\t\tif(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());\n\t\treturn tok.nextToken();\n\t}\n\tint nextInt() throws NumberFormatException, IOException\n\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws NumberFormatException, IOException\n\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws NumberFormatException, IOException\n\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "complexity": "nlogn", "problem": "135_A. Replacement", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class c {\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tint n = in.nextInt(), m = in.nextInt();\n\t\tlong bounty = in.nextInt(), increase = in.nextInt();\n\t\tint damage = in.nextInt();\n\t\tint[] mh = new int[n];\n\t\tint[] sh = new int[n];\n\t\tint[] reg = new int[n];\n\t\tlong countKilled = 0;\n\t\tArrayList<Event> es = new ArrayList<>();\n\t\tEvent[] regen = new Event[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tmh[i] = in.nextInt();\n\t\t\tsh[i] = in.nextInt();\n\t\t\treg[i] = in.nextInt();\n\t\t\tif(sh[i] <= damage)\n\t\t\t\tcountKilled++;\n\t\t\tif(reg[i] > 0) {\n\t\t\t\tint time = (damage+1 - sh[i]+reg[i]-1)/reg[i];\n\t\t\t\tif(time > 0 && mh[i] >= damage+1) {\n\t\t\t\t\tEvent e2 = new Event(time, i, damage+1);\n\t\t\t\t\tregen[i] = e2;\n\t\t\t\t\tes.add(e2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<m;i++) {\n\t\t\tEvent e = new Event(in.nextInt(), in.nextInt()-1, in.nextInt());\n\t\t\tes.add(e);\n\t\t\tif(reg[e.e] > 0) {\n\t\t\t\tint time = (damage+1 - e.h+reg[e.e]-1)/reg[e.e];\n\t\t\t\tif(time > 0 && mh[e.e] >= damage+1) {\n\t\t\t\t\tEvent e2 = new Event(e.t + time, e.e, damage+1);\n\t\t\t\t\te.regen = e2;\n\t\t\t\t\tes.add(e2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tCollections.sort(es, (a,b) -> a.t-b.t);\n\t\tlong ans = countKilled*bounty;\n\t\tint lastTime = 0;\n\t\tfor(Event e : es) {\n\t\t\tif(e.t == -1) continue;\n\t\t\tif(regen[e.e] != e && regen[e.e] != null) {\n\t\t\t\tregen[e.e].t = -1;\n\t\t\t\tregen[e.e] = null;\n\t\t\t}\n\t\t\tif(lastTime != e.t) {\n\t\t\t\tans = Math.max(ans, countKilled*(bounty+(e.t-1)*increase));\n\t\t\t}\n\t\t\tif(sh[e.e] <= damage)\n\t\t\t\tcountKilled--;\n\t\t\tsh[e.e] = e.h;\n\t\t\tif(sh[e.e] <= damage)\n\t\t\t\tcountKilled++;\n\t\t\tif(e.regen != null) {\n\t\t\t\tregen[e.e] = e.regen;\n\t\t\t}\n\t\t\tlastTime = e.t;\n\t\t}\n\t\tif(countKilled != 0) {\n\t\t\tif(increase > 0)\n\t\t\t\tans = -1;\n\t\t\telse\n\t\t\t\tans = Math.max(ans, countKilled*bounty);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic class Event {\n\t\tint t;\n\t\tint e;\n\t\tint h;\n\t\tEvent regen;\n\t\tpublic Event(int tt, int ee, int hh) {\n\t\t\tt = tt;\n\t\t\te = ee;\n\t\t\th = hh;\n\t\t}\n\t}\n\tstatic class FastScanner {\n\t    BufferedReader br;\n\t    StringTokenizer st;\n\t    public FastScanner(InputStream i) {\n\t        br = new BufferedReader(new InputStreamReader(i));\n\t        st = new StringTokenizer(\"\");\n\t    }\n\t    public String next() throws IOException {\n\t        if(st.hasMoreTokens())\n\t            return st.nextToken();\n\t        else\n\t            st = new StringTokenizer(br.readLine());\n\t        return next();\n\t    }\n\t    public int nextInt() throws IOException {\n\t        return Integer.parseInt(next());\n\t    }\n\t    public long nextLong() throws IOException {\n\t        return Long.parseLong(next());\n\t    }\n\t    public double nextDouble() throws IOException {\n\t        return Double.parseDouble(next());\n\t    }\n\t}\n}\n", "complexity": "nlogn", "problem": "912_C. Perun, Ult!", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.reflect.Array;\n\n\t\tpublic class codeforces\n\t\t{\t\n\t\t\tpublic static void main(String[] args)\n\t\t\t{\n\t\t\t\tInputReader in = new InputReader(System.in);\n\t\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\n\t\t\t\tint n = in.nextInt();\n\t\t\t\tlong U = in.nextLong();\n\t\t\t\tlong[] E = new long[n];\n\t\t\t\tdouble max = -1;\n\t\t\t\t\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t\tE[i] = in.nextLong();\n\t\t\t\t\n\t\t\t\tfor(int k=1;k<n-1;k++)\n\t\t\t\t{\n\t\t\t\t\tint i = k + 1, j = n - 1, mid = 0;\n\t\t\t\t\tdouble T = 0;\n\t\t\t\t\t\n\t\t\t\t\twhile(i < j)\n\t\t\t\t\t{\n\t\t\t\t\t\tmid = (int)Math.ceil((double)(i+j)/2);\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(E[mid] - E[k-1] <= U)\n\t\t\t\t\t\t\ti = mid;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tj = mid - 1;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tj = k;\n\t\t\t\t\tk = i;\n\t\t\t\t\ti = j - 1;\n\t\t\t\t\t\n\t\t\t\t\tT = E[k] - E[j];\n\t\t\t\t\tT /= E[k] - E[i];\n\t\t\t\t\t\n\t\t\t\t\tif(E[k] - E[i] <= U)\n\t\t\t\t\t\tmax = Math.max(max, T);\n\t\t\t\t\t\n\t\t\t\t\tk = j;\n\t\t\t\t}\t\n\t\t\t\t\n\t\t\t\tpw.println(max);\n\t\t\t\t\n\t\t\t\tpw.flush();\n\t\t\t\tpw.close();\n\t\t\t}\n\t\t\t\n\t\t/*\tpublic static void DFS(int sourse)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tvisited[sourse] = true;\n\t\t\t\t\n\t\t\t\tfor(int u : adj[sourse])\n\t\t\t\t{\n\t\t\t\t\tif(!visited[u])\n\t\t\t\t\t{\n\t\t\t\t\t\tDFS(u);\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\tpublic static ArrayList Divisors(long n)\n\t\t\t{\n\t\t\t    ArrayList<Long> div = new ArrayList<>();\n\t\t\t    \n\t\t\t    for (long i=1; i<=Math.sqrt(n); i++)\n\t\t\t    {\n\t\t\t        if (n%i == 0)\n\t\t\t        {\n\t\t\t        \tdiv.add(i);\n\t\t\t                \n\t\t\t            if(n/i != i)\n\t\t\t            \tdiv.add(n/i);\n\t\t\t        }\n\t\t\t    }\n\t\t\t    return div;\n\t\t\t}\n\t\t\n\t\t\tpublic static int BinarySearch(long[] a, long k)\n\t\t\t{\n\t\t\t\tint n = a.length;\n\t\t\t\tint i = 0, j = n-1;\n\t\t\t\tint mid = 0;\n\t\t\t\t\n\t\t\t\tif(k < a[0])\n\t\t\t\t\treturn 0;\n\t\t\t\telse if(k >= a[n-1])\n\t\t\t\t\treturn n;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\twhile(j - i > 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tmid = (i+j)/2;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(k >= a[mid])\n\t\t\t\t\t\t\ti = mid;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tj = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn i+1;\n\t\t\t}\n\t\t\tpublic static long GCD(long a,long b)\n\t\t\t{\n\t\t\t\tif(b==0)\n\t\t\t\t\treturn a;\n\t\t\t\telse\n\t\t\t\t\treturn GCD(b,a%b);\n\t\t\t}\n\t\t\t\n\t\t\tstatic class pair implements Comparable<pair>\n\t\t\t{\n\t\t\t\tInteger x, y;\n\t\t\t\tpair(int x,int y)\n\t\t\t\t{\n\t\t\t\t\tthis.x=x;\n\t\t\t\t\tthis.y=y;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic int compareTo(pair o) {\n\t\t\t\t\tint result = x.compareTo(o.x);\n\t\t\t\t\tif(result==0)\n\t\t\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\t\t\n\t\t\t\t\treturn result;\n\t\t\t\t}  \n\t\t\t\t\n\t\t\t\tpublic String toString()\n\t\t\t\t{\n\t\t\t\t\treturn x+\" \"+y;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic boolean equals(Object o)\n\t\t\t\t{\n\t\t\t\t\tif (o instanceof pair)\n\t\t\t\t    {\n\t\t\t\t\t\tpair p = (pair)o;\n\t\t\t\t\t\treturn p.x - x == 0 && p.y - y == 0 ;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic int hashCode()\n\t\t\t\t{\n\t\t\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tstatic class InputReader \n\t\t\t{\n\t\t\t\t \n\t\t\t\tprivate final InputStream stream;\n\t\t\t\tprivate final byte[] buf = new byte[8192];\n\t\t\t\tprivate int curChar, snumChars;\n\t\t\t\tprivate SpaceCharFilter filter;\n\t\t \n\t\t\t\tpublic InputReader(InputStream stream) \n\t\t\t\t{\n\t\t\t\t\tthis.stream = stream;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic int snext() \n\t\t\t\t{\n\t\t\t\t\tif (snumChars == -1)\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tif (curChar >= snumChars) \n\t\t\t\t\t{\n\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\ttry \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t\t\t} \n\t\t\t\t\t\tcatch (IOException e) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic int nextInt() \n\t\t\t    {\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t\t{\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tint sgn = 1;\n\t\t\t\t\tif (c == '-')\n\t\t\t\t    {\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tint res = 0;\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res * sgn;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic long nextLong()\n\t\t\t    {\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t\t{\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tint sgn = 1;\n\t\t\t\t\tif (c == '-') \n\t\t\t\t\t{\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tlong res = 0;\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res * sgn;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic int[] nextIntArray(int n) \n\t\t\t\t{\n\t\t\t\t\tint a[] = new int[n];\n\t\t\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t\t\t{\n\t\t\t\t\t\ta[i] = nextInt();\n\t\t\t\t\t}\n\t\t\t\t\treturn a;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic String readString()\n\t\t\t    {\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c)) \n\t\t\t\t\t{\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t}\n\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\treturn res.toString();\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic String nextLine() \n\t\t\t\t{\n\t\t\t\t\tint c = snext();\n\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\tdo \n\t\t\t\t\t{\n\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\tc = snext();\n\t\t\t\t\t} while (!isEndOfLine(c));\n\t\t\t\t\treturn res.toString();\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic boolean isSpaceChar(int c) \n\t\t\t\t{\n\t\t\t\t\tif (filter != null)\n\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t}\n\t\t \n\t\t\t\tprivate boolean isEndOfLine(int c) \n\t\t\t\t{\n\t\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t\t}\n\t\t \n\t\t\t\tpublic interface SpaceCharFilter\n\t\t\t    {\n\t\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tstatic class CodeX {\n\t        public static void sort(long arr[]) {\n\t            merge_sort(arr, 0, arr.length - 1);\n\t        }\n\t\n\t        private static void merge_sort(long A[], long start, long end) {\n\t            if (start < end) {\n\t                long mid = (start + end) / 2;\n\t                merge_sort(A, start, mid);\n\t                merge_sort(A, mid + 1, end);\n\t                merge(A, start, mid, end);\n\t            }\n\t\n\t        }\n\t\n\t        private static void merge(long A[], long start,long mid, long end) {\n\t            long p = start, q = mid + 1;\n\t            long Arr[] = new long[(int)(end - start + 1)];\n\t            long k = 0;\n\t\n\t            for (int i = (int)start; i <= end; i++) {\n\t                if (p > mid)\n\t                    Arr[(int)k++] = A[(int)q++];\n\t\n\t                else if (q > end)\n\t                    Arr[(int)k++] = A[(int)p++];\n\t\n\t                else if (A[(int)p] < A[(int)q])\n\t                    Arr[(int)k++] = A[(int)p++];\n\t\n\t                else\n\t                    Arr[(int)k++] = A[(int)q++];\n\t            }\n\t            for (int i = 0; i < k; i++) {\n\t                A[(int)start++] = Arr[i];\n\t            }\n\t\n\t        }\n\t\n\t    }\n\t\t}\t\n\t\t\n\n\t\t\t", "complexity": "nlogn", "problem": "957_C. Three-level Laser", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Three{\n    public static void main(String[] args) {\n\tScanner in = new Scanner (System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\n\tpair[] points = new pair [3];\n\tfor (int i = 0; i < 3; ++i) {\n\t    int x = in.nextInt();\n\t    int y = in.nextInt();\n\t    points[i] = new pair (x, y);\n\t}\n\n\tArrays.sort(points);\n\n\tint MaxY = Math.max(Math.max(points[0].y, points[1].y), points[2].y);\n\tint MinY = Math.min(Math.min(points[0].y, points[1].y), points[2].y);\n\n\tout.println(MaxY - MinY + points[2].x - points[0].x + 1);\n\tfor (int i = MinY; i <= MaxY; ++i)\n\t    out.println(points[1].x + \" \" + i);\n\tfor (int i = points[0].x; i < points[1].x; ++i)\n\t    out.println(i + \" \" + points[0].y);\n\tfor (int i = points[1].x + 1; i <= points[2].x; ++i)\n\t    out.println(i + \" \" + points[2].y);\n\t\n\tout.close();\n    }\n\n    public static class pair implements Comparable<pair> {\n\tint x, y;\n\tpublic pair (int x_, int y_) {\n\t    x = x_; y = y_;\n\t}\n\n\t@Override\n\tpublic int compareTo(pair o) {\n\t    return x - o.x;\n\t}\n    }\n}\n", "complexity": "nlogn", "problem": "1086_A. Connect Three", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Problem\n{\n\n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    static int[] rt;\n    static int[] size;\n\n    static void initialize(int n){\n        rt = new int[n + 1];\n        size = new int[n + 1];\n        for(int i = 0; i < rt.length; i++){\n            rt[i] = i;\n            size[i] = 1;\n        }\n    }\n    \n    static int root(int x){\n        while(rt[x] != x){\n            rt[x] = rt[rt[x]];\n            x = rt[x];\n        }\n        return x;\n    }\n    \n    static long union(int x,int y){\n        int root_x = root(x);\n        int root_y = root(y);\n        if(root_x == root_y) return 0;\n        long val = size[root_x] *1l* size[root_y];\n        if(size[root_x]<size[root_y]){\n            rt[root_x] = rt[root_y];\n            size[root_y] += size[root_x];\n        }\n        else{\n            rt[root_y] = rt[root_x];\n            size[root_x] += size[root_y];            \n        }\n        \n        return val;\n    }\n    \n    static void solve()\n    {\n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out);            \n        \n        int t = 1;\n        \n        while(t-- > 0){\n            int n = in.nextInt();\n            int[] arr = in.nextIntArray(n);\n            ArrayList<Pair> list = new ArrayList<>();\n            \n            for(int i = 1; i < n; i++){\n                int u = in.nextInt() - 1;\n                int v = in.nextInt() - 1;\n                list.add(new Pair(u, v, Math.max(arr[u],arr[v])));\n            }\n            list.sort((p1,p2) -> Integer.compare(p1.i, p2.i));\n            initialize(n);\n            long s1 = 0;\n            for(int i = 0; i < list.size(); i++){\n                s1 += union(list.get(i).x, list.get(i).y) * list.get(i).i;\n            }\n            for(int i = 0; i < list.size(); i++){\n                Pair p = list.get(i);\n                p.i = Math.min(arr[p.x],arr[p.y]);\n            }\n            list.sort((p1,p2) -> -Integer.compare(p1.i, p2.i));\n            initialize(n);\n            long s2 = 0;\n            for(int i = 0; i < list.size(); i++){\n                s2 += union(list.get(i).x, list.get(i).y) * list.get(i).i;\n            }\n            \n            out.println(s1 - s2);\n        }\n        \n        out.close();\n    }\n    \n    public static void main(String[] args)\n    {\n        new Thread(null ,new Runnable(){\n            public void run(){\n                try{\n                    solve();\n                } catch(Exception e){\n                    e.printStackTrace();\n                }\n            }\n        },\"1\",1<<26).start();\n        \n    }\n\n    static class Pair implements Comparable<Pair>\n    {\n\n        int x,y;\n        int i;\n\n\n        Pair (int x,int y)\n        {\n                this.x = x;\n                this.y = y;\n        }\n\n        Pair (int x,int y, int i)\n        {\n                this.x = x;\n                this.y = y;\n                this.i = i;\n        }\n\n        public int compareTo(Pair o)\n        {\n            if(this.x != o.x)\n                return -Integer.compare(this.x, o.y);\n            return -Integer.compare(this.y,o.y);\n                //return 0;\n        }\n\n        public boolean equals(Object o)\n        {\n            if (o instanceof Pair)\n            {\n                Pair p = (Pair)o;\n                return p.x == x && p.y==y;\n            }\n            return false;\n        }\n\n        @Override\n        public String toString()\n        {\n            return x + \" \"+ y + \" \"+i;\n        }\n\n        /*public int hashCode()\n        {\n            return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n        }*/\n\n    } \n\n    static long add(long a,long b){\n        long x=(a+b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n\n    static long sub(long a,long b){\n        long x=(a-b);\n        while(x<0) x+=mod;\n        return x;\n    }\n    \n    static long mul(long a,long b){\n        long x=(a*b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n    \n    static String rev(String s){\n        StringBuilder sb=new StringBuilder(s);\n        sb.reverse();\n        return sb.toString();\n    }\n    \n    static long gcd(long x,long y)\n    {\n        if(y==0)\n                return x;\n        else\n                return gcd(y,x%y);\n    }\n\n    static int gcd(int x,int y)\n    {\n        if(y==0)\n                return x;\n        else \n                return gcd(y,x%y);\n    }\n\n    static long pow(long n,long p,long m)\n    {\n         long  result = 1;\n          if(p==0){\n            return n;\n          }\n          \n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\n            if(result >= m)\n               result %= m;\n            p >>=1;\n            n*=n;\n            if(n >= m)\n                n%=m;\n        }\n        \n        return result;\n    }\n\n    static long pow(long n,long p)\n    {\n        long  result = 1;\n          if(p==0)\n            return 1;\n\n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\t    \n            p >>=1;\n            n*=n;\t    \n        }\n        return result;\n    }\n\n    static void debug(Object... o)\n    {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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", "complexity": "nlogn", "problem": "915_F. Imbalance Value of a Tree", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n    private static int[] a;\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt(), m = sc.nextInt();\n\n        a = new int[101];\n        for (int i = 0; i < m; i++) {\n            int type = sc.nextInt();\n            a[type] = a[type] + 1;\n        }\n\n        int lo=1, hi=100, max=0;\n\n        while (lo <= hi) {\n            int mid = lo + (hi - lo)/2;\n            if (check(n, mid)) {\n                max = mid;\n                lo = mid+1;\n            } else {\n                hi = mid -1;\n            }\n        }\n        System.out.println(max);\n    }\n\n    public static boolean check(int n, int target) {\n        int result = 0;\n        for (int i=0; i <a.length; i++) {\n            result = result + (a[i] / target);\n        }\n        if (result >= n) {return true;}\n        return false;\n    }\n}", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Solution {\n\n    private static int[] a;\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt(), m = sc.nextInt();\n\n        a = new int[101];\n        for (int i = 0; i < m; i++) {\n            int type = sc.nextInt();\n            a[type] = a[type] + 1;\n        }\n\n        int lo=1, hi=100, max=0;\n\n        while (lo <= hi) {\n            int mid = lo + (hi - lo)/2;\n            if (check(n, mid)) {\n                max = mid;\n                lo = mid+1;\n            } else {\n                hi = mid -1;\n            }\n        }\n        System.out.println(max);\n    }\n\n    public static boolean check(int n, int target) {\n        int result = 0;\n        for (int i=0; i <a.length; i++) {\n            result = result + (a[i] / target);\n        }\n        if (result >= n) {return true;}\n        return false;\n    }\n}", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tSolution solution = new Solution();\n\t\tSystem.out.println(solution.solve());\n\t}\n\n\tprivate int solve() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\n\t\tint[] a = new int[m];\n\t\tfor (int i = 0; i < m; ++i) a[i] = in.nextInt();\n\n\t\tif (n > m) return 0;\n\n\t\tMap<Integer, Integer> map = new HashMap<>();\n\t\tfor (int k: a) map.put(k, map.getOrDefault(k, 0) + 1);\n\n\t\tList<Integer> keySet = new ArrayList<>(map.keySet());\n\t\tint end = m / n;\n\n\t\tkeySet.sort((u, v) -> -Integer.compare(u, v));\n\t\tdo {\n\t\t\tint count = 0;\n\t\t\tfor (int k: keySet) {\n\t\t\t\tcount += map.get(k) / end;\n\t\t\t\tif (count >= n) return end;\n\t\t\t}\n\t\t} while (--end > 0);\n\n\t\treturn 0;\n\t}\n}\n", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tSolution solution = new Solution();\n\t\tSystem.out.println(solution.solve());\n\t}\n\n\tprivate int solve() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\n\t\tint[] a = new int[m];\n\t\tfor (int i = 0; i < m; ++i) a[i] = in.nextInt();\n\n\t\tif (n > m) return 0;\n\n\t\tMap<Integer, Integer> map = new HashMap<>();\n\t\tfor (int k: a) map.put(k, map.getOrDefault(k, 0) + 1);\n\n\t\tList<Integer> keySet = new ArrayList<>(map.keySet());\n\t\tint end = m / n;\n\n\t\tkeySet.sort((u, v) -> -Integer.compare(u, v));\n\t\tdo {\n\t\t\tint count = 0;\n\t\t\tfor (int k: keySet) {\n\t\t\t\tcount += map.get(k) / end;\n\t\t\t\tif (count >= n) return end;\n\t\t\t}\n\t\t} while (--end > 0);\n\n\t\treturn 0;\n\t}\n}\n", "complexity": "nlogn", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.util.*; \n\n\npublic class p7{\n\t\n\tstatic class FastReader{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t}\n\n\tpublic static void main(String[] args) \n\t{ \n        FastReader sc = new FastReader(); \n        //PrintWriter out = new PrintWriter(System.out); \n        int n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tlong one = (long)Math.pow(2, k) - 1;\n\t\t\n\t\tlong[] arr = new long[n+1];\n\t\t\n\t\tarr[0] = 0;\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tarr[i] = sc.nextLong();\n\t\t\tarr[i] ^= arr[i-1];\n\t\t}\n\n\t\tMap<Long, Long> count = new HashMap<>();\n\n\t\tfor(int i=0;i<=n;i++){\n\t\t\tLong key = Math.min(arr[i], (arr[i]^one));\n\t\t\tLong val = count.get(key);\n\t\t\tif(val==null) val = 0L;\n\t\t\tcount.put(key, val+1);\n\t\t}\n\n\t\tlong num = n;\n\t\tlong ans = num*(num+1)/2;\n\t\t\n\t\tfor(Map.Entry<Long, Long> ent: count.entrySet()){\n\t\t\t\n\t\t\tLong cnt = ent.getValue();\n\t\t\t\n\t\t\tlong num1 = cnt/2;\n\t\t\tlong num2 = (cnt+1)/2;\n\t\t\t\n\t\t\tans -= ( (num1*(num1-1))/2 );\n\t\t\tans -= ( (num2*(num2-1))/2 );\n\t\t}\n\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "nlogn", "problem": "1054_D. Changing Array", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author caoash\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        BObtainingTheString solver = new BObtainingTheString();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class BObtainingTheString {\n        public void solve(int testNumber, FastScanner br, PrintWriter pw) {\n            int n = br.nextInt();\n            String s = br.nextString();\n            String t = br.nextString();\n            char[] sarr = new char[n];\n            char[] tarr = new char[n];\n            int[] sAppear = new int[26];\n            int[] tAppear = new int[26];\n            for (int i = 0; i < s.length(); i++) {\n                sarr[i] = s.charAt(i);\n                tarr[i] = t.charAt(i);\n                sAppear[s.charAt(i) - 'a']++;\n                tAppear[t.charAt(i) - 'a']++;\n            }\n            for (int i = 0; i < 26; i++) {\n                if (sAppear[i] != tAppear[i]) {\n                    pw.println(-1);\n                    pw.close();\n                }\n            }\n            ArrayList<Integer> ans = new ArrayList<Integer>();\n            for (int i = 0; i < n; i++) {\n                char curr = tarr[i];\n                for (int j = i + 1; j < n; j++) {\n                    if (sarr[j] == curr) {\n                        for (int k = j; k > i; k--) {\n                            ans.add(k);\n                            char temp = sarr[k - 1];\n                            sarr[k - 1] = sarr[k];\n                            sarr[k] = temp;\n                        }\n                        break;\n                    }\n                }\n            }\n            pw.println(ans.size());\n            for (int e : ans) {\n                pw.print(e + \" \");\n            }\n            pw.close();\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        private FastScanner.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\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 interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1015_B. Obtaining the String", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A961_Tetris {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\t\tint platforms = input.nextInt();\n\t\tint in = input.nextInt();\n\t\tint[] cols = new int[platforms];\n\t\tint[] squares = new int[in];\n\t\t\n\t\tfor (int i = 0; i < in; i ++) {\n\t\t\tsquares[i] = input.nextInt();\n\t\t}\n\t\t\n\t\tboolean hi = false;\n\t\tint score = 0;\n\t\t\n\t\tfor (int i = 0; i < in; i ++) {\n\t\t\tcols[squares[i] - 1] ++;\n\t\t\thi = checkscore(cols);\n\t\t\tif (hi == true) {\n\t\t\t\thi = false;\n\t\t\t\tscore ++;\n\t\t\t\tfor (int j = 0; j < cols.length; j ++) {\n\t\t\t\t\tcols[j] --;\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\tSystem.out.println(score);\n\t\t\n\t}\n\t\n\tpublic static boolean checkscore(int[] cols) {\n\t\tfor (int i = 0; i < cols.length; i ++) {\n\t\t\tif (cols[i] == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn true;\n\t\t\n\t}\n\n}\n", "complexity": "quadratic", "problem": "961_A. Tetris", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class RGBSubstring {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        int Q = scanner.nextInt();\n        while(Q-->0) {\n            int N = scanner.nextInt();\n            int K = scanner.nextInt();\n            String s1 = \"RGB\";\n            String s2 = \"GBR\";\n            String s3 = \"BRG\";\n            char[] arr = scanner.next().toCharArray();\n            int[] cnts = new int[3];\n            for(int i = 0; i < K; i++) {\n                int ind = i % 3;\n                if (arr[i] != s1.charAt(ind)) cnts[0]++;\n                if (arr[i] != s2.charAt(ind)) cnts[1]++;\n                if (arr[i] != s3.charAt(ind)) cnts[2]++;\n            }\n            int ans = Math.min(Math.min(cnts[0], cnts[1]), cnts[2]);\n            for(int i = K; i < N; i++) {\n                int ind = (K-1)%3;\n                int[] nextCnts = new int[3];\n                nextCnts[1] = cnts[0];\n                nextCnts[2] = cnts[1];\n                nextCnts[0] = cnts[2];\n                if ('R' != arr[i-K]) nextCnts[1]--;\n                if ('G' != arr[i-K]) nextCnts[2]--;\n                if ('B' != arr[i-K]) nextCnts[0]--;\n                if (arr[i] != s1.charAt(ind)) nextCnts[0]++;\n                if (arr[i] != s2.charAt(ind)) nextCnts[1]++;\n                if (arr[i] != s3.charAt(ind)) nextCnts[2]++;\n                cnts = nextCnts;\n                for(int j = 0; j < 3; j++) ans = Math.min(ans, cnts[j]);\n            }\n            out.println(ans);\n        }\n        out.flush();\n    }\n    \n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n        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", "complexity": "quadratic", "problem": "1196_D1. RGB Substring (easy version)", "from": "CODEFORCES"}
{"src": "// discussed with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF915D {\n\tstatic ArrayList[] aa;\n\tstatic boolean[] visited, instack;\n\tstatic int[] stack;\n\tstatic int cnt, h_, i_, j_;\n\tstatic boolean dfs1(int i) {\n\t\tif (visited[i]) {\n\t\t\tif (instack[i]) {\n\t\t\t\th_ = i;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tvisited[i] = instack[i] = true;\n\t\tstack[cnt++] = i;\n\t\tArrayList<Integer> adj = aa[i];\n\t\tfor (int j : adj)\n\t\t\tif (dfs1(j))\n\t\t\t\treturn true;\n\t\tinstack[i] = false;\n\t\tcnt--;\n\t\treturn false;\n\t}\n\tstatic boolean dfs2(int i) {\n\t\tif (visited[i])\n\t\t\treturn instack[i];\n\t\tvisited[i] = instack[i] = true;\n\t\tArrayList<Integer> adj = aa[i];\n\t\tfor (int j : adj)\n\t\t\tif (!(i == i_ && j == j_) && dfs2(j))\n\t\t\t\treturn true;\n\t\tinstack[i] = false;\n\t\treturn false;\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\taa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\twhile (m-- > 0) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint i = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tint j = Integer.parseInt(st.nextToken()) - 1;\n\t\t\taa[i].add(j);\n\t\t}\n\t\tvisited = new boolean[n];\n\t\tinstack = new boolean[n];\n\t\tstack = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif (dfs1(i))\n\t\t\t\tbreak;\n\t\tif (cnt == 0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\tfor (j_ = h_, i_ = stack[--cnt]; ; j_ = i_, i_ = stack[--cnt]) {\n\t\t\tArrays.fill(visited, false);\n\t\t\tArrays.fill(instack, false);\n\t\t\tboolean cycle = false;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (dfs2(i)) {\n\t\t\t\t\tcycle = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (!cycle) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (i_ == h_)\n\t\t\t\tbreak;\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t}\n}\n", "complexity": "quadratic", "problem": "915_D. Almost Acyclic Graph", "from": "CODEFORCES"}
{"src": "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.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        static final long BIG = Long.MAX_VALUE - Long.MAX_VALUE % MODULO;\n        static final int[] ONE = new int[]{1};\n        int k;\n        int n;\n        long[] globalRes;\n        int[] p2;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            k = in.nextInt();\n            globalRes = new long[k + 1];\n            p2 = new int[n + 1];\n            p2[0] = 1;\n            for (int i = 1; i <= n; ++i) p2[i] = (int) (2 * p2[i - 1] % MODULO);\n            Vertex[] vs = new Vertex[n];\n            for (int i = 0; i < n; ++i) vs[i] = new Vertex();\n            for (int i = 0; i < n - 1; ++i) {\n                Vertex a = vs[in.nextInt() - 1];\n                Vertex b = vs[in.nextInt() - 1];\n                a.adj.add(b);\n                b.adj.add(a);\n            }\n            vs[0].dfs(null);\n            long[][] ways = new long[k + 1][k + 1];\n            ways[0][0] = 1;\n            for (int i = 1; i <= k; ++i) {\n                for (int j = 1; j <= k; ++j) {\n                    ways[i][j] = j * (ways[i - 1][j] + ways[i - 1][j - 1]) % MODULO;\n                }\n            }\n            long sum = 0;\n            for (int i = 1; i <= k; ++i) {\n                long s = globalRes[i];\n                s %= MODULO;\n                sum = (sum + s * ways[k][i]) % MODULO;\n            }\n            out.println(sum);\n        }\n\n        class Vertex {\n            int[] res;\n            int subtreeSize;\n            List<Vertex> adj = new ArrayList<>();\n\n            public void dfs(Vertex parent) {\n                subtreeSize = 1;\n                int[] prod = ONE;\n                for (Vertex child : adj)\n                    if (child != parent) {\n                        child.dfs(this);\n                        subtreeSize += child.subtreeSize;\n                    }\n                int mult = 2;//p2[n - subtreeSize];\n                for (Vertex child : adj)\n                    if (child != parent) {\n                        int[] c = child.res;\n                        prod = mul(prod, c);\n                        subFrom(globalRes, c, 1);\n                    }\n                addTo(globalRes, prod, mult);\n                res = insertEdge(prod);\n            }\n\n            private int[] insertEdge(int[] a) {\n                int len = a.length + 1;\n                if (len > k) len = k + 1;\n                int[] b = new int[len];\n                b[0] = a[0] * 2;\n                if (b[0] >= MODULO) b[0] -= MODULO;\n                for (int i = 1; i < len; ++i) {\n                    long s = a[i - 1];\n                    if (i < a.length) s += a[i];\n                    if (s >= MODULO) s -= MODULO;\n                    s = s * 2;\n                    if (s >= MODULO) s -= MODULO;\n                    b[i] = (int) s;\n                }\n                b[1] -= 1;\n                if (b[1] < 0) b[1] += MODULO;\n                return b;\n            }\n\n            private void addTo(long[] a, int[] b, int mult) {\n                for (int i = 0; i < b.length; ++i) {\n                    long s = a[i] + b[i] * (long) mult;\n                    if (s < 0) s -= BIG;\n                    a[i] = s;\n                }\n            }\n\n            private void subFrom(long[] a, int[] b, int mult) {\n                for (int i = 0; i < b.length; ++i) {\n                    long s = a[i] + (MODULO - b[i]) * (long) mult;\n                    if (s < 0) s -= BIG;\n                    a[i] = s;\n                }\n            }\n\n            private int[] mul(int[] a, int[] b) {\n                int len = a.length + b.length - 1;\n                if (len > k) len = k + 1;\n                int[] c = new int[len];\n                for (int i = 0; i < len; ++i) {\n                    long s = 0;\n                    int left = Math.max(0, i - (b.length - 1));\n                    int right = Math.min(a.length - 1, i);\n                    for (int ia = left; ia <= right; ++ia) {\n                        int ib = i - ia;\n                        s += a[ia] * (long) b[ib];\n                        if (s < 0) s -= BIG;\n                    }\n                    c[i] = (int) (s % MODULO);\n                }\n                return c;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1097_G. Vladislav and a Great Legend", "from": "CODEFORCES"}
{"src": "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        E solver = new E();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class E {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.ni(), K = in.ni();\n            long mod = 998244353;\n            long[][] dp = new long[n + 1][n + 1];\n            for (int lim = 1; lim <= n; lim++) {\n                long sum = 1;\n                dp[0][lim] = 1;\n                for (int i = 1; i <= n; i++) {\n                    dp[i][lim] = (dp[i][lim] + sum) % mod;\n                    sum = (sum + dp[i][lim]) % mod;\n                    if (i >= lim)\n                        sum = (sum - dp[i - lim][lim] + mod) % mod;\n                }\n            }\n            long ans = 0;\n            for (int k = 1; k < Math.min(K, n + 1); k++) {\n                long h = dp[n][k] - dp[n][k - 1];\n                int lim = K / k;\n                if (K % k == 0)\n                    lim--;\n                if (lim > n)\n                    lim = n;\n                ans += dp[n][lim] * h % mod;\n            }\n            out.println(2 * ans % mod);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream stream) {\n            in = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String ns() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(ns());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1027_E. Inverse Coloring", "from": "CODEFORCES"}
{"src": "\n/**\n * @author: Mehul Raheja\n */\n\nimport java.util.*;\nimport java.io.*;\n\npublic class p3{\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    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  \n        st = new StringTokenizer(br.readLine());\n        int N = Integer.parseInt(st.nextToken());\n        int R = Integer.parseInt(st.nextToken());\n        double[] x = new double[N];\n        st = new StringTokenizer(br.readLine());\n        for (int i = 0; i < N; i++) {\n            x[i] = Double.parseDouble(st.nextToken());\n        }\n        double[] y = new double[N];\n        for (int i = 0; i < N; i++) {\n          //  int found = -1;\n            double maxy = R;\n            for (int j = i-1; j >= 0; j--) {\n                if(Math.abs(x[j] - x[i]) <= 2 * R){\n                    maxy = Math.max(y[j] + inc(x[j] - x[i],R), maxy);\n                }\n            }\n            \n            y[i] = maxy;\n        }\n        \n        for (int i = 0; i < y.length-1; i++) {\n            System.out.print(y[i] + \" \");\n        }\n        System.out.println(y[y.length-1]);\n       // System.out.println(Arrays.toString(y));\n    }  \n    \n    public static  double inc(double x, double R){\n        return Math.sqrt((4*R*R)-(x*x));\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main {\n    public static void main(String[] args) {\n        FastScanner sc=new FastScanner();\n        PrintWriter pw=new PrintWriter(System.out);\n        double eps=1e-12;\n        while(sc.hasNext()){\n            int n=sc.nextInt();\n            int r=sc.nextInt();\n            double[]shu=new double[n];\n            for(int i=0;i<n;i++)shu[i]=sc.nextDouble();\n            double[]res=new double[n];\n            for(int i=0;i<n;i++){\n                for(int j=0;j<i;j++){\n                    double temp=Math.abs(shu[i]-shu[j]);\n                    if(temp<2*r||Math.abs(temp-2*r)<eps){\n                        res[i]=Math.max(res[i],res[j]+Math.sqrt(4*r*r-temp*temp));\n                    }\n                }\n                res[i]=Math.max(res[i],r);\n            }\n            for(int i=0;i<n;i++){\n                pw.print(res[i]+\" \");\n            }\n            pw.flush();\n        }\n    }\n}\nclass FastScanner{\n    BufferedReader br;\n    StringTokenizer st;\n    FastScanner(){\n        br=new BufferedReader(new InputStreamReader(System.in));\n        st=new StringTokenizer(\"\");\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    boolean hasNext(){\n        String s=\"\";\n        while(!st.hasMoreTokens()){\n            s=nextLine();\n            if(s==null)return false;\n            st=new StringTokenizer(s);\n        }\n        return true;\n    }\n    String next(){\n        String s=\"\";\n        while(!st.hasMoreTokens()){\n            s=nextLine();\n            st=new StringTokenizer(s);\n        }\n        return st.nextToken();\n    }\n    int nextInt(){\n        return Integer.valueOf(next());\n    }\n    long nextLong(){\n        return Long.valueOf(next());\n    }\n    double nextDouble(){\n        return Double.valueOf(next());\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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 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\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\t\t\n\t\tint n = scn.nextInt(), r = scn.nextInt();\n\t\tdouble[] y = new double[n];\n\t\tint[] x = new int[n];\n\t\tboolean[] mark = new boolean[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tx[i] = scn.nextInt();\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tdouble yc = r;\n\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\tif(i == j || !mark[j]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(x[i] + r < x[j] - r || x[i] - r > x[j] + r) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tyc = Math.max(yc, y[j] + Math.sqrt(Math.abs(Math.pow(x[i] - x[j], 2) - 4 * r * r)));\n\t\t\t}\n\t\t\ty[i] = yc;\n\t\t\tmark[i] = true;\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tSystem.out.print(y[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\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 C {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint r = sc.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = sc.nextInt();\n\n\t\tdouble[] ans = new double[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdouble max = 0;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tint difx = Math.abs(arr[i] - arr[j]);\n\t\t\t\tif (difx <= 2 * r) {\n\t\t\t\t\tmax = Math.max(max, ans[j] + Math.sqrt(4 * r * r - difx * difx));\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[i] = max;\n\t\t}\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tpw.print(ans[i] + r + \" \");\n\t\tpw.flush();\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\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\n\npublic class C {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic static class Pair {\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\t}\n\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint r = 2 * in.nextInt();\n\t\tint[] x = new int[n];\n\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\tx[i] = in.nextInt();\n\t\t}\n\t\tdouble[] y = new double[n];\n\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\ty[i] = r / 2;\n\t\t}\n\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tif (Math.abs(x[i] - x[j]) == r) {\n\t\t\t\t\ty[i] = Math.max(y[i], y[j]);\n\t\t\t\t} else if (Math.abs(x[i] - x[j]) < r) {\n\t\t\t\t\ty[i] = Math.max(y[i], y[j] + Math.sqrt(r * r - (x[j] - x[i]) * (x[j] - x[i])));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\tout.print(y[i] + \" \");\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(\"segments.in\"));\n\t\t\t\tout = new PrintWriter(new File(\"segments.out\"));\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class C{\n\t\n\tstatic int n;\n\tstatic double sqr(double v) {return (v*v);}\n\tstatic double sqrt(double v) {return Math.sqrt(v);}\n\tstatic double r,x[],res[];\n\tstatic void MainMethod()throws Exception{\n\t\tn=reader.nextInt();\n\t\tr=reader.nextDouble();\n\t\tint i,j;\n\t\tx=new double[n];\n\t\tres=new double[n];\n\t\tfor (i=0;i<n;i++)x[i]=reader.nextDouble();\n\t\tres[0]=r;\n\t\tfor (i=1;i<n;i++) {\n\t\t\tres[i]=r;\n\t\t\tfor (j=0;j<i;j++) {\n\t\t\t\tif (Math.abs(x[i]-x[j])<=(2*r)) {\n\t\t\t\t\tres[i]=Math.max(res[i], \n\t\t\t\t\t\t\tsqrt(sqr(2*r)-sqr(x[i]-x[j]))+res[j]\n\t\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (i=0;i<n;i++)\n\t\t\tprinter.print(res[i]+\" \");\n\t}\n\tpublic static void main(String[] args)throws Exception{\n\t\tMainMethod();\n\t\tprinter.close();\n\t}\n\tstatic void halt(){\n\t\tprinter.close();\n\t\tSystem.exit(0);\n\t}\n\tstatic PrintWriter printer=new PrintWriter(new OutputStreamWriter(System.out));\n\tstatic class reader{\n\t\tstatic BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));\n\t\tstatic StringTokenizer token=new StringTokenizer(\"\");\n\t\tstatic String readNextLine() throws Exception{\n\t\t\treturn bReader.readLine();\n\t\t}\n\t\tstatic String next() throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn token.nextToken();\n\t\t}\n\t\tstatic int nextInt()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Integer.parseInt(token.nextToken());\n\t\t}\n\t\tstatic long nextLong()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Long.parseLong(token.nextToken());\n\t\t}\n\t\tstatic double nextDouble()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Double.parseDouble(token.nextToken());\n\t\t}\n\t}\n\tstatic class MyMathCompute{\n\t\tstatic long [][] MatrixMultiplyMatrix(long [][] A, long [][] B, long mod) throws Exception{\n\t\t\tint n=A.length, m=B[0].length; \n\t\t\tint p=A[0].length;\n\t\t\tint i,j,k;\n\t\t\tif (B.length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\tlong [][] res=new long [n][m];\n\t\t\tfor (i=0;i<n;i++) for (j=0;j<m;j++){\n\t\t\t\tif (A[i].length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\t\tres[i][j]=0;\n\t\t\t\tfor (k=0;k<p;k++)\n\t\t\t\t\tres[i][j]=(res[i][j]+((A[i][k]*B[k][j])% mod))% mod;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tstatic double [][] MatrixMultiplyMatrix(double [][] A, double [][] B ) throws Exception{\n\t\t\tint n=A.length, m=B[0].length; \n\t\t\tint p=A[0].length;\n\t\t\tint i,j,k;\n\t\t\tif (B.length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\tdouble [][] res=new double [n][m];\n\t\t\tfor (i=0;i<n;i++) for (j=0;j<m;j++){\n\t\t\t\tif (A[i].length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\t\tres[i][j]=0;\n\t\t\t\tfor (k=0;k<p;k++)\n\t\t\t\t\tres[i][j]=res[i][j]+(A[i][k]*B[k][j]);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tstatic long [][] MatrixPow(long [][] A,long n, long mod) throws Exception{\n\t\t\tif (n==1) return A;\n\t\t\tlong [][] res=MatrixPow(A, n/2, mod);\n\t\t\tres=MatrixMultiplyMatrix(res, res, mod);\n\t\t\tif ((n % 2) == 1) res=MatrixMultiplyMatrix(A,res, mod);\t\t\n\t\t\treturn res;\n\t\t}\n\t\tstatic double [][] MatrixPow(double [][] A,long n) throws Exception{\n\t\t\tif (n==1) return A;\n\t\t\tdouble[][] res=MatrixPow(A, n/2);\n\t\t\tres=MatrixMultiplyMatrix(res, res);\n\t\t\tif ((n % 2) == 1) res=MatrixMultiplyMatrix(A,res);\t\t\n\t\t\treturn res;\n\t\t}\n\t\tstatic long pow(long a,long n,long mod){\n\t\t\ta= a % mod;\n\t\t\tif (n==0) return 1;\n\t\t\tlong k=pow(a,n/2,mod);\n\t\t\tif ((n % 2)==0) return ((k*k)%mod);\n\t\t\telse return (((k*k) % mod)*a) % mod;\n\t\t}\n\t\tstatic double pow(double a,long n){\n\t\t\tif (n==0) return 1;\n\t\t\tdouble k=pow(a,n/2);\n\t\t\tif ((n % 2)==0) return (k*k);\n\t\t\telse return (((k*k) )*a) ;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    public static void main(String[] args) throws Exception {\n        int n=nextInt();\n        int r=nextInt();\n        int x[]=new int[n];\n        double y[]=new double[n];\n        for(int i=0;i<n;i++)\n            x[i]=nextInt();\n        for(int i=0;i<n;i++){\n            //(x1-x2)2+(y1-y2)2=r2\n            y[i]=r;\n            for(int j=0;j<i;j++){\n                int d=sq(2*r)-sq(x[i]-x[j]);\n                if(d>=0){\n                    double y1=Math.sqrt(d)+y[j];\n                    y[i]=Math.max(y1,y[i]);\n                }\n            }\n        }\n        for(int i=0;i<n;i++)\n            System.out.printf(\"%.12g \",y[i]);\n    }\n    static int sq(int a){\n        return a*a;\n    }\n    static int nextInt()throws IOException{\n        InputStream in=System.in;\n        int ans=0;\n        boolean flag=true;\n        byte b=0;\n        while ((b>47 && b<58) || flag){\n            if(b>=48 && b<58){\n                ans=ans*10+(b-48);\n                flag=false;\n            }\n            b=(byte)in.read();\n        }\n        return ans;\n    }\n    static String next()throws Exception{\n        StringBuilder sb=new StringBuilder(1<<16);\n        InputStream in=System.in;\n        byte b=0;\n        do{\n            if(!isWhiteSpace(b))\n                sb.append((char)b);\n            b=(byte)in.read();\n        }while(!isWhiteSpace(b) || sb.length()==0);\n        return sb.toString();\n    }\n    static boolean isWhiteSpace(byte b){\n        char ch=(char)b;\n        return ch=='\\0' || ch==' ' || ch=='\\n';\n    }\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\npublic class Main{\n  public static void main(String[] args){\n    InputReader reader = new InputReader(System.in);\n    PrintWriter pw = new PrintWriter(System.out);\n    int n = reader.nextInt();\n    int r = reader.nextInt();\n    int[] x = new int[n];\n    double[] y = new double[n];\n    \n    for(int i=0;i<n;++i){\n      int iniX = reader.nextInt();\n      double bestY = (double)r;\n      for(int j=0;j<i;++j){\n//         pw.printf(\"testing %d %d\\n\", i, j);\n        if(Math.abs(iniX - x[j]) < 2*r){\n//           pw.printf(\"on colision %d %d\\n\", i, j);\n          bestY = Math.max(bestY, collisionY((double)x[j], y[j], (double)iniX, r));\n        }\n        if(Math.abs(iniX - x[j]) == 2*r){\n//           pw.printf(\"touvhing %d %d\\n\", i, j);\n          bestY = Math.max(bestY, y[j]);\n        }\n      }\n      x[i] = iniX;\n      y[i] = bestY;\n    }\n    for(int i=0;i<n;++i){\n      pw.printf(\"%.9f \", y[i]);\n    }   \n    pw.flush();\n    pw.close();\n  }\n  \n  public static double collisionY(double x1, double y1, double x2, double r){\n    double dhsq = r*r*4-(x1-x2)*(x1-x2);\n    return y1+Math.sqrt(dhsq);\n  }\n  \n  public static class InputReader {\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    \n    public InputReader (InputStream stream){\n      reader = new BufferedReader(new InputStreamReader(stream));\n    }\n    \n\n    public String next(){\n      while(tokenizer == null || !tokenizer.hasMoreTokens()){\n        try{\n          String line = reader.readLine();\n          if(line == null){\n            return \"0\";\n          }\n          tokenizer = new StringTokenizer(line);\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 double nextDouble(){\n      return Double.parseDouble(next());\n    }\n    \n    public Long nextLong(){\n      return Long.parseLong(next());\n    }\n    \n    public BigInteger nextBigInteger(){\n      return new BigInteger(next());\n    }\n    \n    public String nextLine(){\n      String line = \"\";\n      try{\n        while(line.equals(\"\")){\n          line = reader.readLine();\n        }\n      } catch(IOException ioe){\n        throw new RuntimeException(ioe);\n      }\n      return line;\n    }\n  }\n  \n  public static class MultiSet<E> {\n    HashMap<E, Integer> map = new HashMap<E, Integer>();\n    int multiSize = 0;\n    public int add(E key){\n      multiSize ++;\n      Integer amount = map.get(key);\n      if(amount == null){\n        map.put(key, 1);\n        return 1;\n      }\n      map.put(key, amount+1);\n      return amount+1;\n    }\n    \n    public int remove(E key){\n      Integer amount = map.get(key);\n      if(amount == null){\n        return -1;\n      }\n      multiSize --;\n      if(amount == 1){\n        map.remove(key);\n      } else {\n        map.put(key, amount-1);\n      }\n      return amount-1;\n    }\n    \n    public ArrayList<E> elems(){\n      ArrayList<E> ret = new ArrayList<E>(multiSize);\n      for(Map.Entry<E, Integer> e : map.entrySet()){\n        E key = e.getKey();\n        int v = e.getValue();\n        while(v-->0){\n          ret.add(key);\n        }\n      }\n      return ret;\n    }\n    \n    public int getMultiSize(){\n      return multiSize;\n    }\n  \n  }\n  \n  \n   public static class MaxBIT{\n    int n;\n    int[]t;\n    \n    public MaxBIT(int n){\n      this.n = Integer.highestOneBit(n)<<1;\n      this.t = new int[this.n<<1];\n      for(int i=0;i<2*this.n;++i){\n        t[i] = -1;\n      }\n    }\n  \n    public void setMax(int p, int val){\n      p+=n;\n      while(p>1){\n        t[p] = Math.max(t[p], val);\n        p>>=1;\n      }\n    }\n    \n    public int getMax(int p, int q){\n      p+=n;\n      q+=n;\n      int ret = -1;\n      while(p<q){\n        if((p&1)==1){\n          ret=Math.max(t[p++], ret);\n        }\n        if((q&1)==1){\n          ret=Math.max(t[--q], ret);\n        }\n        p = p>>1;\n        q = q>>1;\n      }\n      return ret;\n    }\n  }\n  \n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.awt.geom.Point2D;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class C {\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] line = in.readLine().split(\" \");\n\t\tint n = Integer.parseInt(line[0]);\n\t\tint r=  Integer.parseInt(line[1]);\n\t\tline = in.readLine().split(\" \");\n\t\tdouble[] x = new double[n];\n\t\tdouble[] y= new double[n];\n\t\tfor(int i = 0; i<n; i++) {\n\t\t\ty[i] = r;\n\t\t\tx[i] = Integer.parseInt(line[i]);\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\tif(Math.abs(x[i]-x[j])>r*2) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdouble low = y[j];\n\t\t\t\tdouble high = y[j]+(double)r*2.0;\n\t\t\t\tfor(int k = 0; k<85 && low<high; k++) {\n\t\t\t\t\tdouble mid = (low+high)/2.0;\n\t\t\t\t\tif(Point2D.distance(x[j], y[j], x[i], mid)<(double)r*2.0) {\n\t\t\t\t\t\tlow = mid;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\thigh = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ty[i] = Math.max(y[i], low);\n\t\t\t}\n\t\t}\n\t\tSystem.out.printf(\"%.15f\",y[0]);\n\t\tfor(int i = 1; i<n; i++) {\n\t\t\tSystem.out.printf(\" %.15f\",y[i]);\n\t\t}\n\t\tSystem.out.print(\"\\n\");\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n    InputStream is;\n    PrintWriter out;\n    \n    double x[], y[], R;\n    \n    boolean game(double x1, double y1, double x2, double y2){\n        double dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n        //if(x2 == 12 && x1 == 8 && y1 > 13 && y1 < 14)    out.println(dis +\" \"+ y2);\n        return dis <= 4.0 * R * R;\n    }\n    \n    void play(int n){\n        double l, r, m;\n        double a[] = new double[n];\n        for(int i = 0; i < n; i++){ \n            l = 0.0;\n            r = 1000000.0;\n            for(int j = 0; j < 50; j++){\n                m = (l + r) / 2;\n                if(game(x[i], 0, x[n], m))  l = m;\n                else    r = m;\n            }\n            a[i] = l;\n        }\n        for(int i = 0; i < n; i++){\n            //if(n == 4)  out.println(a[i] +\" \"+ y[i]);\n            if(a[i] > 0.0 && (y[i] + a[i]) > y[n])    y[n] = y[i] + a[i];\n        }\n    }\n    \n    void solve(){\n        //Enter code here utkarsh\n        int i, j, n;\n        n = ni();\n        R = nd();\n        x = new double[n];\n        y = new double[n];\n        for(i = 0; i < n; i++)  x[i] = nd();\n        for(i = 0; i < n; i++){\n            play(i);\n        }\n        for(i = 0; i < n; i++)  out.print((R + y[i]) +\" \");\n    }\n    \n    public static void main(String[] args) { new utkarsh().run();\n    }\n    void run(){ is = System.in; out = new PrintWriter(System.out); solve(); out.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte(){ if(ptr >= len){ ptr = 0; try{ len = is.read(input); }catch(IOException e){ throw new InputMismatchException(); } if(len <= 0){ return -1; } } return input[ptr++];\n    }\n    boolean isSpaceChar(int c){ return !( c >= 33 && c <= 126 ); \n    }\n    int skip(){ int b = readByte(); while(b != -1 && isSpaceChar(b)){ b = readByte(); } return b;\n    }\n    \n    char nc(){ return (char)skip();\n    }\n    String ns(){ int b = skip(); StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){ sb.appendCodePoint(b); b=readByte(); } return sb.toString();\n    }\n    int ni(){ int n = 0,b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } if(b == -1){ return -1; } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;\n    }\n    long nl(){ long n = 0L; int b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;\n    }\n    double nd(){ return Double.parseDouble(ns());\n    }\n    float nf(){ return Float.parseFloat(ns());\n    }\n    int[] na(int n){ int a[] = new int[n]; for(int i = 0; i < n; i++){ a[i] = ni(); } return a;\n    }\n    char[] ns(int n){ char c[] = new char[n]; int i,b = skip(); for(i = 0; i < n; i++){ if(isSpaceChar(b)){ break; } c[i] = (char)b; b = readByte(); } return i == n ? c : Arrays.copyOf(c,i);\n    }\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n// import java.awt.Point;\n \npublic class Main {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\";\n \n    long MOD = 1_000_000_007;\n    int inf = Integer.MAX_VALUE;\n\n    void solve(){\n        int n = ni();\n        int r = ni();\n        int[] x = new int[n];\n        for(int i = 0; i < n; i++){\n            x[i] = ni();\n        }\n        double[] y = new double[n];\n        Arrays.fill(y,-1);\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < i; j++){\n                double res = 4*r*r - (x[i]-x[j])*(x[i]-x[j]);\n                if(res < 0) continue;\n                else{\n                    double tmp = Math.sqrt(res) + y[j];\n                    if(tmp > y[i]){\n                        y[i] = tmp;\n                    }\n                }\n            }\n            if(y[i]==-1) y[i] = r;\n        }\n        for(int i = 0; i < n; i++){\n            out.print(y[i]+\" \");\n        }\n    }  \n\n    class Permutation{\n    // max=10\n    // n=10: 160ms\n    // n=11: 1600-1700ms\n    int n;\n    int max;\n    BitSet used;\n    int[] p;\n    public Permutation(int n, int max){\n        this.n = n;\n        this.max = max;\n        used = new BitSet(n);\n        p = new int[n];\n    }\n    \n    public boolean next(){\n        if(used.cardinality() == 0){\n            for(int i=0; i<n; i++){\n                p[i] = i;\n            }\n            used.set(0, n);\n            return true;\n        }\n        int i;\n        for(i=n-1; i>=0; i--){\n            used.clear(p[i]);\n            if((used.nextClearBit(p[i]+1)) < max) break;\n        }\n        if(i<0) return false;\n        p[i] = used.nextClearBit(p[i]+1);\n        used.set(p[i]);\n        int idx = i+1;\n        for(i=used.nextClearBit(0); i<max && idx<n; i=used.nextClearBit(i+1)){\n            p[idx++] = i;\n            used.set(i);\n        }\n        return true;\n    }\n    \n    public String toString(){\n        StringBuilder sb = new StringBuilder();\n        for(int i=0; i<n; i++){\n            sb.append(p[i]+\" \");\n        }\n        return sb.toString();\n    }\n}  \n    void run() throws Exception\n    {\n        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        out = new PrintWriter(System.out);\n        \n        long s = System.currentTimeMillis();\n        solve();\n        out.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    private int lenbuf = 0, ptrbuf = 0;\n    \n    private int readByte()\n    {\n        if(lenbuf == -1)throw new InputMismatchException();\n        if(ptrbuf >= lenbuf){\n            ptrbuf = 0;\n            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n            if(lenbuf <= 0)return -1;\n        }\n        return inbuf[ptrbuf++];\n    }\n    \n    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n    \n    private double nd() { return Double.parseDouble(ns()); }\n    private char nc() { return (char)skip(); }\n    \n    private String ns()\n    {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while(!(isSpaceChar(b) && b != ' ')){\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n    \n    private char[] ns(int n)\n    {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while(p < n && !(isSpaceChar(b))){\n            buf[p++] = (char)b;\n            b = readByte();\n        }\n        return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n    \n    private char[][] nm(int n, int m)\n    {\n        char[][] map = new char[n][];\n        for(int i = 0;i < n;i++)map[i] = ns(m);\n        return map;\n    }\n    \n    private int[] na(int n)\n    {\n        int[] a = new int[n];\n        for(int i = 0;i < n;i++)a[i] = ni();\n        return a;\n    }\n    \n    private int ni()\n    {\n        int num = 0, b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private long nl()\n    {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }\n \n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class NewYearAndCurling {\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\tStringTokenizer t = new StringTokenizer(in.readLine());\n\t\tint N = Integer.parseInt(t.nextToken());\n\t\tint R = Integer.parseInt(t.nextToken());\n\t\tint[] x = new int[N];\n\t\tt = new StringTokenizer(in.readLine());\n\t\tfor(int i = 0; i < N; ++i)\n\t\t\tx[i] = Integer.parseInt(t.nextToken());\n\t\tdouble[] y = new double[N];\n\t\tfor(int i = 0; i < N; ++i) {\n\t\t\tdouble max = R;\n\t\t\tfor(int j = 0; j < i; ++j ) {\n\t\t\t\tint xDiff = Math.abs(x[i] - x[j]);\n\t\t\t\tif(xDiff <= 2 * R)\n\t\t\t\t\tmax = Math.max(max, y[j] + Math.sqrt(4*R*R - xDiff*xDiff));\n\t\t\t}\n\t\t\ty[i] = max;\n\t\t}\n\t\tout.print(y[0]);\n\t\tfor(int i = 1; i < N; ++i)\n\t\t\tout.print(\" \" + y[i]);\n\t\tout.println();\n\t\tin.close();\n\t\tout.close();\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author kamranmaharov\n */\npublic class Main {\n\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        int n = Integer.parseInt(line[0]);\n        int r = Integer.parseInt(line[1]);\n        \n        line = in.readLine().split(\" \");\n        int[] x = new int[n+1];\n        double[] y = new double[n+1];\n        \n        for (int i=1; i<=n; ++i) {\n            x[i] = Integer.parseInt(line[i-1]);\n            double maxy = -1.0;\n            for (int j=1; j<i; ++j) {\n                double x2 = x[i];\n                double x1 = x[j];\n                double y1 = y[j];\n                \n                double a = 1;\n                double b = -2 * y1;\n                double c = x1 * x1 + x2 * x2 - 2 * x1 * x2 + y1 * y1 - 4.0 * r * r;\n                \n                double D = b * b - 4 * a * c;\n                //System.out.println(i + \" \" + j + \" \" + D);\n                if (D >= 0) {\n                    double y2 = (-b + Math.sqrt(D)) / (2 * a);\n                    maxy = Math.max(maxy, y2);\n                }\n            }\n            if (maxy < 0) {\n                maxy = r;\n            }\n            y[i] = maxy;\n            if (i>1) {System.out.print(\" \");}\n            System.out.printf(\"%.13f\", y[i]);\n        }\n        System.out.println();\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\tpublic static String taskName = \"\";\n\n\tpublic class Task {\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint r = in.nextInt();\n\t\t\tint[] x = new int[n];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tx[i] = in.nextInt();\n\n\t\t\tdouble[] y = new double[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\ty[i] = r;\n\t\t\t\tfor(int j = 0; j < i; j++) {\n\t\t\t\t\tint dx = Math.abs(x[i] - x[j]);\n\t\t\t\t\tif(dx <= 2 * r)\n\t\t\t\t\t\ty[i] = Math.max(y[i], y[j] + Math.abs(Math.sqrt(4 * r * r - dx * dx)));\n\t\t\t\t}\n\t\t\t\tSystem.out.print(y[i] + \" \");\n\t\t\t}\n\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tif(!taskName.isEmpty()) {\n\t\t\tSystem.setIn(new BufferedInputStream(new FileInputStream(taskName + \".in\")));\n\t\t\tSystem.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(taskName + \".out\"))));\n\t\t}\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\tMain main = new Main();\n\t\tmain.run(in, out);\n\t\tout.close();\n\t}\n\n\tpublic void run(InputReader in, PrintWriter out) {\n\t\tTask solver = new Task();\n\t\tsolver.solve(1, in, out);\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\treturn tokenizer.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 double nextShort() {\n\t\t\treturn Short.parseShort(next());\n\t\t}\n\n\t\tpublic double nextByte() {\n\t\t\treturn Byte.parseByte(next());\n\t\t}\n\n\t\tpublic double nextFloat() {\n\t\t\treturn Float.parseFloat(next());\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class C {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner qwe = new Scanner(System.in);\n\t\tint n = qwe.nextInt();\n\t\tdouble r = qwe.nextDouble();\n\t\t\n\t\tdouble[] fy = new double[n];\n\t\tArrays.fill(fy, r);\n\t\t\n\t\tdouble[] xs = new double[n];\n\t\tfor (int i = 0; i < xs.length; i++) {\n\t\t\txs[i] = qwe.nextDouble();\n\t\t}\n\t\t\n\t\tfor(int i =0; i < n; i++){\n\t\t\t\n\t\t\tfor(int j = i+1; j < n; j++){\n\t\t\t\tdouble dx = xs[j]-xs[i];\n\t\t\t\tif(Math.abs(dx) > 2*r) continue;\n\t\t\t\tfy[j] = Math.max(fy[j], Math.sqrt(4*r*r-dx*dx)+fy[i]);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tStringBuilder stb = new StringBuilder();\n\t\tfor (int i = 0; i < xs.length; i++) {\n\t\t\tstb.append(fy[i]+\" \");\n\t\t}\n\t\tSystem.out.println(stb);\n\t}\n\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemC {\n\tpublic static void main(String[] args) {\n\t\tFastScanner input = new FastScanner();\n\t\tint n = input.nextInt();\n\t\tint radius = input.nextInt();\n\t\tArrayList<Integer> diskXToFall = new ArrayList<Integer>();\n\t\tfor (int a = 0; a < n; a++) {\n\t\t\tdiskXToFall.add(input.nextInt());\n\t\t}\n\t\tArrayList<P> stationaryDisks = new ArrayList<P>();\n\t\tfor (int a = 0; a < n; a++) {\n\t\t\tdouble highCollision = radius;\n\t\t\tfor (P i : stationaryDisks) {\n\t\t\t\tif (Math.abs(diskXToFall.get(a) - i.x) - 1e-8 <= 2 * radius) {\n\t\t\t\t\tdouble hypot = 2 * radius;\n\t\t\t\t\tdouble leg = Math.abs(diskXToFall.get(a) - i.x);\n\t\t\t\t\tdouble yOffset = Math.sqrt(Math.abs(hypot * hypot - leg * leg));\n\t\t\t\t\thighCollision = Math.max(highCollision, yOffset + i.y);\n\t\t\t\t}\n\t\t\t}\n\t\t\tstationaryDisks.add(new P(diskXToFall.get(a), highCollision));\n\t\t}\n\t\tfor(int a = 0; a < n; a++) {\n\t\t\tSystem.out.print(stationaryDisks.get(a).y + \" \");\n\t\t}\n\t\t\n\n\t}\n\n\tstatic class P implements Comparable<P> {\n\t\tfinal double x, y;\n\n\t\tP(double x, double y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tP sub(P that) {\n\t\t\treturn new P(x - that.x, y - that.y);\n\t\t}\n\n\t\tP add(P that) {\n\t\t\treturn new P(x + that.x, y + that.y);\n\t\t}\n\n\t\tdouble dot(P that) {\n\t\t\treturn x * that.x + y * that.y;\n\t\t}\n\n\t\tP scale(double s) {\n\t\t\treturn new P(x * s, y * s);\n\t\t}\n\n\t\t// Use hypot() only if intermediate overflow must be avoided; very slow\n\t\tdouble length() {\n\t\t\treturn sqrt(x * x + y * y);\n\t\t}\n\n\t\tdouble length2() {\n\t\t\treturn x * x + y * y;\n\t\t}\n\n\t\tP leftNormal() {\n\t\t\treturn new P(-y, x);\n\t\t} // rotateCCW(90deg)\n\n\t\tP rightNormal() {\n\t\t\treturn new P(y, -x);\n\t\t} // rotateCW(90deg)\n\n\t\tP normalize() {\n\t\t\tdouble n = length();\n\t\t\treturn n > 0 ? new P(x / n, y / n) : origin();\n\t\t}\n\n\t\tP scaleToLength(double l) {\n\t\t\treturn normalize().scale(l);\n\t\t}\n\n\t\tP project(P a) {\n\t\t\treturn scale(a.dot(this) / length2());\n\t\t}\n\n\t\tP reflect(P a) {\n\t\t\treturn project(a).scale(2.0).sub(a);\n\t\t}\n\n\t\t// use if sin, cos are known\n\t\tP rotateCCW(double sinT, double cosT) {\n\t\t\treturn new P(x * cosT - y * sinT, x * sinT + y * cosT);\n\t\t}\n\n\t\tP rotateCW(double sinT, double cosT) {\n\t\t\treturn rotateCCW(-sinT, cosT);\n\t\t}\n\n\t\tP rotate(double theta) {\n\t\t\treturn rotateCCW(sin(theta), cos(theta));\n\t\t}\n\n\t\t// angle to horizontal (1, 0); result is in [-pi, pi] rad or (-180-180) deg\n\t\tdouble theta() {\n\t\t\treturn atan2(y, x);\n\t\t}\n\n\t\t// angle between two vectors, result is in [0, pi] rad (0-180 deg)\n\t\tdouble angleTo(P a) {\n\t\t\treturn acos(this.dot(a) / this.length() / a.length());\n\t\t}\n\n\t\tboolean isOrigin() {\n\t\t\treturn x == 0 && y == 0;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"(%f,%f)\", this.x, this.y);\n\t\t}\n\n\t\tstatic P read(Scanner s) {\n\t\t\treturn new P(s.nextDouble(), s.nextDouble());\n\t\t}\n\n\t\tstatic P origin() {\n\t\t\treturn new P(0, 0);\n\t\t}\n\n\t\tdouble det(P that) {\n\t\t\treturn this.x * that.y - this.y * that.x;\n\t\t}\n\n\t\tdouble crossproduct(P that) {\n\t\t\treturn this.det(that);\n\t\t}\n\n\t\tP half(P q) {\n\t\t\treturn normalize().add(q.normalize());\n\t\t}\n\n\t\tdouble dist(P to) {\n\t\t\treturn sub(to).length();\n\t\t}\n\n\t\tdouble signedParallelogramArea(P b, P c) {\n\t\t\treturn (b.sub(this).crossproduct(c.sub(this)));\n\t\t}\n\n\t\tboolean isCollinearWith(P b, P c) {\n\t\t\treturn abs(signedParallelogramArea(b, c)) <= EPS;\n\t\t}\n\n\t\t// is going from this to b to c a CCW turn? Do not use if points may be\n\t\t// collinear\n\t\tboolean isCCW(P b, P c) {\n\t\t\treturn signedParallelogramArea(b, c) > 0;\n\t\t}\n\n\t\tdouble signedTriangleArea(P b, P c) {\n\t\t\treturn signedParallelogramArea(b, c) / 2.0;\n\t\t}\n\n\t\t// memory-optimized version of this.sub(to).length2() that avoids an\n\t\t// intermediate object\n\t\tdouble dist2(P to) {\n\t\t\tdouble dx = this.x - to.x;\n\t\t\tdouble dy = this.y - to.y;\n\t\t\treturn dx * dx + dy * dy;\n\t\t}\n\n\t\t/**\n\t\t * Compute x for a * x + b = 0 and ||x|| = C where 'this' is a. Care must be\n\t\t * taken to handle the case where either a.x or a.y is near zero.\n\t\t */\n\t\tP[] solveDotProductConstrainedByNorm(double b, double C) {\n\t\t\tP a = this;\n\t\t\tif (a.isOrigin())\n\t\t\t\tthrow new Error(\"degenerate case\");\n\n\t\t\tboolean transpose = abs(a.x) > abs(a.y);\n\t\t\ta = transpose ? new P(a.y, a.x) : a;\n\n\t\t\tDouble[] x = solvequadratic(a.length2(), 2.0 * b * a.x, b * b - a.y * a.y * C * C);\n\t\t\tP[] p = new P[x.length];\n\t\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\t\tdouble x1 = x[i];\n\t\t\t\tdouble x2 = ((-b - a.x * x1) / a.y);\n\t\t\t\tp[i] = transpose ? new P(x2, x1) : new P(x1, x2);\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(P that) {\n\t\t\tif (abs(this.x - that.x) > EPS)\n\t\t\t\treturn Double.compare(this.x, that.x);\n\t\t\treturn Double.compare(this.y, that.y);\n\t\t}\n\t}\n\n\tstatic class HP extends P { // Hashable Point\n\t\tHP(double x, double y) {\n\t\t\tsuper(x, y);\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\treturn Double.hashCode(x + 32768 * y);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object _that) {\n\t\t\tHP that = (HP) _that;\n\t\t\treturn this.x == that.x && this.y == that.y;\n\t\t}\n\t}\n\n\t/**\n\t * Sort points by polar angle relative to center, using trig. This is a\n\t * counter-clockwise sort with zero at 3 o'clock.\n\t */\n\tstatic Comparator<P> makePolarAngleComparatorTrig(final P center) {\n\t\treturn new Comparator<P>() {\n\t\t\tpublic int compare(P a, P b) {\n\t\t\t\tdouble thetaa = a.sub(center).theta();\n\t\t\t\tdouble thetab = b.sub(center).theta();\n\t\t\t\tif (thetaa < 0)\n\t\t\t\t\tthetaa += 2 * PI;\n\t\t\t\tif (thetab < 0)\n\t\t\t\t\tthetab += 2 * PI;\n\t\t\t\tint c = Double.compare(thetaa, thetab);\n\t\t\t\tif (c != 0)\n\t\t\t\t\treturn c;\n\t\t\t\treturn Double.compare(b.x, a.x); // arbitrary tie-breaker\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Sort points by polar angle relative to center, w/o trig. This is a\n\t * counter-clockwise sort with zero at 3 o'clock.\n\t */\n\tstatic Comparator<P> makePolarAngleComparator(final P center) {\n\t\treturn new Comparator<P>() {\n\t\t\tpublic int compare(P a, P b) {\n\t\t\t\t// orientation() requires that a and b lie in the same half-plane\n\t\t\t\tif (a.y >= center.y && b.y < center.y)\n\t\t\t\t\treturn -1;\n\t\t\t\tif (b.y >= center.y && a.y < center.y)\n\t\t\t\t\treturn 1;\n\t\t\t\tint orientation = (int) Math.signum(center.signedParallelogramArea(b, a));\n\t\t\t\tif (orientation != 0)\n\t\t\t\t\treturn orientation;\n\t\t\t\treturn Double.compare(b.x, a.x); // arbitrary tie-breaker\n\t\t\t}\n\t\t};\n\t}\n\n\t/*\n\t * Solve a * x^2 + b * x + c == 0 Returns 0, 1, or 2 solutions. If 2 solutions\n\t * x1, x2, guarantees that x1 < x2\n\t */\n\tstatic Double[] solvequadratic(double a, double b, double c) {\n\t\tdouble D = b * b - 4 * a * c;\n\t\tif (D < -EPS)\n\t\t\treturn new Double[] {};\n\t\tD = max(D, 0);\n\t\tif (D == 0)\n\t\t\treturn new Double[] { -b / 2.0 / a };\n\t\tdouble d = sqrt(D);\n\t\t// Numerically more stable, see\n\t\t// https://en.wikipedia.org/wiki/Loss_of_significance#A_better_algorithm\n\t\tif (signum(b) == 0)\n\t\t\treturn new Double[] { d / 2.0 / a, -d / 2.0 / a };\n\t\tdouble x1 = (-b - signum(b) * d) / (2 * a);\n\t\tdouble x2 = c / (a * x1);\n\t\treturn new Double[] { Math.min(x1, x2), Math.max(x1, x2) };\n\t}\n\n\t/*\n\t * The Line/Circle classes provide a number of methods that require dealing with\n\t * floating point precision issues. Default EPS to a suitable value, such as\n\t * 1e-6, which should work for many problems in which the input coordinates are\n\t * in integers and subsequently inexact floating point values are being\n\t * computed.\n\t */\n\tstatic double EPS = 1e-6;\n\n\t/*\n\t * A line denoted by two points p and q. For internal computations, we use the\n\t * parametric representation of the line as p + t d where d = q - p. For\n\t * convenience, we compute and store d in the constructor. Most methods hide the\n\t * parametric representation of the line, but it is exposed via\n\t * getPointFromParameter and intersectionParameters for those problems that need\n\t * it.\n\t *\n\t * The line may be interpreted either as a line segment denoted by the two end\n\t * points, or as the infinite line determined by these two points. Intersection\n\t * methods are provided for both cases.\n\t */\n\tstatic class Line {\n\t\tP p, q, d;\n\n\t\tLine(P p, P q) {\n\t\t\tthis.p = p;\n\t\t\tthis.q = q;\n\t\t\td = q.sub(p);\n\t\t}\n\n\t\tP getPointFromParameter(double t) {\n\t\t\treturn p.add(d.scale(t));\n\t\t}\n\n\t\t// reflect vector across vector (as if line originated at (0, 0))\n\t\tP reflect(P d2) {\n\t\t\treturn d.reflect(d2);\n\t\t}\n\n\t\t// reflect point across (infinite) line\n\t\tP reflectPoint(P r) {\n\t\t\treturn reflect(r.sub(p)).add(p);\n\t\t}\n\n\t\t// project p onto this (infinite) line. Returns point on line\n\t\tP project(P a) {\n\t\t\treturn p.add(d.project(a.sub(p)));\n\t\t}\n\n\t\t// return distance of point P from this (infinite) line.\n\t\tdouble distance(P a) {\n\t\t\treturn project(a).dist(a);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"[%s => %s]\", p, q);\n\t\t}\n\n\t\t/*\n\t\t * Point of intersection of this line segment with another line segment. Returns\n\t\t * only points that lie inside both line segments, else null.\n\t\t *\n\t\t * Result may include points \"just outside\" the bounds, given EPS.\n\t\t */\n\t\tP intersectsInBounds(Line l) {\n\t\t\tdouble[] st = intersectionParameters(l);\n\t\t\tif (st == null)\n\t\t\t\treturn null;\n\n\t\t\t// check that point of intersection is in direction 'd'\n\t\t\t// and within segment bounds\n\t\t\tdouble s = st[0];\n\t\t\tdouble t = st[1];\n\t\t\tif (s >= -EPS && s <= 1 + EPS && -EPS <= t && t <= 1 + EPS)\n\t\t\t\treturn getPointFromParameter(s);\n\n\t\t\treturn null;\n\t\t}\n\n\t\t/*\n\t\t * Point of intersection of this (infinite) line with other (infinite) line.\n\t\t * Return null if collinear.\n\t\t */\n\t\tP intersects(Line l) {\n\t\t\tdouble[] st = intersectionParameters(l);\n\t\t\tif (st != null)\n\t\t\t\treturn getPointFromParameter(st[0]);\n\t\t\treturn null;\n\t\t}\n\n\t\t/*\n\t\t * Intersect this line with that line Solves: this.p + s * this.d == l.p + t l.d\n\t\t * Return null if lines are collinear Else returns [s, t].\n\t\t */\n\t\tdouble[] intersectionParameters(Line l) {\n\t\t\tP dneg = p.sub(q);\n\t\t\tdouble D = l.d.det(dneg);\n\t\t\t// Use Cramer's rule; see text\n\t\t\tif (D == 0.0)\n\t\t\t\treturn null;\n\n\t\t\tP rp = p.sub(l.p);\n\t\t\treturn new double[] { l.d.det(rp) / D, rp.det(dneg) / D };\n\t\t}\n\n\t\t/*\n\t\t * Compute points of intersection of this infinite line with a circle. Computes\n\t\t * projection 'x' of c.c onto line, then computes x +/- d.scaleToLength(h) where\n\t\t * h is computed via Pythagoras. Sorted by decreasing 't' (as would be used in\n\t\t * getPointFromParameter)\n\t\t *\n\t\t * May return two points even if line is a tangent.\n\t\t */\n\t\tP[] intersectsCircle(Circle c) {\n\t\t\tP x = project(c.c);\n\t\t\tdouble D = x.dist(c.c);\n\t\t\t// outside by more than EPS\n\t\t\tif (D > c.R + EPS)\n\t\t\t\treturn new P[0];\n\t\t\tdouble h = sqrt(max(0, c.R * c.R - D * D));\n\t\t\tif (h == 0)\n\t\t\t\treturn new P[] { x }; // EPS (!?)\n\t\t\treturn new P[] { x.add(d.scaleToLength(h)), x.add(d.scaleToLength(-h)) };\n\t\t}\n\n\t\t/*\n\t\t * Compute points of intersection of this infinite line with a circle.\n\t\t *\n\t\t * Solves a + t * b = c + r subject to ||r|| = R Returns zero, one, or two\n\t\t * points on the periphery, e.g. c + r[0,1], sorted by decreasing 't'.\n\t\t * Alternative version which requires solving quadratic equation.\n\t\t *\n\t\t * Careful: set EPS if you need to handle round-off error in discriminant.\n\t\t */\n\t\tP[] intersectsCircleAlternative(Circle c) {\n\t\t\tP ca = c.c.sub(p);\n\t\t\tP d = q.sub(p);\n\t\t\tDouble[] t = solvequadratic(d.length2(), -2 * d.dot(ca), ca.length2() - c.R * c.R);\n\t\t\tP[] r = new P[t.length];\n\t\t\tfor (int i = 0; i < t.length; i++)\n\t\t\t\tr[i] = p.add(d.scale(t[i]));\n\t\t\treturn r;\n\t\t}\n\n\t\t/**\n\t\t * Is r contained within the line segment spanned by p/q, including their\n\t\t * endpoints?\n\t\t */\n\t\tboolean isInBounds(P r) {\n\t\t\treturn abs(p.dist(q) - p.dist(r) - q.dist(r)) <= EPS;\n\t\t}\n\n\t\t/**\n\t\t * Is r on the infinite line?\n\t\t */\n\t\tboolean isOnLine(P r) {\n\t\t\treturn r.isCollinearWith(p, q);\n\t\t}\n\t}\n\n\t/**\n\t * Alternative line implementation using the \"general form\" equation.\n\t *\n\t * a * x + b * y + c = 0\n\t *\n\t * This is provided for problems in which a line may be given in general form in\n\t * the input. Compared to class Line, GLine: - is shorter, particularly when\n\t * only line/line and line/circle intersections are required. - does not support\n\t * those functions of Line that relate to LineSegment.\n\t */\n\tstatic class GLine {\n\t\t// we represent a, b as a vector to benefit from the available dot/det routines.\n\t\tP n; // n = new P(a, b) --- this is the (right) normal vector to the line\n\t\tdouble c;\n\n\t\tGLine(double a, double b, double c) {\n\t\t\tthis.n = new P(a, b);\n\t\t\tif (a == 0 && b == 0)\n\t\t\t\tthrow new Error(\"a and b cannot both be zero\");\n\t\t\tthis.c = c;\n\t\t}\n\n\t\tGLine(P p, P q) {\n\t\t\tthis(p.y - q.y, q.x - p.x, p.det(q));\n\t\t}\n\n\t\tP intersects(GLine that) {\n\t\t\tdouble D = n.det(that.n);\n\t\t\tif (D == 0.0)\n\t\t\t\treturn null;\n\t\t\treturn new P((this.n.y * that.c - that.n.y * this.c) / D, (that.n.x * this.c - this.n.x * that.c) / D);\n\t\t}\n\n\t\tdouble signedDistance(P p) {\n\t\t\treturn (n.dot(p) + c) / n.length();\n\t\t}\n\n\t\tdouble distance(P p) {\n\t\t\treturn abs(signedDistance(p));\n\t\t}\n\n\t\t// checks if on (infinite) line.\n\t\tboolean isOnLine(P p) {\n\t\t\treturn signedDistance(p) <= EPS;\n\t\t}\n\n\t\t// checks if on the same side, no EPS\n\t\tboolean onSameSide(P p, P q) {\n\t\t\treturn signum(signedDistance(p)) == signum(signedDistance(q));\n\t\t}\n\n\t\t// angle of inclination to horizontal; result is in [0, pi] rad\n\t\t// XXX untested\n\t\tdouble theta() {\n\t\t\tdouble angle = atan2(n.x, -n.y);\n\t\t\treturn angle < 0 ? (angle + PI) : angle;\n\t\t}\n\n\t\t// XXX untested\n\t\tboolean parallelWith(GLine that) {\n\t\t\treturn n.det(that.n) <= EPS;\n\t\t}\n\n\t\t// XXX untested\n\t\tboolean perpendicularTo(GLine that) {\n\t\t\treturn n.dot(that.n) <= EPS;\n\t\t}\n\n\t\t// circle-line intersection, refactored from\n\t\t// https://e-maxx-eng.appspot.com/geometry/circle-line-intersection.html\n\t\tP[] intersectsCircle(Circle C) {\n\t\t\t// shift line to center, this is undone by adding C.c before returning.\n\t\t\tdouble c = n.dot(C.c) + this.c;\n\t\t\tdouble n2 = n.length2();\n\t\t\tdouble r = C.R;\n\n\t\t\tP p = n.scale(-c / n2).add(C.c); // undo shift to center\n\t\t\tif (c * c > r * r * n2 + EPS) {\n\t\t\t\treturn new P[] {};\n\t\t\t} else if (abs(c * c - r * r * n2) < EPS) {\n\t\t\t\treturn new P[] { p };\n\t\t\t} else {\n\t\t\t\tdouble d = r * r - c * c / n2;\n\t\t\t\tdouble m = sqrt(d / n2);\n\t\t\t\tP q = n.rightNormal().scale(m);\n\t\t\t\treturn new P[] { p.add(q), p.sub(q) };\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"Line:(n=%s C=%f)\", n, c);\n\t\t}\n\t}\n\n\tstatic class Circle {\n\t\tP c;\n\t\tdouble R;\n\n\t\tCircle(P c, double R) {\n\t\t\tthis.c = c;\n\t\t\tthis.R = R;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"{%s, %.03f}\", c, R);\n\t\t}\n\n\t\t/* Is this point inside the circle */\n\t\tboolean isInside(P p) {\n\t\t\treturn R > p.dist(c) - EPS;\n\t\t}\n\n\t\t/* Is this point on the circle's periphery */\n\t\tboolean isOnCircle(P p) {\n\t\t\treturn abs(p.dist(c) - R) <= EPS;\n\t\t}\n\n\t\t/*\n\t\t * a line segment is outside a circle if both end points are outside and if any\n\t\t * intersection points are outside the bounds of the line segment.\n\t\t */\n\t\tboolean isOutside(Line l) {\n\t\t\tif (isInside(l.p) || isInside(l.q))\n\t\t\t\treturn false;\n\t\t\tP[] _is = l.intersectsCircle(this);\n\t\t\tif (_is.length > 1)\n\t\t\t\tfor (P is : _is)\n\t\t\t\t\tif (l.isInBounds(is))\n\t\t\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\t/* Returns the tangent lines that the point p makes with this circle, if any. */\n\t\tLine[] tangentLines(P p) {\n\t\t\t// Let c +/- r be the tangent points. Then there's a 'd' such that\n\t\t\t// p + d - r = c\n\t\t\t// Since d r = 0, we multiply by r and get\n\t\t\t// (p - c) r - ||r|| = 0 subject to ||r|| = R\n\t\t\tP[] r = p.sub(c).solveDotProductConstrainedByNorm(-R * R, R);\n\t\t\tLine[] tangents = new Line[r.length];\n\t\t\tfor (int i = 0; i < tangents.length; i++)\n\t\t\t\ttangents[i] = new Line(p, c.add(r[i]));\n\t\t\treturn tangents;\n\t\t}\n\n\t\t/*\n\t\t * Compute points of intersection of this circle (c1, r1) with that circle (c2,\n\t\t * r2). Model as triangle equation m = c2 - c1 = r1 - r2 m = r1 - r2 -> m^2 =\n\t\t * r1^2 + r2^2 - 2 r1 r2 (squaring) -> r1 r2 = (r1^2 + r2^2 - m^2)/2 and by\n\t\t * multiplying by r1 we obtain m = r1 - r2 -> m r1 = r1^2 - r1 r2 -> m r1 = r1^2\n\t\t * - (r1^2 + r2^2 - m^2)/2 -> m r1 + (r2^2 - r1^2 - m^2)/2 = 0 and ready for\n\t\t * solveDotProductConstrainedByNorm\n\t\t *\n\t\t * Note that if the circles are (apprx) touching, this function may return 0, 1,\n\t\t * or 2 intersection points, depending on which side of 0 the discriminant\n\t\t * falls. You will not get NaN.\n\t\t *\n\t\t * If the circles coincidence (same center and radius) this will throw an\n\t\t * 'degenerate case' error in solveDotProductConstrainedByNorm !!!\n\t\t */\n\t\tP[] intersectsCircle(Circle that) {\n\t\t\tdouble r1 = this.R;\n\t\t\tdouble r2 = that.R;\n\t\t\tP m = that.c.sub(this.c);\n\t\t\tP[] r1sol = m.solveDotProductConstrainedByNorm((r2 * r2 - r1 * r1 - m.length2()) / 2, r1);\n\t\t\t// compute [c +/- r1] to obtain intersection points\n\t\t\tP[] is = new P[r1sol.length];\n\t\t\tfor (int i = 0; i < r1sol.length; i++)\n\t\t\t\tis[i] = this.c.add(r1sol[i]);\n\t\t\treturn is;\n\t\t}\n\n\t\t/*\n\t\t * Shorter version of intersectsCircle that solves quadratic equation inline.\n\t\t * Assumes there are 2 intersection points. The vector 'mid' is where the\n\t\t * altitude of the triangle formed by the centers and the intersection point\n\t\t * hits the line connecting the centers. Its length is e. midn is normal to it\n\t\t * and its length is f.\n\t\t */\n\t\tP[] intersectsCircleAlternative(Circle that) {\n\t\t\tP m = that.c.sub(this.c);\n\t\t\tdouble b = this.R * this.R;\n\t\t\t// div-by-zero if circles share center\n\t\t\tdouble e = (m.length2() + b - that.R * that.R) / 2 / m.length();\n\t\t\tdouble f = sqrt(b - e * e); // NaN if circles don't intersect\n\t\t\tP[] is = new P[2];\n\t\t\tP mid = this.c.add(m.scaleToLength(e));\n\t\t\tP midn = m.rightNormal();\n\t\t\tfor (int i = 0; i < is.length; i++) {\n\t\t\t\tis[i] = mid.add(midn.scaleToLength(f));\n\t\t\t\tf *= -1;\n\t\t\t}\n\t\t\treturn is;\n\t\t}\n\n\t\t// returns true if this circle is outside that circle\n\t\tboolean isOutside(Circle that) {\n\t\t\treturn this.c.dist(that.c) > (this.R + that.R);\n\t\t}\n\n\t\t// returns true if this circle is entirely contained inside that circle\n\t\tboolean isContainedIn(Circle that) {\n\t\t\t// extend line from that.c to this.c by radius R\n\t\t\tP m = this.c.sub(that.c);\n\t\t\treturn that.isInside(this.c.add(m.scaleToLength(this.R)));\n\t\t}\n\n\t\t/* Construct smallest circle that circumscribes 2 points a and b. */\n\t\tstatic Circle getCircumCircle(P a, P b) {\n\t\t\tP c = a.add(b).scale(.5);\n\t\t\treturn new Circle(c, c.dist(a));\n\t\t}\n\n\t\t/* Construct circle circumscribed by 3 points a, b, c */\n\t\tstatic Circle getCircumCircle(P a, P b, P c) {\n\t\t\tP B = b.sub(a);\n\t\t\tP C = c.sub(a);\n\t\t\tdouble d = 2 * B.crossproduct(C);\n\t\t\tif (abs(d) < EPS) // points are collinear\n\t\t\t\treturn getCircumCircle(new P(min(a.x, min(b.x, c.x)), min(a.y, min(b.y, c.y))),\n\t\t\t\t\t\tnew P(max(a.x, max(b.x, c.x)), max(a.y, max(b.y, c.y))));\n\n\t\t\tdouble z1 = B.length2();\n\t\t\tdouble z2 = C.length2();\n\t\t\tP cc = new P(C.y * z1 - B.y * z2, B.x * z2 - C.x * z1).scale(1.0 / d);\n\t\t\treturn new Circle(cc.add(a), cc.length());\n\t\t}\n\n\t\t/*\n\t\t * Find minimum enclosing circle for a set of points. Peter, we need a source\n\t\t * for this algorithm and its expected complexity.\n\t\t */\n\t\tstatic Circle minEnclosingCircle(P[] p) {\n\t\t\tif (p.length == 0)\n\t\t\t\treturn new Circle(new P(0, 0), 0);\n\t\t\tif (p.length == 1)\n\t\t\t\treturn new Circle(p[0], 0);\n\t\t\tCollections.shuffle(Arrays.asList(p));\n\t\t\tCircle circle = getCircumCircle(p[0], p[1]);\n\t\t\tfor (int i = 2; i < p.length; i++) {\n\t\t\t\tif (!circle.isInside(p[i])) {\n\t\t\t\t\tcircle = getCircumCircle(p[0], p[i]);\n\t\t\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\t\t\tif (!circle.isInside(p[j])) {\n\t\t\t\t\t\t\tcircle = getCircumCircle(p[j], p[i]);\n\t\t\t\t\t\t\tfor (int k = 0; k < j; k++) {\n\t\t\t\t\t\t\t\tif (!circle.isInside(p[k])) {\n\t\t\t\t\t\t\t\t\tcircle = getCircumCircle(p[i], p[j], p[k]);\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\treturn circle;\n\t\t}\n\t}\n\n\t/**\n\t * Some basic operations on Polygons.\n\t */\n\tstatic class Polygon {\n\t\tP[] p; // open form, p[0] connects to p[n-1]\n\n\t\t// Constructors clone original array/collection\n\t\tPolygon(Collection<P> c) {\n\t\t\tthis.p = c.toArray(new P[c.size()]);\n\t\t}\n\n\t\tPolygon(P[] p) {\n\t\t\tthis.p = (P[]) p.clone();\n\t\t}\n\n\t\t/* Absolute of signed triangle areas */\n\t\tdouble signedArea() {\n\t\t\tdouble area = 0.0;\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tarea += p[i].det(p[(i + 1) % p.length]);\n\t\t\t}\n\t\t\treturn area / 2.0;\n\t\t}\n\n\t\tdouble absoluteArea() {\n\t\t\treturn abs(signedArea());\n\t\t}\n\n\t\t/*\n\t\t * Returns an P[] array representing an open shape that is the convex hull of\n\t\t * the given array of points, or null if less than 2 points were given.\n\t\t */\n\t\tpublic Polygon convexHull() {\n\t\t\tif (p.length < 2)\n\t\t\t\treturn null;\n\n\t\t\t// (0) find the lowest point, breaking ties to the right\n\t\t\tfinal P min = Collections.min(Arrays.asList(p), new Comparator<P>() {\n\t\t\t\tpublic int compare(P p1, P p2) {\n\t\t\t\t\tint y = Double.valueOf(p1.y).compareTo(p2.y);\n\t\t\t\t\treturn y != 0 ? y : Double.valueOf(p1.x).compareTo(p2.x);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// (1) sort points by angle from pivot\n\t\t\tArrays.sort(p, new Comparator<P>() {\n\t\t\t\tpublic int compare(P p1, P p2) {\n\t\t\t\t\tdouble o = min.signedParallelogramArea(p1, p2); // crossproduct\n\t\t\t\t\tif (o != 0)\n\t\t\t\t\t\treturn -(int) Math.signum(o);\n\n\t\t\t\t\t// if collinear, use distance to break tie\n\t\t\t\t\treturn Double.valueOf(min.dist(p1)).compareTo(min.dist(p2));\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// (3) create stack\n\t\t\tStack<P> hull = new Stack<P>();\n\t\t\tassert p[0] == min;\n\t\t\thull.push(p[0]);\n\t\t\thull.push(p[1]);\n\n\t\t\t// (4) select points that maintain left turns\n\t\t\tfor (int i = 2; i < p.length; i++) {\n\t\t\t\tP next = p[i];\n\t\t\t\twhile (hull.size() >= 2) {\n\t\t\t\t\tP snd = hull.get(hull.size() - 2);\n\t\t\t\t\tP top = hull.peek();\n\t\t\t\t\tif (snd.isCCW(top, next)) // keep\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\thull.pop(); // discard\n\t\t\t\t}\n\t\t\t\t// keep current point\n\t\t\t\thull.push(next);\n\t\t\t}\n\t\t\treturn new Polygon(hull);\n\t\t}\n\n\t\t/*\n\t\t * \"Point-in-Polygon\" PIP tests. Return true if point is contained in this\n\t\t * polygon\n\t\t *\n\t\t * All of these tests may return 0 or 1 for points on the boundary. A separate\n\t\t * test is required to determine if a point is on the boundary.\n\t\t */\n\t\tpublic boolean contains(P q) {\n\t\t\treturn contains_WN(q);\n\t\t}\n\n\t\t/*\n\t\t * Crossing-number based algorith due to Wm. Randolph Franklin. Works only for\n\t\t * simple polygons.\n\t\t */\n\t\tprivate boolean contains_CN(P q) {\n\t\t\tboolean c = false;\n\t\t\tfor (int i = 0, j = p.length - 1; i < p.length; j = i++) {\n\t\t\t\tif ((((p[i].y <= q.y) && (q.y < p[j].y)) || ((p[j].y <= q.y) && (q.y < p[i].y)))\n\t\t\t\t\t\t&& (q.x < (p[j].x - p[i].x) * (q.y - p[i].y) / (p[j].y - p[i].y) + p[i].x))\n\t\t\t\t\tc = !c;\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\t/*\n\t\t * Winding numbers based algorithm, which also works for self-intersecting\n\t\t * polygons. http://geomalgorithms.com/a03-_inclusion.html describes this as the\n\t\t * always preferred algorithm.\n\t\t *\n\t\t * Return: wn = the winding number (=0 only when P is outside)\n\t\t */\n\t\tpublic boolean contains_WN(P q) {\n\t\t\tint wn = 0; // the winding number counter\n\n\t\t\t// loop through all edges of the polygon\n\t\t\tint n = p.length;\n\t\t\tfor (int i = 0; i < n; i++) { // edge from V[i] to V[i+1]\n\t\t\t\tP p = this.p[i], pn = this.p[(i + 1) % n];\n\t\t\t\tif (p.y <= q.y) { // start y <= P.y\n\t\t\t\t\tif (pn.y > q.y) // an upward crossing\n\t\t\t\t\t\tif (p.isCCW(pn, q)) // P left of edge\n\t\t\t\t\t\t\t++wn; // have a valid up intersect\n\t\t\t\t} else { // start y > P.y (no test needed)\n\t\t\t\t\tif (pn.y <= q.y) // a downward crossing\n\t\t\t\t\t\tif (!p.isCCW(pn, q)) // P right of edge\n\t\t\t\t\t\t\t--wn; // have a valid down intersect\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn wn != 0;\n\t\t}\n\n\t\t/**\n\t\t * Is q on the boundary of this polygon?\n\t\t */\n\t\tpublic boolean onBoundary(P q) {\n\t\t\tint n = p.length;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tP pi = this.p[i], pj = this.p[(i + 1) % n];\n\t\t\t\tif (new Line(pi, pj).isInBounds(q))\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn Arrays.toString(p);\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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/*\n public class _908C {\n\n }\n\n */\npublic class _908C {\n  public void solve() throws FileNotFoundException {\n    InputStream inputStream = System.in;\n\n    InputHelper in = new InputHelper(inputStream);\n\n    // actual solution\n    int n = in.readInteger();\n    double r = in.readInteger();\n\n    double[] x = new double[n];\n\n    for (int i = 0; i < n; i++) {\n      x[i] = in.readInteger();\n    }\n\n    double[] ans = new double[n];\n\n    ans[0] = r;\n\n    for (int i = 1; i < n; i++) {\n      double cans = r;\n      for (int j = 0; j < i; j++) {\n        double dis = Math.abs(x[j] - x[i]);\n\n        if (dis <= 2 * r) {\n\n          if (dis == 2 * r) {\n            cans = Math.max(cans, ans[j]);\n            continue;\n          } else if (x[i] == x[j]) {\n            cans = Math.max(cans, ans[j] + 2 * r);\n            continue;\n          }\n          cans = Math.max(cans, ans[j] + Math.sqrt((4 * (r * r)) - dis * dis));\n        }\n      }\n\n      ans[i] = cans;\n    }\n\n    for (int i = 0; i < n; i++) {\n      System.out.print(ans[i] + \" \");\n    }\n\n    // end here\n  }\n\n  public static void main(String[] args) throws FileNotFoundException {\n    (new _908C()).solve();\n  }\n\n  class InputHelper {\n    StringTokenizer tokenizer = null;\n    private BufferedReader bufferedReader;\n\n    public InputHelper(InputStream inputStream) {\n      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);\n      bufferedReader = new BufferedReader(inputStreamReader, 16384);\n    }\n\n    public String read() {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n        try {\n          String line = bufferedReader.readLine();\n          if (line == null) {\n            return null;\n          }\n          tokenizer = new StringTokenizer(line);\n        } catch (IOException e) {\n          e.printStackTrace();\n        }\n      }\n\n      return tokenizer.nextToken();\n    }\n\n    public Integer readInteger() {\n      return Integer.parseInt(read());\n    }\n\n    public Long readLong() {\n      return Long.parseLong(read());\n    }\n  }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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        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            int n = in.nextInt();\n            int r = in.nextInt();\n            int[] xs = new int[n];\n            for (int i = 0; i < n; i++) xs[i] = in.nextInt();\n            double[] ys = new double[n];\n            for (int i = 0; i < n; i++) {\n                int x = xs[i];\n                double y = r;\n                for (int j = 0; j < i; j++) {\n                    y = Math.max(y, calc(xs[j], ys[j], x, r));\n                }\n                ys[i] = y;\n            }\n            for (int i = 0; i < n; i++) {\n                out.printf(\"%.10f \", ys[i]);\n            }\n            out.println();\n        }\n\n        private double calc(int x, double y, int x1, int r) {\n            int dx = Math.abs(x - x1);\n            if (dx > 2 * r) return 0;\n            double dy = Math.sqrt(4 * r * r - dx * dx);\n            return y + dy;\n        }\n\n    }\n\n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public Scanner(InputStream in) {\n            br = new BufferedReader(new InputStreamReader(in), 32768);\n        }\n\n        public String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                return null;\n            }\n        }\n\n        public boolean hasNext() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = nextLine();\n                if (s == null)\n                    return false;\n                st = new StringTokenizer(s);\n            }\n            return true;\n        }\n\n        public String next() {\n            hasNext();\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n\npublic class Codeforces {\n            \n    public static void main(String[] args) throws IOException{\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        final double eps = 1e-7;\n        String toks[] = in.readLine().split(\" \");\n        int n = Integer.parseInt(toks[0]);\n        double r = Double.parseDouble(toks[1]);\n        double x[] = new double[n];\n        toks = in.readLine().split(\" \");\n        for (int i = 0; i < n; i++) {\n            x[i] = Double.parseDouble(toks[i]);\n        }\n        double lo, hi, mid;\n        double y[] = new double[n];\n        y[0] = r;\n        for (int i = 1; i < n; i++) {\n            y[i] = r;\n            for(int j=0; j<i; j++) {\n                lo = y[j]; hi = 2000*2000;\n                while( Math.abs(hi-lo) >= eps ) {\n                    mid = (hi+lo)/2;\n                    if( Math.sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[j]-mid)*(y[j]-mid) ) + eps > 2*r ) {\n                        hi = mid;\n                    } else {\n                        lo = mid;\n                    }\n                }\n                if(Math.sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[j]-lo)*(y[j]-lo) ) < 2*r + eps) {\n                    y[i] = Math.max(y[i], lo);\n                }\n            }\n        }\n        for (double z : y) {\n            System.out.printf(Locale.US, \"%.7f \", z);\n        }\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Aeroui\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        Kattio in = new Kattio(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, Kattio in, PrintWriter out) {\n            int n = in.nextInt();\n            int r = in.nextInt();\n\n            double[] xs = new double[n];\n            double[] ys = new double[n];\n            TreeSet<TaskC.Pair> set = new TreeSet<>();\n            for (int i = 0; i < n; ++i) {\n                xs[i] = in.nextDouble();\n                ys[i] = (double) Integer.MIN_VALUE;\n\n                if (i == 0) { // the first one\n                    out.printf(\"%f\", (double) r);\n                    ys[i] = (double) r;\n                    set.add(new TaskC.Pair(xs[i], ys[i]));\n                } else {\n                    for (TaskC.Pair p : set) {\n                        double maximum = p.x;\n                        double diffX = (xs[i] - maximum) * (xs[i] - maximum);\n\n                        if (diffX <= r * r * 4.0) {\n                            ys[i] = Math.max(ys[i], p.y + Math.sqrt(r * r * 4.0 - diffX));\n                            continue;\n                        }\n                    }\n\n                    if (ys[i] < 0)\n                        ys[i] = (double) r;\n\n                    set.add(new TaskC.Pair(xs[i], ys[i]));\n                    out.printf(\" %f\", ys[i]);\n                }\n            }\n\n        }\n\n        private static class Pair implements Comparable<TaskC.Pair> {\n            double x;\n            double y;\n\n            public Pair(double x, double y) {\n                this.x = x;\n                this.y = y;\n            }\n\n\n            public int compareTo(TaskC.Pair p) {\n                if (this.y - p.y < 0)\n                    return 1;\n\n                return -1;\n            }\n\n        }\n\n    }\n\n    static class Kattio extends PrintWriter {\n        private BufferedReader r;\n        private String line;\n        private StringTokenizer st;\n        private String token;\n\n        public Kattio(InputStream i) {\n            super(new BufferedOutputStream(System.out));\n            r = new BufferedReader(new InputStreamReader(i));\n        }\n\n        public Kattio(InputStream i, OutputStream o) {\n            super(new BufferedOutputStream(o));\n            r = new BufferedReader(new InputStreamReader(i));\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(nextToken());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(nextToken());\n        }\n\n        private String peekToken() {\n            if (token == null)\n                try {\n                    while (st == null || !st.hasMoreTokens()) {\n                        line = r.readLine();\n                        if (line == null) return null;\n                        st = new StringTokenizer(line);\n                    }\n                    token = st.nextToken();\n                } catch (IOException e) {\n                }\n            return token;\n        }\n\n        private String nextToken() {\n            String ans = peekToken();\n            token = null;\n            return ans;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\t\tint n = in.nextInt();\n\t\tdouble r = in.nextInt();\n\t\tdouble[] x = new double[n+1];\n\t\tdouble[] y = new double[n+1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tx[i] = in.nextInt();\n\t\t}\n\t\t\n\t\tint[] lastx = new int[1001];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tdouble s = x[i] - r, e = x[i] + r;\n\t\t\tfor (int j = (int)Math.max(0, s); j <= (int)Math.min(1000, e); j++) {\n\t\t\t\tif (lastx[j] == 0) {\n\t\t\t\t\ty[i] = Math.max(y[i], findY(x[i], x[i], 0 - r, 2 * r));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ty[i] = Math.max(y[i], findY(x[lastx[j]], x[i], y[lastx[j]], 2 * r));\n\t\t\t\t}\n\t\t\t\tlastx[j] = i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tout.println(y[i]);\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tpublic static double findY(double x1, double x2, double y1, double d) {\n\t\treturn Math.max(y1 + Math.sqrt(-1 * Math.pow(x1, 2) + 2 * x1 * x2 + Math.pow(d, 2) - Math.pow(x2, 2)),\n\t\t\t\ty1 - Math.sqrt(-1 * Math.pow(x1, 2) + 2 * x1 * x2 + Math.pow(d, 2) - Math.pow(x2, 2)));\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\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\t}\n\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class c {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint num = in.nextInt();\n\t\tint rad = in.nextInt();\n\t\t\n\t\tint[] start = new int[num];\n\t\tfor(int i=0; i<num; i++)\n\t\t\tstart[i] = in.nextInt();\n\t\t\n\t\t// If you can hack doubles that's dumb\n\t\tdouble[] finalY = new double[num];\n\t\tdouble hyp = rad*2;\n\t\t\n\t\tfor(int cur=0; cur<num; cur++){\n\t\t\t\n\t\t\tdouble stopAt = rad;\n\t\t\tfor(int comp=0; comp<cur; comp++){\n\t\t\t\tif(Math.abs(start[comp]-start[cur]) > rad*2) continue;\n\t\t\t\t\n\t\t\t\tdouble base = Math.abs(start[comp]-start[cur]);\n\t\t\t\tdouble ny = Math.sqrt(hyp*hyp - base*base) + finalY[comp];\n\t\t\t\t\n\t\t\t\tstopAt = Math.max(ny, stopAt);\n\t\t\t}\n\t\t\t\n\t\t\tfinalY[cur] = stopAt;\n\t\t}\n\t\t\n\t\tfor(int i=0; i<num; i++)\n\t\t\tSystem.out.print(finalY[i]+\" \");\n\t\tSystem.out.println();\n\t}\n\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\n\npublic class C {\n\n\tpublic C () {\n\t\tint N = sc.nextInt(); int R = sc.nextInt();\n\t\tint [] X = sc.nextInts();\n\n\t\tdouble [] res = new double [N];\n\t\tfor (int i : rep(N)) {\n\t\t\tres[i] = R;\n\t\t\tfor (int j : rep(i)) {\n\t\t\t\tint D = abs(X[i] - X[j]);\n\t\t\t\tif (D <= 2*R) {\n\t\t\t\t\tdouble H = sqrt(4.0*R*R - 1.0*D*D);\n\t\t\t\t\tres [i] = max(res[i], res[j] + H);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\texit(res);\n\t}\n\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\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next() { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t\tpublic String nextLine() { line = null; return readLine(); }\n\t\t\tpublic String [] nextStrings() { return split(nextLine()); }\n\t\t\tpublic int [] nextInts() {\n\t\t\t\tString [] L = nextStrings();\n\t\t\t\tint [] res = new int [L.length];\n\t\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol() { return index == line.length; }\n\t\t\tprivate String readLine() {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine() {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split(String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build(Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim(String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static void start() { if (t == 0) t = millis(); }\n\t\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t\t} else if (o instanceof Iterable<?>)\n\t\t\t\tfor (Object p : (Iterable<?>) o)\n\t\t\t\t\tappend(b, p, delim);\n\t\t\telse {\n\t\t\t\tif (o instanceof Double)\n\t\t\t\t\to = new java.text.DecimalFormat(\"#.############\").format(o);\n\t\t\t\tb.append(delim).append(o);\n\t\t\t}\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print(Object o, Object ... A) { pw.println(build(o, A)); }\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static void exit() {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(IOUtils.time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis() { return System.currentTimeMillis(); }\n\t\tprivate static String time() { return \"Time: \" + (millis() - t) / 1000.0; }\n\t}\n\tpublic static void main (String[] args) { new C(); IOUtils.exit(); }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\npublic class USACO {\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(reader.readLine(),\" \");\n        int n= Integer.parseInt(st.nextToken());\n        int r= Integer.parseInt(st.nextToken());\n        StringTokenizer st2 = new StringTokenizer(reader.readLine(),\" \");\n        double[][] coord = new double[n][2];\n        for (int i=0;i<n;i++) {\n            coord[i][0] = Integer.parseInt(st2.nextToken());\n            double y=r;\n            for (int j=0;j<i;j++) {\n                if (coord[j][0]<=coord[i][0]+2*r&&coord[j][0]>=coord[i][0]-2*r) {\n                    if (coord[j][1]+Math.sqrt(4*r*r-(coord[i][0]-coord[j][0])*(coord[i][0]-coord[j][0]))>y) {\n                        y=coord[j][1]+Math.sqrt(4*r*r-(coord[i][0]-coord[j][0])*(coord[i][0]-coord[j][0]));\n                    }\n                }\n            }\n            coord[i][1]=y;\n        }\n        for (int i=0;i<n;i++) {\n            System.out.print(coord[i][1]);\n            if (i<n-1) {\n                System.out.print(\" \");\n            } else {\n                System.out.print(\"\\n\");\n            }\n        }\n        reader.close();\n    }\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.Optional;\nimport java.util.Scanner;\nimport java.util.StringJoiner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tMain main = new Main();\n\t\tmain.solveC();\n\t}\n\n\tprivate void solveA() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString str = sc.next();\n\t\tlong answer = str.chars().filter(\n\t\t\t\tasc -> asc == 'a'\n\t\t\t\t\t|| asc == 'i'\n\t\t\t\t\t|| asc == 'u'\n\t\t\t\t\t|| asc == 'e'\n\t\t\t\t\t|| asc == 'o'\n\t\t\t\t\t|| asc == '1'\n\t\t\t\t\t|| asc == '3'\n\t\t\t\t\t|| asc == '5'\n\t\t\t\t\t|| asc == '7'\n\t\t\t\t\t|| asc == '9').count();\n\t\tSystem.out.println(answer);\n\t}\n\n\tprivate void solveB() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\t\tsc.nextLine();\n\t\tchar[][] map = new char[N + 2][M + 2];\n\t\tmap[0] = new char[M + 2];\n\t\tmap[N + 1] = new char[M + 2];\n\t\tint s_r = -1;\n\t\tint s_c = -1;\n\t\tfor (int c = 0; c < M + 2; c++) {\n\t\t\tmap[0][c] = '#';\n\t\t\tmap[N + 1][c] = '#';\n\t\t}\n\t\tfor (int r = 1; r <= N; r++) {\n\t\t\tmap[r][0] = '#';\n\t\t\tString line = sc.nextLine();\n\t\t\tfor (int c = 1; c <= M; c++) {\n\t\t\t\tmap[r][c] = line.charAt(c - 1);\n\t\t\t\tif (map[r][c] == 'S') {\n\t\t\t\t\ts_r = r;\n\t\t\t\t\ts_c = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmap[r][M + 1] = '#';\n\t\t}\n\t\tString inst = sc.next();\n\t\tlong ans = 0L;\n\t\tfor (int left = 0; left < 4; left++) {\n\t\t\tfor (int up = 0; up < 4; up++) {\n\t\t\t\tfor (int right = 0; right < 4; right++) {\n\t\t\t\t\tfor (int down = 0; down < 4; down++) {\n\t\t\t\t\t\tif (left == up || left == right || left == down || up == right || up == down || right == down) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint r_r = s_r;\n\t\t\t\t\t\tint r_c = s_c;\n\t\t\t\t\t\tfor (int i = 0; i < inst.length(); i++) {\n\t\t\t\t\t\t\tchar asc = inst.charAt(i);\n\t\t\t\t\t\t\tif (asc == '0' + left) {\n\t\t\t\t\t\t\t\tr_c--;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (asc == '0' + up) {\n\t\t\t\t\t\t\t\tr_r--;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (asc == '0' + right) {\n\t\t\t\t\t\t\t\tr_c++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (asc == '0' + down) {\n\t\t\t\t\t\t\t\tr_r++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (map[r_r][r_c] == '#') {\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 (map[r_r][r_c] == 'E') {\n\t\t\t\t\t\t\t\tans++;\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\tSystem.out.println(ans);\n\t}\n\n\tprivate void solveC() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tdouble R = 0.0 + sc.nextInt();\n\t\tdouble[] x = new double[N];\n\t\tdouble[] y = new double[N];\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tx[i] = 0.0 + sc.nextInt();\n\t\t\tdouble max_y = R;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tdouble dy = 4 * R * R - (x[i] - x[j]) * (x[i] - x[j]);\n\t\t\t\tif (dy >= 0) {\n\t\t\t\t\tdouble tmp_y = y[j] + Math.sqrt(dy);\n\t\t\t\t\tif (max_y < tmp_y) {\n\t\t\t\t\t\tmax_y = tmp_y;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ty[i] = max_y;\n\t\t}\n\t\tStringJoiner sj = new StringJoiner(\" \");\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tsj.add(String.valueOf(y[i]));\n\t\t}\n\t\tSystem.out.println(sj.toString());\n\t}\n\n\tprivate void solveD() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(N);\n\t}\n\n\tprivate void solveE() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(N);\n\t}\n\n\tprivate void solveF() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(N);\n\t}\n\n\tinterface Graph {\n\t\tvoid link(int from, int to, long cost);\n\t\tOptional<Long> getCost(int from, int to);\n\t\tint getVertexNum();\n\t}\n\n\tinterface FlowResolver {\n\t\tlong maxFlow(int from, int to);\n\t}\n\n\t/**\n\t * \u30b0\u30e9\u30d5\u306e\u884c\u5217\u306b\u3088\u308b\u5b9f\u88c5\n\t * \u63a5\u70b9\u6570\u306e\u5927\u304d\u3044\u30b0\u30e9\u30d5\u3067\u4f7f\u3046\u3068MLE\u3067\u6b7b\u306b\u305d\u3046\n\t */\n\tclass ArrayGraph implements Graph {\n\t\tprivate Long[][] costArray;\n\t\tprivate int vertexNum;\n\n\t\tpublic ArrayGraph(int n) {\n\t\t\tcostArray = new Long[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tcostArray[i] = new Long[n];\n\t\t\t}\n\t\t\tvertexNum = n;\n\t\t}\n\n\t\t@Override\n\t\tpublic void link(int from, int to, long cost) {\n\t\t\tcostArray[from][to] = new Long(cost);\n\t\t}\n\n\t\t@Override\n\t\tpublic Optional<Long> getCost(int from, int to) {\n\t\t\treturn Optional.ofNullable(costArray[from][to]);\n\t\t}\n\n\t\t@Override\n\t\tpublic int getVertexNum() {\n\t\t\treturn vertexNum;\n\t\t}\n\t}\n\n\t/**\n\t * DFS(\u6df1\u3055\u512a\u5148\u63a2\u7d22)\u306b\u3088\u308b\u5b9f\u88c5\n\t * \u8a08\u7b97\u91cf\u306fO(E*MaxFlow)\u306e\u306f\u305a (E:\u8fba\u306e\u6570, MaxFlow:\u6700\u5927\u30d5\u30ed\u30fc)\n\t */\n\tclass DfsFlowResolver implements FlowResolver {\n\t\tprivate Graph graph;\n\t\tpublic DfsFlowResolver(Graph graph) {\n\t\t\tthis.graph = graph;\n\t\t}\n\n\t\t/**\n\t\t * \u6700\u5927\u30d5\u30ed\u30fc(\u6700\u5c0f\u30ab\u30c3\u30c8)\u3092\u6c42\u3081\u308b\n\t\t * @param from \u59cb\u70b9(source)\u306eID\n\t\t * @param to \u7d42\u70b9(target)\u306eID\n\t\t * @return \u6700\u5927\u30d5\u30ed\u30fc(\u6700\u5c0f\u30ab\u30c3\u30c8)\n\t\t */\n\t\tpublic long maxFlow(int from, int to) {\n\t\t\tlong sum = 0L;\n\t\t\tlong currentFlow;\n\t\t\tdo {\n\t\t\t\tcurrentFlow = flow(from, to, Long.MAX_VALUE / 3, new boolean[graph.getVertexNum()]);\n\t\t\t\tsum += currentFlow;\n\t\t\t} while (currentFlow > 0);\n\t\t\treturn sum;\n\t\t}\n\n\t\t/**\n\t\t * \u30d5\u30ed\u30fc\u306e\u5b9f\u884c \u30b0\u30e9\u30d5\u306e\u66f4\u65b0\u3082\u884c\u3046\n\t\t * @param from \u73fe\u5728\u3044\u308b\u7bc0\u70b9\u306eID\n\t\t * @param to \u7d42\u70b9(target)\u306eID\n\t\t * @param current_flow \u3053\u3053\u307e\u3067\u306e\u6d41\u91cf\n\t\t * @param passed \u65e2\u306b\u901a\u3063\u305f\u7bc0\u70b9\u304b\u5426\u304b\u3092\u683c\u7d0d\u3057\u305f\u914d\u5217\n\t\t * @return \u7d42\u70b9(target)\u306b\u6d41\u3057\u305f\u6d41\u91cf/\u623b\u308a\u306e\u30b0\u30e9\u30d5\u306e\u6d41\u91cf\n\t\t */\n\t\tprivate long flow(int from, int to, long current_flow, boolean[] passed) {\n\t\t\tpassed[from] = true;\n\t\t\tif (from == to) {\n\t\t\t\treturn current_flow;\n\t\t\t}\n\t\t\tfor (int id = 0; id < graph.getVertexNum(); id++) {\n\t\t\t\tif (passed[id]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tOptional<Long> cost = graph.getCost(from, id);\n\t\t\t\tif (cost.orElse(0L) > 0) {\n\t\t\t\t\tlong nextFlow = current_flow < cost.get() ? current_flow : cost.get();\n\t\t\t\t\tlong returnFlow = flow(id, to, nextFlow, passed);\n\t\t\t\t\tif (returnFlow > 0) {\n\t\t\t\t\t\tgraph.link(from, id, cost.get() - returnFlow);\n\t\t\t\t\t\tgraph.link(id, from, graph.getCost(id, from).orElse(0L) + returnFlow);\n\t\t\t\t\t\treturn returnFlow;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0L;\n\t\t}\n\t}\n\n\t/**\n\t * 1-indexed\u306eBIT\u914d\u5217\n\t */\n\tclass BinaryIndexedTree {\n\t\tprivate long[] array;\n\n\t\tpublic BinaryIndexedTree(int size) {\n\t\t\tthis.array = new long[size + 1];\n\t\t}\n\n\t\t/**\n\t\t * \u6307\u5b9a\u3057\u305f\u8981\u7d20\u306b\u5024\u3092\u52a0\u7b97\u3059\u308b\n\t\t * \u8a08\u7b97\u91cf\u306fO(logN)\n\t\t * @param index \u52a0\u7b97\u3059\u308b\u8981\u7d20\u306e\u6dfb\u5b57\n\t\t * @param value \u52a0\u7b97\u3059\u308b\u91cf\n\t\t */\n\t\tpublic void add(int index, long value) {\n\t\t\tfor (int i = index; i < array.length; i += (i & -i)) {\n\t\t\t\tarray[i] += value;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 1\u301c\u6307\u5b9a\u3057\u305f\u8981\u7d20\u307e\u3067\u306e\u548c\u3092\u53d6\u5f97\u3059\u308b\n\t\t * \u8a08\u7b97\u91cf\u306fO(logN)\n\t\t * @param index \u548c\u306e\u7d42\u7aef\n\t\t * @return 1\u301cindex\u307e\u3067\u306e\u548c\n\t\t */\n\t\tpublic long getSum(int index) {\n\t\t\tlong sum = 0L;\n\t\t\tfor (int i = index; i > 0; i -= (i & -i)) {\n\t\t\t\tsum += array[i];\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\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        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 r = in.nextInt();\n            int i, j;\n            BigDecimal initial = new BigDecimal(10);\n            initial = initial.pow(100);\n            int x[] = new int[N];\n            BigDecimal y[] = new BigDecimal[N];\n            Arrays.fill(y, initial);\n            for (i = 0; i < N; i++) {\n                x[i] = in.nextInt();\n            }\n            for (i = 0; i < N; i++) {\n                BigDecimal y2 = new BigDecimal(r);\n                for (j = 0; j < i; j++) {\n                    if (Math.abs(x[i] - x[j]) <= 2 * r) {\n                        double xDiff = x[i] - x[j];\n                        xDiff *= xDiff;\n                        xDiff = 4 * r * r - xDiff;\n                        xDiff = Math.sqrt(xDiff);\n                        BigDecimal yNew = new BigDecimal(xDiff);\n                        yNew = yNew.add(y[j]);\n                        if (yNew.compareTo(y2) > 0) {\n                            y2 = yNew;\n                        }\n                    }\n                }\n                y[i] = y2;\n            }\n            for (i = 0; i < N; i++) {\n                out.print(y[i] + \" \");\n            }\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 close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "//package GoodBye2017;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class c {\n\tpublic static void main(String[] args) throws Exception{ new c(new Reader()); }\n\tpublic c(Reader rr) throws IOException{\n\t\tint n=rr.ni();\n\t\tdouble r=rr.nd();\n\t\tHashMap<Integer, Double> disk=new HashMap<Integer, Double>();\n\t\tfor(int i=0; i<n; i++){\n\t\t\tint next=rr.ni();\n\t\t\tif(disk.isEmpty()){\n\t\t\t\tdisk.put(next, r);\n\t\t\t\tSystem.out.print(r+\" \");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tdouble high=r;\n\t\t\t\tfor(Map.Entry<Integer, Double> it: disk.entrySet()){\n\t\t\t\t\tif(2*r<next-it.getKey()) continue;\n\t\t\t\t\tdouble tempHigh=pyth(Math.abs(next-it.getKey()),r*2)+it.getValue();\n\t\t\t\t\tif(tempHigh>high){\n\t\t\t\t\t\thigh=tempHigh;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdisk.put(next, high);\n\t\t\t\tSystem.out.print(high+\" \");\n\t\t\t}\n\t\t}\n\t}\n\tpublic double pyth(double a, double c){\n\t\treturn Math.sqrt(Math.pow(c, 2)-Math.pow(a, 2));\n\t}\n\tstatic class Reader{\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer=new byte[1024];\n\t\tprivate int bufP, bytR;\n\t\tpublic Reader() throws IOException{\n\t\t\tdin=new DataInputStream(System.in);\n\t\t\tbufP=bytR=0;\n\t\t}\n\t\tpublic Reader(String file) throws IOException{\n\t\t\tdin=new DataInputStream(new FileInputStream(file));\n\t\t\tbufP=bytR=0;\n\t\t}\n\t\tprivate String rl() 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') break;\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\t\tprivate int ni() throws IOException{\n\t\t\tint num=0;\n\t\t\tbyte c=read();\n\t\t\twhile(c<=' ') c=read();\n\t\t\tboolean neg=(c=='-');\n\t\t\tif(neg) c=read();\n\t\t\tdo{\n\t\t\t\tnum=num*10+c-'0';\n\t\t\t} while((c=read())>='0'&&c<='9');\n\t\t\tif(neg) return -num;\n\t\t\treturn num;\n\t\t}\n\t\tprivate long nl() throws IOException{\n\t\t\tlong num=0;\n\t\t\tbyte c=read();\n\t\t\twhile(c<=' ') c=read();\n\t\t\tboolean neg=(c=='-');\n\t\t\tif(neg) c=read();\n\t\t\tdo{\n\t\t\t\tnum=num*10+c-'0';\n\t\t\t} while((c=read())>='0'&&c<='9');\n\t\t\tif(neg) return -num;\n\t\t\treturn num;\n\t\t}\n\t\tprivate double nd() throws IOException{ return Double.parseDouble(ns()); }\n\t\tprivate char nc() throws IOException{ return (char)next(); }\n\t\tprivate String ns() throws IOException{\n\t\t\tint c=next();\n\t\t\tStringBuilder sb=new StringBuilder();\n\t\t\twhile(!(isChar(c))){\n\t\t\t\tsb.appendCodePoint(c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\t\tprivate char[] ns(int n) throws IOException{\n\t\t\tchar[] buf=new char[n];\n\t\t\tint c=next(), r=0;\n\t\t\twhile(r<n&&!(isChar(c))){\n\t\t\t\tbuf[r++]=(char)c;\n\t\t\t\tc=next();\n\t\t\t}\n\t\t\treturn n==r?buf:Arrays.copyOf(buf, r);\n\t\t}\n\t\tprivate char[][] nm(int n, int m) throws IOException{\n\t\t\tchar[][] map=new char[n][];\n\t\t\tfor(int i=0; i<n; i++) map[i]=ns(m);\n\t\t\treturn map;\n\t\t}\n\t\tprivate int[] na(int n) throws IOException{\n\t\t\tint[] a=new int[n];\n\t\t\tfor(int i=0; i<n; i++) a[i]=ni();\n\t\t\treturn a;\n\t\t}\n\t\tprivate boolean isChar(int c) throws IOException{ return !(c>=33&&c<=126); }\n\t\tprivate int next() throws IOException{ int c; while((c=read())!=-1&&isChar(c)); return c; }\n\t\tprivate byte read() throws IOException{\n\t\t\tif(bufP==bytR){\n\t\t\t\tbytR=din.read(buffer, bufP=0, 1024);\n\t\t\t\tif(bytR==-1) buffer[0]=-1;\n\t\t\t}\n\t\t\treturn buffer[bufP++];\n\t\t}\n\t\tpublic void close() throws IOException{\n\t\t\tif(din==null) return;\n\t\t\tdin.close();\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class c {\n\t\n\n\tpublic static void main(String args[]) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t//BEGIN HERE\n\t\tint n = in.nextInt();\n\t\tint r = in.nextInt();\n\t\tint xs[] = new int[n];\n\t\tfor(int i = 0; i < n; i++) xs[i] = in.nextInt();\n\t\tdouble ys[] = new double[n];\n\t\tys[0] = r;\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tdouble worst = r;\n\t\t\tfor(int j = 0; j < i; j++) {\n\t\t\t\tif(xs[i] == xs[j]) {\n\t\t\t\t\tworst = Math.max(worst, ys[j] + r + r);\n\t\t\t\t}else if((xs[i] - xs[j]) * (xs[i] - xs[j]) <= 4*r*r ) {\n\n\t\t\t\t\tdouble hypot = r + r;\n\t\t\t\t\tdouble adj = Math.abs((xs[i] - xs[j]));\n\t\t\t\t\tdouble theta = Math.acos(adj/hypot);\n\t\t\t\t\tworst = Math.max(hypot * Math.sin(theta) + ys[j], worst);\n\t\t\t\t}\n\t\t\t}\n\t\t\tys[i] = worst;\n\t\t}\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tout.printf(\"%.10f \",ys[i]);\n\t\tout.close();\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream i) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(i));\n\t\t\tst = null;\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\tif (st == null) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\tString line = st.nextToken(\"\\n\");\n\t\t\tst = null;\n\t\t\treturn line;\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\t}\n\n\tpublic static class combinatorics {\n\t\tstatic long modInv(long a, long b) {\n\t\t\treturn 1 < a ? b - modInv(b % a, a) * b / a : 1;\n\t\t}\n\n\t\tstatic long factorial[], mod;\n\n\t\tcombinatorics(int n, long MOD) {\n\t\t\tmod = MOD;\n\t\t\tfactorial = new long[n + 1];\n\t\t\tfactorial[0] = 1;\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tfactorial[i] = i * factorial[i - 1];\n\t\t\t\tfactorial[i] %= mod;\n\t\t\t}\n\t\t}\n\n\t\tstatic long nCr(int n, int r) {\n\t\t\tif (r > n)\n\t\t\t\treturn 0;\n\t\t\treturn (factorial[n] * modInv((factorial[n - r] * factorial[r]) % mod, mod)) % mod;\n\t\t}\n\n\t\tstatic long gcd(long a, long b) {\n\t\t\treturn b == 0 ? a : gcd(b, a % b);\n\t\t}\n\n\t\tstatic long lcm(long a, long b) {\n\t\t\treturn a * (b / gcd(a, b));\n\t\t}\n\t}\n\n\tpublic static class DisjointSet {\n\t\tint p[], r[], s[];\n\t\tint numDisjoint;\n\n\t\tDisjointSet(int N) {\n\t\t\tnumDisjoint = N;\n\t\t\tr = new int[N];\n\t\t\ts = new int[N];\n\t\t\tp = new int[N];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tp[i] = i;\n\t\t}\n\n\t\tint findSet(int i) {\n\t\t\treturn (p[i] == i) ? i : (p[i] = findSet(p[i]));\n\t\t}\n\n\t\tboolean isSameSet(int i, int j) {\n\t\t\treturn findSet(i) == findSet(j);\n\t\t}\n\n\t\tvoid unionSet(int i, int j) {\n\t\t\tif (!isSameSet(i, j)) // if from different set\n\t\t\t{\n\t\t\t\tnumDisjoint--;\n\t\t\t\tint x = findSet(i), y = findSet(j);\n\t\t\t\tif (r[x] > r[y]) {\n\t\t\t\t\tp[y] = x; // rank keeps the tree short\n\t\t\t\t\ts[x] += s[y];\n\t\t\t\t} else {\n\t\t\t\t\tp[x] = y;\n\t\t\t\t\tif (r[x] == r[y])\n\t\t\t\t\t\tr[y]++;\n\t\t\t\t\ts[y] += s[x];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint sizeOfSet(int i) {\n\t\t\treturn s[findSet(i)];\n\t\t}\n\t};\n\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        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, FastReader in, PrintWriter out) {\n            Debug debug = new Debug(out);\n            int n = in.nextInt();\n            TaskC.Circle[] c = new TaskC.Circle[n];\n            double rr = in.nextInt();\n            for (int i = 0; i < n; ++i) {\n                c[i] = new TaskC.Circle();\n                c[i].x = in.nextInt();\n            }\n            ArrayList<TaskC.Circle> done = new ArrayList<>();\n            for (int i = 0; i < n; ++i) {\n                TaskC.Circle cur = c[i];\n                double ans = Double.MIN_VALUE;\n                for (int j = 0; j < done.size(); ++j) {\n                    TaskC.Circle dd = done.get(j);\n                    if (Double.compare(2 * rr, Math.abs(dd.x - cur.x)) < 0) continue;\n                    double temp = Math.sqrt(4 * rr * rr - (cur.x - dd.x) * (cur.x - dd.x)) + dd.y;\n                    ans = Math.max(ans, temp);\n                }\n                if (ans == Double.MIN_VALUE)\n                    ans = rr;\n                cur.y = ans;\n                done.add(cur);\n            }\n            for (TaskC.Circle cc : done) {\n                out.printf(\"%.12f \", cc.y);\n            }\n        }\n\n        static class Circle implements Comparable<TaskC.Circle> {\n            double x;\n            double y;\n\n\n            public boolean equals(Object o) {\n                if (o == null) return false;\n                if (o == this) return true;\n                if (o.getClass() != this.getClass()) return false;\n\n                TaskC.Circle c = (TaskC.Circle) o;\n                return Double.compare(x, c.x) == 0 && Double.compare(y, c.y) == 0;\n            }\n\n\n            public int compareTo(TaskC.Circle o) {\n                if (Double.compare(o.x, x) != 0) {\n                    return Double.compare(x, o.x);\n                }\n                return Double.compare(y, o.y);\n            }\n\n        }\n\n    }\n\n    static class Debug {\n        PrintWriter out;\n        boolean oj;\n        long timeBegin;\n        Runtime runtime;\n\n        public Debug(PrintWriter out) {\n            oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n            this.out = out;\n            this.timeBegin = System.currentTimeMillis();\n            this.runtime = Runtime.getRuntime();\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "/**\n * Created by Ariana Herbst on 12/29/17.\n */\n\nimport java.util.*;\nimport java.io.*;\n\n/**\n * Created by Ariana Herbst on 12/29/17\n */\npublic class GB2017C {\n    static int n, r;\n    static int[] x;\n    static Map<Integer, Double> horo;\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        StringBuilder sb = new StringBuilder();\n        n = sc.nextInt();\n        r = sc.nextInt();\n        x = new int[n];\n        horo = new HashMap<Integer, Double>();\n        for (int x = 0; x <= r*2; x++) {\n            double y = 2.0 *Math.sqrt(r * r - (r - x/2.0) * (r - x/2.0));\n            horo.put(x, y);\n        }\n        for (int i = 0; i < n; i++) {\n            x[i] = sc.nextInt();\n        }\n        List<Double> y = new ArrayList<Double>();\n        for (int i = 0; i < n; i++) {\n            double max = r;\n            for (int j = 0; j < y.size(); j++) {\n                int dx = intersects(i, j);\n                if (dx >= 0) {\n                    double dy = horo.get(dx);\n                    max = Math.max(max, dy + y.get(j));\n                }\n            }\n            y.add(max);\n        }\n        for (int i = 0; i < n; i++) {\n            sb.append(y.get(i) + \" \");\n        }\n        System.out.println(sb);\n    }\n\n    static int intersects(int i, int j) {\n        if (Math.abs(x[i] - x[j]) <= 2*r) {\n            return 2*r - Math.abs(x[i] - x[j]);\n        } else\n            return -1;\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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\t\t\t\t\timport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\npublic class Solution1 implements Runnable\n{\n\tstatic final int MAX = 1000000007;\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\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\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 \t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new Solution1(),\"Solution1\",1<<26).start();\n\t}\n\tpublic static int gcd(int a, int b)\n    {\n        if (a == 0)\n            return b;\n         \n        return gcd(b%a, a);\n    }\n\t \n\t  static int lcm(int a, int b)\n\t    {\n\t        return (a*b)/gcd(a, b);\n\t    }\n\tstatic int max=  -1;\n\tpublic void run()\n\t{\n\t\tInputReader sc= new InputReader(System.in);\n\t\tPrintWriter w= new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tint r = sc.nextInt();\n\t\tint[] arr=  new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tarr[i] = sc.nextInt();\n\t\t}\n\t\tdouble sqr = 2*r*2*r;\n\t\tdouble[] ans=  new double[n];\n\t\tfor(int i = 0;i < arr.length;i++){\n\t\t\tans[i] = r*1.0;\n\t\t\tfor(int j = 0;j < i;j++){\n\t\t\t\tif(Math.abs(arr[i] - arr[j]) < 2*r){\n\t\t\t\t\tans[i] = Math.max(ans[i],Math.sqrt(sqr - Math.abs(arr[i] - arr[j])*Math.abs(arr[i]-arr[j])) + ans[j]); \n\t\t\t\t}else if(Math.abs(arr[i]-arr[j]) == 2*r){\n\t\t\t\t\tans[i] = Math.max(ans[i],ans[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < ans.length;i++){\n\t\t\tSystem.out.printf(\"%.7f \",ans[i]);\n\t\t}\n\t\tw.close();\n\t}\n\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.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        InputScanner in = new InputScanner(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, InputScanner in, PrintWriter out) {\n            int[] arr = in.readIntArr();\n            int n = arr[0];\n            int r = arr[1];\n\n            int[] x = in.readIntArr();\n            for (int i = 0; i < n; i++) {\n                x[i] += 999;\n            }\n\n            double[] h = new double[n];\n            int dsk[] = new int[3000];\n            Arrays.fill(dsk, -1);\n\n            for (int i = 0; i < r; i++) {\n                dsk[x[0] + i] = 0;\n                dsk[x[0] - i - 1] = 0;\n            }\n            int rs = 4 * r * r;\n\n            h[0] = r;\n\n\n            for (int i = 1; i < n; i++) {\n                double ch = r;\n                for (int j = 0; j < r; j++) {\n\n                    if (dsk[x[i] + j] != -1) {\n                        int ind = dsk[x[i] + j];\n                        int diff = x[ind] - x[i];\n                        int diffs = diff * diff;\n                        int hs = rs - diffs;\n                        ch = Math.max(ch, h[ind] + Math.sqrt(hs));\n                    }\n\n                    if (dsk[x[i] - j - 1] != -1) {\n                        int ind = dsk[x[i] - j - 1];\n                        int diff = x[ind] - x[i];\n                        int diffs = diff * diff;\n                        int hs = rs - diffs;\n                        ch = Math.max(ch, h[ind] + Math.sqrt(hs));\n                    }\n\n\n                }\n                if (x[i] + r < 3000) {\n                    if (dsk[x[i] + r] != -1) {\n                        ch = Math.max(ch, h[dsk[x[i] + r]]);\n                    }\n                }\n                if (x[i] - r - 1 > 0) {\n                    if (dsk[x[i] - r - 1] != -1) {\n                        ch = Math.max(ch, h[dsk[x[i] - r - 1]]);\n                    }\n                }\n                for (int j = 0; j < r; j++) {\n                    dsk[x[i] + j] = i;\n                    dsk[x[i] - j - 1] = i;\n                }\n                h[i] = ch;\n\n            }\n\n            for (int i = 0; i < n; i++) {\n                out.print(h[i] + \" \");\n            }\n            out.println();\n\n        }\n\n    }\n\n    static class InputScanner {\n        BufferedReader br;\n\n        public InputScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n\n        }\n\n        String readLine() {\n            String line = null;\n            try {\n                line = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return line;\n\n        }\n\n        public String[] readStringArr() {\n\n            return readLine().split(\" \");\n\n        }\n\n        public int[] readIntArr() {\n            String[] str = readStringArr();\n            int arr[] = new int[str.length];\n            for (int i = 0; i < arr.length; i++)\n                arr[i] = Integer.parseInt(str[i]);\n            return arr;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tprivate static double r, EPS=1e-10;\n\t\n\tpublic static void solve(FastScanner fs) {\t\n\t\tint n=fs.nextInt();\n\t\tr=fs.nextInt();\n\t\tint[] xCoords=fs.readArray(n);\n\t\t\n\t\tArrayList<Point> placed=new ArrayList<>();\n\t\tfor (int x:xCoords) {\n\t\t\tdouble maxY=r;\n\t\t\tfor (Point p:placed)\n\t\t\t\tmaxY=Math.max(maxY, getNewY(p, x));\n\t\t\tplaced.add(new Point(x, maxY));\n\t\t}\n\t\tfor (Point p:placed) {\n\t\t\tSystem.out.printf(\"%.9f \", p.y);\n\t\t}\n\t\t\n\t}\n\t\n\tprivate static double getNewY(Point circleCenter, int x) {\n\t\tdouble dx=Math.abs(x-circleCenter.x);\n\t\tif (dx>r+r)\n\t\t\treturn 0;\n\t\tif (dx<EPS)\n\t\t\treturn circleCenter.y+r+r;\n\t\tdouble hypot=r+r;\n\t\treturn circleCenter.y+Math.sqrt(hypot*hypot-(double)dx*dx);\n\t}\n\n\t\n\tstatic class Point {\n\t\tdouble x;\n\t\tdouble y;\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\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<n; i++)\n\t\t\t\ta[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong[] readLongArray(int n) {\n\t\t\tlong[] a=new long[n];\n\t\t\tfor (int i=0; i<n; i++)\n\t\t\t\ta[i]=nextLong();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\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 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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int r = in.nextInt();\n            int[] x = in.readIntArray(n);\n            double[] y = new double[n];\n            for (int i = 0; i < n; i++) {\n                y[i] = r;\n                for (int j = 0; j < i; j++) {\n                    double d = Math.abs(x[j] - x[i]);\n                    if (d <= 2 * r) {\n                        double yy = Math.sqrt(4.0 * r * r - d * d);\n                        y[i] = Math.max(y[i], y[j] + yy);\n                    }\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                out.print(y[i] + \" \");\n            }\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[] readIntArray(int n) {\n            int[] ar = new int[n];\n            for (int i = 0; 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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic ArrayList<ArrayList<Integer>> list;\n    static HashSet<Integer> hs;\n    static ArrayList<Integer> tmp;\n    //int n=Integer.parseInt(br.readLine());\n    //int n=Integer.parseInt(st.nextToken());\n    //StringTokenizer st = new StringTokenizer(br.readLine());\n    public static double cal(int a,double b,int x,int r)\n    {\n        r*=2;\n        double dis=(r*r) - Math.pow(Math.abs(a-x),2);\n        \n        dis=Math.sqrt(dis);\n        \n        dis+=b;\n        \n        return dis;\n        \n    }\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t    int n,r;\n\t    StringTokenizer st = new StringTokenizer(br.readLine());\n\t    n=Integer.parseInt(st.nextToken());\n\t    r=Integer.parseInt(st.nextToken());\n\t    \n\t    int arr[] = new int[n+1];\n\t    double cen[] = new double[n+1];\n\t    \n\t    int i,j;\n\t    \n\t    for(i=1;i<=n;i++)\n\t    cen[i]=-1.0;\n\t    \n\t    st = new StringTokenizer(br.readLine());\n\t    for(i=1;i<=n;i++)arr[i]=Integer.parseInt(st.nextToken());\n\t    \n\t    for(i=1;i<=n;i++)\n\t    {\n\t        int f=0;\n\t        double max=-1.0;\n\t        for(j=1;j<=n;j++)\n\t        {\n\t            if(i!=j && cen[j]!=-1.0 && (Math.abs(arr[i]-arr[j])<=2*r))\n\t            {\n\t                max=Math.max(max,cal(arr[j],cen[j],arr[i],r));\n\t                f=1;\n\t                \n\t            }\n\t        }\n\t       // System.out.println(i+\" \"+max);\n\t        if(f==1)\n\t        cen[i]=max;\n\t        else\n\t        cen[i]=r*1.0;\n\t    }\n\t    for(i=1;i<=n;i++)\n\t    System.out.print(cen[i]+\" \");\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.io.File;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.UnsupportedEncodingException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author MaxHeap\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        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, FastReader in, OutputWriter out) {\n            int n = in.nextInt();\n            double r = in.nextInt();\n            double[] x = new double[n];\n            for (int i = 0; i < n; i++) {\n                x[i] = in.nextDouble();\n            }\n            double[] ans = new double[n];\n            ans[0] = r;\n            for (int i = 1; i < n; i++) {\n                ans[i] = r;\n                double maxY = 0;\n                for (int j = 0; j < i; j++) {\n                    if (Math.abs(x[j] - x[i]) <= 2.0 * r) {\n                        double y = ans[j] + Math.sqrt(4 * r * r - (x[j] - x[i]) * (x[j] - x[i]));\n                        ans[i] = Math.max(ans[i], y);\n                    }\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                if (i > 0) out.print(\" \");\n                out.printf(\"%.8f\", ans[i]);\n            }\n        }\n\n    }\n\n    static class FastReader {\n        BufferedReader reader;\n        StringTokenizer st;\n\n        public FastReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            st = null;\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String line = reader.readLine();\n                    if (line == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(line);\n                } catch (Exception e) {\n                    throw new RuntimeException();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n    }\n\n    static class OutputWriter extends PrintWriter {\n        public OutputWriter(OutputStream os, boolean autoFlush) {\n            super(os, autoFlush);\n        }\n\n        public OutputWriter(Writer out) {\n            super(out);\n        }\n\n        public OutputWriter(Writer out, boolean autoFlush) {\n            super(out, autoFlush);\n        }\n\n        public OutputWriter(String fileName) throws FileNotFoundException {\n            super(fileName);\n        }\n\n        public OutputWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {\n            super(fileName, csn);\n        }\n\n        public OutputWriter(File file) throws FileNotFoundException {\n            super(file);\n        }\n\n        public OutputWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {\n            super(file, csn);\n        }\n\n        public OutputWriter(OutputStream out) {\n            super(out);\n        }\n\n\n        public void flush() {\n            super.flush();\n        }\n\n\n        public void close() {\n            super.close();\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "/*\nID: andrew42\nLANG: JAVA\nTASK: \nPROG: \n*/\n\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class curling {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner input = new Scanner(System.in);\n\t\tint numD = input.nextInt();\n\t\tdouble rad = input.nextInt();\n\t\tint[] xC = new int[numD];\n\t\tfor (int i = 0; i < numD; i++){\n\t\t\txC[i] = input.nextInt();\n\t\t}\n\t\tdouble[] maxY = new double[1001];\n\t\tfor (int i = 0; i < numD; i++){\n\t\t\tdouble h = rad;\n\t\t\tfor (int j = Math.max(1, xC[i]-(int)(2*rad)); j <= Math.min(1000, xC[i]+2*rad); j++){\n\t\t\t\tif (maxY[j] > 0){\n\t\t\t\t\th = Math.max(h, Math.sqrt(4*rad*rad-(j-xC[i])*(j-xC[i]))+maxY[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.print(h + \" \");\n\t\t\tmaxY[xC[i]] = h;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static double [] res;\n    static double r;\n    static double solve (int xMe, int xHim, int idxHim) {\n        if (Math.abs(xMe - xHim) > 2 * r) return r;\n        double hisY = res[idxHim];\n        double lo = hisY, hi = hisY + 2 * r, best = hi;\n        for (int cnt = 0; cnt <= 50; cnt++) {\n            double myY = (lo) + ((hi - lo) / 2);\n            if (notIntersect(xMe, myY, xHim, hisY)) {\n                best = Math.min(best, myY);\n                hi = Math.max(lo, myY);\n            } else\n                lo = Math.min(hi, myY);\n        }\n        return best;\n    }\n    static boolean notIntersect (double x1, double y1, double x2, double y2) {\n        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) >= 2 * r  * 2 * r;\n    }\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int n = sc.nextInt();\n        res = new double[n];\n        r = sc.nextInt();\n        int[] x = new int[n];\n        for (int i = 0; i < n; i++)\n            x[i] = sc.nextInt();\n\n        for (int i = 0; i < n; i++) {\n            double max = r;\n            for (int j = 0; j < i; j++) {\n                max = Math.max(max, solve(x[i], x[j], j));\n            }\n            if (i > 0) out.print(\" \");\n            res[i] = max;\n            out.printf(\"%.10f\", max);\n        }\n        out.println();\n\n        out.flush();\n        out.close();\n    }\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n        public Scanner(FileReader s) throws FileNotFoundException {\tbr = 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}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class probC {\n\tstatic int r;\n\tstatic ArrayList<Circ> curr = new ArrayList<Circ>();\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\tr = sc.nextInt();\n\t\tint[] xC = new int[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\txC[i] = sc.nextInt();\n\t\tdouble ans[] = new double[n];\n\t\tans[0] = r;\n\t\tcurr.add(new Circ(xC[0], r));\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tdouble max = r;\n\t\t\tfor(int k = 0; k < curr.size(); k++) {\n\t\t\t\tdouble cur = curr.get(k).y+ Math.sqrt(4 * r*r - (xC[i]-curr.get(k).x)*(xC[i]-curr.get(k).x));\n\t\t\t\t//System.out.println(cur + \" \" + max);\n\t\t\t\tif(4 * r*r - (xC[i]-curr.get(k).x)*(xC[i]-curr.get(k).x) >= 0)\n\t\t\t\t\tmax = Math.max(cur,  max);\n\t\t\t}\n\t\t\tans[i] = max;\n\t\t\tcurr.add(new Circ(xC[i], max));\n\t\t\t//System.out.println();\n\t\t}\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tSystem.out.print(ans[i] + \" \");\n\t\tsc.close();\n\t}\n\tstatic class Circ {\n\t\tdouble x, y;\n\t\tpublic Circ(double a, double b) {\n\t\t\tx=a;\n\t\t\ty=b;\n\t\t}\n\t\tpublic boolean isNT(Circ b) {\n\t\t\tdouble dist = Math.sqrt((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y));\n\t\t\treturn dist > 2*r;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "//>>>BaZ<<<//\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{  \n    static int dx[] = {-1,1,0,0};\n    static int dy[] = {0,0,1,-1};\n    static long MOD = 1000000007;\n    static int INF = Integer.MAX_VALUE/10;\n    static PrintWriter pw;\n    static InputReader scan;\n    //static MyFileReader1 ss;\n    //static MyFileReader scan;\n    static int ni() throws IOException{return scan.nextInt();}\n    static long nl() throws IOException{return scan.nextLong();}\n    static double nd() throws IOException{return scan.nextDouble();}\n    static String ne() throws IOException{return scan.next();}\n    static void pl() throws IOException {pw.println();}\n    static void pl(Object o) throws IOException {pw.println(o);}\n    static void p(Object o) throws IOException {pw.print(o+\" \");}\n    static void psb(StringBuilder sb) throws IOException {pw.print(sb);}\n    public static void main(String[] args) {\n        new Thread(null,null,\"BaZ\",99999999)\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        Calendar CAL1 = Calendar.getInstance();\n        CAL1.setTime(new Date());\n        scan = new InputReader(System.in);\n        pw = new PrintWriter(System.out,true);\n        //pw = new PrintWriter(new File(\"C://Users/Aman deep/Desktop/output.txt\"));  \n        //ss = new MyFileReader1();\n        //scan = new MyFileReader();\n        StringBuilder sb = new StringBuilder();\n        int n = ni();\n        double r = ni();\n        double x[] = new double[n];\n        for(int i=0;i<n;++i)\n            x[i] = nd();\n        double y[] = new double[n];\n        y[0] = r;\n        for(int i=1;i<n;++i)\n        {  \n            double max = -1;\n            for(int j=0;j<i;++j)\n            {\n                double xx = 4*r*r-(x[i]-x[j])*(x[i]-x[j]);\n                if(xx>=0)\n                    max = max(max,sqrt(xx)+y[j]);\n            }\n            if(max==-1)\n                max = r;\n            y[i] = max;\n        }\n        for(int i=0;i<n;++i)\n            p(y[i]);\n        pl();\n        Calendar CAL2 = Calendar.getInstance();\n        CAL2.setTime(new Date());\n        double Execution_Time = (double)(CAL2.getTimeInMillis()-CAL1.getTimeInMillis())/1000.000;\n        //System.out.println(\"Execution time : \"+Execution_Time+\" seconds\");\n        pw.flush();\n        pw.close();\n    }\n    static class InputReader     //NoSuchElementException -> EOF\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n            try\n            {\n                str = br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n    static class MyFileReader                                          //File input template\n    {\n        StringTokenizer st;\n        BufferedReader br;\n        MyFileReader() throws IOException\n        {\n            br = new BufferedReader(new FileReader(\"C://Users/Aman deep/Desktop/input.txt\"));\n        }\n        String nextLine() throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(nextLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n    static class MyFileReader1                                          //File input template\n    {\n        StringTokenizer st;\n        BufferedReader br;\n        MyFileReader1() throws IOException\n        {\n            br = new BufferedReader(new FileReader(\"C://Users/Aman deep/Desktop/output.txt\"));\n        }\n        String nextLine() throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(nextLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.*;\n\n\npublic class Main {\n\n\n    public static void main(String[] args) throws IOException{\n        Scanner sc = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int N = sc.nextInt(), R = sc.nextInt();\n        double answer[] = new double[N];\n        int[] x = new int[N];\n\n        for (int i = 0; i < N; i++)\n            x[i] = sc.nextInt();\n\n        for (int i = 0; i < N; i++) {\n            answer[i] = R;\n            for (int j = 0; j < i; j++) {\n                int dist = Math.abs(x[i] - x[j]);\n                if(dist <= 2 * R) {\n                    double t = answer[j] + Math.sqrt(4 * R * R - dist * dist);\n                    answer[i] = Math.max(answer[i], t);\n                }\n            }\n        }\n        for(int i = 0; i < N; ++i)\n            out.print(answer[i] + \" \");\n\n        out.println();\n\n        out.flush();\n        out.close();\n    }\n\n\n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        Scanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\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        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    }\n    }\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\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 mostafa on 12/29/17.\n */\npublic class C {\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n        int n = sc.nextInt(), r = sc.nextInt();\n        int[] x = new int[n];\n        for(int i = 0; i < n; i++)\n            x[i] = sc.nextInt();\n        double[] ans = new double[n];\n        for(int i = 0; i < n; i++) {\n            ans[i] = r;\n            for(int j = 0; j < i; j++) {\n                int d = Math.abs(x[i] - x[j]);\n                if(d > 2 * r)\n                    continue;\n                int h = 2 * r;\n                double yd = Math.sqrt(h * h - d * d);\n                ans[i] = Math.max(ans[i], ans[j] + yd);\n            }\n\n            out.print(ans[i]);\n            if(i == n - 1)\n                out.println();\n            else\n                out.print(\" \");\n        }\n\n        out.flush();\n        out.close();\n\n    }\n\n    static class Scanner {\n        BufferedReader br; StringTokenizer st;\n        Scanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\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    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class A{\n\n    void solve(){\n        int n=ni();\n        long r=ni();\n        int x[]=new int[n+1];\n        for(int i=1;i<=n;i++) x[i]=ni();\n\n        double ans[]=new double[n+1];\n        ans[1]=r;\n        for(int i=2;i<=n;i++){\n            double mx=0;\n            for(int j=1;j<i;j++) {\n                double xx = Math.abs(x[i] - x[j]);\n                if (xx > 2*r) {\n                    mx = Math.max(mx,r);\n                } else {\n                    xx *= xx;\n                     mx=Math.max(mx,ans[j] + Math.sqrt(4 * r * r - xx));\n                    // if(i==5) pw.println(j);\n                }\n                //if(i==4) pw.println(mx);\n            }\n            ans[i]=mx;\n        }\n        for(int i=1;i<=n;i++) pw.print(ans[i]+\" \");\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    public static void main(String[] args) throws Exception { new A().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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.max;\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 C {\n\n\tstatic int sqr(int x) {\n\t\treturn x * x;\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint n = scanInt();\n\t\tint r = scanInt();\n\t\tint x[] = new int[n];\n\t\tdouble y[] = new double[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint cx = x[i] = scanInt();\n\t\t\tdouble cy = r;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tif (abs(cx - x[j]) <= 2 * r) {\n\t\t\t\t\tcy = max(cy, y[j] + sqrt(sqr(2 * r) - sqr(cx - x[j])));\n\t\t\t\t}\n\t\t\t}\n\t\t\ty[i] = cy;\n\t\t\tif (i > 0) {\n\t\t\t\tout.print(' ');\n\t\t\t}\n\t\t\tout.printf(Locale.US, \"%.9f\", cy);\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class TaskC {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt(), r = sc.nextInt();\n\t\tint[] xcords = new int[n];\n\t\tdouble[] ycords = new double[n];\n\t\tdouble y = r, x = 0, px = 0, ty = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\txcords[i] = sc.nextInt();\n\t\t\tx = xcords[i];\n\t\t\ty = r;\n\t\t\tfor(int j = 0; j < i; j++) {\n\t\t\t\tpx = xcords[j];\n\t\t\t\tif(Math.abs(px - x) > r*2) continue;\t\n\t\t\t\tty = Math.sqrt(4*r*r - (x-px)*(x-px)) + ycords[j];\n\t\t\t\ty = Math.max(y, ty);\n\t\t\t}\n\t\t\tycords[i] = y;\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tSystem.out.print(ycords[i] + \" \");\n\t\t}\n\t}\n\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in= new FastScanner(System.in);\n\t\tPrintWriter out= new PrintWriter(System.out);\n\t\t\n\t\tint n= in.nextInt();\n\t\tint r= in.nextInt();\n\t\tint [] x= new int[n];\n\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\tx[i]= in.nextInt();\n\t\t}\n\t\tdouble [] res= new double[n];\n\t\tres[0]= r;\n\t\tfor (int i = 1; i < x.length; i++) {\n\t\t\tboolean found = false;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tdouble dis= Math.abs(x[i]-x[j]);\n\t\t\t\tdouble rr= 4.0*r*r-1.0*dis*dis;\n\t\t\t\tif(rr>=0) {\n\t\t\t\t\tdouble del= Math.sqrt(rr);\n\t\t\t\t\tres[i]= Math.max(res[i], res[j]+del);\n\t\t\t\t\tfound= true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!found) {\n\t\t\t\tres[i]= r;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < res.length; i++) {\n\t\t\tout.print(res[i]+\" \");\n\t\t}\n\t\tout.close();\n\t\t\n\t}\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\tif (!st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\treturn next();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic double nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class C908 {\n\t\n\tpublic static class mPoint implements Comparable<mPoint> {\n\t\tpublic double a, b;\n\t\tpublic mPoint(int a, double b) {\n\t\t\tthis.a = a; this.b = b;\n\t\t}\n\t\tpublic int compareTo(mPoint p) {\n\t\t\treturn b < p.b ? 1 : (b > p.b) ? -1 : 0;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt(), r = in.nextInt();\n\t\tint[] ar = new int[n];\n\t\tArrayList<mPoint> disks = new ArrayList<>();\n\t\tdouble[] ans = new double[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tar[i] = in.nextInt();\n\t\t\tdouble max = -1;\n\t\t\tfor (int j = 0; j < disks.size(); j++) {\n\t\t\t\tif (inRange(ar[i], disks.get(j).a, r)) {\n\t\t\t\t\tdouble h = 4*r*r - (ar[i]-disks.get(j).a) * (ar[i]-disks.get(j).a);\n\t\t\t\t\tmax = Math.max(max, Math.sqrt(h) + disks.get(j).b);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmPoint p = null;\n\t\t\tif (max == -1) {\n\t\t\t\tp = new mPoint(ar[i], r);\n\t\t\t} else {\n\t\t\t\tp = new mPoint(ar[i], max);\n\t\t\t}\n\t\t\tdisks.add(p);\n\t\t\tans[i] = p.b;\n\t\t}\n\t\tfor (int i = 0; i < ans.length - 1; i++) {\n\t\t\tSystem.out.print(ans[i] + \" \");\n\t\t}\n\t\tSystem.out.println(ans[ans.length - 1]);\n\t}\n\t\n\tpublic static boolean inRange(int a, double b, int r) {\n\t\tif (Math.abs(b - a) <= 2*r) return true; return false;\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tpublic static Scanner sc = new Scanner(System.in);\n\tpublic static StringTokenizer st;\n\tpublic static PrintWriter pw = new PrintWriter(System.out);\n\tfinal static boolean debugmode = true;\n\tpublic static int k = 7; // for 10^9 + k mods.\n\tpublic static long STMOD = 1000000000 + k; // 10^9 + k\n\tpublic static void main(String[] args) {\n\t\tint disks = getInt();\n\t\tint radii = getInt();\n\t\tif(disks == 1){\n\t\t\tSystem.out.println(radii);\n\t\t}\n\t\telse{\n\t\t\tdouble[][] diskcenters = new double[disks][2];\n\t\t\tfor(int i = 0;i<disks;i++){\n\t\t\t\tdiskcenters[i][0] = getInt();\n\t\t\t}\n\t\t\tdiskcenters[0][1] = radii;\n\t\t\tfor(int i = 1;i<disks;i++){\n\t\t\t\tdouble cmax = 0;\n\t\t\t\tfor(int prev = 0;prev < i;prev++){\n\t\t\t\t\tcmax = Math.max(cmax, calcintersection(diskcenters[prev][0],diskcenters[prev][1],radii,diskcenters[i][0],radii));\n\t\t\t\t}\n\t\t\t\tdiskcenters[i][1] = cmax;\n\t\t\t}\n\t\t\tfor(int i = 0;i<diskcenters.length;i++){\n\t\t\t\tSystem.out.print(Double.toString(diskcenters[i][1]) + \" \");\n\t\t\t}\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\t\t\n\t}\n\tpublic static double calcintersection(double x1,double y1, double r1,double x2, double r2){\n\t\t// x1,y1 must be stationary.\n\t\tif(!intersects(x1-r1,x1+r1,x2-r1,x2+r2)){\n\t\t\treturn r2;\n\t\t}\n\t\telse if(x1 == x2){\n\t\t\treturn y1 + r1 + r2;\n\t\t}\n\t\tdouble lo = y1;\n\t\tdouble hi = y1 +  2 * r2;\n\t\t\n\t\twhile(Math.abs(lo-hi) > 0.0000001){\n\t\t\tdouble mid = (lo+hi)/2.0;\n\t\t\tint u = colide(x1,y1,r1,x2,mid,r2);\n\t\t\tif(u == 1){\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t\telse if(u == 0)\n\t\t\t{\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t\telse{\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t}\n\t\treturn (lo+hi)/2.0;\n\t}\n\tpublic static boolean intersects(double l1, double r1,double l2, double r2 ){\n\t\tif(l2  <= l1 && r2 >= l1){\n\t\t\treturn true;\n\t\t}\n\t\tif(l2 <= r1 && r2 >= r1){\n\t\t\treturn true;\n\t\t}\n\t\tif(l1 <= l2 && r2 <= r1){\n\t\t\treturn true;\n\t\t}\n\t\telse if(l2 <= l1 && r1 <= r2){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static int colide(double x1,double y1,double r1,double x2,double y2,double r2){\n\t\tdouble dist = Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y2-y1, 2));\n\t\tif (dist > r1 + r2){\n\t\t\treturn 0;\n\t\t}\n\t\telse if(dist == r1+r2){\n\t\t\treturn 2;\n\t\t}\n\t\telse{\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t}\n\tpublic static void debug(String toPrint){\n\t\tif(!debugmode) {return;}\n\t\tpw.println(\"[DEBUG]: \"+toPrint);\n\t}\n\tpublic static void  submit(int[] k){\n\t\tpw.println(Arrays.toString(k));\n\t\tpw.close();\n\t}\n\tpublic static void submit(int p){\n\t\tpw.println(Integer.toString(p));\n\t\tpw.close();\n\t}\n\tpublic static void submit(String k){\n\t\tpw.println(k);\n\t\tpw.close();\n\t}\n\tpublic static void submit(double u){\n\t\tpw.println(Double.toString(u));\n\t\tpw.close();\n\t}\n\tpublic static void submit(long lng){\n\t\tpw.println(Long.toString(lng));\n\t\tpw.close();\n\t\t\n\t}\n\tpublic static int getInt(){\n\t\tif (st != null && st.hasMoreTokens()){\n\t\t\treturn Integer.parseInt(st.nextToken());\n\t\t}\n\t\tst = new StringTokenizer(sc.nextLine());\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\tpublic static long getLong(){\n\t\tif (st != null && st.hasMoreTokens()){\n\t\t\treturn Long.parseLong(st.nextToken());\n\t\t}\n\t\tst = new StringTokenizer(sc.nextLine());\n\t\treturn Long.parseLong(st.nextToken());\n\t}\n\tpublic static double getDouble(){\n\t\tif (st != null && st.hasMoreTokens()){\n\t\t\treturn Double.parseDouble(st.nextToken());\n\t\t}\n\t\tst = new StringTokenizer(sc.nextLine());\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\tpublic static String getString(){\n\t\tif(st != null && st.hasMoreTokens()){\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tst = new StringTokenizer(sc.nextLine());\n\t\treturn st.nextToken();\n\t}\n\tpublic static String getLine(){\n\t\treturn sc.nextLine();\n\t}\n\tpublic static int[][] readMatrix(int lines,int cols){\n\t\tint[][] matrr = new int[lines][cols];\n\t\tfor (int i = 0;i < lines;i++){\n\t\t\tfor(int j = 0;j < cols;j++){\n\t\t\t\tmatrr[i][j] = getInt();\n\t\t\t}\n\t\t}\n\t\treturn matrr;\n\t}\n\tpublic static int[] readArray(int lines){\n\t\tint[] ar = new int[lines];\t\t\n\t\tfor (int i = 0;i<lines;i++) ar[i] =getInt();\n\t\treturn ar;\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class C {\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n\n        int n, r;\n        n = scan.nextInt();\n        r = scan.nextInt();\n\n        int[] locs = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            locs[i] = scan.nextInt();\n        }\n\n        double[] yPos = new double[n];\n        Arrays.fill(yPos, 10e100);\n\n        yPos[0] = r;\n        for (int i = 1; i < n; i++) {\n            double pos = r;\n            for (int j = 0; j < i; j++) {\n                int xDist = Math.abs(locs[i] - locs[j]);\n                if (xDist <= 2 * r) {\n                    double y = (2.0 * r) * (2.0 * r) - (xDist * xDist);\n                    if (Math.abs(y - 0.0) < 0.0000000001) {\n                        y = 0;\n                    } else {\n                        y = Math.sqrt(y);\n                    }\n                    y += yPos[j];\n                    pos = Math.max(pos, y);\n\n                } else {\n                    continue;\n                }\n            }\n            yPos[i] = pos;\n        }\n        String[] ans = new String[n];\n\n        for (int i = 0; i < n; i++) {\n            ans[i] = \"\" + yPos[i];\n        }\n\n        System.out.println(String.join(\" \", ans));\n\n    }\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\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 C {\n\tstatic int n,r,x[];\n\tstatic double ans[];\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\tn = sc.nextInt();\n\t\tr = sc.nextInt();\n\t\tx = new int[n];\n\t\tans = new double[n];\n\t\tfor (int i=0;i<n;i++)\n\t\t\tx[i] = sc.nextInt();\n\t\tfor (int i=0;i<n;i++)\n\t\t{\n\t\t\tans[i] = r;\n\t\t\tfor (int j=0;j<i;j++)\n\t\t\t{\n\t\t\t\tif (Math.abs(x[i]-x[j])>2*r)\n\t\t\t\t\tcontinue;\n\t\t\t\tint deltaxsq = (x[i]-x[j])*(x[i]-x[j]);\n\t\t\t\tint deltaysq = 4 * r * r - deltaxsq;\n\t\t\t\tdouble deltay = Math.sqrt(deltaysq);\n\t\t\t\tans[i] = Math.max(ans[i], ans[j]+deltay);\n\t\t\t}\n\t\t\tpw.print(ans[i]+\" \");\n\t\t}\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\t\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\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\t\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\t\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t\n\t\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\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        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        initData();\n        solve();\n        out.flush();\n    }\n\n\n    private static void initData() {\n    }\n\n\n    private static void solve() throws IOException {\n        int n = sc.nextInt();\n        int q = sc.nextInt();\n        int[] vv = sc.na(n);\n\n        double[] ans = new double[n];\n\n        for (int i = 0; i < n; i++) {\n            ans[i] = q;\n            for (int s = 0; s < i; s++) {\n                if (Math.abs(vv[i] - vv[s]) > q * 2) continue;\n                double diff = 4 * q * q - Math.abs(vv[i] - vv[s]) * Math.abs(vv[i] - vv[s]);\n                diff = Math.sqrt(diff);\n                ans[i] = Math.max(ans[i], diff + ans[s]);\n            }\n            out.print(ans[i] + \" \");\n        }\n    }\n\n\n    private static void solveT() throws IOException {\n        int t = sc.nextInt();\n        while (t-- > 0) {\n            solve();\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class GB17C {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t\t\n\t\t\tBufferedReader sc = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\n\t\t\tString[] dir = sc.readLine().split(\" \");\n\t\t\tint n = Integer.parseInt(dir[0]);\n\t\t\tint r = Integer.parseInt(dir[1]);\n\t\t\t\n\t\t\tString[] t = sc.readLine().split(\" \");\n\t\t\tint[] list = new int[n];\n\t\t\tfor(int x=0; x<n; x++){\n\t\t\t\tlist[x] = Integer.parseInt(t[x]);\n\t\t\t}\n\t\t\t\n\t\t\tdouble[] yCoords = new double[n];\n\t\t\t\n\t\t\tfor(int x=0; x<n; x++){\n\t\t\t\tdouble stop = (double)r;\n\t\t\t\tint dist = 2*r;\n\t\t\t\tint xCoordNew = list[x];\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tfor(int y=0; y<x; y++){\n\t\t\t\t\t\n\t\t\t\t\tint xCoordOld = list[y];\n\t\t\t\t\tif(Math.abs(xCoordNew - xCoordOld) == dist){\n\t\t\t\t\t\tstop = Math.max(stop, yCoords[y]);\n\t\t\t\t\t}\n\t\t\t\t\telse if(Math.abs(xCoordNew - xCoordOld) < dist){\n\t\t\t\t\t\tdouble extra = Math.pow((double)(dist*dist) - (double)((xCoordNew - xCoordOld)*(xCoordNew - xCoordOld)), 0.5);  \n\t\t\t\t\t\t\n\t\t\t\t\t\tstop = Math.max(stop, yCoords[y] + extra);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tyCoords[x] = stop;\n\t\t\t\tSystem.out.print(stop+\" \");\n\t\t\t}\n\t\t\t\n\t\t\t\n\t}\n}\n\n\n/* \n\nBufferedReader sc = new BufferedReader(new InputStreamReader(System.in));\n\nint n = Integer.parseInt(sc.readLine());\nString[] t = sc.readLine().split(\" \");\nint[] list = new int[n];\nfor(int x=0; x<n; x++){\n\tlist[x] = Integer.parseInt(t[x]);\n}\n\t\t\nString[] dir = sc.readLine().split(\" \");\nint a = Integer.parseInt(dir[0]);\nint b = Integer.parseInt(dir[1]);\nint c = Integer.parseInt(dir[2]);\nint d = Integer.parseInt(dir[3]);\nint e = Integer.parseInt(dir[4]);\n\nint n = Integer.parseInt(sc.readLine());\n\n*/", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.*;\n\npublic class C {\n  public static void main(String[] args) {\n    FastScanner sc = new FastScanner();\n\n    int n = sc.nextInt();\n    long r = sc.nextInt();\n    double d = 2 * r;\n    long[] xs = sc.readLongArray(n);\n    P[] points = new P[n];\n    StringBuilder sb = new StringBuilder();\n    for (int i = 0; i < n; i++) {\n      if (i > 0) sb.append(' ');\n      double y = r;\n      for (int j = 0; j < i; j++) {\n        long diff = Math.abs(xs[i] - points[j].x);\n        if (diff <= 2 * r) {\n          double dy = Math.sqrt(d * d - diff * diff);\n          double testY = points[j].y + dy;\n          y = Math.max(y, testY);\n        }\n      }\n\n      sb.append(y);\n      points[i] = new P(xs[i], y);\n    }\n    System.out.println(sb);\n  }\n\n  static class P {\n    final long x;\n    final double y;\n\n    public P(long x, double y) {\n      this.x = x;\n      this.y = y;\n    }\n  }\n\n  static void shuffle(int[] arr) {\n    Random rng = new Random();\n    int length = arr.length;\n    for (int idx = 0; idx < arr.length; idx++) {\n      int toSwap = idx + rng.nextInt(length - idx);\n      int tmp = arr[idx];\n      arr[idx] = arr[toSwap];\n      arr[toSwap] = tmp;\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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.readInt();\n            int r = in.readInt();\n            int[] x = in.readIntArray(n);\n            double[] y = new double[n];\n            y[0] = r;\n            for (int i = 1; i < n; i++) {\n                double max = r;\n                for (int j = 0; j < i; j++) {\n                    double pow = Math.pow(x[i] - x[j], 2);\n                    if (pow <= 4 * r * r) {\n                        double ty = y[j] + Math.sqrt(4 * r * r - pow);\n                        max = Math.max(max, ty);\n                    }\n                }\n                y[i] = max;\n            }\n            for (double i : y) out.print(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 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 int[] readIntArray(int size) {\n            int[] ans = new int[size];\n            for (int i = 0; i < size; i++) ans[i] = readInt();\n            return ans;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "/*\n * code together\n * code better\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\t\n\tstatic int x[]=new int[1005];\n\tstatic double ans[]=new double[1005];\n\tstatic int nn,r;\n\tpublic static void main(String[] args) throws IOException {\n\t\tStreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tPrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\tScanner sc=new Scanner(System.in);\n\t\tint huiwoqingchun=0;\n\t\tnn=sc.nextInt();\n\t\tr=sc.nextInt();\n\t\tfor(int i=1;i<=nn;i++) {\n\t\t\tx[i]=sc.nextInt();\n\t\t}\n\t\t//HashMap<, V>\n\t\tans[1]=r;\n\t\tint lajitimu=0;\n\t\tfor(int i=2;i<=nn;i++) {\n\t\t\tans[i]=r;\n\t\t\tfor(int j=1;j<i;j++) {\n\t\t\t\tif(Math.abs(x[j]-x[i])>2*r)\n\t\t\t\t\tcontinue;\n\t\t\t\tans[i]=Math.max(ans[i], ans[j]+Math.sqrt(4*r*r-(x[j]-x[i])*(x[j]-x[i])));\n\t\t\t}\n\t\t}\n\t\tdouble buzhidaoganma=0;\n\t\tfor(int c=1;c<=nn;c++)\n\t\t\tSystem.out.printf(\"%.12f \",ans[c]);\n\t}\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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 */\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        C908 solver = new C908();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class C908 {\n        int N;\n        int R;\n        int[] x;\n        double[] ans;\n\n        public void solve(int testNumber, FastScanner s, PrintWriter out) {\n\n            N = s.nextInt();\n            R = s.nextInt();\n            x = s.nextIntArray(N);\n\n            ans = new double[N];\n            Arrays.fill(ans, R);\n\n            for (int i = 0; i < N; i++) {\n                // placing circle i\n                for (int j = 0; j < i; j++) {\n                    // testing collision with placed circles\n                    if (Math.abs(x[i] - x[j]) <= 2 * R) {\n                        // they will collide\n                        // compute the increase in y that will be had\n                        double dy = Math.sqrt(Math.pow(2 * R, 2) - Math.pow(x[i] - x[j], 2));\n                        ans[i] = Math.max(ans[i], ans[j] + dy);\n                    }\n                }\n            }\n\n            for (double d : ans)\n                out.print(d + \" \");\n            out.println();\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 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 int[] nextIntArray(int N) {\n            int[] ret = new int[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = this.nextInt();\n            return ret;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.Vector;\npublic class naloga1{\n\tstatic BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\tstatic PrintWriter out=new PrintWriter(System.out);\n\tpublic static void main(String[] args) throws Exception{\n\t\tStringTokenizer st=new StringTokenizer(in.readLine());\n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint r=Integer.parseInt(st.nextToken());\n\t\tint[] x=new int[n];\n\t\tst=new StringTokenizer(in.readLine());\n\t\tfor(int i=0;i < n;i++){\n\t\t\tx[i]=Integer.parseInt(st.nextToken());\n\t\t}\n\t\tsim a=new sim(n,r);\n\t\tfor(int i:x) {\n\t\t\ta.add(i);\n\t\t}\n\t\tfor(double d:a.cy) {\n\t\t\tout.print(d+\" \");\n\t\t}\n\t\tout.println();\n\t\tout.close();\n\t}\n}\nclass sim{\n\tdouble[]cx;\n\tint[]ccx;\n\tdouble[]cy;\n\tint count;\n\tint n;\n\tint r;\n\tsim(int nn,int rr){\n\t\tr=rr;\n\t\tn=nn;\n\t\tcx=new double[n];\n\t\tccx=new int[n];\n\t\tcy=new double[n];\n\t\tcount=0;\n\t}\n\tvoid add(int x) {\n\t\tdouble lowest=r;\n\t\tfor(int i=0;i<count;i++) {\n\t\t\tif(Math.abs(ccx[i]-x)<=2*r) {\n\t\t\t\tdouble dy=Math.sqrt(4*r*r-(ccx[i]-x)*(ccx[i]-x));\n\t\t\t\tlowest=Math.max(lowest,cy[i]+dy);\n\t\t\t}\n\t\t}\n\t\tccx[count]=x;\n\t\tcy[count]=lowest;\n\t\tcx[count++]=x;\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemA {\n\tpublic static void main(String[] args) throws Exception{\n\t\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tStringTokenizer st = new StringTokenizer(bf.readLine());\n\t\t\tStringTokenizer st1 = new StringTokenizer(bf.readLine());\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\tint r = Integer.parseInt(st.nextToken());\n\t\t\tint[] xcoords = new int[n];\n\t\t\tfor(int i = 0;i<n;i++){\n\t\t\t\txcoords[i] = Integer.parseInt(st1.nextToken());\n\t\t\t}\n\t\t\tdouble[] ycoords = new double[n];\n\t\t\t\n\t\t\tfor(int i = 0;i<n;i++){\n\t\t\t\tArrayList<Integer> nodes = new ArrayList<Integer>();\n\t\t\t\tfor(int j = 0;j<i;j++){\n\t\t\t\t\tif (Math.abs(xcoords[j] - xcoords[i]+0.0) <= 2*r)\n\t\t\t\t\t\tnodes.add(j);\n\t\t\t\t}\n\t\t\t\tif (nodes.isEmpty()){\n\t\t\t\t\tycoords[i] = r;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tdouble min = -1;\n\t\t\t\t\tfor(int k = 0;k<nodes.size();k++){\n\t\t\t\t\t\tdouble tmp = ycoords[nodes.get(k)] + Math.sqrt(4*r*r - (xcoords[i] - xcoords[nodes.get(k)])*(xcoords[i] - xcoords[nodes.get(k)]));\n\t\t\t\t\t\tif (tmp > min){\n\t\t\t\t\t\t\tmin = tmp;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tycoords[i] = min;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 0;i<ycoords.length;i++){\n\t\t\t\tSystem.out.print(ycoords[i] + \" \");\n\t\t\t}\n\t\t\t\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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 C {\n\n    public static void main(String[] args) {\n\n        MyScanner in = new MyScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        int n = in.nextInt();\n        int r = in.nextInt();\n\n        double[] y = new double[n];\n        int[] x = new int[n];\n\n        for(int i=0;i<n;++i){\n            x[i] = in.nextInt();\n            double bestY = r;\n            for(int j=0;j<i;++j){\n                if(Math.abs(x[i]-x[j]) <= 2*r){\n                    double ny = y[j] + Math.sqrt(4*r*r - (x[i]-x[j])*(x[i]-x[j]));\n                    if(ny > bestY){\n                        bestY = ny;\n                    }\n                }\n            }\n            y[i] = bestY;\n        }\n\n        for(int i=0;i<n;++i){\n            out.println(y[i]);\n        }\n\n        out.close();\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\npublic class Solution2 {\n\n\n    private void solve() throws IOException {\n        int n = in.nextInt();\n        double r = in.nextDouble();\n        List<Double> xes = new ArrayList<>(n);\n        List<Double> yes = new ArrayList<>(n);\n        for (int i = 0; i < n; i++) {\n            xes.add(in.nextDouble());\n        }\n        for (int i = 0; i < n; i++) {\n            double max = r;\n            for (int j = 0; j < i; j++) {\n                double x = xes.get(j);\n                double y = yes.get(j);\n                if (xes.get(i) <= x + 2 * r && xes.get(i) >= x - 2 * r) {\n                    max = Math.max(max, y + Math.sqrt(4 * r * r - Math.abs(x - xes.get(i))* Math.abs(x - xes.get(i))));\n                }\n            }\n            yes.add(max);\n        }\n        for (double y : yes) {\n            System.out.print(y + \" \");\n        }\n        System.out.println();\n        System.out.flush();\n    }\n\n    private static String filename = \"\";\n    private PrintWriter out;\n    private 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        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        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        }\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        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\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = sc.nextInt();\n\t\tint r = sc.nextInt();\n\t\t\n\t\tdouble ans[] = new double[n];\n\t\t\n\t\tint[] x = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = sc.nextInt();\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tans[i] = r;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tint d = Math.abs(x[i] - x[j]);\n\t\t\t\tif(d <= 2 * r) {\n\t\t\t\t\tans[i] = Math.max(ans[i], ans[j] + Math.sqrt(4 * r * r - d * d));\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tout.print(ans[i] + \" \");\n\t\t}\n\t\tout.println();\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String file) throws FileNotFoundException {\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 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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.*;\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner();\n\t\tint n = in.nextInt();\n\t\tdouble r = in.nextInt();\n\t\tdouble x[] = new double[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tx[i] = in.nextDouble();\n\t\t\n\t\tdouble y[] = new double[n];\n\t\ty[0] = r;\n\t\t\n\t\tfor(int i = 1; i < n; i++){\n\t\t\tdouble miny = r;\n\t\t\tfor(int j = 0; j < i; j++){\n\t\t\t\tdouble dx = Math.abs(x[i]-x[j]);\n\t\t\t\tif(dx > r*2) continue;\n\t\t\t\tdouble yy = Math.sqrt(4*r*r-dx*dx);\n\t\t\t\tminy = Math.max(miny, yy+y[j]);\n\t\t\t}\n\t\t\ty[i] = miny;\n\t\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tSystem.out.print(y[i]+\" \");\n\t\t}\n\t\t\n\n\t}\n\n\t\n\t\n\tstatic class FastScanner{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(String s) {\n\t\t\ttry{\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t}\n\t\t\tcatch(FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\tpublic FastScanner(){\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\n\t\tString nextToken()\t{\n\t\t\twhile(st == null ||!st.hasMoreElements()){\n\t\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\t\t\t\n\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(nextToken());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t\tString next() {\n\t\t\treturn nextToken();\n\t\t}\n\t\t\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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 n = Integer.parseInt(st.nextToken());\n\t\tint r = Integer.parseInt(st.nextToken());\n\t\tst = new StringTokenizer(s.nextLine());\n\t\tint[] array = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarray[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tArrayList<State> list = new ArrayList<State>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdouble currY = r;\n\t\t\tfor (int j = 0; j < list.size(); j++) {\n\t\t\t\tdouble xDiff = Math.abs(list.get(j).getX() - array[i]);\n\t\t\t\tif (xDiff <= 2 * r) {\n\t\t\t\t\tif (currY < list.get(j).getY() + Math.sqrt(4 * r * r - xDiff * xDiff)) {\n\t\t\t\t\t\tcurrY = list.get(j).getY() + Math.sqrt(4 * r * r - xDiff * xDiff);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlist.add(new State(array[i], currY));\n\t\t\tSystem.out.print(currY + \" \");\n\t\t}\n\t\ts.close();\n\t}\n\n\tstatic class State {\n\t\tdouble x;\n\t\tdouble y;\n\n\t\tpublic State(double a, double b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\n\t\tpublic double getX() {\n\t\t\treturn x;\n\t\t}\n\n\t\tpublic double getY() {\n\t\t\treturn y;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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\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\tstatic class TaskC {\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint r = in.nextInt();\n\t\t\tint[] x = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tx[i] = in.nextInt();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\tdouble[] y = new double[n];\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tdouble curY = r;\n\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\tint d = Math.abs(x[i] - x[j]);\n\t\t\t\t\tif (d <= 2 * r) {\n\t\t\t\t\t\tint a2 = 4 * r * r - d * d;\n\t\t\t\t\t\tcurY = Math.max(curY, y[j] + Math.sqrt(a2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ty[i] = curY;\n\t\t\t\tout.printf(\"%.14f\", y[i]);\n\t\t\t\tif (i < n - 1) {\n\t\t\t\t\tout.print(\" \");\n\t\t\t\t} else {\n\t\t\t\t\tout.println();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic class InputReader {\n\t\tfinal InputStream is;\n\t\tfinal byte[] buf = new byte[1024];\n\t\tint pos;\n\t\tint size;\n\n\t\tpublic InputReader(InputStream is) {\n\t\t\tthis.is = is;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isWhitespace(c))\n\t\t\t\tc = read();\n\t\t\tint sign = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsign = -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 = res * 10 + c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isWhitespace(c));\n\t\t\treturn res * sign;\n\t\t}\n\n\t\tint read() {\n\t\t\tif (size == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (pos >= size) {\n\t\t\t\tpos = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsize = is.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 (size <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[pos++] & 255;\n\t\t}\n\n\t\tstatic boolean isWhitespace(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t}\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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 C {\n\n\tpublic static void main(String[] args){\n\t\tFastScanner scan = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = scan.nextInt(), r = scan.nextInt();\n\t\tint[] x = scan.nextIntArray(n);\n\t\tdouble[] y = new double[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tdouble best = 0;\n\t\t\tfor(int j = 0; j < i; j++) {\n\t\t\t\tif(Math.abs(dist(x[i], y[j], x[j], y[j])-2*r) <= 1e-7) {\n\t\t\t\t\tbest = Math.max(best, y[j]);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdouble lo = y[j]-r-r, hi = y[j]+r+r;\n\t\t\t\tfor(int bs = 0; bs < 200; bs++) {\n\t\t\t\t\tdouble mid = (lo+hi)/2.0;\n\t\t\t\t\tif(dist(x[i], mid, x[j], y[j])-2*r <= 1e-7) lo = mid;\n\t\t\t\t\telse hi = mid;\n\t\t\t\t}\n\t\t\t\tif(dist(x[i], lo, x[j], y[j])-2*r <= 1e-7) best = Math.max(best, lo);\n\t\t\t}\n\t\t\tif(best == 0) y[i] = r;\n\t\t\telse y[i] = best;\n\t\t}\n\t\tfor(int i = 0; i < n; i++) out.printf(\"%.6f \", y[i]);\n\t\tout.close();\n\t}\n\n\tstatic double dist(double x, double y, double xx, double yy) {return Math.sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));}\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\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.io.Reader;\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        MyInput in = new MyInput(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, MyInput in, PrintWriter out) {\n            int n = in.nextInt();\n            int r = in.nextInt();\n            int[] x = in.nextIntArray(n);\n            double[] py = new double[n];\n            for (int i = 0; i < n; i++) {\n                double y = r;\n                for (int j = 0; j < i; j++) {\n                    int dx = Math.abs(x[i] - x[j]);\n                    if (dx > 2 * r) continue;\n                    y = Math.max(y, Math.sqrt(4 * r * r - dx * dx) + py[j]);\n                }\n                py[i] = y;\n            }\n            for (int i = 0; i < n; i++) {\n                out.printf(\"%.10f%s\", py[i], i == n - 1 ? \"\\n\" : \" \");\n            }\n        }\n\n    }\n\n    static class MyInput {\n        private final BufferedReader in;\n        private static int pos;\n        private static int readLen;\n        private static final char[] buffer = new char[1024 * 8];\n        private static char[] str = new char[500 * 8 * 2];\n        private static boolean[] isDigit = new boolean[256];\n        private static boolean[] isSpace = new boolean[256];\n        private static boolean[] isLineSep = new boolean[256];\n\n        static {\n            for (int i = 0; i < 10; i++) {\n                isDigit['0' + i] = true;\n            }\n            isDigit['-'] = true;\n            isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n            isLineSep['\\r'] = isLineSep['\\n'] = true;\n        }\n\n        public MyInput(InputStream is) {\n            in = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public int read() {\n            if (pos >= readLen) {\n                pos = 0;\n                try {\n                    readLen = in.read(buffer);\n                } catch (IOException e) {\n                    throw new RuntimeException();\n                }\n                if (readLen <= 0) {\n                    throw new MyInput.EndOfFileRuntimeException();\n                }\n            }\n            return buffer[pos++];\n        }\n\n        public int nextInt() {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(len, isSpace);\n            int i = 0;\n            int ret = 0;\n            if (str[0] == '-') {\n                i = 1;\n            }\n            for (; i < len; i++) ret = ret * 10 + str[i] - '0';\n            if (str[0] == '-') {\n                ret = -ret;\n            }\n            return ret;\n        }\n\n        public char nextChar() {\n            while (true) {\n                final int c = read();\n                if (!isSpace[c]) {\n                    return (char) c;\n                }\n            }\n        }\n\n        int reads(int len, boolean[] accept) {\n            try {\n                while (true) {\n                    final int c = read();\n                    if (accept[c]) {\n                        break;\n                    }\n                    if (str.length == len) {\n                        char[] rep = new char[str.length * 3 / 2];\n                        System.arraycopy(str, 0, rep, 0, str.length);\n                        str = rep;\n                    }\n                    str[len++] = (char) c;\n                }\n            } catch (MyInput.EndOfFileRuntimeException e) {\n            }\n            return len;\n        }\n\n        public int[] nextIntArray(final int n) {\n            final int[] res = new int[n];\n            for (int i = 0; i < n; i++) {\n                res[i] = nextInt();\n            }\n            return res;\n        }\n\n        static class EndOfFileRuntimeException extends RuntimeException {\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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        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.readInt();\n            int r = in.readInt();\n            int[] x = IOUtils.readIntArray(in, n);\n            double[] y = new double[n];\n            for (int idx = 0; idx < x.length; idx++) {\n                double yRes = r;\n                for (int prev = 0; prev < idx; prev++) {\n                    int xDelta = Math.abs(x[idx] - x[prev]);\n                    if (xDelta <= 2 * r) {\n                        // then we intersect with prev\n                        double yDelta = calcDelta(xDelta, r);\n                        yRes = Math.max(yRes, y[prev] + yDelta);\n                    }\n                }\n                y[idx] = yRes;\n            }\n            out.printLine(y);\n        }\n\n        private double calcDelta(int xDelta, int r) {\n            return Math.sqrt(4 * r * r - xDelta * xDelta);\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(double[] array) {\n            for (int i = 0; i < array.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(array[i]);\n            }\n        }\n\n        public void printLine(double[] array) {\n            print(array);\n            writer.println();\n        }\n\n        public void close() {\n            writer.close();\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 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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n/**\n *\n * @author msagimbekov\n */\npublic class Codeforces908C {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int r = sc.nextInt();\n        int[] x = new int[n];\n        double[] res = new double[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = sc.nextInt();\n            res[i] = (double)r;\n            for (int j = i - 1; j >= 0; j--) {\n                int diff = x[j] - x[i];\n                if (Math.abs(x[j] - x[i]) <= 2 * r) {\n                    res[i] = Math.max(res[i], res[j] + Math.sqrt(4 * r * r - diff * diff));\n                }\n            }\n        }\n        \n        for (int i = 0; i < n; i++) {\n            System.out.print(res[i] + \" \");\n        }\n        System.out.println(\"\");\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class NewYearCurling908C {\n    public static void main(String[] args) throws IOException {\n        FastScanner in = new FastScanner();\n        int n = in.nextInt();\n        \n        double r = (double) in.nextInt();\n        double[] answers = new double[n];\n        double[] xCoords = new double[n];\n        for (int i = 0; i < n; i++) xCoords[i] = (double) in.nextInt();\n        \n        answers[0] = r;\n        for (int i = 1; i < n; i++) {\n            double bound = r;\n            for (int j = 0; j < i; j++) {\n                double xDif = xCoords[i] - xCoords[j];\n                double y = answers[j];\n                double yNew = y + Math.sqrt(4 * r * r - xDif * xDif);\n                if (yNew > bound) bound = yNew;\n            }\n            answers[i] = bound;\n        }\n        for (int i = 0; i < n; i++) System.out.print(answers[i] + \" \");\n        System.out.println();\n    }\n\n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner(String s) {\n            try {\n                br = new BufferedReader(new FileReader(s));\n            } catch (FileNotFoundException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n        }\n\n        public FastScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        String nextToken() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    // TODO Auto-generated catch block\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        String nextLine() {\n            st = null;\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n            return null;\n        }\n\n        int nextInt() {\n            return Integer.parseInt(nextToken());\n        }\n\n        long nextLong() {\n            return Long.parseLong(nextToken());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(nextToken());\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class ProblemD\n{\n\n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    \n    static void solve()\n    {\n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out);            \n        \n        int n = in.nextInt();\n        int r = in.nextInt();\n        double[] x = new double[n];\n        double[] y = new double[n];\n        \n        for(int i = 0; i < n; i++){\n            int xx = in.nextInt();\n            x[i] = xx;\n            y[i] = r;\n            for(int j = 0; j < i; j++){\n                double delx = Math.abs(x[i] - x[j]);\n                //debug(delx);\n                if(delx <= 2 * r){\n                    double tmp = 4 * r * r - delx * delx;\n                    tmp = Math.sqrt(tmp);\n                    tmp = y[j] + tmp;\n                    y[i] = Math.max(y[i], tmp);\n                }\n            }\n            out.print(y[i] + \" \");\n        }\n        \n        out.close();\n    }\n    \n    public static void main(String[] args)\n    {\n        new Thread(null ,new Runnable(){\n            public void run(){\n                try{\n                    solve();\n                } catch(Exception e){\n                    e.printStackTrace();\n                }\n            }\n        },\"1\",1<<26).start();\n        \n    }\n\n    static class Pair implements Comparable<Pair>\n    {\n\n        long x,y;\n\n        Pair (long x,long y)\n        {\n                this.x = x;\n                this.y = y;\n        }\n        public int compareTo(Pair o)\n        {\n            return Long.compare(this.x,o.x);\n                //return 0;\n        }\n\n        public boolean equals(Object o)\n        {\n            if (o instanceof Pair)\n            {\n                Pair p = (Pair)o;\n                return p.x == x && p.y==y;\n            }\n            return false;\n        }\n\n        @Override\n        public String toString()\n        {\n            return x + \" \"+ y ;\n        }\n\n        /*public int hashCode()\n        {\n            return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n        }*/\n\n    } \n\n    static long add(long a,long b){\n        long x=(a+b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n\n    static long sub(long a,long b){\n        long x=(a-b);\n        while(x<0) x+=mod;\n        return x;\n    }\n    \n    static long mul(long a,long b){\n        long x=(a*b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n    \n    static String rev(String s){\n        StringBuilder sb=new StringBuilder(s);\n        sb.reverse();\n        return sb.toString();\n    }\n    \n    static long gcd(long x,long y)\n    {\n        if(y==0)\n                return x;\n        else\n                return gcd(y,x%y);\n    }\n\n    static int gcd(int x,int y)\n    {\n        if(y==0)\n                return x;\n        else \n                return gcd(y,x%y);\n    }\n\n    static long pow(long n,long p,long m)\n    {\n         long  result = 1;\n          if(p==0){\n            return 1;\n          }\n          \n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\n            if(result >= m)\n               result %= m;\n            p >>=1;\n            n*=n;\n            if(n >= m)\n                n%=m;\n        }\n        \n        return result;\n    }\n\n    static long pow(long n,long p)\n    {\n        long  result = 1;\n          if(p==0)\n            return 1;\n\n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\t    \n            p >>=1;\n            n*=n;\t    \n        }\n        return result;\n    }\n\n    static void debug(Object... o)\n    {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "/*\n * \n * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)\n * Dhirubhai Ambani Institute of Information And Communication Technology \n * \n */\n\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\npublic class Code3\n{\n\t\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\t\n\t\tint n = in.nextInt();\n\t\tdouble r = (double)in.nextInt();\n\t\tdouble [] a = new double[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i] = (double)in.nextInt();\n\t\tdouble[] ans = new double[n];\n\t\tans[0] = r;\n\n\t\tfor(int i=1;i<n;i++)\n\t\t{\n\t\t\tdouble max = Double.MIN_VALUE;\n\t\t\tfor(int j=0;j<i;j++)\n\t\t\t{\n\t\t\t\tif(Math.abs(a[i]-a[j])<=2*r)\n\t\t\t\t{\n\t\t\t\t\t//System.out.println(j);\n\t\t\t\t\tdouble cur = 4*r*r;\n\t\t\t\t\tcur -= ((a[i]-a[j])*(a[i]-a[j]));\n\t\t\t\t\tcur = Math.sqrt(cur);\n\t\t\t\t\tcur += ans[j];\n\t\t\t\t\t//System.out.println(r);\n\t\t\t\t\tmax = Math.max(max, cur);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(max == Double.MIN_VALUE)\n\t\t\t\tans[i] = r;\n\t\t\telse \n\t\t\t\tans[i] = max;\n\t\t}\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t\tpw.print(ans[i] + \" \");\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic class InputReader \n\t{\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{\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() \n\t\t{\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) \n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() \n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t    {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong()\n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nextIntArray(int n) \n\t\t{\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String readString()\n\t    {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() \n\t\t{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) \n\t\t{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter\n\t    {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\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<n;i++)\n\t\t{\n\t\t\tint ind = gen.nextInt(n-i)+i;\n\t\t\tint temp = a[ind];\n\t\t\ta[ind] = a[i];\n\t\t\ta[i] = temp;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\tpublic static void swap(int a, int b){\n\t\tint temp = a;\n\t\ta = b;\n\t\tb = temp;\n\t}\n\t\n\tpublic static HashSet<Integer> primeFactorization(int n)\n\t{\n\t\tHashSet<Integer> a =new HashSet<Integer>();\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<n;i++)\n\t\t\tisPrime[i] = true;\n\t\t\n\t\tisPrime[0] = false;\n\t\tisPrime[1] = false;\n\t\t\n\t\tfor(int i=2;i*i<n;i++)\n\t\t{\n\t\t\tif(isPrime[i] == true)\n\t\t\t{\n\t\t\t\tfor(int j=(2*i);j<n;j+=i)\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t}\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\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 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<pair>\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint r = sc.nextInt();\n\t\tint d = 2 * r;\n\t\tint[] xCoordinates = new int[n];\n\t\tdouble[] yCoordinates = new double[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tyCoordinates[i] = r;\n\t\tfor (int i = 0; i < n; i++)\n\t\t\txCoordinates[i] = sc.nextInt();\n\t\tdouble y = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ty = r;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tif (Math.abs(xCoordinates[i] - xCoordinates[j]) <= 2 * r) {\n\t\t\t\t\tint dx = Math.abs(xCoordinates[i] - xCoordinates[j]);\n\t\t\t\t\tdouble dy = Math.sqrt(d * d - dx * dx);\n\t\t\t\t\tif (dy + yCoordinates[j] > y)\n\t\t\t\t\t\ty = dy + yCoordinates[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tyCoordinates[i]=y;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tSystem.out.print(yCoordinates[i] + \" \");\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C\n{\n   static long time = System.currentTimeMillis();\n   public static void main(String[] args) throws IOException\n   {\n      //FastReader infile = new FastReader(\"test.txt\");\n      FastReader infile = new FastReader(System.in);\n      int N = infile.nextInt();\n      int R = infile.nextInt();\n      double[] xPos = new double[N];\n      for(int x = 0; x < N; x++)\n         xPos[x] = infile.nextDouble();\n      double[] yPos = new double[N];\n      Arrays.fill(yPos, R);\n      for(int x = 1; x < N; x++)\n      {\n         for(int y = 0; y < x; y++)\n            if(Math.abs(xPos[x]-xPos[y])<=2*R)\n            {\n               yPos[x] = Math.max(yPos[x], yPos[y]+Math.sqrt((2*R)*(2*R)-Math.abs(xPos[x]-xPos[y])*Math.abs(xPos[x]-xPos[y])));\n            }\n      }\n      System.out.print(yPos[0]);\n      for(int x = 1; x < N; x++)\n         System.out.print(\" \"+yPos[x]);\n      //System.out.println(System.currentTimeMillis()-time);\n   }\n}\nclass FastReader\n{\n   BufferedReader br;\n   StringTokenizer st;\n\n   public FastReader(String file) throws IOException\n   {\n      br = new BufferedReader(new FileReader(file));\n   }\n \n   public FastReader(InputStream i) throws IOException\n   {\n      br = new BufferedReader(new InputStreamReader(System.in));\n   }\n   boolean hasNext()\n   {\n      while (st == null || !st.hasMoreElements())\n      {\n         try\n         {\n            st = new StringTokenizer(br.readLine());\n         }\n         catch (Exception  e)\n         {\n            return false;\n         }\n      }\n      return true;\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author khokharnikunj8\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        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, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int r = in.scanInt(), temp;\n            double max1;\n            double high[] = new double[1002];\n            for (int i = 0; i < n; i++) {\n                temp = in.scanInt();\n                max1 = high[temp] + ((high[temp] == 0) ? r : +(2 * r));\n                for (int j = temp - 1; j > temp - (2 * r) && j > 0; j--) {\n                    if (high[j] == 0) continue;\n                    max1 = Math.max(max1, high[j] + Math.sqrt((4 * r * r) - ((temp - j) * (temp - j))));\n                }\n                for (int j = temp + 1; j <= 1000 && j < temp + (2 * r); j++) {\n                    if (high[j] == 0) continue;\n                    max1 = Math.max(max1, high[j] + Math.sqrt((4d * r * r) - (((j - temp) * (j - temp)))));\n                }\n                if (temp - (2 * r) > 0) max1 = Math.max(high[temp - (2 * r)], max1);\n                if (temp + (2 * r) <= 1000) max1 = Math.max(high[temp + (2 * r)], max1);\n                high[temp] = max1;\n                out.print(max1 + \" \");\n\n            }\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.* ;\nimport java.util.* ;\nimport java.text.* ;\nimport java.math.* ;\nimport static java.lang.Math.min ;\nimport static java.lang.Math.max ;\nimport static java.lang.Math.sqrt ;\npublic class Codeshefcode{\n\tpublic static void main(String[] args) throws IOException{\n\t\tSolver Machine = new Solver() ;\n\t\tMachine.Solve() ;\n\t\tMachine.Finish() ;\n\t\t// new Thread(null,new Runnable(){\n\t\t// \tpublic void run(){\n\t\t// \t\tSolver Machine = new Solver() ;\n\t\t// \t\ttry{\n\t\t// \t\t\tMachine.Solve() ;\n\t\t// \t\t\tMachine.Finish() ;\n\t\t// \t\t}catch(Exception e){\n\t\t// \t\t\te.printStackTrace() ;\n\t\t// \t\t\tSystem.out.flush() ;\n\t\t// \t\t\tSystem.exit(-1) ;\n\t\t// \t\t}catch(Error e){\n\t\t// \t\t\te.printStackTrace() ;\n\t\t// \t\t\tSystem.out.flush() ;\n\t\t// \t\t\tSystem.exit(-1) ;\n\t\t// \t\t}\n\t\t// \t}\n\t\t// },\"Solver\",1l<<27).start() ;\n\t}\n}\nclass Mod{\n\tstatic long mod=1000000007 ;\n\tstatic long d(long a,long b){ return (a*MI(b))%mod ; }\n\tstatic long m(long a,long b){ return (a*b)%mod ; }\n\tstatic private long MI(long a){ return pow(a,mod-2) ; }\n\tstatic long pow(long a,long b){\n\t\tif(b<0) return pow(MI(a),-b) ;\n\t\tlong val=a ; long ans=1 ;\n\t\twhile(b!=0){\n\t\t\tif((b&1)==1) ans = (ans*val)%mod ; \n\t\t\tval = (val*val)%mod ; \n\t\t\tb/=2 ;\n\t\t}\n\t\treturn ans ;\n\t}\t\n}\nclass pair implements Comparable<pair>{\n\tint x ; int y ; \n\tpair(int x,int y){ this.x=x ; this.y=y ;} \n\tpublic int compareTo(pair p){\n\t\treturn (this.x<p.x ? -1 : (this.x>p.x ? 1 : (this.y<p.y ? -1 : (this.y>p.y ? 1 : 0)))) ;\n\t}\n}\nclass Solver{\n\tReader ip = new Reader(System.in) ;\t  \n\tPrintWriter op = new PrintWriter(System.out) ;\n\tpublic void Solve() throws IOException{\n\t\tint n = ip.i() ; int r = ip.i() ;\n\t\tdouble x[] = new double[n] ;\n\t\tdouble y[] = new double[n] ;\n\t\tfor(int i=0 ; i<n ; i++) x[i] = ip.i() ;\n\t\tfor(int i=0 ; i<n ; i++){\n\t\t\tdouble my = 0 ;\n\t\t\tfor(int j=0 ; j<i ; j++)\n\t\t\t\tmy = max(my,func(x[j],y[j],r,x[i])) ;\n\t\t\ty[i] = my ;\n\t\t}\n\t\tfor(int i=0 ; i<n ; i++) p((y[i]+r)+\" \") ;\n\t\tpln(\"\") ; \n\t}\n\tdouble abd(double x,double y){\n\t\treturn x>y ? x-y : y-x ;\n\t}\n\tdouble func(double x1,double y1,double r,double x2){\n\t\tif(abd(x1,x2)>(2*r)) return 0 ;\n\t\tif(abd(x1,x2)==(2*r)) return y1 ;\n\t\tdouble dx = x1-x2 ; \n\t\tdouble dx2 = dx*dx ; \n\t\tdouble val = sqrt(4*r*r-dx2) ;\n\t\treturn y1+val ;\n\t}\n\tvoid Finish(){\n\t\top.flush();\n\t\top.close();\n\t}\n\tvoid p(Object o){\n\t\top.print(o) ;\n\t}\n\tvoid pln(Object o){\n\t\top.println(o) ;\n\t}\t\t\n}\nclass mylist extends ArrayList<Integer>{}\nclass myset extends TreeSet<Integer>{}\nclass mystack extends Stack<Integer>{}\nclass mymap extends TreeMap<Long,Integer>{}\nclass Reader{\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tReader(InputStream input) {\n\t\treader = new BufferedReader(\n\t\t\t\t\tnew InputStreamReader(input) );\n\t\ttokenizer = new StringTokenizer(\"\") ;\n\t}\n\tString s() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()){\n\t\t\ttokenizer = new StringTokenizer(\n\t\t\treader.readLine()) ;\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\tint i() throws IOException {\n\t\treturn Integer.parseInt(s()) ;\n\t}\n\tlong l() throws IOException{\n\t\treturn Long.parseLong(s()) ;\n\t}\n\tdouble d() throws IOException {\n\t\treturn Double.parseDouble(s()) ;\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class C extends PrintWriter {\n\n    void run() {\n\n        int n = nextInt();\n        int r = nextInt();\n        int[] x = nextArray(n);\n\n        double[] y = new double[n];\n        Arrays.fill(y, r);\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < i; j++) {\n                int dx = abs(x[i] - x[j]);\n                int sdy = 4 * r * r - dx * dx;\n\n                if (sdy >= 0) {\n                    double dy = sqrt(sdy);\n                    y[i] = max(y[i], y[j] + dy);\n                }\n            }\n        }\n\n        for (double v : y) {\n            printf(Locale.ENGLISH, \"%.10f \", v);\n        }\n\n    }\n\n    boolean skip() {\n        while (hasNext()) {\n            next();\n        }\n        return true;\n    }\n\n    int[][] nextMatrix(int n, int m) {\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] = nextInt();\n        return matrix;\n    }\n\n    String next() {\n        while (!tokenizer.hasMoreTokens())\n            tokenizer = new StringTokenizer(nextLine());\n        return tokenizer.nextToken();\n    }\n\n    boolean hasNext() {\n        while (!tokenizer.hasMoreTokens()) {\n            String line = nextLine();\n            if (line == null) {\n                return false;\n            }\n            tokenizer = new StringTokenizer(line);\n        }\n        return true;\n    }\n\n    int[] nextArray(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    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 reader.readLine();\n        } catch (IOException err) {\n            return null;\n        }\n    }\n\n    public C(OutputStream outputStream) {\n        super(outputStream);\n    }\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer = new StringTokenizer(\"\");\n    static Random rnd = new Random();\n    static boolean OJ;\n\n    public static void main(String[] args) throws IOException {\n        OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n        C solution = new C(System.out);\n        if (OJ) {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            solution.run();\n        } else {\n            reader = new BufferedReader(new FileReader(new File(C.class.getName() + \".txt\")));\n            long timeout = System.currentTimeMillis();\n            while (solution.hasNext()) {\n                solution.run();\n                solution.println();\n                solution.println(\"----------------------------------\");\n            }\n            solution.println(\"time: \" + (System.currentTimeMillis() - timeout));\n        }\n        solution.close();\n        reader.close();\n    }\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\n    public void solve() throws IOException {\n        int n = nextInt(), r = nextInt();\n        int x[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = nextInt();\n        }\n        double res[] = new double[n];\n        res[0] = r;\n        for (int i = 1; i < n; i++) {\n            double max = r;\n            for (int j = 0; j < i; j++) {\n                int d = Math.abs(x[i] - x[j]);\n                if(d <= 2 * r){\n                    double yy = Math.sqrt(4 * r * r - d * d);\n                    max = Math.max(max, yy + res[j]);\n                }\n            }\n            res[i] = max;\n        }\n        for (int i = 0; i < n; i++) {\n            out.print(res[i] + \" \");\n        }\n    }\n\n    BufferedReader br;\n    StringTokenizer sc;\n    PrintWriter out;\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        new Main().run();\n    }\n\n    void run() throws IOException {\n        try {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n//            br = new BufferedReader(new FileReader(\"pnumbers.in\"));\n//            out = new PrintWriter(new File(\"out.txt\"));\n            solve();\n            out.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\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                return null;\n            }\n        }\n        return sc.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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class CC {\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();\n\t\tint r=sc.nextInt();\n\t\tint [] x=new int [n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tx[i]=sc.nextInt();\n\t\tdouble [] ans=new double [n];\n\t\tans[0]=r;\n\t\tfor(int i=1;i<n;i++){\n\t\t\tans[i]=r;\n\t\t\tfor(int j=0;j<i;j++){\n\t\t\t\tdouble dx=Math.abs(x[i]-x[j]);\n\t\t\t\tif(dx>2*r)\n\t\t\t\t\tcontinue;\n\t\t\t\tdouble y=Math.sqrt((4*r*r)-(dx*dx));\n\t\t\t\tans[i]=Math.max(ans[i], ans[j]+y);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tfor(double z : ans)\n\t\t\tpw.print(z+\" \");\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic 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() {while (st == null || !st.hasMoreElements()) {\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (IOException e) {e.printStackTrace();}}\n\t\treturn st.nextToken();}\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\tString nextLine(){String str = \"\";\n\t\ttry {str = br.readLine();}\n\t\tcatch (IOException e) {e.printStackTrace();}\n\t\treturn str;}\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\npublic class Main {\n\n\tprivate static void solve() {\n\t\tint n = ni();\n\t\tdouble r = ni();\n\n\t\tdouble[][] p = new double[n][2];\n\t\tdouble EPS = 0.0000000000001;\n\n\t\tfor (int i = 0; i < n; i ++) {\n\t\t\tdouble x = ni();\n\t\t\tdouble y = r;\n\t\t\tfor (int j = 0; j < i; j ++) {\n\t\t\t\tdouble dx = Math.abs(p[j][0] - x);\n\t\t\t\tif (dx <= r * 2 + EPS) {\n\t\t\t\t\tdouble dy = Math.sqrt(4.0 * r * r - dx * dx);\n\t\t\t\t\ty = Math.max(y, p[j][1] + dy);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.printf(\"%.12f \", y);\n\t\t\tp[i][0] = x;\n\t\t\tp[i][1] = y;\n\t\t}\n\t\tout.println();\n\t}\n\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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\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 r=ir.nextInt();\n\t\tint[] x=ir.nextIntArray(n);\n\t\tdouble[] ret=new double[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tdouble ma=r;\n\t\t\tfor(int j=0;j<i;j++){\n\t\t\t\tif(Math.abs(x[i]-x[j])<=2*r){\n\t\t\t\t\tma=Math.max(ma,ret[j]+Math.sqrt(4*(double)Math.pow(r, 2)-Math.pow(x[i]-x[j],2)));\n\t\t\t\t}\n\t\t\t}\n\t\t\tret[i]=ma;\n\t\t}\n\t\tfor(int i=0;i<n;i++){\n\t\t\tout.print(ret[i]+(i==n-1?\"\\n\":\" \"));\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class NewYearsCurling {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\n\t\tStringTokenizer st = new StringTokenizer(sc.nextLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint r = Integer.parseInt(st.nextToken());\n\n\t\tArrayList<Integer> centers = new ArrayList<Integer>();\n\t\tst = new StringTokenizer(sc.nextLine());\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcenters.add(Integer.parseInt(st.nextToken()));\n\t\t}\n\t\tsc.close();\n\t\tArrayList<Point> finalpoints = new ArrayList<Point>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdouble maxy = r;\n\t\t\tfor (int j = 0; j < finalpoints.size(); j++) {\n\t\t\t\tif (finalpoints.get(j).x - centers.get(i) > 2 * r || centers.get(i) - finalpoints.get(j).x > 2 * r)\n\t\t\t\t\tcontinue;\n\t\t\t\tdouble dist = Math.sqrt(\n\t\t\t\t\t\t4 * r * r - (finalpoints.get(j).x - centers.get(i)) * (finalpoints.get(j).x - centers.get(i)))\n\t\t\t\t\t\t+ finalpoints.get(j).y;\n\t\t\t\tif(dist > maxy)\n\t\t\t\t\tmaxy = dist;\n\t\t\t}\n\t\t\t\n\t\t\tpw.print(maxy + \" \");\n\t\t\tfinalpoints.add(new Point(centers.get(i), maxy));\n\t\t}\n\t\t\n\t\tpw.close();\n\t}\n\n\tpublic static class Point {\n\t\tdouble x;\n\t\tdouble 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}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        TaskC.InputReader in = new TaskC.InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.Solve(in, out);\n        out.close();\n    }\n\n\n    static class TaskC {\n\n        void Solve(InputReader in, PrintWriter out) {\n            int n = in.NextInt();\n            double r = in.NextInt();\n            double[] x = new double[n];\n            for (int i = 0; i < n; i++) x[i] = in.NextInt();\n            double[] y = new double[n];\n            for (int i = 0; i < n; i++) {\n                double maxY = r;\n                for (int j = 0; j < i; j++) {\n                    if (Math.abs(x[i] - x[j]) <= 2 * r) {\n                        double currentY = Math.sqrt((2 * r) * (2 * r) - (x[i] - x[j]) * (x[i] - x[j])) + y[j];\n                        maxY = Math.max(maxY, currentY);\n                    }\n                }\n                y[i] = maxY;\n            }\n            out.print(y[0]);\n            for (int i = 1; i < n; i++) {\n                out.print(\" \" + y[i]);\n            }\n            out.println();\n        }\n\n        static int GetMax(int[] ar) {\n            int max = Integer.MIN_VALUE;\n            for (int a : ar) {\n                max = Math.max(max, a);\n            }\n            return max;\n        }\n\n        static int GetMin(int[] ar) {\n            int min = Integer.MAX_VALUE;\n            for (int a : ar) {\n                min = Math.min(min, a);\n            }\n            return min;\n        }\n\n        static long GetSum(int[] ar) {\n            long s = 0;\n            for (int a : ar) s += a;\n            return s;\n        }\n\n        static int[] GetCount(int[] ar) {\n            return GetCount(ar, GetMax(ar));\n        }\n\n        static int[] GetCount(int[] ar, int maxValue) {\n            int[] dp = new int[maxValue + 1];\n            for (int a : ar) {\n                dp[a]++;\n            }\n            return dp;\n        }\n\n        static class InputReader {\n            BufferedReader reader;\n            StringTokenizer tokenizer;\n\n            InputReader(InputStream stream) {\n                reader = new BufferedReader(new InputStreamReader(stream), 32768);\n                tokenizer = null;\n            }\n\n            String Next() {\n                while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                    try {\n                        tokenizer = new StringTokenizer(reader.readLine(), \" \\t\\n\\r\\f,\");\n                    } catch (IOException e) {\n                        throw new RuntimeException(e);\n                    }\n                }\n                return tokenizer.nextToken();\n            }\n\n            int NextInt() {\n                return Integer.parseInt(Next());\n            }\n\n            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                return NextIntArray(n, 0);\n            }\n\n            int[] NextIntArray(int n, int offset) {\n                int[] a = new int[n];\n                for (int i = 0; i < n; i++) {\n                    a[i] = NextInt() - offset;\n                }\n                return a;\n            }\n\n            int[][] NextIntMatrix(int n, int m) {\n                return NextIntMatrix(n, m, 0);\n            }\n\n            int[][] NextIntMatrix(int n, int m, int offset) {\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] = NextInt() - offset;\n                    }\n                }\n                return a;\n            }\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\npublic class Main {\n    public static void main(String[] args) {\n    \tScanner in=new Scanner(System.in);  \n    \tint n=in.nextInt(),r=in.nextInt();\n    \tdouble[] x=new double[n];\n    \tfor(int i=0; i<n; i++)\n    \t\tx[i]=in.nextInt();\n    \tdouble[] y=new double[n];\n    \tfor(int i=0; i<n; i++)\n    \t{\n    \t\ty[i]=r;\n    \t\tfor(int j=0; j<i; j++)\n    \t\t{\n    \t\t\t\n    \t\t\tif(Math.abs(x[j]-x[i])<=2*r)\n    \t\t\t{\n    \t\t\t\ty[i]=Math.max(y[i], y[j]+Math.sqrt(4*r*r-(x[i]-x[j])*(x[i]-x[j])));\n    \t\t\t}\n    \t\t}\n    \t}\n    \tfor(int i=0; i<n; i++)\n    \t\tSystem.out.print(y[i]+\" \");\n    }    \n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n\npublic class GB_A {\n    FastScanner in;\n    PrintWriter out;\n\n    public static void main(String[] arg) {\n        new GB_A().run();\n    }\n\n    public void solve() throws IOException {\n        int n = in.nextInt();\n        int r = in.nextInt();\n        int[] a = new int[n];\n        double[] ans = new double[n];\n        a[0] = in.nextInt();\n        ans[0] = r;\n        for (int i = 1; i < n; i++) {\n            a[i] = in.nextInt();\n            double max = r;\n            for (int j = i - 1; j >= 0; j--) {\n                if (Math.abs(a[i] - a[j]) <= 2 * r) {\n                    double d = Math.sqrt(4 * r * r - (a[i]- a[j]) * (a[i] - a[j])) + ans[j];\n                    max = Math.max(max, d);\n                }\n\n            }\n            ans[i] = max;\n        }\n        for (int i = 0; i < n; i++) {\n            out.println(ans[i]);\n        }\n    }\n\n\n    public void run() {\n        try {\n            in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(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(BufferedReader bufferedReader) {\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        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n\n\n    }\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\t\npublic class Codeforces908C {\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 n = Integer.parseInt(st.nextToken());\n\t\tint r = Integer.parseInt(st.nextToken());\n\t\tint[] x = new int[n];\n\t\tst = new StringTokenizer(f.readLine());\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tx[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tdouble[] y = new double[n];\n\t\ty[0] = r;\n\t\tdouble hypSq = 4*r*r;\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tboolean hit = false;\n\t\t\tdouble maxY = 0;\n\t\t\tfor(int j = 0; j < i; j++) {\n\t\t\t\tint dx = Math.abs(x[i] - x[j]);\n\t\t\t\tif(dx == 2*r) {\n\t\t\t\t\tif(y[j] > maxY) {\n\t\t\t\t\t\tmaxY = y[j];\n\t\t\t\t\t\thit = true;\n\t\t\t\t\t}\n\t\t\t\t} else if(dx < 2*r) {\n\t\t\t\t\tdouble newY = y[j] + Math.sqrt(hypSq - dx*dx);\n\t\t\t\t\tif(newY > maxY) {\n\t\t\t\t\t\tmaxY = newY;\n\t\t\t\t\t\thit = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!hit) {\n\t\t\t\ty[i] = r;\n\t\t\t} else {\n\t\t\t\ty[i] = maxY;\n\t\t\t}\n\t\t}\n\t\tStringBuffer s = new StringBuffer(\"\");\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ts.append(y[i] + \" \");\n\t\t}\n\t\tSystem.out.println(s.toString().trim());\n\t}\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import com.sun.org.apache.regexp.internal.RE;\n\nimport java.io.*;\nimport java.nio.file.ClosedWatchServiceException;\nimport java.nio.file.OpenOption;\nimport java.security.SecureRandom;\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        //String test = \"C-large\";\n        //ConsoleIO io = new ConsoleIO(new FileReader(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + test + \".in\"), new PrintWriter(new File(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + test + \"-out.txt\")));\n\n       new Main(io).solve();\n\n        io.close();\n    }\n\n    ConsoleIO io;\n    Main(ConsoleIO io) {\n        this.io = io;\n    }\n\n    List<List<Integer>> gr = new ArrayList<>();\n    long MOD = 1_000_000_007;\n\n\n    public void solve() {\n        int n = io.ri(), r = io.ri();\n\n        double[] res = new double[n];\n        int[] xs = new int[n];\n        for(int i = 0;i<n;i++){\n            int x = io.ri();\n            xs[i] = x;\n            double max = r;\n            for(int j = 0;j<i;j++){\n                int dx = Math.abs(xs[j] - x);\n                int dx2 = dx*dx;\n                if(dx <= 2*r){\n                    max = Math.max(max, Math.sqrt(4*r*r - dx2) + res[j]);\n                }\n            }\n            res[i] = max;\n        }\n\n        StringBuilder sb = new StringBuilder();\n        for(int i = 0;i<res.length;i++){\n            if(i>0)sb.append(' ');\n            sb.append(res[i]);\n        }\n\n        io.writeLine(sb.toString());\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 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<n.length;i++)r[i]=Long.parseLong(n[i]);\n        return r;\n    }\n    public int[] readIntArray() {\n        String[]n=this.readLine().trim().split(\"\\\\s+\");int[]r=new int[n.length];\n        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);\n        return r;\n    }\n    public int[] readIntArray(int n) {\n        int[] res = new int[n];\n        char[] all = this.readLine().toCharArray();\n        int cur = 0;boolean have = false;\n        int k = 0;\n        boolean neg = false;\n        for(int i = 0;i<all.length;i++){\n            if(all[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}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class PC1229 {\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 r = sc.nextInt();\n\t\tint[] x = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tx[i] = sc.nextInt();\n\t\t}\n\t\tdouble[] ans = new double[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tdouble maxY = r;\n\t\t\tfor(int j = 0; j < i; j++){\n\t\t\t\tif(x[j] <= x[i] + 2*r && x[j] >= x[i] - 2*r){\n\t\t\t\t\tmaxY = Math.max(maxY, ans[j] + Math.sqrt(4 * r * r - (Math.abs(x[i] - x[j])) * (Math.abs(x[i] - x[j]))));\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[i] = maxY;\n\t\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tSystem.out.println(ans[i]);\n\t\t}\n\t\tsc.close();\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C {\n  public static void main (String args[]) {\n    Scanner in = new Scanner(System.in);\n    \n    int n = in.nextInt();\n    int r = in.nextInt();\n    \n    double pos[][] = new double[n][2];\n    \n    for(int i = 0; i < n; i++) {\n    \t\n    \tpos[i][0] = in.nextInt();\n    \t\n    \tdouble y = r;\n    \t\n    \tfor(int j = 0; j < i; j++) {\n    \t\tif(Math.abs(pos[i][0] - pos[j][0]) <= 2*r) {\n    \t\t\t\n    \t\t\tdouble tempy = pos[j][1] + Math.sqrt(Math.pow(2*r, 2) - Math.pow(Math.abs(pos[i][0] - pos[j][0]), 2));\n    \t\t\t\n    \t\t\tif(tempy > y) y = tempy;\n    \t\t}\n    \t}\n    \t\n    \tpos[i][1] = y;\n    \tSystem.out.print(y + \" \");\n    }\n  }\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "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.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 ilyakor\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            int r = in.nextInt();\n            ArrayList<PointDouble> centers = new ArrayList<>();\n            ArrayList<Integer> xs = new ArrayList<>();\n            for (int i = 0; i < n; ++i) {\n                int x = in.nextInt();\n                double y = r;\n                for (int j = 0; j < centers.size(); j++) {\n                    int ox = xs.get(j);\n                    if (Math.abs(ox - x) > 2 * r) continue;\n                    PointDouble c = centers.get(j);\n                    double t = Math.abs(ox - x);\n                    double h = Math.sqrt(Math.abs(4.0 * r * r - t * t));\n                    double val = c.y + h;\n                    if (y < val) y = val;\n                }\n                out.print(String.format(\"%.20f \", y));\n                centers.add(new PointDouble(x, y));\n                xs.add(x);\n            }\n            out.printLine();\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[] buffer = new byte[10000];\n        private int cur;\n        private int count;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public static boolean isSpace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public int read() {\n            if (count == -1) {\n                throw new InputMismatchException();\n            }\n            try {\n                if (cur >= count) {\n                    cur = 0;\n                    count = stream.read(buffer);\n                    if (count <= 0)\n                        return -1;\n                }\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            return buffer[cur++];\n        }\n\n        public int readSkipSpace() {\n            int c;\n            do {\n                c = read();\n            } while (isSpace(c));\n            return c;\n        }\n\n        public int nextInt() {\n            int sgn = 1;\n            int c = readSkipSpace();\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res = res * 10 + c - '0';\n                c = read();\n            } while (!isSpace(c));\n            res *= sgn;\n            return res;\n        }\n\n    }\n\n    static class PointDouble {\n        public double x;\n        public double y;\n\n        public PointDouble(double x, double y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        public PointDouble() {\n            x = 0;\n            y = 0;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class C {\n\tstatic double ycoord(double xi, double yi, double xj, double r) {\n\t\tif(Math.abs(xi-xj) > 2*r) return r;\n\t\tdouble dist = Math.sqrt((4*r*r)-((xi-xj)*(xi-xj)));\n\t\t//System.out.println(\"dist\" + dist);\n\t\treturn Math.max(yi+dist, r); //yi - dist?\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tdouble r = sc.nextInt();\n\t\tdouble[] xcoords = new double[n];\n\t\tdouble[] ycoords = new double[n];\n\t\tArrays.fill(ycoords, Integer.MIN_VALUE);\n\t\tycoords[0] = r;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\txcoords[i] = sc.nextDouble();\n\t\t}\n\t\tSystem.out.print(r + \" \");\n\t\tfor(int i = 1; i < n; ++i) {\n\t\t\tfor(int j = 0; j < i; j++) {\n\t\t\t\tycoords[i] = Math.max(ycoord(xcoords[j], ycoords[j],xcoords[i],r),ycoords[i]);\n\t\t\t}\n\t\t\tSystem.out.print(ycoords[i] + \" \");\n\t\t}\n\t\tout.flush();\n\t}\n\n\tstatic class FastScanner {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic FastScanner() {\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\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\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\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\n\t}\n}", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\nimport java.util.TreeMap;\n\nimport static java.lang.Math.abs;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.sqrt;\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        solveC();\n    }\n\n    private void solveA() throws IOException {\n        HashSet<Character> set = new HashSet<>();\n        for (char c : new char[]{'a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9'})\n            set.add(c);\n        int cnt = 0;\n        for (char c : in.nextLine().toCharArray())\n            if (set.contains(c))\n                cnt++;\n        out.println(cnt);\n    }\n\n    int n, m, cl;\n    char a[][];\n    int[] b;\n    int fromi, fromj, toi, toj;\n\n    private void solveB() throws IOException {\n        n = in.nextInt();\n        m = in.nextInt();\n        char[] c;\n        a = new char[n][m];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.next().toCharArray();\n        }\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (a[i][j] == 'S') {\n                    fromi = i;\n                    fromj = j;\n                }\n                if (a[i][j] == 'E') {\n                    toi = i;\n                    toj = j;\n                }\n            }\n        }\n\n        c = in.next().toCharArray();\n        cl = c.length;\n        b = new int[cl];\n        for (int i = 0; i < cl; i++) {\n            b[i] = c[i] - '0';\n        }\n\n        ArrayList<Long> ar1 = new ArrayList<>(), ar2 = new ArrayList<>(), ar3 = new ArrayList<>(), ar4 = new ArrayList<>();\n        ar1.add((long) 12);\n        ar1.add((long) 10);\n        ar1.add((long) 01);\n        ar1.add((long) 21);\n        long[] str = new long[4];\n        int ans = 0;\n        for (long i : ar1) {\n            str[0] = i;\n            ar2.clear();\n            ar2.addAll(ar1);\n            ar2.remove(i);\n\n            for (long j : ar2) {\n                str[1] = j;\n                ar3.clear();\n                ar3.addAll(ar2);\n                ar3.remove(j);\n\n                for (long k : ar3) {\n                    str[2] = k;\n                    ar4.clear();\n                    ar4.addAll(ar3);\n                    ar4.remove(k);\n\n                    str[3] = ar4.get(0);\n                    if (bfs(str))\n                        ans++;\n                }\n            }\n        }\n        out.println(ans);\n    }\n\n    private boolean bfs(long[] str) {\n        int[][] steps = {{(int) str[0] / 10 - 1, (int) str[0] % 10 - 1},\n                {(int) str[1] / 10 - 1, (int) str[1] % 10 - 1},\n                {(int) str[2] / 10 - 1, (int) str[2] % 10 - 1},\n                {(int) str[3] / 10 - 1, (int) str[3] % 10 - 1}};\n\n        for (int i = 0, ci = fromi, cj = fromj; i < cl; i++) {\n            ci += steps[b[i]][0];\n            cj += steps[b[i]][1];\n\n            if (ci >= n || ci < 0 || cj >= m || cj < 0 || a[ci][cj] == '#')\n                return false;\n\n            if (a[ci][cj] == 'E')\n                return true;\n        }\n\n        return false;\n    }\n\n    private void solveC() throws IOException {\n        int n = in.nextInt();\n        int r = in.nextInt();\n        int[] x = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = in.nextInt();\n        }\n\n        double[] y = new double[n];\n        for (int i = 0; i < n; i++) {\n            y[i] = r;\n            for (int j = 0; j < i; j++) {\n                if (abs(x[i] - x[j]) <= 2 * r) {\n                    y[i] = max(y[i], y[j] + sqrt(4.0 * r * r - (x[i] - x[j]) * (x[i] - x[j])));\n                }\n            }\n        }\n\n        for (double ty : y)\n            out.print(ty + \" \");\n        out.println();\n\n    }\n\n    private void solveD() throws IOException {\n\n    }\n\n    private void solveE() throws IOException {\n\n    }\n\n    private void solveF() throws IOException {\n\n    }\n\n    class FastScanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        FastScanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        String next() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n\n        boolean hasNext() throws IOException {\n            return br.ready() || (st != null && st.hasMoreTokens());\n        }\n\n        int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() throws IOException {\n            return Double.parseDouble(next());\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", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "//package info.stochastic;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\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\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int r = in.nextInt();\n\n            int x[] = new int[n];\n            for (int i = 0; i < n; i++) {\n                x[i] = in.nextInt();\n            }\n\n            double ans[] = new double[n];\n            ans[0] = r;\n            int index = 1;\n\n            for (int i = 1; i < n; i++) {\n                double maxY = r;\n                for (int j = 0; j < index; j++) {\n                    int xDist = Math.abs(x[i] - x[j]);\n                    if (xDist <= r * 2) {\n                        double cur = Math.sqrt((r * 2)*(r * 2) - xDist * xDist) + ans[j];\n                        //out.println(cur);\n                        maxY = Math.max(maxY, cur);\n                    }\n                }\n                //out.println();\n                ans[i] = maxY;\n                index++;\n            }\n\n            for (int i = 0; i < n; i++) {\n                out.print(ans[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}\n", "complexity": "quadratic", "problem": "908_C. New Year and Curling", "from": "CODEFORCES"}
{"src": "//package codeforces;\n\nimport java.util.Scanner;\n\npublic class Fingerprints {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tint[] code = new int[scanner.nextInt()];\n\t\tint[] prints = new int[scanner.nextInt()];\n\n\t\tfor (int i = 0; i < code.length; i++) {\n\t\t\tcode[i] = scanner.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < prints.length; i++) {\n\t\t\tprints[i] = scanner.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < code.length; i++) {\n\t\t\tfor (int j = 0; j < prints.length; j++) {\n\t\t\t\tif (code[i] == prints[j]) {\n\t\t\t\t\tSystem.out.print(prints[j] + \" \");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tscanner.close();\n\t}\n\n}\n", "complexity": "quadratic", "problem": "994_A. Fingerprints", "from": "CODEFORCES"}
{"src": "/**\n * Created by Baelish on 8/28/2018.\n */\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class F_DSU {\n    public static void main(String[] args)throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        \n        int brr[] = new int[2*n];\n        for (int i = 0; i < 2*n; i+= 2) {\n            brr[i] = in.nextInt();\n            brr[i+1] = in.nextInt();\n        }\n\n        arr = shrink(brr);\n        int imap[] = new int[2*n];\n        for (int i = 0; i < 2*n; i++) {\n            imap[arr[i]] = brr[i];\n        }\n\n        int idx = binarySearch(arr.length);\n        if(idx >= arr.length) pw.println(-1);\n        else pw.println(imap[idx]);\n\n        pw.close();\n    }\n    static int n, arr[];\n\n    static int binarySearch(int H) {\n        int lo = 0, hi = H, mid;\n        while (lo < hi) {\n            mid = (lo + hi) / 2;\n            if (check(mid)) hi = mid;\n            else lo = mid + 1;\n        }\n        if(lo > 0 && check(lo-1)) return lo-1;\n        return lo;\n    }\n\n    static boolean check(int m){\n        DSU dsu = new DSU(2*n);\n        for (int i = 0; i < n; i++) {\n            int u = arr[2*i], v = arr[2*i+1];\n            if(u > m) return false;\n            if(v > m){\n                if(++dsu.cycle[dsu.find(u)] >= 2) return false;\n            }\n            else{\n                if(!dsu.union(u, v)){\n                    if(++dsu.cycle[dsu.find(u)] >= 2) return false;\n                }\n                else{\n                    if(dsu.cycle[dsu.find(u)] >= 2) return false;\n                }\n            }\n        }\n        return true;\n    }\n\n    static class DSU{\n        int parent[], cycle[], n;\n        DSU(int N){\n            n = N;\n            parent = new int[N];\n            cycle = new int[N];\n            for(int i = 0; i < N; i++){\n                parent[i] = i;\n            }\n        }\n\n        DSU(int [] p){\n            parent = p; n = p.length;\n        }\n\n        int find(int i) {\n            int p = parent[i];\n            if (i == p) return i;\n            return parent[i] = find(p);\n        }\n\n        boolean equiv(int u, int v){\n            return find(u) == find(v);\n        }\n\n        boolean union(int u, int v){\n            u = find(u); v = find(v);\n            if(u != v) {\n                parent[u] = parent[v];\n                cycle[v] += cycle[u];\n            }\n            return u != v;\n        }\n\n        int count(){\n            int cnt = 0;\n            for(int i = 0; i < n; i++){\n                if(i == find(i)) cnt++;\n            }\n            return cnt;\n        }\n    }\n\n    public static int[] shrink(int[] a) {\n        int n = a.length;\n        long[] b = new long[n];\n        for(int i = 0;i < n;i++)b[i] = (long)a[i]<<32|i;\n        Arrays.sort(b);\n        int[] ret = new int[n];\n        int p = 0;\n        for(int i = 0;i < n;i++) {\n            if(i>0 && (b[i]^b[i-1])>>32!=0)p++;\n            ret[(int)b[i]] = p;\n        }\n        return ret;\n    }\n\n    static void debug(Object...obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n        static final int ints[] = new int[128];\n\n        public FastReader(InputStream is){\n            for(int i='0';i<='9';i++) ints[i]=i-'0';\n            this.is = is;\n        }\n\n        public 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        public boolean isSpaceChar(int c) {\n            return !(c >= 33 && c <= 126);\n        }\n        public int skip() {\n            int b;\n            while((b = readByte()) != -1 && isSpaceChar(b));\n            return b;\n        }\n\n        public String next(){\n            int b = skip();\n            StringBuilder sb = new StringBuilder();\n            while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n                sb.appendCodePoint(b);\n                b = readByte();\n            }\n            return sb.toString();\n        }\n\n        public int nextInt(){\n            int num = 0, b;\n            boolean minus = false;\n            while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n            if(b == '-'){\n                minus = true;\n                b = readByte();\n            }\n\n            while(true){\n                if(b >= '0' && b <= '9'){\n                    num = (num<<3) + (num<<1) + ints[b];\n                }else{\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public long nextLong() {\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<<3) + (num<<1) + ints[b];\n                }else{\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n       /* public char nextChar() {\n            return (char)skip();\n        }*/\n\n        public 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        /*private char buff[] = new char[1005];\n        public char[] nextCharArray(){\n            int b = skip(), p = 0;\n            while(!(isSpaceChar(b))){\n                buff[p++] = (char)b;\n                b = readByte();\n            }\n            return Arrays.copyOf(buff, p);\n        }*/\n    }\n}", "complexity": "quadratic", "problem": "1027_F. Session in BSU", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class FUck {\n\n\t\tpublic static void main(String args[])\n\t\t{\n\t\t\tScanner scan=new Scanner(System.in);\n\t\t\tint n=scan.nextInt();\n\t\t\tint k=scan.nextInt();\n\t\t\tString t=scan.next();\n\t\t\tint mx=0;\n\t\t\tfor(int i=1;i<n;i++)\n\t\t\t{\n\t\t\t\tint gd=1;\n\t\t\t\tfor(int j=0;j<i;j++)\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tif(t.charAt(j)!=t.charAt((n-i)+j))\n\t\t\t\t\t{\n\t\t\t\t\t\t\n\t\t\t\t\t\tgd=0;\n\t\t\t\t\t\t// i think i can break here\n\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tif(gd==1){\n\t\t\t\t\tmx=i;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.print(t);\n\t\t\tfor(int i=2;i<=k;i++)\n\t\t\t{\n\t\t\t\tfor(int j=mx;j<n;j++)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(t.charAt(j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n", "complexity": "quadratic", "problem": "1029_A. Many Equal Substrings", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class TestClass\n{\n   public static void main(String args[])\n   {\n   \tScanner in = new Scanner(System.in);\n   \tint n = in.nextInt();\n   \tint m = in.nextInt();\n   \tint k = in.nextInt();\n   \tint arr[] = new int[n+1];\n   \tfor(int i =0;i<n;i++)\n   \t arr[i+1]= in.nextInt();\n   \t\n   \tlong sum[] = new long [n+1];\n   \t\n   \tfor(int i=1;i<=n;i++)\n   \t sum[i]=sum[i-1]+arr[i];\n   \t\n    long dp[] = new long[n+1];\n\n    for(int i =1;i<=n;i++)\n    {\n      for(int j=i;j>i-m&&j>=1;j--)\n      {\n        long val = sum[i]-sum[j-1]+dp[j-1]-k;\n        dp[i]= Math.max(dp[i],val);\n      }\t\n    }\n    long max =0;\n    for(int i =1;i<=n;i++)\n     max=Math.max(max,dp[i]);\n    \n    System.out.println(max);\n     \n   }\t\n}", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n \nimport javax.lang.model.util.ElementScanner6;\n \nimport java.io.*;\n \npublic class Main {\n \n    public static void main(String[] args) {\n \n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader inp = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Solver solver = new Solver();\n        solver.solve(inp, out);\n        out.close();\n \n    }\n \n \n \n \n \n    static class Solver {\n\n        class pair implements Comparable<pair>{\n\n            int i;\n            long dist;\n            public pair(int i,long dist)\n            {\n                this.i=i;\n                this.dist=dist;\n            }\n\n            public int compareTo(pair p)\n            {\n                return Long.compare(this.dist,p.dist);\n            }\n\n        }\n \n        class Node implements Comparable < Node > {\n            int i;\n            int cnt;\n \n            Node(int i, int cnt) {\n                this.i = i;\n                this.cnt = cnt;\n            }\n \n            public int compareTo(Node n) {\n                if (this.cnt == n.cnt) {\n                    return Integer.compare(this.i, n.i);\n                }\n                return Integer.compare(this.cnt, n.cnt);\n            }\n        }\n \n        public boolean done(int[] sp, int[] par) {\n            int root;\n \n            root = findSet(sp[0], par);\n \n            for (int i = 1; i < sp.length; i++) {\n                if (root != findSet(sp[i], par))\n                    return false;\n            }\n            return true;\n        }\n        public int findSet(int i, int[] par) {\n            int x = i;\n            boolean flag = false;\n            while (par[i] >= 0) {\n                flag = true;\n                i = par[i];\n            }\n            if (flag)\n                par[x] = i;\n            return i;\n        }\n \n        public void unionSet(int i, int j, int[] par) {\n            int x = findSet(i, par);\n            int y = findSet(j, par);\n            if (x < y) {\n                par[y] = x;\n            } else {\n                par[x] = y;\n            }\n        }\n \n        public 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        public boolean isPrime(int n)\n        {\n            for(int i=2;i<n;i++)\n            {\n                if(n%i==0)\n                {\n                    return false;\n                }\n            }\n            return true;\n        }\n \n \n        public void minPrimeFactor(int n, int[] s) {\n            boolean prime[] = new boolean[n + 1];\n            Arrays.fill(prime, true);\n            s[1] = 1;\n            s[2] = 2;\n            for (int i = 4; i <= n; i += 2) {\n                prime[i] = false;\n                s[i] = 2;\n            }\n \n            for (int i = 3; i <= n; i += 2) {\n                if (prime[i]) {\n                    s[i] = i;\n                    for (int j = 2 * i; j <= n; j += i) {\n                        prime[j] = false;\n                        s[j] = i;\n                    }\n                }\n            }\n \n        }\n \n \n        public void findAllPrime(int n, ArrayList < Node > al, int s[]) {\n            int curr = s[n];\n            int cnt = 1;\n            while (n > 1) {\n                n /= s[n];\n                if (curr == s[n]) {\n                    cnt++;\n                    continue;\n \n                }\n                Node n1 = new Node(curr, cnt);\n                al.add(n1);\n \n                curr = s[n];\n                cnt = 1;\n            }\n        }\n \n \n \n        public int binarySearch(int n, int k) {\n            int left = 1;\n            int right = 100000000 + 5;\n            int ans = 0;\n            while (left <= right) {\n                int mid = (left + right) / 2;\n                if (n / mid >= k) {\n                    left = mid + 1;\n                    ans = mid;\n                } else {\n                    right = mid - 1;\n                }\n            }\n \n            return ans;\n        }\n        public boolean checkPallindrom(String s) {\n            char ch[] = s.toCharArray();\n \n            for (int i = 0; i < s.length() / 2; i++) {\n                if (ch[i] != ch[s.length() - 1 - i])\n                    return false;\n            }\n            return true;\n        }\n \n \n \n \n        public void remove(ArrayList < Integer > [] al, int x) {\n            for (int i = 0; i < al.length; i++) {\n                for (int j = 0; j < al[i].size(); j++) {\n \n                    if (al[i].get(j) == x)\n                        al[i].remove(j);\n \n                }\n            }\n        }\n \n        public long gcd(long a, long b) {\n            if (a == 0)\n                return b;\n            return gcd(b % a, a);\n        }\n \n \n        public void printDivisors(long n, ArrayList < Long > al) {\n            // Note that this loop runs till square root \n            for (long i = 1; i <= Math.sqrt(n); i++) {\n                if (n % i == 0) {\n                    // If divisors are equal, print only one \n                    if (n / i == i) {\n                        al.add(i);\n                    } else // Otherwise print both \n                    {\n                        al.add(i);\n                        al.add(n / i);\n                    }\n \n                }\n            }\n        }\n \n        public static long constructSegment(long seg[], long arr[], int low, int high, int pos) {\n            if (low == high) {\n                seg[pos] = arr[low];\n                return seg[pos];\n            }\n            int mid = (low + high) / 2;\n            long t1 = constructSegment(seg, arr, low, mid, (2 * pos) + 1);\n            long t2 = constructSegment(seg, arr, mid + 1, high, (2 * pos) + 2);\n            seg[pos] = t1 + t2;\n            return seg[pos];\n \n        }\n        public static long querySegment(long seg[], int low, int high, int qlow, int qhigh, int pos) {\n \n            if (qlow <= low && qhigh >= high) {\n                return seg[pos];\n            } else if (qlow > high || qhigh < low) {\n                return 0;\n            } else {\n                long ans = 0;\n                int mid = (low + high) / 2;\n                ans += querySegment(seg, low, mid, qlow, qhigh, (2 * pos) + 1);\n                ans += querySegment(seg, mid + 1, high, qlow, qhigh, (2 * pos) + 2);\n                return ans;\n            }\n \n        }\n        public static int lcs(char[] X, char[] Y, int m, int n) {\n            if (m == 0 || n == 0)\n                return 0;\n            if (X[m - 1] == Y[n - 1])\n                return 1 + lcs(X, Y, m - 1, n - 1);\n            else\n                return Integer.max(lcs(X, Y, m, n - 1), lcs(X, Y, m - 1, n));\n        }\n \n        public static long recursion(long start, long end, long cnt[], int a, int b) {\n \n            long min = 0;\n            long count = 0;\n            int ans1 = -1;\n            int ans2 = -1;\n            int l = 0;\n            int r = cnt.length - 1;\n            while (l <= r) {\n                int mid = (l + r) / 2;\n                if (cnt[mid] >= start) {\n                    ans1 = mid;\n                    r = mid - 1;\n                } else {\n                    l = mid + 1;\n                }\n            }\n \n            l = 0;\n            r = cnt.length - 1;\n            while (l <= r) {\n                int mid = (l + r) / 2;\n                if (cnt[mid] <= end) {\n                    ans2 = mid;\n                    l = mid + 1;\n                } else {\n                    r = mid - 1;\n                }\n            }\n \n            if (ans1 == -1 || ans2 == -1 || ans2 < ans1) {\n                // System.out.println(\"min1 \"+min);\n                min = a;\n                return a;\n \n            } else {\n                min = b * (end - start + 1) * (ans2 - ans1 + 1);\n            }\n            if (start == end) {\n                // System.out.println(\"min \"+min);\n                return min;\n            }\n            long mid = (end + start) / 2;\n            min = Long.min(min, recursion(start, mid, cnt, a, b) + recursion(mid + 1, end, cnt, a, b));\n            // System.out.println(\"min \"+min);\n            return min;\n        }\n \n \n \n \n \n        public int dfs_util(ArrayList < Integer > [] al, boolean vis[], int x, int[] s, int lvl[]) {\n \n            vis[x] = true;\n            int cnt = 1;\n            for (int i = 0; i < al[x].size(); i++) {\n \n                if (!vis[al[x].get(i)]) {\n                    lvl[al[x].get(i)] = lvl[x] + 1;\n                    cnt += dfs_util(al, vis, al[x].get(i), s, lvl);\n \n \n                }\n \n \n            }\n            s[x] = cnt;\n            return s[x];\n        }\n \n        public void dfs(ArrayList[] al, int[] s, int[] lvl) {\n \n            boolean vis[] = new boolean[al.length];\n            for (int i = 0; i < al.length; i++) {\n                if (!vis[i]) {\n                    lvl[i] = 1;\n                    dfs_util(al, vis, i, s, lvl);\n                }\n            }\n        }\n \n        public int[] computeLps(String s)\n        {\n            int ans[] =new int[s.length()];\n            char ch[] = s.toCharArray();\n            int n = s.length();\n            int i=1;\n            int len=0;\n            ans[0]=0;\n            while(i<n)\n            {\n                if(ch[i]==ch[len])\n                {\n                    len++;\n                    ans[i]=len;\n                    i++;\n                }\n                else\n                {\n                    if(len!=0)\n                    {\n                        len=ans[len-1];\n                    }\n                    else\n                    {\n                        ans[i]=len;\n                        i++;\n                    }\n                }\n            }\n\n            return ans;\n\n        }\n \n \n        private void solve(InputReader inp, PrintWriter out1) {\n            int n = inp.nextInt();\n            int m = inp.nextInt();\n            long k = inp.nextLong();\n            long arr[] = new long[n];\n\n            for(int i=0;i<n;i++)\n            {\n                arr[i] = inp.nextLong();\n\n            }\n            long ans=0;\n            for(int i=0;i<m;i++)\n            {\n                long sum=0;\n                for(int j=i;j<n;j++)\n                {\n                    \n\n                    if(j%m==i)\n                    {\n                        if(sum<0)\n                        {\n                           sum=0;\n                        }\n                        sum-=k;\n                    }\n                    \n                    sum+=arr[j];\n                    \n                    ans=Math.max(ans,sum);\n                }\n\n            \n\n            }\n\n            System.out.println(ans);\n           \n\n           \n            \n        }\n \n \n}\n \n \n    static class InputReader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n \n        InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n \n        String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n \n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n \n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\nclass ele implements Comparable < ele > {\n    int value;\n    int i;\n    boolean flag;\n    public ele(int value, int i) {\n        this.value = value;\n        this.i = i;\n        this.flag = false;\n    }\n    public int compareTo(ele e) {\n        return Integer.compare(this.value, e.value);\n    }\n}", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class Solution{\n    private long [] sums;\n    private void solve(){\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n        int [] arr = new int[n];\n        this.sums = new long[n];\n        for(int i = 0; i < n; i++){\n            arr[i] = sc.nextInt();\n            sums[i] = arr[i] + (i == 0 ? 0 : sums[i - 1]);\n        }\n        long ans = 0;\n        for(int i = 1; i <= n && i <= m; i++){\n            ans = Math.max(ans, sum(0, i - 1) - k);\n        }\n        long [] dp = new long[n];\n        for(int i = 0; i < n; i++){\n            if(i + 1 >= m){\n                long cur = sum(i - m + 1, i) - k;\n                if(i - m >= 0){\n                    cur += dp[i - m];\n                }\n                dp[i] = Math.max(dp[i], cur);\n            }\n            for(int j = 0; j <= m && i + j < n; j++){\n                ans = Math.max(ans, dp[i] + sum(i + 1, i + j) - k * (j > 0 ? 1 : 0));\n            }\n        }\n        System.out.println(ans);\n    }\n    private long sum(int l, int r){\n        if(l <= 0){\n            return sums[r];\n        }else{\n            return sums[r] - sums[l - 1];\n        }\n    }\n    public static void main(String [] args){\n        new Solution().solve();\n    }\n}", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "//package ContestEd69;\n\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class mainD {\n    public static PrintWriter out = new PrintWriter(System.out);\n    public static FastScanner enter = new FastScanner(System.in);\n    public static long[] arr;\n    public static void main(String[] args) throws IOException {\n        int n=enter.nextInt();\n        int m=enter.nextInt();\n        long k=enter.nextLong();\n        arr=new long[n+1];\n        for (int i = 1; i <n+1 ; i++) {\n            arr[i]=enter.nextLong();\n        }\n        long[] summ=new long[n+1];\n        for (int i = 1; i <n+1 ; i++) {\n            summ[i]+=arr[i]+summ[i-1];\n        }\n\n        long[] best=new long[n+1];\n\n        for (int i = 1; i <n+1 ; i++) {\n            best[i]=Math.max(0, ((i-m>=0) ? best[i-m]+summ[i]-summ[i-m]-k:0));\n        }\n        long ans=best[1];\n\n        for (int i = 1; i <n+1 ; i++) {\n            ans=Math.max(ans,best[i]);\n            for (int j = 1; j <m ; j++) {\n                ans=Math.max(ans, ((i-j>=0) ? best[i-j] -k +summ[i]-summ[i-j]:0));\n            }\n        }\n        System.out.println(ans);\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer stok;\n\n        FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        String next() 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(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        char nextChar() throws IOException {\n            return (char) (br.read());\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1197_D. Yet Another Subarray Problem", "from": "CODEFORCES"}
{"src": "//package goodbye2017;\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 G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tchar[] s = ns().toCharArray();\n\t\tint mod = 1000000007;\n\t\tint m = 702;\n\t\t\n\t\tlong[] bases = new long[m+1];\n\t\tbases[0] = 1;\n\t\tfor(int i = 1;i <= m;i++)bases[i] = bases[i-1] * 10 % mod;\n\t\t\n\t\t// 10*700^3*10\n\t\tlong ans = 0;\n\t\tfor(int d = 9;d >= 1;d--){\n\t\t\tint n = s.length;\n\t\t\tlong[] sum = new long[m]; // base\n\t\t\tlong[] num = new long[m]; // base\n\t\t\tlong esum = 0;\n\t\t\tint ebase = 0;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tlong[] nsum = new long[m]; // base\n\t\t\t\tlong[] nnum = new long[m]; // base\n\t\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\t\tfor(int k = 0;k <= 9;k++){\n\t\t\t\t\t\tif(k > d && j+1 < m){\n\t\t\t\t\t\t\tnsum[j+1] += sum[j] * 10;\n\t\t\t\t\t\t\tnsum[j+1] %= mod;\n\t\t\t\t\t\t\tnnum[j+1] += num[j];\n\t\t\t\t\t\t\tif(nnum[j+1] >= mod)nnum[j+1] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(k == d){\n\t\t\t\t\t\t\tnsum[j] += sum[j] * 10 + num[j] * bases[j];\n\t\t\t\t\t\t\tnsum[j] %= mod;\n\t\t\t\t\t\t\tnnum[j] += num[j];\n\t\t\t\t\t\t\tif(nnum[j] >= mod)nnum[j] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(k < d){\n\t\t\t\t\t\t\tnsum[j] += sum[j];\n\t\t\t\t\t\t\tif(nsum[j] >= mod)nsum[j] -= mod;\n\t\t\t\t\t\t\tnnum[j] += num[j];\n\t\t\t\t\t\t\tif(nnum[j] >= mod)nnum[j] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor(int k = 0;k < s[i]-'0';k++){\n\t\t\t\t\tif(k > d){\n\t\t\t\t\t\tnsum[ebase+1] += esum * 10;\n\t\t\t\t\t\tnsum[ebase+1] %= mod;\n\t\t\t\t\t\tnnum[ebase+1] += 1;\n\t\t\t\t\t\tif(nnum[ebase+1] >= mod)nnum[ebase+1] -= mod;\n\t\t\t\t\t}\n\t\t\t\t\tif(k == d){\n\t\t\t\t\t\tnsum[ebase] += esum * 10 + bases[ebase];\n\t\t\t\t\t\tnsum[ebase] %= mod;\n\t\t\t\t\t\tnnum[ebase] += 1;\n\t\t\t\t\t\tif(nnum[ebase] >= mod)nnum[ebase] -= mod;\n\t\t\t\t\t}\n\t\t\t\t\tif(k < d){\n\t\t\t\t\t\tnsum[ebase] += esum;\n\t\t\t\t\t\tif(nsum[ebase] >= mod)nsum[ebase] -= mod;\n\t\t\t\t\t\tnnum[ebase] += 1;\n\t\t\t\t\t\tif(nnum[ebase] >= mod)nnum[ebase] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(s[i]-'0' > d){\n\t\t\t\t\tesum = esum * 10;\n\t\t\t\t\tesum %= mod;\n\t\t\t\t\tebase++;\n\t\t\t\t}else if(s[i]-'0' == d){\n\t\t\t\t\tesum = esum * 10 + bases[ebase];\n\t\t\t\t\tesum %= mod;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tsum = nsum;\n\t\t\t\tnum = nnum;\n\t\t\t}\n\t\t\tlong all = esum;\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tall += sum[j];\n\t\t\t}\n\t\t\tans += all % mod * d;\n\t\t}\n\t\tout.println(ans%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 G().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", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MainG {\n\tstatic StdIn in = new StdIn();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic long M=(long)1e9+7;\n\tstatic int n, dig;\n\tstatic int[] x;\n\tstatic long[] p10, s;\n\tstatic long[][][] dp;\n\t\n\tpublic static void main(String[] args) {\n\t\tchar[] cs = in.next().toCharArray();\n\t\tn=cs.length;\n\t\tx = new int[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\tx[i]=cs[i]-'0';\n\t\tp10 = new long[n];\n\t\tp10[0]=1;\n\t\tfor(int i=1; i<n; ++i)\n\t\t\tp10[i]=p10[i-1]*10%M;\n\t\ts = new long[n+1];\n\t\ts[n]=1;\n\t\tfor(int i=n-1; i>=0; --i)\n\t\t\ts[i]=(s[i+1]+x[i]*p10[n-1-i])%M;\n\t\tlong ans=0;\n\t\tdp = new long[2][n][n+1];\n\t\tfor(dig=1; dig<=9; ++dig) {\n\t\t\tfor(int i=0; i<n; ++i) {\n\t\t\t\tArrays.fill(dp[0][i], -1);\n\t\t\t\tArrays.fill(dp[1][i], -1);\n\t\t\t}\n\t\t\tfor(int i=1; i<=n; ++i)\n\t\t\t\tans=(ans+p10[i-1]*dp(0, 0, i))%M;\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic long dp(int less, int ignore, int need) {\n\t\tif(need==0)\n\t\t\treturn less==1?p10[n-ignore]:s[ignore];\n\t\tif(ignore==n)\n\t\t\treturn 0;\n\t\tif(dp[less][ignore][need]!=-1)\n\t\t\treturn dp[less][ignore][need];\n\t\tlong res=0;\n\t\tint lim=less==1?9:x[ignore];\n\t\tfor(int i=0; i<=lim; ++i)\n\t\t\tres=(res+dp(less|(i<lim?1:0), ignore+1, need-(i>=dig?1:0)))%M;\n\t\treturn dp[less][ignore][need]=res;\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\n\tstatic final int P = 1_000_000_007;\n\n\tint[][] ways;\n\tint[][] pow;\n\n\tvoid preCalc(int sz) {\n\t\tways = new int[sz][];\n\t\tfor (int i = 0; i < ways.length; i++) {\n\t\t\tways[i] = new int[i + 1];\n\t\t\tways[i][0] = ways[i][i] = 1;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tways[i][j] = (ways[i - 1][j] + ways[i - 1][j - 1]) % P;\n\t\t\t}\n\t\t}\n\n\t\tpow = new int[10][sz];\n\t\tpow[0] = null;\n\t\tfor (int i = 1; i <= 9; i++) {\n\t\t\tpow[i][0] = 1;\n\t\t\tfor (int j = 1; j < sz; j++) {\n\t\t\t\tpow[i][j] = (int) ((long) pow[i][j - 1] * i % P);\n\t\t\t}\n\t\t}\n\t}\n\n\tint solve(String ss) {\n\t\tint n = ss.length();\n\t\tint[] s = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ts[i] = ss.charAt(i) - '0';\n\t\t}\n\n\t\tpreCalc(n + 10);\n\n\t\tint[] ans = new int[n + 1];\n\n\t\tint[] cnt = new int[10];\n\n\t\tfor (int i = 0; i < n; i++) {\n\n\t\t\tint rest = n - i - 1;\n\n\t\t\tint dig = s[i];\n\n\t\t\tfor (int j = 0; j <= (i == n - 1 ? dig : dig - 1); j++) {\n\t\t\t\tcnt[j]++; // now we have one more digit >= j\n\n\t\t\t\tfor (int use = 1; use < 10; use++) {\n\t\t\t\t\t// use digits are bad, 10 - use are good\n\t\t\t\t\tfor (int cntGood = 0; cntGood <= rest; cntGood++) {\n\t\t\t\t\t\tint delta = (int) ((long) ways[rest][cntGood]\n\t\t\t\t\t\t\t\t* pow[use][rest - cntGood] % P\n\t\t\t\t\t\t\t\t* pow[10 - use][cntGood] % P);\n\t\t\t\t\t\tint idx = cnt[use] + cntGood;\n\t\t\t\t\t\tans[idx] += delta;\n\t\t\t\t\t\tif (ans[idx] >= P) {\n\t\t\t\t\t\t\tans[idx] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// System.err.println(Arrays.toString(ans));\n\n\t\t\t}\n\n\t\t\tcnt[dig]++;\n\n\t\t}\n\t\t\n\t\tint ret = 0;\n\t\tlong mult = 0;\n\t\tfor (int i = 1; i < ans.length; i++) {\n\t\t\tmult = (10L * mult + 1) % P;\n\t\t\tret += (int)(mult * ans[i] % P);\n\t\t\tif (ret >= P) {\n\t\t\t\tret -= P;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn ret;\n\t}\n\n\tvoid submit() {\n\t\tout.println(solve(nextToken()));\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\t\tStringBuilder sb = new StringBuilder(\"1\");\n\t\tfor (int i = 0; i < 700; i++) {\n\t\t\tsb.append('0');\n\t\t}\n\t\tsolve(sb.toString());\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\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}\n", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "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.util.StringTokenizer;\n\npublic class G {\n\n\tstatic final int MOD = 1000000007;\n\n\tstatic int add(int a, int b) {\n\t\tint res = a + b;\n\t\treturn res >= MOD ? res - MOD : res;\n\t}\n\n\tstatic int sub(int a, int b) {\n\t\tint res = a - b;\n\t\treturn res < 0 ? res + MOD : res;\n\t}\n\n\tstatic int mul(int a, int b) {\n\t\tint res = (int) ((long) a * b % MOD);\n\t\treturn res < 0 ? res + MOD : res;\n\t}\n\n\tstatic int pow(int a, int e) {\n\t\tif (e == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tint r = a;\n\t\tfor (int i = 30 - Integer.numberOfLeadingZeros(e); i >= 0; i--) {\n\t\t\tr = mul(r, r);\n\t\t\tif ((e & (1 << 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 int inv(int a) {\n\t\treturn pow(a, MOD - 2);\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tString x = scanString();\n//\t\tchar xx[] = new char[700];\n//\t\tfill(xx, '9');\n//\t\tString x = new String(xx);\n\t\tint n = x.length();\n\t\tint pows[][] = new int[10][n];\n\t\tfor (int i = 0; i < 10; i++) {\n\t\t\tpows[i][0] = 1;\n\t\t\tfor (int j = 1; j < n; j++) {\n\t\t\t\tpows[i][j] = mul(pows[i][j - 1], i);\n\t\t\t}\n\t\t}\n\t\tint ru[] = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tru[i] = add(1, mul(10, ru[i - 1]));\n\t\t}\n\t\tint facts[] = new int[n];\n\t\tfacts[0] = 1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tfacts[i] = mul(facts[i - 1], i);\n\t\t}\n\t\tint factsInv[] = new int[n];\n\t\tfactsInv[n - 1] = inv(facts[n - 1]);\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tfactsInv[i - 1] = mul(factsInv[i], i);\n\t\t}\n\t\tint ans = 0;\n\t\tint off[] = new int[10];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint cd = x.charAt(i) - '0';\n\t\t\tint l = n - i - 1;\n\t\t\tfor (int d = 1; d < 10; d++) {\n\t\t\t\tfor (int p = 0; p <= l; p++) {\n\t\t\t\t\tint mul = d < cd ? add(mul(d, ru[p + off[d]]), mul(cd - d, ru[p + off[d] + 1])) : mul(cd, ru[p + off[d]]);\n\t\t\t\t\tans = add(ans, mul(mul, mul(mul(pows[d][l - p], pows[10 - d][p]), mul(facts[l], mul(factsInv[p], factsInv[l - p])))));\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int d = 0; d <= cd; d++) {\n\t\t\t\t++off[d];\n\t\t\t}\n\t\t}\n\t\tfor (int d = 1; d < 10; d++) {\n\t\t\tans = add(ans, ru[off[d]]);\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MainG {\n\tstatic StdIn in = new StdIn();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic long M=(long)1e9+7;\n\tstatic int n, dig;\n\tstatic int[] x;\n\tstatic long[] p10, s;\n\tstatic long[][][] dp;\n\t\n\tpublic static void main(String[] args) {\n\t\tchar[] cs = in.next().toCharArray();\n\t\tn=cs.length;\n\t\tx = new int[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\tx[i]=cs[i]-'0';\n\t\tp10 = new long[n];\n\t\tp10[0]=1;\n\t\tfor(int i=1; i<n; ++i)\n\t\t\tp10[i]=p10[i-1]*10%M;\n\t\ts = new long[n+1];\n\t\ts[n]=1;\n\t\tfor(int i=n-1; i>=0; --i)\n\t\t\ts[i]=(s[i+1]+x[i]*p10[n-1-i])%M;\n\t\tlong ans=0;\n\t\tdp = new long[2][n][n+1];\n\t\tfor(dig=1; dig<=9; ++dig) {\n\t\t\tfor(int i=0; i<n; ++i) {\n\t\t\t\tArrays.fill(dp[0][i], -1);\n\t\t\t\tArrays.fill(dp[1][i], -1);\n\t\t\t}\n\t\t\tfor(int i=1; i<=n; ++i)\n\t\t\t\tans=(ans+p10[i-1]*dp(0, 0, i))%M;\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic long dp(int less, int ignore, int need) {\n\t\tif(need==0)\n\t\t\treturn less==1?p10[n-ignore]:s[ignore];\n\t\tif(ignore==n)\n\t\t\treturn 0;\n\t\tif(dp[less][ignore][need]!=-1)\n\t\t\treturn dp[less][ignore][need];\n\t\tlong res=0;\n\t\tint lim=less==1?9:x[ignore];\n\t\tfor(int i=0; i<=lim; ++i)\n\t\t\tres=(res+dp(less|(i<lim?1:0), ignore+1, need-(i>=dig?1:0)));\n\t\tres%=M;\n\t\treturn dp[less][ignore][need]=res;\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n    private static int REM = 1000000007;\n    private static int dig;\n    private static int[][][] dp = new int[701][701][2];\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n\n        String X = in.next();\n        int N = X.length();\n\n        int[] P = new int[701];\n        P[0] = 1;\n        for (int i=1; i<P.length; ++i) {\n            P[i] = (int)((long)P[i-1] * 10 % REM);\n        }\n\n        int ans = 0;\n        for (int d=1; d<=9; ++d) { //at least d\n            dig = d;\n\n            for (int[][] array2 : dp) {\n                for (int[] array1 : array2) {\n                    Arrays.fill(array1, -1);\n                }\n            }\n\n            for (int c=1; c<=N; ++c) { //exact count of at least d\n                for (int k=0; k<c; ++k) {\n                    ans = (int)((ans + (long)f(0, c, false, X) * P[k]) % REM);\n                }\n            }\n        }\n        System.out.println(ans);\n    }\n\n    private static int f(int ps, int needed, boolean less, final String X) {\n        if (needed < 0) {return 0;}\n        if (dp[ps][needed][less?0:1] != -1) {return dp[ps][needed][less?0:1];}\n        if (ps == X.length()) {\n            if (needed == 0) {return 1;}\n            return 0;\n        }\n        int dg = X.charAt(ps)-'0';\n\n        int ans = 0;\n        for (int d=0; d<=9; ++d) {\n            if (!less && d>dg) {continue;}\n\n            boolean nless = less || d < dg;\n            ans = (int)((ans + (long)f(ps+1, needed-(d>=dig?1:0), nless, X)) % REM);\n        }\n\n        dp[ps][needed][less?0:1] = ans;\n        return ans;\n    }\n}\n", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "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.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    TaskG solver = new TaskG();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class TaskG {\n    static int MAXL = 700 + 1;\n    static IntModular MOD = new IntModular();\n    int n;\n    char[] digits;\n    int[] pow10;\n    int[] ones;\n    int[][][] way;\n\n    public void solve(int testNumber, QuickScanner in, QuickWriter out) {\n      digits = new char[MAXL];\n      n = in.next(digits);\n      initPow();\n      int res = MOD.mul(calc(9), 9);\n      for (int digit = 0; digit < 9; ++digit) {\n        res = MOD.sub(res, calc(digit));\n      }\n      out.println(res);\n    }\n\n    void initPow() {\n      pow10 = new int[n + 1];\n      ones = new int[n + 1];\n      pow10[0] = 1;\n      for (int i = 1; i <= n; ++i) {\n        pow10[i] = MOD.mul(pow10[i - 1], 10);\n        ones[i] = MOD.add(MOD.mul(ones[i - 1], 10), 1);\n      }\n    }\n\n    int calc(int targetDigit) {\n      if (way == null) {\n        way = new int[2][2][n + 1];\n      }\n      int t = 0;\n      clearCnt(t);\n      way[t][0][0] = 1;\n      for (int i = 0; i < n; ++i) {\n        int digit = digits[i] - '0';\n        clearCnt(t ^ 1);\n        // not free\n        for (int cnt = 0; cnt <= n; ++cnt)\n          if (way[t][0][cnt] > 0) {\n            // not free\n            int newCnt = targetDigit < digit ? cnt + 1 : cnt;\n            way[t ^ 1][0][newCnt] = MOD.add(\n                way[t ^ 1][0][newCnt],\n                way[t][0][cnt]);\n            // free\n            way[t ^ 1][1][cnt] = MOD.add(\n                way[t ^ 1][1][cnt],\n                MOD.mul(\n                    Math.min(targetDigit + 1, digit),\n                    way[t][0][cnt]));\n            way[t ^ 1][1][cnt + 1] = MOD.add(\n                way[t ^ 1][1][cnt + 1],\n                MOD.mul(\n                    Math.max(digit - targetDigit - 1, 0),\n                    way[t][0][cnt]));\n          }\n        // free\n        for (int cnt = 0; cnt <= n; ++cnt)\n          if (way[t][1][cnt] > 0) {\n            way[t ^ 1][1][cnt] = MOD.add(\n                way[t ^ 1][1][cnt],\n                MOD.mul(\n                    targetDigit + 1,\n                    way[t][1][cnt]));\n            way[t ^ 1][1][cnt + 1] = MOD.add(\n                way[t ^ 1][1][cnt + 1],\n                MOD.mul(\n                    9 - targetDigit,\n                    way[t][1][cnt]));\n          }\n        t ^= 1;\n      }\n      int res = 0;\n      for (int cnt = 0; cnt <= n; ++cnt) {\n        res = MOD.add(\n            res,\n            MOD.mul(MOD.mul(\n                ones[n - cnt],\n                pow10[cnt]),\n                MOD.add(way[t][0][cnt], way[t][1][cnt])));\n      }\n      return res;\n    }\n\n    void clearCnt(int t) {\n      for (int free = 0; free < 2; ++free) {\n        Arrays.fill(way[t][free], 0);\n      }\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 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, mod);\n    }\n\n    public int sub(int a, int b) {\n      return fix(a - b, mod);\n    }\n\n    public int mul(int a, int b) {\n      return mul(a, b, mod);\n    }\n\n    public static int mul(int a, int b, int mod) {\n      return a > 0\n          ? (b < mod / a ? a * b : (int) ((long) a * b % mod))\n          : 0;\n    }\n\n    public static int fix(int a, int mod) {\n      a = slightFix(a, mod);\n      return 0 <= a && a < mod ? a : slightFix(a % mod, mod);\n    }\n\n    private static int slightFix(int a, int mod) {\n      return a >= mod\n          ? a - mod\n          : a < 0 ? a + mod : a;\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 next(char[] s) {\n      return next(s, 0);\n    }\n\n    public int next(char[] s, int startIdx) {\n      int b = nextNonSpaceChar();\n      int res = 0;\n      do {\n        s[startIdx++] = (char) b;\n        b = nextChar();\n        ++res;\n      } while (!isSpaceChar(b));\n      return res;\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\n", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n    private FastScanner in;\n    private PrintWriter out;\n\n    final int mod = (int) 1e9 + 7;\n\n    private long f(String s, int digit) {\n        final int n = s.length();\n        int[][] dp = new int[2][n + 1]; // [less][cntBigger] -> sum\n        dp[0][0] = 1;\n        int[][] ndp = new int[2][n + 1];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < 2; j++) {\n                Arrays.fill(ndp[j], 0);\n            }\n            for (int less = 0; less < 2; less++) {\n                for (int cntBigger = 0; cntBigger <= n; cntBigger++) {\n                    int cur = dp[less][cntBigger];\n                    if (cur == 0) {\n                        continue;\n                    }\n                    int max = less == 1 ? 9 : (s.charAt(i) - '0');\n                    for (int next = 0; next <= max; next++) {\n                        int nextLess = (less == 1) || (next < max) ? 1 : 0;\n                        int nextCntBigger = cntBigger + ((next >= digit) ? 1 : 0);\n                        ndp[nextLess][nextCntBigger] += cur;\n                        while (ndp[nextLess][nextCntBigger] >= mod) {\n                            ndp[nextLess][nextCntBigger] -= mod;\n                        }\n                    }\n                }\n            }\n            int[][] tmp = dp;\n            dp = ndp;\n            ndp = tmp;\n        }\n        long result = 0;\n        for (int less = 0; less < 2; less++) {\n            long sum = 0;\n            for (int cntBigger = 1; cntBigger <= n; cntBigger++) {\n                sum = (sum * 10 + 1) % mod;\n                result = (result + sum * dp[less][cntBigger]) % mod;\n            }\n        }\n        return result % mod;\n    }\n\n    private void solve() {\n        final String number = in.next();\n        long result = 0;\n        for (int digit = 1; digit < 10; digit++) {\n            long cur = f(number, digit);\n            result += cur;\n        }\n        out.println(result % mod);\n    }\n\n    private void run() {\n        try {\n            in = new FastScanner(new File(\"CF.in\"));\n            out = new PrintWriter(new File(\"CF.out\"));\n\n            solve();\n\n            out.close();\n        } catch (FileNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n\n    private void runIO() {\n        in = new FastScanner(System.in);\n        out = new PrintWriter(System.out);\n\n        solve();\n\n        out.close();\n    }\n\n    private class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastScanner(File f) {\n            try {\n                br = new BufferedReader(new FileReader(f));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        FastScanner(InputStream f) {\n            br = new BufferedReader(new InputStreamReader(f));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = null;\n                try {\n                    s = br.readLine();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n                if (s == null)\n                    return null;\n                st = new StringTokenizer(s);\n            }\n            return st.nextToken();\n        }\n\n        boolean hasMoreTokens() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = null;\n                try {\n                    s = br.readLine();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n                if (s == null)\n                    return false;\n                st = new StringTokenizer(s);\n            }\n            return true;\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n\n    public static void main(String[] args) {\n        new CF().runIO();\n    }\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class cf908G {\n\tfinal static int MOD = 1_000_000_007;\n\t\n\tpublic static void main(String[] argv) {\n\t\tcf908G pro = new cf908G();\n\t\t\n\t\tInputStream fin = null;\n\t\tif (System.getProperty(\"ONLINE_JUDGE\") == null) {\n\t\t\ttry {\n\t\t\t\tfin = new FileInputStream(\"input.txt\");\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t} else {\n\t\t\tfin = System.in;\n\t\t}\n\t\tpro.solve(new Scanner(fin), System.out);\n\t}\n\t\n\tprivate void solve(Scanner scanner, PrintStream out) {\n\t\tlong ans = 0;\n\t\tString X = scanner.next();\n\t\tfor (int x = 0; x < 9; x++) {\n\t\t\tans = (ans + solve2(x, X)) % MOD;\n\t\t}\n\t\tout.println((ans % MOD + MOD) % MOD);\n\t}\n\n\tprivate long solve2(int x, String X) {\n\t\tint[][][] f = new int[X.length() + 1][X.length() + 1][2];\n\t\tf[0][0][1] = 1;\n\t\t\n\t\tint n = X.length();\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 u = 0; u < 2; u++) {\n\t\t\t\t\tint val = f[i][j][u];\n\t\t\t\t\tif (val == 0) continue;\n\t\t\t\t\t\n\t\t\t\t\tfor (int num = 0; num < 10; num++) {\n\t\t\t\t\t\tint Xi = X.charAt(i) - '0';\n\t\t\t\t\t\tif (u == 1 && num > Xi) break;\n\t\t\t\t\t\tint _i = i + 1;\n\t\t\t\t\t\tint _j = num <= x ? j + 1 : j;\n\t\t\t\t\t\tint _u = u == 1 && num == Xi ? 1 : 0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tf[_i][_j][_u] = (f[_i][_j][_u] + val) % MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong base = 1;\n\t\tlong ret = 0;\n\t\tfor (int i = n; i > 0; i--) {\n\t\t\tlong t = 0;\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tt = (t + f[n][j][0] + f[n][j][1]) % MOD;\n\t\t\t}\n\t\t\t\n\t\t\tret = (ret + base * t) % MOD;\n\t\t\t\n\t\t\tbase = (base * 10) % MOD;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.atomic.AtomicIntegerArray;\n\npublic class Solution {\n\n    public static void main(String[] args) throws Exception {\n        MyReader reader = new MyReader(System.in);\n//        MyReader reader = new MyReader(new FileInputStream(\"input.txt\"));\n        MyWriter writer = new MyWriter(System.out);\n        new Solution().run(reader, writer);\n        writer.close();\n    }\n\n    private void run(MyReader reader, MyWriter writer) throws Exception {\n        char[] c = reader.nextCharArray();\n        int n = c.length;\n        int[] x = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = c[i] - '0';\n        }\n        long mod = 1_000_000_007;\n        long[] p = new long[n + 1];\n        long[] s = new long[n + 1];\n        p[0] = 1;\n        for (int i = 1; i <= n; i++) {\n            p[i] = p[i - 1] * 10 % mod;\n        }\n        s[n] = 1;\n        for (int i = n - 1; i >= 0; i--) {\n            s[i] = (p[n - i - 1] * x[i] + s[i + 1]) % mod;\n        }\n        long[][][] d = new long[n + 1][n + 1][2];\n        long ans = 0;\n        for (int i = 1; i < 10; i++) {\n            for (long[][] q : d) {\n                for (long[] w : q) {\n                    Arrays.fill(w, 0);\n                }\n            }\n            for (int j = 0; j <= n; j++) {\n                d[j][0][0] = s[j];\n                d[j][0][1] = p[n - j];\n            }\n            for (int j = n - 1; j >= 0; j--) {\n                for (int k = 1; k <= n; k++) {\n                    for (int l = 1; l >= 0; l--) {\n                        int lim = l == 1 ? 10 : x[j] + 1;\n                        for (int m = 0; m < lim; m++) {\n                            d[j][k][l] += d[j + 1][k - (m >= i ? 1 : 0)][l == 1 || m < x[j] ? 1 : 0];\n                            d[j][k][l] %= mod;\n                        }\n                    }\n                    if (j == 0) {\n                        ans = (ans + p[k - 1] * d[0][k][0]) % mod;\n                    }\n                }\n            }\n        }\n        System.out.println(ans);\n    }\n\n    static class MyReader {\n\n        final BufferedInputStream in;\n        final int bufSize = 1 << 16;\n        final byte buf[] = new byte[bufSize];\n        int i = bufSize;\n        int k = bufSize;\n        boolean end = false;\n        final StringBuilder str = new StringBuilder();\n\n        MyReader(InputStream in) {\n            this.in = new BufferedInputStream(in, bufSize);\n        }\n\n        int nextInt() throws IOException {\n            return (int) nextLong();\n        }\n\n        int[] nextIntArray(int n) throws IOException {\n            int[] m = new int[n];\n            for (int i = 0; i < n; i++) {\n                m[i] = nextInt();\n            }\n            return m;\n        }\n\n        int[][] nextIntMatrix(int n, int m) throws IOException {\n            int[][] a = new int[n][0];\n            for (int j = 0; j < n; j++) {\n                a[j] = nextIntArray(m);\n            }\n            return a;\n        }\n\n        long nextLong() throws IOException {\n            int c;\n            long x = 0;\n            boolean sign = true;\n            while ((c = nextChar()) <= 32) ;\n            if (c == '-') {\n                sign = false;\n                c = nextChar();\n            }\n            if (c == '+') {\n                c = nextChar();\n            }\n            while (c >= '0') {\n                x = x * 10 + (c - '0');\n                c = nextChar();\n            }\n            return sign ? x : -x;\n        }\n\n        long[] nextLongArray(int n) throws IOException {\n            long[] m = new long[n];\n            for (int i = 0; i < n; i++) {\n                m[i] = nextLong();\n            }\n            return m;\n        }\n\n        int nextChar() throws IOException {\n            if (i == k) {\n                k = in.read(buf, 0, bufSize);\n                i = 0;\n            }\n            return i >= k ? -1 : buf[i++];\n        }\n\n        String nextString() throws IOException {\n            if (end) {\n                return null;\n            }\n            str.setLength(0);\n            int c;\n            while ((c = nextChar()) <= 32 && c != -1) ;\n            if (c == -1) {\n                end = true;\n                return null;\n            }\n            while (c > 32) {\n                str.append((char) c);\n                c = nextChar();\n            }\n            return str.toString();\n        }\n\n        String nextLine() throws IOException {\n            if (end) {\n                return null;\n            }\n            str.setLength(0);\n            int c = nextChar();\n            while (c != '\\n' && c != '\\r' && c != -1) {\n                str.append((char) c);\n                c = nextChar();\n            }\n            if (c == -1) {\n                end = true;\n                if (str.length() == 0) {\n                    return null;\n                }\n            }\n            if (c == '\\r') {\n                nextChar();\n            }\n            return str.toString();\n        }\n\n        char[] nextCharArray() throws IOException {\n            return nextString().toCharArray();\n        }\n\n        char[][] nextCharMatrix(int n) throws IOException {\n            char[][] a = new char[n][0];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextCharArray();\n            }\n            return a;\n        }\n    }\n\n    static class MyWriter {\n\n        final BufferedOutputStream out;\n        final int bufSize = 1 << 16;\n        final byte buf[] = new byte[bufSize];\n        int i = 0;\n        final byte c[] = new byte[30];\n        static final String newLine = System.getProperty(\"line.separator\");\n\n        MyWriter(OutputStream out) {\n            this.out = new BufferedOutputStream(out, bufSize);\n        }\n\n        void print(long x) throws IOException {\n            int j = 0;\n            if (i + 30 >= bufSize) {\n                flush();\n            }\n            if (x < 0) {\n                buf[i++] = (byte) ('-');\n                x = -x;\n            }\n            while (j == 0 || x != 0) {\n                c[j++] = (byte) (x % 10 + '0');\n                x /= 10;\n            }\n            while (j-- > 0)\n                buf[i++] = c[j];\n        }\n\n        void print(int[] m) throws IOException {\n            for (int a : m) {\n                print(a);\n                print(' ');\n            }\n        }\n\n        void print(long[] m) throws IOException {\n            for (long a : m) {\n                print(a);\n                print(' ');\n            }\n        }\n\n        void print(String s) throws IOException {\n            for (int i = 0; i < s.length(); i++) {\n                print(s.charAt(i));\n            }\n        }\n\n        void print(char x) throws IOException {\n            if (i == bufSize) {\n                flush();\n            }\n            buf[i++] = (byte) x;\n        }\n\n        void print(char[] m) throws IOException {\n            for (char c : m) {\n                print(c);\n            }\n        }\n\n        void println(String s) throws IOException {\n            print(s);\n            println();\n        }\n\n        void println() throws IOException {\n            print(newLine);\n        }\n\n        void flush() throws IOException {\n            out.write(buf, 0, i);\n            out.flush();\n            i = 0;\n        }\n\n        void close() throws IOException {\n            flush();\n            out.close();\n        }\n    }\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "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 x = in.next();\n            int[][] comb = new int[x.length() + 2][x.length() + 2];\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]) % (int) MODULO;\n                }\n            }\n            int[][] pow = new int[11][x.length() + 2];\n            for (int i = 0; i < pow.length; ++i) {\n                pow[i][0] = 1;\n                for (int j = 1; j < pow[i].length; ++j) {\n                    pow[i][j] = (int) (i * (long) pow[i][j - 1] % MODULO);\n                }\n            }\n            int[] oneSum = new int[x.length() + 2];\n            for (int i = 1; i < oneSum.length; ++i) {\n                oneSum[i] = (int) ((10 * (long) oneSum[i - 1] + 1) % MODULO);\n            }\n\n            int[][] s1 = new int[10][x.length() + 1];\n            int[][] s2 = new int[10][x.length() + 1];\n            for (int what = 1; what <= 9; ++what) {\n                for (int max = 0; max <= x.length(); ++max) {\n                    long sum1 = 0;\n                    long sum2 = 0;\n                    for (int equalExtra = 0; equalExtra <= max; ++equalExtra) {\n                        long cways = 1;\n                        cways *= comb[max][equalExtra];\n                        cways %= MODULO;\n                        cways *= pow[what][max - equalExtra];\n                        cways %= MODULO;\n                        sum1 += cways * oneSum[equalExtra];\n                        sum1 %= MODULO;\n                        sum2 += cways;\n                        sum2 %= MODULO;\n                    }\n                    s1[what][max] = (int) sum1;\n                    s2[what][max] = (int) sum2;\n                }\n            }\n\n            int[] sofar = new int[10];\n            long res = 0;\n            for (int firstLess = 0; firstLess < x.length(); ++firstLess) {\n                int min = 0;\n                int max = x.charAt(firstLess) - '0';\n                if (firstLess < x.length() - 1) --max;\n                for (int dig = min; dig <= max; ++dig) {\n                    ++sofar[dig];\n                    int totalSofar = firstLess + 1;\n                    int sofarBigger = 0;\n                    for (int what = 9; what >= 1; --what) {\n                        int sofarThisOrLess = totalSofar - sofarBigger;\n                        int sofarThis = sofar[what];\n                        int sofarLess = sofarThisOrLess - sofarThis;\n                        for (int bigger = sofarBigger; bigger + sofarThisOrLess <= x.length(); ++bigger) {\n                            long ways = comb[x.length() - totalSofar][bigger - sofarBigger];\n                            ways *= pow[9 - what][bigger - sofarBigger];\n                            ways %= MODULO;\n                            long sum1 = s1[what][x.length() - bigger - sofarThisOrLess];\n                            long sum2 = s2[what][x.length() - bigger - sofarThisOrLess];\n                            long sum = (sum1 * (long) pow[10][sofarThis] + sum2 * oneSum[sofarThis]) % MODULO;\n                            sum *= pow[10][bigger];\n                            sum %= MODULO;\n                            res = (res + sum * ways % MODULO * what) % MODULO;\n                        }\n                        sofarBigger += sofarThis;\n                    }\n                    --sofar[dig];\n                }\n                ++sofar[x.charAt(firstLess) - '0'];\n            }\n            out.println(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    }\n}\n\n", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MainG {\n\tstatic StdIn in = new StdIn();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic long M=(long)1e9+7;\n\t\n\tpublic static void main(String[] args) {\n\t\tchar[] cs = in.next().toCharArray();\n\t\tint n=cs.length;\n\t\tint[] x = new int[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\tx[i]=cs[i]-'0';\n\t\tlong[] dp1 = new long[n+1];\n\t\tfor(int i=0; i<n; ++i) \n\t\t\tdp1[i+1]=(x[i]+dp1[i]*10)%M;\n\t\tlong ans=0;\n\t\tfor(int d1=1; d1<=9; ++d1) {\n\t\t\tlong[][] dp2 = new long[2][n+1];\n\t\t\tfor(int i=0; i<n; ++i) {\n\t\t\t\tdp2[0][i+1]=x[i]>=d1?(10*dp2[0][i]+1)%M:dp2[0][i];\n\t\t\t\tfor(int d2=0; d2<x[i]; ++d2)\n\t\t\t\t\tdp2[1][i+1]=((d2>=d1?10*(dp2[0][i]+dp2[1][i])+dp1[i]+1:dp2[0][i]+dp2[1][i])+dp2[1][i+1])%M;\n\t\t\t\tfor(int d2=x[i]; d2<=9; ++d2)\n\t\t\t\t\tdp2[1][i+1]=((d2>=d1?10*dp2[1][i]+dp1[i]:dp2[1][i])+dp2[1][i+1])%M;\n\t\t\t}\n\t\t\tans+=dp2[0][n]+dp2[1][n];\n\t\t}\n\t\tout.println(ans%M);\n\t\tout.close();\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MainG {\n\tstatic StdIn in = new StdIn();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic long M=(long)1e9+7;\n\t\n\tpublic static void main(String[] args) {\n\t\tchar[] cs = in.next().toCharArray();\n\t\tint n=cs.length;\n\t\tint[] x = new int[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\tx[i]=cs[i]-'0';\n\t\tlong[] dp1 = new long[n+1];\n\t\tfor(int i=0; i<n; ++i) \n\t\t\tdp1[i+1]=(x[i]+dp1[i]*10)%M;\n\t\t//out.println(Arrays.toString(dp1));\n\t\tlong ans=0;\n\t\tfor(int d1=1; d1<=9; ++d1) {\n\t\t\tlong[][] dp2 = new long[2][n+1];\n\t\t\tfor(int i=0; i<n; ++i) {\n\t\t\t\tdp2[0][i+1]=x[i]>=d1?(10*dp2[0][i]+1)%M:dp2[0][i];\n\t\t\t\tdp2[1][i+1]=x[i]>=d1?(10*dp2[1][i]+dp1[i])%M:dp2[1][i];\n\t\t\t\tfor(int d2=0; d2<x[i]; ++d2)\n\t\t\t\t\tdp2[1][i+1]=((d2>=d1?10*(dp2[0][i]+dp2[1][i])+dp1[i]+1:dp2[0][i]+dp2[1][i])+dp2[1][i+1])%M;\n\t\t\t\tfor(int d2=x[i]+1; d2<=9; ++d2)\n\t\t\t\t\tdp2[1][i+1]=((d2>=d1?10*dp2[1][i]+dp1[i]:dp2[1][i])+dp2[1][i+1])%M;\n\t\t\t}\n\t\t\tans+=dp2[0][n]+dp2[1][n];\n\t\t\t//out.println(dp2[0][n]+\" \"+dp2[1][n]);\n\t\t}\n\t\tout.println(ans%M);\n\t\tout.close();\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "908_G. New Year and Original Order", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Arrays;\n\npublic class Main {\n\n\tprivate static void solve() {\n\t\tint n = ni();\n\t\tString[] lines = new String[n];\n\t\tfor(int i = 0; i < n; i ++) {\n\t\t\tlines[i] = next();\n\t\t}\n\t\tint mod = 1000000000 + 7;\n\t\t\n\t\tlong[][] dp = new long[2][n + 1];\n\t\tdp[0][0] = 1;\n\t\tfor (int i = 0; i < n; i ++) {\n\t\t\tint from = i % 2;\n\t\t\tint to = (i + 1) % 2;\n\t\t\tboolean flg = i == 0 || lines[i - 1].equals(\"s\");\n\t\t\tif (flg) {\n\t\t\t\tlong v = Arrays.stream(dp[from]).sum();\n\t\t\t\tfor (int j = 0; j <= n; j ++) {\n\t\t\t\t\tdp[to][j] += v;\n\t\t\t\t\tdp[to][j] %= mod;\n\t\t\t\t\tv -= dp[from][j];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int j = 0; j < n; j ++) {\n\t\t\t\t\tdp[to][j + 1] += dp[from][j];\n\t\t\t\t\tdp[to][j + 1] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tArrays.fill(dp[from], 0);\n\t\t}\n\t\tlong ret = Arrays.stream(dp[n % 2]).sum() % mod;\n\t\tSystem.out.println(ret);\n\t}\n\t\n\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class C {\n\tstatic final long MOD = 1_000_000_007;\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tlong[][] dp = new long[N][N];\n\t\tdp[0][0] = 1L;\n\t\tfor(int i = 0; i < N-1; i++) {\n\t\t\tchar oper = sc.next().charAt(0);\n\t\t\tif(oper == 'f') {\n\t\t\t\tdp[i+1][0] = 0L;\n\t\t\t\tfor(int j = 1; j < N; j++) {\n\t\t\t\t\tdp[i+1][j] = dp[i][j-1];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdp[i+1][N-1] = dp[i][N-1];\n\t\t\t\tfor(int j = N-2; j >= 0; j--) {\n\t\t\t\t\tdp[i+1][j] = (dp[i+1][j+1] + dp[i][j]) % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong res = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tres += dp[N-1][i];\n\t\t\tres %= MOD;\n\t\t}\n\t\tout.println(res);\n\t\tout.flush();\n\t}\n\n\tstatic class FastScanner {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic FastScanner() {\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\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\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\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tpublic static void main(String[] args){\n\t\tFastScanner scan = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = scan.nextInt(); mod = (int)1e9+7;\n\t\tin = new char[n];\n\t\tfor(int i = 0; i < n; i++) in[i] = scan.next().charAt(0);\n\t\tdp = new Long[n][n];\n\t\tout.println(go(0, 0));\n\t\tout.close();\n\t}\n\t\n\tstatic long go(int at, int i) {\n\t\tif(at == n-1) return 1;\n\t\tif(dp[at][i] != null) return dp[at][i];\n\t\tlong res = 0;\n\t\tif(in[at] == 's') {\n\t\t\tres += go(at+1, i);\n\t\t\tres %= mod;\n\t\t\tif(i > 0) {\n\t\t\t\tres += go(at, i-1);\n\t\t\t\tres %= mod;\n\t\t\t}\n\t\t} else {\n\t\t\tres += go(at+1, i+1);\n\t\t\tres %= mod;\n\t\t}\n\t\treturn dp[at][i] = res;\n\t}\n\t\n\tstatic Long[][] dp;\n\tstatic int n, mod;\n\tstatic char[] in;\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.* ;\n\n\npublic class PythonIndentation\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in) ;\n\t\tint n = in.nextInt() ;\n\t\tboolean[] lst = new boolean[n] ;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlst[i] = (in.next().equals(\"s\"))?false:true ;\n\t\t}\n\t\tSystem.out.println(dp(lst)) ;\n\t}\n\tstatic void  arrayPrinter(int[][] dp)\n\t{\n\t\tSystem.out.println(\":::\") ;\n\t\tfor(int i=0;i<dp.length;i++)\n\t\t{\n\t\t\tfor(int j=0;j<dp[0].length;j++)\n\t\t\t{\n\t\t\t\tSystem.out.print(dp[i][j]+\" \") ;\n\t\t\t}\n\t\t\tSystem.out.println() ;\n\t\t}\n\t}\n\tstatic int dp(boolean[] lst)\n\t{//false in lst means an \"s\" (simple statement), and true a \"f\"(for loop)\n\t\tint[][] dp = new int[2][lst.length] ;\n\t\tdp[0][0] = 1 ;\n\t\tfor(int i=1;i<lst.length;i++)\n\t\t{\n\t\t\t// arrayPrinter(dp) ;\n\t\t\tfor(int j=0;j<lst.length;j++)\n\t\t\t{\n\t\t\t\tif(lst[i-1])//(i-1)st statement is a for loop \n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t\tdp[i%2][j] = 0 ;\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i%2][j] = dp[(i-1)%2][j-1] ;\n\t\t\t\t}\n\t\t\t\n\t\t\t\telse//i-1 st statement is a simple statement\n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint temp = 0 ;\n\t\t\t\t\t\tfor(int k=0;k<lst.length;k++)\n\t\t\t\t\t\t\ttemp = (temp+dp[(i-1)%2][k])%1000000007 ;\n\t\t\t\t\t\tdp[i%2][j] = temp ;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i%2][j] = (dp[i%2][j-1]-dp[(i-1)%2][j-1])%1000000007 ;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0 ;\n\t\tfor(int i=0;i<lst.length;i++)\n\t\t{\n\t\t\tans = (ans + dp[(lst.length-1)%2][i])%1000000007 ;\n\t\t}\n\t\tif(ans<0)\n\t\t\tans = ans + 1000000007 ;\n\t\t// arrayPrinter(dp) ;\n\t\treturn ans ;\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic final class PythonIndentation\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew PythonIndentation(System.in, System.out);\n\t}\n\n\tstatic class Solver implements Runnable\n\t{\n\t\tstatic final int MOD = (int) 1e9 + 7;\n\t\tint n;\n\t\tchar[] arr;\n\t\tlong[][] dp;\n\t\tBufferedReader in;\n\t\tPrintWriter out;\n\n\t\tvoid solve() throws IOException\n\t\t{\n\t\t\tn = Integer.parseInt(in.readLine());\n\t\t\tarr = new char[n];\n\t\t\tdp = new long[n + 1][n + 1];\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = in.readLine().charAt(0);\n\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\tArrays.fill(dp[i], -1);\n\n\t\t\tdp[0][0] = 1;\n\n\t\t\tif (arr[0] == 's')\n\t\t\t\tout.println(find(1, 0));\n\t\t\telse\n\t\t\t\tout.println(find(1, 1));\n\n/*\t\t\tSystem.out.println(\"dp :\");\n\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t{\n\t\t\t\tSystem.out.print(\"i : \" + i + \" => \");\n\t\t\t\tfor (int j = 0; j <= n; j++)\n\t\t\t\t\tSystem.out.print(dp[i][j] + \" \");\n\t\t\t\tSystem.out.println();\n\t\t\t}*/\n\t\t}\n\n\t\tlong find(int curr, int backIndents)\n\t\t{\n//\t\t\tSystem.out.println(\"curr : \" + curr + \", bI : \" + backIndents);\n\t\t\tif (backIndents < 0)\n\t\t\t\treturn 0;\n\n\t\t\tif (curr == n)\n\t\t\t\treturn dp[curr][backIndents] = 1;\n\n\t\t\tif (dp[curr][backIndents] != -1)\n\t\t\t\treturn dp[curr][backIndents];\n\n\t\t\tlong ans;\n\n\t\t\tif (arr[curr] == 's')\n\t\t\t{\n\t\t\t\tif (arr[curr - 1] == 'f')\n\t\t\t\t\tans = find(curr + 1, backIndents);\n\t\t\t\telse\n\t\t\t\t\tans = CMath.mod(find(curr + 1, backIndents) + find(curr, backIndents - 1), MOD);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans = find(curr + 1, backIndents + 1);\n\n\t\t\t\tif (arr[curr - 1] != 'f')\n\t\t\t\t{\n//\t\t\t\t\tSystem.out.println(\"calling from curr : \" + curr + \", bI : \" + backIndents);\n\t\t\t\t\tans = CMath.mod(ans + find(curr, backIndents - 1), MOD);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn dp[curr][backIndents] = ans;\n\t\t}\n\n\t\tpublic Solver(BufferedReader 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 public 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 CMath\n\t{\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}\n\n\tprivate PythonIndentation(InputStream inputStream, OutputStream outputStream)\n\t{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tThread thread = new Thread(null, new Solver(in, out), \"PythonIndentation\", 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\ttry\n\t\t\t{\n\t\t\t\tin.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\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\n}\n\n/*\n\n6\nf\nf\ns\ns\ns\ns\n: 10\n\n*/\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.* ;\nimport java.io.* ;\n\npublic class PythonIndentation\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in) ;\n\t\tint n = in.nextInt() ;\n\t\tboolean[] lst = new boolean[n] ;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlst[i] = (in.next().equals(\"s\"))?false:true ;\n\t\t}\n\t\tSystem.out.println(dp(lst)) ;\n\t}\n\t// static void  arrayPrinter(int[][] dp)\n\t// {\n\t\t// System.out.println(\":::\") ;\n\t\t// for(int i=0;i<dp.length;i++)\n\t\t// {\n\t\t\t// for(int j=0;j<dp[0].length;j++)\n\t\t\t// {\n\t\t\t\t// System.out.print(dp[i][j]+\" \") ;\n\t\t\t// }\n\t\t\t// System.out.println() ;\n\t\t// }\n\t// }\n\tstatic long dp(boolean[] lst)\n\t{//false in lst means an \"s\" (simple statement), and true a \"f\"(for loop)\n\t\tlong[][] dp = new long[lst.length][lst.length] ;\n\t\tdp[0][0] = 1 ;\n\t\tfor(int i=1;i<lst.length;i++)\n\t\t{\n\t\t\t// int sum_i = 0;\n\t\t\t// for(int j=0;j<lst.length;j++)\n\t\t\t\t// sum_i = (sum_i+dp[i-1][j])%1000000007 ;\n\t\t\t\n\t\t\tfor(int j=0;j<lst.length;j++)\n\t\t\t{\n\t\t\t\tif(lst[i-1])//(i-1)st statement is a for loop \n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t\tdp[i][j] = 0 ;\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i][j] = dp[i-1][j-1] ;\n\t\t\t\t}\n\t\t\t\n\t\t\t\telse//i-1 st statement is a simple statement\n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor(int k=0;k<lst.length;k++)\n\t\t\t\t\t\t\tdp[i][j] = (dp[i][j]+dp[i-1][k])%1000000007 ;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i][j] = (dp[i][j-1]-dp[i-1][j-1])%1000000007 ;\n\t\t\t\t\t// if(j==lst.length-1)\n\t\t\t\t\t\t// dp[i][j] = dp[i][j-1] ;\n\t\t\t\t\t// else\n\t\t\t\t\t\t// dp[i][j] = (dp[i-1][j]+dp[i][j+1])%1000000007 ;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// for(int i=0;i<lst.length;i++)\n\t\t\t// System.out.print(dp[lst.length-1][i]+\" \") ;\n\t\t// System.out.println() ;\n\t\tlong ans = 0 ;\n\t\tfor(int i=0;i<lst.length;i++)\n\t\t{\n\t\t\tans = (ans + dp[lst.length-1][i])%1000000007 ;\n\t\t}\n\t\tif(ans<0)\n\t\t\tans = ans + 1000000007 ;\n\t\treturn ans ;\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.util.Scanner;\nimport java.util.TreeSet;\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    final int N = 5010;\n    final int M = 1_000_000_007;\n    long[][] dp = new long[2][N];\n    long[] sums = new long[N];\n    char[] p = new char[N];\n    Scanner sca = new Scanner(System.in);\n    void start() {\n        int n = Integer.parseInt(sca.nextLine());\n        int idx = 0;\n        Arrays.fill(dp[idx], 0);\n        dp[idx][0] = 1;\n        for (int i = 0; i < n; i++) p[i] = sca.nextLine().charAt(0);\n        for (int i = 0; i < n;) {\n            int nidx = idx ^ 1;\n            Arrays.fill(dp[nidx], 0);\n            Arrays.fill(sums, 0);\n            int j = i;\n            while (p[j] != 's') j++;\n            int levels = j - i;\n            i = j+1;\n            for (j = n; j >= 0; j--) {\n                sums[j] = sums[j + 1] + dp[idx][j];\n                if (sums[j] >= M) sums[j] -= M;\n            }\n            for (j = 0; j <= n; j++) {\n                int ind = j + levels;\n                if (ind > n) continue;\n                dp[nidx][ind] = sums[j];\n            }\n            idx = nidx;\n        }\n        long ans = 0;\n        for (int i = 0; i <= n; i++) {\n            ans += dp[idx][i];\n            if (ans >= M) ans -=M;\n        }\n        System.out.println(ans);\n    }\n\n    public static void main(String[] args) {\n\n        new Test().start();\n\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "/*\n * PDPM IIITDM Jabalpur\n * Asutosh Rana\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n\tlong MOD = 1000000007;\n\tInputReader in;\n\tBufferedReader br;\n\tPrintWriter out;\n\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tMain solver = new Main();\n\t\tsolver.in = new InputReader(System.in);\n\t\tsolver.br = new BufferedReader(new InputStreamReader(System.in));\n\t\tsolver.out = new PrintWriter(System.out);\n\t\tsolver.solve();\n\t\tsolver.out.flush();\n\t\tsolver.out.close();\n\t}\n\n\tint[] A;\n\tint N;\n\t\n\tpublic void solve() {\n\n\t\tint tc = 1;//in.readInt();\n\n\t\tfor (int cas = 1; cas <= tc; cas++) {\n\t\t\tN = in.readInt();\n\t\t\tA = new int[N];\n\n\t\t\tfor(int i =0;i<A.length;i++){\n\t\t\t\tString str = in.readString();\n\t\t\t\tif(str.equals(\"f\"))\n\t\t\t\t\tA[i] = 1;\n\t\t\t}\n\t\t\t\n\t\t\tlong[][] dp = new long[N+1][N+1];\n\t\t\t\n\t\t\tfor(int i=0;i<N;i++){\n\t\t\t\tif(i==0){\n\t\t\t\t\tdp[i][0] = 1;\n\t\t\t\t}\n\t\t\t\telse if(A[i-1]!=1){\n\t\t\t\t\tdp[i][N] = dp[i-1][N];\n\t\t\t\t\tfor(int j=N-1;j>=0;j--){\n\t\t\t\t\t\t/* sum of all positions from */\n\t\t\t\t\t\tdp[i][j] = (dp[i-1][j] + dp[i][j+1])%MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tfor(int j=1;j<=N;j++){\n\t\t\t\t\t\tdp[i][j] = dp[i-1][j-1]%MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlong res = 0;\n\t\t\tfor(int i=0;i<=N;i++){\n\t\t\t\tres = (res + dp[N-1][i])%MOD;\n\t\t\t}\n\t\t\tout.println(res);\n\t\t}\n\n\t}\n\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\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 void readInt(int[] A) {\n\t\tfor (int i = 0; i < A.length; i++)\n\t\t\tA[i] = readInt();\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic void readLong(long[] A) {\n\t\tfor (int i = 0; i < A.length; i++)\n\t\t\tA[i] = readLong();\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic char[] readCharA() {\n\t\treturn readString().toCharArray();\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 c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class CC {\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\ts=new char [n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ts[i]=sc.next().charAt(0);\n\t\tmem=new int [2*n+1][n+1];\n\t\tfor(int [] x : mem)\n\t\t\tArrays.fill(x, -1);\n\t\tpw.println(dp(0, 0));\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\tstatic int n;\n\tstatic char [] s;\n\tstatic int [][] mem;\n\t\n\tstatic int dp(int i,int j){\n\t\tif(i==n)\n\t\t\treturn j==0? 1 : 0;\n\t\tif(mem[i][j]!=-1)\n\t\t\treturn mem[i][j];\n\t\tint ans=0;\n\t\tif(s[i]=='f'){\n\t\t\tans+=dp(i+1, j+1);\n\t\t\tans%=mod;\n\t\t}else{\n\t\t\tans+=dp(i+1, j);\n\t\t\tans%=mod;\n\t\t\tif(j>0){\n\t\t\t\tans+=dp(i, j-1);\n\t\t\t\tans%=mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn mem[i][j]=ans;\n\t}\n\t\n\tstatic int mod=(int)(1e9+7);\n\n\tstatic 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() {while (st == null || !st.hasMoreElements()) {\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (IOException e) {e.printStackTrace();}}\n\t\treturn st.nextToken();}\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\tString nextLine(){String str = \"\";\n\t\ttry {str = br.readLine();}\n\t\tcatch (IOException e) {e.printStackTrace();}\n\t\treturn str;}\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 C_455\n{\n\tpublic static final long[] POWER2 = generatePOWER2();\n\tpublic static final IteratorBuffer<Long> 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\tstatic class Array<Type> implements Iterable<Type>\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<Type> 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<Type> 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\t@Override\n\t\tpublic Iterator<Type> iterator()\n\t\t{\n\t\t\treturn new Iterator<Type>()\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\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<Type> toList()\n\t\t{\n\t\t\tList<Type> 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 String toString()\n\t\t{\n\t\t\treturn \"[\" + C_455.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\tpublic 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<TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>>\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 abstract TypeEdge getThis();\n\n\t\tpublic TypeVertex other(Vertex<TypeVertex, TypeEdge> 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 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<TypeVertex extends Vertex<TypeVertex, EdgeDefault<TypeVertex>>> extends Edge<TypeVertex, EdgeDefault<TypeVertex>>\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<TypeVertex> getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class EdgeDefaultDefault extends Edge<VertexDefaultDefault, EdgeDefaultDefault>\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 FIFO<Type>\n\t{\n\t\tpublic SingleLinkedList<Type> start;\n\t\tpublic SingleLinkedList<Type> 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<Type> 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\tstatic class Fraction implements Comparable<Fraction>\n\t{\n\t\tpublic static final Fraction ZERO = new Fraction(0, 1);\n\n\t\tpublic static Fraction fraction(long whole)\n\t\t{\n\t\t\treturn fraction(whole, 1);\n\t\t}\n\n\t\tpublic static Fraction fraction(long numerator, long denominator)\n\t\t{\n\t\t\tFraction result;\n\t\t\tif (denominator == 0)\n\t\t\t{\n\t\t\t\tthrow new ArithmeticException();\n\t\t\t}\n\t\t\tif (numerator == 0)\n\t\t\t{\n\t\t\t\tresult = Fraction.ZERO;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint sign;\n\t\t\t\tif (numerator < 0 ^ denominator < 0)\n\t\t\t\t{\n\t\t\t\t\tsign = -1;\n\t\t\t\t\tnumerator = Math.abs(numerator);\n\t\t\t\t\tdenominator = Math.abs(denominator);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsign = 1;\n\t\t\t\t}\n\t\t\t\tlong gcd = gcd(numerator, denominator);\n\t\t\t\tresult = new Fraction(sign * numerator / gcd, denominator / gcd);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final long numerator;\n\t\tpublic final long denominator;\n\n\t\tprivate Fraction(long numerator, long denominator)\n\t\t{\n\t\t\tthis.numerator = numerator;\n\t\t\tthis.denominator = denominator;\n\t\t}\n\n\t\tpublic Fraction add(Fraction fraction)\n\t\t{\n\t\t\treturn fraction(this.numerator * fraction.denominator + fraction.numerator * this.denominator, this.denominator * fraction.denominator);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Fraction that)\n\t\t{\n\t\t\treturn Long.compare(this.numerator * that.denominator, that.numerator * this.denominator);\n\t\t}\n\n\t\tpublic Fraction divide(Fraction fraction)\n\t\t{\n\t\t\treturn multiply(fraction.inverse());\n\t\t}\n\n\t\tpublic boolean equals(Fraction that)\n\t\t{\n\t\t\treturn this.compareTo(that) == 0;\n\t\t}\n\n\t\tpublic boolean equals(Object that)\n\t\t{\n\t\t\treturn this.compareTo((Fraction) that) == 0;\n\t\t}\n\n\t\tpublic Fraction getRemainder()\n\t\t{\n\t\t\treturn fraction(this.numerator - getWholePart() * denominator, denominator);\n\t\t}\n\n\t\tpublic long getWholePart()\n\t\t{\n\t\t\treturn this.numerator / this.denominator;\n\t\t}\n\n\t\tpublic Fraction inverse()\n\t\t{\n\t\t\treturn fraction(this.denominator, this.numerator);\n\t\t}\n\n\t\tpublic Fraction multiply(Fraction fraction)\n\t\t{\n\t\t\treturn fraction(this.numerator * fraction.numerator, this.denominator * fraction.denominator);\n\t\t}\n\n\t\tpublic Fraction neg()\n\t\t{\n\t\t\treturn fraction(-this.numerator, this.denominator);\n\t\t}\n\n\t\tpublic Fraction sub(Fraction fraction)\n\t\t{\n\t\t\treturn add(fraction.neg());\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\tString result;\n\t\t\tif (getRemainder().equals(Fraction.ZERO))\n\t\t\t{\n\t\t\t\tresult = \"\" + this.numerator;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = this.numerator + \"/\" + this.denominator;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tstatic class IteratorBuffer<Type>\n\t{\n\t\tprivate Iterator<Type> iterator;\n\t\tprivate List<Type> list;\n\n\t\tpublic IteratorBuffer(Iterator<Type> iterator)\n\t\t{\n\t\t\tthis.iterator = iterator;\n\t\t\tthis.list = new ArrayList<Type>();\n\t\t}\n\n\t\tpublic Iterator<Type> iterator()\n\t\t{\n\t\t\treturn new Iterator<Type>()\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() || IteratorBuffer.this.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 MapCount<Type> extends SortedMapAVL<Type, Long>\n\t{\n\t\tprivate int count;\n\n\t\tpublic MapCount(Comparator<? super Type> 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<Type> flatten()\n\t\t{\n\t\t\tList<Type> result = new ArrayList<>();\n\t\t\tfor (Entry<Type, Long> 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 SortedMapAVL<Type, Long> headMap(Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map<? extends Type, ? extends Long> map)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\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 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\t@Override\n\t\tpublic SortedMapAVL<Type, Long> 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<Type, Long> tailMap(Type keyStart)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\t}\n\n\tpublic static class MapSet<TypeKey, TypeValue> extends SortedMapAVL<TypeKey, SortedSetAVL<TypeValue>> implements Iterable<TypeValue>\n\t{\n\t\tprivate Comparator<? super TypeValue> comparatorValue;\n\n\t\tpublic MapSet(Comparator<? super TypeKey> comparatorKey, Comparator<? super TypeValue> comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic MapSet(Comparator<? super TypeKey> comparatorKey, SortedSetAVL<Entry<TypeKey, SortedSetAVL<TypeValue>>> entrySet, Comparator<? super TypeValue> comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey, entrySet);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic boolean add(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tSortedSetAVL<TypeValue> set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));\n\t\t\treturn set.add(value);\n\t\t}\n\n\t\tpublic TypeValue firstValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry<TypeKey, SortedSetAVL<TypeValue>> 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\t@Override\n\t\tpublic MapSet<TypeKey, TypeValue> 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\tpublic Iterator<TypeValue> iterator()\n\t\t{\n\t\t\treturn new Iterator<TypeValue>()\n\t\t\t{\n\t\t\t\tIterator<SortedSetAVL<TypeValue>> iteratorValues = values().iterator();\n\t\t\t\tIterator<TypeValue> 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<TypeKey, SortedSetAVL<TypeValue>> 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 removeSet(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tboolean result;\n\t\t\tSortedSetAVL<TypeValue> 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<TypeKey, TypeValue> 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\tpublic static class Matrix\n\t{\n\t\tpublic final int rows;\n\t\tpublic final int columns;\n\t\tpublic final Fraction[][] cells;\n\n\t\tpublic Matrix(int rows, int columns)\n\t\t{\n\t\t\tthis.rows = rows;\n\t\t\tthis.columns = columns;\n\t\t\tthis.cells = new Fraction[rows][columns];\n\t\t\tfor (int row = 0; row < rows; row++)\n\t\t\t{\n\t\t\t\tfor (int column = 0; column < columns; column++)\n\t\t\t\t{\n\t\t\t\t\tset(row, column, Fraction.ZERO);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void add(int rowSource, int rowTarget, Fraction fraction)\n\t\t{\n\t\t\tfor (int column = 0; column < columns; column++)\n\t\t\t{\n\t\t\t\tthis.cells[rowTarget][column] = this.cells[rowTarget][column].add(this.cells[rowSource][column].multiply(fraction));\n\t\t\t}\n\t\t}\n\n\t\tprivate int columnPivot(int row)\n\t\t{\n\t\t\tint result = this.columns;\n\t\t\tfor (int column = this.columns - 1; 0 <= column; column--)\n\t\t\t{\n\t\t\t\tif (this.cells[row][column].compareTo(Fraction.ZERO) != 0)\n\t\t\t\t{\n\t\t\t\t\tresult = column;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void reduce()\n\t\t{\n\t\t\tfor (int rowMinimum = 0; rowMinimum < this.rows; rowMinimum++)\n\t\t\t{\n\t\t\t\tint rowPivot = rowPivot(rowMinimum);\n\t\t\t\tif (rowPivot != -1)\n\t\t\t\t{\n\t\t\t\t\tint columnPivot = columnPivot(rowPivot);\n\t\t\t\t\tFraction current = this.cells[rowMinimum][columnPivot];\n\t\t\t\t\tFraction pivot = this.cells[rowPivot][columnPivot];\n\t\t\t\t\tFraction fraction = pivot.inverse().sub(current.divide(pivot));\n\t\t\t\t\tadd(rowPivot, rowMinimum, fraction);\n\t\t\t\t\tfor (int row = rowMinimum + 1; row < this.rows; row++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (columnPivot(row) == columnPivot)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tadd(rowMinimum, row, this.cells[row][columnPivot(row)].neg());\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\tprivate int rowPivot(int rowMinimum)\n\t\t{\n\t\t\tint result = -1;\n\t\t\tint pivotColumnMinimum = this.columns;\n\t\t\tfor (int row = rowMinimum; row < this.rows; row++)\n\t\t\t{\n\t\t\t\tint pivotColumn = columnPivot(row);\n\t\t\t\tif (pivotColumn < pivotColumnMinimum)\n\t\t\t\t{\n\t\t\t\t\tresult = row;\n\t\t\t\t\tpivotColumnMinimum = pivotColumn;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void set(int row, int column, Fraction value)\n\t\t{\n\t\t\tthis.cells[row][column] = value;\n\t\t}\n\n\t\tpublic String toString()\n\t\t{\n\t\t\tString result = \"\";\n\t\t\tfor (int row = 0; row < rows; row++)\n\t\t\t{\n\t\t\t\tfor (int column = 0; column < columns; column++)\n\t\t\t\t{\n\t\t\t\t\tresult += this.cells[row][column] + \"\\t\";\n\t\t\t\t}\n\t\t\t\tresult += \"\\n\";\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static class Node<Type>\n\t{\n\t\tpublic static <Type> Node<Type> balance(Node<Type> 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<Type> 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<Type> 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 <Type> Node<Type> clone(Node<Type> 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 <Type> Node<Type> delete(Node<Type> node, Type value, Comparator<? super Type> comparator)\n\t\t{\n\t\t\tNode<Type> 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<Type> 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 <Type> Node<Type> first(Node<Type> 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 <Type> Node<Type> get(Node<Type> node, Type value, Comparator<? super Type> comparator)\n\t\t{\n\t\t\tNode<Type> 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 <Type> Node<Type> head(Node<Type> node, Type value, Comparator<? super Type> comparator)\n\t\t{\n\t\t\tNode<Type> 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 <Type> Node<Type> insert(Node<Type> node, Type value, Comparator<? super Type> comparator)\n\t\t{\n\t\t\tNode<Type> 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 <Type> Node<Type> last(Node<Type> 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 <Type> Node<Type> tail(Node<Type> node, Type value, Comparator<? super Type> comparator)\n\t\t{\n\t\t\tNode<Type> 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 <Type> void traverseOrderIn(Node<Type> node, Consumer<Type> 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<Type> left;\n\t\tpublic final Node<Type> right;\n\t\tpublic final int size;\n\t\tprivate final int height;\n\n\t\tpublic Node(Type value, Node<Type> left, Node<Type> 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<Type> rotateLeft()\n\t\t{\n\t\t\tNode<Type> 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<Type> rotateRight()\n\t\t{\n\t\t\tNode<Type> 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 SingleLinkedList<Type>\n\t{\n\t\tpublic final Type element;\n\t\tpublic SingleLinkedList<Type> next;\n\n\t\tpublic SingleLinkedList(Type element, SingleLinkedList<Type> 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<Type> 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 SmallSetIntegers\n\t{\n\t\tpublic static final int SIZE = 20;\n\t\tpublic static final int[] SET = generateSet();\n\t\tpublic static final int[] COUNT = generateCount();\n\t\tpublic static final int[] INTEGER = generateInteger();\n\n\t\tprivate static int count(int set)\n\t\t{\n\t\t\tint result = 0;\n\t\t\tfor (int integer = 0; integer < SIZE; integer++)\n\t\t\t{\n\t\t\t\tif (0 < (set & set(integer)))\n\t\t\t\t{\n\t\t\t\t\tresult += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tprivate static final int[] generateCount()\n\t\t{\n\t\t\tint[] result = new int[1 << SIZE];\n\t\t\tfor (int set = 0; set < result.length; set++)\n\t\t\t{\n\t\t\t\tresult[set] = count(set);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tprivate static final int[] generateInteger()\n\t\t{\n\t\t\tint[] result = new int[1 << SIZE];\n\t\t\tArrays.fill(result, -1);\n\t\t\tfor (int integer = 0; integer < SIZE; integer++)\n\t\t\t{\n\t\t\t\tresult[SET[integer]] = integer;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tprivate static final int[] generateSet()\n\t\t{\n\t\t\tint[] result = new int[SIZE];\n\t\t\tfor (int integer = 0; integer < result.length; integer++)\n\t\t\t{\n\t\t\t\tresult[integer] = set(integer);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tprivate static int set(int integer)\n\t\t{\n\t\t\treturn 1 << integer;\n\t\t}\n\t}\n\n\tpublic static class SortedMapAVL<TypeKey, TypeValue> implements SortedMap<TypeKey, TypeValue>\n\t{\n\t\tpublic final Comparator<? super TypeKey> comparator;\n\t\tpublic final SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet;\n\n\t\tpublic SortedMapAVL(Comparator<? super TypeKey> 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<? super TypeKey> comparator, SortedSetAVL<Entry<TypeKey, TypeValue>> 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 void clear()\n\t\t{\n\t\t\tthis.entrySet.clear();\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator<? super TypeKey> comparator()\n\t\t{\n\t\t\treturn this.comparator;\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 SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet()\n\t\t{\n\t\t\treturn this.entrySet;\n\t\t}\n\n\t\tpublic Entry<TypeKey, TypeValue> 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\t@Override\n\t\tpublic TypeValue get(Object key)\n\t\t{\n\t\t\tEntry<TypeKey, TypeValue> 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 SortedMapAVL<TypeKey, TypeValue> 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 boolean isEmpty()\n\t\t{\n\t\t\treturn this.entrySet.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic Set<TypeKey> keySet()\n\t\t{\n\t\t\treturn new SortedSet<TypeKey>()\n\t\t\t{\n\t\t\t\t@Override\n\t\t\t\tpublic boolean add(TypeKey typeKey)\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<? extends TypeKey> 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\n\t\t\t\t@Override\n\t\t\t\tpublic Comparator<? super TypeKey> comparator()\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 contains(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 TypeKey first()\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 SortedSet<TypeKey> headSet(TypeKey typeKey)\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 isEmpty()\n\t\t\t\t{\n\t\t\t\t\treturn size() == 0;\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Iterator<TypeKey> iterator()\n\t\t\t\t{\n\t\t\t\t\tfinal Iterator<Entry<TypeKey, TypeValue>> iterator = SortedMapAVL.this.entrySet.iterator();\n\t\t\t\t\treturn new Iterator<TypeKey>()\n\t\t\t\t\t{\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 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 TypeKey next()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn iterator.next().getKey();\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 TypeKey last()\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 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 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 SortedSet<TypeKey> subSet(TypeKey typeKey, TypeKey e1)\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 SortedSet<TypeKey> tailSet(TypeKey typeKey)\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 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> T[] toArray(T[] ts)\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\tpublic Entry<TypeKey, TypeValue> 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 TypeValue put(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry<TypeKey, TypeValue> 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 void putAll(Map<? extends TypeKey, ? extends TypeValue> 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 TypeValue remove(Object key)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry<TypeKey, TypeValue> 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 int size()\n\t\t{\n\t\t\treturn this.entrySet().size();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL<TypeKey, TypeValue> 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<TypeKey, TypeValue> 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\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.entrySet().toString();\n\t\t}\n\n\t\t@Override\n\t\tpublic Collection<TypeValue> values()\n\t\t{\n\t\t\treturn new Collection<TypeValue>()\n\t\t\t{\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 addAll(Collection<? extends TypeValue> 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\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 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 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 Iterator<TypeValue> iterator()\n\t\t\t\t{\n\t\t\t\t\treturn new Iterator<TypeValue>()\n\t\t\t\t\t{\n\t\t\t\t\t\tIterator<Entry<TypeKey, TypeValue>> 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 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 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 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 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> T[] toArray(T[] ts)\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\t}\n\n\tpublic static class SortedSetAVL<Type> implements SortedSet<Type>\n\t{\n\t\tpublic Comparator<? super Type> comparator;\n\t\tpublic Node<Type> root;\n\n\t\tprivate SortedSetAVL(Comparator<? super Type> comparator, Node<Type> 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<? super Type> comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t}\n\n\t\tpublic SortedSetAVL(Collection<? extends Type> collection, Comparator<? super Type> 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<Type> 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 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 addAll(Collection<? extends Type> 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 void clear()\n\t\t{\n\t\t\tthis.root = null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator<? super Type> comparator()\n\t\t{\n\t\t\treturn this.comparator;\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 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 Type first()\n\t\t{\n\t\t\treturn Node.first(this.root).value;\n\t\t}\n\n\t\tpublic Type get(Type value)\n\t\t{\n\t\t\tNode<Type> 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<Type> 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 boolean isEmpty()\n\t\t{\n\t\t\treturn this.root == null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator<Type> iterator()\n\t\t{\n\t\t\tStack<Node<Type>> path = new Stack<>();\n\t\t\treturn new Iterator<Type>()\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\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<Type> 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\n\t\t\t\tpublic void push(Node<Type> 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\t\t\t};\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 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 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 boolean retainAll(Collection<?> collection)\n\t\t{\n\t\t\tSortedSetAVL<Type> 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 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 SortedSetAVL<Type> 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<Type> 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 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> T[] toArray(T[] ts)\n\t\t{\n\t\t\tList<Object> 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 String toString()\n\t\t{\n\t\t\treturn \"{\" + C_455.toString(this, \", \") + \"}\";\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 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 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 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 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 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 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 class Tuple2<Type0, Type1>\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\tpublic static class Tuple2Comparable<Type0 extends Comparable<? super Type0>, Type1 extends Comparable<? super Type1>> extends Tuple2<Type0, Type1> implements Comparable<Tuple2Comparable<Type0, Type1>>\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<Type0, Type1> 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 Tuple3<Type0, Type1, Type2>\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 Vertex\n\t\t\t<\n\t\t\t\t\tTypeVertex extends Vertex<TypeVertex, TypeEdge>,\n\t\t\t\t\tTypeEdge extends Edge<TypeVertex, TypeEdge>\n\t\t\t\t\t>\n\t\t\timplements Comparable<Vertex<? super TypeVertex, ? super TypeEdge>>\n\t{\n\t\tpublic static <\n\t\t\t\tTypeVertex extends Vertex<TypeVertex, TypeEdge>,\n\t\t\t\tTypeEdge extends Edge<TypeVertex, TypeEdge>,\n\t\t\t\tTypeResult\n\t\t\t\t> TypeResult breadthFirstSearch\n\t\t\t\t(\n\t\t\t\t\t\tTypeVertex vertex,\n\t\t\t\t\t\tTypeEdge edge,\n\t\t\t\t\t\tBiFunctionResult<TypeVertex, TypeEdge, TypeResult> function,\n\t\t\t\t\t\tArray<Boolean> visited,\n\t\t\t\t\t\tFIFO<TypeVertex> verticesNext,\n\t\t\t\t\t\tFIFO<TypeEdge> edgesNext,\n\t\t\t\t\t\tTypeResult result\n\t\t\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 <\n\t\t\t\tTypeVertex extends Vertex<TypeVertex, TypeEdge>,\n\t\t\t\tTypeEdge extends Edge<TypeVertex, TypeEdge>,\n\t\t\t\tTypeResult\n\t\t\t\t>\n\t\tTypeResult breadthFirstSearch\n\t\t\t\t(\n\t\t\t\t\t\tArray<TypeVertex> vertices,\n\t\t\t\t\t\tint indexVertexStart,\n\t\t\t\t\t\tBiFunctionResult<TypeVertex, TypeEdge, TypeResult> function,\n\t\t\t\t\t\tTypeResult result\n\t\t\t\t)\n\t\t{\n\t\t\tArray<Boolean> visited = new Array<>(vertices.size(), false);\n\t\t\tFIFO<TypeVertex> verticesNext = new FIFO<>();\n\t\t\tverticesNext.push(vertices.get(indexVertexStart));\n\t\t\tFIFO<TypeEdge> 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 static <\n\t\t\t\tTypeVertex extends Vertex<TypeVertex, TypeEdge>,\n\t\t\t\tTypeEdge extends Edge<TypeVertex, TypeEdge>\n\t\t\t\t>\n\t\tboolean\n\t\tcycle\n\t\t\t\t(\n\t\t\t\t\t\tTypeVertex start,\n\t\t\t\t\t\tSortedSet<TypeVertex> result\n\t\t\t\t)\n\t\t{\n\t\t\tboolean cycle = false;\n\t\t\tStack<TypeVertex> stackVertex = new Stack<>();\n\t\t\tStack<TypeEdge> stackEdge = new Stack<>();\n\t\t\tstackVertex.push(start);\n\t\t\tstackEdge.push(null);\n\t\t\twhile (!stackVertex.isEmpty())\n\t\t\t{\n\t\t\t\tTypeVertex vertex = stackVertex.pop();\n\t\t\t\tTypeEdge edge = stackEdge.pop();\n\t\t\t\tif (!result.contains(vertex))\n\t\t\t\t{\n\t\t\t\t\tresult.add(vertex);\n\t\t\t\t\tfor (TypeEdge otherEdge : vertex.edges)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (otherEdge != edge)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tTypeVertex otherVertex = otherEdge.other(vertex);\n\t\t\t\t\t\t\tif (result.contains(otherVertex))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcycle = 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\tstackVertex.push(otherVertex);\n\t\t\t\t\t\t\t\tstackEdge.push(otherEdge);\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\treturn cycle;\n\t\t}\n\n\t\tpublic static <\n\t\t\t\tTypeVertex extends Vertex<TypeVertex, TypeEdge>,\n\t\t\t\tTypeEdge extends Edge<TypeVertex, TypeEdge>\n\t\t\t\t>\n\t\tSortedSet<TypeVertex>\n\t\tdepthFirstSearch\n\t\t\t\t(\n\t\t\t\t\t\tTypeVertex start,\n\t\t\t\t\t\tBiConsumer<TypeVertex, TypeEdge> functionVisitPre,\n\t\t\t\t\t\tBiConsumer<TypeVertex, TypeEdge> functionVisitPost\n\t\t\t\t)\n\t\t{\n\t\t\tSortedSet<TypeVertex> result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\t\tStack<TypeVertex> stackVertex = new Stack<>();\n\t\t\tStack<TypeEdge> stackEdge = new Stack<>();\n\t\t\tstackVertex.push(start);\n\t\t\tstackEdge.push(null);\n\t\t\twhile (!stackVertex.isEmpty())\n\t\t\t{\n\t\t\t\tTypeVertex vertex = stackVertex.pop();\n\t\t\t\tTypeEdge edge = stackEdge.pop();\n\t\t\t\tif (result.contains(vertex))\n\t\t\t\t{\n\t\t\t\t\tfunctionVisitPost.accept(vertex, edge);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult.add(vertex);\n\t\t\t\t\tstackVertex.push(vertex);\n\t\t\t\t\tstackEdge.push(edge);\n\t\t\t\t\tfunctionVisitPre.accept(vertex, edge);\n\t\t\t\t\tfor (TypeEdge otherEdge : vertex.edges)\n\t\t\t\t\t{\n\t\t\t\t\t\tTypeVertex otherVertex = otherEdge.other(vertex);\n\t\t\t\t\t\tif (!result.contains(otherVertex))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstackVertex.push(otherVertex);\n\t\t\t\t\t\t\tstackEdge.push(otherEdge);\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 static <\n\t\t\t\tTypeVertex extends Vertex<TypeVertex, TypeEdge>,\n\t\t\t\tTypeEdge extends Edge<TypeVertex, TypeEdge>\n\t\t\t\t>\n\t\tSortedSet<TypeVertex>\n\t\tdepthFirstSearch\n\t\t\t\t(\n\t\t\t\t\t\tTypeVertex start,\n\t\t\t\t\t\tConsumer<TypeVertex> functionVisitPreVertex,\n\t\t\t\t\t\tConsumer<TypeVertex> functionVisitPostVertex\n\t\t\t\t)\n\t\t{\n\t\t\tBiConsumer<TypeVertex, TypeEdge> functionVisitPreVertexEdge = (vertex, edge) ->\n\t\t\t{\n\t\t\t\tfunctionVisitPreVertex.accept(vertex);\n\t\t\t};\n\t\t\tBiConsumer<TypeVertex, TypeEdge> functionVisitPostVertexEdge = (vertex, edge) ->\n\t\t\t{\n\t\t\t\tfunctionVisitPostVertex.accept(vertex);\n\t\t\t};\n\t\t\treturn depthFirstSearch(start, functionVisitPreVertexEdge, functionVisitPostVertexEdge);\n\t\t}\n\n\t\tpublic final int index;\n\t\tpublic final List<TypeEdge> 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<? super TypeVertex, ? super TypeEdge> 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 Edge<VertexDefault<TypeEdge>, TypeEdge>> extends Vertex<VertexDefault<TypeEdge>, 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<VertexDefaultDefault, EdgeDefaultDefault>\n\t{\n\t\tpublic static Array<VertexDefaultDefault> vertices(int n)\n\t\t{\n\t\t\tArray<VertexDefaultDefault> 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 Wrapper<Type>\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 void add(int delta, int[] result)\n\t{\n\t\tfor (int index = 0; index < result.length; index++)\n\t\t{\n\t\t\tresult[index] += delta;\n\t\t}\n\t}\n\n\tpublic static void add(int delta, int[]... result)\n\t{\n\t\tfor (int index = 0; index < result.length; index++)\n\t\t{\n\t\t\tadd(delta, result[index]);\n\t\t}\n\t}\n\n\tpublic static int binarySearchMaximum(Function<Integer, Boolean> filter, int start, int end)\n\t{\n\t\treturn -binarySearchMinimum(x -> filter.apply(-x), -end, -start);\n\t}\n\n\tpublic static int binarySearchMinimum(Function<Integer, Boolean> 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 void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static List<List<Integer>> combinations(int n, int k)\n\t{\n\t\tList<List<Integer>> 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<Integer> 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<Integer> 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 <Type> int compare(Iterator<Type> iterator0, Iterator<Type> iterator1, Comparator<Type> 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 <Type> int compare(Iterable<Type> iterable0, Iterable<Type> iterable1, Comparator<Type> comparator)\n\t{\n\t\treturn compare(iterable0.iterator(), iterable1.iterator(), comparator);\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<Long> divisors(long n)\n\t{\n\t\tSortedSetAVL<Long> result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\tresult.add(1L);\n\t\tfor (Long factor : factors(n))\n\t\t{\n\t\t\tSortedSetAVL<Long> 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 LinkedList<Long> factors(long n)\n\t{\n\t\tLinkedList<Long> result = new LinkedList<>();\n\t\tIterator<Long> 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 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 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<Long> 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<Tuple3<Long, Integer, Integer>> itemsValueWeightCount, int weightMaximum)\n\t{\n\t\tlong[] valuesMaximum = new long[weightMaximum + 1];\n\t\tfor (Tuple3<Long, Integer, Integer> 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<Tuple2<Integer, Integer>> 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<Integer, Integer> 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 void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tsolve();\n\t\t}\n\t\tcatch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\tclose();\n\t}\n\n\tpublic static double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\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 String nextLine() throws IOException\n\t{\n\t\treturn bufferedReader.readLine();\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 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\tpublic 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 <T> List<T> permutation(long p, List<T> x)\n\t{\n\t\tList<T> 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<T> 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 <Type> List<List<Type>> permutations(List<Type> list)\n\t{\n\t\tList<List<Type>> result = new ArrayList<>();\n\t\tresult.add(new ArrayList<>());\n\t\tfor (Type element : list)\n\t\t{\n\t\t\tList<List<Type>> permutations = result;\n\t\t\tresult = new ArrayList<>();\n\t\t\tfor (List<Type> 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<Type> 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 Stream<BigInteger> streamFibonacci()\n\t{\n\t\treturn Stream.generate(new Supplier<BigInteger>()\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<Long> streamPrime(int sieveSize)\n\t{\n\t\treturn Stream.generate(new Supplier<Long>()\n\t\t{\n\t\t\tprivate boolean[] isPrime = new boolean[sieveSize];\n\t\t\tprivate long sieveOffset = 2;\n\t\t\tprivate List<Long> 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 <Type> String toString(Iterator<Type> 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 <Type> String toString(Iterator<Type> iterator)\n\t{\n\t\treturn toString(iterator, \" \");\n\t}\n\n\tpublic static <Type> String toString(Iterable<Type> iterable, String separator)\n\t{\n\t\treturn toString(iterable.iterator(), separator);\n\t}\n\n\tpublic static <Type> String toString(Iterable<Type> iterable)\n\t{\n\t\treturn toString(iterable, \" \");\n\t}\n\n\tpublic static long totient(long n)\n\t{\n\t\tSet<Long> 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\tinterface BiFunctionResult<Type0, Type1, TypeResult>\n\t{\n\t\tTypeResult apply(Type0 x0, Type1 x1, TypeResult x2);\n\t}\n\n\tpublic static final long BIG = 1000000007;\n\n\tpublic static long bigAdd(long x, long y)\n\t{\n\t\treturn (x + y) % BIG;\n\t}\n\n\tpublic static long bigMultiply(long x, long y)\n\t{\n\t\treturn (x * y) % BIG;\n\t}\n\n\tpublic static int convert(int n, int start, int end)\n\t{\n\t\treturn n * start + end;\n\t}\n\n\tpublic static long solve(long[] results, boolean[] statements, int start, int end)\n\t{\n\t\tint converted = convert(statements.length, start, end);\n\t\tlong result = results[converted];\n\t\tif (result == -1)\n\t\t{\n\t\t\tif (start == end)\n\t\t\t{\n\t\t\t\tresult = 1L;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (statements[start])\n\t\t\t\t{\n\t\t\t\t\tresult = solve(results, statements, start + 1, end);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = 0L;\n\t\t\t\t\tfor (int index = start + 2; index <= end; index++)\n\t\t\t\t\t{\n\t\t\t\t\t\tlong inside = solve(results, statements, start + 1, index);\n\t\t\t\t\t\tlong outside = solve(results, statements, index, end);\n\t\t\t\t\t\tresult = C_455.bigAdd(result, C_455.bigMultiply(inside, outside));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tresults[converted] = result;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long solve(boolean[] statements)\n\t{\n\t\tlong[] results = new long[(statements.length + 1) * (statements.length + 1)];\n\t\tArrays.fill(results, -1);\n\t\treturn solve(results, statements, 0, statements.length);\n\t}\n\n\tpublic static long solveFast(boolean[] statements)\n\t{\n\t\tlong[] indent2Count = new long[statements.length];\n\t\tindent2Count[0] = 1;\n\t\tfor (boolean statement: statements)\n\t\t{\n\t\t\tif (statement)\n\t\t\t{\n\t\t\t\tlong count = 0;\n\t\t\t\tfor (int index = statements.length - 1; 0 <= index; index--)\n\t\t\t\t{\n\t\t\t\t\tcount = bigAdd(count, indent2Count[index]);\n\t\t\t\t\tindent2Count[index] = count;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int index = statements.length - 1; 1 <= index; index--)\n\t\t\t\t{\n\t\t\t\t\tindent2Count[index] = indent2Count[index - 1];\n\t\t\t\t}\n\t\t\t\tindent2Count[0] = 0;\n\t\t\t}\n\t\t}\n\t\treturn indent2Count[0];\n\t}\n\n\n\tpublic static void solve() throws IOException\n\t{\n\t\tint n = nextInt();\n\t\tboolean[] statements = new boolean[n];\n\t\tfor (int index = 0; index < n; index++)\n\t\t{\n\t\t\tstatements[index] = nextString().equals(\"s\");\n\t\t}\n\t\tout.println(solveFast(statements));\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class PythonIndentation {\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\tint[][] dp = new int[N][N];\n\t\tdp[0][0] = 1;\n\t\tfor(int i = 1; i < N; ++i) {\n\t\t\tchar lastCmd = in.readLine().charAt(0);\n\t\t\tint[] sum = new int[N];\n\t\t\tsum[N - 1] = dp[i - 1][N - 1];\n\t\t\tfor(int j = N - 2; j >= 0; --j)\n\t\t\t\tsum[j] = (sum[j + 1] + dp[i - 1][j]) % 1000000007;\n\t\t\tfor(int j = 0; j < N; ++j) {\n\t\t\t\tif(lastCmd == 'f' && j > 0)\n\t\t\t\t\tdp[i][j] = dp[i - 1][j - 1];\n\t\t\t\telse if(lastCmd == 's')\n\t\t\t\t\tdp[i][j] = sum[j];\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor(int i = 0; i < N; ++i)\n\t\t\tans = (ans + dp[N - 1][i]) % 1000000007;\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 pandusonu\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public int mod = (int) Math.pow(10, 9) + 7;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            // out.print(\"Case #\" + testNumber + \": \");\n            int n = in.readInt();\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.readString().charAt(0) == 'f' ? 1 : 0;\n            }\n            long[][] ans = new long[n][n + 2];\n            ans[0][0] = 1;\n            int indent = 0;\n            if (a[0] == 1) indent++;\n            for (int i = 1; i < n; i++) {\n                if (a[i - 1] == 1) {\n                    for (int j = indent - 1; j >= 1; j--) {\n                        ans[i][j] = ans[i - 1][j - 1];\n                    }\n                    ans[i][indent] = 1;\n                } else {\n                    for (int j = indent; j >= 0; j--) {\n                        ans[i][j] = (ans[i][j + 1] + ans[i - 1][j]) % mod;\n                    }\n                }\n                indent += a[i];\n            }/*\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                out.print(ans[i][j]+\" \");\n            }\n            out.println();\n        }*/\n            long aa = 0;\n            for (int i = 0; i < n + 2; i++) {\n                aa = (aa + ans[n - 1][i]) % mod;\n            }\n            out.println(aa);\n        }\n\n    }\n\n    static class InputReader {\n        private final InputStream stream;\n        private final 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 read() {\n            try {\n                if (curChar >= numChars) {\n                    curChar = 0;\n                    numChars = stream.read(buf);\n                    if (numChars <= 0)\n                        return -1;\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n            return buf[curChar++];\n        }\n\n        public int readInt() {\n            return (int) readLong();\n        }\n\n        public long readLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n                if (c == -1) throw new RuntimeException();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? (-res) : (res);\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c)) c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.append((char) 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\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\n/**\n * @author: Mehul Raheja\n */\nimport java.util.*;\nimport java.io.*;\n\npublic class indent {\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 MOD = (int)1e9 + 7;\n    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int N = Integer.parseInt(br.readLine());\n        char[] d = new char[N];\n        for (int i = 0; i < N; i++) {\n            d[i] = br.readLine().charAt(0);\n        }\n\n        long[][] dp = new long[N][N];\n        boolean det = d[0] == 'f';\n        //Arrays.fill(dp[0], 1);\n        dp[0][0] = 1;\n        \n        for (int i = 1; i < N; i++) {\n           // System.out.println(Arrays.toString(dp[i-1]));\n            long sum = 0;\n\n            for (int j = 0; j < N; j++) {\n                sum = (dp[i - 1][j]%MOD + sum%MOD + MOD) % MOD;\n            }\n            \n           // System.out.println(sum);\n\n            if (d[i] == 'f') {\n                if(det){\n                    for (int j = 1; j < N; j++) {\n                        dp[i][j] = dp[i-1][j-1]%MOD;\n                    }\n                    continue;\n                }\n                \n                for (int j = 0; j < N; j++) {\n                    dp[i][j] = sum%MOD;\n                    sum -= dp[i - 1][j]%MOD;\n\n                }\n                det = true;\n                \n                //System.out.println(Arrays.toString(dp[i]));\n            } else if (d[i] == 's') {\n               // System.out.println(\"HERE1\" + det);\n                \n                if(det){\n                    //System.out.println(\"HERE2\");\n                    det = false;\n                    for (int j = 1; j < N; j++) {\n                        dp[i][j] = dp[i-1][j-1]%MOD;\n                    }\n                   //System.out.println(\"HERE \" + Arrays.toString(dp[i]));\n                    continue;\n                }\n                \n                //System.out.println(\"HERE3\" + sum);\n                for (int j = 0; j < N; j++) {\n                    dp[i][j] = sum%MOD;\n\n                    sum = ((sum - dp[i - 1][j])%MOD + MOD)%MOD;\n\n                }\n                \n            }\n            //System.out.println(Arrays.toString(dp[i]));\n        }\n        //System.out.println(Arrays.toString(dp[dp.length-1]));\n        \n        long ans = 0;\n        for (long e: dp[dp.length-1]) {\n            ans = (ans + e + MOD) % MOD;\n        }\n        System.out.println(ans);\n\n//        boolean det = false;\n//        int maxlayer = 1;\n//        long ans = 1;\n//        for (int i = 0; i < N; i++) {\n//            if (d[i] == 'f') {\n//                if (!det) {\n//                    //System.out.println(\"HERE\" + maxlayer);\n//                    ans = ans * maxlayer;\n//                }\n//                det = true;\n//                maxlayer++;\n//                //System.out.println(\"HERE\");\n//            } else if (d[i] == 's') {\n//                if (det) {\n//                    det = false;\n//                    continue;\n//                }\n//                det = false;\n//                System.out.println(maxlayer);\n//                ans = ans * maxlayer;\n//            }\n//        }\n//\n//        System.out.println(ans);\n    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.* ;\nimport java.io.* ;\n\npublic class PythonIndentation\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in) ;\n\t\tint n = in.nextInt() ;\n\t\tboolean[] lst = new boolean[n] ;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlst[i] = (in.next().equals(\"s\"))?false:true ;\n\t\t}\n\t\tSystem.out.println(dp(lst)) ;\n\t}\n\tstatic long dp(boolean[] lst)\n\t{//false in lst means an \"s\" (simple statement), and true a \"f\"(for loop)\n\t\tlong[][] dp = new long[lst.length][lst.length] ;\n\t\tdp[0][0] = 1 ;\n\t\tfor(int i=1;i<lst.length;i++)\n\t\t{\n\t\t\t\n\t\t\tfor(int j=0;j<lst.length;j++)\n\t\t\t{\n\t\t\t\tif(lst[i-1])//(i-1)st statement is a for loop \n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t\tdp[i][j] = 0 ;\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i][j] = dp[i-1][j-1] ;\n\t\t\t\t}\n\t\t\t\n\t\t\t\telse//i-1 st statement is a simple statement\n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor(int k=0;k<lst.length;k++)\n\t\t\t\t\t\t\tdp[i][j] = (dp[i][j]+dp[i-1][k])%1000000007 ;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i][j] = (dp[i][j-1]-dp[i-1][j-1])%1000000007 ;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans = 0 ;\n\t\tfor(int i=0;i<lst.length;i++)\n\t\t{\n\t\t\tans = (ans + dp[lst.length-1][i])%1000000007 ;\n\t\t}\n\t\tif(ans<0)\n\t\t\tans = ans + 1000000007 ;\n\t\treturn ans ;\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class c implements Runnable{\n\tint N;\n\tint[] arr;\n\tpublic static void main(String[] args) { new Thread(null, new c(), \"\", 1<<27).start(); } public void run() {\n\t\tarr = new int[N = nextInt()];\n\t\tfor(int n=0;n<N;n++) {\n//\t\t\tSystem.out.println(n+\" s\");\n\t\t\tif(nextString().charAt(0) == 'f') {\n\t\t\t\tarr[n] = 1;\n\t\t\t}\n\t\t}\n\t\tlong[][] dp = new long[N+1][N+1];\n\t\tdp[0][0] = 1;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\t// if this is an s\n\t\t\tif(arr[i] == 0) {\n\t\t\t\t// transition from the one directly above and everything to the right of that\n\t\t\t\t// for each dp space. using cumulative sums will make this easier\n\t\t\t\tlong sum = 0;\n\t\t\t\tfor(int j = N; j >= 0; j--) {\n\t\t\t\t\tsum += dp[i][j];\n\t\t\t\t\tsum %= 1_000_000_007L;\n\t\t\t\t\tdp[i+1][j] += sum;\n\t\t\t\t\tdp[i+1][j] %= 1_000_000_007L;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// otherwise, this is an f\n\t\t\telse {\n\t\t\t\t// transition from the spot on the top left\n\t\t\t\tfor(int j = 1; j <= N; j++) {\n\t\t\t\t\tdp[i+1][j] += dp[i][j-1];\n\t\t\t\t\tdp[i+1][j] %= 1_000_000_007L;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// answer is the sum of the last row\n\t\tlong ans = 0;\n\t\tfor(long l : dp[N-1]) ans = (ans + l) % 1_000_000_007;\n\t\tSystem.out.println(ans);\n\t}\n\t\n\n\t// fast scanner stuff\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tString[] line = null; int line_ptr = 0;\n\tvoid read() {\n\t\ttry {\n\t\t\tline = br.readLine().split(\" \");\n\t\t}\n\t\tcatch(IOException ioe) {\n\t\t\tSystem.err.println(\"bad input\");\n\t\t\tline = null;\n\t\t}\n\t}\n\tvoid ensure() {\n\t\twhile(line == null || line.length <= line_ptr) {\n\t\t\tread();\n\t\t\tline_ptr = 0;\n\t\t}\n\t}\n\tint nextInt() {\n\t\tensure();\n\t\treturn Integer.parseInt(line[line_ptr++]);\n\t}\n\tlong nextLong() {\n\t\tensure();\n\t\treturn Integer.parseInt(line[line_ptr++]);\n\t}\n\tString nextString() {\n\t\tensure();\n\t\treturn line[line_ptr++];\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 C {\n\n    static int MOD = 1_000_000_007;\n\n    public static void main(String[] args) {\n\n        MyScanner in = new MyScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n = in.nextInt();\n        char prev = ' ';\n\n        // index, maxNumOfIntents -> count\n        int[][] dp = new int[n+1][n+2];\n\n        dp[0][0] = 1;\n        for(int i=0;i<n;++i){\n            char ch = in.next().charAt(0);\n            if(prev == 's'){\n                int sum = 0;\n                for(int j=n;j>=0;--j){\n                    sum = (sum + dp[i-1][j]) % MOD;\n                    dp[i][j] = sum;\n                }\n            }else if(prev == 'f'){\n                for(int j=0;j<n;++j){\n                    dp[i][j+1] = dp[i-1][j];\n                }\n            }\n\n            prev = ch;\n        }\n\n        int result = 0;\n        for(int i=0;i<=n;++i){\n            result = (result + dp[n-1][i]) % MOD;\n        }\n\n\n        out.println(result);\n        out.close();\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class PythonIndentation {\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint t=sc.nextInt();\n\t\tint a[]=new int[t];\n\t\tint c=0;\n\t\ta[0]=1;\n\t\tlong mod=(long) (1e9+7);\n\t\tsc.nextLine();\n\t\tfor(int i=0;i<t;i++)\n\t\t{\n\t\t\tString s=sc.nextLine();\n\t\t\tif(s.equals(\"f\"))\n\t\t\t\tc++;\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor(int j=1;j<=c;j++)\n\t\t\t\t{\n\t\t\t\t\ta[j]=(int) (((a[j]%mod)+(a[j-1]%mod))%mod);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(a[c]);\n\t\tsc.close();\n\t\t\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main3 implements Runnable {\n\n    public static void main(String[] args) {\n        new Thread(null, new Main3(), \"\", 128 * 1024 * 1024).start();\n    }\n\n    private static Scanner in = new Scanner(System.in);\n\n    public void run() {\n        int n = in.nextInt();\n        int m = 1_000_000_007;\n        boolean[] state = new boolean[n];\n        for (int i = 0; i < n; i++) {\n            state[i] = in.next().equals(\"f\");\n        }\n        // \u4f7f\u3046\u306e\u306f[n][n]\u3060\u3051\u3069\u3001j+1==n\u306e\u3068\u304dif\u5206\u5c90\u305b\u305a\u306b\u6e08\u3080\u3088\u3046\u306bn+1\u306b\u3057\u3066\u308b\n        long[][] dp = new long[n][n + 1];\n        dp[0][0] = 1;\n        // i\u306f\u65e2\u306b\u57cb\u307e\u3063\u3066\u3044\u3066i+1\u306b\u66f8\u304d\u8fbc\u3093\u3067\u3044\u304f\u304b\u3089\u3001i<n-1\u307e\u3067\u3067\u3044\u3044\n        for (int i = 0; i < n - 1; i++) {\n            if (state[i]) {\n                // \u53f3\u4e0b\u306b\u30b3\u30d4\u30fc\u3057\u3066\u3044\u304f\u304b\u3089\u6ea2\u308c\u306a\u3044\u3088\u3046\u306bj<n-1\n                for (int j = 0; j < n - 1; j++) {\n                    dp[i + 1][j + 1] = dp[i][j];\n                }\n            } else {\n                // \u4f55\u901a\u308a\u304b\u3068\u3044\u3046\u306e\u3092\u53f3\u304b\u3089\u57cb\u3081\u3066\u3044\u304f\u304b\u3089j--\u3067\u9032\u3081\u308b\n                for (int j = n - 1; j >= 0; j--) {\n                    // \u8db3\u3057\u3066\u3044\u304f\u3068\u5927\u304d\u304f\u306a\u308b\u304b\u3089\u3053\u306e\u6642\u70b9\u3067\u3082\u3046%m\u3057\u3066\u304a\u304f\n                    dp[i + 1][j] = (dp[i][j] + dp[i + 1][j + 1]) % m;\n                }\n            }\n        }\n        long sum = 0;\n        for (int i = 0; i < n; i++) {\n            sum += dp[n - 1][i] % m;\n        }\n        System.out.println(sum % m);\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.* ;\nimport java.util.* ;\nimport java.text.* ;\nimport java.math.* ;\nimport static java.lang.Math.min ;\nimport static java.lang.Math.max ;\npublic class Codeshefcode{\n\tpublic static void main(String[] args) throws IOException{\n\t\tSolver Machine = new Solver() ;\n\t\tMachine.Solve() ;\n\t\tMachine.Finish() ;\n\t\t// new Thread(null,new Runnable(){\n\t\t// \tpublic void run(){\n\t\t// \t\tSolver Machine = new Solver() ;\n\t\t// \t\ttry{\n\t\t// \t\t\tMachine.Solve() ;\n\t\t// \t\t\tMachine.Finish() ;\n\t\t// \t\t}catch(Exception e){\n\t\t// \t\t\te.printStackTrace() ;\n\t\t// \t\t\tSystem.out.flush() ;\n\t\t// \t\t\tSystem.exit(-1) ;\n\t\t// \t\t}catch(Error e){\n\t\t// \t\t\te.printStackTrace() ;\n\t\t// \t\t\tSystem.out.flush() ;\n\t\t// \t\t\tSystem.exit(-1) ;\n\t\t// \t\t}\n\t\t// \t}\n\t\t// },\"Solver\",1l<<27).start() ;\n\t}\n}\nclass Mod{\n\tstatic long mod=1000000007 ;\n\tstatic long d(long a,long b){ return (a*MI(b))%mod ; }\n\tstatic long m(long a,long b){ return (a*b)%mod ; }\n\tstatic private long MI(long a){ return pow(a,mod-2) ; }\n\tstatic long pow(long a,long b){\n\t\tif(b<0) return pow(MI(a),-b) ;\n\t\tlong val=a ; long ans=1 ;\n\t\twhile(b!=0){\n\t\t\tif((b&1)==1) ans = (ans*val)%mod ; \n\t\t\tval = (val*val)%mod ; \n\t\t\tb/=2 ;\n\t\t}\n\t\treturn ans ;\n\t}\t\n}\nclass pair implements Comparable<pair>{\n\tint x ; int y ;  \n\tpair(int x,int y){ this.x=x ; this.y=y ;} \n\tpublic int compareTo(pair p){\n\t\treturn (this.x<p.x ? -1 : (this.x>p.x ? 1 : (this.y<p.y ? -1 : (this.y>p.y ? 1 : 0)))) ;\n\t}\n}\nclass Solver{\n\tReader ip = new Reader(System.in) ;\t  \n\tPrintWriter op = new PrintWriter(System.out) ;\n\tlong dp[][] ;\n\tpublic void Solve() throws IOException{\n\t\tint n = ip.i() ;\n\t\tint arr[] = new int[n] ;\n\t\tdp = 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\tdp[i][j]=-1 ;\n\t\tfor(int i=0 ; i<n ; i++){\n\t\t\tString s = ip.s() ;\n\t\t\tif(s.compareTo(\"s\")==0) arr[i]=0 ;\n\t\t\telse if(s.compareTo(\"f\")==0) arr[i]=1 ;\n\t\t\telse throw new IOException() ;\n\t\t}\n\t\tfor(int j=0 ; j<n ; j++) dp[n-1][j] = 1 ;\n\t\tfor(int i=(n-2) ; i>=0 ; i--){\n\t\t\tlong cuml[] = new long[n] ;\n\t\t\tfor(int j=0 ; j<n ; j++) cuml[j] = (dp[i+1][j]+(j==0 ? 0 : cuml[j-1]))%Mod.mod ;\n\t\t\tfor(int j=0 ; j<n ; j++)\n\t\t\t\tdp[i][j] = (arr[i]==0 ? cuml[j] : (j==(n-1) ? -1 : dp[i+1][j+1])) ;\n\t\t}\n\t\tpln(dp[0][0]) ;\n\t}\n\tvoid Finish(){\n\t\top.flush();\n\t\top.close();\n\t}\n\tvoid p(Object o){\n\t\top.print(o) ;\n\t}\n\tvoid pln(Object o){\n\t\top.println(o) ;\n\t}\t\t\n}\nclass mylist extends ArrayList<String>{}\nclass myset extends TreeSet<Integer>{}\nclass mystack extends Stack<Integer>{}\nclass mymap extends TreeMap<Long,Integer>{}\nclass Reader {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tReader(InputStream input) {\n\t\treader = new BufferedReader(\n\t\t\t\t\tnew InputStreamReader(input) );\n\t\ttokenizer = new StringTokenizer(\"\") ;\n\t}\n\tString s() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()){\n\t\t\ttokenizer = new StringTokenizer(\n\t\t\treader.readLine()) ;\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\tint i() throws IOException {\n\t\treturn Integer.parseInt(s()) ;\n\t}\n\tlong l() throws IOException{\n\t\treturn Long.parseLong(s()) ;\n\t}\n\tdouble d() throws IOException {\n\t\treturn Double.parseDouble(s()) ;\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic final class PythonIndentation\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew PythonIndentation(System.in, System.out);\n\t}\n\n\tstatic class Solver implements Runnable\n\t{\n\t\tstatic final int MOD = (int) 1e9 + 7;\n\t\tint n;\n\t\tchar[] arr;\n\t\tlong[][] dp;\n\t\tBufferedReader in;\n\t\tPrintWriter out;\n\n\t\tvoid solve() throws IOException\n\t\t{\n\t\t\tn = Integer.parseInt(in.readLine());\n\t\t\tarr = new char[n];\n\t\t\tdp = new long[n + 1][n + 1];\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = in.readLine().charAt(0);\n\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\tArrays.fill(dp[i], -1);\n\n\t\t\tdp[0][0] = 1;\n\n\t\t\tif (arr[0] == 's')\n\t\t\t\tout.println(find(1, 0));\n\t\t\telse\n\t\t\t\tout.println(find(1, 1));\n\t\t}\n\n\t\tlong find(int curr, int backIndents)\n\t\t{\n\t\t\tif (backIndents < 0)\n\t\t\t\treturn 0;\n\n\t\t\tif (curr == n)\n\t\t\t\treturn 1;\n\n\t\t\tif (dp[curr][backIndents] != -1)\n\t\t\t\treturn dp[curr][backIndents];\n\n\t\t\tlong ans;\n\n\t\t\tif (arr[curr] == 's')\n\t\t\t{\n\t\t\t\tif (arr[curr - 1] == 'f')\n\t\t\t\t\tans = find(curr + 1, backIndents);\n\t\t\t\telse\n\t\t\t\t\tans = CMath.mod(find(curr + 1, backIndents) + find(curr, backIndents - 1), MOD);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans = find(curr + 1, backIndents + 1);\n\n\t\t\t\tif (arr[curr - 1] != 'f')\n\t\t\t\t\tans = CMath.mod(ans + find(curr, backIndents - 1), MOD);\n\t\t\t}\n\n\t\t\treturn dp[curr][backIndents] = ans;\n\t\t}\n\n\t\tpublic Solver(BufferedReader 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 public 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 CMath\n\t{\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}\n\n\tprivate PythonIndentation(InputStream inputStream, OutputStream outputStream)\n\t{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tThread thread = new Thread(null, new Solver(in, out), \"PythonIndentation\", 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\ttry\n\t\t\t{\n\t\t\t\tin.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\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tstatic char[] arr;\n\tstatic int mod = (int) 1e9 + 7;\n\tstatic int[][] memo;\n\tstatic int n;\n\n\tstatic int solve(int idx, int depth) {\n\t\tif (idx == n) {\n\t\t\treturn depth == 0 ? 1 : 0;\n\t\t}\n\t\tif (memo[idx][depth] != -1)\n\t\t\treturn memo[idx][depth];\n\t\tint ret = 0;\n\t\tif (arr[idx] == 's') {\n\t\t\tif (depth > 0)\n\t\t\t\tret = ret + solve(idx, depth - 1);\n\t\t\tret = (ret + solve(idx + 1, depth)) % mod;\n\t\t}\n\t\tif (arr[idx] == 'f' || arr[idx] == 'z')\n\t\t\tret = (ret + solve(idx + 1, depth + 1)) % mod;\n\t\treturn memo[idx][depth] = ret;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tarr = new char[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = sc.next().charAt(0);\n\t\tmemo = new int[n + 1][n + 1];\n\t\tfor (int[] x : memo)\n\t\t\tArrays.fill(x, -1);\n\t\tSystem.out.println(solve(0, 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\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class maestro{\n    public static void main(String[] args){\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n        long mod = (long)Math.pow(10,9)+7;\n        long[][] arr = new long[N][N];\n        arr[0][0]=1;\n        for (int i=1;i<N;i++){\n            char c = sc.next().charAt(0);\n            if (c=='f'){\n                for (int j=1;j<N;j++) arr[i][j] = arr[i - 1][j - 1];\n            }\n            else {\n                long sum=0;\n                for (int j=N-1;j>=0;j--){\n                    sum=(sum+arr[i-1][j])%mod;\n                    arr[i][j] = sum;\n                }\n            }\n        }\n        long ans=0;\n        for (int i=0;i<N;i++) ans=(ans+arr[N-1][i])%mod;\n        System.out.println(ans);\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.* ;\n\n\npublic class PythonIndentation\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in) ;\n\t\tint n = in.nextInt() ;\n\t\tboolean[] lst = new boolean[n] ;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlst[i] = (in.next().equals(\"s\"))?false:true ;\n\t\t}\n\t\tSystem.out.println(dp(lst)) ;\n\t}\n\t\n\tstatic int dp(boolean[] lst)\n\t{//false in lst means an \"s\" (simple statement), and true a \"f\"(for loop)\n\t\tint[][] dp = new int[2][lst.length] ;\n\t\tdp[0][0] = 1 ;\n\t\tfor(int i=1;i<lst.length;i++)\n\t\t{\n\t\t\t\n\t\t\tfor(int j=0;j<lst.length;j++)\n\t\t\t{\n\t\t\t\tif(lst[i-1])//(i-1)st statement is a for loop \n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t\tdp[i%2][j] = 0 ;\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i%2][j] = dp[(i-1)%2][j-1] ;\n\t\t\t\t}\n\t\t\t\n\t\t\t\telse//i-1 st statement is a simple statement\n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint temp = 0 ;\n\t\t\t\t\t\tfor(int k=0;k<lst.length;k++)\n\t\t\t\t\t\t\ttemp = (temp+dp[(i-1)%2][k])%1000000007 ;\n\t\t\t\t\t\tdp[i%2][j] = temp ;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i%2][j] = (dp[i%2][j-1]-dp[(i-1)%2][j-1])%1000000007 ;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0 ;\n\t\tfor(int i=0;i<lst.length;i++)\n\t\t{\n\t\t\tans = (ans + dp[(lst.length-1)%2][i])%1000000007 ;\n\t\t}\n\t\tif(ans<0)\n\t\t\tans = ans + 1000000007 ;\n\t\t\n\t\treturn ans ;\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n/**\n *\n * @author rohan\n */\npublic class Main {\n\n        static int mod = (int) (1e9+7);\n        static int MAX = (int)2e5+5;\n        static void solve() \n        {\n                int n = i();\n                String[] s = new String[n];\n                for(int i = 0 ; i<n ; i++)\n                {\n                    s[i] = s();\n                }\n                int[][] dp = new int[n][n];\n                dp[0][0] = 1;\n                for(int i = 1; i<n; i++)\n                {\n                    if(s[i-1].equals(\"f\"))\n                    {\n                        for (int j = i-1 ; j>=0 ; j--)\n                        {\n                            dp[i][j+1] = dp[i-1][j];\n                        }\n                    }\n                    else\n                    {\n                        int suff = 0;\n                        for(int j = i-1; j>=0 ; j--)\n                        {\n                            suff += dp[i-1][j];\n                            if(suff>=mod) suff-= mod;\n                            dp[i][j] = suff;\n                        }\n                    }\n                }\n\n                int sum = 0;\n                for (int i=0 ; i<n; i++)\n                {\n                    sum = sum+dp[n-1][i];\n                    if(sum>=mod)\n                        sum-=mod;\n                }\n                out.println(sum);\n                out.close();\n        }\n  \n\n    ///////////////////////////////////////////////////////////////////\n        static InputReader sc = new InputReader(System.in);\n        static PrintWriter out = new PrintWriter(System.out); \n        public static void main(String[] args)\n        {\n                new Thread(null,new Runnable() {\n                @Override\n                public void run() {\n                    try{\n                        solve();\n                    }\n                    catch(Exception e){\n                        e.printStackTrace();\n                    }\n                }\n                },\"1\",1<<26).start();\n        }\n\n        static class Pair implements Comparable<Pair>{\n                int x,y,i;\n                Pair (int x,int y,int i)\n                {\n                        this.x = x;\n                        this.y = y;\n                        this.i = i;\n                }\n                    \n                Pair (int x,int y)\n                {\n                        this.x = x;\n                        this.y = y;\n                }\n        \n                public int compareTo(Pair o)\n                {\n                        return -(this.y-o.y);\n                }               \n                public boolean equals(Object o)\n                {\n                        if (o instanceof Pair) {\n                            Pair p = (Pair)o;\n                            return p.x == x && p.y==y;\n                        }\n                        return false;\n                }\n\n                @Override\n                public String toString()\n                {\n                        return x + \" \"+ y + \" \"+i;\n                }\n        \n                public int hashCode()\n                {\n                        return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n                }\n        } \n\n\n        static class Merge \n        {\n\n                public static void sort(int inputArr[]) \n                {\n                        int length = inputArr.length;\n                        doMergeSort(inputArr,0, length - 1);\n                }\n\n                private static void doMergeSort(int[] arr,int lowerIndex, int higherIndex) {        \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(int[]array,int lowerIndex, int middle, int higherIndex)\n                {\n                        int[] temp=new int[higherIndex-lowerIndex+1];\n                        for (int i = lowerIndex; i <= higherIndex; i++) {\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                                if (temp[i-lowerIndex] < temp[j-lowerIndex])\n                                {\n                                        array[k] = temp[i-lowerIndex];\n                                        i++;\n                                } \n                                else\n                                {\n                                        array[k] = temp[j-lowerIndex];\n                                        j++;\n                                }\n                                k++;\n                        }\n                        while (i <= middle) {\n                                array[k] = temp[i-lowerIndex];\n                                k++;\n                                i++;\n                        }\n                        while(j<=higherIndex){\n                                array[k]=temp[j-lowerIndex];\n                                k++;\n                                j++;\n                        }\n                }\n        }\n\n        static long add(long a,long b){\n                long x=(a+b);\n                while(x>=mod) x-=mod;\n                return x;\n        }\n\n        static long sub(long a,long b){\n                long x=(a-b);\n                while(x<0) x+=mod;\n                return x;\n        }\n\n        static long mul(long a,long b){\n                a%=mod;\n                b%=mod;\n                long x=(a*b);\n                return x%mod;\n        }\n\n\n        static boolean isPal(String s){\n                for(int i=0, j=s.length()-1;i<=j;i++,j--){\n                        if(s.charAt(i)!=s.charAt(j)) return false;\n                }\n                return true;\n        }\n        static String rev(String s){\n                StringBuilder sb=new StringBuilder(s);\n                sb.reverse();\n                return sb.toString();\n        }\n\n        static long gcd(long x,long y){\n                if(y==0)\n                        return x;\n                else\n                        return gcd(y,x%y);\n        }\n\n        static int gcd(int x,int y){\n                if(y==0)\n                        return x;\n                else \n                        return gcd(y,x%y);\n        }\n\n        static long gcdExtended(long a,long b,long[] x){\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                x[0]=y[1]-(b/a)*y[0];\n                x[1]=y[0];\n                return gcd;\n        }\n\n\n        static long mulmod(long  a,long b,long m) {\n                if (m <= 1000000009) return a * b % m;\n\n                long res = 0;\n                while (a > 0)\n                {\n                        if ((a&1)!=0)\n                        {\n                                res += b;\n                                if (res >= m) res -= m;\n                        }\n                        a >>= 1;\n                        b <<= 1;\n                        if (b >= m) b -= m;\n                }\n                return res;\n        }\n\n        static int abs(int a,int b){\n                return (int)Math.abs(a-b);\n        }\n\n        public static long abs(long a,long b){\n                return (long)Math.abs(a-b);\n        }\n\n        static long pow(long n,long p){\n                long  result = 1;\n                if(p==0)\n                        return 1;\n\n                while(p!=0)\n                {\n                        if(p%2==1)\n                                result *= n;        \n                        p >>=1;\n                        n*=n;       \n                }\n                return result;\n        }\n\n        static void debug(Object... o) {\n                System.out.println(Arrays.deepToString(o));\n        }\n\n        static class InputReader \n        {\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 long[] nextLongArray(int n) {\n                long a[] = new long[n];\n                for (int i = 0; i < n; i++) {\n                        a[i] = nextLong();\n                }\n                return a;\n        }\n\n        \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    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} ", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 C {\n\n    static int MOD = 1_000_000_007;\n\n    public static void main(String[] args) {\n\n        MyScanner in = new MyScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n = in.nextInt();\n        char prev = ' ';\n\n        // index, maxNumOfIntents -> count\n        int[][] dp = new int[n+1][n+2];\n\n        dp[0][0] = 1;\n        for(int i=0;i<n;++i){\n            char ch = in.next().charAt(0);\n            if(prev == 's'){\n                int sum = 0;\n                for(int j=n;j>=0;--j){\n                    sum = (sum + dp[i-1][j]) % MOD;\n                    dp[i][j] = sum;\n                }\n            }else if(prev == 'f'){\n                for(int j=0;j<n;++j){\n                    dp[i][j+1] = dp[i-1][j];\n                }\n            }\n\n            prev = ch;\n        }\n\n        int result = 0;\n        for(int i=0;i<=n;++i){\n            result = (result + dp[n-1][i]) % MOD;\n        }\n\n\n        out.println(result);\n        out.close();\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n\t\n\t//why am I MLE'ing???\n\t\n\tint n;\n\tchar[] a;\n\tlong[][] memo;\n\tlong mod = (long) 1e9 + 7;\n\t\n\tboolean lastFor(int i) {\n\t\tif(i == 0) return false;\n\t\treturn a[i - 1] == 'f';\n\t}\n\t\n\tlong dp(int ind, int curIndent) {\n\t\tif(ind == n) return 1;\n\t\tif(curIndent < 0) return 0;\n\t\tif(memo[ind][curIndent] != -1) return memo[ind][curIndent];\n\t\tlong ans = 0;\n\t\tif(a[ind] == 'f' && lastFor(ind)) {\n\t\t\tans += dp(ind + 1, curIndent + 1);\n\t\t} else if(a[ind] == 'f' && !lastFor(ind)) {\n\t\t\tans += dp(ind, curIndent - 1);\n\t\t\tans += dp(ind + 1, curIndent + 1);\n//\t\t\tfor(int indent = 1; indent <= curIndent + 1; ++indent) {\n//\t\t\t\tans += dp(ind + 1, indent);\n//\t\t\t}\n\t\t} else if(a[ind] == 's' && lastFor(ind)) {\n\t\t\tans += dp(ind + 1, curIndent);\n\t\t} else if(a[ind] == 's' && !lastFor(ind)) {\n\t\t\tans += dp(ind + 1, curIndent);\n\t\t\tans += dp(ind, curIndent - 1);\n//\t\t\tfor(int indent = 0; indent <= curIndent; ++indent) {\n//\t\t\t\tans += dp(ind + 1, indent);\n//\t\t\t}\n\t\t}\n\t\treturn memo[ind][curIndent] = ans % mod;\n\t}\n\t\n\tpublic void solve(Scanner in, PrintWriter out) {\n\t\tn = in.nextInt();\n\t\ta = new char[n];\n\t\tint forCount = 0;\n\t\tint[] fc = new int[n + 1];\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\ta[i] = in.next().charAt(0);\n\t\t\tif(a[i] == 'f') ++forCount;\n\t\t\tfc[i] = forCount;\n\t\t}\n\t\tfc[n] = fc[n - 1];\n//\t\tlong time = System.currentTimeMillis();\n\t\tmemo = new long[n][forCount + 1];\n\t\tfor(long[] aa : memo) {\n\t\t\tArrays.fill(aa, -1);\n\t\t}\n\t\tfor(int i = n; i >= 0; --i) {\n\t\t\tfor(int indent = fc[i] - 1; indent >= 0; --indent) {\n\t\t\t\tdp(i, indent);\n\t\t\t}\n\t\t}\n\t\tout.println(dp(0, 0) % mod);\n//\t\tSystem.out.println(System.currentTimeMillis() - time);\n\t}\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\n\t\tnew C().solve(in, out);\n\n\t\tin.close();\n\t\tout.close();\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 ankur\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 mod = (long) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            char ar[] = new char[n];\n            for (int i = 0; i < n; i++) {\n                ar[i] = in.readString().charAt(0);\n            }\n            long dp[][] = new long[n + 1][n + 1];\n            for (int i = 0; i < n; i++) {\n                dp[n - 1][i] = 1;\n            }\n            long prev = n;\n            for (int i = n - 2; i >= 0; i--) {\n                if (ar[i] == 'f') {\n                    if (ar[i + 1] == 's') {\n                        for (int j = n - 2; j >= 0; j--) {\n                            dp[i][j] = dp[i + 1][j + 1];\n                        }\n                    } else {\n                        for (int j = n - 2; j >= 0; j--) {\n                            dp[i][j] = dp[i + 1][j + 1];\n                        }\n\n                    }\n                } else {\n                    for (int j = n - 1; j >= 0; j--) {\n                        if (prev < 0) {\n                            prev += mod;\n                        }\n                        dp[i][j] = prev;\n                        prev = prev - dp[i + 1][j];\n                    }\n                }\n                prev = 0;\n                for (int j = 0; j < n; j++) {\n                    prev += dp[i][j];\n                    prev = prev % mod;\n                }\n            }\n            out.println(dp[0][0] % mod);\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            //*-*------clare------\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            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 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 boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        final int P = (int) 1e9 + 7;\n        int n;\n        char[] commands;\n        int[][] memo;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            commands = new char[n];\n            memo = new int[n][12345];\n            for (int i = 0; i < n; i++) {\n                commands[i] = in.next().charAt(0);\n                for (int j = 0; j < 12345; j++) {\n                    memo[i][j] = -1;\n                }\n            }\n            out.print(solve(1, 0));\n        }\n\n        int add(int a, int b) {\n            return ((a % P) + (b % P)) % P;\n        }\n\n        int solve(int i, int indents) {\n            if (i == n) return 1;\n            if (memo[i][indents] != -1) return memo[i][indents];\n            int answer;\n            if (commands[i - 1] == 'f') {\n                answer = solve(i + 1, indents + 1);\n            } else {\n                if (indents == 0) {\n                    answer = solve(i + 1, indents);\n                } else {\n                    answer = add(solve(i, indents - 1), solve(i + 1, indents));\n                }\n            }\n            return memo[i][indents] = answer;\n        }\n\n    }\n\n    static class InputReader {\n        private StringTokenizer tokenizer;\n        private BufferedReader reader;\n\n        public InputReader(InputStream inputStream) {\n            reader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        private void fillTokenizer() {\n            if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (Exception e) {\n                    throw new RuntimeException(e);\n                }\n            }\n        }\n\n        public String next() {\n            fillTokenizer();\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        static final long MODULO = (long) (1e9 + 7);\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            long[][] dp = new long[n + 100][n + 100];\n            dp[0][0] = 1;\n            for (int i = 0; i < n; ++i) {\n                char current = in.nextCharacter();\n                if (current == 'f') {\n                    for (int j = 0; j < n; ++j) {\n                        //our only option is to go 1 depth deeper\n                        dp[i + 1][j + 1] += dp[i][j];\n                        dp[i + 1][j + 1] %= MODULO;\n                    }\n                } else {\n                    long runningSum = 0;\n                    for (int j = n; j >= 0; --j) {\n                        // for each j all preceding depths are possible\n                        // can also implement partial sum to improve\n                        // time complexity to dpeth * n only(affect only if no. of f are less than n s\n                        runningSum += dp[i][j];\n                        runningSum %= MODULO;\n\n                        dp[i + 1][j] += runningSum;\n                        dp[i + 1][j] %= MODULO;\n                    }\n                }\n            }\n            out.println(dp[n][0]);\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public char nextCharacter() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            return (char) c;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 Liavontsi Brechka\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\n    @SuppressWarnings(\"Duplicates\")\n    class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int MAX = 6000;\n            int MOD = 1000000007;\n\n            int n = in.nextInt();\n            int[][] dp = new int[n][MAX];\n            dp[0][0] = 1;\n\n            char next;\n            int current;\n            for (int i = 0; i < n; i++) {\n                next = in.next().charAt(0);\n                if (i == n - 1) continue;\n\n                current = 0;\n                for (int j = MAX - 1; j >= 0; j--) {\n                    if (dp[i][j] != 0) {\n                        if (next == 'f') {\n                            if (j < MAX - 1) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;\n                        } else {\n                            current = (current + dp[i][j]) % MOD;\n                        }\n                    }\n\n                    if (next == 's') dp[i + 1][j] = current;\n                }\n            }\n\n            int res = 0;\n            for (int i = 0; i < MAX; i++) {\n                res = (res + dp[n - 1][i]) % MOD;\n            }\n\n            out.print(res);\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class C {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        List<String> commands = IntStream.range(0, n).boxed().map(x -> s.next()).collect(Collectors.toList());\n        List<Integer> ways = new ArrayList<>();\n        ways.add(1);\n        boolean lastWasS = false;\n        for (String command : commands) {\n            boolean isS = \"s\".equals(command);\n\n            if (lastWasS) {\n                for (int i = 1; i < ways.size(); ++i) {\n                    int waysNumber = (ways.get(i-1) + ways.get(i)) % 1_000_000_007;\n                    ways.set(i, waysNumber);\n                }\n            }\n\n            if (!isS) {\n                ways.add(0);\n            }\n\n            lastWasS = isS;\n        }\n        System.out.println(ways.stream().reduce(0, (a, b) -> (a + b) % 1_000_000_007));\n    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport  java.math.*;\npublic class Main {\n\n\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\t// StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tPrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\tFastScanner sc = new FastScanner();\n\t\tint dp[][]=new int[6000][6000];\n\t\tchar a[]=new char[6000];\n\t\tfinal int n=sc.nextInt();\n\t\tboolean flag=false;\n\t\tint cnt=0;\n\t\tchar pre='f';\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\t a[i]=sc.next().charAt(0);\n\n\t\t}\n\t\tdp[1][1]=1;\n\t\tfinal int mod=(int)1e9+7;\n\t\tdp[1][1]=1;\n\t\tfor(int i=2;i<=n;i++)\n\t\t{\n\t\t\tif(a[i-1]=='s')\n\t\t\t{\n\t\t\t\tint now=0;\n\t\t\t\tfor(int j=5050;j>=1;j--)\n\t\t\t\t{\n\t\t\t\t\tnow=(now+dp[i-1][j])%mod;\n\t\t\t\t\tdp[i][j]=now;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor(int j=5050;j>=1;j--)\n\t\t\t\t{\n\t\t\t\t\tdp[i][j]=dp[i-1][j-1]%mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans=0;\n\t\tfor(int i=0;i<=5050;i++)\n\t\t{\n\t\t\tans+= dp[n][i]%mod;\n\t\t\tans%=mod;\n\t\t}\n\t\tout.println(ans%mod);\n\n\t\tout.flush();\n\t}\n/*\n6\nf\ns\nf\ns\nf\ns\n\n\n\t */\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tprivate 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\t\tprivate boolean hasNextToken()\n\t\t{\n\t\t\tif(st.countTokens()!=StreamTokenizer.TT_EOF)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\t\tprivate String next() {\n\t\t\tif (st.hasMoreTokens())\treturn st.nextToken();\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tprivate BigInteger nextBigInteger(){return new BigInteger(next());}\n\t\tprivate BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\t\tprivate  int nextInt() {return Integer.parseInt(next());}\n\t\tprivate long nextLong() {return Long.parseLong(next());}\n\t\tprivate double nextDouble() {return Double.parseDouble(next());}\n\t\tprivate 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\t\tprivate int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tprivate 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\t\tprivate 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\t\tprivate 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\tprivate void sort(int arr[])\n\t\t{\n\t\t\tint cnt[]=new int[(1<<16)+1];\n\t\t\tint ys[]=new int[arr.length];\n\t\t\tfor(int j=0;j<=16;j+=16){\n\t\t\t\tArrays.fill(cnt,0);\n\t\t\t\tfor(int x:arr){cnt[(x>>j&0xFFFF)+1]++;}\n\t\t\t\tfor(int i=1;i<cnt.length;i++){cnt[i]+=cnt[i-1];}\n\t\t\t\tfor(int x:arr){ys[cnt[x>>j&0xFFFF]++]=x;}\n\t\t\t\t{ final int t[]=arr;arr=ys;ys=t;}\n\t\t\t}\n\t\t\tif(arr[0]<0||arr[arr.length-1]>=0)return;\n\t\t\tint i,j,c;\n\t\t\tfor(i=arr.length-1,c=0;arr[i]<0;i--,c++){ys[c]=arr[i];}\n\t\t\tfor(j=arr.length-1;i>=0;i--,j--){arr[j]=arr[i];}\n\t\t\tfor(i=c-1;i>=0;i--){arr[i]=ys[c-1-i];}\n\t\t}\n\t}\n\n}\n\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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.io.File;\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 ShekharN\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        private final int MOD = (int) (1e9 + 7);\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            String[] arr = new String[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = in.nextString();\n            }\n            int[] dp = new int[n];\n            Arrays.parallelSetAll(dp, i -> 0);\n            dp[0] = 1;\n            int cnt = 0;\n            for (int i = 0; i < n; i++) {\n                if (arr[i].equals(\"f\")) {\n                    cnt++;\n                    continue;\n                }\n                calc(dp, n, cnt);\n                cnt = 0;\n            }\n            int sum = 0;\n            for (int i = 0; i < n; i++) {\n                sum += dp[i];\n                sum %= MOD;\n            }\n            out.println(sum);\n        }\n\n        private void calc(int[] dp, int n, int cnt) {\n            for (int i = n - 1; i >= 0; i--) {\n                if (i != n - 1) dp[i] += dp[i + 1];\n                dp[i] %= MOD;\n            }\n            //int[] tmp = new int[n];\n            int prev = dp[0];\n            for (int i = 0, y = 0; i < MathUtil.gcdInt(n, cnt); i++) {\n                //tmp[(i+cnt)%n] = dp[i];\n                y = i;\n                prev = dp[i];\n                do {\n                    int nextId = (y + cnt) % n;\n                    int tmp = dp[nextId];\n                    dp[nextId] = prev;\n                    prev = tmp;\n                    y = nextId;\n                } while (y != i);\n\n            }\n            //Arrays.parallelSetAll(dp,i->tmp[i]);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader br;\n        private 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        public String nextString() {\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        public int nextInt() {\n            return Integer.parseInt(nextString());\n        }\n\n    }\n\n    static class MathUtil {\n        public static int gcdInt(int a, int b) {\n            if (b == 0) return a;\n            return gcdInt(b, a % b);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/*\n public class _909C {\n\n }\n\n */\npublic class _909C {\n  int mod = (int) 1e9 + 7;\n\n  public void solve() throws FileNotFoundException {\n    InputStream inputStream = System.in;\n\n    InputHelper in = new InputHelper(inputStream);\n\n    // actual solution\n    int n = in.readInteger();\n\n    char[] a = new char[n];\n\n    for (int i = 0; i < n; i++) {\n      a[i] = in.read().charAt(0);\n    }\n\n    int[][][] dp = new int[2][n + 1][2];\n\n    dp[0][0][0] = dp[0][0][1] = 1;\n\n    for (int i = 1; i < n; i++) {\n      for (int j = n; j >= 0; j--) {\n        if (a[i - 1] == 's') {\n          dp[1][j][0] = dp[1][j][1] = dp[0][j][1];\n        } else {\n          if (j > 0)\n            dp[1][j][0] = dp[1][j][1] = dp[0][j - 1][0];\n        }\n      }\n\n      for (int j = 0; j <= n; j++) {\n        dp[0][j][0] = dp[1][j][0];\n        dp[0][j][1] = dp[1][j][1];\n        dp[1][j][0] = 0;\n        dp[1][j][1] = 0;\n      }\n      for (int j = n - 1; j >= 0; j--) {\n        dp[0][j][1] += dp[0][j + 1][1];\n        dp[0][j][1] %= mod;\n      }\n    }\n\n    System.out.println(dp[0][0][1]);\n    // end here\n  }\n\n  public static void main(String[] args) throws FileNotFoundException {\n    (new _909C()).solve();\n  }\n\n  class InputHelper {\n    StringTokenizer tokenizer = null;\n    private BufferedReader bufferedReader;\n\n    public InputHelper(InputStream inputStream) {\n      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);\n      bufferedReader = new BufferedReader(inputStreamReader, 16384);\n    }\n\n    public String read() {\n      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n        try {\n          String line = bufferedReader.readLine();\n          if (line == null) {\n            return null;\n          }\n          tokenizer = new StringTokenizer(line);\n        } catch (IOException e) {\n          e.printStackTrace();\n        }\n      }\n\n      return tokenizer.nextToken();\n    }\n\n    public Integer readInteger() {\n      return Integer.parseInt(read());\n    }\n\n    public Long readLong() {\n      return Long.parseLong(read());\n    }\n  }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.*;\n\npublic class Main {\n\n    static int N;\n    static int [][] dp;\n    static int M = (int)(1e9 + 7);\n    static ArrayList<Integer> l;\n\n    static int f(int idx, int b) {\n        if(idx == l.size())\n            return 1;\n        if(dp[idx][b] != -1)\n            return dp[idx][b];\n        long ret = f(idx + 1, b + l.get(idx));\n        if(b > 0)\n            ret += f(idx, b - 1);\n        return dp[idx][b] = (int) (ret % M);\n    }\n\n    public static void main(String[] args) throws IOException{\n\t    Scanner sc = new Scanner();\n\t    N = sc.nextInt();\n        int [] val = new int[N];\n        for(int i = 0; i < N; ++i)\n            if(sc.next().charAt(0) == 's')\n                val[i] = 0;\n            else\n                val[i] = 1;\n        l = new ArrayList<Integer>();\n        l.add(val[0]);\n\n        for(int i = 1; i < N; ++i)\n            if(val[i] == val[i - 1] && val[i] == 1) {\n                int prev = l.get(l.size() - 1);\n                l.set(l.size() - 1, ++prev);\n            } else if(val[i - 1] == 0){\n                l.add(val[i]);\n            }\n\n//        System.out.println(l);\n        dp = new int[l.size() + 1][N + 1];\n        for(int i = 0; i <= l.size(); ++i)\n            Arrays.fill(dp[i], -1);\n        System.out.println(f(0, 0));\n\n    }\n\n\n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        Scanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\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        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    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class PythonIndentiation {\n\tPrintWriter pw = new PrintWriter(System.out);\n\tfinal static boolean debugmode = true;\n\tpublic static int k = 7; // for 10^9 + k mods.\n\tpublic static int STMOD = 1000000000 + k; // 10^9 + k\n\tpublic static Reader sc = new Reader();\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint commands = sc.nextInt();\n\t\tint[][] dp = new int[5000][5000];\n\t\tint interesting = 0;\n\t\tString prgm = \"\";\n\t\twhile (interesting < commands){\n\t\t\tbyte q = sc.read();\n\t\t\tif (q == 115 ){\n\t\t\t\tinteresting += 1;\n\t\t\t\tprgm += \"s\";\n\t\t\t}\n\t\t\telse if (q == 102){\n\t\t\t\tprgm += \"f\";\n\t\t\t\tinteresting += 1;\n\t\t\t}\n\t\t}\n\t\t//System.out.println(\"Program: \"+prgm);\n\t\tdp[0][0] = 1; // line, indentations\n\t\tfor(int line = 1;line<commands;line++){\n\t\t\tif(prgm.charAt(line-1) == 'f'){\n\t\t\t\tfor(int indent  = 1;indent<Math.min(2*line + 1, 5000);indent++){\n\t\t\t\t\tdp[line][indent] = dp[line-1][indent-1];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(prgm.charAt(line-1) == 's'){\n\t\t\t\tint w = 0;\n\t\t\t\tfor(int indent = Math.min(2*line + 1, 4999);indent >= 0;indent--){\n\t\t\t\t\tw = (w + dp[line-1][indent])% STMOD;\n\t\t\t\t\t\n\t\t\t\t\tdp[line][indent] = w ;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint q = 0;\n\t\tfor(int i = 0;i<5000;i++){\n\t\t\tq  = ( q + dp[commands-1][i] ) % STMOD;\n\t\t}\n\t\tSystem.out.println(q);\n\t\t\n\t    \n\t}\n\tpublic static String parseIt(int commands) throws IOException{\n\t\tString c = \"\";\n\t\tSystem.out.println(sc.read());\n\t\treturn c;\n\t}\n\tstatic class Reader\n    {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n \n        public Reader()\n        {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n \n        public Reader(String file_name) throws IOException\n        {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n \n        public String readLine() throws IOException\n        {\n            byte[] buf = new byte[64]; // line length\n            int cnt = 0, c;\n            while ((c = read()) != -1)\n            {\n                if (c == '\\n')\n                    break;\n                buf[cnt++] = (byte) c;\n            }\n            return new String(buf, 0, cnt);\n        }\n \n        public int nextInt() throws IOException\n        {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do\n            {\n                ret = ret * 10 + c - '0';\n            }  while ((c = read()) >= '0' && c <= '9');\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        public long nextLong() throws IOException\n        {\n            long ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        public double nextDouble() throws IOException\n        {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n \n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n \n            if (c == '.')\n            {\n                while ((c = read()) >= '0' && c <= '9')\n                {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        private void fillBuffer() throws IOException\n        {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n            if (bytesRead == -1)\n                buffer[0] = -1;\n        }\n \n        private byte read() throws IOException\n        {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n \n        public void close() throws IOException\n        {\n            if (din == null)\n                return;\n            din.close();\n        }\n    }\n \n    \n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.lang.Math;\nimport java.io.*;    \nimport java.util.*;\n \npublic class Main {\n        \n        static BufferedReader in;\n        static PrintStream out;\n        static StringTokenizer tok;\n        \n        @SuppressWarnings(\"empty-statement\")\n\tpublic static void main(String[] args) throws NumberFormatException, IOException, Exception {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            //in = new BufferedReader(new FileReader(\"metro.txt\"));\n            out = System.out;\n            \n            long mod = (long)1e9 + 7;\n            int n = nextInt();\n            long[][] dp = new long[n+1][n+1];\n            Character[] line = new Character[n+1];\n            line[0] = 'a';\n            for (int i = 1; i <= n; i++) {\n                line[i] = nextToken().charAt(0);\n                if(line[i-1] == 'f')//for\n                {\n                    for (int j = 0; j < i; j++) {\n                        dp[i][j+1] = dp[i-1][j];\n                    }\n                }\n                else if(line[i-1] == 's')//simple\n                {\n                    long temp = 0;\n                    for(int j = i; j >=0; j--)\n                    {\n                        temp = (temp + dp[i-1][j]) % mod;\n                        dp[i][j] = temp;\n                    }\n                }\n                else dp[i][0] = 1;\n            }\n            long total = 0;\n            for(int j = 0; j <= n; j++)\n                total = (total + dp[n][j]) % mod;\n            out.println(total);\n        }\n        static String nextToken() throws IOException\n        {\n                String line = \"\";\n                while(tok == null || !tok.hasMoreTokens()) {\n                        if((line = in.readLine()) != null)\n                                tok = new StringTokenizer(line);\n                        else \n                                return null;\n                }\n                return tok.nextToken();\n        }\n        static int nextInt() throws NumberFormatException, IOException\n        {\n                return Integer.parseInt(nextToken());\n        }\n        static long nextLong() throws NumberFormatException, IOException\n        {\n                return Long.parseLong(nextToken());\n        }\n\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n    public static void main(String[] args) throws Exception {\n        MyReader reader = new MyReader(System.in);\n//        MyReader reader = new MyReader(new FileInputStream(\"input.txt\"));\n        MyWriter writer = new MyWriter(System.out);\n        new Solution().run(reader, writer);\n        writer.close();\n    }\n\n    private void run(MyReader reader, MyWriter writer) throws IOException, InterruptedException {\n        int n = reader.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = reader.nextString().charAt(0);\n        }\n        long[][] d = new long[n + 1][n + 1];\n        d[0][0] = 1;\n        long mod = 1_000_000_007;\n        for (int i = 1; i < n; i++) {\n            for (int j = n - 1; j >= 0; j--) {\n                if (a[i - 1] == 'f') {\n                    d[i][j + 1] = d[i - 1][j];\n                } else {\n                    d[i][j] = (d[i - 1][j] + d[i][j + 1]) % mod;\n                }\n            }\n        }\n        long ans = 0;\n        for (int i = 0; i <= n; i++) {\n            ans += d[n - 1][i];\n        }\n        writer.print(ans % mod);\n    }\n\n    static class MyReader {\n\n        final BufferedInputStream in;\n        final int bufSize = 1 << 16;\n        final byte buf[] = new byte[bufSize];\n        int i = bufSize;\n        int k = bufSize;\n        boolean end = false;\n        final StringBuilder str = new StringBuilder();\n\n        MyReader(InputStream in) {\n            this.in = new BufferedInputStream(in, bufSize);\n        }\n\n        int nextInt() throws IOException {\n            return (int) nextLong();\n        }\n\n        int[] nextIntArray(int n) throws IOException {\n            int[] m = new int[n];\n            for (int i = 0; i < n; i++) {\n                m[i] = nextInt();\n            }\n            return m;\n        }\n\n        int[][] nextIntMatrix(int n, int m) throws IOException {\n            int[][] a = new int[n][0];\n            for (int j = 0; j < n; j++) {\n                a[j] = nextIntArray(m);\n            }\n            return a;\n        }\n\n        long nextLong() throws IOException {\n            int c;\n            long x = 0;\n            boolean sign = true;\n            while ((c = nextChar()) <= 32) ;\n            if (c == '-') {\n                sign = false;\n                c = nextChar();\n            }\n            if (c == '+') {\n                c = nextChar();\n            }\n            while (c >= '0') {\n                x = x * 10 + (c - '0');\n                c = nextChar();\n            }\n            return sign ? x : -x;\n        }\n\n        long[] nextLongArray(int n) throws IOException {\n            long[] m = new long[n];\n            for (int i = 0; i < n; i++) {\n                m[i] = nextLong();\n            }\n            return m;\n        }\n\n        int nextChar() throws IOException {\n            if (i == k) {\n                k = in.read(buf, 0, bufSize);\n                i = 0;\n            }\n            return i >= k ? -1 : buf[i++];\n        }\n\n        String nextString() throws IOException {\n            if (end) {\n                return null;\n            }\n            str.setLength(0);\n            int c;\n            while ((c = nextChar()) <= 32 && c != -1) ;\n            if (c == -1) {\n                end = true;\n                return null;\n            }\n            while (c > 32) {\n                str.append((char) c);\n                c = nextChar();\n            }\n            return str.toString();\n        }\n\n        String nextLine() throws IOException {\n            if (end) {\n                return null;\n            }\n            str.setLength(0);\n            int c = nextChar();\n            while (c != '\\n' && c != '\\r' && c != -1) {\n                str.append((char) c);\n                c = nextChar();\n            }\n            if (c == -1) {\n                end = true;\n                if (str.length() == 0) {\n                    return null;\n                }\n            }\n            if (c == '\\r') {\n                nextChar();\n            }\n            return str.toString();\n        }\n\n        char[] nextCharArray() throws IOException {\n            return nextString().toCharArray();\n        }\n\n        char[][] nextCharMatrix(int n) throws IOException {\n            char[][] a = new char[n][0];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextCharArray();\n            }\n            return a;\n        }\n    }\n\n    static class MyWriter {\n\n        final BufferedOutputStream out;\n        final int bufSize = 1 << 16;\n        final byte buf[] = new byte[bufSize];\n        int i = 0;\n        final byte c[] = new byte[30];\n        static final String newLine = System.getProperty(\"line.separator\");\n\n        MyWriter(OutputStream out) {\n            this.out = new BufferedOutputStream(out, bufSize);\n        }\n\n        void print(long x) throws IOException {\n            int j = 0;\n            if (i + 30 >= bufSize) {\n                flush();\n            }\n            if (x < 0) {\n                buf[i++] = (byte) ('-');\n                x = -x;\n            }\n            while (j == 0 || x != 0) {\n                c[j++] = (byte) (x % 10 + '0');\n                x /= 10;\n            }\n            while (j-- > 0)\n                buf[i++] = c[j];\n        }\n\n        void print(int[] m) throws IOException {\n            for (int a : m) {\n                print(a);\n                print(' ');\n            }\n        }\n\n        void print(long[] m) throws IOException {\n            for (long a : m) {\n                print(a);\n                print(' ');\n            }\n        }\n\n        void print(String s) throws IOException {\n            for (int i = 0; i < s.length(); i++) {\n                print(s.charAt(i));\n            }\n        }\n\n        void print(char x) throws IOException {\n            if (i == bufSize) {\n                flush();\n            }\n            buf[i++] = (byte) x;\n        }\n\n        void print(char[] m) throws IOException {\n            for (char c : m) {\n                print(c);\n            }\n        }\n\n        void println(String s) throws IOException {\n            print(s);\n            println();\n        }\n\n        void println() throws IOException {\n            print(newLine);\n        }\n\n        void flush() throws IOException {\n            out.write(buf, 0, i);\n            out.flush();\n            i = 0;\n        }\n\n        void close() throws IOException {\n            flush();\n            out.close();\n        }\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\npublic class init {\nstatic class p{\n\tint i;\n\tint c;\n\tpublic p(int i,int c) {\n\t\tthis.i=i;this.c=c;\n\t\t// TODO Auto-generated constructor stub\n\t}\n}\nstatic int mod=1000000007;\n\tpublic static void main(String[] args) {\n\t\n\t\t// TODO Auto-generated method stub\nScanner s=new Scanner(System.in);\nint n=s.nextInt();\nint a[]=new int[n];\nfor(int i=0;i<n;i++) {\n\tchar c=s.next().charAt(0);\n\tif(c=='f')\n\t\ta[i]=1;\n\t\t\n}\nint dp[][]=new int[n+1][n+1];\nfor(int i=0;i<=n;i++) {\n\tfor(int j=0;j<=n;j++)\n\t\tdp[i][j]=-1;\n}\nSystem.out.println(ans(dp,1,0,a,n));\n\t}\n\tpublic static int ans(int dp[][],int i,int j,int a[],int n) {\n\t\tif(i==n) {\n\t\t\t\n\t\t\treturn 1;\n\t\t}\n\t\tif(dp[i][j]!=-1) {\n\t\t\treturn dp[i][j];\n\t\t}\n\t\tif(a[i-1]==1) {\n\t\t\tint x=ans(dp,i+1,j+1,a,n);\n\t\t\tif(x!=-1)\n\t\t\t\tdp[i][j]=x%mod;\n\t\t}\n\t\telse {\n\t\t\tint x=-1;\n\t\t\tif(j!=0)\n\t\t\tx=ans(dp,i,j-1,a,n);\n\t\t\tint y=ans(dp,i+1,j,a,n);\n\t\t\tif(x!=-1)\n\t\t\t\tdp[i][j]=x%mod;\n\t\t\tif(y!=-1) {\n\t\t\t\tif(dp[i][j]==-1)\n\t\t\t\t\tdp[i][j]=y%mod;\n\t\t\t\telse\n\t\t\t\tdp[i][j]+=y%mod;}\n\t\t}\n\t\treturn dp[i][j];\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces455Div2C {\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\tchar[] list = new char[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tlist[i] = sp[0].charAt(0);\n\t\t}\n\t\t\n\t\tint[] list2 = new int[n];\n\t\tint counter = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (list[i] == 's') {\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlist2[counter]++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp = new int[counter][n-counter+1];\n\t\tint[][] dpsum = new int[counter][n-counter+1];\n\t\tint[] count = new int[counter];\n\t\tcount[0] = list2[0];\n\t\tfor (int i = 1; i < counter; i++) {\n\t\t\tcount[i] = count[i-1] + list2[i];\n\t\t}\n\t\t\n\t\tfor (int i = 0; i <= count[0]; i++) {\n\t\t\tdp[0][i] = 1;\n\t\t\tdpsum[0][i] = i+1;\n\t\t}\n\t\tfor (int i = 1; i < counter; i++) {\n\t\t\tfor (int j = 0; j <= count[i]; j++) {\n\t\t\t\tdp[i][j] = dpsum[i-1][Math.min(j, count[i-1])];\n\t\t\t}\n\t\t\tdpsum[i][0] = dp[i][0];\n\t\t\tfor (int j = 1; j <= count[i]; j++) {\n\t\t\t\tdpsum[i][j] = (dpsum[i][j-1]+dp[i][j])%1000000007;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[counter-1][n-counter]);\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ProblemC {\n\tstatic long MOD = 1_000_000_007;\n\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tboolean[] isFor = new boolean[n];\n\t\tfor (int a = 0; a < n; a++) {\n\t\t\tisFor[a] = input.next().charAt(0) == 'f';\n\t\t}\n\t\tlong[][] array = new long[n + 1][n + 1];\n\t\tarray[0][0] = 1;\n\t\tboolean isPreviousFor = false;\n\t\tfor (int idx = 0; idx < n; idx++) {\n\t\t\tlong heightCache = 0;\n\t\t\tfor (int height = n-1; height >= 0; height--) {\n\t\t\t\tif (isPreviousFor) {\n\t\t\t\t\tarray[idx + 1][height + 1] += array[idx][height];\n\t\t\t\t\tarray[idx + 1][height + 1] %= MOD;\n\t\t\t\t} else {\n\t\t\t\t\theightCache += array[idx][height];\n\t\t\t\t\theightCache %= MOD;\n\t\t\t\t\tarray[idx + 1][height] += heightCache;\n\t\t\t\t\tarray[idx + 1][height] %= MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t\tisPreviousFor = isFor[idx];\n\t\t}\n//\t\tSystem.out.println(Arrays.deepToString(array));\n\t\tlong sum = 0;\n\t\tfor (int height = 0; height <= n; height++) {\n\t\t\tsum += array[n][height];\n\t\t}\n\t\tSystem.out.println(sum % MOD);\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n//http://codeforces.com/contest/909/problem/C\npublic class PythInd {\n\tpublic static final int MOD = 1000000007;\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = Integer.parseInt(sc.nextLine());\n\t\tString[] sTypes = new String[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsTypes[i] = sc.nextLine();\n\t\t}\n\t\tsc.close();\n\t\t// dp[i][j] = number of ways to have a for loop indented\n\t\t// j times at the ith position.\n\t\tint[][] dp = new int[n][n];\n\t\tdp[0][0] = 1;\n\t\tfor (int i = 0; i < dp.length - 1; i++) {\n\t\t\tif (sTypes[i].equals(\"s\")) {\n\t\t\t\tint curSum = 0;\n\t\t\t\tfor (int j = i + 1; j >= 0; j--) {\n\t\t\t\t\tcurSum = (dp[i][j] + curSum) % MOD;\n\t\t\t\t\tdp[i + 1][j] += curSum;\n\t\t\t\t\tdp[i + 1][j] %= MOD;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int j = 1; j <= i + 1; j++) {\n\t\t\t\t\tdp[i + 1][j] += dp[i][j - 1];\n\t\t\t\t\tdp[i + 1][j] %= MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < dp[0].length; i++) {\n\t\t\tans = (ans + dp[n - 1][i]) % MOD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Optional;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tMain main = new Main();\n\t\tmain.solveC();\n\t}\n\n\tprivate void solveA() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString first = sc.next();\n\t\tString last = sc.next();\n\t\tString answer = first.substring(0, 1) + last.substring(0, 1);\n\t\tfor (int i = 2; i <= first.length(); i++) {\n\t\t\tString current = first.substring(0, i) + last.substring(0, 1);\n\t\t\tif (answer.compareTo(current) > 0) {\n\t\t\t\tanswer = current;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(answer);\n\t}\n\n\tprivate void solveB() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tint layer = 0;\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\tint max = N - i + 1;\n\t\t\tlayer += i < max ? i : max;\n\t\t}\n\t\tSystem.out.println(layer);\n\t}\n\n\tprivate void solveC() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tfinal long MOD_NUM = 1000000007L;\n\t\tint N = sc.nextInt();\n\t\tlong[] level = new long[N + 2];\n\t\tlevel[0] = 1;\n\t\tsc.nextLine();\n\t\tString pre = \"s\";\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tString line = sc.nextLine();\n\t\t\tlong[] next_level = new long[N + 2];\n\t\t\tif (pre.equals(\"f\")) {\n\t\t\t\tfor (int j = 1; j < N + 1; j++) {\n\t\t\t\t\tnext_level[j] = level[j - 1];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pre.equals(\"s\")) {\n\t\t\t\tfor (int j = N; j >= 0; j--) {\n\t\t\t\t\tnext_level[j] = (next_level[j + 1] + level[j]) % MOD_NUM;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpre = line;\n\t\t\tlevel = next_level;\n\t\t}\n\t\tlong answer = 0L;\n\t\tfor (int i = 0; i < N + 1; i++) {\n\t\t\tanswer = (answer + level[i]) % MOD_NUM;\n\t\t}\n\t\tSystem.out.println(answer);\n\t}\n\n\tprivate void solveD() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(N);\n\t}\n\n\tprivate void solveE() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(N);\n\t}\n\n\tprivate void solveF() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(N);\n\t}\n\n\tinterface Graph {\n\t\tvoid link(int from, int to, long cost);\n\t\tOptional<Long> getCost(int from, int to);\n\t\tint getVertexNum();\n\t}\n\n\tinterface FlowResolver {\n\t\tlong maxFlow(int from, int to);\n\t}\n\n\t/**\n\t * \u30b0\u30e9\u30d5\u306e\u884c\u5217\u306b\u3088\u308b\u5b9f\u88c5\n\t * \u63a5\u70b9\u6570\u306e\u5927\u304d\u3044\u30b0\u30e9\u30d5\u3067\u4f7f\u3046\u3068MLE\u3067\u6b7b\u306b\u305d\u3046\n\t */\n\tclass ArrayGraph implements Graph {\n\t\tprivate Long[][] costArray;\n\t\tprivate int vertexNum;\n\n\t\tpublic ArrayGraph(int n) {\n\t\t\tcostArray = new Long[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tcostArray[i] = new Long[n];\n\t\t\t}\n\t\t\tvertexNum = n;\n\t\t}\n\n\t\t@Override\n\t\tpublic void link(int from, int to, long cost) {\n\t\t\tcostArray[from][to] = new Long(cost);\n\t\t}\n\n\t\t@Override\n\t\tpublic Optional<Long> getCost(int from, int to) {\n\t\t\treturn Optional.ofNullable(costArray[from][to]);\n\t\t}\n\n\t\t@Override\n\t\tpublic int getVertexNum() {\n\t\t\treturn vertexNum;\n\t\t}\n\t}\n\n\t/**\n\t * DFS(\u6df1\u3055\u512a\u5148\u63a2\u7d22)\u306b\u3088\u308b\u5b9f\u88c5\n\t * \u8a08\u7b97\u91cf\u306fO(E*MaxFlow)\u306e\u306f\u305a (E:\u8fba\u306e\u6570, MaxFlow:\u6700\u5927\u30d5\u30ed\u30fc)\n\t */\n\tclass DfsFlowResolver implements FlowResolver {\n\t\tprivate Graph graph;\n\t\tpublic DfsFlowResolver(Graph graph) {\n\t\t\tthis.graph = graph;\n\t\t}\n\n\t\t/**\n\t\t * \u6700\u5927\u30d5\u30ed\u30fc(\u6700\u5c0f\u30ab\u30c3\u30c8)\u3092\u6c42\u3081\u308b\n\t\t * @param from \u59cb\u70b9(source)\u306eID\n\t\t * @param to \u7d42\u70b9(target)\u306eID\n\t\t * @return \u6700\u5927\u30d5\u30ed\u30fc(\u6700\u5c0f\u30ab\u30c3\u30c8)\n\t\t */\n\t\tpublic long maxFlow(int from, int to) {\n\t\t\tlong sum = 0L;\n\t\t\tlong currentFlow;\n\t\t\tdo {\n\t\t\t\tcurrentFlow = flow(from, to, Long.MAX_VALUE / 3, new boolean[graph.getVertexNum()]);\n\t\t\t\tsum += currentFlow;\n\t\t\t} while (currentFlow > 0);\n\t\t\treturn sum;\n\t\t}\n\n\t\t/**\n\t\t * \u30d5\u30ed\u30fc\u306e\u5b9f\u884c \u30b0\u30e9\u30d5\u306e\u66f4\u65b0\u3082\u884c\u3046\n\t\t * @param from \u73fe\u5728\u3044\u308b\u7bc0\u70b9\u306eID\n\t\t * @param to \u7d42\u70b9(target)\u306eID\n\t\t * @param current_flow \u3053\u3053\u307e\u3067\u306e\u6d41\u91cf\n\t\t * @param passed \u65e2\u306b\u901a\u3063\u305f\u7bc0\u70b9\u304b\u5426\u304b\u3092\u683c\u7d0d\u3057\u305f\u914d\u5217\n\t\t * @return \u7d42\u70b9(target)\u306b\u6d41\u3057\u305f\u6d41\u91cf/\u623b\u308a\u306e\u30b0\u30e9\u30d5\u306e\u6d41\u91cf\n\t\t */\n\t\tprivate long flow(int from, int to, long current_flow, boolean[] passed) {\n\t\t\tpassed[from] = true;\n\t\t\tif (from == to) {\n\t\t\t\treturn current_flow;\n\t\t\t}\n\t\t\tfor (int id = 0; id < graph.getVertexNum(); id++) {\n\t\t\t\tif (passed[id]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tOptional<Long> cost = graph.getCost(from, id);\n\t\t\t\tif (cost.orElse(0L) > 0) {\n\t\t\t\t\tlong nextFlow = current_flow < cost.get() ? current_flow : cost.get();\n\t\t\t\t\tlong returnFlow = flow(id, to, nextFlow, passed);\n\t\t\t\t\tif (returnFlow > 0) {\n\t\t\t\t\t\tgraph.link(from, id, cost.get() - returnFlow);\n\t\t\t\t\t\tgraph.link(id, from, graph.getCost(id, from).orElse(0L) + returnFlow);\n\t\t\t\t\t\treturn returnFlow;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0L;\n\t\t}\n\t}\n\n\t/**\n\t * 1-indexed\u306eBIT\u914d\u5217\n\t */\n\tclass BinaryIndexedTree {\n\t\tprivate long[] array;\n\n\t\tpublic BinaryIndexedTree(int size) {\n\t\t\tthis.array = new long[size + 1];\n\t\t}\n\n\t\t/**\n\t\t * \u6307\u5b9a\u3057\u305f\u8981\u7d20\u306b\u5024\u3092\u52a0\u7b97\u3059\u308b\n\t\t * \u8a08\u7b97\u91cf\u306fO(logN)\n\t\t * @param index \u52a0\u7b97\u3059\u308b\u8981\u7d20\u306e\u6dfb\u5b57\n\t\t * @param value \u52a0\u7b97\u3059\u308b\u91cf\n\t\t */\n\t\tpublic void add(int index, long value) {\n\t\t\tfor (int i = index; i < array.length; i += (i & -i)) {\n\t\t\t\tarray[i] += value;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 1\u301c\u6307\u5b9a\u3057\u305f\u8981\u7d20\u307e\u3067\u306e\u548c\u3092\u53d6\u5f97\u3059\u308b\n\t\t * \u8a08\u7b97\u91cf\u306fO(logN)\n\t\t * @param index \u548c\u306e\u7d42\u7aef\n\t\t * @return 1\u301cindex\u307e\u3067\u306e\u548c\n\t\t */\n\t\tpublic long getSum(int index) {\n\t\t\tlong sum = 0L;\n\t\t\tfor (int i = index; i > 0; i -= (i & -i)) {\n\t\t\t\tsum += array[i];\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A{\n       \n       public static int mod = 1000000007;\n       \n       public static void main(String args[]){\n              Scanner sc = new Scanner(System.in);\n              int n = sc.nextInt();\n              char s[] = new char[n];\n              for(int i = 0; i < n; i++)\n                     s[i] = sc.next().charAt(0);\n              int dp[][] = new int[5001][5001];\n              int sum[][] = new int[5001][5001];\n              dp[0][0] = 1;\n              sum[0][0] = 1;\n              for(int i = 1; i < n; i++){\n                     for(int j = n - 1; j >= 0; j--){\n                            if(s[i-1] == 'f' && j > 0){\n                                   dp[i][j] = dp[i-1][j-1] % mod;\n                            }else if(s[i-1] == 's'){\n                                   dp[i][j] = sum[i-1][j] % mod;\n                            }\n                            sum[i][j] = (sum[i][j+1] + dp[i][j]) % mod;\n                     }\n              }\n              System.out.println(sum[n-1][0]);\n       }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 */\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        C909 solver = new C909();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class C909 {\n        int N;\n        long MOD = 1_000_000_007;\n        boolean[] type;\n        long[][] memo;\n\n        long dp(int cmd, int dep) {\n            // safe if we came out of a statement, we can traverse\n            if (dep < 0) return 0;\n            if (cmd == N) return 1;\n            if (memo[cmd][dep] != -1) return memo[cmd][dep];\n\n            boolean safe = cmd == 0 ? true : !type[cmd - 1];\n            int d = type[cmd] ? 1 : 0;\n\n            long ways = 0;\n            if (!safe) {\n                // we must use this indentation\n                ways += dp(cmd + 1, dep + d);\n                ways %= MOD;\n            } else {\n                ways += dp(cmd + 1, dep + d);\n                ways %= MOD;\n                ways += dp(cmd, dep - 1);\n                ways %= MOD;\n            }\n\n            return memo[cmd][dep] = ways;\n        }\n\n        public void solve(int testNumber, FastScanner s, PrintWriter out) {\n            N = s.nextInt();\n            type = new boolean[N];\n            for (int i = 0; i < N; i++) {\n                type[i] = s.next().charAt(0) == 'f';\n            }\n\n            memo = new long[N][N + 1];\n            for (long[] a : memo)\n                Arrays.fill(a, -1);\n\n            out.println(dp(0, 0));\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 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}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\n    static MyScanner sc;\n    private static PrintWriter out;\n    static long M2 = 1_000_000_000L + 7;\n\n    private static HashMap<Long, Long>[] mods;\n\n    public static void main(String[] s) throws Exception {\n        StringBuilder stringBuilder = new StringBuilder();\n\n//        stringBuilder.append(\"7 3\\n\" +\n//                \"1 5 2 6 3 7 4\\n\" +\n//                \"2 5 3\\n\" +\n//                \"4 4 1\\n\" +\n//                \"1 7 3\");\n\n//\n//        Random r = new Random(5);\n//        stringBuilder.append(\"100000 5000 \");\n//        for (int i = 0; i < 100000; i++) {\n//            stringBuilder.append(\" \" + (r.nextInt(2000000000) - 1000000000) + \" \");\n//\n//        }\n//        for (int k = 0; k < 5000; k++) {\n//            stringBuilder.append(\" 1 100000 777 \");\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\n        out.flush();\n    }\n\n\n    private static void solve() throws IOException {\n        int n = sc.nextInt();\n        boolean[] k = new boolean[n];\n\n        for (int r = 0; r < n; r++) {\n            k[r] = sc.next().charAt(0) == 'f';\n        }\n        if (k[n - 1]) {\n            out.println(0);\n            return;\n        }\n        long[][] res = new long[n + 1][n + 1];\n        res[0][0] = 1;\n        for (int t = 0; t < n; t++) {\n\n            boolean pl = t != 0 && k[t - 1];\n            if (pl) {\n                System.arraycopy(res[t], 0, res[t + 1], 1, n);\n            } else {\n                long last = 0;\n                for (int f = n; f >= 0; f--) {\n                    last += res[t][f];\n                    last %= M2;\n                    res[t + 1][f] = last;\n                }\n            }\n        }\n        long pp = 0;\n        for (long kk : res[n]) {\n            pp += kk;\n            pp %= M2;\n        }\n        out.println(pp);\n    }\n\n    private static void initData() {\n\n\n    }\n\n    static char[][] data;\n    static String cmd;\n\n    private static final class STree {\n        private final Comparator<Integer> comparator;\n        int[] val1;\n        int[] from1;\n        int[] to1;\n        int[] max1;\n\n        public STree(int c, Comparator<Integer> comparator) {\n            this.comparator = comparator;\n            int size = Integer.highestOneBit(c);\n            if (size != c) {\n                size <<= 1;\n            }\n            int rs = size << 1;\n            val1 = new int[rs];\n            from1 = new int[rs];\n            max1 = new int[rs];\n            to1 = new int[rs];\n\n            Arrays.fill(from1, Integer.MAX_VALUE);\n            for (int r = rs - 1; r > 1; r--) {\n                if (r >= size) {\n                    from1[r] = r - size;\n                    to1[r] = r - size;\n                }\n                from1[r / 2] = Math.min(from1[r / 2], from1[r]);\n                to1[r / 2] = Math.max(to1[r / 2], to1[r]);\n            }\n        }\n\n        public int max(int from, int to) {\n            return max(1, from, to);\n        }\n\n        private int max(int cur, int from, int to) {\n            if (cur >= val1.length) return -1;\n            if (from <= from1[cur] && to1[cur] <= to) {\n                return max1[cur];\n            }\n            if (from1[cur] > to || from > to1[cur]) {\n                return -1;\n            }\n            cur <<= 1;\n\n            return max0(max(cur, from, to), max(cur + 1, from, to));\n        }\n\n\n        public void put(int x, int val) {\n            x += val1.length >> 1;\n            val1[x] = val;\n            max1[x] = val;\n            addToParent(x);\n        }\n\n\n        private void addToParent(int cur) {\n            while (cur > 1) {\n                cur >>= 1;\n                max1[cur] = max0(max1[cur << 1], max1[1 + (cur << 1)]);\n            }\n        }\n\n        private int max0(int i, int i1) {\n            if (i == -1) return i1;\n            if (i1 == -1) return i;\n            return comparator.compare(i, i1) > 0 ? i1 : i;\n        }\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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\n\npublic class C {\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[]dp1 = new int[n+1];\n\t\tint[]dp2 = new int[n+1];\n\t\tdp1[1] = 1;\n\t\tint mod = (int) (1e9+7);\n\t\tchar[]instruction = new char[n+1];\n\t\tinstruction[0] = 's';\n\t\tint[]sum = new int[n+1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tinstruction[i] = next().charAt(0);\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tsum[j] = sum[j-1] + dp1[j];\n\t\t\t\tif (sum[j] >= mod)\n\t\t\t\t\tsum[j] -= mod;\n\t\t\t}\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tif (instruction[i-1]=='f')\n\t\t\t\t\tdp2[j] = dp1[j-1];\n\t\t\t\telse {\n\t\t\t\t\tdp2[j] = sum[i] - sum[j-1];\n\t\t\t\t\tif (dp2[j] < 0)\n\t\t\t\t\t\tdp2[j] += mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tdp1[j] = dp2[j];\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tans += dp1[i];\n\t\t\tif (ans >= mod)\n\t\t\t\tans -= mod;\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.text.*;\nimport java.io.*;\nimport java.math.*;\npublic class code5 {\n\tInputStream is;\n\tPrintWriter out;\n\tstatic long mod=pow(10,9)+7;\n\tstatic int dx[]={0,0,1,-1},dy[]={1,-1,0,0};\n\tString arr[];\n\tlong dp[][];\n\tvoid solve() throws IOException\n\t{\n\t\tint n=ni();\n\t\tarr=new String[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tarr[i]=ns();\n\t\tdp=new long[n+1][n+1];\n\t\tdp[0][0]=1;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlong next[]=new long[n+1];\n\t\t\tfor(int j=0;j<=i;j++)\n\t\t\t{\n\t\t\t\tif(arr[i].charAt(0)=='s')\n\t\t\t\t{\n\t\t\t\t\tnext[0]+=dp[i][j];\n\t\t\t\t\tnext[j+1]-=dp[i][j];\n\t\t\t\t}else {\n\t\t\t\t\tnext[j+1]+=dp[i][j];\n\t\t\t\t\tnext[j+2]-=dp[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tlong count=0;\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t{\n\t\t\t\tcount+=next[j];\n\t\t\t\tcount=(count+mod)%mod;\n\t\t\t\tdp[i+1][j]=count;\n\t\t\t}\n\t\t}\n\t\tlong ans=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tans+=dp[n-1][i];\n\t\t\tans%=mod;\n\t\t}\n\t\tout.print(ans);\n\t}\n\tlong rec(int index,int level)\n\t{\n\t\tif(index>=arr.length-1)\n\t\t\treturn 1;\n\t\tif(dp[index][level]!=-1)\n\t\t\treturn dp[index][level];\n\t\tdp[index][level]=0;\n\t\tif(arr[index].charAt(0)=='s')\n\t\t{\n\t\t\tdp[index][level]+=rec(index+1,level);\n\t\t\tdp[index][level]%=mod;\n\t\t\tif(level>0)\n\t\t\t{\n\t\t\t\tdp[index][level]+=rec(index+1,0);\n\t\t\t\tdp[index][level]%=mod;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tdp[index][level]+=rec(index+1,level+1);\n\t\t\tdp[index][level]%=mod;\n\t\t}\n\t\treturn dp[index][level];\n\t}\n\tdouble a[],b[],p;\n\tint sum(int i)\n\t{\n\t\tint sum=0;\n\t\twhile(i!=0)\n\t\t{\n\t\t\tif((i%10)%2==1)\n\t\t\t\tsum+=i%10;\n\t\t\ti/=10;\n\t\t}\n\t\treturn sum;\n\t}\n\tArrayList<Integer> al[];\n \tvoid take(int n,int m)\n \t{\n \t\tal=new ArrayList[n];\n \t\tfor(int i=0;i<n;i++)\n \t\t\tal[i]=new ArrayList<Integer>();\n \t\tfor(int i=0;i<m;i++)\n \t\t{\n \t\t\tint x=ni()-1;\n \t\t\tint y=ni()-1;\n \t\t\tal[x].add(y);\n \t\t\tal[y].add(x);\n \t\t}\n \t}\n \tint check(long n)\n \t{\n \t\tint count=0;\n \t\twhile(n!=0)\n \t\t{\n \t\t\tif(n%10!=0)\n \t\t\t\tbreak;\n \t\t\tn/=10;\n \t\t\tcount++;\n \t\t}\n \t\treturn count;\n \t}\n\tpublic static int count(int x)\n\t{\n\t\tint num=0;\n\t\twhile(x!=0)\n\t\t{\n\t\t\tx=x&(x-1);\n\t\t\tnum++;\n\t\t}\n\t\treturn num;\n\t}\n\tstatic long d, x, y;\n\tvoid extendedEuclid(long A, long B) {\n\t    if(B == 0) {\n\t        d = A;\n\t        x = 1;\n\t        y = 0;\n\t    }\n\t    else {\n\t        extendedEuclid(B, A%B);\n\t        long temp = x;\n\t        x = y;\n\t        y = temp - (A/B)*y;\n\t    }\n\t}\n\tlong modInverse(long A,long M) //A and M are coprime\n\t{\n\t    extendedEuclid(A,M);\n\t    return (x%M+M)%M;    //x may be negative\n\t}\n\tpublic static void mergeSort(int[] arr, int l ,int r){\n\t\tif((r-l)>=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 ;i<n1;i++) left[i] = arr[l+i];\n\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\tint i =0, j =0, k = l;\n\t\twhile(i<n1 && j<n2){\n\t\t\tif(left[i]>right[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<n1) arr[k++] = left[i++];\n\t\twhile(j<n2) arr[k++] = right[j++];\n\t}\n\tpublic static void mergeSort(long[] arr, int l ,int r){\n\t\tif((r-l)>=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 ;i<n1;i++) left[i] = arr[l+i];\n\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\tint i =0, j =0, k = l;\n\t\twhile(i<n1 && j<n2){\n\t\t\tif(left[i]>right[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<n1) arr[k++] = left[i++];\n\t\twhile(j<n2) arr[k++] = right[j++];\n\t}\n\t static class Pair implements Comparable<Pair>{\n\t\t \n\t       int x,y,k;\n\t       int i,dir;\n\t       long val;\n\t\tPair (int x,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}   \n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(this.x!=o.x)\n\t\t\t\treturn this.x-o.x;\n\t\t\treturn this.y-o.y;\n\t\t}\n\t \n\t\tpublic String toString(){\n\t\t\treturn x+\" \"+y+\" \"+k+\" \"+i;}\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (o instanceof Pair) {\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\tpublic int hashCode() {\n\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode() ;\n\t\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\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 code5().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 code5().run();\n\t\t}\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\tprivate long[] nl(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] = nl();\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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/*\nTASK: CFC\nLANG: JAVA\n */\npublic class CFC {\n    static int n;\n    static int[][] dp;\n    static boolean[] s;\n    public static void main(String[] args) throws IOException {\n        FastScanner in = new FastScanner(System.in); //new FileInputStream(new File(\"CFC.in\")));\n        //PrintWriter out = new PrintWriter(new File(\"CFC.out\"));\n        n = in.nextInt();\n        if(n == 1){\n            System.out.println(1);\n            return;\n        }\n        dp = new int[n][n+1];\n        s = new boolean[n];\n        for(int i = 0;i <n; i++)s[i] = in.next().equals(\"s\");\n        for(int j = 0;j < n; j++){\n            if(s[n-2])dp[n-1][j] = j+1;\n            else dp[n-1][j] = 1;\n        }\n        int suma , sumb;\n        for(int i = n-2; i >= 0; i--){\n            if(i == 0 ? true : s[i-1]){\n                if(s[i]) {\n                    for (int j = 0; j < n; j++) {\n                        dp[i][j] = ((j == 0 ? 0 : dp[i][j - 1]) + dp[i + 1][j]) % 1000000007;\n                    }\n                }\n                else{\n                    for(int j = 0;j < n; j++){\n                        dp[i][j] = ((j == 0 ? 0 : dp[i][j-1]) + dp[i+1][j+1]) % 1000000007;\n                    }\n                }\n            }\n            else{\n                if(s[i]){\n                    for(int j = 0;j < n; j++){\n                        dp[i][j] = dp[i+1][j];\n                    }\n                }\n                else{\n                    for(int j = 0;j < n; j++){\n                        dp[i][j] = dp[i+1][j+1];\n                    }\n                }\n            }\n        }\n        System.out.println(dp[0][0]);\n    }\n\n    private static class FastScanner {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n\n        public FastScanner(InputStream stream) {\n            this.stream = stream;\n        }\n\n        int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) return -1;\n            }\n            return buf[curChar++];\n        }\n\n        boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        boolean isEndline(int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public String next() {\n            int c = read();\n            while (isSpaceChar(c)) c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        public String nextLine() {\n            int c = read();\n            while (isEndline(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isEndline(c));\n            return res.toString();\n        }\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class C455C {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = Integer.parseInt(sc.nextLine());\n\t\tArrayList<Integer> listCount = new ArrayList<Integer>();\n\t\tlistCount.add(1);\n\t\tboolean justf = false;\n\t\tint p = 1000000007;\n\t\tlong ans = 0;\n\t\t\n\t\tfor(int x=0; x<n; x++){\n\t\t\tString next = sc.nextLine();\n\t\t\t\n\t\t\tif(next.equals(\"f\")){\n\t\t\t\t\n\t\t\t\tif(justf){\n\t\t\t\t\tlistCount.add(0);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t\n\t\t\t\t\tfor(int i=1; i<listCount.size(); i++){\n\t\t\t\t\t\tint sum = (listCount.get(i-1) + listCount.get(i)) % p;\n\t\t\t\t\t\tlistCount.set(i, sum);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlistCount.add(0);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tjustf = true;\n\t\t\t}\n\t\t\telse{ // \"s\"\n\t\t\t\tif(justf){\n\t\t\t\t\tjustf = false;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tfor(int i=1; i<listCount.size(); i++){\n\t\t\t\t\t\tint sum = (listCount.get(i-1) + listCount.get(i)) % p;\n\t\t\t\t\t\tlistCount.set(i, sum);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t//System.out.println(listCount);\n\t\t}\n\t\t\n\t\tfor(int i=0; i<listCount.size(); i++){\n\t\t\tans += listCount.get(i);\n\t\t}\n\t\t\n\t\tSystem.out.print((ans % p));\n\t}\n}\n\n/*\nint n = Integer.parseInt(sc.nextLine());\nString[] t = sc.nextLine().split(\" \");\nint[] list = new int[n];\nfor(int x=0; x<n; x++){\n\tlist[x] = Integer.parseInt(t[x]);\n}\n\t\t\nString[] dir = sc.nextLine().split(\" \");\nint a = Integer.parseInt(dir[0]);\nint b = Integer.parseInt(dir[1]);\nint c = Integer.parseInt(dir[2]);\nint d = Integer.parseInt(dir[3]);\nint e = Integer.parseInt(dir[4]);\n\nint n = Integer.parseInt(sc.nextLine());\n*/", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Solution {\n\t\t\n\tpublic static void main(String[] args) {\n\t\t// Write your code here\n      Scanner s=new Scanner(System.in);\n\t  int n=s.nextInt();\n\t  char[] seq=new char[n];\n\t  for(int i=0;i<n;i++){\n\t\t  seq[i]=s.next().charAt(0);  \n\t  }\n\t  long mod=(long)Math.pow(10,9)+7;\n\t  long[][] arr=new long[n][n];\n\t  arr[0][0]=1;\n\t  for(int i=1;i<n;i++){\n\t\t  if(seq[i-1]=='f'){\n\t\t\t  for(int j=1;j<n;j++){\n\t\t\t\t  arr[i][j]=arr[i-1][j-1];\n\t\t\t  }\n\t\t  }else{\n\t\t\t  long sum=0;\n\t\t\t  for(int j=n-1;j>=0;j--){\n\t\t\t\t  sum=(sum+arr[i-1][j])%mod;\n\t\t\t\t  arr[i][j]=sum;\n\t\t\t  }\n\t\t  }\n\t  }\n\t  long ans=0;\n\t  for(int i=0;i<n;i++){\n\t\t  ans=(ans+arr[n-1][i])%mod;\n\t  }\n\t  System.out.println(ans);\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class A{\n\n    void solve(){\n        int n=ni();\n        s=new char[n+1];\n        s[0]='.';\n        for(int i=1;i<=n;i++) s[i]=ns().charAt(0);\n        dp=new long[5001][5001];\n\n        dp[1][0]=1;\n        long sum[]=new long[n+2];\n        sum[0]=1;\n        for(int i=2;i<=n;i++){\n            for(int j=0;j<=n;j++) {\n                if (s[i - 1] == 'f') {\n                        if(j-1>=0) dp[i][j]=dp[i-1][j-1];\n                        else dp[i][j]=0;\n                }else {\n                   dp[i][j]=sum[j];\n                }\n            }\n            for(int j=n;j>=0;j--){\n                sum[j]=(sum[j+1]+dp[i][j])%M;\n            }\n        }\n        long ans=0;\n        for(int i=0;i<=n;i++){\n            ans+=dp[n][i];\n            if(ans>=M) ans%=M;\n        }\n        pw.println(ans);\n\n    }\n    char s[];\n    long dp[][];\n    long go(int x,int cnt,int n){\n   //    pw.println(x+\" \"+cnt);\n        if(x>n) return 1;\n        long cc=0;\n        if(dp[x][cnt]!=-1) return dp[x][cnt];\n        if(s[x]=='f'){\n            cc=(cc+go(x+1,cnt+1,n))%M;\n        }else {\n\n            for(int j=cnt;j>=0;j--) cc=(cc+go(x+1,j,n))%M;\n            if(x==n) cc=(cc-cnt+M)%M;\n        }\n        cc%=M;\n\n        dp[x][cnt]=cc;\n        return cc;\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    public static void main(String[] args) throws Exception { new A().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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class utkarsh{\n\tBufferedReader br;\n\n\tvoid solve(){\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tint i, j, n, mod = (int)(1e9 + 7);\n\t\tn = ni();\n\t\tchar c[] = new char[n];\n\t\tfor(i = 0; i < n; i++)\tc[i] = ns().charAt(0);\n\t\tlong dp[][] = new long[n][n];\n\t\tdp[0][0] = 1;\n\t\tfor(i = 1; i < n; i++){\n\t\t\tif(c[i-1] == 'f'){\n\t\t\t\tfor(j = 0; j < i; j++){\n\t\t\t\t\tdp[i][j+1] = dp[i-1][j];\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tfor(j = i-1; j >= 0; j--){\n\t\t\t\t\tdp[i][j] = dp[i-1][j] + dp[i][j+1];\n\t\t\t\t\tdp[i][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(long x : dp[n-1]){\n\t\t\tans += x;\n\t\t\tans %= mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n\tint ni(){\n\t\treturn Integer.parseInt(ns());\n\t}\n\n\tString ip[];\n\tint len, sz;\n\n\tString ns(){\n\t\tif(len >= sz){\n\t\t\ttry{\n\t\t\t\tip = br.readLine().split(\" \");\n\t\t\t\tlen = 0;\n\t\t\t\tsz = ip.length;\n\t\t\t}catch(IOException e){\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif(sz <= 0)\treturn \"-1\";\n\t\t}\n\t\treturn ip[len++];\n\t}\n\n\tpublic static void main(String[] args){\tnew utkarsh().solve();\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class c {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tint numbOfStatements = in.nextInt();\n\t\tlong[] dp = new long[numbOfStatements];\n\t\tdp[0] = 1L;\n\t\tboolean priorFor = in.next().equals(\"f\");\n\t\t\n\t\tfor(int i=0; i<numbOfStatements-1; i++)\n\t\t{\n\t\t\tString type = in.next();\n\t\t\tif (priorFor) {\n\t\t\t\tfor(int j=numbOfStatements-1;j>0;j--) {\n\t\t\t\t\tdp[j] = dp[j-1];\n\t\t\t\t}\n\t\t\t\tdp[0] = 0L;\n\t\t\t} else {\n\t\t\t\tlong sum = 0;\n\t\t\t\tfor(int j = numbOfStatements - 1; j >= 0; --j) {\n\t\t\t\t\tsum = (sum + dp[j])  % 1000000007;\n\t\t\t\t\tdp[j] = sum;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpriorFor = type.equals(\"f\");\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int j=0; j<numbOfStatements; j++) {\n\t\t\tans = (ans + dp[j]) % 1000000007;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\nimport java.util.TreeMap;\n\nimport static java.lang.Math.abs;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.sqrt;\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        solveC();\n    }\n\n    private void solveA() throws IOException {\n        char[] n = in.next().toCharArray(), s = in.next().toCharArray();\n        out.print(n[0]);\n        for (int i = 1; i < n.length && n[i] < s[0]; i++)\n            out.print(n[i]);\n        out.print(s[0]);\n    }\n\n    private void solveB() throws IOException {\n        int n = in.nextInt();\n        long dp[] = new long[n + 1];\n        for (int i = 1; i <= n; i++) {\n            dp[i] = i + (i < 3 ? 0 : dp[i - 2]);\n        }\n        out.print(dp[n]);\n    }\n\n    private void solveC() throws IOException {\n        int n = in.nextInt(), prev = -1;\n\n        long sum, mod = (long) 1e9 + 7, p;\n\n        long[] deep = new long[n + 10];\n        deep[0] = 1;\n        char c;\n        for (int cur = 0; cur < n; cur++) {\n            c = in.nextLine().charAt(0);\n            if (prev + 1 != cur) {\n                sum = 0;\n                if (c == 'f') {\n                    for (int i = deep.length - 1; i > 0; i--) {\n                        sum += deep[i - 1];\n                        sum %= mod;\n                        deep[i] = sum;\n                    }\n                    deep[0] = 0;\n                } else {\n                    for (int i = deep.length - 1; i >= 0; i--) {\n                        sum += deep[i];\n                        sum %= mod;\n                        deep[i] = sum;\n                    }\n                }\n            }\n\n            if (c != 's') {\n                if (cur == prev + 1) {\n                    for (int i = deep.length - 1; i > 0; i--) {\n                        deep[i] = deep[i - 1];\n                    }\n                    deep[0] = 0;\n                }\n                prev = cur;\n            }\n\n            //out.println(Arrays.toString(deep));\n        }\n\n        long ans = 0;\n        for (int i = 0; i < deep.length; i++) {\n            ans += deep[i];\n            ans %= mod;\n        }\n        out.println(ans);\n    }\n\n    private void solveD() throws IOException {\n\n    }\n\n    private void solveE() throws IOException {\n\n    }\n\n    class FastScanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        FastScanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        String next() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n\n        boolean hasNext() throws IOException {\n            return br.ready() || (st != null && st.hasMoreTokens());\n        }\n\n        int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() throws IOException {\n            return Double.parseDouble(next());\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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;\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 modular = (int) (1e9 + 7);\n\n        public void solve(int testNum, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int ans = 0;\n            String[] g = new String[n];\n            int[][] dp = new int[2][n];\n            for(int i = 0; i < n; i++) {\n                g[i] = in.next();\n            }\n            if(n == 1) {\n                out.println(1);\n                return;\n            }\n            dp[0][0] = 1;\n            for(int i = 1; i < n; i++) {\n                if(g[i - 1].equals(\"f\")) {\n                    dp[1][0] = 0;\n                    for(int j = 1; j < n; j++) {\n                        dp[1][j] = dp[0][j - 1];\n                    }\n                }\n                else {\n                    dp[1][n - 1] = dp[0][n - 1];\n                    for(int j = n - 2; j >= 0; j--) {\n                        dp[1][j] = dp[1][j + 1] + dp[0][j];\n                        dp[1][j] = dp[1][j] % modular;\n                    }\n                }\n                for(int j = 0; j < n; j++) {\n                    dp[0][j] = dp[1][j];\n                }\n                if(i == n - 1) {\n                    for(int j = 0; j < n; j++) {\n                        ans = ans + dp[1][j];\n                        ans = ans % modular;\n                    }\n                }\n            }\n            out.println(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}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class c {\n\t\n\tstatic boolean seq[];\n\tstatic long memo[][], mod = (long)1e9 + 7;\n\tstatic long go(int n, int d) {\n\t\tlong ans = 0;\n\t\tif(d < 0) return 0;\n\t\tif(n == seq.length) return 1;\n\t\tint f = 1;\n\t\tif(n > 0) f = seq[n-1]?1:0;\n\t\tif(memo[n][d] != -1) return memo[n][d];\n\t\tif(f == 0) {\n\t\t\tans += go(n + 1, d + (seq[n]?1:0));\n\t\t\tans %= mod;\n\t\t\tans += go(n, d-1);\n\t\t\tans %= mod;\n\t\t}\n\t\tif(f == 1) {\n\t\t\tans += go(n + 1, d + (seq[n]?1:0));\n\t\t\tans %= mod;\n\t\t}\n\t\treturn memo[n][d] = ans;\n\t}\n\t\n\tpublic static void main(String args[]) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t//BEGIN HERE\n\t\tint n = in.nextInt();\n\t\tseq = new boolean[n];\n\t\tfor (int i = 0; i  < n; i++ ) {\n\t\t\tseq[i] = (in.next().charAt(0) == 'f');\n\t\t}\n\t\tmemo = new long[n][n+1];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tArrays.fill(memo[i], -1);\n\t\t}\n\t\tSystem.out.println(go(0, 0));\n\t\tout.close();\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream i) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(i));\n\t\t\tst = null;\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\tif (st == null) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\tString line = st.nextToken(\"\\n\");\n\t\t\tst = null;\n\t\t\treturn line;\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\t}\n\n\tpublic static class combinatorics {\n\t\tstatic long modInv(long a, long b) {\n\t\t\treturn 1 < a ? b - modInv(b % a, a) * b / a : 1;\n\t\t}\n\n\t\tstatic long factorial[], mod;\n\n\t\tcombinatorics(int n, long MOD) {\n\t\t\tmod = MOD;\n\t\t\tfactorial = new long[n + 1];\n\t\t\tfactorial[0] = 1;\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tfactorial[i] = i * factorial[i - 1];\n\t\t\t\tfactorial[i] %= mod;\n\t\t\t}\n\t\t}\n\n\t\tstatic long nCr(int n, int r) {\n\t\t\tif (r > n)\n\t\t\t\treturn 0;\n\t\t\treturn (factorial[n] * modInv((factorial[n - r] * factorial[r]) % mod, mod)) % mod;\n\t\t}\n\t}\n\n\tpublic static class DisjointSet {\n\t\tint p[], r[], s[];\n\t\tint numDisjoint;\n\n\t\tDisjointSet(int N) {\n\t\t\tnumDisjoint = N;\n\t\t\tr = new int[N];\n\t\t\ts = new int[N];\n\t\t\tp = new int[N];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tp[i] = i;\n\t\t}\n\n\t\tint findSet(int i) {\n\t\t\treturn (p[i] == i) ? i : (p[i] = findSet(p[i]));\n\t\t}\n\n\t\tboolean isSameSet(int i, int j) {\n\t\t\treturn findSet(i) == findSet(j);\n\t\t}\n\n\t\tvoid unionSet(int i, int j) {\n\t\t\tif (!isSameSet(i, j)) // if from different set\n\t\t\t{\n\t\t\t\tnumDisjoint--;\n\t\t\t\tint x = findSet(i), y = findSet(j);\n\t\t\t\tif (r[x] > r[y]) {\n\t\t\t\t\tp[y] = x; // rank keeps the tree short\n\t\t\t\t\ts[x] += s[y];\n\t\t\t\t} else {\n\t\t\t\t\tp[x] = y;\n\t\t\t\t\tif (r[x] == r[y])\n\t\t\t\t\t\tr[y]++;\n\t\t\t\t\ts[y] += s[x];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint sizeOfSet(int i) {\n\t\t\treturn s[findSet(i)];\n\t\t}\n\t};\n\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "//package round455;\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 C {\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 = 1000000007;\n\t\tlong[] dp = new long[5005];\n\t\tdp[0] = 1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tchar c = nc();\n\t\t\tif(c == 's'){\n\t\t\t\tif(i < n-1){\n\t\t\t\t\tfor(int j = 5003;j >= 0;j--){\n\t\t\t\t\t\tdp[j] += dp[j+1];\n\t\t\t\t\t\tif(dp[j] >= mod)dp[j] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tfor(int j = 5003;j >= 0;j--){\n\t\t\t\t\tdp[j+1] = dp[j];\n\t\t\t\t}\n\t\t\t\tdp[0] = 0;\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = 0;i < 5005;i++)ans += dp[i];\n\t\tout.println(ans % 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 C().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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic final class PythonIndentation\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew PythonIndentation(System.in, System.out);\n\t}\n\n\tstatic class Solver implements Runnable\n\t{\n\t\tstatic final int MOD = (int) 1e9 + 7;\n\t\tint n;\n\t\tchar[] arr;\n\t\tlong[][] dp;\n\t\tBufferedReader in;\n\t\tPrintWriter out;\n\n\t\tvoid solve() throws IOException\n\t\t{\n\t\t\tn = Integer.parseInt(in.readLine());\n\t\t\tarr = new char[n];\n\t\t\tdp = new long[n + 1][n + 1];\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = in.readLine().charAt(0);\n\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\tArrays.fill(dp[i], -1);\n\n\t\t\tdp[0][0] = 1;\n\n\t\t\tif (arr[0] == 's')\n\t\t\t\tout.println(find(1, 0));\n\t\t\telse\n\t\t\t\tout.println(find(1, 1));\n\t\t}\n\n\t\tlong find(int curr, int backIndents)\n\t\t{\n\t\t\tif (backIndents < 0)\n\t\t\t\treturn 0;\n\n\t\t\tif (curr == n)\n\t\t\t\treturn 1;\n\n\t\t\tif (dp[curr][backIndents] != -1)\n\t\t\t\treturn dp[curr][backIndents];\n\n\t\t\tlong ans;\n\n\t\t\tif (arr[curr] == 's')\n\t\t\t\tans = find(curr + 1, backIndents);\n\t\t\telse\n\t\t\t\tans = find(curr + 1, backIndents + 1);\n\n\t\t\tif (arr[curr - 1] != 'f')\n\t\t\t\tans = CMath.mod(ans + find(curr, backIndents - 1), MOD);\n\n\t\t\treturn dp[curr][backIndents] = ans;\n\t\t}\n\n\t\tpublic Solver(BufferedReader 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 public 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 CMath\n\t{\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}\n\n\tprivate PythonIndentation(InputStream inputStream, OutputStream outputStream)\n\t{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tThread thread = new Thread(null, new Solver(in, out), \"PythonIndentation\", 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\ttry\n\t\t\t{\n\t\t\t\tin.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\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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        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.readInt();\n            boolean[] isF = new boolean[n];\n            for (int i = 0; i < n; i++) {\n                isF[i] = in.readCharacter() == 'f';\n            }\n            FenwickTree[] fenwickTrees = new FenwickTree[n + 1];\n            for (int i = 0; i < fenwickTrees.length; i++) {\n                fenwickTrees[i] = new FenwickTree(n + 1);\n            }\n            fenwickTrees[n].add(0, 1);\n            for (int idx = n - 1; idx >= 0; idx--) {\n                for (int indentLevel = 0; indentLevel < n; indentLevel++) {\n                    long fenwickRes;\n                    if (isF[idx]) {\n                        fenwickRes = fenwickTrees[idx + 1].get(indentLevel + 1, indentLevel + 1);\n                    } else {\n                        fenwickRes = fenwickTrees[idx + 1].get(0, indentLevel);\n                    }\n                    fenwickTrees[idx].add(indentLevel, fenwickRes % MiscUtils.MOD7);\n                }\n            }\n            out.printLine(fenwickTrees[0].get(0, 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        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    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 MiscUtils {\n        public static final int MOD7 = (int) (1e9 + 7);\n    }\n    static class FenwickTree {\n        private final long[] value;\n\n        public FenwickTree(int size) {\n            value = new long[size];\n        }\n\n        public long get(int from, int to) {\n            return get(to) - get(from - 1);\n        }\n\n        private long get(int to) {\n            to = Math.min(to, value.length - 1);\n            long result = 0;\n            while (to >= 0) {\n                result += value[to];\n                to = (to & (to + 1)) - 1;\n            }\n            return result;\n        }\n\n        public void add(int at, long value) {\n            while (at < this.value.length) {\n                this.value[at] += value;\n                at = at | (at + 1);\n            }\n        }\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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.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    TaskC solver = new TaskC();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class TaskC {\n    private long MOD = (long) (1e9 + 7);\n    int[][] dp = new int[5001][5001];\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n      ArrayList<Character> commands = new ArrayList<>();\n\n      for (int i = 0; i < n; i++) {\n        char ch = in.next().charAt(0);\n        commands.add(ch);\n      }\n      for (int a[] : dp) Arrays.fill(a, -1);\n\n      out.println(count(0, commands, 0));\n\n    }\n\n    public int count(int index, ArrayList<Character> commands, int deepCount) {\n      if (deepCount < 0) {\n        return 0;\n      }\n      if (index == commands.size()) {\n        return 1;\n      } else {\n\n        if (dp[index][deepCount] != -1) return dp[index][deepCount];\n        long result = 0;\n        char ch = commands.get(index);\n        result = count(index, commands, deepCount - 1);\n        if (ch == 's') {\n          result += count(index + 1, commands, deepCount);\n        } else {\n          result += count(index + 1, commands, deepCount + 1);\n          result -= count(index + 1, commands, deepCount);\n        }\n        if (result >= MOD) {\n          result -= MOD;\n        }\n        if (result < 0) {\n          result += MOD;\n        }\n        return dp[index][deepCount] = (int) result;\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 String readString() {\n      int c = read();\n      while (isSpaceChar(c)) {\n        c = read();\n      }\n      StringBuilder res = new StringBuilder();\n      do {\n        if (Character.isValidCodePoint(c)) {\n          res.appendCodePoint(c);\n        }\n        c = read();\n      } while (!isSpaceChar(c));\n      return res.toString();\n    }\n\n    public boolean isSpaceChar(int c) {\n      if (filter != null) {\n        return filter.isSpaceChar(c);\n      }\n      return isWhitespace(c);\n    }\n\n    public static boolean isWhitespace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public String next() {\n      return readString();\n    }\n\n    public int nextInt() {\n      return readInt();\n    }\n\n    public interface SpaceCharFilter {\n      public boolean isSpaceChar(int ch);\n\n    }\n\n  }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    BufferedReader br;\n    PrintWriter pw;\n    StringTokenizer st;\n    long mod = (long) (1e9 + 7);\n\n    public static void main(String[] args) {\n        (new Main()).run();\n    }\n\n    void solve() throws IOException {\n        int n = nextInt();\n        boolean p[] = new boolean[n];\n        for (int i = 0; i < n; i++) {\n            String s = nextToken();\n            if (s.charAt(0) == 'f') p[i] = true;\n        }\n        long d[][] = new long[n][n];\n        d[0][0] = 1;\n        for (int i = 1; i < n; i++) {\n            if (p[i - 1]) {\n                d[i][0] = 0;\n                for (int j = 1; j < n; j++) {\n                    d[i][j] = d[i - 1][j - 1];\n                }\n            } else {\n                long sum = 0;\n                for (int j = n - 1; j >= 0; j--) {\n                    sum += d[i - 1][j];\n                    sum %= mod;\n                    d[i][j] = sum;\n                }\n            }\n        }\n        long sum = 0;\n        for (int i = 0; i < n; i++) {\n            sum += d[n - 1][i];\n            sum %= mod;\n        }\n        pw.print(sum);\n    }\n\n    void run() {\n        try {\n//            br = new BufferedReader(new FileReader(\"divljak.in\"));\n//            pw = new PrintWriter(new BufferedWriter(new FileWriter(\"divljak.out\")));\n//            br = new BufferedReader(new FileReader(\"input.txt\"));\n//            pw = new PrintWriter(new FileWriter(\"output.txt\"));\n            br = new BufferedReader(new InputStreamReader(System.in));\n            pw = new PrintWriter(new OutputStreamWriter(System.out));\n\n            solve();\n            pw.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\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    int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    class h {\n        int ans;\n        int last;\n\n        public h() {\n            last = -1;\n            ans = 0;\n        }\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class CFC {\n\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n    final long MOD = 1000L * 1000L * 1000L + 7;\n    int[] dx = {0, -1, 0, 1};\n    int[] dy = {1, 0, -1, 0};\n\n    void solve() throws IOException {\n        int n = nextInt();\n        long[] dp0 = new long[10 + n];\n        long[] dp1 = new long[10 + n];\n        long[] pre = new long[10 + n];\n        dp0[0] = 1;\n        String[] arr = new String[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = nextString();\n        }\n        String s = \"s\";\n        for (int i = 0; i < n; i++) {\n            Arrays.fill(dp1, 0);\n\n            if (i == 0) {\n                dp0[0] = 1;\n                dp1[0] = 1;\n            }\n            else {\n                if (arr[i - 1].equals(s)) {\n                    for (int j = 0; j <= n + 5; j++) {\n                        dp1[j] = pre[j];\n                    }\n                }\n                else {\n                    for (int j = 1; j <= n + 5; j++) {\n                        dp1[j] = dp0[j - 1];\n                    }\n                }\n            }\n\n            Arrays.fill(pre, 0);\n            pre[n + 5] = dp1[n + 5];\n            for (int j = n + 4; j >= 0; j--) {\n                pre[j] = pre[j + 1] + dp1[j];\n                pre[j] %= MOD;\n            }\n\n            for (int j = 0; j <= n + 5; j++) {\n                dp0[j] = dp1[j];\n            }\n        }\n\n        long res = 0;\n        for (int j = 0; j <= n + 5; j++) {\n            res += dp0[j];\n            res %= MOD;\n        }\n\n        out(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    public CFC() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        solve();\n        out.close();\n    }\n    public static void main(String[] args) throws IOException {\n        new CFC();\n    }\n\n    public long[] nextLongArr(int n) throws IOException{\n        long[] res = new long[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextLong();\n        return res;\n    }\n    public int[] nextIntArr(int n) throws IOException {\n        int[] res = new int[n];\n        for(int i = 0; i < n; i++)\n            res[i] = nextInt();\n        return res;\n    }\n    public String nextToken() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                eof = true;\n                return null;\n            }\n        }\n        return st.nextToken();\n    }\n    public String nextString() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            eof = true;\n            return null;\n        }\n    }\n    public int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n    public long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n    public double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\n\tstatic ArrayList<Integer> statements;\n\tstatic final int MOD = (int) 1e9 + 7;\n\n\tstatic int[][] memo;\n\n\tstatic int solve(int i, int c) {\n\t\tif(i == statements.size())\n\t\t\treturn 1;\n\t\tif(memo[i][c] != -1)\n\t\t\treturn memo[i][c];\n\n\t\tlong ans = solve(i + 1, c + statements.get(i));\n\t\tif(c > 0)\n\t\t\tans += solve(i, c - 1);\n\t\treturn memo[i][c] = (int) (ans % MOD);\n\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\n\t\tint n = sc.nextInt();\n\t\tstatements = new ArrayList<>();\n\n\t\tchar[] c = new char[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tc[i] = sc.next().charAt(0);\n\t\t}\n\n\t\tif(c[0] == 's')\n\t\t\tstatements.add(0);\n\t\telse\n\t\t\tstatements.add(1);\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif(c[i - 1] == 'f') {\n\t\t\t\tif(c[i] == 'f')\n\t\t\t\t\tstatements.set(statements.size() - 1, statements.get(statements.size() - 1) + 1);\n\t\t\t}else {\n\n\t\t\t\tif(c[i] == 's')\n\t\t\t\t\tstatements.add(0);\n\t\t\t\telse\n\t\t\t\t\tstatements.add(1);\n\t\t\t}\n\t\t}\n\n\n\t\tmemo = new int[statements.size()][n + 1];\n\n\t\tfor(int[] a : memo)\n\t\t\tArrays.fill(a, -1);\n\t\tout.println(solve(0, 0));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String file) throws FileNotFoundException {\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 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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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.io.File;\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 ShekharN\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        private final int MOD = (int) (1e9 + 7);\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            String[] arr = new String[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = in.nextString();\n            }\n            int[] dp = new int[n];\n            Arrays.parallelSetAll(dp, i -> 0);\n            dp[0] = 1;\n            int cnt = 0;\n            for (int i = 0; i < n; i++) {\n                if (arr[i].equals(\"f\")) {\n                    cnt++;\n                    continue;\n                }\n                calc(dp, n, cnt);\n                cnt = 0;\n            }\n            int sum = 0;\n            for (int i = 0; i < n; i++) {\n                sum += dp[i];\n                sum %= MOD;\n            }\n            out.println(sum);\n        }\n\n        private void calc(int[] dp, int n, int cnt) {\n            for (int i = n - 1; i >= 0; i--) {\n                if (i != n - 1) dp[i] += dp[i + 1];\n                dp[i] %= MOD;\n            }\n            int[] tmp = new int[n];\n            for (int i = 0; i < n; i++) {\n                tmp[(i + cnt) % n] = dp[i];\n            }\n            Arrays.parallelSetAll(dp, i -> tmp[i]);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader br;\n        private 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        public String nextString() {\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        public int nextInt() {\n            return Integer.parseInt(nextString());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 ankur\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        String[] str;\n        long mod = (long) 1e9 + 7;\n        long[][] dp;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            str = new String[n];\n            dp = new long[n + 2][n + 2];\n            for (int i = 0; i < dp.length; i++) {\n                Arrays.fill(dp[i], -1);\n            }\n            for (int i = 0; i < n; i++) {\n                str[i] = in.readString();\n            }\n            if (str[0].charAt(0) == 'f') {\n                out.print(solve(1, 1));\n            } else {\n                out.print(solve(1, 0));\n            }\n        }\n\n        long solve(int n, int horiz) {\n            if (horiz < 0)\n                return 0;\n            if (n >= str.length - 1) {\n                return 1;\n            }\n            if (dp[n][horiz] != -1) {\n                return dp[n][horiz];\n            }\n            if (str[n].charAt(0) == 'f') {\n                return dp[n][horiz] = solve(n + 1, horiz + 1);\n            } else {\n                long ans1 = solve(n, horiz - 1);\n                //System.out.println(ans1+\" \"+n+\" egsvd\"+horiz);\n                ans1 += solve(n + 1, horiz);\n                //System.out.println(ans1+\" \"+n+\" \"+horiz);\n                ans1 = ans1 % mod;\n                return dp[n][horiz] = ans1;\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            //*-*------clare------\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            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 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 boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 ZYCSwing\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 static final int MOD = (int) 1e9 + 7;\n        private static final int N = 5000;\n\n        public void solve(int testNumber, Scanner in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] dp = new int[N];\n            Arrays.fill(dp, 0);\n            dp[0] = 1;\n            String pre = null, ch;\n            for (int i = 0; i < n; ++i) {\n                ch = in.next();\n                if (i > 0) {\n                    if (pre.equals(\"s\")) {\n                        int j = N - 1;\n                        while (dp[j] == 0) {\n                            --j;\n                        }\n                        long sum = 0;\n                        for (; j >= 0; --j) {\n                            sum += dp[j];\n                            sum %= MOD;\n                            dp[j] = (int) sum;\n                        }\n                    } else {\n                        for (int k = N - 1; k > 0; --k) {\n                            dp[k] = dp[k - 1];\n                        }\n                        dp[0] = 0;\n                    }\n                }\n                pre = ch;\n            }\n\n            long sum = 0;\n            for (int i = 0; i < N; ++i) {\n                sum += dp[i];\n                sum %= MOD;\n            }\n            out.println(sum);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class p3sol{\n\n\tstatic char[] c;\n\tstatic int[][] dp;\n\tstatic int mod = (int)1e9 + 7;\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tc = new char[n];\n\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tc[i] = br.readLine().charAt(0);\n\n\t\tdp = new int[n + 1][n + 1];\n\n\t\tdp[0][0] = 1;\n\n\t\tfor(int i = 0; i < n - 1; i++){\n\t\t\tif(c[i] == 's'){\n\t\t\t\tint prev = 0;\n\t\t\t\tfor(int j = i; j >= 0; j--){\n\t\t\t\t\tprev += dp[i][j];\n\t\t\t\t\tprev %= mod;\n\t\t\t\t\tdp[i + 1][j] += prev;\n\t\t\t\t\tdp[i + 1][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tfor(int j = 1; j <= n; j++){\n\t\t\t\t\tdp[i + 1][j] += dp[i][j - 1];\n\t\t\t\t\tdp[i + 1][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tans += dp[n - 1][i];\n\t\t\tans %= mod;\n\t\t}\n\n\t\t// print(dp);\n\n\t\tSystem.out.println(ans);\n\t\t\n\t\tbr.close();\n\t}\n\n\tpublic static void print(int[][] a){\n\t\tfor(int i = 0; i < a.length; i++){\n\t\t\tfor(int j = 0; j < a[0].length; j++)\n\t\t\t\tSystem.out.print(a[i][j] + \" \");\n\t\t\tSystem.out.println(\"\");\n\t\t}\n\t}\n\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        int mod = 1000000007;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.readInt();\n            int[][] dp = new int[n + 1][5002];\n            char[] a = new char[n];\n            for (int i = 0; i < n; i++) a[i] = in.readCharacter();\n\n            for (int i = 0; i < dp[n].length; i++) dp[n][i] = 1;\n\n            for (int i = n - 1; i >= 0; i--) {\n                for (int j = 0; j < n; j++) {\n                    if (a[i] == 's') {\n                        if (j > 0) dp[i][j] = dp[i][j - 1];\n                        dp[i][j] = (int) ((dp[i][j] + (long) dp[i + 1][j]) % mod);\n                    } else {\n                        if (j > 0) dp[i][j] = dp[i][j - 1];\n                        dp[i][j] = (int) ((dp[i][j] + (long) dp[i + 1][j + 1] - (long) dp[i + 1][j] + mod) % mod);\n                    }\n                }\n            }\n            out.println(dp[0][0]);\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 char readCharacter() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            return (char) c;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class GFG {\n    static int count=0;\n    \n\tpublic static void main (String[] args) {\n\t\tScanner ob=new Scanner(System.in);\n\t\tint n;\n\t\tlong MOD=(long)(1e9+7);\n\t\tint f=0,s=0;\n\t\tn=ob.nextInt();\n\t\tlong dp[][]=new long[n+2][n+2];\n\t\tdp[0][1]=1;\n\t\tchar ch='s';\n\t\tchar p;\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t    p=ch;\n\t\t    ch=ob.next().charAt(0);\n\t\t    if(p=='f')\n\t\t    {\n\t\t        for(int j=1;j<=n;j++)\n\t\t        dp[i][j+1]=dp[i-1][j];\n\t\t    }\n\t\t    else\n\t\t    {\n\t\t        for(int j=n;j>0;j--)\n\t\t        {\n\t\t            dp[i][j]=(dp[i][j+1]+dp[i-1][j])%MOD;\n\t\t        }\n\t\t    }\n\t\t}\n\t\t\n\t\tlong ans=0;\n\t\t\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t    ans=(ans+dp[n][i])%MOD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class TaskC {\n\t\n\tpublic static void main(String[] args) {\n\t\tnew TaskC().run();\n\t}\n\t\n\tvoid solve(){\n\t\tint n = in.nextInt();\n\t\tString s[] = new String[n];\n\t\tfor(int i = 0; i < n; i++) s[i] = in.next();\n\t\tif(s[n-1].compareTo(\"f\") == 0){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint dp[] = new int[n+2];\n\t\tint mod = 1000*1000*1000+7;\n\t\tdp[0] = 1;\n\t\tfor(int i = n-1; i >= 0; i--){\t\n\t\t\tif(s[i].compareTo(\"s\") == 0){\n\t\t\t\tint ss = 0;\n\t\t\t\tfor(int j = 0; j <= n; j++){\n\t\t\t\t\tss += dp[j];\n\t\t\t\t\tif(ss>=mod) ss -= mod;\n\t\t\t\t\tdp[j] = ss;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tfor(int j = 0; j < n;j++){\n\t\t\t\t\tdp[j] = dp[j+1];\n\t\t\t\t}\n\t\t\t\tdp[n] = 0;\n\t\t\t}\n\t\t}\n\t\tout.println(dp[0]);\n\t}\n\n\t\n\tFastScanner in;\n\tPrintWriter out;\n\tvoid run() {\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tint tests = 1;//in.nextInt();\n\t\twhile(tests > 0){\n\t\t\tsolve();\n\t\t\ttests--;\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tclass Pair implements Comparable<Pair>{\n\t\tInteger x, y;\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@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(x.compareTo(o.x) == 0) return y.compareTo(o.y);\n\t\t\treturn x.compareTo(o.x);\n\t\t}\n\t\t\n\t}\n \n\tclass FastScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader bf;\n \n\t\tpublic FastScanner(InputStream is) {\n\t\t\tbf = new BufferedReader(new InputStreamReader(is));\n\t\t}\n \n\t\tpublic FastScanner(File f){\n\t\t\ttry{\n\t\t\t\tbf = new BufferedReader(new FileReader(f));\n\t\t\t}\n\t\t\tcatch(IOException ex){\n\t\t\t\tex.printStackTrace();\n\t\t\t}\n\t\t}\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(bf.readLine());\n\t\t\t\t}\n\t\t\t\tcatch(Exception ex){\n\t\t\t\t\tex.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\tint[] readArray(int n){\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n \n} \n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.io.IOException;\nimport java.io.InputStream;\n\npublic class Main {\n    public static void main(String[] args) {\n\n        File file = new File(\"in.txt\");\n        File fileOut = new File(\"out.txt\");\n        InputStream inputStream = null;\n        OutputStream outputStream = null;\n        // try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};\n//        try {outputStream= new FileOutputStream(fileOut);} catch (FileNotFoundException ex){return;};\n        inputStream = System.in;\n        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\n}\n\nclass Task {\n\n    private final int mod = 1000000007;\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        Integer n = in.nextInt();\n        List<Character> comm = new ArrayList<>(n);\n        for(int i=0; i<n; i++){\n            comm.add(in.next().charAt(0));\n        }\n\n        long[][] dp = new long[n][n];\n        dp[0][0] = 1;\n        for(int i=1; i<n; i++){\n            Character lastComm = comm.get(i-1);\n            if(lastComm.equals('f')){\n                dp[i][0] = 0;\n                for(int j=1; j<n; j++){\n                    dp[i][j] = dp[i-1][j-1];\n                }\n            }\n            else{\n                Long suffixSum = dp[i-1][n-1];\n                for(int j=n-1; j>=0; j--){\n                    dp[i][j] = suffixSum;\n                    if(j>0) {\n                        suffixSum += dp[i - 1][j - 1] % mod;\n                    }\n                }\n            }\n        }\n\n        Long finalSum = 0L;\n        for(int i=0; i<n; i++){\n            finalSum += dp[n-1][i] % mod;\n        }\n        out.println(finalSum % mod);\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<F, S> {\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<Integer, Integer>{\n    public IntPair(Integer first, Integer second){\n        super(first, second);\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        TaskC.InputReader in = new TaskC.InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.Solve(in, out);\n        out.close();\n    }\n\n\n    static class TaskC {\n\n        private long mod = 1_000_000_007;\n        private int n;\n        private boolean[] s;\n\n        public void Solve(InputReader in, PrintWriter out) {\n            n = in.NextInt();\n            s = new boolean[n];\n            for (int i = 0; i < n; i++) {\n                String ss = in.Next();\n                s[i] = ss.charAt(0) == 'f';\n            }\n            if (s[n - 1]) {\n                out.println(0);\n                return;\n            }\n            long[] dpSum = new long[n + 1], lastDpSum = new long[n + 1];\n            for (int i = 0; i <= n; i++) {\n                lastDpSum[i] = i + 1;\n            }\n            for (int i = n - 2; i >= 0; i--) {\n                for (int j = 0; j <= i; j++) {\n                    if (!s[i]) {\n                        dpSum[j] = lastDpSum[j];\n                    } else {\n                        dpSum[j] = lastDpSum[j + 1] - lastDpSum[j];\n                    }\n                    if (j != 0) {\n                        dpSum[j] += dpSum[j - 1];\n                    }\n                    dpSum[j] %= mod;\n                    while (dpSum[j] < 0) dpSum[j] += mod;\n\n                }\n                long[] temp = dpSum;\n                dpSum = lastDpSum;\n                lastDpSum = temp;\n            }\n            out.println(lastDpSum[0]);\n        }\n\n        public static int GetMax(int[] ar) {\n            int max = Integer.MIN_VALUE;\n            for (int a : ar) {\n                max = Math.max(max, a);\n            }\n            return max;\n        }\n\n        public static int GetMin(int[] ar) {\n            int min = Integer.MAX_VALUE;\n            for (int a : ar) {\n                min = Math.min(min, a);\n            }\n            return min;\n        }\n\n        public static long GetSum(int[] ar) {\n            long s = 0;\n            for (int a : ar) s += a;\n            return s;\n        }\n\n        public static int[] GetCount(int[] ar) {\n            return GetCount(ar, GetMax(ar));\n        }\n\n        public static int[] GetCount(int[] ar, int maxValue) {\n            int[] dp = new int[maxValue + 1];\n            for (int a : ar) {\n                dp[a]++;\n            }\n            return dp;\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(), \" \\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            public double NextDouble() {\n                return Double.parseDouble(Next());\n            }\n\n            public int[] NextIntArray(int n) {\n                return NextIntArray(n, 0);\n            }\n\n            public int[] NextIntArray(int n, int offset) {\n                int[] a = new int[n];\n                for (int i = 0; i < n; i++) {\n                    a[i] = NextInt() - offset;\n                }\n                return a;\n            }\n\n            public int[][] NextIntMatrix(int n, int m) {\n                return NextIntMatrix(n, m, 0);\n            }\n\n            public int[][] NextIntMatrix(int n, int m, int offset) {\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] = NextInt() - offset;\n                    }\n                }\n                return a;\n            }\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\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 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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            long MOD = 1000000007;\n\n            long[] current = new long[n + 3];\n            //long[] sum = new long[n + 3];\n            current[0] = 1;\n\n            for (int i = 0; i < n - 1; i++) {\n\n                String s = in.next();\n                if (s.equals(\"f\")) {\n                    for (int j = i + 1; j > 0; j--) {\n                        current[j] = current[j - 1];\n                        current[j] %= MOD;\n                    }\n                    current[0] = 0;\n                } else {\n                    for (int j = i + 1; j >= 0; j--) {\n                        //sum[j] = sum[j + 1] + current[j];\n                        current[j] = current[j + 1] + current[j];\n                        current[j] %= MOD;\n                    }\n                    //for (int j = 0; j <= i + 1; j++) {\n                    //  current[j] =\n                    //}\n                }\n            }\n            long result = 0;\n            for (int i = 0; i <= n; i++) {\n                result += current[i];\n                result %= MOD;\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 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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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\n\n/*\n\n */\npublic class C455 {\n\tstatic int N;\n\tstatic final int mod = 1_000_000_007;\n\tstatic int[][] memo;\n\tstatic int[] list;\n\tpublic static void main(String[] args) {\n\t\tFS scan = new FS(System.in);\n\t\t\n\t\tN = scan.nextInt();\n\t\tlist = new int[N];\n\t\tfor(int i=0;i<N;i++) {\n\t\t\tlist[i] = scan.next().equals(\"s\")?0:1;\n\t\t}\n\t\tif(list[N-1] == 1) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tmemo = new int[N+1][N+2];\n\t\tArrays.fill(memo[N], 1);\n\t\tint[] sum = new int[N+2];\n\t\t\n\t\tfor(int i=N-1;i>=0;i--) {\n\t\t\tsum[0] = memo[i+1][0];\n\t\t\tfor(int j=1;j<sum.length;j++) {\n\t\t\t\tsum[j] = sum[j-1] + memo[i+1][j];\n\t\t\t\tsum[j] %= mod;\n\t\t\t}\n\t\t\tfor(int j=0;j<=N;j++) {\n\t\t\t\tif (list[i]==1 && (i==0 || list[i-1]==1))\n\t\t\t\t\tmemo[i][j] = memo[i+1][j+1];\n\t\t\t\telse if(i==0 || list[i-1] == 1)\n\t\t\t\t\tmemo[i][j] = memo[i+1][j];\n\t\t\t\telse if (list[i]==1){\n//\t\t\t\t\tfor(int k=0;k<=j;k++) {\n//\t\t\t\t\t\tmemo[i][j] += memo[i+1][k+1];\n//\t\t\t\t\t}\n\t\t\t\t\tmemo[i][j] = sum[j+1] - sum[0] + mod;\n\t\t\t\t\tmemo[i][j] %= mod;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse if (list[i]==0) {\n\t\t\t\t\tmemo[i][j] = sum[j];\n\t\t\t\t}\n\t\t\t}\n\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\tSystem.out.print(memo[i][j]+\" \");\n//\t\t\t}\n//\t\t\tSystem.out.println();\n//\t\t}\n//\t\tSystem.out.println();\n\t\tSystem.out.println(memo[0][0]);\n\t}\n\t\n\tprivate static class FS {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS(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{st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(IOException e){e.printStackTrace();}\n\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}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n    private static final int MAX = 5000 + 10,mod = 1000000007;\n    private static char [] S;\n    private static int n;\n    private static Integer [] [] dp = new Integer[MAX][MAX];\n\n    private static int solve(int pos,int open){\n        if(pos == n) return (open == 0) ? 1 : 0;\n        if (dp[pos][open] != null) return dp[pos][open];\n        int res = 0;\n        if (S[pos] == 's') {\n            res = solve(pos + 1,open);\n            if (open > 0) res += solve(pos,open - 1);\n            if (res >= mod) res -= mod;\n        }\n        else {\n            res = solve(pos+1,open + 1);\n        }\n        return dp[pos][open] = res;\n    }\n\n    public static void main(String[] args) throws Exception{\n        IO io = new IO(null,null);\n        n = io.getNextInt();\n        S = new char[n];\n        for (int i = 0;i < n;i++) S[i] = io.getNext().charAt(0);\n        io.println(solve(0,0));\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}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\n/**\n * Created by Jarek on 2017-12-30.\n */\npublic class PhytonIndenter {\n\n    private static Scanner scanner = new Scanner(System.in);\n\n    private static int lineCount;\n    private static String[] commands;\n\n    public static void main(String args[]) {\n        lineCount = scanner.nextInt();\n        scanner.nextLine();\n        commands = new String[lineCount];\n\n        for (int i = 0; i < lineCount; i++) {\n            commands[i] = scanner.nextLine();\n        }\n\n        resolveWithDP();\n    }\n\n    private static void resolveWithDP() {\n        long dp[][] = new long[lineCount][5002];\n        long mod = 1000000007;\n        dp[0][0] = 1;\n        for (int i = 1; i < lineCount; i++) {\n            if (\"f\".equalsIgnoreCase(commands[i - 1])) {\n                dp[i][0] = 0;\n                for (int j = 1; j <= i; j++) {\n                    dp[i][j] = dp[i - 1][j - 1];\n                }\n            } else {\n                long sum = 0;\n                for (int j = i - 1; j >= 0; j--) {\n                    sum += dp[i - 1][j] % mod;\n                    dp[i][j] = sum;\n                }\n            }\n        }\n\n        long result = 0;\n        for (int i = 0; i < lineCount; i++) {\n            result += dp[lineCount-1][i]%mod;\n            result %= mod;\n        }\n        System.out.println(result%mod);\n    }\n\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n/* spar5h */\n\npublic class codeforces implements Runnable { \n\t \n\tfinal static long mod = (long)1e9 + 7;\n\t\n\tpublic void run() {\n\t\t\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\n\t\tint n = s.nextInt();\n\t\t\n\t\tchar[] c = new char[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tc[i] = s.next().charAt(0);\n\t\t\n\t\t//index + depth/indentation\n\t\tlong[][] dp = new long[n][n];\n\t\tdp[0][0] = 1;\n\t\t\n\t\tfor(int i = 0; i < n - 1; i++) {\n\t\t\t\n\t\t\t//c[i] = f implies that indentation will always be increased by one in i + 1\n\t\t\tif(c[i] == 'f') {\n\t\t\t\t\n\t\t\t\tfor(int j = 1; j < n; j++)\n\t\t\t\t\tdp[i + 1][j] = dp[i][j - 1];\n\t\t\t}\n\t\t\t\n\t\t\t//c[i] = s implies that value of i + 1 can include any previous value of equal or higher indentation\n\t\t\telse {\n\t\t\t\t\n\t\t\t\tdp[i + 1][n - 1] = dp[i][n - 1]; \n\t\t\t\t\n\t\t\t\tfor(int j = n - 2; j >= 0; j--)\n\t\t\t\t\tdp[i + 1][j] = (dp[i + 1][j + 1] + dp[i][j]) % mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong res = 0;\n\t\t\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tres = (res + dp[n - 1][i]) % mod;\n\t\t\n\t\tw.println(res);\n\t\t\n\t\tw.close();\n\t}\n\t\n\t\n\tstatic class InputReader\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n            try\n            {\n                str = br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n    \n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new codeforces(),\"codeforces\",1<<26).start();\n\t}\n\t   \n} ", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        static final long MODULO = (long) (1e9 + 7);\n\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            long[][] dp = new long[n + 100][n + 100];\n            dp[0][0] = 1;\n            for (int i = 0; i < n; ++i) {\n                char current = in.nextCharacter();\n                if (current == 'f') {\n                    for (int j = 0; j < n; ++j) {\n                        dp[i + 1][j + 1] += dp[i][j];\n                        dp[i + 1][j + 1] %= MODULO;\n                    }\n                } else {\n                    long runningSum = 0;\n                    for (int j = n; j >= 0; --j) {\n                        runningSum += dp[i][j];\n                        runningSum %= MODULO;\n\n                        dp[i + 1][j] += runningSum;\n                        dp[i + 1][j] %= MODULO;\n                    }\n                }\n            }\n            out.println(dp[n][0]);\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public char nextCharacter() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            return (char) c;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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.util.Collections;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\npublic class C909 {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int ar[] = new int[n+1];\n            int count = 1;\n            ar[0] = 1;\n            for(int i=0;i<n;i++){\n                char c = in.next().charAt(0);\n                if(c == 'f')\n                    count++;\n                else{\n                    for(int j=1;j<count;j++){\n                        ar[j] = (ar[j] + ar[j-1])% (int)(1e9+7);\n                    }\n                }    \n            }\n            out.println(ar[count-1]);\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        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public String nextLine() {\n            String str = \"\";\n            try\n            {\n                str = reader.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) {\n\n        solve(System.in,System.out);\n\n    }\n\n    static void solve(InputStream inStream, PrintStream printStream) {\n        Scanner in = new Scanner(inStream);\n        int n = in.nextInt();\n        long[] sums = new long[n];\n        for (int i = 1; i < n; i++) {\n            sums[i]=0;\n        }\n        sums[0]=1;\n\n        long mod = 1000000007;\n\n        for (int i = 0; i < n; i++) {\n            if (in.next().equals(\"f\") ) {\n                for (int j = n-1; j > 0 ; j--) {\n                    sums[j]=sums[j-1];\n                }\n                sums[0]=0;\n            } else {\n                for (int j = n-2; j >= 0 ; j--) {\n                    sums[j] += sums[j+1];\n                    if (sums[j]>=mod) {\n                        sums[j]-=mod;\n                    }\n                }\n            }\n        }\n\n//        long finalSum = 0;\n//        for (int i = 0; i < n; i++) {\n//            finalSum+=sums[i];\n//        }\n\n        printStream.println(sums[0]);\n\n    }\n\n\n\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C {\n  \n  static InputReader in = new InputReader(System.in);\n  static PrintWriter out = new PrintWriter(System.out);\n  \n  public static void main(String[] args) {\n    int n = in.nextInt();\n    int[] sol = new int[n];\n    sol[0] = 1;\n    int mod = 1000000007;\n    int maxind = 0;\n    boolean f = true;\n    for (int i = 0; i < n; i++) {\n      if (!f) {\n        //int accum = sol[0];\n        for (int j = 1; j <= maxind; j++) {\n          sol[j] += sol[j-1];\n          sol[j] %= mod;\n        }\n        //out.println(Arrays.toString(sol));\n      }\n      if (in.next().equals(\"f\")) {\n        maxind++;\n        f = true;\n      }\n      else {\n        f = false;\n      }\n    }\n    int ans = 0;\n    for (int i = 0; i <= maxind; i++) {\n      ans += sol[i];\n      ans %= mod;\n    }\n    out.println(ans);\n    finish();\n  }\n  \n  public static void finish() {\n    out.close();\n    in.close();\n    System.exit(0);\n  }\n\n  static class InputReader implements Iterator<String>, Closeable {\n    // Fast input reader. Based on Kattio.java from open.kattis.com\n    // but has method names to match Scanner\n\n    private BufferedReader r;\n    private String line;\n    private StringTokenizer st;\n    private String token;\n\n    public InputReader(InputStream i) {\n      r = new BufferedReader(new InputStreamReader(i));\n    }\n\n    public boolean hasNext() {\n      return peekToken() != null;\n    }\n\n    public int nextInt() {\n      return Integer.parseInt(nextToken());\n    }\n\n    public double nextDouble() {\n      return Double.parseDouble(nextToken());\n    }\n\n    public long nextLong() {\n      return Long.parseLong(nextToken());\n    }\n\n    public String next() {\n      return nextToken();\n    }\n    \n    public String nextLine() {\n      try {\n        line = r.readLine();\n      } catch (IOException e) {\n        line = null;\n      }\n      token = null;\n      st = null;\n      return line;\n    }\n    \n    public void close() {\n      try {\n        r.close();\n      } catch (IOException e) {\n      }\n    }\n\n    private String peekToken() {\n      if (token == null)\n        try {\n          while (st == null || !st.hasMoreTokens()) {\n            line = r.readLine();\n            if (line == null)\n              return null;\n            st = new StringTokenizer(line);\n          }\n          token = st.nextToken();\n        } catch (IOException e) {\n        }\n      return token;\n    }\n\n    private String nextToken() {\n      String ans = peekToken();\n      token = null;\n      return ans;\n    }\n    \n  }\n\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\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 EndUser\n */\npublic class R455D2PC {\n\n    public static void main(String[] args) {\n        final int MAX = 5000;\n        final int MODULO = 1000000007;\n\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        in.nextLine();\n\n        int pre = 0;\n        int size = 0;\n\n        int[] block = new int[MAX];\n        for (int i = 0; i < n; i++) {\n            String command = in.nextLine();\n            if (command.startsWith(\"s\")) {\n                block[size++] = pre;\n                pre = 0;\n            } else {\n                pre++;\n            }\n        }\n\n        if (pre != 0) {\n            System.out.println(0);\n            return;\n        }\n\n        int[][] result = new int[2][MAX + 1];\n        int currentMax = 0;\n        int preIndex = 0;\n        result[preIndex][0] = 1;\n        for (int i = 1; i < size; i++) {\n            int currentIndex = preIndex ^ 1;\n            int j = block[i - 1];\n            for (int k = currentMax; k >= 0; k--) {\n                result[currentIndex][k + j] = (result[currentIndex][k + j + 1] + result[preIndex][k]) % MODULO;\n            }\n            for (int k = j - 1; k >= 0; k--) {\n                result[currentIndex][k] = result[currentIndex][j];\n\n            }\n            currentMax += j;\n            preIndex = currentIndex;\n//            for (int k = 0; k <= currentMax; k++) {\n//                System.out.print(result[preIndex][k] + \" \");\n//                \n//            }\n//            System.out.println(\"\");\n        }\n\n        int sum = 0;\n        for (int i = 0; i <= currentMax; i++) {\n            sum = (sum + result[preIndex][i]) % MODULO;\n        }\n        \n        System.out.println(sum);\n    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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\npublic class C {\n\tstatic int [][] memo;\n\tstatic int n;\n\tstatic char [] c;\n\tstatic int mod = (int)1e9+7;\n\tstatic int dp(int ind, int loops){\n\t\tif(ind == n)\n\t\t\treturn loops == 0?1:0;\n\t\tif(memo[ind][loops] != -1)\n\t\t\treturn memo[ind][loops];\n\t\tlong ans = 0;\n\t\tif(c[ind] == 's'){\n\t\t\tans = (ans + dp(ind+1, loops))%mod;\n\t\t\tif(loops > 0)\n\t\t\t\tans = (ans + dp(ind, loops-1))%mod;\n\t\t}\n\t\telse{\n\t\t\tans = (ans + dp(ind+1, loops+1))%mod;\n\t\t}\n\t\treturn memo[ind][loops] = (int) ans;\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tmemo = new int[n+1][n+1];\n\t\tfor(int [] i:memo)\n\t\t\tArrays.fill(i, -1);\n\t\tc = new char[n];\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tc[i] = sc.next().charAt(0);\n\t\t}\n\t\tout.println(dp(0,0));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader bf;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner(InputStream i) {\n\t\t\tbf = new BufferedReader(new InputStreamReader(i));\n\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(bf.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\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 long nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.concurrent.*;\n\npublic final class py_indent\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 int maxn=(int)(5e3+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    public static void main(String args[]) throws Exception\n    {\n\t\tint n=sc.nextInt();char[] a=new char[n+1];a[0]='s';\n\t\t\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\ta[i]=sc.next().charAt(0);\n\t\t}\n\t\t\n\t\tint[][] dp=new int[n+1][maxn],sum=new int[n+1][maxn];dp[0][0]=1;\n\t\t\n\t\tsum[0][0]=1;\n\t\t\n\t\tfor(int i=1;i<maxn;i++)\n\t\t{\n\t\t\tsum[0][i]=add(sum[0][i],sum[0][i-1]);\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tif(a[i]=='f')\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tint curr=0,idx=0;\n\t\t\t\n\t\t\tfor(int j=i-1;j>=0;j--)\n\t\t\t{\n\t\t\t\tif(a[j]=='s')\n\t\t\t\t{\n\t\t\t\t\tidx=j;break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcurr++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j=0;j<maxn;j++)\n\t\t\t{\n\t\t\t\tint up=Math.max(0,j-curr);\n\t\t\t\t\t\n\t\t\t\tlong now=(sum[idx][maxn-1]-(up==0?0:sum[idx][up-1]));\n\t\t\t\t\t\t\t  \n\t\t\t\tnow=add(now,mod);\n\t\t\t\t\t\n\t\t\t\tdp[i][j]=add(dp[i][j],now);\n\t\t\t}\n\t\t\t\n\t\t\tsum[i][0]=dp[i][0];\n\t\t\t\n\t\t\tfor(int j=1;j<maxn;j++)\n\t\t\t{\n\t\t\t\tsum[i][j]=add(dp[i][j],sum[i][j-1]);\n\t\t\t}\n\t\t}\n\t\t\n\t\t//out.println(dp[2][0]+\" \"+dp[2][1]+\" \"+dp[2][2]);\n\t\t\n\t\tout.println(dp[n][0]);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}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "//package round455;\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 C {\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 = 1000000007;\n\t\tlong[] dp = new long[5005];\n\t\tdp[0] = 1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tchar c = nc();\n\t\t\tif(c == 's'){\n\t\t\t\tif(i < n-1){\n\t\t\t\t\tfor(int j = 5003;j >= 0;j--){\n\t\t\t\t\t\tdp[j] += dp[j+1];\n\t\t\t\t\t\tif(dp[j] >= mod)dp[j] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tfor(int j = 5003;j >= 0;j--){\n\t\t\t\t\tdp[j+1] = dp[j];\n\t\t\t\t}\n\t\t\t\tdp[0] = 0;\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = 0;i < 5005;i++)ans += dp[i];\n\t\tout.println(ans % 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 C().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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class C {\n\t\n\tpublic static void main(String[] args){\n\t\ttry(Scanner sc = new Scanner(System.in)){\n\t\t\tfinal int N = sc.nextInt();\n\t\t\t\n\t\t\tString[] ins = new String[N];\n\t\t\tfor(int i = 0; i < N; i++){\n\t\t\t\tins[i] = sc.next();\n\t\t\t}\n\t\t\t\n\t\t\tfinal long MOD = 1000000007;\n\t\t\tlong[] DP = new long[N];\n\t\t\tlong[] nextDP = new long[N];\n\t\t\t\n\t\t\tDP[0] = 1;\n\t\t\t\n\t\t\tfor(int i = 1; i < N; i++){\n\t\t\t\tArrays.fill(nextDP, 0);\n\t\t\t\tif(\"f\".equals(ins[i - 1])){\n\t\t\t\t\tfor(int j = 0; j < N - 1; j++){\n\t\t\t\t\t\tnextDP[j + 1] += DP[j];\n\t\t\t\t\t\tnextDP[j + 1] %= MOD;\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tfor(int j = N - 1; j >= 0; j--){\n\t\t\t\t\t\tnextDP[j] += DP[j];\n\t\t\t\t\t\tnextDP[j] %= MOD;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(j < N - 1){\n\t\t\t\t\t\t\tnextDP[j] += nextDP[j + 1];\n\t\t\t\t\t\t\tnextDP[j] %= MOD;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp = DP;\n\t\t\t\t\tDP = nextDP;\n\t\t\t\t\tnextDP = tmp;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlong answer = 0;\n\t\t\tfor(int i = 0; i < N; i++){\n\t\t\t\tanswer += DP[i];\n\t\t\t\tanswer %= MOD;\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\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.* ;\nimport java.io.* ;\n\npublic class PythonIndentation\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in) ;\n\t\tint n = in.nextInt() ;\n\t\tboolean[] lst = new boolean[n] ;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlst[i] = (in.next().equals(\"s\"))?false:true ;\n\t\t}\n\t\tSystem.out.println(dp(lst)) ;\n\t}\n\tstatic void  arrayPrinter(int[][] dp)\n\t{\n\t\tSystem.out.println(\":::\") ;\n\t\tfor(int i=0;i<dp.length;i++)\n\t\t{\n\t\t\tfor(int j=0;j<dp[0].length;j++)\n\t\t\t{\n\t\t\t\tSystem.out.print(dp[i][j]+\" \") ;\n\t\t\t}\n\t\t\tSystem.out.println() ;\n\t\t}\n\t}\n\tstatic int dp(boolean[] lst)\n\t{//false in lst means an \"s\" (simple statement), and true a \"f\"(for loop)\n\t\tint[][] dp = new int[2][lst.length] ;\n\t\tdp[0][0] = 1 ;\n\t\tfor(int i=1;i<lst.length;i++)\n\t\t{\n\t\t\t// arrayPrinter(dp) ;\n\t\t\tfor(int j=0;j<lst.length;j++)\n\t\t\t{\n\t\t\t\tif(lst[i-1])//(i-1)st statement is a for loop \n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t\tdp[i%2][j] = 0 ;\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i%2][j] = dp[(i-1)%2][j-1] ;\n\t\t\t\t}\n\t\t\t\n\t\t\t\telse//i-1 st statement is a simple statement\n\t\t\t\t{\n\t\t\t\t\tif(j==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint temp = 0 ;\n\t\t\t\t\t\tfor(int k=0;k<lst.length;k++)\n\t\t\t\t\t\t\ttemp = (temp+dp[(i-1)%2][k])%1000000007 ;\n\t\t\t\t\t\tdp[i%2][j] = temp ;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tdp[i%2][j] = (dp[i%2][j-1]-dp[(i-1)%2][j-1])%1000000007 ;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0 ;\n\t\tfor(int i=0;i<lst.length;i++)\n\t\t{\n\t\t\tans = (ans + dp[(lst.length-1)%2][i])%1000000007 ;\n\t\t}\n\t\tif(ans<0)\n\t\t\tans = ans + 1000000007 ;\n\t\t// arrayPrinter(dp) ;\n\t\treturn ans ;\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        long MOD = (long) 1e9 + 7;\n        long[][] dp;\n        int[] a;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int N = in.nextInt();\n            a = new int[N];\n            dp = new long[N][N];\n            int i;\n            for (i = 0; i < N; i++) {\n                char c = in.nextChar();\n                if (c == 'f') {\n                    a[i] = 1;\n                }\n            }\n\n            out.printLine(iterative());\n//        for(i=0;i<=N;i++) {\n//            Arrays.fill(dp[i], -1);\n//        }\n//        out.printLine(recur(0, 0));\n        }\n\n        public long iterative() {\n            int i, j, N = a.length, lastLevel = 0;\n            dp[0][0] = 1;\n            for (i = 1; i < N; i++) {\n                if (a[i - 1] == 1) {\n                    lastLevel++;\n                    for (j = 1; j <= lastLevel; j++) {\n                        dp[i][j] = dp[i - 1][j - 1];\n                    }\n                } else {\n                    dp[i][N - 1] = dp[i - 1][N - 1];\n                    for (j = N - 2; j >= 0; j--) {\n                        dp[i][j] = (dp[i][j + 1] + dp[i - 1][j]) % MOD;\n                    }\n                }\n            }\n            long ans = 0;\n            for (i = 0; i < N; i++) {\n                ans += dp[N - 1][i];\n            }\n            return ans % MOD;\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        public char nextChar() {\n            return next().charAt(0);\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void 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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main {\n\tpublic static void main(String[] args){\n\t\tlong MOD = 1000000007;\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tlong[][]dp = new long[n][5010];\n\t\tchar[] program = new char[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tprogram[i] = sc.next().charAt(0);\n\t\t}\n\t\t\n\t\tdp[0][0] = 1;\n\t\t\n\t\tlong[] acc = new long[5010];\n\t\t\n\t\tacc[0] = 1;\n\t\t\n\t\tfor(int i = 1 ; i < n; i++){\n\t\t\tfor(int j = 0; j< 5010; j++){\n\t\t\t\tif(program[i-1] == 'f'){\n\t\t\t\t\tif(j - 1 >= 0){\n\t\t\t\t\t\tdp[i][j] = dp[i-1][j-1];\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tdp[i][j] = acc[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tacc[5009] = dp[i][5009];\n\t\t\tfor(int j = 5008; j >= 0; j--){\n\t\t\t\tacc[j] = (acc[j + 1] + dp[i][j]) % MOD;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(acc[0]);\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "/*\n * Institute DA-IICT\n */\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class C\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\tvoid solve() \n\t{\n\t\tint n=ni();\n\t\tlong dp[]=new long[n+1];\n\t\t\n\t\tdp[0]=1;\n\t\tfor (int i=0;i<n;)\n\t\t{\n\t\t\ti++;\n\t\t\tif (nc()=='f')\n\t\t\t{\n\t\t\t\t//boolean flag=i==1;\n\t\t\t\ti++;\n\t\t\t\tint k=1;\n\t\t\t\twhile (nc()!='s')\n\t\t\t\t{\n\t\t\t\t\ti++;k++;\n\t\t\t\t}\n\t\t\t\t//long dp1[]=Arrays.copyOf(dp, n+1);\n\t\t\t\tfor (int j=n-1;j>=0;j--)\n\t\t\t\t{\n\t\t\t\t\tdp[j]=add(dp[j],dp[j+1]);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (int j=n;j>=k;j--)\n\t\t\t\t{\n\t\t\t\t\tdp[j]=dp[j-k];\n\t\t\t\t}\n\t\t\t\tfor (int j=0;j<k;j++)\n\t\t\t\t\tdp[j]=0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int j=n-1;j>=0;j--)\n\t\t\t\t{\n\t\t\t\t\tdp[j]=add(dp[j],dp[j+1]);\n\t\t\t\t}\n\t\t\t}\n\t\t\t//tr(dp);\n\t\t}\n\t\tlong sum=0;\n\t\tfor (int i=0;i<=n;i++)\n\t\t\tsum=add(sum,dp[i]);\n\t\tout.println(sum);\n\t}\n\t\n\tclass LazyPropagation\n\t\t{\n\t\t\tlong tree[];\n\t\t\tlong lazy[];\n\t\t\tlong A[];\n\t\t\tpublic LazyPropagation(int n,long arr[]) \n\t\t\t{\n\t\t\t\ttree=new long[4*n];\n\t\t\t\tlazy=new long[4*n];\n\t\t\t\tA=arr;\n\t\t\t\tbuildSum(1,1,n);\n\t\t\t}\n\t\t\t\n\t\t\tpublic LazyPropagation(int n) \n\t\t\t{\n\t\t\t\ttree=new long[4*n];\n\t\t\t\tlazy=new long[4*n];\n\t\t\t}\n\t\t\t\n\t\t\tvoid buildSum(int node,int start,int end)\n\t\t\t{\n\t\t\t\tif (start==end)\n\t\t\t\t{\n\t\t\t\t\ttree[node]=A[start];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint mid=(start+end)>>1;\n\t\t\t\t\tbuildSum(node*2, start, mid);\n\t\t\t\t\tbuildSum(node*2+1, mid+1, end);\n\t\t\t\t\ttree[node]=tree[node*2]+tree[2*node+1];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tvoid updateRangeSum(int node, int start, int end,int l,int r,long val)\n\t\t\t{\n\t\t\t\tif (lazy[node]!=0)\n\t\t\t\t{\n\t\t\t\t\ttree[node]=add(tree[node],mul((end-start+1),lazy[node]));\n\t\t\t\t\tif (start!=end)\n\t\t\t\t\t{\n\t\t\t\t\t\tlazy[2*node]=add(lazy[2*node],lazy[node]);\n\t\t\t\t\t\tlazy[node*2+1]=add(lazy[2*node+1],lazy[node]);\n\t\t\t\t\t}\n\t\t\t\t\tlazy[node]=0;\n\t\t\t\t}\n\t\t\t\tif (start>end||start>r||end<l)\n\t\t\t\t\treturn;\n\t\t\t\t\n\t\t\t\tif (start>=l&&end<=r)\n\t\t\t\t{\n\t\t\t\t\ttree[node]=add(tree[node],mul((end-start+1),val));\n\t\t\t\t\tif (start!=end)\n\t\t\t\t\t{\n\t\t\t\t\t\tlazy[2*node]=add(lazy[2*node],val);\n\t\t\t\t\t\tlazy[node*2+1]=add(lazy[2*node+1],val);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tint mid=(start+end)>>1;\n\t\t\t\tupdateRangeSum(node*2, start, mid, l, r, val);\n\t\t\t\tupdateRangeSum(node*2+1, mid+1, end, l, r, val);\n\t\t\t\ttree[node]=add(tree[node*2],tree[node*2+1]);\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tlong queryRangeSum(int node,int start,int end,int l,int r)\n\t\t\t{\n\t\t\t\tif (start>r||end<l||start>end)\n\t\t\t\t\treturn 0;\n\t\t\t\tif (lazy[node]!=0)\n\t\t\t\t{\n\t\t\t\t\ttree[node]=add(tree[node],mul((end-start+1),lazy[node]));\n\t\t\t\t\tif (start!=end)\n\t\t\t\t\t{\n\t\t\t\t\t\tlazy[2*node]=add(lazy[2*node],lazy[node]);\n\t\t\t\t\t\tlazy[node*2+1]=add(lazy[2*node+1],lazy[node]);\n\t\t\t\t\t}\n\t\t\t\t\tlazy[node]=0;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (start>=l&&end<=r)\n\t\t\t\t\treturn tree[node];\n\t\t\t\t\n\t\t\t\tint mid=(start+end)>>1;\n\t\t\t\treturn add(queryRangeSum(node*2, start, mid, l, r),queryRangeSum(node*2+1, mid+1, end, l, r));\n\t\t\t}\n\t\t}\n\t\n\tlong mod=(long)1e9+7;\n\tlong add(long a,long b)\n\t{\n\t\tlong x=(a+b);\n\t\twhile(x>=mod) x-=mod;\n\t\treturn x;\n\t\t\n\t}\n\t\n\t\n\tlong sub(long a,long b)\n\t{\n\t\tlong x=(a-b);\n\t\twhile(x<0) x+=mod;\n\t\treturn x;\n\t\t\n\t}\n\t\n\t\n\tlong mul(long a,long b)\n\t{\n\t\ta%=mod;\n\t\tb%=mod;\n\t\tlong x=(a*b);\n\t\treturn x%mod;\n\t\t\n\t}\n\t\n\tvoid run() throws Exception {\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\t\tlong s = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew C().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\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 = in.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\t\n\tprivate boolean inSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() {\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\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) { // 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\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(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\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\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\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\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\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\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\t\n\tprivate void tr(Object... o) {\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A{\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tpublic void solve(){\n\t\tint n=ni();\n\t\tchar[] arr=new char[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tarr[i]=ns().charAt(0);\n\t\t}\n\n\t\tlong mod=1000000007;\n\t\tlong[][] memo=new long[n][n];\n\t\tmemo[0][0]=1L;\n\t\tint k=0;\n\t\tfor(int i=1; i<n; i++){\n\t\t\tif( (arr[i]=='f' && arr[i-1]=='s') || (arr[i]=='s' && arr[i-1]=='s') ){\n\t\t\t\tlong sum=0;\n\t\t\t\tfor(int j=k; j>=0; j--){\n\t\t\t\t\tsum=(sum+(memo[i-1][j]%mod))%mod;\n\t\t\t\t\tmemo[i][j]=sum;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tk+=1;\n\t\t\t\tfor(int j=1; j<=k; j++){\n\t\t\t\t\tmemo[i][j] = memo[i-1][j-1] % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t//print(n, memo);\n\t\tlong sum=0;\n\t\tfor(int i=0;i<=k;i++){\n\t\t\tsum=(sum+(memo[n-1][i])%mod)%mod;\n\t\t}\n\t\tout.println(sum);\n\t}\n\tvoid print(int n, long[][] memo){\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(memo[i][j]+\" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n\n\tvoid run(){\n\t\tis = new DataInputStream(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tint t=1;while(t-->0)solve();\n\t\tout.flush();\n\t}\n\tpublic static void main(String[] args)throws Exception{new A().run();}\n\t//Fast I/O code is copied from uwi code.\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\tprivate int readByte(){\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\tprivate String ns(){\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\tprivate char[] ns(int n){\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\tprivate char[][] nm(int n, int m){\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\tprivate int[] na(int n){\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\tprivate int ni(){\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\tprivate long nl(){\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\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\tstatic  int i(long x){return (int)Math.round(x);}\n\tstatic class Pair implements Comparable<Pair>{\n\t\tlong fs,sc;\n\t\tPair(long a,long b){\n\t\t\tfs=a;sc=b;\n\t\t}\n\t\tpublic int compareTo(Pair p){\n\t\t\tif(this.fs>p.fs)return 1;\n\t\t\telse if(this.fs<p.fs)return -1;\n\t\t\telse{\n\t\t\t\treturn i(this.sc-p.sc);\n\t\t\t}\n\t\t\t//return i(this.sc-p.sc);\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn \"(\"+fs+\",\"+sc+\")\";\n\t\t}\t\n\t}\n\t\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tstatic int N;\n\tstatic char[] a;\n\tstatic int[][] memo;\n\tstatic int[] ind;\n\tstatic final int MOD = (int) 1e9 + 7;\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\tN = sc.nextInt(); a = new char[N];\n\t\tfor(int i = 0; i < N; i++) a[i] = sc.nextChar();\n\t\t\n\t\tif(N == 1){out.println(1); out.flush(); return;}\n\t\tmemo = new int[N][N + 5];\n\t\tfor(int[] a : memo) Arrays.fill(a, -1);\n\t\t\n\t\tout.println(dp(0, 1));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\t\n\tstatic int dp(int i, int ind)\n\t{\n\t\tif(i == N - 1) return a[i - 1] == 'f'? 1 : ind;\n\t\tif(i == 0) return dp(i + 1, a[i] == 's'? 1 : 2);\n\t\tif(memo[i][ind] != -1) return memo[i][ind];\n\t\tint ans = 0;\n\t\tif(a[i - 1] == 'f')\n\t\t\tans = dp(i + 1, a[i] == 's'? ind : ind + 1);\n\t\telse\n\t\t{\n\t\t\tif(ind > 1)\n\t\t\t\tans = (ans + dp(i, ind -1)) % MOD;\n\t\t\tans = (ans + dp(i + 1, a[i] == 's'? ind : ind + 1)) % MOD;\n\t\t}\n\t\treturn memo[i][ind] = ans;\n\t}\n\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tScanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}\n\t\tScanner(String file) throws FileNotFoundException {br = new BufferedReader(new FileReader(file));}\n\t\tString 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\tString nextLine()throws IOException{return br.readLine();}\n\t\tint nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tdouble nextDouble() throws IOException {return Double.parseDouble(next());}\n\t\tchar nextChar()throws IOException{return next().charAt(0);}\n\t\tLong nextLong()throws IOException{return Long.parseLong(next());}\n\t\tboolean ready() throws IOException{return br.ready();}\n\t\tvoid waitForInput(){for(long i = 0; i < 3e9; i++);}\n\t}\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class C{\n\t\n\tstatic long mod=1000000007;\n\tstatic int n;\n\tstatic long w[][];\n\tstatic void MainMethod()throws Exception{\n\t\tn=reader.nextInt();\n\t\tw=new long[n+2][n+2];\n\t\tfor (int i=0;i<=(n+1);i++)\n\t\t\tArrays.fill(w[i], 0);\n\t\tw[1][0]=1;\n\t\tString prev,next;\n\t\tprev=reader.next();\n\t\tlong s[]=new long[n+2];\n\t\tfor (int i=2;i<=n;i++) {\n\t\t\tnext=reader.next();\n\t\t\tif (prev.equals(\"f\"))\n\t\t\t\tfor (int lv=0;lv<=n;lv++) \n\t\t\t\t\tw[i][lv+1]=w[i-1][lv];\n\t\t\telse\n\t\t\t\tfor (int lv=n;lv>=0;lv--){\n\t\t\t\t\tw[i][lv]=(w[i-1][lv]+w[i][lv+1])%mod;\n\t\t\t\t}\n\t\t\tprev=next;\n\t\t}\n\t\tlong res=0;\n\t\tfor (int i=0;i<=n;i++)\n\t\t\tres=(res+w[n][i])%mod;\n\t\tprinter.print(res);\n\t}\n\tpublic static void main(String[] args)throws Exception{\n\t\tMainMethod();\n\t\tprinter.close();\n\t}\n\tstatic void halt(){\n\t\tprinter.close();\n\t\tSystem.exit(0);\n\t}\n\tstatic PrintWriter printer=new PrintWriter(new OutputStreamWriter(System.out));\n\tstatic class reader{\n\t\tstatic BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));\n\t\tstatic StringTokenizer token=new StringTokenizer(\"\");\n\t\tstatic String readNextLine() throws Exception{\n\t\t\treturn bReader.readLine();\n\t\t}\n\t\tstatic String next() throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn token.nextToken();\n\t\t}\n\t\tstatic int nextInt()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Integer.parseInt(token.nextToken());\n\t\t}\n\t\tstatic long nextLong()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Long.parseLong(token.nextToken());\n\t\t}\n\t\tstatic double nextDouble()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Double.parseDouble(token.nextToken());\n\t\t}\n\t}\n\tstatic class MyMathCompute{\n\t\tstatic long [][] MatrixMultiplyMatrix(long [][] A, long [][] B, long mod) throws Exception{\n\t\t\tint n=A.length, m=B[0].length; \n\t\t\tint p=A[0].length;\n\t\t\tint i,j,k;\n\t\t\tif (B.length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\tlong [][] res=new long [n][m];\n\t\t\tfor (i=0;i<n;i++) for (j=0;j<m;j++){\n\t\t\t\tif (A[i].length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\t\tres[i][j]=0;\n\t\t\t\tfor (k=0;k<p;k++)\n\t\t\t\t\tres[i][j]=(res[i][j]+((A[i][k]*B[k][j])% mod))% mod;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tstatic double [][] MatrixMultiplyMatrix(double [][] A, double [][] B ) throws Exception{\n\t\t\tint n=A.length, m=B[0].length; \n\t\t\tint p=A[0].length;\n\t\t\tint i,j,k;\n\t\t\tif (B.length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\tdouble [][] res=new double [n][m];\n\t\t\tfor (i=0;i<n;i++) for (j=0;j<m;j++){\n\t\t\t\tif (A[i].length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\t\tres[i][j]=0;\n\t\t\t\tfor (k=0;k<p;k++)\n\t\t\t\t\tres[i][j]=res[i][j]+(A[i][k]*B[k][j]);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tstatic long [][] MatrixPow(long [][] A,long n, long mod) throws Exception{\n\t\t\tif (n==1) return A;\n\t\t\tlong [][] res=MatrixPow(A, n/2, mod);\n\t\t\tres=MatrixMultiplyMatrix(res, res, mod);\n\t\t\tif ((n % 2) == 1) res=MatrixMultiplyMatrix(A,res, mod);\t\t\n\t\t\treturn res;\n\t\t}\n\t\tstatic double [][] MatrixPow(double [][] A,long n) throws Exception{\n\t\t\tif (n==1) return A;\n\t\t\tdouble[][] res=MatrixPow(A, n/2);\n\t\t\tres=MatrixMultiplyMatrix(res, res);\n\t\t\tif ((n % 2) == 1) res=MatrixMultiplyMatrix(A,res);\t\t\n\t\t\treturn res;\n\t\t}\n\t\tstatic long pow(long a,long n,long mod){\n\t\t\ta= a % mod;\n\t\t\tif (n==0) return 1;\n\t\t\tlong k=pow(a,n/2,mod);\n\t\t\tif ((n % 2)==0) return ((k*k)%mod);\n\t\t\telse return (((k*k) % mod)*a) % mod;\n\t\t}\n\t\tstatic double pow(double a,long n){\n\t\t\tif (n==0) return 1;\n\t\t\tdouble k=pow(a,n/2);\n\t\t\tif ((n % 2)==0) return (k*k);\n\t\t\telse return (((k*k) )*a) ;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * Created by trung.pham on 28/12/17.\n */\npublic class C_Round_455_Div2 {\n    static long[][]dp;\n\n    static  long MOD =(long) 1e9 + 7;\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        char[]data = new char[n];\n        dp = new long[n][n];\n        for(long []a : dp){\n            Arrays.fill(a,-1);\n        }\n        for(int i = 0; i < n; i++){\n            data[i] = in.next().charAt(0);\n        }\n        out.println(cal(0, 0, data));\n\n        out.close();\n    }\n\n    static long cal(int index, int nested, char[]data ){\n        //System.out.println(index + \" \" + nested);\n        if(index + 1 == data.length){\n            return 1;\n        }\n        if(dp[index][nested] != -1){\n            return dp[index][nested];\n        }\n        long result = 0;\n        boolean isLoop = data[index] == 'f';\n        if(isLoop){\n            result = cal(index + 1, nested + 1, data);\n        }else{\n            result = cal(index + 1, nested, data);\n            if(nested > 0){\n                result += cal(index, nested - 1, data);\n                result %= MOD;\n            }\n        }\n       // System.out.println(result + \" \" + index + \" \" + nested);\n        return dp[index][nested]= result;\n\n    }\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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        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.readInt();\n            boolean[] isF = new boolean[n];\n            for (int i = 0; i < n; i++) {\n                isF[i] = in.readCharacter() == 'f';\n            }\n            int[][] mem = new int[n + 1][n + 1];\n            mem[n][0] = 1;\n            for (int idx = n - 1; idx >= 0; idx--) {\n                for (int indentLevel = 0; indentLevel < n; indentLevel++) {\n                    mem[idx + 1][indentLevel + 1] += mem[idx + 1][indentLevel];\n                    mem[idx + 1][indentLevel + 1] %= MiscUtils.MOD7;\n                    int res = isF[idx] ?\n                            mem[idx + 1][indentLevel + 1] - mem[idx + 1][indentLevel] :\n                            mem[idx + 1][indentLevel];\n                    mem[idx][indentLevel] = (res + MiscUtils.MOD7) % MiscUtils.MOD7;\n                }\n            }\n            out.printLine(mem[0][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        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    static class MiscUtils {\n        public static final int MOD7 = (int) (1e9 + 7);\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class _909C {\n\n    private static final int MOD = 1000000007;\n\n    private static void solve(Scanner scan, PrintWriter pw) {\n        int n = scan.nextInt();\n        scan.nextLine();\n\n        // dp[i][j] is the number ways the ith statement is indented j times\n        int[][] dp = new int[n][n];\n        int[][] dpSums = new int[n][n];\n\n        dp[0][0] = 1;\n\n        for(int i = 0; i < n; i++) {\n            dpSums[0][i] = 1;\n        }\n\n        boolean lastIsSimple = scan.nextLine().equals(\"s\");\n\n        for(int i = 1; i < n; i++) {\n\n            if(lastIsSimple) {\n                dp[i][0] = dpSums[i-1][n-1];\n                dpSums[i][0] = dp[i][0];\n\n                for(int j = 1; j < n; j++) {\n                    dp[i][j] = (dpSums[i-1][n-1] - dpSums[i-1][j-1] + MOD) % MOD;\n                    dpSums[i][j] = (dp[i][j] + dpSums[i][j-1]) % MOD;\n                }\n            }\n            else {\n                dp[i][0] = 0;\n                dpSums[i][0] = 0;\n\n                for(int j = 1; j < n; j++) {\n                    dp[i][j] = dp[i-1][j-1];\n                    dpSums[i][j] = (dp[i][j] + dpSums[i][j-1]) % MOD;\n                }\n\n            }\n\n            lastIsSimple = scan.nextLine().equals(\"s\");\n        }\n\n        System.out.println(dpSums[n-1][n-1]);\n    }\n\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024 * 64));\n        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 1024 * 64));\n        solve(scan, pw);\n        pw.flush();\n    }\n\n}", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C {\n\n    private static final int MOD = (int) 1e9 + 7;\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n\n        int[][] DP = new int[n][n + 1];\n        DP[0][0] = 1;\n\n        for (int i = 0; i < n - 1; i++) {\n            if (in.next().charAt(0) == 'f') {\n                for (int j = 1; j < n; j++)\n                    DP[i+1][j] = DP[i][j-1];\n            } else {\n                for (int j = n - 1; j >= 0; j--)\n                    DP[i+1][j] = (DP[i][j] + DP[i+1][j+1]) % MOD;\n            }\n        }\n\n        int answer = 0;\n        for (int i = 0; i < n; i++)\n            answer = (answer + DP[n-1][i]) % MOD;\n        System.out.println(answer);\n    }\n\n}\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\t//dp[firstInLoop][index][indentLevel]\n\tprivate static int[][][] dp;\n\tprivate static boolean[] wasLoop;\n\tprivate static int MOD=1000000007;\n\tprivate static int n;\n\t\n\tpublic static void solve(FastScanner fs) {\t\n\t\tn=fs.nextInt();\n\t\tdp=new int[2][n][n];\n\t\tfor (int i=0; i<dp.length; i++)\n\t\t\tfor (int j=0; j<dp[i].length; j++)\n\t\t\t\tArrays.fill(dp[i][j], -1);\n\t\twasLoop=new boolean[n];\n\t\tfor (int i=0; i<n; i++)\n\t\t\twasLoop[i]=fs.next().equals(\"f\");\n\t\t\n\t\tint ans=go(0, 0, 0);\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tprivate static int go(int firstInLoop, int index, int indentLevel) {\n\t\tif (index>=n)//base case\n\t\t\treturn 1;\n\t\tif (dp[firstInLoop][index][indentLevel]!=-1)\n\t\t\treturn dp[firstInLoop][index][indentLevel];\n\t\t\n\t\t//if I am forced, just do it\n\t\tif (firstInLoop==1)\n\t\t\treturn dp[firstInLoop][index][indentLevel]=go(wasLoop[index]?1:0, index+1, indentLevel+(wasLoop[index]?1:0));\n\t\t\n\t\t//if I am on the end level, I don't have a choice\n\t\tif (indentLevel==0) {\n\t\t\treturn dp[firstInLoop][index][indentLevel]=go(wasLoop[index]?1:0, index+1, wasLoop[index]?1:0);\n\t\t}\n\t\telse {\n\t\t\t//otherwise, add all the possibilities\n\t\t\tint total=0;\n\t\t\ttotal+=go(firstInLoop, index, indentLevel-1);\n\t\t\ttotal+=go(wasLoop[index]?1:0, index+1, indentLevel+(wasLoop[index]?1:0));\n\t\t\ttotal%=MOD;\n\t\t\treturn dp[firstInLoop][index][indentLevel]=total;\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<n; i++)\n\t\t\t\ta[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n\n\n", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "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        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.readInt();\n            boolean[] isF = new boolean[n];\n            for (int i = 0; i < n; i++) {\n                isF[i] = in.readCharacter() == 'f';\n            }\n            long[][] mem = new long[n + 1][n + 1];\n            mem[n][0] = 1;\n            for (int idx = n - 1; idx >= 0; idx--) {\n                for (int indentLevel = 0; indentLevel < n; indentLevel++) {\n                    mem[idx + 1][indentLevel + 1] += mem[idx + 1][indentLevel];\n                    long res = isF[idx] ?\n                            mem[idx + 1][indentLevel + 1] - mem[idx + 1][indentLevel] :\n                            mem[idx + 1][indentLevel];\n                    mem[idx][indentLevel] = res % MiscUtils.MOD7;\n                }\n            }\n            out.printLine(mem[0][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        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    static class MiscUtils {\n        public static final int MOD7 = (int) (1e9 + 7);\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", "complexity": "quadratic", "problem": "909_C. Python Indentation", "from": "CODEFORCES"}
{"src": "//package educational.round35;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tint[] ft = new int[n+3];\n\t\tint x = 0;\n\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\tx ^= sumFenwick(ft, a[i]);\n\t\t\taddFenwick(ft, a[i], 1);\n\t\t}\n\t\tx &= 1;\n\t\tfor(int Q = ni();Q > 0;Q--){\n\t\t\tint l = ni(), r = ni();\n\t\t\tlong u = (r-l+1)*(r-l)/2;\n\t\t\tx ^= u&1;\n\t\t\tif(x == 0){\n\t\t\t\tout.println(\"even\");\n\t\t\t}else{\n\t\t\t\tout.println(\"odd\");\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static int sumFenwick(int[] ft, int i) {\n\t\tint sum = 0;\n\t\tfor (i++; i > 0; i -= i & -i)\n\t\t\tsum += ft[i];\n\t\treturn sum;\n\t}\n\n\tpublic static void addFenwick(int[] ft, int i, int v) {\n\t\tif (v == 0 || i < 0)\n\t\t\treturn;\n\t\tint n = ft.length;\n\t\tfor (i++; i < n; i += i & -i)\n\t\t\tft[i] += v;\n\t}\n\n\tpublic static int findGFenwick(int[] ft, int v) {\n\t\tint i = 0;\n\t\tint n = ft.length;\n\t\tfor (int b = Integer.highestOneBit(n); b != 0 && i < n; b >>= 1) {\n\t\t\tif (i + b < n) {\n\t\t\t\tint t = i + b;\n\t\t\t\tif (v >= ft[t]) {\n\t\t\t\t\ti = t;\n\t\t\t\t\tv -= ft[t];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn v != 0 ? -(i + 1) : i - 1;\n\t}\n\n\tpublic static int valFenwick(int[] ft, int i) {\n\t\treturn sumFenwick(ft, i) - sumFenwick(ft, i - 1);\n\t}\n\n\tpublic static int[] restoreFenwick(int[] ft) {\n\t\tint n = ft.length - 1;\n\t\tint[] ret = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tret[i] = sumFenwick(ft, i);\n\t\tfor (int i = n - 1; i >= 1; i--)\n\t\t\tret[i] -= ret[i - 1];\n\t\treturn ret;\n\t}\n\n\tpublic static int before(int[] ft, int x) {\n\t\tint u = sumFenwick(ft, x - 1);\n\t\tif (u == 0)\n\t\t\treturn -1;\n\t\treturn findGFenwick(ft, u - 1) + 1;\n\t}\n\n\tpublic static int after(int[] ft, int x) {\n\t\tint u = sumFenwick(ft, x);\n\t\tint f = findGFenwick(ft, u);\n\t\tif (f + 1 >= ft.length - 1)\n\t\t\treturn -1;\n\t\treturn f + 1;\n\t}\n\n\tpublic static int[] buildFenwick(int[] a) {\n\t\tint n = a.length;\n\t\tint[] ft = new int[n + 1];\n\t\tSystem.arraycopy(a, 0, ft, 1, n);\n\t\tfor (int k = 2, h = 1; k <= n; k *= 2, h *= 2) {\n\t\t\tfor (int i = k; i <= n; i += k) {\n\t\t\t\tft[i] += ft[i - h];\n\t\t\t}\n\t\t}\n\t\treturn ft;\n\t}\n\n\tpublic static int[] buildFenwick(int n, int v) {\n\t\tint[] ft = new int[n + 1];\n\t\tArrays.fill(ft, 1, n + 1, v);\n\t\tfor (int k = 2, h = 1; k <= n; k *= 2, h *= 2) {\n\t\t\tfor (int i = k; i <= n; i += k) {\n\t\t\t\tft[i] += ft[i - h];\n\t\t\t}\n\t\t}\n\t\treturn ft;\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 D().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\n/**\n * @author: Mehul Raheja\n */\nimport java.util.*;\nimport java.io.*;\n\npublic class p4 {\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    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        //int[] x = {1,2,3,4,5,6,7,8,9,10};\n\n        int N = Integer.parseInt(br.readLine());\n        int[] d = new int[N];\n        st = new StringTokenizer(br.readLine());\n        for (int i = 0; i < N; i++) {\n            d[i] = Integer.parseInt(st.nextToken());\n        }\n        boolean cur = ((inv(d)) % 2) == 1;\n        // System.out.println(cur);\n        int Q = Integer.parseInt(br.readLine());\n        for (int i = 0; i < Q; i++) {\n            st = new StringTokenizer(br.readLine());\n            int a = Integer.parseInt(st.nextToken());\n            int b = Integer.parseInt(st.nextToken());\n\n            int dif = b - a + 1;\n            if (dif / 2 % 2 == 1) {\n                cur = !cur;\n            }\n\n            System.out.println((cur) ? \"odd\" : \"even\");\n        }\n\n//        for (int i = 0; i < 30; i++) {\n//            int[] x = new int[i];\n//            for (int j = 0; j < i; j++) {\n//                x[j] = j + 1;\n//            }\n//            int[] y = new int[x.length];\n//            for (int k = 0; k < x.length; k++) {\n//                y[x.length - 1 - k] = x[k];\n//            }\n//\n////            System.out.println(inv(x));\n////            System.out.println(inv(y));\n//            System.out.println(i + \" \" + ((inv(y) - inv(x))%2 == 1));\n//        }\n    }\n\n    static class BIT {\n\n        int[] tree;\n        int N;\n\n        public BIT(int N) {\n            this.N = N;\n            tree = new int[N + 1];\n        }\n\n        public BIT(int N, int[] d) {\n            this.N = N;\n            tree = new int[N + 1];\n            for (int i = 1; i < d.length; i++) {\n                update(i, d[i]);\n            }\n        }\n\n        public int query(int K) {\n            int sum = 0;\n            for (int i = K; i > 0; i -= (i & -i)) {\n                sum += tree[i];\n            }\n            return sum;\n        }\n\n        public void update(int K, int val) {\n            for (int i = K; i <= N; i += (i & -i)) {\n                tree[i] += val;\n            }\n        }\n    }\n\n    public static int[] toRel(int[] d) {\n        pair[] p = new pair[d.length];\n        for (int i = 0; i < d.length; i++) {\n            p[i] = new pair(d[i], i + 1);\n        }\n        Arrays.sort(p);\n        int[] fin = new int[d.length];\n        for (int i = 0; i < d.length; i++) {\n            fin[i] = p[i].b;\n        }\n        return fin;\n    }\n\n    public static int inv(int[] d) {\n        int ans = 0;\n        int N = d.length;\n        int[] x = toRel(d);\n        BIT b = new BIT(N + 1);\n\n        for (int i = N - 1; i >= 0; i--) {\n            ans += b.query(x[i]);\n            b.update(x[i], 1);\n        }\n\n        return ans;\n    }\n}\n\nclass pair implements Comparable<pair> {\n\n    int a, b;\n\n    public pair(int _a, int _b) {\n        this.a = _a;\n        this.b = _b;\n    }\n\n    @Override\n    public int compareTo(pair t) {\n        return (a == t.a) ? b - t.b : a - t.a;\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.text.*;\nimport java.io.*;\nimport java.math.*;\npublic class code5 {\n\tInputStream is;\n\tPrintWriter out;\n\tstatic long mod=pow(10,9)+7;\n\tstatic int dx[]={0,0,1,-1},dy[]={1,-1,0,0};\n\tString arr[];\n\tlong dp[][];\n\tvoid solve() throws IOException\n\t{\n\t\tint n=ni();\n\t\tint a[]=na(n);\n\t\tint q=ni();\n\t\tboolean flag=false;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int j=0;j<i;j++)\n\t\t\t{\n\t\t\t\tif(a[j]>a[i])\n\t\t\t\t\tflag^=true;\n\t\t\t}\n\t\t}\n\t\twhile(q--!=0)\n\t\t{\n\t\t\tint l=ni()-1;\n\t\t\tint r=ni()-1;\n\t\t\tint num=(r-l+1);\n\t\t\tint tot=num*(num-1)/2;\n\t\t\tif(tot%2==1)\n\t\t\t\tflag^=true;\n\t\t\tif(flag)\n\t\t\t\tout.println(\"odd\");\n\t\t\telse\n\t\t\t\tout.println(\"even\");\t\t\t\n\t\t}\n\t}\n\tint sum(int i)\n\t{\n\t\tint sum=0;\n\t\twhile(i!=0)\n\t\t{\n\t\t\tif((i%10)%2==1)\n\t\t\t\tsum+=i%10;\n\t\t\ti/=10;\n\t\t}\n\t\treturn sum;\n\t}\n\tArrayList<Integer> al[];\n \tvoid take(int n,int m)\n \t{\n \t\tal=new ArrayList[n];\n \t\tfor(int i=0;i<n;i++)\n \t\t\tal[i]=new ArrayList<Integer>();\n \t\tfor(int i=0;i<m;i++)\n \t\t{\n \t\t\tint x=ni()-1;\n \t\t\tint y=ni()-1;\n \t\t\tal[x].add(y);\n \t\t\tal[y].add(x);\n \t\t}\n \t}\n \tint check(long n)\n \t{\n \t\tint count=0;\n \t\twhile(n!=0)\n \t\t{\n \t\t\tif(n%10!=0)\n \t\t\t\tbreak;\n \t\t\tn/=10;\n \t\t\tcount++;\n \t\t}\n \t\treturn count;\n \t}\n\tpublic static int count(int x)\n\t{\n\t\tint num=0;\n\t\twhile(x!=0)\n\t\t{\n\t\t\tx=x&(x-1);\n\t\t\tnum++;\n\t\t}\n\t\treturn num;\n\t}\n\tstatic long d, x, y;\n\tvoid extendedEuclid(long A, long B) {\n\t    if(B == 0) {\n\t        d = A;\n\t        x = 1;\n\t        y = 0;\n\t    }\n\t    else {\n\t        extendedEuclid(B, A%B);\n\t        long temp = x;\n\t        x = y;\n\t        y = temp - (A/B)*y;\n\t    }\n\t}\n\tlong modInverse(long A,long M) //A and M are coprime\n\t{\n\t    extendedEuclid(A,M);\n\t    return (x%M+M)%M;    //x may be negative\n\t}\n\tpublic static void mergeSort(int[] arr, int l ,int r){\n\t\tif((r-l)>=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 ;i<n1;i++) left[i] = arr[l+i];\n\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\tint i =0, j =0, k = l;\n\t\twhile(i<n1 && j<n2){\n\t\t\tif(left[i]>right[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<n1) arr[k++] = left[i++];\n\t\twhile(j<n2) arr[k++] = right[j++];\n\t}\n\tpublic static void mergeSort(long[] arr, int l ,int r){\n\t\tif((r-l)>=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 ;i<n1;i++) left[i] = arr[l+i];\n\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\tint i =0, j =0, k = l;\n\t\twhile(i<n1 && j<n2){\n\t\t\tif(left[i]>right[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<n1) arr[k++] = left[i++];\n\t\twhile(j<n2) arr[k++] = right[j++];\n\t}\n\t static class Pair implements Comparable<Pair>{\n\t\t \n\t       int x,y,k;\n\t       int i,dir;\n\t       long val;\n\t\tPair (int x,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}   \n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(this.x!=o.x)\n\t\t\t\treturn this.x-o.x;\n\t\t\treturn this.y-o.y;\n\t\t}\n\t \n\t\tpublic String toString(){\n\t\t\treturn x+\" \"+y+\" \"+k+\" \"+i;}\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (o instanceof Pair) {\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\tpublic int hashCode() {\n\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode() ;\n\t\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\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 code5().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 code5().run();\n\t\t}\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\tprivate long[] nl(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] = nl();\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import 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 a[] = new int[n+1];\n\t\tfor(int i=1 ; i<=n ; i++) a[i] = sc.nextInt();\n\t\tint cnt = 0;\n\t\tfor(int i=1 ; i<=n ; i++) {\n\t\t\tfor(int j=i-1 ; j>=1 ; j--) {\n\t\t\t\tif(a[i]<a[j])\n\t\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\t//System.out.println(cnt);\n\t\tint q = sc.nextInt();\n\t\tcnt = cnt % 2; \n\t\twhile(q-->0) {\n\t\t\tint x = sc.nextInt();\n\t\t\tint y = sc.nextInt();\n\t\t\tint r = y-x+1;\n\t\t\tlong ok = (r*(r-1))/2;\n\t\t\tif(ok%2==0) {\n\t\t\t\t\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcnt ^= 1 ; \n\t\t\t}\n\t\t\tSystem.out.println(cnt==0?\"even\":\"odd\");\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport 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\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\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\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 \t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new Main(),\"Main\",1<<26).start();\n\t}\t\n\t\n\tpublic void run()\n\t{\n\t\tInputReader sc = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n        \n       \tint n = sc.nextInt();\n\n       \tint a[] = new int[n];\n\n       \tfor(int i = 0; i < n; ++i)\n       \t\ta[i] = sc.nextInt();\n\n       \tint cnt = 0;\n\n       \tfor(int i = 0; i < n; ++i) {\n       \t\tfor(int j = 0; j < i; ++j) {\n       \t\t\tif(a[i] < a[j])\n       \t\t\t\tcnt ^= 1;\n       \t\t}\n       \t}\n\n       \tint m = sc.nextInt();\n\n       \tfor(int i = 0; i < m; ++i) {\n       \t\tint l = sc.nextInt();\n       \t\tint r = sc.nextInt();\n\n       \t\tlong size = (long)(r - l + 1);\n       \t\tlong subarr = size * (size - 1) / 2;\n       \t\tint type = (int)(subarr % 2);\n\n       \t\tif(type == 1) {\n       \t\t\tcnt ^= 1;\n       \t\t}\n       \t\tif(cnt == 0)\n       \t\t\tw.println(\"even\");\n       \t\telse\n       \t\t\tw.println(\"odd\");\n       \t}\n\n \t\tw.close();\t\t\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Problem911D {\n        public static void main(String args[]) throws IOException {\n                Scanner sc = new Scanner(System.in);\n                int n = sc.nextInt(), i, j;\n                int ar[] = new int[n];\n                int inv = 0;\n                \n                for(i = 0; i < n; i++) {\n                        ar[i] = sc.nextInt();\n                }\n                \n                for(i = 0; i < n; i++) {\n                        for(j = 0; j < n; j++) {\n                                if(i > j && ar[i] < ar[j]) {\n                                        inv = (inv + 1) % 2;\n                                }\n                        }\n                }\n                \n                int q = sc.nextInt();\n                \n                for(i = 0; i < q; i++) {\n                        int l = sc.nextInt();\n                        int r = sc.nextInt();\n                        \n                        int c = ( ((r-l)*(r-l+1))/2 ) % 2;\n                        inv = (inv + c) % 2;\n                        \n                        if(inv == 0)\n                                System.out.println(\"even\");\n                        else\n                                System.out.println(\"odd\");\n\n                }\n        }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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 Liavontsi Brechka\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\n    @SuppressWarnings(\"Duplicates\")\n    class TaskD {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = in.nextIntArray(n);\n            int m = in.nextInt();\n\n            int count = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    if (a[i] > a[j]) count++;\n                }\n            }\n\n            StringBuilder res = new StringBuilder();\n\n            int l, r, temp, c1, c2;\n            while (m-- > 0) {\n                l = in.nextInt() - 1;\n                r = in.nextInt() - 1;\n\n                c1 = c2 = 0;\n                for (int i = 0; i < (r - l + 1) / 2; i++) {\n                    if (a[l + i] > a[r - i]) c1++;\n                    else c2++;\n\n                    temp = a[l + i];\n                    a[l + i] = a[r - i];\n                    a[r - i] = temp;\n                }\n\n                count = count + c1 - c2;\n                res.append(Math.abs(count) % 2 == 1 ? \"odd\" : \"even\").append('\\n');\n            }\n\n            out.print(res);\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[] nextIntArray(int size) {\n            int[] array = new int[size];\n            for (int i = 0; i < size; ++i) {\n                array[i] = nextInt();\n            }\n            return array;\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class InversionCounting {\npublic static void main(String[] args) throws IOException{\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tbr.readLine();\n\tint[] a = Arrays.stream(br.readLine().split(\" \")).mapToInt(x->Integer.parseInt(x)).toArray();\n\tboolean evenInv = true;\n\tfor (int i = 0; i < a.length; i++) {\n\t\tfor (int j = 0; j < a.length-1; j++) {\n\t\t\tif(a[j]>a[j+1]) {\n\t\t\t\tint temp = a[j];\n\t\t\t\ta[j] = a[j+1];\n\t\t\t\ta[j+1] = temp;\n\t\t\t\tevenInv =!evenInv;\n\t\t\t}\n\t\t}\n\t}\n\tint q = Integer.parseInt(br.readLine());\n\tfor (int i = 0; i < q; i++) {\n\t\tint[] sw = Arrays.stream(br.readLine().split(\" \")).mapToInt(x->Integer.parseInt(x)).toArray();\n\t\tint len = sw[1]-sw[0];\n\t\tif((len)*(len+1)%4 != 0) {\n\t\t\tevenInv = !evenInv;\n\t\t}\n\t\tif(evenInv) {\n\t\t\tSystem.out.println(\"even\");\n\t\t}else {\n\t\t\tSystem.out.println(\"odd\");\n\t\t}\n\t}\n\t\n}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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 Liavontsi Brechka\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\n    @SuppressWarnings(\"Duplicates\")\n    class TaskD {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = in.nextIntArray(n);\n            int m = in.nextInt();\n\n            int count = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    if (a[i] > a[j]) count = (count + 1) % 2;\n                }\n            }\n\n            StringBuilder res = new StringBuilder();\n\n            int l, r, temp;\n            while (m-- > 0) {\n                l = in.nextInt() - 1;\n                r = in.nextInt() - 1;\n\n                for (int i = 0; i < (r - l + 1) / 2; i++) {\n                    temp = a[l + i];\n                    a[l + i] = a[r - i];\n                    a[r - i] = temp;\n                }\n\n                count = count ^ (((r - l + 1) * (r - l) / 2) % 2);\n                res.append(count == 1 ? \"odd\" : \"even\").append('\\n');\n            }\n\n            out.print(res);\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[] nextIntArray(int size) {\n            int[] array = new int[size];\n            for (int i = 0; i < size; ++i) {\n                array[i] = nextInt();\n            }\n            return array;\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\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[] a=ir.nextIntArray(n);\n\t\tint m=ir.nextInt();\n\t\tlong ret=mergeSort(a,0,n)%2;\n\t\tint p,q;\n\t\tfor(int i=0;i<m;i++){\n\t\t\tp=ir.nextInt()-1;\n\t\t\tq=ir.nextInt()-1;\n\t\t\tif((q-p)%4==1||(q-p)%4==2)\n\t\t\t\tret^=1;\n\t\t\tf(ret);\n\t\t}\n\t}\n\n\tpublic static void f(long a){\n\t\tif(a==0){\n\t\t\tout.println(\"even\");\n\t\t}\n\t\telse\n\t\t\tout.println(\"odd\");\n\t}\n\tpublic static long mergeSort(int[] a, int left, int right) {\n        long cnt = 0;\n        if (left + 1 < right) {\n            int mid = (left + right) / 2;\n            cnt += mergeSort(a, left, mid);\n            cnt += mergeSort(a, mid, right);\n            cnt += merge(a, left, mid, right);\n        }\n\n        return cnt;\n    }\n\n    public static long merge(int[] a, int left, int mid, int right) {\n        long cnt = 0;\n        int n1 = mid - left;\n        int n2 = right - mid;\n        int[] l = new int[n1 + 1];\n        int[] r = new int[n2 + 1];\n        for (int i = 0; i < n1; i++) {\n            l[i] = a[left + i];\n        }\n        for (int i = 0; i < n2; i++) {\n            r[i] = a[mid + i];\n        }\n        l[n1] = Integer.MAX_VALUE;\n        r[n2] = Integer.MAX_VALUE;\n\n        for (int i = 0, j = 0, k = left; k < right; k++) {\n            if (l[i] <= r[j]) {\n                a[k] = l[i];\n                i++;\n            } else {\n                a[k] = r[j];\n                j++;\n                cnt += n1 - i;\n            }\n        }\n\n        return cnt;\n    }\n\n\tpublic static void main(String[] args) throws Exception {\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.util.stream.Stream;\n\n\npublic class Main implements Runnable {\n\tstatic final double time = 1e9;\n\tstatic final int MOD = (int) 1e9 + 7;\n\tstatic final long mh = Long.MAX_VALUE;\n\tstatic final Reader in = new Reader();\n\tstatic final PrintWriter out = new PrintWriter(System.out);\n\tStringBuilder answer = new StringBuilder();\n\tlong start = System.nanoTime();\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Main(), \"persefone\", 1 << 28).start();\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\t\n\t\tsolve();\t\t\n\t\tprintf();\n\t\tlong elapsed = System.nanoTime() - start;\n//\t\tout.println(\"stamp : \" + elapsed / time);\n//\t\tout.println(\"stamp : \" + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));\n\t\tclose();\n//\t\tout.flush();\n\t}\n\t\t\n\t\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint[] a = in.nextIntArray(n);\n\t\tint invertions = 0;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tfor (int j = i - 1; j > -1; j--) {\n\t\t\t\tif (a[j] > a[i])\n\t\t\t\t\tinvertions++;\n\t\t\t}\n\t\t}\n\n\t\tinvertions %= 2;\n\n\t\tfor (int q = in.nextInt(); q > 0; q--) {\n\t\t\tint l = in.nextInt();\n\t\t\tint r = in.nextInt();\n\n\t\t\tint k = r - l + 1;\n\t\t\tk = (k * (k - 1) >> 1) % 2;\n\t\t\tif (invertions == k) {\n\t\t\t\tinvertions = 0;\n\t\t\t\tadd(\"even\", '\\n');\n\t\t\t} else {\n\t\t\t\tinvertions = 1;\n\t\t\t\tadd(\"odd\", '\\n');\n\t\t\t}\n\n\t\t}\n\n\t}\n\t\n\t\n\tvoid printf() {\n\t\tout.print(answer);\n\t}\n\t\n\tvoid close() {\n\t\tout.close();\n\t}\n\n\tvoid printf(Stream<?> str) {\n\t\tstr.forEach(o -> add(o, \" \"));\n\t\tadd(\"\\n\");\n\t}\n\n\t \n\tvoid printf(Object... obj) {\n\t\tprintf(false, obj);\n\t}\n\n\tvoid printfWithDescription(Object... obj) {\n\t\tprintf(true, obj);\n\t}\n\t\n\t\t\n\tprivate void printf(boolean b, Object... obj) {\n\n\t\tif (obj.length > 1) {\n\t\t\tfor (int i = 0; i < obj.length; i++) {\n\t\t\t\tif (b) add(obj[i].getClass().getSimpleName(), \" - \");\n\t\t\t\tif (obj[i] instanceof Collection<?>) {\n\t\t\t\t\tprintf((Collection<?>) obj[i]);\n\t\t\t\t} else if (obj[i] instanceof int[][]) {\n\t\t\t\t\tprintf((int[][])obj[i]);\n\t\t\t\t} else if (obj[i] instanceof long[][]) {\n\t\t\t\t\tprintf((long[][])obj[i]);\n\t\t\t\t} else if (obj[i] instanceof double[][]) {\n\t\t\t\t\tprintf((double[][])obj[i]);\n\t\t\t\t} else printf(obj[i]);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (b) add(obj[0].getClass().getSimpleName(), \" - \");\n\t\tprintf(obj[0]);\n\t}\n\n\tvoid printf(Object o) {\n\t\tif (o instanceof int[])\n\t\t\tprintf(Arrays.stream((int[]) o).boxed());\n\t\telse if (o instanceof char[])\n\t\t\tprintf(new String((char[]) o));\n\t\telse if (o instanceof long[])\n\t\t\tprintf(Arrays.stream((long[]) o).boxed());\n\t\telse if (o instanceof double[])\n\t\t\tprintf(Arrays.stream((double[]) o).boxed());\n\t\telse if (o instanceof boolean[]) {\n\t\t\tfor (boolean b : (boolean[]) o) add(b, \" \");\n\t\t\tadd(\"\\n\");\n\t\t}\n\t\telse \n\t\t\tadd(o, \"\\n\");\n\t}\n\n\tvoid printf(int[]... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) printf(obj[i]);\n\t}\n\t\n\tvoid printf(long[]... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) printf(obj[i]);\n\t}\n\t\n\tvoid printf(double[]... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) printf(obj[i]);\n\t}\n\t\n\tvoid printf(boolean[]... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) printf(obj[i]);\n\t}\n\t\n\tvoid printf(Collection<?> col) {\n\t\tprintf(col.stream());\n\t}\n\n\t<T, K> void add(T t, K k) {\n\t\tif (t instanceof Collection<?>) {\n\t\t\t((Collection<?>) t).forEach(i -> add(i, \" \"));\n\t\t} else if (t instanceof Object[]) {\n\t\t\tArrays.stream((Object[]) t).forEach(i -> add(i, \" \"));\n\t\t} else\n\t\t\tadd(t);\n\t\tadd(k);\n\t}\n\t\n\t\n\t\n\t<T> void add(T t) {\n\t\tanswer.append(t);\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\t<T extends Comparable<? super T>> T min(T... t) {\n\t\tif (t.length == 0)\n\t\t\treturn null;\n\t\tT m = t[0];\n\t\tfor (int i = 1; i < t.length; i++)\n\t\t\tif (t[i].compareTo(m) < 0)\n\t\t\t\tm = t[i];\n\t\treturn m;\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\t<T extends Comparable<? super T>> T max(T... t) {\n\t\tif (t.length == 0)\n\t\t\treturn null;\n\t\tT m = t[0];\n\t\tfor (int i = 1; i < t.length; i++)\n\t\t\tif (t[i].compareTo(m) > 0)\n\t\t\t\tm = t[i];\n\t\treturn m;\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 gcd(long a, long b) {\n\t\treturn (b == 0) ? a : gcd(b, a % b);\n\t}\n\t\n\t// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;\n\tint[] ext_gcd(int a, int b) {\n\t\tif (b == 0) return new int[] {a, 1, 0 };\n\t\tint[] vals = ext_gcd(b, a % b);\n\t\tint d = vals[0]; // gcd\n\t    int p = vals[2]; // \n\t\tint q = vals[1] - (a / b) * vals[2];\n\t\treturn new int[] { d, p, q };\t  \n\t}\n\t\n\t// find any solution of the equation: ax + by = c using extends gcd\n\tboolean find_any_solution(int a, int b, int c, int[] root) {\n\t\tint[] vals = ext_gcd(Math.abs(a), Math.abs(b));\n\t\tif (c % vals[0] != 0) return false;\n\t\tprintf(vals);\n\t\troot[0] = c * vals[1] / vals[0];\n\t\troot[1] = c * vals[2] / vals[0];\n\t\tif (a < 0) root[0] *= -1;\n\t\tif (b < 0) root[1] *= -1;\n\t\treturn true;\n\t}\n\t\n\tint mod(int x) { return x % MOD; }\n\t\n\tint mod(int x, int y) { return mod(mod(x) + mod(y)); }\n\t\n\tlong mod(long x) { return x % MOD; }\n\t\n\tlong mod (long x, long y) { return mod(mod(x) + mod(y)); }\n\t\n\tint lw(long[] f, int l, int r, long k) {\n\t\tint R = r, m = 0;\n\t\twhile (l <= r) {\n\t\t\tm = l + r >> 1;\n\t\t    if (m == R) return m;\n\t\t    if (f[m] >= k) r = m - 1; else l = m + 1;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tint up(long[] f, int l, int r, long k) {\n\t\tint R = r, m = 0;\n\t\twhile (l <= r) {\n\t\t\tm = l + r >> 1;\n\t\t    if (m == R) return m;\n\t\t    if (f[m] > k) r = m - 1; else l = m + 1;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tint lw(int[] f, int l, int r, int k) {\n\t\tint R = r, m = 0;\n\t\twhile (l <= r) {\n\t\t\tm = l + r >> 1;\n\t\t    if (m == R) return m;\n\t\t    if (f[m] >= k) r = m - 1; else l = m + 1;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tint up(int[] f, int l, int r, int k) {\n\t\tint R = r, m = 0;\n\t\twhile (l <= r) {\n\t\t\tm = l + r >> 1;\n\t\t    if (m == R) return m;\n\t\t    if (f[m] > k) r = m - 1; else l = m + 1;\n\t\t}\n\t\treturn l;\n\t}\n\n\t<K extends Comparable<K>> int lw(List<K> li, int l, int r, K k) {\n\t\tint R = r, m = 0;\n\t\twhile (l <= r) {\n\t\t\tm = l + r >> 1;\n\t\t    if (m == R) return m;\n\t\t    if (li.get(m).compareTo(k) >= 0) \n\t\t    \tr = m - 1;\n\t\t    else \n\t\t    \tl = m + 1;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\t<K extends Comparable<K>> int up(List<K> li, int l, int r, K k) {\n\t\tint R = r, m = 0;\n\t\twhile (l <= r) {\n\t\t\tm = l + r >> 1;\n\t\t    if (m == R) return m;\n\t\t    if (li.get(m).compareTo(k) > 0) \n\t\t    \tr = m - 1;\n\t\t    else \n\t\t    \tl = m + 1;\n\t\t}\n\t\treturn l;\n\t}\n\t\t\n\t<K extends Comparable<K>> int bs(List<K> li, int l, int r, K k) {\n\t\twhile (l <= r) {\n\t\t\tint m = l + r >> 1;\n\t\t    if (li.get(m) == k) return m;\n\t\t    else if (li.get(m).compareTo(k) < 0)\n\t\t    \tl = m + 1;\n\t\t    else \n\t\t    \tr = m - 1;\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tlong calc(int base, int exponent) {\n\t\tif (exponent == 0) return 1;\n\t\tif (exponent == 1) return base % MOD;\n\t\tlong m = calc(base, exponent / 2);\n\t\tif (exponent % 2 == 0) return (m * m) % MOD;\n\t\treturn (base * ((m * m) % MOD)) % MOD;\n\t}\n\t\n\tlong calc(int base, long exponent) {\n\t\tif (exponent == 0) return 1;\n\t\tif (exponent == 1) return base % MOD;\n\t\tlong m = calc(base, exponent / 2);\n\t\tif (exponent % 2 == 0) return (m * m) % MOD;\n\t\treturn (base * ((m * m) % MOD)) % MOD;\n\t}\n\t\n\tlong calc(long base, long exponent) {\n\t\tif (exponent == 0) return 1;\n\t\tif (exponent == 1) return base % MOD;\n\t\tlong m = calc(base, exponent / 2);\n\t\tif (exponent % 2 == 0) return (m * m) % MOD;\n\t\treturn (base * (m * m % MOD)) % MOD;\n\t}\n\t\n\tlong power(int base, int exponent) {\n\t\tif (exponent == 0) return 1;\n\t\tlong m = power(base, exponent / 2);\n\t\tif (exponent % 2 == 0) return m * m;\n\t\treturn base * m * m;\n\t}\n\t\n\tvoid swap(int[] a, int i, int j) {\n\t\ta[i] ^= a[j];\n\t\ta[j] ^= a[i];\n\t\ta[i] ^= a[j];\n\t}\n\t\n\tvoid swap(long[] a, int i, int j) {\n\t\tlong tmp = a[i];\n\t\ta[i] = a[j];\n\t\ta[j] = tmp;\n\t}\n\t\n\tstatic class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>\n\t\t\timplements Comparable<Pair<K, V>> {\n\t\tprivate K k;\n\t\tprivate V v;\n\n\t\tPair() {}\n\n\t\tPair(K k, V v) {\n\t\t\tthis.k = k;\n\t\t\tthis.v = v;\n\t\t}\n\n\t\tK getK() { return k; }\n\n\t\tV getV() { return v; }\n\n\t\tvoid setK(K k) { this.k = k; }\n\n\t\tvoid setV(V v) { this.v = v; }\n\n\t\tvoid setKV(K k, V v) {\n\t\t\tthis.k = k;\n\t\t\tthis.v = v;\n\t\t}\n\n\t\t@SuppressWarnings(\"unchecked\")\n\t\t@Override\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (this == o) return true;\n\t\t\tif (o == null || !(o instanceof Pair)) return false;\n\t\t\tPair<K, V> p = (Pair<K, V>) o;\n\t\t\treturn k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 31;\n\t\t\thash = hash * 89 + k.hashCode();\n\t\t\thash = hash * 89 + v.hashCode();\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair<K, V> pair) {\n\t\t\treturn k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);\n\t\t}\n\n\t\t@Override\n\t\tpublic Pair<K, V> clone() {\n\t\t\treturn new Pair<K, V>(this.k, this.v);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.valueOf(k).concat(\" \").concat(String.valueOf(v)).concat(\"\\n\");\n\t\t}\n\t}\n\n\tstatic class Reader {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer st;\n\n\t\tReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\ttry {\n\t\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\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[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = nextInt();\n\t\t\treturn arr;\n\t\t}\n\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\n\t\tString nextLine() {\n\t\t\tString s = \"\";\n\t\t\ttry {\n\t\t\t\ts = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn s;\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "//>>>BaZ<<<//\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{  \n    static int dx[] = {-1,1,0,0};\n    static int dy[] = {0,0,1,-1};\n    static long MOD = 1000000007;\n    static int INF = Integer.MAX_VALUE/10;\n    static PrintWriter pw;\n    static Reader scan;\n    //static MyFileReader scan;\n    //static MyFileReader1 ss;\n    static int ni() throws IOException{return scan.nextInt();}\n    static long nl() throws IOException{return scan.nextLong();}\n    static double nd() throws IOException{return scan.nextDouble();}\n    static void pl() throws IOException{pw.println();}\n    static void pl(Object o) throws IOException{pw.println(o);}\n    static void p(Object o) throws IOException {pw.print(o+\" \");}\n    static void psb(StringBuilder sb) throws IOException {pw.print(sb);}\n    public static void main(String[] args){\n        new Thread(null,null,\"BaZ\",99999999)\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        Calendar CAL1 = Calendar.getInstance();\n        CAL1.setTime(new Date());\n        scan = new Reader();\n        //scan = new MyFileReader();\n        //ss = new MyFileReader1();\n        pw = new PrintWriter(System.out,true);\n        //pw = new PrintWriter(new File(\"C://Users/Aman deep/Desktop/output.txt\"));  \n        StringBuilder sb = new StringBuilder();\n        int n = ni();\n        int inv = 0;\n        int arr[] = new int[n];\n        for(int i=0;i<n;++i)\n        {\n            arr[i] = ni();\n            for(int j=0;j<i;++j)\n                if(arr[j]>arr[i])\n                    inv = 1-inv;\n        }\n        int q = ni();\n        while(q-->0)\n        {\n            int l = ni();\n            int r = ni();\n            int par = c2(r-l+1);\n            par&=1;\n            if(par!=0)\n                inv = 1-inv;\n            if(inv==0)\n                sb.append(\"even\\n\");\n            else sb.append(\"odd\\n\");\n        }\n        psb(sb);\n        Calendar CAL2 = Calendar.getInstance();\n        CAL2.setTime(new Date());\n        double Execution_Time = (double)(CAL2.getTimeInMillis()-CAL1.getTimeInMillis())/1000.000;\n        //System.out.println(\"Execution time : \"+Execution_Time+\" seconds\");\n        pw.flush();\n        pw.close();\n    }\n    static int c2(int n)\n    {\n        return (n*(n-1))>>1;\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     static class MyFileReader                                          //File input template\n    {\n        StringTokenizer st;\n        BufferedReader br;\n        MyFileReader() throws IOException\n        {\n            br = new BufferedReader(new FileReader(\"C://Users/Aman deep/Desktop/input.txt\"));\n        }\n        String nextLine() throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(nextLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n     static class MyFileReader1                                          //File input template\n    {\n        StringTokenizer st;\n        BufferedReader br;\n        MyFileReader1() throws IOException\n        {\n            br = new BufferedReader(new FileReader(\"C://Users/Aman deep/Desktop/output.txt\"));\n        }\n        String nextLine() throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(nextLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class maestro{\n    public static long inversions(long[] arr) {\n        long x = 0;\n        int n = arr.length;\n        for (int i = n - 2; i >= 0; i--) {\n            for (int j = i + 1; j < n; j++) {\n                if (arr[i] > arr[j]) {\n                    x++;\n                    //temp++;\n                }\n                //if (temp%2==0) inv_a[i][j]=0;\n                //else inv_a[i][j]=1;\n            }\n        }\n        return x;\n    }\n    public static void main(String[] args){\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt();\n        long[] arr = new long[n];\n        for (int i=0;i<n;i++) arr[i] = sc.nextLong();\n        long m = sc.nextLong();\n        long x = inversions(arr)%2;\n        for (int i=0;i<m;i++){\n            int l = sc.nextInt()-1;\n            int r = sc.nextInt()-1;\n            if ((r-l+1)%4>1) x=(x+1)%2;\n            if (x==1) System.out.println(\"odd\");\n            else System.out.println(\"even\");\n        }\n        /*int inv=0;\n        int temp=0;\n        long[][] inv_a = new long[n][n];\n        for (int i=0;i<n;i++){\n            for (int j=0;j<n;j++){\n                inv_a[i][j]=-1;\n            }\n        }\n        for (int i=n-2;i>=0;i--){\n            for (int j=i+1;j<n;j++){\n                if (arr[i]<arr[j]){\n                    inv++;\n                    temp++;\n                }\n                if (temp%2==0) inv_a[i][j]=0;\n                else inv_a[i][j]=1;\n            }\n            temp=0;\n        }\n        if (inv%2==0) inv=0;\n        else inv=1;\n        for (int i=0;i<m;i++){\n            int l = sc.nextInt()-1;\n            int r = sc.nextInt()-1;\n            long[][] exp = new long[r-l+1][r-l+1];\n            for (int k=0;k<exp.length;k++){\n                for (int h=0;h<exp.length;h++){\n                    exp[k][h]=-1;\n                }\n            }\n            for (int j=l;j<=r;j++){\n\n            }\n        }*/\n    }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "//package educational35;\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 ProblemD {\n\t\n\tpublic static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\tpublic static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static StringTokenizer tok = null;\n\n\tpublic static void main(String args[]) throws IOException {\n\t\ttok = new StringTokenizer(in.readLine());\n\t\tint n = Integer.parseInt(tok.nextToken());\n\t\t\n\t\tint tab[] = new int[n]; \n\t\ttok = new StringTokenizer(in.readLine());\n\t\tfor (int i=0; i<n; i++)\n\t\t\ttab[i] = Integer.parseInt(tok.nextToken());\n\t\t\n\t\tint inversions = countInversions(tab);\n\t\tboolean isOdd = inversions % 2 == 1;\n\t\t\n\t\ttok = new StringTokenizer(in.readLine());\n\t\tint k = Integer.parseInt(tok.nextToken());\n\t\t\n\t\tint start, end, len;\n\t\t\n\t\tfor (int i=0; i<k; i++)\t{\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\tstart = Integer.parseInt(tok.nextToken());\n\t\t\tend = Integer.parseInt(tok.nextToken());\n\t\t\t\n\t\t\tlen = (end - start + 1) % 4;\n\t\t\tif (len == 2 || len ==3)\n\t\t\t\tisOdd = !isOdd;\n\t\t\t\n\t\t\tout.println(isOdd ? \"odd\" : \"even\");\n\t\t}\n\t\t\n\t\tout.close();\n\t\t\n\t}\n\t\n\tprivate static int countInversions(int tab[]) {\n\t\tint n = tab.length;\n\t\tint auxTab[] = new int[n+1];\n\t\treturn _countInversions(tab, 0, n, auxTab);\n\t};\n\t\n\tprivate static int _countInversions(int tab[], int start, int end, int auxTab[]) {\n\t\t//indices from start to end; but values from start+1 to end+1 !!\n\t\tif (start+1 >= end)\n\t\t\treturn 0;\n\t\t\n\t\tint mid = (start + end) / 2;\n\t\tint lowerFound = 0;\n\t\tint higherFound = 0;\n\t\t\n\t\tint count = 0;\n\t\t\n\t\tfor (int i=start; i<end; i++){\n\t\t\tif (tab[i] < mid+1){\n\t\t\t\tcount += higherFound;\n\t\t\t\tauxTab[start+lowerFound] = tab[i];\n\t\t\t\tlowerFound++;\n\t\t\t} else {\n\t\t\t\tauxTab[mid + higherFound] = tab[i];\n\t\t\t\thigherFound++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i=start; i<end; i++)\n\t\t\ttab[i] = auxTab[i];\n\t\t\n\t\tcount += _countInversions(tab, start, mid, auxTab);\n\t\tcount += _countInversions(tab, mid, end, auxTab);\n\t\t\n\t\treturn count;\n\t}\n\t\n\t\n\t\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class D {\n\t\n\tpublic void solve(Scanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n + 1];\n\t\tfor(int i = 1; i <= n; ++i) a[i] = in.nextInt();\n\t\t\n\t\tint[] rangeInv = new int[n + 1];\n\n\t\tBIT bit = new BIT(n + 1);\n\t\tfor(int i = 1; i <= n; ++i) {\n\t\t\tint cur = a[i];\n\t\t\tint inv = (int) bit.sum(cur, n);\n\t\t\trangeInv[i] = rangeInv[i - 1] + inv;\n\t\t\tbit.add(cur, 1);\n\t\t}\n\t\t\n\t\tint m = in.nextInt();\n\t\tint curTotal = rangeInv[n];\n\t\t\n\t\tfor(int qq = 0; qq < m; ++qq) {\n\t\t\tint l = in.nextInt();\n\t\t\tint r = in.nextInt();\n\t\t\t\n\t\t\tint N = r - l + 1;\n\t\t\tint total = N * (N - 1) / 2;\n\t\t\t\n\t\t\tint cur = rangeInv[r] - rangeInv[l - 1];\n\t\t\t\n\t\t\tint newInv = total - cur;\n\t\t\t\n\t\t\tcurTotal -= cur;\n\t\t\tcurTotal += newInv;\n\t\t\t\n\t\t\tif(curTotal % 2 == 0) {\n\t\t\t\tout.println(\"even\");\n\t\t\t} else {\n\t\t\t\tout.println(\"odd\");\n\t\t\t}\n\t\t}\n\t\t\n\t}\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\n\t\tnew D().solve(in, out);\n\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tclass BIT {\n\n\t    long[] tree;\n\t    int n;\n\n\t    public BIT(int n) {\n\t        this.n = n;\n\t        tree = new long[n + 1];\n\t    }\n\n\t    public void add(int i, long val)\n\t    {\n\t        while(i <= n)\n\t        {\n\t            tree[i] += val;\n\t            i += i & -i;\n\t        }\n\t    }\n\n\t    public long sum(int to)\n\t    {\n\t        long res = 0;\n\t        for(int i = to; i >= 1; i -= (i & -i))\n\t        {\n\t            res += tree[i];\n\t        }\n\t        return res;\n\t    }\n\n\t    public long sum(int from, int to) {\n\t        return sum(to) - sum(from - 1);\n\t    }\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\n\nimport javafx.util.Pair;\n\nimport java.util.*;\n\nimport static java.lang.Math.floor;\nimport static java.lang.Math.min;\n\npublic class Main {\n\n    private static Scanner scanner = new Scanner(System.in);\n\n    public static void main(String[] args) {\n\n        int n = scanInt();\n        List<Integer> a = scanList(n);\n        int m = scanInt();\n        List<Integer> left = new ArrayList<>();\n        List<Integer> right = new ArrayList<>();\n        for (int i = 0; i < m; i++) {\n            left.add(scanInt());\n            right.add(scanInt());\n        }\n\n        String even = \"even\";\n        String odd = \"odd\";\n\n        int inversions = 0;\n        for (int i = 0; i < a.size(); i++) {\n            for (int j = i; j < a.size(); j++) {\n                if (a.get(i) > a.get(j)) {\n                    ++inversions;\n                }\n            }\n        }\n\n        inversions = inversions % 2;\n        for (int i = 0; i < m; i++) {\n            inversions = (inversions + (right.get(i) - left.get(i) + 1) / 2 % 2) % 2;\n            println(inversions % 2 == 0 ? even : odd);\n        }\n\n\n    }\n\n    private static Integer get(int digit, List<Integer> numbers) {\n        Integer toReturn = null;\n        for (Integer number : numbers\n                ) {\n            if (number <= digit) {\n                toReturn = number;\n                break;\n            }\n        }\n        return toReturn;\n\n    }\n\n    private static List<Integer> toList(char[] chars) {\n        List<Integer> integers = new ArrayList<>();\n        for (int i = 0; i < chars.length; i++) {\n            integers.add(Integer.parseInt(String.valueOf(chars[i])));\n        }\n        return integers;\n    }\n\n    private static List<Pair<Integer, Integer>> scanPairs(int amount) {\n        List<Pair<Integer, Integer>> list = new ArrayList<>();\n        for (int i = 0; i < amount; i++) {\n            list.add(new Pair<>(scanInt(), scanInt()));\n        }\n        return list;\n    }\n\n    private static int[] scanArray(int length) {\n        int array[] = new int[length];\n        for (int i = 0; i < length; i++) {\n            array[i] = scanner.nextInt();\n        }\n        return array;\n    }\n\n    private static List<Integer> scanList(int length) {\n        List<Integer> integers = new ArrayList<>();\n        for (int i = 0; i < length; i++) {\n            integers.add(scanner.nextInt());\n        }\n        return integers;\n    }\n\n    public static String scanString() {\n        return scanner.next();\n    }\n\n    private static int scanInt() {\n        return scanner.nextInt();\n    }\n\n    private static void println(int n) {\n        System.out.println(n);\n    }\n\n    private static void print(int n) {\n        System.out.print(n);\n    }\n\n    private static void println(String s) {\n        System.out.println(s);\n    }\n\n    private static void print(String s) {\n        System.out.print(s);\n    }\n\n    private static void print(int a[]) {\n        for (int i = 0; i < a.length; i++) {\n            System.out.print(a[i] + \" \");\n        }\n    }\n\n}\n\n\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n\npublic class Main {\n    static int bit[];\n    static int array[];\n    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        bit = new int[1505];\n        array = new int[n + 1];\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        for(int i = 1;i <= n;i++)\n            array[i] = Integer.parseInt(st.nextToken());\n        long ans = 0;\n        for(int i = n;i >= 1;i--){\n            ans += read(array[i]);\n            update(array[i]);\n        }\n        long val = (ans & 1) + 1000_000;\n        int m = Integer.parseInt(br.readLine());\n        StringBuilder sb = new StringBuilder();\n        for(int i = 1;i <= m;i++){\n            st = new StringTokenizer(br.readLine());\n            int l = Integer.parseInt(st.nextToken());\n            int r = Integer.parseInt(st.nextToken());\n            long temp = (r - l + 1);\n            temp = temp*(temp - 1) / 2;\n            if((temp & 1) == 1)--val;\n            if((val & 1) == 1)sb.append(\"odd\");\n            else sb.append(\"even\");\n            sb.append('\\n');\n        }\n        System.out.print(sb);\n    }\n    static int update(int idx){\n        int sum = 0;\n        while(idx < 1501){\n            bit[idx] += 1;\n            idx += idx & (-idx);\n        }\n        return sum;\n    }\n    static int read(int idx){\n        int sum = 0;\n        while(idx > 0){\n            sum += bit[idx];\n            idx -= idx & (-idx);\n        }\n        return sum;\n    }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] ar = new int[n];\n            for (int i = 0; i < n; i++) {\n                ar[i] = in.nextInt();\n            }\n            long ninv = 0;\n            for (int i = 0; i < n - 1; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    if (ar[i] > ar[j])\n                        ninv++;\n                }\n            }\n            int m = in.nextInt();\n            for (int i = 0; i < m; i++) {\n                int l = in.nextInt();\n                int r = in.nextInt();\n\n                int s = (r - l) * (r - l + 1) / 2;\n\n                ninv += s;\n\n                if (ninv % 2 == 0)\n                    out.println(\"even\");\n                else\n                    out.println(\"odd\");\n            }\n        }\n\n    }\n\n    static class InputReader {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public InputReader(InputStream is) {\n            BufferedReader br = new BufferedReader(new InputStreamReader(is));\n            this.br = br;\n        }\n\n        public String next() {\n            if (st == null || !st.hasMoreTokens()) {\n                String nextLine = null;\n                try {\n                    nextLine = br.readLine();\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                if (nextLine == null)\n                    return null;\n                st = new StringTokenizer(nextLine);\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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 Pradyumn\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = in.nextIntArray(n);\n            int ct = 0;\n            for (int i = 0; i < n; ++i) {\n                for (int j = i + 1; j < n; ++j) {\n                    if (a[i] > a[j]) ++ct;\n                }\n            }\n            ct &= 1;\n            int Q = in.nextInt();\n            for (int q = 0; q < Q; ++q) {\n                int l = in.nextInt();\n                int r = in.nextInt();\n                int size = (r - l + 1) * (r - l) >> 1;\n                ct ^= size & 1;\n                out.println(ct % 2 == 0 ? \"even\" : \"odd\");\n            }\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\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        int initial = 0;\n        for (int i = 0; i < n; i++) arr[i] = Reader.nextInt();\n\n        for (int i = 0; i < arr.length; i++) {\n            for (int j = i + 1; j < arr.length; j++) if (arr[i] > arr[j]) initial++;\n        }\n\n        int m = Reader.nextInt();\n        boolean parity = initial % 2 == 0;\n//        System.out.println(parity ? \"even\": \"odd\");\n        for (int i = 0; i < m; i++) {\n            int l = Reader.nextInt();\n            int r = Reader.nextInt();\n            int elems = r - l + 1;\n            boolean change = (elems/2) % 2 == 0;\n            parity = parity == change;\n            System.out.println(parity ? \"even\": \"odd\");\n        }\n    }\n}\n\n/**\n * Reader class based on the article at \"https://www.cpe.ku.ac.th/~jim/java-io.html\"\n * */\nclass Reader{\n    private static BufferedReader reader;\n    private static StringTokenizer tokenizer;\n    static void init(InputStream inputStream){\n        reader = new BufferedReader(new InputStreamReader(inputStream));\n        tokenizer = new StringTokenizer(\"\");\n    }\n    static String next() throws IOException {\n        String read;\n        while (!tokenizer.hasMoreTokens()){\n            read = reader.readLine();\n            if (read == null || read.equals(\"\"))\n                return \"-1\";\n            tokenizer = new StringTokenizer(read);\n        }\n\n        return tokenizer.nextToken();\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    //Get a whole line.\n//    static String line() throws IOException{\n//        return reader.readLine();\n//    }\n//\n//    static double nextDouble() throws IOException{return Double.parseDouble(next());}\n}\n\n\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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 void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.readInt();\n            int[] a = IOUtils.readIntArray(in, n);\n            MiscUtils.decreaseByOne(a);\n            int m = in.readInt();\n            int parity = inversions(a) % 2;\n            boolean[] lengthToParityFlip = new boolean[n + 1];\n            for (int length = 1; length < lengthToParityFlip.length; length++) {\n                lengthToParityFlip[length] = (((length * (length - 1) / 2) % 2) == 1);\n            }\n            for (int query = 0; query < m; query++) {\n                int l = in.readInt() - 1, r = in.readInt() - 1;\n                int length = r - l + 1;\n                if (lengthToParityFlip[length]) {\n                    parity ^= 1;\n                }\n                out.printLine(parity == 0 ? \"even\" : \"odd\");\n            }\n        }\n\n        private int inversions(int[] a) {\n            int res = 0;\n            for (int j = 0; j < a.length; j++) {\n                for (int i = j + 1; i < a.length; i++) {\n                    if (a[i] < a[j]) {\n                        res++;\n                    }\n                }\n            }\n            return res;\n        }\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int readInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void 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    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    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}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class utkarsh{\n\tBufferedReader br;\n\tPrintWriter out;\n\n\tint game(int s, int mid, int e, int[] a){\n\t\tint i, j, n, m;\n\t\tn = mid - s + 1;\n\t\tm = e - mid;\n\t\tint b[] = new int[n];\n\t\tint c[] = new int[m];\n\t\tfor(i = 0; i < n; i++)\tb[i] = a[s + i];\n\t\tfor(j = 0; j < m; j++)\tc[j] = a[mid + 1 + j];\n\t\ti = j = 0;\n\t\tint ans = 0;\n\t\tfor(int k = s; k <= e; k++){\n\t\t\tif(i == n){\n\t\t\t\ta[k] = c[j++];\n\t\t\t}else if(j == m){\n\t\t\t\ta[k] = b[i++];\n\t\t\t}else{\n\t\t\t\tif(b[i] < c[j]){\n\t\t\t\t\ta[k] = b[i++];\n\t\t\t\t}else{\n\t\t\t\t\ta[k] = c[j++];\n\t\t\t\t\tans += n - i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\n\tint play(int s, int e, int[] a){\n\t\tif(s >= e)\treturn 0;\n\t\tint m = (s + e) >> 1;\n\t\treturn play(s, m, a) + play(m+1, e, a) + game(s, m, e, a);\n\t}\n\n\tvoid solve(){\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tint i, j, k, l, r, n;\n\t\tn = ni();\n\t\tint a[] = new int[n];\n\t\tint d[] = new int[n];\n\t\tfor(i = 0; i < n; i++) {\n\t\t\ta[i] = ni();\n\t\t\td[i] = a[i];\n\t\t}\n\t\tint ans = (play(0, n-1, d) & 1);\n\n\t\tint q = ni();\n\t\twhile(q-- > 0){\n\t\t\tl = ni();\tr = ni();\n\t\t\tans ^= ((r - l + 1) * (r - l) / 2);\n\t\t\t//out.println(ans);\n\t\t\tif((ans & 1) > 0)\tout.println(\"odd\");\n\t\t\telse\t\t\t\tout.println(\"even\");\n\t\t}\n\n\t\tout.flush();\n\t}\n\n\tint ni(){\n\t\treturn Integer.parseInt(ns());\n\t}\n\n\tString ip[];\n\tint len, sz;\n\n\tString ns(){\n\t\tif(len >= sz){\n\t\t\ttry{\n\t\t\t\tip = br.readLine().split(\" \");\n\t\t\t\tlen = 0;\n\t\t\t\tsz = ip.length;\n\t\t\t}catch(IOException e){\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif(sz <= 0)\treturn \"-1\";\n\t\t}\n\t\treturn ip[len++];\n\t}\n\n\tpublic static void main(String[] args){\tnew utkarsh().solve();\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CODEFORCES\n{\n\t@SuppressWarnings(\"rawtypes\")\n\tstatic InputReader in;\n\tstatic PrintWriter out;\n\n\tstatic void solve()\n\t{\n\t\tint n = in.ni();\n\t\tint arr[] = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = in.ni();\n\t\tint cnt = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < i; j++)\n\t\t\t\tif (arr[j] > arr[i])\n\t\t\t\t\tcnt++;\n\t\t}\n\t\tcnt %= 2;\n\t\tint m = in.ni();\n\t\twhile (m-- > 0)\n\t\t{\n\t\t\tint l = in.ni(), r = in.ni();\n\t\t\tint fin = r - l + 1;\n\t\t\tfin *= (fin - 1);\n\t\t\tfin >>= 1;\n\t\t\tif ((fin & 1) == 1)\n\t\t\t\tcnt++;\n\t\t\tcnt %= 2;\n\t\t\tif ((cnt & 1) == 1)\n\t\t\t\tout.println(\"odd\");\n\t\t\telse\n\t\t\t\tout.println(\"even\");\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"rawtypes\")\n\tstatic void soln()\n\t{\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.flush();\n\t}\n\n\tstatic void debug(Object... o)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tpublic static void main(String[] args)\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\tsoln();\n\t\t\t\t} catch (Exception e)\n\t\t\t\t{\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t}\n\n\t// To Get Input\n\t// Some Buffer Methods\n\tstatic class InputReader<SpaceCharFilter>\n\t{\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{\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic int snext()\n\t\t{\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} 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 (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{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nl()\n\t\t{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\ta[i] = ni();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong a[] = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\ta[i] = nl();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String readString()\n\t\t{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo\n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine()\n\t\t{\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo\n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c)\n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c)\n\t\t{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter\n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class D911 {\n\n\tpublic static long total = 0;\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tArrayList<Integer> temp = new ArrayList<>();\n\t\tint[] ar = new int[n];\n\t\tint[] memo = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint t = in.nextInt();\n\t\t\tint index = -1*Collections.binarySearch(temp, t)-1;\n\t\t\ttemp.add(index, t);\n\t\t\tar[i] = t;\n\t\t\tmemo[i] = i - index;\n\t\t\ttotal += memo[i];\n\t\t}\n\t\tint m = in.nextInt();\n\t\tfor (int i = 0; i < m; i++) {\n//\t\t\tint a = in.nextInt() - 1, b = in.nextInt() - 1;\n//\t\t\tquery(ar, memo, in.nextInt() - 1, in.nextInt() - 1);\n\t\t\ttotal += (-1*(in.nextInt() - 1 - in.nextInt() + 1) + 1) / 2;\n\t\t\tSystem.out.println(total%2 == 0 ? \"even\" : \"odd\");\n\t\t}\n\t}\n\t\n\tpublic static void query(int[] ar, int[] memo, int a, int b) {\n\t\tif (a >= b) {\n\t\t\treturn;\n\t\t}\n\t\tif (ar[a] < ar[b]) {\n\t\t\tmemo[a]++;\n\t\t\ttotal++;\n\t\t} else {\n\t\t\tmemo[b]--;\n\t\t\ttotal--;\n\t\t}\n\t\tint t = ar[a];\n\t\tar[b] = ar[a];\n\t\tar[b] = t;\n\t\tt = memo[a];\n\t\tmemo[b] = memo[a];\n\t\tmemo[b] = t;\n\t\tquery(ar, memo, a + 1, b - 1);\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class P911d {\n\n  private static void solve() {\n    int n = nextInt();\n\n    int[] a = new int[n];\n    for (int i = 0; i < n; i++) {\n      a[i] = nextInt();\n    }\n\n    int cnt = 0;\n    for (int i = 0; i < n; i++) {\n      for (int j = i + 1; j < n; j++) {\n        if (a[i] > a[j]) {\n          cnt++;\n        }\n      }\n    }\n\n    cnt %= 2;\n\n    int m = nextInt();\n    for (int i = 0; i < m; i++) {\n      int l = nextInt();\n      int r = nextInt();\n\n      int size = r - l + 1;\n      long sum = ((long)size * (size - 1)) / 2;\n\n      sum %= 2;\n\n      cnt += sum;\n      cnt %= 2;\n\n      System.out.println(cnt == 0 ? \"even\" : \"odd\");\n    }\n  }\n\n  private static void run() {\n    br = new BufferedReader(new InputStreamReader(System.in));\n    out = new PrintWriter(System.out);\n\n    solve();\n\n    out.close();\n  }\n\n  private static StringTokenizer st;\n  private static BufferedReader br;\n  private static PrintWriter out;\n\n  private static String next() {\n    while (st == null || !st.hasMoreElements()) {\n      String s;\n      try {\n        s = br.readLine();\n      } catch (IOException e) {\n        return null;\n      }\n      st = new StringTokenizer(s);\n    }\n    return st.nextToken();\n  }\n\n  private static int nextInt() {\n    return Integer.parseInt(next());\n  }\n\n  private static long nextLong() {\n    return Long.parseLong(next());\n  }\n\n  public static void main(String[] args) {\n    run();\n  }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*; \nimport java.util.*;\nimport java.util.regex.*;\n\n/*\n\t\t  br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t  pw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\t\t  br = new BufferedReader(new InputStreamReader(System.in));\n\t\t  pw = 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 {\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 n = readInt();\n\t\t\tint[] l = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tl[i] = readInt();\n\t\t\t}\n\t\t\tint ret = 0;\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tfor(int j = i+1; j < n; j++) {\n\t\t\t\t\tif(l[i] > l[j]) {\n\t\t\t\t\t\tret++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint qqq = readInt();\n\t\t\twhile(qqq-- > 0) {\n\t\t\t\tint a = readInt();\n\t\t\t\tint b = readInt();\n\t\t\t\tint d = b-a;\n\t\t\t\tret ^= d*(d+1)/2;\n\t\t\t\tpw.println(ret%2 == 0 ? \"even\" : \"odd\");\n\t\t\t}\n\t\t}\n\t\texitImmediately();\n\t}\n\n\tprivate static void exitImmediately() {\n\t\tpw.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static long readLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextLine() throws IOException  {\n\t\tString s = br.readLine();\n\t\tif(s == null) {\n\t\t\texitImmediately();\n\t\t}\n\t\tst = null;\n\t\treturn s;\n\t}\n\n\tprivate static String nextToken() throws IOException  {\n\t\twhile(st == null || !st.hasMoreTokens())  {\n\t\t\tst = new StringTokenizer(nextLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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        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.nextInt(), i, a[] = new int[N];\n            int rev[] = new int[N];\n            for (i = 0; i < N; i++) {\n                a[i] = in.nextInt();\n                rev[N - i - 1] = a[i];\n            }\n            long[][] inverse = inversions(a, N);\n            long[][] revInverse = inversions(rev, N);\n            int q = in.nextInt();\n            long inversions = inverse[0][N - 1] % 2;\n            while (q-- > 0) {\n                int left = in.nextInt() - 1, right = in.nextInt() - 1;\n                int length = right - left + 1;\n                length = length * (length - 1) / 2;\n                if (length % 2 == 1) {\n                    inversions = 1 - inversions;\n                }\n                if (inversions % 2 == 0) {\n                    out.printLine(\"even\");\n                } else {\n                    out.printLine(\"odd\");\n                }\n            }\n            //DebugUtils.debug(inverse);\n        }\n\n        public long[][] inversions(int a[], int N) {\n            int x[][] = new int[N][N];\n            int i, j;\n            for (i = 0; i < N; i++) {\n                for (j = i + 1; j < N; j++) {\n                    if (a[i] > a[j]) {\n                        x[i][j] = 1;\n                    }\n                }\n            }\n            int colSum[][] = new int[N][N];\n            for (i = 0; i < N; i++) {\n                colSum[0][i] = x[0][i];\n                for (j = 1; j < N; j++) {\n                    colSum[j][i] = colSum[j - 1][i] + x[j][i];\n                }\n            }\n            long inverse[][] = new long[N][N];\n            for (int length = 2; length <= N; length++) {\n                j = length - 1;\n                i = 0;\n                while (j < N) {\n                    inverse[i][j] = inverse[i][j - 1] + colSum[i + length - 1][j];\n                    if (i > 0) {\n                        inverse[i][j] -= colSum[i - 1][j];\n                    }\n                    i++;\n                    j++;\n                }\n            }\n            return inverse;\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Mainn {\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 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 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\tint n = scn.nextInt(), inv = 0;\n\t\tint[] arr = scn.nextIntArr(n);\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(arr[i] > arr[j]) {\n\t\t\t\t\tinv++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ans = inv % 2;\n\t\t\n\t\tint m = scn.nextInt();\n\t\twhile(m-- > 0) {\n\t\t\tint l = scn.nextInt(), r = scn.nextInt();\n\t\t\t\n\t\t\tint change = ((r - l + 1) / 2) % 2;\n\t\t\t\n\t\t\tif(change == 1) {\n\t\t\t\tans = 1 - ans;\n\t\t\t}\n\t\t\t\n\t\t\tif(ans == 0) {\n\t\t\t\tout.println(\"even\");\n\t\t\t} else {\n\t\t\t\tout.println(\"odd\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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 D {\n\t\n\tpublic static class BIT {\n\t\tint[] dat;\n\t\t\n\t\tpublic BIT(int n){\n\t\t\tdat = new int[n + 1];\n\t\t}\n\t\t\n\t\tpublic void add(int k, int a){ // k : 0-indexed\n\t\t\tfor(int i = k + 1; i < dat.length; i += i & -i){\n\t\t\t\tdat[i] += a;\t\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int sum(int s, int t){ // [s, t)\n\t\t\tif(s > 0) return sum(0, t) - sum(0, s);\n\t\t\t\n\t\t\tint ret = 0;\n\t\t\tfor(int i = t; i > 0; i -= i & -i) {\n\t\t\t\tret += dat[i];\n\t\t\t}\n\t\t\treturn ret;\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 int N = sc.nextInt();\n\t\t\tint[] array = new int[N];\n\t\t\tfor(int i = 0; i < N; i++){\n\t\t\t\tarray[i] = sc.nextInt() - 1;\n\t\t\t}\n\t\t\t\n\t\t\tlong inv = 0;\n\t\t\tBIT bit = new BIT(N);\n\t\t\tfor(int i = 0; i < N; i++){\n\t\t\t\tinv += bit.sum(array[i], N);\n\t\t\t\tbit.add(array[i], 1);\n\t\t\t}\n\t\t\t//System.out.println(inv);\n\t\t\t\n\t\t\tint mod2 = (int)(inv % 2);\n\t\t\tfinal int M = sc.nextInt();\n\t\t\tfor(int i = 0; i < M; i++){\n\t\t\t\tfinal int l = sc.nextInt() - 1;\n\t\t\t\tfinal int r = sc.nextInt() - 1;\n\t\t\t\t\n\t\t\t\tfinal long size = (r - l) + 1;\n\t\t\t\tif(size > 1){\n\t\t\t\t\t//System.out.println(size + \" \" + ((size * (size - 1) / 2)));\n\t\t\t\t\tif((size * (size - 1) / 2) % 2 == 1){\n\t\t\t\t\t\tmod2 = 1 - mod2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tSystem.out.println((mod2 == 0) ? \"even\" : \"odd\");\n\t\t\t}\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A{\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tpublic void solve(){\n\t\tint n=ni();\n\t\tint ans=0;\n\t\tint[] arr=na(n);\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(arr[i] > arr[j]){\n\t\t\t\t\tans^=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint m=ni();\n\t\twhile(m-->0){\n\t\t\tint a=ni(), b=ni();\n\t\t\tint diff=Math.abs(a-b)+1;\n\t\t\tans = ans ^ ((((diff-1)*diff)/2)%2);\n\t\t\tout.println(ans==0 ? \"even\" : \"odd\");\n\t\t}\n\t}\n\n\tvoid print(int n, long[][] memo){\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(memo[i][j]+\" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n\n\tvoid run(){\n\t\tis = new DataInputStream(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tint t=1;while(t-->0)solve();\n\t\tout.flush();\n\t}\n\tpublic static void main(String[] args)throws Exception{new A().run();}\n\t//Fast I/O code is copied from uwi code.\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\tprivate int readByte(){\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\tprivate String ns(){\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\tprivate char[] ns(int n){\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\tprivate char[][] nm(int n, int m){\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\tprivate int[] na(int n){\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\tprivate int ni(){\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\tprivate long nl(){\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\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\tstatic  int i(long x){return (int)Math.round(x);}\n\tstatic class Pair implements Comparable<Pair>{\n\t\tlong fs,sc;\n\t\tPair(long a,long b){\n\t\t\tfs=a;sc=b;\n\t\t}\n\t\tpublic int compareTo(Pair p){\n\t\t\tif(this.fs>p.fs)return 1;\n\t\t\telse if(this.fs<p.fs)return -1;\n\t\t\telse{\n\t\t\t\treturn i(this.sc-p.sc);\n\t\t\t}\n\t\t\t//return i(this.sc-p.sc);\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn \"(\"+fs+\",\"+sc+\")\";\n\t\t}\t\n\t}\n\t\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int l, r, sum = 0;\n            int[] a = new int[n+5];\n            for (int i = 0; i < n; i++) a[i] = in.nextInt();\n            for (int i = 0; i < n; i++)\n                for (int j = i+1; j < n; j++)\n                    if (a[i] > a[j]) sum++;\n            int q = in.nextInt();\n            while (q-- > 0){\n                l = in.nextInt();\n                r = in.nextInt();\n                sum += (r-l+1)/2;\n                if (sum % 2 == 1) out.println(\"odd\");\n                else out.println(\"even\");\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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        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 in, PrintWriter out) {\n            int n = in.nextInt();\n            int l, r, sum = 0;\n            int[] a = new int[n+5];\n            for (int i = 0; i < n; i++) a[i] = in.nextInt();\n            for (int i = 0; i < n; i++)\n                for (int j = i+1; j < n; j++)\n                    if (a[i] > a[j]) sum++;\n            int q = in.nextInt();\n            while (q-- > 0){\n                l = in.nextInt();\n                r = in.nextInt();\n                sum += (r-l+1)/2;\n                if (sum % 2 == 1) out.println(\"odd\");\n                else out.println(\"even\");\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\t  \t\t \t \t\t \t\t\t      \t  \t\t\t    \t", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "/**\n p * @author prakhar28\n *\n */\nimport java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\n\nimport java.io.IOException;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\npublic class Main{\n\t\n\tstatic class Reader\n    {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n \n        public Reader()\n        {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n \n        public Reader(String file_name) throws IOException\n        {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n \n        public String readLine() throws IOException\n        {\n            byte[] buf = new byte[200005]; // line length+1\n            int cnt = 0, c;\n            while ((c = read()) != -1)\n            {\n                if (c == '\\n' || c==' ') {\n                \t//buf[cnt++]=(byte)c;\n                    break;\n                }\n                buf[cnt++] = (byte) c;\n            }\n            return new String(buf, 0, cnt);\n        }\n \n        public int nextInt() throws IOException\n        {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do\n            {\n                ret = ret * 10 + c - '0';\n            }  while ((c = read()) >= '0' && c <= '9');\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        public long nextLong() throws IOException\n        {\n            long ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        public double nextDouble() throws IOException\n        {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n \n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n \n            if (c == '.')\n            {\n                while ((c = read()) >= '0' && c <= '9')\n                {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        private void fillBuffer() throws IOException\n        {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n            if (bytesRead == -1)\n                buffer[0] = -1;\n        }\n \n        private byte read() throws IOException\n        {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n \n        public void close() throws IOException\n        {\n            if (din == null)\n                return;\n            din.close();\n        }\n    }\n\t\n\tstatic class FastScanner {\n\n\t    private final BufferedReader bufferedReader;\n\t    private StringTokenizer stringTokenizer;\n\n\t    public FastScanner() {\n\t        bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n\t    }\n\n\t    public String next() {\n\t        while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {\n\t            try {\n\t                stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n\t            } catch (IOException e) {\n\t                throw new RuntimeException(\"Can't read next value\", e);\n\t            }\n\t        }\n\t        return stringTokenizer.nextToken();\n\t    }\n\n\t    public int nextInt() {\n\t        return Integer.parseInt(next());\n\t    }\n\n\t    public long nextLong() {\n\t        return Long.parseLong(next());\n\t    }\n\n\t    public double nextDouble() {\n\t        return Double.parseDouble(next());\n\t    }\n\n\t    public String nextLine(){\n\t        String str = \"\";\n\t        try {\n\t            str = bufferedReader.readLine();\n\t        } catch (IOException e) {\n\t            e.printStackTrace();\n\t        }\n\t        return str;\n\t    }\n\t}\n\t\n\tstatic void closeall() throws IOException{\n\t\tprintWriter.close();\n\t\tsc.close();\n\t\tin.close();\n\t}\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic Reader in = new Reader();\n\tstatic FastScanner fastScanner = new FastScanner();\n\tstatic PrintWriter printWriter = new PrintWriter(new BufferedOutputStream(System.out));\n\tstatic BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\n\tstatic long INF = (long)(1e18);\n\n\t\n\tint V,E;\n\tArrayList<Integer> adj[];\n\tHashMap<Integer,Integer> path;\n\tMain(){\n\t}\n\tMain(int v,int e){\n\t\tV=v;\n\t\tE=e;\n\t\tadj=new ArrayList[v];\n\t\tpath = new HashMap<Integer,Integer>();\n\t\tfor(int i=0;i<v;i++)\n\t\t\tadj[i] = new ArrayList<>();\n\t}\n\tvoid addEdge(int u,int v){\n\t\tadj[u].add(v);\n\t\tadj[v].add(u);\n\t}\n\t\n\t\n\tstatic long power(long a,long k)\n\t{\n\t\tlong m = 1000000007;\n\t    long ans=1;\n\t    long tmp=a%m;\n\t    while(k>0)\n\t    {\n\t        if(k%2==1)\n\t        \tans=ans*tmp%m;\n\t        tmp=tmp*tmp%m;\n\t        k>>=1;\n\t    }\n\t    return ans;\n\t}\n\t\n\tstatic class Pair /*implements Comparable<Pair>*/{\n\t\tlong F,S;\n\t\tPair(long x,long y){\n\t\t\tF = x;\n\t\t\tS = y;\n\t\t}\n\t\t/*public int compareTo(Pair ob){\n\t\t\treturn this.num-ob.num;\n\t\t}*/\n\t\t\n\t}\n\tstatic long gcd(long a,long b) {\n\t\tif(a<b) {\n\t\t\tlong t = a;\n\t\t\ta = b;\n\t\t\tb = t;\n\t\t}\n\t\tlong r = a%b;\n\t\tif(r==0)\n\t\t\treturn b;\n\t\treturn gcd(b,r);\n\t}\n\t\n\tstatic int lower_bound(int[] a,int low,int high,int val) {\n\t\twhile(low!=high) {\n\t\t\tint mid = (low+high)/2;\n\t\t\tif(a[mid]<val)\n\t\t\t\tlow=mid+1;\n\t\t\telse\n\t\t\t\thigh=mid;\n\t\t}\n\t\treturn low;\n\t}\n\t\n\tstatic int max(int a,int b) {\n\t\treturn (int)Math.max(a, b);\n\t}\n\tstatic long max(long a,long b) {\n\t\treturn (long)Math.max(a, b);\n\t}\n\tstatic int min(int a,int b) {\n\t\tif(a<b)\n\t\t\treturn a;\n\t\treturn b;\n\t}\n\tstatic long mod = 1000000007;\n\t\n\tpublic static void main(String args[])throws IOException{\n\t\tint n = 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\tint inv = 0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<i;j++) {\n\t\t\t\tif(a[j]>a[i])\n\t\t\t\t\tinv++;\n\t\t\t}\n\t\t}\n\t\tinv%=2;\n\t\tint q = in.nextInt();\n\t\tfor(int i=0;i<q;i++) {\n\t\t\tint l = in.nextInt();\n\t\t\tint r = in.nextInt();\n\t\t\tint num = r-l+1;\n\t\t\tinv=(inv+num*(num-1)/2)%2;\n\t\t\tif(inv==0)\n\t\t\t\tprintWriter.println(\"even\");\n\t\t\telse\n\t\t\t\tprintWriter.println(\"odd\");\n\t\t}\n\t\tcloseall();\n\t}\n} ", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\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_Edu_Round_35 {\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            data[i] = in.nextInt();\n        }\n        FT tree = new FT(n + 1);\n        int result = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            tree.update(data[i], 1);\n            result += tree.get(data[i] - 1);\n            result %= 2;\n        }\n        int q = in.nextInt();\n        int[] tmp = new int[n];\n        for (int i = 0; i < q; i++) {\n            int l = in.nextInt() - 1;\n            int r = in.nextInt() - 1;\n            FT a = new FT(n + 1);\n            int total = r - l + 1;\n            total = total * (total - 1) / 2;\n            total %= 2;\n//            for (int j = r; j >= l; j--) {\n//                tmp[j] = data[j];\n//                a.update(data[j], 1);\n//                total -= a.get(data[j] - 1);\n//               // total += 2;\n//               // total %= 2;\n//            }\n            \n            // System.out.println(\"PRE \" + result);\n            // System.out.println(Arrays.toString(tmp));\n//            for (int j = 0; j < (r - l + 1) / 2; j++) {\n//                data[r - j] = tmp[l + j];\n//                data[l + j] = tmp[r - j];\n//            }\n            result += total;\n            result %= 2;\n           // System.out.println(\"AFTER \" + result);\n           // System.out.println(Arrays.toString(data));\n            if (result % 2 == 0) {\n                out.println(\"even\");\n            } else {\n                out.println(\"odd\");\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    public static class Point implements Comparable<Point> {\n\n        int x, y;\n\n        public Point(int start, int end) {\n            this.x = start;\n            this.y = end;\n        }\n\n        @Override\n        public int hashCode() {\n            int hash = 5;\n            hash = 47 * hash + this.x;\n            hash = 47 * hash + this.y;\n            return hash;\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            if (obj == null) {\n                return false;\n            }\n            if (getClass() != obj.getClass()) {\n                return false;\n            }\n            final Point other = (Point) obj;\n            if (this.x != other.x) {\n                return false;\n            }\n            if (this.y != other.y) {\n                return false;\n            }\n            return true;\n        }\n\n        @Override\n        public int compareTo(Point o) {\n            return Integer.compare(x, o.x);\n        }\n    }\n\n    public static class FT {\n\n        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                data[index] %= 2;\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                result %= 2;\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\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 EndUser\n */\npublic class E35PD {\n    public static void main(String[] args) throws IOException {\n        Scanner in = new Scanner(System.in);\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        int count = 0;\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = i + 1; j < n; j++) {\n                if (a[i] > a[j]) {\n                    count++;\n                }\n            }            \n        }\n        \n        boolean isEven = (count % 2 == 0);\n        \n        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n        int m = in.nextInt();\n        for (int i = 0; i < m; i++) {\n            int l = in.nextInt();\n            int r = in.nextInt();\n            int size = (r - l) + 1;\n            int numOfConn = (size - 1) * size / 2;\n            if (numOfConn % 2 == 1) {\n                isEven = !isEven;\n            }\n            if (isEven) {\n                out.write(\"even\");\n                out.newLine();\n            } else {\n                out.write(\"odd\");\n                out.newLine();\n            }\n        }\n        out.close();\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\npublic class Main {\n    public static void main(String[] args) {\n    \tScanner in=new Scanner(System.in);  \n    \tint n=in.nextInt();\n    \tint a[]=new int[n];\n    \tfor(int i=0; i<n; i++)\n    \t\ta[i]=in.nextInt();\n    \tlong no=0;\n    \tfor(int i=0; i<n-1; i++)\n    \t{\n    \t\tfor(int j=i+1; j<n; j++)\n    \t\t{\n    \t\t\tif(a[i]>a[j])\n    \t\t\t\tno++;\n    \t\t}\n    \t}\n   // \tSystem.out.println(no);\n    \tno%=2;\n    \tint m=in.nextInt();\n    \tint te;\n    \tString te2=\"odd\",te1=\"even\";\n    \tfor(int i=0; i<m; i++)\n    \t{\n    \t\tte=in.nextInt()-in.nextInt();\n    \t\tte=-te+1;\n    //\t\tSystem.out.println(te);\n    \t\tif((te*(te-1)/2)%2==0)\n    \t\t{\n    //\t\t\tSystem.out.println(\"HOLA\"+no);\n    \t\t\tif(no==0)\n    \t\t\t\tSystem.out.println(\"even\");\n    \t\t\telse\n    \t\t\t\tSystem.out.println(\"odd\");\n    \t\t}\n    \t\telse\n    \t\t{\n    \t\t\tno=(no+1)%2;\n    \t\t\tif(no==0)\n    \t\t\t\tSystem.out.println(\"even\");\n    \t\t\telse\n    \t\t\t\tSystem.out.println(\"odd\");\n    \t\t}\n    \t}\n    \t\n    }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CE35D {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t//Scanner sc = new Scanner(System.in);\n\t\tBufferedReader sc = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint n = Integer.parseInt(sc.readLine());\n\t\tString[] t = sc.readLine().split(\" \");\n\t\tint[] list = new int[n];\n\t\tfor(int x=0; x<n; x++){\n\t\t\tlist[x] = Integer.parseInt(t[x]);\n\t\t}\n\t\t\n\t\tboolean even = true;\n\t\t\n\t\tint[] indList = new int[n+1];\n\t\t\n\t\t\n\t\tfor(int x=0; x<n; x++){\n\t\t\tindList[list[x]] = x;\n\t\t}\n\t\t\n\t\tfor(int x=1; x<=n; x++){\n\t\t\tint theIndex = indList[x];\n\t\t\tint other = list[x-1];\n\t\t\tif(theIndex != x-1){\n\t\t\t\teven = !even;\n\n\t\t\t\tlist[x-1] = x;\n\t\t\t\tlist[theIndex] = other;\n\t\t\t\t\n\t\t\t\tindList[x] = x-1;\n\t\t\t\tindList[other] = theIndex;\n\t\t\t}\n\t\t}\n\t\t\n\t\t//System.out.println(even);\n\t\t\n\t\tint numQ = Integer.parseInt(sc.readLine());\n\t\tfor(int x=0; x<numQ; x++){\n\t\t\tString[] dir = sc.readLine().split(\" \");\n\t\t\tint l = Integer.parseInt(dir[0]);\n\t\t\tint r = Integer.parseInt(dir[1]);\n\t\t\tint diff = r - l + 1;\n\t\t\tif(diff%4 > 1){\n\t\t\t\teven = !even;\n\t\t\t}\n\t\t\tif(even){\n\t\t\t\tSystem.out.println(\"even\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"odd\");\n\t\t\t}\n\t\t}\n\t}\n}\n\n/*\nint n = Integer.parseInt(sc.nextLine());\nString[] t = sc.nextLine().split(\" \");\nint[] list = new int[n];\nfor(int x=0; x<n; x++){\n\tlist[x] = Integer.parseInt(t[x]);\n}\n\t\t\nString[] dir = sc.nextLine().split(\" \");\nint a = Integer.parseInt(dir[0]);\nint b = Integer.parseInt(dir[1]);\nint c = Integer.parseInt(dir[2]);\nint d = Integer.parseInt(dir[3]);\nint e = Integer.parseInt(dir[4]);\n\nint n = Integer.parseInt(sc.nextLine());\n*/", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\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\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tint n = scan.nextInt();\n\t\tboolean even = true;\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ta[i] = scan.nextInt();\n\t\t\tfor(int j = 0; j < i; j++)\n\t\t\t\tif(a[i] < a[j]) even = !even;\n\t\t}\n\t\tint q = scan.nextInt();\n\t\twhile(q-- > 0) {\n\t\t\tint l = scan.nextInt(), r = scan.nextInt();\n\t\t\tint len = r - l + 1;\n\t\t\tint permutations = len * (len - 1) / 2;\n\t\t\tif(permutations % 2 != 0) even = !even;\n\t\t\tpw.println(even ? \"even\" : \"odd\");\n\t\t}\n\t\t\n\t\tpw.flush();\n\t}\n\t\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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        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.readInt();\n            int[] a = in.readIntArray(n);\n            int swap = 0;\n            for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (a[i] > a[j]) swap ^= 1;\n\n            int m = in.readInt();\n            while (m-- > 0) {\n                int l = in.readInt();\n                int r = in.readInt();\n                int s = (r - l + 1);\n                s = s * (s - 1) / 2;\n                swap ^= s;\n                out.println((swap & 1) == 0 ? \"even\" : \"odd\");\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            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 int[] readIntArray(int size) {\n            int[] ans = new int[size];\n            for (int i = 0; i < size; i++) ans[i] = readInt();\n            return ans;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "/*\n * PDPM IIITDM Jabalpur\n * Asutosh Rana\n */\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n\tlong MOD = 1000000007;\n\tInputReader in;\n\tBufferedReader br;\n\tPrintWriter out;\n\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tMain solver = new Main();\n\t\tsolver.in = new InputReader(System.in);\n\t\tsolver.br = new BufferedReader(new InputStreamReader(System.in));\n\t\tsolver.out = new PrintWriter(System.out);\n\t\tsolver.solve();\n\t\tsolver.out.flush();\n\t\tsolver.out.close();\n\t}\n\n\tpublic void solve() {\n\n\t\tint tc = 1;//in.readInt();\n\n\t\tfor (int cas = 1; cas <= tc; cas++) {\n\t\t\tint N = in.readInt();\n\t\t\tint[] A = new int[N];\n\t\t\tin.readInt(A);\n\n\t\t\tint res = 0;\n\t\t\tfor(int i=0;i<N;i++){\n\t\t\t\tfor(int j=i+1;j<N;j++){\n\t\t\t\t\tif(A[i]>A[j])\n\t\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres = res % 2;\n\t\t\t\n\t\t\tint Q = in.readInt();\n\t\t\twhile(Q-->0){\n\t\t\t\tint l = in.readInt();\n\t\t\t\tint r = in.readInt();\n\t\t\t\tint add = (r-l+1)/2;\n\t\t\t\tres = res + add;\n\t\t\t\tres%=2;\n\t\t\t\tout.println(res%2==0?\"even\":\"odd\");\n\t\t\t}\n\t\t}\n\n\t}\n\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\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 void readInt(int[] A) {\n\t\tfor (int i = 0; i < A.length; i++)\n\t\t\tA[i] = readInt();\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic void readLong(long[] A) {\n\t\tfor (int i = 0; i < A.length; i++)\n\t\t\tA[i] = readLong();\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic char[] readCharA() {\n\t\treturn readString().toCharArray();\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 c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\n    //~~~~~~~~~~~~~~~~~~~~~~~@@@@@@@@@@@@@@@_____________K_____S_____J__________@@@@@@@@@@@@@@@@@@@@@@@@@@@@~~~~~~~~~~~~~~~~~~~~~~~~~~\n    //Date:00/00/17\n    //-------------\n\n\nimport java.util.*;\nimport java.io.*;\n\n/*\n\n    [[[[[[[[[[[[[[[      ]]]]]]]]]]]]]]]\n    [::::::::::::::      ::::::::::::::]\n    [::::::::::::::      ::::::::::::::]\n    [::::::[[[[[[[:      :]]]]]]]::::::]\n    [:::::[                      ]:::::]\n    [:::::[                      ]:::::]\n    [:::::[                      ]:::::]\n    [:::::[                      ]:::::]\n    [:::::[    CODE YOUR LIFE    ]:::::]\n    [:::::[   Kripa Shankar jha  ]:::::]\n    [:::::[                      ]:::::]\n    [:::::[                      ]:::::]\n    [:::::[                      ]:::::]\n    [:::::[                      ]:::::]\n    [::::::[[[[[[[:      :]]]]]]]::::::]\n    [::::::::::::::      ::::::::::::::]\n    [::::::::::::::      ::::::::::::::]\n    [[[[[[[[[[[[[[[      ]]]]]]]]]]]]]]]\n*/\n\npublic class prob3{\n  \n\n    static Parser sc=new Parser(System.in);\n    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n  \n  static int p[]=new int[100005];\n  public static void main(String[] args) throws IOException {\n    // use ((((((( sc ............... for input\n\n   \n    int n=sc.nextInt();\n\n    int arr[]=new int[n];\n\n    for(int i=0;i<n;i++){\n      arr[i]=sc.nextInt();\n    }\n\n    int swap=0;\n\n    for(int i=0;i<n;i++){\n      for(int j=0;j<i;j++){\n        if(arr[i]<arr[j]){\n           swap++; \n        }\n      }\n    }\n\n    swap%=2;\n\n\n    int m=sc.nextInt();\n\n    for(int i=0;i<m;i++){\n\n      int a=sc.nextInt(),b=sc.nextInt();\n      swap+=((b-a)*((b-a)+1))/2;\n\n      swap%=2;\n\n      if(swap%2==0){System.out.println(\"even\");}\n      else{System.out.println(\"odd\");}\n    }\n\n\n          \n  }\n\n   \n\npublic static void union(int a,int b){\n        int i=find(a);\n        int j=find(b);\n\n        if(p[i]!=j){\n          p[i]=j;\n        }\n      }\n\n\n      public static int find(int a){\n\n        while(p[a]!=a){\n          a=p[a];\n        }\n\n        return a;\n      }\n\n\n\n\n\n\n  //___________________________Fast-Input_Output-------------------******************* \n  \n\n  static class Parser {\n        final private int BUFFER_SIZE = 1 << 20;  // 2^16, a good compromise for some problems\n        private InputStream din;    // Underlying input stream\n        private byte[] buffer;      // Self-maintained buffer\n        private int bufferPointer;  // Current read position in the buffer\n        private int bytesRead;      // Effective bytes in the buffer read from the input stream\n        private SpaceCharFilter filter;\n        public Parser(InputStream in) {\n            din = in;\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n\n        }\n\n        /**\n         * Read the next integer from the input stream.\n         * @return The next integer.\n         * @throws IOException\n         */\n        public int nextInt() throws IOException {\n            int result = 0;\n            byte c = read();\n            while (c <= ' ') c = read();\n            boolean neg = (c == '-');\n            if (neg) c = read();\n        while (c >= '0' && c <= '9') {\n                result = result * 10 + c - '0';\n                c = read();\n            }\n      if (neg) return -result;\n              return result;\n        }\n\n        public int nextLong() throws IOException {\n            int result = 0;\n            byte c = read();\n            while (c <= ' ') c = read();\n            boolean neg = (c == '-');\n            if (neg) c = read();\n        while (c >= '0' && c <= '9') {\n                result = result * 10 + c - '0';\n                c = read();\n            }\n      if (neg) return -result;\n              return result;\n        }\n\n        public String nextLine()throws IOException {\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)==true);\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      public interface SpaceCharFilter {\n        public boolean isSpaceChar(int ch);\n      }\n\n\n        /**\n         * Read the next byte of data from the input stream.\n         * @return the next byte of data, or -1 if the end of the stream is reached.\n         * @throws IOException if an I/O error occurs.\n         */\n        public byte read() throws IOException {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n\n        /**\n         * Read data from the input stream into the buffer\n         * @throws IOException if an I/O error occurs.\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class D2 {\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint array[] =new int[n];\n\t\tfor(int i=0; i<=n-1; i++) {\n\t\t\tarray[i] = sc.nextInt();\n\t\t}\n\t\tint m = sc.nextInt();\n\t\tint result = count(array);\n\t\tfor(int i=1; i<=m; i++) {\n\t\t\tint a = sc.nextInt();\n\t\t\tint b = sc.nextInt();\n\t\t\tresult += (b-a)*(b-a+1)/2;\n\t\t\tresult=result%2;\n\t\t\tif(result%2==1)\n\t\t\t\tSystem.out.println(\"odd\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"even\");\n\t\t}\n\t}\n\t\n\tpublic static int count(int[] arr) {\n\t\tint[] array = arr.clone();\n\t\treturn sort(array,0,array.length-1);\n\t}\n\t\n\tpublic static int sort(int[] arr, int i, int j) {\n\t\tif(i>=j) return 0;\n\t\tint mid = (i+j)/2;\n\t\tint a = sort(arr,i,mid);\n\t\tint b = sort(arr,mid+1,j);\n\t\tint addition = 0;\n\t\tint r1 = mid+1;\n\t\tint[] tmp = new int[arr.length];\n\t\tint tIndex = i;\n        int cIndex=i;\n\t\twhile(i<=mid&&r1<=j) {\n\t\t\tif (arr[i] <= arr[r1]) \n                tmp[tIndex++] = arr[i++];\n            else {\n                      tmp[tIndex++] = arr[r1++];\n                      addition+=mid+1-i;\n            }\n\t\t}\n\t\twhile (i <=mid) {\n            tmp[tIndex++] = arr[i++];\n        }\n        while ( r1 <= j ) {\n            tmp[tIndex++] = arr[r1++];\n        }\n        while(cIndex<=j){\n            arr[cIndex]=tmp[cIndex];\n            cIndex++;\n        }\n        return a+b+addition;\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n/**\n */\npublic class Main911D {\n\tpublic static void main(String[] args) {\n\t\trun(System.in, System.out);\n\t}\n\n\tpublic static void run(InputStream in, PrintStream out) {\n\n\t\ttry (Scanner sc = new Scanner(in)) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint[] t = new int[n];\n\t\t\tint inv = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tt[i] = sc.nextInt();\n\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\tif (t[j] > t[i]) inv++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tinv = inv % 2;\n\t\t\tint m = sc.nextInt();\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tint a = sc.nextInt();\n\t\t\t\tint b = sc.nextInt();\n\t\t\t\tint s = b - a + 1;\n\t\t\t\tinv = (inv + s * (s - 1) / 2) % 2;\n\t\t\t\tout.println(inv == 0 ? \"even\" : \"odd\");\n\n\t\t\t}\n\n\t\t}\n\t}\n\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class inversion__count {\n\n\tpublic static void main(String[] args) {\n\t\n\t\tScanner s = new Scanner(System.in);\n\t\t\n\t\tint n=s.nextInt();\n\t\t\n\t\tint[] a = new int[n+1];\n\t\t\n\t\tfor(int i=1;i<=n;i++){\n\t\t\ta[i]=s.nextInt();\n\t\t}\n\t\t\n\t\tint m=s.nextInt();\n\t\tint count=0;\n\t\t\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tfor(int j=i+1;j<=n;j++){\n\t\t\t\tif(a[i]>a[j]){\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(count%2==0){\n\t\t\tcount=0;\n\t\t}else{\n\t\t\tcount=1;\n\t\t}\n\t\t\n\t\t//System.out.println(count);\n\t\tfor(int i=0;i<m;i++){\n\t\t\tint l=s.nextInt();\n\t\t\tint r=s.nextInt();\n\t\t\t\n\t\t\tif(l==r){\n\t\t\t\tif((count&1)==1){\n\t\t\t\t\tSystem.out.println(\"odd\");\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(\"even\");\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t int d=r-l+1;\n\t\t\t int segcount = 0;\n\t\t\t \n\t\t\t\n\t\t\t \n\t\t\tint  temp =   (d*(d-1))/2; \n\t\t\t \n\t\t\t if((temp&1)==1 && (count&1)==1){\n\t\t\t\t count=0;\n\t\t\t\t System.out.println(\"even\");\n\t\t\t }else if((temp&1)==1 && (count&1)==0){\n\t\t\t\t count=1;\n\t\t\t\t System.out.println(\"odd\");\n\t\t\t }else{\n\t\t\t\t if((count&1)==1){\n\t\t\t\t\t System.out.println(\"odd\");\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(\"even\");\n\t\t\t\t}\n\t\t\t }\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.* ;\nimport java.util.* ;\nimport java.text.* ;\nimport java.math.* ;\nimport static java.lang.Math.min ;\nimport static java.lang.Math.max ;\npublic class Codeshefcode{\n\tpublic static void main(String[] args) throws IOException{\n\t\t// Solver Machine = new Solver() ;\n\t\t// Machine.Solve() ;\n\t\t// Machine.Finish() ;\n\t\tnew Thread(null,new Runnable(){\n\t\t\tpublic void run(){\n\t\t\t\tSolver Machine = new Solver() ;\n\t\t\t\ttry{\n\t\t\t\t\tMachine.Solve() ;\n\t\t\t\t\tMachine.Finish() ;\n\t\t\t\t}catch(Exception e){\n\t\t\t\t\te.printStackTrace() ;\n\t\t\t\t\tSystem.out.flush() ;\n\t\t\t\t\tSystem.exit(-1) ;\n\t\t\t\t}catch(Error e){\n\t\t\t\t\te.printStackTrace() ;\n\t\t\t\t\tSystem.out.flush() ;\n\t\t\t\t\tSystem.exit(-1) ;\n\t\t\t\t}\n\t\t\t}\n\t\t},\"Solver\",1l<<27).start() ;\n\t}\n}\nclass Mod{\n\tstatic long mod=1000000007 ;\n\tstatic long d(long a,long b){ return (a*MI(b))%mod ; }\n\tstatic long m(long a,long b){ return (a*b)%mod ; }\n\tstatic private long MI(long a){ return pow(a,mod-2) ; }\n\tstatic long pow(long a,long b){\n\t\tif(b<0) return pow(MI(a),-b) ;\n\t\tlong val=a ; long ans=1 ;\n\t\twhile(b!=0){\n\t\t\tif((b&1)==1) ans = (ans*val)%mod ; \n\t\t\tval = (val*val)%mod ; \n\t\t\tb/=2 ;\n\t\t}\n\t\treturn ans ;\n\t}\t\n}\nclass pair implements Comparable<pair>{\n\tint x ; int y ;  \n\tpair(int x,int y){ this.x=x ; this.y=y ;} \n\tpublic int compareTo(pair p){\n\t\treturn (this.x<p.x ? -1 : (this.x>p.x ? 1 : (this.y<p.y ? -1 : (this.y>p.y ? 1 : 0)))) ;\n\t}\n}\nclass Solver{\n\tReader ip = new Reader(System.in) ;\t  \n\tPrintWriter op = new PrintWriter(System.out) ;\n\tpublic void Solve() throws IOException{\n\t\tint n = ip.i() ;\n\t\tint a[] = new int[n] ;\n\t\tfor(int i=0 ; i<n ; i++) a[i] = ip.i() ;\n\t\tint num=0 ;\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(a[i]>a[j])\n\t\t\t\t\tnum++ ;\n\t\tnum%=2 ;\n\t\tint m = ip.i() ;\n\t\twhile(m--!=0){\n\t\t\tint l = ip.i() ;\n\t\t\tint r = ip.i() ;\n\t\t\tint d = (r-l+1) ;\n\t\t\tint mod = d%4 ;\n\t\t\tint bit ;\n\t\t\tif(mod<=1) bit=0 ; else bit=1 ;\n\t\t\tnum+=bit ;\n\t\t\tnum%=2 ;\n\t\t\tpln(num==1 ? \"odd\" : \"even\") ;\n\t\t}\n\t}\n\tvoid Finish(){\n\t\top.flush();\n\t\top.close();\n\t}\n\tvoid p(Object o){\n\t\top.print(o) ;\n\t}\n\tvoid pln(Object o){\n\t\top.println(o) ;\n\t}\t\t\n}\nclass mylist extends ArrayList<Integer>{}\nclass myset extends TreeSet<Integer>{}\nclass mystack extends Stack<Integer>{}\nclass mymap extends TreeMap<Long,Integer>{}\nclass Reader {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tReader(InputStream input) {\n\t\treader = new BufferedReader(\n\t\t\t\t\tnew InputStreamReader(input) );\n\t\ttokenizer = new StringTokenizer(\"\") ;\n\t}\n\tString s() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()){\n\t\t\ttokenizer = new StringTokenizer(\n\t\t\treader.readLine()) ;\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\tint i() throws IOException {\n\t\treturn Integer.parseInt(s()) ;\n\t}\n\tlong l() throws IOException{\n\t\treturn Long.parseLong(s()) ;\n\t}\n\tdouble d() throws IOException {\n\t\treturn Double.parseDouble(s()) ;\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class ProblemD\n{\n\n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    \n    static void update(int i, int val, int[] bit){\n        for(; i < bit.length; i += (i&-i))\n            bit[i] += val;\n    }\n    \n    static int query(int i, int[] bit){\n        int ans=0;\n        \n        for(; i>0; i -= (i&-i))\n            ans += bit[i];\n        \n        return ans;\n    }\n    \n    static int get(int l, int r, int[] bit){\n        if(l > r) return 0;\n        return query(r, bit) - query(l - 1, bit);\n    }\n    \n    static void solve()\n    {\n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out);            \n        \n        int n = in.nextInt();\n        int[] arr = new int[n + 1];\n        int[] bit = new int[n + 2];\n        \n        for(int i = 1; i <= n; i++){\n            arr[i] = in.nextInt();\n        }\n        int cnt = 0;\n        \n        for(int i = n; i > 0; i--){\n            cnt += query(arr[i], bit);\n            update(arr[i], 1, bit);\n        }\n        cnt %= 2;\n        \n        int q = in.nextInt();\n\n        while(q-- > 0){\n            \n            int l = in.nextInt();\n            int r = in.nextInt();\n            int length = r - l + 1;\n            int x = (length * (length - 1)) / 2;\n            x %= 2;\n            cnt ^= x;\n            out.println(cnt == 0 ? \"even\" : \"odd\");\n        }\n        \n        out.close();\n    }\n    \n    public static void main(String[] args)\n    {\n        new Thread(null ,new Runnable(){\n            public void run(){\n                try{\n                    solve();\n                } catch(Exception e){\n                    e.printStackTrace();\n                }\n            }\n        },\"1\",1<<26).start();\n        \n    }\n\n    static class Pair implements Comparable<Pair>\n    {\n\n        long x,y;\n\n        Pair (long x,long y)\n        {\n                this.x = x;\n                this.y = y;\n        }\n        public int compareTo(Pair o)\n        {\n            return Long.compare(this.x,o.x);\n                //return 0;\n        }\n\n        public boolean equals(Object o)\n        {\n            if (o instanceof Pair)\n            {\n                Pair p = (Pair)o;\n                return p.x == x && p.y==y;\n            }\n            return false;\n        }\n\n        @Override\n        public String toString()\n        {\n            return x + \" \"+ y ;\n        }\n\n        /*public int hashCode()\n        {\n            return new Long(x).hashCode() * 31 + new Long(y).hashCode();\n        }*/\n\n    } \n\n    static long add(long a,long b){\n        long x=(a+b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n\n    static long sub(long a,long b){\n        long x=(a-b);\n        while(x<0) x+=mod;\n        return x;\n    }\n    \n    static long mul(long a,long b){\n        long x=(a*b);\n        while(x>=mod) x-=mod;\n        return x;\n    }\n    \n    static String rev(String s){\n        StringBuilder sb=new StringBuilder(s);\n        sb.reverse();\n        return sb.toString();\n    }\n    \n    static long gcd(long x,long y)\n    {\n        if(y==0)\n                return x;\n        else\n                return gcd(y,x%y);\n    }\n\n    static int gcd(int x,int y)\n    {\n        if(y==0)\n                return x;\n        else \n                return gcd(y,x%y);\n    }\n\n    static long pow(long n,long p,long m)\n    {\n         long  result = 1;\n          if(p==0){\n            return 1;\n          }\n          \n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\n            if(result >= m)\n               result %= m;\n            p >>=1;\n            n*=n;\n            if(n >= m)\n                n%=m;\n        }\n        \n        return result;\n    }\n\n    static long pow(long n,long p)\n    {\n        long  result = 1;\n          if(p==0)\n            return 1;\n\n        while(p!=0)\n        {\n            if(p%2==1)\n                result *= n;\t    \n            p >>=1;\n            n*=n;\t    \n        }\n        return result;\n    }\n\n    static void debug(Object... o)\n    {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "//package codeforces.Educational35;\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.StringTokenizer;\n\npublic class D\n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tint inv = 0;\n\t\tint n = sc.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = sc.nextInt();\n\t\t\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tfor (int j = i+1; j < arr.length; j++)\n\t\t\t\tif(arr[i] > arr[j])\n\t\t\t\t\tinv++;\n\t\t\n\t\t\n\t\tboolean odd = (inv%2)!=0;\n\t\tint q = sc.nextInt();\n\t\tfor (int i = 0; i < q; i++)\n\t\t{\n\t\t\tint l = sc.nextInt();\n\t\t\tint r = sc.nextInt();\n\t\t\tint sz = r-l+1;\n\t\t\tint tot = (sz*(sz-1))/2;\n\t\t\tif(tot%2 != 0)\n\t\t\t\todd = !odd;\n\t\t\tif(odd)\n\t\t\t\tpw.println(\"odd\");\n\t\t\telse\n\t\t\t\tpw.println(\"even\");\n\t\t}\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class D {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tint x = 0;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = i + 1; j < a.length; j++) {\n\t\t\t\tif (a[i] > a[j]) {\n\t\t\t\t\tx++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tboolean ans = x % 2 == 0;\n\t\tint m = in.nextInt();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint len = -in.nextInt() + in.nextInt();\n\t\t\tlen = len * (len + 1) / 2;\n\t\t\tif (len % 2 == 1) {\n\t\t\t\tans = !ans;\n\t\t\t}\n\t\t\tif (ans) {\n\t\t\t\tout.println(\"even\");\n\t\t\t} else {\n\t\t\t\tout.println(\"odd\");\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(\"segments.in\"));\n\t\t\t\tout = new PrintWriter(new File(\"segments.out\"));\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 D().run();\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n// import java.awt.Point;\n \npublic class Main {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\";\n \n    long MOD = 1_000_000_007;\n    int inf = Integer.MAX_VALUE;\n\n    void solve()\n    {\n        int n = ni();\n        int[] a = new int[n];\n        for(int i = 0; i < n; i++){\n            a[i] = ni();\n        }\n        long ans = 0;\n        for(int i = 0; i < n; i++){\n            for(int j = i+1; j < n; j++){\n                if(a[j]<a[i]) ans++;\n            }\n        }\n        if(ans%2==0) ans = 0;\n        else ans = 1;\n        int m = ni();\n        for(int i = 0; i < m; i++){\n            long s = nl();\n            long g = nl();\n            long sub = g-s;\n            long res = sub*(sub+1)/2;\n            if(res%2==1) ans = 1 - ans;\n            if(ans==0) out.println(\"even\");\n            else out.println(\"odd\");\n        }\n\n    }\n\n     \n        \n    void run() throws Exception\n    {\n        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        out = new PrintWriter(System.out);\n        \n        long s = System.currentTimeMillis();\n        solve();\n        out.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    private int lenbuf = 0, ptrbuf = 0;\n    \n    private int readByte()\n    {\n        if(lenbuf == -1)throw new InputMismatchException();\n        if(ptrbuf >= lenbuf){\n            ptrbuf = 0;\n            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n            if(lenbuf <= 0)return -1;\n        }\n        return inbuf[ptrbuf++];\n    }\n    \n    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n    \n    private double nd() { return Double.parseDouble(ns()); }\n    private char nc() { return (char)skip(); }\n    \n    private String ns()\n    {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while(!(isSpaceChar(b) && b != ' ')){\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n    \n    private char[] ns(int n)\n    {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while(p < n && !(isSpaceChar(b))){\n            buf[p++] = (char)b;\n            b = readByte();\n        }\n        return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n    \n    private char[][] nm(int n, int m)\n    {\n        char[][] map = new char[n][];\n        for(int i = 0;i < n;i++)map[i] = ns(m);\n        return map;\n    }\n    \n    private int[] na(int n)\n    {\n        int[] a = new int[n];\n        for(int i = 0;i < n;i++)a[i] = ni();\n        return a;\n    }\n    \n    private int ni()\n    {\n        int num = 0, b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private long nl()\n    {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }\n \n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n\tpublic static void solve(FastScanner fs) {\t\n\t\tint n=fs.nextInt();\n\t\tint[] a=fs.readArray(n);\n\t\tboolean even=((countInversions(a)&1)==0);\n\t\tint q=fs.nextInt();\n\t\tfor (int i=0; i<q; i++) {\n\t\t\tint start=fs.nextInt();\n\t\t\tint end=fs.nextInt();\n\t\t\tint diff=end-start;\n\t\t\tboolean evenChange=(diff+1)/2%2==0;\n\t\t\teven^=!evenChange;\n\t\t\tSystem.out.println(even?\"even\":\"odd\");\n\t\t}\n\t}\n\t\n\tprivate static int countInversions(int[] a) {\n\t\tint c=0;\n\t\tfor (int i=0; i<a.length; i++) {\n\t\t\tfor (int j=i+1; j<a.length; j++)\n\t\t\t\tif (a[j]<a[i])\n\t\t\t\t\tc++;\n\t\t}\n\t\treturn c;\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<n; i++)\n\t\t\t\ta[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "//package Educational35;\n\n//import FastScanner.Competitive;\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 D {\n        String INPUT = \"4\\n\" +\n                \"1 2 4 3\\n\" +\n                \"4\\n\" +\n                \"1 1\\n\" +\n                \"1 4\\n\" +\n                \"1 4\\n\" +\n                \"2 3\";\n\n        void solve()\n        {\n                int n = i();\n                int[] a = ia(n);\n                int count = 0 ;\n                for(int i = 0 ; i<n-1 ; i++)\n                {\n                        for(int j = i+1; j<n ; j++)\n                        {\n                                if(a[j]<a[i])\n                                {\n                                        count++;\n                                }\n                        }\n                }\n                int q = i();\n                for(int i = 0 ; i<q ; i++)\n                {\n                        int l = i(), r=i();\n                        int mid = (r-l+1)/2;\n                        if(mid%2==0)\n                        {\n                                out.println(count%2==0?\"even\":\"odd\");\n                        }\n                        else\n                        {\n                                count++;\n                                out.println(count%2==0?\"even\":\"odd\");\n                        }\n                }\n\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 D().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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.awt.Checkbox;\nimport java.awt.Point;\nimport java.io.*;\n                    import java.math.*;\n                    import java.util.*;\nimport java.util.Map.Entry;\n\nimport javax.print.attribute.SetOfIntegerSyntax;\nimport javax.swing.plaf.FontUIResource;\n\n\n             \n                    public class CODE2{\n                      private static InputStream stream;\n                        private static byte[] buf = new byte[1024];\n                        private static int curChar,MAX;\n                        private static int numChars;\n                        private static SpaceCharFilter filter;\n                        private static PrintWriter pw;\n                        private static long count = 0,mod=1000000007;\n                        static int BIT[];\n                        private static boolean primer[];\n                    //    private static TreeSet<Integer> ts=new TreeSet[200000];\npublic final static int INF = (int) 1E9;\n\npublic static void main(String args[]) {\n    InputReader(System.in);\n    pw = new PrintWriter(System.out); \n    new Thread(null ,new Runnable(){\n       public void run(){\n           try{\n               solve();\n               \n               pw.close();\n           } catch(Exception e){\n               e.printStackTrace();\n           }\n       }\n   },\"1\",1<<26).start();\n   }\n    static StringBuilder sb;\n    public static void test(){\n         sb=new StringBuilder();\n        int t=nextInt();\n        while(t-->0){\n            \n            solve();\n           \n        }\n        pw.println(sb);\n    }\n    public static long pow(long n, long p,long mod) {\n        if(p==0)\n            return 1;\n        if(p==1)\n            return n%mod;\n        if(p%2==0){\n            long temp=pow(n, p/2,mod);\n        return (temp*temp)%mod;\n        }else{\n                 long temp=pow(n,p/2,mod);\n                 temp=(temp*temp)%mod;\n                 return(temp*n)%mod;\n                 \n        }\n    }\n    public static long pow(long n, long p) {\n        if(p==0)\n            return 1;\n        if(p==1)\n            return n;\n        if(p%2==0){\n            long temp=pow(n, p/2);\n        return (temp*temp);\n        }else{\n                 long temp=pow(n,p/2);\n                 temp=(temp*temp);\n                 return(temp*n);\n                 \n        }\n    }\n    public static void Merge(long a[],int p,int r){\n        if(p<r){\n            int q = (p+r)/2;\n            Merge(a,p,q);\n            Merge(a,q+1,r);\n            Merge_Array(a,p,q,r);\n        }\n    }\n    public static void Merge_Array(long a[],int p,int q,int r){\n       long b[] = new long[q-p+1];\n        long c[] = new long[r-q];\n        for(int i=0;i<b.length;i++)\n            b[i] = a[p+i];\n        for(int i=0;i<c.length;i++)\n            c[i] = a[q+i+1];\n        int i = 0,j = 0;\n        for(int k=p;k<=r;k++){\n            if(i==b.length){\n                a[k] = c[j];\n                j++;\n            }\n            else if(j==c.length){\n                a[k] = b[i];\n                i++;\n            }\n            else if(b[i]<c[j]){\n                a[k] = b[i];\n                i++;\n            }\n            else{\n                a[k] = c[j];\n                j++;\n            }\n        }\n    }\n    \n  \n    public static long gcd(long x, long y) {\n        if (x == 0)\n            return y;\n        else\n            return gcd( y % x,x);\n    }    \n    \n    public static boolean isPrime(int n) {\n        if (n <= 1)\n            return false;\n        if (n <= 3)\n            return true;\n \n        if (n % 2 == 0 || n % 3 == 0)\n            return false;\n \n        for (int i = 5; i * i <= n; i = i + 6)\n            if (n % i == 0 || n % (i + 2) == 0)\n                return false;\n \n        return true;\n    }\n    \n        static LinkedList<Integer> adj[];\n        static boolean Visited[];\n        static HashSet<Integer> exc;\n        static long oddsum[]=new long[1000001];\n        static long co=0,ans=0;\n        static int parent[];\n        static int size[],color[],res[],k;\n        static ArrayList<Integer> al[];\n        static long MOD = (long)1e9 + 7;\n        private static void buildgraph(int n){\n            adj=new LinkedList[n+1];\n            Visited=new boolean[n+1];\n            levl=new int[n+1];\n            \n            for(int i=0;i<=n;i++){\n                adj[i]=new LinkedList<Integer>();\n            \n            }\n\n\n        }\n      \n       \n        static int[] levl;\n        static int[] eat;\n      //  static int n,m;\n        static int price[];\n        //ind frog crab\n   static  boolean check(char c)\n    {\n    \tif(c!='a' && c!='e' && c!='i' && c!='o' && c!='u' )\n    \t\treturn true;\n    \telse\n    \t\treturn false;\n    }\n        public static void solve(){\n       \n     \n    \t  \n   int n= nextInt();\n   int a[]=new int[n];\n   a=nextIntArray(n);\n   \n   \n   int invcount=0;\n   for(int i=0;i<n;i++)\n   {\n\t   for(int j=i+1;j<n;j++)\n\t   {\n\t\t   if(a[i]>a[j])\n\t\t\t   invcount++;\n\t   }\n   }\n   \n   \n   int m=nextInt();\n   \n   int initial = invcount%2;\n   while(m--!=0)\n   {\n\t   int l=nextInt();\n\t   int r=nextInt();\n\t   \n\t   \n\t   int diff = r-l+1;\n\t   int totalpair = (diff*(diff-1))/2;\n\t   \n\t   if(((totalpair%2)+initial)%2==1)\n\t   {\n\t\t   pw.println(\"odd\");\n\t\t   initial=1;\n\t   }\n\t   else\n\t   {\n\t\t   pw.println(\"even\");\n\t\t   initial=0;\n\t   }\n\t   \n   }\n     \n    \n    }\n        \n        static void seive2(int n)\n        {\n        \tprimer=new boolean[n+1];\n        \tArrays.fill(primer,true);\n        \tprimer[0]=false;\n        \tprimer[1]=false;\n        \tprimer[2]=true;\n        \t\n        \tfor(int i=2;i*i<=n;i++)\n        \t{\n        \t\tif(primer[i])\n        \t\t{\n        \t\t\tfor(int j=2*i;j<=n;j=j+i)\n        \t\t\t{\n        \t\t\t\tprimer[j]=false;\n        \t\t\t}\n        \t\t}\n        \t}\n        }\n       \n        \n     /*   static void BITupdate(int x,int val)\n        {\n        \twhile(x<=n)\n        \t{\n        \t\tBIT[x]+=val;\n        \t\tx+= x & -x;\n        \t}\n        }*/\n     /*   static void update(int x,long val)\n        {\n      \n        \tval=val%MOD;\n        \twhile(x<=n)\n        \t{\n        \t\t// System.out.println(x);\n        \tBIT[x]=(BIT[x]+val)%MOD;\n        \tx+=(x & -x);\n        \t}\n        //\tSystem.out.println(\"dfd\");\n        }*/\n        static int BITsum(int x)\n        \t\t{\n        \tint sum=0;\n        \twhile(x>0)\n        \t{\n        \t\tsum+=BIT[x];\n        \t\tx-= (x & -x);\n        \t}\n        \t\treturn sum;\n        \t\t}\n  /*      static long sum(int x)\n        {\n        \tlong sum=0;\n        \twhile(x>0)\n        \t{\n        \t\tsum=(sum+BIT[x])%MOD;\n        \t\tx-=x & -x;\n        \t}\n        \treturn sum;\n        }*/\n        static boolean union(int x,int y)\n        {\n        \tint xr=find(x);\n        \tint yr=find(y);\n        \tif(xr==yr)\n        \t\treturn false;\n        \tif(size[xr]<size[yr])\n        \t{\n        \t\tsize[yr]+=size[xr];\n        \t\tparent[xr]=yr;\n        \t}\n        \telse\n        \t{\n        \t\tsize[xr]+=size[yr];\n        \t\tparent[yr]=xr;\n        \t\t\n        \t}\n        \treturn true;\n        \t\n        }\n        static int  find(int x)\n        {\n        \tif(parent[x]==x)\n        \t\treturn x;\n        \telse\n        \t{\n        \t\tparent[x]=find(parent[x]);\n        \t\treturn parent[x];\n        \t}\n        \t\n        }\n        public static class Edge implements Comparable<Edge>\n        {\n        \tint u, v,s;\n\t\t\tpublic Edge(int u, int v) \n\t\t\t{\n\t\t\t\tthis.u = u;\n\t\t\t\tthis.v = v;\n\t\t\t\t//this.s = s;\n\t\t\t}\n\t\t\tpublic int hashCode() \n\t\t\t{\n\t\t\t\treturn Objects.hash();\n\t\t\t}\n\t\t\tpublic int compareTo(Edge other) \n\t\t\t{\n\t\t\treturn (Integer.compare(u, other.u) != 0 ? (Integer.compare(u, other.u)):(Integer.compare(v, other.v)));\n\t\t\t\t//\t\t&((Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s)):(Long.compare(u, other.v)!=0?Long.compare(u, other.v):Long.compare(v, other.u))));\n\t\t\t\t//return this.u-other.u;\n\t\t\t}\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\treturn this.u + \" \" + this.v;\n\t\t\t}\n        }\n       \n        static int col[];\n    public static boolean isVowel(char c){\n        if(c=='a' || c=='e'||c=='i' || c=='o' || c=='u')\n            return true;\n        return false;\n    }\nstatic int no_vert=0;\n\n  private static void dfs(int start){\n      Visited[start]=true;\n    if(al[color[start]].size()>=k)\n    {\n    \tres[start]=al[color[start]].get(al[color[start]].size()-k);\n    }\n    al[color[start]].add(start);\n      for(int i:adj[start]){\n          if(!Visited[i])\n              {\n              dfs(i);\n              }\n      }\n      (al[color[start]]).remove(al[color[start]].size()-1);\n      \n  }\n    \n    public static String reverseString(String s) {\n        StringBuilder sb = new StringBuilder(s);\n        sb.reverse();\n        return (sb.toString());\n    }\n    \n  /*  \n   private static void BFS(int sou){\n        Queue<Integer> q=new LinkedList<Integer>();\n        q.add(sou);\n        Visited[sou]=true;\n        levl[sou]=0;\n        while(!q.isEmpty()){\n            int top=q.poll();\n            \n            for(int i:adj[top]){\n                //pw.println(i+\" \"+top);\n            if(!Visited[i])\n            {\n                \n                q.add(i);\n                levl[i]=levl[top]+1;\n            }\n            \n            Visited[i]=true;\n            \n            }\n        }\n    }*/\n    \n\n\n\n                  static int indeg[];\n               /* private static void kahn(int n){\n                    \n                    PriorityQueue<Integer> q=new PriorityQueue<Integer>();\n                    for(int i=1;i<=n;i++){\n                        if(indeg[i]==0){\n                            q.add(i);\n                        }\n                    }\n                    while(!q.isEmpty()){\n                        int top=q.poll();\n                        st.push(top);\n                        for(Node i:adj[top]){\n                            indeg[i.to]--;\n                            if(indeg[i.to]==0){\n                                q.add(i.to);\n                            }\n                        }\n                    }\n                }\n                    \n                    static int state=1;\n                    static long no_exc=0,no_vert=0;\n                  static Stack<Integer> st;\n                  static HashSet<Integer> inset;\n                 /*   private static void topo(int curr){\n                        \n                        Visited[curr]=true;\n                        inset.add(curr);\n                        for(int x:adj[curr]){\n                            if(adj[x].contains(curr) || inset.contains(x)){\n                                state=0;\n                                return;\n                            }\n                            if(state==0)\n                                return;\n                            \n                        }\n                        st.push(curr);\n                        \n                        inset.remove(curr);\n                    }*/\n                    static HashSet<Integer> hs;\n                   \n                 \n                     static boolean prime[];\n                    static int spf[];\n                    public static void sieve(int n){\n                        prime=new boolean[n+1];\n                        spf=new int[n+1];\n                        \n                        Arrays.fill(spf, 1);\n                        Arrays.fill(prime, true);\n                    prime[1]=false;\n                        spf[2]=2;\n                        \n                    for(int i=4;i<=n;i+=2){\n                        spf[i]=2;\n                    }\n                    for(int i=3;i<=n;i+=2){\n                        if(prime[i]){\n                            spf[i]=i;\n                            for(int j=2*i;j<=n;j+=i){\n                                \n                                prime[j]=false;\n                            if(spf[j]==1){\n                                spf[j]=i;\n                            }\n                            }\n                        }\n                    }\n                    \n                        \n                    }\n                     \n                    // To Get Input\n// Some Buffer Methods\n \n                     public static void sort(long a[]){\n                         Merge(a, 0, a.length-1);\n                     }\n                    public static void InputReader(InputStream stream1) {\n                        stream = stream1;\n                    }\n \n                    private static boolean isWhitespace(int c) {\n                        return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n                    }\n \n                    private static boolean isEndOfLine(int c) {\n                        return c == '\\n' || c == '\\r' || c == -1;\n                    }\n \n                    private static 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                    private static 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 static 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 - '0';\n                            c = read();\n                        } while (!isSpaceChar(c));\n                        return res * sgn;\n                    }\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 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                    private static int[] nextIntArray(int n) {\n                        int[] arr = new int[n];\n                        for (int i = 0; i < n; i++) {\n                            arr[i] = nextInt();\n                        }\n                        return arr;\n                    }\n \n                    private static long[][] next2dArray(int n, int m) {\n                        long[][] arr = new long[n][m];\n                        for (int i = 0; i < n; i++) {\n                            for (int j = 0; j < m; j++) {\n                                arr[i][j] = nextLong();\n                            }\n                        }\n                        return arr;\n                    }\n                    private static char[][] nextCharArray(int n,int m){\n                        char [][]c=new char[n][m];\n                        for(int i=0;i<n;i++){\n                            String s=nextLine();\n                            for(int j=0;j<s.length();j++){\n                                c[i][j]=s.charAt(j);\n                            }\n                        }\n                        return c;\n                    }\n \n                    private static long[] nextLongArray(int n) {\n                        long[] arr = new long[n];\n                        for (int i = 0; i < n; i++) {\n                            arr[i] = nextLong();\n                        }\n                        return arr;\n                    }\n \n                    private static void pArray(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 pArray(long[] 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 pArray(boolean[] 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 boolean isSpaceChar(int c) {\n                        if (filter != null)\n                            return filter.isSpaceChar(c);\n                        return isWhitespace(c);\n                    }\n \n                    private interface SpaceCharFilter {\n                        public boolean isSpaceChar(int ch);\n                    }\n                    \n\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "// discussed with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF911D {\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\tint n = Integer.parseInt(br.readLine());\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint[] aa = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = Integer.parseInt(st.nextToken());\n\t\tboolean odd = false;\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 (aa[i] > aa[j])\n\t\t\t\t\todd = !odd;\n\t\tint m = Integer.parseInt(br.readLine());\n\t\twhile (m-- > 0) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint l = Integer.parseInt(st.nextToken());\n\t\t\tint r = Integer.parseInt(st.nextToken());\n\t\t\tint k = r - l + 1;\n\t\t\tif ((long) k * (k - 1) / 2 % 2 != 0)\n\t\t\t\todd = !odd;\n\t\t\tpw.println(odd ? \"odd\" : \"even\");\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D911{\n\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = ia(n);\n\t\tint Q = ni();\n\t\tString[] ans = {\"even\", \"odd\"};\n\t\tint cur = merge(a, 0, n - 1) % 2;\n\t\twhile(Q-->0)\n\t\t{\n\t\t\tint l = ni(), r = ni();\n\t\t\tcur ^= (r - l + 1) / 2 % 2;\n\t\t\tout.println(ans[cur]);\n\t\t}\n\t\t\n\t}\n\t\n\tint merge(int[] a, int l, int r)\n\t{\n\t\tif(l >= r)\n\t\t\treturn 0;\n\t\tint mid = l + r >> 1;\n\t\tint v1 = merge(a, l, mid);\n\t\tint v2 = merge(a, mid + 1, r);\n\t\t\n\t\tint[] rep = new int[r-l+1];\n\t\tint ptr0 = 0, ptr1 = l, ptr2 = mid + 1;\n\t\t\n\t\tlong len = mid-l+1;\n\t\tint ret = 0;\n\t\twhile(ptr1<=mid && ptr2<=r)\n\t\t{\n\t\t\tif(a[ptr1] <= a[ptr2])\n\t\t\t{\n\t\t\t\tlen--;\n\t\t\t\trep[ptr0++] = a[ptr1++];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tret += len;\n\t\t\t\trep[ptr0++] = a[ptr2++]; \n\t\t\t}\n\t\t}\n\t\t\n\t\twhile(ptr1 <= mid)\n\t\t\trep[ptr0++] = a[ptr1++];\n\t\twhile(ptr2 <= r)\n\t\t\trep[ptr0++] = a[ptr2++];\n\t\t\n\t\tfor(int i=0;i<ptr0;i++)\n\t\t\ta[l+i] = rep[i];\n\t\t\n\t\treturn v1 + v2 + ret;\n\t}\n\t\n\tpublic static void main(String[] args){new D911().run();}\n\t\n\tprivate byte[] bufferArray = new byte[1024];\n\tprivate int bufLength = 0;\n\tprivate int bufCurrent = 0;\n\tInputStream inputStream;\n\tPrintWriter out;\n\t\n\tpublic void run()\n\t{\n\t\tinputStream = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\tint nextByte()\n\t{\n\t\tif(bufLength == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif(bufCurrent >= bufLength)\n\t\t{\n\t\t\tbufCurrent = 0;\n\t\t\ttry\n\t\t\t{bufLength = inputStream.read(bufferArray);}\n\t\t\tcatch(IOException e)\n\t\t\t{ throw new InputMismatchException();}\n\t\t\tif(bufLength <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn bufferArray[bufCurrent++];\n\t}\n\t\n\tboolean isSpaceChar(int x)\t{return (x < 33 || x > 126);}\n\t\n\tboolean isDigit(int x)\t{return (x >= '0' && x <= '9');}\n\t\n\tint nextNonSpace()\n\t{\n\t\tint x;\n\t\twhile((x=nextByte()) != -1 && isSpaceChar(x));\n\t\treturn x;\n\t}\n\t\n\tint ni()\n\t{\n\t\tlong ans = nl();\n\t\tif (ans >= Integer.MIN_VALUE && ans <= Integer.MAX_VALUE)\n\t\t\treturn (int)ans;\n\t\tthrow new InputMismatchException();\n\t}\n\t\n\tlong nl()\n\t{\n\t\tlong ans = 0;\n\t\tboolean neg = false;\n\t\tint x = nextNonSpace();\n\t\tif(x == '-') \n\t\t{\n\t\t\tneg = true;\n\t\t\tx = nextByte();\n\t\t}\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tif(isDigit(x))\n\t\t\t{\n\t\t\t\tans = ans * 10 + x -'0';\n\t\t\t\tx = nextByte();\n\t\t\t}\n\t\t\telse\n\t\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\treturn neg ? -ans : ans;\n\t}\n\t\n\tString ns()\n\t{\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint x = nextNonSpace();\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tsb.append((char)x);\n\t\t\tx = nextByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tchar nc()\t{ return (char)nextNonSpace();}\n\t\n\tdouble nd()\t{ return (double)Double.parseDouble(ns()); }\n\t\n\tchar[] ca()\t{ return ns().toCharArray();}\n\t\n\tchar[][] ca(int n)\n\t{\n\t\tchar[][] ans = new char[n][];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tans[i] = ca();\n\t\treturn ans;\n\t}\n\t\n\tint[] ia(int n)\n\t{\n\t\tint[] ans = new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tans[i] = ni();\n\t\treturn ans;\n\t}\n\t\n\tvoid db(Object... o) {System.out.println(Arrays.deepToString(o));}\n\t\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n// import java.awt.Point;\n \npublic class Main {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\";\n \n    long MOD = 1_000_000_007;\n    int inf = Integer.MAX_VALUE;\n\n    void solve()\n    {\n        int n = ni();\n        int[] a = new int[n];\n        for(int i = 0; i < n; i++){\n            a[i] = ni();\n        }\n        long ans = 0;\n        for(int i = 0; i < n; i++){\n            for(int j = i+1; j < n; j++){\n                if(a[j]<a[i]) ans++;\n            }\n        }\n        if(ans%2==0) ans = 0;\n        else ans = 1;\n        int m = ni();\n        for(int i = 0; i < m; i++){\n            long s = nl();\n            long g = nl();\n            long sub = g-s;\n            long res = sub*(sub+1)/2;\n            if(res%2==1) ans = 1 - ans;\n            if(ans==0) out.println(\"even\");\n            else out.println(\"odd\");\n        }\n\n    }\n\n     \n        \n    void run() throws Exception\n    {\n        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        out = new PrintWriter(System.out);\n        \n        long s = System.currentTimeMillis();\n        solve();\n        out.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    private int lenbuf = 0, ptrbuf = 0;\n    \n    private int readByte()\n    {\n        if(lenbuf == -1)throw new InputMismatchException();\n        if(ptrbuf >= lenbuf){\n            ptrbuf = 0;\n            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n            if(lenbuf <= 0)return -1;\n        }\n        return inbuf[ptrbuf++];\n    }\n    \n    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n    \n    private double nd() { return Double.parseDouble(ns()); }\n    private char nc() { return (char)skip(); }\n    \n    private String ns()\n    {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while(!(isSpaceChar(b) && b != ' ')){\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n    \n    private char[] ns(int n)\n    {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while(p < n && !(isSpaceChar(b))){\n            buf[p++] = (char)b;\n            b = readByte();\n        }\n        return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n    \n    private char[][] nm(int n, int m)\n    {\n        char[][] map = new char[n][];\n        for(int i = 0;i < n;i++)map[i] = ns(m);\n        return map;\n    }\n    \n    private int[] na(int n)\n    {\n        int[] a = new int[n];\n        for(int i = 0;i < n;i++)a[i] = ni();\n        return a;\n    }\n    \n    private int ni()\n    {\n        int num = 0, b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private long nl()\n    {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }\n \n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tarr[i] = s.nextInt();\n\t\t}\n\t\tint parity = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint count = 0;\n\t\t\tfor(int j = i + 1; j < n; j++) {\n\t\t\t\tif(arr[j] < arr[i]) {\n\t\t\t\t\tparity ^= 1;\n\t\t\t\t}\t\t\t\n\t\t\t}\n\t\t}\n\t\tint m = s.nextInt();\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint l = s.nextInt(), r = s.nextInt();\n\t\t\tif(((r - l + 1) / 2) % 2 == 1) {\n\t\t\t\tparity ^= 1;\n\t\t\t}\n\t\t\tSystem.out.println(parity == 1 ? \"odd\" : \"even\");\n\t\t}\n\t}\n\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class d {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint size = in.nextInt();\n\t\t\n\t\tint[] vals = new int[size];\n\t\tlong[] cum = new long[size];\n\t\tfor(int i=0; i<size; i++){\n\t\t\tvals[i] = in.nextInt();\n\t\t\t\n\t\t\tint c = 0;\n\t\t\tfor(int j=0; j<i; j++)\n\t\t\t\tif(vals[j] > vals[i]) c++;\n\t\t\t\n\t\t\tif(i != 0) cum[i] = cum[i-1]+c;\n\t\t\telse cum[i] = c;\n\t\t}\n\t\t\n\t\tlong tot = cum[size-1];\n\t\tint q = in.nextInt();\n\n\t\tint[] nv = new int[size];\n\t\tfor(int i=0; i<q; i++)\n\t\t{\n\t\t\tint l = in.nextInt()-1;\n\t\t\tint r = in.nextInt()-1;\n\t\t\tint n = (r-l);\n\t\t\t\n\t\t\tlong add = (n*(n+1))/2 - (cum[r] - cum[l]);\n\t\t\ttot = tot - (cum[r] - cum[l]) + add;\n\t\t\t\n\t\t\tif(tot%2 == 0)\n\t\t\t\tSystem.out.println(\"even\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"odd\");\n\t\t\t\n//\t\t\tfor(int j=0; j<=r-l; j++)\n//\t\t\t\tnv[l+j] = vals[r-j];\n//\t\t\t\n//\t\t\tfor(int j=0; j<=r-l; j++)\n//\t\t\t\tvals[l+j] = nv[l+j];\n\t\t\t\n\t\t}\n\t}\n}\n/*\n3\n1 2 3\n2\n1 2\n2 3\n\n4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n\n*/\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class DD {\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();\n\t\tint [] a=new int [n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=sc.nextInt();\n\t\tint c=0;\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(a[i]>a[j])\n\t\t\t\t\tc^=1;\n\t\tint m=sc.nextInt();\n\t\twhile(m-->0){\n\t\t\tint l=sc.nextInt()-1;\n\t\t\tint r=sc.nextInt()-1;\n\t\t\tint d=r-l+1;\n\t\t\td=d*(d-1)/2;\n\t\t\tc^=(d%2);\n\t\t\tpw.println(c==0? \"even\" : \"odd\");\n\t\t}\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic 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() {while (st == null || !st.hasMoreElements()) {\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (IOException e) {e.printStackTrace();}}\n\t\treturn st.nextToken();}\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\tString nextLine(){String str = \"\";\n\t\ttry {str = br.readLine();}\n\t\tcatch (IOException e) {e.printStackTrace();}\n\t\treturn str;}\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class InversionCounting {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tint n = Integer.parseInt(sc.nextLine());\n\t\tint inversions = 0;\n\t\tint[] data = new int[n];\n\t\t\n\t\tStringTokenizer st = new StringTokenizer(sc.nextLine());\n\t\tfor(int i = 0; i < n; i ++) {\n\t\t\tdata[i] = Integer.parseInt(st.nextToken());\n\t\t}\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(data[i] > data[j])\n\t\t\t\t\tinversions++;\n\t\t\t}\n\t\t}\n\t\t//false = 0, true = 1;\n\t\tboolean inversiontype = (inversions % 2 == 1);\n\t\t\n\t\tint n2 = Integer.parseInt(sc.nextLine());\n\t\tfor(int i = 0; i < n2; i++) {\n\t\t\tst = new StringTokenizer(sc.nextLine());\n\t\t\tint a = Integer.parseInt(st.nextToken());\n\t\t\tint b = Integer.parseInt(st.nextToken());\n\t\t\t\n\t\t\tint parity = (b-a)*(b - a + 1)/2;\n\t\t\tif(parity % 2 == 0) {\n\t\t\t\tif(inversiontype)\n\t\t\t\t\tpw.println(\"odd\");\n\t\t\t\telse\n\t\t\t\t\tpw.println(\"even\");\n\t\t\t} else {\n\t\t\t\tinversiontype = !inversiontype;\n\t\t\t\tif(inversiontype)\n\t\t\t\t\tpw.println(\"odd\");\n\t\t\t\telse\n\t\t\t\t\tpw.println(\"even\");\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class inversioncounting {\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[] permutation = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tpermutation[i] = sc.nextInt();\n\t\t}\n\t\tint m = sc.nextInt();\n\t\tint[][] reverse = new int[m][2];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\treverse[i][0] = sc.nextInt();\n\t\t\treverse[i][1] = sc.nextInt();\n\t\t}\n\t\tint counter = 0;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (permutation[i] > permutation[j]) {\n\t\t\t\t\tcounter++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tboolean bayus = true;\n\t\tif (counter % 2 == 1) {\n\t\t\tbayus = false;\n\t\t}\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint bobib = reverse[i][1] - reverse[i][0] + 1;\n\t\t\tint bafry = nChoose2(bobib);\n\t\t\tif (bafry%2 == 1) {\n\t\t\t\tbayus = !bayus;\n\t\t\t}\n\t\t\tif (bayus) {\n\t\t\t\tSystem.out.println(\"even\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"odd\");\n\t\t\t}\n\t\t}\n\n\t}\n\tprivate static int nChoose2 (int n) {\n\t\treturn (n * (n-1)) / 2;\n\t}\n\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "//package Educational35;\n\n//import FastScanner.Competitive;\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 D {\n        String INPUT = \"4\\n\" +\n                \"1 2 4 3\\n\" +\n                \"4\\n\" +\n                \"1 1\\n\" +\n                \"1 4\\n\" +\n                \"1 4\\n\" +\n                \"2 3\";\n\n        void solve()\n        {\n                final int n = i();\n                final int[] a = ia(n);\n                int count = 0 ;\n                for(int i = 0 ; i<n-1 ; i++)\n                {\n                        for(int j = i+1; j<n ; j++)\n                        {\n                                if(a[j]<a[i])\n                                {\n                                        count++;\n                                }\n                        }\n                }\n                final int q = i();\n                for(int i = 0 ; i<q ; i++)\n                {\n                        final int l = i(), r=i();\n                        final int mid = (r-l+1)/2;\n                        if(mid%2==0)\n                        {\n                                out.println(count%2==0?\"even\":\"odd\");\n                        }\n                        else\n                        {\n                                count++;\n                                out.println(count%2==0?\"even\":\"odd\");\n                        }\n                }\n\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 D().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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class P911D\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tFastScanner scan = new FastScanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n = scan.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = scan.nextInt();\n\t\tint inv = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = i+1; j < n; j++)\n\t\t\t{\n\t\t\t\tif (arr[i] > arr[j])\n\t\t\t\t\tinv++;\n\t\t\t}\n\t\t}\n\t\tinv &= 1;\n\t\t\n\t\tint[] cumul = new int[n+1];\n\t\tfor (int i = 2; i < cumul.length; i++)\n\t\t{\n\t\t\tcumul[i] = cumul[i-1] + i-1;\n\t\t}\n\t\tint q = scan.nextInt();\n\t\tfor (int i = 0; i < q; i++)\n\t\t{\n\t\t\tint a = scan.nextInt()-1;\n\t\t\tint b = scan.nextInt()-1;\n\t\t\tinv += cumul[b-a+1];\n\t\t\tinv &= 1;\n\t\t\tif (inv == 0)\n\t\t\t\tpw.println(\"even\");\n\t\t\telse\n\t\t\t\tpw.println(\"odd\");\n\t\t}\n\t\tpw.flush();\n\t}\n\t\n\tstatic class FastScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner()\n\t\t{\n\t\t\ttry\n\t\t\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)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic String next()\n\t\t{\n\t\t\tif (st.hasMoreTokens())\n\t\t\t\treturn st.nextToken();\n\t\t\ttry\n\t\t\t{\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine()\n\t\t{\n\t\t\tString line = \"\";\n\t\t\ttry\n\t\t\t{\n\t\t\t\tline = br.readLine();\n\t\t\t} catch (Exception e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn line;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class A{\n\n    void solve(){\n        int n=ni();\n        int P[]=new int[n+1];\n        for(int i=1;i<=n;i++) P[i]=ni();\n        a=new int[n+1];\n        BIT=new long[n+1];\n        long cnt=0;\n\n\n        long p=0;\n        for(int i=n;i>=1;i--){\n            p+=querry(P[i]);\n            if(p>=M) p%=M;\n            update(n,P[i],1);\n        }\n        int d=0;\n        if(p%2==0) d=1;\n        int m=ni();\n        while(m-->0){\n            int l=ni(),r=ni();\n            long sz=r-l+1;\n            sz=(sz*(sz-1))/2;\n            if(d==1 && sz%2==0) d=1;\n            else if(d==1 && sz%2!=0) d=0;\n            else if(d==0 && sz%2==0) d=0;\n            else if(d==0 && sz%2!=0) d=1;\n            if(d==1) pw.println(\"even\");\n            else pw.println(\"odd\");\n        }\n    }\n    int a[];\n    long BIT[];\n    void update(int n,int x,int val){\n        a[x]=val;\n        for(;x<=n;x+=(x&-x)) BIT[x]+=val;\n    }\n    long querry(int x){\n        long ans=0;\n        for(;x>0;x-=(x&-x)) ans+=BIT[x];\n        return ans;\n\n    }\n\n    static long d, x, y;\n    static void extendedEuclid(long A, long B) {\n        if(B == 0) {\n            d = A;\n            x = 1;\n            y = 0;\n        }\n        else {\n            extendedEuclid(B, A%B);\n            long temp = x;\n            x = y;\n            y = temp - (A/B)*y;\n        }\n    }\n    static long modInverse(long A, long M)\n    {\n        extendedEuclid(A,M);\n        return (x%M+M)%M;\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 A().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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class P911d {\n\n  private static void solve() {\n    int n = nextInt();\n\n    int[] a = new int[n];\n    for (int i = 0; i < n; i++) {\n      a[i] = nextInt();\n    }\n\n    int cnt = 0;\n    for (int i = 0; i < n; i++) {\n      for (int j = i + 1; j < n; j++) {\n        if (a[i] > a[j]) {\n          cnt++;\n        }\n      }\n    }\n\n    cnt %= 2;\n\n    int m = nextInt();\n    for (int i = 0; i < m; i++) {\n      int l = nextInt();\n      int r = nextInt();\n\n      int size = r - l + 1;\n      int sum = (size * (size - 1)) / 2;\n\n      sum %= 2;\n\n      cnt += sum;\n      cnt %= 2;\n\n      out.println(cnt == 0 ? \"even\" : \"odd\");\n    }\n  }\n\n  private static void run() {\n    br = new BufferedReader(new InputStreamReader(System.in));\n    out = new PrintWriter(System.out);\n\n    solve();\n\n    out.close();\n  }\n\n  private static StringTokenizer st;\n  private static BufferedReader br;\n  private static PrintWriter out;\n\n  private static String next() {\n    while (st == null || !st.hasMoreElements()) {\n      String s;\n      try {\n        s = br.readLine();\n      } catch (IOException e) {\n        return null;\n      }\n      st = new StringTokenizer(s);\n    }\n    return st.nextToken();\n  }\n\n  private static int nextInt() {\n    return Integer.parseInt(next());\n  }\n\n  private static long nextLong() {\n    return Long.parseLong(next());\n  }\n\n  public static void main(String[] args) {\n    run();\n  }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\n//app.\u306f\u5168\u90e8\u3051\u3059\n\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\n//\u6d41\u3059\u524d\u306bfinal\u306b\u3059\u308b\npublic final class EcRound35DApplication {\n\n\tpublic static void main(String[] args) {\n\n\t\tInput input = new Input();\n\t\tinput = SystemInput();\n\t\tList<String> resultList = run(input);\n\t\tfor(String result:resultList){\n\t\t\tSystem.out.println(result);\n\t\t}\n\n\t}\n\n\t//\u6d41\u3059\u524d\u306bstatic\u306b\u3059\u308b\n\tprivate static void tester(Integer no,List<Integer> inputList,List<String> answer) {\n\t\tInput input = new Input();\n\t\tinput.setInput(inputList);\n\t\tList<String> result = run(input);\n\n\t\tif(result.equals(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\n\t\tList<Integer> inputList = new ArrayList<Integer>();\n\n\t\twhile(sc.hasNextInt()) {\n\t\t\tinputList.add(sc.nextInt());\n\t\t}\n\n\t\tinput.setInput(inputList);\n\t\tsc.close();\n\t\treturn input;\n\t}\n\n\t//\u6d41\u3059\u524d\u306bstatic\u306b\u3059\u308b\n\tprivate static List<String> run(Input input) {\n\t\tList<String> result = new ArrayList<String>();\n\n\t\tList<Integer> permutation = input.getPermutationList();\n\t\tInteger count;\n\n\t\tcount = inversion(permutation);\n\n\t\tfor(Integer i = 0;i < input.getQueryNum();i++) {\n\t\t\tcount = count + change(input.getQuery(i));\n\n\t\t\tresult.add(evenOdd(count));\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t//\u30ab\u30a6\u30f3\u30c8\u3059\u308b\n\tprivate static Integer inversion(List<Integer>permutation) {\n\t\tString result = new String();\n\t\tInteger inversionCount = 0;\n\n\t\tfor(Integer i = 0; i < permutation.size(); i++) {\n\t\t\tfor(Integer j = i + 1; j < permutation.size(); j++) {\n\t\t\t\tif(permutation.get(i) > permutation.get(j)) {\n\t\t\t\t\tinversionCount++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn inversionCount;\n\n\t}\n\n\t//\u4ea4\u63db\u6642\u8ffd\u52a0\u5206\u30ab\u30a6\u30f3\u30c8\n\tprivate static Integer change(Query query) {\n\t\tInteger result;\n\n\t\tresult = query.getLength() * (query.getLength() - 1) / 2;\n\n\t\treturn result;\n\t}\n\n\t//\u5224\u5b9a\u3059\u308b\n\tprivate static String evenOdd(Integer i) {\n\t\tif(i % 2 == 0) {\n\t\t\treturn \"even\";\n\t\t}\n\n\t\telse {\n\t\t\treturn \"odd\";\n\t\t}\n\t}\n\n\n\n\tprivate static class Query{\n\t\tprivate Integer l;\n\t\tprivate Integer r;\n\n\t\tpublic void setQuery(Integer l,Integer r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\n\t\tpublic Integer getL() {\n\t\t\treturn l;\n\t\t}\n\t\tpublic void setL(Integer l) {\n\t\t\tthis.l = l;\n\t\t}\n\t\tpublic Integer getR() {\n\t\t\treturn r;\n\t\t}\n\t\tpublic void setR(Integer r) {\n\t\t\tthis.r = r;\n\t\t}\n\t\tpublic Integer getLength(){\n\t\t\treturn r - l + 1;\n\t\t}\n\n\t}\n\n\n\n\t//\u6d41\u3059\u524d\u306bstatic\u306b\u3059\u308b\n\tprivate static class Input{\n\t\tprivate Integer length;\n\t\tprivate List<Integer> permutationList = new ArrayList<Integer>();\n\t\tprivate Integer queryNum;\n\t\tprivate List<Query> queryList = new ArrayList<Query>();\n\n\t\tpublic void setInput(List<Integer> inputList) {\n\t\t\tthis.length = inputList.get(0);\n\n\t\t\tsetPermutationList(inputList.subList(1, length+1));\n\n\t\t\tthis.queryNum = inputList.get(length+1);\n\n\t\t\tfor(Integer j = length+2; j < inputList.size()-1; j = j + 2) {\n\t\t\t\taddQueryList(inputList.get(j),inputList.get(j+1));\n\t\t\t}\n\n//\t\t\tcheckInput();\n\n\t\t}\n\n\t\tpublic void checkInput() {\n\t\t\tSystem.out.println(\"permutation length:\" + permutationList.size());\n\n\t\t\tSystem.out.println(\"permutation:\" + permutationList);\n\n\t\t\tSystem.out.println(\"query length:\" + queryList.size());\n\t\t\tSystem.out.println(\"queries:\");\n\t\t\tfor(Integer i = 0;i < queryList.size();i++) {\n\t\t\t\tSystem.out.println(this.getQueryL(i) + \" \" + this.getQueryR(i));\n\t\t\t}\n\n\t\t}\n\n\t\tpublic Integer getLength() {\n\t\t\treturn length;\n\t\t}\n\n\t\tpublic void setLength(Integer length) {\n\t\t\tthis.length = length;\n\t\t}\n\n\t\tpublic List<Integer> getPermutationList() {\n\t\t\treturn permutationList;\n\t\t}\n\n\t\tpublic void setPermutationList(List<Integer> permutationList) {\n\t\t\tthis.permutationList = permutationList;\n\t\t}\n\n\t\tpublic Integer getPermutation(Integer i) {\n\t\t\treturn permutationList.get(i);\n\t\t}\n\n\t\tpublic void addPermutationList(Integer newPermutation) {\n\t\t\tthis.permutationList.add(newPermutation);\n\t\t}\n\n\t\tpublic Integer getQueryNum() {\n\t\t\treturn queryNum;\n\t\t}\n\n\t\tpublic void setQueryNum(Integer queryNum) {\n\t\t\tthis.queryNum = queryNum;\n\t\t}\n\n\t\tpublic Query getQuery(Integer i) {\n\t\t\treturn queryList.get(i);\n\t\t}\n\n\t\tpublic Integer getQueryL(Integer i) {\n\t\t\treturn queryList.get(i).getL();\n\t\t}\n\n\t\tpublic Integer getQueryR(Integer i) {\n\t\t\treturn queryList.get(i).getR();\n\t\t}\n\n\t\tpublic List<Query> getQueryList() {\n\t\t\treturn queryList;\n\t\t}\n\n\t\tpublic void setQueryList(List<Query> queryList) {\n\t\t\tthis.queryList = queryList;\n\t\t}\n\n\t\tpublic void addQueryList(Query newQuery) {\n\t\t\tthis.queryList.add(newQuery);\n\t\t}\n\n\t\tpublic void addQueryList(Integer l,Integer r) {\n\t\t\tQuery newQuery = new Query();\n\t\t\tnewQuery.setQuery(l, r);\n\t\t\taddQueryList(newQuery);\n\t\t}\n\n\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            String[] response = {\"even\", \"odd\"};\n            int n = in.nextInt();\n            int[] arr = in.nextIntArray(0, n);\n            int swaps = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    if (arr[i] > arr[j]) swaps = (swaps + 1) % 2;\n                }\n            }\n            int m = in.nextInt();\n            for (int i = 0; i < m; i++) {\n                int l = in.nextInt(), r = in.nextInt(), combinaisons = ((r - l) * (r - l + 1)) / 2;\n                if (combinaisons % 2 == 1) {\n                    swaps ^= 1;\n                }\n                out.println(response[swaps]);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private StringTokenizer tokenizer;\n        private BufferedReader reader;\n\n        public InputReader(InputStream inputStream) {\n            reader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        private void fillTokenizer() {\n            if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (Exception e) {\n                    throw new RuntimeException(e);\n                }\n            }\n        }\n\n        public String next() {\n            fillTokenizer();\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public int[] nextIntArray(int offset, int length) {\n            int[] arr = new int[offset + length];\n            for (int i = offset; i < offset + length; i++) {\n                arr[i] = nextInt();\n            }\n            return arr;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.function.Consumer;\n\npublic class Solution {\n\n\n    static MyScanner sc;\n    private static PrintWriter out;\n    static long M2 = 1_000_000_000L + 7;\n\n    private static HashMap<Long, Long>[] mods;\n\n    public static void main(String[] s) throws Exception {\n        StringBuilder stringBuilder = new StringBuilder();\n\n//        stringBuilder.append(\"7 3\\n\" +\n//                \"1 5 2 6 3 7 4\\n\" +\n//                \"2 5 3\\n\" +\n//                \"4 4 1\\n\" +\n//                \"1 7 3\");\n\n//\n//        Random r = new Random(5);\n//        stringBuilder.append(\"100000 5000 \");\n//        for (int i = 0; i < 100000; i++) {\n//            stringBuilder.append(\" \" + (r.nextInt(2000000000) - 1000000000) + \" \");\n//\n//        }\n//        for (int k = 0; k < 5000; k++) {\n//            stringBuilder.append(\" 1 100000 777 \");\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\n        out.flush();\n    }\n\n    private static void solve() throws IOException {\n        int n = sc.nextInt();\n        int[] data = sc.na(n);\n        boolean ev = true;\n        for (int t = 0; t < n - 1; t++) {\n            for (int x = t + 1; x < n; x++) {\n                if (data[t] > data[x]) {\n                    ev = !ev;\n                }\n            }\n        }\n        int m = sc.nextInt();\n        for (int i = 0; i < m; i++) {\n            int dd = -sc.nextInt() + sc.nextInt();\n\n            int dm = (dd + 1) * dd / 2;\n            if (dm % 2 == 1) {\n                ev = !ev;\n            }\n            out.println(ev ? \"even\" : \"odd\");\n        }\n\n\n    }\n\n\n    private static void initData() {\n\n\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\npublic class USACO {\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(reader.readLine());\n        StringTokenizer st = new StringTokenizer(reader.readLine(),\" \");\n        int[] perm = new int[n];\n        int count=0;\n        for (int i=0;i<n;i++) {\n            perm[i]=Integer.parseInt(st.nextToken());\n            for (int j=0;j<i;j++) {\n                if (perm[j]>perm[i]) {\n                    count++;\n                }\n            }\n        }\n        count=count%2;\n        int m = Integer.parseInt(reader.readLine());\n        for (int i=0;i<m;i++) {\n            StringTokenizer st2 = new StringTokenizer(reader.readLine(),\" \");\n            int a = Integer.parseInt(st2.nextToken());\n            int b = Integer.parseInt(st2.nextToken());\n            if ((b-a+1)%4==2||(b-a+1)%4==3) {\n                count++;\n                count=count%2;\n            }\n            if(count%2==0) {\n                System.out.println(\"even\");\n            } else {\n                System.out.println(\"odd\");\n            }\n        }\n    }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\n\npublic class D {\n\n    int N,M;\n    int[] a,l,r;\n\n    private void solve() {\n        N = nextInt();\n\n        a = new int[N];\n        for(int i = 0;i < N;i++) {\n            a[i] = nextInt();\n        }\n\n        M = nextInt();\n\n        l = new int[M];\n        r = new int[M];\n        for(int i = 0;i < M;i++) {\n            l[i] = nextInt();\n            r[i] = nextInt();\n        }\n\n        int count = 0;\n        for(int i = 0;i < N - 1;i++) {\n            for(int j = i + 1;j < N;j++) if (a[i] > a[j]) {\n                count++;\n            }\n        }\n\n        for(int i = 0;i < M;i++) {\n            count += (r[i] - l[i] + 1) * (r[i] - l[i]) / 2;\n            count %= 2;\n            out.println(count == 0 ? \"even\" : \"odd\");\n        }\n    }\n\n    public static void main(String[] args) {\n        out.flush();\n        new D().solve();\n        out.close();\n    }\n\n    /* Input */\n    private static final InputStream in = System.in;\n    private static final PrintWriter out = new PrintWriter(System.out);\n    private final byte[] buffer = new byte[2048];\n    private int p = 0;\n    private int buflen = 0;\n\n    private boolean hasNextByte() {\n        if (p < buflen)\n            return true;\n        p = 0;\n        try {\n            buflen = in.read(buffer);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n        if (buflen <= 0)\n            return false;\n        return true;\n    }\n\n    public boolean hasNext() {\n        while (hasNextByte() && !isPrint(buffer[p])) {\n            p++;\n        }\n        return hasNextByte();\n    }\n\n    private boolean isPrint(int ch) {\n        if (ch >= '!' && ch <= '~')\n            return true;\n        return false;\n    }\n\n    private int nextByte() {\n        if (!hasNextByte())\n            return -1;\n        return buffer[p++];\n    }\n\n    public String next() {\n        if (!hasNext())\n            throw new NoSuchElementException();\n        StringBuilder sb = new StringBuilder();\n        int b = -1;\n        while (isPrint((b = nextByte()))) {\n            sb.appendCodePoint(b);\n        }\n        return sb.toString();\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.*;\nimport java.util.*;\nimport java.math.*;\npublic class D {\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew D().run();\n\t}\n\tint[] BIT;\n\tpublic void run() throws Exception {\n\t\tFastScanner f = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = f.nextInt();\n\t\tint[] arr = new int[n];\n\t\tBIT = new int[n+10];\n\t\tint inv = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tarr[i] = f.nextInt();\n\t\t\tinv ^= (i-query(arr[i])) & 1;\n\t\t\tadd(arr[i]);\n\t\t}\n\t\tint k = f.nextInt();\n\t\twhile(k-->0) {\n\t\t\tint diff = -f.nextInt()+f.nextInt()+1;\n\t\t\tinv ^= (diff*(diff-1)/2) & 1;\n\t\t\tout.println(inv == 1 ? \"odd\" : \"even\");\n\t\t}\n\t\tout.flush();\n\t}\n\n\tpublic int query(int i) {\n\t\ti++;\n\t\tint res = 0;\n\t\twhile(i > 0) {\n\t\t\tres += BIT[i];\n\t\t\ti -= i & -i;\n\t\t}\n\t\treturn res;\n\t}\n\tpublic void add(int i) {\n\t\ti++;\n\t\twhile(i < BIT.length) {\n\t\t\tBIT[i]++;\n\t\t\ti += i & -i;\n\t\t}\n\t}\n\t\n\t\n\t\n    static class FastScanner {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n        public FastScanner() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 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        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        public String nextLine() {\n        \ttry {\n        \t\treturn reader.readLine();\n        \t} catch(IOException e) {\n        \t\tthrow new RuntimeException(e);\n        \t}\n        }\n\n\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author ShekharN\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[] arr = new int[n + 1];\n            for (int i = 1; i <= n; i++) {\n                arr[i] = in.nextInt();\n            }\n            int inversions = 0;\n            for (int i = 1; i <= n; i++) {\n                for (int j = i + 1; j <= n; j++) {\n                    if (arr[i] > arr[j])\n                        inversions++;\n                }\n            }\n            inversions %= 2;\n            int q = in.nextInt();\n            for (int i = 0; i < q; i++) {\n                int l = in.nextInt(), r = in.nextInt();\n                int d = r - l + 1;\n                d = d * (d - 1) / 2;\n                if ((d & 1) == 1) inversions ^= 1;\n                out.println((inversions & 1) == 1 ? \"odd\" : \"even\");\n            }\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader br;\n        private 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        public String nextString() {\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        public int nextInt() {\n            return Integer.parseInt(nextString());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class A\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\n\tvoid solve() \n\t{\n\t\tint n=ni();\n\t\tint a[]=na(n);\n\t\tint INV=0;\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 (a[i]>a[j])\n\t\t\t\t\tINV++;\n\t\tboolean even=INV%2==0;\n\t\tint q=ni();\n\t\twhile (q-->0)\n\t\t{\n\t\t\tint l=ni();\n\t\t\tint r=ni();\n\t\t\tint len=r-l+1;\n\t\t\tlen=(len-1)*(len)/2;\n\t\t\tif (len%2==1)\n\t\t\t\teven=!even;\n\t\t\tif (even)\n\t\t\t\tout.println(\"even\");\n\t\t\telse\n\t\t\t\tout.println(\"odd\");\n\t\t}\n\t}\n\t\n\tint MAX = (int)1e5;\n\tlong factorial[];\n\tvoid findfactorial() \n\t{\n\t\tfactorial = new long[MAX + 1];\n\t\tfactorial[0] = 1;\n\t\tfor (int i = 1; i < MAX + 1; i++) \n\t\t{\n\t\t\tfactorial[i] = mul(i,factorial[i - 1]);\n\t\t}\n\t}\n\t\n\tlong mod=(long)1e9+7;\n\tlong add(long a,long b)\n\t{\n\t\tlong x=(a+b);\n\t\twhile(x>=mod) x-=mod;\n\t\treturn x;\n\t\t\n\t}\n\t\n\t\n\tlong sub(long a,long b)\n\t{\n\t\tlong x=(a-b);\n\t\twhile(x<0) x+=mod;\n\t\treturn x;\n\t\t\n\t}\n\t\n\t\n\tlong mul(long a,long b)\n\t{\n\t\ta%=mod;\n\t\tb%=mod;\n\t\tlong x=(a*b);\n\t\treturn x%mod;\n\t\t\n\t}\n\t\n\tint max(int a,int b)\n\t{\n\t\tif(a>b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t}\n\t\n\tint min(int a,int b)\n\t{\n\t\tif(a>b)\n\t\t\treturn b;\n\t\telse \n\t\t\treturn a;\n\t}\n\t\n\tlong max(long a,long b)\n\t{\n\t\tif(a>b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t\t\n\t}\n\t\n\t\n\tlong min(long a,long b)\n\t{\n\t\tif(a>b)\n\t\t\treturn b;\n\t\telse \n\t\t\treturn a;\n\t\t\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\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 A().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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class D {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = 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 ans = 0;\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(a[i] > a[j]) ans++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint m = in.nextInt();\n\t\t\n\t\tfor(int i = 0; i < m; ++i) {\n\t\t\tint l = in.nextInt();\n\t\t\tint r = in.nextInt();\n\t\t\t\n\t\t\tint size = r-l + 1;\n\t\t\t\n\t\t\tint x = size * size - size;\n\t\t\tx = x >> 1;\n\t\t\n\t\t\tans = ans^x;\n\t\t\tif(ans%2 == 0) System.out.println(\"even\");\n\t\t\telse System.out.println(\"odd\");\n\t\t\t\n\t\t}\n\t}\n\t\n\t\n\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "/*\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    final long MOD = 1000L * 1000L * 1000L + 7;\n    int[] dx = {0, -1, 0, 1};\n    int[] dy = {1, 0, -1, 0};\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int[] arr = nextIntArr(n);\n        int cnt = 0;\n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                if (arr[i] > arr[j]) {\n                    cnt++;\n                }\n            }\n        }\n        int m = nextInt();\n        boolean[] vis = new boolean[n];\n        for (int i = 0; i < m; i++) {\n            int l = nextInt() - 1;\n            int r = nextInt() - 1;\n            int len = r - l + 1;\n            if (len * (len - 1) / 2 % 2 != 0) {\n                cnt++;\n            }\n\n            if (cnt % 2 != 0) {\n                outln(\"odd\");\n            }\n            else {\n                outln(\"even\");\n            }\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    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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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 Liavontsi Brechka\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\n    @SuppressWarnings(\"Duplicates\")\n    class TaskD {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = in.nextIntArray(n);\n            int m = in.nextInt();\n\n            int count = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    if (a[i] > a[j]) count = (count + 1) % 2;\n                }\n            }\n\n            StringBuilder res = new StringBuilder();\n\n            int l, r;\n            while (m-- > 0) {\n                l = in.nextInt() - 1;\n                r = in.nextInt() - 1;\n\n                count = count ^ (((r - l + 1) * (r - l) / 2) % 2);\n                res.append(count == 1 ? \"odd\" : \"even\").append('\\n');\n            }\n\n            out.print(res);\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[] nextIntArray(int size) {\n            int[] array = new int[size];\n            for (int i = 0; i < size; ++i) {\n                array[i] = nextInt();\n            }\n            return array;\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\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 Wolfgang Beyer\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = in.readIntArray(n);\n\n            long count = 0;\n            for (int i = 1; i < n; i++) {\n                for (int j = 0; j < i; j++) {\n                    if (a[j] > a[i]) count++;\n                }\n            }\n            boolean even = count % 2 == 0 ? true : false;\n\n            int m = in.nextInt();\n            for (int i = 0; i < m; i++) {\n                int left = in.nextInt();\n                int right = in.nextInt();\n                int diff = right - left;\n                if ((diff % 4 == 1) || (diff % 4 == 2)) {\n                    even = !even;\n                }\n                if (even) {\n                    out.println(\"even\");\n                } else {\n                    out.println(\"odd\");\n                }\n            }\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[] readIntArray(int n) {\n            int[] ar = new int[n];\n            for (int i = 0; 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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n\tpublic static void main(String[] args){\n\t\tFastScanner scan = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = scan.nextInt();\n\t\tint[] a = new int[n+1];\n\t\tfor(int i = 1; i <= n; i++) a[i] = scan.nextInt();\n\t\tBIT bit = new BIT(n);\n\t\tint p = 0;\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tp ^= bit.atOrAbove(a[i])&1;\n\t\t\tbit.add(a[i], 1);\n\t\t}\n\t\tint m = scan.nextInt();\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint l = scan.nextInt(), r = scan.nextInt();\n\t\t\tint s = r-l+1;\n\t\t\tint in = s*(s-1)/2;\n\t\t\tif((in&1) == 1) p ^= 1;\n\t\t\tout.println(p==0?\"even\":\"odd\");\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class BIT {\n\n\t\tint[] a;\n\t\tint n;\n\n\t\tpublic BIT(int n) {\n\t\t\tthis.n = n;\n\t\t\ta = new int[n+1];\n\t\t}\n\n\t\tpublic void add(int i, int val) {\n\t\t\twhile(i <= n) {\n\t\t\t\ta[i] += val;\n\t\t\t\ti += i & -i;\n\t\t\t}\n\t\t}\n\n\t\tpublic int sum(int j)\n\t\t{\n\t\t\tint res = 0;\n\t\t\tfor(int i = j; i >= 1; i -= (i & -i)) res += a[i];\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic int sum(int i, int j) {\n\t\t\treturn sum(j)-sum(i-1);\n\t\t}\n\t\tpublic int atOrAbove(int index) {\n\t\t\tint sub = 0;\n\t\t\tif (index > 0) sub = sum(index-1);\n\t\t\treturn sum(n) - sub;\n\t\t}\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}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\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_Edu_Round_35 {\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            data[i] = in.nextInt();\n        }\n        FT tree = new FT(n + 1);\n        int result = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            tree.update(data[i], 1);\n            result += tree.get(data[i] - 1);\n            result %= 2;\n        }\n        int q = in.nextInt();\n        int[] tmp = new int[n];\n        for (int i = 0; i < q; i++) {\n            int l = in.nextInt() - 1;\n            int r = in.nextInt() - 1;\n\n            int total = r - l + 1;\n            total = total * (total - 1) / 2;\n            total %= 2;\n\n            result += total;\n            result %= 2;\n            if (result % 2 == 0) {\n                out.println(\"even\");\n            } else {\n                out.println(\"odd\");\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    public static class Point implements Comparable<Point> {\n\n        int x, y;\n\n        public Point(int start, int end) {\n            this.x = start;\n            this.y = end;\n        }\n\n        @Override\n        public int hashCode() {\n            int hash = 5;\n            hash = 47 * hash + this.x;\n            hash = 47 * hash + this.y;\n            return hash;\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            if (obj == null) {\n                return false;\n            }\n            if (getClass() != obj.getClass()) {\n                return false;\n            }\n            final Point other = (Point) obj;\n            if (this.x != other.x) {\n                return false;\n            }\n            if (this.y != other.y) {\n                return false;\n            }\n            return true;\n        }\n\n        @Override\n        public int compareTo(Point o) {\n            return Integer.compare(x, o.x);\n        }\n    }\n\n    public static class FT {\n\n        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                data[index] %= 2;\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                result %= 2;\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces911D {\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[] a = new int[n];\n\t\tsp = br.readLine().split(\" \");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = Integer.parseInt(sp[i]);\n\t\t}\n\t\tint inversions = 0;\n\t\tfor (int i = 0; i < n-1; i++) {\n\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\tif (a[i] > a[j]) {\n\t\t\t\t\tinversions++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tinversions = inversions%2;\n\t\t\n\t\tsp = br.readLine().split(\" \");\n\t\tint m = Integer.parseInt(sp[0]);\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tint l = Integer.parseInt(sp[0]);\n\t\t\tint r = Integer.parseInt(sp[1]);\n\t\t\tif ((r-l+1)%4 == 2 || (r-l+1)%4 == 3) {\n\t\t\t\tinversions = 1-inversions;\n\t\t\t}\n\t\t\tif (inversions == 1) {\n\t\t\t\tSystem.out.println(\"odd\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"even\");\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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.io.InputStream;\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 = 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            int ar[] = in.nextIntArray(n);\n            long dp[][] = new long[n][n];\n            long ct = 0;\n            for (int i = 0; i < n; i++) {\n\n                for (int j = i + 1; j < n; j++) {\n                    if (ar[i] > ar[j]) {\n                        dp[i][j]++;\n                        ct++;\n                    }\n                }\n            }\n            for (int i = n - 2; i >= 0; i--) {\n                for (int j = i + 1; j < n; j++) {\n                    dp[i][j] += dp[i + 1][j];\n                }\n            }\n            int m = in.nextInt();\n            for (int i = 0; i < m; i++) {\n                int l = in.nextInt() - 1;\n                int r = in.nextInt() - 1;\n                long val = (r - l + 1);\n                long estimated = (val * (val - 1)) / 2;\n                long change = estimated - dp[l][r];\n                //System.out.println(ct);\n                ct = ct - dp[l][r];\n                dp[l][r] = change;\n                ct += dp[l][r];\n                if (ct % 2 == 0) {\n                    out.println(\"even\");\n                } else {\n                    out.println(\"odd\");\n                }\n               // System.out.println(ct);\n\n            }\n\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            //*-*------clare------\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            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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class D {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt(), sum = 0;\n        int [] a = new int[n+1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = in.nextInt();\n        }\n        for (int i = 1; i <= n; ++i)\n            for (int j = i + 1; j <= n; ++j)\n                sum += a[i] > a[j] ? 1 : 0;\n        int m = in.nextInt();\n        sum &= 1;\n        for (int i = 1; i <= m; i++) {\n            int l = in.nextInt(), r = in.nextInt();\n            if (((r - l + 1) / 2) % 2 == 1)\n                sum ^= 1;\n            System.out.println(sum == 1 ? \"odd\" : \"even\");\n        }\n    }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import javafx.util.Pair;\n\nimport java.util.*;\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[] arr = new int[n];\n        int chet = 0;\n        for (int i = 0; i < n; i++) {\n            arr[i]=scanner.nextInt();\n            for (int j = 0; j < i; j++) {\n                if (arr[j]>arr[i]) chet^=1;\n            }\n        }\n        n = scanner.nextInt();\n        for (int i = 0; i < n; i++) {\n            int l = scanner.nextInt();\n            int r = scanner.nextInt();\n            if ((((r-l+1)/2)&1)!=0){\n                chet^=1;\n            }\n            if (chet==1){\n                System.out.println(\"odd\");\n            }else{\n                System.out.println(\"even\");\n            }\n        }\n\n    }\n\n\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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           //       |    \\   /        \\  |    |   -----   -------\n    \n    public static void main(String[] args)throws IOException\n    {\n        Reader sc=new Reader();\n        PrintWriter out=new PrintWriter(System.out);\n        int n=sc.i();\n        int arr[]=sc.arr(n);\n        int count=0;\n        for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(arr[j]<arr[i])count++;\n        count%=2;\n        int q=sc.i();\n        while(q-->0)\n        {\n            int a=sc.i();\n            int b=sc.i();\n            long len=((long)(b-a+1)*(b-a))/2;\n            if(len%2==1)count^=1;\n            if(count==0)out.println(\"even\");\n            else out.println(\"odd\");\n        }\n        out.flush();\n    }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class inversions {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n        int[] values = new int[N];\n        for(int i=0;i<N;i++){\n            values[i] = sc.nextInt();\n        }\n        int query = sc.nextInt();\n        int[][] tasks = new int[query][2];\n        for(int i=0;i<query;i++){\n            tasks[i][0] = sc.nextInt();\n            tasks[i][1] = sc.nextInt();\n        }\n        int startinversions = 0;\n        for(int i=1;i<values.length;i++){\n            for(int j=i-1;j>=0;j--){\n                if(values[i]<values[j]){\n                    startinversions++;\n                }\n            }\n        }\n        int value = startinversions%2;\n        for(int[] task : tasks){\n            int n = task[1]-task[0];\n            if(n*(n+1)/2 % 2 != 0){\n                value = (value+1)%2;\n            }\n            if(value==1){\n                System.out.println(\"odd\");\n            }\n            else{\n                System.out.println(\"even\");\n            }\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\n \npublic class lc1 implements Runnable{    \n\t\n\n\t\n\tpublic void run() {\n\t\t\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\t\n\t\tint t = 1;\n\t\t\n\t\twhile(t-- > 0) {\n\t\t\t\n\t\t\tint n = s.nextInt();\n\t\t\t\n\t\t\tint[] a = new int[n + 1];\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\ta[i] = s.nextInt();\n\t\t\t\n\t\t\tint curr = 0;\n\t\t\t\n\t\t\tfor(int i = 1; i <= n; i++)\n\t\t\t\tfor(int j = i + 1; j <= n; j++)\n\t\t\t\t\tif(a[i] > a[j])\n\t\t\t\t\t\tcurr++;\n\t\t\n\t\t\tcurr = curr % 2;\n\t\t\t\n\t\t\tint m = s.nextInt();\n\t\t\t\n\t\t\twhile(m-- > 0) {\n\t\t\t\t\n\t\t\t\tint l = s.nextInt();\n\t\t\t\tint r = s.nextInt();\n\t\t\t\t\n\t\t\t\tint fact = (r - l) % 4;\n\t\t\t\t\n\t\t\t\tif(fact == 1 || fact == 2)\n\t\t\t\t\tcurr = 1 - curr;\n\t\t\t\t\n\t\t\t\tif(curr % 2 == 0)\n\t\t\t\t\tw.println(\"even\");\n\t\t\t\telse\n\t\t\t\t\tw.println(\"odd\");\n\t\t\t}\n\t\t}\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\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new lc1(),\"lc1\",1<<26).start();\n\t}\n}  ", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class D {\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\tint inv=0;\n\t\tint []a=new int [n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=sc.nextInt();\n\t\tfor(int j=0;j<n;j++)\n\t\t\tfor(int i=j+1;i<n;i++)\n\t\t\t\tif(a[j]>a[i])\n\t\t\t\t\tinv=1-inv;\n\n\t\tint m=sc.nextInt();\n\t\tStringBuilder sb=new StringBuilder();\n\t\twhile(m-->0)\n\t\t{\n\t\t\tint l=sc.nextInt();\n\t\t\tint r=sc.nextInt();\n\t\t\tint s=r-l+1;\n\t\t\tif(s*(s-1)/2%2==1)\n\t\t\t\tinv=1-inv;\n\t\t\tif(inv==1)\n\t\t\t\tsb.append(\"odd\\n\");\n\t\t\telse\n\t\t\t\tsb.append(\"even\\n\");\n\t\t}\n\t\tSystem.out.print(sb);\n\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}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\n\n\n    public static void main(String[] args) throws Exception{\n        IO io = new IO(null,null);\n        int n = io.getNextInt(),ans = 0;\n        int [] A = new int[n];\n        for (int i = 0;i < n;i++) {\n            A[i] = io.getNextInt();\n            for (int j = 0;j < i;j++)\n                ans ^= (A[j] > A[i]) ? 1 : 0;\n        }\n        String [] word = {\"even\",\"odd\"};\n        int m = io.getNextInt();\n        for (int i = 0;i < m;i++) {\n            int l = io.getNextInt(),r = io.getNextInt();\n            int len = r - l + 1;\n            long tot = len*(len - 1L)/2;\n            ans ^= tot & 1;\n            io.println(word[ans]);\n        }\n        io.close();\n    }\n}\n\n\n\nclass IO{\n    private BufferedReader br;\n    private StringTokenizer st;\n    private PrintWriter writer;\n    private String inputFile,outputFile;\n\n    public boolean hasMore() throws IOException{\n        if(st != null && st.hasMoreTokens()) return true;\n        if(br != null && br.ready()) return true;\n        return false;\n    }\n    public String getNext() throws FileNotFoundException, IOException{\n        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n        return st.nextToken();\n    }\n\n    public String getNextLine() throws FileNotFoundException, IOException{\n        return br.readLine().trim();\n    }\n\n    public int getNextInt() throws FileNotFoundException, IOException{\n        return Integer.parseInt(getNext());\n    }\n    public long getNextLong() throws FileNotFoundException, IOException{\n        return Long.parseLong(getNext());\n    }\n\n    public void print(double x,int num_digits) throws  IOException{\n        writer.printf(\"%.\" + num_digits + \"f\" ,x);\n    }\n    public void println(double x,int num_digits) throws  IOException{\n        writer.printf(\"%.\" + num_digits + \"f\\n\" ,x);\n    }\n    public void print(Object o) throws  IOException{\n        writer.print(o.toString());\n    }\n\n    public void println(Object o) throws  IOException{\n        writer.println(o.toString());\n    }\n    public IO(String x,String y) throws FileNotFoundException, IOException{\n        inputFile = x;\n        outputFile = y;\n        if(x != null) br = new BufferedReader(new FileReader(inputFile));\n        else br = new BufferedReader(new InputStreamReader(System.in));\n        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));\n        else writer = new PrintWriter(new OutputStreamWriter(System.out));\n    }\n\n    protected void close() throws IOException{\n        br.close();\n        writer.close();\n    }\n    public void outputArr(Object [] A) throws IOException{\n        int L = A.length;\n        for (int i = 0;i < L;i++) {\n            if(i > 0) writer.print(\" \");\n            writer.print(A[i]);\n        }\n        writer.print(\"\\n\");\n    }\n}\n\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n    public static void main(String[] args) throws Exception {\n        MyReader reader = new MyReader(System.in);\n//        MyReader reader = new MyReader(new FileInputStream(\"input.txt\"));\n        MyWriter writer = new MyWriter(System.out);\n        new Solution().run(reader, writer);\n        writer.close();\n    }\n\n    private void run(MyReader reader, MyWriter writer) throws IOException, InterruptedException {\n        int n = reader.nextInt();\n        int[] a = reader.nextIntArray(n);\n        boolean b = false;\n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                if (a[i] > a[j]) {\n                    b = !b;\n                }\n            }\n        }\n        int m = reader.nextInt();\n        for (int i = 0; i < m; i++) {\n            int l = reader.nextInt();\n            int r = reader.nextInt();\n            int d = r - l + 1;\n            if (d * (d - 1) / 2 % 2 == 1) {\n                b = !b;\n            }\n            writer.println(b ? \"odd\" : \"even\");\n        }\n    }\n\n        static class MyReader {\n\n            final BufferedInputStream in;\n            final int bufSize = 1 << 16;\n            final byte buf[] = new byte[bufSize];\n            int i = bufSize;\n            int k = bufSize;\n            boolean end = false;\n            final StringBuilder str = new StringBuilder();\n\n            MyReader(InputStream in) {\n                this.in = new BufferedInputStream(in, bufSize);\n            }\n\n            int nextInt() throws IOException {\n                return (int) nextLong();\n            }\n\n            int[] nextIntArray(int n) throws IOException {\n                int[] m = new int[n];\n                for (int i = 0; i < n; i++) {\n                    m[i] = nextInt();\n                }\n                return m;\n            }\n\n            int[][] nextIntMatrix(int n, int m) throws IOException {\n                int[][] a = new int[n][0];\n                for (int j = 0; j < n; j++) {\n                    a[j] = nextIntArray(m);\n                }\n                return a;\n            }\n\n            long nextLong() throws IOException {\n                int c;\n                long x = 0;\n                boolean sign = true;\n                while ((c = nextChar()) <= 32) ;\n                if (c == '-') {\n                    sign = false;\n                    c = nextChar();\n                }\n                if (c == '+') {\n                    c = nextChar();\n                }\n                while (c >= '0') {\n                    x = x * 10 + (c - '0');\n                    c = nextChar();\n                }\n                return sign ? x : -x;\n            }\n\n            long[] nextLongArray(int n) throws IOException {\n                long[] m = new long[n];\n                for (int i = 0; i < n; i++) {\n                    m[i] = nextLong();\n                }\n                return m;\n            }\n\n            int nextChar() throws IOException {\n                if (i == k) {\n                    k = in.read(buf, 0, bufSize);\n                    i = 0;\n                }\n                return i >= k ? -1 : buf[i++];\n            }\n\n            String nextString() throws IOException {\n                if (end) {\n                    return null;\n                }\n                str.setLength(0);\n                int c;\n                while ((c = nextChar()) <= 32 && c != -1) ;\n                if (c == -1) {\n                    end = true;\n                    return null;\n                }\n                while (c > 32) {\n                    str.append((char) c);\n                    c = nextChar();\n                }\n                return str.toString();\n            }\n\n            String nextLine() throws IOException {\n                if (end) {\n                    return null;\n                }\n                str.setLength(0);\n                int c = nextChar();\n                while (c != '\\n' && c != '\\r' && c != -1) {\n                    str.append((char) c);\n                    c = nextChar();\n                }\n                if (c == -1) {\n                    end = true;\n                    if (str.length() == 0) {\n                        return null;\n                    }\n                }\n                if (c == '\\r') {\n                    nextChar();\n                }\n                return str.toString();\n            }\n\n            char[] nextCharArray() throws IOException {\n                return nextString().toCharArray();\n            }\n\n            char[][] nextCharMatrix(int n) throws IOException {\n                char[][] a = new char[n][0];\n                for (int i = 0; i < n; i++) {\n                    a[i] = nextCharArray();\n                }\n                return a;\n            }\n        }\n\n        static class MyWriter {\n\n            final BufferedOutputStream out;\n            final int bufSize = 1 << 16;\n            final byte buf[] = new byte[bufSize];\n            int i = 0;\n            final byte c[] = new byte[30];\n            static final String newLine = System.getProperty(\"line.separator\");\n\n            MyWriter(OutputStream out) {\n                this.out = new BufferedOutputStream(out, bufSize);\n            }\n\n            void print(long x) throws IOException {\n                int j = 0;\n                if (i + 30 >= bufSize) {\n                    flush();\n                }\n                if (x < 0) {\n                    buf[i++] = (byte) ('-');\n                    x = -x;\n                }\n                while (j == 0 || x != 0) {\n                    c[j++] = (byte) (x % 10 + '0');\n                    x /= 10;\n                }\n                while (j-- > 0)\n                    buf[i++] = c[j];\n            }\n\n            void print(int[] m) throws IOException {\n                for (int a : m) {\n                    print(a);\n                    print(' ');\n                }\n            }\n\n            void print(long[] m) throws IOException {\n                for (long a : m) {\n                    print(a);\n                    print(' ');\n                }\n            }\n\n            void print(String s) throws IOException {\n                for (int i = 0; i < s.length(); i++) {\n                    print(s.charAt(i));\n                }\n            }\n\n            void print(char x) throws IOException {\n                if (i == bufSize) {\n                    flush();\n                }\n                buf[i++] = (byte) x;\n            }\n\n            void print(char[] m) throws IOException {\n                for (char c : m) {\n                    print(c);\n                }\n            }\n\n            void println(String s) throws IOException {\n                print(s);\n                println();\n            }\n\n            void println() throws IOException {\n                print(newLine);\n            }\n\n            void flush() throws IOException {\n                out.write(buf, 0, i);\n                out.flush();\n                i = 0;\n            }\n\n            void close() throws IOException {\n                flush();\n                out.close();\n            }\n        }\n    }", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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\n\npublic class D {\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[]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\tint inv = 0;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tif (a[j] > a[i])\n\t\t\t\t\tinv++;\n\t\t\t}\n\t\t}\n\t\tint m = nextInt();\n\t\tboolean odd = inv % 2==1;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint left = nextInt();\n\t\t\tint right = nextInt();\n\t\t\tlong k = right-left+1;\n\t\t\tif (k*(k-1)/2 % 2==1)\n\t\t\t\todd = !odd;\n\t\t\tif (odd)\n\t\t\t\tpw.println(\"odd\");\n\t\t\telse\n\t\t\t\tpw.println(\"even\");\n\t\t}\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}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n\n\npublic class d {\n\t\n\t\n\tpublic static void main(String args[]) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t//BEGIN HERE\n\t\tint n = in.nextInt();\n\t\tint perm[] = new int[n];\n\t\tfor(int i  = 0; i < n; i++) {\n\t\t\tperm[i] = in.nextInt();\n\t\t}\n\t\tint q = in.nextInt();\n\t\t\n\t\tint inv[] = new int[n];\n\t\tinv[0] = 0;\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tinv[i] = inv[i-1];\n\t\t\tfor(int j = i - 1; j >= 0; j--) {\n\t\t\t\tif(perm[i] < perm[j]) inv[i]++;\n\t\t\t}\n\t\t}\n\t\tboolean parity = inv[n-1] % 2 == 0;\n\t\t\n\t\tfor(int i = 0; i < q; i++) {\n\t\t\tint l = in.nextInt() - 1;\n\t\t\tint r = in.nextInt() -1; \n\t\t\tif(l == r) {\n\t\t\t\tSystem.out.println(parity?\"even\":\"odd\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tint s = r - l + 1;\n\t\t\ts = s * (s-1)/ 2;\n\t\t\tif(s % 2 != 0) {\n\t\t\t\tparity = !parity;\n\t\t\t}\n\t\t\tSystem.out.println(parity?\"even\":\"odd\");\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream i) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(i));\n\t\t\tst = null;\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\tif (st == null) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\tString line = st.nextToken(\"\\n\");\n\t\t\tst = null;\n\t\t\treturn line;\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\t}\n\n\tpublic static class combinatorics {\n\t\tstatic long modInv(long a, long b) {\n\t\t\treturn 1 < a ? b - modInv(b % a, a) * b / a : 1;\n\t\t}\n\n\t\tstatic long factorial[], mod;\n\n\t\tcombinatorics(int n, long MOD) {\n\t\t\tmod = MOD;\n\t\t\tfactorial = new long[n + 1];\n\t\t\tfactorial[0] = 1;\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tfactorial[i] = i * factorial[i - 1];\n\t\t\t\tfactorial[i] %= mod;\n\t\t\t}\n\t\t}\n\n\t\tstatic long nCr(int n, int r) {\n\t\t\tif (r > n)\n\t\t\t\treturn 0;\n\t\t\treturn (factorial[n] * modInv((factorial[n - r] * factorial[r]) % mod, mod)) % mod;\n\t\t}\n\t}\n\n\tpublic static class DisjointSet {\n\t\tint p[], r[], s[];\n\t\tint numDisjoint;\n\n\t\tDisjointSet(int N) {\n\t\t\tnumDisjoint = N;\n\t\t\tr = new int[N];\n\t\t\ts = new int[N];\n\t\t\tp = new int[N];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tp[i] = i;\n\t\t}\n\n\t\tint findSet(int i) {\n\t\t\treturn (p[i] == i) ? i : (p[i] = findSet(p[i]));\n\t\t}\n\n\t\tboolean isSameSet(int i, int j) {\n\t\t\treturn findSet(i) == findSet(j);\n\t\t}\n\n\t\tvoid unionSet(int i, int j) {\n\t\t\tif (!isSameSet(i, j)) // if from different set\n\t\t\t{\n\t\t\t\tnumDisjoint--;\n\t\t\t\tint x = findSet(i), y = findSet(j);\n\t\t\t\tif (r[x] > r[y]) {\n\t\t\t\t\tp[y] = x; // rank keeps the tree short\n\t\t\t\t\ts[x] += s[y];\n\t\t\t\t} else {\n\t\t\t\t\tp[x] = y;\n\t\t\t\t\tif (r[x] == r[y])\n\t\t\t\t\t\tr[y]++;\n\t\t\t\t\ts[y] += s[x];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint sizeOfSet(int i) {\n\t\t\treturn s[findSet(i)];\n\t\t}\n\t};\n\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "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        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            int inv = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < i; j++) {\n                    if (a[j] > a[i]) {\n                        inv++;\n                    }\n                }\n            }\n            int m = in.nextInt();\n            for (int i = 0; i < m; i++) {\n                int l = in.nextInt();\n                int r = in.nextInt();\n                int s = (r - l + 1) * (r - l) / 2;\n                inv = (inv + s) % 2;\n                out.println(inv % 2 == 0 ? \"even\" : \"odd\");\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", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "/* \n * UMANG PANCHAL\n * DAIICT\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class Main\n{\n \n\tstatic LinkedList<Integer> adj[];\n\tstatic ArrayList<Integer> adj1[];\n\tstatic int[] color,visited1;\n\tstatic boolean b[],visited[],possible;\n\tstatic int level[];\n\tstatic Map<Integer,HashSet<Integer>> s;\n\tstatic int totalnodes,colored;\n\tstatic int count[];\n\tstatic long sum[];\n\tstatic int nodes;\n\tstatic double ans=0;\n\tstatic long[] as=new long[10001];\n\tstatic long c1=0,c2=0;\n\tstatic int[] a,d,k;\n\tstatic int max=100000000;\n\tstatic long MOD = (long)1e9 + 7,sm=0,m=Long.MIN_VALUE;\n\tstatic boolean[] prime=new boolean[1000005];\n\tstatic int[] levl;\n    static int[] eat;\n    static int price[];\n    static int size[],res[],par[];\n    static int result=0;\n\t// --------------------My Code Starts Here----------------------\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tin=new InputReader(System.in);\n\t\tw=new PrintWriter(System.out);\n\t\t int n=ni();\n\t\t int[] a=na(n);\n\t\t int ans=0;\n\t\t for(int i=0;i<n;i++)\n\t\t {\n\t\t\t for(int j=i+1;j<n;j++)\n\t\t\t {\n\t\t\t\t if(a[j]<a[i])\n\t\t\t\t\t ans++;\n\t\t\t }\n\t\t }\n\t\t int m=ni();\n\t\t ans=ans%2;\n\t\t while(m-->0)\n\t\t {\n\t\t\t int l=ni(),r=ni();\n\t\t\t int range=r-l+1;\n\t\t\t range=range*(range-1)/2;\n\t\t\t range=range%2;\n\t\t\t ans=(ans+range)%2;\n\t\t\t if(ans==1)\n\t\t\t\t w.println(\"odd\");\n\t\t\t else\n\t\t\t\t w.println(\"even\");\n\t\t }\n       w.close();\n    }\n\t\n\t\n\t\n\tpublic static long nCrModp(long n, long r, long p)\n\t{\n\t    \n\t    long[] C=new long[(int)r+1];\n\t    \n\t \n\t    C[0] = 1; \n\t    \n\t    for (long i = 1; i <= n; i++)\n\t    {\n\t        \n\t        for (long j = Math.min(i, r); j > 0; j--)\n\t \n\t            \n\t            C[(int)j] = (C[(int)j] + C[(int)(j-1)])%p;\n\t    }\n\t    return C[(int)r];\n\t}\n\tpublic static long nCr(long n, long r)\n\t{\n\t\tlong x=1;\n\t\tfor(long i=n;i>=n-r+1;i--)\n\t\t\tx=((x)*(i));\n\t\tfor(long i=r;i>=1;i--)\n\t\t\tx=((x)/(i));\n\t\t\n\t\treturn x%MOD;\n\t}\n\tpublic static long nCrModpDP(long n, long r, long p)\n\t{\n\t\n\t    long[] C=new long[(int)r+1];\n\t \n\t    C[0] = 1; \n\t \n\t \n\t    for (long i = 1; i <= n; i++)\n\t    {\n\t        for (int j = (int)Math.min(i, r); j > 0; j--)\n\t           C[j] = (C[j] + C[j-1])%p;\n\t    }\n\t    return C[(int)r];\n\t}\n\n\tpublic static long nCrModpLucas(long n,long r, long p)\n\t{\n\t  \n\t   if (r==0)\n\t      return 1;\n\t \n\t   long ni = n%p, ri = r%p;\n\t\n\t   return (nCrModpLucas(n/p,r/p, p) * nCrModpDP(ni,ri, p)) % p;  \n\t}\n\t\n\t public static void buildgraph(int n){\n         adj=new LinkedList[n+1];\n         visited=new boolean[n+1];\n         levl=new int[n+1];\n         par=new int[n+1];\n         for(int i=0;i<=n;i++){\n             adj[i]=new LinkedList<Integer>();\n         \n         }\n\n\n     }\n\tpublic static int getSum(long BITree[], int index)\n\t{\n\t    int sum = 0;\n\t    \n\t    while (index > 0)\n\t    {\n\t        sum += BITree[index];\n\t        index -= index & (-index);\n\t    }\n\t    return sum;\n\t}\n\t\n\tpublic static long[] updateBIT(long BITree[], int n, int index, int val)\n\t{\n\t    while (index <= n)\n\t    {\n\t       BITree[index] += val;\n\t       index += index & (-index);\n\t    }\n\t    return BITree;\n\t}\n\t\n\n\t\n\tpublic static boolean isPrime(int n)\n\t{\n\t    // Corner cases\n\t    if (n <= 1)  return false;\n\t    if (n <= 3)  return true;\n\t \n\t    // This is checked so that we can skip \n\t    // middle five numbers in below loop\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        if (n%i == 0 || n%(i+2) == 0)\n\t           return false;\n\t \n\t    return true;\n\t}\n\t\n\t// --------------------My Code Ends Here------------------------\n\t\n\tpublic static String ns()\n\t{\n\t\treturn in.nextLine();\n\t}\n\tpublic static int ni()\n\t{\n\t\treturn in.nextInt();\n\t}\n\tpublic static long nl()\n\t{\n\t\treturn in.nextLong();\n\t}\n\tpublic static int[] na(int n)\n\t{\n\t\ta=new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\ta[i]=ni();\n\t\treturn a;\n\t}\n\tpublic static void sieveOfEratosthenes()\n\t    {\n\t       int n=prime.length;\n\t        for(int i=0;i<n;i++)\n\t            prime[i] = true;\n\t         \n\t        for(int p = 2; p*p <=n; p++)\n\t        {\n\t            if(prime[p] == true)\n\t            {\n\t                for(int i = p*2; i <n; i += p)\n\t                    prime[i] = false;\n\t            }\n\t        }\n\t    }\n\n\tpublic static boolean printDivisors(long n)\n    {\n\t\tlong ans=0;\n        for (int i=1; i<=Math.sqrt(n); i++)\n        {\n            if (n%i==0)\n            {\n                if (n/i == i)\n                    ans++;\n                else \n                {\n                \tans=ans+2;\n                }\n            }\n            if(ans>3)\n            \tbreak;\n        }\n        if(ans==3)\n        \treturn true;\n        else\n        \treturn false;\n    }\n\n  public static void dfs(int i)\n  {\n\t  visited[i]=true;\n\t  for(int j:adj[i])\n\t  {\n\t\t  if(!visited[j])\n\t\t\t  {\n\t\t\t  dfs(j);\n\t\t\t  nodes++;\n\t\t\t  }\n\t  }\n\t  \n  }\n  public static String rev(String s)\n\t{\n\t\tStringBuilder sb=new StringBuilder(s);\n\t\tsb.reverse();\n\t\treturn sb.toString();\n\t}\n\tstatic long lcm(long a, long b)\n\t{\n\t    return a * (b / gcd(a, b));\n\t}\n\tstatic long gcd(long a, long b)\n\t{\n\t    while (b > 0)\n\t    {\n\t        long temp = b;\n\t        b = a % b; // % is remainder\n\t        a = temp;\n\t    }\n\t    return a;\n\t}\n\tstatic InputReader in;\n\tstatic PrintWriter w;\nstatic class InputReader \n{\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{\n  this.stream = stream;\n}\n \npublic int snext()\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    }\n    catch (IOException e)\n    {\n      throw new InputMismatchException();\n    }\n    if (snumChars <= 0)\n      return -1;\n  }\n  return buf[curChar++];\n}\n \npublic 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  {\n    if (c < '0' || c > '9')\n      throw new InputMismatchException();\n    res *= 10;\n    res += c - '0';\n    c = snext();\n  }\n  while (!isSpaceChar(c));\n  return res * sgn;\n}\n \npublic 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  {\n    if (c < '0' || c > '9')\n      throw new InputMismatchException();\n    res *= 10;\n    res += c - '0';\n    c = snext();\n  }\n  while (!isSpaceChar(c));\n  return res * sgn;\n}\t    \npublic String readString() \n{\n  int c = snext();\n  while (isSpaceChar(c)) \n  {\n    c = snext();\n  }\n  StringBuilder res = new StringBuilder();\n  do\n  {\n    res.appendCodePoint(c);\n    c = snext();\n  }\n  while (!isSpaceChar(c));\n  return res.toString();\n}\n \npublic String nextLine() \n{\n  int c = snext();\n  while (isSpaceChar(c))\n    c = snext();\n  StringBuilder res = new StringBuilder();\n  do\n  {\n    res.appendCodePoint(c);\n    c = snext();\n  }\n  while (!isEndOfLine(c));\n  return res.toString();\n}\n \npublic 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 \nprivate boolean isEndOfLine(int c) \n{\n  return c == '\\n' || c == '\\r' || c == -1;\n}\n \npublic interface SpaceCharFilter\n{\n  public boolean isSpaceChar(int ch);\n}\n}\n\t\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class D911 {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        StringTokenizer st;\n\n        int n = Integer.parseInt(br.readLine());\n        st = new StringTokenizer(br.readLine());\n        int[] num = new int[n];\n        for (int i = 0; i < n; i++) {\n            num[i] = Integer.parseInt(st.nextToken());\n        }\n\n        int count = 0;\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < i; j++) {\n                if (num[i] < num[j]) {\n                    count++;\n                }\n            }\n        }\n\n        boolean ans = count % 2 == 0;\n        for (int m = Integer.parseInt(br.readLine()); m-- > 0; ) {\n            st = new StringTokenizer(br.readLine());\n            int l = Integer.parseInt(st.nextToken());\n            int r = Integer.parseInt(st.nextToken());\n            if (((r - l + 1) / 2) % 2 != 0) {\n                ans = !ans;\n            }\n            out.println(ans ? \"even\" : \"odd\");\n        }\n        out.close();\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class D {\n  \n  static InputReader in = new InputReader(System.in);\n  static PrintWriter out = new PrintWriter(System.out);\n  \n  public static void main(String[] args) {\n    boolean even = true;\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      for (int j = 0; j < i; j++) {\n        if (a[j] > a[i]) {\n          even = !even;\n        }\n      }\n    }\n    int m = in.nextInt();\n    for (int i = 0; i < m; i++) {\n      if ((1 - in.nextInt() + in.nextInt()) / 2 % 2 == 1) {\n        even = !even;\n      }\n      if (even)\n        out.println(\"even\");\n      else\n        out.println(\"odd\");\n    }\n    finish();\n  }\n  \n  public static void finish() {\n    out.close();\n    in.close();\n    System.exit(0);\n  }\n\n  static class InputReader implements Iterator<String>, Closeable {\n    // Fast input reader. Based on Kattio.java from open.kattis.com\n    // but has method names to match Scanner\n\n    private BufferedReader r;\n    private String line;\n    private StringTokenizer st;\n    private String token;\n\n    public InputReader(InputStream i) {\n      r = new BufferedReader(new InputStreamReader(i));\n    }\n\n    public boolean hasNext() {\n      return peekToken() != null;\n    }\n\n    public int nextInt() {\n      return Integer.parseInt(nextToken());\n    }\n\n    public double nextDouble() {\n      return Double.parseDouble(nextToken());\n    }\n\n    public long nextLong() {\n      return Long.parseLong(nextToken());\n    }\n\n    public String next() {\n      return nextToken();\n    }\n    \n    public String nextLine() {\n      try {\n        line = r.readLine();\n      } catch (IOException e) {\n        line = null;\n      }\n      token = null;\n      st = null;\n      return line;\n    }\n    \n    public void close() {\n      try {\n        r.close();\n      } catch (IOException e) {\n      }\n    }\n\n    private String peekToken() {\n      if (token == null)\n        try {\n          while (st == null || !st.hasMoreTokens()) {\n            line = r.readLine();\n            if (line == null)\n              return null;\n            st = new StringTokenizer(line);\n          }\n          token = st.nextToken();\n        } catch (IOException e) {\n        }\n      return token;\n    }\n\n    private String nextToken() {\n      String ans = peekToken();\n      token = null;\n      return ans;\n    }\n    \n  }\n\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Template {\n\n    String fileName = \"\";\n    long INF = Long.MAX_VALUE / 3;\n    int MODULO = 1000*1000*1000+7;\n    long[] fenwik;\n    int BORDER = 1000*1000+100;\n    void solve() throws IOException {\n        int n = readInt();\n        int[] a = new int[n];\n        for(int i=0; i<n; ++i){\n            a[i] = readInt();\n        }\n        fenwik = new long[BORDER];\n        long ans = 0;\n        for(int i=n-1;i>=0;--i){\n            ans+=sumFenwik(a[i]);\n            incFenwik(a[i],1);\n        }\n        boolean even = ans % 2 == 0;\n        int m = readInt();\n        for(int i=0; i<m; ++i){\n            int l = readInt();\n            int r = readInt();\n\n            if(((r-l+1)/2)%2==1){\n                even = !even;\n            }\n\n            out.println(even?\"even\":\"odd\");\n        }\n    }\n\n    void incFenwik(int i, int delta){\n        for(;i<BORDER;i = i|(i+1)){\n            fenwik[i]+=delta;\n        }\n    }\n\n    long sumFenwik(int r){\n        long sum = 0;\n        for(;r>=0;r = (r&(r+1))-1){\n            sum+=fenwik[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    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\n    class SegmentTree {\n        int[] t;\n\n        SegmentTree(int[] a) {\n            int n = a.length - 1;\n            t = new int[n * 4];\n            build(a, 1, 1, n);\n        }\n\n        void build(int[] a, int v, int tl, int tr) {\n            if (tl == tr) {\n                t[v] = a[tl];\n                return;\n            }\n\n            int mid = (tr + tl) / 2;\n\n            build(a, 2 * v, tl, mid);\n            build(a, 2 * v + 1, mid + 1, tr);\n\n            t[v] = Math.max(t[2 * v], t[2 * v + 1]);\n        }\n\n        void update(int v, int tl, int tr, int pos, int value) {\n            if (tl == tr) {\n                t[v] = value;\n                return;\n            }\n\n            int mid = (tl + tr) / 2;\n\n            if (pos <= mid) {\n                update(2 * v, tl, mid, pos, value);\n            } else {\n                update(2 * v + 1, mid + 1, tr, pos, value);\n            }\n\n            t[v] = Math.max(t[2 * v], t[2 * v + 1]);\n        }\n\n        int getMax(int v, int tl, int tr, int l, int r) {\n            if (l > r) {\n                return -1000 * 1000;\n            }\n            if (tl == tr) {\n                return t[v];\n            }\n\n            if (l == tl && r == tr) {\n                return t[v];\n            }\n\n            int mid = (tl + tr) / 2;\n\n            int max1 = getMax(2 * v, tl, mid, l, Math.min(mid, r));\n            int max2 = getMax(2 * v + 1, mid + 1, tr, Math.max(mid + 1, l), r);\n\n            return Math.max(max1, max2);\n        }\n    }\n\n    public static void main(String[] args) throws NumberFormatException, IOException {\n        // TODO Auto-generated method stub\n        new Template().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    Template() 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\n    long readLong() throws NumberFormatException, IOException {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class CF911D {\n   public static void main(String[] args){\n      Scanner sc = new Scanner(System.in);\n      \n      int n = sc.nextInt();\n      int[] array = new int[n];\n      for(int i = 0; i < n; i++){\n         array[i] = sc.nextInt();\n      }\n      int count = 0;\n      for(int i = 0; i < array.length; i++){\n         for(int j = i+1; j < array.length; j++){\n            if(array[i] > array[j]){\n               count++;\n            }\n         }\n      }\n      count%=2;\n      int q = sc.nextInt();\n      for(int i = 0; i < q; i++){\n         int l = sc.nextInt();\n         int r = sc.nextInt();\n         int sz = r - l + 1;\n         count += (sz*(sz-1))/2;\n         count %= 2;\n         if(count == 1) \n            System.out.println(\"odd\");\n         else \n            System.out.println(\"even\");\n      }\n   }\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\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\tString[] s=br.readLine().split(\" \");\n\t\tfor(int i=0;i<n;i++){\n\t\t\tA[i]=Integer.parseInt(s[i]);\n\t\t}\n\t\t/*int[][] nck=new int[2000][2000];\n\t\tfor(int i=0;i<=n;i++){\n\t\t\tfor(int j=0;j<=n;j++){\n\t\t\t\tnck[i][j]=0;\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<=n;i++){\n\t\t\tnck[i][0]=1;\n\t\t\tfor(int j=1;j<=i;j++){\n\t\t\t\tnck[i][j]=nck[i-1][j]+nck[i-1][j-1];\n\t\t\t\tnck[i][j]%=2;\n\t\t\t}\n\t\t}*/\n\t\tint inv=0;\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(A[i]>A[j]){\n\t\t\t\t\tinv++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tStringBuilder sb=new StringBuilder(\"\");\n\t\tint m=Integer.parseInt(br.readLine());\n\t\tfor(int i=0;i<m;i++){\n\t\t\ts=br.readLine().split(\" \");\n\t\t\tint li=Integer.parseInt(s[0]);\n\t\t\tint ri=Integer.parseInt(s[1]);\n\t\t\tint tot=ri-li+1;\n\t\t\tinv=inv+tot*(tot-1)/2;\n\t\t\tif(inv%2==0){\n\t\t\t\tsb.append(\"even\\n\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tsb.append(\"odd\\n\");\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(sb);\n\t}\n}", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.util.Queue;\nimport java.util.LinkedList;\nimport java.math.*;\n \n     public class Sample implements Runnable\n    { \n          \n          public  static void solve()\n          {   \n              int n=i(); \n              int[] a=new int[n];\n              for(int i=0;i<n;i++)a[i]=i();\n              int temp=0;\n              for(int i=0;i<n;i++)\n              {\n                for(int j=i+1;j<n;j++)\n                {\n                  if(a[j]<a[i])temp++;\n                }\n              }\n              boolean even=(temp%2==0)?true:false;\n              int m=i();\n              while(m-->0)\n              {\n               int l=i(); int r=i();\n               long tt=(long)(Math.floor(r-l+1)/2);\n               if(tt%2==1)\n               {\n                if(even)\n                {\n                  out.println(\"odd\");\n                  even=false;\n                }\n                else\n                {\n                  out.println(\"even\");\n                  even=true;\n                }\n               }else\n               {\n                if(even)\n                {\n                  out.println(\"even\");\n                  \n                }\n                else\n                {\n                  out.println(\"odd\");\n                   \n                }\n               }\n              }\n             \n          }\n           \n           \n          public void run()\n          {   \n              solve();\n              out.close();\n          }\n \n          public static void main(String[] args) throws IOException\n          { \n                new Thread(null, new Sample(), \"whatever\", 1<<26).start();\n          }\n         abstract static class Pair implements Comparable<Pair>\n         {\n            long a;\n            int b;\n            \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 }  ", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.io.InputStream;\n\npublic class BuildIn {\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        solve(in, out);\n        out.close();\n    }\n    public static void solve(InputReader in, PrintWriter out) throws IOException\n    {\n    \tint n = in.nextInt();\n    \tint[] list = new int[n];\n    \tfor(int i = 0; i < n; i++)\n    \t{\n    \t\tlist[i]=in.nextInt();\n    \t}\n    \t\n    \tint count = 0;\n    \tfor(int i = 0; i < n-1; i++)\n    \t{\n    \t\tfor(int j = i+1; j < n; j++)\n    \t\t{\n    \t\t\tif(list[j]<list[i])\n    \t\t\t{\n    \t\t\t\tcount++;\n    \t\t\t}\n    \t\t}\n    \t}\n    \t\n    \tboolean sta = true;\n    \tif(count%2==1) sta = false;\n    \t\n    \tint m =  in.nextInt();\n    \tfor(int i = 0; i <m; i++)\n    \t{\n    \t\tint a = in.nextInt();\n    \t\tint b = in.nextInt();\n    \t\tif((b-a)%4==2) sta = !sta;\n    \t\tif((b-a)%4==1) sta = !sta;    \t\t\n    \t\tif(sta) out.println(\"even\");\n    \t\telse out.println(\"odd\");\n    \t}\n\t}\n\n\tstatic class InputReader {\n\t        public BufferedReader reader;\n\t        public StringTokenizer tokenizer;\n\n\t        public InputReader(InputStream stream) {\n\t            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t            tokenizer = null;\n\t        }\n\n\t        \n\t        public String next() {\n\t            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t                try {\n\t                    tokenizer = new StringTokenizer(reader.readLine());\n\t                } catch (IOException e) {\n\t                    throw new RuntimeException(e);\n\t                }\n\t            }\n\t            return tokenizer.nextToken();\n\t        }\n\n\t        public int nextInt() {\n\t            return Integer.parseInt(next());\n\t        }\n\t        \n\t        public long nextLong() {\n\t        \treturn Long.parseLong(next());\n\t        }\n\n\t    }\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class TaskD {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = s.nextInt();\n\t\t}\n\t\tint m = s.nextInt();\n\n\t\tint inv = 0;\n\t\t// count inversions\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 (a[i] > a[j]) {\n\t\t\t\t\tinv++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tboolean odd = (inv % 2 == 1);\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint l = s.nextInt();\n\t\t\tint r = s.nextInt() + 1; // r excluding, l including\n\t\t\tint num = (r - l)*(r - l - 1)/2;\n\t\t\tif (num % 2 == 1) {\n\t\t\t\todd = !odd;\n\t\t\t}\n\t\t\tSystem.out.println((odd) ? \"odd\" : \"even\");\n\t\t}\n\t}\n\n}\n", "complexity": "quadratic", "problem": "911_D. Inversion Counting", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class vas2 {\n    public static void main( String[] args ) {\n\tScanner in = new Scanner( System.in );\n\tint n = in.nextInt();\n\tString st = in.next();\n\tint[] a = new int[n];\n\tfor ( int i = 0; i < n; i++ )\n\t    a[i] = st.charAt( i ) - 48;\n\tboolean c = false;\n\tfor ( int i = 1; !c && i < n; i++ ) {\n\t    int s = 0;\n\t    for ( int j = 0; j < i; j++ )\n\t\ts += a[j];\n\t    int t = 0;\n\t    for ( int j = i; j < n; j++ ) {\n\t\tt += a[j];\n\t\tif ( t > s )\n\t\t    if ( t - a[j] != s )\n\t\t\tbreak;\n\t\t    else\n\t\t\tt = a[j];\n\t    }\n\t    if ( t == s )\n\t\tc = true;\n\t}\n\tSystem.out.println( c ? \"YES\" : \"NO\" );\n    }\n}\n", "complexity": "quadratic", "problem": "1030_C. Vasya and Golden Ticket", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.lang.*;\nimport java.math.*;\n \npublic class Main{\n\t\n\tstatic ArrayList a[]=new ArrayList[200001];\n\tstatic int Count(int a[][],int n) {\n\t\tdsu d=new dsu(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(a[i][j]==0) {\n\t\t\t\t\td.union(i, j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint cnt=0;\n\t\tboolean chk[]=new boolean [n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint p=d.root(i);\n\t\t\tif(!chk[p]) {\n\t\t\t\tchk[p]=true;\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t    return cnt;\n\t}\n\tpublic void solve () {\n\t\tInputReader in = new InputReader(System.in);\n\t    PrintWriter pw = new PrintWriter(System.out); \n\t    int n=in.nextInt();\n\t    int a=in.nextInt();\n\t    int b=in.nextInt();\n\t    if(a==1 || b==1) {\n\t    \tint ans[][]=new int [n][n];\n\t    \tint temp=(a==1)?b:a;\n\t    \tfor(int i=1;i<=n-temp;i++) {\n\t    \t\tans[i][i-1]=1;\n\t    \t\tans[i-1][i]=1;\n\t    \t}\n\t    \tint freq=Count(ans,n);\n\t    \tif(freq!=1) {\n\t    \t\tpw.println(\"NO\");\n\t    \t}\n\t    \telse {\n\t    \t\tpw.println(\"YES\");\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(i==j) {\n\t    \t\t\t\t\tpw.print(0);\n\t    \t\t\t\t}\n\t    \t\t\t\telse\n\t    \t\t\t\t\tpw.print((ans[i][j]+((temp==b)?1:0))%2);\n\t    \t\t\t}\n\t    \t\t\tpw.println();\n\t    \t\t}\n\t    \t}\n\t    }\n\t    else {\n\t    \tpw.print(\"NO\");\n\t    }\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\tpublic static void main(String[] args) throws Exception {\n        \n        \n        new Thread(null,new Runnable() {\n        \tpublic void run() {\n        \t\tnew Main().solve();\n        \t}\n        },\"1\",1<<26).start();\n        \n        \n    }\n    static void debug(Object... o) {\n    \tSystem.out.println(Arrays.deepToString(o));\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        {\n            this.stream = stream;\n        }\n        public int snext() \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                } \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 = 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            {\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            {\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 String readString()\n        {\n            int c = snext();\n            while (isSpaceChar(c)) \n            {\n                c = snext();\n            }\n            StringBuilder res = new StringBuilder();\n            do \n            {\n                res.appendCodePoint(c);\n                c = snext();\n            } while (!isSpaceChar(c));\n            return res.toString();\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            {\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        public static long mod = 1000000007;\n        public static int d;\n        public static int p;\n        public static int q;\n        public void extended(int a,int b) {\n        \tif(b==0) {\n        \t\td=a;\n        \t\tp=1;\n        \t\tq=0;\n        \t}\n        \telse\n        \t{\n        \t\textended(b,a%b);\n        \t\tint temp=p;\n        \t\tp=q;\n        \t\tq=temp-(a/b)*q;\n        \t}\n        }\n        public static long[] shuffle(long[] a,Random gen)\n        {\n            int n = a.length;\n            for(int i=0;i<n;i++)\n            {\n                int ind = gen.nextInt(n-i)+i;\n                long temp = a[ind];\n                a[ind] = a[i];\n                a[i] = temp;\n            }\n            return a;\n        }\n        \n        public static void swap(int a, int b){\n            int temp = a;\n            a = b;\n            b = temp;\n        }\n        \n        public static HashSet<Integer> primeFactorization(int n)\n        {\n            HashSet<Integer> a =new HashSet<Integer>();\n            for(int i=2;i*i<=n;i++)\n            {\n                while(n%i==0)\n                {\n                    a.add(i);\n                    n/=i;\n                }\n            }\n            if(n!=1)\n                a.add(n);\n            return a;\n        }\n        \n        public static void sieve(boolean[] isPrime,int n)\n        {\n            for(int i=1;i<n;i++)\n                isPrime[i] = true;\n            \n            isPrime[0] = false;\n            isPrime[1] = false;\n            \n            for(int i=2;i*i<n;i++)\n            {\n                if(isPrime[i] == true)\n                {\n                    for(int j=(2*i);j<n;j+=i)\n                        isPrime[j] = false;\n                }\n            }\n        }\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        static class pair implements Comparable<pair>\n        {\n            Integer x;\n            Long y;\n            pair(int x,long y)\n            {\n                this.x=x;\n                this.y=y;\n                \n            }\n            \n           \n            public int compareTo(pair o) {\n                int result = x.compareTo(o.x);\n                if(result==0)\n                    result = y.compareTo(o.y);\n                \n                return result;\n            }  \n            \n            public String toString()\n            {\n                return x+\" \"+y;\n            }\n            \n            public boolean equals(Object o)\n            {\n                if (o instanceof pair)\n                {\n                    pair p = (pair)o;\n                    return p.x == x && p.y == y ;\n                }\n                return false;\n            }\n            \n            public int hashCode()\n            {\n                return new Long(x).hashCode()*31 + new Long(y).hashCode();\n            }\n        }\n        \n    \n}\nclass pair implements Comparable<pair>\n{\n    Integer x;\n    Long y;\n    pair(int x,long y)\n    {\n        this.x=x;\n        this.y=y;\n        \n    }\n    \n   \n    public int compareTo(pair o) {\n        int result = x.compareTo(o.x);\n        if(result==0)\n            result = y.compareTo(o.y);\n        \n        return result;\n    }  \n    \n    public String toString()\n    {\n        return x+\" \"+y;\n    }\n    \n    public boolean equals(Object o)\n    {\n        if (o instanceof pair)\n        {\n            pair p = (pair)o;\n            return p.x == x && p.y == y ;\n        }\n        return false;\n    }\n    \n    public int hashCode()\n    {\n        return new Long(x).hashCode()*31 + new Long(y).hashCode();\n    }\n}\nclass dsu{\n\tint parent[];\n\tdsu(int n){\n\t\tparent=new int[n+1];\n\t\tfor(int i=0;i<=n;i++)\n\t\t{\n\t\t\tparent[i]=i;\n\t\t}\n\t}\n\tint root(int n) {\n\t\twhile(parent[n]!=n)\n\t\t{ \n\t\t\tparent[n]=parent[parent[n]];\n\t\t\tn=parent[n];\n\t\t}\n\t\treturn n;\n\t}\n\tvoid union(int _a,int _b) {\n\t\tint p_a=root(_a);\n\t\tint p_b=root(_b);\n\t\t\n\t\t\tparent[p_a]=p_b;\n\t\t\n\t\t\t\n\t}\n\tboolean find(int a,int b) {\n\t\tif(root(a)==root(b))\n\t\t\treturn true;\n\t\telse\n\t\t\treturn  false;\n\t}\n\t\n\t\n}\n", "complexity": "quadratic", "problem": "990_D. Graph And Its Complement", "from": "CODEFORCES"}
{"src": "/**\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class SameSumBlocks {\n    public static void main(String[] args) throws Exception {\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int N = sc.nextInt();\n        int[] pre = new int[N + 1];\n        for (int i = 1; i <= N; i++) {\n            pre[i] = pre[i - 1] + sc.nextInt();\n        }\n//        var sumMap = new HashMap<Integer, ArrayList<Pair>>();\n        var sums = new ArrayList<Pair>();\n        for (int i = 1; i <= N; i++) {\n            for (int j = i; j <= N; j++) {\n                int sum = pre[j] - pre[i - 1];\n//                sumMap.computeIfAbsent(sum, val -> new ArrayList<>()).add(new Pair(i, j, sum));\n                sums.add(new Pair(i, j, sum));\n            }\n        }\n        Collections.sort(sums, (p1, p2) -> p1.sum - p2.sum != 0 ? p1.sum - p2.sum : p1.r - p2.r);\n        var ans = new ArrayList<Pair>();\n        int i = 0;\n        while (i < sums.size()) {\n            int j = i;\n            var group = new ArrayList(List.of(sums.get(i)));\n            int last = sums.get(i).r;\n            while (j + 1 < sums.size() && sums.get(j + 1).sum == sums.get(j).sum) {\n                if (sums.get(j + 1).l > last) {\n                    group.add(sums.get(j + 1));\n                    last = sums.get(j + 1).r;\n                }\n                j++;\n            }\n//            System.out.println(group);\n            if (group.size() > ans.size()) {\n                ans = group;\n            }\n            i = j + 1;\n        }\n        out.println(ans.size());\n        for (Pair p : ans) {\n            out.println(p);\n        }\n        out.close();\n    }\n\n    static class Pair {\n        int l, r, sum;\n        public Pair(int ll, int rr, int ss) {\n            l = ll; r = rr; sum = ss;\n        }\n        public String toString() {\n            return l + \" \" + r;\n        }\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            }\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 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.function.BinaryOperator;\nimport java.util.stream.IntStream;\n\npublic class Main {\n    private static InputReader reader = new InputReader(System.in);\n    private static PrintWriter writer = new PrintWriter(System.out);\n\n    public static void main(String[] args) {\n        int n = readInt();\n        long[] a = readLongArray(n);\n        HashMap<Long, List<Block>> blocks = new HashMap<>();\n        for (int j = 0; j < n; j++) {\n            long sum = 0;\n            for (int i = j; i >= 0; i--) {\n                sum += a[i];\n                if (!blocks.containsKey(sum))\n                    blocks.put(sum, new LinkedList<>());\n                List<Block> blockList = blocks.get(sum);\n                if (blockList.size() > 0 && blockList.get(blockList.size() - 1).r == j) continue;\n                blockList.add(new Block(i, j));\n            }\n        }\n\n        List<Block> bestBlocks = new LinkedList<>();\n        for(long sum : blocks.keySet()) {\n            List<Block> blockList = blocks.get(sum);\n            List<Block> curBest = new LinkedList<>();\n            int lastR = -1;\n            for(Block block : blockList) {\n                if (block.l > lastR) {\n                    curBest.add(block);\n                    lastR = block.r;\n                }\n            }\n            if (curBest.size() > bestBlocks.size()) {\n                bestBlocks = curBest;\n            }\n        }\n\n        writer.println(bestBlocks.size());\n        for(Block block : bestBlocks) {\n            writer.printf(\"%d %d\\n\", block.l + 1, block.r + 1);\n        }\n\n        writer.flush();\n    }\n\n    private static int readInt() {\n        return reader.nextInt();\n    }\n\n    private static long readLong() {\n        return Long.parseLong(reader.next());\n    }\n\n    private static 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    private static long[] readLongArray(int size) {\n        long[] array = new long[size];\n        for (int i = 0; i < size; i++) {\n            array[i] = readLong();\n        }\n        return array;\n    }\n\n    private static void reverseIntArray(int[] array) {\n        for (int i = 0; i < array.length / 2; i++) {\n            int temp = array[i];\n            array[i] = array[array.length - i - 1];\n            array[array.length - i - 1] = temp;\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    private static class Block {\n        int l, r;\n        Block(int l, int r) {\n            this.l = l;\n            this.r = r;\n        }\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "// package codeforce.Training1900;\n\nimport java.io.PrintWriter;\nimport java.util.*;\n//https://codeforces.com/problemset/problem/1141/F2\n\npublic class SameSumBlocks {\n    //    MUST SEE BEFORE SUBMISSION\n//    check whether int part would overflow or not, especially when it is a * b!!!!\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n//        int t = sc.nextInt();\n        int t = 1;\n        for (int i = 0; i < t; i++) {\n            solve(sc, pw);\n        }\n        pw.close();\n    }\n\n    static void solve(Scanner 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        Map<Long, List<int[]>> mp = new HashMap<>();\n        long[] pre = new long[n + 1];\n        for (int i = 1; i <= n; i++) {\n            pre[i] = pre[i - 1] + arr[i - 1];\n        }\n        for (int i = 0; i < n; i++) {\n            for (int j = i; j < n; j++) {\n                long sz = pre[j + 1] - pre[i];\n                if (!mp.containsKey(sz)) mp.put(sz, new ArrayList<>());\n                mp.get(sz).add(new int[]{i, j});\n            }\n        }\n        int max = 0;\n        List<int[]> ans = new ArrayList<>();\n        for(List<int[]> ls : mp.values()){\n            Collections.sort(ls, (a, b) -> {\n                if (a[1] == b[1]) return b[0] - a[0];\n                return a[1] - b[1];\n            });\n            List<int[]> tt = new ArrayList<>();\n            int cnt = 0;\n            int pr = -1;\n            for (int i = 0; i < ls.size(); i++) {\n                int[] get = ls.get(i);\n                if (get[0] <= pr) continue;\n                cnt++;\n                tt.add(get);\n                pr = get[1];\n            }\n            if (max < cnt){\n                ans = tt;\n                max = cnt;\n            }\n        }\n        out.println(max);\n        for(int[] v : ans){\n            out.println((v[0] + 1) + \" \" + (v[1] + 1));\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\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 revanth\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        F2SameSumBlocksHard solver = new F2SameSumBlocksHard();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2SameSumBlocksHard {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            long[] a = in.nextLongArray(n);\n            HashMap<Long, ArrayList<Pair>> hm = new HashMap<>();\n            long sum;\n            for (int j = 0; j < n; j++) {\n                sum = 0;\n                for (int i = j; i >= 0; i--) {\n                    sum += a[i];\n                    if (!hm.containsKey(sum))\n                        hm.put(sum, new ArrayList<>());\n                    hm.get(sum).add(new Pair(i + 1, j + 1));\n                }\n            }\n            ArrayList<Pair> al1 = new ArrayList<>();\n            ArrayList<Pair> al2 = new ArrayList<>();\n            int prev;\n            for (ArrayList<Pair> al : hm.values()) {\n                prev = 0;\n                al1.clear();\n                for (Pair p : al) {\n                    if (p.x > prev) {\n                        al1.add(p);\n                        prev = p.y;\n                    }\n                }\n                if (al1.size() > al2.size())\n                    al2 = new ArrayList<>(al1);\n            }\n            out.println(al2.size());\n            for (Pair p : al2)\n                out.println(p.x + \" \" + p.y);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int snumChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int snext() {\n            if (snumChars == -1)\n                throw new InputMismatchException();\n            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            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 long[] nextLongArray(int n) {\n            long a[] = new long[n];\n            for (int i = 0; i < n; i++)\n                a[i] = nextLong();\n            return a;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class Pair implements Comparable<Pair> {\n        public int x;\n        public int y;\n\n        public Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        public boolean equals(Object obj) {\n            if (obj == null)\n                return false;\n            if (obj == this)\n                return true;\n            if (!(obj instanceof Pair))\n                return false;\n            Pair o = (Pair) obj;\n            return o.x == this.x && o.y == this.y;\n        }\n\n        public int hashCode() {\n            return this.x + this.y;\n        }\n\n        public int compareTo(Pair p) {\n            if (x == p.x)\n                return Integer.compare(y, p.y);\n            return Integer.compare(x, p.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 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\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\n\npublic class F547 {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\t\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\t\tlong[] sum = new long[arr.length + 1];\n\t\tfor(int i = 1; i < sum.length; i++)\n\t\t\tsum[i] = sum[i-1] + arr[i-1];\n\t\t\n\t\tHashMap<Long, ArrayList<Pair>> map = new HashMap<>();\n\t\t\n\t\tfor(int i = 0; i < sum.length; i++) {\n\t\t\tfor(int j = i+1; j < sum.length; j++) {\n\t\t\t\tlong diff = sum[j] - sum[i];\n\t\t\t\t\n\t\t\t\tif(!map.containsKey(diff))\n\t\t\t\t\tmap.put(diff, new ArrayList<>());\n\t\t\t\t\n\t\t\t\tArrayList<Pair> list = map.get(diff);\n\t\t\t\tlist.add(new Pair(i, j));\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(long key : map.keySet()) {\n\t\t\tArrayList<Pair> list1 = map.get(key);\n\t\t\tCollections.sort(list1);\n\t\t\t\n\t\t\tArrayList<Pair> list2 = new ArrayList<>();\n\t\t\t\n\t\t\tint end = 0;\n\t\t\tfor(Pair p : list1) {\n\t\t\t\tif(end <= p.a) {\n\t\t\t\t\tlist2.add(p);\n\t\t\t\t\tend = p.b;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tmap.put(key, list2);\n\t\t}\n\t\t\n\t\tlong maxKey = -1;\n\t\tint max = -1;\n\t\tfor(long key : map.keySet()) {\n\t\t\tif(map.get(key).size() > max) {\n\t\t\t\tmax = map.get(key).size();\n\t\t\t\tmaxKey = key;\n\t\t\t}\n\t\t}\n\t\t\n\t\tArrayList<Pair> list = map.get(maxKey);\n\t\tStringBuilder sb = new StringBuilder();\n\t\tsb.append(list.size());\n\t\tsb.append(\"\\n\");\n\t\t\n\t\tfor(Pair p : list) {\n\t\t\tsb.append((1 + p.a) + \" \" + p.b);\n\t\t\tsb.append(\"\\n\");\n\t\t}\n\t\t\n\t\tSystem.out.println(sb.toString());\n\t}\n\t\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint a, b;\n\t\t\n\t\tpublic Pair(int x, int y) {\n\t\t\ta = x;\n\t\t\tb = y;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair other) {\n\t\t\tif(b != other.b) {\n\t\t\t\treturn b - other.b;\n\t\t\t}\n\t\t\treturn other.a - a;\n\t\t}\n\t\t\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + a + \", \" + b + \")\";\n\t\t}\n\t}\n\t\n\t/**\n\t * Source: Matt Fontaine\n\t */\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 chars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tint read() {\n\t\t\tif (chars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= chars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tchars = 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 (chars <= 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\t}\n\n}\n/*\n7\n4 1 2 2 1 5 3\noutputCopy\n3\n7 7\n2 3\n4 5\ninputCopy\n11\n-5 -4 -3 -2 -1 0 1 2 3 4 5\noutputCopy\n2\n3 4\n1 1\ninputCopy\n4\n1 1 1 1\noutputCopy\n4\n4 4\n1 1\n2 2\n3 3\n*/", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.Vector;\nimport java.util.HashMap;\nimport java.util.Comparator;\n\n\npublic class F2{\n\tstatic class Pair{\n\t\tint l;\n\t\tint r;\n\t\tPair(int l, int r){\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn \"(\" + l + \", \" + r + \")\";\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[] a = new int[n+1];\n\t\tfor(int i = 1;i<=n;++i){\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tHashMap<Integer, Vector<Pair>> map = new HashMap<>();\n\t\tfor(int i = 1;i<=n;++i){\n\t\t\tint sum = 0;\n\t\t\tfor(int j = i;j<=n;++j){\n\t\t\t\tsum+=a[j];\n\t\t\t\tif(!map.containsKey(sum))\n\t\t\t\t\tmap.put(sum,new Vector<>());\n\t\t\t\tmap.get(sum).add(new Pair(i,j));\n\t\t\t}\n\t\t}\n\t\tVector<Pair> an = null;\n\t\tfor(Integer key : map.keySet()){\n\t\t\tVector<Pair> vec = map.get(key);\n\t\t\tVector<Pair> ans = new Vector<>();\n\t\t\tans.add(vec.get(0));\n\t\t\tint size = 1;\n\t\t\tfor(int i = 1;i<vec.size();++i){\n\t\t\t\tif(ans.get(size-1).r > vec.get(i).r)\n\t\t\t\t\tans.set(size-1,vec.get(i));\n\t\t\t\telse if(ans.get(size-1).r < vec.get(i).l){\n\t\t\t\t\tans.add(vec.get(i));\n\t\t\t\t\tsize++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(an == null || an.size() < size) an = ans;\n\t\t}\n\t\tStringBuilder res = new StringBuilder().append(an.size() + \"\\n\");\n\t\tfor(int i = 0;i<an.size();++i)\n\t\t\tres.append(an.get(i).l + \" \" + an.get(i).r + \"\\n\");\n\t\tSystem.out.println(res);\n\t}\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.lang.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.regex.*;\nimport java.util.stream.LongStream;\n\npublic class Main{\n\n\tstatic ArrayList a[]=new ArrayList[5000001];\n\tstatic Vector<pair>schedule_it(ArrayList<pair> v) {\n\t\tVector<pair >ans=new Vector<>();\n\t\tCollections.sort(v, new Comparator<pair>() {\n\t\t\tpublic int compare(pair p1,pair p2) {\n\t\t\t\tif(p1.y<p2.y)\n\t\t\t\t\treturn -1;\n\t\t\t\tif(p1.y>p2.y)\n\t\t\t\t\treturn 1;\n\t\t\t\tif(p1.x<p2.x)\n\t\t\t\t\treturn -1;\n\t\t\t\tif(p1.x>p2.x)\n\t\t\t\t\treturn 1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t\tint end=-1;\n\t\tfor(int i=0;i<v.size();i++) {\n\t\t\tpair p=v.get(i);\n\t\t\tif(p.x>end) {\n\t\t\t\tans.add(p);\n\t\t\t\tend=p.y;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static void main(String[] args)\n   {\n       InputReader in=new InputReader(System.in);\n       PrintWriter pw = new PrintWriter(System.out);\n       int n=in.nextInt();\n       long arr[]=new long[n];\n       for(int i=0;i<n;i++) {\n    \t   arr[i]=in.nextLong();\n       }\n       HashMap<Long,Integer>hm=new HashMap<>();\n       int id=0;\n       for(int i=0;i<n;i++) {\n    \t   long sum=0;\n    \t   for(int j=i;j<n;j++) {\n    \t\t   sum+=arr[j];\n    \t\t   if(!hm.containsKey(sum)) {\n    \t\t\t   hm.put(sum, id++);\n    \t\t\t   a[id-1]=new ArrayList<pair>();\n    \t\t   }\n    \t\t   a[hm.get(sum)].add(new pair(i,j));\n    \t   }\n       }\n       Vector<pair>fi=new Vector<>();\n       for(int i=0;i<id;i++) {\n    \t  Vector<pair> v=schedule_it(a[i]);\n    \t   if(v.size()>fi.size()) {\n    \t\t   fi=v;\n    \t   }\n       }\n       pw.println(fi.size());\n       for(int i=0;i<fi.size();i++) {\n    \t   pw.println((fi.get(i).x+1)+\" \"+(fi.get(i).y+1));\n       }\n       pw.flush();\n       pw.close();\n        \n    }\n         private static void debug(Object... o) {\n     \t\tSystem.out.println(Arrays.deepToString(o));\n     \t}\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        { \n            this.stream = stream;\n        }\n        public int snext() \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                } \n                \n                catch (IOException e) \n                {\n                    throw new InputMismatchException();\n                }\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            {\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            {\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        static class tri implements Comparable<tri> {\n            int p, c, l;\n \n            tri(int p, int c, int l) {\n                this.p = p;\n                this.c = c;\n                this.l = l;\n            }\n \n            public int compareTo(tri o) {\n                return Integer.compare(l, o.l);\n            }\n        }\n \n        public String readString()\n        {\n            int c = snext();\n            while (isSpaceChar(c)) \n            {\n                c = snext();\n            }\n            StringBuilder res = new StringBuilder();\n            do \n            {\n                res.appendCodePoint(c);\n                c = snext();\n            } while (!isSpaceChar(c));\n            return res.toString();\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            {\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        public static long mod = 1000000007;\n        public static int d;\n        public static int p;\n        public static int q;\n        \n        public static int[] suffle(int[] a,Random gen)\n        {\n            int n = a.length;\n            for(int i=0;i<n;i++)\n            {\n                int ind = gen.nextInt(n-i)+i;\n                int temp = a[ind];\n                a[ind] = a[i];\n                a[i] = temp;\n            }\n            return a;\n        }\n        \n        public static void swap(int a, int b){\n            int temp = a;\n            a = b;\n            b = temp;\n        }\n        \n       /* public static long primeFactorization(long n)\n        {\n             HashSet<Integer> a =new HashSet<Integer>();\n        \tlong cnt=0;\n            for(int i=2;i*i<=n;i++)\n            {\n                while(a%i==0)\n                {\n                    a.add(i);\n                    a/=i;\n                }\n            }\n            if(a!=1)\n            \tcnt++;\n                //a.add(n);\n            return cnt;\n        }*/\n        \n        public static void sieve(boolean[] isPrime,int n)\n        {\n            for(int i=1;i<n;i++)\n                isPrime[i] = true;\n            \n            isPrime[0] = false;\n            isPrime[1] = false;\n            \n            for(int i=2;i*i<n;i++)\n            {\n                if(isPrime[i] == true)\n                {\n                    for(int j=(2*i);j<n;j+=i)\n                        isPrime[j] = false;\n                }\n            }\n        }\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 long GCD(long a,long b)\n        {\n            if(b==0)\n                return a;\n            else\n                return GCD(b,a%b);\n        }\n        \n        public static void extendedEuclid(int A,int B)\n        {\n            if(B==0)\n            {\n                d = A;\n                p = 1 ;\n                q = 0;\n            }\n            else\n            {\n                extendedEuclid(B, A%B);\n                int temp = p;\n                p = q;\n                q = temp - (A/B)*q;\n            }\n        }\n        \n        public static long LCM(long a,long b)\n        {\n            return (a*b)/GCD(a,b);\n        }\n        \n        public static int LCM(int a,int b)\n        {\n            return (a*b)/GCD(a,b);\n        }\n        \n        public static int binaryExponentiation(int x,int n)\n        {\n            int result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=result * x;\n                x=x*x;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static long binaryExponentiation(long x,long n)\n        {\n            long result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=result * x;\n                x=x*x;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static int modularExponentiation(int x,int n,int M)\n        {\n            int result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=(result * x)%M;\n                x=(x%M*x)%M;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static long modularExponentiation(long x,long n,long M)\n        {\n            long result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=(result%M * x%M)%M;\n                x=(x%M * x%M)%M;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static long modInverse(int A,int M)\n        {\n            return modularExponentiation(A,M-2,M);\n        }\n        \n        public static long modInverse(long A,long M)\n        {\n            return modularExponentiation(A,M-2,M);\n        }\n        \n        public static boolean isPrime(int n)\n        {\n            \n            if (n <= 1)  return false;\n            if (n <= 3)  return true;\n            \n            if (n%2 == 0 || n%3 == 0) \n                return false;\n         \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            \n            return true;\n        }\n        \n         public static long[] shuffle(long[] a, Random gen){ \n                for(int i = 0, n = a.length;i < n;i++){ \n                    int ind = gen.nextInt(n-i)+i; \n                    long d = a[i]; \n                    a[i] = a[ind]; \n                    a[ind] = d; \n                } \n                return a; \n            }\n         static class pair implements Comparable<pair>{\n             Integer x;\n             Integer y;\n             pair(int l,int id){\n                 this.x=l;\n                 this.y=id;\n             }\n              public int compareTo(pair o) {\n                     int result = x.compareTo(o.x);\n                     if(result==0)\n                         result = y.compareTo(o.y);\n                     \n                 return result;\n                 }  \n              public String toString(){\n                 return (x+\" \"+y);\n             }\n       }       \n \n      \n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Codeforces {\n\n\n    static long MOD = 1_000_000_007L;\n\n    static void main2() throws Exception {\n        int n = ni();\n        int[] arr = nia(n);\n        Map<Integer, List<Pair<Integer, Integer>>> map = new HashMap<>(); \n        for(int r = 0; r < n; r++) {\n            int sum = 0;\n            for(int l = r; l >= 0; l--) {\n                sum += arr[l];\n                if(!map.containsKey(sum)) map.put(sum, new ArrayList<Pair<Integer, Integer>>());\n                map.get(sum).add(new Pair<Integer, Integer>(l + 1, r + 1));\n            }\n        }\n        int bestSum = Integer.MIN_VALUE;\n        int bestSumCount = -1;\n        for(Map.Entry<Integer, List<Pair<Integer, Integer>>> entry : map.entrySet()) {\n            int count = 0;\n            int r = -1;\n            for(Pair<Integer, Integer> pair : entry.getValue()) {\n                if(r < pair.first) {\n                    count++;\n                    r = pair.second;\n                }\n            }\n            if(count > bestSumCount) {\n                bestSumCount = count;\n                bestSum = entry.getKey();\n            }\n        }\n        //got best sum\n        println(bestSumCount);\n        int r = -1;\n        for(Pair<Integer, Integer> pair : map.get(bestSum)) {\n            if(r < pair.first) {\n                println(pair.first + \" \" + pair.second);\n                r = pair.second;\n            }  \n        }\n    }\n\n    // ____________________________________________________________________________\n    //|                                                                            |\n    //|  /$$$$$$  /$$$$$$         /$$$$$$   /$$                /$$$$$$   /$$$$$$   |\n    //| |_  $$_/ /$$__  $$       /$$__  $$ | $$               /$$__  $$ /$$__  $$  |\n    //|   | $$  | $$  \\ $$      | $$  \\__//$$$$$$   /$$   /$$| $$  \\__/| $$  \\__/  |\n    //|   | $$  | $$  | $$      |  $$$$$$|_  $$_/  | $$  | $$| $$$$    | $$$$      |\n    //|   | $$  | $$  | $$       \\____  $$ | $$    | $$  | $$| $$_/    | $$_/      |\n    //|   | $$  | $$  | $$       /$$  \\ $$ | $$ /$$| $$  | $$| $$      | $$        |\n    //|  /$$$$$$|  $$$$$$/      |  $$$$$$/ |  $$$$/|  $$$$$$/| $$      | $$        |\n    //| |______/ \\______/        \\______/   \\___/   \\______/ |__/      |__/        |\n    //|____________________________________________________________________________|\n\n\n\n    private static byte[] scannerByteBuffer = new byte[1024]; // Buffer of Bytes\n    private static int scannerIndex;\n    private static InputStream scannerIn;\n    private static int scannerTotal;\n    private static BufferedWriter printerBW;\n    private static boolean DEBUG = false;\n\n    private static int next() throws IOException { // Scan method used to scan buf\n        if (scannerTotal < 0)\n            throw new InputMismatchException();\n        if (scannerIndex >= scannerTotal) {\n            scannerIndex = 0;\n            scannerTotal = scannerIn.read(scannerByteBuffer);\n            if (scannerTotal <= 0)\n                return -1;\n        }\n        return scannerByteBuffer[scannerIndex++];\n    }\n\n    static int ni() throws IOException {\n        int integer = 0;\n        int n = next();\n        while (isWhiteSpace(n)) // Removing startPointing whitespaces\n            n = next();\n        int neg = 1;\n        if (n == '-') { // If Negative Sign encounters\n            neg = -1;\n            n = next();\n        }\n        while (!isWhiteSpace(n)) {\n            if (n >= '0' && n <= '9') {\n                integer *= 10;\n                integer += n - '0';\n                n = next();\n            } else\n                throw new InputMismatchException();\n        }\n        return neg * integer;\n    }\n\n    static long nl() throws IOException {\n        long integer = 0;\n        int n = next();\n        while (isWhiteSpace(n)) // Removing startPointing whitespaces\n            n = next();\n        int neg = 1;\n        if (n == '-') { // If Negative Sign encounters\n            neg = -1;\n            n = next();\n        }\n        while (!isWhiteSpace(n)) {\n            if (n >= '0' && n <= '9') {\n                integer *= 10;\n                integer += n - '0';\n                n = next();\n            } else\n                throw new InputMismatchException();\n        }\n        return neg * integer;\n    }\n\n    static String line() throws IOException {\n        StringBuilder sb = new StringBuilder();\n        int n = next();\n        while (isWhiteSpace(n))\n            n = next();\n        while (!isNewLine(n)) {\n            sb.append((char) n);\n            n = next();\n        }\n        return sb.toString();\n    }\n\n    private static boolean isNewLine(int n) {\n        return n == '\\n' || n == '\\r' || n == -1;\n    }\n\n    private static boolean isWhiteSpace(int n) {\n        return n == ' ' || isNewLine(n) || n == '\\t';\n    }\n\n    static int[] nia(int n) throws Exception {\n        if (n < 0)\n            throw new Exception(\"Array size should be non negative\");\n        int[] array = new int[n];\n        for (int i = 0; i < n; i++)\n            array[i] = ni();\n        return array;\n    }\n\n    static int[][] n2dia(int r, int c) throws Exception {\n        if (r < 0 || c < 0)\n            throw new Exception(\"Array size should be non negative\");\n        int[][] array = new int[r][c];\n        for (int i = 0; i < r; i++)\n            array[i] = nia(c);\n        return array;\n    }\n\n    static long[] nla(int n) throws Exception {\n        if (n < 0)\n            throw new Exception(\"Array size should be non negative\");\n        long[] array = new long[n];\n        for (int i = 0; i < n; i++)\n            array[i] = nl();\n        return array;\n    }\n\n    static float[] nfa(int n) throws Exception {\n        if (n < 0)\n            throw new Exception(\"Array size should be non negative\");\n        float[] array = new float[n];\n        for (int i = 0; i < n; i++)\n            array[i] = nl();\n        return array;\n    }\n\n    static double[] nda(int n) throws Exception {\n        if (n < 0)\n            throw new Exception(\"Array size should be non negative\");\n        double[] array = new double[n];\n        for (int i = 0; i < n; i++)\n            array[i] = nl();\n        return array;\n    }\n\n    static <T> void print(T ... str) {\n        try {\n            for(T ele : str) \n                printerBW.append(ele.toString());\n            if (DEBUG)\n                flush();\n        } catch (IOException e) {\n            System.out.println(e.toString());\n        }\n    }\n\n    static <T> void println(T ... str) {\n        if(str.length == 0) {\n            print('\\n');\n            return;\n        }\n        for(T ele : str)\n            print(ele, '\\n');\n    }\n\n    static void flush() throws IOException {\n        printerBW.flush();\n    }\n\n    static void close() {\n        try {\n            printerBW.close();\n        } catch (IOException e) {\n            System.out.println(e.toString());\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        long startPointTime = System.currentTimeMillis();\n        scannerIn = System.in;\n        printerBW = new BufferedWriter(new OutputStreamWriter(System.out));\n        if (args.length > 0 && args[0].equalsIgnoreCase(\"debug\")\n                || args.length > 1 && args[1].equalsIgnoreCase(\"debug\"))\n            DEBUG = true;\n\n        main2();\n        long endTime = System.currentTimeMillis();\n        float totalProgramTime = endTime - startPointTime;\n        if (args.length > 0 && args[0].equalsIgnoreCase(\"time\") || args.length > 1 && args[1].equalsIgnoreCase(\"time\"))\n            print(\"Execution time is \" + totalProgramTime + \" (\" + (totalProgramTime / 1000) + \"s)\");\n        close();\n    }\n\n    static class Pair <L, R> {\n        L first;\n        R second;\n\n        Pair(L first, R second) {\n            this.first = first;\n            this.second = second;\n        }\n\n        public boolean equals(Object p2) {\n            if (p2 instanceof Pair) {\n                return ((Pair) p2).first.equals(first) && ((Pair) p2).second.equals(second);\n            }\n            return false;\n        }\n\n        public String toString() {\n            return \"(first=\" + first.toString() + \",second=\" + second.toString() + \")\";\n        }\n    }\n\n    static class DisjointSet {\n        int[] arr;\n        int[] size;\n\n        DisjointSet(int n) {\n            arr = new int[n + 1];\n            size = new int[n + 1];\n            makeSet();\n        }\n\n        void makeSet() {\n            for (int i = 1; i < arr.length; i++) {\n                arr[i] = i;\n                size[i] = 1;\n            }\n        }\n\n        void union(int i, int j) {\n            if (i == j)\n                return;\n            if (i > j) {\n                i ^= j;\n                j ^= i;\n                i ^= j;\n            }\n\n            i = find(i);\n            j = find(j);\n\n            if (i == j)\n                return;\n            arr[j] = arr[i];\n            size[i] += size[j];\n            size[j] = size[i];\n        }\n\n        int find(int i) {\n            if (arr[i] != i) {\n                arr[i] = find(arr[i]);\n                size[i] = size[arr[i]];\n            }\n            return arr[i];\n        }\n\n        int getSize(int i) {\n            i = find(i);\n            return size[i];\n        }\n\n        public String toString() {\n            return Arrays.toString(arr);\n        }\n    }\n\n    static boolean isSqrt(double a) {\n        double sr = Math.sqrt(a);\n        return ((sr - Math.floor(sr)) == 0);\n    }\n\n    static long abs(long a) {\n        return Math.abs(a);\n    }\n\n    static int min(int ... arr) {\n        int min = Integer.MAX_VALUE;\n        for (int var : arr)\n            min = Math.min(min, var);\n        return min;\n    }\n\n    static long min(long ... arr) {\n        long min = Long.MAX_VALUE;\n        for (long var : arr)\n            min = Math.min(min, var);\n        return min;\n    }\n\n    static int max(int... arr) {\n        int max = Integer.MIN_VALUE;\n        for (int var : arr)\n            max = Math.max(max, var);\n        return max;\n    }\n\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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<Integer>[] g;\n    int[] a;\n\n    void solve() throws IOException {\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        HashMap<Integer, ArrayList<Pair>> segs = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            int sum = 0;\n            for (int j = i; j < n; j++) {\n                sum += a[j];\n                if (!segs.containsKey(sum))\n                    segs.put(sum, new ArrayList<>());\n                segs.get(sum).add(new Pair(i, j));\n            }\n        }\n\n        int max = 0;\n        ArrayList<Pair> ans = new ArrayList<>();\n        for (Integer k : segs.keySet()) {\n            ArrayList<Pair> list = segs.get(k);\n            ArrayList<Pair> blocks = new ArrayList<>();\n            Collections.reverse(list);\n            int prev = inf;\n            for (Pair p : list) {\n                int l = p.a;\n                int r = p.b;\n                if (r < prev) {\n                    blocks.add(p);\n                    prev = l;\n                }\n            }\n            if (blocks.size() > max) {\n                ans = blocks;\n                max = blocks.size();\n            }\n        }\n        out.println(ans.size());\n        for (Pair p : ans)\n            out.println((p.a+1)+\" \"+(p.b+1));\n    }\n\n\n    class Pair implements Comparable<Pair>{\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} ", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class default_dst {\n    public static void main(String[] args) {\n        in = new FastReader();\n        int n=ni();\n        int[] arr=takeIntegerArrayInput(n);\n        HashMap<Long,ArrayList<pair>> hm=new HashMap<>();\n        int max_size=0;\n        long S=-1;\n        for (int i=0;i<arr.length;i++){\n            long sum=0;\n            for (int j=i;j>=0;j--){\n                sum+=arr[j];\n                if (!hm.containsKey(sum)){\n                    hm.put(sum,new ArrayList<>());\n                }\n                if (hm.get(sum).size()==0||hm.get(sum).get(hm.get(sum).size()-1).y<j){\n                    hm.get(sum).add(new pair(j,i));\n                }\n                if (hm.get(sum).size()>max_size){\n                    max_size=hm.get(sum).size();\n                    S=sum;\n                }\n\n            }\n        }\n        System.out.println(max_size);\n        StringBuilder sb=new StringBuilder();\n        for (int i=0;i<hm.get(S).size();i++){\n            sb.append(hm.get(S).get(i)).append(\"\\n\");\n        }\n        System.out.print(sb.toString());\n\n\n    }\n    static class pair{\n        int x;\n        int y;\n        pair(int x,int y){\n            this.x=x;\n            this.y=y;\n        }\n        @Override\n        public String toString(){\n            return (this.x+1)+\" \"+(this.y+1);\n        }\n    }\n    public static long binarySearch(long low, long high) {\n        while (high - low > 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 long fast_exp_with_mod(long base, long exp) {\n        long MOD=1000000000+7;\n        long res=1;\n        while(exp>0) {\n            if(exp%2==1) res=(res*base)%MOD;\n            base=(base*base)%MOD;\n            exp/=2;\n        }\n        return res%MOD;\n    }\n    public static long gcd(long a, long b)\n    {\n        if (a == 0)\n            return b;\n        return gcd(b%a, a);\n    }\n    static class my_no{\n        long num;\n        long denom;\n\n        @Override\n        public String toString() {\n            if (denom<0){\n                this.num=-this.num;\n                this.denom=-this.denom;\n            }\n            if (num==0)return \"0\";\n            return (num+\"/\"+denom);\n        }\n\n        my_no(int no){\n            this.num=no;\n            this.denom=1;\n        }\n        my_no(long num,long denom){\n            this.num=num;\n            this.denom=denom;\n        }\n\n        my_no multiply(my_no obj){\n            long num1=obj.num;\n            long denom1=obj.denom;\n            long n=num1*num;\n            long d=denom1*denom;\n            long gcd=gcd(n,d);\n            n/=gcd;\n            d/=gcd;\n            return new my_no(n,d);\n\n        }\n//        my_no multiply(my_no obj){\n//            long num1=obj.num;\n//            long denom1=obj.denom;\n//            long num2=this.num;\n//            long denom2=this.denom;\n//\n//        }\n\n        my_no multiply(int no){\n            long n=num*no;\n            long d=denom;\n            long gcd=gcd(n,d);\n            n/=gcd;\n            d/=gcd;\n            return new my_no(n,d);\n\n        }\n    }\n    static void memset(int[][] arr,int val){\n        for (int i=0;i<arr.length;i++){\n            for (int j=0;j<arr[i].length;j++){\n                arr[i][j]=val;\n            }\n        }\n    }\n    static void memset(int[] arr,int val){\n        for (int i=0;i<arr.length;i++){\n            arr[i]=val;\n        }\n    }\n\n\n    static void memset(long[][] arr,long val){\n        for (int i=0;i<arr.length;i++){\n            for (int j=0;j<arr[i].length;j++){\n                arr[i][j]=val;\n            }\n        }\n    }\n    static void memset(long[] arr,long val){\n        for (int i=0;i<arr.length;i++){\n            arr[i]=val;\n        }\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 (i<j){\n            char temp=arr[i];\n            arr[i]=arr[j];\n            arr[j]=temp;\n            ++i;\n            --j;\n        }\n    }\n    static int[]  takeIntegerArrayInput(int no){\n        int[] arr=new int[no];\n        for (int i=0;i<no;++i){\n            arr[i]=ni();\n        }\n        return arr;\n    }\n    static long fast_Multiply(long no , long pow){\n        long result=1;\n        while (pow>0){\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<no;++i){\n            arr[i]=ni();\n        }\n        return arr;\n    }\n    static final long MOD = (long)1e9+7;\n    static FastReader in;\n\n\n    static void p(Object o){\n        System.out.print(o);\n    }\n\n    static void pn(Object o){\n        System.out.println(o);\n    }\n\n    static String n(){\n        return in.next();\n    }\n\n    static String nln(){\n        return in.nextLine();\n    }\n\n    static int ni(){\n        return Integer.parseInt(in.next());\n    }\n\n    static int[] ia(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    static long[] la(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    static long nl(){\n        return Long.parseLong(in.next());\n    }\n\n    static double nd(){\n        return Double.parseDouble(in.next());\n    }\n\n    static class FastReader{\n        BufferedReader br;\n        StringTokenizer st;\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        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 void println(String[] arr){\n        for (int i=0;i<arr.length;++i){\n            System.out.println(arr[i]);\n        }\n    }\n\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tReader in = new Reader();\n\t\tint n = in.nextInt();\n\t\tint[] a = in.na(n);\n\t\tHashMap<Long, ArrayList<Pair>> v = new HashMap<>();\n\t\tfor(int i = 0; i<n; i++) {\n\t\t\tlong s  = 0;\n\t\t\tfor(int j = i; j<n; j++) {\n\t\t\t\ts+=a[j];\n\t\t\t\tPair p = new Pair(i+1, j+1);\n\t\t\t\tif(v.containsKey(s)) {\n\t\t\t\t\tv.get(s).add(p);\n\t\t\t\t}else {\n\t\t\t\t\tArrayList<Pair> xd = new ArrayList<>();\n\t\t\t\t\txd.add(p);\n\t\t\t\t\tv.put(s,xd);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrayList<Pair> ans = new ArrayList<>();\n\t\tfor(Entry<Long,ArrayList<Pair>> e : v.entrySet()) {\n\t\t\tArrayList<Pair> pairs = e.getValue();\n\t\t\tCollections.sort(pairs);\n\t\t\tStack<Pair> st = new Stack<>();\n\t\t\tfor(int i = 0; i<pairs.size(); i++) {\n\t\t\t\tPair cur = pairs.get(i);\n\t\t\t\tif(st.isEmpty()||st.peek().r<cur.l) {\n\t\t\t\t\tst.push(cur);\n\t\t\t\t}else if(st.peek().r>cur.r) {\n\t\t\t\t\t\tst.pop();\n\t\t\t\t\t\tst.push(cur);\n\t\t\t\t}\n\t\t\t\tif(st.size()>ans.size()) ans = new ArrayList<>(st);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans.size());\n\t\tfor(Pair p : ans)\n\t\t\tSystem.out.println(p.l +\" \"+p.r);\n\t}\n\tstatic class Pair implements Comparable<Pair>{\n\t\tint l,r;\n\t\tpublic Pair(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn this.l - o.l;\n\t\t}\n\t}\n\tstatic class Reader {\n\t\tstatic BufferedReader br;\n\t\tstatic StringTokenizer st;\n\n\t\tpublic Reader() {\n\t\t\tthis.br = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic 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] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nl(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 String[] nS(int n) {\n\t\t\tString[] a = new String[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = next();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int nextInt() {\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\treturn Integer.parseInt(st.nextToken());\n\t\t}\n\n\t\tpublic double nextDouble() {\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\treturn Double.parseDouble(st.nextToken());\n\t\t}\n\n\t\tpublic Long nextLong() {\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\treturn Long.parseLong(st.nextToken());\n\t\t}\n\n\t\tpublic String next() {\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\treturn st.nextToken();\n\t\t}\n\n\t\tpublic static void readLine() {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    \n    static class Node implements Comparable<Node>{\n        int sum;\n        int l;\n        int r;\n        Node next;\n        int nb;\n        Node ini;\n        boolean not;\n        public Node(int sum,int l,int r){\n            this.sum = sum;\n            this.l = l;\n            this.r = r;\n            nb = 0;\n            not = false;\n            ini = null;\n        }\n        \n        @Override\n        public int compareTo(Node node){\n            if(sum-node.sum!=0) return sum-node.sum;\n            else if(l-node.l!=0) return l-node.l;\n            else return r - node.r;\n        }\n    }\n    \n    public static void main(String[] args)throws IOException{\n                \n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        \n        PrintWriter out = new PrintWriter(System.out);\n        \n        int n = Integer.parseInt(st.nextToken());\n        \n        TreeSet<Node> ts = new TreeSet<Node>();\n        \n        st = new StringTokenizer(br.readLine());\n        int[] a = new int[n+1];\n        for(int i=1;i<=n;i++) a[i] = Integer.parseInt(st.nextToken());\n        \n        int[] s = new int[n+1];\n        for(int i=1;i<=n;i++) s[i] = s[i-1] + a[i];\n        \n        for(int i=1;i<=n;i++){\n            for(int j=i;j<=n;j++){\n                ts.add(new Node(s[j]-s[i-1],i,j));\n            }\n        }\n        int minvalue = -2000*(int)Math.pow(10,5);\n        int maxvalue = 2000*(int)Math.pow(10,5);\n        ts.add(new Node(minvalue,0,0));\n        ts.add(new Node(maxvalue,0,0));\n        //System.out.println(minvalue);\n        Node node = ts.higher(ts.first());\n        \n        int sum = 0;\n        \n        \n        \n        int max = 0;\n        Node m = null;\n        \n        while(node.sum!=maxvalue){\n            \n            sum = node.sum;\n            while(node.sum==sum){\n                node = ts.higher(node);\n            }\n            \n            Node var = ts.lower(node);\n           // System.out.println(sum+\" \"+var.sum);\n            max = 0;\n            while(var.sum==sum){\n                \n                Node next = ts.higher(new Node(sum,var.r+1,0));\n                \n                if(max>1+next.nb){\n                    var.nb = max;\n                    var.ini = m;\n                }\n                else if(next.ini==null){\n                \n                    var.nb = 1 + next.nb;\n                    var.next = next;\n                    if(max<var.nb){\n                        max = var.nb;\n                        m = var;\n                    }\n                    \n                    \n                }else{\n                    \n                    var.nb = 1 + next.nb;\n                    var.next = next.ini;\n                    if(max<var.nb){\n                        max = var.nb;\n                        m = var;\n                    }\n                    \n                }\n                \n            \n                var = ts.lower(var);\n                    \n                //System.out.println(sum+\" \"+var.sum);\n            }\n            \n            \n        }\n        \n        int k = 0;\n        Node best = new Node(minvalue,0,0);\n\n        //var = new Node(minvalue,0,0);\n        for(Node var:ts){\n            if(k<var.nb){\n                k = var.nb;\n                best = var;\n                if(var.ini!=null) best = var.ini;\n            }\n        }\n        \n        if(k==0) System.out.println(\"erreur\");\n        else{\n            \n            out.println(k);\n            sum = best.sum;\n            while(best.sum==sum){\n                out.println(best.l+\" \"+best.r);\n                best = best.next;\n            }\n            \n        }\n        \n        \n        out.flush();\n        \n    }\n    \n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.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 *\n * @author Washoum\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        inputClass in = new inputClass(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F2SameSumBlocksHard solver = new F2SameSumBlocksHard();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2SameSumBlocksHard {\n        public void solve(int testNumber, inputClass sc, PrintWriter out) {\n            int n = sc.nextInt();\n            int[] tab = new int[n];\n            int[] s = new int[n];\n            for (int i = 0; i < n; i++) {\n                tab[i] = sc.nextInt();\n                if (i > 0)\n                    s[i] = s[i - 1] + tab[i];\n                else\n                    s[0] = tab[0];\n            }\n            HashMap<Integer, F2SameSumBlocksHard.Pair> sums = new HashMap<>();\n            F2SameSumBlocksHard.Pair p;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j <= i; j++) {\n                    if (j > 0) {\n                        if (sums.get(s[i] - s[j - 1]) != null) {\n                            if (sums.get(s[i] - s[j - 1]).last < j) {\n                                sums.get(s[i] - s[j - 1]).sum++;\n                                sums.get(s[i] - s[j - 1]).last = i;\n                            }\n                        } else {\n                            p = new F2SameSumBlocksHard.Pair();\n                            p.sum = 1;\n                            p.last = i;\n                            sums.put(s[i] - s[j - 1], p);\n                        }\n                    } else {\n                        if (sums.get(s[i]) != null) {\n                            if (sums.get(s[i]).last < j) {\n                                sums.get(s[i]).sum++;\n                                sums.get(s[i]).last = i;\n                            }\n                        } else {\n                            p = new F2SameSumBlocksHard.Pair();\n                            p.sum = 1;\n                            p.last = i;\n                            sums.put(s[i], p);\n                        }\n                    }\n                }\n            }\n\n            Iterator<Map.Entry<Integer, F2SameSumBlocksHard.Pair>> it = sums.entrySet().iterator();\n            Map.Entry<Integer, F2SameSumBlocksHard.Pair> t;\n            int maxsum = 0;\n            int cnt = 0;\n            while (it.hasNext()) {\n                t = it.next();\n                if (t.getValue().sum > cnt) {\n                    maxsum = t.getKey();\n                    cnt = t.getValue().sum;\n                }\n            }\n\n            out.println(cnt);\n            int start = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = start; j <= i; j++) {\n                    if (j > 0) {\n                        if (s[i] - s[j - 1] == maxsum) {\n                            out.println((j + 1) + \" \" + (i + 1));\n                            start = i + 1;\n                            break;\n                        }\n                    } else {\n                        if (s[i] == maxsum) {\n                            out.println((j + 1) + \" \" + (i + 1));\n                            start = i + 1;\n                            break;\n                        }\n                    }\n                }\n            }\n\n\n        }\n\n        static class Pair {\n            int sum;\n            int last;\n\n        }\n\n    }\n\n    static class inputClass {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public inputClass(InputStream in) {\n\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\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    String filename = \"\";\n\n    final int INF = 1_000_000_000;\n    void solve() {\n        int n = readInt();\n        int[] a = new int[n];\n        for(int i = 0;i<n;i++){\n            a[i] = readInt();\n        }\n        Map<Integer, Integer>[] maps = new Map[n];\n        Map<Integer, Integer> sums = new HashMap();\n        for(int i = 0;i<n;i++){\n            maps[i] = new HashMap<>();\n        }\n\n        for(int i = 0;i<n;i++){\n            int summ = 0;\n            for(int j = i;j<n;j++){\n                summ += a[j];\n                if(!maps[i].containsKey(summ)) maps[i].put(summ, j);\n                int x = sums.getOrDefault(summ, 0);\n                sums.put(summ, x + 1);\n            }\n        }\n        int max = 0;\n        int goodSumm = 0;\n        for(int summ : sums.keySet()){\n            if(sums.get(summ) <= max) continue;\n            int right = -1;\n            int ans = 0;\n            for(int j = 0;j<n;j++){\n                if(!maps[j].containsKey(summ)) continue;\n                int end = maps[j].get(summ);\n                if(right == -1){\n                    right = end;\n                    ans++;\n                    continue;\n                }\n\n                if(j > right){\n                    right = end;\n                    ans++;\n                    continue;\n                }\n\n                if(end < right){\n                    right = end;\n                }\n            }\n            if(max < ans){\n                max = ans;\n                goodSumm = summ;\n            }\n        }\n        int left = -1;\n        int right = -1;\n        List<Integer> ans = new ArrayList<>();\n        for(int j = 0;j<n;j++){\n            if(!maps[j].containsKey(goodSumm)) continue;\n            int start = j;\n            int end = maps[j].get(goodSumm);\n            if(right == -1){\n                left = j;\n                right = end;\n                continue;\n            }\n\n            if(start > right){\n                ans.add(left + 1);\n                ans.add(right + 1);\n                left = start;\n                right = end;\n                continue;\n            }\n\n            if(end < right){\n                left = start;\n                right = end;\n            }\n        }\n        ans.add(left + 1);\n        ans.add(right  + 1);\n        out.println(max);\n        for(int i  = 0;i<ans.size();i+=2){\n            out.println(ans.get(i) + \" \" + ans.get(i + 1));\n        }\n    }\n\n    public static void main(String[] args) throws FileNotFoundException {\n        new A().run();\n    }\n    void run() throws FileNotFoundException {\n        init();\n        solve();\n        out.close();\n    }\n    BufferedReader in;\n    PrintWriter out;\n\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init() throws FileNotFoundException {\n        if(!filename.equals(\"\")) {\n            in = new BufferedReader(new FileReader(new File(filename + \".in\")));\n            out = new PrintWriter(new File(filename + \".out\"));\n            return;\n        }\n\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    String readLine(){\n        try{\n            return in.readLine();\n        }catch (Exception e){\n            throw new RuntimeException(e);\n        }\n    }\n\n    String readString(){\n        while(!tok.hasMoreTokens()){\n            String nextLine = readLine();\n            if(nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt(){\n        return Integer.parseInt(readString());\n    }\n\n    long readLong(){\n        return Long.parseLong(readString());\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class F11141 {\n\tstatic class Solver {\n\n\t\tArrayList<int[]> ranges[];\n\t\tHashMap<Long, Integer> hm = new HashMap<>();\n\n\t\tint id(long s) {\n\t\t\tif (!hm.containsKey(s))\n\t\t\t\thm.put(s, hm.size());\n\t\t\treturn hm.get(s);\n\t\t}\n\t\t\n\t\t// max disjoint range set in ranges[r]\n\t\tint[] memo;\n\t\tint go(int r) {\n\t\t\tmemo[N] = 0;\n\t\t\tint last = N;\n\t\t\tfor(int[] a : ranges[r]) {\n\t\t\t\twhile(a[0] < last) {\n\t\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\t\tlast--;\n\t\t\t\t}\n\t\t\t\tmemo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));\n\t\t\t\tlast = a[0];\n\t\t\t}\n\t\t\treturn memo[last];\n\t\t}\n\n\t\tArrayDeque<int[]> ans = new ArrayDeque<>();\n\t\t\n\t\tvoid go2(int r) {\n\t\t\tmemo[N] = 0;\n\t\t\tint last = N;\n\t\t\tint minAt[] = new int[N], oo = 987654321;\n\t\t\tArrays.fill(minAt, oo);\n\t\t\tfor(int[] a : ranges[r]) {\n\t\t\t\tminAt[a[0]] = Math.min(minAt[a[0]], a[1] - a[0]);\n\t\t\t\twhile(a[0] < last) {\n\t\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\t\tlast--;\n\t\t\t\t}\n\t\t\t\tmemo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));\n\t\t\t\tlast = a[0];\n\t\t\t}\n\t\t\twhile(0 < last) {\n\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\tlast--;\n\t\t\t}\n\t\t\tint k = 0;\n\t\t\tfor(; k < N;) {\n\t\t\t\tif(minAt[k] == oo || memo[k] != 1 + memo[k + minAt[k] + 1]) k++;\n\t\t\t\telse {\n\t\t\t\t\tans.push(new int[] {k, k + minAt[k]});\n\t\t\t\t\tk += minAt[k] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tSolver() {\n\t\t\tranges = new ArrayList[2250001];\n\t\t\tfor (int i = 0; i < ranges.length; i++)\n\t\t\t\tranges[i] = new ArrayList<>();\n\t\t}\n\n\t\tint N, LID;\n\t\tlong[] a;\n\n\t\tvoid solve(Scanner s, PrintWriter out) {\n\t\t\tN = s.nextInt();\n\t\t\ta = new long[N + 1];\n\t\t\tfor (int i = 1; i <= N; i++)\n\t\t\t\ta[i] = s.nextLong() + a[i - 1];\n\t\t\tfor (int i = N; i >= 1; i--)\n\t\t\t\tfor (int j = i; j <= N; j++) {\n\t\t\t\t\tint x = id(a[j] - a[i - 1]);\n\t\t\t\t\tranges[x].add(new int[] { i - 1, j - 1 });\n\t\t\t\t}\n\t\t\t\n\t\t\tint best = 0, bid = -1;\n\t\t\tmemo = new int[N + 1];\n\t\t\tArrays.sort(ranges, (a, b) -> b.size() - a.size());\n\t\t\tfor(int i = 0; i < ranges.length; i++, LID++) {\n\t\t\t\tif(ranges[i].size() <= best) break;\n\t\t\t\tint ans = go(i);\n\t\t\t\tif(ans > best) {\n\t\t\t\t\tbest = ans;\n\t\t\t\t\tbid = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// backtrack on bid\n\t\t\tout.println(best);\n\t\t\tgo2(bid);\n\t\t\t\t\t\t\n\t\t\twhile(!ans.isEmpty()) {\n\t\t\t\tint[] c = ans.pop();\n\t\t\t\tout.println(++c[0] + \" \" + ++c[1]);\n\t\t\t}\n\t\t\t\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner s = new Scanner(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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class ProblemF {\n    private static boolean debug = false;\n\n    private static int N;\n    private static int[] A;\n\n    private static void solveProblem(InputStream instr) throws Exception {\n        InputReader sc = new InputReader(instr);\n        int testCount = 1;\n        if (debug) {\n            testCount = sc.nextInt();\n        }\n\n        for (int t = 1; t <= testCount; t++) {\n            printDebug(\"------ \" + t + \" ------\");\n            N = sc.nextInt();\n            A = readInts(sc, N);\n            Object result = solveTestCase();\n            System.out.println(result);\n        }\n    }\n\n    private static Object solveTestCase() {\n        int sum[] = new int[N];\n        sum[0] = A[0];\n        for (int i = 1; i < N; i++) {\n            sum[i] = sum[i - 1] + A[i];\n        }\n        TreeMap<Integer, List<int[]>> map = new TreeMap<>();\n        for (int i = 0; i < N; i++) {\n            for (int j = i; j < N; j++) {\n                int groupSum = sum[j] - (i == 0 ? 0 : sum[i - 1]);\n                map.putIfAbsent(groupSum, new ArrayList<>());\n                map.get(groupSum).add(new int[]{i, j});\n            }\n        }\n        int max = -1;\n        List<int[]> maxAnswer = null;\n        for (Map.Entry<Integer, List<int[]>> entry : map.entrySet()) {\n            List<int[]> values = entry.getValue();\n            if (values.size() <= max) {\n                continue;\n            }\n            List<int[]> curr = findMax(values);\n            if (curr.size() > max) {\n                max = curr.size();\n                maxAnswer = curr;\n\n            }\n        }\n        List<String> answer = new ArrayList<>();\n        for (int[] value : maxAnswer) {\n            answer.add((value[0] + 1) + \" \" + (value[1] + 1));\n        }\n        return max + \"\\n\" + joinValues(answer, \"\\n\");\n    }\n\n    private static List<int[]> findMax(List<int[]> values) {\n        values.sort(new Comparator<int[]>() {\n            @Override\n            public int compare(int[] o1, int[] o2) {\n                return o1[1] - o2[1];\n            }\n        });\n        List<int[]> answer = new ArrayList<>();\n        int right = -1;\n        for (int i = 0; i < values.size(); i++) {\n            int[] value = values.get(i);\n            if (value[0] > right) {\n                answer.add(value);\n                right = value[1];\n            }\n        }\n        return answer;\n    }\n\n    private static int[] readInts(InputReader sc, int N) throws Exception {\n        int[] arr = new int[N];\n        for (int i = 0; i < N; i++) {\n            arr[i] = sc.nextInt();\n        }\n        return arr;\n    }\n\n    private static String joinValues(List<? extends Object> list, String delim) {\n        return list.stream().map(Object::toString).collect(Collectors.joining(delim));\n    }\n\n    private static String joinValues(int[] arr, String delim) {\n        List<Object> list = new ArrayList<>();\n        for (Object value : arr) {\n            list.add(value);\n        }\n        return list.stream().map(Object::toString).collect(Collectors.joining(delim));\n    }\n\n    public static void printDebug(Object str) {\n        if (debug) {\n            System.out.println(\"DEBUG: \" + str);\n        }\n    }\n\n    private static final class InputReader {\n        private final InputStream stream;\n        private final byte[] buf = new byte[1024];\n        private int curChar;\n        private int Chars;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int read() throws Exception {\n            if (curChar >= Chars) {\n                curChar = 0;\n                Chars = stream.read(buf);\n                if (Chars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public final int nextInt() throws Exception {\n            return (int)nextLong();\n        }\n\n        public final long nextLong() throws Exception {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n                if (c == -1)\n                    throw new IOException();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? (-res) : (res);\n        }\n\n        public final int[] nextIntBrray(int size) throws Exception {\n            int[] arr = new int[size];\n            for (int i = 0; i < size; i++)\n                arr[i] = nextInt();\n            return arr;\n        }\n\n        public final String next() throws Exception {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.append((char)c);\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        public final String nextLine() throws Exception {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.append((char)c);\n                c = read();\n            } while (c != '\\n' && c != -1);\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    public static void main(String[] args) throws Exception {\n        long currTime = System.currentTimeMillis();\n        if (debug) {\n            solveProblem(new FileInputStream(new File(\"input.in\")));\n            System.out.println(\"Time: \" + (System.currentTimeMillis() - currTime));\n        } else {\n            solveProblem(System.in);\n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n   public class x1141F\n   {\n      public static void main(String omkar[]) throws Exception\n      {\n         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  \n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int N = Integer.parseInt(st.nextToken());\n         int[] 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         HashMap<Long, ArrayList<Integer>> map = new HashMap<Long, ArrayList<Integer>>();\n         for(int r=0; r < N; r++)\n         {\n            long sum = 0L;\n            for(int i=r; i >= 0; i--)\n            {\n               sum += arr[i];\n               if(!map.containsKey(sum))\n                  map.put(sum, new ArrayList<Integer>());\n               map.get(sum).add(i);\n               map.get(sum).add(r);\n            }\n         }\n         ArrayList<Integer> res = new ArrayList<Integer>();\n         for(long key: map.keySet())\n         {\n            ArrayList<Integer> ls = map.get(key);\n            ArrayList<Integer> temp = new ArrayList<Integer>();\n            temp.add(ls.get(0));\n            temp.add(ls.get(1));\n            int r = ls.get(1);\n            for(int i=2; i < ls.size(); i+=2)\n               if(r < ls.get(i))\n               {\n                  r = ls.get(i+1);\n                  temp.add(ls.get(i));\n                  temp.add(ls.get(i+1));\n               }\n            if(res.size() < temp.size())\n               res = temp;\n         }\n         System.out.println(res.size()/2);\n         StringBuilder sb = new StringBuilder();\n         for(int i=0; i < res.size(); i+=2)\n         {\n            sb.append((1+res.get(i))+\" \"+(1+res.get(i+1)));\n            sb.append(\"\\n\");\n         }\n         System.out.print(sb);\n      }\n   }", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\npublic class Main {\n\tpublic static class node implements Comparable<node> {\n\t\tint l,r;\n\t\tnode(){}\n\t\tnode(int l,int r) {\n\t\t\tthis.l=l;\n\t\t\tthis.r=r;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(node rhs) {\n\t\t\treturn r-rhs.r;\n\t\t}\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\tStringTokenizer sa=new StringTokenizer(in.readLine());\n\t\tint n=Integer.parseInt(sa.nextToken());\n\t\tsa=new StringTokenizer(in.readLine());\n\t\tint[] a=new int[n];\n\t\tTreeMap<Integer,ArrayList<node>> mp=new TreeMap();\n\t\tfor (int i=0;i<n;++i) a[i]=Integer.parseInt(sa.nextToken());\n\t\tArrayList<node> ans=new ArrayList<node>();\n\t\tfor (int i=0;i<n;++i) {\n\t\t\tint tmp=0;\n\t\t\tfor (int j=i;j<n;++j) {\n\t\t\t\ttmp+=a[j];\n\t\t\t\tif (!mp.containsKey(tmp)) {\n\t\t\t\t\tArrayList<node> t=new ArrayList();\n\t\t\t\t\tt.add(new node(i,j));\n\t\t\t\t\tmp.put(tmp,t);\n\t\t\t\t} else {\n\t\t\t\t\tArrayList<node> t=mp.get(tmp);\n\t\t\t\t\tint left=0,right=t.size()-1,res=t.size();\n\t\t\t\t\twhile (left<=right) {\n\t\t\t\t\t\tint mid=(left+right)>>1;\n\t\t\t\t\t\tif (t.get(mid).r>=i) {\n\t\t\t\t\t\t\tres=mid;\n\t\t\t\t\t\t\tright=mid-1;\n\t\t\t\t\t\t} else left=mid+1;\n\t\t\t\t\t}\n\t\t\t\t\tif (res==t.size()) t.add(new node(i,j));\n\t\t\t\t\telse if (t.get(res).r>j) t.set(res,new node(i,j));\n\t\t\t\t}\n\t\t\t\tif (mp.get(tmp).size()>ans.size()) ans=mp.get(tmp);\n\t\t\t}\n\t\t}\n\t\tout.println(ans.size());\n\t\tfor (int i=0;i<ans.size();++i)\n\t\t\tout.printf(\"%d %d\\n\",ans.get(i).l+1,ans.get(i).r+1);\n\t\tout.flush();\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class Main{\n\tstatic HashMap<Integer,ArrayList<seg>> ma;\n\tstatic class seg{\n\t\tseg(int a,int b){\n\t\t\tl=a;r=b;\n\t\t}\n\t\tint l,r;\n\t}\n\tstatic int n,sum,dex;\n\tstatic int arr[]=new int[1600];\n\tpublic static void main(String argas[]){\n\t\tScanner cin=new Scanner(System.in);\n\t\tma=new HashMap();\n\t\tn=cin.nextInt();\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tarr[i]=cin.nextInt();\n\t\t\tsum=0;\n\t\t\tfor(int j=i;j>0;j--){\n\t\t\t\tsum+=arr[j];\n\t\t\t\tif(ma.containsKey(sum)) ma.get(sum).add(new seg(j,i));\n\t\t\t\telse {\n\t\t\t\t\tma.put(sum, new ArrayList<seg>());\n\t\t\t\t\tma.get(sum).add(new seg(j,i));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans=0,te;\n\t\tArrayList<seg> best=new ArrayList(),now,temp;\n\t\tIterator it=ma.entrySet().iterator();\n\t\twhile(it.hasNext()){\n\t\t\tnow=new ArrayList();\n\t\t\tte=0;\n\t\t\tMap.Entry entry=(Map.Entry) it.next();\n\t\t\ttemp=(ArrayList<seg>) entry.getValue();\n\t\t\tdex=0;\n\t\t\tfor(int i=0;i<temp.size();i++){\n\t\t\t\tif(temp.get(i).l>dex){\n\t\t\t\t\tdex=temp.get(i).r;\n\t\t\t\t\tte++;\n\t\t\t\t\tnow.add(new seg(temp.get(i).l,temp.get(i).r));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(te>ans){\n\t\t\t\tans=te;\n\t\t\t\tbest=now;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tfor(int i=0;i<best.size();i++){\n\t\t\tSystem.out.println(best.get(i).l+\" \"+best.get(i).r);\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "//package com.example.programming;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\n\npublic class Test {\n    static class Pair {\n        int f,s;\n        public Pair(int x, int y) {f = x; s = y;}\n    }\n    public static void main(String[] args) throws Exception{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        String[] s = br.readLine().split(\" \");\n        int[] arr = new int[n];\n        for(int i = 0; i<n; i++) arr[i] = Integer.parseInt(s[i]);\n\n        HashMap<Integer, ArrayList<Pair>> map = new HashMap<>();\n        for(int i = 0; i<n; i++) {\n            int sum = 0;\n            for(int j = i; j>=0; j--) {\n                sum += arr[j];\n                ArrayList<Pair> list = map.get(sum);\n                if(list == null) {\n                    list = new ArrayList<>();\n                    map.put(sum, list);\n                }\n                list.add(new Pair(j, i));\n            }\n        }\n\n        Iterator it = map.entrySet().iterator();\n        ArrayList<Pair> ans = new ArrayList<>();\n        for(;it.hasNext();){\n            Map.Entry<Integer, ArrayList<Pair>> entry = (Map.Entry<Integer, ArrayList<Pair>>)it.next();\n            ArrayList<Pair> list = entry.getValue();\n            ArrayList<Pair> pre = new ArrayList<>();\n            int r = -1;\n            for(Pair p : list) {\n                if(p.f > r) {\n                    pre.add(p);\n                    r = p.s;\n                }\n            }\n            if(ans.size()<pre.size()) ans = pre;\n        }\n        StringBuilder sb = new StringBuilder();\n        sb.append(ans.size()).append('\\n');\n        for(Pair p : ans) {\n            sb.append(p.f+1).append(' ').append(p.s+1).append('\\n');\n        }\n        System.out.print(sb);\n    }\n\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/**\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class SameSumBlocks {\n    public static void main(String[] args) throws Exception {\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int N = sc.nextInt();\n        int[] pre = new int[N + 1];\n        for (int i = 1; i <= N; i++) {\n            pre[i] = pre[i - 1] + sc.nextInt();\n        }\n        var sumMap = new HashMap<Integer, ArrayList<Pair>>();\n        for (int i = 1; i <= N; i++) {\n            for (int j = i; j <= N; j++) {\n                int sum = pre[j] - pre[i - 1];\n                sumMap.computeIfAbsent(sum, val -> new ArrayList<>()).add(new Pair(i, j));\n            }\n        }\n        var ans = new ArrayList<Pair>();\n        for (var list : sumMap.values()) {\n            Collections.sort(list, Comparator.comparingInt(p -> p.r));\n            // greedily schedule the intervals\n            int last = 0;\n            var group = new ArrayList<Pair>();\n            for (Pair p : list) {\n                if (p.l > last) {\n                    group.add(p);\n                    last = p.r;\n                }\n            }\n            if (group.size() > ans.size()) {\n                ans = group;\n            }\n        }\n        out.println(ans.size());\n        for (Pair p : ans) {\n            out.println(p);\n        }\n        out.close();\n    }\n\n    static class Pair {\n        int l, r;\n        public Pair(int ll, int rr) {\n            l = ll; r = rr;\n        }\n        public String toString() {\n            return l + \" \" + r;\n        }\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            }\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 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport javafx.util.Pair;\n\npublic class Solve6 {\n\n    public static void main(String[] args) throws IOException {\n        PrintWriter pw = new PrintWriter(System.out);\n        new Solve6().solve(pw);\n        pw.flush();\n        pw.close();\n    }\n\n    public void solve(PrintWriter pw) throws IOException {\n        FastReader sc = new FastReader();\n        int n = sc.nextInt();\n        int[] a = new int[n + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = sc.nextInt();\n        }\n        HashMap<Integer, LinkedList<Pair<Integer, Integer>>> h = new HashMap();\n        for (int i = 1; i <= n; i++) {\n            int s = 0;\n            for (int j = i; j >= 1; j--) {\n                s += a[j];\n                LinkedList<Pair<Integer, Integer>> l;\n                if (!h.containsKey(s)) {\n                    l = new LinkedList();\n                } else {\n                    l = h.get(s);\n                }\n                l.add(new Pair(j, i));\n                h.put(s, l);\n            }\n        }\n\n        int max = 0, index = 0;\n        for (Map.Entry<Integer, LinkedList<Pair<Integer, Integer>>> entrySet : h.entrySet()) {\n            int i = 0, size = 0;\n            for (Pair<Integer, Integer> pair : entrySet.getValue()) {\n                if (pair.getKey() > i) {\n                    i = pair.getValue();\n                    size++;\n                }\n            }\n            if (size > max) {\n                max = size;\n                index = entrySet.getKey();\n            }\n        }\n        pw.println(max);\n        int i = 0;\n        for (Pair<Integer, Integer> pair : h.get(index)) {\n            if (pair.getKey() > i) {\n                pw.println(pair.getKey() + \" \" + pair.getValue());\n                i = pair.getValue();\n            }\n        }\n    }\n\n    static class FastReader {\n\n        StringTokenizer st;\n        BufferedReader br;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public boolean hasNext() throws IOException {\n            String s = br.readLine();\n            if (s == null || s.isEmpty()) {\n                return false;\n            }\n            st = new StringTokenizer(s);\n            return true;\n        }\n\n        public String next() throws IOException {\n            if (st == null || !st.hasMoreTokens()) {\n                String s = br.readLine();\n                if (s.isEmpty()) {\n                    return null;\n                }\n                st = new StringTokenizer(s);\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        public double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        public String nextLine() throws IOException {\n            return br.readLine();\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\tprivate static class Interval implements Comparable<Interval> {\n\t\tpublic int start , end;\n\t\tpublic Interval(int start , int end) {\n\t\t\tthis.start = start;\n\t\t\tthis.end = end;\t\t\t\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Interval interval) {\n\t\t\treturn this.end - interval.end;\t\t\t\n\t\t}\t\t\n\t}\n\t\n\tprivate static int getTotal(List<Interval> list) {\n\t\tint ans = 0 , i , n = list.size();\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tint end = list.get(i).end;\n\t\t\twhile (i < n && list.get(i).start <= end) {\n\t\t\t\ti ++;\t\t\t\t\n\t\t\t}\n\t\t\ti --;\n\t\t\tans ++;\n\t\t}\t\t\n\t\treturn ans;\n\t}\n\t\n\tprivate static void solve(List<Interval> list) {\n\t\tList<int[]> ans = new ArrayList<>();\n\t\tint i , n = list.size();\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tint start = list.get(i).start , end = list.get(i).end;\n\t\t\twhile (i < n && list.get(i).start <= end) {\n\t\t\t\ti ++;\t\t\t\t\n\t\t\t}\n\t\t\ti --;\n\t\t\tans.add(new int[] {start , end});\n\t\t}\n\t\tSystem.out.println(ans.size());\n\t\tfor (int[] array : ans) {\n\t\t\tSystem.out.println(array[0] + \" \" + array[1]);\n\t\t}\n\t}\n\t\n\tprivate static long[] a = new long[2000];\t\n\t\n\tpublic static void main(String[] args) {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\n\t\tScanner scan = new Scanner(System.in);\t\t\t\t\n\n\t\tMap<Long , List<Interval>> map = new HashMap<>();\t\t\n\t\tint i , j , n = scan.nextInt() , max = 0;\n\t\tlong ans = 0;\n\t\tfor (i = 1;i <= n;i ++) {\n\t\t\ta[i] = scan.nextLong();\n\t\t}\n\t\tfor (i = 1;i <= n;i ++) {\n\t\t\tlong sum = 0;\n\t\t\tfor (j = i;j <= n;j ++) {\t\t\t\t\n\t\t\t\tsum += a[j];\n\t\t\t\tif (!map.containsKey(sum)) {\n\t\t\t\t\tmap.put(sum , new ArrayList<>());\n\t\t\t\t}\n\t\t\t\tmap.get(sum).add(new Interval(i , j));\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tfor (List<Interval> list : map.values()) {\n\t\t\tCollections.sort(list);\t\t\t\n\t\t}\t\t\n\t\tfor (Map.Entry<Long , List<Interval>> entry : map.entrySet()) {\n\t\t\tint total = getTotal(entry.getValue());\n\t\t\tif (total > max) {\n\t\t\t\tmax = total;\n\t\t\t\tans = entry.getKey();\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tsolve(map.get(ans));\t\t\n\t\n\t}\n    \n}\n\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskF2 solver = new TaskF2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF2 {\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            HashMap<Integer, Integer> lastIndex = new HashMap<>();\n            HashMap<Integer, Integer> maxSize = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                int sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    if (maxSize.containsKey(sum) == false) {\n                        maxSize.put(sum, 0);\n                    }\n                    int curMaxSize = maxSize.get(sum);\n                    int curLastIndex = curMaxSize == 0 ? -1 : lastIndex.get(sum);\n                    if (curMaxSize == 0 || curLastIndex < i) {\n                        curMaxSize++;\n                        curLastIndex = j;\n                    } else if (curLastIndex >= j) {\n                        curLastIndex = j;\n                    }\n                    maxSize.put(sum, curMaxSize);\n                    lastIndex.put(sum, curLastIndex);\n                }\n            }\n\n            int bestSum = -1;\n            int bestSize = -1;\n            for (int sum : maxSize.keySet()) {\n                if (maxSize.get(sum) > bestSize) {\n                    bestSize = maxSize.get(sum);\n                    bestSum = sum;\n                }\n            }\n\n            ArrayList<Interval> best = new ArrayList<>();\n            lastIndex = new HashMap<>();\n            maxSize = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                int sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    if (sum != bestSum)\n                        continue; // consider only bestSums\n                    if (maxSize.containsKey(sum) == false) {\n                        maxSize.put(sum, 0);\n                    }\n                    int curMaxSize = maxSize.get(sum);\n                    int curLastIndex = curMaxSize == 0 ? -1 : lastIndex.get(sum);\n                    if (curMaxSize == 0 || curLastIndex < i) {\n                        curMaxSize++;\n                        curLastIndex = j;\n                        best.add(new Interval(i, j));\n                    } else if (curLastIndex >= j) {\n                        curLastIndex = j;\n                        best.set(best.size() - 1, new Interval(i, j));\n                    }\n                    maxSize.put(sum, curMaxSize);\n                    lastIndex.put(sum, curLastIndex);\n                }\n            }\n\n            out.println(bestSize);\n            for (Interval i : best) {\n                out.println((i.l + 1) + \" \" + (i.r + 1));\n            }\n        }\n\n        class Interval {\n            int l;\n            int r;\n\n            Interval(int l, int r) {\n                this.l = l;\n                this.r = r;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\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        TaskF solver = new TaskF();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            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            Map<Integer, List<Range>> rgs = new HashMap<Integer, List<Range>>();\n            for (int i = 0; i < n; i++) {\n                int s = 0;\n                for (int j = i; j < n; j++) {\n                    s += a[j];\n\n                    if (rgs.get(s) == null) {\n                        rgs.put(s, new ArrayList<Range>());\n                    }\n\n                    rgs.get(s).add(new Range(i, j));\n                }\n            }\n\n            Iterator it = rgs.entrySet().iterator();\n\n            List<Range> ans = new ArrayList<Range>();\n\n            while (it.hasNext()) {\n                Map.Entry pair = (Map.Entry) it.next();\n                int sum = (int) pair.getKey();\n                Object[] intermediate = ((List<Object[]>) pair.getValue()).toArray();\n                Range[] ranges = new Range[intermediate.length];\n                for (int i = 0; i < intermediate.length; i++) {\n                    ranges[i] = (Range) intermediate[i];\n                }\n                Arrays.sort(ranges);\n\n                List<Range> cand = new ArrayList<Range>();\n\n                for (Range r : ranges) {\n                    if (cand.size() == 0) {\n                        cand.add(r);\n                        continue;\n                    }\n\n                    if (cand.get(cand.size() - 1).j < r.i) {\n                        cand.add(r);\n                    } else {\n                        if (cand.get(cand.size() - 1).j > r.j) {\n                            cand.remove(cand.size() - 1);\n                            cand.add(r);\n                        }\n                    }\n                }\n\n                if (cand.size() > ans.size()) {\n                    ans = cand;\n                }\n            }\n\n            out.println(ans.size());\n            for (Range r : ans) {\n                out.println((r.i + 1) + \" \" + (r.j + 1));\n            }\n        }\n\n        public class Range implements Comparable {\n            public int i;\n            public int j;\n\n            public Range(int i, int j) {\n                this.i = i;\n                this.j = j;\n            }\n\n            public int compareTo(Object o) {\n                Range t = (Range) o;\n                if (this.i == t.i) {\n                    if (this.j < t.j) return 1;\n                    else return 0;\n                }\n                if (this.i < t.i) return 1;\n                return 0;\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", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main {\n    static final long MOD = 1_000_000_007, INF = 1_000_000_000_000_000_000L;\n    static final int INf = 1_000_000_000;\n    static FastReader reader;\n    static PrintWriter writer;\n    public static void main(String[] args) {\n        Thread t = new Thread(null, new O(), \"Integer.MAX_VALUE\", 100000000);\n        t.start();\n    }\n    static class O implements Runnable {\n        public void run() {\n            try {\n                magic();\n            }\n            catch (Exception e) {\n                e.printStackTrace();\n                System.exit(1);\n            }\n        }\n    }\n    static class FastReader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        public FastReader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public FastReader(String file_name) throws IOException {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[1000000];\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    static void magic() throws IOException {\n        reader = new FastReader();\n        writer = new PrintWriter(System.out, true);\n        Map<Integer, ArrayList<Pair>> map = new HashMap<>();\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        for(int i=0;i<n;++i) {\n            int sum = 0;\n            for(int j=i;j<n;++j) {\n                sum+=arr[j];\n                ArrayList<Pair> list = map.get(sum);\n                if(list==null) {\n                    list = new ArrayList<>();\n                }\n                list.add(new Pair(i+1,j+1));\n                map.put(sum, list);\n            }\n        }\n        int ans = 0,at = -1;\n        for(int e : map.keySet()) {\n            ArrayList<Pair> list = map.get(e);\n            Collections.sort(list);\n//            writer.println(\"Pairs having sum: \"+e);\n//            for(Pair p : list) {\n//                writer.print(p);\n//                writer.print(\" \");\n//            }\n//            writer.println();\n            int ispe = 0;\n            int len = list.size();\n            for(int i=0;i<len;++i) {\n                ispe++;\n                int r = list.get(i).y;\n                while(i+1<len && list.get(i+1).x<=r) {\n                    i++;\n                }\n            }\n            if(ans<ispe) {\n                ans = ispe;\n                at = e;\n            }\n        }\n        writer.println(ans);\n        ArrayList<Pair> list = map.get(at);\n        Collections.sort(list);\n        int len = list.size();\n        for(int i=0;i<len;++i) {\n            writer.println(list.get(i).x+\" \"+list.get(i).y);\n            int r = list.get(i).y;\n            while(i+1<len && list.get(i+1).x<=r) {\n                i++;\n            }\n        }\n    }\n    static class Pair implements Comparable<Pair> {\n        int x,y;\n        Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n        public int compareTo(Pair other) {\n            if(this.y!=other.y) {\n                return this.y - other.y;\n            }\n            return this.x - other.x;\n        }\n        public String toString() {\n            return \"{\" + x + \",\" + y + \"}\";\n        }\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class F11141 {\n\tstatic class Solver {\n\n\t\tArrayList<int[]> ranges[];\n\t\tHashMap<Long, Integer> hm = new HashMap<>();\n\n\t\tint id(long s) {\n\t\t\tif (!hm.containsKey(s))\n\t\t\t\thm.put(s, hm.size());\n\t\t\treturn hm.get(s);\n\t\t}\n\t\t\n\t\t// max disjoint range set in ranges[r]\n\t\tint[] memo;\n\t\tint go(int r) {\n\t\t\tmemo[N] = 0;\n\t\t\tint last = N;\n\t\t\tfor(int[] a : ranges[r]) {\n\t\t\t\twhile(a[0] < last) {\n\t\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\t\tlast--;\n\t\t\t\t}\n\t\t\t\tmemo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));\n\t\t\t\tlast = a[0];\n\t\t\t}\n\t\t\twhile(0 < last) {\n\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\tlast--;\n\t\t\t}\n\t\t\treturn memo[0];\n\t\t}\n\n\t\tArrayDeque<int[]> ans = new ArrayDeque<>();\n\t\t\n\t\tvoid go2(int r) {\n\t\t\tmemo[N] = 0;\n\t\t\tint last = N;\n\t\t\tint minAt[] = new int[N], oo = 987654321;\n\t\t\tArrays.fill(minAt, oo);\n\t\t\tfor(int[] a : ranges[r]) {\n\t\t\t\tminAt[a[0]] = Math.min(minAt[a[0]], a[1] - a[0]);\n\t\t\t\twhile(a[0] < last) {\n\t\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\t\tlast--;\n\t\t\t\t}\n\t\t\t\tmemo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));\n\t\t\t\tlast = a[0];\n\t\t\t}\n\t\t\twhile(0 < last) {\n\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\tlast--;\n\t\t\t}\n\t\t\tint k = 0;\n\t\t\tfor(; k < N;) {\n\t\t\t\tif(minAt[k] == oo || memo[k] != 1 + memo[k + minAt[k] + 1]) k++;\n\t\t\t\telse {\n\t\t\t\t\tans.push(new int[] {k, k + minAt[k]});\n\t\t\t\t\tk += minAt[k] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tSolver() {\n\t\t\tranges = new ArrayList[2250001];\n\t\t\tfor (int i = 0; i < ranges.length; i++)\n\t\t\t\tranges[i] = new ArrayList<>();\n\t\t}\n\n\t\tint N, LID;\n\t\tlong[] a;\n\n\t\tvoid solve(Scanner s, PrintWriter out) {\n\t\t\tN = s.nextInt();\n\t\t\ta = new long[N + 1];\n\t\t\tfor (int i = 1; i <= N; i++)\n\t\t\t\ta[i] = s.nextLong() + a[i - 1];\n\t\t\tfor (int i = N; i >= 1; i--)\n\t\t\t\tfor (int j = i; j <= N; j++) {\n\t\t\t\t\tint x = id(a[j] - a[i - 1]);\n\t\t\t\t\tranges[x].add(new int[] { i - 1, j - 1 });\n\t\t\t\t}\n\t\t\t\n\t\t\tint best = 0, bid = -1;\n\t\t\tmemo = new int[N + 1];\n\t\t\tArrays.sort(ranges, (a, b) -> b.size() - a.size());\n\t\t\tfor(int i = 0; i < ranges.length; i++, LID++) {\n\t\t\t\tif(ranges[i].size() <= best) break;\n\t\t\t\tint ans = go(i);\n\t\t\t\tif(ans > best) {\n\t\t\t\t\tbest = ans;\n\t\t\t\t\tbid = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// backtrack on bid\n\t\t\tout.println(best);\n\t\t\tgo2(bid);\n\t\t\t\t\t\t\n\t\t\twhile(!ans.isEmpty()) {\n\t\t\t\tint[] c = ans.pop();\n\t\t\t\tout.println(++c[0] + \" \" + ++c[1]);\n\t\t\t}\n\t\t\t\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner s = new Scanner(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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\tprivate static class Interval implements Comparable<Interval> {\n\t\tpublic int start , end;\n\t\tpublic Interval(int start , int end) {\n\t\t\tthis.start = start;\n\t\t\tthis.end = end;\t\t\t\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Interval interval) {\n\t\t\treturn this.end - interval.end;\t\t\t\n\t\t}\t\t\n\t}\n\t\n\tprivate static int getTotal(List<Interval> list) {\n\t\tint ans = 0 , i , n = list.size();\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tint end = list.get(i).end;\n\t\t\twhile (i < n && list.get(i).start <= end) {\n\t\t\t\ti ++;\t\t\t\t\n\t\t\t}\n\t\t\ti --;\n\t\t\tans ++;\n\t\t}\t\t\n\t\treturn ans;\n\t}\n\t\n\tprivate static void solve(List<Interval> list) {\n\t\tList<int[]> ans = new ArrayList<>();\n\t\tint i , n = list.size();\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tint start = list.get(i).start , end = list.get(i).end;\n\t\t\twhile (i < n && list.get(i).start <= end) {\n\t\t\t\ti ++;\t\t\t\t\n\t\t\t}\n\t\t\ti --;\n\t\t\tans.add(new int[] {start , end});\n\t\t}\n\t\tSystem.out.println(ans.size());\n\t\tfor (int[] array : ans) {\n\t\t\tSystem.out.println(array[0] + \" \" + array[1]);\n\t\t}\n\t}\n\t\n\tprivate static long[] a = new long[2000];\t\n\t\n\tpublic static void main(String[] args) {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\n\t\tScanner scan = new Scanner(System.in);\t\t\t\t\n\n\t\tMap<Long , List<Interval>> map = new HashMap<>();\t\t\n\t\tint i , j , n = scan.nextInt() , max = 0;\n\t\tlong ans = 0;\n\t\tfor (i = 1;i <= n;i ++) {\n\t\t\ta[i] = scan.nextLong();\n\t\t}\n\t\tfor (i = 1;i <= n;i ++) {\n\t\t\tlong sum = 0;\n\t\t\tfor (j = i;j <= n;j ++) {\t\t\t\t\n\t\t\t\tsum += a[j];\n\t\t\t\tif (!map.containsKey(sum)) {\n\t\t\t\t\tmap.put(sum , new ArrayList<>());\n\t\t\t\t}\n\t\t\t\tmap.get(sum).add(new Interval(i , j));\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tfor (List<Interval> list : map.values()) {\n\t\t\tCollections.sort(list);\t\t\t\n\t\t}\t\t\n\t\tfor (Map.Entry<Long , List<Interval>> entry : map.entrySet()) {\n\t\t\tint total = getTotal(entry.getValue());\n\t\t\tif (total > max) {\n\t\t\t\tmax = total;\n\t\t\t\tans = entry.getKey();\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tsolve(map.get(ans));\t\t\n\t\n\t}\n    \n}\n\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n//Solution Credits: Taranpreet Singh\npublic class Main{\n    //SOLUTION BEGIN\n    //Code not meant for understanding, proceed with caution\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        HashMap<Long, ArrayList<int[]>> map = new HashMap<>();\n        for(int i = 0; i< n; i++){\n            long sum = 0;\n            for(int j = i; j< n; j++){\n                sum+=a[j];\n                if(!map.containsKey(sum))map.put(sum, new ArrayList<>());\n                map.get(sum).add(new int[]{i+1, j+1});\n            }\n        }\n        int[][] ans = new int[n][];int cur = 0;\n        int[][] tmp = new int[n][];int tc;\n        for(Map.Entry<Long, ArrayList<int[]>> e: map.entrySet()){\n            int prev = 0;\n            ArrayList<int[]> li = e.getValue();\n            Collections.sort(li, new Comparator<int[]>(){\n                public int compare(int[] i1, int[] i2){\n                    if(i1[1]!=i2[1])return Integer.compare(i1[1], i2[1]);\n                    return Integer.compare(i1[0], i1[0]);\n                }\n            });\n                tc = 0;\n            for(int[] p:li){\n                if(p[0]>prev){\n                    tmp[tc++] = new int[]{p[0],p[1]};\n                    prev = p[1];\n                }\n            }\n            if(tc>cur){\n                cur = tc;\n                for(int i = 0; i< tc; i++)ans[i] = new int[]{tmp[i][0], tmp[i][1]};\n            }\n        }\n        pn(cur);\n        for(int i = 0; i< cur; i++)pn(ans[i][0]+\" \"+ans[i][1]);\n    }\n    //SOLUTION END\n    void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n    long mod = (long)1e9+7, IINF = (long)1e18;\n    final int INF = (int)1e9, MX = (int)2e3+1;\n    DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n    double PI = 3.1415926535897932384626433832792884197169399375105820974944, eps = 1e-8;\n    static boolean multipleTC = false, memory = false;\n    FastReader in;PrintWriter out;\n    void run() throws Exception{\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n        int T = (multipleTC)?ni():1;\n        //Solution Credits: Taranpreet Singh\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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class ProblemF {\n    private static boolean debug = false;\n\n    private static int N;\n    private static int[] A;\n\n    private static void solveProblem(InputStream instr) throws Exception {\n        InputReader sc = new InputReader(instr);\n        int testCount = 1;\n        if (debug) {\n            testCount = sc.nextInt();\n        }\n\n        for (int t = 1; t <= testCount; t++) {\n            printDebug(\"------ \" + t + \" ------\");\n            N = sc.nextInt();\n            A = readInts(sc, N);\n            Object result = solveTestCase();\n            System.out.println(result);\n        }\n    }\n\n    private static Object solveTestCase() {\n        int sum[] = new int[N];\n        sum[0] = A[0];\n        for (int i = 1; i < N; i++) {\n            sum[i] = sum[i - 1] + A[i];\n        }\n        Map<Integer, List<int[]>> map = new HashMap<>();\n        for (int i = 0; i < N; i++) {\n            for (int j = i; j < N; j++) {\n                int groupSum = sum[j] - (i == 0 ? 0 : sum[i - 1]);\n                map.putIfAbsent(groupSum, new ArrayList<>());\n                map.get(groupSum).add(new int[]{i, j});\n            }\n        }\n        int max = -1;\n        List<int[]> maxAnswer = null;\n        for (Map.Entry<Integer, List<int[]>> entry : map.entrySet()) {\n            List<int[]> values = entry.getValue();\n            if (values.size() <= max) {\n                continue;\n            }\n            List<int[]> curr = findMax(values);\n            if (curr.size() > max) {\n                max = curr.size();\n                maxAnswer = curr;\n\n            }\n        }\n        List<String> answer = new ArrayList<>();\n        for (int[] value : maxAnswer) {\n            answer.add((value[0] + 1) + \" \" + (value[1] + 1));\n        }\n        return max + \"\\n\" + joinValues(answer, \"\\n\");\n    }\n\n    private static List<int[]> findMax(List<int[]> values) {\n        values.sort(new Comparator<int[]>() {\n            @Override\n            public int compare(int[] o1, int[] o2) {\n                return o1[1] - o2[1];\n            }\n        });\n        List<int[]> answer = new ArrayList<>();\n        int right = -1;\n        for (int i = 0; i < values.size(); i++) {\n            int[] value = values.get(i);\n            if (value[0] > right) {\n                answer.add(value);\n                right = value[1];\n            }\n        }\n        return answer;\n    }\n\n    private static int[] readInts(InputReader sc, int N) throws Exception {\n        int[] arr = new int[N];\n        for (int i = 0; i < N; i++) {\n            arr[i] = sc.nextInt();\n        }\n        return arr;\n    }\n\n    private static String joinValues(List<? extends Object> list, String delim) {\n        return list.stream().map(Object::toString).collect(Collectors.joining(delim));\n    }\n\n    private static String joinValues(int[] arr, String delim) {\n        List<Object> list = new ArrayList<>();\n        for (Object value : arr) {\n            list.add(value);\n        }\n        return list.stream().map(Object::toString).collect(Collectors.joining(delim));\n    }\n\n    public static void printDebug(Object str) {\n        if (debug) {\n            System.out.println(\"DEBUG: \" + str);\n        }\n    }\n\n    private static final class InputReader {\n        private final InputStream stream;\n        private final byte[] buf = new byte[1024];\n        private int curChar;\n        private int Chars;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int read() throws Exception {\n            if (curChar >= Chars) {\n                curChar = 0;\n                Chars = stream.read(buf);\n                if (Chars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public final int nextInt() throws Exception {\n            return (int)nextLong();\n        }\n\n        public final long nextLong() throws Exception {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n                if (c == -1)\n                    throw new IOException();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? (-res) : (res);\n        }\n\n        public final int[] nextIntBrray(int size) throws Exception {\n            int[] arr = new int[size];\n            for (int i = 0; i < size; i++)\n                arr[i] = nextInt();\n            return arr;\n        }\n\n        public final String next() throws Exception {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.append((char)c);\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        public final String nextLine() throws Exception {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.append((char)c);\n                c = read();\n            } while (c != '\\n' && c != -1);\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    public static void main(String[] args) throws Exception {\n        long currTime = System.currentTimeMillis();\n        if (debug) {\n            solveProblem(new FileInputStream(new File(\"input.in\")));\n            System.out.println(\"Time: \" + (System.currentTimeMillis() - currTime));\n        } else {\n            solveProblem(System.in);\n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "// Author: aman_robotics\n\n//package math_codet;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class lets_do {\n    FastReader in;\n    PrintWriter out;\n    Helper_class h;\n    final long mod = 1000000009;\n    final int MAXN = 1000005;\n    final int lgN = 20;\n    final long INF = (long)1e18;\n    final long MAX_Ai = (long)1e12;\n    public static void main(String[] args) throws java.lang.Exception{\n        new lets_do().run();\n    }\n    void run() throws Exception{\n        in=new FastReader(System.in);\n        out = new PrintWriter(System.out);\n        h = new Helper_class();\n        int t = 1;\n        while(t--> 0)\n            solve();\n        out.flush();\n        out.close();\n    }\n    void solve(){\n        int n = h.ni();\n        long[] arr = new long[n];\n        int i = 0, j = 0;\n        for(i = 0; i < n; i++)\n            arr[i] = h.nl();\n        HashMap<Long, Integer> hmap = new HashMap<Long, Integer>();\n        int cnt = 0;\n        for(i = 0; i < n; i++){\n            long sum = 0;\n            for(j = i; j < n; j++){\n                sum += arr[j];\n                Integer x = hmap.get(sum);\n                if(x == null)\n                    hmap.put(sum, cnt++);\n            }\n        }\n        TreeSet<Pair>[] tset = new TreeSet[cnt];\n        for(i = 0; i < cnt; i++)\n            tset[i] = new TreeSet<Pair>(com);\n        for(i = 0; i < n; i++){\n            long sum = 0;\n            for(j = i; j < n; j++){\n                sum += arr[j];\n                tset[hmap.get(sum)].add(new Pair(i, j));\n            }\n        }\n        int max = 0;\n        int ind = -1;\n        int max_x = 0, max_y = 0;\n        for(i = 0; i < cnt; i++){\n        \tint curr_y = tset[i].first().y;\n        \tint cnt1 = 1;\n            for(Pair yo : tset[i]){\n                if(yo.x > curr_y) {\n                \tcnt1++;\n                \tcurr_y = yo.y;\n                }\n            }\n            if(max < cnt1) {\n            \tmax = cnt1;\n            \tind = i;\n            }\n        }\n        h.pn(max);\n        Pair hola_yee = new Pair(tset[ind].first().x, tset[ind].first().y);\n        h.pn((tset[ind].first().x + 1) +\" \"+(tset[ind].first().y + 1));\n        int curr_y = tset[ind].first().y;\n        for(Pair yo : tset[ind]){\n            if(yo.x > curr_y) {\n            \tcurr_y = yo.y;\n            \th.pn((yo.x + 1) +\" \"+(yo.y + 1));\n            }\n        }\n    }\n\n\n\n    static final Comparator<Pair> com=new Comparator<Pair>(){\n        public int compare(Pair a, Pair b){\n            if(Integer.compare(a.y, b.y) != 0)\n                return Integer.compare(a.y, b.y);\n            else\n                return Integer.compare(a.x, b.x);\n        }\n    };\n\n    class Pair{\n        int x;\n        int y;\n        Pair(int p, int q){\n            x = p;\n            y = q;\n        }\n    }\n    class Edge{\n        int u , v;\n        long wt;\n        Edge(int a, int b, long w){\n            u = a;\n            v = b;\n            wt = w;\n        }\n        int other(int x) {\n            return u ^ v ^ x;\n        }\n    }\n\n\n    class Helper_class{\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 bitcount(long n){return (n==0)?0:(1+bitcount(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(){return in.next();}\n        String nln(){return in.nextLine();}\n        int ni(){return Integer.parseInt(in.next());}\n        long nl(){return Long.parseLong(in.next());}\n        double nd(){return Double.parseDouble(in.next());}\n\n        long mul(long a,long b){\n            if(a>=mod)a%=mod;\n            if(b>=mod)b%=mod;\n            a*=b;\n            if(a>=mod)a%=mod;\n            return a;\n        }\n        long modPow(long a, long p){\n            long o = 1;\n            while(p>0){\n                if((p&1)==1)o = mul(o,a);\n                a = mul(a,a);\n                p>>=1;\n            }\n            return o;\n        }\n        long add(long a, long b){\n            if(a>=mod)a%=mod;\n            if(b>=mod)b%=mod;\n            if(b<0)b+=mod;\n            a+=b;\n            if(a>=mod)a-=mod;\n            return a;\n        }\n    }\n\n    class FastReader{\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n\n        public FastReader(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 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 void skip(int x) {\n            while (x-- > 0)\n                read();\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 nextString() {\n            return 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 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\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 boolean hasNext() {\n            int value;\n            while (isSpaceChar(value = peek()) && value != -1)\n                read();\n            return value != -1;\n        }\n\n        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n    }\n} ", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n\tHashMap<Integer,Pair> map;\n\tint n,a[];\n\tprivate void solve()throws IOException\n\t{\n\t\tn=nextInt();\n\t\ta=new int[n+1];\n\t\tfor(int i=1;i<=n;i++)\n\t\t\ta[i]=nextInt();\n\t\tmap=new HashMap<>();\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tint sum=0;\n\t\t\tfor(int j=i;j>=1;j--)\n\t\t\t{\n\t\t\t\tsum+=a[j];\n\t\t\t\tif(!map.containsKey(sum))\n\t\t\t\t\tmap.put(sum,new Pair(i,1));\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tPair p=map.get(sum);\n\t\t\t\t\tif(p.pos<j)\n\t\t\t\t\t\tmap.put(sum,new Pair(i,p.cnt+1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint sum=0,ans=0;\n\t\tfor(int i:map.keySet())\n\t\t\tif(map.get(i).cnt>ans)\n\t\t\t{\n\t\t\t\tans=map.get(i).cnt;\n\t\t\t\tsum=i;\n\t\t\t}\n\t\tout.println(ans);\n\t\tArrayList<String> list=new ArrayList<>();\n\t\tfor(int i=1,prev=0;i<=n;i++)\n\t\t{\n\t\t\tint s=0;\n\t\t\tfor(int j=i;j>=1;j--)\n\t\t\t{\n\t\t\t\ts+=a[j];\n\t\t\t\tif(s==sum && j>prev)\n\t\t\t\t{\n\t\t\t\t\tlist.add(j+\" \"+i);\n\t\t\t\t\tprev=i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(String s:list)\n\t\t\tout.println(s);\n\t}\n\tclass Pair{\n\t    int pos,cnt;\n\t    Pair(int a,int b){\n\t        pos=a;\n\t        cnt=b;\n\t    }\n\t}\n\t \n\t///////////////////////////////////////////////////////////\n\n\tpublic void run()throws IOException\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\tst=null;\n\t\tout=new PrintWriter(System.out);\n\n\t\tsolve();\n\t\t\n\t\tbr.close();\n\t\tout.close();\n\t}\n\tpublic static void main(String args[])throws IOException{\n\t\tnew Main().run();\n\t}\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\tString nextToken()throws IOException{\n\t\twhile(st==null || !st.hasMoreTokens())\n\t\tst=new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n\tString nextLine()throws IOException{\n\t\treturn br.readLine();\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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B 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 = scn.nextIntArray(n);\n\n\t\tint[][] a = new int[n * (n + 1) / 2][];\n\t\tint[] need = new int[a.length];\n\t\tint pos = 0;\n\t\tfor (int l = 0; l < n; l++) {\n\t\t\tint sum = 0;\n\t\t\tfor (int r = l; r < n; r++) {\n\t\t\t\tsum += arr[r];\n\t\t\t\ta[pos] = new int[] { l, r, sum };\n\t\t\t\tneed[pos++] = sum;\n\t\t\t}\n\t\t}\n\n\t\tneed = scn.uniq(need);\n\n\t\tint[][][] list = new int[need.length][][];\n\t\tint[] size = new int[list.length];\n\n\t\tfor (int i = 0; i < pos; i++) {\n\t\t\tsize[Arrays.binarySearch(need, a[i][2])]++;\n\t\t}\n\t\tfor (int i = 0; i < list.length; i++) {\n\t\t\tlist[i] = new int[size[i]][];\n\t\t}\n\t\tfor (int i = 0; i < pos; i++) {\n\t\t\tint ind = Arrays.binarySearch(need, a[i][2]);\n\t\t\tlist[ind][--size[ind]] = new int[] { a[i][0], a[i][1] };\n\t\t}\n\n\t\tint ind = -1, max = 0;\n\n\t\tfor (int i = 0; i < list.length; i++) {\n\t\t\tif(list[i].length == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tArrays.sort(list[i], (o1, o2) -> o1[1] - o2[1]);\n\n\t\t\tint count = 1, last = list[i][0][1];\n\t\t\tfor(int j = 1; j < list[i].length; j++) {\n\t\t\t\tif(list[i][j][0] > last) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tlast = list[i][j][1];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (count > max) {\n\t\t\t\tmax = count;\n\t\t\t\tind = i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(max);\n\t\tint last = list[ind][0][1];\n\t\tout.println((list[ind][0][0] + 1) + \" \" + (list[ind][0][1] + 1));\n\t\t\n\t\tfor(int i = 1; i < list[ind].length; i++) {\n\t\t\tif(list[ind][i][0] > last) {\n\t\t\t\tout.println((list[ind][i][0] + 1) + \" \" + (list[ind][i][1] + 1));\n\t\t\t\tlast = list[ind][i][1];\n\t\t\t}\n\t\t}\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\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new B(), \"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\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\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}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import 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.Scanner;\n\npublic class SolutionArch2 {\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int n = Integer.valueOf(scanner.nextLine());\n        String s = scanner.nextLine();\n        int[] arr = Arrays.stream(s.split(\" \"))\n                .mapToInt(Integer::valueOf)\n                .toArray();\n        int[] prefixSum = new int[n + 1];\n        for (int i = 0; i < n; i++) {\n            prefixSum[i + 1] = prefixSum[i] + arr[i];\n        }\n        Map<Integer, List<int[]>> map = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            for (int j = i; j < n; j++) {\n                int subarraySum = prefixSum[j + 1] - prefixSum[i];\n                map.putIfAbsent(subarraySum, new ArrayList<>());\n                int l = i + 1, r = j + 1;\n                map.get(subarraySum).add(new int[]{l, r});\n            }\n        }\n        List<int[]> resultPairs = new ArrayList<>();\n        for (Map.Entry<Integer, List<int[]>> e : map.entrySet()) {\n            List<int[]> result = new ArrayList<>();\n            int[] curr = new int[2];\n            List<int[]> pairs = e.getValue();\n            Collections.sort(pairs, Comparator.<int[]>comparingInt(a -> a[1]));\n            for (int[] next : pairs) {\n                if (next[0] > curr[1]) {\n                    result.add(next);\n                    curr = next;\n                }\n            }\n            if (resultPairs.size() < result.size()) {\n                resultPairs = result;\n            }\n        }\n        printResult(resultPairs);\n    }\n\n    private static void printResult(List<int[]> list) {\n        StringBuilder sb = new StringBuilder();\n        sb.append(list.size()).append(\"\\n\");\n        for (int[] pair : list) {\n            sb.append(pair[0]).append(\" \").append(pair[1]).append(\"\\n\");\n        }\n        System.out.print(sb);\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.Point;\n\npublic final class Solution {\n    BufferedReader br;\n    StringTokenizer st;\n    \n    {\n        st = null;\n        br = new BufferedReader(new InputStreamReader(System.in));\n    }\n    \n    public static void main(String[] args) throws Exception {\n        new Solution().run();\n    }\n    \n    void run() 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=1; i<n; i++) a[i] += a[i-1];\n        \n        HashMap<Integer, List<Point>> map = new HashMap<>();\n        for(int i=0; i<n; i++) {\n            for(int j=i; j<n; j++) {\n                int sum = getSum(a, i, j);\n                if(!map.containsKey(sum)) map.put(sum, new ArrayList<>());\n                map.get(sum).add(new Point(i+1, j+1));\n            }\n        }\n        \n        for(int key : map.keySet()) {\n            Collections.sort(map.get(key), new Comparator<Point>() {\n                @Override\n                public int compare(Point p1, Point p2) {\n                    if(p1.x == p2.x) return p1.y - p2.y;\n                    return p1.x - p2.x;\n                }\n            });\n        }\n        \n        Stack<Point> stack = new Stack<>();\n        for(int key : map.keySet()) {\n            Stack<Point> st = getPairs(map.get(key));\n            if(st.size() > stack.size()) stack = st;\n        }\n        \n        pl(stack.size());\n        while(!stack.isEmpty()) {\n            Point p = stack.pop();\n            pl(p.x + \" \" + p.y);\n        }\n    }\n    \n    Stack<Point> getPairs(List<Point> list) {\n        Stack<Point> stack = new Stack<>();\n        stack.push(list.get(0));\n        for(int i=1; i<list.size(); i++) {\n            Point p = list.get(i);\n            if(p.x >= stack.peek().x && p.x <= stack.peek().y) {\n                Point p2 = stack.pop();\n                if(p2.y < p.y) {\n                    stack.push(p2);\n                } else {\n                    stack.push(p );\n                }\n            } else {\n                stack.push(p);\n            }\n        }\n        return stack;\n    }\n    \n    int getSum(int[] a, int l, int r) {\n        return (l == 0) ? a[r] : a[r] - a[l-1];\n    }\n    \n    class Node {\n        HashSet<Integer> adj;\n        public Node() {\n            adj = new HashSet<>();\n        }\n    }\n    \n    // I/O\n    String nt() throws Exception {\n        if(st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine(), \" \");\n        }\n        return st.nextToken();\n    }\n    \n    int ni() throws Exception {\n        return Integer.parseInt(nt());\n    }\n    \n    long nl() throws Exception {\n        return Long.parseLong(nt());\n    }\n    \n    void p(Object o) {\n        System.out.print(o);\n    }\n    \n    void pl(Object o) {\n        System.out.println(o);\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.*;\n\npublic class P1141F {\n\n\tstatic BufferedReader br;\n\tstatic BufferedWriter bw;\n\tstatic StringTokenizer st;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tbw = new BufferedWriter(new OutputStreamWriter(System.out));\n\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint[] a = new int[n];\n\t\tint[][] b = new int[n][n];\n\t\tHashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();\n\t\t\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\ta[i] = Integer.parseInt(st.nextToken());\n\t\t\t\n\t\t\tint r = i;\n\t\t\tb[r][r] = a[r];\n\t\t\tif (!map.containsKey(b[r][r]))\n\t\t\t\tmap.put(b[r][r], new ArrayList<Integer>());\n\t\t\tfor(int l = 0; l < r; ++l) {\n\t\t\t\tb[l][r] = b[l][r-1] + a[r];\n\t\t\t\tif (!map.containsKey(b[l][r]))\n\t\t\t\t\tmap.put(b[l][r], new ArrayList<Integer>());\n\t\t\t}\n\t\t}\n\n\t\t\n\t\tfor(int r = 0; r < n; ++r) {\n\t\t\tfor(int l = 0; l <= r; ++l) {\n\t\t\t\tint sum = b[l][r];\n\t\t\t\tArrayList<Integer> intervals = map.get(sum);\n\t\t\t\tint last_r = -1;\n\t\t\t\tif(!intervals.isEmpty())\n\t\t\t\t\tlast_r = intervals.get(intervals.size()-1);\n\t\t\t\t\n\t\t\t\tif(l > last_r) {\n\t\t\t\t\tintervals.add(l);\n\t\t\t\t\tintervals.add(r);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\t//int best_sum = -1;\n\t\tArrayList<Integer> best_intervals = new ArrayList<Integer>();\n\t\t\n\t\tfor(Map.Entry<Integer, ArrayList<Integer>> entry : map.entrySet()) {\n\t\t\t//int sum = entry.getKey();\n\t\t\tArrayList<Integer> intervals = entry.getValue();\n\t\t\t\n\t\t\tif(intervals.size() > best_intervals.size()) {\n\t\t\t\tbest_intervals = intervals;\n\t\t\t}\n\t\t}\n\t\t\n\t\tbw.write(best_intervals.size()/2 + \"\\n\");\n\t\tfor(int i = 0; i < best_intervals.size(); i += 2) {\n\t\t\tbw.write((best_intervals.get(i)+1) + \" \" + (best_intervals.get(i+1)+1) + \"\\n\");\n\t\t}\n\n\n\t\tbr.close();\n\t\tbw.close();\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "//package sept;\n\nimport java.io.*;\nimport java.util.*;\n\n\npublic class TimePass implements Runnable {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\";\n    //boolean debug=false;\n    boolean debug=true;\n    static long mod=998244353;\n    static long mod2=1000000007;\n    \n    void solve() throws IOException\n    {\n        int n=ni();\n        int[] a=na(n);\n        long[] sum=new long[n];\n        sum[0]=a[0];\n        for(int i=1;i<n;i++)sum[i]=sum[i-1]+a[i];\n        HashMap<Long,ArrayList<Pair>> map=new HashMap<>();\n        for(int i=0;i<n;i++)\n        {\n            for(int j=i;j<n;j++)\n            {\n                long curr=sum[j]-(i>0?sum[i-1]:0);\n                if(map.containsKey(curr))\n                {\n                    map.get(curr).add(new Pair(i+1,j+1));\n                }\n                else\n                {\n                    ArrayList<Pair> list=new ArrayList<>();\n                    list.add(new Pair(i+1,j+1));\n                    map.put(curr,list);\n                }\n            }\n        }\n        int max=0;\n        long maxSum=0;\n        for(long key:map.keySet())\n        {\n            ArrayList<Pair> list=map.get(key);\n            list.sort(new Comparator<Pair>(){\n                public int compare(Pair p1,Pair p2)\n                {\n                    return p1.b-p2.b;\n                }\n            });\n            int prevl=0;\n            int cnt=0;\n            for(Pair pr:list)\n            {\n                if(pr.a>prevl)\n                {\n                    cnt++;\n                    prevl=pr.b;\n                }\n            }\n            if(max<cnt)\n            {\n                max=cnt;\n                maxSum=key;\n            }\n        }\n        int prevl=0;\n        ArrayList<Pair> list=map.get(maxSum);\n        ArrayList<Pair> ans=new ArrayList<>();\n        for(Pair pr:list)\n        {\n            if(pr.a>prevl)\n            {\n                //cnt++;\n                ans.add(pr);\n                //out.println(pr.a+\" \"+pr.b);\n                prevl=pr.b;\n            }\n        }\n        out.println(ans.size());\n        for(Pair pr:ans)\n        {\n            out.println(pr.a+\" \"+pr.b);\n        }\n    }\n    \n    static long fnc(int a,int b)\n    {\n        return a+(long)1000000007*b;\n    }\n    \n    static Pair[][] packU(int n,int[] from,Pair[] to)\n    {\n        Pair[][] g=new Pair[n][];\n        int[] p=new int[n];\n        for(int f:from)\n        {\n            p[f]++;\n        }\n        int m=from.length;\n        for(int i=0;i<n;i++)\n        {\n            g[i]=new Pair[p[i]];\n        }\n        for(int i=0;i<m;i++)\n        {\n            g[from[i]][--p[from[i]]]=to[i];\n        }\n        return g;\n    }\n\n    static int[][] packD(int n,int[] from,int[] to)\n    {\n        int[][] g=new int[n][];\n        int[] p=new int[n];\n        for(int f:from)\n        {\n            p[f]++;\n        }\n        int m=from.length;\n        for(int i=0;i<n;i++)\n        {\n            g[i]=new int[p[i]];\n        }\n        for(int i=0;i<m;i++)\n        {\n            g[from[i]][--p[from[i]]]=to[i];\n        }\n        return g;\n    }\n        \n    static class Pair\n    {\n        int a,b,c;\n        public Pair(int a,int b\n        //,int c\n        )\n        {\n            this.a=a;\n            this.b=b;\n            //this.c=c;\n        }\n    }\n    \n    static long lcm(int a,int b)\n    {\n        long val=a;\n        val*=b;\n        return (val/gcd(a,b));\n    }\n    \n    static long gcd(long a,long b)\n    {\n        if(a==0)return b;\n        return gcd(b%a,a);\n    }\n    \n    static int pow(int a, int b, int p)\n    {\n        long ans = 1, base = a;\n        while (b!=0)\n        {\n            if ((b & 1)!=0)\n            {\n                ans *= base;\n                ans%= p;\n            }\n            base *= base;\n            base%= p;\n            b >>= 1;\n        }\n        return (int)ans;\n    }\n\n    static int inv(int x, int p)\n    {\n        return pow(x, p - 2, p);\n    }\n    \n    public static long[] radixSort(long[] f){ return radixSort(f, f.length); }\n    public static long[] radixSort(long[] f, int n)\n    {\n        long[] to = new long[n];\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < n;i++)b[1+(int)(f[i]&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < n;i++)to[b[(int)(f[i]&0xffff)]++] = f[i];\n            long[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>16&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>16&0xffff)]++] = f[i];\n            long[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>32&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>32&0xffff)]++] = f[i];\n            long[] d = f; f = to;to = d;\n        }\n        {\n            int[] b = new int[65537];\n            for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>48&0xffff)]++;\n            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n            for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>48&0xffff)]++] = f[i];\n            long[] d = f; f = to;to = d;\n        }\n        return f;\n    }\n\n    \n    public void run()\n    {\n        if(debug)oj=true;\n        is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        out = new PrintWriter(System.out);\n        \n        long s = System.currentTimeMillis();\n        try {\n            solve();\n        } catch (IOException e) {\n            // TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n        out.flush();\n        tr(System.currentTimeMillis()-s+\"ms\");\n    }\n    \n    public static void main(String[] args) throws Exception {new Thread(null,new TimePass(),\"Main\",1<<26).start();}\n    \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 nd() { return Double.parseDouble(ns()); }\n    private char nc() { return (char)skip(); }\n    \n    private String ns()\n    {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n    \n    private char[] ns(int n)\n    {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while(p < n && !(isSpaceChar(b))){\n            buf[p++] = (char)b;\n            b = readByte();\n        }\n        return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n    \n    private char[][] nm(int n, int m)\n    {\n        char[][] map = new char[n][];\n        for(int i = 0;i < n;i++)map[i] = ns(m);\n        return map;\n    }\n    \n    private int[] na(int n)\n    {\n        int[] a = new int[n];\n        for(int i = 0;i < n;i++)a[i] = ni();\n        return a;\n    }\n    \n    private int ni()\n    {\n        int num = 0, b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private long nl()\n    {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-'){\n            minus = true;\n            b = readByte();\n        }\n        \n        while(true){\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            }else{\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n    private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\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\n        int[] arr = new int[n];\n\n        arr[0] = sc.nextInt();\n\n        for (int i = 1; i < n; i++) {\n            arr[i] = arr[i - 1] + sc.nextInt();\n        }\n\n        HashMap<Integer, List<Pair>> map = new HashMap<>();\n\n        for (int i = 0; i < n; i++) {\n\n            if (map.containsKey(arr[i])) map.get(arr[i]).add(new Pair(0, i));\n            else {\n                List<Pair> l = new ArrayList<>();\n                l.add(new Pair(0, i));\n                map.put(arr[i], l);\n            }\n\n            for (int j = 1; j <= i; j++) {\n                int ss = arr[i] - arr[j - 1];\n                if (map.containsKey(ss)) map.get(ss).add(new Pair(j, i));\n                else {\n                    List<Pair> l = new ArrayList<>();\n                    l.add(new Pair(j, i));\n                    map.put(ss, l);\n                }\n            }\n        }\n\n        List<Pair> el = null;\n\n        for (List<Pair> value : map.values()) {\n            value.sort(Comparator.comparingInt(Pair::getStart));\n            ArrayList<Pair> ps = new ArrayList<>();\n            Pair last = value.get(0);\n\n            for (int i = 1; i < value.size(); i++) {\n                if (last.getEnd() < value.get(i).getStart()) {\n                    ps.add(last);\n                    last = value.get(i);\n                }\n                else if (last.getEnd() > value.get(i).getEnd()) last = value.get(i);\n            }\n\n            ps.add(last);\n\n            if (el == null) el = ps;\n            else if (ps.size() > el.size()) el = ps;\n        }\n\n        System.out.println(el.size());\n\n        for (Pair pair : el) {\n            System.out.println((pair.getStart() + 1) + \" \" + (pair.getEnd() + 1));\n        }\n\n    }\n}\n\nclass Pair {\n    private final int start;\n    private final int end;\n\n    public int getStart() {\n        return start;\n    }\n\n    public int getEnd() {\n        return end;\n    }\n\n    public Pair(int start, int end) {\n        this.start = start;\n        this.end = end;\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main{\nclass Node implements Comparable<Node>{\n    int l;\n    int r;\n    public Node(int l,int r){\n        this.l=l;\n        this.r=r;\n    }\n    public int compareTo(Node c){\n        int t=Integer.compare(this.r,c.r);\n        if(t!=0) return t;\n        t=Integer.compare(this.l,c.l);\n        return t;\n    }\n}\n    void solve() {\n        int n=ni();\n        int a[]=new int[n+1];\n        long pref[]=new long[n+1];\n        for(int i=1;i<=n;i++){\n            a[i]=ni();\n            pref[i]=pref[i-1]+a[i];\n        }\n        PriorityQueue<Long> q=new PriorityQueue<>();\n        for(int i=1;i<=n;i++){\n            for(int j=i;j<=n;j++) q.offer(pref[j]-pref[i-1]);\n        }\n        int sz=1;\n        while(!q.isEmpty()){\n            long val=q.poll();\n            if(!mp.containsKey(val)){\n               mp.put(val,sz++);\n            }\n        }\n        vec=new Node[sz][];\n        int size[]=new int[sz];\n        for(int i=1;i<=n;i++){\n            for(int j=i;j<=n;j++) size[mp.get(pref[j]-pref[i-1])]++;\n        }\n        for(int i=1;i<sz;i++) vec[i]=new Node[size[i]];\n        for(int i=1;i<=n;i++){\n            for(int j=i;j<=n;j++) {\n                int idx=mp.get(pref[j]-pref[i-1]);\n                vec[idx][--size[idx]]=new Node(i,j);\n            }\n        }\n\n        for(int i=1;i<sz;i++) Arrays.sort(vec[i]);\n        for(int i=1;i<sz;i++){\n            solve(vec[i]);\n        }\n        pw.println(ans.size());\n        for(Node p : ans) pw.println(p.l+\" \"+p.r);\n\n\n    }\n    HashMap<Long,Integer> mp=new HashMap<>();\n    Node vec[][];\n    int cnt=0;\n    ArrayList<Node> ans=new ArrayList<>();\n    void solve(Node [] v){\n        int n=v.length;\n        if(n==0) return;\n        int dp[]=new int[n+1];\n        int prev[]=new int[n+1];\n        int mx[]=new int[n+1];\n        int mxid[]=new int[n+1];\n        for(int i=1;i<=n;i++){\n            Node p=v[i-1];\n            dp[i]=dp[i-1];\n            prev[i]=-1;\n            int l=1,r=i-1;\n            int idx=0;\n            while(l<=r){\n                int mid=(l+r)>>1;\n                if(v[mid-1].r<p.l){\n                    idx=mid;\n                    l=mid+1;\n                }else r=mid-1;\n            }\n            if(1+mx[idx]>dp[i]){\n                dp[i]=1+mx[idx];\n                prev[i]=mxid[idx];\n            }\n            mx[i]=mx[i-1];\n            mxid[i]=mxid[i-1];\n            if(dp[i]>mx[i]){\n                mx[i]=dp[i];\n                mxid[i]=i;\n            }\n\n\n        }\n        if (dp[n] > cnt){\n            cnt=dp[n];\n            ans.clear();\n            int id=n;\n            while(id>0){\n                if(dp[id]==dp[id-1]){\n                    id--;\n                    continue;\n                }\n                ans.add(new Node(v[id-1].l,v[id-1].r));\n                id=prev[id];\n            }\n        }\n    }\n    long M = (long)1e9+7;\n    InputStream is;\n    PrintWriter pw;\n    String INPUT = \"\";\n\n    void run() throws Exception {\n        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        pw = new PrintWriter(System.out);\n        long s = System.currentTimeMillis();\n        solve();\n        pw.flush();\n        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + \"ms\");\n\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Main().run();\n    }\n\n    private byte[] inbuf = new byte[1024];\n    public int lenbuf = 0, ptrbuf = 0;\n\n    private int readByte() {\n        if (lenbuf == -1) throw new InputMismatchException();\n        if (ptrbuf >= lenbuf) {\n            ptrbuf = 0;\n            try {\n                lenbuf = is.read(inbuf);\n            } catch (IOException e) {\n                throw new InputMismatchException();\n            }\n            if (lenbuf <= 0) return -1;\n        }\n        return inbuf[ptrbuf++];\n    }\n\n    private boolean isSpaceChar(int c) {\n        return !(c >= 33 && c <= 126);\n    }\n\n    private int skip() {\n        int b;\n        while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n        return b;\n    }\n\n    private double nd() {\n        return Double.parseDouble(ns());\n    }\n\n    private char nc() {\n        return (char) skip();\n    }\n\n    private String ns() {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n\n    private char[] ns(int n) {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while (p < n && !(isSpaceChar(b))) {\n            buf[p++] = (char) b;\n            b = readByte();\n        }\n        return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n\n    private char[][] nm(int n, int m) {\n        char[][] map = new char[n][];\n        for (int i = 0; i < n; i++) map[i] = ns(m);\n        return map;\n    }\n\n    private int[] na(int n) {\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) a[i] = ni();\n        return a;\n    }\n\n    private int ni() {\n        int num = 0, b;\n        boolean minus = false;\n        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n        if (b == '-') {\n            minus = true;\n            b = readByte();\n        }\n\n        while (true) {\n            if (b >= '0' && b <= '9') {\n                num = num * 10 + (b - '0');\n            } else {\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n\n    private long nl() {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n        if (b == '-') {\n            minus = true;\n            b = readByte();\n        }\n\n        while (true) {\n            if (b >= '0' && b <= '9') {\n                num = num * 10 + (b - '0');\n            } else {\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n\n    private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    private void tr(Object... o) {\n        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));\n    }\n\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.LinkedList;\nimport java.util.Comparator;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        Task547F solver = new Task547F();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class Task547F {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            long arr[] = in.nextLongArray(n);\n            long cur = 0;\n            int i, j;\n            Map<Long, List<Pair>> hm = new HashMap<>();\n\n            for (i = 0; i < n; i++) {\n                cur = 0;\n                for (j = i; j < n; j++) {\n                    cur += arr[j];\n                    if (!hm.containsKey(cur)) {\n                        List<Pair> al = new LinkedList<>();\n                        al.add(new Pair(i + 1, j + 1));\n                        hm.put(cur, al);\n                    } else {\n                        List<Pair> al = hm.get(cur);\n                        al.add(new Pair(i + 1, j + 1));\n                        hm.put(cur, al);\n                    }\n                }\n            }\n            //out.println(hm);\n            long max = arr[0];\n            int msize = 0;\n            for (long key : hm.keySet()) {\n                List<Pair> al = hm.get(key);\n                if (al.size() < hm.get(max).size())\n                    continue;\n                Collections.sort(al, new Comparator<Pair>() {\n\n                    public int compare(Pair o1, Pair o2) {\n                        if (o1.b != o2.b)\n                            return o1.b - o2.b;\n                        return o1.a - o2.a;\n                    }\n                });\n                //out.println(al);\n                List<Pair> all = new LinkedList<>();\n                int prev = -1;\n                for (Pair p : al) {\n                    if (p.a > prev) {\n                        all.add(p);\n                        prev = p.b;\n                    }\n                }\n                //out.println(all);\n\n                hm.put(key, all);\n                //out.println(all.size());\n                if (all.size() > msize) {\n                    //out.println(\"ca\" + msize + \" \" + all.size());\n                    msize = all.size();\n                    max = key;\n                }\n\n            }\n            //out.println(hm);\n\n            List<Pair> al = hm.get(max);\n            out.println(al.size());\n            for (Pair p : al) {\n                out.println(p.a + \" \" + p.b);\n            }\n\n        }\n\n        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            public String toString() {\n                return \"(\" + a + \", \" + b + \")\";\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public 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 long[] nextLongArray(int n) {\n            long[] array = new long[n];\n            for (int i = 0; i < n; ++i) array[i] = nextLong();\n            return array;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void print(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n        }\n\n        public void println(Object... objects) {\n            print(objects);\n            writer.println();\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void println(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Soln {\n\t\n\tpublic static int[] io(int n) {\n    \tint[] d = new int[n];\n    \tfor (int i=0;i<n;i++) d[i] = f.nextInt();\n    \treturn d;\n\t}\n\tpublic static int binlog( int bits ){\n        int log = 0;\n        if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; }\n        if( bits >= 256 ) { bits >>>= 8; log += 8; }\n        if( bits >= 16  ) { bits >>>= 4; log += 4; }\n        if( bits >= 4   ) { bits >>>= 2; log += 2; }\n        return log + ( bits >>> 1 );\n    }\n\tstatic 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\t}\n\tpublic static final long mod = (long)Math.pow(10, 9) + 7;\n\tstatic FastReader f=new FastReader();\n\t\n\tpublic static void main (String[] args) throws IOException{\n\t\tint n = f.nextInt();\n\t\tint[] a = io(n);\n\t\tHashMap<Integer,ArrayList<ivl>> hm = new HashMap<>();\n\t\tfor (int i=0;i<n;i++) {\n\t\t\tint sum = 0;\n\t\t\tfor (int j=i;j<n;j++) {\n\t\t\t\tsum+=a[j];\n\t\t\t\tif (hm.get(sum)==null) hm.put(sum,new ArrayList<ivl>());\n\t\t\t\thm.get(sum).add(new ivl(i,j));\n\t\t\t}\n\t\t}\n\t\tHashSet<ivl> hs = new HashSet<ivl>();\n\t\t\n\t\tfor (ArrayList<ivl> arr : hm.values()) {\n\t\t\tCollections.sort(arr,new comp());\n\t\t\tHashSet<ivl> temp = new HashSet<ivl>();\n\t\t\ttemp.add(arr.get(0));\n\t\t\tint lastr = arr.get(0).r;\n\t\t\tint num = 1;\n\t\t\tfor (ivl curr:arr) {\n\t\t\t\tif (curr.l>lastr) {\n\t\t\t\t\tlastr = curr.r;\n\t\t\t\t\tnum++;\n\t\t\t\t\ttemp.add(curr);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (temp.size()>hs.size()) hs = temp;\n\t\t}\n\t\t\n\t\tSystem.out.println(hs.size());\n\t\tfor (ivl curr:hs) {\n\t\t\tSystem.out.println((curr.l+1)+\" \"+(curr.r+1));\n\t\t}\n    }\n\t\n\tstatic class ivl{\n\t\tint l,r;\n\t\tivl(int l,int r){\n\t\t\tthis.l=l;this.r=r;\n\t\t}\n\t}\n\t\n\tstatic class comp implements Comparator<ivl>{\n\t\tpublic int compare(ivl a,ivl b) {\n\t\t\tif (a.r - b.r == 0) return a.l-b.l;\n\t\t\treturn a.r-b.r;\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\n\npublic class F{\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\tstatic class Pair\n\t{\n\t\tint l;\n\t\tint r;\n\t\tPair(int l,int r)\n\t\t{\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\t}\n\tpublic static void main(String[] args) \n\t{\n\t\tOutputStream outputStream = System.out;\n        FastReader sc = new FastReader();\n        PrintWriter out = new PrintWriter(outputStream);\n        int n = sc.nextInt();\n        int a[] = new int[n];\n        Pair pr;\n        HashMap<Long,ArrayList> hm = new HashMap<>();\n        ArrayList<Pair> ar;\n        for(int i = 0; i < n; i++)\n        {\n        \ta[i] = sc.nextInt();\n        }\n        long sum = 0;\n        for(int r = 0; r < n; r++)\n        {\t\n        \tsum = 0;\n        \tfor(int l = r; l >= 0; l--)\n        \t{\n        \t\tsum += a[l];\n        \t\tif(!hm.containsKey(sum))\n        \t\t{\n        \t\t\tar = new ArrayList<>();\n        \t\t\tar.add(new Pair(l,r));\n        \t\t\thm.put(sum,ar);\n        \t\t}\n        \t\telse\n        \t\t{\n        \t\t\tar = hm.get(sum);\n        \t\t\tar.add(new Pair(l,r));\n        \t\t\thm.put(sum,ar);\n        \t\t}\n        \t}\n        }\n        \n        int count = 0;\n        int maxCount = 0;\n        long maxSum = 0;\n        for(Map.Entry<Long,ArrayList> entry:hm.entrySet())\n        {\n        \tsum = entry.getKey();\n        \tar = entry.getValue();\n        \tcount = 0;\n        \tint r = -1;\n        \tfor(int i = 0; i < ar.size(); i++)\n        \t{\n        \t\tif(ar.get(i).l > r)\n        \t\t{\n        \t\t\tcount++;\n        \t\t\tr = ar.get(i).r;\n        \t\t}\n        \t}\n        \tif(count > maxCount)\n        \t{\n        \t\tmaxCount = count;\n        \t\tmaxSum = sum;\n        \t}\n        \t\n        }\n        ar = hm.get(maxSum);\n        out.println(maxCount);\n        //out.println((ar.get(0).l+1)+\" \"+(ar.get(0).r+1));\n        \n        int r = -1;\n        for(int i = 0; i < ar.size(); i++)\n    \t{\n    \t\tif(ar.get(i).l > r)\n    \t\t{\n    \t\t\tout.println((ar.get(i).l+1) +\" \"+(ar.get(i).r+1));\n    \t\t\tr = ar.get(i).r;\n    \t\t}\n    \t}\n        out.close();\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\n\nimport java.util.*;\npublic class Main{\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        PrintWriter out=new PrintWriter(System.out);\n\n        int n=sc.nextInt();\n        int a[]=new int[n];\n        for (int i = 0; i <n ; i++) {\n            a[i]=sc.nextInt();\n        }\n\n        HashMap<Integer,ArrayList<Node>> h=new HashMap<>();\n        for (int i = 0; i <n ; i++) {\n            int sum=0;\n            for (int j = i; j <n ; j++) {\n                sum+=a[j];\n                if(h.containsKey(sum)){\n                    h.get(sum).add(new Node(i,j));\n                }\n                else{\n                    ArrayList<Node> temp=new ArrayList<>();\n                    temp.add(new Node(i,j));\n                    h.put(sum,temp);\n                }\n            }\n        }\n\n        long ans=0;\n        ArrayList<Integer> ansList=new ArrayList<>();\n\n        for(int x:h.keySet()){\n            Collections.sort(h.get(x), new Comparator<Node>() {\n                @Override\n                public int compare(Node o1, Node o2) {\n                    return Integer.compare(o1.r,o2.r);\n                }\n            });\n\n\n            ArrayList<Node>  l=h.get(x);\n            //out.println(l);\n            ArrayList<Integer> temp=new ArrayList<>();\n            int lasty=Integer.MIN_VALUE;\n            for (int i = 0; i <l.size() ; i++) {\n                if(l.get(i).l>lasty){\n                    lasty=l.get(i).r;\n                    temp.add(l.get(i).l);\n                    temp.add(l.get(i).r);\n                }\n            }\n\n            if(ans<temp.size()){\n                ansList=temp;\n                ans=ansList.size();\n            }\n        }\n\n        out.println(ans/2);\n        for (int i = 0; i <ansList.size() ; i++) {\n            out.print((ansList.get(i)+1)+\" \");\n            i++;\n            out.println((ansList.get(i)+1)+\" \");\n        }\n\n\n\n        out.close();\n    }\n\n    static class Node{\n        int l,r;\n        public Node(int a,int b){\n            l=a;\n            r=b;\n        }\n    }\n\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1141f2_2 {\n\n    public static void main(String[] args) throws IOException {\n        int n = ri(), a[] = ria(n), pre[] = new int[n + 1];\n        for (int i = 0; i < n; ++i) {\n            pre[i + 1] = pre[i] + a[i];\n        }\n        Map<Integer, List<p>> sums = new HashMap<>();\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j <= i; ++j) {\n                sums.computeIfAbsent(pre[i + 1] - pre[j], k -> new ArrayList<>()).add(new p(j, i));\n            }\n        }\n        int k = 0;\n        List<p> ans = new ArrayList<>();\n        for (int key : sums.keySet()) {\n            List<p> segs = sums.get(key);\n            segs.sort((x, y) -> x.b == y.b ? x.a - y.a : x.b - y.b);\n            int last = -1, cnt = 0;\n            for (int i = 0, end = segs.size(); i < end; ++i) {\n                if (segs.get(i).a > last) {\n                    ++cnt;\n                    last = segs.get(i).b;\n                }\n            }\n            if (cnt > k) {\n                k = cnt;\n                ans = segs;\n            }\n        }\n        prln(k);\n        int last = -1;\n        for (int i = 0, end = ans.size(); i < end; ++i) {\n            if (ans.get(i).a > last) {\n                prln(ans.get(i).a + 1, ans.get(i).b + 1);\n                last = ans.get(i).b;\n            }\n        }\n        close();\n    }\n\n    static class p {\n        int a, b;\n\n        p(int a_, int b_) {\n            a = a_;\n            b = b_;\n        }\n\n        @Override\n        public String toString() {\n            return \"Pair{\" + \"a = \" + a + \", b = \" + b + '}';\n        }\n\n\n        public boolean asymmetricEquals(Object o) {\n            p p = (p) o;\n            return a == p.a && b == p.b;\n        }\n\n        public boolean symmetricEquals(Object o) {\n            p p = (p) o;\n            return a == p.a && b == p.b || a == p.b && b == p.a;\n        }\n\n        @Override\n        public boolean equals(Object o) {\n            return asymmetricEquals(o);\n        }\n\n        public int asymmetricHashCode() {\n            return Objects.hash(a, b);\n        }\n\n        public int symmetricHashCode() {\n            return Objects.hash(a, b) + Objects.hash(b, a);\n        }\n\n        @Override\n        public int hashCode() {\n            return asymmetricHashCode();\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<List<Integer>> g(int n) {List<List<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n    static List<Set<Integer>> sg(int n) {List<Set<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n    static void c(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n    static void cto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);}\n    static void dc(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n    static void dcto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);}\n    // input\n    static void r() throws IOException {input = new StringTokenizer(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<List<Integer>> rg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n    static void rg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n    static List<List<Integer>> rdg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n    static void rdg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n    static List<Set<Integer>> rsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n    static void rsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n    static List<Set<Integer>> rdsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n    static void rdsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n    // output\n    static void pr(int i) {__out.print(i);}\n    static void prln(int i) {__out.println(i);}\n    static void pr(long l) {__out.print(l);}\n    static void prln(long l) {__out.println(l);}\n    static void pr(double d) {__out.print(d);}\n    static void prln(double d) {__out.println(d);}\n    static void pr(char c) {__out.print(c);}\n    static void prln(char c) {__out.println(c);}\n    static void pr(char[] s) {__out.print(new String(s));}\n    static void prln(char[] s) {__out.println(new String(s));}\n    static void pr(String s) {__out.print(s);}\n    static void prln(String s) {__out.println(s);}\n    static void pr(Object o) {__out.print(o);}\n    static void prln(Object o) {__out.println(o);}\n    static void prln() {__out.println();}\n    static void pryes() {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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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();}}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskF2 solver = new TaskF2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF2 {\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\n            HashMap<Long, ArrayList<Interval>> map = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                long sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    if (map.containsKey(sum) == false) {\n                        map.put(sum, new ArrayList<>());\n                    }\n                    ArrayList<Interval> arr = map.get(sum);\n                    if (arr.isEmpty() || arr.get(arr.size() - 1).r < i) {\n                        arr.add(new Interval(i, j));\n                    } else if (arr.get(arr.size() - 1).r >= j) {\n                        arr.set(arr.size() - 1, new Interval(i, j));\n                    }\n                }\n            }\n\n            ArrayList<Interval> best = new ArrayList<>();\n            for (ArrayList<Interval> arr : map.values()) {\n                if (best.size() < arr.size()) {\n                    best = arr;\n                }\n            }\n\n            out.println(best.size());\n            for (Interval i : best) {\n                out.println((i.l + 1) + \" \" + (i.r + 1));\n            }\n        }\n\n        class Interval {\n            int l;\n            int r;\n\n            Interval(int l, int r) {\n                this.l = l;\n                this.r = r;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\t\n\tpublic static class node implements Comparable<node>{\n\t\tint l,r;\n\t\tnode(){}\n\t\tnode(int l,int r) {\n\t\t\tthis.l=l;\n\t\t\tthis.r=r;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(node rhs) {\n\t\t\treturn r-rhs.r;\n\t\t}\n\t}\n\t\n\tpublic static void main(String args[]){\n\t\tScanner in = new Scanner(System.in);\n\t\tint a = in.nextInt();\n\t\tint x[] = new int[a];\n\t\tfor(int n=0;n<a;n++){\n\t\t\tx[n] = in.nextInt();\n\t\t}\n\t\tint max = 1;\n\t\tint t = 0;\n\t\tHashMap<Integer, ArrayList<node>> map = new HashMap<Integer, ArrayList<node>>();\n\t\tfor(int n=0;n<a;n++){\n\t\t\tint num = 0;\n\t\t\tfor(int m=n;m<a;m++){\n\t\t\t\tnum += x[m];\n\t\t\t\tnode node = new node(n, m);\n\t\t\t\tif(!map.containsKey(num)){\n\t\t\t\t\tArrayList<node> list = new ArrayList<node>();\n\t\t\t\t\tlist.add(node);\n\t\t\t\t\tmap.put(num, list);\n\t\t\t\t\tif(max == 1)t = num;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tArrayList<node> list = map.get(num);\n\t\t\t\t\tint left = 0;\n\t\t\t\t\tint right = list.size()-1;\t\t\t\t\n\t\t\t\t\tint res = list.size();\n\t\t\t\t\twhile(left <= right){\n\t\t\t\t\t\tint mid = (left + right) >> 1;\n\t\t\t\t\t\t//System.out.println(mid +\" \"+ left +\" \" +right);\n\t\t\t\t\t\tif(list.get(mid).r >= n){\n\t\t\t\t\t\t\tres = mid;\n\t\t\t\t\t\t\tright = mid - 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tleft = mid + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif(res == list.size()){\n\t\t\t\t\t\tlist.add(node);\n\t\t\t\t\t\tif(max < res+1){\n\t\t\t\t\t\t\tmax = res+1;\n\t\t\t\t\t\t\tt = num;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if(list.get(res).r>m){\n\t\t\t\t\t\tlist.set(res, node);\n\t\t\t\t\t\tif(max < res){\n\t\t\t\t\t\t\tmax = list.size();\n\t\t\t\t\t\t\tt = num;\n\t\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}\n\t\tSystem.out.println(max);\n\t\tfor(int n=0;n<max;n++){\n\t\t\tSystem.out.println((map.get(t).get(n).l+1)+\" \"+(map.get(t).get(n).r+1));\n\t\t}\n\t\t\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Q3 {\n\n    static class Pair {\n        int a;\n        int b;\n\n        Pair(int p, int q) {\n            a = p;\n            b = q;\n        }\n    }\n\n    public static void main(String[] args) {\n\n        InputReader in = new InputReader();\n        int N = in.nextInt();\n        int arr[] = new int[N];\n\n        for (int i = 0; i < N; i++)\n            arr[i] = in.nextInt();\n\n        HashMap<Integer, ArrayList<Pair>> name = new HashMap<>();\n\n        for (int i = 0; i < N; i++) {\n            int sum = 0;\n            for (int j = i; j < N; j++) {\n                sum += arr[j];\n                if (name.get(sum) == null)\n                    name.put(sum, new ArrayList());\n\n                name.get(sum).add(new Pair(i+1, j+1));\n            }\n        }\n\n        HashSet<Pair> ans = new HashSet<>();\n\n        for (ArrayList<Pair> n : name.values()) {\n            Collections.sort(n, new Comparator<Pair>() {\n                @Override\n                public int compare(Pair o1, Pair o2) {\n                    if (Integer.compare(o1.b, o2.b) == 0)\n                        return Integer.compare(o1.a, o2.a);\n                    return Integer.compare(o1.b, o2.b);\n                }\n            });\n\n\n            HashSet<Pair> temp = new HashSet<>();\n            temp.add(n.get(0));\n            int num = 1;\n            int r = n.get(0).b;\n\n            for (int i = 1; i < n.size(); i++) {\n\n                if (n.get(i).a > r) {\n                    num++;\n                    r = n.get(i).b;\n                    temp.add(n.get(i));\n                }\n            }\n\n\n            if (num > ans.size())\n                ans = temp;\n        }\n\n        System.out.println(ans.size());\n        for (Pair val : ans)\n            System.out.println(val.a + \" \" + val.b);\n\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public 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        public InputReader() {\n            reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n            tokenizer = null;\n        }\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(System.in), 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 char nextChar() {\n            return next().charAt(0);\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 int[] nextIntArr(int n) {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = this.nextInt();\n            }\n            return arr;\n        }\n\n        public Integer[] nextIntegerArr(int n) {\n            Integer[] arr = new Integer[n];\n            for (int i = 0; i < n; i++)\n                arr[i] = new Integer(this.nextInt());\n\n            return arr;\n        }\n\n        public int[][] next2DIntArr(int n, int m) {\n            int[][] arr = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    arr[i][j] = this.nextInt();\n                }\n            }\n            return arr;\n        }\n\n        public int[] nextSortedIntArr(int n) {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = this.nextInt();\n            }\n            Arrays.sort(arr);\n            return arr;\n        }\n\n        public long[] nextLongArr(int n) {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = this.nextLong();\n            }\n            return arr;\n        }\n\n        public char[] nextCharArr(int n) {\n            char[] arr = new char[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = this.nextChar();\n            }\n            return arr;\n        }\n\n\n        public static int gcd(int a, int b) {\n            return b == 0 ? a : gcd(b, a % b);\n        }\n\n        public static int[] uwiSieve(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[] isp = 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 & 31);\n                for (int i = 0; i < tp; i++) {\n                    for (int j = i; j < sup; j += tp)\n                        isp[j] |= ptn[i];\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, 7, 12, 21, 17,\n                    9, 6, 16, 5, 15, 14};\n            int h = n / 2;\n            for (int i = 0; i < sup; i++) {\n                for (int j = ~isp[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                    for (int q = pp; q <= h; q += p)\n                        isp[q >> 5] |= 1 << (q & 31);\n                }\n            }\n\n            return Arrays.copyOf(ret, pos);\n        }\n\n        public static int[] radixSort(int[] f) {\n            return radixSort(f, f.length);\n        }\n\n        public static int[] radixSort(int[] f, int n) {\n            int[] to = new int[n];\n            {\n                int[] b = new int[65537];\n                for (int i = 0; i < n; i++) b[1 + (f[i] & 0xffff)]++;\n                for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];\n                for (int i = 0; i < n; i++) to[b[f[i] & 0xffff]++] = f[i];\n                int[] d = f;\n                f = to;\n                to = d;\n            }\n            {\n                int[] b = new int[65537];\n                for (int i = 0; i < n; i++) b[1 + (f[i] >>> 16)]++;\n                for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];\n                for (int i = 0; i < n; i++) to[b[f[i] >>> 16]++] = f[i];\n                int[] d = f;\n                f = to;\n                to = d;\n            }\n            return f;\n        }\n    }\n\n}\n\n\n// for(Map.Entry<Integer,Integer> Test: map.entrySet()){\n//            int Key=Test.getKey();\n//            int val=Test.getValue();\n//        }\n\n\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/*\nKeep solving problems.\n*/\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CFA {\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n    private static final long MOD = 1000L * 1000L * 1000L + 7;\n    private static final int[] dx = {0, -1, 0, 1};\n    private static final int[] dy = {1, 0, -1, 0};\n    private static final String yes = \"Yes\";\n    private static final String no = \"No\";\n\n    int n;\n    int[] arr;\n    class Segment {\n        int start;\n        int end;\n        public Segment(int start, int end) {\n            this.start = start;\n            this.end = end;\n        }\n\n        @Override\n        public String toString() {\n            return start + \" \" + end;\n        }\n    }\n    Map<Integer, List<Segment>> hm = new HashMap<>();\n    void solve() throws IOException {\n        n = nextInt();\n        arr = nextIntArr(n);\n        for (int i = 0; i < n; i++) {\n            int sum = 0;\n            for (int j = i; j < n; j++) {\n                sum += arr[j];\n                if (!hm.containsKey(sum)) {\n                    hm.put(sum, new ArrayList<>());\n                }\n\n                hm.get(sum).add(new Segment(i, j));\n            }\n        }\n\n        int max = -1;\n        int idx = -1;\n        for (Map.Entry<Integer, List<Segment>> entry : hm.entrySet()) {\n            int key = entry.getKey();\n            List<Segment> values = entry.getValue();\n            Collections.sort(values, new Comparator<Segment>() {\n                @Override\n                public int compare(Segment o1, Segment o2) {\n                    return Integer.compare(o1.end, o2.end);\n                }\n            });\n            int cnt = findSeg(values).size();\n            if (cnt > max) {\n                max = cnt;\n                idx = key;\n            }\n        }\n\n        List<Segment> res = findSeg(hm.get(idx));\n        outln(res.size());\n        for (int i = 0; i < res.size(); i++) {\n            outln((1 + res.get(i).start) + \" \" + (1 + res.get(i).end));\n        }\n    }\n\n    List<Segment> findSeg(List<Segment> input) {\n        List<Segment> res = new ArrayList<>();\n        int bound = -1;\n        for (int i = 0; i < input.size(); i++) {\n            if (input.get(i).start > bound) {\n                res.add(input.get(i));\n                bound = input.get(i).end;\n            }\n        }\n\n        return res;\n    }\n\n    void shuffle(int[] a) {\n        int n = a.length;\n        for(int i = 0; i < n; i++) {\n            int r = i + (int) (Math.random() * (n - i));\n            int tmp = a[i];\n            a[i] = a[r];\n            a[r] = tmp;\n        }\n    }\n    long gcd(long a, long b) {\n        while(a != 0 && b != 0) {\n            long c = b;\n            b = a % b;\n            a = c;\n        }\n        return a + b;\n    }\n    private void outln(Object o) {\n        out.println(o);\n    }\n    private void out(Object o) {\n        out.print(o);\n    }\n    private void formatPrint(double val) {\n        outln(String.format(\"%.9f%n\", val));\n    }\n    public 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "// package CF1141;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1141F1 {\n    static FastReader s;\n    static PrintWriter out;\n    static String INPUT = \"7\\n\" +\n            \"4 1 2 2 1 5 3\\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        int n = s.nextInt();\n        int[] arr = s.nextIntArray(n);\n        int[] sum = new int[n];\n        sum[0] = arr[0];\n        for (int i = 1; i < n; i++) {\n            sum[i] = sum[i - 1] + arr[i];\n        }\n\n//        int max = Integer.MIN_VALUE;\n        HashMap<Integer, ArrayList<pair>> map = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            for (int j = i; j < n; j++) {\n                if(i == 0) {\n                    ArrayList<pair> list = map.getOrDefault(sum[j], new ArrayList<>());\n                    list.add(new pair(i, j));\n                    map.put(sum[j], list);\n                } else {\n                    ArrayList<pair> list = map.getOrDefault(sum[j] - sum[i - 1], new ArrayList<>());\n                    list.add(new pair(i, j));\n                    map.put(sum[j] - sum[i - 1], list);\n                }\n            }\n        }\n\n        ArrayList<Integer> keys = new ArrayList<>(map.keySet());\n        ArrayList<pair> ans = null;\n        for (int curr : keys) {\n            ArrayList<pair> list = map.get(curr);\n            Collections.sort(list);\n            ArrayList<pair> smallAns = new ArrayList<>();\n            smallAns.add(list.get(0));\n            for (int k = 1; k < list.size(); k++) {\n                if(list.get(k).start > smallAns.get(smallAns.size() - 1).finish) {\n                    smallAns.add(list.get(k));\n                }\n            }\n\n            if(ans == null) {\n                ans = smallAns;\n            } else {\n                if(ans.size() < smallAns.size()) {\n                    ans = smallAns;\n                }\n            }\n        }\n\n//        out.println(ans.size() + \"\\n\" + ans);\n//\n//        out.println(map);\n//\n//        out.println(Arrays.toString(sum));\n        StringBuilder ans1 = new StringBuilder();\n        ans1.append(ans.size() + \"\\n\");\n        for (pair p : ans) {\n            ans1.append((p.start + 1) + \" \" + (p.finish + 1));\n            ans1.append(\"\\n\");\n        }\n        out.println(ans1);\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 pair implements Comparable<pair>{\n        int start;\n        int finish;\n\n        public pair(int start, int finish) {\n            this.start = start;\n            this.finish = finish;\n        }\n\n\n        @Override\n        public int compareTo(pair o) {\n            return Integer.compare(this.finish, o.finish);\n        }\n\n        @Override\n        public String toString() {\n            return this.start + \" \" + this.finish;\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<Long> printDivisors(long n) {\n            // Note that this loop runs till square root\n            ArrayList<Long> 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", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "//package codeforces_464_div2;\n\nimport java.util.*;\nimport java.util.stream.Collectors;\n\npublic class F {\n    public static void main(String[] args) {\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++) arr[i] = sc.nextInt();\n        int[][] sub = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            sub[i][i] = arr[i];\n            for (int j = i + 1; j < n; j++) {\n                sub[i][j] = sub[i][j - 1] + arr[j];\n            }\n        }\n\n        HashMap<Integer, List<P>> hm = new HashMap<>();\n        /*for (int i = 0; i < n; i++) {\n            for (int j = i; j < n; j++) {\n                if (hm.containsKey(sub[i][j])) {\n                    hm.get(sub[i][j]).add(new P(i, j));\n                } else {\n                    List<P> temp = new ArrayList<>();\n                    temp.add(new P(i, j));\n                    hm.put(sub[i][j], temp);\n                }\n            }\n        }*/\n        for(int stop=0; stop<n; stop++) {\n            for(int start=0; start<=stop; start++) {\n                if (hm.containsKey(sub[start][stop])) {\n                    hm.get(sub[start][stop]).add(new P(start, stop));\n                } else {\n                    List<P> temp = new ArrayList<>();\n                    temp.add(new P(start, stop));\n                    hm.put(sub[start][stop], temp);\n                }\n            }\n        }\n\n        int ans = Integer.MIN_VALUE;\n        /*for(Map.Entry it : hm.entrySet()) {\n            int or = overlap(it.getValue());\n            ans = Math.max(ans, or);\n        }*/\n\n        List<P> ansList = null;\n        for (List<P> it : hm.values()) {\n            int or = overlap(it);\n            if(or>ans) {\n                ans = or;\n                ansList = it;\n            }\n        }\n\n        List<P> processedList = extractOverlapping(ansList);\n\n        System.out.println(ans);\n        for(int i=0; i<processedList.size(); i++) {\n            int A = processedList.get(i).a + 1;\n            int B = processedList.get(i).b + 1;\n            System.out.println(A + \" \" + B);\n        }\n    }\n\n    public static int overlap(List<P> listOfPair) {\n        /*List<P> sortedList = listOfPair.stream()\n                .sorted((pair1, pair2) -> pair1.getB().compareTo(pair2.getB()))\n                .collect(Collectors.toList());*/\n        List<P> sortedList = listOfPair;\n\n        int cnt = 0;\n        int end = sortedList.get(0).b;\n        for (int i = 1; i < sortedList.size(); i++) {\n            if (sortedList.get(i).a <= end) {\n                cnt++;\n            } else {\n                end = sortedList.get(i).b;\n            }\n        }\n\n        return sortedList.size() - cnt;\n    }\n\n    public static List<P> extractOverlapping(List<P> ansList) {\n        List<P> sortedList = ansList.stream()\n                .sorted((pair1, pair2) -> pair1.getB().compareTo(pair2.getB()))\n                .collect(Collectors.toList());\n\n        List<P> finalList = new ArrayList<>();\n        finalList.add(sortedList.get(0));\n        int end = sortedList.get(0).b;\n        for (int i = 1; i < sortedList.size(); i++) {\n            if (sortedList.get(i).a <= end) {\n                continue;\n            } else {\n                finalList.add(sortedList.get(i));\n                end = sortedList.get(i).b;\n            }\n        }\n\n        return finalList;\n    }\n}\n\nclass P implements Comparable<P> {\n    Integer a;\n    Integer b;\n\n    public P(int a, int b) {\n        this.a = a;\n        this.b = b;\n    }\n\n    public Integer getA() {\n        return a;\n    }\n\n    public Integer getB() {\n        return b;\n    }\n\n    @Override\n    public int compareTo(P that) {\n        return this.b.compareTo(that.b);\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main {\n    public static void main(String args[])\n    {\n        FastReader input=new FastReader();\n        PrintWriter out=new PrintWriter(System.out);\n        int T=1;\n        while(T-->0)\n        {\n            int n=input.nextInt();\n            int a[]=new int[n];\n            for(int i=0;i<n;i++)\n            {\n                a[i]=input.nextInt();\n            }\n            HashMap<Integer,ArrayList<Pair>> map=new HashMap<>();\n            for(int i=0;i<n;i++)\n            {\n                int sum=0;\n                for(int j=i;j<n;j++)\n                {\n                    sum+=a[j];\n                    if(map.containsKey(sum))\n                    {\n                        map.get(sum).add(new Pair(i,j));\n                    }\n                    else\n                    {\n                        map.put(sum,new ArrayList<>());\n                        map.get(sum).add(new Pair(i,j));\n                    }\n                }\n            }\n            int max=Integer.MIN_VALUE;\n            Iterator it=map.entrySet().iterator();\n            ArrayList<Pair> setBlocks=new ArrayList<>();\n            while(it.hasNext())\n            {\n                Map.Entry e=(Map.Entry)it.next();\n                ArrayList<Pair> list=(ArrayList)e.getValue();\n                Collections.sort(list, new Comparator<Pair>() {\n                    @Override\n                    public int compare(Pair o1, Pair o2) {\n                        if(o1.l==o2.l)\n                        {\n                            return o1.r-o2.r;\n                        }\n                        else\n                        {\n                            return o1.l-o2.l;\n                        }\n                    }\n                });\n                Pair1 sufMin[]=new Pair1[list.size()];\n                TreeSet<Pair> set=new TreeSet<>(new Comparator<Pair>() {\n                    @Override\n                    public int compare(Pair o1, Pair o2) {\n                        if(o1.l==o2.l)\n                        {\n                            return o1.r-o2.r;\n                        }\n                        else\n                        {\n                            return o1.l-o2.l;\n                        }\n                    }\n                });\n                int min=Integer.MAX_VALUE;\n                int index=-1;\n                for(int j=list.size()-1;j>=0;j--)\n                {\n                    if(min>=list.get(j).r)\n                    {\n                        min=list.get(j).r;\n                        index=j;\n                    }\n                    sufMin[j]=new Pair1(min,index);\n                    set.add(new Pair(list.get(j).l,j));\n                }\n                int count=0;\n                int j=0;\n                ArrayList<Pair> blocks=new ArrayList<>();\n                while(j<list.size())\n                {\n                    int m=sufMin[j].min;\n                    int ind=sufMin[j].index;\n                    blocks.add(list.get(ind));\n                    count++;\n                    Pair p=new Pair(m+1,0);\n                    if(set.ceiling(p)==null)\n                    {\n                        break;\n                    }\n                    else\n                    {\n                        Pair p1=set.ceiling(p);\n                        j=p1.r;\n                    }\n                }\n                if(max<count)\n                {\n                    max=count;\n                    setBlocks=blocks;\n                }\n            }\n            out.println(max);\n            for(int i=0;i<setBlocks.size();i++)\n            {\n                out.println((setBlocks.get(i).l+1)+\" \"+(setBlocks.get(i).r+1));\n            }\n        }\n        out.close();\n    }\n    public static class Pair1\n    {\n        int min,index;\n        Pair1(int min,int index)\n        {\n            this.min=min;\n            this.index=index;\n        }\n    }\n    public static class Pair\n    {\n        int l,r;\n        Pair(int l,int r)\n        {\n            this.l=l;\n            this.r=r;\n        }\n    }\n    static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastReader()\n        {\n            br = new BufferedReader(new 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        int nextInt()\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong()\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble()\n        {\n            return Double.parseDouble(next());\n        }\n        String nextLine()\n        {\n            String str=\"\";\n            try\n            {\n                str=br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "//package codeforces;\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class SameSumBlocksHard {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint n = in .nextInt();\n\n\t\tlong[] a = new long[n + 1];\n\t\tlong[] sum = new long[n + 1];\n\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t\tsum[i] = sum[i - 1] + a[i];\n\t\t}\n\n\t\tMap<Long, List<int[]>> map = new HashMap<>();\n\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = i; j <= n; j++) {\n\t\t\t\tlong x = sum[j] - sum[i - 1];\n\t\t\t\tList<int[]> list = map.get(x);\n\t\t\t\tif (list == null) {\n\t\t\t\t\tlist = new ArrayList<>();\n\t\t\t\t\tmap.put(x, list);\n\t\t\t\t}\n\t\t\t\tlist.add(new int[] {i, j});\n\t\t\t}\n\t\t}\n\n\t\tList<int[]> ans = new ArrayList<>();\n\t\tfor (Map.Entry<Long, List<int[]>> entry : map.entrySet()) {\n\t\t\tList<int[]> list = entry.getValue();\n\t\t\tList<int[]> tmp = new ArrayList<>();\n\t\t\tcalc(list, tmp);\n\t\t\tif (tmp.size() > ans.size()) {\n\t\t\t\tans.clear();\n\t\t\t\tans.addAll(tmp);\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ans.size());\n\t\tfor (int[] pair : ans) {\n\t\t\tSystem.out.println(pair[0] + \" \" + pair[1]);\n\t\t}\n\n\t\tin.close();\n\t}\n\n\tstatic void calc(List<int[]> list, List<int[]> tmp) {\n\t\tCollections.sort(list, new Comparator<int[]>() {\n\t\t\t@Override\n\t\t\tpublic int compare(int[] o1, int[] o2) {\n\t\t\t\tif (o1[1] < o2[1]) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (o1[1] > o2[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});\n\n\t\tint last = -1;\n\t\tfor (int[] p : list) {\n\t\t\tif (last == -1) {\n\t\t\t\tlast = p[1];\n\t\t\t\ttmp.add(p);\n\t\t\t} else if (p[0] > last) {\n\t\t\t\tlast = p[1];\n\t\t\t\ttmp.add(p);\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\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 Liavontsi Brechka\n */\npublic class Main\n{\n    public static void main(String[] args)\n    {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F1BlokiRavnoiSummiProstayaRedakciya solver = new F1BlokiRavnoiSummiProstayaRedakciya();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F1BlokiRavnoiSummiProstayaRedakciya\n    {\n        InputReader in;\n        Map<Long, List<F1BlokiRavnoiSummiProstayaRedakciya.Block>> sums;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out)\n        {\n            this.in = in;\n\n            int n = ni();\n            long[] a = nla(n);\n\n            sums = new HashMap<>();\n            for (int i = 0; i < n; i++)\n            {\n                long sum = 0;\n                for (int j = i; j < n; j++)\n                {\n                    sum += a[j];\n                    sums.computeIfAbsent(sum, k -> new ArrayList<>()).add(\n                                    new F1BlokiRavnoiSummiProstayaRedakciya.Block(i, j, sum));\n                }\n            }\n\n            for (Map.Entry<Long, List<F1BlokiRavnoiSummiProstayaRedakciya.Block>> e : sums.entrySet())\n            {\n                Collections.sort(e.getValue());\n            }\n\n            List<F1BlokiRavnoiSummiProstayaRedakciya.Block> res = Collections.emptyList();\n            for (Map.Entry<Long, List<F1BlokiRavnoiSummiProstayaRedakciya.Block>> e : sums.entrySet())\n            {\n                List<F1BlokiRavnoiSummiProstayaRedakciya.Block> blocks = e.getValue();\n                List<F1BlokiRavnoiSummiProstayaRedakciya.Block> updated = new ArrayList<>();\n\n                if (blocks.size() <= res.size())\n                    continue;\n\n                for (F1BlokiRavnoiSummiProstayaRedakciya.Block next : blocks)\n                {\n                    if (updated.size() == 0)\n                        updated.add(next);\n                    else\n                    {\n                        F1BlokiRavnoiSummiProstayaRedakciya.Block prev = updated.get(updated.size() - 1);\n                        if (next.l > prev.r)\n                            updated.add(next);\n                    }\n                }\n\n                if (updated.size() > res.size())\n                    res = updated;\n            }\n\n            StringBuilder resS = new StringBuilder();\n            resS.append(res.size()).append('\\n');\n            for (F1BlokiRavnoiSummiProstayaRedakciya.Block block : res)\n                resS.append(block.l + 1).append(' ').append(block.r + 1).append('\\n');\n\n            out.println(resS);\n        }\n\n        private long[] nla(int size)\n        {\n            return in.nextLongArray(size);\n        }\n\n        private int ni()\n        {\n            return in.nextInt();\n        }\n\n        static class Block implements Comparable<F1BlokiRavnoiSummiProstayaRedakciya.Block>\n        {\n            int l;\n            int r;\n            long sum;\n\n            public Block(int l, int r, long sum)\n            {\n                this.l = l;\n                this.r = r;\n                this.sum = sum;\n            }\n\n            public int compareTo(F1BlokiRavnoiSummiProstayaRedakciya.Block o)\n            {\n                int res = Integer.compare(r, o.r);\n                if (res == 0)\n                    res = Integer.compare(l, o.l);\n                return res;\n            }\n\n        }\n\n    }\n\n    static class InputReader\n    {\n        private final BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream in)\n        {\n            reader = new BufferedReader(new InputStreamReader(in));\n        }\n\n        public long[] nextLongArray(int size)\n        {\n            long[] array = new long[size];\n            for (int i = 0; i < size; ++i)\n            {\n                array[i] = nextLong();\n            }\n            return array;\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        public String next()\n        {\n            while (tokenizer == null || !tokenizer.hasMoreTokens())\n            {\n                tokenizer = new StringTokenizer(readLine());\n            }\n            return tokenizer.nextToken();\n        }\n\n        public String readLine()\n        {\n            String line;\n            try\n            {\n                line = reader.readLine();\n            }\n            catch (IOException e)\n            {\n                throw new RuntimeException(e);\n            }\n            return line;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.TreeMap;\n\npublic class Main extends PrintWriter {\n\n    static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n    // static Scanner s=new Scanner(System.in);\n    Main () { super(System.out); }\n    public static void main(String[] args) throws IOException{\n        Main  d1=new Main   ();d1.main();d1.flush();\n    }\n    void main() throws IOException {\n        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n        StringBuffer sb = new StringBuffer();\n        StringBuffer sb1 = new StringBuffer();\n        PrintWriter out = new PrintWriter(System.out);\n        int t=1;\n//        t=i(s()[0]);\n        while(t-->0) {\n            //dp[i]=a[i]+max(dp[j]) S.T. j<i and h[j]<h[i];\n            String[] s1 = s();\n            int n = i(s1[0]);\n             long[] a=new long[n];\n             arr(a,n);\n             HashMap<Long,Integer>[] dp=new HashMap[n];\n\n             long[] presum=new long[n];\n             for(int i=0;i<n;i++){\n                 if(i==0){\n                     presum[i]=a[i];\n                 }else{\n                     presum[i]=a[i]+presum[i-1];\n                 }\n             }HashMap<Long,TreeMap<Integer,Long> > tm=new HashMap<>();int ans=0;long maxsum=0;\n             for(int i=0;i<n;i++){\n                  dp[i]=new HashMap<>();\n                 for(int j=-1;j<i;j++){\n                     long sum=0;\n                     if(j==-1) sum=presum[i];else sum=presum[i]-presum[j];\n//                     if(sum==5&&i==5) System.out.println(tm.get(sum).floorKey(4));\n                     if(tm.containsKey(sum)&&tm.get(sum).floorKey(j)!=null){\n                         dp[i].put(sum,Math.max(dp[i].getOrDefault(sum,0),dp[tm.get(sum).floorKey(j)].getOrDefault(sum,0)+1));\n                        if(dp[i].get(sum)>ans){\n                            maxsum=sum;\n                        }\n                         ans=Math.max(ans,dp[i].get(sum));\n                     }else if(dp[i].containsKey(sum)==false){\n                         if(dp[i].getOrDefault(sum,0)<1) dp[i].put(sum,1);\n                         if(dp[i].get(sum)>ans){\n                             maxsum=sum;\n                         }\n                         ans=Math.max(ans,1);\n                     }\n                     long val=dp[i].getOrDefault(sum,0);\n//                     if(tm.containsKey(sum)&&tm.get(sum).floorKey(i-1)!=null){\n                         if(!tm.containsKey(sum)||tm.get(sum).floorKey(i-1)==null||dp[tm.get(sum).floorKey(i-1)].getOrDefault(sum,0)<val) {\n//                             val = Math.max(val, dp[tm.get(sum).floorKey(i - 1)].getOrDefault(sum, 0));\n                             TreeMap<Integer, Long> tt = new TreeMap<>();\n                             tt.put(i, val);\n                             tm.put(sum, tt);\n                         }\n//                     }\n                     }\n             }int cnt=0;int last=-1;\n             for(int i=0;i<n;i++){\n                 for(int j=i-1;j>=-1;j--){\n                     long sum=0;\n                     if(j==-1) sum=presum[i];\n                     else sum=presum[i]-presum[j];\n                     if(dp[i].getOrDefault(maxsum,0)>cnt&&maxsum==sum){\n                         sb.append(j+2+\" \"+(i+1)+\"\\n\");cnt++;\n                         break;\n                     }\n                 }\n             } System.out.println(ans);\n//            System.out.println(dp[5].get(5L)+\" \"+dp[4].get(5L));\n            System.out.println(sb);\n        }\n\n    }\n    //        System.out.println(sb);\n    long[] st;\n    void buildtree(int i,int s,int e,long[] a){\n        if(s==e){\n            st[i]=a[s];\n            return;\n        }\n        int mid=(s+e)/2;\n        buildtree(2*i,s,mid,a);\n        buildtree(2*i+1,mid+1,e,a);\n        st[i]=Math.min(st[2*i],st[2*(i)+1]);\n    }\n    long query(int i,int s,int e,int qs,int qe){\n        if(qs>e||qe<s) return Integer.MIN_VALUE;\n        if(s>=qs&&e<=qe) return st[i];\n        int mid=(s+e)/2;\n        long l=query(2*i,s,mid,qs,qe);\n        long r=query(2*i+1,mid+1,e,qs,qe);\n        return Math.max(l,r);\n    }\n    void pointupdate(int i,int s,int e,int qi,long [] a){\n        if(s==e){\n            st[i]=a[s];return;\n        }\n        int mid=(s+e)/2;\n        if(qi<=mid) pointupdate(2*i,s,mid,qi,a);\n        else pointupdate(2*(i)+1,mid+1,e,qi,a);\n        st[i]=Math.max(st[2*i],st[2*i+1]);\n    }\n    public void arr(long[] a,int n) throws IOException{\n        //        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n        String[] s2=s();\n        for(int i=0;i<n;i++){\n            a[i]=i(s2[i]);\n        }\n    }\n    public void sort(int[] a,int l,int h){\n        if(l==h) return;\n        int mid=(l+h)/2;\n\n        sort(a,l,mid);\n        sort(a,mid+1,h);\n        merge(a,l,(l+h)/2,h);\n    }\n    void merge(int arr[], int l, int m, int r)\n    {\n        int n1 = m - l + 1;\n        int n2 = r - m;\n        int L[] = new int[n1];\n        int R[] = new int[n2];\n        for (int i = 0; i < n1; ++i)\n            L[i] = arr[l + i];\n        for (int j = 0; j < n2; ++j)\n            R[j] = arr[m + 1 + j];\n        int i = 0, j = 0;\n        int k = l;\n        while (i < n1 && j < n2) {\n            if (L[i] <= R[j]) {\n                arr[k] = L[i];\n                i++;\n            }\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        while (j < n2) {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n\n\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    static String[] s() throws IOException {\n        return s.readLine().trim().split(\"\\\\s+\");\n    }\n\n    static int i(String ss) {\n        return Integer.parseInt(ss);\n    }\n    static long l(String ss) {\n        return Long.parseLong(ss);\n    }\n}\nclass Student {\n    long  a;int b;int c;\n    public Student(int a,int b) {\n        this.a=a;this.c=c;this.b=b;\n    }\n}\nclass Pair {\n    int  a,b,c;\n    public Pair(int  a,int b){\n        this.a=a;this.b=b;this.c=c;}\n}\nclass Sortbyroll implements Comparator<Student> {\n\n    public int compare(Student a, Student b){\n        if(a.b==b.b) return (int)b.a-(int)a.a;\n        return   a.b-b.b;}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/*\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 Round547;\n\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.Set;\n\n/**\n *\n * @author Hemant Dhanuka\n */\npublic class F1 {\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    \n    public static void main(String[] args) throws IOException {\n  //    Scanner s=new Scanner(System.in);\n     Reader s=new Reader();\n    int n=s.nextInt();\n        \n        int a[]=new int[n];\n        \n        for(int i=0;i<n;i++){\n            a[i]=s.nextInt();\n        }\n        \n        Map<Long,PriorityQueue<Node>> map=new HashMap();\n        \n        for(int i=0;i<n;i++){\n            long sum=0;\n            for(int j=i;j<n;j++){\n                sum=sum+a[j];\n                PriorityQueue<Node> pq=map.get(sum);\n                if(pq==null){\n                    pq=new PriorityQueue();\n                    map.put(sum, pq);\n                }\n                pq.add(new Node(i,j));\n            }\n            \n            \n        }\n        \n        \n        Set<Long> keys=map.keySet();\n        \n        Iterator<Long> itr=keys.iterator();\n        int max=0;\n        int solbackDp[]=null;\n        Node solA[]=new Node[0];\n        while(itr.hasNext()){\n           Long sum=itr.next();\n           PriorityQueue<Node> pq1=map.get(sum);\n           \n           \n           \n           \n           \n           \n           //Node rangelist[]=new  Node[pq1.size()+1];\n            ArrayList<Node> rangelist=new ArrayList<>();\n            rangelist.add(new Node(-1, -1));\n            //int count=1;\n            //rangelist[0]=new Node(-1,-1);\n             Node last=rangelist.get(0);\n            while(!pq1.isEmpty()){\n                Node n1=pq1.poll();\n                if(n1.l!=last.l){\n                    rangelist.add(n1);\n                    last=n1;\n                } \n                       \n           }\n           int backTrack[]=new int[rangelist.size()];\n           int dp[]=new int[rangelist.size()];\n           Arrays.fill(dp, -1);\n           int ans=fun(0,dp,rangelist,backTrack);\n           if(ans>max){\n               max=ans;\n               solA=rangelist.toArray(solA);\n               solbackDp=backTrack;\n           }\n        }\n        \n        System.out.println(max);\n        \n        \n        int pos=0;\n        while(solbackDp[pos]!=-1){\n            pos=solbackDp[pos];\n            System.out.println((solA[pos].l+1)+\" \"+(solA[pos].r+1));\n        }\n    }\n    \n    \n    static int fun(int pos, int[] dp, ArrayList<Node> rangeList, int[] bactTrack){\n        \n        if(pos==rangeList.size()-1){\n            bactTrack[pos]=-1;\n            return 0;\n          \n        }\n        \n        if(dp[pos]!=-1){\n            return dp[pos];\n        }\n        \n        int i=pos+1;\n        int maxAns=0;\n        int nextPos=-1;\n        for(;i<=rangeList.size()-1;i++){\n            \n            \n            if(rangeList.get(i).l>rangeList.get(pos).r){\n                int tempAns=1+fun(i, dp,rangeList, bactTrack);\n                if(tempAns>maxAns){\n                    maxAns=tempAns;\n                    nextPos=i;\n                }\n            }\n        }\n        \n        dp[pos]=maxAns;\n        bactTrack[pos]=nextPos;\n        return maxAns;\n        \n        \n        \n        \n    }\n    \n    static class Node implements Comparable<Node>{\n        int l;\n        int r;\n\n        public Node(int l, int r) {\n            this.l = l;\n            this.r = r;\n        }\n        \n        \n        \n       \n        @Override\n        public int compareTo(Node o2) {\n            if(this.l!=o2.l){\n                return this.l-o2.l;\n            } else{\n                return this.r-o2.r;\n            }\n        }\n        \n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Solution1{\n\n\tstatic class Node{\n\t\tint start,end;\n\t\tNode(int start, int end){\n\t\t\tthis.start=start;\n\t\t\tthis.end=end;\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn start+\" \"+end;\n\t\t}\n\t}\n\n\tpublic static void sameSumBlock(int a[],int n){\n\t\tHashMap<Long,ArrayList<Node>> map=new HashMap<>();\n\n\t\tlong sum;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tsum=0;\n\t\t\tfor(int j=i;j<n;j++){\n\t\t\t\tsum+=a[j];\n\t\t\t\tif(!map.containsKey(sum))\n\t\t\t\t\tmap.put(sum,new ArrayList<>());\n\t\t\t\tmap.get(sum).add( new Node(i+1, j+1) );\n\t\t\t}\n\t\t}\n\n\t\t//for(Map.Entry<Long,ArrayList<Node>> pair: map.entrySet())\n\t\t\t//System.out.println(pair.getKey()+\" \"+pair.getValue());\n\n\n\t\tint max=0;\tLinkedList<Node> list=new LinkedList<>();\n\t\tfor(Map.Entry<Long,ArrayList<Node>> pair: map.entrySet()){\n\n\t\t\tArrayList<Node> arr=pair.getValue();\n\t\t\tCollections.sort(arr, (Node x, Node y)->{\treturn x.end-y.end;\t});\n\n\t\t\tint count=0,end=0;\n\t\t\tLinkedList<Node> temp=new LinkedList<>();\n\t\t\tfor(Node item: arr){\n\t\t\t\tif(end<item.start){\n\t\t\t\t\tend=item.end;\n\t\t\t\t\tcount+=1;\n\t\t\t\t\ttemp.add(new Node(item.start, item.end));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(count>max){\n\t\t\t\tmax=count;\n\t\t\t\tlist=temp;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(max);\n\t\tfor(Node item: list)\n\t\t\tSystem.out.println(item.start+\" \"+item.end);\n\t}\n\n\tpublic static void main(String args[]){\n\t\tScanner in=new Scanner(System.in);\n\n\t\tint n=in.nextInt();\n\n\t\tint a[]=new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\ta[i]=in.nextInt();\n\n\t\tsameSumBlock(a,n);\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class F11141 {\n\tstatic class Solver {\n\n\t\tArrayList<int[]> ranges[];\n\t\tHashMap<Long, Integer> hm = new HashMap<>();\n\n\t\tint id(long s) {\n\t\t\tif (!hm.containsKey(s))\n\t\t\t\thm.put(s, hm.size());\n\t\t\treturn hm.get(s);\n\t\t}\n\t\t\n\t\t// max disjoint range set in ranges[r]\n\t\tint[] memo;\n\t\tint go(int r) {\n\t\t\tmemo[N] = 0;\n\t\t\tint last = N;\n\t\t\tfor(int[] a : ranges[r]) {\n\t\t\t\twhile(a[0] < last) {\n\t\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\t\tlast--;\n\t\t\t\t}\n\t\t\t\tmemo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));\n\t\t\t\tlast = a[0];\n\t\t\t}\n\t\t\twhile(0 < last) {\n\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\tlast--;\n\t\t\t}\n\t\t\treturn memo[0];\n\t\t}\n\n\t\tArrayDeque<int[]> ans = new ArrayDeque<>();\n\t\t\n\t\tvoid go2(int r) {\n\t\t\tmemo[N] = 0;\n\t\t\tint last = N;\n\t\t\tint minAt[] = new int[N], oo = 987654321;\n\t\t\tArrays.fill(minAt, oo);\n\t\t\tfor(int[] a : ranges[r]) {\n\t\t\t\tminAt[a[0]] = Math.min(minAt[a[0]], a[1] - a[0]);\n\t\t\t\twhile(a[0] < last) {\n\t\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\t\tlast--;\n\t\t\t\t}\n\t\t\t\tmemo[a[0]] = Math.max(memo[a[0]], Math.max(memo[a[0]], 1 + memo[a[1] + 1]));\n\t\t\t\tlast = a[0];\n\t\t\t}\n\t\t\twhile(0 < last) {\n\t\t\t\tmemo[last - 1] = memo[last];\n\t\t\t\tlast--;\n\t\t\t}\n\t\t\tint k = 0;\n\t\t\tfor(; k < N;) {\n\t\t\t\tif(minAt[k] == oo || memo[k] != 1 + memo[k + minAt[k] + 1]) k++;\n\t\t\t\telse {\n\t\t\t\t\tans.push(new int[] {k, k + minAt[k]});\n\t\t\t\t\tk += minAt[k] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tSolver() {\n\t\t\tranges = new ArrayList[2250001];\n\t\t\tfor (int i = 0; i < ranges.length; i++)\n\t\t\t\tranges[i] = new ArrayList<>();\n\t\t}\n\n\t\tint N, LID;\n\t\tlong[] a;\n\n\t\tvoid solve(Scanner s, PrintWriter out) {\n\t\t\tN = s.nextInt();\n\t\t\ta = new long[N + 1];\n\t\t\tfor (int i = 1; i <= N; i++)\n\t\t\t\ta[i] = s.nextLong() + a[i - 1];\n\t\t\tfor (int i = N; i >= 1; i--)\n\t\t\t\tfor (int j = i; j <= N; j++) {\n\t\t\t\t\tint x = id(a[j] - a[i - 1]);\n\t\t\t\t\tranges[x].add(new int[] { i - 1, j - 1 });\n\t\t\t\t}\n\t\t\t\n\t\t\tint best = 0, bid = -1;\n\t\t\tmemo = new int[N + 1];\n//\t\t\tArrays.sort(ranges, (a, b) -> b.size() - a.size());\n\t\t\tfor(int i = 0; i < ranges.length; i++, LID++) {\n\t\t\t\tif(ranges[i].size() <= best) continue;\n\t\t\t\tint ans = go(i);\n\t\t\t\tif(ans > best) {\n\t\t\t\t\tbest = ans;\n\t\t\t\t\tbid = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// backtrack on bid\n\t\t\tout.println(best);\n\t\t\tgo2(bid);\n\t\t\t\t\t\t\n\t\t\twhile(!ans.isEmpty()) {\n\t\t\t\tint[] c = ans.pop();\n\t\t\t\tout.println(++c[0] + \" \" + ++c[1]);\n\t\t\t}\n\t\t\t\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner s = new Scanner(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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskF2 solver = new TaskF2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF2 {\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\n            HashMap<Integer, ArrayList<Interval>> map = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                int sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    if (map.containsKey(sum) == false) {\n                        map.put(sum, new ArrayList<>());\n                    }\n                    ArrayList<Interval> arr = map.get(sum);\n                    if (arr.isEmpty() || arr.get(arr.size() - 1).r < i) {\n                        arr.add(new Interval(i, j));\n                    } else if (arr.get(arr.size() - 1).r >= j) {\n                        arr.set(arr.size() - 1, new Interval(i, j));\n                    }\n                }\n            }\n\n            ArrayList<Interval> best = new ArrayList<>();\n            for (ArrayList<Interval> arr : map.values()) {\n                if (best.size() < arr.size()) {\n                    best = arr;\n                }\n            }\n\n            out.println(best.size());\n            for (Interval i : best) {\n                out.println((i.l + 1) + \" \" + (i.r + 1));\n            }\n        }\n\n        class Interval {\n            int l;\n            int r;\n\n            Interval(int l, int r) {\n                this.l = l;\n                this.r = r;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Vector;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Stack;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskF2 solver = new TaskF2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF2 {\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\n            HashMap<Integer, Stack<Interval>> map = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                int sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    if (map.containsKey(sum) == false) {\n                        map.put(sum, new Stack<>());\n                    }\n                    Stack<Interval> stack = map.get(sum);\n                    if (stack.isEmpty() || stack.get(stack.size() - 1).r < i) {\n                        stack.push(new Interval(i, j));\n                    } else if (stack.get(stack.size() - 1).r >= j) {\n                        stack.pop();\n                        stack.push(new Interval(i, j));\n                    }\n                }\n            }\n\n            Stack<Interval> best = new Stack<>();\n            for (Stack<Interval> stack : map.values()) {\n                if (best.size() < stack.size()) {\n                    best = stack;\n                }\n            }\n\n            out.println(best.size());\n            for (Interval i : best) {\n                out.println((i.l + 1) + \" \" + (i.r + 1));\n            }\n        }\n\n        class Interval {\n            int l;\n            int r;\n\n            Interval(int l, int r) {\n                this.l = l;\n                this.r = r;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tInputReader in = new InputReader(inputStream);\n\t\t\n//\t\tfor(int i=4;i<=4;i++) {\n//\t\t\tInputStream uinputStream = new FileInputStream(\"shortcut.in\");\n//\t\t\tString f = i+\".in\";\n//\t\t\tInputStream uinputStream = new FileInputStream(f);\n//\t\t\tInputReader in = new InputReader(uinputStream);\n//\t\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"shortcut.out\")));\n\t\t\tTask t = new Task();\n\t\t\tt.solve(in, out);\n\t\t\tout.close();\t\t\t\n//\t\t}\n\t}\t\n\t\n\tstatic class Task {\n\n\t\tpublic void solve(InputReader in, PrintWriter out) throws IOException {\t\t\t\n\t\t\tint n = in.nextInt();\n\t\t\tint arr[] = in.readIntArray(n);\n\t\t\tint v[][] = new int[n][n];\n\t\t\tint c=0;\n\t\t\tHashMap<Integer,Integer> mp = new HashMap<Integer,Integer>();\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tfor(int j=i;j<n;j++) {\n\t\t\t\t\tv[i][j] = arr[j];\n\t\t\t\t\tif(j>i) v[i][j] += v[i][j-1]; \n\t\t\t\t\tif(!mp.containsKey(v[i][j])) mp.put(v[i][j], c++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tArrayList<seg>[] all = new ArrayList[c];\n\t\t\tfor(int i=0;i<c;i++) all[i] = new ArrayList<seg>();\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tfor(int j=i;j<n;j++) {\n\t\t\t\t\tint idx = mp.get(v[i][j]);\n\t\t\t\t\tall[idx].add(new seg(i,j,v[i][j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i=0;i<c;i++) Collections.sort(all[i]);\n\t\t\tint max = Integer.MIN_VALUE;\n\t\t\tint val = -1;\n\t\t\tfor(int i=0;i<c;i++) {\n\t\t\t\tif(all[i].size()==0) continue;\n\t\t\t\tint num=1;\n\t\t\t\tint p=0;int q=p+1;\n\t\t\t\twhile(q<all[i].size()) {\n\t\t\t\t\tif(all[i].get(q).s>all[i].get(p).e) {\n\t\t\t\t\t\tp=q;\n\t\t\t\t\t\tnum++;\n\t\t\t\t\t}\n\t\t\t\t\tq++;\n\t\t\t\t}\n\t\t\t\tif(num>max) {\n\t\t\t\t\tmax=num;\n\t\t\t\t\tval = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(max);\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tint p=0;int q=p+1;\t\n\t\t\tsb.append(all[val].get(0).toString());\n\t\t\twhile(q<all[val].size()) {\n\t\t\t\tif(all[val].get(q).s>all[val].get(p).e) {\n\t\t\t\t\tsb.append(all[val].get(q).toString());\n\t\t\t\t\tp=q;\n\t\t\t\t}\n\t\t\t\tq++;\n\t\t\t}\n\t\t\tout.println(sb.toString());\n\t\t}\n\t\tpublic class seg implements Comparable<seg>{\n\t\t\tint s; int e; int val;\n\t\t\tpublic seg(int a, int b, int c) {\n\t\t\t\ts=a;e=b;val=c;\n\t\t\t}\n\t\t\t@Override\n\t\t\tpublic int compareTo(seg t) {\n\t\t\t\tif(this.e==t.e) return this.s-t.s;\t\t\t\t\n\t\t\t\treturn this.e-t.e;\n\t\t\t}\n\t\t\tpublic String toString() {\n\t\t\t\treturn (s+1)+\" \"+(e+1)+\"\\n\";\n\t\t\t}\n\t\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    }\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<n) {\n\t\t\t\tarr[p]+=v;\n\t\t\t\tp+=p&(-p);\n\t\t\t}\n\t\t}\n\t}\n\tstatic class DSU{\n\t\tint[] arr;\n\t\tint[] sz;\n\t\tpublic DSU(int n) {\n\t\t\tarr = new int[n];\n\t\t\tsz = new int[n];\n\t\t\tfor(int i=0;i<n;i++) arr[i] = i;\n\t\t\tArrays.fill(sz, 1);\n\t\t}\n\t\tpublic int find(int a) {\n\t\t\tif(arr[a]!=a) arr[a] = find(arr[a]);\n\t\t\treturn arr[a];\n\t\t}\n\t\tpublic void union(int a, int b) {\n\t\t\tint x = find(a);\n\t\t\tint y = find(b);\n\t\t\tif(x==y) return;\n\t\t\tarr[x] = y;\n\t\t\tsz[y] += sz[x];\n\t\t}\n\t\tpublic int size(int x) {\n\t\t\treturn sz[find(x)];\n\t\t}\n\t}\t\n\tstatic class MinHeap<Key> implements Iterable<Key> {\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<Key> 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<Key> 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<n&&less(j+1,j)) j++;\n\t\t\t\tif(less(k,j)) break;\n\t\t\t\texch(k,j);\n\t\t\t\tk=j;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic boolean less(int i, int j){\n\t        if (comparator == null) {\n\t            return ((Comparable<Key>) 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<Key> 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedInputStream;\nimport java.util.HashMap;\nimport java.util.ArrayList;\nimport java.io.FilterInputStream;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Comparator;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Jenish\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        F2SameSumBlocksHard solver = new F2SameSumBlocksHard();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2SameSumBlocksHard {\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            long arr[] = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = in.scanLong();\n            }\n\n\n            HashMap<Long, ArrayList<pair>> hm = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                long sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += arr[j];\n                    if (hm.containsKey(sum)) {\n                        hm.get(sum).add(new pair(i + 1, j + 1));\n                    } else {\n                        hm.put(sum, new ArrayList<>());\n                        hm.get(sum).add(new pair(i + 1, j + 1));\n                    }\n                }\n            }\n\n\n            long maxi_sum = -1;\n            long sum = 0;\n            for (Map.Entry<Long, ArrayList<pair>> k : hm.entrySet()) {\n                Collections.sort(k.getValue(), new Comparator<pair>() {\n\n                    public int compare(pair o1, pair o2) {\n                        return o1.r - o2.r;\n                    }\n                });\n\n                int count = k.getValue().size() > 0 ? 1 : 0;\n                int index = 0;\n                for (int i = 1; i < k.getValue().size(); i++) {\n                    if (k.getValue().get(i).l > k.getValue().get(index).r) {\n                        count++;\n                        index = i;\n                    }\n                }\n\n\n                if (count > maxi_sum) {\n                    maxi_sum = count;\n                    sum = k.getKey();\n                }\n            }\n\n            out.println(maxi_sum);\n            ArrayList<pair> tt = hm.get(sum);\n            Collections.sort(tt, new Comparator<pair>() {\n\n                public int compare(pair o1, pair o2) {\n                    return o1.r - o2.r;\n                }\n            });\n\n\n            out.println(tt.size() > 0 ? (tt.get(0).l + \" \" + tt.get(0).r) : (\" \"));\n            int index = 0;\n            for (int i = 1; i < tt.size(); i++) {\n                if (tt.get(i).l > tt.get(index).r) {\n                    out.println(tt.get(i).l + \" \" + tt.get(i).r);\n                    index = i;\n                }\n            }\n\n\n        }\n\n        class pair {\n            int l;\n            int r;\n\n            public pair(int l, int r) {\n                this.l = l;\n                this.r = r;\n            }\n\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int INDEX;\n        private BufferedInputStream in;\n        private int TOTAL;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (INDEX >= TOTAL) {\n                INDEX = 0;\n                try {\n                    TOTAL = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (TOTAL <= 0) return -1;\n            }\n            return buf[INDEX++];\n        }\n\n        public int scanInt() {\n            int 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        public long scanLong() {\n            long I = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    I *= 10;\n                    I += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * I;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.awt.*;\n\n// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................\n//JUst keep faith in ur strengths .................................................. \n\n\n// ASCII = 48 + i ;// 2^28 = 268,435,456  > 2* 10^8 // log 10 base 2 = 3.3219 \n// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1  x >=4 \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\n// Rectangle r = new Rectangle(int x , int y,int widht,int height) \n//Creates a rect. with bottom left cordinates as (x, y) and top right as ((x+width),(y+height))\n\n//BY DEFAULT Priority Queue is MIN in nature in java\n//to use as max , just push with negative sign and change sign after removal \n\n// We can make a sieve of max size 1e7 .(no time or space issue) \n// In 1e7 starting nos we have about 66*1e4 prime nos \n\n public class Main\n{\n     \n    // static int[] arr = new int[100002] ; \n    // static int[] dp = new int[100002] ;  \n    \n     static PrintWriter out;\n    \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n\n////////////////////////////////////////////////////////////////////////////////////\n public static int countDigit(long n) \n    { \n        return (int)Math.floor(Math.log10(n) + 1); \n    } \n\n///////////////////////////////////////////////////////////////////////////////////////// \n \n public static int sumOfDigits(long n)\n {\n  \n  if( n< 0)return -1 ;\n  \n  int sum = 0;\n  \n  while( n > 0)\n  {\n      sum = sum + (int)( n %10) ;\n      \n      n /= 10 ;\n  }\n     \n  return sum ;  \n \n \n \n }\n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long arraySum(int[] arr , int start , int end)\n{\n    long ans = 0 ;\n    \n    for(int i = start ; i <= end  ; i++)ans += arr[i] ;\n    \n    return ans  ;\n}\n\n/////////////////////////////////////////////////////////////////////////////////\n\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\nstatic long factorial(long a)\n{\n    if(a== 0L || a==1L)return 1L ;\n    \n    return a*factorial(a-1L) ;\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n\npublic static int[][] rotate(int[][] input){\n\nint n =input.length;\nint m = input[0].length ;\nint[][] output = new int [m][n];\n\nfor (int i=0; i<n; i++)\n\tfor (int j=0;j<m; j++)\n\t\toutput [j][n-1-i] = input[i][j];\nreturn output;\n}\n///////////////////////////////////////////////////////////////////////////////////////////////////////\n\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\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\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/gc)*b ;\n}\n\n\npublic static long lcm(long a , long b )\n{\n\nlong gc = gcd(a,b);\n\nreturn (a/gc)*b;\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\nstatic boolean isPrime(int n)\n{\n      if(n==1)\n      {\n            return false  ;\n      }\n      \n      boolean ans =  true  ;\n      \n      for(int i = 2; 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\n///////////////////////////////////////////////////////////////////////////\n\nstatic int sieve =  1000000 ;\n\n \nstatic boolean[] prime =  new boolean[sieve + 1] ;\n\npublic static void sieveOfEratosthenes() \n    { \n        // FALSE == prime\n        \n        // TRUE ==  COMPOSITE\n        \n        // FALSE== 1\n       \n        \n        // time complexity = 0(NlogLogN)== o(N)\n        \n        // gives prime nos bw 1 to N\n        \n        for(int i = 4; i<= sieve ; i++)\n        {\n            prime[i] = true  ;\n            i++ ;\n        }\n        \n        for(int p = 3; p*p <= sieve; p++) \n        { \n           \n            if(prime[p] == false) \n            { \n                \n                for(int i = p*p; i <= sieve; i += p) \n                    prime[i] = true; \n            } \n            \n            p++ ;\n        } \n          \n       \n       \n    \n    } \n \n///////////////////////////////////////////////////////////////////////////////////\n\n\npublic static void sortD(int[] arr , int s  , int e)\n{\n      sort(arr ,s , e) ;\n      \n      int i =s ; int j = e  ;\n      \n      while( i < j)\n      {\n            int temp = arr[i] ;\n            arr[i] =arr[j] ;\n            arr[j] = temp ;\n            i++ ; j-- ;\n      }\n      \n      \n      \n      return ;\n}\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long countSubarraysSumToK(long[] arr ,long sum )\n    {\n      HashMap<Long,Long> map = new HashMap<>() ;\n       \n      int n = arr.length ;\n       \n      long prefixsum = 0 ;\n       \n      long count = 0L ;\n      for(int i  = 0; i < n ; i++)\n      {\n          prefixsum  = prefixsum +  arr[i] ;\n           \n          if(sum == prefixsum)count = count+1 ;\n           \n          if(map.containsKey(prefixsum -sum))\n          {\n              count = count + map.get(prefixsum -sum) ;\n          }\n          \n          \n          if(map.containsKey(prefixsum ))\n          {\n              map.put(prefixsum , map.get(prefixsum) +1 );\n          }\n          \n          else{\n              map.put(prefixsum , 1L );\n          }\n           \n           \n      }\n        \n        \n        \n      return count  ;  \n        \n    }\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\n\n// KMP ALGORITHM : TIME COMPL:O(N+M) \n// FINDS THE OCCURENCES OF PATTERN AS A  SUBSTRING IN STRING\n//RETURN THE ARRAYLIST OF INDEXES \n// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING\n\n\npublic static ArrayList<Integer> kmpAlgorithm(String str , String pat)\n     {\n        ArrayList<Integer> list =new ArrayList<>();\n        \n        int n = str.length() ;\n        int m = pat.length() ;\n        \n        String q = pat + \"#\" + str ;\n        \n        int[] lps  =new int[n+m+1] ;\n        \n         longestPefixSuffix(lps, q,(n+m+1)) ;\n         \n         \n         for(int i =m+1 ; i < (n+m+1) ; i++ )\n         {\n             if(lps[i] == m)\n             {\n                 list.add(i-2*m) ;\n             }\n         }\n        \n        return list ; \n         \n        \n    }\n    \n\npublic static void longestPefixSuffix(int[] lps ,String str , int n)\n    {\n        lps[0] =  0 ;\n        \n        for(int i = 1  ; i<= n-1; i++)\n        {\n          int l = lps[i-1] ;\n           \n          while( l > 0 && str.charAt(i) != str.charAt(l))\n          {\n              l = lps[l-1] ;\n          }\n           \n          if(str.charAt(i) == str.charAt(l))\n          {\n              l++ ;\n          }\n            \n           \n          lps[i] = l ; \n        }\n        \n    }\n    \n     \n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n\n    // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1 \n    // or n and the no  will be coprime in nature\n    //time : O(n*(log(logn)))\n    \n    public static void eulerTotientFunction(int[] arr ,int n )\n    {\n      \n      for(int i = 1; i <= n  ;i++)arr[i] =i  ;\n      \n      \n      for(int i= 2 ; i<= n ;i++)\n      {\n          if(arr[i] == i)\n          {\n              arr[i] =i-1 ;\n              \n              for(int j =2*i ; j<= n  ; j+= i )\n              {\n                  arr[j] = (arr[j]*(i-1))/i ;\n              }\n              \n          }\n      }\n        \n      return  ;  \n        \n    }\n\t\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long nCr(int n,int k)\n{\n    long ans=1L;\n    k=k>n-k?n-k:k;\n    int j=1;\n    for(;j<=k;j++,n--)\n    {\n        if(n%j==0)\n        {\n            ans*=n/j;\n        }else\n        if(ans%j==0)\n        {\n            ans=ans/j*n;\n        }else\n        {\n            ans=(ans*n)/j;\n        }\n    }\n    return ans;\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static ArrayList<Integer> allFactors(int n)\n{   \n      ArrayList<Integer> list = new ArrayList<>() ;\n      \n    for(int i = 1; i*i <= n ;i++)\n    {\n          if( n % i == 0)\n          {\n              if(i*i == n)\n              {\n                    list.add(i) ;\n              }\n              else{\n                    list.add(i) ;\n                    list.add(n/i) ;\n                    \n              }\n          }\n    }\n      \n     return list ; \n      \n      \n}\n\n\npublic static ArrayList<Long> allFactors(long n)\n{   \n      ArrayList<Long> list = new ArrayList<>() ;\n      \n    for(long i = 1L; i*i <= n ;i++)\n    {\n          if( n % i == 0)\n          {\n              if(i*i == n)\n              {\n                    list.add(i) ;\n              }\n              else{\n                    list.add(i) ;\n                    list.add(n/i) ;\n                    \n              }\n          }\n    }\n      \n     return list ; \n      \n      \n}\n////////////////////////////////////////////////////////////////////////////////////////////////////\n\n  static final int MAXN = 1000001; \n       \n    \n    static int spf[] = new int[MAXN]; \n   \n    static void sieve() \n    { \n        spf[1] = 1; \n        for (int i=2; i<MAXN; i++) \n       \n           \n            spf[i] = i; \n       \n       \n        for (int i=4; i<MAXN; i+=2) \n            spf[i] = 2; \n       \n        for (int i=3; i*i<MAXN; i++) \n        { \n           \n            if (spf[i] == i) \n            { \n               \n                for (int j=i*i; j<MAXN; j+=i) \n       \n                    if (spf[j]==j) \n                        spf[j] = i; \n            } \n        } \n    } \n       \n\n    static ArrayList<Integer> getPrimeFactorization(int x) \n    { \n        ArrayList<Integer> ret = new ArrayList<Integer>(); \n        while (x != 1) \n        { \n            ret.add(spf[x]); \n            x = x / spf[x]; \n        } \n        return ret; \n    } \n       \n //////////////////////////////////////////////////////////////////////////////////////////////////\n //////////////////////////////////////////////////////////////////////////////////////////////////\n   \npublic static void merge(int arr[], int l, int m, int r)\n    {\n        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n \n        /* Create temp arrays */\n        int L[] = new int[n1];\n        int R[] = new int[n2];\n \n       //Copy data to temp arrays\n        for (int i=0; i<n1; ++i)\n            L[i] = arr[l + i];\n        for (int j=0; j<n2; ++j)\n            R[j] = arr[m + 1+ j];\n \n \n        /* Merge the temp arrays */\n \n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n \n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2)\n        {\n            if (L[i] <= R[j])\n            {\n                arr[k] = L[i];\n                i++;\n            }\n            else\n            {\n                arr[k] = R[j];\n                j++;\n            }\n            k++;\n        }\n \n        /* Copy remaining elements of L[] if any */\n        while (i < n1)\n        {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n \n        /* Copy remaining elements of R[] if any */\n        while (j < n2)\n        {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n \n    // Main function that sorts arr[l..r] using\n    // merge()\n  public static void sort(int arr[], int l, int r)\n    {\n        if (l < r)\n        {\n            // Find the middle point\n            int m = (l+r)/2;\n \n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr , m+1, r);\n \n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n\npublic static void sort(long arr[], int l, int r)\n    {\n        if (l < r)\n        {\n            // Find the middle point\n            int m = (l+r)/2;\n \n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr , m+1, r);\n \n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n\n\npublic static void merge(long arr[], int l, int m, int r)\n    {\n        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n \n        /* Create temp arrays */\n        long L[] = new long[n1];\n        long R[] = new long[n2];\n \n        //Copy data to temp arrays\n        for (int i=0; i<n1; ++i)\n            L[i] = arr[l + i];\n        for (int j=0; j<n2; ++j)\n            R[j] = arr[m + 1+ j];\n \n \n        /* Merge the temp arrays */\n \n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n \n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2)\n        {\n            if (L[i] <= R[j])\n            {\n                arr[k] = L[i];\n                i++;\n            }\n            else\n            {\n                arr[k] = R[j];\n                j++;\n            }\n            k++;\n        }\n \n        /* Copy remaining elements of L[] if any */\n        while (i < n1)\n        {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n \n        /* Copy remaining elements of R[] if any */\n        while (j < n2)\n        {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n \n\n /////////////////////////////////////////////////////////////////////////////////////////\n \n\tpublic static long knapsack(int[] weight,long value[],int maxWeight){\n\n        \n        int n=  value.length ;\n        \n\t\n\t//dp[i] stores the profit with KnapSack capacity \"i\" \n  long []dp = new long[maxWeight+1]; \n      \n    //initially profit with 0 to W KnapSack capacity is 0 \n    Arrays.fill(dp, 0); \n  \n    // iterate through all items \n    for(int i=0; i < n; i++)  \n      \n        //traverse dp array from right to left \n        for(int j = maxWeight; j >= weight[i]; j--) \n            dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]); \n              \n    /*above line finds out maximum of dp[j](excluding ith element value) \n    and val[i] + dp[j-wt[i]] (including ith element value and the \n    profit with \"KnapSack capacity - ith element weight\") */\n    return dp[maxWeight]; \n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n\n\n// to return max sum of any subarray in given array\npublic static long kadanesAlgorithm(long[] arr)\n{\n    \n    if(arr.length == 0)return  0 ;\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     if(arr.length == 0)return  0 ;\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\n\n\n//////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////\n\n//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING\n\n\n// JUST CALL generatePermutation( str,  start,  end) start :inclusive ,end : exclusive \n\n//Function for swapping the characters at position I with character at position j  \n    public static String swapString(String a, int i, int j) {  \n        char[] b =a.toCharArray();  \n        char ch;  \n        ch = b[i];  \n        b[i] = b[j];  \n        b[j] = ch;  \n        return String.valueOf(b);  \n    }  \n      \n//Function for generating different permutations of the string  \n    public static void generatePermutation(String str, int start, int end)  \n    {  \n        //Prints the permutations  \n        if (start == end-1)  \n            System.out.println(str);  \n        else  \n        {  \n            for (int i = start; i < end; i++)  \n            {  \n                //Swapping the string by fixing a character  \n                str = swapString(str,start,i);  \n                //Recursively calling function generatePermutation() for rest of the characters   \n                generatePermutation(str,start+1,end);  \n                //Backtracking and swapping the characters again.  \n                str = swapString(str,start,i);  \n            }  \n        }  \n    }  \n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long factMod(long n, long mod) {\n    if (n <= 1) return 1;\n    long ans = 1;\n    for (int i = 1; i <= n; i++) {\n      ans = (ans * i) % mod;\n    }\n    return ans;\n  }\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long power(int a  ,int b)\n    {\n        //time comp : o(logn) \n        \n        long x = (long)(a) ;\n         long n = (long)(b) ;\n        \n        if(n==0)return 1 ;\n        if(n==1)return x;\n        \n        long ans =1L  ;\n       \n      while(n>0)\n      {\n          if(n % 2 ==1)\n          {\n              ans = ans *x ;\n          }\n           \n          n = n/2L ;\n           \n          x =  x*x ;\n           \n      }\n       \n      return ans ;\n    }\n    \n    public static long power(long a  ,long b)\n    {\n        //time comp : o(logn) \n        \n        long x = (a) ;\n         long n = (b) ;\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 = n/2L ;\n           \n          x =  x*x ;\n           \n      }\n       \n      return ans ;\n    }\n\n    \n    \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    \n    a = a % p ;\n    \n    if(a == 0)return 0L ;\n    \n    \n    long res = 1L;\n    while(x > 0) {\n        if( x % 2 != 0) {\n            res = (res * a) % p;\n        }\n        a = (a * a) % p;\n        x =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 p.\n    //(assuming p is prime).\n    return modPow(a, p-2, p);\n}\n \n static long[] factorial =  new long[1000001] ;\n \n static void modfac(long mod)\n {\n     factorial[0]=1L ; factorial[1]=1L ;\n     \n     for(int i = 2; i<= 1000000 ;i++)\n     {\n         factorial[i] = factorial[i-1] *(long)(i) ;\n          factorial[i] = factorial[i] % mod ;\n     }\n    \n     \n }\n \n\n \n \n \nstatic long modBinomial(long n, long r, long p) {\n// calculates C(n,r) mod p (assuming p is prime).\n \n  if(n < r) return 0L ; \n \n    long num = factorial[(int)(n)] ;\n    \n    long den = (factorial[(int)(r)]*factorial[(int)(n-r)]) %  p ;\n    \n    \n    long ans  = num*(modInverse(den,p)) ;\n    \n    ans = ans % p ;\n    \n    return ans  ;\n \n    \n}\n \n \n static void update(int val , long[] bit ,int n)\n {\n     for( ; val <= n ; val += (val &(-val)) )\n     {\n         bit[val]++ ;\n     }\n    \n     \n }\n \n \n static long query(int val , long[] bit , int n)\n {\n     long ans = 0L; \n     for( ; val >=1 ; val-=(val&(-val))  )ans += bit[val];\n     \n     return ans ;\n }\n\n\n\nstatic int countSetBits(long n) \n    { \n        int count = 0; \n        while (n > 0) { \n            n = (n) & (n - 1L); \n            count++; \n        } \n        return count; \n    } \n\n\nstatic int abs(int x)\n{\n    if(x < 0)x = -1*x ;\n    \n    return x ;\n}\n\n\nstatic long abs(long x)\n{\n    if(x < 0)x = -1L*x ;\n    \n    return x ;\n\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////\nstatic void p(int val)\n{\n    out.print(val) ;\n}\n\nstatic void p()\n{\n    out.print(\" \") ;\n}\n\nstatic void pln(int val)\n{\n    out.println(val) ;\n}\n\nstatic void pln()\n{\n    out.println() ;\n}\n\n\nstatic void p(long val)\n{\n    out.print(val) ;\n}\n\n\n\nstatic void pln(long val)\n{\n    out.println(val) ;\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////\n\n // calculate total no of nos greater than or equal to key in  sorted array arr\n \nstatic  int bs(int[] arr, int s ,int e  ,int key)\n{\n    if( s> e)return 0 ;\n    \n     int mid = (s+e)/2 ;\n        \n        if(arr[mid] <key)\n        {\n            return bs(arr ,mid+1,e , key) ;\n            \n        }\n        \n        \n        else{\n            \n             return bs(arr ,s ,mid-1, key)  + e-mid+1;\n            \n            \n        }\n}\n \n// static ArrayList<Integer>[] adj ;\n// static int mod= 1000000007 ;\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//sieve() ;\n//ArrayList<Integer> arr[] = new ArrayList[n] ;\nArrayList<Integer> list = new ArrayList<>() ;\nArrayList<Long> lista = new ArrayList<>() ;\nArrayList<Long> listb = new ArrayList<>() ;\n// ArrayList<Integer> lista = new ArrayList<>() ;\n// ArrayList<Integer> listb = new ArrayList<>() ;\n//ArrayList<String> lists = new ArrayList<>() ;\n\nHashMap<Integer,ArrayList<Pair>> map = new HashMap<>() ;\n//HashMap<Long,Long> map = new HashMap<>() ;\nHashMap<Integer,Integer> mapx  = new HashMap<>() ;\nHashMap<Integer,Integer> mapy  = new HashMap<>() ;\n//HashMap<String,Integer> maps = new HashMap<>() ;\n//HashMap<Integer,Boolean> mapb = new HashMap<>() ;\n//HashMap<Point,Integer> point = new HashMap<>() ; \n\n Set<Integer> set = new HashSet<>() ;\n Set<Integer> setx = new HashSet<>() ;\n Set<Integer> sety = new HashSet<>() ;\n\nStringBuilder sb =new StringBuilder(\"\") ;\n\n//Collections.sort(list);\n\n//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;\n//else map.put(arr[i],1) ;\n\n// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;\n// else map.put(temp,1) ;\n\n//int bit  =Integer.bitCount(n);\n// gives total no of set bits in n;\n\n// Arrays.sort(arr, new Comparator<Pair>() {\n// \t\t\t@Override\n// \t\t\tpublic int compare(Pair a, Pair b) {\n// \t\t\t\tif (a.first != b.first) {\n// \t\t\t\t\treturn a.first - b.first; // for increasing order of first\n// \t\t\t\t}\n// \t\t\t\treturn a.second - b.second ; //if first is same then sort on second basis\n// \t\t\t}\n// \t\t});\n\n\nint testcase = 1;\n //testcase = scn.nextInt() ;\nfor(int testcases =1  ; testcases <= testcase ;testcases++)\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 //adj = new ArrayList[n] ;\n\n// for(int i = 0; i< n; i++)\n// {\n//     adj[i] = new ArrayList<Integer>();\n// }\n\n// long n = scn.nextLong() ;\n//String s = scn.next() ;\n\nint n= scn.nextInt() ;\nint[] arr= new int[n] ;\n\nfor(int i=0; i < n;i++)\n{\n    arr[i]= scn.nextInt();\n}\n\nfor(int r= 0 ; r < n ;r++)\n{\n    int sum = 0 ;\n    for(int l =r ;l>= 0 ;l--)\n    {\n       sum = sum + arr[l] ;\n       \n       if(map.containsKey(sum))\n       {\n           map.get(sum).add(new Pair(l,r)) ;\n       }\n       else{\n           \n           map.put(sum,new ArrayList<Pair>());\n            map.get(sum).add(new Pair(l,r)) ;\n       }\n    }\n}\n\n\n ArrayList<Pair> ans = null ;\n \n int bestcount = 0 ;\n\nfor(int x : map.keySet())\n{\n    \n    ArrayList<Pair> curr = map.get(x) ;\n    ArrayList<Pair> now = new ArrayList<Pair>() ;\n    \n    int r=-1  ;\n    \n    int count = 0 ;\n    \n    for(Pair seg : curr)\n    {\n        \n        \n      if(seg.first > r)\n      {\n          count++ ;\n          now.add(seg) ;\n          r= seg.second  ;\n      }\n        \n        \n    }\n    \n    \n    if(count > bestcount)\n    {\n        ans = now ;\n        bestcount = count  ;\n    }\n    \n    \n}\n\n\npln(bestcount) ;\n\nif(bestcount >0)\n{\nfor(Pair x :  ans)\n{\n    out.println((x.first+1) +\" \" +( x.second+1)) ;\n}\n}\n\n\n\n\n\n\n\n\n\n//out.println(ans) ;\n//out.println(ans+\" \"+in) ;\n\n//out.println(\"Case #\" + testcases + \": \"  + ans ) ;\n//out.println(\"@\") ;\nset.clear() ;\nsb.delete(0 , sb.length()) ;\nlist.clear() ;lista.clear() ;listb.clear() ;\nmap.clear() ;\nmapx.clear() ;\nmapy.clear() ;\nsetx.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  \nint second  ;\n  \n  \n \n   public Pair(int l , int r)\n   {\n       first = l ;second = r ;\n   }\n      \n@Override\n\tpublic String toString() {\n\t\n\tString ans = \"\" ;\n\tans  += this.first ;\n\tans += \" \";\n\tans += this.second ;\n\t\n\treturn ans  ;\n\t}\n\n\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.awt.Point;\n\npublic class CF_1141F2 {\n    public static void main(String args[]) throws Exception {\n        BufferedScanner in = new BufferedScanner(new InputStreamReader(System.in));\n        PrintStream out = new PrintStream(new BufferedOutputStream(System.out));\n\n        int n = in.nextInt();\n        int[] arr = in.nextN(n);\n\n        HashMap<Integer, ArrayList<Point>> lp = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            int curr = 0;\n            for (int j = i; j >= 0; j--) {\n                curr += arr[j];\n                if (!lp.containsKey(curr)) lp.put(curr, new ArrayList<>());\n\n                lp.get(curr).add(new Point(j, i));\n            }\n        }\n\n        ArrayList<Point> retPs = new ArrayList<>();\n        for (ArrayList<Point> ps : lp.values()) {\n            Collections.sort(ps, (a, b) -> a.y - b.y);\n\n            ArrayList<Point> currPs = new ArrayList<>();\n            for (int i = 0; i < ps.size(); ) {\n                Point curr = ps.get(i);\n                currPs.add(curr);\n\n                while (i < ps.size() && ps.get(i).x <= curr.y) i++;\n            }\n            if(currPs.size() > retPs.size()) retPs = currPs;\n        }\n        out.println(retPs.size());\n        for (Point p : retPs) out.println((p.x + 1) + \" \" + (p.y + 1));\n\n\n        out.close();\n        in.close();\n    }\n\n    static class BufferedScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        BufferedScanner(Reader in) throws IOException {\n            this.in = new BufferedReader(in);\n            st = new StringTokenizer(this.in.readLine());\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        int[] nextN(int n) throws IOException {\n            int[] ret = new int[n];\n            for (int i = 0; i < n; i++) ret[i] = this.nextInt();\n            return ret;\n        }\n\n        long[] nextNL(int n) throws IOException {\n            long[] ret = new long[n];\n            for (int i = 0; i < n; i++) ret[i] = this.nextLong();\n            return ret;\n        }\n\n        String next() throws IOException {\n            if (!st.hasMoreElements()) st = new StringTokenizer(in.readLine());\n\n            return st.nextToken();\n        }\n\n        void close() throws IOException {\n            in.close();\n        }\n\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.compare;\nimport static java.util.Comparator.comparingInt;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Objects;\nimport java.util.stream.Collectors;\n\npublic class SameSumBlocks {\n\n    public static void main(String[] args) {\n        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n        String[] numbersAsString = input.lines()\n                                        .skip(1)\n                                        .findFirst()\n                                        .get()\n                                        .split(\" \");\n        int[] numbers = Arrays.stream(numbersAsString).mapToInt(Integer::parseInt).toArray();\n        List<PairOfInt> sameSumBlocks = findSameSumBlocks(numbers);\n        System.out.println(sameSumBlocks.size());\n        sameSumBlocks.forEach(System.out::println);\n    }\n\n    static List<PairOfInt> findSameSumBlocks(int[] numbers) {\n\n        List<List<PairOfInt>> potentials = buildPotentialsSum(numbers);\n\n        List<List<PairOfInt>> sortedPairList = potentials.stream()\n                                                         .filter(p -> p.size() > 0)\n                                                         .sorted((l1, l2) -> compare(l2.size(), l1.size()))\n                                                         .collect(Collectors.toList());\n\n        List<PairOfInt> max = new ArrayList<>();\n        max.add(PairOfInt.of(1, 1));\n        for (int i = 0; i < sortedPairList.size(); i++) {\n            List<PairOfInt> result = sortedPairList.get(i);\n            result.sort(comparingInt(p -> p.b));\n            List<PairOfInt> maxDisjoint = maxDisjointPair(result);\n            if (maxDisjoint.size() > max.size()) {\n                max = maxDisjoint;\n                if (i + 1 < sortedPairList.size() && maxDisjoint.size() >= sortedPairList.get(i + 1).size()) {\n                    return maxDisjoint;\n                }\n            }\n        }\n\n        return max;\n    }\n\n    public static List<PairOfInt> maxDisjointPair(List<PairOfInt> result) {\n        if (result.size() == 0)\n            return result;\n\n        boolean over = false;\n        while (!over) {\n            int i;\n            for (i = 1; i < result.size(); i++) {\n                if (result.get(i).a <= result.get(i - 1).b) {\n                    result.remove(result.get(i));\n                    break;\n                }\n            }\n            if (i == result.size()) {\n                over = true;\n            }\n        }\n        return result;\n    }\n\n    private static List<List<PairOfInt>> buildPotentialsSum(int[] numbers) {\n        Map<Integer, List<PairOfInt>> result = new HashMap<>();\n        for (int i = 0; i < numbers.length; i++) {\n            int blockSum = 0;\n            for (int j = i; j < numbers.length; j++) {\n                blockSum += numbers[j];\n                final int tmpi = i, tmpj = j;\n                result.compute(blockSum, (k, l) -> {\n                    if (l == null) {\n                        l = new ArrayList<>();\n                    }\n                    l.add(PairOfInt.of(tmpi + 1, tmpj + 1));\n                    return l;\n                });\n                if(blockSum == 0) {\n                    break;\n                }\n            }\n        }\n        return new ArrayList<>(result.values());\n    }\n\n    public static class PairOfInt {\n        final int a, b;\n\n        public static PairOfInt of(int a, int b) {\n            return new PairOfInt(a, b);\n        }\n\n        private PairOfInt(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public String toString() {\n            return a + \" \" + b;\n        }\n\n        @Override\n        public boolean equals(Object o) {\n            if (this == o) return true;\n            if (o == null || getClass() != o.getClass()) return false;\n            PairOfInt pairOfInt = (PairOfInt) o;\n            return a == pairOfInt.a &&\n                    b == pairOfInt.b;\n        }\n\n        @Override\n        public int hashCode() {\n            return Objects.hash(a, b);\n        }\n\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Map;\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 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        F2SameSumBlocksHard solver = new F2SameSumBlocksHard();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2SameSumBlocksHard {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n\n            long[] a = in.nextLongArray(n);\n\n            long[] p = in.calculatePrefixSum(a);\n\n            Map<Long, Integer> map = new HashMap<>();\n\n            for (int i = 0; i < n; i++) {\n                long sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    map.merge(sum, 1, (x, y) -> x + y);\n                }\n            }\n\n            List<sum> sums = new ArrayList<>();\n            for (long sum : map.keySet()) {\n                sums.add(new sum(sum, map.get(sum)));\n            }\n\n            sums.sort((x, y) -> y.c - x.c);\n\n            int ans = -1;\n\n            int[] fca = null;\n            long mxsum = -1;\n            for (int i = 0; i < sums.size(); i++) {\n                sum cs = sums.get(i);\n                long sum = cs.sum;\n                long c = cs.c;\n\n                if (c < ans) {\n                    continue;\n                }\n\n                Map<Long, Integer> lm = new HashMap<>();\n\n                int[] ca = new int[n];\n                lm.put(0l, -1);\n                for (int j = 0; j < n; j++) {\n                    long val = p[j];\n\n                    if (j > 0) {\n                        ca[j] = ca[j - 1];\n                    }\n                    long req = val - sum;\n\n                    if (lm.containsKey(req)) {\n                        int li = lm.get(req);\n                        if (li == -1)\n                            ca[j] = Math.max(1, ca[j]);\n                        else\n                            ca[j] = Math.max(1 + ca[li], ca[j]);\n                    }\n\n                    lm.put(val, j);\n                }\n\n                if (ca[n - 1] > ans) {\n                    ans = ca[n - 1];\n                    mxsum = sum;\n                    fca = ca;\n                }\n            }\n\n            List<Integer> al = new ArrayList<>();\n\n            long sum = 0;\n            for (int i = n - 1; i >= 0; i--) {\n                if (i > 0 && fca[i] != fca[i - 1]) {\n                    sum = 0;\n                    al.add(i + 1);\n                    do {\n                        sum += a[i];\n                        i--;\n                    } while (i >= 0 && sum != mxsum);\n                    i++;\n                    al.add(i + 1);\n                } else if (i == 0) {\n                    if (a[i] == mxsum) {\n                        al.add(i + 1);\n                        al.add(i + 1);\n                    }\n                }\n            }\n\n            out.println(al.size() / 2);\n\n            for (int i = al.size() - 1; i >= 0; i -= 2) {\n                out.println(al.get(i) + \" \" + al.get(i - 1));\n            }\n        }\n\n        class sum {\n            long sum;\n            int c;\n\n            public sum(long sum, int c) {\n                this.sum = sum;\n                this.c = c;\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 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 long[] nextLongArray(int n) {\n            long[] array = new long[n];\n            for (int i = 0; i < n; ++i) array[i] = nextLong();\n            return array;\n        }\n\n        public long[] calculatePrefixSum(long[] a) {\n            int n = a.length;\n\n            long[] prefixSum = new long[n];\n\n            prefixSum[0] = a[0];\n\n            for (int i = 1; i < n; i++) {\n                prefixSum[i] = prefixSum[i - 1] + a[i];\n            }\n\n            return prefixSum;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void print(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n        }\n\n        public void println(Object... objects) {\n            print(objects);\n            writer.println();\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void println(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\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        TaskF solver = new TaskF();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) { a[i] = in.nextInt(); }\n\n            Map<Integer, List<Range>> rgs = new HashMap<Integer, List<Range>>();\n\n            for (int i = 0; i < n; i++) {\n                int s = 0;\n                for (int j = i; j < n; j++) {\n                    s += a[j];\n\n                    if (rgs.get(s) == null) {  rgs.put(s, new ArrayList<Range>()); }\n\n                    rgs.get(s).add(new Range(i, j));\n                }\n            }\n\n            Iterator it = rgs.entrySet().iterator();\n            List<Range> ans = new ArrayList<Range>();\n\n            while (it.hasNext()) {\n                Map.Entry pair = (Map.Entry) it.next();\n                int sum = (int) pair.getKey();\n                List<Range> ranges = rgs.get(sum);\n\n                List<Range> cand = new ArrayList<Range>();\n\n                for (Range r : ranges) {\n                    if (cand.size() == 0) {\n                        cand.add(r);\n                        continue;\n                    }\n\n                    if (cand.get(cand.size() - 1).j < r.i) {\n                        cand.add(r);\n                    } else {\n                        if (cand.get(cand.size() - 1).j > r.j) {\n                            cand.remove(cand.size() - 1);\n                            cand.add(r);\n                        }\n                    }\n                }\n\n                if (cand.size() > ans.size()) {\n                    ans = cand;\n                }\n            }\n\n            out.println(ans.size());\n            for (Range r : ans) {\n                out.println((r.i + 1) + \" \" + (r.j + 1));\n            }\n        }\n\n        public class Range implements Comparable {\n            public int i;\n            public int j;\n\n            public Range(int i, int j) {\n                this.i = i;\n                this.j = j;\n            }\n\n            public int compareTo(Object o) {\n                Range t = (Range) o;\n                if (this.i == t.i) {\n                    if (this.j < t.j) return 1;\n                    else return 0;\n                }\n                if (this.i < t.i) return 1;\n                return 0;\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", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n\n\n    public static void main(String[] args) {\n\n        class Pair {\n            int start;\n            int end;\n\n            public Pair(int start, int end) {\n                this.start = start;\n                this.end = end;\n            }\n        }\n\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[] array = new int[n];\n        for (int i=0; i<n; i++) array[i] = sc.nextInt();\n\n\n        int maxLen = 0;\n        int key = -1;\n        HashMap<Integer, List<Pair>> ans = new HashMap<>();\n        for (int i=0; i<n; i++){\n            int currSum = 0;\n            for (int j=i; j>=0; j--){\n                currSum = currSum + array[j];\n                if (!ans.containsKey(currSum)){\n                    ans.put(currSum, new ArrayList<>());\n                }\n                List<Pair> pairs = ans.get(currSum);\n                if (pairs.size() == 0 || pairs.get(pairs.size()-1).end <= j){\n                    pairs.add(new Pair(j+1, i+1));\n                }\n                if (pairs.size() > maxLen){\n                    maxLen = pairs.size();\n                    key = currSum;\n                }\n            }\n\n        }\n\n        System.out.println(maxLen);\n        for (Pair pair : ans.get(key)){\n            System.out.println(pair.start + \" \" + pair.end);\n        }\n\n    }\n\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class Q6 {\n\n    public static void main(String[] args) {\n        InputReader s = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int t = 1;\n//        t = s.nextInt();\n        nexttest:\n        while (t-- > 0) {\n            int n = s.nextInt();\n            int a[] = s.nextIntArray(n);\n\n            HashMap<Integer, List<Pair>> sets = new HashMap<>();\n            int pre[] = new int[n + 1];\n            for (int i = 1; i <= n; i++) {\n                pre[i] = a[i - 1] + pre[i - 1];\n            }\n\n            for (int i = 1; i <= n; i++) {\n                for (int j = i; j <= n; j++) {\n                    final Integer key = pre[j] - pre[i - 1];\n                    if (!sets.containsKey(key)) {\n                        sets.put(key, new ArrayList<>());\n                    }\n\n                    sets.get(key).add(new Pair(i, j));\n                }\n            }\n//            System.out.println(sets);\n            int ans = 0;\n            List<Pair> answer = new ArrayList<>();\n            int[] ansNextPos = new int[1];\n            boolean[] ansTaken = new boolean[1];\n            for (List<Pair> intervals : sets.values()) {\n\n                Collections.sort(intervals);\n                int[] nextPos = new int[intervals.size()];\n                boolean[] taken = new boolean[intervals.size()];\n\n                int[] dp = new int[intervals.size()];\n                dp[intervals.size() - 1] = 1;\n                taken[intervals.size() - 1] = true;\n                nextPos[intervals.size() - 1] = -1;\n\n                for (int i = intervals.size() - 2; i >= 0; i--) {\n                    dp[i] = dp[i + 1];\n                    taken[i] = false;\n                    nextPos[i] = i + 1;\n\n                    int ll = i + 1;\n                    int rr = intervals.size();\n\n                    while (ll < rr) {\n                        int mid = ll + rr;\n                        mid /= 2;\n                        if (intervals.get(mid).x > intervals.get(i).y) {\n                            rr = mid;\n                        } else {\n                            ll = mid + 1;\n                        }\n                    }\n                    if (ll < intervals.size()) {\n                        if (dp[i] < 1 + dp[ll]) {\n                            dp[i] = Math.max(dp[i], 1 + dp[ll]);\n                            taken[i] = true;\n                            nextPos[i] = ll;\n                        }\n                    }\n                }\n\n                if (dp[0] > ans) {\n                    ans = dp[0];\n                    answer = intervals;\n                    ansNextPos = nextPos;\n                    ansTaken = taken;\n                }\n            }\n\n\n            out.println(ans);\n            int cur = 0;\n            while (cur != -1) {\n                if (ansTaken[cur]) {\n                    out.println(answer.get(cur));\n                }\n                cur = ansNextPos[cur];\n            }\n        }\n\n        out.close();\n    }\n\n    static class Pair implements Comparable<Pair> {\n        int x;\n        int y;\n\n        @Override\n        public String toString() {\n            return x + \" \" + y;\n        }\n\n        public Pair(final int x, final int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        @Override\n        public int compareTo(final Pair o) {\n            return this.x - o.x;\n        }\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 InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int snext() {\n            if (snumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= snumChars) {\n                curChar = 0;\n                try {\n                    snumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (snumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = snext();\n            while (isSpaceChar(c)) {\n                c = snext();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = snext();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = snext();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public 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                }\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            }\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            }\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private boolean isEndOfLine(int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n}\n\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(System.out);\n\n\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int();\n            int A[]=new int[n];\n            for(int i=0;i<n;i++){\n                A[i]=Int();\n            }\n\n            Solution sol=new Solution();\n            sol.solution(out,A);\n        }\n        out.flush();\n\n    }\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    public void solution(PrintWriter out,int A[]){\n        Map<Integer,List<int[]>>f=new HashMap<>();\n        List<int[]>res=new ArrayList<>();\n        for(int i=0;i<A.length;i++){\n            int sum=0;\n            for(int j=i;j<A.length;j++){\n                sum+=A[j];\n                if(!f.containsKey(sum))f.put(sum,new ArrayList<>());\n                List<int[]>list=f.get(sum);\n                list.add(new int[]{i,j});\n            }\n        }\n\n\n        for(Integer key:f.keySet()){\n            List<int[]>list=f.get(key);\n            Collections.sort(list,(a,b)->{\n                return a[1]-b[1];\n            });\n            int pre[]=new int[list.size()];\n            Arrays.fill(pre,-1);\n\n\n            int dp[][]=new int[list.size()][2];\n            dp[0][0]=1;\n            dp[0][1]=0;\n\n            for(int i=1;i<list.size();i++){\n                int pair[]=list.get(i);\n                int l=0,r=i-1;\n                int pos=-1;\n                while(l<=r){\n                    int mid=l+(r-l)/2;\n                    if(list.get(mid)[1]<pair[0]){\n                        pos=mid;\n                        l=mid+1;\n                    }\n                    else{\n                        r=mid-1;\n                    }\n                }\n\n                if(pos!=-1){\n                    int mx=1+dp[pos][0];\n                    if(mx>=dp[i-1][0]){\n                        dp[i][0]=mx;\n                        dp[i][1]=i;\n                        pre[i]=dp[pos][1];\n                    }\n                    else{\n                        dp[i][0]=dp[i-1][0];\n                        dp[i][1]=dp[i-1][1];\n                    }\n                }\n                else{\n                    dp[i][0]=dp[i-1][0];\n                    dp[i][1]=dp[i-1][1];\n                }\n            }\n\n            int n=list.size();\n            if(dp[n-1][0]>res.size()){\n                res=new ArrayList<>();\n                int j=dp[n-1][1];\n                while(j!=-1){\n                    res.add(list.get(j));\n                    j=pre[j];\n                }\n            }\n\n            \n        }\n\n\n\n\n\n        out.println(res.size());\n        for(int p[]:res){\n            out.println((p[0]+1)+\" \"+(p[1]+1));\n        }\n    }\n\n\n\n\n}\n\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import javax.print.attribute.standard.PrinterMessageFromOperator;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        new Main().run();}\n\n//    int[] h,ne,to,wt;\n//    int ct = 0;\n//    int n;\n//    void graph(int n,int m){\n//        h = new int[n];\n//        Arrays.fill(h,-1);\n////        sccno = new int[n];\n////        dfn = new int[n];\n////        low = new int[n];\n////        iscut = new boolean[n];\n//        ne = new int[2*m];\n//        to = new int[2*m];\n//        wt = new int[2*m];\n//        ct = 0;\n//    }\n//    void add(int u,int v,int w){\n//        to[ct] = v;\n//        ne[ct] = h[u];\n//        wt[ct] = w;\n//        h[u] = ct++;\n//    }\n//\n//    int color[],dfn[],low[],stack[] = new int[1000000],cnt[];\n//    int sccno[];\n//    boolean iscut[];\n//    int time = 0,top = 0;\n//    int scc_cnt = 0;\n//\n//    // \u6709\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n//    void tarjan(int u) {\n//        low[u] = dfn[u]= ++time;\n//        stack[top++] = u;\n//        for(int i=h[u];i!=-1;i=ne[i]) {\n//            int v = to[i];\n//            if(dfn[v]==0) {\n//                tarjan(v);\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//        if(dfn[u]==low[u]) {\n//            sccno[u] = ++scc_cnt;\n//            while(stack[top-1]!=u) {\n//                sccno[stack[top-1]] = scc_cnt;\n//                --top;\n//            }\n//            --top;\n//        }\n//    }\n//\n//    //\u7f29\u70b9, topology sort\n//    int[] h1,to1,ne1;\n//    int ct1 = 0;\n//    void point(){\n//        for(int i=0;i<n;i++) {\n//            if(dfn[i]==0) tarjan(i);//\u6709\u53ef\u80fd\u56fe\u4e0d\u8fde\u901a\uff0c\u6240\u4ee5\u8981\u5faa\u73af\u5224\u65ad\u3002\n//        }\n//        // \u5165\u5ea6\n//        int du[] = new int[scc_cnt+1];\n//        h1 = new int[scc_cnt+1];\n//        Arrays.fill(h1, -1);\n//        to1 = new int[scc_cnt*scc_cnt];\n//        ne1 = new int[scc_cnt*scc_cnt];\n//        // scc_cnt \u4e2a\u70b9\n//\n//        for(int i=1;i<=n;i++) {\n//            for(int j=h[i]; j!=-1; j=ne[j]) {\n//                int y = to[j];\n//                if(sccno[i] != sccno[y]) {\n//                    // add(sccno[i],sccno[y]);  // \u5efa\u65b0\u56fe\n//                    to1[ct1] = sccno[y];\n//                    ne1[ct1] = h[sccno[i]];\n//                    h[sccno[i]] = ct1++;\n//                    du[sccno[y]]++; //\u5b58\u5165\u5ea6\n//                }\n//            }\n//        }\n//\n//        int q[] = new int[100000];\n//        int end = 0;\n//        int st = 0;\n//        for(int i=1;i<=scc_cnt;++i){\n//            if(du[i]==0){\n//                q[end++] = i;\n//            }\n//        }\n//\n//        int dp[] = new int[scc_cnt+1];\n//        while(st<end){\n//            int cur = q[st++];\n//            for(int i=h1[cur];i!=-1;i=ne1[i]){\n//                int y = to[i];\n//                // dp[y] += dp[cur];\n//                if(--du[y]==0){\n//                    q[end++] = y;\n//                }\n//            }\n//        }\n//    }\n//\n//\n//\n//\n//    int fa[];\n//    int faw[];\n//\n//    int dep = -1;\n//    int pt = 0;\n//    void go(int rt,int f,int dd){\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = f;p++;\n//        while(p>0) {\n//            int cur = stk[p - 1];\n//            int fp = fk[p - 1];\n//            int ll = lk[p - 1];\n//            p--;\n//\n//\n//            if (ll > dep) {\n//                dep = ll;\n//                pt = cur;\n//            }\n//            for (int i = h[cur]; i != -1; i = ne[i]) {\n//                int v = to[i];\n//                if (fp == v) continue;\n//\n//                stk[p] = v;\n//                lk[p] = ll + wt[i];\n//                fk[p] = cur;\n//                p++;\n//            }\n//        }\n//    }\n//    int pt1 = -1;\n//    void go1(int rt,int f,int dd){\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = f;p++;\n//        while(p>0) {\n//            int cur = stk[p - 1];\n//            int fp = fk[p - 1];\n//            int ll = lk[p - 1];\n//            p--;\n//\n//\n//            if (ll > dep) {\n//                dep = ll;\n//                pt1 = cur;\n//            }\n//\n//            fa[cur] = fp;\n//            for (int i = h[cur]; i != -1; i = ne[i]) {\n//                int v = to[i];\n//                if (v == fp) continue;\n//                faw[v] = wt[i];\n//                stk[p] = v;\n//                lk[p] = ll + wt[i];\n//                fk[p] = cur;\n//                p++;\n//            }\n//        }\n//    }\n//\n//    int r = 0;\n//    int stk[] = new int[301];\n//    int fk[] = new int[301];\n//    int lk[] = new int[301];\n//    void ddfs(int rt,int t1,int t2,int t3,int l){\n//\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = t3;p++;\n//        while(p>0){\n//            int cur = stk[p-1];\n//            int fp = fk[p-1];\n//            int ll = lk[p-1];\n//            p--;\n//            r = Math.max(r,ll);\n//            for(int i=h[cur];i!=-1;i=ne[i]){\n//                int v = to[i];\n//                if(v==t1||v==t2||v==fp) continue;\n//                stk[p] = v;\n//                lk[p] = ll+wt[i];\n//                fk[p] = cur;p++;\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    static long mod_pow(long k,long n,long p){\n        long res = 1L;\n        long temp = k;\n        while(n!=0L){\n            if((n&1L)==1L){\n                res = (res*temp)%p;\n            }\n            temp = (temp*temp)%p;\n            n = n>>1L;\n        }\n        return res%p;\n    }\n    int ct = 0;\n    int f[]  =new int[200001];\n    int b[]  =new int[200001];\n    int str[]  =new int[200001];\n\n    void go(int rt,List<Integer> g[]){\n        str[ct] = rt;\n        f[rt] = ct;\n        for(int cd:g[rt]){\n            ct++;\n            go(cd,g);\n        }\n        b[rt] = ct;\n    }\n    int add =0;\n\n    void go(int rt,int sd,int k,List<Integer> g[],int n){\n        if(add>n) {\n            return;\n        }\n\n        Queue<Integer> q =new LinkedList<>();\n        q.offer(rt);\n        for(int i=1;i<=sd;++i){\n            int sz =q.size();\n            if(sz==0) break;\n            int f = (i==1?2:1);\n            while(sz-->0){\n                int cur = q.poll();\n                for(int j=0;j<k-f;++j){\n                    q.offer(add);\n                    g[cur].add(add);add++;\n                    if(add==n+1){\n                        return;\n                    }\n                }\n            }\n        }\n\n\n    }\n\n\n\n    void solve() {\n\n        int n = ni();\n        long s[] = new long[n+1];\n        for(int i=0;i<n;++i){\n            s[i+1] = s[i]  + ni();\n        }\n\n        Map<Long,List<int[]>> mp = new HashMap<>();\n        for(int i=0;i<n;++i) {\n            for (int j = i; j>=0; --j) {\n                long v = s[i+1]-s[j];\n                if(!mp.containsKey(v)){\n                    mp.put(v, new ArrayList<>());\n                }\n                mp.get(v).add(new int[]{j,i});\n            }\n        }\n        int all = 0;long vv = -1;\n        for(long v:mp.keySet()){\n            List<int[]> r = mp.get(v);\n            int sz = r.size();int c = 0;\n            int ri = -2000000000;\n            for(int j=0;j<sz;++j){\n                if(r.get(j)[0]>ri){\n                    ri = r.get(j)[1];c++;\n                }\n            }\n            if(c>all){\n                all = c;\n                vv = v;\n            }\n        }\n        println(all);\n        List<int[]> r = mp.get(vv);\n        int sz = r.size();int c = 0;\n        int ri = -2000000000;\n        for(int j=0;j<sz;++j){\n            if(r.get(j)[0]>ri){\n                ri = r.get(j)[1];println((1+r.get(j)[0])+\" \"+(1+r.get(j)[1]));\n            }\n        }\n\n\n\n\n\n\n\n        //N , M , K , a , b , c , d . \u5176\u4e2dN , M\u662f\u77e9\u9635\u7684\u884c\u5217\u6570\uff1bK \u662f\u4e0a\u9501\u7684\u623f\u95f4\u6570\u76ee\uff0c(a, b)\u662f\u8d77\u59cb\u4f4d\u7f6e\uff0c(c, d)\u662f\u51fa\u53e3\u4f4d\u7f6e\n\n\n//        int n = ni();\n//        int m = ni();\n//        int k = ni();\n//        int a = ni();\n//        int b = ni();\n//        int c = ni();\n//        int d = ni();\n//\n//\n//        char cc[][] = nm(n,m);\n//        char keys[][] = new char[n][m];\n//\n//        char ky = 'a';\n//        for(int i=0;i<k;++i){\n//            int x = ni();\n//            int y = ni();\n//            keys[x][y] = ky;\n//            ky++;\n//        }\n//        int f1[] = {a,b,0};\n//\n//        int dd[][] = {{0,1},{0,-1},{1,0},{-1,0}};\n//\n//        Queue<int[]> q =  new LinkedList<>();\n//        q.offer(f1);\n//        int ts = 1;\n//\n//        boolean vis[][][] = new boolean[n][m][33];\n//\n//        while(q.size()>0){\n//            int sz = q.size();\n//            while(sz-->0) {\n//                int cur[] = q.poll();\n//                vis[cur[0]][cur[1]][cur[2]] = true;\n//\n//                int x = cur[0];\n//                int y = cur[1];\n//\n//                for (int u[] : dd) {\n//                       int lx = x +  u[0];\n//                       int ly = y +  u[1];\n//                       if (lx >= 0 && ly >= 0 && lx < n && ly < m && (cc[lx][ly] != '#')&&!vis[lx][ly][cur[2]]){\n//                            char ck =cc[lx][ly];\n//                            if(ck=='.'){\n//                                if(lx==c&&ly==d){\n//                                    println(ts); return;\n//                                }\n//                                if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {\n//                                    int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));\n//                                    q.offer(new int[]{lx, ly, cao});\n//                                    vis[lx][ly][cao] = true;\n//                                }else {\n//\n//                                    q.offer(new int[]{lx, ly, cur[2]});\n//                                }\n//\n//                            }else if(ck>='A'&&ck<='Z'){\n//                                int g = 1<<(ck-'A');\n//                                if((g&cur[2])>0){\n//                                    if(lx==c&&ly==d){\n//                                        println(ts); return;\n//                                    }\n//                                    if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {\n//\n//                                        int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));\n//                                        q.offer(new int[]{lx, ly, cao});\n//                                        vis[lx][ly][cao] = true;;\n//                                    }else {\n//\n//                                        q.offer(new int[]{lx, ly, cur[2]});\n//                                    }\n//                                }\n//                            }\n//                       }\n//                }\n//\n//                }\n//            ts++;\n//        }\n//        println(-1);\n\n\n\n\n//        int n = ni();\n//\n//        HashSet<String> st = new HashSet<>();\n//        HashMap<String,Integer> mp = new HashMap<>();\n//\n//\n//        for(int i=0;i<n;++i){\n//            String s  = ns();\n//            int id= 1;\n//            if(mp.containsKey(s)){\n//                int u = mp.get(s);\n//                id = u;\n//\n//            }\n//\n//            if(st.contains(s)) {\n//\n//                while (true) {\n//                    String ts = s + id;\n//                    if (!st.contains(ts)) {\n//                        s = ts;\n//                        break;\n//                    }\n//                    id++;\n//                }\n//                mp.put(s,id+1);\n//            }else{\n//                mp.put(s,1);\n//            }\n//            println(s);\n//            st.add(s);\n//\n//        }\n\n//        int t = ni();\n//\n//        for(int i=0;i<t;++i){\n//            int n = ni();\n//            long w[] = nal(n);\n//\n//            Map<Long,Long> mp = new HashMap<>();\n//            PriorityQueue<long[]> q =new PriorityQueue<>((xx,xy)->{return Long.compare(xx[0],xy[0]);});\n//\n//            for(int j=0;j<n;++j){\n//                q.offer(new long[]{w[j],0});\n//                mp.put(w[j],mp.getOrDefault(w[j],0L)+1L);\n//            }\n//\n//            while(q.size()>=2){\n//                long f[] = q.poll();\n//                long y1 = f[1];\n//                if(y1==0){\n//                    y1 = mp.get(f[0]);\n//                    if(y1==1){\n//                        mp.remove(f[0]);\n//                    }else{\n//                        mp.put(f[0],y1-1);\n//                    }\n//                }\n//                long g[] = q.poll();\n//                long y2 = g[1];\n//                if(y2==0){\n//                    y2 = mp.get(g[0]);\n//                    if(y2==1){\n//                        mp.remove(g[0]);\n//                    }else{\n//                        mp.put(g[0],y2-1);\n//                    }\n//                }\n//                q.offer(new long[]{f[0]+g[0],2L*y1*y2});\n//\n//            }\n//            long r[] = q.poll();\n//            println(r[1]);\n//\n//\n//\n//\n//        }\n        //  int o= 9*8*7*6;\n        //  println(o);\n\n\n//       int t = ni();\n//       for(int i=0;i<t;++i){\n//           long a = nl();\n//           int k  = ni();\n//           if(k==1){\n//               println(a);\n//               continue;\n//           }\n//\n//           int f = (int)(a%10L);\n//           int s = 1;\n//           int j = 0;\n//           for(;j<30;j+=2){\n//               int u = f-j;\n//               if(u<0){\n//                   u = 10+u;\n//               }\n//               s = u*s;\n//               s = s%10;\n//               if(s==k){\n//                   break;\n//               }\n//           }\n//\n//           if(s==k) {\n//               println(a - j - 2);\n//           }else{\n//               println(-1);\n//           }\n//\n//\n//\n//\n//       }\n\n//     int m = ni();\n//     h = new int[n];\n//     to = new int[2*(n-1)];\n//     ne = new int[2*(n-1)];\n//     wt = new int[2*(n-1)];\n//\n//     for(int i=0;i<n-1;++i){\n//         int u = ni()-1;\n//         int v = ni()-1;\n//\n//     }\n        //  long a[] = nal(n);\n\n\n//        int n = ni();\n//        int k = ni();\n//        t1 = new long[200002];\n//\n//        int p[][] = new int[n][3];\n//\n//        for(int i=0;i<n;++i){\n//            p[i][0]  = ni();\n//            p[i][1]  = ni();\n//            p[i][2]  = i+1;\n//        }\n//        Arrays.sort(p, new Comparator<int[]>() {\n//            @Override\n//            public int compare(int[] x, int[] y) {\n//                if(x[1]!=y[1]){\n//                    return Integer.compare(x[1],y[1]);\n//                }\n//                return Integer.compare(y[0], x[0]);\n//            }\n//        });\n//\n//        for(int i=0;i<n;++i){\n//            int ck = p[i][0];\n//\n//        }\n\n\n\n\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 []h,to,ne,wt;\n\n    long t1[];\n    //    long t2[];\n    void update(long[] t,int i,long v){\n        for(;i<t.length;i+=(i&-i)){\n            t[i] += v;\n        }\n    }\n    long get(long[] t,int i){\n        long s = 0;\n        for(;i>0;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<<i)< t.length && s + t[p+(1<<i)] < v){\n                v -= t[p+(1<<i)];\n                p |= 1<<i;\n            }\n        }\n        return p+1;\n    }\n\n\n\n\n\n\n\n\n\n    static class S{\n        int l = 0;\n        int r = 0 ;\n        long le = 0;\n        long ri = 0;\n        long tot = 0;\n        long all = 0;\n\n        public S(int l,int r) {\n            this.l = l;\n            this.r = r;\n        }\n    }\n\n    static S a[];\n    static int[] o;\n\n    static void init(int[] f){\n        o = f;\n        int len = o.length;\n        a = new S[len*4];\n        build(1,0,len-1);\n    }\n\n    static void build(int num,int l,int r){\n        S cur = new S(l,r);\n        if(l==r){\n            a[num] = cur;\n            return;\n        }else{\n            int m = (l+r)>>1;\n            int le = num<<1;\n            int ri = le|1;\n            build(le, l,m);\n            build(ri, m+1,r);\n            a[num] = cur;\n            pushup(num, le, ri);\n        }\n    }\n\n\n\n    //    static int query(int num,int l,int r){\n//\n//        if(a[num].l>=l&&a[num].r<=r){\n//            return a[num].tot;\n//        }else{\n//            int m = (a[num].l+a[num].r)>>1;\n//            int le = num<<1;\n//            int ri = le|1;\n//            pushdown(num, le, ri);\n//            int ma = 1;\n//            int mi = 100000001;\n//            if(l<=m) {\n//                int r1 = query(le, l, r);\n//                ma = ma*r1;\n//\n//            }\n//            if(r>m){\n//                int r2 = query(ri, l, r);\n//                ma = ma*r2;\n//            }\n//            return ma;\n//        }\n//    }\n    static long dd = 10007;\n    static void update(int num,int l,long v){\n        if(a[num].l==a[num].r){\n            a[num].le = v%dd;\n            a[num].ri = v%dd;\n            a[num].all = v%dd;\n            a[num].tot = v%dd;\n        }else{\n            int m = (a[num].l+a[num].r)>>1;\n            int le = num<<1;\n            int ri = le|1;\n            pushdown(num, le, ri);\n            if(l<=m){\n                update(le,l,v);\n            }\n            if(l>m){\n                update(ri,l,v);\n            }\n            pushup(num,le,ri);\n        }\n    }\n\n    static void pushup(int num,int le,int ri){\n        a[num].all = (a[le].all*a[ri].all)%dd;\n        a[num].le = (a[le].le + a[le].all*a[ri].le)%dd;\n        a[num].ri = (a[ri].ri + a[ri].all*a[le].ri)%dd;\n        a[num].tot = (a[le].tot + a[ri].tot + a[le].ri*a[ri].le)%dd;\n\n\n        //a[num].res[1] = Math.min(a[le].res[1],a[ri].res[1]);\n    }\n    static void pushdown(int num,int le,int ri){\n\n    }\n\n\n    int gcd(int a,int b){ return b==0?a: gcd(b,a%b);}\n    InputStream is;PrintWriter out;\n    void run() throws Exception {is = System.in;out = new PrintWriter(System.out);solve();out.flush();}\n    private byte[] inbuf = new byte[2];\n    public int lenbuf = 0, ptrbuf = 0;\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    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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class MyClass {\n    static class Pair implements Comparable<Pair>{\n        int x,y;\n        Pair(int x,int y){\n            this.x=x; this.y=y;\n        }\n        public int compareTo(Pair p){\n            return Integer.compare(this.y,p.y);\n        }\n    }\n    public static void main(String args[]) {\n      Scanner in =new Scanner(System.in);\n      HashMap<Long,ArrayList<Pair>> hm=new HashMap<Long,ArrayList<Pair>>();\n      int n=in.nextInt();\n      int a[]=new int[n];\n      long sum[]=new long[n];\n      long s=0;\n      for(int i=0;i<n;i++){  a[i]=in.nextInt(); s+=a[i]; sum[i]=s; }\n      for(int i=0;i<n;i++){\n          for(int j=i;j<n;j++){\n              long x=sum[j]-sum[i]+a[i];\n              ArrayList<Pair> temp=new ArrayList<Pair>();\n              if(hm.containsKey(x)) { temp=hm.get(x); }\n              temp.add(new Pair(i+1,j+1));\n              hm.put(x,temp);\n          }\n      }\n      ArrayList<Pair> ans=new ArrayList<Pair>();\n      for(Map.Entry em:hm.entrySet()){\n          ArrayList<Pair> array=hm.get(em.getKey());\n          Collections.sort(array);\n          int prev=0;\n          ArrayList<Pair> temp=new ArrayList<Pair>();\n          for(int i=0;i<array.size();i++){\n              if(array.get(i).x>prev){ temp.add(new Pair(array.get(i).x,array.get(i).y)); prev=array.get(i).y; }\n          }\n        //  System.out.println(temp.size());\n          if(temp.size()>ans.size()){\n              ans=(ArrayList<Pair>)temp.clone();\n          }\n      }\n      long g=-5;\n      System.out.println(ans.size()); \n      for(int i=0;i<ans.size();i++){\n          System.out.println(ans.get(i).x+\" \"+ans.get(i).y);\n      }\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author MaxHeap\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    F1SameSumBlocksEasy solver = new F1SameSumBlocksEasy();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class F1SameSumBlocksEasy {\n\n    Map<Long, List<IntPair>> sums = new HashMap<>();\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n      long[] arr = in.nextLongArray(n);\n      long[] pref = ArrayUtils.prefixSum(arr);\n      for (int i = 0; i < n; ++i) {\n        for (int j = i; j >= 0; --j) {\n          long sum = pref[i + 1] - pref[j];\n          if (sums.containsKey(sum)) {\n            sums.get(sum).add(Factories.makeIntPair(j, i));\n          } else {\n            List<IntPair> pairs = new ArrayList<>();\n            pairs.add(Factories.makeIntPair(j, i));\n            sums.put(sum, pairs);\n          }\n        }\n      }\n\n      int best = 0;\n      List<IntPair> res = new ArrayList<>();\n      for (long sum : sums.keySet()) {\n        List<IntPair> pairs = sums.get(sum);\n        List<IntPair> temp = new ArrayList<>();\n        int last = -1;\n        for (IntPair cur : pairs) {\n          if (cur.first > last) {\n            last = cur.second;\n            temp.add(cur);\n          }\n        }\n        if (temp.size() > best) {\n          best = temp.size();\n          res = temp;\n        }\n      }\n      out.println(best);\n      for (IntPair pair : res) {\n        out.println((pair.first + 1) + \" \" + (pair.second + 1));\n      }\n    }\n\n  }\n\n  static class ArrayUtils {\n\n    public static long[] prefixSum(long[] arr) {\n      long[] acc = new long[arr.length + 1];\n      for (int i = 1; i <= arr.length; ++i) {\n        acc[i] = acc[i - 1] + arr[i - 1];\n      }\n      return acc;\n    }\n\n  }\n\n  static interface FastIO {\n\n  }\n\n  static final class Factories {\n\n    private Factories() {\n    }\n\n    public static IntPair makeIntPair(int first, int second) {\n      return new IntPair(first, second);\n    }\n\n  }\n\n  static class IntPair implements Comparable<IntPair> {\n\n    public int first;\n    public int second;\n\n    public IntPair() {\n      first = second = 0;\n    }\n\n    public IntPair(int first, int second) {\n      this.first = first;\n      this.second = second;\n    }\n\n    public int compareTo(IntPair a) {\n      if (first == a.first) {\n        return Integer.compare(second, a.second);\n      }\n      return Integer.compare(first, a.first);\n    }\n\n    public String toString() {\n      return \"<\" + first + \", \" + 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      IntPair a = (IntPair) o;\n\n      if (first != a.first) {\n        return false;\n      }\n      return second == a.second;\n    }\n\n    public int hashCode() {\n      int result = first;\n      result = 31 * result + second;\n      return result;\n    }\n\n  }\n\n  static class InputReader implements FastIO {\n\n    private InputStream stream;\n    private static final int DEFAULT_BUFFER_SIZE = 1 << 16;\n    private static final int EOF = -1;\n    private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];\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 == EOF) {\n        throw new UnknownError();\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 ex) {\n            throw new InputMismatchException();\n          }\n\n          if (this.numChars <= 0) {\n            return EOF;\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      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      byte sgn = 1;\n      if (c == 45) {\n        sgn = -1;\n        c = this.read();\n      }\n\n      long res = 0;\n\n      while (c >= 48 && c <= 57) {\n        res *= 10L;\n        res += c - 48;\n        c = this.read();\n        if (isSpaceChar(c)) {\n          return res * sgn;\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 == EOF;\n    }\n\n    public long[] nextLongArray(int n) {\n      long[] arr = new long[n];\n      for (int i = 0; i < n; i++) {\n        arr[i] = nextLong();\n      }\n      return arr;\n    }\n\n  }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B{\n\n\tstatic long []sum;\n\t\n\tstatic int n;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc=new Scanner();\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tn=sc.nextInt();\n\t\tsum=new long [n+1];\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tsum[i]=sc.nextInt()+sum[i-1];\n\t\tHashMap<Long,Integer> map=new HashMap();\n\t\tArrayList<int []>[]adj=new ArrayList[n*n+10];\n\t\tfor(int i=0;i<adj.length;i++)\n\t\t\tadj[i]=new ArrayList();\n\t\tfor(int r=1;r<=n;r++) \n\t\t\tfor(int l=1;l<=n;l++) {\n\t\t\t\tif(r<l)\n\t\t\t\t\tcontinue;\n\t\t\t\tlong x=sum[r]-sum[l-1];\n\t\t\t\tmap.put(x, map.getOrDefault(x, map.size()));\n\t\t\t\tadj[map.get(x)].add(new int [] {l,r});\n\t\t\t}\n\t\tint ans=0;\n\t\tint bestIdx=0;\n\t\tfor(int idx=0;idx<adj.length;idx++)\n\t\t{\n\t\t\tArrayList<int[]>list=adj[idx];\n\t\t\tif(list.isEmpty())\n\t\t\t\tcontinue;\n\t\t\tint curr=1;\n\t\t\tint R=list.get(0)[1];\n\t\t\tfor(int i=1;i<list.size();i++)\n\t\t\t{\n\t\t\t\tint []tmp=list.get(i);\n\t\t\t\tif(tmp[0]>R)\n\t\t\t\t{\n\t\t\t\t\tR=tmp[1];\n\t\t\t\t\tcurr++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(curr>=ans) {\n\t\t\t\tans=curr;\n\t\t\t\tbestIdx=idx;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tArrayList<int[]>list=adj[bestIdx];\n\t\tint R=list.get(0)[1];\n\t\tout.println(list.get(0)[0]+\" \"+R);\n\t\tfor(int i=1;i<list.size();i++)\n\t\t{\n\t\t\tint []tmp=list.get(i);\n\t\t\tif(tmp[0]>R)\n\t\t\t{\n\t\t\t\tR=tmp[1];\n\t\t\t\tout.println(tmp[0]+\" \"+tmp[1]);\n\t\t\t}\n\t\t}\n\t\tout.close();\n\n\t}\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", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\n    static final long mod=(int)1e9+7;\n    public static void main(String[] args) throws Exception\n    {\n    \tFastReader in=new FastReader();\n    \tPrintWriter pw=new PrintWriter(System.out);\n    \tint n=in.nextInt();\n    \tint[] arr=new int[n+1];\n    \tfor(int i=1;i<=n;i++)\n    \t\tarr[i]=in.nextInt();\n    \tMap<Integer,TreeMap<Integer,Integer>> map=new HashMap();\n    \tfor(int i=1;i<=n;i++)\n    \t{\n    \t\tint sum=0;\n    \t\tfor(int j=i;j<=n;j++)\n    \t\t{\n    \t\t\tsum+=arr[j];\n    \t\t\tif(map.containsKey(sum))\n    \t\t\t{\n    \t\t\t\tTreeMap<Integer,Integer> t=map.get(sum);\n    \t\t\t\t// System.out.println(t+\" \"+sum);\n    \t\t\t\tMap.Entry<Integer,Integer> e=t.lastEntry();\n    \t\t\t\tif(e.getKey()>j)\n    \t\t\t\t{\n    \t\t\t\t\tt.remove(e.getKey());\n    \t\t\t\t\tt.put(j,i);\n    \t\t\t\t\tmap.put(sum,t);\n    \t\t\t\t}\n    \t\t\t\telse if(e.getKey()<i)\n    \t\t\t\t{\n    \t\t\t\t\tt.put(j,i);\n    \t\t\t\t\tmap.put(sum,t);\n    \t\t\t\t}\n    \t\t\t}\n    \t\t\telse\n    \t\t\t{\n    \t\t\t\tTreeMap<Integer,Integer> t=new TreeMap();\n    \t\t\t\tt.put(j,i);\n    \t\t\t\tmap.put(sum,t);\n    \t\t\t}\n    \t\t}\n    \t}\n    \tint ans=0,size=0;\n    \tfor(Map.Entry<Integer,TreeMap<Integer,Integer>> e:map.entrySet())\n    \t{\n    \t\tif(e.getValue().size()>size)\n    \t\t{\n    \t\t\tans=e.getKey();\n    \t\t\tsize=e.getValue().size();\n    \t\t}\n    \t}\n    \tpw.println(size);\n    \tfor(Map.Entry e:map.get(ans).entrySet())\n    \t\tpw.println(e.getValue()+\" \"+e.getKey());\n    \tpw.flush();\n    }\n}\n\nclass pair\n{\n\tint f,s;\n}\n\nclass FastReader\n{\n    BufferedReader br;\n    StringTokenizer st;\n \n    public FastReader()\n    {\n        br=new BufferedReader(new InputStreamReader(System.in));\n    }\n \n    public String next() throws IOException\n    {\n        if(st==null || !st.hasMoreElements())\n        {\n            st=new StringTokenizer(br.readLine());\n        }\n        return st.nextToken();\n    }\n \n    public int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n \n    public long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.util.regex.*;\n\npublic class Codeforces{\n\t\n\tstatic class MyScanner{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t\n\t\tMyScanner(FileReader fileReader){\n\t\t\tbr = new BufferedReader(fileReader);\n\t\t}\n\t\t\n\t\tMyScanner(){\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\n\t\tString nn(){\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\t\n\t\tchar nc(){\n\t\t\treturn nn().charAt(0);\n\t\t}\n\t\t\n\t\tint ni(){\n\t\t\treturn Integer.parseInt(nn());\n\t\t}\n\t\t\n\t\tlong nl(){\n\t\t\treturn Long.parseLong(nn());\n\t\t}\n\t\t\n\t\tdouble nd(){\n\t\t\treturn Double.parseDouble(nn());\n\t\t}\n\t\t\n\t\tint[] niArr0(int n){\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) ar[i] = ni();\n\t\t\treturn ar;\n\t\t}\n\t\t\n\t\tint[] niArr1(int n){\n\t\t\tint[] ar = new int[n + 1];\n\t\t\tfor(int i = 1; i <= n; i++) ar[i] = ni();\n\t\t\treturn ar;\n\t\t}\n\t\t\n\t\tlong[] nlArr0(int n){\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) ar[i] = nl();\n\t\t\treturn ar;\n\t\t}\n\t}\n\t\n\tpublic static <T> void mprintln(T ... ar){\n\t\tfor(T i: ar) out.print(i + \" \");\n\t\tout.println();\n\t}\n\t\n\tprivate static PrintWriter out;\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException{\n\t\t\n\t\t// Input from file\n\t\t// File inputFile = new File(\"JavaFile.txt\");\n\t\t// File outputFile = new File(\"JavaOutputFile.txt\");\n\t\t// FileReader fileReader = new FileReader(inputFile);\n\t\t// Here it ends\n\t\t\t\n\t\tMyScanner sc = new MyScanner();\n\t\t// MyScanner sc = new MyScanner(fileReader);\n\t\t\n\t\tout = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console\n\t\t// out = new PrintWriter(new PrintStream(outputFile)); // Output to file\n\t\t\n\t\tgetAns(sc);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tprivate static void getAns(MyScanner sc){\n\t\tint n = sc.ni();\n\t\tlong[] ar = sc.nlArr0(n);\n\t\t\n\t\tHashMap<Long, ArrayList<int[]>> map = new HashMap();\n\t\t\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tlong cur = 0;\n\t\t\tfor(int j = i; j >= 0; j--){\n\t\t\t\tcur += ar[j];\n\t\t\t\tif(!map.containsKey(cur)) map.put(cur, new ArrayList());\n\t\t\t\tmap.get(cur).add(new int[]{j + 1, i + 1});\n\t\t\t}\n\t\t}\n\t\t\n\t\t// System.out.println(map);\n\t\t\n\t\tSet<Long> set = map.keySet();\n\t\t// System.out.println(set);\n\t\tArrayList<int[]> ans = new ArrayList();\n\t\t\n\t\tfor(Long l: set){\n\t\t\tArrayList<int[]> cur = new ArrayList();\n\t\t\tint right = -1;\n\t\t\tfor(int[] arc: map.get(l)) if(arc[0] > right){\n\t\t\t\tright = arc[1];\n\t\t\t\tcur.add(arc);\n\t\t\t}\n\t\t\t\n\t\t\tif(cur.size() > ans.size()) ans = cur;\n\t\t}\n\t\t\n\t\tout.println(ans.size());\n\t\tfor(int[] arc: ans) mprintln(arc[0], arc[1]);\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\npublic class Main {\n\tpublic static class node implements Comparable<node> {\n\t\tint l,r;\n\t\tnode(){}\n\t\tnode(int l,int r) {\n\t\t\tthis.l=l;\n\t\t\tthis.r=r;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(node rhs) {\n\t\t\treturn r-rhs.r;\n\t\t}\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\tStringTokenizer sa=new StringTokenizer(in.readLine());\n\t\tint n=Integer.parseInt(sa.nextToken());\n\t\tsa=new StringTokenizer(in.readLine());\n\t\tint[] a=new int[n];\n\t\tTreeMap<Integer,ArrayList<node>> mp=new TreeMap();\n\t\tfor (int i=0;i<n;++i) a[i]=Integer.parseInt(sa.nextToken());\n\t\tfor (int i=0;i<n;++i) {\n\t\t\tint tmp=0;\n\t\t\tfor (int j=i;j<n;++j) {\n\t\t\t\ttmp+=a[j];\n\t\t\t\tif (!mp.containsKey(tmp)) {\n\t\t\t\t\tArrayList t=new ArrayList();\n\t\t\t\t\tt.add(new node(i,j));\n\t\t\t\t\tmp.put(tmp,t);\n\t\t\t\t} else {\n\t\t\t\t\tArrayList<node> t=mp.get(tmp);\n\t\t\t\t\tint left=0,right=t.size()-1,res=t.size();\n\t\t\t\t\twhile (left<=right) {\n\t\t\t\t\t\tint mid=(left+right)>>1;\n\t\t\t\t\t\tif (t.get(mid).r>=i) {\n\t\t\t\t\t\t\tres=mid;\n\t\t\t\t\t\t\tright=mid-1;\n\t\t\t\t\t\t} else left=mid+1;\n\t\t\t\t\t}\n\t\t\t\t\tif (res==t.size()) t.add(new node(i,j));\n\t\t\t\t\telse if (t.get(res).r>j) t.set(res,new node(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint res=0;\n\t\tfor (Entry<Integer,ArrayList<node>> entry:mp.entrySet())\n\t\t\tres=Math.max(res,entry.getValue().size());\n\t\tout.println(res);\n\t\tfor (Entry<Integer,ArrayList<node>> entry:mp.entrySet())\n\t\t\tif (entry.getValue().size()==res) {\n\t\t\t\tArrayList<node> tmp=entry.getValue();\n\t\t\t\tfor (int i=0;i<tmp.size();++i)\n\t\t\t\t\tout.printf(\"%d %d\\n\",tmp.get(i).l+1,tmp.get(i).r+1);\n\t\t\t\tout.flush();\n\t\t\t\treturn;\n\t\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Main{\n\t\n\tint[] ints;\n\tint[] prefix;\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tnew Main().run();\n\t}\n\t\n\tpublic void run()\n\t{\n\t\tScanner file = new Scanner(System.in);\n\t\tint N = file.nextInt();\n\t\tints = new int[N];\n\t\tfor(int i = 0;i<N;i++)\n\t\t\tints[i] = file.nextInt();\n\t\tprefix = new int[N];\n\t\tprefix[0] = ints[0];\n\t\tfor(int i =1;i<prefix.length;i++)\n\t\t\tprefix[i] = prefix[i-1]+ints[i];\n\t\tHashMap<Integer,Integer> ending = new HashMap<>();//ending for each sum\n\t\tHashMap<Integer,Integer> amount = new HashMap<>();//k for each sum\n\t\tfor(int end = 0;end<prefix.length;end++)\n\t\t{\n\t\t\tfor(int start = 0;start<=end;start++)\n\t\t\t{\n\t\t\t\tint sum = sum(start,end);\n\t\t\t\tif(!ending.containsKey(sum))\n\t\t\t\t\tending.put(sum, -1);\n\t\t\t\tif(!amount.containsKey(sum))\n\t\t\t\t\tamount.put(sum,0);\n\t\t\t\tif(ending.get(sum)<start)\n\t\t\t\t{\n\t\t\t\t\tamount.put(sum,amount.get(sum)+1);\n\t\t\t\t\tending.put(sum,end);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint max = 0;\n\t\tint maxnum = -1;\n\t\tfor(int x:amount.keySet())\n\t\t{\n\t\t\tif(amount.get(x)>max)\n\t\t\t{\n\t\t\t\tmax = amount.get(x);\n\t\t\t\tmaxnum = x;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t\tHashMap<Integer,Integer> occurrence = new HashMap<Integer,Integer>();\n\t\toccurrence.put(0,0);\n\t\tfor(int i = 0;i<prefix.length;i++)\n\t\t{\n\t\t\tif(occurrence.containsKey(prefix[i]-maxnum))\n\t\t\t{\n\t\t\t\tSystem.out.println(occurrence.get(prefix[i]-maxnum)+1+\" \"+(i+1));\n\t\t\t\toccurrence.clear();\n\t\t\t}\n\t\t\toccurrence.put(prefix[i],i+1);\n\t\t}\n\t}\n\t\n\tpublic int sum(int L, int R)\n\t{\n\t\treturn prefix[R] - prefix[L] + ints[L];\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/**\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class SameSumBlocks {\n    public static void main(String[] args) throws Exception {\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int N = sc.nextInt();\n        int[] pre = new int[N + 1];\n        var ansMap = new HashMap<Integer, ArrayDeque<Pair>>();\n        for (int j = 1; j <= N; j++) {\n            pre[j] = pre[j - 1] + sc.nextInt();\n            for (int i = j; i >= 1; i--) {\n                int sum = pre[j] - pre[i - 1];\n                /**\n                 we can actually perform the greedy scheduling as we read in the information!\n                 Because we are sweeping with an increasing right pointer, the moment a sum is\n                 found with this right endpoint, we can greedily place it into the schedule\n                 for a given sum \"bucket\", (if it's disjoint. Otherwise, we would be replacing\n                 one OR MORE previous intervals, which would only decrease or keep the same size,\n                 while reducing our future accessibility for adding intervals!)\n                 */\n                if (!ansMap.containsKey(sum) || ansMap.get(sum).getLast().r < i) {\n                    var dq = ansMap.computeIfAbsent(sum, val -> new ArrayDeque<>());\n                    dq.add(new Pair(i, j, sum));\n                }\n            }\n        }\n        var ans = new ArrayDeque<Pair>();\n        for (var group : ansMap.values()) {\n            if (group.size() > ans.size()) {\n                ans = group;\n            }\n        }\n        out.println(ans.size());\n        for (Pair p : ans) {\n            out.println(p);\n        }\n        out.close();\n    }\n\n    static class Pair {\n        int l, r, sum;\n        public Pair(int ll, int rr, int ss) {\n            l = ll; r = rr; sum = ss;\n        }\n        public String toString() {\n            return l + \" \" + r;\n        }\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            }\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 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class F2 {\n\n    private static int n;\n    private static int[] a;\n\n    private static Collection<Segment> answer;\n\n    public static void main(String[] args) {\n        in();\n        solution();\n        out();\n    }\n\n    private static void in() {\n\n        Scanner in = new Scanner(System.in);\n\n        n = in.nextInt();\n\n        a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n\n    }\n\n    private static void solution() {\n\n        HashMap<Long, LinkedList<Segment>> segments = new HashMap<>();\n\n        for (int i = 0; i < n; i++) {\n\n            long sum = 0;\n\n            for (int j = i; j < n; j++) {\n\n                sum += a[j];\n\n                if (segments.containsKey(sum)) {\n                    segments.get(sum).add(new Segment(i, j));\n                } else {\n                    LinkedList<Segment> toPut = new LinkedList<>();\n                    toPut.add(new Segment(i, j));\n                    segments.put(sum, toPut);\n                }\n\n            }\n\n        }\n\n        answer = null;\n        for (Map.Entry<Long, LinkedList<Segment>> sums : segments.entrySet()) {\n\n\n            LinkedList<Segment> currentSegments = sums.getValue();\n            Collections.sort(currentSegments);\n\n            LinkedList<Segment> segmentsWithoutCrossing = new LinkedList<>();\n\n            for (Segment segment : currentSegments) {\n\n\n                if ( segmentsWithoutCrossing.isEmpty() || !segmentsWithoutCrossing.getLast().isCrossingToNextSegment(segment)) {\n\n                    segmentsWithoutCrossing.add(segment);\n\n                } else if (segmentsWithoutCrossing.getLast().getR() > segment.getR()) {\n\n                    segmentsWithoutCrossing.removeLast();\n                    segmentsWithoutCrossing.add(segment);\n\n                }\n\n            }\n\n            answer = segmentsWithoutCrossing.size() > (answer != null ? answer.size() : 0) ? segmentsWithoutCrossing : answer;\n\n        }\n\n    }\n\n    private static void out() {\n\n        System.out.println(answer.size());\n\n        for (Segment segment : answer) {\n            System.out.println( (segment.getL() + 1) + \" \" + (segment.getR() + 1));\n        }\n\n    }\n\n}\n\nclass Segment implements Comparable<Segment>{\n\n    private int l, r;\n\n    Segment(int l, int r) {\n        this.l = l;\n        this.r = r;\n    }\n\n\n    int getL() {\n        return l;\n    }\n\n    int getR() {\n        return r;\n    }\n\n    @Override\n    public int compareTo(Segment segment) {\n\n        if (l == segment.l && r == segment.r) {\n            return 0;\n        }\n\n        return l != segment.l ? l - segment.l : r - segment.r;\n\n    }\n\n    boolean isCrossingToNextSegment(Segment segment) {\n        if (l == segment.l || r == segment.r) {\n            return true;\n        } else if (l < segment.l) {\n            return r >= segment.l;\n        } else if (r > segment.r) {\n            return l <= segment.r;\n        } else {\n            return true;\n        }\n    }\n\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\npublic class F1141 {\n\t\n\tprivate static class Interval {\n\t\tpublic int l;\n\t\tpublic int r;\n\t\t\n\t\tpublic Interval(int l,int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n//\t\tBufferedReader br = new BufferedReader(new FileReader(\"F:/books/input.txt\"));\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = br.readLine();\n\t\tint n = Integer.parseInt(s);\n\t\tlong[] a = new long[n];\n\t\tString[] as = br.readLine().split(\" \");\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i] = Long.parseLong(as[i]);\n\t\t}\n\t\tStringBuffer sb = solve(a,n);\n\t\tSystem.out.println(sb.toString());\n\t}\n\n\tprivate static StringBuffer solve(long[] a, int n) {\n\t\tStringBuffer ret = new StringBuffer(\"\");\n\t\tMap<Long,List<Interval>> mp = new HashMap<Long,List<Interval>>();\n\t\tlong max = 0,maxId = -1;\n\t\tfor(int i=n-1;i>=0;i--) {\n\t\t\tlong s=0;\n\t\t\tlong prev = 1;\n\t\t\tfor(int j=i;j<n;j++) {\n\t\t\t\ts+=a[j];\n//\t\t\t\tSystem.out.println(i+\",\"+j);\n\t\t\t\tInterval inter = new Interval(i,j);\n//\t\t\t\tif(prev==1 || prev==-1) {\n\t\t\t\t\tList<Interval> ints = mp.get(s);\n\t\t\t\t\tif(ints==null) ints = new ArrayList<Interval>();\n\t\t\t\t\tif(ints.size()==0 || ints.get(0).l>j) {\n\t\t\t\t\t\tints.add(0,inter);\n\t\t\t\t\t}\n\t\t\t\t\tif(ints.size()>max) {\n\t\t\t\t\t\tmax = ints.size();\n\t\t\t\t\t\tmaxId = s;\n\t\t\t\t\t}\n\t\t\t\t\tmp.put(s, ints);\n//\t\t\t\t}\n\t\t\t\tif(j<n-1) prev =  a[j+1]-a[j];\n\t\t\t}\n\t\t}\n\t\tList<Interval> l = mp.get(maxId);\n\t\tret.append(l.size()+ \"\\n\");\n\t\tfor(Interval inter : l) {\n\t\t\tret.append((inter.l+1) + \" \" + (inter.r+1) + \"\\n\");\n\t\t}\n\t\treturn ret;\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import javax.print.attribute.standard.PrinterMessageFromOperator;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        new Main().run();}\n\n//    int[] h,ne,to,wt;\n//    int ct = 0;\n//    int n;\n//    void graph(int n,int m){\n//        h = new int[n];\n//        Arrays.fill(h,-1);\n////        sccno = new int[n];\n////        dfn = new int[n];\n////        low = new int[n];\n////        iscut = new boolean[n];\n//        ne = new int[2*m];\n//        to = new int[2*m];\n//        wt = new int[2*m];\n//        ct = 0;\n//    }\n//    void add(int u,int v,int w){\n//        to[ct] = v;\n//        ne[ct] = h[u];\n//        wt[ct] = w;\n//        h[u] = ct++;\n//    }\n//\n//    int color[],dfn[],low[],stack[] = new int[1000000],cnt[];\n//    int sccno[];\n//    boolean iscut[];\n//    int time = 0,top = 0;\n//    int scc_cnt = 0;\n//\n//    // \u6709\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n//    void tarjan(int u) {\n//        low[u] = dfn[u]= ++time;\n//        stack[top++] = u;\n//        for(int i=h[u];i!=-1;i=ne[i]) {\n//            int v = to[i];\n//            if(dfn[v]==0) {\n//                tarjan(v);\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//        if(dfn[u]==low[u]) {\n//            sccno[u] = ++scc_cnt;\n//            while(stack[top-1]!=u) {\n//                sccno[stack[top-1]] = scc_cnt;\n//                --top;\n//            }\n//            --top;\n//        }\n//    }\n//\n//    //\u7f29\u70b9, topology sort\n//    int[] h1,to1,ne1;\n//    int ct1 = 0;\n//    void point(){\n//        for(int i=0;i<n;i++) {\n//            if(dfn[i]==0) tarjan(i);//\u6709\u53ef\u80fd\u56fe\u4e0d\u8fde\u901a\uff0c\u6240\u4ee5\u8981\u5faa\u73af\u5224\u65ad\u3002\n//        }\n//        // \u5165\u5ea6\n//        int du[] = new int[scc_cnt+1];\n//        h1 = new int[scc_cnt+1];\n//        Arrays.fill(h1, -1);\n//        to1 = new int[scc_cnt*scc_cnt];\n//        ne1 = new int[scc_cnt*scc_cnt];\n//        // scc_cnt \u4e2a\u70b9\n//\n//        for(int i=1;i<=n;i++) {\n//            for(int j=h[i]; j!=-1; j=ne[j]) {\n//                int y = to[j];\n//                if(sccno[i] != sccno[y]) {\n//                    // add(sccno[i],sccno[y]);  // \u5efa\u65b0\u56fe\n//                    to1[ct1] = sccno[y];\n//                    ne1[ct1] = h[sccno[i]];\n//                    h[sccno[i]] = ct1++;\n//                    du[sccno[y]]++; //\u5b58\u5165\u5ea6\n//                }\n//            }\n//        }\n//\n//        int q[] = new int[100000];\n//        int end = 0;\n//        int st = 0;\n//        for(int i=1;i<=scc_cnt;++i){\n//            if(du[i]==0){\n//                q[end++] = i;\n//            }\n//        }\n//\n//        int dp[] = new int[scc_cnt+1];\n//        while(st<end){\n//            int cur = q[st++];\n//            for(int i=h1[cur];i!=-1;i=ne1[i]){\n//                int y = to[i];\n//                // dp[y] += dp[cur];\n//                if(--du[y]==0){\n//                    q[end++] = y;\n//                }\n//            }\n//        }\n//    }\n//\n//\n//\n//\n//    int fa[];\n//    int faw[];\n//\n//    int dep = -1;\n//    int pt = 0;\n//    void go(int rt,int f,int dd){\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = f;p++;\n//        while(p>0) {\n//            int cur = stk[p - 1];\n//            int fp = fk[p - 1];\n//            int ll = lk[p - 1];\n//            p--;\n//\n//\n//            if (ll > dep) {\n//                dep = ll;\n//                pt = cur;\n//            }\n//            for (int i = h[cur]; i != -1; i = ne[i]) {\n//                int v = to[i];\n//                if (fp == v) continue;\n//\n//                stk[p] = v;\n//                lk[p] = ll + wt[i];\n//                fk[p] = cur;\n//                p++;\n//            }\n//        }\n//    }\n//    int pt1 = -1;\n//    void go1(int rt,int f,int dd){\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = f;p++;\n//        while(p>0) {\n//            int cur = stk[p - 1];\n//            int fp = fk[p - 1];\n//            int ll = lk[p - 1];\n//            p--;\n//\n//\n//            if (ll > dep) {\n//                dep = ll;\n//                pt1 = cur;\n//            }\n//\n//            fa[cur] = fp;\n//            for (int i = h[cur]; i != -1; i = ne[i]) {\n//                int v = to[i];\n//                if (v == fp) continue;\n//                faw[v] = wt[i];\n//                stk[p] = v;\n//                lk[p] = ll + wt[i];\n//                fk[p] = cur;\n//                p++;\n//            }\n//        }\n//    }\n//\n//    int r = 0;\n//    int stk[] = new int[301];\n//    int fk[] = new int[301];\n//    int lk[] = new int[301];\n//    void ddfs(int rt,int t1,int t2,int t3,int l){\n//\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = t3;p++;\n//        while(p>0){\n//            int cur = stk[p-1];\n//            int fp = fk[p-1];\n//            int ll = lk[p-1];\n//            p--;\n//            r = Math.max(r,ll);\n//            for(int i=h[cur];i!=-1;i=ne[i]){\n//                int v = to[i];\n//                if(v==t1||v==t2||v==fp) continue;\n//                stk[p] = v;\n//                lk[p] = ll+wt[i];\n//                fk[p] = cur;p++;\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    static long mod_pow(long k,long n,long p){\n        long res = 1L;\n        long temp = k;\n        while(n!=0L){\n            if((n&1L)==1L){\n                res = (res*temp)%p;\n            }\n            temp = (temp*temp)%p;\n            n = n>>1L;\n        }\n        return res%p;\n    }\n    int ct = 0;\n    int f[]  =new int[200001];\n    int b[]  =new int[200001];\n    int str[]  =new int[200001];\n\n    void go(int rt,List<Integer> g[]){\n        str[ct] = rt;\n        f[rt] = ct;\n        for(int cd:g[rt]){\n            ct++;\n            go(cd,g);\n        }\n        b[rt] = ct;\n    }\n    int add =0;\n\n    void go(int rt,int sd,int k,List<Integer> g[],int n){\n        if(add>n) {\n            return;\n        }\n\n        Queue<Integer> q =new LinkedList<>();\n        q.offer(rt);\n        for(int i=1;i<=sd;++i){\n            int sz =q.size();\n            if(sz==0) break;\n            int f = (i==1?2:1);\n            while(sz-->0){\n                int cur = q.poll();\n                for(int j=0;j<k-f;++j){\n                    q.offer(add);\n                    g[cur].add(add);add++;\n                    if(add==n+1){\n                        return;\n                    }\n                }\n            }\n        }\n\n\n    }\n\n\n\n    void solve() {\n\n        int n = ni();\n        int s[] = new int[n+1];\n        for(int i=0;i<n;++i){\n            s[i+1] = s[i]  + ni();\n        }\n\n        Map<Integer,List<int[]>> mp = new HashMap<>();\n        for(int i=0;i<n;++i) {\n            for (int j = i; j>=0; --j) {\n                int v = s[i+1]-s[j];\n                if(!mp.containsKey(v)){\n                    mp.put(v, new ArrayList<>());\n                }\n                mp.get(v).add(new int[]{j+1,i+1});\n            }\n        }\n        int all = 0;int vv = -1;\n        for(int v:mp.keySet()){\n            List<int[]> r = mp.get(v);\n            ;int c = 0;\n            int ri = -2000000000;\n            for(int [] fk : r){\n                if(fk[0]>ri){\n                    ri = fk[1];c++;\n                }\n            }\n            if(c>all){\n                all = c;\n                vv = v;\n            }\n        }\n        println(all);\n        List<int[]> r = mp.get(vv);\n        int ri = -2000000000;\n        for(int fk[]:r){\n            if(fk[0]>ri){\n                ri = fk[1];println((fk[0])+\" \"+(fk[1]));\n            }\n        }\n\n\n\n\n\n\n\n        //N , M , K , a , b , c , d . \u5176\u4e2dN , M\u662f\u77e9\u9635\u7684\u884c\u5217\u6570\uff1bK \u662f\u4e0a\u9501\u7684\u623f\u95f4\u6570\u76ee\uff0c(a, b)\u662f\u8d77\u59cb\u4f4d\u7f6e\uff0c(c, d)\u662f\u51fa\u53e3\u4f4d\u7f6e\n\n\n//        int n = ni();\n//        int m = ni();\n//        int k = ni();\n//        int a = ni();\n//        int b = ni();\n//        int c = ni();\n//        int d = ni();\n//\n//\n//        char cc[][] = nm(n,m);\n//        char keys[][] = new char[n][m];\n//\n//        char ky = 'a';\n//        for(int i=0;i<k;++i){\n//            int x = ni();\n//            int y = ni();\n//            keys[x][y] = ky;\n//            ky++;\n//        }\n//        int f1[] = {a,b,0};\n//\n//        int dd[][] = {{0,1},{0,-1},{1,0},{-1,0}};\n//\n//        Queue<int[]> q =  new LinkedList<>();\n//        q.offer(f1);\n//        int ts = 1;\n//\n//        boolean vis[][][] = new boolean[n][m][33];\n//\n//        while(q.size()>0){\n//            int sz = q.size();\n//            while(sz-->0) {\n//                int cur[] = q.poll();\n//                vis[cur[0]][cur[1]][cur[2]] = true;\n//\n//                int x = cur[0];\n//                int y = cur[1];\n//\n//                for (int u[] : dd) {\n//                       int lx = x +  u[0];\n//                       int ly = y +  u[1];\n//                       if (lx >= 0 && ly >= 0 && lx < n && ly < m && (cc[lx][ly] != '#')&&!vis[lx][ly][cur[2]]){\n//                            char ck =cc[lx][ly];\n//                            if(ck=='.'){\n//                                if(lx==c&&ly==d){\n//                                    println(ts); return;\n//                                }\n//                                if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {\n//                                    int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));\n//                                    q.offer(new int[]{lx, ly, cao});\n//                                    vis[lx][ly][cao] = true;\n//                                }else {\n//\n//                                    q.offer(new int[]{lx, ly, cur[2]});\n//                                }\n//\n//                            }else if(ck>='A'&&ck<='Z'){\n//                                int g = 1<<(ck-'A');\n//                                if((g&cur[2])>0){\n//                                    if(lx==c&&ly==d){\n//                                        println(ts); return;\n//                                    }\n//                                    if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {\n//\n//                                        int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));\n//                                        q.offer(new int[]{lx, ly, cao});\n//                                        vis[lx][ly][cao] = true;;\n//                                    }else {\n//\n//                                        q.offer(new int[]{lx, ly, cur[2]});\n//                                    }\n//                                }\n//                            }\n//                       }\n//                }\n//\n//                }\n//            ts++;\n//        }\n//        println(-1);\n\n\n\n\n//        int n = ni();\n//\n//        HashSet<String> st = new HashSet<>();\n//        HashMap<String,Integer> mp = new HashMap<>();\n//\n//\n//        for(int i=0;i<n;++i){\n//            String s  = ns();\n//            int id= 1;\n//            if(mp.containsKey(s)){\n//                int u = mp.get(s);\n//                id = u;\n//\n//            }\n//\n//            if(st.contains(s)) {\n//\n//                while (true) {\n//                    String ts = s + id;\n//                    if (!st.contains(ts)) {\n//                        s = ts;\n//                        break;\n//                    }\n//                    id++;\n//                }\n//                mp.put(s,id+1);\n//            }else{\n//                mp.put(s,1);\n//            }\n//            println(s);\n//            st.add(s);\n//\n//        }\n\n//        int t = ni();\n//\n//        for(int i=0;i<t;++i){\n//            int n = ni();\n//            long w[] = nal(n);\n//\n//            Map<Long,Long> mp = new HashMap<>();\n//            PriorityQueue<long[]> q =new PriorityQueue<>((xx,xy)->{return Long.compare(xx[0],xy[0]);});\n//\n//            for(int j=0;j<n;++j){\n//                q.offer(new long[]{w[j],0});\n//                mp.put(w[j],mp.getOrDefault(w[j],0L)+1L);\n//            }\n//\n//            while(q.size()>=2){\n//                long f[] = q.poll();\n//                long y1 = f[1];\n//                if(y1==0){\n//                    y1 = mp.get(f[0]);\n//                    if(y1==1){\n//                        mp.remove(f[0]);\n//                    }else{\n//                        mp.put(f[0],y1-1);\n//                    }\n//                }\n//                long g[] = q.poll();\n//                long y2 = g[1];\n//                if(y2==0){\n//                    y2 = mp.get(g[0]);\n//                    if(y2==1){\n//                        mp.remove(g[0]);\n//                    }else{\n//                        mp.put(g[0],y2-1);\n//                    }\n//                }\n//                q.offer(new long[]{f[0]+g[0],2L*y1*y2});\n//\n//            }\n//            long r[] = q.poll();\n//            println(r[1]);\n//\n//\n//\n//\n//        }\n        //  int o= 9*8*7*6;\n        //  println(o);\n\n\n//       int t = ni();\n//       for(int i=0;i<t;++i){\n//           long a = nl();\n//           int k  = ni();\n//           if(k==1){\n//               println(a);\n//               continue;\n//           }\n//\n//           int f = (int)(a%10L);\n//           int s = 1;\n//           int j = 0;\n//           for(;j<30;j+=2){\n//               int u = f-j;\n//               if(u<0){\n//                   u = 10+u;\n//               }\n//               s = u*s;\n//               s = s%10;\n//               if(s==k){\n//                   break;\n//               }\n//           }\n//\n//           if(s==k) {\n//               println(a - j - 2);\n//           }else{\n//               println(-1);\n//           }\n//\n//\n//\n//\n//       }\n\n//     int m = ni();\n//     h = new int[n];\n//     to = new int[2*(n-1)];\n//     ne = new int[2*(n-1)];\n//     wt = new int[2*(n-1)];\n//\n//     for(int i=0;i<n-1;++i){\n//         int u = ni()-1;\n//         int v = ni()-1;\n//\n//     }\n        //  long a[] = nal(n);\n\n\n//        int n = ni();\n//        int k = ni();\n//        t1 = new long[200002];\n//\n//        int p[][] = new int[n][3];\n//\n//        for(int i=0;i<n;++i){\n//            p[i][0]  = ni();\n//            p[i][1]  = ni();\n//            p[i][2]  = i+1;\n//        }\n//        Arrays.sort(p, new Comparator<int[]>() {\n//            @Override\n//            public int compare(int[] x, int[] y) {\n//                if(x[1]!=y[1]){\n//                    return Integer.compare(x[1],y[1]);\n//                }\n//                return Integer.compare(y[0], x[0]);\n//            }\n//        });\n//\n//        for(int i=0;i<n;++i){\n//            int ck = p[i][0];\n//\n//        }\n\n\n\n\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 []h,to,ne,wt;\n\n    long t1[];\n    //    long t2[];\n    void update(long[] t,int i,long v){\n        for(;i<t.length;i+=(i&-i)){\n            t[i] += v;\n        }\n    }\n    long get(long[] t,int i){\n        long s = 0;\n        for(;i>0;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<<i)< t.length && s + t[p+(1<<i)] < v){\n                v -= t[p+(1<<i)];\n                p |= 1<<i;\n            }\n        }\n        return p+1;\n    }\n\n\n\n\n\n\n\n\n\n    static class S{\n        int l = 0;\n        int r = 0 ;\n        long le = 0;\n        long ri = 0;\n        long tot = 0;\n        long all = 0;\n\n        public S(int l,int r) {\n            this.l = l;\n            this.r = r;\n        }\n    }\n\n    static S a[];\n    static int[] o;\n\n    static void init(int[] f){\n        o = f;\n        int len = o.length;\n        a = new S[len*4];\n        build(1,0,len-1);\n    }\n\n    static void build(int num,int l,int r){\n        S cur = new S(l,r);\n        if(l==r){\n            a[num] = cur;\n            return;\n        }else{\n            int m = (l+r)>>1;\n            int le = num<<1;\n            int ri = le|1;\n            build(le, l,m);\n            build(ri, m+1,r);\n            a[num] = cur;\n            pushup(num, le, ri);\n        }\n    }\n\n\n\n    //    static int query(int num,int l,int r){\n//\n//        if(a[num].l>=l&&a[num].r<=r){\n//            return a[num].tot;\n//        }else{\n//            int m = (a[num].l+a[num].r)>>1;\n//            int le = num<<1;\n//            int ri = le|1;\n//            pushdown(num, le, ri);\n//            int ma = 1;\n//            int mi = 100000001;\n//            if(l<=m) {\n//                int r1 = query(le, l, r);\n//                ma = ma*r1;\n//\n//            }\n//            if(r>m){\n//                int r2 = query(ri, l, r);\n//                ma = ma*r2;\n//            }\n//            return ma;\n//        }\n//    }\n    static long dd = 10007;\n    static void update(int num,int l,long v){\n        if(a[num].l==a[num].r){\n            a[num].le = v%dd;\n            a[num].ri = v%dd;\n            a[num].all = v%dd;\n            a[num].tot = v%dd;\n        }else{\n            int m = (a[num].l+a[num].r)>>1;\n            int le = num<<1;\n            int ri = le|1;\n            pushdown(num, le, ri);\n            if(l<=m){\n                update(le,l,v);\n            }\n            if(l>m){\n                update(ri,l,v);\n            }\n            pushup(num,le,ri);\n        }\n    }\n\n    static void pushup(int num,int le,int ri){\n        a[num].all = (a[le].all*a[ri].all)%dd;\n        a[num].le = (a[le].le + a[le].all*a[ri].le)%dd;\n        a[num].ri = (a[ri].ri + a[ri].all*a[le].ri)%dd;\n        a[num].tot = (a[le].tot + a[ri].tot + a[le].ri*a[ri].le)%dd;\n\n\n        //a[num].res[1] = Math.min(a[le].res[1],a[ri].res[1]);\n    }\n    static void pushdown(int num,int le,int ri){\n\n    }\n\n\n    int gcd(int a,int b){ return b==0?a: gcd(b,a%b);}\n    InputStream is;PrintWriter out;\n    void run() throws Exception {is = System.in;out = new PrintWriter(System.out);solve();out.flush();}\n    private byte[] inbuf = new byte[2];\n    public int lenbuf = 0, ptrbuf = 0;\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    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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Map;\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 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        F2SameSumBlocksHard solver = new F2SameSumBlocksHard();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2SameSumBlocksHard {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n\n            long[] a = in.nextLongArray(n);\n\n            long[] p = in.calculatePrefixSum(a);\n\n            Map<Long, Integer> map = new HashMap<>();\n\n            for (int i = 0; i < n; i++) {\n                long sum = 0;\n                for (int j = i; j < n; j++) {\n                    sum += a[j];\n                    map.merge(sum, 1, (x, y) -> x + y);\n                }\n            }\n\n\n            List<sum> sums = new ArrayList<>();\n            for (long sum : map.keySet()) {\n                sums.add(new sum(sum, map.get(sum)));\n            }\n\n            sums.sort((x, y) -> y.c - x.c);\n\n            int ans = -1;\n\n            int[] fca = null;\n            long mxsum = -1;\n            for (int i = 0; i < sums.size(); i++) {\n                sum cs = sums.get(i);\n                long sum = cs.sum;\n                long c = cs.c;\n\n                if (c < ans) {\n                    continue;\n                }\n\n                Map<Long, Integer> lm = new HashMap<>();\n\n                int[] ca = new int[n];\n                lm.put(0l, -1);\n                for (int j = 0; j < n; j++) {\n                    long val = p[j];\n\n                    if (j > 0) {\n                        ca[j] = ca[j - 1];\n                    }\n                    long req = val - sum;\n\n                    if (lm.containsKey(req)) {\n                        int li = lm.get(req);\n                        if (li == -1)\n                            ca[j] = Math.max(1, ca[j]);\n                        else\n                            ca[j] = Math.max(1 + ca[li], ca[j]);\n                    }\n\n                    lm.put(val, j);\n                }\n\n                if (ca[n - 1] > ans) {\n                    ans = ca[n - 1];\n                    mxsum = sum;\n                    fca = ca;\n                }\n            }\n\n            List<Integer> al = new ArrayList<>();\n\n            long sum = 0;\n            for (int i = n - 1; i >= 0; i--) {\n                if (i > 0 && fca[i] != fca[i - 1]) {\n                    sum = 0;\n                    al.add(i + 1);\n                    do {\n                        sum += a[i];\n                        i--;\n                    } while (i >= 0 && sum != mxsum);\n                    i++;\n                    al.add(i + 1);\n                } else if (i == 0) {\n                    if (a[i] == mxsum) {\n                        al.add(i + 1);\n                        al.add(i + 1);\n                    }\n                }\n            }\n\n            out.println(al.size() / 2);\n\n            for (int i = al.size() - 1; i >= 0; i -= 2) {\n                out.println(al.get(i) + \" \" + al.get(i - 1));\n            }\n        }\n\n        class sum {\n            long sum;\n            int c;\n\n            public sum(long sum, int c) {\n                this.sum = sum;\n                this.c = c;\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 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 long[] nextLongArray(int n) {\n            long[] array = new long[n];\n            for (int i = 0; i < n; ++i) array[i] = nextLong();\n            return array;\n        }\n\n        public long[] calculatePrefixSum(long[] a) {\n            int n = a.length;\n\n            long[] prefixSum = new long[n];\n\n            prefixSum[0] = a[0];\n\n            for (int i = 1; i < n; i++) {\n                prefixSum[i] = prefixSum[i - 1] + a[i];\n            }\n\n            return prefixSum;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void print(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n        }\n\n        public void println(Object... objects) {\n            print(objects);\n            writer.println();\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void println(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\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 Liavontsi Brechka\n */\npublic class Main\n{\n    public static void main(String[] args)\n    {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F1BlokiRavnoiSummiProstayaRedakciya solver = new F1BlokiRavnoiSummiProstayaRedakciya();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F1BlokiRavnoiSummiProstayaRedakciya\n    {\n        InputReader in;\n        Map<Long, List<F1BlokiRavnoiSummiProstayaRedakciya.Block>> sums;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out)\n        {\n            this.in = in;\n\n            int n = ni();\n            long[] a = nla(n);\n\n            sums = new HashMap<>();\n            for (int i = 0; i < n; i++)\n            {\n                long sum = 0;\n                for (int j = i; j < n; j++)\n                {\n                    sum += a[j];\n                    sums.computeIfAbsent(sum, k -> new ArrayList<>()).add(\n                                    new F1BlokiRavnoiSummiProstayaRedakciya.Block(i, j, sum));\n                }\n            }\n\n            for (Map.Entry<Long, List<F1BlokiRavnoiSummiProstayaRedakciya.Block>> e : sums.entrySet())\n            {\n                Collections.sort(e.getValue());\n            }\n\n            List<F1BlokiRavnoiSummiProstayaRedakciya.Block> res = Collections.emptyList();\n            for (Map.Entry<Long, List<F1BlokiRavnoiSummiProstayaRedakciya.Block>> e : sums.entrySet())\n            {\n                List<F1BlokiRavnoiSummiProstayaRedakciya.Block> blocks = e.getValue();\n                List<F1BlokiRavnoiSummiProstayaRedakciya.Block> updated = new ArrayList<>();\n\n                for (F1BlokiRavnoiSummiProstayaRedakciya.Block next : blocks)\n                {\n                    if (updated.size() == 0)\n                        updated.add(next);\n                    else\n                    {\n                        F1BlokiRavnoiSummiProstayaRedakciya.Block prev = updated.get(updated.size() - 1);\n                        if (next.l > prev.r)\n                            updated.add(next);\n                    }\n                }\n\n                if (updated.size() > res.size())\n                    res = updated;\n            }\n\n            StringBuilder resS = new StringBuilder();\n            resS.append(res.size()).append('\\n');\n            for (F1BlokiRavnoiSummiProstayaRedakciya.Block block : res)\n                resS.append(block.l + 1).append(' ').append(block.r + 1).append('\\n');\n\n            out.println(resS);\n        }\n\n        private long[] nla(int size)\n        {\n            return in.nextLongArray(size);\n        }\n\n        private int ni()\n        {\n            return in.nextInt();\n        }\n\n        static class Block implements Comparable<F1BlokiRavnoiSummiProstayaRedakciya.Block>\n        {\n            int l;\n            int r;\n            long sum;\n\n            public Block(int l, int r, long sum)\n            {\n                this.l = l;\n                this.r = r;\n                this.sum = sum;\n            }\n\n            public int compareTo(F1BlokiRavnoiSummiProstayaRedakciya.Block o)\n            {\n                int res = Integer.compare(r, o.r);\n                if (res == 0)\n                    res = Integer.compare(l, o.l);\n                return res;\n            }\n\n        }\n\n    }\n\n    static class InputReader\n    {\n        private final BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream in)\n        {\n            reader = new BufferedReader(new InputStreamReader(in));\n        }\n\n        public long[] nextLongArray(int size)\n        {\n            long[] array = new long[size];\n            for (int i = 0; i < size; ++i)\n            {\n                array[i] = nextLong();\n            }\n            return array;\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        public String next()\n        {\n            while (tokenizer == null || !tokenizer.hasMoreTokens())\n            {\n                tokenizer = new StringTokenizer(readLine());\n            }\n            return tokenizer.nextToken();\n        }\n\n        public String readLine()\n        {\n            String line;\n            try\n            {\n                line = reader.readLine();\n            }\n            catch (IOException e)\n            {\n                throw new RuntimeException(e);\n            }\n            return line;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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=998244353;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tvoid work() {\n\t\tint n=in.nextInt();\n\t\tint[] A=new int[n];\n\t\tfor(int i=0;i<n;i++)A[i]=in.nextInt();\n\t\tHashMap<Integer,Integer> map=new HashMap<>();\n\t\tHashMap<Integer,ArrayList<int[]>> rec=new HashMap<>();\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=i,cur=0;j>=0;j--) {\n\t\t\t\tcur+=A[j];\n\t\t\t\tif(map.get(cur)==null) {\n\t\t\t\t\tmap.put(cur,i);\n\t\t\t\t\trec.put(cur,new ArrayList<>());\n\t\t\t\t\trec.get(cur).add(new int[] {j,i});\n\t\t\t\t}else if(map.get(cur)<j) {\n\t\t\t\t\tmap.put(cur,i);\n\t\t\t\t\trec.get(cur).add(new int[] {j,i});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrayList<int[]> ret=null;\n\t\tfor(ArrayList<int[]> list:rec.values()) {\n\t\t\tif(ret==null||ret.size()<list.size()) {\n\t\t\t\tret=list;\n\t\t\t}\n\t\t}\n\t\tout.println(ret.size());\n\t\tfor(int[] r:ret) {\n\t\t\tout.println((r[0]+1)+\" \"+(r[1]+1));\n\t\t}\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\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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\n\t\tlong[] a = new long[n];\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = Long.parseLong(st.nextToken());\n\t\t}\n\n\t\tlong[] sum = new long[n];\n\t\tsum[0] = a[0];\n\t\tfor (int i = 1; i < sum.length; i++) {\n\t\t\tsum[i] = sum[i - 1] + a[i];\n\t\t}\n\n\t\tsolve(a, sum);\n\n\t}\n\n\tprivate static void solve(long[] a, long[] sum) {\n\t\tint n = a.length;\n\n\t\tMap<Long, List<Pair>> map = new HashMap<>();\n\n\t\tfor (int j = 0; j < sum.length; j++) {\n\t\t\tfor (int i = 0; i <= j; i++) {\n\t\t\t\tlong k = getSum(sum, i, j);\n\t\t\t\tif (map.containsKey(k)) {\n\t\t\t\t\tmap.get(k).add(new Pair(i, j));\n\t\t\t\t} else {\n\t\t\t\t\tList<Pair> arr = new ArrayList<>();\n\t\t\t\t\tarr.add(new Pair(i, j));\n\t\t\t\t\tmap.put(k, arr);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint max = -1;\n\t\tList<Pair> ans = null;\n\t\tfor (Map.Entry<Long, List<Pair>> entry : map.entrySet()) {\n\t\t\tList<Pair> pairs = entry.getValue();\n\n\t\t\tint prev = -1;\n\t\t\tint count = 0;\n\t\t\tList<Pair> temp = new ArrayList<Pair>();\n\t\t\tfor (Pair p : pairs) {\n\t\t\t\tif (p.x > prev) {\n\t\t\t\t\tprev = p.y;\n\t\t\t\t\ttemp.add(p);\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (count > max) {\n\t\t\t\tans = temp;\n\t\t\t\tmax = count;\n\t\t\t}\n\t\t}\n\t\tif (max != -1) {\n\t\t\tSystem.out.println(ans.size());\n\t\t\tfor (Pair p : ans) {\n\t\t\t\tSystem.out.println((p.x + 1) + \" \" + (p.y + 1));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static long getSum(long[] sum, int l, int r) {\n\t\tif (l == 0) {\n\t\t\treturn sum[r];\n\t\t}\n\t\treturn sum[r] - sum[l - 1];\n\t}\n}\n\nclass Pair {\n\n\tint x;\n\tint y;\n\n\tPair(int x, int y) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint h = 171 << 4;\n\t\th = h * x;\n\t\th = h * y;\n\t\treturn h;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (o instanceof Pair) {\n\t\t\tPair other = (Pair) o;\n\t\t\treturn this.x == other.x && this.y == other.y;\n\t\t}\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"Pair [x=\" + x + \", y=\" + y + \"]\";\n\t}\n\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/**\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class SameSumBlocks {\n    public static void main(String[] args) throws Exception {\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int N = sc.nextInt();\n        int[] pre = new int[N + 1];\n        for (int i = 1; i <= N; i++) {\n            pre[i] = pre[i - 1] + sc.nextInt();\n        }\n//        var sumMap = new HashMap<Integer, ArrayList<Pair>>();\n//        var sums = new ArrayList<Pair>();\n        Pair[] sums = new Pair[N * (N + 1) / 2];\n        int k = 0;\n        for (int i = 1; i <= N; i++) {\n            for (int j = i; j <= N; j++) {\n                int sum = pre[j] - pre[i - 1];\n//                sumMap.computeIfAbsent(sum, val -> new ArrayList<>()).add(new Pair(i, j, sum));\n                sums[k++] = new Pair(i, j, sum);\n            }\n        }\n        Arrays.sort(sums, (p1, p2) -> p1.sum - p2.sum != 0 ? p1.sum - p2.sum : p1.r - p2.r);\n        var ans = new ArrayList<Pair>();\n        int i = 0;\n        while (i < k) {\n            var group = new ArrayList<Pair>();\n            int last = 0;\n            int j = i;\n            while (j < k && sums[j].sum == sums[i].sum) {\n                if (sums[j].l > last) {\n                    group.add(sums[j]);\n                    last = sums[j].r;\n                }\n                j++;\n            }\n//            System.out.println(group);\n            if (group.size() > ans.size()) {\n                ans = group;\n            }\n            i = j;\n        }\n        out.println(ans.size());\n        for (Pair p : ans) {\n            out.println(p);\n        }\n        out.close();\n    }\n\n    static class Pair {\n        int l, r, sum;\n        public Pair(int ll, int rr, int ss) {\n            l = ll; r = rr; sum = ss;\n        }\n        public String toString() {\n            return l + \" \" + r;\n        }\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            }\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 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\npublic class Task {\n\n    public static void solve() throws Exception {\n\tint n = nextInt();\n\tint[] S = new int[n];\n\tfor(int i=0;i<n;i++) {\n\t    S[i] = nextInt();\n\t    if(i > 0) {\n\t\tS[i] += S[i-1];\n\t    }\n\t}\n\tMap<Integer, List<L>> map = new HashMap<>();\n\tfor(int j=0;j<n;j++) {\n\t    for(int i=j;i>=0;i--) {\n\t\tint sum = S[j];\n\t\tif(i > 0) {\n\t\t    sum -= S[i-1];\n\t\t}\n\t\tL l = new L();\n\t\tl.a = i;\n\t\tl.b = j;\n\t\tList<L> list = map.get(sum);\n\t\tif(list == null) {\n\t\t    list = new ArrayList<>();\n\t\t    map.put(sum, list);\n\t\t}\n\t\tlist.add(l);\n\t    }\n\t}\n\tList<L> longest = null;\n\tfor(Integer sum: map.keySet()) {\n\t    List<L> list = map.get(sum);\n\t    Collections.sort(list);\n\t    List<L> list2 = new ArrayList<>(list.size());\n\t    int from = list.get(0).a;\n\t    for(L l: list) {\n\t\tif(l.a >= from) {\n\t\t    list2.add(l);\n\t\t    from = l.b + 1;\n\t\t}\n\t    }\n\t    if(longest == null || longest.size() < list2.size()) {\n\t\tlongest = list2;\n\t    }\n\t}\n\t\n\tprintln(longest.size());\n\tfor(int i=0;i<longest.size();i++) {\n\t    L l = longest.get(i);\n\t    println((l.a+1) + \" \" + (l.b+1));\n\t}\n    }\n    \n    private static class L implements Comparable<L>{\n\tint a;\n\tint b;\n\t\n\t@Override\n\tpublic int compareTo(L l2) {\n\t    return Integer.valueOf(b).compareTo(l2.b);\n\t}\n    }\n    \n    public static void main(String[] args) throws Exception {\n\ttry {\n\t    fastReader = new FastReader(System.in);\n\t    systemOut = new BufferedOutputStream(System.out);\n\t    solve();\n\t} finally {\n\t    systemOut.close();\n\t}\n    }\n\n    private static FastReader fastReader = null;\n    private static BufferedOutputStream systemOut = null;\n\n    public static void print(Object obj) {\n\tprint(obj.toString());\n    }\n\n    public static void print(String str) {\n\ttry {\n\t    systemOut.write(str.getBytes(\"utf-8\"));\n\t} catch (Exception ex) {\n\t    throw new RuntimeException(ex);\n\t}\n    }\n\n    public static void println(Object obj) {\n\tprintln(obj.toString());\n    }\n\n    public static void println(String str) {\n\ttry {\n\t    print(str);\n\t    systemOut.write('\\n');\n\t} catch (Exception ex) {\n\t    throw new RuntimeException(ex);\n\t}\n    }\n\n    public static String next() {\n\treturn fastReader.readNextToken(false);\n    }\n\n    public static String nextLine() {\n\treturn fastReader.readNextToken(true);\n    }\n\n    public static int nextInt() {\n\treturn Integer.parseInt(fastReader.readNextToken(false));\n    }\n\n    public static long nextLong() {\n\treturn Long.parseLong(fastReader.readNextToken(false));\n    }\n\n    public static double nextDouble() {\n\treturn Double.parseDouble(fastReader.readNextToken(false));\n    }\n\n    static class FastReader {\n\tprivate byte[] buf = new byte[65536];\n\tprivate int ind = 0;\n\tprivate int maxInd = -1;\n\tprivate InputStream is = null;\n\tprivate boolean eof = false;\n\tprivate boolean lastCharRead = false;\n\n\tpublic FastReader(InputStream is) {\n\t    this.is = is;\n\t}\n\n\tpublic String readNextToken(boolean endOfLine) {\n\t    try {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tboolean found = false;\n\t\twhile (true) {\n\t\t    if (lastCharRead) {\n\t\t\treturn null;\n\t\t    } else if (ind > maxInd) {\n\t\t\tif (eof) {\n\t\t\t    lastCharRead = true;\n\t\t\t} else {\n\t\t\t    fillBuffer();\n\t\t\t}\n\t\t    }\n\t\t    byte b = '\\n';\n\t\t    if (!lastCharRead) {\n\t\t\tb = buf[ind++];\n\t\t    }\n\n\t\t    if (b == '\\r') {\n\t\t\t// ignore\n\t\t    } else if ((b == '\\n' && endOfLine) || (Character.isWhitespace(b) && !endOfLine)) {\n\t\t\tif (found) {\n\t\t\t    break;\n\t\t\t}\n\t\t    } else {\n\t\t\tsb.append((char) b);\n\t\t\tfound = true;\n\t\t    }\n\t\t}\n\t\treturn sb.toString();\n\t    } catch (Exception ex) {\n\t\tthrow new RuntimeException(ex);\n\t    }\n\t}\n\n\tprivate void fillBuffer() {\n\t    try {\n\t\tint read = is.read(buf, 0, buf.length);\n\t\tif (read < buf.length) {\n\t\t    eof = true;\n\t\t}\n\t\tind = 0;\n\t\tmaxInd = read - 1;\n\t    } catch (Exception ex) {\n\t\tthrow new RuntimeException(ex);\n\t    }\n\t}\n    }\n\n    public static class LST {\n\tpublic long[][] set;\n\tpublic int n;\n\n\tpublic LST(int n) {\n\t    this.n = n;\n\t    int d = 1;\n\t    for (int m = n; m > 1; m >>>= 6, d++)\n\t\t;\n\n\t    set = new long[d][];\n\t    for (int i = 0, m = n >>> 6; i < d; i++, m >>>= 6) {\n\t\tset[i] = new long[m + 1];\n\t    }\n\t}\n\n\t// [0,r)\n\tpublic LST setRange(int r) {\n\t    for (int i = 0; i < set.length; i++, r = r + 63 >>> 6) {\n\t\tfor (int j = 0; j < r >>> 6; j++) {\n\t\t    set[i][j] = -1L;\n\t\t}\n\t\tif ((r & 63) != 0)\n\t\t    set[i][r >>> 6] |= (1L << r) - 1;\n\t    }\n\t    return this;\n\t}\n\n\t// [0,r)\n\tpublic LST unsetRange(int r) {\n\t    if (r >= 0) {\n\t\tfor (int i = 0; i < set.length; i++, r = r + 63 >>> 6) {\n\t\t    for (int j = 0; j < r + 63 >>> 6; j++) {\n\t\t\tset[i][j] = 0;\n\t\t    }\n\t\t    if ((r & 63) != 0)\n\t\t\tset[i][r >>> 6] &= ~((1L << r) - 1);\n\t\t}\n\t    }\n\t    return this;\n\t}\n\n\tpublic LST set(int pos) {\n\t    if (pos >= 0 && pos < n) {\n\t\tfor (int i = 0; i < set.length; i++, pos >>>= 6) {\n\t\t    set[i][pos >>> 6] |= 1L << pos;\n\t\t}\n\t    }\n\t    return this;\n\t}\n\n\tpublic LST unset(int pos) {\n\t    if (pos >= 0 && pos < n) {\n\t\tfor (int i = 0; i < set.length && (i == 0 || set[i - 1][pos] == 0L); i++, pos >>>= 6) {\n\t\t    set[i][pos >>> 6] &= ~(1L << pos);\n\t\t}\n\t    }\n\t    return this;\n\t}\n\n\tpublic boolean get(int pos) {\n\t    return pos >= 0 && pos < n && set[0][pos >>> 6] << ~pos < 0;\n\t}\n\n\tpublic LST toggle(int pos) {\n\t    return get(pos) ? unset(pos) : set(pos);\n\t}\n\n\tpublic int prev(int pos) {\n\t    for (int i = 0; i < set.length && pos >= 0; i++, pos >>>= 6, pos--) {\n\t\tint pre = prev(set[i][pos >>> 6], pos & 63);\n\t\tif (pre != -1) {\n\t\t    pos = pos >>> 6 << 6 | pre;\n\t\t    while (i > 0)\n\t\t\tpos = pos << 6 | 63 - Long.numberOfLeadingZeros(set[--i][pos]);\n\t\t    return pos;\n\t\t}\n\t    }\n\t    return -1;\n\t}\n\n\tpublic int next(int pos) {\n\t    for (int i = 0; i < set.length && pos >>> 6 < set[i].length; i++, pos >>>= 6, pos++) {\n\t\tint nex = next(set[i][pos >>> 6], pos & 63);\n\t\tif (nex != -1) {\n\t\t    pos = pos >>> 6 << 6 | nex;\n\t\t    while (i > 0)\n\t\t\tpos = pos << 6 | Long.numberOfTrailingZeros(set[--i][pos]);\n\t\t    return pos;\n\t\t}\n\t    }\n\t    return -1;\n\t}\n\n\tprivate static int prev(long set, int n) {\n\t    long h = set << ~n;\n\t    if (h == 0L)\n\t\treturn -1;\n\t    return -Long.numberOfLeadingZeros(h) + n;\n\t}\n\n\tprivate static int next(long set, int n) {\n\t    long h = set >>> n;\n\t    if (h == 0L)\n\t\treturn -1;\n\t    return Long.numberOfTrailingZeros(h) + n;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t    List<Integer> list = new ArrayList<Integer>();\n\t    for (int pos = next(0); pos != -1; pos = next(pos + 1)) {\n\t\tlist.add(pos);\n\t    }\n\t    return list.toString();\n\t}\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class TaskF {\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 + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = in.nextInt();\n        }\n\n        int[] prefixSum = new int[n + 1];\n        prefixSum[0] = 0;\n        for (int i = 1; i <= n; i++) {\n            prefixSum[i] = prefixSum[i - 1] + a[i];\n        }\n\n        Map<Integer, List<Segment>> sumToSegments = new HashMap<>();\n        for (int i = 1; i <= n; i++) {\n            for (int j = i; j <= n; j++) {\n                int sum = prefixSum[j] - prefixSum[i - 1];\n                sumToSegments\n                        .computeIfAbsent(sum, $ -> new ArrayList<>())\n                        .add(Segment.make(i, j));\n            }\n        }\n\n        List<Segment> bestSegments = null;\n        for (int sum : sumToSegments.keySet()) {\n            List<Segment> segments = sumToSegments.get(sum);\n            int size = segments.size();\n\n            int[] f = new int[size];\n            int[] next = new int[size];\n            boolean[] take = new boolean[size];\n\n            f[size - 1] = 1;\n            next[size - 1] = -1;\n            take[size - 1] = true;\n            int bestStartIndex = size - 1;\n\n            for (int i = size - 2; i >= 0; i--) {\n                int nextIndex;\n\n                if (segments.get(i).q >= segments.get(size - 1).p) {\n                    nextIndex = -1;\n                } else {\n                    int L = i + 1;\n                    int R = size - 1;\n                    while (L < R) {\n                        int M = (L + R) / 2;\n                        if (segments.get(i).q >= segments.get(M).p) { /* intersection */\n                            L = M + 1;\n                        } else {\n                            R = M;\n                        }\n                    }\n                    nextIndex = L;\n                }\n\n                f[i] = 1 + ((nextIndex == -1) ? 0 : f[nextIndex]);\n                next[i] = nextIndex;\n                take[i] = true;\n\n                if (f[i + 1] > f[i]) {\n                    take[i] = false;\n                    f[i] = f[i + 1];\n                    next[i] = i + 1;\n                }\n\n                if (bestStartIndex == -1 || f[i] > f[bestStartIndex]) {\n                    bestStartIndex = i;\n                }\n            }\n\n            // recover segment set\n            List<Segment> maxForSum = new ArrayList<>();\n            int index = bestStartIndex;\n            do {\n                if (take[index]) {\n                    maxForSum.add(segments.get(index));\n                }\n                index = next[index];\n            } while (index != -1);\n\n            if (bestSegments == null || maxForSum.size() > bestSegments.size()) {\n                bestSegments = maxForSum;\n            }\n        }\n\n        System.out.println(bestSegments.size());\n        for (Segment segment : bestSegments) {\n            System.out.printf(\"%s %s%n\", segment.p, segment.q);\n        }\n\n        in.close();\n    }\n\n    private static class Segment {\n        public final int p;\n        public final int q;\n\n        private Segment(int p, int q) {\n            this.p = p;\n            this.q = q;\n        }\n\n        public static Segment make(int p, int q) {\n            return new Segment(p, q);\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/*Author: Satyajeet Singh, Delhi Technological University*/\nimport java.io.*;\nimport java.util.*;\nimport java.text.*; \nimport java.lang.*;\n\npublic class Main {\n/*********************************************Constants******************************************/\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        \n    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    static long mod=(long)1e9+7;\n    static long mod1=998244353;\n    static boolean sieve[];\n    static ArrayList<Integer> primes;\n    static ArrayList<Long> factorial;\n    static HashSet<Integer> graph[];\n/****************************************Solutions Begins*****************************************/\n    public static void main (String[] args) throws Exception {\n        String st[]=br.readLine().split(\" \");\n        int n=Integer.parseInt(st[0]);\n        long input[]=new long[n];\n        st=br.readLine().split(\" \");\n        for(int i=0;i<n;i++){\n            input[i]=Long.parseLong(st[i]);\n        }\n        HashMap<Long,ArrayList<Pair>> map=new HashMap<>();\n        long pref[]=new long[n+1];\n        pref[1]=input[0];\n        for(int i=1;i<n;i++){\n            pref[i+1]=pref[i]+input[i];\n        }\n        for(int i=0;i<n;i++){\n            for(int j=i;j<n;j++){\n                long sum=pref[j+1]-pref[i];\n                if(!map.containsKey(sum)){\n                    ArrayList<Pair> list=new ArrayList<>();\n                    list.add(new Pair(i,j));\n                    map.put(sum,list);\n                }\n                else{\n                    ArrayList<Pair> list=map.get(sum);\n                    list.add(new Pair(i,j));\n                }\n            }\n        }\n        ArrayList<Pair> ans=new ArrayList<>();\n       // debug(map);\n        for(long keys:map.keySet()){\n            ArrayList<Pair> list=map.get(keys);\n            Collections.sort(list,new PairComp());\n            int nn=list.size();\n            for(int j=0;j<=0;j++){\n                ArrayList<Pair> cur=new ArrayList<>();\n                cur.add(list.get(j));\n                int lim=list.get(j).v;\n                int i=j;\n                while(i<nn){\n                    if(list.get(i).u<=lim){\n                        i++;\n                    }\n                    else{\n                        cur.add(list.get(i));\n                        lim=list.get(i).v;\n                        i++;\n                    }\n                }\n                if(ans.size()<cur.size()){\n                    ans=cur;\n                }\n            }\n        }\n        out.println(ans.size());\n        for(Pair p:ans){\n            out.println(++p.u+\" \"+ ++p.v);\n        }\n/****************************************Solutions Ends**************************************************/\n        out.flush();\n        out.close();\n    }\n/****************************************Template Begins************************************************/\n/***************************************Precision Printing**********************************************/\n    static void printPrecision(double d){\n        DecimalFormat ft = new DecimalFormat(\"0.00000000000000000\"); \n        out.println(ft.format(d));\n    }\n/******************************************Graph*********************************************************/\n    static void Makegraph(int n){\n        graph=new HashSet[n];\n        for(int i=0;i<n;i++){\n            graph[i]=new HashSet<>();\n        }\n    }\n    static void addEdge(int a,int b){\n        graph[a].add(b);\n    }    \n/*********************************************PAIR********************************************************/\n    static class PairComp implements Comparator<Pair>{\n        public int compare(Pair p1,Pair p2){\n            if(p1.v>p2.v){\n                return 1;\n            }\n            else if(p1.v<p2.v){\n                return -1;\n            }\n            else{\n                return p1.u-p2.u;\n            }\n        }\n    }\n    static class Pair implements Comparable<Pair> {\n        int u;\n        int v;\n        int index=-1;\n        public Pair(int u, int v) {\n            this.u = u;\n            this.v = v;\n        }\n \n        public int hashCode() {\n            int hu = (int) (u ^ (u >>> 32));\n            int hv = (int) (v ^ (v >>> 32));\n            return 31 * hu + hv;\n        }\n \n        public boolean equals(Object o) {\n            Pair other = (Pair) o;\n            return u == other.u && v == other.v;\n        }\n \n        public int compareTo(Pair other) {\n            if(index!=other.index)\n                return Long.compare(index, other.index);\n            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n        }\n \n        public String toString() {\n            return \"[u=\" + u + \", v=\" + v + \"]\";\n        }\n    }\n\n    static class PairCompL implements Comparator<Pairl>{\n        public int compare(Pairl p1,Pairl p2){\n            if(p1.v>p2.v){\n                return -1;\n            }\n            else if(p1.v<p2.v){\n                return 1;\n            }\n            else{\n                return 0;\n            }\n        }\n    }\n    static class Pairl implements Comparable<Pair> {\n            long u;\n            long v;\n            int index=-1;\n            public Pairl(long u, long v) {\n                this.u = u;\n                this.v = v;\n            }\n    \n            public int hashCode() {\n                int hu = (int) (u ^ (u >>> 32));\n                int hv = (int) (v ^ (v >>> 32));\n                return 31 * hu + hv;\n            }\n    \n            public boolean equals(Object o) {\n                Pair other = (Pair) o;\n                return u == other.u && v == other.v;\n            }\n    \n            public int compareTo(Pair other) {\n                if(index!=other.index)\n                    return Long.compare(index, other.index);\n                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n            }\n    \n            public String toString() {\n                return \"[u=\" + u + \", v=\" + v + \"]\";\n            }\n        }\n/*****************************************DEBUG***********************************************************/\n    public static void debug(Object... o) {\n        System.out.println(Arrays.deepToString(o));\n    }\n/************************************MODULAR EXPONENTIATION***********************************************/\n    static long modulo(long a,long b,long c) {\n        long x=1;\n        long y=a;\n        while(b > 0){\n            if(b%2 == 1){\n                x=(x*y)%c;\n            }\n            y = (y*y)%c; // squaring the base\n            b /= 2;\n        }\n        return  x%c;\n    }\n/********************************************GCD**********************************************************/\n    static long gcd(long x, long y)\n    {\n        if(x==0)\n            return y;\n        if(y==0)\n            return x;\n        long r=0, a, b;\n        a = (x > y) ? x : y; // a is greater number\n        b = (x < y) ? x : y; // b is smaller number\n        r = b;\n        while(a % b != 0)\n        {\n            r = a % b;\n            a = b;\n            b = r;\n        }\n        return r;\n    }\n/******************************************SIEVE**********************************************************/\n    static void sieveMake(int n){\n        sieve=new boolean[n];\n        Arrays.fill(sieve,true);\n        sieve[0]=false;\n        sieve[1]=false;\n        for(int i=2;i*i<n;i++){\n            if(sieve[i]){\n                for(int j=i*i;j<n;j+=i){\n                    sieve[j]=false;\n                }\n            }\n        }\n        primes=new ArrayList<Integer>();\n        for(int i=0;i<n;i++){\n            if(sieve[i]){\n                primes.add(i);\n            }\n        }        \n    }\n/********************************************End***********************************************************/\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.util.HashMap;\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\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        F2BlokiRavnoiSummiUslozhnennayaRedakciya solver = new F2BlokiRavnoiSummiUslozhnennayaRedakciya();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2BlokiRavnoiSummiUslozhnennayaRedakciya {\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] sum = new int[n];\n            int prev = 0;\n            for (int i = 0; i < n; i++) {\n                sum[i] = in.nextInt() + prev;\n                prev = sum[i];\n            }\n\n            HashMap<Integer, List<Pair<Integer, Integer>>> blocks = new HashMap<>();\n\n            int max = 0;\n            int maxS = 0;\n            for (int i = 0; i < n; i++) {\n                for (int h = i; h >= 0; h--) {\n                    int s = sum[i];\n                    if (h > 0) {\n                        s -= sum[h - 1];\n                    }\n                    blocks.putIfAbsent(s, new ArrayList<>());\n                    List<Pair<Integer, Integer>> l = blocks.get(s);\n                    if (l.isEmpty() || l.get(l.size() - 1).sc < h) {\n                        l.add(new Pair<>(h, i));\n                    }\n                    if (l.size() > max) {\n                        max = l.size();\n                        maxS = s;\n                    }\n                }\n            }\n\n            out.println(max);\n            for (int i = 0; i < max; i++) {\n                out.println(String.format(\"%d %d\", blocks.get(maxS).get(i).fs + 1, blocks.get(maxS).get(i).sc + 1));\n            }\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\n    static class Pair<T, K> {\n\n        T fs;\n        K sc;\n\n        public Pair(T fs, K sc) {\n            this.fs = fs;\n            this.sc = sc;\n        }\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.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 *\n * @author Washoum\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        inputClass in = new inputClass(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F2SameSumBlocksHard solver = new F2SameSumBlocksHard();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F2SameSumBlocksHard {\n        public void solve(int testNumber, inputClass sc, PrintWriter out) {\n            int n = sc.nextInt();\n            int[] tab = new int[n];\n            int[] s = new int[n];\n            for (int i = 0; i < n; i++) {\n                tab[i] = sc.nextInt();\n                if (i > 0)\n                    s[i] = s[i - 1] + tab[i];\n                else\n                    s[0] = tab[0];\n            }\n            HashMap<Integer, F2SameSumBlocksHard.Pair> sums = new HashMap<>();\n            F2SameSumBlocksHard.Pair p;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j <= i; j++) {\n                    if (j > 0) {\n                        if (sums.get(s[i] - s[j - 1]) != null) {\n                            if (sums.get(s[i] - s[j - 1]).last < j) {\n                                sums.get(s[i] - s[j - 1]).sum++;\n                                sums.get(s[i] - s[j - 1]).last = i;\n                            }\n                        } else {\n                            p = new F2SameSumBlocksHard.Pair();\n                            p.sum = 1;\n                            p.last = i;\n                            sums.put(s[i] - s[j - 1], p);\n                        }\n                    } else {\n                        if (sums.get(s[i]) != null) {\n                            if (sums.get(s[i]).last < j) {\n                                sums.get(s[i]).sum++;\n                                sums.get(s[i]).last = i;\n                            }\n                        } else {\n                            p = new F2SameSumBlocksHard.Pair();\n                            p.sum = 1;\n                            p.last = i;\n                            sums.put(s[i], p);\n                        }\n                    }\n                }\n            }\n\n            Iterator<Map.Entry<Integer, F2SameSumBlocksHard.Pair>> it = sums.entrySet().iterator();\n            Map.Entry<Integer, F2SameSumBlocksHard.Pair> t;\n            int maxsum = 0;\n            int cnt = 0;\n            while (it.hasNext()) {\n                t = it.next();\n                if (t.getValue().sum > cnt) {\n                    maxsum = t.getKey();\n                    cnt = t.getValue().sum;\n                }\n            }\n\n            out.println(cnt);\n            int start = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = start; j <= i; j++) {\n                    if (j > 0) {\n                        if (s[i] - s[j - 1] == maxsum) {\n                            out.println((j + 1) + \" \" + (i + 1));\n                            start = i + 1;\n                            break;\n                        }\n                    } else {\n                        if (s[i] == maxsum) {\n                            out.println((j + 1) + \" \" + (i + 1));\n                            start = i + 1;\n                            break;\n                        }\n                    }\n                }\n            }\n\n\n        }\n\n        static class Pair {\n            int sum;\n            int last;\n\n        }\n\n    }\n\n    static class inputClass {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public inputClass(InputStream in) {\n\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\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "//package com.example.programming;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\n\npublic class CodeforcesProblems {\n\n\n    static class Pair {\n        public Pair(int key, int val) {\n            this.key = key;\n            this.val = val;\n        }\n        int key;\n        int val;\n    }\n\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        //String[] strings = br.readLine().split(\" \");\n        int n = Integer.parseInt(br.readLine());\n\n        String[] strings = br.readLine().split(\" \");\n        int[] arr = new int[n];\n        for(int i = 0; i<n; i++) {\n            arr[i] = Integer.parseInt(strings[i]);\n        }\n\n\n        HashMap<Integer, ArrayList<Pair>> segments = new HashMap<>();\n        for(int r = 0; r<arr.length; r++) {\n            int sum = 0;\n            for(int l = r; l>=0; l--) {\n                sum += arr[l];\n                ArrayList<Pair> pairs = segments.get(sum);\n                if(pairs == null) {\n                    pairs = new ArrayList<>();\n                    segments.put(sum, pairs);\n                }\n                pairs.add(new Pair(l, r));\n            }\n        }\n\n        int res = 0;\n        ArrayList<Pair> result = new ArrayList<>();\n        for(ArrayList<Pair> pairs: segments.values()) {\n            ArrayList<Pair> temp = new ArrayList<>();\n            int count = 0;\n            int r = -1;\n            for(Pair p : pairs) {\n                if(p.key>r) {\n                    count++;\n                    temp.add(p);\n                    r = p.val;\n                }\n            }\n            if(count>res) {\n                res = count;\n                result = temp;\n            }\n        }\n        System.out.println(res);\n        StringBuilder sb = new StringBuilder();\n        for(Pair p : result){\n            sb.append(p.key+1).append(' ').append(p.val+1).append('\\n');\n        }\n        System.out.print(sb);\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import javax.print.attribute.standard.PrinterMessageFromOperator;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        new Main().run();}\n\n//    int[] h,ne,to,wt;\n//    int ct = 0;\n//    int n;\n//    void graph(int n,int m){\n//        h = new int[n];\n//        Arrays.fill(h,-1);\n////        sccno = new int[n];\n////        dfn = new int[n];\n////        low = new int[n];\n////        iscut = new boolean[n];\n//        ne = new int[2*m];\n//        to = new int[2*m];\n//        wt = new int[2*m];\n//        ct = 0;\n//    }\n//    void add(int u,int v,int w){\n//        to[ct] = v;\n//        ne[ct] = h[u];\n//        wt[ct] = w;\n//        h[u] = ct++;\n//    }\n//\n//    int color[],dfn[],low[],stack[] = new int[1000000],cnt[];\n//    int sccno[];\n//    boolean iscut[];\n//    int time = 0,top = 0;\n//    int scc_cnt = 0;\n//\n//    // \u6709\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n//    void tarjan(int u) {\n//        low[u] = dfn[u]= ++time;\n//        stack[top++] = u;\n//        for(int i=h[u];i!=-1;i=ne[i]) {\n//            int v = to[i];\n//            if(dfn[v]==0) {\n//                tarjan(v);\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//        if(dfn[u]==low[u]) {\n//            sccno[u] = ++scc_cnt;\n//            while(stack[top-1]!=u) {\n//                sccno[stack[top-1]] = scc_cnt;\n//                --top;\n//            }\n//            --top;\n//        }\n//    }\n//\n//    //\u7f29\u70b9, topology sort\n//    int[] h1,to1,ne1;\n//    int ct1 = 0;\n//    void point(){\n//        for(int i=0;i<n;i++) {\n//            if(dfn[i]==0) tarjan(i);//\u6709\u53ef\u80fd\u56fe\u4e0d\u8fde\u901a\uff0c\u6240\u4ee5\u8981\u5faa\u73af\u5224\u65ad\u3002\n//        }\n//        // \u5165\u5ea6\n//        int du[] = new int[scc_cnt+1];\n//        h1 = new int[scc_cnt+1];\n//        Arrays.fill(h1, -1);\n//        to1 = new int[scc_cnt*scc_cnt];\n//        ne1 = new int[scc_cnt*scc_cnt];\n//        // scc_cnt \u4e2a\u70b9\n//\n//        for(int i=1;i<=n;i++) {\n//            for(int j=h[i]; j!=-1; j=ne[j]) {\n//                int y = to[j];\n//                if(sccno[i] != sccno[y]) {\n//                    // add(sccno[i],sccno[y]);  // \u5efa\u65b0\u56fe\n//                    to1[ct1] = sccno[y];\n//                    ne1[ct1] = h[sccno[i]];\n//                    h[sccno[i]] = ct1++;\n//                    du[sccno[y]]++; //\u5b58\u5165\u5ea6\n//                }\n//            }\n//        }\n//\n//        int q[] = new int[100000];\n//        int end = 0;\n//        int st = 0;\n//        for(int i=1;i<=scc_cnt;++i){\n//            if(du[i]==0){\n//                q[end++] = i;\n//            }\n//        }\n//\n//        int dp[] = new int[scc_cnt+1];\n//        while(st<end){\n//            int cur = q[st++];\n//            for(int i=h1[cur];i!=-1;i=ne1[i]){\n//                int y = to[i];\n//                // dp[y] += dp[cur];\n//                if(--du[y]==0){\n//                    q[end++] = y;\n//                }\n//            }\n//        }\n//    }\n//\n//\n//\n//\n//    int fa[];\n//    int faw[];\n//\n//    int dep = -1;\n//    int pt = 0;\n//    void go(int rt,int f,int dd){\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = f;p++;\n//        while(p>0) {\n//            int cur = stk[p - 1];\n//            int fp = fk[p - 1];\n//            int ll = lk[p - 1];\n//            p--;\n//\n//\n//            if (ll > dep) {\n//                dep = ll;\n//                pt = cur;\n//            }\n//            for (int i = h[cur]; i != -1; i = ne[i]) {\n//                int v = to[i];\n//                if (fp == v) continue;\n//\n//                stk[p] = v;\n//                lk[p] = ll + wt[i];\n//                fk[p] = cur;\n//                p++;\n//            }\n//        }\n//    }\n//    int pt1 = -1;\n//    void go1(int rt,int f,int dd){\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = f;p++;\n//        while(p>0) {\n//            int cur = stk[p - 1];\n//            int fp = fk[p - 1];\n//            int ll = lk[p - 1];\n//            p--;\n//\n//\n//            if (ll > dep) {\n//                dep = ll;\n//                pt1 = cur;\n//            }\n//\n//            fa[cur] = fp;\n//            for (int i = h[cur]; i != -1; i = ne[i]) {\n//                int v = to[i];\n//                if (v == fp) continue;\n//                faw[v] = wt[i];\n//                stk[p] = v;\n//                lk[p] = ll + wt[i];\n//                fk[p] = cur;\n//                p++;\n//            }\n//        }\n//    }\n//\n//    int r = 0;\n//    int stk[] = new int[301];\n//    int fk[] = new int[301];\n//    int lk[] = new int[301];\n//    void ddfs(int rt,int t1,int t2,int t3,int l){\n//\n//\n//        int p = 0;\n//        stk[p] = rt;\n//        lk[p] = 0;\n//        fk[p] = t3;p++;\n//        while(p>0){\n//            int cur = stk[p-1];\n//            int fp = fk[p-1];\n//            int ll = lk[p-1];\n//            p--;\n//            r = Math.max(r,ll);\n//            for(int i=h[cur];i!=-1;i=ne[i]){\n//                int v = to[i];\n//                if(v==t1||v==t2||v==fp) continue;\n//                stk[p] = v;\n//                lk[p] = ll+wt[i];\n//                fk[p] = cur;p++;\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    static long mod_pow(long k,long n,long p){\n        long res = 1L;\n        long temp = k;\n        while(n!=0L){\n            if((n&1L)==1L){\n                res = (res*temp)%p;\n            }\n            temp = (temp*temp)%p;\n            n = n>>1L;\n        }\n        return res%p;\n    }\n    int ct = 0;\n    int f[]  =new int[200001];\n    int b[]  =new int[200001];\n    int str[]  =new int[200001];\n\n    void go(int rt,List<Integer> g[]){\n        str[ct] = rt;\n        f[rt] = ct;\n        for(int cd:g[rt]){\n            ct++;\n            go(cd,g);\n        }\n        b[rt] = ct;\n    }\n    int add =0;\n\n    void go(int rt,int sd,int k,List<Integer> g[],int n){\n        if(add>n) {\n            return;\n        }\n\n        Queue<Integer> q =new LinkedList<>();\n        q.offer(rt);\n        for(int i=1;i<=sd;++i){\n            int sz =q.size();\n            if(sz==0) break;\n            int f = (i==1?2:1);\n            while(sz-->0){\n                int cur = q.poll();\n                for(int j=0;j<k-f;++j){\n                    q.offer(add);\n                    g[cur].add(add);add++;\n                    if(add==n+1){\n                        return;\n                    }\n                }\n            }\n        }\n\n\n    }\n\n\n\n    void solve() {\n\n        int n = ni();\n        int s[] = new int[n+1];\n        for(int i=0;i<n;++i){\n            s[i+1] = s[i]  + ni();\n        }\n\n        Map<Integer,List<int[]>> mp = new HashMap<>();\n        for(int i=0;i<n;++i) {\n            for (int j = i; j>=0; --j) {\n                int v = s[i+1]-s[j];\n                if(!mp.containsKey(v)){\n                    mp.put(v, new ArrayList<>());\n                }\n                mp.get(v).add(new int[]{j,i});\n            }\n        }\n        int all = 0;int vv = -1;\n        for(int v:mp.keySet()){\n            List<int[]> r = mp.get(v);\n            int sz = r.size();int c = 0;\n            int ri = -2000000000;\n            for(int j=0;j<sz;++j){\n                if(r.get(j)[0]>ri){\n                    ri = r.get(j)[1];c++;\n                }\n            }\n            if(c>all){\n                all = c;\n                vv = v;\n            }\n        }\n        println(all);\n        List<int[]> r = mp.get(vv);\n        int sz = r.size();int c = 0;\n        int ri = -2000000000;\n        for(int j=0;j<sz;++j){\n            if(r.get(j)[0]>ri){\n                ri = r.get(j)[1];println((1+r.get(j)[0])+\" \"+(1+r.get(j)[1]));\n            }\n        }\n\n\n\n\n\n\n\n        //N , M , K , a , b , c , d . \u5176\u4e2dN , M\u662f\u77e9\u9635\u7684\u884c\u5217\u6570\uff1bK \u662f\u4e0a\u9501\u7684\u623f\u95f4\u6570\u76ee\uff0c(a, b)\u662f\u8d77\u59cb\u4f4d\u7f6e\uff0c(c, d)\u662f\u51fa\u53e3\u4f4d\u7f6e\n\n\n//        int n = ni();\n//        int m = ni();\n//        int k = ni();\n//        int a = ni();\n//        int b = ni();\n//        int c = ni();\n//        int d = ni();\n//\n//\n//        char cc[][] = nm(n,m);\n//        char keys[][] = new char[n][m];\n//\n//        char ky = 'a';\n//        for(int i=0;i<k;++i){\n//            int x = ni();\n//            int y = ni();\n//            keys[x][y] = ky;\n//            ky++;\n//        }\n//        int f1[] = {a,b,0};\n//\n//        int dd[][] = {{0,1},{0,-1},{1,0},{-1,0}};\n//\n//        Queue<int[]> q =  new LinkedList<>();\n//        q.offer(f1);\n//        int ts = 1;\n//\n//        boolean vis[][][] = new boolean[n][m][33];\n//\n//        while(q.size()>0){\n//            int sz = q.size();\n//            while(sz-->0) {\n//                int cur[] = q.poll();\n//                vis[cur[0]][cur[1]][cur[2]] = true;\n//\n//                int x = cur[0];\n//                int y = cur[1];\n//\n//                for (int u[] : dd) {\n//                       int lx = x +  u[0];\n//                       int ly = y +  u[1];\n//                       if (lx >= 0 && ly >= 0 && lx < n && ly < m && (cc[lx][ly] != '#')&&!vis[lx][ly][cur[2]]){\n//                            char ck =cc[lx][ly];\n//                            if(ck=='.'){\n//                                if(lx==c&&ly==d){\n//                                    println(ts); return;\n//                                }\n//                                if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {\n//                                    int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));\n//                                    q.offer(new int[]{lx, ly, cao});\n//                                    vis[lx][ly][cao] = true;\n//                                }else {\n//\n//                                    q.offer(new int[]{lx, ly, cur[2]});\n//                                }\n//\n//                            }else if(ck>='A'&&ck<='Z'){\n//                                int g = 1<<(ck-'A');\n//                                if((g&cur[2])>0){\n//                                    if(lx==c&&ly==d){\n//                                        println(ts); return;\n//                                    }\n//                                    if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {\n//\n//                                        int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));\n//                                        q.offer(new int[]{lx, ly, cao});\n//                                        vis[lx][ly][cao] = true;;\n//                                    }else {\n//\n//                                        q.offer(new int[]{lx, ly, cur[2]});\n//                                    }\n//                                }\n//                            }\n//                       }\n//                }\n//\n//                }\n//            ts++;\n//        }\n//        println(-1);\n\n\n\n\n//        int n = ni();\n//\n//        HashSet<String> st = new HashSet<>();\n//        HashMap<String,Integer> mp = new HashMap<>();\n//\n//\n//        for(int i=0;i<n;++i){\n//            String s  = ns();\n//            int id= 1;\n//            if(mp.containsKey(s)){\n//                int u = mp.get(s);\n//                id = u;\n//\n//            }\n//\n//            if(st.contains(s)) {\n//\n//                while (true) {\n//                    String ts = s + id;\n//                    if (!st.contains(ts)) {\n//                        s = ts;\n//                        break;\n//                    }\n//                    id++;\n//                }\n//                mp.put(s,id+1);\n//            }else{\n//                mp.put(s,1);\n//            }\n//            println(s);\n//            st.add(s);\n//\n//        }\n\n//        int t = ni();\n//\n//        for(int i=0;i<t;++i){\n//            int n = ni();\n//            long w[] = nal(n);\n//\n//            Map<Long,Long> mp = new HashMap<>();\n//            PriorityQueue<long[]> q =new PriorityQueue<>((xx,xy)->{return Long.compare(xx[0],xy[0]);});\n//\n//            for(int j=0;j<n;++j){\n//                q.offer(new long[]{w[j],0});\n//                mp.put(w[j],mp.getOrDefault(w[j],0L)+1L);\n//            }\n//\n//            while(q.size()>=2){\n//                long f[] = q.poll();\n//                long y1 = f[1];\n//                if(y1==0){\n//                    y1 = mp.get(f[0]);\n//                    if(y1==1){\n//                        mp.remove(f[0]);\n//                    }else{\n//                        mp.put(f[0],y1-1);\n//                    }\n//                }\n//                long g[] = q.poll();\n//                long y2 = g[1];\n//                if(y2==0){\n//                    y2 = mp.get(g[0]);\n//                    if(y2==1){\n//                        mp.remove(g[0]);\n//                    }else{\n//                        mp.put(g[0],y2-1);\n//                    }\n//                }\n//                q.offer(new long[]{f[0]+g[0],2L*y1*y2});\n//\n//            }\n//            long r[] = q.poll();\n//            println(r[1]);\n//\n//\n//\n//\n//        }\n        //  int o= 9*8*7*6;\n        //  println(o);\n\n\n//       int t = ni();\n//       for(int i=0;i<t;++i){\n//           long a = nl();\n//           int k  = ni();\n//           if(k==1){\n//               println(a);\n//               continue;\n//           }\n//\n//           int f = (int)(a%10L);\n//           int s = 1;\n//           int j = 0;\n//           for(;j<30;j+=2){\n//               int u = f-j;\n//               if(u<0){\n//                   u = 10+u;\n//               }\n//               s = u*s;\n//               s = s%10;\n//               if(s==k){\n//                   break;\n//               }\n//           }\n//\n//           if(s==k) {\n//               println(a - j - 2);\n//           }else{\n//               println(-1);\n//           }\n//\n//\n//\n//\n//       }\n\n//     int m = ni();\n//     h = new int[n];\n//     to = new int[2*(n-1)];\n//     ne = new int[2*(n-1)];\n//     wt = new int[2*(n-1)];\n//\n//     for(int i=0;i<n-1;++i){\n//         int u = ni()-1;\n//         int v = ni()-1;\n//\n//     }\n        //  long a[] = nal(n);\n\n\n//        int n = ni();\n//        int k = ni();\n//        t1 = new long[200002];\n//\n//        int p[][] = new int[n][3];\n//\n//        for(int i=0;i<n;++i){\n//            p[i][0]  = ni();\n//            p[i][1]  = ni();\n//            p[i][2]  = i+1;\n//        }\n//        Arrays.sort(p, new Comparator<int[]>() {\n//            @Override\n//            public int compare(int[] x, int[] y) {\n//                if(x[1]!=y[1]){\n//                    return Integer.compare(x[1],y[1]);\n//                }\n//                return Integer.compare(y[0], x[0]);\n//            }\n//        });\n//\n//        for(int i=0;i<n;++i){\n//            int ck = p[i][0];\n//\n//        }\n\n\n\n\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 []h,to,ne,wt;\n\n    long t1[];\n    //    long t2[];\n    void update(long[] t,int i,long v){\n        for(;i<t.length;i+=(i&-i)){\n            t[i] += v;\n        }\n    }\n    long get(long[] t,int i){\n        long s = 0;\n        for(;i>0;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<<i)< t.length && s + t[p+(1<<i)] < v){\n                v -= t[p+(1<<i)];\n                p |= 1<<i;\n            }\n        }\n        return p+1;\n    }\n\n\n\n\n\n\n\n\n\n    static class S{\n        int l = 0;\n        int r = 0 ;\n        long le = 0;\n        long ri = 0;\n        long tot = 0;\n        long all = 0;\n\n        public S(int l,int r) {\n            this.l = l;\n            this.r = r;\n        }\n    }\n\n    static S a[];\n    static int[] o;\n\n    static void init(int[] f){\n        o = f;\n        int len = o.length;\n        a = new S[len*4];\n        build(1,0,len-1);\n    }\n\n    static void build(int num,int l,int r){\n        S cur = new S(l,r);\n        if(l==r){\n            a[num] = cur;\n            return;\n        }else{\n            int m = (l+r)>>1;\n            int le = num<<1;\n            int ri = le|1;\n            build(le, l,m);\n            build(ri, m+1,r);\n            a[num] = cur;\n            pushup(num, le, ri);\n        }\n    }\n\n\n\n    //    static int query(int num,int l,int r){\n//\n//        if(a[num].l>=l&&a[num].r<=r){\n//            return a[num].tot;\n//        }else{\n//            int m = (a[num].l+a[num].r)>>1;\n//            int le = num<<1;\n//            int ri = le|1;\n//            pushdown(num, le, ri);\n//            int ma = 1;\n//            int mi = 100000001;\n//            if(l<=m) {\n//                int r1 = query(le, l, r);\n//                ma = ma*r1;\n//\n//            }\n//            if(r>m){\n//                int r2 = query(ri, l, r);\n//                ma = ma*r2;\n//            }\n//            return ma;\n//        }\n//    }\n    static long dd = 10007;\n    static void update(int num,int l,long v){\n        if(a[num].l==a[num].r){\n            a[num].le = v%dd;\n            a[num].ri = v%dd;\n            a[num].all = v%dd;\n            a[num].tot = v%dd;\n        }else{\n            int m = (a[num].l+a[num].r)>>1;\n            int le = num<<1;\n            int ri = le|1;\n            pushdown(num, le, ri);\n            if(l<=m){\n                update(le,l,v);\n            }\n            if(l>m){\n                update(ri,l,v);\n            }\n            pushup(num,le,ri);\n        }\n    }\n\n    static void pushup(int num,int le,int ri){\n        a[num].all = (a[le].all*a[ri].all)%dd;\n        a[num].le = (a[le].le + a[le].all*a[ri].le)%dd;\n        a[num].ri = (a[ri].ri + a[ri].all*a[le].ri)%dd;\n        a[num].tot = (a[le].tot + a[ri].tot + a[le].ri*a[ri].le)%dd;\n\n\n        //a[num].res[1] = Math.min(a[le].res[1],a[ri].res[1]);\n    }\n    static void pushdown(int num,int le,int ri){\n\n    }\n\n\n    int gcd(int a,int b){ return b==0?a: gcd(b,a%b);}\n    InputStream is;PrintWriter out;\n    void run() throws Exception {is = System.in;out = new PrintWriter(System.out);solve();out.flush();}\n    private byte[] inbuf = new byte[2];\n    public int lenbuf = 0, ptrbuf = 0;\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    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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\nimport javafx.util.Pair;\n\npublic class Solve6 {\n\n    public static void main(String[] args) throws IOException {\n        PrintWriter pw = new PrintWriter(System.out);\n        new Solve6().solve(pw);\n        pw.flush();\n        pw.close();\n    }\n\n    public void solve(PrintWriter pw) throws IOException {\n        FastReader sc = new FastReader();\n        int n = sc.nextInt();\n        int[] a = new int[n + 1];\n        for (int i = 1; i <= n; i++) {\n            a[i] = sc.nextInt();\n        }\n        HashMap<Integer, LinkedList<Pair<Integer, Integer>>> h = new HashMap();\n        for (int i = 1; i <= n; i++) {\n            int s = 0;\n            for (int j = i; j >= 1; j--) {\n                s += a[j];\n                LinkedList<Pair<Integer, Integer>> l;\n                if (!h.containsKey(s)) {\n                    l = new LinkedList();\n                } else {\n                    l = h.get(s);\n                }\n                l.add(new Pair(j, i));\n                h.put(s, l);\n            }\n        }\n        LinkedList<Pair<Integer, Integer>>[] l = new LinkedList[h.size() + 1];\n        for (int i = 1; i <= h.size(); i++) {\n            l[i] = new LinkedList();\n        }\n        int k = 0, max = 0, index = 0;\n        for (LinkedList<Pair<Integer, Integer>> temp : h.values()) {\n            k++;\n            int i = 0, size = 0;\n            for (Pair<Integer, Integer> pair : temp) {\n                if (pair.getKey() > i) {\n                    i = pair.getValue();\n                    l[k].add(pair);\n                    size++;\n                    if (size > max) {\n                        max = size;\n                        index = k;\n                    }\n                }\n            }\n        }\n        pw.println(l[index].size());\n        for (Pair<Integer, Integer> pair : l[index]) {\n            pw.println(pair.getKey() + \" \" + pair.getValue());\n        }\n    }\n\n    static class FastReader {\n\n        StringTokenizer st;\n        BufferedReader br;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public boolean hasNext() throws IOException {\n            String s = br.readLine();\n            if (s == null || s.isEmpty()) {\n                return false;\n            }\n            st = new StringTokenizer(s);\n            return true;\n        }\n\n        public String next() throws IOException {\n            if (st == null || !st.hasMoreTokens()) {\n                String s = br.readLine();\n                if (s.isEmpty()) {\n                    return null;\n                }\n                st = new StringTokenizer(s);\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        public double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        public String nextLine() throws IOException {\n            return br.readLine();\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/*\n    Author: Anthony Ngene\n    Created: 05/10/2020 - 14:12\n*/\n\nimport java.io.*;\nimport java.util.*;\n\npublic class F {\n// checks: 1. edge cases   2. overflow   3. possible errors (e.g 1/0, arr[out])   4. time/space complexity\n    void solver() throws IOException {\n        int n = in.intNext();\n        int[] arr = in.nextIntArray(n);\n        HashMap<Integer, Deque<Tuple>> subSum = new HashMap<>();\n\n        Integer best = null;\n        for (int i = 0; i < n; i++) {\n            int total = 0;\n            for (int j = i; j < n; j++) {\n                total += arr[j];\n                if (!subSum.containsKey(total)) subSum.put(total, new ArrayDeque<>());\n                Deque<Tuple> rs = subSum.get(total);\n                if (rs.size() > 0 && rs.peekLast().b > j) rs.pollLast();\n                if (rs.size() == 0 || rs.peekLast().b < i)\n                    rs.add(new Tuple(i, j));\n                if (best == null || rs.size() > subSum.get(best).size())\n                    best = total;\n            }\n        }\n        Deque<Tuple> bestList = subSum.get(best);\n        out.println(bestList.size());\n        for (Tuple aa: bestList)\n            out.pp(aa.a + 1, aa.b + 1);\n\n    }\n\n\n// Generated Code Below:\nprivate static final FastWriter out = new FastWriter();\nprivate static FastScanner in;\nstatic ArrayList<Integer>[] adj;\nprivate static long e97 = (long)1e9 + 7;\npublic static void main(String[] args) throws IOException {\n    in = new FastScanner();\n    new F().solver();\n    out.close();\n}\n\nstatic class FastWriter {\n    private static final int IO_BUFFERS = 128 * 1024;\n    private final StringBuilder out;\n    public FastWriter() { out = new StringBuilder(IO_BUFFERS); }\n    public FastWriter p(Object object) { out.append(object); return this; }\n    public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }\n    public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(\" \");  } out.append(\"\\n\"); return this; }\n    public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(\" \");  } out.append(\"\\n\"); return this; }\n    public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(\" \");  } out.append(\"\\n\"); return this; }\n    public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(\" \");  } out.append(\"\\n\"); return this; }\n    public void println(long[] arr) { for(long e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n    public void println(int[] arr) { for(int e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n    public void println(char[] arr) { for(char e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n    public void println(double[] arr) { for(double e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n    public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n    public <T>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 <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n    public FastWriter println(Object object) { out.append(object).append(\"\\n\"); return this; }\n    public void toFile(String fileName) throws IOException {\n        BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));\n        writer.write(out.toString());\n        writer.close();\n    }\n    public void close() throws IOException { System.out.print(out); }\n}\nstatic class FastScanner {\n    private InputStream sin = System.in;\n    private final byte[] buffer = new byte[1024];\n    private int ptr = 0;\n    private int buflen = 0;\n    public FastScanner(){}\n    public FastScanner(String filename) throws FileNotFoundException {\n        File file = new File(filename);\n        sin = new FileInputStream(file);\n    }\n    private boolean hasNextByte() {\n        if (ptr < buflen) {\n            return true;\n        }else{\n            ptr = 0;\n            try {\n                buflen = sin.read(buffer);\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            if (buflen <= 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}\n    public String next() {\n        if (!hasNext()) throw new NoSuchElementException();\n        StringBuilder sb = new StringBuilder();\n        int b = readByte();\n        while(isPrintableChar(b)) {\n            sb.appendCodePoint(b);\n            b = readByte();\n        }\n        return sb.toString();\n    }\n    public long longNext() {\n        if (!hasNext()) throw new NoSuchElementException();\n        long n = 0;\n        boolean minus = false;\n        int b = readByte();\n        if (b == '-') {\n            minus = true;\n            b = readByte();\n        }\n        if (b < '0' || '9' < b) {\n            throw new NumberFormatException();\n        }\n        while(true){\n            if ('0' <= b && b <= '9') {\n                n *= 10;\n                n += b - '0';\n            }else if(b == -1 || !isPrintableChar(b) || b == ':'){\n                return minus ? -n : n;\n            }else{\n                throw new NumberFormatException();\n            }\n            b = readByte();\n        }\n    }\n    public int intNext() {\n        long nl = longNext();\n        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\n        return (int) nl;\n    }\n    public double doubleNext() { return Double.parseDouble(next());}\n    public long[] nextLongArray(final int n){\n        final long[] a = new long[n];\n        for (int i = 0; i < n; i++)\n            a[i] = longNext();\n        return a;\n    }\n    public int[] nextIntArray(final int n){\n        final int[] a = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = intNext();\n        return a;\n    }\n    public double[] nextDoubleArray(final int n){\n        final double[] a = new double[n];\n        for (int i = 0; i < n; i++)\n            a[i] = doubleNext();\n        return a;\n    }\n    public ArrayList<Integer>[] getAdj(int n) {\n        ArrayList<Integer>[] adj = new ArrayList[n + 1];\n        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();\n        return adj;\n    }\n    public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {\n        return adjacencyList(nodes, edges, false);\n    }\n    public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {\n        adj = getAdj(nodes);\n        for (int i = 0; i < edges; i++) {\n            int a = intNext(), b = intNext();\n            adj[a].add(b);\n            if (!isDirected) adj[b].add(a);\n        }\n        return adj;\n    }\n}\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<Long> 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<Long> 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> 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 <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }\n    private static void customSort(int[][] arr) {\n        Arrays.sort(arr, new Comparator<int[]>() {\n            public int compare(int[] a, int[] b) {\n                if (a[0] == b[0]) return Integer.compare(a[1], b[1]);\n                return Integer.compare(a[0], b[0]);\n            }\n        });\n    }\n    public static int[] swap(int[] arr, int left, int right) {\n        int temp = arr[left];\n        arr[left] = arr[right];\n        arr[right] = temp;\n        return arr;\n    }\n    public static char[] swap(char[] arr, int left, int right) {\n        char temp = arr[left];\n        arr[left] = arr[right];\n        arr[right] = temp;\n        return arr;\n    }\n    public static int[] reverse(int[] arr, int left, int right) {\n        while (left < right) {\n            int temp = arr[left];\n            arr[left++] = arr[right];\n            arr[right--] = temp;\n        }\n        return arr;\n    }\n    public static boolean findNextPermutation(int[] data) {\n        if (data.length <= 1) return false;\n        int last = data.length - 2;\n        while (last >= 0) {\n            if (data[last] < data[last + 1]) break;\n            last--;\n        }\n        if (last < 0) return false;\n        int nextGreater = data.length - 1;\n        for (int i = data.length - 1; i > last; i--) {\n            if (data[i] > data[last]) {\n                nextGreater = i;\n                break;\n            }\n        }\n        data = swap(data, nextGreater, last);\n        data = reverse(data, last + 1, data.length - 1);\n        return true;\n    }\n    public static int biSearch(int[] dt, int target){\n        int left=0, right=dt.length-1;\n        int mid=-1;\n        while(left<=right){\n            mid = (right+left)/2;\n            if(dt[mid] == target) return mid;\n            if(dt[mid] < target) left=mid+1;\n            else right=mid-1;\n        }\n        return -1;\n    }\n    public static int biSearchMax(long[] dt, long target){\n        int left=-1, right=dt.length;\n        int mid=-1;\n\n        while((right-left)>1){\n            mid = left + (right-left)/2;\n            if(dt[mid] <= target) left=mid;\n            else right=mid;\n        }\n        return left;\n    }\n    public static int biSearchMaxAL(ArrayList<Integer> 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 <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}\n    private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}\n    private static void fill(int[][] ob, int res){      for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}\n    private static void fill(long[][] ob, long res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}\n    private static void fill(char[][] ob, char res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}\n    private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}\n    private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}\n    private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}\n    private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}\n    private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; }\n    private static boolean same3(long a, long b, long c){\n        if(a!=b) return false;\n        if(b!=c) return false;\n        if(c!=a) return false;\n        return true;\n    }\n    private static boolean dif3(long a, long b, long c){\n        if(a==b) return false;\n        if(b==c) return false;\n        if(c==a) return false;\n        return true;\n    }\n    private static double hypotenuse(double a, double b){\n        return Math.sqrt(a*a+b*b);\n    }\n    private static long factorial(int n) {\n        long ans=1;\n        for(long i=n; i>0; 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<<d;  }\n        return d;\n    }\n    private static int getDigit10(long num){\n        long cf = 1;    int d=0;\n        while(num >= 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<Integer> generatePrimes(int n) {\n        int[] lp = new int[n + 1];\n        ArrayList<Integer> pr = new ArrayList<>();\n        for (int i = 2; i <= n; ++i) {\n            if (lp[i] == 0) {\n                lp[i] = i;\n                pr.add(i);\n            }\n            for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {\n                lp[i * pr.get(j)] = pr.get(j);\n            }\n        }\n        return pr;\n    }\n    static long nPrMod(int n, int r, long MOD) {\n        long res = 1;\n        for (int i = (n - r + 1); i <= n; i++) {\n            res = (res * i) % MOD;\n        }\n        return res;\n    }\n    static long nCr(int n, int r) {\n        if (r > (n - r))\n            r = n - r;\n        long ans = 1;\n        for (int i = 1; i <= r; i++) {\n            ans *= n;\n            ans /= i;\n            n--;\n        }\n        return ans;\n    }\n    static long nCrMod(int n, int r, long MOD) {\n        long rFactorial = nPrMod(r, r, MOD);\n        long first = nPrMod(n, r, MOD);\n        long second = binpowMod(rFactorial, MOD-2, MOD);\n        return  (first * second) % MOD;\n    }\n    static void printBitRepr(int n) {\n        StringBuilder res = new StringBuilder();\n        for (int i = 0; i < 32; i++) {\n            int mask = (1 << i);\n            res.append((mask & n) == 0 ? \"0\" : \"1\");\n        }\n        out.println(res);\n    }\n    static String bitString(int n) {return Integer.toBinaryString(n);}\n    static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed\n    static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }\n    static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }\n    static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }\n    static HashMap<Character, Integer> counts(String word) {\n        HashMap<Character, Integer> 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<Integer, Integer> counts(int[] arr) {\n        HashMap<Integer, Integer> counts = new HashMap<>();\n        for (int value : arr) counts.merge(value, 1, Integer::sum);\n        return counts;\n    }\n    static HashMap<Long, Integer> counts(long[] arr) {\n        HashMap<Long, Integer> counts = new HashMap<>();\n        for (long l : arr) counts.merge(l, 1, Integer::sum);\n        return counts;\n    }\n    static HashMap<Character, Integer> counts(char[] arr) {\n        HashMap<Character, Integer> counts = new HashMap<>();\n        for (char c : arr) counts.merge(c, 1, Integer::sum);\n        return counts;\n    }\n    static long hash(int x, int y) {\n        return x* 1_000_000_000L +y;\n    }\n    static final Random random = new Random();\n    static void sort(int[] a) {\n        int n = a.length;// shuffle, then sort\n        for (int i = 0; i < n; i++) {\n            int oi = random.nextInt(n), temp = a[oi];\n            a[oi] = a[i];\n            a[i] = temp;\n        }\n        Arrays.sort(a);\n    }\n    static void sort(long[] arr) {\n        shuffleArray(arr);\n        Arrays.sort(arr);\n    }\n    static void shuffleArray(long[] arr) {\n        int n = arr.length;\n        for(int i=0; i<n; ++i){\n            long tmp = arr[i];\n            int randomPos = i + random.nextInt(n-i);\n            arr[i] = arr[randomPos];\n            arr[randomPos] = tmp;\n        }\n    }\n}\nstatic class Tuple implements Comparable<Tuple> {\n    int a;\n    int b;\n    int c;\n    public Tuple(int a, int b) {\n        this.a = a;\n        this.b = b;\n        this.c = 0;\n    }\n    public Tuple(int a, int b, int c) {\n        this.a = a;\n        this.b = b;\n        this.c = c;\n    }\n    public int getA() { return a; }\n    public int getB() { return b; }\n    public int getC() { return c; }\n    public int compareTo(Tuple other) {\n        if (this.a == other.a) {\n            if (this.b == other.b) return Long.compare(this.c, other.c);\n            return Long.compare(this.b, other.b);\n        }\n        return Long.compare(this.a, other.a);\n    }\n    @Override\n    public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }\n    @Override\n    public boolean equals(Object o) {\n        if (!(o instanceof Tuple)) return false;\n        Tuple pairo = (Tuple) o;\n        return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);\n    }\n    @Override\n    public String toString() { return String.format(\"(%d %d %d)  \", this.a, this.b, this.c); }\n}\nprivate static int abs(int a){  return (a>=0) ? a: -a;  }\nprivate static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }\nprivate static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[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<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }\nprivate static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[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<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }\nprivate static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[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", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\n\npublic class CF1141F {\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\tString[] split = br.readLine().split(\" \");\n\t\tint[] terms = new int[n];\n\t\tint[] sums = new int[n+1];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tterms[i] = Integer.parseInt(split[i]);\n\t\t\tsums[i+1] = sums[i]+terms[i];\n\t\t}\n\t\tArrayList<Block> blocks = new ArrayList<>();\n\t\tfor(int i=0; i<n; i++)\n\t\t\tfor(int j=i; j<n; j++){\n\t\t\t\tint s = sums[j+1]-sums[i];\n\t\t\t\tblocks.add(new Block(i, j, s));\n\t\t\t}\n\t\tCollections.sort(blocks);\n\t\tArrayList<Block> best = new ArrayList<>();\n\t\tint i = 0;\n\t\twhile(i<blocks.size()){\n\t\t\tint curSum = blocks.get(i).sum;\n\t\t\tArrayList<Block> curBlocks = new ArrayList<>();\n\t\t\twhile(i<blocks.size() && blocks.get(i).sum==curSum) curBlocks.add(blocks.get(i++));\n\t\t\tint[] memo = new int[curBlocks.size()+1];\n\t\t\tArrays.fill(memo, -1);\n\t\t\tmemo[curBlocks.size()] = 0;\n\t\t\tfor(int j=curBlocks.size()-1; j>=0; j--){\n\t\t\t\tint idx = Collections.binarySearch(curBlocks, new Block(curBlocks.get(j).r+1, curBlocks.get(j).r+1, curBlocks.get(j).sum));\n\t\t\t\tif(idx<0) idx = -(idx+1);\n\t\t\t\tmemo[j] = Math.max(memo[j+1], 1+memo[idx]);\n\t\t\t}\n\t\t\tif(memo[0]>best.size()){\n\t\t\t\tbest = new ArrayList<>();\n\t\t\t\tint idx = 0;\n\t\t\t\twhile(memo[idx]>=1){\n\t\t\t\t\tif(memo[idx]>memo[idx+1]) best.add(curBlocks.get(idx));\n\t\t\t\t\tidx++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tsb.append(best.size()).append(\"\\n\");\n\t\tfor(Block b : best){\n\t\t\tsb.append(b.l+1).append(\" \").append(b.r+1).append(\"\\n\");\n\t\t}\n\t\tSystem.out.print(sb);\n\t}\n\t\n\tstatic class Block implements Comparable<Block>{\n\t\tint l, r, sum;\n\t\t\n\t\tBlock(int a, int b, int c){\n\t\t\tl = a;\n\t\t\tr = b;\n\t\t\tsum = c;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Block o) {\n\t\t\tif(sum==o.sum){\n\t\t\t\tif(l==o.l) return r-o.r;\n\t\t\t\treturn l-o.l;\n\t\t\t}\n\t\t\treturn sum-o.sum;\n\t\t}\n\t}\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\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        SameSumBlocks solver = new SameSumBlocks();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class SameSumBlocks {\n        int N;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            N = in.nextInt();\n            int[] arr = new int[N];\n            for (int i = 1; i <= N; i++) {\n                arr[i - 1] = in.nextInt();\n            }\n            HashMap<Integer, ArrayList<Segment>> map = new HashMap<>();\n            for (int i = 1; i <= N; i++) {\n                int sum = 0;\n                for (int j = i; j <= N; j++) {\n                    sum += arr[j - 1];\n                    map.putIfAbsent(sum, new ArrayList<>());\n                    map.get(sum).add(new Segment(i, j));\n                }\n            }\n            int resI = 0;\n            int resVal = 0;\n            int sum = 0;\n            if (arr.length > 1 && arr[1] == -999) {\n                for (int i = 11; i < 130; i++) {\n                    sum += arr[i];\n                }\n            }\n            for (int key : map.keySet()) {\n                if (map.get(key).size() > resI) {\n                    int next = largestNon(map.get(key));\n                    if (next > resI) {\n                        resVal = key;\n                        resI = next;\n                    }\n                }\n            }\n            Pair res = largestNonOverlap(map.get(resVal));\n            out.println(resI);\n            for (int i = 0; i < resI; i++) {\n                out.println(res.used.get(i).li + \" \" + res.used.get(i).ri);\n            }\n        }\n\n        int largestNon(ArrayList<Segment> arr) {\n            Collections.sort(arr, new Comparator<Segment>() {\n\n                public int compare(Segment o1, Segment o2) {\n                    return Integer.compare(o1.ri, o2.ri);\n                }\n            });\n            SameSumBlocks.SegmentTree seg = new SameSumBlocks.SegmentTree(N + 1);\n            for (int i = 0; i < arr.size(); i++) {\n                seg.add(arr.get(i).ri, arr.get(i).ri, 1 + seg.query(0, arr.get(i).li - 1).mx);\n            }\n            return seg.query(0, N).mx;\n        }\n\n        Pair largestNonOverlap(ArrayList<Segment> arr) {\n            Segment[] segs = new Segment[N + 1];\n            int[] dp = new int[N + 1];\n            for (int i = 0; i <= N; i++) {\n                segs[i] = new Segment(-1, 0);\n            }\n            for (Segment s : arr) {\n                if (s.li > segs[s.ri].li) {\n                    segs[s.ri] = s;\n                }\n            }\n            int[] used = new int[N + 1];\n            for (int i = 1; i <= N; i++) {\n                dp[i] = dp[i - 1];\n                used[i] = used[i - 1];\n                if (segs[i].li != -1) {\n                    if (dp[i] < dp[segs[i].li - 1] + 1) {\n                        used[i] = i;\n                        dp[i] = dp[segs[i].li - 1] + 1;\n                    }\n                }\n            }\n            ArrayList<Segment> res = new ArrayList<>();\n            int u = used[N];\n            while (segs[u].li > 0) {\n                res.add(segs[u]);\n                u = used[segs[u].li - 1];\n            }\n            return new Pair(dp[N], res);\n        }\n\n        class Segment {\n            int li;\n            int ri;\n\n            Segment() {\n            }\n\n            Segment(int li, int ri) {\n                this.li = li;\n                this.ri = ri;\n            }\n\n        }\n\n        class Pair {\n            int val;\n            ArrayList<Segment> used = new ArrayList<>();\n\n            Pair(int val, ArrayList<Segment> used) {\n                this.val = val;\n                this.used = used;\n            }\n\n        }\n\n        static class SegmentTree {\n            Node[] tree;\n            int size = 0;\n\n            public Node none() {\n                //return a node that will do nothing while merging: ex. Infinity for min query, -Infinity for max query, 0 for sum\n                Node res = new Node();\n                return res;\n            }\n\n            public SegmentTree(int N) {\n                tree = new Node[4 * N];\n                size = N;\n                for (int i = 0; i < 4 * N; i++) {\n                    tree[i] = new Node();\n                }\n            }\n\n            Node combine(Node a, Node b) {\n                //change when doing different operations\n                Node res = new Node();\n                res.mx = Math.max(a.mx, b.mx);\n                return res;\n            }\n\n            public Node query(int l, int r) {\n                return queryUtil(1, 0, size - 1, l, r);\n            }\n\n            public Node queryUtil(int n, int tl, int tr, int l, int r) {\n                //node number, cur range of node, cur range of query\n                if (l > r) {\n                    return none();\n                }\n                if (tl == l && tr == r) {\n                    return tree[n];\n                }\n                int tm = (tl + tr) / 2;\n                return combine(queryUtil(2 * n, tl, tm, l, Math.min(r, tm)), queryUtil(2 * n + 1, tm + 1, tr, Math.max(tm + 1, l), r));\n            }\n\n            public void add(int l, int r, int val) {\n                //change query, not assignment\n                addUtil(1, 0, size - 1, l, r, val);\n            }\n\n            public void addUtil(int n, int tl, int tr, int l, int r, int val) {\n                if (l > r) {\n                    return;\n                }\n                if (tl == l && tr == r) {\n                    tree[n].update(val);\n                } else {\n                    int tm = (tl + tr) / 2;\n                    addUtil(2 * n, tl, tm, l, Math.min(tm, r), val);\n                    addUtil(2 * n + 1, tm + 1, tr, Math.max(l, tm + 1), r, val);\n                    tree[n] = combine(tree[2 * n], tree[2 * n + 1]);\n                }\n            }\n\n            class Node {\n                int mx = 0;\n                int lzy = 0;\n\n                void update(int val) {\n                    mx = Math.max(mx, val);\n                    lzy += val;\n                }\n\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner s=new Scanner(System.in);\n\t\t\n\t\tint n=s.nextInt();\n\t\t\n\t\tlong[] arr=new long[n];\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tarr[i]=s.nextInt();\n\t\t}\n\t\t\n\t\tlong[] pre=new long[n];\n\t\t\n\t\tpre[0]=arr[0];\n\t\t\n\t\tfor(int i=1;i<n;i++)\n\t\t{\n\t\t\tpre[i]=pre[i-1]+arr[i];\n\t\t}\n\t\t\n\t\tHashMap<Long,ArrayList<pair>> map=new HashMap<>();\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int j=i;j<n;j++)\n\t\t\t{\n\t\t\t\tlong key=pre[j]-pre[i]+arr[i];\n\t\t\t\t\n\t\t\t\tif(map.containsKey(key))\n\t\t\t\t{\n\t\t\t\t\tpair p=new pair(i+1,j+1);\n\t\t\t\t\tArrayList<pair> temp=map.get(key);\n\t\t\t\t\ttemp.add(p);\n\t\t\t\t\t\n\t\t\t\t\tmap.put(key,temp);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tArrayList<pair> list=new ArrayList<>();\n\t\t\t\t\tpair p=new pair(i+1,j+1);\n\t\t\t\t\tlist.add(p);\n\t\t\t\t\t\n\t\t\t\t\tmap.put(key,list);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(Map.Entry<Long,ArrayList<pair>> entry:map.entrySet())\n\t\t{\n\t\t\tArrayList<pair> curr=entry.getValue();\n\t\t\t\n\t\t\tCollections.sort(curr,new comp());\n\t\t}\n\t\t\n\t\tlong ans=0;\n\t\tlong max=-1000000000000l;\n\t\t\n\t\tfor(Map.Entry<Long,ArrayList<pair>> entry:map.entrySet())\n\t\t{\n\t\t\tArrayList<pair> curr=entry.getValue();\n\t\t\t\n\t\t\tint count=1;\n\t\t\tint l=curr.get(0).l;\n\t\t\tint r=curr.get(0).r;\n\t\t\t\n\t\t\tfor(int i=1;i<curr.size();i++)\n\t\t\t{\n\t\t\t\tif(curr.get(i).l>r)\n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t\t\tl=curr.get(i).l;\n\t\t\t\t\tr=curr.get(i).r;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(count>max)\n\t\t\t{\n\t\t\t\tmax=count;\n\t\t\t\tans=entry.getKey();\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(max);\n\t\t\n\t\tArrayList<pair> list=map.get(ans);\n\t\t\n\t\tSystem.out.println(list.get(0).l+\" \"+list.get(0).r);\n\t\t\n\t\tint l=list.get(0).l;\n\t\tint r=list.get(0).r;\n\t\t\n\t\tfor(int i=1;i<list.size();i++)\n\t\t{\n\t\t\tif(list.get(i).l>r)\n\t\t\t{\n\t\t\t\tSystem.out.println(list.get(i).l+\" \"+list.get(i).r);\n\t\t\t\tl=list.get(i).l;\n\t\t\t\tr=list.get(i).r;\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n}\n\nclass pair\n{\n\tint l;\n\tint r;\n\t\n\tpublic pair(int l,int r)\n\t{\n\t\tthis.l=l;\n\t\tthis.r=r;\n\t}\n}\n\nclass comp implements Comparator<pair>\n{\n\tpublic int compare(pair a,pair b)\n\t{\n\t\tif(a.r<b.r)\n\t\t\treturn -1;\n\t\telse if(a.r==b.r)\n\t\t{\n\t\t\treturn b.l-a.l;\n\t\t}\n\t\telse\n\t\t\treturn 1;\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n \n/* spar5h */\n \npublic class cf1 implements Runnable {   \n\t\n\tstatic void addMap(int curr, HashMap<Integer, Integer> map, HashMap<Integer, Integer>[] hm, int j) {\n\t\t\n\t\tint prev = 0;\n\t\t\n\t\tif(map.get(curr) != null)\n\t\t\tprev = map.get(curr);\n\t\t\n\t\tint val = 0;\n\t\t\n\t\tif(hm[j].get(curr) != null)\n\t\t\tval = hm[j].get(curr);\n\t\t\n\t\tif(prev + 1 <= val)\n\t\t\treturn;\n\t\t\n\t\thm[j].put(curr, prev + 1);\n\t}\n\t\n\tpublic void run() {\n\t\t\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\n\t\tint n = s.nextInt();\n\t\t\n\t\tint[] a = new int[n];\n\t\t\n\t\tHashMap<Integer, Integer>[] hm = new HashMap[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ta[i] = s.nextInt();\n\t\t\thm[i] = new HashMap<Integer, Integer>();\n\t\t}\n\t\t\n\t\tHashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tint curr = 0;\n\t\t\t\n\t\t\tfor(int j = i; j < n; j++) {\n\t\t\t\tcurr += a[j];\n\t\t\t\taddMap(curr, map, hm, j);\n\t\t\t}\n\t\t\t\n\t\t\tfor(Map.Entry<Integer, Integer> e : hm[i].entrySet()) {\n\t\t\t\t\n\t\t\t\tif(map.get(e.getKey()) != null && map.get(e.getKey()) >= e.getValue())\n\t\t\t\t\tcontinue;\n\t\t\t\t\n\t\t\t\tmap.put(e.getKey(), e.getValue());\n\t\t\t}\n\t\t}\n\t\t\n\t\tint key = -1;\n\t\tint value = 0;\n\t\t\n\t\tfor(Map.Entry<Integer, Integer> e : map.entrySet()) {\n\t\t\t\n\t\t\tif(e.getValue() > value) {\n\t\t\t\tkey = e.getKey(); value = e.getValue();\n\t\t\t}\n\t\t}\n\t\t\n\t\tw.println(value);\n\t\t\n\t\tint prev = -1;\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tint curr = 0;\n\t\t\t\n\t\t\tfor(int j = i; j > prev; j--) {\n\t\t\t\t\n\t\t\t\tcurr += a[j];\n\t\t\t\t\n\t\t\t\tif(curr == key) {\n\t\t\t\t\tw.println((j + 1) + \" \" + (i + 1));\n\t\t\t\t\tprev = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\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\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read() {\n\t\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\t\n\t\t\t\tcurChar = 0;\n\t\t\t\t\n\t\t\t\ttry {\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\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\t\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\t \n\t\tpublic String nextLine() {\n\t\t\t\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n\t        \n\t\t\ttry {\n\t            str = br.readLine();\n\t        }\n\t        catch (IOException e) {\n\t            e.printStackTrace();\n\t        }\n\t\t\t\n\t        return str;\n\t\t}\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\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\t\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}\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\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\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tlong res = 0;\n\t\t\t\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}\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\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\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tdouble res = 0;\n\t\t\t\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\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\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\t\n\t\t\tif (c == '.') {\n\t\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\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() {\n\t\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\tStringBuilder res = new StringBuilder();\n\t\t\t\n\t\t\tdo {\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\t\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 \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 \n\tpublic static void main(String args[]) throws Exception {\n\t\tnew Thread(null, new cf1(),\"cf1\",1<<26).start();\n\t}\n} ", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastScanner in = new FastScanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F solver = new F();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.ni();\n            int[] a = in.na(n);\n            TreeMap<Integer, TreeMap<Integer, Segment>> map = new TreeMap<>();\n            int[] pref = new int[n + 1];\n            for (int i = 0; i < n; i++) {\n                pref[i + 1] = pref[i] + a[i];\n            }\n\n            for (int i = 0; i < n; i++) {\n                for (int j = i; j >= 0; j--) {\n                    int val = pref[i + 1] - pref[j];\n                    TreeMap<Integer, Segment> dp = map.computeIfAbsent(val, k -> new TreeMap<>());\n                    if (!dp.containsKey(i)) {\n\n                        Map.Entry<Integer, Segment> lastEntry = dp.lastEntry();\n                        if (lastEntry == null) {\n                            dp.put(i, new Segment(j, i, 1, null));\n                        } else {\n                            Segment lastValue = lastEntry.getValue();\n                            Map.Entry<Integer, Segment> prev = dp.lowerEntry(j);\n                            if (prev == null) {\n                                if (lastValue.dp >= 1)\n                                    dp.put(i, lastValue);\n                                else\n                                    dp.put(i, new Segment(j, i, 1, null));\n                            } else if (lastValue.dp >= prev.getValue().dp + 1) {\n                                dp.put(i, lastValue);\n                            } else {\n                                dp.put(i, new Segment(j, i, prev.getValue().dp + 1, prev.getValue()));\n                            }\n                        }\n                    }\n                }\n            }\n            Segment best = null;\n            for (TreeMap<Integer, Segment> segments : map.values()) {\n                Segment seg = segments.lastEntry().getValue();\n                if (best == null || best.dp < seg.dp) {\n                    best = seg;\n                }\n            }\n            if (best == null)\n                throw new RuntimeException(\"Null best\");\n            out.println(best.dp);\n            while (best != null) {\n                out.printf(\"%d %d%n\", best.from + 1, best.to + 1);\n                best = best.prev;\n            }\n        }\n\n        class Segment {\n            int from;\n            int to;\n            int dp;\n            Segment prev;\n\n            public Segment(int from, int to, int dp, Segment prev) {\n                this.from = from;\n                this.to = to;\n                this.dp = dp;\n                this.prev = prev;\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 ns() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(ns());\n        }\n\n        public 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    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n    static class Node implements Comparable<Node>{\n        public int l,r;\n        public long s;\n        Node(int l,int r,long s){\n            this.l=l;\n            this.r=r;\n            this.s=s;\n        }\n        public int compareTo(Node o) {\n            if(o.s==s){\n                if(r>o.r) return 1;\n                else if(r==o.r) {\n                    return 0;\n                }\n                else return -1;\n            } else if(s>o.s){\n                return 1;\n            } else {\n                return -1;\n            }\n        }\n    }\n    static long[] sum=new long[1550];\n    public static void main(String[] args) {\n        TreeMap<Long, ArrayList<Node> > mp = new TreeMap<>();\n        Scanner cin = new Scanner(System.in);\n        int N=cin.nextInt();\n        for(int i=1;i<=N;i++){\n            int x=cin.nextInt();\n            sum[i]=sum[i-1]+x;\n        }\n        //System.out.println(\"here\");\n        ArrayList<Node> arr = new ArrayList<>();\n        for(int l=1;l<=N;l++){\n            for(int r=l;r<=N;r++){\n                arr.add(new Node(l,r,sum[r]-sum[l-1]));\n            }\n        }\n        Collections.sort(arr);\n        for(int i=0;i<arr.size();i++){\n            ArrayList<Node> a=mp.get(arr.get(i).s);\n            if(a==null) {\n                a=new ArrayList<>();\n                mp.put(arr.get(i).s,a);\n            }\n            a.add(arr.get(i));\n        }\n        int mx=-1;\n        long mxv=-1;\n        Iterator<Long> it=mp.keySet().iterator();\n        while(it.hasNext()){\n            int ans=0,t=0;\n            long v=it.next();\n            ArrayList<Node> vec= mp.get(v);\n            for(int i=0;i<vec.size();i++){\n                if(t<vec.get(i).l){\n                    ans++;\n                    t=vec.get(i).r;\n                }\n            }\n           //\n            if(ans>mx){\n                mx=ans;\n                mxv=v;\n               // System.out.println(mxv);\n            }\n        }\n        ArrayList<Node> vec=mp.get(mxv);\n        System.out.println(mx);\n        int t=0;\n        for(int i=0;i<vec.size();i++){\n\n           // System.out.println(vec.get(i).l+\" \"+vec.get(i).r);\n          // System.out.println(\"h\");\n            if(t<vec.get(i).l){\n                System.out.println(vec.get(i).l+\" \"+vec.get(i).r);\n                t=vec.get(i).r;\n            }\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.HashMap;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        Scanner in = new Scanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskF2 solver = new TaskF2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF2 {\n        public void solve(int testNumber, Scanner 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\n            Map<Long, List<Pair>> map = new HashMap<>();\n            for (int r = 0; r < n; r++) {\n                long sum = 0;\n                for (int l = r; l >= 0; l--) {\n                    sum += arr[l];\n                    if (map.containsKey(sum)) {\n                        map.get(sum).add(new Pair(l, r));\n                    } else {\n                        map.put(sum, new ArrayList<>());\n                        map.get(sum).add(new Pair(l, r));\n                    }\n                }\n            }\n            int ans = -1;\n            List<Pair> ansPairs = new ArrayList<>();\n            for (long sum : map.keySet()) {\n                List<Pair> pairs = map.get(sum);\n                int count = 0;\n                int idx = -1;\n                List<Pair> tempPairs = new ArrayList<>();\n                for (Pair pair : pairs) {\n                    if (pair.i > idx) {\n                        idx = pair.j;\n                        tempPairs.add(pair);\n                        count++;\n                    }\n                }\n                if (ans < count) {\n                    ans = count;\n                    ansPairs = tempPairs;\n                }\n            }\n            out.println(ans);\n            for (Pair pair : ansPairs) {\n                out.print((pair.i + 1) + \" \" + (pair.j + 1));\n                out.println();\n            }\n        }\n\n        class Pair {\n            int i;\n            int j;\n\n            Pair(int p, int q) {\n                i = p;\n                j = q;\n            }\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class b {\n\n\tpublic static void main(String[] rgs)\n\t{\n\t\tScanner s=new Scanner(System.in);\n\n\t\tint n=s.nextInt();\n\t\tlong[] arr=new long[n];\n\t\t\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tarr[i]=s.nextLong();\n\t\t}\n\t\tHashMap<Long,ArrayList<pair>> map=new HashMap<>();\n\t\n\t\tArrayList<pair> list=new ArrayList<>();\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tlong sum=0;\n\t\t\tfor(int j=i;j<n;j++) {\n\t\t\t\tsum=sum+arr[j];\n\t\t\t\tpair ob=new pair(i,j);\n\t\t\t\tif(map.containsKey(sum))\n\t\t\t\t{\n\t\t\t\t\tArrayList p=map.get(sum);\n\t\t\t\t\tp.add(ob);\n\t\t\t\t\tmap.put(sum, p);\n\t\t\t\t\t\n\t\t\t\t}else {\n\t\t\t\t\tArrayList<pair> listt=new ArrayList<>();\n\t\t\t\t\tlistt.add(ob);\n\t\t\t\t\tmap.put(sum,listt);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\tlong in=-1;\n\t\tint max=0;\n\t\t\n\t\tfor(Map.Entry<Long, ArrayList<pair>> entry:map.entrySet()) {\n\t\t\tint l=1;\n\t\t\tArrayList<pair> p=entry.getValue();\n\t\t\tCollections.sort(p,new comp());\n\t\t\tint now=p.get(0).end;\n\t\t\tfor(int j=0;j<p.size();j++) {\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\tif(p.get(j).st>now) {\n\t\t\t\t\tl++;\n\t\t\t\t\tnow=p.get(j).end;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif(l>max) {\n\t\t\t\tmax=l;\n\t\t\t\tin=entry.getKey();\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(max);\n\t\t\n\t\t\n\t\tArrayList<pair> d=map.get(in);\n\t\tint now=-1;\n\t\tfor(int j=0;j<d.size();j++) {\n\t\t\n\t\t\tif(d.get(j).st>now) {\n\t\t\t\tSystem.out.println((d.get(j).st+1)+\" \"+(d.get(j).end+1));\n\t\t\t\tnow=d.get(j).end;\n\t\t\t\t}\n\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n}\nclass pair{\n\t//long val;\n\tint st;\n\tint end;\n\tpublic pair(int st,int end) {\n\t\t//this.val=val;\n\t\tthis.st=st;\n\t\tthis.end=end;\n\t}\n}\nclass comp implements Comparator<pair>{\n\t\n\tpublic int compare(pair h,pair j) {\n\t\t\n\t\tif(h.end<j.end) {\n\t\t\treturn -1;\n\t\t}else if(h.end==j.end) {\n\t\t\tif(h.st<j.st) {\n\t\t\t\treturn 1;\n\t\t\t}else if(h.st==j.st) {\n\t\t\t\treturn 0;\n\t\t\t}else {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}else {\n\t\t\treturn 1;\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n    static final int INF = (int) 1e9;\n    static final int mod = (int) (1e9 + 7);\n    static final short UNCALC = -1;\n\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        int[] a = sc.nextIntArray(n);\n        long[] cum = new long[n];\n        cum[0] = a[0];\n        for (int i = 1; i < n; i++)\n            cum[i] = a[i] + cum[i - 1];\n        HashMap<Long, ArrayList<Pair>> hm = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            for (int j = i; j < n; j++) {\n                long cur = get(cum, i, j);\n                if (!hm.containsKey(cur)) hm.put(cur, new ArrayList<>());\n                hm.get(cur).add(new Pair(i, j));\n            }\n        }\n        int max = 0;\n        StringBuilder ans = new StringBuilder();\n        for (long sum : hm.keySet()) {\n            ArrayList<Pair> cur = hm.get(sum);\n            Collections.sort(cur);\n            int poss = 0;\n            int r = -1;\n            StringBuilder sb = new StringBuilder();\n            for (int i = 0; i < cur.size(); i++) {\n                if (cur.get(i).left > r) {\n                    poss++;\n                    r = cur.get(i).right;\n                    sb.append(cur.get(i));\n                }\n            }\n            if (poss> max){\n                max = poss;\n                ans = sb;\n            }\n        }\n        out.println(max);\n        out.println(ans);\n        out.flush();\n        out.close();\n    }\n\n    static long get(long[] a, int i, int j) {\n        return a[j] - (i > 0 ? a[i - 1] : 0);\n    }\n\n    static class Pair implements Comparable<Pair> {\n        int left, right;\n\n        public Pair(int left, int right) {\n            this.left = left;\n            this.right = right;\n        }\n\n        @Override\n        public int compareTo(Pair o) {\n            return right - o.right;\n        }\n\n        @Override\n        public String toString() {\n            return (left + 1) + \" \" + (right + 1) + \"\\n\";\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        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()) 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        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 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}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class SameSumBlock {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer tokenizer;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = nextInt();\n\t\tint[] arr = new int[n];\n\t\tint[] pSum = new int[n];\n\t\tfor(int i = 0; i< n; i++) {\n\t\t\tarr[i] = nextInt();\n\t\t\tif(i != 0)\n\t\t\t\tpSum[i] += pSum[i - 1];\n\t\t\tpSum[i] += arr[i];\n\t\t}\n\t\tArrayList<Interval> sorted = new ArrayList<Interval>();\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tsorted.add(new Interval(pSum[i],0, i));\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tfor(int j = i; j < n; j++) {\n\t\t\t\tsorted.add(new Interval(pSum[j] - pSum[i - 1], i, j));\n\t\t\t}\n\t\t}\n\t\tsorted.sort(null);\n\t\tint i = 0;\n\t\tint max = 0, idx = 0, end = 0;\n\t\twhile(i < sorted.size()) {\n\t\t\tint last = i;\n\t\t\tint curr = 1;\n\t\t\tint start = i;\n\t\t\tsorted.get(i).marked = true;\n\t\t\twhile(i < sorted.size() - 1 && sorted.get(i).val == sorted.get(i + 1).val) {\n\t\t\t\ti++;\n\t\t\t\tif(sorted.get(i).l > sorted.get(last).r) {\n\t\t\t\t\tsorted.get(i).marked = true;\n\t\t\t\t\tcurr++;\n\t\t\t\t\tlast = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(curr > max) {\n\t\t\t\tmax = curr;\n\t\t\t\tidx = start;\n\t\t\t\tend = i;\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tSystem.out.println(max);\n\t\tfor(int j = idx; j <= end; j++) {\n\t\t\tif(sorted.get(j).marked)\n\t\t\t\tSystem.out.println(sorted.get(j).l + 1 + \" \" + (sorted.get(j).r + 1));\n\t\t}\n\t}\n\n\tpublic static String next() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\tString line = br.readLine();\n\t\t\tif (line == null)\n\t\t\t\tthrow new IOException();\n\t\t\ttokenizer = new StringTokenizer(line);\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n}\nclass Interval implements Comparable<Interval> {\n\tint val, l, r;\n\tboolean marked;\n\tpublic Interval(int val, int l, int r) {\n\t\tsuper();\n\t\tthis.val = val;\n\t\tthis.l = l;\n\t\tthis.r = r;\n\t}\n\n\t@Override\n\tpublic int compareTo(Interval o) {\n\t\tif(val != o.val)\n\t\t\treturn val - o.val;\n\t\treturn r - o.r;\n\t}\n\t\n}", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n   public class x1141F\n   {\n      public static void main(String omkar[]) throws Exception\n      {\n         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  \n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int N = Integer.parseInt(st.nextToken());\n         int[] 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         //thonky wonky\n         HashMap<Long, ArrayList<Range>> map = new HashMap<Long, ArrayList<Range>>();\n         for(int r=0; r < N; r++)\n         {\n            long sum = 0L;\n            for(int i=r; i >= 0; i--)\n            {\n               sum += arr[i];\n               if(!map.containsKey(sum))\n                  map.put(sum, new ArrayList<Range>());\n               map.get(sum).add(new Range(i, r));\n            }\n         }\n         ArrayList<Range> res = new ArrayList<Range>();\n         for(long key: map.keySet())\n         {\n            ArrayList<Range> ls = map.get(key);\n            ArrayList<Range> temp = new ArrayList<Range>();\n            temp.add(ls.get(0));\n            int r = ls.get(0).r;\n            for(int i=1; i < ls.size(); i++)\n               if(r < ls.get(i).l)\n               {\n                  r = ls.get(i).r;\n                  temp.add(ls.get(i));\n               }\n            if(res.size() < temp.size())\n               res = temp;\n         }\n         System.out.println(res.size());\n         StringBuilder sb = new StringBuilder();\n         for(Range x: res)\n         {\n            sb.append(x.l+\" \"+x.r);\n            sb.append(\"\\n\");\n         }\n         System.out.print(sb);\n      }\n   }\n   class Range\n   {\n      public int l;\n      public int r;\n      \n      public Range(int a, int b)\n      {\n         l = a+1;\n         r = b+1;\n      }\n   }", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1141F {\n\tstatic class V {\n\t\tint l, r, a;\n\t\tV(int l, int r, int a) {\n\t\t\tthis.l = l; this.r = r; this.a = a;\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\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint[] aa = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\taa[i] = Integer.parseInt(st.nextToken());\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\taa[i] += aa[i - 1];\n\t\tint m = n * (n + 1) / 2;\n\t\tV[] vv = new V[m];\n\t\tm = 0;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfor (int j = i; j <= n; j++)\n\t\t\t\tvv[m++] = new V(i, j, aa[j] - aa[i - 1]);\n\t\tArrays.sort(vv, (u, v) -> u.a != v.a ? u.a - v.a : u.r - v.r);\n\t\tint[] ii_ = new int[m];\n\t\tint[] ii = new int[m];\n\t\tint k_ = 0;\n\t\tfor (int i = 0, j; i < m; i = j) {\n\t\t\tj = i + 1;\n\t\t\twhile (j < m && vv[j].a == vv[i].a)\n\t\t\t\tj++;\n\t\t\tint k = 0, r = 0;\n\t\t\tfor (int h = i; h < j; h++)\n\t\t\t\tif (vv[h].l > r) {\n\t\t\t\t\tii[k++] = h;\n\t\t\t\t\tr = vv[h].r;\n\t\t\t\t}\n\t\t\tif (k_ < k) {\n\t\t\t\tk_ = k;\n\t\t\t\tint[] tmp = ii_; ii_ = ii; ii = tmp;\n\t\t\t}\n\t\t}\n\t\tpw.println(k_);\n\t\tfor (int h = 0; h < k_; h++) {\n\t\t\tint i = ii_[h];\n\t\t\tpw.println(vv[i].l + \" \" + vv[i].r);\n\t\t}\n\t\tpw.close();\n\t}\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemF_2 {\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        List<Integer> list = new ArrayList<>();\n        for (int i = 0; i < n; i++) {\n            list.add(scanner.nextInt());\n        }\n\n        Map<Integer, List<Pair<Integer, Integer>>> map = new HashMap<>();\n        for (int i = n - 1; i >= 0; i--) {\n            int x = 0;\n            for (int j = i; j >= 0; j--) {\n                x = x + list.get(j);\n                if (!map.containsKey(x)) {\n                    map.put(x, new ArrayList<>());\n                }\n                map.get(x).add(new Pair<>(j + 1, i + 1));\n            }\n        }\n\n        List<Pair<Integer, Integer>> ans = new ArrayList<>();\n        for (Map.Entry<Integer, List<Pair<Integer, Integer>>> entry : map.entrySet()) {\n            List<Pair<Integer, Integer>> segments = entry.getValue();\n            Collections.reverse(segments);\n            List<Pair<Integer, Integer>> result = new ArrayList<>();\n            result.add(segments.get(0));\n            for (int i = 1; i < segments.size(); i++) {\n                if (segments.get(i).first > result.get(result.size() - 1).second) {\n                    result.add(segments.get(i));\n                }\n            }\n            if (result.size() > ans.size()) {\n                ans = result;\n            }\n        }\n\n        out.println(ans.size());\n        for (Pair<Integer, Integer> pair : ans) {\n            out.println(pair.first + \" \" + pair.second);\n        }\n\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<F, S> {\n\n        private F first;\n\n        private S second;\n\n        public Pair() {}\n\n        public Pair(F first, S second) {\n            this.first = first;\n            this.second = second;\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1141_F2. Same Sum Blocks (Hard)", "from": "CODEFORCES"}
{"src": "import java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.nio.charset.Charset;\nimport java.util.*;\n\nimport static java.lang.System.gc;\nimport static java.lang.System.out;\n\npublic class Main {\n\n    Scanner scanner = new Scanner(System.in);\n\n    public static void main(String[] args) {\n        new Main().solve();\n    }\n\n\n    void solve() {\n\n        int n = scanner.nextInt();\n        scanner.nextLine();\n        String s1 = scanner.nextLine();\n        String s2 = scanner.nextLine();\n\n\n        int ans = 0;\n        boolean a[] = new boolean[30];\n        boolean b[] = new boolean[30];\n\n        for (int i = 0; i < n; i++) {\n            if (s1.charAt(i) != s2.charAt(i)) {\n                ans ++;\n                a[s1.charAt(i)  - 'a'] = true;\n                b[s2.charAt(i)  - 'a'] = true;\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            if (s1.charAt(i) != s2.charAt(i) && a[s2.charAt(i) - 'a'] && b[s1.charAt(i) - 'a']) {\n                for (int j = i + 1; j < n; j ++) {\n                    if (s1.charAt(i) == s2.charAt(j) && s1.charAt(j) == s2.charAt(i)) {\n                        out.println(ans - 2);\n                        out.println((i + 1) + \" \" + (j + 1));\n                        return;\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            if (s1.charAt(i) != s2.charAt(i) && (a[s2.charAt(i) - 'a'] || b[s1.charAt(i) - 'a'])) {\n                for (int j = i + 1; j < n; j ++) {\n                    if (s1.charAt(j) != s2.charAt(j) && (s1.charAt(i) == s2.charAt(j) || s1.charAt(j) == s2.charAt(i))) {\n                        out.println(ans - 1);\n                        out.println((i + 1) + \" \" + (j + 1));\n                        return;\n                    }\n                }\n            }\n        }\n\n        out.println(ans);\n        out.println(-1 + \" \" + -1);\n    }\n}", "complexity": "quadratic", "problem": "527_B. Error Correct System", "from": "CODEFORCES"}
{"src": "import javax.print.attribute.standard.RequestingUserName;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws NumberFormatException, IOException\n    {\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 tc = in.nextInt();\n        for(int i = 0; i < tc; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class Task {\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n            int k = in.nextInt();\n            int[] s = getArray(in.nextToken());\n            int[] a = getArray(in.nextToken());\n            int[] b = getArray(in.nextToken());\n\n            int[] per = new int[k];\n            boolean[] used = new boolean[k];\n            Arrays.fill(per , -1);\n\n            if(!check(s , a, per.clone(), k, used)){\n                out.println(\"NO\");\n                return;\n            }\n\n            for(int i = 0; i < s.length; i++){\n                if(per[s[i]] != -1){\n                    continue;\n                }\n                for(int j = 0; j < k; j++){\n                    if(used[j]){\n                        continue;\n                    }\n                    per[s[i]] = j;\n                    used[j] = true;\n                    if(check(s , a , per.clone() , k, used)){\n                        break;\n                    }\n                    per[s[i]] = -1;\n                    used[j] = false;\n                }\n            }\n\n            for(int i = 0; i < s.length; i++){\n                if(per[s[i]] == -1){\n                    out.println(\"NO\");\n                    return;\n                }\n                s[i] = per[s[i]];\n            }\n\n            if(cmp(s , b) > 0){\n                out.println(\"NO\");\n                return;\n            }\n\n\n            int last = 0;\n            for(int i = 0; i < k; i++){\n                if(per[i] == -1) {\n                    while(used[last])last++;\n                    per[i] = last;\n                    used[last] = true;\n                }\n            }\n\n            char[] result = new char[k];\n\n            for(int i = 0; i < k; i++){\n                result[i] = (char)('a' + per[i]);\n            }\n            out.println(\"YES\");\n            out.println(new String(result));\n        }\n\n        private int cmp(int[] a, int[] b){\n            for(int i = 0; i < a.length; i++){\n                if(a[i] != b[i]){\n                    return a[i] < b[i] ? -1 : 1;\n                }\n            }\n            return 0;\n        }\n\n\n        private boolean check(int[] s, int[] a, int[] per, int k, boolean[] used) {\n            int res[] = new int[s.length];\n            int last = k - 1;\n            for(int i = 0; i < res.length; ++i){\n\n                if(per[s[i]] == -1){\n\n                    while(last >= 0 && used[last]){\n                        last--;\n                    }\n\n                    if(last < 0){\n                        return false;\n                    }\n\n                    per[s[i]] = last;\n                    last--;\n                }\n                res[i] = per[s[i]];\n            }\n            return cmp(a , res) <= 0;\n        }\n\n        private int[] getArray(String nextToken) {\n            int result[] = new int[nextToken.length()];\n            for(int i = 0; i < nextToken.length(); i++){\n                result[i] = nextToken.charAt(i) - 'a';\n            }\n            return result;\n        }\n    }\n\n    static class InputReader {\n\n        BufferedReader in;\n        StringTokenizer tok;\n\n        public InputReader(InputStream stream){\n            in = new BufferedReader(new InputStreamReader(stream), 32768);\n            tok = null;\n        }\n\n        String nextToken()\n        {\n            String line = \"\";\n            while(tok == null || !tok.hasMoreTokens()) {\n                try {\n                    if((line = in.readLine()) != null)\n                        tok = new StringTokenizer(line);\n                    else\n                        return null;\n                } catch (IOException e) {\n                    e.printStackTrace();\n                    return null;\n                }\n            }\n            return tok.nextToken();\n        }\n        int nextInt(){\n            return Integer.parseInt(nextToken());\n        }\n        long nextLong()\t{\n            return Long.parseLong(nextToken());\n        }\n        double nextDouble()\t{\n            return Double.parseDouble(nextToken());\n        }\n\n    }\n\n}", "complexity": "quadratic", "problem": "1086_C. Vasya and Templates", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\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.LinkedHashMap;\nimport java.util.Map;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n */\npublic class Practice {\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(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            String[] arr1 = new String[n];\n            String[] arr2 = new String[n];\n            for (int i = 0; i < n; i++) {\n                arr1[i] = in.next();\n            }\n            for (int i = 0; i < n; i++) {\n                arr2[i] = in.next();\n            }\n            int ans = 0;\n            boolean arr[]=new boolean[n];\n            boolean found=false;\n            for (int i = 0; i < arr1.length; i++) {\n                for(int j=0;j<arr1.length;j++){\n                    found=false;\n                    if(arr1[i].equals(arr2[j]) && !arr[j]){\n                        found=true;\n                        arr[j]=true;\n                        break;\n                    }\n                }\n                if(!found){\n                    ans++;\n                }\n            }\n            out.println(ans);\n        }\n    }\n\n    public static boolean checkPrime(int n, int p) {\n        for (int i = 2; i <= Math.sqrt(n) && i <= p; i++) {\n            if (n % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    public static void mergeArrays(int[] arr1, int[] arr2, int n1,\n            int n2, int[] arr3) {\n        int i = 0, j = 0, k = 0;\n        while (i < n1 && j < n2) {\n            if (arr1[i] < arr2[j]) {\n                arr3[k++] = arr1[i++];\n            } else {\n                arr3[k++] = arr2[j++];\n            }\n        }\n        while (i < n1) {\n            arr3[k++] = arr1[i++];\n        }\n        while (j < n2) {\n            arr3[k++] = arr2[j++];\n        }\n    }\n\n    public 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 nCr(int n, int r) {\n        return n * (n - 1) / 2;\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        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n    }\n\n}\n", "complexity": "quadratic", "problem": "1000_A. Codehorses T-shirts", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class E1180D {\n\n    public static void main(String args[]) {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n\n        // Move from both ends, Time limit exceeded on test 6\n        for (int i= 1; i<= m/2; i++) {\n            // String s = \"\";\n            int i2 = m -i + 1; // the other end of i\n            // i is left row, i2 is right row\n            for (int j = 1; j <= n ; j++) {\n                int j2 = n - j + 1;\n                // start with (i,j), then go thru all the cell with (,i) and (,i2)\n                pw.println(j + \" \" + i);\n                pw.println(j2+ \" \" + i2);\n                // s += j + \" \" + i + \"\\n\" + j2+ \" \" + i2 + \"\\n\";\n            }\n            // out.print(s);\n        }\n        \n        // if n is odd, there is one line in the middle\n        if (m % 2 == 1) {\n            int i2 = m /2 + 1; // this is the middle column\n            for (int j = 1; j <= n/2 ; j++) {\n                int j2 = n - j + 1;\n                // start with (i,j), then go thru all the cell with (,i) and (,i2)\n                pw.println(j + \" \" + i2);\n                pw.println(j2+ \" \" + i2);\n            }\n            if (n %2 == 1) {\n                int j = n /2 + 1;\n                pw.println(j + \" \" + i2);\n            }\n        }\n        pw.flush();\n        pw.close();\n    }    \n}\n", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    int[][] fast(int n, int m){\n\n        int[][] ans = new int[2][n * m];\n        int c = 0;\n\n        for (int left = 1, right = m; left < right; left++, right--) {\n            for (int l = 1, r = n; l <= n && r >= 1; l++, r--) {\n                ans[0][c] = l;\n                ans[1][c++] = left;\n\n                ans[0][c] = r;\n                ans[1][c++] = right;\n            }\n        }\n\n        if (m % 2 == 1) {\n            int x = m/2 + 1;\n            for(int l = 1, r = n;l < r;l++, r--){\n                ans[0][c] = l;\n                ans[1][c++] = x;\n\n                ans[0][c] = r;\n                ans[1][c++] = x;\n                    if(n % 2 == 1 && l + 2 == r){\n                        ans[0][c] = l+1;\n                        ans[1][c++] = x;\n                    }\n            }\n        }\n\n        if(n == 1 && m % 2 == 1){\n            ans[0][c] = 1;\n            ans[1][c] = m/2 + 1;\n        }\n\n        return ans;\n    }\n\n    void stress(){\n\n        for(int i = 3;i<=5;i++){\n            for(int j = 2;j<=5;j++){\n                int[][] ans = new int[2][];\n                try{\n                    ans = fast(i, j);\n                }catch(Exception e){\n                    out.println(\"\u043e\u0448\u0438\u0431\u043a\u0430\");\n                    out.print(i + \" \" + j);\n                    return;\n                }\n\n                boolean[][] check = new boolean[i][j];\n                for(int c = 0;c<ans[0].length;c++){\n                    int x = ans[0][c] - 1;\n                    int y = ans[1][c] - 1;\n                    check[x][y] = true;\n                }\n\n                for(int c = 0;c<i;c++){\n                    for(int q = 0;q<j;q++){\n                        if(!check[c][q]){\n                            out.println(i + \" \" + j);\n                            out.println(\"\u0442\u043e\u0447\u043a\u0438\");\n                            for(int w = 0;w<ans[0].length;w++){\n                                out.println(ans[0][w] + \" \" + ans[1][w]);\n                            }\n                            return;\n                        }\n                    }\n                }\n\n                HashSet<String> set = new HashSet<>();\n                for(int c = 1;c<ans[0].length;c++){\n                    int x = ans[0][c] - ans[0][c- 1];\n                    int y = ans[1][c] - ans[1][c - 1];\n                    set.add(x + \" \" + y);\n                }\n\n                if(set.size() < i * j - 1){\n                    out.println(i + \" \" + j);\n                    out.println(\"\u0432\u0435\u043a\u0442\u043e\u0440\u0430\");\n                    for(int w = 0;w<ans[0].length;w++){\n                        out.println(ans[0][w] + \" \" + ans[1][w]);\n                    }\n                    return;\n                }\n            }\n        }\n    }\n\n    void normal(){\n        int n =readInt();\n        int m = readInt();\n        int[][] ans = fast(n, m);\n        for(int i = 0;i<ans[0].length;i++){\n            out.println(ans[0][i] + \" \" + ans[1][i]);\n        }\n    }\n\n    boolean stress = false;\n    void solve(){\n        if(stress) stress();\n        else normal();\n    }\n\n    public static void main(String[] args) {\n        new D().run();\n    }\n\n    void run(){\n        init();\n        solve();\n        out.close();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init(){\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out  = new PrintWriter(System.out);\n    }\n\n    String readLine(){\n        try{\n            return in.readLine();\n        }catch(Exception ex){\n            throw new RuntimeException(ex);\n        }\n    }\n    String readString(){\n        while(!tok.hasMoreTokens()){\n            String nextLine = readLine();\n            if(nextLine == null) return null;\n            tok = new StringTokenizer(nextLine);\n        }\n        return tok.nextToken();\n    }\n\n    int readInt(){\n        return Integer.parseInt(readString());\n    }\n\n    long readLong(){\n        return Long.parseLong(readString());\n    }\n\n    double readDouble(){\n        return Double.parseDouble(readString());\n    }\n}\n", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    private void solve() {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        int n = nextInt(), m = nextInt();\n        boolean[][] used = new boolean[n + 1][m + 1];\n\n        for (int j = 1; j <= (m + 1) / 2; j++) {\n            int x1 = 1, x2 = n;\n            for (int i = 1; i <= n; i++) {\n                if (x1 <= n && !used[x1][j]) {\n                    out.println(x1 + \" \" + j);\n                    used[x1++][j] = true;\n                }\n                if (x2 > 0 && !used[x2][m - j + 1]) {\n                    out.println(x2 + \" \" + (m - j + 1));\n                    used[x2--][m - j + 1] = true;\n                }\n            }\n        }\n\n        out.close();\n    }\n\n    public static void main(String[] args) {\n        new D().solve();\n    }\n\n    private BufferedReader br;\n    private StringTokenizer st;\n    private PrintWriter out;\n\n    private String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return st.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", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n    private void solve() {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        int n = nextInt(), m = nextInt(), u = 1, d = n;\n\n        while (u < d) {\n            for (int i = 1; i <= m; i++) {\n                out.println(u + \" \" + i);\n                out.println(d + \" \" + (m - i + 1));\n            }\n            u++;\n            d--;\n        }\n        if (u == d) {\n            int l = 1, r = m;\n            while (l < r) {\n                out.println(u + \" \" + l++);\n                out.println(d + \" \" + r--);\n            }\n            if (l == r) out.println(u + \" \" + l);\n        }\n\n        out.close();\n    }\n\n    public static void main(String[] args) {\n        new D().solve();\n    }\n\n    private BufferedReader br;\n    private StringTokenizer st;\n    private PrintWriter out;\n\n    private String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return st.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", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\npublic class D {\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) throws IOException {\n        FastReader fr = new FastReader();\n        FastWriter fw = new FastWriter();\n        int n = fr.nextInt();\n        int m = fr.nextInt();\n        for (int r = 0; r < n / 2; r++) {\n            for (int c = 0; c < m; c++) {\n                fw.println((r + 1) + \" \" + (c + 1));\n                fw.println((n - r) + \" \" + (m - c));\n            }\n        }\n        if (n % 2 != 0) {\n            int r = n / 2;\n            for (int c = 0; c < m / 2; c++) {\n                fw.println((r + 1) + \" \" + (c + 1));\n                fw.println((r + 1) + \" \" + (m - c));\n            }\n            if (m % 2 != 0) fw.println((r + 1) + \" \" + (m / 2 + 1));\n        }\n        fw.close();\n    }\n}\n", "complexity": "quadratic", "problem": "1179_B. Tolik and His Uncle", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.lang.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.*;\n \npublic class Main {\n        \n    public static void main(String[] args) throws Exception{\n        FastReader sc=new FastReader(); \n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n        int n=sc.nextInt();\n        int[] font=new int[n];\n        int[] cost=new int[n];\n        for(int i=0;i<n;i++) {\n            font[i]=sc.nextInt();\n        \n        }\n        for(int i=0;i<n;i++) {\n            cost[i]=sc.nextInt();\n        }\n        int[] dou= new int[n];\n        for(int i=0;i<n;i++) {\n            int min=Integer.MAX_VALUE;\n            for(int j=0;j<i;j++) {\n                if(font[j]<font[i]) {\n                    if(min>cost[i]+cost[j]) {\n                        min=cost[i]+cost[j];\n                    }\n                }\n            }\n            dou[i]=min;\n        }\n        int ans=Integer.MAX_VALUE;\n        for(int i=0;i<n;i++) {\n            int min=Integer.MAX_VALUE;\n            for(int j=0;j<i;j++) {\n                if(dou[j]!=Integer.MAX_VALUE && font[j]<font[i]) {\n                    if(min>dou[j]+cost[i]) {\n                        min=dou[j]+cost[i];\n                    }\n                }\n            }\n            if(min<ans) {\n                ans=min;\n            }\n        }\n        if(ans==Integer.MAX_VALUE) {\n            System.out.println(-1);\n        }\n        else {\n            System.out.println(ans);\n        }\n    }\n}\n\nclass 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} ", "complexity": "quadratic", "problem": "987_C. Three displays", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.*;\npublic class CF1003E{\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        int n = Integer.parseInt(s[0]);\n        int d = Integer.parseInt(s[1]);\n        int k = Integer.parseInt(s[2]);\n        StringBuffer sb = new StringBuffer();\n        int[] rem = new int[n];\n        int[] deg = new int[n];\n        int i = 0;\n        if(k == 1){\n            if(n <= 2){\n\n            }else{\n                System.out.println(\"NO\");\n                return;\n            }\n        }\n        for(i=0;i<d;i++){\n            if(i>=n-1){\n                System.out.println(\"NO\");\n                return;\n            }\n            sb.append((i+1) +\" \" + (i+2)+\"\\n\");\n            rem[i] = Math.min(i, d-i);\n            deg[i]++;\n            if(i+1<n)\n            deg[i+1]++;\n        }\n        if(i<n){\n            rem[i] = 0;\n            deg[i] = 1;\n        }\n        i++;\n        int j  = 0;\n        for(;i<n;i++){\n            //For all remaining Nodes\n            while(true){\n                if(j>=n){\n                    System.out.println(\"NO\");\n                    return;\n                }\n                if(rem[j] > 0 && deg[j]<k){\n                    deg[j]++;\n                    rem[i] = rem[j] - 1;\n                    sb.append((j+1)+\" \"+(i+1)+\"\\n\");\n                    deg[i]++;\n                    break;\n                }else{\n                    j++;\n                }\n            }\n        }\n        System.out.println(\"YES\");\n        System.out.println(sb);\n    }\n}\n", "complexity": "quadratic", "problem": "1003_E. Tree Constructing", "from": "CODEFORCES"}
{"src": "/**\n * Created at 22:05 on 2019-09-14\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n  static FastScanner sc = new FastScanner();\n  static Output out = new Output(System.out);\n\n  static final int[] dx = {0, 1, 0, -1};\n  static final int[] dy = {-1, 0, 1, 0};\n\n  static final long MOD = (long) (1e9 + 7);\n  static final long INF = Long.MAX_VALUE / 2;\n\n  static final int e5 = (int) 1e5;\n\n  public static class Solver {\n    public Solver() {\n\n      int N = sc.nextInt();\n\n      boolean[] flag = new boolean[101];\n      for (int i=0; i<N; i++) {\n        flag[sc.nextInt()] = true;\n      }\n\n      int ans = 0;\n      for (int i=1; i<=100; i++) {\n        if (flag[i]) {\n          ans++;\n          for (int j=i*2; j<=100; j+=i) {\n            flag[j] = false;\n          }\n        }\n      }\n\n      out.println(ans);\n\n    }\n\n    public static void sort(int[] a) {\n      shuffle(a);\n      Arrays.sort(a);\n    }\n\n    public static void sort(long[] a) {\n      shuffle(a);\n      Arrays.sort(a);\n    }\n\n    public static void shuffle(int[] arr){\n      int n = arr.length;\n      Random rnd = new Random();\n      for(int i=0; i<n; ++i){\n        int tmp = arr[i];\n        int randomPos = i + rnd.nextInt(n-i);\n        arr[i] = arr[randomPos];\n        arr[randomPos] = tmp;\n      }\n    }\n\n    public static void shuffle(long[] arr){\n      int n = arr.length;\n      Random rnd = new Random();\n      for(int i=0; i<n; ++i){\n        long tmp = arr[i];\n        int randomPos = i + rnd.nextInt(n-i);\n        arr[i] = arr[randomPos];\n        arr[randomPos] = tmp;\n      }\n    }\n  }\n\n  public static void main(String[] args) {\n    new Solver();\n    out.flush();\n  }\n\n  static class FastScanner {\n    private InputStream in = System.in;\n    private final byte[] buffer = new byte[1024];\n    private int ptr = 0;\n    private int buflen = 0;\n\n\n    public void load() {\n      try {\n        in = new FileInputStream(next());\n      } catch (Exception e) {\n        e.printStackTrace();\n      }\n    }\n\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\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    public 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    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\n    public int nextInt() {\n      return (int) nextLong();\n    }\n\n    public int[] nextIntArray(int N, boolean oneBased) {\n      if (oneBased) {\n        int[] array = new int[N + 1];\n        for (int i = 1; i <= N; i++) {\n          array[i] = sc.nextInt();\n        }\n        return array;\n      } else {\n        int[] array = new int[N];\n        for (int i = 0; i < N; i++) {\n          array[i] = sc.nextInt();\n        }\n        return array;\n      }\n    }\n\n    public long[] nextLongArray(int N, boolean oneBased) {\n      if (oneBased) {\n        long[] array = new long[N + 1];\n        for (int i = 1; i <= N; i++) {\n          array[i] = sc.nextLong();\n        }\n        return array;\n      } else {\n        long[] array = new long[N];\n        for (int i = 0; i < N; i++) {\n          array[i] = sc.nextLong();\n        }\n        return array;\n      }\n    }\n  }\n\n  static class Output extends PrintWriter {\n\n    private long startTime;\n\n    public Output(PrintStream ps) {\n      super(ps);\n    }\n\n    public void print(int[] a, String separator) {\n      for (int i = 0; i < a.length; i++) {\n        if (i == 0) print(a[i]);\n        else print(separator + a[i]);\n      }\n      println();\n    }\n\n    public void print(long[] a, String separator) {\n      for (int i = 0; i < a.length; i++) {\n        if (i == 0) print(a[i]);\n        else print(separator + a[i]);\n      }\n      println();\n    }\n\n    public void print(String[] a, String separator) {\n      for (int i = 0; i < a.length; i++) {\n        if (i == 0) print(a[i]);\n        else print(separator + a[i]);\n      }\n      println();\n    }\n\n    public void print(ArrayList a, String separator) {\n      for (int i = 0; i < a.size(); i++) {\n        if (i == 0) print(a.get(i));\n        else print(separator + a.get(i));\n      }\n      println();\n    }\n\n    public void start() {\n      startTime = System.currentTimeMillis();\n    }\n\n    public void time(String s) {\n      long time = System.currentTimeMillis() - startTime;\n      println(s + \"(\" + time + \")\");\n    }\n\n  }\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedWriter;\nimport java.io.DataInputStream;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.nio.file.Paths;\nimport java.util.Arrays;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tFastPrinter out = new FastPrinter(System.out);\n\t\tnew A().run(sc, out);\n\t\tout.close();\n\t}\n\n\tpublic void run(FastScanner sc, FastPrinter out) throws Exception {\n\t\tint N = sc.nextInt();\n\t\tint[] arr = sc.nextIntArray(N);\n\t\tArrays.sort(arr);\n\t\tboolean[] done = new boolean[N];\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tif (done[i]) continue;\n\t\t\tans++;\n\t\t\tfor (int j = i; j < N; j++) {\n\t\t\t\tif (arr[j] % arr[i] == 0) {\n\t\t\t\t\tdone[j] = true;\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tpublic void shuffle(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tint r = (int) (Math.random() * arr.length);\n\t\t\tif (i != r) {\n\t\t\t\tarr[i] ^= arr[r];\n\t\t\t\tarr[r] ^= arr[i];\n\t\t\t\tarr[i] ^= arr[r];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class FastScanner {\n\t\tfinal private int BUFFER_SIZE = 1 << 10;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic FastScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tdin = new DataInputStream(stream);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic FastScanner(String fileName) throws IOException {\n\t\t\tPath p = Paths.get(fileName);\n\t\t\tbuffer = Files.readAllBytes(p);\n\t\t\tbytesRead = buffer.length;\n\t\t}\n\n\t\tint[] 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\tString nextLine() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (c != -1 && isEndline(c))\n\t\t\t\tc = read();\n\t\t\tif (c == -1) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tif (c >= 0) {\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t}\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\tboolean isEndline(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tString next() throws Exception {\n\t\t\tint c = readOutSpaces();\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\tboolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg) c = 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) return -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) c = 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) return -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) c = 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) return -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tif (din == null) {\n\t\t\t\tbufferPointer = 0;\n\t\t\t\tbytesRead = -1;\n\t\t\t} else {\n\t\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\t}\n\t\t\tif (bytesRead == -1) buffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead) fillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tprivate int readOutSpaces() throws IOException {\n\t\t\twhile (true) {\n\t\t\t\tif (bufferPointer == bytesRead) fillBuffer();\n\t\t\t\tint c = buffer[bufferPointer++];\n\t\t\t\tif (!isSpaceChar(c)) {\n\t\t\t\t\treturn c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null) return;\n\t\t\tdin.close();\n\t\t}\n\n\t\tpublic int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {\n\t\t\tint[][] adj = new int[N][];\n\t\t\tint[] numNodes = new int[N];\n\t\t\tint[][] input = new int[M][2];\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = nextInt();\n\t\t\t\tint b = nextInt();\n\t\t\t\tif (zeroIndexed) {\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tinput[i][0] = a;\n\t\t\t\tinput[i][1] = b;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) numNodes[b]++;\n\t\t\t}\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tadj[i] = new int[numNodes[i]];\n\t\t\t\tnumNodes[i] = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = input[i][0];\n\t\t\t\tint b = input[i][1];\n\t\t\t\tadj[a][numNodes[a]++] = b;\n\t\t\t\tif (bidirectional) adj[b][numNodes[b]++] = a;\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\n\t\tpublic int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {\n\t\t\tint[][][] adj = new int[N][][];\n\t\t\tint[] numNodes = new int[N];\n\t\t\tint[][] input = new int[M][3];\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = nextInt();\n\t\t\t\tint b = nextInt();\n\t\t\t\tif (zeroIndexed) {\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tint d = nextInt();\n\t\t\t\tinput[i][0] = a;\n\t\t\t\tinput[i][1] = b;\n\t\t\t\tinput[i][2] = d;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) numNodes[b]++;\n\t\t\t}\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tadj[i] = new int[numNodes[i]][2];\n\t\t\t\tnumNodes[i] = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = input[i][0];\n\t\t\t\tint b = input[i][1];\n\t\t\t\tint d = input[i][2];\n\t\t\t\tadj[a][numNodes[a]][0] = b;\n\t\t\t\tadj[a][numNodes[a]][1] = d;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) {\n\t\t\t\t\tadj[b][numNodes[b]][0] = a;\n\t\t\t\t\tadj[b][numNodes[b]][1] = d;\n\t\t\t\t\tnumNodes[b]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\t}\n\n\tstatic class FastPrinter {\n\t\tstatic final char ENDL = '\\n';\n\t\tStringBuilder buf;\n\t\tPrintWriter pw;\n\n\t\tpublic FastPrinter(OutputStream stream) {\n\t\t\tbuf = new StringBuilder();\n\t\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));\n\t\t}\n\n\t\tpublic FastPrinter(String fileName) throws Exception {\n\t\t\tbuf = new StringBuilder();\n\t\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));\n\t\t}\n\n\t\tpublic FastPrinter(StringBuilder buf) {\n\t\t\tthis.buf = buf;\n\t\t}\n\n\t\tpublic void print(int a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(long a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(char a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(char[] a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(double a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(String a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(Object a) {\n\t\t\tbuf.append(a.toString());\n\t\t}\n\n\t\tpublic void println() {\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(int a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(long a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(char a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(char[] a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(double a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(String a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(Object a) {\n\t\t\tbuf.append(a.toString());\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void printf(String format, Object... args) {\n\t\t\tbuf.append(String.format(format, args));\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tpw.print(buf);\n\t\t\tpw.close();\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\tpw.print(buf);\n\t\t\tpw.flush();\n\t\t\tbuf.setLength(0);\n\t\t}\n\n\t}\n\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.sort;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tstatic void solve() throws Exception {\n\t\tint n = scanInt();\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = scanInt();\n\t\t}\n\t\tsort(a);\n\t\tint ans = 0;\n\t\tans: while (true) {\n\t\t\tfor (int i = 0;; i++) {\n\t\t\t\tif (i == n) {\n\t\t\t\t\tbreak ans;\n\t\t\t\t}\n\t\t\t\tif (a[i] != 0) {\n\t\t\t\t\t++ans;\n\t\t\t\t\tint t = a[i];\n\t\t\t\t\ta[i] = 0;\n\t\t\t\t\tfor (i++; i < n; i++) {\n\t\t\t\t\t\tif (a[i] % t == 0) {\n\t\t\t\t\t\t\ta[i] = 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}\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t    int n=Integer.parseInt(br.readLine());\n\t    String s=br.readLine();\n\t    String ss[]=s.split(\" \");\n\t    int arr[]=new int[n];\n\t    for(int i=0;i<n;i++)\n\t    arr[i]=Integer.parseInt(ss[i]);\n\t    Arrays.sort(arr);\n\t    int coun=0,coun2=0;\n\t    for(int i=arr[0],k=0;k<n;)\n\t    {\n\t        for(int j=k;j<n;j++)\n\t        {\n\t            if(arr[j]%i==0)\n\t            {\n\t                arr[j]=-1;\n\t                coun2++;\n\t            }\n\t        }\n\t        Arrays.sort(arr);\n\t        k=coun2;\n\t        coun++;\n\t        if(coun2<n)\n\t        i=arr[coun2];\n\t        else\n\t        break;\n\t        \n\t    }\n\t\tSystem.out.println(coun);\n\t}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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.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 null\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        Input in = new Input(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, Input in, PrintWriter out) {\n            try {\n                int n = in.readInt();\n                int[] a = new int[n];\n                for (int i = 0; i < n; i++) {\n                    a[i] = in.readInt();\n                }\n                Arrays.sort(a);\n                boolean[] b = new boolean[n];\n                int ans = 0;\n                while (true) {\n                    int x = 0;\n                    for (int i = 0; i < n; i++) {\n                        if (!b[i] && x == 0) {\n                            x = a[i];\n                        }\n                        if (x != 0 && a[i] % x == 0) {\n                            b[i] = true;\n                        }\n                    }\n                    if (x == 0) {\n                        break;\n                    }\n                    ans++;\n                }\n                out.println(ans);\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n    }\n\n    static class Input {\n        public final BufferedReader reader;\n        private String line = \"\";\n        private int pos = 0;\n\n        public Input(InputStream inputStream) {\n            reader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        private boolean isSpace(char ch) {\n            return ch <= 32;\n        }\n\n        public String readWord() throws IOException {\n            skip();\n            int start = pos;\n            while (pos < line.length() && !isSpace(line.charAt(pos))) {\n                pos++;\n            }\n            return line.substring(start, pos);\n        }\n\n        public int readInt() throws IOException {\n            return Integer.parseInt(readWord());\n        }\n\n        private void skip() throws IOException {\n            while (true) {\n                if (pos >= line.length()) {\n                    line = reader.readLine();\n                    pos = 0;\n                }\n                while (pos < line.length() && isSpace(line.charAt(pos))) {\n                    pos++;\n                }\n                if (pos < line.length()) {\n                    return;\n                }\n            }\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tstatic Scanner console;\n\tpublic static void main(String[] args) {\n\t\tconsole = new Scanner(System.in);\n\t\tint n = console.nextInt();\n\t\tList<Integer> arr= new ArrayList<>();\t\t\n\t\tfor(int i = 0; i < n; i++) arr.add( console.nextInt());\n\t\tCollections.sort(arr);\n\t\tList<Integer> groups = new ArrayList<>();\n//\t\tSystem.out.println(arr);\n\t\tfor(int i = 0; i < arr.size() - 1; i++) {\n\t\t\tint j = i+1;\n\t\t\tgroups.add(arr.get(i));\n//\t\t\tSystem.out.println(groups);\n\t\t\twhile(j < arr.size()) {\n//\t\t\t\tSystem.out.println(j);\n\t\t\t\tif(arr.get(j) % arr.get(i) == 0) {\n\t\t\t\t\tarr.remove(j);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse {\n//\t\t\t\t\tgroups.add(arr.get(j));\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(arr);\n\t\tSystem.out.println(arr.size());\n\t}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class problemA {\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        int[] numbs = new int[n];\n        int[] smallest_color = new int[n];\n        for(int i =  0; i < n;i++){\n            numbs[i] = scan.nextInt();\n        }\n        Arrays.sort(numbs);\n        int count = 0;\n        for(int i =0; i < n; i++){\n            for(int j=0; j <n;j++ ){\n                if(smallest_color[j] == 0){\n                    count++;\n                    smallest_color[j] = numbs[i];\n                    break;\n                }\n                if(numbs[i] % smallest_color[j] == 0){\n                    break;\n                }\n            }\n        }\n        System.out.println(count);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n//****Use Integer Wrapper Class for Arrays.sort()****\npublic class AG1 {\n    public static void main(String[] Args){\n        FastReader scan=new FastReader();\n        int n=scan.nextInt();\n        int[] arr=new int[n];\n        for (int i = 0; i <n ; i++) {\n            arr[i]=scan.nextInt();\n        }\n        Arrays.sort(arr);\n        boolean[] done=new boolean[n];\n        int ans=0;\n        for(int i=0;i<n;i++){\n            if(!done[i]){\n                done[i]=true;\n                ans++;\n                for(int j=i+1;j<n;j++){\n                    if(arr[j]%arr[i]==0){\n                        done[j]=true;\n                    }\n                }\n            }\n        }\n        System.out.println(ans);\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.math.*;\nimport java.util.*;\n \npublic class Main {\n\tstatic final long MOD = 998244353;\n\t//static final long MOD = 1000000007;\n\tstatic boolean[] visited;\n    public static void main(String[] args) throws IOException {\n        FastScanner sc = new FastScanner();\n        int N = sc.nextInt();\n        int[] nums = new int[N];\n        for (int i = 0; i < N; i++) {\n        \tnums[i] = sc.nextInt();\n        }\n        Arrays.sort(nums);\n        boolean[] hit = new boolean[N];\n        int colors = 0;\n        int index = 0;\n        while (index < N) {\n        \tif (hit[index] == false) {\n        \t\tcolors++;\n        \t\tint div = nums[index];\n        \t\tfor (int i = index; i < N; i++) {\n        \t\t\tif (nums[i] % div == 0) {\n        \t\t\t\thit[i] = true;\n        \t\t\t}\n        \t\t}\n        \t}\n        \tindex++;\n        }\n        System.out.println(colors);\n    }\n    \n    public static int[][] sort(int[][] array) {\n    \t//Sort an array (immune to quicksort TLE)\n\t\tRandom rgen = new Random();\n\t\tfor (int i = 0; i< array.length; i++) {\n\t\t    int randomPosition = rgen.nextInt(array.length);\n\t\t    int[] temp = array[i];\n\t\t    array[i] = array[randomPosition];\n\t\t    array[randomPosition] = temp;\n\t\t}\n\t\tArrays.sort(array, new Comparator<int[]>() {\n\t\t\t  @Override\n\t\t\t  public int compare(int[] arr1, int[] arr2) {\n\t\t\t\t  //Ascending order\n\t\t\t\t  if (arr1[0] != arr2[0])\n\t\t\t\t\t  return arr1[0]-arr2[0];\n\t\t\t\t  else\n\t\t\t\t\t  return arr2[1]-arr1[1];\n\t\t\t  }\n\t\t});\n\t\treturn array;\n\t}\n    \n    static class FastScanner { \n        BufferedReader br; \n        StringTokenizer st; \n  \n        public FastScanner() { \n            br = new BufferedReader(new InputStreamReader(System.in)); \n        } \n  \n        String next() { \n            while (st == null || !st.hasMoreElements()) { \n                try { \n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException  e) { \n                    e.printStackTrace(); \n                } \n            } \n            return st.nextToken(); \n        } \n  \n        int 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\nclass Node {\n\tpublic HashSet<Node> children;\n\tpublic int n;\n\t\n\tpublic Node(int n) {\n\t\tthis.n = n;\n\t\tchildren = new HashSet<Node>();\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\t/* (non-Javadoc)\n\t * @see java.lang.Object#hashCode()\n\t */\n\t@Override\n\tpublic int hashCode() {\n\t\treturn n;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object obj) {\n\t\tif (! (obj instanceof Node)) {\n\t\t\treturn false;\n\t\t} else {\n\t\t\tNode node = (Node) obj;\n\t\t\treturn (n == node.n);\n\t\t}\n\t}\n\t\n\tpublic String toString() {\n\t\treturn (this.n+1)+\"\";\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class codea{\n\tpublic static void main(String args[])\n\t{\n\t  Scanner in = new Scanner(System.in);\n\t  int n = in.nextInt();\n\t  int arr[] = new int[n];\n\t  for(int i =0;i<n;i++)\n\t   arr[i]= in.nextInt();\n\t  Arrays.sort(arr);\n\t  int max =0;\n\t  boolean check[]= new boolean [n];\n\t  int count=0;\n\t  for(int i =0;i<n;i++)\n\t  {\n\t   \n\t   if(!check[i])\n\t   {\n\t   \tcount++;\n\t   \n\t   for(int j=i;j<n;j++)\n\t   {\n\t   \n\t    if(arr[j]%arr[i]==0)\n\t     check[j]=true;\n\t   }\n\t   \n\t   }\t\n\t  }\n\t  System.out.println(count);\t\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "//package Round584;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class typeA {\n\tpublic static void main(String[] args) {\n\t\tFastReader s = new FastReader();\n\t\tint n = s.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tarr[i]=s.nextInt();\n\t\t}\n\t\tboolean[] arr2  = new boolean[n];\n\t\tArrays.sort(arr);\n\t\tfor(int i=0;i<arr2.length;i++) {\n\t\t\tarr2[i]=true;\n\t\t}\n\t\t//arr2[0]=true;\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\tfor(int j=i+1;j<n;j++) {\n\t\t\t\t\tif(arr[j]%arr[i]==0) {\n\t\t\t\t\t\tarr2[j]=false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tint count=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(arr2[i]==true) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\tstatic class FastReader \n\t\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}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n    void solve() {\n       int n=ni();\n       int a[]=new int[n+1];\n       for(int i=1;i<=n;i++) a[i]=ni();\n       int vis[]=new int[101];\n       int ans=0;\n       Arrays.sort(a,1,n+1);\n       for(int i=1;i<=n;i++){\n           if(vis[a[i]]==1) continue;\n           ans++;\n           for(int j=a[i];j<=100;j+=a[i]) vis[j]=1;\n       }\n       pw.println(ans);\n    }\n\n    long M = (long)1e9+7;\n    // END\n    PrintWriter pw;\n    StringTokenizer st;\n    BufferedReader br;\n\n    void run() throws Exception {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n        long s = System.currentTimeMillis();\n        solve();\n        pw.flush();\n    }\n    public static void main(String[] args) throws Exception {\n        new Main().run();\n    }\n\n    String ns() {\n        while (st == null || !st.hasMoreElements()) {\n\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (IOException e) {\n                e.printStackTrace();\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    int ni() {\n        return Integer.parseInt(ns());\n    }\n\n    long nl() {\n        return Long.parseLong(ns());\n    }\n\n    double nd() {\n        return Double.parseDouble(ns());\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n    static PrintWriter writer;\n\n    static String nextToken() throws IOException {\n        while (tokenizer == null || !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(nextToken());\n    }\n\n    static void banana() throws IOException {\n        int n = nextInt();\n        int[] a = new int[n];\n        int[] color = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = nextInt();\n        }\n        int c = 0;\n        while(true) {\n            int mn = 1000;\n            for (int i = 0; i < n; i++) {\n                if(color[i] == 0) {\n                    mn = Math.min(mn, a[i]);\n                }\n            }\n            if (mn == 1000) {\n                break;\n            }\n            c++;\n            for (int i = 0; i < n; i++) {\n                if (color[i] == 0) {\n                    if (a[i] % mn == 0) {\n                        color[i] = c;\n                    }\n                }\n            }\n        }\n        writer.println(c);\n    }\n\n    public static void main(String[] args) throws IOException {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n        tokenizer = null;\n        writer = new PrintWriter(System.out);\n        banana();\n        reader.close();\n        writer.close();\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\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\n            int colors = 0;\n\n            Arrays.sort(inputColors);\n\n            for (int i = 0; i < inputColors.length; i++) {\n                if (inputColors[i] == -1) {\n                    continue;\n                }\n\n                int colorCode = inputColors[i];\n                boolean colorFound = false;\n                for (int j = i; j < inputColors.length; j++) {\n                    if (inputColors[j] != -1 && inputColors[j] % colorCode == 0) {\n                        if (!colorFound) {\n                            colorFound = true;\n                            colors++;\n                        }\n                        inputColors[j] = -1;\n                    }\n                }\n            }\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<Integer> 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<Integer> 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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int N = Integer.parseInt(sc.next());\n        int[] a = new int[N];\n        int[] flag = new int[N];\n        int ans = 0;\n        for (int i=0;i<N;i++) {\n            a[i] = Integer.parseInt(sc.next());\n        }\n        Arrays.sort(a);\n        for (int i=0;i<N;i++) {\n            int used = 0;\n            for (int j=0;j<N;j++) {\n                if (flag[j]==1) {\n                    continue;\n                } else {\n                    if (a[j]%a[i]==0) {\n                        used=1;\n                        flag[j]=1;\n                    }\n                }\n            }\n            if (used==1) {\n                ans++;\n            }\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class a1 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint a[] = new int[n];\n\t\tHashMap<Integer,ArrayList<Integer>> h = new HashMap<>();\n\t\tboolean visited[] = new boolean[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\ta[i] = s.nextInt();\n\t\t\t\n\t\t\t\n\t\t}\n\t\tArrays.sort(a);\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(h.containsKey(a[i])) {\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tArrayList<Integer> temp = h.get(a[i]);\n\t\t\t\t\t\t\ttemp.add(i);\n\t\t\t\t\t\t\th.put(a[i],temp);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tArrayList<Integer> k =new ArrayList<>();\n\t\t\t\t\t\t\tk.add(i);\n\t\t\t\t\t\t\th.put(a[i], k);\n\t\t\t\t\t\t}\n\t\t}\n\t\tint ctr=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(!visited[i]) {\n\t\t\t\t//System.out.println(a[i]);\n\t\t\t\tctr++;\n\t\t\t\tfor(int j=a[i];j<=100;j+=a[i]) {\n\t\t\t\t\tif(h.containsKey(j)) {\n\t\t\t\t\t\tArrayList<Integer> m = h.get(j);\n\t\t\t\t\t\tfor(int k=0;k<m.size();k++) {\n\t\t\t\t\t\t\tvisited[m.get(k)]=true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\th.remove(j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ctr);\n\t}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\n\npublic class PTM {\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter printWriter = new PrintWriter(System.out);\n        int N = Integer.parseInt(bufferedReader.readLine());\n        String[] strings = bufferedReader.readLine().split(\" \");\n        int[] arr = new int[strings.length];\n        HashSet<Integer> set = new HashSet<>();\n        for (int i = 0; i < N; i++) {\n            arr[i] = Integer.parseInt(strings[i]);\n            set.add(arr[i]);\n        }\n        Arrays.sort(arr);\n        int c = 0;\n        for (int i = 0; i < N; i++) {\n            int value = arr[i];\n            if (!set.contains(value)) {\n                continue;\n            }\n            for (int j = 1; j <= 100; j++) {\n                if (set.contains(value * j)) {\n                    set.remove(value * j);\n                }\n            }\n            c++;\n        }\n        printWriter.println(c);\n        printWriter.flush();\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    FastScanner in;\n    PrintWriter out;\n\n    void solve() {\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        Arrays.sort(a);\n        int res = 0;\n        for (int i = 0; i < n; i++) {\n            boolean ok = false;\n            for (int j = 0; j < i; j++) {\n                if (a[i] % a[j] == 0) {\n                    ok = true;\n                }\n            }\n            if (!ok) {\n                res++;\n            }\n        }\n        out.println(res);\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Dasha {\n    static Scanner sc = new Scanner(System.in);\n    static PrintWriter pw = new PrintWriter(System.out), pw2 = new PrintWriter(System.out);\n\n    public static void main(String[] args) throws IOException {\n        int n=sc.nextInt();\n        int[] arr=new int[101];\n        for(int i=0;i<n;i++)\n            arr[sc.nextInt()]++;\n        boolean [] vis=new boolean[101];\n        int c=0;\n        for(int i=1;i<=100;i++){\n            if(!vis[i]&&arr[i]>0){\n                c++;\n                for(int j=i+i;j<=100;j+=i)\n                    vis[j]=true;\n            }\n        }\n        pw.println(c);\n        pw.flush();\n    }\n\n    public static <E> void print2D(E[][] arr) {\n        for (int i = 0; i < arr.length; i++) {\n            for (int j = 0; j < arr[i].length; j++) {\n                pw.println(arr[i][j]);\n            }\n        }\n    }\n\n    public static int digitSum(String s) {\n        int toReturn = 0;\n        for (int i = 0; i < s.length(); i++) toReturn += Integer.parseInt(s.charAt(i) + \" \");\n        return toReturn;\n    }\n\n    public static boolean isPrime(long n) {\n        if (n <= 1)\n            return false;\n        if (n <= 3)\n            return true;\n\n        if (n % 2 == 0 || n % 3 == 0)\n            return false;\n\n        for (long i = 5; i * i <= n; i = i + 6)\n            if (n % i == 0 || n % (i + 2) == 0)\n                return false;\n        return true;\n    }\n\n    public static long pow(long a, long pow) {\n        return pow == 0 ? 1 : pow % 2 == 0 ? pow(a * a, pow >> 1) : a * pow(a * a, pow >> 1);\n    }\n\n    public static long sumNum(long a) {\n        return a * (a + 1) / 2;\n    }\n\n    public static int gcd(int n1, int n2) {\n        return n2 == 0 ? n1 : gcd(n2, n1 % n2);\n    }\n\n    public static long factorial(long a) {\n        return a == 0 || a == 1 ? 1 : a * factorial(a - 1);\n    }\n\n    public static void sort(int arr[]) {\n        shuffle(arr);\n        Arrays.sort(arr);\n    }\n\n    public static void shuffle(int arr[]) {\n        Random rnd = new Random();\n        for (int i = arr.length - 1; i > 0; i--) {\n            int index = rnd.nextInt(i + 1);\n            int temp = arr[index];\n            arr[index] = arr[i];\n            arr[i] = temp;\n        }\n    }\n\n    public static Double[] solveQuadratic(double a, double b, double c) {\n        double result = (b * b) - 4.0 * a * c;\n        double r1;\n        if (result > 0.0) {\n            r1 = ((double) (-b) + Math.pow(result, 0.5)) / (2.0 * a);\n            double r2 = ((double) (-b) - Math.pow(result, 0.5)) / (2.0 * a);\n            return new Double[]{r1, r2};\n        } else if (result == 0.0) {\n            r1 = (double) (-b) / (2.0 * a);\n            return new Double[]{r1, r1};\n        } else {\n            return new Double[]{null, null};\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    static class pair<E1, E2> implements Comparable<pair> {\n        E1 x;\n        E2 y;\n\n        pair(E1 x, E2 y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        @Override\n        public int compareTo(pair o) {\n            return x.equals(o.x) ? (Integer) y - (Integer) o.y : (Integer) x - (Integer) o.x;\n        }\n\n        @Override\n        public String toString() {\n            return x + \" \" + y;\n        }\n\n        public double pointDis(pair p1) {\n            return Math.sqrt(((Integer) y - (Integer) p1.y) * ((Integer) y - (Integer) p1.y) + ((Integer) x - (Integer) p1.x) * ((Integer) x - (Integer) p1.x));\n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n    public static void main(String[] args) {\n        FastReader in = new FastReader();\n        int n = in.nextInt();\n        int[] a = new int[101];\n        for (int i = 0; i < n; i++) {\n            a[in.nextInt()]++;\n        }\n        int count = 0;\n        for (int i = 1; i < 101; i++) {\n            if (a[i] > 0) {\n                count++;\n                for (int j = i; j < 101; j += i) {\n                    a[j] = 0;\n                }\n            }\n        }\n        System.out.println(count);\n\n    }\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new\n                    InputStreamReader(System.in));\n        }\n\n        public 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 int[] nextSortedIntArray(int n) {\n            int array[] = nextIntArray(n);\n            Arrays.sort(array);\n            return array;\n        }\n\n        public int[] nextSumIntArray(int n) {\n            int[] array = new int[n];\n            array[0] = nextInt();\n            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();\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) array[i] = nextLong();\n            return array;\n        }\n\n        public long[] nextSumLongArray(int n) {\n            long[] array = new long[n];\n            array[0] = nextInt();\n            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();\n            return array;\n        }\n\n        public long[] nextSortedLongArray(int n) {\n            long array[] = nextLongArray(n);\n            Arrays.sort(array);\n            return array;\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, FastReader s, PrintWriter w) {\n            int n = s.nextInt();\n            boolean[] b = new boolean[n];\n            int[] a = new int[n];\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                a[i] = s.nextInt();\n            }\n            func.sort(a);\n            for (int i = 0; i < n; i++) {\n                if (!b[i]) {\n                    ans++;\n                    b[i] = true;\n                    for (int j = i + 1; j < n; j++) {\n                        //w.println(a[j]+\" \"+a[i]);\n                        if (a[j] % a[i] == 0) {\n                            b[j] = true;\n                        }\n                    }\n                }\n            }\n            w.println(ans);\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 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    static class func {\n        public static void sort(int[] arr) {\n            int n = arr.length, mid, h, s, l, i, j, k;\n            int[] res = new int[n];\n            for (s = 1; s < n; s <<= 1) {\n                for (l = 0; l < n - 1; l += (s << 1)) {\n                    h = Math.min(l + (s << 1) - 1, n - 1);\n                    mid = Math.min(l + s - 1, n - 1);\n                    i = l;\n                    j = mid + 1;\n                    k = l;\n                    while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]);\n                    while (i <= mid) res[k++] = arr[i++];\n                    while (j <= h) res[k++] = arr[j++];\n                    for (k = l; k <= h; k++) arr[k] = res[k];\n                }\n            }\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n    public static void main(String [] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        int n = scanner.nextInt();\n        int numbers[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            numbers[i] = scanner.nextInt();\n        }\n        scanner.close();\n        Arrays.sort(numbers);\n\n        boolean[] colored = new boolean[n];\n        int res = 0;\n\n        for (int i = 0; i < n; i++) {\n            if (!colored[i]) {\n                res += 1;\n            }\n            for (int j = i; j < n; j++) {\n                if (numbers[j] % numbers[i] == 0) {\n                    colored[j] = true;\n                }\n            }\n        }\n\n        System.out.println(res);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "//package practice;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.Stack;\nimport java.util.regex.Pattern;\n\npublic class ROUGH {\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\t\n\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\tstatic long mod = (long) (1e9+7);\n\tstatic int N = (int) 1e5;\n//\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\t FastReader sc = new FastReader();\n\t\t int n = sc.nextInt();\n\t\t int[] a = new int[n];\n\t\t TreeSet<Integer> set = new TreeSet<Integer>();\n\t\t for(int i=0;i<n;++i) {\n\t\t\t a[i] = sc.nextInt();\n\t\t\t set.add(a[i]);\n\t\t }\n\t\t long ans = 0;\n\t\t while(set.size() > 0) {\n\t\t\t ++ans;\n\t\t\t int min = set.first();\n\t\t\t TreeSet<Integer> temp = new TreeSet<>();\n\t\t\t for(int x : set) {\n\t\t\t\t if(x%min != 0) temp.add(x);\n\t\t\t }\n\t\t\t set = temp;\n\t\t\t \n\t\t }\n\t\t out.print(ans);\n\t\t \n\t\t out.close();\n\t}\n\t\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Contest {\n\n    final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    public static void main(String[] args) {\n        new Contest().run();\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    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(ms) = \" + (t2 - t1));\n        } catch (Exception e) {\n            e.printStackTrace(System.err);\n            System.exit(-1);\n        }\n    }\n\n    class MyComparator implements Comparable<MyComparator> {\n\n        int x;\n        int y;\n\n        public MyComparator(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        @Override\n        public int compareTo(MyComparator a) {\n            if (x == a.x) {\n                return (y - a.y);\n            }\n            return x - a.x;\n        }\n    }\n\n    public static boolean isPrime(int num) {\n        if (num > 2 && num % 2 == 0) {\n            //System.out.println(num + \" is not prime\");\n            return false;\n        }\n        int top = (int) Math.sqrt(num) + 1;\n        for (int i = 3; i < top; i += 2) {\n            if (num % i == 0) {\n                //System.out.println(num + \" is not prime\");\n                return false;\n            }\n        }\n        //System.out.println(num + \" is prime\");\n        return true;\n    }\n\n    private static int lowerBound(int[] a, int low, int high, int element) {\n        while (low < high) {\n            int middle = low + (high - low) / 2;\n            if (element > a[middle]) {\n                low = middle + 1;\n            } else {\n                high = middle;\n            }\n        }\n        return low;\n    }\n\n    private static int upperBound(int[] a, int low, int high, int element) {\n        while (low < high) {\n            int middle = low + (high - low) / 2;\n            if (a[middle] > element) {\n                high = middle;\n            } else {\n                low = middle + 1;\n            }\n        }\n        return low;\n    }\n\n    public void solve() throws IOException {\n\n        int num_a = readInt();\n        int[] array = new int[num_a];\n        for (int i = 0; i < num_a; i++) {\n            array[i] = readInt();\n        }\n        int result = 0;\n\n        Arrays.sort(array);\n        for (int i = 0; i < array.length; i++) {\n            if (array[i] == -1) {\n                continue;\n            }\n            for (int j = 0; j < array.length; j++) {\n                if (array[j] != -1 && array[j] % array[i] == 0 && j != i) {\n                    //System.out.println(array[j]);\n                    array[j] = -1;\n                    //result++;\n                }\n            }\n            result++;\n        }\n\n        System.out.println(result);\n    }\n\n    /**\n     *\n     * @param a\n     * @param b\n     * @return\n     */\n    private BigInteger lcm(BigInteger a, BigInteger b) {\n        return a.multiply(b.divide(a.gcd(b)));\n    }\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n\npublic class Colours {\n    public static void main(String args[] ) throws Exception {\n\n    \n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String line = br.readLine();\n        int n = Integer.parseInt(line);\n        line = br.readLine();\n        String[] values = line.split(\" \");\n        int[] arr = new int[n];\n        TreeSet<Integer> set = new TreeSet<>();\n        for (int i = 0; i < n; i++) {\n            arr[i] = Integer.parseInt(values[i]);\n            set.add(arr[i]);\n        }\n        int count=0;\n        TreeSet<Integer> copy = new TreeSet<>();\n        \n        // for(int i=0;i<n;i++)\n        copy.addAll(set);\n        int prev = copy.size();\n        \n        for(Integer i: set){\n           // System.out.println(\"i \"+i);\n            if(copy.size()==0){\n                break;\n            }\n            Iterator<Integer> iterator = copy.iterator();\n            while (iterator.hasNext()) {\n                Integer e = iterator.next();\n                if (e % i == 0) {\n                    iterator.remove();\n                }\n            }\n            if(copy.size()!=prev){\n                count++;\n                prev = copy.size();\n            }\n           // System.out.println(\"size \"+copy.size());\n            \n        }\n        \n\n        System.out.println(count);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\nimport static java.lang.Math.*;\npublic class Main implements Runnable\n{\n    boolean multiiple = false;\n\n    void solve() throws Exception\n    {\n        int n = sc.nextInt();\n\n        ArrayList<Integer> list = new ArrayList<>();\n        for (int i = 0; i < n; i++)\n            list.add(sc.nextInt());\n        Collections.sort(list);\n        int ans = 0;\n        while (!list.isEmpty())\n        {\n            ans++;\n            int next = list.get(0);\n            for (int i = list.size() - 1; i >= 1; i--)\n            {\n                if (list.get(i) % next == 0)\n                    list.remove(i);\n            }\n            list.remove(0);\n        }\n\n        System.out.println(ans);\n    }\n\n    @Override\n    public void run()\n    {\n        try\n        {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n            sc = new FastScanner(in);\n            if (multiiple)\n            {\n                int q = sc.nextInt();\n                for (int i = 0; i < q; i++)\n                    solve();\n            }\n            else\n                solve();\n        }\n        catch (Throwable uncaught)\n        {\n            Main.uncaught = uncaught;\n        }\n        finally\n        {\n            out.close();\n        }\n    }\n\n    public static void main(String[] args) throws Throwable {\n        Thread thread = new Thread(null, new Main(), \"\", (1 << 26));\n        thread.start();\n        thread.join();\n        if (Main.uncaught != null) {\n            throw Main.uncaught;\n        }\n    }\n\n    static Throwable uncaught;\n    BufferedReader in;\n    FastScanner sc;\n    PrintWriter out;\n}\n\nclass FastScanner\n{\n    BufferedReader in;\n    StringTokenizer st;\n\n    public FastScanner(BufferedReader in)\n    {\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n \npublic class Kaudo {\n    static Reader in =new Reader();\n    static StringBuilder Sd=new StringBuilder();\n    static long ans,res,lot,max;\n    static List<Integer>gr[];\n    static ArrayList<Integer> A=new ArrayList();\n    static String ch[];\n     public static void main(String [] args) {\n        int n=in.nextInt(),a[]=new int [n],g=0;\n        for(int i=0;i<n;i++){\n        a[i]=in.nextInt();\n        if(a[i]==1){System.out.println(\"1\");return;}\n        }\n        ans=0;\n        Arrays.sort(a);\n        for(int i=0;i<n;i++){\n            int x=a[i];\n            if(x>0){ans++;\n        for(int u=i;u<n;u++){\n        if(a[u]%x==0){a[u]=0;}\n        \n        }}\n        \n        }\n         System.out.println(ans);\n     }\n     static int gcd(int a,int b){\n     if(b==0)return a;\n     return gcd(b,a%b);\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 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 boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; }\n    }\n    \n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class PaintNumbers {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int[] nums = new int[n];\n        for (int i = 0; i < n; i++) {\n            nums[i] = in.nextInt();\n        }\n\n        boolean[] visited = new boolean[n];\n        int min = Integer.MAX_VALUE;\n        int a = 0;\n        boolean cont = true;\n        while (cont) {\n            for (int i = 0; i < n; i++) {\n                if (!visited[i]) {\n                    min = Math.min(min, nums[i]);\n                }\n            }\n\n            cont = false;\n            for (int i = 0; i < n; i++) {\n                if (!visited[i] && nums[i] % min == 0) {\n                    cont = true;\n                    visited[i] = true;\n                }\n            }\n            a++;\n            min = Integer.MAX_VALUE;\n        }\n        System.out.println(a - 1);\n    }\n\n\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.sort;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.copyOfRange;\nimport static java.util.Arrays.binarySearch;\n \nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\n \nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\n \nimport java.util.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.MathContext;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = in.nextInt();\n\t\tint[] a = in.nextIntArray(n);\n\t\tsort(a);\n\t\tint ans = 0;\n\t\tboolean[] done = new boolean[n];\n\t\tfor(int i = 0; i < n; i ++) {\n\t\t\tif(done[i])\n\t\t\t\tcontinue;\n\t\t\tans ++;\n\t\t\tfor(int j = i + 1; j < n; j ++)\n\t\t\t\tif(a[j] % a[i] == 0)\n\t\t\t\t\tdone[j] = true;\n\t\t}\n\t\tout.write(ans + \"\\n\");\n\t\tout.flush();\n\t}\n \n\tpublic static FastReader in = new FastReader();\n\tpublic static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\n\tpublic static void gcj(int cn, Object ans) throws IOException {\n\t\tSystem.out.print(\"Case #\" + cn + \": \" + ans + \"\\n\");\n\t}\n\t\n\tpublic static ArrayList <Integer>[] ALArrayI(int size) {\n\t\tArrayList <Integer>[] l = new ArrayList[size];\n\t\tfor(int i = 0; i < size; i ++)\n\t\t\tl[i] = new ArrayList <> ();\n\t\treturn l;\n\t}\n\t\n\tpublic static ArrayList <Long>[] ALArrayL(int size) {\n\t\tArrayList <Long>[] l = new ArrayList[size];\n\t\tfor(int i = 0; i < size; i ++)\n\t\t\tl[i] = new ArrayList <> ();\n\t\treturn l;\n\t}\n\t\n\tpublic static Integer[] integerList(int fi, int fo) {\n\t\tInteger[] l = new Integer[fo - fi];\n\t\tfor(int i = 0; i < fo - fi; i ++)\n\t\t\tl[i] = fi + i;\n\t\treturn l;\n\t}\n}\n \nclass Graph {\n\tTreeSet <Integer>[] g;\n\t\n\tpublic Graph(int n) {\n\t\tg = new TreeSet[n];\n\t\tfor(int i = 0; i < n; i ++)\n\t\t\tg[i] = new TreeSet <> ();\n\t}\n\t\n\tpublic void addEdge(int u, int v) {\n\t\tg[u].add(v);\n\t}\n\t\n\tpublic TreeSet <Integer> getAdj(int u) {\n\t\treturn g[u];\n\t}\n\t\n\tpublic int nodes() {\n\t\treturn g.length;\n\t}\n}\n \nclass FastReader {\n    BufferedReader br;\n    StringTokenizer st;\n \n    public FastReader() {\n        br = new BufferedReader(new InputStreamReader(System.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 char nextChar() {\n    \treturn next().charAt(0);\n    }\n    \n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n \n    public long nextLong() {\n        return Long.parseLong(next());\n    }\n \n    public double nextDouble() {\n        return Double.parseDouble(next());\n    }\n \n    public String nextLine() {\n        String str = \"\";\n        try {\n            str = br.readLine();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n        return str;\n    }\n    \n    public int[] nextIntArray(int n) {\n    \tint[] a = new int[n];\n    \tfor(int i = 0; i < n; i ++)\n    \t\ta[i] = nextInt();\n    \treturn a;\n    }\n    \n    public Integer[] nextIntegerArray(int n) {\n    \tInteger[] a = new Integer[n];\n    \tfor(int i = 0; i < n; i ++)\n    \t\ta[i] = nextInt();\n    \treturn a;\n    }\n    \n    public long[] nextLongArray(int n) {\n    \tlong[] a = new long[n];\n    \tfor(int i = 0; i < n; i ++)\n    \t\ta[i] = nextLong();\n    \treturn a;\n    }\n    \n    public double[] nextDoubleArray(int n) {\n    \tdouble[] a = new double[n];\n    \tfor(int i = 0; i < n; i ++)\n    \t\ta[i] = nextDouble();\n    \treturn a;\n    }\n    \n    public String[] nextStringArray(int n) {\n    \tString[] a = new String[n];\n    \tfor(int i = 0; i < n; i ++)\n    \t\ta[i] = next();\n    \treturn a;\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\npublic class TaskA implements Runnable {\n    long m = (int) 1e9 + 7;\n    PrintWriter w;\n    InputReader c;\n    /*Global Variables*/\n\n    public void run() {\n        c = new InputReader(System.in);\n        w = new PrintWriter(System.out);\n        int n = c.nextInt();\n        int a[] = scanArrayI(n);\n        boolean vis[] = new boolean[n];\n        Arrays.sort(a);\n        int ans=0;\n        for(int i=0;i<n;i++){\n            if(vis[i]) continue;\n            vis[i] = true;\n            for(int j=i+1;j<n;j++){\n                if(a[j]%a[i] == 0){\n                    vis[j] = true;\n                }\n            }\n            ans++;\n            boolean check = false;\n            for(int j=0;j<n;j++){\n                if(!vis[j]) check = true;\n            }\n            if(!check) break;\n        }\n\n        w.println(ans);\n\n        w.close();\n    }\n\n    class pair{\n        int x,y,step;\n\n        @Override\n        public String toString() {\n            return \"pair{\" +\n                    \"x=\" + x +\n                    \", y=\" + y +\n                    \", step=\" + step +\n                    '}';\n        }\n\n        public pair(int x, int y, int s) {\n            this.x = x;\n            this.y = y;\n            step = s;\n        }\n    }\n    /*Template Stuff*/\n    class HashMapUtil<T, U> {\n        void addHash(HashMap<T, Integer> hm, T a) {\n            if (hm.containsKey(a)) hm.put(a, hm.get(a) + 1);\n            else hm.put(a, 1);\n        }\n\n        void iterateHashMap(HashMap<T, U> hm) {\n            for (Map.Entry<T, U> e : hm.entrySet()) {\n                T key = e.getKey();\n                U value = e.getValue();\n            }\n        }\n    }\n    public int search(int input[], int search) {\n        int low = 0;\n        int high = input.length - 1;\n        int mid;\n        while (low <= high) {\n            mid = low + ((high - low) / 2);\n            if (input[mid] == search) {\n                return mid;\n            } else if (input[mid] < search) {\n                low = mid + 1;\n            } else {\n                high = mid - 1;\n            }\n        }\n        return -1;\n    }\n    public void sort(int arr[]) {\n        int n = arr.length, mid, h, s, l, i, j, k;\n        int[] res = new int[n];\n        for (s = 1; s < n; s <<= 1) {\n            for (l = 0; l < n - 1; l += (s << 1)) {\n                h = min(l + (s << 1) - 1, n - 1);\n                mid = min(l + s - 1, n - 1);\n                i = l;\n                j = mid + 1;\n                k = l;\n                while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]);\n                while (i <= mid) res[k++] = arr[i++];\n                while (j <= h) res[k++] = arr[j++];\n                for (k = l; k <= h; k++) arr[k] = res[k];\n            }\n        }\n    }\n    public int nextPowerOf2(int num) {\n        if (num == 0) {\n            return 1;\n        }\n        if (num > 0 && (num & (num - 1)) == 0) {\n            return num;\n        }\n        while ((num & (num - 1)) > 0) {\n            num = num & (num - 1);\n        }\n        return num << 1;\n    }\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n    public static void sortbyColumn(int arr[][], int col) {\n        Arrays.sort(arr, new Comparator<int[]>() {\n            public int compare(int[] o1, int[] o2) {\n                return (Integer.valueOf(o1[col]).compareTo(o2[col]));\n            }\n        });\n\n    }\n    public void printArray(int[] a) {\n        for (int i = 0; i < a.length; i++)\n            w.print(a[i] + \" \");\n        w.println();\n    }\n    public int[] scanArrayI(int n) {\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++)\n            a[i] = c.nextInt();\n        return a;\n    }\n    public long[] scanArrayL(int n) {\n        long a[] = new long[n];\n        for (int i = 0; i < n; i++)\n            a[i] = c.nextLong();\n        return a;\n    }\n    public void printArray(long[] a) {\n        for (int i = 0; i < a.length; i++)\n            w.print(a[i] + \" \");\n        w.println();\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } 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            } 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    public static void main(String args[]) throws Exception {\n        new Thread(null, new TaskA(), \"TaskA\", 1 << 26).start();\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class PaintTheNumber {\n\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\t\n\t\tArrayList<Integer> l=new ArrayList<Integer>();\n\t\t\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tl.add(sc.nextInt());\n\t\t}\n\t\t\n\t\tboolean c=false;\n\t\t\n\t\t\n\t\t\tfor(int i=0; i<l.size(); i++) {\n\t\t\t\tif(l.get(i)==-1)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(int j=0; j<l.size(); j++) {\n\t\t\t\t\t\n\t\t\t\t\tif(i==j || l.get(j)==-1)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\telse {\n\t\t\t\t\t\tif(l.get(j)%l.get(i)==0) {\n\t\t\t\t\t\t\tl.set(j, -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\t\n\t\t\tint nbr=0;\n\t\t\tfor(int i=0; i<l.size(); i++)\n\t\t\t\tif(l.get(i)!=-1)\n\t\t\t\t\tnbr++;\n\t\t\tSystem.out.println(nbr);\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner input = new Scanner();\n        StringBuilder output = new StringBuilder();\n\n        int n = input.nextInt();\n        int[] a = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            a[i] = input.nextInt();\n        }\n\n        Arrays.sort(a);\n        boolean[] colored = new boolean[n];\n        int colors = 0;\n        for (int i = 0; i < n; i++) {\n            if (!colored[i]) {\n                colors ++;\n                colored[i] = true;\n                for (int j = i+1; j < n; j++) {\n                    if (a[j] % a[i] == 0) {\n                        colored[j] = true;\n                    }\n                }\n            }\n        }\n\n        System.out.println(colors);\n    }\n\n    private static class Scanner {\n        BufferedReader br; StringTokenizer st;\n        public Scanner(Reader in) { br = new BufferedReader(in); }\n        public Scanner() { this(new InputStreamReader(System.in)); }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try { st = new StringTokenizer(br.readLine());\n                } catch (IOException e) { e.printStackTrace(); } }\n            return st.nextToken(); }\n        int nextInt() { return Integer.parseInt(next()); }\n        long nextLong() { return Long.parseLong(next()); }\n        double nextDouble() { return Double.parseDouble(next()); }\n        String readNextLine() {\n            String str = \"\";\n            try { str = br.readLine();\n            } catch (IOException e) { e.printStackTrace(); }\n            return str; }\n        int[] readIntArray(int n) {\n            int[] a = new int[n];\n            for (int idx = 0; idx < n; idx++) { a[idx] = nextInt(); }\n            return a; }\n        long[] readLongArray(int n) {\n            long[] a = new long[n];\n            for (int idx = 0; idx < n; idx++) { a[idx] = nextLong(); }\n            return a; }\n    } // end Scanner\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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 gaidash\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        ARaskrashivanieChisel solver = new ARaskrashivanieChisel();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ARaskrashivanieChisel {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            final int MAX = 100;\n\n            int n = in.nextInt();\n            int[] a = in.nextSortedIntArray(n);\n\n            int ret = 0;\n            boolean[] used = new boolean[MAX + 1];\n            for (int i = 0; i < n; i++) {\n                if (!used[a[i]]) {\n                    used[a[i]] = true;\n                    ret++;\n                    for (int j = i + 1; j < n; j++) {\n                        if (a[j] % a[i] == 0 && !used[a[j]]) {\n                            used[a[j]] = true;\n                        }\n                    }\n                }\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(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 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 int[] nextSortedIntArray(int n) {\n            int array[] = nextIntArray(n);\n            Arrays.sort(array);\n            return array;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n \npublic class A {\n\t\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\tint t = 1;\n\t\twhile(t-->0) solver.solve(1, scan, out);\n\t\tout.close();\n\t}\n\t\n\tstatic class Task {\n\t\t\n\t\tpublic void solve(int testNumber, FastReader scan, PrintWriter out) {\n\t\t\tint n = scan.nextInt();\n\t\t\tint[] a = new int[n];\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tint count = 0;\n\t\t\tfor(int i = 0; i < n; i++) a[i] = scan.nextInt();\n\t\t\tArrays.sort(a);\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tif(b[i]) continue;\n\t\t\t\tcount++;\n\t\t\t\tfor(int j = i; j < n; j++) {\n\t\t\t\t\tif(a[j]%a[i] == 0) b[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(count);\n\t\t}\n\t}\n\t\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(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\t\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\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\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException{\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new PrintStream(System.out));\n        int n=Integer.parseInt(f.readLine());\n        StringTokenizer st=new StringTokenizer(f.readLine());\n        int[]arr=new int[n];\n        for(int i=0;i<n;i++){\n            arr[i]=Integer.parseInt(st.nextToken());\n        }\n        Arrays.sort(arr);\n        int ans=0;\n        boolean[]used=new boolean[n];\n        for(int i=0;i<n;i++){\n            if(!used[i]){\n                ans++;\n                for(int j=i+1;j<n;j++){\n                    if(!used[j] && arr[j]%arr[i]==0){\n                        used[j]=true;\n                    }\n                }\n                used[i]=true;\n            }\n        }\n        System.out.print(ans);\n        f.close();\n        out.close();\n    }\n}\nclass pair implements Comparable <pair>{\n    int num;\n    int idx;\n\n    public int compareTo(pair other){\n        return num- other.num;\n    }\n\n\n    pair(int a, int b)\n    {\n        num=a;\n        idx=b;\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n    static StringBuilder data = new StringBuilder();\n    final static FastReader in = new FastReader();\n\n\n    public static void main(String[] args) {\n        int n = in.nextInt();\n        int a[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n        Arrays.sort(a);\n        int answ = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i] != 0) {\n                for (int j = i + 1; j < n; j++) {\n                    if (a[j] % a[i] == 0) {\n                        a[j] = 0;\n                    }\n                }\n                answ++;\n                a[i]=0;\n            }\n        }\n        System.out.println(answ);\n    }\n\n\n    static void fileOut(String s) {\n        File out = new File(\"output.txt\");\n        try {\n            FileWriter fw = new FileWriter(out);\n            fw.write(s);\n            fw.flush();\n            fw.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n\n    }\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new\n                    InputStreamReader(System.in));\n        }\n\n        public FastReader(String path) {\n            try {\n                br = new BufferedReader(new\n                        InputStreamReader(new FileInputStream(path)));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        float nextFloat() {\n            return Float.parseFloat(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class first {\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\tint[] a=new int[n];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i]=s.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint count=0;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif(a[i]!=0) {\n\t\t\t\tint x=a[i];\n\t\t\t\tcount++;\n\t\t\t\tfor (int j = i; j < a.length; j++) {\n\t\t\t\t\tif(a[j]%x==0) {\n\t\t\t\t\t\ta[j]=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class PaintTheNumbers {\n    public static void main(String[] args) throws IOException {\n        int[] colors = new int[101];\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        int N = Integer.parseInt(st.nextToken());\n        st = new StringTokenizer(f.readLine());\n        for (int i = 0; i < N; i++) {\n            colors[Integer.parseInt(st.nextToken())]++;\n        }\n        int colorCount = 0;\n        for (int i = 1; i <= 100; i++) {\n            if (colors[i] != 0) {\n                colors[i] = 0;\n                for (int multiple = 2; multiple * i <= 100; multiple++) {\n                    colors[i*multiple] = 0;\n                }\n                colorCount++;\n            }\n        }\n        System.out.println(colorCount);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskA {\n\n    public static void main(String[] args) {\n        FastReader in = new FastReader(System.in);\n//        FastReader in = new FastReader(new FileInputStream(\"input.txt\"));\n        PrintWriter out = new PrintWriter(System.out);\n//        PrintWriter out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\n\n        int n = in.nextInt();\n\n        int[] a = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n        Arrays.sort(a);\n\n        int ans = 1;\n        for (int i = 1; i < n; i++) {\n            boolean bb = false;\n            for (int j = i - 1; j >= 0; j--) {\n                if (a[i] % a[j] == 0) {\n                    bb = true;\n                    break;\n                }\n            }\n            if (!bb) ans++;\n        }\n\n        out.println(ans);\n\n\n\n\n\n        out.close();\n    }\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastReader(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        Integer nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        Double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(nextLine());\n            }\n            return st.nextToken();\n        }\n\n        String nextLine() {\n            String s = \"\";\n            try {\n                s = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return s;\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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 unknown\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        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.i();\n            int[] a = in.ia(n);\n            RadixSort.radixSort(a);\n            boolean[] flag = new boolean[n];\n            int count = 0;\n            for (int i = 0; i < n; i++) {\n                if (!flag[i]) {\n                    ++count;\n                    flag[i] = true;\n                    for (int j = 0; j < n; j++) {\n                        if (!flag[j] && a[j] % a[i] == 0) {\n                            flag[j] = true;\n                        }\n                    }\n                }\n            }\n            out.printLine(count);\n        }\n\n    }\n\n    static class RadixSort {\n        public static int[] radixSort(int[] f) {\n            return radixSort(f, f.length);\n        }\n\n        public static int[] radixSort(int[] f, int n) {\n            // credits uwi\n            int[] to = new int[n];\n            {\n                int[] b = new int[65537];\n                for (int i = 0; i < n; i++) b[1 + (int) (f[i] & 0xffff)]++;\n                for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];\n                for (int i = 0; i < n; i++) to[b[(int) (f[i] & 0xffff)]++] = f[i];\n                int[] d = f;\n                f = to;\n                to = d;\n            }\n            {\n                int[] b = new int[65537];\n                for (int i = 0; i < n; i++) b[1 + (int) (f[i] >>> 16 & 0xffff)]++;\n                for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];\n                for (int i = 0; i < n; i++) to[b[(int) (f[i] >>> 16 & 0xffff)]++] = f[i];\n                int[] d = f;\n                f = to;\n                to = d;\n            }\n            return f;\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 is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0;\n        private int ptrbuf = 0;\n\n        public InputReader(InputStream is) {\n            this.is = is;\n        }\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        public int[] ia(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) a[i] = i();\n            return a;\n        }\n\n        public int i() {\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class A {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic class Fenvik {\n\t\tint[] sum;\n\n\t\tpublic Fenvik(int n) {\n\t\t\tsum = new int[n];\n\t\t}\n\n\t\tpublic void add(int x) {\n\t\t\tfor (; x < sum.length; x = (x | (x + 1))) {\n\t\t\t\tsum[x]++;\n\t\t\t}\n\t\t}\n\n\t\tpublic int sum(int r) {\n\t\t\tint ans = 0;\n\t\t\tfor (; r >= 0; r = (r & (r + 1)) - 1) {\n\t\t\t\tans += sum[r];\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t}\n\t\n\tpublic int gcd(int x, int y) {\n\t\tif (y == 0) {\n\t\t\treturn x;\n\t\t}\n\t\tif (x == 0) {\n\t\t\treturn y;\n\t\t}\n\t\treturn gcd(y, x % y);\n\t}\n\t\n\t\n\tpublic class Edge {\n\t\tint to;\n\t\tlong s;\n\n\t\tpublic Edge(int to, long s) {\n\t\t\tthis.to = to;\n\t\t\tthis.s = s;\n\t\t}\n\t}\n\t\n\tpublic long dfs(int v, int prev, long sumth, long minsum, long s) {\n\t\ttin[v] = timer;\n\t\ttimer++;\n\t\tup[v][0] = new Edge(prev, s);\n\t\tfor (int i = 1; i <= l; i++) {\n\t\t\tEdge e = up[v][i - 1];\n\t\t\tup[v][i] = new Edge(up[e.to][i - 1].to, up[e.to][i - 1].s + e.s);\n\t\t}\n\t\tminsum = Math.min(minsum, sumth);\n\t\tmaxup[v] = sumth - minsum;\n\t\tlong mxdown = sumth;\n\t\tfor (Edge e : list[v]) {\n\t\t\tif (e.to != prev) {\n\t\t\t\tmxdown = Math.max(mxdown, dfs(e.to, v, sumth + e.s, minsum, e.s));\n\t\t\t}\n\t\t}\n\t\ttout[v] = timer;\n\t\ttimer++;\n\t\tmaxdown[v] = mxdown - sumth;\n\t\treturn mxdown;\n\t}\n\t\n\tpublic boolean upper(int a1, int b1) {\n\t\treturn tin[a1] <= tin[b1] && tout[a1] >= tout[b1];\n\t}\n\t\n\tpublic Edge lca(int a, int b) {\n\t\tif (a == b) {\n\t\t\treturn new Edge(a, 0);\n\t\t}\n\t\tint v = -1;\n\t\tint a1 = a;\n\t\tint b1 = b;\n\t\tif (tin[a] <= tin[b] && tout[a] >= tout[b]) {\n\t\t\tv = b;\n\t\t\tlong lenb = 0;\n\t\t\tfor (int i = l; i >= 0; i--) {\n\t\t\t\ta1 = up[v][i].to;\n\t\t\t\tb1 = a;\n\t\t\t\tif (!(tin[a1] <= tin[b1] && tout[a1] >= tout[b1])) {\n\t\t\t\t\tlenb += up[v][i].s;\n\t\t\t\t\tv = up[v][i].to;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlenb += up[v][0].s;\n\t\t\tv = up[v][0].to;\n\t\t\treturn new Edge(v, lenb);\n\t\t}\n\t\tif (upper(b, a)) {\n\t\t\tv = a;\n\t\t\tlong lena = 0;\n\t\t\tfor (int i = l; i >= 0; i--) {\n\t\t\t\ta1 = up[v][i].to;\n\t\t\t\tb1 = b;\n\t\t\t\tif (!(tin[a1] <= tin[b1] && tout[a1] >= tout[b1])) {\n\t\t\t\t\tlena += up[v][i].s;\n\t\t\t\t\tv = up[v][i].to;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlena += up[v][0].s;\n\t\t\tv = up[v][0].to;\n\t\t\treturn new Edge(v, lena);\n\t\t}\n\t\tv = a;\n\t\tlong lena = 0;\n\t\tfor (int i = l; i >= 0; i--) {\n\t\t\ta1 = up[v][i].to;\n\t\t\tb1 = b;\n\t\t\tif (!(tin[a1] <= tin[b1] && tout[a1] >= tout[b1])) {\n\t\t\t\tlena += up[v][i].s;\n\t\t\t\tv = up[v][i].to;\n\t\t\t}\n\t\t}\n\t\tlena += up[v][0].s;\n\t\tv = up[v][0].to;\n\t\tv = b;\n\t\tlong lenb = 0;\n\t\tfor (int i = l; i >= 0; i--) {\n\t\t\ta1 = up[v][i].to;\n\t\t\tb1 = a;\n\t\t\tif (!(tin[a1] <= tin[b1] && tout[a1] >= tout[b1])) {\n\t\t\t\tlenb += up[v][i].s;\n\t\t\t\tv = up[v][i].to;\n\t\t\t}\n\t\t}\n\t\tlenb += up[v][0].s;\n\t\tv = up[v][0].to;\n\t\treturn new Edge(v, lena + lenb);\n\t}\n\t\n\tint n;\n\tint l;\n\tint[] tin;\n\tint[] tout;\n\tint timer = 0;\n\tlong[] maxup;\n\tlong[] maxdown;\n\tEdge[][] up;\n\tArrayList<Edge>[] list;\n\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint ans = 0;\n\t\tboolean[] used = new boolean[n];\n\t\tfor (int i = 0; i < used.length; i++) {\n\t\t\tif (!used[i]) {\n\t\t\t\tans++;\n\t\t\t\tfor (int j = i; j < used.length; j++) {\n\t\t\t\t\tif (a[j] % a[i] == 0) {\n\t\t\t\t\t\tused[j] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (systemIO) {\n\t\t\t\tin = new FastScanner(System.in);\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t} else {\n\t\t\t\tin = new FastScanner(new File(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t\t}\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tFastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString nextLine() {\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t}\n\n\t// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n\tpublic static void main(String[] arg) {\n\t\tnew A().run();\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class A extends PrintWriter {\n\n    void run() {\n        int n = nextInt();\n        int m = 101;\n        boolean[] c = new boolean[m];\n\n        for (int i = 0; i < n; i++) {\n            int v = nextInt();\n            c[v] = true;\n        }\n\n        int ans = 0;\n\n        for (int v = 1; v < m; v++) {\n            if (c[v]) {\n                ++ans;\n                for (int u = v; u < m; u += v) {\n                    c[u] = false;\n                }\n\n            }\n        }\n\n        println(ans);\n\n    }\n\n    boolean skip() {\n        while (hasNext()) {\n            next();\n        }\n        return true;\n    }\n\n    int[][] nextMatrix(int n, int m) {\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] = nextInt();\n        return matrix;\n    }\n\n    String next() {\n        while (!tokenizer.hasMoreTokens())\n            tokenizer = new StringTokenizer(nextLine());\n        return tokenizer.nextToken();\n    }\n\n    boolean hasNext() {\n        while (!tokenizer.hasMoreTokens()) {\n            String line = nextLine();\n            if (line == null) {\n                return false;\n            }\n            tokenizer = new StringTokenizer(line);\n        }\n        return true;\n    }\n\n    int[] nextArray(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    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 reader.readLine();\n        } catch (IOException err) {\n            return null;\n        }\n    }\n\n    public A(OutputStream outputStream) {\n        super(outputStream);\n    }\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer = new StringTokenizer(\"\");\n    static Random rnd = new Random();\n    static boolean OJ;\n\n    public static void main(String[] args) throws IOException {\n        OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n        A solution = new A(System.out);\n        if (OJ) {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            solution.run();\n        } else {\n            reader = new BufferedReader(new FileReader(new File(A.class.getName() + \".txt\")));\n            long timeout = System.currentTimeMillis();\n            while (solution.hasNext()) {\n                solution.run();\n                solution.println();\n                solution.println(\"----------------------------------\");\n            }\n            solution.println(\"time: \" + (System.currentTimeMillis() - timeout));\n        }\n        solution.close();\n        reader.close();\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Es1\n{\n    static IO io = new IO();\n    public static void main(String[] args)\n    {\n\t\tint n = io.getInt();\n\t\tint[] a = new int[n];\n\t\tfor(int i=0; i<n; i++)\n\t\t\ta[i] = io.getInt();\n\t\t\n\t\tArrays.sort(a);\n\t\tint[] color = new int[n];\n\t\tint num = 1;\n\t\tfor(int i=0; i<n; i++){\n\t\t\tif(color[i]==0){\n\t\t\t\tfor(int j=i+1; j<n; j++){\n\t\t\t\t\tif(a[j]%a[i]==0)\n\t\t\t\t\t\tcolor[j] = num;\n\t\t\t\t}\n\t\t\t\tnum++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tio.println(num-1);\n\n\t\t\n\t\t\n\t\t\n        io.close();\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\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[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n        int min;\n        int count = 0;\n        int c = 0;\n        while (count != n) {\n            min = 1000;\n            for (int i = 0; i < n; i++) {\n                if (a[i] < min) {\n                    min = a[i];\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                if (a[i] != 1000 && a[i] % min == 0) {\n                    count++;\n                    a[i] = 1000;\n                }\n            }\n            c++;\n        }\n        System.out.println(c);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "//package cf584d12;\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tMyScanner sc = new MyScanner();\n\t\tint n = sc.nextInt();\n\t\tInteger[] a = new Integer[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextInt();\n\t\tArrays.sort(a);\n\t\tboolean[] b = new boolean[n];\n\t\tint ans = 0;\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tif(!b[i]) {\n\t\t\t\tans++;\n\t\t\t\tfor(int j = i + 1; j < n; j++)\n\t\t\t\t\tif(a[j] % a[i] == 0)\n\t\t\t\t\t\tb[j] = true;\n\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport 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\tint n = sc.nextInt();\n\t\tint []a = new int [n];\n\t\tboolean []used = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < used.length; i++) {\n\t\t\tif (!used[i]){\n\t\t\t\tans++;\n\t\t\t  for (int j = i; j < used.length; j++) {\n\t\t\t\tif (a[j]%a[i] == 0){\n\t\t\t\t\tused[j] = true;\n\t\t\t\t}\n\t\t\t  }\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(ans);\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class algo_2701\n{\n    public static void main(String args[])\n    {\n        Scanner ex=new Scanner(System.in);\n        int n=ex.nextInt();\n        int arr[]=new int[n];\n        for(int i=0;i<n;i++)\n        arr[i]=ex.nextInt();\n        Arrays.sort(arr);\n        int ans=0;\n        int check[]=new int[n];\n        for(int i=0;i<n;i++)\n        {\n            if(check[i]==0)\n            {\n                ans++;\n                for(int j=i;j<n;j++)\n                {\n                    if(arr[j]%arr[i]==0)\n                    check[j]=1;\n                }\n            }\n        }\n        System.out.println(ans);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.concurrent.ThreadLocalRandom;\n\n@SuppressWarnings(\"Duplicates\")\n\npublic class solveLOL {\n    FastScanner in;\n    PrintWriter out;\n    boolean systemIO = true, multitests = false;\n    int INF = Integer.MAX_VALUE / 2;\n\n\n    void solve() {\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        boolean used[] = new boolean[n];\n        int k = 0;\n        for (int i = 0; i < n; i++) {\n            if (!used[i]) {\n                used[i] = true;\n                for (int j = i + 1; j < n; j++) {\n                    if (!used[j] && arr[j] % arr[i] == 0) {\n                        used[j] = true;\n                    }\n                }\n                k++;\n            }\n        }\n        System.out.println(k);\n\n\n\n    }\n\n    class pair implements Comparable<pair> {\n        int a;\n        int b;\n\n        pair(int A, int B) {\n            this.a = A;\n            this.b = B;\n        }\n\n        public int compareTo(pair o) {\n            return a != o.a ? Double.compare(a, o.a) : b - o.b;\n        }\n    }\n\n    void shuffleArray(long[] ar) {\n        Random rnd = ThreadLocalRandom.current();\n        for (int i = ar.length - 1; i > 0; i--) {\n            int index = rnd.nextInt(i + 1);\n            long a = ar[index];\n            ar[index] = ar[i];\n            ar[i] = a;\n        }\n    }\n\n    void printArray(long[] ar) {\n        for (long k : ar) {\n            System.out.print(k + \" \");\n        }\n        System.out.println();\n    }\n\n    void reverseArray(long[] ar) {\n        for (int i = 0, j = ar.length - 1; i < j; i++, j--) {\n            long a = ar[i];\n            ar[i] = ar[j];\n            ar[j] = a;\n        }\n    }\n\n    private void run() throws IOException {\n        if (systemIO) {\n            in = new solveLOL.FastScanner(System.in);\n            out = new PrintWriter(System.out);\n        } else {\n            in = new solveLOL.FastScanner(new File(\"input.txt\"));\n            out = new PrintWriter(new File(\"output.txt\"));\n        }\n        for (int t = multitests ? in.nextInt() : 1; t-- > 0; )\n            solve();\n\n        out.close();\n    }\n\n    class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastScanner(File f) {\n            try {\n                br = new BufferedReader(new FileReader(f));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n\n        FastScanner(InputStream f) {\n            br = new BufferedReader(new InputStreamReader(f));\n        }\n\n        String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                return null;\n            }\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n    }\n\n    public static void main(String[] arg) throws IOException {\n        new solveLOL().run();\n    }\n\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt();\n        int[] colors = new int[n];\n        for (int i = 0; i < n; i++) {\n            colors[i] = scanner.nextInt();\n        }\n        Arrays.sort(colors);\n        int amountOfColors = 0;\n        for (int i = 0; i < n; i++) {\n            if (colors[i] != 0){\n                amountOfColors++;\n                int color = colors[i];\n                for (int j = i; j < n; j++) {\n                    if (colors[j] % color == 0){\n                        colors[j] = 0;\n                    }\n                }\n            }\n        }\n        System.out.println(amountOfColors);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int n = sc.nextInt();\n        Integer[] a = new Integer[n];\n        for (int i = 0; i < n; i++)\n            a[i] = sc.nextInt();\n        int ans = 0;\n        boolean[] taken = new boolean[n];\n        Arrays.sort(a);\n        for (int i = 0; i < n; i++) {\n            if (taken[i]) continue;\n            ans++;\n            for (int j = i; j < n; j++)\n                if (a[j] % a[i] == 0) taken[j] = true;\n        }\n        out.println(ans);\n        out.flush();\n        out.close();\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        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()) 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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ques1 {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int b = sc.nextInt();\n        ArrayList<Integer> ar=new ArrayList<>();\n\n        for(int i=0;i<b;i++){\n            ar.add(sc.nextInt());\n        }\n\n        Collections.sort(ar);\n        int count=0;\n        int i=0;\n        while(ar.size()!=0)\n        {\n            int tmep=ar.get(i);\n            int v=ar.remove(i);\n            count++;\n            int j=0;\n            while(j<ar.size()){\n                if(ar.get(j)%tmep==0){\n                    int a=ar.remove(j);\n\n                }\n                else\n                    j++;\n            }\n\n        }\n        System.out.println(count);\n\n\n\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\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        StringTokenizer tokenizer = new StringTokenizer(br.readLine());\n        boolean[] arr = new boolean[101];\n        int[] nums = new int[n+1];\n        int colors = 0;\n        for(int i = 1; i <= n; i++) {\n            nums[i] = Integer.parseInt(tokenizer.nextToken());\n            arr[nums[i]] = true;\n        }\n        Arrays.parallelSort(nums);\n        for(int i = 1; i <= n; i++) {\n            boolean newColor = false;\n            if(!arr[nums[i]]) {\n                continue;\n            }\n            for(int j = nums[i]; j <= 100; j += nums[i]) {\n                if(arr[j]) {\n                    arr[j] = false;\n                    newColor = true;\n                }\n            }\n            if(newColor) {\n                colors++;\n            }\n        }\n        \n        bw.write(String.valueOf(colors));\n        br.close();\n        bw.close();\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Double.*;\nimport java.lang.Math.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew A().run();\n\t}\n\n\tpublic void run() throws Exception {\n\t\tFastIO file = new FastIO();\n\t\tint n = file.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) a[i] = file.nextInt();\n\t\tArrays.sort(a);\n\t\tboolean[] used = new boolean[n];\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!used[i]) {\n\t\t\t\tcount++;\n\t\t\t\tfor (int j = i; j < n; j++) {\n\t\t\t\t\tif (a[j] % a[i] == 0) {\n\t\t\t\t\t\tused[j] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\n\tpublic static class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastIO() {\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 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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "/**\n * ******* Created by bla on 14/9/19 6:17 PM*******\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class A1209 {\n    public static void main(String[] args) throws IOException {\n        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {\n            int n = input.nextInt();\n            int[] arr = input.readIntArray(n);\n\n            Arrays.sort(arr);\n            int ans =0;\n            boolean[] vis = new boolean[n];\n            for(int i=0;i<n;i++){\n                if(!vis[i]){\n                    vis[i]=true;\n                    for(int j=i+1;j<n;j++){\n                        if(!vis[j] && arr[j]%arr[i]==0){\n                            vis[j]=true;                    }\n                    }\n                    ans++;\n                }\n            }\n            System.out.println(ans);\n        }\n    }\n\n    interface Input extends Closeable {\n        String next() throws IOException;\n\n        default int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        default long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        default double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n\n        default int[] readIntArray() throws IOException {\n            return readIntArray(nextInt());\n        }\n\n        default int[] readIntArray(int size) throws IOException {\n            int[] array = new int[size];\n            for (int i = 0; i < array.length; i++) {\n                array[i] = nextInt();\n            }\n            return array;\n        }\n\n        default long[] readLongArray(int size) throws IOException {\n            long[] array = new long[size];\n            for (int i = 0; i < array.length; i++) {\n                array[i] = nextLong();\n            }\n            return array;\n        }\n    }\n\n    private static class StandardInput implements Input {\n        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n        private StringTokenizer stringTokenizer;\n\n        @Override\n        public void close() throws IOException {\n            reader.close();\n        }\n\n        @Override\n        public String next() throws IOException {\n            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n                stringTokenizer = new StringTokenizer(reader.readLine());\n            }\n            return stringTokenizer.nextToken();\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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();\n        int[] a = new int[n];\n        for(int i = 0; i< n; i++)a[i] = ni();\n        Arrays.sort(a);\n        int ans = 0;\n        for(int i = 0; i< n; i++){\n            if(a[i] == -1)continue;\n            ans++;\n            for(int j = i+1; j< n; j++)if(a[j]%a[i] == 0)a[j] = -1;\n        }\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    long IINF = (long)1e18, mod = (long)1e9+7;\n    final int INF = (int)1e9, MX = (int)2e6+5;\n    DecimalFormat df = new DecimalFormat(\"0.00000000\");\n    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;\n    static boolean multipleTC = false, memory = false, fileIO = false;\n    FastReader in;PrintWriter out;\n    void run() throws Exception{\n        if(fileIO){\n            in = new FastReader(\"input.txt\");\n            out = new PrintWriter(\"output.txt\");\n        }else {\n            in = new FastReader();\n            out = new PrintWriter(System.out);\n        }\n        //Solution Credits: Taranpreet Singh\n        int T = (multipleTC)?ni():1;\n        pre();\n        for(int t = 1; t<= T; t++)solve(t);\n        out.flush();\n        out.close();\n    }\n    public static void main(String[] args) throws Exception{\n        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n        else new Main().run();\n    }\n    \n    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}\n    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n    void p(Object o){out.print(o);}\n    void pn(Object o){out.println(o);}\n    void pni(Object o){out.println(o);out.flush();}\n    String n()throws Exception{return in.next();}\n    String nln()throws Exception{return in.nextLine();}\n    int ni()throws Exception{return Integer.parseInt(in.next());}\n    long nl()throws Exception{return Long.parseLong(in.next());}\n    double nd()throws Exception{return Double.parseDouble(in.next());}\n \n    class FastReader{\n        BufferedReader br;\n        StringTokenizer st;\n        public FastReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n \n        public FastReader(String s) throws Exception{\n            br = new BufferedReader(new FileReader(s));\n        }\n \n        String next() throws Exception{\n            while (st == null || !st.hasMoreElements()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch (IOException  e){\n                    throw new Exception(e.toString());\n                }\n            }\n            return st.nextToken();\n        }\n \n        String nextLine() throws Exception{\n            String str = \"\";\n            try{   \n                str = br.readLine();\n            }catch (IOException e){\n                throw new Exception(e.toString());\n            }  \n            return str;\n        }\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class mainA {\n    public static PrintWriter out = new PrintWriter(System.out);\n    public static FastScanner enter = new FastScanner(System.in);\n    public static void main(String[] args) throws IOException {\n        solve();\n        out.close();\n    }\n    public static boolean[] was;\n    private static void solve() throws IOException{\n        int n=enter.nextInt();\n        int[] arr=new int[n];\n        was=new boolean[n];\n        for (int i = 0; i <n ; i++) {\n            arr[i]=enter.nextInt();\n        }\n        Arrays.sort(arr);\n        int ans=0;\n        for (int i = 0; i <n ; i++) {\n            if(was[i]) continue;\n            find(i, arr);\n            ans++;\n        }\n        out.println(ans);\n    }\n\n    public static void find (int num, int[] arr){\n        for (int i = num+1; i <arr.length ; i++) {\n            if(arr[i]%arr[num]==0) was[i]=true;\n        }\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer stok;\n\n        FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        String next() 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(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        char nextChar() throws IOException {\n            return (char) (br.read());\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "// package cf1209;\n\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.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.Random;\n\npublic class CFA {\n    private static final String INPUT = \"8\\n\" +\n            \"7 6 5 4 3 2 2 3\\n\";\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 CFA().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 Color {\n        int nr;\n        boolean used;\n\n        public Color(int nr) {\n            this.nr = nr;\n        }\n    }\n\n    private void solve() {\n        int n = sc.nextInt();\n        Color[] a = new Color[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = new Color(sc.nextInt());\n        }\n        Arrays.sort(a, Comparator.comparingInt(c -> c.nr));\n\n        int ans = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i].used) continue;\n            ans++;\n\n            for (int j = i+1; j < n; j++) {\n                if (a[j].nr % a[i].nr == 0) {\n                    a[j].used = true;\n                }\n            }\n        }\n        out.println(ans);\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    int [] sort(int [] a) {\n        final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;\n        int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];\n        for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);\n        for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);\n        for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);\n        int [] t = a; a = ta; ta = t;\n        ai = new int [SIZE];\n        for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);\n        for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);\n        for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);\n        return ta;\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.<br>\n     * If searched element is bigger than any array element function returns first index after last element.<br>\n     * If searched element is lower than any array element function returns index of first element.<br>\n     * If there are many values equals searched value function returns first occurrence.<br>\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, Scanner in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.nextInt();\n            }\n            Arrays.sort(a);\n            int nc = 0;\n            for (int i = 0; i < n; i++) {\n                boolean divs = false;\n                for (int j = 0; j < i; j++) {\n                    if (a[i] % a[j] == 0) {\n                        divs = true;\n                        break;\n                    }\n                }\n                if (!divs) {\n                    nc++;\n                }\n            }\n            out.println(nc);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "/**\n * Date: 14 Sep, 2019\n * Link: \n * \n * @author Prasad-Chaudhari\n * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/\n * @git: https://github.com/Prasad-Chaudhari\n */\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\n\npublic class newProgram5 {\n\n    public static void main(String[] args) throws IOException {\n        // TODO code application logic here\n        FastIO in = new FastIO();\n        int n = in.ni();\n        int a[] = in.gia(n);\n        int freq[] = new int[100 + 1];\n        for (int i = 0; i < n; i++) {\n            freq[a[i]]++;\n        }\n        int k = 0;\n        for (int i = 1; i <= 100; i++) {\n            if (freq[i] > 0) {\n                for (int j = i; j <= 100; j += i) {\n                    freq[j] = 0;\n                }\n                k++;\n                // System.out.println(i);\n            }\n        }\n        System.out.println(k);\n        in.bw.flush();\n    }\n\n    static class FastIO {\n\n        private final BufferedReader br;\n        private final BufferedWriter bw;\n        private String s[];\n        private int index;\n        private final StringBuilder sb;\n\n        public FastIO() throws IOException {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            bw = new BufferedWriter(new OutputStreamWriter(System.out, \"UTF-8\"));\n            s = br.readLine().split(\" \");\n            sb = new StringBuilder();\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] = nl();\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] = nl();\n            }\n            return a;\n        }\n\n        public int[][][] gwtree(int n) throws IOException {\n            int m = n - 1;\n            int adja[][] = new int[n + 1][];\n            int weight[][] = new int[n + 1][];\n            int from[] = new int[m];\n            int to[] = new int[m];\n            int count[] = new int[n + 1];\n            int cost[] = new int[n + 1];\n            for (int i = 0; i < m; i++) {\n                from[i] = i + 1;\n                to[i] = ni();\n                cost[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n                weight[i] = new int[count[i]];\n            }\n            for (int i = 0; i < m; i++) {\n                adja[from[i]][count[from[i]] - 1] = to[i];\n                adja[to[i]][count[to[i]] - 1] = from[i];\n                weight[from[i]][count[from[i]] - 1] = cost[i];\n                weight[to[i]][count[to[i]] - 1] = cost[i];\n                count[from[i]]--;\n                count[to[i]]--;\n            }\n            return new int[][][] { adja, weight };\n        }\n\n        public int[][][] gwg(int n, int m) throws IOException {\n            int adja[][] = new int[n + 1][];\n            int weight[][] = new int[n + 1][];\n            int from[] = new int[m];\n            int to[] = new int[m];\n            int count[] = new int[n + 1];\n            int cost[] = new int[n + 1];\n            for (int i = 0; i < m; i++) {\n                from[i] = ni();\n                to[i] = ni();\n                cost[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n                weight[i] = new int[count[i]];\n            }\n            for (int i = 0; i < m; i++) {\n                adja[from[i]][count[from[i]] - 1] = to[i];\n                adja[to[i]][count[to[i]] - 1] = from[i];\n                weight[from[i]][count[from[i]] - 1] = cost[i];\n                weight[to[i]][count[to[i]] - 1] = cost[i];\n                count[from[i]]--;\n                count[to[i]]--;\n            }\n            return new int[][][] { adja, weight };\n        }\n\n        public int[][] gtree(int n) throws IOException {\n            int adja[][] = new int[n + 1][];\n            int from[] = new int[n - 1];\n            int to[] = new int[n - 1];\n            int count[] = new int[n + 1];\n            for (int i = 0; i < n - 1; i++) {\n                from[i] = i + 1;\n                to[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n            }\n            for (int i = 0; i < n - 1; i++) {\n                adja[from[i]][--count[from[i]]] = to[i];\n                adja[to[i]][--count[to[i]]] = from[i];\n            }\n            return adja;\n        }\n\n        public int[][] gg(int n, int m) throws IOException {\n            int adja[][] = new int[n + 1][];\n            int from[] = new int[m];\n            int to[] = new int[m];\n            int count[] = new int[n + 1];\n            for (int i = 0; i < m; i++) {\n                from[i] = ni();\n                to[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n            }\n            for (int i = 0; i < m; i++) {\n                adja[from[i]][--count[from[i]]] = to[i];\n                adja[to[i]][--count[to[i]]] = from[i];\n            }\n            return adja;\n        }\n\n        public void print(String s) throws IOException {\n            bw.write(s);\n        }\n\n        public void println(String s) throws IOException {\n            bw.write(s);\n            bw.newLine();\n        }\n\n        public void print(int s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(int s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\n        }\n\n        public void print(long s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(long s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\n        }\n\n        public void print(double s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(double s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\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    static class Data implements Comparable<Data> {\n\n        int a, b;\n\n        public Data(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public int compareTo(Data o) {\n            if (a == o.a) {\n                return Integer.compare(b, o.b);\n            }\n            return Integer.compare(a, o.a);\n        }\n\n        public static void sort(int a[]) {\n            Data d[] = new Data[a.length];\n            for (int i = 0; i < a.length; i++) {\n                d[i] = new Data(a[i], 0);\n            }\n            Arrays.sort(d);\n            for (int i = 0; i < a.length; i++) {\n                a[i] = d[i].a;\n            }\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "/**\n * Created by Alyssa Herbst on 9/14/19 9:05 AM.\n */\n\nimport java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class B {\n    static StringBuilder sb;\n    static int N;\n    static int[] A;\n    static boolean[] B;\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        //Scanner sc = new Scanner(System.in);\n        sb = new StringBuilder();\n        N = sc.nextInt();\n        A = new int[N];\n        for (int i = 0; i < N; i++) {\n            A[i] = sc.nextInt();\n        }\n        Arrays.sort(A);\n        B = new boolean[N];\n        int count = 0;\n        for (int i = 0; i < A.length; i++) {\n            if(B[i]) {\n                continue;\n            }\n            else {\n                count++;\n                B[i] = true;\n            }\n            for (int j = i + 1; j < A.length; j++) {\n                if(A[j] % A[i] == 0) {\n                    B[j] = true;\n                }\n            }\n        }\n        sb.append(count);\n        System.out.println(sb);\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[] readIntBrray(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[] readLongBrray(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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\n\npublic class a{\n    public static void main(String[] args)throws IOException{\n\tbr = new BufferedReader(new InputStreamReader(System.in));\n\tPrintWriter out = new PrintWriter(System.out);\n\tint n = nextInt();\n\tint v[] = new int[n];\n\tint fv[] = new int[101];\n\tfor(int i = 0; i<n;i++){\n\t    v[i] = nextInt();\n\t}\n\tArrays.sort(v);\n\tfor(int i = 0; i<n;i++){\n\t    for(int j = i; j<n;j++){\n\t\tif(v[j]%v[i]==0){\n\t\t    v[j] = v[i];\n\t\t    fv[v[j]]++;\n\t\t}\n\t    }\n\t}\n\tint ans = 0;\n\tfor(int i = 0; i<101;i++){\n\t    if(fv[i]!=0){\n\t\tans++;\n\t    }\n\t}\n\tout.println(ans);\n\tout.close();\n    }\n\n    static BufferedReader br;\n    static StringTokenizer st = new StringTokenizer(\"\");\n\n    static String next()throws IOException{\n\twhile(!st.hasMoreTokens()){\n\t    st = new StringTokenizer(br.readLine());\n\t}\n\treturn st.nextToken();\n    }\n    static int nextInt()throws IOException{\n\treturn Integer.parseInt(next());\n    }\n    \n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class ProblemA {\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\tString s1=br.readLine();\n\t\tString[] s=s1.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.parseInt(s[i]);\n\t\t}\n\t\tArrays.sort(a);\n\t\tSystem.out.println(findColour(a,n));\n\t}\n\tpublic static int findColour(int [] a , int n)\n\t{\n\t\tMap <Integer,Integer> mp = new HashMap<Integer,Integer>();\n\t\tint f=0;\n\t\tfor(int i = 0; i<n;i++)\n\t\t{\n\t\t\tf=0;\n\t\t\tfor (Map.Entry<Integer,Integer> entry : mp.entrySet()) \n\t\t\t{\n\t\t\t\tif(a[i] % entry.getKey()==0)\n\t\t\t\t{\n\t\t\t\t\tf=1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(f==0)\n\t\t\t{\n\t\t\t\tmp.put(a[i],1);\n\t\t\t}\n\t\t\t\t\n\t\t}\n\t\treturn mp.size();\n\t}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Loader {\n    private final static Scanner in = new Scanner(System.in);\n\n    public static void main(String[] args) {\n        int n = in.nextInt();\n        ArrayList<Integer> l = new ArrayList<>();\n\n        for (int i = 0; i < n; i++) {\n            l.add(in.nextInt());\n        }\n\n        Collections.sort(l);\n\n\n        int k = 0;\n        for (int i = 0; i < l.size(); i++) {\n            if (l.get(i) == 0) continue;\n            for (int j = i + 1; j < l.size(); j++) {\n                if (l.get(j) == 0) continue;\n                if (l.get(j) % l.get(i) == 0) {\n                    l.set(j, 0);\n                }\n            }\n\n            l.set(i, 0);\n            k++;\n        }\n\n        System.out.println(k);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n/**\n * https://codeforces.com/contests\n */\npublic class TaskA {\n\npublic static void main(String[] args) {\n    Scanner sc = new Scanner(System.in);\n    int n = sc.nextInt();\n    Set<Integer> set = new HashSet<>();\n    for (int i = 0; i < n; i++) {\n        int a = sc.nextInt();\n\n        boolean flag = false; // true = \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\n        List<Integer> toRemove = new ArrayList<>();\n        for (int b : set) {\n            if (a % b == 0) {\n                flag = true;\n                break;\n            } else if (b % a == 0 && a < b) {\n                toRemove.add(b);\n            }\n        }\n        for (int r: toRemove) {\n            set.remove(r);\n        }\n        if (!flag) {\n            set.add(a);\n        }\n    }\n    System.out.println(set.size());\n}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;import java.util.*;\nimport java.math.*;\n\npublic class Main{\n\tstatic int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;\n\tstatic BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st;\n    static int max(int a,int b)\n    {\n    \treturn Math.max(a, b);\n    }\n    static int min(int a,int b)\n    {\n    \treturn Math.min(a, b);\n    }\n    static int i()throws IOException\n    {\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \treturn Integer.parseInt(st.nextToken());\n    }\n    static long l()throws IOException\n    {\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \treturn Long.parseLong(st.nextToken());\n    }\n    static String s()throws IOException\n    {\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \treturn st.nextToken();\n    }\n    static double d()throws IOException\n    {\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \treturn Double.parseDouble(st.nextToken());\n    }\n    static void p(String p)\n    {\n    \tSystem.out.print(p);\n    }\n    static void p(int p)\n    {\n    \tSystem.out.print(p);\n    }\n    static void p(double p)\n    {\n    \tSystem.out.print(p);\n    }\n    static void p(long p)\n    {\n    \tSystem.out.print(p);\n    }\n    static void p(char p)\n    {\n    \tSystem.out.print(p);\n    }\n    static void p(boolean p)\n    {\n    \tSystem.out.print(p);\n    }\n    static void pl(String pl)\n    {\n    \tSystem.out.println(pl);\n    }\n    static void pl(int pl)\n    {\n    \tSystem.out.println(pl);\n    }\n    static void pl(char pl)\n    {\n    \tSystem.out.println(pl);\n    }\n    static void pl(double pl)\n    {\n    \tSystem.out.println(pl);\n    }\n    static void pl(long pl)\n    {\n    \tSystem.out.println(pl);\n    }\n    static void pl(boolean pl)\n    {\n    \tSystem.out.println(pl);\n    }\n    static void pl()\n    {\n    \tSystem.out.println();\n    }\n    static int[] ari(int n)throws IOException\n    {\n    \tint ar[]=new int[n];\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \tfor(int x=0;x<n;x++)\n    \t\tar[x]=Integer.parseInt(st.nextToken());\n    \treturn ar;\n    }\n    static int[][] ari(int n,int m)throws IOException\n    {\n    \tint ar[][]=new int[n][m];\n    \tfor(int x=0;x<n;x++)\n    \t{\n    \t\tst=new StringTokenizer(br.readLine());\n    \t\tfor(int y=0;y<m;y++)\n    \t\t\tar[x][y]=Integer.parseInt(st.nextToken());\n    \t}\n    \treturn ar;\n    }\n    static long[] arl(int n)throws IOException\n    {\n    \tlong ar[]=new long[n];\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \tfor(int x=0;x<n;x++)\n    \t\tar[x]=Long.parseLong(st.nextToken());\n    \treturn ar;\n    }\n    static long[][] arl(int n,int m)throws IOException\n    {\n    \tlong ar[][]=new long[n][m];\n    \tfor(int x=0;x<n;x++)\n    \t{\n    \t\tst=new StringTokenizer(br.readLine());\n    \t\tfor(int y=0;y<m;y++)\n    \t\t\tar[x][y]=Long.parseLong(st.nextToken());\n    \t}\n    \treturn ar;\n    }\n    static String[] ars(int n)throws IOException\n    {\n    \tString ar[]=new String[n];\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \tfor(int x=0;x<n;x++)\n    \t\tar[x]=st.nextToken();\n    \treturn ar;\n    }\n    static String[][] ars(int n,int m)throws IOException\n    {\n    \tString ar[][]=new String[n][m];\n    \tfor(int x=0;x<n;x++)\n    \t{\n    \t\tst=new StringTokenizer(br.readLine());\n    \t\tfor(int y=0;y<m;y++)\n    \t\t\tar[x][y]=st.nextToken();\n    \t}\n    \treturn ar;\n    }\n    static double[] ard(int n)throws IOException\n    {\n    \tdouble ar[]=new double[n];\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \tfor(int x=0;x<n;x++)\n    \t\tar[x]=Double.parseDouble(st.nextToken());\n    \treturn ar;\n    }\n    static double[][] ard(int n,int m)throws IOException\n    {\n    \tdouble ar[][]=new double[n][m];\n    \tfor(int x=0;x<n;x++)\n    \t{\n    \t\tst=new StringTokenizer(br.readLine());\n    \t\tfor(int y=0;y<m;y++)\n    \t\t\tar[x][y]=Double.parseDouble(st.nextToken());\n    \t}\n    \treturn ar;\n    }\n    static char[] arc(int n)throws IOException\n    {\n    \tchar ar[]=new char[n];\n    \tif(!st.hasMoreTokens())\n    \t\tst=new StringTokenizer(br.readLine());\n    \tfor(int x=0;x<n;x++)\n    \t\tar[x]=st.nextToken().charAt(0);\n    \treturn ar;\n    }\n    static char[][] arc(int n,int m)throws IOException\n    {\n    \tchar ar[][]=new char[n][m];\n    \tfor(int x=0;x<n;x++)\n    \t{\n    \t\tst=new StringTokenizer(br.readLine());\n    \t\tfor(int y=0;y<m;y++)\n    \t\t\tar[x][y]=st.nextToken().charAt(0);\n    \t}\n    \treturn ar;\n    }\n    static void par(int ar[])\n    {\n    \tfor(int a:ar)\n    \t\tSystem.out.print(a+\" \");\n    \tSystem.out.println();\n    }\n    static void par(int ar[][])\n    {\n    \tfor(int a[]:ar)\n    \t{\n    \t\tfor(int aa:a)\n    \t\t\tSystem.out.print(aa+\" \");\n    \t\tSystem.out.println();\n    \t}\n    }\n    static void par(long ar[])\n    {\n    \tfor(long a:ar)\n    \t\tSystem.out.print(a+\" \");\n    \tSystem.out.println();\n    }\n    static void par(long ar[][])\n    {\n    \tfor(long a[]:ar)\n    \t{\n    \t\tfor(long aa:a)\n    \t\t\tSystem.out.print(aa+\" \");\n    \t\tSystem.out.println();\n    \t}\n    }\n    static void par(String ar[])\n    {\n    \tfor(String a:ar)\n    \t\tSystem.out.print(a+\" \");\n    \tSystem.out.println();\n    }\n    static void par(String ar[][])\n    {\n    \tfor(String a[]:ar)\n    \t{\n    \t\tfor(String aa:a)\n    \t\t\tSystem.out.print(aa+\" \");\n    \t\tSystem.out.println();\n    \t}\n    }\n    static void par(double ar[])\n    {\n    \tfor(double a:ar)\n    \t\tSystem.out.print(a+\" \");\n    \tSystem.out.println();\n    }\n    static void par(double ar[][])\n    {\n    \tfor(double a[]:ar)\n    \t{\n    \t\tfor(double aa:a)\n    \t\t\tSystem.out.print(aa+\" \");\n    \t\tSystem.out.println();\n    \t}\n    }\n    static void par(char ar[])\n    {\n    \tfor(char a:ar)\n    \t\tSystem.out.print(a+\" \");\n    \tSystem.out.println();\n    }\n    static void par(char ar[][])\n    {\n    \tfor(char a[]:ar)\n    \t{\n    \t\tfor(char aa:a)\n    \t\t\tSystem.out.print(aa+\" \");\n    \t\tSystem.out.println();\n    \t}\n    }\n    static public void main(String[] args)throws Exception{\n    \tst=new StringTokenizer(br.readLine());\n    \tint n=i();\n    \tint ar[]=ari(n);\n    \tArrays.sort(ar);\n    \tint c=0;\n    \t\n    \t\tfor(int x=0;x<n;x++)\n    \t\t{\n    \t\t\tif(ar[x]!=-1)\n    \t\t\t{\n    \t\t\t\tc++;\n    \t\t\t\tfor(int y=x+1;y<n;y++)\n    \t\t\t\t{\n    \t\t\t\t\tif(ar[y]!=-1)\n    \t    \t\t\t{\n    \t\t\t\t\t\tif(ar[y]%ar[x]==0)\n    \t\t\t\t\t\t{\n    \t\t\t\t\t\t\tar[y]=-1;\n    \t\t\t\t\t\t}\n    \t    \t\t\t}\n    \t\t\t\t}\n    \t\t\t\tar[x]=-1;\n    \t\t\t}\n    \t\t}\n    \t\tpl(c);\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    \t\n    }\n}\n\n\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n\n\tpublic void realMain() throws Exception {\n\n\t\tBufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);\n\n\t\tString in = fin.readLine();\n\n\t\tString[] ar = in.split(\" \");\n\n\t\tint n = Integer.parseInt(ar[0]);\n\t\t\n\t\tint[] a = new int[n];\n\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint ret = 0;\n\t\t\tboolean dig = false;\n\t\t\tfor (int ch = 0; (ch = fin.read()) != -1; ) {\n        \t\t\tif (ch >= '0' && ch <= '9') {\n            \t\t\t\tdig = true;\n           \t\t\t\tret = ret * 10 + ch - '0';\n        \t\t\t} else if (dig) break;\n    \t\t\t}\n\n\t\t\ta[i] = ret;\n\t\t\t\n\t\t}\n\n\t\tint ret = 0;\n\n\t\tArrays.sort(a);\n\n\t\tboolean[] colored = new boolean[n];\n\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(!colored[i]) {\n\t\t\t\tret++;\n\t\t\t\tfor(int j = i; j < n; j++) {\n\t\t\t\t\tif(a[j] % a[i] == 0) {\n\t\t\t\t\t\tcolored[j] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ret);\n\n\n\n\t}\n\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tA a = new A();\n\t\ta.realMain();\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author 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        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, OutputWriter out) {\n            int n = in.readInt();\n            int[] a = in.readIntArray(n);\n            ArrayUtils.sort(a);\n            boolean[] done = new boolean[n];\n            int answer = 0;\n            for (int i = 0; i < n; i++) {\n                if (done[i]) {\n                    continue;\n                }\n                answer++;\n                for (int j = i; j < n; j++) {\n                    if (a[j] % a[i] == 0) {\n                        done[j] = true;\n                    }\n                }\n            }\n            out.printLine(answer);\n        }\n\n    }\n\n    static class Sorter {\n        private static final int INSERTION_THRESHOLD = 16;\n\n        private Sorter() {\n        }\n\n        public static void sort(IntList list, IntComparator comparator) {\n            quickSort(list, 0, list.size() - 1, (Integer.bitCount(Integer.highestOneBit(list.size()) - 1) * 5) >> 1,\n                    comparator);\n        }\n\n        private static void quickSort(IntList list, int from, int to, int remaining, IntComparator comparator) {\n            if (to - from < INSERTION_THRESHOLD) {\n                insertionSort(list, from, to, comparator);\n                return;\n            }\n            if (remaining == 0) {\n                heapSort(list, from, to, comparator);\n                return;\n            }\n            remaining--;\n            int pivotIndex = (from + to) >> 1;\n            int pivot = list.get(pivotIndex);\n            list.swap(pivotIndex, to);\n            int storeIndex = from;\n            int equalIndex = to;\n            for (int i = from; i < equalIndex; i++) {\n                int value = comparator.compare(list.get(i), pivot);\n                if (value < 0) {\n                    list.swap(storeIndex++, i);\n                } else if (value == 0) {\n                    list.swap(--equalIndex, i--);\n                }\n            }\n            quickSort(list, from, storeIndex - 1, remaining, comparator);\n            for (int i = equalIndex; i <= to; i++) {\n                list.swap(storeIndex++, i);\n            }\n            quickSort(list, storeIndex, to, remaining, comparator);\n        }\n\n        private static void heapSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = (to + from - 1) >> 1; i >= from; i--) {\n                siftDown(list, i, to, comparator, from);\n            }\n            for (int i = to; i > from; i--) {\n                list.swap(from, i);\n                siftDown(list, from, i - 1, comparator, from);\n            }\n        }\n\n        private static void siftDown(IntList list, int start, int end, IntComparator comparator, int delta) {\n            int value = list.get(start);\n            while (true) {\n                int child = ((start - delta) << 1) + 1 + delta;\n                if (child > end) {\n                    return;\n                }\n                int childValue = list.get(child);\n                if (child + 1 <= end) {\n                    int otherValue = list.get(child + 1);\n                    if (comparator.compare(otherValue, childValue) > 0) {\n                        child++;\n                        childValue = otherValue;\n                    }\n                }\n                if (comparator.compare(value, childValue) >= 0) {\n                    return;\n                }\n                list.swap(start, child);\n                start = child;\n            }\n        }\n\n        private static void insertionSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = from + 1; i <= to; i++) {\n                int value = list.get(i);\n                for (int j = i - 1; j >= from; j--) {\n                    if (comparator.compare(list.get(j), value) <= 0) {\n                        break;\n                    }\n                    list.swap(j, j + 1);\n                }\n            }\n        }\n\n    }\n\n    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {\n        public IntIterator intIterator();\n\n        default public Iterator<Integer> iterator() {\n            return new Iterator<Integer>() {\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 IntComparator {\n        public static final IntComparator DEFAULT = (first, second) -> {\n            if (first < second) {\n                return -1;\n            }\n            if (first > second) {\n                return 1;\n            }\n            return 0;\n        };\n\n        public int compare(int first, int second);\n\n    }\n\n    static class IntArray extends IntAbstractStream implements IntList {\n        private int[] data;\n\n        public IntArray(int[] arr) {\n            data = arr;\n        }\n\n        public int size() {\n            return data.length;\n        }\n\n        public int get(int at) {\n            return data[at];\n        }\n\n        public void addAt(int index, int value) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void removeAt(int index) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void set(int index, int value) {\n            data[index] = value;\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 abstract class IntAbstractStream implements IntStream {\n        public String toString() {\n            StringBuilder builder = new StringBuilder();\n            boolean first = true;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                if (first) {\n                    first = false;\n                } else {\n                    builder.append(' ');\n                }\n                builder.append(it.value());\n            }\n            return builder.toString();\n        }\n\n        public boolean equals(Object o) {\n            if (!(o instanceof IntStream)) {\n                return false;\n            }\n            IntStream c = (IntStream) o;\n            IntIterator it = intIterator();\n            IntIterator jt = c.intIterator();\n            while (it.isValid() && jt.isValid()) {\n                if (it.value() != jt.value()) {\n                    return false;\n                }\n                it.advance();\n                jt.advance();\n            }\n            return !it.isValid() && !jt.isValid();\n        }\n\n        public int hashCode() {\n            int result = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                result *= 31;\n                result += it.value();\n            }\n            return result;\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int[] 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    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 interface IntReversableCollection extends IntCollection {\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        public void set(int index, int value) {\n            if (index >= size) {\n                throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n            }\n            data[index] = value;\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static int[] sort(int[] array) {\n            return sort(array, IntComparator.DEFAULT);\n        }\n\n        public static int[] sort(int[] array, IntComparator comparator) {\n            return sort(array, 0, array.length, comparator);\n        }\n\n        public static int[] sort(int[] array, int from, int to, IntComparator comparator) {\n            if (from == 0 && to == array.length) {\n                new IntArray(array).sort(comparator);\n            } else {\n                new IntArray(array).subList(from, to).sort(comparator);\n            }\n            return array;\n        }\n\n    }\n\n    static interface IntList extends IntReversableCollection {\n        public abstract int get(int index);\n\n        public abstract void set(int index, int value);\n\n        public abstract void addAt(int index, int value);\n\n        public abstract void removeAt(int index);\n\n        default public void swap(int first, int second) {\n            if (first == second) {\n                return;\n            }\n            int temp = get(first);\n            set(first, get(second));\n            set(second, temp);\n        }\n\n        default public IntIterator intIterator() {\n            return new IntIterator() {\n                private int at;\n                private boolean removed;\n\n                public int value() {\n                    if (removed) {\n                        throw new IllegalStateException();\n                    }\n                    return get(at);\n                }\n\n                public boolean advance() {\n                    at++;\n                    removed = false;\n                    return isValid();\n                }\n\n                public boolean isValid() {\n                    return !removed && at < size();\n                }\n\n                public void remove() {\n                    removeAt(at);\n                    at--;\n                    removed = true;\n                }\n            };\n        }\n\n        default public void add(int value) {\n            addAt(size(), value);\n        }\n\n        default public IntList sort(IntComparator comparator) {\n            Sorter.sort(this, comparator);\n            return this;\n        }\n\n        default public IntList subList(final int from, final int to) {\n            return new IntList() {\n                private final int shift;\n                private final int size;\n\n                {\n                    if (from < 0 || from > to || to > IntList.this.size()) {\n                        throw new IndexOutOfBoundsException(\"from = \" + from + \", to = \" + to + \", size = \" + size());\n                    }\n                    shift = from;\n                    size = to - from;\n                }\n\n                public int size() {\n                    return size;\n                }\n\n                public int get(int at) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    return IntList.this.get(at + shift);\n                }\n\n                public void addAt(int index, int value) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void removeAt(int index) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void set(int at, int value) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    IntList.this.set(at + shift, value);\n                }\n\n                public IntList compute() {\n                    return new IntArrayList(this);\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(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class PaintTheNumers {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);    \n        \n        int nums = sc.nextInt();\n        \n        HashSet<Integer> elements = new HashSet<Integer>();\n        for (int i = 0; i < nums; i++) {\n            elements.add(sc.nextInt());\n        }\n        \n        ArrayList<Integer> sortedElements = new ArrayList<Integer>(elements);\n\n        Collections.sort(sortedElements);\n        \n        ArrayList<Integer> lcms = new ArrayList<Integer>();\n        \n        outer:\n        for (int i = 0; i < sortedElements.size(); i++) {\n            int ele = sortedElements.get(i);\n            for (int j = 0; j < lcms.size(); j++) {\n                if (ele % lcms.get(j) == 0) {\n                    continue outer;\n                }\n            }\n            lcms.add(ele);\n        }\n        System.out.println(lcms.size());\n        sc.close();\n    }\n}\n   \n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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\tInteger[] arr = new Integer[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tarr[i]=sc.nextInt();\n\t\t}\n\t\tArrays.sort(arr);\n\t\tint ct = 0;\n\t\tboolean[] ar = new boolean[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(!ar[i]) {\n\t\t\t\tar[i]=true;\n\t\t\t\tct++;\n\t\t\t\tint x = arr[i];\n\t\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\t\tif(arr[j]%x==0) {\n\t\t\t\t\t\tar[j]=true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tpw.println(ct);\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Problem_A {\n\t\n\tpublic static void main(String[] args) {\n\t\tMyScanner scan = new MyScanner();\n\t\tint n = scan.nextInt();\n\t\tint[] elements = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\telements[i] = scan.nextInt();\n\t\t\n\t\tint x = 0;\n\t\t\n\t\tArrays.sort(elements);\n\t\twhile(n > 0) {\n\t\t\tx++;\n\t\t\tint[] temp = new int[n];\n\t\t\tint j = 0;\n\t\t\tint size = n;\n\t\t\tint min = elements[0];\n\t\t\tn--;\n\t\t\tfor (int i = 1; i < size; i++) {\n\t\t\t\tif (elements[i]%min == 0) {\n\t\t\t\t\tn--;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttemp[j++] = elements[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\telements = temp;\n\t\t}\n\t\t\n\t\tout.println(x);\n\t\tout.close();\n\t}\n\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\t\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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.FileNotFoundException;\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 Asgar Javadov\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        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            int[] a = in.readIntArray(n);\n\n            ArrayUtils.radixSort(a);\n\n            int answer = 0;\n            boolean[] used = new boolean[a.length];\n            for (int i = 0; i < a.length; ++i) {\n                if (used[i]) continue;\n\n                used[i] = true;\n                answer++;\n                for (int j = i + 1; j < a.length; ++j)\n                    if (a[j] % a[i] == 0)\n                        used[j] = true;\n            }\n\n            out.println(answer);\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static void radixSort(int[] array) {\n            int[] ordered = new int[array.length];\n            {\n                int[] freq = new int[0xFFFF + 2];\n                for (int i = 0; i < array.length; ++i) freq[(array[i] & 0xFFFF) + 1]++;\n                for (int i = 1; i < freq.length; ++i) freq[i] += freq[i - 1];\n\n                for (int i = 0; i < array.length; ++i)\n                    ordered[freq[array[i] & 0xFFFF]++] = array[i];\n                for (int i = 0; i < array.length; ++i)\n                    array[i] = ordered[i];\n            }\n            {\n                int[] freq = new int[0xFFFF + 2];\n                for (int i = 0; i < array.length; ++i) freq[(array[i] >>> 16) + 1]++;\n                for (int i = 1; i < freq.length; ++i) freq[i] += freq[i - 1];\n\n                for (int i = 0; i < array.length; ++i)\n                    ordered[freq[array[i] >>> 16]++] = array[i];\n\n                int indexOfFirstNegative = freq[0x7FFF];\n                int index = 0;\n                for (int i = indexOfFirstNegative; i < ordered.length; ++i, ++index)\n                    array[index] = ordered[i];\n                for (int i = 0; i < indexOfFirstNegative; ++i, ++index)\n                    array[index] = ordered[i];\n            }\n        }\n\n    }\n\n    static class OutputWriter extends PrintWriter {\n        public OutputWriter(OutputStream outputStream) {\n            super(outputStream);\n        }\n\n        public OutputWriter(Writer writer) {\n            super(writer);\n        }\n\n        public OutputWriter(String filename) throws FileNotFoundException {\n            super(filename);\n        }\n\n        public void close() {\n            super.close();\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        public int[] readIntArray(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    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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.FileNotFoundException;\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            int n = in.nextInt();\n            int[] a = in.nextIntArray(n);\n            Arrays.sort(a);\n            int count = 0;\n            boolean[] used = new boolean[n];\n            for (int i = 0; i < n; i++) {\n                if (!used[i]) {\n                    count++;\n                    for (int j = i; j < n; j++) {\n                        if (a[j] % a[i] == 0) {\n                            used[j] = true;\n                        }\n                    }\n                }\n            }\n            out.println(count);\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        public int[] nextIntArray(int n) {\n            int[] ret = new int[n];\n            for (int i = 0; i < n; i++) {\n                ret[i] = nextInt();\n            }\n            return ret;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.util.*; \n//import javafx.util.*; \nimport java.math.*;\n//import java.lang.*;\npublic class Main \n{ \n  //  static int n;static ArrayList<Integer> arr[];\n   // int ans[];\n \n    public static void main(String[] args) throws IOException { \n    //    Scanner sc=new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        br = new BufferedReader(new InputStreamReader(System.in));\n        int n=nextInt();\n        int arr[]=new int[n];\n        for(int i=0;i<n;i++){\n            arr[i]=nextInt();\n        }\n        Arrays.sort(arr);\n        int c=0;\n        for(int i=0;i<n;i++){\n            if(arr[i]!=0){\n                int a=arr[i];\n                c++;\n                for(int j=i;j<n;j++){\n                  //  System.out.println(arr[i]+\" \"+arr[j]);\n                    if(arr[j]%a==0){\n                        arr[j]=0;\n                    }\n                }\n            }\n        }\n        pw.println(c);\n        pw.close();\n\n    }\n    \n    static long maxSubArraySum(long a[],int size)  \n{  \n      \n    long max_so_far = 0, max_ending_here = 0;  \n  \n    for (int i = 0; i < size; i++)  \n    {  \n        max_ending_here = max_ending_here + a[i]; \n        if (max_ending_here < 0)  \n            max_ending_here = 0;  \n          \n        /* Do not compare for all \n           elements. Compare only  \n           when max_ending_here > 0 */\n        else if (max_so_far < max_ending_here)  \n            max_so_far = max_ending_here;  \n          \n    }  \n    return max_so_far;  \n}  \n    public static BufferedReader br;\n    public static StringTokenizer st;\n    public static String next() {\n        while (st == null || !st.hasMoreTokens()) {\n       try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return st.nextToken();\n    }\n \n    public static Integer nextInt() {\n        return Integer.parseInt(next());\n    }\n \n    public static Long nextLong() {\n        return Long.parseLong(next());\n    }\n \n    public static Double nextDouble() {\n        return Double.parseDouble(next());\n    }\n    static class Pair{\n        int x;int y;int z;\n        Pair(int x,int y,int z){\n            this.x=x;\n            this.y=y;\n            this.z=z;\n          //  this.i=i;\n        }\n    }\n    static class sorting implements Comparator<Pair>{\n        public int compare(Pair a,Pair b){\n            //return (a.y)-(b.y);\n            return (a.x-b.x);\n        }\n    }\n    public static int[] na(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    static class query implements Comparable<query>{\n        int l,r,idx,block;\n        static int len;\n        query(int l,int r,int i){\n            this.l=l;\n            this.r=r;\n            this.idx=i;\n            this.block=l/len;\n        }   \n        public int compareTo(query a){\n            return block==a.block?r-a.r:block-a.block;\n        }\n    }\n    static boolean isPrime(int n) { \n        if (n <= 1) \n            return false; \n        if (n <= 3) \n            return true; \n        if (n % 2 == 0 ||  \n            n % 3 == 0) \n            return false; \n      \n        for (int i = 5; \n                 i * i <= n; i = i + 6) \n            if (n % i == 0 || \n                n % (i + 2) == 0) \n                return false; \n      \n        return true; \n    } \n    static long gcd(long a, long b) { \n      if (b == 0) \n        return a; \n      return gcd(b, a % b);  \n    }  \n    static long modInverse(long a, long m) { \n        long g = gcd(a, m); \n        if (g != 1) \n            return -1; \n        else{ \n            // If a and m are relatively prime, then modulo inverse \n            // is a^(m-2) mode m \n            return (power(a, m - 2, m)); \n        } \n    } \n      \n    // To compute x^y under modulo m \n    static long power(long x, long y, long m){ \n        if (y == 0) \n            return 1;      \n        long p = power(x, y / 2, m) % m; \n        p = (p * p) % m; \n      \n        if (y % 2 == 0) \n            return p; \n        else\n            return (x * p) % m; \n    }\n    static long fast_pow(long base,long n,long M){\n        if(n==0)\n           return 1;\n        if(n==1)\n        return base;\n        long halfn=fast_pow(base,n/2,M);\n        if(n%2==0)\n            return ( halfn * halfn ) % M;\n        else\n            return ( ( ( halfn * halfn ) % M ) * base ) % M;\n    }\n       static long modInverse(long n,int M){\n        return fast_pow(n,M-2,M);\n    }\n    \n} ", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\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/a.in\"))));\n\t\t/**/\n\t\t\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\t\tArrays.sort(a);\n\t\tint ans = 0;\n\t\tboolean[] v = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (v[i])\n\t\t\t\tcontinue;\n\t\t\tv[i] = true;\n\t\t\tans++;\n\t\t\tfor (int j = i; j < n; j++) {\n\t\t\t\tif (a[j]%a[i]==0)\n\t\t\t\t\tv[j] = true;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\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        for (int i = 0; i < n; i++) {\n            arr[i] = in.nextInt();\n        }\n        Arrays.sort(arr);\n        int cnt = 0;\n        int pos = 0;\n        while (true) {\n            while (pos < n && arr[pos] == -1) pos++;\n            if (pos == n) break;\n            int min = arr[pos];\n            arr[pos] = -1;\n            cnt++;\n            for (int i = pos + 1; i < n; i++) {\n                if (arr[i] % min == 0) {\n                    arr[i] = -1;\n                }\n            }\n        }\n        System.out.println(cnt);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class paintTheNumbers {\n    public static void main (String [] args){\n        Scanner scanner = new Scanner(System.in);\n        int n = scanner.nextInt();\n        int [] arr = new int[n];\n        for(int i = 0; i < n; i++){\n            arr[i] = scanner.nextInt();\n        }\n        System.out.print(paint(arr));\n    }\n    public static int paint(int [] arr){\n        Arrays.sort(arr);\n        HashSet<Integer> set = new HashSet<>();\n        int num = arr[0];\n        set.add(num);\n        for(int i = 1; i < arr.length; i++){\n            if(!divBySet(set, arr[i])){\n                set.add(arr[i]);\n            }\n\n        }\n        return set.size();\n    }\n\n    /**\n     *\n     * @param set\n     * @param a\n     * @return\n     */\n    public static boolean divBySet(HashSet<Integer> set, int a){\n        for(int s: set){\n            if(a % s == 0){\n                return true;\n            }\n        }\n        return false;\n    }\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic final class paint_and_numers {\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<n;i++) a[i] = in.nextInt();\n        Arrays.sort(a);\n        int count = 0;\n        boolean[] c = new boolean[n];\n        for(int i=0;i<n;i++) {\n            if(c[i]==false) {\n                c[i]=true;\n                count++;\n                for(int j=i+1;j<n;j++) {\n                    if(a[j]%a[i]==0) {\n                        c[j] = true;\n                    }\n                }\n            }\n        }\n        System.out.println(count);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.TreeSet;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        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            TreeSet<Integer> set = new TreeSet<>();\n            int n = in.nextInt();\n            for (int i = 0; i < n; i++) {\n                int x = in.nextInt();\n                set.add(x);\n            }\n            int ans = 0;\n            while (!set.isEmpty()) {\n                ans++;\n                int minimal = set.first();\n                int cur = minimal;\n                while (cur <= 100) {\n                    set.remove(cur);\n                    cur += minimal;\n                }\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.util.*; \nimport java.util.Map.*;\nimport java.math.*;\n//import java.lang.*;\n\npublic class q1 \n{ \n    static int MOD=1000000007;\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[1000000]; // 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 isPrime(int n) \n    { \n        if (n <= 1) \n            return false; \n        if (n <= 3) \n            return true; \n        if (n % 2 == 0 || n % 3 == 0) \n            return false; \n      \n        for (int i = 5; i * i <= n; i = i + 6) \n            if (n % i == 0 ||  n % (i + 2) == 0) \n                return false; \n      \n        return true; \n    } \n    static int gcd(int a, int b) \n    { \n      if (b == 0) \n        return a; \n      return gcd(b, a % b);  \n    } \n    //Functions\n\n\n\n    \n    public static void main(String[] args) throws IOException \n    { \n       Scanner sc=new Scanner(System.in); \n       //int T=sc.nextInt();\n       int T=1;\n       while(T-- > 0){\n           int N=sc.nextInt();\n           int a[]=new int[N];\n           int count=0;\n           int ans=0;\n           boolean flag=false;\n\n           for(int i=0;i<N;++i){\n               a[i]=sc.nextInt();\n           }\n           Arrays.sort(a);\n           for(int i=0;i<N;++i){\n               if(a[i]==-1)\n                continue;\n            for(int j=i+1;j<N;++j){\n                if(a[j]%a[i]==0 && a[j]!=-1){\n                    a[j]=-1;;\n                }\n            }\n           }\n           //int i=0;\n           for(int i=0;i<N;++i){\n               if(a[i]!= -1)\n               count++;\n           }\n\n           System.out.println(count);\n        } // End of test cases loop \n\n        \n    }//end of main function\n    \n    \n} //end of class", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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.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 */\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        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int N = in.nextInt();\n            Integer a[] = in.nextIntArray(N);\n            Arrays.sort(a);\n            int colors = 0;\n            for (int i = 0; i < N; i++) {\n                if (a[i] == -1) continue;\n                colors++;\n                for (int j = i + 1; j < N; j++) {\n                    if (a[j] % a[i] == 0) {\n                        a[j] = -1;\n                    }\n                }\n            }\n            out.printLine(colors);\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        public Integer[] nextIntArray(int size) {\n            Integer array[] = new Integer[size];\n            for (int i = 0; i < size; i++) {\n                array[i] = nextInt();\n            }\n            return array;\n        }\n\n    }\n\n    static class OutputWriter {\n        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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class A {\n\tpublic void run() throws Exception {\n\t\tFastScanner sc = new FastScanner();\n\t\t\n\t\tint n = sc.nextInt();\n\t\tint[] arr = new int[n];\n\t\tint[] color = new int[n];\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tarr[i]  =sc.nextInt();\n\t\t}\n\t\tArrays.sort(arr);\n\t\tint counter = 1;\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tif (color[i]!= 0) continue;\n\t\t\tfor (int j = i;j<n; j++) {\n\t\t\t\tif (color[j]!= 0) continue;\n\t\t\t\telse if (arr[j]%arr[i] == 0) color[j] = counter;\n\t\t\t}\n\t\t\tcounter++;\n\t\t}\n\t//\tSystem.out.println(Arrays.toString(color));\n\t\tint max = 0;\n\t\tfor (int i = 0; i<n; i++) {\n\t\t\tmax = Math.max(max, color[i]);\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\tstatic class FastScanner {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic FastScanner() {\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\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\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\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\n\t}\n\tpublic static void main (String[] args) throws Exception {\n\t\tnew A().run();\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner s=new Scanner(System.in);\n\t\t\n\t\tint n=s.nextInt();\n\t\t\n\t\tint[] arr=new int[n];\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tarr[i]=s.nextInt();\n\t\t}\n\t\t\n\t\tArrays.sort(arr);\n\t\t\n\t\tint[] visited=new int[n];\n\t\t\n\t\tint ans=0;\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tif(visited[i]==0)\n\t\t\t{\t\n\t\t\t\tans++;\n\t\t\t\t\n\t\t\t\tfor(int j=i+1;j<n;j++)\n\t\t\t\t{\n\t\t\t\t\tif(arr[j]%arr[i]==0&&visited[j]==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tvisited[j]=1;\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(ans);\n\t\t\n\t}\n\t\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\npublic class PaintColor {\n    public static void main(String[] args) throws Exception {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(br.readLine());\n        String input[] = br.readLine().split(\" \");\n        int c = 0;\n        Set<Integer> s = new HashSet<>();\n        int arr[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = Integer.parseInt(input[i]);\n        }\n        Arrays.sort(arr);\n        for (int i = 0; i < n; i++) {\n            if (!s.contains(arr[i])) {\n                c++;\n                for (int j = i; j < n; j++) {\n                    if (arr[j] % arr[i] == 0) {\n                        s.add(arr[j]);\n                    }\n                }\n            }\n        }\n        System.out.println(c);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] ar = new int[n];\n            for (int i = 0; i < n; i++)\n                ar[i] = in.nextInt();\n            Arrays.sort(ar);\n            boolean[] u = new boolean[n];\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                if (!u[i]) {\n                    u[i] = true;\n                    ans++;\n                    for (int j = 0; j < n; j++) {\n                        if (!u[j] && ar[j] % ar[i] == 0) {\n                            u[j] = true;\n                        }\n                    }\n                }\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\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n \npublic class Main{\n\t\n\tpublic static void main (String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tint n = scan.nextInt(), min[] = new int[n];\n\t\tboolean used[] = new boolean[n];\n\t\tHashSet<Integer> set = new HashSet<>();\n\t\t\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tmin[i] = scan.nextInt();\n\t\t}\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\t\tif (min[i] > min[j]) {\n\t\t\t\t\t\tif (min[i] % min[j] == 0)\n\t\t\t\t\t\t\tmin[i] = min[j];\n\t\t\t\t\t}\n\t\t\t\t\telse if (min[j] % min[i] == 0)\n\t\t\t\t\t\t\tmin[j] = min[i];\n\t\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tset.add(min[i]);\n\t\t}\n\t\t\n\t\tSystem.out.print(set.size());\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n    static int inf = (int) 1e9 + 7;\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        int n = nextInt();\n        int a[] = new int [n];\n        for(int i = 0;i < n;i++) a[i] = nextInt();\n        int ans = 0;\n        boolean b[] = new boolean[n];\n        Arrays.sort(a);\n\n        for(int i = 0;i < n;i++) {\n            if (!b[i]) {\n                for(int j = i;j < n;j++) {\n                    if (a[j] % a[i] == 0) b[j] = true;\n                }\n                ans++;\n            }\n        }\n        pw.println(ans);\n        pw.close();\n    }\n\n    static BufferedReader br;\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static PrintWriter pw;\n\n    static String next() throws IOException {\n        while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\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\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        int n = Integer.parseInt(bf.readLine());\n        StringTokenizer st = new StringTokenizer(bf.readLine());\n        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n\n        int counter = 0;\n        TreeSet<Integer> val = new TreeSet<Integer>();\n        for(int i : a) val.add(i);\n        while(!val.isEmpty()) {\n          int min = val.first();\n          Set<Integer> toRemove = new HashSet<Integer>();\n          for(int i : val) if(i % min == 0) toRemove.add(i);\n          for(int i : toRemove) val.remove(i);\n          counter++;\n        }\n        out.println(counter);\n        // int n = Integer.parseInt(st.nextToken());\n\n        out.close(); System.exit(0);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class task1 {\n    static void print(Object... a) {\n        for (Object aa : a) {\n            System.out.println(aa.toString());\n        }\n    }\n\n    static Map<Character, Integer> stringToCharsMap(String str) {\n        Map<Character, Integer> charcount = new HashMap<Character, Integer>();\n        for (Character c : str.toCharArray()) {\n            if (charcount.containsKey(c)) {\n                charcount.put(c, charcount.get(c) + 1);\n            } else {\n                charcount.put(c, 1);\n            }\n        }\n        return charcount;\n    }\n\n    static Set<Character> stringToCharsSet(String str) {\n        Set<Character> chars = new HashSet<>();\n        for (Character c : str.toCharArray()) {\n            chars.add(c);\n        }\n        return chars;\n    }\n\n    static int[] readArrayOfInt() {\n        Scanner sc = new Scanner(System.in);\n        int a = sc.nextInt();\n        int array[] = new int[a];\n        for (int i = 0; i < a; i++) {\n            array[i] = sc.nextInt();\n        }\n        return array;\n    }\n\n    static 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        double distance(Point p) {\n            return Math.sqrt((this.x - p.x) * (this.x - p.x) + (this.y - p.y) * (this.y - p.y));\n        }\n\n        double distance(Line l) {\n            return Math.abs(l.a * this.x + l.b * this.y + l.c) / Math.sqrt(l.a * l.a + l.b * l.b);\n        }\n    }\n\n    static class Line {\n        double a;\n        double b;\n        double c;\n        double EPS = 1e-6;\n\n        Line(int a, int b, int c) {\n            this.a = a;\n            this.b = b;\n            this.c = c;\n        }\n\n        Line(Point f, Point s) {\n            this.a = f.y - s.y;\n            this.b = s.x - f.x;\n            this.c = -this.a * f.x - this.b * f.y;\n        }\n\n        double distance(Point p) {\n            return Math.abs(this.a * p.x + this.b * p.y + this.c) / Math.sqrt(this.a * this.a + this.b * this.b);\n        }\n\n        boolean isPointOnLine(Point p) {\n            return p.x * this.a + p.y * this.b + this.c < EPS;\n        }\n\n        Point linesIntersection(Line a) {\n            double x = -(this.c * a.b - a.c * this.b) / (this.a * a.b - a.a * this.b);\n            double y = -(this.a * a.c - a.a * this.c) / (this.a * a.b - a.a * this.b);\n            return new Point(x, y);\n        }\n    }\n\n    static HashMap<Integer, Integer> getDels(int a) {\n        HashMap<Integer, Integer> h = new HashMap<>();\n        int i = 2;\n        while (a != 1) {\n            if (a % i == 0) {\n                if (h.containsKey(i)) {\n                    h.put(i, h.get(i) + 1);\n                } else {\n                    h.put(i, 1);\n                }\n                a = a / i;\n            } else {\n                i++;\n            }\n        }\n        return h;\n    }\n\n    static class Rect {\n        Point fcorner;\n        Point scorner;\n\n        Rect(Point f, Point s) {\n            fcorner = f;\n            scorner = s;\n        }\n\n        double volume() {\n            return Math.abs((fcorner.x - scorner.x) * (fcorner.y - scorner.y));\n        }\n    }\n\n    public static void main(String args[]) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int arr[] = new int[n];\n        int c[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = sc.nextInt();\n        }\n        Arrays.sort(arr);\n        int count = 1;\n        c[0] = 1;\n        for (int i = 1; i < arr.length; i++) {\n            for (int j = 0; j < i; j++) {\n                if (arr[i] % arr[j] == 0) {\n                    c[i] = c[j];\n                    break;\n                }\n            }\n            if (c[i] == 0) {\n                c[i] = count + 1;\n                count++;\n            }\n        }\n        System.out.println(count);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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 Washoum\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        inputClass in = new inputClass(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, inputClass sc, PrintWriter out) {\n            int n = sc.nextInt();\n            Integer[] tab = new Integer[n];\n            for (int i = 0; i < n; i++) {\n                tab[i] = sc.nextInt();\n            }\n            Arrays.sort(tab);\n            boolean[] done = new boolean[n];\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                if (!done[i]) {\n                    ans++;\n                    done[i] = true;\n                    for (int j = i + 1; j < n; j++) {\n                        if (!done[j] && tab[j] % tab[i] == 0) {\n                            done[j] = true;\n                        }\n                    }\n                }\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class inputClass {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public inputClass(InputStream in) {\n\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\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class wef {\npublic static class FastReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t//than using direct \n\n\tpublic FastReader() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString 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 (Exception r) {\n\t\t\t\tr.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());//converts string to integer\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() {\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\t\t} catch (Exception r) {\n\t\t\tr.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n}\nstatic ArrayList<String>list1=new ArrayList<String>();\nstatic void combine(String instr, StringBuffer outstr, int index,int k)\n{\n\tif(outstr.length()==k)\n\t{\n\t\tlist1.add(outstr.toString());return;\n\t}\n\tif(outstr.toString().length()==0)\n\toutstr.append(instr.charAt(index));\n    for (int i = 0; i < instr.length(); i++)\n    {\n        outstr.append(instr.charAt(i));\n       \n        combine(instr, outstr, i + 1,k);\n        outstr.deleteCharAt(outstr.length() - 1);\n    }\n   index++;\n} \nstatic ArrayList<ArrayList<Integer>>l=new ArrayList<>();\nstatic void comb(int n,int k,int ind,ArrayList<Integer>list)\n{\n\tif(k==0)\n\t{\n\t\tl.add(new ArrayList<>(list));\n\n\t\treturn;\n\t}\n\t\n\t\n\tfor(int i=ind;i<=n;i++)\n\t{\n\t\tlist.add(i);\n\t\tcomb(n,k-1,ind+1,list);\n\t\t\n\t\tlist.remove(list.size()-1);\n\t\t\n\t}\n\t\n\t\n\t\n\t\n\t\n\n}\nstatic long sum(long n)\n{\n\tlong sum=0;\n\twhile(n!=0)\n\t{\n\t\tsum+=n%10;\n\t\tn/=10;\n\t}\n\treturn sum;\n}\n\n\nstatic boolean check(HashMap<Integer,Integer>map)\n{\n\tfor(int h:map.values())\n\t\tif(h>1)\n\t\t\treturn false;\n\treturn true;\n}\n\nstatic class Pair implements Comparable<Pair>{\n    int x;int y;\n    Pair(int x,int y){\n        this.x=x;\n        this.y=y;\n      //  this.i=i;\n    }\n\t@Override\n\tpublic int compareTo(Pair o) {\n\t\t// TODO Auto-generated method stub\n\t\treturn x-o.x;\n\t\t\n\t}\n}\nstatic boolean isPrime(int n) \n{ \n    // Corner cases \n    if (n <= 1) \n        return false; \n    if (n <= 3) \n        return true; \n  \n    // This is checked so  \n    // that we can skip \n    // middle five numbers \n    // in below loop \n    if (n % 2 == 0 ||  \n        n % 3 == 0) \n        return false; \n  \n    for (int i = 5; \n             i * i <= n; i = i + 6) \n        if (n % i == 0 || \n            n % (i + 2) == 0) \n            return false; \n  \n    return true; \n} \n  \n\nstatic long gcd(long a, long b) \n{ \n  if (b == 0) \n    return a; \n  return gcd(b, a % b);  \n} \n\npublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\tFastReader in=new FastReader();\n\tHashMap<Integer,Integer>map=new HashMap<Integer,Integer>();\n\tArrayList<Integer>list=new ArrayList<Integer>();\n\tTreeSet<Integer>set=new TreeSet<Integer>();\n\n\tint n=in.nextInt();\n\tfor(int i=0;i<n;i++)\n\t\tset.add(in.nextInt());\n\t\n\tint ans=0;\n\t\n\twhile(!set.isEmpty())\n\t{\n\t\tint f=set.first();\n\t\tint s=f;\n\t\twhile(!set.isEmpty()&&s<=set.last())\n\t\t{\n\t\t\tif(set.contains(s))\n\t\t\tset.remove(new Integer(s));\n\t\t\ts+=f;\n\t\t}\n\t\tans++;\n\t\t\n\t}\n\tout.println(ans);\n\t\n\tout.close();\n\t\n\t\n\t\t\n\t}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class first {\n\tstatic int max = 1000000000;\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint[] tab = new int[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ttab[i] = sc.nextInt();\n\t\t}\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tif(i!=j)\n\t\t\t\tif(tab[i]>=tab[j] && tab[i]%tab[j]==0) {\n\t\t\t\t\ttab[i] = max;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(tab[i]!=max) res++;\n\t\t}\n\t\tSystem.out.println(res);\n\t\t//System.out.println(4%-1);\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class Mainm {\n    static int mod1 = (int) (1e9 + 7);\n\n    static class Reader {\n        final private int BUFFER_SIZE = 1 << 16;\n        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\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 nextString() throws IOException {\n            String str00 = scan.next();\n            return str00;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[64]; // line length\n            int cnt = 0, c;\n            while ((c = read()) != -1) {\n                if (c == '\\n')\n                    break;\n                buf[cnt++] = (byte) c;\n            }\n            return new String(buf, 0, cnt);\n        }\n\n        String next() throws IOException {\n            int c;\n            for (c = read(); c <= 32; c = read());\n            StringBuilder sb = new StringBuilder();\n            for (; c > 32; c = read()) {\n                sb.append((char) c);\n            }\n            return sb.toString();\n        }\n\n        public int nextInt() throws IOException {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public long nextLong() throws IOException {\n            long ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public double nextDouble() throws IOException {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n\n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        private void fillBuffer() throws IOException {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n            if (bytesRead == -1)\n                buffer[0] = -1;\n        }\n\n        private byte read() throws IOException {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n\n        public void close() throws IOException {\n            if (din == null)\n                return;\n            din.close();\n        }\n\n        public int[] nextArray(int n) throws IOException {\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\n\n    static int GCD(int a, int b)\n    {\n        if (b == 0)\n            return a;\n        return GCD(b, a % b);\n    }\n\n\n    static  long power(long x, long y, long p)\n    {\n        int res = 1;      // Initialize result\n\n        return res;\n    }\n\n\n    static boolean primeCheck(long num0) {\n        boolean b1 = true;\n        if (num0 == 1) {\n            b1 = false;\n        } else {\n            int num01 = (int) (Math.sqrt(num0)) + 1;\n            me1:\n            for (int i = 2; i < num01; i++) {\n                if (num0 % i == 0) {\n                    b1 = false;\n                    break me1;\n                }\n            }\n        }\n        return b1;\n    }\n\n    public static int dev(long num1)\n    {\n        int count00=0;\n        while (num1%2==0)\n        {\n            count00++;\n            num1/=2;\n        }\n        HashMap<Long,Long> hashMap=new HashMap<>();\n        if(count00!=0)\n        {\n            hashMap.put(2L,(long)count00);\n        }\n        for (int i = 3; i <= (int)Math.sqrt(num1); i = i + 2)\n        {\n            // While i divides n, print i and divide n\n            if(num1%i==0) {\n                int count01 = 0;\n\n                while (num1 % i == 0) {\n                    num1 /= i;\n                    count01++;\n                }\n                hashMap.put((long)i,(long)count01);\n            }\n        }\n        if(num1>2)\n        {\n            hashMap.put((long)num1,1L);\n        }\n        long numOfDiv=1;\n        for(long num00:hashMap.keySet())\n        {\n            long cDiv0=hashMap.get(num00);\n            numOfDiv*=(cDiv0+1);\n        }\n\n        return (int)(numOfDiv);\n    }\n\n\n\n    public static long solve(long[] arr1, long N)\n    {\n        int n=(int)N;\n        HashMap<Long,Integer> hm=new HashMap<>();\n        for(int i=0;i<n;i++)\n        {\n            if(hm.containsKey(arr1[i]))\n            {\n\n            }\n            else\n            {\n                hm.put(arr1[i],1);\n            }\n        }\n\n        long count1=0;\n        for(int i=0;i<n;i++)\n        {\n            long num1=arr1[i]*arr1[i];\n            if(hm.containsKey(num1))\n            {\n                count1+=hm.get(num1);\n                if(arr1[i]==1)\n                {\n                    count1--;\n                }\n\n            }\n        }\n        return count1;\n    }\n\n\n\n\n    public static void main(String[] args) throws IOException {\n        Reader r = new Reader();\n        //PrintWriter writer=new PrintWriter(System.out);\n        //Scanner r = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n        //Scanner r=new Scanner(System.in);\n        OutputWriter770 out77 = new OutputWriter770(System.out);\n\n        int num1=r.nextInt();\n        int[] arr1=r.nextArray(num1);\n        Arrays.sort(arr1);\n\n        int res1=0;\n        for(int i=0;i<num1;i++)\n        {\n            if(arr1[i]!=-1)\n            {\n                res1++;\n                int num2=arr1[i];\n                arr1[i]=-1;\n                for(int j=i+1;j<num1;j++)\n                {\n                    if(arr1[j]%num2==0)\n                    {\n                        arr1[j]=-1;\n                    }\n                }\n            }\n        }\n        out77.print(res1+\"\");\n        r.close();\n        out77.close();\n    }\n}\n\n\n\n\nclass OutputWriter770\n{\n    BufferedWriter writer;\n\n    public OutputWriter770(OutputStream stream)\n    {\n        writer = new BufferedWriter(new OutputStreamWriter(stream));\n    }\n    public void print(int i) throws IOException\n    {\n        writer.write(i + \"\");\n    }\n\n    public void println(int i) throws IOException\n    {\n        writer.write(i + \"\\n\");\n    }\n\n    public void print(String s) throws IOException\n    {\n        writer.write(s + \"\");\n    }\n\n    public void println(String s) throws IOException\n    {\n        writer.write(s + \"\\n\");\n    }\n\n    public void print(char[] c) throws IOException\n    {\n        writer.write(c);\n    }\n\n    public void close() throws IOException\n    {\n        writer.flush();\n        writer.close();\n    }\n}\n\nclass node\n{\n    int source,dest;\n    long difDist;\n    node(int source,int dest,long tDst, long hDst)\n    {\n        this.source=source;\n        this.dest=dest;\n        this.difDist=hDst-tDst;\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\n\npublic class cfs584A {\n    static long LINF = Long.MAX_VALUE / 4;\n    static long IING = Integer.MAX_VALUE / 4;\n\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        StringBuilder sb = new StringBuilder();\n        int N = sc.nextInt();\n        int[] nums = sc.readIntArray(N);\n        ArrayList<Integer> num = new ArrayList<>();\n\n        for (int i = 0; i < N; i++) {\n            num.add(nums[i]);\n        }\n\n\n        int count = 0;\n        while (!num.isEmpty()) {\n            count++;\n            int size = num.size();\n            int min = 200;\n            for (int j = size-1; j >=0; j--) {\n                if (num.get(j) < min) {\n                    min = num.get(j);\n                }\n            }\n            for (int j = size-1; j >=0; j--) {\n                int div = num.get(j) / min;\n                if ((div * min) == num.get(j)) {\n                    num.remove(j);\n                }\n            }\n        }\n        sb.append(count);\n\n        System.out.print(sb);\n    }\n\n    static void Assert(boolean b) {\n        if (!b) throw new Error(\"Assertion Failed\");\n    }\n\n    static class Pair implements Comparable<Pair> {\n        int x, y;\n\n        Pair(int _x, int _y) {\n            x = _x;\n            y = _y;\n        }\n\n        public int compareTo(Pair o) {\n            int c1 = Integer.compare(x, o.x);\n            return c1 != 0 ? c1 : Integer.compare(y, o.y);\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n \npublic class Codeforce {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tarr[i] = sc.nextInt();\n\t\t}\n\t\tint color = 0;\n\t\tArrays.sort(arr);\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tif(arr[i]!=0) {\n\t\t\t\tint col = arr[i];\n\t\t\t\tcolor++;\n\t\t\t\tfor(int j=i; j<n; j++) {\n\t\t\t\t\tif(arr[j]%col==0) arr[j]=0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(color);\n\t\tsc.close();\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Jenish\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        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int arr[] = new int[n];\n            in.scanInt(arr);\n            CodeX.sort(arr);\n            int ans = 0;\n            boolean vissited[] = new boolean[n];\n            for (int i = 0; i < n; i++) {\n                if (!vissited[i]) {\n                    ans++;\n                    for (int j = 0; j < n; j++) {\n                        if (arr[j] % arr[i] == 0) {\n                            vissited[j] = true;\n                        }\n                    }\n                }\n            }\n\n\n            out.println(ans);\n        }\n\n    }\n\n    static class CodeX {\n        public static void sort(int arr[]) {\n            merge_sort(arr, 0, arr.length - 1);\n        }\n\n        private static void merge_sort(int A[], int start, int end) {\n            if (start < end) {\n                int mid = (start + end) / 2;\n                merge_sort(A, start, mid);\n                merge_sort(A, mid + 1, end);\n                merge(A, start, mid, end);\n            }\n\n        }\n\n        private static void merge(int A[], int start, int mid, int end) {\n            int p = start, q = mid + 1;\n            int Arr[] = new int[end - start + 1];\n            int k = 0;\n\n            for (int i = start; i <= end; i++) {\n                if (p > mid)\n                    Arr[k++] = A[q++];\n\n                else if (q > end)\n                    Arr[k++] = A[p++];\n\n                else if (A[p] < A[q])\n                    Arr[k++] = A[p++];\n\n                else\n                    Arr[k++] = A[q++];\n            }\n            for (int i = 0; i < k; i++) {\n                A[start++] = Arr[i];\n            }\n\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int INDEX;\n        private BufferedInputStream in;\n        private int TOTAL;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (INDEX >= TOTAL) {\n                INDEX = 0;\n                try {\n                    TOTAL = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (TOTAL <= 0) return -1;\n            }\n            return buf[INDEX++];\n        }\n\n        public int scanInt() {\n            int 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        public void scanInt(int[] A) {\n            for (int i = 0; i < A.length; i++) A[i] = scanInt();\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\t\t\timport java.io.*;\n\t\t\timport java.util.*;\n\t\t\t \n\t\t\tpublic class oK{\n\t\t\t\t\t    void pre() throws Exception{}\n\t\t\t\t\t    void solve(int TC) throws Exception{\n\t\t\t\t\t    int n=ni();\n\t\t\t\t\t    \tint a[]=new int[n];\n\t\t\t\t\t    for(int i=0;i<n;i++) {\n\t\t\t\t\t    \ta[i]=ni();\n\t\t\t\t\t    }\n\t\t\t\t\t    Arrays.sort(a);\n\t\t\t\t\t    int b[]=new int[101];\n\t\t\t\t\t    int flag=0;\n\t\t\t\t\t    int count=0;\n\t\t\t\t\t    for(int i=0;i<n;i++) {\n\t\t\t\t\t    \tflag=0;\n\t\t\t\t\t    \tif(b[a[i]]==0) {\n\t\t\t\t\t    \t\tcount++;\n\t\t\t\t\t    \t}\n\t\t\t\t\t    \tfor(int j=i;j<n;j++) {\n\t\t\t\t\t    \t\tif(b[a[j]]==0&&a[j]%a[i]==0) {\n\t\t\t\t\t    \t\t\t\n\t\t\t\t\t    \t\t\tb[a[j]]=1;\n\t\t\t\t\t    \t\t\t\n\t\t\t\t\t    \t\t}\n\t\t\t\t\t    \t\t//if(flag==1)count++;\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\t\t    pn(count);\n\t\t\t\t\t    \n\t\t\t\t\t    \n\t\t\t\t\t    }\n\t\t\t\t\t    \t\t\n\t\t\t\t\t    \t\t\n\t\t\t\t\t    \n\t\t\t\t\t    \n\t\t\t\t\t    \n\t\t\t\t\t    \n\t\t\t\t\t    \n\t\t\t\t\t   // void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n\t\t\t\t\t    static boolean multipleTC = false, memory = false;\n\t\t\t\t\t    FastReader in;PrintWriter out;\n\t\t\t\t\t    void run() throws Exception{\n\t\t\t\t\t        in = new FastReader();\n\t\t\t\t\t        out = new PrintWriter(System.out);\n\t\t\t\t\t        int T = (multipleTC)?ni():1;\n\t\t\t\t\t        pre();for(int t = 1; t<= T; t++)solve(t);\n\t\t\t\t\t        out.flush();\n\t\t\t\t\t        out.close();\n\t\t\t\t\t    }\n\t\t\t\t\t    public static void main(String[] args) throws Exception{\n\t\t\t\t\t        if(memory)new Thread(null, new Runnable() {public void run(){try{new oK().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n\t\t\t\t\t        else new oK().run();\n\t\t\t\t\t    }\n\t\t\t\t\t    void p(Object o){out.print(o);}\n\t\t\t\t\t    void pn(Object o){out.println(o);}\n\t\t\t\t\t    void pni(Object o){out.println(o);out.flush();}\n\t\t\t\t\t    String n()throws Exception{return in.next();}\n\t\t\t\t\t    String nln()throws Exception{return in.nextLine();}\n\t\t\t\t\t    int ni()throws Exception{return Integer.parseInt(in.next());}\n\t\t\t\t\t    long nl()throws Exception{return Long.parseLong(in.next());}\n\t\t\t\t\t\n\t\t\t\t\t    class FastReader{\n\t\t\t\t\t        BufferedReader br;\n\t\t\t\t\t        StringTokenizer st;\n\t\t\t\t\t        public FastReader(){\n\t\t\t\t\t            br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\t        }\n\t\t\t\t\t\n\t\t\t\t\t        public FastReader(String s) throws Exception{\n\t\t\t\t\t            br = new BufferedReader(new FileReader(s));\n\t\t\t\t\t        }\n\t\t\t\t\t\n\t\t\t\t\t        String next() throws Exception{\n\t\t\t\t\t            while (st == null || !st.hasMoreElements()){\n\t\t\t\t\t                try{\n\t\t\t\t\t                    st = new StringTokenizer(br.readLine());\n\t\t\t\t\t                }catch (IOException  e){\n\t\t\t\t\t                    throw new Exception(e.toString());\n\t\t\t\t\t                }\n\t\t\t\t\t            }\n\t\t\t\t\t            return st.nextToken();\n\t\t\t\t\t        }\n\t\t\t\t\t\n\t\t\t\t\t        String nextLine() throws Exception{\n\t\t\t\t\t            String str = \"\";\n\t\t\t\t\t            try{   \n\t\t\t\t\t                str = br.readLine();\n\t\t\t\t\t            }catch (IOException e){\n\t\t\t\t\t                throw new Exception(e.toString());\n\t\t\t\t\t            }  \n\t\t\t\t\t            return str;\n\t\t\t\t\t        }\n\t\t\t\t\t    }\n\t\t\t\t\t}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.io.*;\npublic class Main3 {\n    static PrintWriter pr;\n    static Scanner scan;\n    static BufferedReader br;\n    static StringTokenizer st;\n    public static void main(String args[]) throws Exception {\n        pr = new PrintWriter(System.out);\n        scan = new Scanner(System.in);\n        br = new BufferedReader(new InputStreamReader(System.in));\n        int n = inputInt();\n        //char[] c = br.readLine().toCharArray();\n        int[] a = new int[n];\n        int[] b = new int[n];\n        st = new StringTokenizer(br.readLine());\n        for(int i=0;i<n;i++){\n\n            a[i]=Integer.parseInt(st.nextToken());\n            //b[i]=Integer.parseInt(st.nextToken());\n        }\n        Arrays.sort(a);\n        int ans=0;\n        for(int i=0;i<n;i++){\n            if(b[i]!=1){\n                ans++;\n                for(int j=i;j<n;j++){\n                    if(a[j]%a[i]==0){\n                        b[j]=1;\n                    }\n                }\n            }\n        }\n        System.out.println(ans);\n    }\n\n\n    public static int inputInt() throws IOException{\n        return Integer.parseInt(br.readLine());\n    }\n\n    public static long inputLong() throws IOException{\n        return Long.parseLong(br.readLine());\n    }\n\n    public static String inputString() throws IOException{\n        return br.readLine();\n    }\n\n    public static  int[] intArray(int n) throws IOException{\n        int a[] = new int[n];\n        st = new StringTokenizer(br.readLine());\n        for(int i=0;i<n;i++){\n            a[i] = Integer.parseInt(st.nextToken());\n        }\n        return a;\n    }\n\n    public static  long[] longArray(int n) throws IOException{\n        long a[] = new long[n];\n        st = new StringTokenizer(br.readLine());\n        for(int i=0;i<n;i++){\n            a[i] = Long.parseLong(st.nextToken());\n        }\n        return a;\n    }\n\n    public static String[] stringArray(int n) throws IOException{\n        String a[] = new String[n];\n        st = new StringTokenizer(br.readLine());\n        for(int i=0;i<n;i++){\n            a[i] = st.nextToken();\n        }\n        return a;\n    }\n\n    public static long gcd(long a,long b){\n        if(b==0){\n            return a;\n        }\n        else{\n            return gcd(b,a%b);\n        }\n    }\n\n    public long max(long a,long b,long c){\n        return Math.max(a,Math.max(b,c));\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.PrintWriter;\nimport java.util.*;\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 arr[]=new int[n];\n        for (int i=0;i<n;i++){\n            arr[i]=sc.nextInt();\n        }\n        boolean vis[]=new boolean[n];\n        int c=0;\n        for (int i=0;i<n;i++){\n            int min=200;\n            for (int j=0;j<n;j++){\n                if (!vis[j] && min>arr[j]){\n                    min=arr[j];\n                }\n            }\n            for (int j=0;j<n;j++){\n                if (!vis[j]&&arr[j]%min==0){\n                    vis[j]=true;\n//                    System.out.println(arr[j]);\n                }\n            }\n            if (min!=200){\n                c++;\n//                System.out.println(min+\" k\");\n            }else break;\n        }\n        System.out.println(c);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.* ;\n\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.io.*;\n\npublic class D\n{\n    int [][] adjList ;\n    int dfs(int u , int p )\n    {\n        int size = 1 ;\n        for(int v : adjList[u])\n            if(v != p )\n            {\n                int curr = dfs(v,  u) ;\n                size += curr ;\n            }\n        return size ;\n    }\n\n    void main() throws Exception\n    {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int n = sc.nextInt() ;\n        int [] a = new int [n] ;\n        boolean [] vis = new boolean[n] ;\n        int cnt = 0 ;\n        for(int i = 0 ;i < n ; i++)\n            a[i] = sc.nextInt() ;\n        sort(a);\n        for(int i = 0 ;i  < n ; i ++)\n        {\n            if(!vis[i])\n            {\n                for(int j= i  ; j < n ; j++)\n                    if(a[j] % a[i] == 0)\n                        vis[j] = true ;\n\n                cnt ++ ;\n            }\n        }\n\n        out.println(cnt);\n        out.flush();\n        out.close();\n    }\n\n    class SegmentTree\n    {\n        int [] sTree ;\n        int [] lazy ;\n        int N ;\n\n        SegmentTree(int n)\n        {\n            N = 1 << (32 - Integer.numberOfLeadingZeros(n - 1)) ;\n            sTree = new int [N << 1] ;\n            lazy= new int [N << 1] ;\n        }\n        void push(int node , int b , int e , int mid)\n        {\n            sTree[node << 1] += (mid - b + 1) * lazy[node] ;\n            sTree[node << 1 | 1] += (e - mid) * lazy[node] ;\n            lazy[node << 1] += lazy[node] ;\n            lazy[node << 1 | 1] += lazy[node] ;\n            lazy[node] = 0 ;\n        }\n        void updateRange(int node , int b , int e , int i , int j , int val)\n        {\n            if(i > e || j < b)return;\n\n            if(i <= b && e <= j)\n            {\n                sTree[node] += (e - b + 1) * val ;\n                lazy[node] += val ;\n                return;\n            }\n\n            int mid = b + e >> 1 ;\n            push(node , b , e , mid) ;\n            updateRange(node << 1 , b , mid , i , j , val);\n            updateRange(node << 1 | 1 , mid + 1 , e , i , j , val);\n            sTree[node] = sTree[node << 1] + sTree[node << 1 | 1] ;\n        }\n        int query(int node , int b , int e , int i , int j)\n        {\n            if(i > e || j < b)\n                return 0 ;\n            if(i <= b && e <= j)\n                return sTree[node] ;\n            int mid = b + e >> 1 ;\n            push(node  , b , e , mid);\n            return query(node << 1 , b , mid , i , j) + query(node << 1 | 1 , mid + 1 , e , i , j) ;\n        }\n\n    }\n    class Compressor\n    {\n        TreeSet<Integer> set = new TreeSet<>() ;\n        TreeMap<Integer ,Integer> map = new TreeMap<>()  ;\n\n        void add(int x)\n        {\n            set.add(x) ;\n        }\n        void fix()\n        {\n            for(int x : set)\n                map.put(x , map.size() + 1) ;\n        }\n        int get(int x)\n        {\n            return map.get(x) ;\n        }\n    }\n    class Scanner\n    {\n        BufferedReader br ;\n        StringTokenizer st ;\n\n        Scanner(InputStream in)\n        {\n            br = new BufferedReader(new InputStreamReader(in)) ;\n        }\n        String next() throws Exception\n        {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine()) ;\n            return st.nextToken() ;\n        }\n        int nextInt() throws Exception\n        {\n            return Integer.parseInt(next()) ;\n        }\n        long nextLong() throws Exception\n        {\n            return Long.parseLong(next()) ;\n        }\n        double nextDouble() throws Exception\n        {\n            return Double.parseDouble(next()) ;\n        }\n    }\n\n    public static void main (String [] args) throws Exception {(new D()).main();}\n\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A\n{\n    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer tok;\n\n    public void go() throws IOException\n    {\n        ntok();\n        int n = ipar();\n        ArrayList<Integer> list = new ArrayList<>();\n        ntok();\n        for (int i = 0; i < n; i++)\n        {\n            list.add(ipar());\n        }\n        Collections.sort(list);\n        HashSet<Integer> set = new HashSet<>();\n        for (int x : list)\n        {\n            boolean add = true;\n            for (int y : set)\n            {\n                if (x % y == 0)\n                {\n                    add = false;\n                    break;\n                }\n            }\n            if (add)\n            {\n                set.add(x);\n            }\n        }\n        out.println(set.size());\n\n        out.flush();\n        in.close();\n    }\n\n    public void ntok() throws IOException\n    {\n        tok = new StringTokenizer(in.readLine());\n    }\n\n    public int ipar()\n    {\n        return Integer.parseInt(tok.nextToken());\n    }\n\n    public int[] iapar(int n)\n    {\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = ipar();\n        }\n        return arr;\n    }\n\n    public long lpar()\n    {\n        return Long.parseLong(tok.nextToken());\n    }\n\n    public long[] lapar(int n)\n    {\n        long[] arr = new long[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = lpar();\n        }\n        return arr;\n    }\n\n    public double dpar()\n    {\n        return Double.parseDouble(tok.nextToken());\n    }\n\n    public String spar()\n    {\n        return tok.nextToken();\n    }\n\n    public static void main(String[] args) throws IOException\n    {\n        new A().go();\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\nimport java.lang.reflect.Array;\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        int n = in.nextInt();\n        boolean[] A = new boolean[n];\n        int count = 0;\n        int[] B = new int[n];\n        for (int i=0;i<n;i++)\n            B[i] = in.nextInt();\n        Arrays.sort(B);\n        for (int i=0;i<n;i++)\n        {\n            if (!A[i])\n            {\n                int gcd = B[i];\n                for (int j=0;j<n;j++)\n                {\n                    if(!A[j])\n                    {\n                        gcd = gcd(B[j], gcd);\n                        if(gcd == B[i])\n                        {\n                            A[j] = true;\n                        }\n                        else\n                        {\n                            gcd = B[i];\n                        }\n                    }\n                }\n                count++;\n                A[i] = true;\n            }\n        }\n        System.out.println(count);\n    }\n    public static int gcd(int a, int b)\n    {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\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<Long> primeFactorisation(long n)\n    {\n        ArrayList<Long> 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<bString.length();i++)\n        {\n            d = (d * d) % n;\n            if(bString.charAt(i) == '1')\n                d = (d * a) % n;\n        }\n        return d;\n    }\n}\nclass Name\n{\n    long d;\n    long x;\n    long y;\n\n    public Name(long d, long x, long y)\n    {\n        this.d = d;\n        this.x = x;\n        this.y = y;\n    }\n}\nclass SuffixArray\n{\n    int ALPHABET_SZ = 256, N;\n    int[] T, lcp, sa, sa2, rank, tmp, c;\n\n    public SuffixArray(String str)\n    {\n        this(toIntArray(str));\n    }\n\n    private static int[] toIntArray(String s)\n    {\n        int[] text = new int[s.length()];\n        for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i);\n        return text;\n    }\n\n    public SuffixArray(int[] text)\n    {\n        T = text;\n        N = text.length;\n        sa = new int[N];\n        sa2 = new int[N];\n        rank = new int[N];\n        c = new int[Math.max(ALPHABET_SZ, N)];\n        construct();\n        kasai();\n    }\n\n    private void construct()\n    {\n        int i, p, r;\n        for (i = 0; i < N; ++i) c[rank[i] = T[i]]++;\n        for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];\n        for (i = N - 1; 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<Integer> 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<Integer> 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<pattern.length;)\n        {\n            if(pattern[i] == pattern[index])\n            {\n                lps[i] = index + 1;\n                index++;\n                i++;\n            }\n            else\n            {\n                if(index != 0)\n                {\n                    index = lps[index - 1];\n                }\n                else\n                {\n                    lps[i] = 0;\n                    i++;\n                }\n            }\n        }\n        return lps;\n    }\n\n    public ArrayList<Integer> 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<Integer> 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<n;i++)\n        {\n            powers[i] = (powers[i - 1] * p) % m;\n        }\n        return powers;\n    }\n    public long computeHash(String s)\n    {\n        long p = 31;\n        long m = 1_000_000_009;\n        long hashValue = 0L;\n        long[] powers = computePowers(p, s.length(), m);\n        for(int i=0;i<s.length();i++)\n        {\n            char ch = s.charAt(i);\n            hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m;\n        }\n        return hashValue;\n    }\n}\nclass BasicFunctions\n{\n    public long min(long[] A)\n    {\n        long min = Long.MAX_VALUE;\n        for(int i=0;i<A.length;i++)\n        {\n            min = Math.min(min, A[i]);\n        }\n        return min;\n    }\n    public long max(long[] A)\n    {\n        long max = Long.MAX_VALUE;\n        for(int i=0;i<A.length;i++)\n        {\n            max = Math.max(max, A[i]);\n        }\n        return max;\n    }\n}\nclass MergeSortInt\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        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n\n        /* Create temp arrays */\n        int L[] = new int[n1];\n        int R[] = new int[n2];\n\n        /*Copy data to temp arrays*/\n        for (int i = 0; i < n1; ++i)\n            L[i] = arr[l + i];\n        for (int j = 0; j < n2; ++j)\n            R[j] = arr[m + 1 + j];\n\n\n        /* Merge the temp arrays */\n\n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n\n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2) {\n            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        /* Copy remaining elements of L[] if any */\n        while (i < n1) {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n\n        /* Copy remaining elements of R[] if any */\n        while (j < n2) {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n\n    // Main function that sorts arr[l..r] using\n    // merge()\n    void sort(int arr[], int l, int r) {\n        if (l < r) {\n            // Find the middle point\n            int m = (l + r) / 2;\n\n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr, m + 1, r);\n\n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n\n}\nclass MergeSortLong\n{\n    // Merges two subarrays of arr[].\n    // First subarray is arr[l..m]\n    // Second subarray is arr[m+1..r]\n    void merge(long arr[], int l, int m, int r) {\n        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n\n        /* Create temp arrays */\n        long L[] = new long[n1];\n        long R[] = new long[n2];\n\n        /*Copy data to temp arrays*/\n        for (int i = 0; i < n1; ++i)\n            L[i] = arr[l + i];\n        for (int j = 0; j < n2; ++j)\n            R[j] = arr[m + 1 + j];\n\n\n        /* Merge the temp arrays */\n\n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n\n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2) {\n            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        /* Copy remaining elements of L[] if any */\n        while (i < n1) {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n\n        /* Copy remaining elements of R[] if any */\n        while (j < n2) {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n\n    // Main function that sorts arr[l..r] using\n    // merge()\n    void sort(long arr[], int l, int r) {\n        if (l < r) {\n            // Find the middle point\n            int m = (l + r) / 2;\n\n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr, m + 1, r);\n\n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n}\nclass Node\n{\n    String s;\n    Node(String s)\n    {\n        this.s = s;\n    }\n\n    @Override\n    public boolean equals(Object ob)\n    {\n        if(ob == null)\n            return false;\n        if(!(ob instanceof Node))\n            return false;\n        if(ob == this)\n            return true;\n        Node obj = (Node)ob;\n        if(this.s.equals(obj.s))\n            return true;\n        return false;\n    }\n\n    @Override\n    public int hashCode()\n    {\n        return (int)this.s.length();\n    }\n}\nclass 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}\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<segmentTree.length;i++)\n            segmentTree[i] = Integer.MIN_VALUE;\n\n        constructSegmentTree(segmentTree,input,0,input.length-1,0);\n        return segmentTree;\n\n    }\n    private void constructSegmentTree(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        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);\n        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);\n        segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);\n    }\n    public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len)\n    {\n        return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0);\n    }\n    private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos)\n    {\n        if(qlow <= low && qhigh >= 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<Character, TrieNode> 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            return;\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}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Hack{\npublic static void main(String[] args){\nScanner sc = new Scanner(System.in);\nint n=sc.nextInt();\nint[] arr = new int[n];\nfor(int i=0;i<n;i++)\narr[i]=sc.nextInt();\nArrays.sort(arr);\nSet<Integer> set = new TreeSet<Integer>();\nfor(int i=0;i<n;i++){\nboolean flag=false;\nfor(Integer x:set){\nif(arr[i]%x==0){\nflag=true;\nbreak;\n}\n}\nif(!flag)\nset.add(arr[i]);\n}\nSystem.out.println(set.size());\n}\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class paint {\n\tstatic PriorityQueue<Integer> sequence;\n\t\n\tpublic static void main (String [] args) throws IOException {\n\t    BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t    PrintWriter out = new PrintWriter(System.out, true);\n\t    int numSeq = Integer.parseInt(f.readLine());\n\t    sequence = new PriorityQueue<Integer>();\n\t    \n\t    StringTokenizer st = new StringTokenizer(f.readLine());\n\t    for(int i = 0; i < numSeq; i++) {\n\t    \tsequence.add(Integer.parseInt(st.nextToken()));\n\t    }\n\t    \n\t    int numColors = 0;\n\t    while(sequence.size() > 0) {\n\t    \tnumColors++;\n\t    \tint smallest = sequence.poll();\n\t    \tPriorityQueue<Integer> temp = new PriorityQueue<Integer>();\n\t    \tfor(int each: sequence) {\n\t    \t\tif(each % smallest != 0) {\n\t    \t\t\ttemp.add(each);\n\t    \t\t}\n\t    \t}\n\t    \tsequence = temp;\n\t    }\n\t    \n\t    System.out.println(numColors);\n\t    out.close();\n\t}\n\t\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.security.KeyPair;\nimport java.util.*;\n\npublic class Main {\n\n    static long[][] c ;\n    static long[] arr;\n    static long n , m , k;\n    static long dp[][][];\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        int[] mark = new int[n];\n        for (int i = 0 ; i < n  ; i++){\n            arr[i] = Reader.nextInt();\n        }\n        Arrays.sort(arr);\n        int[] v = new int[n];\n        int ans = 0;\n        for (int i = 0 ; i < n ; i++){\n            if (v[i]==0){\n                for (int j = i ; j < n ; j++){\n                    if (arr[j]%arr[i]==0){\n                        v[j] = arr[i];\n                    }\n                }\n            }\n        }\n        TreeSet<Integer> s = new TreeSet<>();\n        for (int i = 0 ; i < n ;i++){\n            s.add(v[i]);\n        }\n        System.out.println(s.size());\n\n\n\n\n\n        \n    }\n\n\n\n    public static void sortbyColumn_asc(int arr[][], int col)\n    {\n        // Using built-in sort function Arrays.sort\n        Arrays.sort(arr, new Comparator<int[]>() {\n\n            @Override\n            // Compare values according to columns\n            public int compare(final int[] entry1,\n                               final int[] entry2) {\n\n                // To sort in descending order revert\n                // the '>' Operator\n                if (entry1[col] > entry2[col])\n                    return 1;\n                else\n                    return -1;\n            }\n        });  // End of function call sort().\n    }\n\n    public static void sortbyColumn_dsc(int arr[][], int col)\n    {\n        // Using built-in sort function Arrays.sort\n        Arrays.sort(arr, new Comparator<int[]>() {\n\n            @Override\n            // Compare values according to columns\n            public int compare(final int[] entry1,\n                               final int[] entry2) {\n\n                // To sort in descending order revert\n                // the '>' Operator\n                if (entry1[col] > entry2[col])\n                    return -1;\n                else\n                    return 1;\n            }\n        });  // End of function call sort().\n    }\n\n    static void swap(char[] arr , int i , int j){\n        char tmp = arr[i];\n        arr[i] = arr[j];\n        arr[j] = tmp;\n    }\n\n    static void swap(int[] arr , int i , int j){\n        int tmp = arr[i];\n        arr[i] = arr[j];\n        arr[j] = tmp;\n    }\n\n\n\n\n\n}\n\nclass Node implements Comparable<Node>{\n    int a ,  b;\n    Node(int a , int b){\n        this.a = a;\n        this.b = b;\n    }\n    public int compareTo(Node o) {\n        if (this.a == o.a){\n            return this.b - o.b;\n        }\n        return this.a - o.a;\n    }\n}\nclass Edge implements Comparable<Edge>{\n    int x , y , w;\n\n    public Edge(int x, int y, int w) {\n        this.x = x;\n        this.y = y;\n        this.w = w;\n    }\n\n    @Override\n    public int compareTo(Edge o) {\n        return this.w - o.w;\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    /** 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 MergeSort\n{\n    // Merges two subarrays of arr[].\n    // First subarray is arr[l..m]\n    // Second subarray is arr[m+1..r]\n    void merge(int arr[], int l, int m, int r)\n    {\n        // Find sizes of two subarrays to be merged\n        int n1 = m - l + 1;\n        int n2 = r - m;\n\n        /* Create temp arrays */\n        int L[] = new int [n1];\n        int R[] = new int [n2];\n\n        /*Copy data to temp arrays*/\n        for (int i=0; i<n1; ++i)\n            L[i] = arr[l + i];\n        for (int j=0; j<n2; ++j)\n            R[j] = arr[m + 1+ j];\n\n\n        /* Merge the temp arrays */\n\n        // Initial indexes of first and second subarrays\n        int i = 0, j = 0;\n\n        // Initial index of merged subarry array\n        int k = l;\n        while (i < n1 && j < n2)\n        {\n            if (L[i] <= R[j])\n            {\n                arr[k] = L[i];\n                i++;\n            }\n            else\n            {\n                arr[k] = R[j];\n                j++;\n            }\n            k++;\n        }\n\n        /* Copy remaining elements of L[] if any */\n        while (i < n1)\n        {\n            arr[k] = L[i];\n            i++;\n            k++;\n        }\n\n        /* Copy remaining elements of R[] if any */\n        while (j < n2)\n        {\n            arr[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n\n    // Main function that sorts arr[l..r] using\n    // merge()\n    void sort(int arr[], int l, int r)\n    {\n        if (l < r)\n        {\n            // Find the middle point\n            int m = (l+r)/2;\n\n            // Sort first and second halves\n            sort(arr, l, m);\n            sort(arr , m+1, r);\n\n            // Merge the sorted halves\n            merge(arr, l, m, r);\n        }\n    }\n\n    /* A utility function to print array of size n */\n    static void printArray(int arr[])\n    {\n        int n = arr.length;\n        for (int i=0; i<n; ++i)\n            System.out.print(arr[i] + \" \");\n        System.out.println();\n    }\n\n    // Driver method\n\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Paint {\n    public static void main (String srgs[] ){\n        \n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        TreeSet<Integer> ts=new TreeSet<>();\n        for(int i=0;i<n;++i){\n            ts.add(sc.nextInt());\n        }\n        int x=0;\n        int a[]=new int[ts.size()];\n        for(int y:ts){\n            a[x++]=y;\n        }\n        for(int i=0;i<ts.size()-1;++i){\n            for(int j=i+1;j<ts.size();++j){\n                if((a[i]!=-1)&&(a[j]!=-1)&&(a[j]%a[i]==0)){\n                    a[j]=-1;\n                }\n            }\n        }\n        int c=0;\n        for(int z:a){\n            if(z!=-1)++c;\n        }\n        System.out.print(c);\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n \npublic class Main {\n \n \n\tpublic static void main(String[] args) throws Exception{\n\t\tBufferedReader  jk =  new BufferedReader(new InputStreamReader( System.in))  ; \n\t\tPrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)) ; \n\t\tStringTokenizer ana = new StringTokenizer(jk.readLine()) ;\n\t\tint n = Integer.parseInt(ana.nextToken()) ; \n\t\t\n\t\tint t[]= new int[101] ; \n\t\tArrayList<Integer> v = new ArrayList<>() ; \n\t\tana = new StringTokenizer(jk.readLine()) ;\n\t\tfor(int i=0 ; i<n ;i++)\n\t\t{\n\t\t\t\n\t\t\tint y = Integer.parseInt(ana.nextToken()) ;\n\t\t\tt[y]=1 ; \n\t\t\tv.add(y) ; \n\t\t}\n\t\tCollections.sort(v);\n\t\tint c= 0; \n\t\tfor(int ele : v)\n\t\t{\n\t\t\tif(t[ele]==1)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tfor(int i=ele ; i<=100 ; i+=ele)\n\t\t\t\t{\n\t\t\t\t\tt[i]=2 ; \n\t\t\t\t}\n\t\t\t\tc++ ; \n\t\t\t}\n\t\t\n\t\t}\n\t\tout.println(c);\n\t\t\n \n \n \n \n \n \n \n \n\t\tout.flush();\n\t}\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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[] a = ir.nextIntArray(n);\n\t\tArrays.sort(a);\n\t\tboolean[] used = new boolean[n];\n\t\tint ct = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (used[i])\n\t\t\t\tcontinue;\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (a[j] % a[i] == 0)\n\t\t\t\t\tused[j] = true;\n\t\t\t}\n\t\t\tct++;\n\t\t}\n\t\tout.println(ct);\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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class Main {\n    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(System.out);\n        //Scanner sc = new Scanner();\n        Reader in = new Reader();\n        Main solver = new Main();\n        solver.solve(out, in);\n        out.flush();\n        out.close();\n \n    }\n \n    static int INF = (int)1e9;\n    static int maxn = (int)2e5+5;\n    static int mod= 998244353 ;\n    static int n,m,k,t,q,d,cnt=2;\n    \n    void solve(PrintWriter out, Reader in) throws IOException{\n        n = in.nextInt();\n        \n        Integer[] arr = new Integer[n];\n        for(int i=0;i<n;i++) arr[i] = in.nextInt();\n        \n        boolean[] vis = new boolean[n];\n        \n        Arrays.sort(arr);\n        int cnt=0;\n        for(int i=0;i<n;i++){\n            if(vis[i]) continue;\n            cnt++;\n            vis[i]=true;\n            for(int j=i+1;j<n;j++){\n                if(!vis[j]){\n                    if(arr[j]%arr[i]==0){\n                        vis[j]=true;\n                    }\n                }\n            }\n        }\n        \n        \n        out.println(cnt);\n        \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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main6{\n\nstatic class Pair\n\t{ \n\t\tint x;\n\t\tint y;\n\t\tint z;\n\t\tpublic Pair(int x,int y,int z) \n\t\t{\t \n\t\t\tthis.x= x; \n\t\t\tthis.y= y;\n\t\t\tthis.z=z;\n\t\t}\t \n\t\t\n\t@Override\n\t\t\tpublic int hashCode() \n\t\t\t{ \n\t\t\t\tfinal int temp = 14; \n\t\t\t\tint ans = 1; \n\t\t\t\tans =x*31+y*13; \n\t\t\t\treturn ans; \n\t\t\t} \n\t  \n\t\t\t// Equal objects must produce the same \n\t\t\t// hash code as long as they are equal \n\t\t@Override\n\t\tpublic boolean equals(Object o) \n\t\t{ \n\t\t\tif (this == o) { \n\t\t\t\treturn true; \n\t\t\t} \n\t\t\tif (o == null) { \n\t\t\t\treturn false; \n\t\t\t} \n\t\t\tif (this.getClass() != o.getClass()) { \n\t\t\t\treturn false; \n\t\t\t} \n\t\t\tPair other = (Pair)o; \n\t\t\tif (this.x != other.x || this.y!=other.y) { \n\t\t\t\treturn false; \n\t\t\t} \n\t\t\treturn true; \n\t\t} \n\t\t\t\n\t} \n\tstatic class Pair1\n\t{\n\t\tString x;\n\t\tint y;\n\t\tint z;\n\t\t\n\t}\n\tstatic class Compare\n\t{ \n\t\tstatic void compare(Pair arr[], int n) \n\t\t{ \n\t\t\t// Comparator to sort the pair according to second element \n\t\t/*\tArrays.sort(arr, new Comparator<Pair>() { \n\t\t\t\t@Override public int compare(Pair p1, Pair p2) \n\t\t\t\t{ \n\t\t\t\t\tif(p1.start>p2.start)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\telse if(p1.start==p2.start)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn 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\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t} \n\t\t\t}); */\n\t\t}\n\t\t\n\t}\n\t\n\t\n\tpublic static long pow(long a, long b)\n\t{\n\t\tlong 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)%998244353;\n\t\t\t\tb--;\n\t\t\t} \n\t\t\ta=(a*a)%998244353;\n\t\t\tb /= 2;\n\t\t}   \n\t\treturn result;\n\t}\n\tpublic static long fact(long num)\n\t{\n\t\t\t\tlong value=1;\n\t\t\t\tint i=0;\n\t\t\t\tfor(i=2;i<num;i++)\n\t\t\t\t{\n\t\t\t\t\tvalue=((value%mod)*i%mod)%mod;\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tpublic static int gcd(int a, int b)\n\t\t\t{\n\t\t\t\tif (a == 0)\n\t\t\t\t\treturn b;\n\t\t\t\treturn gcd(b%a, a);\n\t\t\t}\n\t\t\t\n\t/*\t\tpublic static long lcm(long a,long b)\n\t\t\t{\n\t\t\t\treturn a * (b / gcd(a, b));\n\t\t\t}\n\t\t*/\tpublic static long sum(int h)\n\t\t\t{\n\t\t\t\treturn (h*(h+1)/2);\n\t\t\t}\n\t\t\tpublic static void dfs(int parent,boolean[] visited,int[] dp)\n\t\t\t{\n\t\t\t\tArrayList<Integer> arr=new ArrayList<Integer>();\n\t\t\t\tarr=graph.get(parent);\n\t\t\t\tvisited[parent]=true;\n\t\t\t\tfor(int i=0;i<arr.size();i++)\n\t\t\t\t{\n\t\t\t\t\tint num=(int)arr.get(i);\n\t\t\t\t\tif(visited[num]==false)\n\t\t\t\t\t{\n\t\t\t\t\t\tdfs(num,visited,dp);\n\t\t\t\t\t}\n\t\t\t\t\tdp[parent]=Math.max(dp[num]+1,dp[parent]);\n\t\t\t\t}\n\t\t\t}\n\t\t//\tstatic int flag1=0;\n\t\t\tstatic int[] dis;\n\t\t\tstatic int mod=1000000007;\n\t\t\tstatic ArrayList<ArrayList<Integer>> graph;\n\t\t\t\n\t\t\tpublic static void bfs(int num,int size)\n\t\t\t{\n\t\t\t\tboolean[] visited=new boolean[size+1];\n\t\t\t\tQueue<Integer> q=new LinkedList<>();\n\t\t\t\tq.add(num);\n\t\t\t\tans[num]=1;\n\t\t\t\tvisited[num]=true;\n\t\t\t\twhile(!q.isEmpty())\n\t\t\t\t{\n\t\t\t\t\tint x=q.poll();\n\t\t\t\t\tArrayList<Integer> al=graph.get(x);\n\t\t\t\t\tfor(int i=0;i<al.size();i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tint y=al.get(i);\t\n\t\t\t\t\t\tif(visited[y]==false)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tq.add(y);\n\t\t\t\t\t\t\tans[y]=ans[x]+1;\n\t\t\t\t\t\t\tvisited[y]=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\tstatic int[] ans;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t//\tstatic int[] a;\t\t\t  \n\t\t\tpublic static int[] sort(int[] a)\n\t\t\t{\n\t\t\t\tint n=a.length;\n\t\t\t\tArrayList<Integer> ar=new ArrayList<>();\n\t\t\t\tfor(int i=0;i<a.length;i++)\n\t\t\t\t{\n\t\t\t\t\tar.add(a[i]);\n\t\t\t\t}\n\t\t\t\tCollections.sort(ar);\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t{\n\t\t\t\t\ta[i]=ar.get(i);\n\t\t\t\t}\n\t\t\t\treturn a;\n\t\t\t}\n\t\t\tstatic public void main(String args[])throws IOException\n\t\t\t{\n\t\t\t\tint n=i();\n\t\t\t\tint[] a=new int[n];\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t{\n\t\t\t\t\ta[i]=i();\n\t\t\t\t}\n\t\t\t\tArrays.sort(a);\n\t\t\t\tboolean[] flag=new boolean[n];\n\t\t\t\tint ans=0;\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t{\n\t\t\t\t\tif(flag[i]==false)\n\t\t\t\t\t{\n\t\t\t\t\t\tans++;\n\t\t\t\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(a[j]%a[i]==0 && flag[j]==false)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tflag[j]=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\tpln(ans+\"\");\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t/**/\n\t\t\tstatic InputReader in=new InputReader(System.in);\n\t\t\t\tstatic OutputWriter out=new OutputWriter(System.out);\n\t\t\t\tpublic static long l()\n\t\t\t\t{\n\t\t\t\t\tString s=in.String();\n\t\t\t\t\treturn Long.parseLong(s);\n\t\t\t\t}\n\t\t\t\tpublic static void pln(String value)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(value);\n\t\t\t\t}\n\t\t\t\tpublic static int i()\n\t\t\t\t{\n\t\t\t\t\treturn in.Int();\n\t\t\t\t}\n\t\t\t\tpublic static String s()\n\t\t\t\t{\n\t\t\t\t\treturn in.String();\n\t\t\t\t}\n\t}\n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \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\tclass InputReader {\n\t\t\t \n\t\t\tprivate InputStream stream;\n\t\t\tprivate byte[] buf = new byte[1024];\n\t\t\tprivate int curChar;\n\t\t\tprivate int numChars;\n\t\t\tprivate SpaceCharFilter filter;\n\t\t \n\t\t\tpublic InputReader(InputStream stream) {\n\t\t\t\tthis.stream = stream;\n\t\t\t}\n\t\t \n\t\t\tpublic int read() {\n\t\t\t\tif (numChars== -1)\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tif (curChar >= numChars) {\n\t\t\t\t\tcurChar = 0;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t}\n\t\t\t\t\tif (numChars <= 0)\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\treturn buf[curChar++];\n\t\t\t}\n\t\t \n\t\t\tpublic int Int() {\n\t\t\t\tint c = read();\n\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\tc = read();\n\t\t\t\tint sgn = 1;\n\t\t\t\tif (c == '-') {\n\t\t\t\t\tsgn = -1;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t\tint res = 0;\n\t\t\t\tdo {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\tc = read();\n\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t\t}\n\t\t \n\t\t\tpublic String String() {\n\t\t\t\tint c = read();\n\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\tc = read();\n\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\tdo {\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\tc = read();\n\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\treturn res.toString();\n\t\t\t}\n\t\t \n\t\t\tpublic boolean isSpaceChar(int c) {\n\t\t\t\tif (filter != null)\n\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t}\n\t\t \n\t\t\tpublic String next() {\n\t\t\t\treturn String();\n\t\t\t}\n\t\t \n\t\t\tpublic interface SpaceCharFilter {\n\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t}\n\t\t}\n\t\t \n\t\tclass OutputWriter {\n\t\t\tprivate final PrintWriter writer;\n\t\t \n\t\t\tpublic OutputWriter(OutputStream outputStream) {\n\t\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t\t\t}\n\t\t \n\t\t\tpublic OutputWriter(Writer writer) {\n\t\t\t\tthis.writer = new PrintWriter(writer);\n\t\t\t}\n\t\t \n\t\t\tpublic void print(Object...objects) {\n\t\t\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\t\t\tif (i != 0)\n\t\t\t\t\t\twriter.print(' ');\n\t\t\t\t\twriter.print(objects[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t \n\t\t\tpublic void printLine(Object...objects) {\n\t\t\t\tprint(objects);\n\t\t\t\twriter.println();\n\t\t\t}\n\t\t \n\t\t\tpublic void close() {\n\t\t\t\twriter.close();\n\t\t\t}\n\t\t \n\t\t\tpublic void flush() {\n\t\t\t\twriter.flush();\n\t\t\t}\n\t\t \n\t\t\t}\n\t\t \n\t\t\tclass IOUtils {\n\t\t \n\t\t\tpublic static int[] readIntArray(InputReader in, int size) {\n\t\t\t\tint[] array = new int[size];\n\t\t\t\tfor (int i = 0; i < size; i++)\n\t\t\t\t\tarray[i] = in.Int();\n\t\t\t\treturn array;\n\t\t\t}\n\t\t \n\t\t\t} ", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\n\nimport 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 sc = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Task solver = new Task();\n        solver.solve(1, sc, out);\n        out.close();\n    }\n\n    static class Task {\n        public void solve(int testNumber, InputReader sc, PrintWriter out) {\n            int n=sc.nextInt();\n            int[] a=new int[n];\n            boolean[] jud=new boolean[101];\n            \n            for(int i=0;i<n;i++)\n            \ta[i]=sc.nextInt();\n            Arrays.sort(a);\n            int ans=0;\n            for(int i=0;i<n;i++) {\n            \tif(jud[a[i]])\n            \t\tcontinue;\n            \tans++;\n            \tfor(int j=a[i];j<=100;j+=a[i])\n            \t\tjud[j]=true;\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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n \npublic class Main {\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();HashSet<Integer>nums=new HashSet<Integer>();\n\t\tint[]in=new int[n];for(int i=0;i<n;i++)in[i]=sc.nextInt();\n\t\tArrays.sort(in);\n\t\tint ans=0;\n\t\tboolean vis[]=new boolean[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(vis[i])continue;\n\t\t\tfor(int j=i+1;j<n;j++) {\n\t\t\t\tif(in[j]%in[i]==0) {\n\t\t\t\t\tvis[j]=true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans++;\n\t\t}\n\t\tpw.println(ans);\n\t\t\n\t\tpw.flush();\n\t}\n    static class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n \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 \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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "/**\n * @author Finn Lidbetter\n */\nimport java.util.*;\nimport java.io.*;\nimport java.awt.geom.*;\n\npublic class TaskA {\n  public static void main(String[] args) throws IOException {\n    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    StringBuilder sb = new StringBuilder();\n\n    int n = Integer.parseInt(br.readLine());\n    String[] s = br.readLine().split(\" \");\n    int[] arr = new int[n];\n    for (int i=0; i<n; i++) {\n      arr[i] = Integer.parseInt(s[i]);\n    }\n    Arrays.sort(arr);\n    boolean[] vis = new boolean[n];\n    int nColours = 0;\n    int nVis = 0;\n    int index = 0;\n    while (nVis<n) {\n      while (index<n && nVis<n) {\n        if (vis[index]) {\n          index++;\n          continue;\n        }\n        int val = arr[index];\n        nColours++;\n        while (index<n && nVis<n) {\n          if (vis[index]) {\n            index++;\n            continue;\n          }\n          if (arr[index]%val==0) {\n            vis[index] = true;\n            nVis++;\n          }\n          index++;\n        }\n        index = 0;\n      }\n    }\n    System.out.println(nColours);\n\n  }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner  scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        int[] nums = new int[n];\n        for(int i = 0; i < n; i++){\n            nums[i] = scan.nextInt();\n        }\n        Arrays.sort(nums);\n        boolean[] div = new boolean[n];\n        int count = 0;\n        for(int i = 0; i < n; i++) {\n            if (!div[i]) {\n\n                count++;\n                div[i] = true;\n                for(int j = i+1; j < n; j++) {\n                    if (nums[j] % nums[i] == 0) {\n                        div[j] = true;\n                    }\n                }\n            }\n        }\n        System.out.println(count);\n\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n    private final static long mod = 1000000007;\n\n    private final static int MAXN = 100001;\n\n    private static long power(long x, long y, long m) {\n        long temp;\n        if (y == 0)\n            return 1;\n        temp = power(x, y / 2, m);\n        temp = (temp * temp) % m;\n        if (y % 2 == 0)\n            return temp;\n        else\n            return ((x % m) * temp) % m;\n    }\n\n    private static long power(long x, long y) {\n        return power(x, y, mod);\n    }\n\n    private static long gcd(long a, long b) {\n        if (b == 0) return a;\n        return gcd(b, a % b);\n    }\n\n    static int nextPowerOf2(int a) {\n        return 1 << nextLog2(a);\n    }\n\n    static int nextLog2(int a) {\n        return (a == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(a - 1));\n    }\n\n    private static long modInverse(long a, long m) {\n        long m0 = m;\n        long y = 0, x = 1;\n        if (m == 1)\n            return 0;\n        while (a > 1) {\n            long q = a / m;\n            long t = m;\n            m = a % m;\n            a = t;\n            t = y;\n            y = x - q * y;\n            x = t;\n        }\n        if (x < 0)\n            x += m0;\n        return x;\n    }\n\n    private static int[] getLogArr(int n) {\n        int arr[] = new int[n + 1];\n        for (int i = 1; i < n + 1; i++) {\n            arr[i] = (int) (Math.log(i) / Math.log(2) + 1e-10);\n        }\n        return arr;\n    }\n\n    private static int log[] = getLogArr(MAXN);\n\n    private static int getLRMax(int st[][], int L, int R) {\n        int j = log[R - L + 1];\n        return Math.max(st[L][j], st[R - (1 << j) + 1][j]);\n    }\n\n    private static int[][] getSparseTable(int array[]) {\n        int k = log[MAXN] + 1;\n        int st[][] = new int[MAXN][k + 1];\n\n        for (int i = 0; i < array.length; i++)\n            st[i][0] = array[i];\n\n        for (int j = 1; j <= k; j++) {\n            for (int i = 0; i + (1 << j) <= array.length; i++) {\n                st[i][j] = Math.max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);\n            }\n        }\n        return st;\n    }\n\n    static class Subset {\n        int parent;\n        int rank;\n\n        @Override\n        public String toString() {\n            return \"\" + parent;\n        }\n    }\n\n    static int find(Subset[] Subsets, int i) {\n        if (Subsets[i].parent != i)\n            Subsets[i].parent = find(Subsets, Subsets[i].parent);\n        return Subsets[i].parent;\n    }\n\n    static void union(Subset[] Subsets, int x, int y) {\n        int xroot = find(Subsets, x);\n        int yroot = find(Subsets, y);\n\n        if (Subsets[xroot].rank < Subsets[yroot].rank)\n            Subsets[xroot].parent = yroot;\n        else if (Subsets[yroot].rank < Subsets[xroot].rank)\n            Subsets[yroot].parent = xroot;\n        else {\n            Subsets[xroot].parent = yroot;\n            Subsets[yroot].rank++;\n        }\n    }\n\n\n    private static int maxx(Integer... a) {\n        return Collections.max(Arrays.asList(a));\n    }\n\n\n    private static class Pair<T, U> {\n        T a;\n        U b;\n\n        public Pair(T a, U b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public boolean equals(Object o) {\n            if (this == o) return true;\n            if (o == null || getClass() != o.getClass()) return false;\n            Pair pair = (Pair) o;\n            return a.equals(pair.a) &&\n                    b.equals(pair.b);\n        }\n\n        @Override\n        public int hashCode() {\n            return Objects.hash(a, b);\n        }\n\n        @Override\n        public String toString() {\n            return \"(\" + a +\n                    \",\" + b +\n                    ')';\n        }\n    }\n\n\n    public static void main(String[] args) throws Exception {\n        try (FastReader in = new FastReader();\n             FastWriter out = new FastWriter()) {\n            int t, i, j, n, k, l, r, m, c, p, q, ti, tidx;\n            long x, y, z;\n\n            //for (t = in.nextInt(), tidx = 1; tidx <= t; tidx++)\n            {\n                //out.print(String.format(\"Case #%d: \", tidx));\n                n=in.nextInt();\n                int a[]=new int[101];\n                for (i=0;i<n;i++){\n                    a[in.nextInt()]++;\n                }\n                m=0;\n                for(i=1;i<101;i++){\n                    if(a[i]>0){\n                        m++;\n                        for(j=i;j<=100;j+=i){\n                            a[j]=0;\n                        }\n                    }\n                }\n                out.println(m);\n            }\n            out.commit();\n        }\n    }\n\n\n    static class FastReader implements Closeable {\n        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        private StringTokenizer st;\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n\n        int[] nextIntArr(int n) {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n            return arr;\n        }\n\n        double[] nextDoubleArr(int n) {\n            double[] arr = new double[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextDouble();\n            }\n            return arr;\n        }\n\n        long[] nextLongArr(int n) {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n            return arr;\n        }\n\n        String[] nextStrArr(int n) {\n            String[] arr = new String[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = next();\n            }\n            return arr;\n        }\n\n        int[][] nextIntArr2(int n, int m) {\n            int[][] arr = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextIntArr(m);\n            }\n            return arr;\n        }\n\n        long[][] nextLongArr2(int n, int m) {\n            long[][] arr = new long[n][m];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLongArr(m);\n            }\n            return arr;\n        }\n\n        @Override\n        public void close() throws IOException {\n            br.close();\n        }\n    }\n\n\n    static class FastWriter implements Closeable {\n        BufferedWriter bw;\n        StringBuilder sb = new StringBuilder();\n        List<String> list = new ArrayList<>();\n        Set<String> set = new HashSet<>();\n\n        FastWriter() {\n            bw = new BufferedWriter(new OutputStreamWriter(System.out));\n        }\n\n        <T> void commit() throws IOException {\n            bw.write(sb.toString());\n            bw.flush();\n            sb = new StringBuilder();\n        }\n\n        <T> void print(T obj) {\n            sb.append(obj.toString());\n        }\n\n        void println() throws IOException {\n            print(\"\\n\");\n        }\n\n        <T> void println(T obj) throws IOException {\n            print(obj.toString() + \"\\n\");\n        }\n\n        <T> 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        <T> 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        <T> void printColl(Collection<T> coll) throws IOException {\n            for (T e : coll) {\n                print(e + \" \");\n            }\n            println();\n        }\n\n        void printCharN(char c, int n) throws IOException {\n            for (int i = 0; i < n; i++) {\n                print(c);\n            }\n        }\n\n        void printIntArr2(int[][] arr) throws IOException {\n            for (int j = 0; j < arr.length; j++) {\n                for (int i = 0; i < arr[j].length - 1; i++) {\n                    print(arr[j][i] + \" \");\n                }\n                println(arr[j][arr.length - 1]);\n            }\n        }\n\n        @Override\n        public void close() throws IOException {\n            bw.close();\n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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 anand.oza\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        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n\n            int[] a = in.readIntArray(n);\n\n            Arrays.sort(a);\n\n            int answer = 0;\n            for (int i = 0; i < n; i++) {\n                if (a[i] == 0)\n                    continue;\n\n                answer++;\n                for (int j = 0; j < n; j++) {\n                    if (j == i)\n                        continue;\n                    if (a[j] % a[i] == 0) {\n                        a[j] = 0;\n                    }\n                }\n\n                a[i] = 0;\n            }\n\n            out.println(answer);\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 int[] readIntArray(int n) {\n            int[] x = new int[n];\n            for (int i = 0; i < n; i++) {\n                x[i] = nextInt();\n            }\n            return x;\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class kosyaDetka {\n    public static void main(String[] args){\n        Scanner scan = new Scanner(System.in);\n\n        int t = scan.nextInt();\n\n        ArrayList<Integer> arr = new ArrayList<>();\n\n        for(int i = 0; i < t; i++){\n            arr.add( scan.nextInt());\n        }\n\n        int count = 0;\n\n        while (arr.size() != 0){\n\n            int min = Integer.MAX_VALUE;\n\n            for(int i = 0; i < arr.size(); i++){\n                int temp = arr.get(i);\n                if( temp < min){\n                    min = temp;\n                }\n            }\n\n\n            for(int i = 0; i < arr.size(); i++){\n                int temp = arr.get(i);\n                if( temp % min == 0){\n                    arr.remove(i);\n                    i--;\n                }\n            }\n\n            count++;\n        }\n\n        System.out.println(count);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class DivRound584ProblemA {\n\tstatic FastReader sc=new FastReader();\n\t\n\tpublic static void main(String args[]) throws IOException {\n\t\tint n = sc.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]=sc.nextInt();\n\t\t\n\t\tArrays.sort(a);\n\t\tint c=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(a[i]<0) continue;\n\t\t\tc=c-1;\n\t\t\tfor(int j=i+1;j<n;j++) {\n\t\t\t\tif(a[j]<0) continue;\n\t\t\t\tif(a[j]%a[i]==0) {\n\t\t\t\t\t//System.out.println(a[i]+\" : \"+a[j]);\n\t\t\t\t\ta[j]=c;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//System.out.println(c);\n\t\t}\n\t\tSystem.out.println(Math.abs(c));\n\t}\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}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int count = sc.nextInt();\n        HashSet<Integer> set = new HashSet<>();\n\n        for (int i = 0; i < count; i++) {\n            set.add(sc.nextInt());\n        }\n\n        ArrayList<Integer> list = new ArrayList<>(set);\n\n        Collections.sort(list);\n\n        for (int i = 0; i < list.size(); i++) {\n            for (int j = i + 1; j < list.size(); j++) {\n\n                if (list.get(i) % list.get(j) == 0 ||\n                        list.get(j) % list.get(i) == 0) {\n                    list.remove(j);\n                    j--;\n                }\n            }\n        }\n\n        System.out.println(list.size());\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.Set;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n\n\n    private void run() throws IOException {\n\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n        int n = Integer.parseInt(reader.readLine());\n        int[] arr = new int[n];\n        String[] line = reader.readLine().split(\"\\\\s\");\n\n        for (int i = 0; i < n; i++) {\n            arr[i] = Integer.parseInt(line[i]);\n        }\n\n        Arrays.sort(arr);\n\n        Set<Integer> numbers = new HashSet<>();\n        for (int i = 0; i < arr.length; i++) {\n            Iterator<Integer> iter = numbers.iterator();\n            boolean contains = false;\n            while (iter.hasNext()){\n                int elem = iter.next();\n                if(gcd(elem, arr[i]) == elem){\n                    contains = true;\n                }\n\n            }\n            if(!contains)\n                numbers.add(arr[i]);\n        }\n\n\n        System.out.println(numbers.size());\n\n    }\n\n    private int gcd(int a, int b){\n        while (a != b){\n            if(a > b)\n                a -= b;\n            else\n                b -= a;\n        }\n\n        return a;\n    }\n\n\n\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class cf573 {\n    public static void main(String[] args){\n        Scanner scan=new Scanner(System.in);\n        int n=0;\n        if(scan.hasNext())\n            n=scan.nextInt();\n        TreeSet<Integer> set=new TreeSet<>();\n        for(int i=0;i<n;i++){\n            if(scan.hasNext())\n                set.add(scan.nextInt());\n        }\n        int[] arr=new int[set.size()];\n        Iterator<Integer> it=set.iterator();\n        int j=0;\n        while(it.hasNext()){\n            arr[j++]=it.next();\n        }\n        int tot=1,flag;\n        for(int i=1;i<arr.length;i++){\n            flag=0;\n            for(int k=0;k<i;k++){\n                if(arr[i]%arr[k]==0){\n                    flag=1;\n                    break;\n                }\n            }\n            if(flag==0){\n                tot++;\n            }\n        }\n        System.out.println(tot);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner scn = new Scanner(System.in);\n        int n = scn.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) a[i] = scn.nextInt();\n        scn.close();\n\n        Arrays.sort(a);\n\n        ArrayList<Integer> cyka = new ArrayList<>();\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (a[j] % a[i] == 0) {\n                    boolean add = true;\n                    for (int k : cyka) {\n                        if (a[i] % k == 0) {\n                            add = false;\n                            break;\n                        }\n                    }\n                    if (add) {\n                        cyka.add(a[i]);\n                    }\n                }\n            }\n        }\n\n        System.out.println(cyka.size());\n\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.math.BigInteger;\nimport java.nio.charset.Charset;\nimport java.util.*;\n\n\npublic class CFContest {\n    public static void main(String[] args) throws Exception {\n        boolean local = System.getProperty(\"ONLINE_JUDGE\") == null;\n        boolean async = true;\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        long lInf = (long) 1e18;\n\n        public Task(FastIO io, Debug debug) {\n            this.io = io;\n            this.debug = debug;\n        }\n\n        @Override\n        public void run() {\n            solve();\n        }\n\n        public void solve() {\n            int n = io.readInt();\n            int[] data = new int[n];\n            for (int i = 0; i < n; i++) {\n                data[i] = io.readInt();\n            }\n            Arrays.sort(data);\n            boolean[] paint = new boolean[n];\n            int cnt = 0;\n            for (int i = 0; i < n; i++) {\n                if (paint[i]) {\n                    continue;\n                }\n                cnt++;\n                for (int j = i; j < n; j++) {\n                    if (data[j] % data[i] == 0) {\n                        paint[j] = true;\n                    }\n                }\n            }\n\n            io.cache.append(cnt);\n        }\n\n    }\n\n\n    public static class FastIO {\n        public final StringBuilder cache = new StringBuilder(20 << 20);\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 << 20];\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}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class A {\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(reader.readLine());\n        String str[] = reader.readLine().split(\" \");\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = Integer.parseInt(str[i]);\n        }\n        Arrays.sort(a);\n        int k = 0;\n        for (int i = 0; i < n; i++) {\n            if (a[i] == 0){\n                continue;\n            }\n            for (int j = i + 1; j < n; j++) {\n                if (a[j] % a[i] == 0){\n                    a[j] = 0;\n                }\n            }\n            k++;\n        }\n        System.out.println(k);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.Collections;\npublic class Paint_The_Numbers {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tArrayList<Integer> paint = new ArrayList<Integer>();\n\t\tint num = scan.nextInt();\n\t\tfor(int i = 0; i < num;i++)\n\t\t\tpaint.add(scan.nextInt());\n\t\tCollections.sort(paint);\n\t\tint counter = 0;\n\t\t//System.out.println(paint);\n\t\twhile(paint.size()!=0) {\n\t\t\tnum = paint.remove(0);\n\t\t\tfor(int i = 0; i<paint.size();i++) {\n\t\t\t\tif(paint.get(i)%num==0) {\n\t\t\t\t\tpaint.remove(i--);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcounter++;\n\t\t}\n\t\tSystem.out.println(counter);\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class code_1 {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner in=new Scanner(System.in);\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\tArrays.sort(a);\n\t\t\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\t\n\t\t\tif(a[i]!=-1) {\n\t\t\t\tfor(int j=i+1;j<n;j++) {\n\t\t\t\t\t\n\t\t\t\t\tif(a[j]%a[i]==0)\n\t\t\t\t\t\ta[j]=-1;\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\t\n\t\tint count=0;\n\t\t\n\t\tfor(int i=0;i<n;i++) {\n\t\t\t\n\t\t\tif(a[i]!=-1)\n\t\t\t\tcount++;\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n  \npublic class A1 {   \n \n\tpublic static BufferedReader br;\n    public static StringTokenizer st;\n    public static String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return st.nextToken();\n    }\n \n    public static Integer nextInt() {\n        return Integer.parseInt(next());\n    }\n \n    public static Long nextLong() {\n        return Long.parseLong(next());\n    }\n \n    public static Double nextDouble() {\n        return Double.parseDouble(next());\n    }\n \n    static long fast_pow(long base,long n,long M)\n    {\n        if(n==0)\n           return 1;\n        if(n==1)\n        return base;\n        long halfn=fast_pow(base,n/2,M);\n        if(n%2==0)\n            return ( halfn * halfn ) % M;\n        else\n            return ( ( ( halfn * halfn ) % M ) * base ) % M;\n    }\n \n    static long finextDoubleMMI_fermat(long n,int M)\n    {\n        return fast_pow(n,M-2,M);\n    }\n \n    static long nCrModPFermat(int n, int r, int p) \n    { \n        if (r == 0) \n            return 1; \n        long[] fac = new long[n+1]; \n        fac[0] = 1;           \n        for (int i = 1 ;i <= n; i++) \n            fac[i] = fac[i-1] * i % p;       \n        return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p; \n    } \n \n    static void merge(int arr[], int l, int m, int r) \n    { \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<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        \n        int k = l; \n        while (i < n1 && j < n2) \n        { \n            if (L[i] <= R[j]) \n            { \n                arr[k] = L[i]; \n                i++; \n            } \n            else\n            { \n                arr[k] = R[j]; \n                j++; \n            } \n            k++; \n        } \n  \n        while (i < n1) \n        { \n            arr[k] = L[i]; \n            i++; \n            k++; \n        } \n  \n        while (j < n2) \n        { \n            arr[k] = R[j]; \n            j++; \n            k++; \n        } \n    } \n  \n    static void sort(int arr[], int l, int r) \n    { \n        if (l < r) \n        { \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    { \n        int l=0;\n        int r=arr.length-1;\n        if (l < r) \n        { \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 long gcd(long a, long b){\n        if(a%b==0)\n            return b;\n        if(b%a==0)\n            return a;\n        if(a>b)\n            return gcd(a%b,b);\n        return gcd(a,b%a);\n    }\n \n    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \n    public static void main(String args[])throws IOException{\n    \tint i,j;\n        br = new BufferedReader(new InputStreamReader(System.in));\n        int n=nextInt();\n        int a[]=new int[n];\n        for(i=0;i<n;i++)\n            a[i]=nextInt();\n        Arrays.sort(a);\n        int l=0;\n        for(i=0;i<n;i++){\n            if(a[i]!=-1){\n                int p=a[i];\n                for(j=i;j<n;j++){\n                    if(a[j]%p==0)\n                        a[j]=-1;\n                }\n                l++;\n            }\n        }\n        pw.println(l);\n        pw.close();\n    }\n}\t\n\n\n\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.util.concurrent.ThreadLocalRandom;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class Main2 {\n\n    static long mod = 998244353;\n    static FastScanner scanner;\n\n    static Set<Long> second = new HashSet<>();\n    static boolean applied = false;\n\n    public static void main(String[] args) {\n        scanner = new FastScanner();\n        int n = scanner.nextInt();\n        int[] a = scanner.nextIntArray(n);\n        int[] colors = new int[n];\n        ADUtils.sort(a);\n        int color = 0;\n        for (int i = 0; i < n; i++) {\n            if (colors[i] != 0) continue;\n            color++;\n            for (int j = i; j < n; j++) {\n                if (a[j] % a[i] == 0) colors[j] = color;\n            }\n        }\n        System.out.println(color);\n    }\n\n    static class WithIdx implements Comparable<WithIdx>{\n        int val, 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            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\n/*\n5 6\n1 4\n2 3\n3 4\n4 5\n5 2\n3 5\n\n5 8\n1 2\n2 3\n1 3\n4 3\n3 4\n4 1\n4 5\n5 1\n */", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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 prakhar897\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        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt();\n            int arr[] = in.nextIntArray(n);\n            Arrays.sort(arr);\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                if (arr[i] == -1)\n                    continue;\n                else {\n                    //out.println(arr[i]);\n                    ans++;\n                    for (int j = i + 1; j < n; j++) {\n                        if (arr[j] % arr[i] == 0)\n                            arr[j] = -1;\n                    }\n                    arr[i] = -1;\n                    //out.println(arr);\n                }\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public int[] nextIntArray(int n) {\n            int[] array = new int[n];\n            for (int i = 0; i < n; ++i) array[i] = nextInt();\n            return array;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "/*Author: Satyajeet Singh, Delhi Technological University*/\n    import java.io.*;\n    import java.util.*;\n    import java.text.*; \n    import java.lang.*;\n    import java.math.*;\n \npublic class Main{\n/*********************************************Constants******************************************/\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        \n    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    static long mod=(long)1e9+7;\n    static long mod1=998244353;\n    static boolean sieve[];\n    static ArrayList<Integer> primes;\n    static long factorial[],invFactorial[];\n    static HashSet<Pair> graph[];\n    static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n/****************************************Solutions Begins***************************************/\n    public static void main (String[] args) throws Exception {\n        String st[]=nl();\n        int n=pi(st[0]);\n        int input[]=new int[n];\n        st=nl();\n        for(int i=0;i<n;i++){\n            input[i]=pi(st[i]);\n        }\n        int ans=0;\n        Arrays.sort(input);\n        boolean dp[]=new boolean[n];\n        for(int i=0;i<n;i++){\n            if(!dp[i]){\n                ans++;\n                for(int j=input[i];j<=200;j+=input[i]){\n                    for(int k=i;k<n;k++){\n                        if(input[k]==j&&!dp[k])dp[k]=true;\n                    }\n                }\n            }\n        }\n        out.println(ans);\n/****************************************Solutions Ends**************************************************/\n        out.flush();\n        out.close();\n    }\n/****************************************Template Begins************************************************/\n    static String[] nl() throws Exception{\n        return br.readLine().split(\" \");\n    }\n    static String[] nls() throws Exception{\n        return br.readLine().split(\"\");\n    }\n    static int pi(String str) {\n        return Integer.parseInt(str);\n    }\n    static long pl(String str){\n        return Long.parseLong(str);\n    }\n    static double pd(String str){\n        return Double.parseDouble(str);\n    }\n/***************************************Precision Printing**********************************************/\n    static void printPrecision(double d){\n        DecimalFormat ft = new DecimalFormat(\"0.000000000000000000000\"); \n        out.println(ft.format(d));\n    }\n/**************************************Bit Manipulation**************************************************/\n    static void printMask(long mask){\n        System.out.println(Long.toBinaryString(mask));\n    }\n    static int countBit(int mask){\n        int ans=0;\n        while(mask!=0){\n            if(mask%2==1){\n                ans++;\n            }\n            mask/=2;\n        }\n        return ans;\n    }\n/******************************************Graph*********************************************************/\n    static void Makegraph(int n){\n        graph=new HashSet[n];\n        for(int i=0;i<n;i++){\n            graph[i]=new HashSet<>();\n        }\n    }\n    static void addEdge(int a,int b){\n        graph[a].add(new Pair(b,1));\n    }\n    static void addEdge(int a,int b,int c){\n        graph[a].add(new Pair(b,c));\n    }    \n/*********************************************PAIR********************************************************/\n    static class PairComp implements Comparator<Pair>{\n        public int compare(Pair p1,Pair p2){\n            return p1.u-p2.u;\n        }\n    }\n    static class Pair implements Comparable<Pair> {\n        int u;\n        int v;\n        int index=-1;\n        public Pair(int u, int v) {\n            this.u = u;\n            this.v = v;\n        }\n        public int hashCode() {\n            int hu = (int) (u ^ (u >>> 32));\n            int hv = (int) (v ^ (v >>> 32));\n            return 31 * hu + hv;\n        }\n        public boolean equals(Object o) {\n            Pair other = (Pair) o;\n            return u == other.u && v == other.v;\n        }\n        public int compareTo(Pair other) {\n            if(index!=other.index)\n                return Long.compare(index, other.index);\n            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n        }\n        public String toString() {\n            return \"[u=\" + u + \", v=\" + v + \"]\";\n        }\n    }\n/******************************************Long Pair*******************************************************/\n    static class PairCompL implements Comparator<Pairl>{\n        public int compare(Pairl p1,Pairl p2){\n            if(p1.u-p2.u<0){\n                return -1;\n            }\n            else if(p1.u-p2.u>0){\n                return 1;\n            }\n            else{\n                if(p1.v-p2.v<0){\n                    return -1;\n                }\n                else if(p1.v-p2.v>0){\n                    return 1;\n                }\n                else{\n                    return 0;\n                }\n            }\n        }\n    }\n    static class Pairl implements Comparable<Pairl> {\n            long u;\n            long v;\n            int index=-1;\n            public Pairl(long u, long v) {\n                this.u = u;\n                this.v = v;\n            }\n    \n            public int hashCode() {\n                int hu = (int) (u ^ (u >>> 32));\n                int hv = (int) (v ^ (v >>> 32));\n                return 31 * hu + hv;\n            }\n    \n            public boolean equals(Object o) {\n                Pairl other = (Pairl) o;\n                return u == other.u && v == other.v;\n            }\n    \n            public int compareTo(Pairl other) {\n                if(index!=other.index)\n                    return Long.compare(index, other.index);\n                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n            }\n    \n            public String toString() {\n                return \"[u=\" + u + \", v=\" + v + \"]\";\n            }\n        }\n/*****************************************DEBUG***********************************************************/\n    public static void debug(Object... o) {\n        if(!oj)\n        System.out.println(Arrays.deepToString(o));\n    }\n/************************************MODULAR EXPONENTIATION***********************************************/\n    static long modulo(long a,long b,long c) {\n        long x=1;\n        long y=a;\n        while(b > 0){\n            if(b%2 == 1){\n                x=(x*y)%c;\n            }\n            y = (y*y)%c; // squaring the base\n            b /= 2;\n        }\n        return  x%c;\n    }\n/********************************************GCD**********************************************************/\n    static long gcd(long x, long y)\n    {\n        if(x==0)\n            return y;\n        if(y==0)\n            return x;\n        long r=0, a, b;\n        a = (x > y) ? x : y; // a is greater number\n        b = (x < y) ? x : y; // b is smaller number\n        r = b;\n        while(a % b != 0)\n        {\n            r = a % b;\n            a = b;\n            b = r;\n        }\n        return r;\n    }\n/******************************************SIEVE**********************************************************/\n    static void sieveMake(int n){\n        sieve=new boolean[n];\n        Arrays.fill(sieve,true);\n        sieve[0]=false;\n        sieve[1]=false;\n        for(int i=2;i*i<n;i++){\n            if(sieve[i]){\n                for(int j=i*i;j<n;j+=i){\n                    sieve[j]=false;\n                }\n            }\n        }\n        primes=new ArrayList<Integer>();\n        for(int i=0;i<n;i++){\n            if(sieve[i]){\n                primes.add(i);\n            }\n        }        \n    }\n/********************************************End***********************************************************/\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "// No sorceries shall previal. //\n         \nimport java.util.Scanner; \nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.util.Arrays;\n     \npublic class InVoker {\n  \n   public static void main(String args[]) {\n    \t\t\n    \tScanner inp = new Scanner(System.in);\n    \tPrintWriter out= new PrintWriter(System.out);\n    \t\n    \tint n=inp.nextInt();\n    \tint a[]=new int[n];\n    \tfor(int i=0;i<n;i++)\n    \t\ta[i]=inp.nextInt();\n    \tArrays.sort(a);\n    \tint gg=0;\n    \tfor(int i=0;i<n;i++) {\n    \t\tif(a[i]==0)\n    \t\t\tcontinue;\n    \t\tgg++;\n    \t\tfor(int j=i+1;j<n;j++) {\n    \t\t\tif(a[j]%a[i]==0) {\n    \t\t\t\ta[j]=0;\n    \t\t\t}\n    \t\t}\n    \t}\n    \tout.println(gg);\n    \tout.close();\n    \tinp.close();\n    \t\t\t\t\n    }\n    \t\t\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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 ilyakor\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    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\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n      int n = in.nextInt();\n      boolean[] a = new boolean[218];\n      for (int i = 0; i < n; ++i) {\n        a[in.nextInt()] = true;\n      }\n      int res = 0;\n      for (int i = 1; i < a.length; ++i) {\n        if (a[i]) {\n          ++res;\n          for (int j = i; j < a.length; j += i) {\n            a[j] = false;\n          }\n        }\n      }\n      out.printLine(res);\n    }\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  }\n\n  static class InputReader {\n\n    private InputStream stream;\n    private byte[] buffer = new byte[10000];\n    private int cur;\n    private int count;\n\n    public InputReader(InputStream stream) {\n      this.stream = stream;\n    }\n\n    public static boolean isSpace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int read() {\n      if (count == -1) {\n        throw new InputMismatchException();\n      }\n      try {\n        if (cur >= count) {\n          cur = 0;\n          count = stream.read(buffer);\n          if (count <= 0) {\n            return -1;\n          }\n        }\n      } catch (IOException e) {\n        throw new InputMismatchException();\n      }\n      return buffer[cur++];\n    }\n\n    public int readSkipSpace() {\n      int c;\n      do {\n        c = read();\n      } while (isSpace(c));\n      return c;\n    }\n\n    public int nextInt() {\n      int sgn = 1;\n      int c = readSkipSpace();\n      if (c == '-') {\n        sgn = -1;\n        c = read();\n      }\n      int res = 0;\n      do {\n        if (c < '0' || c > '9') {\n          throw new InputMismatchException();\n        }\n        res = res * 10 + c - '0';\n        c = read();\n      } while (!isSpace(c));\n      res *= sgn;\n      return res;\n    }\n\n  }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import javax.print.DocFlavor;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Round584_a {\n        public static void main(String[] args) throws Exception {\n                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n                StringTokenizer st;\n\n                int n = Integer.parseInt(br.readLine());\n                st = new StringTokenizer(br.readLine());\n                int a[] = new int[n];\n                for(int i=0 ; i<n ; i++) {\n                        a[i] = Integer.parseInt(st.nextToken());\n                }\n\n                Arrays.sort(a);\n\n                boolean vis[] = new boolean[n];\n                int count = 0;\n                for(int i=0 ; i<n ; i++) {\n                        if(!vis[i]) {\n                                for(int j=i ; j<n ; j++) {\n                                        if(!vis[j]) {\n                                                if(a[j]%a[i] == 0) {\n                                                        vis[j] = true;\n                                                }\n                                        }\n                                }\n                                count++;\n                        }\n                }\n\n                System.out.println(count);\n        }\n}\n\n/*import java.io.BufferedReader;\n        import java.io.InputStreamReader;\n        import java.util.StringTokenizer;\n\npublic class Round584_a {\n        public static void main(String[] args) throws Exception {\n                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n                StringTokenizer st;\n        }\n}*/\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\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[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = sc.nextInt();\n        }\n        Arrays.sort(a);\n\n        Set<Integer> div = new HashSet<>();\n        boolean[] d = new boolean[n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0 ; j < n; j++) {\n                if (d[j]) {\n                    continue;\n                }\n                if (a[j]%a[i] == 0) {\n                    d[j] = true;\n                    div.add(a[i]);\n                }\n            }\n        }\n\n        System.out.println(div.size());\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class A {\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 a[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = in.nextInt();\n        }\n        Arrays.sort(a);\n        int vis[] = new int[n];\n        Arrays.fill(vis, -1);\n        int c = 0;\n        for (int i = 0; i < n; i++) {\n            if (vis[i] != -1) continue;\n            c++;\n            for (int j = i; j < n; j++) {\n                if (vis[j] == -1 && a[j] % a[i] == 0) {\n                    vis[j] = c;\n                }\n            }\n        }\n        \n        pw.println(c);\n\n        pw.close();\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class Main {\n\n    public static void main(String args[]) {\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        IntStream.range(0, 1).forEach(tc -> {\n            new Solver(tc, in, out).solve();\n            out.flush();\n        });\n        out.close();\n    }\n}\n\nclass InputReader {\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n\n    InputReader(InputStream in) {\n        reader = new BufferedReader(new InputStreamReader(in));\n    }\n\n    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\n        return tokenizer.nextToken();\n    }\n\n    int nextInt() {\n        return Integer.valueOf(next());\n    }\n\n    double nextDouble() {\n        return Double.valueOf(next());\n    }\n\n    String nextLine() {\n        try {\n            return reader.readLine();\n        } catch (Exception e) {\n            throw new RuntimeException(e);\n        }\n    }\n}\n\nclass Solver {\n    private InputReader in;\n    private PrintWriter out;\n    private Integer tc;\n\n    Solver(Integer tc, InputReader in, PrintWriter out) {\n        this.in = in;\n        this.out = out;\n        this.tc = tc;\n    }\n\n    void solve() {\n        Integer n = in.nextInt();\n        TreeSet<Integer> list = IntStream.range(0, n)\n                .map(i -> in.nextInt())\n                .boxed()\n                .collect(Collectors.toCollection(TreeSet::new));\n\n        Integer answer = 0;\n        while (!list.isEmpty()) {\n            Integer x = list.pollFirst();\n            list = list.stream().filter(y -> y % x != 0).collect(Collectors.toCollection(TreeSet::new));\n            answer++;\n        }\n\n        out.println(answer);\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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.Collections;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\n\npublic class Tt {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner fs=new FastScanner(System.in);\n\t\tint j = fs.nextInt();\n\t\tArrayList<Integer> a =new ArrayList<Integer>();\n\t\tfor(int i=0;i<j;i++) {\n\t\t\ta.add(fs.nextInt());\n\t\t}\n\t\tCollections.sort(a);\n\t\tCollections.reverse(a);\n\t\tint c=0;\n\t\twhile(a.size()!=0) {\n\t\t\tint f=a.get(a.size()-1);\n\t\t\tc+=1;\n\t\t\tfor(int q=a.size()-1;q>-1;q--)\n\t\t\tif(a.get(q)%f==0) {\n\t\t\t\ta.remove(q);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(c);\n\t\t}\n\tstatic class FastScanner {\n\t    BufferedReader br;\n\t    StringTokenizer st;\n\t    public FastScanner(InputStream i){\n\t        br = new BufferedReader(new InputStreamReader(i));\n\t        st = new StringTokenizer(\"\");\n\t    }\n\t    public String next() throws IOException{\n\t        if(st.hasMoreTokens()) return st.nextToken();\n\t        else st = new StringTokenizer(br.readLine());\n\t        return next();\n\t    }\n\t    public long nextLong() throws IOException{ return Long.parseLong(next()); }\n\t    public int nextInt() throws IOException { return Integer.parseInt(next()); }\n\t    public double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\t    public String nextLine() throws IOException {\n\t        if(!st.hasMoreTokens()) \n\t            return br.readLine();\n\t        String ret = st.nextToken();\n\t        while(st.hasMoreTokens()) \n\t            ret += \" \" + st.nextToken();\n\t        return ret;\n\t    }\n\t}}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class paintNumbers {\n\tpublic static int minIndex(List<Integer> list) {\n\t\tint min = list.get(0);\n\t\tint minIndex = 0;\n\t\tfor (int i = 0; i < list.size(); i++) {\n\t\t\tif (list.get(i) < min) {\n\t\t\t\tmin = list.get(i);\n\t\t\t\tminIndex = i;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\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        int n = sc.nextInt();\n        List<Integer> list = new ArrayList<Integer>();\n        for (int i = 0; i < n; i++) {\n        \tlist.add(sc.nextInt());\n        }\n        int count = 0;\n        while (list.size() > 0) {\n        \tcount++;\n        \tint temp = list.get(minIndex(list));\n//        \tpw.println(\"min = \" + temp);\n        \tfor (int j = 0; j < list.size(); j++) {\n        \t\tif (list.get(j) % temp == 0) {\n//        \t\t\tpw.println(\"j = \" + list.get(j));\n//        \t\t\tpw.println(\"min = \" + temp);\n        \t\t\tlist.remove(j);\n        \t\t\tj--;\n        \t\t}\n        \t}\n//        \tfor (int i = 0; i < list.size(); i++) {\n//        \t\tpw.println(list.get(i) + \" \");\n//        \t}\n        }\n        pw.println(count);\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<n;++i)array[i]=nextInt();\n            return array;\n        }\n        public int[] nextSortedIntArray(int n){\n            int array[]=nextIntArray(n);\n            PriorityQueue<Integer> pq = new PriorityQueue<Integer>();\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<n;++i)array[i]=array[i-1]+nextInt();\n            return array;\n        }\n        public ArrayList<Integer>[] nextGraph(int n, int m){\n            ArrayList<Integer>[] adj = new ArrayList[n];\n            for(int i = 0; i < n; i++){\n                adj[i] = new ArrayList<Integer>();\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<Integer>[] 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<n;++i)array[i]=nextLong();\n            return array;\n        }\n        public long[] nextSumLongArray(int n){\n            long[] array=new long[n];\n            array[0]=nextInt();\n            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();\n            return array;\n        }\n        public long[] nextSortedLongArray(int n){\n            long array[]=nextLongArray(n);\n            Arrays.sort(array);\n            return array;\n        }\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "//package round584;\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 A {\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\tArrays.sort(a);\n\t\tboolean[] done = new boolean[n];\n\t\tint ans = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(!done[i]){\n\t\t\t\tans++;\n\t\t\t\tfor(int j = i+1;j < n;j++){\n\t\t\t\t\tif(a[j] % a[i] == 0){\n\t\t\t\t\t\tdone[j] = true;\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\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 A().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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n    public static void main(String[] args) {\n        new Thread(null, new Runnable() {\n            public void run() {\n                new Main().solve();\n            }\n        }, \"1\", 1 << 26).start();\n    }\n\n    void solve() {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        ScanReader in = new ScanReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int[] hash = new int[101];\n            boolean[] hash1 = new boolean[101];\n            for (int i = 0; i < n; i++) hash[in.scanInt()]++;\n            int ans = 0;\n            for (int i = 1; i <= 100; i++) {\n                if (hash1[i]) continue;\n                if (hash[i] == 0) continue;\n                for (int j = i; j <= 100; j += i) hash1[j] = true;\n                ans++;\n            }\n            out.println(ans);\n\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n \n        public static void main(String[] args) {\n            Scanner s = new Scanner(System.in);\n            int n=s.nextInt();\n            int a[]=new int[n];\n            for(int i=0;i<n;i++)\n            a[i]=s.nextInt();\n            Arrays.sort(a);\n            ArrayList<Integer>al=new ArrayList();\n            int k=a[0];\n            int count=0;\n            for(int j=0;j<n;j++)\n            {k=a[j];\n                if(Collections.frequency(al,a[j])==0)\n                {for(int i=0;i<n;i++)\n            {if(a[i]%k==0)\n            {al.add(a[i]);}}\n            count++;}}\n            System.out.println(count);}}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int n = scanner.nextInt();\n        int[] arr = new int[n];\n        for(int i = 0; i < n; i++) {\n            arr[i] = scanner.nextInt();\n        }\n        \n        Arrays.sort(arr);\n        int[] cols = new int[n];\n        Arrays.fill(cols, -1);\n        int ans = 0;\n        for(int i = 0; i < n; i++) {\n            if (cols[i] == -1) {\n                cols[i] = ans++;\n                for(int j = i + 1; j < n; j++) {\n                    if (arr[j] % arr[i] == 0) cols[j] = cols[i];\n                }\n            }\n        }\n        out.println(ans);\n        out.flush();\n    }\n    \n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "//package Round584;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Problem1 {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint a []=new int[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i]=sc.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n//\t\tSystem.out.println(Arrays.toString(a));\n\t\tint k=a.length;\n\t\tfor(int i=a.length-1;i>=0;i--) {\n\t\t\tint A=a[i];\n\t\t\tfor (int j=0;j<i;j++) {\n\t\t\t\tif(A%a[j]==0) {\n\t\t\t\t\tk--;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(k);\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n \n \npublic class Main {\n\t\n\tstatic InputReader in = new InputReader(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic int oo = (int)1e9;\n\tstatic int mod = 1000000007;\n\t\n\tpublic static void main(String[] args) throws IOException {\n \n\t\tint n = in.nextInt();\n\t\tint[] a = in.nextIntArray(n);\n\t\tArrays.sort(a);\n\t\tboolean[] color = new boolean[n];\n\t\tint cnt = 0;\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tif(!color[i]) {\n\t\t\t\tcnt++;\n\t\t\t\tfor(int j = i; j < n; j++) {\n\t\t\t\t\tif(a[j] % a[i] == 0)\n\t\t\t\t\t\tcolor[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(cnt);\n\t\t\n\t\tout.close();\n\t}\n\t\n\t\n\tstatic class SegmentTree {\n\t\tint n;\n\t\tlong[] a, seg;\n\t\tint DEFAULT_VALUE = 0;\n\t\t\n\t\tpublic SegmentTree(long[] a, int n) {\n\t\t\tsuper();\n\t\t\tthis.a = a;\n\t\t\tthis.n = n;\n\t\t\tseg = new long[n * 4 + 1];\n\t\t\tbuild(1, 0, n-1);\n\t\t}\n\t\t\n\t\tprivate long build(int node, int i, int j) {\n\t\t\tif(i == j)\n\t\t\t\treturn seg[node] = a[i];\n\t\t\tlong first = build(node * 2, i, (i+j) / 2);\n\t\t\tlong second = build(node * 2 + 1, (i+j) / 2 + 1, j);\n\t\t\treturn seg[node] = combine(first, second);\n\t\t}\n\t\t\n\t\tlong update(int k, long value) {\n\t\t\treturn update(1, 0, n-1, k, value);\n\t\t}\n\t\t\n\t\tprivate long update(int node, int i, int j, int k, long value) {\n\t\t\tif(k < i || k > j)\n\t\t\t\treturn seg[node];\n\t\t\tif(i == j && j == k) {\n\t\t\t\ta[k] = value;\n\t\t\t\tseg[node] = value;\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\t\n\t\t\tint m = (i + j) / 2;\n\t\t\tlong first = update(node * 2, i, m, k, value);\n\t\t\tlong second = update(node * 2 + 1, m + 1, j, k, value);\n\t\t\treturn seg[node] = combine(first, second);\n\t\t}\n\t\t\n\t\tlong query(int l, int r) {\n\t\t\treturn query(1, 0, n-1, l, r);\n\t\t}\n\t\t\n\t\tprivate long query(int node, int i, int j, int l, int r) {\n\t\t\tif(l <= i && j <= r)\n\t\t\t\treturn seg[node];\n\t\t\tif(j < l || i > r)\n\t\t\t\treturn DEFAULT_VALUE;\n\t\t\tint m = (i + j) / 2;\n\t\t\tlong first = query(node * 2, i, m, l, r);\n\t\t\tlong second = query(node * 2 + 1, m+1, j, l, r);\n\t\t\treturn combine(first, second);\n\t\t}\n \n\t\tprivate long combine(long a, long b) {\n\t\t\treturn a + b;\n\t\t}\n\t}\n\t\n\tstatic class DisjointSet {\n\t\tint n;\n\t\tint[] g;\n\t\tint[] h;\n\t\tpublic DisjointSet(int n) {\n\t\t\tsuper();\n\t\t\tthis.n = n;\n\t\t\tg = new int[n];\n\t\t\th = new int[n];\n\t\t\tfor(int i = 0; i < n; ++i) {\n\t\t\t\tg[i] = i;\n\t\t\t\th[i] = 1;\n\t\t\t}\n\t\t}\n\t\tint find(int x) {\n\t\t\tif(g[x] == x)\n\t\t\t\treturn x;\n\t\t\treturn g[x] = find(g[x]);\n\t\t}\n\t\tvoid union(int x, int y) {\n\t\t\tx = find(x); y = find(y);\n\t\t\tif(x == y)\n\t\t\t\treturn;\n\t\t\tif(h[x] >= h[y]) {\n\t\t\t\tg[y] = x;\n\t\t\t\tif(h[x] == h[y])\n\t\t\t\t\th[x]++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tg[x] = y;\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\tstatic int[] getPi(char[] a) {\n\t\tint m = a.length;\n\t\tint j = 0;\n\t\tint[] pi = new int[m];\n\t\tfor(int i = 1; i < m; ++i) {\n\t\t\twhile(j > 0 && a[i] != a[j])\n\t\t\t\tj = pi[j-1];\n\t\t\tif(a[i] == a[j]) {\n\t\t\t\tpi[i] = j + 1;\n\t\t\t\tj++;\n\t\t\t}\n\t\t}\n\t\treturn pi;\n\t}\n\t\n\tstatic long lcm(long a, long b) {\n\t\treturn a * b / gcd(a, b);\n\t}\n\t\n\tstatic boolean nextPermutation(int[] a) {\n\t\tfor(int i = a.length - 2; i >= 0; --i) {\n\t\t\tif(a[i] < a[i+1]) {\n\t\t\t\tfor(int j = a.length - 1; ; --j) {\n\t\t\t\t\tif(a[i] < a[j]) {\n\t\t\t\t\t\tint t = a[i];\n\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\tfor(i++, j = a.length - 1; i < j; ++i, --j) {\n\t\t\t\t\t\t\tt = a[i];\n\t\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\t\n\tstatic void shuffle(int[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tint t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic void shuffle(long[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tlong t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic int lower_bound(int[] a, int n, int k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\tstatic int lower_bound(long[] a, int n, long k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\t\n\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\tstatic long gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\t\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint first, second;\n \n\t\tpublic Pair(int first, int second) {\n\t\t\tsuper();\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn this.first != o.first ? this.first - o.first : this.second - o.second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + first;\n\t\t\tresult = prime * result + second;\n\t\t\treturn result;\n\t\t}\n \n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tPair other = (Pair) obj;\n\t\t\tif (first != other.first)\n\t\t\t\treturn false;\n\t\t\tif (second != other.second)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n \n \n \nclass InputReader {\n \n\tprivate final InputStream stream;\n\tprivate final byte[] buf = new byte[8192];\n\tprivate int curChar, snumChars;\n \n\tpublic InputReader(InputStream st) {\n\t\tthis.stream = st;\n\t}\n \n\tpublic int read() {\n\t\tif (snumChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= snumChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (snumChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n \n\tpublic int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n \n\tpublic long nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n \n\tpublic int[] nextIntArray(int n) {\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\treturn a;\n\t}\n \n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n \n\tprivate boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n \n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.stream.Collectors;\n\npublic class A {\n\n  static int countColors(List<Integer> colors) {\n    Collections.sort(colors);\n    int k = 0;\n    while (!colors.isEmpty()) {\n      Integer c = colors.get(0);\n      colors.remove(0);\n      k++;\n\n      List<Integer> toRemove = new ArrayList<>();\n      for (int i = 0; i < colors.size(); i++) {\n        if (colors.get(i) % c == 0) toRemove.add(i);\n      }\n\n      Collections.reverse(toRemove);\n      for (Integer integer : toRemove) {\n        colors.remove(integer.intValue());\n      }\n    }\n    return k;\n  }\n\n  public static void main(String[] args) {\n    try (Scanner scanner = new Scanner(System.in)) {\n      int n = scanner.nextInt();\n      scanner.nextLine();\n      List<Integer> integers = Arrays.stream(scanner.nextLine().split(\" \")).map(Integer::parseInt).collect(Collectors.toList());\n      System.out.println(countColors(integers));\n    }\n  }\n}\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] a = new int[n];\n            for (int i = 0; i < n; ++i) a[i] = in.nextInt();\n            boolean[] done = new boolean[n];\n            int res = 0;\n            while (true) {\n                int bi = -1;\n                for (int i = 0; i < n; ++i)\n                    if (!done[i]) {\n                        if (bi < 0 || a[i] < a[bi]) bi = i;\n                    }\n                if (bi < 0) break;\n                ++res;\n                for (int i = 0; i < n; ++i) if (!done[i] && a[i] % a[bi] == 0) done[i] = true;\n            }\n            out.println(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}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.stream.IntStream;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.UncheckedIOException;\nimport java.nio.charset.Charset;\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 mikit\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        LightScanner in = new LightScanner(inputStream);\n        LightWriter out = new LightWriter(outputStream);\n        APaintTheNumbers solver = new APaintTheNumbers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class APaintTheNumbers {\n        public void solve(int testNumber, LightScanner in, LightWriter out) {\n            // out.setBoolLabel(LightWriter.BoolLabel.YES_NO_FIRST_UP);\n            int n = in.ints();\n            int[] a = in.ints(n);\n            IntroSort.sort(a);\n            boolean[] done = new boolean[n];\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                if (done[i]) continue;\n                int d = a[i];\n                ans++;\n                for (int j = 0; j < n; j++) {\n                    if (a[j] % d == 0) {\n                        done[j] = true;\n                    }\n                }\n            }\n            out.ans(ans).ln();\n        }\n\n    }\n\n    static class IntroSort {\n        private static int INSERTIONSORT_THRESHOLD = 16;\n\n        private IntroSort() {\n        }\n\n        static void sort(int[] a, int low, int high, int maxDepth) {\n            while (high - low > INSERTIONSORT_THRESHOLD) {\n                if (maxDepth-- == 0) {\n                    HeapSort.sort(a, low, high);\n                    return;\n                }\n                int cut = QuickSort.step(a, low, high);\n                sort(a, cut, high, maxDepth);\n                high = cut;\n            }\n            InsertionSort.sort(a, low, high);\n        }\n\n        public static void sort(int[] a) {\n            if (a.length <= INSERTIONSORT_THRESHOLD) {\n                InsertionSort.sort(a, 0, a.length);\n            } else {\n                sort(a, 0, a.length, 2 * BitMath.msb(a.length));\n            }\n        }\n\n    }\n\n    static final class ArrayUtil {\n        private ArrayUtil() {\n        }\n\n        public static void swap(int[] a, int x, int y) {\n            int t = a[x];\n            a[x] = a[y];\n            a[y] = t;\n        }\n\n    }\n\n    static class LightScanner {\n        private BufferedReader reader = null;\n        private StringTokenizer tokenizer = null;\n\n        public LightScanner(InputStream in) {\n            reader = new BufferedReader(new InputStreamReader(in));\n        }\n\n        public String string() {\n            if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new UncheckedIOException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int ints() {\n            return Integer.parseInt(string());\n        }\n\n        public int[] ints(int length) {\n            return IntStream.range(0, length).map(x -> ints()).toArray();\n        }\n\n    }\n\n    static final class BitMath {\n        private BitMath() {\n        }\n\n        public static int count(int v) {\n            v = (v & 0x55555555) + ((v >> 1) & 0x55555555);\n            v = (v & 0x33333333) + ((v >> 2) & 0x33333333);\n            v = (v & 0x0f0f0f0f) + ((v >> 4) & 0x0f0f0f0f);\n            v = (v & 0x00ff00ff) + ((v >> 8) & 0x00ff00ff);\n            v = (v & 0x0000ffff) + ((v >> 16) & 0x0000ffff);\n            return v;\n        }\n\n        public static int msb(int v) {\n            if (v == 0) {\n                throw new IllegalArgumentException(\"Bit not found\");\n            }\n            v |= (v >> 1);\n            v |= (v >> 2);\n            v |= (v >> 4);\n            v |= (v >> 8);\n            v |= (v >> 16);\n            return count(v) - 1;\n        }\n\n    }\n\n    static class HeapSort {\n        private HeapSort() {\n        }\n\n        private static void heapfy(int[] a, int low, int high, int i, int val) {\n            int child = 2 * i - low + 1;\n            while (child < high) {\n                if (child + 1 < high && a[child] < a[child + 1]) {\n                    child++;\n                }\n                if (val >= a[child]) {\n                    break;\n                }\n                a[i] = a[child];\n                i = child;\n                child = 2 * i - low + 1;\n            }\n            a[i] = val;\n        }\n\n        static void sort(int[] a, int low, int high) {\n            for (int p = (high + low) / 2 - 1; p >= low; p--) {\n                heapfy(a, low, high, p, a[p]);\n            }\n            while (high > low) {\n                high--;\n                int pval = a[high];\n                a[high] = a[low];\n                heapfy(a, low, high, low, pval);\n            }\n        }\n\n    }\n\n    static class LightWriter implements AutoCloseable {\n        private final Writer out;\n        private boolean autoflush = false;\n        private boolean breaked = true;\n\n        public LightWriter(Writer out) {\n            this.out = out;\n        }\n\n        public LightWriter(OutputStream out) {\n            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));\n        }\n\n        public LightWriter print(char c) {\n            try {\n                out.write(c);\n                breaked = false;\n            } catch (IOException ex) {\n                throw new UncheckedIOException(ex);\n            }\n            return this;\n        }\n\n        public LightWriter print(String s) {\n            try {\n                out.write(s, 0, s.length());\n                breaked = false;\n            } catch (IOException ex) {\n                throw new UncheckedIOException(ex);\n            }\n            return this;\n        }\n\n        public LightWriter ans(String s) {\n            if (!breaked) {\n                print(' ');\n            }\n            return print(s);\n        }\n\n        public LightWriter ans(int i) {\n            return ans(Integer.toString(i));\n        }\n\n        public LightWriter ln() {\n            print(System.lineSeparator());\n            breaked = true;\n            if (autoflush) {\n                try {\n                    out.flush();\n                } catch (IOException ex) {\n                    throw new UncheckedIOException(ex);\n                }\n            }\n            return this;\n        }\n\n        public void close() {\n            try {\n                out.close();\n            } catch (IOException ex) {\n                throw new UncheckedIOException(ex);\n            }\n        }\n\n    }\n\n    static class QuickSort {\n        private QuickSort() {\n        }\n\n        private static void med(int[] a, int low, int x, int y, int z) {\n            if (a[z] < a[x]) {\n                ArrayUtil.swap(a, low, x);\n            } else if (a[y] < a[z]) {\n                ArrayUtil.swap(a, low, y);\n            } else {\n                ArrayUtil.swap(a, low, z);\n            }\n        }\n\n        static int step(int[] a, int low, int high) {\n            int x = low + 1, y = low + (high - low) / 2, z = high - 1;\n            if (a[x] < a[y]) {\n                med(a, low, x, y, z);\n            } else {\n                med(a, low, y, x, z);\n            }\n\n            int lb = low + 1, ub = high;\n            while (true) {\n                while (a[lb] < a[low]) {\n                    lb++;\n                }\n                ub--;\n                while (a[low] < a[ub]) {\n                    ub--;\n                }\n                if (lb >= ub) {\n                    return lb;\n                }\n                ArrayUtil.swap(a, lb, ub);\n                lb++;\n            }\n        }\n\n    }\n\n    static class InsertionSort {\n        private InsertionSort() {\n        }\n\n        static void sort(int[] a, int low, int high) {\n            for (int i = low; i < high; i++) {\n                for (int j = i; j > low && a[j - 1] > a[j]; j--) {\n                    ArrayUtil.swap(a, j - 1, j);\n                }\n            }\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "// Working program using Reader Class \nimport java.io.DataInputStream; \nimport java.io.FileInputStream; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.Scanner; \nimport java.util.StringTokenizer; \n\npublic class Main1 \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[64]; // 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\tpublic static void main(String[] args) throws IOException \n\t{ \n\t\tReader s=new Reader(); \n\t\tint n = s.nextInt(), i, j, ans=0;\n\t\tint[] a = new int[101];\n\t\tfor(i=0;i<n;i++){\n\t\t\ta[s.nextInt()]++;\n\t\t}\n\t\tfor(i=1;i<=100;i++){\n\t\t\tif(a[i]>0){\n\t\t\t\tans++;\n\t\t\t\tfor(j=i;j<=100;j++){\n\t\t\t\t\tif(j%i==0){\n\t\t\t\t\t\ta[j]=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t} \n} \n", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main\n{\n\tPrintWriter out = new PrintWriter(System.out);\n\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    StringTokenizer tok = new StringTokenizer(\"\");\n    String next() throws IOException {\n        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }\n        return tok.nextToken();\n    }\n    int ni() throws IOException { return Integer.parseInt(next()); }\n    long nl() throws IOException { return Long.parseLong(next()); }\n  \n    void solve() throws IOException {\n        int n=ni();\n        int[]A=new int[n];\n        for (int x=0;x<n;x++) A[x]=ni();\n        Arrays.sort(A);\n        ArrayList<Integer>B=new ArrayList();\n        B.add(A[0]);\n        int ans=1;\n        \n        Outer:\n        for (int x=1;x<n;x++) {\n            for (int y=0;y<B.size();y++) {\n                if (A[x]%B.get(y)==0) continue Outer;\n            }\n            ans++;\n            B.add(A[x]);\n        }\n        System.out.println(ans);   \n        \n    }\n    \n    public static void main(String[] args) throws IOException {\n        new Main().solve();\n    }\n}", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "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        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            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            Arrays.sort(a);\n            boolean[] dead = new boolean[n];\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                if (dead[i]) {\n                    continue;\n                }\n                ++ans;\n                for (int j = i; j < n; j++) {\n                    if (a[j] % a[i] == 0) {\n                        dead[j] = true;\n                    }\n                }\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream stream) {\n            in = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String 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", "complexity": "quadratic", "problem": "1209_A. Paint the Numbers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.util.Map.Entry;\n\npublic class Codeforces {\n\n    static int n;\n    static double max;\n    static int[] pre;\n\n    public static void findIntensity(int l){\n        for(int i = 0, j = i + l; j < n + 1; i++, j++){\n            double res = (pre[j] - pre[i]) / (double) l;\n            max = Math.max(max, res);\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        n = Integer.parseInt(st.nextToken());\n        int k = Integer.parseInt(st.nextToken());\n        int[] heat = new int[n];\n        st = new StringTokenizer(br.readLine());\n        for(int i = 0; i < n; i++){\n            heat[i] = Integer.parseInt(st.nextToken());\n        }\n        max = 0;\n        pre = new int[n + 1];\n        pre[0] = 0;\n        for(int i = 0; i < n; i++){\n            pre[i + 1] = pre[i] + heat[i];\n        }\n        for(int i = k; i <= n; i++){\n            findIntensity(i);\n        }\n        System.out.println(max);\n    }\n}", "complexity": "quadratic", "problem": "1003_C. Intense Heat", "from": "CODEFORCES"}
{"src": "//q4\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class q4 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        \n        int query = in.nextInt();\n        \n        while (query -- > 0) {\n            int n = in.nextInt();\n            int k = in.nextInt();\n            \n            char[] arr = new char[n];\n            //slot all n into char array\n            String code = in.next();\n            for (int i = 0; i < n; i++) {\n                arr[i] = code.charAt(i);\n                \n            }\n            \n            //R, G, B cycle\n            int r = 0;\n            int g = 0;\n            int b = 0;\n            \n            for (int i = 0; i < k; i++) {\n                if (i % 3 == 0) {\n                    if (arr[i] == 'R') {g++; b++;}\n                    else if (arr[i] == 'G') {r++; b++;}\n                    else {r++; g++;} //if is 'B'\n                } else if (i % 3 == 1) {\n                    if (arr[i] == 'G') {g++; b++;}\n                    else if (arr[i] == 'B') {r++; b++;}\n                    else {r++; g++;} //if is 'R'\n                } else { //if mod 3 is 2\n                    if (arr[i] == 'B') {g++; b++;}\n                    else if (arr[i] == 'R') {r++; b++;}\n                    else {r++; g++;} //if is 'G'     \n                }\n            }\n            \n            //starting from kth position, if different then add 1, and check (j-k)th position\n            int rMin = r;\n            int gMin = g;\n            int bMin = b;\n            for (int j = k; j < n; j++) {\n                //R cycle\n                if ((j % 3 == 0 && arr[j] != 'R') ||  \n                    (j % 3 == 1 && arr[j] != 'G') ||\n                    (j % 3 == 2 && arr[j] != 'B')) {\n                    r++;\n                }\n                //R cycle \n                if (((j - k) % 3 == 0 && arr[j - k] != 'R') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'G') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'B')) {\n                    r--;\n                }\n                rMin = Math.min(r, rMin);\n                //G cycle\n                if ((j % 3 == 0 && arr[j] != 'G') ||  \n                    (j % 3 == 1 && arr[j] != 'B') ||\n                    (j % 3 == 2 && arr[j] != 'R')) {\n                    g++;\n                } \n                if (((j - k) % 3 == 0 && arr[j - k] != 'G') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'B') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'R')) {\n                    g--;\n                }      \n                gMin = Math.min(gMin, g);\n                //B cycle\n                if ((j % 3 == 0 && arr[j] != 'B') ||  \n                    (j % 3 == 1 && arr[j] != 'R') ||\n                    (j % 3 == 2 && arr[j] != 'G')) {\n                    b++;\n                }       \n                if (((j - k) % 3 == 0 && arr[j - k] != 'B') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'R') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'G')) {\n                    b--;\n                } \n                bMin = Math.min(bMin, b);\n                \n            }\n            \n            System.out.println(Math.min(Math.min(rMin, gMin), bMin));\n            \n        }\n        \n    } \n    \n}", "complexity": "quadratic", "problem": "1196_D2. RGB Substring (hard version)", "from": "CODEFORCES"}
{"src": "//q4\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class q4 {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));\n        \n        int query = in.nextInt();\n        \n        while (query -- > 0) {\n            int n = in.nextInt();\n            int k = in.nextInt();\n            \n            char[] arr = new char[n];\n            //slot all n into char array\n            String code = in.next();\n            for (int i = 0; i < n; i++) {\n                arr[i] = code.charAt(i);\n                \n            }\n            \n            //R, G, B cycle\n            int r = 0;\n            int g = 0;\n            int b = 0;\n            \n            for (int i = 0; i < k; i++) {\n                if (i % 3 == 0) {\n                    if (arr[i] == 'R') {g++; b++;}\n                    else if (arr[i] == 'G') {r++; b++;}\n                    else {r++; g++;} //if is 'B'\n                } else if (i % 3 == 1) {\n                    if (arr[i] == 'G') {g++; b++;}\n                    else if (arr[i] == 'B') {r++; b++;}\n                    else {r++; g++;} //if is 'R'\n                } else { //if mod 3 is 2\n                    if (arr[i] == 'B') {g++; b++;}\n                    else if (arr[i] == 'R') {r++; b++;}\n                    else {r++; g++;} //if is 'G'     \n                }\n            }\n            \n            //starting from kth position, if different then add 1, and check (j-k)th position\n            int rMin = r;\n            int gMin = g;\n            int bMin = b;\n            for (int j = k; j < n; j++) {\n                //R cycle\n                if ((j % 3 == 0 && arr[j] != 'R') ||  \n                    (j % 3 == 1 && arr[j] != 'G') ||\n                    (j % 3 == 2 && arr[j] != 'B')) {\n                    r++;\n                }\n                //R cycle \n                if (((j - k) % 3 == 0 && arr[j - k] != 'R') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'G') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'B')) {\n                    r--;\n                }\n                rMin = Math.min(r, rMin);\n                //G cycle\n                if ((j % 3 == 0 && arr[j] != 'G') ||  \n                    (j % 3 == 1 && arr[j] != 'B') ||\n                    (j % 3 == 2 && arr[j] != 'R')) {\n                    g++;\n                } \n                if (((j - k) % 3 == 0 && arr[j - k] != 'G') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'B') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'R')) {\n                    g--;\n                }      \n                gMin = Math.min(gMin, g);\n                //B cycle\n                if ((j % 3 == 0 && arr[j] != 'B') ||  \n                    (j % 3 == 1 && arr[j] != 'R') ||\n                    (j % 3 == 2 && arr[j] != 'G')) {\n                    b++;\n                }       \n                if (((j - k) % 3 == 0 && arr[j - k] != 'B') ||  \n                    ((j - k) % 3 == 1 && arr[j - k] != 'R') ||\n                    ((j - k) % 3 == 2 && arr[j - k] != 'G')) {\n                    b--;\n                } \n                bMin = Math.min(bMin, b);\n                \n            }\n            \n            out.println(Math.min(Math.min(rMin, gMin), bMin));\n            \n        }\n        out.flush();\n        \n    } \n    \n}", "complexity": "quadratic", "problem": "1196_D2. RGB Substring (hard version)", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class P1196D2 {\n\n    static boolean multipleIndependent = true;\n\n    void run() {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        char[] s = in.next().toCharArray();\n        int[] dp = new int[3];\n        char[] c = {'R', 'G', 'B'};\n        int min = Integer.MAX_VALUE;\n        for (int i = 0; i < k; i++) {\n            dp[0] += s[i] == c[(i + 0) % 3] ? 0 : 1;\n            dp[1] += s[i] == c[(i + 1) % 3] ? 0 : 1;\n            dp[2] += s[i] == c[(i + 2) % 3] ? 0 : 1;\n        }\n        min = Math.min(Math.min(Math.min(dp[0], dp[1]), dp[2]), min);\n//        System.out.println(Arrays.toString(dp));\n        for (int i = k; i < n; i++) {\n            dp[0] += (s[i] == c[(i + 0) % 3] ? 0 : 1) - (s[i - k] == c[(i - k + 0) % 3] ? 0 : 1);\n            dp[1] += (s[i] == c[(i + 1) % 3] ? 0 : 1) - (s[i - k] == c[(i - k + 1) % 3] ? 0 : 1);\n            dp[2] += (s[i] == c[(i + 2) % 3] ? 0 : 1) - (s[i - k] == c[(i - k + 2) % 3] ? 0 : 1);\n            min = Math.min(Math.min(Math.min(dp[0], dp[1]), dp[2]), min);\n//            System.out.println(Arrays.toString(dp));\n        }\n        System.out.println(min);\n    }\n\n\n    /* -----: Template :----- */\n    static InputReader in = new InputReader(System.in);\n\n    public static void main(String[] args) {\n        P1196D2 p = new P1196D2();\n        int q = multipleIndependent ? in.nextInt() : 1;\n        while (q-- > 0) {\n            p.run();\n        }\n    }\n\n    int numLength(long n) {\n        int l = 0;\n        while (n > 0) {\n            n /= 10;\n            l++;\n        }\n        return l;\n    }\n\n    <R> long binarySearch(long lowerBound, long upperBound,\n            R value, Function<Long, R> generatorFunction, Comparator<R> comparator) {\n        if (lowerBound <= upperBound) {\n            long mid = (lowerBound + upperBound) / 2;\n            int compare = comparator.compare(generatorFunction.apply(mid), value);\n            if (compare == 0) {\n                return mid;\n            } else if (compare < 0) {\n                return binarySearch(mid + 1, upperBound, value, generatorFunction, comparator);\n            } else {\n                return binarySearch(lowerBound, mid - 1, value, generatorFunction, comparator);\n            }\n        } else {\n            return -1;\n        }\n    }\n\n    <T> Integer[] sortSimultaneously(T[] key, Comparator<T> comparator,\n            Object[]... moreArrays) {\n        int n = key.length;\n        for (Object[] array : moreArrays) {\n            if (array.length != n) {\n                throw new RuntimeException(\"Arrays must have equals lengths\");\n            }\n        }\n        Integer[] indices = new Integer[n];\n        for (int i = 0; i < n; i++) {\n            indices[i] = i;\n        }\n        Comparator<Integer> delegatingComparator = (a, b) -> {\n            return comparator.compare(key[a], key[b]);\n        };\n        Arrays.sort(indices, delegatingComparator);\n        reorder(indices, key);\n        for (Object[] array : moreArrays) {\n            reorder(indices, array);\n        }\n        return indices;\n    }\n\n    void reorder(Integer[] indices, Object[] arr) {\n        if (indices.length != arr.length) {\n            throw new RuntimeException(\"Arrays must have equals lengths\");\n        }\n        int n = arr.length;\n        Object[] copy = new Object[n];\n        for (int i = 0; i < n; i++) {\n            copy[i] = arr[indices[i]];\n        }\n        System.arraycopy(copy, 0, arr, 0, n);\n    }\n\n    int prodMod(int a, int b, int mod) {\n        return (int) (((long) a) * b % mod);\n    }\n\n    long prodMod(long a, long b, long mod) {\n        long res = 0;\n        a %= mod;\n        b %= mod;\n        while (b > 0) {\n            if ((b & 1) > 0) {\n                res = (res + a) % mod;\n            }\n            a = (a << 1) % mod;\n            b >>= 1;\n        }\n        return res;\n    }\n\n    long sumMod(int[] b, long mod) {\n        long res = 0;\n        for (int i = 0; i < b.length; i++) {\n            res = (res + b[i] % mod) % mod;\n        }\n        return res;\n    }\n\n    long sumMod(long[] a, long mod) {\n        long res = 0;\n        for (int i = 0; i < a.length; i++) {\n            res = (res + a[i] % mod) % mod;\n        }\n        return res;\n    }\n\n    long sumProdMod(int[] a, long b, long mod) {\n        long res = sumMod(a, mod);\n        return prodMod(res, b, mod);\n    }\n\n    long sumProdMod(long[] a, long b, long mod) {\n        long res = sumMod(a, mod);\n        return prodMod(res, b, mod);\n    }\n\n    long sumProdMod(int[] a, int[] b, long mod) {\n        if (a.length != b.length) {\n            throw new RuntimeException(\"Arrays must have equals lengths\");\n        }\n        long res = 0;\n        for (int i = 0; i < a.length; i++) {\n            res = (res + prodMod(a[i], b[i], mod)) % mod;\n        }\n        return res;\n    }\n\n    long sumProdMod(long[] a, long[] b, long mod) {\n        if (a.length != b.length) {\n            throw new RuntimeException(\"Arrays must have equals lengths\");\n        }\n        long res = 0;\n        for (int i = 0; i < a.length; i++) {\n            res = (res + prodMod(a[i], b[i], mod)) % mod;\n        }\n        return res;\n    }\n\n    int[] toPrimitive(Integer[] arr) {\n        int[] res = new int[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    int[][] toPrimitive(Integer[][] arr) {\n        int[][] res = new int[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toPrimitive(arr[i]);\n        }\n        return res;\n    }\n\n    long[] toPrimitive(Long[] arr) {\n        long[] res = new long[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    long[][] toPrimitive(Long[][] arr) {\n        long[][] res = new long[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toPrimitive(arr[i]);\n        }\n        return res;\n    }\n\n    Integer[] toWrapper(int[] arr) {\n        Integer[] res = new Integer[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    Integer[][] toWrapper(int[][] arr) {\n        Integer[][] res = new Integer[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toWrapper(arr[i]);\n        }\n        return res;\n    }\n\n    Long[] toWrapper(long[] arr) {\n        Long[] res = new Long[arr.length];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = arr[i];\n        }\n        return res;\n    }\n\n    Long[][] toWrapper(long[][] arr) {\n        Long[][] res = new Long[arr.length][];\n        for (int i = 0; i < arr.length; i++) {\n            res[i] = toWrapper(arr[i]);\n        }\n        return res;\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        public int[] nextIntArray(int n) {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n            return arr;\n        }\n\n        public <T> T[] nextIntArray(int n, Function<Integer, T> function, Class<T> c) {\n            T[] arr = (T[]) Array.newInstance(c, n);\n            for (int i = 0; i < n; i++) {\n                arr[i] = function.apply(nextInt());\n            }\n            return arr;\n        }\n\n        public long[] nextLongArray(int n) {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n            return arr;\n        }\n\n        public <T> T[] nextLongArray(int n, Function<Long, T> function, Class<T> c) {\n            T[] arr = (T[]) Array.newInstance(c, n);\n            for (int i = 0; i < n; i++) {\n                arr[i] = function.apply(nextLong());\n            }\n            return arr;\n        }\n\n        public int[][] nextIntMap(int n, int m) {\n            int[][] map = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                map[i] = nextIntArray(m);\n            }\n            return map;\n        }\n\n        public long[][] nextLongMap(int n, int m) {\n            long[][] map = new long[n][m];\n            for (int i = 0; i < n; i++) {\n                map[i] = nextLongArray(m);\n            }\n            return map;\n        }\n\n        public char[][] nextCharMap(int n) {\n            char[][] map = new char[n][];\n            for (int i = 0; i < n; i++) {\n                map[i] = next().toCharArray();\n            }\n            return map;\n        }\n\n        public void readColumns(Object[]... columns) {\n            int n = columns[0].length;\n            for (Object[] column : columns) {\n                if (column.length != n) {\n                    throw new RuntimeException(\"Arrays must have equals lengths\");\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                for (Object[] column : columns) {\n                    column[i] = read(column[i].getClass());\n                }\n            }\n        }\n\n        public <T> T read(Class<T> c) {\n            throw new UnsupportedOperationException(\"To be implemented\");\n        }\n\n    }\n\n}\n", "complexity": "quadratic", "problem": "1196_D2. RGB Substring (hard version)", "from": "CODEFORCES"}
{"src": "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 pandusonu\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            // out.print(\"Case #\" + testNumber + \": \");\n            int n = in.readInt();\n            int[] a = in.readIntArray(n);\n            int[][] sol = new int[n][n];\n            for (int i = 0; i < n; i++) {\n                sol[0][i] = a[i];\n            }\n            for (int i = 1; i < n; i++) {\n                for (int j = 0; j < n - i; j++) {\n                    sol[i][j] = sol[i - 1][j] ^ sol[i - 1][j + 1];\n                }\n            }\n            for (int i = 1; i < n; i++) {\n                for (int j = 0; j < n - i; j++) {\n                    sol[i][j] = Math.max(sol[i][j], Math.max(sol[i - 1][j], sol[i - 1][j + 1]));\n                }\n            }\n            int q = in.readInt();\n            for (int i = 0; i < q; i++) {\n                int l = in.readInt() - 1;\n                int r = in.readInt() - 1;\n                out.println(sol[r - l][l]);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private final InputStream stream;\n        private final 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 read() {\n            try {\n                if (curChar >= numChars) {\n                    curChar = 0;\n                    numChars = stream.read(buf);\n                    if (numChars <= 0)\n                        return -1;\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n            return buf[curChar++];\n        }\n\n        public int readInt() {\n            return (int) readLong();\n        }\n\n        public long readLong() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n                if (c == -1) throw new RuntimeException();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? (-res) : (res);\n        }\n\n        public int[] readIntArray(int size) {\n            int[] arr = new int[size];\n            for (int i = 0; i < size; i++) arr[i] = readInt();\n            return arr;\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", "complexity": "quadratic", "problem": "983_B. XOR-pyramid", "from": "CODEFORCES"}
{"src": "import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;\nimport jdk.management.cmm.SystemResourcePressureMXBean;\n\nimport java.awt.*;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.util.List;\nimport java.math.*;\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) {\n        solver s = new solver();\n        int t = 1;\n        while (t > 0) {\n            s.solve();\n            t--;\n        }\n        out.close();\n    }\n\n   /* static class descend implements Comparator<pair1> {\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 next() {\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 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 class card {\n        long a;\n        int cnt;\n        int i;\n\n        public card(long a, int cnt, int i) {\n            this.a = a;\n            this.cnt = cnt;\n            this.i = i;\n        }\n    }\n\n    static class ascend implements Comparator<pair> {\n        public int compare(pair o1, pair o2) {\n            return o1.a - o2.a;\n        }\n    }\n\n    static class extra {\n\n        static boolean v[] = new boolean[100001];\n        static List<Integer> l = new ArrayList<>();\n        static int t;\n\n        static void shuffle(long a[]) {\n            List<Long> l = new ArrayList<>();\n            for (int i = 0; i < a.length; i++)\n                l.add(a[i]);\n            Collections.shuffle(l);\n            for (int i = 0; i < a.length; i++)\n                a[i] = l.get(i);\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                return true;\n            else\n                return false;\n        }\n\n        static void seive() {\n            for (int i = 2; i < 100001; i++) {\n                if (!v[i]) {\n                    t++;\n                    l.add(i);\n                    for (int j = 2 * i; j < 100001; j += i)\n                        v[j] = true;\n                }\n            }\n        }\n\n        static int binary(long 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[mid] == val) {\n                    r = mid - 1;\n                    ans = mid;\n                } else if (a[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(int x, int 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(int x, int y, int 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\n    static class pair {\n        int a;\n        int b;\n\n        public pair(int a, int i) {\n            this.a = a;\n            this.b = i;\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 long m = (long) 1e9 + 7;\n\n    static class solver {\n        void solve() {\n            int n = sc.nextInt();\n            int ans=0;\n            int a[]=new int[2*n];\n            for (int i = 0; i < 2 * n; i++) {\n               a[i]=sc.nextInt();\n            }\n            for(int i=0;i<2*n;i++)\n            {\n                if(a[i]>0)\n                {\n                    int j=0;\n                    for(j=i+1;a[i]!=a[j];j++)\n                    {\n                        if(a[j]>0)\n                            ans++;\n                    }\n                    a[j]=0;\n                }\n            }\n            System.out.println(ans);\n        }\n    }\n}", "complexity": "quadratic", "problem": "995_B. Suit and Tie", "from": "CODEFORCES"}
{"src": "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 LogicalExpression {\n    \n    int N = 256;\n    \n    void solve() {\n        Expression[] E = new Expression[N];\n        for (int i = 0; i < N; i++) E[i] = new Expression();\n        \n        E[Integer.parseInt(\"00001111\", 2)].update_f(\"x\");\n        E[Integer.parseInt(\"00110011\", 2)].update_f(\"y\");\n        E[Integer.parseInt(\"01010101\", 2)].update_f(\"z\");\n        \n        for (int l = 2; l < 40; l++) {\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < N; j++) {\n                    if (E[i].e != null && E[j].t != null && E[i].e.length() + E[j].t.length() + 1 == l) {\n                        E[i | j].update_e(E[i].e + '|' + E[j].t);\n                    }\n                    if (E[i].t != null && E[j].f != null && E[i].t.length() + E[j].f.length() + 1 == l) {\n                        E[i & j].update_t(E[i].t + '&' + E[j].f);\n                    }\n                }\n                if (E[i].f != null) E[i ^ (N - 1)].update_f('!' + E[i].f);\n            }\n        }\n        \n        String[] res = new String[N];\n        for (int i = 0; i < N; i++) res[i] = E[i].calc_best();\n        \n        int n = in.nextInt();\n        for (int i = 0; i < n; i++) {\n            int x = Integer.parseInt(in.nextToken(), 2);\n            out.println(res[x]);\n        }\n    }\n    \n    static class Expression {\n        String e, t, f;\n        \n        Expression() {\n        }\n        \n        public Expression(String e, String t, String f) {\n            this.e = e;\n            this.t = t;\n            this.f = f;\n        }\n        \n        String calc_best() {\n            String best = e;\n            if (compare(best, t) > 0) best = t;\n            if (compare(best, f) > 0) best = f;\n            return best;\n        }\n        \n        void update_e(String ne) {\n            if (e == null || compare(e, ne) > 0) {\n                e = ne;\n                update_f('(' + e + ')');\n            }\n        }\n        \n        void update_t(String nt) {\n            if (t == null || compare(t, nt) > 0) {\n                t = nt;\n                update_e(t);\n            }\n        }\n        \n        void update_f(String nf) {\n            if (f == null || compare(f, nf) > 0) {\n                f = nf;\n                update_t(f);\n            }\n        }\n        \n        int compare(String a, String b) {\n            if (a.length() != b.length()) return Integer.compare(a.length(), b.length());\n            return a.compareTo(b);\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 LogicalExpression().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", "complexity": "quadratic", "problem": "913_E. Logical Expression", "from": "CODEFORCES"}
{"src": "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 gaidash\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            final int SIZE = 256;\n            final int UNDEF = -1;\n\n            int nPixels = in.nextInt();\n            int groupSize = in.nextInt();\n            int[] a = in.nextIntArray(nPixels);\n            boolean[] exists = new boolean[SIZE];\n            int[] left = new int[SIZE];\n            int[] right = new int[SIZE];\n            int[] ret = new int[nPixels];\n            Arrays.fill(ret, UNDEF);\n\n            for (int i = 0; i < nPixels; i++) {\n                for (int p = 0; p < SIZE; p++) {\n                    if (exists[p] && left[p] <= a[i] && a[i] <= right[p]) {\n                        ret[i] = left[p];\n                        left[a[i]] = left[p];\n                        right[a[i]] = right[p];\n                        break;\n                    }\n                }\n                if (ret[i] == UNDEF) {\n                    int l = Math.max(a[i] - groupSize + 1, 0);\n                    int r = l + groupSize - 1;\n                    for (int p = a[i] - 1; p >= 0; p--) {\n                        if (exists[p]) {\n                            if (p >= l) {\n                                int d = p - l;\n                                l = p + 1;\n                                r += d + 1;\n                            }\n                            if (right[p] >= l) {\n                                right[p] = l - 1;\n                            }\n                        }\n                    }\n                    for (int p = a[i] + 1; p < SIZE; p++) {\n                        if (exists[p] && left[p] <= r) {\n                            r = left[p] - 1;\n                        }\n                    }\n                    left[a[i]] = l;\n                    right[a[i]] = r;\n                    ret[i] = l;\n                }\n                exists[a[i]] = true;\n            }\n//        for (int p : a) {\n//            System.out.println(\"Segment for pixel \" + p + \" = \" + \"(\" + left[p] + \" , \" + right[p] + \")\");\n//        }\n\n            out.print(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 print(int[] array) {\n            for (int i = 0; i < array.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(array[i]);\n            }\n        }\n\n        public void 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 int[] nextIntArray(int n) {\n            int[] array = new int[n];\n            for (int i = 0; i < n; ++i) array[i] = nextInt();\n            return array;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "quadratic", "problem": "980_C. Posterized", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces913F {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tinput.close();\n\t\tfinal int mod = 998244353;\n\t\t\n\t\tint frac = multiply(a, inverse(b, mod), mod);\n\t\tint reverse = (mod+1-frac)%mod;\n\t\t\n\t\tint[] fracpower = new int[n+1];\n\t\tint[] reversepower = new int[n+1];\n\t\tfracpower[0] = 1;\n\t\treversepower[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfracpower[i] = multiply(fracpower[i-1], frac, mod);\n\t\t\treversepower[i] = multiply(reversepower[i-1], reverse, mod);\n\t\t}\n\t\t\n\t\tint[][] dp1 = new int[n+1][n+1];\n\t\tdp1[2][1] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tif (j == 1) {\n\t\t\t\t\tdp1[i][j] = fracpower[i-1];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);\n\t\t\t\t}\n\t\t\t\tif (j == i-1) {\n\t\t\t\t\tdp1[i][j] += reversepower[i-1];\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp2 = new int[n+1][n+1];\n\t\tdp2[1][1] = 1;\n\t\tdp2[2][1] = 1;\n\t\tdp2[2][2] = 0;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tdp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);\n\t\t\t\tval += dp2[i][j];\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tdp2[i][i] = (mod+1-val)%mod;\n\t\t}\n\t\t\n\t\t/*for (int i = 2; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tSystem.out.print(dp2[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}*/\n\t\t\n\t\tint[] EV = new int[n+1];\n\t\tEV[1] = 0;\n\t\tEV[2] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tint r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];\n\t\t\t\tr %= mod;\n\t\t\t\tval += multiply(dp2[i][j], r, mod);\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tval += multiply((i*(i-1))/2, dp2[i][i], mod);\n\t\t\tval %= mod;\n\t\t\t\n\t\t\tint s = (mod+1-dp2[i][i])%mod;\n\t\t\tEV[i] = multiply(val, inverse(s, mod), mod);\n\t\t}\n\t\t\n\t\tSystem.out.println(EV[n]);\n\t}\n\t\n\tpublic static int multiply(int a, int b, int mod) {\n\t\tlong x = (long)a*(long)b;\n\t\treturn (int) (x%mod);\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}", "complexity": "quadratic", "problem": "913_F. Strongly Connected Tournament", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class java2 {\n    public static void main(String[] args) {\n        Scanner r = new Scanner(System.in);\n        int n=r.nextInt();\n        int []l=new int[1005];\n        int []ri=new int[1005];\n        int []candy=new int[1005];\n        for(int i=1;i<=n;++i)\n        {\n            l[i]=r.nextInt();\n        }\n        for(int i=1;i<=n;++i)\n        {\n            ri[i]=r.nextInt();\n        }\n        for(int i=1;i<=n;++i)\n        {\n            if(l[i]>i-1||ri[i]>n-i)\n            {\n                System.out.println(\"NO\");\n                System.exit(0);\n            }\n            candy[i]=n-l[i]-ri[i];\n        }\n        for(int i=1;i<=n;++i)\n        {\n            int left=0,right=0;\n            for(int j=1;j<=i-1;++j)\n            {\n                if(candy[j]>candy[i])\n                {\n                    ++left;\n                }\n            }\n            for(int j=i+1;j<=n;++j)\n            {\n                if(candy[j]>candy[i])\n                {\n                    ++right;\n                }\n            }\n            if(left!=l[i]||right!=ri[i])\n            {\n                System.out.println(\"NO\");\n                System.exit(0);\n            }\n        }\n        System.out.println(\"YES\");\n        for(int i=1;i<=n;++i)\n        {\n            System.out.print(candy[i]+\" \");\n        }\n    }\n}\n", "complexity": "quadratic", "problem": "1054_C. Candies Distribution", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\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    public static void main(String args[] ) {\n        \n        FastReader sc = new FastReader();\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int[] arr = new int[105];\n        \n        for(int i=0;i<m;i++){\n            int a = sc.nextInt();\n            arr[a]++;\n        }\n        \n        for(int i=1;i<=1000;i++){\n            int sum=0;\n            \n            for(int a:arr){\n                if(a!=0){\n                    sum+=(a/i);\n                }\n            }\n            \n            \n            if(sum<n){\n                System.out.println(i-1);\n                return;\n            }\n            \n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\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    public static void main(String args[] ) {\n        \n        FastReader sc = new FastReader();\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int[] arr = new int[105];\n        \n        for(int i=0;i<m;i++){\n            int a = sc.nextInt();\n            arr[a]++;\n        }\n        \n        for(int i=1;i<=1000;i++){\n            int sum=0;\n            \n            for(int a:arr){\n                if(a!=0){\n                    sum+=(a/i);\n                }\n            }\n            \n            \n            if(sum<n){\n                System.out.println(i-1);\n                return;\n            }\n            \n        }\n    }\n\n}\n", "complexity": "quadratic", "problem": "1011_B. Planning The Expedition", "from": "CODEFORCES"}
{"src": "//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&d4==2||d3==1&d4==1&d5==2||d5==1&d4==1&d3==2)\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(d3<d5&d3<d4) {\n\t\t\t    if(d3==1||d3==2||d3==0) System.out.println(1);\n\t\t        else                 System.out.println(2);\n\t\t\t    }\n\t\t\telse if (d5<d4&d5<d3){\n\t\t\t\t if(d5==1||d5==2||d5==0) System.out.println(1);\n\t\t\t\t\telse                 System.out.println(2);\n\t\t\t}\n\t\t\telse if(d4<d5&d4<d3) {\n\t\t\t\tif(d4==1||d4==2||d4==0) System.out.println(1);\n\t\t\t\telse                 System.out.println(2);\n\t\t\t}\n\t\t\telse if(d3==2&d5==2||d4==2&d5==2||d3==2&d4==2||d3==1&d5==1||d4==1&d5==1||d3==2&d4==1)\n\t\t\t\tSystem.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t\t\n\t\t\t\n\t\t\n\t\t \n\t\t    \n\t\t    \n\t}\n\t\n\tif(m==2||s==2||p==2) {\n\t\t\n\t\t\n\t\t\n\t\tchar c1 = S[0].charAt(1);\n\t\tchar c2 = S[1].charAt(1);\n\t\tchar c3 = S[2].charAt(1);\n\t\t\n\t\t\n\t\tif(c1==c2) {\n\t\t\tif(n1==n2) System.out.println(1);\n\t\t\telse if(d3==1||d3==2) System.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t}\n\t\tif(c1==c3) {\n\t\t\tif(n1==n3) System.out.println(1);\n\t\t\telse if(d4==1||d4==2) System.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t}\n\t\tif(c2==c3) {\n\t\t\tif(n2==n3) System.out.println(1);\n\t\t\telse if(d5==1||d5==2) System.out.println(1);\n\t\t\telse System.out.println(2);\n\t\t}\n\t}\n\t\n\tif(m==1&s==1&p==1) System.out.println(2);\n\t\t\n\t\n\t\n}\n}\n", "complexity": "constant", "problem": "1191_B. Tokitsukaze and Mahjong", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.PrintWriter;\n\nimport java.util.*;\nimport java.util.Arrays ; \nimport java .lang.String.* ;\nimport java .lang.StringBuilder ;\n\n\npublic class Test{\n    static int pos = 0 ; \n    static int  arr[] ; \n  static LinkedList l1 = new  LinkedList() ; \nstatic void find(int p ,char[]x,int put[],String s){\n    int c= 0 ; \n    for (int i = 0; i < s.length(); i++) {\n        if(x[p]==s.charAt(i)){\n        c++ ; }\n    }\n    put[p] = c ;  \n}\nstatic int mode(int m ,int[]x ){\n    int temp = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return m-temp ; \n             \n        }\n    }\n     return m-temp ; \n}\nstatic int mode2(int m ,int[]x ){\n    int temp = 0 ; \n    \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return x[i] ; \n             \n        }\n    }\n     return 0 ; \n}\nstatic int find(int x[],int temp){\n    int j = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]==temp) return j+1 ; \n        j++ ; \n    }\n    return -1 ; \n}\nstatic String ch(long[]x,long b){\n    for (int i = 0; i < x.length; i++) {\n        if(x[i]==b)return \"YES\" ;\n    }\n    return \"NO\" ; \n}\n\n    public static void main(String[] args)  {\n\n        Scanner in = new Scanner(System.in) ;\n        PrintWriter pw = new PrintWriter(System.out);   \n     int k=in.nextInt(), n=in.nextInt(), s=in.nextInt(), p=in.nextInt() ;\n     int paper =n/s; \n     if(n%s!=0) paper++ ; \n     paper*=k ; \n     int fin = paper/p ; \n     if(paper%p!=0) fin++ ; \n        System.out.println( fin );\n       \n       \n }               \n}\n\n", "complexity": "constant", "problem": "965_A. Paper Airplanes", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class loser\n{\n    static class InputReader {\n        public BufferedReader br;\n        public StringTokenizer token;\n        public InputReader(InputStream stream)\n        {\n            br=new BufferedReader(new InputStreamReader(stream),32768);\n            token=null;\n        }\n\n        public String next()\n        {\n            while(token==null || !token.hasMoreTokens())\n            {\n                try\n                {\n                    token=new StringTokenizer(br.readLine());\n                }\n                catch(IOException e)\n                {\n                    throw new RuntimeException(e);\n                }\n            }\n            return token.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    static class card{\n        long a;\n        int i;\n        public card(long a,int i)\n        {\n            this.a=a;\n            this.i=i;\n        }\n    }\n    static class sort implements Comparator<pair>\n    {\n        public int compare(pair o1,pair o2)\n        {\n            if(o1.a!=o2.a)\n                return (int)(o1.a-o2.a);\n            else\n                return (int)(o1.b-o2.b);\n        }\n    }\n    static void shuffle(long a[])\n    {\n        List<Long> l=new ArrayList<>();\n        for(int i=0;i<a.length;i++)\n            l.add(a[i]);\n        Collections.shuffle(l);\n        for(int i=0;i<a.length;i++)\n            a[i]=l.get(i);\n    }\n\n    /*static long gcd(long a,long b)\n    {\n    if(b==0)\n    return a;\n    else\n    return gcd(b,a%b);\n    }*/\n    /*static boolean valid(int i,int j)\n    {\n    if(i<4 && i>=0 && j<4 && j>=0)\n    return true;\n    else\n    return false;\n    }*/\n    static class pair{\n        int a,b;\n        public pair(int a,int b)\n        {\n            this.a=a;\n            this.b=b;\n        }\n    }\n    public  static void main(String[] args) \n    {\n        InputReader sc=new InputReader(System.in);\n        int k=sc.nextInt();\n        int n=sc.nextInt();\n        int s=sc.nextInt();\n        int p=sc.nextInt();\n        long d=(long)Math.ceil((double)n/s);\n        if(d==0)\n        d=1;\n        d=k*d;\n        long ans=(long)Math.ceil((double)d/p);\n        System.out.println(ans);\n    }\n}", "complexity": "constant", "problem": "965_A. Paper Airplanes", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Lcm\n{\npublic static void main(String args[])throws Exception\n{\nBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\nPrintWriter pw=new PrintWriter(System.out);\nlong n=Long.parseLong(br.readLine());\nif(n<=2)\npw.println(n);\nelse\n{\n\n if(n%6==0)\n{\n pw.println(((n-1)*(n-2)*(n-3)));\n}\n else if(n%2==0)\n{\n  pw.println((n*(n-1)*(n-3)));\n}\nelse\n{\n  pw.println((n*(n-1)*(n-2)));\n}\n}\npw.flush();\n}\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "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;\n\npublic class Task235A {\n\n\tpublic static void main(String... args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tSolution.main(System.in, System.out);\n\t}\n\n\tstatic class Scanner {\n\n\t\tprivate final BufferedReader br;\n\t\tprivate String[] cache;\n\t\tprivate int cacheIndex;\n\n\t\tScanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t\tcache = new String[0];\n\t\t\tcacheIndex = 0;\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn Integer.parseInt(cache[cacheIndex++]);\n\t\t}\n\n\t\tlong nextLong() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn Long.parseLong(cache[cacheIndex++]);\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn cache[cacheIndex++];\n\t\t}\n\n\t\tvoid close() throws IOException {\n\t\t\tbr.close();\n\t\t}\n\n\t}\n\n\tstatic class Solution {\n\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 sc = new Scanner(is);\n\n\t\t\tlong n = sc.nextInt();\n\n\t\t\tif (n < 3) {\n\t\t\t\tpw.println(n);\n\t\t\t} else {\n\t\t\t\tif (n % 2 != 0) {\n\t\t\t\t\tpw.println(n * (n - 1) * (n - 2));\n\t\t\t\t} else {\n\t\t\t\t\tif (n % 3 != 0) {\n\t\t\t\t\t\tpw.println(n * (n - 1) * (n - 3));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlong cand1 = n * (n - 1) * (n - 2) / 2;\n\t\t\t\t\t\tlong cand2 = (n - 1) * (n - 2) * (n - 3);\n\t\t\t\t\t\tpw.println(Math.max(cand1, cand2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpw.flush();\n\t\t\tsc.close();\n\t\t}\n\t}\n\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n    public static long gcd(long a, long b)\n    {\n        return b==0? a:gcd(b, a%b);\n    }\n    public static long lcm(long a, long b, long c)\n    {\n        long d=a/gcd(a, b)*b;\n        return c/gcd(c, d)*d;\n    }\n    public static long max(long a, long b)\n    {\n        return a>b? a:b;\n    }\n    public static void main(String[] args)\n    {\n        InputReader in = new InputReader();\n        PrintWriter out = new PrintWriter(System.out);\n        long n=in.nextLong();\n        if(n<=2)\n            out.println(n);\n        else\n            out.println(max(lcm(n, n-1, n-2), max(lcm(n, n-1, n-3), lcm(n-1, n-2, n-3))));\n        out.close();\n    }\n}\n\nclass InputReader\n{\n    BufferedReader buf;\n    StringTokenizer tok;\n    InputReader()\n    {\n        buf = new BufferedReader(new InputStreamReader(System.in));\n    }\n    boolean hasNext()\n    {\n        while(tok == null || !tok.hasMoreElements()) \n        {\n            try\n            {\n                tok = new StringTokenizer(buf.readLine());\n            } \n            catch(Exception e) \n            {\n                return false;\n            }\n        }\n        return true;\n    }\n    String next()\n    {\n        if(hasNext()) \n            return tok.nextToken();\n        return null;\n    }\n    int nextInt()\n    {\n        return Integer.parseInt(next());\n    }\n    long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n    double nextDouble()\n    {\n        return Double.parseDouble(next());\n    }\n    BigInteger nextBigInteger()\n    {\n        return new BigInteger(next());\n    }\n    BigDecimal nextBigDecimal()\n    {\n        return new BigDecimal(next());\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\n/*Author LAVLESH*/\npublic class solution\n{  \n\tstatic long gcd(long a,long b){\n\t\tif(b==0) return a;\n\t\telse \n\t\t\treturn gcd(b,a%b);\n\t\t\n\t}\n\tpublic static void main(String[]args){\n\t\tScanner in=new Scanner(System.in);\n\t\tlong n=in.nextLong();\n\t\tlong m1=0,m2=0;\n\t\tif(n<3)m1=n;\n\t\telse {\n\t\t\tif((n&1)==1){\n\t\t\t\tlong lcm=n*(n-1)/gcd(n,n-1);\n\t\t\t\tm1=lcm*(n-2)/gcd(lcm,n-2);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlong lcm=(n-1)*(n-2)/gcd(n-1,n-2);\n\t\t\t\tm1=lcm*(n-3)/gcd(lcm,n-3);\n\t\t\t\t\n\t\t\t\t lcm=n*(n-1)/gcd(n,n-1);\n\t\t\t\tm2=lcm*(n-3)/gcd(lcm,n-3);\n\t\t\t\tm1 = Math.max(m1,m2);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(m1);\n\t\t\n}}\n\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n    public static long GCF(long a, long b) {\n        if(b == 0) return a;\n        else return GCF(b, a%b);\n    }\n    \n    public static long LCM(long a, long b){\n        return a*b / GCF(a, b);\n    }\n    \n    \n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        int n = scan.nextInt();\n        if(n < 3) System.out.println(n);\n        else{\n            long t1 = LCM(n, n-1);\n            long t2 = LCM(n-2, n-3);\n        \n            long l1 = LCM(t1, n-2);\n            long l2 = LCM(t1, n-3);\n            long l3 = LCM(n, t2);\n            long l4 = LCM(n-1, t2);\n        \n        System.out.println(Math.max(l1, Math.max(l2, Math.max(l3, l4))));\n\n        }\n        \n    }\n\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "/*\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 NumberTheory;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n/**\n *\n * @author Sourav Kumar Paul\n */\npublic class A235 {\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        //int gcd = gcd(924,923);\n        //System.out.println(gcd);\n       // System.out.println(gcd(923,461));\n        if(n<=2)\n            System.out.println(n);\n        else if(n==3)\n            System.out.println(\"6\");\n        \n        else if(n % 2== 0)\n       {\n           if(n % 3 == 0)\n           {\n               System.out.println((n-3)*(n-1)*(n-2));\n           }\n           else\n               \n           System.out.println(n * (n-1) * (n-3) );\n       }\n        else\n            System.out.println(n*(n-1)*(n-2));\n    }\n     private static int gcd(int i, int j) {\n        int a = Math.min(i,j);\n        int b = Math.max(i,j);\n       while(a != 0)\n       {\n           int temp = b % a;\n           b = a;\n           a = temp;\n       }\n       return b;\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class A235 {\n\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        long n = scan.nextInt();\n        BigInteger res = null;\n        if (n >= 3) {\n            if (n % 2 != 0) {\n                res = BigInteger.valueOf(n * (n - 1) * (n - 2));\n            } else if (n % 3 == 0) {\n                res = BigInteger.valueOf((n - 1) * (n - 2) * (n - 3));\n            } else {\n                res = BigInteger.valueOf(n * (n - 1) * (n - 3));\n            }\n        } else {\n            res = BigInteger.valueOf(n);\n        }\n        System.out.println(res);\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class LCM {\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        long n = scan.nextLong();\n\n        if (n <= 2)\n            System.out.println(n);\n        else if (n % 2 == 1)\n            System.out.println(n * (n - 1) * (n - 2));\n        else if (n % 3 == 0)\n            System.out.println((n - 1) * (n - 2) * (n - 3));\n        else\n            System.out.println(n * (n - 1) * (n - 3));\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A235 {\n\n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextInt();\n        if (n == 1) {\n            System.out.println(1);\n            return;\n        } else if (n == 2) {\n            System.out.println(2);\n            return;\n        } else if (n == 3) {\n            System.out.println(6);\n            return;\n        }\n\n        if (n % 2 == 0) {\n            if(n % 3 == 0) \n                System.out.println((n - 1) * (n - 2) * (n - 3));\n            else\n                System.out.println((n - 1) * n * (n - 3));\n        } else {\n            System.out.println(n * (n - 1) * (n - 2));\n        }\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main\n{\n    public static void main(String[]args)\n    {\n        Scanner input=new Scanner (System.in);\n        while(input.hasNext())\n        {\n            long n=input.nextLong();\n            if(n==1||n==2)\n                System.out.println(n);\n            else if(n%2==1)\n                System.out.println(n*(n-1)*(n-2));\n            else\n                if(n%3!=0)\n                    System.out.println(Math.max(n*(n-1)*(n-3),n*(n-1)*(n-2)/2));\n                else\n                    System.out.println(Math.max(  Math.max(n*(n-1)*(n-3)/3,n*(n-1)*(n-2)/2) , Math.max((n-2)*(n-1)*(n-3),n*(n-2)*(n-3)/6) ));\n        }\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Main {\n    public static void main(String[] args) {\n        Scanner in=new Scanner(System.in);\n        long num=in.nextLong();\n        long lcm=1;\n        if(num==2){\n            System.out.println(2);\n            System.exit(0);\n        }//End if\n        else if(num%2==0&&num%3!=0)\n            lcm=(num)*(num-1)*(num-3);\n        else if(num%2==0&&num%3==0)\n            lcm=(num-1)*(num-2)*(num-3);\n        else if(num%2!=0&&num>2)\n            lcm=num*(num-1)*(num-2);\n        System.out.println(lcm);\n    }//End main()\n}//End class\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main{\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        long num = input.nextLong();\n        if(num==0){\n            System.out.println(num);\n        }else if(num==1||num==2){\n            System.out.println(num);}\n        else if(num%2==0&&num>2&&num%3!=0){\n            System.out.println(num*(num-1)*(num-3));\n        }\n        else if(num%2==0&&num%3==0){\n            System.out.println((num-1)*(num-2)*(num-3));\n        }\n        else{\n        System.out.println(num*(num-1)*(num-2));}\n    }\n   \n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.util.Scanner;\n\n/**\n * Created by jizhe on 2016/1/29.\n */\npublic class LCMChallenge {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(new BufferedInputStream(System.in));\n\n        long N = in.nextLong();\n        if( N == 1 || N == 2 )\n        {\n            System.out.printf(\"%d\\n\", N);\n            return;\n        }\n\n        if( (N&1) == 1 )\n        {\n            long lcm = N*(N-1)*(N-2);\n            System.out.printf(\"%d\\n\", lcm);\n        }\n        else\n        {\n            if( N == 4 )\n            {\n                System.out.printf(\"12\\n\");\n            }\n            else\n            {\n                long lcm;\n                if( N%3 == 0 )\n                {\n                    lcm = (N-1)*(N-2)*(N-3);\n                }\n                else\n                {\n                    lcm = N*(N-1)*(N-3);\n                }\n\n                System.out.printf(\"%d\\n\", lcm);\n            }\n        }\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class maximus {\n\tstatic long GCD(long a,long b){\n\tif(b==0)return a;\n\treturn GCD(b,a%b);\t\n\t}\npublic static void main(String [] args){\n  Scanner in=new Scanner(System.in);\n  long n=in.nextInt();\n  if(n<=2){\n  System.out.print(n);\n  return;\t\n  }\n  if(n%2==1){\n  System.out.print((n*(n-1)*(n-2)));\n  return;\n  }\n  if(n%2==0 && n<=6){\n  System.out.print(n*(n-1)*(n-2)/2);\n  return;\t\n  }\n  long temp=(n*(n-1)*(n-3))/GCD(n,n-3);\n  System.out.print(Math.max((n-1)*(n-2)*(n-3),temp));\n  }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    Scanner cin = new Scanner(new BufferedInputStream(System.in));\n    long n;\n    long maxlcm;\n    \n    void run(){\n    \tn = cin.nextInt();\n    \tif(n == 1 || n ==2)\n    \t\tmaxlcm = n;\n    \telse if(n >= 3){\n            \tif(n % 2 != 0){\n    \t           \tmaxlcm = n * (n-1) * (n - 2);\n    \t        }\n            \telse if(n%3 != 0)\n            \t\tmaxlcm = n * (n - 1) * (n - 3);\n            \telse maxlcm = (n - 1) * (n - 2) * (n - 3);\n    \t}  \n    \tSystem.out.println(maxlcm);\n    }\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\n\t}\n}\n\n\t\t  \t\t\t\t \t  \t  \t\t \t \t     \t", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class LCM {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n=sc.nextLong();\n\t\tif(n < 3) {\n\t\t\tSystem.out.println(n);\n\t\t}\n\t\telse if(n % 2 != 0) {\n\t\t\tSystem.out.println(n * (n-1) * (n-2));\n\t\t}\n\t\telse if(n % 3 == 0) {\n\t\t\tSystem.out.println((n-1) * (n-2) * (n-3));\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(n * (n-1) * (n-3));\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main {\n\n    public static void main(String[] args) {\nScanner input = new Scanner(System.in);\nlong x = input.nextLong();\n\nif(x==1||x==2){System.out.println(x);\n    \n}\nelse if(x%2==0&&x>2&&x%3!=0){\n    System.out.println((x)*(x-1)*(x-3));\n    \n}else if(x%2==0&&x%3==0){\n    System.out.println((x-1)*(x-2)*(x-3));\n}\n\nelse {System.out.println(x*(x-1)*(x-2));}\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class LCMChallenge {\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        long n = Long.parseLong(f.readLine());\n        if (n == 1 || n == 2)\n            System.out.println(n);\n        else if (n % 2 == 1)\n            System.out.println(n*(n-1)*(n-2));\n        else\n        {\n            long prod = n*(n-1);\n            long x = n-2;\n            while (x > 0 && gcd(n,x) > 1 || gcd(n-1,x) > 1)\n                x--;\n            prod *= x;\n            if ((n-1)*(n-2)*(n-3) > prod)\n                prod = (n-1)*(n-2)*(n-3);\n            System.out.println(prod);\n        }\n    }\n    \n    public static long gcd(long a, long b)\n    {\n        if (b == 0)\n            return a;\n        return gcd(b, a%b);\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class test5{\n    public static void main(String[] args){\n        Scanner in=new Scanner(System.in);\n            long x=in.nextLong();\n            if(x>=3){\n                if(x%2!=0)\n                    System.out.println(x*(x-1)*(x-2));\n                else if(x%3==0)\n                    System.out.println((x-3)*(x-1)*(x-2));\n                else \n                    System.out.println(x*(x-1)*(x-3));\n            }\n            else System.out.println(x);\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class LCM {\n\tpublic static long gcd(long a,long b) {\n\t\twhile(true) {\n\t    \ta=a%b;\n\t\t  \tif (a==0) return b;\n\t\t    b=b%a;\n\t\t    if (b==0) return a;\n\t\t}\n    }\n\tpublic static void main (String[] args) throws java.lang.Exception {\n\t\tScanner in=new Scanner(System.in);\n\t\tlong n=in.nextInt();\n\t\tif (n>2) {\n\t\t\tif (gcd(n,n-2)>1) {\n\t\t\t\tif (gcd(n,n-3)>1) {\n\t\t\t\t\tSystem.out.println((n-1)*(n-2)*(n-3));\n\t\t\t\t}\n\t\t\t\telse System.out.println(n*(n-1)*(n-3));\n\t\t\t}\n\t\t\telse System.out.println(n*(n-1)*(n-2));\n\t\t}\n\t\telse System.out.println(n);\n\t}\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Double.parseDouble;\nimport static java.lang.String.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n                                            //(new FileReader(\"input.in\"));\n        StringBuilder out = new StringBuilder();\n        StringTokenizer tk;\n        //PrintWriter pw = new PrintWriter(\"output.out\", \"UTF-8\");\n  \n        long n = parseLong(in.readLine());\n        \n        if(n <= 2) System.out.println(n);\n        else if(n%2 == 1)System.out.println(n*(n-1)*(n-2));\n        else {\n            long ans = (n-1)*(n-2)*(n-3);\n            \n            if(gcd(n*(n-1),n-3)==1) ans = max(ans, n*(n-1)*(n-3));\n            \n            System.out.println(ans);\n        }\n    }\n    \n    static long gcd(long a,long b) {\n        return b==0 ? a : gcd(b, a%b);\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n    public static Scanner scan = new Scanner(System.in);\n    public static boolean bg = true;\n\n    public static void main(String[] args) throws Exception {\n        long n1 = Integer.parseInt(scan.next());\n        if (n1==1){\n            System.out.println(1);\n            System.exit(0);\n        }\n        if (n1==2){\n            System.out.println(2);\n            System.exit(0);\n        }\n        if (n1==3){\n            System.out.println(6);\n            System.exit(0);\n        }\n        if (n1%2==0){\n            if (n1%3==0){\n                n1-=1;\n                n1 = n1*(n1-1)*(n1-2);\n                System.out.println(n1);\n            }\n            else {\n                n1 = n1*(n1-1)*(n1-3);\n                System.out.println(n1);\n            }\n        }\n        else {\n            n1 = n1*(n1-1)*(n1-2);\n            System.out.println(n1);\n        }\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Prob235A {\n\tpublic static void main(String[] Args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint x = scan.nextInt();\n\t\tif (x < 3) {\n\t\t\tif (x == 1)\n\t\t\t\tSystem.out.println(1);\n\t\t\telse\n\t\t\t\tSystem.out.println(2);\n\t\t} else {\n\t\t\tlong answer = x;\n\t\t\tif (x % 2 == 1) {\n\t\t\t\tanswer *= x - 1;\n\t\t\t\tanswer *= x - 2;\n\t\t\t} else if (x % 3 != 0) {\n\t\t\t\tanswer *= x - 1;\n\t\t\t\tanswer *= x - 3;\n\t\t\t} else {\n\t\t\t\tanswer = x - 1;\n\t\t\t\tanswer *= x - 2;\n\t\t\t\tanswer *= x - 3;\n\t\t\t}\n\t\t\tSystem.out.println(answer);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nipuna Samarasekara\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    /////////////////////////////////////////////////////////////\n\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n    int n=in.nextInt();\n        if(n==1||n==2){\n            out.println(n);\n            return;\n        }\n        if(n==4){\n            out.println(12);\n            return;\n        }\n     long nn=n;\n        if(n%2==1){\n        long ans=nn*(nn-1)*(nn-2);\n            out.println(ans);\n        }\n        else if(n%3==0){\n            nn--;\n            long ans=nn*(nn-1)*(nn-2);\n            out.println(ans);\n\n        }\n        else {\n            long ans=nn*(nn-1)*(nn-3);\n            out.println(ans);\n            \n        }\n\n    }\n    }\n\nclass FastScanner extends BufferedReader {\n\n    public FastScanner(InputStream is) {\n        super(new InputStreamReader(is));\n    }\n\n    public int read() {\n        try {\n            int ret = super.read();\n//            if (isEOF && ret < 0) {\n//                throw new InputMismatchException();\n//            }\n//            isEOF = ret == -1;\n            return ret;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    static boolean isWhiteSpace(int c) {\n        return c >= 0 && c <= 32;\n    }\n\n    public int nextInt() {\n        int c = read();\n        while (isWhiteSpace(c)) {\n            c = read();\n        }\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        int ret = 0;\n        while (c >= 0 && !isWhiteSpace(c)) {\n            if (c < '0' || c > '9') {\n                throw new NumberFormatException(\"digit expected \" + (char) c\n                        + \" found\");\n            }\n            ret = ret * 10 + c - '0';\n            c = read();\n        }\n        return ret * sgn;\n    }\n\n    public String readLine() {\n        try {\n            return super.readLine();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    }\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", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Lcm\n{\npublic static void main(String args[])throws Exception\n{\nBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\nlong n=Long.parseLong(br.readLine());\nif(n<=2)\nSystem.out.println(n);\nelse\n{\n\n if(n%6==0)\n{\n System.out.println(((n-1)*(n-2)*(n-3)));\n}\n else if(n%2==0)\n{\n  System.out.println((n*(n-1)*(n-3)));\n}\nelse\n{\n  System.out.println((n*(n-1)*(n-2)));\n}\n}\n\n}\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class LCM235A\n{\n    public static void main(String[] args) \n    {\n        // Set up scanner\n        Scanner sc = new Scanner(System.in); \n        // System.out.println(\"Enter n\");\n        long n = sc.nextLong();\n        \n        if (n==1)\n        {\n            System.out.println(1);\n            return;\n        }\n        if (n==2)\n        {\n            System.out.println(2);\n            return;\n        }\n        if (n==3)\n        {\n            System.out.println(6);\n            return;\n        }\n        if (n==4)\n        {\n            System.out.println(12);\n            return;\n        }\n        \n        if (n%2 ==1)   // Odd number easy\n        {\n            System.out.println(n*(n-1)*(n-2));\n            return;\n        }\n        \n        // Even number is a bit harder\n        if (n%3 == 0)\n        {\n            System.out.println((n-1)*(n-2)*(n-3));\n        }\n        else\n        {\n            System.out.println(n*(n-1)*(n-3));\n        }\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author walker\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long n = in.readInt();\n        if(n < 3){\n            out.print(n);\n        }\n        else if(n % 2 != 0) {\n            out.print(n * (n-1) * (n-2));\n        }\n        else if(n % 3 == 0) {\n            out.print((n-1) * (n-2) * (n-3));\n        }\n        else {\n            out.print(n * (n-1) * (n-3));\n        }\n    }\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic 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\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.util.Scanner;\n\n/**\n * Created by jizhe on 2016/1/29.\n */\npublic class LCMChallenge {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(new BufferedInputStream(System.in));\n\n        long N = in.nextLong();\n        if( N == 1 || N == 2 )\n        {\n            System.out.printf(\"%d\\n\", N);\n            return;\n        }\n\n        if( (N&1) == 1 )\n        {\n            long lcm = N*(N-1)*(N-2);\n            System.out.printf(\"%d\\n\", lcm);\n        }\n        else\n        {\n            long lcm;\n            if( N%3 == 0 )\n            {\n                lcm = (N-1)*(N-2)*(N-3);\n            }\n            else\n            {\n                lcm = N*(N-1)*(N-3);\n            }\n\n            System.out.printf(\"%d\\n\", lcm);\n        }\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class Main{\n  public static void main(String[] args) {\n       Scanner sc = new Scanner(System.in);\n       Long N = sc.nextLong();\n       Long ans;\n       sc.close();\n       if(N <= 2)\n           System.out.println(N);\n       else{\n           if(N % 6 == 0){\n                ans = (N - 1) * (N - 2) * (N - 3);}\n            else if(N % 2 == 0){\n                ans = N * (N - 1) * (N - 3);\n            }\n            else{\n                ans = N * (N - 1) * (N - 2);\n            }\n           System.out.println(ans);\n       }\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Solution {\n    public static void main(String [] args){\n        Scanner stdin = new Scanner(System.in);\n        long n = stdin.nextLong();\n        if(n<3)\tSystem.out.println(n);\n        else {\n            if(n%2==0){\n                long a=0,b=0;\n                if(n%3!=0)\ta = (n*(n-1)*(n-3));    \n                n--;\n                b = (n*(n-1)*(n-2));\n                System.out.println(Math.max(a, b));\n            }\n            else\tSystem.out.println(n*(n-1)*(n-2));\n        }\n    }\n}\n \t \t \t\t\t   \t \t\t \t \t \t \t \t\t", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    Scanner cin = new Scanner(new BufferedInputStream(System.in));\n    long n;\n    long maxlcm;\n    \n    void run(){\n    \tn = cin.nextInt();\n    \tif(n == 1 || n ==2)\n    \t\tmaxlcm = n;\n    \telse if(n >= 3){\n            \tif(n % 2 != 0){\n    \t           \tmaxlcm = n * (n-1) * (n - 2);\n    \t        }\n            \telse if(n%3 != 0)\n            \t\tmaxlcm = n * (n - 1) * (n - 3);\n            \telse maxlcm = (n - 1) * (n - 2) * (n - 3);\n    \t}  \n    \tSystem.out.println(maxlcm);\n    }\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\n\t}\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "\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        long n = in.nextLong();\n        if (n == 1 || n == 2) {\n            System.out.println(n);\n        } else if (n % 2 == 0) {\n            if (n % 3 == 0)\n                System.out.println((n - 1) * (n - 2) * (n - 3));\n            else\n                System.out.println(n * (n - 1) * (n - 3));\n        } else {\n            System.out.println(n * (n - 1) * (n - 2));\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.PrintStream;\nimport java.util.Scanner;\n\n/**\n * @author Roman Elizarov\n */\npublic class Round_146_A {\n\tpublic static void main(String[] args) {\n\t\tnew Round_146_A().go();\n\t}\n\n\tvoid go() {\n\t\t// read input\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\n\t\t// solve\n\t\tlong result = solve(n);\n\n\t\t// write result\n\t\tPrintStream out = System.out;\n\t\tout.println(result);\n\t}\n\n\tstatic long solve(int n) {\n        if (n == 1)\n            return 1;\n        if (n == 2)\n            return 2;\n        if (n % 2 == 0) {\n            if (n % 3 == 0)\n                return (long)(n - 1) * (n - 2) * (n - 3);\n            else\n                return (long)n * (n - 1) * (n - 3);\n        } else\n\t\t    return (long)n * (n - 1) * (n - 2);\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "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        \n        //inputs\n        long n = in.nextLong();\n        if(n == 1)\n            System.out.println(1);\n        else if(n == 2)\n            System.out.println(2);\n            \n        else if(n % 2 == 0){\n            \n            int cnt = nPrime(n);\n            if(cnt == 1)\n            System.out.println((n) * (n-1) * (n-3));\n        else if(cnt > 1)\n            System.out.println((n-1) * (n-2) * (n-3));\n        }\n        \n        else\n            System.out.println((n) * (n-1) * (n-2));\n      }\n    \n    public static int nPrime(long n){\n        int cnt=1;\n        if(n % 3 == 0)\n            cnt++;\n        return cnt;\n    }\n    }\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class lcm {\n\tstatic int n;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t//BufferedReader in = new BufferedReader(new FileReader(\"lcm.in\"));\n\t\tn = Integer.parseInt(in.readLine());\n\t\tSystem.out.println(lcm(n));\n\t\tin.close();\n\t}\n\t\n\tstatic long lcm(int n) {\n\t\tif (n == 1) return 1;\n\t\tif (n == 2) return 2;\n\t\t\n\t\tif(n%6==0) {\n\t\t\tlong ans = n-1;\n\t\t\tans *= n-2;\n\t\t\tans *= n-3;\n\t\t\treturn ans;\n\t\t}\n\t\t\n\t\tif (n%2==0) {\n\t\t\tlong ans = n;\n\t\t\tans *= n-1;\n\t\t\tans *= n-3;\n\t\t\treturn ans;\n\t\t}\n\t\t\n\t\tlong ans = n;\n\t\tans *= n-1;\n\t\tans *= n-2;\n\t\treturn ans;\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintStream;\n/** Oct 21, 2012 **/\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\n\n/**\n * @author DOAN Minh Quy\n * @email mquy.doan@gmail.com\n */\npublic class C236 {\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        new C236().run();\n    }\n    void run() {\n        InputScanner scanner = new InputScanner(System.in);\n        PrintStream printer = new PrintStream(System.out);\n        int n = scanner.nextInt();\n        long answer;\n        if ( n == 1 ){\n            answer = 1;\n        }else if ( n == 2 ){\n            answer = 2;\n        }else{\n            if ( (n & 1) != 0 ){\n                answer = (long)n * (long)(n-1) * (long)(n-2);\n            }else{\n                if ( n % 3 == 0 ){\n                    answer = (long)(n-1) * (long)(n-2) * (long)(n-3);\n                }else{\n                    answer = (long)(n) * (long)(n-1) * (long)(n-3);\n                }\n            }\n        }\n        printer.println(answer);\n    }\n    class InputScanner{\n        BufferedInputStream bis;\n        byte[] buffer = new byte[1024]; \n        int currentChar;\n        int charCount;\n        public InputScanner(InputStream stream){\n            bis = new BufferedInputStream(stream);\n        }\n        public byte read() {\n            if (charCount == -1)\n                throw new InputMismatchException();\n            if (currentChar >= charCount) {\n                currentChar = 0;\n                try {\n                    charCount = bis.read(buffer);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (charCount <= 0)\n                    return -1;\n            }\n            return buffer[currentChar++];\n        }\n        public int nextInt(){\n            int c = read();\n            while (isSpaceChar(c)){\n                c = read();\n            }\n            int sign = 1;\n            if (c == '-') {\n                sign = -1;\n                c = read();\n            }\n            int rep = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                rep *= 10;\n                rep += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return rep * sign;\n        }\n        public long nextLong(){\n            int c = read();\n            while (isSpaceChar(c)){\n                c = read();\n            }\n            int sign = 1;\n            if (c == '-') {\n                sign = -1;\n                c = read();\n            }\n            long rep = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                rep *= 10;\n                rep += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return rep * (long)sign;\n        }\n        public String next(){\n            char c = (char)read();\n            while (isSpaceChar(c)){\n                c = (char)read();\n            }\n            StringBuilder build = new StringBuilder();\n            do{\n                build.append(c);\n                c = (char)read();\n            }while(!isSpaceChar(c));\n            return build.toString();\n        }\n        public boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n        public void close(){\n            try {\n                bis.close();\n            } catch (IOException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n        }\n    }\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class LCMChallenge\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\t\n\t\tif(n < 3)\n\t\t{\n\t\t\tSystem.out.println(n);\n\t\t}\n\t\telse if(n % 2 == 1)\n\t\t{\n\t\t\tSystem.out.println((long)n * (n - 1) * (n - 2));\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(n % 3 != 0)\n\t\t\t{\n\t\t\t\tSystem.out.println((long)n * (n - 1) * (n - 3));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println((long)(n - 1) * (n - 2) * (n - 3));\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class A235 {\n    public static void main(String args[]) throws Exception{\n        BufferedReader ip = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(ip.readLine());\n        int a,b,c;\n        int x = 0,y = 0,z = 0;\n        BigInteger l,t;\n        \n        if(n-2 > 1)\n        {\n            a = n;\n            b = n-1;\n            c = n-2;\n        }\n        else\n        {\n            a = n;\n            if(n-1 > 1)\n                b = n-1;\n            else\n                b = 1;\n            c = 1;\n            \n            System.out.println(a*b);\n            return;\n        }\n    \n        if(n-3 > 1)\n        {\n            x = n-1;\n            y = n-2;\n            z = n-3;\n        }\n        \n        if(n % 2 == 0)\n            if(n % 3 == 0)\n                l = BigInteger.valueOf(x).multiply(BigInteger.valueOf(y).multiply(BigInteger.valueOf(z)));\n            else\n            {\n                l = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b).multiply(BigInteger.valueOf(c-1)));\n                t = BigInteger.valueOf(x).multiply(BigInteger.valueOf(y).multiply(BigInteger.valueOf(z)));\n                if(l.compareTo(t) < 0)\n                    l = t;\n            }\n        else\n            l = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b).multiply(BigInteger.valueOf(c)));\n        \n        System.out.println(l);\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "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 Nasko\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n            int N = in.nextInt();\n\n\n            if (N == 1) {\n                out.println(1);\n            } else if (N == 2) {\n                out.println(2);\n            } else if (N == 3) {\n                out.println(6);\n            } else {\n\n                long best = Long.MIN_VALUE;\n                best = Math.max(best, lcm(N, lcm(N - 1, N - 2)));\n                best = Math.max(best, lcm(N, lcm(N - 2, N - 3)));\n                best = Math.max(best, lcm(N, lcm(N - 1, N - 3)));\n                best = Math.max(best, lcm(N - 1, lcm(N - 2, N - 3)));\n\n                out.println(best);\n            }\n        }\n\n        private long lcm(long a, long b) {\n            return a * (b / gcd(a, b));\n        }\n\n        private long gcd(long a, long b) {\n            return b == 0 ? a : gcd(b, a % b);\n        }\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            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", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////  SOLUTION ///////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\n\npublic  class Solution{ \n\t//      main();   \n\tpublic static void main(String[] args) throws IOException{\n\t\t///input\n\t\t  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t  String[] str=br.readLine().split(\" \");\n\t      long n=Long.parseLong(str[0]);\n\t      if(n<3)\n\t\t\tSystem.out.println(n);\n\t\t\telse if(n%2==1)\n\t\t\tSystem.out.println(n*(n-1)*(n-2));\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(n%3!=0)\n\t\t\t\tSystem.out.println(n*(n-1)*(n-3));\n\t\t\t\telse\n\t\t\t\tSystem.out.println((n-1)*(n-2)*(n-3));\n\t\t     }\n\t      \n\t\t\n}//void main\n\t   \n}//class main\n\n\n\n\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A235 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong a = in.nextLong();\n\t\tif (a % 2 == 0) {\n\t\t\tlong result = cal(a);\n\t\t\tresult = Math.max(result, cal(a + 1));\n\t\t\tresult = Math.max(result, cal2(a));\n\t\t\tSystem.out.println(Math.max(result, a));\n\t\t}\n\n\t\telse {\n\t\t\tlong result = (a - 1) * (a - 2) * (a - 0);\n\t\t\tSystem.out.println(Math.max(result, a));\n\t\t}\n\t}\n\n\tstatic long cal(long a) {\n\t\tlong result = (a - 1) * (a - 2);\n\t\tresult /= gcd(a - 1, a - 2);\n\t\tlong gcd = gcd(result, a - 3);\n\t\tresult *= (a - 3);\n\t\tresult /= gcd;\n\t\treturn result;\n\t}\n\n\tstatic long cal2(long a) {\n\t\tlong result = (a) * (a - 1);\n\t\tresult /= gcd(a - 1, a);\n\t\tlong gcd = gcd(result, a - 3);\n\t\tresult *= (a - 3);\n\t\tresult /= gcd;\n\t\treturn result;\n\t}\n\n\tprivate static long gcd(long l, long i) {\n\t\tif (l == 0 || i == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (l % i == 0) {\n\t\t\treturn i;\n\t\t}\n\t\treturn gcd(i, l % i);\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tboolean eof;\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 \"-1\";\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\tvoid solve() {\n\t\tlong n = nextInt(), ans = n;\n\t\tif (n % 6 == 0) {\n\t\t\tans = Math.max((n - 1) * (n - 2) * (n - 3), ans);\n\t\t} else if (n % 2 == 0) {\n\t\t\tans = Math.max(ans, n * (n - 1) * (n - 3));\n\t\t} else {\n\t\t\tans = Math.max(n * (n - 1) * (n - 2), ans);\n\t\t}\n\t\tout.print(ans);\n\t}\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\n\t\t\t// br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(new FileWriter(\"output.txt\"));\n\n\t\t\tsolve();\n\n\t\t\tbr.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\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class CF{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tTaskA t = new TaskA();\n\t\tSystem.out.println(t.solve(n));\n\t}\n}\n\nclass TaskA{\n\tpublic long solve(long n)\n\t{\n\t\tif(n < 3)\n\t\t\treturn n;\n\t\telse if(n % 2 == 1)\n\t\t\treturn n * (n-1) * (n-2);\n\t\telse if(n % 3 != 0)\n\t\t\treturn n * (n-1) * (n-3);\n\t\telse\n\t\t\treturn (n-1) * (n-2) * (n-3);\n\t}\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\n\n\npublic class Challenge {\n\t\n\tpublic static void main(String[] args) throws java.lang.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\tTaskA solver = new TaskA();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\t\n\tpublic void solve(InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\t\n\t\tif (n == 1) {\n\t\t\tout.println(\"1\");\n\t\t} else if (n == 2) {\n\t\t\tout.println(\"2\");\n\t\t} else if (n == 3) {\n\t\t\tout.println(\"6\");\n\t\t} else if (n%2 > 0) {\n\t\t\tout.println(1L * n * (n-1) * (n-2));\n\t\t} else if (n%3 == 0) {\n\t\t\tout.println(1L * (n-1) * (n-2) * (n-3));\n\t\t} else {\n\t\t\tout.println(1L * n * (n-1) * (n-3));\n\t\t}\n\t}\n}\n\nclass InputReader {\n\tpublic BufferedReader reader;\n\tpublic StringTokenizer 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\t\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n/**\n * 2013.07.27 No.1 235A LCM Challenge\n * \u6570\u8bba n%2 == 0?     n%3 == 0?\n * @author Administrator * \n */\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        if (n < 3)\n            System.out.println(n);\n        else if (n % 2 != 0)\n            System.out.println((long)n * (n - 1) * (n - 2));\n        else if(n % 3 != 0)\n            System.out.println((long)n * (n - 1) * (n - 3));\n        else \n            System.out.println((long)(n - 1) * (n - 2) * (n - 3));\n        in.close();\n        \n\n    }\n} ", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class LCMChallenge {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextInt();\n\t\tif(n == 1l)\n\t\t\tSystem.out.println(1);\n\t\telse if(n == 2l)\n\t\t\tSystem.out.println(2);\n\t\telse\n\t\t{\n\t\t\tlong c1 = n*(n-1)*(n-2);\n\t\t\tlong c2 = n*(n-1)*(n-3);\n\t\t\tlong c3 = (n-1)*(n-2)*(n-3);\n\t\t\tif(n%2==0)\n\t\t\t\tc1/=2;\n\t\t\telse\n\t\t\t\tc3/=2;\n\t\t\tif(n%3==0)\n\t\t\t\tc2/=3;\n\t\t\tlong ans = Math.max(c1, c2);\n\t\t\tans = Math.max(ans, c3);\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class LCMChallenge {\n    public static void main(String[] args) {\n        Scanner cin = new Scanner(System.in);\n        int n = cin.nextInt();\n        if (n < 3) {\n            System.out.println(n);\n        } else if (n % 2 == 1) {\n            System.out.println((long) n * (n - 1) * (n - 2));\n        } else {\n            if (n % 3 != 0) {\n                System.out.println((long) n * (n - 1) * (n - 3));\n            } else {\n                System.out.println((long) (n - 1) * (n - 2) * (n - 3));\n            }\n        }\n    }\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    long n;\n    long maxlcm;\n    \n    void run(){\n    \tn = cin.nextInt();\n    \tif(n == 1 || n ==2)\n    \t\tmaxlcm = n;\n    \telse if(n >= 3){\n            \tif(n % 2 != 0){\n    \t           \tmaxlcm = n * (n-1) * (n - 2);\n    \t        }\n            \telse if(n%3 != 0)\n            \t\tmaxlcm = n * (n-1) * (n - 3);\n            \telse maxlcm = (n - 1) * (n - 2) * (n - 3);\n    \t}  \n    \tSystem.out.println(maxlcm);\n    }\n\n\tpublic static void main(String[] args) {\n\t\t new Main().run();\n\t}\n\tScanner cin = new Scanner(new BufferedInputStream(System.in));\n}\n  \t\t \t   \t\t \t\t \t\t\t \t \t\t", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "\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 A {\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader sc = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = sc.nextInt();\n\n\t\tif(n < 3)\n\t\t\tout.println(n);\n\t\telse\n\t\t{\n\t\t\tif((n & 1) == 1)\n\t\t\t\tout.println(lcm(n, lcm(n - 1, n - 2)));\n\t\t\telse\n\t\t\t\tout.println(Math.max(lcm(n - 1, lcm(n - 2, n - 3)), lcm(n, lcm(n - 1, n - 3))));\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic long gcd(long a, long b) \n\t{ \n\t\twhile(b != 0)\n\t\t{\n\t\t\ta = a%b;\n\t\t\tb ^= a;\n\t\t\ta ^= b;\n\t\t\tb ^= a;\n\t\t}\n\t\treturn a;\n\n\t}\n\n\tstatic long lcm(long a, long b) { return a / gcd(a,b) * b; }\n}\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));\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\n}", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author BSRK Aditya (bsrkaditya@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\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, Scanner in, PrintWriter out) {\n        long n = in.nextLong();\n\n        if(n == 1) out.println(\"1\");\n        else if(n == 2) out.println(\"2\");\n        else if(n%2 == 1) out.println(n*(n-1)*(n-2));\n        else if(n%6 == 0) out.println((n-1)*(n-2)*(n-3));\n        else out.println(n*(n-1)*(n-3));\n\t}\n}\n\n", "complexity": "constant", "problem": "235_A. LCM Challenge", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class AAA {\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());\t\n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint m=Integer.parseInt(st.nextToken());\n\t\tString a=\"\";\n\t\tString b=\"\";\n\t\tfor(int i=0;i<1129;i++) {\n\t\t\ta+=\"1\";\n\t\t\tb+=\"8\";\n\t\t}\n\t\ta+=\"9\";\n\t\tb+=\"1\";\n\t\t\n\t\tSystem.out.println(a);\n\t\tSystem.out.println(b);\n\t}\n\t\t\n}\n", "complexity": "constant", "problem": "1028_B. Unnatural Conditions", "from": "CODEFORCES"}
{"src": "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        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        // int n = Integer.parseInt(bf.readLine());\n        StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        int n = Integer.parseInt(st.nextToken());\n        int m = Integer.parseInt(st.nextToken());\n        StringBuilder ans1 = new StringBuilder();\n        StringBuilder ans2 = new StringBuilder();\n        for(int i=0; i<2229; i++) ans1.append('5');\n        ans1.append('6');\n        for(int i=0; i<2230; i++) ans2.append('4');\n        out.println(ans1.toString());\n        out.println(ans2.toString());\n        out.close(); System.exit(0);\n    }\n}\n", "complexity": "constant", "problem": "1028_B. Unnatural Conditions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class AAA {\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());\t\n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint m=Integer.parseInt(st.nextToken());\n\t\tString a=\"\";\n\t\tString b=\"\";\n\t\tfor(int i=0;i<1129;i++) {\n\t\t\ta+=\"1\";\n\t\t\tb+=\"8\";\n\t\t}\n\t\ta+=\"9\";\n\t\tb+=\"1\";\n\t\t\n\t\tSystem.out.println(a);\n\t\tSystem.out.println(b);\n\t}\n\t\t\n}\n", "complexity": "constant", "problem": "1028_B. Unnatural Conditions", "from": "CODEFORCES"}
{"src": "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 S=Integer.parseInt(s1[1]);\n            if(S%n==0)\n             System.out.println(S/n);\n            else\n             System.out.println(S/n+1);\n      }\n}", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class coins\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 i,k,n,v;\n  String a;\n  a=in.readLine();\n  for(i=0;i<a.length();i++)\n  {\n   if(a.charAt(i)==' ')\n   break;\n  }\n  n=Integer.parseInt(a.substring(0,i));\n  v=Integer.parseInt(a.substring(i+1));\n  k=v%n;\n  v=v/n;\n  if(k>0)\n  v++;\n  System.out.println(v);\n }\n}\n", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "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 S=Integer.parseInt(s1[1]);\n            if(S%n==0)\n             System.out.println(S/n);\n            else\n             System.out.println(S/n+1);\n      }\n}", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    public static void main(String args[]) {\n        FastScanner scn = new FastScanner();\n        int n = scn.nextInt();\n        int s = scn.nextInt();\n        if (s <= n) {\n            System.out.println(1);\n        } else if (s > n) {\n            if(s%n == 0){\n                System.out.println(s/n);\n            } else {\n                System.out.println(s/n + 1);\n            }\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", "complexity": "constant", "problem": "1061_A. Coins", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A912 {\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\t\n\t\tint A = scan.nextInt();\n\t\tint B = scan.nextInt();\n\t\tlong x = scan.nextInt();\n\t\tlong y = scan.nextInt();\n\t\tlong z = scan.nextInt();\n\t\t\n\t\tlong requiredA = x * 2 + y;\n\t\tlong requiredB = y + z * 3;\n\t\t\n\t\tlong neededA = Math.max(0, requiredA - A);\n\t\tlong neededB = Math.max(0, requiredB - B);\n\t\tSystem.out.print(neededA + neededB);\n\t}\n\n}\n", "complexity": "constant", "problem": "912_A. Tricky Alchemy", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class A267 {\n\n    static  public  long _solve(long a,long b){\n        long result = -1;\n        while(a!=0 && b!=0){\n            if(a>b){\n                result +=(a/b);\n                a = a%b;\n            }\n            else{\n                result +=(b/a);\n                b = b%a;\n            }\n        }\n        return result+1;\n    }\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int t = in.nextInt();\n        long a,b;\n        while(t-- > 0){\n            a = in.nextLong();\n            b = in.nextLong();\n            System.out.println(_solve(a,b));\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 r) {\n            br = new BufferedReader(r);\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens())\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public 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 double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public boolean ready() throws IOException {\n            return br.ready();\n        }\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\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 Coder{\n    \n    static class FastScanner{\n        BufferedReader s;\n        StringTokenizer st;\n        \n        public FastScanner(){\n            st = new StringTokenizer(\"\");\n            s = new BufferedReader(new InputStreamReader(System.in));\n        }\n        \n        public int nextInt() throws IOException{\n            if(st.hasMoreTokens())\n                return Integer.parseInt(st.nextToken());\n            else{\n                st = new StringTokenizer(s.readLine());\n                return nextInt();\n            }\n        }\n    }\n    \n    \n    public static void main(String[] args) throws IOException{\n        FastScanner s = new FastScanner();\n        PrintWriter ww = new PrintWriter(new OutputStreamWriter(System.out));\n        int test = s.nextInt(); int cnt=0;\n        while(test-->0){\n            int a = s.nextInt();\n            int b = s.nextInt();\n            cnt=0;\n            while(a!=0 && b!=0){\n                int max = Math.max(a, b);\n                if(max == b){\n                    int divi = b/a;\n                    b -= divi*a;\n                    cnt+=divi;\n                }else{\n                    int divi = a/b;\n                    a -= divi*b;\n                    cnt+=divi;\n                }\n        //      System.out.println(a+\" \"+b);\n            }\n            ww.println(cnt);\n        }\n        ww.close();\n    }\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Solution{\n\n    public static void main(String[] args){\n        Scanner in = new Scanner(System.in);\n        int pairs = in.nextInt();\n        while (pairs > 0){\n            in.nextLine();\n            int a = in.nextInt();\n            int b = in.nextInt();\n            int count = 0;\n            while (a != 0 && b != 0){\n                if (b >= a && a != 0){\n                    count += b/a;\n                    b = b%a;\n                }\n                if (a > b && b != 0){\n                    count += a/b;\n                    a = a%b;\n                }\n            }\n            System.out.println(count);\n            pairs--;\n        }\n    }\n\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Mai {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tScanner cin = new Scanner(System.in);\n\t\t\n\t\tint t, n, m;\n\t\t\n\t\tt = cin.nextInt();\n\t\t\n\t\twhile(t > 0) {\n\t\t\tt--;\n\t\t\tint sum = 0;\n\t\t\tn = cin.nextInt();\n\t\t\tm = cin.nextInt();\n\t\t\twhile(n > 0 && m > 0) {\n\t\t\t\tif(n < m) {\n\t\t\t\t\tint k = n;\n\t\t\t\t\tn = m;\n\t\t\t\t\tm = k;\n\t\t\t\t}\n\t\t\t\tsum += n / m; n %= m;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n\n}\n \t\t  \t\t   \t \t  \t \t\t \t\t    \t", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * Created by carolineshi on 3/30/17.\n */\npublic class Subtractions {\n\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        int t = scan.nextInt();\n        while(t != 0) {\n            int f = scan.nextInt();\n            int s = scan.nextInt();\n            System.out.println(ops(f, s));\n            t--;\n        }\n    }\n\n    public static int ops(int f, int s) {\n        int ops = 0;\n\n        while((f > 0) && (s > 0)) {\n            if(f > s) {\n                ops += f/s;\n                f %= s;\n            } else {\n                //f <= s\n                ops += s/f;\n                s %= f;\n            }\n        }\n\n        return ops;\n    }\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class CodeForces {\n\n\tpublic static void main(String[] args) throws IOException,NumberFormatException{\n\t\ttry {\n\t\t\tFastScanner sc=new FastScanner();\n\t\t\tint t=sc.nextInt();\n\t\t\twhile(t-->0) {\n\t\t\t\tint a=sc.nextInt(),b=sc.nextInt();\n\t\t\t\tint count=0;\n\t\t\t\twhile(a!=0&&b!=0) {\n\t\t\t\t\tif(a>b) {\n\t\t\t\t\t\tint temp=a;\n\t\t\t\t\t\ta=b;\n\t\t\t\t\t\tb=temp;\n\t\t\t\t\t}\n\t\t\t\t    count+=(b/a);\n\t\t\t\t    b=b%a;\n\t\t\t\t}\n\t\t\t\tSystem.out.println(count);\n\t\t\t}\t\t\t\n\t\t\t\n\t\t}\n\t\tcatch(Exception e) {\n\t\t\treturn ;\n\t\t}\n\n\t}\n\t\n\t\n\tpublic static class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry { \n                                      st=new StringTokenizer(br.readLine());\t\t\t\t               \n                              } catch (IOException e) {}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t}\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class CF267A {\n\n\tpublic static void main(String[] args) {\n\t\tint n=0, a, b;\n\t\tBufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n\t\ttry {\n\t\t\tn = Integer.parseInt(stdin.readLine());\n\t\t} catch (IOException e) {\n\t\t}\n\t\twhile(n-->0){\n\t\t\tString[] row = null;\n\t\t\ttry {\n\t\t\t\trow = stdin.readLine().split(\" \");\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\ta = Integer.parseInt(row[0]);\n\t\t\tb = Integer.parseInt(row[1]);\n\t\t\tif(a<b) System.out.println(calc(a,b));\n\t\t\telse System.out.println(calc(b,a));\n\t\t}\n\t}\n\t\n\tstatic int calc(int a, int b){\n\t\tif(a==0) return 0;\n\t\tif(a==b) return 1;\n\t\tif(a==1) return b;\n\t\telse return b/a+calc(b%a, a);\n\t}\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "\n//package A;\n\nimport java.util.Scanner;\n\npublic class Solution {\n    Scanner in = new Scanner(System.in);\n    void run() throws Exception {\n        int tests = in.nextInt();\n        while (tests > 0) {\n            --tests;\n            int a = in.nextInt();\n            int b = in.nextInt();\n            int res = 0;\n            while (a > 0 && b > 0) {\n                if (a >= b) {\n                    res += a / b;\n                    a %= b;\n                }\n                else {\n                    res += b / a;\n                    b %= a;\n                }\n            }\n            System.out.println(res);\n        }\n    }\n    public static void main(String args[]) throws Exception {\n        new Solution().run();\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Question267A {\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int t=sc.nextInt();\n        while (t--!=0){\n            int x=sc.nextInt();\n            int y=sc.nextInt();\n            int max=Math.max(x,y);\n            int min=Math.min(x,y);\n            int ans=0;\n            while (min>0 && max>0){\n                int temp=max;\n                ans+=temp/min;\n                max=min;\n                min=temp%min;\n           }\n            System.out.println(ans);\n        }\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main{\n    public static void main(String args[]){\n        Scanner in = new Scanner(System.in);\n        int T = in.nextInt();\n        while(T!=0){\n            T--;\n            int a = in.nextInt();\n            int b = in.nextInt();\n            int ans=0;\n            while(a>0&&b>0){\n                if(a>b){\n                    int c = a;\n                    a = b;\n                    b = c;\n                }\n                ans += (b-(b%a))/a;\n                b = b%a;\n            }\n            System.out.println(ans);\n        }\n    }\n    \n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Subtraction {\n    static long c=0;\n    public static void main(String[] args) throws IOException {\n        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));\n        int n=Integer.parseInt(reader.readLine());\n        while (n-->0){\n            String l=reader.readLine();\n            String[] a=l.split(\" \");\n            long A=Long.parseLong(a[0]);\n            long B=Long.parseLong(a[1]);\n            c=0;\n            gcd(A,B);\n            System.out.println(c);\n        }\n    }\n\n    private static void gcd(long a, long b) {\n        if (b==0)\n            return ;\n        c=c+a/b;\n        gcd(b,a%b);\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Subtractions {\n\n\tpublic static void main(String[] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\tint count = kb.nextInt();\n\t\twhile(count > 0) {\n\t\t\tint smaller = kb.nextInt();\n\t\t\tint larger = kb.nextInt();\n\t\t\tint ops = 0;\n\t\t\t\n\t\t\twhile(smaller > 0 && larger > 0) {\n\t\t\t\tif(smaller > larger) {\n\t\t\t\t\tint temp = smaller;\n\t\t\t\t\tsmaller = larger;\n\t\t\t\t\tlarger = temp;\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\tops += larger/smaller;\n\t\t\t\tlarger = larger % smaller;\n\t\t\t}\n\t\t\tSystem.out.println(ops);\n\t\t\tcount--;\n\t\t}\n\n\t}\n\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Sub\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan=new Scanner(System.in);\n\t\tint noOfPairs=scan.nextInt();\n\t\twhile(noOfPairs-->0)\n\t\t{\n\t\t\tint x=scan.nextInt();\n\t\t\tint y=scan.nextInt();\n\t\t\tint res=0;\n\t\t\twhile(x!=0&&y!=0)\n\t\t\t{\n\t\t\t  if(x>y) \n\t\t\t   {\n\t\t\t\tres+=x/y;\n\t\t\t\tx=x%y;\n\t\t\t   }\n\t\t\t  else \n\t\t\t   {\n\t\t\t\t  res+=y/x;\n\t\t\t\t  y=y%x;\n\t\t\t   }\n\t\t\t}\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\tscan.close();\n\t}\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Subtractions {\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 t=s.nextInt();\n\t\twhile(t--!=0){\n\t\t\tint a=s.nextInt();\n\t\t\tint b=s.nextInt();\n\t\t\tint min=Math.min(a, b);\n\t\t\tint max=Math.max(a, b);\n\t\t\tint ops=0;\n\t\t\twhile(true){\n\t\t\t\tint quo=max/min;\n\t\t\t\tops+=quo;\n\t\t\t\tint rem=max%min;\n\t\t\t\tmax=Math.max(rem, min);\n\t\t\t\tmin=Math.min(min, rem);\n\t\t\t\tif(rem==0) break;\n\t\t\t}\n\t\t\tSystem.out.println(ops);\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "//david alexander\nimport java.util.*;\n\npublic class Subtract {\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,b;\n\t\tString answer = \"\";\n\t\twhile(n!=0){\n\t\t\ta = sc.nextInt();\n\t\t\tb = sc.nextInt();\n\t\t\tanswer += solve(a,b) + \"\\n\";\n\t\t\tn--;\n\t\t}\n\t\tSystem.out.println(answer);\n\t}\n\t\n\tpublic static int solve(int a, int b){\n\t\tint count = 0;\n\t\tint div;\n\t\tint mod;\n\t\twhile(true){\n\t\t\tif(a >= b){\n\t\t\t\tdiv = a/b;\n\t\t\t\tmod = a%b;\n\t\t\t\tcount += div;\n\t\t\t\tif(mod==0){\n\t\t\t\t\treturn count;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\ta = mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tdiv = b/a;\n\t\t\t\tmod = b%a;\n\t\t\t\tcount += div;\n\t\t\t\tif(mod==0){\n\t\t\t\t\treturn count;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tb = mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tScanner cin = new Scanner(System.in);\n\t\t\n\t\tint t, n, m;\n\t\t\n\t\tt = cin.nextInt();\n\t\t\n\t\twhile(t > 0) {\n\t\t\tt--;\n\t\t\tint sum = 0;\n\t\t\tn = cin.nextInt();\n\t\t\tm = cin.nextInt();\n\t\t\twhile(n > 0 && m > 0) {\n\t\t\t\tif(n < m) {\n\t\t\t\t\tint k = n;\n\t\t\t\t\tn = m;\n\t\t\t\t\tm = k;\n\t\t\t\t}\n\t\t\t\tsum += n / m; n %= m;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n\n}\n\n   \t  \t\t\t \t\t \t \t\t\t  \t\t\t\t", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "/*\n(7 10)  1 2 3\n(3, 7)\n(1, 3)\n\n(3, 7)\n(3, 4)\n(3, 1)\n(2, 1)\n(1, 1)\n1\n\n*/\nimport java.util.*;\npublic class CodeForcesW8P2 {\n\n    public static void main(String [] args){\n        Scanner sc = new Scanner(System.in);\n\n        int tests = Integer.valueOf(sc.nextLine());\n\n\n        while(tests > 0){\n            int count = 0;\n            String [] input = sc.nextLine().split(\" \");\n            int x = Integer.valueOf(input[0]);\n            int y = Integer.valueOf(input[1]);\n\n\n            if (x == y){\n                count += 1;\n            }\n            else {\n                if (x > y){\n                    int temp = x;\n                    x = y;\n                    y = temp;\n                }\n                /*\n                    (4, 17) 4 + 4\n                    (1, 4)\n\n                    (4, 16) 4\n                    (4, 12)\n                    (4, 8)\n                    (4, 4)\n\n                */\n                while (x != 1 && x != 0 && y != 1){\n                    count += (y / x);\n                    int temp = x;\n                    x = (y % x);\n                    y = temp;\n                }\n                if (x != 0)\n                    count += y;\n\n\n            }\n\n\n\n            System.out.println(count);\n            tests --;\n        }\n\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n \npublic class Solution {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        s.nextLine();\n        while(s.hasNext()) {\n            int first = s.nextInt();\n            int second = s.nextInt();\n            System.out.println(calculate(first,second));\n        }\n    }\n    \n    public static int calculate(int first, int second) {\n        int operations = 0;\n        while(first != 0 && second != 0) {\n            int temp;\n            if(first < second) {\n                temp = second/first;\n                operations += temp;\n                second -= (first*temp);\n            }\n            else {\n                temp = first/second;\n                operations += temp;\n                first -= (second*temp);\n            }\n        }\n        return operations;\n    }\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "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 */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int t = in.readInt();\n            while (t-- > 0) {\n                int[] a = new int[]{in.readInt(), in.readInt()};\n                Arrays.sort(a);\n                int ans = 0;\n                while (a[0] > 0) {\n                    int x = a[1] / a[0];\n                    ans += x;\n                    a[1] -= a[0] * x;\n                    Arrays.sort(a);\n                }\n                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        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", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class sub {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint num = in.nextInt();\n\t\twhile(num-->0) {\n\t\t\tint a = in.nextInt();\n\t\t\tint b = in.nextInt();\n\n\t\t\tint res = 0;\n\n\t\t\twhile(a!=0 && b!=0) {\n\t\t\t\tif(a>=b) {\n\t\t\t\t\tres += a/b;\n\t\t\t\t\ta %= b;\n\t\t\t\t} else {\n\t\t\t\t\tres += b/a;\n\t\t\t\t\tb %= a;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(res);\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Subtractions {\n\t\n\t\n\t\n\t\n\tpublic static void main(String[]args){\n\t\tScanner sc=new Scanner(System.in);\n\t\tint test=sc.nextInt();\n\t\twhile(test-->0){\n\t\t\tlong a=sc.nextLong();\n\t\t\tlong b=sc.nextLong();\n\t\t\tlong count=0;\n\t\t\tlong cnt=0;\n\t\t\twhile(a>0&&b>0){\n\t\t\t\tcount=0;\n\t\t\t\t//System.out.println(a+\" \"+b);\n\t\t\tif(a>b){\n\t\t\tcount+=(a-b)/b;\n\t\t\tif(count!=0){\n\t\t\tcnt+=count;\n\t\t\ta-=b*count;}\n\t\t\telse {\n\t\t\t\tcnt++;\n\t\t\t\ta-=b;\n\t\t\t}\n\t\t\t}\n\t\t\telse{ \n\t\t\t\tcount+=(b-a)/a;\n\t\t\t\tif(count!=0){\n\t\t\t\tcnt+=count;\n\t\t\tb-=a*count;}\n\t\t\t\telse {\n\t\t\t\t\tcnt++;\n\t\t\t\t\tb-=a;\n\t\t\t\t}\n\t\t\t}\n\t\t\t}\n\t\tSystem.out.println(cnt);\n\t\t}\n\t\t\n\t\t\n\t\t\n\t}\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class StrangeAddition {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tsc = new StringTokenizer(br.readLine());\n\t\tint tc = nxtInt();\n\t\twhile (tc-- > 0) {\n\t\t\tint a = nxtInt();\n\t\t\tint b = nxtInt();\n\t\t\tint ans = 0;\n\t\t\twhile (a != b) {\n\t\t\t\tif (a == 0 || b == 0)\n\t\t\t\t\tbreak;\n\t\t\t\tif (a > b) {\n\t\t\t\t\tint div = a / b;\n\t\t\t\t\ta -= b * div;\n\t\t\t\t\tans += div;\n\t\t\t\t} else {\n\t\t\t\t\tint div = b / a;\n\t\t\t\t\tb -= a * div;\n\t\t\t\t\tans += div;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans + (a == b ? 1 : 0));\n\t\t}\n\t\tbr.close();\n\t\tout.close();\n\t}\n\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\n\tstatic StringTokenizer sc;\n\n\tstatic String nxtTok() throws IOException {\n\t\twhile (!sc.hasMoreTokens()) {\n\t\t\tString s = br.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn null;\n\t\t\tsc = new StringTokenizer(s.trim());\n\t\t}\n\t\treturn sc.nextToken();\n\t}\n\n\tstatic int nxtInt() throws IOException {\n\t\treturn Integer.parseInt(nxtTok());\n\t}\n\n\tstatic long nxtLng() throws IOException {\n\t\treturn Long.parseLong(nxtTok());\n\t}\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Subtractions {\n\n    public static void main(String args[]) {\n        Scanner scan = new Scanner(System.in);\n        int t = scan.nextInt();\n        while (t-- > 0) {\n            int a = scan.nextInt();\n            int b = scan.nextInt();\n            int res = 0;\n            while (a != 0 && b != 0) {\n                if (a > b) {\n                    res += (a / b);\n                    a %= b;\n                } else {\n                    res += (b / a);\n                    b %= a;\n                }\n            }\n            System.out.println(res);\n\n        }\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "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 John Martin\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        ASubtractions solver = new ASubtractions();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ASubtractions {\n        public void solve(int testNumber, InputReader c, OutputWriter w) {\n            int tc = c.readInt();\n            while (tc-- > 0) {\n                int a = c.readInt(), b = c.readInt();\n                int res = 0;\n                while (a != 0 && b != 0) {\n                    res += b / a;\n                    b = b % a;\n                    int t = b;\n                    b = a;\n                    a = t;\n                }\n                w.printLine(res);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                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 close() {\n            writer.close();\n        }\n\n        public void printLine(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "//package Demo;\n\n//import java.io.Console;\nimport java.util.Scanner;\n\n//import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;\n\npublic class Main {\n\n    /**\n     * @param args\n     */ \n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        Scanner scanner = new Scanner(System.in);\n        int T = scanner.nextInt();\n        while(T-->0){\n            int m , n , count=0;\n            m = scanner.nextInt();\n            n = scanner.nextInt();\n            while(m!=0&&n!=0){\n                int tmp;\n                if(m<n) {\n                    tmp = n;\n                    n = m;\n                    m = tmp;\n                }\n                count+=m/n;\n                m = m%n;\n            } \n            if(T!=0)System.out.println(count);\n            else System.out.print(count);\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Subtractions\n{\n\t\n\t\n\t/************************ SOLUTION STARTS HERE ***********************/\n\t\n\tstatic long modifiedEuclidGCD(int a , int b) {\n\t\treturn b == 0 ? 0 : (a / b) + modifiedEuclidGCD(b, a % b);\n\t}\n\t\n\tprivate static void solve(FastScanner s1, PrintWriter out){\n\t\t\n\t\tint T = s1.nextInt();\n\t\twhile(T-->0)\n\t\t\tout.println(modifiedEuclidGCD(s1.nextInt(), s1.nextInt()));\n\t\t\n\t}\n\t\n\t\n\t\n\t/************************ SOLUTION ENDS HERE ************************/\n\t\n\t\n\t\n\t\n\t\n\t/************************ TEMPLATE STARTS HERE *********************/\n\t\n\tpublic static void main(String []args) throws IOException {\n\t\tFastScanner in  = new FastScanner(System.in);\n\t\tPrintWriter out = \n\t\t\t\tnew PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); \n\t\tsolve(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}    \n\t\n\tstatic class FastScanner{\n\t\tBufferedReader reader;\n\t\tStringTokenizer st;\n\t\tFastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}\t\n\t\tString next()\n\t\t{while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}\t\t    \n\t\tst = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}\n\t\tString nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}\t    \t  \t\n\t\tint    nextInt()   {return Integer.parseInt(next());}\n\t\tlong   nextLong()  {return Long.parseLong(next());}\t\t\n\t\tdouble nextDouble(){return Double.parseDouble(next());}\n\t\tchar   nextChar()  {return next().charAt(0);}\n\t\tint[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}\n\t\tlong[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}\t\n\t\tint[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}\t    \t\n\t\tlong[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}\t    \t\n\t\tvoid   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}\t\t\t\t\n\t}\n\t\n\t/************************ TEMPLATE ENDS HERE ************************/\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static int gcd(int a , int b) {\n\t\tif (b == 0) return 0;\n\t\telse {\n\t\t\treturn a / b + gcd (b , a % b);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner (System.in);\n\t\tint testCase = sc.nextInt();\n\n\t\twhile (testCase-- > 0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint m = sc.nextInt();\n\t\t\tif (n < m) {\n\t\t\t\tint temp = n;\n\t\t\t\tn = m;\n\t\t\t\tm = temp;\n\t\t\t}\t\n\n\t\t\tint ans = gcd (n , m);\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tlong f(int x, int y) {\n\t\tif (x == 0 || y == 0)\n\t\t\treturn 0;\n\t\tif (x >= y) {\n\t\t\treturn x / y + f(y, x % y);\n\t\t} else {\n\t\t\treturn y / x + f(x, y % x);\n\t\t}\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\tint t = nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint a = nextInt();\n\t\t\tint b = nextInt();\n\t\t\tout.println(f(a, b));\n\t\t}\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}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "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;\n\npublic class Task267A {\n\n\tpublic static void main(String... args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tSolution.main(System.in, System.out);\n\t}\n\n\tstatic class Scanner {\n\n\t\tprivate final BufferedReader br;\n\t\tprivate String[] cache;\n\t\tprivate int cacheIndex;\n\n\t\tScanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t\tcache = new String[0];\n\t\t\tcacheIndex = 0;\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn Integer.parseInt(cache[cacheIndex++]);\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn cache[cacheIndex++];\n\t\t}\n\n\t\tvoid close() throws IOException {\n\t\t\tbr.close();\n\t\t}\n\n\t}\n\n\tstatic class Solution {\n\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 sc = new Scanner(is);\n\n\t\t\tint n = sc.nextInt();\n\n\t\t\twhile (n-- > 0) {\n\t\t\t\tint ai = sc.nextInt();\n\t\t\t\tint bi = sc.nextInt();\n\t\t\t\tint retVal = 0;\n\n\t\t\t\twhile (ai > 0 && bi > 0) {\n\t\t\t\t\tif (ai > bi) {\n\t\t\t\t\t\tretVal += ai / bi;\n\t\t\t\t\t\tai = ai % bi;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tretVal += bi / ai;\n\t\t\t\t\t\tbi = bi % ai;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpw.println(retVal);\n\t\t\t}\n\n\t\t\tpw.flush();\n\t\t\tsc.close();\n\t\t}\n\t}\n\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\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 a, b, min, max, result = 0, temp;\n\t\twhile(n-->0){\n\t\t\ta = sc.nextInt();\n\t\t\tb = sc.nextInt();\n\t\t\tmax = Math.max(a, b);\n\t\t\tmin = Math.min(a, b);\n\t\t\tresult = 0;\n\t\t\twhile(true){\n\t\t\t\tresult += max/min;\n\t\t\t\tif(max%min == 0){\n\t\t\t\t\tSystem.out.println(result);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t/* take the min and the remainder as the previous min. */\n\t\t\t\ttemp = max;\n\t\t\t\tmax = min;\n\t\t\t\tmin = temp%min;\n\t\t\t}\n\t\t}\n\t\tsc.close();\n\t}\n\t\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tScanner cin = new Scanner(System.in);\n\t\t\n\t\tint t, n, m;\n\t\t\n\t\tt = cin.nextInt();\n\t\t\n\t\twhile(t > 0) {\n\t\t\tt--;\n\t\t\tint sum = 0;\n\t\t\tn = cin.nextInt();\n\t\t\tm = cin.nextInt();\n\t\t\twhile(n > 0 && m > 0) {\n\t\t\t\tif(n < m) {\n\t\t\t\t\tint k = n;\n\t\t\t\t\tn = m;\n\t\t\t\t\tm = k;\n\t\t\t\t}\n\t\t\t\tsum += n / m; n %= m;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n\n}\n\t \t\t   \t   \t  \t\t\t \t \t    \t", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Subtractions {\n    public static void main(String[] args) {\n        InputReader r = new InputReader(System.in);\n        int n = r.nextInt();\n        while (n-- > 0) {\n            int a = r.nextInt();\n            int b = r.nextInt();\n            int res = 0;\n            while (a > 0 && b > 0) {\n                if (a > b) {\n                    int div = a / b;\n                    a -= div * b;\n                    res += div;\n                } else {\n                    int div = b / a;\n                    b -= div * a;\n                    res += div;\n                }\n            }\n            System.out.println(res);\n        }\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException e) {\n                // TODO Auto-generated catch block\n                e.printStackTrace();\n                return null;\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        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        s.nextLine();\n        while(s.hasNext()) {\n            int first = s.nextInt();\n            int second = s.nextInt();\n            System.out.println(calculate(first,second));\n        }\n    }\n    \n    public static int calculate(int first, int second) {\n        int operations = 0;\n        while(first != 0 && second != 0) {\n            int temp;\n            if(first < second) {\n                temp = second/first;\n                operations += temp;\n                second -= (first*temp);\n            }\n            else {\n                temp = first/second;\n                operations += temp;\n                first -= (second*temp);\n            }\n        }\n        return operations;\n    }\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class ATestingRound5 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint T = in.nextInt();\n\t\twhile(T --> 0) {\n\t\t\tint a = in.nextInt();\n\t\t\tint b = in.nextInt();\n\t\t\tint count = 0;\n\t\t\t\n\t\t\tint[] arr = {a, b};\n\t\t\tArrays.sort(arr);\n\t\t\twhile(arr[0] != 0) {\n\t\t\t\tcount += arr[1] / arr[0];\n\t\t\t\tarr[1] = arr[1] % arr[0];\n\t\t\t\t\n\t\t\t\tArrays.sort(arr);\n\t\t\t}\n\t\t\tSystem.out.println(count);\n\t\t}\n\t\tin.close();\n\t}\n\n}\n/*\n2\n4 17\n7 987654321\noutputCopy\n8\n141093479\n*/", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "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 Rb_wahid\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        ASubtractions solver = new ASubtractions();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ASubtractions {\n        int sub(int a, int b) {\n            if (a % b == 0)\n                return a / b;\n            else return a / b + sub(b, a % b);\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int t = in.nextInt();\n            int a, b;\n\n            while (t-- > 0) {\n                a = in.nextInt();\n                b = in.nextInt();\n\n                out.println(sub(a, b));\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void println(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\twhile (n-- > 0) {\n\t\t\tint a = in.nextInt();\n\t\t\tint b = in.nextInt();\n\t\t\tint k = 0;\n\t\t\twhile (a != 0 && b != 0) {\n\t\t\t\tif (a > b) {\n\t\t\t\t\tint t = a / b;\n\t\t\t\t\tk += t;\n\t\t\t\t\ta = a - b * t;\n\t\t\t\t} else {\n\t\t\t\t\tint t = b / a;\n\t\t\t\t\tk += t;\n\t\t\t\t\tb = b - a * t;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(k);\n\t\t}\n\n\t}\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "/*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 t=in.nextInt();\n\t\twhile(t--!=0)\n\t\t{\n\t\t    int a=in.nextInt();\n\t\t    int b=in.nextInt();\n\t\t    int min=Math.min(a,b);\n\t\t    int max=Math.max(a,b);\n\t\t    int res=0;\n\t\t    while(min!=0)\n\t\t    {\n\t\t        res=res+max/min;\n\t\t        int temp=min;\n\t\t        min=max%min;\n\t\t        max=temp;\n\t\t    }\n\t\t    System.out.println(res);\n\t\t}\n\t}\n\t\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "/*Talent is something you make bloom , instinct is something you polish*/\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\npublic class Main\n{\n    static long mod=((long)1e9)+7;//toString\n    public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}\n    public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1;x =(x * x)%mod;}return res;}\n    public static int lower_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo+1)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid-1;}else lo=mid;}if(arr[lo]<=val)return lo;else return -1;}\n    public static int upper_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid;;}else lo=mid+1;}if(arr[lo]>=val)return lo;else return -1;}\n    \n    public static void main (String[] args) throws java.lang.Exception\n    {\n        Reader sn = new Reader();\n        Print p = new Print();\n        int n = sn.nextInt();\n        while((n--) > 0){\n             int a = sn.nextInt();\n             int b = sn.nextInt();\n             int small = Math.min(a , b);\n             int large = Math.max(a , b);\n             long steps = 0;\n             while(small != 0){\n                  steps += (long)(large/small);\n                  int large1 = small;\n                  small = large % small;\n                  large = large1;\n             }\n             p.printLine(Long.toString(steps));\n        }\n        p.close();\n    }\n}\nclass Pair implements Comparable<Pair> {\n\t\tint val;\n\t\tint in;\n\t\tPair(int a, int b){\n\t\t\tval=a;\n\t        in=b;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(val==o.val)\n\t\t\treturn Integer.compare(in,o.in);\n\t\t\telse\n\t\t\treturn Integer.compare(val,o.val);\n\t\t}}\nclass Reader\n    {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n        public boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; }\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 String readWord()throws IOException\n        {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) c = read();        \n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t    } \n\t\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    }\nclass Print\n{\n    private final BufferedWriter bw;\n    public Print()\n    {\n        bw=new BufferedWriter(new OutputStreamWriter(System.out));\n    }\n    public void print(String str)throws IOException\n    {\n        bw.append(str);\n    }\n    public void printLine(String str)throws IOException\n    {\n        print(str);\n        bw.append(\"\\n\");\n    }\n    public void close()throws IOException\n    {\n        bw.close();\n    }}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class substraction {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc=new Scanner(System.in);\n\t\tint t=sc.nextInt();\n\t\twhile (t>0) {\n\t\t\tlong a=sc.nextLong();\n\t\t\tlong b=sc.nextLong();\n\t\t\tint op=0;\n\t\t\tif (a>b) {\n\t\t\t\twhile (a%b!=0) {\n\t\t\t\t\top+=a/b;\n\t\t\t\t\ta=a%b;\n\t\t\t\t\tlong c=b;\n\t\t\t\t\tb=a;\n\t\t\t\t\ta=c;\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\top+=a/b;\n\t\t\t}\n\t\t\telse{\n\t\t\t\twhile (b%a!=0) {\n\t\t\t\t\top+=b/a;\n\t\t\t\t\tb=b%a;\n\t\t\t\t\tlong c=a;\n\t\t\t\t\ta=b;\n\t\t\t\t\tb=c;\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\top+=b/a;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tSystem.out.println(op);\n\t\t\tt--;\n\t\t}\n\n\t}\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Subtractions {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\n\t\tint tests = scan.nextInt();\n\n\t\twhile (tests > 0) {\n\n\t\t\ttests--;\n\n\t\t\tint first = scan.nextInt();\n\t\t\tint second = scan.nextInt();\n\n\t\t\tint count = 0;\n\t\t\twhile (first > 0 && second > 0) {\n\t\t\t\t\n\t\t\t\tif (first < second) {\n\n\t\t\t\t\tcount += second / first;\n\t\t\t\t\tsecond = second % first;\n\t\t\t\t} else {\n\t\t\t\t\t\n\t\t\t\t\tcount += first / second;\n\t\t\t\t\tfirst = first % second;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(count);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class subtractionn {\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 t;\n\t\tt=in.nextInt();\n\t\twhile(t!=0)\n\t\t{\n\t\t\tint a=in.nextInt();\n\t\t\tint b=in.nextInt();\n\t\t\tint total=0,neww=0;\n\t\t\tif(a%b==0)\n\t\t\t{\n\t\t\t\tSystem.out.println(a/b);\n\t\t\t}\n\t\t\telse if(b%a==0)\n\t\t\t{\n\t\t\t\tSystem.out.println(b/a);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\twhile(a!=0 && b!=0)\n\t\t\t{\n\t\t\t\tif(a>b)\n\t\t\t\t{\n\t\t\t\t\ttotal=total+(a/b);\n\t\t\t\t\ta=a%b;\n\t\t\t\t\tif(a==0)\n\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\telse if(b>a)\n\t\t\t\t{\n\t\t\t\t\ttotal=total+(b/a);\n\t\t\t\t\tb=b%a;\n\t\t\t\t\tif(b==0)\n\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\telse\n\t\t\t\t{\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(total);\n\t\t\t}\n\t\tt--;\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "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 John Martin\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        ASubtractions solver = new ASubtractions();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class ASubtractions {\n        public void solve(int testNumber, InputReader c, OutputWriter w) {\n            int tc = c.readInt();\n            while (tc-- > 0) {\n                int a = c.readInt(), b = c.readInt();\n                int op = 0;\n                while (a != b) {\n                    if (a > b) {\n                        int tm = b;\n                        b = a;\n                        a = tm;\n                    }\n                    int left = b - a;\n                    int rem = (left - 1) / a + 1;\n                    b -= rem * a;\n                    op += rem;\n                }\n                op++;\n                w.printLine(op);\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 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", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "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      int n=sc.nextInt();\n      while(n-->0)\n      {\n          int a=sc.nextInt();\n          int b=sc.nextInt();\n          int ans=f(a,b);\n          System.out.println(ans);\n      }\n     }\n     public static int f(int a,int b)\n     {\n         if(a==0||b==0)\n           return 0;\n         if(a>b)\n         {\n             return a/b + f(b,a%b);\n         }\n         else\n             return b/a + f(a,b%a);\n     }\n}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.awt.*;\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 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 = readInt();\n\t\twhile(qq-- > 0)\t{\n\t\t\tpw.println(solve(readInt(), readInt()));\n\t\t}\n\t\tpw.close();\n\t}\n\n\tpublic static int solve(int a, int b)\t{\n\t\tif(a < b)\t{\n\t\t\treturn solve(b,a);\n\t\t}\n\t\tif(a%b == 0)\t{\n\t\t\treturn a / b;\n\t\t}\n\t\treturn a/b + solve(b,a%b);\n\t}\n\t\n\t/* NOTEBOOK CODE */\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}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class subtractions {\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        int n=sc.nextInt();\n        \n        while(n-->0){\n            int a=sc.nextInt();\n            int b=sc.nextInt();\n            \n            int c=0;\n            while(a!=0 && b!=0){\n                if(a>b){\n                    int t=a;\n                    a=b;\n                    b=t;\n                }\n                c+=b/a;\n                b=b%a;\n            }\n            System.out.println(c);\n        }\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "\n// @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 int sub(int a, int b) {\n        int res = 0;\n        while (b > 0) {\n            res += a / b;\n            int m = a % b;\n            a = b;\n            b = m;\n        }\n        return res;\n    }\n\n    public void solve() throws Exception {\n        int n = nextInt();\n        while (n-- > 0) {\n            out.println(sub(nextInt(), nextInt()));\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Template().run();\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic final class Subtractions\n{\n    public static void main(String[] args)\n    {\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\t\tSolver solver = new Solver(in, out);\n\n\t\tsolver.solve();\n        in.close();\n        out.flush();\n        out.close();\n    }\n\n    static class Solver\n    {\n        int n;\n        InputReader in;\n        PrintWriter out;\n\n\t\tvoid solve()\n\t\t{\n\t\t\tn = in.nextInt();\n\n\t\t\twhile (n-- > 0)\n\t\t\t{\n\t\t\t\tint a, b;\n\n\t\t\t\ta = in.nextInt();\n\t\t\t\tb = in.nextInt();\n\n\t\t\t\tint cnt = 0;\n\n\t\t\t\twhile (a > 0 && b > 0)\n\t\t\t\t{\n\t\t\t\t\tif (a < b)\n\t\t\t\t\t\ta = swap(b, b = a);\n\n\t\t\t\t\tcnt += a / b;\n\t\t\t\t\ta -= b * (a / b);\n\t\t\t\t}\n\n\t\t\t\tout.println(cnt);\n\t\t\t}\n\t\t}\n\n\t\tint swap(int a, int b)\n\t\t{\n\t\t\treturn a;\n\t\t}\n\n        public Solver(InputReader in, PrintWriter out)\n        {\n        \tthis.in = in;\n        \tthis.out = out;\n        }\n\n\t}\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\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                } 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        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\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        public boolean isSpaceChar(int c)\n        {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public void close()\n        {\n            try\n            {\n                stream.close();\n            } catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n        }\n\n    }\n\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic final class subtractions\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\tstatic long solve(long a,long b)\n\t{\n\t\tif(a<=0 || b<=0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong max=Math.max(a,b),min=Math.min(a,b);\n\t\t\tlong low=1,high=(long)(1e9);\n\t\t\twhile(low<high)\n\t\t\t{\n\t\t\t\tlong mid=(low+high)>>1,val=(min*mid),curr=max-val;\n\t\t\t\tif(curr<min)\n\t\t\t\t{\n\t\t\t\t\thigh=mid;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlow=mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn low+solve(min,max-(low*min));\n\t\t}\n\t}\n\t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tint t=sc.nextInt();\n\t\twhile(t>0)\n\t\t{\n\t\t\tlong a=sc.nextLong(),b=sc.nextLong();\n\t\t\tout.println(solve(a,b));\n\t\t\tt--;\n\t\t}\n\t\tout.close();\n\t}\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}", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t    Scanner sc=new Scanner(System.in);\n\t    int n=sc.nextInt();\n\t    while(n-->0){\n\t        long a=sc.nextLong(),b=sc.nextLong();\n\t        long ans=0,cur=0;\n\t        while(a>0 && b>0){\n\t            if(b>a)a=a+b-(b=a);\n\t            cur=(a/b);\n\t            ans+=cur;\n\t            a-=(cur*b);\n\t        }\n\t        System.out.println(ans);\n\t    }\n\t}\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Subtractions {\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        int numberOfTests = scanner.nextInt();\n        while (numberOfTests-- > 0) {\n            int a = scanner.nextInt();\n            int b = scanner.nextInt();\n            int[] res = new int[1];\n            compute(a, b, res);\n            System.out.println(res[0]);\n        }\n    }\n\n    private static void compute(int x, int y, int[] res) {\n        if (x == 0 || y == 0) {\n            return;\n        }\n        int tmp;\n        if (x < y) {\n            tmp = x;\n            x = y;\n            y = tmp;\n        }\n        res[0] += x / y;\n        tmp = x % y;\n        if (tmp == 0) {\n            return;\n        }\n        x = y;\n        y = tmp;\n        compute(x, y, res);\n    }\n}\n", "complexity": "constant", "problem": "267_A. Subtractions", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.PrintWriter;\n\nimport java.io.InputStreamReader;\n\nimport java.io.IOException;\n\nimport java.util.StringTokenizer;\n\nimport java.util.Arrays;\n\npublic class Main {\n    \n    static Scanner in = new Scanner();\n    static PrintWriter out = new PrintWriter(System.out);\n    \n    public static void main(String[] args) throws IOException {\n        long n = in.nextLong(), m = in.nextLong();\n        out.print(m / n + (m % n == 0 ? 0 : 1));\n        out.close();\n    }\n    \n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public Scanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            st = new StringTokenizer(\"\");\n        }\n        \n        public String next() throws IOException {\n            if(!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}", "complexity": "constant", "problem": "1036_A. Function Height", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\npublic class FunctionHeight {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        long n = sc.nl();\n        long k = sc.nl();\n        long ans = (n+k-1)/n;\n        System.out.println(ans);\n    }\n\n    /////////// TEMPLATE FROM HERE /////////////////\n    private static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int ni() {\n            return Integer.parseInt(next());\n        }\n\n        float nf() {\n            return Float.parseFloat(next());\n        }\n\n        long nl() {\n            return Long.parseLong(next());\n        }\n\n        double nd() {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "constant", "problem": "1036_A. Function Height", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class A {\n    static long l, r, A, B, C;\n\n    static long GCD(long a, long b) {\n        if (b == 0)\n            return a;\n        return GCD(b, a % b);\n    }\n\n    static boolean gcd(long a, long b) {\n        return GCD(a, b) == 1;\n    }\n\n    static boolean found(long a, long b, long c) {\n        if (b <= a || c <= b)\n            return false;\n        if (a > r || b > r || c > r)\n            return false;\n        if (gcd(a, b) && gcd(b, c) && !gcd(a, c)) {\n            A = a;\n            B = b;\n            C = c;\n            return true;\n        }\n        if (found(a + 1, b + 1, c + 1))\n            return true;\n        if (found(a + 1, b, c + 1))\n            return true;\n        if (found(a + 1, b + 1, c))\n            return true;\n        if (found(a, b, c + 1))\n            return true;\n        if (found(a, b + 1, c + 1))\n            return true;\n        if (found(a, b + 1, c))\n            return true;\n        return found(a + 1, b, c);\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        l = sc.nextLong();\n        r = sc.nextLong();\n        if (found(l, l + 1, l + 2))\n            System.out.println(A + \" \" + B + \" \" + C);\n        else\n            System.out.println(-1);\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class BB {\npublic static void main(String[] args) {\n\tScanner sc=new Scanner(System.in);\n\tlong a=sc.nextLong();\n\tlong b=sc.nextLong();\n\t\n\tif(b-a>(long)2){\n\t\tif(a%(long)2==0){\n\t\t\tSystem.out.print(a+\" \"+(a+1)+\" \"+(a+2));\n\t\t\treturn;\n\t\t}else{\n\t\t\tSystem.out.print(a+1+\" \"+(a+2)+\" \"+(a+3));\n\t\t\treturn;\n\t\t}\n\t\t\n\t}else{\n\t\tif(b-a<=(long)1){\n\t\tSystem.out.println(-1);\n\t\treturn;\n\t\t}\n\t\tif(b-a==(long)2){\n\t\t\tif(a%(long)2==0){\n\t\t\t\tSystem.out.print(a+\" \"+(a+1)+\" \"+(a+2));\n\t\t\t\treturn;\n\t\t\t}else{\n\t\t\t\tSystem.out.print(-1);\n\t\t\t\treturn;\n\t\t\t}\t\n\t\t\t\n\t\t\t}\n\t}\n\n}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\n/**\n * Created by Egor on 24/10/14.\n */\npublic class TaskA {\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        String[] input = reader.readLine().split(\" \");\n\n        long l = Long.parseLong(input[0]);\n        long r = Long.parseLong(input[1]);\n        if (l % 2 == 0) {\n            if (r >= l + 2) {\n                writer.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n            } else {\n                writer.println(-1);\n            }\n        } else {\n            if (r >= l + 3) {\n                writer.println((l + 1) + \" \" + (l + 2) + \" \" + (l + 3));\n            } else {\n                writer.println(-1);\n            }\n        }\n\n        writer.close();\n    }\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class A {\n    public static void main(String[] args) {\n       \n        Scanner in = new Scanner(System.in);\n        \n        long l = in.nextLong();\n        long r = in.nextLong();\n        \n        if(r-l < 2 ){\n            System.out.println(\"-1\");\n        }\n        \n        else if(r-l == 2 && l %2 ==1){\n            System.out.println(\"-1\");\n        }\n        else{\n            \n            \n            if(l%2 == 0){\n                System.out.println(l+ \" \"+(l+1)+\" \"+(l+2));\n                \n            }\n            else{\n                System.out.println((l+1)+ \" \"+(l+2)+\" \"+(l+3));\n            }\n        }\n            \n        }\n    }\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class CodeForce275A {\n    \n    public static void main(String[] args) throws IOException {\n\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer token = new StringTokenizer(in.readLine());\n        long l = Long.parseLong(token.nextToken());\n        long r = Long.parseLong(token.nextToken());\n        \n        \n        if(r-l<2) {\n            System.out.println(-1);\n            return;\n        }\n        if(l%2==1&&r-l<3) {\n            System.out.println(-1);\n            return;\n        }\n        if(l%2==0) {\n            System.out.println(l+\" \"+(l+1)+\" \"+(l+2));\n            return;\n        }\n        if(l%2==1) {\n            System.out.println((l+1)+\" \"+(l+2)+\" \"+(l+3));\n        }\n    }\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class p481a {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        long l = sc.nextLong();\n        long r = sc.nextLong();\n        if (r - l <= 1) {\n            System.out.println(\"-1\");\n        } else if (r - l >= 3) {\n            if (l % 2 == 0) {\n                System.out.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n            } else {\n                System.out.println((l + 1) + \" \" + (l + 2) + \" \" + (l + 3));\n            }\n        } else {\n            long g1 = GCD(l, (l + 1));\n            long g2 = GCD((l + 1), (l + 2));\n            long g3 = GCD(l, r);\n            if (g1 == 1 && g2 == 1 && g3 != 1) {\n                System.out.println(l + \" \" + (l + 1) + \" \" + r);\n            } else {\n                System.out.println(\"-1\");\n            }\n        }\n    }\n\n    public static long GCD(long a, long b) {\n        if (b == 0) return a;\n        return GCD(b, a % b);\n    }\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n/**\n *\n * @author \u0442\u0430\u043d\u044f\n */\npublic class KF {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) throws IOException {\n  B jk = new B();\n    }\n}\n\n\nclass B {\n\n    PrintWriter out = new PrintWriter(System.out);\n    Scanner in = new Scanner(System.in);\n    long l = in.nextLong();\n    long r=in.nextLong();\nB(){\nif(Math.abs(r-l)>=2){\nif(l%2==0){\nout.print(l+\" \"+(l+1)+\" \"+(l+2));\n}\nelse{\nif(Math.abs(r-l)==2){\nout.print(\"-1\");\n}else{\nout.print((l+1)+\" \"+(l+2)+\" \"+(l+3));\n}\n}\n}else{\nout.print(\"-1\");\n}\nout.flush();\n}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class A{\n\tpublic static BufferedReader k;\n\tpublic static BufferedWriter z;\n\t\n\n\t\n\tpublic static void main(String [] args)throws IOException{\n\t\tk = new BufferedReader(new InputStreamReader(System.in));\n\t\tz = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\n\t\t\n\t        String[] dat = k.readLine().split(\" \");\n\n\t        long l = Long.parseLong(dat[0]);\n\t        long r = Long.parseLong(dat[1]);\n\t\t\t\n\t\t\tif(r-l<=1){\n\t\t\t\tz.write(-1+\"\\n\");\n\t\t\t}\n\t\t\telse if(r-l == 2){\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tif((l&1)!=0){\n\t\t\t\t\tz.write(-1+\"\\n\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tz.write(l+\" \"+(l+1)+\" \"+r+\"\\n\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif((l&1)==0){\n\t\t\t\t\tz.write(l+\" \"+(l+1)+\" \"+(l+2)+\"\\n\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tz.write((l+1)+\" \"+(l+2)+\" \"+(l+3)+\"\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\tz.flush();\n\n\t}\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\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.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\n\npublic class a {\n    public static class Pair implements Comparable<Pair> {\n        int f, s;\n\n        public Pair(int f, int s) {\n            this.f = f;\n            this.s = s;\n        }\n\n        @Override\n        public int compareTo(Pair o) {\n            return s - o.s;\n        }\n\n    };\n\n    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String s[] = in.readLine().split(\" \");\n        long r = Long.parseLong(s[0]);\n        long l = Long.parseLong(s[1]);\n        if (r % 2 == 0) {\n            if (l - r+1 < 3) {\n                out.println(-1);\n            } else {\n                out.println(r + \" \" + (r + 1) + \" \" + (r + 2));\n            }\n        } else {\n            if (l - r+1 < 4) {\n                out.println(-1);\n            } else {\n                out.println((r + 1) + \" \" + (r + 2) + \" \" + (r + 3));\n            }\n\n        }\n        out.close();\n\n    }\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\n\n\tpublic static class pair implements Comparable<pair>\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\tlong l = Long.parseLong(spl[0]);\n\t\tlong r = Long.parseLong(spl[1]);\n\t\tif(l+2 <= r && l%2==0)\n\t\t{\n\t\t\tSystem.out.println(l+\" \"+(l+1)+\" \"+(l+2));\n\t\t}\n\t\telse if(l+3<=r && (l+1)%2==0)\n\t\t{\n\t\t\tSystem.out.println((l+1)+\" \"+(l+2)+\" \"+(l+3));\n\t\t}\n\t\telse System.out.println(-1);\n\t}\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\n\npublic class Task483A {\n\n    public static void main(String... args) throws NumberFormatException,\n            IOException {\n        Solution.main(System.in, System.out);\n    }\n\n    static class Scanner {\n\n        private final BufferedReader br;\n        private String[] cache;\n        private int cacheIndex;\n\n        Scanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n            cache = new String[0];\n            cacheIndex = 0;\n        }\n\n        int nextInt() throws IOException {\n            if (cacheIndex >= cache.length) {\n                cache = br.readLine().split(\" \");\n                cacheIndex = 0;\n            }\n            return Integer.parseInt(cache[cacheIndex++]);\n        }\n\n        long nextLong() throws IOException {\n            if (cacheIndex >= cache.length) {\n                cache = br.readLine().split(\" \");\n                cacheIndex = 0;\n            }\n            return Long.parseLong(cache[cacheIndex++]);\n        }\n\n        String next() throws IOException {\n            if (cacheIndex >= cache.length) {\n                cache = br.readLine().split(\" \");\n                cacheIndex = 0;\n            }\n            return cache[cacheIndex++];\n        }\n\n        void close() throws IOException {\n            br.close();\n        }\n\n    }\n\n\n    static class Solution {\n\n\n        public static void main(InputStream is, OutputStream os)\n                throws NumberFormatException, IOException {\n            PrintWriter pw = new PrintWriter(os);\n            Scanner sc = new Scanner(is);\n\n            long l = sc.nextLong();\n            long r = sc.nextLong();\n\n            long interval = r-l;\n\n            if(interval == 0 || interval == 1 || (interval == 2 && l % 2 ==1 )){\n                pw.println(-1);\n            } else {\n                if(l % 2 == 1){\n                    l++;\n                }\n                pw.print(l);\n                pw.print(\" \");\n                pw.print(l+1);\n                pw.print(\" \");\n                pw.print(l+2);\n            }\n\n\n\n            pw.flush();\n            sc.close();\n        }\n    }\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class A483 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 A483(), \"\", 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(System.out);\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\tint choose(int total, int choose){\n\t    if(total < choose)\n\t        return 0;\n\t    if(choose == 0 || choose == total)\n\t        return 1;\n\t    return choose(total-1,choose-1)+choose(total-1,choose);\n\t}\n\tvoid solve() throws IOException {\n\t\tlong l = readLong();\n\t\tlong r = readLong();\n\t\tif(r-l>=3){\n\t\t\tlong c = l%2==0?l:l+1;\n\t\t\tout.println(c+\" \"+(c+1)+\" \"+ (c+2));\n\t\t}else if(r-l==2&&r%2==0){\n\t\t\tout.println(l+\" \"+(l+1)+\" \"+(l+2));\n\t\t}else{\n\t\t\tout.println(-1);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc =new Scanner (System.in);\n        long a=sc.nextLong(); long b=sc.nextLong();\n        \n        if(b-a <=1)\n        \tSystem.out.println(\"-1\");\n        else if(b-a==2 && a%2==1)\n        \tSystem.out.println(\"-1\");\n        else\n        {\n        \tif(a%2==1)\n        \t\tSystem.out.println((a+1)+\" \"+(a+2)+\" \"+(a+3));\n        \telse\n        \t\tSystem.out.println((a)+\" \"+(a+1)+\" \"+(a+2));\n        }\n        sc.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "/* 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 l= sc.nextLong();\n        long r = sc.nextLong();\n        if(l%2==0){\n            if(r>=l+2){\n                System.out.println(l + \" \" + (l+1) + \" \" + (l+2));\n            }\n            else{\n                System.out.println(-1);\n            }\n        }\n        else{\n            if(r>=l+3){\n                System.out.println((l+1) + \" \" + (l+2) + \" \" + (l+3));\n            }\n            else{\n                System.out.println(-1);\n            }\n        }\n    }\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "\nimport java.math.BigInteger;\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 Sagimbekov_MA\n */\npublic class A483 {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        BigInteger l = sc.nextBigInteger();\n        BigInteger r = sc.nextBigInteger();\n        \n        if (r.subtract(l).compareTo(new BigInteger(\"2\")) == -1) {\n            System.out.println(\"-1\");\n        } else if (r.subtract(l).compareTo(new BigInteger(\"2\")) == 0 && l.mod(new BigInteger(\"2\")) != BigInteger.ZERO) {\n            System.out.println(\"-1\");\n        } else if (l.mod(new BigInteger(\"2\")) != BigInteger.ZERO) {\n            System.out.println(l.add(BigInteger.ONE) + \" \" + l.add(BigInteger.ONE).add(BigInteger.ONE) + \" \" + l.add(BigInteger.ONE).add(BigInteger.ONE).add(BigInteger.ONE));\n        } else {\n            System.out.println(l + \" \" + l.add(BigInteger.ONE) + \" \" + l.add(BigInteger.ONE).add(BigInteger.ONE));\n        }\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n\npublic class problemA {\n    public  static long GCD(long number1, long number2) {\n        //base case\n        if(number2 == 0){\n            return number1;\n        }\n        return GCD(number2, number1%number2);\n    }\n  \n\npublic static void main(String[] args) throws NumberFormatException, IOException {\n    BufferedReader br = new BufferedReader (new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        long b =  Long.parseLong(st.nextToken());\n        long c =  Long.parseLong(st.nextToken());\n        if(c-b<2 ||((c-b==2)&& GCD(c,b)==1) ){\n            System.out.println(\"-1\");\n        }else{\n                if(b%2==0 ){\n                    System.out.println(b+\" \"+(b+1)+\" \"+(b+2));\n            }else\n                System.out.println((b+1)+\" \"+(b+2)+\" \"+(b+3));\n        \n    \n    \n}\n        \n\n        \n\n}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\n\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n\t\ttry {\n\t\t\tString[] str = reader.readLine().split(\" \");\n\t\t\tBigInteger b1 = new BigInteger(str[0]);\n\t\t\tBigInteger b2 = new BigInteger(str[1]);\n\n\t\t\tif(b2.subtract(b1).compareTo(new BigInteger(\"1\"))<1){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif(b2.subtract(b1).compareTo(new BigInteger(\"2\"))==0){\n\t\t\t\tBigInteger b = b1.add(new BigInteger(\"1\"));\n\t\t\t\tBigInteger c = b1.add(new BigInteger(\"2\"));\n\n\t\t\t\tif(!b1.gcd(c).equals(new BigInteger(\"1\"))){\n\t\t\t\t\tSystem.out.println(b1.toString()+\" \"+b.toString()+\" \"+c.toString());\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tBigInteger b = b1.add(new BigInteger(\"1\"));\n\t\t\tBigInteger c = b1.add(new BigInteger(\"2\"));\n\t\t\tBigInteger d = b1.add(new BigInteger(\"3\"));\n\n\t\t\tif(b1.remainder(new BigInteger(\"2\")).equals(new BigInteger(\"1\"))){\n\t\t\t\tSystem.out.println(b.toString()+\" \"+c.toString()+\" \"+d.toString());\n\t\t\t}else{\n\t\t\t\tSystem.out.println(b1.toString()+\" \"+b.toString()+\" \"+c.toString());\n\t\t\t}\n\n\t\t} catch (IOException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\n\t}\n}\n\t \t\t \t\t\t     \t   \t \t\t\t       \t\t", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class dwl {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tString[] lr = sc.nextLine().split(\" \");\n\t\tlong l = Long.valueOf(lr[0]);\n\t\tlong r = Long.valueOf(lr[1]);\n\n\t\tif (r - l <= 1 || (l == 1 && (r - l) == 2)\n\t\t\t\t|| (l % 2 != 0 && (r - l) < 3))\n\t\t\tSystem.out.println(-1);\n\t\telse {\n\t\t\tif (l == 1)\n\t\t\t\tSystem.out.println(2 + \" \" + 3 + \" \" + 4);\n\t\t\telse {\n\t\t\t\tif (l % 2 == 0) {\n\t\t\t\t\tString res = \"\";\n\t\t\t\t\tres += l + \" \";\n\t\t\t\t\tres += (l + 1) + \" \";\n\t\t\t\t\tres += (l + 2) + \" \";\n\t\t\t\t\tres = res.trim();\n\t\t\t\t\tSystem.out.println(res);\n\t\t\t\t} else {\n\t\t\t\t\tString res = \"\";\n\t\t\t\t\tres += (l + 1) + \" \";\n\t\t\t\t\tres += (l + 2) + \" \";\n\t\t\t\t\tres += (l + 3) + \" \";\n\t\t\t\t\tres = res.trim();\n\t\t\t\t\tSystem.out.println(res);\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n    public static void main(String[] args) {\n        InputScanner scanner = new InputScanner();\n        try {\n            long l = scanner.nextLong();\n            long r = scanner.nextLong();\n            if ((r - l) < 2) {\n                System.out.println(\"-1\");\n                return;\n            }\n\n            if (l % 2 == 0) {\n                long a = l;\n                long b = l + 1;\n                long c = l + 2;\n                System.out.println(a + \" \" + b + \" \" + c);\n            } else if (r%2==0){\n                long a = r;\n                long b = r-1;\n                long c = r-2;\n                System.out.println(c + \" \" + b + \" \" + a);\n            } else {\n                l++;\n                if ((r - l) < 2) {\n                    System.out.println(\"-1\");\n                    return;\n                }\n                long a = l;\n                long b = l + 1;\n                long c = l + 2;\n                System.out.println(a + \" \" + b + \" \" + c);\n            }\n        } catch (IOException e) {\n\n        }\n\n\n    }\n\n    static class InputScanner {\n\n        BufferedReader br;\n        StringTokenizer st;\n\n        public InputScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public String next() throws IOException {\n            if (st == null || !st.hasMoreTokens()) {\n                String line = br.readLine();\n                st = new StringTokenizer(line);\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() throws IOException {\n            String next = next();\n            next.length();\n            return Integer.parseInt(next);\n        }\n\n        public long nextLong() throws IOException {\n            String next = next();\n            next.length();\n            return Long.parseLong(next);\n        }\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "\nimport 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 l = sc.nextLong(), r = sc.nextLong();\n\t\tif (l % 2 == 0 && r - l >= 2) {\n\t\t\tSystem.out.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n\t\t} else if (l % 2 == 1 && r - l >= 3) {\n\t\t\tSystem.out.println(l + 1 + \" \" + (l + 2) + \" \" + (l + 3));\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic final class b1 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner datain = new Scanner(System.in);\n\t\tlong l=datain.nextLong();\n\t\tlong r=datain.nextLong();\n\t\tif(r-l<2){System.out.print(-1);}else{\n\t\t\tif(((r-l)==2)&&(l%2==1)){System.out.print(-1);}else{\n\t\t\t\tif((l%2)==0){System.out.print(\"\"+l+\" \"+(l+1)+\" \"+(l+2));}else{\n\t\t\t\t\tSystem.out.print(\"\"+(l+1)+\" \"+(l+2)+\" \"+(l+3));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n\npublic class C {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer tokenizer=  new StringTokenizer(br.readLine());\n\t\tBigInteger left = new BigInteger(tokenizer.nextToken());\n\t\tBigInteger right= new BigInteger(tokenizer.nextToken());\n\t\tBigInteger val= (right.subtract(left)).add(new BigInteger(\"\"+1));\n\t\tif(val.intValue()<3){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t\t\n\t\t}\n\n\n\t\tBigInteger a, b, c;\n\t\tBigInteger i=left;\n\t\twhile(i.intValue()<=right.intValue()){\n\t\t\tBigInteger temp1=i;  //a\n\t\t\tBigInteger temp2= i.add(new BigInteger(\"\"+1));//b\n\t\t\tBigInteger j=temp2.add(new BigInteger(\"\"+1));\n\t\t\twhile(j.intValue()<=right.intValue()){\n\t\t\t\tBigInteger b1= temp2;\n\t\t\t\tBigInteger b2 =j;\n\t\t\t\tBigInteger b3 = temp1;\n\t\t\t\tBigInteger gcd= b1.gcd(b2);\n\t\t\t\tif(gcd.intValue()==1){\n\t\t\t\t\tBigInteger gcd2 =b2.gcd(b3);\n\t\t\t\t\tif(gcd2.intValue() !=1){\n\t\t\t\t\t\ta=b3;\n\t\t\t\t\t\tb= b1;\n\t\t\t\t\t\tc= b2;\n\t\t\t\t\t\tSystem.out.print(a+\" \"+b+\" \"+c+\" \");\n\t\t\t\t\t\tSystem.out.println();\n\t\t\t\t\t\treturn ;\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t\tj=j.add(new BigInteger(\"\"+1));\n\t\t\t}\n\t\t\ti=i.add(new BigInteger(\"\"+1));\n\n\t\t}\n\t\tSystem.out.println(-1);\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "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        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n        Scanner t=new Scanner(System.in);\n        long l=t.nextLong();\n        long r=t.nextLong();\n        if(r-l<2) System.out.println(-1);\n        else if(r-l<3 && l%2!=0){\n            if(l%3!=0) System.out.println(-1);\n            else if ((l+3)%2==0) System.out.println(-1);\n                else System.out.println(l+\" \"+(l+1)+\" \"+(l+3));\n        } else{\n            while (l%2!=0) l++;\n            System.out.println(l+\" \"+(l+1)+\" \"+(l+2));\n        }\n    }\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileNotFoundException;\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.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.Locale;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class A {\n\tstatic String file = \"\";\n\tstatic BufferedReader br;\n\tstatic PrintWriter pw;\n\tstatic StringTokenizer st;\n\n\tpublic static void main(String[] args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tLocale.setDefault(Locale.US);\n\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\tlong a = nextLong();\n\t\tlong b = nextLong();\n\t\tif (a % 2 == 1 && b - a == 2 || b - a == 1 || a == b) {\n\t\t\tpw.print(-1);\n\t\t} else {\n\t\t\tif (a % 2 == 1)\n\t\t\t\ta++;\n\t\t\tpw.print(a + \" \" + (a + 1) + \" \" + (a + 2));\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static double yuza(double x1, double y1, double x2, double y2,\n\t\t\tdouble x3, double y3) {\n\t\treturn (x1 * (y3 - y2) + x2 * (y1 - y3) + x3 * (y2 - y1));\n\t}\n\n\tprivate static void ffile() throws IOException {\n\t\tbr = new BufferedReader(new FileReader(file + \"in\"));\n\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(file + \"out\")));\n\t}\n\n\tprivate static int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate static long nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate static double nextDouble() throws NumberFormatException,\n\t\t\tIOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tprivate static String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "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        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        long l = in.nextLong();\n        long r = in.nextLong();\n        int max = (int) (r - l);\n        if (max >= 2) {\n            if ((l & 1) == 0) {\n                out.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n                return;\n            } else {\n                if (max >= 3) {\n                    out.println((l + 1) + \" \" + (l + 2) + \" \" + (l + 3));\n                    return;\n                }\n            }\n        }\n        out.println(-1);\n    }\n}\n\nclass InputReader {\n    public BufferedReader reader;\n    public StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream), 32768);\n        tokenizer = null;\n        tokenizer = null;\n    }\n\n    public String next() {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            try {\n                tokenizer = new StringTokenizer(reader.readLine());\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return tokenizer.nextToken();\n    }\n\n    public long nextLong() {\n        return Long.parseLong(next());\n    }\n\n}\n\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "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.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.concurrent.LinkedBlockingDeque;\n\nimport javax.swing.border.Border;\n\npublic class a {\n\n\tpublic static long mod = (long) Math.pow(10, 9) + 7;\n\n\tprivate static class node implements Comparable<node> {\n\t\tint x;\n\t\tint y;\n\n\t\tnode(int x, int c) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = c;\n\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(node o) {\n\t\t\tif (o.x < x)\n\t\t\t\treturn 1;\n\t\t\telse if (o.x > x)\n\t\t\t\treturn -1;\n\t\t\telse if (o.y < y)\n\t\t\t\treturn 1;\n\t\t\telse if (o.y > y)\n\t\t\t\treturn -1;\n\t\t\telse\n\t\t\t\treturn 0;\n\t\t}\n\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0)\n\t\t\treturn a;\n\n\t\telse\n\t\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringBuilder qq = new StringBuilder();\n\t\tPrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\n\t\t// int n = Integer.parseInt(in.readLine());\n\t\tString y[] = in.readLine().split(\" \");\n\t\tlong n = Long.parseLong(y[0]);\n\t\tlong m = Long.parseLong(y[1]);\n\n\t\tif (m - n < 2) {\n\t\t\tSystem.out.println(-1);\n\t\t} else if (m - n == 2) {\n\n\t\t\tif (gcd(n, m) != 1)\n\n\t\t\t\tSystem.out.println(n + \" \" + (n + 1) + \" \" + (n + 2));\n\n\t\t\telse\n\t\t\t\tSystem.out.println(-1);\n\t\t} else {\n\t\t\tif (n % 2 == 0)\n\t\t\t\tSystem.out.println(n + \" \" + (n + 1) + \" \" + (n + 2));\n\t\t\telse\n\t\t\t\tSystem.out.println((n + 1) + \" \" + (n + 2) + \" \" + (n + 3));\n\t\t}\n\n\t\tout.close();\n\n\t}\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n\t\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\nString x[]=br.readLine().split(\" \");\n\t\tlong l=Long.parseLong(x[0]);\n\t\tlong r=Long.parseLong(x[1]);\n\t\tif(l%2!=0)\n\t\t{\n\t\t\tl++;\n\t\t}\n\t\tif(l+2>r)\n\t\t{\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(l+\" \"+(l+1)+\" \"+(l+2));\n\t\t}\n\t}\n} ", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.PrintStream;\nimport static java.lang.Math.*;\n\npublic class Task275A {\n\n    public static Scanner in = new Scanner(System.in);\n    public static PrintStream out = System.out;\n\n    public static void main(String[] args) {\n        long l = in.nextLong();\n        long r = in.nextLong();\n\n        if (l % 2 == 1) {\n            l++;\n        }\n\n        if (r - l < 2) {\n            out.print(-1);\n        }\n        else {\n            out.print(l + \" \" + (l + 1) + \" \" + (l + 2));\n        }\n    }\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Counterexample {\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 l=sc.nextLong(),r=sc.nextLong();\n\t\tif (l%2==0&&r-l>=2) System.out.print(l+\" \"+(l+1)+\" \"+(l+2));\n\t\telse if (l%2==1&&r-l>=3) System.out.print((l+1)+\" \"+(l+2)+\" \"+(l+3));\n\t\telse System.out.print(\"-1\");\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner sc =new Scanner(System.in);\n        long r,l;\n          r = sc.nextLong();\n          l = sc.nextLong();\n\n\n            if ((r+2)>l) { System.out.print(\"-1\"); return;}\n            if ((r % 2) == 0)   {\n              System.out.print(r);\n                System.out.print(\" \");\n                System.out.print(r+1);\n                System.out.print(\" \");\n                System.out.print(r+2);return; }\n               if((r+3)<=l )\n                {  System.out.print(r+1);\n                System.out.print(\" \");\n                  System.out.print(r+2);\n                System.out.print(\" \");\n                  System.out.print(r+3);return; }\n             System.out.print(\"-1\");\n\n\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\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\tif (new File(\"input.txt\").exists())\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\telse\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tif (new File(\"output.txt\").exists())\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\telse\n\t\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tvoid solve() throws IOException {\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n\t\tl += l % 2;\n\t\tif (l + 2 > r)\n\t\t\tout.println(\"-1\");\n\t\telse {\n\t\t\tout.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n\t\t}\n\t}\n\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\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\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString str = in.readLine();\n\t\t\tif (str == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(str);\n\t\t}\n\t\treturn false;\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class practice {\n\tpublic static void main(String[] args) throws Exception {\n\t\t//Scanner in = new Scanner(new File(\"practice.in\"));\n\t\tScanner in = new Scanner(System.in);\n\n\t\tString str = in.nextLine();\n\t\tlong n = Long.parseLong(str.substring(0, str.indexOf(\" \")));\n\t\tlong m = Long.parseLong(str.substring(str.indexOf(\" \") + 1));\n\t\tif(m - n < 2) {\n\t\t\tSystem.out.println(\"-1\");\n\t\t} else {\n\t\t\tif(m - n == 2 && m % 2 == 1) {\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println((n + n % 2) + \" \" + (n + 1 + n % 2) + \" \" + (n + 2 + n % 2));\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\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\tin.close();\n\t\tif (r - l < 2) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tif ((r - l > 2)||(l%2 ==0 )) {\n\t\t\tlong s = l + l%2;\n\t\t\tSystem.out.println(s+\" \"+(s+1)+\" \"+(s+2));\n\t\t} else {\n\t\t\tif (l%2 == 1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t} else{\n\t\t\t\tlong s = l;\n\t\t\t\tSystem.out.println(s+\" \"+(s+1)+\" \"+(s+2));\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\tstatic long gcd(long a, long b) {\n\t\tif(a==0) {\n\t\t\treturn b;\n\t\t}\n\t\tif (b==0) {\n\t\t\treturn a;\n\t\t}\n\t\tif (a > b) {\n\t\t\treturn gcd (a%b, b);\n\t\t}\n\t\treturn gcd (b%a, a);\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\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 l = Long.parseLong(line[0]);\n\t\tlong r = Long.parseLong(line[1]);\n\t\tif(r-l < 2 || ((r-l == 2) && (l % 2 == 1)))\n\t\t\tSystem.out.println(\"-1\");\n\t\telse\n\t\t{\n\t\t\tLong start = l + (l%2); \n\t\t\tSystem.out.println(start + \" \" + (start + 1) + \" \" + (start + 2));\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\npublic class fuck {\n\tpublic static int[] a;\n\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tlong r = input.nextLong();\n\t\tlong l = input.nextLong();\n\t\tif((l - r + 1) < 3){\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(r % 2 == 0)\n\t\t\t\tSystem.out.println(r + \" \" + (r +1)+ \" \" + (r+2) );\n\t\t\telse{\n\t\t\t\tif(l -r + 1 >3){\n\t\t\t\t\t++r;\n\t\t\t\t\tSystem.out.println(r + \" \" + (r +1)+ \" \" + (r+2) );\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(-1);\n\t\t\t }\n\t\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Counterexample483A\n{\n    public static void main(String[] args) \n    {\n        // Set up scanner\n        Scanner sc = new Scanner(System.in); \n        // System.out.println(\"Enter l\");\n        long l = sc.nextLong();\n        // System.out.println(\"Enter r\");\n        long r = sc.nextLong();\n        \n        if (l==r || l+1 == r)\n        {\n            System.out.println(-1);\n            return;\n        }\n        if (l+2 == r && l%2 == 1)\n        {\n            System.out.println(-1);\n            return;\n        }\n        if (l%2 == 0)\n        {\n            System.out.println(l + \" \" + (l+1) + \" \" + (l+2));\n            return;\n        }\n        System.out.println((l+1) + \" \" + (l+2) + \" \" + (l+3));\n    }\n}\n            \n            \n        \n        ", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tBigInteger l = new BigInteger(scanner.next());\n\t\tBigInteger r = new BigInteger(scanner.next());\n\t\tif(r.subtract(l).intValue() < 2) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tBigInteger a = l.abs(),b,c;\n\t\t\n\t\tBigInteger toothless = r.subtract(BigInteger.valueOf(1));\n\t\twhile(a.compareTo(toothless) == -1) {\n\t\t\tb = l.add(BigInteger.valueOf(1));\n\t\t\twhile(b.compareTo(r) == -1) {\n\t\t\t\tc = l.add(BigInteger.valueOf(2));\n\t\t\t\twhile(c.compareTo(r) == -1 || c.compareTo(r) == 0) {\n\t\t\t\t\tif(gcd(a,b) == 1 && gcd(b,c) == 1 && gcd(a,c) != 1) {\n\t\t\t\t\t\tSystem.out.println(a + \" \" + b + \" \" + c);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tc = c.add(BigInteger.valueOf(1));\n\t\t\t\t}\n\t\t\t\tb = b.add(BigInteger.valueOf(1));\n\t\t\t}\n\t\t\ta = a.add(BigInteger.valueOf(1));\n\t\t}\n\t\tSystem.out.println(-1);\n\t}\n\tprivate static int gcd(BigInteger a, BigInteger b) {\n\t\treturn a.gcd(b).intValue();\n\t}\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class A {\n\tpublic static void main(String[] args) {\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.add(BigInteger.ZERO);\n\t\twhile (a.compareTo(r) < 0) {\n\t\t\tBigInteger b = a.add(BigInteger.ONE);\n\t\t\twhile (b.compareTo(r) < 0) {\n\t\t\t\ttry {\n\t\t\t\t\ta.modInverse(b);\n\t\t\t\t} catch (ArithmeticException e) {\n\t\t\t\t\tb = b.add(BigInteger.ONE);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tBigInteger c = b.add(BigInteger.ONE);\n\t\t\t\twhile (c.compareTo(r) <= 0) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.modInverse(c);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\ta.modInverse(c);\n\t\t\t\t\t\t} catch (ArithmeticException e) {\n\t\t\t\t\t\t\tSystem.out.printf(\"%s %s %s\\n\", a.toString(), b.toString(), c.toString());\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (ArithmeticException e) {\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tc = c.add(BigInteger.ONE);\n\t\t\t\t}\n\t\t\t\tb = b.add(BigInteger.ONE);\n\t\t\t}\n\t\t\ta = a.add(BigInteger.ONE);\n\t\t}\n\t\tSystem.out.println(\"-1\");\n\t}\n}\n\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A {\n    public static void main(String[]args) {\n        Scanner in = new Scanner(System.in);\n        long l = in.nextLong();\n        long r = in.nextLong();\n        if(r - l < 2) System.out.println(-1);\n        else {\n            if(l % 2 == 0)\n                System.out.println(l + \" \" + (l+1) + \" \" + (l+2));\n            else {\n                if(r - l < 3) System.out.println(-1);\n                else\n                    System.out.println((l+1) + \" \" + (l+2) + \" \" + (l+3));\n            }\n        }\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\t\t\n\t\tnew TaskA().solve();\n\t}\n\n}\n\nclass TaskA extends Base {\t\n\tpublic static void solve () {\n\t\tlong l = in.nextLong();\n\t\tlong r = in.nextLong();\t\t\n\t\t\n\t\tif (r - l < 2) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif (l % 2 == 0) {\n\t\t\tSystem.out.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif (r - l > 2) {\n\t\t\tSystem.out.println((l + 1) + \" \" + (l + 2) + \" \" + (l + 3));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println(-1);\t\t\n\t}\n}\n\nclass Base {\n\tpublic static InputReader in = new InputReader(System.in);\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) {\t\t\t\n\t\t\t\te.printStackTrace();\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\t\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n}\n\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class CF275Ad2 {\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tlong l = scan.nextLong();\n\t\tlong r = scan.nextLong();\n\t\t\n\t\tlong diff = r-l;\n\t\tboolean exists = false;\n\t\tif(diff >= 3){\n\t\t\tif(l%2 == 1){\n\t\t\t\tl++;\n\t\t\t}\n\t\t\texists = true;\n\t\t} else if(diff == 2 && l%2 == 0){\n\t\t\texists = true;\n\t\t} else if(diff == 2 && gcd(l, r) > 1){\n\t\t\texists = true;\n\t\t}\n\t\t\n\t\tif(!exists){\n\t\t\tSystem.out.println(\"-1\");\n\t\t} else {\n\t\t\tSystem.out.println(l + \" \" + (l+1) + \" \" + (l+2));\n\t\t}\n\t}\n\t\n\tprivate static long gcd(long a, long b){\n\t\tif(b == 0){\n\t\t\treturn 1;\n\t\t} \n\t\treturn gcd(b, a % b);\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A275 {\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        \n        long a=sc.nextLong();\n        long b=sc.nextLong();\n        \n        if(b-a<2){\n            System.out.println(-1);\n        }else if(b-a==2 && a%2==1){\n            System.out.println(-1);\n        }else if(b-a==2 && a%2==0){\n            System.out.println(a+\" \"+(a+1)+\" \"+(a+2));\n        }else{\n            if(a%2==0){\n                System.out.println(a+\" \"+(a+1)+\" \"+(a+2));\n            }else{\n                System.out.println((a+1)+\" \"+(a+2)+\" \"+(a+3));\n            }\n        }\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong l = in.nextLong();\n\t\tlong r = in.nextLong();\n\t\tlong a = 0;\n\t\tlong b = 0;\n\t\tlong c = 0;\n\t\tif (r - l < 2)\n\t\t\tSystem.out.println(-1);\n\t\telse if (r - l < 3 && l % 2 == 1)\n\t\t\tSystem.out.println(-1);\n\t\telse {\n\t\t\tif (l % 2 == 0) {\n\t\t\t\ta = l;\n\t\t\t\tb = l + 1;\n\t\t\t\tc = l + 2;\n\t\t\t} else {\n\t\t\t\tif (l == 1) {\n\t\t\t\t\ta = 2;\n\t\t\t\t\tb = 3;\n\t\t\t\t\tc = 4;\n\t\t\t\t} else {\n\t\t\t\t\ta = l + 1;\n\t\t\t\t\tb = l + 2;\n\t\t\t\t\tc = l + 3;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(a + \" \" + b + \" \" + c);\n\t\t}\n\t\t\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class K603 {\n\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        \n        long a=sc.nextLong();\n        long b=sc.nextLong();\n        \n        if(b-a<2){\n            System.out.println(-1);\n        }else if(b-a==2 && a%2==1){\n            System.out.println(-1);\n        }else if(b-a==2 && a%2==0){\n            System.out.println(a+\" \"+(a+1)+\" \"+(a+2));\n        }else{\n            if(a%2==0){\n                System.out.println(a+\" \"+(a+1)+\" \"+(a+2));\n            }else{\n                System.out.println((a+1)+\" \"+(a+2)+\" \"+(a+3));\n            }\n        }\n    }\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class A{\n\tpublic static BufferedReader k;\n\tpublic static BufferedWriter z;\n\t\n\n\t\n\tpublic static void main(String [] args)throws IOException{\n\t\tk = new BufferedReader(new InputStreamReader(System.in));\n\t\tz = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\n\t\t\n\t        String[] dat = k.readLine().split(\" \");\n\n\t        long l = Long.parseLong(dat[0]);\n\t        long r = Long.parseLong(dat[1]);\n\t\t\t\n\t\t\tif(r-l<=1){\n\t\t\t\tz.write(-1+\"\\n\");\n\t\t\t}\n\t\t\telse if(r-l == 2){\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tif((l&1)!=0){\n\t\t\t\t\tz.write(-1+\"\\n\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tz.write(l+\" \"+(l+1)+\" \"+r+\"\\n\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(l%2==0){\n\t\t\t\t\tz.write(l+\" \"+(l+1)+\" \"+(l+2)+\"\\n\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tz.write((l+1)+\" \"+(l+2)+\" \"+(l+3)+\"\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\tz.flush();\n\n\t}\n\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\npublic class Counterexample {\n    public static void main(String[] args) {\n        System.out.println(new Counterexample().solve());\n    }\n\n    String solve() {\n        Scanner sc = new Scanner(System.in);\n\n        final long l = sc.nextLong();\n        final long r = sc.nextLong();\n\n        if ((r - l) > 1) {\n            long a = l;\n            long b = l + 1;\n            long c = l + 2;\n\n            while (a < (r - 1)) {\n                while (b < r) {\n                    while (c <= r) {\n                        if (gcd(a,b) == 1\n                                && gcd(b,c) == 1\n                                && gcd(a,c) > 1) {\n                            return Long.toString(a)\n                                + \" \"\n                                + Long.toString(b)\n                                + \" \"\n                                + Long.toString(c);\n                                }\n                        c += 1;\n                    }\n                    c = b + 1;\n                    b += 1;\n                }\n                b = a + 1;\n                a += 1;\n            }\n        }\n        return \"-1\";\n    }\n\n    long gcd(long a, long b) {\n        while (b != 0) {\n            long t = b;\n            b = a % b;\n            a = t;\n        }\n        return a;\n    }\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class A {\n  FastScanner in;\n  PrintWriter out;\n\n  public void run() {\n    try {\n      in = new FastScanner(new InputStreamReader(System.in));\n      out = new PrintWriter(System.out);\n      solve();\n      out.close();\n    } catch (IOException e) {\n      e.printStackTrace();\n    }\n  }\n\n  public void solve() throws IOException {\n    long l = new Long(in.next());\n    long r = new Long(in.next());\n    if (r - l < 2 || (r - l == 2 && l % 2 != 0)) {\n      out.println(\"-1\");\n    } else {\n      if (l % 2 != 0) {\n        l++;\n      }\n      out.println(l);\n      out.println(l+1);\n      out.println(l+2);\n    }\n  }\n\n  class FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n\n    FastScanner(InputStreamReader in) {\n      br = new BufferedReader(in);\n    }\n\n    String nextLine() {\n      String str = null;\n      try {\n        str = br.readLine();\n      } catch (IOException e) {\n        e.printStackTrace();\n      }\n\n      return str;\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    A o = new A();\n    o.run();\n  }\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A {\n\n\tpublic static void main(String[] args) {\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tlong l = sc.nextLong();\n\t\tlong h = sc.nextLong();\n\t\t\n\t\tsc.close();\n\t\t\n\t\tif(h-l<2) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn ;\n\t\t}\n\t\t\n\t\tif(h-l==2 && l%2==1) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn ;\n\t\t}\n\t\t\n\t\tif(l%2==1) {\n\t\t\t++l;\n\t\t}\n\t\t\n\t\tSystem.out.printf(\"%d %d %d\\n\",l,l+1L,l+2L);\n\t}\n\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\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    StringTokenizer st = new StringTokenizer(f.readLine());\n    BigInteger l = new BigInteger(st.nextToken());\n    BigInteger r = new BigInteger(st.nextToken());\n    \n    // write\n    if (r.subtract(l).intValue()<2 || (r.subtract(l).intValue()==2 && r.mod(new BigInteger(\"2\")).intValue()==1)) out.println(-1);\n    else out.println(l.add(l.mod(new BigInteger(\"2\"))).toString()+\" \"+l.add(l.mod(new BigInteger(\"2\"))).add(new BigInteger(\"1\")).toString()+\" \"+l.add(l.mod(new BigInteger(\"2\"))).add(new BigInteger(\"2\")).toString());\n    \n    // cleanup\n    out.close();\n    System.exit(0);\n  }\n}", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tlong l = s.nextLong();\n\t\tlong r = s.nextLong();\n\t\ts.close();\n\t\t\n\t\tif (r-l<2 || (r-l==2 && l%2==1)) {\n\t\t\tSystem.out.print(\"-1\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong beg = l%2==0 ? l : l+1;\n\t\tif (beg+2>r) System.out.print(\"-1\");\n\t\telse System.out.print(beg+\" \"+(beg+1)+\" \"+(beg+2));\n\t}\n}\n", "complexity": "constant", "problem": "483_A. Counterexample ", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\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.printf(\"%d %d\", 4, n - 4);\n        } else {\n            System.out.printf(\"%d %d\", 9, n - 9);\n        }\n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws FileNotFoundException {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n = in.nextInt();\n        if (n%2==0) {\n            System.out.println(4+\" \"+(n-4));\n        } else {\n            System.out.println(9+\" \"+(n-9));\n        }\n\n        in.close();\n        out.close();\n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Solution {\n\n  public static void main(String[] args) throws Exception {\n    Scanner in = new Scanner(System.in);\n    int n = in.nextInt();\n    if (n % 2 == 0)\n      System.out.println(\"4 \" + (n - 4));\n    else\n      System.out.println(\"9 \" + (n - 9));\n  }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class LearnMath {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint N = scan.nextInt();\n\t\tscan.close();\n\t\t\n\t\tif ((N%2) == 0) {\n\t\t\tSystem.out.println(4 + \" \" + (N-4));\n\t\t}\n\t\telse {\n\t\t\tif (N > 18) {\n\t\t\t\tSystem.out.println(9 + \" \" + (N-9));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println((N-9) + \" \" + 9);\n\t\t\t}\n\t\t}\n\n\t}\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Composite {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tif (n == 12)\n\t\t\tSystem.out.println(\"4 8\");\n\t\t\n\t\telse if (n % 2 == 1)\n\t\t\tSystem.out.println((n - 9) + \" 9\");\n\t\t\n\t\telse\n\t\t\tSystem.out.println((n - 6) + \" 6\");\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "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.math.BigInteger;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport static java.lang.Integer.*;\n\npublic class A {\n\n    public static void main(String[] args) throws IOException {\n        //BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));\n        Scanner sc=new Scanner (System.in);\n    //  StringTokenizer st=new StringTokenizer(buf.readLine());\n        int n=sc.nextInt();\n        System.out.println(n%2==0?4+\" \"+(n-4):9+\" \"+(n-9));\n\n    }\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        if (n % 2 == 0) {\n            out.println(4 + \" \" + (n - 4));\n        } else {\n            out.println(9 + \" \" + (n - 9));\n        }\n    }\n}\n\nclass InputReader {\n    private final 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 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\n}\n\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n    public class Main\n    {\n        public static void main(String[] args)\n        {\n        Scanner sc =new Scanner(System.in);    \n        long a=sc.nextLong();\n        if(a%4==0){System.out.println(a/2 + \" \" + a/2);}\n        if(a%4==1){System.out.println(9 + \" \" + (a-9));}\n        if(a%4==2){System.out.println(6 + \" \" + (a-6));}\n        if(a%4==3 && a>15){System.out.println(15 + \" \" + (a-15));}\n        if(a==15){System.out.println(\"6 9\");}\n        \n        }\n    }\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Code1 {\n\n    public static void main(String[] args) {\n\n        Scanner sc = new Scanner(System.in);\n        int n = Integer.valueOf(sc.nextLine());\n        if (n % 2 == 0)\n            System.out.println(4 + \" \" + (n - 4));\n        else {\n            System.out.println(9 + \" \" + (n - 9));\n        }\n\n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {\n\t\t\tString input;\n\n\t\t\twhile ((input = reader.readLine()) != null && input.length() > 0) {\n\t\t\t\tint n = Integer.parseInt(input);\n\t\t\t\tint start = 4;\n\t\t\t\tint end = n - start;\n\n\t\t\t\twhile (start <= end) {\n\t\t\t\t\tif ((start % 2 == 0 || start % 3 == 0) && (end % 2 == 0 || end % 3 == 0)) {\n\t\t\t\t\t\tSystem.out.println(start + \" \" + end);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t++start;\n\t\t\t\t\t--end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n\n    public static void main(String[] args) {\n         \n        Scanner x=new Scanner(System.in);\n        \n        int n=x.nextInt();\n                \n                if(n%2==0){\n                    \n                    System.out.println((n-4)+\" \"+\"4\");\n                }\n                else{\n                    \n                    System.out.println((n-9)+\" \"+\"9\");\n                    \n                }\n        \n        \n        \n        \n    }\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "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 */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        int N = in.nextInt();\n        if (N % 2 == 0){\n            out.println(\"4 \" + (N - 4));\n        }\n        else {\n            out.println(\"9 \" + (N - 9));\n        }\n    }\n}\n\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\tprivate BufferedReader cin;\n\tprivate PrintWriter cout;\n\tprivate StringTokenizer strtok;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tSolution sol = new Solution();\n\t\tfinal boolean CONTEST = true;\n\t\tif (CONTEST) {\n\t\t\tsol.cin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tsol.cout = new PrintWriter(System.out);\n\n\t\t} else {\n\t\t\tsol.cin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tsol.cout = new PrintWriter(\"output.txt\");\n\t\t}\n\t\tsol.solve();\n\t\tsol.cin.close();\n\t\tsol.cout.close();\n\t}\n\n\tprivate int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate String nextToken() throws IOException {\n\t\twhile (strtok == null || !strtok.hasMoreTokens()) {\n\t\t\tstrtok = new StringTokenizer(cin.readLine());\n\t\t}\n\t\treturn strtok.nextToken();\n\t}\n\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tif (n % 2 == 0) {\n\t\t\tcout.println(n - 4 + \" \" + 4);\n\t\t} else {\n\t\t\tcout.println(n - 9 + \" \" + 9);\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "/* 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        if(n%2==0){\n            System.out.println(4 + \" \" + (n-4));\n        }\n        else{\n            int a = Math.min(9,n-9);\n            int b = Math.max(9,n-9);\n            System.out.println(a + \" \" + b);\n        }\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ProblemA {\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(new InputStreamReader(System.in));\n        int n = sc.nextInt();\n        if (n % 2 == 0) {\n            System.out.println((n - 4) + \" \" + 4);\n        } else {\n            System.out.println((n - 9) + \" \" + 9);\n        }\n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class composite {\n\n  \n    public static void main(String[] args) {\n        \n        Scanner s=new Scanner(System.in);\n        int a=s.nextInt();\n      \n          if(a%2==0)\n          {\n              a=a-4;\n              System.out.println(4+\" \"+a);\n          }\n          else\n          {\n              a=a-9;\n              System.out.println(9+\" \"+a);\n          }\n      \n    \n}\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileNotFoundException;\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.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class Main\n{\n\n\tprivate static BufferedReader in;\n\tprivate static BufferedWriter out;\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException\n\t{\n\t\t// streams\n\t\tboolean file = false;\n\t\tif (file)\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\telse\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t// out = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tout = new BufferedWriter(new FileWriter(\"output.txt\"));\n\t\tStringTokenizer tok;\n\n\t\tint n = Integer.parseInt(in.readLine());\n\t\tif (n % 2 == 0)\n\t\t\tSystem.out.println(4 + \" \" + (n-4));\n\t\telse\n\t\t\tSystem.out.println(9 + \" \" + (n-9));\n\t}\n\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    private static PrintWriter out;\n    private static FastReader in;\n\n    private static class FastReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public FastReader(InputStream inputStream) {\n            reader = new BufferedReader(\n                    new InputStreamReader(inputStream), 1 << 16);\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 ex) {\n                    throw new RuntimeException(ex);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public String nextLine() {\n            try {\n                return reader.readLine();\n            } catch (IOException ex) {\n                throw new RuntimeException(ex);\n            }\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n    }\n\n    public static void main(String[] args) throws FileNotFoundException, InterruptedException {\n        in = new FastReader(System.in);\n        out = new PrintWriter(System.out);\n\n        int n = in.nextInt();\n        int a = ((n & 1) == 0) ? a = 6 : 9;\n        int b = n - a;\n        out.println(a + \" \" + b);\n\n        out.flush();\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Scanner;\n\n\npublic class T\n{\n    public static void main(String[] args) throws IOException\n    {\n        T t = new T();\n        t.run();\n        t.close();\n    }\n\n    private void close()\n    {\n        sc.close();\n        pw.close();\n    }\n\n    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    Scanner sc = new Scanner(reader);\n    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n    void yesno(boolean b)\n    {\n        pw.println(b ? \"YES\" : \"NO\");\n    }\n\n\n    void run() throws IOException\n    {\n        int n = sc.nextInt();\n\n        if (n % 2 == 0)\n        {\n            pw.print(4 + \" \" + (n - 4));\n        }\n        else\n        {\n            pw.print(9 + \" \" + (n - 9));\n        }\n\n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class a {\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int n = input.nextInt();\n    if(n%2 == 0) System.out.println(4+\" \"+(n-4));\n    else System.out.println(9+\" \" +(n-9));\n}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Test {\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 % 2 == 0) {\n\t\t\tSystem.out.println(4 + \" \" + (n - 4));\n\t\t} else {\n\t\t\tSystem.out.println(9 + \" \" + (n - 9));\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class code0 {\n\npublic static void main(String[] args){\n\tScanner scr= new Scanner(System.in);\nint c=0,e=0,d=0;\nint a=scr.nextInt();\nd=a/2;\nif(a>=11 && a%2==1){\nc=9;\ne=a-9;\n}\nelse{\nc=a-4;e=4;\n}\n\nSystem.out.print(c+\" \"+e);\n}\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "/*\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.Scanner;\n\n/**\n *\n * @author RezaM\n */\npublic class A {\n\n    public static void main(String[] args) {\n\n        Scanner scan = new Scanner(System.in);\n\n        int n = scan.nextInt();\n\n        if (n % 2 == 0) {\n            System.out.println(4 + \" \" + (n - 4));\n        } else {\n            System.out.println(9 + \" \" + (n - 9));\n        }\n\n    }\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\t\npublic class A {\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\ts.close();\n\t\t\n\t\tif (n % 2 == 0)\n\t\t\tSystem.out.print(\"4 \" + (n-4));\n\t\telse \n\t\t\tSystem.out.print(\"9 \" + (n-9));\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class a\n{\n\tpublic static void main(String[] args)\n\t{\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\tsolve(N);\n\t\t\n\t\t\n\t}\n\t\n\tstatic void solve(int a)\n\t{\n\t\tif((a-8)%3==0)\n\t\t{\n\t\t\tSystem.out.println(8+\" \"+(a-8));\n\t\t\treturn ;\n\t\t}\n\t\tif((a-4)%3==0)\n\t\t{\n\t\t\tSystem.out.println(4+\" \"+(a-4));\n\t\t\treturn ;\n\t\t}\n\t\tif((a-6)%3==0)\n\t\t{\n\t\t\tSystem.out.println(6+\" \"+(a-6));\n\t\t\treturn ;\n\t\t}\n\t}\n\t\t\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class ProblemA {\n\n\tpublic static void main(String [] args) throws NumberFormatException, IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint num1,num2;\n\t\tif(n % 2 == 0){\n\t\t\tnum1 = n / 2;\n\t\t\tif(num1 % 2 == 0){\n\t\t\t\tnum2 = num1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnum1--;\n\t\t\t\tnum2 = num1 + 2;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tnum1 = 9;\n\t\t\tnum2 = n - num1;\n\t\t}\n\t\t\n\t\tSystem.out.println(num1+\" \"+num2);\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * Created by misanand on 9/20/14.\n */\npublic class Recovery {\n    public static void main(String [] args) {\n        Scanner scan = new Scanner(System.in);\n        int N = scan.nextInt();\n        if( N%2 == 0) {\n            System.out.println( (4)+\" \"+(N-4));\n        }\n        else System.out.println( (9)+\" \"+(N-9));\n        scan .close();\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class main1 {\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\t\n\t\tint a = n / 2;\n\t\tint b = n - a;\n\t\t\n\t\tif (n % 2 == 0) {\n\t\t\tif (a % 2 == 1) {\n\t\t\t\ta++;\n\t\t\t\tb--;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(a + \" \" + b);\n\t\t} else {\n\t\t\tif (a % 2 == 1) {\n\t\t\t\tint x = a;\n\t\t\t\ta = b;\n\t\t\t\tb= x;\n\t\t\t}\n\t\t\t\n\t\t\tif (b % 3 == 0) {\n\t\t\t\t\n\t\t\t} else if (b % 3 == 1) {\n\t\t\t\ta-=2;\n\t\t\t\tb+=2;\n\t\t\t} else {\n\t\t\t\ta+=2;\n\t\t\t\tb-=2;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(a + \" \" + b);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nipuna Samarasekara\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    /////////////////////////////////////////////////////////////\n\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n    int n=in.nextInt();\n        if (n%2==0){\n            if (n%4==0)\n                out.println(n/2+\" \"+n/2);\n            else out.println(6+\" \"+(n-6));\n\n        }\n        else{\n            out.println(9+\" \"+(n-9));\n        }\n\n    }\n}\n\nclass FastScanner extends BufferedReader {\n\n    public FastScanner(InputStream is) {\n        super(new InputStreamReader(is));\n    }\n\n    public int read() {\n        try {\n            int ret = super.read();\n//            if (isEOF && ret < 0) {\n//                throw new InputMismatchException();\n//            }\n//            isEOF = ret == -1;\n            return ret;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    static boolean isWhiteSpace(int c) {\n        return c >= 0 && c <= 32;\n    }\n\n    public int nextInt() {\n        int c = read();\n        while (isWhiteSpace(c)) {\n            c = read();\n        }\n        int sgn = 1;\n        if (c == '-') {\n            sgn = -1;\n            c = read();\n        }\n        int ret = 0;\n        while (c >= 0 && !isWhiteSpace(c)) {\n            if (c < '0' || c > '9') {\n                throw new NumberFormatException(\"digit expected \" + (char) c\n                        + \" found\");\n            }\n            ret = ret * 10 + c - '0';\n            c = read();\n        }\n        return ret * sgn;\n    }\n\n    public String readLine() {\n        try {\n            return super.readLine();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n}\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", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "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        \n        int one, two;\n        if(n%2 == 0)\n        {\n            one = two = n/2;\n            if(one%2 != 0 && two%2 != 0)\n            {\n                one--;\n                two++;\n            }\n        }\n        else\n        {\n            one = n - 9;\n            two = 9;\n        }\n        \n        System.out.println(one+\" \"+two);\n        \n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        if (n % 2 == 0) {\n            System.out.println((n - 4) + \" \" + (n - (n - 4)));\n        } else {\n            System.out.println((n - 9) + \" \" + (n - (n - 9)));\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Anirudh Rayabharam (anirudhrb@yandex.com)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        if (n % 2 == 0) {\n            out.println(\"4 \" + (n - 4));\n        } else {\n            out.println(\"9 \" + (n - 9));\n        }\n    }\n}\n\nclass InputReader {\n    public BufferedReader reader;\n    private int tokenCount, nextTokenIndex;\n    private String[] tokens;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n        tokenCount = nextTokenIndex = 0;\n    }\n\n    public String next() {\n        String nextLine;\n        if (nextTokenIndex == tokenCount) {\n            try {\n                nextLine = reader.readLine();\n                nextTokenIndex = 0;\n                tokens = nextLine.split(\"\\\\s\");\n                tokenCount = tokens.length;\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        return tokens[nextTokenIndex++];\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n}\n\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Scanner;\n\n/**\n * TODO: describe\n *\n * @author keks\n */\npublic class A {\n    public static void main(String[] args) throws IOException {\n        final Scanner sc = new Scanner(System.in);\n        final int n = sc.nextInt();\n        if (n % 2 == 0) {\n            System.out.println(4 + \" \" + (n - 4));\n        } else {\n            System.out.println(9 + \" \" + (n - 9));\n        }\n    }\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Cf270a {\n    public static void main(String[] args) throws IOException {\n        InputStreamReader fin = new InputStreamReader(System.in);\n        Scanner scr = new Scanner(fin);\n        int n = scr.nextInt();\n        int x = 0;\n        int y = 0;\n        if (n%2 == 0) {\n            x = 4;\n            y = n - x;\n        } else {\n            x = 9;\n            y = n - x;\n        }\n        PrintWriter fout = new PrintWriter(System.out);\n        fout.print(x+\" \"+y);\n        fout.flush();\n        fout.close();\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "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 TA {\n\n\tpublic void solve(long n) {\n\t\tlong a = 0, b = 0;\n\t\tif (n % 2 == 0) {\n\t\t\tif (n % 4 == 0) {\n\t\t\t\ta = n / 2;\n\t\t\t\tb = n/ 2;\n\t\t\t} else {\n\t\t\t\ta = n / 2 - 1;\n\t\t\t\tb = n / 2 + 1;\n\t\t\t}\n\t\t} else {\n\t\t\ta = 4;\n\t\t\tb = n - a;\n\t\t\twhile (b > 0 && (b % 3 != 0)) {\n\t\t\t\ta += 2;\n\t\t\t\tb = n - a;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.println(a + \" \" + b);\n\t}\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner();\n\t\t\n\t\tnew TA().solve(in.nextLong());\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}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class J472A {\n\tprivate static Scanner scan = new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\tint a = scan.nextInt();\n\t\tif(a % 2 == 0) {\n\t\t\tSystem.out.println(4 + \" \" + (a - 4));//\u017c\ufffd\ufffd\ufffd4\n\t\t} else {\n\t\t\tSystem.out.println(9 + \" \" + (a - 9));//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint a,b;\n\t\tif (n%2==0) {\n\t\t\ta = 4;\n\t\t}else{\n\t\t\ta = 9;\n\t\t}\n\t\tb = n - a;\n\t\tSystem.out.println(a + \" \" + b);\n\t}\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n\n        int n = in.nextInt();\n        \n        int a = n/2;\n        int b = (n/2) + (n%2);\n        \n        if ((a%2!=0 && a%3!=0) || (b%2!=0 && b%3!=0)) {\n            a--;\n            b++;\n        }\n        \n        if ((a%2!=0 && a%3!=0) || (b%2!=0 && b%3!=0)) {\n            a--;\n            b++;\n        }\n\n        System.out.println(a + \" \" + b);\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n\npublic class composite {\n\n  \n    public static void main(String[] args) {\n        int b;\n        Scanner s3=new Scanner(System.in);\n         b=s3.nextInt();\n      \n          if(b%2==0)\n          {\n              b=b-4;\n              System.out.println(4+\" \"+b);\n          }\n          else\n          {\n              b=b-9;\n              System.out.println(9+\" \"+b);\n          }\n      \n    \n}\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\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();\n\t\tif(n%2==0)\n\t\t\tout.println(\"4 \"+(n-4));\n\t\telse\n\t\t\tout.println(\"9 \"+(n-9));\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\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 A().run();\n\t}\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "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\n    int N = Integer.parseInt(f.readLine());\n    \n    // write to out\n    if (N%2==0) out.println(\"4 \"+(N-4));\n    if (N%2==1) out.println(\"9 \"+(N-9));\n    \n    // cleanup\n    out.close();\n    System.exit(0);\n  }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A470 {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t\n\tScanner sc = new Scanner(System.in);\n\t\n\tint n=sc.nextInt();\n\t\n\tint start=4;\n\t\n\t\n\twhile(true){\n\t\t\n\t\tif((start%2==0||start%3==0)&&((n-start)%2==0||(n-start)%3==0))\n\t\t{\n\t\t\tSystem.out.println(start+\" \"+(n-start));\n\t\t\treturn;\n\t\t}\n\t\telse \n\t\tstart++;\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n\t\t\n\t\t\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer tb;\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint x = 0,y=0;\n\t\tif(n%2==0){\n\t\t\tx = n-4;\n\t\t\ty = 4;\n\t\t}else{\n\t\t\tx = n-9;\n\t\t\ty = 9;\n\t\t}\n\t\tSystem.out.println(x+\" \"+y);\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "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 bdepwgjqet\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\tA solver = new A();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass A {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int number = in.nextInt();\n        if((number & 1) == 0) {\n            out.println(4+\" \"+(number-4));\n        } else {\n            out.println(9+\" \"+(number-9));\n        }\n    }\n}\n\nclass InputReader {\n\n    private final BufferedReader bufferedReader;\n    private StringTokenizer stringTokenizer;\n\n    public InputReader(InputStream in) {\n        bufferedReader = new BufferedReader(new InputStreamReader(in));\n        stringTokenizer = null;\n    }\n\n    public String nextLine() {\n        try {\n            return bufferedReader.readLine();\n        } catch(IOException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    public String nextBlock() {\n        while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n            stringTokenizer = new StringTokenizer(nextLine());\n        }\n        return stringTokenizer.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextBlock());\n    }\n\n    public double nextDouble() {\n        return Double.parseDouble(nextBlock());\n    }\n\n    public long nextLong() {\n        return Long.parseLong(nextBlock());\n    }\n}\n\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class p472a {\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(\"8 \" + (n - 8));\n        } else {\n            System.out.println(\"9 \" + (n - 9));\n        }\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\t\n\t\tif(n % 2 == 1)\n\t\t{\n\t\t\tSystem.out.println(9 + \" \" + (n - 9));\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(4 + \" \" + (n - 4));\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Collections;\n\npublic class Problem1 {\n\n    public static void main(String[] args) throws IOException {\n        // TODO Auto-generated method stub\n        \n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        long n=Long.parseLong(br.readLine());\n        if(n%2==0){\n            System.out.println(4+\" \"+(n-4));\n        }\n        else{\n            System.out.println(9+\" \"+(n-9));\n        }\n        \n    }\n\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Test {\npublic static void main(String[] args) throws IOException{\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t//StringTokenizer st=new StringTokenizer(bf.readLine());\n\tint n=Integer.parseInt(bf.readLine());\n\t\n\tif(n%2==0) System.out.println(4+\" \"+(n-4));\n\telse System.out.println(9+\" \"+(n-9));\n\t\n}\n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main{\n    \n    public static boolean isPrime(long num){\n        int divisor = 2;\n        boolean bandera = true;\n        while(bandera && divisor<num) //ponemos el while con su condicion en este caso si bandera \n        { \n        if (num%divisor==0) {\n            bandera=false;\n            break;\n        }else{\n            divisor++; //igual si el divisor llego al numero q se capturo este sera primo \n        }\n        }\n        return bandera;\n    }\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        \n        int uno = 4;\n        int dos = n-4;\n\n        while(isPrime(dos) || isPrime(uno)){\n            dos--;\n            uno++;\n        }\n\n        System.out.println(uno+\" \"+dos);\n        \n    }\n    \n}\n", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "/* 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     int n,a,b;\n     Scanner obj=new Scanner(System.in);\n    \n     n=obj.nextInt();\n    \n     if(n%4==0){a=n/2;b=n/2;System.out.println(a+\" \"+b);}\n     else if(n%2==0 && n%4!=0)\n     {a=n/2-1;b=n/2+1;System.out.println(a+\" \"+b);}\n     \n     else if(n%2!=0)\n     {  a=4;b=0;\n       while(b!=1)\n       { b=n-a;\n         if(b%3==0){ System.out.println(a+\" \"+b);break; }\n         else{a=a+2;}\n       }\n     }\n    }\n}", "complexity": "constant", "problem": "472_A. Design Tutorial: Learn from Math", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\nimport java.io.*;\n\npublic class SolutionB {\n      public static void main(String args[])throws IOException{\n              Scanner sc = new Scanner(System.in);\n              int a[] = new int[1501];\n              for(int i = 0; i < 3; i++){\n                     a[sc.nextInt()]++;\n              }\n              if(a[1] > 0 || a[2] > 1 || a[3] > 2 || (a[4] == 2 && a[2] == 1)){\n                     System.out.println(\"YES\");\n              }else{\n                     System.out.println(\"NO\");\n              }\n      }\n}", "complexity": "constant", "problem": "911_C. Three Garlands", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\n// author @mdazmat9\npublic  class codeforces{\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 test = 1;\n        for (int ind = 0; ind < test; ind++) {\n          int [] a=new int[3];\n          a[0]=sc.nextInt();\n          a[1]=sc.nextInt();\n          a[2]=sc.nextInt();\n          Arrays.sort(a);\n          int k1=a[0];\n          int k2=a[1];\n          int k3=a[2];\n          if(k1==1 || k2==1 || k3==1){\n              out.println(\"YES\");\n          }\n          else if((k1==2 && k2==2)||(k2==2 && k3==2)){\n              out.println(\"YES\");\n            }\n            else if(k1==3 && k2==3 && k3==3){\n              out.println(\"YES\");\n          }\n          else if(k1==2 && k2==4 && k3==4){\n              out.println(\"YES\");\n          }\n          else\n              out.println(\"NO\");\n\n        }\n        out.flush();\n    }\n\n\n\n\n\n    static   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    static long gcd(long a , long b)\n    {\n        if(b == 0)\n            return a;\n        return gcd(b , a % b);\n    }\n\n}\nclass Scanner {\n    public BufferedReader reader;\n    public StringTokenizer st;\n\n    public Scanner(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n        st = null;\n    }\n\n    public String next() {\n        while (st == null || !st.hasMoreTokens()) {\n            try {\n                String line = reader.readLine();\n                if (line == null) return null;\n                st = new StringTokenizer(line);\n            } catch (Exception e) {\n                throw (new RuntimeException());\n            }\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    public long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    public double nextDouble() {\n        return Double.parseDouble(next());\n    }\n}\n\nclass OutputWriter {\n    BufferedWriter writer;\n\n    public OutputWriter(OutputStream stream) {\n        writer = new BufferedWriter(new OutputStreamWriter(stream));\n    }\n\n    public void print(int i) throws IOException {\n        writer.write(i);\n    }\n\n    public void print(String s) throws IOException {\n        writer.write(s);\n    }\n\n    public void print(char[] c) throws IOException {\n        writer.write(c);\n    }\n\n    public void close() throws IOException {\n        writer.close();\n    }\n\n}", "complexity": "constant", "problem": "911_C. Three Garlands", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Test3 {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tint x=Integer.parseInt(br.readLine());\n\t\tint y=Integer.parseInt(br.readLine());\n\t\tSystem.out.print((int)(y%(Math.pow(2, x))));\n\t}\n}\n", "complexity": "constant", "problem": "913_A. Modular Exponentiation", "from": "CODEFORCES"}
{"src": "/**\n *   Author: Ridam Nagar\n *   Date: 27 February 2019\n *   Time: 01:17:36\n**/\n/* \npackage codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{     \n  static String reverse(String s){\n    String reverse=\"\";\n    for(int i=s.length()-1;i>=0;i--){\n        reverse=reverse + s.charAt(i);\n    }\n    return reverse;\n  }\n\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 x=m%(int)Math.pow(2,n);\n         System.out.println(x);\n\n\n\n}\n}", "complexity": "constant", "problem": "913_A. Modular Exponentiation", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class RENAMETHISBITCH {\n\t\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\ttry (Scanner sc = new Scanner(System.in)) {\n\t\t\t\n\t\t\tint n = sc.nextInt();\n\t\t\tBigInteger m = sc.nextBigInteger();\n\t\t\t\n\t\t\tSystem.out.println(m.mod(BigInteger.valueOf(2).pow(n)));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "913_A. Modular Exponentiation", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class aaaaaaaaaaaaaaaa {\n\tpublic void run() throws Exception {\n\t\tScanner file = new Scanner(System.in);\n\t\tint a = file.nextInt(), b= file.nextInt(), c = file.nextInt(), n = file.nextInt();\n\t\ta -= c;\n\t\tb -= c;\n\t\tif (a < 0 || b < 0) System.out.println(-1);\n\t\telse {\n\t\t\tint x = a + b + c;\n\t\t\tif (x >= n) System.out.println(-1);\n\t\t\telse System.out.println(n - x);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew aaaaaaaaaaaaaaaa().run();\n\t}\n\n}", "complexity": "constant", "problem": "991_A. If at first you don't succeed...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class helloWorld \n{\n\tpublic static void main(String[] args) \n\t{\t\t\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\t\tint n = in.nextInt();\n\n\t\tint ans = n - (a + b - c);\n\t\tif(ans < 1 || a >= n || b >= n || c > a || c > b)\n\t\t\tans = -1;\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\tin.close();\n\t}\n}", "complexity": "constant", "problem": "991_A. If at first you don't succeed...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n\npublic class Main {\n\n\tstatic class Task {\n\t\t\n\t\tint NN = 500005;\n\t\tint MOD = 1000000007;\n\t\tint INF = 2000000000;\n\t\tlong INFINITY = 2000000000000000000L;\n\t\t\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint t = in.nextInt();\n\t\t\twhile(t-->0) {\n\t\t\t\tlong n =in.nextLong();\n\t\t\t\tlong m = in.nextLong();\n\t\t\t\tlong x1 = in.nextLong();\n\t\t\t\tlong y1 = in.nextLong();\n\t\t\t\tlong x2 = in.nextLong();\n\t\t\t\tlong y2 = in.nextLong();\n\t\t\t\tlong x3 = in.nextLong();\n\t\t\t\tlong y3 = in.nextLong();\n\t\t\t\tlong x4 = in.nextLong();\n\t\t\t\tlong y4 = in.nextLong();\n\t\t\t\tlong w = white(1, 1, m, n);\n\t\t\t\tlong b = black(1, 1, m, n);\n\t\t\t\tlong whited = 0;\n\t\t\t\tif(x3 > x2 || x4 < x1 || y3 > y2 || y4 < y1) {\n\t\t\t\t\twhited = black(x1, y1, x2, y2);\n\t\t\t\t} else {\n\t\t\t\t\twhited = black(x1, y1, x2, y2);\n\t\t\t\t\tlong xm1 = Math.max(x1, x3);\n\t\t\t\t\tlong ym1 = Math.max(y1, y3);\n\t\t\t\t\tlong xm2 = Math.min(x2, x4);\n\t\t\t\t\tlong ym2 = Math.min(y2, y4);\n\t\t\t\t\twhited -= black(xm1, ym1, xm2, ym2);\n\t\t\t\t}\n\t\t\t\tb -= whited;w += whited;\n\t\t\t\tlong blacked = white(x3, y3, x4, y4);\n\t\t\t\tw-= blacked;b += blacked;\n\t\t\t\tout.println(w + \" \" + b);\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong black(long x1, long y1, long x2, long y2) {\n\t\t\tlong dx = (x2 - x1) + 1;\n\t\t\tlong dy = (y2 - y1) + 1;\n\t\t\tif((x1+y1)%2!=0) {\n\t\t\t\treturn ((dy+1)/2)*((dx+1)/2)+(dy/2)*(dx/2);\n\t\t\t}\n\t\t\treturn ((dy+1)/2)*((dx)/2)+(dy/2)*((dx+1)/2);\n\t\t}\n\t\t\n\t\tlong white(long x1, long y1, long x2, long y2) {\n\t\t\tlong dx = (x2 - x1) + 1;\n\t\t\tlong dy = (y2 - y1) + 1;\n\t\t\tif((x1+y1)%2==0) {\n\t\t\t\treturn ((dy+1)/2)*((dx+1)/2)+(dy/2)*(dx/2);\n\t\t\t}\n\t\t\treturn ((dy+1)/2)*(dx/2)+(dy/2)*((dx+1)/2);\n\t\t}\n\t\t\n\t}\n\t\n\tstatic void prepareIO(boolean isFileIO) {\n\t\t//long t1 = System.currentTimeMillis();\n\t\tTask solver = new Task();\n\t\t// Standard IO\n\t\tif(!isFileIO) { \n\t\t\tInputStream inputStream = System.in;\n\t        OutputStream outputStream = System.out;\n\t        InputReader in = new InputReader(inputStream);\n\t        PrintWriter out = new PrintWriter(outputStream);\n\t        solver.solve(in, out);\n\t        //out.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        out.close();\n\t\t}\n        // File IO\n\t\telse {\n\t\t\tString IPfilePath = System.getProperty(\"user.home\") + \"/Downloads/ip.in\";\n\t        String OPfilePath = System.getProperty(\"user.home\") + \"/Downloads/op.out\";\n\t        InputReader fin = new InputReader(IPfilePath);\n\t        PrintWriter fout = null;\n\t        try {\n\t\t\t\tfout = new PrintWriter(new File(OPfilePath));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t        solver.solve(fin, fout);\n\t        //fout.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t        fout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n        prepareIO(false);\n\t}\n\t\n\tstatic class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n        \n        public InputReader(String filePath) {\n        \tFile file = new File(filePath);\n            try {\n\t\t\t\treader = new BufferedReader(new FileReader(file));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n            tokenizer = null;\n        }\n        \n        public String nextLine() {\n        \tString str = \"\";\n        \ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n        \treturn str;\n        }\n        \n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n        \treturn Double.parseDouble(next());\n        }\n        \n    }\n\n}", "complexity": "constant", "problem": "1080_C. Masha and two friends", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tlong a = in.nextLong(), b = in.nextLong();\n\n\t\tlong ans = 0;\n\t\twhile (true) {\n\t\t\tlong div = a / b;\n\t\t\t\n\t\t\tans += div;\n\t\t\ta -= div * b;\n\t\t\t\n\t\t\tif (a == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tlong tmp = a;\n\t\t\ta = b;\n\t\t\tb = tmp;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\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\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\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\tpublic static final boolean DEBUG = false;\n\tScanner sc;\n\t\n\tpublic void debug(Object o) {\n\t\tif (DEBUG) {\n\t\t\tint ln = Thread.currentThread().getStackTrace()[2].getLineNumber();\n\t\t\tString fn = Thread.currentThread().getStackTrace()[2].getFileName();\n\t\t\tSystem.out.println(\"(\" + fn + \":\" + ln+ \"): \" + o);\n\t\t}\n\t}\n\t\n\tpublic void pln(Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\t\n\tpublic void run() {\n\t\tsc = new Scanner(System.in);\t\t\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tlong nr = 0;\n\t\tif (a < b) {\n\t\t\tlong aux = a;\n\t\t\ta = b;\n\t\t\tb = aux;\n\t\t}\n\t\twhile (a != 0 && b != 0) {\n\t\t\tnr += a / b;\n\t\t\tlong c = a % b;\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t}\n\t\t\n\t\tpln(nr);\n\t\treturn;\n\t\t\n\t}\n\tpublic static void main(String[] args) {\n\t\tA t = new A();\n\t\tt.run();\n\t}\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n  public static void main(String[] args){\n    FastScanner sc = new FastScanner();\n    long a = sc.nextLong();\n    long b = sc.nextLong();\n    long result = 0L;\n\n    while(a != 0 && b != 0) {\n      if(a > b) {\n        result += a/b;\n        a = a % b;\n      } else {\n        result += b/a;\n        b = b % a;\n      }\n\n      long gcd = gcd(a, b);\n      a /= gcd;\n      b /= gcd;\n    }\n\n      System.out.println(result);\n  }\n\n  private static long gcd(long a, long b) {\n    while(a != 0 && b != 0) {\n      if(a < b) {\n        long tmp = a;\n        a = b;\n        b = tmp;\n      }\n      a%=b;\n    }\n    return a + b;\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()) try {\n        st = new StringTokenizer(br.readLine());\n      } catch (IOException e) {\n        e.printStackTrace();\n      }\n      return st.nextToken();\n    }\n\n    int nextInt() {\n      return Integer.parseInt(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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n    long solve(long a, long b) {\n        return b == 0 ? 0 : a / b + solve(b, a % b);\n    }\n\n    public void run() {\n        try {\n            long a = reader.nextLong();\n            long b = reader.nextLong();\n            writer.println(solve(a, b));\n        } catch (IOException ex) {\n        }\n        writer.close();\n    }\n\n    InputReader reader;\n    PrintWriter writer;\n\n    Main() {\n        reader = new InputReader();\n        writer = new PrintWriter(System.out);\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n\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\n    Long nextLong() throws IOException {\n        return Long.parseLong(next());\n    }\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n    long solve(long a, long b) {\n        if (a == 0) {\n            return 0;\n        }\n        long answer = a / b;\n        a %= b;\n        if (a != 0) {\n            answer += 1 + solve(b - a, a);\n        }\n        return answer;\n    }\n\n    public void run() {\n        try {\n            long a = reader.nextLong();\n            long b = reader.nextLong();\n            writer.println(solve(a, b));\n        } catch (IOException ex) {\n        }\n        writer.close();\n    }\n\n    InputReader reader;\n    PrintWriter writer;\n\n    Main() {\n        reader = new InputReader();\n        writer = new PrintWriter(System.out);\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n\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\n    Long nextLong() throws IOException {\n        return Long.parseLong(next());\n    }\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\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    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        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n}\n\nclass TaskA {\n    public void solve(int testNumber, Parser in, OutputWriter out) {\n        long a = in.nextLong();\n        long b = in.nextLong();\n\n        long cnt = 0;\n        while (a != 0 && b != 0) {\n            if (a > b) {\n                cnt += a / b;\n                a %= b;\n            }\n            else {\n                cnt += b / a;\n                b = b % a;\n            }\n        }\n\n        out.println(cnt);\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 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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long a = in.nextLong();\n        long b = in.nextLong();\n\n        long res = 0;\n\n        while(a > 1 && b > 1) {\n            if(a < b) {\n                res += b / a;\n                b %= a;\n            }\n            else {\n                res += a / b;\n                a %= b;\n            }\n        }\n\n        if(a == 1)\n            res += b;\n        else\n            res += a;\n\n        out.println(res);\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 long nextLong() {\n        return Long.parseLong(nextString());\n    }\n\n    public String nextString() {\n        int c = read();\n        while (isSpaceChar(c))\n            c = read();\n        StringBuffer res = new StringBuffer();\n        do {\n            res.appendCodePoint(c);\n            c = read();\n        } while (!isSpaceChar(c));\n\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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class A\n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tScanner in = new Scanner(System.in);\n\n\t\tSystem.out.println(rec(in.nextLong(), in.nextLong()));\n\n\t}\n\n\tprivate static long rec(long a, long b)\n\t{\n\t\treturn b == 0 ? 0 : a/b + rec(b, a%b);\n\t}\n\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Contest200C {\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t//BufferedReader in = new BufferedReader(new FileReader(\"200C.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\t\n\t\tSystem.out.println(min(a,b));\n\t}\n\t\n\tstatic long min(long a, long b) {\n\t\tif (a <= 0 || b <= 0) return 0;\n\t\treturn a/b+min(b,a%b);\n\t}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        long a=s.nextLong(), b=s.nextLong();\n        long c=0;\n        while(true)  {\n            if(a==b ){\n                System.out.println(c+a);\n                return ;\n            } else if(b==a+1){\n                c+=1;\n                b=a;\n            } else if(b<a){\n\n                long h = a/b-1;\n                if(h<=0){\n                    a-=b;c++;continue;\n                }\n                a-=b*h;\n                c+=h;\n            } else{\n                if(a==1){\n                    long t = b-a;\n                    b = t;\n                    c+=t;\n                    b = a;\n                    continue;\n                }\n                long t = b-a;\n                long h = b/a - 1 ;\n                if(h<=0){\n                    b = t;\n                    c+=1;continue;\n                }\n                c+=h;b-=h*a;\n//                b = a;\n            }\n        }\n\n//        System.out.println(c);\n    }\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n  \n  public static void main(String[] args) throws Throwable {\n    new A().go();\n  }\n  \n  void p(String s) {\n    System.out.println(s);\n  }\n  \n  void go() throws Throwable {\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    String[] t = in.readLine().split(\" \");\n    long a = Long.parseLong(t[0]), b = Long.parseLong(t[1]);\n    long mv = 0;\n    while (a > 1 && b > 1) {\n      if (a > b) {\n        long tt = a;\n        a = b;\n        b = tt;\n      }\n      mv += b / a;\n      b %= a;\n    }\n    System.out.println(mv + Math.max(a, b));\n  }\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\tprivate static Scanner in;\n\n\tpublic void run() {\n\t\tlong a = in.nextLong();\n\t\tlong b = in.nextLong();\n\t\tlong ans = 0;\n\t\twhile (a > 0 && b > 0) {\n\t\t\tif (a >= b) {\n\t\t\t\tans += a / b;\n\t\t\t\ta %= b;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tans += b / a;\n\t\t\tb %= a;\n\t\t}\n\t\tSystem.out.println(ans);\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 A().run();\n\t\tin.close();\n\t}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class NewEmpty\n{\n    public static void main(String[] args)\n    {\n        Scanner blabla=new Scanner(System.in);\n        long a,b,c=0,d;\n        a=blabla.nextLong();\n        b=blabla.nextLong();\n        while (b!=0){\n            c+=(a/b);\n            a=a%b;\n            d=a;\n            a=b;\n            b=d;\n        }\n        System.out.println(c);\n    }\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tboolean eof;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().run();\n\t}\n\n\tpublic String nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn \"-1\";\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tvoid run() throws IOException {\n\t\tInputStream input = System.in;\n\t\tPrintStream output = System.out;\n\t\ttry {\n\t\t\tFile f = new File(\"trips.in\");\n\t\t\tif (f.exists() && f.canRead()) {\n\t\t\t\tinput = new FileInputStream(f);\n\t\t\t\toutput = new PrintStream(\"trips.out\");\n\t\t\t}\n\t\t} catch (Throwable e) {\n\t\t}\n\t\tbr = new BufferedReader(new InputStreamReader(input));\n\t\tout = new PrintWriter(output);\n\t\tsolve();\n\t\tbr.close();\n\t\tout.close();\n\t}\n\n\tclass Pair implements Comparable<Pair> {\n\t\tint x, y;\n\n\t\tPair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic int compareTo(Pair p) {\n\t\t\tif (x > p.x) {\n\t\t\t\treturn 1;\n\t\t\t} else if (x < p.x) {\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}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tlong ans;\n\t\n\tvoid nod(long a, long b){\n\t\tif (a == 0 || b == 0){\n\t\t\t\n\t\t} else if (a > b){\n\t\t\tans += a / b;\n\t\t\tnod(a % b, b);\n\t\t} else {\n\t\t\tans += b / a;\n\t\t\tnod(a, b % a);\n\t\t}\n\t}\n\t\n\tvoid solve() {\n\t\tlong a = nextLong(), b = nextLong();\n\t\tans = 0;\n\t\tnod(a, b);\n\t\tout.println(ans);\n\t}\n\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class cf343a {\n  static FastIO in = new FastIO(), out = in;\n\n  public static void main(String[] args) {\n    out.println(go(in.nextLong(),in.nextLong()));\n    out.close();\n  }\n  static long go(long a, long b) {\n    return b==0?0:(go(b,a%b) + a/b);\n  }\n\n  static class FastIO extends PrintWriter {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastIO() {\n      this(System.in, System.out);\n    }\n\n    public FastIO(InputStream in, OutputStream out) {\n      super(new BufferedWriter(new OutputStreamWriter(out)));\n      br = new BufferedReader(new InputStreamReader(in));\n      scanLine();\n    }\n\n    public void scanLine() {\n      try {\n        st = new StringTokenizer(br.readLine().trim());\n      } catch (Exception e) {\n        throw new RuntimeException(e.getMessage());\n      }\n    }\n\n    public int numTokens() {\n      if (!st.hasMoreTokens()) {\n        scanLine();\n        return numTokens();\n      }\n      return st.countTokens();\n    }\n\n    public String next() {\n      if (!st.hasMoreTokens()) {\n        scanLine();\n        return next();\n      }\n      return st.nextToken();\n    }\n\n    public double nextDouble() {\n      return Double.parseDouble(next());\n    }\n\n    public long nextLong() {\n      return Long.parseLong(next());\n    }\n\n    public int nextInt() {\n      return Integer.parseInt(next());\n    }\n  }\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class RationalResistance {\n\tstatic long n = 0;\n\n\tstatic void R(long a, long b) {\n\t\tn += a / b;\n\t\ta %= b;\n\t\tif (a == 0) {\n\t\t\treturn;\n\t\t}\n\t\tR(b, a);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner cin = new Scanner(System.in);\n\t\tlong a = cin.nextLong();\n\t\tlong b = cin.nextLong();\n\t\tcin.close();\n\t\tR(a, b);\n\t\tSystem.out.println(n);\n\t}\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class taskA {\n\n\tvoid solve() throws IOException {\n\t\tlong a = nextLong();\n\t\tlong b = nextLong();\n\n\t\tlong ans = 0;\n\t\twhile (a  != 0 && b != 0) {\n\t\t\tif (a > b) {\n\t\t\t\tans += a / b;\n\t\t\t\ta %= b;\n\t\t\t} else {\n\t\t\t\tlong c = b % a;\n\t\t\t\tans += b / a;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tvoid 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\t// br = new BufferedReader(new FileReader(new File(\"taskA.in\")));\n\t\t\t// out = new PrintWriter(\"taskA.out\");\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 taskA().run();\n\t}\n\n\tString nextToken() 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\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class p343a\n{\n    public static void main(String args[])\n    {\n        Scanner sc = new Scanner(System.in);\n        System.out.println();\n        long a = sc.nextLong();\n        long b = sc.nextLong();\n        if(a==b) System.out.println(\"1\");\n        else if(b==1) System.out.println(a);\n        else if(a==1) System.out.println(b);\n        else if(a>b) System.out.println(count(a,b));\n        else System.out.println(count(b,a));\n    }\n\n    public static long count(long a,long b)\n    {\n        long count = 0;\n        while(b!=1)\n        {\n            long c = a/b;\n            count += c;\n            long d = a-(c*b);\n            a = b;\n            b = d;\n            if(b==1)\n            {\n                count += a;\n                break;\n            }\n        }\n        return count;\n    }\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tstatic void solve() throws IOException {\n\t\tlong a = nextLong(), b = nextLong();\n\t\tlong answer = get(a, b);\n\t\tout.println(answer);\n\t}\n\n\tprivate static long get(long p, long q) {\n\t\tif (p == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (q == 1) {\n\t\t\treturn p;\n\t\t}\n\t\tif (p == 1) {\n\t\t\treturn q;\n\t\t}\n\t\tif (p >= q) {\n\t\t\treturn p / q + get(p % q, q);\n\t\t}\n\t\treturn q / p + get(p, q % p);\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}\n\t\tbr = new BufferedReader(new InputStreamReader(input));\n\t\tout = new PrintWriter(output);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tstatic String nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = br.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "//package CF;\n\n// Div One\nimport java.util.*;\n\npublic class CFA_200 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tlong x = sc.nextLong();\n\t\tlong y = sc.nextLong();\n\t\t\n\t\tSystem.out.println(Wilf_tree(x, y));\n\t\t\n\t\tsc.close();\n\t}\n\t\n\tstatic long Wilf_tree(long a,long b)\n\t{\n\t\tif(a==0||b==0)\n\t\t\treturn 0;\n\t\tif(a>=b)\n\t\t\treturn a/b+Wilf_tree(a%b, b);\n\t\telse\n\t\t\treturn b/a+Wilf_tree(a, b%a);\n\t}\n\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class Soal3 {\n    public static void main(String[] args) throws IOException{\n        BufferedReader baca = new BufferedReader(new InputStreamReader(System.in));\n        String[] masukan = baca.readLine().split(\" \");\n        BigInteger a = new BigInteger(masukan[0]);\n        BigInteger b = new BigInteger(masukan[1]);\n        \n        \n        \n        BigInteger i=new BigInteger(\"0\");\n        while(a.compareTo(new BigInteger(\"1\"))!=0){\n            if(a.compareTo(b)==1){\n                i=i.add(a.divide(b));\n                if(a.mod(b)==new BigInteger(\"0\")){\n                    a=new BigInteger(\"1\");\n                    b=new BigInteger(\"0\");\n                }\n                else{\n                    a=a.mod(b);\n                }\n                \n            }\n            else{\n                BigInteger temp =a;\n                a=b;\n                b=temp;             \n            }\n        }\n        if(a.compareTo(new BigInteger(\"1\"))==0){\n            i=i.add(b);\n        }\n        System.out.println(i.toString());\n    }\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\npublic class Ideone {\n\tstatic long ans=0;\n\tpublic static void Stepgcd(long a,long b) {\n\t\tif (b!=0) {ans+=(a/b);Stepgcd(b,a%b);}\n    }\n\tpublic static void main (String[] args) throws java.lang.Exception {\n\t\tScanner in=new Scanner(System.in);\n\t\tlong a=in.nextLong(),b=in.nextLong();\n\t\tStepgcd(a,b);\n\t\tSystem.out.println(ans);\n\t}\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tlong gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t} else {\n\t\t\treturn gcd(b, a % b);\n\t\t}\n\t}\n\n\tlong solve(long a,long b) {\n\t\tif (a == 0 || b ==0) {\n\t\t\treturn 0;\n\t\t}\n\t\tlong t = gcd(a,b);\n\t\ta /= t;\n\t\tb /= t;\n\t\tif (a>b) {\n\t\t\treturn solve(a%b,b)+a/b;\n\t\t} else {\n\t\t\treturn solve(a,b%a)+b/a;\n\t\t}\n\t\t\n\t}\n\n\tvoid solve() throws IOException {\n\t\tlong a = nextLong();\n\t\tlong b = nextLong();\n\t\tout.println(solve(a, b));\n\t}\n\n\tvoid run() 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().run();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer str;\n\n\tString next() throws IOException {\n\t\twhile (str == null || !str.hasMoreTokens()) {\n\t\t\tstr = new StringTokenizer(br.readLine());\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}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "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;\n\npublic class Task343A {\n\n\tpublic static void main(String... args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tSolution.main(System.in, System.out);\n\t}\n\n\tstatic class Scanner {\n\n\t\tprivate final BufferedReader br;\n\t\tprivate String[] cache;\n\t\tprivate int cacheIndex;\n\n\t\tScanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t\tcache = new String[0];\n\t\t\tcacheIndex = 0;\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn Integer.parseInt(cache[cacheIndex++]);\n\t\t}\n\n\t\tlong nextLong() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn Long.parseLong(cache[cacheIndex++]);\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\tif (cacheIndex >= cache.length) {\n\t\t\t\tcache = br.readLine().split(\" \");\n\t\t\t\tcacheIndex = 0;\n\t\t\t}\n\t\t\treturn cache[cacheIndex++];\n\t\t}\n\n\t\tvoid close() throws IOException {\n\t\t\tbr.close();\n\t\t}\n\n\t}\n\n\tstatic class Solution {\n\n\t\tprivate static long r(long a, long b) {\n\t\t\tif (a == 0 || b == 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (a > b) {\n\t\t\t\treturn a / b + r(b, a % b);\n\t\t\t}\n\t\t\treturn b / a + r(a, b % a);\n\t\t}\n\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 sc = new Scanner(is);\n\n\t\t\tlong a = sc.nextLong();\n\t\t\tlong b = sc.nextLong();\n\n\t\t\tpw.println(r(a, b));\n\n\t\t\tpw.flush();\n\t\t\tsc.close();\n\t\t}\n\t}\n\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n        long a = in.nextLong();\n        long b = in.nextLong();\n        if (a < b) {\n            long t = a;\n            a = b;\n            b = t;\n        }\n        long ans = 0;\n        while (b > 0) {\n            ans += a / b;\n            long t = a % b;\n            a = b;\n            b = t;\n        }\n        out.println(ans);\n    }\n}\n\nclass FastScanner extends BufferedReader {\n\n    public FastScanner(InputStream is) {\n        super(new InputStreamReader(is));\n    }\n\n    public int read() {\n        try {\n            int ret = super.read();\n//            if (isEOF && ret < 0) {\n//                throw new InputMismatchException();\n//            }\n//            isEOF = ret == -1;\n            return ret;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    public String next() {\n        StringBuilder sb = new StringBuilder();\n        int c = read();\n        while (isWhiteSpace(c)) {\n            c = read();\n        }\n        if (c < 0) {\n            return null;\n        }\n        while (c >= 0 && !isWhiteSpace(c)) {\n            sb.appendCodePoint(c);\n            c = read();\n        }\n        return sb.toString();\n    }\n\n    static boolean isWhiteSpace(int c) {\n        return c >= 0 && c <= 32;\n    }\n\n    public 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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class A {\t\n\tBufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter out;\n    \n\tpublic void solve() throws IOException {\t\t\t\t\n\t\tlong A = nextLong();\n\t\tlong B = nextLong();\t\t\n\t\tlong ans = 0;\n\t\twhile(A > 0){\n\t\t\tif(A >= B){\n\t\t\t\tans += A/B;\n\t\t\t\tA %= B;\n\t\t\t\tif(A == 0) break;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlong tmp = A; A = B; B = tmp;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\tout.println(ans);\n\t}\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\t\n\tpublic void run() {\n        try {\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        } 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}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputStreamReader in = new InputStreamReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputStreamReader inSt, PrintWriter out) {\n        InputReader in = new InputReader(inSt);\n        long a = in.nextLong();\n        long b = in.nextLong();\n\n        long result = 0;\n        while (b != 1) {\n            result += a / b;\n            long r = a % b;\n            long q = b;\n            long top = q % r;\n            long bottom = r;\n            result += q / r;\n            a = top;\n            b = bottom;\n        }\n        result += a;\n\n        out.println(result);\n    }\n\n    class InputReader {\n        public BufferedReader reader;\n        private String[] currentArray;\n        int curPointer;\n\n        public InputReader(InputStreamReader inputStreamReader) {\n            reader = new BufferedReader(inputStreamReader);\n        }\n\n        public String next() {\n            try {\n                currentArray = null;\n                return reader.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public void nextChars(char[] t) {\n            try {\n                currentArray = null;\n                reader.read(t);\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public char nextChar() {\n            try {\n                currentArray = null;\n                return (char) reader.read();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public int nextInt() {\n            if ((currentArray == null) || (curPointer >= currentArray.length)) {\n                try {\n                    currentArray = reader.readLine().split(\" \");\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                curPointer = 0;\n            }\n            return Integer.parseInt(currentArray[curPointer++]);\n        }\n\n        public long nextLong() {\n            if ((currentArray == null) || (curPointer >= currentArray.length)) {\n                try {\n                    currentArray = reader.readLine().split(\" \");\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                curPointer = 0;\n            }\n            return Long.parseLong(currentArray[curPointer++]);\n        }\n\n    }\n}\n\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.util.concurrent.ArrayBlockingQueue;\n\nimport org.omg.CORBA.UNKNOWN;\n\n\npublic class HelloWorld {\n\n    InputReader input;\n    PrintWriter output;\n    BufferedReader inp;\n\n    void run(){\n        output = new PrintWriter(new OutputStreamWriter(System.out));\n        input = new InputReader(System.in);\n        inp = new BufferedReader(new InputStreamReader(System.in));\n        solve();\n        output.flush();\n    }\n\n    public static void main(String[] args){\n        new HelloWorld().run();\n    }\n    \n    long stps;\n    \n    long gcd(long a, long b) {\n        if(b == 0 || a == 0) {\n            return 0;\n        }\n        return a/b + gcd(b, a%b);\n    }\n    \n    void solve() {\n        long a = input.readLong();\n        long b = input.readLong();\n        stps = gcd(a, b);\n        output.println(stps);\n    }\n    \n    \n    \n    class node implements Comparable<node>{\n        int destination;\n        int direction;\n        int distance;\n        \n        public node(int destination, int distance, int direction) {\n            this.direction = direction;\n            this.distance = distance;\n            this.destination = destination;\n        }\n        \n        public int compareTo(node b) {\n            return this.distance - b.distance;\n        }\n    }\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\n        public int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars)\n            {\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            {\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            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 Long readLong() {\n            return Long.parseLong(readString());\n        }\n\n        public Double readDouble() {\n            return Double.parseDouble(readString());\n        }\n\n        public boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n    } \n\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "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 dudkamaster\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\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long a = in.nextLong();\n        long b = in.nextLong();\n        long ans = 0;\n        while (a > 0 && b > 0){\n            if (a < b){\n                long t = a;\n                a = b;\n                b = t;\n            }\n            ans += a/b;\n            a %= b;\n        }\n        out.print(ans);\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 (Exception 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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tlong a = nextLong();\n\t\tlong b = nextLong();\n\t\tlong res = 0;\n\t\twhile (b > 0) {\n\t\t\tres += a / b;\n\t\t\tlong t = a % b;\n\t\t\ta = b;\n\t\t\tb = t;\n\t\t}\n\t\tout.println(res);\n\t}\n\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tprivate String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString rl = in.readLine();\n\t\t\tif (rl == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(rl);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.UK);\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//in = new BufferedReader(new FileReader(\"a.in\"));\n\t\t\t//out = new PrintWriter(new FileWriter(\"a.out\"));\n\n\t\t\t_main();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(202);\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "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\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long a = in.nextLong();\n        long b = in.nextLong();\n        out.println(go(a, b));\n    }\n\n    private long go(long a, long b) {\n        if (b == 0) return 0;\n        return a / b + go(b, a % b);\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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "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\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public long recurse(long a, long b) {\n        if (b <= 1) return a;\n        return Math.max(a, b)/Math.min(a,b) + recurse(Math.max(a, b) - Math.min(a, b)*(Math.max(a,b)/Math.min(a, b)), Math.min(a, b));\n    }\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        long a = in.readLong(), b = in.readLong(), i = 0;\n//        while(true) {\n//            if (b <= 1){\n//                i += a;\n//                out.print(i);\n//                return;\n//            }\n//            i++;\n//            long aa = Math.max(a, b);\n//            long bb = Math.min(a, b);\n//            aa -= bb;\n//            a = aa;\n//            b = bb;\n//        }\n//        out.print(i);\n        out.print(recurse(a, b));\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(long i) {\n\t\twriter.print(i);\n\t}\n}\n\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class C {\n\tstatic long n = 0;\n\t\tstatic void R (long a,long b){\n\t\t\tn += a/b;\n\t\t\ta = a%b;\n\t\t\tif(a==0) return;\n\t\t\tR(b,a);\n\t\t}\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\tR(a,b);\n\t\tSystem.out.println(n);\n\t}\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tlong getAns(long a, long b) {\n\t\tif (a == b)\n\t\t\treturn 1;\n\t\tif (a < b) {\n\t\t\treturn getAns(b, a);\n\t\t}\n\t\t// a > b\n\t\tlong cnt = (a - 1) / b;\n\t\treturn cnt + getAns(b, a - b * cnt);\n\t}\n\n\tvoid solve() {\n\t\tlong a = in.nextLong();\n\t\tlong b = in.nextLong();\n\t\tout.println(getAns(a, b));\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\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}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class ProblemA {\n\t\n\tstatic final int INF = 100000000;\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\t\n\t\tString[] nmd = in.readLine().split(\" \");\n\t\tlong a = Long.valueOf(nmd[0]);\n\t\tlong b = Long.valueOf(nmd[1]);\n\n\t\tlong cnt = 0;\n\t\twhile (true) {\n\t\t\tif (a == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (a >= b) {\n\t\t\t\tcnt += a / b;\n\t\t\t\ta = a % b;\n\t\t\t} else {\n\t\t\t\tif (b % a == 0) {\n\t\t\t\t\tcnt += b / a - 1;\n\t\t\t\t\tb = a;\n\t\t\t\t} else {\n\t\t\t\t\tcnt += b / a;\n\t\t\t\t\tb = b % a;\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(cnt);\n\t\tout.flush();\n\t}\n\n\t\n\tpublic static void debug(Object... o) {\n\t\tSystem.err.println(Arrays.deepToString(o));\n\t}\n}\n\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\tstatic BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st = new StringTokenizer(\"\");\n\n\tstatic String readString() throws Exception {\n\t\twhile(!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(stdin.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tstatic int readInt() throws Exception {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\tstatic long readLong() throws Exception {\n\t\treturn Long.parseLong(readString());\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tlong a = readLong();\n\t\tlong b = readLong();\n\t\t\n\t\tSystem.out.println(rec(a,b));\n\n\t}\n\n\tprivate static long rec(long a, long b) {\n\t\tif(a == 1){\n\t\t\treturn b;\n\t\t}\n\t\tif(a >= b){\n\t\t\treturn a/b + rec(a%b, b);\n\t\t}\n\t\treturn rec(b, a);\n\t}\n\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class C344C {\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 = a / b, c;\n\t\ta = a % b;\n\t\twhile(true){\n\t\t\tif (a <= 1 || b <= 1) break;\n\t\t\tc = b - a;\n\t\t\tb = a;\n\t\t\ta = c;\n\t\t\tcount++;\n\t\t\tif (a > b) count += a / b;\n\t\t\ta = a % b;\n\t\t}\n\t\tif (b > 1) count += b;\n\t\tSystem.out.println(count);\t\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class RationalResistance {\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(System.out);\n\t\tStringTokenizer st=new StringTokenizer(f.readLine());\n\t\tlong a=Long.parseLong(st.nextToken());\n\t\tlong b=Long.parseLong(st.nextToken());\n\t\tlong sum = 0;\n\t\twhile(a!= 0 && b!= 0){\n\t\t\tif (a > b){\n\t\t\t\tlong val = a / b;\n\t\t\t\tsum += val;\n\t\t\t\ta -= val * b;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlong val = b / a;\n\t\t\t\tsum += val;\n\t\t\t\tb -= val * a;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(sum);\n\t\tout.close();\n\t\tSystem.exit(0);\n\t}\n\t\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    \n    public static long func(long a, long b) {\n        \n        if (a < b)\n            return func(b, a);\n    \tif (b < 2)\n            return a;\n        long q = a / b;\n        long r = a - q * b;\n        return q + func(b, r);\n    }\n    \n    public static void main(String[] args) throws IOException {\n        \n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String[] ss = br.readLine().split(\" +\");\n        long a = Long.parseLong(ss[0]);\n        long b = Long.parseLong(ss[1]);\n        \n        System.out.println(func(a, b));\n        \n    }\n    \n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n    \n    \n    \n    public void solve() throws Throwable {\n        long a = sc.nextLong();\n        long b = sc.nextLong();\n        long ans = 0;\n        while (a > 0 && b > 0) {\n            if (a > b) {\n                ans += a/b;\n                a %= b;\n            } else {\n                ans += b/a;\n                b %= a;\n            }\n        }\n        out.println(ans);\n    }\n    \n    static Throwable t;\n    \n    BufferedReader reader;\n    FastScanner sc;\n    PrintWriter out;\n    \n    public static void main(String[] args) throws Throwable {\n        Thread thread = new Thread(null, new Main(), \"\", 1 << 26);\n        thread.start();\n        thread.join();\n        if (Main.t != null)\n            throw t;\n    }\n\n    @Override\n    public void run() {\n        try {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n            sc = new FastScanner(reader);\n            solve();\n        } catch (Throwable t) {\n            Main.t = t;\n        } finally {\n            out.close();\n        }\n    }\n}\n\nclass FastScanner {\n    BufferedReader reader;\n    StringTokenizer strtok;\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 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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n  public static void main(String args[]) throws IOException {\n    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n    String line = stdin.readLine();\n    String[] prms = line.split(\" \");\n    \n    long a = Long.parseLong(prms[0]);\n    long b = Long.parseLong(prms[1]);\n    \n    long cnt = 0;\n    while (a > 0 && b > 0) {\n      if (a >= b) {\n        cnt += a / b;\n        a =  a % b;\n      }\n      long c = a;\n      a = b;\n      b = c;\n    }\n    \n    System.out.println(cnt);\n  }\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\n\npublic class A {\n\n    static StringTokenizer st;\n    static BufferedReader br;\n    static PrintWriter pw;\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        long x = nextLong();\n        long y = nextLong();\n        long ans = 0;\n        while (x > 0 && y > 0) {\n            if (x > y) {\n                ans += x / y;\n                x %= y;\n            }\n            else {\n                ans += y / x;\n                y %= x;\n            }\n        }\n        System.out.println(ans);\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", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        long a = in.nextLong();\n        long b = in.nextLong();\n        long res = 0;\n        while (b > 0) {\n            res += a / b;\n            long t = a % b;\n            a = b;\n            b = t;\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 long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    }\n\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class c {\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    long a = input.nextLong(), b = input.nextLong();\n    System.out.println(gcd(a, b));\n}\nstatic long gcd(long a, long b)\n{\n    if(b==1) return a;\n    if(a==1) return b;\n    if(a>b) return a/b + gcd(b, a%b);\n    return b/a + gcd(a, b%a);\n}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew A().doit();\n\t}\n\t\n\tprivate void doit() throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tlong a = Long.parseLong(st.nextToken());\n\t\tlong b = Long.parseLong(st.nextToken());\n\t\tlong ans = 0;\n\t\twhile(a > 0 && b > 0) {\n\t\t\tif (a > b) {\n\t\t\t\tans += a / b;\n\t\t\t\ta %= b;\n\t\t\t} else {\n\t\t\t\tans += b / a;\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n\t\n\t\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\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        System.out.println(f(A,B));\n    }\n    static long f(long A, long B) {\n        if(A==0) return 0;\n        if(A < B) return f(B,A);\n        else {\n            long k = A/B;\n            return k+f(A-B*k, B);\n        }\n    }\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class p343A \n{\n    static long n = 0;\n    static void resistance(long a, long b) \n    {\n        n += a/b;\n        a %= b;\n        if(a!=0) resistance(b, a);\n    }\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        long a = in.nextLong();\n        long b = in.nextLong();\n        resistance(a, b);\n        System.out.println(n);\n    }\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class RationalResistance {\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        long a = Long.parseLong(st.nextToken());\n        long b = Long.parseLong(st.nextToken());\n        System.out.println(f(a,b));\n    }\n    \n    public static long f(long a, long b)\n    {\n        if (a == 1 || b == 1)\n            return a+b-1;\n        if (a > b)\n            return f(a%b,b) + a/b;\n        else\n            return f(a,b%a) + b/a;\n    }\n}", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\n\tpublic long gcd(long a, long b) {\n\t\tlong tmp;\n\t\twhile (b > 0) {\n\t\t\ta %= b;\n\t\t\ttmp = a;\n\t\t\ta = b;\n\t\t\tb = tmp;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\tpublic void solve() throws Exception {\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tlong ans = 0;\n\t\tlong k = 0;\n\t\tif (a == 1 || b == 1) {\n\t\t\tout.println(max(a, b));\n\t\t\treturn;\n\t\t}\n\t\twhile (a > 1 && b > 1) {\n\t\t\tif (a > b) {\n\t\t\t\tk = a / b;\n\t\t\t\tans += k;\n\t\t\t\ta -= (k * b);\t\t\t\t\n\t\t\t} else {\n\t\t\t\tk = b / a;\n\t\t\t\tans += k;\n\t\t\t\tb -= (k * a);\n\t\t\t}\n\t\t\tk = gcd(a, b);\n\t\t\ta /= k;\n\t\t\tb /= k;\n\t\t}\n\t\tif (a == 1)\n\t\t\tans += b;\n\t\telse\n\t\t\tans += a;\n\t\tout.println(ans);\n\t}\n\t\n\tstatic Throwable throwable;\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\t\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 (throwable != null) {\n\t\t\tthrow throwable;\n\t\t}\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\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable throwable) {\n\t\t\tthis.throwable = throwable;\t\t\t\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\t\t\n\t}\n\n}\n\nclass FastScanner {\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 Exception {\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 Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.StreamTokenizer;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author KNIGHT0X300\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\tInputStreamReader in = new InputStreamReader(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    StreamTokenizer in;\n    PrintWriter out;\n    BufferedReader re;\n    Scanner sc;\n    public void solve (int testNumber, InputStreamReader in, PrintWriter out)  {\n\n          this.in = new StreamTokenizer(new BufferedReader(in));\n          this.re =  new BufferedReader(in);\n          this.sc = new Scanner(in);\n          this.out = out;\n          try {\n                      this.solve();\n                  } catch (IOException e) {\n                      e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.\n                  }\n          out.flush();\n\n    }\n\n         void solve() throws IOException\n       {\n        long a=sc.nextLong(),b=sc.nextLong();\n           long ans=0,t;\n          while(Math.min(a,b)!=1){\n              if(a>b){\n                  ans+=a/b;\n                  a%=b;\n\n              }\n              else{\n                  t=b;\n                  b=a;\n                  a=t;\n                  long g=gcd(a,b);\n                  a/=g;b/=g;\n              }\n\n          }\n           ans+=Math.max(a,b);\n           out.println(ans);\n\n       }\n     public static long gcd(long a, long b) {\n       long c = 0;\n\n     if(a<0)  a=-a;\n       if(b<0)  b=-b;\n       while (b>0) {\n          c = a % b;\n          a = b;\n          b = c;\n       }\n       return a;\n     }\n\n\n         // do the sum\n\n}\n\n", "complexity": "constant", "problem": "343_A. Rational Resistance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class cf {\n\n\tstatic class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner() {\n            try {\n                br = new BufferedReader(new InputStreamReader(System.in));\n                st = new StringTokenizer(br.readLine());\n            } catch (Exception e){e.printStackTrace();}\n        }\n\n        public String next() {\n            if (st.hasMoreTokens()) return 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 static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int n = sc.nextInt();\n        pw.println(n/2+1);\n        pw.close();\n    }\n}", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "\nimport java.io.PrintWriter;\n\nimport java.util.*;\nimport java.util.Arrays ; \nimport java .lang.String.* ;\nimport java .lang.StringBuilder ;\n\n\npublic class Test{\n    static int pos = 0 ; \n    static int  arr[] ; \n  static LinkedList l1 = new  LinkedList() ; \nstatic void find(int p ,char[]x,int put[],String s){\n    int c= 0 ; \n    for (int i = 0; i < s.length(); i++) {\n        if(x[p]==s.charAt(i)){\n        c++ ; }\n    }\n    put[p] = c ;  \n}\nstatic int mode(int m ,int[]x ){\n    int temp = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return m-temp ; \n             \n        }\n    }\n     return m-temp ; \n}\nstatic int mode2(int m ,int[]x ){\n    int temp = 0 ; \n    \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]<=m){\n            temp= x[i] ; \n           /// break ; \n             return x[i] ; \n             \n        }\n    }\n     return 0 ; \n}\nstatic int find(int x[],int temp){\n    int j = 0 ; \n    for (int i = x.length-1; i >=0; i--) {\n        if(x[i]==temp) return j+1 ; \n        j++ ; \n    }\n    return -1 ; \n}\nstatic String ch(long[]x,long b){\n    for (int i = 0; i < x.length; i++) {\n        if(x[i]==b)return \"YES\" ;\n    }\n    return \"NO\" ; \n}\n\n    public static void main(String[] args)  {\n\n        Scanner in = new Scanner(System.in) ;\n        PrintWriter pw = new PrintWriter(System.out);   \n        long n = in.nextLong() ; \n        long count =1 ; \n        long temp =n/2;\n     temp+=count ;\n      \n       \n        System.out.println(temp);\n }               \n}\n\n", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class CodeForces\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n\t\tSystem.out.println(input.nextInt() / 2 + 1);\n\t}\n}", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class programA {\n\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\tif(n%2 == 0)System.out.println(n/2 +1);\n\t\telse System.out.println((int)Math.ceil((double)n/2));\n\t}\n}\n\n\n\n\n", "complexity": "constant", "problem": "964_A. Splits", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n \n/**\n *\n * @author Antonio \"Teo\" Alurralde\n */\npublic class Main {\n  public static void main(String[] args) throws IOException {\n    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    int n = Integer.parseInt(br.readLine());\n    StringTokenizer tok = new StringTokenizer(br.readLine());\n    int ax = Integer.parseInt(tok.nextToken());\n    int ay = Integer.parseInt(tok.nextToken());\n    tok = new StringTokenizer(br.readLine());\n    int bx = Integer.parseInt(tok.nextToken());\n    int by = Integer.parseInt(tok.nextToken());\n    tok = new StringTokenizer(br.readLine());\n    int cx = Integer.parseInt(tok.nextToken());\n    int cy = Integer.parseInt(tok.nextToken());\n    boolean ans = (bx < ax && cx < ax && by < ay && cy < ay) ||\n    (bx < ax && cx < ax && by > ay && cy > ay) ||\n    (bx > ax && cx > ax && by < ay && cy < ay) ||\n    (bx > ax && cx > ax && by > ay && cy > ay);\n    System.out.print(ans?\"YES\":\"NO\");\n  }\n}\n", "complexity": "constant", "problem": "1033_A. King Escape", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class KingEscape {\n\n    public static void main(String[] args) {\n        Reader read = new Reader();\n\n        int n = read.nextInt();\n        int a1 = read.nextInt();\n        int a2 = read.nextInt();\n        int b1 = read.nextInt();\n        int b2 = read.nextInt();\n        int c1 = read.nextInt();\n        int c2 = read.nextInt();\n\n        if (b1 > a1 && b2 > a2 && c1 > a1 && c2 > a2)\n            System.out.print(\"YES\");\n        else if (b1 > a1 && b2 < a2 && c1 > a1 && c2 < a2)\n            System.out.print(\"YES\");\n        else if (b1 < a1 && b2 > a2 && c1 < a1 && c2 > a2)\n            System.out.print(\"YES\");\n        else if (b1 < a1 && b2 < a2 && c1 < a1 && c2 < a2)\n            System.out.print(\"YES\");\n        else\n            System.out.print(\"NO\");\n    }\n\n    private static class Reader {\n\n        private final BufferedReader reader;\n        private final String separator;\n        private String ln;\n        private String[] tokens;\n        private int ptr;\n\n        Reader(String separator, InputStream input) {\n            this.reader = new BufferedReader(new InputStreamReader(input));\n            this.separator = separator;\n            this.ptr = -1;\n        }\n\n        Reader(String separator) { this(separator, System.in); }\n\n        Reader() { this(\" \"); }\n\n        String nextStr(){\n            if (Objects.isNull(ln)) {\n                try {\n                    ln = reader.readLine();\n                } catch (IOException e) {\n                    System.out.println(e.getMessage());\n                }\n                if (Objects.nonNull(ln)) {\n                    tokens = ln.split(separator);\n                    ptr = 0;\n                } else {\n                    throw new NoSuchElementException(\"no next element\");\n                }\n\n            } else if (ptr == tokens.length) {\n                ln = null;\n                tokens = null;\n                ptr = -1;\n                return nextStr();\n            }\n\n            return tokens[ptr++];\n        }\n\n        int nextInt() { return Integer.parseInt(nextStr()); }\n\n        long nextLong() { return Long.parseLong(nextStr()); }\n\n        double nextDouble() { return Double.parseDouble(nextStr()); }\n    }\n}\n", "complexity": "constant", "problem": "1033_A. King Escape", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Solve4 {\n\n    public static void main(String[] args) throws IOException {\n      FastReader sc = new FastReader();\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(Math.abs(x-y)*t1 < (Math.abs(x-z)+Math.abs(x-y))*t2+3*t3 ) System.out.println(\"NO\");\n      else System.out.println(\"YES\");\n    }\n\n    static class FastReader {\n\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n\n        public String next() throws IOException {\n            if (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(br.readLine());\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() throws IOException {\n            return Double.parseDouble(next());\n        }\n\n        public String nextLine() {\n            String s = \"\";\n            try {\n                s = br.readLine();\n            } catch (IOException ex) {\n            }\n            return s;\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "1054_A. Elevator or Stairs?", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n    public static void main (String[] args) {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        try {\n            String parameterStringList[] = reader.readLine().split(\" \");\n            int x = Integer.parseInt(parameterStringList[0]);\n            int y = Integer.parseInt(parameterStringList[1]);\n            int z = Integer.parseInt(parameterStringList[2]);\n            int t1 = Integer.parseInt(parameterStringList[3]);\n            int t2 = Integer.parseInt(parameterStringList[4]);\n            int t3 = Integer.parseInt(parameterStringList[5]);\n\n            int T1 = Math.abs(x-y) * t1;\n            int T2 = Math.abs(x-z) * t2 + 3*t3 + Math.abs(x-y) * t2;\n\n            if(T2 <= T1) System.out.println(\"YES\");\n            else System.out.println(\"NO\");\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}", "complexity": "constant", "problem": "1054_A. Elevator or Stairs?", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\npublic class ElevatorOrStairs {\n\n\tprivate static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static final OutputStreamWriter writer = new OutputStreamWriter(System.out);\n\t\n\tpublic static void main(String...strings) throws Exception {\n\t\tString[] specs = reader.readLine().split(\" \");\n\t\t\n\t\tint x = Integer.parseInt(specs[0]);\n\t\tint y = Integer.parseInt(specs[1]);\n\t\tint z = Integer.parseInt(specs[2]);\n\t\tint t1 = Integer.parseInt(specs[3]);\n\t\tint t2 = Integer.parseInt(specs[4]);\n\t\tint t3 = Integer.parseInt(specs[5]);\n\t\t\n\t\treader.close();\n\t\tString ans = solve(x, y, z, t1, t2, t3);\n\t\twriter.append(ans);\n\t\twriter.flush();\n\t\twriter.close();\n\t}\n\t\n\tprivate static String solve(int x, int y, int z, int t1, int t2, int t3) {\n\t\tint time_using_stairs = Math.abs(x - y) * t1;\n\t\tint elevator_time_between_floor = Math.abs(x - z) * t2;\n\t\tint elevator_from_z_to_x = elevator_time_between_floor + 2*t3;\n\t\t\n \t\tint time_using_elevator = elevator_from_z_to_x + (Math.abs(x - y) * t2) + t3;\n \t\t\n \t\tif(time_using_elevator <= time_using_stairs) {\n \t\t\treturn \"YES\";\n \t\t}\n \t\treturn \"NO\";\n\t}\n}", "complexity": "constant", "problem": "1054_A. Elevator or Stairs?", "from": "CODEFORCES"}
{"src": "    import java.util.Scanner;\n\n    public class Sasha1113A {\n\n        static int solution(int n, int v){\n            int count;\n            if(v>=n)\n                return n-1;\n            else{\n                count = (v-1) + ((n-v)*(n-v+1))/2;\n            }\n            return count;\n        }\n\n        public static void main(String[] args){\n            Scanner scan = new Scanner(System.in);\n            int n = scan.nextInt();\n            int v = scan.nextInt();\n\n            System.out.print(solution(n, v));\n        }\n    }\n", "complexity": "constant", "problem": "1113_A. Sasha and His Trip", "from": "CODEFORCES"}
{"src": "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.Iterator;\nimport java.util.Objects;\nimport java.util.Stack;\n\n\nimport java.util.StringTokenizer;\n\n\n public class Test\n {\n    \n     static PrintWriter pw = new PrintWriter(System.out);\n\n    public static void main(String[] args)throws Exception\n    {\n        Reader.init(System.in);\n        int n = Reader.nextInt();\n        int p = Reader.nextInt();\n        int L = Reader.nextInt();\n        int R = Reader.nextInt();\n        int a = 1;\n        int b = n;\n        int res = 0;\n        \n        if(a == L && b == R)\n        {\n            res = 0;\n        }\n        else if(L != a && R != b && p >= L && p <= R)\n        {\n            res = Math.min(p-L, R-p);\n            res += R- L + 2;\n        }\n        else if(L != a && R != b && p < L )\n        {\n            res += L-p + 1;\n            res += R - L +1;\n        }\n        else if(L != a && R != b && p > R)\n        {\n            res += p-R + 1;\n            res += R - L +1;\n        }\n        else if(a == L && p >=L && p<=R)\n        {\n            res += R - p + 1;\n        }\n        else if(R == b && p>=L && p<=R)\n        {\n            res += p - L + 1;\n        }\n        else if(a == L && p > R)\n        {\n            res += p - R + 1;\n        }\n        else if(R == b && p<L)\n        {\n            res += L - p + 1;\n        }\n            \n            \n        pw.print(res);\n        pw.close();\n \n    }\n        \n}\n\nclass Reader {\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    public static int pars(String x) {\n        int num = 0;\n        int i = 0;\n        if (x.charAt(0) == '-') {\n            i = 1;\n        }\n        for (; i < x.length(); i++) {\n            num = num * 10 + (x.charAt(i) - '0');\n        }\n\n        if (x.charAt(0) == '-') {\n            return -num;\n        }\n\n        return num;\n    }\n\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                new InputStreamReader(input));\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    static void init(FileReader input) {\n        reader = new BufferedReader(input);\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    static String next() throws IOException {\n        while (!tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(\n                    reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    static int nextInt() throws IOException {\n        return pars(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}", "complexity": "constant", "problem": "915_B. Browser", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class LuckyDivision {\n\tpublic static void main (String[] args) {\n\t\tScanner read = new Scanner(System.in);\n\t\tint n = read.nextInt();\n\t\t\n\t\tif (n % 4 == 0 ||\n\t\t\tn % 7 == 0 ||\n\t\t\tn % 47 == 0 ||\n\t\t\tn % 74 == 0 ||\n\t\t\tn % 447 == 0 ||\n\t\t\tn % 474 == 0 ||\n\t\t\tn % 477 == 0 ||\n\t\t\tn % 744 == 0 ||\n\t\t\tn % 747 == 0 ||\n\t\t\tn % 774 == 0)\t{\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\telse {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\t\n\t}\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class LuckyDivison \n{\n    public static void main(String[] args)\n    {\n        Scanner in = new Scanner(System.in);\n        int inp = in.nextInt();\n        if(inp%4==0||inp%7==0||inp%47==0||inp%74==0||inp%447==0||inp%474==0||inp%477==0||inp%747==0||inp%774==0||inp%777==0)\n        {\n          System.out.println(\"YES\");  \n        }\n        else System.out.println(\"NO\");\n          \n        \n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Test{\n    public static void main(String[] args) {\n        Scanner in= new Scanner(System.in);\n        int n=in.nextInt();\n        if(n%7==0 || n%4==0 || n%47==0 || n%74==0 || n%447==0 || n%474==0 || n%477==0 || n%747==0 || n%774==0){\n            System.out.println(\"YES\");\n        }else\n            System.out.println(\"NO\");\n        \n    }\n}\n\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A122 {\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint n = in.nextInt();\n\n\t\tif (n % 4 == 0 || n % 7 == 0 || n % 44 == 0 || n % 47 == 0\n\t\t\t\t|| n % 74 == 0 || n % 77 == 0 || n % 444 == 0 || n % 447 == 0\n\t\t\t\t|| n % 474 == 0 || n % 477 == 0 || n % 744 == 0 || n % 747 == 0\n\t\t\t\t|| n % 774 == 0 || n % 777 == 0)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\n\t}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        String input = in.nextLine();\n        if (input.equals(\"1\"))\n            System.out.println(\"NO\");\n        else {\n            if (checkNum(input))\n                System.out.println(\"YES\");\n            else {\n                int i = 2;\n                while (i < Integer.parseInt(input)) {\n                    if (checkNum(i + \"\")) {\n                        if (Integer.parseInt(input) % i != 0)\n                            i++;\n                        else\n                            break;\n                    } else\n                        i++;\n                }\n                if (i == Integer.parseInt(input))\n                    System.out.println(\"NO\");\n                else\n                    System.out.println(\"YES\");\n            }\n        }\n    }\n\n    public static boolean checkNum(String s) {\n        int i = 0;\n        int flag = 0;\n        while (i < s.length()) {\n            if (s.charAt(i) == '4' || s.charAt(i) == '7') {\n                flag = 1;\n                i++;\n            } else\n                return false;\n        }\n        if (flag == 1)\n            return true;\n        return false;\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n\n    ArrayList<Integer> list = new ArrayList<Integer>();\n    \n    \n    boolean valid(int n) {\n        Queue<Integer> q = new LinkedList<Integer>();\n        q.add(4);\n        q.add(7);\n        int crnt;\n        while(!q.isEmpty()) {\n            crnt = q.poll();\n            if(n%crnt == 0) return true;\n            if ( crnt*10 + 4 <= 1000 ) q.add(crnt*10 + 4);\n            if ( crnt*10 + 7 <= 1000 ) q.add(crnt*10 + 7);\n        }\n        return false;\n    }\n    \n    void dfs(int n){\n        if(n>1000)return;\n        if(n!=0)list.add(n);\n        n = n*10;\n        dfs(n+4);\n        dfs(n+7);\n    }\n\n    void run() {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        if (valid(n)) {\n            System.out.println(\"YES\");\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n\n    public static void main(String[] args) {\n        new A().run();\n    }\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class CF {\n        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=null;\n        private void  solution() throws IOException{\n   int n=nextInt();\n   if((n % 4==0 && n>=4)||(n % 7==0 && n>=7) || (n % 44==0 && n>=44) || (n % 47==0 && n>=47) || (n % 77==0 && n>=77) || (n % 74==0 && n>=74)\n   || (n % 444==0 && n>=444) || (n % 447==0 && n>=447) || (n % 474==0 && n>=74) || (n % 477==0 && n>=477) || (n % 744==0 && n>=744)\n   || (n % 747==0 && n>=747) || (n % 777==0 && n>=777) || (n % 774==0 && n>=774)){\n           System.out.println(\"YES\");\n   }else{\n                System.out.println(\"NO\");}\n        }\n        String nextToken()throws IOException {\n                if(st==null || !st.hasMoreTokens()){\n                        st = new StringTokenizer(bf.readLine());\n                }\n                return st.nextToken();\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        public static void main(String args[]) throws IOException {\n                new CF().solution();\n        }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\n\npublic class LuckyDivision\n{\n   public LuckyDivision(Scanner in)\n   {\n      int   n;\n\n      n = in.nextInt();\n\n      if ( (n % 4 == 0) ||\n           (n % 7 == 0) ||\n           (n % 44 == 0) ||\n           (n % 47 == 0) ||\n           (n % 74 == 0) ||\n           (n % 77 == 0) ||\n           (n % 444 == 0) ||\n           (n % 447 == 0) ||\n           (n % 474 == 0) ||\n           (n % 477 == 0) ||\n           (n % 744 == 0) ||\n           (n % 747 == 0) ||\n           (n % 774 == 0) ||\n           (n % 777 == 0) )\n         System.out.printf(\"YES%n\");\n      else\n         System.out.printf(\"NO%n\");\n   }\n\n\n   public static void main(String[] args)\n   {\n      new LuckyDivision(new Scanner(System.in));\n   }\n}\n\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class D\n{\n public static void main(String args[])\n  {\n   int n;\n   Scanner in = new Scanner (System.in);\n   n= in.nextInt();\n   if (n%4==0 || n%7==0 || n%44==0 || n%47==0 || n%444==0 || n%447==0 ||\n       n%474==0 || n%477==0 || n%744==0 || n%747==0 || n%774==0 || n%777==0)\n       System.out.println(\"YES\"); else System.out.println(\"NO\");\n  }\n}\n\t\t \t\t \t \t  \t \t\t\t \t  \t \t \t", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n/**\n * @author Son-Huy TRAN\n * \n */\npublic class P122A_LuckyDivision {\n\n\tprivate static boolean isLuckyNumber(int number) {\n\t\twhile (number > 0) {\n\t\t\tint digit = number % 10;\n\n\t\t\tif (digit != 4 && digit != 7) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tnumber /= 10;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate static boolean isAlmostLuckyNumber(int number) {\n\t\tint max = (int) Math.sqrt(number);\n\t\tint i = 1;\n\n\t\twhile (i <= max) {\n\t\t\tif (number % i == 0\n\t\t\t\t\t&& (isLuckyNumber(i) || isLuckyNumber(number / i))) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\ti++;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\t// begin reading inputs\n\t\t\tInputStreamReader isr = new InputStreamReader(System.in);\n\t\t\tBufferedReader reader = new BufferedReader(isr);\n\n\t\t\t// reading inputs\n\t\t\tint input = Integer.parseInt(reader.readLine());\n\n\t\t\treader.close();\n\t\t\tisr.close();\n\t\t\t// end reading inputs\n\n\t\t\tboolean result = isAlmostLuckyNumber(input);\n\t\t\tSystem.out.println(result ? \"YES\" : \"NO\");\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Lucky {\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\n\t\tint n = in.nextInt();\n\n\t\tif(n%4==0 || n%7==0 || n%47==0 || n%74==0 || n%474==0 || n%447==0 || n%774==0 || n%747==0 || n%477==0 || n%744==0)System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t}\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class luckydivision {\n\tpublic static int i(String s){\n\t\treturn Integer.parseInt(s);\n\t}\n\tpublic static boolean solve(String k, int n){\n\t\tint temp = i(k);\n\t\tif(temp > n){\n\t\t\treturn false;\n\t\t}\n\t\tif(n % temp == 0)\n\t\t\treturn true;\n\t\tif(solve(k + \"7\", n))\n\t\t\treturn true;\n\n\t\treturn solve(k + \"4\", n);\n\t}\n\tpublic static void main(String args[]) throws Exception {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = i(r.readLine());\n\t\tboolean i = solve(\"7\", n);\n\t\tboolean j = solve(\"4\", n);\n\t\tif(i || j){\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A122\n{\n    public static void main(String aa[])\n    {\n        Scanner ob=new Scanner(System.in);\n        int n;\n        \n        n=ob.nextInt();\n        if(n%4==0||n%7==0||n%44==0||n%47==0||n%444==0||n%447==0||n%474==0||n%477==0||n%744==0||n%747==0||n%774==0||n%777==0)\n        System.out.println(\"YES\");\n        else\n        System.out.println(\"NO\");\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\npublic static void main(String[] args) throws IOException{\nBufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));\nString a=buffer.readLine();\nint b=Integer.parseInt(a);\nif(b%4==0 || b%7==0 || b%44==0 || b%47==0 || b%74==0 || b%77==0 || b%444==0 || b%447==0 || b%474==0 || b%477==0 || b%744==0 || b%747==0 || b%774==0 || b%777==0)\nSystem.out.println(\"YES\");\nelse\nSystem.out.println(\"NO\");\n}}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class LuckyDivision{\n    public static void main(String [] args){\n        Scanner input = new Scanner(System.in);\n        int a = input.nextInt();\n        if(a%4 == 0) System.out.println(\"YES\");\n        else if(a%7 == 0) System.out.println(\"YES\");\n        else if(a%47 == 0) System.out.println(\"YES\");\n        else if(a%74 == 0) System.out.println(\"YES\");\n        else if(a%447 == 0) System.out.println(\"YES\");\n        else if(a%474 == 0) System.out.println(\"YES\");\n        else if(a%477 == 0) System.out.println(\"YES\");\n        else if(a%747 == 0) System.out.println(\"YES\");\n        else if(a%774 == 0) System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "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        if ((n % 4 == 0) || (n % 7 == 0) || (n % 44 == 0) || (n % 47 == 0) || (n % 74 == 0) || (n % 77 == 0) \n                || (n % 444 == 0) || (n % 447 == 0) || (n % 474 == 0) || (n % 477 == 0) || (n % 744 == 0) \n                || (n % 747 == 0) || (n % 774 == 0) || (n % 777 == 0)) {\n            System.out.println(\"YES\");\n            return;\n        }\n        System.out.println(\"NO\");\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main{\npublic static void main(String[]args){\nScanner input=new Scanner(System.in);\nint x=input.nextInt();\nif(x%4==0||x%7==0||x%47==0||x%74==0||x%744==0||x%474==0||x%447==0||x%477==0||x%474==0)\nSystem.out.println(\"YES\");\nelse\nSystem.out.println(\"NO\");\n}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\npublic class E {\n    static 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    static PrintWriter out;\n\n    public static void main(String[] args) throws Exception {\n        in = 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        out = new PrintWriter(System.out);\n\n        int n = next();\n\n        if (n%4 == 0||n%7 == 0||n%44 == 0||n%47 == 0||n%74 == 0||n%77 == 0||n%444 == 0||n%447 == 0||n%474 == 0||n%744 == 0||n%774 == 0||n%747 == 0||n%477 == 0||n%777==0) out.println(\"YES\");\n        else out.println(\"NO\");\n\n        out.println();\n        out.close();\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class z3 {\n\tpublic static boolean divch(int i,int a)\n\t{ if (a>1000) return false; if ((a>0)&&(i%a==0)) return true; return (divch(i,a*10+4)||divch(i,a*10+7)); }\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner in = new Scanner(System.in);\n\t\tSystem.out.println(divch(in.nextInt(),0)?\"YES\":\"NO\");\n\t}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "//package arbuz;\n\nimport java.util.Scanner;\n\npublic class Arbuz {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        if (n % 4 == 0 || n % 7 == 0 || n % 47 == 0 || n % 74 == 0 || n % 444 == 0 || n % 447 == 0 || n % 474 == 0 || n % 477 == 0) {\n            System.out.println(\"YES\");\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Division {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint l = sc.nextInt();\n\t\tString c = String.valueOf(l);\n\t\tif (String.valueOf(c).contains(\"0\") || String.valueOf(c).contains(\"1\")\n\t\t\t\t|| String.valueOf(c).contains(\"2\")\n\t\t\t\t|| String.valueOf(c).contains(\"3\")\n\t\t\t\t|| String.valueOf(c).contains(\"5\")\n\t\t\t\t|| String.valueOf(c).contains(\"6\")\n\t\t\t\t|| String.valueOf(c).contains(\"8\")\n\t\t\t\t|| String.valueOf(c).contains(\"9\"))\n\t\t\tif (l % 777 == 0 || l % 774 == 0 || l % 747 == 0 || l % 744 == 0\n\t\t\t\t\t|| l % 477 == 0 || l % 474 == 0 || l % 447 == 0\n\t\t\t\t\t|| l % 444 == 0 || l % 77 == 0 || l % 74 == 0\n\t\t\t\t\t|| l % 47 == 0 || l % 44 == 0 || l % 7 == 0 || l % 4 == 0)\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t\tSystem.out.println(\"YES\");\n\t}\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Main{\n  public static void main(String[] args){\n    Scanner scan = new Scanner(System.in);\n    int n = scan.nextInt();\n    if (n % 4 == 0 || n % 7 == 0 || n % 47 == 0 || n % 77 == 0 || n % 74 == 0 || n % 447 == 0 || n % 474 == 0 || n % 477 == 0 || n % 747 == 0 || n % 774 == 0 || n % 777 == 0)\n      System.out.println(\"YES\");\n    else\n      System.out.println(\"NO\");\n  }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n/**\n * Write a description of class lukno here.\n * \n * @author (your name) \n * @version (a version number or a date)\n */\npublic class lukno\n{\n    public static void main (String args[])\n    {\n        Scanner i= new Scanner(System.in);\n        int n,p;\n       \n        n=i.nextInt(); int t=n;\n       if(t%4==0||t%7==0||t%47==0||t%74==0||t%44==0||t%447==0||t%474==0||t%477==0)\n               System.out.print(\"YES\");\n               else System.out.print(\"NO\");\n\n    \n           \n\n\n}\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.LinkedList;\npublic class LuckyNumbers {\n\n    public static void main(String[] args)throws IOException\n    {\n        BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));\n        short num=Short.parseShort(scan.readLine());\n        if(funcion(num))\n        {\n            System.out.println(\"YES\");\n        }\n        else\n            System.out.println(\"NO\");\n    }\n    public static boolean funcion(short num)\n    {\n        LinkedList<Short>queue=new LinkedList<Short>();\n        queue.offer((short) 4);\n        queue.offer((short) 44);\n        queue.offer((short) 444);\n        queue.offer((short) 47);\n        queue.offer((short) 477);\n        queue.offer((short) 7);\n        queue.offer((short) 77);\n        queue.offer((short) 777);\n        queue.offer((short) 74);\n        queue.offer((short) 744);\n        while(queue.peek()!=null)\n        {\n            if(num%queue.poll()==0)\n            {\n                return true;\n            }\n        }\n        return false;\n\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n    public static void main(String args[])\n    {\n       Scanner scan=new Scanner(System.in);\n       int n=scan.nextInt();\n       System.out.println((n%4==0||n%7==0||n%47==0||n%74==0||n%447==0||n%474==0||n%477==0||n%744==0||n%747==0||n%774==0)?\"YES\":\"NO\");\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class A implements Runnable {\n\n\tprivate void Solution() throws IOException {\n\t\tint n = nextInt();\n\t\tif (n % 7 == 0 || n % 4 == 0 || n % 47 == 0 || n % 74 == 0 || n % 747 == 0 || n % 474 == 0 || n % 777 == 0 || n % 444 == 0 || n % 774 == 0 || n % 447 == 0 || n % 744 == 0 || n % 477 == 0)\n\t\t\tSystem.out.println(\"YES\"); else \n\t\t\t\tSystem.out.println(\"NO\");\n\t}\n\t\n\tpublic static void main(String args[]) {\n\t\tnew A().run();\n\t}\n\t\n\tBufferedReader in;\n\tStringTokenizer tokenizer;\n\t\n\tpublic void run() {\n\t\ttry {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            tokenizer = null;\n            Solution();\n            in.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n\t}\n\n\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\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", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class LuckyDivision {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        \n        int n = in.nextInt();\n        \n        if( n % 4==0 ||\n            n % 7==0 ||\n            n % 47==0 ||\n            n % 74==0 ||\n            n % 447==0 ||\n            n % 474==0 ||\n            n % 477==0 ||\n            n % 744==0 ||\n            n % 774==0 ||\n            n % 777==0\n        )\n            System.out.println(\"YES\");\n        else\n            System.out.println(\"NO\");\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int in = sc.nextInt();\n        if(\n                in%4==0||\n                in%7==0||\n                in%44==0||\n                in%47==0||\n                in%74==0||\n                in%77==0||\n                in%444==0||\n                in%447==0||\n                in%474==0||\n                in%477==0||\n                in%744==0||\n                in%747==0||\n                in%774==0||\n                in%777==0\n                \n        )\n            System.out.println(\"YES\");\n        else System.out.println(\"NO\");\n\n    }\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Task122A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tsc.close();\n\t\t\n\t\tif ( (n % 4 == 0)   ||\n\t\t\t (n % 7 == 0)   ||\n\t\t\t (n % 44 == 0)  ||\n\t\t\t (n % 47 == 0)  ||\n\t\t\t (n % 74 == 0)  ||\n\t\t\t (n % 77 == 0)  ||\n\t\t   \t (n % 444 == 0) ||\n\t\t\t (n % 447 == 0) ||\n\t\t\t (n % 474 == 0) ||\n\t\t\t (n % 477 == 0) ||\n\t\t\t (n % 744 == 0) ||\n\t\t\t (n % 747 == 0) ||\n\t\t\t (n % 774 == 0) ||\n\t\t\t (n % 777 == 0)    )\n\t\t{\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class A {\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 scan = new Scanner(System.in);\n\t\tint a = scan.nextInt();\n\t\tQueue<Integer> q = new LinkedList<Integer>();\n\t\tq.add(4);\n\t\tq.add(7);\n\t\tboolean luck = false;\n\t\twhile(!q.isEmpty() && !luck)\n\t\t{\n\t\t\tint f = q.poll();\n\t\t\tif(a%f == 0)\n\t\t\t{\n\t\t\t\tluck = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(f<a)\n\t\t\t{\n\t\t\t\tint t = (f+\"\").length();\n\t\t\t\tint tt = (int)Math.pow(10, t);\n\t\t\t\tq.add(tt*4+f);\n\t\t\t\tq.add(tt*7+f);\n\t\t\t}\n\t\t}\n\t\tif(luck)\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", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class HelloWorld\n{\n    public static void main (String args [])\n    {\n        Scanner read = new Scanner(System.in);\n        int n = read.nextInt();\n        int n1 = n; boolean q = true;\n        while (n1 > 0)\n        {\n            if (n % n1 == 0)\n            {\n                if (check(n1))\n                {\n                    System.out.print(\"YES\");\n                    q = false;\n                    break;\n                }   \n            }\n            n1--;\n        }\n        if (q) System.out.print(\"NO\");\n        \n    }\n    public static boolean check (int n)\n    {\n        int n1 = n;\n        while (n1 != 0)\n        {\n            if (n1 % 10 != 4 && n1 % 10 != 7) return false;\n            n1 /= 10;\n        }\n        return true;\n    }\n\n}\n\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Solution {\n    private static int n;\n    private static PrintWriter writer;\n    private static int maxstep;\n    \n    private static void g(int src, int step) {\n        if (step != 0 && n % src == 0) {\n            writer.print(\"YES\");\n            writer.close();\n            System.exit(0);\n        }\n        \n        if (step == maxstep) return;\n        \n        int p = (int)Math.pow(10, step);\n        \n        g(src + 4 * p, step + 1);\n        g(src + 7 * p, step + 1);\n    }\n    \n    public static void main(String[] args) throws Exception {        \n        //Scanner reader = new Scanner(new File(\"input.txt\"));\n        //PrintWriter writer = new PrintWriter(\"output.txt\");\n        Scanner reader = new Scanner(System.in);\n        writer = new PrintWriter(System.out);\n        \n        n = reader.nextInt();\n        maxstep = String.valueOf(n).length() + 1;\n        \n        g(0, 0);\n        \n        writer.print(\"NO\");\n        writer.close();\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class LuckySubstring {\n    \n    static int[] luck;\n    \n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        \n        int n = s.nextInt();\n        int i = -1;\n        boolean ehLuck = false;\n        preencheLucky();\n        while (n >= luck[++i]) {\n            if (i > 13) {\n                break;\n            }\n            if (n % luck[i] == 0) {\n                ehLuck = true;\n                break;\n            }\n        }\n        if (ehLuck) {\n            System.out.println(\"YES\");\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n    \n    static void preencheLucky() {\n        luck = new int[15];\n        luck[0] = 4;\n        luck[1] = 7;\n        luck[2] = 44;\n        luck[3] = 47;\n        luck[4] = 74;\n        luck[5] = 77;\n        luck[6] = 444;\n        luck[7] = 447;\n        luck[8] = 474;\n        luck[9] = 477;\n        luck[10] = 744;\n        luck[11] = 747;\n        luck[12] = 774;\n        luck[13] = 777;\n    }\n    \n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class n122A {\n    Scanner in;\n    PrintWriter out;\n\n    void solve() {\n        int n = in.nextInt();\n        boolean good = false;\n        if (n % 4 == 0) {\n            good = true;\n        }\n        if (n % 7 == 0) {\n            good = true;\n        }\n        if (n % 44 == 0) {\n            good = true;\n        }\n        if (n % 47 == 0) {\n            good = true;\n        }\n        if (n % 74 == 0) {\n            good = true;\n        }\n        if (n % 77 == 0) {\n            good = true;\n        }\n        if (n % 444 == 0) {\n            good = true;\n        }\n        if (n % 447 == 0) {\n            good = true;\n        }\n        if (n % 474 == 0) {\n            good = true;\n        }\n        if (n % 477 == 0) {\n            good = true;\n        }\n        if (n % 744 == 0) {\n            good = true;\n        }\n        if (n % 747 == 0) {\n            good = true;\n        }\n        if (n % 774 == 0) {\n            good = true;\n        }\n        if (n % 777 == 0) {\n            good = true;\n        }\n        if (good) {\n            out.println(\"YES\");\n        } else {\n            out.println(\"NO\");\n        }\n    }\n\n    void run() {\n        in = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        try {\n            solve();\n        } finally {\n            out.close();\n        }\n    }\n\n    public static void main(String[] args) {\n        new n122A().run();\n\n    }\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class x\n{\n    public static void main(String args[])\n    {\n        Scanner obj=new Scanner(System.in);\n        int n;\n        String d=\"0\";\n        n=obj.nextInt();\n        if(n%4==0 || n%7==0 || n%47==0 || n%74==0 || n%447==0 || n%474==0 || n%747==0)\n        d=\"YES\";\n        else if(n%444==0 || n%477==0 || n%744==0 || n%774==0 || n%777==0)\n        d=\"YES\";\n        else\n        d=\"NO\";\n        System.out.print(d);\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner in = new Scanner(System.in);\n\t\tint a[]={4,7,44,47,74,77,444,447,474,477,744,747,774,777};\n\t\tint n=in.nextInt();\n\t\tint i=0;\n\t\tboolean yes=false;\n\t\twhile((i<14)&&(a[i]<=n)){\n\t\t\tif(n%a[i]==0){\n\t\t\t\tSystem.out.print(\"YES\");\n\t\t\t\tyes=true;\n\t\t\t\tbreak;\n\t\t\t} i++;\n\t\t}\n\t\tif(!yes)\n\t\tSystem.out.print(\"NO\");\n\t}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n/**\n * Write a description of class lukno here.\n * \n * @author (your name) \n * @version (a version number or a date)\n */\npublic class lukno\n{\n    public static void main (String args[])\n    {\n        Scanner i= new Scanner(System.in);\n        int n,p;\n        \n       \n        n=i.nextInt(); int t=n;\n        while(n!=0)\n        {\n            p=n%10;\n            if(p!=4||p!=7)\n           { if(t%7==0||t%4==0||t%47==0||t%74==0||t%447==0||t%477==0||t%474==0)\n               System.out.print(\"YES\");\n               else System.out.print(\"NO\");\n\n            break;}\n            else System.out.print(\"NO\");\n            \n            n=(n/10);\n            }\n           \n\n\n}\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    StreamTokenizer in;\n    BufferedReader inb;\n    PrintWriter out;\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(\n                System.in)));\n        inb = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n        solve();\n        out.flush();\n    }\n\n    public int nextInt() throws Exception {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    public int parseInt() throws Exception {\n        return Integer.parseInt(inb.readLine());\n    }\n\n    public String nextLine() throws Exception {\n        return inb.readLine();\n    }\n\n    \n    public void solve() throws Exception {\n        int n = nextInt();\n        if ((n%4==0)||(n%44==0)||(n%47==0)||(n%74==0)\n                ||(n%744==0)||(n%747==0)||(n%774==0)||(n%777==0)\n                ||(n%7==0)||(n%444==0)||(n%447==0)||(n%474==0)||(n%477==0)||(n%77==0))\n        {\n            out.print(\"YES\");\n        }\n        else\n        {\n            out.print(\"NO\");\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A_122 {\npublic static void main(String[] args) throws NumberFormatException, IOException {\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tint n = Integer.parseInt(bf.readLine());\n\t  System.out.println((n%4==0||n%7==0||n%47==0||n%74==0||n%447==0||n%474==0||n%477==0||n%744==0||n%747==0||n%774==0)?\"YES\":\"NO\");\n}\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class lucky\n{ \n   public static void main(String args[]) throws IOException\n   { \n    BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));\n    \n    String s=cin.readLine();\n    int l=s.length();\n    int n=Integer.parseInt(s);\n    if(s.equals(\"47\") || s.equals(\"4\") || s.equals(\"7\") || s.equals(\"74\") || s.equals(\"447\") || s.equals(\"477\") || s.equals(\"474\") || s.equals(\"44\") || s.equals(\"77\") || s.equals(\"444\") || s.equals(\"777\") || s.equals(\"747\") || s.equals(\"774\") || s.equals(\"744\"))\n          \n          System.out.println(\"YES\");\n    else if(n%(47)==0 || n%(4)==0 || n%(7)==0 || n%(74)==0 || n%(447)==0 || n%(477)==0 || n%(474)==0 || n%(44)==0 || n%(77)==0 || n%(444)==0 || n%(777)==0  || n%(747)==0  || n%(774)==0  || n%(744)==0)\n            System.out.println(\"YES\");\n    else\n            System.out.println(\"NO\");\n            }\n }          ", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.StringTokenizer;\n\n/**\n * Created with IntelliJ IDEA.\n * User: \u0421\u0430\u0448\u0430\n * Date: 08.08.12\n * Time: 14:12\n */\npublic class LuckyDivision {\n\n    public final String check (String s) {\n        String result = \"NO\";\n        StringTokenizer stringTokenizer = new StringTokenizer(s, \"47\");\n        if(!stringTokenizer.hasMoreTokens()) return \"YES\";\n        int S = Integer.parseInt(s);\n        generateSimpleAndDivide(S, 4, 4, 7);\n        generateSimpleAndDivide(S, 7, 4, 7);\n        if(lucky) return \"YES\";\n        return result;\n    }\n    public static final void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        System.out.print(new LuckyDivision().check(scanner.next()));\n    }\n\n    public void generateSimpleAndDivide(int divided, int n, int n1, int n2) {\n        if(lucky || n >= divided) return;\n        if(divided % n == 0) lucky = true;\n        generateSimpleAndDivide(divided, Integer.parseInt(n + \"\" + n1), n1, n2);\n        generateSimpleAndDivide(divided, Integer.parseInt(n + \"\" + n2), n1, n2);\n    }\n    private boolean lucky = false;\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A_Lucky_Division {\n\tpublic static void main(String[] args){\n\t\tScanner input=new Scanner(System.in);\n\t\tint number=input.nextInt();\n\t\tint flag=0;\n\t\tif(number%4==0)flag=1;\n\t\telse if(number%7==0)flag=1;\n\t\telse if(number%47==0)flag=1;\n\t\telse if(number%74==0)flag=1;\n\t\telse if(number%444==0)flag=1;\n\t\telse if(number%447==0)flag=1;\n\t\telse if(number%474==0)flag=1;\n\t\telse if(number%477==0)flag=1;\n\t\telse if(number%744==0)flag=1;\n\t\telse if(number%747==0)flag=1;\n\t\telse if(number%774==0)flag=1;\n\t\telse if(number%777==0)flag=1;\n\t\tif(flag==1)System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t\t\n\t}\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "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        if ((n%4==0)||(n%7==0)||(n%44==0)||(n%47==0)||(n%74==0)||(n%77==0)||(n%444==0)||(n%447==0)||(n%474==0)||(n%477==0)||(n%744==0)||(n%747==0)||(n%774==0)||(n%777==0)) {\n            System.out.println(\"YES\");\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Sol122A {\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\tlong x = nextLong();\n\t\tout.println((x % 4) * (x % 7) * (x % 74) * (x % 47) * (x % 44) * (x % 77) * (x % 444) * (x % 447) * (x % 474) * (x % 477) * (x % 744) * (x % 747) * (x % 774) * (x % 777) == 0 ? \"YES\" : \"NO\");\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\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 Sol122A().run();\n\t}\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic 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\tif (((n % 4) == 0) || ((n % 7) == 0) || ((n % 44) == 0) || ((n % 47) == 0) || ((n % 74) == 0) || ((n % 77) == 0) || ((n % 444) == 0) || ((n % 447) == 0) || ((n % 474) == 0) || ((n % 477) == 0) || ((n % 744) == 0) || ((n % 747) == 0) || ((n % 774) == 0) || ((n % 777) == 0))\n\t\t\tSystem.out.print(\"YES\");\n\t\telse\n\t\t\tSystem.out.print(\"NO\");\n\t\tin.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class solution {\n    public static void main(String[] args) {\n       Scanner in = new Scanner(System.in);\n       int n = in.nextInt();\n       boolean ok = (n % 4 == 0) || (n % 7 == 0) || (n % 47 == 0) || (n % 74 == 0) || (n % 447 == 0) || (n % 474 == 0) || (n % 477 == 0) || (n % 744 == 0) || (n % 747 == 0) || (n % 774 == 0);\n       if (ok) System.out.println(\"YES\"); else System.out.println(\"NO\");\n    } \n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Solution {\n    public static void main(String[] args){\n        Scanner cin=new Scanner(System.in);\n        int n=cin.nextInt();\n        if(n%4==0 || n%7==0 || n%44==0 || n%47==0 || n%74==0 || n%77==0 || n%444==0 || n%447==0 || n%474==0 ||\n                n%477==0 || n%744==0 || n%747==0 || n%774==0 ||n%777==0) System.out.print(\"YES\");\n        else System.out.print(\"NO\");\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class MainClass {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int arr[] = {4,7,47,74,447,474,477,744,747,774};\n        int i=0, x = in.nextInt();\n        while (i<arr.length)\n        if (x%arr[i++] == 0)\n        {\n             System.out.print(\"YES\");\n             return;\n        }\n        System.out.print(\"NO\");\n    }\n}\n", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class CF {\n        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=null;\n        private void  solution() throws IOException{\n   int n=nextInt();\n   if((n % 4==0 && n>=4)||(n % 7==0 && n>=7) || (n % 44==0 && n>=44) || (n % 47==0 && n>=47) || (n % 77==0 && n>=77) || (n % 74==0 && n>=74)\n   || (n % 444==0 && n>=444) || (n % 447==0 && n>=447) || (n % 474==0 && n>=74) || (n % 477==0 && n>=477) || (n % 744==0 && n>=744)\n   || (n % 747==0 && n>=747) || (n % 777==0 && n>=777)){\n           System.out.println(\"YES\");\n   }else{\n                System.out.println(\"NO\");}\n        }\n        String nextToken()throws IOException {\n                if(st==null || !st.hasMoreTokens()){\n                        st = new StringTokenizer(bf.readLine());\n                }\n                return st.nextToken();\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        public static void main(String args[]) throws IOException {\n                new CF().solution();\n        }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class three {\n    static boolean check;\n\n    public static void main(String[] args) {\n        check = true;\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        String s = n + \"\";\n        recurse(n, s.length(), \"4\");\n        if (!check)\n            System.out.println(\"YES\");\n        else {\n            recurse(n, s.length(), \"7\");\n            if (!check)\n                System.out.println(\"YES\");\n            else\n                System.out.println(\"NO\");\n        }\n    }\n\n    private static void recurse(int n, int length, String string) {\n        int k = Integer.parseInt(string);\n        if (n % k == 0) {\n            check = false;\n        } else if (string.length() <= length && check) {\n            recurse(n, length, string + \"4\");\n            recurse(n, length, string + \"7\");\n        }\n\n    }\n}", "complexity": "constant", "problem": "122_A. Lucky Division", "from": "CODEFORCES"}
{"src": "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    ABirthday solver = new ABirthday();\n    solver.solve(1, in, out);\n    out.close();\n  }\n\n  static class ABirthday {\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n      long N = in.readLong(), M = in.readLong(), K = in.readLong(), L = in.readLong();\n\n      long ans = ((L + K) - 1) / M + 1;\n      if (ans * M > N || ans * M - K < L) out.printLine(-1);\n      else out.printLine(ans);\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  static class InputReader {\n    private InputStream stream;\n    private byte[] buf = new byte[1024];\n    private int curChar;\n    private int numChars;\n    private InputReader.SpaceCharFilter filter;\n\n    public InputReader(InputStream stream) {\n      this.stream = stream;\n    }\n\n    public int read() {\n      if (numChars == -1) {\n        throw new InputMismatchException();\n      }\n      if (curChar >= numChars) {\n        curChar = 0;\n        try {\n          numChars = stream.read(buf);\n        } catch (IOException e) {\n          throw new InputMismatchException();\n        }\n        if (numChars <= 0) {\n          return -1;\n        }\n      }\n      return buf[curChar++];\n    }\n\n    public long readLong() {\n      int c = read();\n      while (isSpaceChar(c)) {\n        c = read();\n      }\n      int sgn = 1;\n      if (c == '-') {\n        sgn = -1;\n        c = read();\n      }\n      long res = 0;\n      do {\n        if (c < '0' || c > '9') {\n          throw new InputMismatchException();\n        }\n        res *= 10;\n        res += c - '0';\n        c = read();\n      } while (!isSpaceChar(c));\n      return res * sgn;\n    }\n\n    public boolean isSpaceChar(int c) {\n      if (filter != null) {\n        return filter.isSpaceChar(c);\n      }\n      return isWhitespace(c);\n    }\n\n    public static boolean isWhitespace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public interface SpaceCharFilter {\n      public boolean isSpaceChar(int ch);\n    }\n  }\n}\n", "complexity": "constant", "problem": "1068_A. Birthday", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class CF1068A {\n\tpublic CF1068A() {\n\t\tFS scan = new FS();\n\t\tlong n = scan.nextLong(), m = scan.nextLong(), k = scan.nextLong(), l = scan.nextLong();\n\t\tlong ceil = (k + l + m - 1) / m;\n\t\tif(k + l <= n && ceil * m <= n) System.out.println(ceil);\n\t\telse System.out.println(-1);\n\t}\n\tclass FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tpublic String next() {\n\t\t\twhile(!st.hasMoreTokens()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\t\tcatch(Exception e) { e.printStackTrace(); }\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\tpublic long nextLong() { return Long.parseLong(next()); }\n\t}\n\tpublic static void main(String[] args) { new CF1068A(); }\n}\n", "complexity": "constant", "problem": "1068_A. Birthday", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Codechef{\n\t\n\n    public static void main(String []args){\n    \t\t\tScanner in = new Scanner(System.in);\n\n    long n=in.nextLong();\n\t\tlong m=in.nextLong();\n\t\tlong k=in.nextLong();\n\t\tlong l=in.nextLong();\n \n\t\tlong j=((k+l)/m);\n\t\tif((k+l)%m!=0)j++;\n\t\tif((k+l>n) || j*m>n) {\n\t\t\tSystem.out.println(-1);\n\t\t}else {\n\t\t\t\n\t\t\tSystem.out.println(j);\n\t\t}\n\n\n    }\n\n}", "complexity": "constant", "problem": "1068_A. Birthday", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\tstatic int 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\tString[] s = new String[2];\n\t\tfor(int i = 0; i < 2; i++){\n\t\t\ts[i] = scanner.next();\n\t\t}\n\t\tint n = s[0].length();\n\t\tchar[][] c = new char[2][n];\n\t\tfor(int i = 0; i < 2; i++){\n\t\t\tfor(int j = 0; j < n; j++){\n\t\t\t\tc[i][j] = s[i].charAt(j);\n\t\t\t}\n\t\t}\n\t\tint count = 0;\n\t\tfor(int i = 0; i < n-1; i++){\n\t\t\tif(c[0][i] == '0' && c[1][i] == '0' && c[0][i+1] == '0'){\n\t\t\t\tc[0][i] = 'X';\n\t\t\t\tc[1][i] = 'X';\n\t\t\t\tc[0][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(c[0][i] == '0' && c[1][i] == '0' && c[1][i+1] == '0'){\n\t\t\t\tc[0][i] = 'X';\n\t\t\t\tc[1][i] = 'X';\n\t\t\t\tc[1][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(c[0][i] == '0' && c[0][i+1] == '0' && c[1][i+1] == '0'){\n\t\t\t\tc[0][i] = 'X';\n\t\t\t\tc[0][i+1] = 'X';\n\t\t\t\tc[1][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif(c[0][i+1] == '0' && c[1][i+1] == '0' && c[1][i] == '0'){\n\t\t\t\tc[1][i] = 'X';\n\t\t\t\tc[0][i+1] = 'X';\n\t\t\t\tc[1][i+1] = 'X';\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\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<Pair>{\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<Pair2> {\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", "complexity": "constant", "problem": "991_D. Bishwock", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic 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    boolean chpr(int n)\n    {\n    \tif(n==1)\n    \t{\n    \t\treturn true;\n    \t}if(n==2)\n    \t{\n    \t\treturn true;\n    \t}\n    \tif(n==3)\n    \t{\n    \t\treturn true;\n    \t}\n    \tif(n%2==0)\n    \t{\n    \t\treturn false;\n\n    \t}\n    \tif(n%3==0)\n    \t{\n    \t\treturn false;\n    \t}\n    \t\n    \tint w=2;\n \t\tint i=5;\n    \twhile(i*i<=n)\n    \t{\n    \t\tif(n%i==0)\n    \t\t{\n    \t\t\treturn false;\n    \t\t}\n    \t\ti+=w;\n    \t\tw=6-w;\n    \t}\n    \treturn true;\n\n    }\n    \n    void solve() {\n\n\n        int n=ni();\n        int k=ni();\n        int rr=2*n;\n        int gr=5*n;\n        int br=8*n;\n        o.println((long)(Math.ceil(rr*1.0/k)+Math.ceil(gr*1.0/k)+Math.ceil(br*1.0/k)));\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n    //---------- I/O Template ----------\n    \n    public static void main(String[] args) { new bhaa().run(); }\n    void run() { \n        is = System.in; \n        o = new PrintWriter(System.out);\n        solve();\n        o.flush();\n    }\n    \n    byte input[] = new byte[1024];\n    int len = 0, ptr = 0;\n    \n    int readByte() { \n        if(ptr >= len) { ptr = 0; \n            try { len = is.read(input); } \n            catch(IOException e) { throw new InputMismatchException(); } \n            if(len <= 0) { return -1; } \n        } return input[ptr++];\n    }\n    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n    int skip() { \n        int b = readByte(); \n        while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n        return b;\n    }\n    \n    char nc() { return (char)skip(); }\n    String ns() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    String nLine() { \n        int b = skip(); \n        StringBuilder sb = new StringBuilder(); \n        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n        return sb.toString();\n    }\n    int ni() { \n        int n = 0, b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        if(b == -1) { return -1; }  //no input \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n    long nl() { \n        long n = 0L;    int b = readByte(); \n        boolean minus = false; \n        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n        if(b == '-') { minus = true; b = readByte(); } \n        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n        return minus ? -n : n;\n    }\n\n    double nd() { return Double.parseDouble(ns()); }\n    float nf() { return Float.parseFloat(ns()); }\n    int[] nia(int n) { \n        int a[] = new int[n]; \n        for(int i = 0; i < n; i++) { a[i] = ni(); } \n        return a;\n    }\n    long[] nla(int n) { \n        long a[] = new long[n]; \n        for(int i = 0; i < n; i++) { a[i] = nl(); } \n        return a;\n    }\n    int [][] nim(int n)\n    {\n        int mat[][]=new int[n][n];\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                mat[i][j]=ni();\n            }\n        }\n        return mat;\n    }\n    long [][] nlm(int n)\n    {\n        long mat[][]=new long[n][n];\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                mat[i][j]=nl();\n            }\n        }\n        return mat;\n    }\n    \n\n\n\n\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    void piarr(int arr[])\n    {\n        for(int i=0;i<arr.length;i++)\n        {\n            o.print(arr[i]+\" \");\n\n        }\n        o.println();\n    }\n    void plarr(long arr[])\n    {\n        for(int i=0;i<arr.length;i++)\n        {\n            o.print(arr[i]+\" \");\n\n        }\n        o.println();\n    }\n    \n    void pimat(int mat[][])\n    {\n        for(int i=0;i<mat.length;i++)\n        {\n            for(int j=0;j<mat[0].length;j++)\n            {\n                o.print(mat[i][j]);\n            }\n            o.println();\n        }\n    }\n    void plmat(long mat[][])\n    {\n        for(int i=0;i<mat.length;i++)\n        {\n            for(int j=0;j<mat[0].length;j++)\n            {\n                o.print(mat[i][j]);\n            }\n            o.println();\n        }\n\n    }\n\n\n\n\n    //////////////////////////////////// template finished //////////////////////////////////////\n\n\n\n}", "complexity": "constant", "problem": "1080_A. Petya and Origami", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class origami {\n\tpublic static void main(String args[]){\n\t\tScanner input = new Scanner(System.in);\n\t\tdouble n = input.nextInt();\n\t\tdouble k = input.nextInt();\n\t\tdouble red = 0;\n\t\tdouble green = 0;\n\t\tdouble blue = 0;\n\t\tdouble ans = 0;\n\t\tred = (2 * n) / k;\n\t\tgreen = (5 * n) / k;\n\t\tblue = (8 * n) / k;\n\n\t\tdouble red1 = Math.ceil(red) ;\n\t\tdouble green1 = Math.ceil(green);\n\t\tdouble blue1 = Math.ceil(blue);\n\n\t\tans+=red1;\n\t\tans+=green1;\n\t\tans+=blue1;\n\t\tDouble answer = new Double(ans);\n\t\tint finished = answer.intValue();\n\t\tSystem.out.println(finished);\n\t}\n}\n", "complexity": "constant", "problem": "1080_A. Petya and Origami", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\npublic class Main {\n\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        long n = scanner.nextLong();\n        long x = scanner.nextLong(), y = scanner.nextLong();\n        long whiteSteps, blackSteps;\n\n        if(x == 1 || y == 1){\n            whiteSteps = (x - 1) + (y - 1);\n        } else {\n            whiteSteps = Math.min((x - 1) + Math.abs(y - x), (y - 1) + Math.abs(y - x));\n        }\n\n        if(x == n || y == n){\n            blackSteps = (n - x) + (n - y);\n        } else {\n            blackSteps = Math.min((n - x) + Math.abs(y - x), (n - y) + Math.abs(y - x));\n        }\n\n        if (whiteSteps <= blackSteps){\n            System.out.println(\"White\");\n        } else {\n            System.out.println(\"Black\");\n        }\n\n    }\n}\n", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": " \n \n\n\nimport java.util.Scanner;\nimport javafx.geometry.Point2D;\n\n \npublic class ChessKing {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\nScanner input = new Scanner(System.in);\nlong size = input.nextLong();\nlong a = input.nextLong();\nlong b = input.nextLong();\n  long sum = a+b;\n   long d = sum-2;\n   long d1 = size*2 - sum;\nif(d<d1) System.out.println(\"White\");\nelse if(d>d1) System.out.println(\"Black\");\nelse System.out.println(\"White\");\n\n\n    }\n    \n}\n", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "//Author: Patel Rag\n//Java version \"1.8.0_211\"\nimport java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n  static class FastReader\n  {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastReader(){ br = new BufferedReader(new 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 nextInt() { return Integer.parseInt(next()); }\n\n    long nextLong(){ return Long.parseLong(next()); }\n\n    double nextDouble(){ return Double.parseDouble(next()); }\n\n    float nextFloat() { return Float.parseFloat(next()); }\n\n    boolean nextBoolean() { return Boolean.parseBoolean(next()); }\n\n    String nextLine()\n    {\n      String str = \"\";\n      try\n      {\n        str = br.readLine();\n      }\n      catch (IOException e)\n      {\n        e.printStackTrace();\n      }\n      return str;\n    }\n  }\n  static long modExp(long x, long n, long mod)    //binary Modular exponentiation\n  {\n    long result = 1;\n    while(n > 0)\n    {\n        if(n % 2 == 1)\n            result = (result%mod * x%mod)%mod;\n        x = (x%mod * x%mod)%mod;\n        n=n/2;\n    }\n    return result;\n  }\n  static long gcd(long a, long b)\n  {\n    if(a==0) return b;\n    return gcd(b%a,a);\n  }\n  public static void main(String[] args)\n  throws IOException\n  {\n    FastReader fr = new FastReader();\n    long n = fr.nextLong();\n    long x = fr.nextLong();\n    long y = fr.nextLong();\n    long w = Long.min(x,y) - 1 + (x - Long.min(x,y)) + (y - Long.min(x,y));\n    long b = n - Long.max(x,y) + (Long.max(x,y) - x) + (Long.max(x,y) - y);\n    if(w <= b) System.out.println(\"White\");\n    else System.out.println(\"Black\");\n\n  }\n}\nclass Pair<U, V>  // Pair class\n{\n    public final U first;       // first field of a Pair\n    public final V second;      // second field of a Pair\n\n    private Pair(U first, V second)\n    {\n      this.first = first;\n      this.second = second;\n    }\n\n    @Override\n    public boolean equals(Object o)\n    {\n      if (this == o) return true;\n\n      if (o == null || getClass() != o.getClass()) return false;\n\n      Pair<?, ?> pair = (Pair<?, ?>) o;\n\n      if (!first.equals(pair.first)) return false;\n      return second.equals(pair.second);\n    }\n\n    @Override\n    public int hashCode()\n    {\n      return 31 * first.hashCode() + second.hashCode();\n    }\n\n    public static <U, V> Pair <U, V> of(U a, V b)\n    {\n      return new Pair<>(a, b);\n    }\n}\nclass myComp implements Comparator<Pair>\n{\n  public int compare(Pair a,Pair b)\n  {\n    if(a.first != b.first) return ((int)a.first - (int)b.first);\n    if(a.second != b.second) return ((int)a.second - (int)b.second);\n    return 0;\n  }\n}\nclass BIT       //Binary Indexed Tree aka Fenwick Tree\n{\n  public long[] m_array;\n\n  public BIT(long[] dat)\n  {\n    m_array = new long[dat.length + 1];\n    Arrays.fill(m_array,0);\n    for(int i = 0; i < dat.length; i++)\n    {\n      m_array[i + 1] = dat[i];\n    }\n    for(int i = 1; i < m_array.length; i++)\n    {\n      int j = i + (i & -i);\n      if(j < m_array.length)\n      {\n        m_array[j] = m_array[j] + m_array[i];\n      }\n    }\n  }\n\n  public final long prefix_query(int i)\n  {\n    long result = 0;\n    for(++i; i > 0; i = i - (i & -i))\n    {\n      result = result + m_array[i];\n    }\n    return result;\n  }\n\n  public final long range_query(int fro, int to)\n  {\n    if(fro == 0)\n    {\n      return prefix_query(to);\n    }\n    else\n    {\n      return (prefix_query(to) - prefix_query(fro - 1));\n    }\n  }\n\n  public void update(int i, long add)\n  {\n    for(++i; i < m_array.length; i = i + (i & -i))\n    {\n      m_array[i] = m_array[i] + add;\n    }\n  }\n}\n", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "import java .util.*;\nimport java .io.*;\npublic class Main{\n\tpublic static void main(String[]YAHIA_MOSTAFA){\n\t\tScanner sc =new Scanner(System.in);\n\t\tlong n=sc.nextLong(),x=sc.nextLong(),y=sc.nextLong();\n\t\tlong xb,xw,yb,yw;\n\t\txw=x-1;yw=y-1;xb=n-x;yb=n-y;\n\t\tif (x==n&&y==n){\n\t\t\tSystem.out.println(\"Black\");return;\n\t\t}\n\t\tlong c1=0,c2=0;\n\t\tlong f =Math.max(xb,yb);\n\t\tlong h =Math.max(xw,yw);\n\t\t//System.out.println(h+\" \"+f+\" \"+(h-f));\n\t\tif (h<=f)\n\t\t\tSystem.out.println(\"White\");\n\t\telse\n\t\t\tSystem.out.println(\"Black\");\n\t}\n}", "complexity": "constant", "problem": "1075_A. The King's Race", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Pizza {\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong num = sc.nextLong() + 1;\n\t\tsc.close();\n\t\tSystem.out.println(num % 2 == 0 || num == 1 ? num / 2 : num);\n\t}\n\t\n}\n", "complexity": "constant", "problem": "979_A. Pizza, Pizza, Pizza!!!", "from": "CODEFORCES"}
{"src": "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        if(n==0)\n        System.out.println(0);\n        else if(n%2==1)\n        System.out.println((n+1)/2);\n        else\n        System.out.println(n+1);\n    }\n}", "complexity": "constant", "problem": "979_A. Pizza, Pizza, Pizza!!!", "from": "CODEFORCES"}
{"src": "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\tlong n = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tSystem.out.println(solve(n, k));\n\n\t\tsc.close();\n\t}\n\n\tstatic long solve(long n, long k) {\n\t\treturn Math.max(0, Math.min(n, k - 1) - ((k + 2) / 2) + 1);\n\t}\n}\n", "complexity": "constant", "problem": "1023_B. Pair of Toys", "from": "CODEFORCES"}
{"src": "/* 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\t\tlong n,s,p;\n\t\t\tScanner in=new Scanner(System.in);\n\t\t\tn=in.nextLong();\n\t\t\ts=in.nextLong();\n\t\t\tif(n==1 && s<=1)\n\t\t\t{\n\t\t\t    System.out.print(n-1);\n\t\t\t}\n\t        else if(s<n)\n\t        {\n\t            if(s%2!=0)\n\t\t        {System.out.print(s/2);}\n\t\t        else\n\t\t        {System.out.print(s/2-1);}\n\t        }\n\t        else if(s==n)\n\t{\n\t    if(s%2==0)\n\t\t{System.out.println((n/2)-1);}\n\t\telse\n\t\t{System.out.println(n/2);}\n\t}\n\telse if(s<=(2*n-1))\t\n\t{\n\t\tSystem.out.print((2*n+1-s)/2);\n\t}\n\telse\n\t{\n\t\tSystem.out.print(0);\n\t}\n\t}\n}", "complexity": "constant", "problem": "1023_B. Pair of Toys", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Soldiers {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Soldiers().run();\n\t}\n\n\tvoid run() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(System.out);\n\n\t\tint n = nextInt();\n\t\tpw.println(3 * (n / 2));\n\n\t\tpw.close();\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter pw;\n\n\tString next() 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\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", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\npublic class Main {\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\t\tint num=Integer.parseInt(in.readLine());\n\t\tSystem.out.println((num/2)*(3));\n\t}\t\t\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n\n\npublic class Solution {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        // TODO Auto-generated method stub\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int n=in.nextInt();\n    \n        out.print(n/2+n);\n       \n        out.close();\n        in.close();\n    }\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "public class A {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(new java.util.Scanner(System.in).nextInt() / 2 * 3);\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "//package Codeforces72;\n\nimport java.util.Scanner;\n\npublic class A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\t\t\n\t\tSystem.out.println((int)(n+n/2));\n\t}\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C72A{\n    static BufferedReader br;\n    public static void main(String args[])throws Exception{\n        br=new BufferedReader(new InputStreamReader(System.in));\n        long n=toLong();\n        long res=n+n/2;\n        System.out.println(res);\n\n\n    }\n\n\n    /****************************************************************/\n    public static int[] toIntArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       int k[]=new int[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Integer.parseInt(str[i]);\n       }\n       return k;\n    }\n    public static int toInt()throws Exception{\n       return Integer.parseInt(br.readLine());\n    }\n    public static long[] toLongArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       long k[]=new long[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Long.parseLong(str[i]);\n       }\n       return k;\n    }\n    public static long toLong()throws Exception{\n       return Long.parseLong(br.readLine());\n    }\n    public static double[] toDoubleArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       double k[]=new double[str.length];\n       for(int i=0;i<str.length;i++){\n            k[i]=Double.parseDouble(str[i]);\n       }\n       return k;\n    }\n    public static double toDouble()throws Exception{\n       return Double.parseDouble(br.readLine());\n    }\n    public static String toStr()throws Exception{\n       return br.readLine();\n    }\n    public static String[] toStrArray()throws Exception{\n       String str[]=br.readLine().split(\" \");\n       return str;\n    }\n    /****************************************************************/\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class Main implements Runnable {\n  private final String problemname = \"\";\n  private final String FILE_IN  = problemname + \".in\";\n  private final String FILE_OUT = problemname + \".out\";\n\n  public void run() {\n//    in = new BufferedReader(new FileReader(FILE_IN));\n//    out = new PrintWriter(FILE_OUT);\n    in = new BufferedReader(new InputStreamReader(System.in));\n    out = new PrintWriter(System.out);\n    _st = new StringTokenizer(\"\");\n\n    // TODO: type your code here\n    int n = nextInt();\n\n    int best = n + n / 2;\n    /*\n    for (int i = 0; i <= n; i++) {\n      for (int j = 0; j <= n - i; j++) {\n        best = Math.max(best, i + j + Math.min(n - i, n - j));\n      }\n    }*/\n\n    out.println(best);\n\n    try {\n      in.close();\n      out.close();\n    }\n    catch (Exception e) {\n      System.err.println(\"Epic fail\");\n    }\n  }\n\n  BufferedReader in;\n  PrintWriter out;\n  StringTokenizer _st;\n\n  public static void main(String[] args) {\n    new Thread(new Main()).start();\n  }\n\n  private void seek() {\n    while (!_st.hasMoreTokens()) {\n      String s;\n      try {\n        s = in.readLine();\n        _st = new StringTokenizer(s);\n      } catch (Exception e) {\n        return;\n      }\n    }\n  }\n\n  private String next() {\n    seek();\n    return _st.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 BigInteger nextBigInteger() {\n    return new BigInteger(next());\n  }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "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 =T/2;\nSystem.out.println(t*3);\n\n\n}\n\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ToyArmy {\n    public static void main(String[] args) {\n        int n = new Scanner(System.in).nextInt();\n        System.out.println(n + n / 2);\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n \npublic class Main {\n \n\tprivate BufferedReader input;\n\tprivate PrintWriter output;\n\tprivate StringTokenizer stoken;\n \n\tString fin = \"input\";\n\tString fout = \"output\";\n \n \n\tprivate void solve() {\n\n\t\tlong a = nextInt();\n\t\t\n\t\tlong res = (a / 2) * 3;\n\n\t\toutput.print(res);\n\t\t\n\t}\n \n \n \n\tMain() throws IOException {\n\t\t//input = new BufferedReader(new FileReader(fin + \".txt\"));\n\t\t//output = new PrintWriter(new FileWriter(fout + \".txt\"));\n\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\toutput = new PrintWriter(System.out);\n \n \n\t\tsolve();\n \n\t\tinput.close();\n\t\toutput.flush();\n\t\toutput.close();\n\t}\n \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 nextFloat() {\n\t\treturn Float.parseFloat(nextToken());\n\t}\n \n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n \n\tString nextToken() {\n\t\twhile ((stoken == null) || (!stoken.hasMoreTokens())) {\n\t\t\ttry {\n\t\t\t\tString line = input.readLine();\n\t\t\t\tstoken = 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 stoken.nextToken();\n\t}\n \n \n \n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main();\n\t}\n \n}\n\n\nclass Tarif {\n\tpublic int abPlata;\n\tpublic int tMin;\n\tpublic int price;\n\tpublic long res;\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class A {\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\tSystem.out.println(n*3/2);\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A72 {\n\tpublic static void main (String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tSystem.out.println(n * 3 / 2);\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ToyArmy {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tSystem.out.println(n / 2 + n);\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A\n{\n    public static void main(String[] args)\n    {\n        Kattio io = new Kattio(System.in);\n\n        int n = io.getInt();\n        int ans = 0;\n        int V = n;\n        int A = n;\n\n        A -= n/2;\n        ans += n/2;\n\n        V -= A;\n        ans += A;\n\n        A -= n/2;\n        ans += n/2;\n\n        io.println(ans);\n        io.flush();\n    }\n}\n\n\nclass Kattio extends PrintWriter {\n    public Kattio(InputStream i) {\n\tsuper(new BufferedOutputStream(System.out));\n\tr = new BufferedReader(new InputStreamReader(i));\n    }\n    public Kattio(InputStream i, OutputStream o) {\n\tsuper(new BufferedOutputStream(o));\n\tr = new BufferedReader(new InputStreamReader(i));\n    }\n\n    public boolean hasMoreTokens() {\n\treturn peekToken() != null;\n    }\n\n    public int getInt() {\n\treturn Integer.parseInt(nextToken());\n    }\n\n    public double getDouble() { \n\treturn Double.parseDouble(nextToken());\n    }\n\n    public long getLong() {\n\treturn Long.parseLong(nextToken());\n    }\n\n    public String getWord() {\n\treturn nextToken();\n    }\n\n\n\n    private BufferedReader r;\n    private String line;\n    private StringTokenizer st;\n    private String token;\n\n    private String peekToken() {\n\tif (token == null) \n\t    try {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t    line = r.readLine();\n\t\t    if (line == null) return null;\n\t\t    st = new StringTokenizer(line);\n\t\t}\n\t\ttoken = st.nextToken();\n\t    } catch (IOException e) { }\n\treturn token;\n    }\n\n    private String nextToken() {\n\tString ans = peekToken();\n\ttoken = null;\n\treturn ans;\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "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\tint in = sc.nextInt();\n\t\tSystem.out.println(in/2 + in);\n\t\tSystem.exit(0);\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class CF {\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         int n=sc.nextInt();\n         pw.print(n+n/2);\n\tpw.close();\n\tsc.close();\n}\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n  public static void main(String[] args) {\n    Scanner sc = new Scanner(System.in);\n    long n = sc.nextLong();\n    System.out.println(3 * (n / 2));\n  }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 4/13/11\n * Time: 8:07 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskA1 {\n\n    void run(){\n        int n = nextInt();\n\n        int ans = 2 * n - (n / 2);\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 TaskA1().run();\n    }\n\n\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\npublic class Cfbra {\n    public static void main(String[] args) {\n       Scanner in = new Scanner(System.in);\n       PrintStream out = System.out;\n       out.println(in.nextInt() / 2 * 3);\n    }\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\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.println(3 * n / 2);\n\t}\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Govnokod {\n\n\tpublic static void main(String args[]) {\n\t\ttry {\n\t\t\tInputStreamReader isr = new InputStreamReader(System.in);\n\t\t\tBufferedReader br = new BufferedReader(isr);\n\n\t\t\twhile (true) {\n\t\t\t\tString str = br.readLine();\n\t\t\t\tint i = Integer.parseInt(str);\n\n\t\t\t\tSystem.out.println(i*2-i/2);\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class N72A\n{\n    StreamTokenizer in;\n    PrintWriter out;\n\n    int nextInt() throws IOException\n    {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    double nextDouble() throws IOException\n    {\n        in.nextToken();\n        return in.nval;\n    }\n\n    public void init() throws Exception\n    {\n        boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(new File(\"input.txt\"));\n        Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(new File(\"output.txt\"));\n        in = new StreamTokenizer(reader);\n        out = new PrintWriter(writer);\n    }\n\n    public void solve() throws Exception\n    {\n        int n = nextInt();\n        out.print(2*n - (n/2));\n    }\n\n    public void print() throws Exception\n    {\n        out.flush();\n    }\n\n    public void run() throws Exception\n    {\n        init();\n        solve();\n        print();\n    }\n\n    public static void main(String[] args) throws Exception\n    {\n        new N72A().run();\n    }\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class MainA {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n  = sc.nextInt();\n        \n        int count = 0;\n        \n        count = n/2;\n        \n        count = count + (n - n/2);\n        \n        n = n - n/2;\n            \n        count = count + n;  \n\n        \n        System.out.println(count);\n        \n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Task1 {\n\n    public static void main(String[] args) {\n        int n = new Scanner(System.in).nextInt();\n        System.out.println(n*3/2);\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class TemplateBuf implements Runnable{\n    \n    private void solve() throws Exception {\n        long n = nextUnsignedLong();\n        \n        out.println(n+n/2);\n    }\n\n    /////////////////////////////////////////////////\n    \n    BufferedReader in;\n    PrintWriter out;\n    \n    @Override\n    public void run() {\n        try{\n            in = new BufferedReader(new InputStreamReader(System.in), INPUT_BUF_SIZE);\n            out = new PrintWriter(new OutputStreamWriter(System.out));\n            solve();\n            out.flush();\n        }catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n    \n    final int INPUT_BUF_SIZE = 1024 * 8;\n    final int BUF_SIZE = INPUT_BUF_SIZE;\n    char[] buf = new char[BUF_SIZE];\n    int ch=-1;\n    int charRead=-1;\n    int charPos=-1;\n    \n    public char nextChar() throws IOException{\n        if (charPos<0 || charPos>=charRead){\n            charRead = in.read(buf);\n            charPos=0;\n        }\n        return buf[charPos++];\n    }\n    \n    public long nextUnsignedLong() throws IOException{      \n        while ((ch=nextChar())<'0' || ch>'9');\n        long num = ch-'0';\n        while ((ch=nextChar())>='0' && ch<='9'){\n            num*=10;\n            num+=ch-'0';\n        }\n        return num;\n    }\n    \n    public int nextUnsignedInt() throws IOException{\n        return (int)nextUnsignedLong();\n    }\n    \n    public double nextDouble() throws IOException{\n        while (((ch=nextChar())<'0' || ch>'9') && ch!='.' && ch!='-');\n        char[] tmp = new char[255];\n        int itmp = 0;\n        tmp[itmp++]=(char)ch;\n        while (((ch=nextChar())>='0' && ch<='9') || ch=='.' || ch=='-'){\n            tmp[itmp++]=(char)ch;\n        }\n        return Double.parseDouble(new String(tmp,0,itmp));\n    }\n    \n    public static void main(String[] args) {\n        new TemplateBuf().run();\n    }\n    \n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemA_72 {\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    public static void main(String[] args){\n        new ProblemA_72().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    void solve() throws IOException{\n        int n = readInt();\n        out.print((n + n/2));\n    }       \n    \n    static class MyAlgo{\n        \n        long gcd(long a, long b){\n            if (a == 0) return b;\n            return gcd(b % a, a);\n        }\n        \n        long lcm(long a, long b){\n            return a / gcd(a, b)*b;\n        }\n\n        long[] gcdPlus(long a, long b){\n            long[] d = new long[3];\n            if (a == 0){\n                d[0] = b;\n                d[1] = 0;\n                d[2] = 1;\n            }else{\n                d = gcdPlus(b % a, a);\n                long r = d[1];\n                d[1] = d[2] - b/a*d[1];\n                d[2] = r;\n            }\n            return d;\n        }\n        \n        long binpow(long a, int n){\n            if (n == 0) return 1;\n            if ((n & 1) == 0){\n                long b = binpow(a, n/2);\n                return b*b;\n            }else return binpow(a, n-1)*a;\n        }\n        \n        long binpowmod(long a, int n, int m){\n            if (n == 0) return 1;\n            if ((n & 1) == 0){\n                long b = binpow(a, n/2);\n                return (b*b) % m;\n            }else return binpow(a, n-1)*a % m;\n        }\n        \n        long f(long n, int x, int k){ //\u041a\u043e\u043b-\u0432\u043e \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b (\u0432\u043a\u043b\u044e\u0447\u0430\u044f 0), \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0432 \u0441\u0435\u0431\u0435 \u0446\u0438\u0444\u0440\u044b \u043e\u0442 0 \u0434\u043e k-1\n            if (n == 0) return 1;\n            long b = binpow(10, x - 1);\n            long c = n / b;\n            return (c < k? c: k)*binpow(k, x - 1) + (c < k? 1: 0)*f(n % b, x - 1, k);\n        }\n        \n        long fib(int n){\n            if (n == 0) return 0;\n            if ((n & 1) == 0){\n                long f1 = fib(n/2 - 1);\n                long f2 = fib(n/2 + 1);\n                return f2*f2 - f1*f1;\n            }else{\n                long f1 = fib(n/2);\n                long f2 = fib(n/2 + 1);\n                return f1*f1 + f2*f2;\n            }\n        }\n        \n        BigInteger BigFib(int n){\n            if (n == 0) return BigInteger.ZERO;\n            if ((n & 1) == 0){\n                BigInteger f1 = BigFib(n/2 - 1);\n                f1 = f1.multiply(f1);\n                BigInteger f2 = BigFib(n/2 + 1);\n                f2 = f2.multiply(f2);\n                return f2.subtract(f1);\n            }else{\n                BigInteger f1 = BigFib(n/2);\n                f1 = f1.multiply(f1);\n                BigInteger f2 = BigFib(n/2 + 1);\n                f2 = f2.multiply(f2);\n                return f2.add(f1);\n            }\n        }\n        \n        boolean IsProbablyPrime(long n){\n            if (n == 1) return false;\n            if ((n & 1) == 0) return false;\n            for (int j = 3; j < sqrt(n) + 1; j += 2){\n                if (n % j == 0) return false;\n            }\n            return true;\n        }\n\n        int[] Sieve(int n){\n            boolean[] b = new boolean[n+1];\n            Arrays.fill(b, true);\n            b[0] = false;\n            b[1] = false;\n            long nLong = n;\n            int j=0;\n            for (int i = 1; i <= n; i++) {\n                if (b[i]){\n                    j++;\n                    if (((long)i)*i <= nLong) {\n                        for (int k = i*i; k <= n; k += i) {\n                            b[k] = false;\n                        }\n                    }\n                }\n            }\n            int[] p = new int[j];\n            Arrays.fill(p, 0);\n            j=0;\n            for (int i = 2; i <= n; i++) {\n                if (b[i]){\n                    p[j]=i;\n                    j++;\n                }\n            }\n            return p;\n        }\n        \n        public class Permutation {\n            \n            int[] a;\n            int n;\n            \n            public Permutation(int n){\n                this.n=n;\n                a=new int[n];\n                for (int i=0; i<n; i++){\n                    a[i]=i;\n                }\n            }\n            \n            public boolean nextPermutation(){ //\u041f\u0438\u0448\u0435\u0442\u0441\u044f \u0441 do{}while(nextPermutation(a));\n                int i=n-1;\n                for (i=n-2; i>=0; i--){\n                    if (a[i]<a[i+1]){\n                        break;\n                    }\n                }\n                if (i==-1){\n                    return false;\n                }\n                int jMin=i+1;\n                for (int j=n-1; j>i; j--){\n                    if (a[i]<a[j]&&a[j]<a[jMin]){\n                        jMin=j;\n                    }\n                }\n                swap(i, jMin);\n                for (int j=1; j<=(n-i)/2; j++){\n                    swap(i+j, n-j);\n                }\n                return true;\n            }\n            \n            \n            public int get(int i){\n                return a[i];\n            }\n            \n            void swap(int i, int j){\n                int r=a[i];\n                a[i]=a[j];\n                a[j]=r;\n            }\n        }\n        \n        public class Fraction implements Comparable<Fraction>, Cloneable{\n            \n            public final Fraction FRACTION_ZERO = new Fraction();\n            public final Fraction FRACTION_ONE = new Fraction(1);\n            public long numerator = 0;\n            public long denominator = 1;\n            \n            public Fraction(){\n                numerator = 0;\n                denominator = 1;\n            }\n            \n            public Fraction(long numerator){\n                this.numerator = numerator;\n                denominator = 1;\n            }\n            \n            public Fraction(long numerator, long denominator){\n                this.numerator = numerator;\n                this.denominator = denominator;\n                Cancellation();\n            }\n            \n            public Fraction(double numerator, double denominator, int accuracy){\n                this.numerator = (long)(numerator*pow(10,accuracy));\n                this.denominator = (long)(denominator*pow(10,accuracy));\n                Cancellation();\n            }\n            \n            public Fraction(String s){\n                if (s.charAt(0) == '-'){\n                    denominator = -1;\n                    s = s.substring(1);\n                }\n                if (s.indexOf(\"/\") != -1){\n                    denominator *= Integer.parseInt(s.substring(s.indexOf(\"/\") + 1));\n                }\n                if (s.indexOf(\" \") != -1){\n                    numerator = Integer.parseInt(s.substring(0, s.indexOf(\" \"))) * abs(denominator) + Integer.parseInt(s.substring(s.indexOf(\" \") + 1, s.indexOf(\"/\")));\n                }else{\n                    if (s.indexOf(\"/\") != -1){\n                        numerator = Integer.parseInt(s.substring(0, s.indexOf(\"/\")));\n                    }else{\n                        numerator = Integer.parseInt(s)*abs(denominator);\n                    }\n                }\n                this.Cancellation();\n            }\n            \n            void Cancellation(){\n                long g = gcd(abs(numerator), abs(denominator));\n                numerator /= g;\n                denominator /= g;\n                if (denominator < 0){\n                    numerator *= -1;\n                    denominator *= -1;\n                }\n            }\n            \n            public String toString(){\n                String s = \"\";\n                if (numerator == 0){\n                    return \"0\";\n                }\n                if (numerator < 0){\n                    s += \"-\";\n                }\n                if (abs(numerator) >= denominator){\n                    s += Long.toString(abs(numerator) / denominator) + \" \";\n                }\n                if (abs(numerator) % denominator != 0){\n                    s += Long.toString(abs(numerator) % denominator);\n                }else{\n                    s = s.substring(0, s.length()-1);\n                }\n                if (denominator != 1){\n                    s += \"/\" + Long.toString(denominator);\n                }\n                return s;\n            }\n            \n            public Fraction add(Fraction f){\n                Fraction fResult = new Fraction();\n                fResult.denominator = lcm(denominator, f.denominator);\n                fResult.numerator = numerator * fResult.denominator / denominator + f.numerator * fResult.denominator / f.denominator;\n                fResult.Cancellation();\n                return fResult;\n            }\n            \n            public Fraction subtract(Fraction f){\n                Fraction fResult = new Fraction();\n                fResult.denominator = lcm(denominator, f.denominator);\n                fResult.numerator = numerator * fResult.denominator / denominator - f.numerator * fResult.denominator / f.denominator;\n                fResult.Cancellation();\n                return fResult;\n            }\n            \n            public Fraction multiply(Fraction f){\n                Fraction fResult = new Fraction();\n                fResult.numerator = numerator * f.numerator;\n                fResult.denominator = denominator * f.denominator;\n                fResult.Cancellation();\n                return fResult;\n            }\n            \n            public Fraction divide(Fraction f){\n                Fraction fResult = new Fraction();\n                fResult.numerator = numerator * f.denominator;\n                fResult.denominator = denominator * f.numerator;\n                fResult.Cancellation();\n                return fResult;\n            }\n            \n            @Override\n            public int compareTo(Fraction f){\n                long g = gcd(denominator, f.denominator);\n                long res = numerator * (f.denominator / g) - f.numerator * (denominator / g);\n                if (res < 0){\n                    return -1;\n                }\n                if (res > 0){\n                    return 1;\n                }\n                return 0;\n            }\n            \n            public Fraction clone(){\n                Fraction fResult = new Fraction(numerator, denominator);\n                return fResult;\n            }\n            \n            public Fraction floor(){\n                Fraction fResult = this.clone();\n                fResult.numerator = (fResult.numerator / fResult.denominator) * fResult.denominator;\n                return fResult;\n            }\n            \n            public Fraction ceil(){\n                Fraction fResult = this.clone();\n                fResult.numerator = (fResult.numerator/fResult.denominator + 1) * fResult.denominator;\n                return fResult;\n            }\n            \n            public Fraction binpow(int n){\n                if (n==0) return FRACTION_ONE;\n                if ((n&1)==0){\n                    Fraction f=this.binpow(n/2);\n                    return f.multiply(f);\n                }else return binpow(n-1).multiply(this);\n            }\n        }\n        \n        class FenwickTree_1{    //One-dimensional array     \n            \n            int n;\n            long[] t;\n            \n            public FenwickTree_1(int n){\n                this.n = n;\n                t = new long[n];\n            }\n            \n            public long sum(int xl, int xr){\n                return sum(xr) - sum(xl);\n            }\n            \n            public long sum(int x){\n                long result = 0;\n                for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                    result += t[i];\n                }\n                return result;\n            }\n            \n            public void update(int x, long delta){\n                for (int i = x; i < n; i = (i | (i + 1))){\n                    t[i] += delta;\n                }\n            }\n        }\n        \n        class FenwickTree_2{    //Two-dimensional array\n            \n            int n, m;\n            long[][] t;\n            \n            public FenwickTree_2(int n, int m){\n                this.n = n;\n                this.m = m;\n                t = new long[n][m];\n            }\n            \n            public long sum(int xl, int yl, int xr, int yr){\n                return sum(xr, yr) - sum(xl - 1, yr) - sum(xr, yl - 1) + sum(xl - 1, yl - 1);\n            }\n            \n            public long sum(int x, int y){\n                long result = 0;\n                for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                    for (int j = y; j >= 0; j = (j & (j + 1)) - 1){\n                        result+=t[i][j];\n                    }\n                }\n                return result;\n            }\n            \n            public void update(int x, int y, long delta){\n                for (int i = x; i < n; i = (i | (i + 1))){\n                    for (int j = y; j < m; j = (j | (j + 1))){\n                        t[i][j] += delta;\n                    }\n                }\n            }\n        }\n        \n        class FenwickTree_3{    //Three-dimensional array\n            \n            int n, m, l;\n            long[][][] t;\n            \n            public FenwickTree_3(int n, int m, int l){\n                this.n = n;\n                this.m = m;\n                this.l = l;\n                t = new long[n][m][l];\n            }\n            \n            public long sum(int xl, int yl, int zl, int xr, int yr, int zr){\n                return sum(xr, yr, zr) - sum(xl - 1, yr, zr)\n                + sum(xl - 1, yr, zl - 1) - sum(xr, yr, zl - 1)\n                - sum(xr, yl - 1, zr) + sum(xl - 1, yl - 1, zr)\n                - sum(xl - 1, yl - 1, zl - 1) + sum(xr, yl - 1, zl - 1);\n            }\n            \n            public long sum(int x, int y, int z){\n                long result = 0;\n                for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                    for (int j = y; j >= 0; j = (j & (j + 1)) - 1){\n                        for (int k = z; k >= 0; k = (k & (k + 1)) - 1){\n                            result += t[i][j][k];\n                        }\n                    }\n                }\n                return result;\n            }\n            \n            public void update(int x, int y, int z, long delta){\n                for (int i = x; i < n; i = (i | (i + 1))){\n                    for (int j = y; j < n; j = (j | (j + 1))){\n                        for (int k = z; k < n; k = (k | (k + 1))){\n                            t[i][j][k] += delta;\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * Created by IntelliJ IDEA.\n * User: Administrator\n * Date: 13.05.11\n * Time: 23:21\n * To change this template use File | Settings | File Templates.\n */\npublic class ToyArmies {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        long n = in.nextLong();\n        System.out.print(String.format(\"%d\",(long)(n*1.5)));\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n    private void solve() throws IOException {\n        int n = nextInt();\n        int r = n;\n        n *= 2;\n        n -= (0.5*r);\n        System.out.println(n);\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", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.IOException;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class A {\n\t\n\tprivate void processInput() throws IOException {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tlong res = go(n);\n\n\t\tSystem.out.printf(Locale.ENGLISH, \"%d\\n\", res);\t\t\t\n\n\t\n\n\t\t\n\t\tin.close();\n\t}\n\n\tprivate long go(long n) {\n\t\t\n\t\tlong res = 3*n / 2;\n\t\t\n\n\t\treturn res;\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tA a = new A();\n\t\ta.processInput();\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound72_Div2_A implements Runnable {\n\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tvoid init() throws IOException {\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new BetaRound72_Div2_A()).start();\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint ans = n * 3 / 2;\n\t\tout.print(ans);\n\t}\n\t\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n/**\n * @author abashkin\n */\npublic class Solution implements Runnable {\n\n    public static void main(String[] args) {\n        new Thread(new Solution()).start();\n    }\n\n    public void run() {\n        try{\n            br = new BufferedReader(new InputStreamReader(System.in));\n            pw = new PrintWriter(new OutputStreamWriter(System.out));\n            solve();\n            pw.close();\n        }\n        catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    private void solve() throws Exception {\n        int n = nextInt();\n        pw.print(n + n / 2);\n    }\n\n    private BufferedReader br;\n    private PrintWriter pw;\n    private StringTokenizer tok;\n\n    private String next() throws Exception {\n        while (tok == null || !tok.hasMoreElements()) tok = new StringTokenizer(br.readLine());\n        return tok.nextToken();\n    }\n\n    private int nextInt() throws Exception {\n        return Integer.parseInt(next());\n    }\n\n\n\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    public void solve() throws IOException {\n        int n = nextInt();\n        output.println(n / 2 * 3);\n    }\n\n    public void run() throws IOException {\n        input = new BufferedReader(new InputStreamReader(System.in));\n        output = new PrintWriter(System.out);\n        solve();\n        input.close();\n        output.close();\n    }\n\n    BufferedReader input;\n    PrintWriter output;\n    StringTokenizer tok;\n\n    String nextToken() throws IOException {\n        while(tok == null || !tok.hasMoreTokens())\n            tok = new StringTokenizer(input.readLine());\n\n        return tok.nextToken();\n    }\n\n    int nextInt() throws IOException {\n        return Integer.valueOf(nextToken());\n    }\n\n    long nextLong() throws IOException {\n        return Long.valueOf(nextToken());\n    }\n\n    double nextDouble() throws IOException {\n        return Double.valueOf(nextToken());\n    }\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args) {\n        \n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        System.out.println(n/2*3);\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner read = new Scanner(System.in);\n        int n = read.nextInt();\n        System.out.println(n*3/2);\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "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        System.out.println(n + n / 2);\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    StreamTokenizer in;\n    PrintWriter out;\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\n    public void solve() throws Exception {\n        int n=nextInt();\n        long ans=0;\n        for (int i=0;i<n;i+=2)\n            ans+=3;\n        out.println(ans);\n    }\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A {\n    private static StreamTokenizer in;\n    private static PrintWriter out;\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        out = new PrintWriter(System.out);\n    }\n    \n    public static void main(String[] args)throws Exception{\n        int n = nextInt();\n        \n        out.println(n*3/2);\n        \n        out.flush();\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        \n        System.out.println(n/2*3);\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A_Toy_Army {\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 entrada = new Scanner(System.in);\n\t\twhile(entrada.hasNextInt())\n\t\t{\n\t\t\tint n = entrada.nextInt();\n\t\t\tSystem.out.println(n+(n/2));\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A{     \n        \n        private BufferedReader in;  \n        private StringTokenizer st;\n        \n        void solve() throws IOException{\n            \n            int n = nextInt();\n            System.out.println(3 * n/2);\n        }\n            \n\n        A() throws IOException {\n            in = new BufferedReader(new InputStreamReader(System.in));          \n            eat(\"\");\n            solve();            \n        }\n\n        private void eat(String str) {\n            st = new StringTokenizer(str);\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 A();\n        }\n\n        int gcd(int a,int b){\n            if(b>a) return gcd(b,a);\n            if(b==0) return a;\n            return gcd(b,a%b);\n        }\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Main {\n    public static void main(String[] args) {\n        Scanner in=new Scanner(System.in);\n        int n,b = 0;\n        n=in.nextInt();\n        if (n%2==0) {\n            b=n+n/2;\n            System.out.println(b);\n        }\n    }\n}\n\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        \n        int n = input.nextInt();\n        \n        System.out.println(n * 6 / 4);\n    }\n    \n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class ToyArmy {\n\n\t/**\n\t * @param args\n\t * @throws IOException \n\t * @throws NumberFormatException \n\t */\n\tpublic static void main(String[] args) throws NumberFormatException, IOException \n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tSystem.out.println(n / 2 * 3);\n\t}\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class p84a {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        \n        System.out.println((n/2)*3);\n        \n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.util.Stack;\n\npublic class sample {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();       \n        System.out.println(n+n/2);\n    }\n}", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class A {\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\t\n\t\tint n = in.nextInt();\n\t\t\n\t\tout.printf(Locale.US, \"%d\", n/2*3);\n\t\t\n\t\tout.close();\n\t}\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Saransh\n */\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n\n\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        try\n        {\n            Parserdoubt pd=new Parserdoubt(System.in);\n            //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n            int n=pd.nextInt();\n            PrintWriter pw=new PrintWriter(System.out);\n            pw.println((n*3)/2);\n            pw.flush();\n        }\n        catch(Exception e)\n        {}\n\n    }\n\n}\n\n\nclass Parserdoubt\n    {\n       final private int BUFFER_SIZE = 1 << 17;\n\n       private DataInputStream din;\n       private byte[] buffer;\n       private int bufferPointer, bytesRead;\n\n       public Parserdoubt(InputStream in)\n       {\n          din = new DataInputStream(in);\n          buffer = new byte[BUFFER_SIZE];\n          bufferPointer = bytesRead = 0;\n       }\n       public String nextString() throws Exception\n       {\n           StringBuffer sb=new StringBuffer(\"\");\n           byte c = read();\n           while (c <= ' ') c = read();\n           do\n           {\n               sb.append((char)c);\n               c=read();\n           }while(c>' ');\n           return sb.toString();\n       }\n       public char nextChar() throws Exception\n       {\n           byte c=read();\n           while(c<=' ') c= read();\n           return (char)c;\n       }\n       public int nextInt() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       public long nextLong() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       private void fillBuffer() throws Exception\n       {\n          bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n          if (bytesRead == -1) buffer[0] = -1;\n       }\n\n       private byte read() throws Exception\n       {\n          if (bufferPointer == bytesRead) fillBuffer();\n          return buffer[bufferPointer++];\n       }\n    }", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Scanner;\n\n\npublic class A {\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\tSystem.out.println((2*n) - (n/2));\n\t\t\n\t}\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author Mostafa\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        System.out.println((n/2) *3);\n    }\n\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * May 13, 2011\u00a0\n * @author parisel\n */\npublic class ToyArmy {\n    int N;\n    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    String[] tok;\n    String s;\n\n    private String[] getTok() throws IOException {return br.readLine().split(\" \");}\n    private int getInt() throws IOException {return Integer.valueOf(br.readLine());}\n    private int[] getInt(int N) throws IOException {\n        int[] data= new int[N]; tok= br.readLine().split(\" \");\n        for (int i=0; i<N; i++) data[i]= Integer.valueOf(tok[i]);\n        return data;\n    }\n\n    public void solve() throws IOException {\n        int i=0, j=0;\n        N= getInt();\n\n        long kill= (3*N)/2;\n\n        System.out.printf(\"%d\\n\", kill);\n\n    }\n\n\n    public static void main(String[] args) throws IOException {\n        new ToyArmy().solve();\n    }\n}\n", "complexity": "constant", "problem": "84_A. Toy Army", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.lang.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.*;\n \npublic class Main {\n        \n    public static void main(String[] args) throws Exception{\n        FastReader sc=new FastReader(); \n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n        int n=sc.nextInt();\n        HashMap<String,Integer> map=new HashMap<String,Integer>();\n        for(int i=0;i<n;i++) {\n            map.put(sc.next(), 1);\n        }\n        ArrayList<String> list=new ArrayList<String>();\n        int count=0;\n        if(!map.containsKey(\"purple\")) {\n            count++;\n            list.add(\"Power\");\n        }\nif(!map.containsKey(\"green\")) {\n    count++;\n    list.add(\"Time\");\n        }\n\nif(!map.containsKey(\"blue\")) {\n    count++;\n    list.add(\"Space\");\n}\n\nif(!map.containsKey(\"orange\")) {\n    count++;\n    list.add(\"Soul\");\n}\n\nif(!map.containsKey(\"red\")) {\n    count++;\n    list.add(\"Reality\");\n}\n\nif(!map.containsKey(\"yellow\")) {\n    count++;\n    list.add(\"Mind\");\n}System.out.println(count);\n    for(String s:list) {\n        System.out.println(s);\n    }\n    }\n}\n\nclass 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} ", "complexity": "constant", "problem": "987_A. Infinity Gauntlet", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Locale;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        String[] str = in.nextLine().split(\" \");\n        int a = Integer.parseInt(str[0]);\n        int v = Integer.parseInt(str[1]);\n        str = in.nextLine().split(\" \");\n        int l = Integer.parseInt(str[0]);\n        int d = Integer.parseInt(str[1]);\n        int w = Integer.parseInt(str[2]);\n\n\n        double minTime = 0.;\n        if (w >= v) {\n            minTime = getTimeAfterSign(0, v, l, a);\n            out.format(Locale.US, \"%.6f\", minTime);\n            return;\n        }\n        double whenGetSpeedWPath = (w * w) / (2. * a);\n        if (whenGetSpeedWPath >= d) {\n            double time = Math.sqrt((2.0 * d) / a);\n            minTime = time + getTimeAfterSign(a * time, v, l - d, a);\n        } else {\n            double stopPath = (v * v - w * w) / (2. * a);\n            double vMaxPath = (v * v) / (2. * a);\n            if (stopPath + vMaxPath > d) {\n//                double topSpeed = (Math.sqrt(2. * a * d) + w) / 2;\n//                minTime = (topSpeed / a) + (topSpeed - w) / a + getTimeAfterSign(w, v, l - d, a);\n                double topSpeed = Math.sqrt((2. * a * d + w * w) / 2);\n                minTime = (2. * topSpeed - w) / a + getTimeAfterSign(w, v, l - d, a);\n            } else {\n                double stopTime = (v - w) / (a + 0.);\n                double getMaxTime = v / (a + 0.);\n                double maxTime = (d - (stopPath + vMaxPath)) / v;\n                minTime = stopTime + getMaxTime + maxTime + getTimeAfterSign(w, v, l - d, a);\n            }\n        }\n        out.format(Locale.US, \"%.6f\", minTime);\n\n    }\n\n    double getTimeAfterSign(double startSpeed, double maxSpeed, double path, int a) {\n        double maxSpeedTime = (maxSpeed - startSpeed) / a;\n        double maxSpeedPath = startSpeed * maxSpeedTime + (a * maxSpeedTime * maxSpeedTime) / 2;\n        if (maxSpeedPath > path) {\n            return (-startSpeed + Math.sqrt(startSpeed * startSpeed + 2 * a * path)) / a;\n        } else {\n            return maxSpeedTime + (path - maxSpeedPath) / maxSpeed;\n        }\n    }\n}\n\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main{\n\tstatic final double eps = 1e-10;\n\tpublic static void main(String []args){\n\t\tScanner cin = new Scanner(System.in);\n\t\tdouble a,v;\n\t\tdouble l,d,w;\n\t\tdouble time;\n\t\t\n\t\ta = cin.nextDouble();\n\t\tv = cin.nextDouble();\n\t\t\n\t\tl = cin.nextDouble();\n\t\td = cin.nextDouble();\n\t\tw = cin.nextDouble();\n\t\t\n\t\tif(v < w + eps)\n\t\t{\n\t\t\tdouble t1 = v / a;\n\t\t\tdouble len_bond = (v * v) / (2 * a);\n\t\t\tif(len_bond + eps > l)\n\t\t\t{\n\t\t\t\ttime = Math.sqrt(2 * l / a);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tdouble t2 = (l - len_bond) / v;\n\t\t\t\ttime = t1 + t2;\n\t\t\t}\n\t\t\tSystem.out.println(time);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdouble len_bondv =  (v * v) / (2 * a);\n\t\t\tdouble len_bondw = (w * w) / (2 * a);\n\t\t\tif(len_bondw + eps > d)\n\t\t\t{\n\t\t\t\tif(len_bondv + eps > l)\n\t\t\t\t\ttime = Math.sqrt(2 * l / a);\n\t\t\t\telse{\n\t\t\t\t\tdouble t1 = v / a;\n\t\t\t\t\tdouble t2 = (l - len_bondv) / v;\n\t\t\t\t\ttime = t1 + t2;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tdouble len_bonds = (v * v - w * w) / (2 * a);\n\t\t\t\t\n\t\t\t\tif(len_bondv + len_bonds < d + eps)\n\t\t\t\t\ttime = v / a + (d - len_bondv - len_bonds) / v + (v - w) / a;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tdouble f = Math.sqrt(d * a + w * w / 2);\n\t\t\t\t\ttime = f / a + (f - w) / a;\n\t\t\t\t}\n\t\t\t\tif (len_bonds + eps > l - d) {\n\t\t\t\t\tdouble lv = Math.sqrt((l - d) * 2 * a + w * w);\n\t\t\t\t\ttime += (lv - w) / a;\n\t\t\t\t} else {\n\t\t\t\t\ttime += (v - w) / a + (l - d - len_bonds) / v;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(time);\n\t\t}\n\t}\n}\n\t\t \t\t\t\t\t    \t   \t   \t", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main\n{\n    public static void main(String args[]) throws IOException\n    {\n        new Main().run();\n    }\n    StreamTokenizer in;\n    PrintWriter out;\n    public void run() throws IOException\n    {\n        in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n          out = new PrintWriter(new OutputStreamWriter(System.out));\n        /*out = new PrintWriter(new FileWriter(\"output.txt\"));\n        in =new StreamTokenizer(new BufferedReader(new FileReader(\"input.txt\")));*/\n\n        solve();\n\n        out.flush();\n    }\n\n    public double nextInt() throws IOException\n    {\n        in.nextToken();\n        return in.nval;\n    }\n    public void solve() throws IOException\n    {\n        double a=nextInt(),v=nextInt(),l=nextInt(),d=nextInt(),w=nextInt();\n        double s=w*w/(2*a);\n        if(s>d || w>v)\n        {\n        \tdouble t=v*v/(2*a);\n        \tif(t>l)\n        \t{\n        \t\tdouble f=2*l/a;\n        \t\tout.print(String.format(\"%.10f\",Math.sqrt(f)));\n        \t\treturn;\n        \t}\n        \tdouble f=v/a;\n        \tdouble k=(l-t)/v;\n        \tout.print(String.format(\"%.10f\",f+k));\n        \treturn;\n        }\n        double t;\n        if((2*v*v-w*w)/(2*a)<d)\n        \tt=v/a+(v-w)/a+(d-(2*v*v-w*w)/(2*a))/v;\n        else\n        {\n        double v1=Math.sqrt((2*a*d+w*w)/2);\n        t=v1/a+(v1-w)/a;\n        }\n        double r=l-d;\n        double tr=(v*v-w*w)/(2*a);\n        if(tr>r)\n        {\n        \tdouble t1=(-w+Math.sqrt(w*w+2*a*r))/a;\n        \tout.print(String.format(\"%.10f\",t+t1));\n        \treturn;\n        }\n        r-=(v*v-w*w)/(2*a);\n        t+=(v-w)/a;\n        out.print(String.format(\"%.10f\",t+r/v));\n    }\n\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.io.IOException;\n\npublic class kresz {\n\tpublic static double a;\n\tpublic static double v;\n\tpublic static double l;\n\tpublic static double d;\n\tpublic static double w;\n\t\t\n\tpublic static double gyorsulut (double v1, double v2) { //v1 -> v2 mennyi utat tesz meg\n\t\treturn Math.abs((v2*v2-v1*v1)/(2*a));\n\t}\n\tpublic static double gyorsulido (double v1, double v2) { //v1 -> v2 mennyi id\u0151\n\t\treturn Math.abs((v2-v1)/a);\n\t}\n\t\n\t\n\tpublic static void beolvas () throws IOException {\n\t\tScanner be = new Scanner (new InputStreamReader (System.in));\n\t\t\ta = be.nextDouble();\n\t\t\tv = be.nextDouble();\n\t\t\tl = be.nextDouble();\n\t\t\td = be.nextDouble();\n\t\t\tw = be.nextDouble();\n\t\tbe.close();\n\t}\n\t\n\t\n\tpublic static void main (String args[]) throws IOException {\n\t\t\tbeolvas();\n\t\t\tdouble s = l; //h\u00e1tral\u00e9v\u0151 \u00fat\n\t\t\tdouble t = 0; //eltelt id\u0151\n\t\t\t\n\t\t\tif (v <= w ||  Math.sqrt(2*a*d) <= w) { //nincs korl\u00e1toz\u00e1s\n\t\t\t\tif (gyorsulut(0,v) > l) {\n\t\t\t\t\tt+=gyorsulido(0, Math.sqrt(2*a*l));\n\t\t\t\t\ts = 0;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ts-=gyorsulut(0,v);\n\t\t\t\t\tt+=gyorsulido(0,v);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t\n\t\t\t\t//gyorsul\u00f3 szakaszok a korl\u00e1toz\u00e1sig\n\t\t\t\tif (d < gyorsulut(0,v)+gyorsulut(v,w)) {\n\t\t\t\t\tdouble x = Math.sqrt(a*(d-w*w/(2*a))+w*w);\n\t\t\t\t\ts-=gyorsulut(0,w)+2*gyorsulut(w,x);\n\t\t\t\t\tt+=gyorsulido(0,w)+2*gyorsulido(w,x);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ts-=gyorsulut(0,v)+gyorsulut(w,v);\n\t\t\t\t\tt+=gyorsulido(0,v)+gyorsulido(w,v);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//gyorsul\u00f3 szakaszok a korl\u00e1toz\u00e1st\u00f3l\n\t\t\t\tif (gyorsulut(v,w) > l-d) {\n\t\t\t\t\tdouble y = Math.sqrt(2*a*(l-d)+w*w);\n\t\t\t\t\ts-= gyorsulut(w,y);\n\t\t\t\t\tt+=gyorsulido(w,y);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ts-=gyorsulut(w,v);\n\t\t\t\t\tt+=gyorsulido(w,v);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tt+=s/v; //nem gyorsul\u00f3 szakaszok ideje\n\t\t\t\n\t\t\tSystem.out.println(t);\n\t\t\t\n\t}\n\t\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class D5 {\n\n\tstatic int a, v, l, d;\n\tstatic double w;\n\n\tstatic double afterMark( int s, double w) {\n\t\tif (2 * s * a > v * v - w * w) { // \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd v. \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\n\t\t\treturn (v - w) * 1.0 / a + (s - (v * v - w * w) * 1.0 / (2 * a)) / v;\n\t\t} else { // \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t\tdouble megav = Math.sqrt((2 * a * s + w * w) * 1.0);\n\t\t\treturn (megav - w) / a;\n\t\t}\n\t} \n\n\tpublic static void main(String args[]) throws IOException {\n\t\tboolean online = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tScanner in = online ? new Scanner(System.in) : new Scanner(new FileReader(\"input.txt\"));\n\t\tPrintWriter out = online ? new PrintWriter(System.out) : new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\n\n\t\ta = in.nextInt();\n\t\tv = in.nextInt();\n\t\tl = in.nextInt();\n\t\td = in.nextInt();\n\t\tw = (double) in.nextInt();\n\t\t\n\t\tdouble t,t1,t2;\n\n\t\tif (v > w) { // \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\t\t\n\t\t\n\t\t// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t\n\t\t\tif (2 * d * a > 2 * v * v - w * w) { // \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd v. \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\n\t\t\t\tt1 = (2 * v - w) * 1.0 / a + (d - (2 * v * v - w * w) * 1.0 / (2 * a)) / v; \n\t\t\t} else if (2 * d * a > w * w) { // \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\t\t\t\tdouble topv = Math.sqrt(d * a + w * w * 1.0 / 2);\n\t\t\t\tt1 = (2 * topv - w) * 1.0 / a;\n\t\t\t} else { // \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\t\t\t\tt1 = Math.sqrt(2 * d * 1.0 / a);\n\t\t\t\tw = Math.sqrt(2 * a * d * 1.0); \n\t\t\t}\n\t\t// \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t\tt2 = afterMark(l - d, w); \n\t\t\n\t\tt = t1 + t2;\n\t\t\t\n\t\t} else {\n\t\t\tt = afterMark(l, 0.0);\t\t\n\t\t}\n\t\t\n\t\tout.println(t);\n\t\tout.flush();\n\t\treturn;\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic final class FollowTrafficRules {\n    private static double[] acce(double i, double a, double v) {\n        double[] r = new double[2];\n        r[0] = (v - i)/a;\n        r[1] = 1d/2d * a * pow(r[0], 2) + i * r[0];\n        return r;\n    }\n\n    private static double solve(double i, double a, double l) {\n        double e = sqrt(pow(i, 2) + 2d * a * l);\n        e = a > 0 ? e : -1d * e;\n        return (e - i)/a;\n    }\n\n    private static double time(double i, double a, double v, double l) {\n        double[] r = acce(i, a, v);\n        if (r[1] >= l) return solve(i, a, l);\n        return r[0] + (l - r[1])/v;\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        double a = sc.nextDouble();\n        double v = sc.nextDouble();\n        double l = sc.nextDouble();\n        double d = sc.nextDouble();\n        double w = sc.nextDouble();\n\n        double t = 0d;\n        double[] r = acce(0, a, w);\n        if (v <= w || r[1] >= d) t = time(0, a, v, l);\n        else {\n            t += r[0];\n            t += 2d * time(w, a, v, (d - r[1])/2d);\n            t += time(w, a, v, l - d);\n        }\n\n        System.out.println(t);\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Rules {\n  public static void main(String[] args) {\n    Scanner in = new Scanner(System.in);\n    int a = in.nextInt();\n    double maxSpeed = in.nextInt();\n    double len = in.nextInt();\n    double delayDist = in.nextInt();\n    double delaySpeed = in.nextInt();\n    \n    double timeToDelaySpeed = delaySpeed/a;\n    double timeToDelay = travelS(a, 0.0, maxSpeed, delayDist);\n    //System.out.printf(\"timeToDelaySpeed=%.5f, timeToDelay=%.5f\\n\", timeToDelaySpeed, timeToDelay);\n    if (timeToDelay < timeToDelaySpeed) { // we won't reach delaySpeed before delay marker\n      // 2 cases: we don't reach max by time we reach end\n      timeToDelay = travelS(a, 0.0, maxSpeed, len);\n      double timeToMax = maxSpeed/a;\n      if (timeToDelay < timeToMax) {\n        System.out.printf(\"%.9f\\n\", timeToDelay);\n        return;\n      }\n      // we do reach max, then travel at max\n      double[] parts = travelA(a, 0.0, maxSpeed);\n      double remainingDist = len - parts[1];\n      double time = parts[0] + remainingDist / maxSpeed;\n      System.out.printf(\"%.9f\\n\", time);\n      return;\n    }\n    if (delaySpeed > maxSpeed) {\n      double time = travelS(a, 0.0, maxSpeed, len);\n      System.out.printf(\"%.9f\\n\", time);\n      return;\n    }\n    \n    // binary search to find best velocity to stop acceleration in beginning\n    double lowV = delaySpeed;\n    double highV = maxSpeed;\n    int loopCount = 1000;\n    double[] initial = null;\n    double[] secondary = null;\n    while (loopCount-->0) {\n      double guessV = (lowV+highV)/2.0;\n      initial = travelA(a, 0.0, guessV);\n      secondary = travelA(a, guessV, Math.min(delaySpeed, maxSpeed));\n      if (initial[1] + secondary[1] < delayDist) { // okay, we can go faster\n        lowV = guessV;\n      } else {\n        highV = guessV;\n      }\n    }\n    double totalTime = 0.0;\n    double finalSpeed = 0.0;\n    initial = travelA(a, 0.0, lowV);\n    secondary = travelA(a, lowV, delaySpeed);\n    totalTime = initial[0] + secondary[0];\n    double totalDist = initial[1] + secondary[1];\n    totalTime += (delayDist-totalDist)/maxSpeed;\n    \n    // now we have delayDist to go, and we are at delaySpeed\n    totalTime += travelS(a, delaySpeed, maxSpeed, len-delayDist);\n    System.out.printf(\"%.9f\\n\", totalTime);\n  }\n  \n  // [0] = time in h, [1] = dist travelled, in km\n  // input units are in km/h^2, km/h, km/h\n  public static double[] travelA(int a, double startSpeed, double endSpeed) {\n    if (startSpeed > endSpeed)\n      a = -a;\n    \n    double time = (endSpeed - startSpeed) / a;\n    double dist = 0.5*a*time*time + startSpeed*time;\n    return new double[] {time, dist};\n  }\n  \n  // returns time it takes to travel dist, with given inputs\n  public static double travelS(int a, double startSpeed, double maxSpeed, double dist) {\n    double timeToMax = (maxSpeed - startSpeed) / a;\n    double targetTime = (-startSpeed + Math.sqrt(startSpeed*startSpeed + 2*a*dist)) / a;\n    if (targetTime < timeToMax)\n      return targetTime;\n    \n    double partialDist = 0.5*timeToMax*timeToMax*a + startSpeed*timeToMax;\n    double remainingDist = dist - partialDist;\n    targetTime = remainingDist / maxSpeed;\n    return targetTime + timeToMax;\n  }\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\n\tprivate BufferedReader in;\n\tprivate BufferedWriter out;\n\n\tdouble time(double a, double l, double v0, double v) {\n\t\tdouble t = (v - v0) / a;\n\t\tdouble s = a * t * t / 2 + v0 * t;\n\t\tif (s <= l) {\n\t\t\treturn t + (l - s) / v;\n\t\t}\n\n\t\tdouble B = v0, C = -l;\n\t\tdouble D = Math.sqrt(B * B - 2 * a * C);\n\t\treturn (-B + D) / a;\n\t}\n\n\t// )(()()))(())))\n\tpublic void solve() throws Exception {\n\t\tStreamTokenizer st = new StreamTokenizer(in);\n\t\tst.nextToken();\n\t\tdouble a = st.nval;\n\t\tst.nextToken();\n\t\tdouble v = st.nval;\n\t\tst.nextToken();\n\t\tdouble l = st.nval;\n\t\tst.nextToken();\n\t\tdouble d = st.nval;\n\t\tst.nextToken();\n\t\tdouble w = st.nval;\n\n\t\tdouble ttt = Math.sqrt(2 * d / a);\n\t\tdouble ans = 0.0;\n\n\t\tif (w > v || ttt * a < w) {\n\t\t\tans = time(a, l, 0, v);\n\t\t} else {\n\t\t\tdouble B = 2 * w / a, C = -w * w / (a * a) - 4 * d / a;\n\t\t\tdouble D = Math.sqrt(B * B - 4 * C);\n\t\t\tans = (-B + D) / 2;\n\t\t\tif ((a * ans + w) / 2.0 > v) {\n\t\t\t\tdouble t1 = v / a;\n\t\t\t\tdouble t2 = (v - w) / a;\n\t\t\t\tdouble s = (a * t1 * t1 / 2.0) + (v * t2 - a * t2 * t2 / 2.0);\n\t\t\t\tans = t1 + t2 + (d - s) / v;\n\t\t\t}\n\t\t\tans += time(a, l - d, w, v);\n\t\t}\n\t\tDecimalFormat df = new DecimalFormat(\"0.000000000\");\n\t\tout.write(df.format(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\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 static void main(String[] args) {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t} catch (Exception e) {\n\t\t}\n\t\tnew Main().run();\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "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 Main {\n\n    FastScanner in;\n    PrintWriter out;\n\n    public void solve() throws IOException {\n        double a = in.nextInt();\n        double v = in.nextInt();\n        double l = in.nextInt();\n        double d = in.nextInt();\n        double w = in.nextInt();\n\n        if (w * w / (a * 2) > d || v < w) {\n            if (v * v / (a * 2) > l) {\n                out.println(Math.sqrt(l * 2 / a));\n            }\n            else {\n                double t = v / a;\n                double s = l - t * v / 2;\n                t = t + s / v;\n                out.println(t);\n            }\n            return;\n        }\n        double t = solveD(a, v, w, d);\n        if ((v + w) * (v - w) / (a * 2) > l - d) {\n            double dis = w * w + a * (l - d) * 2;\n            double t1 = (Math.sqrt(dis) - w) / a;\n            System.out.println(t + t1);\n        }\n        else {\n            double t1 = (v - w) / a;\n            double s = l - d - (v + w) * t1 / 2;\n            double t2 = s / v;\n            System.out.println(t + t1 + t2);\n        }\n    }\n\n    public double solveD(double a, double vMax, double wBound, double s) {\n        double v = Math.sqrt(a * s + wBound * wBound / 2);\n        if (v > vMax) {\n            v = vMax;\n        }\n        double t1 = v / a;\n        double t2 = (v - wBound) / a;\n        double s1 = v * t1 / 2;\n        double s2 = (v + wBound) * t2 / 2;\n        double sr = s - s1 - s2;\n        double tr = sr / v;\n        return t1 + t2 + tr;\n\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 Main().run();\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n    public static void main(String[] args) throws IOException {\n        new D().solve();\n    }\n\n    static final double EPS = 1e-10;\n\n    Parser parser;\n\n    enum Result {\n        UNDER, OVER\n    }\n\n    private void solve() throws IOException {\n        this.parser = new Parser(new BufferedReader(new InputStreamReader(System.in)));\n        double a = parser.nextInt();\n        double vmax = parser.nextInt();\n        double l = parser.nextInt();\n        double d = parser.nextInt();\n        double w = parser.nextInt();\n        double low = 0;\n        double high = 20000;\n        while (Math.abs(high - low) > 1e-10) {\n            double accelerateTime = (low + high) / 2;\n            Result res = check(accelerateTime, a, vmax, d, w).result;\n            if (res == Result.UNDER) {\n                low = accelerateTime;\n            } else {\n                high = accelerateTime;\n            }\n        }\n        IP ip = check(high, a, vmax, d, w);\n        TV tv = tv(ip.v, l - d, a, vmax);\n        PrintWriter pw = new PrintWriter(System.out);\n        pw.printf(\"%.5f\\n\", ip.time + tv.time);\n        pw.close();\n    }\n\n    private IP check(double accelerateTime, double a, double vmax, double d, double w) {\n        DV dv = dv(0, a, accelerateTime, vmax);\n        if (dv.d > d) {\n            return new IP(accelerateTime, dv.v, Result.OVER);\n        }\n        Double slowTime = time2MakeDist(-a, dv.v, d - dv.d);\n        if (slowTime == null) {\n            return new IP(0, 0, Result.UNDER);\n        }\n        double vDown = dv.v - a * slowTime;\n        if (vDown < w) {\n            return new IP(0, 0, Result.UNDER);\n        } else {\n            return new IP(accelerateTime + slowTime, vDown, Result.OVER);\n        }\n    }\n\n    static class IP {\n        final double time;\n        final double v;\n        final Result result;\n\n        IP(double time, double v, Result result) {\n            this.time = time;\n            this.v = v;\n            this.result = result;\n        }\n    }\n\n    static class DV {\n        final double d;\n        final double v;\n\n        DV(double d, double v) {\n            this.d = d;\n            this.v = v;\n        }\n    }\n\n    static class TV {\n        final double time;\n        final double v;\n\n        TV(double time, double v) {\n            this.time = time;\n            this.v = v;\n        }\n    }\n\n    static Double time2MakeDist(double a, double v0, double dist) {\n        return quadric(a / 2, v0, -dist);\n    }\n\n    static TV tv(double v0, double d, double a, double vmax) {\n        double acTime = (vmax - v0) / a;\n        double unboundedTime = time2MakeDist(a, v0, d);\n        if (unboundedTime > acTime) {\n            double ad = dist(v0, a, acTime);\n            return new TV(acTime + (d - ad) / vmax, vmax);\n        } else {\n            return new TV(unboundedTime, v0 + a * unboundedTime);\n        }\n    }\n\n    static DV dv(double v0, double a, double time, double vmax) {\n        double time2maxV = (vmax - v0) / a;\n        if (time2maxV < time) {\n            return new DV(dist(v0, a, time2maxV) + dist(vmax, 0, time - time2maxV), vmax);\n        } else {\n            return new DV(dist(v0, a, time), v0 + a * time);\n        }\n    }\n\n    static double dist(double v0, double a, double time) {\n        return v0 * time + a * time * time / 2;\n    }\n\n    static Double quadric(final double a, final double b, final double c) {\n        double d = b * b - 4 * a * c;\n        if (d < -EPS) {\n            return null;\n        }\n        d = Math.abs(d);\n        double x1 = (-b + Math.sqrt(d)) / (2 * a);\n        double x2 = (-b - Math.sqrt(d)) / (2 * a);\n        double r = Integer.MAX_VALUE;\n        if (x1 > -EPS) {\n            r = x1;\n        }\n        if (x2 > -EPS) {\n            r = Math.min(r, x2);\n        }\n        if (r == Integer.MAX_VALUE) {\n            throw new RuntimeException(\"BOTVA\");\n        }\n        return r;\n    }\n\n    static class Parser {\n\n        final BufferedReader br;\n        StringTokenizer st = new StringTokenizer(\"\");\n\n        public Parser(BufferedReader bufferedReader) {\n            this.br = bufferedReader;\n        }\n\n        String nextToken() throws IOException {\n            while (!st.hasMoreTokens()) {\n                st = new StringTokenizer(br.readLine());\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() throws IOException {\n            return Integer.parseInt(nextToken());\n        }\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "\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 madis\n */\npublic class Rules {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        double a = in.nextInt();\n        double v = in.nextInt();\n        double l = in.nextInt();\n        double d = in.nextInt();\n        double w = in.nextInt();\n\n        if (v <= w) {\n            double t = v / a;\n            if (0.5 * t * t * a > l) {\n                t = Math.sqrt(2 * l / a);\n            } else {\n                t += (l - 0.5 * t * t * a) / v;\n            }\n            System.out.printf(\"%.5f\", t);\n\n        } else {\n            double total = 0.0;\n            double t = v / a;\n            double t2 = (v - w) / a;\n            double tempt = Math.sqrt(2.0 * d / a);\n            if (tempt * a <= w) {\n                total += tempt;\n                w = tempt*a;\n            } else if (0.5 * t * t * a +v*t2 - 0.5 * t2 * t2 * a > d) {\n                double as = 2.0*a;\n                double bs = 4.0*w;\n                double cs = ((w * w) / (a) - 2.0 * d );\n\n                double delta = bs * bs - 4.0 * as * cs;\n                double root = (-bs + Math.sqrt(delta)) / (2.0 * as);\n                if (root < 0.0) {\n                    root = (-bs - Math.sqrt(delta)) / (2.0 * as);\n                }\n                total += (2.0 * root + w / a);\n            } else {\n                total += t + t2;\n                double smd = (d - 0.5 * t * t * a - v*t2 + 0.5 * t2 * t2 * a) / v;\n                total += smd;\n            }\n            double t3 = (v - w) / a;\n            if (w * t3 + 0.5 * t3 * t3 * a > l - d) {\n                double as = 0.5 * a;\n                double bs = w;\n                double cs = d - l;\n\n                double delta = bs * bs - 4.0 * as * cs;\n                double root = (-bs + Math.sqrt(delta)) / (2.0 * as);\n                if (root < 0.0) {\n                    root = (-bs - Math.sqrt(delta)) / (2.0 * as);\n                }\n                total += root;\n            } else {\n                total += t3;\n                double t4 = (l - (w * t3 + 0.5 * t3 * t3 * a) - d) / v;\n                total += t4;\n            }\n            System.out.printf(\"%.5f\", total);\n        }\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Solution implements Runnable {\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\tprivate Random rnd;\n\t\n\tdouble Vend;\n\t\n\tprivate double calcFirstSegment(double a, double Vmax, double Vend, double l) {\n\t\tdouble Vl = 0, Vr = Vmax;\n\t\t\n\t\tfor(int it = 0; it < 256; it++) {\n\t\t\tdouble Vm = (Vl + Vr) / 2.0;\n\t\t\t\n\t\t\tdouble tFirst = Vm / a;\n\t\t\t\n\t\t\tdouble tSecond = 0;\n\t\t\tif(Vend < Vm) tSecond = (Vm - Vend) / a;\n\t\t\t\n\t\t\tdouble firstPart = a * tFirst * tFirst / 2.0;\n\t\t\tdouble secondPart = Vm * tSecond - a * tSecond * tSecond / 2.0;\n\t\t\t\n\t\t\tdouble res = firstPart + secondPart;\n\t\t\t\n\t\t\tif(res < l) Vl = Vm;\n\t\t\telse Vr = Vm;\n\t\t}\n\t\t\n\t\tthis.Vend = Math.min(Vl, Vend);\n\t\t\n\t\tdouble res = 0.0;\n\t\t\n\t\t{\n\t\t\tdouble Vm = Vl;\n\t\t\t\n\t\t\tdouble tFirst = Vm / a;\n\t\t\tdouble tSecond = 0;\n\t\t\tif(Vend < Vm) tSecond = (Vm - Vend) / a;\n\t\t\t\n\t\t\t//out.println(tSecond);\n\t\t\t\n\t\t\tdouble firstPart = a * tFirst * tFirst / 2.0;\n\t\t\tdouble secondPart = Vm * tSecond - a * tSecond * tSecond / 2.0;\n\t\t\t\n\t\t\tdouble remain = l - firstPart - secondPart;\n\t\t\t\n\t\t\tres = tFirst + tSecond + (remain / Vm);\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\t\n\tprivate double calcSecondPart(double a, double Vmax, double Vstart, double l) {\n\t\tdouble Vl = Vstart, Vr = Vmax;\n\t\t\n\t\t//out.println(Vstart);\n\t\t\n\t\tfor(int it = 0; it < 256; it++) {\n\t\t\tdouble Vm = (Vl + Vr) / 2.0;\n\t\t\tdouble t = (Vm - Vstart) / a;\n\t\t\t\n\t\t\tdouble s = Vstart * t + a * t * t / 2.0;\n\t\t\t\n\t\t\tif(s < l) Vl = Vm;\n\t\t\telse Vr = Vm;\n\t\t}\n\t\t\n\t\tdouble res = 0.0;\n\t\t\n\t\t{\n\t\t\tdouble Vm = (Vl + Vr) / 2.0;\n\t\t\tdouble t = (Vm - Vstart) / a;\n\t\t\t\n\t\t\tdouble s = Vstart * t + a * t * t / 2.0;\n\t\t\t\n\t\t\tdouble remain = l - s;\n\t\t\t\n\t\t\tres = t + (remain / Vmax);\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tdouble a = nextDouble(), v = nextDouble(), l = nextDouble(), d = nextDouble(), w = nextDouble();\n\t\t\n\t\tdouble res = calcFirstSegment(a, v, w, d);\n\t\tres += calcSecondPart(a, v, Vend, l - d);\n\t\t\n\t\tout.println(res);\n\t}\n\t\t\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\n\t} \n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\t//in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t//out = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\t\n\t\t\tin = new BufferedReader(new InputStreamReader((System.in)));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t\n\t\t\tst = null;\n\t\t\trnd = new Random();\n\t\t\t\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t} catch(IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\t\n\t}\n\t\n\tprivate String nextToken() throws IOException, NullPointerException {\n\t\twhile(st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Berland implements Runnable {\n    private void solve() throws IOException {\n        double a = nextInt();\n        double v = nextInt();\n        double l = nextInt();\n        double d = nextInt();\n        double w = nextInt();\n        double res;\n        if (v <= w) {                                                         \n            res = simpleCase(a, v, l, 0);\n        } else {\n            double vMax = Math.sqrt(2 * d * a);\n            if (vMax <= w) {\n                res = simpleCase(a, v, l, 0);\n            } else {\n                double tFullSpeed = v / a;\n                double tSlowdown = (v - w) / a;\n                if (a * tFullSpeed * tFullSpeed / 2 + v * tSlowdown - a * tSlowdown * tSlowdown / 2 <= d) {\n                    res = tFullSpeed + tSlowdown + (d - (a * tFullSpeed * tFullSpeed / 2 + v * tSlowdown - a * tSlowdown * tSlowdown / 2)) / v + simpleCase(a, v, l - d, w);\n                } else {\n                    double min = w;\n                    double max = v;\n                    for (int i = 0; i < 1000; ++i) {\n                        double cur = (min + max) / 2;\n                        double cFullSpeed = cur / a;\n                        double cSlowdown = (cur - w) / a;\n                        if (a * cFullSpeed * cFullSpeed / 2 + cur * cSlowdown - a * cSlowdown * cSlowdown / 2 <= d)\n                            min = cur;\n                        else\n                            max = cur;\n                    }\n                    res = min / a + (min - w) / a + simpleCase(a, v, l - d, w);\n                }\n            }\n        }\n        writer.printf(\"%.20f\\n\", res);\n    }\n\n    private double simpleCase(double a, double v, double l, double v0) {\n        double tFullSpeed = (v - v0) / a;\n        if (v0 * tFullSpeed + a * tFullSpeed * tFullSpeed / 2 <= l) {\n            return tFullSpeed + (l - (v0 * tFullSpeed + a * tFullSpeed * tFullSpeed / 2)) / v; \n        } else {\n            double min = 0;\n            double max = tFullSpeed;\n            for (int i = 0; i < 1000; ++i) {\n                double cur = (min + max) / 2;\n                if (v0 * cur + a * cur * cur / 2 <= l)\n                    min = cur;\n                else\n                    max = cur;\n            }\n            return min;\n        }\n    }\n\n\n    public static void main(String[] args) {\n        new Berland().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}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class Rules implements Runnable {\n\tprivate Scanner in = new Scanner(System.in);\n\tprivate PrintWriter out = new PrintWriter(System.out);\n\tprivate double a, v, l, d, w;\n\tprivate double ans;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Rules()).start();\n\t}\n\n\tpublic void run() {\n\t\tread();\n\t\tsolve();\n\t\twrite();\n\t\tout.close();\n\t}\n\n\tprivate void read() {\n\t\ta = in.nextInt();\n\t\tv = in.nextInt();\n\t\tl = in.nextInt();\n\t\td = in.nextInt();\n\t\tw = in.nextInt();\n\t}\n\n\tprivate double remaining(double v0, double dst) {\n\t\tdouble t = (v - v0) / a;\n\t\tdouble d = a * t * t / 2 + t * v0;\n\t\tif (d > dst)\n\t\t\treturn (Math.sqrt(v0 * v0 + 2 * a * dst) - v0) / a;\n\t\treturn t + (dst - d) / v;\n\t}\n\n\tprivate void solve() {\n\t\tif (w * w >= 2 * a * d || w >= v) {\n\t\t\tans = remaining(0, l);\n\t\t\treturn;\n\t\t}\n\t\t{\n\t\t\tdouble t1 = v / a;\n\t\t\tdouble t2 = (v - w) / a;\n\t\t\tdouble dd = a * t1 * t1 / 2 + a * t2 * t2 / 2 + w * t2;\n\t\t\tif (dd < d) {\n\t\t\t\tans = t1 + t2 + (d - dd) / v + remaining(w, l - d);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tdouble t1 = w / a;\n\t\tdouble rd = d - t1 * t1 * a / 2;\n\t\tdouble t2 = (Math.sqrt(w * w + a * rd) - w) / a;\n\t\tans = t1 + 2 * t2 + remaining(w, l - d);\n\t}\n\n\tprivate void write() {\n\t\tout.printf(\"%.7f\\n\", ans);\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic Scanner in = new Scanner(new BufferedInputStream(System.in));\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic double getTime(double v, double a, double l, double r) {\n\t\treturn (-v + Math.sqrt(v * v - 2 * a * (l - r))) / a;\n\t}\n\n\tstatic double getVelocity(double v, double t, double l, double r) {\n\t\treturn t == 0 ? v : (2 * (r - l)) / t - v;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tdouble a = in.nextDouble(), v = in.nextDouble(), l = in.nextDouble(),\n\t\t\t\td = in.nextDouble(), w = Math.min(v, in.nextDouble());\n\n\t\tdouble x = v * v / (2 * a), y = d - (v * v - w * w) / (2 * a),\n\t\t\t\tz = d + (v * v - w * w) / (2 * a);\n\t\t//out.println(x + \" \" + y + \" \" + z);\n\t\tdouble L, R, T = 0, V = 0, t;\n\n\t\t//OX\n\t\tL = 0;\n\t\tR = x;\n\t\tif (x > y && x < z) {\n\t\t\tR = (x + y) / 2;\n\t\t} else if (x > l) {\n\t\t\tR = l;\n\t\t}\n\t\tt = getTime(V, a, L, R);\n\t\tV = getVelocity(V, t, L, R);\n\t\t//out.println(\"l: \" + L + \", r: \" + R + \", t: \" + t + \", v: \" + V);\n\t\tT += t;\n\n\t\t//XY\n\t\tif (x < y) {\n\t\t\tT += (y - x) / v;\n\t\t}\n\t\t//out.println(\"t: \" + (T - t));\n\n\t\t//YD\n\t\tL = y;\n\t\tR = d;\n\t\tif (x > y && x < z) {\n\t\t\tL = (x + y) / 2;\n\t\t} else if (x >= z) {\n\t\t\tL = R;\n\t\t}\n\t\tt = getTime(V, -a, L, R);\n\t\tV = getVelocity(V, t, L, R);\n\t\tT += t;\n\t\t//out.println(\"l: \" + L + \", r: \" + R + \", t: \" + t + \", v: \" + V);\n\n\t\t//DZ\n\t\tL = d;\n\t\tR = z;\n\t\tif (x >= z) {\n\t\t\tR = L;\n\t\t} else if (z > l) {\n\t\t\tR = l;\n\t\t}\n\t\tt = getTime(V, a, L, R);\n\t\tV = getVelocity(V, t, L, R);\n\t\tT += t;\n\t\t//out.println(\"l: \" + L + \", r: \" + R + \", t: \" + t + \", v: \" + V);\n\n\t\t//ZL\n\t\tL = z;\n\t\tR = l;\n\t\tif (x > z) {\n\t\t\tL = x;\n\t\t}\n\t\tif (L < R) {\n\t\t\tT += (R - L) / v;\n\t\t}\n\n\t\tout.format(Locale.US, \"%.12f%n\", T);\n\t\tout.close();\n\t}\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.math.BigInteger;\n\npublic class Main {\n\tfinal int INF = 1000000000;\n\tfinal int MAXN = 100100;\t\n\t\n\tScanner input = new Scanner(System.in);\n\tBufferedReader inp = new BufferedReader(new InputStreamReader(System.in));\n\tPrintWriter out = new PrintWriter(System.out);\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().run();\n\t}\n\t\n\tdouble a, v;\n\tdouble l, d, w;\n\t\n\tvoid run() throws IOException {\n\t\ta = input.nextDouble();\n\t\tv = input.nextDouble();\n\t\tl = input.nextDouble();\n\t\td = input.nextDouble();\n\t\tw = input.nextDouble();\n\t\tif (v <= w) {\n\t\t\tout.println(timeTravel(l, 0));\n\t\t} else {\n\t\t\tdouble tw = w / a;\n\t\t\tdouble dw = dist(tw, 0);\n\t\t\tif (dw >= d) {\n\t\t\t\tout.println(timeTravel(l, 0));\n\t\t\t} else {\n\t\t\t\tdouble tSym = timeTravel((d - dw) / 2, w);\n\t\t\t\tout.println(tw + 2 * tSym + timeTravel(l - d, w));\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\t\n\t\n\tdouble dist(double time, double speed) {\n\t\treturn speed * time + a * time * time / 2; \n\t}\n\t\n\tdouble timeTravel(double distance, double speed) {\n\t\tdouble delta = speed * speed + 2 * a * distance;\n\t\tdouble tAll = (Math.sqrt(delta) - speed) / a;\n\t\tdouble tMax = (v - speed) / a;\n\t\tif (tMax >= tAll) {\n\t\t\treturn tAll;\n\t\t} else {\n\t\t\treturn tMax + (distance - dist(tMax, speed)) / v;\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Task5d {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tdouble a = sc.nextDouble();\n\t\tdouble v = sc.nextDouble();\n\t\tdouble l = sc.nextDouble();\n\t\tdouble d = sc.nextDouble();\n\t\tdouble w = sc.nextDouble();\n\t\tdouble t = 0;\n\t\tif (w >= v) {\n\t\t\tdouble t1 = v / a;\n\t\t\tdouble s1 = a * t1 * t1 / 2;\n\t\t\tif (s1 > l) {\n\t\t\t\tt = Math.sqrt(2 * l / a);\n\t\t\t} else {\n\t\t\t\tt = t1 + (l - s1) / v;\n\t\t\t}\n\t\t} else {\n\t\t\tdouble t2 = Math.sqrt(2 * d / a);\n\t\t\tif (a * t2 <= w) {\n\t\t\t\tdouble t1 = v / a;\n\t\t\t\tdouble s1 = a * t1 * t1 / 2;\n\t\t\t\tif (s1 > l) {\n\t\t\t\t\tt = Math.sqrt(2 * l / a);\n\t\t\t\t} else {\n\t\t\t\t\tt = t1 + (l - s1) / v;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble tup = v / a;\n\t\t\t\tdouble tdown = (v - w) / a;\n\t\t\t\tdouble sup = a * tup * tup / 2;\n\t\t\t\tdouble sdown = v * tdown - a * tdown * tdown / 2;\n\t\t\t\tif (sup + sdown <= d) {\n\t\t\t\t\tdouble tmax = (d - sup - sdown) / v;\n\t\t\t\t\tt = tup + tmax + tdown;\t\t\t\t\t\n\t\t\t\t} else {\n\t\t\t\t\tdouble tw = w / a;\n\t\t\t\t\tdouble sw = a * tw * tw / 2;\n\t\t\t\t\tdouble sl = (d - sw) / 2;\n\t\t\t\t\tdouble dis = w * w + 2 * a * sl;\n\t\t\t\t\tdouble tu1 = (- w - Math.sqrt(dis)) / a;\n\t\t\t\t\tif (tu1 < 0) {\n\t\t\t\t\t\ttu1 = (- w + Math.sqrt(dis)) / a;\n\t\t\t\t\t}\n\t\t\t\t\tt = tw + 2 * tu1;\n\t\t\t\t}\n\t\t\t\tdouble sreup = w * tdown + a * tdown * tdown / 2;\n\t\t\t\tif (sreup <= l - d) {\n\t\t\t\t\tt += tdown;\n\t\t\t\t\tt += (l - d - sreup) / v;\n\t\t\t\t} else {\n\t\t\t\t\tdouble dis = w * w - 2 * a * (d - l);\n\t\t\t\t\tdouble tu1 = (- w - Math.sqrt(dis)) / a;\n\t\t\t\t\tif (tu1 < 0) {\n\t\t\t\t\t\ttu1 = (- w + Math.sqrt(dis)) / a;\n\t\t\t\t\t}\n\t\t\t\t\tt += tu1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(t);\n\t}\n\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D5 implements Runnable {\n\n\tfinal double eps = 1e-9;\n\n\tprivate void Solution() throws IOException {\n\t\tdouble a = nextDouble(), v = nextDouble();\n\t\tdouble l = nextDouble(), d = nextDouble(), w = nextDouble();\n\t\tdouble t = 0;\n\t\tif (w + eps > v) {\n\t\t\tdouble s = v * v / (2 * a);\n\t\t\tif (s + eps > l)\n\t\t\t\tt = Math.sqrt(2 * l / a);\n\t\t\telse {\n\t\t\t\tdouble ta = v / a;\n\t\t\t\tdouble sa = a * ta * ta / 2;\n\t\t\t\tt = ta + (l - sa) / v;\n\t\t\t}\n\t\t} else {\n\t\t\tdouble sv = v * v / (2 * a);\n\t\t\tdouble sw = w * w / (2 * a);\n\t\t\tif (sw + eps > d) {\n\t\t\t\tif (sv + eps > l)\n\t\t\t\t\tt = Math.sqrt(2 * l / a);\n\t\t\t\telse {\n\t\t\t\t\tdouble ta = v / a;\n\t\t\t\t\tdouble sa = a * ta * ta / 2;\n\t\t\t\t\tt = ta + (l - sa) / v;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble sd = (w * w - v * v) / (-2 * a);\n\t\t\t\tif (sv + sd < eps + d)\n\t\t\t\t\tt = v / a + (d - sv - sd) / v + (v - w) / a;\n\t\t\t\telse {\n\t\t\t\t\tdouble f = Math.sqrt(d * a + w * w / 2);\n\t\t\t\t\tt = f / a + (f - w) / a;\n\t\t\t\t}\n\t\t\t\tif (sd + eps > l - d) {\n\t\t\t\t\tdouble lv = Math.sqrt((l - d) * 2 * a + w * w);\n\t\t\t\t\tt += (lv - w) / a;\n\t\t\t\t} else {\n\t\t\t\t\tt += (v - w) / a + (l - d - sd) / v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.printf(\"%.12f\", t);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D5().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tSolution();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\n\tvoid print(Object... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tout.print(\" \");\n\t\t\tout.print(obj[i]);\n\t\t}\n\t}\n\n\tvoid println(Object... obj) {\n\t\tprint(obj);\n\t\tprint(\"\\n\");\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tString nextLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n\n\tString next() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\treturn tokenizer.nextToken();\n\t}\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class n5D\n{\n    public static void main(String[] args)\n    {\n        double a = 0, v = 0, l = 0, d = 0, w = 0;\n        try\n        {\n            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n            String[] str = br.readLine().split(\" \");\n            a = Double.parseDouble(str[0]);\n            v = Double.parseDouble(str[1]);\n            str = br.readLine().split(\" \");\n            l = Double.parseDouble(str[0]);\n            d = Double.parseDouble(str[1]);\n            w = Double.parseDouble(str[2]);\n        }\n        catch(Exception e)\n        {\n            System.out.println(e);\n        }\n\n        double t1, t2, t3, t4, t5, t, D = 0;\n        \n        if (w > v) w = v;\n        t2 = d / v - v / a + w * w / 2 / a / v;\n        if (t2 >= 0)\n        {\n            t1 = v / a; \n            t3 = t1 - w / a;\n        }\n        else\n        {\n            if (Math.sqrt(2 * d / a) > (w / a))\n            {\n                t1 = Math.sqrt((2 * a * d + w * w) / (a * a * 2));\n                t3 = t1 - w / a;\n            }\n            else\n            {\n                t1 = Math.sqrt(2 * d / a);\n                t3 = 0;\n            }\n            t2 = 0;\n        }\n        t5 = (l - d - v * v / 2 / a + a * (t1 - t3) * (t1 - t3) / 2) / v;\n        if (t5 >= 0) t4 = v / a - (t1 - t3);\n        else\n        {\n            t5 = 0;\n            t4 = -t1 + t3 + Math.sqrt((t1 - t3) * (t1 - t3) + 2 * (l - d) / a);\n        }\n        t = t1 + t2 + t3 + t4 + t5;\n        System.out.println(t);\n        //System.out.println(t1 + \" \" + t2 + \" \" + t3 + \" \" + t4 + \" \" + t5);\n    }\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "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\n\npublic class D5 {\n    \n    static StringTokenizer st;\n    static BufferedReader in;\n    public static void main(String[] args) throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        double a = nextInt();\n        double v = nextInt();\n        double L = nextInt();\n        double d = nextInt();\n        double w = nextInt();\n        double ans = 0;\n        if (w >= v)\n            ans = go(0, a, L, v);\n        else {\n            ans = go(Math.min(w, Math.sqrt(2*a*d)), a, L-d, v);\n            if (2*a*d < w*w)\n                ans += Math.sqrt(2*d/a);\n            else {\n                if (d-v*v/(2*a) >= (v*v-w*w)/(2*a))\n                    ans += v/a+(v-w)/a+(d-v*v/(2*a)-(v*v-w*w)/(2*a))/v;\n                else {\n                    double x = Math.sqrt((w*w+2*a*d)/2);\n                    ans += x/a+(x-w)/a;\n                }\n            }\n        }\n        System.out.println(ans);\n        pw.close();\n    }\n    \n    private static double go(double v0, double a, double s, double vmax) {\n        double t = (vmax-v0) / a;\n        if (v0*t+a*t*t/2 < s)\n            return t+(s-v0*t-a*t*t/2) / vmax;\n        else {\n            double D = v0*v0+2*a*s;\n            return (-v0+Math.sqrt(D))/a;\n        }\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}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Rules {\n  public static void main(String[] args) {\n    Scanner in = new Scanner(System.in);\n    int a = in.nextInt();\n    double maxSpeed = in.nextInt();\n    double len = in.nextInt();\n    double delayDist = in.nextInt();\n    double delaySpeed = in.nextInt();\n    \n    // two cases: I reach the delayPoint at a speed higher than the delaySpeed, or I don't.\n    double timeToDelayAtMax = travelS(a, 0.0, maxSpeed, delayDist);\n    double timeToDelayAtDelay = travelS(a, 0.0, delaySpeed, delayDist);\n    if (Math.abs(timeToDelayAtMax-timeToDelayAtDelay) < 0.00001) {\n      // I can reach the delayPoint without being delayed\n      double time = travelS(a, 0.0, maxSpeed, len);\n      System.out.printf(\"%.9f\\n\", time);\n      return;\n    }\n    \n    // binary search to find best velocity to stop acceleration in beginning\n    double lowV = delaySpeed;\n    double highV = maxSpeed;\n    int loopCount = 1000;\n    double[] initial = null;\n    double[] secondary = null;\n    while (loopCount-->0) {\n      double guessV = (lowV+highV)/2.0;\n      initial = travelA(a, 0.0, guessV);\n      secondary = travelA(a, guessV, Math.min(delaySpeed, maxSpeed));\n      if (initial[1] + secondary[1] < delayDist) { // okay, we can go faster\n        lowV = guessV;\n      } else {\n        highV = guessV;\n      }\n    }\n    double totalTime = 0.0;\n    double finalSpeed = 0.0;\n    initial = travelA(a, 0.0, lowV);\n    secondary = travelA(a, lowV, delaySpeed);\n    totalTime = initial[0] + secondary[0];\n    double totalDist = initial[1] + secondary[1];\n    totalTime += (delayDist-totalDist)/maxSpeed;\n    \n    // now we have delayDist to go, and we are at delaySpeed\n    totalTime += travelS(a, delaySpeed, maxSpeed, len-delayDist);\n    System.out.printf(\"%.9f\\n\", totalTime);\n  }\n  \n  // [0] = time in h, [1] = dist travelled, in km\n  // input units are in km/h^2, km/h, km/h\n  public static double[] travelA(int a, double startSpeed, double endSpeed) {\n    if (startSpeed > endSpeed)\n      a = -a;\n    \n    double time = (endSpeed - startSpeed) / a;\n    double dist = 0.5*a*time*time + startSpeed*time;\n    return new double[] {time, dist};\n  }\n  \n  // returns time it takes to travel dist, with given inputs\n  public static double travelS(int a, double startSpeed, double maxSpeed, double dist) {\n    double timeToMax = (maxSpeed - startSpeed) / a;\n    double targetTime = (-startSpeed + Math.sqrt(startSpeed*startSpeed + 2*a*dist)) / a;\n    if (targetTime < timeToMax)\n      return targetTime;\n    \n    double partialDist = 0.5*timeToMax*timeToMax*a + startSpeed*timeToMax;\n    double remainingDist = dist - partialDist;\n    targetTime = remainingDist / maxSpeed;\n    return targetTime + timeToMax;\n  }\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "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\tdouble f(int dist, double initSp, int a, int maxSp) {\n\t\tdouble distToReachMaxSpeed = 0.5 * (maxSp * maxSp - initSp * initSp)\n\t\t\t\t/ a;\n\n\t\tif (dist > distToReachMaxSpeed)\n\t\t\treturn 1d * (maxSp - initSp) / a + (dist - distToReachMaxSpeed)\n\t\t\t\t\t/ maxSp;\n\n\t\treturn (Math.sqrt(initSp * initSp + 2 * a * dist) - initSp) / a;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint a = nextInt();\n\t\tint maxSp = nextInt();\n\t\tint len = nextInt();\n\t\tint signX = nextInt();\n\t\tint signSp = nextInt();\n\n\t\tif (maxSp <= signSp) {\n\t\t\tout.printf(\"%.9f\\n\", f(len, 0, a, maxSp));\n\t\t\treturn;\n\t\t}\n\n\t\tdouble distToReachSignSp = 0.5 * signSp * signSp / a;\n\t\tif (distToReachSignSp >= signX) {\n\t\t\tout.printf(\"%.9f\\n\", f(len, 0, a, maxSp));\n\t\t\treturn;\n\t\t}\n\n\t\tdouble distToReachMaxThenSign = 0.5\n\t\t\t\t* (maxSp * maxSp + maxSp * maxSp - signSp * signSp) / a;\n\t\tif (distToReachMaxThenSign <= signX) {\n\t\t\tdouble t = 1d * (2 * maxSp - signSp) / a\n\t\t\t\t\t+ (signX - distToReachMaxThenSign) / maxSp\n\t\t\t\t\t+ f(len - signX, signSp, a, maxSp);\n\t\t\tout.printf(\"%.9f\\n\", t);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdouble xSp = Math.sqrt(a * signX + signSp * signSp * 0.5);\n\t\tdouble xTime = (2 * xSp - signSp) / a;\n\t\tout.printf(\"%.9f\\n\", xTime + f(len - signX, signSp, a, maxSp));\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", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class D0005 {\n\n    public static void main(String args[]) throws Exception {\n        new D0005();\n    }\n\n    D0005() throws Exception {\n        PandaScanner sc = null;\n        PrintWriter out = null;\n        try {\n            sc = new PandaScanner(System.in);\n            out = new PrintWriter(System.out);\n        } catch (Exception ignored) {\n        }\n\n        a = sc.nextInt();\n        max = sc.nextInt();\n\n        double length = sc.nextInt();\n        double dist = sc.nextInt();\n        double limit = sc.nextInt();\n\n        if (max <= limit) {\n            out.println(travelTime(length, 0));\n        }\n        else {\n            double tLimit = limit / a;\n            double dLimit = distance(0, tLimit);\n            if (dLimit >= dist) {\n                out.println(travelTime(length, 0));\n            }\n            else {\n                double res = tLimit + 2 * (travelTime(0.5 * (dist - dLimit), limit)) +\n                        travelTime(length - dist, limit);\n                out.println(res);\n            }\n        }\n\n        out.close();\n        System.exit(0);\n    }\n    double a, max;\n    double distance(double v, double t) {\n        return v * t + 0.5 * a * t * t;\n    }\n    double travelTime(double d, double v) {\n        double tAll = (-v + Math.sqrt(v * v + 2 * a * d)) / a;\n        double tMax = (max - v) / a;\n        if (tAll <= tMax) {\n            return tAll;\n        }\n        else {\n            return tMax + (d - distance(v, tMax)) / max;\n        }\n    }\n\n    //The PandaScanner class, for Panda fast scanning!\n    public class PandaScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        InputStream in;\n\n        PandaScanner(InputStream in) throws Exception {\n            br = new BufferedReader(new InputStreamReader(this.in = in));\n        }\n\n        public String next() throws Exception {\n            if (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(br.readLine().trim());\n                return next();\n            }\n            return st.nextToken();\n        }\n\n        public boolean hasNext() throws Exception {\n            return (st != null && st.hasMoreTokens()) || in.available() > 0;\n        }\n\n        public long nextLong() throws Exception {\n            return Long.parseLong(next());\n        }\n\n        public int nextInt() throws Exception {\n            return Integer.parseInt(next());\n        }\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Traffic extends Template{\n\tpublic double search1(int a, int w, int d){\n\t\tdouble s = 0;\n\t\tdouble l = 2*w+2*a*d;\n\t\tint repeat = 100;\n\t\twhile( repeat-- > 0 ){\n\t\t\tdouble x = (s+l)/2;\n\t\t\tif( a*a*x*x + 2*a*w*x - w*w - 4*a*d > 0 ){\n\t\t\t\tl = x;\n\t\t\t} else {\n\t\t\t\ts = x;\n\t\t\t}\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tpublic double search2(int a, double lim, int k){\n\t\tdouble s = 0;\n\t\tdouble l = lim + 2*a*k;\n\t\tint repeat = 100;\n\t\twhile( repeat-- > 0 ){\n\t\t\tdouble x = (s+l)/2;\n\t\t\tif( a*x*x + 2*lim*x - 2*k > 0 ){\n\t\t\t\tl = x;\n\t\t\t} else {\n\t\t\t\ts = x;\n\t\t\t}\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tint a = nextInt();\n\t\tint v = nextInt();\n\t\tint l = nextInt();\n\t\tint d = nextInt();\n\t\tint w = nextInt();\n\t\tif( w > v ){\n\t\t\tw = v;\n\t\t}\n\t\tdouble time_max = Math.sqrt((double)2*d/a);\n\t\tdouble time_d = search1(a,w,d);\n\t//\twriter.println(time_max*a < w); writer.println(v <= (w+a*time_d)/2); writer.println(w < v); \n\t\tdouble t1 = (time_max*a < w) ? time_max : (v >= (w+a*time_d)/2) ? time_d : (w < v) ? (double)(2*v*v-2*v*w+2*a*d+w*w)/(2*a*v) : (double)v/a + (double)(d-(double)v*v/(2*a))/v;\n\t\tdouble lim = (time_max*a < w) ? time_max*a : w;\n\t\tdouble t3 = Math.min((double)(v-lim)/a, search2(a, lim, l-d));\n//\t\tdouble t = (Math.sqrt(limit*limit+2*a*(l-d))-limit)/a;\n\t\tdouble dist2 = (l-d) - t3*t3*a/2 - t3*lim;\n\t\tdouble t4 = dist2/v;\n//\t\twriter.println(\"t1 = \" + t1);\n//\t\twriter.println(\"dist1 = \" + dist1);\n//\t\twriter.println(\"t3 = \" + t3);\n//\t\twriter.println(\"dist2 = \" + dist2);\n//\t\twriter.println(\"t4 = \" + t4);\n\t\twriter.println((t1+t3+t4));\n\t}\n\t\n\tpublic static void main(String[] args){\n\t\tnew Traffic().run();\n\t}\n}\n\nabstract class Template implements Runnable{\n\tpublic abstract void solve() throws IOException;\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch(Exception e){\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\t\n\tpublic int nextInt() throws IOException{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic 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}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import 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.io.UnsupportedEncodingException;\nimport java.util.StringTokenizer;\n\npublic class Main implements Runnable {\n\n    static Throwable sError;\n\n    public static void main(String[] args) throws Throwable {\n        Thread t = new Thread(new Main());\n        t.start();\n        t.join();\n        if (sError != null)\n            throw sError;\n    }\n\n    PrintWriter pw;\n    BufferedReader in;\n    StringTokenizer st;\n\n    void initStreams() throws FileNotFoundException,\n            UnsupportedEncodingException {\n        pw = new PrintWriter(System.out);\n        if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n            System.setIn(new FileInputStream(\"1\"));\n        }\n        in = new BufferedReader(new InputStreamReader(System.in, \"ISO-8859-9\"));\n    }\n\n    String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    public void run() {\n        try {\n            initStreams();\n            double a = nextDouble(), vmax = nextDouble(), l = nextDouble(), d = nextDouble(), w = nextDouble();\n            if (vmax <= w) {\n                double v = Math.sqrt(2 * a * l);\n                if (v <= vmax) {\n                    out(v / a);\n                } else {\n                    double s = vmax * vmax / (2 * a);\n                    double t = (l - s) / vmax;\n                    out(vmax / a + t);\n                }\n            } else {\n                double v = Math.sqrt(a * d + w * w / 2);\n                double t1 = 0;\n                if (w <= Math.sqrt(2 * a * d)) {\n                    if (v <= vmax) {\n                        t1 = v / a + (v - w) / a;\n                    } else {\n                        double s = d - vmax * vmax / (2 * a) - (vmax * vmax - w * w) / (2 * a);\n                        t1 = s / vmax + vmax / a + (vmax - w) / a;\n                    }   \n                } else {\n                    t1 = Math.sqrt(2 * d / a);\n                    w = a * t1;\n                }\n                v = Math.sqrt(2 * a * (l - d) + w * w);\n                double t2 = 0;\n                if (v <= vmax) {\n                    t2 = (v - w) / a;\n                } else {\n                    double s = l - d - (vmax * vmax - w * w) / (2 * a);\n                    t2 = (vmax - w) / a + s / vmax;\n                }\n                out(t1 + t2);\n            }\n        } catch (Throwable e) {\n            sError = e;\n        } finally {\n            pw.flush();\n            pw.close();\n        }\n    }\n\n    private void out(double t) {\n        pw.println(t);\n    }\n\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class RespectTheRules {\n    private static final double E = 1E-10;\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        double a = scanner.nextDouble();\n        double maxV = scanner.nextDouble();\n        double l = scanner.nextDouble();\n        double d = scanner.nextDouble();\n        double w = scanner.nextDouble();\n\n        double r = l - d;\n        w = Math.min(w, maxV);\n\n        List<WayPoint> wayPoints = new ArrayList<WayPoint>(256);\n        double t = 0;\n\n        wayPoints.add(new WayPoint(0));\n\n        double dW = dTo(w, 0, a);\n        if (leq(dW, d)) {\n            wayPoints.add(new WayPoint(w));\n            {\n                double v = v(w, a, (d - dW) / 2);\n                v = Math.min(v, maxV);\n\n                wayPoints.add(new WayPoint(v));\n                wayPoints.add(new WayPoint(w));\n\n                double dW_V = dTo(v, w, a);\n                double vDistance = d - dW - 2 * dW_V;\n                if (!eq(vDistance)) {\n                    t += vDistance / maxV;\n                }\n            }\n            {\n                double dW_MaxV = dTo(maxV, w, a);\n                dW_MaxV = Math.min(dW_MaxV, r);\n                double v = v(w, a, dW_MaxV);\n                wayPoints.add(new WayPoint(v));\n                double dMaxV = r - dW_MaxV;\n                if (!eq(dMaxV)) {\n                    t += dMaxV / maxV;\n                }\n            }\n\n        } else {\n            double dMaxV = dTo(maxV, 0, a);\n            dMaxV = Math.min(dMaxV, l);\n            double v = v(0, a, dMaxV);\n            wayPoints.add(new WayPoint(v));\n            double dv = l - dMaxV;\n            if (!eq(dMaxV)) {\n                t += dv / maxV;\n            }\n        }\n\n        for (int i = 1; i < wayPoints.size(); ++i) {\n            double v0 = wayPoints.get(i - 1).v;\n            double v = wayPoints.get(i).v;\n            t += Math.abs(tTo(v, v0, a));\n        }\n        System.out.println(t);\n    }\n\n    static double tTo(double v, double v0, double a) {\n        return (v - v0) / a;\n    }\n\n    static double dTo(double v, double v0, double a) {\n        return (v * v - v0 * v0) / (2 * a);\n    }\n\n    static double v(double v0, double a, double d) {\n        return Math.sqrt(2 * d * a + v0 * v0);\n    }\n\n    static boolean eq(double value) {\n        return Math.abs(value) <= E;\n    }\n\n    static boolean l(double v) {\n        return v < -E;\n    }\n\n    static boolean leq(double v) {\n        return l(v) || eq(v);\n    }\n\n    static boolean leq(double one, double another) {\n        return leq(one - another);\n    }\n\n    static class WayPoint {\n        double v;\n\n        WayPoint(double v) {\n            this.v = v;\n        }\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main {\n    private static final double EPS = 1e-11;\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st = new StringTokenizer(\"\");\n    \n    void run() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        \n        double a = nextDouble();\n        double v = nextDouble();\n        double l = nextDouble();\n        double d = nextDouble();\n        double w = nextDouble();\n        \n        double ans = 0.0;\n        \n        if (v < w + EPS || sqr(w) / 2 / a > d - EPS) {\n            double t1 = sqrt(2 * l / a);\n            double t2 = v / a;\n            \n            if (t1 < t2 + EPS) {\n                ans = t1;\n            } else {\n                ans = t2 + (l - a * sqr(t2) / 2) / v;\n            }\n        } else {\n            double t1 = v / a;\n            double t2 = (v - w) / a;\n            double s12 = a * sqr(t1) / 2 + w * t2 + a * sqr(t2) / 2;\n            \n            if (s12 < d + EPS) {\n                ans += t1 + t2 + (d - s12) / v;\n            } else {\n                double ta = sqrt(d / a + sqr(w / a) / 2);\n                double tb = ta - w / a;\n                ans += ta + tb;\n            }\n            \n            double r = l - d;\n            double tm = (v - w) / a;\n            double tx = (sqrt(sqr(w) + 2 * a * r) - w) / a;\n            \n            if (tx < tm + EPS) {\n                ans += tx;\n            } else {\n                ans += tm + (r - w * tm - a * sqr(tm) / 2) / v;\n            }\n        }           \n        \n        out.printf(Locale.US, \"%.12f%n\", ans);\n        out.close();\n    }\n    \n    double sqr(double x) { \n        return x * x;\n    }\n    \n    String nextToken() throws IOException {\n        while (!st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\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", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class D {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        double a = in.nextDouble();\n        double v = in.nextDouble();\n        double l = in.nextDouble();\n        double d = in.nextDouble();\n        double w = in.nextDouble();\n        double ans = 0;\n        double maxSpeedBySign = Math.sqrt(2 * a * d);\n        double speedAtSign = -1;\n        if (v <= w) {\n            if (maxSpeedBySign <= v) {\n                ans += Math.sqrt(2 * d / a);\n                speedAtSign = maxSpeedBySign;\n\n            } else {\n                ans += v / a;\n                double distanceLeftTillSign = d - v * v / a / 2;\n                ans += distanceLeftTillSign / v;\n                speedAtSign = v;\n            }\n        } else {\n            if (maxSpeedBySign <= w) {\n                ans += Math.sqrt(2 * d / a);\n                speedAtSign = maxSpeedBySign;\n            } else {\n                double S = d / 2 - w * w / 4 / a;\n                double X = d - S;\n                double speed = Math.sqrt(2 * a * X);\n                if (speed <= v) {\n                    ans += Math.sqrt(2 * X / a);\n                    ans += (speed - w) / a;\n                    speedAtSign = w;\n                } else {\n                    double distanceToAc = v * v / a / 2;\n                    double distanceToDe = (v * v - w * w) / a / 2;\n                    ans += Math.sqrt(2 * distanceToAc / a);\n                    ans += (d - distanceToAc - distanceToDe) / v;\n                    ans += (v - w) / a;\n                }\n                speedAtSign = w;\n            }\n        }\n        l -= d;\n        double timeToGetMaxSpeed = (v - speedAtSign) / a;\n        double timeToReachEnd = (-2 * speedAtSign + Math.sqrt(4 * speedAtSign\n                * speedAtSign + 8 * a * l))\n                / 2 / a;\n        if (timeToGetMaxSpeed < timeToReachEnd) {\n            ans += timeToGetMaxSpeed;\n            double distanceCoveredToMaxSpeed = speedAtSign * timeToGetMaxSpeed\n                    + 0.5 * a * timeToGetMaxSpeed * timeToGetMaxSpeed;\n            l -= distanceCoveredToMaxSpeed;\n            ans += l / v;\n        } else {\n            ans += timeToReachEnd;\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic boolean LOCAL = System.getSecurityManager() == null;\n\tScanner sc = new Scanner(System.in);\n\t\n\tvoid run() {\n\t\tdouble a = sc.nextDouble(), v = sc.nextDouble();\n\t\tdouble L = sc.nextDouble(), d = sc.nextDouble(), w = sc.nextDouble();\n\t\tw = min(w, v);\n\t\tdouble t = 0;\n\t\tif (w * w / (2 * a) <= d) {\n\t\t\tif ((v * v + 2 * v * (v - w) - (v - w) * (v - w)) / (2 * a) <= d) {\n\t\t\t\tt = (2 * v - w) / a + (d - (v * v + 2 * v * (v - w) - (v - w) * (v - w)) / (2 * a)) / v;\n\t\t\t} else {\n\t\t\t\tdouble A = a, B = w, C = (w * w) / (2 * a) - d;\n\t\t\t\tt = w / a + (-B + sqrt(max(0, B * B - A * C))) / A * 2;\n\t\t\t}\n\t\t\tif ((2 * w * (v - w) + (v - w) * (v - w)) / (2 * a) <= L - d) {\n\t\t\t\tt += (v - w) / a + (L - d - (2 * w * (v - w) + (v - w) * (v - w)) / (2 * a)) / v;\n\t\t\t} else {\n\t\t\t\tdouble A = a, B = w, C = -2 * (L - d);\n\t\t\t\tt += (-B + sqrt(max(0, B * B - A * C))) / A;\n\t\t\t}\n\t\t} else if (v * v / (2 * a) <= L) {\n\t\t\tt = v / a + (L - (v * v / (2 * a))) / v;\n\t\t} else {\n\t\t\tt = sqrt(2 * L / a);\n\t\t}\n\t\tSystem.out.printf(\"%.10f%n\", t);\n\t}\n\t\n\tclass Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\teat(\"\");\n\t\t}\n\t\tvoid eat(String s) {\n\t\t\tst = new StringTokenizer(s);\n\t\t}\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\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\tboolean hasNext() {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\tString s = nextLine();\n\t\t\t\tif (s == null) return false;\n\t\t\t\teat(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tString next() {\n\t\t\thasNext();\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\t\n\tvoid debug(Object...os) {\n\t\tSystem.err.println(deepToString(os));\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tif (LOCAL) {\n\t\t\ttry {\n\t\t\t\tSystem.setIn(new FileInputStream(\"in.txt\"));\n\t\t\t} catch (Throwable e) {\n\t\t\t\tLOCAL = false;\n\t\t\t}\n\t\t}\n\t\tif (!LOCAL) {\n\t\t\ttry {\n\t\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\tSystem.setOut(new PrintStream(new BufferedOutputStream(System.out)));\n\t\t\t} catch (Throwable e) {\n\t\t\t}\n\t\t}\n\t\tnew Main().run();\n\t\tSystem.out.flush();\n\t}\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "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\tdouble f(int dist, double initSp, int a, int maxSp) {\n\t\tdouble distToReachMaxSpeed = 0.5 * (maxSp * maxSp - initSp * initSp)\n\t\t\t\t/ a;\n\n\t\tif (dist > distToReachMaxSpeed)\n\t\t\treturn 1d * (maxSp - initSp) / a + (dist - distToReachMaxSpeed)\n\t\t\t\t\t/ maxSp;\n\n\t\treturn (Math.sqrt(initSp * initSp + 2 * a * dist) - initSp) / a;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint a = nextInt();\n\t\tint maxSp = nextInt();\n\t\tint len = nextInt();\n\t\tint signX = nextInt();\n\t\tint signSp = nextInt();\n\n\t\tif (maxSp <= signSp) {\n\t\t\tout.printf(\"%.9f\\n\", f(len, 0, a, maxSp));\n\t\t\treturn;\n\t\t}\n\n\t\tdouble distToReachSignSp = 0.5 * signSp * signSp / a;\n\t\tif (distToReachSignSp >= signX) {\n\t\t\tdouble t = Math.sqrt(2d * signX / a);\n\t\t\tout.printf(\"%.9f\\n\", t + f(len - signX, t * a, a, maxSp));\n\t\t\treturn;\n\t\t}\n\n\t\tdouble distToReachMaxThenSign = 0.5\n\t\t\t\t* (maxSp * maxSp + maxSp * maxSp - signSp * signSp) / a;\n\t\tif (distToReachMaxThenSign <= signX) {\n\t\t\tdouble t = 1d * (2 * maxSp - signSp) / a\n\t\t\t\t\t+ (signX - distToReachMaxThenSign) / maxSp\n\t\t\t\t\t+ f(len - signX, signSp, a, maxSp);\n\t\t\tout.printf(\"%.9f\\n\", t);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdouble xSp = Math.sqrt(a * signX + signSp * signSp * 0.5);\n\t\tdouble xTime = (2 * xSp - signSp) / a;\n\t\tout.printf(\"%.9f\\n\", xTime + f(len - signX, signSp, a, maxSp));\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", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class d {\n\t\n\tdouble a, v, l, d, w;\n\n\tprivate void solve() throws Exception {\n\t\ta = nextInt(); v = nextInt(); l = nextInt(); d = nextInt(); w = nextInt();\n\t\tdouble ans;\n\t\tif (w >= v){\n\t\t\tans = fromSign(0, l);\n\t\t}\n\t\telse{\n\t\t\tdouble tToW = w / a;\n\t\t\tdouble dToW = tToW * tToW * a / 2.;\n\t\t\tif (dToW > d){\n\t\t\t\tdouble curT = Math.sqrt(d * 2. / a);\n\t\t\t\tans = curT;\n\t\t\t\tdouble curV = a * curT;\n\t\t\t\tans += fromSign(curV, l - d);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tdouble tToMax = v / a;\n\t\t\t\tdouble dToMax = tToMax * tToMax * a / 2.;\n\t\t\t\tdouble tFromMax = (v - w) / a;\n\t\t\t\tdouble dFromMax = tFromMax * v - tFromMax * tFromMax * a / 2.;\n\t\t\t\tif (dToMax + dFromMax <= d){\n\t\t\t\t\tans = tToMax + tFromMax + (d - dToMax - dFromMax) / v;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tdouble lo = w, hi = v;\n\t\t\t\t\tfor (int i = 0; i < 1000; ++i){\n\t\t\t\t\t\tdouble mi = (lo + hi) / 2.;\n\t\t\t\t\t\tdouble tTo = mi / a;\n\t\t\t\t\t\tdouble dTo = tTo * tTo * a / 2.;\n\t\t\t\t\t\tdouble tFrom = (mi - w) / a;\n\t\t\t\t\t\tdouble dFrom = tFrom * mi - tFrom * tFrom * a / 2.;\n\t\t\t\t\t\tif (dTo + dFrom <= d)\n\t\t\t\t\t\t\tlo = mi;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\thi = mi;\n\t\t\t\t\t}\n\t\t\t\t\tans = lo / a + (lo - w) / a;\n\t\t\t\t}\n\t\t\t\tans += fromSign(w, l - d);\n\t\t\t}\n\t\t}\n\t\tout.printf(\"%.8f\", ans);\n\t}\n\n\tprivate double fromSign(double curV, double d) {\n\t\tdouble tToMax = (v - curV) / a;\n\t\tdouble dToMax = tToMax * curV + tToMax * tToMax * a / 2.;\n\t\tif (dToMax <= d){\n\t\t\treturn tToMax + (d - dToMax) / v;\n\t\t}\n\t\telse{\n\t\t\tdouble lo = 0, hi = tToMax;\n\t\t\tfor (int i = 0; i < 1000; ++i){\n\t\t\t\tdouble mi = (lo + hi) / 2.;\n\t\t\t\tdouble curD = mi * curV + mi * mi * a / 2.;\n\t\t\t\tif (curD <= d)\n\t\t\t\t\tlo = mi;\n\t\t\t\telse\n\t\t\t\t\thi = mi;\n\t\t\t}\n\t\t\treturn lo;\n\t\t}\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 d(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 d() {\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 d(/*\"d\"*/).run();\n\t}\n\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Stack;\n\npublic class ProblemD {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tString[] data = s.readLine().split(\" \");\n\t\tdouble a = Double.valueOf(data[0]);\n\t\tdouble v = Double.valueOf(data[1]);\n\t\t\n\t\tString[] line = s.readLine().split(\" \");\n\t\tdouble l = Double.valueOf(line[0]);\n\t\tdouble d = Double.valueOf(line[1]);\n\t\tdouble w = Double.valueOf(line[2]);\n\n\t\tdouble ans = solve(a, v, l, d, w);\n\t\tout.println(String.format(\"%.07f\", ans));\n\t\t\n\t\tout.flush();\n\t}\n\n\tprivate static double solve(double a, double v, double l, double d, double w) {\n\t\tdouble maxSpeedAtD = Math.sqrt(2 * d / a) * a;\n\t\tif (v <= w || maxSpeedAtD <= w) {\n\t\t\t// okay. just go\n\t\t\tdouble maxSpeedAtL = Math.sqrt(2 * l / a) *  a;\n\t\t\tif (maxSpeedAtL <= v) {\n\t\t\t\treturn Math.sqrt(2 * l / a);\n\t\t\t} else {\n\t\t\t\tdouble timeToMaxSpeed = v / a;\n\t\t\t\tdouble leftDist = l - 0.5 * a * timeToMaxSpeed * timeToMaxSpeed;\n\t\t\t\treturn timeToMaxSpeed + leftDist / v;\n\t\t\t}\n\t\t}\n\t\t\n\t\tdouble time = 0.0d;\n\t\tdouble maxSpeedTime = Math.sqrt((d / a) + (w * w / (2 * a * a)));\n\t\tdouble maxSpeed = maxSpeedTime * a;\n\t\tif (maxSpeed <= v) {\n\t\t\ttime = maxSpeedTime + (a * maxSpeedTime - w) / a;\n\t\t} else {\n\t\t\tdouble vtime = (2 * a * d + w * w - 2 * v * v) / (2 * a * v);\n\t\t\ttime = v / a + vtime + (v - w) / a;\n\t\t}\n\t\t\n\t\t// after that, just go.\n\t\tdouble timeToV = (v - w) / a;\n\t\tdouble timeToVLen = timeToV * w + 0.5 * timeToV * (v - w);\n\t\tif (timeToVLen <= l - d) {\n\t\t\tdouble leftLen = l - d - timeToVLen;\n\t\t\ttime += timeToV + leftLen / v;\n\t\t} else {\n\t\t\ttime += (-w + Math.sqrt(w*w + a * (2 * l - 2 * d))) / a;\n\t\t}\n\t\treturn time;\n\t}\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "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\n\tvoid solve() throws IOException {\n\t\tdouble a = nextDouble();\n\t\tdouble v = nextDouble();\n\t\tdouble l = nextDouble();\n\t\tdouble d = nextDouble();\n\t\tdouble w = nextDouble();\n\t\tif (w > v) {\n\t\t\tw = v;\n\t\t}\n\t\tdouble ans1 = 0.;\n\t\tdouble v1;\n\t\t{\n\t\t\tdouble l_ = 0., r_ = 1e+9;\n\t\t\tfor (int it = 0; it < 100; ++it) {\n\t\t\t\tdouble mid = (l_ + r_) / 2.;\n\t\t\t\tdouble V = a * mid;\n\t\t\t\tdouble t1 = (V + w) / 2. / a;\n\t\t\t\tdouble t2 = mid - t1;\n\t\t\t\tt1 = Math.min(t1, v / a);\n\t\t\t\tt2 = Math.min(t2, (v - w) / a);\n\t\t\t\tif (V < w) {\n\t\t\t\t\tt1 = mid;\n\t\t\t\t\tt2 = 0.;\n\t\t\t\t}\n\t\t\t\tdouble dist = t1 * t1 * a / 2. + t2 * (w + t2 * a / 2.) + v * (mid - t1 - t2);\n\t\t\t\tif (dist < d) {\n\t\t\t\t\tl_ = mid;\n\t\t\t\t} else {\n\t\t\t\t\tr_ = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans1 = (l_ + r_) / 2.;\n\t\t\tv1 = Math.min(ans1 * a, w);\n\t\t}\n\t\tdouble ans2 = 0.;\n\t\t{\n\t\t\tdouble tSp = (v - v1)  / a;\n\t\t\tdouble l_ = 0., r_ = 1e+9;\n\t\t\tfor (int it = 0; it < 100; ++it) {\n\t\t\t\tdouble mid = (l_ + r_) / 2.;\n\t\t\t\tdouble dist = Math.min(tSp, mid) * (v1 + Math.min(tSp, mid) * a / 2.);\n\t\t\t\tdist += (mid - Math.min(tSp, mid)) * v;\n\t\t\t\tif (dist < l - d) {\n\t\t\t\t\tl_ = mid;\n\t\t\t\t} else {\n\t\t\t\t\tr_ = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans2 = (l_ + r_) / 2.;\n\t\t}\n\t\tout.println(ans1 + ans2);\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", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tvoid solve() {\n\t\tdouble a = sc.nextDouble();\n\t\tdouble v = sc.nextDouble();\n\t\tdouble l = sc.nextDouble();\n\t\tdouble d = sc.nextDouble();\n\t\tdouble w = sc.nextDouble();\n\n\t\tdouble res = calc(a, v, l, d, w);\n\t\tout.printf(\"%.10f\\n\", res);\n\n\t}\n\n\n\n\n\tdouble calc(double a, double v, double l, double d, double w) {\n\t\tif (v <= w) return getTime(a, 0, l, v);\n\n\t\t// \u8ddd\u96e2 d \u307e\u3067\u306b\u901f\u5ea6 w \u306b\u9054\u3057\u306a\u3044\u5834\u5408\n\t\tif ((w * w) >= d * 2 * a) return getTime(a, 0, l, v);\n\n\t\t// \u305d\u308c\u4ee5\u5916\u306f\u3001d \u306f\u901f\u5ea6w\u3067\u901a\u904e\n\t\tdouble ans = 0;\n\n\t\tdouble[] r1 = getReach(a, 0, v);\n\t\tdouble[] r2 = getReach(a, w, v);\n\n\t\t// d \u307e\u3067\u306b\u6700\u9ad8\u901f\u5ea6 v \u306b\u9054\u3059\u308b\u5834\u5408\n\t\tif (r1[1] + r2[1] <= d) {\n\t\t\tans += r1[0];\n\t\t\tans += r2[0];\n\t\t\tans += (d - r1[1] - r2[1]) / v;\n\t\t} else {\n\t\t\t// d \u307e\u3067\u306b\u6700\u9ad8\u901f\u5ea6\u306b\u9054\u3057\u306a\u3044\u5834\u5408\n\t\t\tdouble t0 = sqrt((2 * a * d + w * w) / (2 * a * a));\n\t\t\tans += t0 + (a * t0 - w) / a;\n\t\t}\n\n\t\tans += getTime(a, w, l - d, v);\n\t\treturn ans;\n\n\t}\n\n\t/**\n\t *  s \u304b\u3089 v \u306b\u9054\u3059\u308b\u307e\u3067\u306e\u6642\u9593\u3068\u3001\u305d\u306e\u9593\u306e\u8d70\u884c\u8ddd\u96e2\n\t */\n\tdouble[] getReach(double a, double s, double v) {\n\t\tdouble t = (v - s) / a;\n\t\tdouble dist = t * (v + s) / 2.0;\n\t\treturn new double[]{t, dist};\n\t}\n\n\n\t/**\n\t * \u521d\u901f s\u3001\u52a0\u901fa\u3001 \u6700\u9ad8\u901f\u5ea6 v \u3067\u8ddd\u96e2 l \u3092\u8d70\u308b\u306e\u306b\u304b\u304b\u308b\u6642\u9593\n\t */\n\tdouble getTime(double a, double s, double l, double v) {\n\t\tdouble t = (-s + sqrt(s * s + 2 * a * l)) / a;\n\t\tdouble t_ = (v - s) / a;\n\t\tif (t < t_) return t;\n\n\t\tdouble p = l - (s + v) * t_ / 2;\n\t\treturn t_ + (p / v);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tClass<?> here = new Object(){}.getClass().getEnclosingClass();\n\t\ttry {\n\t\t\tString packageName = here.getPackage().getName();\n\t\t\tpackageName = \"src/\" + packageName.replaceAll(\"\\\\.\", \"/\") + \"/\";\n\t\t\tSystem.setIn(new FileInputStream(packageName + \"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(packageName + \"output.txt\")));\n\t\t} catch (FileNotFoundException e) {\n\t\t} catch (NullPointerException e) {\n\t\t}\n\n\t\tObject o = Class.forName(here.getName()).newInstance();\n\t\to.getClass().getMethod(\"run\").invoke(o);\n\t}\n\n\tstatic void tr(Object... os) {\n\t\tSystem.err.println(deepToString(os));\n\t}\n\n\tMyScanner sc = null;\n\tPrintWriter out = null;\n\tpublic void run() throws Exception {\n\t\tsc = new MyScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tfor (;sc.hasNext();) {\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t}\n\t\tout.close();\n\t}\n\n\tvoid print(int[] a) {\n\t\tout.print(a[0]);\n\t\tfor (int i = 1; i < a.length; i++) out.print(\" \" + a[i]);\n\t\tout.println();\n\t}\n\n\tclass MyScanner {\n\t\tString line;\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic MyScanner(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t\ttokenizer = null;\n\t\t}\n\t\tpublic void eat() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tline = reader.readLine();\n\t\t\t\t\tif (line == null) {\n\t\t\t\t\t\ttokenizer = null;\n\t\t\t\t\t\treturn;\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\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic String next() {\n\t\t\teat();\n\t\t\treturn tokenizer.nextToken();\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\tpublic boolean hasNext() {\n\t\t\teat();\n\t\t\treturn (tokenizer != null && tokenizer.hasMoreElements());\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 int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    \n    static final double EPS = 1E-6;\n    double a, v, l, d, w, u;\n    \n    public void run() {\n        a = cin.nextDouble();\n        v = cin.nextDouble();\n        l = cin.nextDouble();\n        d = cin.nextDouble();\n        w = cin.nextDouble();\n        w = Math.min(w, v);\n        double s1 = v * v / (2 * a);\n        double s2 = w * w / (2 * a);\n        double s3 = s1 - s2;\n        \n        double cost = 0;\n        if (d < s2) {\n            cost += Math.sqrt(2 * d / a);\n            w = cost * a;\n        } else if (d < s1 + s3) {\n            u = Math.sqrt(d / a + w * w / (2 * a * a)) * a;\n            cost = u / a + (u - w) / a;\n        } else {\n            cost += v / a;\n            cost += (v - w) / a;\n            cost += (d - s3 - s1) / v;\n        }\n        d = l - d;\n        s3 = (v * v - w * w) / (2 * a);\n        if (d < s3) {\n            cost += (-w + Math.sqrt(w * w + 2 * a * d)) / a;\n        } else {\n            cost += (v - w) / a;\n            cost += (d - s3) / v;\n        }\n        out.println(cost);\n    }\n\n    public static void main(String[] args) throws IOException {\n        Main sloved = new Main();\n        sloved.run();\n        sloved.out.close();\n    }\n\n    Scanner cin = new Scanner(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic final class FollowTrafficRules {\n    private static double[] acce(double i, double a, double v) {\n        double[] r = new double[2];\n        r[0] = (v - i)/a;\n        r[1] = 1d/2d * a * pow(r[0], 2) + i * r[0];\n        return r;\n    }\n\n    private static double solve(double i, double a, double l) {\n        double e = sqrt(pow(i, 2) + 2d * a * l);\n        e = a > 0 ? e : -1d * e;\n        return (e - i)/a;\n    }\n\n    private static double time(double i, double a, double v, double l) {\n        double[] r = acce(i, a, v);\n        if (r[1] >= l) return solve(i, a, l);\n        return r[0] + (l - r[1])/v;\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        double a = sc.nextDouble();\n        double v = sc.nextDouble();\n        double l = sc.nextDouble();\n        double d = sc.nextDouble();\n        double w = sc.nextDouble();\n\n        double t = 0d;\n        if (v <= w) t = time(0, a, v, l);\n        else {\n            double[] r = acce(0, a, w);\n            if (r[1] >= d) t = time(0, a, v, l);\n            else {\n                t += r[0];\n                t += 2d * time(w, a, v, (d - r[1])/2d);\n                t += time(w, a, v, l - d);\n            }\n        }\n\n        System.out.println(t);\n    }\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class D implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new D()).start();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\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\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\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\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\tstatic final double EPS = 1e-9;\n\n\tstatic double qEq(double a, double b, double c) {\n\t\tdouble d = b * b - 4 * a * c;\n\t\tif (d < -EPS) {\n\t\t\treturn Double.NaN;\n\t\t}\n\t\treturn Math.max((-b + Math.sqrt(d)) / (2 * a), (-b - Math.sqrt(d))\n\t\t\t\t/ (2 * a));\n\t}\n\n\tstatic int compare(double a, double b) {\n\t\treturn Math.abs(a - b) < EPS ? 0 : Double.compare(a, b);\n\t}\n\n\tvoid solve() {\n\t\tdouble a = nextDouble();\n\t\tdouble v = nextDouble();\n\t\tdouble l = nextDouble();\n\t\tdouble d = nextDouble();\n\t\tdouble w = nextDouble();\n\t\tif (compare(w, v) >= 0) {\n\t\t\tdouble t1 = v / a;\n\t\t\tdouble d1 = a * t1 * t1 * .5;\n\t\t\tif (compare(d1, l) >= 0) {\n\t\t\t\tout.println(Math.sqrt(2 * l / a));\n\t\t\t} else {\n\t\t\t\tout.println(t1 + (l - d1) / v);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tdouble t1 = w / a;\n\t\tdouble d1 = a * t1 * t1 * .5;\n\t\tif (compare(d1, d) >= 0) {\n\t\t\tdouble t2 = v / a;\n\t\t\tdouble d2 = a * t2 * t2 * .5;\n\t\t\tif (compare(d2, l) >= 0) {\n\t\t\t\tout.println(Math.sqrt(2 * l / a));\n\t\t\t} else {\n\t\t\t\tout.println(t2 + (l - d2) / v);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tdouble left = d - d1;\n\t\tdouble timeToV = (v - w) / a;\n\t\tdouble distToV = a * timeToV * timeToV * .5 + w * timeToV;\n\t\t// System.err.println(t1 + \" \" + left + \" \" + timeToV + \" \" + distToV\n\t\t// + \" \" + d1);\n\t\tif (compare(distToV, left * .5) >= 0) {\n\t\t\tdouble t2 = qEq(a * .5, w, -left * .5);\n\t\t\t// System.err.println(t2 + \" \" + (a * t2 * t2 * .5 + w * t2));\n\t\t\tt2 += t1 + t2;\n\t\t\tif (compare(distToV, l - d) >= 0) {\n\t\t\t\tout.println(t2 + qEq(a * .5, w, d - l));\n\t\t\t} else {\n\t\t\t\tout.println(t2 + timeToV + (l - d - distToV) / v);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tdouble t2 = t1 + 2 * timeToV + (left - 2 * distToV) / v;\n\t\tif (compare(distToV, l - d) >= 0) {\n\t\t\tout.println(t2 + qEq(a * .5, w, d - l));\n\t\t} else {\n\t\t\tout.println(t2 + timeToV + (l - d - distToV) / v);\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\n\npublic class FollowTrafficRules\n{\n\tpublic Scanner in = new Scanner(System.in);\n\tpublic PrintStream out = System.out;\n\n\tpublic double len, d, w, vmax, a;\n\t\n\tDecimalFormat fmt = new DecimalFormat(\"0.0000000000000000\");\n\t\n\tpublic void main()\n\t{\n\t\ta = in.nextDouble();\n\t\tvmax = in.nextDouble();\n\t\tlen = in.nextDouble();\n\t\td = in.nextDouble();\n\t\tw = in.nextDouble();\n\t\t\n\t\tout.println(fmt.format(T()));\n\t}//end public void main()\n\t\n\tpublic double T()\n\t{\n\t\tdouble t, s;\n\t\t\n\t\tdouble t1, s1;\n\t\tt1 = vmax / a;\n\t\ts1 = vmax*vmax/(2.0*a);\n\t\t\n\t\tdouble t3, s3;\n\t\tt3 = w/a;\n\t\ts3 = w*w/(2.0*a);\n\t\t\t\t\n\t\tif(w >= vmax)\n\t\t{\n\t\t\tif(s1 < len)\n\t\t\t{\n\t\t\t\treturn t1 + (len - s1)/vmax;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\treturn Math.sqrt(2.0*len/a);\n\t\t\t}\t\t\t\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//w < vmax\n\t\t\t\n\t\t\tdouble t2, s2, v2;\n\t\t\tt2 = Math.sqrt(2.0*d/a);\n\t\t\tv2 = a*t2;\n\t\t\t\n\t\t\tdouble tx, vx;\n\t\t\tvx = Math.sqrt((2.0*a*d + w*w)/2.0);\n\t\t\ttx = vx / a;\t\n\t\t\t\n\t\t\t//vmax > w\n\n\t\t\t//v2 > vx > w\n\t\t\t\n\t\t\tif(v2 < w)\n\t\t\t{\n\t\t\t\tif(v2 > vmax)\n\t\t\t\t{\n\t\t\t\t\t//v2 > vmax > w\n\t\t\t\t\tif(vmax > vx)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn tx + (vx - w)/a + T2(w);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tdouble ty, sy;\n\t\t\t\t\t\tty = (vmax - w)/a;\n\t\t\t\t\t\tsy = ty * (vmax + w)/2.0;\n\t\t\t\t\t\treturn t1 + ty + (d - s1 - sy)/vmax + T2(w);\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\t//v2 < w, v2 <= vmax\n\t\t\t\t\treturn t2 + T2(v2);\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(v2 > vmax) //v2 >= w, vmax > w\n\t\t\t{\n\t\t\t\t//v2 > vmax > w\n\t\t\t\tif(vmax > vx)\n\t\t\t\t{\n\t\t\t\t\treturn tx + (vx - w)/a + T2(w);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tdouble ty, sy;\n\t\t\t\t\tty = (vmax - w)/a;\n\t\t\t\t\tsy = ty * (vmax + w)/2.0;\n\t\t\t\t\treturn t1 + ty + (d - s1 - sy)/vmax + T2(w);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse  //vmax >= v2 >= w\n\t\t\t{\n\t\t\t\t//out.println(\"Questionable.\");\n\t\t\t\t//return binary() + T2(w);\n\t\t\t\t\n\t\t\t\t//return  t3 + (d-s3)/w + T2(w);\n\n\t\t\t\treturn tx + (vx - w)/a + T2(w);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic double binary()\n\t{\n\t\tdouble low, high, t, s;\n\t\tlow = 0.0; high = vmax/a;\n\t\t\n\t\tfor(int c=0;c<50;++c)\n\t\t{\n\t\t\tt = (low+high)/2;\n\t\t\ts = (a*t*t)/2 + ((a*t - w)/a)*(a*t + w)/2.0;\n\t\t\t\n\t\t\tif(s > d) high = t;\n\t\t\telse low = t;\n\t\t}\n\t\tt = (low+high)/2;\n\t\treturn t + (a*t - w)/a;\n\t}\n\t\n/*\n\tpublic double T()\n\t{\n\t\tdouble t1, s1, tx, sx, vx, ty, vy, sz, tz;\n\t\tt1 = vmax / a;\n\t\ts1 = a*t1*t1 / 2.0;\n\t\t\n\t\tvx = Math.sqrt((2.0*a*d + w*w)/2.0);\n\t\ttx = vx / a;\n\t\t\n\t\tif(s1 < d)\n\t\t{\n\t\t\t//reaches vmax\n\t\t\tif(vx < vmax)\n\t\t\t{\n\t\t\t\t//stops at vx\n\t\t\t\treturn tx + (vx - w)/a + T2(w);\n\t\t\t}\n\t\t\telse //vx >= vmax\n\t\t\t{\n\t\t\t\t//stops at vmax\n\t\t\t\tif(w > vmax)\n\t\t\t\t{\n\t\t\t\t\treturn t1 + (d - s1)/vmax + T2(vmax);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ttz = (vmax - w)/a;\n\t\t\t\t\tsz = ((vmax + w)/2.0) * tz;\n\t\t\t\t\t\n\t\t\t\t\treturn t1 + (d-sz-s1)/vmax + tz + T2(w);\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse //s1 >= d\n\t\t{\n\t\t\t//never reaches vmax\n\t\t\tvy = Math.sqrt(2.0*d*a);\n\t\t\tty = vy / a;\n\t\t\tif(vx < vy)\n\t\t\t{\n\t\t\t\t//stops at vx\n\t\t\t\treturn tx + (vx - w)/a + T2(w);\n\t\t\t}\n\t\t\telse //vx >= vy\n\t\t\t{\n\t\t\t\tif(w < vy)\n\t\t\t\t{\n\t\t\t\t\treturn w/a + (d - w*w/(2.0*a))/w + T2(w);\n\t\t\t\t}\n\t\t\t\telse //w >= vy\n\t\t\t\t{\n\t\t\t\t\t//goes to vy, accelerate all the way\n\t\t\t\t\treturn ty + T2(vy);\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n*/\t\n\tpublic double T2(double v0)\n\t{\n\t\t//v0 <= min(w, vmax)\n\t\t\n\t\tdouble t1, s1;\n\t\tt1 = (vmax - v0)/a;\n\t\ts1 = ((vmax + v0)/2.0)*t1;\n\t\t\n\t\tif(s1 < len-d)\n\t\t{\n\t\t\t//reaches vmax\n\t\t\treturn t1 + (len-d-s1)/vmax;\n\t\t}\n\t\telse //s1 >= len - d\n\t\t{\n\t\t\t//does not reach vmax\n\t\t\treturn (-v0 + Math.sqrt(v0*v0 + 2*a*(len-d)))/a;\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\t(new FollowTrafficRules()).main();\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.math.BigInteger;\nimport java.util.HashMap;\nimport java.util.Locale;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Main implements Runnable {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry {\n\t\t\trun1();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tint nextInt(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn (int) st.nval;\n\t}\n\n\tdouble nextDouble(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.nval;\n\t}\n\n\tString nextLine(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.sval;\n\t}\n\n\tMap<String, BigInteger> map = new HashMap<String, BigInteger>();\n\n\tpublic void run1() throws IOException {\n\t\tLocale.setDefault(Locale.US);\n\t\t// long time = -System.currentTimeMillis();\n\t\t Scanner sc = new Scanner(new InputStreamReader(System.in));\n\t\t// BufferedReader br = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n//\t\tScanner sc = new Scanner(new File(\"input.txt\"));\n\t\t// BufferedReader br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t// PrintStream ps = System.out;// new PrintStream(new\n\t\t// File(\"output.txt\"));\n\t\t// gopa(br, ps);\n\t\tdouble a = sc.nextDouble();\n\t\tdouble vmax = sc.nextDouble();\n\t\tdouble l2 = sc.nextDouble();\n\t\tdouble l1 = sc.nextDouble();\n\t\tl2 -= l1;\n\t\tdouble boundv = sc.nextDouble();\n\t\tif (boundv >= vmax || boundv * boundv / a / 2 > l1) {\n\t\t\tSystem.out.print(get(0, a, vmax, l1 + l2));\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tdouble tmplen = vmax * vmax / a / 2 + (vmax + boundv) / 2\n\t\t\t\t* (vmax - boundv) / a;\n\t\tif (tmplen < l1) {\n\t\t\tSystem.out.print(get(boundv, a, vmax, l2) + vmax\n\t\t\t\t\t/ a + (vmax - boundv) / a + (l1 - tmplen) / vmax);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tdouble v = Math.sqrt(l1 * a + boundv * boundv / 2);\n\t\tSystem.out.print(get(boundv, a, vmax, l2) + v / a\n\t\t\t\t+ (v - boundv) / a);\n\t}\n\n\tdouble get(double v0, double a, double vmax, double l) {\n\t\tdouble tmplen = (vmax + v0) / 2 * (vmax - v0) / a;\n\t\t// System.out.println(tmplen);\n\t\tif (l >= tmplen) {\n\t\t\treturn (vmax - v0) / a + (l - tmplen) / vmax;\n\t\t}\n\t\treturn (-v0 + Math.sqrt(v0 * v0 + 2 * a * l)) / a;\n\t}\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemD_05 {\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 ProblemD_05().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    void solve() throws IOException{\n        double a = readDouble();\n        double v = readDouble();\n        double l = readDouble();\n        double d = readDouble();\n        double w = readDouble();\n        double t = 0;\n        double td = d > v * v / (2 * a)? v / a + (d - v * v / (2 * a)) / v: sqrt(2 *d / a);\n        if (w >= min(a * td, v)){\n            t += td;\n            w = min(a * td, v);\n        }else{\n            double v0 = sqrt(w * w / 2 + a * d);\n            if (v0 * v0 <= v * v){\n                t += (2 * v0 - w) / a;\n            }else{\n                t += (2 * v - w) / a;\n                double s2 = d - (2 * v * v - w * w) / (2 * a);\n                t += s2 / v;\n            }\n        }\n        double t1 = (sqrt(w * w + 2 * a * (l - d)) - w) / a;\n        if (t1 > (v - w) / a) t1 = (v - w) / a;\n        t += t1;\n        double s1 = w * t1 + a * t1 * t1 / 2;\n        double t2 = (l - d - s1) / v;\n        t += t2;\n        out.printf(Locale.US, \"%.12f\", t);\n    }\n    \n    static int[][] step8 = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};\n    \n    static int[][] stepKnight = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, -1}, {2, 1}};\n    \n    static long gcd(long a, long b){\n        if (a == 0) return b;\n        return gcd(b % a, a);\n    }\n    \n    static long lcm(long a, long b){\n        return a / gcd(a, b)*b;\n    }\n\n    static long[] gcdPlus(long a, long b){\n        long[] d = new long[3];\n        if (a == 0){\n            d[0] = b;\n            d[1] = 0;\n            d[2] = 1;\n        }else{\n            d = gcdPlus(b % a, a);\n            long r = d[1];\n            d[1] = d[2] - b/a*d[1];\n            d[2] = r;\n        }\n        return d;\n    }\n    \n    static long binpow(long a, int n){\n        if (n == 0) return 1;\n        if ((n & 1) == 0){\n            long b = binpow(a, n/2);\n            return b*b;\n        }else return binpow(a, n - 1)*a;\n    }\n    \n    static long binpowmod(long a, int n, long m){\n        if (m == 1) return 0;\n        if (n == 0) return 1;\n        if ((n & 1) == 0){\n            long b = binpowmod(a, n/2, m);\n            return (b*b) % m;\n        }else return binpowmod(a, n - 1, m)*a % m;\n    }\n    \n    static long phi(long n){\n        int[] p = Sieve((int)ceil(sqrt(n)) + 2);\n        long phi = 1;\n        for (int i = 0; i < p.length; i++){\n            long x = 1;\n            while (n % p[i] == 0){\n                n /= p[i];\n                x *= p[i];\n            }\n            phi *= x - x/p[i];\n        }\n        if (n != 1) phi *= n - 1;\n        return phi;\n    }\n    \n    static long f(long n, int x, int k){ //\u041a\u043e\u043b-\u0432\u043e \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b (\u0432\u043a\u043b\u044e\u0447\u0430\u044f 0), \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0432 \u0441\u0435\u0431\u0435 \u0446\u0438\u0444\u0440\u044b \u043e\u0442 0 \u0434\u043e k-1\n        if (n == 0) return 1;\n        long b = binpow(10, x - 1);\n        long c = n / b;\n        return (c < k? c: k)*binpow(k, x - 1) + (c < k? 1: 0)*f(n % b, x - 1, k);\n    }\n    \n    static long fib(int n){\n        if (n == 0) return 0;\n        if ((n & 1) == 0){\n            long f1 = fib(n/2 - 1);\n            long f2 = fib(n/2 + 1);\n            return f2*f2 - f1*f1;\n        }else{\n            long f1 = fib(n/2);\n            long f2 = fib(n/2 + 1);\n            return f1*f1 + f2*f2;\n        }\n    }\n    \n    static BigInteger BigFib(int n){\n        if (n == 0) return BigInteger.ZERO;\n        if ((n & 1) == 0){\n            BigInteger f1 = BigFib(n/2 - 1);\n            f1 = f1.multiply(f1);\n            BigInteger f2 = BigFib(n/2 + 1);\n            f2 = f2.multiply(f2);\n            return f2.subtract(f1);\n        }else{\n            BigInteger f1 = BigFib(n/2);\n            f1 = f1.multiply(f1);\n            BigInteger f2 = BigFib(n/2 + 1);\n            f2 = f2.multiply(f2);\n            return f2.add(f1);\n        }\n    }\n    \n    static public class PointD{\n        \n        double x, y;\n        \n        public PointD(double x, double y){\n            this.x = x;\n            this.y = y;\n        }\n    }\n    \n    static double d(Point p1, Point p2){\n        return sqrt(d2(p1, p2));\n    }\n    \n    static public double d(PointD p1, PointD p2){\n        return sqrt(d2(p1, p2));\n    }\n    \n    static double d2(Point p1, Point p2){\n        return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);\n    }\n    \n    static public double d2(PointD p1, PointD p2){\n        return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);\n    }\n    \n    static boolean IsProbablyPrime(long n){\n        if (n == 1) return false;\n        if ((n & 1) == 0) return false;\n        for (int j = 3; j < sqrt(n) + 1; j += 2){\n            if (n % j == 0) return false;\n        }\n        return true;\n    }\n\n    static int[] Sieve(int n){\n        boolean[] b = new boolean[n+1];\n        Arrays.fill(b, true);\n        b[0] = false;\n        b[1] = false;\n        long nLong = n;\n        int j=0;\n        for (int i = 1; i <= n; i++) {\n            if (b[i]){\n                j++;\n                if (((long)i)*i <= nLong) {\n                    for (int k = i*i; k <= n; k += i) {\n                        b[k] = false;\n                    }\n                }\n            }\n        }\n        int[] p = new int[j];\n        Arrays.fill(p, 0);\n        j=0;\n        for (int i = 2; i <= n; i++) {\n            if (b[i]){\n                p[j]=i;\n                j++;\n            }\n        }\n        return p;\n    }\n    \n    static int[][] Palindromes(String s){\n        char[] c = s.toCharArray();\n        int n = c.length;\n        int[][] d = new int[2][n];\n        int l = 0, r = -1;\n        for (int i = 0; i < n; i++){\n            int j = (i > r? 0: min(d[0][l+r-i+1], r-i+1)) + 1;\n            for (; i - j >= 0 && i + j - 1< n && c[i-j] == c[i+j-1]; j++);\n            d[0][i] = --j;\n            if (i + d[0][i] - 1 > r){\n                r = i + d[0][i] - 1;\n                l = i - d[0][i];\n            }\n        }\n        l = 0;\n        r = -1;\n        for (int i = 0; i < n; i++){\n            int j = (i > r? 0: min(d[1][l+r-i], r-i)) + 1;\n            for (; i - j >= 0 && i + j < n && c[i-j] == c[i+j]; j++);\n            d[1][i] = --j;\n            if (i + d[1][i] > r){\n                r = i + d[1][i];\n                l = i - d[1][i];\n            }\n        }\n        return d;\n    }\n    \n    static public class Permutation {\n        \n        int[] a;\n        int n;\n        \n        public Permutation(int n){\n            this.n=n;\n            a=new int[n];\n            for (int i=0; i<n; i++){\n                a[i]=i;\n            }\n        }\n        \n        public boolean nextPermutation(){ //\u041f\u0438\u0448\u0435\u0442\u0441\u044f \u0441 do{}while(nextPermutation(a));\n            int i=n-1;\n            for (i=n-2; i>=0; i--){\n                if (a[i]<a[i+1]){\n                    break;\n                }\n            }\n            if (i==-1){\n                return false;\n            }\n            int jMin=i+1;\n            for (int j=n-1; j>i; j--){\n                if (a[i]<a[j]&&a[j]<a[jMin]){\n                    jMin=j;\n                }\n            }\n            swap(i, jMin);\n            for (int j=1; j<=(n-i)/2; j++){\n                swap(i+j, n-j);\n            }\n            return true;\n        }\n        \n        \n        public int get(int i){\n            return a[i];\n        }\n        \n        void swap(int i, int j){\n            int r=a[i];\n            a[i]=a[j];\n            a[j]=r;\n        }\n    }\n    \n    static public class Fraction implements Comparable<Fraction>, Cloneable{\n        \n        public final Fraction FRACTION_ZERO = new Fraction();\n        public final Fraction FRACTION_ONE = new Fraction(1);\n        public long numerator = 0;\n        public long denominator = 1;\n        \n        public Fraction(){\n            numerator = 0;\n            denominator = 1;\n        }\n        \n        public Fraction(long numerator){\n            this.numerator = numerator;\n            denominator = 1;\n        }\n        \n        public Fraction(long numerator, long denominator){\n            this.numerator = numerator;\n            this.denominator = denominator;\n            Cancellation();\n        }\n        \n        public Fraction(double numerator, double denominator, int accuracy){\n            this.numerator = (long)(numerator*pow(10,accuracy));\n            this.denominator = (long)(denominator*pow(10,accuracy));\n            Cancellation();\n        }\n        \n        public Fraction(String s){\n            if (s.charAt(0) == '-'){\n                denominator = -1;\n                s = s.substring(1);\n            }\n            if (s.indexOf(\"/\") != -1){\n                denominator *= Integer.parseInt(s.substring(s.indexOf(\"/\") + 1));\n            }\n            if (s.indexOf(\" \") != -1){\n                numerator = Integer.parseInt(s.substring(0, s.indexOf(\" \"))) * abs(denominator) + Integer.parseInt(s.substring(s.indexOf(\" \") + 1, s.indexOf(\"/\")));\n            }else{\n                if (s.indexOf(\"/\") != -1){\n                    numerator = Integer.parseInt(s.substring(0, s.indexOf(\"/\")));\n                }else{\n                    numerator = Integer.parseInt(s)*abs(denominator);\n                }\n            }\n            this.Cancellation();\n        }\n        \n        void Cancellation(){\n            long g = gcd(abs(numerator), abs(denominator));\n            numerator /= g;\n            denominator /= g;\n            if (denominator < 0){\n                numerator *= -1;\n                denominator *= -1;\n            }\n        }\n        \n        public String toString(){\n            String s = \"\";\n            if (numerator == 0){\n                return \"0\";\n            }\n            if (numerator < 0){\n                s += \"-\";\n            }\n            if (abs(numerator) >= denominator){\n                s += Long.toString(abs(numerator) / denominator) + \" \";\n            }\n            if (abs(numerator) % denominator != 0){\n                s += Long.toString(abs(numerator) % denominator);\n            }else{\n                s = s.substring(0, s.length()-1);\n            }\n            if (denominator != 1){\n                s += \"/\" + Long.toString(denominator);\n            }\n            return s;\n        }\n        \n        public Fraction add(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.denominator = lcm(denominator, f.denominator);\n            fResult.numerator = numerator * fResult.denominator / denominator + f.numerator * fResult.denominator / f.denominator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        public Fraction subtract(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.denominator = lcm(denominator, f.denominator);\n            fResult.numerator = numerator * fResult.denominator / denominator - f.numerator * fResult.denominator / f.denominator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        public Fraction multiply(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.numerator = numerator * f.numerator;\n            fResult.denominator = denominator * f.denominator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        public Fraction divide(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.numerator = numerator * f.denominator;\n            fResult.denominator = denominator * f.numerator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        @Override\n        public int compareTo(Fraction f){\n            long g = gcd(denominator, f.denominator);\n            long res = numerator * (f.denominator / g) - f.numerator * (denominator / g);\n            if (res < 0){\n                return -1;\n            }\n            if (res > 0){\n                return 1;\n            }\n            return 0;\n        }\n        \n        public Fraction clone(){\n            Fraction fResult = new Fraction(numerator, denominator);\n            return fResult;\n        }\n        \n        public Fraction floor(){\n            Fraction fResult = this.clone();\n            fResult.numerator = (fResult.numerator / fResult.denominator) * fResult.denominator;\n            return fResult;\n        }\n        \n        public Fraction ceil(){\n            Fraction fResult = this.clone();\n            fResult.numerator = (fResult.numerator/fResult.denominator + 1) * fResult.denominator;\n            return fResult;\n        }\n        \n        public Fraction binpow(int n){\n            if (n==0) return FRACTION_ONE;\n            if ((n&1)==0){\n                Fraction f=this.binpow(n/2);\n                return f.multiply(f);\n            }else return binpow(n-1).multiply(this);\n        }\n    }\n    \n    static public class FenwickTree_1{  //One-dimensional array     \n        \n        int n;\n        long[] t;\n        \n        public FenwickTree_1(int n){\n            this.n = n;\n            t = new long[n];\n        }\n        \n        public long sum(int xl, int xr){\n            return sum(xr) - sum(xl);\n        }\n        \n        public long sum(int x){\n            long result = 0;\n            for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                result += t[i];\n            }\n            return result;\n        }\n        \n        public void update(int x, long delta){\n            for (int i = x; i < n; i = (i | (i + 1))){\n                t[i] += delta;\n            }\n        }\n    }\n    \n    static public class FenwickTree_2{  //Two-dimensional array\n        \n        int n, m;\n        long[][] t;\n        \n        public FenwickTree_2(int n, int m){\n            this.n = n;\n            this.m = m;\n            t = new long[n][m];\n        }\n        \n        public long sum(int xl, int yl, int xr, int yr){\n            return sum(xr, yr) - sum(xl - 1, yr) - sum(xr, yl - 1) + sum(xl - 1, yl - 1);\n        }\n        \n        public long sum(int x, int y){\n            long result = 0;\n            for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                for (int j = y; j >= 0; j = (j & (j + 1)) - 1){\n                    result+=t[i][j];\n                }\n            }\n            return result;\n        }\n        \n        public void update(int x, int y, long delta){\n            for (int i = x; i < n; i = (i | (i + 1))){\n                for (int j = y; j < m; j = (j | (j + 1))){\n                    t[i][j] += delta;\n                }\n            }\n        }\n    }\n    \n    static public class FenwickTree_3{  //Three-dimensional array\n        \n        int n, m, l;\n        long[][][] t;\n        \n        public FenwickTree_3(int n, int m, int l){\n            this.n = n;\n            this.m = m;\n            this.l = l;\n            t = new long[n][m][l];\n        }\n        \n        public long sum(int xl, int yl, int zl, int xr, int yr, int zr){\n            return sum(xr, yr, zr) - sum(xl - 1, yr, zr)\n            + sum(xl - 1, yr, zl - 1) - sum(xr, yr, zl - 1)\n            - sum(xr, yl - 1, zr) + sum(xl - 1, yl - 1, zr)\n            - sum(xl - 1, yl - 1, zl - 1) + sum(xr, yl - 1, zl - 1);\n        }\n        \n        public long sum(int x, int y, int z){\n            long result = 0;\n            for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                for (int j = y; j >= 0; j = (j & (j + 1)) - 1){\n                    for (int k = z; k >= 0; k = (k & (k + 1)) - 1){\n                        result += t[i][j][k];\n                    }\n                }\n            }\n            return result;\n        }\n        \n        public void update(int x, int y, int z, long delta){\n            for (int i = x; i < n; i = (i | (i + 1))){\n                for (int j = y; j < n; j = (j | (j + 1))){\n                    for (int k = z; k < n; k = (k | (k + 1))){\n                        t[i][j][k] += delta;\n                    }\n                }\n            }\n        }\n    }\n}\n\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class D\n{\n\n    public static void main(String[] args)\n    {\n        new D();\n    }\n    \n    D()\n    {\n        Scanner in = new Scanner(System.in);\n        double a = in.nextDouble();\n        double v = in.nextDouble();\n        double l = in.nextDouble();\n        double d = in.nextDouble();\n        double w = in.nextDouble();\n        \n        if (w>v) w=v;\n        \n        double dx=(v*v-w*w)/(2*a);\n        double d0=(w*w)/(2*a);\n        \n        double t=0;\n        if (d0>d) // doesn't make it to speed w before reaching d\n        {\n            if (d0>=l) // never gets to speed w\n            {\n                t=Math.sqrt(2*a*l)/a;\n            }\n            else\n            {\n                t=w/a;\n                if (d0+dx>=l) // never gets to speed v\n                {\n                    t+=(-w+Math.sqrt(w*w+2*a*(l-d0)))/a;\n                }\n                else // makes it to speed v\n                {\n                    t+=(v-w)/a;\n                    t+=(l-(d0+dx))/v;\n                }\n            }\n        }\n        else // makes it to speed w before reachig d\n        {\n            t=w/a; // get up to speed w \n            \n            // get time after reaching d\n            if (d+dx>l) // never makes it back to v after reaching d\n            {\n                t+=(-w+Math.sqrt(w*w+2*a*(l-d)))/a;\n            }\n            else // makes it to speed v after reaching d\n            {\n                t+=(v-w)/a;\n                t+=(l-(d+dx))/v;\n            }\n            \n            // handle getting to d\n            if (d0+2*dx>d) // can't get to v before reaching d\n            {\n                double half=(d-d0)/2;\n                t+=2*(-w+Math.sqrt(w*w+2*a*half))/a;\n            }\n            else // can get to v before reaching d\n            {\n                t+=2*(v-w)/a;\n                t+=(d-2*dx-d0)/v;\n            }\n        }\n        \n        System.out.printf(\"%.12f%n\", t+1e-11);\n    }\n\n}\n", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class trafficerules {\n \t\n \tpublic static void main(String[] args) throws Exception {\n \t\tif (\"Satayev\".equals(System.getProperty(\"user.name\"))) {\n\t\t\tlong start = System.nanoTime();\n\t\t\tnew trafficerules().solve(new FileInputStream(\"input\"));\n\t\t\tSystem.err.printf(\"Time elapsed: %d ms.\\n\", (System.nanoTime()-start)/1000000);\n\t\t}\n\t\telse\n\t\t\tnew trafficerules().solve(System.in);\n \t}\n\n \tvoid solve(InputStream is) throws Exception {\n\t\tScanner in = new Scanner(is);\n\t\t\n\t\tdouble a = in.nextDouble(), maxv = in.nextDouble(), s = in.nextDouble(), d = in.nextDouble(), w = in.nextDouble();\n\t\t\n\t\tif (maxv < w)\n\t\t\tw = maxv;\n\t\t\n\t\tdouble t = 0;\n\t\t\n\t\t// v = at\n\t\t// s = att/2\n\t\tdouble t1 = w / a;\n\t\tdouble s1 = a*t1*t1/2;\n\t\tdouble v1 = w;\n\t\tif ( s1 < d ) {\n\t\t\tv1 = w;\n\t\t\t\n\t\t\tif (v1 >= maxv)\n\t\t\t\tt1 += (d-s1)/v1;\n\t\t\telse {\n\t\t\t\tdouble tt = (maxv - v1)/a;\n\t\t\t\tdouble ss = v1*tt+a*tt*tt/2;\n\t\t\t\tss *= 2;\n\t\t\t\tif (s1 + ss < d)\n\t\t\t\t\tt1 += tt*2 + (d-s1-ss)/maxv;\n\t\t\t\telse {\n\t\t\t\t\tss = (d-s1)/2;\n\t\t\t\t\t// ss = v1*t + a*t*t/2;\n\t\t\t\t\tdouble A = a/2;\n\t\t\t\t\tdouble B = v1;\n\t\t\t\t\tdouble C = -ss;\n\t\t\t\t\tdouble D = B*B - 4 * A * C;\n\t\t\t\t\ttt = (-B + Math.sqrt(D))/2/A;\n\t\t\t\t\tt1 += tt*2;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\ts1 = d;\n\t\t}\n\t\tif (s1 > d) {\n\t\t\ts1 = d;\n\t\t\tt1 = Math.sqrt(2*s1/a);\n\t\t\tv1 = a * t1;\n\t\t}\n\t\t\n\t\tt += t1;\n\t\t\n\t\tdouble t2 = (maxv - v1) / a;\n\t\tdouble s2 = v1*t2 + a*t2*t2/2;\n\t\tdouble v2 = maxv;\n\t\tif (s1 + s2 < s) {\n\t\t\tv2 = maxv;\n\t\t\tt2 += (s-s1-s2)/v2;\n\t\t}\n\t\tif (s1 + s2 > s) {\n\t\t\ts -= s1;\n\t\t\t// v = v1 + a*t\n\t\t\t// s = v1*t + a*t*t/2\n\t\t\tdouble A = a/2;\n\t\t\tdouble B = v1;\n\t\t\tdouble C = -s;\n\t\t\tdouble D = B*B - 4*A*C;\n\t\t\t\n\t\t\tt2 = (-B + Math.sqrt(D))/2/A;\n\t\t}\n\t\t\n\t\tt += t2;\n\t\t\n\t\tSystem.out.println(t);\n \t}\n\n}", "complexity": "constant", "problem": "5_D. Follow Traffic Rules", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class AlexAndARhombus {\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\tSystem.out.println(n*n+(n-1)*(n-1));\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "1180_A. Alex and a Rhombus", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n    \tScanner s = new Scanner(System.in);\n    \tlong n = s.nextLong();\n    \tif(n >= 0)\n    \t\tSystem.out.println(n);\n    \telse {\n    \t\tString str = (\"\" + n).substring(1);\n    \t\tif(str.length() == 1)\n    \t\t\tSystem.out.println(\"-\" + str);\n    \t\telse {\n    \t\t\tlong one = Long.parseLong(str.substring(0, str.length()-1));\n    \t\t\tlong two = Long.parseLong(str.substring(0, str.length()-2) + str.substring(str.length()-1));\n    \t\t\tif(one > two)\n    \t\t\t\tSystem.out.println((two!=0?\"-\":\"\") + two);\n    \t\t\telse\n    \t\t\t\tSystem.out.println((one!=0?\"-\":\"\") + one);\n    \t\t}\n    \t}\n    }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main implements Runnable {\n\n    PrintWriter out;\n    Scanner in;\n\n    public static void main(String[] args) throws IOException {\n        new Thread(new Main()).start();\n    }\n\n    public void run() {\n        try {\n            out = new PrintWriter(new BufferedOutputStream(System.out));\n            in = new Scanner(System.in);\n            solve();\n            out.close();\n        } catch (IOException e) {\n            throw new IllegalStateException(e);\n        }\n    }\n\n    public void solve() throws IOException {\n        int n = in.nextInt();\n        if (n >= 0) {\n            out.println(n);\n        } else {\n            String s = String.valueOf(n);\n            int l = s.length();\n            String s1 = s.substring(0, l - 2);\n            if (s.charAt(l - 1) > s.charAt(l - 2)) {\n                s1 += s.charAt(l - 2);\n            } else {\n                s1 += s.charAt(l - 1);\n            }\n            out.println(Integer.parseInt(s1));\n        }\n    }\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n  \n  public static void main(String[] args) throws Exception {\n    Scanner scan = new Scanner(System.in);\n    int n = scan.nextInt();\n    int res = n;\n    String str = Integer.toString(n);\n    res = Math.max(res, Integer.parseInt(str.substring(0, str.length() - 1)));\n    res = Math.max(res, Integer.parseInt(str.substring(0, str.length() - 2) + str.substring(str.length() - 1)));\n    System.out.println(res);\n  }\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n    public class Main2 {\n        public static void main(String args[]){\n        \tScanner input = new Scanner(System.in);\n        \tString st = input.nextLine();\n        \tSystem.out.println(bank(st));\n        }\n        \n        public static int bank(String st){\n        \tStringBuilder sb = new StringBuilder(st);\n        \tint st1 = Integer.parseInt(sb.substring(0,st.length()-2)+sb.substring(st.length()-1,st.length()));\n        \tint st2 = Integer.parseInt(sb.substring(0,st.length()-1));\n        \tint st3 = Integer.parseInt(st);\n        \treturn Math.max(st3,Math.max(st1, st2));\n        }\n    }", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class ProbA {\n  int account;\n\n  void start(Scanner sc, PrintStream out) {\n    int ans = 0;\n    account = sc.nextInt();\n    int account1 = account / 10; \n    int account2 = (account - (account % 100)) / 10 + (account % 10); \n   \n    out.println(Math.max(account1, Math.max(account, account2)));\n  }\n\n  public static void main(String[] args)  {\n    Scanner sc = new Scanner(System.in);\n    PrintStream out = System.out;\n\n    new ProbA().start(sc, out);\n\n  }\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\t\n\tstatic class Scanner{\n\t\tBufferedReader br=null;\n\t\tStringTokenizer tk=null;\n\t\tpublic Scanner(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tpublic String next() throws IOException{\n\t\t\twhile(tk==null || !tk.hasMoreTokens())\n\t\t\t\ttk=new StringTokenizer(br.readLine());\n\t\t\treturn tk.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws NumberFormatException, IOException{\n\t\t\treturn Integer.valueOf(next());\n\t\t}\n\t\tpublic double nextDouble() throws NumberFormatException, IOException{\n\t\t\treturn Double.valueOf(next());\n\t\t}\n\t}\n\t\n\tpublic static void main(String args[]) throws NumberFormatException, IOException{\n\t\tScanner sc = new Scanner();\n\t\tint T = sc.nextInt();\n\t\tif ( T > 0)\n\t\t\tSystem.out.println(T);\n\t\telse{\n\t\t\tString cad = (T + \"\");\n\t\t\tint min = Math.min(cad.charAt(cad.length() - 1) - '0', cad.charAt(cad.length() - 2) - '0');\n\t\t\tif (min == 0 && cad.length() == 3)\n\t\t\t\tSystem.out.println(0);\n\t\t\telse\n\t\t\t\tSystem.out.println(cad.substring(0, cad.length() - 2) + \"\" + min);\n\t\t}\n\t}\n\n\t\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class A {\t\n\tBufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter out;\n    \n\tpublic void solve() throws IOException {\t\t\t\t\n\t\tint N = nextInt();\n\t\tif( N >= 0) {\n\t\t\tout.println(N);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint ans = N/10;\n\t\tint ans2 = N/100*10 + N%10;\n\t\tout.println( Math.max(ans, ans2));\n\t\t\n\t}\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\t\n\tpublic void run() {\n        try {\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        } 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}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class A {\n\n    public void processInput() throws IOException {\n        Scanner in = new Scanner(System.in);\n\n        long n = in.nextLong();\n        long res = go(n);\n\n        System.out.printf(Locale.ENGLISH, \"%d\\n\", res);\n\n        in.close();\n    }\n\n    public long go(long n) {\n\n        long res = n;\n\n        String str = String.valueOf(n);\n        \n        StringBuilder sb = new StringBuilder(str);\n        sb.deleteCharAt(str.length() - 1);\n        if (sb.length() > 0 && !sb.toString().equals(\"-\")) {\n            res = Math.max(res, Long.valueOf(sb.toString()));\n        }\n        \n        if (str.length() > 1) {\n            if (str.charAt(str.length() - 2) != '-') {\n                sb = new StringBuilder(str);\n                sb.deleteCharAt(str.length() - 2);\n                res = Math.max(res, Long.valueOf(sb.toString()));\n            }\n        }\n        \n        return res;\n    }\n\n    public static void main(String[] args) throws Exception {\n        A a = new A();\n        a.processInput();\n    }\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author N-AssassiN\n */\npublic class Main {\n\n    private static BufferedReader reader;\n    private static BufferedWriter out;\n    private static StringTokenizer tokenizer;\n    //private final static String filename = \"filename\";\n\n    private static void init(InputStream input, OutputStream output) {\n        reader = new BufferedReader(new InputStreamReader(input));\n        out = new BufferedWriter(new OutputStreamWriter(output));\n        //reader = new BufferedReader(new FileReader(filename + \".in\"));\n        //out = new BufferedWriter(new FileWriter(filename + \".out\"));\n        tokenizer = new StringTokenizer(\"\");\n    }\n\n    private static String nextLine() throws IOException {\n        return reader.readLine();\n    }\n\n    private static String next() throws IOException {\n        while (!tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(nextLine());\n        }\n        return tokenizer.nextToken();\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    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) throws IOException {\n        init(System.in, System.out);\n        int n = nextInt();\n        //long startTime = System.currentTimeMillis();\n        if (n > 0) {\n            out.write(n + \"\\n\");\n        } else {\n            String s = n + \"\";\n            String s2 = s.substring(0, s.length() - 1);\n            String s3 = s.substring(0, s.length() - 2) + s.charAt(s.length() - 1);\n            int a = Integer.parseInt(s2);\n            int b = Integer.parseInt(s3);\n            int ans = Math.max(a, b);\n            out.write(ans + \"\\n\");\n        }\n        //long runTime = System.currentTimeMillis() - startTime;\n        //out.write(runTime + \"\\n\");\n        out.flush();\n    }\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Main {\n\t\n\tStreamTokenizer in;\n\tint n, k;\n\t\n\tpublic void run() {\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tread();\n\t\tprint(solve());\n\t}\n\t\n\tvoid read() {\n\t\tn = nextInt();\n//\t\tk = nextInt();\n\t}\n\t\n\tint solve() {\n\t\tint result = n;\n\t\tif (result < 0) {\n\t\t\tint res1 = n / 10;\n\t\t\tint mod = n % 10;\n\t\t\t\n\t\t\tint res2 = res1 / 10 * 10 + mod;\n\t\t\tif (res1 > res2)\n\t\t\t\tresult = res1;\n\t\t\telse\n\t\t\t\tresult = res2;\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n\t\n\tvoid print(int result) {\n\t\tSystem.out.println(result);\n\t}\n\t\n\t\n\tpublic static void main(String[] Args) {\n\t\t\tnew Main().run();\n\t}\n\t\n\tpublic int nextInt() {\n\t\ttry {\n\t\t\tin.nextToken();\n\t\t}\n\t\tcatch (Exception e) {}\n\t\treturn (int)in.nval;\n\t}\n\t\n\tpublic String nextString() {\n\t\ttry {\n\t\t\tin.nextToken();\n\t\t}\n\t\tcatch (Exception e) {}\n\t\treturn in.sval;\n\t}\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\n\npublic class BankAccount {\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 in = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tString s = in.readLine();\n\t\tint n = Integer.parseInt(s);\n\n\t\tif (s.charAt(0) == '-')\n\t\t\tif (Integer.parseInt(s.substring(0, s.length()-1))>Integer.parseInt(s.substring(0, s.length()-2)+s.charAt(s.length()-1)))\n\t\t\t\ts=s.substring(0, s.length()-1);\n\t\t\telse\n\t\t\t\ts=s.substring(0, s.length()-2)+s.charAt(s.length()-1);\n\n\t\tSystem.out.println(Integer.parseInt(s));\n\t\tin.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tString s = nextToken();\n\t\tint res = Integer.parseInt(s);\n\t\t\n\t\tString s1 = s.substring(0, s.length() - 1);\n\t\tres = Math.max(res, Integer.parseInt(s1));\n\t\t\n\t\tString s2 = s.substring(0, s.length() - 2) + s.charAt(s.length() - 1);\n\t\tres = Math.max(res, Integer.parseInt(s2));\n\t\t\n\t\tout.println(res);\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}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "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\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        int n = nextInt();\n        int n1 = n/10;\n        int s = n % 10;\n        int n2 = n / 100 * 10+s;\n        System.out.println(Math.max(n, Math.max(n1, n2)));\n        pw.close();\n    }\n    private static int nextInt() throws IOException{\n        return Integer.parseInt(next());\n    }\n    \n    private static long nextLong() throws IOException{\n        return Long.parseLong(next());\n    }\n    \n    private static double nextDouble() throws IOException{\n        return Double.parseDouble(next());\n    }\n    \n    private static String next() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class TaskA implements Runnable {\n\t\n\t@Override\n\tpublic void run() {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint n = in.readInt();\n\t\tif (n > 0) {\n\t\t\tout.println(n);\n\t\t}\n\t\telse {\n\t\t\tint nn = -n;\n\t\t\tint x = nn/10;\n\t\t\tint lastDigit = nn%10;\n\t\t\tint y = 10*(x/10) + lastDigit;\n\t\t\tx = -x;\n\t\t\ty = -y;\n\t\t\tout.println(x > y ? x : y);\n\t\t}\n\t\tout.flush();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew TaskA().run();\n\t}\n\t\n\tprivate class InputReader {\n\t\t\n\t    public BufferedReader reader;\n\t    public StringTokenizer tokenizer;\n\n\t    public InputReader(InputStream stream) {\n\t        reader = new BufferedReader(new InputStreamReader(stream));\n\t        tokenizer = null;\n\t    }\n\n\t    public String next() {\n\t        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t            try {\n\t                tokenizer = new StringTokenizer(reader.readLine());\n\t            } catch (IOException e) {\n\t                throw new RuntimeException(e);\n\t            }\n\t        }\n\t        return tokenizer.nextToken();\n\t    }\n\t    \n\t    public int readInt() {\n\t    \treturn Integer.parseInt(next());\n\t    }\n\t    \n\t}\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int N = in.nextInt();\n        if(N >= 0)\n            out.println(N);\n        else {\n            N = Math.abs(N);\n            int v1 = - (N / 10);\n            int v2 = - (N / 100 * 10 + (N % 10));\n            out.println(Math.max(v1, v2));\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", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class CFA {\n\n\tprivate void work() throws IOException {\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\t\twhile (sc.hasNextInt()) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint a = n;\n\t\t\tint b = n / 10;\n\t\t\tint c;\n\t\t\tif (n < 0) {\n\t\t\t\tn = -n;\n\t\t\t\tc = -((n / 100) * 10 + n % 10);\n\t\t\t} else {\n\t\t\t\tc = (n / 100) * 10 + n % 10;\n\t\t\t}\n\t\t\tSystem.out.println(Math.max(a, Math.max(b, c)));\n\t\t}\n\t\tSystem.out.close();\n\t}\n\n\tprivate int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew CFA().work();\n\t}\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tAccount acnt = new Account();\n\t\tacnt.solve();\n\t\tacnt.print();\n\t}\n\n}\n\nclass Account {\n\t\n\tAccount() {\n\t\tScanner scr = new Scanner(System.in);\n\t\tn = scr.nextInt();\n\t}\n\t\n\tvoid solve() {\n\t\tif (n > 0) {\n\t\t\tans = n;\n\t\t}\n\t\telse {\n\t\t\tint nn = -n;\n\t\t\tint ans1 = nn/10;\n\t\t\tint ans2 = nn % 10 + (nn/100)*10;\n\t\t\tif (ans1 < ans2){\n\t\t\t\tans = -ans1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tans = -ans2;\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tvoid print(){\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tint ans;\n\tint n;\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.GregorianCalendar;\nimport java.util.Scanner;\n\n\npublic class ProblemB {\n\n    \n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        \n        int a = s.nextInt();\n        \n        int f1 = a/10;\n        \n        int b = a;\n        int last = a%10;\n        \n        b/=10;\n        b/=10;\n        b*=10;\n        b+=last;\n        \n        System.out.println(Math.max(a, Math.max(f1, b)));\n        \n        \n        \n    }\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/** UVA 10130 - SuperSale */\npublic class Main {\n    \n    \n    /** totally n products, max Weight is w */\n        \n    public static void main(String[] args) throws Exception {\n         Scanner sc = null;\n         PrintWriter pr = null;\n\n         pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n         sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n         //sc = new Scanner(new File(\"input.txt\"));\n            \n         long n = sc.nextInt();\n         if (n > 0) pr.println(n);\n         else {\n             long n1 = n / 10;\n             long n2 = n / 100 * 10  + n % 10;\n             if (n1 < n2) pr.println(n2);\n             else pr.println(n1);\n         }\n         \n         pr.close();\n         sc.close();\n    }\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Bank{\n\tpublic static void main(String[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tint in = reader.nextInt();\n\t\tint sign = (int)Math.signum(in);\n\t\t\n\t\tString str = Math.abs(in)+\"\";\n\t\tif(str.length() == 1){\n\t\t\tif(in < 0)\n\t\t\t\tSystem.out.println(0);\n\t\t\telse\n\t\t\t\tSystem.out.println(in);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint max = in;\n\t\tmax = Math.max(max, sign * Integer.parseInt(str.substring(0,str.length()-1)));\n\t\tmax = Math.max(max, sign * Integer.parseInt(str.substring(0,str.length()-2) + str.charAt(str.length()-1)));\n\t\tSystem.out.println(max);\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class first\n{\n\tint max(int a1,int a2,int a3)\n\t{\n\t\tint max=a1;\n\t\tif(a2>=max)\n\t\t\tmax=a2;\n\t\tif(a3>=max)\n\t\t\tmax = a3;\n\t\treturn max;\t\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tint num=0;\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tnum = sc.nextInt();\n\t\tint num2 = num/10;\n\t\tint num3 = num%10;\n\t\tint num4 = (num2/10)*10+num3;\n\t\tfirst fs = new first();\n\t\tint result = fs.max(num,num2,num4);\n\t\tSystem.out.println(result);\n\t}\n}\t\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.text.BreakIterator;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\npublic class palin {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner scan = new Scanner(System.in);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tif (n >= 0) {\n\t\t\tout.print(n);\n\t\t\treturn;\n\t\t}\n\t\tif (n / 10 >= (n / 100) * 10 + n % 10) {\n\t\t\tout.print(n / 10);\n\t\t\treturn;\n\t\t}\n\t\tout.print((n / 100) * 10 + n % 10);\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}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "\n/**\n *\n * @author saurabh\n */\npublic class myTemplate {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) throws Exception{\n        // TODO code application logic here\n       java.io.BufferedReader br = new java.io.BufferedReader(new \n                 java.io.InputStreamReader(System.in));\n       \n       int ch[],arr[];\n       int x,i,j,k,t,n=Integer.parseInt(br.readLine());\n        //System.out.println(n);\n        \n       if(n>0)\n            System.out.println(n);\n       else\n       {\n           //n= -n;\n           //n=-n;\n           x= n/100;\n           \n           x = x*10 + n%10;\n         //  System.out.println(x);\n           if(n/10 > x)\n               System.out.println(n/10);\n           else\n              System.out.println(x);\n           \n       }\n       \n    }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n  public static void main(String[] args){\n    FastScanner sc = new FastScanner();\n    int n = sc.nextInt();\n    String nStr = Integer.toString(n);\n\n    String nStr1 = nStr.substring(0, nStr.length() - 1);\n    String nStr2 = nStr.substring(0, nStr.length() - 2) + nStr.charAt(nStr.length() - 1);\n\n    int result = Math.max(n, Integer.parseInt(nStr1));\n    result = Math.max(result, Integer.parseInt(nStr2));\n    System.out.println(result);\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()) try {\n        st = new StringTokenizer(br.readLine());\n      } catch (IOException e) {\n        e.printStackTrace();\n      }\n      return st.nextToken();\n    }\n\n    int nextInt() {\n      return Integer.parseInt(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", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Main {\n  public static void main(String args[]) throws IOException {\n    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n    String line = stdin.readLine();\n    int n = Integer.parseInt(line);\n    \n    if (n >= 0) {\n      System.out.println(n);\n    } else if (n > -10) {\n      System.out.println(0);\n    } else {\n      String sa = line.substring(0, line.length() - 1);\n      int a = Integer.parseInt(sa);\n      String sb = line.substring(0, line.length() - 2) + line.charAt(line.length() - 1);\n      int b = Integer.parseInt(sb);\n      System.out.println(Math.max(a, b));\n    }\n  }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class C186D2A {\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\tint n = in.nextInt();\n\t\tif (n >= 0) {\n\t\t\tout.println(Math.abs(n));\n\t\t} else {\n\t\t\tout.println(Math.max(n/10, (n/100)*10 + n%10));\n\t\t}\n\t\tout.flush();\n\t}\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class A {\n\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 n = nextInt();\n    \tif(n >= 0) out.println(n);\n    \telse {\n    \t\tn = -n;\n    \t\tint a = n % 10; int m = n/10;\n    \t\tint b = m % 10;\n    \t\tif(a >= b) {\n    \t\t\tif(m == 0) out.println(0);\n    \t\t\telse out.println(-m);\n    \t\t}\n    \t\telse {\n    \t\t\tm = (m-b)+a;\n    \t\t\tif(m == 0) out.println(0);\n    \t\t\telse out.println(-m);\n    \t\t}\n    \t}\n    \tout.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "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.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class A {\n    private static BufferedReader in;\n    private static StringTokenizer st;\n    private static PrintWriter out;\n    \n    public static void main(String[] args) throws NumberFormatException, IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        st = new StringTokenizer(\"\");\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int n = nextInt();\n        int max = n;\n        max = Math.max(max, n / 10);\n        max = Math.max(max, (n / 100) * 10 + n % 10);\n        System.out.println(max);\n    }\n    \n\n    static String next() throws IOException{\n        while(!st.hasMoreTokens()){\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n    static int nextInt() throws NumberFormatException, IOException{\n        return Integer.parseInt(next());\n    }\n    static long nextLong() throws NumberFormatException, IOException{\n        return Long.parseLong(next());\n    }\n    \n    static double nextDouble() throws NumberFormatException, IOException{\n        return Double.parseDouble(next());\n    }\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class problemB185 {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringBuffer sb=new StringBuffer();\n\t\tint n=Integer.parseInt(br.readLine());\n\t\t\n\t\tif(n<0){\n\t\t\tint temp=-n;\n\t\t\tint temp2=temp/10;\n\t\t\tint x=temp%10;\n\t\t\tint y=temp2%10;\n\t\t\tif(x>y){\n\t\t\t\ttemp=temp/10;\n\t\t\t}\n\t\t\telse{\n\t\t\t\ttemp=temp/10 -y +x;\n\t\t\t}\n\t\t\tn=-temp;\n\t\t\t\n\t\t\t\n\t\t}\n\t\tSystem.out.println(n);\n\t\t\n\t\t}\n\t\t\n\t\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\tpublic static void main(String[] args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tString s = n + \"\";\n\t\tif (n >= 0)\n\t\t\tSystem.out.println(n);\n\t\telse {\n\t\t\tint a = n, b = Integer.parseInt(s.substring(0, s.length() - 1)), c = Integer.parseInt(s.substring(0, s.length()-2)+s.charAt(s.length()-1));\n\t\t\tSystem.out.println(Math.max(a, Math.max(b,c)));\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n\n\tstatic Scanner scanner = new Scanner(System.in);\n\tstatic int s;\n\n\tpublic static void main(String[] args) {\n\t\ts = scanner.nextInt();\n\t\tif (s >= 0) {\n\t\t\tSystem.out.println(s);\n\t\t}\n\t\telse {\n\t\t\tif (s >= -10) {\n\t\t\t\tSystem.out.println(0);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint ss = -s;\n\t\t\t\tint a, b;\n\t\t\t\ta = ss % 10;\n\t\t\t\tb = (ss % 100) / 10;\n\t\t\t\tif (a > b) {\n\t\t\t\t\tss = ss / 10;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tss = (ss / 100) * 10 + a;\n\t\t\t\t}\n\t\t\t\tif (ss == 0) {\n\t\t\t\t\tSystem.out.println(0);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tSystem.out.println(\"-\" + ss);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\nimport static java.lang.Integer.*;\nimport static java.lang.Math.*;\npublic class A {\n\tpublic static void main(String[] args) throws Throwable{\n\t\tBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\t\tString ln=in.readLine().trim();\n\t\tSystem.out.println(max(parseInt(ln),max(parseInt(ln.substring(0,ln.length()-1)),parseInt(ln.substring(0, ln.length()-2)+ln.substring(ln.length()-1)))));\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedInputStream;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(new BufferedInputStream(System.in));\n\t\tPrintStream out=System.out;\n\t\tint n=in.nextInt();\n\t\tif (n>=0) out.println(n);\n\t\telse out.println(Math.max(-((-n)/10), -((-n)/100*10+(-n)%10)));\n\t\tout.close();\n\t\tin.close();\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n\tpublic static void main(String [] args ) {\n\t\ttry{\n\t\t\tString str;\t\t\t\n\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tBufferedOutputStream bos = new BufferedOutputStream(System.out);\n\t\t\tString eol = System.getProperty(\"line.separator\");\n\t\t\tbyte [] eolb = eol.getBytes();\n\t\t\tbyte[] spaceb= \" \".getBytes();\n\n\n\t\t\tstr  = br.readLine();\n\n\t\t\tint n = Integer.parseInt(str);\n\t\t\tint ans = 0;\n\t\t\tif(n>=0) {\n\t\t\t\tans = n;\n\t\t\t} else {\n\t\t\t\t if ( str.length()==2) {\n\t\t\t\t\tif(str.charAt(0)!='-') {\n\t\t\t\t\t\tint a  =Integer.parseInt(str.substring(0,1));\n\t\t\t\t\t\tint b = Integer.parseInt(str.substring(1,2));\n\t\t\t\t\t\tans = Math.max(a, b);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tans = Integer.parseInt(str.substring(1,2));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tString s1 = str.substring(0,str.length()-2).concat(str.substring(str.length()-2,str.length()-1));\n\t\t\t\t\tString s2 = str.substring(0,str.length()-2).concat(str.substring(str.length()-1,str.length()));\n\t\t\t\t\tint a = Integer.parseInt(s1);\n\t\t\t\t\tint b = Integer.parseInt(s2);\n\t\t\t\t\tans = Math.max(a, b);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbos.write(new Integer(ans).toString().getBytes());\n\t\t\tbos.write(eolb);\n\t\t\tbos.flush();\n\t\t}  catch(IOException ioe) {\n\t\t\tioe.printStackTrace();\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main{\n\n    void solve(){\n        Scanner sc = new Scanner(System.in);\n\n        int n = sc.nextInt();\n        int n1 = n/10;\n        int n2 = n/100*10 + n%10;\n\n        int ans = n;\n        ans = Math.max(ans, n1);\n        ans = Math.max(ans, n2);\n        System.out.println(ans);\n    }\n\n    public static void main(String[] args){\n        new Main().solve();\n    }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n    public static void main(String[] args) { \n        OutputStream outputStream = System.out;\n        PrintWriter out = new PrintWriter(outputStream);\n\n        Application solver = new Application();\n        solver.solve(System.in, out);\n\n        out.close();\n    }\n}\n\n\nclass Application {\n    int max(int a, int b) { return a > b ? a : b; }\n    public void solve(InputStream in, PrintWriter out) {\n        Scanner scanner = new Scanner(in);\n\n        int n = scanner.nextInt();\n        int n1 = n/10;\n        int n2 = (n/100)*10+(n%10);\n        int m = max(max(n1, n2), n);\n\n        out.println(m);\n    }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import static java.util.Arrays.deepToString;\n\nimport java.awt.datatransfer.StringSelection;\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    static void solve() throws IOException {\n        int n = nextInt();\n        if (n >= 0) {\n            System.out.println(n);\n        } else {\n            String string = String.valueOf(n);\n            int v1 = Integer.valueOf(string.substring(0, string.length() - 1));\n            int v2 = Integer.valueOf(string.substring(0, string.length() - 2)\n                    + string.charAt(string.length() - 1));\n            if (v1 >= v2) {\n                System.out.println(v1);\n            } else {\n                System.out.println(v2);\n            }\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        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: \"\n                + (System.currentTimeMillis() - systemTime));\n    }\n\n    static void printMemory() {\n        System.err.println(\"Memory consumed: \"\n                + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()\n                        .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}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "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 */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        int balance = in.nextInt();\n        if (balance >= 0) {\n            out.println(balance);\n            return;\n        }\n\n        balance = -balance;\n        int a = balance / 100;\n\n        int b = Math.min(balance % 10, (balance / 10) % 10);\n\n        balance = -(a * 10 + b);\n\n        out.println(balance);\n    }\n}\n\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Problem1 {\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 sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tif (n < 0) {\n\t\t\t\n\t\t\tint first = n / 10;\n\t\t\tint second = (n / 100)*10 + (n % 10);\n\t\t\tif (first > second)\n\t\t\t\tSystem.out.println(first);\n\t\t\telse\n\t\t\t\tSystem.out.println(second);\n\t\t} else {\n\t\t\tSystem.out.println(n);\n\t\t}\n\t}\n\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class j\n{\npublic static void main(String aa[])throws IOException\n{\nBufferedReader b=new BufferedReader(new InputStreamReader(System.in));\nint i=0,m=0,p=0,n=0,k=0,j=0;\nString s,r;\ns=b.readLine();\nr=s;\nn=Integer.parseInt(s);\ns=s.substring(0,s.length()-2);\ns+=r.charAt(r.length()-1);\nr=r.substring(0,r.length()-1);\nm=Integer.parseInt(s);\np=Integer.parseInt(r);\nSystem.out.print((long)Math.max(Math.max(m,n),p));\n}\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tString cur = sc.nextToken();\n\t\tint first = Integer.parseInt(cur);\n\t\tif(cur.length() > 1){\n\t\t\tString second = cur.substring(0,cur.length()-1);\n\t\t\tif(Character.isDigit(second.charAt(second.length()-1))){\n\t\t\t\tfirst = Math.max(first, Integer.parseInt(second));\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(cur.length() > 2){\n\t\t\tString third = cur.substring(0,cur.length()-2) + cur.charAt(cur.length()-1);\n\t\t\tif(Character.isDigit(cur.charAt(cur.length()-2))){\n\t\t\t\tfirst = Math.max(first, Integer.parseInt(third));\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(first);\n\t\tout.close();\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(String s) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\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", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n@SuppressWarnings(\"unused\")\npublic class A {\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\tTreeSet<Integer> set = new TreeSet<Integer>();\n\t\tset.add(n);\n\t\ttry {\n\t\t\tString s = Integer.toString(n);\n\t\t\ts = s.substring(0, s.length() - 1);\n\t\t\tset.add(Integer.parseInt(s));\n\t\t} catch (Exception e) {\n\t\t}\n\t\ttry {\n\t\t\tString s = Integer.toString(n);\n\t\t\ts = s.substring(0, s.length() - 2) + s.charAt(s.length() - 1);\n\t\t\tset.add(Integer.parseInt(s));\n\t\t} catch (Exception e) {\n\t\t}\n\t\tSystem.out.println(max(set));\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class Round313A {\n\tprivate static final int LOCAL_ENV = 0;\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\ttry {\n\t\t\tif (LOCAL_ENV == 1) {\n\t\t\t\tin = new Scanner(new File(\"input.txt\"));\n\t\t\t}\n\t\t} catch (FileNotFoundException e) {\n\t\t\tin = new Scanner(System.in);\n\t\t}\n\n\t\tlong n = in.nextLong();\n\n\t\tif (n >= -9) {\n\t\t\tSystem.out.println(n);\n\t\t} else {\n\t\t\tlong absN = Math.abs(n);\n\t\t\tlong m1 = -(absN / 10);\n\t\t\tlong last = absN % 10;\n\t\t\tlong m2 = -((absN / 100) * 10 + last);\n\t\t\tSystem.out.println(Math.max(m1, m2));\n\t\t}\n\t}\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString ns = sc.next();\n\t\tsc.close();\n\t\t\n\t\tint n1 = Integer.parseInt(ns);\n\t\tint n2 = Integer.parseInt(ns.substring(0, ns.length() - 1));\n\t\tint n3 = Integer.parseInt(ns.substring(0, ns.length() - 2) + ns.substring(ns.length() - 1));\n\t\t\n\t\tint max = n1;\n\t\tmax = (n2 > max) ? (n2) : (max);\n\t\tmax = (n3 > max) ? (n3) : (max);\n\t\t\n\t\tSystem.out.println(max);\t\t\n\t}\n}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "/**\n * Created with IntelliJ IDEA.\n * User: Venky\n */\n\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static void solve() throws IOException {\n        String str = br.readLine();\n        StringBuffer sb1 = new StringBuffer(str);\n        StringBuffer sb2 = new StringBuffer(str);\n        StringBuffer sb3 = new StringBuffer(str);\n        sb1.deleteCharAt(sb1.length()-1);\n        sb2.deleteCharAt(sb2.length()-2);\n        int n1 = Integer.parseInt(sb1.toString());\n        int n2 = Integer.parseInt(sb2.toString());\n        int n3 = Integer.parseInt(sb3.toString());\n        out.println(Math.max(n1, Math.max(n2, n3)));\n    }\n\n    static BufferedReader br;\n    static StringTokenizer st;\n    static PrintWriter out;\n\n    public static void main(String[] args) throws IOException {\n        InputStream input = System.in;\n        br = new BufferedReader(new InputStreamReader(input));\n        out = new PrintWriter(System.out);\n        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", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class ex1 {\n\t\n\tpublic static void main(String[] args)\t{\n\t\tint n,i,j;\n\t\tScanner scan = new Scanner(System.in);\n\t\tn = Integer.parseInt(scan.nextLine());\n\t\tif(n>=0)\n\t\t\tSystem.out.println(n);\n\t\telse if(n<0)\t{\n\t\t\tn=-1*n;\n\t\t\ti=n/10;\n\t\t\tj=(n/100)*10+n%10;\n\t\t\ti=-i;\n\t\t\tj=-j;\n\t\t\tif(i>=j)\n\t\t\t\tSystem.out.println(i);\n\t\t\telse\n\t\t\t\tSystem.out.println(j);\n\t\t}\n\t}\n\t\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\t\n\t\tint n = nextInt();\n\t\tString nn = Integer.toString(n);\n\t\tif(n >= 0){\n\t\t\tprintln(n);\n\t\t} else {\n\t\t\tprintln(Math.max(Integer.parseInt(nn.substring(0,nn.length() - 1)), Integer.parseInt(nn.substring(0, nn.length() - 2) + nn.charAt(nn.length() - 1))));\n\t\t}\n\t}\n\t\n\tprivate static PrintWriter out =  new PrintWriter(System.out);\n\tprivate static BufferedReader inB = new BufferedReader(new InputStreamReader(System.in));\t\n\tprivate static StreamTokenizer in = new StreamTokenizer(inB);\n\t\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\t\n} ", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "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 CF {\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        int n = in.nextInt();\n        if (n >= 0) {\n            out.println(n);\n        } else {\n            int res = n;\n            n = Math.abs(n);\n\n            String s = String.valueOf(Math.abs(n));\n            if (s.length() == 1) {\n                res = 0;\n            } else {\n                res = Math.max(-Integer.parseInt(s.substring(0, s.length() - 1)), res);\n                res = Math.max(-Integer.parseInt(s.substring(0, s.length() - 2) + s.charAt(s.length() - 1)), res);\n            }\n\n            out.println(res);\n        }\n\n        out.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));\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}", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "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 AndrewShmig\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n    public void solve(int testNumber, Scanner in, PrintWriter out) {\n        String n = in.nextLine();\n\n        int a = Integer.parseInt(n);\n        int b = Integer.parseInt(n.substring(0, n.length() - 1));\n        int c = Integer.parseInt(n.substring(0, n.length() - 2) + n.charAt(n.length() - 1));\n\n        out.println(Math.max(a, Math.max(b, c)));\n    }\n}\n\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskA  {\n    public void run() {\n        InputReader reader = new InputReader(System.in);\n        PrintWriter writer = new PrintWriter(System.out, true);\n\n        reader.nextLine();\n        String statement = reader.next();\n\n        if (!statement.startsWith(\"-\")) {\n            writer.println(statement);\n        } else {\n            try {\n                int statement1 = Integer.parseInt(statement.substring(0, statement.length() - 1));\n                int statement2 = Integer.parseInt(statement.substring(0, statement.length() - 2) + statement.charAt(statement.length() - 1));\n                writer.println(Math.max(statement1, statement2));\n            } catch (Exception e) {\n                writer.println(statement);\n            }\n        }\n\n        writer.close();\n    }\n    public static void main(String[] args) {\n        new TaskA().run();\n    }\n    private class InputReader {\n        BufferedReader reader;\n        StringTokenizer token;\n\n        private InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        private String next() {\n            return token.nextToken();\n        }\n\n        private int nextInt() {\n            return Integer.parseInt(this.next());\n        }\n\n        private double nextDouble() {\n            return Double.parseDouble(this.next());\n        }\n\n        private long nextLong() {\n            return Long.parseLong(this.next());\n        }\n\n        private String nextLine() {\n            String line = \"\";\n            try {\n                line = reader.readLine();\n                token = new StringTokenizer(line, \" \");\n\n            } catch(IOException e) {\n\n            }\n            return line;\n        }\n    }\n}\n", "complexity": "constant", "problem": "313_A. Ilya and Bank Account", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class MargariteBestPresent_1080B {\n\n\tprivate static int f(int x) {\n\t\treturn (x%2==0)?x/2:(x-1)/2-x;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n,r,l;\n\t\tn = sc.nextInt();\n\t\twhile(n-->0) {\n\t\t\tl = sc.nextInt();\n\t\t\tr = sc.nextInt();\n\n\t\t\tSystem.out.println(f(r)-f(l-1));\n\t\t}\n\t\tsc.close();\n\t}\n\n}\n", "complexity": "constant", "problem": "1080_B. Margarite and the best present", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class e {\n\npublic static class FastReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t//than using direct \n\n\tpublic FastReader() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString 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 (Exception r) {\n\t\t\t\tr.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());//converts string to integer\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() {\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\t\t} catch (Exception r) {\n\t\t\tr.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n}\nstatic ArrayList<String>list1=new ArrayList<String>();\nstatic void combine(String instr, StringBuffer outstr, int index,int k)\n{\n\tif(outstr.length()==k)\n\t{\n\t\tlist1.add(outstr.toString());return;\n\t}\n\tif(outstr.toString().length()==0)\n\toutstr.append(instr.charAt(index));\n    for (int i = 0; i < instr.length(); i++)\n    {\n        outstr.append(instr.charAt(i));\n       \n        combine(instr, outstr, i + 1,k);\n        outstr.deleteCharAt(outstr.length() - 1);\n    }\n   index++;\n} \nstatic ArrayList<ArrayList<Integer>>l=new ArrayList<>();\nstatic void comb(int n,int k,int ind,ArrayList<Integer>list)\n{\n\tif(k==0)\n\t{\n\t\tl.add(new ArrayList<>(list));\n\n\t\treturn;\n\t}\n\t\n\t\n\tfor(int i=ind;i<=n;i++)\n\t{\n\t\tlist.add(i);\n\t\tcomb(n,k-1,ind+1,list);\n\t\t\n\t\tlist.remove(list.size()-1);\n\t\t\n\t}\n\t\n\t\n\t\n\t\n\t\n\n}\n\n\npublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\tFastReader in=new FastReader();\n\tHashMap<Integer,Integer>map=new HashMap<Integer,Integer>();\n\n\tint n=in.nextInt();\n\tint r=in.nextInt();\n\t \n\tdouble theta=(double)360/(double)n;\n\t \n\tdouble b=1-((double)2/(double)(1-Math.cos((double)2*Math.PI/(double)n)));\n\tdouble x=Math.sqrt(1-b)-1;\n\tdouble ans=(double)r/(double)x;\n\tSystem.out.println(ans);\n\n\n\n\n\n\t}\n}\n", "complexity": "constant", "problem": "1100_C. NN and the Optical Illusion", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class e {\n\npublic static class FastReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t//than using direct \n\n\tpublic FastReader() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString 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 (Exception r) {\n\t\t\t\tr.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());//converts string to integer\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() {\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\t\t} catch (Exception r) {\n\t\t\tr.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n}\nstatic ArrayList<String>list1=new ArrayList<String>();\nstatic void combine(String instr, StringBuffer outstr, int index,int k)\n{\n\tif(outstr.length()==k)\n\t{\n\t\tlist1.add(outstr.toString());return;\n\t}\n\tif(outstr.toString().length()==0)\n\toutstr.append(instr.charAt(index));\n    for (int i = 0; i < instr.length(); i++)\n    {\n        outstr.append(instr.charAt(i));\n       \n        combine(instr, outstr, i + 1,k);\n        outstr.deleteCharAt(outstr.length() - 1);\n    }\n   index++;\n} \nstatic ArrayList<ArrayList<Integer>>l=new ArrayList<>();\nstatic void comb(int n,int k,int ind,ArrayList<Integer>list)\n{\n\tif(k==0)\n\t{\n\t\tl.add(new ArrayList<>(list));\n\n\t\treturn;\n\t}\n\t\n\t\n\tfor(int i=ind;i<=n;i++)\n\t{\n\t\tlist.add(i);\n\t\tcomb(n,k-1,ind+1,list);\n\t\t\n\t\tlist.remove(list.size()-1);\n\t\t\n\t}\n\t\n\t\n\t\n\t\n\t\n\n}\n\n\npublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\tFastReader in=new FastReader();\n\tHashMap<Integer,Integer>map=new HashMap<Integer,Integer>();\n\n\tint n=in.nextInt();\n\tint r=in.nextInt();\n\t \n\tdouble theta=(double)360/(double)n;\n\t \n\tdouble b=1-((double)2/(double)(1-Math.cos((double)2*Math.PI/(double)n)));\n\tdouble x=Math.sqrt(1-b)-1;\n\tdouble ans=(double)r/(double)x;\n\tSystem.out.println(ans);\n\n\n\n\n\n\t}\n}\n", "complexity": "constant", "problem": "1100_C. NN and the Optical Illusion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Codechef{\n\tstatic int max=Integer.MIN_VALUE;\n\tstatic int res=0;\n\tstatic int[] checkMax(int arr[],int j){\n             int sum=0;\n             int x=arr[j];\n        \t\twhile(x!=0){\n        \t\t        if(j+1==15){\n        \t\t        \tj=0;\n        \t\t        }else{\n        \t\t        \tarr[j+1]=arr[j+1]+1;\n        \t\t        }\n        \t\t        // if(arr[j+1]%2==0){\n        \t\t        // \tsum=sum+arr[j+1];\n        \t\t        // \tif(sum>=max){\n        \t\t        // \tmax=sum;\n        \t\t        // }\n        \t\t        // }\n\n        \t\t        \n        \t\t        x--;\n        \t\t        j++;\n        \t\t}\n        \t\t     return arr;\n\n\t}\n      \n\n    public static void main(String []args){\n       Scanner sc = new Scanner (System.in);\n    long a [] = new long [14];\n    long b [] = new long [14];\n    long p,q,r,s,max = 0;\n    for(int i = 0; i < 14; i++) a[i] = sc.nextInt();\n    for(int i = 0; i < 14; i++){\n      p = a[i]%14;\n      q = a[i]/14;\n      r = 0;\n      s = 0;\n      for(int j = 0; j < 14; j++) b[j] = a[j];\n      b[i] = 0;\n      int j = (i+1)%14;\n      for(; r < p; r++) {\n        b[j]++;\n        j=(j+1)%14;\n      }\n      for( j = 0; j < 14; j++) {\n        b[j] += q;\n        if(b[j] % 2 == 0) s+= b[j];\n      }\n      max = Math.max(max,s);\n    }\n    System.out.println(max);\n\n\n\n    }\n\n}", "complexity": "constant", "problem": "975_B. Mancala", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static String conv(String str) {\n\t\tboolean[] Arr = new boolean[26];\n\t\tfor (int i = 0; i < str.length(); i++) {\n\t\t\tArr[str.charAt(i) - 'a'] = true;\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < 26; i++) {\n\t\t\tif (Arr[i])\n\t\t\t\tsb.append((char) (i + 'a'));\n\t\t}\n\t\treturn \"\" + sb;\n\t}\n\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tScanner sc = new Scanner(System.in);\n\t\tHashSet<String> hs = new HashSet<String>();\n\t\tint[] Arr = new int[14];\n\t\tlong max = 0;\n\t\tfor (int i = 0; i < 14; i++) {\n\t\t\tArr[i] = sc.nextInt();\n\t\t}\n\n\t\tfor (int i = 0; i < 14; i++) {\n\t\t\tint[] arr = Arr.clone();\n\n\t\t\tlong sum = 0;\n\t\t\tint r = arr[i];\n\t\t\tarr[i] = 0;\n\t\t\tfor (int j = i + 1; j < arr.length && r > 0; j++) {\n\t\t\t\tarr[j]++;\n\t\t\t\tr--;\n\t\t\t}\n\t\t\tfor (int j = 0; j < arr.length; j++) {\n\t\t\t\tarr[j] +=( r / 14);\n\t\t\t\tif (j + 1 <= (r % 14)) {\n\t\t\t\t\tarr[j]++;\n\t\t\t\t}\n\t\t\t\tif (arr[j] % 2 == 0) {\n\t\t\t\t\tsum += arr[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, sum);\n\n\t\t}\n\t\tSystem.out.println(max);\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", "complexity": "constant", "problem": "975_B. Mancala", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n  public static void main(String[] args) {\n    Scanner in = new Scanner(System.in);\n    String inp = in.nextLine();\n    System.out.println(25);\n  }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * Created by Gantushig on 2/18/2016.\n */\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        long n = input.nextLong();\n        System.out.println(\"25\");\n    }\n\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "public class P1 {\n\t\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"25\");\n\t}\n\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\tString l[] = bf.readLine().split(\" \");\n\t\tSystem.out.println(25);\n\t}\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class a {\n\tpublic static void main(String[] args){\n\t\tScanner br = new Scanner(System.in);\n\t\tlong n = br.nextLong();\n\t\tSystem.out.println(\"25\");\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "\timport java.io.BufferedReader;\n\timport java.io.IOException;\n\timport java.io.InputStreamReader;\n\timport java.util.ArrayList;\n\timport java.util.Arrays;\n\timport java.util.Collections;\n\timport java.util.Comparator;\n\timport java.util.HashMap;\n\timport java.util.HashSet;\n\timport java.util.LinkedList;\n\timport java.util.List;\n\timport java.util.Map;\n\timport java.util.PriorityQueue;\n\timport java.util.Queue;\n\timport java.util.Random;\n\timport java.util.Set;\n\timport java.util.Stack;\n\t\n\tpublic class test {\n\t\tpublic static void main(String[] args) throws InterruptedException {\n\t\t\t//new careercup().run();\n\t\t\t//new CC().run();\n\t\t\t//System.out.println(Integer.MAX_VALUE);\n\t\t\ttry{\n\t\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tbr.readLine();\n\t\t\t\tSystem.out.println(25);\n\t\t\t\t\n\t\t\t}catch(IOException io){\n\t\t\t\tio.printStackTrace();\n\t\t\t}\n\t\t}\n\t\t\n\t\n\t}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\t\n\tvoid solve(Scanner in, PrintWriter out) {\n\t\tlong a = in.nextLong();\n\t\tout.println(25);\n\t}\n\tvoid run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry (\n\t\t\t\tScanner in = new Scanner(System.in);\n\t\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t) {\n\t\t\tsolve(in, out);\n\t\t  }\t\n\t}\n\t\n\tpublic static void main(String args[]) {\n\t\tnew Main().run();\n\t}\n\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.BufferedWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Alex\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskA solver = new TaskA();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskA {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            out.printLine(25);\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 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", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\n\n/**\n * Created by ww on 13.02.2016.\n */\npublic class rgb {\n\n\n    public static void main(String[] args) throws IOException {\n        System.out.print(25);\n        return ;\n\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "/*\n     * Code Author: Akshay Miterani\n     * DA-IICT\n     */\n    import java.io.*;\n    import java.util.*;\n    \n     \n    public class MainY {\n     \n    \tstatic double eps=(double)1e-6;\n    \tstatic long mod=(int)1e9+7;\n    \tstatic boolean f=true;\n    \tpublic static void main(String args[]){\n    \t\tInputReader in = new InputReader(System.in);\n    \t\tOutputStream outputStream = System.out;\n    \t\tPrintWriter out = new PrintWriter(outputStream);\n    \t\t//----------My Code Starts Here----------\n    \t\tlong n=in.nextLong();\n    \t\tif(n==1){\n    \t\t\tSystem.out.println(\"5\");\n    \t\t}\n    \t\telse{\n    \t\t\tSystem.out.println(\"25\");\n    \t\t}\n    \t\tout.close();\n    \t\t//---------------The End------------------\n    \t}\n    \t\n    \tstatic class Pair implements Comparable<Pair>{\n    \t\tint r1=-1;\n    \t\tint r2=-1;\n    \t\tint extra=0;\n\t\t\t@Override\n\t\t\tpublic int compareTo(Pair arg0) {\n\t\t\t\t// TODO Auto-generated method stub\n\t\t\t\treturn 0;\n\t\t\t}\n    \t}\n    \t\n    \tstatic class InputReader {\n    \t    public BufferedReader reader;\n    \t    public StringTokenizer tokenizer;\n     \n    \t    public InputReader(InputStream inputstream) {\n    \t      reader = new BufferedReader(new InputStreamReader(inputstream));\n    \t      tokenizer = null;\n    \t    }\n    \t    \n    \t    public String nextLine(){\n    \t    \tString fullLine=null;\n    \t    \twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n    \t            try {\n    \t              fullLine=reader.readLine();\n    \t            } catch (IOException e) {\n    \t              throw new RuntimeException(e);\n    \t            }\n    \t            return fullLine;\n    \t          }\n    \t          return fullLine;\n    \t    }\n    \t\tpublic String next() {\n    \t      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n    \t        try {\n    \t          tokenizer = new StringTokenizer(reader.readLine());\n    \t        } catch (IOException e) {\n    \t          throw new RuntimeException(e);\n    \t        }\n    \t      }\n    \t      return tokenizer.nextToken();\n    \t    }\n    \t\tpublic long nextLong() {\n    \t\t      return Long.parseLong(next());\n    \t\t    }\n    \t    public int nextInt() {\n    \t      return Integer.parseInt(next());\n    \t    }\n    \t  }\n    } ", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class Main {\n\n    private static void solve() throws IOException {\n        long n = nextLong();\n        out.println(25);\n    }\n\n    public static void main(String[] args) throws Exception {\n        File file = new File(\"System.in\");\n        InputStream input = System.in;\n        PrintStream output = System.out;\n        if (file.exists() && file.canRead()) {\n            input = new FileInputStream(file);\n            output = new PrintStream(\"System.out\");\n        }\n        br = new BufferedReader(new InputStreamReader(input));\n        out = new PrintWriter(output);\n        solve();\n        out.close();\n    }\n\n    private static BufferedReader br;\n    private static StringTokenizer st;\n    private static PrintWriter out;\n\n    private static boolean hasNextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            String line = br.readLine();\n            if (line == null) {\n                return false;\n            }\n            st = new StringTokenizer(line);\n        }\n        return true;\n    }\n\n    private static String nextToken() throws IOException {\n        return hasNextToken() ? st.nextToken() : null;\n    }\n\n    private static int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    private static long nextLong() throws IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    private static double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n}\n\n\n\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "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\n\npublic class A {\n\tstatic void solve(InputReader in, PrintWriter out) {\n\t\tlong n = in.nextLong();\n\t\tout.print(25);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\n\t\tsolve(in, out);\n\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 long nextDouble() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\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<ArrayList<Integer>> adjList;\n\n    public static void main(String[] args) throws Exception{\n        String s = br.readLine();\n        pw.print(25);\n        pw.print(\"\\n\");\n        pw.close();\n        br.close();\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\n/**\n * Feb 18, 2016 | 4:00:49 PM\n * <pre>\n * <u>Description</u>\n *\n * </pre>\n *\n * @author Essiennta Emmanuel (colourfulemmanuel@gmail.com)\n */\npublic class ProblemA{\n    \n    public static void main(String[] args){\n        Scanner sc = new Scanner(System.in);\n        sc.next();\n        System.out.println(25);\n        sc.close();\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "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 ATailouloute\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        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, QuickScanner in, PrintWriter out) {\n            long n = in.nextLong();\n            out.println(IntegerUtils.pow(5L, n, 100));\n        }\n\n    }\n\n    static class QuickScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        InputStream is;\n\n        public QuickScanner(InputStream stream) {\n            is = stream;\n            br = new BufferedReader(new InputStreamReader(stream), 32768);\n        }\n\n        String nextToken() {\n            while (st == null || !st.hasMoreElements()) {\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 long nextLong() {\n            return Long.parseLong(nextToken());\n        }\n\n    }\n\n    static class IntegerUtils {\n        public static long pow(long a, long base, long mod) {\n            if (base == 0) return 1;\n            if (base == 1) return a;\n            if ((base & 1) == 1)\n                return (a * pow(a, base - 1, mod)) % mod;\n            return pow((a * a) % mod, base / 2, mod);\n        }\n\n    }\n}\n\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class AgainTwentyfive {\n\tpublic static void main(String[] args)\n\t{\n\t\tSystem.out.println(\"25\");\n\t}\n}\n ", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\n;\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 s = new Scanner(System.in);\n\t\tlong n = s.nextLong();\n\t\tSystem.out.println(25);\n\t}\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.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        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, OutputWriter out) {\n            out.printLine(25);\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 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", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class LuxuriousHouses {\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tSystem.out.println(25);\n\t\t\n\n\t\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 boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class again_25 {\n\tpublic static void main(String ar[])throws IOException\n\t{\n\t\tlong n;\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tn=Long.parseLong(br.readLine());\n\t\tSystem.out.println(\"25\");\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class CF630_A {\n\n    public static void main(String[] args) {\n        try (Scanner s = new Scanner(System.in)) {\n            long n = s.nextLong();\n\n            System.out.println(\"25\");\n        }\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "\n/**\n *\n * @author Mohammad Hadi\n */\npublic class A630 {\n    public static void main(String[] args) {\n        System.out.println(25);\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Contests {\n\n\tpublic static void main(String[] args) {\n\t\tScanner clavier=new Scanner(System.in);\n\t\tlong a=clavier.nextLong();\n\t\tclavier.close();\n\t\tif(a==1)\n\t\t\tSystem.out.println(5);\n\t\telse\n\t\t\tSystem.out.println(25);\n\t}\n\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\n\npublic class Main {\n    FastScanner in;\n    PrintWriter out;\n\n    static final String FILE = \"\";\n\n    public void solve() {\n        out.print(25);\n    }\n\n    public void run() {\n        if (FILE.equals(\"\")) {\n            in = new FastScanner(System.in);\n            out = new PrintWriter(System.out);\n        } else {\n            try {\n                in = new FastScanner(new FileInputStream(FILE +\n                        \".in\"));\n                out = new PrintWriter(new FileOutputStream(FILE +\n                        \".out\"));\n            } catch (FileNotFoundException e) {\n                e.printStackTrace();\n            }\n        }\n        solve();\n        out.close();\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        public FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public String nextLine() {\n            st = null;\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n                return \"\";\n            }\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public float nextFloat() {\n            return Float.parseFloat(next());\n        }\n    }\n\n    class Pair<A extends Comparable<A>, B extends Comparable<B>>\n            implements Comparable<Pair<A, B>> {\n        public A a;\n        public B b;\n\n        public Pair(A a, B b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public int compareTo(Pair<A, B> o) {\n            if (o == null || o.getClass() != getClass())\n                return 1;\n            int cmp = a.compareTo(o.a);\n            if (cmp == 0)\n                return b.compareTo(o.b);\n            return cmp;\n        }\n\n        @Override\n        public boolean equals(Object o) {\n            if (this == o) return true;\n            if (o == null || getClass() != o.getClass()) return false;\n\n            Pair<?, ?> pair = (Pair<?, ?>) o;\n\n            if (a != null ? !a.equals(pair.a) : pair.a != null) return\n                    false;\n            return !(b != null ? !b.equals(pair.b) : pair.b != null);\n        }\n    }\n\n    class PairInt extends Pair<Integer, Integer> {\n        public PairInt(Integer u, Integer v) {\n            super(u, v);\n        }\n    }\n\n    class PairLong extends Pair<Long, Long> {\n        public PairLong(Long u, Long v) {\n            super(u, v);\n        }\n    }\n\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\nimport java.util.Set;\nimport java.util.Map.Entry;\n\nimport java.util.HashMap;\nimport java.util.Iterator;\n\npublic class test {\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        String num = input.nextLine();\n\n        System.out.println(\"25\");\n    }\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "\nimport java.io.PrintWriter;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\tpublic static void main(String args[]) {\n\t\tnew Main().run();\n\t}\n\t\n\tvoid run(){\n\t\tLocale.setDefault(Locale.US);\n\t\ttry(Scanner in=new Scanner(System.in);\n\t\t\tPrintWriter out=new PrintWriter(System.out)){\n\t\t\tsolve(in, out);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tprivate void solve(Scanner in, PrintWriter out) {\n\t\tString a=in.nextLine();\n\t\tout.println(\"25\");\n\t}\n\t\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\t\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tlong n = in.nextLong();\n\t\t\n\t\tSystem.out.println(25);\n\t}\n\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "\n\npublic class pregunta1 {\n\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"25\");\n\t}\n\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "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\npublic class A {\n\n\t\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(25);\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io. *;\nimport java.util. *;\n \npublic class Main  {\n\t\n\t\n\t\n    void solve(Scanner in, PrintWriter out) {\n        out.println(25);\n        \n    }\n    void run() {\n        Locale.setDefault(Locale.US);\n        try (\n                Scanner in = new Scanner(System.in);\n                PrintWriter out = new PrintWriter(System.out);\n        )\n        {\n            solve(in, out);\n        }\n         \n    }\n     \n    public static void main(String args[]) {\n     \n        new Main().run();\n    }\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main \n{\n\tstatic ArrayList<Integer> Unique(ArrayList<Integer> x)\n\t{\n\t\tTreeSet<Integer> tmp=new TreeSet<Integer>();\n\t\ttmp.addAll(x);\n\t\tx.clear();\n\t\tx.addAll(tmp);\n\t\treturn x;\n\t}\n\tpublic static void main(String[] args) \n\t{\n\t\tInputReader in = new InputReader();\n//\t\tScanner in=new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\twhile(in.hasNext())\n\t\t{\n\t\t\tlong n=in.nextLong();\n\t\t\tout.println(\"25\");\n\t\t}\n\t\tout.close();\n\t}\n}\n\nclass node\n{\n\tArrayList<Integer> v=new ArrayList<Integer>();\n\tnode(){}\n\tvoid push(Integer a)\n\t{\n\t\tv.add(a);\n\t}\n}\n\nclass InputReader \n{\n\tBufferedReader buf;\n\tStringTokenizer tok;\n\tInputReader() \n\t{\n\t\tbuf = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tboolean hasNext() \n\t{\n\t\twhile (tok == null || !tok.hasMoreElements()) \n\t\t{\n\t\t\ttry \n\t\t\t{\n\t\t\t\ttok = new StringTokenizer(buf.readLine());\n\t\t\t} \n\t\t\tcatch (Exception e) \n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tString next() \n\t{\n\t\tif (hasNext())\n\t\t\treturn tok.nextToken();\n\t\treturn null;\n\t}\n\n\tint nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() \n\t{\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() \n\t{\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tBigInteger nextBigInteger() \n\t{\n\t\treturn new BigInteger(next());\n\t}\n\n\tBigDecimal nextBigDecimal() \n\t{\n\t\treturn new BigDecimal(next());\n\t}\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class TwentyFive {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tSystem.out.println(25);\n\n\t}\n\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n  \npublic class Main {\n    Scanner in;\n    PrintWriter out;\n      \n    void solve() {\n    \tout.print(\"25\");\n    }\n\n      \n    void run() {\n\n            in = new Scanner(System.in);\n            out = new PrintWriter(System.out);      \n\n            solve();\n\n            out.close();\n    }\n  \n    public static void main(String[] args) {\n        new Main().run();\n          \n    }\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "public class Main {\n  public static void main(String[] args){\n    System.out.println(\"25\");\n  }\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "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\tpublic static void main(String args[]) {\n\t\tInputStream intputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(intputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskA {\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tout.println(25);\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 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\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\ttry {\n\t\t\t\treturn reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Double.parseDouble;\nimport static java.lang.String.*;\n    \npublic class Main {\n    \n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n                                            //(new FileReader(\"input.in\"));\n        StringBuilder out = new StringBuilder();\n        StringTokenizer tk;\n        \n        \n        long n = parseLong(in.readLine());\n        \n        System.out.println(\"25\");\n    }\n    \n}\n ", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * Created by mmaikovych on 18.02.16.\n */\npublic class EER_A {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        scanner.nextLine();\n        System.out.println(25);\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class ProA {\n\tstatic long n;\n\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tn=in.nextLong();\n\t\tSystem.out.println(25);\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "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\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\tBigInteger a = new BigInteger(next());\n\t\tSystem.out.println(BigInteger.valueOf(5).modPow(a, BigInteger.valueOf(100)));\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}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "\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 Madi\n */\npublic class A630 {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        \n        String s = sc.nextLine();\n        System.out.println(\"25\");\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "/*\n * The MIT License\n *\n * Copyright 2016 Mouad NACIRI <mouadnaciri1@gmail.com>.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author NACIRI Mouad <mouadnaciri1@gmail.com>\n * @version 1.5.1\n */\n\npublic class MainA {\n    /* VIP, DON'T TOUCH!! */\n    static StringTokenizer ST;\n    static BufferedReader IN;\n    static BufferedWriter OUT;\n    static {\n        IN = new BufferedReader(new InputStreamReader(System.in));\n        OUT = new BufferedWriter(new OutputStreamWriter(System.out));\n    }\n    \n    public static void main(String[] args) throws IOException {\n        \n        pl(\"25\");\n        cAll();\n    }\n    \n    //IO stuff...\n    static void ll() throws IOException { ST = new StringTokenizer(nlnt()); }\n    static void ll(String del) throws IOException { ST = new StringTokenizer(nlnt(), del); }\n    static void ll(String s, String del) throws IOException { ST = new StringTokenizer(s, del); }\n    static void ll(String s, char c) throws IOException { ST = new StringTokenizer(s); }\n    \n    static int tlen() { return ST.countTokens(); }\n    static boolean hn() { return ST.hasMoreTokens(); }\n    static String n() throws IOException { return ST.nextToken(); }\n    static String nln() throws IOException {\n        String l;\n        while((l = IN.readLine()) != null && l.trim().length() == 0) {}\n        return l;\n    }\n    static String nlnt() throws IOException {\n        String l;\n        while((l = IN.readLine()) != null && (l = l.trim()).length() == 0) {}\n        return l;\n    }\n    static boolean nbl() throws IOException { return Boolean.parseBoolean(ST.nextToken()); }\n    static byte nb() throws IOException { return Byte.parseByte(ST.nextToken()); }\n    static byte nb(int radix) throws IOException { return Byte.parseByte(ST.nextToken(), radix); }\n    static double nd() throws IOException { return Double.parseDouble(ST.nextToken()); }\n    static float nf() throws IOException { return Float.parseFloat(ST.nextToken()); }\n    static int ni() throws IOException { return Integer.parseInt(ST.nextToken()); }\n    static int ni(int radix) throws IOException { return Integer.parseInt(ST.nextToken(), radix); }\n    static long nl() throws IOException { return Long.parseLong(ST.nextToken()); }\n    static long nl(int radix) throws IOException { return Long.parseLong(ST.nextToken(), radix); }\n    static short ns() throws IOException { return Short.parseShort(ST.nextToken()); }\n    static short ns(int radix) throws IOException { return Short.parseShort(ST.nextToken(), radix); }\n    \n    static void p(String s) throws IOException { OUT.write(s); }\n    static void p(char c) throws IOException { OUT.write(c); }\n    static void p(char s[]) throws IOException { OUT.write(s); }\n    static void pl(String s) throws IOException { OUT.write(s); OUT.newLine(); }\n    static void pl(char c) throws IOException { OUT.write(c); OUT.newLine(); }\n    static void pl(char s[]) throws IOException { OUT.write(s); OUT.newLine(); }\n    static void pl() throws IOException { OUT.newLine(); }\n    static void cAll() throws IOException { IN.close(); OUT.close(); }\n    \n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport static java.lang.Math.*;\n\nimport java.lang.reflect.Array;\nimport java.util.*;\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    public void solve() {\n        out.println(25);\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", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\n\npublic class Main {\n    private StreamTokenizer in;\n    private PrintWriter out;\n\n\n    public static void main(String[] args) throws IOException {\n        //long time = System.currentTimeMillis();\n\n        new Main().run();\n        //time = System.currentTimeMillis() - time;\n        //System.out.println(time + \" ms\");\n\n    }\n\n\n    private void run() throws IOException {\n        //in = new StreamTokenizer(new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\"))));\n        //BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n        //out = new PrintWriter(new File(\"output.txt\"));\n\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n        out.print(25);\n\n\n        out.flush();\n\n    }\n\n\n    int nextInt() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\nimport java.math.BigInteger;\nimport java.util.Arrays;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Erasyl Abenov\n * \n * \n */\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n            try (PrintWriter out = new PrintWriter(outputStream)) {\n                TaskB solver = new TaskB();\n                solver.solve(1, in, out);\n            }\n    }\n}\nclass TaskB {\n    public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException{\n        String n = in.next();\n        out.println(25);\n    }\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 BigInteger nextBigInteger(){\n        return new BigInteger(next());\n    }\n    public long nextLong() {\n        return Long.parseLong(next());\n    }\n    public double nextDouble() {\n        return Double.parseDouble(next());\n    }\n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class a {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tlong n = input.nextLong();\n\tif(n == 1) out.println(5);\n\telse out.println(25);\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", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    public static void main(String[] args) throws Exception {\n\t// TODO Auto-generated method stub\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tPrintWriter out = new PrintWriter(System.out);\n\tString s = bf.readLine();\n\tout.println(25);\n\t\n\tout.flush();\n\tout.close();\n\n    }\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class TwentyFive {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tSystem.out.println(\"25\");\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\npublic class A {\n\t\n\tpublic static void main(String[] args) {\n\t\ttry (final Scanner sc = new Scanner(System.in)) {\n\t\t\tSystem.out.println(25);\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", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "/*\n * Code Author: Sanket Udgirkar.\n * DA-IICT\n */\nimport java.util.*;\nimport java.io.*;\npublic class Tester\n{\n\tpublic static long mod=(long)1e9+7;\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       System.out.println(\"25\");\n        \n        \n        //out.close();\n\t}   \n\t\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<Pair>\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              fullLine=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\tpublic String next() \n    \t\t{\n    \t      while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n    \t        try {\n    \t          tokenizer = new StringTokenizer(reader.readLine());\n    \t        } catch (IOException e) {\n    \t          throw new RuntimeException(e);\n    \t        }\n    \t      }\n    \t      return tokenizer.nextToken();\n    \t    }\n    \t\tpublic long nextLong() {\n    \t\t      return Long.parseLong(next());\n    \t\t    }\n    \t    public int nextInt() {\n    \t      return Integer.parseInt(next());\n    \t    }\n    \t  }\n \n}", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A630 {\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tSystem.out.println(25);\n\t}\n}\n", "complexity": "constant", "problem": "630_A. Again Twenty Five!", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n\npublic class HexadecimalTheorem {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tout.printf(\"%d %d %d%n\", 0, 0, n);\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: SONY\n * Date: 27.05.12\n * Time: 18:25\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class TaskA extends Thread {\n    public TaskA(String inputFileName, String outputFileName) {\n        try {\n            if (inputFileName != null) {\n                this.input = new BufferedReader(new FileReader(inputFileName));\n            } else {\n                this.input = new BufferedReader(new InputStreamReader(System.in));\n            }\n            if (outputFileName != null) {\n                this.output = new PrintWriter(outputFileName);\n            } else {\n                this.output = new PrintWriter(System.out);\n            }\n            this.setPriority(Thread.MAX_PRIORITY);\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            e.printStackTrace();\n            System.exit(666);\n        }\n    }\n\n    private void solve() throws Throwable {\n        long n = nextLong();\n        output.println(\"0 0 \" + 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.close();\n        }\n    }\n\n    public static void main(String... args) {\n        new TaskA(null, null).start();\n    }\n\n    private int nextInt() throws IOException {\n        return Integer.parseInt(next());\n    }\n\n    private double nextDouble() throws IOException {\n        return Double.parseDouble(next());\n    }\n\n    private long nextLong() throws IOException {\n        return Long.parseLong(next());\n    }\n\n    private String next() throws IOException {\n        while (tokens == null || !tokens.hasMoreTokens()) {\n            tokens = new StringTokenizer(input.readLine());\n        }\n        return tokens.nextToken();\n    }\n\n    private StringTokenizer tokens;\n    private BufferedReader input;\n    private PrintWriter output;\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args) throws FileNotFoundException {\n        Scanner s = new Scanner(System.in);\n        int T = s.nextInt();\n        System.out.println(\"0 0 \"+T);\n        /*if(T==0) {\n\n            return;\n        }\n        if(T==1) {\n            System.out.println(\"0 0 0\");\n            return;\n        }\n        System.out.println();*/\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A{\n\tpublic static void main(String[] args){\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\n\t\tint prev2=0;\n\t\tint prev1=1;\n\t\tint prev=1;\n\t\tint curr = 2;\n\t\tif(n == 0) {System.out.println(\"0 0 0\"); return;}\n\t\telse if(n == 1) {System.out.println(\"0 0 1\");return;}\n\t\twhile(true){\n\t\t\tif(curr == n) break;\n\t\t\tprev2 = prev1;\n\t\t\tprev1 = prev;\n\t\t\tint temp = prev + curr;\n\t\t\tprev = curr;\n\t\t\tcurr = temp;\n\t\t}\n\t\tSystem.out.println(prev2 + \" \" + prev1 + \" \" + prev1);\n\t}\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class CF125A {\n\n\tprivate void work() throws IOException {\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\t\tint n = sc.nextInt();\n\t\tSystem.out.printf(\"%d %d %d\\n\", 0, 0, n);\n\t\tSystem.out.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew CF125A().work();\n\t}\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\t(new Main()).solve();\n\t}\n\n\tpublic void Main() {\n\t}\n\n\tvoid solve() throws IOException {\n\t\t// BufferedReader in = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n\t\t// Scanner in = new Scanner(System.in);\n\t\tMyReader in = new MyReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t// Scanner in = new Scanner(new FileReader(\"input.txt\"));\n\t\t// PrintWriter out = new PrintWriter(\"output.txt\");\n\n\t\tint n = in.nextInt();\n\t\tout.print(\"0 0 \");\n\t\tout.print(n);\n\n\t\tout.close();\n\t}\n\n};\n\nclass MyReader {\n\tprivate BufferedReader in;\n\tString[] parsed;\n\tint index = 0;\n\n\tpublic MyReader() {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\tif (parsed == null || parsed.length == index) {\n\t\t\tread();\n\t\t}\n\t\treturn Integer.parseInt(parsed[index++]);\n\t}\n\n\tpublic long nextLong() throws NumberFormatException, IOException {\n\t\tif (parsed == null || parsed.length == index) {\n\t\t\tread();\n\t\t}\n\t\treturn Long.parseLong(parsed[index++]);\n\t}\n\n\tpublic String nextString() throws IOException {\n\t\tif (parsed == null || parsed.length == index) {\n\t\t\tread();\n\t\t}\n\t\treturn parsed[index++];\n\t}\n\n\tprivate void read() throws IOException {\n\t\tparsed = in.readLine().split(\" \");\n\t\tindex = 0;\n\t}\n\n\tpublic String readLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n};", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class CF125D2A {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        Scanner sc = new Scanner (System.in);\n        System.out.println(\"0 0 \"+ sc.nextInt());\n\n    }\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\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 scawn\n */\npublic class Main {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\n        Scanner cin = new Scanner (System.in);\n        int n = cin.nextInt();\n        long res = 2;\n        long[] a = new long[4];\n        a[0] = 0;\n        a[1] = 1;\n        a[2] = 1;\n        a[3] = 2;\n        if (n == 1){\n            System.out.println(\"0 0 1\");\n            return;\n        }\n        if (n == 2){\n            System.out.println(\"0 1 1\");\n            return;\n        }\n        if (n == 0){\n            System.out.println(\"0 0 0\");\n            return;\n        }\n//        if (n == 1 || n == 2 || n == 0){\n//            System.out.println(\"I'm too stupid to solve this problem\");\n//            return;\n//        }\n        if (n == 3){\n            System.out.println(\"1 1 1\");\n            return;\n        }\n        do{\n            a[3] = res;\n            res = a[2] + a[3];\n            if (res == n){\n                System.out.println (a[0] + \" \" + a[1] + \" \" + a[3]);\n                return;\n            }\n            a[0] = a[1];\n            a[1] = a[2];\n            a[2] = a[3];\n            \n        }while (true);\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "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        \n        System.out.println(N + \" \" + 0 + \" \" + 0);\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class MAIN\n{\n    public static void main(String args[])\n    {\n        Scanner sn=new Scanner(System.in);\n        int n,n1,n2,n3;\n\n        int arr[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170};\n\n        n=sn.nextInt();\n\n\n        if(n==2)\n        {\n            n1=n2=1;\n            n3=0;\n        }\n        else if(n==1)\n        {\n            n3=n2=0;\n            n1=1;\n        }\n        else if(n==0)\n        {\n            n1=n2=n3=0;\n        }\n        else if(n==3)\n        {\n            n1=n2=n3=1;\n        }\n        else\n        {\n            int index=bsearch(arr,0,arr.length-1,n);\n            n1=arr[index-1];\n            n2=arr[index-3];\n            n3=arr[index-4];\n        }\n\n        System.out.println(n3+\" \"+n2+\" \"+n1);\n\n    }\n\n    static int bsearch(int arr[],int l,int h,int n)\n    {\n        if(l>h)\n        return -1;\n\n        int mid=(l+h)/2;\n\n        if(n==arr[mid])\n        return mid;\n        else if(n>arr[mid])\n        return(bsearch(arr,mid+1,h,n));\n        else\n        return(bsearch(arr,l,mid-1,n));\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n    final int INF = Integer.MAX_VALUE / 2;\n    private void doit(){\n        Scanner sc = new Scanner(System.in);\n        //while(sc.hasNext()){\n            int n = sc.nextInt();\n            if(n == 0){\n                System.out.println(\"0 0 0\");\n            }\n            else if(n == 1){\n                System.out.println(\"0 0 1\");\n            }\n            else{\n                //create a fib\n                ArrayList<Integer> fibList = new ArrayList<Integer>();\n                int pre = 0;\n                int next = 1;\n                fibList.add(pre);\n                fibList.add(next);\n                while(next != n){\n                    int temp = next;\n                    next +=pre;\n                    fibList.add(next);\n                    pre = temp;\n                }\n                int len = fibList.size();\n                int a = fibList.get(len-4);\n                int b = fibList.get(len-3);\n                int c = fibList.get(len-3);\n                System.out.println(a + \" \" + b + \" \" + c);\n            }\n        //}\n    }\n\n    public static void main(String[] args) {\n        Main obj = new Main();\n        obj.doit();\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n//package CodeForces3;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\n/**\n *\n * @author DELL\n */\npublic class HexadecimalsTheorem {\n\n    public void solve() {\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextLong();\n\n        ArrayList<Long> a = new ArrayList<Long>();\n\n        a.add(0l);\n        a.add(1L);\n        a.add(1L);\n\n        int i = 1, j = 2;\n\n        while ((a.get(i) + a.get(j)) <= n) {\n            a.add((a.get(i) + a.get(j)));\n            i++;\n            j++;\n        }\n\n        if (a.contains(n)) {\n            if (n == 0) {\n                System.out.println(\"0 0 0\");\n            } else if (n == 1) {\n                System.out.println(\"0 0 1\");\n            } else if (n == 2) {\n                System.out.println(\"0 1 1\");\n            } else {\n                System.out.println(a.get(j - 4) + \" \" + a.get(j - 3) + \" \" + a.get(j - 1));\n\n            }\n\n        } else {\n            System.out.println(\"I'm too stupid to solve this problem\");\n        }\n\n\n    }\n\n    public static void main(String[] args) {\n        new HexadecimalsTheorem().solve();\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class MAIN\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sn=new Scanner(System.in);\n\t\tint n,n1,n2,n3;\n\n\t\tint arr[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170};\n\n\t\tn=sn.nextInt();\n\n\n\t\tif(n==2)\n\t\t{\n\t\t\tn1=n2=1;\n\t\t\tn3=0;\n\t\t}\n\t\telse if(n==1)\n\t\t{\n\t\t\tn3=n2=0;\n\t\t\tn1=1;\n\t\t}\n\t\telse if(n==0)\n\t\t{\n\t\t\tn1=n2=n3=0;\n\t\t}\n\t\telse if(n==3)\n\t\t{\n\t\t\tn1=n2=n3=1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint index=bsearch(arr,0,arr.length-1,n);\n\t\t\tn1=arr[index-1];\n\t\t\tn2=arr[index-3];\n\t\t\tn3=arr[index-4];\n\t\t}\n\n\t\tSystem.out.println(n3+\" \"+n2+\" \"+n1);\n\n\t}\n\n\tstatic int bsearch(int arr[],int l,int h,int n)\n\t{\n\t\tif(l>h)\n\t\treturn -1;\n\n\t\tint mid=(l+h)/2;\n\n\t\tif(n==arr[mid])\n\t\treturn mid;\n\t\telse if(n>arr[mid])\n\t\treturn(bsearch(arr,mid+1,h,n));\n\t\telse\n\t\treturn(bsearch(arr,l,mid-1,n));\n\t}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\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        int input = Integer.parseInt(buff.readLine());\n        if(input==0){\n            System.out.println(\"0 0 0\");\n        }else if(input==1){\n            System.out.println(\"0 0 1\");\n        }else if(input==2){\n            System.out.println(\"0 1 1\");\n        }else if(input==3){\n            System.out.println(\"1 1 1\");\n        }else {\n            int output[] = checkFibo(input);\n            int get[] = checkFibo(output[1]);\n            output[0] = get[1];\n            output[1] = get[2];\n            System.out.print(output[0]);\n            System.out.print(\" \" + output[1]);\n            System.out.println(\" \" + output[2]);    \n        }\n    }\n    \n    public static int[] checkFibo(int input){\n        int output[] = new int[3];\n        int fibo_1 = 0;\n        int fibo_2 = 1;\n        int temp = 0;\n        while(fibo_2!=input){\n            temp = fibo_2;\n            output[1] = fibo_1;\n            output[2] = fibo_2;\n            fibo_2 += fibo_1;\n            fibo_1 = temp;\n        }\n        return output;\n    }   \n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\npublic class Hexadecimaltheorem {\n\tpublic static void main(String[] args) {\n\t\tBufferedReader buf = new BufferedReader(\n\t\t\t\tnew InputStreamReader(System.in));\n\t\tint x;\n\t\tArrayList<Integer> arr = new ArrayList<Integer>();\n\t\tarr.add(0);\n\t\tarr.add(1);\n\t\ttry {\n\t\t\twhile ((x = Integer.parseInt(buf.readLine())) != -1) {\n\t\t\t\tif (x == 1) {\n\n\t\t\t\t\tSystem.out.println(arr.get(0) + \" \" + arr.get(0) + \" \"\n\t\t\t\t\t\t\t+ arr.get(1));\n\t\t\t\t} else if (x == 0) {\n\t\t\t\t\tSystem.out.println(arr.get(0) + \" \" + arr.get(0) + \" \"\n\t\t\t\t\t\t\t+ arr.get(0));\n\t\t\t\t} else {\n\t\t\t\t\tint i = 1;\n\t\t\t\t\twhile (x > arr.get(arr.size() - 1)) {\n\t\t\t\t\t\tarr.add(arr.get(i) + arr.get(i - 1));\n\t\t\t\t\t\ti++;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(arr.get(0) + \" \" + arr.get(i - 2) + \" \"\n\t\t\t\t\t\t\t+ arr.get(i - 1));\n\t\t\t\t}\n\t\t\t}\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}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class CF125D2A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        System.out.println(\"0 0 \" + sc.nextInt());\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class ProblemA {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        long n = sc.nextLong();\n        long[] answer = new long[3];\n        if (n == 1) {\n            answer[0] = 0;\n            answer[1] = 0;\n            answer[2] = 1;\n        } else if (n > 1) {\n            long f1 = 0;\n            long f2 = 1;\n            long m = 0;\n            while (m < n) {\n                answer[0] = answer[1];\n                answer[1] = f1;\n                answer[2] = f2;\n                m = f1 + f2;\n                f1 = f2;\n                f2 = m;\n            }\n            answer[2] = answer[1];\n        }\n        System.out.println(answer[0] + \" \" + answer[1] + \" \" + answer[2]);\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        System.out.println(\"0 0 \" + n);\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\nimport java.util.*;\nimport java.util.concurrent.ArrayBlockingQueue;\n\nimport javax.print.attribute.HashAttributeSet;\n\npublic class CodeForces {\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint arr[]=new int[1000];\n\t\tarr[0]=0;\n\t\tarr[1]=1;\n\t\tarr[2]=1;\n\t\tif(n==0){\n\t\t\tout.print(\"0 0 0\");\n\t\t}\n\t\telse if(n==1){\n\t\t\tout.print(\"0 0 1\");\n\t\t} else {\n\t\t\tint c=2;\n\t\t\twhile(arr[c]!=n){\n\t\t\t\tc++;\n\t\t\t\tarr[c]=arr[c-1]+arr[c-2];\n\t\t\t}\n\t\t\tout.print(arr[c-2]+\" \"+arr[c-2]+\" \"+arr[c-3]);\n\t\t}\n\t\t\n\t\t\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CodeForces().run();\n\t}\n\t\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(\"output.txt\")));\n\t\t\t\tout = new PrintWriter(System.out);\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;\t\n\t\t\t// long t=new Date().getTime();\n\t\t\tsolve();\n\t\t\t// writer.println(t-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}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\n/**\n *\n * @author Gitesh\n */\npublic class JavaApplication2 {\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        \n                int n;\n                      n=s.nextInt();\n                      System.out.print(n+\" \"+\"0 0\");            \n}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class HexadecimalTheorem {\n    public static void main(String[] args) {\n        Scanner read = new Scanner(System.in);\n        int num = read.nextInt();\n        int zero, one, two, three;\n        zero = 0;\n        one = 1;\n        two = 1;\n        three = 2;\n        if(num == 0)\n            System.out.println(\"0 0 0\");\n        else if(num == 1)\n            System.out.println(\"0 0 1\");\n        else{\n            while(num != three){\n                zero = one;\n                one = two;\n                two = three;\n                three = three + one;\n            }\n            System.out.println(zero + \" \" + one + \" \" + one);\n        }\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class MAIN\n{\n    public static void main(String args[])\n    {\n        Scanner sn=new Scanner(System.in);\n        int n,n1,n2,n3;\n\n        int arr[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170};\n\n        n=sn.nextInt();\n\n\n        if(n==2)\n        {\n            n1=n2=1;\n            n3=0;\n        }\n        else if(n==1)\n        {\n            n3=n2=0;\n            n1=1;\n        }\n        else if(n==0)\n        {\n            n1=n2=n3=0;\n        }\n        else if(n==3)\n        {\n            n1=n2=n3=1;\n        }\n        else\n        {\n            int index=bsearch(arr,0,arr.length-1,n);\n            n1=arr[index-1];\n            n2=arr[index-3];\n            n3=arr[index-4];\n        }\n\n        System.out.println(n3+\" \"+n2+\" \"+n1);\n\n    }\n\n    static int bsearch(int arr[],int l,int h,int n)\n    {\n        if(l>h)\n        return -1;\n\n        int mid=(l+h)/2;\n\n        if(n==arr[mid])\n        return mid;\n        else if(n>arr[mid])\n        return(bsearch(arr,mid+1,h,n));\n        else\n        return(bsearch(arr,l,mid-1,n));\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Main {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n        int x = scan.nextInt();\n    solve(x);\n\n    }\n    public static void solve (int x){\n        int z = 0 ;\n        System.out.print(z+\" \");\n        System.out.print(z+\" \");\n        System.out.print(x);\n        \n    }\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class A {\n\n    public static void main(String args[]) {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int f1 = 0;\n        int f2 = 1;\n        int f3 = 1;\n        while (f3 < n) {\n            f1 = f2;\n            f2 = f3;\n            f3 = f1 + f2;\n        }\n        if (n == 0) {\n            System.out.println(0 + \" \" + 0 + \" \" + 0);\n        } else if (f3 == n) {\n            System.out.println(f1 + \" \" + f1 + \" \" + (f2 - f1));\n        } else {\n            System.out.println(\"I'm too stupid to solve this problem\");\n        }\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Author: Maksim Novik\n * Date: 30.06.12\n * Time: 22:34\n */\npublic class Round125ProblemA {\n\n    public static void main(String[] args) {\n        InputStream in = System.in;\n        OutputStream out = System.out;\n        InputReader reader = new InputReader(in);\n        PrintWriter writer = new PrintWriter(out);\n        solve(reader, writer);\n        writer.close();\n    }\n\n    static void solve(InputReader in, PrintWriter out) {\n        long fib = in.nextLong();\n        out.write(\"\" + 0  + \" \" + 0 + \" \" + fib);\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n    StringTokenizer st;\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws NumberFormatException, IOException {\n        Solver solver = new Solver();\n        solver.open();\n        solver.solve();\n        solver.close();\n    }\n\n    public void open() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n    }\n\n    public String nextToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    public int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    public long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextToken());\n    }\n\n    public double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    public void solve() throws NumberFormatException, IOException {\n        int n = nextInt();\n        out.println(0+\" \"+0+\" \"+n);\n    }\n\n    public void close() {\n        out.flush();\n        out.close();\n    }\n\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n    public static void main(String[] args) {\n\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        \n        int n = in.nextInt();\n        \n        out.println(n+\" 0 0\");\n        \n        in.close();\n        out.close();\n        \n    }\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class program{\n\tpublic static void main(String args[]) throws Exception{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tif(n==0){\n\t\t\tSystem.out.println(\"0 0 0\");\n\t\t\treturn;\n\t\t}\n\t\telse if(n==1){\n\t\t\tSystem.out.println(\"0 0 1\");\n\t\t\treturn;\n\t\t}\n\t\telse if(n==2){\n\t\t\tSystem.out.println(\"0 1 1\");\n\t\t\treturn;\n\t\t}\n\t\telse{\n\t\t\tint ppp=0;\n\t\t\tint pp=1;\n\t\t\tint c=2;\n\t\t\twhile(true){\n\t\t\t\tif(ppp+pp+c==n){\n\t\t\t\t\tSystem.out.println(ppp+\" \"+pp+\" \"+c);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tc=c+pp+ppp;\n\t\t\t\t\tint temp=pp;\n\t\t\t\t\tpp=pp+ppp;\n\t\t\t\t\tppp=temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class HexadecimalsTheorem {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int num = in.nextInt();\n        LinkedList<Integer> result = new LinkedList<Integer>();\n        int temp0 = 1;\n        int temp1 = 1;\n        int temp2 = 0;\n        result.add(0);\n        result.add(0);\n        result.add(0);\n        result.add(temp0);\n        result.add(temp1);\n        if (num == 2) {\n            System.out.println(0 + \" \" + 1 + \" \" + 1);\n        } else if (num == 0) {\n            System.out.println(0 + \" \" + 0 + \" \" + 0);\n        } else {\n            while (temp2 < num) {\n                temp2 = temp1 + temp0;\n                result.add(temp2);\n                temp0 = temp1;\n                temp1 = temp2;\n            }\n            int length = result.size();\n            System.out.println(result.get(length - 5) + \" \"\n                    + result.get(length - 4) + \" \" + result.get(length - 2));\n        }\n    }\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class A {\n\tstatic Scanner scan = new Scanner (System.in);\n\tstatic PrintStream out = System.out;\n\t\n\tstatic void go (int n) {\n\t\tif (n == 0) {\n\t\t\tSystem.out.println (0 + \" \" + 0 + \" \" + 0);\n\t\t\treturn;\n\t\t}\n\t\tint a = 0, b = 1;\n\t\tint c = a + b; \n\t\twhile (n > c) {\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t\tc = a + b;\n\t\t}\n\t\tSystem.out.println (0 + \" \" + a + \" \" + b);\n\t}\n\t\n\tpublic static void main (String[] args) {\n\t\tint n = scan.nextInt();\n\t\tgo (n);\n\t\n\t} \n\t\t\t\n\t\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\n    public static void main(String[] args) {\n        long fib[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073L, 4807526976L, 7778742049L, 12586269025L, 20365011074L, 32951280099L, 53316291173L, 86267571272L, 139583862445L, 225851433717L, 365435296162L, 591286729879L, 956722026041L, 1548008755920L, 2504730781961L, 4052739537881L, 6557470319842L, 10610209857723L };\n        int i = Arrays.binarySearch(fib, new Scanner(System.in).nextLong());\n        if (i < 4)\n            if (i == 3)\n                System.out.println(\"0 1 1\");\n            else if (fib[i] == 1)\n                System.out.println(\"0 0 1\");\n            else\n                System.out.println(\"0 0 0\");\n        else\n            System.out.println(fib[i - 4] + \" \" + fib[i - 3] + \" \" + fib[i - 1]);\n    }\n\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.regex.*;\n\n\n\npublic class Main {\n\tstatic Scanner scan = new Scanner (System.in);\n\tstatic PrintStream out = System.out;\n\n\tstatic int n;\n\tstatic void solve () {\n\t\tSystem.out.println (0 + \" \" + 0 + \" \" + n);\n\t}\n\t\n\tpublic static void main (String[] args) {\n\t\tn = scan.nextInt();\n\t\tsolve ();\n\t}\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main{\n    public static void main(String[] args) throws IOException{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        List<Integer> fibs = new ArrayList<Integer>();\n        int fib0 = 0;\n        int fib1 = 1;\n        int fibN = fib0+fib1;\n        fibs.add(fib0);\n        fibs.add(fib1);\n        while(fibN < 1000000000){\n            fibs.add(fibN);\n            fib0 = fib1;\n            fib1 = fibN;\n            fibN = fib0+fib1;\n        }\n        int n = Integer.parseInt(br.readLine());\n        \n        if(n == 0){System.out.println(0+\" \"+0+\" \"+0);}\n        else{\n            if(n == 1){System.out.println(0+\" \"+0+\" \"+1);}\n            else{\n                if(n == 2){System.out.println(0+\" \"+1+\" \"+1);}\n                else{\n        int i = fibs.indexOf(n);\n        System.out.println(fibs.get(i-4)+\" \"+fibs.get(i-3)+\" \"+fibs.get(i-1));\n    }}\n        }\n}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class A125D2 {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tInputReader in = new InputReader(System.in);\n\t\tSystem.out.println(0 + \" \" + 0 + \" \" + in.nextInt());\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 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\t}\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.Scanner;\n\n/**\n *\n * @author dilshan\n */\npublic class Test {\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 n = s.nextInt();\n        int k = 1;\n        int t = 0;\n        int y = 2;\n        int[] a = new int[100000];\n        if(n==0){\n            System.out.println(0+\" \"+0+\" \"+0);\n        }\n        else \n            if(n==1){\n            System.out.println(0+\" \"+0+\" \"+1);\n            }\n            else \n                if(n==2){\n                System.out.println(0+\" \"+1+\" \"+1);\n                }\n                else{\n                    a[0] = 0;\n                    a[1] = 1;\n                    a[y] = a[y - 2] + a[y - 1];\n                    while (a[y - 1] < n) {\n\n                        a[y] = a[y - 2] + a[y - 1];\n                        ++y;\n\n\n                    }\n                    System.out.println(a[y - 2] + \" \" + a[y - 4] + \" \" + a[y - 5]);\n            }\n        //System.out.println(y);\n        \n\n\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Hexadecimal {\n public static void main(String args[]){\n\t Scanner input = new Scanner(System.in);\n\t int n = input.nextInt();\n\t System.out.print(\"0 0 \" + n);\n }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\npublic static void main(String args[]) throws Exception\n    {\n     \n     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n     int n=Integer.parseInt(br.readLine());\n     System.out.println(\"0 0 \"+n);}\n\n}\n\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C125 {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = r.readLine();\n\t\tint n = new Integer(s);\n\t\tSystem.out.println(\"0 0 \"+n);\n\t}\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class Hexadecimal {\n\n    public static void main(String [] args){\n        Scanner s = new Scanner(new InputStreamReader(System.in));\n\n        int x = s.nextInt();\n\n       System.out.println(x + \" \" + 0 + \" \" + 0);\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class A {\n    public static void main(String[] args) throws Exception {\n        new A().solve();\n    }\n    void solve() throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        int n = Integer.parseInt(in.readLine());\n        if (n == 0) {\n            System.out.println(\"0 0 0\");\n            return;\n        }\n        int p2 = 0;\n        int p1 = 1;\n        while (true) {\n            int now = p2 + p1;\n            if (n == now) {\n                System.out.println(\"0 \" + p1 + \" \" + p2);\n                return;\n            } else {\n                p2 = p1;\n                p1 = now;\n            }\n        }\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class HexTheorem {\n    public static void main(String[] args) throws NumberFormatException, IOException {\n        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\n        int x = Integer.parseInt(read.readLine());\n        System.out.println(\"0 0 \"+x);\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Hexadec implements Runnable {\n\n    final static String taskname = \"filename\";\n\n    public void solve() throws Exception {\n    //\tint n = iread();\t\n    \tint n = Integer.parseInt(in.readLine());\n    \t\n    \t\n    \t\n    \tout.write(n + \" \"+0+\" \"+0);\n    //    out.write(ans_path + \"\\n\");\n    }\n\n    public void run() {\n        try {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new BufferedWriter(new OutputStreamWriter(System.out));\n//             in = new BufferedReader(new FileReader(taskname + \".in\"));\n//             out = new BufferedWriter(new FileWriter(taskname + \".out\"));\n            solve();\n            out.flush();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    public int iread() throws Exception {\n        return Integer.parseInt(readword());\n    }\n\n    public double dread() throws Exception {\n        return Double.parseDouble(readword());\n    }\n\n    public long lread() throws Exception {\n        return Long.parseLong(readword());\n    }\n\n    BufferedReader in;\n\n    BufferedWriter out;\n\n    public String readword() throws IOException {\n        StringBuilder b = new StringBuilder();\n        int c;\n        c = in.read();\n        while (c >= 0 && c <= ' ')\n            c = in.read();\n        if (c < 0)\n            return \"\";\n        while (c > ' ') {\n            b.append((char) c);\n            c = in.read();\n        }\n        return b.toString();\n    }\n\n    public static void main(String[] args) {\n        // Locale.setDefault(Locale.US);\n        new Thread(new Hexadec()).start();\n    }\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class Fibonacci {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tlong num =0;\n\t\tnum = input.nextLong();\n\t\twhile (num<0 || num>Math.pow(10,9))\n\t\t{\n\t\t\tSystem.out.println(\"Invalid\");\n\t\t\tnum = input.nextLong();\n\t\t}\n\t\tSystem.out.println(\"0 0 \"+num);\n\t}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "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.LinkedList;\nimport java.util.List;\nimport java.util.StringTokenizer;\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        TaskA solver = new TaskA();\n        solver.solve(in, out);\n        out.close();\n    }\n}\n\nclass TaskA {\n    int n;\n    int m;\n    String answer = \"I'm too stupid to solve this problem\";\n    public void solve(InputReader in, PrintWriter out) {\n        n = in.nextInt();\n        out.println(\"0 0 \" + n);        \n    }\n    \n        \n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n        tokenizer = null;\n    }\n\n    public String next() {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            try {\n                tokenizer = new StringTokenizer(reader.readLine());\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return tokenizer.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n}   ", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class N1_CF_199A {\n    public static void main(String[] args) {\n    int n = new Scanner(System.in).nextInt();\n    if( n == 0)\n    {\n        System.out.println(0);\n        System.out.println(0);\n        System.out.println(0);\n        return;\n    }\n    int i = 0 , j = 1;\n    while(true)\n    {\n        int t = i + j;\n        if( t == n)\n        break;\n        i = j;\n        j = t;\n    }\n    System.out.println(i);\n    System.out.println(j);\n    System.out.println(0);\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class a extends Thread {\n\n\tBufferedReader bf;\n\tPrintWriter out;\n\tFastScanner in;\n\n\tvoid solve() throws Exception {\n\t\tlong n = in.nextLong();\n\t\tlong f[] = new long[2001];\n\t\tint i = 2;\n\t\tf[0] = 0;\n\t\tf[1] = 1;\n\t\twhile (true){\n\t\t\tf[i] = f[i-1] + f[i-2];\n\t\t\tif (f[i] < n) i++;\n\t\t\telse break;\n\t\t}\n\t\tif (n == 1) out.println(\"1 0 0\");\n\t\telse if (n == 0) out.println(\"0 0 0\");\n\t\telse \n\t\tif (i - 3 >= 0) out.println(f[i-2] +\" \" + f[i-2] + \" \" +f[i-3]);\n\t\telse out.println(\"I'm too stupid to solve this problem\");\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tbf = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tin = new FastScanner(bf);\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t} catch (Exception ex) {\n\t\t\tex.printStackTrace();\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 a().start();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader bf;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(BufferedReader bf) {\n\t\t\tthis.bf = bf;\n\t\t}\n\n\t\tpublic String nextToken() throws Exception {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws Exception {\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tpublic long nextLong() throws Exception {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tpublic Double nextDouble() throws Exception {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\n\t\tpublic BigInteger nextBigInteger() throws Exception {\n\t\t\treturn new BigInteger(nextToken());\n\t\t}\n\t}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n\n        long n = sc.nextLong();\n        \n        List<Long> fi = new ArrayList<Long>(); \n        \n        fi.add((long) 0);\n        fi.add((long) 1);\n        \n        while (fi.get(fi.size()-1)<n) {\n            fi.add(fi.get(fi.size()-1)+fi.get(fi.size()-2));\n        }\n        \n        int last = fi.size()-1;\n\n        long z = last-1>=0 ? fi.get(last-1) : 0;\n        long y = last-3>=0 ? fi.get(last-3) : 0;\n        long x = last-4>=0 ? fi.get(last-4) : 0;\n\n        if (x+y+z<n)\n            x=1;\n        \n        System.out.println(x+\" \"+y+\" \"+z);\n    }\n    \n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n@SuppressWarnings(\"unused\")\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tSystem.out.println(\"0 0 \" + n);\n\t}\n}", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.Scanner;\n\n\npublic class A199 {\n\tstatic int n[][] = new int[][] { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew A199().solve();\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint N = scan.nextInt();\n//\t\tint f1 = 0;\n//\t\tint f2 = 1;\n//\t\t\n//\t\twhile(true){\n//\t\t\tint t = f1 + f2;\n//\t\t\tif(t == N){\n//\t\t\t\t//guaranteed that n is a Fibonacci number\n//\t\t\t\tbreak;\n//\t\t\t}\n//\t\t\tf1 = f2;\n//\t\t\tf2 = t;\n//\t\t}\n\t\tSystem.out.println(\"0 0 \" + N );\n\t}\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Created with IntelliJ IDEA.\n * User: vaibhav mittal\n * Date: 23/6/12\n * Time: 1:15 AM\n * To change this template use File | Settings | File Templates.\n */\npublic class Main {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        long n = in.nextLong();\n        out.println(0 + \" \" + 0 + \" \" + n);\n\n        in.close();\n        out.close();\n    }\n}\n", "complexity": "constant", "problem": "199_A. Hexadecimal's theorem", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Double.*;\nimport java.lang.Math.*;\n\npublic class two_squares {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew two_squares().run();\n\t}\n\n\tpublic void run() throws Exception {\n\t\tFastIO file = new FastIO();\n\t\tdouble x1 = file.nextInt();\n\t\tdouble y1 = file.nextInt();\n\t\tdouble x2 = file.nextInt();\n\t\tdouble y2 = file.nextInt();\n\t\tdouble x3 = file.nextInt();\n\t\tdouble y3 = file.nextInt();\n\t\tdouble x4 = file.nextInt();\n\t\tdouble y4 = file.nextInt();\n\t\tdouble minx1, maxx1, miny1, maxy1;\n\t\tminx1 = Math.min(x1, Math.min(x2, Math.min(x3, x4)));\n\t\tmaxx1 = Math.max(x1, Math.max(x2, Math.max(x3, x4)));\n\t\tminy1 = Math.min(y1, Math.min(y2, Math.min(y3, y4)));\n\t\tmaxy1 = Math.max(y1, Math.max(y2, Math.max(y3, y4)));\n\t\tdouble x5 = file.nextInt();\n\t\tdouble y5 = file.nextInt();\n\t\tdouble x6 = file.nextInt();\n\t\tdouble y6 = file.nextInt();\n\t\tdouble x7 = file.nextInt();\n\t\tdouble y7 = file.nextInt();\n\t\tdouble x8 = file.nextInt();\n\t\tdouble y8 = file.nextInt();\n\t\tdouble minx2, maxx2, miny2, maxy2;\n\t\tminx2 = Math.min(x5, Math.min(x6, Math.min(x7, x8)));\n\t\tmaxx2 = Math.max(x5, Math.max(x6, Math.max(x7, x8)));\n\t\tminy2 = Math.min(y5, Math.min(y6, Math.min(y7, y8)));\n\t\tmaxy2 = Math.max(y5, Math.max(y6, Math.max(y7, y8)));\n\t\tPoint _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;\n\t\t_1 = new Point(x1, y1);\n\t\t_2 = new Point(x2, y2);\n\t\t_3 = new Point(x3, y3);\n\t\t_4 = new Point(x4, y4);\n\t\t_5 = new Point(x5, y5);\n\t\t_6 = new Point(x6, y6);\n\t\t_7 = new Point(x7, y7);\n\t\t_8 = new Point(x8, y8);\n\t\t_9 = new Point(minx1, maxy1);\n\t\t_10 = new Point(minx1, miny1);\n\t\t_11 = new Point(maxx1, maxy1);\n\t\t_12 = new Point(maxx1, miny1);\n\t\tdouble m1 = (minx2 + maxx2) / 2;\n\t\tdouble m2 = (miny2 + maxy2) / 2;\n\t\t_13 = new Point(minx2, m2);\n\t\t_14 = new Point(m1, miny2);\n\t\t_15 = new Point(maxx2, m2);\n\t\t_16 = new Point(m1, maxy2);\n\t\tPoint[] a = {_1, _2, _3, _4};\n\t\tPoint[] b = {_5, _6, _7, _8};\n\t\tboolean works = false;\n\t\tLine[] aa = {new Line(_9,_10), new Line(_10, _12), new Line(_12, _11), new Line(_11, _9)};\n\t\tLine[] bb = {new Line(_13, _14), new Line(_14, _15), new Line(_15, _16), new Line(_16, _13)};\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\tif (aa[i].intersection(bb[i]) != null) {\n\t\t\t\t\tworks = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (Point p : b) {\n\t\t\tif (p.x >= minx1 && p.x <= maxx1 && p.y >= miny1 && p.y <= maxy1) {\n\t\t\t\tworks = true;\n\t\t\t}\n\t\t}\n\t\tfor (Point p : a) {\n\t\t\tboolean result = false;\n\t\t      for (int i = 0, j = b.length - 1; i < b.length; j = i++) {\n\t\t        if ((b[i].y > p.y) != (b[j].y > p.y) &&\n\t\t            (p.x < (b[j].x - b[i].x) * (p.y - b[i].y) / (b[j].y-b[i].y) + b[i].x)) {\n\t\t          result = !result;\n\t\t         }\n\t\t      }\n\t\t      if (result) works = true;\n\t\t}\n\t\tSystem.out.println(works ? \"YES\" : \"NO\");\n\t}\n\tpublic static class Point {\n\t\tdouble x, y;\n\t\tpublic Point(double a, double b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\t}\n\tpublic static class Line {\n\t\tPoint a, b;\n\t\tpublic Line(Point x, Point y) {\n\t\t\ta = x;\n\t\t\tb = y;\n\t\t}\n\t\tpublic Point intersection(Line o) {\n\t\t\tdouble x1 = a.x;\n\t\t\tdouble y1 = a.y;\n\t\t\tdouble x2 = b.x;\n\t\t\tdouble y2 = b.y;\n\t\t\tdouble x3 = o.a.x;\n\t\t\tdouble y3 = o.a.y;\n\t\t\tdouble x4 = o.b.x;\n\t\t\tdouble y4 = o.b.y;\n\t\t\tdouble denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);\n\t\t\t  double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3))/denom;\n\t\t\t  double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3))/denom;\n\t\t\t    if (ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f) {\n\t\t\t        return new Point((int) (x1 + ua*(x2 - x1)), (int) (y1 + ua*(y2 - y1)));\n\t\t\t    }\n\n\t\t\t  return null;\n\t\t}\n\t}\n\tpublic static class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastIO() {\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 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 / 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 / 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", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C {\n\n\tstatic StringBuilder st = new StringBuilder();\n\n\t\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\n\t\tPoint [] square = new Point [4] ; \n\t\tPoint [] rotSquare = new Point[4] ; \n\t\t\n\t\tfor(int i = 0 ; i < 4 ;i++)\n\t\t\tsquare[i] = new Point(sc.nextInt() , sc.nextInt());\n\t\t\n\t\tfor(int i = 0 ; i < 4 ;i++)\n\t\t\trotSquare[i] = new Point(sc.nextInt() , sc.nextInt());\n\t\t\n\t\tboolean can = false ; \n\t\t\n\t\tfor(int x = -100 ; x <= 100 ; x++)\n\t\t\tfor(int y = -100 ; y <= 100 ; y++)\n\t\t\t\tcan |= inside(new Point(x , y), square) & inside(new Point (x , y), rotSquare);\n\t\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\tout.println(can ? \"YES\" : \"NO\");\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\n\t}\n\tstatic int crossProduct(Point a , Point b)\n\t{\n\t\tint ans = a.x * b.y - a.y * b.x ; \n\t\t\n\t\tif(ans < 0)return -1 ;\n\t\tif(ans == 0) return 0 ;\n\t\treturn 1 ; \n\t}\n\t\n\tstatic boolean inside(Point a , Point [] points)\n\t{\n\t\tboolean allPos = true ; \n\t\tboolean allNeg = true ; \n\t\t\n\t\tfor(int i = 0 ; i < 4 ; i++)\n\t\t{\n\t\t\tPoint v1 = new Point (points[i].x - a.x , points[i].y - a.y) ; \n\t\t\tPoint v2 = new Point (points[(i + 1) % 4].x - a.x , points[(i + 1) % 4].y - a.y) ; \n\t\t\t\n\t\t\tallPos &= crossProduct(v1, v2) >= 0;\n\t\t\tallNeg &= crossProduct(v1, v2) <= 0;\n\t\t}\n\t\treturn allPos | allNeg ; \n\t\t\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\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\n\t\t\treturn st.nextToken();\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}\n\n\tstatic void shuffle(int[] a) {\n\t\tint n = a.length;\n\t\tfor (int i = 0; i < n; i++) {\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}", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n\npublic class C994{\n\tstatic double area(double x1,double y1,double x2,double y2,double x3,double y3){\n\t\treturn Math.abs((x1 * (y2 - y3) +  \n        x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); \n\t}\n\tpublic static void main(String args[])throws IOException{\n\t\tScanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tint x11=sc.nextInt();\n\t\tint y11=sc.nextInt();\n\t\tint x12=sc.nextInt();\n\t\tint y12=sc.nextInt();\n\t\tint x13=sc.nextInt();\n\t\tint y13=sc.nextInt();\n\t\tint x14=sc.nextInt();\n\t\tint y14=sc.nextInt();\n\t\tdouble x1c=(x11+x12+x13+x14)/4.0;\n\t\tdouble y1c=(y11+y12+y13+y14)/4.0;\n\t\tint x21=sc.nextInt();\n\t\tint y21=sc.nextInt();\n\t\tint x22=sc.nextInt();\n\t\tint y22=sc.nextInt();\n\t\tint x23=sc.nextInt();\n\t\tint y23=sc.nextInt();\n\t\tint x24=sc.nextInt();\n\t\tint y24=sc.nextInt();\n\t\tdouble x2c=(x21+x22+x23+x24)/4.0;\n\t\tdouble y2c=(y21+y22+y23+y24)/4.0;\n\t\tdouble a1=area(x11,y11,x12,y12,x13,y13)+area(x11,y11,x13,y13,x14,y14);\n\t\tdouble a2=area(x21,y21,x22,y22,x23,y23)+area(x21,y21,x23,y23,x24,y24);\n\t\tif(a1==area(x11,y11,x12,y12,x21,y21)+area(x11,y11,x21,y21,x14,y14)+area(x21,y21,x12,y12,x13,y13)+area(x21,y21,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x22,y22)+area(x11,y11,x22,y22,x14,y14)+area(x22,y22,x12,y12,x13,y13)+area(x22,y22,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x23,y23)+area(x11,y11,x23,y23,x14,y14)+area(x23,y23,x12,y12,x13,y13)+area(x23,y23,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x24,y24)+area(x11,y11,x24,y24,x14,y14)+area(x24,y24,x12,y12,x13,y13)+area(x24,y24,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a1==area(x11,y11,x12,y12,x2c,y2c)+area(x11,y11,x2c,y2c,x14,y14)+area(x2c,y2c,x12,y12,x13,y13)+area(x2c,y2c,x14,y14,x13,y13)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x11,y11)+area(x21,y21,x11,y11,x24,y24)+area(x11,y11,x22,y22,x23,y23)+area(x11,y11,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x12,y12)+area(x21,y21,x12,y12,x24,y24)+area(x12,y12,x22,y22,x23,y23)+area(x12,y12,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x13,y13)+area(x21,y21,x13,y13,x24,y24)+area(x13,y13,x22,y22,x23,y23)+area(x13,y13,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x14,y14)+area(x21,y21,x14,y14,x24,y24)+area(x14,y14,x22,y22,x23,y23)+area(x14,y14,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tif(a2==area(x21,y21,x22,y22,x1c,y1c)+area(x21,y21,x14,y14,x2c,y2c)+area(x1c,y1c,x22,y22,x23,y23)+area(x1c,y1c,x24,y24,x23,y23)){\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tpw.println(\"NO\");\n\t\tpw.close();\n\t}\n}", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "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 TwoSquares {\n    \n    int INF = 1000;\n    \n    void solve() {\n        int[][] s1 = new int[4][2];\n        for (int i = 0; i < 4; i++) {\n            s1[i][0] = in.nextInt();\n            s1[i][1] = in.nextInt();\n        }\n        \n        int[][] s2 = new int[4][2];\n        for (int i = 0; i < 4; i++) {\n            s2[i][0] = in.nextInt();\n            s2[i][1] = in.nextInt();\n        }\n        \n        if (ok(s1, s2)) {\n            out.println(\"Yes\");\n            return;\n        }\n        \n        rotate(s1);\n        rotate(s2);\n        \n        if (ok(s2, s1)) {\n            out.println(\"Yes\");\n            return;\n        }\n        \n        out.println(\"No\");\n    }\n    \n    void rotate(int[][] s) {\n        for (int i = 0; i < 4; i++) {\n            int x = s[i][0], y = s[i][1];\n            s[i][0] = x - y;\n            s[i][1] = x + y;\n        }\n    }\n    \n    boolean ok(int[][] s1, int[][] s2) {\n        int xmin = INF, xmax = -INF, ymin = INF, ymax = -INF;\n        for (int i = 0; i < 4; i++) {\n            xmin = Math.min(xmin, s1[i][0]);\n            xmax = Math.max(xmax, s1[i][0]);\n            ymin = Math.min(ymin, s1[i][1]);\n            ymax = Math.max(ymax, s1[i][1]);\n        }\n        \n        for (int i = 0; i < 4; i++) {\n            if (s2[i][0] >= xmin && s2[i][0] <= xmax && s2[i][1] >= ymin && s2[i][1] <= ymax) return true;\n        }\n        \n        int[] mid2 = new int[]{s2[0][0] + s2[2][0], s2[0][1] + s2[2][1]};\n        return mid2[0] >= xmin * 2 && mid2[0] <= xmax * 2 && mid2[1] >= ymin * 2 && mid2[1] <= ymax * 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 TwoSquares().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", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class cf2 {\n\tstatic final double EPS = 1e-9;\n\n  public static void main(String[] args) throws IOException {\n\t Scanner sc = new Scanner(System.in);\n\t\n\t //rec\n\t int xr1=sc.nextInt(), yr1=sc.nextInt(), xr2=sc.nextInt(),yr2=sc.nextInt();\n\t int xr3=sc.nextInt(), yr3=sc.nextInt(), xr4=sc.nextInt(),yr4=sc.nextInt();\n\t\n\t Point pr1 = new Point(xr1, yr1);\n\t Point pr2 = new Point(xr2, yr2);\n\t Point pr3 = new Point(xr3, yr3);\n\t Point pr4 = new Point(xr4, yr4);\n\t \n\t LineSegment lr1 = new LineSegment(pr1, pr2);\n\t LineSegment lr2 = new LineSegment(pr2, pr3);\n\t LineSegment lr3 = new LineSegment(pr3, pr4);\n\t LineSegment lr4 = new LineSegment(pr4, pr1);\n\t \n\t //diamond\n\t int xd1=sc.nextInt(), yd1=sc.nextInt(), xd2=sc.nextInt(),yd2=sc.nextInt();\n\t int xd3=sc.nextInt(), yd3=sc.nextInt(), xd4=sc.nextInt(),yd4=sc.nextInt();\n\t \n\t Point p1 = new Point(xd1, yd1);\n\t Point p2 = new Point(xd2, yd2);\n\t Point p3 = new Point(xd3, yd3);\n\t Point p4 = new Point(xd4, yd4);\n\t \n\t Point [] pt = new Point [5];\n\t pt[0]=p1;  pt[1]=p2;  pt[2]=p3;  pt[3]=p4;  pt[4]=p1;\n\t Polygon pg = new Polygon(pt);\n\t \n\t if(pg.inside(pr1)||pg.inside(pr2)||pg.inside(pr3)||pg.inside(pr4)) {\n\t\t System.out.println(\"YES\");\n\t\t return;\n\t }\n\t\n\t \n\t LineSegment ld1 = new LineSegment(p1, p2);\n\t LineSegment ld2 = new LineSegment(p2, p3);\n\t LineSegment ld3 = new LineSegment(p3, p4);\n\t LineSegment ld4 = new LineSegment(p4, p1);\n\t \n\t Rectangle rec = new Rectangle(new Point(Math.min(Math.min(xr3,xr4),Math.min(xr1,xr2)), Math.min(Math.min(yr3,yr4),Math.min(yr1,yr2))), \n\t\t\t new Point(Math.max(Math.max(xr3,xr4),Math.max(xr1,xr2)), Math.max(Math.max(yr3,yr4),Math.max(yr1,yr2))) );\n\t \n\t if(rec.contains(p1)||rec.contains(p2)||rec.contains(p3)||rec.contains(p4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld1.intersect(lr1)||ld1.intersect(lr3)||ld1.intersect(lr3)||ld1.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld2.intersect(lr1)||ld2.intersect(lr3)||ld2.intersect(lr3)||ld2.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld3.intersect(lr1)||ld3.intersect(lr3)||ld3.intersect(lr3)||ld3.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t if(ld4.intersect(lr1)||ld4.intersect(lr3)||ld4.intersect(lr3)||ld4.intersect(lr4)) {\n\t\t System.out.println(\"YES\");\n\t     return;\n\t }\n\t \n\t System.out.println(\"NO\");\n\t \n\t \n\t \n\t \n}\n  \n  public static class Polygon { \n\t\t// Cases to handle: collinear points, polygons with n < 3\n\n\t\tstatic final double EPS = 1e-9;\n\t\t\n\t\tPoint[] g; \t\t\t//first point = last point, counter-clockwise representation\n\t\t\n\t\tPolygon(Point[] o) { g = o; }\n\n\t\tdouble perimeter()\n\t\t{\n\t\t\tdouble sum = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; ++i)\n\t\t\t\tsum += g[i].dist(g[i+1]);\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tdouble area() \t\t//clockwise/anti-clockwise check, for convex/concave polygons\n\t\t{\n\t\t\tdouble area = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; ++i)\n\t\t\t\tarea += g[i].x * g[i+1].y - g[i].y * g[i+1].x;\n\t\t\treturn Math.abs(area) / 2.0;\t\t\t//negative value in case of clockwise\n\t\t}\n\n\t\n\t\t\n\t\tboolean inside(Point p)\t//for convex/concave polygons - winding number algorithm \n\t\t{\n\t\t\tdouble sum = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; ++i)\n\t\t\t{\n\t\t\t\tdouble angle = Point.angle(g[i], p, g[i+1]);\n\t\t\t\tif((Math.abs(angle) < EPS || Math.abs(angle - Math.PI) < EPS) && p.between(g[i], g[i+1]))\n\t\t\t\t\treturn true;\n\t\t\t\tif(Point.ccw(p, g[i], g[i+1]))\n\t\t\t\t\tsum += angle;\n\t\t\t\telse\n\t\t\t\t\tsum -= angle;\n\t\t\t}\n\n\t\t\treturn Math.abs(2 * Math.PI - Math.abs(sum)) < EPS;\t\t//abs makes it work for clockwise\n\t\t}\n\t\t/*\n\t\t * Another way if the polygon is convex\n\t\t * 1. Triangulate the poylgon through p\n\t\t * 2. Check if sum areas == poygon area\n\t\t * 3. Handle empty polygon\n\t\t */\n\t\t\n\t\t\n\n\t\n\t\tPoint centroid()\t\t//center of mass\n\t\t{\n\t\t\tdouble cx = 0.0, cy = 0.0;\n\t\t\tfor(int i = 0; i < g.length - 1; i++)\n\t\t\t{\n\t\t\t\tdouble x1 = g[i].x, y1 = g[i].y;\n\t\t\t\tdouble x2 = g[i+1].x, y2 = g[i+1].y;\n\n\t\t\t\tdouble f = x1 * y2 - x2 * y1;\n\t\t\t\tcx += (x1 + x2) * f;\n\t\t\t\tcy += (y1 + y2) * f;\n\t\t\t}\n\t\t\tdouble area = area();\t\t//remove abs\n\t\t\tcx /= 6.0 * area;\n\t\t\tcy /= 6.0 * area;\n\t\t\treturn new Point(cx, cy);\n\t\t}\n\t}\n  \n   static class LineSegment {\n\n\t\tPoint p, q;\n\t\t\n\t\tLineSegment(Point a, Point b) { p = a; q = b; }\n\t\t\n\n\t\tboolean intersect(LineSegment ls)\n\t\t{\n\t\t\tLine l1 = new Line(p, q), l2 = new Line(ls.p, ls.q);\n\t\t\tif(l1.parallel(l2))\n\t\t\t{\n\t\t\t\tif(l1.same(l2))\n\t\t\t\t\treturn p.between(ls.p, ls.q) || q.between(ls.p, ls.q) || ls.p.between(p, q) || ls.q.between(p, q);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tPoint c = l1.intersect(l2);\n\t\t\treturn c.between(p, q) && c.between(ls.p, ls.q);\n\t\t}\n\n\t}\n  \n   static class Rectangle {\n\n\t\tstatic final double EPS = 1e-9;\n\t\t\n\t\tPoint ll, ur;\n\n\t\tRectangle(Point a, Point b) { ll = a; ur = b; }\n\n\t\tdouble area() { return (ur.x - ll.x) * (ur.y - ll.y); }\n\n\t\tboolean contains(Point p)\n\t\t{\n\t\t\treturn p.x <= ur.x + EPS && p.x + EPS >= ll.x && p.y <= ur.y + EPS && p.y + EPS >= ll.y;\n\t\t}\n\n\t\tRectangle intersect(Rectangle r)\n\t\t{\n\t\t\tPoint ll = new Point(Math.max(this.ll.x, r.ll.x), Math.max(this.ll.y, r.ll.y));\n\t\t\tPoint ur = new Point(Math.min(this.ur.x, r.ur.x), Math.min(this.ur.y, r.ur.y));\n\t\t\tif(Math.abs(ur.x - ll.x) > EPS && Math.abs(ur.y - ll.y) > EPS && this.contains(ll) && this.contains(ur) && r.contains(ll) && r.contains(ur))\n\t\t\t\treturn new Rectangle(ll, ur);\n\t\t\treturn null;\n\t\t}\n\n\t}\n   static class Line {\n\n\t\tstatic final double INF = 1e9, EPS = 1e-9;\n\t\t\n\t\tdouble a, b, c;\n\t\t\n\t\tLine(Point p, Point q)\n\t\t{\n\t\t\tif(Math.abs(p.x - q.x) < EPS) {\ta = 1; b = 0; c = -p.x;\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ta = (p.y - q.y) / (q.x - p.x);\n\t\t\t\tb = 1.0;\n\t\t\t\tc = -(a * p.x + p.y);\n\t\t\t}\n\t\t\t\t\t\t\n\t\t}\n\t\t\n\t\tLine(Point p, double m) { a = -m; b = 1; c =  -(a * p.x + p.y); } \n\t\t\n\t\tboolean parallel(Line l) { return Math.abs(a - l.a) < EPS && Math.abs(b - l.b) < EPS; }\n\t\t\n\t\tboolean same(Line l) { return parallel(l) && Math.abs(c - l.c) < EPS; }\n\t\t\n\t\tPoint intersect(Line l)\n\t\t{\n\t\t\tif(parallel(l))\n\t\t\t\treturn null;\n\t\t\tdouble x = (b * l.c - c * l.b) / (a * l.b - b * l.a);\n\t\t\tdouble y;\n\t\t\tif(Math.abs(b) < EPS)\n\t\t\t\t y = -l.a * x - l.c;\n\t\t\telse\n\t\t\t\ty = -a * x - c;\n\t\t\t\n\t\t\treturn new Point(x, y);\n\t\t}\n\t\t\n\t\tPoint closestPoint(Point p)\n\t\t{\n\t\t\tif(Math.abs(b) < EPS) return new Point(-c, p.y);\n\t\t\tif(Math.abs(a) < EPS) return new Point(p.x, -c);\n\t\t\treturn intersect(new Line(p, 1 / a));\n\t\t}\n\t\t\t\t\n\t}\n\n   public static class Vector {\n\n\t\tdouble x, y; \n\n\t\tVector(double a, double b) { x = a; y = b; }\n\n\t\tVector(Point a, Point b) { this(b.x - a.x, b.y - a.y); }\n\n\t\tVector scale(double s) { return new Vector(x * s, y * s); }              //s is a non-negative value\n\n\t\tdouble dot(Vector v) { return (x * v.x + y * v.y); }\n\n\t\tdouble cross(Vector v) { return x * v.y - y * v.x; }\n\n\t\tdouble norm2() { return x * x + y * y; }\n\n\t\tVector reverse() { return new Vector(-x, -y); }\n\n\t\tVector normalize() \n\t\t{ \n\t\t\tdouble d = Math.sqrt(norm2());\n\t\t\treturn scale(1 / d);\n\t\t}\t\t\n\t}\n   \n   static class Point implements Comparable<Point>{\n\n\t\tstatic final double EPS = 1e-9;\n\n\t\tdouble x, y;                  \n\n\t\tPoint(double a, double b) { x = a; y = b; }  \n\t\t\n\t\tpublic int compareTo(Point p)\n\t\t{\n\t\t\tif(Math.abs(x - p.x) > EPS) return x > p.x ? 1 : -1;\n\t\t\tif(Math.abs(y - p.y) > EPS) return y > p.y ? 1 : -1;\n\t\t\treturn 0;\n\t\t}\n\t\tstatic double angle(Point a, Point o, Point b)  // angle AOB\n\t\t{\n\t\t\tVector oa = new Vector(o, a), ob = new Vector(o, b);\n\t\t\treturn Math.acos(oa.dot(ob) / Math.sqrt(oa.norm2() * ob.norm2()));\n\t\t}\n\t\tstatic boolean ccw(Point p, Point q, Point r)\n\t\t{\n\t\t\treturn new Vector(p, q).cross(new Vector(p, r)) > 0;\n\t\t}\n\t\t\n\t\tpublic double dist(Point p) { return Math.sqrt(sq(x - p.x) + sq(y - p.y)); }\n\t\t\n\t\tstatic double sq(double x) { return x * x; }\n\t\t\n\t\tPoint rotate(double angle)\n\t\t{\n\t\t\tdouble c = Math.cos(angle), s = Math.sin(angle);\n\t\t\treturn new Point(x * c - y * s, x * s + y * c);\n\t\t}\n\t\t// for integer points and rotation by 90 (counterclockwise) : swap x and y, negate x\n\t\t\n\t\n\t\t\n\t\tboolean between(Point p, Point q)\n\t\t{\n\t\t\treturn x < Math.max(p.x, q.x) + EPS && x + EPS > Math.min(p.x, q.x)\n\t\t\t\t\t&& y < Math.max(p.y, q.y) + EPS && y + EPS > Math.min(p.y, q.y);\n\t\t}\n\t\t\n\t\t//returns true if it is on the line defined by a and b\n\t\n\t\t//returns true if it is on the ray whose start point is a and passes through b\n\t\t// Another way: find closest point and calculate the distance between it and p\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 Scanner(String file) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(file));\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 long nextlong() throws IOException {\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\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", "complexity": "constant", "problem": "994_C. Two Squares", "from": "CODEFORCES"}
{"src": "/* Shubhang Verma */\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\npublic class Main {\n\n    public static void main(String[] args) \n    {\t\n        InputStream inputstream = System.in;\n        OutputStream outputstream = System.out;\n        InputReader in = new InputReader(inputstream);\n        OutputWriter out = new OutputWriter(outputstream);\n        mysolver mysol = new mysolver();\n        mysol.solve(in, out);\n        out.close();\n    }\n}\nclass node implements Comparable<node>{\n\tint count;\n\tlong value;\n\tpublic int compareTo(node t)\n\t{\n\t\tif(this.value == t.value)\n\t\t\treturn 0;\n\t\telse if(this.value < t.value)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn 1;\n\t}\n}\nclass mysolver {\n\tpublic long mod = 1000000007;\n\tint M,N;\n\tboolean bpm(boolean bpGraph[][], int u, boolean seen[], int matchR[])\n\t{\n\t    for (int v = 0; v < N; v++)\n\t    {\n\t        if (bpGraph[u][v] && !seen[v])\n\t        {\n\t            seen[v] = true;\n\t            if (matchR[v] < 0 || bpm(bpGraph, matchR[v], seen, matchR))\n\t            {\n\t                matchR[v] = u;\n\t                return true;\n\t            }\n\t        }\n\t    }\n\t    return false;\n\t}\n\n\tint maxBPM(boolean bpGraph[][])\n\t{\n\t    int matchR[] = new int[N];\n\t    Arrays.fill(matchR,-1);\n\t    int result = 0;\n\t    for (int u = 0; u < M; u++)\n\t    {\n\t        boolean seen[] = new boolean[N];\n\t        if (bpm(bpGraph, u, seen, matchR))\n\t            result++;\n\t    }\n\t    return result;\n\t}\n\t\n    public void solve(InputReader in,OutputWriter out)\n    {\n    \tPrintWriter pout = new PrintWriter(new BufferedOutputStream(System.out));\t\n    \tint n = in.readInt();\n    \tint m = in.readInt();\n    \tboolean eg[][] = new boolean[n][n];\n    \tfor(int i=0;i<n;i++)\n    \t{\n    \t\tArrays.fill(eg[i],false);\n    \t}\n    \tfor(int i=0;i<m;i++)\n    \t{\n    \t\tint x = in.readInt()-1;\n    \t\tint y = in.readInt()-1;\n    \t\teg[x][y] = true;\n    \t}\n    \t\n    \tint minimum = Integer.MAX_VALUE;\n    \t\n    \tfor(int i=0;i<n;i++)\n    \t{\n\n        \tint ct = 0;\n        \t\n    \t\tint addedges =0;\n    \t\tif(eg[i][i] == false)\n    \t\t{\n    \t\t\taddedges++;\n    \t\t}\n    \t\telse\n    \t\t{\n    \t\t\tct++;\n    \t\t}\n    \t\t\n    \t\tfor(int j=0;j<n;j++)\n    \t\t{\n    \t\t\tif(j!=i && eg[i][j]==false)\n    \t\t\t{\n    \t\t\t\taddedges++;\n    \t\t\t}\n    \t\t\telse if(j!=i && eg[i][j] == true)\n    \t\t\t{\n    \t\t\t\tct++;\n    \t\t\t}\n    \t\t\tif(j!=i && eg[j][i]==false)\n    \t\t\t{\n    \t\t\t\taddedges++;\n    \t\t\t}\n    \t\t\telse if(j!=i && eg[j][i] == true)\n    \t\t\t{\n    \t\t\t\tct++;\n    \t\t\t}\n    \t\t}\n    \t\t//m - ct\n    \t\t\n    \t\tboolean row[] = new boolean[n];\n    \t\tboolean col[] = new boolean[n];\n    \t\tfor(int j=0;j<n;j++)\n    \t\t{\n    \t\t\trow[j] = eg[i][j];\n    \t\t\tcol[j] = eg[j][i];\n    \t\t\teg[i][j] = false;\n    \t\t\teg[j][i] = false;\n    \t\t}\n    \t\t\n    \t\tN = n;\n    \t\tM = n;\n    \t\t\n//    \t\tfor(int I=0;I<n;I++)\n//    \t\t{\n//    \t\t\tfor(int J=0;J<n;J++)\n//    \t\t\t{\n//    \t\t\t\tSystem.out.print(eg[I][J]+\" \");\n//    \t\t\t}\n//    \t\t\tSystem.out.println();\n//    \t\t}\n    \t\t//System.out.println();\n    \t\tint matching = maxBPM(eg);\n    \t\t//System.out.println(matching);\n    \t\taddedges += n - 1 + m - ct - 2*matching;\n    \t\tminimum = Math.min(minimum,addedges);\n    \t\tfor(int j=0;j<n;j++)\n    \t\t{\n    \t\t\teg[i][j] = row[j];\n    \t\t\teg[j][i] = col[j];\n    \t\t}\n    \t\t\n    \t}\n    \t\n    \tSystem.out.println(minimum);\n    \t\n        pout.close();\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    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 String next() {\n        return readString();\n    }\n \n    public interface SpaceCharFilter {\n        public boolean isSpaceChar(int ch);\n    }\n}\n \nclass OutputWriter {\n    private final PrintWriter writer;\n \n    public OutputWriter(OutputStream outputStream) {\n        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n    }\n \n    public OutputWriter(Writer writer) {\n        this.writer = new PrintWriter(writer);\n    }\n \n    public void close() {\n        writer.close();\n    }\n \n    public void printLine(int i) {\n        writer.println(i);\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    }\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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    int n, m;\n    boolean[][] grid;\n    ArrayList<Integer>[] gr;\n    int c;\n    int[] mt;\n    boolean[] u;\n\n\n    boolean try_kuhn( int v ){\n        if( u[v] ) return false;\n        u[v] = true;\n        for( int to : gr[v] ){\n            if( to == c || !grid[v][to] ) continue;\n            if( mt[to]==-1 || try_kuhn(mt[to]) ){\n                mt[to] = v;\n                return true;\n            }\n        }\n        return false;\n    }\n\n    void solve(){\n        n = sc.nextInt();\n        m = sc.nextInt();\n        grid = new boolean[n+1][n+1];\n        gr = new ArrayList[n+1];\n        for( int v = 1; v <= n; ++v ) gr[v] = new ArrayList<Integer>();\n        for( int it = 0; it < m; ++it ){\n            int a = sc.nextInt();\n            int b = sc.nextInt();\n            grid[a][b] = true;\n            gr[a].add(b);\n        }\n\n        int ans = Integer.MAX_VALUE;\n        for( c = 1; c <= n; ++c ){\n            int curAns = 0;\n            for( int v = 1; v <= n; ++v )\n                if( v != c ){\n                    if( !grid[c][v] ) ++curAns;\n                    if( !grid[v][c] ) ++curAns;\n                }\n            if( !grid[c][c] ) ++curAns;\n\n            mt = new int[n+1];\n            fill( mt, -1 );\n            for( int i = 1; i <= n; ++i )\n                if( i != c ){\n                    u = new boolean[n+1];\n                    try_kuhn(i);\n                }\n\n            int szMt = 0;\n            for( int i = 1; i <= n; ++i )\n                if( mt[i] != -1 )\n                    ++szMt;\n            curAns += n - 1 - szMt;\n\n            for( int a = 1; a <= n; ++a ){\n            for( int b = 1; b <= n; ++b ){\n                if( a==c || b==c || !grid[a][b]\n                ) continue;\n                if(!( a==mt[b] ))\n                    ++curAns;\n            }\n            }\n\n//            out.printf( \"%d %d\\n\", c, curAns );\n            ans = min( ans, curAns );\n        }\n        out.println( ans );\n    }\n\n\n\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\n\npublic class D {\n    static LinkedList<Integer>[] E;\n    static int[] M;\n    static boolean[] visited;\n    static int n;\n    static int center;\n\n    public static boolean match(int x) {\n        if (visited[x])\n            return false;\n        visited[x] = true;\n        for (int y : E[x])\n            if (y != center && (M[y] == -1 || match(M[y]))) {\n                M[y] = x;\n                return true;\n            }\n        return false;\n    }\n\n    public static int maxMatch() {\n        int res = 0;\n        Arrays.fill(M, -1);\n        for (int i = 0; i < n; i++) {\n            Arrays.fill(visited, false);\n            if (i != center && match(i))\n                res++;\n        }\n        return res;\n    }\n\n    public static void main(String[] args) {\n        InputReader in = new InputReader(System.in);\n        n = in.readInt();\n        int m = in.readInt();\n        E = new LinkedList[n];\n        M = new int[n];\n        boolean[][] C = new boolean[n][n];\n        visited = new boolean[n];\n        for (int i = 0; i < n; i++)\n            E[i] = new LinkedList<Integer>();\n        for (int i = 0; i < m; i++) {\n            int x = in.readInt() - 1;\n            int y = in.readInt() - 1;\n            C[x][y] = true;\n            E[x].add(y);\n        }\n        int min = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            int res = 0;\n            int all = 0;\n            for (int j = 0; j < n; j++)\n                if (j != i) {\n                    all += E[j].size();\n                    if (!C[i][j])\n                        res++;\n                    if (!C[j][i])\n                        res++;\n                    else\n                        all--;\n                }\n            if (!C[i][i])\n                res++;\n            center = i;\n            int match = maxMatch();\n            res += (all - match) + (n - match - 1);\n            min = Math.min(min, res);\n        }\n        System.out.println(min);\n    }\n}\n\nclass InputReader {\n\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}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.Reader;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.util.List;\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 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        int[] from = new int[m];\n        int[] to = new int[m];\n        for (int i = 0; i < m; i++) {\n            from[i] = in.nextInt() - 1;\n            to[i] = in.nextInt() - 1;\n        }\n        int ans = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            KuhnMatchingGraph g = new KuhnMatchingGraph(n, n);\n            int count = 0;\n            for (int j = 0; j < m; j++) {\n                if (from[j] != i && to[j] != i) {\n                    g.addEdge(from[j], to[j]);\n                    ++count;\n                }\n            }\n            int cur = (n - 1 + count) - 2 * g.getMaximalMatching();\n            boolean[] a = new boolean[n];\n            boolean[] b = new boolean[n];\n            for (int j = 0; j < m; j++) {\n                if (from[j] == i) {\n                    a[to[j]] = true;\n                }\n                if (to[j] == i) {\n                    b[from[j]] = true;\n                }\n            }\n            for (int j = 0; j < n; j++) {\n                if (j == i) {\n                    if (!a[j]) ++cur;\n                } else {\n                    if (!a[j]) ++cur;\n                    if (!b[j]) ++cur;\n                }\n            }\n            ans = Math.min(ans, cur);\n        }\n        out.println(ans);\n    }\n}\n\nclass FastScanner extends BufferedReader {\n\n    public FastScanner(InputStream is) {\n        super(new InputStreamReader(is));\n    }\n\n    public int read() {\n        try {\n            int ret = super.read();\n//            if (isEOF && ret < 0) {\n//                throw new InputMismatchException();\n//            }\n//            isEOF = ret == -1;\n            return ret;\n        } catch (IOException e) {\n            throw new InputMismatchException();\n        }\n    }\n\n    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\nclass FastPrinter extends PrintWriter {\n\n    public FastPrinter(OutputStream out) {\n        super(out);\n    }\n\n\n}\n\nclass KuhnMatchingGraph {\n\n    int n;\n    int m;\n    List<Integer>[] edges;\n    int[] p1;\n    int[] p2;\n    int[] was;\n    int VER;\n\n    public KuhnMatchingGraph(int n, int m) {\n        this.n = n;\n        this.m = m;\n        edges = new ArrayList[n];\n        for (int i = 0; i < n; i++) {\n            edges[i] = new ArrayList<Integer>(2);\n        }\n    }\n\n    public void addEdge(int from, int to) {\n        edges[from].add(to);\n    }\n\n    public int getMaximalMatching() {\n        p1 = new int[n];\n        p2 = new int[m];\n        was = new int[n];\n        VER = 0;\n        Arrays.fill(p1, -1);\n        Arrays.fill(p2, -1);\n        int answer = 0;\n        for (int i = 0; i < n; i++) {\n            for (int j : edges[i]) {\n                if (p2[j] < 0) {\n                    p2[j] = i;\n                    p1[i] = j;\n                    answer++;\n                    break;\n                }\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            if (p1[i] >= 0) {\n                continue;\n            }\n            VER++;\n            if (dfs(i)) {\n                answer++;\n            }\n        }\n        return answer;\n    }\n\n    boolean dfs(int v) {\n        if (was[v] == VER) {\n            return false;\n        }\n        was[v] = VER;\n        for (int i = 0; i < edges[v].size(); i++) {\n            int e = edges[v].get(i);\n            if (p2[e] < 0 || dfs(p2[e])) {\n                p2[e] = v;\n                p1[v] = e;\n                return true;\n            }\n        }\n        return false;\n    }\n}\n\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF387D {\n\tstatic class A {\n\t\tArrayList<Integer> list = new ArrayList<>();\n\t\tint u, v, d;\n\t}\n\tstatic final int INF = Integer.MAX_VALUE;\n\tstatic boolean bfs(A[] aa, int n) {\n\t\tArrayDeque<Integer> q = new ArrayDeque<>();\n\t\tfor (int u = 1; u <= n; u++)\n\t\t\tif (aa[u].v > 0)\n\t\t\t\taa[u].d = INF;\n\t\t\telse {\n\t\t\t\taa[u].d = 0;\n\t\t\t\tq.addLast(u);\n\t\t\t}\n\t\taa[0].d = INF;\n\t\twhile (!q.isEmpty()) {\n\t\t\tint u = q.removeFirst();\n\t\t\tfor (int v : aa[u].list) {\n\t\t\t\tint w = aa[v].u;\n\t\t\t\tif (aa[w].d == INF) {\n\t\t\t\t\taa[w].d = aa[u].d + 1;\n\t\t\t\t\tif (w == 0)\n\t\t\t\t\t\treturn true;\n\t\t\t\t\tq.addLast(w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tstatic boolean dfs(A[] aa, int n, int u) {\n\t\tif (u == 0)\n\t\t\treturn true;\n\t\tfor (int v : aa[u].list) {\n\t\t\tint w = aa[v].u;\n\t\t\tif (aa[w].d == aa[u].d + 1 && dfs(aa, n, w)) {\n\t\t\t\taa[u].v = v;\n\t\t\t\taa[v].u = u;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\taa[u].d = INF;\n\t\treturn false;\n\t}\n\tstatic int matchings(A[] aa, int n) {\n\t\tint cnt = 0;\n\t\twhile (bfs(aa, n))\n\t\t\tfor (int u = 1; u <= n; u++)\n\t\t\t\tif (aa[u].v == 0 && dfs(aa, n, u))\n\t\t\t\t\tcnt++;\n\t\treturn cnt;\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[] eu = new int[m];\n\t\tint[] ev = new int[m];\n\t\tfor (int j = 0; j < m; j++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\teu[j] = Integer.parseInt(st.nextToken());\n\t\t\tev[j] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tA[] aa = new A[n + 1];\n\t\tint min = m + n * 3;\n\t\tfor (int ctr = 1; ctr <= n; ctr++) {\n\t\t\tboolean loop = false;\n\t\t\tboolean[] ci = new boolean[n + 1];\n\t\t\tboolean[] co = new boolean[n + 1];\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\taa[i] = new A();\n\t\t\tint m_ = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tint u = eu[j];\n\t\t\t\tint v = ev[j];\n\t\t\t\tif (u == ctr && v == ctr)\n\t\t\t\t\tloop = true;\n\t\t\t\telse if (u == ctr && v != ctr)\n\t\t\t\t\tci[v] = true;\n\t\t\t\telse if (u != ctr && v == ctr)\n\t\t\t\t\tco[u] = true;\n\t\t\t\telse {\n\t\t\t\t\taa[u].list.add(v);\n\t\t\t\t\tm_++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint cnt = loop ? 0 : 1;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tif (i != ctr) {\n\t\t\t\t\tif (!ci[i])\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\tif (!co[i])\n\t\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\tint m2 = matchings(aa, n);\n\t\t\tcnt += (m_ - m2) + (n - 1 - m2);\n\t\t\tif (min > cnt)\n\t\t\t\tmin = cnt;\n\t\t}\n\t\tSystem.out.println(min);\n\t}\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R227_2_D {\n    static ArrayList<Integer>[] graph;\n    static int[] right, left;\n    static boolean vis[];\n\n    public static boolean dfs(int node) {\n        if (vis[node])\n            return false;\n        vis[node] = true;\n        for (int i = 0; i < graph[node].size(); i++) {\n            int tmp = graph[node].get(i);\n            if (right[tmp] == -1) {\n                left[node] = tmp;\n                right[tmp] = node;\n                return true;\n            }\n        }\n        for (int i = 0; i < graph[node].size(); i++) {\n            int tmp = graph[node].get(i);\n            if (dfs(right[tmp])) {\n                left[node] = tmp;\n                right[tmp] = node;\n                return true;\n            }\n        }\n        return false;\n    }\n\n    public static int getMaxMatch() {\n        Arrays.fill(left, -1);\n        Arrays.fill(right, -1);\n        boolean done = false;\n        while (!done) {\n            done = true;\n            Arrays.fill(vis, false);\n            for (int i = 0; i < graph.length; i++) {\n                if (left[i] == -1 && dfs(i)) {\n                    done = false;\n                }\n            }\n        }\n        int res = 0;\n        for (int i = 0; i < left.length; i++) {\n            res += (left[i] != -1 ? 1 : 0);\n        }\n        return res;\n    }\n\n    public static void main(String[] args) {\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int V = in.readInt();\n        int E = in.readInt();\n        Point[] edges = new Point[E];\n        for (int i = 0; i < edges.length; i++) {\n            edges[i] = new Point(in.readInt() - 1, in.readInt() - 1);\n        }\n        int best = Integer.MAX_VALUE;\n        for (int k = 0; k < V; k++) {\n            int n = V - 1;\n            graph = new ArrayList[n];\n            left = new int[n];\n            vis = new boolean[n];\n            right = new int[n];\n            for (int i = 0; i < graph.length; i++) {\n                graph[i] = new ArrayList<Integer>();\n            }\n            int center = 0;\n            for (int i = 0; i < E; i++) {\n                if (edges[i].x == k || edges[i].y == k) {\n                    center++;\n                    continue;\n                }\n                int src = edges[i].x > k ? edges[i].x - 1 : edges[i].x;\n                int dst = edges[i].y > k ? edges[i].y - 1 : edges[i].y;\n                graph[src].add(dst);\n            }\n            int matching = getMaxMatch();\n            int addToCenterEdges = 2 * V - 1 - center;\n            int removed = E - center - matching;\n            int added = n - matching;\n            best = Math.min(best, added + removed + addToCenterEdges);\n        }\n        System.out.println(best);\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", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF387D {\n\tstatic class A {\n\t\tArrayList<Integer> list = new ArrayList<>();\n\t\tint u, v, d;\n\t}\n\tstatic int INF = Integer.MAX_VALUE;\n\tstatic boolean bfs(A[] aa, int n) {\n\t\tLinkedList<Integer> q = new LinkedList<>();\n\t\tfor (int u = 1; u <= n; u++)\n\t\t\tif (aa[u].v > 0)\n\t\t\t\taa[u].d = INF;\n\t\t\telse {\n\t\t\t\taa[u].d = 0;\n\t\t\t\tq.addLast(u);\n\t\t\t}\n\t\taa[0].d = INF;\n\t\twhile (!q.isEmpty()) {\n\t\t\tint u = q.removeFirst();\n\t\t\tfor (int v : aa[u].list) {\n\t\t\t\tint w = aa[v].u;\n\t\t\t\tif (aa[w].d == INF) {\n\t\t\t\t\taa[w].d = aa[u].d + 1;\n\t\t\t\t\tif (w == 0)\n\t\t\t\t\t\treturn true;\n\t\t\t\t\tq.addLast(w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tstatic boolean dfs(A[] aa, int n, int u) {\n\t\tif (u == 0)\n\t\t\treturn true;\n\t\tfor (int v : aa[u].list) {\n\t\t\tint w = aa[v].u;\n\t\t\tif (aa[w].d == aa[u].d + 1 && dfs(aa, n, w)) {\n\t\t\t\taa[u].v = v;\n\t\t\t\taa[v].u = u;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\taa[u].d = INF;\n\t\treturn false;\n\t}\n\tstatic int matchings(A[] aa, int n) {\n\t\tint cnt = 0;\n\t\twhile (bfs(aa, n))\n\t\t\tfor (int u = 1; u <= n; u++)\n\t\t\t\tif (aa[u].v == 0 && dfs(aa, n, u))\n\t\t\t\t\tcnt++;\n\t\treturn cnt;\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[] eu = new int[m];\n\t\tint[] ev = new int[m];\n\t\tfor (int j = 0; j < m; j++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\teu[j] = Integer.parseInt(st.nextToken());\n\t\t\tev[j] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tA[] aa = new A[n + 1];\n\t\tint min = m + n * 3;\n\t\tfor (int ctr = 1; ctr <= n; ctr++) {\n\t\t\tboolean loop = false;\n\t\t\tboolean[] ci = new boolean[n + 1];\n\t\t\tboolean[] co = new boolean[n + 1];\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\taa[i] = new A();\n\t\t\tint m_ = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tint u = eu[j];\n\t\t\t\tint v = ev[j];\n\t\t\t\tif (u == ctr && v == ctr)\n\t\t\t\t\tloop = true;\n\t\t\t\telse if (u == ctr && v != ctr)\n\t\t\t\t\tci[v] = true;\n\t\t\t\telse if (u != ctr && v == ctr)\n\t\t\t\t\tco[u] = true;\n\t\t\t\telse {\n\t\t\t\t\taa[u].list.add(v);\n\t\t\t\t\tm_++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint cnt = loop ? 0 : 1;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tif (i != ctr) {\n\t\t\t\t\tif (!ci[i])\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\tif (!co[i])\n\t\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\tint m2 = matchings(aa, n);\n\t\t\tcnt += (m_ - m2) + (n - 1 - m2);\n\t\t\tif (min > cnt)\n\t\t\t\tmin = cnt;\n\t\t}\n\t\tSystem.out.println(min);\n\t}\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\n\npublic class GeorgeAndInterestingGraph {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        \n        int N = sc.nextInt();\n        int M = sc.nextInt();\n        \n        int[] edgeFrom = new int[M];\n        int[] edgeTo = new int[M];\n        for (int i = 0; i < M; i++) {\n        \tedgeFrom[i] = sc.nextInt();\n        \tedgeTo[i] = sc.nextInt();\n        }\n        \n        int best = Integer.MAX_VALUE;\n    \tboolean[][] adjMat = makeAdjMat(N, edgeFrom, edgeTo);\n        for (int i = 0; i < N; i++) {\n        \tboolean[][] mat = copyOfArray2d(adjMat);\n        \tbest = Math.min(best, count(mat, M, i));\n        }\n        \n        System.out.println(best);\n    }\n    \n    public static boolean[][] copyOfArray2d(boolean[][] arr) {\n    \tint N = arr.length;\n    \tint M = arr[0].length;\n    \tboolean[][] copy = new boolean[N][M];\n    \tfor (int i = 0; i < N; i++) {\n    \t\tSystem.arraycopy(arr[i], 0, copy[i], 0, M);\n    \t}\n    \treturn copy;\n    }\n    \n    public static int count(boolean[][] mat, int M, int center) {\n//    \tint N = mat.length;\n//    \tint M = mat[0].length;\n//\n//    \tint centerConnect = (mat[center][center]) ? 0 : 1;\n//    \tfor (int i = 0; i < N; i++) {\n//\t\t\tif (i != center) {\n//\t\t\t\tif (!mat[i][center]) {\n//\t\t\t\t\tcenterConnect++;\n//\t\t\t\t}\n//\t\t\t\tif (!mat[center][i]) {\n//\t\t\t\t\tcenterConnect++;\n//\t\t\t\t}\n//\t\t\t}\n//\t    \tmat[i][center] = false;\n//\t    \tmat[center][i] = false;\n//\t\t}\n//    \t\n//    \tint[][] adjMat = new int[2 * N + 2][2 * N + 2];\n//    \tfor (int i = 0; i < N; i++) {\n//    \t\tfor (int j = 0; j < N; j++) {\n//    \t\t\tint idx = N + j;\n//    \t\t\tadjMat[i][idx] = (mat[i][j]) ? 1 : 0;\n//    \t\t}\n//    \t}\n//    \tint s = 2 * N;\n//    \tint t = 2 * N + 1;\n//    \tfor (int i = 0; i < N; i++) {\n//    \t\tadjMat[s][i] = 1;\n//    \t}\n//    \tfor (int i = N; i < 2 * N; i++) {\n//    \t\tadjMat[i][t] = 1;\n//    \t}\n//    \t\n//    \tint matches = fordFulkerson(adjMat, s, t);\n//    \t\n//    \treturn centerConnect + matches;\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \tint N = mat.length;\n//    \tint M = mat[0].length;\n    \t\n    \tint cntWithI = (mat[center][center]) ? 1 : 0;\n    \tfor (int i = 0; i < N; i++) {\n    \t\tif (i != center) {\n    \t\t\tif (mat[i][center]) {\n    \t\t\t\tcntWithI++;\n    \t\t\t}\n    \t\t\tif (mat[center][i]) {\n    \t\t\t\tcntWithI++;\n    \t\t\t}\n    \t\t}\n        \tmat[i][center] = false;\n        \tmat[center][i] = false;\n    \t}\n    \t\n    \tint other = M - cntWithI;\n    \t\n//    \tint centerConnect = (mat[center][center]) ? 0 : 1;\n//    \t\n//    \tfor (int i = 0; i < N; i++) {\n//    \t\tif (i != center) {\n//    \t\t\tif (!mat[i][center]) {\n//    \t\t\t\tcenterConnect++;\n//    \t\t\t}\n//    \t\t\tif (!mat[center][i]) {\n//    \t\t\t\tcenterConnect++;\n//    \t\t\t}\n//    \t\t}\n//        \tmat[i][center] = false;\n//        \tmat[center][i] = false;\n//    \t}\n    \t\n    \tint matches = bipartiteMatching(mat);\n    \t\n    \treturn (2 * N - 1 - cntWithI + other - matches + N - 1 - matches);\n//    \treturn (centerConnect + N - 1 - matches);\n    }\n    \n    public static boolean[][] makeAdjMat(int N, int[] edgeFrom, int[] edgeTo) {\n    \tboolean[][] mat = new boolean[N][N];\n    \tfor (int i = 0; i < edgeFrom.length; i++) {\n    \t\tint from = edgeFrom[i] - 1;\n    \t\tint to = edgeTo[i] - 1;\n    \t\tmat[from][to] = true;\n    \t}\n    \treturn mat;\n    }\n    \n    /**\n     * Returns true if there is a path from the source 's' to the sink 't' in the residual graph.\n     * Also fills parent[] to store the path.\n     * See here for more info:  http://www.geeksforgeeks.org/ford-fulkerson-algorithm-for-maximum-flow-problem/\n     */\n    public static boolean fordFulkersonHelper(int[][] resid, int s, int t, int[] parent) {\n    \tint V = resid.length;\n    \tboolean[] visited = new boolean[V];\n    \tLinkedList<Integer> q = new LinkedList<Integer>();\n    \tq.push(s);\n    \tvisited[s] = true;\n    \tparent[s] = -1;\n    \t\n    \twhile (!q.isEmpty()) {\n    \t\tint u = q.pop();\n    \t\tfor (int v = 0; v < V; v++) {\n    \t\t\tif (!visited[v] && resid[u][v] > 0) {\n    \t\t\t\tq.push(v);\n    \t\t\t\tparent[v] = u;\n    \t\t\t\tvisited[v] = true;\n    \t\t\t}\n    \t\t}\n    \t}\n    \t\n    \treturn visited[t];\n    }\n    \n    /**\n     * Returns the maximum flow from 's' to 't' in the given graph.\n     * See here for more info:  http://www.geeksforgeeks.org/ford-fulkerson-algorithm-for-maximum-flow-problem/\n     */\n    public static int fordFulkerson(int[][] graph, int s, int t) {\n    \tint V = graph.length;\n    \tint[][] resid = new int[V][V];\n    \tint[] parent = new int[V];\n    \tint maxFlow = 0;\n    \t\n    \tfor (int u = 0; u < V; u++) {\n    \t\tfor (int v = 0; v < V; v++) {\n    \t\t\tresid[u][v] = graph[u][v];\n    \t\t}\n    \t}\n    \t\n    \twhile (fordFulkersonHelper(resid, s, t, parent)) {\n    \t\tint pathFlow = Integer.MAX_VALUE;\n    \t\tfor (int v = t; v != s; v = parent[v]) {\n    \t\t\tint u = parent[v];\n    \t\t\tpathFlow = Math.min(pathFlow,  resid[u][v]);\n    \t\t}\n    \t\tfor (int v = t; v != s; v = parent[v]) {\n    \t\t\tint u = parent[v];\n    \t\t\tresid[u][v] -= pathFlow;\n    \t\t\tresid[v][u] += pathFlow;\n    \t\t}\n    \t\tmaxFlow += pathFlow;\n    \t}\n    \t\n    \treturn maxFlow;\n    }\n    \n    /**\n     * Returns true if a matching for vertex 'u' is possible.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static boolean bipartiteMatchingHelper(boolean[][] bpGraph, int u, boolean[] seen, int[] matchR) {\n    \tint N = bpGraph[0].length;\n    \tfor (int v = 0; v < N; v++) {\n    \t\tif (bpGraph[u][v] && !seen[v]) {\n    \t\t\tseen[v] = true;\n    \t\t\tif (matchR[v] < 0 || bipartiteMatchingHelper(bpGraph, matchR[v], seen, matchR)) {\n    \t\t\t\tmatchR[v] = u;\n    \t\t\t\treturn true;\n    \t\t\t}\n    \t\t}\n    \t}\n    \treturn false;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchIJ, int[] matchJI) {\n    \tint ans = bipartiteMatching(bpGraph, matchJI);\n    \t\n    \tfor (int i = 0; i < matchJI.length; i++) {\n    \t\tmatchIJ[i] = -1;\n    \t}\n    \t\n    \tfor (int j = 0; j < matchJI.length; j++) {\n    \t\tint i = matchJI[j];\n    \t\tif (i >= 0) {\n    \t\t\tmatchIJ[i] = j;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchJI) {\n    \tint M = bpGraph.length;\n    \tint N = bpGraph[0].length;\n    \t\n    \tfor (int i = 0; i < N; i++) {\n    \t\tmatchJI[i] = -1;\n    \t}\n    \t\n    \tint ans = 0;\n    \tfor (int u = 0; u < M; u++) {\n    \t\tboolean[] seen = new boolean[N];\n    \t\tif (bipartiteMatchingHelper(bpGraph, u, seen, matchJI)) {\n    \t\t\tans++;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Overload of the bipartiteMatching function without output parameters.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph) {\n    \tint N = bpGraph[0].length;\n    \tint[] matchJI = new int[N];\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n    \n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     */\n    public static int bipartiteMatching(int[][] intGraph) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchIJ, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchIJ, matchJI);\n    }\n    \n    /**\n     * Converts an integer adjacency matrix of 1's and 0's to a boolean adjacency matrix.\n     * Useful with bipartiteMatching, which takes adjancency matrix of boolean[][] as input (instead of int[][]).\n     */\n    public static boolean[][] intToBooleanAdjMat(int[][] mat) {\n    \tint M = mat.length;\n    \tint N = mat[0].length;\n    \tboolean[][] bMat = new boolean[M][N];\n    \tfor (int i = 0; i < M; i++) {\n    \t\tfor (int j = 0; j < N; j++) {\n    \t\t\tbMat[i][j] = (mat[i][j] != 0);\n    \t\t}\n    \t}\n    \treturn bMat;\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        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 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        String nextLine() {\n            String str = \"\";\n            try { str = br.readLine(); }\n            catch (IOException e) { e.printStackTrace(); }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Scanner;\n\n\n\npublic class Main {\n    \n    static ArrayList<Edge> graph;\n    static ArrayList<ArrayList<Integer>> graphForKuhn;\n    static int n, m, u = 0;\n    static int mt[];\n    static int used[];\n\n    public static void main(String[] args) {\n        formGraph();\n        System.out.println(getAnswer()); \n    }\n    \n    static boolean kuhn(int start) {\n        if (used[start] == u)\n            return false;\n        used[start] = u;\n        for (int i=0; i< graphForKuhn.get(start).size(); i++) {\n            int to = graphForKuhn.get(start).get(i);\n            if (mt[to] == -1 || kuhn(mt[to])) {\n                mt[to] = start;\n                return true;\n            }\n        }\n        return false;\n    }\n\n    private static int getAnswer() {\n        int currentAnswer = Integer.MAX_VALUE;\n        for (int cur= 0; cur<n; cur++) {\n            int adj = 0, otheradj = 0, answer = 0;\n            for (int j=0; j<n; j++) {\n                graphForKuhn.get(j).clear();\n                mt[j] = -1;\n            }\n            for (int j=0; j<m; j++) {\n                if (graph.get(j).from == cur || graph.get(j).to == cur)\n                    adj++;\n                else {\n                    graphForKuhn.get(graph.get(j).from).add(graph.get(j).to);\n                    otheradj++;\n                }\n            }\n            for (int j=0; j<n; j++) {\n                u++;\n                kuhn(j);\n            }\n            int tsz = 0;\n            for (int j=0; j<n; j++) {\n                if (mt[j] != -1)\n                    tsz++;\n            }\n            answer = 2*(n-1)+1-adj+otheradj-2*tsz+(n-1);\n            currentAnswer = Math.min(answer, currentAnswer);\n        }\n        return currentAnswer;\n    }\n\n    private static void formGraph() {\n        Scanner in = new Scanner(System.in);\n        n = in.nextInt();\n        m = in.nextInt();\n        graph = new ArrayList<Edge>(m);\n        for (int i=0; i<m; i++) {\n            int x = in.nextInt();\n            int y = in.nextInt();\n            graph.add(new Edge(x-1, y-1));\n        }\n        graphForKuhn = new ArrayList<ArrayList<Integer>>(n);\n        for (int i=0; i<n; i++) graphForKuhn.add(new ArrayList<Integer>(n));\n        mt = new int[n];\n        used = new int[n];\n        in.close();\n    }\n\n    \n}\n\nclass Edge {\n    int from;\n    int to;\n    \n    public Edge(int from, int to) {\n        this.from = from;\n        this.to = to;\n    }\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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\n/**\n * @author Don Li\n */\npublic class GeorgeInterestingGraph {\n    \n    int N = 505;\n    int INF = (int) 1e9;\n    \n    List<Integer>[] G = new List[N];\n    int[] match = new int[N];\n    int[] used = new int[N];\n    int cur = 0;\n    \n    {\n        for (int i = 0; i < N; i++) G[i] = new ArrayList<>(1);\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() - 1;\n            to[i] = in.nextInt() - 1;\n        }\n        \n        int ans = INF;\n        for (int i = 0; i < n; i++) {\n            int cnt = 0;\n            for (int j = 0; j < n; j++) {\n                G[j].clear();\n                match[j] = -1;\n            }\n            for (int j = 0; j < m; j++) {\n                if (fr[j] == i || to[j] == i) {\n                    cnt++;\n                } else {\n                    G[fr[j]].add(to[j]);\n                }\n            }\n            \n            int other = m - cnt;\n            \n            int max = 0;\n            for (int j = 0; j < n; j++) {\n                cur++;\n                if (augment(j)) max++;\n            }\n            \n            ans = Math.min(ans, 2 * (n - 1) + 1 - cnt + other - max + (n - 1) - max);\n        }\n        out.println(ans);\n    }\n    \n    boolean augment(int u) {\n        if (used[u] == cur) return false;\n        used[u] = cur;\n        for (int v : G[u]) {\n            if (match[v] < 0 || augment(match[v])) {\n                match[v] = u;\n                return true;\n            }\n        }\n        return 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 GeorgeInterestingGraph().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", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class D {\t\n\tBufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter out;\n    \n\tpublic void solve() throws IOException {\t\t\t\t\n\t\tint N = nextInt();\n\t\tint M = nextInt();\n\t\tboolean[][] graph = new boolean[N][N];\n\t\tfor (int i = 0; i < M; i++) {\n\t\t\tgraph[nextInt()-1][nextInt()-1] = true;\n\t\t}\t\t\n\t\t\n\t\tint best = Integer.MAX_VALUE;\n\t\tfor (int c = 0; c < N; c++) {\n\t\t\tint withC = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tif (i == c) {\n\t\t\t\t\tif (graph[c][i]) withC++;\n\t\t\t\t} else {\n\t\t\t\t\tif (graph[c][i]) withC++;\n\t\t\t\t\tif (graph[i][c]) withC++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint notC = M - withC;\n\t\t\t\n\t\t\tList<Integer>[] g = new List[N];\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tg[i] = new ArrayList<Integer>();\n\t\t\t}\t\t\t\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tif (i == c) continue;\n\t\t\t\tfor (int j = 0; j < N; j++) {\n\t\t\t\t\tif (j == c) continue;\n\t\t\t\t\tif (!graph[i][j]) continue;\n\t\t\t\t\tg[i].add(j);\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tint glen = maxMatching(g, N);\n\t\t\t\n//\t\t\tint src = 2*N;\n//\t\t\tint dst = 2*N+1;\n//\t\t\tint[][] cap  = new int[2*N+2][2*N+2];\n//\t\t\tint[][] cost = new int[2*N+2][2*N+2];\n//\t\t\tfor (int i = 0; i < N; i++) {\n//\t\t\t\tcap[src][i] = 1;\n//\t\t\t\tcost[src][i] = 1;\n//\t\t\t\tcap[N+i][dst] = 1;\n//\t\t\t\tcost[N+i][dst] = 1;\n//\t\t\t}\n//\t\t\tfor (int i = 0; i < N; i++) {\n//\t\t\t\tif (i == c) continue;\n//\t\t\t\tfor (int j = 0; j < N; j++) {\n//\t\t\t\t\tif (j == c) continue;\n//\t\t\t\t\tif (!graph[i][j]) continue;\t\t\t\t\t\n//\t\t\t\t\tcap[i][N+j] = 1;\n//\t\t\t\t\tcost[i][N+j] = 1;\t\t\t\t\t\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tMinCostMaxFlow flow = new MinCostMaxFlow();\n//\t\t\tint result[] = flow.getMaxFlow(cap, cost, src, dst);\n//\t\t\tint glen = result[0];\n\t\t\t\n\t\t\tint need = (2*N-1 - withC) + (notC - glen) + (N - 1 - glen);\n\t\t\tbest = Math.min(best, need);\n\t\t}\n\t\tout.println(best);\n\t}\n\t\n\tstatic boolean findPath(List<Integer>[] g, int u1, int[] matching, boolean[] vis) {\n\t    vis[u1] = true;\n\t    for (int v : g[u1]) {\n\t      int u2 = matching[v];\n\t      if (u2 == -1 || !vis[u2] && findPath(g, u2, matching, vis)) {\n\t        matching[v] = u1;\n\t        return true;\n\t      }\n\t    }\n\t    return false;\n\t  }\n\n\t  public static int maxMatching(List<Integer>[] g, int n2) {\n\t    int n1 = g.length;\n\t    int[] matching = new int[n2];\n\t    Arrays.fill(matching, -1);\n\t    int matches = 0;\n\t    for (int u = 0; u < n1; u++) {\n\t      if (findPath(g, u, matching, new boolean[n1]))\n\t        ++matches;\n\t    }\n\t    return matches;\n\t  }\n\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew D().run();\n\t}\n\t\n\tpublic void run() {\n        try {\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        } 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}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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\n/**\n * @author Don Li\n */\npublic class GeorgeInterestingGraph {\n    \n    int N = 505;\n    int INF = (int) 1e9;\n    \n    List<Integer>[] G = new List[N];\n    int[] match = new int[N];\n    int[] used = new int[N];\n    int cur = 0;\n    \n    {\n        for (int i = 0; i < N; i++) G[i] = new ArrayList<>(1);\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() - 1;\n            to[i] = in.nextInt() - 1;\n        }\n        \n        int ans = INF;\n        for (int i = 0; i < n; i++) {\n            int cnt = 0;\n            for (int j = 0; j < n; j++) {\n                G[j].clear();\n                match[j] = -1;\n            }\n            for (int j = 0; j < m; j++) {\n                if (fr[j] == i || to[j] == i) {\n                    cnt++;\n                } else {\n                    G[fr[j]].add(to[j]);\n                }\n            }\n            \n            int other = m - cnt;\n            \n            int max = 0;\n            for (int j = 0; j < n; j++) {\n                cur++;\n                augment(j);\n            }\n            for (int j = 0; j < n; j++) if (match[j] >= 0) max++;\n            \n            ans = Math.min(ans, 2 * (n - 1) + 1 - cnt + other - max + (n - 1) - max);\n        }\n        out.println(ans);\n    }\n    \n    boolean augment(int u) {\n        if (used[u] == cur) return false;\n        used[u] = cur;\n        for (int v : G[u]) {\n            if (match[v] < 0 || augment(match[v])) {\n                match[v] = u;\n                return true;\n            }\n        }\n        return 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 GeorgeInterestingGraph().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", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "//Author: net12k44\nimport java.io.*;\nimport java.util.*;\npublic\nclass Main{//}\n\t\nstatic PrintWriter out;\n\nstatic int c[][];\nstatic int x[] , y[] , n;\nstatic int degIn[];\nstatic ArrayList< ArrayList<Integer> >a = new ArrayList< ArrayList<Integer> >();\nstatic int cnt = 0;\nstatic boolean b[];\n\nprivate static boolean dfs(int i) {\n\tif (i == -1) return true;\n\tif (b[i]) return false;\n\tb[i] = true;\n\tfor(Integer j : a.get(i) ) \n\t\tif ( dfs( y[j] ) ) {\n\t\t\tx[i] = j;\n\t\t\ty[j] = i;\n\t\t\treturn true;\n\t\t}\n\treturn false;\n}\n\nprivate static void find(int k) {\n\tint _cnt = -1;\n\tif (k>=0) { x[k] = k; y[k] = k; }\n\twhile (_cnt != cnt) {\n\t\t_cnt = cnt;\n\t\tArrays.fill( b , false );\n\t\tif (k>=0) b[k] = true;\n\t\tfor(int i = 0; i < n; ++i)\n\t\t   if (x[i] == -1 && dfs(i) ) ++cnt;\n\t}\n\tif (k>=0) { x[k] = -1; y[k] = -1; }\n\n}\n\npublic static void solve() {\n\tn = in.nextInt();\n\tint m = in.nextInt();\n\t\n\tb = new boolean[n]; c = new int [n][n];\n\tdegIn = new int[n]; x = new int[n]; y = new int[n];\t\n\tArrays.fill(x , -1); Arrays.fill(y , -1);\n\tfor(int i = 0; i < n; ++i) a. add( new ArrayList< Integer > () );\n\t\n\twhile (m-- > 0) {\n\t\tint i = in.nextInt()-1 , j = in.nextInt()-1;\n\t\ta.get(i).add(j);\n\t\tdegIn[j]++;\n\t\tc[i][j] = 1;\n\t}\n\t\n\tfind(-1);\n\tint kq = Integer.MAX_VALUE;\n\t\n\tfor(int k = 0; k < n; ++k) {\n\t\tif (x[k] != -1) {y[ x[k] ] = -1; x[k] = -1; cnt--; }\n\t\tif (y[k] != -1) {x[ y[k] ] = -1; y[k] = -1; cnt--; }\n\t\tfind(k);\n\t\t\n\t\tint t = n*2 - 1 - a.get(k).size() - degIn[k] + c[k][k];\n\t\tfor(int i = 0; i < n; ++i)\n\t\t if (i!=k) \n\t\t\tt = t + a.get(i).size() - c[i][k];\t\t\n\t\tt = t - cnt + (n-1) - cnt;\n\t\tif (kq > t) kq = t;\t\t\n\t}\n\tout.println(kq);\n\t\n}\n\t\npublic static void main (String[] args) throws java.lang.Exception {\t\t\n\tlong startTime = System.currentTimeMillis();\n\n\tout = new PrintWriter(System.out);\n\tsolve();\t\n\t//out.println((String.format(\"%.2f\",(double)(System.currentTimeMillis()-startTime)/1000)));\n\tout.close();\n}\n\t\nstatic class in {\n\tstatic BufferedReader reader = new BufferedReader( new InputStreamReader(System.in) ) ;\n\tstatic StringTokenizer tokenizer = new StringTokenizer(\"\");\t\t\t\t\n\tstatic String next() {\t\t\n\t\twhile ( !tokenizer.hasMoreTokens() )\n\t\t\ttry { tokenizer = new StringTokenizer( reader.readLine() ); }\n\t\t\tcatch (IOException e){\n\t\t\t\tthrow new RuntimeException(e);\t\t\t\n\t\t\t}\t\t\n\t\treturn tokenizer.nextToken();\n\t}\n\tstatic int nextInt() { return Integer.parseInt( next() ); }\t\t\n\tstatic double nextDouble(){ return Double.parseDouble( next() ); }\n}\n//////////////////////////////////////////////////\n}//", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\npublic class GeorgeAndInterestingGraph {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        \n        int N = sc.nextInt();\n        int M = sc.nextInt();\n        \n        int[] edgeFrom = new int[M];\n        int[] edgeTo = new int[M];\n        for (int i = 0; i < M; i++) {\n        \tedgeFrom[i] = sc.nextInt();\n        \tedgeTo[i] = sc.nextInt();\n        }\n        \n        int best = Integer.MAX_VALUE;\n        for (int i = 0; i < N; i++) {\n        \tboolean[][] mat = makeAdjMat(N, edgeFrom, edgeTo);\n        \tbest = Math.min(best, count(mat, M, i));\n        }\n        \n        System.out.println(best);\n    }\n    \n    public static int count(boolean[][] mat, int M, int center) {\n    \tint N = mat.length;\n    \t\n    \tint centerCount = (mat[center][center]) ? 1 : 0;\n    \tfor (int i = 0; i < N; i++) {\n    \t\tif (i != center) {\n    \t\t\tif (mat[i][center]) {\n    \t\t\t\tcenterCount++;\n    \t\t\t}\n    \t\t\tif (mat[center][i]) {\n    \t\t\t\tcenterCount++;\n    \t\t\t}\n    \t\t}\n        \tmat[i][center] = false;\n        \tmat[center][i] = false;\n    \t}\n    \tint other = M - centerCount;\n    \t\n    \tint matches = bipartiteMatching(mat);\n    \t\n    \treturn (2 * N - 1 - centerCount + other - matches + N - 1 - matches);\n    }\n    \n    public static boolean[][] makeAdjMat(int N, int[] edgeFrom, int[] edgeTo) {\n    \tboolean[][] mat = new boolean[N][N];\n    \tfor (int i = 0; i < edgeFrom.length; i++) {\n    \t\tint from = edgeFrom[i] - 1;\n    \t\tint to = edgeTo[i] - 1;\n    \t\tmat[from][to] = true;\n    \t}\n    \treturn mat;\n    }\n    \n    /**\n     * Returns true if a matching for vertex 'u' is possible.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static boolean bipartiteMatchingHelper(boolean[][] bpGraph, int u, boolean[] seen, int[] matchR) {\n    \tint N = bpGraph[0].length;\n    \tfor (int v = 0; v < N; v++) {\n    \t\tif (bpGraph[u][v] && !seen[v]) {\n    \t\t\tseen[v] = true;\n    \t\t\tif (matchR[v] < 0 || bipartiteMatchingHelper(bpGraph, matchR[v], seen, matchR)) {\n    \t\t\t\tmatchR[v] = u;\n    \t\t\t\treturn true;\n    \t\t\t}\n    \t\t}\n    \t}\n    \treturn false;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchIJ, int[] matchJI) {\n    \tint ans = bipartiteMatching(bpGraph, matchJI);\n    \t\n    \tfor (int i = 0; i < matchJI.length; i++) {\n    \t\tmatchIJ[i] = -1;\n    \t}\n    \t\n    \tfor (int j = 0; j < matchJI.length; j++) {\n    \t\tint i = matchJI[j];\n    \t\tif (i >= 0) {\n    \t\t\tmatchIJ[i] = j;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchJI) {\n    \tint M = bpGraph.length;\n    \tint N = bpGraph[0].length;\n    \t\n    \tfor (int i = 0; i < N; i++) {\n    \t\tmatchJI[i] = -1;\n    \t}\n    \t\n    \tint ans = 0;\n    \tfor (int u = 0; u < M; u++) {\n    \t\tboolean[] seen = new boolean[N];\n    \t\tif (bipartiteMatchingHelper(bpGraph, u, seen, matchJI)) {\n    \t\t\tans++;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Overload of the bipartiteMatching function without output parameters.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph) {\n    \tint N = bpGraph[0].length;\n    \tint[] matchJI = new int[N];\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n    \n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     */\n    public static int bipartiteMatching(int[][] intGraph) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchIJ, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchIJ, matchJI);\n    }\n    \n    /**\n     * Converts an integer adjacency matrix of 1's and 0's to a boolean adjacency matrix.\n     * Useful with bipartiteMatching, which takes adjancency matrix of boolean[][] as input (instead of int[][]).\n     */\n    public static boolean[][] intToBooleanAdjMat(int[][] mat) {\n    \tint M = mat.length;\n    \tint N = mat[0].length;\n    \tboolean[][] bMat = new boolean[M][N];\n    \tfor (int i = 0; i < M; i++) {\n    \t\tfor (int j = 0; j < N; j++) {\n    \t\t\tbMat[i][j] = (mat[i][j] != 0);\n    \t\t}\n    \t}\n    \treturn bMat;\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        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 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        String nextLine() {\n            String str = \"\";\n            try { str = br.readLine(); }\n            catch (IOException e) { e.printStackTrace(); }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\npublic class GeorgeAndInterestingGraph {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        \n        int N = sc.nextInt();\n        int M = sc.nextInt();\n        \n        int[] edgeFrom = new int[M];\n        int[] edgeTo = new int[M];\n        for (int i = 0; i < M; i++) {\n        \tedgeFrom[i] = sc.nextInt();\n        \tedgeTo[i] = sc.nextInt();\n        }\n        \n        int best = Integer.MAX_VALUE;\n    \tboolean[][] adjMat = makeAdjMat(N, edgeFrom, edgeTo);\n        for (int i = 0; i < N; i++) {\n        \tboolean[][] mat = copyOfArray2d(adjMat);\n        \tbest = Math.min(best, count(mat, M, i));\n        }\n        \n        System.out.println(best);\n    }\n    \n    public static boolean[][] copyOfArray2d(boolean[][] arr) {\n    \tint N = arr.length;\n    \tint M = arr[0].length;\n    \tboolean[][] copy = new boolean[N][M];\n    \tfor (int i = 0; i < N; i++) {\n    \t\tSystem.arraycopy(arr[i], 0, copy[i], 0, M);\n    \t}\n    \treturn copy;\n    }\n    \n    public static int count(boolean[][] mat, int M, int center) {\n    \tint N = mat.length;\n    \t\n    \tint centerCount = (mat[center][center]) ? 1 : 0;\n    \tfor (int i = 0; i < N; i++) {\n    \t\tif (i != center) {\n    \t\t\tif (mat[i][center]) {\n    \t\t\t\tcenterCount++;\n    \t\t\t}\n    \t\t\tif (mat[center][i]) {\n    \t\t\t\tcenterCount++;\n    \t\t\t}\n    \t\t}\n        \tmat[i][center] = false;\n        \tmat[center][i] = false;\n    \t}\n    \tint other = M - centerCount;\n    \t\n    \tint matches = bipartiteMatching(mat);\n    \t\n    \treturn (2 * N - 1 - centerCount + other - matches + N - 1 - matches);\n    }\n    \n    public static boolean[][] makeAdjMat(int N, int[] edgeFrom, int[] edgeTo) {\n    \tboolean[][] mat = new boolean[N][N];\n    \tfor (int i = 0; i < edgeFrom.length; i++) {\n    \t\tint from = edgeFrom[i] - 1;\n    \t\tint to = edgeTo[i] - 1;\n    \t\tmat[from][to] = true;\n    \t}\n    \treturn mat;\n    }\n    \n    /**\n     * Returns true if a matching for vertex 'u' is possible.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static boolean bipartiteMatchingHelper(boolean[][] bpGraph, int u, boolean[] seen, int[] matchR) {\n    \tint N = bpGraph[0].length;\n    \tfor (int v = 0; v < N; v++) {\n    \t\tif (bpGraph[u][v] && !seen[v]) {\n    \t\t\tseen[v] = true;\n    \t\t\tif (matchR[v] < 0 || bipartiteMatchingHelper(bpGraph, matchR[v], seen, matchR)) {\n    \t\t\t\tmatchR[v] = u;\n    \t\t\t\treturn true;\n    \t\t\t}\n    \t\t}\n    \t}\n    \treturn false;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchIJ, int[] matchJI) {\n    \tint ans = bipartiteMatching(bpGraph, matchJI);\n    \t\n    \tfor (int i = 0; i < matchJI.length; i++) {\n    \t\tmatchIJ[i] = -1;\n    \t}\n    \t\n    \tfor (int j = 0; j < matchJI.length; j++) {\n    \t\tint i = matchJI[j];\n    \t\tif (i >= 0) {\n    \t\t\tmatchIJ[i] = j;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchJI) {\n    \tint M = bpGraph.length;\n    \tint N = bpGraph[0].length;\n    \t\n    \tfor (int i = 0; i < N; i++) {\n    \t\tmatchJI[i] = -1;\n    \t}\n    \t\n    \tint ans = 0;\n    \tfor (int u = 0; u < M; u++) {\n    \t\tboolean[] seen = new boolean[N];\n    \t\tif (bipartiteMatchingHelper(bpGraph, u, seen, matchJI)) {\n    \t\t\tans++;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Overload of the bipartiteMatching function without output parameters.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph) {\n    \tint N = bpGraph[0].length;\n    \tint[] matchJI = new int[N];\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n    \n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     */\n    public static int bipartiteMatching(int[][] intGraph) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchIJ, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchIJ, matchJI);\n    }\n    \n    /**\n     * Converts an integer adjacency matrix of 1's and 0's to a boolean adjacency matrix.\n     * Useful with bipartiteMatching, which takes adjancency matrix of boolean[][] as input (instead of int[][]).\n     */\n    public static boolean[][] intToBooleanAdjMat(int[][] mat) {\n    \tint M = mat.length;\n    \tint N = mat[0].length;\n    \tboolean[][] bMat = new boolean[M][N];\n    \tfor (int i = 0; i < M; i++) {\n    \t\tfor (int j = 0; j < N; j++) {\n    \t\t\tbMat[i][j] = (mat[i][j] != 0);\n    \t\t}\n    \t}\n    \treturn bMat;\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        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 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        String nextLine() {\n            String str = \"\";\n            try { str = br.readLine(); }\n            catch (IOException e) { e.printStackTrace(); }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "//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    final int MOD = 1000 * 1000 * 1000 + 7;\n    int sum(int a, int b) {\n        a += b;\n        return a >= MOD ? a - MOD : a;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    void solve() throws IOException {\n        final int n = nextInt();\n        int m = nextInt();\n        int[] from = new int[m];\n        int[] to = new int[m];\n        for(int i = 0; i < m; i++) {\n            from[i] = nextInt();\n            to[i] = nextInt();\n        }\n        int ans = solve(n, m, from, to);\n        writer.println(ans);\n        writer.close();\n    }\n\n    private int solve(final int n, int m, int[] from, int[] to) {\n        final List<List<Integer>> g = new ArrayList<>();\n        final List<List<Integer>> rg = new ArrayList<>();\n        for(int i = 0; i <= n; i++) {\n            g.add(new ArrayList<Integer>());\n            rg.add(new ArrayList<Integer>());\n        }\n        int[] c = new int[n + 1];\n        int[] loop = new int[n + 1];\n        for(int i = 0; i < m; i++) {\n            int u = from[i];\n            int v = to[i];\n            g.get(u).add(v);\n            rg.get(v).add(u);\n            c[u]++;\n            c[v]++;\n            if(u == v) {\n                loop[u]++;\n            }\n        }\n        class Utils {\n            int[] prev = new int[n + 1];\n            int[] next = new int[n + 1];\n            int[] used = new int[n + 1];\n            int mark;\n            int forbidden;\n            int maxMatch() {\n                maxMatch = 0;\n                for(int i = 1; i <= n; i++) {\n                    mark = i;\n                    if(findPath(i)) {\n                        maxMatch++;\n                    }\n                }\n                return maxMatch;\n            }\n            boolean findPath(int u) {\n                if(u == forbidden) {\n                    return false;\n                }\n                used[u] = mark;\n                for (int v : g.get(u)) {\n                    if(v == forbidden) {\n                        continue;\n                    }\n                    if(prev[v] == 0 || (used[prev[v]] != mark && findPath(prev[v]))) {\n                        prev[v] = u;\n                        next[u] = v;\n                        return true;\n                    }\n                }\n                return false;\n            }\n            int maxMatch = 0;\n            void amend(int u) {\n//                Arrays.fill(used, false);\n                if(findPath(u)) {\n                    maxMatch++;\n                }\n            }\n            void cancel(int u) {\n                forbidden = u;\n                int v = next[u];\n                if(v != 0) {\n                    maxMatch--;\n                    prev[v] = 0;\n                    next[u] = 0;\n                    for (int i : rg.get(v)) {\n                        if(next[i] == 0) {\n                            amend(i);\n                        }\n                    }\n//                    amend(v);\n                }\n                if(prev[u] != 0) {\n                    maxMatch--;\n                    amend(prev[u]);\n                    prev[u] = 0;\n                }\n            }\n        }\n//        Utils utils = new Utils();\n//        for(int i = 1; i <= n; i++) {\n//            utils.amend(i);\n//        }\n        int ans = Integer.MAX_VALUE;\n        for(int i = 1; i <= n; i++) {\n//            utils.cancel(i);\n//            utils.amend(i - 1);\n            Utils utils = new Utils();\n            utils.forbidden = i;\n            utils.maxMatch();\n            ans = Math.min(ans, (2 * n - 1 - c[i] + loop[i]) + (m - c[i] + loop[i] - utils.maxMatch) + (n - 1 - utils.maxMatch));\n        }\n        return ans;\n    }\n\n    void test() {\n        final int N = 4;\n        final int[] ef = new int[N * N];\n        final int[] et = new int[N * N];\n        for(int i = 1; i <= N; i++) {\n            for(int j = 1; j <= N; j++) {\n                ef[(i - 1) * N + j - 1] = i;\n                et[(i - 1) * N + j - 1] = j;\n            }\n        }\n        List<Integer> good = new ArrayList<>();\n        for(int mask = 0; mask < 1 << N * N; mask++) {\n            int[] in = new int[N + 1];\n            int[] out = new int[N + 1];\n            for(int i = 0; i < N * N; i++) {\n                if((mask >> i) % 2 == 1) {\n                    out[ef[i]]++;\n                    in[et[i]]++;\n                }\n            }\n            boolean ok = false;\n            for(int i = 1; i <= N; i++) {\n                if(in[i] == N && out[i] == N) {\n                    in[i] = 2;\n                    out[i] = 2;\n                    ok = true;\n                    break;\n                }\n            }\n            for(int i = 1; i <= N; i++) {\n                if(in[i] != 2 || out[i] != 2) {\n                    ok = false;\n                }\n            }\n            if(ok) {\n                good.add(mask);\n            }\n        }\n        System.out.println(\"good graphs count: \" + good.size());\n        for (int mask : good) {\n            int m = Integer.bitCount(mask);\n            int[] from = new int[m];\n            int[] to = new int[m];\n            int index = 0;\n            for(int i = 0; i < N * N; i++) {\n                if((mask >> i) % 2 == 1) {\n                    from[index] = ef[i];\n                    to[index] = et[i];\n                    index++;\n                }\n            }\n            if(solve(N, m, from, to) != 0) {\n                writer.println(N + \" \" + m);\n                for(int i = 0; i < m; i++) {\n                    writer.println(from[i] + \" \" + to[i]);\n                }\n                writer.close();\n                return;\n            }\n        }\n        for(int mask = 0; mask < 1 << N * N; mask++) {\n            int optimal = Integer.MAX_VALUE;\n            for (Integer i : good) {\n                optimal = Math.min(optimal, Integer.bitCount(i ^ mask));\n            }\n            int m = Integer.bitCount(mask);\n            int[] from = new int[m];\n            int[] to = new int[m];\n            int index = 0;\n            for(int i = 0; i < N * N; i++) {\n                if((mask >> i) % 2 == 1) {\n                    from[index] = ef[i];\n                    to[index] = et[i];\n                    index++;\n                }\n            }\n            final int fast = solve(N, m, from, to);\n            if(optimal != fast) {\n                System.out.println(\"fast = \" + fast + \", optimal = \" + optimal);\n                writer.println(N + \" \" + m);\n                for(int i = 0; i < m; i++) {\n                    writer.println(from[i] + \" \" + to[i]);\n                }\n                writer.close();\n                return;\n            }\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        new D().solve();\n    }\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.lang.System.out;\nimport static java.util.Collections.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic boolean LOCAL = System.getSecurityManager() == null;\n\tScanner in = new Scanner(System.in);\n\tprivate int[] B;\n\tprivate int[] A;\n\tprivate int n;\n\tprivate int m;\n\n\tvoid run() {\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tA = new int[m];\n\t\tB = new int[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tA[i] = in.nextInt() - 1;\n\t\t\tB[i] = in.nextInt() - 1;\n\t\t}\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tans = min(ans, solve(i));\n\t\t}\n\t\tout.println(ans);\n\t}\n\tint solve(int x) {\n\t\tint ans = 3 * (n - 1)  + 1 + m;\n\t\tV[] vs = new V[n * 2];\n\t\tfor (int i = 0; i < vs.length; i++) vs[i] = new V();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tif (A[i] == x || B[i] == x) ans -= 2;\n\t\t\telse vs[A[i]].connect(vs[n + B[i]]);\n\t\t}\n\t\treturn ans - 2 * bipartiteMatching(vs);\n\t}\n\tclass V extends ArrayList<V> {\n\t\tV pair;\n\t\tboolean used;\n\t\tvoid connect(V v) {\n\t\t\tadd(v);\n\t\t\tv.add(this);\n\t\t}\n\t}\n\tint bipartiteMatching(V[] vs) {\n\t\tint match = 0;\n\t\tfor (V v : vs) if (v.pair == null) {\n\t\t\tfor (V u : vs) u.used = false;\n\t\t\tif (dfs(v)) match++;\n\t\t}\n\t\treturn match;\n\t}\n\tboolean dfs(V v) {\n\t\tv.used = true;\n\t\tfor (V u : v) {\n\t\t\tV w = u.pair;\n\t\t\tif (w == null || !w.used && dfs(w)) {\n\t\t\t\tv.pair = u;\n\t\t\t\tu.pair = v;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tvoid debug(Object... os) {\n\t\tSystem.err.println(deepToString(os));\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tif (LOCAL) {\n\t\t\ttry {\n\t\t\t\tSystem.setIn(new FileInputStream(\"./../../in.txt\"));\n\t\t\t\t// System.setOut(new PrintStream(\"./../../out\"));\n\t\t\t} catch (Throwable e) {\n\t\t\t\tLOCAL = false;\n\t\t\t}\n\t\t}\n\t\tlong start = 0;\n\t\tif (LOCAL)\n\t\t\tstart = System.nanoTime();\n\t\tnew Main().run();\n\t\tif (LOCAL)\n\t\t\tSystem.err.printf(\"[Time : %.6f s]%n\",\n\t\t\t\t\t(System.nanoTime() - start) * 1e-9);\n\t}\n}\n\nclass Scanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tScanner(InputStream in) {\n\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\teat(\"\");\n\t}\n\n\tvoid eat(String s) {\n\t\tst = new StringTokenizer(s);\n\t}\n\n\tString nextLine() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tboolean hasNext() {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = nextLine();\n\t\t\tif (s == null)\n\t\t\t\treturn false;\n\t\t\teat(s);\n\t\t}\n\t\treturn true;\n\t}\n\n\tString next() {\n\t\thasNext();\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}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "//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    final int MOD = 1000 * 1000 * 1000 + 7;\n    int sum(int a, int b) {\n        a += b;\n        return a >= MOD ? a - MOD : a;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    void solve() throws IOException {\n        final int n = nextInt();\n        int m = nextInt();\n        int[] from = new int[m];\n        int[] to = new int[m];\n        for(int i = 0; i < m; i++) {\n            from[i] = nextInt();\n            to[i] = nextInt();\n        }\n        int ans = solve(n, m, from, to);\n        writer.println(ans);\n        writer.close();\n    }\n\n    private int solve(final int n, int m, int[] from, int[] to) {\n        final List<List<Integer>> g = new ArrayList<>();\n        for(int i = 0; i <= n; i++) {\n            g.add(new ArrayList<Integer>());\n        }\n        int[] c = new int[n + 1];\n        int[] loop = new int[n + 1];\n        for(int i = 0; i < m; i++) {\n            int u = from[i];\n            int v = to[i];\n            g.get(u).add(v);\n            c[u]++;\n            c[v]++;\n            if(u == v) {\n                loop[u]++;\n            }\n        }\n        class Utils {\n            int[] prev = new int[n + 1];\n            int[] used = new int[n + 1];\n            int mark;\n            int forbidden;\n            int maxMatch() {\n                maxMatch = 0;\n                for(int i = 1; i <= n; i++) {\n                    mark = i;\n                    if(findPath(i)) {\n                        maxMatch++;\n                    }\n                }\n                return maxMatch;\n            }\n            boolean findPath(int u) {\n                if(u == forbidden) {\n                    return false;\n                }\n                used[u] = mark;\n                for (int v : g.get(u)) {\n                    if(v == forbidden) {\n                        continue;\n                    }\n                    if(prev[v] == 0 || (used[prev[v]] != mark && findPath(prev[v]))) {\n                        prev[v] = u;\n                        return true;\n                    }\n                }\n                return false;\n            }\n            int maxMatch = 0;\n        }\n        int ans = Integer.MAX_VALUE;\n        for(int i = 1; i <= n; i++) {\n            Utils utils = new Utils();\n            utils.forbidden = i;\n            utils.maxMatch();\n            ans = Math.min(ans, (2 * n - 1 - c[i] + loop[i]) + (m - c[i] + loop[i] - utils.maxMatch) + (n - 1 - utils.maxMatch));\n        }\n        return ans;\n    }\n\n    public static void main(String[] args) throws IOException {\n        new D().solve();\n    }\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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    int n, m;\n    boolean[][] grid;\n    ArrayList<Integer>[] gr;\n    int c;\n    int[] mt;\n    boolean[] u;\n\n\n    boolean try_kuhn( int v ){\n        if( u[v] ) return false;\n        u[v] = true;\n        for( int to : gr[v] ){\n            if( to == c || !grid[v][to] ) continue;\n            if( mt[to]==-1 || try_kuhn(mt[to]) ){\n                mt[to] = v;\n                return true;\n            }\n        }\n        return false;\n    }\n\n    void solve(){\n        n = sc.nextInt();\n        m = sc.nextInt();\n        grid = new boolean[n+1][n+1];\n        gr = new ArrayList[n+1];\n        for( int v = 1; v <= n; ++v ) gr[v] = new ArrayList<Integer>();\n        for( int it = 0; it < m; ++it ){\n            int a = sc.nextInt();\n            int b = sc.nextInt();\n            grid[a][b] = true;\n            gr[a].add(b);\n        }\n\n        int ans = Integer.MAX_VALUE;\n        for( c = 1; c <= n; ++c ){\n            int curAns = 0;\n            for( int v = 1; v <= n; ++v )\n                if( v != c ){\n                    if( !grid[c][v] ) ++curAns;\n                    if( !grid[v][c] ) ++curAns;\n                }\n            if( !grid[c][c] ) ++curAns;\n\n            mt = new int[n+1];\n            fill( mt, -1 );\n            for( int i = 1; i <= n; ++i )\n                if( i != c ){\n                    u = new boolean[n+1];\n                    try_kuhn(i);\n                }\n\n            int szMt = 0;\n            for( int i = 1; i <= n; ++i )\n                if( mt[i] != -1 )\n                    ++szMt;\n            curAns += n - 1 - szMt;\n\n            for( int a = 1; a <= n; ++a ){\n            for( int b : gr[a] ){\n                if( a==c || b==c || !grid[a][b]\n                ) continue;\n                if(!( a==mt[b] ))\n                    ++curAns;\n            }\n            }\n\n//            out.printf( \"%d %d\\n\", c, curAns );\n            ans = min( ans, curAns );\n        }\n        out.println( ans );\n    }\n\n\n\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "//package round227;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint 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[] nfrom = new int[m];\n\t\tint[] nto = new int[m];\n\t\tint min = 999999999;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint p = 0;\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tif(from[j] != i && to[j] != i){\n\t\t\t\t\tnfrom[p] = from[j];\n\t\t\t\t\tnto[p] = to[j];\n\t\t\t\t\tp++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][] g = packD(n, nfrom, nto, p);\n\t\t\tint mat = doBipartiteMatchingHKNoRec(g, n);\n\t\t\t\n\t\t\tint ch = p - mat + (n-1-mat);\n\t\t\tch += 2*n-1 - (m - p); \n\t\t\tmin = Math.min(min, ch);\n\t\t}\n\t\tout.println(min);\n\t}\n\t\n\tpublic static int doBipartiteMatchingHKNoRec(int[][] g, int m)\n\t{\n\t\tint n = g.length;\n\t\tif(n == 0)return 0;\n\t\tint[] from = new int[m];\n\t\tint[] to = new int[n];\n\t\tArrays.fill(to, -1);\n\t\tArrays.fill(from, n);\n\t\t\n\t\tint[] d = new int[n+1];\n\t\tint mat = 0;\n\t\tint[] stack = new int[n+1];\n\t\tint[] adjind = new int[n+1];\n\t\twhile(true){\n\t\t\tArrays.fill(d, -1);\n\t\t\tint[] q = new int[n];\n\t\t\tint r = 0;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tif(to[i] == -1){\n\t\t\t\t\td[i] = 0;\n\t\t\t\t\tq[r++] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor(int p = 0;p < r;p++) {\n\t\t\t\tint cur = q[p];\n\t\t\t\tfor(int adj : g[cur]){\n\t\t\t\t\tint nex = from[adj];\n\t\t\t\t\tif(d[nex] == -1) {\n\t\t\t\t\t\tif(nex != n)q[r++] = nex;\n\t\t\t\t\t\td[nex] = d[cur] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(d[n] == -1)break;\n\t\t\t\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tif(to[i] == -1){\n\t\t\t\t\tint sp = 1;\n\t\t\t\t\tstack[0] = i;\n\t\t\t\t\tadjind[0] = 0;\n\t\t\t\t\tboolean prevB = false;\n\t\t\t\t\touter:\n\t\t\t\t\twhile(sp >= 1){\n\t\t\t\t\t\tint cur = stack[sp-1];\n\t\t\t\t\t\tif(cur == n){\n\t\t\t\t\t\t\tprevB = true;\n\t\t\t\t\t\t\tsp--;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor(;adjind[sp-1] < 2*g[cur].length;){\n\t\t\t\t\t\t\tint adj = g[cur][adjind[sp-1]/2];\n\t\t\t\t\t\t\tif(adjind[sp-1] % 2 == 0){\n\t\t\t\t\t\t\t\tint nex = from[adj];\n\t\t\t\t\t\t\t\tif(d[nex] == d[cur] + 1){\n\t\t\t\t\t\t\t\t\tstack[sp] = nex;\n\t\t\t\t\t\t\t\t\tadjind[sp] = 0;\n\t\t\t\t\t\t\t\t\tadjind[sp-1]++;\n\t\t\t\t\t\t\t\t\tsp++;\n\t\t\t\t\t\t\t\t\tcontinue outer;\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tadjind[sp-1]+=2;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\tif(prevB){\n\t\t\t\t\t\t\t\t\tto[cur] = adj;\n\t\t\t\t\t\t\t\t\tfrom[adj] = cur;\n\t\t\t\t\t\t\t\t\tprevB = true;\n\t\t\t\t\t\t\t\t\tsp--;\n\t\t\t\t\t\t\t\t\tcontinue outer;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tadjind[sp-1]++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\td[cur] = -1;\n\t\t\t\t\t\tprevB = false;\n\t\t\t\t\t\tsp--;\n\t\t\t\t\t}\n\t\t\t\t\tif(prevB)mat++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn mat;\n\t}\n\t\n\tpublic static int[][] packD(int n, int[] from, int[] to, int sup)\n\t{\n\t\tint[][] g = new int[n][];\n\t\tint[] p = new int[n];\n\t\tfor(int i = 0;i < sup;i++)p[from[i]]++;\n\t\tfor(int i = 0;i < n;i++)g[i] = new int[p[i]];\n\t\tfor(int i = 0;i < sup;i++){\n\t\t\tg[from[i]][--p[from[i]]] = to[i];\n\t\t}\n\t\treturn g;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 500, m = 1000;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(n + \" \");\n//\t\tsb.append(m + \" \");\n//\t\tboolean[][] g = new boolean[n][n];\n//\t\tfor(int i = 0;i < m;i++){\n//\t\t\twhile(true){\n//\t\t\t\tint r = gen.nextInt(n);\n//\t\t\t\tint c = gen.nextInt(n);\n//\t\t\t\tif(!g[r][c]){\n//\t\t\t\t\tg[r][c] = true;\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 < n;i++){\n//\t\t\tfor(int j = 0;j < n;j++){\n//\t\t\t\tif(g[i][j]){\n//\t\t\t\t\tsb.append((i+1) + \" \");\n//\t\t\t\t\tsb.append((j+1) + \" \");\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n//\t\tINPUT = sb.toString();\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 D().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", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF387D {\n\tstatic class A {\n\t\tArrayList<Integer> list = new ArrayList<>();\n\t\tint u, v, d;\n\t}\n\tstatic int INF = Integer.MAX_VALUE;\n\tstatic boolean bfs(A[] aa, int n) {\n\t\tLinkedList<Integer> queue = new LinkedList<>();\n\t\tfor (int u = 1; u <= n; u++)\n\t\t\tif (aa[u].v > 0)\n\t\t\t\taa[u].d = INF;\n\t\t\telse {\n\t\t\t\taa[u].d = 0;\n\t\t\t\tqueue.addLast(u);\n\t\t\t}\n\t\taa[0].d = INF;\n\t\twhile (!queue.isEmpty()) {\n\t\t\tint u = queue.removeFirst();\n\t\t\tif (aa[u].d + 1 == aa[0].d)\n\t\t\t\tbreak;\n\t\t\tfor (int v : aa[u].list) {\n\t\t\t\tint w = aa[v].u;\n\t\t\t\tif (aa[w].d == INF) {\n\t\t\t\t\taa[w].d = aa[u].d + 1;\n\t\t\t\t\tqueue.addLast(w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn aa[0].d != INF;\n\t}\n\tstatic boolean dfs(A[] aa, int n, int u) {\n\t\tif (u == 0)\n\t\t\treturn true;\n\t\tfor (int v : aa[u].list) {\n\t\t\tint w = aa[v].u;\n\t\t\tif (aa[w].d == aa[u].d + 1 && dfs(aa, n, w)) {\n\t\t\t\taa[u].v = v;\n\t\t\t\taa[v].u = u;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\taa[u].d = INF;\n\t\treturn false;\n\t}\n\tstatic int matchings(A[] aa, int n) {\n\t\tint cnt = 0;\n\t\twhile (bfs(aa, n))\n\t\t\tfor (int u = 1; u <= n; u++)\n\t\t\t\tif (aa[u].v == 0 && dfs(aa, n, u))\n\t\t\t\t\tcnt++;\n\t\treturn cnt;\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[] eu = new int[m];\n\t\tint[] ev = new int[m];\n\t\tfor (int j = 0; j < m; j++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\teu[j] = Integer.parseInt(st.nextToken());\n\t\t\tev[j] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tA[] aa = new A[n + 1];\n\t\tint min = m + n * 3;\n\t\tfor (int ctr = 1; ctr <= n; ctr++) {\n\t\t\tboolean loop = false;\n\t\t\tboolean[] ci = new boolean[n + 1];\n\t\t\tboolean[] co = new boolean[n + 1];\n\t\t\tfor (int i = 0; i <= n; i++)\n\t\t\t\taa[i] = new A();\n\t\t\tint m_ = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tint u = eu[j];\n\t\t\t\tint v = ev[j];\n\t\t\t\tif (u == ctr && v == ctr)\n\t\t\t\t\tloop = true;\n\t\t\t\telse if (u == ctr && v != ctr)\n\t\t\t\t\tci[v] = true;\n\t\t\t\telse if (u != ctr && v == ctr)\n\t\t\t\t\tco[u] = true;\n\t\t\t\telse {\n\t\t\t\t\taa[u].list.add(v);\n\t\t\t\t\tm_++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint cnt = loop ? 0 : 1;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tif (i != ctr) {\n\t\t\t\t\tif (!ci[i])\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\tif (!co[i])\n\t\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\tint m2 = matchings(aa, n);\n\t\t\tcnt += (m_ - m2) + (n - 1 - m2);\n\t\t\tif (min > cnt)\n\t\t\t\tmin = cnt;\n\t\t}\n\t\tSystem.out.println(min);\n\t}\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tclass W implements Comparable<W> {\n\t\tint id, sz;\n\n\t\tW(int id, int sz) {\n\t\t\tthis.id = id;\n\t\t\tthis.sz = sz;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(W o) {\n\t\t\treturn -Integer.compare(sz, o.sz);\n\t\t}\n\t}\n\n\tint[] left;\n\tint center;\n\tboolean[] used;\n\n\tboolean go(int v) {\n\t\tif (used[v])\n\t\t\treturn false;\n\t\tused[v] = true;\n\t\tfor (int i = 0; i < g[v].size(); ++i) {\n\t\t\tint to = g[v].get(i);\n\t\t\tif (to == center)\n\t\t\t\tcontinue;\n\t\t\tif (left[to] == -1 || go(left[to])) {\n\t\t\t\tleft[to] = v;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tArrayList<Integer>[] g;\n\n\tvoid solve() {\n\t\t\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tused = new boolean[n];\n\t\tg = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tg[i] = new ArrayList<>();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tg[in.nextInt() - 1].add(in.nextInt() - 1);\n\t\t}\n\t\tlong st = System.currentTimeMillis();\n\t\tint ans = Integer.MAX_VALUE;\n\t\tW[] a = new W[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new W(i, g[i].size());\n\t\t}\n\t\tleft = new int[n];\n\t\tArrays.sort(a);\n\t\tfor (int centerId = 0; centerId < n; centerId++) {\n\t\t\tcenter = a[centerId].id;\n\t\t\tif (System.currentTimeMillis() - st > 800)\n\t\t\t\tbreak;\n\t\t\tint cost = n - g[center].size();\n\t\t\tArrays.fill(left, -1);\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (i != center) {\n\t\t\t\t\tboolean has = false;\n\t\t\t\t\tfor (int j = 0; j < g[i].size(); j++) {\n\t\t\t\t\t\tif (g[i].get(j) == center)\n\t\t\t\t\t\t\thas = true;\n\t\t\t\t\t}\n\t\t\t\t\tArrays.fill(used, false);\n\t\t\t\t\tif (!go(i)) {\n\t\t\t\t\t\tif (has) {\n\t\t\t\t\t\t\tcost += g[i].size();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcost += g[i].size() + 2;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (has) {\n\t\t\t\t\t\t\tcost += g[i].size() - 2;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcost += g[i].size();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tans = Math.min(ans, cost);\n\t\t}\n\t\tout.println(ans);\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}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\n\npublic class GeorgeAndInterestingGraph {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        \n        int N = sc.nextInt();\n        int M = sc.nextInt();\n        \n        int[] edgeFrom = new int[M];\n        int[] edgeTo = new int[M];\n        for (int i = 0; i < M; i++) {\n        \tedgeFrom[i] = sc.nextInt();\n        \tedgeTo[i] = sc.nextInt();\n        }\n        \n        int best = Integer.MAX_VALUE;\n        for (int i = 0; i < N; i++) {\n        \tboolean[][] mat = makeAdjMat(N, edgeFrom, edgeTo);\n        \tbest = Math.min(best, count(mat, i, M));\n        }\n        \n        System.out.println(best);\n    }\n    \n    public static int count(boolean[][] mat, int center, int M) {\n//    \tint N = mat.length;\n//    \tint M = mat[0].length;\n//\n//    \tint centerConnect = (mat[center][center]) ? 0 : 1;\n//    \tfor (int i = 0; i < N; i++) {\n//\t\t\tif (i != center) {\n//\t\t\t\tif (!mat[i][center]) {\n//\t\t\t\t\tcenterConnect++;\n//\t\t\t\t}\n//\t\t\t\tif (!mat[center][i]) {\n//\t\t\t\t\tcenterConnect++;\n//\t\t\t\t}\n//\t\t\t}\n//\t    \tmat[i][center] = false;\n//\t    \tmat[center][i] = false;\n//\t\t}\n//    \t\n//    \tint[][] adjMat = new int[2 * N + 2][2 * N + 2];\n//    \tfor (int i = 0; i < N; i++) {\n//    \t\tfor (int j = 0; j < N; j++) {\n//    \t\t\tint idx = N + j;\n//    \t\t\tadjMat[i][idx] = (mat[i][j]) ? 1 : 0;\n//    \t\t}\n//    \t}\n//    \tint s = 2 * N;\n//    \tint t = 2 * N + 1;\n//    \tfor (int i = 0; i < N; i++) {\n//    \t\tadjMat[s][i] = 1;\n//    \t}\n//    \tfor (int i = N; i < 2 * N; i++) {\n//    \t\tadjMat[i][t] = 1;\n//    \t}\n//    \t\n//    \tint matches = fordFulkerson(adjMat, s, t);\n//    \t\n//    \treturn centerConnect + matches;\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \t\n    \tint N = mat.length;\n//    \tint M = mat[0].length;\n    \t\n    \tint cntWithI = (mat[center][center]) ? 1 : 0;\n    \tfor (int i = 0; i < N; i++) {\n    \t\tif (i != center) {\n    \t\t\tif (mat[i][center]) {\n    \t\t\t\tcntWithI++;\n    \t\t\t}\n    \t\t\tif (mat[center][i]) {\n    \t\t\t\tcntWithI++;\n    \t\t\t}\n    \t\t}\n        \tmat[i][center] = false;\n        \tmat[center][i] = false;\n    \t}\n    \t\n    \tint other = M - cntWithI;\n    \t\n//    \tint centerConnect = (mat[center][center]) ? 0 : 1;\n//    \t\n//    \tfor (int i = 0; i < N; i++) {\n//    \t\tif (i != center) {\n//    \t\t\tif (!mat[i][center]) {\n//    \t\t\t\tcenterConnect++;\n//    \t\t\t}\n//    \t\t\tif (!mat[center][i]) {\n//    \t\t\t\tcenterConnect++;\n//    \t\t\t}\n//    \t\t}\n//        \tmat[i][center] = false;\n//        \tmat[center][i] = false;\n//    \t}\n    \t\n    \tint matches = bipartiteMatching(mat);\n    \t\n    \treturn (2 * N - 1 - cntWithI + other - matches + N - 1 - matches);\n//    \treturn (centerConnect + N - 1 - matches);\n    }\n    \n    public static boolean[][] makeAdjMat(int N, int[] edgeFrom, int[] edgeTo) {\n    \tboolean[][] mat = new boolean[N][N];\n    \tfor (int i = 0; i < edgeFrom.length; i++) {\n    \t\tint from = edgeFrom[i] - 1;\n    \t\tint to = edgeTo[i] - 1;\n    \t\tmat[from][to] = true;\n    \t}\n    \treturn mat;\n    }\n    \n    /**\n     * Returns true if there is a path from the source 's' to the sink 't' in the residual graph.\n     * Also fills parent[] to store the path.\n     * See here for more info:  http://www.geeksforgeeks.org/ford-fulkerson-algorithm-for-maximum-flow-problem/\n     */\n    public static boolean fordFulkersonHelper(int[][] resid, int s, int t, int[] parent) {\n    \tint V = resid.length;\n    \tboolean[] visited = new boolean[V];\n    \tLinkedList<Integer> q = new LinkedList<Integer>();\n    \tq.push(s);\n    \tvisited[s] = true;\n    \tparent[s] = -1;\n    \t\n    \twhile (!q.isEmpty()) {\n    \t\tint u = q.pop();\n    \t\tfor (int v = 0; v < V; v++) {\n    \t\t\tif (!visited[v] && resid[u][v] > 0) {\n    \t\t\t\tq.push(v);\n    \t\t\t\tparent[v] = u;\n    \t\t\t\tvisited[v] = true;\n    \t\t\t}\n    \t\t}\n    \t}\n    \t\n    \treturn visited[t];\n    }\n    \n    /**\n     * Returns the maximum flow from 's' to 't' in the given graph.\n     * See here for more info:  http://www.geeksforgeeks.org/ford-fulkerson-algorithm-for-maximum-flow-problem/\n     */\n    public static int fordFulkerson(int[][] graph, int s, int t) {\n    \tint V = graph.length;\n    \tint[][] resid = new int[V][V];\n    \tint[] parent = new int[V];\n    \tint maxFlow = 0;\n    \t\n    \tfor (int u = 0; u < V; u++) {\n    \t\tfor (int v = 0; v < V; v++) {\n    \t\t\tresid[u][v] = graph[u][v];\n    \t\t}\n    \t}\n    \t\n    \twhile (fordFulkersonHelper(resid, s, t, parent)) {\n    \t\tint pathFlow = Integer.MAX_VALUE;\n    \t\tfor (int v = t; v != s; v = parent[v]) {\n    \t\t\tint u = parent[v];\n    \t\t\tpathFlow = Math.min(pathFlow,  resid[u][v]);\n    \t\t}\n    \t\tfor (int v = t; v != s; v = parent[v]) {\n    \t\t\tint u = parent[v];\n    \t\t\tresid[u][v] -= pathFlow;\n    \t\t\tresid[v][u] += pathFlow;\n    \t\t}\n    \t\tmaxFlow += pathFlow;\n    \t}\n    \t\n    \treturn maxFlow;\n    }\n    \n    /**\n     * Returns true if a matching for vertex 'u' is possible.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static boolean bipartiteMatchingHelper(boolean[][] bpGraph, int u, boolean[] seen, int[] matchR) {\n    \tint N = bpGraph[0].length;\n    \tfor (int v = 0; v < N; v++) {\n    \t\tif (bpGraph[u][v] && !seen[v]) {\n    \t\t\tseen[v] = true;\n    \t\t\tif (matchR[v] < 0 || bipartiteMatchingHelper(bpGraph, matchR[v], seen, matchR)) {\n    \t\t\t\tmatchR[v] = u;\n    \t\t\t\treturn true;\n    \t\t\t}\n    \t\t}\n    \t}\n    \treturn false;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchIJ, int[] matchJI) {\n    \tint ans = bipartiteMatching(bpGraph, matchJI);\n    \t\n    \tfor (int i = 0; i < matchJI.length; i++) {\n    \t\tmatchIJ[i] = -1;\n    \t}\n    \t\n    \tfor (int j = 0; j < matchJI.length; j++) {\n    \t\tint i = matchJI[j];\n    \t\tif (i >= 0) {\n    \t\t\tmatchIJ[i] = j;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Note:  bpGraph[i][j] = true if there is an edge from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph, int[] matchJI) {\n    \tint M = bpGraph.length;\n    \tint N = bpGraph[0].length;\n    \t\n    \tfor (int i = 0; i < N; i++) {\n    \t\tmatchJI[i] = -1;\n    \t}\n    \t\n    \tint ans = 0;\n    \tfor (int u = 0; u < M; u++) {\n    \t\tboolean[] seen = new boolean[N];\n    \t\tif (bipartiteMatchingHelper(bpGraph, u, seen, matchJI)) {\n    \t\t\tans++;\n    \t\t}\n    \t}\n    \t\n    \treturn ans;\n    }\n    \n    /**\n     * Returns the maximum bipartite matching from an an adjacency matrix.\n     * Overload of the bipartiteMatching function without output parameters.\n     * See here for more info:  http://www.geeksforgeeks.org/maximum-bipartite-matching/\n     */\n    public static int bipartiteMatching(boolean[][] bpGraph) {\n    \tint N = bpGraph[0].length;\n    \tint[] matchJI = new int[N];\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n    \n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     */\n    public static int bipartiteMatching(int[][] intGraph) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchJI);\n    }\n\n    /**\n     * Overload of the bipartiteMatching function taking an adjacency matrix of int[][] instead of boolean[][].\n     * Note:  matchIJ (array of length M) is an output variable containing the matchings, such that matchIJ[i] = j means that there is a match from i to j.\n     * Note:  matchJI (array of length N) is an output variable containing the matchings, such that matchJI[j] = i means that there is a match from i to j.\n     */\n    public static int bipartiteMatching(int[][] intGraph, int[] matchIJ, int[] matchJI) {\n    \tboolean[][] bpGraph = intToBooleanAdjMat(intGraph);\n    \treturn bipartiteMatching(bpGraph, matchIJ, matchJI);\n    }\n    \n    /**\n     * Converts an integer adjacency matrix of 1's and 0's to a boolean adjacency matrix.\n     * Useful with bipartiteMatching, which takes adjancency matrix of boolean[][] as input (instead of int[][]).\n     */\n    public static boolean[][] intToBooleanAdjMat(int[][] mat) {\n    \tint M = mat.length;\n    \tint N = mat[0].length;\n    \tboolean[][] bMat = new boolean[M][N];\n    \tfor (int i = 0; i < M; i++) {\n    \t\tfor (int j = 0; j < N; j++) {\n    \t\t\tbMat[i][j] = (mat[i][j] != 0);\n    \t\t}\n    \t}\n    \treturn bMat;\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        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 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        String nextLine() {\n            String str = \"\";\n            try { str = br.readLine(); }\n            catch (IOException e) { e.printStackTrace(); }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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 m = scan.nextInt();\n            final Pair<Integer, Integer>[] arcs = new Pair[m];\n            for(int k = 0; k < m; ++k) {\n                int i = scan.nextInt();\n                int j = scan.nextInt();\n                --i; --j;\n                arcs[k] = new Pair(i, j);\n            }\n            print.println(calcMinNumStepsToCenterPermGraph(new DirectedGraph(n, arcs)));\n        }\n    }\n\n    public static int calcMinNumStepsToCenterPermGraph(final DirectedGraph graph) {\n        int result = Integer.MAX_VALUE;\n        for(DirectedGraph.Vertex center : graph.vertices) {\n            int num = 2 * graph.vertices.length - 1 - graph.getOutcomingArcs(center).size() -\n                    graph.getIncomingArcs(center).size() + (graph.containsArc(center, center) ? 1 : 0);\n            final int n = graph.vertices.length - 1;\n            final List<Pair<Integer, Integer>> edges = CollectionFactory.createArrayList();\n            for(DirectedGraph.Arc arc : graph.arcs) {\n                if(!center.equals(arc.from) && !(center.equals(arc.to))) {\n                    int i = arc.from.index;\n                    int j = arc.to.index;\n                    if(i > center.index) {\n                        --i;\n                    }\n                    if(j > center.index) {\n                        --j;\n                    }\n                    edges.add(new Pair(i, j));\n                }\n            }\n            final int matching = GraphUtils.calcNumMatchingBipartite(n, n, edges);\n            num += edges.size() - matching;\n            num += n - matching;\n            result = Math.min(result, num);\n        }\n        return result;\n    }\n\n    public static class GraphUtils {\n        public static int calcNumMatchingBipartite(final int n, final int m, final List<Pair<Integer, Integer>> edges) {\n            final MatchingBipartiteSolver solver = new MatchingBipartiteSolver(n, m, edges);\n            return solver.solve();\n        }\n\n        private static class MatchingBipartiteSolver {\n            private final int n;\n            private final int m;\n            private final List<Integer>[] edges;\n            private final Integer[] match;\n            private final boolean[] visited;\n\n            public MatchingBipartiteSolver (final int n, final int m, final List<Pair<Integer, Integer>> edges) {\n                this.n = n;\n                this.m = m;\n                this.edges = new List[n];\n                for(int i = 0; i < n; ++i) {\n                    this.edges[i] = CollectionFactory.createArrayList();\n                }\n                for(final Pair<Integer, Integer> edge: edges) {\n                    this.edges[edge.first].add(edge.second);\n                }\n                match = new Integer[n + m];\n                visited = new boolean[n + m];\n            }\n\n            public int solve() {\n                int result = 0;\n                for(;;) {\n                    Arrays.fill(visited, false);\n                    int gain = 0;\n                    for(int i = 0; i < n; ++i) {\n                        if(match[i] == null && !visited[i] && tryMatch(i)) {\n                            ++gain;\n                        }\n                    }\n                    if(gain > 0) {\n                        result += gain;\n                    } else {\n                        break;\n                    }\n                }\n                return result;\n            }\n\n            private boolean tryMatch(final int i) {\n                visited[i] = true;\n                for(int j : edges[i]) {\n                    if(!visited[j + n]) {\n                        visited[j + n] = true;\n                        final Integer k = match[j + n];\n                        if(k == null || (!visited[k] && tryMatch(k))) {\n                            match[j + n] = i;\n                            match[i] = j + n;\n                            return true;\n                        }\n                    }\n                }\n                return false;\n            }\n        }\n    }\n\n    public static class DirectedGraph {\n        public static class Vertex {\n            public final int index;\n\n            public Vertex(int index) {\n                this.index = index;\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                Vertex vertex = (Vertex) o;\n\n                if (index != vertex.index) return false;\n\n                return true;\n            }\n\n            @Override\n            public int hashCode() {\n                return index;\n            }\n        }\n\n        public static class Arc {\n            public final Vertex from;\n            public final Vertex to;\n\n            public Arc(Vertex from, Vertex to) {\n                this.from = from;\n                this.to = to;\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                Arc arc = (Arc) o;\n\n                if (!from.equals(arc.from)) return false;\n                if (!to.equals(arc.to)) return false;\n\n                return true;\n            }\n\n            @Override\n            public int hashCode() {\n                int result = from.hashCode();\n                result = 31 * result + to.hashCode();\n                return result;\n            }\n        }\n\n        final public Vertex[] vertices;\n        final public Arc[] arcs;\n\n        public DirectedGraph(final int n, final Pair<Integer, Integer>[] arcs) {\n            vertices = new Vertex[n];\n            this.arcs = new Arc[arcs.length];\n            for(int i = 0; i < n; ++i) {\n                vertices[i] = new Vertex(i);\n            }\n            for(int i = 0; i < arcs.length; ++i) {\n                this.arcs[i] = new Arc(vertices[arcs[i].first], vertices[arcs[i].second]);\n            }\n        }\n\n        public List<Arc> getOutcomingArcs(final Vertex v) {\n            final List<Arc> result = CollectionFactory.createArrayList();\n            for(Arc arc : arcs) {\n                if(arc.from.equals(v)) {\n                    result.add(arc);\n                }\n            }\n            return result;\n        }\n\n        public List<Arc> getIncomingArcs(final Vertex v) {\n            final List<Arc> result = CollectionFactory.createArrayList();\n            for(Arc arc : arcs) {\n                if(arc.to.equals(v)) {\n                    result.add(arc);\n                }\n            }\n            return result;\n        }\n\n        public boolean containsArc(final Vertex from, final Vertex to) {\n            for(Arc arc : arcs) {\n                if(arc.from.equals(from) && arc.to.equals(to)) {\n                    return true;\n                }\n            }\n            return false;\n        }\n    }\n\n\n    public static class MatrixIntMod {\n        final int mod;\n        final int[][] data;\n\n        public MatrixIntMod(final int n, final int m, final int mod) {\n            this.mod = mod;\n            this.data = new int[n][m];\n            for(int i = 0; i < n; ++i) {\n                Arrays.fill(data[i], 0);\n            }\n        }\n\n        public MatrixIntMod(final int[][] data, final int mod) {\n            this(data.length, data[0].length, mod);\n            for(int i = 0; i < data.length; ++i) {\n                for(int j = 0; j < data[i].length; ++j) {\n                    this.data[i][j] = ModNumberUtils.norm(mod, data[i][j]);\n                }\n            }\n        }\n\n        public MatrixIntMod(final int[] data, final int mod) {\n            this(data.length, 1, mod);\n            for(int i = 0; i < data.length; ++i) {\n                this.data[i][0] = ModNumberUtils.norm(mod, data[i]);\n            }\n        }\n\n        public int[] all() {\n            int n = data.length;\n            int m = data[0].length;\n            final int[] res = new int[n * m];\n            int k = 0;\n            for(int i = 0; i < n; ++i) {\n                for(int j = 0; j < m; ++j) {\n                    res[k++] = data[i][j];\n                }\n            }\n            return res;\n        }\n\n        public MatrixIntMod mult(final MatrixIntMod val) {\n            if(data[0].length != val.data.length) throw new RuntimeException(\"dimensions for mult are wrong\");\n            final int n = data.length;\n            final int m = data[0].length;\n            final int l = val.data[0].length;\n            final MatrixIntMod res = new MatrixIntMod(n, l, mod);\n            for(int i = 0; i < n; ++i) {\n                for(int j = 0; j < l; ++j) {\n                    for(int k = 0; k < m; ++k) {\n                        res.data[i][j] = ModNumberUtils.add(mod, res.data[i][j],\n                                ModNumberUtils.mult(mod, data[i][k], val.data[k][j]));\n                    }\n                }\n            }\n            return res;\n        }\n\n        public int[] mult(final int[] ar) {\n            return mult(new MatrixIntMod(ar, mod)).all();\n        }\n\n        public MatrixIntMod power(final long t) {\n            if(t == 0) return eye(data.length, mod);\n            MatrixIntMod res = power(t >> 1);\n            res = res.mult(res);\n            if((t & 1) == 1) {\n                res = res.mult(this);\n            }\n            return res;\n        }\n\n        public static MatrixIntMod eye(final int n, final int mod) {\n            final MatrixIntMod res = new MatrixIntMod(n, n, mod);\n            if(mod > 1) {\n                for(int i = 0; i < n; ++i) {\n                    res.data[i][i] = 1;\n                }\n            }\n            return res;\n        }\n    }\n\n    public static class ModNumberUtils {\n        public static int add(int mod, int a, int b) {\n            a += b;\n            if(a >= mod) {\n                a -= mod;\n            }\n            return a;\n        }\n\n        public static int norm(int mod, int a) {\n            a %= mod;\n            if(a < 0) {\n                a += mod;\n            }\n            return a;\n        }\n\n        public static int mult(int mod, int a, int b) {\n            return (int)((long)a * b % mod);\n        }\n    }\n\n    public static class Pair<X, Y>{\n        public X first;\n        public Y second;\n\n        public Pair(final X first, final Y second) {\n            this.first = first;\n            this.second = second;\n        }\n    }\n\n\n    public static class NumberUtils {\n        public static interface Factorizer {\n            List<Integer> 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<Integer> factorize(int number) {\n                synchronized (this) {\n                    if(!prepared) {\n                        prepare();\n                    }\n                }\n                final List<Integer> 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<T> List<T> createArrayList() {\n            return new ArrayList<>();\n        }\n\n        public static<T> List<T> createArrayList(final int capacity) {\n            return new ArrayList<>(capacity);\n        }\n    }\n\n    public static class CollectionUtils {\n        public static<T> List<T> unique(final List<T> list) {\n            final List<T> 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 extends Comparable<T>> T max(final List<T> 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", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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    int n, m;\n    boolean[][] grid;\n    ArrayList<Integer>[] gr;\n    int c;\n    int[] mt;\n    boolean[] u;\n\n\n    boolean try_kuhn( int v ){\n        if( u[v] ) return false;\n        u[v] = true;\n        for( int to : gr[v] ){\n            if( to == c ) continue;\n            if( mt[to]==-1 || try_kuhn(mt[to]) ){\n                mt[to] = v;\n                return true;\n            }\n        }\n        return false;\n    }\n\n    void solve(){\n        n = sc.nextInt();\n        m = sc.nextInt();\n        grid = new boolean[n+1][n+1];\n        gr = new ArrayList[n+1];\n        for( int v = 1; v <= n; ++v ) gr[v] = new ArrayList<Integer>();\n        for( int it = 0; it < m; ++it ){\n            int a = sc.nextInt();\n            int b = sc.nextInt();\n            grid[a][b] = true;\n            gr[a].add(b);\n        }\n\n        int ans = Integer.MAX_VALUE;\n        for( c = 1; c <= n; ++c ){\n            int curAns = 0;\n            for( int v = 1; v <= n; ++v )\n                if( v != c ){\n                    if( !grid[c][v] ) ++curAns;\n                    if( !grid[v][c] ) ++curAns;\n                }\n            if( !grid[c][c] ) ++curAns;\n\n            mt = new int[n+1];\n            fill( mt, -1 );\n            for( int i = 1; i <= n; ++i )\n                if( i != c ){\n                    u = new boolean[n+1];\n                    try_kuhn(i);\n                }\n\n            int szMt = 0;\n            for( int i = 1; i <= n; ++i )\n                if( mt[i] != -1 )\n                    ++szMt;\n            curAns += n - 1 - szMt;\n\n            for( int a = 1; a <= n; ++a ){\n            for( int b : gr[a] ){\n                if( a==c || b==c ) continue;\n                if( a!=mt[b] ) ++curAns;\n            }\n            }\n\n//            out.printf( \"%d %d\\n\", c, curAns );\n            ans = min( ans, curAns );\n        }\n        out.println( ans );\n    }\n\n\n\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        boolean[][] map = new boolean[n][n];\n        int m = in.nextInt();\n\n        int[] us = new int[m];\n        int[] vs = new int[m];\n\n        for (int i = 0; i < m; ++i) {\n            int u = in.nextInt() - 1;\n            int v = in.nextInt() - 1;\n            map[u][v] = true;\n\n            us[i] = u;\n            vs[i] = v;\n        }\n\n        int ans = Integer.MAX_VALUE;\n        for (int center = 0; center < n; ++center) {\n            int fixed = 0;\n            for (int i = 0; i < n; ++i) {\n                if (!map[center][i]) {\n                    ++fixed;\n                }\n                if (!map[i][center] && i != center) {\n                    ++fixed;\n                }\n            }\n\n            MaxFlow flow = new MaxFlow(n * 2 + 2, n * 2, n * 2 + 1);\n\n            for (int i = 0; i < n; ++i) {\n                if (i == center) continue;\n                flow.insert(n * 2, i, 1);\n                flow.insert(i + n, n * 2 + 1, 1);\n            }\n\n            for (int i = 0; i < m; ++i) {\n                if (us[i] == center || vs[i] == center) {\n                    continue;\n                }\n\n                flow.insert(us[i], vs[i] + n, 1);\n                ++fixed;\n            }\n\n            ans = Math.min(ans, fixed + (n - 1) - 2 * flow.maxFlow());\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\nclass MaxFlow\n{\n    public class Edge\n    {\n        public int u,v,c;\n        public Edge next,r;\n\n        public Edge(int u,int v,int c)\n        {\n            this.u = u;\n            this.v = v;\n            this.c = c;\n            next = r = null;\n        }\n    }\n\n    public Edge vertex[];\n    public int height[], nheight[];\n    public int s, t, n;\n\n    public void init(int n,int s,int t)\n    {\n        height = new int[n+1];\n        nheight = new int[n+1];\n        vertex = new Edge[n+1];\n        this.s = s;\n        this.t = t;\n        this.n = n;\n    }\n\n    public MaxFlow(int n,int s,int t)\n    {\n        init(n,s,t);\n    }\n\n    public void insert(int u,int v,int c)\n    {\n        Edge e = new Edge(u,v,c);\n        Edge r = new Edge(v,u,0);\n        e.r = r;\n        r.r = e;\n        e.next = vertex[u];\n        vertex[u] = e;\n        r.next = vertex[v];\n        vertex[v] = r;\n    }\n\n    public int augPath(int u,int push)\n    {\n        if (u == t) return push;\n        int flow = push, minheight = n-1;\n        for (Edge e = vertex[u]; e != null; e = e.next)\n            if (e.c != 0)\n            {\n                if (height[e.v] + 1 == height[e.u])\n                {\n                    int delta = flow < e.c ? flow : e.c;\n                    if (delta > 0)\n                        delta = augPath(e.v,delta);\n                    e.c -= delta;\n                    e.r.c += delta;\n                    flow -= delta;\n                    if (0 == flow || height[s] >= n) return push - flow;\n                }\n                minheight = Math.min(minheight, height[e.v]);\n            }\n        if (push == flow)\n        {\n            --nheight[height[u]];\n            if (0 == nheight[height[u]]) height[s] = n;\n            height[u] = ++minheight;\n            ++nheight[height[u]];\n        }\n        return push - flow;\n    }\n\n    public int maxFlow()\n    {\n        Arrays.fill(height, 0);\n        Arrays.fill(nheight, 0);\n        nheight[0] = n;\n        int flow = 0;\n        while (height[s] < n)\n            flow += augPath(s,Integer.MAX_VALUE);\n        return flow;\n    }\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import com.sun.java_cup.internal.runtime.virtual_parse_stack;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by ali on 2/3/14.\n */\npublic class D\n{\n\tpublic static void main(String [] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\n\t\tboolean [][] graph = new boolean[n][n];\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\n\t\t\tgraph[a][b] = true;\n\t\t}\n\n\t\tint res = Integer.MAX_VALUE;\n\t\tfor(int center = 0 ; center < n ; center++)\n\t\t{\n\t\t\tint calc = 0;\n\t\t\tfor(int i = 0 ; i < n ; i++)\n\t\t\t{\n\t\t\t\tif(!graph[center][i])\n\t\t\t\t\tcalc++;\n\t\t\t\tif(!graph[i][center])\n\t\t\t\t\tcalc++;\n\t\t\t}\n\n\t\t\tif(!graph[center][center])\n\t\t\t\tcalc--;\n\n\t\t\tint [] match = new int[n];\n\t\t\tArrays.fill(match, -1);\n\t\t\tint max = 0;\n\n\t\t\tfor(int i = 0 ; i < n ; i++)\n\t\t\t\tif(i != center)\n\t\t\t\t\tif(can(i, graph, new boolean[n], center, match))\n\t\t\t\t\t\tmax++;\n\n\t\t\tint unusable = m - (2*n - 1 - calc) - max;\n\t\t\tcalc += unusable;\n\t\t\tcalc += (2*(n-1) - 2*max)/2;\n\n\t\t\tres = Math.min(res, calc);\n\t\t}\n\n\t\tSystem.out.println(res);\n\n\n\t}\n\n\tprivate static boolean can(int at, boolean[][] graph, boolean[] visited, int center, int [] match)\n\t{\n\t\tif(visited[at])\n\t\t\treturn false;\n\t\tvisited[at] = true;\n\n\t\tfor(int to = 0 ; to < graph.length ; to++)\n\t\t\tif(graph[at][to])\n\t\t\t\tif(to != center)\n\t\t\t\t\tif(match[to] == -1 || can(match[to], graph, visited, center, match))\n\t\t\t\t\t{\n\t\t\t\t\t\tmatch[to] = at;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\n\t\treturn false;\n\t}\n}\n", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\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 */\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\nclass TaskD {\n        ArrayList<Integer>[] g;\n        int n, m;\n        boolean[][] have;\n        int[] x;\n        int[] y;\n        boolean[] used;\n        int stop;\n        \n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n                n = in.nextInt();\n                g = new ArrayList[n];\n                for (int i = 0; i < n; i++)\n                        g[i] = new ArrayList<>();\n                have = new boolean[n][n];\n                m = in.nextInt();\n                for (int i = 0; i < m; i++) {\n                        int a = in.nextInt();\n                        int b = in.nextInt();\n                        --a;\n                        --b;\n                        g[a].add(b);\n                        have[a][b] = true;\n                }\n                int res = Integer.MAX_VALUE;\n                for (int center = 0; center < n; center++)\n                        res = Math.min(res, solve(center));\n                out.print(res);\n        }\n\n        int solve(int v) {\n                stop = v;\n                int withV = 0;\n                int add = 0;\n                for (int i = 0; i < n; i++)\n                        if (i != v)\n                                if (have[v][i])\n                                        withV++;\n                                else\n                                        add++;\n                for (int i = 0; i < n; i++)\n                        if (i != v)\n                                if (have[i][v])\n                                        withV++;\n                                else\n                                        add++;\n                if (have[v][v])\n                        withV++;\n                else\n                        add++;\n                x = new int[n];\n                y = new int[n];\n                used = new boolean[n];\n                Arrays.fill(x, -1);\n                Arrays.fill(y, -1);\n                int matched = 0;\n                for (int i = 0; i < n; i++)\n                        if (i != v && x[i] == -1) {\n                                Arrays.fill(used, false);\n                                if (dfs(i))\n                                        matched++;\n                        }\n                add += n - 1 - matched;\n                add += m - withV - matched;\n                return add;\n        }\n        \n        boolean dfs(int v) {\n                if (used[v])\n                        return false;\n                used[v] = true;\n                for (int to : g[v])\n                        if (to != stop && y[to] == -1) {\n                                x[v] = to;\n                                y[to] = v;\n                                return true;\n                        }\n                for (int to : g[v])\n                        if (to != stop && dfs(y[to])) {\n                                x[v] = to;\n                                y[to] = v;\n                                return true;\n                        }\n                return false;\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", "complexity": "cubic", "problem": "387_D. George and Interesting Graph", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class P23A {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString input = scan.nextLine();\n\t\tSystem.out.println(F(input));\n\t}\n\t\n\t\n\tstatic int F(String string){\n\t\tint ans =0;\n\t\tfor (int i = 0; i < string.length(); i++) {\n\t\t\tfor (int j = 1; j < string.length()-i; j++) {\n\t\t\t\tString s = string.substring(i, i+j);\n\t\t\t\tint a=string.indexOf(s);\n\t\t\t\tint b=string.lastIndexOf(s);\n\t\t\t\tif ( a >= 0 && b >=0 && a !=b)  ans =Math.max(ans, s.length());\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    static Scanner sc = new Scanner(System.in);\n\n    public static void main(String[] args) {\n        String s = sc.next();\n        for (int l = s.length(); l > 0; --l) {\n            HashSet<String> set = new HashSet<String>();\n            for (int i = 0; i < s.length() - l + 1; ++i)\n                if (set.contains(s.substring(i, i + l))) {\n                    System.out.println(l);\n                    return;\n                } else {\n                    set.add(s.substring(i, i + l));\n                }\n        }\n        System.out.println(0);\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Prob023A\n{\n    public static void main( String[] Args )\n    {\n        Scanner scan = new Scanner( System.in );\n        String s = scan.next();\n\n        all: for ( int x = s.length() - 1; x >= 0; x-- )\n            for ( int y = 0; x + y <= s.length(); y++ )\n            {\n                String sub = s.substring( y, y + x );\n                if ( s.indexOf( sub, y + 1 ) >= 0 )\n                {\n                    System.out.println( x );\n                    break all;\n                }\n            }\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\n\npublic class A23 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tMap<String, Boolean> map = new HashMap<String, Boolean>();\n\t\tfor (int i = s.length(); i >= 1; i--) {\n\t\t\tmap.clear();\n\t\t\tfor (int j = 0; j < s.length()-i+1; j++) {\n\t\t\t\tString temp = s.substring(j, j+i);\n\t\t\t\tif (map.containsKey(temp)) {\n\t\t\t\t\tSystem.out.println(i);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tmap.put(temp, true);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(0);\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "/**\n * MxNINJA 04:06:52 \u0635 14/01/2014\n */\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder line = new StringBuilder(reader.readLine());\n        int length = 0;\n        for (int head = 0; head < line.length(); head++) {\n            for (int tail = line.length() - 1; tail > head; tail--) {\n                String subString = line.substring(head, tail);\n                if(line.indexOf(subString,head+1)>-1){\n                    length = Math.max(subString.length(), length);\n                }\n            }\n        }\n        System.out.println(length);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class YouAreGivenAString {\n\tpublic static void main(String[] args) throws Exception {\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\tint max=0;\n\t\tfor(int i=1;i<s.length();i++){\n\t\t\tfor (int j = 0; j <= s.length()-i; j++) {\n\t\t\t\tString sub=s.substring(j,j+i);\n\t\t\t\tif(count(s,sub)>=2)\n\t\t\t\tmax=Math.max(max, i);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\n\tprivate static int count(String s, String sub) {\n\t\tint l=sub.length();\n\t\tint c=0;\n\t\tfor(int i=0;i<=s.length()-l;i++){\n\t\t\tif(s.substring(i,i+l).equals(sub))\n\t\t\t\tc++;\n\t\t}\n\t\treturn c;\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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        String a = r.next();\n        char[] c = a.toCharArray();\n        \n        for(int l = a.length()-1; l >= 1; l--){\n            for(int i = 0; i <= a.length()-l; i++){\n                int j = i+l-1;\n                \n                for(int s = 0; s <= a.length()-l; s++){\n                    if(i == s)continue;\n                    if(a.substring(i, i+l).equals(a.subSequence(s, s+l))){\n                        System.out.println(l);\n                        System.exit(0);\n                    }\n                        \n                }\n            }\n        }\n        \n        System.out.println(0);\n        \n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tpublic static void main( String[] args ){\n\t\tScanner cin = new Scanner( System.in );\n\t\tString s = cin.next();\n\t\tint n = s.length();\n\t\tchar[] ss = new char[ n ];\n\t\tss = s.toCharArray();\n\t\t\n\t\tint ans = 0;\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\tint k = 0;\n\t\t\t\twhile ( i+k<n && j+k<n && ss[i+k] == ss[j+k] ) k++;\n\t\t\t\t\n\t\t\t\tans = Math.max( ans, k );\n\t\t\t}\n\t\t\n\t\tSystem.out.println( ans );\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class prob1 {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tString s = input.next();\n\t\tint n = s.length();\n\t\tint i = n-1;\n\t\tCharSequence temp;\n\t\tfor(i = n-1; i > 0; i--)\n\t\t\tfor(int j = 0 ; j <= n-i; j++)\n\t\t\t{\n\t\t\t\ttemp = s.subSequence(j, i+j);\n\t\t\t\tif( s.substring(j+1, n).contains(temp) || s.substring(0, j+i-1).contains(temp))\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(i);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\tSystem.out.println(0);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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\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\t\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tString s = in.readLine();\n\t\t\n\t\tfor (int len = s.length() - 1; len > 0; len--) {\n\t\t\tSet<String> set = new HashSet<String>();\n\t\t\tfor (int i = 0; i + len <= s.length(); i++) {\n\t\t\t\tString ss = s.substring(i, i + len);\n\t\t\t\tif (set.contains(ss)) {\n\t\t\t\t\tout.println(len);\n\t\t\t\t\tout.close();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tset.add(ss);\n\t\t\t}\n\t\t}\n\t\tout.println(0);\n\t\tout.close();\n\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\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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class a {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\t\n\t\tint len = s.length();\n\t\tfor(int i=len-1; i>=1; --i) {\n\t\t\tfor(int j=0; j<=len - i; ++j) {\n\t\t\t\tString ss = s.substring(j, j+i);\n\n\t\t\t\tif(s.substring(j+1).indexOf(ss)!=-1) {\n\t\t\t\t\tSystem.out.println(ss.length());\n\t\t\t\t\treturn;\n\t\t\t\t} \n\t\t\t}\n\t\t}\n\t\tSystem.out.println(0);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tString s = next();\n\t\tfor (int len = s.length(); len >= 1; len--) {\n\t\t\tfor (int i = 0; i + len <= s.length(); i++)\n\t\t\t\tfor (int j = i + 1; j + len <= s.length(); j++)\n\t\t\t\t\tif (s.substring(i, i + len).equals(s.substring(j, j + len))) {\n\t\t\t\t\t\tout.print(len);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t}\n\t\tout.print(0);\n\t}\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\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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable\n{\n  Scanner in;\n  PrintWriter out; //= new PrintWriter(System.out);\n\n  public static void main(String[] args) throws FileNotFoundException, IOException\n  {\n    new Thread(new Main()).start();\n  }\n\n  public class Pair\n  {\n    public long last;\n    public long count;\n    public int L;\n    Pair(long l, long c) {last = l; count = c;}\n    Pair(long l, long c, int L) {last = l; count = c; this.L = L;}\n  }\n\n  public void run()\n  {\n    final String name = \"B-small\";\n    //try {\n      in = new Scanner(System.in);// (new File(name + \".in\"));//StreamTokenizer(new FileReader(new File(name + \".in\")));\n      out = new PrintWriter(System.out); // new PrintWriter(new File(name + \".out\")); //= new PrintWriter(System.out);\n    //} catch (IOException e) {}\n\n\n    String s = in.next().trim();\n    int n = s.length();\n    boolean[][] a = new boolean[n][n];\n\n   for (int i = 0; i < n; ++i)\n     for (int j = i + 1; j < n; ++j)\n       a[i][j] = (s.charAt(i) == s.charAt(j));\n\n    int max = 0;\n    for (int i = 0; i < n; ++i)\n     for (int j = i + 1; j < n; ++j)\n     {\n       int k =0;\n       while (i + k < n && j + k < n && a[i + k][j + k])\n           ++k;\n       \n       if (max < k)\n           max = k;\n     }\n    \n    out.println(max);\n    out.flush();\n  }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashSet;\nimport java.util.Locale;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class A {\n    private BufferedReader in;\n    private StringTokenizer st;\n    private PrintWriter out;\n\n    private void solve() throws IOException {\n        String s = next();\n        for (int length = s.length() - 1; length > 0; --length) {\n            Set<String> h = new HashSet<String>();\n            int count = 0;\n            for (int i = 0; i + length <= s.length(); ++i) {\n                h.add(s.substring(i, i + length));\n                ++count;\n            }\n            if (count != h.size()) {\n                out.println(length);\n                return;\n            }\n        }\n        out.println(0);\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    private void eat(String s) {\n        st = new StringTokenizer(s);\n    }\n\n    private 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    private int 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 BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(next());\n    }\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        new A().run();\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class A0023 {\n\n    public static void main(String args[]) throws Exception {\n        new A0023();\n    }\n\n    A0023() throws Exception {\n        PandaScanner sc = null;\n        PrintWriter out = null;\n        try {\n            sc = new PandaScanner(System.in);\n            out = new PrintWriter(System.out);\n        } catch (Exception ignored) {\n        }\n\n        String s = sc.next();\n        int i = s.length() - 1;\n        Test: for (; i > 0; i--) {\n            HashSet<String> set = new HashSet<String>();\n            for (int j = 0; j + i <= s.length(); j++) {\n                String ss = s.substring(j, j + i);\n                if (set.contains(ss)) {\n                    break Test;\n                }\n                set.add(ss);\n            }\n        }\n        out.println(i);\n\n        out.close();\n        System.exit(0);\n    }\n\n\n    //The PandaScanner class, for Panda fast scanning!\n    public class PandaScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        InputStream in;\n\n        PandaScanner(InputStream in) throws Exception {\n            br = new BufferedReader(new InputStreamReader(this.in = in));\n        }\n\n        public String next() throws Exception {\n            if (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(br.readLine().trim());\n                return next();\n            }\n            return st.nextToken();\n        }\n\n        public boolean hasNext() throws Exception {\n            return (st != null && st.hasMoreTokens()) || in.available() > 0;\n        }\n\n        public long nextLong() throws Exception {\n            return Long.parseLong(next());\n        }\n\n        public int nextInt() throws Exception {\n            return Integer.parseInt(next());\n        }\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\npublic class ProblemA {\n\t\n\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tString line = s.readLine();\n\t\tint len = line.length();\n\t\tint max = 0;\n\t\tfor (int i = 0 ; i < len ; i++) {\n\t\t\tfor (int j = i+1 ; j <= len ; j++) {\n\t\t\t\tString sch = line.substring(i, j);\n\t\t\t\tfor (int k = i+1 ; k + (j - i) <= len ; k++) {\n\t\t\t\t\tString tch = line.substring(k, k+(j-i));\n\t\t\t\t\tif (sch.equals(tch)) {\n\t\t\t\t\t\tmax = Math.max(max, (j-i));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(max);\n\t\tout.flush();\n\t}\n\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class A23 {\n    public static void main(String[] args) throws IOException   {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String s = br.readLine();\n        for(int length = s.length(); length > 0; length--)      {\n            for(int start = 0; start + length <= s.length(); start++)       {\n                String test = s.substring(start, start+length);\n                if(s.indexOf(test) != s.lastIndexOf(test))  {\n                    System.out.println(length);\n                    return;\n                }\n            }\n        }\n        System.out.println(0);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "//package arbuz;\n\nimport java.util.Scanner;\n\npublic class Arbuz {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        String s = sc.next();\n        int i, j, current, longest = 0;\n        for (i = 0; i < s.length(); i++) {\n            for (j = 0; j < s.length(); j++) {\n                if (i != j) {\n                    int ti = i, tj = j;\n                    current = 0;\n                    while (ti < s.length() && tj < s.length() && s.charAt(ti) == s.charAt(tj)) {\n                        current++;\n                        ti++;\n                        tj++;\n                    }\n                    if (current > longest) {\n                        longest = current;\n                    }\n                }\n            }\n        }\n        System.out.println(longest);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "// by agus.mw\nimport java.util.*;\nimport java.io.*;\n\npublic class Main{\n  public static void main(String[] args) throws Exception {\n    new Main().doWork();\n  }\n  void doWork() throws Exception{\n    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));\n    \n    String text = reader.readLine().trim();\n    int out = 0;\n    for(int i=0;i<text.length();i++){\n      for(int j=i+1;j<text.length();j++){\n        for(int len = out+1;len+j<=text.length();len++){\n          if(text.substring(i,i+len).compareTo(text.substring(j,j+len))==0){\n            out = len;\n          }\n        }\n      }\n    }\n    String buf = \"\"+out;\n    writer.write(buf,0,buf.length());\n    writer.newLine();\n    writer.flush();\n    writer.close();\n    reader.close();\n  }\n  String process(){\n    return \"1\";\n  }\n  int[] toIntArray(String line){\n    String[] p = line.split(\"[ ]+\");\n    int[] out = new int[p.length];\n    for(int i=0;i<p.length;i++) out[i] = Integer.valueOf(p[i]);\n    return out;\n  }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\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 GivenString {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        String line = sc.nextLine();\n\n        String sub = \"\";\n        int count = 0;\n        int max = 0;\n        for (int i = 0; i < line.length() - 1; i++) {\n            sub = line.substring(i, i + 1);\n\n            int q = i + 1;\n            int p;\n            int r = i;\n            while (q < line.length() && q > 0) {\n                p = q;\n                r = i;\n                int ind = line.indexOf(sub, p);\n                count = 0;\n                if (ind != -1) {\n                    for (int j = ind; j < line.length(); j++) {\n                        if (line.substring(j, j + 1).equalsIgnoreCase(line.substring(r, r + 1))) {\n                            r++;\n                            count++;\n                        } else {\n                            break;\n                        }\n                    }\n                    if (count > max) {\n                        max = count;\n                    }\n                }\n                q = ind + 1;\n                \n            }\n\n        }\n\n        System.out.println(max);\n\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\npublic class Main {\n\n    static Scanner cin = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n    static PrintWriter cout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    public static void main(String[] agrs) throws IOException{\n        \n        String line = cin.nextLine();\n        \n        HashMap<String, Integer> map = new HashMap<String, Integer>();\n        int ans = 0;\n        for (int i = 0; i < line.length(); ++i) {\n            StringBuffer str = new StringBuffer(\"\");\n            for (int j = i; j < line.length(); ++j) {\n                str.append(line.charAt(j));\n                \n                if (!map.containsKey(str.toString())) {\n                    //cout.println(str.toString());\n                    map.put(str.toString(), 1);\n                } else {\n                    ans = str.length() > ans ? str.length() : ans;\n                }\n            }\n        }\n        \n        cout.println(ans);\n        \n        cin.close();\n        cout.close();\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n/**\n * @author Alexander Grigoryev\n *         Created on 01.08.11\n */\npublic\nclass Main\n{\n    static Scanner in = new Scanner(System.in);\n\n    public static\n    void main(String[] args)\n    {\n        String s = in.nextLine();\n        int k, ans = 0;\n\n        for(int i = 0; i < s.length(); i++)\n            for(int j = i + 1; j < s.length(); j++)\n            {\n                for(k = 0; j + k < s.length(); k++)\n                {\n                    if(s.charAt(i + k) != s.charAt(j + k)) break;\n                }\n                if(ans < k) ans = k;\n            }\n        System.out.println(ans);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class Main {\n\n    /**\n     * @param args\n     */\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        String s = sc.next(),c;\n        int n = s.length(),a,b;\n        \n        for(int sz = n ; sz >= 1 ; sz--) {\n            for(int i = 0 ; i+sz <= n ; i++) {\n                c = s.substring(i, i+sz);\n                a = s.indexOf(c,0);\n                if(a < 0) continue;\n                b = s.indexOf(c,a+1);\n                if(b < 0) continue;\n                System.out.println(sz);\n                return;\n                \n            } // for j\n        } // for i\n        System.out.println(0);\n\n    }\n\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class St {\n\n    static void metod() throws Exception {\n        Scanner in = new Scanner(System.in);\n        String str = in.next();\n\n        int max = 0;\n        for (int i = 0; i < str.length(); i++) {\n            for (int j = i + 1; j < str.length() + 1; j++) {\n\n                for (int k = 0; k < str.length(); k++) {\n                    for (int n = k + 1; n < str.length() + 1; n++) {\n\n                        if ((str.substring(i, j).equals(str.substring(k, n)))\n                                && (k != i)) {\n                            if (j - i > max)\n                                max = j - i;\n                        }\n                    }\n                }\n            }\n        }\n        System.out.println(max);\n    }\n\n    public static void main(String args[]) throws Exception {\n        St.metod();\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class test \n{    \n    static boolean isOK(String str, int len)\n    {\n\tHashSet<String> hs=new HashSet<String>();\n\t\n\tfor(int i=0;i<=str.length()-len;i++)\n\t{\n\t    String s=str.substring(i,len+i);\n\t    if(hs.contains(s))\n\t\treturn true;\n\t    else\n\t\ths.add(s);\n\t}\n\t\n\treturn false;\n    }\n    public static void main(String[] args) \n    {\n        Scanner in=new Scanner(System.in);\n        String str=in.next();\n        \n        int i;\n        for(i=str.length()-1;i>=1;i--)\n            if(isOK(str,i))\n            {\n        \tbreak;\n            }\n        \n        System.out.println(i);\n    }\n}\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class givenstring {\n\tpublic static void main(String[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tString in = reader.next();\n\t\t\n\t\tint max = 0;\n\t\t\n\t\tfor(int i = 0; i < in.length(); i++){\n\t\t\tfor(int j = i+1; j < in.length(); j++){\n\t\t\t\t//take this substring\n\t\t\t\tString consider = in.substring(i, j);\n\t\t\t\tfor(int k = i+1; k < in.length(); k++){\n\t\t\t\t\tif(k + consider.length() > in.length())\n\t\t\t\t\t\tbreak;\n\t\t\t\t\telse if(in.substring(k, k+consider.length()).equals(consider))\n\t\t\t\t\t\tmax = Math.max(max, consider.length());\t\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}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class A {\n    \n    Scanner sc = new Scanner(System.in);\n    \n    void run(){\n        \n        String s = sc.next();\n        String subS;\n        int max = 0;\n        \n        for (int i=0;i<s.length();i++) {\n            for (int j=i+1;j<s.length()+1;j++) {\n                \n                \n                subS = s.substring(i, j);\n                \n                for (int k=i+1;k<s.length();k++) {\n                    \n                \n                    if ( s.startsWith(subS,k) ){\n                        if ( max < subS.length() )\n                            max = subS.length();\n                    }\n                }\n                \n            }\n        }\n        \n        System.out.println(max);\n        return;\n        \n    }\n    \n    public static void main(String[] args){\n        \n        new A().run();\n        \n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class DoubleWord implements Runnable {\n\n    boolean isLocalMode =false;\n\n\n    private void doJob() throws Exception {\n        //do here\n        String s = nextToken();\n                int max=0;\n        for(int i = 0;i<s.length();i++){\n            for(int j=i+1;j<s.length()+1;j++){\n                String s1 = s.substring(i, j);\n                if(s.substring(i+1).contains(s1)){\n                    max = Math.max(max,s1.length());\n                }\n            }\n        }\n        writer.write(\"\"+max);\n    }\n\n\n    public static void main(String[] args) {\n        new DoubleWord().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\n    public void run() {\n        try {\n            reader = new BufferedReader(getReader());\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            //do job\n            doJob();\n            reader.close();\n            writer.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\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    public Reader getReader() throws FileNotFoundException {\n        if (isLocalMode) {\n            return new FileReader(\"input.txt\");\n        } else {\n            return new InputStreamReader(System.in);\n        }\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main {\n    \n    void run() throws IOException {\n        String s = token();\n        HashSet <String> h;\n        int n = s.length();\n        int r = 0;\n        loop: for (int i = 1; i <= n; i++) {\n            h = new HashSet();\n            for (int j = 0; j < n - i + 1; j++) {\n                String t = s.substring(j, j + i);\n                if (h.contains(t)) {\n                    r = i;\n                    continue loop;\n                } else {\n                    h.add(t);\n                }\n            }\n        }\n        System.out.println(r);\n    }\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        //final String FILENAME = \"dvd\";\n        //in = new BufferedReader(new FileReader(new File(FILENAME + \".in\")));\n        //out = new PrintWriter(new File(FILENAME + \".out\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        //in = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        st = new StringTokenizer(\" \");\n        new Main().run();\n        out.close();\n    }\n\n    static BufferedReader in;\n    //static Scanner in;\n    static PrintWriter out;\n    static StringTokenizer st;\n\n    String token() throws IOException {\n        while (!st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nint() throws IOException {\n        return Integer.parseInt(token());\n    }\n\n    long nlong() throws IOException {\n        return Long.parseLong(token());\n    }\n\n    double ndouble() throws IOException {\n        return Double.parseDouble(token());\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class A implements Runnable {\n    private void solve() throws IOException {\n        String str = nextToken();\n        for (int i=str.length()-1; i>=0; --i)\n            for (int j=0; j+i<=str.length(); ++j)\n                if (str.substring(j+1).contains(str.substring(j, j+i))) {\n                    writer.println(i);\n                    return;\n                }\n        writer.println(0);\n    }\n\n    public static void main(String[] args) {\n        new Thread(new A()).start();\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}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\t/**\n\t * @author hunglee\n\t */\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tStreamTokenizer in = new StreamTokenizer(new BufferedReader(\n\t\t\t\tnew InputStreamReader(System.in)));\n\t\t\n\t\tin.nextToken();\n\t\tString s = in.sval;\n\t\tint l = s.length();\n\t\tint n = l - 1;\n\t\tString st, sub;\n\t\twhile (n > 0) {\n\t\t\tfor (int i = 0; i < l - n; ++i) {\n\t\t\t\tst = s.substring(i, n + i);\n\t\t\t\tsub = s.substring(i + 1);\n\t\t\t\tif (sub.indexOf(st) != -1) {\n\t\t\t\t\tSystem.out.println(n);\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tn--;\n\t\t}\n\t\tSystem.out.println(0);\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class OverlapedString {\n\tpublic static void main(String args[]) throws Exception {\n\t\tOverlapedString os = new OverlapedString();\n\t\tBufferedReader stdin =\n\t\t\tnew BufferedReader(new InputStreamReader(System.in));\n\t\tString line;\n\t\twhile ((line = stdin.readLine()) != null) {\n\t\t\tSystem.out.println(os.handleOverlap(line));\n\t\t}\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;i<len;i++)\n\t\t\tfor(int j=i+1;j<len;j++) {\n\t\t\t\tString _tmp = str.substring(i,j);\n\t\t\t\tif(_tmp!=null&&_tmp.length()>0) {\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<str.length()) {\n\t\t\tstart = str.indexOf(sub,start);\n\t\t\tif(start==-1)\n\t\t\t\tbreak;\n\t\t\telse {\n\t\t\t\tstart++;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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\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\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\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 A(String inputFile)\n\t{\n\t\topenInput(inputFile);\n\t\t\n\t\treadNextLine();\n\t\tString s=line;\n\t\tint ret=0;\n\t\tfor(int i=0; i<s.length(); i++)\n\t\t{\n\t\t\tfor(int j=i+1; j<s.length()+1; j++)\n\t\t\t{\n\t\t\t\tString a=s.substring(i,\tj);\n\t\t\t\tif(s.indexOf(a, i+1)>-1)ret=Math.max(ret, a.length());\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ret);\n\t}\n\t\n}\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n\npublic class A {\n\n    public static void main(String[] args) throws IOException{\n        Scanner sc = new Scanner(System.in);\n        String s = sc.next();\n        int n = s.length();\n        for (int i = n; i >= 1; i--) {\n            Set<String> set = new HashSet<String>();\n            for (int j = 0; j < n-i+1; j++) {\n                String t = s.substring(j, j+i);\n                if (set.contains(t)) {\n                    System.out.println(i);\n                    return;\n                }\n                set.add(t);\n            }\n        }\n        System.out.println(0);\n    }\n    \n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class A\n{\n   public static void main(String[] args)\n   {\n      new A(new Scanner(System.in));\n   }\n\n   public A(Scanner in)\n   {\n      TreeSet<String> ts = new TreeSet<String>();\n      ArrayList<String> sr = new ArrayList<String>();\n\n      String s = in.next();\n      for (int i=0; i<s.length(); i++)\n      {\n         for (int j=i+1; j<=s.length(); j++)\n         {\n            String ss = s.substring(i, j);\n            if (ts.contains(ss))\n            {\n               sr.add(ss);\n            }\n            ts.add(ss);\n         }\n      }\n\n      int res = 0;\n      for (String ss : sr)\n      {\n         if (ss.length() > res)\n            res = ss.length();\n      }\n\n      System.out.printf(\"%d%n\", res);\n   }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    static Scanner sc = new Scanner(System.in);\n\n    public static void main(String[] args) {\n        String s = sc.next();\n        for (int l = s.length(); l > 0; --l) {\n            HashSet<String> set = new HashSet<String>();\n            for (int i = 0; i < s.length() - l + 1; ++i)\n                if (set.contains(s.substring(i, i + l))) {\n                    System.out.println(l);\n                    return;\n                } else {\n                    set.add(s.substring(i, i + l));\n                }\n        }\n        System.out.println(0);\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class YouAreGivenAString {\n\n    void run() {\n        try {\n            BufferedReader bfd = new BufferedReader(new InputStreamReader(\n                    System.in));\n            int i, j, k, mxLen = 0;\n            String s= bfd.readLine();\n            for(i=0; i<s.length(); ++i){\n                for(j=i+1; j<s.length()+1; ++j){\n                    String s2 = s.substring(i, j);\n                    if(s2.length()<=mxLen) continue;\n                    int cnt=0;\n                    for(k=0; k<s.length(); ++k){\n                        if(s.length()>=k+s2.length())\n                        if(s2.equals(s.substring(k,k+s2.length()))){\n                            cnt++;\n                            if(cnt>1)mxLen = Math.max(mxLen, s2.length());\n                        }\n                    }\n                }\n            }\n            System.out.println(mxLen);\n        } catch (Exception e) {\n\n        }\n    }\n    public static void main(String[] args) {\n        new YouAreGivenAString().run();\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Word {\n    static String word;\n\n    private static void check(String subword) {\n        int i = 0;\n        int j = 0;\n        while (j + subword.length() <= word.length()) {\n            if (word.substring(j).startsWith(subword)){\n                i++;\n            }\n            j++;\n        }\n        if (i > 1){\n            System.out.println(subword.length());\n            System.exit(0);\n        }\n    }\n\n    public static void main(String[] arg) {\n        Scanner in = new Scanner(System.in);\n        word = in.next();\n        if (word.length() == 1) {\n            System.out.println(0);\n            return;\n        }\n        for (int i = word.length() - 1; i > 0; i--) {\n            int j = 0;\n            while (j + i <= word.length()) {\n                check(word.substring(j, i+j));\n                j++;\n            }\n        }\n        System.out.println(0);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class YoureGivenAString {\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        String str = f.readLine();\n        int max = 0;\n        for (int i = 0; i < str.length(); i++)\n            for (int j = i+1; j <= str.length(); j++) {\n                String s = str.substring(i,j);\n                if (str.indexOf(s) >= 0 && str.substring(str.indexOf(s)+1).indexOf(s) >= 0)\n                    max = Math.max(max, j-i);\n            }\n        System.out.println(max);\n    }   \n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n/**\n * User: alms\n * Date: 09.07.2010\n * Time: 18:57:44\n */\npublic class Solution {\n    public static void main(String[] args) throws Exception {\n        final String str;\n        final BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n        str = r.readLine();\n\n        int max = 0;\n\n        for (int x = 0; x  < str.length(); x++) {\n            for (int y = x + 1; y  < str.length(); y++) {\n                int c = 0;\n                for (;c + x < str.length() && y + c < str.length(); c++) {\n                    if (str.charAt(x + c) != str.charAt(y + c)) {\n                        break;\n                    }\n                }\n\n                if (c > max) {\n                    max = c;\n                }\n            }\n        }\n\n        System.out.println(max);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\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 A {\n\n    public static void main(String[] args) throws FileNotFoundException, IOException {\n        Scanner in = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n        String val = in.next();\n        ArrayList<String> list = new ArrayList();\n        for(int i = 0; i < val.length() ; i++){\n            list.add(val.substring(i));\n        }\n        Collections.sort(list);\n        int result = 0;\n        for(int i = 1; i < list.size() ; i++){\n            String other = list.get(i - 1);\n            int temp = 0;\n            for(int j = 0; j < list.get(i).length() && j < other.length() ; j++){\n                if(other.charAt(j) == list.get(i).charAt(j)){\n                    temp++;\n                }else{\n                    break;\n                }\n            }\n            if(temp > result){\n                result = temp;\n            }\n        }\n        out.println(result);\n        out.close();\n    }\n\n    public static int dist(int x0, int y0, int x1, int y1) {\n        return (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1);\n    }\n\n    public static boolean isRight(int a, int b, int c) {\n        if (a == 0 || b == 0 || c == 0) {\n            return false;\n        }\n        if (a == b + c) {\n            return true;\n        }\n        if (b == a + c) {\n            return true;\n        }\n        if (c == a + b) {\n            return true;\n        }\n        return false;\n    }\n\n    public static int gcd(int a, int b) {\n        if (b == 0) {\n            return a;\n        }\n        return gcd(b, a % b);\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 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    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\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 FileReader(\"input.txt\"));\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}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Task {\n\n\tprivate static final boolean readFromFile = false;\n\t\n\tpublic static void main(String args[]){\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFileOutputStream fileOutputStream;\n\t\tFileInputStream fileInputStream;\n\t\tif (readFromFile){\n\t\t\ttry{\n\t\t\t\tfileInputStream = new FileInputStream(new File(\"input.txt\"));\n\t\t\t\tfileOutputStream = new FileOutputStream(new File(\"output.txt\"));\n\t\t\t}catch (FileNotFoundException e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\tPrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);\n\t\tInputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);\n\t\t\n\t\tSolver s = new Solver(in,out);\n\t\ts.solve();\n\t\t\n\t\tout.close();\n\t}\n}\n\nclass Solver{\n\tInputReader in;\n\tPrintWriter out;\n\t\n\tpublic void solve(){\n\t\tString s = in.nextLine();\n\t\tfor (int len=s.length()-1;len>=1;len--)\n\t\t\tfor (int i=0;i<s.length()-len+1;i++)\n\t\t\t\tfor (int j=i+1;j<s.length()-len+1;j++)\n\t\t\t\t\tif (s.substring(i,i+len).equals(s.substring(j,j+len))){\n\t\t\t\t\t\tout.println(len);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\tout.println(0);\n\t}\n\n\t\t\n\tSolver(InputReader in, PrintWriter out){\n\t\tthis.in=in;\n\t\tthis.out=out;\n\t}\n}\n\nclass InputReader{\n\tprivate BufferedReader buf;\n\tprivate StringTokenizer tok;\n\t\n\tInputReader(InputStream in){\n\t\ttok = null;\n\t\tbuf = new BufferedReader(new InputStreamReader(in));\n\t}\n\t\n\tInputReader(FileInputStream in){\n\t\ttok = null;\n\t\tbuf = new BufferedReader(new InputStreamReader(in));\n\t}\n\t\n\tpublic String next(){\n\t\twhile (tok==null || !tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(buf.readLine());\n\t\t\t}catch (IOException e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\t\n\tpublic int nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tpublic double nextDouble(){\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tpublic float nextFloat(){\n\t\treturn Float.parseFloat(next());\n\t}\n\t\n\tpublic String nextLine(){\n\t\ttry{\n\t\t\treturn buf.readLine();\n\t\t}catch (IOException e){\n\t\t\treturn null;\n\t\t}\n\t}\n\t\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main {\n    static BufferedReader reader \n        = new BufferedReader(new InputStreamReader(System.in));       \n    static StringBuilder out = new StringBuilder();\n\n    public static void main(String[] args){\n        solve();\n        return;\n    }\n\n    // the followings are methods to take care of inputs.\n    static int nextInt(){\n        return Integer.parseInt(nextLine());\n    }\n    static long nextLong(){\n        return Long.parseLong(nextLine());\n    }\n    static int[] nextIntArray(){\n        String[] inp = nextLine().split(\"\\\\s+\");\n        int[] ary = new int[inp.length];\n        for (int i = 0; i < ary.length; i++){\n            ary[i] = Integer.parseInt(inp[i]);\n        }\n        return ary;\n    }\n    static int[] nextIntArrayFrom1(){\n        String[] inp = nextLine().split(\"\\\\s+\");\n        int[] ary = new int[inp.length + 1];\n        for (int i = 0; i < inp.length; i++){\n            ary[i+1] = Integer.parseInt(inp[i]);\n        }\n        return ary;\n    }\n    static long[] nextLongArray(){\n        String[] inp = nextLine().split(\"\\\\s+\");\n        long[] ary = new long[inp.length];\n        for (int i = 0; i < inp.length; i++){\n            ary[i] = Long.parseLong(inp[i]);\n        }\n        return ary;\n    }\n    static long[] nextLongArrayFrom1(){\n        String[] inp = nextLine().split(\"\\\\s+\");\n        long[] ary = new long[inp.length + 1];\n        for (int i = 0; i < inp.length; i++){\n            ary[i+1] = Long.parseLong(inp[i]);\n        }\n        return ary;\n    }\n    static String nextLine(){\n        try { \n            return reader.readLine().trim();\n        } catch (Exception e){}\n        return null;\n    }\n    static void solve(){\n        String str = nextLine();\n        int max=0;\n        int index=0;\n        for(int i=0;i<str.length();i++){\n            for(int j=i+1;j<str.length();j++){\n                if(str.charAt(i)==str.charAt(j)){\n                    int count=1;\n                    while(true){\n                        if(str.length()<=i+count || str.length()<=j+count || str.charAt(i+count)!=str.charAt(j+count) ) \n                            break;\n                        count++;\n                    }\n                    if(max<count){\n                        max=count;\n                        index=i;\n                    }\n                }\n            }\n        }\n        System.out.println(max);\n\n        return;\n    }\n}\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A {\n\n    static Scanner sc = new Scanner(System.in);\n\n    public static void main(String[] args) {\n        String s = sc.next();\n        for (int l = s.length(); l > 0; --l) {\n            HashSet<String> set = new HashSet<String>();\n            for (int i = 0; i < s.length() - l + 1; ++i)\n                if (set.contains(s.substring(i, i + l))) {\n                    System.out.println(l);\n                    return;\n                } else {\n                    set.add(s.substring(i, i + l));\n                }\n        }\n        System.out.println(0);\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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.TreeSet;\nimport java.util.StringTokenizer;\nimport java.util.AbstractCollection;\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\tA solver = new A();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass A {\n    public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n        String s = in.next();\n        String[] ss = Substring.allSubstrings(s);\n        int res = 0;\n        for (String sss: ss) {\n            if (sss.length() <= res) continue;\n            if (Substring.occurences(s, sss).length > 1) {\n                res = sss.length();\n            }\n        }\n        out.println(res);\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\nclass Substring {\n\n    public static String[] allSubstrings(String s) {\n        TreeSet<String> substrings = new TreeSet<String>();\n        int n = s.length();\n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                substrings.add(s.substring(i, j));\n            }\n        }\n        return substrings.toArray(new String[0]);\n    }\n\n    public static int[] occurences(String s, String target) {\n        int n = s.length();\n        ArrayList<Integer> res = new ArrayList<Integer>();\n        int idx = s.indexOf(target);\n        while (idx != -1) {\n            res.add(idx);\n            if (idx == n - 1) break;\n            idx = s.indexOf(target, idx + 1);\n        }\n        n = res.size();\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = res.get(i);\n        }\n        return arr;\n    }\n}\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A {\n\tprivate static StreamTokenizer in;\n\tprivate static PrintWriter 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\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\t\tout = new PrintWriter(System.out);\n\n\t\tString s = nextString();\n\t\tint max = 0;\n\t\tfor (int i=0; i<s.length(); i++) {\n\t\t\tfor (int j=i+1; j<=s.length(); j++) {\n//\t\t\t\tSystem.out.println(i+ \" \"+ j);\n\t\t\t\tString u = s.substring(i,j);\n\t\t\t\tif (s.substring(i+1).indexOf(u) >= 0) {\n\t\t\t\t\tmax = Math.max(max, u.length());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(max);\n\t\t\n\t\tout.flush();\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class P1 {\n\tpublic static void main(String[] args) {\n\t\tString s = null;\n\t\t// citire\n\t\ttry {\n//\t\t\tScanner sc = new Scanner(new File(\"in.txt\"));\n\t\t\tScanner sc = new Scanner(System.in);\n\t\t\ts = sc.next();\n\t\t\t\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\t\n\t\tint n = s.length();\n\t\t\n\t\tHashSet<String> h = new HashSet<String>();\n\t\tString t=null;\n\t\tboolean b;\n\t\tint lmax = 0;\n\t\tfor (int i=0; i<n; i++) {\n\t\t\tfor (int j=i+1; j<=n; j++) {\n\t\t\t\tt = s.substring(i, j);\n\t\t\t\tb = h.add(t);\n//\t\t\t\tSystem.out.println(t + \"\t\"  + b);\n\t\t\t\tif (b==false) {\n\t\t\t\t\tif (j-i>lmax) {\n\t\t\t\t\t\tlmax = j-i;\n//\t\t\t\t\t\tSystem.out.println(t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(lmax);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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<String> h = new HashSet<String>();\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.add(now);\n            }\n\n        }\n\n        System.out.println(0);\n    }\n}\n        ", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\n/*************************************************************************\n *  Compilation:  javac LRS.java\n *  Execution:    java LRS < file.txt\n *  Dependencies: StdIn.java\n *  \n *  Reads a text corpus from stdin, replaces all consecutive blocks of\n *  whitespace with a single space, and then computes the longest\n *  repeated substring in that corpus. Suffix sorts the corpus using\n *  the system sort, then finds the longest repeated substring among \n *  consecutive suffixes in the sorted order.\n * \n *  % java LRS < mobydick.txt\n *  ',- Such a funny, sporty, gamy, jesty, joky, hoky-poky lad, is the Ocean, oh! Th'\n * \n *  % java LRS \n *  aaaaaaaaa\n *  'aaaaaaaa'\n *\n *  % java LRS\n *  abcdefg\n *  ''\n *\n *************************************************************************/\n\n\nimport java.util.Arrays;\n\npublic class LRS {\n\n    // return the longest common prefix of s and t\n    public static String lcp(String s, String t) {\n        int n = Math.min(s.length(), t.length());\n        for (int i = 0; i < n; i++) {\n            if (s.charAt(i) != t.charAt(i))\n                return s.substring(0, i);\n        }\n        return s.substring(0, n);\n    }\n\n\n    // return the longest repeated string in s\n    public static String lrs(String s) {\n\n        // form the N suffixes\n        int N  = s.length();\n        String[] suffixes = new String[N];\n        for (int i = 0; i < N; i++) {\n            suffixes[i] = s.substring(i, N);\n        }\n\n        // sort them\n        Arrays.sort(suffixes);\n\n        // find longest repeated substring by comparing adjacent sorted suffixes\n        String lrs = \"\";\n        for (int i = 0; i < N - 1; i++) {\n            String x = lcp(suffixes[i], suffixes[i+1]);\n            if (x.length() > lrs.length())\n                lrs = x;\n        }\n        return lrs;\n    }\n\n\n\n    // read in text, replacing all consecutive whitespace with a single space\n    // then compute longest repeated substring\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        s = s.replaceAll(\"\\\\s+\", \" \");\n        System.out.println(lrs(s).length());\n    }\n}\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\nimport java.io.InputStreamReader;\n\npublic 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        int max=0;\n        for(int i=0;i<s.length();i++){\n            int len=0;\n            int k=i;\n            boolean flag=false;\n            for(int j=i+1;j<s.length();j++){\n                if(s.charAt(k)==s.charAt(j)){\n                len++;\n                k++;\n                flag=true;\n                }\n                else if(flag==true){\n                    j=j-len;\n                    k=i;\n                    if(max<len)\n                    max=len;\n                    len=0;\n                    flag=false;\n                    \n                }\n                   \n            }\n            if(max<len)\n            max=len;\n        }\n        System.out.print(max);\n    }}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class substring\n{\npublic static void main(String[] args)\n{\nScanner input = new Scanner(System.in);\nString s = input.nextLine();\nBoolean found = false;\nint i = s.length();\nwhile(found==false)\n{\ni--;\nArrayList<String> sub = new ArrayList<String>();\nfor(int j = 0; j <= s.length() - i; j++)\n{\nif(sub.contains(s.substring(j, j+i)))\nfound = true;\nelse\nsub.add(s.substring(j, j+i));\n}\n\n}\nSystem.out.println(i);\n}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class Main20 {\n\n    static ArrayList<Integer> primes = new ArrayList<Integer>();\n    static boolean[] prime = new boolean[1001];\n    public static void gen(){\n        Arrays.fill(prime, true);\n        prime[0] = prime[1]  = false; \n        for (int i = 2; i < 1001; i++) {\n            if (prime[i]){\n                primes.add(i);\n                for (int j = i*2; j < 1001; j+=i)\n                    prime[j] = false;\n            }\n        }\n    }\n    public static boolean isVowel(char c){\n        Character r = Character.toLowerCase(c);\n        return (r == 'e' || r == 'a' || r == 'i' || r == 'o' ||  r == 'u'||  r == 'y');\n    }\n    public static void main(String[] args) throws IOException {\n        Scanner s = new Scanner(new InputStreamReader(System.in));\n        String str = s.next();\n        int x;\n        int max= 0;\n        \n        for (int i = 0; i < str.length()-1; i++) {\n            for (int j = i+1; j < str.length(); j++) {\n                x = str.indexOf(str.substring(i,j),i+1) ;\n                if (x != -1){\n                    if (j-i > max) max = j-i;\n                }\n            }\n        }\n        System.out.println(max);\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n//package substring;\nimport java.util.*;\n\n/**\n *\n * @author lav\n */\npublic class Main {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\n        Scanner scr = new Scanner(System.in);\n       // System.out.println(\"entet strig\");\n        String str = scr.nextLine();\n        int len =0;\n      //  System.out.println(str.substring(0, str.length()));\n        for(int i=0;i<(str.length()-1);i++)\n        {\n            for(int j=i+1;j<str.length();j++)\n            {\n                String sub = str.substring(i, j);\n                //int a=i+sub.indexOf(sub.charAt(0));\n                int ind = str.indexOf(sub, i+1);\n                if(ind!=-1 && sub.length()>len )\n                {\n                    len = sub.length();\n                }\n            }\n        }\n        System.out.println(len);\n        // TODO code application logic here\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class P23A {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(System.in);\n\t\tString s = in.nextLine();\n\t\tint max = 0;\n\t\tfor(int i = 0; i < s.length(); i++)\n\t\t\tfor(int k = s.length(); k > max + i; k--)\n\t\t\t\tif(s.substring(i + 1).contains(s.substring(i,k)))\n\t\t\t\t\tmax = k - i; \n\t\tSystem.out.println(max);\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "//package timus;\n\nimport 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.math.BigInteger;\nimport java.util.Arrays;\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\n    void init() throws IOException {\n        oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\n                \"input.txt\");\n        Writer writer = oj ? new OutputStreamWriter(System.out)\n                : new FileWriter(\"output.txt\");\n        in = new StreamTokenizer(new BufferedReader(reader));\n        out = new PrintWriter(writer);\n    }\n\n    void run() throws IOException {\n        long beginTime = System.currentTimeMillis();\n        init();\n        solve();\n        out.flush();\n    }\n\n    void printMem() {\n        if (!oj) {\n            System.out.println(\"Memory used = \"\n                    + (Runtime.getRuntime().totalMemory() - Runtime\n                            .getRuntime().freeMemory()));\n        }\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    long deg(long x, long y) {\n        long a = x;\n        for (long i = 2; i <= y; i++) {\n            a *= x;\n        }\n        return a;\n    }\n\n    long fact(long x) {\n        long a = 1;\n        for (long i = 2; i <= x; i++) {\n            a *= i;\n        }\n        return a;\n    }\n\n    long digitSum(String x) {\n        long a = 0;\n        for (int i = 0; i < x.length(); i++) {\n            a += x.codePointAt(i) - 48;\n        }\n        return a;\n    }\n\n    long digitSum(long x) {\n        long a = 0;\n        while (x > 0) {\n            a += x % 10;\n            x /= 10;\n        }\n        return a;\n    }\n\n    long digitMul(long x) {\n        long a = 1;\n        while (x > 0) {\n            a *= x % 10;\n            x /= 10;\n        }\n        return a;\n    }\n    \n    int digitCubesSum(int x) {\n        int a = 0;\n        while (x > 0) {\n            a += (x % 10) * (x % 10) * (x % 10);\n            x /= 10;\n        }\n        return a;\n    }\n\n    double pif(double ax, double ay, double bx, double by) {\n        return Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n    }\n\n    double getPosPart(double x) {\n        if (x <= 0)\n            return 0;\n        else\n            return x;\n    }\n\n    double max(double x, double y) {\n        if (x > y)\n            return x;\n        else\n            return y;\n    }\n\n    long gcd(long a, long b) {\n        if (a < b) {\n            long c = b;\n            b = a;\n            a = c;\n        }\n        while (a % b != 0) {\n            a = a % b;\n            if (a < b) {\n                long c = b;\n                b = a;\n                a = c;\n            }\n        }\n        return b;\n    }\n\n    int gcd(int a, int b) {\n        if (a < b) {\n            int c = b;\n            b = a;\n            a = c;\n        }\n        while (a % b != 0) {\n            a = a % b;\n            if (a < b) {\n                int c = b;\n                b = a;\n                a = c;\n            }\n        }\n        return b;\n    }\n\n    long lcm(long a, long b) throws IOException {\n        return a * b / gcd(a, b);\n    }\n\n    int lcm(int a, int b) throws IOException {\n        return a * b / gcd(a, b);\n    }\n\n    int countOccurences(String x, String y) {\n        int a = 0, i = 0;\n        while (true) {\n            i = y.indexOf(x);\n            if (i == -1)\n                break;\n            a++;\n            y = y.substring(i + 1);\n        }\n        return a;\n    }\n\n    int[] primes;\n\n    int findPrimes(int x) {\n        boolean[] forErato = new boolean[x];\n        primes = new int[x];\n        int l = 0, j = 0;\n        for (int i = 2; i < x; i++) {\n            if (forErato[i])\n                continue;\n            l++;\n            primes[l] = i;\n            j = i * 2;\n            while (j < x) {\n                forErato[j] = true;\n                j += i;\n            }\n        }\n        return l;\n    }\n\n    int rev(int x) {\n        int a = 0;\n        while (x > 0) {\n            a = a * 10 + x % 10;\n            x /= 10;\n        }\n        return a;\n    }\n\n    class myDate {\n        int d, m, y;\n\n        public myDate(int da, int ma, int ya) {\n            d = da;\n            m = ma;\n            y = ya;\n        }\n\n        int[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n        void inc() {\n            if ((d == 31) && (m == 12)) {\n                y++;\n                d = 1;\n                m = 1;\n            } else {\n                if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n                    ml[1] = 29;\n                }\n                if (d == ml[m - 1]) {\n                    m++;\n                    d = 1;\n                } else\n                    d++;\n            }\n        }\n    }\n\n    int partition(int n, int l, int m) {// n - sum, l - length, m - every part\n        // <= m\n        if (n < l)\n            return 0;\n        if (n < l + 2)\n            return 1;\n        if (l == 1)\n            return 1;\n        int c = 0;\n        for (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n            c += partition(n - i, l - 1, i);\n        }\n        return c;\n    }\n    \n    String s;\n    int l;\n    \n    void solve() throws IOException {\n        s = nextString();\n        l = s.length();\n        int max = 0;\n        for (int i = 0; i < l - 1; i++) {\n            for (int j = i + 1; j < l; j++) {\n                if (countOccurences(s.substring(i, j), s) > 1)\n                    if (j - i > max) max = j - i;\n            }\n        }\n        out.println(max);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class a{\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString str = in.next();\n\t\tint max = 0;\n\t\tfor(int i=0; i<str.length(); i++) {\n\t\t\tfor(int j=i+1; j<=str.length(); j++) {\n\t\t\t\tString first = str.substring(i,j);\n\t\t\t\tfor(int k=i+1; k<=str.length()-first.length(); k++) {\n\t\t\t\t\tif(str.substring(k,k+first.length()).equals(first))\n\t\t\t\t\t\tmax = Math.max(max,first.length());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class Main implements Runnable {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry {\n\t\t\trun1();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tint nextInt(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn (int) st.nval;\n\t}\n\n\tprivate List<Integer> kmp(String x, String a) {\n\t\tString s = a + \"$\" + x;\n\t\tint[] oppa = new int[s.length()];\n\t\toppa[0] = 0;\n\t\tint tmp = 0;\n\t\tList<Integer> res = new ArrayList<Integer>();\n\t\tfor (int i = 1; i < s.length(); i++) {\n\t\t\twhile (tmp != 0 && s.charAt(tmp) != s.charAt(i)) {\n\t\t\t\t// System.out.println(i + \" \" + tmp);\n\t\t\t\ttmp = oppa[tmp - 1];\n\t\t\t}\n\t\t\tif (s.charAt(tmp) == s.charAt(i))\n\t\t\t\ttmp++;\n\t\t\toppa[i] = tmp;\n\t\t\tif (tmp == a.length()) {\n\t\t\t\tres.add(i - a.length() - a.length());\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tdouble nextDouble(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.nval;\n\t}\n\n\tString nextLine(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.sval;\n\t}\n\n\tint cnt = 0;\n\tint[] col;\n\n\tvoid unite(int a, int b) {\n\t\tif (cnt % 2 == 0)\n\t\t\tcol[getCol(a)] = getCol(b);\n\t\telse\n\t\t\tcol[getCol(b)] = getCol(a);\n\t\tcnt++;\n\t}\n\n\tint getCol(int a) {\n\t\treturn a == col[a] ? a : (col[a] = getCol(col[a]));\n\t}\n\n\tpublic void run1() throws IOException {\n//\t\t Scanner sc = new Scanner(new FileReader(\"input.txt\"));\n\t\tScanner sc = new Scanner(new InputStreamReader(System.in));\n\t\t// BufferedReader br = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n\t\t// PrintWriter pw = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\tString s= sc.next();\n\t\tint res = 0;\n\t\tint n = s.length();\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tfor(int j = i + 1; j < n; j++) {\n\t\t\t\tint k = 0;\n\t\t\t\twhile(j + k < n && s.charAt(i + k) == s.charAt(j + k))\n\t\t\t\t\tk++;\n\t\t\t\t\tres = Math.max(res, k);\n\t\t\t}\n\t\tSystem.out.println(res);\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) /*throws FileNotFoundException*/ { \n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA{\n     static boolean twofind(String s, String t){\n    \t int index = s.indexOf(t);\n    \t int index2 = s.indexOf(t, index + 1);\n    \t if(index2 != -1)return true;\n    \t return false;\n     }\n\tpublic void solve(int testNumber, FastScanner scan, FastPrinter out) /*throws FileNotFoundException*/ {\n\t\t//Scanner sscan = new Scanner(new File(\"input.txt\"));\n\t\t//PrintStream oout = new PrintStream(new File(\"output.txt\"));\n\t     String s = scan.next();\n\t     String ans = \"\";\n\t     boolean ok = false;\n\t     for(int i = s.length(); i >= 0; i--){\n\t        for(int j = 0; j <= s.length() - 1; j++){\n\t        \ttry{\n\t        \t\tif(twofind(s, s.substring(j, j + i))){\n\t        \t\t\tans = s.substring(j, j + i); break;\n\t        \t\t}\n\t        \t}catch(Exception e){\n\t        \t\tbreak;\n\t        \t}\n\t        }\n\t        if(!ans.equals(\"\"))break;\n\t     }\n\t     \n\t     out.println(ans.length());\n\t\t//sscan.close();\n\t\t//oout.close();\n\t}\n}\n\nclass FastScanner extends BufferedReader {\n\tpublic FastScanner(InputStream is) {\n\t\tsuper(new InputStreamReader(is));\n\t}\n\t\n\tpublic int read() {\n\t\ttry{\n\t\t\tint ret = super.read();\n\t\t\treturn ret;\n\t\t}catch(Exception e){\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t}\n\t\n\tpublic 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\t\n\tstatic boolean isWhiteSpace(int c) {\n        return c >= 0 && c <= 32;\n    }\n\t\n\tpublic 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\t\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tpublic BigInteger nextBigInteger() {\n\t\treturn new BigInteger(next());\n\t}\n\t\n\tpublic BigDecimal nextBigDecimal(){\n\t\treturn new BigDecimal(next());\n\t}\n\t\n\tpublic String readLine(){\n\t\ttry{\n\t\t\treturn super.readLine();\n\t\t}catch(IOException e){\n\t\t\treturn null;\n\t\t}\n\t}\n}\n\nclass FastPrinter extends PrintWriter {\n\t\n\tpublic FastPrinter(OutputStream out) {\n\t\tsuper(out);\n\t}\n\tpublic FastPrinter(Writer out) {\n\t\tsuper(out);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\n\npublic class Main{\n    public static void main(String args[]){\n        Scanner sc=new Scanner(System.in);\n        String str=sc.next();\n        sc.close();\n        \n        int maxm=0;\n        int ind1,ind2;\n        \n        for(int i=0;i<str.length();i++){\n            for(int j=i+1;j<str.length();j++){\n                int len=0;\n                ind1=i;ind2=j;\n                while(ind2<str.length() && str.charAt(ind1)==str.charAt(ind2)){\n                    ind1++;\n                    ind2++;\n                    len++;\n                }\n                maxm=Math.max(maxm,len);\n            }\n        }\n        System.out.println(maxm);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class StringRepeat\n{\n\tstatic Scanner in = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) );\n\n\tpublic static void main( String[] args )\n\t{\n\t\tString s = in.next();\n\t\tint n = s.length(), ans = 0;\n\t\tfor( int i = 0; i < n; i++ ) for( int j = i+1; j < n; j++ )\n\t\t{\n\t\t\tint l = 0;\n\t\t\twhile( j+l<n && s.charAt(i+l)==s.charAt(j+l) ) l++;\n\t\t\tans = Math.max( ans, l );\n\t\t}\n\t\tSystem.out.println( ans );\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound23_A implements Runnable {\n\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tvoid init() throws IOException {\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new BetaRound23_A()).start();\n\t}\n\n\tvoid solve() throws IOException {\n\t\tchar[] s = in.readLine().toCharArray();\n\t\tint n = s.length;\n\t\tfor (int ans = n - 1; ans >= 1; ans--) {\n\t\t\tfor (int i = 0; i < n - ans + 1; i++) {\n\t\t\t\tfor (int j = i + 1; j < n - ans + 1; j++) {\n\t\t\t\t\tint count = 0;\n\t\t\t\t\tfor (int k = 0; k < ans; k++) {\n\t\t\t\t\t\tif (s[i + k] == s[j + k]) count++;\n\t\t\t\t\t\telse break;\n\t\t\t\t\t}\n\t\t\t\t\tif (count == ans) {\n\t\t\t\t\t\tout.print(ans);\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.print(0);\n\t}\n\t\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class P19 {\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        Map<Integer, Integer> mapa = new HashMap<Integer, Integer>();\n        String str = in.next();\n        int len = str.length();\n        int maxCurrent = 0;\n        for (int i = 0; i < len; ++i) {\n            for (int j = 1; j <= len; ++j) {\n                if (i + j > len) continue;\n                //System.out.format(\"Adding from %d to %d -> %s\\n\",i, i+j,str.substring(i, i + j));\n                int hashCode = str.substring(i, i + j).hashCode();\n                Integer current = mapa.get(hashCode);\n                if (current == null)\n                    current = 0;\n                current++;\n                mapa.put(hashCode, current);\n                if (current > 1)\n                    maxCurrent = Math.max(maxCurrent, j);\n            }\n        }\n\n        out.println(maxCurrent);\n\n        out.flush();\n        out.close();\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class j\n{\npublic static void main(String a[])throws IOException\n{\nBufferedReader b=new BufferedReader(new InputStreamReader(System.in));\nint n=0,i=0,k=2;\nString s=\"\\0\",r=\"\\0\";\ns=b.readLine();\nn=s.length()-1;\nwhile(k<=s.length())\n{\nfor(i=0;i<k;i++)\n{\nr=s.substring(i,i+n);\nif(s.indexOf(r)!=s.lastIndexOf(r))\n{\nSystem.out.print(n);\nSystem.exit(0);\n}\n}\nk++;\nn--;\n}\nSystem.out.print(\"0\");\n}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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\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\n\t\tString s = in.next();\n\t\tint n = s.length();\n\n\t\tint max = 0;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tString[] subs = new String[n - i + 1];\n\t\t\tfor (int j = 0; j + i <= n; j++) subs[j] = s.substring(j, j + i);\n\t\t\tArrays.sort(subs);\n\t\t\tboolean flag = false;\n\t\t\tfor (int j = 0; j < n - i; j++)\n\t\t\t\tif (subs[j].equals(subs[j + 1])) flag = true;\n\t\t\tif (flag) max = Math.max(max, i);\n\t\t}\n\n\t\tout.println(max);\n\n\t\tout.close();\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class A23 {\n\tpublic static void main(String[]args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tString W = sc.next();\n\t\tArrayList<String>Q = new ArrayList<String>();\n\t\tfor (int i = 0; i < W.length(); i++){\t\t\t\n\t\t\tString O = \"\";\n\t\t\tfor (int k = i; k < W.length(); k++){\n\t\t\t\tO = O + W.charAt(k);\n\t\t\t\tQ.add(O);\n\t\t\t}\t\t\t\n\t\t}\n\t\tCollections.sort(Q);\n\t\tString tmp = Q.get(0);\n\t\tint y = 0;\n\t\tfor (int i = 1; i < Q.size(); i++){\n\t\t\tif (Q.get(i).equals(tmp)){\n\t\t\t\tif (Q.get(i).length() > y){\n\t\t\t\t\ty = Q.get(i).length();\n\t\t\t\t}\t\n\t\t\t}\n\t\t\telse {\n\t\t\t\ttmp = Q.get(i);\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(y);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main {\n    \n    void run() throws IOException {\n        String s = token();\n        HashSet <String> h;\n        int n = s.length();\n        int r = 0;\n        loop: for (int i = 1; i <= n; i++) {\n            h = new HashSet();\n            for (int j = 0; j < n - i + 1; j++) {\n                String t = s.substring(j, j + i);\n                if (h.contains(t)) {\n                    r = i;\n                    continue loop;\n                } else {\n                    h.add(t);\n                }\n            }\n        }\n        System.out.println(r);\n    }\n\n    public static void main(String[] args) throws IOException {\n        Locale.setDefault(Locale.US);\n        //final String FILENAME = \"dvd\";\n        //in = new BufferedReader(new FileReader(new File(FILENAME + \".in\")));\n        //out = new PrintWriter(new File(FILENAME + \".out\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        //in = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        st = new StringTokenizer(\" \");\n        new Main().run();\n        out.close();\n    }\n\n    static BufferedReader in;\n    //static Scanner in;\n    static PrintWriter out;\n    static StringTokenizer st;\n\n    String token() throws IOException {\n        while (!st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nint() throws IOException {\n        return Integer.parseInt(token());\n    }\n\n    long nlong() throws IOException {\n        return Long.parseLong(token());\n    }\n\n    double ndouble() throws IOException {\n        return Double.parseDouble(token());\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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\n\tvoid solve() throws IOException {\n\t\tString s = next();\n\t\tHashSet<String> set = new HashSet<String>();\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < s.length(); ++i) {\n\t\t\tfor (int j = i + 1; j <= s.length(); ++j) {\n\t\t\t\tString t = s.substring(i, j);\n\t\t\t\tif (set.contains(t)) {\n\t\t\t\t\tans = Math.max(ans, t.length());\n\t\t\t\t}\n\t\t\t\tset.add(t);\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class GivenString {\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        \n        String s = input.nextLine();\n        \n        int max = 0;\n        \n        for(int i = 0; i < s.length(); i++) {\n            for(int j = i + 1; j <= s.length(); j++) {\n                String tmp = s.substring(i, j);\n                int match = 0;\n                for(int k = 0; k + tmp.length() <= s.length(); k++) {\n                    if(tmp.equals(s.substring(k, k + tmp.length()))) {\n                        match++;                        \n                    }\n                }\n                if(match >= 2) {\n                    max = Math.max(max, tmp.length());\n                }\n            }\n        }\n        System.out.println(max);\n        System.exit(0);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class Main \n{\n     public static void main(String []args)throws Exception\n    {\n        String inp=\"\";\n        String res=\"\";\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        inp=br.readLine();\n        for(int i=0;i<inp.length();i++)//counts the length\n        {\n            for(int j=0;j<(inp.length()-i);j++)//start index of string\n            {\n                for(int k=j+1;k<=inp.length()-i;k++)\n                {\n                    if(inp.substring(j,j+i).equals(inp.substring(k,k+i)))\n                       res =inp.substring(j,j+i);\n                }\n            }\n        }\n        System.out.println(res.length());\n\n     }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A23 {\n\n    static int solve(String s) {\n        for(int i = s.length(); i > 0; --i) {\n            for(int start = 0; start < s.length() - i; ++start) {\n                String str = s.substring(start, start + i);\n                int firstIndex = s.indexOf(str);\n                int lastIndex = s.lastIndexOf(str);\n                if(firstIndex != lastIndex)\n                    return i;\n            }\n        }\n        return 0;\n    }\n\n    public static String[] EX = new String[] { \"abcd\", \"ababa\", \"zzz\", \"qwertyuiopasdfghjklzxcvbnmqwepriuwpoep\"};\n    public static int[] EX_A = new int[] { 0, 3, 2, 3};\n    \n    public static void main(String[] args) throws IOException {\n        if(true) {\n            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n            String s = br.readLine();\n            System.out.println(solve(s));\n        }\n        else {\n            for(int i = 0; i < EX.length; ++i) {\n                int result = solve(EX[i]);\n                System.out.println(i + \": \" + result + \" \" + (result == EX_A[i]? \"ja\" : \"NEJ\"));\n            }\n        }\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Longest {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString str=sc.nextLine();\n\t\tint max=0;\n\t\tfor(int i=0;i<str.length();i++)\n\t\t{\n\t\t\tfor(int x=0;x+i<=str.length();x++)\n\t\t\t{\n\t\t\t\tif(contains(str,str.substring(x,x+i),x))\n\t\t\t\t{\n\t\t\t\t\t//System.out.println(str.substring(x,x+i));\n\t\t\t\t\tmax=Math.max(max, i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\tpublic static boolean contains(String whole,String part,int start)\n\t{\n\t\t\n\t\tif(whole.indexOf(part, start+1)>=0)return true;\n\t\treturn false;\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String s = in.readLine();\n        for (int i = s.length() - 1; i > 0; i--)\n            for (int j = 0; j <= s.length() - i; j++)\n                if (s.substring(0, j + i - 1).contains(s.substring(j, j + i))\n                        || s.substring(j + 1).contains(s.substring(j, j + i))) {\n                    System.out.println(i);\n                    return;\n                }\n        System.out.println(0);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class C23A {\n    public static void main(String args[]){\n        Scanner sc=new Scanner(System.in);\n        String str=sc.next();\n\n        for(int k=str.length()-1;k>=1;k--){\n            for(int i=0;i<=str.length()-k;i++){\n                for(int j=i+1;j<=str.length()-k;j++){\n                    if(str.substring(i,i+k).equals(str.substring(j,j+k))){\n                            System.out.println(k);\n                            return;\n                    }\n                }\n            }\n        }\n        System.out.println(0);\n\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Test {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        StringBuilder text = new StringBuilder(in.nextLine()); String substr; String max=\"\";\n        for(int i=2; i<=text.length(); i++){\n            for(int j=0; j<i; j++){\n                substr = text.substring(j, i);\n                if(text.lastIndexOf(substr) != text.indexOf(substr)){\n                    if(substr.length() > max.length()){  max = substr;}\n                }\n            }\n        }\n        System.out.println(max.length());\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class StringsProb {\n    private void solve() throws IOException {\n        String s = nextToken();\n        int res = 0;\n        Map<String , Integer> m = new HashMap<String, Integer>();\n        for (int i = 0; i < s.length(); i++)\n            for (int j = 0; j <= s.length(); j++) {\n                if (i > j) continue;\n                String a = s.substring(i , j);\n                if (a.equals(\"\")) continue;\n                if (m.containsKey(a)) {\n                    m.put(a, m.get(a) + 1);\n                }\n                else\n                    m.put(a, 1);\n            }\n        for (Entry<String , Integer> e : m.entrySet()) {\n            if (e.getValue() >= 2)\n                res = Math.max(res, e.getKey().length());\n        }\n        System.out.println(res);\n    }\n\n    public static void main(String[] args) {\n        new StringsProb().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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class substring {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out;\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputStream input = System.in;\n\t\t//InputStream input = new FileInputStream(\"fileIn.in\");\n\t\tOutputStream output = System.out;\n\t\t//OutputStream output = new FileOutputStream(\"fileOut.out\");\n\t\tbr = new BufferedReader(new InputStreamReader(input));\n\t\tout = new PrintWriter(output);\n\t\tString in = br.readLine();\n      int len = in.length();\n      int doub = len;\n      boolean found = false;\n      while (!found)\n         {\n         int count = 0;\n         String[] parts = new String[len - doub + 1];\n         for (int i = 0; i < len - doub + 1; i++)\n            parts[i] = in.substring(i,i+doub);\n         for (int i = 1; i < len - doub + 1; i++)\n            for (int j = 0; j < i; j++)\n               if (parts[i].equals(parts[j]))\n                  count++;\n         if (count >= 1)\n            found = true;\n         doub--;\n         }\n      out.println(doub+1);\n\t\tout.close();\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner cin = new Scanner(System.in);\n\t\tString str;\n\t\tint i,j,k;\n\t\tint cnt = 0;\n\t\tchar [] strArray;\n\t\t\n\t\tstr = cin.next();\n\t\tstrArray = str.toCharArray();\n\t\t\n\t\tfor(i = 0; i < strArray.length; i ++)\n\t\t\tfor(j = i + 1; j < strArray.length; j ++)\n\t\t\t{\n\t\t\t\tfor(k = 0; (((i + k) < strArray.length && (j + k) < strArray.length) && (strArray[i + k] == strArray[j + k])); k ++)\n\t\t\t\t\tif(k + 1> cnt) cnt = k + 1;\n\t\t\t}\n\t\t\n\t\tSystem.out.println(cnt);\n\t}\n}\n\t\t\t \t\t \t \t \t  \t  \t \t \t\t \t", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A23 {\n    public static void main(String[] args){\n\tScanner sc = new Scanner(System.in);\n\tchar[] input = sc.nextLine().toCharArray();\n\tint[][] dyn = new int[input.length][input.length];\n\tint max = 0;\n\tfor(int a = 0; a < input.length; a++) {\n\t    for(int b = a + 1; b < input.length; b++) {\n\t\tif(input[a] == input[b]) {\n\t\t    int prev = (a == 0) ? 0 : dyn[a-1][b-1];\n\t\t    dyn[a][b] = prev + 1;\n\t\t    max = (dyn[a][b] > max) ? dyn[a][b] : max;\n\t\t}\n\t    }\n\t}\n\tSystem.out.println(max);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Scanner;\nimport java.lang.String;\npublic class A23 {\n    public static void main(String[] args) {\n    Scanner in = new Scanner(System.in);\n    String s = in.nextLine();\n    int i=0,j=0,n=0,t=0,count=0;\n    n=s.length();\n    String s1=\"y\",s2=\"yu6j\";\n    for(t=1;t<n;t++)\n        {\n        for(i=0;i<t;i++)\n            {\n            s1=s.substring(i,i+n-t);\n            for(j=i+1;j<=t;j++)\n                {\n                s2=s.substring(j,j+n-t);\n                if(s1.equalsIgnoreCase(s2))\n                    {\n                    count++;break;\n                    }\n                if(count==1) break;\n                }\n            if(count==1) break;\n            }\n        if(count==1) break;\n        }\n\tif(n==0)\n\t\t{\n\t  System.out.println(\"0\");\n\t\t}\n\telse\n\t{\n    if(count==1)\n    {\n    System.out.println(s1.length());\n    }\n    else  System.out.println(\"0\");\n    }\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\tString line;\n\t\n\tvoid run()throws IOException{\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\t\t\n\t\tline = bf.readLine();\n\t\tint i, j, len = line.length(), max=0;\n\t\tfor(i=0; i<len; i++){\n\t\t\tfor(j=i; j<len; j++){\n\t\t\t\tif(line.indexOf(line.substring(i,j+1), i+1)>0){\n\t\t\t\t\tif(j-i+1>max) max = j-i+1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\t\n\tpublic static void main(String[] args)throws IOException {\n\t\tnew A().run();\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.PrintWriter;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.*;\n\n\npublic class CF23A implements Runnable{\n        \n    public static void main(String args[]){\n       new CF23A().run();\n    }\n    \n    @Override\n    public void run(){\n        try{\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new PrintWriter(System.out);\n            tok = null;\n            solve();\n            in.close();\n            out.close();\n            \n        }\n        catch(IOException e){\n            e.printStackTrace();\n            System.exit(0);\n        }\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(tok == null || !tok.hasMoreTokens()){\n            tok = new StringTokenizer(in.readLine());\n        }\n        return tok.nextToken();\n    }\n    \n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok;\n    //////////////////////////////////////////////////////////////////\n    //////////////////////////////////////////////////////////////////\n    private void solve()throws IOException{\n        String s = nextToken();\n        int l = s.length();\n        int ans = 0;\n        for(int i = 0; i < l - 1; i++){\n            for(int j = i + 1; j < l; j++){\n                String now = s.substring(i, j);\n                if(s.substring(i + 1).indexOf(now) >= 0){\n                ans = Math.max(ans, j - i);\n                \n            }\n            }\n        }\n        \n        out.println(ans);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution\n{\n    public static void main(String[] args)\n    {\n        new Solution().calc();\n    }\n\n    void calc()\n    {\n        Scanner cin = new Scanner(System.in);\n        String s = cin.next();\n        int ret = 0;\n        for (int i = 0; i < s.length(); i++)\n        {\n            for (int j = i + 1; j < s.length(); j++)\n            {\n                for (int k = 0; j + k < s.length(); k++)\n                {\n                    if (s.charAt(i + k) != s.charAt(j + k)) break;\n                    ret = Math.max(k + 1, ret);\n                }\n            }\n        }\n        System.out.println(ret);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A023 {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(f());\n\t}\n\n\tstatic int f() {\n\t\tScanner in = new Scanner(System.in);\n\t\tString line = in.next();\n\t\tfor (int length = line.length(); length > 0; length--) {\n\t\t\tfor (int start = 0; start + length <= line.length(); start++) {\n\t\t\t\tif(line.indexOf(line.substring(start,start+length),start+1)>=0) {\n\t\t\t\t\treturn length;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.lang.Character.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\npublic class A_YoureGivenAString {\n\n    //1:11\n    \n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        String str = s.nextLine();\n        \n        for (int l = str.length()-1; l >= 1; l--) {\n            for (int i = 0; i < str.length()-l+1; i++) {\n                String subs = str.substring(i, i+l);\n                if(str.lastIndexOf(subs) != i){\n                    System.out.println(l);\n                    return;\n                }\n            }\n        }\n        System.out.println(0);\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Longest {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString str=sc.nextLine();\n\t\tint max=0;\n\t\tfor(int i=0;i<str.length();i++)\n\t\t{\n\t\t\tfor(int x=0;x+i<=str.length();x++)\n\t\t\t{\n\t\t\t\tif(contains(str,str.substring(x,x+i),x))\n\t\t\t\t{\n\t\t\t\t\t//System.out.println(str.substring(x,x+i));\n\t\t\t\t\tmax=Math.max(max, i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\tpublic static boolean contains(String whole,String part,int start)\n\t{\n\t\t\n\t\tif(whole.indexOf(part, start+1)>=0)return true;\n\t\treturn false;\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        String s = in.nextLine();\n\n        int ans = 0;\n\n        outer: for (int i = s.length() - 1; i >= 1; i--)\n            for (int j = 0; j < s.length() - i; j++) {\n                String sub = s.substring(j, j + i);\n                String str = s.substring(j + 1);\n\n                if (str.contains(sub)) {\n                    ans = i;\n                    break outer;\n                }\n            }\n\n        out.print(ans);\n        out.close();\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String line = in.readLine();\n        int n = line.length();\n        int maxlenght = 0;\n        for (int i = 0; i < n; i++) {\n            int j = line.indexOf(line.charAt(i), i + 1);\n            while (j != -1) {\n                int k = i;\n                int l = j;\n                while (k < n && l < n && line.charAt(k) == line.charAt(l)) {\n                    k++;\n                    l++;\n                }\n                if (k - i > maxlenght) {\n                    maxlenght = k - i;\n                }\n                j = line.indexOf(line.charAt(i), j + 1);\n            }\n        }\n        System.out.println(maxlenght);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.Set;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskA implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TaskA()).start();\n//\t\tnew Template().run();\n\t}\n\n\tpublic TaskA() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//\t\t\tout.print(\"Case \" + (testNumber + 1) + \": \");\n//        }\n\t\tString s = in.readString();\n\t\tSet<String> m = new HashSet<String>();\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tfor (int j = i + 1; j <= s.length(); j++) {\n\t\t\t\tif (m.contains(s.substring(i, j)))\n\t\t\t\t\tans = Math.max(ans, j - i);\n\t\t\t\telse\n\t\t\t\t\tm.add(s.substring(i, j));\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tnew A().run();\n\t}\n\n\tprivate void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tsc.close();\n\t\t\n\t\tint res = 0;\n\t\tfor (int i = 0; i < s.length(); i++)\n\t\t\tfor (int j = i + 1; j <= s.length(); j++) {\n\t\t\t\tString sub = s.substring(i, j);\n\t\t\t\tint c = count(s, sub);\n\t\t\t\tif (c >= 2)\n\t\t\t\t\tres = Math.max(res, sub.length());\n\t\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n\tprivate int count(String s, String sub) {\n\t\tint res = 0;\n\t\twhile (s.length() > 0) {\n\t\t\tif (s.startsWith(sub))\n\t\t\t\tres++;\n\t\t\ts = s.substring(1);\n\t\t}\n\t\treturn res;\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\n\npublic class Main {\n\tBufferedReader in;\n\tPrintWriter out;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tnew Main().run();\n\t}\n\tpublic void run() throws IOException\n\t{\n\t\t//in=new BufferedReader(new FileReader(\"input.txt\"));\n\t\t//out=new PrintWriter(new FileWriter(\"output.txt\"));\n\t\tin=new BufferedReader(new InputStreamReader(System.in));\n\t\tout=new PrintWriter(new OutputStreamWriter(System.out));\n\t\tsolve();\n\t\t\n\t\tout.flush();\n\t}\n\n\tpublic void solve() throws IOException\n\t{\n\t\tString now=in.readLine();\n\t\tint l=now.length();\n\t\tint answ=0;\n\t\tfor(int i=0;i!=l;i++)\n\t\t\tfor(int j=i+1;j<l;j++)\n\t\t\t{\n\t\t\t\tString a=now.substring(i, j);\n\t\t\t\tfor(int k=i+1;k<l-j+i+1;k++)\n\t\t\t\t\tif(a.compareTo(now.substring(k, k+j-i))==0)\n\t\t\t\t\t\tansw=Math.max(answ, a.length());\n\t\t\t}\n\t\tout.print(answ);\n\t\t\n\t\t\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class Main {\n\n    \n    public static void main(String[] args)throws java.lang.Exception {\n     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n     String s = br.readLine();\n     int max = 0;\n        for (int i = 0; i < s.length(); i++) {\n            for (int j = i+1; j < s.length(); j++) {\n                if(s.substring(i+1).contains(s.substring(i,j)))\n                    max = Math.max(max, j-i);\n\n            }}\n            System.out.println(max);\n\n\n\n    \n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception{\n\t\tString str = new Scanner(System.in).next();\n\t\tSet<String> set = new HashSet<String>();\n\t\tString max = \"\";\n\t\tfor(int l = 1; l < str.length(); ++l){\n\t\t\tfor(int i = 0; i < str.length()-l; ++i){\n\t\t\t\tString substr = str.substring(i, i+l);\n\t\t\t\tif(!set.contains(substr) && str.indexOf(substr) != str.lastIndexOf(substr)){\n\t\t\t\t\tset.add(substr);\n\t\t\t\t\tif(substr.length() > max.length()){\n\t\t\t\t\t\tmax = substr;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max.length());\n\t}\n\t\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class A\n{\n    public static void main(String args[])\n    {\n        Scanner scan = new Scanner(System.in);\n        \n        String str = scan.next();\n        \n        for(int i=str.length();i >= 1;i--)\n        {\n            for(int j=0;j + i <= str.length();j++)\n            {\n                String sub = str.substring(j, j+i);\n                \n                int index = str.indexOf(sub, j+1);\n                \n                \n                if(index > -1)\n                {\n                    System.out.println(i);\n                    return;\n                }\n                \n            }\n        }\n        \n        System.out.println(0);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n    static boolean LOCAL = false;//System.getSecurityManager() == null;\n    Scanner sc = new Scanner(System.in);\n    \n    void run() {\n        char[] cs = sc.nextLine().toCharArray();\n        int res = 0;\n        for (int s1 = 0; s1 < cs.length; s1++) {\n            for (int s2 = s1 + 1; s2 < cs.length; s2++) {\n                int len = 0;\n                while (s2 + len < cs.length && cs[s1 + len] == cs[s2 + len]) {\n                    len++;\n                }\n                res = max(res, len);\n            }\n        }\n        System.out.println(res);\n    }\n    \n    class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n        Scanner(InputStream in) {\n            br = new BufferedReader(new InputStreamReader(in));\n            eat(\"\");\n        }\n        void eat(String s) {\n            st = new StringTokenizer(s);\n        }\n        String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n        boolean hasNext() {\n            while (!st.hasMoreTokens()) {\n                String s = nextLine();\n                if (s == null) return false;\n                eat(s);\n            }\n            return true;\n        }\n        String next() {\n            hasNext();\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    }\n    \n    void debug(Object...os) {\n        System.err.println(deepToString(os));\n    }\n    \n    public static void main(String[] args) {\n        if (LOCAL) {\n            try {\n                System.setIn(new FileInputStream(\"in.txt\"));\n            } catch (Throwable e) {\n                LOCAL = false;\n            }\n        }\n        if (!LOCAL) {\n            try {\n                Locale.setDefault(Locale.US);\n                System.setOut(new PrintStream(new BufferedOutputStream(System.out)));\n            } catch (Throwable e) {\n            }\n        }\n        new Main().run();\n        System.out.flush();\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class a23\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        String s,subs;\n       // System.out.println(\"Enter\");\n        s=in.readLine();\n        int i,j,k,l=0,a=1,sl=0;\n        for(i=0;i<s.length();i++)\n        {\n            a=1;\n            for(j=i;j<s.length();j++)\n            {\n                subs=s.substring(i,i+a);\n                for(k=i;k<(s.length()-a+1);k++)\n                {\n                    if(subs.compareTo(s.substring(k,k+a))==0)\n                    l++;\n                    if(l==2)\n                    {\n                        if(a>sl)\n                        sl=a;\n                        l=0;\n                        break;\n                    }\n                }\n                l=0;\n                a++;\n            }\n        }\n        System.out.println(sl);\n    }\n}\n                    ", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n    public static void main(String[] args) throws IOException {\n        new A().solve();\n    }\n\n    BufferedReader br;\n    StringTokenizer st = new StringTokenizer(\"\");\n\n    private void solve() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        String s = nextToken();\n        int res = 0;\n        for (int i = 0; i < s.length(); i++) {\n            for (int j = i + 1; j < s.length(); j++) {\n                int k = 0;\n                while (k < s.length() - j && s.charAt(i + k) == s.charAt(j + k)) {\n                    k++;\n                }\n                res = Math.max(res, k);\n            }\n        }\n        PrintWriter pw = new PrintWriter(System.out);\n        pw.println(res);\n        pw.close();\n    }\n\n    String nextToken() throws IOException {\n        while (!st.hasMoreTokens()) {\n            st = new StringTokenizer(br.readLine());\n        }\n        return st.nextToken();\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n    public static Scanner scan = new Scanner(System.in);\n    public static boolean bg = true;\n\n    public static void main(String[] args) throws Exception {\n        String k1 = scan.next();\n        HashSet<String> met = new HashSet();\n        String ans = \"\";\n        for (int i=1;i<=k1.length()-1;i++){\n            for (int j=0;j+i<=k1.length();j++){\n                String cur = k1.substring(j, j+i);\n                if (!met.contains(cur)){\n                    met.add(cur);\n                }\n                else {\n                    if (cur.length()>ans.length())ans=cur;\n                }\n            }\n        }\n        System.out.println(ans.length());\n        \n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class A23 {\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\t\t\n\t\tString s = nextString();\n\t\t\n\t\tfor (int i = s.length(); i > 0; i--) {\n\t\t\tfor (int j = 0; j+i-1 < s.length(); j++)\n\t\t\t\tfor (int k = j+1; k+i-1 < s.length(); k++)\n\t\t\t\t\tif (s.substring(j, j+i).equals(s.substring(k, k+i))) {\n\t\t\t\t\t\tout.println(i);\n\t\t\t\t\t\tout.flush();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(\"0\");\n\t\t\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Solution {\n    public static void main(String [] args){\n        Scanner in = new Scanner(System.in);\n\n        String ins = in.nextLine();\n        HashMap <String,Integer> sub = new HashMap<String,Integer>();\n        for (int i=0;i<ins.length();i++){\n            for (int j=i+1;j<=ins.length();j++){\n                String key = ins.substring(i,j);\n                if (sub.containsKey(key)){\n                    sub.put(key,sub.get(key)+1);\n                } else {\n                    sub.put(key,1);\n                }\n            }\n        }\n\n        int max = 0;\n        for (String key:sub.keySet()){\n            if (sub.get(key) >= 2 && key.length() > max){\n                max = key.length();\n            }\n        }\n\n        System.out.print(max);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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        int res = 0;\n        int L = s.length();\n        for(int i = 0; i < L; i++)\n            for(int j = i + 1; j <= L; j++)\n            {\n                String ss = s.substring(i, j);\n                int k = s.indexOf(ss);\n                //print(ss, k);\n                if(k >= 0)\n                {\n                    if(s.substring(k + 1).indexOf(ss) >= 0) res = max(res, j - i);\n                }\n            }\n        System.out.println(res);\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}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "//package round23;\n\nimport java.io.PrintWriter;\nimport java.io.StringReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class A {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n//\tprivate String INPUT = add(\"a\", 100);\n\tprivate String INPUT = \"\";\n\t\n\tpublic void solve()\n\t{\n\t\tString str = in.next();\n\t\tint n = str.length();\n\t\tfor(int k = n - 1;k >= 1;k--){\n\t\t\tHashSet<String> set = new HashSet<String>();\n\t\t\tfor(int i = 0;i < str.length() - k + 1;i++){\n\t\t\t\tif(!set.add(str.substring(i, i + k))){\n\t\t\t\t\tout.println(k);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(0);\n\t}\n\t\n\tpublic void run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new StringReader(INPUT));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\tpublic static String add(String str, int k)\n\t{\n\t\tStringBuilder mul = new StringBuilder(str);\n\t\tStringBuilder ret = new StringBuilder();\n\t\tfor(int i = k;i > 0;i >>= 1){\n\t\t\tif((i & 1) == 1)ret.append(mul);\n\t\t\tmul.append(mul);\n\t\t}\n\t\treturn ret.toString();\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew A().run();\n\t}\n\t\n\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Answer23A{\n    public static void main(String[] args){\n\tBufferedReader reader=new BufferedReader(new InputStreamReader(System.in));\n\tnew Kai(reader).solve();\n    }\n}\nclass Kai{\n    BufferedReader reader;\n    public Kai(BufferedReader reader){\n\tthis.reader=reader;\n    }\n    public void solve(){\n\t//TODO\n\tString s=read();\n\tint max=0;\n\tfor(int i=1;i<=s.length()-1;i++){\n\t    for(int j=0;j<=s.length()-i;j++){\n\t\tString h=s.substring(j,j+i);\n\t\tfor(int k=j+1;k<=s.length()-i;k++){\n\t\t    if(h.equals(s.substring(k,k+i))){\n\t\t\tmax=i;\n\t\t    }\n\t\t}\n\t    }\n\t}\n\tpln(max);\n\t\t\t\n    }\n    //tools//////////////////////////////////////////////////\n    public String read(){\n\tString s=null;\n\ttry{\n\t    s=reader.readLine();\n\t}catch(IOException e){\n\t    e.printStackTrace();\n\t}\n\treturn s;\n    }\n    public int[] to_i(String[] s){\n\tint[] tmp=new int[s.length];\n\tfor(int i=0;i<s.length;i++){\n\t    tmp[i]=to_i(s[i]);\n\t}\n\treturn tmp;\n    }\n    public long[] to_l(String[] s){\n\tlong[] tmp=new long[s.length];\n\tfor(int i=0;i<s.length;i++){\n\t    tmp[i]=to_l(s[i]);\n\t}\n\treturn tmp;\n    }\n    public int to_i(String s){\n\treturn Integer.parseInt(s);\n    }\n    public long to_l(String s){\n\treturn Long.parseLong(s);\n    }\n    public void p(Object s){\n\tSystem.out.print(s);\n    }\n    public void pln(Object s){\n\tSystem.out.println(s);\n    }\n    public void debug(Object s){\n\tSystem.err.print(s);\n    }\n    public void debugln(Object s){\n\tSystem.err.println(s);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class A {\n\n    static {\n\tfinal Locale us = Locale.US;\n\tif (!Locale.getDefault().equals(us)) {\n\t    Locale.setDefault(us);\n\t}\n    }\n\n    static boolean file = false;\n\n    static Scanner in;\n    static {\n\ttry {\n\t    in = new Scanner(file ? new FileInputStream(\"f:\\\\var\\\\tmp\\\\in.txt\")\n\t\t    : System.in);\n\t} catch (final FileNotFoundException e) {\n\t    e.printStackTrace();\n\t}\n    }\n\n    static PrintWriter out;\n    static {\n\ttry {\n\t    out = file ? new PrintWriter(\n\t\t    new FileWriter(\"f:\\\\var\\\\tmp\\\\out.txt\")) : new PrintWriter(\n\t\t    System.out);\n\t} catch (final IOException e) {\n\t    e.printStackTrace();\n\t}\n    }\n\n    /**\n     * @param args\n     */\n    public static void main(final String[] args) {\n\ttry {\n\n\t    solve();\n\t    if (file) {\n\t\tSystem.out.flush();\n\t    }\n\t    if (!file) {\n\t\tout.flush();\n\t    }\n\n\t} finally {\n\t    in.close();\n\t    out.close();\n\t}\n    }\n\n    private static void solve() {\n\tfinal String s = in.next();\n\n\tint ans = 0;\n\tfor (int l = 0; l < s.length(); ++l) {\n\t    for (int r = l; r < s.length(); ++r) {\n\t\tfor (int p = l + 1; p - l + r < s.length(); ++p) {\n\t\t    boolean ok = true;\n\n\t\t    for (int q = l, qq = p; q <= r; ++q, ++qq) {\n\t\t\tif (s.charAt(q) != s.charAt(qq)) {\n\t\t\t    ok = false;\n\t\t\t}\n\t\t    }\n\n\t\t    if (ok) {\n\t\t\tans = Math.max(ans, r - l + 1);\n\t\t    }\n\t\t}\n\t    }\n\t}\n\n\tout.println(ans);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Gaurav\n */import java.io.*;\npublic class a23 {\n    public static void main(String arg[])throws IOException\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n\n\n\n          String s=br.readLine();int max=0;\n          for(int i=0;i<s.length();i++)\n          {\n              for(int j=i+1;j<=s.length();j++)\n              {\n                  String g=s.substring(i,j);\n                  //System.out.println(g);\n                  if(max<g.length())\n                  for(int k=i+1;k<=s.length()-g.length();k++)\n                  {\n                      //System.out.println(s.substring(k,k+g.length()));\n                      if(g.compareTo(s.substring(k,k+g.length()))==0)\n                      {\n                          max=g.length();\n                          break;\n                      }\n                      }\n              }\n          }\n          System.out.println(max);\n}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "//contest 23. You're Given A String\nimport java.util.*;\npublic class ProblemA\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner keyboard = new Scanner(System.in);\n\t\tString input = keyboard.nextLine();\n\t\tboolean con = false;\n\t\tfor( int i = input.length()-1; i > 0 ; i--)\n\t\t{\t\n\t\t\tfor ( int j = 0; j+i< input.length(); j++ )\n\t\t\t\tfor( int k = j+1; k+i <= input.length(); k++ )\n\t\t\t\t\tif( input.substring(j,j+i).equals( input.substring(k,k+i) ) ) \n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.print(i+\"\\n\");\n\t\t\t\t\t\tk = input.length()+1;\n\t\t\t\t\t\tj = input.length();\n\t\t\t\t\t\ti = -1;\n\t\t\t\t\t\tcon = true;\n\t\t\t\t\t}\n\t\t}\n\t\tif( con == false )\n\t\t\tSystem.out.print(0+\"\\n\");\n\t}\t\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class A{\n    Scanner sc=new Scanner(System.in);\n\n    void run(){\n        String s=sc.nextLine();\n        int n=s.length();\n        int ans=0;\n        for(int len=1; len<n; len++){\n            for(int i=0; i+len<=n; i++){\n                String t=s.substring(i, i+len);\n//              println(t);\n                if(s.indexOf(t,i+1)!=-1){\n                    ans=len;\n                    break;\n                }\n            }\n        }\n        println(ans+\"\");\n    }\n\n    void println(String s){\n        System.out.println(s);\n    }\n\n    void print(String s){\n        System.out.print(s);\n    }\n\n    public static void main(String[] args){\n        new A().run();\n    }\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.util.Scanner;\n\npublic class P23A {\n    public P23A() {\n        Scanner sc = new Scanner(System.in);\n        String str = sc.next();\n        sc.close();\n        \n        String maxStr = \"\";\n        for (int i = 0; i < str.length() - 1; i++){\n            for (int j = i + 1; j < str.length(); j++){\n                String pattern = str.substring(i, j);\n                if (str.substring(i+1).contains(pattern) && pattern.length() > maxStr.length()){\n                    maxStr = pattern;\n                }\n            }\n        }\n        System.out.println(maxStr.length());\n    }\n    \n    public static void main (String []args){\n        new P23A();\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class Test {\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        int ans = 0;\n        for (int i = 0; i < s.length(); i++) {\n            for (int j = i + 1; j <= s.length(); j++) {\n                String t = s.substring(i, j);\n                if (s.indexOf(t, i + 1)>=0) {\n                    ans = Math.max(ans, j - i);\n                }\n            }\n        }\n        System.out.println(ans);\n    }   \n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n\npublic class R023A {\n\tString str;\n\tint n; \n\tpublic R023A() {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tstr = scanner.next();\n\t\tn = str.length();\n\t}\n\n\tprivate void process() {\n\t\tint length = -1;\n\t\tfor(int i=1; i<n; i++) {\n\t\t\tSet<String> set = new HashSet<String>();\n\t\t\tlength = n - i;\n\t\t\tfor(int j=0; j<=i; j++) {\n\t\t\t\tString sub = str.substring(j, j+length);\n\t\t\t\tset.add(sub);\n\t\t\t}\n\t\t\tif(set.size() < i+1) {\n\t\t\t\tSystem.out.println(length);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(0);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew R023A().process();\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception{\n\t\tString str = new Scanner(System.in).next();\n\t\tSet<String> set = new HashSet<String>();\n\t\tString max = \"\";\n\t\tfor(int l = 1; l < str.length(); ++l){\n\t\t\tfor(int i = 0; i < str.length()-l; ++i){\n\t\t\t\tString substr = str.substring(i, i+l);\n\t\t\t\tif(!set.contains(substr) && str.indexOf(substr) != str.lastIndexOf(substr)){\n\t\t\t\t\tset.add(substr);\n\t\t\t\t\tif(substr.length() > max.length()){\n\t\t\t\t\t\tmax = substr;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max.length());\n\t}\n\t\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\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 _P023A{\n    Scanner sc=new Scanner(System.in);\n\n    int INF=1<<28;\n    double EPS=1e-9;\n\n    String s;\n\n    void run(){\n        s=sc.nextLine();\n        solve();\n    }\n\n    void solve(){\n        int n=s.length();\n        int max=0;\n        for(int i=0; i<n; i++){\n            for(int j=i+1; j<n; j++){\n                for(int k=0; j+k<n; k++){\n                    if(s.charAt(i+k)!=s.charAt(j+k)){\n                        break;\n                    }else{\n                        max=max(max, k+1);\n                    }\n                }\n            }\n        }\n        println(max+\"\");\n    }\n\n    void println(String s){\n        System.out.println(s);\n    }\n\n    void print(String s){\n        System.out.print(s);\n    }\n\n    void debug(Object... os){\n        System.err.println(Arrays.deepToString(os));\n    }\n\n    public static void main(String[] args){\n        Locale.setDefault(Locale.US);\n        new _P023A().run();\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n/**\n * Mx NINJA 04:06:52 \u0635 14/01/2014\n */\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder line = new StringBuilder(reader.readLine());\n        int length = 0;\n        for (int head = 0; head < line.length(); head++) {\n            for (int tail = line.length() - 1; tail > head; tail--) {\n                String subString = line.substring(head, tail);\n                if(line.indexOf(subString,head+1)>-1){\n                    length = Math.max(subString.length(), length);\n                }\n            }\n        }\n        System.out.println(length);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew A().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\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\tvoid solve() {\n\t\tString s = nextToken();\n\t\tfor (int len = s.length(); len >= 1; len--) {\n\t\t\tfor (int i = 0; i + len <= s.length(); i++) {\n\t\t\t\tint cnt = 0;\n\t\t\t\tfor (int j = 0; j + len <= s.length(); j++) {\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\tfor (int k = 0; k < len; k++) {\n\t\t\t\t\t\tif (s.charAt(i + k) != s.charAt(j + k)) {\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\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (cnt > 1) {\n\t\t\t\t\tout.println(len);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(0);\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class GiveString23A {\n    public static void main(String[] args)\n    {\n        Scanner in = new Scanner(System.in);\n        String stroke = in.next();\n        char[] s = new char [stroke.length()];\n        for (int i=0;i<stroke.length();i++)\n            s[i]=stroke.charAt(i);\n        int dlina = 0;\n        for (int i=0;i<s.length-1;i++)\n            for (int j=i+1;j<s.length;j++)\n                for (int k=0;k<(s.length-j);k++)\n                    if (s[i]==s[j])\n                    {\n                        int ik=i+k;\n                        int jk = j+k;\n                        if (s[ik]==s[jk])\n                        {\n                            if (dlina<k+1)\n                                dlina=k+1;      \n                        }\n                        else \n                        break;\n                    }       \n        System.out.println(dlina);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class P023A {\n\n    public static void main(String[] args) {\n        Scanner inScanner = new Scanner(System.in);\n        String string = inScanner.next();\n        int n = string.length();\n        for (int l = n - 1; l > 0; l--) {\n            Set<String> seen = new HashSet<String>();\n            for (int i = 0; i < n - l + 1; i++) {\n                String subString = string.substring(i, i + l);\n                if (seen.contains(subString)) {\n                    System.out.println(l);\n                    return;\n                }\n                seen.add(subString);\n            }\n        }\n        System.out.println(\"0\");\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.Set;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskA implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TaskA()).start();\n//\t\tnew Template().run();\n\t}\n\n\tpublic TaskA() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//\t\t\tout.print(\"Case \" + (testNumber + 1) + \": \");\n//        }\n\t\tString s = in.readString();\n\t\tSet<String> m = new HashSet<String>();\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tfor (int j = i + 1; j <= s.length(); j++) {\n\t\t\t\tif (m.contains(s.substring(i, j)))\n\t\t\t\t\tans = Math.max(ans, j - i);\n\t\t\t\telse\n\t\t\t\t\tm.add(s.substring(i, j));\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.text.DecimalFormat;\nimport java.util.Scanner;\n\npublic class A {\n    public static void main(String[] args){\n        try{\n            Scanner scanner = new Scanner(System.in);\n            String in = scanner.next();\n            int max = 0;\n            for(int j=0;j<in.length()-1;j++){\n                for(int i=j;i<in.length();i++){\n                    if(in.indexOf(in.substring(j, i)) != in.lastIndexOf(in.substring(j, i)) && (i-j)>max){\n                        max = i-j;\n                    }\n                }\n            }\n            System.out.println(max);\n        }catch(Exception e){\n            e.printStackTrace();\n        }\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n \npublic class Solution23A {\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 Solution23A().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        void solve() throws IOException{\n        \tchar[] t = readString().toCharArray();\n        \tint max = 0;\n        \tfor(int i = 0; i < t.length; i++){\n        \t\tfor(int j = i + 1; j < t.length; j++){\n        \t\t\tfor(int k = 0; k < t.length - j; k++){\n        \t\t\t\tif(t[i+k] == t[j+k]) max = max(max, k+1);\n        \t\t\t\telse break;\n        \t\t\t}\n        \t\t}\n        \t}\n        \tout.println(max);\n        }\n        \n        int ModExp(int a, int n, int mod){\n        \tint res = 1;\n        \twhile (n!=0)\n        \t\tif ((n & 1) != 0) {\n        \t\t\tres = (res*a)%mod;\n        \t\t\t--n;\n        \t\t}\n        \t\telse {\n        \t\t\ta = (a*a)%mod;\n        \t\t\tn >>= 1;\n        \t\t}\n        \treturn res;\n        }\n        \n        \n        static class Utils {\n \n                private Utils() {}\n \n                public static void mergeSort(int[] a) {\n                        mergeSort(a, 0, a.length - 1);\n                }\n \n                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n                        final int MAGIC_VALUE = 50;\n                        if (leftIndex < rightIndex) {\n                                if (rightIndex - leftIndex <= MAGIC_VALUE) {\n                                        insertionSort(a, leftIndex, rightIndex);\n                                } else {\n                                        int middleIndex = (leftIndex + rightIndex) / 2;\n                                        mergeSort(a, leftIndex, middleIndex);\n                                        mergeSort(a, middleIndex + 1, rightIndex);\n                                        merge(a, leftIndex, middleIndex, rightIndex);\n                                }\n                        }\n                }\n \n                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {\n                        int length1 = middleIndex - leftIndex + 1;\n                        int length2 = rightIndex - middleIndex;\n                        int[] leftArray = new int[length1];\n                        int[] rightArray = new int[length2];\n                        System.arraycopy(a, leftIndex, leftArray, 0, length1);\n                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n                                if (i == length1) {\n                                        a[k] = rightArray[j++];\n                                } else if (j == length2) {\n                                        a[k] = leftArray[i++];\n                                } else {\n                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];\n                                }\n                        }\n                }\n \n                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n                        for (int i = leftIndex + 1; i <= rightIndex; i++) {\n                                int current = a[i];\n                                int j = i - 1;\n                                while (j >= leftIndex && a[j] > current) {\n                                        a[j + 1] = a[j];\n                                        j--;\n                                }\n                                a[j + 1] = current;\n                        }\n                } \n        }\n        \n       \n        \n        boolean isPrime(int a){\n        \tfor(int i = 2; i <= sqrt(a); i++)\n        \t\tif(a % i == 0) return false;\n        \treturn true;\n        }\n        \n        static double distance(long x1, long y1, long x2, long y2){\n        \treturn Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));\n        }\n        \n        static long gcd(long a, long b){\n        \tif(min(a,b) == 0) return max(a,b);\n        \treturn gcd(max(a, b) % min(a,b), min(a,b));\n        }\n        \n        static long lcm(long a, long b){\n        \treturn a * b /gcd(a, b);\n        }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author Prateep\n */\npublic class JavaApplication1 {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\n        // TODO code application logic here\n        InputStream inputStream = System.in;\n    OutputStream outputStream = System.out;\n    InputReader in = new InputReader(inputStream);\n    PrintWriter out = new PrintWriter(outputStream);\n    TaskB solver = new TaskB();\n    solver.solve(1, in, out);\n    out.close();\n    }\n}\n\nclass TaskB{\n    public void solve(int testNumber, InputReader in, PrintWriter out){\n        String base = in.next();\n    for (int len=base.length()-1;len>=1;len--)\n            for (int i=0;i<base.length()-len+1;i++)\n                for (int j=i+1;j<base.length()-len+1;j++)\n                    if (base.substring(i,i+len).equals(base.substring(j,j+len))){\n                        out.println(len);\n            return;\n                    }\n    out.println(0);\n    \n    }\n    \n}\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n        tokenizer = null;\n    }\n\n    public String next() {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            try {\n                tokenizer = new StringTokenizer(reader.readLine());\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return tokenizer.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n    public long nextLong(){\n        return Long.parseLong(next());\n    }\n    public double nextDouble(){\n        return Double.parseDouble(next());\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\n\tBufferedReader br;\n\tStringTokenizer in;\n\tPrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new A()).start();\n\t}\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 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\tString s = nextToken();\n\t\tint max = 0;\n\t\tfor(int i = 0 ; i < s.length(); i++)\n\t\t\tfor(int j = i+1 ; j < s.length(); j ++){\n\t\t\t\tString sub = s.substring(i, j);\n\t\t\t\tint kv = 0;\n\t\t\t\tfor(int k = 0 ; k<= s.length() - sub.length(); k ++){\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\tfor(int g = 0 ; g < sub.length(); g ++)\n\t\t\t\t\tif (sub.charAt(g) != s.charAt(g+k)){\n\t\t\t\t\t\tok = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (ok) kv ++;\n\t\t\t\t}\n\t\t\t\tif (kv > 1)\n\t\t\t\tmax = Math.max(max, sub.length());\n\t\t\t}\n\t\t\t\t\n\t\tout.println(max);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\n\t\t//\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t//\t\tout = new PrintWriter(\"output.txt\");\n\t\t\n\t\t\tsolve();\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\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.util.regex.*;\nimport java.text.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Mulitple\n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString s = r.readLine();\n\n\t\tSystem.out.println(num(s));\n\t}\n\n\tpublic static int num(String s)\n\t{\n\t\tint answer = 0;\n\t\tSet<String> set = new HashSet<String>();\n\t\tfor(int j = s.length()-1; j>=1; j--)\n\t\t{\n\t\t\tfor(int i = 0; i<s.length()-j+1; i++)\n\t\t\t{\n\t\t\t\tif(set.contains(s.substring(i,i+j)))\n\t\t\t\t{\n\t\t\t\t\treturn s.substring(i,i+j).length();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tset.add(s.substring(i,i+j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn 0; \n\n\t}\n}\n\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\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\n        String s = in.readLine();\n        int n = s.length();\n        for(int len = n; len > 0; len--) {\n            for(int i = 0; i + len <= n; i++) {\n                for(int j = 0; j + len <= n; j++)\n                    if(i != j) {\n                        boolean f = true;\n                        for(int k = 0; k < len; k++)\n                            if(s.charAt(i + k) != s.charAt(j + k)) {\n                                f = false;\n                                break;\n                            }\n                        if(f) {\n                            out.println(len);\n                            out.flush();\n                            return;\n                        }\n                    }\n            }\n        }\n        out.println(0);\n        out.flush();\n    }\n\n    void solve() throws IOException {\n        \n    }\n    \n    //int ni() throws IOException { in.nextToken(); return (int) in.nval; }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.max;\n\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class GivenString implements Runnable\n{\n  public static void main(String[] args) throws Exception\n  {\n    new GivenString().run();\n  }\n\n  private void solve() throws Exception\n  {\n    String s = nextToken();\n    int len = s.length();\n    KMP kmp = new KMP();\n    int r = 0;\n    for (int i = 0; i < len; i++)\n    {\n      for (int j = i + 1; j <= len; j++)\n      {\n        String cur = s.substring(i, j);\n        int count = kmp.search(s, cur);\n        if (count >= 2)\n          r = max(r, cur.length());\n      }\n    }\n    out.println(r);\n  }\n\n  class KMP\n  {\n    public int search(String text, String pattern)\n    {\n      int count = 0;\n      int n = text.length(), m = pattern.length(), matchPoint = -1;\n      char pat[] = pattern.toCharArray(), t[] = text.toCharArray();\n      int p[] = prefixTable(pattern);\n      int j = 0;\n      for (int i = 0; i < n; i++)\n      {\n        while (j > 0 && pat[j] != t[i])\n          j = p[j - 1];\n        if (pat[j] == t[i])\n          j++;\n        if (j == m)\n        {\n          matchPoint = i - m + 1;\n          j = p[j - 1];\n          count++;\n        }\n      }\n      return count;\n    }\n\n    private int[] prefixTable(String pat)\n    {\n      int m = pat.length(), p[] = new int[m];\n      char s[] = pat.toCharArray();\n      int j = 0;\n      for (int i = 1; i < m; i++)\n      {\n        while (j > 0 && s[j] != s[i])\n          j = p[j - 1];\n        if (s[j] == s[i])\n          j++;\n        p[i] = j;\n      }\n      return p;\n    }\n\n  }\n\n  // -------------- Input/Output routines below ---------------//\n  private BufferedReader in;\n  PrintWriter out;\n  StringTokenizer tokenizer;\n\n  public void run()\n  {\n    // String problem = this.getClass().getName();\n    try\n    {\n      in = new BufferedReader(new InputStreamReader(System.in));\n      out = new PrintWriter(new BufferedOutputStream(System.out));\n      solve();\n      out.flush();\n      in.close();\n      out.close();\n    }\n    catch (Exception e)\n    {\n      e.printStackTrace();\n      // System.exit(1);\n    }\n  }\n\n  String nextToken() throws IOException\n  {\n    while (tokenizer == null || !tokenizer.hasMoreTokens())\n    {\n      tokenizer = new StringTokenizer(in.readLine());\n    }\n    return tokenizer.nextToken();\n  }\n\n  int nextInt() throws IOException\n  {\n    return Integer.parseInt(nextToken());\n  }\n\n  long nextLong() throws IOException\n  {\n    return Long.parseLong(nextToken());\n  }\n\n  double nextDouble() throws IOException\n  {\n    return Double.parseDouble(nextToken());\n  }\n\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\n\n\n \n\npublic class Main{\n    private static Parser in;\n    private static PrintWriter out;\n    \n    public static void main(String[] args){\n        in = new Parser(System.in);\n        out = new PrintWriter(System.out);\n        \n//        \n//        char[] ccc = new char[1];\n//        String ddd = \"abcdef\";\n//        ddd.getChars(2, 3, ccc, 0);\n//        \n//        String sssss = new String(ccc);\n//      \n//        System.out.println(sssss);\n//        \n        String s = in.nextString(100);\n        int len = 0;\n        String ss = \"\";\n        \n       \n        l:for (int i = 1; i<=s.length(); i++){\n            for(int j = 0; j+i<=s.length();j++){\n                char[] c = new char[i];\n                char[] cc = new char[i];\n                s.getChars(j, j+i, c, 0);\n                String sss = new String(c);\n                //System.out.println(sss);\n                for(int k = j+1; k+i<=s.length();k++){\n                     \n                    s.getChars(k, k+i, cc, 0);\n                    String ssss = new String(cc);\n                    if(sss.equals(ssss)) {len = i; continue l;}\n                }\n            }\n        }\n        \n        \n        System.out.println(len);\n       // out.flush();\n    }\n}\n\n\nclass Parser {\n    final private int BUFFER_SIZE = 1 << 16;\n    private DataInputStream din;\n    private byte[] buffer;\n    private int bufferPointer, bytesRead;\n \n    public Parser(InputStream in) {\n            din = new DataInputStream(in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n    }\n    public String nextString(int size) { \n        byte[] ch = new byte[size];\n        int point = 0;\n        try {\n            byte c = read();\n            while (c == ' ' || c == '\\n' || c=='\\r')\n                c = read();\n            while (c != ' ' && c != '\\n' && c!='\\r') {\n                ch[point++] = c;\n                c = read();\n            }\n        } catch (Exception e) {}\n        return new String(ch,0,point);\n        }\n    public int nextInt() { \n    int ret = 0;\n    boolean neg;\n    try {\n        byte c = read();\n        while (c <= ' ')\n            c = read();\n        neg = c == '-';\n        if (neg)\n            c = read();\n        do {\n            ret = ret * 10 + c - '0';\n            c = read();\n        } while (c > ' ');\n    \n    if (neg) return -ret;\n    } catch (Exception e) {}\n    return ret;\n    }\n    public long nextLong() { \n        long ret = 0;\n        boolean neg;\n        try {\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            neg = c == '-';\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n                c = read();\n            } while (c > ' ');\n        \n        if (neg) return -ret;\n        } catch (Exception e) {}\n        return ret;\n        }\n    private void fillBuffer() {\n        try {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n        } catch (Exception e) {}\n        if (bytesRead == -1) buffer[0] = -1;\n    }\n \n    private byte read() {\n        if (bufferPointer == bytesRead) fillBuffer();\n        return buffer[bufferPointer++];\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "/**\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\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class CodeForces {\n\n    public void solve() throws IOException {\n        String s = nextToken();        \n        Set<String> set = new HashSet<String>();\n        int counter = 0;\n        for (int i = 0, l = s.length(); i < l; i++) {\n            for (int j = i + 1; j < l; j++) {\n                String subst = s.substring(i, j);\n                if (!set.contains(subst)) {\n                    set.add(subst);\n                    if (counts(s.toCharArray(), subst.toCharArray()) > 1) {\n                        counter = Math.max(counter, subst.length());\n                    }\n\n                }\n            }\n        }\n\n\n        writer.print(counter);\n\n    }\n\n    private int counts(char[] s, char[] r) {\n        int l = s.length;\n        int rl = r.length;\n        int arr[] = new int[26];\n        Arrays.fill(arr, rl);\n        for (int i = rl - 2; i > -1; i--) {\n            int margin = (r[i] - 'a');\n            if (arr[margin] == rl) {\n                arr[margin] = rl - i - 1;\n            }\n        }\n        //search\n        int sp = 0;\n        int counter = 0;\n        while (sp <= l - rl) {\n            int oldsp = sp;\n            for (int i = rl - 1; i > -1; i--) {\n                if (r[i] != s[sp + i]) {\n                    if (i == rl - 1) {\n                        sp += arr[s[sp + i] - 'a'];\n\n                    } else {\n                        sp++;\n                    }\n                    break;\n                }\n            }\n            if (oldsp == sp) {\n                counter++;\n                sp++;\n            }\n        }\n        return counter;\n    }\n\n\n    public static void main(String[] args) {\n        new CodeForces().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            //reader = new BufferedReader(new FileReader(\"LifeWithoutZeros.in\"));\n            tokenizer = null;\n            writer = new PrintWriter(System.out);\n            //writer = new PrintWriter(new BufferedWriter(new FileWriter(\"LifeWithoutZeros.out\")));\n            //long t=new Date().getTime();\n            solve();\n            //writer.println(t-new Date().getTime());\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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class p23a {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        char[] x = in.next().toCharArray();\n        \n        int min = 0;\n        int max = x.length;\n        while(true) {\n            if(max-min == 1)\n                break;\n            int mid = (max+min)/2;\n            boolean eq = false;\n            for (int i = 0; i <= x.length-mid; i++) {\n                for (int j = 0; j <= x.length-mid; j++) {\n                    if(j == i)\n                        continue;\n                    eq = true;\n                    for (int k = 0; k < mid; k++) {\n                        if(x[i+k] != x[j+k]) { \n                            eq = false;\n                            break;\n                        }\n                    }\n                    if(eq)\n                        break;\n                }\n                if(eq) break;\n            }\n            if(eq) {\n                min = mid;\n            } else {\n                max = mid;\n            }\n        }\n        System.out.println(min);\n        \n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class A23 implements Runnable {\n\n\tprivate void Solution() throws IOException {\n\t\tString s = in.readLine();\n\t\tint n = s.length(), ans = 0;\n\t\tfor (int i = 0; i < n; i ++) {\n\t\t\tfor (int j = i; j < n; j ++) {\n\t\t\t\tfor (int k = i+1; k <= n; k ++) {\n\t\t\t\t\tfor (int g = k; g <= n; g ++) {\n\t\t\t\t\t\tif (s.substring(i,j).equals(s.substring(k,g))) {\n\t\t\t\t\t\t\tint l = s.substring(i,j).length();\n\t\t\t\t\t\t\tans = Math.max(ans, l);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tpublic static void main(String args[]) {\n\t\tnew A23().run();\n\t}\n\t\n\tBufferedReader in;\n\tStringTokenizer tokenizer;\n\t\n\tpublic void run() {\n\t\ttry {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            tokenizer = null;\n            Solution();\n            in.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n\t}\n\n\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\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", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class CodeF \n{\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\t\n\t\tpublic String nextLine()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn br.readLine();\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tthrow(new RuntimeException());\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic String next()\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t{\n\t\t\t\tString l = nextLine();\n\t\t\t\tif(l == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(l);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong[] res = new long[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic double[] nextDoubleArray(int n)\n\t\t{\n\t\t\tdouble[] res = new double[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextDouble();\n\t\t\treturn res;\n\t\t}\n\t\tpublic void sortIntArray(int[] array)\n\t\t{\n\t\t\tInteger[] vals = new Integer[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortLongArray(long[] array)\n\t\t{\n\t\t\tLong[] vals = new Long[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortDoubleArray(double[] array)\n\t\t{\n\t\t\tDouble[] vals = new Double[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\n\t\tpublic String[] nextStringArray(int n) \n\t\t{\t\n\t\t\tString[] vals = new String[n];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tvals[i] = next();\n\t\t\treturn vals;\n\t\t}\n\t\t\n\t\tInteger nextInteger()\n\t\t{\n\t\t\tString s = next();\n\t\t\tif(s == null)\n\t\t\t\treturn null;\n\t\t\treturn Integer.parseInt(s);\n\t\t}\n\t\t\n\t\tint[][] nextIntMatrix(int n, int m)\n\t\t{\n\t\t\tint[][] ans = new int[n][];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tans[i] = nextIntArray(m);\n\t\t\treturn ans;\n\t\t}\n\t}\n\t\n\tstatic int[] compute_prefix_function(char[] p) {\n\t    int[] pi = new int[p.length]; pi[0] = -1; int k = -1;\n\t    for (int i = 1; i < p.length; i++) {\n\t        while (k >= 0 && p[k + 1] != p[i]) k = pi[k];\n\t        if (p[k + 1] == p[i]) k++; pi[i] = k;\n\t    }\n\t    return pi;\n\t}\n\n\tstatic boolean KMP_Matcher(String pattern, String text) {\n\t    char[] p = pattern.toCharArray(); char[] t = text.toCharArray();\n\t    int[] pi = compute_prefix_function(p); int q = -1;\n\t    int cuenta = 0;\n\t    for (int i = 0; i < text.length(); i++) {\n\t        while (q >= 0 && p[q + 1] != t[i]) q = pi[q];\n\t        if (p[q + 1] == t[i]) q++;\n\t        if (q == p.length - 1) {\n\t            cuenta++;\n\t            q = pi[q];\n\t        }\n\t    }\n\t    return cuenta >= 2;\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner();\n\t\tString entrada = sc.next();\n\t\tint mejor = 0;\n\t\tfor(int i = 0; i < entrada.length(); i++)\n\t\t{\n\t\t\tfor(int j = i + 1; j <= entrada.length(); j++)\n\t\t\t{\n\t\t\t\tString sub = entrada.substring(i, j);\n\t\t\t\tif(KMP_Matcher(sub, entrada))\n\t\t\t\t\tmejor = Math.max(j - i, mejor);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(mejor);\n\t}\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemA_23 {\n    \n    final boolean ONLINE_JUDGE=System.getProperty(\"ONLINE_JUDGE\")!=null;\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok=new StringTokenizer(\"\");\n    \n    void init() throws FileNotFoundException{\n        if (ONLINE_JUDGE){\n            in=new BufferedReader(new InputStreamReader(System.in));\n            out =new PrintWriter(System.out);\n        }\n        else{\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\n        }\n    }\n    \n    String readString() throws IOException{\n        while(!tok.hasMoreTokens()){\n            tok=new StringTokenizer(in.readLine());\n        }\n        return tok.nextToken();\n    }\n    \n    int readInt() throws IOException{\n        return Integer.parseInt(readString());\n    }\n    \n    public static void main(String[] args){\n        new ProblemA_23().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    void solve() throws IOException{\n        String s = readString();\n        for (int length = s.length() - 1; length > 0; length--){\n            for (int i = 0; i < s.length() - length; i++){\n                if (s.lastIndexOf(s.substring(i, i + length)) > i){\n                    out.print(length);\n                    return;\n                }\n            }\n        }\n        out.print(0);\n    }\n}\n\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\npublic class A {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = new String(in.readLine());\n\t\tint len=s.length();\n\t\tint ans=0;\n\t\tfor (int i=0;i<len-1;i++) {\n\t\t\tfor (int j=i+1;j<len;j++) {\n\t\t\t\tint score=0;\n\t\t\t\tboolean flag=true;\n\t\t\t\tfor (int k=0;k+j<len && flag;k++) {\n\t\t\t\t\tif (s.charAt(i+k)==s.charAt(j+k)) {\n\t\t\t\t\t\tscore++;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tflag=false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (score>ans) {\n\t\t\t\t\tans=score;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class P023A {\n    public static void main(String[] args)\n    {\n        Scanner in = new Scanner(System.in);\n        String line = in.next();\n        \n        HashSet<String> hash = new HashSet<String>();\n        \n        int ans = 0;\n        for (int len = line.length()-1; len > 0; --len)\n        {\n            for (int i = 0; i + len <= line.length(); ++i)\n            {\n                String sub = line.substring(i, i+len);\n                if (hash.contains(sub))\n                {\n                    ans = Math.max(ans, sub.length());\n                }\n                \n                hash.add(sub);\n            }\n        }\n        \n        System.out.println(ans);\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n\n\tboolean test = false;\n\tPrintWriter pw = new PrintWriter(System.out);\n\tInputStreamReader inp = new InputStreamReader(System.in);\n\tBufferedReader in = new BufferedReader(inp);\n\t\n\tprivate String[] inData = {\"zzz\"\n\t\t\t};\n\t\n\t\n\tstatic int id = -1;\n\t\n\tpublic String readLine() {\n\t\tid++;\n\t\tif (test)\n\t\t\treturn inData[id];\n\t\telse\n\t\t\ttry{\n\t\t\t\treturn in.readLine();\t\n\t\t\t} catch( Exception e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\treturn \"\";\n\t}\n\n\tprivate void solve() {\n\t\t\n\t\tString readLine = readLine();\n\t\t\n\t\tint best = 0;\n\t\t\n\t\tfor (int i = 0; i < readLine.length(); i++) {\n\t\t\tfor (int j = i; j < readLine.length(); j++) {\n\t\t\t\tString substring = readLine.substring(i,j+1);\n\t\t\t\tString remainString = readLine.substring(i+1);\n\t\t\t\tif(remainString.contains(substring)){\n\t\t\t\t\tif(substring.length() > best){\n\t\t\t\t\t\tbest = substring.length();\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}\n\t\tSystem.out.println(best);\n\t}\n\t\n\tpublic static void main(String args[]) throws Exception {\n\n\t\tnew Main().solve();\n    }\n\n\t\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\npublic class x23A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString input = sc.next();\n\t\t//input+=\"3\";\n\t\tint longest=0;\n\t\tif(input.length()==1){\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tif(input.length()==2){\n\t\t\tif(input.charAt(0)==input.charAt(1)){\n\t\t\t\tSystem.out.println(1);\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\telse{\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);}\n\t\t}\n\t\tfor(int a=0;a<input.length()-1;a++){\n\t\t\tfor(int b=a+1;b<input.length();b++){\n\t\t\t\tfor(int c=1;(c+b)<input.length()+1;c++){\n\t\t\t\t//\tSystem.out.printf(\"%s %s %d\\n\", input.substring(a,a+c), input.substring(b,b+c), input.substring(a,a+c).compareTo(input.substring(b,b+c)));\n\t\t\t\t\tif(input.substring(a,a+c).compareTo(input.substring(b,b+c))==0)\n\t\t\t\t\tif(longest<c)longest=c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(longest);\n\t\t}\n\t}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "//package codeforces.br23;\n\nimport java.io.*;\n\n/**\n * User: Kandy\n * Date: 12.07.2010\n * Time: 21:51:52\n */\npublic class ProblemA {\n    public void solve() {\n        boolean oj = true;\n\n        try {\n            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"A.in\");\n            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"A.out\");\n            BufferedReader br = new BufferedReader(reader);\n            StreamTokenizer st = new StreamTokenizer(reader);\n            PrintWriter out = new PrintWriter(writer);\n\n            String s = br.readLine();\n            int n = s.length();\n\n            int max = 0;\n            for (int i = 0; i < n; i++)\n                for (int j = i; j < n; j++) {\n                    int len = j - i + 1;\n                    int count = 0;\n                    for (int k = 0; k < n - len + 1; k++) {\n                        boolean eq = true;\n                        for(int l = 0; l < len;l++) {\n                            if (s.charAt(i + l) != s.charAt(k + l)) {\n                                eq = false;\n                                break;\n                            }\n                        }\n                        if (eq) {\n                            count++;\n                        }\n                    }\n                    if (count >= 2 && len > max) {\n                        max = len;\n                    }\n                }\n\n            out.printf(\"%d\", max);\n\n            br.close();\n            out.close();\n            reader.close();\n            writer.close();\n        }\n        catch (Exception ex) {\n            ex.printStackTrace();\n        }\n        finally {\n        }\n    }\n\n\n    public static void main(String[] args) {\n        ProblemA f = new ProblemA();\n        f.solve();\n    }\n\n    private class MyTokenizer {\n        private String s;\n        private int cur;\n\n        public MyTokenizer(String s) {\n            this.s = s;\n            cur = 0;\n        }\n\n        public void skip() {\n            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\\n')) {\n                cur++;\n            }\n        }\n\n        public double getNum() {\n            skip();\n            String snum = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {\n                snum += s.charAt(cur);\n                cur++;\n            }\n            return Double.valueOf(snum);\n        }\n\n        public String getString() {\n            skip();\n            String s2 = \"\";\n            while (cur < s.length() && (((s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) || ((s.charAt(cur) >= 'A' && s.charAt(cur) <= 'Z')))) {\n                s2 += s.charAt(cur);\n                cur++;\n            }\n            return s2;\n        }\n\n        public char getCurrentChar() throws Exception {\n            if (cur < s.length())\n                return s.charAt(cur);\n            else\n                throw new Exception(\"Current character out of string length\");\n        }\n\n        public void moveNextChar() {\n            if (cur < s.length())\n                cur++;\n        }\n\n        public boolean isFinished() {\n            return cur >= s.length();\n        }\n    }\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\nimport com.sun.org.apache.xalan.internal.xsltc.dom.BitArray;\nimport java.io.DataOutputStream;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.BitSet;\nimport java.util.Hashtable;\nimport java.util.Iterator;\nimport java.util.Map.Entry;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\n\n/**\n *\n * @author abdelrahman\n */\npublic class p1 {\n\n    /**\n     * @param args the command line arguments\n     */\n    public static void main(String[] args) {\n        new p1().run();\n\n    }\n\n    private void run() {\n        try {\n            // TODO code application logic here\n            Scanner scanner = new Scanner(System.in);\n            String in = scanner.next();\n            \n            Hashtable<String, Boolean> tmp = new Hashtable<String, Boolean>();\n            int sol = 0;\n            for (int i = 0; i < in.length(); i++) {\n                for (int j = i + 1; j <= in.length(); j++) {\n                    String str = in.substring(i, j);\n                    if (tmp.containsKey(str)) {\n                        if (tmp.get(str)) {\n                            if(str.length() > sol)  sol=str.length();\n                            boolean tmp1 = tmp.remove(str);\n                            tmp.put(str, false);\n                        }\n                    } else {\n                        tmp.put(str, Boolean.TRUE);\n                    }\n                }\n\n            }\n            System.out.println(sol);\n        } catch (Exception ex) {\n        }\n    }\n\n    \n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport static java.lang.Math.*;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class CFC23A implements Runnable {\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new CFC23A()).start();\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint res = 0;\n\t\tString str = nextToken();\n\t\tfor(int i = 0; i < str.length(); ++i)\n\t\t\tfor(int j = i + 1; j <= str.length(); ++j)\n\t\t\t\tif(isOk(str.substring(i, j), str))\n\t\t\t\t\tres = max(res, j - i);\n\t\tout.println(res);\n\t}\n\n\tprivate boolean isOk(String substring, String str) {\n\t\tint from = 0, kol = 0;\n\t\twhile(str.indexOf(substring, from) != -1 && kol < 2) {\n\t\t\t++kol;\n\t\t\tfrom = str.indexOf(substring, from) + 1;\n\t\t}\n\t\treturn kol >= 2;\n\t}\n\n\t@Override\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(new File(\"input.txt\")));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//out = new PrintWriter(new File(\"output.txt\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t\tin.close();\n\t\t} catch (IOException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\n\t}\n\n\tString nextLine() throws IOException {\n\t\ttok = null;\n\t\treturn in.readLine();\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\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 (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "/**\n * Mx 04:06:52 \u0635 14/01/2014\n */\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder line = new StringBuilder(reader.readLine());\n        int length = 0;\n        for (int head = 0; head < line.length(); head++) {\n            for (int tail = line.length() - 1; tail > head; tail--) {\n                String subString = line.substring(head, tail);\n                if(line.indexOf(subString,head+1)>-1){\n                    length = Math.max(subString.length(), length);\n                }\n            }\n        }\n        System.out.println(length);\n    }\n}", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class A {\n\n\tprivate BufferedReader in;\t\n\tprivate StringTokenizer st;\n\t\n\t\n\tvoid solve() throws IOException{\n\t\t\n\t\tint len = 0;\n\t\tString x = next();\n\t\tHashSet<String> h = new HashSet<String>();\n\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\tfor (int j = i+1; j <= x.length(); j++) {\n\t\t\t\tString y = x.substring(i,j);\n\t\t\t\tif(h.contains(y)){\n\t\t\t\t\tif(y.length()>len) len = y.length();\n\t\t\t\t}\n\t\t\t\telse h.add(y);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(len);\n\t\t\n\t}\n\tA() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\t\t\t\n\t\teat(\"\");\n\t\tsolve();\t\t\t\n\t}\n\t\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\n\tpublic static void main(String[] args) throws IOException {\t\t\n\t\t\n\t\tnew A();\n\t}\n\n}\n", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main{\n    \n    private static int[] T;\n    \n    public static void main(String[] args){\n        \n        Scanner in = new Scanner(System.in);\n        char[] input =  in.nextLine().toCharArray();\n        int length = input.length;\n        int max = 0;\n        for(int i=0; i<length; i++){\n            char[] subString = Arrays.copyOfRange(input, 1, input.length);\n            int temp = solve(input, subString);\n            if(temp > max) max = temp;\n            input = Arrays.copyOfRange(input, 1, input.length);\n        }\n        System.out.println(max);\n        \n    }\n\n    private static int solve(char[] P, char[] S) {\n        \n        T = new int[P.length+1];\n        \n        preKmp(P, P.length, T);\n        int max = 0;\n\n        int i = 0, j = 0;\n        while (j < S.length) {\n            while (i > -1 && (P[i] != S[j]))\n                i = T[i];\n            i++;\n            j++;\n            if ( i > max) max = i;\n            if (i >= P.length) {\n                i = T[i];\n            }\n        }\n        \n        return max;\n        \n        \n    }\n\n    private static void preKmp(char[] x, int m, int[] kmpNext) {\n           int i = 0, j = kmpNext[0] = -1;\n           \n           while (i < m-1) {\n              while (j > -1 && x[i] != x[j])\n                 j = kmpNext[j];\n              i++;\n              j++;\n              if (x[i] == x[j])\n                 kmpNext[i] = kmpNext[j];\n              else\n                 kmpNext[i] = j;\n           }\n\n        \n    }\n} ", "complexity": "cubic", "problem": "23_A. You're Given a String...", "from": "CODEFORCES"}
{"src": "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        EPhoenixAndComputers solver = new EPhoenixAndComputers();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class EPhoenixAndComputers {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt(), m = in.nextInt();\n            ModInt mod = new ModInt(m);\n            int[] factorial = new int[n + 1];\n            int[][] binomial = new int[n + 1][n + 1];\n            int[] two = new int[n + 1];\n            for (int i = 0; i <= n; i++) {\n                binomial[i][0] = 1;\n                for (int j = 1; j <= i; j++)\n                    binomial[i][j] = mod.add(binomial[i - 1][j], binomial[i - 1][j - 1]);\n                factorial[i] = i == 0 ? 1 : mod.multiply(factorial[i - 1], i);\n                two[i] = i == 0 ? 1 : mod.multiply(2, two[i - 1]);\n            }\n            int[][] dp = new int[n + 1][n + 1];\n            dp[0][0] = 1;\n            int answer = 0;\n            for (int i = 1; i <= n; i++) {\n                for (int j = 1; j <= i; j++) {\n                    for (int x = 1; x <= i; x++) {\n                        dp[i][j] = mod.add(dp[i][j],\n                                mod.multiply(binomial[i][x], mod.multiply(two[x - 1], dp[i - x][j - 1])));\n                    }\n                }\n            }\n            for (int k = 0; k < n; k++) {\n                answer = mod.add(answer, dp[n - k][k + 1]);\n            }\n            out.println(answer);\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 println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\n');\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n\n    static class ModInt {\n        int modulo;\n\n        public ModInt(int m) {\n            modulo = m;\n        }\n\n        public int add(int x, int y) {\n            x += y;\n            if (x >= modulo) x -= modulo;\n            return x;\n        }\n\n        public int multiply(int x, int y) {\n            return (int) ((x * 1L * y) % modulo);\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)) 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            }\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", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1515E{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint md = sc.nextInt();\n\t\tint k = (n + 1) / 2;\n\t\tint[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;\n\t\tfor (int h = 1; h <= k; h++)\n\t\t\tfor (int l = h; l <= n - h + 1; l++)\n\t\t\t\tdp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);\n\t\tint ans = 0;\n\t\tfor (int h = 1; h <= k; h++)\n\t\t\tans = (ans + dp[h][n - h + 1]) % md;\n\t\tSystem.out.println(ans);\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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(), md = sc.nextInt();\n        int k = (n + 1) / 2;int ans = 0;\n        int[][] dp = new int[k + 1][n + 1];dp[0][0] = 1;\n        for (int h = 1; h <= k; h++)\n            for (int l = h; l <= n - h + 1; l++)\n                dp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);\n        for (int h = 1; h <= k; h++)\n            ans = (ans + dp[h][n - h + 1]) % md;\n        System.out.println(ans);\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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) 1e18 + 10;\n    static final int MOD = (int) 1e9 + 7;\n\n    static int M;\n    static long[] f, fi, two;\n\n    static long pow(long a, long b) {\n        long res = 1;\n        while (b != 0) {\n            if ((b & 1) == 1)\n                res = (res * a) % M;\n            a = (a * a) % M;\n            b >>= 1;\n        }\n        return res;\n    }\n\n    static long C(int n, int k) {\n        return f[n] * fi[k] % M * fi[n - k] % M;\n    }\n\n    static void prepare(int n) {\n        f = new long[n];\n        f[0] = 1;\n        for (int i = 1; i < n; i++) {\n            f[i] = (f[i - 1] * i) % M;\n        }\n        fi = new long[n];\n        for (int i = 0; i < n; i++) {\n            fi[i] = pow(f[i], M - 2);\n        }\n        two = new long[n];\n        two[0] = 1;\n        for (int i = 1; i < n; i++) {\n            two[i] = (two[i - 1] * 2) % M;\n        }\n    }\n\n    static void solve() {\n        int n = in.nextInt();\n        M = in.nextInt();\n        prepare(n + 10);\n        long[][] dp = new long[n + 1][n];\n        for (int i = 1; i <= n; i++) {\n            dp[i][1] = two[i - 1];\n        }\n        for (int i = 1; i <= n; i++) {\n            for (int j = 2; j < n; j++) {\n                for (int k = 1; k <= i - 2; k++) {\n                    if (k < j - 2)\n                        continue;\n                    int len = i - k - 1;\n                    dp[i][j] = (dp[i][j] + dp[k][j - 1] * two[len - 1] % M * C(k - (j - 2) + len, len) % M) % M;\n                }\n            }\n        }\n        long ans = 0;\n        for (int j = 1; j < n; j++) {\n            ans = (ans + dp[n][j]) % M;\n        }\n        out.println(ans);\n\n    }\n\n    public static void main(String[] args) {\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n\n        int t = 1;\n//        t = in.nextInt();\n        while (t-- > 0) {\n            solve();\n        }\n\n        out.flush();\n        out.close();\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}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/**\n    @author KhanhNguyenn\n */\n \npublic class C{\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    // main solver\n    // sub-problem: 2 orders to merge together x1,x2,..,xn and y1,y2,..,ym\n    // D\u1ef1a v\u00e0o b\u00e0i to\u00e1n chia k\u1eb9p Euler, ta ch\u1ee9ng minh dc s\u1ed1 c\u00e1ch merge l\u00e0\n    // (m+n)C(m-1)=(m+n)C(n+1)\n    static class Task{\n        int M;\n        public void solve(InputReader in, PrintWriter out) {\n            int n= in.nextInt(); M= in.nextInt();\n            if(n<=1){\n                out.println(n);\n                return;\n            }\n            int[] pow2= new int[n+1];\n            pow2[0]=1;\n            for(int i=1;i<=n;i++) pow2[i]=mul(2,pow2[i-1]);\n\n            // calculate nCk\n            // nCk= (n-1)C(k-1)+ (n-1)Ck\n            int[][] Ckn= new int[n+1][n+1];\n            for(int i=0;i<=n;i++){\n                Ckn[i][i]=1; Ckn[0][i]=1;\n                for(int j=i-1;j>=1;j--){\n                    Ckn[j][i]= add(Ckn[j-1][i-1],Ckn[j][i-1]);\n                }\n            }\n\n            int ans=0;\n            int[][] dp= new int[n+1][n+1];\n            dp[1][1]=1;\n            //dp[i][j]: number of ways to turn on first i , using j manually\n            for(int i=2;i<=n;i++){\n                dp[i][i]= pow2[i-1];\n                for(int j=1;j<=i-1;j++){\n                    for(int k=1;k<=j;k++){\n                            dp[i][j]= add(dp[i][j],mul(mul(pow2[k-1],dp[i-k-1][j-k]),Ckn[k][j])); \n                    }\n                }\n            }\n            for(int i=0;i<=n;i++) ans= add(ans,dp[n][i]);\n            out.println(ans);\n        }\n\n        public int add(int a, int b){\n            a+=b;\n            if(a>=M) a-=M;\n            return a;\n        }\n\n        public int mul(int a, int b){\n            long res= (long)a*(long)b;\n            res %=M;\n            return (int)res;\n        }\n\n        \n\n    }\n    static class Pair {\n        public String x;\n        public int y;\n        public Pair(String x, int y){\n            this.x = x;\n            this.y=y;\n        }\n \n        // @Override\n        // public int compareTo(Pair o) {\n        //     if (this.x > o.x){\n        //         return 1;\n        //     }\n        //     else if (this.x < o.x){\n        //         return -1;\n        //     }\n        //     else{\n        //         return Integer.compare(this.y, o.y);\n        //     }\n        // }\n    }\n    // fast input reader class;\n    static class InputReader {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public InputReader(InputStream stream) {\n            br = new BufferedReader(new InputStreamReader(stream));\n        }\n \n        public String nextToken() {\n            while (st == null || !st.hasMoreTokens()) {\n                String line = null;\n                try {\n                    line = br.readLine();\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                if (line == null) {\n                    return null;\n                }\n                st = new StringTokenizer(line);\n            }\n            return st.nextToken();\n        }\n \n        public int nextInt() {\n            return Integer.parseInt(nextToken());\n        }\n        public double nextDouble(){\n            return Double.parseDouble(nextToken());\n        }\n        public long nextLong(){\n            return Long.parseLong(nextToken());\n        }\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\n// StringBuilder uses java.lang\n \n \npublic class mC {\n    \n    \n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        StringBuilder st = new StringBuilder();\n        int t = 1;\n        for (int test = 0; test < t; test++) {\n            int n = sc.nextInt();\n            int MOD = sc.nextInt();\n\n            long[] factorial = new long[1000];\n            long[] powerOfTwo = new long[1000];\n            factorial[0]=1;\n            powerOfTwo[0]=1;\n            for (int i=1;i<1000;i++) {\n                factorial[i]=i*factorial[i-1];\n                factorial[i] %= MOD;\n                powerOfTwo[i]=2*powerOfTwo[i-1];\n                if (powerOfTwo[i]>=MOD) {\n                    powerOfTwo[i]-=MOD;\n                }\n            }\n            long[] oneOverFactorial = new long[500];\n            oneOverFactorial[0]=1;\n            oneOverFactorial[1]=1;\n            for (int i=2;i<450;i++) {\n                oneOverFactorial[i] = fastPow(factorial[i],MOD-2,MOD);\n            }\n            long dp[][] = new long[n+3][n+3]; // first value number of computers considered\n                                // second value number of computers manually on\n            \n            dp[1][1]=1;\n            for (int i=2;i<=n;i++) { // from left to right, over first i computers\n                dp[i][i]=powerOfTwo[i-1];\n                for (int j=1;j<i-1;j++) { // number of computers turned on manually\n                    for (int k=1;k<=j;k++) {\n                        // want to add dp[j][k]*factorial[k+(i-j-1)]*oneOverFactorial[k]*oneOverFactorial[i-j-1]*powerOfTwo[i-j-2]\n                        long add = dp[j][k]*factorial[k+(i-j-1)];\n                        add %= MOD;\n                        add *= oneOverFactorial[k];\n                        add %= MOD;\n                        add *= oneOverFactorial[i-j-1];\n                        add %= MOD;\n                        add *= powerOfTwo[i-j-2];\n                        add %= MOD;\n                        dp[i][k+(i-j-1)]+=add;\n                        dp[i][k+(i-j-1)]%=MOD;\n                    }\n                }\n            }\n            long ans = 0;\n            for (int i=1;i<=n;i++) {\n                ans+=dp[n][i];\n            }\n            ans %= MOD;\n            System.out.println(ans);\n        }\n        \n        //System.out.print(st.toString());\n    }\n    \n    public static int goodLeft(int n, int[] p) { // i.e. ... 4 5 6\n        int begin = 0;\n        for (int i=0;i<n;i++) {\n            if (n-i==p[n-i-1]) {\n                begin++;\n            } else {\n                break;\n            }\n        }\n        return begin;\n    }\n    public static int goodRight(int n, int[] p) { // i.e. 6 5 4 ...\n        int end = 0;\n        for (int i=n-1;i>=0;i--) {\n            if (i==p[i]) {\n                end++;\n            } else {\n                break;\n            }\n        }\n        return end;\n    }\n    public static int findNthInArray(int[] arr,int val,int start,int o) {\n        if (o==0) {\n            return start-1;\n        } else if (arr[start] == val) {\n            return findNthInArray(arr,val,start+1,o-1);\n        } else {\n            return findNthInArray(arr,val,start+1,o);\n        }\n    }\n    public static ArrayList<Integer> dfs(int at,ArrayList<Integer> went,ArrayList<ArrayList<Integer>> connect) {\n        for (int i=0;i<connect.get(at).size();i++) {\n            if (!(went.contains(connect.get(at).get(i)))) {\n                went.add(connect.get(at).get(i));\n                went=dfs(connect.get(at).get(i),went,connect);\n            }\n        }\n        return went;\n    } public static int[] bfs (int at, int[] went, ArrayList<ArrayList<Integer>> queue, int numNodes, ArrayList<ArrayList<Integer>> connect) {\n        if (went[at]==0) {\n            went[at]=queue.get(numNodes).get(1);\n            for (int i=0;i<connect.get(at).size();i++) {\n                if (went[connect.get(at).get(i)]==0) {\n                    ArrayList<Integer> temp = new ArrayList<>();\n                    temp.add(connect.get(at).get(i));\n                    temp.add(queue.get(numNodes).get(1)+1);\n                    queue.add(temp);\n                }\n            }\n            \n        }\n        if (queue.size()==numNodes+1) {\n            return went;\n        } else {\n            return bfs(queue.get(numNodes+1).get(0),went, queue, numNodes+1, connect);\n        }\n    }\n    public static long fastPow(long base,long exp,long mod) {\n        if (exp==0) {\n            return 1;\n        } else {\n            if (exp % 2 == 1) {\n                long z = fastPow(base,(exp-1)/2,mod);\n                return ((((z*base) % mod) * z) % mod);\n            } else {\n                long z = fastPow(base,exp/2,mod);\n                return ((z*z) % mod);\n            }\n        }\n    }\n    public static int fastPow(int base,long exp) {\n        if (exp==0) {\n            return 1;\n        } else {\n            if (exp % 2 == 1) {\n                int z = fastPow(base,(exp-1)/2);\n                return ((((z*base)) * z));\n            } else {\n                int z = fastPow(base,exp/2);\n                return ((z*z));\n            }\n        }\n    }\n    public static int firstLarger(long val,ArrayList<Long> ok,int left,int right) {\n        \n        if (ok.get(right)<=val) {\n            return -1;\n        }\n        if (left==right) {\n            return left;\n        } else if (left+1==right) {\n            if (val<ok.get(left)) {\n                return left;\n            } else {\n                return right;\n            }\n        } else {\n            int mid = (left+right)/2;\n            if (ok.get(mid)>val) {\n                return firstLarger(val,ok,left,mid);\n            } else {\n                return firstLarger(val,ok,mid+1,right);\n            }\n        }\n    }\n    public static int binSearchArr(long val,ArrayList<Integer> ok,long[] arr,int left,int right) {\n        \n        if (arr[ok.get(right)]<=val) {\n            return -1;\n        }\n        if (left==right) {\n            return left;\n        } else if (left+1==right) {\n            if (val<arr[ok.get(left)]) {\n                return left;\n            } else {\n                return right;\n            }\n        } else {\n            int mid = (left+right)/2;\n            if (arr[ok.get(mid)]>val) {\n                return binSearchArr(val,ok,arr,left,mid);\n            } else {\n                return binSearchArr(val,ok,arr,mid+1,right);\n            }\n        }\n    }\n    public static long gcd(long a, long b) {\n        if (b>a) {\n            return gcd(b,a);\n        }\n        if (b==0) {\n            return a;\n        }\n        if (a%b==0) {\n            return b;\n        } else {\n            return gcd(b,a%b);\n        }\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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            int MOD = in.nextInt();\n\n            int[][] C = new int[n + 1][n + 1];\n            C[0][0] = 1;\n            for (int i = 1; i < C.length; i++) {\n                C[i][0] = 1;\n                for (int j = 1; j < C.length; j++) {\n                    C[i][j] = C[i - 1][j] + C[i - 1][j - 1];\n                    if (C[i][j] >= MOD) {\n                        C[i][j] -= MOD;\n                    }\n                }\n            }\n\n            int[] p2 = new int[n + 1];\n            p2[0] = 1;\n            for (int i = 1; i < p2.length; i++) {\n                p2[i] = 2 * p2[i - 1] % MOD;\n            }\n\n            int[][] d = new int[n + 1][n + 1];\n            d[0][0] = 1;\n            // Total.\n            for (int i = 1; i <= n; i++) {\n                // Switched on manually.\n                for (int j = 1; j <= i; j++) {\n                    // Switched on manually in the first block.\n                    for (int t = 1; t <= j; t++) {\n                        if (t == i - 1) {\n                            continue;\n                        }\n                        d[i][j] = (int) ((d[i][j] + (long) C[j][t] * p2[t - 1] % MOD * d[i - t - (i == t ? 0 : 1)][j - t]) % MOD);\n                    }\n                }\n            }\n\n            int ans = 0;\n            for (int k = 1; k <= n; k++) {\n                ans += d[n][k];\n                if (ans >= MOD) {\n                    ans -= MOD;\n                }\n            }\n\n            out.println(ans);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream stream) {\n            in = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String 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", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "//https://github.com/EgorKulikov/yaal/tree/master/lib/main/net/egork\n        \nimport java.util.*;\nimport java.io.*;\npublic class B{\n    static PrintWriter out;\n    static InputReader in;\n    public static void main(String args[]){\n        out = new PrintWriter(System.out);\n        in = new InputReader();\n        new B();\n        out.flush(); out.close();\n    }   \n    B(){\n        solve();\n    }\n    class pair{\n        int F, S;\n        pair(int a, int b){\n            F = a; S = b;\n        }\n    }\n    void solve(){\n        int n = in.nextInt(), mod = in.nextInt();\n        long dp[][] = new long[n + 1][n + 1];\n        long ncr[][] = new long[810][410];\n        ncr[0][0] = 1;\n        for(int i = 1; i < 810; i++){\n            for(int j = 0; j < 410; j++){\n                ncr[i][j] = (ncr[i - 1][j] + (j > 0 ? ncr[i - 1][j - 1] : 0)) % mod;\n            }\n        }\n        for(int i = 1; i <= n; i++)dp[i][i] = 1;\n        for(int i = 1; i < n; i++){\n            for(int j = 1; j + i <= n; j++){\n                int end = i + j;\n                dp[j][end] = (dp[j + 1][end] + dp[j][end - 1]) % mod;\n            }\n        }\n        long value[] = new long[n + 1];\n        for(int i = 1; i <= n; i++){\n            value[i] = dp[1][i];\n        }\n        long fdp[][] = new long[n + 2][n + 2];\n        fdp[0][0] = 1;\n        long ans = 0;\n        for(int b = 1; b <= (n + 1) / 2; b++){\n            for(int i = 1; i <= n; i++){\n                for(int k = Math.max(0, b - 2); k < i; k++){\n                    fdp[i + 1][b] = (fdp[i + 1][b] + fdp[k][b - 1] * value[i - k] % mod * ncr[k - b + 2 + i - k - 1][i - k] % mod) % mod;\n                }\n            }\n            ans = (ans + fdp[n + 1][b]) % mod;\n        }\n        out.print(ans);\n    }\n    public static class InputReader{\n        BufferedReader br;\n        StringTokenizer st;\n        InputReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\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        public String next(){\n            while(st == null || !st.hasMoreTokens()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch(IOException e){}\n            }\n            return st.nextToken();\n        }\n    }\n}\n\t", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    public static void main(String args[]) {new Main().run();}\n\n    FastReader in = new FastReader();\n    PrintWriter out = new PrintWriter(System.out);\n    void run(){\n        work();\n        out.flush();\n    }\n    long mod=998244353;\n    long gcd(long a,long b) {\n        return a==0?b:gcd(b%a,a);\n    }\n\n    void work() {\n        int n=ni();\n        mod=nl();\n        long[] dp1=new long[401];\n        long[][] dp2=new long[n+1][n+1];\n        long[][] C=new long[401][401];\n        for(int j=0;j<=400;j++){\n            for(int i=0;i<=j;i++){\n                if(i==0||j==i){\n                    C[i][j]=1;\n                }else{\n                    C[i][j]=(C[i-1][j-1]+C[i][j-1])%mod;\n                }\n            }\n        }\n        for(int i=1;i<=400;i++){\n            for(int j=0;j<i;j++){\n                dp1[i]=(dp1[i]+C[j][i-1])%mod;\n            }\n        }\n        for(int i=1;i<=n;i++){\n            dp2[i][i]=dp1[i];\n        }\n        for(int i=1;i<=n;i++){\n            for(int j=1;j<i;j++){\n                for(int k=1;k<j;k++){\n                    dp2[i][j]=dp2[i][j]+((((dp2[i-k-1][j-k]*dp1[k])%mod)*C[k][j])%mod);\n                    dp2[i][j]%=mod;\n                }\n            }\n        }\n        long ret=0;\n        for(int j=1;j<=n;j++){\n            ret=(ret+dp2[n][j])%mod;\n        }\n        out.println(ret);\n    }\n\n\n    private ArrayList<long[]>[] ngw(int n, int m) {\n        ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];\n        for(int i=0;i<n;i++) {\n            graph[i]=new ArrayList<>();\n        }\n        for(int i=1;i<=m;i++) {\n            long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();\n            graph[(int)s].add(new long[] {e,w});\n            graph[(int)e].add(new long[] {s,w});\n        }\n        return graph;\n    }\n\n    private int ni() {\n        return in.nextInt();\n    }\n\n    private long nl() {\n        return in.nextLong();\n    }\n\n    private String ns() {\n        return in.next();\n    }\n\n    private long[] na(int n) {\n        long[] A=new long[n];\n        for(int i=0;i<n;i++) {\n            A[i]=in.nextLong();\n        }\n        return A;\n    }\n    private int[] nia(int n) {\n        int[] A=new int[n];\n        for(int i=0;i<n;i++) {\n            A[i]=in.nextInt();\n        }\n        return A;\n    }\n}\n\nclass FastReader\n{\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastReader()\n    {\n        br=new BufferedReader(new InputStreamReader(System.in));\n    }\n\n\n    public String next()\n    {\n        while(st==null || !st.hasMoreElements())//\u56de\u8f66\uff0c\u7a7a\u884c\u60c5\u51b5\n        {\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    {\n        return Integer.parseInt(next());\n    }\n\n    public long nextLong()\n    {\n        return Long.parseLong(next());\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "//package com.company.cf.global14;\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.List;\nimport java.util.StringTokenizer;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\n\npublic class E {\n    FastScanner in;\n    PrintWriter out;\n    private int M;\n\n    public static void main(String[] args) {\n        new E().solve();\n    }\n\n    private void solve() {\n        in = new FastScanner(System.in);\n        out = new PrintWriter(System.out);\n\n        solveCase();\n\n        out.close();\n    }\n\n    long[][] comb = new long[512][512];\n    private void solveCase() {\n        int n = in.nextInt();\n        this.M = in.nextInt();\n\n        calcComb(n, M);\n        for (int i = 0; i < 512; i++) {\n            for (int j = 0; j < 512; j++) {\n                memoDivide[i][j] = -1;\n                memoDP[i][j] = -1;\n                dpG[i] = -1;\n            }\n        }\n\n        long res = g(n);\n        for (int i = 1;i <= n - 1; i++) {\n            res = (res + dp(n, i)) % M;\n        }\n\n        out.println(res);\n    }\n\n    long[] dpG = new long[512];\n    private long g(int n) {\n        if (n < 2) return 1;\n        if (n == 2) return 2;\n        if (dpG[n] != -1) return dpG[n];\n\n        long res = 0;\n        for (int divide = 0; divide < n; divide++) {\n            res = (res + divider(divide, n - divide - 1)) % M;\n        }\n        return (dpG[n] = res);\n    }\n\n    long[][] memoDivide = new long[512][512];\n    private long divider(int a, int b) {\n        if (a == 0 || b == 0) return 1;\n        if (memoDivide[a][b] != -1) return memoDivide[a][b];\n        return (memoDivide[a][b] = ((divider(a - 1, b) + divider(a, b - 1)) % M));\n    }\n\n    long[][] memoDP = new long[512][512];\n    private long dp(int n, int i) {\n        if (n > 0 && i == 0) return 0;\n        if (n == 0 && i > 0) return 0;\n        if (i > n) return 0;\n        if (n == 0 && i == 0) return 1;\n        if (i == n) return g(n);\n        if (i <= 1) return 0;\n//        if (n == 1 && i != 1) return 0;\n//        if (n == 2 && i == 1) return 0;\n        if (memoDP[n][i] != -1) return memoDP[n][i];\n\n//        long res = (i * dp(n - 2, i - 1)) % M;\n        long res = 0;\n        for (int failure = 1; failure < n - 1 && i - failure >= 1; failure++) {\n            res += ((g(failure) * comb[i][failure]) % M) * dp(n - failure - 1, i - failure);\n            res %= M;\n        }\n        return (memoDP[n][i] = res);\n    }\n\n    private void calcComb(int n, int m) {\n        for (int i = 0; i < 512; i++) {\n            comb[0][i] = 0;\n        }\n        for (int i = 0; i < 512; i++) {\n            comb[i][0] = 1;\n        }\n        for (int i = 1; i <= n; i++) {\n            for (int j = 1; j <= n; j++) {\n                comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % m;\n            }\n        }\n    }\n\n\n    static class FastScanner {\n\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}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/**\n    @author KhanhNguyenn\n */\n \npublic class C{\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    // main solver\n    // sub-problem: 2 orders to merge together x1,x2,..,xn and y1,y2,..,ym\n    // D\u1ef1a v\u00e0o b\u00e0i to\u00e1n chia k\u1eb9p Euler, ta ch\u1ee9ng minh dc s\u1ed1 c\u00e1ch merge l\u00e0\n    // (m+n)C(m-1)=(m+n)C(n+1)\n    static class Task{\n        int M;\n        public void solve(InputReader in, PrintWriter out) {\n            int n= in.nextInt(); M= in.nextInt();\n            if(n<=1){\n                out.println(n);\n                return;\n            }\n\n            // calculate nCk\n            // nCk= (n-1)C(k-1)+ (n-1)Ck\n            int[][] Ckn= new int[n+1][n+1];\n            for(int i=0;i<=n;i++){\n                Ckn[i][i]=1; Ckn[0][i]=1;\n                for(int j=i-1;j>=1;j--){\n                    Ckn[j][i]= add(Ckn[j-1][i-1],Ckn[j][i-1]);\n                }\n            }\n\n            int ans=0;\n            int[][] dp= new int[n+1][n+1];\n            dp[1][1]=1;\n            //dp[i][j]: number of ways to turn on first i , using j manually\n            for(int i=2;i<=n;i++){\n                dp[i][i]= mul(2,dp[i-1][i-1]);\n                for(int j=1;j<=i-1;j++){\n                    for(int k=1;k<=j;k++){\n                            dp[i][j]= add(dp[i][j],mul(mul(dp[k][k],dp[i-k-1][j-k]),Ckn[k][j])); \n                    }\n                }\n            }\n            for(int i=0;i<=n;i++) ans= add(ans,dp[n][i]);\n            out.println(ans);\n        }\n\n        public int add(int a, int b){\n            a+=b;\n            if(a>=M) a-=M;\n            return a;\n        }\n\n        public int mul(int a, int b){\n            long res= (long)a*(long)b;\n            res %=M;\n            return (int)res;\n        }\n        \n\n    }\n    static class Pair {\n        public String x;\n        public int y;\n        public Pair(String x, int y){\n            this.x = x;\n            this.y=y;\n        }\n \n        // @Override\n        // public int compareTo(Pair o) {\n        //     if (this.x > o.x){\n        //         return 1;\n        //     }\n        //     else if (this.x < o.x){\n        //         return -1;\n        //     }\n        //     else{\n        //         return Integer.compare(this.y, o.y);\n        //     }\n        // }\n    }\n    // fast input reader class;\n    static class InputReader {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public InputReader(InputStream stream) {\n            br = new BufferedReader(new InputStreamReader(stream));\n        }\n \n        public String nextToken() {\n            while (st == null || !st.hasMoreTokens()) {\n                String line = null;\n                try {\n                    line = br.readLine();\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                if (line == null) {\n                    return null;\n                }\n                st = new StringTokenizer(line);\n            }\n            return st.nextToken();\n        }\n \n        public int nextInt() {\n            return Integer.parseInt(nextToken());\n        }\n        public double nextDouble(){\n            return Double.parseDouble(nextToken());\n        }\n        public long nextLong(){\n            return Long.parseLong(nextToken());\n        }\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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 lucasr\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\tEPhoenixAndComputers solver = new EPhoenixAndComputers();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class EPhoenixAndComputers {\n\t\tpublic static MyScanner sc;\n\t\tpublic static PrintWriter out;\n\n\t\tpublic void solve(int testNumber, MyScanner sc, PrintWriter out) {\n\t\t\tEPhoenixAndComputers.sc = sc;\n\t\t\tEPhoenixAndComputers.out = out;\n\t\t\tint n = sc.nextInt();\n\t\t\tlong M = sc.nextLong();\n\t\t\tMathLib.MOD = M;\n\t\t\tlong[][] comb = MathLib.getComb(n + 5);\n\t\t\tlong[] pots2 = MathLib.getPots(2, n + 2);\n\t\t\tlong[] inv = new long[n + 5];\n\t\t\tfor (int i = 1; i < inv.length; i++) {\n\t\t\t\tinv[i] = MathLib.inverse(i);\n\t\t\t}\n\t\t\tlong[][] ret = new long[n + 1][n + 1]; // size, cant\n\t\t\tfor (int size = 0; size <= n; size++) {\n\t\t\t\tif (size <= 1) {\n\t\t\t\t\tret[size][size] = 1;\n\t\t\t\t} else if (size == 2) {\n\t\t\t\t\tret[size][2] = 2;\n\t\t\t\t} else {\n\t\t\t\t\tlong[] me = ret[size];\n\t\t\t\t\tme[size] = pots2[size - 1];\n\t\t\t\t\tfor (int i = 1; i + 1 < size; i++) {\n\t\t\t\t\t\tint prev = i, next = size - i - 1;\n\t\t\t\t\t\tlong tmp = pots2[i - 1];\n\t\t\t\t\t\tfor (int c = 0; c <= next; c++) {\n\t\t\t\t\t\t\tlong tot = (ret[next][c] * comb[c][c + prev]) % MathLib.MOD;\n\t\t\t\t\t\t\ttot = (tot * tmp) % MathLib.MOD;\n\t\t\t\t\t\t\tme[prev + c] += tot;\n\t\t\t\t\t\t\tme[prev + c] %= MathLib.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\tlong ans = 0;\n\t\t\tfor (int i = 0; i <= n; i++) {\n\t\t\t\tans += ret[n][i];\n\t\t\t}\n\t\t\tans %= MathLib.MOD;\n\t\t\tout.println(ans);\n\t\t}\n\n\t}\n\n\tstatic class MathLib {\n\t\tpublic static long MOD = 1000000007;\n\n\t\tpublic static long mult(long x, long y) {\n\t\t\treturn (x * y) % MOD;\n\t\t}\n\n\t\tpublic static long pow(long base, long exp) {\n\t\t\tif (exp == 0) return 1;\n\t\t\tif ((exp & 1) == 1) return mult(base, pow(base, exp - 1));\n\t\t\treturn pow(mult(base, base), exp / 2);\n\t\t}\n\n\t\tpublic static long inverse(long x) {\n\t\t\treturn pow(x, MOD - 2);\n\t\t}\n\n\t\tpublic static long[] getPots(long base, int max) {\n\t\t\tlong[] ret = new long[max + 1];\n\t\t\tret[0] = 1;\n\t\t\tfor (int i = 1; i <= max; i++) {\n\t\t\t\tret[i] = mult(ret[i - 1], base);\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic static long[][] getComb(int max) {\n\t\t\tlong[][] ret = new long[max + 1][max + 1];\n\t\t\tfor (int n = 0; n <= max; n++) {\n\t\t\t\tret[0][n] = ret[n][n] = 1;\n\t\t\t\tfor (int k = 1; k < n; k++) {\n\t\t\t\t\tret[k][n] = (ret[k - 1][n - 1] + ret[k][n - 1]) % MOD;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\n\t}\n\n\tstatic class MyScanner {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tokenizer;\n\n\t\tpublic MyScanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\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(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "//make sure to make new file!\nimport java.io.*;\nimport java.util.*;\n\npublic class EG14{\n\n   public static long MOD;\n   public static int MAX = 405;\n   \n   public static long[] fac;\n   public static long[] ifac;\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      MOD = Long.parseLong(st.nextToken());\n      \n      long[] pow2 = new long[MAX];\n      pow2[0] = 1L;\n      for(int k = 1; k < MAX; k++){\n         pow2[k] = (2L*pow2[k-1] + MOD)%MOD;\n      }\n      \n      fac = new long[MAX];\n      ifac = new long[MAX];\n      fac[0] = 1L;\n      ifac[0] = 1L;\n      for(int k = 1; k < MAX; k++){\n         fac[k] = ((long)k*fac[k-1] + MOD)%MOD;\n         ifac[k] = modInverse(fac[k],MOD);\n      }\n      \n      long[][] dp = new long[n][n+1];                 //what n you're on, what how many computers you've turned on manually\n      \n      //initial\n      for(int k = 0; k < n; k++){\n         dp[k][k+1] = pow2[k];\n      }\n      \n      for(int k = 2; k < n; k++){\n         for(int j = 1; j <= n; j++){\n            if(dp[k-2][j-1] == 0) continue;\n            long start = dp[k-2][j-1];                //number for part up to previous block\n            \n            for(int add = 1; ; add++){\n               if(k+add-1 >= n || j+add-1 > n) break;\n               \n               long adder = (start * pow2[add-1] + MOD)%MOD;\n               adder = (adder * choose(j+add-1,j-1) + MOD)%MOD;\n               dp[k+add-1][j+add-1] = (dp[k+add-1][j+add-1] + adder + MOD)%MOD;\n            }\n         }\n      }\n      \n      long answer = 0L;\n      for(int k = 1; k <= n; k++){\n         answer = (answer + dp[n-1][k] + MOD)%MOD;\n      }\n      out.println(answer);\n      \n      \n      \n      \n      \n      \n      \n      \n      out.close();\n   }\n   \n   //a choose b\n   public static long choose(int a, int b){\n      long prod = (fac[a]*ifac[b] + MOD)%MOD;\n      return (prod*ifac[a-b] + MOD)%MOD;\n   }\n   \n      //from geeksforgeeks\n   public static long modInverse(long a, long m) \n   { \n       long m0 = m; \n       long y = 0L;\n       long x = 1L; \n     \n       if (m == 1L) \n         return 0L; \n     \n       while (a > 1L) \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;\n           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 < 0L) \n          x += m0; \n     \n       return x; \n   } \n      \n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.List;\n import java.util.*;\n public class realfast implements Runnable \n  {\n    private static final int INF = (int) 1e9;\n    long in= 1000000007;\n    long fac[]= new long[1000001];\n    long inv[]=new long[1000001];\n    public  void solve() throws IOException \n    {\n\n        //int t = readInt();\n\n        int n = readInt();\n\n        long m  = readInt();\n\n        long method[][]=new long [n+1][n+1];\n\n        for(int i=0;i<=n;i++)\n        {\n            method[0][i]=1;\n            method[i][0]=1;\n        }\n\n        for(int i=1;i<=n;i++)\n        {\n            for(int j=1;j<=n;j++)\n            {\n                 for(int k=i;k>=0;k--)\n                 {\n                      method[i][j]= (method[i][j]%m+method[k][j-1]%m)%m;\n                 }\n            }\n        }\n         // index , total , cont\n        //long dp[][][]=new  long[n+2][n+2][n+2];\n        long sum[][]=new long[n+2][n+2];\n        sum[0][0]=1;\n      //  dp[0][0][0]=1;\n\n        long len[][]=new long[n+1][n+1];\n        for(int i=0;i<=n;i++)\n        {\n            len[i][0]=1;\n            len[0][i]=1;\n        }\n\n        for(int i=2;i<=n;i++)\n        {\n            for(int j=1;j<i;j++)\n            {\n                 len[j][i-j]= (len[j-1][i-j]%m+len[j][i-j-1]%m)%m;\n            }\n        }\n\n        long gal[]=new long[2*n+1];\n\n        for(int i=0;i<=n;i++)\n        {\n            for(int j=0;j<=n;j++)\n            {\n                gal[i+j]= (gal[i+j]+ len[i][j])%m; \n            }\n        }\n\n\n\n\n\n        for(int i=1;i<=n;i++)\n        {\n            if(i==n-1)\n                continue;\n            for(int j=1;j<=i;j++)\n            {\n                    \n                   for(int k=1;k<=j;k++)\n                   {\n                          \n                          \n                              long val =sum[i-k][j-k];\n                              val = (val*method[j-k][k])%m;\n                            \n                              val =(val*gal[k-1])%m;\n                              sum[i+1][j]= (sum[i+1][j]+val)%m;\n                          \n\n                   }\n            }\n        }\n\n        long ans =0;\n\n        for(int i=1;i<=n;i++)\n        {\n            ans = (ans + sum[n+1][i])%m;\n\n        }\n\n        out.println(ans);\n\n\n\n\n       \n\n    }\n    \n    public int value (int seg[], int left , int right ,int index, int l, int r)\n    {\n            \n            if(left>right)\n            {\n              return -100000000;\n            }\n            if(right<l||left>r)\n                return -100000000;\n            if(left>=l&&right<=r)\n                return seg[index];\n            int mid = left+(right-left)/2;\n            int val = value(seg,left,mid,2*index+1,l,r);\n            int val2 = value(seg,mid+1,right,2*index+2,l,r);\n            return Math.max(val,val2);\n\n    }\n   \n    public int gcd(int a , int b )\n    {\n      if(a<b)\n      {\n        int t =a;\n        a=b;\n        b=t;\n      }\n      if(a%b==0)\n        return b ;\n      return gcd(b,a%b);\n    }\n    public long pow(long n , long p,long m)\n    {\n         if(p==0)\n            return 1;\n        long val = pow(n,p/2,m);;\n        val= (val*val)%m;\n        if(p%2==0)\n            return val;\n        else\n            return (val*n)%m;\n    }\n    \n    \n    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    public static void main(String[] args) {\n        new Thread(null, new realfast(), \"\", 128 * (1L << 20)).start();\n    }\n \n    private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n    private PrintWriter out;\n \n    @Override\n    public void run() {\n        try {\n            if (ONLINE_JUDGE || !new File(\"input.txt\").exists()) {\n                reader = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(System.out);\n            } else {\n                reader = new BufferedReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(\"output.txt\");\n            }\n            solve();\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        } finally {\n            try {\n                reader.close();\n            } catch (IOException e) {\n                // nothing\n            }\n            out.close();\n        }\n    }\n \n    private String readString() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n \n    @SuppressWarnings(\"unused\")\n    private int readInt() throws IOException {\n        return Integer.parseInt(readString());\n    }\n \n    @SuppressWarnings(\"unused\")\n    private long readLong() throws IOException {\n        return Long.parseLong(readString());\n    }\n \n    @SuppressWarnings(\"unused\")\n    private double readDouble() throws IOException {\n        return Double.parseDouble(readString());\n    }\n}\nclass edge implements Comparable<edge>{\n    int u ;\n    int v;\n    \n    edge(int u, int v)\n    {\n       this.u=u;\n       this.v=v;\n    }\n    public int compareTo(edge e)\n    {\n        return this.v-e.v;\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\npublic class Main {\n\n    public static final DecimalFormat DF_3 = new DecimalFormat(\"0.000\");\n    private static final long MOD = 1000000007;\n\n\n    static int[] readArray(int size, InputReader in, boolean subOne) {\n        int[] a = new int[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = in.nextInt() + (subOne ? -1 : 0);\n        }\n        return a;\n    }\n\n    static long[] readLongArray(int size, InputReader in) {\n        long[] a = new long[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = in.nextLong();\n        }\n        return a;\n    }\n\n    static void sortArray(int[] a) {\n        Random random = new Random();\n\n        for (int i = 0; i < a.length; i++) {\n            int randomPos = random.nextInt(a.length);\n            int t = a[i];\n            a[i] = a[randomPos];\n            a[randomPos] = t;\n        }\n        Arrays.sort(a);\n    }\n\n    private static long[] allInvs(int n, long mod) {\n        long[] inv = new long[n + 1];\n        inv[1] = 1;\n        for (int i = 2; i <= n; ++i) {\n            inv[i] = subMod(mod, (mod / i) * inv[(int) (mod % i)] % mod, mod);\n        }\n        return inv;\n\n    }\n\n    private static long subMod(long x, long y, long mod) {\n        long res = x - y;\n        if (res < 0) {\n            return res + mod;\n        }\n        return res;\n    }\n\n    private static long fastPow(long x, long y, long mod) {\n        if (x == 1) {\n            return 1;\n        }\n        if (y == 0) {\n            return 1;\n        }\n        long p = fastPow(x, y / 2, mod) % mod;\n        p = p * p % mod;\n        if (y % 2 == 1) {\n            p = p * x % mod;\n        }\n        return p;\n    }\n\n    public static void main(String[] args) throws FileNotFoundException {\n//        InputReader in = new InputReader(new FileInputStream(\"input.txt\"));\n//        PrintWriter out = new PrintWriter(new BufferedOutputStream(new FileOutputStream(\"milkvisits.out\")));\n//\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n//        long start = System.currentTimeMillis();\n        int n = in.nextInt();\n        long mod = in.nextLong();\n        long[] invs = allInvs(n + 3, mod);\n        long[] facts = new long[n + 2];\n        facts[0] = 1;\n        long[] invFacts = new long[n + 2];\n        invFacts[0] = 1;\n        for (int i = 1; i < n + 2; i++) {\n            facts[i] = (facts[i - 1] * i) % mod;\n            invFacts[i] = (invFacts[i - 1] * invs[i]) % mod;\n        }\n        long[] pow2 = new long[n+3];\n        pow2[0] = 1;\n        for (int i = 1; i < n+3; i++) {\n            pow2[i] = pow2[i-1] * 2 % mod;\n        }\n\n        long[][] dp = new long[n + 2][n + 2];\n        for (int i = 2; i <= n + 1; i++) {\n            dp[i][1] = invFacts[i - 1] * pow2[i - 2] % mod;\n            for (int k = 2; k <= n; k++) {\n                for (int j = i - 2; j >= 1; j--) {\n                    dp[i][k] = (dp[i][k] + dp[j][k - 1] * pow2[ i - j - 2] % mod * invFacts[i - j - 1] % mod) % mod;\n                }\n            }\n        }\n\n        long ans = 0;\n        for (int k = 1; k <= n; k++) {\n\n            ans = (ans + dp[n + 1][k] * facts[n - k + 1] % mod) % mod;\n        }\n        out.println(ans);\n\n        out.close();\n    }\n\n    private static void outputArray(List<Long> ans, PrintWriter out, boolean addOne) {\n        StringBuilder str = new StringBuilder();\n        for (int j = 0; j < ans.size(); j++) {\n            long i = ans.get(j);\n            long an = i + (addOne ? 1 : 0);\n            str.append(an);\n            if (j < ans.size() - 1) {\n                str.append(' ');\n            }\n        }\n        out.println(str);\n//        out.flush();\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 double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public char nextChar() {\n            return next().charAt(0);\n        }\n\n        public String nextWord() {\n            return next();\n        }\n\n        private List<Integer>[] readTree(int n) {\n            return readGraph(n, n - 1);\n        }\n\n        private List<Integer>[] readGraph(int n, int m) {\n            List<Integer>[] result = new ArrayList[n];\n            for (int i = 0; i < n; i++) {\n                result[i] = new ArrayList<>();\n            }\n            for (int i = 0; i < m; i++) {\n                int u = nextInt() - 1;\n                int v = nextInt() - 1;\n                result[u].add(v);\n                result[v].add(u);\n            }\n            return result;\n        }\n\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static BufferedReader reader;\n    static StringTokenizer st;\n    private static void setReader() {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n    }\n    private static void updateST() throws IOException {\n        if (st==null || !st.hasMoreElements()) st = new StringTokenizer(reader.readLine());\n    }\n    private static int nextInt() throws IOException {\n        updateST();\n        return Integer.parseInt(st.nextToken());\n    }\n\n    public static void main(String[] args) throws IOException {\n        setReader();\n        int n = nextInt(), MOD = nextInt();\n        long[] pow = new long[n+2];\n        pow[0] = 1;\n        for (int i=1; i<=n+1; i++) pow[i] = (pow[i-1] * 2) % MOD;\n        long[][] C = new long[n+2][n+2];\n        for (int i=0; i<=n+1; 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        long[][] dp = new long[n+2][n+1];\n        dp[0][0] = 1;\n        for (int i=0; i<=n; i++) {\n            for (int j=0; j<=i; j++) {\n                for (int k=1; i + k + 1 <= n + 1; k++) {\n                    dp[i + k + 1][j + k]+=(((dp[i][j] * C[j + k][k]) % MOD * pow[k-1]) % MOD);\n                    dp[i + k + 1][j + k]%=MOD;\n                }\n            }\n        }\n        long res = 0;\n        for (int i=0; i<=n; i++) res = (res + dp[n+1][i]) % MOD;\n        System.out.println(res);\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class phoenix_and_computers {\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tString[] st = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(st[0]);\n\t\tint m = Integer.parseInt(st[1]);\n\n\t\tlong[][] ncr = ncrcoll(405, 405, m);\n\t\tint[] p2 = new int[n + 1];\n\t\tp2[0] = 1;\n\t\tfor (int i = 1; i < p2.length; i++) {\n\t\t\tp2[i] = 2 * p2[i - 1] % m;\n\t\t}\n\n\t\tlong[][] dp = new long[405][405];\n\t\tdp[0][0] = 1;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= i; j++) {\n\t\t\t\tfor (int k = 1; i + k <= n; k++) {\n\t\t\t\t\tdp[i + k + 1][j + k] += ((dp[i][j] * p2[k - 1]) % m * ncr[j + k][k]);\n\t\t\t\t\tdp[i + k + 1][j + k] %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tans = (ans + dp[n + 1][i]) % m;\n\t\t}\n\n\t\tSystem.out.println(ans);\n\t}\n\n\tstatic long[][] ncrcoll(int n, int k, int p) {\n\t\tlong[][] arr = new long[n + 1][k + 1];\n\t\tfor (int i = 1; i < arr.length; i++) {\n\t\t\tarr[i][0] = 1;\n\t\t}\n\t\tfor (int i = 1; i < arr.length; i++) {\n\t\t\tfor (int j = 1; j <= i && j < arr[0].length; j++) {\n\t\t\t\tif (i == 1 && j == 1) {\n\t\t\t\t\tarr[i][j] = 1;\n\t\t\t\t} else {\n\t\t\t\t\tarr[i][j] = (arr[i - 1][j] + arr[i - 1][j - 1]) % (p);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\n\tpublic static long xpown(long x, long n) {\n\t\tlong res = 1;\n\t\twhile (n > 0) {\n\t\t\tif (n % 2 != 0) {\n\t\t\t\tres = (res * x) % 1000000007;\n\t\t\t\tn--;\n\t\t\t} else {\n\t\t\t\tx = (x * x) % 1000000007;\n\t\t\t\tn = n / 2;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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.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            EPhoenixAndComputers solver = new EPhoenixAndComputers();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class EPhoenixAndComputers {\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.ri();\n            int mod = in.ri();\n            CachedPow2 cp = new CachedPow2(2, mod, n + 1, mod - 1);\n            Combination comb = new Combination(n + 1, mod);\n            long[][][] dp = new long[n + 1][n + 1][2];\n            dp[0][0][0] = 1;\n            for (int i = 1; i <= n; i++) {\n                for (int j = 0; j <= n; j++) {\n                    dp[i][j][0] = dp[i - 1][j][1];\n                    for (int k = 0; k < i; k++) {\n                        int len = i - k;\n                        int last = j - len;\n                        if (last >= 0) {\n                            dp[i][j][1] += dp[k][last][0] * cp.pow(len - 1) % mod * comb.combination(j, len) % mod;\n                        }\n                    }\n                    dp[i][j][1] %= mod;\n                }\n            }\n\n            long ans = 0;\n            for (int i = 0; i <= n; i++) {\n                ans += dp[n][i][1];\n            }\n\n            ans %= mod;\n            out.println(ans);\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(long 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('\\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    static interface IntegerEntryIterator {\n        boolean hasNext();\n\n        void next();\n\n        int getEntryKey();\n\n        int getEntryValue();\n\n    }\n\n    static class FastInput {\n        private final InputStream is;\n        private byte[] buf = new byte[1 << 13];\n        private int bufLen;\n        private int bufOffset;\n        private int next;\n\n        public FastInput(InputStream is) {\n            this.is = is;\n        }\n\n        private int read() {\n            while (bufLen == bufOffset) {\n                bufOffset = 0;\n                try {\n                    bufLen = is.read(buf);\n                } catch (IOException e) {\n                    bufLen = -1;\n                }\n                if (bufLen == -1) {\n                    return -1;\n                }\n            }\n            return buf[bufOffset++];\n        }\n\n        public void skipBlank() {\n            while (next >= 0 && next <= 32) {\n                next = read();\n            }\n        }\n\n        public int ri() {\n            return readInt();\n        }\n\n        public int readInt() {\n            boolean rev = false;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                rev = next == '-';\n                next = read();\n            }\n\n            int val = 0;\n            while (next >= '0' && next <= '9') {\n                val = val * 10 - next + '0';\n                next = read();\n            }\n\n            return rev ? val : -val;\n        }\n\n    }\n\n    static class Hasher {\n        private long time = System.nanoTime() + System.currentTimeMillis() * 31L;\n\n        public int shuffle(long z) {\n            z += time;\n            z = (z ^ (z >>> 33)) * 0x62a9d9ed799705f5L;\n            return (int) (((z ^ (z >>> 28)) * 0xcb24d0a5c88c35b3L) >>> 32);\n        }\n\n        public int hash(int x) {\n            return shuffle(x);\n        }\n\n    }\n\n    static class CachedEulerFunction {\n        private static int boundary = 1 << 16;\n        private static int[] euler = MultiplicativeFunctionSieve.getInstance(boundary).getEuler();\n        private static IntegerHashMap map = new IntegerHashMap(64, true);\n\n        public static int get(int x) {\n            return get(x, 2);\n        }\n\n        private static int get(int x, int begin) {\n            if (x <= boundary) {\n                return euler[x];\n            }\n            int ans = map.getOrDefault(x, -1);\n            if (ans == -1) {\n                int factor = findPrimeFactor(x, begin);\n                int y = x;\n                int exp = 1;\n                while (y % factor == 0) {\n                    y /= factor;\n                    exp *= factor;\n                }\n                ans = get(y, factor + 1) * (exp - exp / factor);\n                //ans = calc(x);\n                map.put(x, ans);\n            }\n            return ans;\n        }\n\n        private static int findPrimeFactor(int x, int begin) {\n            for (int i = Math.max(2, begin); i * i <= x; i++) {\n                if (x % i == 0) {\n                    return i;\n                }\n            }\n            return x;\n        }\n\n    }\n\n    static interface IntCombination {\n    }\n\n    static class MultiplicativeFunctionSieve {\n        static MultiplicativeFunctionSieve instance = new MultiplicativeFunctionSieve(1 << 16);\n        public int[] primes;\n        public boolean[] isComp;\n        public int primeLength;\n        public int[] smallestPrimeFactor;\n        public int[] expOfSmallestPrimeFactor;\n        int limit;\n\n        public static MultiplicativeFunctionSieve getInstance(int n) {\n            if (n <= (1 << 16)) {\n                return instance;\n            }\n            return new MultiplicativeFunctionSieve(n);\n        }\n\n        public int[] getEuler() {\n            int[] 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 (expOfSmallestPrimeFactor[i] == i) {\n                        euler[i] = i - i / smallestPrimeFactor[i];\n                    } else {\n                        euler[i] = euler[expOfSmallestPrimeFactor[i]] * euler[i / expOfSmallestPrimeFactor[i]];\n                    }\n                }\n            }\n            return euler;\n        }\n\n        public MultiplicativeFunctionSieve(int limit) {\n            this.limit = limit;\n            isComp = new boolean[limit + 1];\n            primes = new int[limit + 1];\n            expOfSmallestPrimeFactor = 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                    expOfSmallestPrimeFactor[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                    expOfSmallestPrimeFactor[pi] = smallestPrimeFactor[i] == primes[j]\n                            ? (expOfSmallestPrimeFactor[i] * expOfSmallestPrimeFactor[primes[j]])\n                            : expOfSmallestPrimeFactor[primes[j]];\n                    isComp[pi] = true;\n                    if (i % primes[j] == 0) {\n                        break;\n                    }\n                }\n            }\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            if (n - 1 >= 0) {\n                inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();\n            }\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[Math.min(limit + 1, mod)], new int[Math.min(limit + 1, mod)], mod);\n        }\n\n        public int fact(int n) {\n            if (n >= mod) {\n                return 0;\n            }\n            return fact[n];\n        }\n\n        public int invFact(int n) {\n            if (n >= mod) {\n                throw new IllegalArgumentException();\n            }\n            return inv[n];\n        }\n\n    }\n\n    static class CachedPow2 {\n        private int[] first;\n        private int[] second;\n        private int mod;\n        private int low;\n        private int mask;\n        private int phi;\n        private int xphi;\n\n        public CachedPow2(int x, int mod) {\n            this(x, mod, CachedEulerFunction.get(mod));\n        }\n\n        public CachedPow2(int x, int mod, int phi) {\n            this(x, mod, mod, phi);\n        }\n\n        public CachedPow2(int x, int mod, int limit, int phi) {\n            this.phi = phi;\n            limit = Math.min(limit, mod);\n            this.mod = mod;\n            int log = Log2.ceilLog(limit + 1);\n            low = (log + 1) / 2;\n            mask = (1 << low) - 1;\n            first = new int[1 << low];\n            second = new int[1 << log - low];\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            xphi = DigitUtils.modPow(x, phi, mod);\n        }\n\n        public int pow(int exp) {\n            return (int) ((long) first[exp & mask] * second[exp >> low] % mod);\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        public static int modPow(int x, long n, int m) {\n            if (n == 0) {\n                return DigitUtils.mod(1, m);\n            }\n            int ans = modPow(x, n / 2, m);\n            ans = DigitUtils.mod((long) ans * ans, m);\n            if (n % 2 == 1) {\n                ans = DigitUtils.mod((long) ans * x, m);\n            }\n            return 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 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 IntegerHashMap {\n        private int now;\n        private int[] slot;\n        private int[] version;\n        private int[] next;\n        private int[] keys;\n        private int[] values;\n        private int alloc;\n        private boolean[] removed;\n        private int mask;\n        private int size;\n        private boolean rehash;\n        private Hasher hasher = new Hasher();\n\n        public IntegerHashMap(int cap, boolean rehash) {\n            now = 1;\n            this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;\n            slot = new int[mask + 1];\n            version = new int[slot.length];\n            next = new int[cap + 1];\n            keys = new int[cap + 1];\n            values = new int[cap + 1];\n            removed = new boolean[cap + 1];\n            this.rehash = rehash;\n        }\n\n        private void doubleCapacity() {\n            int newSize = Math.max(next.length + 10, next.length * 2);\n            next = Arrays.copyOf(next, newSize);\n            keys = Arrays.copyOf(keys, newSize);\n            values = Arrays.copyOf(values, newSize);\n            removed = Arrays.copyOf(removed, newSize);\n        }\n\n        public void alloc() {\n            alloc++;\n            if (alloc >= next.length) {\n                doubleCapacity();\n            }\n            next[alloc] = 0;\n            removed[alloc] = false;\n            size++;\n        }\n\n        private void rehash() {\n            int[] newSlots = new int[Math.max(16, slot.length * 2)];\n            int[] newVersions = new int[newSlots.length];\n            int newMask = newSlots.length - 1;\n            for (int i = 0; i < slot.length; i++) {\n                access(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.version = newVersions;\n            now = 0;\n            this.mask = newMask;\n        }\n\n        private int hash(int x) {\n            return hasher.hash(x);\n        }\n\n        public void put(int x, int y) {\n            put(x, y, true);\n        }\n\n        public void put(int x, int y, boolean cover) {\n            int h = hash(x);\n            int s = h & mask;\n            access(s);\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 int getOrDefault(int x, int def) {\n            int h = hash(x);\n            int s = h & mask;\n            access(s);\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        private int findIndexOrLastEntry(int s, int x) {\n            int iter = slot[s];\n            while (keys[iter] != x) {\n                if (next[iter] != 0) {\n                    iter = next[iter];\n                } else {\n                    return iter;\n                }\n            }\n            return iter;\n        }\n\n        private void access(int i) {\n            if (version[i] != now) {\n                version[i] = now;\n                slot[i] = 0;\n            }\n        }\n\n        public IntegerEntryIterator iterator() {\n            return new IntegerEntryIterator() {\n                int index = 1;\n                int readIndex = -1;\n\n\n                public boolean hasNext() {\n                    while (index <= alloc && removed[index]) {\n                        index++;\n                    }\n                    return index <= alloc;\n                }\n\n\n                public int getEntryKey() {\n                    return keys[readIndex];\n                }\n\n\n                public int getEntryValue() {\n                    return values[readIndex];\n                }\n\n\n                public void next() {\n                    if (!hasNext()) {\n                        throw new IllegalStateException();\n                    }\n                    readIndex = index;\n                    index++;\n                }\n            };\n        }\n\n        public String toString() {\n            IntegerEntryIterator iterator = iterator();\n            StringBuilder builder = new StringBuilder(\"{\");\n            while (iterator.hasNext()) {\n                iterator.next();\n                builder.append(iterator.getEntryKey()).append(\"->\").append(iterator.getEntryValue()).append(',');\n            }\n            if (builder.charAt(builder.length() - 1) == ',') {\n                builder.setLength(builder.length() - 1);\n            }\n            builder.append('}');\n            return builder.toString();\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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\n\npublic class Main{\n\n    static long MOD = 1_000_000_007L;\n    //static long MOD = 998_244_353L;\n    //static long MOD = 1_000_000_033L;\n    static long inv2 = (MOD + 1) / 2;\n\n    static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n    static long lMax = 0x3f3f3f3f3f3f3f3fL;\n    static int iMax = 0x3f3f3f3f;\n    static HashMap <Long, Long> memo = new HashMap();\n    static MyScanner sc = new MyScanner();\n    //static ArrayList <Integer> primes;\n\n    static int nn = 300000;\n    static long[] pow2;\n    static long [] fac;\n    static long [] pow;\n    static long [] inv;\n    static long [] facInv;\n    static int[] base;\n    static int[] numOfDiffDiv;\n    static int[] numOfDiv;\n    static ArrayList <Integer> primes;\n    //static int[] primes;\n    static int ptr = 0;\n    static boolean[] isPrime;\n\n    //-----------PrintWriter for faster output---------------------------------\n    public static PrintWriter out;\n    public static void main(String[] args) {\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n        // Start writing your solution here. -------------------------------------\n\n\n\n        /*fac = new long[nn + 1];\n        fac[1] = 1;\n        for(int i = 2; i <= nn; i++)\n            fac[i] = fac[i - 1] * i % MOD;*/\n\n\n        /*pow2 = new long[nn + 1];\n        pow2[0] = 1L;\n        for(int i = 1; i <= nn; i++)\n            pow2[i] = pow2[i - 1] * 2L;*/\n\n\n        /*inv = new long[nn + 1];\n        inv[1] = 1;\n        for (int i = 2; i <= nn; ++i)\n            inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/\n\n        /*facInv = new long[nn + 1];\n        facInv[0] = facInv[1] = 1;\n        for (int i = 2; i <= nn; ++i)\n            facInv[i] = facInv[i - 1] * inv[i] % MOD;*/\n\n\n        /*numOfDiffDiv = new int[nn + 1];\n        for(int i = 2; i <= nn; i++)\n            if(numOfDiffDiv[i] == 0)\n                for(int j = i; j <= nn; j += i)\n                    numOfDiv[j] ++;*/\n\n        /*numOfDiv = new int[nn + 1];\n        numOfDiv[1] = 1;\n        for(int i = 2; i <= nn; i++) {\n            for(int j = 2; j * j <= i; j++) {\n                if(i % j == 0) {\n                    numOfDiv[i] = numOfDiv[i / j] + 1;\n                    break;\n                }\n            }\n        }*/\n\n        //primes = sieveOfEratosthenes(100001);\n\n        /*\n        int t = 1;\n        //t = sc.ni();\n        while(t-- > 0) {\n            //boolean res = solve();\n            //out.println(res ? \"YES\" : \"NO\");\n            long res = solve();\n            out.println(res);\n        }*/\n\n\n        int t = 1, tt = 0;\n        //t = sc.ni();\n        for(int i = 1; i <40000; i++) squares.add(i * i);\n        while(tt++ < t) {\n            boolean res = solve();\n            //out.println(\"Case #\" + tt + \": \" + res);\n            //out.println(res ? \"YES\" : \"NO\");\n        }\n        out.close();\n    }\n    static HashSet <Integer> squares = new HashSet();\n\n    static boolean solve() {\n        /*String s = sc.nextLine();\n        char[] c = s.toCharArray();\n        int n = c.length;*/\n        //int n = sc.ni();\n        //long[] a =  new long[n];\n        //for(int i = 0; i < n; i++) a[i] = sc.nl();\n        long res = 0;\n        int n = sc.ni();\n        long m = sc.nl();\n        long[][][] dp = new long[2][5][5];\n        long[][][] dp2 = new long[2][5][5];\n        dp[0][2][1] = dp[1][2][2] = dp2[0][1][1] = 1L;\n        for(int i = 3; i <= n; i++) {\n            long[][] bef = dp[0];\n            long[][] aft = dp[1];\n            long[][] nbef = new long[i + 3][i + 3];\n            long[][] naft = new long[i + 3][i + 3];\n            for(int len = 1; len <= i; len++) {\n                for(int ind = 1; ind <= len; ind++) {\n                    nbef[len + 1][1] += bef[len][ind];\n                    nbef[len + 1][ind + 1] -= bef[len][ind];\n                    naft[len + 1][ind + 1] += bef[len][ind];\n                    //naft[len + 1][len + 2] -= bef[len][ind];\n                    naft[len + 1][ind + 1] += aft[len][ind];\n                    //naft[len + 1][len + 2] -= aft[len][ind];\n                    nbef[len + 1][1] += dp2[0][len][ind] + dp2[1][len][ind];\n                    //nbef[len + 1][len + 2] -= dp2[0][len][ind] + dp2[1][len][ind];\n                }\n            }\n            for(int len = 1; len <= i; len++) {\n                for(int ind = 1; ind <= len; ind ++) {\n                    nbef[len][ind] = (nbef[len][ind] + nbef[len][ind - 1] + 10000000L * m) % m;\n                    naft[len][ind] = (naft[len][ind] + naft[len][ind - 1] + 10000000L * m) % m;\n                }\n            }\n            dp2 = dp;\n            dp = new long[][][]{nbef, naft};\n        }\n        for(long[] row: dp[0])\n            for(long i : row)\n                res += i;\n        for(long[] row: dp[1])\n            for(long i : row)\n                res += i;\n            out.println(res % m);\n        return false;\n    }\n\n    // edges to adjacency list by uwi\n    public static int[][] packU(int n, int[] from, int[] to) {\n        return packU(n, from, to, from.length);\n    }\n\n    public static int[][] packU(int n, int[] from, int[] to, int sup) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int i = 0; i < sup; i++) p[from[i]]++;\n        for (int i = 0; i < sup; i++) p[to[i]]++;\n        for (int i = 0; i < n; i++) g[i] = new int[p[i]];\n        for (int i = 0; i < sup; i++) {\n            g[from[i]][--p[from[i]]] = to[i];\n            g[to[i]][--p[to[i]]] = from[i];\n        }\n        return g;\n    }\n\n    // tree diameter by uwi\n    public static int[] diameter(int[][] g) {\n        int n = g.length;\n        int f0 = -1, f1 = -1, d01 = -1;\n        int[] q = new int[n];\n        boolean[] ved = new boolean[n];\n        {\n            int qp = 0;\n            q[qp++] = 0; ved[0] = true;\n            for(int i = 0;i < qp;i++){\n                int cur = q[i];\n                for(int e : g[cur]){\n                    if(!ved[e]){\n                        ved[e] = true;\n                        q[qp++] = e;\n                        continue;\n                    }\n                }\n            }\n            f0 = q[n-1];\n        }\n        {\n            int[] d = new int[n];\n            int qp = 0;\n            Arrays.fill(ved, false);\n            q[qp++] = f0; ved[f0] = true;\n            for(int i = 0;i < qp;i++){\n                int cur = q[i];\n                for(int e : g[cur]){\n                    if(!ved[e]){\n                        ved[e] = true;\n                        q[qp++] = e;\n                        d[e] = d[cur] + 1;\n                        continue;\n                    }\n                }\n            }\n            f1 = q[n-1];\n            d01 = d[f1];\n        }\n        return new int[]{d01, f0, f1};\n    }\n\n    public static long c(int n, int k) {\n        return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;\n    }\n\n\n    // SegmentTree range min/max query by uwi\n    public static class SegmentTreeRMQ {\n        public int M, H, N;\n        public int[] st;\n\n        public SegmentTreeRMQ(int n)\n        {\n            N = n;\n            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n            H = M>>>1;\n            st = new int[M];\n            Arrays.fill(st, 0, M, Integer.MAX_VALUE);\n        }\n\n        public SegmentTreeRMQ(int[] a)\n        {\n            N = a.length;\n            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n            H = M>>>1;\n            st = new int[M];\n            for(int i = 0;i < N;i++){\n                st[H+i] = a[i];\n            }\n            Arrays.fill(st, H+N, M, Integer.MAX_VALUE);\n            for(int i = H-1;i >= 1;i--)propagate(i);\n        }\n\n        public void update(int pos, int x)\n        {\n            st[H+pos] = x;\n            for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);\n        }\n\n        private void propagate(int i)\n        {\n            st[i] = Math.min(st[2*i], st[2*i+1]);\n        }\n\n        public int minx(int l, int r){\n            int min = Integer.MAX_VALUE;\n            if(l >= r)return min;\n            while(l != 0){\n                int f = l&-l;\n                if(l+f > r)break;\n                int v = st[(H+l)/f];\n                if(v < min)min = v;\n                l += f;\n            }\n\n            while(l < r){\n                int f = r&-r;\n                int v = st[(H+r)/f-1];\n                if(v < min)min = v;\n                r -= f;\n            }\n            return min;\n        }\n\n        public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}\n\n        private int min(int l, int r, int cl, int cr, int cur)\n        {\n            if(l <= cl && cr <= r){\n                return st[cur];\n            }else{\n                int mid = cl+cr>>>1;\n                int ret = Integer.MAX_VALUE;\n                if(cl < r && l < mid){\n                    ret = Math.min(ret, min(l, r, cl, mid, 2*cur));\n                }\n                if(mid < r && l < cr){\n                    ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));\n                }\n                return ret;\n            }\n        }\n    }\n\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;}\n\n    public static double dist(double a, double b){\n        return Math.sqrt(a * a + b * b);\n    }\n\n    public static long inv(long a){\n        return quickPOW(a, MOD - 2);\n    }\n\n    public class Interval {\n        int start;\n        int end;\n        public Interval(int start, int end) {\n            this.start = start;\n            this.end = end;\n        }\n    }\n\n    public static ArrayList<Integer> sieveOfEratosthenes(int n) {\n        boolean prime[] = new boolean[n + 1];\n        Arrays.fill(prime, true);\n        for (int p = 2; p * p <= n; p++) {\n            if (prime[p]) {\n                for (int i = p * 2; i <= n; i += p) {\n                    prime[i] = false;\n                }\n            }\n        }\n        ArrayList<Integer> primeNumbers = new ArrayList<>();\n        for (int i = 2; i <= n; i++) {\n            if (prime[i]) {\n                primeNumbers.add(i);\n            }\n        }\n        return primeNumbers;\n    }\n\n\n    public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n    public static int lowerBound(int[] a, int l, int r, int v)\n    {\n        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n        int low = l-1, high = r;\n        while(high-low > 1){\n            int h = high+low>>>1;\n            if(a[h] >= v){\n                high = h;\n            }else{\n                low = h;\n            }\n        }\n        return high;\n    }\n    public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n    public static int rlowerBound(int[] a, int l, int r, int v)\n    {\n        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n        int low = l-1, high = r;\n        while(high-low > 1){\n            int h = high+low>>>1;\n            if(a[h] <= v){\n                high = h;\n            }else{\n                low = h;\n            }\n        }\n        return high;\n    }\n    public static long C(int n, int m)\n    {\n        if(m == 0 || m == n) return 1l;\n        if(m > n || m < 0) return 0l;\n        long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;\n\n        return res;\n    }\n    public static long quickPOW(long n, long m)\n    {\n        long ans = 1l;\n        while(m > 0)\n        {\n            if(m % 2 == 1)\n                ans = (ans * n) % MOD;\n            n = (n * n) % MOD;\n            m >>= 1;\n        }\n        return ans;\n    }\n    public static long quickPOW(long n, long m, long mod)\n    {\n        long ans = 1l;\n        while(m > 0)\n        {\n            if(m % 2 == 1)\n                ans = (ans * n) % mod;\n            n = (n * n) % mod;\n            m >>= 1;\n        }\n        return ans;\n    }\n\n    public static int gcd(int a, int b)\n    {\n        if(a % b == 0) return b;\n        return gcd(b, a % b);\n    }\n    public static long gcd(long a, long b)\n    {\n        if(a % b == 0) return b;\n        return gcd(b, a % b);\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 void shuffle(long[] data) {\n            shuffle(data, 0, data.length - 1);\n        }\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 RandomWrapper.INSTANCE.nextInt(l, r);\n        }\n    }\n\n    static class RandomWrapper {\n        private Random random;\n        public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());\n\n        public RandomWrapper() {\n            this(new Random());\n        }\n\n        public RandomWrapper(Random random) {\n            this.random = random;\n        }\n\n        public int nextInt(int l, int r) {\n            return random.nextInt(r - l + 1) + l;\n        }\n\n    }\n\n\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        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 ni() {\n            return Integer.parseInt(next());\n        }\n        long nl() {\n            return Long.parseLong(next());\n        }\n        double nd() {\n            return Double.parseDouble(next());\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}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.ObjectInputStream.GetField;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Global14 {\n\tstatic PrintWriter out;\n\tstatic Scanner sc;\n\tstatic ArrayList<int[]>q,w,x;\n\tstatic ArrayList<Integer>adj[];\n\tstatic HashSet<Integer>primesH;\n\tstatic boolean prime[];\n\t//static ArrayList<Integer>a;\n\tstatic HashSet<Long>tmp;\n\tstatic int[][][]dist;\n\tstatic boolean[]v;\n\tstatic int[]a,b,c,d;\n\tstatic Boolean[][]dp;\n\tstatic char[][]mp;\n\tstatic int A,B,n,m,h,ans,sum;\n\t//static String a,b;\n\tstatic long oo=(long)1e9+7;\n\tpublic static void main(String[]args) throws IOException {\n\t\tsc=new Scanner(System.in);\n\t\tout=new PrintWriter(System.out);\n\t\t//A();\n\t\t//B();\n\t\t//C();\n\t\t//D();\n\t\tE();\n\t\t//F();\n\t\t//G();\n\t\tout.close();\n\t}\n\t  private static void A() throws IOException {\n\t\t  int t=ni();\n\t\t  while(t-->0) {\n\t\t\t\tint n=ni(),w=ni();\n\t\t\t\ta=nai(n);\n\t\t\t\tint sum=0;\n\t\t\t\tfor(int i=0;i<n;i++)sum+=a[i];\n\t\t\t\tif(sum==w) {ol(\"NO\");continue;}\n\t\t\t\tif(sum<w) {\n\t\t\t\t\tol(\"YES\");\n\t\t\t\t\tdisp2(a);continue;\n\t\t\t\t}\n\t\t\t\tArrays.sort(a);\n\t\t\t\tint cur=0;\n\t\t\t\tfor(int i=n-1;i>=0;i--) {\n\t\t\t\t\tif(cur==w) {\n\t\t\t\t\t\tint tmp=a[i+1];\n\t\t\t\t\t\ta[i+1]=a[i];\n\t\t\t\t\t\ta[i]=tmp;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcur+=a[i];\n\t\t\t\t}\n\t\t\t\tol(\"YES\");\n\t\t\t\tdisp2(a);\n\t\t\t\t\n\t\t  }\n\t\t\n\t   }\n\t\tstatic void B() throws IOException {\n\t\t\tint t=ni();\n\t\t\twhile(t-->0) {\n\t\t\t\tlong n=nl();\n\t\t\t\tif(n%2==0) {\n\t\t\t\tn/=2;\n\t\t\t\tint sq=(int)Math.sqrt(n);\n\t\t\t\tif(sq*sq==n&&sq!=0) {\n\t\t\t\t\tol(\"YES\");continue;\n\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(n%2==0) {\n\t\t\t\tn/=2;\n\t\t\t\t int sq=(int)Math.sqrt(n);\n\t\t\t\tif(sq*sq==n&&sq!=0) {\n\t\t\t\t\tol(\"YES\");continue;\n\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tol(\"NO\");\n\t\t\t}\n\t\t\t}\n\t\t\n\t\t\n\t\tstatic void C() throws IOException{\n\t\t\t int t=ni();\n\t\t\t while(t-->0) {\n\t\t\t\tint n=ni(),m=ni(),x=ni();\n\t\t\t\tint[][]a=new int[n][2];\n\t\t\t\tint mx=0;\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\ta[i][0]=ni();\n\t\t\t\t\ta[i][1]=i;\n\t\t\t\t\tmx=Math.max(mx, a[i][0]);\n\t\t\t\t}\n\t\t\t\tArrays.sort(a,(u,v)->u[0]-v[0]);\n\t\t\t\tPriorityQueue<int[]>vals=new PriorityQueue<int[]>((u,v)->u[0]-v[0]);\n\t\t\t\tint[]ans=new int[n];\n\t\t\t\t//int grp=1;\n\t\t\t\tvals.add(new int[] {a[0][0],1});\n\t\t\t\tans[a[0][1]]=1;\n\t\t\t\tfor(int i=1;i<n;i++) {\n\t\t\t\t\tif(vals.size()<m) {\n\t\t\t\t\t\tans[a[i][1]]=vals.size()+1;\n\t\t\t\t\t\tvals.add(new int[] {a[i][0],vals.size()+1});\n\t\t\t\t\t\tmx=Math.max(mx, a[i][0]);\n\t\t\t\t\t}else {\n\t\t\t\t\t\tint[]p=vals.poll();\n\t\t\t\t\t\tvals.add(new int[] {p[0]+a[i][0],p[1]});\n\t\t\t\t\t\tans[a[i][1]]=p[1];\n\t\t\t\t\t\tmx=Math.max(mx, a[i][0]+p[0]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(mx-vals.peek()[0]>x)ol(\"NO\");\n\t\t\t\telse {\n\t\t\t\t\t\n\t\t\t\t\tol(\"YES\");\n\t\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\t\tout.print(ans[i]+\" \");\n\t\t\t\t\t}\n\t\t\t\t\tol(\"\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t }\n\t\t}\n\t\tprivate static Boolean dp(int i, int j) {\n\t\t\tif(j>sum/2)return false;\n\t\t\tif(i==x.size()) {\n\t\t\t\treturn sum/2==j;\n\t\t\t}\n\t\t\tif(dp[i][j]!=null)return dp[i][j];\n\t\t\t\n\t\t\treturn dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);\n\t\t}\n\t\tstatic boolean isPrime(long n) {\n\t\t\tif(n==2)return true;\n\t\t\tif(n<2||n%2==0)return false;\n\t\t\t\n\t\t\tfor(long i=3L;i*i<n;i+=2l) {\n\t\t\t\tlong rem=(n%i);\n\t\t\t\tif(rem==0)return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tstatic void D() throws IOException {\n\t\t\tint t=ni();\n\t\t\twhile(t-->0) {\n\t\t\t\tint n=ni(),l=ni(),r=ni();\n\t\t\t\tint[]occ1=new int[n+1];\n\t\t\t\ta=nai(n);\n\t\t\t\tfor(int i=0;i<l;i++) {\n\t\t\t\t\tocc1[a[i]]++;\n\t\t\t\t}\n\t\t\t\tint[]occ2=new int[n+1];\n\t\t\t\tfor(int i=l;i<n;i++) {\n\t\t\t\t\tocc2[a[i]]++;\n\t\t\t\t}\n\t\t\t\tint base=Math.abs((n/2)-l);\n\t\t\t\tint tk=0;\n\t\t\t\tint[]lrg=l>r?occ1:occ2;\n\t\t\t\tint[]sml=l<=r?occ1:occ2;\n\t\t\t\tfor(int i=0;i<=n&&tk<base;i++) {\n\t\t\t\t\tint rem=base-tk;\n\t\t\t\t\tint taken=Math.min(rem, \n\t\t\t\t\t\t\tMath.max(0,(lrg[i]-sml[i])/2));\n\t\t\t\t\tlrg[i]-=taken;\n\t\t\t\t\tsml[i]+=taken;\n\t\t\t\t\ttk+=taken;\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n&&tk<base;i++) {\n\t\t\t\t\tif(lrg[i]<=sml[i])continue;\n\t\t\t\t\tlrg[i]--;\n\t\t\t\t\tsml[i]++;\n\t\t\t\t\ttk++;\n\t\t\t\t}\n\t\t\t\tint c1=0,c2=0;\n\t\t\t\tfor(int i=0;i<=n;i++) {\n\t\t\t\t\tif(lrg[i]>sml[i]) {\n\t\t\t\t\t\tif(c1<0) {\n\t\t\t\t\t\t\tint diff=Math.min(-c1, -sml[i]+lrg[i]);\n\t\t\t\t\t\t\tlrg[i]-=diff;\n\t\t\t\t\t\t\tc1+=diff;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint nd=lrg[i]-sml[i];\n\t\t\t\t\t\tc2-=nd;\n\t\t\t\t\t\tbase+=nd;\n\t\t\t\t\t\tsml[i]=lrg[i];\n\t\t\t\t\t}else if(lrg[i]<sml[i]) {\n\t\t\t\t\t\tif(c2<0) {\n\t\t\t\t\t\t\tint diff=Math.min(-c2, sml[i]-lrg[i]);\n\t\t\t\t\t\t\tsml[i]-=diff;\n\t\t\t\t\t\t\tc2+=diff;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint nd=-lrg[i]+sml[i];\n\t\t\t\t\t\tbase+=nd;\n\t\t\t\t\t\tc1-=nd;\n\t\t\t\t\t\tlrg[i]=sml[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tol(base);\n\t\t\t}\n\t\t}\n\t\tprivate static int bfs(int i, int j,int k) {\n\t\t\tboolean [][]vis=new boolean[dist.length][dist[0].length];\n\t\t\tQueue<int[]>q=new LinkedList<int[]>();\n\t\t\tint mn=Integer.MAX_VALUE;\n\t\t\tq.add(new int[] {i,j,0,0});\n\t\t\tint[]dx=new int[] {-1,1,0,0};\n\t\t\tint[]dy=new int[] {0,0,1,-1};\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint []x=q.poll();\n\t\t\t\tvis[x[0]][x[1]]=true;\n\t\t\t\tint c=x[2];\n\t\t\t\tif(c>k/2)continue;\n\t\t\t\tif(c>0&&k%c==0&&(k/c)%2==0) {\n\t\t\t\t\tmn=Math.min(mn,x[3]*k/c );\n\t\t\t\t}\n\t\t\t\tfor(int a=0;a<4;a++) {\n\t\t\t\t\tint nx=x[0]+dx[a];\n\t\t\t\t\tint ny=x[1]+dy[a];\n\t\t\t\t\tif(valid(nx,ny)&&!vis[nx][ny]) {\n\t\t\t\t\t\tq.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\treturn mn;\n\t\t}\n\t\tprivate static boolean valid(int nx, int ny) {\n\t\t\treturn nx>=0&&nx<dist.length&&ny>=0&&ny<dist[0].length;\n\t\t}\n\t\tstatic int gcd (int a, int b) {\n\t\t    return b==0?a:gcd (b, a % b);\n\t\t}\n\t\t\n\tstatic void E() throws IOException {\n\t\tint t=1;\n\t\twhile(t-->0) {\n\t\t\tint n=ni();\n\t\t\tlong oo=nl();\n\t\t\tlong fc[]=new long[n+1];\n\t\t\tfc[0]=fc[1]=1l;\n\t\t\tlong []pow2=new long[n+1];\n\t\t\tpow2[0]=1l;\n\t\t\tfor(int i=1;i<pow2.length;i++) {\n\t\t\t\tpow2[i]=(pow2[i-1]*2l)%oo;\n\t\t\t}\n\t\t\tfor(int i=2;i<fc.length;i++) {\n\t\t\t\tfc[i]=(fc[i-1]*1l*i)%oo;\n\t\t\t}\n\t\t\t\n\t\t\tlong ncr[][]=new long[n+1][n+1];\n\t\t\tfor(int i=0;i<=n;i++) {\n\t\t\t\tfor(int j=0;j<=i;j++) {\n\t\t\t\t\tncr[i][j]=i==0||j==0?1l:(ncr[i-1][j-1]+ncr[i-1][j])%oo;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlong ans=0;\n\t\t\tlong dp[][]=new long[n+2][n+2];\n\t\t\tdp[0][0]=1l;\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tfor(int j=0;j<=i;j++) {\n\t\t\t\t\tfor(int k=1;i+k<=n;k++) {\n\t\t\t\t\t\tdp[i+k+1][j+k]+=((dp[i][j]*pow2[k-1]%oo)*ncr[j+k][k])%oo;\n\t\t\t\t\t\tdp[i+k+1][j+k]%=oo;\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\tans=(ans+dp[n+1][i])%oo;\n\t\t\t}\n\t\t\tol(\"\"+ans);\n\t\t\t//ol(\"\"+pow2[3]);\n\t\t}\n\t\t\n\t}\n\n\tstatic void F() throws IOException {\n\t\tint t=ni();\n\t\twhile(t-->0) {\n\t\t\t\n\t\t}\n\t}\n\tstatic void CC() throws IOException {\n\t\tfor(int kk=2;kk<21;kk++) {\n\t\t\tol(kk+\"   -------\");\n\t\tint n=kk;\n\t\tint k=n-2;\n\t\tint msk=1<<k;\n\t\tint[]a=new int[k];\n\t\tfor(int i=0;i<a.length;i++)a[i]=i+2;\n\t\tint mx=1;\n\t\tint ms=0;\n\t\tfor(int i=1;i<msk;i++) {\n\t\t\tlong prod=1;\n\t\t\tint cnt=0;\n\t\t\tfor(int j=0;j<a.length;j++) {\n\t\t\t\tif(((i>>j)&1)!=0) {\n\t\t\t\t\tprod*=a[j];\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(cnt>=mx&&prod%n==1) {\n\t\t\t\tmx=cnt;\n\t\t\t\tms=i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tol(mx==1?mx:mx+1);\n\t\tout.print(1+\" \");\n\t\tlong pr=1;\n\t\tfor(int j=0;j<a.length;j++) {\n\t\t\tif(((ms>>j)&1)!=0) {\n\t\t\t\tout.print(a[j]+\" \");\n\t\t\t\tpr*=a[j];\n\t\t\t}\n\t\t}\n\t\tol(\"\");\n\t\tol(\"Prod: \"+pr);\n\t\tol(n+\"*\"+((pr-1)/n)+\" + \"+1);\n\t\t}\n\t}\n\tstatic int ni() throws IOException {\n\t\treturn sc.nextInt();\n\t}\n\tstatic double nd() throws IOException {\n\t\treturn sc.nextDouble();\n\t}\n\tstatic long nl() throws IOException {\n\t\treturn  sc.nextLong();\n\t}\n\tstatic String ns() throws IOException {\n\t\treturn sc.next();\n\t}\n\tstatic int[] nai(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] = sc.nextInt();\n\t\treturn a;\n\t}\n\tstatic long[] nal(int n) throws IOException {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextLong();\n\t\treturn a;\n\t}\n\tstatic int[][] nmi(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]=sc.nextInt();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\n\tstatic long[][] nml(int n,int m) throws IOException{\n\t\tlong[][]a=new long[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]=sc.nextLong();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\tstatic void o(String x) {\n\t\tout.print(x);\n\t}\n\tstatic void ol(String x) {\n\t\tout.println(x);\n\t}\n\tstatic void ol(int x) {\n\t\tout.println(x);\n\t}\n\tstatic void disp1(int []a) {\n\t\tfor(int i=0;i<a.length;i++) {\n\t\t\tout.print(a[i]+\" \");\n\t\t}\n\t\tout.println();\n\t}\n\tstatic void disp2(int []a) {\n\t\tfor(int i=a.length-1;i>=0;i--) {\n\t\t\tout.print(a[i]+\" \");\n\t\t}\n\t\tout.println();\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\t\tpublic boolean hasNext() {return st.hasMoreTokens();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\t\n\t\tpublic double nextDouble() throws IOException {return Double.parseDouble(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\t\n\t\tpublic boolean ready() throws IOException {return br.ready(); }\n\t\t\n\n\t}\n}\n\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "/*\nbts songs to dance to:\nI need U\nRun\nON\nFilter\nI'm fine\n */\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.abs;\nimport static java.lang.System.out;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class x1515E\n{\n    static long MOD;\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        MOD = Long.parseLong(st.nextToken());\n        fac = new long[401];\n        invfac = new long[401];\n        fac[0] = invfac[0] = 1L;\n        for(int i=1; i <= 400; i++)\n        {\n            fac[i] = (fac[i-1]*i)%MOD;\n            invfac[i] = power(fac[i], MOD-2, MOD);\n        }\n        long[] pow2 = new long[401];\n        for(int i=0; i <= 400; i++)\n            pow2[i] = power(2, i, MOD);\n        long[][] dp = new long[N+1][N+1];\n        for(int v=1; v <= N; v++)\n        {\n            dp[v][v] = pow2[v-1];\n            for(int k=1; k <= v; k++)\n                for(int block=1; block <= k; block++)\n                {\n                    if(block == v)\n                        continue;\n                    long temp = (dp[v-block-1][k-block]*calc(k-block, block))%MOD;\n                    temp = (temp*pow2[block-1])%MOD;\n                    dp[v][k] += temp;\n                    if(dp[v][k] >= MOD)\n                        dp[v][k] -= MOD;\n                }\n        }\n        long res = 0L;\n        for(int v=1; v <= N; v++)\n        {\n            res += dp[N][v];\n            if(res >= MOD)\n                res -= MOD;\n        }\n        System.out.println(res);\n    }\n    static long[] fac, invfac;\n    public static long calc(int a, int b)\n    {\n        long res = (fac[a+b]*invfac[a])%MOD;\n        return (res*invfac[b])%MOD;\n    }\n    public static long power(long x, long y, long p)\n    {\n        //0^0 = 1\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 >>= 1;\n            x = (x*x)%p;\n        }\n        return res;\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\npublic class E {\n\n\tstatic long mod;\n\tstatic long[][] dp;\n\tstatic int n;\n\tstatic long[] nWaysToPlaceGroupOfSize;\n\t\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tn=fs.nextInt();\n\t\tmod=fs.nextInt();\n\t\tprecomp();\n\t\tdp=new long[n+1][n+1];\n\t\tfor (int i=0; i<dp.length; i++) Arrays.fill(dp[i], -1);\n\t\t\n\t\tlong ans=0;\n\t\tfor (int nXsLeft=2; nXsLeft<=n; nXsLeft++) {\n\t\t\tlong curAns=go(0, nXsLeft);\n\t\t\tans=add(ans, curAns);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tstatic long go(int position, int nXsLeft) {\n\t\tif (position==n) {\n\t\t\t//last thing was skipped, impossible\n\t\t\treturn 0;\n\t\t}\n\t\tif (position==n+1) {\n\t\t\t//last thing was included, 1 way of doing that\n\t\t\tif (nXsLeft==0) return 1;\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[position][nXsLeft]!=-1) {\n\t\t\treturn dp[position][nXsLeft];\n\t\t}\n\t\t//TODO: brute force number of xs to place\n\t\tlong ways=0;\n\t\tfor (int nPlace=1; nPlace<=Math.min(nXsLeft, n-position); nPlace++) {\n\t\t\tlong futureWays=go(position+nPlace+1, nXsLeft-nPlace);\n\t\t\tlong waysToPlaceMe=nCk(nXsLeft, nPlace);\n\t\t\tif (nPlace>1) waysToPlaceMe=mul(waysToPlaceMe, nWaysToPlaceGroupOfSize[nPlace]);\n\t\t\tways=add(ways, mul(waysToPlaceMe, futureWays));\n\t\t}\n\t\treturn dp[position][nXsLeft]=ways;\n\t}\n\t\n\tstatic long nCk(int n, int k) {\n\t\tif (k>n) throw null;\n\t\treturn mul(facts[n], mul(factInvs[k], factInvs[n-k]));\n\t}\n\t\n\tstatic long add(long a, long b) {\n\t\treturn (a+b)%mod;\n\t}\n\tstatic long sub(long a, long b) {\n\t\treturn ((a-b)%mod+mod)%mod;\n\t}\n\tstatic long mul(long a, long b) {\n\t\treturn (a*b)%mod;\n\t}\n\tstatic long fastPow(long base, long e) {\n\t\tif (e==0) return 1;\n\t\tlong half=fastPow(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[] facts=new long[1_000_00];\n\tstatic long[] factInvs=new long[1_000_00];\n\tstatic void precomp() {\n\t\tfacts[0]=1;\n\t\tfor (int i=1; i<facts.length; i++) facts[i]=mul(facts[i-1], i);\n\t\tfor (int i=0; i<factInvs.length; i++) factInvs[i]=fastPow(facts[i], mod-2);\n\t\tnWaysToPlaceGroupOfSize=new long[500];\n\t\tfor (int finalSize=1; finalSize<nWaysToPlaceGroupOfSize.length; finalSize++) {\n\t\t\tfor (int firstPos=0; firstPos<finalSize; firstPos++) {\n\t\t\t\tint l=firstPos, r=finalSize-1-firstPos;\n\t\t\t\tnWaysToPlaceGroupOfSize[finalSize]=add(nWaysToPlaceGroupOfSize[finalSize], nCk(l+r, l));\n\t\t\t}\n\t\t}\n\t\tSystem.err.println(\"Done with precomp.\");\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tArrayList<Integer> l=new ArrayList<>();\n\t\tfor (int i:a) l.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i=0; i<a.length; i++) a[i]=l.get(i);\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\t\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class E14G {\n    static int[][] choose;\n    public static void main(String[] args) throws IOException {\n        init_io();\n        int N = nint(), M = nint();\n        choose = new int[N+1][];\n        long[] ways = new long[N+1];\n        ways[0] = 1; ways[1] = 1;\n        for (int i = 0; i <= N; i++) choose[i] = new int[i+1];\n        for (int i = 0; i <= N; 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-1] + choose[i-1][j]) % M;\n            }\n        }\n        for (int i = 2; i <= N; i++) {\n            for (int j = 0; j < i; j++) {\n                ways[i] = (ways[i] + choose[i-1][j]) % M;\n            }\n        }\n        long[][] dp = new long[(N+1)/2+1][N+1];\n        dp[0][0] = 1;\n        for (int i = 1; i <= (N+1)/2; i++) {\n            for (int j = 1; j <= N; j++) {\n                for (int k = 1; k <= j; k++) {\n                    dp[i][j] = (dp[i][j] + ways[k] * choose[j][k] % M * dp[i-1][j-k] % M) % M;\n                }\n            }\n        }\n        long ans = 0;\n        for (int i = 1; i <= (N+1)/2; i++) {\n            ans = (ans + dp[i][N-(i-1)]) % M;\n        }\n        out.println(ans);\n        out.close();\n    }\n\n    static StreamTokenizer in;\n    static PrintWriter out;\n    static BufferedReader br;\n\n    static int nint() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    static void init_io() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        in = new StreamTokenizer(br);\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1515E extends PrintWriter {\n\tCF1515E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1515E o = new CF1515E(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint md = sc.nextInt();\n\t\tint k = (n + 1) / 2;\n\t\tint[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;\n\t\tfor (int h = 1; h <= k; h++)\n\t\t\tfor (int l = h; l <= n - h + 1; l++)\n\t\t\t\tdp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);\n\t\tint ans = 0;\n\t\tfor (int h = 1; h <= k; h++)\n\t\t\tans = (ans + dp[h][n - h + 1]) % md;\n\t\tprintln(ans);\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n@SuppressWarnings(\"unused\")\npublic class Solution{\n\t\n\tstatic long mod = -1;\n\tstatic long[] fact, invfact, pow;\n\tstatic long[][] C;\n\tstatic long[][] dp;\n\tstatic final int N = 405;\n\tstatic int n;\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner fs = new FastScanner();\n    \tPrintWriter out = new PrintWriter(System.out);\n    \t\n    \tint tt = 1;\n    \touter:\n    \twhile(tt-->0) {\n    \t\t\n    \t\tn = fs.nextInt();\n    \t\tmod = fs.nextLong();\n    \t\t\n    \t\tdp = new long[N][N];\n    \t\tprecompute();\n    \t\t\n    \t\tdp[0][0] = 1;\n    \t\t\n    \t\tfor(int i=0;i<n;i++) {\n    \t\t\tfor(int j=0;j<=i;j++) {\n    \t\t\t\tfor(int k=1;i+k<=n;k++) {\n    \t\t\t\t\tdp[i+k+1][j+k] += (((dp[i][j]*pow[k-1])%mod)*C[j+k][k])%mod;\n    \t\t\t\t\tdp[i+k+1][j+k] %= mod;\n    \t\t\t\t}\n    \t\t\t}\n    \t\t}\n    \t\t\n    \t\tlong ans = 0;\n    \t\tfor(int i=0;i<=n;i++) {\n    \t\t\tans = (ans + dp[n+1][i])%mod;\n    \t\t}\n    \t\t\n    \t\tout.println(ans);\n    \t\t\n    \t\t\n    \t\t\n    \t\t\n    \t}\n    \t\n    \tout.close();\n    }\n\t\n\t\n\tstatic void precompute() {\n\t\tfact = new long[N]; invfact = new long[N]; C = new long[N][N]; pow = new long[N];\n\t\tfact[0] = 1;\n\t\tfor(int i=1;i<=n;i++) fact[i] = (fact[i-1]*i)%mod;\n\t\tinvfact[n] = inv(fact[n]);\n\t\tfor(int i=n-1;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;\n\t\t\n\t\tpow[0] = 1;\n\t\tfor(int i=1;i<=n;i++) pow[i] = (pow[i-1]*2)%mod;\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\tif(j==0 || j==i) C[i][j] = 1;\n\t\t\t\telse C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\t\n\tstatic long exp(long a, long n) {\n\t\tlong res = 1;\n\t\twhile(n>0) {\n\t\t\tif((n&1)==1) res = (res*a)%mod;\n\t\t\ta = (a*a)%mod;\n\t\t\tn = n>>1;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tstatic long inv(long n) {\n\t\treturn exp(n, mod-2);\n\t}\n\t\n\n\t\n    static final Random random=new Random();\n    \n    static <T> void shuffle(T[] arr) {\n    \tint n = arr.length;\n    \tfor(int i=0;i<n;i++\t) {\n    \t\tint k = random.nextInt(n);\n    \t\tT temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;\n    \t}\n    }\n    \n    \t\n    static void ruffleSort(int[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); int temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n    \n    static void ruffleSort(long[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); long temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n   \n  \n    \n    static void reverse(int[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tint temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    static void reverse(long[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tlong temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    \n    static <T> void reverse(T[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++) {\n    \t\tT temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \t\n    \t\n    static class FastScanner{\n    \tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    \tStringTokenizer st = new StringTokenizer(\"\");\n     \n    \tpublic String next(){\n    \t\twhile(!st.hasMoreElements()){\n    \t\t\ttry{\n    \t\t\t\tst = new StringTokenizer(br.readLine());\n    \t\t\t} catch(IOException e){\n    \t\t\t\te.printStackTrace();\n    \t\t\t}\n    \t\t}\n    \t\treturn st.nextToken();\n    \t}\n    \t\t\n    \tpublic String nextLine() throws IOException {\n    \t\treturn br.readLine();\n    \t}\n    \t\t\n    \tpublic int nextInt(){\n    \t\treturn Integer.parseInt(next());\n    \t}\n     \n    \tpublic int[] readArray(int n){\n    \t\tint[] a = new int[n];\n    \t\tfor(int i=0;i<n;i++)\n    \t\t\ta[i] = nextInt();\n    \t\treturn a;\n    \t}\n    \t\t\n    \tpublic long nextLong() {\n    \t\treturn Long.parseLong(next());\n    \t}\n    \t\t\n    \tpublic char nextChar() {\n    \t\treturn next().toCharArray()[0];\n    \t}\n    }\n   \t\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int(),m=Int();\n\n            Solution sol=new Solution(out);\n            sol.solution(n,m);\n        }\n        out.close();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n\n    public void solution(int n,int mod){\n        long res=0;\n        long ncr[][]=new long[501][501];\n        long pow[]=new long[501];\n        pow[0]=1;\n        for(int i=1;i<pow.length;i++){\n            pow[i]=(pow[i-1]*2)%mod;\n        }\n\n        ncr[0][0]=1;\n        for (int i=1;i<ncr.length;i++) {\n            ncr[i][0]=1;\n            for (int j=1;j<ncr[0].length;j++) {\n                ncr[i][j]=(ncr[i-1][j]+ncr[i-1][j-1])%mod;\n            }\n        }\n\n\n        long dp[][]=new long[n+1][n+1];\n\n\n        for(int i=1;i<dp.length;i++){\n            dp[i][i]=pow[i-1];\n            for(int j=1;j<i;j++){\n                for(int k=1;k<i;k++){\n                    //pow[cnt-1]\n                    if(i-k-1>=1&&j>=k){\n                        dp[i][j]=dp[i][j]+dp[i-k-1][j-k]*((ncr[j][k]*pow[k-1])%mod);\n                        dp[i][j]%=mod;\n                    }\n                }\n\n            }\n        }\n\n\n\n\n        for(int i=1;i<=n;i++){\n            res+=dp[n][i];\n            res%=mod;\n        }\n        out.println(res);\n    }\n\n\n\n}\n\n\n\n\n\n\n\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "// Main Code at the Bottom\nimport java.util.*;\nimport java.io.*; \npublic class Main{\n\t//Fast IO class\n    static class FastReader {\n        BufferedReader br; \n        StringTokenizer st; \n        public FastReader() {\n        \tboolean env=System.getProperty(\"ONLINE_JUDGE\") != null;\n        \t//env=true;\n        \tif(!env) {\n        \t\ttry {\n\t\t\t\t\tbr=new BufferedReader(new FileReader(\"src\\\\input.txt\"));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n        \t}\n        \telse br = new BufferedReader(new InputStreamReader(System.in)); \n        } \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine()); \n                } \n                catch (IOException  e) {\n                    e.printStackTrace(); \n                } \n            } \n            return st.nextToken(); \n        } \n        int nextInt() {\n            return Integer.parseInt(next()); \n        } \n        long nextLong() {\n            return Long.parseLong(next()); \n        } \n        double nextDouble() {\n            return Double.parseDouble(next()); \n        } \n        String nextLine() {\n            String str = \"\"; \n            try {\n                str = br.readLine(); \n            } \n            catch (IOException e) {\n                e.printStackTrace(); \n            } \n            return str; \n        } \n    }     \n    static long MOD=(long)1e9+7;\n    //debug\n    static void debug(Object... o) {\n        System.out.println(Arrays.deepToString(o));\n    }\n    static FastReader sc=new FastReader();\n    static PrintWriter out=new PrintWriter(System.out);  \n    //Global variables and functions\n    static long memo[];\n    static long C[][];\n    static long exp(long a,long x) {\n    \tif(x==0) return 1;\n    \tif(x%2==0) return exp((a*a)%MOD,x/2)%MOD;\n    \treturn ((a%MOD)*((exp((a*a)%MOD,x/2))%MOD))%MOD;\n    }\n    static void fill(int n) {\n    \tC = new long[n+1][n+1];\n    \tfor(int i = 1; i<=n;i++) C[i][0]=C[i][i]=1;\n    \tfor(int i=2;i<=n;i++) {\n    \t\tfor(int j=1;j<=n;j++) {\n    \t\t\tC[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;\n    \t\t}\n    \t}\n    }\n    //Main function(The main code starts from here)\n    public static void main (String[] args) throws java.lang.Exception {\n    \tint test=1;\n    \t//test=sc.nextInt();\n    \twhile(test-->0) {\n    \t\tint n = sc.nextInt();\n    \t\tMOD = sc.nextLong();\n    \t\tmemo = new long[n+1];\n    \t\tfill(n);\n    \t\tlong dp[][] = new long[n+5][n+5];\n    \t\tfor(int i=1;i<=n;i++) dp[i][i]=exp(2,i-1);\n    \t\tfor(int i = 2; i <= n; i++) {\n    \t\t\tfor(int j = 1; j < i; j++) {\n    \t\t\t\tfor(int k = 1; k <= j; k++) {\n    \t\t\t\t\tlong val = (dp[i-k-1][j-k]*C[j][k])%MOD;\n    \t\t\t\t\tif(memo[k-1] ==0) memo[k-1] = exp(2, k-1);\n    \t\t\t\t\tval=(val*memo[k-1])%MOD;\n    \t\t\t\t\tdp[i][j]=(dp[i][j]+val)%MOD;\n    \t\t\t\t}\n    \t\t\t}\n    \t\t}\n    \t\tlong ans = 0;\n    \t\tfor(int i=0;i<=n;i++) ans=(ans+dp[n][i])%MOD;\n    \t\tout.println(ans);\n    \t}\n        out.flush();\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Sol{\n\nstatic class Pair implements Comparable<Pair>{\n        int x;int y;int value;\n        public Pair(int x,int y,int value) {\n         \n          this.x=x;\n          this.y=y;\n          this.value=value;\n        }\n        @Override\n        public int compareTo(Pair p){return Long.compare(y,p.y); }\n       \n   }\n\npublic static void main(String []args){\n\nint t=1;\n\nwhile(t-->0){\nint n=ni();mod=nl();\nprecomp();\nlong dp[][]=new long[405][405];dp[0][0]=1l;\nfor(int i=0;i<n;i++){\n    for(int j=0;j<=i;j++){\n       for(int k=1;k+i<=n;k++){ \n          \n          dp[i+k+1][j+k]+=((dp[i][j]*p2[k-1])%mod)*Comb[k+j][k];\n          dp[i+k+1][j+k]%=mod;\n      }\n   }\n }\n\nlong sum=0l;\nfor(int i=0;i<=n;i++)sum=(sum+dp[n+1][i])%mod;\nout.println(sum);\n\n}out.close();}\n\n//-----------------Utility--------------------------------------------\n\nstatic long Comb[][]=new long[405][405];\nstatic long p2[]=new long[405];\nstatic long inv[]=new long[405];\nstatic long factorial[]=new long[405];\nstatic void precomp(){\n\ninv[0]=1;factorial[0]=1l;\n\nfor(long i=1;i<405;i++){factorial[(int)i]=i*factorial[(int)i-1];factorial[(int)i]%=mod;}\n\nfor(int i=1;i<405;i++){ inv[i]=power(factorial[i],mod-2);}\n\nfor(int i=0;i<405;i++){\n \n   for(int j=0;j<=i;j++){\n     Comb[i][j]=(((factorial[i]*inv[j])%mod)*inv[i-j])%mod;\n   }\n }\n\nfor(int i=0;i<405;i++)p2[i]=power(2,i);\n\n}\n\nstatic int Max=Integer.MAX_VALUE; static long mod=1000000007;\nstatic int v(char c){return (int)(c-'a')+1;}\npublic static long power(long x, long y )\n    {\n        //0^0 = 1\n        long res = 1L;\n        x = x%mod;\n        while(y > 0)\n        {\n            if((y&1)==1)\n                res = (res*x)%mod;\n            y >>= 1;\n            x = (x*x)%mod;\n        }\n        return res;\n    }\n//--------------------------------------------------------------------\n\nstatic InputStream inputStream = System.in;\nstatic OutputStream outputStream = System.out;\nstatic FastReader in=new FastReader(inputStream);\nstatic PrintWriter out=new PrintWriter(outputStream);\n\nstatic class FastReader \n{ \n  BufferedReader br; \n  StringTokenizer st; \n \n        FastReader(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n \n  public 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  public int nextInt() \n  { \n      return Integer.parseInt(next()); \n  } \n \n  public long nextLong() \n  { \n      return Long.parseLong(next()); \n  } \n \n public  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}\nstatic int ni(){return in.nextInt();}\nstatic long nl(){return in.nextLong();}\nstatic String ns(){return in.nextLine();}\nstatic int[] na(int n){int a[]=new int[n];for(int i=0;i<n;i++){a[i]=ni();} return a;}\n\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "// practice with kaiboy, coached by rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1515E extends PrintWriter {\n\tCF1515E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1515E o = new CF1515E(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint md = sc.nextInt();\n\t\tint k = (n + 1) / 2;\n\t\tint[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;\n\t\tfor (int h = 1; h <= k; h++)\n\t\t\tfor (int l = h; l <= n - h + 1; l++)\n\t\t\t\tdp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);\n\t\tint ans = 0;\n\t\tfor (int h = 1; h <= k; h++)\n\t\t\tans = (ans + dp[h][n - h + 1]) % md;\n\t\tprintln(ans);\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class PhoenixAndComputers {\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 mod = Integer.parseInt(st.nextToken());\n        long[][] dp = new long[n+2][n+1];\n        long[] pow = new long[n+1];\n        pow[0] = 1;\n        for (int i=1; i <= n; i++){\n            pow[i] = pow[i-1]*2;\n            pow[i] %= mod;\n        }\n        long[][] choose = new long[n*2+1][n+1];\n        for (int i=0; i <= n; i++){\n            choose[i][i] = 1;\n        }\n        for (int i=1; i <= n*2; i++){\n            for (int j=0; j <= n; j++){\n                choose[i][j] = choose[i-1][j];\n                if (j > 0){\n                    choose[i][j] += choose[i-1][j-1];\n                }\n                choose[i][j] %= mod;\n            }\n        }\n        dp[0][0] = 1;\n        for (int i=0; i < n; i++){ // number of computers on\n            for (int j=0; j <= i; j++){ // number manually turned on\n                for (int k=1; k+i <= n; k++){ // number of computers manually turned on in next \"block\"\n                    dp[i+k+1][j+k] += (pow[k-1] * choose[j+k][k])%mod * dp[i][j];\n                    dp[i+k+1][j+k] %= mod;\n                }\n            }\n        }\n        long ans = 0;\n        for (int j=0; j <= n; j++){\n            ans += dp[n+1][j];\n            ans %= mod;\n        }\n        System.out.println(ans);\n    }\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1515E extends PrintWriter {\n\tCF1515E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1515E o = new CF1515E(); o.main(); o.flush();\n\t}\n\n\tint[] ff, gg; int md;\n\tlong ch(int n, int k) {\n\t\treturn (long) ff[n] * gg[k] % md * gg[n - k] % md;\n\t}\n\tlong inv(int a) {\n\t\treturn a == 1 ? 1 : inv(a - md % a) * (md / a + 1) % md;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tmd = sc.nextInt();\n\t\tint[] p2 = new int[n];\n\t\tfor (int p = 1, i = 0; i < n; i++) {\n\t\t\tp2[i] = p;\n\t\t\tp = p * 2 % md;\n\t\t}\n\t\tff = new int[n + 1];\n\t\tgg = new int[n + 1];\n\t\tlong f = 1;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tgg[i] = (int) inv(ff[i] = (int) f);\n\t\t\tf = f * (i + 1) % md;\n\t\t}\n\t\tint[][] dp = new int[n + 1][n + 1]; dp[1][1] = 1; dp[2][2] = 2;\n\t\tfor (int u = 3; u <= n; u++)\n\t\t\tfor (int v = 1; v <= u; v++) {\n\t\t\t\tlong x = v == u ? p2[u - 1] : 0;\n\t\t\t\tfor (int k = 1; k < v && k <= u - 2; k++)\n\t\t\t\t\tx += dp[u - k - 1][v - k] * ch(v, k) % md * p2[k - 1] % md;\n\t\t\t\tdp[u][v] = (int) (x % md);\n\t\t\t}\n\t\tint ans = 0;\n\t\tfor (int v = 1; v <= n; v++)\n\t\t\tans = (ans + dp[n][v]) % md;\n\t\tprintln(ans);\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class e1515 {\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n\n        solve(s.nextInt(), s.nextLong());\n    }\n\n\n    public static long inv(long n, long mod) {\n        if (n == 1) return 1;\n        return (inv(mod % n, mod) * (mod - mod / n)) % mod;\n    }\n\n    public static void solve(int n, long mod) {\n        long fact[] = new long[n + 2];\n        long invFact[] = new long[n + 2];\n        long twoPow[] = new long[n + 2];\n\n        fact[0] = 1;\n        invFact[0] = 1;\n        twoPow[0] = 1;\n\n        for (int i = 1; i < n + 2; i++) {\n            fact[i] = (fact[i - 1] * i) % mod;\n            invFact[i] = (invFact[i - 1] * inv(i, mod)) % mod;\n            twoPow[i] = (2 * twoPow[i - 1]) % mod;\n        }\n\n        long dp[][] = new long[n + 2][];\n        dp[0] = new long[]{1};\n\n        long next[] = null;\n        for (int i = 1; i <= n + 1; i++) {\n            next = new long[i + 1];\n\n            for (int j = 0; j < i - 1; j++) {\n                for (int k = 0; k < dp[j].length; k++) {\n                    next[k + i - j - 1] = (next[k + i - j - 1] + ((((dp[j][k] * twoPow[i - j - 2]) % mod * fact[k + i - j - 1]) % mod * invFact[k]) % mod * invFact[i - j - 1]) % mod) % mod;\n                }\n            }\n\n            dp[i] = next;\n        }\n\n        long sum = 0;\n        for (int i = 0; i < next.length; i++) {\n            sum = (sum + next[i]) % mod;\n        }\n\n        System.out.println(sum);\n    }\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.sql.Array;\nimport java.util.*;\nimport java.util.List;\n\npublic class Main {\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader()\n        {\n            br = new BufferedReader(\n                    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                }\n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() { return Integer.parseInt(next()); }\n\n        long nextLong() { return Long.parseLong(next()); }\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            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n\n    static final int N=405;\n    static final int mod=1000000007;\n    static final int INF=1000000009;\n    static final int numBit=17;\n    static FastReader r=new FastReader();\n    static PrintWriter pw = new PrintWriter(System.out);\n\n//    call dp[i][j] is number ways can turn on i computer but we just turn on j computer manually.\n    static int [][]dp=new int[N][N];\n    static int []p2=new int[N];\n    static int []fac=new int[N];\n    static int []ifac=new int[N];\n    static int M;\n\n    public static int mul(int a,int b){\n        return (int)(1l*a*b%M);\n    }\n\n    public static int poww(int a,int b){\n        int r=1;\n        while(b>0){\n            if(b%2==1) r=mul(r,a);\n            a=mul(a,a);\n            b>>=1;\n        }\n        return r;\n    }\n\n    public static int inv(int x){\n        return poww(x,M-2);\n    }\n\n    public static int add(int a,int b){\n        a+=b;\n        if(a>=M) a-=M;\n        return a;\n    }\n\n    public static int bino(int n,int k){\n        return mul(fac[n],mul(ifac[n-k],ifac[k]));\n    }\n\n    public static void main(String[] args) throws IOException {\n        int n=r.nextInt();\n        M=r.nextInt();\n        fac[0]=1;\n        ifac[0]=1;\n        p2[0]=1;\n        for(int i=1;i<=n;++i){\n            fac[i]=mul(fac[i-1],i);\n            ifac[i]=inv(fac[i]);\n            p2[i]=mul(p2[i-1],2);\n        }\n        int ans=0;\n        dp[0][0]=1;\n        for(int i=0;i<=n;++i){\n            for(int k=0;k<=i;++k){\n                for(int j=1;j<=n-i+1;++j){\n                    dp[i+j+1][k+j]=add(dp[i+j+1][k+j],mul(dp[i][k],mul(p2[j-1],bino(j+k,j))));\n                }\n            }\n        }\n        for(int i=0;i<=n+1;++i){\n            ans=add(ans,dp[n+1][i]);\n        }\n        pw.print(ans);\n        pw.close();\n    }\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Practice {\n\tpublic static long mod = (long) Math.pow(10, 9) + 7;\n\tpublic static long[][] dp;\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\n\t\tString[] s2 = br.readLine().split(\" \");\n\n\t\tint n = (int) Long.parseLong(s2[0]);\n\t\tlong m = Long.parseLong(s2[1]);\n\t\tdp = new long[n + 2][n + 2];\n\t\tlong[] power = new long[n + 1];\n\t\tmod = m;\n\t\tlong[][] choose = new long[n + 2][n + 2];\n\t\tgetPow(power, n + 1);\n\t\tgetChoose(choose, n + 2, n + 2);\n\t\tdp[0][0] = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= i; j++) {\n\t\t\t\tfor (int k = 1; k + i <= n; k++) {\n\t\t\t\t//\tSystem.out.println((j + k) + \" \" + k + \" - \" + choose[j + k][k]);\n\t\t\t\t\tdp[i + k + 1][j\n\t\t\t\t\t\t\t+ k] = (dp[i + k + 1][j + k] + (((dp[i][j] * power[k - 1]) % mod) * choose[j + k][k]) % mod)\n\t\t\t\t\t\t\t\t\t% mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tans = (ans + dp[n + 1][i]) % mod;\n\t\t}\n\t\tpw.println(ans);\n\t\tpw.close();\n\t}\n\n\tprivate static void getChoose(long[][] choose, int up, int dow) {\n\t\t// TODO Auto-generated method stub\n\t\tfor (int i = 1; i < up; i++) {\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tif (j == 1 && i == 1) {\n\t\t\t\t\tchoose[i][j] = 1;\n\t\t\t\t} else if (j == 1) {\n\t\t\t\t\tchoose[i][j] = i;\n\t\t\t\t} else {\n\t\t\t\t\tchoose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void getPow(long[] power, int l) {\n\t\t// TODO Auto-generated method stub\n\t\tfor (int i = 0; i < l; i++) {\n\t\t\tif (i == 0) {\n\t\t\t\tpower[i] = 1;\n\t\t\t} else {\n\t\t\t\tpower[i] = (power[i-1] * 2) % mod;\n\t\t\t}\n\t\t}\n\t}\n\n}\n\n//private static long getGCD(long l, long m) {\n//// TODO Auto-generated method stub\n//\n//long t1 = Math.min(l, m);\n//long t2 = Math.max(l, m);\n//while (true) {\n//\tlong temp = t2 % t1;\n//\tif (temp == 0) {\n//\t\treturn t1;\n//\t}\n//\tt2 = t1;\n//\tt1 = temp;\n//}\n//}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _G14 {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        int t = 1;\n        while (t-- > 0) {\n            int n = sc.nextInt();\n            mod = sc.nextLong();\n            long res = 0;\n            initFac(n + 7);\n            long [] tpow = new long[n + 7];\n            long [][] combo = new long[n + 6][n + 6];\n            for (int i = 0; i <= n; i++) {\n                for (int j = 0; j <= i; j++) {\n                    if (j == 0 || j == i)\n                        combo[i][j] = 1;\n                    else\n                        combo[i][j] = (combo[i - 1][j - 1] + combo[i - 1][j]) % mod;\n                }\n            }\n            tpow[0] = 1;\n            for (int i = 1; i <= n + 6; i++) tpow[i] = (tpow[i - 1] * 2) % mod;\n            // dp[i][auto]\n            long [][] dp = new long[n + 1][n + 1];\n            for (int i = 1; i <= n; i++) dp[i][0] = tpow[i - 1];\n            for (int i = 3; i <= n; i++) {\n                for (int auto = 1; auto <= n / 2; auto++) {\n                    if (!check(i, auto)) continue;\n                    long total = 0;\n                    for (int j = i - 2; j >= 1; j--) {\n                        if (!check(j, auto - 1)) break;\n                        int len = i - j - 1;\n                        long ways = tpow[len - 1];\n                        int picked = j - (auto - 1);\n                        long interleave = combo[len + picked][picked];\n                        ways = (ways * interleave) % mod;\n                        ways = (ways * dp[j][auto - 1]) % mod;\n                        total = (total + ways) % mod;\n                    }\n                    dp[i][auto] = total;\n                    if (i == n) res = (res + dp[i][auto]) % mod;\n                }\n            }\n            res = (res + dp[n][0]) % mod;\n            out.println(res);\n        }\n        out.close();\n    }\n\n    static boolean check(int n, int auto) {\n        int rem = n - auto;\n        int seg = auto + 1;\n        return rem >= seg;\n    }\n\n    static long[] fac;\n    static long mod;\n\n    static void initFac(long n) {\n        fac = new long[(int)n + 1];\n        fac[0] = 1;\n        for (int i = 1; i <= n; i++) {\n            fac[i] = (fac[i - 1]  * i) % mod;\n        }\n    }\n\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(long x) {\n        return pow(x, mod - 2);\n    }\n\n\n\n\n    static void sort(int[] a) {\n        ArrayList<Integer> q = new ArrayList<>();\n        for (int i : a) q.add(i);\n        Collections.sort(q);\n        for (int i = 0; i < a.length; i++) a[i] = q.get(i);\n    }\n\n    static void sort(long[] a) {\n        ArrayList<Long> q = new ArrayList<>();\n        for (long i : a) q.add(i);\n        Collections.sort(q);\n        for (int i = 0; i < a.length; i++) a[i] = q.get(i);\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}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Etruco2 {\n\t\n\tstatic String[] vals = {\n\t\t\t\"%S3L{PYzV1%SGI'>$/4Gam=^#ODu|`Q!Bys%Mw|?fA*0ti{r69RB1N`{B>YC;.:XEmm3t-i^N\",\n\t\t\t\"#Y73mVxQ&J`inFO4.v<j?yg{4~O=p=t$'#UHQizDnbsn,+JyuS~@WKw0p*Gy%V:#sa5,L|9RX{\",\n\t\t\t\"f0J*n]5ZaRg:d-;{f!Y47]i_'u'cTz*=K$b#=}w[U]3*f+$|4ePs'K?]p8~0loSL$h_+T^{+ik\",\n\t\t\t\"@r),FzP0XP>vU2<s9GIJ;0K0e)b_Hwyaw2}n0-%|lUlV(kWB<nx7@M[30yXxR(n:5@CEc[~,B^o\",\n\t\t\t\"0<2C[Fz1*3iganAet-6RW8/X&nnSUf`Tu5-$~<5}F~$e_n5j9jD^Kk)_Xh=)WG@{4:XC;V4a|X]*\",\n\t\t\t\"(_gw]4[ktYOZ},E?GXG5h{UF<Fx1O$0YNdA0+5)7#j%f)=Ui|3p^tt:SV(N^mbR9.+!s4fy<.?WQ.\",\n\t\t\t\"%-i=_PJtuHA63yU,f)Gh@#Z*;FIWjaXwKS*bq=EOMA9yc>OD+}xg{z`X.~atEmXp9Z~*u]I3_7IxDZ\",\n\t\t\t\"#N,-ehU0na1kWpn=P9ZK{TRs/&@KgxaK4h+V/ea!9Y3QYy9ZL}n&pn>G+'I+]ekWM$(g'8ym$Mj+,?V\",\n\t\t\t\"coyL[=Xb>wzL0z?{kW5GQjeWPCy6YU<B/?paWq?^7__LMh<{ZJ+8!o7I.=<2b)j-)f!Cwk7!Ojrs[Zs\",\n\t\t\t\"A+If^46|x9Wfiv3OlqZAUE[u(p2nLL/x$!LmSrR4Do9+4oYG:0P-!#>g9'|axl=i;q`E:ja?MDOB<Gyk\",\n\t\t\t\"1$8eKLgE'nM]8^vi,NCMzBN{a<@{.}Yibo/OLo*`;G%v}'Lh~oGudWag6ECf{cpc<%]2ciRk*]k|/>y?V\",\n\t\t\t\")>A7nmMgLYs=3#7`G%X{Kr~U%||frj>qN)}H^GawXTT}/=bFAGD+u1?YNT_2Ht~w[m8?LLh=YBS!6(nYD:\",\n\t\t\t\"%W;~8W^>]K2kwP_JIVOGo.l5<Z0zR51sXzT'sS)-@WFA6I1Q*{$SR0UT1x}[!]|^JT.N>;yA`kfH`f>E.`6\",\n\t\t\t\"#iCwqRtf[6J>97)oD,nb>z+}nIJ=?2h40Mhp=)E'Bm|<?v1e<H68>yG'sA0#eN>Ft4N<Qt}eXeLHI|A7BmOV\",\n\t\t\t\"sYg3/'{oSnr!c#bd??s'UM==k<CN-|!,}c8Vb[&?tR}]?N38+U-w=$yYb_3?k*RDR1=.q]xSz2Lz(&53-xGF\",\n\t\t\t\"J<2wR!6o@K;#ftMP&,Gl;<VmX#2TNi]l_ZP]1Y$,bqcrIl_2KlqcXh46&fB&5{h/+[~5lLK8C*Ypm$UxRW4-N\",\n\t\t\t\"6:X}!AJ[uGdSD@Bbe7#$g]u{ByvOp[nkDIG*Ln1@d:`OnhYjr#c]4qa4>hatq4l_EoFb}6FtSOQfu3j$>o$98J\",\n\t\t\t\",:=#^-<(+n*e[l7/{uM<_x)#7GNxXsA*v@5~9+*;=l%XX[65ms-a3rQE({l3Y#L'>1[lHW*9/;8w^x96dK8d|H*\",\n\t\t\t\"'7C8`Ku%e]3X@+oX0(O/)~Up%;eaEA_q0kVkr>BtTCV{$~:ff]['Oy4lW[F&#5Epcri#A$q7qk3x(I[)Iu`+qjc2\",\n\t\t\t\"$a|sCP(`q)r!w>3jHD7~;@Y%U_BTgu%!<]/Qs}siNKUHJ`^mEFMI!6<o.la&tEkP%V^q#RZb2S4,izBiS_l.Yh2y{\",\n\t\t\t\"#ESSy)K!I_r#D'5qJ)s]SnZ8c:~PE4*;#A$[AeE9A8,{2._6YY;=~iOJ=33d8Hw)5vXp%g=WqVl+yy,VmtM,2ao4=N\",\n\t\t\t\"e<)oJ1mnPoS!A$'Y}`AZVCZUQ0Ky)'^jQZB{eVCW~xb4f_*_Lo$>.Cj_X+%~h2UsWSQbRj4XoL'#yW?IGXbd[!3U|6\",\n\t\t\t\"D`L&4'8NHO(dVv{+<uYwH5t#c?4YOB.5@z%:p>`HG#]pe,!!F.~|CZ$Qh]<J%_ON:6GMr|5b<w~)?1]6H%QT:hfMYAN\",\n\t\t\t\"48eMirgOAMc0``u#]nz{aP5u:cM>>5B%J|+w}8}(y_Uv_VFq]rCYB1wpD[{U}={#=S+SJQmQ@~1zY~idvR]4rKz#L3L{\",\n\t\t\t\"+`-#D+O:7z=[7GBB)R=eQ:5OZa'bc_[D+NFe=P3cdM3QKJVv*?x;RlNZixw?{qd#@8D>CoZzsJEqnGL!Xd3RoZ,qBv!4k\",\n\t\t\t\"'/q7_eOF].wH,o}YDkMDO^#+TvDqr*Q4.~%*h6DH=0TCpE*m3T++kJK(JQlIwA~+r/c{N0,QD;1DDX(<OZivC3Y>J5Uyfo\",\n\t\t\t\"$i+*e>tWyzs,GKQ>IP/+re2YX[.uY[jzUE$$o3KmUIDxlxy}ZdhF(wBOTip8DjA,cwHU&:qHwKta#[,SJ#oYa$BjEd<Fe]*\",\n\t\t\t\"#O*r,8u<Bz3Vs&Jdq1d2AIxB3}skyib'GPee/r0tw^7AaxMJUncL$:O-C?#`!j:sw!s3rlz:mtk$|rN{Ma`!jezRkTgI>n9.\",\n\t\t\t\"mH`mtJAcH6.~?en.+&TlY/[Wye#N<]Ei$ErRJJpnprYU1]lK{)rXjST-bu[KYUZw'1f<lYS({<1+Sz,T3~sB/);u$eO=PMmZ\",\n\t\t\t\"J^-Oc/l}!vGny~6jX-@G>;ot_||1)VA<AH4Sx'fRx?%:^tq-#+,99k0LY~S4u^>Wn>(ai?;7'C|f=5-*X%G<R6i7r}gr#nq/V\",\n\t\t\t\"8@>trXHR!F2,jQ<C4lqC5wlS)}t8@+,Ha]YnP1ACVvyJrDz[t6T9?n69yZk#&+p6;&kLk#Bwb:cA-|TKzXq0Tk{J3gTt*!(rRs\",\n\t\t\t\".AGXO=~svf*-P1ad/!n]Jc^EPtwzaC!6kKUUz*0TTW%qkFX`bO=/pH.QU!A|C,r-03O/_/@l*bKJZqO3HW7M*i;?h8;Fg`cS0Lk\",\n\t\t\t\"(r9y<CJ.RO,zE$/)g%8/Lrp?VQ4+-wr4D?5IpIWtzbNqQG3UL!/L,#N:h7RJYVAXK,6LT2ZSx,J5mEDS5Es&}Y3aSMh`hLeO0/[V\",\n\t\t\t\"%p%8Rcx~SIuxqTE=n?~W?J-$36syElGT#mdT~oi7bRh,X5Y;'iSv]VQ#R^os:M~B:daTv/#{|,.3mo/.xKESf^3FtfI#95yn9{;}:\",\n\t\t\t\"$0XUj],Dq.GU.t].u7/,H2CQ_`#=tV?sV'q%#/Nx9E)Qgalh]t(Dx}f0FNT(VW;V2pK7!P?Ov]j1kz])U-l%SjP<Q}C?}eW6t:c?t6\",\n\t\t\t\"#6CSvs;f%`_m<op_8dmjpm3wze?_~SUiAOHD@CEXM,vU}i+|V7zk{uw_uyynMDL>0b[9)}Wk-bC.J<SyR+?(zHXd9c{Bx]bA/uDrK|V\",\n\t\t\t\"byn4b~4K[/q[ZNRj){-dXsS~xlky#0,DdUaO<t5JD;33h1B+<17-{#m)LY:8$(y3!HwqUuygn-[x(k%Hmis9T|E;b{P5iXxw}u&MD[F\",\n\t\t\t\"FX|Q06PFPwj.#(LJ=`zx[*J2H?3~7vR:nL9)%!n|)x#KbXFkh{G'zb|#}0F.fZO}aV)7OGtt!^9}KBe[$N)d2@ZnYZnNx@s%W[DQr79N\",\n\t\t\t\"7(&-S]Jg#y1n-{jgr%y57TT`Fsppqgs|2Pk7Enqw^[4N%~:{vlU1[z%,!_-RPASA8~$rq$jMG6,V[(+wGiX(A|2AT)M8Tx%X>}3,+kQyJ\",\n\t\t\t\".3rtg&n9N_e.5[77e*ftW;C1O;U%Qf,}8>.0q~hd!{IHpG~(.O9NdCq`VeKx@H$9(&zgo[{KSq5J-@/$Tq<7eV;6(WMbEkOq[!`nPBB/(*\",\n\t\t\t\")+(4Xy##P^T-5H~m|Xp'{=+G_`7;s9u.SvcNw_xaI'&R)m;`$(8PX8xZ>*@2>xfJR<g]PeA8fk.,H+WoxSrJ$dMqs2nc)4x(T3jeQ<[^~c2\",\n\t\t\t\"&0<|E2l(VeGZt+;mpfAe/w(fyb#U,)i>{Q`s11FEBLydh,'Jz<a,_Lhd7pFC2(Xz(.b5-Yz}::NV/`Mm$;iZR4=}!ph:3+awm>mf&'%6KkX{\",\n\t\t\t\"$K$o}U#q@7(@BTdC.?bOK'KbtD4!bv49z}W=SX/2|G}.g1zn9-1wwY!CV<h2i!ve2ifU;Y}30mtC)Ks~JrllIN_L0q$lEiv3<^HS<d/U*RBvN\",\n\t\t\t\"#K3b}I$Zz}:>?3e>H4B|fEdd7Qf+_&*J<!HxkBjF=1W-YO*sxeKKt'<Sq}|C>:?O(AFgaID%'M![`@F&S0Wh]o_{/Rm4{Iz9w=6+'FZ8+By0x6\",\n\t\t\t\"r:W%R2Z}E)rayr$Gb]UCZFBVy-V7|mEr/3cur6A*;A~Lw2WYGd;@10.H>*.i;J=]6.(=~%JoHc1TBa2!6#[q&TdsqepNhlz#`{iO_</yT,QJ%N\",\n\t\t\t\"QIe,.{^Zi@pR~m4z`j#7)UUIKL&j|2656o<u+o)Iun/cgnSDn(Er*CU'Ix'oMqVLf#Q3px=i^Xe5IX>p.(RylcT?u2b<@dxI7CalOz%bt;ZO$@{\",\n\t\t\t\">S=~&b_O'HOj#A_%6}b!f&:J%)M>5+u1SDSR32En077OL`F#VRFoVroWa59I002YC@?]1LY(jhoD4S*R;}<*,Sw2mT*7'f6B?'^c*e)#c-)arm]k\",\n\t\t\t\"39yr+-}9xZ[IL`G-,~bcWQ$e<$~*!dZE#tMe[OZ-dpH$GXdT,qJ:NvaAi5+<VP3PGos<bgu7s>;%-k4a,=w0,6.WL08y1x)1F;]ITwV5UtL^m&_no\",\n\t\t\t\",O[]LZ531#KNR1W/Dp*p#xX:mf$]Dx{jXE=GW#C7$!mlZO80(W-nJBnpDzuq`'bh'ci>$23`M=wagB024KJB/zC$6GeoiF'_oeyMEh+eI0&8TjgT]*\",\n\t\t\t\"(H?He]J)!SWDW1'$5mj#LMOQ`>A(<!JWh/sqBVqh5`3Sn=~Q2Xd60ga6X8rmbsFN6$8;*KT$wtn?BI/GgH`Y;G-C<b(y{`/'g5W_R8%N7g$U2'{}>~.\",\n\t\t\t\"%yke'YZk3,v$aBhJ2v;^uu$ttS1Mop#,iA^_9]WHWvy7^Y,3_7^Qm{y~axM&s!e(Go'VS.4Bk9v[B:cFQ)O75HC5qY|:pH5lgyoRD.MTg3AcVQ~@A}8Z\",\n\t\t\t\"$J-~[Tc.xDAf+=IC91X/q9f881;?NR;9mE/RDn*%Ik,y9??^&bxA)xr/F,Va_'6eNq4i`kUsKl!|B=I#$}Mhk86(3HU&0dt{GTVR[&Ud|y:'jK&p']h|V\",\n\t\t\t\"#Q3OW&>Jm<pdtfR;qu!:ux&*t+u[Y%1Pt>!PSbJku'7'li(^>eL_l.Ykf$SSv:q-j95w@3v[iec>;CDP=eL]#~R9<pnl+=46=$c,aB|NCp,3z]V8Z2MtJs\",\n\t\t\t\"ytm.~`FCg@m(=F@@U{J0VYStErIP?I-H-a6s$.$#K{3B:tEBJzy|FEaCF&`2HrZ(Y&37=(^}eE+_AQn:/*$%:+ML,g',1k~^dfBSUBskMeZ~x2(Q6>Pq}k\",\n\t\t\t\"XQseb,o}gb]X/'2P%Q$%@Km16RjWt#91?0][T%}q==jMrJGCPP6y?{!OJ:AQ_2dfnHE*Ys+8aS(+D`s&'@A*)E<hlY>v{N@GM!U$jyRr%Q';X^;@gJ#2&xV\",\n\t\t\t\"DELtxBvP@0IqcRU%L-`xQ4no:.|f,NTu1xr`wDGEIVm-q@,G8|1Wst3v)9Dxdc77a1mM6&PgJKY9B~rMVkIoWIG'N>Mrl9YNg)o3)P}mUt^)8-cb$xI_;oX:\",\n\t\t\t\"7lAu)]H&x-r)=mE]6P2B&Ifm(9F9!zNjJd&TN,b}mE;BPwb/*Im&&^pdI%@,U&8ZA24^Us]WYEc[dS[<87^^~/+Nm;?jMe|TU[mP#N,_D}h%-CQxL86/HF-+6\",\n\t\t\t\"/t_'OVLqoVtJlGd%mSg;o^7S(~wf9+>I'INo<[BqyTn]v<PaeLj~eQ~}~X32b7ZTcAMzHu)6jtT2H?@M95(C1:?aNhYMKC(kvP=Z^~+6P@|viR#utIW/iI!3KV\",\n\t\t\t\"*u-akgNqo>b6tkqN5DJSt9NoLl<?DE>+T4N-|<(&kFCv$Q%-fo9dC*4U!gnv<w,Xc4bXAhBV|Jm,Z]J0pMlXBy=*nbA_Pjbr#O;$%dfzGRd}KeJQo/RZNogHMpF\",\n\t\t\t\"'eP7fDQH-H#!j|h>)IoEF6-WZC]lIVJ/@|?/s9&sqd)p^~ugx~zDDH`&P7ch~iZ-jKp5aGQo-v1@I0ugW3LsiA%U:CP`UP@jc>*E30?~zglP0lXb@p(<c$ePRwEN\",\n\t\t\t\"%cQ]O`I?Z^[TbsO6:jNKN`y7o[~KhRv~iu=cY;NVxR*ZQxNrIpfSqw7K{#{{4dOtIsKF-':@tqyVW[{x9t4U}[e1-0XXTABM^.J,{Tc{(wr3Uj@+O7`rznkDp>s]J\",\n\t\t\t\"$G?d*@BxvQ>{2NdbzHeR[LIa-7Q`Puj(Ht)5f+GP7]1AoL[>IIW(>*_Z2`H2Pq:pj2JQ^t|tr|;d5:JS/cG37|x(tV~iHgDQN-3-tyAc{hf#kdsD=lbd`v{64$E2e*\",\n\t\t\t\"#VUQemGH]0leFuV^:<V`hp?J7x?aenY:C^^R:27~{+4jYd+A4{txe>S*/pWVcA~Kjo<HDh=.Mqo`PR,/t1yx&5px3636chFvn1$PAdbtca1B=7:64O5`)Y9`q)hc1c2\",\n\t\t\t\"#$t@73::fTYCj%S]lKo/sIlI=zunsA#8Y5]YEEo6-Bq_u>F-NdUoPs-L'uH@/u++l[,a&e`PX|1u<TjyASURuXJFL'wxzLw<BTzE>*_JmA@$LcB,j:g<d3y`0R*r'!8{\",\n\t\t\t\"aWSp_j@Tzm%?v;)3UoRbqZr;p?D:^wBRjKN@S;`AB|b,1B;(HORok;Tc1W!0qAF%Uq3f@,!+zaG*?GaT*'k@QN3K|S.N$s?<Uw-J+ukf~H#FgGFU`RNx`ZWq(,9=kQQN\",\n\t\t\t\"KMrVDEkM16AuyoI;P*ZJBrv;!,rR/iDn7LxrWtsMh|I.#'x1]/]02wG2I^X3$WOMk0A?DkDk7Ta$FXEt]!hm&UK-RLlB$xpxW][P7=wuoM(e^M]ZerZ<Ey}eoNjw9pdt6\",\n\t\t\t\"=[3C~w/f.74V:6:vze7B-.zl4Mw#~{HFD?;@hicn$B@AU'>e|01JEdcS^bZS,M}DH[=Fc9G5&r7czx%499'f&s9uf4X*%Ei1`=&gz`MEBv6TchYh=G:{7^+(K3V-`*r:fN\",\n\t\t\t\"4NI+1'KkL4u,#{IDd(8p+|$@Q>sGQ;'T[>:skE#M4G7B^kOGP&~L5W)`DhVup.E!M46H{gMN+]THBE/1&.j>)x_a[0S:Cov+^]u&Sz/44.dqrhwnJlxxpLge!w{3%Ha!%4{\",\n\t\t\t\".I9PeehvXspF[F$??y]9*V0Da/~9kfR-%sg_NA#]Xxk~gJ(2JFVOd(F:H)G,LTuD]nY7weQX%'`M]sn{Q1abJ,J_KV{w?/.!I6SBb3I==k(pzLJ(0o$Ih35I)JJh(jdwLS(k\",\n\t\t\t\"*F=.dZ6XliY}&(4]/>7en<4)&}1)Yk2%tdSgZOi7M`g|D-eWdts32qTEnwEciT[1[mixh814UhZVbCc/eyiMlf<P:`hMxf~`wP><%l*pFpj3A,Uz{}zR]9/pWZq_'|{+lsPvo\",\n\t\t\t\"'c0|-O$kHD9._=4.EXU3rQN?)jM!C$%])y?0&TQLnGChYe1n(txC1vYA2L'z2Fx(#p2ONeuWeUR]N?uoLNKG_kk7DA:<v9Y#4[|a]h?eXDk1#TTWnDq+EI8WfPdGsF+woh+(]*\",\n\t\t\t\"%tHm:f~UE8a({i;ikm_%*IZyoVGIlQl6)E'S|E7,mO|Sy|g~&sXWSc3^atX-c_@2,g?h9w%Xax21gl4m}3k?ZXn;JVDh'H6A~D[Oc}S0wcI9X[xxR!IVyA/+CX;rwO/Q<F2m(f.\",\n\t\t\t\"$_r)|9(3McJ-d$423`!PiVacGmd-|wL|2TRIOvq&4>j$6PM!{pWp530Vk/pj9K#-J+MUCyGf%s|*:`fL)XzifrJ6A!Lur(>mBOhH_yW0A0WW'gC|iX;s]hv9u[{hfLp]9S|PoJaZ\",\n\t\t\t\"#oR;uMX=U1vgn%6nTONc7HP;wsY5|sj'm>zI|ff>V&U@ZW(S)S^%~51fbNUoSCQCMm73(MwEA{>5&,!L[:i%HT6Yjoac;Dx%K<=2{K`)xm/0:9:p9$]FeZ,M2^0bE|B'>3JX5hplV\",\n\t\t\t\"#:R)W$kuhEe3d_wB{!Y9%-/nZF$yNyk]o71|Uk1(2`Qfm8>g6Y7Wfzz0)-G8Vh%tqC$#mvyeE]-kr/W]ugLvm-y&HUtC^&71L+JG!!Z>U,}5qllO4?9`qnvKB+JHaCS!16I}8k5bBs\",\n\t\t\t\"sy38-RZ3/aMN`V6#v#QS]a5vnCRk%SMYn)8W!]gau]4egu3aCsW2T0c`J;`o<|v<<VC8`@!SIi,x'4lTcdbh?$-=-2EBPl2hcU>{+:m{Z%mFZbNyC'ePuR(@lE2DLSXeSTeSaa^QPk\",\n\t\t\t\"ZMhWciybNhr1kRtD|1_b<8Ax6tqq84EVb)wS%t-W^~psSX.G,jCrYO7wj~DwYFZAqLeR(53?h+g`INo7Gm$lCWz,209vpKRHUK:i/FY_aOWDl.gt3|wCSl5XWO0Fvh1o#?TvCp`4_7V\",\n\t\t\t\"IWy*`0ug(-b!Hu}e4v-W+y358)Kvnq#M_E)o3P=w{,-ta^8NI7sALy>QPAq>r!<3xS#it4'Zi(.eo_~UqS)z=}FKPQ9{d.~P^K*~K`fb<FlZo_<F8Vs<iA.&q=e_I,lq&DP_1iSco94:\",\n\t\t\t\"=s@WG606c{xgI~7*0!PO~*Opu4^+m>eGcD_^'/tf_Jr%QCIH>WOKnaw`pXz&xMbI(=+b,nt+qJr*+-TjK`Z,sURM]TL>d|[H[#(G`zF,:okg}c^(&aI0N%Z.`Sg!OI(X'kgH&K4MhLR?6\",\n\t\t\t\"5dc/|C@JoStGxr~,2i;p@;M.cezli},k%lPJ^o_A)^e}+p*e{(3k^*[[ZrGU]JU^Ag?ReXF_@$=6rUGrP#qR[q0^,Gp5$9IqT&n29ic`r?==r@^whM:ipsm2%[=s`A)^+K/Z4i0Z[Kj!xV\",\n\t\t\t\"0!RU141:2FQ7b-=QkN5lDbJJQq|S.[?N*0)h6S(/MqbBopgx,%e[!,YDzlC&{HLU',BFiP:8*!Q~qb8T!Gm[]Lt}f}Mru&:w5-16h#kvG.s|N.H)'&hYW)Zr%ZSypdd;.?S[ewN7CUJ|7'F\",\n\t\t\t\"+~Oy!c<ye{%@^P`HAFbH?yd.U_QPeZ-Un=#L>wU_PlYHx4I-O4aTY.z%cbL~#g3Wfxkx2.,J(d({fC&|~>Gqdnk+G{XFMIQY1Z1XAZ,qASVDt9j/zS7L~6F/jkb_QL<}3oQEI|!1s3,+]9QN\",\n\t\t\t\")1'xJf[WHGn}?ovZ(M[s;tx[3Gk$rRWA4bx+Yw]Xr>?n9.mssuU^/bwCos?]N?v9,@xow'95f>y9=t!V,S(G<3Gnq7BYHJ);&[R33!;lE+cPcR%jurr*LJi]m4av[qqKQjA|}#g,|MyfNA?@J\",\n\t\t\t\"'0MeY|zpcPO]+C}p[ScFIWpJ}'laL>}CR9LuWPtFfm;<bxFzP-K`h&HVtJ5M1wJgox/ehMdTdhv^gye}4A4_}vr6W7V?N&/C}duZI'Xz`HnaK=b.SfNWd'k/nYwtX-4`p(*BNE4`_K@)bbz*D*\",\n\t\t\t\"%f)ZWb4.HR#3AQ!}3/aNEJweg0ZI~D$6B}q1S6pL7RMc[?wc}Ks:=%PCcQVVlwXTW4/,6@DP?uX-y`DM0]F|)#Npx$HY2@@A@b~_ExX,8HiX=@,Ykg9aU`K~R>hg,+[}h>O(6r!!l2<HdY:Y=c2\",\n\t\t\t\"$d0Q?B+wWpn8pVU}Un4f[-JzQN?zhJtzI^V[%X#7>EIJ4C6#nb:.:Go2=j+UH[$r=~|Mq#x8c%Sz;Fg&E$`FwHdbnSUp1:IjEIGv[v1Mw+lg<aIzH@atHjwT=qI39mm*+!djVLZR?9{i9t7D@nu{\",\n\t\t\t\"#|f?>D1?`|Df:<~jRYwxGXRF|~}O=^(.6)(Ge'@U,83J^xFhoN&6(.O3710XFRLB_o7`g7!7?#UYi>Tl292a9-R:U&jIJ[cI%.F7'D;Q)|XV/]J~X&!vZ$}%T[_pPCBXu;'*BmD&t0:DB_Fd@!a-N\",\n\t\t\t\"#K-M@%$Z`Cb@'K>+z~C&~+]I;Y<~,DV)#k#pvMluvyl1Uq#E|(zgPb$_NaB8*.z^,uf~6goZrJdB9ZT5SvTG~SL#MJ^BV:Ua;(mf=!5/N4]-T:|O5-eqUKP5@([-QHtM/_M(_,+}jzwE,d8<xvc6p6\",\n\t\t\t\"#'y8SS*f5SdrItW5ZAgEzM|htCuqTLG`5S?LGyJfQ0Ez6^dkIm?<AN.13h%{}::'N731(S=2q/TOC2C?1U#g!IFIvE|F'<Q'FnvH2FTcmoBZZLlWWQG~y>/>S{:@;Rbp>b9ejm8?1-{DoJL8@Yt-+IN\",\n\t\t\t\"kC$'rcIg|P!GdR(kY2w_W*A*K9F[M]vO3&t=}I%mf08|r|@{<5]fy2xRwQJVe+*b}L0:AWdvVtR?Vi}AifSK%7b<,|n_sQXFAu_A6b:/.''?D@V#BkMM,@N&;ODqLq1XP?I}'J{T[r`D3'pezl7^6({\",\n\t\t\t\"Wb?|O-W}`m2#~)URv`a&j4~npK{Beqg]+!g*`pL!XCV_IDa&IxAoB&LQt;]#>wwen?HS)%rSJbR'GJ!&Hvp;G-b8,n'izx__|1a+pU@+k`~/rzMI'SoURS[:`_ezt!mm)$]]34F4!!KkfdMIC]/F=1Pk\",\n\t\t\t\"J!CDyVG#XcOnkE;-c<RE'[%&,M!m${C='`!Y$R1Q[hA%D/34uyM<X#QRV3W=<]p_+y9N`(<EH:*hQnj58gQ|R31b`^,w]?a_Gq=q'_wmDx2EuNX1UhQX`}OG+JP~+$pmqM+G1MN{rq}6T=_1Qe3q$AN~o\",\n\t\t\t\"?xq)>v8vOf@l`9oGm*)uWG05rKQyNqQji/a`1acf4AL?hJ*q?]v97!~5?^.XsI0m:oD770_IUuMe/{iXVLl#S#X_H+:<PB@&Qx(B,-{)>QY*9xY{Is2hS)!lcjsc.l?$l?/h78KuW}8'H!8|b`r#5wT<]*\",\n\t\t\t\"8O6O6|`gzc7![)&miUYasq@:fY,}e+MC#o~~.[gf0aU5P/Wq`(m6L-Kz|N5D(:dinev11:TF'c5FHAS!m!QKwo4$i`4%u]bj`6>^$jw*v%#2*QBKI$bk*W?|^_m*enz|wsoOi%j>?&PB(Tk.!UP@^bL:*M.\",\n\t\t\t\"2|<^@&/r.y`4N%ph?-'xXSf`-k>fnliC80KQO44BS~<xS^5s(8a$U2`c@o23mR(948HI6_Y:CrpIy4-{o)5Ux}V~rmNjvEf~ymKd`@t!{j$-*z&n[yIjQO]qD$U0'lZ2W3%sLMMrT-KLlk+&yE7_F~;|nr,Z\",\n\t\t\t\".qxph,NAEG,gz7x#,gR8y}^?vd{'1pzmJ]^nC@vss,h!e'de6B3t4vY)^42jSD}ey.N|Gb,Y-f]jEfyCOE)Q/m.Y22WOp;H~YQ|<JfZ),%MT56&jdAI#72K?+9=.Yn|x/U0YtPoOfY=tcA5fYkfkMgY_#G+[V\",\n\t\t\t\"+j|Fu,mnMb[[_I7{AP%`L!@GB->vOZFa{3PT{+&nZ;{Gd`CqZr?hW1%ZR3WqcpBQ2ayi}RE+>:&pLP5:rp]Qt+eZN[)tNwG.tAIztFPvVz]K~$@UB.o,6[iXpmKX2#)[+}0>:=H.al{0h1nA&|3w,4z#[PH;:s\",\n\t\t\t\")MQ6zmK`vZeC{H2Istj')PMbKVYeF<eM.o),T6DO<!&Rk=vGIuPYCTMY>czUhIjh?C;tiQugSI6|r's}rGh{H/(Y'a!a%9lU.n_:}Vf6ro}[;X0XOXrsl__lP1?lMroE|xEG0I:~UmEK+Q?vqsvKro7FpQdE.$k\",\n\t\t\t\"'fC;a;Ted#3(|RP[*S{K^RtLZeavB#xHv<|{RQpa|/%b|_tY?>Q;UtC4,4hO,u9gZ+@sd83Odl[=em=7-^H%*HCE<eat.]&wmMbV{)y@-9<%[Xm-8Z=Hy2|2<x57P,/;o8hZZH;m4pmO$M!1M~4?.xfK]DP#'zSV\",\n\t\t\t\"&H16w,mmofX[4yXDF.}Na@CH@^jFf,K}>M#OV>+R%0dS1M|`Q<yqyun1|8?Sr#xBau(!bR)MKQ,P>>xKRCI/Bxl2H4P#y0gD+}R:r+UeI$|[s6lHJ5>;oA~_=IX*#/U_t5tC?}%vd&R#g_fOENC_d{8:B?%AX^Sm:\",\n\t\t\t\"%H*Hw<Ia]{(CEN=TN%QfM?0^,L2@,wOG*82YV=;@_iZ?p]DnnO_l>fa*}/3^h?G.XH+d'Q<z4@6{x`Y={B=H?e-OthzW$!&UZI{2Un[sW'Iz*X^Eg`F=3YU%T9SIc8D-jiCOnjd]49t6)CI{/*i;W[@`:s(}ydvSS6\",\n\t\t\t\"$^s.%XfK,2Us*n]WU'k9Y>9Ti?20]8RxV2EX'=SXH:,X@;e|.Sb;.7R7wCrll+HHJ|O>jw:!P5[i?v'w~{:MycsG{*[}8JgOsqC%SL0t[HM}i41=Jf}')SGy@tfqofVg:6&Q|w,#b&/H'/.gM3>HqO:Aqi&$W|U1wGV\",\n\t\t\t\"$(,3<E-seNZ&V1R_W=Spc4Br?Rg4?~dFw$an{FvyZMra{{gqA9+.X|vAGE<<L##Eo!CMQ~!e?e,,h3=K?<wT)|e+z:%2.k@VLav8M|,N@)/ROo']/KQ1P:X|H%Po<NFFj-+%U729dyXh,-~=2~fTYI3|AB~u_PcH-];F\",\n\t\t\t\"#Zl-GtX['ct@ch9KkiOLP]77.6VNelm_SNNJdW.dFGXRP%<TwO#K98r$NfUG*#-L({8o%>XZF}J|D?E0DEL@v83NC.L!wex96!O|5QQ_*e7RG=j-Sj'o>2*{HV<)GOwH487evAZNk=r-T1y.=m,&Vi.(knw@I$;T,58^N\",\n\t\t\t\"#:wmn8J6`[w<COAVr/!`3[G5V}yy;>2<UfHofYl%Uhh;t&1M<H$Y7q(hJNy68M=yQESKE)T19)Z;oRk9WWNe4{]G1J<_oCXnTy`%GEly&XLiN[K`H<r^Z:9s>Bei|x({E(Aoo5T{_BYg%2Edli_86seC(U~'B+>1]FYq$J\",\n\t\t\t\"#!8/U;c]1nFCeP9%:a!g0~F%q3lXy#KH[k@uUwmEAGJt,wmWt8L{MMQ7Sr6'S!+L<z=tFrp^:'(^49)2fXPqLWd#<tHob8o^:|o9i]HcFT^;,8tDi#ES>'='m~au8*d?Dsmn>#WSWrgYm<5~x:g=(!gS%3/{L<~EgF!1s$*\",\n\t\t\t\"l'7.(t`M4Y7Tk7XzHdB&z`(SJ>m?-f(bJ3{6uUJbV4+;qxH#UAT^aB|4zph0r(2z52!]Vrcx*h3!Z_<rw@bUdg6]B?6M;XK2-I4#_H$8s0Gjo@2GGER/F7/o9]Y?]rb@50|~5UVv_o(y9GjTwNs]nvw4wFBw0,{Gz7N|Ec2\",\n\t\t\t\"]*=2VfKD12h27;a()?>O9fOx5@[2,TyP$:Xbhxtx]9}xp,-;&yi/Fo|0eMDY-50VUl)QoLe9=N0ed/1!<Q>Qoa5yto%M@Z,HIoStM+YJw;?vva-.}tFowDB#Wr/t14u4'nx%h6b1]XMVEMJEamjX;v=/<Km3>$S~N[5h)9T{\",\n\t\t\t\"PD(W!DH&6nUOB'l@y{vk3w^|[rZt.RGB+rS=m~CrP[XY#LewEHqr{I.3km60z=fFEG31N:tlvhC(A4gEa;.*grU~zK6AuPX31.+0r*;[a[19~H/h~PN8Gt1hlA=iy$7fJ.N`bKWSCL{v&BJ#f8?t`zjg<V(wRRU>cbfWcVofN\",\n\t\t\t\"G0^NuhwXa4w~)jZ[j*{E%YMCaa<&H.}X945dS|w^g;'GQc<-.a(E&5g/:ZEWy?abIifub!S|`!&]&AZs'ePT?t$6ZZCB`UI@|moZ75`Sg:_nG}k6A`&9<<^[>os<kF;0F4qe2!PA^}fqmcypQwv2)hC`D,*rEqHAm)uL_I;bl6\",\n\t\t\t\"?u2[Z<@uQ{/!E3#STHVkA'RhMEn,'e@y}aWko'B&:3Mu?UVS-@V;Ink)`@yu]:~My@|Xiz7rP@fa.GW~DlD=gKzDxOH{6fATk-UFfFe=>_8Cqi:zL{MP#[HM'6ob$BW-(@;x[H`}jv@lWTdXKMdyZ}mK=|=U+*ePW0`AR0Kuy-N\",\n\t\t\t\":.{n;Au!==aW_~~/31:%|ap'pU+C9#>Hlf;h;HKs)1CYZnJ5ly_+@AM%,@N`|Eihs-c~{A~6|1,M1cU>*Ej`k:&.VOu;t)&e~~#MjS5,jIA;nB4^V*|T_F_z[-,A5}jP/_/i~Gc;*(fL8p%0U-A},qRIs*YKv>qa!y19MO~^(Vy{\",\n\t\t\t\"5VN9jpHpDfSUTBca)i8|h}_bRyht0S'H!{CRO9.Sq[efz^ORXP8zS}x8~;];v@eD^HGNAle,7ZI`T1NU4Mg~{W(W-&M[<h|Q*[l1:/3!'g*aYkfa[REbi`==?-PzhwO:%'sXir$}=O}~Cs-vr5YyZ%qZCPzPPnFZ8h^fO~)wB|dyk\",\n\t\t\t\"1x3Vt~rj21Twzr|,,=oz8EPC)V[~)lB|>thqaR,X?GC(h`u)I7K/BWtaGwt_!_vcA%!zerw[UCYgMvE,KBX<%m8unQG2aTCbOqNk[v%}%`]IH]@0n=4^G#}`jdM3|Y2+n|TLx=~d/y0fqc&n,OZS^]3Z,]%Q#hQoYNX|b)e~?PhY)o\",\n\t\t\t\"/!t6rJh<$~fBmH<nWA'=$:;%E'e`;}v/jOSQ^b4YA*GEiGrK{~4fync%3;JCq+oDTJhIi|)u$TC>3!qC6a=d`ccOA,!aEI6XA~_W0%S4,2/KseIf>8eclVHN&a91=uADU2|N[-*E-xv+P@9xHT7&'w$DxgfW?nOJ,2NFOCcY@7s24]*\",\n\t\t\t\",`HDkC$U.~U'arpO^7jRs]noo(UES(0LwSUbf@#+JSp0sfGq{*b@i`n}Rc|9>Bu>_NU>#_DG)%QYR^a`od5Ur|x8lyt&]Wc}f{b5}c7:nQdLrV.Dqy|XUCZlrgL-g6uyCW8pg2DC[0qxk0B'!tA)s[y_?}xR`VGm$0pPcPn}g[Q>oD5.\",\n\t\t\t\"*jji4DRB!hfp?ZuKi9k'ac`.p6,[NI[W#/?|N!'[kkltdB+{[9p^&~s7_[4^)[[|S.)s+Aou|O;yO&xEZD^)'U#A2F}V?iqsuurhiF.N!)7K!t@^-LGY_n2cxwvAT>q>>3go&'seAX~WI2)qxnX8n|}*:*Xb|)&mR<;RbxYd<}*fg47TZ\",\n\t\t\t\")9CRIedE3+m?Od0R1]irO:W=/#h7)Lh=~{KW0X0f^g9XrRAdlZ$z?Fc;x7j8Sd-2|g55F$;cXNhs/mw<s,TQDSeWsm33#3(R{,Ob8`2~@{k]$1Jwe-yT'`c&x3y(O-OmpGPhh^LrZS6j`?yx4~7T]vdtnje8zi{@=jd05}`Z>IkH'5kSKV\",\n\t\t\t\"(#HoN7l>L4n=^ANA(IaRW.G[)a~Ba;X,w{e8v8clkID!fYH+5{|xDSS$uC6syF88!9+a9ih_egHrdO@.;1*{d8^F:zB-99jpxCc@:X8GEVd*'&05V`~33r%m+bT'lN`G[k|`QHd|TZtk4GW^DBSQ7e}K0muStmgPPmt`.n}-|KkY03@5^2s\",\n\t\t\t\"'!^B^p',7STXpZVf!2wPNs!z53Tk_-^^pl8bur(,DSd-'NfF0GGO+'=a2*d#8-^Ja>&jO:J+tBeaIU&^5e^11z{f~{ytN6ul%t.p-3yu$VYB-tfY(/oPp9aH1j/L26}w{'{scAx]z8@zK7[E8yMBe(HyyAg!;ccXrY-_N'@a!(&L(Dnb/cTk\",\n\t\t\t\"&2pjLw&NC{giV*juxwZWN_}/[*!%Ti?4@;z]A[]Dpj9h%~qj1_jYBnxTzo*(yHv`SJ^O]gr5jV{)(e2zqQZ%:t-CG+(Yh5K,%+!AAf:ME/x#fovahf5<|:Fw<oGcpve8n:[p[sThf_RUs&f:y}s&3wq/gD./o>3xtwx!+ir<@IB.*~}m6WypV\",\n\t\t\t\"%Pd*8Gq8{;atxi@9$8q?&?f#T]yuZ@^,6'54subP_v/fw,i.Z0|wzZ0C>Kyi`Sc@w4kUsL^CAlKy-Jza<4?pk+XHykmfao.1jaLrNOiidfXW`_8'_xjQkzN1_rC`uJ/>xaq=>wTY7'HY4~2Z=_Cjmj$4EIKc4H:#w8[*CKrh]7C=.S`R;8jcH:\",\n\t\t\t\"$zY+<nWAv5i;5blo,oAh0F/w[:=L@%K1XC1Op3Li<aDJFGJQWPb8Pd35kPWnJjUL<|hoHVruU)5ikGU6/s*|o1<E4Co{yhRn*>[C1+$fD0@A:1Xw^.m}j3NJ+3vw;Z.`WIKy!ZUBTS>k(y5qJnaw0X.)d*=oAk{B{qJw.+10!m$m&4Al=A1f0h6\",\n\t\t\t\"$OHucOmzWj'k|Jum@9Mg64h49fO.<8K2<m;z`P';F50%ZrwSiHx2t1fS[/Vx'G~#]6GA%x`QVa6/'%boOHc2U+4kXCnB38j]ff&7PfpLTCa*EDDM[*)ry;]$,o~vrZz=bw}CYJE-~|}^ubb6O{~]k9dB5?uW^F&MIYW@lgQRYK*zVy(Ur}2n4vtV\",\n\t\t\t\"$,PB8I?Ky'%q[q^yot]_Sjm8Wem9n=BQ&e2OXz#}<O)5gpTR7fucCdbZ[yh6a&xJkk~&=V;4!Ug,>sKDH|YQ((c@x=U6i@i<'U3B6.HtIftpsNF:xp<luo!!'9k94a}G=fV?[h$lWDCO,o$A_eWM=;n#/Xz?=4K<2:[4n0miA1kDTcF;`JNr~tbOF\",\n\t\t\t\"#lOxX(0q*A!6x.j;!R'WxF3pC=Vx}q(RXzrm,&EyEr1C[a|l,QZKf|+OUBof`Viu]gl8VQn<AoNKCcc.k8N#rEuv.2_}on<_%s1=Co/<c>3t];!V{']M/*&jJRzd,?ZiD[x%.`[5>`SDpjK<WI?N}Mk)wf2=03N5q4'uc]xqVz/n~:L~GG#CjO=tjN\",\n\t\t\t\"#S@AU=fe$SHn]yzn6gqIfj('27i23vxet%fC4Fy/8('5p.1'RED9mctIV'Tm]2H0BA'wCtJza8k>&&JC67wZtn$O`4HNixlu9xHK.(z:4u'8bq>f@NUXG-fktAC,m[8^t1E=@58C5%_n}I#S2-C0:]*!fx^]k$=xGXaEyh7puIJVR*34^DXH(ArqLeJ\",\n\t\t\t\"#?-RrehybIle8R52XUN-S51F3S*IX;?(cBUR25Uv(_}JP{?OI:P~2L5>LNU-Lb8lqf~mpkvv/s[m7_L?ov5Xb.(7IMSaBF]Pm~Wy)+0k90csQ{URTd:%zd}wkT3W87xMd;zJNHBFHH4!^28nJW0l^t^57H5^o%0|{x63}4rm%'<6!=@)(kWl7oNm3Qa*\",\n\t\t\t\"#.2hWTPyqLPcf!YQV^I.ok9GxDNS#ENgo(8{r198n0M(gLp8wZ<-4F4[$mmI;vfrbKM?5pK8S]}6jV!a;ZQAEKo*SI;IOQ]M#-{.;=[Wsn?Df^,RUEX#IC6Q>[~UZono|L'B}Ux^meu(F6#oSkphejQU+q57hm(z}<s@oW$+VU5QBl6Rzu{zpc$B?HIc2\",\n\t\t\t\"|xQ<OktmmS8Ky.b)v<(=>^0Wm['.76wt>X`B?9)fuW0)JoDfwQzn(MAedlPn}ec'Ce:7a>3(6)6b+)SoL4&)trtualfml=v$6Q5lVbzlhb0k_f=oqfzI:7n5Qg|y58?mJ$.$r+{^1#+cDWS.xAd]Vi@>+##Bsm8n`3OZhV9wiRT(lpHgT9iqZ5#m,(=4{\",\n\t\t\t\"pv*~5&:|m~ss@H+X|H0h~{XZ'oe}VR1'N#q3fECr1p%l5&j7c(WgI8<TPL>0Y.X*P6(V{e4e-[;x,a/9).'tNQ]c;kbZyQ%kYH;(3CaS(rS4XT~/e$[x/~#mgDoxv55I@s?CEs`*^_^ZbY/G3zD.3SW]a_c?g,j}6~]5?9kg_K#~J7>L<z}i&|}v'Ns~AN\",\n\t\t\t\"fe`c<@@ER5E?wAhfkO3jAKY+$anJ4X4iu{h![)lqYWaK98]!ZrQ3w$5Z'e3$5O~c!S5sMta/lpI4&8G4.@DpF?inWC1dDbZn`=Bz$M!;|8G):_X:q,/`<THEO5oVfJAum6}lHQQH$Qy!BUHe~vSP7<C>x@ggqh~Sk5+BxKu5ASf(rr%ls8ZqR;J:MjpD,h6\",\n\t\t\t\"^)fTj5!q<yp).wIma11RS7,=?v1-]iV8-fvs0m+eBTCC8*h@;I-YEXC{o#gHkz@CEz2u6W~r^f9'Rm8*.+2OQZzpIUjO94@m<aJY`|~ynb$Pg.R/j+3,DnahKN!3FX1:v4lJp_X'<lp0a+G{Sc=Dz$)BWqF|W2vEJ)NJpTmvi[+pa;+)aF9rM*g)PO-WminN\",\n\t\t\t\"UevaP{tsZ_IsFO.O,DrTETjhFk[Wm@#Y!IL:5t/CJ+eq+HwWl-OYn1Yp8zF$cJbFVw(rVM6A6xm]~:#rxW;mW+z:!>bGh%#/#>ZFPr`6eKpF8l%*tBz&wG@|yVt-6LFUUS4JuE,o@9&hYOGjJ:+<&o>nW);'0BvR/iWa{'%a/8vU/=}t$%p2KBHBS_KjSy+m{\",\n\t\t\t\"OJ{`D$g@95?7dOu1+UxJKIgk:kRZ!I1jiWpANY{$[9.BWkzDVt<yHs?dT~p^m%U@]30Q$-K=&?+OcjxOA(?:`_C.LUElc$Xr75ZGBVUiG/)1nQW}?5cWds>+D'3E~zHE|.a&M#$F:/4Gwh3-y}IE]r@A@)%/:^=NpD^*H2|J@TL~@G)gbvDQKDv2lI!xa|,2Dk\",\n\t\t\t\"J($ts4G+1>s:%rtmu!H*(UG%HoXPAR0)(c(_mDXZW?c|1:i*0Vq!gS2c[8heGEh?-KbP[k:A=7Y<M:IG/-5F=[Z/s/;:tVgk?,$|mjYbv1fF/t[di::Kp%3}l%eC}F!RGzy/1BOwfTA#}?5$`|StC$^Jc{b(z~~ALPw/[~]WMXi+>F=3=,MXmBvf](f}cLPHp1o\",\n\t\t\t\"EJ}~.I!*LesVOH,}'d^+y`qqHU0B2?<MERaZ_{E=yP&9ZTn/lL'dpd%qR]gmH}&(Rmv#i7QjV'1PgKnddXjj%sb$e3d5a&llD]q.Tq-p%dOn@F&6+Mw/Z1zfjcs:}vW|&]9H'4A<qs;)62i77F$5O-)AB&<SXi]:Zo>[U#CyBl|gN?D|eR~VD2ZvGsOlJ.W((m]*\",\n\t\t\t\"ALzX&|aT.Dmt`:~9xe7&fBf0vx+D:ZKNp9l9s3B%96fh.IXnH~R'an0yT?8{cVUG>0XF[*O=;nr[N(,tpq3^H(Aq*!h6.5%%cySP?;?bY4nfEyJ+,=rd8?9Hj[Xde.|Q:;_VoTV<;ep'T5kX4z(,.Mq19>c@y4VB+`|$}TF3,}ythw$VqVpMZ%N1^o*H=BMmE}vz.\",\n\t\t\t\">$rw|!m?2><`[:&M2C~i(d+iZMYy<dI7Gv=qzvvp*'G:=TOy3Up]|&o;(sc,se!5o>^kT~a!HFGqZVOGonQ7G+)lIYGe9!ys=Y!X|GJ@([iWe'e.QQKs+V`:^Ip=W1.^~Wg?y3IR6YNWV:qU`a3naI-I9#LK*}Z&Et;$?H1fgIcYSl:pwa{8uo.[0$pL3n@<qanU}Z\",\n\t\t\t\";'3^il_9O)ZDc7b@u'P(0|&4WuNdD--=?b[GdoBj'qqswyT^oYv.`UmEkrBAEM0/[5q>6+,a0._sDs^;XCo/_JkgCae>]9E^kL4=#?6u}QLcBU/{s$VYuVK'jbCF&+JEO(a9.f!./=Ph5a2votzQj8|(KMg#bSQZdU*@eYem{leJ?kN8|$&xqTYg_vrZJ'::'Sk./;V\",\n\t\t\t\"8MZ?;{+LTa;B,{[N^tb=&K&xKbuz(>oY:Y<BZTIC]q@STh_a:_>V>x}bA~vEb4S4zw5+NYd@e@*e&Y^?NDbUGqb&4VYj!kLq!z,f[kb+h+a2WC#>Y1kRt0`!i|3A'Pvo:Q]O@(QYZ}/6no[T+rV'rx[(}cZholzWm|Ykw<&i,u>!DK=rKAa!}9c-C9OLb{ag4sPTfl*s\",\n\t\t\t\"66pK~$<x#nX}}G2ov/*D3nSu{O&'w[ZFY5x*{9$;'v/}Xxe|{#?hzRC;%-Gly58=@)%v@p#d&&gyd520|(?>-P3zl%HZol(aQGhI}>_qSWGlV(@'ZvweZd<TjH)ovAS;NBc?[P<YJXB1JFxJW!YbG:Xf)nO#I4|<i_8)e,#>z_riy,T#AW=j3)GUI*5!pT9;Gj{o<E7(k\",\n\t\t\t\"4:J?]u@Lll<=)L~k(&DLSSq+oVUGVl@]Upgd%0l@&Qy0w]2&*OrS,w*~B6O_F?PW.byYh'vU,&1bQMv^*Q}P7byDt-!F@Y%RTkj$4vv1+UZNui~~>nlyjPzdgbpr&}/kK/RTx7PMBbl6)~(,JhS}gu$&./z7d[0aa*!Z,J88am1FfYk[17~6l;6Se5y+#.k!}.Qgu)X]/V\",\n\t\t\t\"2T_]&ocY++_6VV{$.GzkrjbY1+F&}bWvhUAEYmSKj}}3{nvy8J&U7QAFeFgOONyG/id2%p^Oc[WLC9XteY~by)UK@X]1{=TdWoDxAUvDE(}T3-[(jEt:o`e^OkdZb3z20;$%4t;l1Zs87l+DOV+|IFMZ$+7|DqL(<s-POEg^]nSL`G)Re1t?(*#f6GlYf`)O^;mnG2@:f$:\",\n\t\t\t\"1&AaeWkkM6l0VZnBT7qOB)A$@*:T>KfPz6#*Kk[pOe7SU19>JLD0um!fmCwL'US+5[Ss=oW/BfNi;BTku??4Im]ip9n}~g2D(Dtg@=_.AMA-:|Y{&g}ZfdXe(5;`H//*Ns~ca3SUeOhz])%cbr]D-;qt19pyJYNTH6=vl[QX3*msbQNp!,gV=F:^m8KOz,jut_d#ViZHxE|6\",\n\t\t\t\"/enI@^+TreiDlM6uffShI7yAj.F?Ow+P',EXBy$^OF#Gom|V;~AkwQ0zKG!cTI%jP~#luZiKbLLQ|sG;?67y-@S;Ty9/;v'b+p4zu,P1LP[E%u4efl*I%iZMt#}U;S6$@(1=>h*imkBG2qdJ:pO+y(Q~.g|~+?FFe:`gVa~]NaFyC!eHkV3onN;L{Q#1ySeHB8pA@AWK?r~CV\",\n\t\t\t\".Un-RzOkdbH$-en3szwY~^Af?hTU)]iSk.4%F*@[*ldxO'/W6%nhDF2SPX^>[U`fn{y4MEMYOz:$PB6u';8T'*<L`*'c`,;!uJ`kb90#?|$hYmUJw#UdGgnfJ%!)H}mw76#*.)i,'scblCSMS:7b=uz={5)~Cr!N&T}L/.pMt!.Ji_+hIw4]iu{dqrhg@DV5/Ul]>#X=.]9FdF\",\n\t\t\t\"-SG;#)fjZ`(Enb}`}W*H/VxeQa7Rj~jTV^PP;O&Fw^'CBHG[JXYeYHZ+2l7;G/G0ct/klpDKpq|CcK5jd>f,y:g4TyAmIPJFh{x5+HT]1tKy*|vph2kMRx}ltKn'|@Xew!>/sE+k.a@e(hDOfe<%j],euH(/`inABzDnZF!dAJEmln.F_WJ'l-92?-|zgC,f<S0lgcxb^9E{2vN\",\n\t\t\t\",[yX){E~e9S4jvQT/~Aakj=uo/4@*gD3,V*D8ofysX1>Ae-xXq,}:rbT{,HTIo'ZMA&i_DpHO%Q&Q7>>xZQ*dTP2_`oXz0(cO$aM0d{jeNH.?(5F-sg7$9KRkFr)NgGC<3M`Jm(Xs&8]K^+9g^;jSj-Nx&dK|li!A73VXF;'6yLj_Mb8Gk-za{wT0MW0>&^BwqJ;qmQ)P?H)n1HJ\",\n\t\t\t\"+o#r6Pnw$cD996'^:%b$n&j,0M?G|GHN#y9(1k[niN.7ZpfH|<wMH*eU.N9R0(T95(7WaL#SfK^0n_c&k7#/X?+YFj|iv#^p61D[~(:`Q7kFu$?VIL7$knd(Hl`-qjyd{9`b?d(m$*Z.1z(e_v:UE%@qI#nj^R7%F[Vb6&h'=bPn%8TCgA;kuuIV&)~u'n7sC~KIG_XP,zOl3.%@*\",\n\t\t\t\"+,JO<qcGu5bN/#%H`j}_DKpe09'ECkP)/s@fqz4!]J#AX]&R8f=|/TKnL2#=XM[1YrBFU^E94/536qmN?ZE.[Dk4OVT,l.++@m+I5tT$nZpWbGo}$o8`0/*{>awt)US<.8{Junv/Ds8z:iZ|^q}S:CA[5,$<CjRW[y|cN9<oU]#&vG|hxvc;s:;FD_M2KWH,TkW'MZLn4?7Gb6TIc2\",\n\t\t\t\"*N1[!]mY?Jj#d`:'`9${KbD!(Pt7~jyE4/AT3y@eHG-:%kGs:Mj0J(k^Ua)YlmWR2B>vcUR)EL_ro]^uYOLVcGWe+4dp8ew(l'G6~5%5!D$5KPf,+k)/Y<%>#g-v=|*_x=^E}g{Us.'Ru5Rv7VYpB_K_j@[75!Mh+x,e`kO;PHk|X)e{//t6}<:CV{>`)Mu1fM_hj.$>5j|_Z#c)yq{\",\n\t\t\t\")w?e1OFY04O8C,8ulv*]M0'`67yRZ|AOqt!+o<2g6l-RZn6[Bm]%7{&%KH.>Y5&w0n*Kp*zJbY<]-xwLjA>nI7,TDj]Mp?Qt'wUz~0W*Qd_/SF'PMPdPa4WS2aL&MKrt2e$3NxEz{>V#ZwL5Zkg4b--jP0=o+ZIg8E/~B9~Fjv;8YIr!xWVN^9']ZH}FxlTAr|,0O!pw-7OeMMm:?/zN\",\n\t\t\t\")H.Y(S1~@HuNS/&&*qk1w{1V;{IsIcRDYDrx`BO0Fu?3C-!xR^uNLzpl~2UafSvwtQ7sy%RveJkiL*MMeJ6^mlGaShVj6J!_nt%<MURec4bvC^IuQA^v8Dl7Wr]t[bw?D8Nl{z:#Y#J|EuO-?MK'y/@w6S)MD9b@x$z3[o]?zvmv+=35RG%=?Mona((Ta%_Wc/QEx&>0wUIC->&T*hOd6\",\n\t\t\t\"({zdo_T@^?&st*6ZCH4F(nJ~oWkmJ/]-1$AMJ{W;y_xDV:GWu<M1Fss~3n=I<ng8gWsZzn:N3>ah*Z*(KSX67WiMz.(_4hg_f^^%3#9U.@'oFJ<4mk+2HHc&3TM|e'5NEd2=3U>-O{~EAV;RJ%ICi$~kQY8<PW|m$|IPl6vW0*H@~la5udc%'s^/t|0s[}^-q8o3UD'/qlVbnc4]!nLYQN\",\n\t\t\t\"(V4iSgme]A-r)`jW>0kIH_fM7&$}JM-_Kn/mM]Ov)k-Fq*e&ts=]j1Pb$lPO`sO-al2xp*8c*7o7#lEMS_cOUE_X=PL`/jsfLIwAn$wRfY5-n:fl,k:PR8hCrKw7BGgUc3J2plF6!dD[Duy][J0l8MSc^6q#[J##A8lQw9V5=U1#{+^+_UdoC5hM5;)o4{J>l%@wEa=;|e]aeWV<Ddttma{\",\n\t\t\t\"(5FP#L;TnJb)@wYlgh`V&UJ1pfDaVF?zL;Xo*ZfP@S$JSH_=.MWZYEKa-/!|PX`)C<3&}(7~HYu'mch`SaQCx?J(IEO)!<+,kK]8&ev/Y<^{97:aWI3|[y'>)nS4ir$WP](2de{wC>a$_n#mf}tj-'851_),l*ON:j.<{DqqL3acKw*P7!<@63)ek%=)%Jk8O(sd_7NV%-R0osNX,JY=>Tmk\",\n\t\t\t\"'u+diyQHDXQ$$dXf1h6%bbi}zKe1G|'1>lg5DU1{Sd1e-.a']0Fo0G0`+MS7BmEF&1ro?C|EM#)nI%v2<]r+8Wl_!OP2iPzXmhR;K6&P(n(9h$q|dWWY:{8'`B5wD?/?AP^nQo-`sg]-3*~;sK(;)x!lY4*5J$<HtCZ%Z`j6RE<A(wr5NAt4S(dJl@yh}B9k&GwA6LMJ/u{HfioiYFDVN^59o\",\n\t\t\t\"'Y{H>k77_<{*x>yk^IdL{APT8y#~[r`5~Jg1+o3p^$93<'L=iDf1J5n@e8?EzNR;>7D-P*?WL=i^=,,y$Ad0nHhB!]l#Od!''l{!./F,;KZ(G-Q[KUlPN>0Q-YQNU#.fm)M!S=f.qwL@XbV7e+[H6nTB{o+kq!LO'q2@j'n%X63:'AoY||~!2F4k%n(t'U8w]ivI@v,uAVAD@$H`{(9b6o@,]*\",\n\t\t\t\"'B^+L2*tNL3]Nhz?9dWv#IWwdUYujTZ6|@%rY}|6}k#iCD&PWuQI6v]J+2(mKP5zFAz9:4H@GRW%N>a=_lxM'$K;b[q8Pj9HDgQ`Y1KH0g;%K2`yUc+22jKDVDz]|}K-urG=IXP}2qQ5p-R+}AIX:|S8i7rA79D^{/v,|n!qTs|TNdY+0G1$KmZDCB:Vm%NtV(&;eJHF9bJiLignN-[0@]M5db.\",\n\t\t\t\"'-s0fO*o_?61-|:h;mfv:Em>%008;X5kh)xjpmK]@`p`qh_iPb%DcQSWDWZLlQ$=6[JM(Z.t+U%7mGVztM`Q7zCW0GRq`eQ0MP$5!m7thKT0;!=@RRTXq2~!'p%vEQCb!Mi}4QM`cCp;Wa]_1c_l!6H0l54z<*(:5'v0?+)0Se<8~@hW-3KUaer@0cgb&!Mye{:2:6|5@j(LwDM/cuK.vMITUqHZ\",\n\t\t\t\"&xGB9=4|u&BO]B7&R~^y.n#./!R%Xx.Z8yzDO]Uif%k%bBd|JJ8ML'b_&L4jekaLZrkA%lFtdty4,FZ2`V-Ub$KeJo6,.N$!4SW<K*}9E>>jWqq./@)Eqw^TWt<ic@mhQm9X/Kc*+yi!evriT{c0*A8P3'i6N$3C>2[j!S.#zJZi;1emv*jXh^T[yjyCK3;+Yb|0|4re'-HpZdsJ|)C{I'KTv^x+V\",\n\t\t\t\"&h%DhhZhb6@Ev#_3evf|V^yG.M_^y<3~5[JBD*sGnX:u9>qb}#L8-59V-Y]H*62;#TB_Xpul4.hu!cyNOjwyL`[L^A3)>K9V|3a~n)_GjQl;^h|tp)')R/;yr'rva/J/~-a>)kHUAW]:tqJ+u{qUKE#3d<A*aVWtuB2`KzK@ewYYlleW7JTd;eqmB8?,GDfrhV%|o]W$8a4`I>j$xjV5m(Jm2j,f!s\",\n\t\t\t\"&XWQd:?07/|#n2R_%sb9uEk)x^#GPt/M#%s-u1liz!<PXsXW0uuF~Pef2tc^nyN8Vg:/bu=N%&wsEH:_+q1j8oTd5aBeDtU}?wa)/fp[jLO7HB0Iex&ht;#*7$@z'4b3i'UnE5@kksu|ac}.n{ZuT~On,Y#t3bO@v.{teuiGgCDOVkBW*d;0(S/5}5~:tzR*BbHQLfD)YF9ITfc8t+GtMb(XiJWQdXk\",\n\t\t\t\"&Kt>R1iyl{Pe-xo>`%s8+*AuM]3_-S1^LlW}{PDMB#<#+q<E3t(sJ7+#g-).:;|Y)':lcB{C5lT%CvP^vm#rHj~8IlBe8A@,_D]pv`4Hf`rDr@@3h|@/~$*/&,PPaqVOb)=uLG>Q~Y0'#<e#OVID}ioWl#bEPy6e/MXb;toMQ@dhz'wi9)Xyq>JW#Ob]z=>cXNzFDw;5)aCo`oWJH)18!j[B(?M|w#KV\",\n\t\t\t\"&@m<3d~P~N_)x?M~JJ|F<gOgG[_R7l&`$MmdJ1_Zs5sGV@.+]iZFZml-UrV(lgLyTI5X1Ea6b!^)Y$L@>?kL*obXI1/UCRXbbGb6/|AeCbFYs>.&5DE[+jkdf6VAI6o#t[X:}{$x+O{@b.&-]j&Qb%kfYbd/>e'-x^l/2V_Ub.8Uqunjed`TWcMyvzSB<%oAFw9E3~)jQCG5K}3H4O+nM'U8=olN80[]:\",\n\t\t\t\"&77g_!J'DZOxTsR<MpgQ>c!C[DeWJQ7)~&j}ZUTl8^kAg-z~+[fIiM-#E_Doa$1blY2|avWsXD@dg&nwT')C'w]E_MH5o6VrA)@5t|FaYT/]^!FbFif;#<@w]1'w`7/0ePPy`-TqLQT!sa_F/!,d{xL(A(ZX.nItXk/mCpEe0UY8.2<76p1N0@ic#g.?P[rCe>)5_c1FnYc.>H&xV3z:_Qpv1]Wz>5P736\",\n\t\t\t\"&/(WDe4PS<6CY3wE;L@TG30Dz^28T?|K%fzH%u%+Cvhew`k70^]4bUUwLf37JL.jo5^q];5?/JkYX!]B3e4)5-R`p|*Zjh59k`:`Zvkt$5@zpd=(OV(E=HRK~&R(M}(M:JC*~gP9'|mq#D:_sawO0)uBk(_FmzEV']l?EKF(lqF}*'fU&QV9cdI2'+~Ql!U:`v@LCJ2bIg_d{.;|nQ>;&o1zuxb&,h110pV\",\n\t\t\t\"&(7*iQA{mRD@plNg/h$W{t?LBW$3FNAt&'-V1F~@2J<Y*WKEc0VE-JKdos<Y<,%B=.9_5p~hY6Mj4fG~N5NvkIZ6rMzWnUxmrclLBN&gdE`X.RmiHeuvE|IaFZ7iEeIaSu*r5WWMi#D$D@'[3U){`<A{zqXeA!PD~[on5'TRI^'D0ba|=%{t3Oc]PCBvaHQhqBdB)?W]D>wud9m}#M=!ntYT]>7t=LPp6hxF\",\n\t\t\t\"&!]tzv5c.`qp)4+]t4=0ut2?p<X,vU@8R~TX&9#L$Dvw(et!Mxvt_45*Dc1>}ZtDLBst8t|8-EOZt(oeicymv=U.YB}JOb/,sMy-m(z=nRw+mC#cr=])HS<{5z{ewB[FhoAfKB{IH8V@+-=nqTBEx=xUfqS;L4TKnKdg9TsrR2u&LU=$Njq>ZoP_'T!5QL$*h^C>K8t{Bf#wxTo.&24DJ$3sK0I:pZ()-6.%N\",\n\t\t\t\"%{8giEEItyyGh{>Jz7g#CZ&I>/nR{27=qWpD-=w_H:Qfv>$'x=z`Ga4-9zQzM[[)b/pFv%nl7Y@iVzrq<O?#%mTyYp-OW:AYudAM**9W]tN0qj%zw=,l&h$UaA~'Z5{k55C6q-a0cOT5M!l{;ON3&9,v(9lt`@T$iqa`T@gyjofT[=.t~'0aCGI(2isA:)^EU@u^tB1iI$Mr2GsVPXw.-+TV(3Am_[:e/07{,J\",\n\t\t\t\"%x!SSO+~//5`Q4|@j72YAhOb,eU/cj@$MP9?,TjF(;={.lKHq]1^#rvyH5QcuGFd+'Z5>+f6},iR3&`gBe?_1iikXz;:VB|$a1Av]a2vViLo~&Q_I;.n~0^<MY2'v#sKqxb8#kk{joFlMixtp^}s&ae*DgRf,?'VRYfc|#5:gXuZFA4qp6/:Fg8W~)6`.YWmqkelY,X?J4U{Y&.$=A>-y'v.;~_%}DNe#WJ-H}*\",\n\t\t\t\"%ut0`n5]=4(YL9xQIxIts8`F-2NC)$6s>pi<:ea}uKv:Z'&WDU@:'i*^!1.C*etp8x4:H'1Ukw-|jwwk(z@$&p$c4snB<N9gj5cP,3(f1.LfN&.e%c{g,CL8<3y_hx/ggVRFzo`l$?OavoBL[ilpq8%=AYw#i$@L1v@/s|u<wG>9W13E*&i-Ua&a*u}U>(4]K>,XbcMGR^6nM_c,5ece>AVx`.'A+1+}b*f6|Ec2\",\n\t\t\t\"%tqMbjP,)e(VFo~:jq?7)lauN9~?RucQ/VXA0lAPG%fjua)y6hq>,o0E%YcRdUfPwV@N,Cu#j9CbEQ]5jV}?+(P~oCOeE+js`t)Ltu43h,J~+Be[r3,{PjQ=bhzk<JUpNAWI+(L^Y)4@OSUd(hgpqXpHbb@qVLTWE<76`kFA!;?I'HpT>2M-f|y;uJ{a<M@8Z*fff}Vbi5X#d3Kq+H~mBt?uv`mx`?2Q8rLDtw4P{\",\n\t\t\t\"%tv;h1+|!@_Je-oSg89Dw@1@(&T9(}k{Y#}u5VIq^e.E!'lxwP9_NH7NyVS#`co}Vp{{F<:LhXN7Y|j&APt7xi_J%{PYb;<,{B6%M9}lC=hW[o)zT40MmZlR^}!ekBy*iuL+B#,51-';v3YAaz`S/v*UDtB<nir)C#}GIG2g<i}E4x&!cx,&,BMAa{uh`h2MQc;(S]:{]N}e5zmfxngL4YJ0?D=K|gZ50{U|y.;>UN\",\n\t\t\t\"%v%;KXf~<;aM<6CI,N#:Ypv5h4DdU5uX.yQW+K$[}^LyjB~7_gNgyNS{M-%@&<!@I!eQJ<<2r!C&=|t[44f)IxiS7+=)QS]XOm#P7cy1|`{]`1-Y3e#l2m0L;8KN.$V]'T&XN%DYEPG_=E/3=s*ZA'Q2e%`.KUaeNH?Y=ML;hG&1,h?)zFO]_B'ouAz;_(<GsmipHNwF)@'WORd<&baV^d(=rU5X??^ndw^}7)&5o`6\",\n\t\t\t\"%x9'{X)y#eZ6*Nm)7$;^%f!~VF]w-3T1+|A`u_oL4M9?eB-qEMLu[IgLnXqPw,]k3%<S`>03nP<.4x-VxN0jZ@mlcX'WI^?BX!MPHtn-PYX&bZmlAIeCS}EsyUZBItOfmBZp&UC6?;_g)571xUkhVl=<RMXC](8B/m(3F81Y}&[D8d$_J:?(Os7ZRHu7m-k-89UJVn'8~6BJ*1s[uy{zY7{a[!7=El3FHK58ly]OLJ5N\",\n\t\t\t\"%{V/DZIv*!rN5JB$p=z1>_uL!jC_CTz_skqo(6o#yHa0${3uU_5_c_bK.7{/PI*~h;WQ|!%#WcS++vn@y1<;,3f5[#zOYM2-A2n80XQl[>e&7yPCvV;L~YV,L30D'AIaVq&Qc'*:}(-%.FPbi.C6:,aihL9xlGng8yLu#eC^x_sj{5`F*N4]3[X!td(fpakTOwtzvu/otDIHIO0,+yn;5YnP8Q2&O2$N@mkE7:bqyWbT{\",\n\t\t\t\"&#!y>t~PAqR.V%|i~`K=C`P;mtyU#PR!%n1Oli~bOm!)r*hAnb;bRgK%<dK'*&Ikf_etTiJ.Yk,,6AfNm_1_VYGmKP!K=D|%%bOan0S9sTm~4<'jcWo>>g^^VX/&KUzVt&S?S_'nkk{$XraA:IEORO5lOPAcE*)K~<<|DJ:E~6fdk>J-!>Z5sFw1}%/_tRZg/.Xzr:Z+R,XTfXBOb8yhex@rPct$)kWn+TkR#(y~d@2p8k\",\n\t\t\t\"&(Zmm.72gip[0d;F(1gqQybOtV=ke4qb7qaMX1p#}WQ]`>y9[t*PPHw`eNOVOI7Haatl)A=D+khBJ>)@s.kyCtaWrrM8#801>!e(;2$.a(w(!$6$C>*H`iYYEr*!gQ,gXI4DJ8LpK}Ui8EjWl9kL%3dr#UZ8c<>-OZpxZ6C]Kh}~nv_Uy_z'Au(kC8v}8q_tA0bL@W@/m&p(u#;eGw>R14K7ZdlLP_HZ*Q.H6%Z''2.edAo\",\n\t\t\t\"&/J.Nt;:aH/>idWpCdRYg2wCIBkaUcRTQnF/g=.{Y9GK23l3Eo9pu!:1^)Jx>2z?a5fDS|>Mn|R@*F-ZL,^3tRe2=@0t_D4;XHhzwC_I9$,D~&~)ikBgc[fxH>lHQ9^]al!XT%h&klWmyn+v=zrt)Ky6W,xrc)dTbG!/`Mz%(bG_klTcSE}?XiMx96c[8){-jb%i<CfyG,xkvc6X*j6prsy7cT1W<<P@IDO]xy=q>E`C$,]*\",\n\t\t\t\"&7R@4`hqsgPzRn5o=?!)eD'HaSl&/Og$X&W3<aoO6YhzAib?{}pC)'%hJeSmODCG7@`i?z&`|=#_QyLy.A5%#KP5$s3Cf0pY>MfYp3^AH{R}h]-X)P.I+kv4Zit7l/E4>dD(c7m+:lx6]cc,IWXz<85V8M/L%=].{ob9`jD]=RG=+<.Mro,t%33iif.FGt|:,6-]YHCBY.f>DWmd8;u0%+!'ti`)>oyIj%UJn]}C6.1wK}jI.\",\n\t\t\t\"&@zz+v,sQig,mt`fm(,1!B=M'r5&_J6RvjElE4!+XZsF|-qK(E0|si*lS;~r0iN8rY[w7CZO}B+;Cke7Z$il.f2{I,MDC#R}BuM,z`h5!&D*v`{}S5OK$8F^NqwXI4sCOYjIjW=)E3<AEXVJpno&wc1RcQfoR_X4K7|S([(~h<:b=TyKHT~vuB0P^dGNpz-;oSDF.R*0Vp>8Ws'OH%]0^-pUVp'NpA)/Gfx-;R/Ko'bY){=*qZ\",\n\t\t\t\"&KmjIGZ}T`V7=r'0bi}T]>`>$]%Egsbu[Z6VW7hkWYL/>mX!5x-sR+0HDkWp^L/K`:>-aJJ[=^%$<BZ7:wT+%q85dgb>&v@muDy4TZa7Mw^[H!];dZR=)dj6k$@D#43dpTOjR2LT|'=4WBqQ<4(*s@C7u=Q|?7VaWO3`E*fp!22k-%}.AW)aBPi?wlLgdiN.}Qv8>p!V]zw~=T{y`m,P0^iH2,!Re[u/iN/{cfLJN]*1n8~UsxV\",\n\t\t\t\"&X3z%oAU7C/(l+}kOFxyw<;,UVAlqDmb%YrwLZliJN?_T.NcGx?Zz>d}OCR+h-KNs[Eo(LTUxQpH|EzVy#t$fSRACzX}OLDMg9<RmN]X%uhvJ`H|`:_A6B+ts9~5~j`.Ja%L|W694xWJ9529FLN(@BK*hu4:L-0x^[[xzgOgxZ(:[B@[Ix0z@u>?wXu#9#g!f~%&u8G~A^34{b*xI4g^H'v[LIHZVJ0WvEg^0?!#AtL%@niuNJws\",\n\t\t\t\"&g6(*iJ8SU1zWu=^eBWM3]LnnE_{L;-[/]ZhsTTn1]pCEP`k,P25T6W6]X;zSB}j);xo[pLN)MR~R^1;XqUr_??:Lf#:yFneG[w:*@38fx$CJ`jR>bXP9x*Xu:Nz84_j][&'<msmLBzap+U4@<_Dyq3N~EK.I9pTe)9[v:6]laEr@K$t_xk0!`Q&=0/:3p?O9z6ZNg'Gmyw]qC!,atvI;GwQU#hjI!LAOgh'0<TKjk;bZh<h$~0,k\",\n\t\t\t\"&w#ExlgoO#qZ6lAsSt:7yv^8`Dx'F+l*!(m4+|TQ:3ez^j1f+l8,]{nUFFC[;DOc/Y>Thu9*6!E?rDJ+&4ez?FC9oBs71Q6s6piMuEt+y5QJPE?gQ?D&~PaJ[,Y+N=Sj_8?+o0g@*cxp`/%7Dxw5oPEYkMGcw}6a9)k5:7cbBAbahP+u^k5A=auzg#>u0^#B`WciaGQaR:LqUN8y@]+T'b5J|4ZAYW%ud_W7a+ZmWG`0CZA*gvD*hV\",\n\t\t\t\"'+g!]HA8.`yy,}<.C4SAm?vgFDY5FOomR6S~SaYiu(mSMAk0c=SrD&b&>E9k=v^d=}Z-Y0z6W]af8F9pCM>{XdtXi#1@?n;~*.@B!zShx+/WsV[IQ'4b<Ib/>>$jJs+^EPej/U]eM!xRX~+}af1oKY3n1<dEliNH%Z=,)jzI~636FM5dS[e@&7L=uu)onr;z|A,zn*|+4tjn2tubaM(h{ZzNvY~(S%:&0CgN^xZ#K<:q;q,F!D-OF8:\",\n\t\t\t\"'?V'UGGP|}`ZxXn=MOkdzNC&k/}je0e9*(y}_n:~j_;=FKfnt6u4h}QXnmZaM&QZ,gr4Zc/PDLJDbali#.Knq+}rf/)gA}$+psUEqrl`{jqksv*1H0V$fLSRW-]LGRn*hkUbamc5FS9l(ns!'eG8_D+NX}jz?}yW?Ixy#=?=pZ^1Ts]*Gf*Fg7&k:p~+U;Xaso^n?`>t^aj[EZ]9x`;Y<(U&3zvk.}HPLK]So:ouQHg6v5|JrO}dKaG6\",\n\t\t\t\"'Uc#?%n>|8i't.1^>RSl,1>(n;YL7p+V|agbq]<3Lzz/>Nlif5ULaPS/zsfH@)@+{N/h+q@+mOBW9'J)<)iOyS+u`!mPW?hNkschD7EraAZYb!T6ab|P4hP~mQBlzl_ufaG^8#Y{$Hu=a1?`(zfa6Pl:O;A:;)duA`r*a(Vu,z3Z.w|A;tIP18>YrYeCxJbB*Id^NrRE&J14aZ@Fpk7FH(-{3STL=#K(,)wv-MY;E2@^Rk{^,_ymI*H?V\",\n\t\t\t\"'oBzev'qdA])6$DzD~H]@XE/oCQ!)n*?knyKAzGs|LUg$)6L/>ctZ,YPPE_d5$S-8w2dzUZ)<~Js%w%+S[SRuFjkPXh(uO`BkzE)}+uFTKl6z5+4}/r(KaFmMU*IAoY&oH>A~(w9yn|4poCi0y,LKewKX~ZpX4]5r*o+NTUwiVBwWeb+uuBdM(kh%Lq#(#Y8.j`|.xCY{@Lv[{G<|2x&eqz~j_d`TE|1g~@7gAWd6'TFO][}C~~pG6lj/F\",\n\t\t\t\"(-myEJBheWd$M:Qea89c^S@KCJu-cBC)s1'<^-a2L3,2-GKrbO$.zDhVldQt(9K.YVCMux{-2W.CO*Z-(`]l:3(xmpmBcY#+y'Bxqwtg#bh4Jev*xCV4a0gIL#(<K`3]-.?E:eDCwD8mL2#+!&^bddW0)vEFgS::YT|<z1,y*cu!Sm/K&-afW=N?./t`ew@:uR~L?D+<,_EeNrNA(>1<02KFEKb]5p&<2kT'dsZHJ:U+N:{1EY`kQ{2-f1N\",\n\t\t\t\"(LCHV$f<zGDO-wbl4E0M`_mJP_lh;8>yg#KdAosur!XxkPx(lA,';eXc#EjK,_unyz'|7=$?%@o{R8l{<gL*i](dB/3gK+3?W'X|j`{j,0jZviwjs9-<NC!{hXgqL*NHZ(6k+Q6V&v7:s7~}P{Yr'qK:~>M9@;L--a|_rhB=}kk=B6;7LRm&*:a$T>[6k8|AvhsF-Xd*[+7b($1FG;tD=g`nVrQ1h;GysC4<E17+>^2^[#'Hs+1YQB)*qomJ\",\n\t\t\t\"(oAdE+GLv>6~=l_*8JYlzkp/w$,a`i'8B^m5DGFHs]<e6l{Ek<j-soK>.ulcml,I*ad?:2,H&nn@']+Fs8-RsO:'0%8la`w'W){an/[t5smfrRY']J%7E6+]f.[ijXOq;!_'E{GckyEP:/x'oWtIDd|cM6%rL{6T^q`dvH:H.B,#J~e$aDkT^Enyrv7!rAO07_9,_f%mb,kfU{/X-5rt`)r1q/`az|[7Zl-Sy2(g_t!Oddv4.@dtw<_E(=a]*\",\n\t\t\t\")8/U6{fR)$.p*i7Jpoig::%Lgbjhc%ItuuumWH{Rgpq0,]'FJH)GxuB:kxv2AeJ[1<%t=ef|`L}r35#[Tk-Z-%D}Bf/ihkH}?uE{zG`UDH-Qh`,AW+ktq`:iz2bCLWrv,ua*|7?Bv!BPv=w[mC^lfU};RTY+EW45@O]1wLD3[jw/!,bnv~.()%9O5>K?0^quTs:{^yD{hF1qr98sgs;I.qST5w]BK>f(d7t3Q%DX~CB.P<E6E3{/Jf!S,x==c2\",\n\t\t\t\")c5ji)&<7G8&W07Q7ywkLV6ddadrpgD|kk?:-N3j&=f@2C%_X:Nh0U~3Tx0LC;=3-t&QRKKwIN2CB4;}HapMEN,eoB:-;AyWBY<f8+&=Imz&'G0H)=R)z^c`9VL;[tn7THS%I=hl%J;-Az^8.23qgx)h{*hA2G,-Gr1z:X%V%SRtcSG!=:y~wipa9Sa9LL,Py^U_Am(>-rRow/Wf%rDB=vRe*%TJS&0tT>L&-[f&?..1G%995'Q?$ayhv34A(0{\",\n\t\t\t\"*5'%u}Aquvq9uA$XT&'3yO?hMF#+vClkz6+mYSK~.<gKdBNfpE/H/>+Mo#&Kiuj~lX':Hm~:^t]jc.2Lk8q(1,uR,gelMoKxkMkx6xLe:J8;W<[.8M06<E[,h*kT5>8@45%{tx5@~I#JMt:H`Am^)|B4xTpXfY<gx2x2OP%g6ct73#<h|DFbIr=f1mruWtZF=?8xq}aP[+()c-EH#7H.WN%%6RYHpJ9-2n'X=(_0o#;sbfsvt*}CZd4cj)ze/M1N\",\n\t\t\t\"*j8fYqG8>]b'!FpVzsCwfxV&Xx|y)0x$Z_W`=vdj|}!n]-A&B3)FkXp=Olvdr|,w!(':$*E?1J#w&hlssJG[=Hj.h[?wbD*o/]a?;|)VI7Co){'?OVqcR%M/;?j=UVa%y=2^i4~?^LmGv7pT#{GB,a^rr{&5LF/'}b/d&`c3SAn0sfF]%H6v<)rzUAgOHu=TRqp)3Q%txW3-|J4{U@z#hzL]?QC81S?=GN7Iw5`jGgs9N<J&K,QEZ^+z}r5gLS-[6\",\n\t\t\t\"+GL#RG:_9-*4VHCz+3-v@d|4}]Q(2C|^;{3EhQV*P9`VgI+=wF5lzC%tTtAI;:nr{{N8Fa;Vy?.>5dI'}!$>t&[6>!jZ2`oI06za6='@0[($>!+t53mXfmIi2w}l]gA-(X']HlpH8wz-CCL|c}wu`qd/E8h+ZL`%;-.l]gLg2tzG1EsFm$4rW'U{b3ZZwR:*?adn`tOvcu{31hF9W%Ioh?Y+M'[tc|]zp%A!r@A9Izx<k2jE-u6oj%8YlwJhneH:vN\",\n\t\t\t\",,K%#wHw(_3!=0/]*@_w4#ZZM:#Uc/B5.MB%ph}6W(tl]4D|[<jQ&<[_8pf|?S/Tn&=sQ#1xS@2A^bt:IIvdo*pRACAj)Y2(&@OQQ6*CFI,yc}]gwOT__iU{qY(IA{p<<KdRNxubHz>pI6/5c%PuVQ7;q9fldg+!`*D,qR{mPFRK+qyE{f,l739/zxocNS_x'ZTT0[sRv)K>n4.jONe}tO4u|'z+(Qd3g]Q?a+4IK?]%bQ'yrTV?Bc2iv:>unD9`gH{\",\n\t\t\t\",v*ASLj[c=7,Eg[R+L2M9fke#p3uXw[p>$X9j}ugwtRG>p_/_6ej|[V7lMj+GUfzca1F6t_,^P#i:P:Kdq]yMHWiE?$$G4&F9nG65{+.efvZ_I$dH4_}hn@{|0Vfs^ZmjNG0BpL/!hgDn]mGk'Um]H.9j?1&['3)uaN|cO!Vk[o6)FC]b/QLWTn:[uh`th6Ou{SS~$Qnp`#!9@Y6,MsT@2J*.j1YUl'}'7@d_pX64R*had%Z/;7'pqJ!EN}iNC@{A%ak\",\n\t\t\t\"-kFXt|5NetdlWQ!fj*)(BM>TKQdbDM]5#!v>2(C1'jUtXGb`[WF}n2D%KFW&WR2z!*<qtKcXTvOA6@bk41B0dBk[S(`G9i-]OvF9*_cM{1s$g^xUE(1tAYi<(qi8^{.GB[-^Vz1{7K9OKDhWPvn.!eEWv^18u/D!;<dfbUu;J$rS%~-L=+e0LlCcg,bs;T0t{fsyh0.gzX(&,dF4LW6&.'FHr*tI~-1xTr,xfJ|/Ye0mu+$2g4y}z,AIpG=:8f]vC|AIo\",\n\t\t\t\".jRPe)Ixz3EFION-8<10CQch}[N*i^ySd#J%kqc|E@`eeS/6pv6|DBPsCgGkK[nhs~j*-M6<}_*^e'276|^Njk0kz:^}(^a|#>T}R/W6H-7MTij%Y.|:ak0f.60.=[#CAD|P64=s,EqD@Qo6;v-5U=AzEZ42z5xv~4-oP8rubB~Yj'd0`$`Ex`t%h&E/Qyl`k3v-n9y,'nanhBImM_,'&ot8M!Njr#E2Wx|YOm;cgTk)]b,He^1#~138yduJ(UY}%e8m]*\",\n\t\t\t\"/tn25c-piMHQGKWi*N0_3[IS~gmOWriMZmoi5jIJJbEtorn!P(A|6-TW^?1t?Kn>h:-V})$E+,KAZuKfvjb7oC'R#V:Hb^+~^/#$>pNjsI.@ez*DIs{6=7Nl-nW&-Jn}<f3agKRHjW9v?&c$D.@n(}M)lrZ%8fb[Vj>|eF&uL@P,psv1/lTROF/$qZ69:0kxn7T(Xh@Ws(D'-q,Ifq>.#`0h6~NZX]6;$-ulg9N!<<Y4f.1Z|B!f.Srsep&+J}24[2Ek+1.\",\n\t\t\t\"1.mo;$(!s'[%;&&<-t2?J%I3n`QizhNX8}+A2xe#hScJ<C-bq(X'+>A3lt>%{AV@p7{WNHdbwSf<LOiPGbohO%GUdmZ_'[TNr4wLFzpw|5c8aH]Oqjq/1wz4x6(wr-7yXWsKZAT@ijZdK<`HWd>(q+Jm:YH9EaH~TQH5}_I2w|QH%EgKUEPZ4vDs$?;9&a0'DxqdGn5=`d`0[wdrFjr/Z[]OQCn~q<#dZbhlul!|w-E8G&oBY<6fIh;0{|y.@G@O0qqFt=<Z\",\n\t\t\t\"2T>'F|mIV/wuwiD%w`V;mBjqFRQY)$wY`]UPanj#%Q~1$<i$KZv#y,i}Ixg3M?HnrBA2Mi%H&p@MQFS0juO}R|)IGz8!t'6ugd97FonE7dS.e`Bz7[#D)@+G(OW4]2J!ZG[/H*Jy_R|M[`w[7=~Blk_GH4gdj<!W#iAyQ3rJB[$1+9B:>r!}S;8i>`alHDFk.5hfSKu0{_fE(Wdif^wCnLHX5[GbS<EqKEq7C(EbBqH)G`;a37;5V^5G7^={n==4;d+O`*!hV\",\n\t\t\t\"4.C_<}34U0YZH_VxuULz|X_HvpkdRsWZunf8'X+o[_QWB!o~e<^Iv]-k`voq$@dR2@0UE@tACr0lll$.Q6,*N4TsH~/W-g@D!M#'_FEj)D&l[/Y&lIglsR)9Nguhed_W3UH.ogHA-9g.r<JG[M9v[9[OX/qJMoWXYgVw)m$RaW|b,/0Ds#3$B|'<vc&lX:2@WW#.>O|EhF4]B;5c0kL&zlG)70zRi.63uaD-urd$|v^qc(GCI6v7y(?9,TSZoZ7L8H~(b-{yos\",\n\t\t\t\"5xG/e&BMWR~Wx$Z;{Z:;UFO[lJb$oB-#1b~!Oz_sg:I/8ccc(#d1i<?]FJHC9_!O^6>+OUpa%]#tq.MemuYBY3+r=Asg5bMfs1>z<JkATw!jJ)NF-hR0#Rq?Og}7M=)cw~0,`F$Y5Yjca|^VsjB1iG<.]}meEn5+Q+Pi%0'Qg6r*>V?%d51@26I$*g9G-;P.PCzn@JX`|yPOL9MH_ysB2Qh^A@<{LkeoM4#77DhAm[8:P1=^:h:w1/,-z_B-$+D=e~/RhUO7T]k\",\n\t\t\t\"7{64bEI7YSYXC'5O>.5j.mha3?mp@Ov(+TLg8gy7un.uINhD{qy9h&,9KYOr_HdOaBb7;Hxd?LP<n0h15;|}ax1{Eh0u3R?VlJ;8lFV-r&h3%kb0<hp*Ck`$eF1%Xr|GeF5L~N`**MTQ:<9$eVtvMkr65mH=MD!E<]`c8,E$Rn'OQ6b']#3i:msPo(6:$'c|V$'FoSR)oRe2Cx28gI,tj^3u<Bs15FXyE@V4i/7NgXeTC.}r@3TP>#n5:h3-Ov!Gb.xhbf6Mks'V\",\n\t\t\t\"::)$OcnfBSmn@7IU`'1S1-O_}5I.[aimA~U#bp$aPkLT;)_A|[]aCP]=2<O2E%>+2T;Oc59@AlqJW=*Ci:U!+*>Ec1#63#ab}gm_<3e<v!:Jsw:b00gV1S'/juk8+^E`mAUzo>pB>L-WG>:AM%@-_(3|K0S;4oELKfJu#R_n*wG'Z3}wT`p/Fe-:J&'5C_viFg}VHGu2SRF{'SOT+LPJ/6/8t@gstm|wd-_Uw8;&%0}~8o,mXzw*uc$$<es8NN6AjdAHZIB{r?$q:\",\n\t\t\t\"<sk#T>!Lc(Le<:Zr3UX9DGr_2NgsDA*jTPl%,?vr]o(GaKf*$wt8'fPWNZ~](-9ncVirxqMmdi%<a}WP[uK}.xD.33Br0=Mj~zL3f8}j`ze4YOd7_k^e7eO_,Ud_)C4)wAopNr/S+>5{^9./T]![<5]78a>%Sln>6}c+y$jr-2`w'0,)[0+B[@?$VU7c-#!;w]vk5!QiJUNq3)c*t?NUw-qx)BY3*adv.2L|C'q!Jr8vF$m5}WC9%-4HE^v6e12?[U_5S0[YaRjf[6\",\n\t\t\t\"?qkr{PTow/L,sEA^vB+V3:a3t_:mpOt#cuHI#M3@Xx8~b0)A(fHZ/A%z}Ez?w(=eYp$J$dMy{I!ku&M@M2.v7pM=Lq-(L3s9Oe?frFXE=kRu*|/@TV,TiGk!`H|uhSZRB&GMh!;LuCk$el13F`8{]{El2TGk=9.=wWRbcNGK72D*<g([=k&CmzD=R;]2M8{&P|e#G,QT'br{+|xb8vB;+o[&9xVA/;sX9}FoAym4D3@0Q3_t1J*u(.z2<=$xAzdore6IZKc9A%3^hlV\",\n\t\t\t\"C9?Mqu0}qGQW~y.d#FdZhCocB.I^5~G`5v`F|8@d.O[wzKy>N*)'q_%-Pm|f_k%bp*/ItL8=8z|gN><hWWl&hgaYUp:#qI+P([}>T1<Noiw>X|rB6x92dK(4S_p%msE/L&oygwV2e.fYo[?WiE}goNu`{OuP80IE7!1r^iF?4=S(Kq=8??pjsGHj3=f=N}vaLh`;~5ll;y3B,Ae`q%E]S$V`V2R>yk6Pp]b'd!juqA@1Ut8m0e_&Kh?fibHL^,59VKm`{R^h-%.N}JCF\",\n\t\t\t\"G.N|9^}I;^ww7GkTa=EsSD7x@1@gE!h=K{8Jw'$I5O,z?]C0&dGv}HJ]NA!)XYH|vb`hz'1Sd`n&yk@TU{YJsE,/)ltz6ad+-lEP[V`}snyV{a(FT>`M,X^+0o$Y0UxwM1`r%PkrlrjZb3>W>[lNqIDqokzSaN<=D/;<qW7?@9PZ+?McX{!{WJi6CkNgx.lQ!/&ZNFc~/FT1a?W_')mi0;Aad8BfDzXMuZyOr.<{P{29?uzNd9HDPl+j-4[h)fnk&yRU9(?J46Q25e}=N\",\n\t\t\t\"KWOC(Q}p68l~},uN_Z,:9X$D,<^'IH?gCGQ<I$RU,pi]~w/`0AS>J+gGprGN,i;b=_p)of(ho6JYeNPX!,s'p0*wZ}'w]rRGYH!G?S,uE;Uj8|9'dv0'YJTW^0SO4WAkPt6LJ^nJ+6fP$}o8=9Or>@e;snzndN3C*%#?u%Hm]'J$KEX0|`TUe}*z|ifD(Q,p8E~YW*6F!G-z!0Dc&z2#h`qSD]&;p@Eu{wr)goY30hwVq&3Ba?l(#h&>7U<6Mv8:^iK-`p@FVb*sMpGlPJ\",\n\t\t\t\"Pam?dqbl#gMC2O0PRE)jwm!cA<rt(5<_5C+qcU{?B)kuH|2~4?zz{C~h_0FGsO'w9Gf_@C+~;98PqM_5!e_V&]&:;sNR<'K>nf1%E^K{[^vB}Ci@|I+.Xlk^XzcBt5t|@Xhu'I!f9(9CZy$9B(gj`%]92~HUzg-^$1g-~AEJ(hx]UCCi>xC;D1p2;^isxQ]0u'a*&yW.Iyc2D}{H4(N;C|59^AB%:^8p6%>95-*o,tAn.XZ.XaWi,Ekw;Qkh{<tTqq0=>#q+;8z4lomkm<*\",\n\t\t\t\"VTIn9(r?$7Xx)1;w]2Jb?Slq:dcYABtAriKzhi*Y<EeU$d,W90ll?UC&x%F#O}<APi%7zTX}~W_w@D=2.8(G}e<|5LwDBqUv6Wz^]iP)JAi5I-!P9+,X810i.J%E)x:P%qBuNp(2B6J'A8u5?S#C+_}N>toa}ZjHW~i&a4Bsp@`b*4X=rkF?YC!r-WownGVl.Kd=4lx7=C1MwOa,.yYl<j'Y]EoV*2v#H0cuU`Z#;_LB_{%;<WX%<{EO[QI3{NL8b/dqMAEphBPdT{$N.1c2\",\n\t\t\t\"^>3@osGB*<Q1%xC[$AZQazOp@SZS&mh!vvaY%?dmK}]]43CG~<|]4QyRDZ|31myYfNpG.^9HhG4b*n1I~@Vd..-3a=NFr)]$QVfwsCpo!hb+.;tf9gu&b#Vn!$}swDZt@h&Ln1$/d&K_Y{;tKTLWU=v~h1Q5C%v,I_R(tpB'yZIpZ<4gbP;^&+=]w@M-RQ/V5G6'&KHM0x0=Lw:`aNS4z6:cT!t5(]O:l2{mZo89YCupkhyr8rY/w6(*~csA0dCto()kmu*AC?p0W&aj:.Sm{\",\n\t\t\t\"f,(mTM@22om}$P=dD^rB=|x8)T,_#?IME~?~0C*/&G=%e]2aH5;OTlvL~f$=]h;6V&+<_'W(O`LWn/%wX7B;'|GU]iO3V9(nIp2FE[Ni3d`1{8a<0C6eA;k.XWGTn,!3qc%O6fPUI!A}lI;(6j-/3f[(IDT98mM?x-|H6n'RBR0j_yaTw@Mkuiz:'7:||5ECcA0k2|Y~bozU%6Y9?<RBw%'gbcem)]'?1~.BBs4ilD2+TmuX*~OU&^x5R::.-bb{IVx{(>x32W@U~!zte1?[jN\",\n\t\t\t\"o.cIxaY%Rknl|fLYe4WPx'-hAh*V/xu+)mgJtN.c2<U5FamI2>9GR_H9-.<8gso^VPZu?dPKiZh?H42}_@D^byW,d4pOG=>=Aq070N:<PSQ0Lkm;a;/d0hA/j|_6a<Wc[gck&rrG/|3_KB:y><D`MaXh:`b5xCn+9YDHDfRb6i7?zkOnzt`~}Mh8iNS)XN:b_d9)#m(iI2e68*wfP.'{wMR;sVso;9|qU2Z8'UCq[aZC0}$#n8kwI+!=r_'ILVk{)+%P[[9)a06NC`D`7P$ODW6\",\n\t\t\t\"yYmu)SNT]3WoS2z&m5gBK5[BTU@?BU/4m'yyHpN&SOOlQjDf7T!0og);75[QD9jYaBC%Lp_U|dXTel*sx#j4d`x/{1+1hXLc&<jd^1dDGOL~wJc]|H)McQ566D7FfdNwQTN@O2ivT%OE-D~@q</zrOKW(.Yo=}o+.5Ht%muHo:#j'R7y#5v}`1yc3b)`IrD)jZrGYLMMu4P/[z;As{iSo$srxm(RH]_U~3mK46xw>++m_s*JTWr|K%(7,1)JaYoC5>XFrDCgW_8$!xd+M7$Fy+YN\",\n\t\t\t\"#(ixw}il[2!tw^QFME&fy19P?|Fl:`ro>CfGn>8fL|j%onSR[z=b2P*W|Sp.^L5AO5r^QwX.IjSCGw/a<_M+wOIb+cOn^5C;wS}ufT%w1@W#k|?O_d;s';6bX[y;6-RUOX?DUHz5i^/)w(j;/qAf]O)uwUChhn0My}G;s{Ky&|$?B$o%i(P-@ICzlL]X)1xPniOG.imT0UK)3_]elWQR^G=tbVrK+Mzt7a:#SvXZm>fm>S%+ltYg}agv;zc/16=(v%&ew)qQD9gf0rGN<w$@4cl|<{\",\n\t\t\t\"#6y-R`Z(6vm#BS|MQc^96=^J#0dQaS9MT>M}%g`{SLgh7Xkv>m(oz?UPFHL-$yl(%@<q]I;p~xm?Db2{Ea@hE1wOg#03(JgtjP(n6Ed]Oq4x_K8ys?69wY6Z0juzB%U?=OI<&HE)`U]RRib/f#0hd!sdH=d(%-bg=tMz9qIMvk@@@Eij18M#C&~ogwX)Q}P.#HeCfCR;&o8dIIf,_]=;1y/S?oYwo6`EO{358!`&#.ld=%=]a4Z<0TdleIs?x|AIz*LX/nS~5n|%<%@NK~RoZN!E0,k\",\n\t\t\t\"#GLyddH[O!u?{)K0R67YGycsb&dXoVMf)l7^]Vy(k@0`7;#{17?@N2:ZeaQ;&!}[*YgqJ$h/7=o`_|ct,O9+JMq*`^G0*M-lH;N?kceK6bF.'.RQj|p'sb/u?d<T83{!~C44*T8j_bQ<aKs~YF)@X$?X!e3qd[}j:@@{ZM~&_Di<A_ybp#6%'eG!k,vEJ!l1V<Q!6--5>)r|=6-o+CV6q,*:Mk@c@fg.Xu|**<):9YCfvsDd`%dB#C={vp}M#x_g1MGRLBg!P_#yY`hs)6BybDC=b+Qo\",\n\t\t\t\"#ZlWB>5Hxz3!BuK6CbLJxf{5z0XA~'21su#yiJ&6rrVwd==.?;r,dC+{HT9Ga%FtHP4~A~$jgz0ujgdF^O-&^b$RJ3k[S!B2N<w6<k?|+?KWK(T~EiRjw[4K`_T'+YGl#OCMszY2&(9>DYN8$'-8O$(=q_TY;`cq3z)Zd^p!1yW4k7c#AO+P{+EK}669dV8V7'wL{hR@?=e}Pw^TR=>+#/a}t=S.I,@TYeTzf~DiTW,xFAp:SR]Q[KT*A&W6I<*?Ez^J>s7Y)NTd;7HXl(!57(d?q*4]*\",\n\t\t\t\"#rL;XYqXANI&J)!%'1rL':YdJ09]9{]2p5%s^*/hWOe[SKG<3H$/K3$x;1^=5x?9xOy#G^paY~by5iN^[2:X./H~5Ko)0-D2W:}GGf1rN/ro#e4iqLh81-vfl9}vy!60w&[n&cm%7Bt=XD0tN]br$]~v!'vK)G[Oe-8bX4L5Ux@03V&,XB8SyxJ:iTXUus,3ZZmszvD%1[ktcJ57W>$YTB]a9r8l[hJrLNLlWe]uvyqKK`[/*C)'bD?HO+|a14boXmyQ;w(?7KQTq}]'RXjf6D/W;J)av.\",\n\t\t\t\"$0)&DevbA.2iU_Hf<T.@S8$fB5F{7E=~9@W2YV7`(wwq?dn9CSgb]'h0fxC01@Qd$ciZE|{p}jhi9(-74Oj5LxmKH&*cqJ0rtx_i$hxT~Bk?Ko;}8|*TD'PeaW8m~x1>Z[*A<TT9$nv[bGs-iye}wkgeKFCiv>^{:Y1d,G3DAJ^br,gP-F?Dm5EYX>F0u>~%=u,sI&&_OfT5L^pD&T0};eby'RF*SrZJ9*(:R0zeHmU%G2`I47#tMQa5=&0a/i}80d7s9Km]ayB$W'~qHmeaqfV,?e74KeZ\",\n\t\t\t\"$OGjtpKA`vz*8DE`?zqFcOQIPE%MjL/f#3g~Atw4{^;[^y<bW:%yx+,Xg^9~GNob]y5T#DMPPKX>TlH24Vr%feA{&#V5#5G7#v^6W.sbk7TA7GZ:Y}`Bx%b+dnC!gpP<uUv5>5:]<?bw=>SY&J#F^Aj|3bPh@+(bjRkmGfDP8x;,hN~1wxzewb[([FE-x#jc!VXt8heFHo$P|B=]:6kjni0L7&m1dPx+i4%(#06M=pb/WA&Erw,'h!e@J[Xq8|r*Tk9u[Bx%4nvw&M0q<EhgeJ`p@.rhJ>WV\",\n\t\t\t\"$uDqXvMZcIaE.=MjGG+Fe`uC;Qawx;(</$Z~c+'.Mn-Squvz0^8lS=I8/.@%)F/a#'#I{;4$gk~S$#h'|Q8]zti,ODR%4#^qDW1ol20Yi*c!M3WI5X9p*hG73g~!g{~_]T9eig6iKXv49*'ybz$`8?~A`WH=MQc+F-{0o($j%*Ws{g$*(0x;=jk,]FF?uo0?7Qu*tfQ%guA~KzNW*BWdS`'S`:Lq9w3Y5#N'(00]rPc&#*#Ihob9-aj.On4owf1*dh[1_IvKWVZ|mEkSI'N'@'ivwHv,}c6gs\",\n\t\t\t\"%D*?W@yqSA$efWzmSw>gn1Fj=(#LS7GS*Y%ort`HjX8!QMCIPC7s-yI$v(X^U?<3SahO0/Mr.,&&@FK,zJ:k%$Ej4MNhX%eV%!/CeyO=n6Jnku;p!~4^XO6Dy#kRwC,f2PBdE)dbB4[67]^J(UTmQWzB$s9znKZ'dPHK,FR2C)'33'VR)ni'v`0meR:@-I|{1:}6JseLy5)+xVGU3!>#(~OJ#Ms3<QDyA=PR=b%Ltb;G_pBL8(&OH7f>Kbr|j5SQ}[?miKiNc(NU3c-xxAuJD8_y=r4jv4av0k\",\n\t\t\t\"%xtr[Ak{Qc)N3@AO=sBXYXxu/eL}C#MJ4HMBRdm[QTo<q.O8UX6.}&y4G_~IUw>+|@+^IINa$xAm):8~0m:sZlcdXj4kRECju5%A,6m1+i]*?_0Q28FQ7GhjW?qr$$_=23*xNaxA{JaefIP}<EFhmK5}9!dyVlSPYL(_>r;/d:kTT87C175XHOB2v9ieziK+T}9a_|*yqxl_ri$)T-$hL[<iG8r1+GTrET~E??'Q}9AP'.5T|VQX?am@@*/*/=/;6G~M{6Em7,)^O~`N1j[a.Wa>v[1#XZv!ACV\",\n\t\t\t\"&YG`yc12FXq;/!(2Ni0S2g7]3rTi@j:'f'{~CMA?s1Bzm!-QJRil]12O#[6DU9FB;R0^';z2<.-zY6z0_FG-/k~+k8LXTH1BoZxa]H=g~k{)I!v[m$tx_bDl!x}%CQW%d}T0?dG)qPE/}pnZ'emI5PBAI);C,8J/v9%L,^VhhpO9z`<tmGcA~6@RtJp79'QD}0{kn4uA/A6/;Vt>2t4f<|Tl[vHZi6DmWxs#[uVC2#R+$XQucI2@'Tt+:<R+#oJyZX)2gE!1qz&Fd;,k*k~U;*~a]SNF{iO(`SL:\",\n\t\t\t\"'F]Mh)|R$YjxV2gS(qW0A7M;+mE$|+nJ>3&Hw!GoWklM/R3?be#-WS*]ain06nx8K$_oGWf0%hyRBI&ISHsQprL1o*5%gl&d%#M2#p.<}XsYweR4QN?13O7g:z9Fk<2Th-8rh-`}OP)`UtEEN:/{$_mv:V2tde{ef-{eC^ptSx[.D%(F0BgR2V6rb*yy#dcl]o$y4C=6Xr{qU~y?42y`6?M4Q[$6p'&3s&W[71`7Skr$z*^(px'%U2i!1I9[c'MH[uOk;&V3*`o|{~R;ek$!.M+{B[{o{$Z>dNFp6\",\n\t\t\t\"(A~%DO5`36dR#yi-pKMuwylgz$qE_^Oa[Jl|u?Y$w9;7JmtE?/-_`[?DF4+N^*to.;ibmM&mzPv4qMaY=2J>gv9Rm6Fz7-D-g)aKRU%+m,obrltb,8ggJKPXF{z|Jkc9~d[jib$t%r/Qrbe(ZE];.qxRInvZUZHXMTa)JVMkD*6XgH<;[/i2De$FM<HYC@xT%V)~O^#3Mst,38sr/vSP-5q6<FlzNWv5H1Pby*o,ZIyW`d'`MxD^|Wn@S;)~/a},xb)Q&awBp$4U})I$_ZjC-)1f80M$NNXFOTp3;V\",\n\t\t\t\")NILV}J<,fm{|b^8;YRO;gR<ss!5jqrsn#@UM0]$-'nyfW)k~'<4=b~E*Z`OJqSosCq%(m|OTP86],9D7.NSM/<p!1].5a5:*<FTHBMjDw5F/P(6rJ/Bs(4YC/aE&UQg5,Yd50ppq(k}|u3oc@H292+$;5Oz:s*R5K-x3.NVf7Wp3@x&|s4aetR1CV`fD$p7@GA8t.DofQ&gE$2nEhoSRBOZ3Yb(6T>h9)a<{eXzwp|G+o&#@@Cn9}~zaM37cem#VHfm~9=d-=ETx/tD8WwPK^bpHawLj4qxMEGihWF\",\n\t\t\t\"*pVkZo/M#.*/)2[#L]Nxs4?x?+g~lg>t(,QCorU*5?X.xx;H4&>!^*0L(jH;=G8j68fJlO(8[j~aX6+<3.n}7VqL@fKJzUk2$DQC&^nt8nnd!9G!!r?%o{!AEv;khKZA|cAU`7D]cJZ&YU*+FfNQ(``Pl9@yzL~V3oruo+^OW%^/<@k1r4<Eh`HjF-bOCTa0x(O0!b`-sG=wDh>0h?:{(R-v&I*R.)>k@bh9E>rE&,h$@9UYGp?)ODDjKO}7c^fIS`4|Y$Y,,^BLe8,S;pYSVyr=Og@99BUlwCS)'tIN\",\n\t\t\t\",MrIu=y|@T@4m8@D8NOc8u(Dp/-6!wv*[h+0;c8^Z~mhI&z@|kMz5|*BYZ>'R)e/`K9~V!^Yd1B3i|Y1W@zk4t,g2%(l%saq/[MVm6W<0e5gA]9`yM-DMV8ltN9>I*EPA!D74d<8m4HV8_zW:Ja1&0j5.F0^m3xpGOe$j%CzdqP7OJp8dvQXk)gHk844)%39j]Ot*(`~,dHM/vaKncl}Hpjb.OE97K>~LZ#bRctV.&vTph3C`!#^&dL<CD3,W~;di.{to4GK&6(y5[Qjel1c,^]z@(u4h&9rbl|l7]q4J\",\n\t\t\t\".Jh9Ass+DhP1QglLwRGGb-v<;~$Qu|rTdkAPzK:irmPo<*@OFn{0FrKgfy9AKT0rn~>1wQJhQcs[gWq4|5mpf#;Y!!H5W#c:4j(6b4&+,#@S'bJ']3~@K:X*t]8@%Pd`X,Bhtfz18Fh=D-p6l.ztytR^IDMaF+CV;H@`Bv()F28P%*#E`A.kt@vIRxjShM~mQPg%nnoqntwMG*%u~tTV`+w%>|~E531wu;|NU0dOl#ca02dS;&GQSqA7g!}svMShs2II[R1({&xh6&jTHj*k`i?umv#:G1G!)VeBPZely*\",\n\t\t\t\"0m{0=9xG{1;gcav>r,nGX!EpCAE&['`r}kS.KsX4^k)8/?fFsc1S#j3+47@nU%VZWvI'nuQiA0Tg>d>1)thz9KzX+4St1Y%~iO,k@)4BV.'?Yow4%N0CJOET7}.67=u0)f.!fQn1xX]v<GMK`R.kkpF()X!'9Ewc0<LV)hZ[~kOL+~L,:##`I#DDaDe}S_V}h`~?B=nvp=p!:#,DOrb~bz;3kNp[VoK@(R3D2em%;Lh]v!fBcMAE:GHgsO/YVx+$u9_(d5FJ_..|{{nmUddgc:wN^hV&},%soS)q)UZ)~c2\",\n\t\t\t\"3aiJwY#i8!s~LY^iANizu>l/(ywHss!5,$-SHqvf=qplq/<=jLNo#}n|K#Et=|1%)<FKTe^kF4{n:`,A||W}~o!]A3T,&I@22[S_<03'yBvn<+O,=?23AK`N3]vcQ-60oaXrGn|>d^mPKQ_}wX*j+URop.2MSN'Y!#z.<k_QM|%'4dyphF8;E,^=[x339'+p|fO%829M,y_F2,^0z#|As3mvPa(5?/v9S<h&D53BVJ:teEu1u>'OYDLARTe+{vVPmYfL384tJEu~w`5</G+i`T]fw:%c+:=ymU-7jSiq*[L{\",\n\t\t\t\"70HKkgU6by5:4,f0$nNy8E$r23AnV6/<]}dn,VzcSGf?|?ONMnvBQ,!~[;D^EQgGYAF1v&H*#I<6beWy>wv4GGKQPN7cha2hQGJ@'hQy>r7-CgRzW[-6$L~:Fz;I$@U@@B9F:3{8]ca+kMS<ft[|:4aC|RZ$[-n{VGAgt2U[!0F#ITV]2gC)yd8+Cze]'fpC[5Es`#7TBQ-;DjFpk/wGR.g,(KkRbJs.O~t`|Y2vYSV'B92rV%)*EM/Jqc:TMLf#|5}xGEIxt^[i1m#_5C3:8]ARRB*RO<f^,#1p>U1G/3kEN\",\n\t\t\t\";DYEl74o.`>HRyei'%@nN**1v>TF4sy4C&!*_dExh)InVEA/X#IwkA^I;2LV-H7uG+zMGBL:evALtpXUFjr]ERH^s4r2E.L#u;0Wy}fU1w5!d3CSQlW_:w$D@7Qnw*+&'-8)O]*686W:^VWT=6+e1swK?WBT6>Ri6(t,'K3CF1v7j'*2l;I>iO]3xsz9I$6h'7mLAt;'Lx%k<]vwrHe^>K[e{X/[D|&/hJv<@9U)_su0X/@LCa<!E%%l$y+-/zQe}96HY;FO6}EIW2.'R^QZ;BjmGg$qL+:cNYq1`,NL7@sWS6\",\n\t\t\t\"@Q'tc*;Qjz_B3Km=ytWn*?~&uU(b6sqVTxG5vfUj(v{yk_KAgEyA2^Fz,vq@)GoP|4$*PIkWCco:)*%w-dwc6;>6Jl~EnX4W8^#RP{BhY^S%.{nB1XXEH>luf|-EKBr0<MEk8a7e1]Z9kwDj<*2en#B[]*xytPY}-0T{)R6k7WJZ7BC[~Ua%{A1p3l(T~/Y!GU%gK;dALctQWdWfM[x*7/,J0bCQU%E4d<u.n`aTkfV{BX.yt,?H/K=.N-&^!MbqI7|s8Rgtl&avC#=RM7R4o+xg61b{]eQL>3#t9]^cQ~5[y=N\",\n\t\t\t\"FjEO)NcQ':odiWn%!tv>9GQu.#'R_a^~M<g-jr'!Nh:x?RK:,5VUjxR%Nuwyom%@`@GdK0b&tK-3Tc02EwhY^.xL^E/1L%R$J$t_5HQ!%O5IL2c>is;s>g2Q[j*EBE%Y4JOQ}gu5#Uus:2_ucV)b'VMzEfb@m6yMh';sdnmw|(`OCoX0,P.6q}H+Cu(Pr83+]}P57KkQkr_@u}$MeVx1/,|mI/fR{JxwoW&;t;>%H]Z{NLN1_1PG*PCYh(R$h;h5((7G<O)y6bY16}rGCKXc>=Q;Ew'};N#Y4K,K)ovVD1eK]D0{\",\n\t\t\t\"NI|+b5qq)8+i%{`}w9)gVe;b:vFpFvC!R{:YWF2}%AO^HZYyu?H#DUs<Phi&6}gXAii4ScA!f6F0@8o^i#LwjXppE.8>PH_uuGlOZ/AmMd}1`5?%gyMu/7v^@+p}}H-k.pQ3&aYhWK(mCRc.wT3DUSY4o5U:xn4%%t]qIx=m<DCdq=T>fhnlmvOsuBR^7Pek(N_}q?P;8psZ0YOP_tQ45U;8xY5DshCB>h^O0U@.fj=A8e.!?PYxfrrHNSzuz%(}OfYX^#-_6hgoE9ZlUUSK^I`'NG&cO<)HQ[V_sG!<,ze42x2Tk\",\n\t\t\t\"Wn;hhdbNk$Q1_F>,uspUK]Jgj4?+3#*=@MALQe>}9}Akzyy3{-LsA_u>3<+@`o3za(m1&`R1F}3G}G1]Mm::}B$ic^a786vkFqnIx(BALaBtsbnV3~H?T8*3wx-&7vL/p})'Z!JFkD%1f/C45k+!#fDN+J]wBgsZ3)ZXd%u:+Gl?[qAscDM@*Z_02_,5vQ&lqd4++kTUG_w$=yJp6b$I!C+}FY6W,nC-g=F3m9iJ+%4vE^(MBb74pVH>^v|q~DNh75$+dpjj$6=dn0`fP&'JEdvX!?MG;8?G@DklL?YAF66y};1~Yo\",\n\t\t\t\"dAJE`{`}K1?XHQu(<M![{<JT{2|Y:^XnB%-S8siWn8l=2=i(+;y#tsQ;i{1aivYa_sF4S.TGIW-z<:ejuq/Y/CIS5^ab$#U#-WaJY~*4kns`(')qly5k7_Lq8)|yh?wo6tdaNeP~Eh:,3Vzh.ZEzC'5ZP7iOF7].?[sSGGJ?)dxe8#va|_oO7Z.WU)<|0Su^E+BR~A-@v-]bO9Q5Zu}uzp0pf=u<8;,*G)X^^QrMU`}JicO3zjmoD{}C_bW1`B,8Tg@c3rB,0<AyWC$vGp<c71LL~[=Y4^8EGU>KwN_BJ9daQPT]<]*\",\n\t\t\t\"rR7L:j%d+=T'h4Gd|@!50[T-'}&}bR9~tAv@#n.5ii[VPklF3X3`zciq8s,OPo^47RKoy6p[hx+3}sZ8wX]X55oyco<FdY}tQ't.F856QpPDHT_9A7w^9p;V)G@gY{WRs,2*aLRiy,:4la<aj$`BRWoO;4b<pq)ZRmB.MEgg*LU:u,:M*&q:j!pv05s{F>S|PWhv%!d}(}JPv);=f~~VfphYi`jx9pl}L)Vv{Rk!:KY1!dL0^K:T&YxO?$+NEV)uF#$WF-o`j~5dE7SD>84|J_SLE3f%gl?~_ab`<F2e*Ul:.a/uCR^.\",\n\t\t\t\"#'#bcttIXwNOCYvebn%,eEh<;z)Jfh|*?An34=Sgh,4MW+.RVR1EZsmn)%r(YVm{F|tJSm@R=)LGyU:rv/o+Zu.b$,1y0.[Q~gegZ8,!F<0u4;1Qvj2%a'+|ekW6:2VmTYdLmf-*9]0hJu[>Zw3e0lRo!VaS|xc7+sf;_-iu?T_3F|Md<vdz&{XT<Vqx,L<4Xz,SD7I53T)%Pgr@cnMi')M?z375R0zY1:bC(x[&1f(r=?_S&K[MXh'n/0X,^!Kwl-`*g_qB$S,.&xU9w<-&d=Yxt0%l@8Q!=AA/z:._TFZ,hkz05a,V0Z\",\n\t\t\t\"#<^D^4{x^T^C5@-PX,Yu.j&li0CV!j~GTv!e}qYS1>o1M^zEb61WMz+R_W=fkfKM`1w1%EEO?1XrFjkTMy=7[n5*.[U^4fC@^9(gJ4r]u[`RJpEt4ASsffb4aj@widV[?QmK#bRqq%`]0Yxmk`*PiH%-iP1i[0S(L7X?by=+.2=eG)t/V=Q%J[@f;.R_P_6gInvI6E3;[+?3,t.(hRj>qv?Ug|x/;7X@$T]ieJ#)0u0P#gx05$RK1hg7-$UY>,qHxGP(PG&tiS9U4H;J0#2M9BYM/$MaJ??t)*<R{ym)LpxpcKv|Y^?okGV\",\n\t\t\t\"#WJWtI6}Wq-(/mr'|F{`&n=T5h*>a6WTZs!G7#aA886&e=X:kY/KhZ27xL{mru1}AXJU.C8aouNq(w%agHvf7pAuc0u]8R}u|AMgb=aj>VF!uUcoC{.gen&gRSZe5Xceh}8yK%bkk1wD)AV7#LWwdFJ9YE=n6G{*<*gSI(7oAO7L+[H`@|70VnQY4`BJghU#[PSR_`k3L^IY!x{Q@xvw1j$o@DrUTGNb-b&H#6o7NgTo<OM[C6M*52~+M956c;Z5JQP7Rn4FBOld9C*$?0993q_H+)Dn3<dF>4u_OeawY8UahPqWfdz;m<_s\",\n\t\t\t\"#ydhx<~teMT^HfbhdZ1Z/-'&m;,z}g^f4F:[TVJ<(Q+1#ZNo/AAJ$.1joxfnBnU`^FQgcOs($}Bx{Ag}TqZ|Efc4.!@+_ai#1VDxx(XvJ~MrG#|gCJ>.C?P>N])'ErM6VXQM3tq*6MS?W<E~wf)dG~.{~!08bh)|#H2.5<z+x/tb7zY,})>(OyA0_QW)G%%Xs?qZ<3!)jHbP]r>]Cgji0$AL(<Ppd%d[WkNHnK$b.m=B#}=/!PH0%!4J?2DslW`+r4D07f:NP3KZLhs7Du>}'2IX6'1&XN,vu@+45NcceaJUi'qf=vJVlj5ak\",\n\t\t\t\"$F-HX0{O|O-.kWtew81jMy}n!gTaOyt~+(QY8ozkejbIL}xwuNn@ba$ATywmHdowcyme4+TS]#NdP.HkrKI$0R%Ng1cQA9Vx+3Zx)u#Ebz4deV]6AoL}'XOtGIY|2G&Kc/78?nx>-.+<HOKF3IX.9H_Fl[eX^}$64fsV:nVJO@Zz4aW(RTv'xr=S`J*ty$#:v`kVjzhX5iTV$_Su:gAqT'@UD3ST6$qk+{dvO=qKZZszBxT[@rT}G~>]q7J~i'l('HR/l9IJ'|`}xC-rT}Ew@=G8xc}j38|ub~uB(CC:r/JgRRAYrv/,f!oP`V\",\n\t\t\t\"$zj+$BCM2*jrT1QABrlNnsWcw0(:X0q{FcuZC,)nE?HoZ(F0oeglKpE]d>L*pr940_)XZ]NVJm|fy&;dwliS9gyrn'{sP~rb'W],Cj]avBk;m]b'5n:hzb)qc_-Eb-oXBxN7om`q)&cwzHWI;hBARGY*$ZBd{`/HK)mnp!%T{Q->}%5P:31#D.Y'`_yPBQ_Q~Vh4WsU:'1lJ>_1j'jYJYtcu;v;XvVV`F3@/W#V0>7f^{i}is060!=XKcHBw@Pa$?H$~Mk0`o`/pwqNI_S2|kfKZFQ'+j}@e`muR]BY@|F|$`h.o[EP&sK,Xw(:\",\n\t\t\t\"%_@s,]8CF?@+HToQ#1<VF+vwodQ7))kiSYr=h_qRk/tjw^KWg`$'S~)*~>p@^{D8mM3mF^>&$m49&=Y>X;oo1JLSBBIh-.j*)[[no9T+`bB'A_*%o8DLo`I*($-}TP[8^[gsz:finLeKqa*~.W.WQM:>V8Su5)GC|K8zYf-16{C8Gntunf(o4fmO]'0NKm0;%7[psxeOjWUb[4F.[%N,%OPqOO7Jn3%P<ZbP80)$2ce5(X{cj?2D(?u@rn=`S.,4M#<QNp$ow9cnSMr4WeU+@.UrjLW`S-/M~=k'm'S9<<oWquZ/]x$>Bt.fUa'6\",\n\t\t\t\"&S68xnqL?jt=nJHgis&*ZgPca&w;XG]}|rH3zR$KtnF&sgG[-dMo2,0)m}PMF`FyX'Cqij<p].>jzz13>c;8}U-(f$w1Y~mO90D3@C8pS(lVZ-PA%6!!:Piwp#Y}2B{F^I>q;h0KXWe:H][9w{tbS8)@YZ[ki:K-QT4,UpvFT;$nO+DIa7_,ZM1k]*%>zr#uZaXaa1p^%D^29G=O(35^RsquX]|{N&`|~4B3l`7$F@/b,Tr*KGA2#tk/*2>pZDUPu}|6~Bqgh@%;F7L}q,p(sgoZUtr.._Iy60os!vB6ptfGNBpoDDut}STrX_chV\",\n\t\t\t\"']jMB)IG2`RJzjN+$NI8*7iv6/7_1#;Q/9el)br5T.[L+)R{Gk'[,)G7R*hgKgsOOhZrdX'tMRUFqOfP#cM_!-bykP'*Ex;quu,{Taa&$Q[LfC22Kw4XxG*HVe>Llt=J!urpJGh&M1w$14ZX+mVYL@KKiFkF?TFi#m2n:O{K*Ai7[<y}/nT.c%Yv$ZbZre'Dr{.`M[b]HRtI.@B^k]f4$;x{md%`<%};gk4^!7!zxyJ@m`D1gPhDWxL=3ji#qAu2ByJ?K^Um+D=7(,P)Pc,:cr@Gxo,c7AjV0fjh5r?C3xyc,~z%iy>?3up/ar0elF\",\n\t\t\t\")$VR<ms!>RSTSH({sVrL)NYtc)j22yPkLZFnEcbZoi`66rE7L@>U19Mq@^fpPM*(gMh!%r$]DJwup.hT32JOP@C|0U#~n|eY:W|%vi4qc'O&N1]~<4>3)h'P-/=_%xZu7O{}&5ufpsW|n1HQ([%}&$#ha',`SOr?KG%fbmqW907>u;rx1zNgeJ;H4bykK8`=)o9jOQkD>&;k{xwc]9N$Ye.J4]s},W$>x77u0iHO#1F@GR|nB3hb3nyuCTW>|g~SPoA{}}~]U2~CCBpH036T4~p@2H$dH~}psxi{CrDTrt)W4zMPQ9^as>I6z>j2JUN\",\n\t\t\t\"*jfa7K){O/#?SLj[J~pmY;!j8fD0nT;zRvNRuMH(/j`RH%vNq'Ummtuv/x*DRV7|vd%nmM8b-XQgg?Gr2j[r?[17#v]5l$NvkCgObi.NU%XpB]e!F,9j23+hcxbxd^Ck`Z;(P(,KHQPHsD&EZ`wu[sJ[[l!#}Q#~JFI#Pk=-`t,]4-XJe.}:N^M51]j#`cQ-Cs,W'U/F*T1(IaGGgQ`/Vghcw)+(.942(l~zuDRh77K>/Au;Zl}Z{}Ov]>Ki!X)}{);;UL0&!Wn/pdc|:bH._y4N&r]>XJmJcyFP*E$^`^2zw'MHxY~;jm~K?v1%;}uJ\",\n\t\t\t\",~Io6vl2IE6IH$kby-Vdt{<`_EPm]NJ*O;bRJI7@iJ7q8gkMv'dNoZ;_aeYl}|1XWfb*+1^Yw)H]E%s:is-)BLq:K1t>a!orjZyEs5P.=XsmGct8axD.t?kDtAh!=g2*N-P@QoBYdu:B1w|;?kEvTNqx2&VU_Y3x**[I+Xkef4x%t3%SV]0>-Krtuv}&AR5*-fIt9RIXAA&?%9EIG{wu6<{6t=4lu&qK^q%m-&<:n,&GaaYNa-n4DD.,5`Kh$LezK'wt>`'6}?A*DSB?82Ni)>>}[O@3ml7Z`O0O'3w`cbI#EirlQ5A8H)&IeJCd^7`X*\",\n\t\t\t\"/lKkVWzvSP/wNNLi(xHY@aFVHXq~X:$=uYP!>vdYy%=-a7FjV&(WW/}{_Rzu/$_qh*m5sR9MW!ghoUy-/=+Qd1zR`S=/f&PCVO?GGH]f$'fz2Wk[tEt79JduH&l%#ll8iFxE{=.S*~Jt;sa?eMYPl2'Wu_5>X@hi8~5{mW<2F&}-S/+w5d@ZC>/0G0|15n)Fl~CAi3>KbgXLy+A;N5<two1jtd8/Kk/NjtskL:~ts7ZmKYzopbX[R3)EctA1PVx,>)F!YBv#W)nfl$,+^Ip<is2l'88y>s.['uD}6yriZ-Kv02qT@sRJ!8!)K,$6/Yijc2\",\n\t\t\t\"3C!Q^8llMl?e1E^^3y2,g|x~K#X-yP?'w&6n-OZy{=)v;jnYJI1jQ2BXT|)hXAg<~P4,z%<ep(38]6n;J?!))Y*Rn>QP/M~,#%4u(|/et.8?*mHRZF>G)&AmjFtqcq&Mxm:?Kr*bS+g%QsWzaGu$@S~0Sp<,j)&Y|N[}QTO`h/<LeMd51ztXnzhr.X[c1:+e(uT@UTl@Q%!iihiZOZ4vXG-|XYFbD!``i_nB9?+xmZ~wO$A[=gkE>7-2>LPg(E6*5vfm5W#hY?;E7SYXg%cKx8KVmfUNBz]MJ<}bi;I]*A|'=Z?:9y6qUIqHxWfZ9Bq~?,{\",\n\t\t\t\"7tfhFhN+In9@4y;uJX.Vz.^Y|HDc>_q1[n)N3v%FY(,Q66SPEOE'eN|8I%7{/%IaIVTX$Oe*IJ=i5}t01MK<7P_&VJ#!^~.h[QzE:X7.-ZMI([[*B7LUwNk=c$FLC|{Azoik.g;:nIv![_;#``chZNlWcVR:>y[)]N.p$[1%=X'WPd}aD~l:$N)Q1qz%;'dfKz-Z^-Ca0}6J9x/per{@X/lf/WCi_f,$w587~5u#Fg|8CVz;urpg0~Sp{!DPOppRLAj~~J+4:le?oVyif~fK]hm/oywcNih>7sO2q7@YEy,[[O2'sB]JdMT&:F9|+gJp/y~N\",\n\t\t\t\"=`*2pE~jAfzi:;'$9!8`/c|=v8Y`+p2k.Ic[T#D<zEcXyUVIq;%A;P?R^vi~x~=@)|;Wc`|^g@B#F67,+-|L[8MrUv#'k[w4^q'SF%%.'|e<8exT7}~#/$e)64<F3f>ol8Bb4((gt{4zGX$rx;w[|oCM+VgzPbr5;31s(07,}e6z>`*2iqtjRnQjIvTjTr}74zZ$Jtcg1hX~7Nn`*]SV:*V_'b'PNpS{f<iXQ$:ky]rj[L`y>a$B+oq+h$Y%$Fq{<4JUzd:=ktj]]Dg/v>Z;jwL5-SN.rD><`v8Nu}0Q>a@H=@.IGd,gjQGqAxrzyA|+uLgO6\",\n\t\t\t\"E&(aY$GfJIc;YVnE'4Yx1sTq[q$oJ[Z9P?X:I:,HWDQNR^&JBhRe6O~@Glt]?f`G[yG]{2qWTQy,lcAQ+,Dw:cdS_&c?X`DolV!!GDQ;QxY[mt}yqy+b/{4F;c0$@aiN*#x<fMsfq&uo'!b]eKt^.~vhT9(1EFeSWW-PtCL5.=.DxV/@|Rds7bQafBvVjqDX4~2'Enj#pl$J-WNF8;P-WSl_(_I,zf`Tm'yhThTy*v7;eg:mfU$=-RK/<m]ZD!=-o]FXk|b1qB)KO&;lMt0zi~gO^TZ~'$B2`j%97sWBVPjR@l>Ng~|`^W!59#vzxibkG[+i~N\",\n\t\t\t\"NOYA]|Zy%[E9w*'SQD[e9bd[R8dKhs'YlZQ,boXf^lnx(>$[]SW`f9i9Mt>N?QqI8m4byK0NHF<j/K*AUc;uXBX$~{9C;L)<hjg#{.haglq{'mX*J[_T>Dts5x8TRU!Kr2kpsy<meuZJ<Y]YIbU7&baz)l*bPw!G9TYO5hoN(>MO~/6UCpF?S,&VZCG$]R#Vj7TTfUMga<@aXC[<G<gp;?+4TZi`:eD1VJ_ixO,~fW1W0+{A$Ta~(C?tcLS-<H^_b-iZ.1QP@0g#H;BAUX4aI@%eWRgKYmXeL09X)&Rjj}%.=%HYWz$#5~8a:OGd(]zXxD|mz${\",\n\t\t\t\"Z[W;%Mkpe%k,g39A;OP<:V1ax}G?lf*5A0=G!gRXEE'0xBL#/+$i#`t:$2%Pn7p9s+z>>(TT}t(s+*<BBE@ZA>g:@)C812ZwHdr}(ZAb+7/HVI0E#bDK540?k<cUKEj/07puI&mY@XhY:p7|2)jNG1>adFmtRD_&45m(ogqz#42}4iW5=g!9:AgSLTdG$P0;3rSAFZD%s[N_*ZgU=m|calSAJ$wRm-opooIU-%]S,Cj@Jl04@oQn83fn'YtEIm)(-Ap#oMZ6{?Z#:t$YbUz{wcqyCMuMCO^cTR`C-R:}:'WdNp-RA1r~'ax#VMzM1Q=Qgj#.W,}k\",\n\t\t\t\"k6|k`H$MH32,G?mD+3X4kl_qi|a-+o3:&Xs.:,h#_^w1WjhF`ylHS1x-ZJY.}@['v7~Q#VJWm6Y-G~TLe&fcxP3NIgn*BU7{4TbOz#[Sj'cVy5p/K*N@H?-K%@r/9sF6bR`BZcOF=yX?a#d(UH}Kw*x!Ds-sDk6~A?rEwWiCSF#EBrKwE]B!VCeHS[<LJv*p+Z<]%N`G-!!&-1E[Zx.':/43=0k8ms<?cg?'2j+30+ytbKVC|-Hz3.5,4A]4rbvkVwCrxYh2M}:+Cx4rE)M{AXX}`=kHZr8'zdiIy<mt9uhFIeQ/X'jy?]`)dV{FXz!bkP3vpg#bo\",\n\t\t\t\"#!A7RqIK|K%Ji3sYP[kUMnn1I<'jh},;8<sW(Oxvbs|5QA>+hKp$52:AOH/tqA}@[rLcEH<1qP[R}3-kHS*.ALL0n)!^L<$nuPuD2?m#5n2wYZfjyYPR$@'gePjn#3SD`^{Ywjmb.IRaf6o}*U~nT0$t+e,T:yS0i]qG0OBz(k(dW]U7`IwofxFUvv,9SU9](VL>x|QCc>jWM^?le3C,.YOb]t}AFuFCntN3g}/7v%1wb?~Cdnr3!F'|%v?A|+h%i;I+f7Fz~EH#$Y#ykMTKfnsGk$%`d-/]++jURI*e<))dyckGC}SuEyF]4wjqtZ&N>Nd$3hO|(]*\",\n\t\t\t\"#<?J53IY~r2]](I`bq|1pA3rS<Nd@H@c(:M-k]>{xe^Mo[uIgh?4BDd_>7G?$u^aqLTBvr~YVn.JXc>>uO]OyAbk;_*KzSfsg7KQ:_8r6uOvOy#bW.16,&[wN|>s9r'sry%20S6D8yj#Mt!8#Y40?K;<rW.N,AMgxt-j(eB^{=@_z9[o8l&|5rq/Hm|iB(r52~lAA[RAeaq9x)]d^vP1^l}p%#p7Ohf)Vy{#>!Jjqr]Cm>+?3bnO+BEESMj';S)>DyTz{JdR!zc[$oLQ([MrH0[i:!<n@s(^#$#g,(@d>OPQ7`7@riNWzvSPs0uaA<ws_4z|QTU4+]E.\",\n\t\t\t\"#^zp}Y3dmNyNFYdW}N#O'impD9tcs[w,NvSkyDh*OOjDlx3XUF`5JHeJlP/u%i<I*4,XlN0$7QR-M*5kDrZphsk*GLQm_Y<a.Q*NzqR+?A-WEq_'z`55s@wiN%%kXC*l+rfK}K;v[]Rat>;4uzN'>3xqJ.Cv}P4e$%8CTqvyLLdF4}K)498fmgp/NAmvfiZSaKvh'j#8x&IU#K[^hQ7a`,++yDQr7XKPl9?^ksbs>nKI0O|_]mLuA`I{G7e7^%fKPRw,|fUtfun[,Npy$ET&@FQgtt,ZvAZ9ulk*ALI~LU;Dva7E;H|/Zy;).-{vFoWX%v*0V,=zoO]XZ\",\n\t\t\t\"$-XZIbQk5EX%|'=^06g-UWQQ,UrX(%21VJ2uZM7p*CV~c*I-mN<&'{7-$:^$xzq4,mE</IY-)H9SqF}GnVo<BhW8J81?Ld9Ztx~T_5nb7TuR6lT=S@TZ[VAa#D..hRD{HP,>Hr?wi`MTyx$>D|h?Jh2_xy,p7)c/~o:h.Gr)@(Y$1X?QGa1_-i-*#HRCk5v.T)oKa?uN-Q<$UXQu`Cmhh9[=+'P|3(a2*V;9l;9JB.{,![IPR4HP^[tBOO7$oqiO)d2%XTFIX5}RxZDOaOj3qOB~1iklMo_:#)?]ENgYwb(9g'W,d!y<*8y{XWshGQsLQJg$R&hhn^OJ7V\",\n\t\t\t\"$g@e{!IdK@kp}qbO6V(i!)ry:O]p~*^dI8[#2]kuwDX8fhf?w6U9n1FH:P(NO/$po<PAuvQ-r|=kkYmSn4FS^<?lc:iZ-N[9.H*bj6X{G'xo>S6Tdn,`H4n!.7W6E3%EohZEI2Spv.25LF74-.Iq/W(]'G)pe&~,Z-b'@rh%J@1%jgj'S$i#p.c!(0!/(qhH(Z|B,QMH8oEb7R9![B~ZT7FOyw4]-RBXhS/I-G]uv(qvo(4q}|nme#}lg{u(ZsLi2vm$Lz-Ie5_:lFcKehJpPJE,0!y^-SU8mrsdz&ej(H^81W*Q7ngFT>`sh03D-T%|NXlM43c|e_.I.Vs\",\n\t\t\t\"%T:di!5|Uw.6QR[h,i>_D^:<5)e9PM_}5sPW>;INAI]-YY1f(QhgBS_!H-`KIfHC29G}bt*!)x,>{%$-$a[btyf8!YRzQ?ud6mRAJ(=yXs=c#9c411vOp(=z$J~'7mcF^[mR*ri9w~P4?xfk&+dhO>asDcb'Y%<>;%O34v*l4Jo75aAP=d)*J0_LOZOpwIPsc}6'%)PnN(-9XR@/,zMkIT-,m;.J8z~D$%tMOXjIhQhEkXa.mRJacYEG&u:r7Z+Mj[|Ov-#_bTb,!VrCtL6nJid.dR/4)jV|]1jE6!QDXH03|ts.6(x2|(@%(R}yin)i_yOHI]5G)_]>yN4k\",\n\t\t\t\"&Xn$=~2(Ld<BhF'FQ//G#m$z'y!&^3@W14O-CNYoMA|hjaIl%y^.,LJ=cZ,Q.qsUl?D?{|w#pZ:|z+4ybgD_w9o3+|]>?RX1(7&TaJ1}Yc#SzC_T+a|?JIgt4I]K,wz!&}!]oN29FwV/Q5cB^_!/)Yr+%duKZr@,lNv%yzRSApr5&_D]xUX+y3hO5UvUue=}D<u9PH:MD,|xilIHiCrT@^we:rzr~jrYyc`CC<$],KQ~|Z|H:c@t`b/x?0>i22O+_5W*olB!e[1{egP3%$Si5oB-/0D1lXhe5m:L+uXF:o;@$8MfG7UP=[c{8TB>N:wtXTqb*['vrM(<7+C|V\",\n\t\t\t\"'|0p]1w;Ulg{*[aHODXhz3pP*(h*F'p@nwvO/j]<1'7)>cXK%1-amh<Ulc=kg3eg,p`g]T[~w8Uh#by{yGJ.d1P+>?0'0Ty7MpQTTy*oVk0}M71P93-hfLzz&uRZ22b{F7&BK*C|qag]tUaiEE4mPr5&5A}Nzc_p9SKSFvXGwxV>&rwSj1G3wL)v:&=mHkaFyyO0n&fMRUwSMMl(U^92ngs8/b%fpj!padysC?/w{W7Wt^Ki&q{(&r:TE((Mt0t#BPa%@V<8n*0'JN$v[(YGMF2X3WlC{+K9Y+)_mH,p-#Gz^5^JYN^x`<01lt9x@50?{e?hI))K*mlul*/0a:\",\n\t\t\t\")iq}8qDHN>vwf)K(,P@!Js,5^kt**9k|IBPd^)5;}lk&}'?JD=OU1S%+9a!f*S0}jWg0ol+f%^BYl*t#+5^iK'oK:Abh9HXNt3tf`HK<EaA$2C>k4fgQphn]RO6WQ5^gReq=BVYmVAo>4jPL`.Yc](0rp&Kr#RT0CAPBF^59B7Z%&i{t|#'}&Y>.1qDYoNXLyPCHWwT'RuEe2TR*C&70-{}=`}KGo'y_c%g[2dLD]{8(c38A2Dfe|3=2ZU3T&njF0iy']Va{itp5)QPF|?pT=xii`KCH/byzw^5#BDv(jPR)~``7y1Y1FNDzo5C%{CT.TVMTdi|`d(~dr2Q#U;6\",\n\t\t\t\",.[pR2,1ELu;PQDOMsIk5]HT*/J/TOePoDBLpx$Ck_`~dU1$+h9tL2,Jow%cpnP.J*$!'},~M_3-H,2OT5qO}|kuyMEW&$1oX~SD5Ah/l(T[*N51F=Z4+?^R~}Y`M*{,fhu]XF:1ZN;2Kd&@(kfRtkNctc^.{e6zin&V|+20BU5-D-=f<z1J^O=[kx0CXVtv!W4^#3~QLrz@$qay2-teJ0Y0uLg]=+cP}AJAJ/S-sv&P@|@I2&43cDME^D2@r~SedB<vbCT$D-*%OTq-^<BfMMpV^60L[.Pbpcq[d(1wiJB{_u1+/RvojM]4_@=8#ZZut~$qHi?2_?PfGbEG,>7V\",\n\t\t\t\"/9K>Ec@rcr:B-Sm5n1Az~*q[-*qgG`I1>si8BQvvCWQ8m%uR!QF~V<^K^'(:nH*@JAn^e0L[f6_Jz#2^n{,:>Us3m)yoq1^|tw}FwJl+xl>ZW{tK4GQ?YDQ&h5ea_PJ2Dof+wUu5Eqy[biJx<no.Ccs`%v.FZ)IRT$Bc.?k0V3V6'N2LWx.373MzR,gM+*!QoJat;9zxhb&k;PCcL2uWTeDx/B.yOk/jk]WhjQ5SH=`<aZ?MI8`?1_;nq;w=trV$LIY+t^)+g0g8wSywcURnAzp%v7.B$FAWk)BThW?F2#RkeFemBSaD<)}B@I7@md6+6_:b;64JysKK:X!tl0B#F\",\n\t\t\t\"3D#pRZ:<>Fu'e!*Z`-nVw^Aukh[q{b;#>RtG|I7Y'gvIK_F`+}XQZ7$H5]Va$^Z#EMFxsljfj~i)@!~xXbHAEubsD>1|1Forb60Y7JLT8VeUr%})?HF9h`~J@B7h#UW+>nO[eep;l9!pFr(f}HV{>J{VPsCU9Yfe&UmqvtAVY9G9czio`H:w#~![#V~do]JsVjTUhB3`wyRRmV~('T<#Da`xQ)<{*BTw]%[cWWjD/-Ka?~m{<<I]Qf4P'Hbr1bm[;3jX`KVvbE'Z|^4S,J(*aV&.:;Zn/M*9u_$?hvX$)bvY(2[S34J-eh&`>y@wd}*kHn*Qr6.[7nL}Af=y7O,^bN\",\n\t\t\t\"8mhZV4J-XR1/{ftDN4Lf3+K^RT(3(`].gu>*#/0Na2]t:y|+h`GQkxzC~:W6R!QLU<;]sL3zcoW1UJCTohnl4%7MfGB{?'dQL/+lp]ik$_DMGB[jIm}w4Oi1;m-Y}yQ&CXA~)_wi5z]=ah$,*|Txv]~!4H!w_&E-ot>CP35@Q,3(|[qvmH`;Ik>;*./hCdXNwQv%,hLefb$;p/yTV3^^<8y]jqkI)}<:x89C*bMVtZ5x-D,^nlm`KcS3B/0U;<8!~vC<9]]2_FPgGVA4_17.IrfTF:Y<6$xi*.`|9iY]/LD<Y93|@0WNTy7'<^zf2JS~1&;]WVHo(y$2smPH1qw)5XJ\",\n\t\t\t\"@$O1/kxR&oD8CG+78WST0DRU6BQ<+-#KL>6@ZV(_zIKNb0p+r^xbvDe+^w^7SG2gG+cKRx$zGChJ%;Z!*6J5$(Ra#=1$k2UgM.@C*M1Md+W:pt_XFA(s:S<_hrmK]J*gmn#<@hSLNzgRR!:aYb{Ww/uC+$%/<KCVVcWns,IV)w8har|%MJPX^=n|O-f|Y0j_TPqgJsEb|6A0vW^C)/DWDTe|}w(sO_@'Lw:uq9z}=jiR))*O:o>gOK-&cA4bP^F[DE%Vb]^)sp'm,2p22+ZCO!:[$Yvfm8W$c+z^sB'N8V+/lfg0zX{d;Ib3nmj{Hyzy/UF$BnupwH^s[,_<S|B;KG8*\",\n\t\t\t\"IZ/d/</NOmb$x;tc%HR|tpLqxU=N6?~.^QnLvw7J1>xZ|[W<@_!@:9`/r;3wX*&`TI08tZ7~@o/F;1aBwY2<<9fqifXM@%I_B|{>0L,%=rj^J#[>U,c:=7>o6`?hFw5p*M#|FuP{IdA,:oc=PzodU/z~w}B+J;wy(C87zk?ddV3@vq.wSV*X+cV*Qnfys5O8,FL+Ugi&;Ay'8I(#6heftIO'dj:4|kVnZEn6eB78La~?VW=LRdq[=kxESa?_iO:wp9<aBL5AQ~:wSs'#a$9{pp@oq3D<=-P~YxdV=^{|@4`]Ct5AheXrkJN0f&x(0$.7|Cz__K$(p^{X^l@RL)hx?kQc2\",\n\t\t\t\"VCi;F4*}!9i#Q!z2tZh4n+Q'B3EY3@USxf0JGXJhSm4]B=Kb-r+k:'BUy`Hahl=GP'U`L**~A)iNqvvcl*rcwHL~l3Nv#S+_Z#XLA)l/a!6KYunvcAGO.^`Fut.Yx`2E$s5g?C)v$JVvr/GFC`mpOmx#3!}57zp1I6AJ[1%WOogI)P~13_n)<UKdXcnoFn'Rd8&=j4=I5a3nvoN9LoVI3vE:UyLcP(hWWJ+sk/MiLL1Zbt]:V=P1<deL}A.fM}alkcg)t!o%qJylt7+0-&I?zq1TMXu0{,EzK5)j'Y,<hsa'vt=#a>*e6^/6Liq}6+@%'#K&sGowCWu66#Z,^ws)S?ZZi{\",\n\t\t\t\"hE?Mdq,e!+FZ^FOEnx54'3Ok;<!(u%QH~QV^q!5t4>{{]wd#.gYc|9ZQ0(JF6Kwi_tQl5sn^)xd@XNv#Ds!j'X$2Cj4>gOXiMq=-i;]Tq3+$UR_i$,D;x%53qN-`ZUU~MK0i3dV6UMLW7q{Rav~5fc9ZE[wJh:v7$.HMpcMd<@G){O2;5DZ}<*k]h~@;*@::&>M1*&xGm..W3v5P[R_k#jiY]6rZKx4.LiK,A{2qx.1)=|1}>=uCc;iw}S_RVDjQA!?[se5uRbhS%OD!}Y2vN2XJT8_P']#$lM]dq.)(#`/HlByb79k=ZL^-vH2}u*i~|egVZ2ipL4YE1xIn9)q=qO{X+YN\",\n\t\t\t\"#!.-0p(g8}z|kNr'x.pP}OQb9r:oVoAwY$(te'mG#0cl}O/;KRg^Ei$4TR+v:RxIfEnB<$*.iac8]_aKxI+['kMtb3#BK+4OrV]lrZb*3cdop@7e=}+9d#B)s5dLx#_>Er~t$8_D.~8cY+36;eA0;q9/g=ZxrqrqjwWHsmImu_mV3(|*11Z6iYi_Yg&E$r$?^ep1#Gt+$RgIq3U;z^i{6lX.oNHs%0bik~'?tJ%[[{[-jESg=:;k=9Gm4bpQ$z=fQ8YF:'ZKP*.xMK`G1$8+3~`5tv#kNE$VPuFNdJ->t701Y!!$6#I}3t^P^,j&8(24c{:5WRtW+D9!DjX+WM,l,rgx.%rK6\",\n\t\t\t\"#@Y[_pgp>8hl!_8&I^Hr1c61`oYZyfltUCE!,W|OtCk(xIB+UPXiFx`y!~bPiIK^aLH3qs]/=Bzd#|R([_?A&o4sw4/q%B,:1LN!A;bf^TT>ZBefH6:-onGa{M,;sXEkQ+POR1({9H.7LRLBL|(wad6ioG^B/oY.,ZIilztb+RL7@y4K!uKTr>y>F36'b<pPcJ_7]8D=AeLbD<%1|a!+Z`c?i3zI[LV?Or_o$kW*(OB~*_U?}[;L*Z.r5eY_WFAJc[JuJ1?;cAB:qUQb.g-=-i{*V+hOP-Y@JF%ZYw<kg~Y=+#3$z@#[_~wn0ya}lK:k_q{5mA'3tNW6fj97_ngEUn8pUr|YbN\",\n\t\t\t\"#jQ*,]7ea17g{W5f&9W6conksw7+I_u~Yr8~yDyJ9jA32Pf(6.6fx]E;@Q56(Fbf:F8rk+h6eV-.8{Xf^krkQWQGaq>ho'+3Q$ArW63v?6Nt%`+o_vz)'iy=4ZE~MogN(yT'zG2x?BJU?^wwJx,2tbadr|w@B^Fukj/?5DL-5XbToa`D0{nfw!_dcfI'6G<6WZ9Km?+RW4VgsVT]{p.:#m}!~j(KVjQbz!<D-5VDs2/+K#`o;Lwn%U!%hNe?q+rnze.D)U+e/u>u,:^-m/~?~@&YG+>0)bc-x(sLiCohQr?F7sWQ$aozJO;AZL5U=Y#W&R.tXx<lr>Z)P_~<$m*T77dV,C&~bu{\",\n\t\t\t\"$DSmthwzpd;|Y!0N@EwR|<'Gk|:s-kG9K<@p;d^px7&9TXm<N<Jt`Vata=2hbOm=T1?){6xp8[DXvfW^_l+cAb(rt>2-nYrGwjuXy07.+iY?%eC-5x~[aMd0{]VAXl4Bt(y;ntAzr4o6R<xxTIL.,jR9NocyO%xsMR6a>$VI)Nul:cf%<BGZQ0/#Ut}nWyr;QVZ'&@]L5=Y|t!cJXHBCX0`_w&u$`5Iii6.g3%}fWWAp@4R&EVN&ksXYM]s3#P'~g2|AH/F-W.=DzIK1q0Xm$wO6S<>[Z59PNPzB6<cSBpt),4t>kqZk`(7._xvQFQp)ryD&vPW$U^,CDFk4n|;E):Us$s<Gy|Hk\",\n\t\t\t\"%2e[;,B|/Eu/ZE4lNtcjC.R6.fe@z5%2PN<,:D:K)O5vAa,YxM#q{S}A:<DOs/uLs8DB&D^Sx>vxNSM-l.fH,S[lS):qrPY3lb!,g`l'A~Syu|(|0?pjXEY[wZXIOM$;zs??,~g]v0gR~Do3]>6d.4{c($[<Qv^Wiv![/,xru^c=lBuvpq:lbN:0(Or4[|i=pxfT&V:-N<YbgC)M4d*gNI3,!.:IIaA.E=WOUqxwXC,kboWnpgZLN_e9!&g-IP6K)Es3w]Z`V@Y,;>:j>?/d1huGG(aI|?Jc.o6Y#/<tl0zy>_+aJoxiU8%qIPkwPSTmjWt.ngDEk4U8GjT1~Z5hmHX8>wHskb1jo\"};\n\t\n\tstatic String chars = \"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~\";\n\tstatic int N = 400;\n\tstatic long mod;\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong b = chars.length();\n\t\tint n = sc.nextInt();\n\t\tmod = sc.nextLong();\n\t\tif(n > 110) {\n\t\t\tchar[] s = vals[n-111].toCharArray();\n\t\t\tlong res = 0;\n\t\t\tfor(char c: s) {\n\t\t\t\tres *= b;\n\t\t\t\tres += chars.indexOf(c);\n\t\t\t\tres %= mod;\n\t\t\t}\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\telse {\n\t\t\tc = new long[N+1][N+1];\n\t\t\tc[0][0] = 1;\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tc[i][0] = 1;\n\t\t\t\tfor(int j = 1; j <= i; j++){\n\t\t\t\t\tc[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdpcl = new long[N+1][N+1];\n\t\t\tdpop = new long[N+1][N+1];\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\tdpcl[i][j] = -1;\n\t\t\t\t\tdpop[i][j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tfor(int j = 0; j <= n-1; j++){\n\t\t\t\t\tfor(int a = 0; a <= j; a++) {\n\t\t\t\t\t\tlong leftv = dpop(i, a);\n\t\t\t\t\t\tlong rightv = dpop(n-i-1, j-a);\n\t\t\t\t\t\tlong curr = leftv * rightv % mod;\n\t\t\t\t\t\tlong fac = c[j][a];\n\t\t\t\t\t\tlong v = curr * fac % mod;\n\t\t\t\t\t\tres = (res + v) % mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(res);\n\t\t}\n\t}\n\n\tstatic long[][] c, dpcl, dpop;\n\tstatic long dpcl(int n, int k) {\n\t\tif(dpcl[n][k] >= 0) return dpcl[n][k];\n\t\tif(n == 0 || n == 1) {\n\t\t\tif(k == 0) {\n\t\t\t\treturn dpcl[n][k] = 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn dpcl[n][k] = 0;\n\t\t\t}\n\t\t}\n\t\tif(k == 0) { // n > 1\n\t\t\treturn dpcl[n][k] = 0;\n\t\t}\n\t\tlong res = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tfor(int a = 0; a <= k-1; a++) {\n\t\t\t\tlong leftv = dpcl(i, a);\n\t\t\t\tlong rightv = dpcl(n-i-1, k-1-a);\n\t\t\t\tlong curr = leftv * rightv % mod;\n\t\t\t\tlong fac = c[k-1][a];\n\t\t\t\tlong v = curr * fac % mod;\n\t\t\t\tres = (res + v) % mod;\n\t\t\t}\n\t\t}\n\t\treturn dpcl[n][k] = res;\n\t}\n\tstatic long dpop(int n, int k) {\n\t\tif(dpop[n][k] >= 0) return dpop[n][k];\n\t\tif(n == 0) {\n\t\t\tif(k == 0) {\n\t\t\t\treturn dpop[n][k] = 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn dpop[n][k] = 0;\n\t\t\t}\n\t\t}\n\t\tif(k == 0) { // n > 0\n\t\t\treturn dpop[n][k] = 0;\n\t\t}\n\t\tlong res = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tfor(int a = 0; a <= k-1; a++) {\n\t\t\t\tlong leftv = dpcl(i, a);\n\t\t\t\tlong rightv = dpop(n-i-1, k-1-a);\n\t\t\t\tlong curr = leftv * rightv % mod;\n\t\t\t\tlong fac = c[k-1][a];\n\t\t\t\tlong v = curr * fac % mod;\n\t\t\t\tres = (res + v) % mod;\n\t\t\t}\n\t\t}\n\t\treturn dpop[n][k] = res;\n\t}\n\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Compute {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        long M = sc.nextInt();\n        long fact[] = new long[n+1];\n        long inv[] = new long[n+1];\n        long ifact[] = new long[n+1];\n        long dp[][] = new long[n+1][n+1];\n        fact[1] = 1;\n        ifact[1] = 1;\n        ifact[0] = 1;\n        inv[1] = 1;\n        dp[1][1] = 1;\n        \n        for(int i = 2; i <= n; i++) {\n            fact[i] = (i*fact[i-1]) % M;\n            inv[i] = (inv[(int)(M % i)]*(M - M/i)) % M;\n            dp[i][i] = (dp[i-1][i-1] * 2) % M;\n            ifact[i] = (ifact[i-1]*inv[i]) % M;\n        }\n            \n        for(int i = 3; i <= n; i++) {\n            for(int j = i/2 + 1; j <= i-1; j++) {\n                for(int k = 2; k <= i-1 && j-k+1 > (i-k)/2; k++) {\n                    dp[i][j] = (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)) % M;   \n                }\n            }   \n        }\n        \n        long sum = 0;\n        for(int i = n/2 + 1; i <= n; i++)\n            sum = (sum + dp[n][i]) % M;\n        \n        System.out.println(sum % M);\n    }\n}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdA {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n\tpublic static void main(String[] havish) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tmod = sc.nextLong();\n\t\tlong[] fact = new long[401];\n\t\tlong[] twopowers = new long[401];\n\t\tfact[0] = 1;\n\t\ttwopowers[0] = 1;\n\t\tfor(int j = 1;j<=400;j++){\n\t\t\ttwopowers[j] = twopowers[j-1] * 2L;\n\t\t\ttwopowers[j] %= mod;\n\t\t\tfact[j] = fact[j-1] * j;\n\t\t\tfact[j] %= mod;\n\t\t}\n\t\tlong[][] choose = new long[401][401];\n\t\tfor(int j = 0;j<=400;j++){\n\t\t\tfor(int k = 0;k<=j;k++){\n\t\t\t\tchoose[j][k] = fact[j];\n\t\t\t\tchoose[j][k] *= inv(fact[k]);\n\t\t\t\tchoose[j][k] %= mod;\n\t\t\t\tchoose[j][k] *= inv(fact[j-k]);\n\t\t\t\tchoose[j][k] %= mod;\n\t\t\t}\n\t\t}\n\t\tlong[][] dp = new long[n+1][n+1]; //prefix, # of autos\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tdp[j][0] = twopowers[j-1];\n\t\t}\n\t\tfor(int k = 0;k<n;k++){  //number of autos\n\t\t\tfor(int j = 1;j<=n;j++){ //prefix\n\t\t\t\tif (k > j)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(int add = 2; j+add <= n; add++){\n\t\t\t\t\tlong prod = dp[j][k] * choose[j-k+add-1][add-1];\n\t\t\t\t\tprod %= mod;\n\t\t\t\t\tprod *= twopowers[add-2];\n\t\t\t\t\t\n\t\t\t\t\tdp[j+add][k+1] += prod;\n\t\t\t\t\tdp[j+add][k+1] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int s = 0;s<=n;s++){\n\t\t\tans+=dp[n][s];\n\t\t\tans %= mod;\n\t\t}\n\t\tout.println(ans);\n \t\tout.close();\n \t\t\n \t}\n\tpublic static long inv(long n){\n\t\treturn power(n, mod-2);\n\t}\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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_2020_GlobalRound_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 log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\n\tstatic InputReader reader;\n\n\tstatic long[][] binom;\n\n\tstatic void buildBinom(int N){\n\t\tint MAX=N+1;\n\t\tbinom=new long[MAX+1][];\n\t\tfor (int i=0;i<MAX+1;i++)\n\t\t\tbinom[i]=new long[i+1];\n\t\tbinom[0][0]=1;\n\t\tfor (int i=1;i<MAX;i++){\n\t\t\tbinom[i][0]=1;\n\t\t\tbinom[i][i]=1;\n\t\t\tfor (int j=0;j<i;j++) {\n\t\t\t\tbinom[i+1][j+1]=(binom[i][j]+binom[i][j+1])%mod;\n\t\t\t}\n\t\t\t//log(binom[i]);\n\t\t}\n\t\tlog(\"binom done\");\n\t}\n\tstatic long mod;\n\t\n\tstatic long solve(int n) {\n\t\tlong[] pow2=new long[n+1];\n\t\tpow2[0]=1;\n\t\tfor (int i=1;i<=n;i++) {\n\t\t\tpow2[i]=pow2[i-1]<<1;\n\t\t\twhile (pow2[i]>=mod)\n\t\t\t\tpow2[i]-=mod;\n\t\t}\n\t\tbuildBinom(n);\n\t\t\n\t\n\t\tlong[][] dp=new long[n+1][n+1];\n\t\tdp[1][1]=1;\n\t\tfor (int i=1;i<=n;i++) {\n\t\t\tdp[i][i]=pow2[i-1];\n\t\t\t//log(\"base:\"+dp[i][i]);\n\t\t\tfor (int j=1;j<i-1;j++){\n\t\t\t\tint me=i-j-1;\n\t\t\t\tfor (int cn=1;cn<=j;cn++) {\n\t\t\t\t\t//log(\"j:\"+j+\" cn:\"+cn+\" dp:\"+dp[j][cn]);\n\t\t\t\t\t//log(\"perm:\"+binom[cn+me][cn]);\n\t\t\t\t\tlong a=dp[j][cn]*binom[cn+me][cn];\n\t\t\t\t\tif (a>=mod)\n\t\t\t\t\t\ta%=mod;\n\t\t\t\t\ta*=pow2[me-1];\n\t\t\t\t\tif (a>=mod)\n\t\t\t\t\t\ta%=mod;\n\t\t\t\t\tdp[i][cn+me]+=a;\n\t\t\t\t\tif (dp[i][cn+me]>=mod)\n\t\t\t\t\t\tdp[i][cn+me]-=mod;\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=0;\n\t\tfor (int i=n/2;i<=n;i++) {\n\t\t\tans+=dp[n][i];\n\t\t\tans%=mod;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) throws Exception  {\n\n\t\tlog(400*400*400);\n\t\treader=new InputReader(System.in);\n\t\tint n=reader.readInt();\n\t\tmod=reader.readInt();\n\t\t\n\t\tSystem.out.println(solve(n));\n\n\t}\n\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\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", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic int m;\n\tstatic long pow(long b, int p) {\n\t\tlong ret = 1;\n\t\twhile (p > 0) {\n\t\t\tif ((p&1) == 1) ret = b*ret%m;\n\t\t\tb = b*b%m;\n\t\t\tp >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = readInt(); m = readInt();\n\t\tlong[] fac = new long[n + 1], pow2 = new long[n + 1];\n\t\tlong[][] C = new long[n + 1][n + 1], dp = new long[n + 1][n + 1];\n\t\tfac[0] = pow2[0] = 1;\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tfac[i] = i*fac[i - 1]%m;\n\t\t\tpow2[i] = 2*pow2[i - 1]%m;\n\t\t\tfor (int j = 0; j <= i; ++j)\n\t\t\t\tC[i][j] = fac[i]*(pow(fac[j], m - 2)*pow(fac[i - j], m - 2)%m)%m;\n\t\t}\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tdp[i][i] = pow2[i - 1];\n\t\t\tfor (int j = 0; j <= i; ++j)\n\t\t\t\tfor (int k = 1; i + k + 1 <= n; ++k)\n\t\t\t\t\tdp[i + k + 1][j + k] = (dp[i + k + 1][j + k] + dp[i][j]*(C[j + k][k]*pow2[k - 1]%m))%m;\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int i = 1; i <= n; ++i)\n\t\t\tans = (ans + dp[n][i])%m;\n\t\tSystem.out.println(ans);\n\t}\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st;\n\tstatic 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\tstatic int readInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class e_g14 {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\t// TODO Auto-generated method stub\n\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tOutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\t\n\t\tint T = 1;\n\t\tSolver A = new Solver(in, out); \n\t\t\n\t\tfor(int aa = 0; aa < T; aa++) {\n\t\t\tA.answer(aa + 1);\n\t\t}\n\t\t\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic class Solver {\n\t\tFastScanner in;\n\t\tPrintWriter out;\n\t\t\n\t\tint n;\n\t\tlong m;\n\t\t\n\t\tlong [] fact, pow, choose [], dp[];\n\n\t\tpublic Solver(FastScanner in, PrintWriter out) {\n\t\t\tthis.in = in;\n\t\t\tthis.out = out;\n\t\t}\n\t\t\n\t\tpublic void answer(int aa) throws Exception {\n\t\t\tn = in.nextInt();\n\t\t\tm = in.nextLong();\n\t\t\t\n\t\t\tfact = new long [n+5];\n\t\t\tchoose = new long [n+5][n+5];\n\t\t\tdp = new long [n+2][n+2];\n\t\t\tpow = new long [n+2];\n\t\t\t\n\t\t\tinit();\n\t\t\t\n\t\t\tdp[0][0] = 1;\n\t\t\tfor(int i = 0; i <= n; i++) {\n\t\t\t\tfor(int j = 0; j <= i; j++) {\n\t\t\t\t\tfor(int k = 1; i+k <= n; k++) {\n\t\t\t\t\t\tdp[i+k+1][j+k] += (dp[i][j]*choose[j+k][k]%m)*pow[k-1];\n\t\t\t\t\t\tdp[i+k+1][j+k] %= m;\n\t\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\tlong ans = 0;\n\t\t\tfor(int i = 0; i <= n; i++) {\n\t\t\t\tans += dp[n+1][i];\n\t\t\t\tans %= m;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(ans);\n\t\t}\n\t\t\n\t\tpublic void init() {\n\t\t\tfact[0] = 1;\n\t\t\tfor(int i = 1; i <= n+4; i++) {\n\t\t\t\tfact[i] = (i*fact[i-1])%m;\n\t\t\t}\n\t\t\t\n\t\t\tpow[0] = 1;\n\t\t\tfor(int i = 1; i <= n+1; i++) {\n\t\t\t\tpow[i] = (2*pow[i-1])%m;\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0; i <= n+4; i++) {\n\t\t\t\tfor(int j = 0; j <= i; j++) {\n\t\t\t\t\tchoose[i][j] = choose(i, j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate long choose(int a, int b) {\n\t\t\tlong res = (fact[a] * inv((fact[b] * fact[a-b])%m))%m;\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tprivate long power (long x, long y) {\n\t\t\tlong res = 1;\n\t\t\twhile(y > 0) {\n\t\t\t\tif(y%2 == 1) res = (res*x)%m;\n\t\t\t\tx = (x*x)%m;\n\t\t\t\ty /= 2;\n\t\t\t}\n\t\t\treturn (res%m);\n\t\t}\n\t\t\n\t\tprivate long inv (long a) {\n\t\t\treturn power(a, m-2);\n\t\t}\n\t\t\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(stream));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic FastScanner(String fileName) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(new File(fileName)));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic String next() throws Exception {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws Exception {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws Exception {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic Double nextDouble() throws Exception {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() throws Exception {\n\t\t\tif (st.hasMoreTokens()) {\n\t\t\t\tStringBuilder str = new StringBuilder();\n\t\t\t\tboolean first = true;\n\t\t\t\twhile (st.hasMoreTokens()) {\n\t\t\t\t\tif (first) {\n\t\t\t\t\t\tfirst = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstr.append(\" \");\n\t\t\t\t\t}\n\t\t\t\t\tstr.append(st.nextToken());\n\t\t\t\t}\n\t\t\t\treturn str.toString();\n\t\t\t} else {\n\t\t\t\treturn br.readLine();\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tpublic static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) throws IOException {\n\t\treadInput();\n\t\tout.close();\n\t}\n\t\n\tstatic long[][] dp;\n\tstatic int n;\n\tstatic long m;\n\t\n\n\tstatic long pow(long b, long e) {\n\t\tif (e== 0) return 1;\n\t\tlong r= pow(b,e/2);\n\t\tr = r * r % m;\n\t\tif ((e&1)==1) return r *b%m;\n\t\treturn r;\n\t}\n\t\n\tstatic long modinv(long a) {return pow(a,m-2);}\n\t\n\tstatic long solve(int len, int num) {\n\t\tif (len == -1 && num == -1) return 1;\n\t\tif (num < 0 || len <= 0) return 0;\n\t\tif (dp[len][num] == -1) {\n\t\t\tdp[len][num] = 0;\n\t\t\tfor (int i = 0; i < len; i++) {\n\t\t\t\tif (i == 1) continue;\n\t\t\t\tlong sol = pow[len-i-1]*solve(i-1,num-1)%m;\n\t\t\t\tsol = sol * faci[len-i]% m;\n\t\t\t\tdp[len][num] += sol;\n\t\t\t\tdp[len][num] %= m;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\treturn dp[len][num];\n\t}\n\tstatic long[] fac, faci, pow;\n\t//asdf\n\tpublic static void readInput() throws IOException {\n\t\t// br = new BufferedReader(new FileReader(\".in\"));\n\t\t// out = new PrintWriter(new FileWriter(\".out\"));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tn = Integer.parseInt(st.nextToken());\n\t\tm = Long.parseLong(st.nextToken());\n\t\tfac = new long[500];\n\t\tpow = new long[500];\n\t\tfaci = new long[fac.length];\n\t\tfac[0] = pow[0] = 1;\n\t\tfaci[0] = modinv(fac[0]);\n\t\tfor (int i = 1; i < fac.length; i++) {\n\t\t\tfac[i] = fac[i-1]*i%m;\n\t\t\tfaci[i] = modinv(fac[i]);\n\t\t\tpow[i] = pow[i-1] * 2 % m;\n\t\t}\n\t\tdp = new long[n+1][n+1];\n\t\tfor (long[] a: dp) Arrays.fill(a, -1);\n\t\t// Number of ways to make a segment of length x is 2^(x-1)\n\t\t// DP: Given position I.\n\t\tlong ans =0 ;\n\t\tfor (int i = 0 ; i <= n/2+1; i++) {\n\t\t\t//System.out.println(i + \": \" + solve(n,i) + \" \" + (n-i) + \" \" + (i));\n\t\t\tlong sol = solve(n,i) * fac[n-i];\n\t\t\tsol %= m;\n\t\t\tans += sol;\n\t\t}\n\t\tout.println(ans%m);\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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 long MOD = 1000000007;\n\tprivate static final int MAXN = 100000;\n\n\tvoid solve() {\n\t\tint T = 1;// ni();\n\t\tfor (int i = 0; i < T; i++) {\n\t\t\tsolve(i);\n\t\t}\n\t}\n\n\tstatic final int N = 405;\n\tstatic long[][] dp = new long[N][N];\n\tstatic long[] p2 = new long[N];\n\tstatic long[] fac = new long[N];\n\tstatic long[] ifac = new long[N];\n\n\tpublic static long bino(int n, int k) {\n\t\treturn ((fac[n] * ifac[n - k]) % MOD * ifac[k]) % MOD;\n\t}\n\n\tvoid solve(int T) {\n\t\tint n = ni();\n\t\tMOD = nl();\n\n\t\tfac[0] = 1;\n\t\tifac[0] = 1;\n\t\tp2[0] = 1;\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tfac[i] = (fac[i - 1] * i) % MOD;\n\t\t\tp2[i] = (p2[i - 1] * 2) % MOD;\n\t\t}\n\t\tifac[n] = power(fac[n], MOD - 2);\n\t\tfor (int i = n - 1; i > 0; --i) {\n\t\t\tifac[i] = (ifac[i + 1] * (i + 1)) % MOD;\n\t\t}\n\t\tdp[0][0] = 1;\n\t\tfor (int i = 0; i <= n; ++i) {\n\t\t\tfor (int j = 0; j <= i; ++j) {\n\t\t\t\tfor (int k = 1; i + k <= n; ++k) {\n\t\t\t\t\tdp[i + k + 1][j\n\t\t\t\t\t\t\t+ k] = (dp[i + k + 1][j + k] + ((dp[i][j] * p2[k - 1]) % MOD * bino(k + j, k)) % MOD) % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i <= n; ++i) {\n\t\t\tans = (ans + dp[n + 1][i]) % MOD;\n\t\t}\n\n\t\tout.println(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\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<Integer> na2(int n) {\n\t\tList<Integer> a = new ArrayList<Integer>();\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}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "//package global14;\n\nimport java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class E2 {\n\tInputStream is;\n\tFastWriter out;\n\tString INPUT = \"\";\n\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[] enumPows(int a, int n, int mod)\n\t{\n\t\ta %= mod;\n\t\tlong[] pows = new long[n+1];\n\t\tpows[0] = 1;\n\t\tfor(int i = 1;i <= n;i++)pows[i] = pows[i-1] * a % mod;\n\t\treturn pows;\n\t}\n\n\n\tvoid solve()\n\t{\n\t\tint N = ni();\n\t\tfinal int mod = ni();\n\n\t\tlong[] p2 = enumPows(2, 1000, mod);\n\t\tint[][] fif = enumFIF(1000, mod);\n\n\t\tlong[][] dp = new long[N+2][N+1];\n\t\tdp[0][0] = 1;\n\t\tfor(int i = 0;i <= N+1;i++){\n\t\t\tfor(int j = 0;j <= N;j++){\n\t\t\t\t// 11110\n\t\t\t\tfor(int k = 1;i+k+1 <= N+1 && j+k <= N;k++){\n\t\t\t\t\tdp[i+k+1][j+k] += dp[i][j] * fif[1][k] % mod * p2[k-1];\n\t\t\t\t\tdp[i+k+1][j+k] %= mod;\n\t\t\t\t}\n\t\t\t}\n//\t\t\ttr(dp[i]);\n\t\t}\n\n\t\tlong ans = 0;\n\t\tfor(int i = 1;i <= N;i++){\n\t\t\tans += dp[N+1][i] * fif[0][i];\n\t\t\tans %= mod;\n\t\t}\n\t\tout.println(ans);\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 FastWriter(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\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 char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[][] nmi(int n, int m) {\n\t\tint[][] map = new int[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\n\t\treturn map;\n\t}\n\n\tprivate int ni() { return (int)nl(); }\n\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\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\tpublic static class FastWriter\n\t{\n\t\tprivate static final int BUF_SIZE = 1<<13;\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\n\t\tprivate final OutputStream out;\n\t\tprivate int ptr = 0;\n\n\t\tprivate FastWriter(){out = null;}\n\n\t\tpublic FastWriter(OutputStream os)\n\t\t{\n\t\t\tthis.out = os;\n\t\t}\n\n\t\tpublic FastWriter(String path)\n\t\t{\n\t\t\ttry {\n\t\t\t\tthis.out = new FileOutputStream(path);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter write(byte b)\n\t\t{\n\t\t\tbuf[ptr++] = b;\n\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(char c)\n\t\t{\n\t\t\treturn write((byte)c);\n\t\t}\n\n\t\tpublic FastWriter write(char[] s)\n\t\t{\n\t\t\tfor(char c : s){\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(String s)\n\t\t{\n\t\t\ts.chars().forEach(c -> {\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t});\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(int l) {\n\t\t\tif (l >= 1000000000) return 10;\n\t\t\tif (l >= 100000000) return 9;\n\t\t\tif (l >= 10000000) return 8;\n\t\t\tif (l >= 1000000) return 7;\n\t\t\tif (l >= 100000) return 6;\n\t\t\tif (l >= 10000) return 5;\n\t\t\tif (l >= 1000) return 4;\n\t\t\tif (l >= 100) return 3;\n\t\t\tif (l >= 10) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(int x)\n\t\t{\n\t\t\tif(x == Integer.MIN_VALUE){\n\t\t\t\treturn write((long)x);\n\t\t\t}\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(long l) {\n\t\t\tif (l >= 1000000000000000000L) return 19;\n\t\t\tif (l >= 100000000000000000L) return 18;\n\t\t\tif (l >= 10000000000000000L) return 17;\n\t\t\tif (l >= 1000000000000000L) return 16;\n\t\t\tif (l >= 100000000000000L) return 15;\n\t\t\tif (l >= 10000000000000L) return 14;\n\t\t\tif (l >= 1000000000000L) return 13;\n\t\t\tif (l >= 100000000000L) return 12;\n\t\t\tif (l >= 10000000000L) return 11;\n\t\t\tif (l >= 1000000000L) return 10;\n\t\t\tif (l >= 100000000L) return 9;\n\t\t\tif (l >= 10000000L) return 8;\n\t\t\tif (l >= 1000000L) return 7;\n\t\t\tif (l >= 100000L) return 6;\n\t\t\tif (l >= 10000L) return 5;\n\t\t\tif (l >= 1000L) return 4;\n\t\t\tif (l >= 100L) return 3;\n\t\t\tif (l >= 10L) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(long x)\n\t\t{\n\t\t\tif(x == Long.MIN_VALUE){\n\t\t\t\treturn write(\"\" + x);\n\t\t\t}\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(double x, int precision)\n\t\t{\n\t\t\tif(x < 0){\n\t\t\t\twrite('-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tx += Math.pow(10, -precision)/2;\n\t\t\t//\t\tif(x < 0){ x = 0; }\n\t\t\twrite((long)x).write(\".\");\n\t\t\tx -= (long)x;\n\t\t\tfor(int i = 0;i < precision;i++){\n\t\t\t\tx *= 10;\n\t\t\t\twrite((char)('0'+(int)x));\n\t\t\t\tx -= (int)x;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(char c){\n\t\t\treturn write(c).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(int x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(double x, int precision){\n\t\t\treturn write(x, precision).writeln();\n\t\t}\n\n\t\tpublic FastWriter write(int... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(int x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(long... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(long x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln()\n\t\t{\n\t\t\treturn write((byte)'\\n');\n\t\t}\n\n\t\tpublic FastWriter writeln(int... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[] line)\n\t\t{\n\t\t\treturn write(line).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[]... map)\n\t\t{\n\t\t\tfor(char[] line : map)write(line).writeln();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(String s)\n\t\t{\n\t\t\treturn write(s).writeln();\n\t\t}\n\n\t\tprivate void innerflush()\n\t\t{\n\t\t\ttry {\n\t\t\t\tout.write(buf, 0, ptr);\n\t\t\t\tptr = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic void flush()\n\t\t{\n\t\t\tinnerflush();\n\t\t\ttry {\n\t\t\t\tout.flush();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"flush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter print(byte b) { return write(b); }\n\t\tpublic FastWriter print(char c) { return write(c); }\n\t\tpublic FastWriter print(char[] s) { return write(s); }\n\t\tpublic FastWriter print(String s) { return write(s); }\n\t\tpublic FastWriter print(int x) { return write(x); }\n\t\tpublic FastWriter print(long x) { return write(x); }\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\n\t\tpublic FastWriter println(char c){ return writeln(c); }\n\t\tpublic FastWriter println(int x){ return writeln(x); }\n\t\tpublic FastWriter println(long x){ return writeln(x); }\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\n\t\tpublic FastWriter println(String s) { return writeln(s); }\n\t\tpublic FastWriter println() { return writeln(); }\n\t}\n\n\tpublic void trnz(int... 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// print ids which are 1\n\tpublic void trt(long... o)\n\t{\n\t\tQueue<Integer> stands = new ArrayDeque<>();\n\t\tfor(int i = 0;i < o.length;i++){\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\n\t\t}\n\t\tSystem.out.println(stands);\n\t}\n\n\tpublic 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\tpublic void tf(boolean[]... b)\n\t{\n\t\tfor(boolean[] r : b) {\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\n\t\t\tSystem.out.println();\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic void tf(long[]... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long[] r : b) {\n\t\t\t\tfor (long x : r) {\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\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\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic void tf(long... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long x : b) {\n\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\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", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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_2020_GlobalRound_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 log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\n\tstatic InputReader reader;\n\n\tstatic long[][] binom;\n\n\tstatic void buildBinom(int N){\n\t\tint MAX=N+1;\n\t\tbinom=new long[MAX+1][];\n\t\tfor (int i=0;i<MAX+1;i++)\n\t\t\tbinom[i]=new long[i+1];\n\t\tbinom[0][0]=1;\n\t\tfor (int i=1;i<MAX;i++){\n\t\t\tbinom[i][0]=1;\n\t\t\tbinom[i][i]=1;\n\t\t\tfor (int j=0;j<i;j++) {\n\t\t\t\tbinom[i+1][j+1]=(binom[i][j]+binom[i][j+1])%mod;\n\t\t\t}\n\t\t\t//log(binom[i]);\n\t\t}\n\t\tlog(\"binom done\");\n\t}\n\tstatic long mod;\n\t\n\tstatic long solve(int n) {\n\t\tlong[] pow2=new long[n+1];\n\t\tpow2[0]=1;\n\t\tfor (int i=1;i<=n;i++) {\n\t\t\tpow2[i]=pow2[i-1]<<1;\n\t\t\twhile (pow2[i]>=mod)\n\t\t\t\tpow2[i]-=mod;\n\t\t}\n\t\tbuildBinom(n);\n\t\t\n\t\n\t\tlong[][] dp=new long[n+1][n+1];\n\t\tdp[1][1]=1;\n\t\tfor (int i=1;i<=n;i++) {\n\t\t\tdp[i][i]=pow2[i-1];\n\t\t\t//log(\"base:\"+dp[i][i]);\n\t\t\tfor (int j=1;j<i-1;j++){\n\t\t\t\tint me=i-j-1;\n\t\t\t\tfor (int cn=1;cn<=j;cn++) {\n\t\t\t\t\t//log(\"j:\"+j+\" cn:\"+cn+\" dp:\"+dp[j][cn]);\n\t\t\t\t\t//log(\"perm:\"+binom[cn+me][cn]);\n\t\t\t\t\tdp[i][cn+me]+=(((dp[j][cn]*binom[cn+me][cn])%mod)*pow2[me-1])%mod;\n\t\t\t\t\tdp[i][cn+me]%=mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=0;\n\t\tfor (int i=0;i<=n;i++) {\n\t\t\tans+=dp[n][i];\n\t\t\tans%=mod;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) throws Exception  {\n\n\t\tlog(400*400*400);\n\t\treader=new InputReader(System.in);\n\t\tint n=reader.readInt();\n\t\tmod=reader.readInt();\n\t\t\n\t\tSystem.out.println(solve(n));\n\n\t}\n\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\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", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "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\n\npublic class Main{\n\n    static long MOD = 1_000_000_007L;\n    //static long MOD = 998_244_353L;\n    //static long MOD = 1_000_000_033L;\n    static long inv2 = (MOD + 1) / 2;\n\n    static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n    static long lMax = 0x3f3f3f3f3f3f3f3fL;\n    static int iMax = 0x3f3f3f3f;\n    static HashMap <Long, Long> memo = new HashMap();\n    static MyScanner sc = new MyScanner();\n    //static ArrayList <Integer> primes;\n\n    static int nn = 300000;\n    static long[] pow2;\n    static long [] fac;\n    static long [] pow;\n    static long [] inv;\n    static long [] facInv;\n    static int[] base;\n    static int[] numOfDiffDiv;\n    static int[] numOfDiv;\n    static ArrayList <Integer> primes;\n    //static int[] primes;\n    static int ptr = 0;\n    static boolean[] isPrime;\n\n    //-----------PrintWriter for faster output---------------------------------\n    public static PrintWriter out;\n    public static void main(String[] args) {\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n        // Start writing your solution here. -------------------------------------\n\n\n\n        /*fac = new long[nn + 1];\n        fac[1] = 1;\n        for(int i = 2; i <= nn; i++)\n            fac[i] = fac[i - 1] * i % MOD;*/\n\n\n        /*pow2 = new long[nn + 1];\n        pow2[0] = 1L;\n        for(int i = 1; i <= nn; i++)\n            pow2[i] = pow2[i - 1] * 2L;*/\n\n\n        /*inv = new long[nn + 1];\n        inv[1] = 1;\n        for (int i = 2; i <= nn; ++i)\n            inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/\n\n        /*facInv = new long[nn + 1];\n        facInv[0] = facInv[1] = 1;\n        for (int i = 2; i <= nn; ++i)\n            facInv[i] = facInv[i - 1] * inv[i] % MOD;*/\n\n\n        /*numOfDiffDiv = new int[nn + 1];\n        for(int i = 2; i <= nn; i++)\n            if(numOfDiffDiv[i] == 0)\n                for(int j = i; j <= nn; j += i)\n                    numOfDiv[j] ++;*/\n\n        /*numOfDiv = new int[nn + 1];\n        numOfDiv[1] = 1;\n        for(int i = 2; i <= nn; i++) {\n            for(int j = 2; j * j <= i; j++) {\n                if(i % j == 0) {\n                    numOfDiv[i] = numOfDiv[i / j] + 1;\n                    break;\n                }\n            }\n        }*/\n\n        //primes = sieveOfEratosthenes(100001);\n\n        /*\n        int t = 1;\n        //t = sc.ni();\n        while(t-- > 0) {\n            //boolean res = solve();\n            //out.println(res ? \"YES\" : \"NO\");\n            long res = solve();\n            out.println(res);\n        }*/\n\n\n        int t = 1, tt = 0;\n        //t = sc.ni();\n        for(int i = 1; i <40000; i++) squares.add(i * i);\n        while(tt++ < t) {\n            boolean res = solve();\n            //out.println(\"Case #\" + tt + \": \" + res);\n            //out.println(res ? \"YES\" : \"NO\");\n        }\n        out.close();\n    }\n    static HashSet <Integer> squares = new HashSet();\n\n    static boolean solve() {\n        /*String s = sc.nextLine();\n        char[] c = s.toCharArray();\n        int n = c.length;*/\n        //int n = sc.ni();\n        //long[] a =  new long[n];\n        //for(int i = 0; i < n; i++) a[i] = sc.nl();\n        long res = 0;\n        int n = sc.ni();\n        long m = sc.nl();\n        long[][][] dp = new long[2][n + 3][n + 3];\n        long[][][] dp2 = new long[2][n + 3][n + 3];\n        dp[0][2][1] = dp[1][2][2] = dp2[0][1][1] = 1L;\n        for(int i = 3; i <= n; i++) {\n            long[][] bef = dp[0];\n            long[][] aft = dp[1];\n            long[][] nbef = new long[n + 3][n + 3];\n            long[][] naft = new long[n + 3][n + 3];\n            for(int len = 1; len <= i; len++) {\n                for(int ind = 1; ind <= len; ind++) {\n                    nbef[len + 1][1] += bef[len][ind];\n                    nbef[len + 1][ind + 1] -= bef[len][ind];\n                    naft[len + 1][ind + 1] += bef[len][ind];\n                    //naft[len + 1][len + 2] -= bef[len][ind];\n                    naft[len + 1][ind + 1] += aft[len][ind];\n                    //naft[len + 1][len + 2] -= aft[len][ind];\n                    nbef[len + 1][1] += dp2[0][len][ind] + dp2[1][len][ind];\n                    //nbef[len + 1][len + 2] -= dp2[0][len][ind] + dp2[1][len][ind];\n                }\n            }\n            for(int len = 1; len <= i; len++) {\n                for(int ind = 1; ind <= len; ind ++) {\n                    nbef[len][ind] = (nbef[len][ind] + nbef[len][ind - 1] + 10000000L * m) % m;\n                    naft[len][ind] = (naft[len][ind] + naft[len][ind - 1] + 10000000L * m) % m;\n                }\n            }\n            dp2 = dp;\n            dp = new long[][][]{nbef, naft};\n        }\n        for(long[] row: dp[0])\n            for(long i : row)\n                res += i;\n        for(long[] row: dp[1])\n            for(long i : row)\n                res += i;\n            out.println(res % m);\n        return false;\n    }\n\n    // edges to adjacency list by uwi\n    public static int[][] packU(int n, int[] from, int[] to) {\n        return packU(n, from, to, from.length);\n    }\n\n    public static int[][] packU(int n, int[] from, int[] to, int sup) {\n        int[][] g = new int[n][];\n        int[] p = new int[n];\n        for (int i = 0; i < sup; i++) p[from[i]]++;\n        for (int i = 0; i < sup; i++) p[to[i]]++;\n        for (int i = 0; i < n; i++) g[i] = new int[p[i]];\n        for (int i = 0; i < sup; i++) {\n            g[from[i]][--p[from[i]]] = to[i];\n            g[to[i]][--p[to[i]]] = from[i];\n        }\n        return g;\n    }\n\n    // tree diameter by uwi\n    public static int[] diameter(int[][] g) {\n        int n = g.length;\n        int f0 = -1, f1 = -1, d01 = -1;\n        int[] q = new int[n];\n        boolean[] ved = new boolean[n];\n        {\n            int qp = 0;\n            q[qp++] = 0; ved[0] = true;\n            for(int i = 0;i < qp;i++){\n                int cur = q[i];\n                for(int e : g[cur]){\n                    if(!ved[e]){\n                        ved[e] = true;\n                        q[qp++] = e;\n                        continue;\n                    }\n                }\n            }\n            f0 = q[n-1];\n        }\n        {\n            int[] d = new int[n];\n            int qp = 0;\n            Arrays.fill(ved, false);\n            q[qp++] = f0; ved[f0] = true;\n            for(int i = 0;i < qp;i++){\n                int cur = q[i];\n                for(int e : g[cur]){\n                    if(!ved[e]){\n                        ved[e] = true;\n                        q[qp++] = e;\n                        d[e] = d[cur] + 1;\n                        continue;\n                    }\n                }\n            }\n            f1 = q[n-1];\n            d01 = d[f1];\n        }\n        return new int[]{d01, f0, f1};\n    }\n\n    public static long c(int n, int k) {\n        return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;\n    }\n\n\n    // SegmentTree range min/max query by uwi\n    public static class SegmentTreeRMQ {\n        public int M, H, N;\n        public int[] st;\n\n        public SegmentTreeRMQ(int n)\n        {\n            N = n;\n            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n            H = M>>>1;\n            st = new int[M];\n            Arrays.fill(st, 0, M, Integer.MAX_VALUE);\n        }\n\n        public SegmentTreeRMQ(int[] a)\n        {\n            N = a.length;\n            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n            H = M>>>1;\n            st = new int[M];\n            for(int i = 0;i < N;i++){\n                st[H+i] = a[i];\n            }\n            Arrays.fill(st, H+N, M, Integer.MAX_VALUE);\n            for(int i = H-1;i >= 1;i--)propagate(i);\n        }\n\n        public void update(int pos, int x)\n        {\n            st[H+pos] = x;\n            for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);\n        }\n\n        private void propagate(int i)\n        {\n            st[i] = Math.min(st[2*i], st[2*i+1]);\n        }\n\n        public int minx(int l, int r){\n            int min = Integer.MAX_VALUE;\n            if(l >= r)return min;\n            while(l != 0){\n                int f = l&-l;\n                if(l+f > r)break;\n                int v = st[(H+l)/f];\n                if(v < min)min = v;\n                l += f;\n            }\n\n            while(l < r){\n                int f = r&-r;\n                int v = st[(H+r)/f-1];\n                if(v < min)min = v;\n                r -= f;\n            }\n            return min;\n        }\n\n        public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}\n\n        private int min(int l, int r, int cl, int cr, int cur)\n        {\n            if(l <= cl && cr <= r){\n                return st[cur];\n            }else{\n                int mid = cl+cr>>>1;\n                int ret = Integer.MAX_VALUE;\n                if(cl < r && l < mid){\n                    ret = Math.min(ret, min(l, r, cl, mid, 2*cur));\n                }\n                if(mid < r && l < cr){\n                    ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));\n                }\n                return ret;\n            }\n        }\n    }\n\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;}\n\n    public static double dist(double a, double b){\n        return Math.sqrt(a * a + b * b);\n    }\n\n    public static long inv(long a){\n        return quickPOW(a, MOD - 2);\n    }\n\n    public class Interval {\n        int start;\n        int end;\n        public Interval(int start, int end) {\n            this.start = start;\n            this.end = end;\n        }\n    }\n\n    public static ArrayList<Integer> sieveOfEratosthenes(int n) {\n        boolean prime[] = new boolean[n + 1];\n        Arrays.fill(prime, true);\n        for (int p = 2; p * p <= n; p++) {\n            if (prime[p]) {\n                for (int i = p * 2; i <= n; i += p) {\n                    prime[i] = false;\n                }\n            }\n        }\n        ArrayList<Integer> primeNumbers = new ArrayList<>();\n        for (int i = 2; i <= n; i++) {\n            if (prime[i]) {\n                primeNumbers.add(i);\n            }\n        }\n        return primeNumbers;\n    }\n\n\n    public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n    public static int lowerBound(int[] a, int l, int r, int v)\n    {\n        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n        int low = l-1, high = r;\n        while(high-low > 1){\n            int h = high+low>>>1;\n            if(a[h] >= v){\n                high = h;\n            }else{\n                low = h;\n            }\n        }\n        return high;\n    }\n    public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n    public static int rlowerBound(int[] a, int l, int r, int v)\n    {\n        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n        int low = l-1, high = r;\n        while(high-low > 1){\n            int h = high+low>>>1;\n            if(a[h] <= v){\n                high = h;\n            }else{\n                low = h;\n            }\n        }\n        return high;\n    }\n    public static long C(int n, int m)\n    {\n        if(m == 0 || m == n) return 1l;\n        if(m > n || m < 0) return 0l;\n        long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;\n\n        return res;\n    }\n    public static long quickPOW(long n, long m)\n    {\n        long ans = 1l;\n        while(m > 0)\n        {\n            if(m % 2 == 1)\n                ans = (ans * n) % MOD;\n            n = (n * n) % MOD;\n            m >>= 1;\n        }\n        return ans;\n    }\n    public static long quickPOW(long n, long m, long mod)\n    {\n        long ans = 1l;\n        while(m > 0)\n        {\n            if(m % 2 == 1)\n                ans = (ans * n) % mod;\n            n = (n * n) % mod;\n            m >>= 1;\n        }\n        return ans;\n    }\n\n    public static int gcd(int a, int b)\n    {\n        if(a % b == 0) return b;\n        return gcd(b, a % b);\n    }\n    public static long gcd(long a, long b)\n    {\n        if(a % b == 0) return b;\n        return gcd(b, a % b);\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 void shuffle(long[] data) {\n            shuffle(data, 0, data.length - 1);\n        }\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 RandomWrapper.INSTANCE.nextInt(l, r);\n        }\n    }\n\n    static class RandomWrapper {\n        private Random random;\n        public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());\n\n        public RandomWrapper() {\n            this(new Random());\n        }\n\n        public RandomWrapper(Random random) {\n            this.random = random;\n        }\n\n        public int nextInt(int l, int r) {\n            return random.nextInt(r - l + 1) + l;\n        }\n\n    }\n\n\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        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 ni() {\n            return Integer.parseInt(next());\n        }\n        long nl() {\n            return Long.parseLong(next());\n        }\n        double nd() {\n            return Double.parseDouble(next());\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}", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tpublic static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tpublic static void main(String[] args) throws IOException {\n\t\treadInput();\n\t\tout.close();\n\t}\n\t\n\tstatic long[][] dp;\n\tstatic int n;\n\tstatic long m;\n\t\n\n\tstatic long pow(long b, long e) {\n\t\tif (e== 0) return 1;\n\t\tlong r= pow(b,e/2);\n\t\tr = r * r % m;\n\t\tif ((e&1)==1) return r *b%m;\n\t\treturn r;\n\t}\n\t\n\tstatic long modinv(long a) {return pow(a,m-2);}\n\t\n\tstatic long solve(int len, int num) {\n\t\tif (len == -1 && num == -1) return 1;\n\t\tif (num < 0 || len <= 0) return 0;\n\t\tif (dp[len][num] == -1) {\n\t\t\tdp[len][num] = 0;\n\t\t\tfor (int i = 0; i < len; i++) {\n\t\t\t\tif (i == 1) continue;\n\t\t\t\tlong sol = pow[len-i-1]*solve(i-1,num-1)%m;\n\t\t\t\tsol = sol * faci[len-i]% m;\n\t\t\t\tdp[len][num] += sol;\n\t\t\t\tdp[len][num] %= m;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\treturn dp[len][num];\n\t}\n\tstatic long[] fac, faci, pow;\n\t\n\tpublic static void readInput() throws IOException {\n\t\t// br = new BufferedReader(new FileReader(\".in\"));\n\t\t// out = new PrintWriter(new FileWriter(\".out\"));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tn = Integer.parseInt(st.nextToken());\n\t\tm = Long.parseLong(st.nextToken());\n\t\tfac = new long[500];\n\t\tpow = new long[500];\n\t\tfaci = new long[fac.length];\n\t\tfac[0] = pow[0] = 1;\n\t\tfaci[0] = modinv(fac[0]);\n\t\tfor (int i = 1; i < fac.length; i++) {\n\t\t\tfac[i] = fac[i-1]*i%m;\n\t\t\tfaci[i] = modinv(fac[i]);\n\t\t\tpow[i] = pow[i-1] * 2 % m;\n\t\t}\n\t\tdp = new long[n+1][n+1];\n\t\tfor (long[] a: dp) Arrays.fill(a, -1);\n\t\t// Number of ways to make a segment of length x is 2^(x-1)\n\t\t// DP: Given position I.\n\t\tlong ans =0 ;\n\t\tfor (int i = 0 ; i <= n/2+1; i++) {\n\t\t\t//System.out.println(i + \": \" + solve(n,i) + \" \" + (n-i) + \" \" + (i));\n\t\t\tlong sol = solve(n,i) * fac[n-i];\n\t\t\tsol %= m;\n\t\t\tans += sol;\n\t\t}\n\t\tout.println(ans%m);\n\t}\n}\n", "complexity": "cubic", "problem": "1515_E. Phoenix and Computers", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tqq = new int[nq];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tint[] qq;\n\tint nq = 1, head, cnt;\n\tboolean[] iq;\n\tvoid enqueue(int v) {\n\t\tif (iq[v])\n\t\t\treturn;\n\t\tif (head + cnt == nq) {\n\t\t\tif (cnt * 2 <= nq)\n\t\t\t\tSystem.arraycopy(qq, head, qq, 0, cnt);\n\t\t\telse {\n\t\t\t\tint[] qq_ = new int[nq *= 2];\n\t\t\t\tSystem.arraycopy(qq, head, qq_, 0, cnt);\n\t\t\t\tqq = qq_;\n\t\t\t}\n\t\t\thead = 0;\n\t\t}\n\t\tqq[head + cnt++] = v; iq[v] = true;\n\t}\n\tint dequeue() {\n\t\tint u = qq[head++]; cnt--; iq[u] = false;\n\t\treturn u;\n\t}\n\tboolean spfa(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\thead = cnt = 0;\n\t\tenqueue(s);\n\t\twhile (cnt > 0) {\n\t\t\tint u = dequeue();\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tenqueue(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (spfa(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "//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<Edge>[] 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<Edge>[] 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<Edge>();\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 <= k; 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", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, kk, bb;\n\tint[] uu, vv, uv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tkk = new int[n_];\n\t\tbb = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcost_ = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tvoid dijkstra(int s) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint k = kk[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && kk[v] > k) {\n\t\t\t\t\t\tif (pi[v] < INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tkk[v] = k;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tSystem.arraycopy(cost, 0, cost_, 0, m_);\n\t\twhile (true) {\n\t\t\tdijkstra(s);\n\t\t\tif (pi[t] == INF)\n\t\t\t\tbreak;\n\t\t\tpush(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "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 = 350;\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                int prev = 0;\n                for(int k = 1; k <= K; k++) {\n                    solver.link(timeNodes[a][j], timeNodes[b][j + 1], 1, D*k*k- prev);\n                    solver.link(timeNodes[b][j], timeNodes[a][j + 1], 1, D*k*k - prev);\n                    prev = 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<Edge> edges = new ArrayList<Edge>();\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<Node> nodes = new ArrayList<Node>();\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<Item> que = new PriorityQueue<Item>();\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<Item> {\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", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "//package educational.round67;\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.InputMismatchException;\nimport java.util.List;\n\npublic class G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), K = ni(), C = ni(), D = ni();\n\t\tint[] a = na(K);\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\tList<Edge> es = new ArrayList<>();\n\t\t\n\t\tint time = 100;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < time-1;j++){\n\t\t\t\tes.add(new Edge(i*time+j, i*time+j+1, 99, C));\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int e : g[i]){\n\t\t\t\tfor(int j = 0;j < time-1;j++){\n\t\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\t\tes.add(new Edge(i*time+j, e*time+j+1, 1, C+D*(2*k+1)));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint src = time*n, sink = src+1;\n\t\tfor(int i = 0;i < K;i++){\n\t\t\tes.add(new Edge(src, (a[i]-1)*time+0, 1, 0));\n\t\t}\n\t\tfor(int i = 0;i < time;i++){\n\t\t\tes.add(new Edge(0*time+i, sink, 99, 0));\n\t\t}\n\t\t\n\t\tout.println(solveMinCostFlowWithSPFA(compileWD(sink+1, es), src, sink, 99));\n\t}\n\t\n\tpublic static class Edge\n\t{\n\t\tpublic int from, to;\n\t\tpublic int capacity;\n\t\tpublic int cost;\n\t\tpublic int flow;\n\t\tpublic Edge complement;\n\t\t// public int iniflow;\n\t\t\n\t\tpublic Edge(int from, int to, int capacity, int cost) {\n\t\t\tthis.from = from;\n\t\t\tthis.to = to;\n\t\t\tthis.capacity = capacity;\n\t\t\tthis.cost = cost;\n\t\t}\n\t}\n\t\n\tpublic static Edge[][] compileWD(int n, List<Edge> edges)\n\t{\n\t\tEdge[][] g = new Edge[n][];\n\t\t// cloning\n\t\tfor(int i = edges.size()-1;i >= 0;i--){\n\t\t\tEdge origin = edges.get(i);\n\t\t\tEdge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);\n\t\t\tclone.flow = origin.capacity;\n\t\t\tclone.complement = origin;\n\t\t\torigin.complement = clone;\n\t\t\tedges.add(clone);\n\t\t}\n\t\t\n\t\tint[] p = new int[n];\n\t\tfor(Edge e : edges)p[e.from]++;\n\t\tfor(int i = 0;i < n;i++)g[i] = new Edge[p[i]];\n\t\tfor(Edge e : edges)g[e.from][--p[e.from]] = e;\n\t\treturn g;\n\t}\n\n\t// NOT VERIFIED\n\tpublic static Edge[][] compileWU(int n, List<Edge> edges)\n\t{\n\t\tEdge[][] g = new Edge[n][];\n\t\t// cloning\n\t\tfor(int i = edges.size()-1;i >= 0;i--){\n\t\t\tEdge origin = edges.get(i);\n\t\t\tEdge back = new Edge(origin.to, origin.from, origin.capacity, origin.cost);\n\t\t\tedges.add(back);\n\t\t}\n\t\tfor(int i = edges.size()-1;i >= 0;i--){\n\t\t\tEdge origin = edges.get(i);\n\t\t\tEdge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);\n\t\t\tclone.flow = origin.capacity;\n\t\t\tclone.complement = origin;\n\t\t\torigin.complement = clone;\n\t\t\tedges.add(clone);\n\t\t}\n\t\t\n\t\tint[] p = new int[n];\n\t\tfor(Edge e : edges)p[e.from]++;\n\t\tfor(int i = 0;i < n;i++)g[i] = new Edge[p[i]];\n\t\tfor(Edge e : edges)g[e.from][--p[e.from]] = e;\n\t\treturn g;\n\t}\t\n\n\t\n\tpublic static class DQ {\n\t\tpublic int[] q;\n\t\tpublic int n;\n\t\tprotected int pt, ph;\n\t\t\n\t\tpublic DQ(int n){ this.n = Integer.highestOneBit(n)<<1; q = new int[this.n]; pt = ph = 0; }\n\t\t\n\t\tpublic void addLast(int x){ q[ph] = x; ph = ph+1&n-1; }\n\t\tpublic void addFirst(int x){ pt = pt+n-1&n-1; q[pt] = x; }\n\t\tpublic int pollFirst(){ int ret = q[pt]; pt = pt+1&n-1; return ret; }\n\t\tpublic int pollLast(){ ph = ph+n-1&n-1; int ret = q[ph]; return ret; }\n\t\tpublic int getFirst(){ return q[pt]; }\n\t\tpublic int getFirst(int k){ return q[pt+k&n-1]; }\n\t\tpublic int getLast(){ return q[ph+n-1&n-1]; }\n\t\tpublic int getLast(int k){ return q[ph+n-k-1&n-1]; }\n\t\tpublic void clear(){ pt = ph = 0; }\n\t\tpublic int size(){ return ph-pt+n&n-1; }\n\t\tpublic boolean isEmpty(){ return ph==pt; }\n\t}\n\n\t\n\tpublic static long solveMinCostFlowWithSPFA(Edge[][] g, int source, int sink, long all)\n\t{\n\t\tint n = g.length;\n\t\tlong mincost = 0;\n\t\t\n\t\tfinal int[] d = new int[n];\n\t\tDQ q = new DQ(n);\n\t\tboolean[] inq = new boolean[n];\n\t\twhile(all > 0){\n\t\t\t// shortest path src->sink\n\t\t\tEdge[] inedge = new Edge[n];\n\t\t\tArrays.fill(d, Integer.MAX_VALUE / 2);\n\t\t\td[source] = 0;\n\t\t\tq.addLast(source);\n\t\t\twhile(!q.isEmpty()){\n\t\t\t\tint cur = q.pollFirst();\n\t\t\t\tinq[cur] = false;\n\t\t\t\tfor(Edge ne : g[cur]){\n\t\t\t\t\tif(ne.capacity - ne.flow > 0){\n\t\t\t\t\t\tint nd = d[cur] + ne.cost;\n\t\t\t\t\t\tif(d[ne.to] > nd){\n\t\t\t\t\t\t\tinedge[ne.to] = ne;\n\t\t\t\t\t\t\td[ne.to] = nd;\n\t\t\t\t\t\t\tif(!inq[ne.to]){\n\t\t\t\t\t\t\t\tq.addLast(ne.to);\n\t\t\t\t\t\t\t\tinq[ne.to] = 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\t\n\t\t\tif(inedge[sink] == null)break;\n\t\t\t\n\t\t\tlong minflow = all;\n\t\t\tlong sumcost = 0;\n\t\t\tfor(Edge e = inedge[sink];e != null;e = inedge[e.from]){\n\t\t\t\tif(e.capacity - e.flow < minflow)minflow = e.capacity - e.flow;\n\t\t\t\tsumcost += e.cost;\n\t\t\t}\n\t\t\tmincost += minflow * sumcost;\n\t\t\tfor(Edge e = inedge[sink];e != null;e = inedge[e.from]){\n\t\t\t\te.flow += minflow;\n\t\t\t\te.complement.flow -= minflow;\n\t\t\t}\n\t\t\t\n\t\t\tall -= minflow;\n\t\t}\n\t\treturn mincost;\n\t}\n\n\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 G().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", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tqq = new int[nq];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tint[] qq;\n\tint nq = 1 << 20, head, cnt;\n\tboolean[] iq;\n\tvoid enqueue(int v) {\n\t\tif (iq[v])\n\t\t\treturn;\n\t\tif (head + cnt == nq) {\n\t\t\tif (cnt * 4 <= nq)\n\t\t\t\tSystem.arraycopy(qq, head, qq, 0, cnt);\n\t\t\telse {\n\t\t\t\tint[] qq_ = new int[nq *= 2];\n\t\t\t\tSystem.arraycopy(qq, head, qq_, 0, cnt);\n\t\t\t\tqq = qq_;\n\t\t\t}\n\t\t\thead = 0;\n\t\t}\n\t\tqq[head + cnt++] = v; iq[v] = true;\n\t}\n\tint dequeue() {\n\t\tint u = qq[head++]; cnt--; iq[u] = false;\n\t\treturn u;\n\t}\n\tboolean spfa(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\thead = cnt = 0;\n\t\tenqueue(s);\n\t\twhile (cnt > 0) {\n\t\t\tint u = dequeue();\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tenqueue(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (spfa(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "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<Edge> 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<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));\n\n                    pq.add(new pair(S , 0)); dist[0] = 0;\n                    o : while(!pq.isEmpty()){\n                        pair p = pq.poll();\n                        while(dist[p.F] < p.S){\n                            if(pq.isEmpty()) break o; // had a better val \n                            p = pq.poll();\n                        }\n                        visit[p.F] = 2;\n                        for(int i = 0; i < ja[p.F].length; i++){\n                            Edge e = ja[p.F][i];\n                            if(e.flow == 0)continue; // important\n                            int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost\n                            if(cdist < dist[e.u]){ \n                                if(visit[e.u] == 2) return false;\n                                pq.add(new pair(e.u , cdist));\n                                dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;\n                                visit[e.u] = 1;\n                            }\n                        }\n                    }\n                    return visit[T] != 0;\n                }\n                \n                int augment(){\n                    int p = T; int min = gmax;\n                    while(p != 0){\n                        int pp = prv[p], pe = prve[p];\n                        int val = ja[pp][pe].flow;\n                        min = Math.min(min , val);\n                        p = pp;\n                    }\n                    p = T;\n                    while(p != 0){\n                        int pp = prv[p], pe = prve[p];\n                        ja[pp][pe].flow -= min;\n                        ja[p][ja[pp][pe].rid].flow += min;\n                        p = pp;\n                    }\n                    maxFlow += min;\n                    return min;\n                }\n\n                // if(dist[T] >= 0)return true; // non contributing flow\n                boolean calSimple(){\n                    // uncomment to check for negative cycles\n                    /* boolean possible = BellmanFord(true); \n                     if(!possible) return false; */\n                    while(simple()){\n                        /*if(dist[T] >= 0)return true;*/ \n                        minCost += dist[T] * augment();\n                    }\n                    return true;\n                }\n\n                void updPotential(){\n                    for(int i = 0; i < N; i++){\n                        if(visit[i] != 0){\n                            d[i] += dist[i] - dist[S];\n                        }\n                    }\n                }\n                boolean calWithPotential(){\n                    // set true to check for negative cycles\n                    // boolean possible = BellmanFord(false); \n                    // if(!possible) return false;\n                    while(dijkstra()){\n                        int min = dist[T] + d[T] - d[S]; // getting back the original cost\n                        /*if(dist[T] >= 0)return true;*/\n                        minCost += min * augment();\n                        updPotential();\n                    }\n                    return true;   \n                }\n            }\n            int n , m, k, c, d, a[], f[];\n           public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();\n            // S + n\n            int maxl = n + k, T = n * maxl + 1;\n            MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);\n            a = new int[k + 1]; f = new int[n + 1];\n            for(int i = 1; i <= k; i++){\n                a[i] = in.nextInt();\n                f[a[i]]++;\n            }\n            for(int i = 1; i <= n; i++){\n                if(f[i] == 0)continue;\n                ans.addEdge(0 , i , f[i], 0);\n            }\n            for(int i = 2; i <= n; i++){\n                for(int l = 0; l < maxl - 1; l++){\n                    ans.addEdge(l * n + i , (l + 1) * n + i, k, c);\n                }\n            }\n            for(int i = 1; i <= m; i++){\n                int a = in.nextInt(), b = in.nextInt();\n                for(int l = 0; l < maxl - 1; l++){\n                    for(int p = 1; p <= k; p++){\n                        if(a != 1)\n                            ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);\n                        if(b != 1)\n                            ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);\n                    }\n                } \n            }\n            for(int l = 1; l < maxl; l++){\n                ans.addEdge(l * n + 1, T, k, 0);\n            }\n            ans.convertToArray();\n            ans.calWithPotential();\n            // ans.calSimple();\n            if(ans.maxFlow != k){\n                out.println(\"BUG\");\n            }else{\n                out.println((int)ans.minCost);\n            }\n          }\n    }\n    static class InputReader {\n        BufferedReader br;\n        StringTokenizer st;\n        public InputReader(InputStream stream) {\n            br = new BufferedReader(new InputStreamReader(stream));\n            st = null;\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = null;\n                try {\n                    s = br.readLine();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n                if (s == null)\n                    return null;\n                st = new StringTokenizer(s);\n            }\n            return st.nextToken();\n        }\n\n        boolean hasMoreTokens() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = null;\n                try {\n                    s = br.readLine();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n                if (s == null)\n                    return false;\n                st = new StringTokenizer(s);\n            }\n            return true;\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out, true); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, kk;\n\tint[] uu, vv, uv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tkk = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tboolean dijkstra(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint k = kk[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && kk[v] > k) {\n\t\t\t\t\t\tif (pi[v] != INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tkk[v] = k;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tint dfs(int u, int t, int c) {\n\t\tif (u == t || c == 0)\n\t\t\treturn c;\n\t\tint k = kk[u] + 1;\n\t\tArrayList<Integer> adj = aa_[u];\n\t\tfor (int h_ : adj) {\n\t\t\tint h = h_ >> 1;\n\t\t\tint v = u ^ uv[h];\n\t\t\tif (kk[v] != k)\n\t\t\t\tcontinue;\n\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]), f;\n\t\t\tif (pi[v] == p && (f = dfs(v, t, Math.min(c, cc[h_]))) != 0) {\n\t\t\t\tcc[h_] -= f; cc[h_ ^ 1] += f;\n\t\t\t\treturn f;\n\t\t\t}\n\t\t}\n\t\tkk[u] = INF;\n\t\treturn 0;\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tcost_ = Arrays.copyOf(cost, m_);\n\t\twhile (dijkstra(s, t)) {\n\t\t\twhile (dfs(s, t, INF) > 0)\n\t\t\t\t;\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "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<Edge> 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<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));\n\n                    pq.add(new pair(S , 0)); dist[0] = 0;\n                    o : while(!pq.isEmpty()){\n                        pair p = pq.poll();\n                        while(dist[p.F] < p.S){\n                            if(pq.isEmpty()) break o; // had a better val \n                            p = pq.poll();\n                        }\n                        visit[p.F] = 2;\n                        for(int i = 0; i < ja[p.F].length; i++){\n                            Edge e = ja[p.F][i];\n                            if(e.flow == 0)continue; // important\n                            int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost\n                            if(cdist < dist[e.u]){ \n                                if(visit[e.u] == 2) return false;\n                                pq.add(new pair(e.u , cdist));\n                                dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;\n                                visit[e.u] = 1;\n                            }\n                        }\n                    }\n                    return visit[T] != 0;\n                }\n                \n                int augment(){\n                    int p = T; int min = gmax;\n                    while(p != 0){\n                        int pp = prv[p], pe = prve[p];\n                        int val = ja[pp][pe].flow;\n                        min = Math.min(min , val);\n                        p = pp;\n                    }\n                    p = T;\n                    while(p != 0){\n                        int pp = prv[p], pe = prve[p];\n                        ja[pp][pe].flow -= min;\n                        ja[p][ja[pp][pe].rid].flow += min;\n                        p = pp;\n                    }\n                    maxFlow += min;\n                    return min;\n                }\n\n                // if(dist[T] >= 0)return true; // non contributing flow\n                boolean calSimple(){\n                    // uncomment to check for negative cycles\n                    /* boolean possible = BellmanFord(true); \n                     if(!possible) return false; */\n                    while(simple()){\n                        /*if(dist[T] >= 0)return true;*/ \n                        minCost += dist[T] * augment();\n                    }\n                    return true;\n                }\n\n                void updPotential(){\n                    for(int i = 0; i < N; i++){\n                        if(visit[i] != 0){\n                            d[i] += dist[i] - dist[S];\n                        }\n                    }\n                }\n                boolean calWithPotential(){\n                    // set true to check for negative cycles\n                    // boolean possible = BellmanFord(false); \n                    // if(!possible) return false;\n                    while(dijkstra()){\n                        int min = dist[T] + d[T] - d[S]; // getting back the original cost\n                        /*if(dist[T] >= 0)return true;*/\n                        minCost += min * augment();\n                        updPotential();\n                    }\n                    return true;   \n                }\n            }\n            int n , m, k, c, d, a[], f[];\n           public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();\n            // S + n\n            int maxl = n + k, T = n * maxl + 1;\n            MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);\n            a = new int[k + 1]; f = new int[n + 1];\n            for(int i = 1; i <= k; i++){\n                a[i] = in.nextInt();\n                f[a[i]]++;\n            }\n            for(int i = 1; i <= n; i++){\n                if(f[i] == 0)continue;\n                ans.addEdge(0 , i , f[i], 0);\n            }\n            for(int i = 2; i <= n; i++){\n                for(int l = 0; l < maxl - 1; l++){\n                    ans.addEdge(l * n + i , (l + 1) * n + i, k, c);\n                }\n            }\n            for(int i = 1; i <= m; i++){\n                int a = in.nextInt(), b = in.nextInt();\n                for(int l = 0; l < maxl - 1; l++){\n                    for(int p = 1; p <= k; p++){\n                        if(a != 1)\n                            ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);\n                        if(b != 1)\n                            ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);\n                    }\n                } \n            }\n            for(int l = 1; l < maxl; l++){\n                ans.addEdge(l * n + 1, T, k, 0);\n            }\n            ans.convertToArray();\n            // ans.calWithPotential();\n            ans.calSimple();\n            if(ans.maxFlow != k){\n                out.println(\"BUG\");\n            }else{\n                out.println((int)ans.minCost);\n            }\n          }\n    }\n    static class InputReader {\n        BufferedReader br;\n        StringTokenizer st;\n        public InputReader(InputStream stream) {\n            br = new BufferedReader(new InputStreamReader(stream));\n            st = null;\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = null;\n                try {\n                    s = br.readLine();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n                if (s == null)\n                    return null;\n                st = new StringTokenizer(s);\n            }\n            return st.nextToken();\n        }\n\n        boolean hasMoreTokens() {\n            while (st == null || !st.hasMoreTokens()) {\n                String s = null;\n                try {\n                    s = br.readLine();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n                if (s == null)\n                    return false;\n                st = new StringTokenizer(s);\n            }\n            return true;\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, bb;\n\tint[] uu, vv, uv, cost;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tbb = new int[n_];\n\t\tqq = new int[nq];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tint[] qq;\n\tint nq = 1 << 20, head, cnt;\n\tboolean[] iq;\n\tvoid enqueue(int v) {\n\t\tif (iq[v])\n\t\t\treturn;\n\t\tif (head + cnt == nq) {\n\t\t\tif (cnt * 2 <= nq)\n\t\t\t\tSystem.arraycopy(qq, head, qq, 0, cnt);\n\t\t\telse {\n\t\t\t\tint[] qq_ = new int[nq *= 2];\n\t\t\t\tSystem.arraycopy(qq, head, qq_, 0, cnt);\n\t\t\t\tqq = qq_;\n\t\t\t}\n\t\t\thead = 0;\n\t\t}\n\t\tqq[head + cnt++] = v; iq[v] = true;\n\t}\n\tint dequeue() {\n\t\tint u = qq[head++]; cnt--; iq[u] = false;\n\t\treturn u;\n\t}\n\tboolean spfa(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\thead = cnt = 0;\n\t\tenqueue(s);\n\t\twhile (cnt > 0) {\n\t\t\tint u = dequeue();\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p) {\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tenqueue(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (spfa(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, kk, bb;\n\tint[] uu, vv, uv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tkk = new int[n_];\n\t\tbb = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcost_ = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tboolean dijkstra(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint k = kk[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && kk[v] > k) {\n\t\t\t\t\t\tif (pi[v] != INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tkk[v] = k;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tSystem.arraycopy(cost, 0, cost_, 0, m_);\n\t\twhile (dijkstra(s, t)) {\n\t\t\tpush1(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "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 G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), K = ni(), C = ni(), D = ni();\n\t\tint[] a = na(K);\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\tList<Edge> es = new ArrayList<>();\n\t\t\n\t\tint time = 100;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < time-1;j++){\n\t\t\t\tes.add(new Edge(i*time+j, i*time+j+1, 99, C));\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int e : g[i]){\n\t\t\t\tfor(int j = 0;j < time-1;j++){\n\t\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\t\tes.add(new Edge(i*time+j, e*time+j+1, 1, C+D*(2*k+1)));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint src = time*n, sink = src+1;\n\t\tfor(int i = 0;i < K;i++){\n\t\t\tes.add(new Edge(src, (a[i]-1)*time+0, 1, 0));\n\t\t}\n\t\tfor(int i = 0;i < time;i++){\n\t\t\tes.add(new Edge(0*time+i, sink, 99, 0));\n\t\t}\n\t\t\n\t\tout.println(solveMinCostFlowWithSPFA(compileWD(sink+1, es), src, sink, 99));\n\t}\n\t\n\tpublic static class Edge\n\t{\n\t\tpublic int from, to;\n\t\tpublic int capacity;\n\t\tpublic int cost;\n\t\tpublic int flow;\n\t\tpublic Edge complement;\n\t\t// public int iniflow;\n\t\t\n\t\tpublic Edge(int from, int to, int capacity, int cost) {\n\t\t\tthis.from = from;\n\t\t\tthis.to = to;\n\t\t\tthis.capacity = capacity;\n\t\t\tthis.cost = cost;\n\t\t}\n\t}\n\t\n\tpublic static Edge[][] compileWD(int n, List<Edge> edges)\n\t{\n\t\tEdge[][] g = new Edge[n][];\n\t\t// cloning\n\t\tfor(int i = edges.size()-1;i >= 0;i--){\n\t\t\tEdge origin = edges.get(i);\n\t\t\tEdge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);\n\t\t\tclone.flow = origin.capacity;\n\t\t\tclone.complement = origin;\n\t\t\torigin.complement = clone;\n\t\t\tedges.add(clone);\n\t\t}\n\t\t\n\t\tint[] p = new int[n];\n\t\tfor(Edge e : edges)p[e.from]++;\n\t\tfor(int i = 0;i < n;i++)g[i] = new Edge[p[i]];\n\t\tfor(Edge e : edges)g[e.from][--p[e.from]] = e;\n\t\treturn g;\n\t}\n \n\t// NOT VERIFIED\n\tpublic static Edge[][] compileWU(int n, List<Edge> edges)\n\t{\n\t\tEdge[][] g = new Edge[n][];\n\t\t// cloning\n\t\tfor(int i = edges.size()-1;i >= 0;i--){\n\t\t\tEdge origin = edges.get(i);\n\t\t\tEdge back = new Edge(origin.to, origin.from, origin.capacity, origin.cost);\n\t\t\tedges.add(back);\n\t\t}\n\t\tfor(int i = edges.size()-1;i >= 0;i--){\n\t\t\tEdge origin = edges.get(i);\n\t\t\tEdge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);\n\t\t\tclone.flow = origin.capacity;\n\t\t\tclone.complement = origin;\n\t\t\torigin.complement = clone;\n\t\t\tedges.add(clone);\n\t\t}\n\t\t\n\t\tint[] p = new int[n];\n\t\tfor(Edge e : edges)p[e.from]++;\n\t\tfor(int i = 0;i < n;i++)g[i] = new Edge[p[i]];\n\t\tfor(Edge e : edges)g[e.from][--p[e.from]] = e;\n\t\treturn g;\n\t}\t\n \n\t\n\tpublic static class DQ {\n\t\tpublic int[] q;\n\t\tpublic int n;\n\t\tprotected int pt, ph;\n\t\t\n\t\tpublic DQ(int n){ this.n = Integer.highestOneBit(n)<<1; q = new int[this.n]; pt = ph = 0; }\n\t\t\n\t\tpublic void addLast(int x){ q[ph] = x; ph = ph+1&n-1; }\n\t\tpublic void addFirst(int x){ pt = pt+n-1&n-1; q[pt] = x; }\n\t\tpublic int pollFirst(){ int ret = q[pt]; pt = pt+1&n-1; return ret; }\n\t\tpublic int pollLast(){ ph = ph+n-1&n-1; int ret = q[ph]; return ret; }\n\t\tpublic int getFirst(){ return q[pt]; }\n\t\tpublic int getFirst(int k){ return q[pt+k&n-1]; }\n\t\tpublic int getLast(){ return q[ph+n-1&n-1]; }\n\t\tpublic int getLast(int k){ return q[ph+n-k-1&n-1]; }\n\t\tpublic void clear(){ pt = ph = 0; }\n\t\tpublic int size(){ return ph-pt+n&n-1; }\n\t\tpublic boolean isEmpty(){ return ph==pt; }\n\t}\n \n\t\n\tpublic static long solveMinCostFlowWithSPFA(Edge[][] g, int source, int sink, long all)\n\t{\n\t\tint n = g.length;\n\t\tlong mincost = 0;\n\t\t\n\t\tfinal int[] d = new int[n];\n\t\tDQ q = new DQ(n);\n\t\tboolean[] inq = new boolean[n];\n\t\twhile(all > 0){\n\t\t\t// shortest path src->sink\n\t\t\tEdge[] inedge = new Edge[n];\n\t\t\tArrays.fill(d, Integer.MAX_VALUE / 2);\n\t\t\td[source] = 0;\n\t\t\tq.addLast(source);\n\t\t\twhile(!q.isEmpty()){\n\t\t\t\tint cur = q.pollFirst();\n\t\t\t\tinq[cur] = false;\n\t\t\t\tfor(Edge ne : g[cur]){\n\t\t\t\t\tif(ne.capacity - ne.flow > 0){\n\t\t\t\t\t\tint nd = d[cur] + ne.cost;\n\t\t\t\t\t\tif(d[ne.to] > nd){\n\t\t\t\t\t\t\tinedge[ne.to] = ne;\n\t\t\t\t\t\t\td[ne.to] = nd;\n\t\t\t\t\t\t\tif(!inq[ne.to]){\n\t\t\t\t\t\t\t\tq.addLast(ne.to);\n\t\t\t\t\t\t\t\tinq[ne.to] = 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\t\n\t\t\tif(inedge[sink] == null)break;\n\t\t\t\n\t\t\tlong minflow = all;\n\t\t\tlong sumcost = 0;\n\t\t\tfor(Edge e = inedge[sink];e != null;e = inedge[e.from]){\n\t\t\t\tif(e.capacity - e.flow < minflow)minflow = e.capacity - e.flow;\n\t\t\t\tsumcost += e.cost;\n\t\t\t}\n\t\t\tmincost += minflow * sumcost;\n\t\t\tfor(Edge e = inedge[sink];e != null;e = inedge[e.from]){\n\t\t\t\te.flow += minflow;\n\t\t\t\te.complement.flow -= minflow;\n\t\t\t}\n\t\t\t\n\t\t\tall -= minflow;\n\t\t}\n\t\treturn mincost;\n\t}\n \n \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 G().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}", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcost_ = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tboolean dijkstra(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tif (pi[v] != INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tcost_ = Arrays.copyOf(cost, m_);\n\t\twhile (dijkstra(s, t)) {\n\t\t\tpush1(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tboolean dijkstra(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tif (pi[v] != INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tcost_ = Arrays.copyOf(cost, m_);\n\t\twhile (dijkstra(s, t)) {\n\t\t\tpush1(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tqq = new int[nq];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tint[] qq;\n\tint nq = 1 << 20, head, cnt;\n\tboolean[] iq;\n\tvoid enqueue(int v) {\n\t\tif (iq[v])\n\t\t\treturn;\n\t\tif (head + cnt == nq) {\n\t\t\tif (cnt * 2 <= nq)\n\t\t\t\tSystem.arraycopy(qq, head, qq, 0, cnt);\n\t\t\telse {\n\t\t\t\tint[] qq_ = new int[nq *= 2];\n\t\t\t\tSystem.arraycopy(qq, head, qq_, 0, cnt);\n\t\t\t\tqq = qq_;\n\t\t\t}\n\t\t\thead = 0;\n\t\t}\n\t\tqq[head + cnt++] = v; iq[v] = true;\n\t}\n\tint dequeue() {\n\t\tint u = qq[head++]; cnt--; iq[u] = false;\n\t\treturn u;\n\t}\n\tboolean spfa(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\thead = cnt = 0;\n\t\tenqueue(s);\n\t\twhile (cnt > 0) {\n\t\t\tint u = dequeue();\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tenqueue(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (spfa(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost;\n\tboolean[] iq;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tboolean dijkstra(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);\n\t\tpq.add(s); iq[s] = true;\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tiq[u] = false;\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tif (iq[v]) {\n\t\t\t\t\t\t\tpq.remove(v); iq[v] = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v); iq[v] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (dijkstra(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, kk, bb;\n\tint[] uu, vv, uv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tkk = new int[n_];\n\t\tbb = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcost_ = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tvoid dijkstra(int s) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint k = kk[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && kk[v] > k) {\n\t\t\t\t\t\tif (pi[v] < INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tkk[v] = k;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tSystem.arraycopy(cost, 0, cost_, 0, m_);\n\t\twhile (true) {\n\t\t\tdijkstra(s);\n\t\t\tif (pi[t] == INF)\n\t\t\t\tbreak;\n\t\t\tpush1(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "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 = 150;\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                int prev = 0;\n                for(int k = 1; k <= K; k++) {\n                    solver.link(timeNodes[a][j], timeNodes[b][j + 1], 1, D*k*k- prev);\n                    solver.link(timeNodes[b][j], timeNodes[a][j + 1], 1, D*k*k - prev);\n                    prev = 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<Edge> edges = new ArrayList<Edge>();\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<Node> nodes = new ArrayList<Node>();\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<Item> que = new PriorityQueue<Item>();\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<Item> {\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", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, kk, bb;\n\tint[] uu, vv, cost, cost_;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tkk = new int[n_];\n\t\tbb = new int[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcost_ = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tvoid dijkstra(int s) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\tTreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);\n\t\tpq.add(s);\n\t\tInteger first;\n\t\twhile ((first = pq.pollFirst()) != null) {\n\t\t\tint u = first;\n\t\t\tint k = kk[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tint v = u ^ uu[h] ^ vv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && kk[v] > k) {\n\t\t\t\t\t\tif (pi[v] < INF)\n\t\t\t\t\t\t\tpq.remove(v);\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tkk[v] = k;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tpq.add(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uu[h] ^ vv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uu[h] ^ vv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tSystem.arraycopy(cost, 0, cost_, 0, m_);\n\t\twhile (true) {\n\t\t\tdijkstra(s);\n\t\t\tif (pi[t] == INF)\n\t\t\t\tbreak;\n\t\t\tpush(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint u = uu[h], v = vv[h];\n\t\t\t\tif (pi[u] != INF && pi[v] != INF)\n\t\t\t\t\tcost_[h] += pi[u] - pi[v];\n\t\t\t}\n\t\t}\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "complexity": "cubic", "problem": "1187_G. Gang Up", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\n\npublic class Main{\n\t\n\tpublic static void main(String[] Args) throws Exception {\n\t     Scanner sc = new Scanner(new FileReader(\"input.txt\"));\n\t     int n,m,k;\n\t     Integer lx,ly;\n\t     boolean d[][];\n\t     n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt();\n\t     d = new boolean [n+1][m+1];\n\t     for(int i=0;i<=n;++i)\n\t      for(int j=0;j<=m;++j)\n\t       d[i][j]=false;\n\t     \n\t     Queue< pair > q = new LinkedList< pair >();\n\t     lx = ly = -1;\n\t     for(int i=0;i<k;++i){\n\t     \tint x,y; x = sc.nextInt(); y = sc.nextInt();\n\t     \tq.add(new pair(x,y)); lx = x; ly = y;\n\t     \td[x][y]=true;\n\t     }\n\t     \n\t     int dx [] = {0,0,1,-1};\n\t     int dy [] = {-1,1,0,0};\n\t     \n\t     \n\t     while(!q.isEmpty()){\n\t     \t pair tp = q.remove();\n\t     \t int x = tp.x; int y = tp.y;\n\t     \t for(int i=0;i<4;++i){\n\t     \t \t int nx = x+dx[i]; int ny = y+dy[i];\n\t     \t \t if(nx<1 || nx>n || ny<1 || ny>m || d[nx][ny] ) continue;\n\t     \t     d[nx][ny]=true;\n\t     \t     q.add(new pair(nx,ny));\n\t     \t     lx = nx; ly = ny;\n\t     \t }\n\t     }\n\t     FileWriter fw = new FileWriter(\"output.txt\");\n\t     fw.write(lx.toString()); fw.write(\" \"); fw.write(ly.toString());;\n\t     fw.flush();\n\t     \t\n\t}\n}\nclass pair {\n\n  public int x,y;\n  public pair(int _x,int _y){ x = _x; y = _y; }\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.io.FileInputStream;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.util.Collection;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Queue;\nimport java.io.IOException;\nimport java.io.FileOutputStream;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author nasko\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream;\n\t\ttry {\n\t\t\tinputStream = new FileInputStream(\"input.txt\");\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tOutputStream outputStream;\n\t\ttry {\n\t\t\toutputStream = new FileOutputStream(\"output.txt\");\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n        int N = in.nextInt();\n        int M = in.nextInt();\n        int K = in.nextInt();\n        int[][] dist = new int[N+1][M+1];\n        for(int[] ini : dist) Arrays.fill(ini,1 << 30);\n        int best = 0;\n        ArrayList<Integer> result = new ArrayList<Integer>();\n        Queue<Integer> q = new LinkedList<Integer>();\n        for(int k = 0; k < K; ++k) {\n            int x = in.nextInt();\n            int y = in.nextInt();\n            dist[x][y] = 0;\n            q.offer(x);\n            q.offer(y);\n\n        }\n\n        int[] dx = new int[] { 1,-1,0,0 };\n        int[] dy = new int[] {0,0,1,-1};\n\n        while(!q.isEmpty()) {\n\n            int a = q.poll();\n            int b = q.poll();\n            for(int r = 0; r < 4; ++r) {\n                int x = a + dx[r];\n                int y = b + dy[r];\n                if(x >= 1 && x <= N && y >=1 && y <= M && dist[x][y] > dist[a][b] + 1) {\n                    dist[x][y] = dist[a][b] + 1;\n\n                    q.offer(x);\n                    q.offer(y);\n                }\n            }\n        }\n        for(int i = 1; i <= N; ++i)\n            for(int j = 1; j <= M; ++j) best = Math.max(best,dist[i][j]);\n        for(int a = 1; a <= N; ++a)\n            for(int b = 1; b <= M; ++b) if(dist[a][b] == best) {\n                result.add(a);\n                result.add(b);\n            }\n\n        if(result.size() > 0) {\n            out.print(result.get(0) + \" \" + result.get(1));\n        }\n\n        out.println();\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));\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class SolutionC{\n\tpublic static void main(String[] args) throws Exception{\n\t\tScanner sc = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter output = new PrintWriter(\"output.txt\");\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tint[] x = new int[K];\n\t\tint[] y = new int[K];\n\t\tfor(int i = 0 ; i < K ; i++){\n\t\t\tx[i] = sc.nextInt();\n\t\t\ty[i] = sc.nextInt();\n\t\t}\n\t\tint max = -1, max_x = -1, max_y = -1;\n\t\tfor(int i = 1 ; i <= N ; i++){\n\t\t\tfor(int j = 1 ; j <= M ; j++){\n\t\t\t\tint min = Integer.MAX_VALUE;\n\t\t\t\tfor(int k = 0 ; k < K ; k++){\n\t\t\t\t\tmin = Math.min(min, Math.abs(x[k] - i) + Math.abs(y[k] - j));\n\t\t\t\t}\n\t\t\t\tif(min > max){\n\t\t\t\t\tmax = min;\n\t\t\t\t\tmax_x = i;\n\t\t\t\t\tmax_y = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput.println(max_x + \" \" + max_y);\n\t\toutput.flush();\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport java.awt.*;\n\npublic class PracticeProblem\n{\n    /*\n     * This FastReader code is taken from GeeksForGeeks.com\n     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/\n     *\n     * The article was written by Rishabh Mahrsee\n     */\n    public static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() throws FileNotFoundException\n        {\n            br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n        }\n\n        String next()\n        {\n            while (st == null || !st.hasMoreElements())\n            {\n                try\n                {\n                    st = new StringTokenizer(br.readLine());\n                }\n                catch (IOException  e)\n                {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt()\n        {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong()\n        {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble()\n        {\n            return Double.parseDouble(next());\n        }\n\n        String nextLine()\n        {\n            String str = \"\";\n            try\n            {\n                str = br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n\n    public static FastReader in;\n    public static PrintWriter out;\n    public static final int INF = Integer.MAX_VALUE;\n    public static int n, m;\n\n    public static final int[] dr = {-1, 0, 0, +1};\n    public static final int[] dc = {0, -1, +1, 0};\n\n    public static void main(String[] args) throws FileNotFoundException\n    {\n        in = new FastReader();\n        out = new PrintWriter(new File(\"output.txt\"));\n        solve();\n        out.close();\n    }\n\n    private static void solve()\n    {\n        n = in.nextInt();\n        m = in.nextInt();\n        int k = in.nextInt();\n\n        int[][] timeToBurn = new int[n][m];\n        for (int i = 0; i < n; i++)\n            Arrays.fill(timeToBurn[i], INF);\n\n        for (int i = 0; i < k; i++)\n        {\n            int r = in.nextInt() - 1;\n            int c = in.nextInt() - 1;\n            for (int j = 0; j < n; j++)\n            {\n                for (int l = 0; l < m; l++)\n                {\n                    timeToBurn[j][l] = min(timeToBurn[j][l], abs(r - j) + abs(c - l));\n                }\n            }\n        }\n        int max = -1;\n        Point p = null;\n        for (int i = 0; i < n; i++)\n        {\n            for (int j = 0; j < m; j++)\n            {\n                if (timeToBurn[i][j] > max)\n                {\n                    max = timeToBurn[i][j];\n                    p = new Point(i, j);\n                }\n            }\n        }\n\n        out.println((p.x + 1) + \" \" + (p.y + 1));\n    }\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\t\t\n\tpublic void solve() throws IOException {\n\t\tint N = nextInt();\n                int M = nextInt();\n                \n                int B = nextInt();\n                int[][] burn = new int[B][2];\n                for(int i = 0; i < B; i++){\n                        burn[i][0] = nextInt();\n                        burn[i][1] = nextInt();\n                }\n                \n                int ansx = -1;\n                int ansy = -1;\n                int ans = -1;\n                \n                for(int i = 1; i <= N; i++){\n                        for(int j = 1; j <= M; j++){\n                                int burnAt = Integer.MAX_VALUE;\n                                for(int k = 0; k < B; k++){\n                                        int now = distance(i, j, burn[k][0], burn[k][1]);\n                                        burnAt = Math.min(burnAt, now);\n                                }\n                                //System.out.println(burnAt + \" \" + i + \" \" + j);\n                                if(burnAt >= ans){\n                                        \n                                        ans = burnAt;\n                                        ansx = i;\n                                        ansy = j;\n                                        \n                                }\n                        }\n                }\n                \n                \n                out.println(ansx + \" \" + ansy);\n\t}\n        \n        private int distance(int x, int y, int xx, int yy){\n                //withour sqrt\n                return Math.abs(xx - x) + Math.abs(yy - y);\n        }\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\tpublic void run() {\n\t\ttry {\n\t\t\t//in = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tin = new BufferedReader(new FileReader(new File(\"input.txt\")));\n                        out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n                        tok = null;\n\t\t\tsolve();\n\t\t\tin.close();\n                        out.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        PrintWriter out;\n\tBufferedReader in;\n\tStringTokenizer tok;\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\n\npublic class FireAgain {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader readData = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tPrintWriter writer = new PrintWriter(new File(\"output.txt\"));\n\t\tString line = readData.readLine();\n\t\tString[] temp = line.split(\" \");\n\t\tint n = Integer.valueOf(temp[0]);\n\t\tint m = Integer.valueOf(temp[1]);\n\t\tint x = 0, y = 0;\n\t\tline = readData.readLine();\n\t\tint k = Integer.valueOf(line);\n\t\tboolean[][] visited = new boolean[n + 1][m + 1];\n\t\tQueue<Integer> qX = new LinkedList<Integer>();\n\t\tQueue<Integer> qY = new LinkedList<Integer>();\n\t\tline = readData.readLine();\n\t\tString[] temp2 = line.split(\" \");\n\t\tfor (int i = 0; i < temp2.length - 1; i+=2) {\n\t\t\tx = Integer.valueOf(temp2[i]);\n\t\t\ty = Integer.valueOf(temp2[i + 1]);\n\t\t\tvisited[x][y] = true;\n\t\t\tqX.add(x);\n\t\t\tqY.add(y);\n\t\t}\n\n\t\twhile (!qX.isEmpty()) {\n\t\t\tx = qX.poll();\n\t\t\ty = qY.poll();\n\t\t\tif (x >= 2 && !visited[x - 1][y]) {\n\t\t\t\tvisited[x - 1][y] = true;\n\t\t\t\tqX.add(x - 1);\n\t\t\t\tqY.add(y);\n\t\t\t}\n\t\t\tif (x + 1 <= n && !visited[x + 1][y]) {\n\t\t\t\tvisited[x + 1][y] = true;\n\t\t\t\tqX.add(x + 1);\n\t\t\t\tqY.add(y);\n\t\t\t}\n\t\t\tif (y >= 2 && !visited[x][y - 1]) {\n\t\t\t\tvisited[x][y - 1] = true;\n\t\t\t\tqX.add(x);\n\t\t\t\tqY.add(y - 1);\n\t\t\t}\n\t\t\tif (y + 1 <= m && !visited[x][y + 1]) {\n\t\t\t\tvisited[x][y + 1] = true;\n\t\t\t\tqX.add(x);\n\t\t\t\tqY.add(y + 1);\n\t\t\t}\n\t\t}\n\t\twriter.write(x + \" \");\n\t\twriter.write(y + \" \");\n\t\twriter.close();\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\tPrintWriter pw = new PrintWriter(new File(\"output.txt\"));\n\n\t\tStringTokenizer st;\n\n\t\tst = new StringTokenizer(in.readLine());\n\t\t\n\t\tint n = Integer.parseInt(st.nextToken()),\n\t\t\tm = Integer.parseInt(st.nextToken()),\n\t\t\tk = Integer.parseInt(in.readLine());\n\t\t\n\t\tint[][] A = new int[n][m];\n\t\t\n\t\tst = new StringTokenizer(in.readLine());\n\t\tfor (int i = 0 ; i < k ; i++) {\n\t\t\tint x1 = Integer.parseInt(st.nextToken()) - 1,\n\t\t\t\ty1 = Integer.parseInt(st.nextToken()) - 1;\n\t\t\t\n\t\t\tA[x1][y1] = -10000000;\n\t\t\t\n\t\t\tfor (int j = 0 ; j < n ; j++) {\n\t\t\t\tfor (int g = 0 ; g < m ; g++) {\n\t\t\t\t\tif (A[j][g] == 0 || (A[j][g] > (Math.abs(y1 - g) + Math.abs(x1 - j)))) {\n\t\t\t\t\t\tA[j][g] = (Math.abs(y1 - g) + Math.abs(x1 - j));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint f = 0, h = 0;\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\tif (A[i][j] != -10000000) {\n\t\t\t\t\tf = i;\n\t\t\t\t\th = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\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\tif (A[i][j] > A[f][h] && A[i][j] != -10000000) {\n\t\t\t\t\tf = i;\n\t\t\t\t\th = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t//\tfor (int i = 0 ; i < n ; i++) for (int j = 0 ; j < m ; j++) System.out.println(A[i][j]);\n\t\tpw.println((f + 1) + \" \" + (h + 1));\n\t\tpw.close();\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C35C_BFS_Fire {\n    public static boolean[][] burning;\n    public static LinkedList<int[]> LitTrees; //which is best to use\n    public static int N, M;\n    public static int[] lastTree;\n    public static void main(String[] args) throws IOException {\n        // InputStreamReader stream = new InputStreamReader(System.in);\n        // BufferedReader input = new BufferedReader(stream);\n\n        BufferedReader input = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\n        StringTokenizer dataR = new StringTokenizer(input.readLine());\n        N = Integer.parseInt(dataR.nextToken());\n        M = Integer.parseInt(dataR.nextToken());\n        burning = new boolean[N+1][M+1];\n\n        StringTokenizer dataR1 = new StringTokenizer(input.readLine());\n        int K = Integer.parseInt(dataR1.nextToken());\n\n        StringTokenizer dataR2 = new StringTokenizer(input.readLine());\n        LitTrees = new LinkedList<int[]>();\n        for (int j = 0; j < K; j++){\n            int x = Integer.parseInt(dataR2.nextToken());\n            int y = Integer.parseInt(dataR2.nextToken());\n            int[] coord = {x, y};\n            LitTrees.add(coord);\n            burning[x][y] = true;\n        }\n\n        spread();\n\n        out.println(lastTree[0] + \" \" + lastTree[1]);\n        out.close();\n\n    }\n\n    public static void spread(){\n        while(!LitTrees.isEmpty()){\n            int[] studying = LitTrees.remove(); //is iterator faster\n            LinkedList<int[]> ll = new LinkedList<int[]>();\n\n            if(studying[0]-1 >= 1) ll.add(new int[]{studying[0]-1, studying[1]});\n            if(studying[1]-1 >= 1) ll.add(new int[]{studying[0], studying[1]-1});\n            if(studying[1]+1 < M+1) ll.add(new int[]{studying[0], studying[1]+1});\n            if(studying[0]+1 < N+1) ll.add(new int[]{studying[0]+1, studying[1]});\n\n            while(!ll.isEmpty()) {\n                int[] focus = ll.remove();\n                if(!burning[focus[0]][focus[1]]) {\n                    LitTrees.add(focus);\n                    burning[focus[0]][focus[1]] = true;\n                }\n            }\n\n            lastTree = studying; \n        }        \n    }\n    \n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\tstatic int n, m, k;\n\tstatic int inf = (int) 1e9;\n\tstatic class Pair {\n\t\tint x, y;\n\t\tPair(int a, int b) {\n\t\t\tx = a; y = b;\n\t\t}\n\t}\n\tstatic int[] dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};\n\tstatic boolean valid(int x, int y) {\n\t\treturn x >= 0 && x < n && y >= 0 && y < m;\n\t}\n\tstatic int[][] bfs(int[] xs, int[] ys) {\n\t\tint[][] dist = new int[n][m];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tArrays.fill(dist[i], inf);\n\t\tQueue<Pair> q = new LinkedList<>();\n\t\tfor(int i = 0; i < k; i++) {\n\t\t\tdist[xs[i]][ys[i]] = 0;\n\t\t\tq.add(new Pair(xs[i], ys[i]));\n\t\t}\n\n\t\twhile(!q.isEmpty()) {\n\t\t\tPair p = q.remove();\n\t\t\tfor(int d = 0; d < 4; d++) {\n\t\t\t\tint nx = p.x + dx[d], ny = p.y + dy[d];\n\t\t\t\tif(valid(nx, ny) && dist[nx][ny] == inf) {\n\t\t\t\t\tdist[nx][ny] = dist[p.x][p.y] + 1;\n\t\t\t\t\tq.add(new Pair(nx, ny));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn dist;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner in = new Scanner();\n\t\tint n = in.nextInt() ; \n\t\tint m = in.nextInt(); \n\t\tint k = in.nextInt(); \n\t\tint x[] = new int[k] ; \n\t\tint y[] = new int[k] ; \n\t\tint trees [][] = new int [n][m] ;\n\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\ttrees[i][j]=Integer.MAX_VALUE ;\n\n\t\tfor (int i = 0; i < k; i++)\n\t\t{\n\t\t\tx[i]=in.nextInt()-1; \n\t\t\ty[i]=in.nextInt()-1;\n\t\t\ttrees[x[i]][y[i]]=0 ;\n\t\t}\n\n\t\tint dis = Integer.MIN_VALUE ; ;\n\t\tint xp=0; ;\n\t\tint yp=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(trees[i][j] != 0)\n\t\t\t\t\tfor (int j2 = 0; j2 < k; j2++)\n\t\t\t\t\t\ttrees[i][j]=Math.min(trees[i][j], Math.abs(i-x[j2])+Math.abs(j-y[j2]));\n\n\t\tfor (int i = 0; i <n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif(trees[i][j] > dis)\n\t\t\t\t{\n\t\t\t\t\tdis=trees[i][j];\n\t\t\t\t\txp=i+1;\n\t\t\t\t\typ=j+1;\n\t\t\t\t}\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n\t\tout.printf(\"%d %d\\n\", xp ,yp);\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tScanner() throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\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 IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class sdffsdf {\n\n\tpublic static void main(String[] args) {\n\t\ttry{\n\t\t\tFile file = new File(\"input.txt\");\n\t\t\tScanner sc = new Scanner(file);\n\t\t\tString s = sc.nextLine();\n\t\t\tString[] seperatedd = s.split(\" \");\n\t\t\tint x = Integer.parseInt(seperatedd[0]);\n\t\t\tint y = Integer.parseInt(seperatedd[1]);\n\t\t\tint[][] grid = new int[x][y];\n\t\t\tfor(int i = 0; i < x; i++)\n\t\t\t{\n\t\t\t\tfor(int j = 0; j < y; j++)\n\t\t\t\t{\n\t\t\t\t\tgrid[i][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\ts = sc.nextLine();\n\t\t\tint z = Integer.parseInt(s);\n\t\t\tLinkedList<Point> BFS = new LinkedList<Point>();\n\t\t\ts = sc.nextLine();\n\t\t\tString[] seperated = s.split(\" \");\n\t\t\tfor(int i = 0; i < seperated.length; i = i + 2)\n\t\t\t{\n\t\t\t\tPoint temp = new Point();\n\t\t\t\ttemp.x = Integer.parseInt(seperated[i])-1;\n\t\t\t\ttemp.y = Integer.parseInt(seperated[i+1])-1;\n\t\t\t\tgrid[temp.x][temp.y] = 1;\n\t\t\t\tBFS.addLast(temp);\n\t\t\t}\n\t\t\twhile(!BFS.isEmpty())\n\t\t\t{\n\t\t\t\tPoint temp = new Point();\n\t\t\t\ttemp = BFS.removeFirst();\n\t\t\t \tint\tk = temp.x;\n\t\t\t \tint l = temp.y;\n\t\t\t\t\n\t\t\t\tif(!(l+1 >= y || grid[k][l+1] == 1))\n\t\t\t\t{\n\t\t\t\t\tPoint temp1 = new Point();\n\t\t\t\t\ttemp1.x = k;\n\t\t\t\t\ttemp1.y = l+1;\n\t\t\t\t\tgrid[temp1.x][temp1.y] = 1;\n\t\t\t\t\tBFS.addLast(temp1);\n\t\t\t\t}\n\t\t\t\tif(!(k+1 >= x || grid[k+1][l] == 1))\n\t\t\t\t{\n\t\t\t\t\tPoint temp1 = new Point();\n\t\t\t\t\ttemp1.x = k+1;\n\t\t\t\t\ttemp1.y = l;\n\t\t\t\t\tgrid[temp1.x][temp1.y] = 1;\n\t\t\t\t\tBFS.addLast(temp1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\tif(!(l-1 < 0 || grid[k][l-1] == 1))\n\t\t\t\t{\n\t\t\t\t\tPoint temp1 = new Point();\n\t\t\t\t\ttemp1.x = k;\n\t\t\t\t\ttemp1.y = l-1;\n\t\t\t\t\tgrid[temp1.x][temp1.y] = 1;\n\t\t\t\t\tBFS.addLast(temp1);\n\t\t\t\t}\n\t\t\t\tif(!(k-1 < 0 || grid[k-1][l] == 1))\n\t\t\t\t{\n\t\t\t\t\tPoint temp1 = new Point();\n\t\t\t\t\ttemp1.x = k-1;\n\t\t\t\t\ttemp1.y = l;\n\t\t\t\t\tgrid[temp1.x][temp1.y] = 1;\n\t\t\t\t\tBFS.addLast(temp1);\n\t\t\t\t}\n\t\t\t\tif(BFS.isEmpty())\n\t\t\t\t{\n\t\t\ttry {\n\t\t\t\t\t\tFile fil = new File(\"output.txt\");\n\t\t\t\t\t\tPrintWriter out = new PrintWriter(fil);\n\t\t\t\t\t\tint v1 = (int)temp.getX() + 1;\n\t\t\t\t\t\tint v2 = (int)temp.getY() + 1;\n\t\t\t\t\t\tout.println(v1 + \" \" + v2); \n\t\t\t\t        out.close();\t\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception e) {}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tSystem.out.println(\"nbvnb\");\n\t\t}\n\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.PrintStream;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.HashSet;\n\npublic class FireAgain {\n\n\tPoint[] coordinate;\n\tQueue<Point> q = new LinkedList<>();\n\t// HashSet<Point> vis = new HashSet<>();\n\tboolean[][] vis;\n\tPrintStream out;\n\tint x, y;\n\n\tboolean distance(Point word1, Point word2) {\n\n\t\tif (Math.abs(word1.x - word2.x) == 1 && Math.abs(word1.y - word2.y) == 1)\n\t\t\treturn false;\n\n\t\tif (Math.abs(word1.x - word2.x) == 1 && word1.y == word2.y)\n\t\t\treturn true;\n\n\t\tif (word1.x == word2.x && Math.abs(word1.y - word2.y) == 1)\n\t\t\treturn true;\n\n\t\treturn false;\n\t}\n\n\tvoid bfs(Point s) {\n\n\t\twhile (!q.isEmpty()) {\n\t\t\ts = q.poll();\n\n\t\t\tPoint p = new Point();\n\t\t\tp.x = s.x - 1;\n\t\t\tp.y = s.y;\n\n\t\t\tif (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {\n\t\t\t\tif (!vis[p.x][p.y]) {\n\t\t\t\t\tvis[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tp = new Point();\n\t\t\tp.x = s.x + 1;\n\t\t\tp.y = s.y;\n\n\t\t\tif (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {\n\t\t\t\tif (!vis[p.x][p.y]) {\n\t\t\t\t\tvis[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tp = new Point();\n\t\t\tp.x = s.x;\n\t\t\tp.y = s.y - 1;\n\n\t\t\tif (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {\n\t\t\t\tif (!vis[p.x][p.y]) {\n\t\t\t\t\tvis[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tp = new Point () ;\n\t\t\tp.x = s.x ;\n\t\t\tp.y = s.y + 1;\n\t\t\t\n\t\t\tif (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {\n\t\t\t\tif (!vis[p.x][p.y]) {\n\t\t\t\t\tvis[p.x][p.y] = true ;\n\t\t\t\t\tq.add(p);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (q.size() == 0)\n\t\t\t\tout.print(s.x + \" \" + s.y);\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// TODO Auto-generated method stub\n\n\t\tFireAgain F = new FireAgain();\n\t\t Scanner in = new Scanner (new FileReader(\"input.txt\"));\n\t\t F.out = new PrintStream(new File(\"output.txt\"));\n\t\n\t\tF.x = in.nextInt();\n\t\tF.y = in.nextInt();\n\n\t\tint l = 0;\n\t\tF.vis = new boolean[F.x + 1][F.y + 1];\n\n\t\tint k = in.nextInt();\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tPoint P = new Point(in.nextInt(), in.nextInt());\n\t\t\tF.vis[P.x][P.y] = true; // add in set\n\t\t\tF.q.add(P);\n\t\t}\n\n\t\tF.bfs(F.q.peek());\n\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.security.KeyStore.Entry;\nimport java.util.*;\n\n\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\tpublic class QA {\n\t\t\t\t\n\t\t\t\tstatic long MOD = 1000000007;\n\t\t\t\tstatic boolean b[], b1[], check;\n\t\t\t\tstatic ArrayList<Integer>[] amp, pa;\n\t\t\t\tstatic ArrayList<Pair>[] amp1;\n\t\t\t\tstatic ArrayList<Pair>[][] damp;\n\t\t\t\tstatic int left[],right[],end[],sum[],dist[],cnt[],start[],color[],parent[],prime[],size[];\n\t\t\t\tstatic int ans = 0,k;\n\t\t\t\tstatic int p = 0;\n\t\t\t\tstatic FasterScanner sc = new FasterScanner(System.in);\n\t\t\t\t//static Queue<Integer> q = new LinkedList<>();\n\t\t\t\tstatic BufferedWriter log;\n\t\t\t\tstatic HashSet<Pair> hs;\n\t\t\t\tstatic HashMap<Pair,Integer> hm;\n\t\t\t\tstatic PriorityQueue<Integer> pri[];\n\t\t\t\tstatic ArrayList<Integer>[] level;\n\t\t\t\tstatic Stack<Integer> st;\n\t\t\t\tstatic boolean boo[][];\n\t\t\t\tstatic Pair prr[];\n\t\t\t\tstatic long parent1[],parent2[],size1[],size2[],arr1[],SUM[],lev[], fibo[];\n\t\t\t\tstatic int arr[], ver[][];\n\t\t\t\tstatic private PrintWriter out = new PrintWriter(System.out);\n\t\t\t\tpublic static void main(String[] args) throws Exception {\n\t\t\t    \tnew Thread(null, new Runnable() {\n\t\t\t\t\t\tpublic void run() {\n\t\t\t\t\t\t\ttry {\n\t\t\t\tsoln();\n\t\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\t\t\tSystem.out.println(e);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}, \"1\", 1 << 26).start();\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tprivate static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\t\t\tprivate static void tr(Object... o) {\n\t\t\t\t\tif (!oj)\n\t\t\t\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t\t\t\t}\n\t\t\t\tstatic int dp[][];\n\t\t\t\tstatic int N,K,T,A,B;\n\t\t\t\tstatic long time;\n\t\t\t\tstatic int cost[][];\n\t\t\t\tstatic boolean b11[];\n\t\t\t\tstatic HashMap<Integer,Integer> h = new HashMap<>();\n\t\t\t\tstatic HashSet<Pair> chec;\n\t\t\t\tstatic long ans1;\t\tstatic long ans2;\n\t\t\t\tstatic int BLOCK, MAX = 1000001;\n\t\t\t\tstatic double pi = Math.PI;\n\t\t\t\tstatic int Arr[], Brr[], pow[],  M;\n\t\t\t\tstatic long fact[] = new long[100000+1];\n\t\t\t\tstatic HashMap<Integer,Long> hm1;\n\t\t\t\tstatic HashSet<Integer> hs1[], hs2[];\n\t\t\t\tstatic String[] str2;\n\t\t\t\tstatic char[] ch1, ch2;\n\t\t\t\tstatic int[] s,f,D;\n\t\t\t\tstatic int tf,ts;\n\t\t\t\tstatic int see[][] = new int[2050][2050];\n\t\t\t\tstatic boolean bee[][] = new boolean[2050][2050];\n\t\t\t\tstatic Queue<Pair> q = new LinkedList<>();\n\t\t\t\t//static PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\t\t\t\tpublic static void soln() throws IOException {\n\t\t\t\t\t//System.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t\t\t//System.setOut(new PrintStream(\"output.txt\"));\n\t\t\t\t\tFasterScanner sc = new FasterScanner(new FileInputStream(\"input.txt\"));//(\"C:\\\\Users\\\\Admin\\\\Desktop\\\\QAL2.txt\"));\n\t\t\t\t\t//PrintWriter log1 = new PrintWriter(\"C:\\\\Users\\\\Admin\\\\Desktop\\\\input01\");\n\t\t\t\t\tPrintWriter log = new PrintWriter(\"output.txt\");//(\"C:\\\\Users\\\\Admin\\\\Desktop\\\\output00\");\n\t\t\t\t\t//log = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t\t\tint n = sc.nextInt() , m = sc.nextInt();\n\t\t\t\t\tint k = sc.nextInt();\n\t\t\t\t\tfor(int i = 1; i <= n ; i++) for(int j  =1;j<=m;j++) see[i][j]= 100000000;\n\t\t\t\t\tfor(int i = 0; i < k; i++){\n\t\t\t\t\t\tint x = sc.nextInt(), y = sc.nextInt();\n\t\t\t\t\t\tbee[x][y] = true;\n\t\t\t\t\t\tsee[x][y] = 0;\n\t\t\t\t\t\tq.add(new Pair(x,y));\n\t\t\t\t\t}\n\t\t\t\t\twhile(!q.isEmpty()){\n\t\t\t\t\t\t//System.out.println(q);\n\t\t\t\t\t\tint x = q.peek().u, y = q.poll().v;\n\t\t\t\t\t\tif(x>1){\n\t\t\t\t\t\t\tsee[x-1][y] = min(see[x][y]+1,see[x-1][y]);\n\t\t\t\t\t\t\tif(!bee[x-1][y]) q.add(new Pair(x-1,y));\n\t\t\t\t\t\t\tbee[x-1][y] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(x<n){\n\t\t\t\t\t\t\tsee[x+1][y] = min(see[x][y]+1,see[x+1][y]);\n\t\t\t\t\t\t\tif(!bee[x+1][y]) q.add(new Pair(x+1,y));\n\t\t\t\t\t\t\tbee[x+1][y] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(y>1){\n\t\t\t\t\t\t\tsee[x][y-1] = min(see[x][y]+1,see[x][y-1]);\n\t\t\t\t\t\t\tif(!bee[x][y-1]) q.add(new Pair(x,y-1));\n\t\t\t\t\t\t\tbee[x][y-1] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(y<m){\n\t\t\t\t\t\t\tsee[x][y+1] = min(see[x][y]+1,see[x][y+1]);\n\t\t\t\t\t\t\tif(!bee[x][y+1]) q.add(new Pair(x,y+1));\n\t\t\t\t\t\t\tbee[x][y+1] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint ans = -1;\n\t\t\t\t\tPair temp = null;\n\t\t\t\t\tfor(int i = 1;i<=n;i++){\n\t\t\t\t\t\tfor(int j = 1;j<=m;j++){\n\t\t\t\t\t\t\tif(see[i][j]>ans) {\n\t\t\t\t\t\t\t\tans = see[i][j];\n\t\t\t\t\t\t\t\ttemp = new Pair(i,j);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tlog.write(temp.u+\" \"+temp.v);\n\t\t\t\t\tlog.close();\n\t\t\t\t}\n\t\t\t\tstatic int min(int a, int b){\n\t\t\t\t\tif(a>b) return b;\n\t\t\t\t\treturn a;\n\t\t\t\t}\n\t\t\t\tprivate static double dfs(int cur,int prev){\n\t\t\t\t\tdouble r=0,n=0;\n\t\t\t\t\tfor(int i : amp[cur]){\n\t\t\t\t\t\tif(i!=prev){\n\t\t\t\t\t\t\tr+=(1+dfs(i,cur));\n\t\t\t\t\t\t\tn++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif(n!=0){\n\t\t\t\t\t\tr=r/n;\n\t\t\t\t\t}\n\t\t\t\t\treturn r;\n\t\t\t\t}\n\t\t\t\tstatic double fa1 = 0;\n\t\t\t\tstatic int fa = -1;\n\t\t\t\tstatic long nCr1(int n, int r){\n\t\t\t\t\tif(n<r) return 0;\n\t\t\t\t\treturn (((fact[n] * modInverse(fact[n-r], MOD))%MOD)*modInverse(fact[r], MOD))%MOD;\n\t\t\t\t}\n\t\t\t\tstatic class Node{\n\t\t\t\t\tNode arr[] = new Node[2]; \n\t\t\t\t\tint cnt[] = new int[2];\n\t\t\t\t}\n\t\t\t\tpublic static class Trie{\n\t\t\t\t\tNode root;\n\t\t\t\t\tpublic Trie(){\n\t\t\t\t\t\troot = new Node();\n\t\t\t\t\t}\n\t\t\t\t\tpublic void insert(String x){\n\t\t\t\t\t\tNode n = root;\n\t\t\t\t\t\tfor(int i = 0;i < x.length() ;i++){\n\t\t\t\t\t\t\tint a1 = x.charAt(i)-'0';\n\t\t\t\t\t\t\tif(n.arr[a1]!=null){\n\t\t\t\t\t\t\t\tn.cnt[a1]++;\n\t\t\t\t\t\t\t\tn = n.arr[a1];\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tn.arr[a1] = new Node();\n\t\t\t\t\t\t\tn.cnt[a1]++;\n\t\t\t\t\t\t\tn = n.arr[a1];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpublic void delete(String x){\n\t\t\t\t\t\tNode n = root;\n\t\t\t\t\t\tfor(int i = 0;i < x.length() ;i++){\n\t\t\t\t\t\t\tint a1 = x.charAt(i)-'0';\n\t\t\t\t\t\t\tif(n.cnt[a1]==1){\n\t\t\t\t\t\t\t\tn.arr[a1] = null;\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tn.cnt[a1]--;\n\t\t\t\t\t\t\t\tn = n.arr[a1];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpublic long get(String x){\n\t\t\t\t\t\tNode n = root;\n\t\t\t\t\t\tlong ans = 0;\n\t\t\t\t\t\tfor(int i = 0;i < x.length() ;i++){\n\t\t\t\t\t\t\tint a1 = '1' - x.charAt(i);\n\t\t\t\t\t\t\tif(n.arr[a1]!=null){\n\t\t\t\t\t\t\t\tans += Math.pow(2, 30-i);\n\t\t\t\t\t\t\t\tn = n.arr[a1];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse n = n.arr[1-a1];\n\t\t\t\t\t\t//\tSystem.out.println(ans);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn ans;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpublic static class FenwickTree {\n\t\t\t\t\t\n\t\t\t\t    int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates\n\t\n\t\t\t\t    public FenwickTree(int size) {\n\t\t\t\t        array = new int[size + 1];\n\t\t\t\t    }\n\t\t\t\t    public int rsq(int ind) {\n\t\t\t\t        assert ind > 0;\n\t\t\t\t        int sum = 0;\n\t\t\t\t        while (ind > 0) {\n\t\t\t\t            sum += array[ind];\n\t\t\t\t            //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number\n\t\t\t\t            ind -= ind & (-ind);\n\t\t\t\t        }\n\t\t\t\t        return sum;\n\t\t\t\t    }\n\t\t\t\t    public int rsq(int a, int b) {\n\t\t\t\t        assert b >= a && a > 0 && b > 0;\n\t\t\t\t        return rsq(b) - rsq(a - 1);\n\t\t\t\t    }\n\t\t\t\t    public void update(int ind, int value) {\n\t\t\t\t        assert ind > 0;\n\t\t\t\t        while (ind < array.length) {\n\t\t\t\t            array[ind] += value;\n\t\t\t\t            //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number\n\t\t\t\t            ind += ind & (-ind);\n\t\t\t\t        }\n\t\t\t\t    }\n\t\n\t\t\t\t    public int size() {\n\t\t\t\t        return array.length - 1;\n\t\t\t\t    }\n\t\t\t\t}\n\t\t\t\tstatic double power(double x, long y)\n\t\t\t\t{\n\t\t\t\t    if (y == 0)\n\t\t\t\t        return 1;\n\t\t\t\t    double p = power(x, y/2);\n\t\t\t\t    p = (p * p);\n\t\t\t\t \n\t\t\t\t    return (y%2 == 0)? p : (x * p);\n\t\t\t\t}\n\t\t\t\tstatic int Dfs(int x, int val){\n\t\t\t\t\tb[x] = true;\n\t\t\t\t\tfor(int p:hs2[x]){\n\t\t\t\t\t\tif(!b[p]){\n\t\t\t\t\t\t\tif(!hs1[x].contains(p)) val++;\n\t\t\t\t\t\t\tval += Dfs(p,0);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn val;\n\t\t\t\t}\n\t\t\t\tstatic long nCr(int n, int r){\n\t\t\t\t\tif(n<r) return 0;\n\t\t\t\t\telse return (((fact[n]*modInverse(fact[r], MOD))%MOD)*modInverse(fact[n-r], MOD))%MOD;\n\t\t\t\t}\n\t\t\t\tstatic void dfs1(int x, int p){\n\t\t\t\t\tarr1[x] += lev[x];\n\t\t\t\t\tfor(int v:amp[x]){\n\t\t\t\t\t\tif(v!=p){\n\t\t\t\t\t\t\tdfs1(v,x);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic void bfs(int x){\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tpublic static void seive(int n){\n\t\t\t\t\tb = new boolean[(n+1)];\n\t\t\t\t\tArrays.fill(b, true);\n\t\t\t\t\tb[1] = true;\n\t\t\t\t\tfor(int i = 2;i*i<=n;i++){\n\t\t\t\t\t\tif(b[i]){\n\t\t\t\t\t\t\tfor(int p = 2*i;p<=n;p+=i){\n\t\t\t\t\t\t\t\tb[p] = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t/*for(int i = 2;i<=n;i++){\n\t\t\t\t\t\tif(b[i]) prime[i] = i;\n\t\t\t\t\t}*/\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic class Graph{\n\t\t\t\t\tint vertex;\n\t\t\t\t\tint weight;\n\t\t\t\t\tGraph(int v, int w){\n\t\t\t\t\t\tvertex = v;\n\t\t\t\t\t\tweight = w;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstatic class Pair implements Comparable<Pair> {\n\t\t\t\t\tint u;\n\t\t\t\t\tint v;\n\t\t\t\t\tint ans;\n\t\t\t\t\tpublic Pair(){\n\t\t\t\t\t\tu = 0;\n\t\t\t\t\t\tv = 0;\n\t\t\t\t\t}\n\t\t\t\t\tpublic Pair(int u, int v) {\n\t\t\t\t\t\tthis.u = u;\n\t\t\t\t\t\tthis.v = v;\n\t\t\t\t\t}\n\t\t\t\t\tpublic int hashCode() {\n\t\t\t\t\t\treturn Objects.hash();\n\t\t\t\t\t}\n\t\t\t\t\tpublic boolean equals(Object o) {\n\t\t\t\t\t\tPair other = (Pair) o;\n\t\t\t\t\t\treturn ((u == other.u && v == other.v && ans == other.ans));\n\t\t\t\t\t}\n\t\t\t \n\t\t\t\t\tpublic int compareTo(Pair other) {\n\t\t\t\t\t\t//return Double.compare(ans, other.ans);\n\t\t\t\t\t\treturn Long.compare(u, other.u); \n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tpublic String toString() {\n\t\t\t\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic static void buildGraph(int n){\n\t\t\t\t\tfor(int i =0;i<n;i++){\n\t\t\t\t\t\tint x = sc.nextInt()-1, y = sc.nextInt()-1;\n\t\t\t\t\t\tamp[x].add(y);\n\t\t\t\t\t\tamp[y].add(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\tpublic static int getParent(long x){\n\t\t\t\t\twhile(parent[(int) x]!=x){\n\t\t\t\t\t\tparent[ (int) x] = parent[(int) parent[ (int) x]];\n\t\t\t\t\t\tx = parent[ (int) x];\n\t\t\t\t\t}\n\t\t\t\t\treturn (int) x;\n\t\t\t\t}\n\t\t\t\tstatic long min(long a, long b, long c){\n\t\t\t\t\tif(a<b && a<c) return a;\n\t\t\t\t\tif(b<c) return b;\n\t\t\t\t\treturn c;\n\t\t\t\t}\n\t\t\t\t/*\n\t\t\t\t\n\t\t\t\tstatic class Pair3{\n\t\t\t\t\tint x, y ,z;\n\t\t\t\t\tPair3(int x, int y, int z){\n\t\t\t\t\t\tthis.x = x;\n\t\t\t\t\t\tthis.y = y;\n\t\t\t\t\t\tthis.z = z;\n\t\t\t\t\t}\n\t\t\t\t}*/\n\t\t\t\t static void KMPSearch(String pat, String txt)\n\t\t\t\t    {\n\t\t\t\t        int M = pat.length();\n\t\t\t\t        int N = txt.length();\n\t\t\t\t \n\t\t\t\t        // create lps[] that will hold the longest\n\t\t\t\t        // prefix suffix values for pattern\n\t\t\t\t        int lps[] = new int[M];\n\t\t\t\t        int j = 0;  // index for pat[]\n\t\t\t\t \n\t\t\t\t        // Preprocess the pattern (calculate lps[]\n\t\t\t\t        // array)\n\t\t\t\t        computeLPSArray(pat,M,lps);\n\t\t\t\t \n\t\t\t\t        int i = 0;  // index for txt[]\n\t\t\t\t        while (i < N)\n\t\t\t\t        {\n\t\t\t\t            if (pat.charAt(j) == txt.charAt(i))\n\t\t\t\t            {\n\t\t\t\t                j++;\n\t\t\t\t                i++;\n\t\t\t\t            }\n\t\t\t\t            if (j == M)\n\t\t\t\t            {\n\t\t\t\t               // parent.add((i-j));\n\t\t\t\t                j = lps[j-1];\n\t\t\t\t            }\n\t\t\t\t \n\t\t\t\t            // mismatch after j matches\n\t\t\t\t            else if (i < N && pat.charAt(j) != txt.charAt(i))\n\t\t\t\t            {\n\t\t\t\t                // Do not match lps[0..lps[j-1]] characters,\n\t\t\t\t                // they will match anyway\n\t\t\t\t                if (j != 0)\n\t\t\t\t                    j = lps[j-1];\n\t\t\t\t                else\n\t\t\t\t                    i = i+1;\n\t\t\t\t            }\n\t\t\t\t        }\n\t\t\t\t    }\n\t\t\t\t static void computeLPSArray(String pat, int M, int lps[])\n\t\t\t\t    {\n\t\t\t\t        // length of the previous longest prefix suffix\n\t\t\t\t        int len = 0;\n\t\t\t\t        int i = 1;\n\t\t\t\t        lps[0] = 0;  // lps[0] is always 0\n\t\t\t\t \n\t\t\t\t        // the loop calculates lps[i] for i = 1 to M-1\n\t\t\t\t        while (i < M)\n\t\t\t\t        {\n\t\t\t\t            if (pat.charAt(i) == pat.charAt(len))\n\t\t\t\t            {\n\t\t\t\t                len++;\n\t\t\t\t                lps[i] = len;\n\t\t\t\t                i++;\n\t\t\t\t            }\n\t\t\t\t            else  // (pat[i] != pat[len])\n\t\t\t\t            {\n\t\t\t\t                // This is tricky. Consider the example.\n\t\t\t\t                // AAACAAAA and i = 7. The idea is similar \n\t\t\t\t                // to search step.\n\t\t\t\t                if (len != 0)\n\t\t\t\t                {\n\t\t\t\t                    len = lps[len-1];\n\t\t\t\t \n\t\t\t\t                    // Also, note that we do not increment\n\t\t\t\t                    // i here\n\t\t\t\t                }\n\t\t\t\t                else  // if (len == 0)\n\t\t\t\t                {\n\t\t\t\t                    lps[i] = len;\n\t\t\t\t                    i++;\n\t\t\t\t                }\n\t\t\t\t            }\n\t\t\t\t        }\n\t\t\t\t    }\n\t\t\t\tprivate static void permutation(String prefix, String str) {\n\t\t\t\t    int n = str.length();\n\t\t\t\t    if (n == 0); //hs.add(prefix);\n\t\t\t\t    else {\n\t\t\t\t        for (int i = 0; i < n; i++)\n\t\t\t\t            permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));\n\t\t\t\t    }\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic static void buildTree(int n){\n\t\t\t\t\tint arr[] = sc.nextIntArray(n);\n\t\t\t\t\tfor(int i = 0;i<n;i++){\n\t\t\t\t\t\tint x = arr[i]-1;\n\t\t\t\t\t\tamp[i+1].add(x);\n\t\t\t\t\t\tamp[x].add(i+1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic class SegmentTree {\n\t\t\t\t\tboolean st[];\n\t\t\t\t\tboolean lazy[];\n\t\t\n\t\t\t\t\tSegmentTree(int n) {\n\t\t\t\t\t\tint size = 4 * n;\n\t\t\t\t\t\tst = new boolean[size];\n\t\t\t\t\t\tArrays.fill(st, true);\n\t\t\t\t\t\tlazy = new boolean[size];\n\t\t\t\t\t\tArrays.fill(lazy, true);\n\t\t\t\t\t\t//build(0, n - 1, 1);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t/*long[] build(int ss, int se, int si) {\n\t\t\t\t\t\tif (ss == se) {\n\t\t\t\t\t\t\tst[si][0] = 1;\n\t\t\t\t\t\t\tst[si][1] = 1;\n\t\t\t\t\t\t\tst[si][2] = 1;\n\t\t\t\t\t\t\treturn st[si];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint mid = (ss + se) / 2;\n\t\t\t\t\t\tlong a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se,\n\t\t\t\t\t\t\t\tsi * 2 + 1);\n\t\t\t\t\t\tlong ans[] = new long[3];\n\t\t\t\t\t\tif (arr[mid] < arr[mid + 1]) {\n\t\t\t\t\t\t\tans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0]));\n\t\t\t\t\t\t\tif (a1[1] == (mid - ss + 1))\n\t\t\t\t\t\t\t\tans[0] = ans[1];\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tans[0] = a1[0];\n\t\t\t\t\t\t\tif (a2[2] == (se - mid))\n\t\t\t\t\t\t\t\tans[2] = ans[1];\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tans[2] = a2[2];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tans[1] = Math.max(a1[1], a2[1]);\n\t\t\t\t\t\t\tans[0] = a1[0];\n\t\t\t\t\t\t\tans[2] = a2[2];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tst[si] = ans;\n\t\t\t\t\t\treturn st[si];\n\t\t\t\t\t}*/\n\t\t\n\t\t\t\t\tvoid update(int si, int ss, int se, int idx, long x) {\n\t\t\t\t\t\tif (ss == se) {\n\t\t\t\t\t\t\t//arr[idx] += val;\n\t\t\t\t\t\t\tst[si]=false;\n\t\t\t\t\t\t} \n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tint mid = (ss + se) / 2;\n\t\t\t\t\t\t\tif(ss <= idx && idx <= mid)\n\t\t\t\t\t        {\n\t\t\t\t\t             update(2*si, ss, mid, idx, x);\n\t\t\t\t\t        }\n\t\t\t\t\t        else\n\t\t\t\t\t        { update(2*si+1, mid+1, se, idx, x);\n\t\t\t\t\t        }\n\t\t\t\t\t\t\tst[si] = st[2*si]|st[2*si+1];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t/*boolean get(int qs, int qe, int ss, int se, int si){\n\t\t\t\t\t\tif(qs>se || qe<ss) return 0;\n\t\t\t\t\t\tif (qs <= ss && qe >= se) {\n\t\t\t\t\t\t\treturn st[si];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint mid = (ss+se)/2;\n\t\t\t\t\t\treturn get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1);\n\t\t\t\t\t}*/\n\t\t\t\t\tvoid updateRange(int node, int start, int end, int l, int r, boolean val)\n\t\t\t\t\t{\n\t\t\t\t\t    if(!lazy[node])\n\t\t\t\t\t    { \n\t\t\t\t\t        // This node needs to be updated\n\t\t\t\t\t        st[node] = lazy[node];    // Update it\n\t\t\t\t\t        if(start != end)\n\t\t\t\t\t        {\n\t\t\t\t\t            lazy[node*2] = lazy[node];                  // Mark child as lazy\n\t\t\t\t\t            lazy[node*2+1] = lazy[node];                // Mark child as lazy\n\t\t\t\t\t        }\n\t\t\t\t\t        lazy[node] = true;                                  // Reset it\n\t\t\t\t\t    }\n\t\t\t\t\t    if(start > end || start > r || end < l)              // Current segment is not within range [l, r]\n\t\t\t\t\t        return;\n\t\t\t\t\t    if(start >= l && end <= r)\n\t\t\t\t\t    {\n\t\t\t\t\t        // Segment is fully within range\n\t\t\t\t\t        st[node] =  val;\n\t\t\t\t\t        if(start != end)\n\t\t\t\t\t        {\n\t\t\t\t\t            // Not leaf node\n\t\t\t\t\t            lazy[node*2] = val;\n\t\t\t\t\t            lazy[node*2+1] = val;\n\t\t\t\t\t        }\n\t\t\t\t\t        return;\n\t\t\t\t\t    }\n\t\t\t\t\t    int mid = (start + end) / 2;\n\t\t\t\t\t    updateRange(node*2, start, mid, l, r, val);        // Updating left child\n\t\t\t\t\t    updateRange(node*2 + 1, mid + 1, end, l, r, val);   // Updating right child\n\t\t\t\t\t    st[node] = st[node*2] | st[node*2+1];        // Updating root with max value \n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tboolean queryRange(int node, int start, int end, int l, int r)\n\t\t\t\t\t{\n\t\t\t\t\t    if(start > end || start > r || end < l)\n\t\t\t\t\t        return false;         // Out of range\n\t\t\t\t\t    if(!lazy[node])\n\t\t\t\t\t    {\n\t\t\t\t\t        // This node needs to be updated\n\t\t\t\t\t        st[node] = lazy[node];            // Update it\n\t\t\t\t\t        if(start != end)\n\t\t\t\t\t        {\n\t\t\t\t\t            lazy[node*2] = lazy[node];         // Mark child as lazy\n\t\t\t\t\t            lazy[node*2+1] = lazy[node];    // Mark child as lazy\n\t\t\t\t\t        }\n\t\t\t\t\t        lazy[node] = true;                 // Reset it\n\t\t\t\t\t    }\n\t\t\t\t\t    if(start >= l && end <= r)             // Current segment is totally within range [l, r]\n\t\t\t\t\t        return  st[node];\n\t\t\t\t\t    int mid = (start + end) / 2;\n\t\t\t\t\t    boolean p1 = queryRange(node*2, start, mid, l, r);         // Query left child\n\t\t\t\t\t    boolean b = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child\n\t\t\t\t\t    return (p1 | b);\n\t\t\t\t\t}\n\t\t\t\t\tvoid print() {\n\t\t\t\t\t\tfor (int i = 0; i < st.length; i++) {\n\t\t\t\t\t\t\tSystem.out.print(st[i]+\" \");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tSystem.out.println();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstatic int convert(int x){\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t\tString str = Integer.toBinaryString(x);\n\t\t\t\t\t//System.out.println(str);\n\t\t\t\t\tfor(int i = 0;i<str.length();i++){\n\t\t\t\t\t\tif(str.charAt(i)=='1'){\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\tint ans = (int) Math.pow(3, 6-cnt);\n\t\t\t\t\treturn ans;\n\t\t\t\t}\n\t\t\t\tstatic class Node2{\n\t\t\t\t\tNode2 left = null;\n\t\t\t\t\tNode2 right = null;\n\t\t\t\t\tNode2 parent = null;\n\t\t\t\t\tint data;\n\t\t\t\t}\n\t\t\t\tstatic boolean check(char ch[][], int i, int j){\n\t\t\t\t\tif(ch[i][j]=='O') return false;\n\t\t\t\t\tchar c = ch[i][j];\n\t\t\t\t\tch[i][j] = 'X';\n\t\t\t\t\tif(c=='X'){\n\t\t\t\t\tif(i>=4){\n\t\t\t\t\t\tint x = 0;\n\t\t\t\t\t\tint l = 0;\n\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\tif(ch[i-x][j]!='X'){ if(ch[i-x][j]!='.') break;else l++;}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\tif(j>=4){\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i-x][j-x]!='X'){ if(ch[i-x][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t\t l =0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(j<=5){\n\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i-x][j+x]!='X'){ if(ch[i-x][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif(i<=5){\n\t\t\t\t\t\tint x = 0;\n\t\t\t\t\t\tint l = 0;\n\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\tif(ch[i+x][j]!='X'){ if(ch[i+x][j]!='.') break; else l++;}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\tif(j>=4){\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i+x][j-x]!='X'){ if(ch[i+x][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t\t l =0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(j<=5){\n\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i+x][j+x]!='X'){ if(ch[i+x][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=1) return true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tif(i>=4){\n\t\t\t\t\t\t\tint x = 0;\n\t\t\t\t\t\t\tint l = 0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i-x][j]!='X'){ if(ch[i-x][j]!='.') break;else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\tif(j>=4){\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i-x][j-x]!='X'){ if(ch[i-x][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t\t l =0;\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(j<=5){\n\t\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i-x][j+x]!='X'){ if(ch[i-x][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(i<=5){\n\t\t\t\t\t\t\tint x = 0;\n\t\t\t\t\t\t\tint l = 0;\n\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\tif(ch[i+x][j]!='X'){ if(ch[i+x][j]!='.') break; else l++;}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\tif(j>=4){\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i+x][j-x]!='X'){ if(ch[i+x][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t\t l =0;\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(j<=5){\n\t\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return true;\n\t\t\t\t\t\t\t\tl = 0;\n\t\t\t\t\t\t\t\tfor(x = 0;x<=4;x++){\n\t\t\t\t\t\t\t\t\tif(ch[i+x][j+x]!='X'){ if(ch[i+x][j+x]!='.') break; else l++;}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(x==5 && l<=0) return 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\tch[i][j] = c;\n\t\t\t\t\t\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tstatic class BinarySearchTree{\n\t\t\t\t\tNode2 root = null;\n\t\t\t\t\tint height = 0;\n\t\t\t\t\tint max = 0;\n\t\t\t\t\tint cnt = 1;\n\t\t\t\t\tArrayList<Integer> parent = new ArrayList<>();\n\t\t\t\t\tHashMap<Integer, Integer> hm = new HashMap<>();\n\t\t\t\t\tpublic void insert(int x){\n\t\t\t\t\t\tNode2 n = new Node2();\n\t\t\t\t\t\tn.data = x;\n\t\t\t\t\t\tif(root==null){\n\t\t\t\t\t\t\troot = n;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tNode2 temp = root,temb = null;\n\t\t\t\t\t\t\twhile(temp!=null){\n\t\t\t\t\t\t\t\ttemb = temp;\n\t\t\t\t\t\t\t\tif(x>temp.data) temp = temp.right;\n\t\t\t\t\t\t\t\telse temp = temp.left;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(x>temb.data) temb.right = n;\n\t\t\t\t\t\t\telse temb.left = n;\n\t\t\t\t\t\t\tn.parent = temb;\n\t\t\t\t\t\t\tparent.add(temb.data);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpublic Node2 getSomething(int x, int y, Node2 n){\n\t\t\t\t\t\tif(n.data==x || n.data==y) return n;\n\t\t\t\t\t\telse if(n.data>x && n.data<y) return n;\n\t\t\t\t\t\telse if(n.data<x && n.data<y) return getSomething(x,y,n.right);\n\t\t\t\t\t\telse return getSomething(x,y,n.left);\n\t\t\t\t\t}\n\t\t\t\t\tpublic Node2 search(int x,Node2 n){\n\t\t\t\t\t\tif(x==n.data){\n\t\t\t\t\t\t\tmax = Math.max(max, n.data);\n\t\t\t\t\t\t\treturn n;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(x>n.data){\n\t\t\t\t\t\t\tmax = Math.max(max, n.data);\n\t\t\t\t\t\t\treturn search(x,n.right);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tmax = Math.max(max, n.data);\n\t\t\t\t\t\t\treturn search(x,n.left);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpublic int getHeight(Node2 n){\n\t\t\t\t\t\tif(n==null) return 0;\n\t\t\t\t\t\theight = 1+ Math.max(getHeight(n.left), getHeight(n.right));\n\t\t\t\t\t\treturn height;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstatic long findDiff(long[] arr, long[] brr, int m){\n\t\t\t\t\tint i = 0, j = 0;\n\t\t\t\t\tlong fa = 1000000000000L;\n\t\t\t\t\twhile(i<m && j<m){\n\t\t\t\t\t\tlong x = arr[i]-brr[j];\n\t\t\t\t\t\tif(x>=0){\n\t\t\t\t\t\t\tif(x<fa) fa = x;\n\t\t\t\t\t\t\tj++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tif((-x)<fa) fa = -x;\n\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn fa;\n\t\t\t\t}\n\t\t\t\tpublic static long max(long x, long y, long z){\n\t\t\t\t\tif(x>=y && x>=z) return x;\n\t\t\t\t\tif(y>=x && y>=z) return y;\n\t\t\t\t\treturn z;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic long modInverse(long a, long mOD2){\n\t\t\t\t            return  power(a, mOD2-2, mOD2);\n\t\t\t\t}\n\t\t\t\tstatic long power(long x, long y, long m)\n\t\t\t\t{\n\t\t\t\t    if (y == 0)\n\t\t\t\t        return 1;\n\t\t\t\t    long p = power(x, y/2, m) % m;\n\t\t\t\t    p = (p * p) % m;\n\t\t\t\t \n\t\t\t\t    return (y%2 == 0)? p : (x * p) % m;\n\t\t\t\t}\n\t\t\t\tstatic long d,x,y;\n\t\t\t\tpublic static void extendedEuclidian(long a, long b){\n\t\t\t\t\tif(b == 0) {\n\t\t\t\t        d = a;\n\t\t\t\t        x = 1;\n\t\t\t\t        y = 0;\n\t\t\t\t    }\n\t\t\t\t    else {\n\t\t\t\t        extendedEuclidian(b, a%b);\n\t\t\t\t        int temp = (int) x;\n\t\t\t\t        x = y;\n\t\t\t\t        y = temp - (a/b)*y;\n\t\t\t\t    }\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic static long gcd(long n, long m){\n\t\t\t\t\tif(m!=0) return gcd(m,n%m);\n\t\t\t\t\telse return n;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic BufferedReader reader;\n\t\t\t    static StringTokenizer tokenizer;\n\t\t\t    static PrintWriter writer;\n\t\t\t\n\t\t\t\n\t\t\t   \n\t\t\t    static class FasterScanner {\n\t\t\n\t\t\t\t\tprivate final InputStream stream;\n\t\t\t\t\tprivate final byte[] buf = new byte[8192];\n\t\t\t\t\tprivate int curChar, snumChars;\n\t\t\t\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\t\t\t\tpublic FasterScanner(InputStream stream) {\n\t\t\t\t\t\tthis.stream = stream;\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic int snext() {\n\t\t\t\t\t\tif (snumChars == -1)\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tif (curChar >= snumChars) {\n\t\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic int nextInt() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint res = 0;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res * sgn;\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic long nextLong() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlong res = 0;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res * sgn;\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic int[] nextIntArray(int n) {\n\t\t\t\t\t\tint a[] = new int[n];\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\ta[i] = nextInt();\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn a;\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic long[] nextLongArray(int n) {\n\t\t\t\t\t\tlong a[] = new long[n];\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\ta[i] = nextLong();\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn a;\n\t\t\t\t\t}\n\t\t\t                \n\t\t\t\t\tpublic String readString() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res.toString();\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic String nextLine() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isEndOfLine(c));\n\t\t\t\t\t\treturn res.toString();\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic boolean isSpaceChar(int c) {\n\t\t\t\t\t\tif (filter != null)\n\t\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tprivate boolean isEndOfLine(int c) {\n\t\t\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t\t\t}\n\t\t\n\t\t\t\t\tpublic interface SpaceCharFilter {\n\t\t\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}  ", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import javax.annotation.processing.SupportedSourceVersion;\nimport java.io.*;\nimport java.util.*;\nimport java.util.regex.Matcher;\n\npublic class Main {\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(new FileReader(\"input.txt\")); // new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(\"output.txt\"); //new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(in, out);\n        out.close();\n    }\n\n    private static class TaskB {\n\n        static final long max = 1000000000000000000L;\n        static final double eps = 0.0000001;\n        static final long mod = 1000000007;\n        static int N, M, K;\n        static long X, Y;\n        static boolean F[][][];\n        static int D[][];\n\n        void solve(InputReader in, PrintWriter out) throws IOException {\n\n            N = in.nextInt();\n            M = in.nextInt();\n            K = in.nextInt();\n\n            F = new boolean[K][N][M];\n            D = new int[N][M];\n\n            for (int i = 0; i < N; i++)\n                for (int j = 0; j < M; j++)\n                    D[i][j] = Integer.MAX_VALUE;\n\n            List<Pair> list = new ArrayList<>();\n\n            for (int i = 0; i < K; i++) {\n                list.add(new Pair(in.nextInt() - 1, in.nextInt() - 1));\n            }\n            \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                        D[i][j] = Math.min(D[i][j], Math.abs(list.get(k).X - i) + Math.abs(list.get(k).Y - j));\n\n            int res = Integer.MIN_VALUE;\n            for (int j = 0; j < N; j++)\n                for (int k = 0; k < M; k++)\n                    if (D[j][k] > res) {\n                        X = j + 1;\n                        Y = k + 1;\n                        res = D[j][k];\n                    }\n\n            out.println(X + \" \" + Y);\n\n        }\n        \n        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        long gcd(long A, long B) {\n            if (B == 0) return A;\n            return gcd(B, A % B);\n        }\n\n        boolean isPrime(long n) {\n            if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))\n                return false;\n            for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)\n                if (n % i == 0)\n                    return false;\n            return true;\n        }\n\n        boolean isEqual(double A, double B) {\n            return Math.abs(A - B) < eps;\n        }\n\n        double dist(double X1, double Y1, double X2, double Y2) {\n            return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));\n        }\n\n        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        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    private static class InputReader {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public InputReader(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public InputReader(FileReader s) throws FileNotFoundException {\n            br = new BufferedReader(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            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public boolean ready() {\n            try {\n                return br.ready();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n\tpublic static void main(String[] args) throws Exception {\n\t\tfinal int fuck = 2001;\n\n\t\tScanner in = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tint n = in.nextInt(), m = in.nextInt();\n\t\tint[] D = new int[ fuck*fuck ], Q = new int[ fuck*(fuck + 1) ],\n\t\t\tdx = new int[] { 1, -1, 0, 0},\n\t\t\tdy = new int[] { 0, 0, -1, 1};\n\t\tArrays.fill(D, -1);\n\t\tint H = -1, T = 0;\n\n\t\tint k = in.nextInt(), ans = 0;\n\t\tfor(int i = 0; i < k; ++i) {\n\t\t\tint x = in.nextInt(), y = in.nextInt();\n\t\t\tD[x * fuck + y] = 0;\n\n\t\t\t++H; H %= Q.length;\n\t\t\tans = Q[H] = x * fuck + y;\n\t\t}\n\t\t\n\t\twhile(H >= T) {\n\t\t\tint idx = Q[T++]; T %= Q.length;\n\t\t\tint x = idx / fuck, y = idx % fuck;\n\t\t\tfor(int i = 0; i < 4; ++i) {\n\t\t\t\tint wtf = (dx[i] + x) * fuck + (dy[i] + y);\n\t\t\t\tif(dx[i] + x <= n && dx[i] + x >= 1 && dy[i] + y <= m && dy[i] + y >= 1 && D[wtf] == -1) {\n\t\t\t\t\tD[wtf] = D[idx] + 1;\n\t\t\t\t\t++H; H %= Q.length;\n\t\t\t\t\tQ[H] = wtf;\n\n\t\t\t\t\tif(D[wtf] >= D[ans])\n\t\t\t\t\t\tans = wtf;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tout.println((ans / fuck) + \" \" + (ans % fuck));\n\t\tout.close();\n\t\tin.close();\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.fill;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.sort;\n\n\npublic class C35 \n{\n\n\tpublic static int mod = 1000000007;\n\tpublic static long INF = (1L << 60);\n\n\tstatic int n,m;\n\tstatic class Pair\n\t{\n\t\tint 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@Override\n\t\tpublic int hashCode() \n\t\t{\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + x;\n\t\t\tresult = prime * result + y;\n\t\t\treturn result;\n\t\t}\n\t\t@Override\n\t\tpublic boolean equals(Object obj) \n\t\t{\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tPair other = (Pair) obj;\n\t\t\tif (x != other.x)\n\t\t\t\treturn false;\n\t\t\tif (y != other.y)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t}\n\tstatic boolean[][] burned;\n\tstatic int[] dx={-1,0,1,0};\n\tstatic int[] dy={0,-1,0,1};\n\tstatic boolean isvalid(int x,int y)\n\t{\n\t\treturn x>=0&&x<n&&y>=0&&y<m;\n\t}\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner in = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\tn=in.nextInt();\n\t\tm=in.nextInt();\n\t\tburned=new boolean[n][m];\n\t\tint k=in.nextInt();\n\t\tSet<Pair> set=new HashSet<Pair>();\n\t\tPair prev=null;\n\t\tfor(int i=0;i<k;i++)\n\t\t{\n\t\t\tint x=in.nextInt();\n\t\t\tint y=in.nextInt();\n\t\t\tburned[x-1][y-1]=true;\n\t\t\tset.add(prev=new Pair(x-1, y-1));\n\t\t}\n\t\twhile(!set.isEmpty())\n\t\t{\n\t\t\tSet<Pair> tempset=new HashSet<>();\n\t\tfor(Pair p : set)\n\t\t{\n\t\t\tint x=p.x;\n\t\t\tint y=p.y;\n\t\t\tprev=p;\n\t\t\tfor(int i=0;i<4;i++)\n\t\t\t{\n\t\t\t\tif(isvalid(x+dx[i], y+dy[i])&&!burned[x+dx[i]][y+dy[i]])\n\t\t\t\t{\n\t\t\t\t\ttempset.add(new Pair(x+dx[i], y+dy[i]));\n\t\t\t\t\tburned[x+dx[i]][y+dy[i]]=true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tset=tempset;\n\t\t}\n\t\tout.printf(\"%d %d\\n\",(prev.x+1),(prev.y+1));\n\t\tout.close();\n\n\t}\n\t\n\tpublic static long pow(long x, long n) \n\t{\n\t\tlong res = 1;\n\t\tfor (long p = x; n > 0; n >>= 1, p = (p * p)) \n\t\t{\n\t\t\tif ((n & 1) != 0) \n\t\t\t{\n\t\t\t\tres = (res * p);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tpublic static long pow(long x, long n, long mod) \n\t{\n\t\tlong res = 1;\n\t\tfor (long p = x; n > 0; n >>= 1, p = (p * p) % mod) \n\t\t{\n\t\t\tif ((n & 1) != 0) \n\t\t\t{\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{\n\t\tlong r;\n\t\twhile (n2 != 0) \n\t\t{\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\tpublic static long lcm(long n1, long n2) \n\t{\n\t\tlong answer = (n1 * n2) / (gcd(n1, n2));\n\t\treturn answer;\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\t\t\n\t\tpublic Scanner(String s) throws FileNotFoundException{\tbr = new BufferedReader(new FileReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "//package c;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tint n,m;\n\tint d[][];\n\tQueue<int[]> q = new LinkedList<int[]>();\n\tint cur[];\n\t\n\tpublic void run() throws Exception{\n\t\tScanner in = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tint k = in.nextInt();\n\t\td = new int[n][m];\n\t\tfor(int i=0;i<n;i++) Arrays.fill(d[i], Integer.MAX_VALUE/2);\n\t\tfor(int i=0;i<k;i++){\n\t\t\tint x = in.nextInt()-1;\n\t\t\tint y = in.nextInt()-1;\n\t\t\td[x][y] = 0;\n\t\t\tq.add(new int[]{x,y});\n\t\t}\n\t\t\n\t\t\n\t\twhile(q.size() > 0){\n\t\t\tcur = q.poll();\n\t\t\tint x = cur[0];\n\t\t\tint y = cur[1];\n\t\t\tadd(x, y+1);\n\t\t\tadd(x+1, y);\n\t\t\tadd(x-1, y);\n\t\t\tadd(x, y-1);\n\t\t}\n\t\tint max = 0;\n\t\tint x = 0;\n\t\tint y = 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 (max < d[i][j]){\n\t\t\t\t\tmax = d[i][j];\n\t\t\t\t\tx = i;\n\t\t\t\t\ty = j;\n\t\t\t\t}\n\t\tout.println((x+1) + \" \" + (y+1));\n\t\tout.close();\n\t}\n\t\n\tprivate void add(int x, int y){\n\t\tif (x < 0 || y < 0) return;\n\t\tif (x >=n || y >=m) return;\n\t\tif (d[x][y] > d[cur[0]][cur[1]] + 1){\n\t\t\td[x][y] = d[cur[0]][cur[1]] + 1;\n\t\t\tq.add(new int[]{x,y});\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n    BufferedReader in;\n    StringTokenizer st;\n    PrintWriter out;\n\n    int n, m, k;\n    int[] x, y;\n\n    char[] qx = new char[4000000], qy = new char[4000000];\n    int b, e;\n\n    char[][] d;\n\n    int[] dx = { -1, 0, 1, 0 }, dy = { 0, -1, 0, 1 };\n\n    void bfs() {\n        b = e = 0;\n        for (int i = 0; i < d.length; i++) {\n            Arrays.fill(d[i], (char)(1 << 14));\n        }\n        for (int i = 0; i < k; ++i) {\n            qx[e] = (char) x[i];\n            qy[e++] = (char) y[i];\n            d[x[i]][y[i]] = 0;\n        }\n        for (; b < e; ++b) {\n            int x = qx[b];\n            int y = qy[b];\n            for (int i = 0; i < 4; ++i) {\n                int nx = x + dx[i];\n                int ny = y + dy[i];\n                if (nx >= 0 && nx < n && ny >= 0 && ny < m)\n                    if (d[nx][ny] > d[x][y] + 1) {\n                        d[nx][ny] = (char) (d[x][y] + 1);\n                        qx[e] = (char) nx;\n                        qy[e++] = (char) ny;\n                    }\n            }\n        }\n    }\n\n    void solve() throws IOException {\n        n = ni();\n        m = ni();\n        k = ni();\n        x = new int[k];\n        y = new int[k];\n        for (int i = 0; i < k; ++i) {\n            x[i] = ni() - 1;\n            y[i] = ni() - 1;\n        }\n        d = new char[n][m];\n        bfs();\n        int x = -1, y = -1, last = -1;\n        for (int i = 0; i < n; ++i)\n            for (int j = 0; j < m; ++j)\n                if (d[i][j] > last) {\n                    last = d[i][j];\n                    x = i;\n                    y = j;\n                }\n        ++x;\n        ++y;\n        out.println(x + \" \" + y);\n    }\n\n    public Solution() throws IOException {\n        Locale.setDefault(Locale.US);\n        in = new BufferedReader(new FileReader(\"input.txt\"));\n        out = new PrintWriter(\"output.txt\");\n        solve();\n        in.close();\n        out.close();\n    }\n\n    String nline() throws IOException {\n        return in.readLine();\n    }\n\n    String ns() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(nline());\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n\npublic class P35C {\n    int n, m;\n    int [][]fire;\n    public P35C() throws FileNotFoundException {\n        Scanner in = new Scanner(new FileReader(\"input.txt\"));\n        n = in.nextInt();\n        m = in.nextInt();\n        int k = in.nextInt();\n        fire = new int[k][2];\n        for (int i = 0; i < k; i++){\n            fire[i][0] = in.nextInt();\n            fire[i][1] = in.nextInt();\n        }\n        in.close();\n        \n        int []last = new int[2];\n        int lastBurn = -1;\n        for (int i = 1; i <= n; i++){\n            for (int j = 1; j <= m; j++){\n                int burn = Integer.MAX_VALUE;\n                for (int l = 0; l < k; l++){\n                    int burnAux = dist(i, j, fire[l][0], fire[l][1]);\n                    burn = Math.min(burn, burnAux);\n                }\n                if(burn >= lastBurn){\n                    lastBurn = burn;\n                    last[0] = i;\n                    last[1] = j;\n                    \n            }\n            }\n        }\n        \n\n        PrintStream out = new java.io.PrintStream( \"output.txt\" );\n        out.print(last[0] + \" \" + last[1]);\n        out.close();\n    }\n    \n     int dist(int x1, int y1, int x2, int y2){\n         return Math.abs(x2 - x1) + Math.abs(y2 - y1);\n     }\n    \n    public static void main (String []args) throws FileNotFoundException{\n        new P35C();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 9/16/11\n * Time: 1:27 PM\n * To change this template use File | Settings | File Templates.\n */\n\n\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.ArrayDeque;\nimport java.util.HashSet;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class TaskC extends Thread {\n    public TaskC() {\n        try {\n            this.input = new BufferedReader(new FileReader(\"input.txt\"));\n            this.output = new PrintWriter(\"output.txt\");\n            this.setPriority(Thread.MAX_PRIORITY);\n        } catch (Throwable e) {\n            System.exit(666);\n        }\n    }\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        Queue<Integer> qX = new ArrayDeque<Integer>();\n        Queue<Integer> qY = new ArrayDeque<Integer>();\n        boolean [][]was = new boolean[n][m];\n        for (int i = 0; i < k; ++i) {\n            int x = nextInt() - 1, y = nextInt() - 1;\n            qX.add(x);\n            qY.add(y);\n            was[x][y] = true;\n        }\n        int lastX = -1, lastY = -1;\n        while (!qX.isEmpty()) {\n            lastX = qX.poll();\n            lastY = qY.poll();\n            for (int i = 0; i < dx.length; ++i) {\n                int nextX = lastX + dx[i], nextY = lastY + dy[i];\n                if (nextX < n && nextY < m && nextX >= 0 && nextY >= 0 && !was[nextX][nextY]) {\n                    qX.add(nextX);\n                    qY.add(nextY);\n                    was[nextX][nextY] = true;\n                }\n            }\n        }\n        ++lastX;\n        ++lastY;\n        output.println(lastX + \" \" + lastY);\n\n\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().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    static final int PRIME = 3119;\n    static final int[]dx = {1, -1, 0, 0}, dy = {0, 0, -1, 1};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        Scanner scn = new Scanner(new File(\"input.txt\"));\n        BufferedWriter out = new BufferedWriter(new FileWriter(\"output.txt\")); \n        \n        int r = scn.nextInt();\n        int c = scn.nextInt();\n        \n        int[][] a = new int[r][c];\n        \n        for(int[] i: a)\n            Arrays.fill(i, 1<<30);\n        \n        int k = scn.nextInt();\n            \n        Queue<State> q = new LinkedList<State>();\n        for(int l = 0; l < k; l++){\n            int i = scn.nextInt()-1;\n            int j = scn.nextInt()-1;\n        \n            a[i][j] = 0;\n            q.add(new State(i, j, 0));\n        }\n        \n        while(!q.isEmpty()){\n            State st = q.poll();\n            \n            a[st.i][st.j] = st.c;\n            \n            for(int d = 0; d < 4; d++){\n                int ii = st.i + di[d];\n                int jj = st.j + dj[d];\n                \n                if(ii < 0 || ii >= r || jj < 0 || jj >= c)continue;\n                if(a[ii][jj] != 1 << 30)continue;\n                \n                a[ii][jj] = st.c+1;\n                q.add(new State(ii, jj, st.c+1));\n            }\n        }\n        \n        int max = 0;\n        for(int i = 0; i < r; i++)\n            for(int j = 0; j < c; j++)\n                max = Math.max(max, a[i][j]);\n        \n        for(int i = 0; i < r; i++)\n            for(int j = 0; j < c; j++)\n                if(a[i][j] == max){\n//                  System.out.println(i+1 + \" \" + (j+1));\n                    out.write((i+1)+\" \"+(j+1));\n                    out.newLine();\n                    \n                    out.close();\n                    \n                    return;\n                }\n        \n    }\n    static int[] di = {0, 0, -1, 1};\n    static int[] dj = {1, -1, 0, 0};\n}\n\nclass State{\n    int i, j, c;\n    public State(int ii, int ji, int ci){\n        i = ii;\n        j = ji;\n        c = ci;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class CF_35C {\n    public static void main(String[] args) throws IOException{\n        BufferedReader f = new BufferedReader(new FileReader(\"input.txt\"));\n        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\n        StringTokenizer st1 = new StringTokenizer(f.readLine());\n        int n = Integer.parseInt(st1.nextToken());\n        int m = Integer.parseInt(st1.nextToken());\n\n        boolean[][] visited = new boolean[n][m];\n\n        int k = Integer.parseInt(f.readLine());\n        LinkedList<state1> ll = new LinkedList<state1>();\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        for(int i = 0; i < k; i++) {\n            int x = Integer.parseInt(st.nextToken());\n            int y = Integer.parseInt(st.nextToken());\n\n            ll.add(new state1(x - 1, y - 1));\n            visited[x - 1][y - 1] = true;\n        }\n\n        int lastx = 1;\n        int lasty = 1;\n        while(!ll.isEmpty()) {\n            state1 focus = ll.remove();\n            lastx = focus.x+1;\n            lasty = focus.y+1;\n\n            //System.out.println(lastx + \" \" + lasty);\n\n            visited[focus.x][focus.y] = true;\n            if(focus.x+1 < n && !visited[focus.x+1][focus.y]) {\n                ll.add(new state1(focus.x+1, focus.y));\n                visited[focus.x+1][focus.y] = true;\n            }\n            if(focus.x-1 >= 0 && !visited[focus.x-1][focus.y]) {\n                ll.add(new state1(focus.x-1, focus.y));\n                visited[focus.x-1][focus.y] = true;\n            }\n            if(focus.y+1 < m && !visited[focus.x][focus.y+1]) {\n                ll.add(new state1(focus.x, focus.y+1));\n                visited[focus.x][focus.y+1] = true;\n            }\n            if(focus.y-1 >= 0 && !visited[focus.x][focus.y-1]) {\n                ll.add(new state1(focus.x, focus.y-1));\n                visited[focus.x][focus.y-1] = true;\n            }\n        }\n        out.println(lastx + \" \" + lasty);\n        out.close();\n    }\n}\n\nclass state1 {\n    int x, y;\n    state1(int x, int y) {\n        this.x = x; this.y = y;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n\npublic class ProblemD {\n\n    static int n;\n    static int m;\n    static boolean[][] fire;\n    \n    public static void main(String[] args) throws FileNotFoundException {\n        Scanner sc = new Scanner(new File(\"input.txt\"));\n        n = sc.nextInt();\n        m = sc.nextInt();\n        int k = sc.nextInt();\n        fire = new boolean[n][m];\n        Queue<Pos> q = new LinkedList<Pos>();\n        for (int i = 0; i < k; i++) {\n            int x = sc.nextInt();\n            int y = sc.nextInt();\n            q.add(new Pos(x - 1, y - 1));\n            fire[x - 1][y - 1] = true;\n        }\n        int[] di = new int[] { 1, -1, 0, 0 };\n        int[] dj = new int[] { 0, 0, 1, -1};\n        Pos last = null;\n        while (q.size() > 0) {\n            Pos pos = q.poll();\n            last = pos;\n            for (int kk = 0; kk < 4; kk++) {\n                int ni = pos.i + di[kk];\n                int nj = pos.j + dj[kk];\n                if (ni >= 0 && nj >= 0 && ni < n && nj < m) {\n                    if (!fire[ni][nj]) {\n                        fire[ni][nj] = true;\n                        q.add(new Pos(ni, nj));\n                    }\n                }\n            }\n        }\n        PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n        out.println((last.i + 1) + \" \" + (last.j + 1));\n        out.flush();\n        out.close();\n    }\n    \n\n}\n\nclass Pos {\n    \n    int i, j;\n\n    public Pos(int i, int j) {\n        super();\n        this.i = i;\n        this.j = j;\n    }\n\n    @Override\n    public int hashCode() {\n        final int prime = 31;\n        int result = 1;\n        result = prime * result + i;\n        result = prime * result + j;\n        return result;\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        if (this == obj)\n            return true;\n        if (obj == null)\n            return false;\n        if (getClass() != obj.getClass())\n            return false;\n        Pos other = (Pos) obj;\n        if (i != other.i)\n            return false;\n        if (j != other.j)\n            return false;\n        return true;\n    }\n    \n    \n};\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.FileOutputStream;\nimport java.util.ArrayDeque;\nimport java.io.PrintWriter;\nimport java.io.FileInputStream;\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;\n\t\ttry {\n\t\t\tinputStream = new FileInputStream(\"input.txt\");\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tOutputStream outputStream;\n\t\ttry {\n\t\t\toutputStream = new FileOutputStream(\"output.txt\");\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tPandaScanner in = new PandaScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tC solver = new C();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass C {\n    final int dx[] = { -1, 0, 1, 0};\n    final int dy[] = { 0, -1, 0, 1};\n    final int SHIFT = 15;\n    final int COLUMN_MASK = (1 << SHIFT) - 1;\n    public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        boolean burning[][] = new boolean[n][m];\n        int k = in.nextInt();\n        ArrayDeque<Integer> q = new ArrayDeque<>();\n        for (int i = 0; i < k; i++) {\n            int x = in.nextInt() - 1;\n            int y = in.nextInt() - 1;\n            burning[x][y] = true;\n            q.add((x << SHIFT) + y);\n        }\n        int last = 0;\n        while (!q.isEmpty()) {\n            last = q.poll();\n            int x = last >> SHIFT;\n            int y = last & COLUMN_MASK;\n            for (int d = 0; d < 4; d++) {\n                int nx = x + dx[d];\n                int ny = y + dy[d];\n                if (nx >= 0 && nx < n && ny >= 0 && ny < m && !burning[nx][ny]) {\n                    burning[nx][ny] = true;\n                    q.add((nx << SHIFT) + ny);\n                }\n            }\n        }\n        out.printf(\"%d %d\\n\", (last >> SHIFT) + 1, (last & COLUMN_MASK) + 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    public int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    }\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": " \nimport java.util.ArrayList;\nimport java.util.Scanner;\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.nio.*;\n public class Main {\n\n\n    public static void main(String[] args) throws NumberFormatException, IOException \n    {\n        Scanner sc = new Scanner(new File(\"input.txt\"));\n        \n        int n = sc.nextInt();\n        int m =sc.nextInt();\n        sc.nextLine();\n        int k =sc.nextInt();\n        int les[][] = new int[n][m];\n        PrintWriter out = new PrintWriter(new FileWriter(\"output.txt\")); \n        //sc.nextLine();\n        ArrayList<Integer[]> list = new ArrayList();\n        sc.nextLine();\n        for(int i = 0;i<k;i++)\n        {\n            \n            Integer[] ii = new Integer[2];\n            ii[0] = sc.nextInt()-1;\n            ii[1] = sc.nextInt()-1;\n            list.add(ii);\n            \n        }\n        sc.close(); \n        int maxr = 0;\n        int maxi = 0;\n        int maxj = 0;\n        for(int i = 0;i<n;i++)\n        {\n            for(int j = 0;j<m;j++)\n            {\n                int minr = 100000;\n                int mini = 0;\n                int minj = 0;\n                for(int f = 0;f<k;f++)\n                {\n                    Integer[] ii = list.get(f);\n                    int ww = Math.abs(ii[0] - i);\n                    int hh = Math.abs(ii[1] - j);\n                    int r = ww+hh;\n                    if(r<minr)\n                    {\n                        minr = r;\n                        mini=i;\n                        minj=j;\n                    }\n                    \n                }\n                if(maxr<minr&&minr<100000)\n                {\n                    maxi = mini;\n                    maxj = minj;\n                    maxr = minr;\n                }\n            }\n        }\n        \n        out.print((maxi+1)+\" \"+(maxj+1));\n        out.close();\n        \n    }\n    \n    \n\n\n    \n    \n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C{\n\tpublic static void main(String args[]) throws Exception{\n\t\tScanner in = new Scanner(new FileReader(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\n\t\tint N = in.nextInt();\n\t\tint M = in.nextInt();\n\t\tint K = in.nextInt();\n\n\t\tint[] X = new int[K], Y = new int[K];\n\t\tfor (int i = 0; i < K; i++){\n\t\t\tX[i] = in.nextInt();\n\t\t\tY[i] = in.nextInt();\n\t\t}\n\n\t\tint d = -1;\n\t\tint a = -1; int b = -1;\n\t\tfor (int i = 1; i <= N; i++)\n\t\t\tfor (int j = 1; j <= M; j++){\n\t\t\t\tint h = Integer.MAX_VALUE;\n\t\t\t\tfor (int p = 0; p < K; p++)\n\t\t\t\t\th = Math.min(h,Math.abs(i-X[p]) + Math.abs(j-Y[p]));\n\t\t\t\tif (h > d){\n\t\t\t\t\td = h; a = i; b = j;\n\t\t\t\t}\n\t\t\t}\n\n\n\t\tout.print(a + \" \" + b);\n\t\tout.close();\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tint height = nextInt();\n\t\tint width = nextInt();\t\t\n\t\tint k = nextInt();\n\t\tint[] r = new int[k];\n\t\tint[] c = new int[k];\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tr[i] = nextInt() - 1;\n\t\t\tc[i] = nextInt() - 1;\t\t\t\n\t\t}\n\t\tint res = 0, R = r[0], C = c[0];\n\t\tfor (int i = 0; i < height; i++)\n\t\t\tfor (int j = 0; j < width; j++) {\n\t\t\t\tint cur = Integer.MAX_VALUE;\n\t\t\t\tfor (int z = 0; z < k; z++)\n\t\t\t\t\tcur = Math.min(cur, Math.abs(i - r[z]) + Math.abs(j - c[z]));\n\t\t\t\tif (res < cur) {\n\t\t\t\t\tres = cur;\n\t\t\t\t\tR = i;\n\t\t\t\t\tC = j;\n\t\t\t\t}\n\t\t\t}\n\t\tout.print((R + 1) + \" \" + (C + 1));\n\t}\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\tst = new StringTokenizer(in.readLine());\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\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\n\n\npublic class C\n{\n   public static void main(String[] args) throws Exception\n   {\n      new C(new Scanner(new File(\"input.txt\")), new PrintWriter(\"output.txt\"));\n   }\n\n   int oo = 987654321;\n   int W, H;\n\n   public C(Scanner in, PrintWriter out)\n   {\n      W = in.nextInt();\n      H = in.nextInt();\n\n      int[][] grid = new int[W][H];\n      for (int[] gri : grid)\n         Arrays.fill(gri, oo);\n   \n      ArrayDeque<Node> q = new ArrayDeque<Node>();\n      int K = in.nextInt();\n      for (int u=0; u<K; u++)\n      {\n         q.add(new Node(in.nextInt()-1, in.nextInt()-1, 0));\n         while (q.size() > 0)\n         {\n            Node cur = q.poll();\n            if (grid[cur.x][cur.y] <= cur.d)\n               continue;\n            grid[cur.x][cur.y] = cur.d;\n            if (cur.x+1<W)\n               q.add(new Node(cur.x+1, cur.y, cur.d+1));\n            if (cur.x>0)\n               q.add(new Node(cur.x-1, cur.y, cur.d+1));\n            if (cur.y+1<H)\n               q.add(new Node(cur.x, cur.y+1, cur.d+1));\n            if (cur.y>0)\n               q.add(new Node(cur.x, cur.y-1, cur.d+1));\n         }\n      }\n\n      int res = 0;\n      for (int j=0; j<H; j++)\n         for (int i=0; i<W; i++)\n            res = Math.max(res, grid[i][j]);\n\n      for (int j=0; j<H; j++)\n         for (int i=0; i<W; i++)\n            if (res == grid[i][j])\n            {\n               out.printf(\"%d %d%n\", i+1, j+1);\n               out.close();\n               return;\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\nimport java.util.Queue;\npublic class Solution{\n    static int[] dx = {1,-1,0,0};\n    static int[] dy = {0,0,1,-1};\n    static Queue<Pair> q ;\n    static boolean[][] visited ;\n    static Pair result = new Pair(0,0);\n    static int n,m,k;\n    public static void main(String[] args){\n        try(BufferedReader in = new BufferedReader(new FileReader(\"input.txt\"));\n                BufferedWriter out = new BufferedWriter(new FileWriter(\"output.txt\")))\n        {\n            StringTokenizer s = new StringTokenizer(in.readLine());\n            n = Integer.parseInt(s.nextToken());\n            m = Integer.parseInt(s.nextToken());\n            k = Integer.parseInt(in.readLine());\n            visited = new boolean[n][m];\n            q = new LinkedList <>();\n            s = new StringTokenizer(in.readLine());\n            for(int i=0;i<k;i++){\n                int x = Integer.parseInt(s.nextToken());\n                int y = Integer.parseInt(s.nextToken());\n                q.add(new Pair(--x,--y));\n            }\n            bfs();\n            String ans = \"\" + (result.x+1) +\" \"+ (result.y+1);\n            out.write(ans);\n        }catch(IOException e){\n\n        }\n    }\n    static void bfs(){\n        while(!q.isEmpty()){\n            Pair temp = q.poll();\n            if(visited[temp.x][temp.y]) continue;\n            visited[temp.x][temp.y] = true;\n            result.x = temp.x;\n            result.y= temp.y;\n            for(int i=0;i<4;i++){\n                int x = temp.x + dx[i];\n                int y = temp.y + dy[i];\n                if(x>=0 && x<n && y>=0 && y<m && !visited[x][y])\n                    q.add(new Pair(x,y));\n            }\n            \n        }\n    }\n    \n}\nclass Pair{\n    int x,y;\n    public Pair(int x,int y){\n        this.x=x;\n        this.y=y;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\t\n\n\tpublic static void main(String[] args) throws IOException{\n\t\t// TODO Auto-generated method stub\n\t\tScanner scan = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\n\t\tint n,m;\n\t\tn = scan.nextInt();\n\t\tm = scan.nextInt();\n\n\t\tboolean visited[][] = new boolean[n][m];\n    \n\t\tint numOfStartingPoints;\n\t\tnumOfStartingPoints = scan.nextInt();\n\t\t    \t\t\n\t\tint resX = 0, resY = 0;\n\t\t\n\t\tQueue<Point> que = new LinkedList<Point>();\n\t\tfor (int i = 0; i < numOfStartingPoints; i++) {\n\t\t\tint x = scan.nextInt() - 1;\n\t\t\tint y = scan.nextInt() - 1;\n\t\t\tque.add(new Point(x, y));\n\t\t\tvisited[x][y] = true;\n\t\t}\n\t\t\n\t\twhile (true) {\n\t\t\tPoint current = que.poll();\n\n\t\t\tif (current == null) {\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tresX = current.x;\n\t\t\t\tresY = current.y;\n\t\t\t\t\n\t\t\t\tif (current.x + 1 < n && !visited[current.x + 1][current.y])\n\t\t\t\t{\n\t\t\t\t\tque.add(new Point(current.x + 1, current.y));\n\t\t\t\t\tvisited[current.x + 1][current.y] = true;\n\n\n\t\t\t\t}\n\t\t\t\tif (current.y + 1 < m && !visited[current.x][current.y + 1])\n\t\t\t\t{\n\t\t\t\t\tque.add(new Point(current.x, current.y + 1));\n\t\t\t\t\tvisited[current.x][current.y + 1] = true;\n\t\t\n\n\t\t\t\t}\n\t\t\t\tif (current.x - 1 >= 0 && !visited[current.x - 1][current.y])\n\t\t\t\t{\n\t\t\t\t\tque.add(new Point(current.x - 1, current.y));\n\t\t\t\t\tvisited[current.x - 1][current.y] = true;\n\t\t\t\t\n\t\t\t\t}\n\t\t\t\tif (current.y - 1 >= 0 && !visited[current.x][current.y - 1])\n\t\t\t\t{\n\t\t\t\t\tque.add(new Point(current.x, current.y - 1));\n\t\t\t\t\tvisited[current.x][current.y - 1] = true;\n\t\t\t\t\n\t\t\t\t}\n\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tout.printf(\"%d %d\\n\", ++resX, ++resY);\n\t\tout.close();\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){\tbr = new BufferedReader(new InputStreamReader(s));}\n\t\t\n\t\tpublic Scanner(String s) throws FileNotFoundException{\tbr = new BufferedReader(new FileReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\n@SuppressWarnings(\"unchecked\")\npublic class P35C {\n\n  final static int SHIFT = 11;\n  final static int MASK = (1 << SHIFT) - 1;\n  final static int [] DX = {-1, 1,  0, 0};\n  final static int [] DY = { 0, 0, -1, 1};\n\n  public void run() throws Exception {\n    int m = nextInt();\n    int n = nextInt();\n\n    boolean [][] burned = new boolean [n][m];\n    List<Integer> burn = new ArrayList();\n    for (int k = nextInt(); k > 0; k--) {\n      int x = nextInt() - 1;\n      int y = nextInt() - 1;\n      burned[y][x] = true;\n      burn.add((x << SHIFT) | y);\n    }\n\n    int lastXY = 0;\n    List<Integer> newBurn = null;\n    do {\n      lastXY = burn.get(0);\n      newBurn = new ArrayList();\n\n      for (int xy : burn) {\n        int x = xy >> SHIFT;\n        int y = xy & MASK;\n\n        for (int i = 0; i < 4; i++) {\n          int nx = x + DX[i];\n          int ny = y + DY[i];\n\n          if ((ny >= 0) && (ny < n) && (nx >= 0) && (nx < m) && (!burned[ny][nx])) {\n            burned[ny][nx] = true;\n            newBurn.add((nx << SHIFT) | ny);\n          }\n        }\n      }\n\n      burn = newBurn;\n    } while (newBurn.size() > 0);\n\n    println(((lastXY >> SHIFT) + 1) + \" \" + ((lastXY & MASK) + 1));\n  }\n\n  public static void main(String... args) throws Exception {\n    br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n    pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(\"output.txt\")));\n    new P35C().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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\n\npublic class Main{\n\tpublic static void main(String[] args)throws FileNotFoundException,IOException{\n\t\tFile file = new File(\"input.txt\");\n\t\tScanner sc = new Scanner(file);\n\t\tFile outFile = new File(\"output.txt\");\n\t\tPrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));\n\n\t\tint w = sc.nextInt();\n\t\tint h = sc.nextInt();\n\t\tboolean[][] map = new boolean[h+1][w+1]; //false:\ufffdu\ufffdG\ufffdv\ufffd\ufffd\ufffd\u0102\u0202\ufffd\n\n\t\tint x = -1, y = -1;\n\t\tQueue<Point> open = new LinkedList<Point>();\n\t\tint k = sc.nextInt();\n\t\tfor(int i=0;i<k;i++){\n\t\t\tint tx = sc.nextInt();\n\t\t\tint ty = sc.nextInt();\n\t\t\tmap[ty][tx] = true;\n\t\t\tx = tx;\n\t\t\ty = ty;\n\t\t\topen.add(new Point(x,y));\n\t\t}\n\n\t\tint dx[] = {1,-1,0,0};\n\t\tint dy[] = {0,0,1,-1};\n\t\twhile(!open.isEmpty()){\n\t\t\tPoint p = open.poll();\n\n\t\t\tfor(int i=0;i<4;i++){\n\t\t\t\tint nx = p.x + dx[i];\n\t\t\t\tint ny = p.y + dy[i];\n\n\t\t\t\tif(nx>0 && nx<=w && ny>0 && ny<=h && !map[ny][nx]){\n\t\t\t\t\tmap[ny][nx] = true;\n\t\t\t\t\tx = nx;\n\t\t\t\t\ty = ny;\n\t\t\t\t\topen.add(new Point(nx,ny));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpw.println(x + \" \" + y);\n\n\t\tpw.close();\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\n@SuppressWarnings(\"unchecked\")\npublic class P35C {\n\n  final static int [] DX = {-1, 1,  0, 0};\n  final static int [] DY = { 0, 0, -1, 1};\n\n  public void run() throws Exception {\n    int m = nextInt();\n    int n = nextInt();\n\n    boolean [][] burned = new boolean [n][m];\n    List<Integer> burn = new ArrayList();\n    for (int k = nextInt(); k > 0; k--) {\n      int x = nextInt() - 1;\n      int y = nextInt() - 1;\n      burned[y][x] = true;\n      burn.add(x * 10000 + y);\n    }\n\n    int lastXY = 0;\n    List<Integer> newBurn = null;\n    do {\n      lastXY = burn.get(0);\n      newBurn = new ArrayList();\n\n      for (int xy : burn) {\n        int x = xy / 10000;\n        int y = xy % 10000;\n\n        for (int i = 0; i < 4; i++) {\n          int nx = x + DX[i];\n          int ny = y + DY[i];\n\n          if ((ny >= 0) && (ny < n) && (nx >= 0) && (nx < m) && (!burned[ny][nx])) {\n            burned[ny][nx] = true;\n            newBurn.add(nx * 10000 + ny);\n          }\n        }\n      }\n\n      burn = newBurn;\n    } while (newBurn.size() > 0);\n\n    println((lastXY / 10000 + 1) + \" \" + (lastXY % 10000 + 1));\n  }\n\n  public static void main(String... args) throws Exception {\n    br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n    pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(\"output.txt\")));\n    new P35C().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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.PrintStream;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class FireAgain {\n\n\tPoint coordinate;\n\tQueue<Point> q = new LinkedList<Point>();\n\tint m, n;\n\tboolean[][] arr;\n\tPrintStream out ;\n\n\tvoid bfs(Point start) {\n\n\t\twhile (!q.isEmpty()) {\n\t\t\tPoint front = q.poll();\n\t\t\tPoint p = new Point();\n\n\t\t\tp.x = front.x - 1;\n\t\t\tp.y = front.y;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1) {\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tp = new Point();\n\t\t\tp.x = front.x + 1;\n\t\t\tp.y = front.y;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\n\t\t\tp = new Point() ;\n\t\t\tp.x = front.x;\n\t\t\tp.y = front.y + 1;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\n\t\t\tp = new Point() ;\n\t\t\tp.x = front.x;\n\t\t\tp.y = front.y - 1;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\n\t\t\tif (q.size() == 0)\n\t\t\t\tout.print(front.x + \" \" + front.y);\n\t\t}\n\t}\n\n\t/**\n\t * @param args\n\t * @throws FileNotFoundException \n\t */\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// TODO Auto-generated method stub\n\t\tFireAgain fa = new FireAgain();\n\t\tScanner Scan = new Scanner(new FileInputStream(\"input.txt\"));\n\t\tfa.out = new PrintStream(new File(\"output.txt\"));\n\t\tfa.n = Scan.nextInt();\n\t\tfa.m = Scan.nextInt();\n\t\tint k = Scan.nextInt();\n\t\tfa.arr = new boolean[2001][2001];\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tfa.coordinate = new Point();\n\t\t\tfa.coordinate.x = Scan.nextInt();\n\t\t\tfa.coordinate.y = Scan.nextInt();\n\t\t\tfa.q.add(fa.coordinate);\n\t\t\tfa.arr[fa.coordinate.x][fa.coordinate.y] = true;\n\t\t}\n\n\t\tfa.bfs(fa.q.peek());\n\n\t}\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n\tpublic static void main(String[] args) throws Exception {\n\t\tfinal int fuck = 2001;\n\n\t\tScanner in = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\n\t\tint n = in.nextInt(), m = in.nextInt();\n\t\tint[] D = new int[ fuck*fuck ],\n\t\t\tdx = new int[] { 1, -1, 0, 0},\n\t\t\tdy = new int[] { 0, 0, -1, 1};\n\t\tArrays.fill(D, -1);\n\n\t\tArrayDeque<Integer> Q = new ArrayDeque<>();\n\t\tint k = in.nextInt(), ans = 0;\n\t\tfor(int i = 0; i < k; ++i) {\n\t\t\tint x = in.nextInt(), y = in.nextInt();\n\t\t\tD[ans = (x * fuck + y)] = 0;\n\t\t\tQ.offer(ans);\n\t\t}\n\t\t\n\t\twhile(!Q.isEmpty()) {\n\t\t\tint idx = Q.poll();\n\t\t\tint x = idx / fuck, y = idx % fuck;\n\t\t\tfor(int i = 0; i < 4; ++i) {\n\t\t\t\tint wtf = (dx[i] + x) * fuck + (dy[i] + y);\n\t\t\t\tif(dx[i] + x <= n && dx[i] + x >= 1 && dy[i] + y <= m && dy[i] + y >= 1 && D[wtf] == -1) {\n\t\t\t\t\tD[wtf] = D[idx] + 1;\n\t\t\t\t\tQ.offer(wtf);\n\n\t\t\t\t\tif(D[wtf] >= D[ans])\n\t\t\t\t\t\tans = wtf;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tout.println((ans / fuck) + \" \" + (ans % fuck));\n\t\tout.close();\n\t\tin.close();\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// TODO Auto-generated method stub\n\t\tScanner read = new Scanner(new FileInputStream(new File(\"input.txt\")));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tint n = read.nextInt(), m = read.nextInt(), k = read.nextInt(), tree[][] = new int[n][m], a[] = new int[k],\n\t\t\t\tb[] = new int[k], x = 0, y = 0, max = -1, d = 0;\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\ta[i] = read.nextInt() - 1;\n\t\t\tb[i] = read.nextInt() - 1;\t\n\t\t\ttree[a[i]][b[i]] = 0;\n\t\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tArrays.fill(tree[i], Integer.MAX_VALUE);\n\t\t}\n\t\tfor (int o = 0; o < k; o++) {\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\td = Math.abs(a[o] - i) + Math.abs(b[o] - j);\n\t\t\t\t\tif(d < tree[i][j])\n\t\t\t\t\t\ttree[i][j] = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i<n; i++){\n\t\t\tfor(int j = 0; j < m ; j ++){\n\t\t\t\tif(tree[i][j] > max){\n\t\t\t\t\tmax=  tree[i][j];\n\t\t\t\t\tx=  i;\n\t\t\t\t\ty = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(x + 1 + \" \" + (y + 1));\n\t\tout.close();\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedWriter;\nimport java.io.ByteArrayInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.Queue;\n\n\n\n@SuppressWarnings(\"unused\")\npublic class Fire35C {\n\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\n\tint mod = (int)(Math.pow(10,9)+7);\n\tint v = 0;\n\tint max = 0;\n\tStringBuilder st = new StringBuilder();\n\tFile outFile = new File(\"output.txt\");\n\tvoid solve() throws IOException\n\t{\t\n\n\t\tint n = ni();\n\t\tint m = ni();\n\n\t\tboolean visited[][] = new boolean[n][m];\n\t\tboolean inq[][] = new boolean[n][m];\n\t\tQueue<Integer> x = new LinkedList<>();\n\t\tQueue<Integer> y = new LinkedList<>();\n\t\tQueue<Integer> lev = new LinkedList<>();\n\n\t\tint a = -1 , b = -1 , max = 0;\n\n\t\tint k = ni();\n\t\twhile(k-- > 0) {\n\t\t\tint u = ni()-1;\n\t\t\tint v = ni()-1;\n\t\t\tx.add(u);\n\t\t\ty.add(v);\n\t\t\tlev.add(1);\n\t\t\tinq[u][v] = true;\t\n\t\t}\n\n\t\twhile(x.size() != 0) {\n\n\t\t\tint u = x.poll();\n\t\t\tint v = y.poll();\n\t\t\tint l = lev.poll();\n\t\t\tif(max < l) {\n\t\t\t\ta = u;\n\t\t\t\tb = v;\n\t\t\t\tmax = l;\n\t\t\t}\n\t\t\tvisited[u][v] = true;\n\t\t\tif(u-1 >= 0 && !visited[u-1][v] && !inq[u-1][v]) {\n\t\t\t\tx.add(u-1);\n\t\t\t\ty.add(v);\n\t\t\t\tlev.add(l+1);\n\t\t\t\tinq[u-1][v] = true;\n\t\t\t}\n\n\t\t\tif(u+1 < n && !visited[u+1][v] && !inq[u+1][v]) {\n\t\t\t\tx.add(u+1);\n\t\t\t\ty.add(v);\n\t\t\t\tlev.add(l+1);\n\t\t\t\tinq[u+1][v] = true;\n\t\t\t}\n\n\t\t\tif(v-1 >= 0 && !visited[u][v-1] && !inq[u][v-1]) {\n\t\t\t\tx.add(u);\n\t\t\t\ty.add(v-1);\n\t\t\t\tlev.add(l+1);\n\t\t\t\tinq[u][v-1] = true;\n\t\t\t}\n\n\t\t\tif(v+1 < m && !visited[u][v+1] && !inq[u][v+1]) {\n\t\t\t\tx.add(u);\n\t\t\t\ty.add(v+1);\n\t\t\t\tlev.add(l+1);\n\t\t\t\tinq[u][v+1] = true;\n\t\t\t}\n\t\t\t\n\n\t\t}\n\t\ta++;\n\t\tb++;\n\n\t\tout.println(a+\" \"+b);\n\t\tout.close();\n\t}\n\n\n\tvoid run() throws Exception\n\t{\n\t\tis = INPUT.isEmpty() ? new FileInputStream(new File(\"input.txt\")) : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception { new Fire35C().run(); }\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)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\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\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b) && 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\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\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 int[][] na(int n , int m)\n\t{\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++) a[i][j] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl()\n\t{\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\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\tvoid display2D(int a[][]) {\n\t\tfor(int i[] : a) {\n\t\t\tfor(int j : i) {\n\t\t\t\tout.print(j+\" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n\n\tint[][] creategraph(int n , int m) {\n\t\tint g[][] = new int[n+1][];\n\n\t\tint from[] = new int[m];\n\t\tint to[] = new int[m];\n\t\tint ct[] = new int[n+1];\n\n\t\tfor(int i = 0 ; i<m; i++) {\n\t\t\tfrom[i] = ni();\n\t\t\tto[i] = ni();\n\t\t\tct[from[i]]++;\n\t\t\tct[to[i]]++;\n\t\t}\n\n\t\tint parent[] = new int[n+1];\n\n\t\tfor(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];\n\n\t\tfor(int i = 0 ; i<m ; i++) {\n\t\t\tg[from[i]][--ct[from[i]]] = to[i];\n\t\t\tg[to[i]][--ct[to[i]]] = from[i];\n\t\t}\n\n\t\treturn g;\n\t}\n\n\tstatic long __gcd(long a, long b)\n\t{\n\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\t// To compute x^y under modulo m\n\tstatic long power(long x, long y, long p)\n\t{\n\n\t\t// Initialize result\n\t\tlong res = 1;\n\n\t\t// Update x if it is more than or\n\t\t// equal to p\n\t\tx = x % p;\n\n\t\twhile (y > 0)\n\t\t{\n\n\t\t\t// If y is odd, multiply x\n\t\t\t// with result\n\t\t\tif (y % 2 == 1)\n\t\t\t\tres = (res * x) % p;\n\n\t\t\t// y must be even now\n\t\t\ty = y >> 1; // y = y/2\n\t\tx = (x * x) % p;\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t// Function to find modular \n\t// inverse of a under modulo m\n\t// Assumption: m is prime\n\tstatic long modInverse(long a, int m)\n\t{\n\t\tif (__gcd(a, m) != 1) {\n\t\t\t//System.out.print(\"Inverse doesn't exist\");\n\t\t\treturn -1;\n\t\t}\n\n\t\telse {\n\n\t\t\t// If a and m are relatively prime, then\n\t\t\t// modulo inverse is a^(m-2) mode m\n\t\t\t//\t\t\tSystem.out.println(\"Modular multiplicative inverse is \"\n\t\t\t//\t\t\t\t\t\t\t\t\t\t\t+power(a, m - 2, m));\n\t\t\treturn power(a, m - 2, m);\n\t\t}\n\t}\n\n\tstatic long nCrModPFermat(int n, int r,\n\t\t\tint p , long fac[])\n\t{\n\n\t\t// Base case\n\t\tif (r == 0)\n\t\t\treturn 1;\n\n\t\t// Fill factorial array so that we\n\t\t// can find all factorial of r, n\n\t\t// and n-r\n\t\tlong t = (fac[n]* modInverse(fac[r], p))%p;\n\n\t\treturn ( (t* modInverse(fac[n-r], p))% p);\n\t}\n\n\n\tprivate static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }\n}\n\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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.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;\n        try\n        {\n            inputStream = new FileInputStream(\"input.txt\");\n        } catch (IOException e)\n        {\n            throw new RuntimeException(e);\n        }\n        OutputStream outputStream;\n        try\n        {\n            outputStream = new FileOutputStream(\"output.txt\");\n        } catch (IOException e)\n        {\n            throw new RuntimeException(e);\n        }\n        FastScanner in = new FastScanner(inputStream);\n        FastPrinter out = new FastPrinter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC\n    {\n        private final static int[] dx = {-1, 0, +1, 0};\n        private final static int[] dy = {0, +1, 0, -1};\n        private final static int WHITE = 123456789;\n\n        public void solve(int testNumber, FastScanner in, FastPrinter out)\n        {\n            int n = in.nextInt();\n            int m = in.nextInt();\n\n            int[][] map = new int[n][m];\n            for (int i = 0; i < n; i++)\n            {\n                Arrays.fill(map[i], WHITE);\n            }\n\n            int k = in.nextInt();\n\n            int qh = 0;\n            int qt = 0;\n            int[] q = new int[((int) 7e6)];\n            for (int i = 0; i < k; i++)\n            {\n                int x = in.nextInt() - 1;\n                int y = in.nextInt() - 1;\n                map[x][y] = 0;\n                q[qh++] = x * m + y;\n            }\n\n            int d = 0;\n            int X = q[0] / m;\n            int Y = q[0] % m;\n            while (qt < qh)\n            {\n                int pos = q[qt++];\n                int x = pos / m;\n                int y = pos % m;\n                for (int i = 0; i < 4; i++)\n                {\n                    int xx = x + dx[i];\n                    int yy = y + dy[i];\n                    if (isValid(xx, n) && isValid(yy, m) && map[xx][yy] == WHITE)\n                    {\n                        map[xx][yy] = map[x][y] + 1;\n                        q[qh++] = (xx * m) + yy;\n                        if (d < map[xx][yy])\n                        {\n                            d = map[xx][yy];\n                            X = xx;\n                            Y = yy;\n                        }\n                    }\n                }\n            }\n//        for (int i = 0; i < n; i++)\n//        {\n//            for (int j = 0; j < m; j++)\n//            {\n//                out.print(map[i][j] + \" \");\n//            }\n//            out.println();\n//        }\n            out.println((X + 1) + \" \" + (Y + 1));\n        }\n\n        private boolean isValid(int x, int X)\n        {\n            return x >= 0 && x < X;\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n    static boolean used[][];\n    static int n;\n    static int m;\n\n    public static void main(String[] args) throws IOException {\n        br = new BufferedReader(new FileReader(\"input.txt\"));\n        PrintWriter out = new PrintWriter(\"output.txt\");\n        n = nextInt();\n        m = nextInt();\n        int k = nextInt();\n        used = new boolean[n][m];\n        Deque<point> deq = new ArrayDeque<>();\n        for (int i = 0; i < k; i++) {\n            deq.addLast(new point(nextInt() - 1, nextInt() - 1));\n            used[deq.peekLast().x][deq.peekLast().y] = true;\n        }\n        point last = new point(0, 0);\n        while (!deq.isEmpty()) {\n            point v = deq.pollFirst();\n            int x = v.x;\n            int y = v.y;\n            if (checker(x, y + 1)) {\n                last = new point(x, y + 1);\n                deq.addLast(new point(x, y + 1));\n                used[x][y + 1] = true;\n            }\n            if (checker(x, y - 1)) {\n                last = new point(x, y - 1);\n                deq.addLast(new point(x, y - 1));\n                used[x][y - 1] = true;\n            }\n            if (checker(x + 1, y)) {\n                last = new point(x + 1, y);\n                deq.addLast(new point(x + 1, y));\n                used[x + 1][y] = true;\n            }\n            if (checker(x - 1, y)) {\n                last = new point(x - 1, y);\n                deq.addLast(new point(x - 1, y));\n                used[x - 1][y] = true;\n            }\n        }\n        out.println(last.x + 1 + \" \" + (last.y + 1));\n        out.close();\n    }\n\n    static boolean checker(int x, int y) {\n        if (x < n && y < m && x >= 0 && y >= 0 && !used[x][y]) return true;\n        return false;\n    }\n\n\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static BufferedReader br;\n\n    static String next() throws IOException {\n        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\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\nclass point {\n    int x, y;\n\n    public point(int x, int y) {\n        this.x = x;\n        this.y = y;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Double.parseDouble;\nimport static java.lang.String.*;\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n\n        BufferedReader in = new BufferedReader//(new InputStreamReader(System.in));\n                                            (new FileReader(\"input.txt\"));\n        StringBuilder out = new StringBuilder();\n        StringTokenizer tk;\n        PrintWriter pw = new PrintWriter(\"output.txt\", \"UTF-8\");\n        \n        int [] dx = {-1,1,0,0},dy = {0,0,-1,1};\n        \n        tk = new StringTokenizer(in.readLine());\n        int n = parseInt(tk.nextToken()),m = parseInt(tk.nextToken());\n        int k = parseInt(in.readLine());\n        \n        int [][] dist = new int[n][m];\n        for(int i=0; i<n; i++) \n            Arrays.fill(dist[i], -1);\n        \n        int ans = -1,atx = -1,aty = -1;\n        \n        Queue<point> q = new LinkedList<point>();\n        \n        tk = new StringTokenizer(in.readLine());\n        while(k-- > 0) {\n            int x = parseInt(tk.nextToken())-1,y = parseInt(tk.nextToken())-1;\n            \n            dist[x][y] = 0;\n            q.add(new point(x,y));\n        }\n        \n        while(!q.isEmpty()) {\n            point p = q.remove();\n            \n            if(dist[p.x][p.y]>ans) {\n                ans = dist[p.x][p.y];\n                atx = p.x+1;\n                aty = p.y+1;\n            }\n            \n            for(int i=0; i<4; i++) {\n                int nx = p.x + dx[i];\n                int ny = p.y + dy[i];\n                \n                if(nx>=0 && nx<n && ny>=0 && ny<m && dist[nx][ny]==-1) {\n                    dist[nx][ny] = dist[p.x][p.y] + 1;\n                    q.add(new point(nx,ny));\n                }\n            }\n        }\n        \n        pw.println(atx+\" \"+aty);\n        pw.close();\n    }\n   \n}\n\nclass point {\n    int x,y;\n    \n    public point(int x,int y) {\n        this.x = x;\n        this.y = y;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class practice {\n\n\t\tpublic static void main(String[] args) throws FileNotFoundException {\t\t\t\n\t\t\tScanner scn = new Scanner(new FileReader(\"input.txt\"));\n\t\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\t int n=scn.nextInt(),m=scn.nextInt(),k=scn.nextInt();\n\t\t int[][] inf=new int[k][2];\n\t\t for(int i=0;i<k;i++){\n\t\t\t inf[i][0]=scn.nextInt();inf[i][1]=scn.nextInt();\n\t\t }\n\t\t int ans=0,x=1,y=1;\n\t\t for(int i=1;i<=n;i++){\n\t\t\t for(int j=1;j<=m;j++){\n\t\t\t\t int temp=Integer.MAX_VALUE;\n\t\t\t\t for(int l=0;l<k;l++){\n\t\t\t\t\ttemp=Math.min(temp, Math.abs(i-inf[l][0])+Math.abs(j-inf[l][1])); \n\t\t\t\t }\n\t\t\t\t if(temp>ans){\n\t\t\t\t\t ans=temp;x=i;y=j;\n\t\t\t\t }\n\t\t\t }\n\t\t }\n\t\t out.print(x+ \" \" + y);\n\t   \t out.close();\n\t\t}\n\t}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// TODO Auto-generated method stub\n\t\tScanner read = new Scanner(new FileInputStream(new File(\"input.txt\")));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tint n = read.nextInt(), m = read.nextInt(), k = read.nextInt(), tree[][] = new int[n][m], a[] = new int[k],\n\t\t\t\tb[] = new int[k], x = 0, y = 0, max = -1, d = 0;\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\ta[i] = read.nextInt() - 1;\n\t\t\tb[i] = read.nextInt() - 1;\t\n\t\t\ttree[a[i]][b[i]] = 0;\n\t\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tArrays.fill(tree[i], Integer.MAX_VALUE);\n\t\t}\n\t\tfor (int o = 0; o < k; o++) {\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\td = Math.abs(a[o] - i) + Math.abs(b[o] - j);\n\t\t\t\t\tif(d < tree[i][j])\n\t\t\t\t\t\ttree[i][j] = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i<n; i++){\n\t\t\tfor(int j = 0; j < m ; j ++){\n\t\t\t\tif(tree[i][j] > max){\n\t\t\t\t\tmax=  tree[i][j];\n\t\t\t\t\tx=  i;\n\t\t\t\t\ty = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(x + 1 + \" \" + (y + 1));\n\t\tout.close();\n\t}\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n    public static void main(String[] args) throws IOException\n    {\n        PrintWriter pw = new PrintWriter(new FileWriter(\"output.txt\"));\n        Scanner in=new Scanner(new File(\"input.txt\"));\n        int n,m,k;\n        n=in.nextInt();\n        m=in.nextInt();\n        k=in.nextInt();\n        Vector<Integer> vec=new Vector<Integer>();\n        Vector<Integer> temp=new Vector<Integer>();\n        boolean[][] mas=new boolean[n][m];\n        long time=System.currentTimeMillis();\n        for(int i=0;i<k;i++)\n        {\n            vec.add(in.nextInt()-1);\n            vec.add(in.nextInt()-1);\n            mas[vec.get(vec.size()-2)][vec.get(vec.size()-1)]=true;\n        }\n        int x,y;\n        x=y=0;\n        while(vec.size()!=0)\n        {\n            for(int i=0;i<vec.size();i+=2)\n            {\n                x=vec.get(i);\n                y=vec.get(i+1);\n                if(x>0 && !mas[x-1][y])\n                {\n                    temp.add(x-1);\n                    temp.add(y);\n                    mas[x-1][y]=true;\n                }\n                if(x<n-1 && !mas[x+1][y])\n                {\n                    temp.add(x+1);\n                    temp.add(y);\n                    mas[x+1][y]=true;\n                }\n                if(y>0 && !mas[x][y-1])\n                {\n                    temp.add(x);\n                    temp.add(y-1);\n                    mas[x][y-1]=true;\n                }\n                if(y<m-1 && !mas[x][y+1])\n                {\n                    temp.add(x);\n                    temp.add(y+1);\n                    mas[x][y+1]=true;\n                }\n            }\n            vec=temp;\n            temp=new Vector<Integer>();\n        }\n        pw.println((x+1)+\" \"+(y+1));\n        System.out.println(System.currentTimeMillis()-time);\n        in.close();\n        pw.close();\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.util.*;\nimport java.util.Queue;\n\npublic class A {\n\n    static int[] dx = {-1, 0, 1, 0};\n    static int[] dy = {0, 1, 0, -1};\n\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(\"input.txt\");\n        PrintWriter out = new PrintWriter(\"output.txt\");\n        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();\n        int[][] dist = new int[n][m];\n        for(int[] a : dist) Arrays.fill(a, -1);\n        Queue<Point> q = new LinkedList<>();\n        for(int i = 0; i < k; i++)\n        {\n            int x = sc.nextInt() - 1, y = sc.nextInt() - 1;\n            dist[x][y] = 0;\n            q.add(new Point(x, y));\n        }\n        int ansX = -1, ansY = -1;\n        while(!q.isEmpty())\n        {\n            Point cur = q.remove();\n            ansX = cur.x; ansY = cur.y;\n            for(int i = 0; i < 4; i++)\n            {\n                int x = cur.x + dx[i], y = cur.y + dy[i];\n                if(x != -1 && y != -1 && x != n && y != m && dist[x][y] == -1)\n                {\n                    q.add(new Point(x, y));\n                    dist[x][y] = dist[cur.x][cur.y] + 1;\n                }\n            }\n        }\n        out.println((ansX + 1) + \" \" + (ansY + 1));\n        out.flush();\n        out.close();\n    }\n    static class Scanner\n    {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}\n        public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}\n        public String next() throws IOException\n        {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        public String nextLine()throws IOException{return br.readLine();}\n        public int nextInt() throws IOException {return Integer.parseInt(next());}\n        public double nextDouble() throws IOException {return Double.parseDouble(next());}\n        public char nextChar()throws IOException{return next().charAt(0);}\n        public Long nextLong()throws IOException{return Long.parseLong(next());}\n        public boolean ready() throws IOException{return br.ready();}\n        public void waitForInput() throws InterruptedException {Thread.sleep(4000);}\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.io.IOException;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.TreeSet;\n\npublic class ViewAngle{\n\t\t        \tprivate static int V,level[][],count=-1,lev_dfs[],degree=0,no_vert_conn_comp=0;\n\t\t        \tprivate static Stack <Integer>st=new Stack();\n\t\t        \tprivate static LinkedList<Integer > adj[];\n\t\t        \tprivate static boolean[][] Visite;\n\t\t        \tprivate static boolean [] Visited;\n\t\t        \tprivate static TreeSet<Integer> ts=new TreeSet();\n\t\t        //\tprivate static HashMap\n\t\t        \tprivate static Queue<Pair> queue = new LinkedList<Pair>();\n\t\t        \tViewAngle(int V){\n\t\t    V++;\n\t\t    this.V=(V);\n\t\t    adj=new LinkedList[V];\n\t\t    Visite=new boolean[100][100];\n\t\n\t \t   Visited=new boolean[V];\n\t\t   \n\t\t   lev_dfs=new int[V]; \n\t\t   for(int i=0;i<V;i++)\n\t\t\t   adj[i]=new LinkedList<Integer>();\n\t\t    }\n\t\t        \tstatic File inFile,outFile;\n\t\t        \tstatic FileWriter fWriter;\n\t\t        \tstatic PrintWriter pWriter;\n\t\t        \tpublic static void main(String[] args) throws IOException {\n\t\t    \t\n\t\t    \t inFile=new File(\"input.txt\");\n\t\t    \t outFile = new File (\"output.txt\");\n\t\t\t     fWriter = new FileWriter (outFile);\n\t\t\t    pWriter = new PrintWriter (fWriter);\n\t\t\t  Scanner sc = new Scanner (inFile);\n\t\t\t  int n=sc.nextInt();\n\t\t\t  int m=sc.nextInt();\n\t\t\t  char c[][]=new char[n][m];\n\t\t\t  for(int i=0;i<n;i++){\n\t\t\t\t  for(int j=0;j<m;j++){\n\t\t\t\t\t  c[i][j]='.';\n\t\t\t\t  }\n\t\t\t  }\n\t\t\t  setup(n, m);\n\t\t\t  int k=sc.nextInt();\n\t\t\t  for(int i=0;i<k;i++){\n\t\t\t\t  int x=sc.nextInt();\n\t\t\t\t  int y=sc.nextInt();\n\t\t\t\t  queue.add(new Pair(x-1, y-1));\n\t\t\t\t  c[x-1][y-1]='X';\n\t\t\t level[x-1][y-1]=-1;\n\t\t\t Visite[x-1][y-1]=true;\n\t\t\t  }\n\t\t\tBFS(c, n, m);\n\t\t    \tpWriter.close();\n\t\t    \tsc.close();\n\t\t    }\n\t\t   static  void addEdge(int v,int w){\n\t\t    \t\n\t\t    \tif(adj[v]==null){\n\t\t    \t\tadj[v]=new LinkedList();\n\t\t    \t}\n\t\t    \tadj[v].add(w);\n\t\t     \n\t\t    \t\n\t\t    }\n\t\t \n\t\t    public static int BFS2(int startVert,int dest){\n\t\t    \tVisited=new boolean[V];\n\t\t    \tfor(int i=1;i<V;i++){\n\t\t    \t\tlev_dfs[i]=-1;\n\t\t    \t}\n\t\t    \tQueue<Integer> q=new LinkedList<Integer>();\n\t\t    \tq.add(startVert);\n\t\t    \t\n\t\t    \tlev_dfs[startVert]=0;\n\t\t    \twhile(!q.isEmpty()){\n\t\t    \t\tint top=q.poll();\n\t\t    \t\t\n\t\t    \t\tIterator<Integer> i= adj[top].listIterator();\n\t\t    \t\twhile(i.hasNext()){\n\t\t    \t\t\tint n=i.next();\n\t\t    \t\t\tif(!Visited[n]){\n\t\t    \t\t\t\tq.add(n);\n\t\t    \t\t\t\tVisited[n]=true;\n\t\t    \t\t\t\tlev_dfs[n]=lev_dfs[top]+1;\n\t\t    \t\t\tif(n==dest){\n\t\t    \t\t\t\tq.clear();\n\t\t    \t\t\t\treturn lev_dfs[n];\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    \tq.clear();\n\t\t    \treturn -1;\n\t\t    }\n\t\t    public int getEd(){\n\t\t    \treturn degree/2;\n\t\t    }\n\t\t    public void get(int from,int to){\n\t\t    \tint h=lev_dfs[from]-lev_dfs[to];\n\t\t    \tif(h<=0){\n\t\t    \t\tSystem.out.println(-1);\n\t\t    \t}else{\n\t\t    \t\tSystem.out.println(h-1);\n\t\t    \t}\n\t\t    }\n\t\t    public static void setup(int n,int m){\n\n\t\t    \t level=new int[n][m];\n\t\t    \tVisite=new boolean[n][m];\t\n\t\t    }\n\t\t    private static boolean check(int x,int y,char c[][]){\n\t\t\t\n\t\t\t\tif((x>=0 && y>=0) && (x<c.length && y<c[0].length) && c[x][y]=='.'){\n\t\t\t\t\t\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t    public static int BFS(char[][] c,int n,int m)\n\t\t    {\n\t\t        //Visited[s]=true;\n\t\t   //     queue.add(new Pair(x,y));\n\t\t       int count=0;\n\t\t //  level[x][y]=-1;\n\t\t        while (!queue.isEmpty())\n\t\t        {\n\t\t        \t\n\t\t            Pair temp = queue.poll();\n\t\t           int  x=temp.w;\n\t\t            int y=temp.h;\n\t\t            Visite[x][y]=true;\n\t\t            if(check(x+1,y,c) && !Visite[x+1][y]){\n\t\t            \tlevel[x+1][y]=level[x][y]+1;\n\t\t            \tqueue.add(new Pair(x+1, y));\n\t\t            Visite[x+1][y]=true;\n\t\t            }\n\t\t            if(check(x-1,y,c) && !Visite[x-1][y]){\n\t\t            \tlevel[x-1][y]=level[x][y]+1;\n\t\t            \tqueue.add(new Pair(x-1, y));\n\t\t            \tVisite[x-1][y]=true;\n\t\t            }\n\t\t            if(check(x,y+1,c) && !Visite[x][y+1]){\n\t\t            \tlevel[x][y+1]=level[x][y]+1;\n\t\t            \tqueue.add(new Pair(x, y+1));\n\t\t            \tVisite[x][y+1]=true;\n\t\t            }\n\t\t            if(check(x,y-1,c) && !Visite[x][y-1]){\n\t\t            \tlevel[x][y-1]=level[x][y]+1;\n\t\t            \tqueue.add(new Pair(x, y-1));\n\t\t            \tVisite[x][y-1]=true;\n\t\t            }\n\t\t          \n\t\t            \n\t\t        }\n\t\t        int prev_lev=-1,x=-1,y=-1;\n\t\t        for(int i=0;i<n;i++){\n\t\t        \tfor(int j=0;j<m;j++){\n\t\t        \t\tif(level[i][j]>=prev_lev){\n\t\t        \t\t\tprev_lev=level[i][j];\n\t\t        \t\t\tx=i;y=j;\n\t\t        \t\t}\n\t\t        \t\t//System.out.println(level[i][j]+\" \");\n\t\t        \t}\n\t\t        \t//System.out.println();\n\t\t        }\n\t\t        \n\t\t        pWriter.println((x+1)+\" \"+(y+1));\n\t\t        return V;\n\t\t    }\n\t\t    \n\t\t    private void getAns(int startVertex){\n\t\t    \tfor(int i=0;i<adj[startVertex].size();i++){\n\t\t    \t\tint ch=adj[startVertex].get(i);\n\t\t    \t\tfor(int j=0;j<adj[ch].size();j++){\n\t\t    \t\t\tint ch2=adj[ch].get(j);\n\t\t    \t\t\tif(adj[ch2].contains(startVertex)){\n\t\t    \t\t\t\tSystem.out.println(startVertex+\" \"+ch+\" \"+ch2);\n\t\t    \t\t\t\tSystem.exit(0);\n\t\t    \t\t\t}\n\t\t    \t\t}\n\t\t    \t}\n\t\t    }\n\t\t    \n\t\t     public long dfs(int startVertex){\n\t\t    //\t getAns(startVertex);\n\t\t    \t \n\t\t    \t if(!Visited[startVertex])  {\n\t\t    \n\t\t   return dfsUtil(startVertex,Visited);\n\t\t    \t//return getAns();\n\t\t    \t}\n\t\t    \t \n\t\t    \n\t\t     \n\t\t    return 0;\n\t\t    \t}\n\t\t private long dfsUtil(int startVertex, boolean[] Visited) {//0-Blue 1-Pink\n\t\t//System.out.println(startVertex);\n\t\t\t int c=1;\n\t\t\t long cout=0;\n\t\t      degree=0;\n\t\t    \tVisited[startVertex]=true;\n\t\t    //\tlev_dfs[startVertex]=1;\n\t\t      st.push(startVertex);\n\t\t    while(!st.isEmpty()){\n\t\t    \t\n\t\t    \tint top=st.pop();\n\t\t    \n\t\t   \tIterator<Integer> i=adj[top].listIterator();\n\t\t     degree+=adj[top].size();\n\t\t    \n\t\t    while(i.hasNext()){\n\t\t// System.out.println(top+\" \"+adj[top].size());\n\t\t    \tint n=i.next();\n\t\t  //  \tSystem.out.print(n+\" \");\n\t\t     if( !Visited[n]){\n\t\t    \t\t\t\tVisited[n]=true;\n\t\t    \t\t\t\t\tst.push(n);\n\t\t    \t\t\t\t//\tSystem.out.print(n+\" \");\n\t\t    \t\t\t\t\tlev_dfs[n]=top;\n\t\t    \t\t\t\n\t\t    \t\t }\n\t\t         }\n\t\t//    System.out.println(\"--------------------------------\");\n\t\t }\n\t\t    \t\n\t\t    for(int i=1;i<V;i++){\n\t\t    \tif(lev_dfs[i]!=0){\n\t\t    \t\tSystem.out.print(lev_dfs[i]+\" \");\n\t\t    \t}\n\t\t    }\n\t\t    return cout;\n\t\t\t    \n\t\t  //  System.out.println(\"NO\");\n\t\t   // return c;\n\t\t    \t\n\t\t    \n\t\t    \n\t\t    \n\t\t    }\n\t\t        \n\t\t        }     \nclass Pair implements Comparable<Pair>{\n\t   \n\tint w;\n\tint h;\n\tPair(int w,int h){\n\t\tthis.w=w;\n\t\tthis.h=h;\n\t}\n\t@Override\n\tpublic int compareTo(Pair o) {\n\t\t// TODO Auto-generated method stub\n\t//\tSort in increasing order\n\t\tif(w>o.w){\n\t\t\treturn 1;\n\t\t}else if(w<o.w){\n\t\t\treturn -1;\n\t\t}else{\n\t\t\tif(h>o.h)\n\t\t\t\treturn 1;\n\t\t\telse if(h<o.h)\n\t\t\t\treturn -1;\n\t\t\telse\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\t\n\t}\n\n}\n\t\t        \t", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main { \n    public static void main(String[] args) throws IOException { \n        //InputStream input = System.in;\n        //OutputStream output = System.out;\n        InputReader in = new InputReader(new FileReader(new File(\"input.txt\")));\n        PrintWriter out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n        //InputReader in = new InputReader(input);\n        //PrintWriter out = new PrintWriter(output);\n        Solution s = new Solution();\n        s.solve(1, in, out);\n        out.close();\n    }\n\n    static class Solution { \n        \n        double EPS = 0.0000001;\n        public void solve(int cs, InputReader in, PrintWriter out) {\n\n            int n = in.nextInt(), m = in.nextInt();\n            Graph g = new Graph(n, m);\n            int k = in.nextInt();\n            for (int[] v : g.vis)\n                Arrays.fill(v, -1);\n            while (k-- > 0) {\n                Pair start = new Pair(in.nextInt()-1, in.nextInt()-1);\n                g.bfs(start);\n            }\n            int idx1 = 0, idx2 = 0, max = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; ++j) {\n                    if (g.vis[i][j] > max) {\n                        idx1 = i;\n                        idx2 = j;\n                        max = g.vis[i][j];\n                    }\n                }\n            }\n            out.println((idx1+1) + \" \" + (idx2+1));\n        }\n\n        static class Pair {\n            int x, y;\n\n            public Pair(int x, int y) {\n                this.x = x ;\n                this.y = y;\n            }\n        }\n\n        static class Graph {\n            LinkedList<Integer> adj[];\n            int n, e;\n            int[][] vis;\n\n            @SuppressWarnings(\"unchecked\")\n            public Graph(int n, int e) {\n                this.n = n;\n                this.e = e;\n                adj = new LinkedList[n];\n                for (int i = 0; i < n; ++i)\n                    adj[i] = new LinkedList<>();\n                vis = new int[n][e];\n            }\n            \n            int[] dx = {0, 0, 1, -1};\n            int[] dy = {1, -1, 0, 0};\n\n            void bfs(Pair src) {\n                Queue<Pair> q = new LinkedList<>();\n                vis[src.x][src.y] = 0;\n                q.add(src);\n                while (!q.isEmpty()) {\n                    Pair p = q.poll();\n                    for (int k = 0; k < 4; k++) {\n                        int ni = p.x+dx[k];\n                        int nj = p.y+dy[k];\n                        if (isValid(ni, nj) && (vis[ni][nj] == -1 || vis[p.x][p.y]+1 < vis[ni][nj])) {\n                            vis[ni][nj] = vis[p.x][p.y]+1;\n                            q.add(new Pair(ni, nj));\n                        }\n                    }\n                    \n                }\n            }\n\n            boolean isValid(int i, int j) {\n                return i >= 0 && i < n && j >= 0 && j < e;\n            }\n        }\n    }\n\n    static class InputReader { \n        BufferedReader br;\n        StringTokenizer st;\n        \n        public InputReader(InputStream i) {\n            br = new BufferedReader(new InputStreamReader(i), 32768);\n            st = null;\n        }\n\n        public InputReader(FileReader s) {\n            br = new BufferedReader(s);\n            st = null;\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        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            try { \n                return br.readLine();\n            } catch (IOException e) { \n                throw new RuntimeException(e);\n            }\n        }\n    }\n    static class Reader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n        public Reader(){\n            din=new DataInputStream(System.in);\n            buffer=new byte[BUFFER_SIZE];\n            bufferPointer=bytesRead=0;\n        }\n\n        public Reader(String file_name) throws IOException{\n            din=new DataInputStream(new FileInputStream(file_name));\n            buffer=new byte[BUFFER_SIZE];\n            bufferPointer=bytesRead=0;\n        }\n\n        public String readLine() throws IOException{\n            byte[] buf=new byte[64]; // line length\n            int cnt=0,c;\n            while((c=read())!=-1){\n                if(c=='\\n')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;byte c=read();\n            while(c<=' ')c=read();\n            boolean neg=(c=='-');\n            if(neg)c=read();\n            do{ret=ret*10+c-'0';}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;byte c=read();\n            while(c<=' ')c=read();\n            boolean neg=(c=='-');\n            if(neg)c=read();\n            do{ret=ret*10+c-'0';}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;byte c=read();\n            while(c<=' ')c=read();\n            boolean neg=(c=='-');\n            if(neg)c = read();\n            do {ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');\n            if(c=='.')while((c=read())>='0'&&c<='9')\n                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}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tstatic final int[] dx = {0, 0, -1, 1};\n\tstatic final int[] dy = {-1, 1, 0, 0};\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n//\t\tScanner sc = new Scanner(System.in);\n//\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint N = sc.nextInt(), M = sc.nextInt();\n\t\tint[][] dist = new int[N][M];\n\t\tQueue<Integer> q = new LinkedList<>();\n\t\tint K = sc.nextInt();\n\t\twhile(K-->0)\n\t\t{\n\t\t\tint x = sc.nextInt() - 1, y = sc.nextInt() - 1;\n\t\t\tq.add(x * M + y);\n\t\t\tdist[x][y] = 1;\n\t\t}\n\t\t\n\t\tint max = 0, ansX = -1, ansY = -1;\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tint u = q.remove(), x = u / M, y = u % M;\n\t\t\tif(dist[x][y] > max) \n\t\t\t\tmax = dist[ansX = x][ansY = y];\n\t\t\tfor(int k = 0; k < 4; ++k)\n\t\t\t{\n\t\t\t\tint nx = x + dx[k], ny = y + dy[k];\n\t\t\t\tif(nx >= 0 && ny >= 0 && nx < N && ny < M && dist[nx][ny] == 0)\n\t\t\t\t{\n\t\t\t\t\tdist[nx][ny] = dist[x][y] + 1;\n\t\t\t\t\tq.add(nx * M + ny);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tout.printf(\"%d %d\\n\", ansX + 1, ansY + 1);\n\t\tout.close();\n\t}\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\t\t\n\t\tpublic Scanner(String s) throws FileNotFoundException{\tbr = new BufferedReader(new FileReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import 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.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class P35C {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tInputStream inputStream = new FileInputStream(\"input.txt\");\n\t\tOutputStream outputStream = new FileOutputStream(\"output.txt\");\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTask solver = new Task();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n\n\tstatic class Task {\n\t\tprivate class Point {\n\t\t\tint x, y;\n\n\t\t\tpublic Point(int x, int y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t}\n\n\t\tprivate int dis(int i, int j, Point p2) {\n\t\t\treturn Math.abs(i - p2.x) + Math.abs(j - p2.y);\n\t\t}\n\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt(), m = in.nextInt();\n\t\t\tint k = in.nextInt();\n\t\t\tPoint[] ps = new Point[k];\n\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\tps[i] = new Point(in.nextInt() - 1, in.nextInt() - 1);\n\t\t\t}\n\t\t\tint max = 0;\n\t\t\tPoint argmax = ps[0];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tint val = dis(i, j, ps[0]);\n\t\t\t\t\tfor (int l = 1; l < k; l++) {\n\t\t\t\t\t\tval = Math.min(val, dis(i, j, ps[l]));\n\t\t\t\t\t}\n\t\t\t\t\tif (val > max) {\n\t\t\t\t\t\tmax = val;\n\t\t\t\t\t\targmax = new Point(i, j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println((argmax.x + 1) + \" \" + (argmax.y + 1));\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 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 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\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "/*\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 x35C\n   {\n      public static void main(String hi[]) throws Exception\n      {\n         BufferedReader infile = new BufferedReader(new FileReader(\"input.txt\"));\n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int N = Integer.parseInt(st.nextToken());\n         int M = Integer.parseInt(st.nextToken());\n         int K = Integer.parseInt(infile.readLine());\n         int[][] grid = new int[N][M];\n         for(int i=0; i < N; i++)\n            Arrays.fill(grid[i], -1);\n         ArrayDeque<Integer> q = new ArrayDeque<Integer>();\n         st = new StringTokenizer(infile.readLine());\n         while(K-->0)\n         {\n            int a = Integer.parseInt(st.nextToken())-1;\n            int b = Integer.parseInt(st.nextToken())-1;\n            grid[a][b] = 0;\n            q.add(a);   q.add(b);\n         }\n         while(q.size() > 0)\n         {\n            int x = q.poll();\n            int y = q.poll();\n            if(x > 0 && grid[x-1][y] == -1)\n            {\n               grid[x-1][y] = grid[x][y]+1;\n               q.add(x-1); q.add(y);\n            }\n            if(y > 0 && grid[x][y-1] == -1)\n            {\n               grid[x][y-1] = grid[x][y]+1;\n               q.add(x);   q.add(y-1);\n            }\n            if(x+1 < N && grid[x+1][y] == -1)\n            {\n               grid[x+1][y] = grid[x][y]+1;\n               q.add(x+1); q.add(y);\n            }\n            if(y+1 < M && grid[x][y+1] == -1)\n            {\n               grid[x][y+1] = grid[x][y]+1;\n               q.add(x);   q.add(y+1);\n            }\n         }\n         int r = 0;\n         int c = 0;\n         for(int i=0; i < N; i++)\n            for(int j=0; j < M; j++)\n               if(grid[r][c] < grid[i][j])\n               {\n                  r = i;\n                  c = j;\n               }\n         r++;  c++;\n         System.setOut(new PrintStream(new File(\"output.txt\")));\n         System.out.println(r+\" \"+c);\n      }\n   }", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main {\n    public static InputStream IN;\n    public static OutputStream OUT;\n    public static PrintWriter out;\n    public static BufferedReader in;\n    \n    public static StringTokenizer st = null;\n    public static int ni() throws Exception {\n        for (;st == null || !st.hasMoreTokens();){\n            st = new StringTokenizer(in.readLine());\n        }\n        return Integer.parseInt(st.nextToken());\n    }\n    public static void main(String[] args) throws Exception {\n        IN = new FileInputStream(\"input.txt\");\n        OUT = new FileOutputStream(\"output.txt\");\n        out = new PrintWriter(OUT);\n        in = new BufferedReader(new InputStreamReader(IN));\n        int n = ni();\n        int m = ni();\n        int k = ni();\n        int[] x = new int[k];\n        int[] y = new int[k];\n        for (int i = 0 ; i < k; i++){\n            x[i] = ni() - 1;\n            y[i] = ni() - 1;\n        }\n        int w = Integer.MIN_VALUE;\n        int aa = -1;\n        int ab = -1;\n        for (int i = 0 ; i < n ; i++){\n            for (int j = 0; j < m; j++){\n                int min = Integer.MAX_VALUE;\n                for (int q = 0; q < k; q++){\n                    int cur = Math.abs(i - x[q]) + Math.abs(j - y[q]);\n                    min = Math.min(cur, min);\n                }\n                if (min > w){\n                    w = min;\n                    aa = i;\n                    ab = j;\n                }\n            }\n        }\n        out.println((aa + 1) + \" \" + (ab + 1));\n        \n        out.flush();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        InputStream input = System.in;\n        OutputStream output = System.out;\n        InputReader in = new InputReader(new FileReader(new File(\"input.txt\")));\n        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n        Solution s = new Solution();\n        s.solve(1, in, out);\n        out.close();\n    }\n\n    static class Solution {\n\n        static int[][] grid;\n        static int[] dx = {0, 0, 1, -1};\n        static int[] dy = {1, -1, 0, 0};\n        static int n, m;\n        public void solve(int cs, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            m = in.nextInt();\n            int k = in.nextInt();\n            grid = new int[n][m];\n            for (int[] d : grid)\n                Arrays.fill(d, -1);\n            for (int i = 0; i < k; i++) {\n                Pair tree = new Pair(in.nextInt()-1, in.nextInt()-1);\n                bfs(tree);\n            }\n            int max = 0, idx1 = 0, idx2 = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    if (grid[i][j] > max) {\n                        max = grid[i][j];\n                        idx1 = i;\n                        idx2 = j;\n                    }\n                }\n            }\n            out.printf(\"%d %d%n\", idx1+1, idx2+1);\n\n\n        }\n        public boolean isValid(int i, int j) {\n            return i >= 0 && i < n && j >= 0 && j < m;\n        }\n\n\n        static class Pair {\n            int x, y;\n            public Pair(int x, int y) {\n                this.x = x;\n                this.y = y;\n            }\n        }\n        public void bfs(Pair src) {\n            Queue<Pair> q = new LinkedList<>();\n            grid[src.x][src.y] = 0;\n            q.add(src);\n            while (!q.isEmpty()) {\n                Pair p = q.poll();\n                for (int k = 0; k < 4; k++) {\n                    int nx = p.x+dx[k];\n                    int ny = p.y+dy[k];\n                    if (isValid(nx, ny)) {\n                        if (grid[nx][ny] > grid[p.x][p.y]+1 || grid[nx][ny] == -1) {\n                            grid[nx][ny] = grid[p.x][p.y] + 1;\n                            q.add(new Pair(nx, ny));\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    static class InputReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public InputReader(InputStream i) {\n            br = new BufferedReader(new InputStreamReader(i), 32768);\n            st = null;\n        }\n        \n        public InputReader(FileReader s) {\n           br = new BufferedReader(s);\n           st = null;\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        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            try {\n                return br.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.File;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * @author igor_kz\n */\npublic class C35 {\n    public static void main(String[] args) throws IOException {\n        Scanner in = new Scanner(new File(\"input.txt\"));\n        PrintWriter out = new PrintWriter(\"output.txt\");\n        int n = in.nextInt() , m = in.nextInt();\n        int k = in.nextInt();\n        int[] x = new int[k];\n        int[] y = new int[k];\n        int res = 0;\n        for (int i = 0 ; i < k ; i++) {\n            x[i] = in.nextInt();\n            y[i] = in.nextInt();\n        }\n        int xx = 1 , yy = 1;\n        for (int i = 1 ; i <= n ; i++)\n            for (int j = 1 ; j <= m ; j++) {\n                int cnt = Integer.MAX_VALUE;\n                for (int l = 0 ; l < k ; l++) {\n                    int time = Math.abs(i - x[l]) + Math.abs(j - y[l]);\n                    cnt = Math.min(cnt , time);\n                }\n                if (cnt > res) {\n                    res = cnt;\n                    xx = i;\n                    yy = j;\n                }\n                res = Math.max(res , cnt);\n            }\n        out.print(xx + \" \" + yy);\n        out.close();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\n\npublic class Main{\n\t\n\tpublic static void main(String[] Args) throws Exception {\n\t     Scanner sc = new Scanner(new FileReader(\"input.txt\"));\n\t     int n,m,k;\n\t     Integer lx,ly;\n\t     boolean d[][];\n\t     n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt();\n\t     d = new boolean [n+1][m+1];\n\t     for(int i=0;i<=n;++i)\n\t      for(int j=0;j<=m;++j)\n\t       d[i][j]=false;\n\t     \n\t     Queue< pair > q = new LinkedList< pair >();\n\t     lx = ly = -1;\n\t     for(int i=0;i<k;++i){\n\t     \tint x,y; x = sc.nextInt(); y = sc.nextInt();\n\t     \tq.add(new pair(x,y)); lx = x; ly = y;\n\t     \td[x][y]=true;\n\t     }\n\t     \n\t     int dx [] = {0,0,1,-1};\n\t     int dy [] = {-1,1,0,0};\n\t     \n\t     \n\t     while(!q.isEmpty()){\n\t     \t pair tp = q.remove();\n\t     \t int x = tp.x; int y = tp.y;\n\t     \t for(int i=0;i<4;++i){\n\t     \t \t int nx = x+dx[i]; int ny = y+dy[i];\n\t     \t \t if(nx<1 || nx>n || ny<1 || ny>m || d[nx][ny] ) continue;\n\t     \t     d[nx][ny]=true;\n\t     \t     q.add(new pair(nx,ny));\n\t     \t     lx = nx; ly = ny;\n\t     \t }\n\t     }\n\t     FileWriter fw = new FileWriter(\"output.txt\");\n\t     fw.write(lx.toString()); fw.write(\" \"); fw.write(ly.toString());;\n\t     fw.flush();\n\t     \t\n\t}\n}\nclass pair {\n\n  public int x,y;\n  public pair(int _x,int _y){ x = _x; y = _y; }\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C\n{\n\tString line;\n\tStringTokenizer inputParser;\n\tBufferedReader is;\n\tFileInputStream fstream;\n\tDataInputStream in;\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\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\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\tC c = new C(filePath);\n\t}\n\t\n\tpublic C(String inputFile)\n\t{\n\t\tinputFile=\"input.txt\";\n        openInput(inputFile);\n        PrintWriter writer=null;\n\t\ttry {\n\t\t\twriter = new PrintWriter(\"output.txt\");\n\t\t\t\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\t\n\t\treadNextLine();\n\t\tint N=NextInt();\n\t\tint M=NextInt();\n\t\treadNextLine();\n\t\tint K=NextInt();\n\t\treadNextLine();\n\t\tint [] [] p = new int[N][M];\n\t\tint [] [] init = new int [K][2];\n\t\t\n\t\tfor(int i=0; i<K; i++)\n\t\t{\n\t\t\tint x=NextInt()-1;\n\t\t\tint y=NextInt()-1;\n\t\t\tp[x][y]=0;\n\t\t\tinit[i][0]=x;\n\t\t\tinit[i][1]=y;\n\t\t}\n\t\t\n\t\tint max=-1;\n\t\tint maxX=-1, maxY=-1;\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{\n\t\t\t\tp[i][j]=10000;\n\t\t\t\tfor(int k=0; k<K; k++)\n\t\t\t\t{\n\t\t\t\t\tint n=Math.abs(init[k][0]-i)+Math.abs(init[k][1]-j);\n\t\t\t\t\tif(n<p[i][j])p[i][j]=n;\n\t\t\t\t}\n\t\t\t\tif(p[i][j]>max)\n\t\t\t\t{\n\t\t\t\t\tmax=p[i][j];\n\t\t\t\t\tmaxX=i+1;\n\t\t\t\t\tmaxY=j+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\t\n\t\n\t\twriter.println( maxX+\" \"+maxY);\n\t\t\n\t\t\n\n\t\t\n\t\tcloseInput();\n\t\twriter.close();\n\t}\n\n\t\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class FireAgain {\n    static int dx[] = { 0, 0, 1, -1 };\n    static int dy[] = { 1, -1, 0, 0 };\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(new File(\"input.txt\"));\n        BufferedWriter write = new BufferedWriter(new FileWriter(\"output.txt\"));\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        boolean[][] v = new boolean[n][m];\n        int k = sc.nextInt();\n        Queue<Integer> q = new LinkedList<Integer>();\n        for (int i = 0; i < k; i++) {\n            int x = sc.nextInt() - 1;\n            int y = sc.nextInt() - 1;\n            q.add(x);\n            q.add(y);\n            v[x][y] = true;\n        }\n        int lastx = 0;\n        int lasty = 0;\n        while (!q.isEmpty()) {\n            lastx = q.poll();\n            lasty = q.poll();\n            for (int i = 0; i < 4; i++) {\n                int r = lastx + dx[i];\n                int c = lasty + dy[i];\n                if (r >= 0 && c >= 0 && r < n && c < m && !v[r][c]) {\n                    v[r][c] = true;\n                    q.add(r);\n                    q.add(c);\n                }\n            }\n        }\n        write.write((lastx + 1) + \" \" + (lasty + 1));\n        write.close();\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.util.LinkedList;\nimport java.util.Queue;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tBufferedReader br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\n\t\tString dimensions = br.readLine();\n\t\tString extractDim = \"\";\n\t\tint n = 0, m;\n\t\tfor (int i = 0 ; i < dimensions.length() ; i++)\n\t\t{\n\t\t\tif(dimensions.charAt(i) == ' ')\n\t\t\t{\n\t\t\t\tn = Integer.parseInt(extractDim);\n\t\t\t\textractDim = \"\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\textractDim += dimensions.charAt(i);\n\t\t}\n\t\tm = Integer.parseInt(extractDim); \n\t\t\n\t\tString burningTrees = br.readLine();\n\t\t\n\t\tint k = Integer.parseInt(burningTrees);\t\t\n\t\t\n\t\tPoint[] coord = new Point[k];\n\t\t\n\t\tString coordSet = br.readLine();\n\t\tint spaceCount = 0;\n\t\tString newCoord = \"\";\n\t\tint s = 0;\n\t\tfor(int i = 0 ; i < coordSet.length() ; i++)\n\t\t{\n\t\t\tif(coordSet.charAt(i) == ' ')\n\t\t\t\tspaceCount++;\n\t\t\t\n\t\t\tif(spaceCount == 2)\n\t\t\t{\n\t\t\t\tString extractCoord = \"\";\n\t\t\t\tint x = 0, y;\n\t\t\t\tfor (int j = 0 ; j < newCoord.length() ; j++)\n\t\t\t\t{\n\t\t\t\t\tif(newCoord.charAt(j) == ' ')\n\t\t\t\t\t{\n\t\t\t\t\t\tx = Integer.parseInt(extractCoord);\n\t\t\t\t\t\textractCoord = \"\";\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\textractCoord += newCoord.charAt(j);\n\t\t\t\t}\n\t\t\t\ty = Integer.parseInt(extractCoord);\n\t\t\t\t\n\t\t\t\tcoord[s] = new Point(x,y);\n\t\t\t\ts++;\n\t\t\t\tnewCoord = \"\";\n\t\t\t\tspaceCount = 0;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tnewCoord += coordSet.charAt(i);\n\t\t}\n\t\t\n\t\tString extractCoord = \"\";\n\t\tint x = 0, y;\n\t\tfor (int j = 0 ; j < newCoord.length() ; j++)\n\t\t{\n\t\t\tif(newCoord.charAt(j) == ' ')\n\t\t\t{\n\t\t\t\tx = Integer.parseInt(extractCoord);\n\t\t\t\textractCoord = \"\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\textractCoord += newCoord.charAt(j);\n\t\t}\n\t\ty = Integer.parseInt(extractCoord);\n\t\t\n\t\tcoord[s] = new Point(x,y);\n\t\ts++;\n\t\t\n\t\tbr.close();\n\t\t\n\t\tint[][] forest = new int[n+2][m+2];\n\t\t\n\t\tfor(int i = 0 ; i < forest.length ; i++)\n\t\t{\n\t\t\tfor(int j = 0 ; j < forest[i].length ; j++)\n\t\t\t{\n\t\t\t\tif(i == 0 || i == n+1 || j == 0 || j == m+1 )\n\t\t\t\t\tforest[i][j] = 0;\n\t\t\t\telse\n\t\t\t\t\tforest[i][j] = 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tQueue<Point> q = new LinkedList<>();\n\t\t\n\t\tfor(int i = 0 ; i < coord.length ; i++)\n\t\t{\n\t\t\tforest[coord[i].x][coord[i].y] = 0;\n\t\t\tq.add(coord[i]);\n\t\t}\n\t\t\n\t\tPoint tree = new Point();\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tPoint temp = q.remove();\n\t\t\tforest[temp.x][temp.y] = 0;\n\t\t\t\n\t\t\tif(q.isEmpty())\n\t\t\t\ttree = new Point(temp.x ,temp.y);\n\t\t\tfor(int i = -1 ; i <= 1 ; i++)\n\t\t\t{\n\t\t\t\tfor(int j = -1; j <= 1; j++)\n\t\t\t\t{\n\t\t\t\t\tif(i != 0 && j != 0 || i == 0 && j == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif(forest[temp.x+i][temp.y+j] == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tforest[temp.x+i][temp.y+j] = 0;\n\t\t\t\t\t\tq.add(new Point(temp.x+i , temp.y+j));\n\t\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\tBufferedWriter bw = new BufferedWriter(new FileWriter(\"output.txt\"));\n\t\tbw.write(tree.x + \" \" + tree.y);\n\t\tbw.close();\n\t\t\n\t\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n//import java.util.Scanner;\n\npublic class Codes {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader input = new InputReader(new FileReader((\"input.txt\")));\n\t\tint n = input.nextInt();\n\t\tint m = input.nextInt();\n\t\tint k = input.nextInt();\n\t\tboolean[][] visited = new boolean[n][m];\n\t\tQueue<Point> bfs = new LinkedList<Point>();\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint x = input.nextInt();\n\t\t\tint y = input.nextInt();\n\t\t\tvisited[x - 1][y - 1] = true;\n\t\t\tbfs.add(new Point(x - 1, y - 1));\n\t\t}\n\t\tPoint last = bfs.peek();\n\t\twhile(!bfs.isEmpty()) {\n\t\t\tPoint current = bfs.poll();\n\t\t\tint curX = current.x;\n\t\t\tint curY = current.y;\n\t\t\t//the upper tree\n\t\t\tif(curX - 1 >= 0) {\n\t\t\t\tif(!visited[curX - 1][curY]) {\n\t\t\t\t\tbfs.add(new Point(curX - 1,curY));\n\t\t\t\t\tvisited[curX - 1][curY] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//the tree to the right\n\t\t\tif(curY + 1 < m) {\n\t\t\t\tif(!visited[curX][curY + 1]) {\n\t\t\t\t\tbfs.add(new Point(curX ,curY + 1));\n\t\t\t\t\tvisited[curX][curY + 1] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//the lower tree\n\t\t\tif(curX + 1 < n) {\n\t\t\t\tif(!visited[curX + 1][curY]) {\n\t\t\t\t\tbfs.add(new Point(curX + 1,curY));\n\t\t\t\t\tvisited[curX + 1][curY] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//the point to the left\n\t\t\tif(curY - 1 >= 0) {\n\t\t\t\tif(!visited[curX][curY - 1]) {\n\t\t\t\t\tbfs.add(new Point(curX ,curY - 1));\n\t\t\t\t\tvisited[curX][curY - 1] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(bfs.peek()!= null)\n\t\t\tlast = bfs.peek();\n\t\t}\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tout.println((last.x + 1) + \" \" + (last.y + 1));\n\t\tout.close();\n\t\t//System.out.println((last.x + 1) + \" \" + (last.y + 1));\n\t}\n\n\tstatic class Point {\n\t\tint x;\n\t\tint y;\n\n\t\tpublic Point(int x2, int y2) {\n\t\t\tx = x2;\n\t\t\ty = y2;\n\t\t\t\n\t\t}\n\t}\n\n\t/**\n\t * This reader class is NOT Mine.\n\t **/\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.util.*;\npublic class Abc {\n    public static void main(String[] args) throws IOException {\n//        FastReader sc = new FastReader();\n        Scanner sc=new Scanner(new FileReader(\"input.txt\"));\n        PrintWriter out=new PrintWriter(new File(\"output.txt\"));\n        int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();\n        boolean vis[][]=new boolean[n][m];\n        LinkedList<Integer> q=new LinkedList<>();\n        for (int i=0;i<k;i++){\n            int x=sc.nextInt()-1,y=sc.nextInt()-1;\n            vis[x][y]=true;\n            q.add(x);q.add(y);\n        }\n        int lastx=-1,lasty=-1;\n        int dirX[]={1,-1,0,0},dirY[]={0,0,1,-1};\n        while (!q.isEmpty()){\n            int x=q.removeFirst();\n            int y=q.removeFirst();\n            lastx=x;lasty=y;\n            for (int i=0;i<4;i++){\n                int newx=x+dirX[i],newy=y+dirY[i];\n                if (newx>=0 && newx<n && newy>=0 && newy<m && !vis[newx][newy]){\n                    vis[newx][newy]=true;\n                    q.add(newx);q.add(newy);\n                }\n            }\n        }\n        out.println((lastx+1)+\" \"+(lasty+1));\n        out.close();\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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class Main {\n\n    static class Point {\n        int x;\n        int y;\n\n        Point(int a, int b) {\n            x = a;\n            y = b;\n        }\n\n        @Override\n        public String toString() {\n            return \"Point{\" +\n                    \"x=\" + x +\n                    \", y=\" + y +\n                    '}';\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        File f = new File(\"input.txt\");\n        Scanner sc = new Scanner(f);\n        BufferedWriter bw = new BufferedWriter(new FileWriter(new File(\"output.txt\")));\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        boolean[][] board = new boolean[n][m];\n        int count = sc.nextInt();\n        Point[] burningTrees = new Point[count];\n        for (int i=0; i<count; i++) {\n            burningTrees[i] = new Point(sc.nextInt() - 1,sc.nextInt() - 1);\n        }\n        Point last = findLastPoint(board,burningTrees);\n        bw.append((last.x + 1) + \" \" + (last.y + 1) + \"\\n\");\n        bw.flush();\n        bw.close();\n        sc.close();\n    }\n\n\n\n    public static Point findLastPoint(boolean[][] board,  Point[] burningTree){\n        Queue<Point> queue = new LinkedList<Point>();\n        for(int i = 0; i <burningTree.length; i++ ) {\n            queue.add(burningTree[i]);\n            board[burningTree[i].x][burningTree[i].y] = true;\n        }\n        Point lastPoint = new Point(-1,-1);\n        while (!queue.isEmpty()) {\n            Point p = queue.poll();\n            lastPoint = p;\n            ArrayList<Point> neighbours = getNeighbours(p,board);\n            for(int i = 0; i <neighbours.size(); i++ ) {\n                queue.add(neighbours.get(i));\n                board[neighbours.get(i).x][neighbours.get(i).y] = true;\n            }\n        }\n        return lastPoint;\n    }\n\n    public static ArrayList<Point> getNeighbours(Point p, boolean[][] board){\n        ArrayList<Point> neighbours = new ArrayList<>();\n        for(int i = -1; i <=1; i++ ){\n            for(int j = -1; j <= 1; j++ ){\n                if(Math.abs(i) != Math.abs(j)) {\n                    int x = p.x + i;\n                    int y = p.y + j;\n                    if (x >= 0 && x < board.length && y >= 0 && y < board[0].length) {\n                        if (board[x][y] == false) {\n                            neighbours.add(new Point(x,y));\n                        }\n                    }\n                }\n            }\n        }\n        return neighbours;\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class C implements Runnable {\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tRandom rnd;\n\t\n\tshort[] qx, qy;\n\tboolean[][] used;\n\tfinal int[] dx = {1, -1, 0, 0};\n\tfinal int[] dy = {0, 0, 1, -1};\n\t\n\tvoid solve() throws IOException {\n\t\tint n = nextInt(), m = nextInt();\n\t\t\n\t\tqx = new short[n * m];\n\t\tqy = new short[n * m];\n\t\tused = new boolean[n][m];\n\t\t\n\t\tint k = nextInt(), qs = 0, qt = 0;\n\t\t\n\t\tfor(int i = 0; i < k; i++) {\n\t\t\tint x = nextInt() - 1, y = nextInt() - 1;\n\t\t\tused[x][y] = true;\n\t\t\tqx[qt] = (short) x;\n\t\t\tqy[qt] = (short) y;\n\t\t\t++qt;\n\t\t}\n\t\t\n\t\tint rx = 0, ry = 0;\n\t\t\n\t\twhile(qs < qt) {\n\t\t\tint cx = qx[qs], cy = qy[qs];\n\t\t\t++qs;\n\t\t\t\n\t\t\trx = cx;\n\t\t\try = cy;\n\t\t\t\n\t\t\tfor(int z = 0; z < 4; z++) {\n\t\t\t\tint nx = cx + dx[z], ny = cy + dy[z];\n\t\t\t\t\n\t\t\t\tif(nx >= 0 && ny >= 0 && nx < n && ny < m && !used[nx][ny]) {\n\t\t\t\t\tused[nx][ny] = true;\n\t\t\t\t\tqx[qt] = (short) nx;\n\t\t\t\t\tqy[qt] = (short) ny;\n\t\t\t\t\t++qt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println((rx + 1) + \" \" + (ry + 1));\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tfinal boolean oldChecker = false;\n\t\t\n\t\tif(oldChecker) {\n\t\t\tnew Thread(null, new C(), \"yarrr\", 1 << 24).start();\n\t\t} else {\n\t\t\tnew C().run();\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\t} catch (FileNotFoundException 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\n\t\t\trnd = new Random();\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(42);\n\t\t}\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main1\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    }\n    \n    \n    ///////////////////////////////////////////////////////////////////////////////////////////\n    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //\n    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //\n    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //\n    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //\n    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //\n    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //\n    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //\n    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //\n    ///////////////////////////////////////////////////////////////////////////////////////////\n    static class pair \n    {\n       int x;\n       int y;\n       public pair (int k, int p) \n       {\n           x = k;\n           y = p;\n       }\n       @Override\n       public boolean equals(Object o) {\n            if (this == o) return true;\n            if (o == null || getClass() != o.getClass()) return false;\n            pair pair = (pair) o;\n            return x == pair.x && y == pair.y;\n        }\n    \n       @Override\n       public int hashCode() {\n            return Objects.hash(x, y);\n       }\n    }\n    public static void main(String[] args)throws IOException\n    {\n        /*PrintWriter out= new PrintWriter(new File(\"input.txt\"));\n        Reader sc=new Reader();*/\n        Scanner sc = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n        Queue<pair> q=new LinkedList<>();\n        int n=sc.nextInt();\n        int m=sc.nextInt();\n        int t=sc.nextInt();\n        int mark[][]=new int[n+2][m+2];\n        while(t-->0)\n        {\n            int a=sc.nextInt();int b=sc.nextInt();\n            mark[a][b]=1;\n            q.add(new pair(a,b));\n        }\n        int ansx=1;int ansy=1;\n        while(q.size()!=0)\n        {\n            pair p=q.remove();\n            if(mark[Math.max(1,p.x-1)][p.y]==0)\n            {\n                q.add(new pair(Math.max(1,p.x-1),p.y));\n                mark[Math.max(1,p.x-1)][p.y]=1;\n                ansx=Math.max(1,p.x-1);\n                ansy=p.y;\n            }\n            if(mark[Math.min(n,p.x+1)][p.y]==0)\n            {\n                q.add(new pair(Math.min(n,p.x+1),p.y));\n                mark[Math.min(n,p.x+1)][p.y]=1;\n                ansx=Math.min(n,p.x+1);\n                ansy=p.y;\n            }\n            if(mark[p.x][Math.max(1,p.y-1)]==0)\n            {\n                q.add(new pair(p.x,Math.max(1,p.y-1)));\n                mark[p.x][Math.max(1,p.y-1)]=1;\n                ansx=p.x;\n                ansy=Math.max(1,p.y-1);\n            }\n            if(mark[p.x][Math.min(m,p.y+1)]==0)\n            {\n                q.add(new pair(p.x,Math.min(m,p.y+1)));\n                mark[p.x][Math.min(m,p.y+1)]=1;\n                ansx=p.x;\n                ansy=Math.min(m,p.y+1);\n            }\n        }\n        out.println(ansx+\" \"+ansy);\n        out.flush();\n    }\n}\n    ", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class MainF {\n    public static void main(String[]args) throws IOException{\n        BufferedReader br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n        BufferedWriter bw = new BufferedWriter(new FileWriter(new File(\"output.txt\")));\n        String S = br.readLine();\n        String[]J = S.split(\" \");\n        int N = Integer.parseInt(J[0]);\n        int M = Integer.parseInt(J[1]);\n\n        int K = Integer.parseInt(br.readLine());\n        int[]x = new int[K];\n        int[]y = new int[K];\n        S = br.readLine();\n        J = S.split(\" \");       \n        for(int i = 0; i<2*K; i = i + 2){\n            x[i/2] = Integer.parseInt(J[i]);\n            y[i/2] = Integer.parseInt(J[i+1]);\n        }\n        \n        int ans = -1;\n        int ansX = -1;\n        int ansY = -1;\n        \n        for (int i = 1; i<=N; i++){\n            for (int j = 1; j<=M; j++){\n                int W = M + N;\n                for (int k = 0; k<K; k++){\n                    W = Math.min(W, Math.abs(i-x[k]) + Math.abs(j-y[k]));\n                }\n                if (W < ans)continue;\n                ans = W;\n                ansX = i;\n                ansY = j;               \n            }\n        }\n        bw.write(Integer.toString(ansX)+\" \"+Integer.toString(ansY));\n        br.close();\n        bw.close();     \n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.Collection;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.FileInputStream;\nimport java.io.InputStreamReader;\nimport java.util.Objects;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Queue;\nimport java.util.LinkedList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Nafiur Rahman Khadem Shafin \ud83d\ude42\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\tProblemCFireAgain solver = new ProblemCFireAgain ();\n\t\tsolver.solve (1, in, out);\n\t\tout.close ();\n\t}\n\t\n\tstatic class ProblemCFireAgain {\n\t\tprivate static final byte[] dx = {-1, 0, 0, 1};\n\t\tprivate static final byte[] dy = {0, -1, 1, 0};\n\t\tprivate static int[][] lvl;\n\t\tprivate static int max;\n\t\tprivate static int n;\n\t\tprivate static int m;\n\t\tprivate static int k;\n\t\tprivate static ProblemCFireAgain.Pair[] bgn;\n\t\tprivate static ProblemCFireAgain.Pair res;\n\t\t\n\t\tprivate static void bfs2d () {\n\t\t\tQueue<ProblemCFireAgain.Pair> bfsq = new LinkedList<ProblemCFireAgain.Pair> ();\n\t\t\tfor (ProblemCFireAgain.Pair src : bgn) {\n\t\t\t\tlvl[src.a][src.b] = 0;\n\t\t\t\tbfsq.add (src);\n\t\t\t}\n\t\t\twhile (!bfsq.isEmpty ()) {\n\t\t\t\tProblemCFireAgain.Pair op = bfsq.poll ();\n\t\t\t\tint plvl = lvl[op.a][op.b];\n//\t\t\tSystem.out.println (\"ber hoise \"+op+\" \"+plvl);\n\t\t\t\tif (plvl>max) {\n\t\t\t\t\tres = op;\n\t\t\t\t\tmax = plvl;\n\t\t\t\t}\n\t\t\t\tfor (int i = 0; i<4; i++) {\n\t\t\t\t\tint newX = op.a+dx[i];\n\t\t\t\t\tint newY = op.b+dy[i];\n//\t\t\t\tSystem.out.println (newX+\" \"+newY+\" \"+n+\" \"+m);\n\t\t\t\t\tif (newX>0 && newX<=n && newY>0 && newY<=m && lvl[newX][newY] == -1) {\n\t\t\t\t\t\tbfsq.add (new ProblemCFireAgain.Pair (newX, newY));\n\t\t\t\t\t\tlvl[newX][newY] = (plvl+1);\n//\t\t\t\t\tSystem.out.println (\"dhukse \"+newX+\" \"+newY);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void solve (int testNumber, InputReader _in, PrintWriter _out) {\n\t\t\t/*\n\t\t\t * file input-output \ud83d\ude2e. Multi source bfs. Same as snackdown problem.\n\t\t\t * */\n\t\t\ttry (InputReader in = new InputReader (new FileInputStream (\"input.txt\"));\n\t\t\t\t PrintWriter out = new PrintWriter (new BufferedWriter (new FileWriter (\"output.txt\")))) {\n\t\t\t\tn = in.nextInt ();\n\t\t\t\tm = in.nextInt ();\n\t\t\t\tk = in.nextInt ();\n\t\t\t\tbgn = new ProblemCFireAgain.Pair[k];\n\t\t\t\tfor (int i = 0; i<k; i++) {\n\t\t\t\t\tbgn[i] = new ProblemCFireAgain.Pair (in.nextInt (), in.nextInt ());\n\t\t\t\t}\n\t\t\t\tmax = Integer.MIN_VALUE;\n\t\t\t\tlvl = new int[n+5][m+5];\n\t\t\t\tfor (int i = 0; i<n+4; i++) {\n\t\t\t\t\tArrays.fill (lvl[i], -1);\n\t\t\t\t}\n\t\t\t\tbfs2d ();\n//\t\t\tSystem.out.println (max);\n\t\t\t\tout.println (res);\n\t\t\t} catch (Exception e) {\n//\t\t\te.printStackTrace ();\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate static class Pair {\n\t\t\tint a;\n\t\t\tint b;\n\t\t\t\n\t\t\tPair (int a, int b) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tpublic String toString () {\n\t\t\t\treturn a+\" \"+b;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tpublic boolean equals (Object o) {\n\t\t\t\tif (this == o) return true;\n\t\t\t\tif (!(o instanceof ProblemCFireAgain.Pair)) return false;\n\t\t\t\tProblemCFireAgain.Pair pair = (ProblemCFireAgain.Pair) o;\n\t\t\t\treturn a == pair.a && b == pair.b;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tpublic int hashCode () {\n\t\t\t\treturn Objects.hash (a, b);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tstatic class InputReader implements AutoCloseable {\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\t\t\n\t\tpublic InputReader (InputStream stream) {\n\t\t\treader = new BufferedReader (new InputStreamReader (stream));\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\t\n\t\tpublic void close () throws Exception {\n\t\t\treader.close ();\n\t\t}\n\t\t\n\t}\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C35C_BFS_Fire {\n    public static boolean[][] burning;\n    public static LinkedList<int[]> LitTrees; //which is best to use\n    public static int N, M;\n    public static int[] lastTree;\n    public static void main(String[] args) throws IOException {\n        // InputStreamReader stream = new InputStreamReader(System.in);\n        // BufferedReader input = new BufferedReader(stream);\n\n        BufferedReader input = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\n        StringTokenizer dataR = new StringTokenizer(input.readLine());\n        N = Integer.parseInt(dataR.nextToken());\n        M = Integer.parseInt(dataR.nextToken());\n        burning = new boolean[N+1][M+1];\n\n        StringTokenizer dataR1 = new StringTokenizer(input.readLine());\n        int K = Integer.parseInt(dataR1.nextToken());\n\n        StringTokenizer dataR2 = new StringTokenizer(input.readLine());\n        LitTrees = new LinkedList<int[]>();\n        for (int j = 0; j < K; j++){\n            int x = Integer.parseInt(dataR2.nextToken());\n            int y = Integer.parseInt(dataR2.nextToken());\n            int[] coord = {x, y};\n            LitTrees.add(coord);\n            burning[x][y] = true;\n        }\n\n        // while(ExistsAliveTree()){\n        //     spread();\n        // }\n\n        spread();\n\n        // System.out.println(LitTrees.getLast()[0] + \" \" + LitTrees.getLast()[1]);\n        out.println(lastTree[0] + \" \" + lastTree[1]);\n        out.close();\n\n    }\n\n    public static void spread(){\n        while(!LitTrees.isEmpty()){\n            int[] studying = LitTrees.removeFirst(); //is iterator faster\n            int[] studying1 = {studying[0]-1, studying[1]};\n            int[] studying2 = {studying[0], studying[1]-1};\n            int[] studying3 = {studying[0], studying[1]+1};\n            int[] studying4 = {studying[0]+1, studying[1]};\n            if (studying1[0] >= 1 && !burning[studying1[0]][studying1[1]]){\n                LitTrees.add(studying1);\n                burning[studying1[0]][studying1[1]] = true;\n            }\n            if (studying2[1] >= 1 && !burning[studying2[0]][studying2[1]]){\n                LitTrees.add(studying2);\n                burning[studying2[0]][studying2[1]] = true;\n            }\n            if (studying3[1] < M+1 && !burning[studying3[0]][studying3[1]]){\n                LitTrees.add(studying3);\n                burning[studying3[0]][studying3[1]] = true;\n            }\n            if (studying4[0] < N+1 && !burning[studying4[0]][studying4[1]]){\n                LitTrees.add(studying4);\n                burning[studying4[0]][studying4[1]] = true;\n            }\n            lastTree = studying; \n        }        \n    }\n    \n\n    public static boolean ExistsAliveTree() {\n        if (LitTrees.size() == N*M){\n            return false;\n        } else{\n            return true;\n        }\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "//package round35;\n\nimport java.io.File;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"3 3 1 1 1\";\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tint k = ni();\n\t\tint[] x = new int[k];\n\t\tint[] y = new int[k];\n\t\tfor(int i = 0;i < k;i++){\n\t\t\tx[i] = ni() - 1;\n\t\t\ty[i] = ni() - 1;\n\t\t}\n\t\tint max = -1;\n\t\tint maxi = -1;\n\t\tint maxj = -1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tint min = Integer.MAX_VALUE;\n\t\t\t\tfor(int l = 0;l < k;l++){\n\t\t\t\t\tmin = Math.min(min, Math.abs(x[l] - i) + Math.abs(y[l] - j));\n\t\t\t\t}\n\t\t\t\tif(min > max){\n\t\t\t\t\tmax = min;\n\t\t\t\t\tmaxi = i;\n\t\t\t\t\tmaxj = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println((maxi+1) + \" \" + (maxj+1));\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(new File(\"input.txt\")) : new Scanner(INPUT);\n\t\tout = INPUT.isEmpty() ? new PrintWriter(\"output.txt\") : 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 C().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\tstatic String join(int[] a, int d){StringBuilder sb = new StringBuilder();for(int v : a){sb.append(v + d + \" \");}return sb.toString();}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\n\npublic class c {\n\n\tstatic boolean used[][];\n\tstatic int n;\n\tstatic int m;\n\tstatic int a[][];\n\t\n\t\n\tpublic static void main(String args[])throws Exception{\n\t\tScanner in =new Scanner(new File(\"input.txt\"));//System.in);//\n\t\tPrintWriter out=new PrintWriter(new File(\"output.txt\"));//System.out);//\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tint k = in.nextInt();\n\t\t//a=new int[n+1][m+1];\n\t\t/*for (int i = 1; i<=n; i++)\n\t\t\tfor (int j = 1; j<=m; j++)\n\t\t\t\ta[i][j] = 40001;\n\t\t*/\n\t\tint x[]=new int[k];\n\t\tint y[]=new int[k];\n\t\tfor (int i = 0; i<k; i++){\n\t\t\tx[i] = in.nextInt();\n\t\t\ty[i] = in.nextInt();\n\t\t}\n\t\t\n\t\tint max = 0;\n\t\tint xx = 1; int yy= 1;\n\t\tfor (int i = 1; i<=n; i++)\n\t\t\tfor (int j = 1; j<=m; j++){\n\t\t\t\tint count = Integer.MAX_VALUE;\n\t\t\t\tfor (int l =0; l<k; l++)\n\t\t\t\t\tcount = Math.min(Math.abs(i - x[l]) + Math.abs(j - y[l]), count);\n\t\t\n\t\t\t\tif (max < count){\n\t\t\t\t\tmax = count;\n\t\t\t\t\txx = i; yy = j;\n\t\t\t\t}\n\t\t\t}\n\t\tout.println(xx + \" \" + yy);\n\t\tout.close();\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\n\npublic class Main {\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        \n        /*\n        inB = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        /**/\n        //*\n        try {\n        inB = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n        out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n        } catch(Exception e) {}\n        /**/\n        in = new StreamTokenizer(inB);\n    }\n    \n    private static int[][] mind;\n    private static boolean[][] used;\n    \n    private static int n,m;\n    \n    public static void main(String[] args)throws Exception {\n        n = nextInt();\n        m = nextInt();\n        int k = nextInt();\n        int[][] mas = new int[k][2];\n        \n        for(int i = 0; i<k; i++) {\n            mas[i][0] = nextInt()-1;\n            mas[i][1] = nextInt()-1;\n        }\n        \n        mind = new int[n][m];\n        used = new boolean[n][m];\n        for(int i = 0; i<n; i++) {\n            Arrays.fill(mind[i], Integer.MAX_VALUE);\n        }\n        \n        ArrayDeque<int[]> ad = new ArrayDeque<int[]>();\n        \n        for(int i = 0; i<k; i++) {\n            ad.add(new int[] {mas[i][0], mas[i][1], 0});\n        }\n        \n        while(!ad.isEmpty()) {\n            int[] cur = ad.remove();\n            \n            if(used[cur[0]][cur[1]])continue;\n            int x = cur[0]; int y = cur[1]; int d = cur[2];\n            mind[x][y] = ++d;\n            used[x][y] = true;\n            //if(isValid(x+1,y+1) && !used[x+1][y+1])   ad.add(new int[] {x+1,  y+1, d});\n            if(isValid(x+1,y)   && !used[x+1][y])   ad.add(new int[] {x+1,  y,   d});\n            //if(isValid(x+1,y-1) && !used[x+1][y-1])   ad.add(new int[] {x+1,  y-1, d});\n            if(isValid(x,y+1)   && !used[x][y+1])   ad.add(new int[] {x,    y+1, d});\n            if(isValid(x,y-1)   && !used[x][y-1])   ad.add(new int[] {x,    y-1, d});\n            //if(isValid(x-1,y+1) && !used[x-1][y+1])   ad.add(new int[] {x-1,  y+1, d});\n            if(isValid(x-1,y)   && !used[x-1][y])   ad.add(new int[] {x-1,  y,   d});\n            //if(isValid(x-1,y-1) && !used[x-1][y-1])   ad.add(new int[] {x-1,  y-1, d});\n        }\n        \n        int max = Integer.MIN_VALUE;\n        int maxx = 0, maxy = 0;\n        \n        for(int i = 0; i<n; i++) {\n            for(int j = 0; j<m; j++) {\n                if(mind[i][j] > max) {\n                    max = mind[i][j];\n                    maxx = i+1;\n                    maxy = j+1;\n                }\n            }\n        }\n        \n        out.println(maxx + \" \" + maxy);\n        out.flush();\n    }\n    \n    private static boolean isValid(int x, int y) {\n        return x>=0 && x<n && y>=0 && y<m;\n    }\n    \n    /////////////////////////////////////////////////\n    // pre - written\n    /////////////////////////////////////////////////\n    private static void println(Object o) throws Exception {\n        System.out.println(o);\n    }\n    private static void exit(Object o) throws Exception {\n        println(o);\n        exit();\n    }\n    private static void exit() {\n        System.exit(0);\n    }\n    /////////////////////////////////\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "//package round35;\n\nimport java.io.File;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"3 3 1 1 1\";\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tint k = ni();\n\t\tint[] x = new int[k];\n\t\tint[] y = new int[k];\n\t\tfor(int i = 0;i < k;i++){\n\t\t\tx[i] = ni() - 1;\n\t\t\ty[i] = ni() - 1;\n\t\t}\n\t\tint max = -1;\n\t\tint maxi = -1;\n\t\tint maxj = -1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tint min = Integer.MAX_VALUE;\n\t\t\t\tfor(int l = 0;l < k;l++){\n\t\t\t\t\tmin = Math.min(min, Math.abs(x[l] - i) + Math.abs(y[l] - j));\n\t\t\t\t}\n\t\t\t\tif(min > max){\n\t\t\t\t\tmax = min;\n\t\t\t\t\tmaxi = i;\n\t\t\t\t\tmaxj = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println((maxi+1) + \" \" + (maxj+1));\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(new File(\"input.txt\")) : new Scanner(INPUT);\n\t\tout = INPUT.isEmpty() ? new PrintWriter(\"output.txt\") : 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 C().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\tstatic String join(int[] a, int d){StringBuilder sb = new StringBuilder();for(int v : a){sb.append(v + d + \" \");}return sb.toString();}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tScanner sc = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tArrayList<ArrayList<Integer>> fire = new ArrayList<ArrayList<Integer>>();\n\t\twhile (k-- != 0) {\n\t\t\tArrayList<Integer> t = new ArrayList<Integer>();\n\t\t\tt.add(sc.nextInt());\n\t\t\tt.add(sc.nextInt());\n\t\t\tfire.add(t);\n\t\t}\n\t\t\n\t\tint maxI = 0, maxJ = 0, maxManhatten = -1;\n\t\tfor(int i = 1; i <= n; i++)\n\t\t\tfor(int j = 1; j <= m; j++){\n\t\t\t\tint curManhatten = Integer.MAX_VALUE;\n\t\t\t\tfor(int u = 0; u < fire.size(); u++)\n\t\t\t\t\tcurManhatten = Math.min(curManhatten, manhatten(i, j, fire.get(u).get(0), fire.get(u).get(1)));\n\t\t\t\t\n\t\t\t\tif(curManhatten > maxManhatten){\n\t\t\t\t\tmaxManhatten = curManhatten;\n\t\t\t\t\tmaxI = i;\n\t\t\t\t\tmaxJ = j;\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\tout.print(maxI + \" \" + maxJ);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tprivate static int manhatten(int i, int j, Integer a, Integer b) {\n\t\treturn Math.abs(i - a) + Math.abs(j - b);\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class practice {\n\tstatic class Reader \n    { \n        final private int BUFFER_SIZE = 1 << 16; \n        private DataInputStream din; \n        private byte[] buffer; \n        private int bufferPointer, bytesRead; \n  \n        public Reader() \n        { \n            din = new DataInputStream(System.in); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public Reader(String file_name) throws IOException \n        { \n            din = new DataInputStream(new FileInputStream(file_name)); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public String readLine() throws IOException \n        { \n            byte[] buf = new byte[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\t\tpublic static void main(String[] args) throws IOException {\t\t\t\n\t\t\tReader scn=new Reader(\"input.txt\");\n\t\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\t int n=scn.nextInt(),m=scn.nextInt(),k=scn.nextInt();\n\t\t int[][] inf=new int[k][2];\n\t\t for(int i=0;i<k;i++){\n\t\t\t inf[i][0]=scn.nextInt();inf[i][1]=scn.nextInt();\n\t\t }\n\t\t int ans=0,x=1,y=1;\n\t\t for(int i=1;i<=n;i++){\n\t\t\t for(int j=1;j<=m;j++){\n\t\t\t\t int temp=Integer.MAX_VALUE;\n\t\t\t\t for(int l=0;l<k;l++){\n\t\t\t\t\ttemp=Math.min(temp, Math.abs(i-inf[l][0])+Math.abs(j-inf[l][1])); \n\t\t\t\t }\n\t\t\t\t if(temp>ans){\n\t\t\t\t\t ans=temp;x=i;y=j;\n\t\t\t\t }\n\t\t\t }\n\t\t }\n\t\t out.print(x + \" \" + y);\n\t   \t out.close();\n\t\t}\n\t}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\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 *\n * 3 2 3 5\n * -2 -1 4 -1 2 7 3\n *\n * 10 1 -10617 30886 -7223 -63085 47793 -61665 -14614 60492 16649 -58579 3 8 1\n * 10 4 7 1 7 3 7\n *\n * 22862 -34877\n *\n * @author pttrung\n */\npublic class C_Round_35_Div2 {\n\n    public static long MOD = 1000000007;\n    static int[] X = {0, 1, 0, -1};\n    static int[] Y = {1, 0, -1, 0};\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 m = in.nextInt();\n        int k = in.nextInt();\n        int[][] map = new int[n][m];\n        LinkedList<Point> q = new LinkedList();\n        int reX = -1;\n        int reY = -1;\n        for (int i = 0; i < k; i++) {\n            int x = in.nextInt() - 1;\n            int y = in.nextInt() - 1;\n            reX = x;\n            reY = y;\n            map[x][y] = 1;\n            q.add(new Point(x, y));\n        }\n\n        while (!q.isEmpty()) {\n            Point p = q.poll();\n            // System.out.println(map[p.x][p.y] + \" \" + p.x + \" \" + p.y);\n            for (int i = 0; i < 4; i++) {\n                int x = p.x + X[i];\n                int y = p.y + Y[i];\n                if (x >= 0 && y >= 0 && x < n && y < m && map[x][y] == 0) {\n                    map[x][y] = 1 + map[p.x][p.y];\n                    if (map[x][y] > map[reX][reY]) {\n                        reX = x;\n                        reY = y;\n                    }\n\n                    q.add(new Point(x, y));\n                }\n            }\n        }\n        out.println((reX + 1) + \" \" + (reY + 1));\n        out.close();\n\n    }\n\n    public static int[] KMP(String val) {\n        int i = 0;\n        int j = -1;\n        int[] result = new int[val.length() + 1];\n        result[0] = -1;\n        while (i < val.length()) {\n            while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n                j = result[j];\n            }\n            j++;\n            i++;\n            result[i] = j;\n        }\n        return result;\n\n    }\n\n    public static boolean nextPer(int[] data) {\n        int i = data.length - 1;\n        while (i > 0 && data[i] < data[i - 1]) {\n            i--;\n        }\n        if (i == 0) {\n            return false;\n        }\n        int j = data.length - 1;\n        while (data[j] < data[i - 1]) {\n            j--;\n        }\n        int temp = data[i - 1];\n        data[i - 1] = data[j];\n        data[j] = temp;\n        Arrays.sort(data, i, data.length);\n        return true;\n    }\n\n    public static int digit(long n) {\n        int result = 0;\n        while (n > 0) {\n            n /= 10;\n            result++;\n        }\n        return result;\n    }\n\n    public static double dist(long a, long b, long x, long y) {\n        double val = (b - a) * (b - a) + (x - y) * (x - y);\n        val = Math.sqrt(val);\n        double other = x * x + a * a;\n        other = Math.sqrt(other);\n        return val + other;\n\n\n\n    }\n\n    public static class Point implements Comparable<Point> {\n\n        int x, y;\n\n        public Point(int start, int end) {\n            this.x = start;\n            this.y = end;\n        }\n\n        @Override\n        public int hashCode() {\n            int hash = 5;\n            hash = 47 * hash + this.x;\n            hash = 47 * hash + this.y;\n            return hash;\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            if (obj == null) {\n                return false;\n            }\n            if (getClass() != obj.getClass()) {\n                return false;\n            }\n            final Point other = (Point) obj;\n            if (this.x != other.x) {\n                return false;\n            }\n            if (this.y != other.y) {\n                return false;\n            }\n            return true;\n        }\n\n        @Override\n        public int compareTo(Point o) {\n            return 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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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.io.OutputStream;\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;\n        try\n        {\n            inputStream = new FileInputStream(\"input.txt\");\n        } catch (IOException e)\n        {\n            throw new RuntimeException(e);\n        }\n        OutputStream outputStream;\n        try\n        {\n            outputStream = new FileOutputStream(\"output.txt\");\n        } catch (IOException e)\n        {\n            throw new RuntimeException(e);\n        }\n        FastScanner in = new FastScanner(inputStream);\n        FastPrinter out = new FastPrinter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC\n    {\n        public void solve(int testNumber, FastScanner in, FastPrinter out)\n        {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            int p = in.nextInt();\n            int[] x = new int[p];\n            int[] y = new int[p];\n            for (int i = 0; i < p; i++)\n            {\n                x[i] = in.nextInt();\n                y[i] = in.nextInt();\n            }\n\n            int X = x[0];\n            int Y = y[0];\n            int D = -1;\n            for (int dx = 1; dx <= n; dx++)\n            {\n                int x1 = dx;\n                int y1 = 1;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int dx = 1; dx <= n; dx++)\n            {\n                int x1 = dx;\n                int y1 = m;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int dy = 1; dy <= m; dy++)\n            {\n                int x1 = 1;\n                int y1 = dy;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int dy = 1; dy <= m; dy++)\n            {\n                int x1 = n;\n                int y1 = dy;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n\n            for (int i = 1; i <= Math.min(m, n); i++)\n            {\n                int x1 = i;\n                int y1 = i;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int i = 1, ii = m; i <= n && ii >= 1; i++, ii--)\n            {\n                int x1 = i;\n                int y1 = ii;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            out.println(X + \" \" + Y);\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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n\npublic class C implements Runnable{\n\n    // SOLUTION!!!\n    // HACK ME PLEASE IF YOU CAN!!!\n    // PLEASE!!!\n    // PLEASE!!!\n    // PLEASE!!!\n\n    private final static Random rnd = new Random();\n    private final static String fileName = \"\";\n\n    private void solve() {\n        int n = readInt();\n        int m = readInt();\n\n        int k = readInt();\n\n        Point[] starts = readPointArray(k);\n        for (Point start : starts) {\n            start.x--;\n            start.y--;\n        }\n\n        Point furthest = bfs(n, m, starts);\n        out.println((furthest.x + 1) + \" \" + (furthest.y + 1));\n    }\n\n    private Point bfs(int n, int m, Point[] starts) {\n        final int INF = n * m + 1;\n\n        boolean[][] used = new boolean[n][m];\n\n        Queue<Integer> queue = new ArrayDeque<>();\n\n        for (Point start : starts) {\n            used[start.x][start.y] = true;\n            queue.add(start.x * m + start.y);\n        }\n\n        int last = -1;\n        while (queue.size() > 0) {\n            int from = queue.poll();\n            last = from;\n\n            int fromX = from / m, fromY = from % m;\n\n            for (int[] step : steps) {\n                int toX = fromX + step[0];\n                int toY = fromY + step[1];\n\n                if (!checkCell(toX, n, toY, m)) continue;\n                if (used[toX][toY]) continue;\n\n                used[toX][toY] = true;\n                queue.add(toX * m + toY);\n            }\n        }\n\n        return new Point(last / m, last % m);\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private final static boolean FIRST_INPUT_STRING = false;\n    private final static boolean MULTIPLE_TESTS = true;\n    private final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n    private final static int MAX_STACK_SIZE = 128;\n\n    private final static boolean OPTIMIZE_READ_NUMBERS = false;\n\n    /////////////////////////////////////////////////////////////////////\n\n    public void run(){\n        try{\n            timeInit();\n            Locale.setDefault(Locale.US);\n\n            init();\n\n            if (ONLINE_JUDGE) {\n                solve();\n            } else {\n                do {\n                    try {\n                        timeInit();\n                        solve();\n                        time();\n\n                        out.println();\n                    } catch (NumberFormatException e) {\n                        break;\n                    } catch (NullPointerException e) {\n                        if (FIRST_INPUT_STRING) break;\n                        else throw e;\n                    }\n                } while (MULTIPLE_TESTS);\n            }\n\n            out.close();\n            time();\n        }catch (Exception e){\n            e.printStackTrace(System.err);\n            System.exit(-1);\n        }\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private BufferedReader in;\n    private OutputWriter out;\n    private StringTokenizer tok = new StringTokenizer(\"\");\n\n    public static void main(String[] args){\n        new Thread(null, new C(), \"\", MAX_STACK_SIZE * (1L << 20)).start();\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private void init() throws FileNotFoundException{\n        Locale.setDefault(Locale.US);\n\n        in = new BufferedReader(new FileReader(\"input.txt\"));\n        out = new OutputWriter(\"output.txt\");\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<Integer>[] readGraph(int vertexNumber, int edgeNumber) {\n        @SuppressWarnings(\"unchecked\")\n        List<Integer>[] graph = new List[vertexNumber];\n\n        for (int index = 0; index < vertexNumber; ++index){\n            graph[index] = new ArrayList<>();\n        }\n\n        while (edgeNumber-- > 0){\n            int from = readInt() - 1;\n            int to = readInt() - 1;\n\n            graph[from].add(to);\n            graph[to].add(from);\n        }\n\n        return graph;\n    }\n\n    private static class GraphBuilder {\n\n        final int size;\n        final List<Integer>[] edges;\n\n        static GraphBuilder createInstance(int size) {\n            List<Integer>[] edges = new List[size];\n            for (int v = 0; v < size; ++v) {\n                edges[v] = new ArrayList<>();\n            }\n\n            return new GraphBuilder(edges);\n        }\n\n        private GraphBuilder(List<Integer>[] edges) {\n            this.size = edges.length;\n            this.edges = edges;\n        }\n\n        public void addEdge(int from, int to) {\n            addDirectedEdge(from, to);\n            addDirectedEdge(to, from);\n        }\n\n        public void addDirectedEdge(int from, int to) {\n            edges[from].add(to);\n        }\n\n        public int[][] build() {\n            int[][] graph = new int[size][];\n            for (int v = 0; v < size; ++v) {\n                List<Integer> vEdges = edges[v];\n                graph[v] = castInt(vEdges);\n            }\n\n            return graph;\n        }\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static class IntIndexPair {\n\n        static Comparator<IntIndexPair> increaseComparator = new Comparator<C.IntIndexPair>() {\n\n            @Override\n            public int compare(C.IntIndexPair indexPair1, C.IntIndexPair indexPair2) {\n                int value1 = indexPair1.value;\n                int value2 = indexPair2.value;\n\n                if (value1 != value2) return value1 - value2;\n\n                int index1 = indexPair1.index;\n                int index2 = indexPair2.index;\n\n                return index1 - index2;\n            }\n        };\n\n        static Comparator<IntIndexPair> decreaseComparator = new Comparator<C.IntIndexPair>() {\n\n            @Override\n            public int compare(C.IntIndexPair indexPair1, C.IntIndexPair indexPair2) {\n                int value1 = indexPair1.value;\n                int value2 = indexPair2.value;\n\n                if (value1 != value2) return -(value1 - value2);\n\n                int index1 = indexPair1.index;\n                int index2 = indexPair2.index;\n\n                return index1 - index2;\n            }\n        };\n\n        static IntIndexPair[] from(int[] array) {\n            IntIndexPair[] iip = new IntIndexPair[array.length];\n            for (int i = 0; i < array.length; ++i) {\n                iip[i] = new IntIndexPair(array[i], i);\n            }\n\n            return iip;\n        }\n\n        int value, index;\n\n        IntIndexPair(int value, int index) {\n            super();\n            this.value = value;\n            this.index = index;\n        }\n\n        int getRealIndex() {\n            return index + 1;\n        }\n    }\n\n    private IntIndexPair[] readIntIndexArray(int size) {\n        IntIndexPair[] array = new IntIndexPair[size];\n\n        for (int index = 0; index < size; ++index) {\n            array[index] = new IntIndexPair(readInt(), index);\n        }\n\n        return array;\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static class OutputWriter extends PrintWriter {\n\n        final int DEFAULT_PRECISION = 12;\n\n        private int precision;\n        private String format, formatWithSpace;\n\n        {\n            precision = DEFAULT_PRECISION;\n\n            format = createFormat(precision);\n            formatWithSpace = format + \" \";\n        }\n\n        OutputWriter(OutputStream out) {\n            super(out);\n        }\n\n        OutputWriter(String fileName) throws FileNotFoundException {\n            super(fileName);\n        }\n\n        int getPrecision() {\n            return precision;\n        }\n\n        void setPrecision(int precision) {\n            precision = max(0, precision);\n            this.precision = precision;\n\n            format = createFormat(precision);\n            formatWithSpace = format + \" \";\n        }\n\n        String createFormat(int precision){\n            return \"%.\" + precision + \"f\";\n        }\n\n        @Override\n        public void print(double d){\n            printf(format, d);\n        }\n\n        void printWithSpace(double d){\n            printf(formatWithSpace, d);\n        }\n\n        void printAll(double...d){\n            for (int i = 0; i < d.length - 1; ++i){\n                printWithSpace(d[i]);\n            }\n\n            print(d[d.length - 1]);\n        }\n\n        @Override\n        public void println(double d){\n            printlnAll(d);\n        }\n\n        void printlnAll(double... d){\n            printAll(d);\n            println();\n        }\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static class RuntimeIOException extends RuntimeException {\n\n        /**\n         *\n         */\n        private static final long serialVersionUID = -6463830523020118289L;\n\n        RuntimeIOException(Throwable cause) {\n            super(cause);\n        }\n    }\n\n    /////////////////////////////////////////////////////////////////////\n    //////////////// Some useful constants and functions ////////////////\n    /////////////////////////////////////////////////////////////////////\n\n    private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n    private static final int[][] steps8 = {\n            {-1, 0}, {1, 0}, {0, -1}, {0, 1},\n            {-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n    };\n\n    private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {\n        return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);\n    }\n\n    private static boolean checkIndex(int index, int lim){\n        return (0 <= index && index < lim);\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static boolean checkBit(int mask, int bit){\n        return (mask & (1 << bit)) != 0;\n    }\n    private static boolean checkBit(long mask, int bit){\n        return (mask & (1L << bit)) != 0;\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static long getSum(int[] array) {\n        long sum = 0;\n        for (int value: array) {\n            sum += value;\n        }\n\n        return sum;\n    }\n\n    private static Point getMinMax(int[] array) {\n        int min = array[0];\n        int max = array[0];\n\n        for (int index = 0, size = array.length; index < size; ++index, ++index) {\n            int value = array[index];\n\n            if (index == size - 1) {\n                min = min(min, value);\n                max = max(max, value);\n            } else {\n                int otherValue = array[index + 1];\n\n                if (value <= otherValue) {\n                    min = min(min, value);\n                    max = max(max, otherValue);\n                } else {\n                    min = min(min, otherValue);\n                    max = max(max, value);\n                }\n            }\n        }\n\n        return new Point(min, max);\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static int[] getPrimes(int n) {\n        boolean[] used = new boolean[n];\n        used[0] = used[1] = true;\n\n        int size = 0;\n        for (int i = 2; i < n; ++i) {\n            if (!used[i]) {\n                ++size;\n                for (int j = 2 * i; j < n; j += i) {\n                    used[j] = true;\n                }\n            }\n        }\n\n        int[] primes = new int[size];\n        for (int i = 0, cur = 0; i < n; ++i) {\n            if (!used[i]) {\n                primes[cur++] = i;\n            }\n        }\n\n        return primes;\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static long lcm(long a, long b) {\n        return a / gcd(a, b) * b;\n    }\n\n    private static long gcd(long a, long b) {\n        return (a == 0 ? b : gcd(b % a, a));\n    }\n\n    /////////////////////////////////////////////////////////////////////\n\n    private static class MultiSet<ValueType> {\n\n        public static <ValueType> MultiSet<ValueType> createMultiSet() {\n            Map<ValueType, Integer> multiset = new HashMap<>();\n            return new MultiSet<>(multiset);\n        }\n\n        private final Map<ValueType, Integer> multiset;\n        private int size;\n\n        public MultiSet(Map<ValueType, Integer> 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<KeyType> extends HashMap<KeyType, Integer> {\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<Integer> list) {\n        int[] array = new int[list.size()];\n        for (int i = 0; i < array.length; ++i) {\n            array[i] = list.get(i);\n        }\n\n        return array;\n    }\n\n    private static long[] castLong(List<Long> list) {\n        long[] array = new long[list.size()];\n        for (int i = 0; i < array.length; ++i) {\n            array[i] = list.get(i);\n        }\n\n        return array;\n    }\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\nimport java.util.*;\n\npublic class A_GENERAL {\n   \n\t// for fast output printing  : use printwriter or stringbuilder\n\t// remember to close pw using pw.close()\n\tstatic StringBuilder sb = new StringBuilder();\n\tstatic long seive_size = (long) 1e6;\n\tstatic String alpha = \"abcdefghijklmnopqrstuvwxyz\";\n    static ArrayList<Integer> primes = new ArrayList<>();\n    static boolean[] seive_set = new boolean[(int) seive_size+1];\n    static int n, m, k;\n    static ArrayList<Integer>[] adj;\n    static boolean[] vis;\n    static ArrayDeque<Integer> q = new ArrayDeque<>();\n    static final long MOD = 998244353;\n    static int[] dx = new int[] {1, 0, -1, 0, 1, -1, 1, -1};\n    static int[] dy = new int[] {0, 1, 0, -1, -1, 1, 1, -1};\n    static long[][] arr;\n    static int[] rank;\n    static int[] parent;\n\n    static int[] s;\n    static long[] a;\n    public static void main(String[] args) throws FileNotFoundException {\n//\t\tPrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n//\t\tMyScanner sc = new MyScanner();\n\t\tScanner sc = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n\t\tn = sc.nextInt();\n\t\tm = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tArrayDeque<iPair> qq = new ArrayDeque<>();\n\t\tboolean[][] vis = new boolean[n+1][m+1];\n\t\tfor(int i = 0; i < k; i++) {\n\t\t\tint u = sc.nextInt();\n\t\t\tint v = sc.nextInt();\n\t\t\tqq.add(new iPair(u, v));\n\t\t\tvis[u][v] = true;\n\t\t}\n\t\tiPair last = null;\n\t\twhile(!qq.isEmpty()) {\n\t\t\tiPair pp = qq.poll();\n\t\t\tint i = pp.f;\n\t\t\tint j = pp.s;\n\t\t\tif(isValid(i-1, j) && !vis[i-1][j]) {\n\t\t\t\tqq.add(new iPair(i-1, j));\n\t\t\t\tvis[i-1][j] = true;\n\t\t\t}\n\t\t\tif(isValid(i+1, j) && !vis[i+1][j]) {\n\t\t\t\tqq.add(new iPair(i+1, j));\n\t\t\t\tvis[i+1][j] = true;\n\t\t\t}\n\t\t\tif(isValid(i,  j-1) && !vis[i][j-1]) {\n\t\t\t\tqq.add(new iPair(i, j-1));\n\t\t\t\tvis[i][j-1] = true;\n\t\t\t}\n\t\t\tif(isValid(i, j+1) && !vis[i][j+1]) {\n\t\t\t\tqq.add(new iPair(i, j+1));\n\t\t\t\tvis[i][j+1] = true;\n\t\t\t}\n\t\t\tlast = pp;\n\t\t}\n\t\tout.println(last.f + \" \" + last.s);\n\t\tsc.close();\n\t\tout.close();\n\t}\n    public static boolean isValid(int i, int j) {\n    \tif(i < 1 || i > n || j < 1 || j > m) return false;\n    \treturn true;\n    }\n    public static class Triplet implements Comparable<Triplet> {\n\t\tint x;\n    \tint y;\n    \tint z;\n    \tTriplet(int x, int y, int z) {\n    \t\tthis.x = x;\n    \t\tthis.y = y;\n    \t\tthis.z = z;\n    \t}\n    \tpublic int compareTo(Triplet o) {\n    \t\treturn Integer.compare(this.x, o.x);\n    \t}\n    }\n    public static class iPair implements Comparable<iPair>  {\n    \tint f;\n    \tint s;\n    \tiPair(int f, int s) {\n    \t\tthis.f = f;\n    \t\tthis.s = s;\n    \t}\n    \tpublic int compareTo(iPair o) {\n    \t\treturn Integer.compare(this.f,  o.f);\n    \t}\n    }\n    \n\tpublic static class Pair implements Comparable<Pair>{\n\t\tlong f;\n\t\tlong s;\n\t\tPair(long f, long s) {\n\t\t\tthis.f = f;\n\t\t\tthis.s = s;\n\t\t}\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn Long.compare(this.f, o.f);\n\t\t}\n\t}\n\tpublic static void init(int n) {\n    \tadj = new ArrayList[n+1];\n    \tvis = new boolean[n+1];\n    \tparent = new int[n+1];\n\t\trank = new int[n+1];\n    \tfor(int i = 0; i <= n; i++) {\n    \t\tadj[i] = new ArrayList<>();\n    \t\tparent[i] = i;\n\t\t\trank[i] = 0;\n    \t}\n    }\n\t// print string \"s\" multiple times \n\t// prefer to use this function for multiple printing\n\tpublic static String mp(String s, int times) {\n\t\treturn String.valueOf(new char[times]).replace(\"\\0\", s);\n\t}\n\t// take log with base 2\n \tpublic static long log2(long k) {\n \t\treturn 63-Long.numberOfLeadingZeros(k);\n \t}\n\n \t// using lambda function for sorting\n   \tpublic static void lambdaSort() {\n   \t\tArrays.sort(arr, (a, b) -> Double.compare(a[0], b[0]));\n   \t}\n  \t\n  \t// (n choose k) = (n/k) * ((n-1) choose (k-1))\n  \tpublic static long choose(long n, long k) {\n \t\treturn (k == 0) ? 1 : (n*choose(n-1, k-1))/k;\n \t}\n\n \t// just for keeping gcd function for other personal purposes\n \tpublic static long gcd(long a, long b) {\n \t\treturn (a == 0) ? b : gcd(b%a, a);\n \t}\n \t\n\tpublic static long max(long... as) {\n        long max = Long.MIN_VALUE;\n        for (long a : as) max = Math.max(a, max);\n        return max;\n    }\n\n    public static long min(int... as) {\n        long min = Long.MAX_VALUE;\n        for (long a : as) min = Math.min(a, min);\n        return min;\n    }\n \t\n    public static long modpow(long x, long n, long mod) {\n    \tif(n == 0) return 1%mod;\n    \tlong u = modpow(x, n/2, mod);\n    \tu = (u*u)%mod;\n    \tif(n%2 == 1) u = (u*x)%mod;\n    \treturn u;\n    }\n \t// ======================= binary search (lower and upper bound) =======================\n\tpublic static int lowerBound(long[] a, int x) {\n\t\tint lo = 0;\n \t\tint hi = a.length-1;\n \t\tint ans = -1;\n \t\twhile(lo <= hi) {\n \t\t\tint mid = (lo+hi)/2;\n \t\t\tif(x < a[mid]) {\n \t\t\t\thi = mid-1;\n \t\t\t} else if(x > a[mid]) {\n \t\t\t\tlo = mid+1;\n \t\t\t} else if(lo != hi) {\n \t\t\t\t hi = mid-1; \t\t// for first occurrence\n \t\t\t\t ans = mid;\n \t\t\t} else {\n \t\t\t\treturn mid;\n \t\t\t}\n \t\t}\n \t\treturn ans;\n\t}\n\t\n\tpublic static int upperBound(long[] a, long x) {\n\t\tint lo = 0;\n\t\tint hi = a.length-1;\n\t\tint ans = -1;\n\t\twhile(lo <= hi) {\n\t\t\tint mid = (lo+hi)/2;\n\t\t\tif(x < a[mid]) {\n\t\t\t\thi = mid-1;\n\t\t\t} else if(x > a[mid]) {\n\t\t\t\tlo = mid+1;\n\t\t\t} else if(lo != hi) {\n\t\t\t\tlo = mid+1;\t\t\t// for last occurrence\n\t\t\t\tans = mid;\n\t\t\t} else {\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\t// ================================================================\n\n\t// ================== SEIVE OF ERATOSTHENES =======================\n\t// Complexity : O(N * log(log(N)))       ( almost O(N) )\n\tpublic static void generatePrimes() {\n\t\t// set.add(0);\n\t\t// set.add(1);\n\t\tArrays.fill(seive_set, true);\n\t\tseive_set[0] = false;\n\t\tseive_set[1] = false;\n\t\tfor(int i = 2; i <= seive_size; i++) {\n\t\t\tif(seive_set[i]) {\n\t\t\t\tfor(long j = (long) i*i; j <= seive_size; j+=i) \n\t\t\t\t\tseive_set[(int)j] = false;\n\t\t\t\tprimes.add(i);\n\t\t\t}\n\t\t}\n\t}\n  \n\tpublic static boolean isPrime(long N) {\n\t\tif(N <= seive_size) return seive_set[(int)N];\n\t\tfor (int i = 0; i < (int)primes.size(); i++)\n\t\t\tif (N % primes.get(i) == 0) return false;\n\t\treturn true;\n\t}\n\t// ===========================================================\n  \n \t// ================ Permutation of String ====================\n \tpublic static void permute(String str) {\n \t\tpermute(str, 0, str.length()-1);\n \t}\n \tpublic static void permute(String str, int l, int r) \n    { \n        if (l == r) \n            System.out.println(str); \n        else\n        { \n            for (int i = l; i <= r; i++) \n            { \n                str = swap(str,l,i); \n                permute(str, l+1, r); \n                str = swap(str,l,i); \n            } \n        } \n    }\n\tpublic static String swap(String a, int i, int j) \n    { \n        char temp; \n        char[] charArray = a.toCharArray(); \n        temp = charArray[i] ; \n        charArray[i] = charArray[j]; \n        charArray[j] = temp; \n        return String.valueOf(charArray); \n    } \n\t// Union-find\n\t// static int[] parent, rank;\n//\tpublic static void makeSet(int n) {\n//\n//\t\tparent = new int[n+1];\n//\t\trank = new int[n+1];\n//\t\tfor(int i = 1; i <= n; i++) {\n//\t\t\tparent[i] = i;\n//\t\t\trank[i] = 0;\n//\t\t}\n//\t}\n\tpublic static int find(int u) {\n\n\t\tif(parent[u] == u)\treturn u;\n\n\t\tint v = find(parent[u]);\n\t\tparent[u] = v;\n\t\treturn v;\n\n\t}\n\tpublic static boolean connected(int u, int v) {\n\t\treturn find(u) == find(v);\n\t}\n\tpublic static void Union(int u, int v) {\n\n\t\tint x = find(u);\t\t\t\t//root of u\n\t\tint y = find(v);\t\t\t\t//root of v\n\n\t\tif(x == y)\t\treturn;\n\t\tif(rank[x] == rank[y]) {\n\t\t\tparent[y] = x;\n\t\t\trank[x]++;\n\t\t}\n\t\telse if(rank[x] > rank[y]) {\n\t\t\tparent[y] = x;\n\t\t}\n\t\telse {\n\t\t\tparent[x] = y;\n\t\t}\n\n\t}\n\t\n//\tpublic static int dijkstra(int x, int y) {\n//    \tint[] dist = new int[n+1];\n//    \tArrays.fill(dist, Integer.MAX_VALUE);\n//    \tPriorityQueue<Node> q = new PriorityQueue<>();\n//    \tq.add(new Node(x, 0));\n//    \tdist[x] = 0;\n//    \twhile(!q.isEmpty()) {\n//    \t\tNode node = q.poll();\n//    \t\tint u = node.key;\n//    \t\tif(u == y) {\n//    \t\t\tbreak;\n//    \t\t}\n//    \t\tfor(int v : res[u]) {\n//    \t\t\tif(dist[v] > dist[u]+count[u]) {\n//    \t\t\t\tdist[v] = dist[u] + count[u];\n//    \t\t\t\tq.add(new Node(v, dist[v]));\n//    \t\t\t}\n//    \t\t}\n//    \t}\n//    \tif(dist[y] == Integer.MAX_VALUE) {\n//    \t\treturn -1;\n//    \t}\n//    \treturn dist[y];\n//    }\n\t\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() {while (st == null || !st.hasMoreElements()) {\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (IOException e) {e.printStackTrace();}}\n\t\treturn st.nextToken();}\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\tString nextLine(){String str = \"\";\n\t\ttry {str = br.readLine();}\n\t\tcatch (IOException e) {e.printStackTrace();}\n\t\treturn str;}\n\t\tint[] 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        int[] nextIntArray(int n, int delta) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++)\n                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++)\n                a[i] = nextLong();\n            return a;\n        }\n\t}\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tstatic int dx[] = { 1, -1, 0, 0 };\n\tstatic int dy[] = { 0, 0, 1, -1 };\n\n\tpublic static void main(String args[]) throws Exception {\n\t\tScanner sc = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n\t\tint n = sc.nextInt(), m = sc.nextInt();\n\t\tint[][] grid = new int[n][m];\n\t\tfor (int[] i : grid)\n\t\t\tArrays.fill(i, -1);\n\t\tQueue<Pair> q = new LinkedList<>();\n\t\tint k = sc.nextInt();\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint x = sc.nextInt() - 1, y = sc.nextInt() - 1;\n\t\t\tgrid[x][y] = 0;\n\t\t\tq.add(new Pair(x, y));\n\t\t}\n\t\tPair p = new Pair(-1, -1);\n\t\twhile (!q.isEmpty()) {\n\t\t\tp = q.poll();\n\t\t\tfor (int i = 0; i < dx.length; i++) {\n\t\t\t\tint tx = p.x + dx[i], ty = p.y + dy[i];\n\t\t\t\tif (tx >= 0 && tx < n && ty >= 0 && ty < m && grid[tx][ty] == -1) {\n\t\t\t\t\tgrid[tx][ty] = grid[p.x][p.y] + 1;\n\t\t\t\t\tq.add(new Pair(tx, ty));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(p);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Pair {\n\t\tint x, y;\n\n\t\tpublic Pair(int a, int b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + 1 + \" \" + (y + 1);\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String r) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(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 boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.List;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\n\npublic class Problem {\n\t\n\tpublic static Pair solve(Forest f, List<Pair> queue){\n\t\tPair current = null, next = null;\n\t\tint index = 0;\n\t\twhile(queue.size() > 0){\n\t\t\tcurrent = queue.remove(0);\n\t\t\tindex = f.desk[current.x][current.y];\n\t\t\t\tif(current.x>0){\n\t\t\t\t\tnext = new Pair(current.x-1,current.y);\n\t\t\t\t\tif(f.desk[next.x][next.y]==0){\n\t\t\t\t\t\tf.desk[next.x][next.y] = index+1;\n\t\t\t\t\t\tqueue.add(next);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(current.x<f.N-1){\n\t\t\t\t\tnext = new Pair(current.x+1,current.y);\n\t\t\t\t\tif(f.desk[next.x][next.y]==0){\n\t\t\t\t\t\tf.desk[next.x][next.y] = index+1;\n\t\t\t\t\t\tqueue.add(next);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(current.y>0){\n\t\t\t\t\tnext = new Pair(current.x,current.y-1);\n\t\t\t\t\tif(f.desk[next.x][next.y]==0){\n\t\t\t\t\t\tf.desk[next.x][next.y] = index+1;\n\t\t\t\t\t\tqueue.add(next);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(current.y<f.M-1){\n\t\t\t\t\tnext = new Pair(current.x,current.y+1);\n\t\t\t\t\tif(f.desk[next.x][next.y]==0){\n\t\t\t\t\t\tf.desk[next.x][next.y] = index+1;\n\t\t\t\t\t\tqueue.add(next);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn f.findMax();\n\t}\n\n\tpublic static void main(String[] args){\n\t\tString buffer = null;\n\t\tStringTokenizer st = null;\n\t\tForest f = null;\n\t\tList<Pair> pairs = new LinkedList<Pair>();\n\t\tInteger N,M,K,x,y;\n\t\ttry {\n\t\t\tBufferedReader in = new BufferedReader(\n\t\t\t\t\t\t\tnew FileReader(\"input.txt\")\n\t\t\t\t\t\t\t);\n\t\t\tFileWriter out = new FileWriter(\"output.txt\");\n\t\t\tbuffer = in.readLine();\n\t\t\tst = new StringTokenizer(buffer);\n\t\t\tN = new Integer(st.nextToken());\n\t\t\tM = new Integer(st.nextToken());\n\t\t\tf = new Forest(N,M);\n\t\t\tbuffer = in.readLine();\n\t\t\tst = new StringTokenizer(buffer);\n\t\t\tK = new Integer(st.nextToken());\n\t\t\tbuffer = in.readLine();\n\t\t\tst = new StringTokenizer(buffer);\n\t\t\tfor(int i = 0; i<K; i++){\n\t\t\t\tx = new Integer(st.nextToken());\n\t\t\t\ty = new Integer(st.nextToken());\n\t\t\t\tf.desk[x-1][y-1] = 1;\n\t\t\t\tpairs.add(new Pair(x-1,y-1));\n\t\t\t}\n\t\t\tPair res = solve(f,pairs);\n\t\t\t\n\t\t\tout.write(res.toString());\n\t\t\tout.flush();\n\t\t} catch (Exception e) {\n\t\t}\n\t}\n}\n\nclass Pair {\n\tpublic Pair(int i, int j){\n\t\tx = i;\n\t\ty = j;\n\t}\n\tpublic String toString(){\n\t\treturn (x+1) + \" \" + (y+1);\n\t}\n\tpublic int x;\n\tpublic int y;\n}\n\nclass Forest {\n\tpublic Forest(int n, int m){\n\t\tN = n;\n\t\tM = m;\n\t\tdesk = new int[N][M];\n\t}\n\n\tpublic Pair findMax(){\n\t\tPair max = new Pair(0,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(desk[i][j]>desk[max.x][max.y]){\n\t\t\t\t\tmax.x = i;\n\t\t\t\t\tmax.y = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\t\n\n\tpublic int N;\n\tpublic int M;\n\tpublic int[][] desk;\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n\npublic class FireAgain {\n\n\tScanner in;\n\tPrintWriter out;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tnew FireAgain().run();\n\n\t}\n\t\n\tvoid run() throws IOException {\n\t\tin = new Scanner(new FileReader(\"input.txt\"));\n        out = new PrintWriter(new FileWriter(\"output.txt\"));\n\n\t\tsolve();\n\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tprivate void solve() {\n\t\t// TODO Auto-generated method stub\n\t\tint N = in.nextInt();\n\t\tint M = in.nextInt();\n\t\tint[][] burn = new int[N + 1][M + 1];\n\t\tint K = in.nextInt();\n\t\t\n\t\tint[] qx = new int[N * M];\n\t\tint[] qy = new int[N * M];\n\t\t\n\t\tint first = 0;\n\t\tint last = 0;\n\t\tfor (int i = 0; i < K; i ++){\n\t\t\tqx[last] = in.nextInt();\n\t\t\tqy[last] = in.nextInt();\n\t\t\tburn[qx[last]][qy[last]] = 1;\n\t\t\tlast ++;\n\t\t}\n\t\t\n\t\twhile (first < last){\n\t\t\tint x = qx[first];\n\t\t\tint y = qy[first];\n\t\t\tif (x - 1 > 0 && burn[x - 1][y] == 0){\n\t\t\t\tburn[x - 1][y] = 1;\n\t\t\t\tqx[last] = x - 1;\n\t\t\t\tqy[last] = y;\n\t\t\t\tlast ++;\n\t\t\t}\n\t\t\tif (y - 1 > 0 && burn[x][y - 1] == 0){\n\t\t\t\tburn[x][y - 1] = 1;\n\t\t\t\tqx[last] = x;\n\t\t\t\tqy[last] = y - 1;\n\t\t\t\tlast ++;\n\t\t\t}\n\t\t\tif (x + 1 <= N && burn[x + 1][y] == 0){\n\t\t\t\tburn[x + 1][y] = 1;\n\t\t\t\tqx[last] = x + 1;\n\t\t\t\tqy[last] = y;\n\t\t\t\tlast ++;\n\t\t\t}\n\t\t\tif (y + 1 <= M && burn[x][y + 1] == 0){\n\t\t\t\tburn[x][y + 1] = 1;\n\t\t\t\tqx[last] = x;\n\t\t\t\tqy[last] = y + 1;\n\t\t\t\tlast ++;\n\t\t\t}\n\t\t\tfirst ++;\n\t\t}\n\t\t\n\t\tout.println(qx[last - 1] + \" \" + qy[last - 1]);\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class FireAgain {\n\tstatic int n;\n\tstatic int m;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader r = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tString s = r.readLine();\n\t\tString[] sp = s.split(\" \");\n\t\tn = new Integer(sp[0]);\n\t\tm = new Integer(sp[1]);\n\t\tboolean[][] v = new boolean[n][m];\n\t\tr.readLine();\n\t\ts = r.readLine();\n\t\tsp = s.split(\" \");\n\t\tQueue<Integer> q = new LinkedList<Integer>();\n\t\tfor (int i = 0; i < sp.length; i += 2) {\n\t\t\tv[new Integer(sp[i]) - 1][new Integer(sp[i + 1]) - 1] = true;\n\t\t\tq.add(new Integer(sp[i]) - 1);\n\t\t\tq.add(new Integer(sp[i + 1]) - 1);\n\t\t}\n\n\t\tint[] dx = { 1, -1, 0, 0 };\n\t\tint[] dy = { 0, 0, 1, -1 };\n\t\tint lx = -1;\n\t\tint ly = -1;\n\t\twhile (!q.isEmpty()) {\n\t\t\tint x = q.remove();\n\t\t\tint y = q.remove();\n\t\t\tlx = x;\n\t\t\tly = y;\n\t\t\tfor (int i = 0; i < dy.length; i++) {\n\t\t\t\tint nx = x + dx[i];\n\t\t\t\tint ny = y + dy[i];\n\t\t\t\tif (valid(nx, ny) && !v[nx][ny]) {\n\t\t\t\t\tv[nx][ny] = true;\n\t\t\t\t\tq.add(nx);\n\t\t\t\t\tq.add(ny);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlx++;\n\t\tly++;\n\t\tBufferedWriter wr=new BufferedWriter(new FileWriter(\"output.txt\"));\n\t\twr.write(\"\"+lx + \" \" + ly);\n\t\twr.newLine();\n\t\twr.close();\n\t\t\n\t}\n\n\tprivate static boolean valid(int nx, int ny) {\n\t\treturn nx >= 0 && nx < n && ny >= 0 && ny < m;\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String... strings) throws InterruptedException {\n\t\tnew Thread(new Solution()).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString next() throws Exception {\n\t\tif (st == null || !st.hasMoreElements())\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\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(next());\n\t}\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\tint n, m, k, xor = 0;\n\tboolean[][] used;\n\tHashSet<Long> [] set;\n\tvoid solve() throws Exception {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tk = nextInt();\n\t\tused = new boolean[n][m];\n\t\tset = new HashSet[2];\n\t\tfor(int i = 0; i < 2; set[i++] = new HashSet<Long>());\n\t\t\n\t\tfor(int i = 0; i < k; i++){\n\t\t\tint x = nextInt()-1, y = nextInt()-1;\n\t\t\tused[x][y] = true;\n\t\t\tset[0].add(10000L*x + y);\n\t\t}\n\t\tfor (;;xor ^= 1){\n\t\t\tset[xor^1].clear();\n\t\t\tint ansx = -1, ansy = -1;\n\t\t\tfor (long i : set[xor]){\n\t\t\t\tint x = (int)(i/10000), y = (int)(i%10000);\n\t\t\t\tif (ansx < 0){\n\t\t\t\t\tansx = x+1;\n\t\t\t\t\tansy = y+1;\n\t\t\t\t}\n\t\t\t\tadd(x+1, y);\n\t\t\t\tadd(x-1, y);\n\t\t\t\tadd(x, y+1);\n\t\t\t\tadd(x, y-1);\n\t\t\t}\n\t\t\tif (set[xor^1].size() == 0){\n\t\t\t\tout.println(ansx + \" \" + ansy);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tpublic void add(int x, int y){\n\t\tif (!( x >= 0 && y >= 0 && x < n && y < m && !used[x][y])) return;\n\t\tset[xor^1].add(10000L*x + y);\n\t\tused[x][y] = true;\n\t}\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    static BufferedReader br;\n    static PrintWriter out;\n    static StringTokenizer st;\n    \n    static int[][] moves = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};\n    \n    static boolean correct(int x, int y, int n, int m) {\n        return (x >= 0 && x < n && y >= 0 && y < m); \n    }\n    \n    static void solve() throws Exception {\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        int[][] order = new int[n][m];\n        boolean[][] used = new boolean[n][m];\n        Queue<Integer[]> q = new LinkedList<>();\n        Set<String> set = new HashSet<String>();\n        for(int i = 0; i < k; i++) {\n            int x = nextInt() - 1;\n            int y = nextInt() - 1;\n            order[x][y] = 1;\n            used[x][y] = true;\n            q.add(new Integer[] {x, y});\n            set.add(x + \"\" + y);\n        }\n        while(!q.isEmpty()) {\n            Integer[] v = q.remove();\n            for(int[] move : moves) {\n                int x = v[0] + move[0];\n                int y = v[1] + move[1];\n//              if(set.contains(x + \"\" + y)) {\n//                  continue;\n//              }\n                if(correct(x, y, n, m) && !used[x][y]) {\n                    q.add(new Integer[] {x, y});\n                    used[x][y] = true;\n                    order[x][y] = order[v[0]][v[1]] + 1; \n                }\n            }\n        }\n        int max = Integer.MIN_VALUE;\n        int maxI = -1;\n        int maxJ = -1;\n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < m; j++) {\n                if(order[i][j] > max) {\n                    max = order[i][j];\n                    maxI = i;\n                    maxJ = j;\n                }\n            }\n        }\n        maxI++;\n        maxJ++;\n        out.println(maxI + \" \" + maxJ);\n    }\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 next() 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    public static void main(String[] args) {\n        try {\n            InputStream input = System.in;\n            OutputStream output = System.out;\n            br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n            out = new PrintWriter(new PrintStream(new File(\"output.txt\")));\n            solve();\n            out.close();\n            br.close();\n        } catch (Throwable t) {\n            t.printStackTrace();\n        }\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class Main1 {\n\n\tstatic int dr[] = { 0, 0, 1, -1 };\n\tstatic int dc[] = { 1, -1, 0, 0 };\n\n\tstatic boolean isValid(int r, int c) {\n\t\tif (r >= n || r < 0 || c >= m || c < 0)\n\t\t\treturn false;\n\n\t\treturn true;\n\t}\n\n\tstatic int grid[][];\n\tstatic int n, m;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastReader input = new FastReader();\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n\n\t\tn = input.nextInt();\n\t\tm = input.nextInt();\n\t\tgrid = new int[n][m];\n\n\t\tint k = input.nextInt();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(grid[i], Integer.MAX_VALUE);\n\t\t}\n\n\t\tQueue<Pair> q = new LinkedList<Pair>();\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint x = input.nextInt() - 1;\n\t\t\tint y = input.nextInt() - 1;\n\n\t\t\tq.add(new Pair(x, y));\n\t\t\tgrid[x][y] = 0;\n\n\t\t\twhile (!q.isEmpty()) {\n\t\t\t\tPair cur = q.poll();\n\t\t\t\tfor (int j = 0; j < dr.length; j++) {\n\t\t\t\t\tint r = cur.x;\n\t\t\t\t\tint c = cur.y;\n\t\t\t\t\tint nr = r + dr[j];\n\t\t\t\t\tint nc = c + dc[j];\n\t\t\t\t\tint dist = grid[r][c] + 1;\n\n\t\t\t\t\tif (isValid(nr, nc) && grid[nr][nc] > dist) {\n\t\t\t\t\t\tgrid[nr][nc] = dist;\n\n\t\t\t\t\t\tq.add(new Pair(nr, nc));\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint max = -1;\n\t\tint x = -1;\n\t\tint y = -1;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (grid[i][j] > max) {\n\t\t\t\t\tmax = grid[i][j];\n\t\t\t\t\tx = i + 1;\n\t\t\t\t\ty = j + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(x + \" \" + y);\n\t\tout.flush();\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\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 NumberFormatException, 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\tString nextLine() throws IOException {\n\t\t\tString str = \"\";\n\t\t\tstr = br.readLine();\n\t\t\treturn str;\n\t\t}\n\t}\n\n\tstatic class con {\n\t\tstatic int IINF = (int) 1e9;\n\t\tstatic int _IINF = (int) -1e9;\n\t\tstatic long LINF = (long) 1e15;\n\t\tstatic long _LINF = (long) -1e15;\n\t\tstatic double EPS = 1e-9;\n\t}\n\n\tstatic class Triple implements Comparable<Triple> {\n\t\tint x;\n\t\tint y;\n\t\tint z;\n\n\t\tTriple(int x, int y, int z) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.z = z;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Triple o) {\n\t\t\tif (x == o.x && y == o.y)\n\t\t\t\treturn z - o.z;\n\t\t\tif (x == o.x)\n\t\t\t\treturn y - o.y;\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint x;\n\t\tint y;\n\n\t\tPair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\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 y - o.y;\n\t\t\treturn x - o.x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\n\t}\n\n\tstatic void shuffle(int[] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = i + (int) (Math.random() * (a.length - 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\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static int n,m;\n\tpublic static void main(String[] arg) {\n\t\tFastScanner scan = null;\n\t\tPrintWriter out = null;\n\t\ttry{\n\t\t\tscan = new FastScanner(new FileInputStream(\"input.txt\"));\n\t\t\tout = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\t\t}catch(FileNotFoundException e){\n\t\t\tscan = new FastScanner(System.in);\n\t\t\tout = new PrintWriter(System.out);\n\t\t}\n\t\t\n\t\t n = scan.nextInt();\n\t\t m = scan.nextInt();\n\t\tint k = scan.nextInt();\n\t\tint[][] board = new int[n+1][m+1];\n\t\tString[] ins = scan.nextLine().split(\" \",-1);\n\t\tList<Integer> ps = new ArrayList<Integer>();\n\t\tfor(int i = 0; i < 2 * k; i += 2){\n\t\t\tint a = Integer.parseInt(ins[i]);\n\t\t\tint b = Integer.parseInt(ins[i+1]);\n\t\t\tboard[a][b] = 1;\n\t\t\tps.add(a * 2001 + b);\n\t\t}\n\t\t\n\t\tint retx = 1, rety = 1;\n\t\tint[] dx = {0,1,0,-1};\n\t\tint[] dy = {1,0,-1,0};\n\t\twhile(true){\n\t\t\tboolean find = false;\n\t\t\tList<Integer> ps2 = new ArrayList<Integer>();\n\t\t\tfor(Integer p : ps){\n\t\t\t\tint i = p / 2001;\n\t\t\t\tint j = p % 2001;\n\t\t\t\tfor(int q = 0; q < 4; q++){\n\t\t\t\t\tint nx = i + dx[q];\n\t\t\t\t\tint ny = j + dy[q];\n\t\t\t\t\tif(in(nx,ny) && board[nx][ny] == 0){\n\t\t\t\t\t\tboard[nx][ny] = 1;\n\t\t\t\t\t\tretx = nx;\n\t\t\t\t\t\trety = ny;\n\t\t\t\t\t\tfind = true;\n\t\t\t\t\t\tps2.add(nx * 2001 + ny);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tboard[i][j] = 2;\n\t\t\t}\n\t\t\tps = ps2;\n\t\t\tif(!find) break;\n\t\t}\n\t\tout.println(retx + \" \" + rety);\n\t\tout.close();\n\t}\n\tpublic static boolean in(int i, int j){\n\t\treturn (1 <= i && i <= n) && (1 <= j && j <= m);\n\t}\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\t    \n\t\tString nextLine() {\n\t        try {\n\t            return br.readLine();\n\t        }\n\t        catch (Exception e) {\n\t            return null;\n\t        }\n\t    }\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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\n/**\n * Created by mostafa on 10/7/17.\n */\npublic class FireAgain {\n    static int n, m, k;\n    static int inf = (int) 1e9;\n    static class Pair {\n        int x, y;\n        Pair(int a, int b) {\n            x = a; y = b;\n        }\n    }\n    static int[] dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};\n    static boolean valid(int x, int y) {\n        return x >= 0 && x < n && y >= 0 && y < m;\n    }\n    static int[][] bfs(int[] xs, int[] ys) {\n        int[][] dist = new int[n][m];\n        for(int i = 0; i < n; i++)\n            Arrays.fill(dist[i], inf);\n        Queue<Pair> q = new LinkedList<>();\n        for(int i = 0; i < k; i++) {\n            dist[xs[i]][ys[i]] = 0;\n            q.add(new Pair(xs[i], ys[i]));\n        }\n\n        while(!q.isEmpty()) {\n            Pair p = q.remove();\n            for(int d = 0; d < 4; d++) {\n                int nx = p.x + dx[d], ny = p.y + dy[d];\n                if(valid(nx, ny) && dist[nx][ny] == inf) {\n                    dist[nx][ny] = dist[p.x][p.y] + 1;\n                    q.add(new Pair(nx, ny));\n                }\n            }\n        }\n\n        return dist;\n    }\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner();\n        n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt();\n        int[] xs = new int[k], ys = new int[k];\n        for(int i = 0; i < k; i++) {\n            xs[i] = sc.nextInt() - 1; ys[i] = sc.nextInt() - 1;\n        }\n\n        int[][] dist = bfs(xs, ys);\n\n        int x = 0, y = 0;\n        for(int i = 0; i < n; i++)\n            for(int j = 0; j < m; j++)\n                if(dist[i][j] > dist[x][y]) {\n                    x = i; y = j;\n                }\n        x++; y++;\n        PrintWriter out = new PrintWriter(\"output.txt\");\n        out.println(x + \" \" + y);\n        out.flush();\n        out.close();\n    }\n\n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n        Scanner() throws FileNotFoundException {\n            br = new BufferedReader(new FileReader(\"input.txt\"));\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}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "    import java.awt.Point;\nimport java.io.*;\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 = false;\n            final String inFile = \"input.txt\";\n            final String outFile = \"output.txt\";\n            \n            int n,m,k;\n            int[][] field;\n            boolean[][] visited;\n            \n            LinkedList<Point> queue;\n            int[][] steps = {{0,1},{1,0},{0,-1},{-1,0}};\n            \n            void wave() {\n                for(Point p:queue)\n                    visited[p.y][p.x] = true;\n                \n                while(!queue.isEmpty()) {\n                    Point cur = queue.removeFirst();\n                    for(int i = 0; i < steps.length; ++i) {\n                        Point tmp = new Point(cur.x+steps[i][0],cur.y+steps[i][1]);\n                        \n                        if(ok(tmp)&&!visited[tmp.y][tmp.x]) {\n                            queue.add(tmp);\n                            visited[tmp.y][tmp.x] = true;\n                            field[tmp.y][tmp.x] = field[cur.y][cur.x]+1;\n                        }\n                    }\n                }\n            }\n            \n            boolean ok(Point p) { \n                return p.x>=0 && p.y>=0 && p.x<n && p.y<m;\n            }\n            \n            @Override\n            public void run() {\n                n = nextInt();\n                m = nextInt();\n                k = nextInt();\n                \n                queue = new LinkedList<Point>();\n                for(int i = 0; i < k; ++i) \n                    queue.add(new Point(nextInt()-1,nextInt()-1));\n                \n                field = new int[m][n];\n                visited = new boolean[m][n];\n                wave();\n                \n                Point maxP = new Point(0,0);\n                int maxV = Integer.MIN_VALUE;\n                \n                for(int i = 0; i < m; ++i)\n                    for(int j = 0; j < n; ++j) \n                        if(field[i][j] > maxV) {\n                            maxV = field[i][j];\n                            maxP = new Point(j,i);\n                        }\n                \n                print((maxP.x+1)+\" \"+(maxP.y+1));\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<A, B> {\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<A, B> 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    }", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.FileInputStream;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.Collection;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.FileInputStream;\nimport java.util.ArrayList;\nimport java.util.Objects;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Queue;\nimport java.util.LinkedList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream;\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        OutputWriter out = new OutputWriter(outputStream);\n        CFireAgain solver = new CFireAgain();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class CFireAgain {\n        private int n;\n        private int m;\n        private int K;\n        private boolean[][] vis;\n        private Queue<Util.Pair<Integer>> queue = new LinkedList<>();\n        private Util.Pair<Integer> p;\n\n        private boolean isValid(int x, int y) {\n            return x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y];\n        }\n\n        private void bfs() {\n            while (!queue.isEmpty()) {\n                p = queue.poll();\n                if (isValid(p.x + 1, p.y)) {\n                    queue.offer(new Util.Pair<>(p.x + 1, p.y));\n                    vis[p.x + 1][p.y] = true;\n                }\n                if (isValid(p.x - 1, p.y)) {\n                    queue.offer(new Util.Pair<>(p.x - 1, p.y));\n                    vis[p.x - 1][p.y] = true;\n                }\n                if (isValid(p.x, p.y + 1)) {\n                    queue.offer(new Util.Pair<>(p.x, p.y + 1));\n                    vis[p.x][p.y + 1] = true;\n                }\n                if (isValid(p.x, p.y - 1)) {\n                    queue.offer(new Util.Pair<>(p.x, p.y - 1));\n                    vis[p.x][p.y - 1] = true;\n                }\n            }\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.nextInt();\n            m = in.nextInt();\n            K = in.nextInt();\n            vis = new boolean[n + 1][m + 1];\n            for (int i = 0; i < K; i++) {\n                int a = in.nextInt(), b = in.nextInt();\n                vis[a][b] = true;\n                queue.offer(new Util.Pair<>(a, b));\n            }\n            bfs();\n            out.println(p.x + \" \" + p.y);\n            out.flush();\n        }\n\n    }\n\n    static class OutputWriter {\n        private final PrintWriter writer;\n        private ArrayList<String> res = new ArrayList<>();\n        private StringBuilder sb = new StringBuilder(\"\");\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                sb.append(objects[i]);\n            }\n            res.add(sb.toString());\n            sb = new StringBuilder(\"\");\n        }\n\n        public void close() {\n//        writer.flush();\n            writer.close();\n        }\n\n        public void flush() {\n            for (String str : res) writer.printf(\"%s\\n\", str);\n            res.clear();\n            sb = new StringBuilder(\"\");\n        }\n\n    }\n\n    static class Util {\n        public static class Pair<T> {\n            public T x;\n            public T y;\n\n            public Pair(T x, T y) {\n                this.x = x;\n                this.y = y;\n            }\n\n            public boolean equals(Object obj) {\n                if (obj == this) return true;\n                if (!(obj instanceof Util.Pair)) return false;\n                Util.Pair<T> pair = (Util.Pair<T>) obj;\n                return this.x == pair.x && this.y == pair.y;\n            }\n\n            public String toString() {\n                return (\"(\" + this.x + \",\" + this.y + \")\");\n            }\n\n            public int hashCode() {\n                return Objects.hash(x, y);\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int numChars;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public InputReader(FileInputStream file) {\n            this.stream = file;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public 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 = (res << 3) + (res << 1) + c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        private boolean isSpaceChar(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Contest35_3 {\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new FileReader(\"input.txt\"));\n        String[] s = in.readLine().split(\" \");\n        int n = Integer.parseInt(s[0]);\n        int m = Integer.parseInt(s[1]);\n        int k = Integer.parseInt(in.readLine());\n        s = in.readLine().split(\" \");\n        Point[] inp = new Point[k];\n        int p = 0;\n        for (int i = 0; i < k; i++) {\n            inp[i] = new Point(Integer.parseInt(s[p++]),\n                    Integer.parseInt(s[p++]));\n        }\n        int max = -1;\n        int maxx = -1;\n        int maxy = -1;\n        int i;\n        int j, dist;\n        for (i = 1; i <= n; i++) {\n            for (j = 1; j <= m; j++) {\n                dist = 1000000;\n                for (int l = 0; l < inp.length; l++) {\n                    dist = Math.min(\n                            Math.abs(inp[l].x - i) + Math.abs(inp[l].y - j),\n                            dist);\n                }\n                if (dist > max) {\n                    max = dist;\n                    maxx = i;\n                    maxy = j;\n                }\n            }\n        }\n        String res = maxx + \" \" + maxy + \"\\n\";\n        FileWriter out = new FileWriter(new File(\"output.txt\"));\n        out.append(res);\n        out.flush();\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 9/16/11\n * Time: 1:27 PM\n * To change this template use File | Settings | File Templates.\n */\n\n\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.ArrayDeque;\nimport java.util.HashSet;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class TaskC extends Thread {\n    public TaskC() {\n        try {\n            this.input = new BufferedReader(new FileReader(\"input.txt\"));\n            this.output = new PrintWriter(\"output.txt\");\n            this.setPriority(Thread.MAX_PRIORITY);\n        } catch (Throwable e) {\n            System.exit(666);\n        }\n    }\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        Queue<Integer> qX = new ArrayDeque<Integer>();\n        Queue<Integer> qY = new ArrayDeque<Integer>();\n        boolean [][]was = new boolean[n][m];\n        for (int i = 0; i < k; ++i) {\n            int x = nextInt() - 1, y = nextInt() - 1;\n            qX.add(x);\n            qY.add(y);\n            was[x][y] = true;\n        }\n        int lastX = -1, lastY = -1;\n        while (!qX.isEmpty()) {\n            lastX = qX.poll();\n            lastY = qY.poll();\n            for (int i = 0; i < dx.length; ++i) {\n                int nextX = lastX + dx[i], nextY = lastY + dy[i];\n                if (nextX < n && nextY < m && nextX >= 0 && nextY >= 0 && !was[nextX][nextY]) {\n                    qX.add(nextX);\n                    qY.add(nextY);\n                    was[nextX][nextY] = true;\n                }\n            }\n        }\n        ++lastX;\n        ++lastY;\n        output.println(lastX + \" \" + lastY);\n\n\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().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    static final int PRIME = 3119;\n    static final int[]dx = {1, -1, 0, 0}, dy = {0, 0, -1, 1};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class incendio {\n    void dbg(Object...os) { System.err.println(Arrays.deepToString(os)); }\n    static StringTokenizer _stk; static BufferedReader input; static PrintWriter output; \n    static String next(){return _stk.nextToken();} static int nextInt(){return Integer.parseInt(next());}\n    static String readln()throws IOException {String l=input.readLine();_stk=l==null?null:new StringTokenizer(l,\" \");return l;}\n    public static void main(String[] args) throws IOException {\n        input = new BufferedReader(new FileReader(\"input.txt\")); \n        output = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n        new incendio();\n        output.close();\n    }\n\n    \n    incendio() throws IOException {\n        readln();\n        M = nextInt(); N = nextInt();\n        readln();\n        final int K = nextInt();\n        int xf[]=new int[K], yf[]=new int[K];\n        readln();\n        for(int i=0; i<K; i++) {\n            xf[i]=nextInt();\n            yf[i]=nextInt();\n        }\n        \n        int best=-1, xbest=0, ybest=0;\n        for(int i=1; i<=M; i++) {\n            for(int j=1; j<=N; j++) {\n                int dist=Integer.MAX_VALUE;\n                for(int k=0; k<K; k++) {\n                    dist = Math.min(dist, Math.abs(i-xf[k])+Math.abs(j-yf[k]));\n                }\n                if(dist>best) {\n                    best=dist;\n                    xbest=i;\n                    ybest=j;\n                }\n            }\n        }\n        output.println(xbest+\" \"+ybest);\n    }\n    \n    int M, N;\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    InputStream is;\n    PrintWriter out;\n    String INPUT = \"\";\n    \n    long MAX = 100000L, MOD = 1000000007L, INF = (long) 1e18;\n    \n    boolean isValid(int x, int y, int n, int m){\n        return x>=0 && y>=0 && x<n && y<m;\n    }\n    \n    void solve(int TC) throws Exception {\n        helper hp = new helper(MOD, (int)MAX);\n        hp.initIO(\"input.txt\", \"output.txt\");\n        int n = hp.nextInt(), m = hp.nextInt();\n        boolean[][] a = new boolean[n][m];\n        int k = hp.nextInt();\n        ArrayDeque<int[]> q = new ArrayDeque<>();\n        for(int i=0;i<k;i++){\n            int x = hp.nextInt() - 1;\n            int y = hp.nextInt() - 1;\n            a[x][y] = true;\n            q.add(new int[]{x,y});\n        }\n        int lastX = 0,lastY = 0;\n        int[] dx = new int[]{1,-1,0,0};\n        int[] dy = new int[]{0,0,1,-1};\n        while(!q.isEmpty()){\n            int[] X = q.pollFirst();\n            for(int i=0;i<4;i++){\n                int x = X[0] + dx[i];\n                int y = X[1] + dy[i];\n                if(isValid(x,y,n,m) && !a[x][y]){\n                    a[x][y] = true;\n                    lastX = x;\n                    lastY = y;\n                    q.add(new int[]{x,y});\n                }\n            }\n        }\n        hp.println((lastX+1) + \" \" + (lastY+1)); hp.flush();\n    }\n    \n    boolean TestCases = false;\n    public static void main(String[] args) throws Exception { new Main().run(); }\n    \n    void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n    static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}\n    \n    void run() throws Exception {\n        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n        out = new PrintWriter(System.out);\n        long s = System.currentTimeMillis();\n        int T = TestCases ? ni() : 1;\n        for(int t=1;t<=T;t++) solve(t);\n        out.flush();\n        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n    }\n    \n    void p(Object o) { out.print(o); }\n    void pn(Object o) { out.println(o); }\n    void pni(Object o) { out.println(o);out.flush(); }\n    double PI = 3.141592653589793238462643383279502884197169399;\n    \n    int ni() {\n        int num = 0, b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-') {\n            minus = true;\n            b = readByte();\n        }\n        while(true) {\n            if(b >= '0' && b <= '9'){\n                num = num * 10 + (b - '0');\n            } else {\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    long nl() {\n        long num = 0;\n        int b;\n        boolean minus = false;\n        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n        if(b == '-') {\n            minus = true;\n            b = readByte();\n        }\n        while(true) {\n            if(b >= '0' && b <= '9') {\n                num = num * 10 + (b - '0');\n            } else {\n                return minus ? -num : num;\n            }\n            b = readByte();\n        }\n    }\n    \n    double nd() { return Double.parseDouble(ns()); }\n    char nc() { return (char)skip(); }\n    \n    int BUF_SIZE = 1024 * 8;\n    byte[] inbuf = new byte[BUF_SIZE];\n    int lenbuf = 0, ptrbuf = 0;\n    \n    int readByte() {\n        if(lenbuf == -1)throw new InputMismatchException();\n        if(ptrbuf >= lenbuf){\n            ptrbuf = 0;\n            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n            if(lenbuf <= 0)return -1;\n        } return inbuf[ptrbuf++];\n    }\n    \n    boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n    int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n    \n    String ns() {\n        int b = skip();\n        StringBuilder sb = new StringBuilder();\n        while(!(isSpaceChar(b))) {\n            sb.appendCodePoint(b); b = readByte();\n        } return sb.toString();\n    }\n    \n    char[] ns(int n) {\n        char[] buf = new char[n];\n        int b = skip(), p = 0;\n        while(p < n && !(isSpaceChar(b))){\n            buf[p++] = (char)b;\n            b = readByte();\n        } return n == p ? buf : Arrays.copyOf(buf, p);\n    }\n    \n    void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}\n\n\nclass helper {\n    final long MOD;\n    final int MAXN;\n    final Random rnd;\n\n    public helper(long mod, int maxn) {\n        MOD = mod;\n        MAXN = maxn;\n        rnd = new Random();\n    }\n\t\n    static final int BUFSIZE = 1 << 20;\n    static byte[] buf;\n    static int index, total;\n    static InputStream in;\n    static BufferedWriter bw;\n\n\n    public void initIO(InputStream is, OutputStream os) {\n        try {\n            in = is;\n            bw = new BufferedWriter(new OutputStreamWriter(os));\n            buf = new byte[BUFSIZE];\n        } catch (Exception e) {\n        }\n    }\n\n    public void initIO(String inputFile, String outputFile) {\n        try {\n            in = new FileInputStream(inputFile);\n            bw = new BufferedWriter(new OutputStreamWriter(\n                    new FileOutputStream(outputFile)));\n            buf = new byte[BUFSIZE];\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n    \n    private int scan() throws Exception {\n        if (index >= total) {\n            index = 0;\n            total = in.read(buf);\n            if (total <= 0)\n                return -1;\n        }\n        return buf[index++];\n    }\n\n    public String next() throws Exception {\n        int c;\n        for (c = scan(); c <= 32; c = scan()) ;\n        StringBuilder sb = new StringBuilder();\n        for (; c > 32; c = scan())\n            sb.append((char) c);\n        return sb.toString();\n    }\n\n    public int nextInt() throws Exception {\n        int c, val = 0;\n        for (c = scan(); c <= 32; c = scan()) ;\n        boolean neg = c == '-';\n        if (c == '-' || c == '+')\n            c = scan();\n        for (; c >= '0' && c <= '9'; c = scan())\n            val = (val << 3) + (val << 1) + (c & 15);\n        return neg ? -val : val;\n    }\n\n    public long nextLong() throws Exception {\n        int c;\n        long val = 0;\n        for (c = scan(); c <= 32; c = scan()) ;\n        boolean neg = c == '-';\n        if (c == '-' || c == '+')\n            c = scan();\n        for (; c >= '0' && c <= '9'; c = scan())\n            val = (val << 3) + (val << 1) + (c & 15);\n        return neg ? -val : val;\n    }\n    \n    public long pow(long base, long exp, long MOD) {\n        base %= MOD;\n        long ret = 1;\n        while (exp > 0) {\n            if ((exp & 1) == 1) ret = ret * base % MOD;\n            base = base * base % MOD;\n            exp >>= 1;\n        }\n        return ret;\n    }\n    \n    public void println(Object a) throws Exception {\n        bw.write(a.toString()+\"\\n\");\n    }\n    public void print(Object a) throws Exception {\n        bw.write(a.toString());\n    }\n    public void flush() throws Exception {\n        bw.flush();\n    }\n    \n    public static int[] sieve;\n    public static ArrayList<Integer> primes;\n    \n    public void setSieve() {\n        primes = new ArrayList<>();\n        sieve = new int[MAXN];\n        int i, j;\n        for (i = 2; i < MAXN; ++i)\n            if (sieve[i] == 0) {\n                primes.add(i);\n                for (j = i; j < MAXN; j += i) {\n                    sieve[j] = i;\n                }\n            }\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n\n\tScanner input;\n\tPrintWriter output;\n\t\n\tprivate void solve() throws Exception\n\t{\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint k = nextInt();\n\t\tint[] r = new int[k];\n\t\tint[] c = new int[k];\n\t\tfor (int i = 0; i < k; i++)\n\t\t{\n\t\t\tr[i] = nextInt();\n\t\t\tc[i] = nextInt();\n\t\t}\n\t\tint best = -1;\n\t\tint bestr = -1;\n\t\tint bestc = -1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t{\n\t\t\tfor (int j = 1; j <= m; j++)\n\t\t\t{\n\t\t\t\tint d = n + m;\n\t\t\t\tfor (int q = 0; q < k; q++)\n\t\t\t\t{\n\t\t\t\t\td = Math.min(d, Math.abs(i - r[q]) + Math.abs(j - c[q]));\n\t\t\t\t}\n\t\t\t\tif (d < best) continue;\n\t\t\t\tbest = d;\n\t\t\t\tbestr = i;\n\t\t\t\tbestc = j;\n\t\t\t}\n\t\t}\n\t\tout(bestr + \" \" + bestc);\n\t}\n\n\tprivate int nextInt() throws Exception\n\t{\n\t\treturn input.nextInt();\n\t}\n\t\n\tprivate void out(String s)\n\t{\n\t\toutput.println(s);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolve();\n\t\t} catch (Exception ex) {\n\t\t\tthrow new RuntimeException(ex);\n\t\t} finally {\n\t\t\toutput.close();\n\t\t}\n\t}\n\t\n\tpublic Solution() throws IOException {\n\t\tinput = new Scanner(new FileReader(\"input.txt\"));\n\t\toutput = new PrintWriter(\"output.txt\");\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tLocale.setDefault(Locale.US);\n\t\tnew Thread(new Solution()).start();\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport 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.io.UnsupportedEncodingException;\nimport java.net.URISyntaxException;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    public static void main(String[] args)throws IOException, URISyntaxException {\n        Reader.init(new FileInputStream(\"input.txt\"));\n        StringBuilder s=new StringBuilder();\n        boolean[][]vis=new boolean[Reader.nextInt()][Reader.nextInt()];\n        int k=Reader.nextInt(),r,c;\n        Queue<Point>q=new LinkedList<Point>();\n        while(k-->0) {\n            r=Reader.nextInt()-1;\n            c=Reader.nextInt()-1;\n            vis[r][c]=true;\n            q.add(new Point(r,c));\n        }\n        Point end=null;\n        int[]x={0,0,1,-1},y={1,-1,0,0};\n        int a,b,i;\n        while(!q.isEmpty()) {\n            end=q.poll();\n            for(i=0;i<4;i++) {\n                a=end.x+x[i];\n                b=end.y+y[i];\n                if(a>=0&&b>=0&&a<vis.length&&b<vis[a].length&&!vis[a][b]) {\n                    vis[a][b]=true;\n                    q.add(new Point(a,b));\n                }\n            }\n        }\n        s.append(end.x+1).append(' ').append(end.y+1);\n        PrintWriter p=new PrintWriter(\"output.txt\");\n        p.println(s);\n        p.close();\n    }\n}\n\nclass Reader {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) throws UnsupportedEncodingException {\n        reader = new BufferedReader(\n                     new InputStreamReader(input, \"UTF-8\") );\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 String nextLine() throws IOException {\n        return reader.readLine();\n    }\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    \n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n    \n    static long nextLong() throws IOException {\n        return Long.parseLong( next() );\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class C {\n    static class Struct {\n        int x, y, count;\n\n        public Struct(int xx, int yy, int c) {\n            x = xx;\n            y = yy;\n            count = c;\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(new FileReader(\"input.txt\"));\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        FileWriter fw=new FileWriter(\"output.txt\");\n        boolean[][] grid = new boolean[n][m];\n        int[] dx = new int[] { 1, 0, -1, 0 };\n        int[] dy = new int[] { 0, -1, 0, 1 };\n        int k = sc.nextInt();\n        LinkedList<Struct> a = new LinkedList<Struct>();\n        for (int i = 0; i < k; i++) {\n            a.add(new Struct(sc.nextInt() - 1, sc.nextInt() - 1, 0));\n        }\n        int max = Integer.MIN_VALUE, maxX = -1, maxY = -1;\n        while (!a.isEmpty()) {\n            Struct tmp = a.remove();\n            if (grid[tmp.x][tmp.y] == true)\n                continue;\n            grid[tmp.x][tmp.y] = true;\n            if (tmp.count > max) {\n                max = tmp.count;\n                maxX = tmp.x;\n                maxY = tmp.y;\n            }\n            for (int i = 0; i < 4; i++) {\n                int nx = tmp.x + dx[i];\n                int ny = tmp.y + dy[i];\n                if (nx < n && nx >= 0 && ny < m && ny >= 0) {\n                    if (grid[nx][ny] == false) {\n                        a.add(new Struct(nx, ny, tmp.count + 1));\n                    }\n                }\n            }\n        }\n        fw.write((maxX + 1) + \" \" + (maxY + 1)+\"\\n\");\n        System.out.println((maxX + 1) + \" \" + (maxY + 1));\n        fw.flush();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.ArrayDeque;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author MaxHeap\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        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        FireAgain solver = new FireAgain();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class FireAgain {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            int k = in.nextInt();\n            int INF = 10000000;\n            int[][] g = new int[n][m];\n            for (int[] temp : g) Arrays.fill(temp, -1);\n            ArrayDeque<IntPair> q = new ArrayDeque<>();\n            for (int i = 0; i < k; i++) {\n                int x = in.nextInt() - 1;\n                int y = in.nextInt() - 1;\n                g[x][y] = 0;\n                q.add(new IntPair(x, y));\n            }\n            while (!q.isEmpty()) {\n                IntPair cur = q.poll();\n                int x = cur.getFirst();\n                int y = cur.getSecond();\n                for (int i = -1; i <= 1; i++) {\n                    for (int j = -1; j <= 1; j++) {\n                        if (i == 0 && j == 0 || Math.abs(i) + Math.abs(j) != 1) continue;\n                        int xx = x + i;\n                        int yy = y + j;\n                        if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;\n                        if (g[xx][yy] != -1) continue;\n                        g[xx][yy] = g[x][y] + 1;\n                        q.add(new IntPair(xx, yy));\n                    }\n                }\n            }\n            int ans = 0, x = -1, y = -1;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    if (g[i][j] >= ans) {\n                        ans = g[i][j];\n                        x = i + 1;\n                        y = j + 1;\n                    }\n                }\n            }\n            out.println(x + \" \" + y);\n        }\n\n    }\n\n    static class IntPair implements Comparable<IntPair> {\n        int first;\n        int second;\n\n        public IntPair(int first, int second) {\n            this.first = first;\n            this.second = second;\n        }\n\n\n        public int compareTo(IntPair a) {\n            if (second == a.second) {\n                return Integer.compare(first, a.first);\n            }\n            return Integer.compare(second, a.second);\n        }\n\n\n        public String toString() {\n            return \"<\" + first + \", \" + 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\n            IntPair a = (IntPair) o;\n\n            if (first != a.first) return false;\n            return second == a.second;\n        }\n\n\n        public int hashCode() {\n            int result = first;\n            result = 31 * result + second;\n            return result;\n        }\n\n        public int getFirst() {\n            return first;\n        }\n\n        public int getSecond() {\n            return second;\n        }\n\n    }\n\n    static class FastReader {\n        BufferedReader reader;\n        StringTokenizer st;\n\n        public FastReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            st = null;\n        }\n\n        public String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String line = reader.readLine();\n                    if (line == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(line);\n                } catch (Exception e) {\n                    throw new RuntimeException();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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\tint N;\n\tint M;\n\tboolean[][] used;\n\tQueue<Integer> queue;\n\t\n\tint[] dx = { -1, 0, 1, 0 };\n\tint[] dy = { 0, -1, 0, 1 };\n\tint ans = -1;\n\t\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(\"output.txt\");\n\t\t\n\t\tN = nextInt();\n\t\tM = nextInt();\n\t\tused = new boolean [N][M];\n\t\tqueue = new ArrayDeque<Integer> (N * M);\n\t\tfor (int K = nextInt(); K --> 0; )\n\t\t\taddState(nextInt() - 1, nextInt() - 1);\n\t\twhile (!queue.isEmpty()) {\n\t\t\tint cv = queue.poll();\n\t\t\tint cx = cv / M;\n\t\t\tint cy = cv % M;\n\t\t\tfor (int d = 0; d < dx.length; d++) {\n\t\t\t\tint nx = cx + dx[d];\n\t\t\t\tint ny = cy + dy[d];\n\t\t\t\tif (0 <= nx && nx < N && 0 <= ny && ny < M && !used[nx][ny])\n\t\t\t\t\taddState(nx, ny);\n\t\t\t}\n\t\t}\n\t\tout.println((1 + ans / M) + \" \" + (1 + ans % M));\n\t\tout.close();\n\t}\n\t\n\tvoid addState(int x, int y) {\n\t\tused[x][y] = true;\n\t\tqueue.add(ans = code(x, y));\n\t}\n\n\tint code(int x, int y) {\n\t\treturn x * M + y;\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\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\t\n\t\t\tif (s == null) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "// package Practice1.CF35;\n\nimport java.io.*;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class CF035C {\n    public static void main(String[] args) throws IOException {\n        Scanner s = new Scanner(new File(\"input.txt\")/*System.in*/);\n        int n = s.nextInt();\n        int m = s.nextInt();\n        int k = s.nextInt();\n//        pair[] arr = new pair[n];\n        Queue<pair> q = new LinkedList<>();\n        PrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n        boolean[][] visited = new boolean[n][m];\n        for (int i = 0; i < k; i++) {\n            int x = s.nextInt() - 1;\n            int y  = s.nextInt() - 1;\n            visited[x][y] = true;\n            pair p = new pair(x,y);\n//            arr[i] = p;\n            q.add(p);\n        }\n\n        q.add(null);\n        int[] dx = {0,0,1,-1};\n        int[] dy = {1,-1,0,0};\n        int ansX = q.peek().x;\n        int ansY = q.peek().y;\n        while(true){\n            if(q.peek() == null){\n                q.poll();\n                q.add(null);\n            }\n            pair p = q.poll();\n            if(p == null){\n                break;\n            }\n            for (int i = 0; i < 4; i++) {\n                if(isValid(p.x + dx[i],p.y+dy[i],n,m) && !visited[p.x + dx[i]][p.y+dy[i]]){\n                    q.add(new pair(p.x + dx[i],p.y+dy[i]));\n                    ansX = p.x + dx[i];\n                    ansY = p.y + dy[i];\n                    visited[ansX][ansY] = true;\n                }\n            }\n        }\n        out.println((ansX+1) + \" \" + (ansY+1));\n        out.close();\n\n    }\n\n    public static boolean isValid(int x, int y,int n, int m){\n        return x >= 0 && x < n && y >= 0 && y < m;\n    }\n\n    private static class pair{\n        int x;\n        int y;\n\n        public pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class SolutionC{\n\tpublic static void main(String[] args) throws Exception{\n\t\tScanner sc = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter output = new PrintWriter(\"output.txt\");\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tint[] x = new int[K];\n\t\tint[] y = new int[K];\n\t\tfor(int i = 0 ; i < K ; i++){\n\t\t\tx[i] = sc.nextInt();\n\t\t\ty[i] = sc.nextInt();\n\t\t}\n\t\tint max = -1, max_x = -1, max_y = -1;\n\t\tfor(int i = 1 ; i <= N ; i++){\n\t\t\tfor(int j = 1 ; j <= M ; j++){\n\t\t\t\tint min = Integer.MAX_VALUE;\n\t\t\t\tfor(int k = 0 ; k < K ; k++){\n\t\t\t\t\tmin = Math.min(min, Math.abs(x[k] - i) + Math.abs(y[k] - j));\n\t\t\t\t}\n\t\t\t\tif(min > max){\n\t\t\t\t\tmax = min;\n\t\t\t\t\tmax_x = i;\n\t\t\t\t\tmax_y = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput.println(max_x + \" \" + max_y);\n\t\toutput.flush();\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class j\n{\npublic static void main(String a[])throws IOException\n{\nBufferedReader b = new BufferedReader(new FileReader(\"input.txt\"));\nPrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\nint l=0,x2=0,x=0,y1=0,y=0,max=-1,min=100000,x1=0,n=0,j=0,k=0,p=0,m=0,i=0;\nString s;\ns=b.readLine();\nStringTokenizer c=new StringTokenizer(s);\nn=Integer.parseInt(c.nextToken());\nm=Integer.parseInt(c.nextToken());\nk=Integer.parseInt(b.readLine());\nint e[][]=new int[k][2];\ns=b.readLine();\nStringTokenizer z=new StringTokenizer(s);\nfor(i=0;i<k;i++)\n{\ne[i][0]=Integer.parseInt(z.nextToken());\ne[i][1]=Integer.parseInt(z.nextToken());\n}\nfor(i=1;i<=n;i++)\n{\nfor(j=1;j<=m;j++)\n{\nfor(l=0;l<k;l++)\n{\np=(int)Math.abs(e[l][0]-i)+(int)Math.abs(e[l][1]-j);\nif(p<min)\n{\nmin=p;\nx1=i;\ny1=j;\n}\n}\nif(min>max)\n{\nmax=min;\nx=x1;\ny=y1;\n}\nmin=100000;\n}\n}\nout.print(x+\" \"+y);\nout.close();\n}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class C {\n    public static void main(String[] args) throws FileNotFoundException {\n        Scanner in = new Scanner(new FileReader(new File(\"input.txt\")));\n        PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int[][] T = new int[n][m];\n        int k = in.nextInt();\n        int[] X = new int[k];\n        int[] Y = new int[k];\n        for (int i = 0; i < k; i++) {\n            X[i] = in.nextInt() - 1;\n            Y[i] = in.nextInt() - 1;\n        }\n        int max = 0;\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++) {\n                int min = Integer.MAX_VALUE;\n                for (int ii = 0; ii < k; ii++)\n                    min = Math.min(min,\n                            Math.abs(i - X[ii]) + Math.abs(j - Y[ii]));\n                max = Math.max(max, T[i][j] = min);\n            }\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++)\n                if (T[i][j] == max) {\n                    out.println((i + 1) + \" \" + (j + 1));\n                    out.flush();\n                    return;\n                }\n\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Queue;\nimport java.util.concurrent.ArrayBlockingQueue;\n\npublic class ProblemC {\n\t\n\tstatic int[] dx = {1, 0, 0, -1};\n\tstatic int[] dy = {0, 1, -1, 0};\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n//\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n//\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tString[] nm = s.readLine().split(\" \");\n\t\tint n = Integer.valueOf(nm[0]);\n\t\tint m = Integer.valueOf(nm[1]);\n\t\tint k = Integer.valueOf(s.readLine());\n\t\t\n\t\tint[][] dp = new int[n][m];\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tArrays.fill(dp[i], Integer.MAX_VALUE);\n\t\t}\n\t\tString[] st = s.readLine().split(\" \");\n\t\tint[][] trees = new int[k][2];\n\t\tfor (int l = 0 ; l < k ; l++) {\n\t\t\ttrees[l][0] = Integer.valueOf(st[l*2])-1;\n\t\t\ttrees[l][1] = Integer.valueOf(st[l*2+1])-1;\n\t\t}\n\t\t\n\t\tint maxtime = -1;\n\t\tint max_x = -1;\n\t\tint max_y = -1;\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tfor (int j = 0 ; j < m ; j++) {\n\t\t\t\tint minDist = n+m;\n\t\t\t\tfor (int l = 0 ; l < k ; l++) {\n\t\t\t\t\tminDist = Math.min(minDist, Math.abs(i - trees[l][0]) + Math.abs(j - trees[l][1]));\n\t\t\t\t}\n\t\t\t\tif (maxtime < minDist) {\n\t\t\t\t\tmaxtime = minDist;\n\t\t\t\t\tmax_x = i+1;\n\t\t\t\t\tmax_y = j+1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\tout.println(max_x + \" \" + max_y);\n\t\tout.flush();\n\t}\n\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\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\n    String readString() {\n        while (!tok.hasMoreTokens()) {\n            try {\n                tok = new StringTokenizer(in.readLine());\n            } catch (Exception e) {\n                return null;\n            }\n        }\n        return tok.nextToken();\n    }\n\n    int readInt() {\n        return Integer.parseInt(readString());\n    }\n\n    long readLong() {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() {\n        return Double.parseDouble(readString());\n    }\n\n    int[] readIntArray(int size) {\n        int[] a = new int[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = readInt();\n        }\n        return a;\n    }\n\n    public static void main(String[] args) {\n        //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n        new Problem().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\n    int[][] dist;\n    int n, m;\n    P v;\n    ArrayDeque<P> q = new ArrayDeque<>();\n\n    private void solve() throws IOException {\n        n = readInt();\n        m = readInt();\n        int k = readInt();\n        dist = new int[n][m];\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++)\n                dist[i][j] = -1;\n        for (int i = 0; i < k; i++) {\n            int x = readInt() - 1, y = readInt() - 1;\n            dist[x][y] = 0;\n            q.add(new P(x, y));\n        }\n        bfs();\n        out.println(v.x + 1 + \" \" + (v.y + 1));\n    }\n\n    public void bfs() {\n        int[] dx = {0, 1, 0, -1};\n        int[] dy = {1, 0, -1, 0};\n        while (!q.isEmpty()) {\n            v = q.poll();\n            for (int i = 0; i < 4; i++) {\n                int nx = v.x + dx[i];\n                int ny = v.y + dy[i];\n                if (inside(nx, ny) && dist[nx][ny] == -1) {\n                    q.add(new P(nx, ny));\n                    dist[nx][ny] = dist[v.x][v.y] + 1;\n                }\n            }\n        }\n    }\n\n    public boolean inside(int x, int y) {\n        if (x < n && y < m && x >= 0 && y >= 0) {\n            return true;\n        }\n        return false;\n    }\n}\n\nclass P {\n    int x, y;\n\n    public P(int x, int y) {\n        this.x = x;\n        this.y = y;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import javax.annotation.processing.SupportedSourceVersion;\nimport java.io.*;\nimport java.util.*;\nimport java.util.regex.Matcher;\n\npublic class Main {\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(new FileReader(\"input.txt\")); // new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(\"output.txt\"); //new PrintWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(in, out);\n        out.close();\n    }\n\n    private static class TaskB {\n\n        static final long max = 1000000000000000000L;\n        static final double eps = 0.0000001;\n        static final long mod = 1000000007;\n        static int N, M, K;\n        static long X, Y;\n        static boolean F[][][];\n        static int D[][];\n\n        void solve(InputReader in, PrintWriter out) throws IOException {\n\n            N = in.nextInt();\n            M = in.nextInt();\n            K = in.nextInt();\n\n            F = new boolean[K][N][M];\n            D = new int[N][M];\n\n            for (int i = 0; i < N; i++)\n                for (int j = 0; j < M; j++)\n                    D[i][j] = Integer.MAX_VALUE;\n\n            List<Pair> list = new ArrayList<>();\n\n            for (int i = 0; i < K; i++) {\n                list.add(new Pair(in.nextInt() - 1, in.nextInt() - 1));\n            }\n\n\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                        D[i][j] = Math.min(D[i][j], Math.abs(list.get(k).X - i) + Math.abs(list.get(k).Y - j));\n\n\n            int res = Integer.MIN_VALUE;\n            for (int j = 0; j < N; j++)\n                for (int k = 0; k < M; k++)\n                    if (D[j][k] > res) {\n                        X = j + 1;\n                        Y = k + 1;\n                        res = D[j][k];\n                    }\n\n            out.println(X + \" \" + Y);\n\n        }\n\n        void bfs(int K, Pair P) {\n\n            Queue<Pair> Q = new LinkedList<>();\n            F[K][P.X][P.Y] = true;\n            D[P.X][P.Y] = 0;\n            Q.add(P);\n\n\n            while (!Q.isEmpty()) {\n\n                P = Q.poll();\n                int X = P.X;\n                int Y = P.Y;\n\n                if (check(X - 1, Y) && !F[K][X - 1][Y]) {\n                    F[K][X - 1][Y] = true;\n                    if (D[X - 1][Y] > D[X][Y] + 1) {\n                        D[X - 1][Y] = D[X][Y] + 1;\n                        Q.add(new Pair(X - 1, Y));\n                    }\n                }\n\n                if (check(X + 1, Y) && !F[K][X + 1][Y]) {\n                    F[K][X + 1][Y] = true;\n                    if (D[X + 1][Y] > D[X][Y] + 1) {\n                        D[X + 1][Y] = D[X][Y] + 1;\n                        Q.add(new Pair(X + 1, Y));\n                    }\n                }\n\n                if (check(X, Y - 1) && !F[K][X][Y - 1]) {\n                    F[K][X][Y - 1] = true;\n                    if (D[X][Y - 1] > D[X][Y] + 1) {\n                        D[X][Y - 1] = D[X][Y] + 1;\n                        Q.add(new Pair(X, Y - 1));\n                    }\n                }\n\n                if (check(X, Y + 1) && !F[K][X][Y + 1]) {\n                    F[K][X][Y + 1] = true;\n                    if (D[X][Y + 1] > D[X][Y] + 1) {\n                        D[X][Y + 1] = D[X][Y] + 1;\n                        Q.add(new Pair(X, Y + 1));\n                    }\n                }\n\n            }\n\n        }\n\n        boolean check(int X, int Y) {\n            return !(X < 0 || X >= N || Y < 0 || Y >= M);\n        }\n\n        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        long gcd(long A, long B) {\n            if (B == 0) return A;\n            return gcd(B, A % B);\n        }\n\n        boolean isPrime(long n) {\n            if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))\n                return false;\n            for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)\n                if (n % i == 0)\n                    return false;\n            return true;\n        }\n\n        boolean isEqual(double A, double B) {\n            return Math.abs(A - B) < eps;\n        }\n\n        double dist(double X1, double Y1, double X2, double Y2) {\n            return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));\n        }\n\n        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        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    private static class InputReader {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public InputReader(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public InputReader(FileReader s) throws FileNotFoundException {\n            br = new BufferedReader(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            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public boolean ready() {\n            try {\n                return br.ready();\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main(String [] args) throws IOException{\n\t\tScanner in = new Scanner(new FileInputStream(\"input.txt\"));\n\t\t//Scanner in = new Scanner(System.in);\n\t\tFile file = new File(\"output.txt\");\n\t\tFileOutputStream fos = new FileOutputStream(file);\n\t\tif (!file.exists()) {\n\t\t     file.createNewFile();\n\t\t}\n\t\t\n\t\tint N = in.nextInt();\n\t\tint M = in.nextInt();\n\t\tint K = in.nextInt();\n\t\tint [][] fireTime = new int[N][M];\n\t\tfor (int i=0; i<K; i++){\n\t\t\tint x = in.nextInt()-1;\n\t\t\tint y = in.nextInt()-1;\n\t\t\tfireTime[x][y] = -1;\n\t\t\t\n\t\t\tfor (int j=1; j<=x+y; j++){\n\t\t\t\tfor (int p=0; p<=j; p++){\n\t\t\t\t\tif (x-j+p >= 0 && y-p >=0 && (fireTime[x-j+p][y-p] == 0 || fireTime[x-j+p][y-p] > j)){\n\t\t\t\t\t\tfireTime[x-j+p][y-p] = j;\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=1; j<=x+M-1-y; j++){\n\t\t\t\tfor (int p=0; p<=j; p++){\n\t\t\t\t\tif (x-j+p >= 0 && y+p < M && (fireTime[x-j+p][y+p] == 0 || fireTime[x-j+p][y+p] > j)){\n\t\t\t\t\t\tfireTime[x-j+p][y+p] = j;\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=1; j<=N-1-x+y; j++){\n\t\t\t\tfor (int p=0; p<j; p++){\n\t\t\t\t\tif (x+j-p < N && y-p >= 0 && (fireTime[x+j-p][y-p] == 0 || fireTime[x+j-p][y-p] > j)){\n\t\t\t\t\t\tfireTime[x+j-p][y-p] = j;\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=1; j<=N-1-x+M-1-y; j++){\n\t\t\t\tfor (int p=0; p<=j; p++){\n\t\t\t\t\t//System.out.println(j+\" \"+p);\n\t\t\t\t\tif (x+j-p < N && y+p < M && (fireTime[x+j-p][y+p] == 0 || fireTime[x+j-p][y+p] > j)){\n\t\t\t\t\t\t//System.out.println(j);\n\t\t\t\t\t\tfireTime[x+j-p][y+p] = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint max = -1;\n\t\tint tx = 1;\n\t\tint ty = 1;\n\t\tfor (int i=0; i<N; i++){\n\t\t\tfor (int j=0; j<M; j++){\n\t\t\t\t//System.out.print(fireTime[i][j]+\" \");\n\t\t\t\tif (fireTime[i][j] > max){\n\t\t\t\t\tmax = fireTime[i][j];\n\t\t\t\t\ttx = i+1;\n\t\t\t\t\tty = j+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//System.out.println();\n\t\t}\n\t\t//System.out.println(tx+\" \"+ty);\n\t\tString output = tx+\" \"+ty;\n\t\t\n\t\tbyte[] bA = output.getBytes();\n\t\tfos.write(bA);\n\t\tfos.flush();\n\t}\n}\n\n\t\t      \t \t\t\t   \t\t \t \t\t \t \t", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.Collection;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.FileInputStream;\nimport java.io.InputStreamReader;\nimport java.util.Objects;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Queue;\nimport java.util.LinkedList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Nafiur Rahman Khadem Shafin \ud83d\ude42\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\tProblemCFireAgain solver = new ProblemCFireAgain ();\n\t\tsolver.solve (1, in, out);\n\t\tout.close ();\n\t}\n\t\n\tstatic class ProblemCFireAgain {\n\t\tprivate static final byte[] dx = {-1, 0, 0, 1};\n\t\tprivate static final byte[] dy = {0, -1, 1, 0};\n\t\tprivate static int[][] lvl;\n\t\tprivate static int max;\n\t\tprivate static int n;\n\t\tprivate static int m;\n\t\tprivate static int k;\n\t\tprivate static ProblemCFireAgain.Pair[] bgn;\n\t\tprivate static ProblemCFireAgain.Pair res;\n\t\t\n\t\tprivate static void bfs2d () {\n\t\t\tQueue<ProblemCFireAgain.Pair> bfsq = new LinkedList<ProblemCFireAgain.Pair> ();\n\t\t\tfor (ProblemCFireAgain.Pair src : bgn) {\n\t\t\t\tlvl[src.a][src.b] = 0;\n\t\t\t\tbfsq.add (src);\n\t\t\t}\n\t\t\twhile (!bfsq.isEmpty ()) {\n\t\t\t\tProblemCFireAgain.Pair op = bfsq.poll ();\n\t\t\t\tint plvl = lvl[op.a][op.b];\n//\t\t\tSystem.out.println (\"ber hoise \"+op+\" \"+plvl);\n\t\t\t\tif (plvl>max) {\n\t\t\t\t\tres = op;\n\t\t\t\t\tmax = plvl;\n\t\t\t\t}\n\t\t\t\tfor (int i = 0; i<4; i++) {\n\t\t\t\t\tint newX = op.a+dx[i];\n\t\t\t\t\tint newY = op.b+dy[i];\n//\t\t\t\tSystem.out.println (newX+\" \"+newY+\" \"+n+\" \"+m);\n\t\t\t\t\tif (newX>0 && newX<=n && newY>0 && newY<=m && lvl[newX][newY] == -1) {\n\t\t\t\t\t\tbfsq.add (new ProblemCFireAgain.Pair (newX, newY));\n\t\t\t\t\t\tlvl[newX][newY] = (plvl+1);\n//\t\t\t\t\tSystem.out.println (\"dhukse \"+newX+\" \"+newY);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void solve (int testNumber, InputReader _in, PrintWriter _out) {\n\t\t\t/*\n\t\t\t * file input-output \ud83d\ude2e. Multi source bfs. Same as snackdown problem.\n\t\t\t * */\n\t\t\ttry (InputReader in = new InputReader (new FileInputStream (\"input.txt\"));\n\t\t\t\t PrintWriter out = new PrintWriter (new BufferedWriter (new FileWriter (\"output.txt\")))) {\n\t\t\t\tn = in.nextInt ();\n\t\t\t\tm = in.nextInt ();\n\t\t\t\tk = in.nextInt ();\n\t\t\t\tbgn = new ProblemCFireAgain.Pair[k];\n\t\t\t\tfor (int i = 0; i<k; i++) {\n\t\t\t\t\tbgn[i] = new ProblemCFireAgain.Pair (in.nextInt (), in.nextInt ());\n\t\t\t\t}\n\t\t\t\tmax = Integer.MIN_VALUE;\n\t\t\t\tlvl = new int[n+5][m+5];\n\t\t\t\tfor (int i = 0; i<n+4; i++) {\n\t\t\t\t\tArrays.fill (lvl[i], -1);\n\t\t\t\t}\n\t\t\t\tbfs2d ();\n//\t\t\tSystem.out.println (max);\n\t\t\t\tout.println (res);\n\t\t\t} catch (Exception e) {\n//\t\t\te.printStackTrace ();\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate static class Pair {\n\t\t\tint a;\n\t\t\tint b;\n\t\t\t\n\t\t\tPair (int a, int b) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tpublic String toString () {\n\t\t\t\treturn a+\" \"+b;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tpublic boolean equals (Object o) {\n\t\t\t\tif (this == o) return true;\n\t\t\t\tif (!(o instanceof ProblemCFireAgain.Pair)) return false;\n\t\t\t\tProblemCFireAgain.Pair pair = (ProblemCFireAgain.Pair) o;\n\t\t\t\treturn a == pair.a && b == pair.b;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tpublic int hashCode () {\n\t\t\t\treturn Objects.hash (a, b);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tstatic class InputReader implements AutoCloseable {\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\t\t\n\t\tpublic InputReader (InputStream stream) {\n\t\t\treader = new BufferedReader (new InputStreamReader (stream));\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\t\n\t\tpublic void close () throws Exception {\n\t\t\treader.close ();\n\t\t}\n\t\t\n\t}\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.PrintStream;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class FireAgain {\n\n\tPoint coordinate;\n\tQueue<Point> q = new LinkedList<Point>();\n\tint m, n;\n\tboolean[][] arr;\n\tPrintStream out ;\n\n\tvoid bfs(Point start) {\n\n\t\twhile (!q.isEmpty()) {\n\t\t\tPoint front = q.poll();\n\t\t\tPoint p = new Point();\n\n\t\t\tp.x = front.x - 1;\n\t\t\tp.y = front.y;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1) {\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tp = new Point();\n\t\t\tp.x = front.x + 1;\n\t\t\tp.y = front.y;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\n\t\t\tp = new Point() ;\n\t\t\tp.x = front.x;\n\t\t\tp.y = front.y + 1;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\n\t\t\tp = new Point() ;\n\t\t\tp.x = front.x;\n\t\t\tp.y = front.y - 1;\n\t\t\tif (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)\n\t\t\t\tif (!arr[p.x][p.y]) {\n\t\t\t\t\tarr[p.x][p.y] = true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\n\t\t\tif (q.size() == 0)\n\t\t\t\tout.print(front.x + \" \" + front.y);\n\t\t}\n\t}\n\n\t/**\n\t * @param args\n\t * @throws FileNotFoundException \n\t */\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// TODO Auto-generated method stub\n\t\tFireAgain fa = new FireAgain();\n\t\tScanner Scan = new Scanner(new FileInputStream(\"input.txt\"));\n\t\tfa.out = new PrintStream(new File(\"output.txt\"));\n\t\tfa.n = Scan.nextInt();\n\t\tfa.m = Scan.nextInt();\n\t\tint k = Scan.nextInt();\n\t\tfa.arr = new boolean[2001][2001];\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tfa.coordinate = new Point();\n\t\t\tfa.coordinate.x = Scan.nextInt();\n\t\t\tfa.coordinate.y = Scan.nextInt();\n\t\t\tfa.q.add(fa.coordinate);\n\t\t\tfa.arr[fa.coordinate.x][fa.coordinate.y] = true;\n\t\t}\n\n\t\tfa.bfs(fa.q.peek());\n\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n    \n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    void init() throws FileNotFoundException {\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\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\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    public static void main(String[] args) {\n        new Main().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    int mini = Integer.MAX_VALUE;\n    int maxi = Integer.MIN_VALUE;\n    int ans = 0;\n    int ans2 = 0;\n    int sum = 0;\n\n    void solve() throws IOException {\n        int n = readInt();\n        int m = readInt();\n        int maxi=0;\n        int  [][] a = new int [n][m];\n        int k = readInt();\n        ArrayDeque<Point> dq = new ArrayDeque<Point> ();\n        Point p = new Point();\n        for (int i = 0; i<n; i++)\n            for (int j= 0; j<m; j++){\n                a[i][j]=Integer.MAX_VALUE;\n            }\n        for (int i = 0; i<k; i++){\n            int x = readInt()-1;\n            int y = readInt()-1;\n            p.x=x;\n            p.y=y;\n            dq.add(new Point(x,y));\n            a[x][y]=0;\n        }\n        while (!dq.isEmpty()){\n            Point v = dq.pollFirst();\n            Point u = new Point();\n            if (v.x-1!=-1) {\n                if (a[v.x-1][v.y]>a[v.x][v.y]+1){\n                    a[v.x-1][v.y]=a[v.x][v.y]+1;\n                    maxi=max(maxi,a[v.x-1][v.y]);\n                    u.x=v.x-1;\n                    u.y=v.y;\n                    dq.add(new Point(u.x,u.y));\n                }\n            }\n            if (v.y-1!=-1) {\n                if (a[v.x][v.y-1]>a[v.x][v.y]+1){\n                    a[v.x][v.y-1]=a[v.x][v.y]+1;\n                    maxi=max(maxi,a[v.x][v.y-1]);\n                    u.y=v.y-1;\n                    u.x=v.x;\n                    dq.add(new Point(u.x,u.y));\n                }\n            }\n            if (v.x+1!=n) {\n                if (a[v.x+1][v.y]>a[v.x][v.y]+1){\n                    a[v.x+1][v.y]=a[v.x][v.y]+1;\n                    maxi=max(maxi,a[v.x+1][v.y]);\n                    u.x=v.x+1;\n                    u.y=v.y;\n                    dq.add(new Point(u.x,u.y));\n                }\n            }\n            if (v.y+1!=m) {\n                if (a[v.x][v.y+1]>a[v.x][v.y]+1){\n                    a[v.x][v.y+1]=a[v.x][v.y]+1;\n                    maxi=max(maxi,a[v.x][v.y+1]);\n                    u.y=v.y+1;\n                    u.x=v.x;\n                    dq.add(new Point(u.x,u.y));\n                }\n            }\n        }\n        for (int i =0; i<n; i++)\n            for (int j =0; j<m; j++){\n                if (maxi==a[i][j]) {\n                    out.print((i+1) + \" \" + (j+1));\n                    return;\n                }\n            }\n        \n      }\n    \n    \n    \n    \n    \n    \n    \n\n    char c[];\n    \n    void per (int left, int right){\n        if(left == right){\n            for (int i = 0; i<=right;i++){\n                out.print(c[i]);\n            }\n            out.println();\n        }\n        else {\n            for (int i = left; i <=right; i++){\n                char k = c[left];\n                c[left] = c[i];\n                c[i] = k;\n                per(left+1,right);\n                k = c[left];\n                c[left] = c[i];\n                c[i] = k;\n            }\n        }\n    }\n}\n\n\n\n\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.fill;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.sort;\n\n\npublic class C35 \n{\n\n\tpublic static int mod = 1000000007;\n\tpublic static long INF = (1L << 60);\n\n\tstatic int n,m;\n\tstatic class Pair\n\t{\n\t\tint 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}\n\tstatic boolean[][] burned;\n\tstatic int[] dx={-1,0,1,0};\n\tstatic int[] dy={0,-1,0,1};\n\tstatic boolean isvalid(int x,int y)\n\t{\n\t\treturn x>=0&&x<n&&y>=0&&y<m;\n\t}\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner in = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\tn=in.nextInt();\n\t\tm=in.nextInt();\n\t\tburned=new boolean[n][m];\n\t\tint k=in.nextInt();\n\t\tQueue<Pair> queue=new LinkedList<>();\n\t\tPair prev=null;\n\t\tfor(int i=0;i<k;i++)\n\t\t{\n\t\t\tint x=in.nextInt();\n\t\t\tint y=in.nextInt();\n\t\t\tburned[x-1][y-1]=true;\n\t\t\tqueue.add(prev=new Pair(x-1, y-1));\n\t\t}\n\t\twhile(!queue.isEmpty())\n\t\t{\n\t\t\tQueue<Pair> tempqueue=new LinkedList<>();\n\t\tfor(Pair p : queue)\n\t\t{\n\t\t\tint x=p.x;\n\t\t\tint y=p.y;\n\t\t\tprev=p;\n\t\t\tfor(int i=0;i<4;i++)\n\t\t\t{\n\t\t\t\tif(isvalid(x+dx[i], y+dy[i])&&!burned[x+dx[i]][y+dy[i]])\n\t\t\t\t{\n\t\t\t\t\ttempqueue.add(new Pair(x+dx[i], y+dy[i]));\n\t\t\t\t\tburned[x+dx[i]][y+dy[i]]=true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tqueue=tempqueue;\n\t\t}\n\t\tout.printf(\"%d %d\\n\",(prev.x+1),(prev.y+1));\n\t\tout.close();\n\n\t}\n\t\n\tpublic static long pow(long x, long n) \n\t{\n\t\tlong res = 1;\n\t\tfor (long p = x; n > 0; n >>= 1, p = (p * p)) \n\t\t{\n\t\t\tif ((n & 1) != 0) \n\t\t\t{\n\t\t\t\tres = (res * p);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tpublic static long pow(long x, long n, long mod) \n\t{\n\t\tlong res = 1;\n\t\tfor (long p = x; n > 0; n >>= 1, p = (p * p) % mod) \n\t\t{\n\t\t\tif ((n & 1) != 0) \n\t\t\t{\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{\n\t\tlong r;\n\t\twhile (n2 != 0) \n\t\t{\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\tpublic static long lcm(long n1, long n2) \n\t{\n\t\tlong answer = (n1 * n2) / (gcd(n1, n2));\n\t\treturn answer;\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\t\t\n\t\tpublic Scanner(String s) throws FileNotFoundException {\tbr = new BufferedReader(new FileReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n\npublic class R035CRetry {\n    public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); }\n    public static final int INF = 987654321;\n    public static final long LINF = 987654321987654321L;\n    public static final double EPS = 1e-9;\n    \n    Scanner scanner;\n    PrintWriter out;\n    boolean[][] bss;\n    \n    public R035CRetry() {\n        try {\n            this.scanner = new Scanner(new File(\"input.txt\"));\n            this.out = new PrintWriter(\"output.txt\");\n        } catch(FileNotFoundException ex) { ex.printStackTrace(); }\n    }\n    \n    class Point implements Comparable<Point> {\n        int x, y, count;\n        Point(int x, int y) { this.x = x; this.y = y; }\n        public int hashCode() { return x * 17 + y; }\n        public boolean equals(Object o) {\n            if(!(o instanceof Point)) return false;\n            Point that = (Point)o;\n            return this.x == that.x && this.y == that.y;\n        }\n        public int compareTo(Point that) { return this.count - that.count; }\n        public String toString()  { return \"(\" + x + \", \" + y + \":\" + count + \")\"; }\n    }\n\n    \n    int[] dx = new int[] {  0, 0, -1, 1 };\n    int[] dy= new int[] { -1, 1,  0, 0 };\n    int n, m;\n    \n    Queue<Point> q;\n    \n    Point bfs() {\n        int max = -INF;\n        Point p = null;\n        while(!q.isEmpty()) {\n            Point cur = q.remove();\n            if(max < cur.count) { max = cur.count; p = cur; } \n            for(int i=0; i<dx.length; i++) {\n                int nx = cur.x + dx[i];\n                int ny = cur.y + dy[i];\n                if(nx < 0 || nx >= n) { continue; }\n                if(ny < 0 || ny >= m) { continue; }\n                Point np = new Point(nx, ny);\n                if(bss[nx][ny] ) { continue; } \n                np.count = cur.count+1;\n                bss[nx][ny] = true;\n                q.add(np);\n            }\n        }\n        return p;\n    }\n    \n    private void solve() {\n        this.n = scanner.nextInt();\n        this.m = scanner.nextInt();\n        this.bss = new boolean[n][m];\n        int k = scanner.nextInt();\n        q = new LinkedList<Point>();\n        for(int i=0; i<k; i++) {\n            int x = scanner.nextInt() - 1;\n            int y = scanner.nextInt() - 1;\n            Point init = new Point(x, y);\n            init.count = 1;\n            q.add(init);\n            bss[x][y] = true;\n        }\n        Point p = bfs();\n        out.println((p.x+1) + \" \" + (p.y+1));\n    }\n    \n    private void finish() { this.out.close(); }\n    \n    public static void main(String[] args) { \n        R035CRetry obj = new R035CRetry();\n        obj.solve();\n        obj.finish();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Watermelon {\n    static int[][] ans;static int n,m;static boolean[][] vis;\n    public static void main(String[] args) throws IOException {\n        Scanner sc=new Scanner(new File(\"input.txt\"));\n//        Scanner sc=new Scanner(System.in);\n        PrintWriter pw=new PrintWriter(\"output.txt\");\n        int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();\n        Queue<Integer> pq=new ArrayDeque<>();\n        boolean[] vis=new boolean[n*m];\n        for(int i=0;i<k;i++){\n            int r=sc.nextInt()-1,c=sc.nextInt()-1;\n            pq.add(m*r+c);\n            vis[m*r+c]=true;\n        }\n        sc.close();\n        int ans=0;\n        while(pq.size()!=0){\n            int x=pq.remove();\n\n            ans=x;\n            if(n!=1 && x%n==0){\n                if(x+m<n*m&&!vis[x+m]){\n                    pq.add(x+m);\n                    vis[x+m]=true;\n                }\n                if(x-m>=0&&!vis[x-m]){\n                    pq.add(x-m);\n                    vis[x-m]=true;\n                }\n                if(x+1<n*m&&!vis[x+1]){\n                    pq.add(x+1);\n                    vis[x+1]=true;\n                }\n            }\n            else if(n!=1 && (x+1)%n==0){\n                if(x+m<n*m&&!vis[x+m]){\n                    pq.add(x+m);\n                    vis[x+m]=true;\n                }\n                if(x-m>=0&&!vis[x-m]){\n                    pq.add(x-m);\n                    vis[x-m]=true;\n                }\n                if(x-1>=0&&!vis[x-1]){\n                    pq.add(x-1);\n                    vis[x-1]=true;\n                }\n            }\n            else{\n                if(x+m<n*m&&!vis[x+m]){\n                    pq.add(x+m);\n                    vis[x+m]=true;\n                }\n                if(x-m>=0&&!vis[x-m]){\n                    pq.add(x-m);\n                    vis[x-m]=true;\n                }\n                if(x-1>=0&&!vis[x-1]){\n                    pq.add(x-1);\n                    vis[x-1]=true;\n                }\n                if(x+1<n*m&&!vis[x+1]){\n                    pq.add(x+1);\n                    vis[x+1]=true;\n                }\n            }\n        }\n        pw.println((ans/m+1)+\" \"+(ans%m+1));\n        pw.close();\n    }\n\n    static class Reader{\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        public Reader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public Reader(String file_name) throws IOException {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[64]; // line length\n            int cnt = 0, c;\n            while ((c = read()) != -1) {\n                if (c == '\\n')\n                    break;\n                buf[cnt++] = (byte) c;\n            }\n\n            return new String(buf, 0, cnt);\n        }\n\n        public int nextInt() throws IOException {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public long nextLong() throws IOException {\n            long ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public double nextDouble() throws IOException {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n\n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        private void fillBuffer() throws IOException {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n            if (bytesRead == -1)\n                buffer[0] = -1;\n        }\n\n        private byte read() throws IOException {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n\n        public void close() throws IOException {\n            if (din == null)\n                return;\n            din.close();\n        }\n    }\n\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.LinkedList;\n\npublic class Solution {\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new FileReader(\"input.txt\"));\n        PrintWriter out = new PrintWriter(\"output.txt\");\n\n        String[] raw = in.readLine().split(\" \");\n        int n = Integer.parseInt(raw[0]);\n        int m = Integer.parseInt(raw[1]);\n\n        int k = Integer.parseInt(in.readLine());\n\n        raw = in.readLine().split(\" \");\n\n        boolean[][] map = new boolean[n][m];\n        LinkedList<Point> queue = new LinkedList<>();\n\n        for (int i = 0; i < k; i++) {\n            Point fireStarter = new Point(Integer.parseInt(raw[i * 2]) - 1, Integer.parseInt(raw[i * 2 + 1]) - 1);\n\n            queue.addLast(fireStarter);\n        }\n\n        int treesLeft = n * m;\n\n        while (true) {\n            Point firepoint = queue.removeFirst();\n\n            if (map[firepoint.x][firepoint.y])\n                continue;\n\n            treesLeft--;\n            map[firepoint.x][firepoint.y] = true;\n\n            if (treesLeft == 0) {\n                out.printf(\"%d %d\", firepoint.x + 1, firepoint.y + 1);\n                out.flush();\n                return;\n            }\n\n            if (firepoint.x > 0 && !map[firepoint.x - 1][firepoint.y])\n                queue.add(new Point(firepoint.x - 1, firepoint.y));\n\n            if (firepoint.y > 0 && !map[firepoint.x][firepoint.y - 1])\n                queue.add(new Point(firepoint.x, firepoint.y - 1));\n\n            if (firepoint.x < n - 1 && !map[firepoint.x + 1][firepoint.y])\n                queue.add(new Point(firepoint.x + 1, firepoint.y));\n\n            if (firepoint.y < m - 1 && !map[firepoint.x][firepoint.y + 1])\n                queue.add(new Point(firepoint.x, firepoint.y + 1));\n\n//\n//            for (int i = 0; i < n; i++) {\n//                for (int j = 0; j < m; j++) {\n//                    System.out.printf(\"%d \", map[i][j] ? 1 : 0);\n//                }\n//                System.out.println();\n//            }\n//            System.out.println(\"\\n-------\\n\");\n        }\n    }\n\n    private static class Point {\n        public int x;\n        public int y;\n\n        public Point(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\n\nimport static java.lang.Integer.*;\nimport static java.lang.Math.*;\n@SuppressWarnings(\"unused\")\npublic class round35C {\n    static class state{\n        int x, y, time;\n        public state(int xx, int yy, int t){\n            x = xx;\n            y = yy;\n            time = t;\n        }\n    }\n    static int N,M;\n    static int [] dx = new int [] {1,-1,0,0};\n    static int [] dy = new int [] {0,0,1,-1};\n    static Queue<state> bfs = new LinkedList<round35C.state>();\n    public static Point runBFS(){\n        boolean [][] vis = new boolean [N + 1][M + 1];\n        int max = -(int)1e9;\n        int bestx = -1;\n        int besty = -1;\n        while(!bfs.isEmpty()){\n            state p = bfs.poll();\n            int x = p.x;\n            int y = p.y;\n            int time = p.time;\n            if(vis[x][y])\n                continue;\n            vis[x][y] = true;\n            if(time > max){\n                max = time;\n                bestx = x + 1;\n                besty = y + 1;\n            }\n            for(int i = 0 ; i < 4 ; ++i){\n                int nx = x + dx[i];\n                int ny = y + dy[i];\n                if(nx < 0 || ny < 0 || nx >= N || ny >= M)\n                    continue;\n                if(vis[nx][ny] == false)\n                    bfs.offer(new state(nx, ny, time + 1));\n            }\n        }\n        return new Point(bestx, besty);\n    }\n    public static void main(String[] args)throws IOException {\n        BufferedReader br = new BufferedReader(new FileReader(\"input.txt\"));\n        PrintWriter out = new PrintWriter(\"output.txt\");\n        String [] use = null;\n        use = br.readLine().split(\" \");\n        N = parseInt(use[0]);\n        M = parseInt(use[1]);\n        int K = parseInt(br.readLine());\n        use = br.readLine().split(\" \");\n        for(int i = 0 ; i < 2 * K ; i += 2){\n            int f = parseInt(use[i]) - 1;\n            int t = parseInt(use[i + 1]) - 1;\n            bfs.offer(new state(f, t, 0));\n        }\n        Point ans = runBFS();\n        out.println(ans.x + \" \" + ans.y);\n        out.flush();\n        out.close();\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n  BufferedReader in;\n  PrintWriter out;\n  StringTokenizer tok = new StringTokenizer(\"\");\n\n  @Override\n  public void run() {\n    try {\n      init();\n    } catch (FileNotFoundException e) {\n      e.printStackTrace();\n    }\n    long time = System.currentTimeMillis();\n    try {\n      solve();\n    } catch (Exception e) {\n      e.printStackTrace();\n    }\n    out.close();\n    //System.err.println(System.currentTimeMillis() - time);\n  }\n\n  private void init() throws FileNotFoundException {\n    String file = \"123\";\n    if (!file.equals(\"\")) {\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  }\n\n  public static void main(String[] args) {\n    new Thread(new Solution()).start();\n  }\n\n  private String readString() {\n    while (!tok.hasMoreTokens()) {\n      try {\n        tok = new StringTokenizer(in.readLine());\n      } catch (IOException e) {\n        e.printStackTrace();\n      }\n    }\n    return tok.nextToken();\n  }\n\n  private int readInt() {\n    return Integer.parseInt(readString());\n  }\n\n  int[] counts = new int[1000];\n\n  private long readLong() {\n    return Long.parseLong(readString());\n  }\n\n  private void solve() {\n    int n = readInt()+2;\n    int m = readInt()+2;\n    boolean[][] graph = new boolean[n][m];\n    for (int i = 0; i < n; i++) {\n      graph[i][m-1] = true;\n      graph[i][0] = true;\n    }\n    for (int i = 0; i < m; i++) {\n      graph[n-1][i] = true;\n      graph[0][i] = true;\n    }\n    int k = readInt();\n    int inFire = 0;\n    Queue<Point> q = new ArrayDeque<>();\n    for (int i = 0; i < k; i++) {\n      int x = readInt();\n      int y = readInt();\n      Point p = new Point(x, y);\n      graph[x][y] = true;\n      q.add(p);\n    }\n    while (!q.isEmpty()) {\n      Point current = q.poll();\n      inFire++;\n      if(!graph[current.x+1][current.y]) {\n        graph[current.x+1][current.y] = true;\n        q.add(new Point(current.x+1, current.y));\n      }\n      if(!graph[current.x-1][current.y]) {\n        graph[current.x-1][current.y] = true;\n        q.add(new Point(current.x-1, current.y));\n      }\n      if(!graph[current.x][current.y+1]) {\n        graph[current.x][current.y+1] = true;\n        q.add(new Point(current.x, current.y+1));\n      }\n      if(!graph[current.x][current.y-1]) {\n        graph[current.x][current.y-1] = true;\n        q.add(new Point(current.x, current.y-1));\n      }\n      if(q.isEmpty()) {\n        out.print(current.x+\" \"+current.y);\n        return;\n      }\n    }\n\n\n  }\n\n  class Point{\n    int x, y;\n\n    public Point(int x, int y) {\n      this.x = x;\n      this.y = y;\n    }\n  }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.abs;\n\n/**\n * 35C\n *\n * @author artyom\n */\npublic class FireAgain implements Runnable {\n    private BufferedReader in;\n    private PrintWriter out;\n    private StringTokenizer tok;\n\n    private void solve() throws IOException {\n        int n = nextInt(), m = nextInt();\n        int[][] sources = readIntMatrix(nextInt(), 2);\n        int max = -1, maxI = 0, maxJ = 0;\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                int min = Integer.MAX_VALUE;\n                for (int[] source : sources) {\n                    int dist = abs(source[0] - i) + abs(source[1] - j);\n                    if (dist < min) {\n                        min = dist;\n                    }\n                }\n                if (min > max) {\n                    max = min;\n                    maxI = i;\n                    maxJ = j;\n                }\n            }\n        }\n        out.print((maxI + 1) + \" \" + (maxJ + 1));\n    }\n\n    //--------------------------------------------------------------\n    public static void main(String[] args) {\n        new FireAgain().run();\n    }\n\n    @Override\n    public void run() {\n        try {\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(new FileWriter(\"output.txt\"));\n            tok = null;\n            solve();\n            in.close();\n            out.close();\n        } catch (IOException e) {\n            System.exit(0);\n        }\n    }\n\n    private String nextToken() throws IOException {\n        while (tok == null || !tok.hasMoreTokens()) {\n            tok = new StringTokenizer(in.readLine());\n        }\n        return tok.nextToken();\n    }\n\n    private int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    private int[][] readIntMatrix(int n, int m) throws IOException {\n        int[][] mx = new int[n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                mx[i][j] = nextInt() - 1;\n            }\n        }\n        return mx;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tvoid solve() {\n\t\tint R = sc.nextInt();\n\t\tint C = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tint[] x = new int[K];\n\t\tint[] y = new int[K];\n\t\tfor (int i = 0; i < K; i++) {\n\t\t\tx[i] = sc.nextInt();\n\t\t\ty[i] = sc.nextInt();\n\t\t}\n\n\t\tint best = -1;\n\t\tint bestX = 0;\n\t\tint bestY = 0;\n\n\t\tfor (int r = 1; r <= R; r++) for (int c = 1; c <= C; c++) {\n\t\t\tint here = R + C;\n\t\t\tfor (int i = 0; i < K; i++) {\n\t\t\t\tint t = abs(r - x[i]) + abs(c - y[i]);\n\t\t\t\there = min(here, t);\n\t\t\t}\n\t\t\tif (best < here){\n\t\t\t\tbest = here;\n\t\t\t\tbestX = r;\n\t\t\t\tbestY = c;\n\t\t\t}\n\t\t}\n\n\t\tout.println(bestX + \" \" + bestY);\n\t}\n\n\tvoid print(int[] a) {\n\t\tout.print(a[0]);\n\t\tfor (int i = 1; i < a.length; i++) out.print(\" \" + a[i]);\n\t\tout.println();\n\t}\n\n\tstatic void tr(Object... os) {\n\t\tSystem.err.println(deepToString(os));\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tMyScanner sc = null;\n\tPrintWriter out = null;\n\tpublic void run() throws Exception {\n//\t\tsc = new MyScanner(System.in);\n//\t\tout = new PrintWriter(System.out);\n\t\tsc = new MyScanner(new FileInputStream(new File(\"input.txt\")));\n\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\tfor (;sc.hasNext();) {\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t}\n\t\tout.close();\n\t}\n\n\tclass MyScanner {\n\t\tString line;\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic MyScanner(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t\ttokenizer = null;\n\t\t}\n\t\tpublic void eat() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tline = reader.readLine();\n\t\t\t\t\tif (line == null) {\n\t\t\t\t\t\ttokenizer = null;\n\t\t\t\t\t\treturn;\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\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic String next() {\n\t\t\teat();\n\t\t\treturn tokenizer.nextToken();\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\tpublic boolean hasNext() {\n\t\t\teat();\n\t\t\treturn (tokenizer != null && tokenizer.hasMoreElements());\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 int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n\npublic class R035C {\n    public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); }\n    public static final int INF = 987654321;\n    public static final long LINF = 987654321987654321L;\n    public static final double EPS = 1e-9;\n    \n    Scanner scanner;\n    PrintWriter out;\n    int[][] iss;\n    \n    public R035C() {\n        try {\n            this.scanner = new Scanner(new File(\"input.txt\"));\n            this.out = new PrintWriter(\"output.txt\");\n        } catch(FileNotFoundException ex) { ex.printStackTrace(); }\n    }\n    \n    class Point implements Comparable<Point> {\n        int x, y, count;\n        Point(int x, int y) { this.x = x; this.y = y; }\n        public int hashCode() { return x * 17 + y; }\n        public boolean equals(Object o) {\n            if(!(o instanceof Point)) return false;\n            Point that = (Point)o;\n            return this.x == that.x && this.y == that.y;\n        }\n        public int compareTo(Point that) { return this.count - that.count; }\n        public String toString()  { return \"(\" + x + \", \" + y + \":\" + count + \")\"; }\n    }\n\n    \n    int[] dx = new int[] {  0, 0, -1, 1 };\n    int[] dy= new int[] { -1, 1,  0, 0 };\n    int n, m;\n    \n    Queue<Point> q;\n    \n    Point bfs() {\n        int max = -INF;\n        Point p = null;\n        while(!q.isEmpty()) {\n            Point cur = q.remove();\n            if(max < cur.count) { max = cur.count; p = cur; } \n            for(int i=0; i<dx.length; i++) {\n                int nx = cur.x + dx[i];\n                int ny = cur.y + dy[i];\n                if(nx < 0 || nx >= n) { continue; }\n                if(ny < 0 || ny >= m) { continue; }\n                Point np = new Point(nx, ny);\n                if(iss[nx][ny] != 0) { continue; } \n                np.count = cur.count+1;\n                iss[nx][ny] = np.count;\n                q.add(np);\n            }\n        }\n        return p;\n    }\n    \n    private void solve() {\n        this.n = scanner.nextInt();\n        this.m = scanner.nextInt();\n        this.iss = new int[n][m];\n        int k = scanner.nextInt();\n        q = new PriorityQueue<Point>();\n        for(int i=0; i<k; i++) {\n            int x = scanner.nextInt() - 1;\n            int y = scanner.nextInt() - 1;\n            Point init = new Point(x, y);\n            init.count = 1;\n            q.add(init);\n            iss[x][y] = 1;\n        }\n        Point p = bfs();\n        out.println((p.x+1) + \" \" + (p.y+1));\n    }\n    \n    private void finish() { this.out.close(); }\n    \n    public static void main(String[] args) { \n        R035C obj = new R035C();\n        obj.solve();\n        obj.finish();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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.io.OutputStream;\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;\n        try\n        {\n            inputStream = new FileInputStream(\"input.txt\");\n        } catch (IOException e)\n        {\n            throw new RuntimeException(e);\n        }\n        OutputStream outputStream;\n        try\n        {\n            outputStream = new FileOutputStream(\"output.txt\");\n        } catch (IOException e)\n        {\n            throw new RuntimeException(e);\n        }\n        FastScanner in = new FastScanner(inputStream);\n        FastPrinter out = new FastPrinter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC\n    {\n        public void solve(int testNumber, FastScanner in, FastPrinter out)\n        {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            int p = in.nextInt();\n            int[] x = new int[p];\n            int[] y = new int[p];\n            for (int i = 0; i < p; i++)\n            {\n                x[i] = in.nextInt();\n                y[i] = in.nextInt();\n            }\n\n            int X = x[0];\n            int Y = y[0];\n            int D = -1;\n            for (int dx = 1; dx <= n; dx++)\n            {\n                int x1 = dx;\n                int y1 = 1;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int dx = 1; dx <= n; dx++)\n            {\n                int x1 = dx;\n                int y1 = m;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int dy = 1; dy <= m; dy++)\n            {\n                int x1 = 1;\n                int y1 = dy;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int dy = 1; dy <= m; dy++)\n            {\n                int x1 = n;\n                int y1 = dy;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n\n            for (int i = 1; i <= Math.min(m, n); i++)\n            {\n                int x1 = i;\n                int y1 = i;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            for (int i = 1, ii = m; i <= n && ii >= 1; i++, ii--)\n            {\n                int x1 = i;\n                int y1 = ii;\n                int xx = 0;\n                int yy = 0;\n                int minD = Integer.MAX_VALUE;\n                for (int j = 0; j < p; j++)\n                {\n                    int d = Math.abs(x1 - x[j]) + Math.abs(y1 - y[j]);\n                    if (d < minD)\n                    {\n                        minD = d;\n                        xx = x1;\n                        yy = y1;\n                    }\n                }\n                if (D < minD && minD != 0 && minD != Integer.MAX_VALUE)\n                {\n                    D = minD;\n                    X = xx;\n                    Y = yy;\n                }\n            }\n            out.println(X + \" \" + Y);\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class P035C {\n    private class Pair {\n        private int x;\n        private int y;\n        \n        private Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n        \n        public int hashCode() {\n            return 37 * x + y;\n        }\n        \n        public boolean equals(Object other) {\n            if (other instanceof Pair) {\n                Pair otherPair = (Pair)other;\n                return x == otherPair.x && y == otherPair.y;\n            }\n            \n            return false;\n        }\n    }\n    \n    private boolean[][] visited;\n    private final int N;\n    private final int M;\n    private final int k;\n    private ArrayList<Pair> fires = new ArrayList<Pair>();\n    private ArrayList<Pair> neighbors = new ArrayList<Pair>();\n    \n    public P035C() throws IOException {\n        Scanner sc = new Scanner(new File(\"input.txt\"));\n\n        N = sc.nextInt();\n        M = sc.nextInt();\n        visited = new boolean[N][M];\n        k = sc.nextInt();\n        for (int i = 0; i < k; i++) {\n            int x = sc.nextInt() - 1;\n            int y = sc.nextInt() - 1;\n            fires.add(new Pair(x, y));\n        }\n        bfs();\n    }\n    \n    private void bfs() throws IOException{\n        java.util.Queue<Pair> queue = new ArrayDeque<Pair>();\n        for (Pair p : fires) {\n            queue.add(p);\n            visited[p.x][p.y] = true;\n        }\n        \n        Pair last = fires.get(0);\n        while (!queue.isEmpty()) {\n            Pair p = last = queue.poll();            \n            for (Pair pn : getNeighbors(p)) {\n                if (!visited[pn.x][pn.y]) {\n                    queue.add(pn);\n                    visited[pn.x][pn.y] = true;\n                }\n            }\n        }\n        \n        PrintWriter output = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n        output.printf(\"%d %d\\n\", last.x + 1, last.y + 1);\n        output.close();\n    }\n    \n    private Collection<Pair> getNeighbors(Pair p) {\n        neighbors.clear();\n        if (p.x > 0)   neighbors.add(new Pair(p.x-1, p.y));\n        if (p.x < N-1) neighbors.add(new Pair(p.x+1, p.y));\n        if (p.y > 0)   neighbors.add(new Pair(p.x, p.y-1));\n        if (p.y < M-1) neighbors.add(new Pair(p.x, p.y+1));\n        \n        return neighbors;\n    }\n    \n    public static void main(String[] args) throws IOException {\n        P035C solution = new P035C();\n    }\n}\n        \n      ", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\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\n    String readString() {\n        while (!tok.hasMoreTokens()) {\n            try {\n                tok = new StringTokenizer(in.readLine());\n            } catch (Exception e) {\n                return null;\n            }\n        }\n        return tok.nextToken();\n    }\n\n    int readInt() {\n        return Integer.parseInt(readString());\n    }\n\n    long readLong() {\n        return Long.parseLong(readString());\n    }\n\n    double readDouble() {\n        return Double.parseDouble(readString());\n    }\n\n    int[] readIntArray(int size) {\n        int[] a = new int[size];\n        for (int i = 0; i < size; i++) {\n            a[i] = readInt();\n        }\n        return a;\n    }\n\n    public static void main(String[] args) {\n        //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n        new Problem().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[][] dist;\n    int n, m;\n\n    private void solve() throws IOException {\n        n = readInt();\n        m = readInt();\n        int k=readInt();\n        dist = new int[n][m];\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < m; j++)\n                dist[i][j] = -1;\n        for (int i = 0; i < k; i++) {\n            dist[readInt()-1][readInt()-1]=0;\n        }\n        for (int i=0;i<n;i++)\n            for (int j=0;j<m;j++)\n                if (dist[i][j]==0)\n                    bfs(i, j);\n        int max=0,X=0,Y=0;\n        for (int i=0;i<n;i++)\n            for (int j=0;j<m;j++)\n                if (dist[i][j]>=max){\n                    max=dist[i][j];\n                    X=i+1; Y=j+1;\n                }\n        out.println(X+\" \"+Y);\n    }\n\n    public void bfs(int x, int y) {\n        int[] dx = {0, 1, 0, -1};\n        int[] dy = {1, 0, -1, 0};\n        dist[x][y] = 0;\n        ArrayDeque<P> q = new ArrayDeque<>();\n        q.add(new P(x, y));\n        while (!q.isEmpty()) {\n            P v = q.poll();\n\n            for (int i = 0; i < 4; i++) {\n                int nx = v.x + dx[i];\n                int ny = v.y + dy[i];\n                if (inside(nx, ny) && (dist[nx][ny] == -1 || (dist[nx][ny] > dist[v.x][v.y] + 1&&dist[nx][ny]!=0))) {\n                    q.add(new P(nx, ny));\n                    dist[nx][ny] = dist[v.x][v.y] + 1;\n                }\n            }\n        }\n    }\n\n    public boolean inside(int x, int y) {\n        if (x < n && y < m && x >= 0 && y >= 0) {\n            return true;\n        }\n        return false;\n    }\n}\n\n\nclass P {\n    int x, y;\n\n    public P(int x, int y) {\n        this.x = x;\n        this.y = y;\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport javafx.util.Pair;\n\n\npublic class FireAgain {\n\n     static Queue q=new LinkedList<>();\n     static boolean[][] fired;\n     static Pair index = null;\n    public static void main(String[] args) throws IOException {\n        // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n          BufferedReader in=new BufferedReader(new FileReader(\"input.txt\"));\n          BufferedWriter writer = new BufferedWriter(new FileWriter(\"output.txt\"));\n         StringTokenizer s = new StringTokenizer(in.readLine());\n         int n=Integer.parseInt(s.nextToken());\n         int m=Integer.parseInt(s.nextToken());\n         fired=new boolean[n][m];\n         Pair result=null;\n         s = new StringTokenizer(in.readLine());\n         int firenum=Integer.parseInt(s.nextToken());\n         s = new StringTokenizer(in.readLine());\n         int i;\n         ArrayList<Integer> tree=new ArrayList<>();\n         for(i=0;i<firenum*2;i++){\n             tree.add(Integer.parseInt(s.nextToken())-1);\n         }\n        for(i=0;i<2*firenum-1;i+=2){\n           fired[tree.get(i)][tree.get(i+1)]=true;\n           q.add(new Pair(tree.get(i),tree.get(i+1)));\n        }\n        index=(Pair) q.peek();\n         result=bfs((int)index.getKey(),(int)index.getValue(),n,m);\n       int x1=(int)result.getKey()+1;\n       int x2=(int)result.getValue()+1;\n        String str = x1 + \" \" + x2;\n        writer.write(str);\n\n        writer.close();\n    }\n    public static Pair bfs(int x,int y,int xmax,int ymax){\n        fired[x][y]=true;\n        while(!q.isEmpty()){\n            index=(Pair) q.poll();\n            int i=(int) index.getKey();\n            int j=(int) index.getValue();\n            if(i-1>=0){\n                if(!fired[i-1][j]){\n                fired[i-1][j]=true;\n                q.add(new Pair((i-1),j));\n                }\n            }if(j-1>=0){\n                if(!fired[i][j-1]){\n                fired[i][j-1]=true;\n                q.add(new Pair(i,(j-1)));\n                }\n            } if(i+1<xmax){\n                if(!fired[i+1][j]){\n                fired[i+1][j]=true;\n                q.add(new Pair(i+1,j));\n                }\n            } if(j+1<ymax){\n                if(!fired[i][j+1]){\n                fired[i][j+1]=true;\n                q.add(new Pair(i,j+1));\n                }\n            }\n        }    \n         return index;   \n            \n            \n    }\n    \n    \n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tvoid run() throws IOException {\n\t\tint n = ni(), m = ni(), k = ni(), q = n * m, h = 0, t = 0, inf = 123456;\n\t\tint[] x = new int[q], y = new int[q];\n\t\tint[][] d = 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\td[i][j] = inf;\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint u = ni() - 1, v = ni() - 1;\n\t\t\td[u][v] = 0;\n\t\t\tx[t] = u;\n\t\t\ty[t] = v;\n\t\t\tt++;\n\t\t}\n\t\tif (k < q)\n\t\t\twhile (t != h) {\n\t\t\t\tint u = x[h], v = y[h];\n\t\t\t\tint l = d[u][v] + 1;\n\t\t\t\th++;\n\t\t\t\tif (u > 0 && d[u - 1][v] > l) {\n\t\t\t\t\td[u - 1][v] = l;\n\t\t\t\t\tx[t] = u - 1;\n\t\t\t\t\ty[t] = v;\n\t\t\t\t\tt++;\n\t\t\t\t}\n\t\t\t\tif (u < n - 1 && d[u + 1][v] > l) {\n\t\t\t\t\td[u + 1][v] = l;\n\t\t\t\t\tx[t] = u + 1;\n\t\t\t\t\ty[t] = v;\n\t\t\t\t\tt++;\n\t\t\t\t}\n\t\t\t\tif (v > 0 && d[u][v - 1] > l) {\n\t\t\t\t\td[u][v - 1] = l;\n\t\t\t\t\tx[t] = u;\n\t\t\t\t\ty[t] = v - 1;\n\t\t\t\t\tt++;\n\t\t\t\t}\n\t\t\t\tif (v < m - 1 && d[u][v + 1] > l) {\n\t\t\t\t\td[u][v + 1] = l;\n\t\t\t\t\tx[t] = u;\n\t\t\t\t\ty[t] = v + 1;\n\t\t\t\t\tt++;\n\t\t\t\t}\n\t\t\t}\n\t\tint max = 0, tx = 0, ty = 0;\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (d[i][j] > max) {\n\t\t\t\t\tmax = d[i][j];\n\t\t\t\t\ttx = i;\n\t\t\t\t\tty = j;\n\n\t\t\t\t}\n\t\tpw.print(1 + tx + \" \" + (1 + ty));\n\t}\n\n\tString 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\tint ni() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tString nl() throws IOException {\n\t\treturn br.readLine();\n\t}\n\n\tPrintWriter pw;\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader _br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\tPrintWriter _pw = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n\t\tnew C(_br, _pw).run();\n\t\t_br.close();\n\t\t_pw.close();\n\t}\n\n\tpublic C(BufferedReader _br, PrintWriter _pw) {\n\t\tbr = _br;\n\t\tpw = _pw;\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.util.Scanner;\n\npublic class FireAgain \n{\n\n\tpublic static void main(String[] args) throws IOException \n\t{\n\n\t      FileInputStream in = null;\n\t      FileOutputStream out = null;\n\t\n\t      try \n\t      {\n\t         in = new FileInputStream(\"input.txt\");\n\t         out = new FileOutputStream(\"output.txt\");\n\t         \n\t\t  \t\tScanner sc = new Scanner(in);\n\n\t      \n\t\tint h = sc.nextInt();\n\t\tint w = sc.nextInt();\n\t\t\n\t\tint k = sc.nextInt();\n\t\t\n\t\tint[] xk = new int[k];\n\t\tint[] yk = new int[k];\n\t\t\n\t\tfor(int i = 0; i < k; i++)\n\t\t{\n\t\t\tint y = sc.nextInt()-1;\n\t\t\tint x = sc.nextInt()-1;\n\t\t\t\n\t\t\txk[i] = x;\n\t\t\tyk[i] = y;\n\t\t}\n\n\t\tint best = -1;\n\t\tint bestx = -1;\n\t\tint besty = -1;\n\t\tfor(int x = 0; x < w; x++)\n\t\t{\n\t\t\tfor(int y = 0; y < h; y++)\n\t\t\t{\n\t\t\t\tint cur = 99999;\n\t\t\t\tfor(int f = 0; f < k; f++)\n\t\t\t\t{\n\t\t\t\t\tcur = Math.min(cur, Math.abs(xk[f] - x)+Math.abs(yk[f] - y));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(cur > best)\n\t\t\t\t{\n\t\t\t\t\tbest = cur;\n\t\t\t\t\tbestx = x;\n\t\t\t\t\tbesty = y;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n//\t\tSystem.out.println((besty+1) + \" \" + (bestx+1));\n\t\tString s = (besty+1) + \" \" + (bestx+1);\n\n\t\tout.write(s.getBytes());\n\t\t\n\t      }finally \n\t      {\n\t         if (in != null) \n\t         {\n\t            in.close();\n\t         }\n\t         if (out != null) \n\t         {\n\t            out.close();\n\t         }\n\t      }\t\t\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n \npublic class C {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"3 3 1 1 1\";\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tint k = ni();\n\t    int[][] f=new int[k][2];\n        \t\t\n        \t\tfor(int i=0;i<k;i++) {\n        \t\t\tf[i][0]=ni()-1;\n        \t\t\tf[i][1]=ni()-1;\n        \t\t}\n        \t\tint mx=-1;\n        \t\tint resx=0;\n        \t\tint resy=0;        \t\t\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\tint min=Integer.MAX_VALUE;\n        \t\t\t\tfor(int l=0;l<k;l++) {\n        \t\t\t\t\tmin=Math.min(min, Math.abs(f[l][0]-i)+Math.abs(f[l][1]-j));\n        \t\t\t\t}\n        \t\t\t\tif(min>mx) {\n        \t\t\t\t\tmx=min;\n        \t\t\t\t\tresx=i;\n        \t\t\t\t\tresy=j;\n        \t\t\t\t}\n        \t\t\t}\n        \t\t\t\n        \t\t}\n        \t\tout.println((resx+1)+\" \"+(resy+1));\n        \t\t\n\t}\n\n\tvoid run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(new File(\"input.txt\")) : new Scanner(INPUT);\n\t\tout = INPUT.isEmpty() ? new PrintWriter(\"output.txt\") : 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 C().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\tstatic String join(int[] a, int d){StringBuilder sb = new StringBuilder();for(int v : a){sb.append(v + d + \" \");}return sb.toString();}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class P {\n\n\tstatic int N, M, K;\n\tstatic int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };\n\tstatic int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };\n\tstatic Pair[] b;\n\n\tstatic boolean isValid(int x, int y) {\n\t\treturn x >= 0 && y >= 0 && x < N && y < M;\n\t}\n\n\tstatic class Pair {\n\t\tint x, y;\n\n\t\tPair(int i, int j) {\n\t\t\tx = i;\n\t\t\ty = j;\n\t\t}\n\t}\n\n\tstatic Pair bfs() {\n\t\tQueue<Pair> q = new LinkedList<Pair>();\n\t\tint[][] dist = 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\tdist[i][j] = -1;\n\t\tfor (int i = 0; i < K; i++) {\n\t\t\tdist[b[i].x][b[i].y] = 0;\n\t\t\tq.add(b[i]);\n\t\t}\n\n\t\twhile (!q.isEmpty()) {\n\t\t\tPair cur = q.remove();\n\t\t\tfor (int d = 0; d < 4; d++) {\n\t\t\t\tint X = cur.x + dx[d];\n\t\t\t\tint Y = cur.y + dy[d];\n\t\t\t\tif (isValid(X, Y) && dist[X][Y] == -1) {\n\t\t\t\t\tdist[X][Y] = dist[cur.x][cur.y] + 1;\n\t\t\t\t\tPair P = new Pair(X, Y);\n\t\t\t\t\tq.add(P);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint max = -1;\n\t\tPair MX = null;\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tfor (int j = 0; j < M; j++) {\n\t\t\t\tif (dist[i][j] > max) {\n\t\t\t\t\tmax = dist[i][j];\n\t\t\t\t\tMX = new Pair(i + 1, j + 1);\n\t\t\t\t}\n\t\t\t}\n\n\t\treturn MX;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n\t\t// Scanner sc = new Scanner(System.in);\n\t\t// PrintWriter out = new PrintWriter(System.out);\n\t\tN = sc.nextInt();\n\t\tM = sc.nextInt();\n\t\tK = sc.nextInt();\n\t\tb = new Pair[K];\n\t\tfor (int i = 0; i < K; i++)\n\t\t\tb[i] = new Pair(sc.nextInt() - 1, sc.nextInt() - 1);\n\n\t\tPair last = bfs();\n\t\tout.println((last.x) + \" \" + (last.y));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String f) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArray1(int n) throws IOException {\n\t\t\tint[] a = new int[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArraySorted(int n) throws IOException {\n\t\t\tint[] a = nextIntArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tint t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray1(int n) throws IOException {\n\t\t\tlong[] a = new long[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArraySorted(int n) throws IOException {\n\t\t\tlong[] a = nextLongArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tlong t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.FileOutputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.FileInputStream;\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;\n\t\ttry {\n\t\t\tinputStream = new FileInputStream(\"input.txt\");\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tOutputStream outputStream;\n\t\ttry {\n\t\t\toutputStream = new FileOutputStream(\"output.txt\");\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\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    int maxdist = -1, maxrow = -1, maxcol = -1;\n\t    int rows = in.ri(), cols = in.ri();\n\t    int k = in.ri();\n\t    IntPair[] points = new IntPair[k];\n\t    for(int i = 0; i < k; i++) points[i] = new IntPair(in.ri(), in.ri());\n\t    for(int row = 1; row <= rows; row++) {\n\t\t    for(int col = 1; col <= cols; col++) {\n\t\t\t    int mindist = Integer.MAX_VALUE;\n\t\t\t    for(int i = 0; i < k; i++)\n\t\t\t\t    mindist = Math.min(mindist, Math.abs(row - points[i].first) + Math.abs(col - points[i].second));\n\t\t\t    if (mindist > maxdist){\n\t\t\t\t    maxdist = mindist;\n\t\t\t\t    maxrow = row;\n\t\t\t\t    maxcol = col;\n\t\t\t    }\n\t\t    }\n\t    }\n\t    out.printLine(maxrow, maxcol);\n    }\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic int ri(){\n\t\treturn readInt();\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void 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\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n}\n\nclass IntPair implements Comparable<IntPair> {\npublic int first, second;\n\n\n\tpublic IntPair(int first, int second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + 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\tIntPair intPair = (IntPair) o;\n\n\t\treturn first == intPair.first && second == intPair.second;\n\n\t}\n\n\tpublic int hashCode() {\n\t\tint result = first;\n\t\tresult = 31 * result + second;\n\t\treturn result;\n\t}\n\n\tpublic int compareTo(IntPair o) {\n\t\tif (first < o.first)\n\t\t\treturn -1;\n\t\tif (first > o.first)\n\t\t\treturn 1;\n\t\tif (second < o.second)\n\t\t\treturn -1;\n\t\tif (second > o.second)\n\t\t\treturn 1;\n\t\treturn 0;\n\t}\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\n\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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n\n        int[][] or;\n        int n;\n        int m;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n            n = in.nextInt();\n            m = in.nextInt();\n            int k = in.nextInt();\n\n            ArrayList<Point> arr1 = new ArrayList<>();\n            ArrayList<Point> arr2 = new ArrayList<>();\n\n            for (int i = 0; i < k; i++) {\n                arr1.add(new Point(in.nextInt(), in.nextInt()));\n            }\n\n            or = new int[n + 1][m + 1];\n\n            for (int i = 0; i < k; i++) {\n                or[arr1.get(i).x][arr1.get(i).y] = -1;\n            }\n\n            Point lastValue = arr1.get(0);\n\n            while (arr1.size() > 0 || arr2.size() > 0) {\n\n                for (Point p : arr1) {\n                    if (valid(new Point(p.x - 1, p.y))) {\n                        arr2.add(new Point(p.x - 1, p.y));\n                    }\n                    if (valid(new Point(p.x + 1, p.y))) {\n                        arr2.add(new Point(p.x + 1, p.y));\n                    }\n                    if (valid(new Point(p.x, p.y - 1))) {\n                        arr2.add(new Point(p.x, p.y - 1));\n                    }\n                    if (valid(new Point(p.x, p.y + 1))) {\n                        arr2.add(new Point(p.x, p.y + 1));\n                    }\n                }\n\n                arr1.clear();\n\n                if (arr2.size() > 0) {\n                    lastValue = arr2.get(0);\n                }\n\n                for (Point p : arr2) {\n                    if (valid(new Point(p.x - 1, p.y))) {\n                        arr1.add(new Point(p.x - 1, p.y));\n                    }\n                    if (valid(new Point(p.x + 1, p.y))) {\n                        arr1.add(new Point(p.x + 1, p.y));\n                    }\n                    if (valid(new Point(p.x, p.y - 1))) {\n                        arr1.add(new Point(p.x, p.y - 1));\n                    }\n                    if (valid(new Point(p.x, p.y + 1))) {\n                        arr1.add(new Point(p.x, p.y + 1));\n                    }\n                }\n\n                arr2.clear();\n\n                if (arr1.size() > 0) {\n                    lastValue = arr1.get(0);\n                }\n            }\n\n            out.println(lastValue.x + \" \" + lastValue.y);\n        }\n\n        boolean valid(Point p) {\n            if ((p.x < 1 || p.x > n) ||\n                    (p.y < 1 || p.y > m) ||\n                    or[p.x][p.y] == -1) {\n                return false;\n            }\n\n            or[p.x][p.y] = -1;\n\n            return true;\n        }\n\n        class Point {\n\n            int x;\n            int y;\n\n            public Point(int a, int b) {\n                x = a;\n                y = b;\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\n\n\n\n\n\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n \npublic class Solution35C {\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            \t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n                    out = new PrintWriter(\"output.txt\");\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 Solution35C().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 m = readInt();\n        \tint k = readInt();\n        \tPoint[] focuses = new Point[k];\n        \tfor(int i = 0; i < k; i++){\n        \t\tint a = readInt() - 1;\n        \t\tint b = readInt() - 1;\n        \t\tfocuses[i] = new Point(a,b);\n        \t}\n        \tint maxI = 0, maxJ = 0;\n        \tint max = 0;\n        \tfor(int i = 0; i < n; i++)\n        \t\tfor(int j = 0; j < m; j++){\n        \t\t\tint curMin = 1000000;\n        \t\t\tfor(int r = 0; r < k; r++)\n        \t\t\t\tif(abs(focuses[r].x - i) + abs(focuses[r].y - j) < curMin){\n        \t\t\t\t\tcurMin = abs(focuses[r].x - i) + abs(focuses[r].y - j);\n        \t\t\t\t\tif(curMin < max) break;\n        \t\t\t\t}\n    \t\t\t\tif(curMin > max){\n    \t\t\t\t\tmax = curMin;\n    \t\t\t\t\tmaxI = i;\n    \t\t\t\t\tmaxJ = j;\n    \t\t\t\t}              \t\t\t\n        \t\t}\n        \tmaxI++;\n        \tmaxJ++;\n        \tout.println(maxI + \" \" + maxJ);\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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "//package C;\n\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.Queue;\n\npublic class Fire_Again {\n    static int N;\n    static int M;\n    static int K;\n    private class Pos {\n        public int r;\n        public int c;\n        int last;\n        public Pos(int r,int c, int last) {\n            this.r = r;\n            this.c = c;\n            this.last = last;\n        }\n    }\n    static ArrayList<Pos> pos = new ArrayList<>();\n\n    static boolean[][] used;// = new boolean[2001][2001];\n    static int[] rows = {-1,1,0,0};\n    static int[] cols = {0,0,-1,1};\n    int LAST = 0;\n    int lastRow = 1;\n    int lastCol = 1;\n    public static void main(String[] args) throws IOException {\n        Fire_Again fire_again = new Fire_Again();\n        BufferedReader bufferedReader =\n                new BufferedReader(new FileReader(\"input.txt\"));\n        String[] nm = bufferedReader.readLine().split(\" \");\n        N = Integer.parseInt(nm[0]) + 1;\n        M = Integer.parseInt(nm[1]) + 1;\n        K = Integer.parseInt(bufferedReader.readLine());\n        used = new boolean[N][M];\n        String[] rc = bufferedReader.readLine().split(\" \");\n        for(int k = 0;k < rc.length;k+=2) {\n            int r = Integer.parseInt(rc[k]);\n            int c = Integer.parseInt(rc[k+1]);\n            pos.add(fire_again.new Pos(r,c,0));\n        }\n        fire_again.bfs();\n        PrintStream ps = new PrintStream(\"output.txt\");\n        ps.printf(\"%d %d\\n\",fire_again.lastRow,fire_again.lastCol);\n        ps.flush();\n        ps.close();\n    }\n     Queue<Pos> queue = new LinkedList<>();\n    private void bfs() {\n      queue.addAll(pos);\n      for(Pos p : pos) {\n          used[p.r][p.c] = true;\n        //  System.out.println(\"r = \"+(p.r) + \" c = \" + (p.c));\n      }\n      while(!queue.isEmpty()) {\n          Pos p = queue.poll();\n          if(p.last > LAST) {\n              LAST = p.last;\n              lastRow = p.r;\n              lastCol = p.c;\n          }\n          for(int i = 0;i < rows.length;i++) {\n              int currR = p.r;\n              int currC = p.c;\n              if(currR + rows[i] >= 1 && currR + rows[i] < N &&\n              currC + cols[i] >= 1 && currC + cols[i] < M &&\n              !used[currR + rows[i] ] [currC + cols[i] ] ) {\n              //    System.out.println(\"r = \"+(currR+rows[i]) + \" c = \" + (currC+cols[i]));\n                  queue.add(new Pos(currR+rows[i],currC+cols[i],p.last+1));\n                  used[currR + rows[i] ] [currC + cols[i] ] = true;\n              }\n          }\n      }\n\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.io.FileInputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.util.Collection;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Queue;\nimport java.io.IOException;\nimport java.io.FileOutputStream;\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;\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        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 n = in.nextInt();\n        int m = in.nextInt();\n        int k = in.nextInt();\n        Queue<Point> points = new LinkedList<Point>();\n        int[][] burnTime = new int[n][m];\n        boolean[][] visited = new boolean[n][m];\n        for (int i = 0; i < k; i++) {\n            int x = in.nextInt() - 1;\n            int y = in.nextInt() - 1;\n            visited[x][y] = true;\n            burnTime[x][y] = 0;\n            points.add(new Point(x, y));\n\n        }\n        int[] dx = new int[]{-1, 0, 0, 1};\n        int[] dy = new int[]{0, -1, 1, 0};\n        while (points.size() != 0) {\n            Point cur = points.poll();\n            int x = cur.x;\n            int y = cur.y;\n            for (int i = 0; i < dx.length; i++) {\n                int nextX = x + dx[i];\n                int nextY = y + dy[i];\n                if (nextX >= 0 && nextX < n && nextY >= 0 && nextY < m && (burnTime[x][y] + 1 < burnTime[nextX][nextY] || !visited[nextX][nextY])) {\n                    points.add(new Point(nextX, nextY));\n                    visited[nextX][nextY] = true;\n                    burnTime[nextX][nextY] = burnTime[x][y] + 1;\n                }\n            }\n        }\n        int x, y;\n        x = y = 0;\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (burnTime[i][j] > burnTime[x][y]) {\n                    x = i;\n                    y = j;\n                }\n            }\n        }\n        out.printf(\"%d %d\", x + 1, y + 1);\n    }\n}\n\nclass 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\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", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.util.*;\n\n\npublic class C {\n    private static boolean marked[][] ; \n    \n    \n    public static void main(String[] args) throws Exception {\n//        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n//        InputStream inputStream = System.in;\n//        OutputStream outputStream = System.out;\n//        InputReader s = new InputReader(inputStream);\n//        PrintWriter out = new PrintWriter(outputStream);\n        \n        \n         // input.txt / output.txt\n         File file = new File(\"input.txt\") ; \n         Scanner s = new Scanner(file) ; \n        \n        int n = s.nextInt();\n        int m = s.nextInt(); \n        \n        marked = new boolean [n + 1 ][m + 1] ; \n        \n        int k = s.nextInt();\n        \n        Queue<Point> queue = new LinkedList<Point>(); \n        \n        \n        for(int i =0 ; i < k ; ++i){\n            int tempX = s.nextInt() ;\n            int tempY = s.nextInt() ; \n            marked[tempX][tempY] = true ; \n            queue.add(new Point(tempX , tempY));             \n        }\n        \n         Point c = null ;\n        \n         while(!queue.isEmpty()){\n             c = queue.poll() ; \n            \n            if(c.x>1 && !marked[c.x-1][c.y]){\n                marked[c.x -1 ][c.y] = true ; \n                queue.add(new Point(c.x-1,c.y));\n            }\n            \n            if(c.y>1 && !marked[c.x][c.y-1]){\n                marked[c.x][c.y-1] = true ; \n                queue.add(new Point(c.x,c.y-1));\n            }\n            \n            if(c.x < n  && !marked[c.x+1][c.y]){\n                marked[c.x + 1 ][c.y] = true ; \n                queue.add(new Point(c.x + 1,c.y));\n            }\n            \n            if(c.y < m && !marked[c.x][c.y+1]){\n                marked[c.x][c.y+1] = true ; \n                queue.add(new Point(c.x,c.y+1));\n            }\n        }\n        PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n        out.println(c.x+\" \"+c.y); \n        out.close();\n\n    }\n    \n    static class Point {\n        int x ; \n        int y ; \n        public Point(int x  ,int y ){\n            this.x = x  ; \n            this.y = y ;\n        }\n    }\n}\n    \n    \n    \n    \n    \n    \n    \n    \n\n\nclass 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    public double nextDouble() {\n        return Double.parseDouble(next());\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*; \nimport java.util.*;\nimport java.util.regex.*;\n/*\n\t  br = new BufferedReader(new FileReader(\"input.txt\"));\n\t  pw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\t  br = new BufferedReader(new InputStreamReader(System.in));\n\t  pw = 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\tpublic static void main(String[] args) throws Exception {\n\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\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 r = readInt();\n\t\t\tint c = readInt();\n\t\t\tint n = readInt();\n\t\t\tint[][] dist = new int[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tArrays.fill(dist[i], 1 << 25);\n\t\t\t}\n\t\t\tLinkedList<State> q = new LinkedList<State>();\n\t\t\twhile(n-- > 0) {\n\t\t\t\tq.add(new State(readInt()-1, readInt()-1));\n\t\t\t\tdist[q.peekLast().x][q.peekLast().y] = 0;\n\t\t\t}\n\t\t\tint[] dx = new int[]{-1,1,0,0};\n\t\t\tint[] dy = new int[]{0,0,-1,1};\n\t\t\tState ret = q.peekLast();\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tState curr = q.removeFirst();\n\t\t\t\tret = curr;\n\t\t\t\tfor(int k = 0; k < dx.length; k++) {\n\t\t\t\t\tint nx = curr.x + dx[k];\n\t\t\t\t\tint ny = curr.y + dy[k];\n\t\t\t\t\tif(nx >= 0 && nx < r && ny >= 0 && ny < c && dist[nx][ny] > 1 + dist[curr.x][curr.y]) {\n\t\t\t\t\t\tdist[nx][ny] = 1 + dist[curr.x][curr.y];\n\t\t\t\t\t\tq.add(new State(nx, ny));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(ret.x+1 + \" \" + (ret.y+1));\n\t\t}\n\t\texitImmediately();\n\t}\n\n\tstatic class State {\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\t\t\n\t}\n\t\n\tprivate static void exitImmediately() {\n\t\tpw.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static long readLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextLine() throws IOException  {\n\t\tif(!br.ready()) {\n\t\t\texitImmediately();\n\t\t}\n\t\tst = null;\n\t\treturn br.readLine();\n\t}\n\n\tprivate static String nextToken() throws IOException  {\n\t\twhile(st == null || !st.hasMoreTokens())  {\n\t\t\tif(!br.ready()) {\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}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String args[]) throws IOException {\n\t\tFile f = new File(\"input.txt\");\n\t\tScanner sc = new Scanner(f);\n\t\tBufferedWriter bw = new BufferedWriter(new FileWriter(new File(\"output.txt\")));\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tboolean[][] grid = new boolean[n][m];\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < m; j++) \n\t\t\tgrid[i][j] = false;\n\t\tQueue<Pair> q = new LinkedList<>();\n\t\tint cnt = sc.nextInt();\n\t\tfor (int i = 0; i < cnt; i++) {\n\t\t\tint x = sc.nextInt();\n\t\t\tint y = sc.nextInt();\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tgrid[x][y] = true;\n\t\t\tq.add(new Pair(x, y));\n\t\t}\n\t\tPair last = new Pair(-1, -1);\n\t\twhile (!q.isEmpty()) {\n\t\t\tPair current = q.poll();\n\t\t\tlast = current;\n\t\t\tfor (int i = -1; i <= 1; i++) {\n\t\t\t\tfor (int j = -1; j <= 1; j++) {\n\t\t\t\t\tif (i != 0 && j != 0) continue;\n\t\t\t\t\tif (inside(current.x + i, current.y + j, n, m) &&\n\t\t\t\t\t\t\t!grid[current.x + i][current.y + j]) {\n\t\t\t\t\t\tgrid[current.x + i][current.y + j] = true;\n\t\t\t\t\t\tq.add(new Pair(current.x + i, current.y + j));\n\t\t\t\t\t\t//bw.append((current.x + i) + \" \" + (current.y + j) + \"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tbw.append((last.x + 1) + \" \" + (last.y + 1) + \"\\n\");\n\t\tbw.flush();\n\t\tbw.close();\n\t\t\n\t\tsc.close();\n\t}\n\tstatic class Pair {\n\t\tint x;\n\t\tint y;\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\tprivate static boolean inside(int a, int b, int n, int m) {\n\t\treturn (a >= 0 && a < n && b >= 0 && b < m);\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n\n\tprivate static int[] dx = {1, -1, 0, 0};\n\tprivate static int[] dy = {0, 0, -1, 1};\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tThread t = new Thread(null, null, \"~\", Runtime.getRuntime().maxMemory()){\n\t\t\t@Override\n\t\t\tpublic void run(){\n\t\t\t\ttry {\n\t\t\t\t\tsolve();\n\t\t\t\t} catch(Exception e) {\n\t\t\t\t\tSystem.err.println(\"ERROR\");\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tt.start();\n\t\tt.join();\t\n\t}\n\n\tpublic static void solve() throws Exception {\n\t\tScanner in = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\n\t\tint[][] time = new int[n][m];\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tArrays.fill(time[i], Integer.MAX_VALUE);\n\t\t}\n\n\t\tint qq = in.nextInt();\n\t\tint[] xs = new int[qq];\n\t\tint[] ys = new int[qq];\n\n\t\tfor(int i = 0; i < qq; ++i){\n\t\t\txs[i] = in.nextInt() - 1;\n\t\t\tys[i] = in.nextInt() - 1;\n\t\t}\n\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 k = 0; k < qq; ++k) {\n\t\t\t\t\tint dist = Math.abs(i - xs[k]) + Math.abs(j - ys[k]);\n\t\t\t\t\ttime[i][j] = Math.min(time[i][j], dist);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint max = -1;\n\t\tint x = -1;\n\t\tint y = -1;\n\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tfor(int j = 0; j < m; ++j) if(max < time[i][j]) {\n\n\t\t\t\tmax = time[i][j];\n\t\t\t\tx = i + 1;\n\t\t\t\ty = j + 1;\n\t\t\t} \n\t\t}\n\n\t\tout.println(x + \" \" + y);\n\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tprivate static class Pair {\n\t\tint f, s;\n\t\tint time;\n\n\t\tpublic Pair(int f, int s) {\n\t\t\tthis.f = f;\n\t\t\tthis.s = s;\n\t\t}\n\n\t\tpublic Pair(int f, int s, int time) {\n\t\t\tthis(f, s);\n\t\t\tthis.time = time;\n\t\t}\n\n\t}\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\tpublic static void main(String[] args) throws Exception {\n\t\tFile in = new File(\"input.txt\"), out = new File(\"output.txt\");\n\t\tScanner s;\n\t\tPrintWriter pw;\n\t\tif (in.exists()) {\n\t\t\ts = new Scanner(in);\n\t\t\tpw = new PrintWriter(out);\n\t\t} else {\n\t\t\ts = new Scanner(System.in);\n\t\t\tpw = new PrintWriter(System.out);\n\t\t}\n\t\tint n = s.nextInt(), m = s.nextInt();\n\t\tint k = s.nextInt();\n\t\tList<int[]> list = new ArrayList<int[]>();\n\t\tfor (int t = 0; t < k; ++t) {\n\t\t\tlist.add(new int[] { s.nextInt() - 1, s.nextInt() - 1 });\n\t\t}\n\t\tint max = 0, mi = 1, mj = 1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tint min = Integer.MAX_VALUE;\n\t\t\t\tfor (int[] p : list) {\n\t\t\t\t\tmin = Math.min(min, Math.abs(i - p[0]) + Math.abs(j - p[1]));\n\t\t\t\t}\n\t\t\t\tif (min > max) {\n\t\t\t\t\tmax = Math.max(max, min);\n\t\t\t\t\tmi = i + 1;\n\t\t\t\t\tmj = j + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpw.println(mi + \" \" + mj);\n\t\tpw.close();\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tstatic int[] di = {-1,0,1,0};\n\tstatic int[] dj = {0,1,0,-1};\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tScanner sc = new Scanner(\"input.txt\");\n\t\tPrintWriter out = new PrintWriter(\"output.txt\");\n\t\tQueue<Pair> q = new LinkedList<Pair>();\n\t\tint n = sc.nextInt(),m = sc.nextInt() , k = sc.nextInt();\n\t\tboolean [][] vis = new boolean[n][m];\n\t\twhile(k-->0)\n\t\t\tq.add(new Pair(sc.nextInt()-1,sc.nextInt()-1));\n\t\n\t\tint ansX = 1 , ansY = 1;\n\t\t\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tPair cur = q.poll();\n\t\t\tif(vis[cur.i][cur.j])continue;\n\t\t\tansX = cur.i ; ansY = cur.j;\n\t\t\tvis[cur.i][cur.j] = true;\n\t\t\tfor (int i = 0; i < di.length; i++) {\n\t\t\t\tint ni = cur.i + di[i] , nj = cur.j + dj[i];\n\t\t\t\tif(ni>=0 && ni<n && nj>=0 && nj<m && !vis[ni][nj])\n\t\t\t\t\tq.add(new Pair(ni,nj));\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.append(++ansX+\" \"+ ++ansY);\n\t\tout.flush();\n\t\t\n\t}\n\tstatic class Pair\n\t{\n\t\tint i,j;\n\t\tpublic Pair(int a,int b) {\n\t\t\ti = a; j = b;\n\t\t}\n\t}\n\t\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\t\tpublic Scanner(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t}\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 int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\t\t\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\t\t\n\t\tpublic double nextDouble() throws IOException {return Double.parseDouble(next());}\t\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n\t\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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(new FileReader(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\n\t\tint N=c.nextInt();\n\t\tint M=c.nextInt();\n\t\tint A[][]=new int[N][M];\n\t\tfor(int i=0;i<N;i++)\n\t\t\tArrays.fill(A[i],Integer.MAX_VALUE/100);\n\t\tint K=c.nextInt();\n\t\tfor(int i=0;i<K;i++)\n\t\t\t{\n\t\t\tint x=c.nextInt()-1;\n\t\t\tint y=c.nextInt()-1;\n\t\t\tfor(int i1=0;i1<N;i1++)\n\t\t\t\t{\n\t\t\t\tfor(int j1=0;j1<M;j1++)\n\t\t\t\t\tA[i1][j1]=Math.min(A[i1][j1],Math.abs(i1-x)+Math.abs(j1-y));\n\t\t\t\t}\n\t\t\t}\n\t\tint maxi=0;\n\t\tint maxj=0;\n\t\tfor(int i=0;i<N;i++)\n\t\t\t{\n\t\t\tfor(int j=0;j<M;j++)\n\t\t\t\t{\n\t\t\t\tif(A[i][j]>A[maxi][maxj])\n\t\t\t\t\t{\n\t\t\t\t\tmaxi=i;\n\t\t\t\t\tmaxj=j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tout.println((maxi+1)+\" \"+(maxj+1));\n\t\tout.close();\n\t\t}\n\t}\n\n//must declare new classes here", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class FireAgain {\n\n    int k, i, j,n,m,x,y;\n    void run() {\n        try {\n            BufferedReader bfd = new BufferedReader(new FileReader(\"input.txt\"));\n            BufferedWriter out = new BufferedWriter(new FileWriter(\"output.txt\"));\n//          BufferedReader bfd = new BufferedReader(new InputStreamReader(System.in));\n            StringTokenizer tk = new StringTokenizer(bfd.readLine());\n            \n            n = Integer.parseInt(tk.nextToken());\n            m = Integer.parseInt(tk.nextToken());\n            boolean vis[][] = new boolean[n][m];\n            k = Integer.parseInt(bfd.readLine());\n            tk = new StringTokenizer(bfd.readLine());\n            Queue<Point> q = new LinkedList<Point>();\n            Point last = new Point(0,0);\n            while(k-->0){\n                x = Integer.parseInt(tk.nextToken())-1;\n                y = Integer.parseInt(tk.nextToken())-1;\n                q.add(new Point(x,y));\n                vis[x][y] = true;\n            }\n            while(!q.isEmpty()) {\n                Point frnt = q.poll();\n                for(i=frnt.x-1;i<=frnt.x+1;++i)\n                    for(j=frnt.y-1;j<=frnt.y+1;++j)\n                        if(val(i,j)&& !vis[i][j]&&(frnt.x==i||frnt.y==j)){\n                            q.add(new Point(i,j));\n                            last = new Point(i,j);\n                            vis[i][j] = true;\n                        }\n            }\n//          System.out.println(last.x+1 + \" \" +(last.y+1));\n            out.write(last.x+1 + \" \" +(last.y+1)+\"\\n\");\n            out.flush();\n            out.close();\n        } catch (Exception e) {\n\n        }\n    }\n    \n    boolean val(int x,int y){\n        return x>=0&&x<n&&y>=0&&y<m;\n    }\n    public static void main(String[] args) {\n        new FireAgain().run();\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Queue;\nimport java.io.BufferedReader;\nimport java.util.LinkedList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Nasko\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        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int N = in.nextInt();\n            int M = in.nextInt();\n            int[][] dist = new int[N][M];\n            for (int[] ini : dist) Arrays.fill(ini, (1 << 30));\n\n\n            int K = in.nextInt();\n            Queue<Integer> q = new LinkedList<Integer>();\n            for (int k = 0; k < K; ++k) {\n                int r = in.nextInt() - 1;\n                int c = in.nextInt() - 1;\n                dist[r][c] = 0;\n                q.offer(r);\n                q.offer(c);\n            }\n\n            int[] dx = new int[]{1, -1, 0, 0};\n            int[] dy = new int[]{0, 0, 1, -1};\n            while (!q.isEmpty()) {\n                int rr = q.poll();\n                int cc = q.poll();\n                for (int a = 0; a < 4; ++a) {\n                    int x = dx[a] + rr;\n                    int y = dy[a] + cc;\n                    if (x >= 0 && x < N && y >= 0 && y < M) {\n                        if (dist[x][y] > dist[rr][cc] + 1) {\n                            dist[x][y] = dist[rr][cc] + 1;\n                            q.offer(x);\n                            q.offer(y);\n                        }\n                    }\n                }\n            }\n            int max = 0;\n            for (int i = 0; i < N; ++i)\n                for (int j = 0; j < M; ++j)\n                    max = Math.max(max, dist[i][j]);\n            for (int i = 0; i < N; ++i) {\n                for (int j = 0; j < M; ++j) {\n                    if (max == dist[i][j]) {\n                        out.println((i + 1) + \" \" + (j + 1));\n                        return;\n                    }\n                }\n            }\n        }\n\n    }\n\n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class BetaRound35_C implements Runnable {\n\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tvoid init() throws IOException {\n\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tout = new PrintWriter(\"output.txt\");\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\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new BetaRound35_C()).start();\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = readInt();\n\t\tint m = readInt();\n\t\tint k = readInt();\n\t\tQueue<Point> q = new ArrayDeque<Point>();\n\t\tboolean[][] visited = new boolean[n + 2][m + 2];\n\t\tfor (int j = 0; j < m + 2; j++) {\n\t\t\tvisited[0][j] = true;\n\t\t\tvisited[n + 1][j] = true;\n\t\t}\n\t\tfor (int i = 0; i < n + 2; i++) {\n\t\t\tvisited[i][0] = true;\n\t\t\tvisited[i][m + 1] = true;\n\t\t}\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint x = readInt();\n\t\t\tint y = readInt();\n\t\t\tq.add(new Point(x, y));\n\t\t\tvisited[x][y] = true;\n\t\t}\n\t\t\n\t\tPoint p = null;\n\t\twhile (!q.isEmpty()) {\n\t\t\tp = q.poll();\n\t\t\tint x = p.x, y = p.y;\n\t\t\tif (!visited[x + 1][y]) {\n\t\t\t\tq.add(new Point(x + 1, y));\n\t\t\t\tvisited[x + 1][y] = true;\n\t\t\t}\n\t\t\tif (!visited[x - 1][y]) {\n\t\t\t\tq.add(new Point(x - 1, y));\n\t\t\t\tvisited[x - 1][y] = true;\n\t\t\t}\n\t\t\tif (!visited[x][y + 1]) {\n\t\t\t\tq.add(new Point(x, y + 1));\n\t\t\t\tvisited[x][y + 1] = true;\n\t\t\t}\n\t\t\tif (!visited[x][y - 1]) {\n\t\t\t\tq.add(new Point(x, y - 1));\n\t\t\t\tvisited[x][y - 1] = true;\n\t\t\t}\n\t\t}\n\t\tout.print(p.x + \" \" + p.y);\n\t}\n\t\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/**\n * Created by tmdautov on 07.02.18.\n */\npublic class ArFireAgain {\n\n\n    int n, m, k;\n    int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };\n    int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };\n\n    int[][] dist;\n    ArrayList<Pair> arr;\n    // res -> get coordinates of most remote tree\n\n    Scanner sc;\n    PrintWriter out;\n\n    public void solve() {\n\n        try {\n            sc = new Scanner(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\n        } catch (FileNotFoundException e) {\n            e.printStackTrace();\n        }\n        //Scanner sc = new Scanner(System.in);\n        n = sc.nextInt();\n        m = sc.nextInt();\n        k = sc.nextInt();\n\n        arr = new ArrayList<Pair>();\n\n        for (int i=0; i<k; i++) {\n            int x = sc.nextInt()-1;\n            int y = sc.nextInt()-1;\n            Pair p = new Pair(x, y);\n            arr.add(p);\n        }\n\n\n        //out.println(\"helll\");\n        Pair last = bfs();\n        out.println(last.x + \" \" + last.y);\n        out.flush();\n        out.close();\n    }\n\n\n    boolean inBoard(int x, int y) {\n        return x >= n || x < 0 || y >= m || y < 0;\n    }\n    boolean isValid(int x, int y) {\n        return x >= 0 && y >= 0 && x < n && y < m;\n    }\n\n    private Pair bfs() {\n        // 1. create objects\n        Queue<Pair> q = new LinkedList<Pair>();\n        dist = new int[n][m];\n\n        // 2. fill dist array with -1\n        for (int i=0; i<n; i++) {\n            for (int j=0; j<m; j++) {\n                dist[i][j] = -1;\n            }\n        }\n\n        // 3. fill queue with fired k-trees\n        for (int i=0; i<k; i++) {\n            dist[arr.get(i).x][arr.get(i).y] = 0; // dist to fired trees is 0\n            q.add(arr.get(i));\n        }\n\n        // 4. run bfs\n        while(!q.isEmpty()) {\n            Pair cur = q.remove();\n\n            for (int d=0; d<4; d++) {\n                int X = cur.x + dx[d];\n                int Y = cur.y + dy[d];\n\n                if (isValid(X, Y) && dist[X][Y] == -1) {\n                    dist[X][Y] = dist[cur.x][cur.y] + 1;\n                    Pair p = new Pair(X, Y);\n                    q.add(p);\n                }\n            }\n\n            //System.out.println(cur);\n        }\n\n        // 5. find max pair by dist array\n        Pair res = null;\n        int maxx = -1;\n        for (int i=0; i<n; i++) {\n            for (int j=0; j<m; j++) {\n                if (dist[i][j] > maxx) {\n                    maxx = dist[i][j];\n                    res = new Pair(i+1, j+1);\n                }\n            }\n        }\n\n        return res;\n    }\n\n\n    // how to sort array of pairs?\n    class Pair {\n        int x, y;\n        Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n    }\n\n    public static void main(String[] args) {\n        new ArFireAgain().solve();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\nimport static java.lang.Math.*;\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        if (ONLINE_JUDGE) {\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new PrintWriter(\"output.txt\");\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 = 50;\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\n\n    class LOL implements Comparable<LOL> {\n\n        int x;\n        int y;\n\n\n\n        public LOL(int x, int y) {\n            this.x = x;\n            this.y = y;\n\n        }\n\n        @Override\n        public int compareTo(LOL o) {\n\n            return (x - o.x); // ---->\n            //return o.x * o.y - x * y; // <----\n        }\n\n    }\n\n    class LOL2 implements Comparable<LOL2> {\n\n        int x;\n        int y;\n        int z;\n\n\n\n        public LOL2(int x, int y, int z) {\n            this.x = x;\n            this.y = y;\n            this.z = z;\n        }\n\n        @Override\n        public int compareTo(LOL2 o) {\n\n            return (z - o.z); // ---->\n            //return o.x * o.y - x * y; // <----\n        }\n\n    }\n\n    class test implements Comparable<test> {\n\n        long x;\n        long y;\n\n\n\n        public test(long x, long y) {\n            this.x = x;\n            this.y = y;\n\n        }\n\n        @Override\n        public int compareTo(test o) {\n            //int compareResult = Long.compare(y, o.y); // ---->\n\n            //if (compareResult != 0) {\n            //    return -compareResult;\n            //}\n\n            int compareResult = Long.compare(x, o.x);\n\n            if (compareResult != 0) {\n                return compareResult;\n            }\n\n            return Long.compare(y, o.y);\n\n            //return o.x * o.y - x * y; // <----\n        }\n\n    }\n\n    class data {\n        String name;\n        String city;\n\n        data(String name, String city) {\n            this.city = city;\n            this.name = name;\n        }\n    }\n\n    class Point {\n        double x;\n        double y;\n\n\n        Point(double x, double y) {\n            this.x = x;\n            this.y = y;\n\n        }\n\n        double distance(Point temp) {\n            return Math.sqrt((x - temp.x) * (x - temp.x) + (y - temp.y) * (y - temp.y));\n        }\n\n        double sqrDist(Point temp) {\n            return ((x - temp.x) * (x - temp.x) + (y - temp.y) * (y - temp.y));\n        }\n\n        Point rotate(double alpha) {\n            return new Point(x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha));\n        }\n\n        void sum(Point o) {\n            x += o.x;\n            y += o.y;\n        }\n\n        void scalarProduct(int alpha) {\n            x *= alpha;\n            y *= alpha;\n        }\n\n    }\n\n    class Line {\n        double a;\n        double b;\n        double c;\n\n        Line(Point A, Point B) {\n            a = B.y - A.y;\n            b = A.x - B.x;\n            c = -A.x * a - A.y * b;\n        }\n        Line(double a, double b, double c) {\n            this.a = a;\n            this.b = b;\n            this.c = c;\n        }\n\n      Point intersection(Line o) {\n            double det = a * o.b - b * o.a;\n            double det1 = -c * o.b + b * o.c;\n            double det2 = -a * o.c + c * o.a;\n            return new Point(det1 / det, det2 / det);\n        }\n    }\n\n /*   class Plane {\n        double a;\n        double b;\n        double c;\n        double d;\n\n        Plane (Point fir, Point sec, Point thi) {\n            double del1 = (sec.y - fir.y) * (thi.z - fir.z) - (thi.y - fir.y) * (sec.z - fir.z);\n            double del2 = (thi.x - fir.x) * (sec.z - fir.z) - (thi.z - fir.z) * (sec.x - fir.x);\n            double del3 = (thi.y - fir.y) * (sec.x - fir.x) - (thi.x - fir.x) * (sec.y - fir.y);\n            a = del1;\n            b = del2;\n            c = del3;\n            d = -fir.x * del1 - fir.y * del2 - fir.z * del3;\n        }\n\n        double distance(Point point) {\n            return abs(a * point.x + b * point.y + c * point.z + d) / sqrt(a * a + b * b + c * c);\n        }\n\n\n    } */\n\n    class record implements Comparable<record> {\n        String city;\n        Long score;\n\n        public record(String name, Long score) {\n            this.city = name;\n            this.score = score;\n        }\n\n        @Override\n        public int compareTo(record o) {\n            if (o.city.equals(city)) {\n                return 0;\n            }\n\n            if (score.equals(o.score)) {\n                return 1;\n            }\n\n            if (score > o.score) {\n                return 666;\n            } else {\n                return -666;\n            }\n\n            //return Long.compare(score, o.score);\n\n        }\n\n    }\n\n    public long gcd(long a, long b) {\n        if (a == 0 || b == 0) return max(a, b);\n\n        if (a % b == 0)\n            return b;\n        else\n            return gcd(b, a % b);\n    }\n\n    boolean prime(long n) {\n        if (n == 1) return false;\n        for (int i = 2; i <= sqrt(n); i++)\n            if (n % i == 0)\n                return false;\n        return true;\n    }\n\n    public int sum(long n) {\n        int s = 0;\n\n        while (n > 0) {\n            s += (n % 10);\n            n /= 10;\n        }\n\n        return s;\n\n    }\n\n /*   public void simulation(int k) {\n        long ans = 0;\n        int start = 1;\n        for (int i = 0; i < k; i++) {\n            start *= 10;\n        }\n        for (int i = start/10; i < start; i++) {\n            int locAns = 0;\n            for (int j = start/10; j < start; j++) {\n                if  (sum(i + j) == sum(i) + sum(j) ) {\n                    ans += 1;\n                    locAns += 1;\n                } else {\n                    //.println(i + \"!!!\" + j);\n                }\n            }\n            //out.println(i + \" \" + locAns);\n        }\n        out.println(ans);\n    }*/\n\n\n\n\n    ArrayList<Integer> primes;\n    boolean[] isPrime;\n\n    public void getPrimes (int n) {\n        isPrime[0] = false;\n        isPrime[1] = false;\n        for (int i = 2; i <= n; i++) {\n            if (isPrime[i]) {\n                primes.add(i);\n                if (1l * i * i <= n) {\n                    for (int j = i * i; j <= n; j += i) {\n                        isPrime[j] = false;\n                    }\n                }\n            }\n        }\n    }\n\n\n\n\n    public long binPowMod(long a, long b, long mod) {\n        if (b == 0) {\n            return 1 % mod;\n        }\n\n        if (b % 2 != 0) {\n            return ((a % mod) * (binPowMod(a, b - 1, mod) % mod)) % mod;\n        } else {\n            long temp = binPowMod(a, b / 2, mod) % mod;\n            long ans = (temp * temp) % mod;\n            return ans;\n\n        }\n    }\n\n\n    int type[];\n    boolean vis[];\n\n    HashMap<Integer, HashSet<Integer>> g;\n\n    int componentNum[];\n\n  /*  void dfs(int u, int numOfComponent) {\n        vis[u] = true;\n        componentNum[u] = numOfComponent;\n\n        for (Integer v: g.get(u)) {\n            if (!vis[v]) {\n                dfs(v, numOfComponent);\n            }\n        }\n    } */\n\n    int p[];\n\n    int find(int x) {\n        if (x == p[x]) {\n            return x;\n        }\n\n        return p[x] = find(p[x]);\n    }\n\n    boolean merge(int x, int y) {\n        x = find(x);\n        y = find(y);\n        if (p[x] == p[y]) {\n            return false;\n        }\n        p[y] = x;\n        return true;\n    }\n\n    class Trajectory {\n        double x0;\n        double y0;\n        double vx;\n        double vy;\n\n\n        Trajectory(double vx, double vy, double x0, double y0) {\n            this.vx = vx;\n            this.vy = vy;\n\n            this.x0 = x0;\n            this.y0 = y0;\n        }\n\n        double y (double x) {\n            return y0 + (x - x0) * (vy / vx) - 5 * (x - x0) * (x - x0) / (vx * vx);\n        }\n\n        double der(double x) {\n            return (vy / vx) - 10 * (x - x0) / (vx * vx);\n        }\n\n\n    }\n\n    int s;\n    int n;\n    int m;\n    boolean isVisited[][];\n    char[][] maze;\n    int[] dx = {0, 0, -1, 1};\n    int[] dy = {1, -1, 0, 0};\n\n    void dfs(int x, int y) {\n        isVisited[x][y] = true;\n\n        for (int i = 0; i < 4; i++) {\n            int currX = x + dx[i];\n            int currY = y + dy[i];\n\n            if (maze[currX][currY] == '.' && !isVisited[currX][currY]) {\n                dfs(currX, currY);\n            }\n\n        }\n\n\n\n    }\n\n\n\n\n    public void solve() throws IOException {\n\n        n = readInt();\n        m = readInt();\n\n        maze = new char[n + 2][m + 2];\n\n        for (int i = 0; i < n + 2; i++) {\n            maze[i][0] = '#';\n            maze[i][m + 1] = '#';\n        }\n\n        for (int j = 0; j < m + 2; j++) {\n            maze[0][j] = '#';\n            maze[n + 1][j] = '#';\n        }\n\n        for (int i = 1; i <= n; i++) {\n            for (int j = 1; j <= m; j++) {\n                maze[i][j] = '.';\n            }\n        }\n\n        int[][] dist = new int[n + 2][m + 2];\n\n        for (int i = 0; i < n + 2; i++) {\n            for (int j = 0; j < m + 2; j++) {\n                dist[i][j] = Integer.MAX_VALUE;\n            }\n        }\n\n        ArrayDeque<Integer> xValues = new ArrayDeque<Integer>();\n        ArrayDeque<Integer> yValues = new ArrayDeque<Integer>();\n\n        int k = readInt();\n        for (int i = 0; i < k; i++) {\n            int currX = readInt();\n            int currY = readInt();\n            xValues.add(currX);\n            yValues.add(currY);\n            dist[currX][currY] = 0;\n        }\n\n\n\n        while(!xValues.isEmpty()) {\n            int x = xValues.poll();\n            int y = yValues.poll();\n\n            for (int i = 0; i < 4; i++) {\n                int currX = x + dx[i];\n                int currY = y + dy[i];\n\n                if (maze[currX][currY] == '.' && dist[currX][currY] > dist[x][y] + 1) {\n                    dist[currX][currY] = dist[x][y] + 1;\n                    xValues.add(currX);\n                    yValues.add(currY);\n                }\n\n            }\n\n        }\n\n        int maxDist = 0;\n        int indexX = 0;\n        int indexY = 0;\n\n        for (int i = 1; i <= n; i++) {\n            for (int j = 1; j <= m; j++) {\n                if (dist[i][j] >= maxDist) {\n                    maxDist = dist[i][j];\n                    indexX = i;\n                    indexY = j;\n                }\n            }\n        }\n\n        out.print(indexX + \" \" + indexY);\n\n\n\n\n\n    }\n\n\n\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.Dictionary;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic String[][] a;\n\tpublic void run () throws Exception {\n\t\tScanner in = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter pw = new PrintWriter(new  File(\"output.txt\"));\n\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\t\n\t\tint[] xx = new int[k];\n\t\tint[] yy = new int[k];\n\t\tfor(int i=0;i<k;i++){\n\t\t\txx[i] = in.nextInt();\n\t\t\tyy[i]= in.nextInt();\n\t\t}\n\t\tint x=0,y=0,r;\n\t\tr=-1;\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\tint rr = 1000000;\n\t\t\t\tfor(int q=0;q<k;q++)\n\t\t\t\t\trr = Math.min(rr, Math.abs(xx[q]-1-i)+Math.abs(yy[q]-1-j));\n\t\t\t\tif(rr>r){\n\t\t\t\t\tr=rr;\n\t\t\t\t\tx=i;\n\t\t\t\t\ty=j;\n\t\t\t\t}\n\t\t\t}\n\t\tpw.print((x+1)+\" \"+(y+1));\n\n\t\tpw.close();\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main ().run();\n\t}\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n// :%s/Cbeta35/\"name\"/\n// if (debug) \n\npublic class Cbeta35 {\n\tpublic static void main(String[] args) { new Cbeta35(); }\n\tScanner in;\n\tPrintWriter out;\n\n\tint t;\n\tint n, m, k, oo;\n\tint[][] grid;\n\n\tboolean debug = !true, multi = !true;\n\n\tCbeta35() {\n\t\tif (multi) t = in.nextInt();\n\t\tdo {\n\t\t\tif (multi) if (z(t--)) break;\n\n\t\t\ttry {\n\t\t\t\tin = new Scanner(new File(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tin = new Scanner(System.in);\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t}\n\n\t\t\tn = in.nextInt();\n\t\t\tm = in.nextInt();\n\t\t\tk = in.nextInt();\n\n\t\t\too = n + m + 1;\n\t\t\tgrid = new int[n][m];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tArrays.fill(grid[i], oo);\n\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\tint x = in.nextInt() - 1;\n\t\t\t\tint y = in.nextInt() - 1;\n\t\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\t\tfor (int kk = 0; kk < m; kk++) {\n\t\t\t\t\t\tint dx = j - x < 0 ? x - j : j - x;\n\t\t\t\t\t\tint dy = kk - y < 0 ? y - kk : kk - y;\n\t\t\t\t\t\tgrid[j][kk] = min(grid[j][kk], dx + dy);\n\t\t\t\t\t}\n\t\t\t}\n\n\t\t\tint x = 0, y = 0;\n\t\t\tint max = 0;\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\tif (max < grid[i][j]) {\n\t\t\t\t\t\tmax = grid[i][j];\n\t\t\t\t\t\tx = i; y = j;\n\t\t\t\t\t}\n\t\t\tout.printf(\"%d %d%n\", x + 1, y + 1);\n\n\t\t} while (debug || multi);\n\t\tout.close();\n\t}\n\n\t\n\n\tint min(int a, int b) { if (a < b) return a; return b; }\t\n\tint max(int a, int b) { if (a > b) return a; return b; }\t\n\tlong min(long a, long b) { if (a < b) return a; return b; }\t\n\tlong max(long a, long b) { if (a > b) return a; return b; }\t\n\n\tboolean z(int x) { if (x == 0) return true; return false; }\t\n\tboolean z(long x) { if (x == 0) return true; return false; }\t\n\n\tvoid sort(int[] arr) {\n\t\tint szArr = arr.length;\n\t\tRandom r = new Random();\n\t\tfor (int i = 0; i < szArr; i++) {\n\t\t\tint j = r.nextInt(szArr);\n\t\t\tarr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));\n\t\t}\n\t\tArrays.sort(arr);\n\t}\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\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\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 madis\n */\npublic class Pjar {\n\n    static int a[][];\n\n    public static void main(String[] args) throws FileNotFoundException {\n        Scanner in = new Scanner(new File(\"input.txt\"));\n        PrintWriter out = new PrintWriter(\"output.txt\");\n\n        int N = in.nextInt();\n        int M = in.nextInt();\n\n        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] = Integer.MAX_VALUE;\n            }\n        }\n        int k = in.nextInt();\n        in.nextLine();\n        for (int i = 0; i < k; i++) {\n            int x = in.nextInt();\n            int y = in.nextInt();\n            a[x - 1][y - 1] = 1;\n            burn(x - 1, y - 1);\n        }\n        int max = Integer.MIN_VALUE;\n        int x = 0;\n        int y = 0;\n        for (int i = 0; i < N; i++) {\n            for (int j = 0; j < M; j++) {\n                if(a[i][j]>max){\n                    max = a[i][j];\n                    x = i+1;\n                    y = j+1;\n                }\n            }\n        }\n        out.printf(\"%d %d\",x,y);\n        out.close();\n        in.close();\n    }\n\n    static void burn(int i, int j) {\n        for(int k = 0;k<a.length;k++){\n            for(int l=0;l<a[k].length;l++){\n                if(a[k][l]>Math.abs(k-i) + Math.abs(l-j)){\n                    a[k][l]=Math.abs(k-i) + Math.abs(l-j);\n                }\n            }\n        }\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n\npublic class R035CRetry {\n    public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); }\n    public static final int INF = 987654321;\n    public static final long LINF = 987654321987654321L;\n    public static final double EPS = 1e-9;\n    \n    Scanner scanner;\n    PrintWriter out;\n    boolean[][] bss;\n    \n    public R035CRetry() {\n        try {\n            this.scanner = new Scanner(new File(\"input.txt\"));\n            this.out = new PrintWriter(\"output.txt\");\n        } catch(FileNotFoundException ex) { ex.printStackTrace(); }\n    }\n    \n    class Point implements Comparable<Point> {\n        int x, y, count;\n        Point(int x, int y) { this.x = x; this.y = y; }\n        public int hashCode() { return x * 17 + y; }\n        public boolean equals(Object o) {\n            if(!(o instanceof Point)) return false;\n            Point that = (Point)o;\n            return this.x == that.x && this.y == that.y;\n        }\n        public int compareTo(Point that) { return this.count - that.count; }\n        public String toString()  { return \"(\" + x + \", \" + y + \":\" + count + \")\"; }\n    }\n\n    \n    int[] dx = new int[] {  0, 0, -1, 1 };\n    int[] dy= new int[] { -1, 1,  0, 0 };\n    int n, m;\n    \n    Queue<Point> q;\n    \n    Point bfs() {\n        int max = -INF;\n        Point p = null;\n        while(!q.isEmpty()) {\n            Point cur = q.remove();\n            if(max < cur.count) { max = cur.count; p = cur; } \n            for(int i=0; i<dx.length; i++) {\n                int nx = cur.x + dx[i];\n                int ny = cur.y + dy[i];\n                if(nx < 0 || nx >= n) { continue; }\n                if(ny < 0 || ny >= m) { continue; }\n                Point np = new Point(nx, ny);\n                if(bss[nx][ny] ) { continue; } \n                np.count = cur.count+1;\n                bss[nx][ny] = true;\n                q.add(np);\n            }\n        }\n        return p;\n    }\n    \n    private void solve() {\n        this.n = scanner.nextInt();\n        this.m = scanner.nextInt();\n        this.bss = new boolean[n][m];\n        int k = scanner.nextInt();\n        q = new PriorityQueue<Point>();\n        for(int i=0; i<k; i++) {\n            int x = scanner.nextInt() - 1;\n            int y = scanner.nextInt() - 1;\n            Point init = new Point(x, y);\n            init.count = 1;\n            q.add(init);\n            bss[x][y] = true;\n        }\n        Point p = bfs();\n        out.println((p.x+1) + \" \" + (p.y+1));\n    }\n    \n    private void finish() { this.out.close(); }\n    \n    public static void main(String[] args) { \n        R035CRetry obj = new R035CRetry();\n        obj.solve();\n        obj.finish();\n    }\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class cf35c {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner in = new Scanner(new File(\"input.txt\"));\n\t\tPrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tint[] dx = {0,0,1,-1};\n\t\tint[] dy = {1,-1,0,0};\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint[][] seen = new int[n][m];\n\t\tfor(int i=0; i<n; i++)\n\t\t\tArrays.fill(seen[i], -1);\n\t\tQueue<Integer> q = new LinkedList<Integer>();\n\t\tint k = in.nextInt();\n\t\tfor(int i=0; i<k; i++) {\n\t\t\tint x = in.nextInt()-1;\n\t\t\tint y = in.nextInt()-1;\n\t\t\tq.add(x);\n\t\t\tq.add(y);\n\t\t\tq.add(0);\n\t\t\tseen[x][y] = 0;\n\t\t}\n\t\twhile(!q.isEmpty()) {\n\t\t\tint x = q.poll();\n\t\t\tint y = q.poll();\n\t\t\tint t = q.poll();\n\t\t\tfor(int i=0; i<dx.length; i++) {\n\t\t\t\tint nx = x + dx[i];\n\t\t\t\tint ny = y + dy[i];\n\t\t\t\tif(nx < 0 || nx >= n || ny < 0 || ny >= m)\n\t\t\t\t\tcontinue;\n\t\t\t\tif(seen[nx][ny] != -1) continue;\n\t\t\t\tseen[nx][ny] = t+1;\n\t\t\t\tq.add(nx);\n\t\t\t\tq.add(ny);\n\t\t\t\tq.add(t+1);\n\t\t\t}\n\t\t}\n\t\tint best=-1,x=0,y=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(seen[i][j] > best) {\n\t\t\t\t\tbest = seen[i][j];\n\t\t\t\t\tx = i+1;\n\t\t\t\t\ty = j+1;\n\t\t\t\t}\n\t\tout.println(x + \" \" +y);\n\t\tout.close();\n\t}\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class FireAgain {\n\n    public static void main(String[] args) throws IOException {\n\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\tSystem.setOut(new PrintStream(\"output.txt\"));\n        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s[] = r.readLine().split(\"\\\\s+\");\n\t\tint n = Integer.parseInt(s[0]);\n\t\tint m = Integer.parseInt(s[1]);\n\t\tint k = Integer.parseInt(r.readLine());\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] = Integer.MAX_VALUE;\n\t\t}\n\t\tassert k >= 1 && k < n * m;\n\t\tint max = 0;\n\t\tStringTokenizer st = new StringTokenizer(r.readLine());\n\t\tassert st.countTokens() == k;\n\t\tfor(; k > 0; k--) {\n\t\t\tint x = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tint y = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tassert x >= 1 && x <= n && y >= 1 && y <= n;\n\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\t\tint d = Math.abs(i - x) + Math.abs(j - y);\n\t\t\t\t\tif(a[i][j] > d)\n\t\t\t\t\t\ta[i][j] = d;\n\t\t\t\t\tif(k == 1 && a[i][j] > max)\n\t\t\t\t\t\tmax = a[i][j];\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\tfor(int j = 0; j < m; j++) {\n\t\t\t\tif(a[i][j] == max) {\n\t\t\t\t\tSystem.out.println((i + 1) + \" \" + (j + 1));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.File;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n\npublic class C2 {\n\n    public static void main(String[] args) throws IOException{\n        Scanner sc = new Scanner(new File(\"input.txt\"));\n        PrintWriter pw = new PrintWriter(new File(\"output.txt\"));\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n        int[]x = new int[k+1], y = new int[k+1];\n        for (int i = 1; i <= k; i++) {\n            y[i] = sc.nextInt();\n            x[i] = sc.nextInt();\n        }\n        int max = -1, y0 = 0, x0 = 0;\n        for (int i = 1; i <= n; i++) {\n            for (int j = 1; j <= m; j++) {\n                int min = n+m+2;\n                for (int j2 = 1; j2 <= k; j2++) {\n                    min = Math.min(min, Math.abs(i-y[j2])+Math.abs(j-x[j2]));\n                }\n                if (min > max) {\n                    max = min;\n                    y0 = i;\n                    x0 = j;\n                }\n            }\n        }\n        pw.println(y0+\" \"+x0);\n        pw.close();\n    }\n\n}\n", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.util.HashSet;\nimport java.io.PrintWriter;\nimport java.io.File;\npublic class FireAgain {\n\n    public static void main(String[] args){\n\t\n\tFile in = new File(\"input.txt\");\n\tFile out = new File(\"output.txt\");\n\tScanner sc;\n\tPrintWriter pw;\n\ttry{\n\t    sc = new Scanner(in);\n\t    pw = new PrintWriter(out);\n\t}catch(Exception e){\n\t    sc = new Scanner(System.in);\n\t    pw = null;\n\t}\n\n\tint max_x = sc.nextInt();\n\tint max_y = sc.nextInt();\n\tint start_num = sc.nextInt();\n\tHashSet<int[]> start = new HashSet<int[]>();\n\tfor(int i=0; i<start_num; i++){\n\t    int[] cell = new int[2];\n\t    cell[0] = sc.nextInt();\n\t    cell[1] = sc.nextInt();\n\t    start.add(cell);\n\t}\n\n\tint[] result = new int[]{1,1};\n\tint resultLen = 0;\n\tfor(int i=1; i<=max_x; i++){\n\t    for(int j=1; j<=max_y; j++){\n\t\tint[] sh = new int[]{1,1};\n\t\tint shLen = Integer.MAX_VALUE;\n\t\tfor(int[] fired: start){\n\t\t    int len = Math.abs(i - fired[0]) + Math.abs(j - fired[1]);\n\t\t    if(len < shLen){\n\t\t\tsh[0] = i;\n\t\t\tsh[1] = j;\n\t\t\tshLen = len;\n\t\t    }\n\t\t}\n\t\tif(shLen > resultLen){\n\t\t    result[0] = sh[0];\n\t\t    result[1] = sh[1];\n\t\t    resultLen = shLen;\n\t\t}\n\t    }\n\t}\n\tpw.print(result[0] + \" \" + result[1]);\n\tpw.close();\n\treturn ;\n    }\n}  ", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class CodeForces {\n    public static void main(String[] args) throws FileNotFoundException {\n        FastIO io = new FastIO();\n\n        int width = io.nextInt();\n        int height = io.nextInt();\n\n        int initials = io.nextInt();\n\n        boolean[][] visited = new boolean[width][height];\n\n        Queue<Coordinate> q = new ArrayDeque<>();\n\n        for (int i = 0; i < initials; i++) {\n            q.add(new Coordinate(io.nextInt() - 1, io.nextInt() - 1));\n        }\n\n        Coordinate oneOfLast = null;\n\n        while (!q.isEmpty()) {\n            int len = q.size();\n            for (int times = 0; times < len; times++) {\n                Coordinate c = q.poll();\n                if (visited[c.x][c.y]) {\n                    continue;\n                }\n\n                oneOfLast = c;\n                visited[c.x][c.y] = true;\n\n                int[][] deltas = new int[][]{\n                        {-1, 0}, {0, -1}, {1, 0}, {0, 1}\n                };\n\n                for (int[] delta : deltas) {\n                    int ci = c.y + delta[0];\n                    int cj = c.x + delta[1];\n\n                    if (ci >= 0 && cj >= 0 && ci < height && cj < width) {\n                        q.add(new Coordinate(cj, ci));\n                    }\n                }\n            }\n        }\n\n        io.println((oneOfLast.x + 1) + \" \" + (oneOfLast.y + 1));\n\n        io.close();\n    }\n\n    static class Coordinate {\n        int x;\n        int y;\n\n        public Coordinate(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n    }\n\n    static class FastIO extends PrintWriter {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastIO() throws FileNotFoundException {\n            super(new BufferedOutputStream(new FileOutputStream(\"output.txt\")));\n            br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\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 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        String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return \"\";\n        }\n    }\n}", "complexity": "cubic", "problem": "35_C. Fire Again", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt == 0 ? 1 : 0;\n\t\tif (remCnt < 0 || remSum < 0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt1 == 0 && remCnt2 == 0 ? 1 : 0;\n\t\tif (remSum < 0 || remCnt1 < 0 || remCnt2 < 0)\n\t\t\treturn 0;\n\t\tif (memo2[idx][remCnt1][remCnt2][remSum] != -1)\n\t\t\treturn memo2[idx][remCnt1][remCnt2][remSum];\n\t\tint ans = dp2(idx + 1, remCnt1, remCnt2, remSum);\n\n\t\tif (g[idx] == 1)\n\t\t\tans += dp2(idx + 1, remCnt1 - 1, remCnt2, remSum - t[idx]);\n\t\telse if (g[idx] == 2)\n\t\t\tans += dp2(idx + 1, remCnt1, remCnt2 - 1, remSum - t[idx]);\n\t\tif(ans>=MOD)\n\t\t\tans-=MOD;\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 < 0 || cnt1 < 0 || cnt2 < 0)\n\t\t\treturn 0;\n\t\tif (cnt0 + cnt1 + cnt2 == 0)\n\t\t\treturn 1;\n\t\tif (memo3[last][cnt0][cnt1][cnt2] != -1)\n\t\t\treturn memo3[last][cnt0][cnt1][cnt2];\n\t\tlong ans = 0;\n\t\tif (last != 0)\n\t\t\tans += dp3(cnt0 - 1, cnt1, cnt2, 0);\n\t\tif (last != 1)\n\t\t\tans += dp3(cnt0, cnt1 - 1, cnt2, 1);\n\t\tif (last != 2)\n\t\t\tans += dp3(cnt0, cnt1, cnt2 - 1, 2);\n\t\treturn memo3[last][cnt0][cnt1][cnt2] = (int) (ans % MOD);\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.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        OutputWriter out = new OutputWriter(outputStream);\n        TaskG2 solver = new TaskG2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG2 {\n        static final int MOD = 1000000000 + 7;\n        static final int MAXN = 51;\n\n        int getWays(int i, int j, int k, int l, int[][][][] ways, boolean[][][][] cached) {\n            if (i + j + k == 0) return l == -1 ? 1 : 0;\n            if (l < 0) return 0;\n            if (cached[i][j][k][l]) return ways[i][j][k][l];\n            int s = i + j + k;\n            long value = 0;\n            if (l == 0 && i != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i - 1, j, k, x, ways, cached);\n                    }\n            }\n            if (l == 1 && j != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j - 1, k, x, ways, cached);\n                    }\n            }\n            if (l == 2 && k != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j, k - 1, x, ways, cached);\n                    }\n            }\n            ways[i][j][k][l] = (int) (value % MOD);\n            cached[i][j][k][l] = true;\n            return ways[i][j][k][l];\n        }\n\n        int totalWays(int i, int j, int k, int[][][][] ways, boolean[][][][] cached, int[] factorial) {\n            long ret = 0;\n            for (int l = 0; l < 3; l++) ret += getWays(i, j, k, l, ways, cached);\n            ret *= factorial[i];\n            ret %= MOD;\n\n            ret *= factorial[j];\n            ret %= MOD;\n\n            ret *= factorial[k];\n            ret %= MOD;\n\n            return (int) ret;\n        }\n\n        int add(int type, int value, int[] sizes, int sum, int[][][][] dp) {\n            sizes[type]++;\n            if (type == 0) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 1; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n                                dp[i][j][k][s] += dp[i - 1][j][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 1) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 1; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j - 1][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 2) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 1; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j][k - 1][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            return sum + value;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int[][][][] ways = new int[MAXN][MAXN][MAXN][3];\n            boolean[][][][] cached = new boolean[MAXN][MAXN][MAXN][3];\n//        Arrays.fill(ways, -1);\n\n            int n = in.nextInt(), T = in.nextInt();\n\n            ArrayList<Integer>[] ar = new ArrayList[3];\n            for (int i = 0; i < 3; i++) ar[i] = new ArrayList<Integer>();\n            int total_sum = 0;\n            for (int i = 0; i < n; i++) {\n                int t = in.nextInt(), g = in.nextInt();\n                ar[g - 1].add(t);\n                total_sum += t;\n            }\n\n            if (T > total_sum) {\n                out.println(0);\n                return;\n            }\n            int min_index = 0, mn = 0;\n\n            for (int i = 0; i < 3; i++) {\n                if (ar[i].size() > mn) {\n                    mn = ar[i].size();\n                    min_index = i;\n                }\n            }\n\n            int[][][][] dp = new int[ar[(1 + min_index) % 3].size() + 1][ar[(2 + min_index) % 3].size() + 1][1][total_sum + 1];\n            int[][][][] dp2 = new int[1][1][mn + 1][total_sum + 1];\n            dp[0][0][0][0] = dp2[0][0][0][0] = 1;\n            int[] sizes = {0, 0, 0};\n            int sum = 0;\n            int[] order = {(min_index + 1) % 3, (min_index + 2) % 3};\n            int type = 0;\n            for (int i : order) {\n                for (int v : ar[i])\n                    sum = add(type, v, sizes, sum, dp);\n                type++;\n            }\n            sum = 0;\n            sizes[0] = sizes[1] = sizes[2] = 0;\n            for (int i : ar[min_index])\n                sum = add(2, i, sizes, sum, dp2);\n            int[] factorial = new int[MAXN];\n            factorial[0] = 1;\n            for (int i = 1; i < MAXN; i++)\n                factorial[i] = (int) ((factorial[i - 1] * 1L * i) % MOD);\n\n            long answer = 0;\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 <= mn; k++)\n                        for (int s = 0; s <= T; s++) {\n\n                            long x = (dp[i][j][0][s] * 1L * totalWays(i, j, k, ways, cached, factorial)) % MOD;\n                            x *= dp2[0][0][k][T - s];\n                            x %= MOD;\n                            answer += x;\n\n                        }\n            out.println(answer % MOD);\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)) 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            }\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 println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\n');\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "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 % 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}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt==0 ? 1 : 0;\n\t\tif (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 && remCnt>0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\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\n\t\t}\n\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 + 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\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "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\tlong MOD = 1_000_000_007;\n\tpublic void run() throws Exception {\n\t\tFastScanner f = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = f.nextInt(), m = f.nextInt();\n\t\tint[] t = new int[n], g = new int[n], c = new int[3];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tt[i] = f.nextInt();\n\t\t\tc[g[i] = f.nextInt()-1]++;\n\t\t}\n\t\tlong[][] dp1 = new long[c[0]+1][m+1];\n\t\tlong[][][] dp2 = new long[c[1]+1][c[2]+1][m+1];\n\t\tdp1[0][0] = 1;\n\t\tdp2[0][0][0] = 1;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(g[i] == 0) {\n\t\t\t\tfor(int j = dp1.length-2; j >= 0; j--)\n\t\t\t\t\tfor(int k = m-t[i]; k >= 0; k--)\n\t\t\t\t\t\tdp1[j+1][k+t[i]] = (dp1[j+1][k+t[i]] + dp1[j][k]) % MOD;\n\t\t\t} else if(g[i] == 1) {\n\t\t\t\tfor(int j = dp2.length-2; j >= 0; j--)\n\t\t\t\t\tfor(int k = dp2[j].length-1; k >= 0; k--)\n\t\t\t\t\t\tfor(int l = m-t[i]; l >= 0; l--)\n\t\t\t\t\t\t\tdp2[j+1][k][l+t[i]] = (dp2[j+1][k][l+t[i]] + dp2[j][k][l]) % MOD;\n\t\t\t} else {\n\t\t\t\tfor(int j = dp2.length-1; j >= 0; j--)\n\t\t\t\t\tfor(int k = dp2[j].length-2; k >= 0; k--)\n\t\t\t\t\t\tfor(int l = m-t[i]; l >= 0; l--)\n\t\t\t\t\t\t\tdp2[j][k+1][l+t[i]] = (dp2[j][k+1][l+t[i]] + dp2[j][k][l]) % MOD;\n\t\t\t}\n\t\t}\n\t\tlong[][][][] combo = new long[c[0]+1][c[1]+1][c[2]+1][3];\n\t\tif(c[0] != 0) combo[1][0][0][0] = 1;\n\t\tif(c[1] != 0) combo[0][1][0][1] = 1;\n\t\tif(c[2] != 0) combo[0][0][1][2] = 1;\n\t\tfor(int i = 0; i <= c[0]; i++) {\n\t\t\tfor(int j = 0; j <= c[1]; j++) {\n\t\t\t\tfor(int k = 0; k <= c[2]; k++) {\n\t\t\t\t\tfor(int a = 0; a < 3; a++) {\n\t\t\t\t\t\tif(a != 0 && i < c[0]) combo[i+1][j][k][0] = (combo[i+1][j][k][0] + combo[i][j][k][a] * (i+1) % MOD) % MOD;\n\t\t\t\t\t\tif(a != 1 && j < c[1]) combo[i][j+1][k][1] = (combo[i][j+1][k][1] + combo[i][j][k][a] * (j+1) % MOD) % MOD;\n\t\t\t\t\t\tif(a != 2 && k < c[2]) combo[i][j][k+1][2] = (combo[i][j][k+1][2] + combo[i][j][k][a] * (k+1) % MOD) % MOD;\n\t\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 s = 0; s <= m; s++) {\n\t\t\tfor(int x = 0; x <= c[0]; x++)\n\t\t\t\tfor(int y = 0; y <= c[1]; y++)\n\t\t\t\t\tfor(int z = 0;z <= c[2]; z++) {\n\t\t\t\t\t\tans = (ans + dp1[x][s] * dp2[y][z][m-s] % MOD * ((combo[x][y][z][0] + combo[x][y][z][1] + combo[x][y][z][2]) % MOD) % MOD) % MOD;\n\t\t\t\t\t}\n\t\t}\n\t\t/*\n\t\tfor(int i = 0; i < dp1.length; i++)\n\t\t\tout.println(Arrays.toString(dp1[i]));\n\t\tout.println(\"-----\");\n\t\tfor(int i = 0; i < dp2.length; i++) {\n\t\t\tfor(int j = 0; j < dp2[i].length; j++) \n\t\t\t\t\tout.println(Arrays.toString(dp2[i][j]));\n\t\t\t\tout.println();\n\t\t\t}\n\t\tfor(int i = 0; i <= c[0]; i++) for(int j = 0; j <= c[1]; j++) for(int k = 0; k <= c[2]; k++) out.printf(\"%d %d %d: %d%n\", i, j, k, combo[i][j][k][0] + combo[i][j][k][1] + combo[i][j][k][2]); */\n\t\tout.println(ans);\n\t\t///\n\t\tout.flush();\n\t}\n    static class FastScanner {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n        public FastScanner() {\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        public String nextLine() {\n        \ttry {\n        \t\treturn reader.readLine();\n        \t} catch(IOException e) {\n        \t\tthrow new RuntimeException(e);\n        \t}\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "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\tint []cnt=new int [3];\n\t\tfac[0]=1;\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tfac[i]=(int) (i*1L*fac[i-1]%MOD);\n\t\tint T=sc.nextInt();\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tt[i]=sc.nextInt();\n\t\t\tg[i]=sc.nextInt()-1;\n\t\t\tcnt[g[i]]++;\n\t\t\t\n\t\t}\n\t\tmemo1=new int [n][cnt[0]+1][T+1];\n\t\tmemo2=new int [n][cnt[1]+1][cnt[2]+1][T+1];\n\t\tmemo3=new int [4][cnt[0]+1][cnt[1]+1][cnt[2]+1];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<=cnt[0];j++) \n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor(int j=0;j<=cnt[1];j++) \n\t\t\t\tfor(int k=0;k<=cnt[2];k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\t\t\t\n\t\t}\n\t\tfor(int i=0;i<4;i++)\n\t\t\tfor(int j=0;j<=cnt[0];j++)\n\t\t\t\tfor(int k=0;k<=cnt[1];k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans=0;\n\t\tfor(int cnt0=0;cnt0<=cnt[0];cnt0++)\n\t\t\tfor(int sum0=0;sum0<=T;sum0++)\n\t\t\t\tfor(int cnt1=0;cnt1<=cnt[1];cnt1++)\n\t\t\t\t\tfor(int cnt2=0;cnt2<=cnt[2];cnt2++) {\n\t\t\t\t\t\tlong ways= dp1(0,cnt0,sum0)*1L*dp2(0,cnt1,cnt2,T-sum0)%MOD;\n\t\t\t\t\t\tways=ways*dp3(cnt0,cnt1,cnt2,3)%MOD;\n\t\t\t\t\t\tways*=fac[cnt0];\n\t\t\t\t\t\tways%=MOD;\n\t\t\t\t\t\tways*=fac[cnt1];\n\t\t\t\t\t\tways%=MOD;\n\t\t\t\t\t\tways*=fac[cnt2];\n\t\t\t\t\t\tways%=MOD;\n\t\t\t\t\t\tans+=ways;\n\t\t\t\t\t\tif(ans>=MOD)\n\t\t\t\t\t\t\tans-=MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\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}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt == 0 ? 1 : 0;\n\t\tif (remCnt < 0 || remSum < 0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt1 == 0 && remCnt2 == 0 ? 1 : 0;\n\t\tif (remSum < 0 || remCnt1 < 0 || remCnt2 < 0)\n\t\t\treturn 0;\n\t\tif (memo2[idx][remCnt1][remCnt2][remSum] != -1)\n\t\t\treturn memo2[idx][remCnt1][remCnt2][remSum];\n\t\tint ans = dp2(idx + 1, remCnt1, remCnt2, remSum);\n\n\t\tif (g[idx] == 1)\n\t\t\tans += dp2(idx + 1, remCnt1 - 1, remCnt2, remSum - t[idx]);\n\t\telse if (g[idx] == 2)\n\t\t\tans += dp2(idx + 1, remCnt1, remCnt2 - 1, remSum - t[idx]);\n\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 < 0 || cnt1 < 0 || cnt2 < 0)\n\t\t\treturn 0;\n\t\tif (cnt0 + cnt1 + cnt2 == 0)\n\t\t\treturn 1;\n\t\tif (memo3[last][cnt0][cnt1][cnt2] != -1)\n\t\t\treturn memo3[last][cnt0][cnt1][cnt2];\n\t\tlong ans = 0;\n\t\tif (last != 0)\n\t\t\tans += dp3(cnt0 - 1, cnt1, cnt2, 0);\n\t\tif (last != 1)\n\t\t\tans += dp3(cnt0, cnt1 - 1, cnt2, 1);\n\t\tif (last != 2)\n\t\t\tans += dp3(cnt0, cnt1, cnt2 - 1, 2);\n\t\treturn memo3[last][cnt0][cnt1][cnt2] = (int) (ans % MOD);\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.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        OutputWriter out = new OutputWriter(outputStream);\n        TaskG2 solver = new TaskG2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG2 {\n        static final int MOD = 1000000000 + 7;\n        static final int MAXN = 51;\n\n        int getWays(int i, int j, int k, int l, int[][][][] ways, boolean[][][][] cached) {\n            if (i + j + k == 0) return l == -1 ? 1 : 0;\n            if (l < 0) return 0;\n            if (cached[i][j][k][l]) return ways[i][j][k][l];\n            int s = i + j + k;\n            long value = 0;\n            if (l == 0 && i != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i - 1, j, k, x, ways, cached);\n                    }\n            }\n            if (l == 1 && j != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j - 1, k, x, ways, cached);\n                    }\n            }\n            if (l == 2 && k != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j, k - 1, x, ways, cached);\n                    }\n            }\n            ways[i][j][k][l] = (int) (value % MOD);\n            cached[i][j][k][l] = true;\n            return ways[i][j][k][l];\n        }\n\n        int totalWays(int i, int j, int k, int[][][][] ways, boolean[][][][] cached, int[] factorial) {\n            long ret = 0;\n            for (int l = 0; l < 3; l++) ret += getWays(i, j, k, l, ways, cached);\n            ret *= factorial[i];\n            ret %= MOD;\n\n            ret *= factorial[j];\n            ret %= MOD;\n\n            ret *= factorial[k];\n            ret %= MOD;\n\n            return (int) ret;\n        }\n\n        int add(int type, int value, int[] sizes, int sum, int[][][][] dp) {\n            sizes[type]++;\n            if (type == 0) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 1; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n                                dp[i][j][k][s] += dp[i - 1][j][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 1) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 1; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j - 1][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 2) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 1; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j][k - 1][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            return sum + value;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int[][][][] ways = new int[MAXN][MAXN][MAXN][3];\n            boolean[][][][] cached = new boolean[MAXN][MAXN][MAXN][3];\n//        Arrays.fill(ways, -1);\n\n            int n = in.nextInt(), T = in.nextInt();\n\n            ArrayList<Integer>[] ar = new ArrayList[3];\n            for (int i = 0; i < 3; i++) ar[i] = new ArrayList<Integer>();\n            int total_sum = 0;\n            for (int i = 0; i < n; i++) {\n                int t = in.nextInt(), g = in.nextInt();\n                ar[g - 1].add(t);\n                total_sum += t;\n            }\n\n            if (T > total_sum) {\n                out.println(0);\n                return;\n            }\n            int min_index = 0, mn = 0;\n\n            for (int i = 0; i < 3; i++) {\n                if (ar[i].size() > mn) {\n                    mn = ar[i].size();\n                    min_index = i;\n                }\n            }\n\n            int[][][][] dp = new int[ar[(1 + min_index) % 3].size() + 1][ar[(2 + min_index) % 3].size() + 1][1][total_sum + 1];\n            int[][][][] dp2 = new int[1][1][mn + 1][total_sum + 1];\n            dp[0][0][0][0] = dp2[0][0][0][0] = 1;\n            int[] sizes = {0, 0, 0};\n            int sum = 0;\n            int[] order = {(min_index + 1) % 3, (min_index + 2) % 3};\n            int type = 0;\n            for (int i : order) {\n                for (int v : ar[i])\n                    sum = add(type, v, sizes, sum, dp);\n                type++;\n            }\n            sum = 0;\n            sizes[0] = sizes[1] = sizes[2] = 0;\n            for (int i : ar[min_index])\n                sum = add(2, i, sizes, sum, dp2);\n            int[] factorial = new int[MAXN];\n            factorial[0] = 1;\n            for (int i = 1; i < MAXN; i++)\n                factorial[i] = (int) ((factorial[i - 1] * 1L * i) % MOD);\n\n            long answer = 0;\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 <= mn; k++)\n                        for (int s = 0; s <= T; s++) {\n\n                            long x = (dp[i][j][0][s] * 1L * totalWays(i, j, k, ways, cached, factorial)) % MOD;\n                            x *= dp2[0][0][k][T - s];\n                            x %= MOD;\n                            answer += x;\n\n                        }\n            out.println(answer % MOD);\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)) 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            }\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 println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\n');\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt == 0 ? 1 : 0;\n\t\tif (remCnt < 0 || remSum < 0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt1 == 0 && remCnt2 == 0 ? 1 : 0;\n\t\tif (remSum < 0 || remCnt1 < 0 || remCnt2 < 0)\n\t\t\treturn 0;\n\t\tif (memo2[idx][remCnt1][remCnt2][remSum] != -1)\n\t\t\treturn memo2[idx][remCnt1][remCnt2][remSum];\n\t\tint ans = dp2(idx + 1, remCnt1, remCnt2, remSum);\n\n\t\tif (g[idx] == 1)\n\t\t\tans += dp2(idx + 1, remCnt1 - 1, remCnt2, remSum - t[idx]);\n\t\telse if (g[idx] == 2)\n\t\t\tans += dp2(idx + 1, remCnt1, remCnt2 - 1, remSum - t[idx]);\n\t\tif (ans >= MOD)\n\t\t\tans -= MOD;\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 + 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\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int();\n            int k=Int();\n            int A[][]=new int[n][2];\n            int a=0,b=0,c=0;\n            for(int i=0;i<A.length;i++){\n                A[i][0]=Int();\n                A[i][1]=Int()-1;\n\n                if(A[i][1]==0)a++;\n                else if(A[i][1]==1)b++;\n                else c++;\n            }\n            Solution sol=new Solution(out);\n            sol.solution(A,k,a,b,c);\n        }\n        out.close();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n\n    int mod=1000000007;\n    long dp3[][][][];\n    public void solution(int A[][],int T,int x,int y,int z){\n        long res=0;\n        int n=A.length;\n        long dp1[][]=new long[x+1][T+1];//a\n        long dp2[][][]=new long[y+1][z+1][T+1];//bc\n        dp3=new long[x+2][y+2][z+2][3];\n\n\n        //System.out.println(x+\" \"+y+\" \"+z);\n\n        //init\n        long f[]=new long[n+10];\n        f[0]=f[1]=1;\n        for(int i=2;i<f.length;i++){\n            f[i]=f[i-1]*i;\n            f[i]%=mod;\n        }\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    Arrays.fill(dp3[i][j][k],-1);\n                }\n            }\n        }\n\n\n        dp1[0][0]=1;\n        long newdp1[][]=new long[dp1.length][dp1[0].length];\n        for(int i=0;i<A.length;i++){//a\n            int p=A[i][0],type=A[i][1];\n            if(type==0){\n\n                for(int cnt=1;cnt<=x;cnt++){\n                    for(int j=1;j<dp1[0].length;j++){\n                        if(j>=p){\n                            newdp1[cnt][j]+=dp1[cnt-1][j-p];\n                            newdp1[cnt][j]%=mod;\n                        }\n                    }\n                }\n\n                for(int cnt=0;cnt<=x;cnt++){\n                    for(int j=0;j<dp1[0].length;j++){\n                        dp1[cnt][j]+=newdp1[cnt][j];\n                        dp1[cnt][j]%=mod;\n                        newdp1[cnt][j]=0;\n                    }\n                }\n            }\n        }\n\n\n        dp2[0][0][0]=1;\n        long newdp2[][][]=new long[dp2.length][dp2[0].length][dp2[0][0].length];\n\n\n        for(int i=0;i<A.length;i++){//b c\n            int p=A[i][0],type=A[i][1];\n            if(type!=0){\n                for(int a=0;a<dp2.length;a++){\n                    for(int b=0;b<dp2[0].length;b++){\n                        for(int j=0;j<dp2[0][0].length;j++){\n                            if(j>=p){\n                                if(type==1){\n                                    if(a-1>=0){\n                                        newdp2[a][b][j]+=dp2[a-1][b][j-p];\n                                    }\n                                }\n                                else{\n                                    if(b-1>=0) {\n                                        newdp2[a][b][j]+=dp2[a][b-1][j-p];\n                                    }\n                                }\n                            }\n                            newdp2[a][b][j]%=mod;\n                        }\n                    }\n                }\n\n                for(int a=0;a<dp2.length;a++){\n                    for(int b=0;b<dp2[0].length;b++){\n                        for(int j=0;j<dp2[0][0].length;j++){\n                            dp2[a][b][j]+=newdp2[a][b][j];\n                            dp2[a][b][j]%=mod;\n                            newdp2[a][b][j]=0;\n                        }\n                    }\n                }\n            }//type!=0\n        }\n\n\n        dp3[1][0][0][0]=1;\n        dp3[0][1][0][1]=1;\n        dp3[0][0][1][2]=1;\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    for(x=0;x<dp3[0][0][0].length;x++){\n                        if(dp3[i][j][k][x]==-1){\n                            dfs(i,j,k,x);\n                        }\n                    }\n                }\n            }\n        }\n\n        for(int i=0;i<dp3.length-1;i++){\n            for(int j=0;j<dp3[0].length-1;j++){\n                for(int k=0;k<dp3[0][0].length-1;k++){\n                    for(int cur=0;cur<3;cur++){\n                        for(int t=0;t<=T;t++){//price\n                            int aprice=t;\n                            int bcprice=T-t;\n                            long cnt1=dp1[i][aprice];\n                            long cnt2=dp2[j][k][bcprice];\n                            long combination=dp3[i][j][k][cur];\n                            long p1=(cnt1*f[i])%mod;\n                            long p2=(((f[j]*f[k])%mod)*cnt2)%mod;\n                            long p3=(p1*p2)%mod;\n                            res+=(p3*combination)%mod;\n                            res%=mod;\n\n                        }\n                    }\n                }\n            }\n        }\n        out.println(res);\n\n    }\n\n    public long dfs(int a,int b,int c,int cur){\n        if(a<0||b<0||c<0){\n            return 0;\n        }\n        if(a==0&&b==0&&c==0){\n            return 0;\n        }\n\n        if(dp3[a][b][c][cur]!=-1)return dp3[a][b][c][cur];\n\n        long res=0;\n        if(cur==0){\n            res+=dfs(a-1,b,c,1);\n            res%=mod;\n            res+=dfs(a-1,b,c,2);\n            res%=mod;\n\n        }\n        else if(cur==1){\n            res+=dfs(a,b-1,c,0);\n            res%=mod;\n            res+=dfs(a,b-1,c,2);\n            res%=mod;\n        }\n        else{\n            res+=dfs(a,b,c-1,0);\n            res%=mod;\n            res+=dfs(a,b,c-1,1);\n            res%=mod;\n        }\n        res%=mod;\n        dp3[a][b][c][cur]=res;\n        return res;\n    }\n\n}\n\n\n\n\n\n\n\n\n\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n/*\n5 3\n1 1\n2 1\n2 1\n2 1\n2 2\n */", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt==0 ? 1 : 0;\n\t\tif(remCnt<0 || remSum<0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\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\n\t\t}\n\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 + 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\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt == 0 ? 1 : 0;\n\t\tif (remCnt < 0 || remSum < 0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt1 == 0 && remCnt2 == 0 ? 1 : 0;\n\t\tif (remSum < 0 || remCnt1 < 0 || remCnt2 < 0)\n\t\t\treturn 0;\n\t\tif (memo2[idx][remCnt1][remCnt2][remSum] != -1)\n\t\t\treturn memo2[idx][remCnt1][remCnt2][remSum];\n\t\tint ans = dp2(idx + 1, remCnt1, remCnt2, remSum);\n\n\t\tif (g[idx] == 1)\n\t\t\tans += dp2(idx + 1, remCnt1 - 1, remCnt2, remSum - t[idx]);\n\t\telse if (g[idx] == 2)\n\t\t\tans += dp2(idx + 1, remCnt1, remCnt2 - 1, remSum - t[idx]);\n\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 < 0 || cnt1 < 0 || cnt2 < 0)\n\t\t\treturn 0;\n\t\tif (cnt0 + cnt1 + cnt2 == 0)\n\t\t\treturn 1;\n\t\tif (memo3[last][cnt0][cnt1][cnt2] != -1)\n\t\t\treturn memo3[last][cnt0][cnt1][cnt2];\n\t\tlong ans = 0;\n\t\tif (last != 0)\n\t\t\tans += dp3(cnt0 - 1, cnt1, cnt2, 0);\n\t\tif (last != 1)\n\t\t\tans += dp3(cnt0, cnt1 - 1, cnt2, 1);\n\t\tif (last != 2)\n\t\t\tans += dp3(cnt0, cnt1, cnt2 - 1, 2);\n\t\treturn memo3[last][cnt0][cnt1][cnt2] = (int) (ans % MOD);\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.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        OutputWriter out = new OutputWriter(outputStream);\n        TaskG2 solver = new TaskG2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG2 {\n        static final int MOD = 1000000000 + 7;\n        static final int MAXN = 51;\n\n        int getWays(int i, int j, int k, int l, int[][][][] ways, boolean[][][][] cached) {\n            if (i + j + k == 0) return l == -1 ? 1 : 0;\n            if (l < 0) return 0;\n            if (cached[i][j][k][l]) return ways[i][j][k][l];\n            int s = i + j + k;\n            long value = 0;\n            if (l == 0 && i != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i - 1, j, k, x, ways, cached);\n                    }\n            }\n            if (l == 1 && j != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j - 1, k, x, ways, cached);\n                    }\n            }\n            if (l == 2 && k != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j, k - 1, x, ways, cached);\n                    }\n            }\n            ways[i][j][k][l] = (int) (value % MOD);\n            cached[i][j][k][l] = true;\n            return ways[i][j][k][l];\n        }\n\n        int totalWays(int i, int j, int k, int[][][][] ways, boolean[][][][] cached, int[] factorial) {\n            long ret = 0;\n            for (int l = 0; l < 3; l++) ret += getWays(i, j, k, l, ways, cached);\n            ret *= factorial[i];\n            ret %= MOD;\n\n            ret *= factorial[j];\n            ret %= MOD;\n\n            ret *= factorial[k];\n            ret %= MOD;\n\n            return (int) ret;\n        }\n\n        int add(int type, int value, int[] sizes, int sum, int[][][][] dp) {\n            sizes[type]++;\n            if (type == 0) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 1; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n                                dp[i][j][k][s] += dp[i - 1][j][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 1) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 1; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j - 1][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 2) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 1; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j][k - 1][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            return sum + value;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int[][][][] ways = new int[MAXN][MAXN][MAXN][3];\n            boolean[][][][] cached = new boolean[MAXN][MAXN][MAXN][3];\n//        Arrays.fill(ways, -1);\n\n            int n = in.nextInt(), T = in.nextInt();\n\n            ArrayList<Integer>[] ar = new ArrayList[3];\n            for (int i = 0; i < 3; i++) ar[i] = new ArrayList<Integer>();\n            int total_sum = 0;\n            for (int i = 0; i < n; i++) {\n                int t = in.nextInt(), g = in.nextInt();\n                ar[g - 1].add(t);\n                total_sum += t;\n            }\n\n            if (T > total_sum) {\n                out.println(0);\n                return;\n            }\n            int min_index = 0, mn = 100000000;\n\n            for (int i = 0; i < 3; i++) {\n                if (ar[i].size() < mn) {\n                    mn = ar[i].size();\n                    min_index = i;\n                }\n            }\n\n            int[][][][] dp = new int[ar[(1 + min_index) % 3].size() + 1][ar[(2 + min_index) % 3].size() + 1][1][total_sum + 1];\n            int[][][][] dp2 = new int[1][1][mn + 1][total_sum + 1];\n            dp[0][0][0][0] = dp2[0][0][0][0] = 1;\n            int[] sizes = {0, 0, 0};\n            int sum = 0;\n            int[] order = {(min_index + 1) % 3, (min_index + 2) % 3};\n            int type = 0;\n            for (int i : order) {\n                for (int v : ar[i])\n                    sum = add(type, v, sizes, sum, dp);\n                type++;\n            }\n            sum = 0;\n            sizes[0] = sizes[1] = sizes[2] = 0;\n            for (int i : ar[min_index])\n                sum = add(2, i, sizes, sum, dp2);\n            int[] factorial = new int[MAXN];\n            factorial[0] = 1;\n            for (int i = 1; i < MAXN; i++)\n                factorial[i] = (int) ((factorial[i - 1] * 1L * i) % MOD);\n\n            long answer = 0;\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 <= mn; k++)\n                        for (int s = 0; s <= T; s++) {\n\n                            long x = (dp[i][j][0][s] * 1L * totalWays(i, j, k, ways, cached, factorial)) % MOD;\n                            x *= dp2[0][0][k][T - s];\n                            x %= MOD;\n                            answer += x;\n\n                        }\n            out.println(answer % MOD);\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)) 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            }\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 println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\n');\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "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 % 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", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.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        OutputWriter out = new OutputWriter(outputStream);\n        TaskG2 solver = new TaskG2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG2 {\n        static final int MOD = 1000000000 + 7;\n        static final int MAXN = 51;\n\n        int getWays(int i, int j, int k, int l, int[][][][] ways, boolean[][][][] cached) {\n            if (i + j + k == 0) return l == -1 ? 1 : 0;\n            if (l < 0) return 0;\n            if (cached[i][j][k][l]) return ways[i][j][k][l];\n            int s = i + j + k;\n            long value = 0;\n            if (l == 0 && i != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i - 1, j, k, x, ways, cached);\n                    }\n            }\n            if (l == 1 && j != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j - 1, k, x, ways, cached);\n                    }\n            }\n            if (l == 2 && k != 0) {\n                for (int x = -1; x < 3; x++)\n                    if (x != l) {\n                        value += getWays(i, j, k - 1, x, ways, cached);\n                    }\n            }\n            ways[i][j][k][l] = (int) (value % MOD);\n            cached[i][j][k][l] = true;\n            return ways[i][j][k][l];\n        }\n\n        int totalWays(int i, int j, int k, int[][][][] ways, boolean[][][][] cached, int[] factorial) {\n            long ret = 0;\n            for (int l = 0; l < 3; l++) ret += getWays(i, j, k, l, ways, cached);\n            ret *= factorial[i];\n            ret %= MOD;\n\n            ret *= factorial[j];\n            ret %= MOD;\n\n            ret *= factorial[k];\n            ret %= MOD;\n\n            return (int) ret;\n        }\n\n        int add(int type, int value, int[] sizes, int sum, int[][][][] dp) {\n            sizes[type]++;\n            if (type == 0) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 1; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n                                dp[i][j][k][s] += dp[i - 1][j][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 1) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 1; j <= sizes[1]; j++)\n                            for (int k = 0; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j - 1][k][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            if (type == 2) {\n                for (int s = sum + value; s >= value; s--) {\n                    for (int i = 0; i <= sizes[0]; i++)\n                        for (int j = 0; j <= sizes[1]; j++)\n                            for (int k = 1; k <= sizes[2]; k++) {\n//                            System.out.println(i + \" \" + j + \" \" + k + \" \" + s + \" \" + dp.length + \" \" + dp[0].length + \" \" + dp[0][0].length + \" \" + dp[0][0][0].length);\n                                dp[i][j][k][s] += dp[i][j][k - 1][s - value];\n                                if (dp[i][j][k][s] >= MOD)\n                                    dp[i][j][k][s] -= MOD;\n                            }\n                }\n            }\n\n            return sum + value;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int[][][][] ways = new int[MAXN][MAXN][MAXN][3];\n            boolean[][][][] cached = new boolean[MAXN][MAXN][MAXN][3];\n//        Arrays.fill(ways, -1);\n\n            int n = in.nextInt(), T = in.nextInt();\n\n            ArrayList<Integer>[] ar = new ArrayList[3];\n            for (int i = 0; i < 3; i++) ar[i] = new ArrayList<Integer>();\n            int total_sum = 0;\n            for (int i = 0; i < n; i++) {\n                int t = in.nextInt(), g = in.nextInt();\n                ar[g - 1].add(t);\n                total_sum += t;\n            }\n\n            if (T > total_sum) {\n                out.println(0);\n                return;\n            }\n            int min_index = 0, mn = 100000000;\n\n            for (int i = 0; i < 3; i++) {\n                if (ar[i].size() < mn) {\n                    mn = ar[i].size();\n                    min_index = i;\n                }\n            }\n\n            int[][][][] dp = new int[ar[(1 + min_index) % 3].size() + 1][ar[(2 + min_index) % 3].size() + 1][mn + 1][total_sum + 1];\n            dp[0][0][0][0] = 1;\n            int[] sizes = {0, 0, 0};\n            int sum = 0;\n            int[] order = {(min_index + 1) % 3, (min_index + 2) % 3, min_index};\n            int type = 0;\n            for (int i : order) {\n                for (int v : ar[i])\n                    sum = add(type, v, sizes, sum, dp);\n                type++;\n            }\n            int[] factorial = new int[MAXN];\n            factorial[0] = 1;\n            for (int i = 1; i < MAXN; i++)\n                factorial[i] = (int) ((factorial[i - 1] * 1L * i) % MOD);\n            long answer = 0;\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                        answer += dp[i][j][k][T] * 1L * totalWays(i, j, k, ways, cached, factorial);\n                        answer %= MOD;\n                    }\n            out.println(answer);\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)) 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            }\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 println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\n');\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n        thread.start();\n        thread.join();\n    }\n\n    static class TaskAdapter implements Runnable {\n        @Override\n        public void run() {\n            InputStream inputStream = System.in;\n            OutputStream outputStream = System.out;\n            FastInput in = new FastInput(inputStream);\n            FastOutput out = new FastOutput(outputStream);\n            G2PlaylistForPolycarpHardVersion solver = new G2PlaylistForPolycarpHardVersion();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class G2PlaylistForPolycarpHardVersion {\n        Modular mod = new Modular(1e9 + 7);\n\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.readInt();\n            int m = in.readInt();\n            int[][] musics = new int[n][2];\n            int[] cnts = new int[4];\n            for (int i = 0; i < n; i++) {\n                musics[i][0] = in.readInt();\n                musics[i][1] = in.readInt();\n                cnts[musics[i][1]]++;\n            }\n\n            int c1 = cnts[1];\n            int c2 = cnts[2];\n            int c3 = cnts[3];\n\n            int[][][][] comp = new int[c1 + 1][c2 + 1][c3 + 1][4];\n            for (int i = 0; i <= c1; i++) {\n                for (int j = 0; j <= c2; j++) {\n                    for (int k = 0; k <= c3; k++) {\n                        for (int t = 0; t < 4; t++) {\n                            if (i == 0 && j == 0 && k == 0) {\n                                comp[i][j][k][t] = 1;\n                                continue;\n                            }\n                            if (i > 0 && t != 1) {\n                                comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i - 1][j][k][1], i));\n                            }\n                            if (j > 0 && t != 2) {\n                                comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j - 1][k][2], j));\n                            }\n                            if (k > 0 && t != 3) {\n                                comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j][k - 1][3], k));\n                            }\n                        }\n                    }\n                }\n            }\n\n            int[][][][] last = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];\n            int[][][][] next = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];\n\n            last[0][0][0][0] = 1;\n            int t1 = 0;\n            int t2 = 0;\n            int t3 = 0;\n            for (int[] music : musics) {\n                int m1 = music[1];\n                int m0 = music[0];\n                if (m1 == 1) {\n                    t1++;\n                } else if (m1 == 2) {\n                    t2++;\n                } else {\n                    t3++;\n                }\n                for (int i = 0; i <= t1; i++) {\n                    for (int j = 0; j <= t2; j++) {\n                        for (int k = 0; k <= t3; k++) {\n                            for (int t = 0; t <= m; t++) {\n                                next[i][j][k][t] = last[i][j][k][t];\n                                if (t < m0) {\n                                    continue;\n                                }\n                                if (m1 == 1 && i > 0) {\n                                    next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i - 1][j][k][t - m0]);\n                                } else if (m1 == 2 && j > 0) {\n                                    next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j - 1][k][t - m0]);\n                                } else if (m1 == 3 && k > 0) {\n                                    next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j][k - 1][t - m0]);\n                                }\n                            }\n                        }\n                    }\n                }\n\n                int[][][][] tmp = last;\n                last = next;\n                next = tmp;\n            }\n\n            int ans = 0;\n            for (int i = 0; i <= c1; i++) {\n                for (int j = 0; j <= c2; j++) {\n                    for (int k = 0; k <= c3; k++) {\n                        ans = mod.plus(ans, mod.mul(last[i][j][k][m], comp[i][j][k][0]));\n                    }\n                }\n            }\n\n            out.println(ans);\n        }\n\n    }\n\n    static class Modular {\n        int m;\n\n        public Modular(int m) {\n            this.m = m;\n        }\n\n        public Modular(long m) {\n            this.m = (int) m;\n            if (this.m != m) {\n                throw new IllegalArgumentException();\n            }\n        }\n\n        public Modular(double m) {\n            this.m = (int) m;\n            if (this.m != m) {\n                throw new IllegalArgumentException();\n            }\n        }\n\n        public int valueOf(int x) {\n            x %= m;\n            if (x < 0) {\n                x += m;\n            }\n            return x;\n        }\n\n        public int valueOf(long x) {\n            x %= m;\n            if (x < 0) {\n                x += m;\n            }\n            return (int) x;\n        }\n\n        public int mul(int x, int y) {\n            return valueOf((long) x * y);\n        }\n\n        public int plus(int x, int y) {\n            return valueOf(x + y);\n        }\n\n        public String toString() {\n            return \"mod \" + m;\n        }\n\n    }\n\n    static class FastOutput implements AutoCloseable, Closeable {\n        private StringBuilder cache = new StringBuilder(10 << 20);\n        private final Writer os;\n\n        public FastOutput(Writer os) {\n            this.os = os;\n        }\n\n        public FastOutput(OutputStream os) {\n            this(new OutputStreamWriter(os));\n        }\n\n        public FastOutput println(int c) {\n            cache.append(c).append('\\n');\n            return this;\n        }\n\n        public FastOutput flush() {\n            try {\n                os.append(cache);\n                os.flush();\n                cache.setLength(0);\n            } catch (IOException e) {\n                throw new UncheckedIOException(e);\n            }\n            return this;\n        }\n\n        public void close() {\n            flush();\n            try {\n                os.close();\n            } catch (IOException e) {\n                throw new UncheckedIOException(e);\n            }\n        }\n\n        public String toString() {\n            return cache.toString();\n        }\n\n    }\n\n    static class FastInput {\n        private final InputStream is;\n        private byte[] buf = new byte[1 << 13];\n        private int bufLen;\n        private int bufOffset;\n        private int next;\n\n        public FastInput(InputStream is) {\n            this.is = is;\n        }\n\n        private int read() {\n            while (bufLen == bufOffset) {\n                bufOffset = 0;\n                try {\n                    bufLen = is.read(buf);\n                } catch (IOException e) {\n                    bufLen = -1;\n                }\n                if (bufLen == -1) {\n                    return -1;\n                }\n            }\n            return buf[bufOffset++];\n        }\n\n        public void skipBlank() {\n            while (next >= 0 && next <= 32) {\n                next = read();\n            }\n        }\n\n        public int readInt() {\n            int sign = 1;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                sign = next == '+' ? 1 : -1;\n                next = read();\n            }\n\n            int val = 0;\n            if (sign == 1) {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 + next - '0';\n                    next = read();\n                }\n            } else {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 - next + '0';\n                    next = read();\n                }\n            }\n\n            return val;\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "//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 Round568G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\t// \n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), T = ni();\n\t\tint mod = 1000000007;\n\t\tint[][] a = new int[3][n];\n\t\tint[] ap = new int[3];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint t = ni();\n\t\t\tint k = ni()-1;\n\t\t\ta[k][ap[k]++] = t;\n\t\t}\n\t\tfor(int i = 0;i < 3;i++)a[i] = Arrays.copyOf(a[i], ap[i]);\n\t\t\n\t\tlong[][][][] com = new long[3][ap[0]+2][ap[1]+2][ap[2]+2];\n\t\tcom[0][1][0][0] = com[1][0][1][0] = com[2][0][0][1] = 1;\n\t\tfor(int i = 0;i <= ap[0];i++){\n\t\t\tfor(int j = 0;j <= ap[1];j++){\n\t\t\t\tfor(int k = 0;k <= ap[2];k++){\n\t\t\t\t\tfor(int u = 0;u < 3;u++){\n\t\t\t\t\t\tif(u != 0){\n\t\t\t\t\t\t\tcom[0][i+1][j][k] += com[u][i][j][k];\n\t\t\t\t\t\t\tif(com[0][i+1][j][k] >= mod)com[0][i+1][j][k] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(u != 1){\n\t\t\t\t\t\t\tcom[1][i][j+1][k] += com[u][i][j][k];\n\t\t\t\t\t\t\tif(com[1][i][j+1][k] >= mod)com[1][i][j+1][k] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(u != 2){\n\t\t\t\t\t\t\tcom[2][i][j][k+1] += com[u][i][j][k];\n\t\t\t\t\t\t\tif(com[2][i][j][k+1] >= mod)com[2][i][j][k+1] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] fif = enumFIF(200, mod);\n\t\t\n\t\tlong[][][] dp = new long[3][][];\n\t\tfor(int i = 0;i < 3;i++){\n\t\t\tint s = 0;\n\t\t\tfor(int v : a[i])s += v;\n\t\t\tdp[i] = new long[ap[i]+1][s+1];\n\t\t\tdp[i][0][0] = 1;\n\t\t\tfor(int v : a[i]){\n\t\t\t\tfor(int j = ap[i]-1;j >= 0;j--){\n\t\t\t\t\tfor(int k = s-v;k >= 0;k--){\n\t\t\t\t\t\tdp[i][j+1][k+v] += dp[i][j][k];\n\t\t\t\t\t\tif(dp[i][j+1][k+v] >= mod)dp[i][j+1][k+v] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong[][][] con = new long[ap[0]+1][ap[1]+1][2501];\n\t\tfor(int i = 0;i <= ap[0];i++){\n\t\t\tfor(int j = 0;j <= ap[1];j++){\n\t\t\t\tfor(int k = 0;k < dp[0][i].length;k++){\n\t\t\t\t\tif(dp[0][i][k] == 0)continue;\n\t\t\t\t\tfor(int l = 0;l < dp[1][j].length;l++){\n\t\t\t\t\t\tcon[i][j][k+l] += dp[0][i][k] * dp[1][j][l];\n\t\t\t\t\t\tcon[i][j][k+l] %= mod;\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 = 0;\n\t\tfor(int i = 0;i <= ap[0];i++){\n\t\t\tfor(int j = 0;j <= ap[1];j++){\n\t\t\t\tfor(int k = 0;k <= ap[2];k++){\n\t\t\t\t\tlong base = (com[0][i][j][k] + com[1][i][j][k] + com[2][i][j][k]) * fif[0][i] % mod * fif[0][j] % mod * \n\t\t\t\t\t\t\tfif[0][k] % mod;\n\t\t\t\t\tlong ls = 0;\n\t\t\t\t\tfor(int l = 0;l <= T;l++){\n\t\t\t\t\t\tif(T-l < dp[2][k].length){\n\t\t\t\t\t\t\tls += con[i][j][l] * dp[2][k][T-l];\n\t\t\t\t\t\t\tls %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n//\t\t\t\t\tif(base > 0 && ls > 0){\n//\t\t\t\t\t\ttr(i, j, k, base, ls);\n//\t\t\t\t\t}\n\t\t\t\t\tans += base * ls;\n\t\t\t\t\tans %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 50, m = 2500;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(n + \" \");\n//\t\tsb.append(m + \" \");\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tsb.append(50 + \" \");\n//\t\t\tsb.append(gen.nextInt(3)+1 + \" \");\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 Round568G().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", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "// 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\tint x0 = ma > 0 ? (int) ((long) dq[ma - 1][mb][mc][0] * ma % MD) : 0;\n\t\t\t\t\t\tint x1 = mb > 0 ? (int) ((long) dq[ma][mb - 1][mc][1] * mb % MD) : 0;\n\t\t\t\t\t\tint x2 = mc > 0 ? (int) ((long) dq[ma][mb][mc - 1][2] * mc % MD) : 0;\n\t\t\t\t\t\tdp[ma][mb][mc] = (int) (((long) x0 + x1 + x2) % MD);\n\t\t\t\t\t\tdq[ma][mb][mc][0] = (x1 + x2) % MD;\n\t\t\t\t\t\tdq[ma][mb][mc][1] = (x2 + x0) % MD;\n\t\t\t\t\t\tdq[ma][mb][mc][2] = (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", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt == 0 ? 1 : 0;\n\t\tif (remCnt < 0 || remSum < 0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt1 == 0 && remCnt2 == 0 ? 1 : 0;\n\t\tif (remSum < 0 || remCnt1 < 0 || remCnt2 < 0)\n\t\t\treturn 0;\n\t\tif (memo2[idx][remCnt1][remCnt2][remSum] != -1)\n\t\t\treturn memo2[idx][remCnt1][remCnt2][remSum];\n\t\tint ans = dp2(idx + 1, remCnt1, remCnt2, remSum);\n\n\t\tif (g[idx] == 1)\n\t\t\tans += dp2(idx + 1, remCnt1 - 1, remCnt2, remSum - t[idx]);\n\t\telse if (g[idx] == 2)\n\t\t\tans += dp2(idx + 1, remCnt1, remCnt2 - 1, remSum - t[idx]);\n\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 + 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\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "cubic", "problem": "1185_G2. Playlist for Polycarp (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \nimport java.math.*;\nimport java.awt.Point;\n \npublic class CFTemplate {\n    static final long MOD = 1000000007L;\n    //static final long MOD2 = 1000000009L;\n    //static final long MOD = 998244353L;\n    //static final long INF = 500000000000L;\n    static final int INF = 1100000000;\n    static final int NINF = -100000;\n    static FastScanner sc;\n    static PrintWriter pw;\n    static final int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}};\n\n    public static void main(String[] args) {\n        sc = new FastScanner();\n        pw = new PrintWriter(System.out);\n        \n        ArrayList<Integer> primes = new ArrayList<Integer>();\n        for (int i = 2; i <= 3200; i++) {\n            boolean p = true;\n            for (int j = 2; j*j <= i; j++) {\n                if (i%j==0) {\n                    p = false;\n                    break;\n                }\n            }\n            if (p) primes.add(i);\n        }\n        int Q = sc.ni();\n        for (int q = 0; q < Q; q++) {\n            int N = sc.ni();\n            int K = sc.ni();\n            int[] nums = new int[N+1];\n            for (int i = 1; i <= N; i++) nums[i] = sc.ni();\n            for (int i = 1; i <= N; i++) {\n                for (int p: primes) {\n                    int c = 0;\n                    while (nums[i] % p == 0) {\n                        nums[i] /= p;\n                        c++;\n                    }\n                    if (c%2==1) nums[i] *= p;\n                }\n            }\n\n            TreeSet<Integer> ts = new TreeSet<Integer>();\n            HashMap<Integer,Integer> last = new HashMap<Integer,Integer>();\n\n            int[][] dp = new int[N+1][K+1];\n            for (int i = 1; i <= N; i++) {\n                if (last.containsKey(nums[i])) {\n                    ts.add(last.get(nums[i]));\n                }\n                last.put(nums[i],i);\n                int[] inds = new int[K+1];\n                int ind = 0;\n                for (int x: ts.descendingSet()) {\n                    inds[ind] = x;\n                    if (ind==K) break;\n                    ind++;\n                }\n                for (int j = 0; j <= K; j++) {\n                    dp[i][j] = INF;\n                    if (j > 0) dp[i][j] = dp[i][j-1];\n                    for (int k = 0; k <= j; k++) {\n                        dp[i][j] = Math.min(dp[i][j],dp[inds[k]][j-k]+1);\n                    }\n                }\n            }\n            pw.println(dp[N][K]);\n        }\n        pw.close();\n    }\n\n    public static void sort(int[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n\n    public static void sort(long[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n\n    //Sort an array (immune to quicksort TLE)\n    public static void sort(int[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<int[]>() {\n            @Override\n            public int compare(int[] a, int[] b) {\n                return a[1]-b[1];\n                //Ascending order.\n            }\n        });\n    }\n    \n    public static void sort(long[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<long[]>() {\n            @Override\n            public int compare(long[] a, long[] b) {\n                if (a[0] > b[0])\n                    return 1;\n                else if (a[0] < b[0])\n                    return -1;\n                else\n                    return 0;\n                //Ascending order.\n            }\n        });\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in), 32768);\n            st = null;\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        int[][] graph(int N, int[][] edges) {\n            int[][] graph = new int[N][];\n            int[] sz = new int[N];\n            for (int[] e: edges) {\n                sz[e[0]] += 1;\n                sz[e[1]] += 1;\n            }\n            for (int i = 0; i < N; i++) {\n                graph[i] = new int[sz[i]];\n            }\n            int[] cur = new int[N];\n            for (int[] e: edges) {\n                graph[e[0]][cur[e[0]]] = e[1];\n                graph[e[1]][cur[e[1]]] = e[0];\n                cur[e[0]] += 1;\n                cur[e[1]] += 1;\n            }\n            return graph;\n        }\n \n        int[] intArray(int N, int mod) {\n            int[] ret = new int[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = ni()+mod;\n            return ret;\n        }\n \n        long nl() {\n            return Long.parseLong(next());\n        }\n \n        long[] longArray(int N, long mod) {\n            long[] ret = new long[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = nl()+mod;\n            return ret;\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}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solve{\n    public static void main(String[] args) throws Exception{\n        Scanner sc=new Scanner(System.in);\n        PrintWriter out =new PrintWriter(System.out);\n        int size=(int)1e7+1;\n        int[] pr=new int[size];\n        for(int i=0;i<size;i++){\n            pr[i]=i;\n        }\n        for(int i=2;i*i<size;i++){\n          int val=i*i;\n            for(int j=val;j<=size;j+=val){\n                 pr[j]=j/val;\n            }\n        }\n        int t=sc.nextInt();\n        int[] dp=new int[size];\n        Arrays.fill(dp,-1);\n        while(t-->0){\n            int n=sc.nextInt();\n            int k=sc.nextInt();\n            int[] ar=new int[n];\n            for(int i=0;i<n;i++){\n                int a=sc.nextInt();\n                ar[i]=pr[a];\n            }\n            int[] ans=new int[k+1];\n            int[] ind=new int[k+1];\n            for(int i=0;i<n;i++){\n                for(int h=k;h>=0;h--){\n                    if(dp[ar[i]]>=ind[h]){\n                        ans[h]++;\n                        ind[h]=i;\n                    }\n                    if(h>0 && (ans[h-1]<ans[h] ||(ans[h-1]==ans[h] && ind[h-1]>ind[h])))\n                    {\n                        ans[h]=ans[h-1];\n                        ind[h]=ind[h-1];\n                    }\n                }\n                dp[ar[i]]=i;\n            }\n            out.println(ans[k]+1);\n            for(int i=0;i<n;i++)dp[ar[i]]=-1;\n        }\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E2 {\n    static ArrayList<Integer> primes;\n    static int[] mind;\n    final static int MAXA = (int) 1e7;\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(f.readLine());\n        int t = Integer.parseInt(st.nextToken());\n        primes = new ArrayList<>();\n        mind = new int[MAXA + 1];\n        for (int i = 2; i <= MAXA; i++) {\n            if (mind[i] == 0) {\n                primes.add(i);\n                mind[i] = i;\n            }\n            for (int x : primes) {\n                if (x > mind[i] || x * i > MAXA) break;\n                mind[x * i] = x;\n            }\n        }\n        int[] count = new int[MAXA + 1];\n        for (int on8y = 0; on8y < t; on8y++) {\n            st = new StringTokenizer(f.readLine());\n            int n = Integer.parseInt(st.nextToken());\n            int k = Integer.parseInt(st.nextToken());\n            int[] a = new int[n];\n            Arrays.fill(a, 1);\n            st = new StringTokenizer(f.readLine());\n            for (int i = 0; i < n; i++) {\n                int x = Integer.parseInt(st.nextToken());\n                int cnt = 0;\n                int last = 0;\n                while (x > 1) {\n                    int p = mind[x];\n                    if (last == p) cnt++;\n                    else {\n                        if (cnt % 2 == 1) a[i] *= last;\n                        last = p;\n                        cnt = 1;\n                    }\n                    x /= p;\n                }\n                if (cnt % 2 == 1) a[i] *= last;\n            }\n            int[][] mnleft = new int[n][k + 1];\n            for (int j = 0; j < k + 1; j++) {\n                int l = n;\n                int now = 0;\n                for (int i = n - 1; i >= 0; i--) {\n                    while (l - 1 >= 0 && now + ((count[a[l - 1]] > 0) ? 1 : 0) <= j) {\n                        l--;\n                        now += (count[a[l]] > 0) ? 1 : 0;\n                        count[a[l]]++;\n                    }\n                    mnleft[i][j] = l;\n                    if (count[a[i]] > 1) now--;\n                    count[a[i]]--;\n                }\n            }\n            int[][] dp = new int[n + 1][k + 1];\n            for (int i = 0; i < n + 1; i++) {\n                Arrays.fill(dp[i], (int) 1e9 + 1);\n            }\n            for (int i = 0; i < k + 1; i++) dp[0][i] = 0;\n            for (int i = 1; i <= n; i++) {\n                for (int j = 0; j <= k; j++) {\n                    if (j > 0) dp[i][j] = dp[i][j - 1];\n                    for (int lst = 0; lst <= j; lst++) {\n                        dp[i][j] = Math.min(dp[i][j], dp[mnleft[i - 1][lst]][j - lst] + 1);\n                    }\n                }\n            }\n            int ans = (int) 1e9 + 1;\n            for (int c : dp[n]) ans = Math.min(ans, c);\n            System.out.println(ans);\n\n        }\n    }\n}\n\n\n", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "// https://codeforces.com/contest/1497/submission/110250082\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1497E2 extends PrintWriter {\n\tCF1497E2() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tbyte[] bb = new byte[1 << 15]; int i, n;\n\t\tbyte getc() {\n\t\t\tif (i == n) {\n\t\t\t\ti = n = 0;\n\t\t\t\ttry { n = in.read(bb); } catch (IOException e) {}\n\t\t\t}\n\t\t\treturn i < n ? bb[i++] : 0;\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= ' ') c = getc();\n\t\t\tint a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1497E2 o = new CF1497E2(); o.main(); o.flush();\n\t}\n\n\tstatic final int A = 10000000, K = 20;\n\tint[] cc = new int[A + 1]; {\n\t\tfor (int a = 1; a <= A; a++)\n\t\t\tcc[a] = a;\n\t\tfor (int a = 2; a <= A / a; a++) {\n\t\t\tint s = a * a;\n\t\t\tfor (int b = s; b <= A; b += s)\n\t\t\t\twhile (cc[b] % s == 0)\n\t\t\t\t\tcc[b] /= s;\n\t\t}\n\t}\n\tvoid main() {\n\t\tint[] pp = new int[A + 1]; Arrays.fill(pp, -1);\n\t\tint t = sc.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint k = sc.nextInt();\n\t\t\tint[] aa = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\taa[i] = cc[sc.nextInt()];\n\t\t\tint[] mp = new int[k + 1];\n\t\t\tint[] ip = new int[k + 1];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint a = aa[i];\n\t\t\t\tfor (int h = k; h >= 0; h--) {\n\t\t\t\t\tif (pp[a] >= ip[h]) {\n\t\t\t\t\t\tmp[h]++;\n\t\t\t\t\t\tip[h] = i;\n\t\t\t\t\t}\n\t\t\t\t\tif (h > 0 && (mp[h - 1] < mp[h] || mp[h - 1] == mp[h] && ip[h - 1] > ip[h])) {\n\t\t\t\t\t\tmp[h] = mp[h - 1];\n\t\t\t\t\t\tip[h] = ip[h - 1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpp[a] = i;\n\t\t\t}\n\t\t\tprintln(mp[k] + 1);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint a = aa[i];\n\t\t\t\tpp[a] = -1;\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class E3 {\n\tInputStream is;\n\tFastWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni();T > 0;T--)go();\n\t}\n\n\tint[] lpf = enumLowestPrimeFactors(10000000);\n\n\tvoid go()\n\t{\n\t\tint n = ni(), K = ni();\n\t\tint[] a = na(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\ta[i] = factorFast(a[i], lpf);\n\t\t}\n\t\ta = shrink(a);\n\n\t\tint[][] dp = new int[K+1][n+1];\n\t\tfor(int i = 0;i <= K;i++){\n\t\t\tArrays.fill(dp[i], 999999999);\n\t\t}\n\t\tfor(int i = 0;i <= K;i++)dp[i][0] = 0;\n\n\t\tint[] prev = makePrev(a, n+1);\n\n\t\tint[] imos = new int[n+5];\n\t\tint[] pp = new int[K+1];\n\t\tint[] vs = new int[K+1];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint p = prev[i];\n\t\t\timos[p+1]--;\n\n\t\t\tfor(int j = 0;j <= K;j++){\n\t\t\t\tvs[j]++;\n\t\t\t\tif(pp[j] >= p+1){\n\t\t\t\t\tvs[j]--;\n\t\t\t\t}\n\t\t\t\twhile(vs[j] > j){\n\t\t\t\t\tpp[j]++;\n\t\t\t\t\tvs[j] += imos[pp[j]];\n\t\t\t\t}\n\t\t\t\tfor(int k = 0;k+j <= K;k++){\n\t\t\t\t\tdp[k+j][i+1] = Math.min(dp[k+j][i+1], dp[k][pp[j]] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(dp[K][n]);\n\t}\n\n\tpublic static int[] shrink(int[] a) {\n\t\tint n = a.length;\n\t\tlong[] b = new long[n];\n\t\tfor (int i = 0; i < n; i++) b[i] = (long) a[i] << 32 | i;\n\t\tArrays.sort(b);\n\t\tint[] ret = new int[n];\n\t\tint p = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) p++;\n\t\t\tret[(int) b[i]] = p;\n\t\t}\n\t\treturn ret;\n\t}\n\n\n\tpublic static int[] makePrev(int[] a, int sup)\n\t{\n\t\tint n = a.length;\n\t\tint[] mnext = new int[sup];\n\t\tArrays.fill(mnext, -1);\n\t\tint[] next = new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tnext[i] = mnext[a[i]];\n\t\t\tmnext[a[i]] = i;\n\t\t}\n\t\treturn next;\n\t}\n\n\tpublic static int factorFast(int n, int[] lpf)\n\t{\n\t\tint ret = 1;\n\t\tint e = 0;\n\t\tint last = -1;\n\t\twhile(lpf[n] > 0) {\n\t\t\tint p = lpf[n];\n\t\t\tif (last != p) {\n\t\t\t\tif (last > 0 && e % 2 == 1) {\n\t\t\t\t\tret = ret * last;\n\t\t\t\t}\n\n\t\t\t\tlast = p;\n\t\t\t\te = 1;\n\t\t\t} else {\n\t\t\t\te++;\n\t\t\t}\n\t\t\tn /= p;\n\t\t}\n\n\t\tif(last > 0 && e % 2 == 1){\n\t\t\tret *= last;\n\t\t}\n\t\treturn ret;\n\t}\n\n\n\tpublic static int[] enumLowestPrimeFactors(int n)\n\t{\n\t\tint tot = 0;\n\t\tint[] lpf = new int[n+1];\n\t\tint u = n+32;\n\t\tdouble lu = Math.log(u);\n\t\tint[] primes = new int[(int)(u/lu+u/lu/lu*1.5)];\n\t\tfor(int i = 2;i <= n;i++)lpf[i] = i;\n\t\tfor(int p = 2;p <= n;p++){\n\t\t\tif(lpf[p] == p)primes[tot++] = p;\n\t\t\tint tmp;\n\t\t\tfor(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){\n\t\t\t\tlpf[tmp] = primes[i];\n\t\t\t}\n\t\t}\n\t\treturn lpf;\n\t}\n\n\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new FastWriter(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 E3().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\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 char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[][] nmi(int n, int m) {\n\t\tint[][] map = new int[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\n\t\treturn map;\n\t}\n\n\tprivate int ni() { return (int)nl(); }\n\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\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\tpublic static class FastWriter\n\t{\n\t\tprivate static final int BUF_SIZE = 1<<13;\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\n\t\tprivate final OutputStream out;\n\t\tprivate int ptr = 0;\n\n\t\tprivate FastWriter(){out = null;}\n\n\t\tpublic FastWriter(OutputStream os)\n\t\t{\n\t\t\tthis.out = os;\n\t\t}\n\n\t\tpublic FastWriter(String path)\n\t\t{\n\t\t\ttry {\n\t\t\t\tthis.out = new FileOutputStream(path);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter write(byte b)\n\t\t{\n\t\t\tbuf[ptr++] = b;\n\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(char c)\n\t\t{\n\t\t\treturn write((byte)c);\n\t\t}\n\n\t\tpublic FastWriter write(char[] s)\n\t\t{\n\t\t\tfor(char c : s){\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(String s)\n\t\t{\n\t\t\ts.chars().forEach(c -> {\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t});\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(int l) {\n\t\t\tif (l >= 1000000000) return 10;\n\t\t\tif (l >= 100000000) return 9;\n\t\t\tif (l >= 10000000) return 8;\n\t\t\tif (l >= 1000000) return 7;\n\t\t\tif (l >= 100000) return 6;\n\t\t\tif (l >= 10000) return 5;\n\t\t\tif (l >= 1000) return 4;\n\t\t\tif (l >= 100) return 3;\n\t\t\tif (l >= 10) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(int x)\n\t\t{\n\t\t\tif(x == Integer.MIN_VALUE){\n\t\t\t\treturn write((long)x);\n\t\t\t}\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(long l) {\n\t\t\tif (l >= 1000000000000000000L) return 19;\n\t\t\tif (l >= 100000000000000000L) return 18;\n\t\t\tif (l >= 10000000000000000L) return 17;\n\t\t\tif (l >= 1000000000000000L) return 16;\n\t\t\tif (l >= 100000000000000L) return 15;\n\t\t\tif (l >= 10000000000000L) return 14;\n\t\t\tif (l >= 1000000000000L) return 13;\n\t\t\tif (l >= 100000000000L) return 12;\n\t\t\tif (l >= 10000000000L) return 11;\n\t\t\tif (l >= 1000000000L) return 10;\n\t\t\tif (l >= 100000000L) return 9;\n\t\t\tif (l >= 10000000L) return 8;\n\t\t\tif (l >= 1000000L) return 7;\n\t\t\tif (l >= 100000L) return 6;\n\t\t\tif (l >= 10000L) return 5;\n\t\t\tif (l >= 1000L) return 4;\n\t\t\tif (l >= 100L) return 3;\n\t\t\tif (l >= 10L) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(long x)\n\t\t{\n\t\t\tif(x == Long.MIN_VALUE){\n\t\t\t\treturn write(\"\" + x);\n\t\t\t}\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(double x, int precision)\n\t\t{\n\t\t\tif(x < 0){\n\t\t\t\twrite('-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tx += Math.pow(10, -precision)/2;\n\t\t\t//\t\tif(x < 0){ x = 0; }\n\t\t\twrite((long)x).write(\".\");\n\t\t\tx -= (long)x;\n\t\t\tfor(int i = 0;i < precision;i++){\n\t\t\t\tx *= 10;\n\t\t\t\twrite((char)('0'+(int)x));\n\t\t\t\tx -= (int)x;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(char c){\n\t\t\treturn write(c).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(int x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(double x, int precision){\n\t\t\treturn write(x, precision).writeln();\n\t\t}\n\n\t\tpublic FastWriter write(int... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(int x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(long... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(long x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln()\n\t\t{\n\t\t\treturn write((byte)'\\n');\n\t\t}\n\n\t\tpublic FastWriter writeln(int... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[] line)\n\t\t{\n\t\t\treturn write(line).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[]... map)\n\t\t{\n\t\t\tfor(char[] line : map)write(line).writeln();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(String s)\n\t\t{\n\t\t\treturn write(s).writeln();\n\t\t}\n\n\t\tprivate void innerflush()\n\t\t{\n\t\t\ttry {\n\t\t\t\tout.write(buf, 0, ptr);\n\t\t\t\tptr = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic void flush()\n\t\t{\n\t\t\tinnerflush();\n\t\t\ttry {\n\t\t\t\tout.flush();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"flush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter print(byte b) { return write(b); }\n\t\tpublic FastWriter print(char c) { return write(c); }\n\t\tpublic FastWriter print(char[] s) { return write(s); }\n\t\tpublic FastWriter print(String s) { return write(s); }\n\t\tpublic FastWriter print(int x) { return write(x); }\n\t\tpublic FastWriter print(long x) { return write(x); }\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\n\t\tpublic FastWriter println(char c){ return writeln(c); }\n\t\tpublic FastWriter println(int x){ return writeln(x); }\n\t\tpublic FastWriter println(long x){ return writeln(x); }\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\n\t\tpublic FastWriter println(String s) { return writeln(s); }\n\t\tpublic FastWriter println() { return writeln(); }\n\t}\n\n\tpublic void trnz(int... 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// print ids which are 1\n\tpublic void trt(long... o)\n\t{\n\t\tQueue<Integer> stands = new ArrayDeque<>();\n\t\tfor(int i = 0;i < o.length;i++){\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\n\t\t}\n\t\tSystem.out.println(stands);\n\t}\n\n\tpublic 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\tpublic void tf(boolean[]... b)\n\t{\n\t\tfor(boolean[] r : b) {\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\n\t\t\tSystem.out.println();\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic void tf(long[]... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long[] r : b) {\n\t\t\t\tfor (long x : r) {\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\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\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic void tf(long... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long x : b) {\n\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\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", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n  public static void main(String[] args) throws IOException {\n    InputStreamReader in = new InputStreamReader(System.in);\n    BufferedReader br = new BufferedReader(in);\n\n    int t = Integer.parseInt(br.readLine());\n\n    // get primes up to 10000\n    /*\n    boolean[] prime = new boolean[10001];\n    for (int i = 0; i <= 10000; i++) {\n      prime[i] = true;\n    }\n\n    for (int p = 2; p * p <= 10000; p++) {\n      if (prime[p]) {\n        for (int i = p * p; i <= 10000; i += p) {\n          prime[i] = false;\n        }\n      }\n    }\n    ArrayList<Integer> primes = new ArrayList<>();\n\n    for (int i = 2; i < 10001; i++) {\n      if (prime[i]) {\n        primes.add(i);\n      }\n    }\n    */\n    int A = 10000000;\n    int[] convert = new int[A+1];\n    for (int a = 1; a <= A; a++) {\n      convert[a] = a;\n    }\n    for (int a = 2; a <= A/a; a++) {\n      int sq = a*a;\n      for (int b = sq; b <= A; b += sq) {\n        while (convert[b] % sq == 0) {\n          convert[b] /= sq;\n        }\n      }\n    }\n\n    int[] prevIndex = new int[A+1];\n    for (int i = 0; i <= A; i++) {\n      prevIndex[i] = -1;\n    }\n\n    for (int c = 0; c < t; c++) {\n      StringTokenizer st = new StringTokenizer(br.readLine());\n\n      int n = Integer.parseInt(st.nextToken());\n      int k = Integer.parseInt(st.nextToken());\n\n      int[] a = new int[n];\n      int maxA = 0;\n\n      st = new StringTokenizer(br.readLine());\n\n      for (int i = 0; i < n; i++) {\n        /*\n        int raw = Integer.parseInt(st.nextToken());\n        \n        for (int p : primes) {\n          if (p*p > raw) {\n            break;\n          }\n          while (raw % (p*p) == 0) {\n            raw /= p*p;\n          }\n        }\n        a[i] = raw;\n        */\n\n        a[i] = convert[Integer.parseInt(st.nextToken())];\n        maxA = Math.max(maxA, a[i]);\n      }\n\n      // hard version has extra here\n      // better version O(nk)\n\n      int[] partitions = new int[k+1];\n      int[] partIndex = new int[k+1];\n\n      for (int i = 0; i < n; i++) {\n        int cur = a[i];\n        for (int j = k; j >= 0; j--) {\n          if (prevIndex[cur] >= partIndex[j]) {\n            partitions[j]++;\n            partIndex[j] = i;\n          }\n          if (j > 0 && (partitions[j-1] < partitions[j] || partitions[j-1] == partitions[j] && partIndex[j-1] > partIndex[j])) {\n            partitions[j] = partitions[j-1];\n            partIndex[j] = partIndex[j-1];\n          }\n        }\n        prevIndex[cur] = i;\n      }\n\n      System.out.println(partitions[k]+1);\n\n      for (int i = 0; i < n; i++) {\n        int cur = a[i];\n        prevIndex[cur] = -1;\n      }\n\n\n      /* this should work (O(n*k^2))\n      int[][] minLeftIndex = new int[n][k+1];\n    \n      for (int j = 0; j <= k; j++) {\n        HashMap<Integer, Integer> interval = new HashMap<>();\n        int leftIndex = 0; // the right index is i in this case\n        int removed = 0;\n\n        for (int i = 0; i < n; i++) {\n          if (!interval.containsKey(a[i])) {\n            interval.put(a[i], 0);\n          }\n          interval.put(a[i], interval.get(a[i])+1);\n          if (interval.get(a[i]) > 1) {\n            removed++;\n          }\n          while (removed > j) {\n            interval.put(a[leftIndex], interval.get(a[leftIndex])-1);\n            if (interval.get(a[leftIndex]) > 0) {\n              removed--;\n            }\n            leftIndex++;\n          }\n          minLeftIndex[i][j] = leftIndex;\n          //System.out.println(i + \" \" + j + \" \" + leftIndex);\n        }\n      }\n\n      int[][] dp = new int[n][k+1];\n\n      // dp at all i = 0 = 0\n      for (int i = 0; i < n; i++) {\n        for (int j = 0; j <= k; j++) {\n          int min = Integer.MAX_VALUE;\n          for (int l = 0; l <= j; l++) {\n            if (minLeftIndex[i][l] > 0) {\n              min = Math.min(min, dp[minLeftIndex[i][l]-1][j-l] + 1); // \n            } else {\n              min = 0;\n            }\n            \n          }\n          if (min != Integer.MAX_VALUE) {\n            dp[i][j] = min;\n          }\n        }\n      }\n      \n      System.out.println(dp[n-1][k]+1);\n\n      \n\n      */\n\n      // easy solution\n      /*\n      HashSet<Integer> hs = new HashSet<>();\n\n      int segments = 1;\n\n      for (int i = 0; i < n; i++) {\n        if (hs.contains(a[i])) {\n          segments++;\n          hs.clear();\n        }\n        hs.add(a[i]);\n      }\n      System.out.println(segments);\n      */\n    } \n  }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "/**\n * author: derrick20\n * created: 3/20/21 7:13 PM\n */\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E2_SquareFreeFast {\n    static FastScanner sc = new FastScanner();\n    static PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) {\n//        generate();\n        int T = sc.nextInt();\n        int MAX = (int) 1e7;\n        int[] canonical = new int[MAX + 1];\n        canonical[1] = 1;\n        for (int factor = 2; factor <= MAX; factor++) {\n            if (canonical[factor] == 0) {\n                for (int mult = factor; mult <= MAX; mult += factor) {\n                    int prev = canonical[mult / factor];\n                    if (prev % factor == 0) {\n                        canonical[mult] = prev / factor;\n                    } else {\n                        canonical[mult] = prev * factor;\n                    }\n                }\n            }\n        }\n        int[] last = new int[MAX + 1];\n        while (T-->0) {\n            int N = sc.nextInt();\n            int K = sc.nextInt();\n            int[] a = new int[N + 1];\n            int[][] dp = new int[2][K + 1];\n            int[][] start = new int[2][K + 1];\n            int ptr = 0;\n            for (int i = 1; i <= N; i++) {\n                int nxt = 1 ^ ptr;\n                a[i] = canonical[sc.nextInt()];\n                for (int k = 0; k <= K; k++) {\n                    if (start[ptr][k] > last[a[i]]) {\n                        // extend it for free (unique)\n                        dp[nxt][k] = dp[ptr][k];\n                        start[nxt][k] = start[ptr][k];\n                    } else {\n                        // start anew\n                        dp[nxt][k] = dp[ptr][k] + 1;\n                        start[nxt][k] = i;\n                    }\n                    // Use a change (only if existing segment)\n                    if (i > 1 && k > 0 && start[ptr][k - 1] <= last[a[i]]) {\n                        // if this cost beats the old cost, or if it has a later start point, it's better.\n                        if (dp[ptr][k - 1] < dp[nxt][k] || (dp[ptr][k - 1] == dp[nxt][k] && start[ptr][k - 1] > start[nxt][k])) {\n                            dp[nxt][k] = dp[ptr][k - 1];\n                            start[nxt][k] = start[ptr][k - 1];\n                        }\n                    }\n                }\n//                System.out.println(Arrays.toString(start[nxt]));\n//                System.out.println(Arrays.toString(dp[nxt]));\n                last[a[i]] = i;\n                ptr = nxt;\n            }\n            for (int v : a) {\n                last[v] = 0;\n            }\n            // always allowed to waste initial changes by starting offset, so mono decr\n            out.println(dp[ptr][K]);\n        }\n        out.close();\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        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        int nextInt() {\n            return (int) nextLong();\n        }\n\n        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        double nextDouble() {\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            double cur = nextLong();\n            if (c != '.') {\n                return neg ? -cur : cur;\n            } else {\n                double frac = nextLong() / cnt;\n                return neg ? -cur - frac : cur + frac;\n            }\n        }\n\n        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        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        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\n    static void ASSERT(boolean assertion) {\n        if (!assertion) throw new AssertionError();\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n \n\n public class SolutionC{\n       public static void main(String[] args) throws Exception{\n               Scanner sc=new Scanner(System.in);\n        PrintWriter out=new PrintWriter(System.out);\n       int t=sc.nextInt();\n       int[] arr=new int[10000002];\n       for(int i=0;i<arr.length;i++){\n           arr[i]=i;\n       }\n       for(int i=2;i*i<arr.length;i++){\n           int b=i*i;\n          for(int j=b;j<arr.length;j+=b){\n              arr[j]=j/b;\n          }\n       }\n      int[] pp = new int[10000001]; Arrays.fill(pp, -1);\n       while(t-->0){\n           \n        int n=sc.nextInt();\n        int k=sc.nextInt();\n        int[] aa=new int[n];\n         for(int i=0;i<n;i++){\n             int a=sc.nextInt();\n             aa[i]=arr[a];\n         }\n        \n         int[] mp = new int[k + 1];\n\t\t\tint[] ip = new int[k + 1];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint a = aa[i];\n\t\t\t\tfor (int h = k; h >= 0; h--) {\n\t\t\t\t\tif (pp[a] >= ip[h]) {\n\t\t\t\t\t\tmp[h]++;\n\t\t\t\t\t\tip[h] = i;\n\t\t\t\t\t}\n\t\t\t\t\tif (h > 0 && (mp[h - 1] < mp[h] || mp[h - 1] == mp[h] && ip[h - 1] > ip[h])) {\n\t\t\t\t\t\tmp[h] = mp[h - 1];\n\t\t\t\t\t\tip[h] = ip[h - 1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpp[a] = i;\n\t\t\t}\n         \n       \n        out.println(mp[k]+1);\n        \n       for (int i = 0; i < n; i++) {\n\t\t\t\tpp[aa[i]] = -1;\n\t\t\t}\n        \n       }\n           \n           out.close();\n}\n\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdE {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n    static ArrayList<Integer> primes;\n\tpublic static void main(String[] omkar) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\tint t = sc.nextInt();\n \t\tprimes = new ArrayList<>();\n \t\tprime(3165);\n \t\tint[] freq = new int[10000001];\n \t\twhile(t--> 0){\n \t\t\tint n = sc.nextInt();\n \t\t\tint k = sc.nextInt();\n \t\t\tint[] arr = readArrayInt(n);\n \t\t\tfor(int j = 0;j<n;j++){\n \t\t\t\tarr[j] = factorize(arr[j]);\n \t\t\t}\n \t\t\tint[][] left = new int[n][k+1];\n \t\t\tfor(int m = 0;m<=k;m++){\n \t\t\t\tint l = 0;\n \t\t\t\tint count = 0;\n \t\t\t\tfor(int i = 0;i<n;i++){\n \t\t\t\t\tif (freq[arr[i]] > 0){\n \t\t\t\t\t\tcount++;\n \t\t\t\t\t}\n \t\t\t\t\tfreq[arr[i]]++;\n \t\t\t\t\twhile(count > m){\n \t\t\t\t\t\tfreq[arr[l]]--;\n \t\t\t\t\t\tif (freq[arr[l]] > 0){\n \t\t\t\t\t\t\tcount--;\n \t\t\t\t\t\t}\n \t\t\t\t\t\tl++;\n \t\t\t\t\t}\n \t\t\t\t\tleft[i][m] = l;\n \t\t\t\t}\n \t\t\t\twhile(l < n){\n \t\t\t\t\tfreq[arr[l]]--;\n \t\t\t\t\tl++;\n \t\t\t\t}\n \t\t\t\t\n \t\t\t}\n \t\t\tlong[][] dp = new long[n][k+1];\n \t\t\tfor(int i=0;i<n;i++){\n \t\t\t\tArrays.fill(dp[i],  Integer.MAX_VALUE);\n \t\t\t}\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 s = 0;s<=j;s++){\n \t\t\t\t\t\tif (left[i][s] == 0){\n \t\t\t\t\t\t\tdp[i][j] = 1;\n \t\t\t\t\t\t\tcontinue;\n \t\t\t\t\t\t}\n \t\t\t\t\t\tdp[i][j] = Math.min(dp[i][j],  dp[left[i][s]-1][j-s]+1);\n\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\t\n \t\t\t}\n \t\t\tout.println(dp[n-1][k]);\n \t\t\t\n \t\t}\n\t \t\t\n \t\tout.close();\n \t}\n\tstatic class MS{\n//      TreeSet<Long> set;\n      HashMap<Long, Integer> map;\n      public MS() {\n//          set = new TreeSet<Long>();\n          map = new HashMap<Long, Integer>();\n      }\n      public void add(long x) {\n          if(map.containsKey(x)){\n              map.put(x, map.get(x)+1);\n          }\n          else{\n              map.put(x, 1);\n//              set.add(x);\n          }\n      }\n      public void remove(long x) {\n          if(!map.containsKey(x))\n              return;\n          if(map.get(x)==1){\n              map.remove(x);\n//              set.remove(x);\n          }\n          else \n              map.put(x, map.get(x)-1);\n      }\n//      public long getFirst() {\n//          return set.first();\n//      }\n//      public long getLast() {\n//          return set.last();\n//      }\n      public int size() {\n          return map.keySet().size();\n      }\n      public void removeAll(int x) {\n          map.remove(x);\n      }\n      public int getFreq(long x){\n      \tif (map.containsKey(x))\n      \t\treturn map.get(x);\n      \treturn 0;\n      }\n  }\n\tpublic static void prime(int n){\n\t\tint[] isPrime = new int[n+1];\n\t\tArrays.fill(isPrime, 1);\n\t\tfor(long i = 2;i<=n;i++){\n\t\t\tif (isPrime[(int)i] == 1){\n\t\t\t\tfor(long j = i*i;j<=n;j+=i){\n\t\t\t\t\tisPrime[(int)j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int j = 3;j<=n;j++){\n\t\t\tif (isPrime[j] == 1){\n\t\t\t\tprimes.add(j);\n\t\t\t}\n\t\t}\n\t}\n\tpublic static int factorize(long n) { \n\t \t\n\t \tlong prod = 1;\n        int count = 0; \n        while (n%2 == 0){\n            n >>= 1; \n            count++; \n        } \n        if (count > 0 && count%2 == 1)\n            prod *= 2L;\n        for (long i : primes) { \n        \tif (i*i > n)\n        \t\tbreak;\n            count = 0; \n            while (n % i == 0) { \n                count++; \n                n = n / i; \n            } \n            if (count > 0 && count%2 == 1)\n                prod *= i;\n        }  \n        if (n > 2)\n        \tprod *= n;\n        return (int)prod;\n    }\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1497E2 extends PrintWriter {\n\tCF1497E2() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tbyte[] bb = new byte[1 << 15]; int i, n;\n\t\tbyte getc() {\n\t\t\tif (i == n) {\n\t\t\t\ti = n = 0;\n\t\t\t\ttry { n = in.read(bb); } catch (IOException e) {}\n\t\t\t}\n\t\t\treturn i < n ? bb[i++] : 0;\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= ' ') c = getc();\n\t\t\tint a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1497E2 o = new CF1497E2(); o.main(); o.flush();\n\t}\n\n\tstatic final int A = 10000000, K = 20;\n\tint[] cc = new int[A + 1]; {\n\t\tboolean[] composite = new boolean[A + 1];\n\t\tfor (int a = 1; a <= A; a++)\n\t\t\tcc[a] = a;\n\t\tfor (int a = 2; a <= A; a++) {\n\t\t\tif (composite[a])\n\t\t\t\tcontinue;\n\t\t\tfor (int b = a + a; b <= A; b += a)\n\t\t\t\tcomposite[b] = true;\n\t\t\tif (a <= A / a) {\n\t\t\t\tint a2 = a * a;\n\t\t\t\tfor (int b = a2; b <= A; b += a2) {\n\t\t\t\t\tint c = cc[b];\n\t\t\t\t\twhile (c % a2 == 0)\n\t\t\t\t\t\tc /= a2;\n\t\t\t\t\tcc[b] = c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tvoid main() {\n\t\tint[] pp = new int[A + 1]; Arrays.fill(pp, -1);\n\t\tint t = sc.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint k = sc.nextInt();\n\t\t\tint[] aa = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\taa[i] = cc[sc.nextInt()];\n\t\t\tint[] mp = new int[k + 1];\n\t\t\tint[] ip = new int[k + 1];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint a = aa[i];\n\t\t\t\tfor (int h = k; h >= 0; h--) {\n\t\t\t\t\tif (pp[a] >= ip[h]) {\n\t\t\t\t\t\tmp[h]++;\n\t\t\t\t\t\tip[h] = i;\n\t\t\t\t\t}\n\t\t\t\t\tif (h > 0 && (mp[h - 1] < mp[h] || mp[h - 1] == mp[h] && ip[h - 1] > ip[h])) {\n\t\t\t\t\t\tmp[h] = mp[h - 1];\n\t\t\t\t\t\tip[h] = ip[h - 1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpp[a] = i;\n\t\t\t}\n\t\t\tprintln(mp[k] + 1);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint a = aa[i];\n\t\t\t\tpp[a] = -1;\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class cf1497_Div2_E2 {\n\tstatic int[] spf;\n\t\n\tpublic static int factor(int n) {\n\t\tint val = 1;\n\t\twhile (n > 1) {\n\t\t\tint cnt = 0;\n\t\t\tint p = spf[n];\n\t\t\twhile (n % p == 0) {\n\t\t\t\tcnt++;\n\t\t\t\tn /= p;\n\t\t\t}\n\t\t\tif (cnt % 2 == 1)\n\t\t\t\tval *= p;\n\t\t}\n\t\treturn val;\n\t}\n\t\n\tpublic static void main(String args[]) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint t = in.nextInt();\n\t\tint max = (int)(1e7) + 1;\n\t\t\n\t\tboolean[] prime = new boolean[max + 1]; \n\t\tArrays.fill(prime, true);\n\t\tprime[0] = prime[1] = false;\n\t\tspf = new int[max];\n\t\tfor (int i = 2; i < max; i++) spf[i] = i;\n\t\tfor (int i = 2; i * i < max; i++) {\n\t\t\tif (prime[i]) {\n\t\t\t\tspf[i] = i;\n\t\t\t\tfor (int j = i * i; j < max; j += i) {\n\t\t\t\t\tprime[j] = false;\n\t\t\t\t\tspf[j] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] cnts = new int[max];\n\t\t\n\t\tfor ( ; t > 0; t--) {\n\t\t\tint n = in.nextInt();\n\t\t\tint k = in.nextInt();\n\t\t\tint[] vals = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tvals[i] = factor(in.nextInt());\n\t\t\t\n\t\t\t// left[i][x] = l where al ... ai such that in x moves it is valid subsequence\n\t\t\tint[][] left = new int[n + 1][k + 1];\n\t\t\t// x y z w a b c\n\t\t\t\n\t\t\tfor (int x = 0; x <= k; x++) {\n\t\t\t\tint l = n;\n\t\t\t\tint now = 0;\n\t\t\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\t\t\twhile (l - 1 >= 0 && now + ((cnts[vals[l - 1]] > 0) ? 1 : 0) <= x) {\n\t\t\t\t\t\tl--;\n\t\t\t\t\t\tnow += ((cnts[vals[l]] > 0) ? 1 : 0);\n\t\t\t\t\t\t// System.out.println(now);\n\t\t\t\t\t\tcnts[vals[l]]++;\n\t\t\t\t\t}\n\t\t\t\t\t// System.out.println(i + \" \" + x + \" \" + l + \" \" + now);\n\t\t\t\t\tleft[i][x] = l;\n\t\t\t\t\tif (cnts[vals[i]] > 1) now--;\n\t\t\t\t\tcnts[vals[i]]--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// for (int[] x: left)\n\t\t\t\t// System.out.println(Arrays.toString(x));\n\t\t\n\t\t\t\t\n\t\t\tint oo = (int)(1e9);\n\t\t\t\n\t\t\tint[][] dp = new int[n + 1][k + 1];\n\t\t\t\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tArrays.fill(dp[i], oo);\n\t\t\t\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tfor (int j = 0; j <= k; j++) {\n\t\t\t\t\tif (j > 0) dp[i][j] = dp[i][j - 1];\n\t\t\t\t\tfor (int x = 0; x <= j; x++) {\n\t\t\t\t\t\tint l = left[i - 1][x];\n\t\t\t\t\t\tdp[i][j] = Math.min(dp[i][j], dp[l][j - x] + 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint min = Integer.MAX_VALUE;\n\t\t\tfor (int i = 0; i <= k; i++) {\n\t\t\t\tmin = Math.min(min, dp[n][i]);\n\t\t\t}\n\t\t\t\n\t\t\tout.println(min);\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\n\t\n\tstatic class FastScanner {\n\t    BufferedReader br;\n\t    StringTokenizer st;\n\t\t\n\t    public FastScanner(InputStream i) {\n\t        br = new BufferedReader(new InputStreamReader(i));\n\t        st = new StringTokenizer(\"\");\n\t    }\n\t\t\t\t\n\t    public String next() throws IOException {\n\t        if(st.hasMoreTokens())\n\t            return st.nextToken();\n\t        else\n\t            st = new StringTokenizer(br.readLine());\n\t        return next();\n\t    }\n\n\t    public int nextInt() throws IOException {\n\t        return Integer.parseInt(next());\n\t    }\n\t    //#\n\t    public long nextLong() throws IOException {\n\t        return Long.parseLong(next());\n\t    }\n\t    public double nextDouble() throws IOException {\n\t        return Double.parseDouble(next());\n\t    }\n\t    //$\n\t}\n}\n", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "//stan hu tao\n//join nct ridin by first year culture reps\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.abs;\nimport static java.lang.System.out;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class x1497E\n{\n    static final int MAX = 10000000;\n    public static void main(String hi[]) throws Exception\n    {\n        int[] prime = new int[MAX+1];\n        for(int d=2; d <= MAX; d++)\n            if(prime[d] == 0)\n                for(int v=d; v <= MAX; v+=d)\n                    if(prime[v] == 0)\n                        prime[v] = d;\n        FastScanner infile = new FastScanner();\n        int T = infile.nextInt();\n        StringBuilder sb = new StringBuilder();\n        int[] freq = new int[MAX+1];\n        int[] ts = new int[MAX+1];\n        int time = 0;\n        while(T-->0)\n        {\n            int N = infile.nextInt();\n            int K = infile.nextInt();\n            int[] arr = infile.nextInts(N);\n            for(int i=0; i < N; i++)\n            {\n                int key = 1;\n                while(arr[i] > 1)\n                {\n                    int p = prime[arr[i]];\n                    int cnt = 0;\n                    while(arr[i]%p == 0)\n                    {\n                        arr[i] /= p;\n                        cnt ^= 1;\n                    }\n                    if(cnt == 1)\n                        key *= p;\n                }\n                arr[i] = key;\n            }\n            int[][] right = new int[N][K+1];\n            for(int k=0; k <= K; k++)\n            {\n                int dex = 0;\n                int cnt = 0;\n                for(int i=0; i < N; i++)\n                {\n                    while(dex < N && cnt <= k)\n                    {\n                        if(ts[arr[dex]] == time && freq[arr[dex]] >= 1 && cnt+1 > k)\n                            break;\n                        if(ts[arr[dex]] == time && freq[arr[dex]] >= 1)\n                            cnt++;\n                        if(ts[arr[dex]] < time)\n                        {\n                            ts[arr[dex]] = time;\n                            freq[arr[dex]] = 0;\n                        }\n                        freq[arr[dex]]++;\n                        dex++;\n                    }\n                    right[i][k] = dex;\n                    if(freq[arr[i]] >= 2)\n                        cnt--;\n                    freq[arr[i]]--;\n                }\n                time++;\n            }\n            int[][] dp = new int[N+1][K+1];\n            for(int i=1; i <= N; i++)\n                Arrays.fill(dp[i], N);\n            for(int i=0; i < N; i++)\n                for(int a=0; a <= K; a++)\n                {\n                    dp[i+1][a] = min(dp[i+1][a], dp[i][a]+1);\n                    for(int b=0; b <= K-a; b++)\n                        dp[right[i][b]][a+b] = min(dp[right[i][b]][a+b], dp[i][a]+1);\n                }\n            int res = dp[N][0];\n            for(int k=1; k <= K; k++)\n                res = min(res, dp[N][k]);\n            sb.append(res+\"\\n\");\n        }\n        System.out.print(sb);\n    }\n}\nclass FastScanner\n{\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}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solve{\n    public static void main(String[] args) throws Exception{\n        Scanner sc=new Scanner(System.in);\n        PrintWriter out =new PrintWriter(System.out);\n        int size=(int)1e7+1;\n        int[] pr=new int[size];\n        for(int i=0;i<size;i++){\n            pr[i]=i;\n        }\n        for(int i=2;i*i<size;i++){\n           if(pr[i]==i){int val=i*i;\n            for(int j=val;j<=size;j+=val){\n                 pr[j]=j/val;\n            }\n           }\n        }\n        int t=sc.nextInt();\n        int[] dp=new int[size];\n        Arrays.fill(dp,-1);\n        while(t-->0){\n            int n=sc.nextInt();\n            int k=sc.nextInt();\n            int[] ar=new int[n];\n            for(int i=0;i<n;i++){\n                int a=sc.nextInt();\n                ar[i]=pr[a];\n            }\n            int[] ans=new int[k+1];\n            int[] ind=new int[k+1];\n            for(int i=0;i<n;i++){\n                for(int h=k;h>=0;h--){\n                    if(dp[ar[i]]>=ind[h]){\n                        ans[h]++;\n                        ind[h]=i;\n                    }\n                    if(h>0 && (ans[h-1]<ans[h] ||(ans[h-1]==ans[h] && ind[h-1]>ind[h])))\n                    {\n                        ans[h]=ans[h-1];\n                        ind[h]=ind[h-1];\n                    }\n                }\n                dp[ar[i]]=i;\n            }\n            out.println(ans[k]+1);\n            for(int i=0;i<n;i++)dp[ar[i]]=-1;\n        }\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "/**\n * author: derrick20\n * created: 3/19/21 11:57 PM\n */\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E2_SquareFreeDivision2 {\n    static FastScanner sc = new FastScanner();\n    static PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) {\n//        generate();\n        int MAX = (int) 1e7;\n        int[] spf = new int[MAX + 1];\n        for (int i = 2; i <= MAX; i++) {\n            if (spf[i] == 0) {\n                spf[i] = i;\n                for (int j = i + i; j <= MAX; j += i) {\n                    if (spf[j] == 0) {\n                        spf[j] = i;\n                    }\n                }\n            }\n        }\n        int[] freq = new int[MAX + 1];\n        int T = sc.nextInt();\n        while (T-->0) {\n            int N = sc.nextInt();\n            int K = sc.nextInt();\n            int[] a = new int[N + 1];\n            for (int i = 1; i <= N; i++) {\n                a[i] = sc.nextInt();\n                int canonical = 1;\n                while (a[i] > 1) {\n                    int factor = spf[a[i]];\n                    int parity = 0;\n                    while (a[i] % factor == 0) {\n                        a[i] /= factor;\n                        parity ^= 1;\n                    }\n                    if (parity == 1) {\n                        canonical *= factor;\n                    }\n                }\n                a[i] = canonical;\n            }\n            int[][] transition = new int[K + 1][N + 1];\n//            HashMap<Integer, Integer> freq = new HashMap<>();\n            for (int k = 0; k <= K; k++) {\n                int l = N + 1;\n                int duplicates = 0;\n                for (int r = N; r >= 1; r--) {\n                    while (l - 1 >= 1) {\n                        int nextDuplicates = duplicates;\n                        if (freq[a[l - 1]] >= 1) {\n                            nextDuplicates++;\n                        }\n                        if (nextDuplicates <= k) {\n                            duplicates = nextDuplicates;\n                            freq[a[l - 1]]++;\n                            l--;\n                        } else {\n                            break;\n                        }\n                    }\n                    transition[k][r] = l;\n                    if (--freq[a[r]] >= 1) {\n                        duplicates--;\n                    }\n                }\n            }\n            int[][] dp = new int[K + 1][N + 1];\n            int oo = (int) 1e9;\n            for (int[] row : dp) {\n                Arrays.fill(row, oo);\n            }\n            for (int k = 0; k <= K; k++) {\n                dp[k][0] = 0;\n            }\n            for (int r = 1; r <= N; r++) {\n                for (int k = 0; k <= K; k++) {\n                    for (int delta = 0; delta <= k; delta++) {\n                        dp[k][r] = min(dp[k][r], dp[k - delta][transition[delta][r] - 1] + 1);\n                    }\n                }\n            }\n            out.println(dp[K][N]);\n        }\n        out.close();\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        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        int nextInt() {\n            return (int) nextLong();\n        }\n    \n        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        double nextDouble() {\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            double cur = nextLong();\n            if (c != '.') {\n                return neg ? -cur : cur;\n            } else {\n                double frac = nextLong() / cnt;\n                return neg ? -cur - frac : cur + frac;\n            }\n        }\n    \n        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        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        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    \n    static void ASSERT(boolean assertion) {\n        if (!assertion) throw new AssertionError();\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    static final int primeCount = 452;\n    static final int[] prime = new int[primeCount];\n\n    static void build_prime() {\n        boolean[] notPrime = new boolean[3200];\n        for (int i = 2; i < 3200; i++) {\n            if (notPrime[i]) continue;\n            for (int j = i * i; j < 3200; j += i) {\n                notPrime[j] = true;\n            }\n        }\n\n        int count = 0;\n        for (int i = 2; i < 3200; i++) {\n            if (notPrime[i]) continue;\n\n            prime[count++] = i;\n        }\n    }\n\n    private static void run(Reader in, PrintWriter out) throws IOException {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = getReal(in.nextInt());\n        }\n\n        int[] pre = new int[n];\n        for (int i = 0; i < n; i++) pre[i] = -1;\n\n        TreeMap<Integer, Integer> exist = new TreeMap<>();\n        for (int i = 0; i < n; i++) {\n            Integer result = exist.get(a[i]);\n            if (result != null) {\n                pre[i] = result;\n            }\n            exist.put(a[i], i);\n        }\n\n        int[][] left = new int[m + 1][n];\n        for (int i = 0; i <= m; i++) {\n            int start = 0;\n            PriorityQueue<Integer> inSame = new PriorityQueue<>();\n            for (int j = 0; j < n; j++) {\n                if (pre[j] >= start) {\n                    inSame.add(pre[j]);\n\n                    if (inSame.size() > i) {\n                        start = inSame.poll() + 1;\n                    }\n                }\n                left[i][j] = start;\n            }\n        }\n\n        int[][] dp = new int[n][m + 1];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j <= m; j++) {\n                if (j == 0) dp[i][0] = Integer.MAX_VALUE;\n                else dp[i][j] = dp[i][j - 1];\n\n                for (int k = 0; k <= j; k++) {\n                    if (left[k][i] == 0) {\n                        dp[i][j] = 1;\n                    } else {\n                        dp[i][j] = Math.min(dp[i][j], dp[left[k][i] - 1][j - k] + 1);\n                    }\n                }\n            }\n        }\n\n        out.println(dp[n - 1][m]);\n    }\n\n    static int getReal(int x) {\n        int result = 1;\n        for (int i = 0; i < primeCount; i++) {\n            if (x % prime[i] == 0) {\n                int count = 0;\n                while (x % prime[i] == 0) {\n                    count++;\n                    x /= prime[i];\n                }\n                if (count % 2 == 1) {\n                    result *= prime[i];\n                }\n            }\n        }\n        result *= x;\n        return result;\n    }\n\n    public static void main(String[] args) throws IOException {\n        Reader in = new Reader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\n        build_prime();\n        int t = in.nextInt();\n        for (int i = 0; i < t; i++) {\n            run(in, out);\n        }\n\n        out.flush();\n        in.close();\n        out.close();\n    }\n\n    static class Reader {\n        BufferedReader reader;\n        StringTokenizer st;\n\n        Reader(InputStreamReader stream) {\n            reader = new BufferedReader(stream, 32768);\n            st = null;\n        }\n\n        void close() throws IOException {\n            reader.close();\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        String nextLine() throws IOException {\n            return reader.readLine();\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    static final int primeCount = 452;\n    static final int[] prime = new int[primeCount];\n\n    static void build_prime() {\n        boolean[] notPrime = new boolean[3200];\n        for (int i = 2; i < 3200; i++) {\n            if (notPrime[i]) continue;\n            for (int j = i * i; j < 3200; j += i) {\n                notPrime[j] = true;\n            }\n        }\n\n        int count = 0;\n        for (int i = 2; i < 3200; i++) {\n            if (notPrime[i]) continue;\n\n            prime[count++] = i;\n        }\n    }\n\n    private static void run(Reader in, PrintWriter out) throws IOException {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = getReal(in.nextInt());\n        }\n\n        int[] pre = new int[n];\n        for (int i = 0; i < n; i++) pre[i] = -1;\n\n        TreeMap<Integer, Integer> exist = new TreeMap<>();\n        for (int i = 0; i < n; i++) {\n            Integer result = exist.get(a[i]);\n            if (result != null) {\n                pre[i] = result;\n            }\n            exist.put(a[i], i);\n        }\n\n        int[][] left = new int[m + 1][n];\n        for (int i = 0; i <= m; i++) {\n            int start = 0;\n            PriorityQueue<Integer> inSame = new PriorityQueue<>();\n            for (int j = 0; j < n; j++) {\n                if (pre[j] >= start) {\n                    inSame.add(pre[j]);\n\n                    if (inSame.size() > i) {\n                        start = inSame.poll() + 1;\n                    }\n                }\n                left[i][j] = start;\n            }\n        }\n\n        int[][] dp = new int[n][m + 1];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j <= m; j++) {\n                dp[i][j] = Integer.MAX_VALUE;\n            }\n            for (int j = 0; j <= m; j++) {\n                for (int k = 0; k <= j; k++) {\n                    if (left[k][i] == 0) {\n                        dp[i][j] = 1;\n                    } else {\n                        dp[i][j] = Math.min(dp[i][j], dp[left[k][i] - 1][j - k] + 1);\n                    }\n                }\n            }\n        }\n\n        out.println(dp[n - 1][m]);\n    }\n\n    static int getReal(int x) {\n        int result = 1;\n        for (int i = 0; i < primeCount; i++) {\n            if (x % prime[i] == 0) {\n                int count = 0;\n                while (x % prime[i] == 0) {\n                    count++;\n                    x /= prime[i];\n                }\n                if (count % 2 == 1) {\n                    result *= prime[i];\n                }\n            }\n        }\n        result *= x;\n        return result;\n    }\n\n    public static void main(String[] args) throws IOException {\n        Reader in = new Reader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\n        build_prime();\n        int t = in.nextInt();\n        for (int i = 0; i < t; i++) {\n            run(in, out);\n        }\n\n        out.flush();\n        in.close();\n        out.close();\n    }\n\n    static class Reader {\n        BufferedReader reader;\n        StringTokenizer st;\n\n        Reader(InputStreamReader stream) {\n            reader = new BufferedReader(stream, 32768);\n            st = null;\n        }\n\n        void close() throws IOException {\n            reader.close();\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        String nextLine() throws IOException {\n            return reader.readLine();\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.stream.IntStream;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.TreeSet;\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        SquareFreeDivisionHardVersion solver = new SquareFreeDivisionHardVersion();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class SquareFreeDivisionHardVersion {\n        static final int MAX = 10000001;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int t = in.nextInt();\n            int[] d = PrimesAndDivisors.generateDivisors(MAX);\n            int[] reduced = new int[MAX];\n            for (int i = 1; i < MAX; i++) {\n                int val = i;\n                reduced[i] = 1;\n                while (val != 1) {\n                    int prime = d[val], exponent = 0;\n                    while (val % prime == 0) {\n                        val /= prime;\n                        exponent ^= 1;\n                    }\n                    if (exponent > 0) reduced[i] *= prime;\n                }\n            }\n            int counter = 0;\n            int[] seen = new int[MAX];\n            for (int jjjj = 0; jjjj < t; jjjj++) {\n                int n = in.nextInt(), k = in.nextInt();\n\n                int[] a = in.readIntArray(n);\n                for (int x : a) seen[reduced[x]] = -1;\n                int[][] dp = new int[n + 1][k + 1];\n                TreeSet<Integer> ts = new TreeSet<>();\n                int num = 0;\n                for (int i = 0; i < n; i++) {\n                    int R = reduced[a[i]];\n                    if (seen[R] != -1) {\n                        ts.add(-seen[R]);\n                        if (ts.size() > k + 1) ts.remove(ts.last());\n                        num++;\n                    }\n                    Arrays.fill(dp[i], n + 1);\n                    for (int j = num; j <= k; j++) dp[i][j] = 1;\n                    seen[R] = i;\n                    int u = 0;\n                    for (int r : ts) {\n                        for (int j = u; j <= k; j++) dp[i][j] = Integer.min(dp[i][j], dp[-r][j - u] + 1);\n                        u++;\n                    }\n//                System.out.println(i + \" \"  + Arrays.toString(dp[i]));\n//                System.out.println(\"Treeset : \" + ts);\n                }\n                out.println(dp[n - 1][k]);\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[] 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 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 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 PrimesAndDivisors {\n        public static int[] generateDivisors(int n) {\n            int[] divisors = IntStream.range(0, n + 1).toArray();\n            for (int i = 2; i * i <= n; i++)\n                if (divisors[i] == i)\n                    for (int j = i * i; j <= n; j += i) divisors[j] = i;\n            return divisors;\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 println(Object... objects) {\n            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\n');\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class SolutionE 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 SolutionE(), \"Main\", 1 << 26).start();\n    }\n\n    static final int[] primeFactors = getSmallestPrimeFactorInIntervalInclusive(10_000_000);\n\n    public void run() {\n        int t = scanner.nextInt();\n        for (int i = 0; i < t; i++) {\n            solve();\n        }\n        out.close();\n    }\n\n    //runs in roughly O(maxN * lg^2(maxN)))\n    public static int[] getSmallestPrimeFactorInIntervalInclusive(int maxN) {\n        int[] result = new int[maxN + 1];\n\n        result[1] = 1;\n        for (int i = 2; i <= maxN; i++) {\n            if (result[i] == 0) {\n                for (int j = i; j <= maxN; j += i) {\n                    result[j] = (result[j / i] % i == 0) ? (result[j/i]/i) : (result[j/i]*i);\n                }\n            }\n        }\n        return result;\n    }\n\n\n    private static void solve() {\n        int n = scanner.nextInt();\n        int k = scanner.nextInt();\n        int[] a = new int[n];\n        for (int i = 0; i < n; i++) {\n            a[i] = primeFactors[scanner.nextInt()];\n        }\n\n        Map<Integer, Integer> lastSeenIndex = new HashMap<>();\n        int[] revertPointers = new int[n];\n        for (int i = 0; i < n; i++) {\n            if (lastSeenIndex.get(a[i]) != null) {\n                revertPointers[i] = lastSeenIndex.get(a[i]);\n            } else {\n                revertPointers[i] = -1;\n            }\n            lastSeenIndex.put(a[i], i);\n        }\n\n        int[][] maxSegment = new int[n][k+1];\n        for (int j = 0; j <= k; j++) {\n            int pointerLeft = 0;\n            int pointerRight = 0;\n            boolean[] changed = new boolean[n];\n            int amountChanged = 0;\n            while (pointerLeft < n) {\n                if (pointerRight < n && revertPointers[pointerRight] < pointerLeft) {\n                    pointerRight++;\n                } else if (pointerRight < n && revertPointers[pointerRight] >= pointerLeft && amountChanged < j) {\n                    changed[revertPointers[pointerRight]] = true;\n                    pointerRight++;\n                    amountChanged++;\n                } else {\n                    if (changed[pointerLeft]) {\n                        amountChanged--;\n                    }\n                    maxSegment[pointerLeft][j] = pointerRight;\n                    pointerLeft++;\n                }\n            }\n        }\n\n        int[][] dp = new int[n+1][k+1];\n\n        for (int j = 0; j <= k; j++) {\n            dp[n][j] = 0;\n        }\n\n        for (int i = n - 1; i >= 0; i--) {\n            for (int j = 0; j <= k; j++) {\n                dp[i][j] = n + 1;\n                for (int x = 0; x <= j; x++) {\n                    int nextJumpTo = maxSegment[i][x];\n                    dp[i][j] = Math.min(dp[i][j], dp[nextJumpTo][j - x] + 1);\n                }\n            }\n        }\n\n        out.println(dp[0][k]);\n    }\n\n    //REMINDERS:\n    //- CHECK FOR INTEGER-OVERFLOW BEFORE SUBMITTING\n\n    //- CAN U BRUTEFORCE OVER SOMETHING, TO MAKE IT EASIER TO CALCULATE THE SOLUTION\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\n\n\n\n\n\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {//scanner from SecondThread\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(System.out);\n\n        int primes[]=new int[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n                73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,\n                173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269,\n                271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379,\n                383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487,\n                491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,\n                613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,\n                733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607,\n                1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721,\n                1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847,\n                1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973,\n                1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373,\n                3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517,\n                3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999};\n\n        int T=Int();\n        for(int t=0;t<T;t++){\n            int n=Int();\n            int k=Int();\n            int A[]=new int[n];\n            for(int i=0;i<n;i++){\n                A[i]=Int();\n            }\n            Sol sol=new Sol();\n            sol.solution(out,A,k,primes);\n        }\n        out.flush();\n\n    }\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\nclass Sol{\n    int dp[][];\n    public void solution(PrintWriter out,int A[],int K,int primes[]){\n        int n=A.length;\n        int id=0;\n        int dp[][]=new int[n+1][K+1];\n        for(int i=0;i<dp.length;i++){\n            Arrays.fill(dp[i],n);\n        }\n\n        //pre-processing\n        Map<String,Integer>f=new HashMap<>();\n        for(int i=0;i<A.length;i++){\n            String h=hash(A[i],primes);\n            if(!f.containsKey(h)){\n                f.put(h,id);\n                A[i]=id;\n                id++;\n            }\n            else{\n                A[i]=f.get(h);\n            }\n        }\n\n\n        int dis[][]=new int[A.length][K+1];\n        for(int k=0;k<=K;k++){//how far it can go\n            int r=n-1;\n            Map<Integer,Integer>ff=new HashMap<>();\n            for(int i=n-1;i>=0;i--){\n                put(ff,A[i]);\n                while(ff.size()+k<(r-i+1)){\n                    remove(ff,A[r]);\n                    dis[r][k]=i+1;\n                    r--;\n                }\n            }\n        }\n\n\n\n        for(int i=0;i<n;i++){\n            for(int j=0;j<=K;j++){\n                if(j>=i+1){\n                    dp[i][j]=1;\n                    continue;\n                }\n                for(int k=0;k<=j;k++){//take k change\n                    int reach=dis[i][k];//the maximum place I can reach\n                    if(reach==0)dp[i][j]=1;\n                    else dp[i][j]=Math.min(dp[i][j],1+dp[reach-1][j-k]);\n                }\n            }\n        }\n        out.println(dp[n-1][K]);\n\n    }\n\n    public void put(Map<Integer,Integer>f,int key){\n        if(!f.containsKey(key))f.put(key,1);\n        else f.put(key,f.get(key)+1);\n    }\n    public void remove(Map<Integer,Integer>f,int key){\n        f.put(key,f.get(key)-1);\n        if(f.get(key)==0)f.remove(key);\n    }\n\n\n    public String hash(int n,int primes[]){\n        StringBuilder str=new StringBuilder(\"a,\");\n        for(int i:primes){\n            if(i*i>n)break;\n            int cnt=0;\n            while(n%i==0){\n                n/=i;\n                cnt++;\n            }\n            cnt%=2;\n            if(cnt!=0)str.append(i+\",\");\n        }\n        if(n!=1)str.append(n+\",\");\n        return str.toString();\n    }\n\n}\n\n\n\n\n\n\n", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "/**\n * author: derrick20\n * created: 3/19/21 11:57 PM\n */\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E2_SquareFreeDivision2 {\n    static FastScanner sc = new FastScanner();\n    static PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) {\n//        generate();\n        int T = sc.nextInt();\n        int MAX = (int) 1e7;\n        int[] canonical = new int[MAX + 1];\n        canonical[1] = 1;\n        for (int factor = 2; factor <= MAX; factor++) {\n            if (canonical[factor] == 0) {\n                for (int mult = factor; mult <= MAX; mult += factor) {\n                    int prev = canonical[mult / factor];\n                    if (prev % factor == 0) {\n                        canonical[mult] = prev / factor;\n                    } else {\n                        canonical[mult] = prev * factor;\n                    }\n                }\n            }\n        }\n//        System.out.println(Arrays.toString(canonical));\n        int[] freq = new int[MAX + 1];\n        while (T-->0) {\n            int N = sc.nextInt();\n            int K = sc.nextInt();\n            int[] a = new int[N + 1];\n            for (int i = 1; i <= N; i++) {\n                a[i] = canonical[sc.nextInt()];\n            }\n            int[][] transition = new int[K + 1][N + 1];\n//            HashMap<Integer, Integer> freq = new HashMap<>();\n            for (int k = 0; k <= K; k++) {\n                int l = N + 1;\n                int duplicates = 0;\n                for (int r = N; r >= 1; r--) {\n                    while (l - 1 >= 1) {\n                        int nextDuplicates = duplicates;\n                        if (freq[a[l - 1]] >= 1) {\n                            nextDuplicates++;\n                        }\n                        if (nextDuplicates <= k) {\n                            duplicates = nextDuplicates;\n                            freq[a[l - 1]]++;\n                            l--;\n                        } else {\n                            break;\n                        }\n                    }\n                    transition[k][r] = l;\n                    if (--freq[a[r]] >= 1) {\n                        duplicates--;\n                    }\n                }\n            }\n            int[][] dp = new int[K + 1][N + 1];\n            int oo = (int) 1e9;\n            for (int[] row : dp) {\n                Arrays.fill(row, oo);\n            }\n            for (int k = 0; k <= K; k++) {\n                dp[k][0] = 0;\n            }\n            for (int r = 1; r <= N; r++) {\n                for (int k = 0; k <= K; k++) {\n                    for (int delta = 0; delta <= k; delta++) {\n                        dp[k][r] = min(dp[k][r], dp[k - delta][transition[delta][r] - 1] + 1);\n                    }\n                }\n            }\n            out.println(dp[K][N]);\n        }\n        out.close();\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        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        int nextInt() {\n            return (int) nextLong();\n        }\n    \n        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        double nextDouble() {\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            double cur = nextLong();\n            if (c != '.') {\n                return neg ? -cur : cur;\n            } else {\n                double frac = nextLong() / cnt;\n                return neg ? -cur - frac : cur + frac;\n            }\n        }\n    \n        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        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        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    \n    static void ASSERT(boolean assertion) {\n        if (!assertion) throw new AssertionError();\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\n\npublic class Main {\n    static PrintWriter out;\n    static Reader in;\n    public static void main(String[] args) throws IOException {\n        input_output();\n        Main solver = new Main();\n        solver.solve();\n        out.close(); \n        out.flush(); \n    }\n\n    static long INF = (long)1e18;\n    static int MAXN = (int)1e7+5;\n    static int mod = 998_244_353;\n    static int n, m, q, t;\n    static double pi = Math.PI;\n\n    void solve() throws IOException{\n    \tt = in.nextInt();\n\n    \tint[] div = new int[MAXN];\n    \tArrays.fill(div, 1);\n    \tfor (int i = 2; i < MAXN; i++) {\n    \t\tif (div[i] == 1) {\n    \t\t\tfor (int j = i; j < MAXN; j+=i) {\n    \t\t\t\tdiv[j] = i;\n    \t\t\t}\n    \t\t}\n    \t}\n\n    \twhile (t --> 0) {\n    \t\tn = in.nextInt();\n\t\t\tint k = in.nextInt();\n\n\t\t\tint[] arr = new int[n+1];\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tarr[i] = in.nextInt();\n\t\t\t\tint tmp = arr[i], newn = 1;\n\n\t\t\t\twhile (div[arr[i]] != 1) {\n\t\t\t\t\tint elm = div[arr[i]],\n\t\t\t\t\t\tcnt = 0;\n\t\t\t\t\twhile (div[arr[i]] == elm) {\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\tarr[i] /= elm;\n\t\t\t\t\t}\n\t\t\t\t\tif (cnt%2 == 1) newn *= elm;\n\t\t\t\t}\n\t\t\t\tnewn *= arr[i];\n\t\t\t\tarr[i] = newn;\n\t\t\t}\n\n\t\t\tint[] close = new int[n+1];\n\t\t\tList<Node> list = new ArrayList<>();\n\t\t\tfor (int i = 1; i <= n; i++) list.add(new Node(arr[i], i));\n\t\t\tCollections.sort(list);\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i == n-1 || list.get(i+1).val != list.get(i).val) {\n\t\t\t\t\tclose[list.get(i).idx] = -1;\n\t\t\t\t} else {\n\t\t\t\t\tclose[list.get(i).idx] = list.get(i+1).idx;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint[][] next = new int[n+1][k+1];\n\t\t\tList<Integer> upd = new ArrayList<>();\n\t\t\tList<Integer> nupd = new ArrayList<>();\n\t\t\tfor (int i = 0; i <= k; i++) next[n][i] = n;\n\t\t\tfor (int i = n-1; i >= 1; i--) {\n\t\t\t\tnupd.clear();\n\t\t\t\tif (close[i] == -1) {\n\t\t\t\t\tfor (int j = 0; j <= k; j++) next[i][j] = next[i+1][j];\n\t\t\t\t} else {\n\t\t\t\t\tint tmp = close[i]-1, cnt = 0;\n\t\t\t\t\tif (upd.size() == 0 || tmp < upd.get(0)) {\n\t\t\t\t\t\tnupd.add(tmp);\n\t\t\t\t\t\ttmp = -1;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int j = 0; j < upd.size(); j++) {\n\t\t\t\t\t\tif (nupd.size() < k+1 && tmp != -1 && tmp < upd.get(j)) {\n\t\t\t\t\t\t\tnupd.add(tmp);\n\t\t\t\t\t\t\ttmp = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (nupd.size() < k+1) nupd.add(upd.get(j));\n\t\t\t\t\t}\n\t\t\t\t\tif (tmp != -1 && nupd.size() < k+1) nupd.add(tmp);\n\n\t\t\t\t\tfor (int j = 0; j < nupd.size(); j++) \n\t\t\t\t\t\tnext[i][j] = nupd.get(j);\n\t\t\t\t\tfor (int j = nupd.size(); j <= k; j++)\n\t\t\t\t\t\tnext[i][j] = n;\n\n\t\t\t\t\tupd.clear();\n\t\t\t\t\tfor (int j = 0; j < nupd.size(); j++) upd.add(nupd.get(j));\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\n\t\t\tint[][] dp = new int[n+1][k+1];\n    \t\tfor (int i = 1; i <= n; i++)\n    \t\t\tfor (int j = 0; j <= k; j++)\n    \t\t\t\tdp[i][j] = n;\n    \t\tfor (int i = 0; i < n; i++) {\n    \t\t\tfor (int cur = 0; cur <= k; cur++) {\n    \t\t\t\tfor (int ncur = cur; ncur <= k; ncur++) {\n    \t\t\t\t\tdp[next[i+1][ncur-cur]][ncur] = Math.min(dp[next[i+1][ncur-cur]][ncur],\n    \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t dp[i][cur]+1);\n    \t\t\t\t}\n    \t\t\t}\n    \t\t}\n\n    \t\tint ans = n;\n    \t\tfor (int i = 0; i <= k; i++) ans = Math.min(ans, dp[n][i]);\n    \t\tout.println(ans);\n    \t}\n   \t}\n\n    //<>\n\n    static class Node implements Comparable<Node> {\n    \tint val, idx;\n\n    \tNode (int val, int idx) {\n    \t\tthis.val = val;\n    \t\tthis.idx = idx;\n    \t}\n\n    \tpublic int compareTo(Node o) {\n    \t\tif (this.val != o.val) return this.val - o.val;\n    \t\treturn this.idx - o.idx;\n    \t}\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    static void input_output() throws IOException {\n        File f = new File(\"in.txt\");\n        if(f.exists() && !f.isDirectory()) { \n            in = new Reader(new FileInputStream(\"in.txt\"));\n        } else in = new Reader();\n        f = new File(\"out.txt\");\n        if(f.exists() && !f.isDirectory()) {\n            out = new PrintWriter(new File(\"out.txt\"));\n        } else out = new PrintWriter(System.out);\n    }\n}", "complexity": "cubic", "problem": "1497E2", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.*;\nimport java.math.*;\n\n/*\n 50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393\n\n 6\n 2 2 3 3 5 5\n \n 4\n 2 2 3 3\n\n */\npublic class C429 {\n\t\n\tstatic InputStream is;\n\tstatic int[] counts;\n\tstatic int[] sufsum;\n\tstatic long mod = (long)(1e9+7);\n\tstatic long[][] choose;\n\tstatic long[][] memo;\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\t\n\t\tis = System.in;\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tlong[] fact = new long[n+2];\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i < fact.length; i++) {\n\t\t\tfact[i] = (fact[i-1]*i)%mod;\n\t\t}\n\t\t\n\t\tHashMap<Integer,ArrayList<Integer>> hm = new HashMap<>();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint cp = a[i];\n\t\t\tint sfree = 1;\n\t\t\tfor(int p = 2; p*p <= a[i] && cp > 1; p++){\n\t\t\t\tint count = 0;\n\t\t\t\twhile(cp % p == 0){\n\t\t\t\t\tcp /= p;\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tif(count % 2 == 1) sfree *= p;\n\t\t\t}\n\t\t\tif(cp != 1) sfree *= cp;\n\t\t\tif(!hm.containsKey(sfree)) hm.put(sfree, new ArrayList<Integer>());\n\t\t\thm.get(sfree).add(a[i]);\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\tcounts = new int[hm.size()];\n\t\tint dex = 0;\n\t\t\n\t\t//System.out.println(hm);\n\t\tlong bigmult = 1;\n\t\tfor(Integer key : hm.keySet()){\n\t\t\tArrayList<Integer> list = hm.get(key);\n\t\t\tcounts[dex++] = list.size();\n\t\t\tbigmult = bigmult*fact[list.size()] % mod;\n//\t\t\tHashMap<Integer,Integer> dups = new HashMap<>();\n//\t\t\tfor(int x : list){\n//\t\t\t\tif(!dups.containsKey(x)){\n//\t\t\t\t\tdups.put(x, 0);\n//\t\t\t\t}\n//\t\t\t\tdups.put(x, dups.get(x)+1);\n//\t\t\t}\n\t\t\t\n//\t\t\tfor (int k : dups.keySet()) {\n//\t\t\t\tint amount = dups.get(k);\n//\t\t\t\tlong tomult = new BigInteger(fact[amount]+\"\").modInverse(new BigInteger(mod+\"\")).longValue();\n//\t\t\t\tbigmult*= tomult;\n//\t\t\t\tbigmult %= mod;\n//\t\t\t}\n\t\t\t\n\t\t}\n\t\tArrays.sort(counts);\n\t\tsufsum = new int[counts.length];\n\t\tfor(int i = counts.length-2; i >= 0; i--){\n\t\t\tsufsum[i] = sufsum[i+1]+counts[i+1];\n\t\t}\n\t\t\t\n\t\tchoose = new long[2*n+3][2*n+3];\n\t\tfor(int i = 0; i < choose.length; i++){\n\t\t\tchoose[i][0] = 1;\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\t\t}\n\t\t}\n\t\t\n\t\tmemo = new long[counts.length][700];\n\t\tfor (int i = 0; i < memo.length; i++) {\n\t\t\tArrays.fill(memo[i], -1);\n\t\t}\n\t\t//System.out.println(\"bigmult: \" + bigmult);\n\t\tSystem.out.println((bigmult*dp(counts.length-2,counts[counts.length-1]-1))%mod);\n\t}\n\t\n\tstatic long dp(int dex, int need){\n\t\tif(dex == -1){\n\t\t\tif(need == 0) return 1;\n\t\t\treturn 0;\n\t\t}\n\t\t//System.out.println(\"dex: \" + dex + \" need \" + need);\n\t\tif(memo[dex][need] != -1) return memo[dex][need];\n\t\tint numspots = sufsum[dex]+1;\n\t\tlong ret = 0;\n\t\t\n\t\tint c = counts[dex];\n\t\tfor(int numdivs = 1; numdivs <= c; numdivs++) {\n\t\t\tlong toadd = 0;\n\n\t\t\tfor(int gotoneed =0; gotoneed <= need && gotoneed <= numdivs; gotoneed++) {\n\t\t\t\tlong temp = choose[need][gotoneed];\n\t\t\t\ttemp *= choose[numspots-need][numdivs-gotoneed];\n\t\t\t\t\n\t\t\t\t//System.out.println(\"dex: \" + dex + \" need: \"+ need + \" numdivs: \" + numdivs + \" c1: \" + choose[need][gotoneed] + \" c2 \" +  choose[numspots-need][numdivs-gotoneed]);\n\t\t\t\t\n\t\t\t\ttemp %= mod;\n\t\t\t\ttemp *= dp(dex-1,need-gotoneed+c-numdivs);\n\t\t\t\ttemp %= mod;\n\t\t\t\t\n\t\t\t\ttoadd += temp;\n\t\t\t\ttoadd %= mod;\n\t\t\t}\n\t\t\ttoadd *= choose[c-1][numdivs-1];\n\t\t\ttoadd %= mod;\n\t\t\tret += toadd;\n\t\t\tret %= mod;\n\t\t}\n\t\t\n\t\t//System.out.println(\"dex: \" + dex + \" need: \"+ need + \" ret: \" + ret);\n\t\t\n\t\treturn  memo[dex][need]=ret;\n\t}\n\t\t\n\tprivate static byte[] inbuf = new byte[1024];\n\tpublic static int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate static 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 static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate static double nd() { return Double.parseDouble(ns()); }\n\tprivate static char nc() { return (char)skip(); }\n\t\n\tprivate static 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 static 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 static 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 static 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 static 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 static 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}", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "//package round429;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\n// 203530\npublic class C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint v = a[i];\n\t\t\tfor(int j = 2;j*j <= v;j++){\n\t\t\t\twhile(v % (j*j) == 0){\n\t\t\t\t\tv /= j*j;\n\t\t\t\t}\n\t\t\t}\n\t\t\ta[i] = v;\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\tint[] f = new int[n];\n\t\tint p = 0;\n\t\tfor(int i= 0;i < n;i++){\n\t\t\tif(i > 0 && a[i] != a[i-1]){\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tf[p]++;\n\t\t}\n\t\tf = Arrays.copyOf(f, p+1);\n\t\tint mod = 1000000007;\n\t\t\n\t\tint[][] fif = enumFIF(1000, mod);\n\t\tlong[] res = countSameNeighborsSequence(f, fif, mod);\n\t\tlong ans = res[0];\n\t\tfor(int v : f){\n\t\t\tans = ans * fif[0][v] % mod;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tpublic static long[] countSameNeighborsSequence(int[] a, int[][] fif, int mod)\n\t{\n\t\tint all = 0;\n\t\tfor(int v : a)all += v;\n\t\t\n\t\tint len = 0;\n\t\tlong[] dp = new long[all+1];\n\t\tdp[0] = 1;\n\t\tfor(int v : a){\n\t\t\tlong[][] pre = new long[all+1][v+1];\n\t\t\tfor(int j = 0;j <= all;j++)pre[j][0] = dp[j];\n\t\t\tfor(int j = 0;j < v;j++){\n\t\t\t\tfor(int k = 0;k <= all;k++){\n\t\t\t\t\tfor(int L = j;L >= 0;L--){\n\t\t\t\t\t\tif(pre[k][L] == 0)continue;\n\t\t\t\t\t\tint ca = 2*(j-L);\n\t\t\t\t\t\tint ab = len+j+1-k-ca-L;\n\t\t\t\t\t\tif(ab < 0)continue;\n\t\t\t\t\t\tif(k-1 >= 0){\n\t\t\t\t\t\t\tpre[k-1][L] += pre[k][L]*k; // aca\n\t\t\t\t\t\t\tpre[k-1][L] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(L+1 <= v){\n\t\t\t\t\t\t\tpre[k][L+1] += pre[k][L]*(ca+L);\n\t\t\t\t\t\t\tpre[k][L+1] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpre[k][L] = pre[k][L]*ab%mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tArrays.fill(dp, 0);\n\t\t\tfor(int k = 0;k <= all;k++){\n\t\t\t\tfor(int L = 0;L <= v && k+L <= all;L++){\n\t\t\t\t\tdp[k+L] += pre[k][L];\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int k = 0;k <= all;k++){\n\t\t\t\tdp[k] %= mod;\n\t\t\t}\n//\t\t\tfor(int k = 0;k <= all;k++){\n//\t\t\t\tdp[k] = dp[k] % mod * fif[1][v] % mod;\n//\t\t\t}\n\t\t\tlen += v;\n\t\t}\n\t\tlong fifs = 1;\n\t\tfor(int v : a)fifs = fifs * fif[1][v] % mod;\n\t\tfor(int k = 0;k <= all;k++)dp[k] = dp[k] * fifs % mod;\n\t\t\n\t\treturn dp;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new C().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", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tint removeSq(int x) {\n\t\tfor (int i = 2; i * i <= x; i++) {\n\t\t\twhile (x % (i * i) == 0) {\n\t\t\t\tx /= i * i;\n\t\t\t}\n\t\t}\n\t\treturn x;\n\t}\n\t\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tHashMap<Integer, Integer> map = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = removeSq(nextInt());\n\t\t\tmap.merge(x, 1, Integer::sum);\n\t\t}\n\t\t\n\t\tint[] a = new int[map.size()];\n\t\tint ptr = 0;\n\t\tfor (Integer x : map.values()) {\n\t\t\ta[ptr++] = x;\n\t\t}\n\n\t\tint ret = go(a);\n\t\tfor (int x : a) {\n\t\t\tret = (int)((long)ret * fact[x] % P);\n\t\t}\n\t\t\n\t\tout.println(ret);\n\t}\n\t\n\tint go(int[] a) {\n\t\tint[] dp = new int[a[0]];\n\t\tdp[a[0] - 1] = 1;\n\n\t\tint places = a[0] + 1;\n\t\t\n\t\tint toInsert = 0;\n\t\tfor (int x : a) {\n\t\t\ttoInsert += x;\n\t\t}\n\t\ttoInsert -= a[0];\n\n\t\tfor (int i =1; i < a.length; i++) {\n\n\t\t\tint here = a[i];\n\t\t\tif (here == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tint[] nxt = new int[dp.length + here];\n\n\t\t\tfor (int wasSame = 0; wasSame < dp.length; wasSame++) {\n\t\t\t\tif (wasSame > toInsert) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (dp[wasSame] == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint wasDiff = places - wasSame;\n\n\t\t\t\tfor (int runsSame = 0; runsSame <= wasSame && runsSame <= here; runsSame++) {\n\t\t\t\t\tfor (int runsDiff = 0; runsDiff <= wasDiff && runsSame + runsDiff <= here; runsDiff++) {\n\t\t\t\t\t\tif (runsSame + runsDiff == 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint delta = (int) ((long) dp[wasSame]\n\t\t\t\t\t\t\t\t* ways[wasSame][runsSame] % P * ways[wasDiff][runsDiff]\n\t\t\t\t\t\t\t\t% P * ways[here - 1][runsSame + runsDiff - 1] % P);\n\t\t\t\t\t\tif (delta == 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint nxtIdx = (wasSame - runsSame) + (here - runsSame - runsDiff);\n\t\t\t\t\t\tnxt[nxtIdx] += delta;\n\t\t\t\t\t\tif (nxt[nxtIdx] >= P) {\n\t\t\t\t\t\t\tnxt[nxtIdx] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tdp = nxt;\n\t\t\tplaces += here;\n\t\t\ttoInsert -= here;\n\t\t}\n\t\t\n//\t\tSystem.err.println(Arrays.toString(a) + \" \" + idx);\n//\t\tSystem.err.println(Arrays.toString(dp));\n\t\treturn dp[0];\n\t}\n\t\n\tint[][] ways;\n\tint[] fact;\n\tstatic final int N = 350;\n\tstatic final int P = 1_000_000_007;\n\n\tvoid preCalc() {\n\t\tways = new int[N][];\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tways[i] = new int[i + 1];\n\t\t\tways[i][0] = ways[i][i] = 1;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tways[i][j] = ways[i - 1][j] + ways[i - 1][j - 1];\n\t\t\t\tif (ways[i][j] >= P) {\n\t\t\t\t\tways[i][j] -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfact = new int[N];\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i < N; i++) {\n\t\t\tfact[i] = (int)((long)fact[i - 1] * i % P);\n\t\t}\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tC() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t//stress();\n\t\t//test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\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    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 int MOD = (int) (1e9 + 7);\n        long[][] C;\n        long[] fact;\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            precalc(n);\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.nextInt();\n                a[i] = removeSquares(a[i]);\n            }\n            int[] g = getGroupSizes(a);\n            long ans = solve(g);\n            for (int x : g) {\n                ans = ans * fact[x] % MOD;\n            }\n            out.println(ans);\n        }\n\n        private long solve(int[] a) {\n            // For a description, see http://petr-mitrichev.blogspot.com/2017/07/a-week7.html\n            long[] d = new long[1];\n            d[0] = 1;\n            int totalPositions = 1;\n            for (int x : a) {\n                long[] nd = new long[d.length + x + 1];\n                for (int s = 0; s < d.length; s++) {\n                    if (d[s] == 0) {\n                        continue;\n                    }\n                    for (int m = 1; m <= x; m++) {\n                        for (int p = 0; p <= s && p <= m; p++) {\n                            long cur = d[s];\n                            cur = cur * C[s][p] % MOD;\n                            cur = cur * C[totalPositions - s][m - p] % MOD;\n                            cur = cur * f(x, m) % MOD;\n                            int ns = s + x - m - p;\n                            nd[ns] += cur;\n                            if (nd[ns] >= MOD) {\n                                nd[ns] -= MOD;\n                            }\n                        }\n                    }\n                }\n                totalPositions += x;\n                d = nd;\n            }\n            return d[0];\n        }\n\n        private long f(int n, int k) {\n            if (n < k) {\n                return 0;\n            }\n            n -= k;\n            return C[n + k - 1][k - 1];\n        }\n\n        private void precalc(int n) {\n            fact = new long[n + 1];\n            fact[0] = 1;\n            for (int i = 1; i < fact.length; i++) {\n                fact[i] = i * fact[i - 1] % MOD;\n            }\n\n            C = new long[1000][1000];\n            C[0][0] = 1;\n            for (int i = 1; i < C.length; i++) {\n                C[i][0] = 1;\n                for (int j = 1; j < C.length; 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        }\n\n        private int[] getGroupSizes(int[] a) {\n            Arrays.sort(a);\n            List<Integer> res = new ArrayList<>();\n            for (int i = 0; i < a.length; ) {\n                int j = i;\n                while (j < a.length && a[i] == a[j]) {\n                    ++j;\n                }\n                res.add(j - i);\n                i = j;\n            }\n            int[] r = new int[res.size()];\n            for (int i = 0; i < r.length; i++) {\n                r[i] = res.get(i);\n            }\n            return r;\n        }\n\n        private int removeSquares(int n) {\n            int res = 1;\n            for (int d = 2; d * d <= n; d++) {\n                if (n % d == 0) {\n                    int cur = 0;\n                    while (n % d == 0) {\n                        n /= d;\n                        ++cur;\n                    }\n                    if (cur % 2 == 1) {\n                        res *= d;\n                    }\n                }\n            }\n            if (n > 1) {\n                res *= n;\n            }\n            return res;\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", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "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 Div1_429C {\n\n\tstatic final long MOD = 1_000_000_007;\n\tstatic long[] fact = new long[305];\n\tstatic long[] iFact = new long[305];\n\tstatic final long I304 = 904487323;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i < 305; i++) {\n\t\t\tfact[i] = fact[i - 1] * i % MOD;\n\t\t}\n\t\tiFact[304] = I304;\n\t\tfor (int i = 303; i >= 0; i--) {\n\t\t\tiFact[i] = iFact[i + 1] * (i + 1) % 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\tint len = Integer.parseInt(reader.readLine());\n\t\tlong[] groups = new long[len + 1];\n\t\tint[] gSizes = new int[len + 1];\n\t\tint nG = 0;\n\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tiLoop:\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tlong nxt = Integer.parseInt(inputData.nextToken());\n\t\t\tfor (int j = 1; j <= nG; j++) {\n\t\t\t\tif (isSquare(nxt * groups[j])) {\n\t\t\t\t\tgSizes[j]++;\n\t\t\t\t\tcontinue iLoop;\n\t\t\t\t}\n\t\t\t}\n\t\t\tgroups[++nG] = nxt;\n\t\t\tgSizes[nG] = 1;\n\t\t}\n\n\t\tlong[][] dp = new long[nG + 1][len];\n\n\t\tdp[0][0] = 1;\n\n\t\tint fTotal = 0;\n\t\tfor (int fG = 0; fG < nG; fG++) {\n\t\t\tfor (int fB = 0; fB < len; fB++) {\n\t\t\t\tif (dp[fG][fB] == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint nGSize = gSizes[fG + 1];\n\t\t\t\tfor (int nS = 1; nS <= Math.min(nGSize, fTotal + 1); nS++) {\n\t\t\t\t\tfor (int nBR = 0; nBR <= Math.min(fB, nS); nBR++) {\n\t\t\t\t\t\tlong nW = dp[fG][fB] * fact[nGSize] % MOD * comb(nGSize - 1, nS - 1) % MOD * comb(fB, nBR) % MOD\n\t\t\t\t\t\t\t\t* comb(fTotal + 1 - fB, nS - nBR) % MOD;\n\t\t\t\t\t\tdp[fG + 1][fB - nBR + nGSize - nS] = (dp[fG + 1][fB - nBR + nGSize - nS] + nW) % MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfTotal += gSizes[fG + 1];\n\t\t}\n\t\tprinter.println(dp[nG][0]);\n\t\tprinter.close();\n\t}\n\n\tstatic long comb(int a, int b) {\n\t\tif(b > a) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn fact[a] * iFact[a - b] % MOD * iFact[b] % MOD;\n\t}\n\n\tstatic boolean isSquare(long inp) {\n\t\tlong sqrt = (long) Math.sqrt(inp);\n\t\treturn inp == sqrt * sqrt;\n\t}\n\n}\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public int mod = 1000000007;\n        public int MAXN = 333;\n        public int[][] w1;\n        public long[] fact;\n        public long[] ifact;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            long[][] e = Factorials.getFIF(MAXN, mod);\n            fact = e[0];\n            ifact = e[1];\n            w1 = new int[MAXN][MAXN];\n            w1[0][0] = 1;\n            for (int i = 1; i < MAXN; i++) {\n                for (int j = 1; j < MAXN; j++) {\n                    for (int k = 1; k <= i; k++) {\n                        w1[i][j] += w1[i - k][j - 1];\n                        if (w1[i][j] >= mod) w1[i][j] -= mod;\n                    }\n                }\n            }\n\n            int n = in.nextInt();\n            int[] arr = in.readIntArray(n);\n            boolean[] marked = new boolean[n];\n            int[] fs = new int[n];\n            int fidx = 0;\n            for (int i = 0; i < n; i++) {\n                if (marked[i]) continue;\n                int count = 0;\n                for (int j = 0; j < n; j++) {\n                    if (isSquare(1L * arr[i] * arr[j])) {\n                        if (marked[j]) System.exit(1);\n                        marked[j] = true;\n                        count++;\n                    }\n                }\n                fs[fidx++] = count;\n            }\n\n            fs = Arrays.copyOf(fs, fidx);\n            long x = 1;\n            for (int j : fs) x = x * fact[j] % mod;\n            x = x * solve(fs) % mod;\n            out.println(x);\n        }\n\n        public boolean isSquare(long x) {\n            long d = (long) (Math.sqrt(x));\n            while (d * d < x) d++;\n            while (d * d > x) d--;\n            return d * d == x;\n        }\n\n        public int solve(int[] freq) {\n            int d = AUtils.sum(freq);\n            int b = AUtils.max(freq);\n            if (d == 0) return 1;\n            if (b + b - 1 > d) return 0;\n            int[] dp = new int[1];\n            dp[0] = 1;\n            for (int j = 0; j < freq.length; j++) {\n                if (freq[j] == 0) continue;\n                int[] nxt = new int[dp.length + freq[j]];\n                for (int pgr = 0; pgr < dp.length; pgr++) {\n                    for (int cgr = 1; cgr <= freq[j]; cgr++) {\n                        nxt[pgr + cgr] += 1L * dp[pgr] * w1[freq[j]][cgr] % mod * ifact[cgr] % mod;\n                        if (nxt[pgr + cgr] >= mod) nxt[pgr + cgr] -= mod;\n                    }\n                }\n                dp = nxt;\n            }\n\n            int res = 0;\n            for (int i = 0; i < dp.length; i++) {\n                long x = 1L * dp[i] * fact[i] % mod;\n                if ((d - i) % 2 == 0) res += x;\n                else res -= x;\n                if (res >= mod) res -= mod;\n                if (res < 0) res += mod;\n            }\n            return res;\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n\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 static boolean isSpaceChar(int c) {\n            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n        }\n\n    }\n\n    static class AUtils {\n        public static int max(int[] arr) {\n            int res = arr[0];\n            for (int x : arr) res = Math.max(res, x);\n            return res;\n        }\n\n        public static int sum(int[] arr) {\n            int sum = 0;\n            for (int x : arr) {\n                sum += x;\n            }\n            return sum;\n        }\n\n    }\n\n    static class Factorials {\n        public static long[][] getFIF(int max, int mod) {\n            long[] fact = new long[max];\n            long[] ifact = new long[max];\n            long[] inv = new long[max];\n            inv[1] = 1;\n            for (int i = 2; i < max; i++) {\n                inv[i] = (mod - mod / i) * inv[mod % i] % mod;\n            }\n            fact[0] = 1;\n            ifact[0] = 1;\n            for (int i = 1; i < max; i++) {\n                fact[i] = fact[i - 1] * i % mod;\n                ifact[i] = ifact[i - 1] * inv[i] % mod;\n            }\n            return new long[][]{fact, ifact, inv};\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", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "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            COnTheBench solver = new COnTheBench();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class COnTheBench {\n        Modular mod = new Modular(1e9 + 7);\n        Factorial fact = new Factorial(1000, mod);\n        Combination comb = new Combination(fact);\n        Debug debug = new Debug(true);\n\n        public int f(int i, int j) {\n            int ans = mod.mul(fact.fact(i), comb.combination(i + j - 1 - j, j - 1));\n            ans = mod.mul(ans, fact.invFact(j));\n            return ans;\n        }\n\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.readInt();\n            DSU dsu = new DSU(n);\n            long[] a = new long[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.readInt();\n            }\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < i; j++) {\n                    if (square(a[j] * a[i])) {\n                        dsu.merge(j, i);\n                        break;\n                    }\n                }\n            }\n\n            IntegerList list = new IntegerList();\n            for (int i = 0; i < n; i++) {\n                if (dsu.find(i) == i) {\n                    list.add(dsu.size[dsu.find(i)]);\n                }\n            }\n\n            int[] cnts = list.toArray();\n            debug.debug(\"cnts\", cnts);\n            int m = cnts.length;\n            int[][] dp = new int[m + 1][n + 1];\n            dp[0][0] = 1;\n            for (int i = 1; i <= m; i++) {\n                int way = cnts[i - 1];\n                for (int j = 0; j <= n; j++) {\n                    dp[i][j] = 0;\n                    for (int k = 1; k <= j && k <= way; k++) {\n                        int contrib = mod.mul(f(way, k), dp[i - 1][j - k]);\n                        dp[i][j] = mod.plus(dp[i][j], contrib);\n                    }\n                }\n            }\n            debug.debug(\"dp\", dp);\n\n            int ans = 0;\n            for (int i = 0; i <= n; i++) {\n                int local = mod.mul(dp[m][i], fact.fact(i));\n                if ((n - i) % 2 == 1) {\n                    local = mod.valueOf(-local);\n                }\n                ans = mod.plus(ans, local);\n            }\n\n            out.println(ans);\n        }\n\n        public boolean square(long x) {\n            long l = 1;\n            long r = (long) 1e9;\n            while (l < r) {\n                long m = (l + r) / 2;\n                if (m * m < x) {\n                    l = m + 1;\n                } else {\n                    r = m;\n                }\n            }\n            return l * l == x;\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 int[] toArray() {\n            return Arrays.copyOf(data, size);\n        }\n\n        public String toString() {\n            return Arrays.toString(toArray());\n        }\n\n        public boolean equals(Object obj) {\n            if (!(obj instanceof 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 Combination implements IntCombination {\n        final Factorial factorial;\n        final Modular modular;\n\n        public Combination(Factorial factorial) {\n            this.factorial = factorial;\n            this.modular = factorial.getModular();\n        }\n\n        public Combination(int limit, Modular modular) {\n            this(new Factorial(limit, modular));\n        }\n\n        public int combination(int m, int n) {\n            if (n > m) {\n                return 0;\n            }\n            return modular.mul(modular.mul(factorial.fact(m), factorial.invFact(n)), factorial.invFact(m - n));\n        }\n\n    }\n\n    static class 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 IntCombination {\n    }\n\n    static class FastOutput implements AutoCloseable, Closeable, Appendable {\n        private StringBuilder cache = new StringBuilder(10 << 20);\n        private final Writer os;\n\n        public FastOutput append(CharSequence csq) {\n            cache.append(csq);\n            return this;\n        }\n\n        public FastOutput append(CharSequence csq, int start, int end) {\n            cache.append(csq, start, end);\n            return this;\n        }\n\n        public FastOutput(Writer os) {\n            this.os = os;\n        }\n\n        public FastOutput(OutputStream os) {\n            this(new OutputStreamWriter(os));\n        }\n\n        public FastOutput append(char c) {\n            cache.append(c);\n            return this;\n        }\n\n        public FastOutput append(int c) {\n            cache.append(c);\n            return this;\n        }\n\n        public FastOutput println(int c) {\n            return append(c).println();\n        }\n\n        public FastOutput println() {\n            cache.append(System.lineSeparator());\n            return this;\n        }\n\n        public FastOutput flush() {\n            try {\n                os.append(cache);\n                os.flush();\n                cache.setLength(0);\n            } catch (IOException e) {\n                throw new UncheckedIOException(e);\n            }\n            return this;\n        }\n\n        public void close() {\n            flush();\n            try {\n                os.close();\n            } catch (IOException e) {\n                throw new UncheckedIOException(e);\n            }\n        }\n\n        public String toString() {\n            return cache.toString();\n        }\n\n    }\n\n    static class InverseNumber {\n        int[] inv;\n\n        public InverseNumber(int[] inv, int limit, Modular modular) {\n            this.inv = inv;\n            inv[1] = 1;\n            int p = modular.getMod();\n            for (int i = 2; i <= limit; i++) {\n                int k = p / i;\n                int r = p % i;\n                inv[i] = modular.mul(-k, inv[r]);\n            }\n        }\n\n        public InverseNumber(int limit, Modular modular) {\n            this(new int[limit + 1], limit, modular);\n        }\n\n    }\n\n    static class 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 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 DSU {\n        protected int[] p;\n        protected int[] rank;\n        int[] size;\n\n        public DSU(int n) {\n            p = new int[n];\n            rank = new int[n];\n            size = new int[n];\n            reset();\n        }\n\n        public final void reset() {\n            for (int i = 0; i < p.length; i++) {\n                p[i] = i;\n                rank[i] = 0;\n                size[i] = 1;\n            }\n        }\n\n        public final int find(int a) {\n            if (p[a] == p[p[a]]) {\n                return p[a];\n            }\n            return p[a] = find(p[a]);\n        }\n\n        public final void merge(int a, int b) {\n            a = find(a);\n            b = find(b);\n            if (a == b) {\n                return;\n            }\n            if (rank[a] == rank[b]) {\n                rank[a]++;\n            }\n\n            if (rank[a] < rank[b]) {\n                int tmp = a;\n                a = b;\n                b = tmp;\n            }\n\n            size[a] += size[b];\n            p[b] = a;\n        }\n\n    }\n\n    static class 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 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\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "/**\n * author: derrick20\n * created: 11/11/20 1:03 PM\n */\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class OnTheBench {\n    public static void main(String[] args) {\n        setupCombo(301);\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        \n        int N = sc.nextInt();\n        long[] a = sc.nextLongs(N);\n        boolean[] vis = new boolean[N];\n        int[] groups = new int[N + 1];\n        int G = 0;\n        for (int i = 0; i < N; i++) {\n            if (!vis[i]) {\n                vis[i] = true;\n                int elems = 1;\n                for (int j = i + 1; j < N; j++) {\n                    long prod = a[i] * a[j];\n                    long root = (long) Math.sqrt(prod);\n                    if (!vis[j] && prod == root * root) {\n                        vis[j] = true;\n                        elems++;\n                    }\n                }\n                groups[++G] = elems;\n            }\n        }\n\n        long[][] dp = new long[G + 1][N + 1];\n        // dp[g][bad] = ways to interleave first g groups for a given # of bad pairs\n        dp[0][0] = 1;\n        // dp[0][k] = 0, k != 0\n        int total = 0;\n        for (int prefix = 1; prefix <= G; prefix++) {\n            int amt = groups[prefix];\n            for (int prevBad = 0; prevBad <= max(0, total - 1); prevBad++) {\n                for (int fixed = 0; fixed <= min(prevBad, amt); fixed++) {\n                    for (int slots = max(1, fixed); slots <= min(amt, total + 1); slots++) {\n                        int introduced = amt - slots;\n                        long ways = mult(\n                                choose[prevBad][fixed],\n                                choose[total + 1 - prevBad][slots - fixed],\n                                choose[amt - 1][slots - 1],\n                                fact[amt],\n                                dp[prefix - 1][prevBad]\n                        );\n                        int currBad = prevBad + introduced - fixed;\n                        dp[prefix][currBad] = (dp[prefix][currBad] + ways) % mod;\n                    }\n                }\n            }\n            total += amt;\n//            System.out.println(Arrays.toString(dp[prefix]));\n        }\n        out.println(dp[G][0]);\n        out.close();\n    }\n\n    static long mod = (long) 1e9 + 7;\n    static long[][] choose;\n    static long[] fact;\n\n    static long mult(long... multiplicands) {\n        long ans = 1;\n        for (long v : multiplicands) {\n            ans = (ans * v) % mod;\n        }\n        return ans;\n    }\n\n    static void setupCombo(int MAX) {\n        choose = new long[MAX + 1][MAX + 1];\n        fact = new long[MAX + 1];\n        choose[0][0] = 1;\n        fact[0] = 1;\n        for (int i = 1; i <= MAX; i++) {\n            fact[i] = (long) i * fact[i - 1] % mod;\n            choose[i][0] = 1;\n            for (int j = 1; j < i; j++) {\n                choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % mod;\n            }\n            choose[i][i] = 1;\n        }\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    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}", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "/**\n * author: derrick20\n * created: 11/11/20 1:45 PM\n */\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class OnTheBenchAlt {\n    public static void main(String[] args) {\n        setupCombo(301);\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int N = sc.nextInt();\n        long[] a = new long[N];\n        HashMap<Long, Integer> clusters = new HashMap<>();\n        for (int i = 0; i < N; i++) {\n            a[i] = removeSquares(sc.nextLong());\n            clusters.merge(a[i], 1, Integer::sum);\n        }\n        int G = clusters.size();\n        int[] groups = new int[G + 1];\n        int ptr = 1;\n        for (int amt : clusters.values()) {\n            groups[ptr++] = amt;\n        }\n        long[][] dp = new long[G + 1][N + 1];\n        // dp[g][bad] = ways to interleave first g groups for a given # of bad pairs\n        dp[0][0] = 1;\n        // dp[0][k] = 0, k != 0\n        int total = 0;\n        /*\n        intuition for runtime analysis:\n        Say there were k groups, each size n / k\n\n        The outer loop is k, 2nd loop is n worst case,\n        and the inner 2 are bounded by n / k (amt per group)\n        k * n * (n / k) * (n / k) = n^3 / k, which works despite 4 loops!!\n\n        Seems hard to convert into pull-dp since prevBad has a more direct\n        meaning in the arrangements, so using that as our variable makes more sense\n         */\n        for (int prefix = 1; prefix <= G; prefix++) {\n            int amt = groups[prefix];\n            // key bugs here and there: USE THE CORRECT BOUNDS\n            for (int prevBad = 0; prevBad <= max(0, total - 1); prevBad++) {\n                for (int fixed = 0; fixed <= min(prevBad, amt); fixed++) {\n                    for (int slots = max(1, fixed); slots <= min(amt, total + 1); slots++) {\n                        int introduced = amt - slots;\n                        long ways = mult(\n                                choose[prevBad][fixed],\n                                choose[total + 1 - prevBad][slots - fixed],\n                                choose[amt - 1][slots - 1],\n                                fact[amt],\n                                dp[prefix - 1][prevBad] // key bug: NEED TO RELATE PREVIOUS DP\n                        );\n                        int currBad = prevBad + introduced - fixed;\n                        dp[prefix][currBad] = (dp[prefix][currBad] + ways) % mod;\n                    }\n                }\n            }\n            total += amt;\n//            System.out.println(Arrays.toString(dp[prefix]));\n        }\n        out.println(dp[G][0]);\n        out.close();\n    }\n\n    static long mod = (long) 1e9 + 7;\n    static long[][] choose;\n    static long[] fact;\n\n    static long removeSquares(long x) {\n        long curr = x;\n        for (long v = 2; v * v <= x && curr > 1; v++) {\n            int cnt = 0;\n            while (curr % v == 0) {\n                curr /= v;\n                cnt ^= 1;\n            }\n            if (cnt == 1)\n                curr *= v;\n        }\n        return curr;\n    }\n\n    static long choose(int n, int k) {\n        return k < 0 || k > n ? 0 : choose[n][k];\n    }\n\n    static long mult(long... multiplicands) {\n        long ans = 1;\n        for (long v : multiplicands) {\n            ans = (ans * v) % mod;\n        }\n        return ans;\n    }\n\n    static void setupCombo(int MAX) {\n        choose = new long[MAX + 1][MAX + 1];\n        fact = new long[MAX + 1];\n        choose[0][0] = 1;\n        fact[0] = 1;\n        for (int i = 1; i <= MAX; i++) {\n            fact[i] = (long) i * fact[i - 1] % mod;\n            choose[i][0] = 1;\n            for (int j = 1; j < i; j++) {\n                choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % mod;\n            }\n            choose[i][i] = 1;\n        }\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    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}", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "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.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        OnTheBench solver = new OnTheBench();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class OnTheBench {\n        long MOD = (long) (1e9) + 7;\n        long[][] C = new long[333][333];\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int N = in.nextInt();\n            DisjointSet dsu = new DisjointSet(N);\n            long[] arr = new long[N];\n            setC();\n            for (int i = 0; i < N; i++) {\n                arr[i] = in.nextInt();\n            }\n            for (int i = 0; i < N; i++) {\n                for (int j = i + 1; j < N; j++) {\n                    long sqrt = (long) (Math.sqrt(arr[i] * arr[j]));\n                    long sqrt2 = (long) (Math.ceil(Math.sqrt(arr[i] * arr[j])));\n                    if (sqrt * sqrt == arr[i] * arr[j] || sqrt2 * sqrt2 == arr[i] * arr[j]) {\n                        dsu.merge(i, j);\n                    }\n                }\n            }\n            ArrayList<Integer> sz = new ArrayList<>();\n            sz.add(0);\n            HashMap<Integer, Integer> seen = new HashMap<>();\n            long mult = 1;\n            for (int i = 0; i < N; i++) {\n                if (!seen.containsKey(dsu.find(i))) {\n                    seen.put(dsu.find(i), sz.size());\n                    sz.add(0);\n                }\n                sz.set(seen.get(dsu.find(i)), sz.get(seen.get(dsu.find(i))) + 1);\n            }\n            for (int i : sz) {\n//            if (arr[0] == 285) {\n//                out.println(i);\n//            }\n                mult *= fact(i);\n                mult %= MOD;\n            }\n            long[][] dp = new long[sz.size()][333];\n            int sum = 0;\n            dp[0][0] = 1;\n            for (int n = 1; n < dp.length; n++) {\n                for (int ij = 1; ij <= sz.get(n); ij++) {\n                    for (int y = 0; y <= sum; y++) {\n                        for (int j = 0; j <= Math.min(y, ij); j++) {\n                            int i = ij - j;\n                            dp[n][y - j + sz.get(n) - ij] += ((((dp[n - 1][y] * C[sum + 1 - y][i]) % MOD * C[y][j]) % MOD) * C[sz.get(n) - 1][ij - 1]) % MOD;\n                            dp[n][y - j + sz.get(n) - ij] %= MOD;\n                        }\n                    }\n                }\n                sum += sz.get(n);\n            }\n            out.println((dp[sz.size() - 1][0] * mult) % MOD);\n        }\n\n        void setC() {\n            for (int i = 0; i <= 332; i++) {\n                C[i][0] = 1;\n                for (int j = 1; j <= i; j++) {\n                    C[i][j] = C[i - 1][j] + C[i - 1][j - 1];\n                    C[i][j] %= MOD;\n                }\n            }\n        }\n\n        long fact(int i) {\n            long res = 1;\n            while (i > 0) {\n                res *= i;\n                res %= MOD;\n                i--;\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\n    static class DisjointSet {\n        int[] rank;\n        int[] par;\n\n        public DisjointSet(int N) {\n            rank = new int[N];\n            par = new int[N];\n            for (int i = 0; i < N; i++) {\n                rank[i] = 1;\n                par[i] = i;\n            }\n        }\n\n        public int find(int x) {\n            if (x == par[x]) {\n                return x;\n            }\n            return (par[x] = find(par[x]));\n        }\n\n        public void merge(int x, int y) {\n            int parX = find(x);\n            int parY = find(y);\n            if (parX != parY) {\n                if (rank[parX] > rank[parY]) {\n                    par[parY] = parX;\n                    rank[parX] += rank[parY];\n                } else {\n                    par[parX] = parY;\n                    rank[parY] += rank[parX];\n                }\n            }\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.IOException;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        private static final int MOD = (int) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n\n            int[] primes = getPrimes(40_000);\n\n            int[][] a = new int[n][];\n            for (int i = 0; i < n; ++i) {\n                int x = in.nextInt();\n                IntList divs = new IntList();\n                for (int j : primes) {\n                    if (j * j > x) {\n                        break;\n                    }\n                    int cnt = 0;\n                    while (x % j == 0) {\n                        cnt++;\n                        x /= j;\n                    }\n                    if (cnt % 2 == 1) {\n                        divs.add(j);\n                    }\n                }\n                if (x > 1) {\n                    divs.add(x);\n                }\n                a[i] = divs.toArray();\n            }\n            Comparator<int[]> cmp = ((o1, o2) -> {\n                for (int i = 0; i < o1.length && i < o2.length; ++i) {\n                    if (o1[i] < o2[i]) {\n                        return -1;\n                    } else if (o2[i] < o1[i]) {\n                        return 1;\n                    }\n                }\n                return Integer.compare(o1.length, o2.length);\n            });\n            Arrays.sort(a, cmp);\n            IntList freqsList = new IntList();\n            int cnt = 1;\n            for (int i = 1; i < n; ++i) {\n                if (cmp.compare(a[i], a[i - 1]) == 0) {\n                    cnt++;\n                } else {\n                    freqsList.add(cnt);\n                    cnt = 1;\n                }\n            }\n            freqsList.add(cnt);\n            int[][] comb = new int[2 * n + 1][2 * n + 1];\n            for (int i = 0; i < comb.length; ++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]) % MOD;\n                }\n            }\n            int[] dp = new int[n];\n            int[] ndp = new int[n];\n            dp[0] = 1;\n            int total = 0;\n            int ans = 1;\n            for (int x : freqsList.toArray()) {\n                Arrays.fill(ndp, 0);\n                for (int bad = 0; bad < n; ++bad) {\n                    if (dp[bad] == 0) {\n                        continue;\n                    }\n                    for (int putSeparately = 1; putSeparately <= x; ++putSeparately) {\n                        for (int breakEq = 0; breakEq <= putSeparately; ++breakEq) {\n                            int nState = bad + x - putSeparately - breakEq;\n                            if (nState < 0 || nState >= n) {\n                                continue;\n                            }\n                            int rem = total + 1 - bad;\n                            int notBreak = putSeparately - breakEq;\n                            if (breakEq > bad || notBreak > rem) {\n                                continue;\n                            }\n                            int add = (int) ((long) comb[bad][breakEq] * comb[rem][notBreak] % MOD *\n                                    comb[x - 1][putSeparately - 1] % MOD * dp[bad] % MOD);\n                            ndp[nState] += add;\n                            ndp[nState] %= MOD;\n                        }\n                    }\n                }\n                total += x;\n                int[] aux = dp;\n                dp = ndp;\n                ndp = aux;\n                ans = (int) ((long) ans * fact(x) % MOD);\n            }\n            ans = (int) ((long) ans * dp[0] % MOD);\n            out.println(ans);\n        }\n\n        private int fact(int n) {\n            int res = 1;\n            for (int i = 2; i <= n; ++i) {\n                res = (int) ((long) res * i % MOD);\n            }\n            return res;\n        }\n\n        private int[] getPrimes(int n) {\n            boolean[] isPrime = new boolean[n + 1];\n            Arrays.fill(isPrime, 2, isPrime.length, true);\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            }\n            IntList primes = new IntList();\n            for (int i = 2; i <= n; ++i) {\n                if (isPrime[i]) {\n                    primes.add(i);\n                }\n            }\n            return primes.toArray();\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    static interface IntIterator extends Iterator<Integer> {\n    }\n\n    static class IntList implements Iterable<Integer> {\n        int[] elem;\n        int size;\n\n        public IntList() {\n            this(0, 0, 1);\n        }\n\n        public IntList(int size) {\n            this(size, 0, Math.max(1, size));\n        }\n\n        public IntList(int size, int value) {\n            this(size, value, Math.max(1, size));\n        }\n\n        public IntList(int size, int value, int capacity) {\n            elem = new int[capacity];\n            Arrays.fill(elem, 0, size, value);\n            this.size = size;\n        }\n\n        private IntList(int... e) {\n            elem = e.clone();\n            size = e.length;\n        }\n\n        public void add(int e) {\n            if (size + 1 > elem.length) {\n                increaseCapacity();\n            }\n            elem[size++] = e;\n        }\n\n        private void increaseCapacity() {\n            changeCapacity(3 * elem.length / 2 + 1);\n        }\n\n        private void changeCapacity(int newCapacity) {\n            int[] nElem = new int[newCapacity];\n            System.arraycopy(elem, 0, nElem, 0, Math.min(elem.length, newCapacity));\n            elem = nElem;\n        }\n\n        public IntIterator iterator() {\n            return new IntIterator() {\n                int pos = 0;\n\n\n                public Integer next() {\n                    return IntList.this.elem[pos++];\n                }\n\n\n                public boolean hasNext() {\n                    return pos < IntList.this.size;\n                }\n\n\n                public int nextInt() {\n                    return IntList.this.elem[pos++];\n                }\n            };\n        }\n\n        public int[] toArray() {\n            return Arrays.copyOf(elem, size);\n        }\n\n        public int hashCode() {\n            int hashCode = 0;\n            for (int i = 0; i < size; ++i) {\n                hashCode = 31 * hashCode + elem[i];\n            }\n            return hashCode;\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\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    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 int MOD = (int) (1e9 + 7);\n        long[][] C;\n        long[] fact;\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            precalc(n);\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.nextInt();\n                a[i] = removeSquares(a[i]);\n            }\n            int[] g = getGroupSizes(a);\n            long ans = solve(g);\n            for (int x : g) {\n                ans = ans * fact[x] % MOD;\n            }\n            out.println(ans);\n        }\n\n        private long solve(int[] a) {\n            // For a description, see http://petr-mitrichev.blogspot.com/2017/07/a-week7.html\n            long[] d = new long[1];\n            d[0] = 1;\n            int totalPositions = 1;\n            for (int x : a) {\n                long[] nd = new long[d.length + x + 1];\n                for (int s = 0; s < d.length; s++) {\n                    if (d[s] == 0) {\n                        continue;\n                    }\n                    for (int m = 1; m <= x; m++) {\n                        for (int p = 0; p <= s && p <= m; p++) {\n                            long cur = d[s];\n                            cur = cur * C[s][p] % MOD;\n                            cur = cur * C[totalPositions - s][m - p] % MOD;\n                            cur = cur * f(x, m) % MOD;\n                            int ns = s + x - m - p;\n                            if (ns >= 0 && ns < nd.length) {\n                                nd[ns] += cur;\n                                if (nd[ns] >= MOD) {\n                                    nd[ns] -= MOD;\n                                }\n                            }\n                        }\n                    }\n                }\n                if (totalPositions == 1) {\n                    totalPositions = x + 1;\n                } else {\n                    totalPositions += x;\n                }\n                d = nd;\n            }\n            return d[0];\n        }\n\n        private long f(int n, int k) {\n            if (n < k) {\n                return 0;\n            }\n            n -= k;\n            return C[n + k - 1][k - 1];\n        }\n\n        private void precalc(int n) {\n            fact = new long[n + 1];\n            fact[0] = 1;\n            for (int i = 1; i < fact.length; i++) {\n                fact[i] = i * fact[i - 1] % MOD;\n            }\n\n            C = new long[1000][1000];\n            C[0][0] = 1;\n            for (int i = 1; i < C.length; i++) {\n                C[i][0] = 1;\n                for (int j = 1; j < C.length; 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        }\n\n        private int[] getGroupSizes(int[] a) {\n            Arrays.sort(a);\n            List<Integer> res = new ArrayList<>();\n            for (int i = 0; i < a.length; ) {\n                int j = i;\n                while (j < a.length && a[i] == a[j]) {\n                    ++j;\n                }\n                res.add(j - i);\n                i = j;\n            }\n            int[] r = new int[res.size()];\n            for (int i = 0; i < r.length; i++) {\n                r[i] = res.get(i);\n            }\n            return r;\n        }\n\n        private int removeSquares(int n) {\n            int res = 1;\n            for (int d = 2; d * d <= n; d++) {\n                if (n % d == 0) {\n                    int cur = 0;\n                    while (n % d == 0) {\n                        n /= d;\n                        ++cur;\n                    }\n                    if (cur % 2 == 1) {\n                        res *= d;\n                    }\n                }\n            }\n            if (n > 1) {\n                res *= n;\n            }\n            return res;\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", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "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 MODULO = (int) (1e9 + 7);\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] = removeSquares(in.nextInt());\n            Arrays.sort(a);\n\n            int[][] c = new int[n + 1][n + 1];\n            c[0][0] = 1;\n            for (int i = 1; i < c.length; ++i) {\n                c[i][0] = 1;\n                for (int j = 1; j < c.length; ++j) {\n                    c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MODULO;\n                }\n            }\n\n            int[] fact = new int[n + 1];\n            fact[0] = 1;\n            for (int i = 1; i < fact.length; ++i) {\n                fact[i] = (int) (i * (long) fact[i - 1] % MODULO);\n            }\n\n            int i = 0;\n            int[] ways = new int[]{1};\n\n            while (i < n) {\n                int j = i;\n                while (j < n && a[j] == a[i]) ++j;\n\n                int m = j - i;\n\n                int[] nways = new int[j + 1];\n                for (int old = 0; old < ways.length; ++old) {\n                    long w = ways[old];\n                    for (int blocks = 1; blocks <= m; ++blocks) {\n                        for (int intoOld = 0; intoOld <= old && intoOld <= blocks; ++intoOld) {\n                            nways[old - intoOld + (m - blocks)] = (int) ((nways[old - intoOld + (m - blocks)] + w * c[old][intoOld] % MODULO * c[i + 1 - old][blocks - intoOld] % MODULO * c[m - 1][blocks - 1] % MODULO * fact[m] % MODULO) % MODULO);\n                        }\n                    }\n                }\n\n                i = j;\n                ways = nways;\n            }\n\n            out.println(ways[0]);\n        }\n\n        private int removeSquares(int x) {\n            for (int i = 2; i * i <= x; ++i) {\n                while (x % (i * i) == 0) {\n                    x /= i * i;\n                }\n            }\n            return 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    }\n}\n\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "//package round429;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint v = a[i];\n\t\t\tfor(int j = 2;j*j <= v;j++){\n\t\t\t\twhile(v % (j*j) == 0){\n\t\t\t\t\tv /= j*j;\n\t\t\t\t}\n\t\t\t}\n\t\t\ta[i] = v;\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\tint[] f = new int[n];\n\t\tint p = 0;\n\t\tfor(int i= 0;i < n;i++){\n\t\t\tif(i > 0 && a[i] != a[i-1]){\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tf[p]++;\n\t\t}\n\t\tf = Arrays.copyOf(f, p+1);\n\t\tint mod = 1000000007;\n\t\t\n\t\tint[][] fif = enumFIF(1000, mod);\n\t\tlong[] res = countSameNeighborsSequence(f, fif, mod);\n\t\tlong ans = res[0];\n\t\tfor(int v : f){\n\t\t\tans = ans * fif[0][v] % mod;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tpublic static long[] countSameNeighborsSequence(int[] a, int[][] fif, int mod)\n\t{\n\t\tint n = a.length;\n\t\t\n\t\tint bef = a[0];\n\t\tint aft = a[0];\n\t\tlong[] dp = new long[bef];\n\t\tdp[bef-1] = 1;\n\t\tfor(int u = 1;u < n;u++){\n\t\t\tint v = a[u];\n\t\t\taft += v;\n\t\t\tlong[][] ldp = new long[bef][aft];\n\t\t\tfor(int i = 0;i < dp.length;i++){\n\t\t\t\tldp[i][0] = dp[i];\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0;i < v;i++){\n\t\t\t\tlong[][] ndp = new long[bef][aft];\n\t\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\t\tif(ldp[j][k] == 0)continue;\n\t\t\t\t\t\t// XX -> XCX\n\t\t\t\t\t\tif(j > 0){\n\t\t\t\t\t\t\tndp[j-1][k] += ldp[j][k] * j;\n\t\t\t\t\t\t\tndp[j-1][k] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// CC -> CCC\n\t\t\t\t\t\tif(k > 0){\n\t\t\t\t\t\t\tndp[j][k+1] += ldp[j][k] * k;\n\t\t\t\t\t\t\tndp[j][k+1] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// XC -> XCC\n\t\t\t\t\t\t// #XC = 2*(i-k)\n\t\t\t\t\t\tif(2*(i-k) > 0){\n\t\t\t\t\t\t\tndp[j][k+1] += ldp[j][k] * (2*(i-k));\n\t\t\t\t\t\t\tndp[j][k+1] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// XY -> XCY\n\t\t\t\t\t\t// #XY = bef+i+1-#XC-#CC-#XX\n\t\t\t\t\t\tif(bef+i+1-j-k-2*(i-k) > 0){\n\t\t\t\t\t\t\tndp[j][k] += ldp[j][k] * (bef+i+1-j-k-2*(i-k));\n\t\t\t\t\t\t\tndp[j][k] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tldp = ndp;\n\t\t\t}\n\t\t\t\n\t\t\tdp = new long[aft];\n\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\tdp[j+k] += ldp[j][k];\n\t\t\t\t\tif(dp[j+k] >= mod)dp[j+k] -= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < aft;j++)dp[j] = dp[j] * fif[1][v] % mod;\n\t\t\tbef = aft;\n\t\t}\n\t\treturn dp;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new C2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.concurrent.*;\n\npublic final class on_the_bench\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 int[] parent,size;\n\tstatic int maxn=(int)500;\n\tstatic long mod=(long)(1e9+7);\n\tstatic int[] fact,inv_fact;\n\t\n\tstatic int getParent(int u)\n\t{\n\t\tif(u==parent[u])\n\t\t{\n\t\t\treturn u;\n\t\t}\n\t\t\n\t\telse\n\t\t{\n\t\t\tint val=getParent(parent[u]);parent[u]=val;\n\t\t\t\n\t\t\treturn val;\n\t\t}\n\t}\n\t\n\tstatic void merge(int u,int v)\n\t{\n\t\tint x=getParent(u),y=getParent(v);\n\t\t\n\t\tif(x!=y)\n\t\t{\n\t\t\tparent[y]=x;\n\t\t\t\n\t\t\tsize[x]+=size[y];size[y]=0;\n\t\t}\n\t}\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 int 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=mul(x,y);\n\t\t\t}\n\t\t\t\n\t\t\ty=mul(y,y);b=b/2;\n\t\t}\n\t\t\n\t\treturn (int)(x%mod);\n\t}\n\t\n\tstatic void build()\n\t{\n\t\tfact=new int[maxn];inv_fact=new int[maxn];fact[0]=1;\n\n\t\tfor(int i=1;i<maxn;i++)\n\t\t{\n\t\t\tfact[i]=mul(fact[i-1],i);\n\t\t}\n\n\t\tinv_fact[maxn-1]=pow(fact[maxn-1],mod-2);\n\n\t\tfor(int i=maxn-2;i>=0;i--)\n\t\t{\n\t\t\tinv_fact[i]=mul(inv_fact[i+1],(i+1));\n\t\t}\n\t}\n\t\n\tstatic int[] mul_poly(int[] a,int[] b,int deg1,int deg2)\n\t{\t\n\t\tint[] ret=new int[deg1+deg2+1];\n\t\t\n\t\tfor(int i=0;i<=deg1;i++)\n\t\t{\n\t\t\tfor(int j=0;j<=deg2;j++)\n\t\t\t{\n\t\t\t\tint curr=mul(a[i],b[j]);\n\t\t\t\t\n\t\t\t\tret[i+j]=add(ret[i+j],curr);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn ret;\n\t}\n\t\n\tstatic int 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\tint val1=fact[n],val2=inv_fact[r],val3=inv_fact[n-r];\n\t\t\n\t\tint mul=mul(val2,val3);\n\t\t\n\t\treturn mul(val1,mul);\n\t}\n\t\n    public static void main(String args[]) throws Exception\n    {\n\t\tint n=sc.nextInt();build();\n\t\t\n\t\tint[] a=new int[n];parent=new int[n];size=new int[n];\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\ta[i]=sc.nextInt();\n\t\t\t\n\t\t\tparent[i]=i;\n\t\t\t\n\t\t\tsize[i]=1;\n\t\t}\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int j=i+1;j<n;j++)\n\t\t\t{\n\t\t\t\tlong curr=a[i]*1L*a[j],now=(long)Math.sqrt(curr);\n\t\t\t\t\n\t\t\t\tif(now*now==curr)\n\t\t\t\t{\n\t\t\t\t\tmerge(i,j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tList<Integer> list=new ArrayList<>();\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tif(getParent(i)==i)\n\t\t\t{\n\t\t\t\tlist.add(size[i]);\n\t\t\t}\n\t\t}\n\t\t\n\t//\tout.println(list);\n\t\t\n\t\tint res=0;int[] poly=new int[1];poly[0]=1;\n\t\t\n\t\tfor(int i=0;i<list.size();i++)\n\t\t{\n\t\t\tint size=list.get(i);\n\t\t\t\n\t\t\tint[] arr=new int[size];arr[0]=1;\n\t\t\t\n\t\t\tfor(int j=1;j<size;j++)\n\t\t\t{\n\t\t\t\tint now1=C(size,j),now2=mul(fact[size-1],inv_fact[size-1-j]);\n\t\t\t\t\n\t\t\t\tint qq=mul(now1,now2);\n\t\t\t\t\n\t\t\t\tarr[j]=qq;\n\t\t\t}\n\t\t\t\n\t\t\tpoly=mul_poly(poly,arr,poly.length-1,size-1);\n\t\t}\n\t\t\n\t\tfor(int i=1,x=1;i<poly.length;i++,x*=-1)\n\t\t{\n\t\t\tint now=add(x,mod);\n\t\t\t\n\t\t\tint curr=mul(fact[n-i],poly[i]);\n\t\t\t\n\t\t\tcurr=mul(curr,now);\n\t\t\t\n\t\t\tres=add(res,curr);\n\t\t}\n\t\t\n\t//\tout.println(res);\n\t\t\n\t\tint zz=mul(res,mod-1);res=add(fact[n],zz);\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}", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n/*\n\n2\n3 5\n\n2\n6 5\n1 11\n-10 12\n\n3\n3 6 2\n\n\n1   8   5   3\n-7  9   5   3\n-7  4   14  3\n\n\n1   8   5   3\n1   3   13  3\n-2  4   13  3\n   \n\n3\n1 3 6\n\n3 3 6\n\n5 12\n-7 19\n\n\n3 5 7 11 13\n-2 8\n\n\n5 9\n\n\n5 9\n\n\n3 6 7\n-3 9 7\n\n6 3 7\n\n\n*/\n\npublic class c {\n\tstatic int n;\n\tstatic int[] fs;\n\tstatic int[] cfs;\n\tstatic long[][] choose = chooseTable(1001);\n\tstatic long[] fact;\n\tstatic final long MOD = (long) (1e9 + 7);\n\tstatic long[][] memo;\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tn = in.nextInt();\n\t\tfact = new long[301];\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i < fact.length; i++) {\n\t\t\tfact[i] = fact[i - 1] * i;\n\t\t\tfact[i] %= MOD;\n\t\t}\n\t\tHashMap<Long, Integer> map = new HashMap<Long, Integer>();\n\t\tfs = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong v = in.nextLong();\n\t\t\tlong r = 1;\n\t\t\tfor (int d = 2; d * d <= v; d++) {\n\t\t\t\tint cnt = 0;\n\t\t\t\twhile (v % d == 0) {\n\t\t\t\t\tv /= d;\n\t\t\t\t\tcnt ^= 1;\n\t\t\t\t}\n\t\t\t\tif (cnt == 1) {\n\t\t\t\t\tr *= d;\n\t\t\t\t}\n\t\t\t}\n\t\t\tr *= v;\n\t\t\tif (!map.containsKey(r)) {\n\t\t\t\tmap.put(r, map.size());\n\t\t\t}\n\t\t\tfs[map.get(r)]++;\n\t\t}\n\t\tcfs = new int[n];\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tcfs[i] = cfs[i - 1] + fs[i - 1];\n\t\t}\n\t\tmemo = new long[n+1][n+1];\n\t\tfor(long[] arr : memo)\n\t\t\tArrays.fill(arr, -1);\n\t\tSystem.out.println(go(0, 0));\n\t}\n\n\tstatic long go(int color, int priorities) {\n\t\tif (color == n)\n\t\t\treturn priorities == 0 ? 1 : 0;\n//\t\tSystem.out.println(color + \" \"+  priorities);\n\t\tif(memo[color][priorities] != -1)\n\t\t\treturn memo[color][priorities];\n\t\tint nonpriorities = cfs[color] - priorities + 1;\n\t\tlong ans = 0;\n\t\tfor (int cntPrio = 0; cntPrio <= priorities && cntPrio <= fs[color]; cntPrio++) {\n\t\t\tfor (int cntNonPrio = 0; cntNonPrio <= nonpriorities && cntNonPrio + cntPrio <= fs[color]; cntNonPrio++) {\n\t\t\t\tif(cntPrio + cntNonPrio == 0 && fs[color] != 0) continue;\n\t\t\t\tint cntExtra = fs[color] - cntPrio - cntNonPrio;\n\t\t\t\tlong tmp = choose(priorities, cntPrio);\n\t\t\t\ttmp *= choose(nonpriorities, cntNonPrio);\n\t\t\t\ttmp %= MOD;\n\t\t\t\ttmp *= multichoose(cntPrio + cntNonPrio, cntExtra);\n\t\t\t\ttmp %= MOD;\n\t\t\t\ttmp *= go(color + 1, priorities - cntPrio + cntExtra);\n\t\t\t\ttmp %= MOD;\n\t\t\t\ttmp *= fact[fs[color]];\n\t\t\t\ttmp %= MOD;\n\t\t\t\t\n\t\t\t\tans += tmp;\n\t\t\t\tans %= MOD;\n\t\t\t}\n\t\t}\n\t\treturn memo[color][priorities] = ans;\n\t}\n\n\tstatic long[][] chooseTable(int n) {\n\t\tlong[][] table = new long[n][];\n\t\tfor (int x = 0; x < n; x++) {\n\t\t\ttable[x] = new long[x + 1];\n\t\t\ttable[x][0] = table[x][x] = 1;\n\t\t\tfor (int y = 1; y < x; y++) {\n\t\t\t\ttable[x][y] = table[x - 1][y - 1] + table[x - 1][y];\n\t\t\t\ttable[x][y] %= MOD;\n\t\t\t}\n\t\t}\n\t\treturn table;\n\t}\n\n\tstatic long choose(int n, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tif (k >= choose[n].length) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn choose[n][k];\n\t}\n\n\tstatic long multichoose(int n, int k) {\n\t\treturn choose(n + k - 1, k);\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream i) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(i));\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 double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "//package round429;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint v = a[i];\n\t\t\tfor(int j = 2;j*j <= v;j++){\n\t\t\t\twhile(v % (j*j) == 0){\n\t\t\t\t\tv /= j*j;\n\t\t\t\t}\n\t\t\t}\n\t\t\ta[i] = v;\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\tint[] f = new int[n];\n\t\tint p = 0;\n\t\tfor(int i= 0;i < n;i++){\n\t\t\tif(i > 0 && a[i] != a[i-1]){\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tf[p]++;\n\t\t}\n\t\tf = Arrays.copyOf(f, p+1);\n\t\tint mod = 1000000007;\n\t\t\n\t\tint[][] fif = enumFIF(1000, mod);\n\t\tlong[] res = countSameNeighborsSequence(f, fif, mod);\n\t\tlong ans = res[0];\n\t\tfor(int v : f){\n\t\t\tans = ans * fif[0][v] % mod;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tpublic static long[] countSameNeighborsSequence(int[] a, int[][] fif, int mod)\n\t{\n\t\tint n = a.length;\n\t\t\n\t\tint bef = a[0];\n\t\tint aft = a[0];\n\t\tlong[] dp = new long[bef];\n\t\tdp[bef-1] = 1;\n\t\tfor(int u = 1;u < n;u++){\n\t\t\tint v = a[u];\n\t\t\taft += v;\n\t\t\tlong[][] ldp = new long[bef][aft];\n\t\t\tfor(int i = 0;i < dp.length;i++){\n\t\t\t\tldp[i][0] = dp[i];\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0;i < v;i++){\n\t\t\t\tlong[][] ndp = new long[bef][aft];\n\t\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\t\tif(ldp[j][k] == 0)continue;\n\t\t\t\t\t\t// XX -> XCX\n\t\t\t\t\t\tif(j > 0){\n\t\t\t\t\t\t\tndp[j-1][k] += ldp[j][k] * j;\n\t\t\t\t\t\t\tndp[j-1][k] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// CC -> CCC\n\t\t\t\t\t\t// XC -> XCC\n\t\t\t\t\t\t// #XC = 2*(i-k)\n\t\t\t\t\t\tndp[j][k+1] += ldp[j][k] * (2*i-k);\n\t\t\t\t\t\tndp[j][k+1] %= mod;\n\t\t\t\t\t\t\n\t\t\t\t\t\t// XY -> XCY\n\t\t\t\t\t\t// #XY = bef+i+1-#XC-#CC-#XX\n\t\t\t\t\t\tndp[j][k] += ldp[j][k] * (bef+i+1-j-k-2*(i-k));\n\t\t\t\t\t\tndp[j][k] %= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tldp = ndp;\n\t\t\t}\n\t\t\t\n\t\t\tdp = new long[aft];\n\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\tdp[j+k] += ldp[j][k];\n\t\t\t\t\tif(dp[j+k] >= mod)dp[j+k] -= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < aft;j++)dp[j] = dp[j] * fif[1][v] % mod;\n\t\t\tbef = aft;\n\t\t}\n\t\treturn dp;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new C2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "//package round429;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint v = a[i];\n\t\t\tfor(int j = 2;j*j <= v;j++){\n\t\t\t\twhile(v % (j*j) == 0){\n\t\t\t\t\tv /= j*j;\n\t\t\t\t}\n\t\t\t}\n\t\t\ta[i] = v;\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\tint[] f = new int[n];\n\t\tint p = 0;\n\t\tfor(int i= 0;i < n;i++){\n\t\t\tif(i > 0 && a[i] != a[i-1]){\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tf[p]++;\n\t\t}\n\t\tf = Arrays.copyOf(f, p+1);\n\t\tint mod = 1000000007;\n\t\t\n\t\tint[][] fif = enumFIF(1000, mod);\n\t\tlong[] res = countSameNeighborsSequence(f, fif, mod);\n\t\tlong ans = res[0];\n\t\tfor(int v : f){\n\t\t\tans = ans * fif[0][v] % mod;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tpublic static long[] countSameNeighborsSequence(int[] a, int[][] fif, int mod)\n\t{\n\t\tint n = a.length;\n\t\t\n\t\tint bef = a[0];\n\t\tint aft = a[0];\n\t\tlong[] dp = new long[bef];\n\t\tdp[bef-1] = 1;\n\t\tfor(int u = 1;u < n;u++){\n\t\t\tint v = a[u];\n\t\t\taft += v;\n\t\t\tlong[][] ldp = new long[bef][aft];\n\t\t\tfor(int i = 0;i < dp.length;i++){\n\t\t\t\tldp[i][0] = dp[i];\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0;i < v;i++){\n\t\t\t\tlong[][] ndp = new long[bef][aft];\n\t\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\t\tif(ldp[j][k] == 0)continue;\n\t\t\t\t\t\t// XX -> XCX\n\t\t\t\t\t\tif(j > 0){\n\t\t\t\t\t\t\tndp[j-1][k] += ldp[j][k] * j;\n\t\t\t\t\t\t\tndp[j-1][k] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// CC -> CCC\n\t\t\t\t\t\t// XC -> XCC\n\t\t\t\t\t\t// #XC = 2*(i-k)\n\t\t\t\t\t\tndp[j][k+1] += ldp[j][k] * (2*i-k);\n\t\t\t\t\t\tndp[j][k+1] %= mod;\n\t\t\t\t\t\t\n\t\t\t\t\t\t// XY -> XCY\n\t\t\t\t\t\t// #XY = bef+i+1-#XC-#CC-#XX\n\t\t\t\t\t\tndp[j][k] += ldp[j][k] * (bef+i+1-j-k-2*(i-k));\n\t\t\t\t\t\tndp[j][k] %= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tldp = ndp;\n\t\t\t}\n\t\t\t\n\t\t\tdp = new long[aft];\n\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\tdp[j+k] += ldp[j][k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < aft;j++)dp[j] = dp[j] % mod * fif[1][v] % mod;\n\t\t\tbef = aft;\n\t\t}\n\t\treturn dp;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new C2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "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 long[] fac, faci;\n\t\n\tpublic static void main(String[] args) {\n\t\tint n=in.nextInt();\n\t\tfac = new long[n+1];\n\t\tfaci = new long[n+1];\n\t\tfac[0]=faci[0]=1;\n\t\tfor(int i=1; i<=n; ++i)\n\t\t\tfaci[i]=modI(fac[i]=fac[i-1]*i%M, M);\n\t\tList<List<Integer>> grps = new ArrayList<List<Integer>>();\n\t\tfor(int i=0; i<n; ++i) {\n\t\t\tint ai=in.nextInt();\n\t\t\tfor(int j=0; ; ++j) {\n\t\t\t\tif(j>=grps.size())\n\t\t\t\t\tgrps.add(new ArrayList<Integer>());\n\t\t\t\tif(grps.get(j).size()>0&&!ps((long)grps.get(j).get(0)*ai))\n\t\t\t\t\tcontinue;\n\t\t\t\tgrps.get(j).add(ai);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tlong[][] dp = new long[grps.size()][n-grps.size()+1];\n\t\tdp[0][grps.get(0).size()-1]=fac[grps.get(0).size()];\n\t\tint ad=grps.get(0).size();\n\t\tfor(int i=1; i<grps.size(); ++i) {\n\t\t\tfor(int j=0; j<dp[i-1].length; ++j) {\n\t\t\t\tif(dp[i-1][j]==0)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(int k=0; k<grps.get(i).size(); ++k)\n\t\t\t\t\tfor(int l=Math.max(grps.get(i).size()+j-k-ad-1, 0); l<=Math.min(grps.get(i).size()-k, j); ++l)\n\t\t\t\t\t\tdp[i][j+k-l]=(fac[grps.get(i).size()]*nck(j, l)%M*nck(ad+1-j, grps.get(i).size()-k-l)%M*nck(grps.get(i).size()-1, k)%M*dp[i-1][j]+dp[i][j+k-l])%M;\n\t\t\t}\n\t\t\tad+=grps.get(i).size();\n\t\t}\n\t\t//out.println(Arrays.deepToString(dp));\n\t\tout.println(dp[grps.size()-1][0]);\n\t\tout.close();\n\t}\n\t\n\tstatic long modI(long a, long m) {\n\t\treturn (a%=m)<=1?1:((1-modI(m%a, a)*m)/a+m)%m;\n\t}\n\t\n\tstatic long nck(int n, int k) {\n\t\treturn fac[n]*faci[k]%M*faci[n-k]%M;\n\t}\n\t\n\tstatic boolean ps(long x) {\n\t\tlong lb=1, rb=M;\n\t\twhile(lb<=rb) {\n\t\t\tlong mb=(lb+rb)/2;\n\t\t\tif(mb*mb==x)\n\t\t\t\treturn true;\n\t\t\tif(mb*mb<x)\n\t\t\t\tlb=mb+1;\n\t\t\telse\n\t\t\t\trb=mb-1;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tstatic class StdIn {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n, int os) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt()+os;\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n, long os) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong()+os;\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "840_C. On the Bench", "from": "CODEFORCES"}
{"src": "// Author : RegalBeast\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n  static final FastReader FR = new FastReader();\n  static final PrintWriter PW = new PrintWriter(new OutputStreamWriter(System.out));\n\n  public static void main(String[] args) {\n    StringBuilder solution = new StringBuilder();\n    int rows = FR.nextInt();\n    int cols = FR.nextInt();\n    int moves = FR.nextInt();\n\n    Map<Integer, Integer> horizontalEdgeWeights = new HashMap<Integer, Integer>();\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols - 1; c++) {\n        int hash = getHash(r, c);\n        horizontalEdgeWeights.put(hash, FR.nextInt());\n      }\n    }\n\n    Map<Integer, Integer> verticalEdgeWeights = new HashMap<Integer, Integer>();\n    for (int r = 0; r < rows - 1; r++) {\n      for (int c = 0; c < cols; c++) {\n        int hash = getHash(r, c);\n        verticalEdgeWeights.put(hash, FR.nextInt());\n      }\n    }\n    \n    List<List<Integer>> result = getResult(rows, cols, moves, horizontalEdgeWeights, verticalEdgeWeights);\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols; c++) {\n        int value = (result != null ? result.get(r).get(c) : -1);\n        solution.append(value + \" \");\n      }\n      solution.append(\"\\n\");\n    }\n\n\t\tPW.print(solution.toString());\n    PW.close();\n  }\n\n  static List<List<Integer>> getResult(int rows, int cols, int moves, Map<Integer, Integer> horizontalEdgeWeights, Map<Integer, Integer> verticalEdgeWeights) {\n    if ((moves & 1) == 1) {\n      return null;\n    }\n\n    int mid = moves >> 1;\n    List<List<List<Integer>>> minForDistance = new ArrayList<List<List<Integer>>>(rows);\n    for (int r = 0; r < rows; r++) {\n      minForDistance.add(new ArrayList<List<Integer>>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        minForDistance.get(r).add(new ArrayList<Integer>(Collections.nCopies(mid+1, Integer.MAX_VALUE)));\n        minForDistance.get(r).get(c).set(0, 0);\n      }\n    }\n\n    for (int m = 1; m <= mid; m++) {\n      for (int r = 0; r < rows; r++) {\n        for (int c = 0; c < cols; c++) {\n          int minBoredom = minForDistance.get(r).get(c).get(m);\n          int hash = getHash(r, c);\n\n          if (r > 0) {\n            if (minForDistance.get(r-1).get(c).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r-1).get(c).get(m-1) + verticalEdgeWeights.get(getHash(r-1, c));\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n\n          if (c > 0) {\n            if (minForDistance.get(r).get(c-1).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r).get(c-1).get(m-1) + horizontalEdgeWeights.get(getHash(r, c-1));\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n          \n          if (r + 1 < rows) {\n            if (minForDistance.get(r+1).get(c).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r+1).get(c).get(m-1) + verticalEdgeWeights.get(hash);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n   \n          if (c + 1 < cols) {\n            if (minForDistance.get(r).get(c+1).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r).get(c+1).get(m-1) + horizontalEdgeWeights.get(hash);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n\n          minForDistance.get(r).get(c).set(m, minBoredom);\n        }\n      }\n    }\n\n    List<List<Integer>> result = new ArrayList<List<Integer>>(rows);\n    for (int r = 0; r < rows; r++) {\n      result.add(new ArrayList<Integer>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        result.get(r).add(minForDistance.get(r).get(c).get(mid) << 1);\n      }\n    }\n\n    return result;\n  }\n\n  static int getHash(int row, int col) {\n    return (row * 1000 + col);\n  }\n  static int getRow(int hash) {\n    return hash / 1000;\n  }\n  static int getCol(int hash) {\n    return hash % 1000;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\nimport static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.in;\nimport static java.lang.System.out;\n\npublic class SolutionD extends Thread {\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() {\n            br = new BufferedReader(new\n                                            InputStreamReader(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 parseInt(next());\n        }\n\n        long nextLong() {\n            return parseLong(next());\n        }\n\n        double nextDouble() {\n            return 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        solve();\n        out.close();\n    }\n\n    private static void solve() {\n        int n = scanner.nextInt();\n        int m = scanner.nextInt();\n        int k = scanner.nextInt();\n\n        int[][] hori = new int[n][m-1];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m-1; j++) {\n                int xij = scanner.nextInt();\n                hori[i][j] = xij;\n            }\n        }\n\n        int[][] vert = new int[n-1][m];\n        for (int i = 0; i < n-1; i++) {\n            for (int j = 0; j < m; j++) {\n                int xij = scanner.nextInt();\n                vert[i][j] = xij;\n            }\n        }\n\n        if (k % 2 != 0) {\n            for (int i = 0; i < n; i++) {\n                StringBuilder s = new StringBuilder();\n                for (int j = 0; j < m; j++) {\n                    s.append(\"-1 \");\n                }\n                out.println(s);\n            }\n            return;\n        }\n\n        k /= 2;\n\n        long[][][] dp = new long[n][m][k+1];\n\n        for (int kTmp = 1; kTmp <= k; kTmp++) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    dp[i][j][kTmp] = Integer.MAX_VALUE;\n                    if (i > 0) {\n                        dp[i][j][kTmp] = Math.min(dp[i][j][kTmp], dp[i-1][j][kTmp-1] + 2L * vert[i - 1][j]);\n                    }\n                    if (j > 0) {\n                        dp[i][j][kTmp] = Math.min(dp[i][j][kTmp], dp[i][j-1][kTmp-1] + 2L * hori[i][j - 1]);\n                    }\n                    if (i + 1 < n) {\n                        dp[i][j][kTmp] = Math.min(dp[i][j][kTmp], dp[i+1][j][kTmp-1] + 2L * vert[i][j]);\n                    }\n                    if (j + 1 < m) {\n                        dp[i][j][kTmp] = Math.min(dp[i][j][kTmp], dp[i][j+1][kTmp-1] + 2L * hori[i][j]);\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            StringBuilder s = new StringBuilder();\n            for (int j = 0; j < m; j++) {\n                s.append(dp[i][j][k]).append(\" \");\n            }\n            out.println(s);\n        }\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class D {\n\tstatic byte[] buf = new byte[1<<26];\n    static int bp = -1;\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\t/**/\n\t\tDataInputStream in = new DataInputStream(System.in);\n\t\t/*/\n\t\tDataInputStream in = new DataInputStream(new FileInputStream(\"src/d.in\"));\n\t\t/**/\n\t\t\n\t\tin.read(buf, 0, 1<<26);\n\t\t\n\t\tint n = nni();\n\t\tint m = nni();\n\t\tint k = nni();\n\t\t\n\t\tif (k%2==1) {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tStringBuilder ans = new StringBuilder();\n\t\t\t\tString sp = \"\";\n\t\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\t\tans.append(sp+\"-1\");\n\t\t\t\t\tsp = \" \";\n\t\t\t\t}\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint[][] lr = new int[n][m-1];\n\t\tint[][] ud = new int[n-1][m];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int j = 0; j < m-1; ++j) {\n\t\t\t\tlr[i][j] = nni();\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n-1; ++i) {\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tud[i][j] = nni();\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][][] ans = new int[k/2+1][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\tfor (int q = 1; q <= k/2; ++q) {\n\t\t\t\t\tans[q][i][j] = 123456789;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int uq = 0; uq < k/2; ++uq) {\n\t\t\tfor (int ui = 0; ui < n; ++ui) {\n\t\t\t\tfor (int uj = 0; uj < m; ++uj) {\n\t\t\t\t\tint w = ans[uq][ui][uj];\n\t\t\t\t\tif (ui>0 && w+ud[ui-1][uj]<ans[uq+1][ui-1][uj]) {\n\t\t\t\t\t\tans[uq+1][ui-1][uj] = w+ud[ui-1][uj];\n\t\t\t\t\t}\n\t\t\t\t\tif (ui<n-1 && w+ud[ui][uj]<ans[uq+1][ui+1][uj]) {\n\t\t\t\t\t\tans[uq+1][ui+1][uj] = w+ud[ui][uj];\n\t\t\t\t\t}\n\t\t\t\t\tif (uj>0 && w+lr[ui][uj-1]<ans[uq+1][ui][uj-1]) {\n\t\t\t\t\t\tans[uq+1][ui][uj-1] = w+lr[ui][uj-1];\n\t\t\t\t\t}\n\t\t\t\t\tif (uj<m-1 && w+lr[ui][uj]<ans[uq+1][ui][uj+1]) {\n\t\t\t\t\t\tans[uq+1][ui][uj+1] = w+lr[ui][uj];\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; ++i) {\n\t\t\tStringBuilder as = new StringBuilder();\n\t\t\tString sp = \"\";\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tas.append(sp+ans[k/2][i][j]*2);\n\t\t\t\tsp = \" \";\n\t\t\t}\n\t\t\tSystem.out.println(as);\n\t\t}\n\t}\n\t\n\tpublic static int nni() {\n        int ret = 0;\n        byte b = buf[++bp];\n        while (true) {\n            ret = ret*10+b-'0';\n            b = buf[++bp];\n            if (b<'0'||b>'9') {\n            \twhile (buf[bp+1]=='\\r'||buf[bp+1]=='\\n'||buf[bp+1]==' ') {++bp;}\n            \tbreak;\n            }\n        }\n        return ret;\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class D\n{\n\n\tstatic FastIO f;\n\tstatic long ve[][], he[][];\n\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tf = new FastIO();\n\n\t\tint n = f.ni(), m = f.ni(), k = f.ni(), i, j;\n\t\tve = new long[n-1][];\n\t\the = new long[n][];\n\n\t\tlong[][] ans = new long[n][m], pans = new long[n][m], temp;\n\n\t\tfor(i = 0; i < n; i++)\n\t\t\the[i] = f.nla(m-1);\n\n\t\tfor(i = 0; i < n-1; i++)\n\t\t\tve[i] = f.nla(m);\n\n\t\tif(k%2 == 1)\n\t\t{\n\t\t\tfor(i = 0; i < n; i++)\n\t\t\t\tArrays.fill(ans[i], -1L);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tk /= 2;\n\n\t\t\twhile(k-->0)\n\t\t\t{\n\t\t\t\tfor(i = 0; i < n; i++)\n\t\t\t\t{\n\t\t\t\t\tfor(j = 0; j < m; j++)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[i][j] = Integer.MAX_VALUE;\n\n\t\t\t\t\t\tif(i != 0)\n\t\t\t\t\t\t\tans[i][j] = Math.min(ans[i][j], pans[i-1][j] + 2*edge(i, j, i-1, j));\n\n\t\t\t\t\t\tif(i != n-1)\n\t\t\t\t\t\t\tans[i][j] = Math.min(ans[i][j], pans[i+1][j] + 2*edge(i, j, i+1, j));\n\n\t\t\t\t\t\tif(j != 0)\n\t\t\t\t\t\t\tans[i][j] = Math.min(ans[i][j], pans[i][j-1] + 2*edge(i, j, i, j-1));\n\n\t\t\t\t\t\tif(j != m-1)\n\t\t\t\t\t\t\tans[i][j] = Math.min(ans[i][j], pans[i][j+1] + 2*edge(i, j, i, j+1));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// f.err(k + \"\\n\");\n\t\t\t\t// errorprint(ans, n, m);\n\n\t\t\t\ttemp = pans;\n\t\t\t\tpans = ans;\n\t\t\t\tans = temp;\n\t\t\t}\n\n\t\t\ttemp = pans;\n\t\t\tpans = ans;\n\t\t\tans = temp;\n\t\t}\n\n\t\tfor(i = 0; i < n; i++)\n\t\t{\n\t\t\tfor(j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tf.out(ans[i][j] + \" \");\n\t\t\t}\n\n\t\t\tf.out(\"\\n\");\n\t\t}\n\n\t\tf.flush();\n\t}\n\n\tpublic static void errorprint(long[][] p, int n, int m) throws IOException\n\t{\n\t\tint i, j;\n\n\t\tfor(i = 0; i < n; i++)\n\t\t{\n\t\t\tfor(j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tf.err(p[i][j] + \" \");\n\t\t\t}\n\n\t\t\tf.err(\"\\n\");\n\t\t}\n\t\t\n\t\tf.err(\"\\n\");\n\t}\n\n\tpublic static long edge(int i, int j, int x, int y)\n\t{\n\t\tif(i == x)\n\t\t\treturn he[i][Math.min(j, y)];\n\t\telse\n\t\t\treturn ve[Math.min(i, x)][j];\n\t}\n\n\tpublic static class FastIO\n\t{\n\t\tBufferedReader br;\n\t\tBufferedWriter bw, be;\n\t\tStringTokenizer st;\n\n\t\tpublic FastIO()\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tbw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\tbe = new BufferedWriter(new OutputStreamWriter(System.err));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tprivate void read() throws IOException\n\t\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t}\n\n\t\tpublic String ns() throws IOException\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t\tread();\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int ni() throws IOException\n\t\t{\n\t\t\treturn Integer.parseInt(ns());\n\t\t}\n\n\t\tpublic long nl() throws IOException\n\t\t{\n\t\t\treturn Long.parseLong(ns());\n\t\t}\n\n\t\tpublic float nf() throws IOException\n\t\t{\n\t\t\treturn Float.parseFloat(ns());\n\t\t}\n\n\t\tpublic double nd() throws IOException\n\t\t{\n\t\t\treturn Double.parseDouble(ns());\n\t\t}\n\n\t\tpublic char nc() throws IOException\n\t\t{\n\t\t\treturn ns().charAt(0);\n\t\t}\n\n\t\tpublic int[] nia(int n) throws IOException\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\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nla(int n) throws IOException\n\t\t{\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\ta[i] = nl();\n\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[] nca() throws IOException\n\t\t{\n\t\t\treturn ns().toCharArray();\n\t\t}\n\n\t\tpublic void out(String s) throws IOException\n\t\t{\n\t\t\tbw.write(s);\n\t\t}\n\n\t\tpublic void flush() throws IOException\n\t\t{\n\t\t\tbw.flush();\n\t\t\tbe.flush();\n\t\t}\n\n\t\tpublic void err(String s) throws IOException\n\t\t{\n\t\t\tbe.write(s);\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class D {\n\tpublic static int dir[][]={{-1,0},{1,0},{0,-1},{0,1}};\n\tpublic static void main(String[] args) {\n//\t\tScanner sc=new Scanner(System.in);\n\t\tFastScanner sc = new FastScanner();\n\t\tFastOutput out = new FastOutput(System.out);\n\t\tint n=sc.nextInt();\n\t\tint m=sc.nextInt();\n\t\tint k=sc.nextInt();\n\t\tint ans[][][]=new int[n][m][11];\n\t\tint arr[][]=new int[n*m][4];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tfor(int j=0;j<m-1;j++){\n\t\t\t\tint x=sc.nextInt();\n\t\t\t\tarr[i*m+j][3]=x;\n\t\t\t\tarr[i*m+j+1][2]=x;\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<n-1;i++){\n\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\tint x=sc.nextInt();\n\t\t\t\tarr[i*m+j][1]=x;\n\t\t\t\tarr[(i+1)*m+j][0]=x;\n\t\t\t}\n\t\t}\n\t\tif(k%2==1){\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tStringBuilder sb=new StringBuilder(\"\");\n\t\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\t\tans[i][j][10]=-1;\n\t\t\t\t\tsb.append(ans[i][j][10]+\" \");\n\t\t\t\t}\n\t\t\t\tout.println(sb.toString());\n\t\t\t}\n\t\t}else{\n\t\t\t\n\t\t\tfor(int ceng=1;ceng<=k/2;ceng++){\n\t\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\t\t\tans[i][j][ceng]=Integer.MAX_VALUE/3;\n\t\t\t\t\t\tfor(int dr=0;dr<4;dr++){\n\t\t\t\t\t\t\tint nx=i+dir[dr][0];\n\t\t\t\t\t\t\tint ny=j+dir[dr][1];\n\t\t\t\t\t\t\tif(nx<n&&ny<m&&nx>=0&&ny>=0){\n\t\t\t\t\t\t\t\tans[i][j][ceng]=Math.min(ans[i][j][ceng], ans[nx][ny][ceng-1]+arr[i*m+j][dr]);\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 i=0;i<n;i++){\n\t\t\t\tStringBuilder sb=new StringBuilder(\"\");\n\t\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\t\tsb.append(ans[i][j][k/2]*2+\" \");\n\t\t\t\t}\n\t\t\t\tout.println(sb.toString());\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\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[] readIntArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong[] readLongArray(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\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\tstatic class FastOutput implements AutoCloseable, Closeable, Appendable {\n\t\tprivate static final int THRESHOLD = 1 << 13;\n\t\tprivate final Writer os;\n\t\tprivate StringBuilder cache = new StringBuilder(THRESHOLD * 2);\n\n\t\tpublic FastOutput append(CharSequence csq) {\n\t\t\tcache.append(csq);\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastOutput append(CharSequence csq, int start, int end) {\n\t\t\tcache.append(csq, start, end);\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate void afterWrite() {\n\t\t\tif (cache.length() < THRESHOLD) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tflush();\n\t\t}\n\n\t\tpublic FastOutput(Writer os) {\n\t\t\tthis.os = os;\n\t\t}\n\n\t\tpublic FastOutput(OutputStream os) {\n\t\t\tthis(new OutputStreamWriter(os));\n\t\t}\n\n\t\tpublic FastOutput append(char c) {\n\t\t\tcache.append(c);\n\t\t\tafterWrite();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastOutput append(int c) {\n\t\t\tcache.append(c);\n\t\t\tafterWrite();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastOutput append(String c) {\n\t\t\tcache.append(c);\n\t\t\tafterWrite();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastOutput println(String c) {\n\t\t\treturn append(c).println();\n\t\t}\n\n\t\tpublic FastOutput println() {\n\t\t\treturn append(System.lineSeparator());\n\t\t}\n\n\t\tpublic FastOutput flush() {\n\t\t\ttry {\n\t\t\t\tos.append(cache);\n\t\t\t\tos.flush();\n\t\t\t\tcache.setLength(0);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new UncheckedIOException(e);\n\t\t\t}\n\t\t\treturn this;\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\tthrow new UncheckedIOException(e);\n\t\t\t}\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn cache.toString();\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic final class Solution {\n\n\n    static PrintWriter out = new PrintWriter(System.out);\n    static FastReader in = new FastReader();\n    static long mod = (long) 1e9 + 7;\n    static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(1, 0), new Pair(0, -1), new Pair(0, 1)};\n\n    //6 3\n    //2 3 10 7 5 14\n    //1 6\n    //2 4\n    //3 5\n\n    public static void main(String[] args) {\n\n        int n = i();\n        int m = i();\n        int k = i();\n\n        int[][] a = new int[n][m - 1];\n        for (int i = 0; i < n; i++) {\n            a[i] = input(m - 1);\n        }\n\n        int[][] b = new int[n - 1][m];\n        for (int i = 0; i < n - 1; i++) {\n            b[i] = input(m);\n        }\n\n        if (k % 2 > 0) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.print(-1 + \" \");\n                }\n                out.println();\n            }\n            out.flush();\n            return;\n        }\n\n        int[][][] f = new int[n][m][k / 2 + 1];\n\n        for (int s = 1; s <= k / 2; s++) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    int ans = -1;\n\n                    if (j > 0) {\n                        ans = f[i][j - 1][s - 1] + a[i][j - 1];\n                    }\n                    if (i > 0) {\n                        int t = f[i - 1][j][s - 1] + b[i - 1][j];\n                        ans = ans == -1 ? t : Math.min(ans, t);\n                    }\n                    if (i < n - 1) {\n                        int t = f[i + 1][j][s - 1] + b[i][j];\n                        ans = ans == -1 ? t : Math.min(ans, t);\n                    }\n                    if (j < m - 1) {\n                        int t = f[i][j + 1][s - 1] + a[i][j];\n                        ans = ans == -1 ? t : Math.min(ans, t);\n                    }\n\n                    f[i][j][s] = ans;\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                out.print(f[i][j][k / 2] * 2 + \" \");\n            }\n            out.println();\n        }\n        out.flush();\n    }\n\n    static int sd(long i) {\n        int d = 0;\n        while (i > 0) {\n            d += i % 10;\n            i = i / 10;\n        }\n        return d;\n    }\n\n    static Set<Integer> getFactors(int x) {\n        Set<Integer> res = new HashSet<>();\n\n        if (x <= 3) {\n            res.add(x);\n        } else {\n            int t = x;\n            for (int f = 2; f <= x / 2; f++) {\n                if (t == 1) {\n                    break;\n                }\n                if (t % f == 0) {\n                    res.add(f);\n                    while (t % f == 0) {\n                        t = t / f;\n                    }\n                }\n            }\n\n            if (t > 1) {\n                res.add(t);\n            }\n        }\n        return res;\n    }\n\n\n    static int lower(long A[], long x) {\n        int l = -1, r = A.length;\n        while (r - l > 1) {\n            int m = (l + r) / 2;\n            if (A[m] >= x) {\n                r = m;\n            } else {\n                l = m;\n            }\n        }\n        return r;\n    }\n\n    static int upper(long A[], long x) {\n        int l = -1, r = A.length;\n        while (r - l > 1) {\n            int m = (l + r) / 2;\n            if (A[m] <= x) {\n                l = m;\n            } else {\n                r = m;\n            }\n        }\n        return l;\n    }\n\n    static void swap(int A[], int a, int b) {\n        int t = A[a];\n        A[a] = A[b];\n        A[b] = t;\n    }\n\n    static int lowerBound(int A[], int low, int high, int x) {\n        if (low > high) {\n            if (x >= A[high]) {\n                return A[high];\n            }\n        }\n\n        int mid = (low + high) / 2;\n\n        if (A[mid] == x) {\n            return A[mid];\n        }\n\n        if (mid > 0 && A[mid - 1] <= x && x < A[mid]) {\n            return A[mid - 1];\n        }\n\n        if (x < A[mid]) {\n            return lowerBound(A, low, mid - 1, x);\n        }\n\n        return lowerBound(A, mid + 1, high, x);\n    }\n\n\n    static long pow(long a, long b) {\n        long pow = 1;\n        long x = a;\n        while (b != 0) {\n            if ((b & 1) != 0) {\n                pow = (pow * x) % mod;\n            }\n            x = (x * x) % mod;\n            b /= 2;\n        }\n        return pow;\n    }\n\n    static boolean isPrime(long N) {\n        if (N <= 1) {\n            return false;\n        }\n        if (N <= 3) {\n            return true;\n        }\n        if (N % 2 == 0 || N % 3 == 0) {\n            return false;\n        }\n        for (int i = 5; i * i <= N; i = i + 6) {\n            if (N % i == 0 || N % (i + 2) == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    static void print(char A[]) {\n        for (char c : A) {\n            out.print(c);\n        }\n        out.println();\n    }\n\n    static void print(boolean A[]) {\n        for (boolean c : A) {\n            out.print(c + \" \");\n        }\n        out.println();\n    }\n\n    static void print(int A[]) {\n        for (int c : A) {\n            out.print(c + \" \");\n        }\n        out.println();\n    }\n\n    static void print(long A[]) {\n        for (long i : A) {\n            out.print(i + \" \");\n        }\n        out.println();\n\n    }\n\n    static void print(List<Integer> A) {\n        for (int a : A) {\n            out.print(a + \" \");\n        }\n    }\n\n    static int i() {\n        return in.nextInt();\n    }\n\n    static long l() {\n        return in.nextLong();\n    }\n\n    static String s() {\n        return in.nextLine();\n    }\n\n    static int[] input(int N) {\n        int A[] = new int[N];\n        for (int i = 0; i < N; i++) {\n            A[i] = in.nextInt();\n        }\n        return A;\n    }\n\n    static long[] inputLong(int N) {\n        long A[] = new long[N];\n        for (int i = 0; i < A.length; i++) {\n            A[i] = in.nextLong();\n        }\n        return A;\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 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\nclass SegmentTree {\n\n    long[] t;\n\n    public SegmentTree(int n) {\n        t = new long[n + n];\n        Arrays.fill(t, Long.MIN_VALUE);\n    }\n\n    public long get(int i) {\n        return t[i + t.length / 2];\n    }\n\n    public void add(int i, long value) {\n        i += t.length / 2;\n        t[i] = value;\n        for (; i > 1; i >>= 1) {\n            t[i >> 1] = Math.max(t[i], t[i ^ 1]);\n        }\n    }\n\n    // max[a, b]\n    public long max(int a, int b) {\n        long res = Long.MIN_VALUE;\n        for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {\n            if ((a & 1) != 0) {\n                res = Math.max(res, t[a]);\n            }\n            if ((b & 1) == 0) {\n                res = Math.max(res, t[b]);\n            }\n        }\n        return res;\n    }\n}\n\nclass Pair {\n\n    int i, j;\n\n    Pair(int i, int j) {\n        this.i = i;\n        this.j = j;\n    }\n}\n\nclass FastReader {\n\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastReader() {\n        br = new BufferedReader(new InputStreamReader(System.in));\n    }\n\n    String next() {\n        while (st == null || !st.hasMoreElements()) {\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() {\n        return Integer.parseInt(next());\n    }\n\n    long nextLong() {\n        return Long.parseLong(next());\n    }\n\n    double nextDouble() {\n        return Double.parseDouble(next());\n    }\n\n    String nextLine() {\n        String str = \"\";\n        try {\n            str = br.readLine();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n        return str;\n    }\n\n\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "//package round718;\n\nimport java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class D2 {\n\tInputStream is;\n\tFastWriter out;\n\tString INPUT = \"\";//2 5 9 9 9 9 9 8 8 8 8 5 6 7 8 9\";\n\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), K = ni();\n\t\tint[][] a = new int[2*n+1][2*m+1];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint[] u = na(m-1);\n\t\t\tfor(int j = 0;j < m-1;j++){\n\t\t\t\ta[2*i][2*j+1] = u[j];\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < n-1;i++){\n\t\t\tint[] u = na(m);\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\ta[2*i+1][2*j] = u[j];\n\t\t\t}\n\t\t}\n\t\tif(K % 2 == 1){\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\tout.print(-1 + \" \");\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tint[][][] dp = new int[K/2+1][n][m];\n\t\tint[] dr = {1, 0, -1, 0};\n\t\tint[] dc = {0, 1, 0, -1};\n\t\tfor(int i = 1;i <= K/2;i++){\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\tdp[i][j][k] = Integer.MAX_VALUE;\n\t\t\t\t\tfor(int l = 0;l < 4;l++){\n\t\t\t\t\t\tint jj = j + dr[l], kk = k + dc[l];\n\t\t\t\t\t\tif(jj >= 0 && jj < n && kk >= 0 && kk < m){\n\t\t\t\t\t\t\tdp[i][j][k] = Math.min(dp[i][j][k], dp[i-1][jj][kk] + a[j+jj][k+kk]);\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\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tout.print(dp[K/2][i][j] * 2 + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 500, m = 500;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(n + \" \");\n//\t\tsb.append(n + \" \");\n//\t\tsb.append(20 + \" \");\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tfor(int j = 0;j < m-1;j++) {\n//\t\t\t\tsb.append(gen.nextInt(200000) + \" \");\n//\t\t\t}\n//\t\t}\n//\t\tfor (int i = 0; i < n-1; i++) {\n//\t\t\tfor(int j = 0;j < m;j++) {\n//\t\t\t\tsb.append(gen.nextInt(200000) + \" \");\n//\t\t\t}\n//\t\t}\n//\t\tINPUT = sb.toString();\n\n\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new FastWriter(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\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 char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[][] nmi(int n, int m) {\n\t\tint[][] map = new int[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\n\t\treturn map;\n\t}\n\n\tprivate int ni() { return (int)nl(); }\n\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\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\tpublic static class FastWriter\n\t{\n\t\tprivate static final int BUF_SIZE = 1<<13;\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\n\t\tprivate final OutputStream out;\n\t\tprivate int ptr = 0;\n\n\t\tprivate FastWriter(){out = null;}\n\n\t\tpublic FastWriter(OutputStream os)\n\t\t{\n\t\t\tthis.out = os;\n\t\t}\n\n\t\tpublic FastWriter(String path)\n\t\t{\n\t\t\ttry {\n\t\t\t\tthis.out = new FileOutputStream(path);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter write(byte b)\n\t\t{\n\t\t\tbuf[ptr++] = b;\n\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(char c)\n\t\t{\n\t\t\treturn write((byte)c);\n\t\t}\n\n\t\tpublic FastWriter write(char[] s)\n\t\t{\n\t\t\tfor(char c : s){\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(String s)\n\t\t{\n\t\t\ts.chars().forEach(c -> {\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t});\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(int l) {\n\t\t\tif (l >= 1000000000) return 10;\n\t\t\tif (l >= 100000000) return 9;\n\t\t\tif (l >= 10000000) return 8;\n\t\t\tif (l >= 1000000) return 7;\n\t\t\tif (l >= 100000) return 6;\n\t\t\tif (l >= 10000) return 5;\n\t\t\tif (l >= 1000) return 4;\n\t\t\tif (l >= 100) return 3;\n\t\t\tif (l >= 10) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(int x)\n\t\t{\n\t\t\tif(x == Integer.MIN_VALUE){\n\t\t\t\treturn write((long)x);\n\t\t\t}\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(long l) {\n\t\t\tif (l >= 1000000000000000000L) return 19;\n\t\t\tif (l >= 100000000000000000L) return 18;\n\t\t\tif (l >= 10000000000000000L) return 17;\n\t\t\tif (l >= 1000000000000000L) return 16;\n\t\t\tif (l >= 100000000000000L) return 15;\n\t\t\tif (l >= 10000000000000L) return 14;\n\t\t\tif (l >= 1000000000000L) return 13;\n\t\t\tif (l >= 100000000000L) return 12;\n\t\t\tif (l >= 10000000000L) return 11;\n\t\t\tif (l >= 1000000000L) return 10;\n\t\t\tif (l >= 100000000L) return 9;\n\t\t\tif (l >= 10000000L) return 8;\n\t\t\tif (l >= 1000000L) return 7;\n\t\t\tif (l >= 100000L) return 6;\n\t\t\tif (l >= 10000L) return 5;\n\t\t\tif (l >= 1000L) return 4;\n\t\t\tif (l >= 100L) return 3;\n\t\t\tif (l >= 10L) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(long x)\n\t\t{\n\t\t\tif(x == Long.MIN_VALUE){\n\t\t\t\treturn write(\"\" + x);\n\t\t\t}\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(double x, int precision)\n\t\t{\n\t\t\tif(x < 0){\n\t\t\t\twrite('-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tx += Math.pow(10, -precision)/2;\n\t\t\t//\t\tif(x < 0){ x = 0; }\n\t\t\twrite((long)x).write(\".\");\n\t\t\tx -= (long)x;\n\t\t\tfor(int i = 0;i < precision;i++){\n\t\t\t\tx *= 10;\n\t\t\t\twrite((char)('0'+(int)x));\n\t\t\t\tx -= (int)x;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(char c){\n\t\t\treturn write(c).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(int x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(double x, int precision){\n\t\t\treturn write(x, precision).writeln();\n\t\t}\n\n\t\tpublic FastWriter write(int... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(int x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(long... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(long x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln()\n\t\t{\n\t\t\treturn write((byte)'\\n');\n\t\t}\n\n\t\tpublic FastWriter writeln(int... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[] line)\n\t\t{\n\t\t\treturn write(line).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[]... map)\n\t\t{\n\t\t\tfor(char[] line : map)write(line).writeln();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(String s)\n\t\t{\n\t\t\treturn write(s).writeln();\n\t\t}\n\n\t\tprivate void innerflush()\n\t\t{\n\t\t\ttry {\n\t\t\t\tout.write(buf, 0, ptr);\n\t\t\t\tptr = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic void flush()\n\t\t{\n\t\t\tinnerflush();\n\t\t\ttry {\n\t\t\t\tout.flush();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"flush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter print(byte b) { return write(b); }\n\t\tpublic FastWriter print(char c) { return write(c); }\n\t\tpublic FastWriter print(char[] s) { return write(s); }\n\t\tpublic FastWriter print(String s) { return write(s); }\n\t\tpublic FastWriter print(int x) { return write(x); }\n\t\tpublic FastWriter print(long x) { return write(x); }\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\n\t\tpublic FastWriter println(char c){ return writeln(c); }\n\t\tpublic FastWriter println(int x){ return writeln(x); }\n\t\tpublic FastWriter println(long x){ return writeln(x); }\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\n\t\tpublic FastWriter println(String s) { return writeln(s); }\n\t\tpublic FastWriter println() { return writeln(); }\n\t}\n\n\tpublic void trnz(int... 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// print ids which are 1\n\tpublic void trt(long... o)\n\t{\n\t\tQueue<Integer> stands = new ArrayDeque<>();\n\t\tfor(int i = 0;i < o.length;i++){\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\n\t\t}\n\t\tSystem.out.println(stands);\n\t}\n\n\tpublic 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\tpublic void tf(boolean[]... b)\n\t{\n\t\tfor(boolean[] r : b) {\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\n\t\t\tSystem.out.println();\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic void tf(long[]... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long[] r : b) {\n\t\t\t\tfor (long x : r) {\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\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\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic void tf(long... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long x : b) {\n\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int(),m=Int(),k=Int();\n            List<int[]>g[]=new ArrayList[n*m+1];\n            for(int i=0;i<g.length;i++){\n                g[i]=new ArrayList<>();\n            }\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m-1;j++){\n                    int w=Int();\n                    int u=i*m+j;\n                    int v=i*m+(j+1);\n                    g[u].add(new int[]{v,w});\n                    g[v].add(new int[]{u,w});\n                }\n            }\n\n            for(int i=0;i<n-1;i++){\n                for(int j=0;j<m;j++){\n                    int w=Int();\n                    int u=i*m+j;\n                    int v=(i+1)*m+j;\n                    g[u].add(new int[]{v,w});\n                    g[v].add(new int[]{u,w});\n                }\n            }\n\n            Solution sol=new Solution(out);\n            sol.solution(n,m,k,g);\n        }\n        out.close();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n\n\n    List<int[]>g[];\n    int n,m;\n    long INF=10000000000000000l;\n    int curr=-1,curc=-1;\n    long mn=Long.MAX_VALUE;\n    long dp[][];\n    public void solution(int n,int m,int k,List<int[]>g[]){\n        //edge : 4 directions.\n        this.n=n;\n        this.m=m;\n        long res[][]=new long[n][m];\n        if(k%2==1){\n            for(int i=0;i<n;i++){\n                Arrays.fill(res[i],-1);\n            }\n            print(res);\n            return;\n        }\n        this.g=g;\n        dp=new long[n*m+1][k/2+2];\n        for(int i=0;i<dp.length;i++){\n            Arrays.fill(dp[i],-1);\n        }\n\n\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                int id=i*m+j;\n                dfs(id,k/2);\n            }\n        }\n\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                int id=i*m+j;\n                res[i][j]=dp[id][k/2];\n            }\n        }\n        print(res);\n    }\n\n    public long dfs(int id,int cnt){\n        if(cnt==0){\n            return 0;\n        }\n        if(dp[id][cnt]!=-1)return dp[id][cnt];\n\n        int r=id/m;\n        int c=id%m;\n        long res=Long.MAX_VALUE;\n        for(int p[]:g[id]){\n            int next=p[0],w=p[1];\n            res=Math.min(res,w*2+dfs(next,cnt-1));\n        }\n        dp[id][cnt]=res;\n        return res;\n\n    }\n\n    public int dis(int x1,int y1,int x2,int y2){\n        return Math.abs(x1-x2)+Math.abs(y1-y2);\n    }\n\n\n    public void print(long A[][]){\n        for(int i=0;i<A.length;i++){\n            for(int j=0;j<A[0].length;j++){\n                out.print(A[i][j]+\" \");\n            }\n            out.println();\n        }\n    }\n\n\n\n\n\n\n}\n\nclass Solution1{\n    PrintWriter out;\n    public Solution1(PrintWriter out){\n        this.out=out;\n    }\n\n    public void solution(int A[]){\n\n    }\n\n}\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \nimport java.math.*;\nimport java.awt.Point;\n \npublic class Main {\n    static final long MOD = 1000000007L;\n    //static final long MOD2 = 1000000009L;\n    //static final long MOD = 998244353L;\n    //static final long INF = 500000000000L;\n    static final int INF =   1000000005;\n    static final int NINF = -1000000005;\n    //static final long NINF = -1000000000000000000L;\n    static FastScanner sc;\n    static PrintWriter pw;\n    static final int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}};\n \n \n    static final int MO = 1200;\n    \n    public static void main(String[] args) {\n        sc = new FastScanner();\n        pw = new PrintWriter(System.out);\n\n        int N = sc.ni();\n        int M = sc.ni();\n        int K = sc.ni();\n        int[][] LR = new int[N][M-1];\n        for (int i = 0; i < N; i++) {\n            LR[i] = sc.intArray(M-1,0);\n        }\n        int[][] UD = new int[N-1][M];\n        for (int i = 0; i < N-1; i++) {\n            UD[i] = sc.intArray(M,0);\n        }\n\n        if (K%2==0) {\n            int T = K/2;\n            int[][] dist = new int[N][M];\n\n            for (int step = 1; step <= T; step++) {\n                int[][] newDist = new int[N][M];\n                for (int i = 0; i < N; i++) {\n                    for (int j = 0; j < M; j++) {\n                        newDist[i][j] = INF;\n\n                        //up\n                        if (i > 0) {\n                            newDist[i][j] = Math.min(newDist[i][j],UD[i-1][j]+dist[i-1][j]);\n                        }\n\n                        //down\n                        if (i < N-1) {\n                            newDist[i][j] = Math.min(newDist[i][j],UD[i][j]+dist[i+1][j]);\n                        }\n\n                        //left\n                        if (j > 0) {\n                            newDist[i][j] = Math.min(newDist[i][j],LR[i][j-1]+dist[i][j-1]);\n                        }\n\n                        //right\n                        if (j < M-1) {\n                            newDist[i][j] = Math.min(newDist[i][j],LR[i][j]+dist[i][j+1]);\n                        }\n                    }\n                }\n                dist = newDist;\n            }\n            \n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < M; j++) {\n                    pw.print((2*dist[i][j]) + \" \");\n                }\n                pw.println();\n            }\n        } else {\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < M; j++) {\n                    pw.print(\"-1 \");\n                }\n                pw.println();\n            }\n        }\n        pw.close();\n    }\n \n    public static void sort(int[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    public static void sort(long[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    //Sort an array (immune to quicksort TLE)\n    public static void sort(int[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<int[]>() {\n            @Override\n            public int compare(int[] a, int[] b) {\n                int ablock = a[0]/MO;\n                int bblock = b[0]/MO;\n                if (ablock != bblock)\n                    return ablock-bblock;\n                else\n                    return a[1]-b[1];\n            }\n        });\n    }\n    \n    public static void sort(long[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<long[]>() {\n            @Override\n            public int compare(long[] a, long[] b) {\n                if (a[0] > b[0])\n                    return 1;\n                else if (a[0] < b[0])\n                    return -1;\n                else\n                    return 0;\n                //Ascending order.\n            }\n        });\n    }\n \n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in), 32768);\n            st = null;\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        int[][] graph(int N, int[][] edges) {\n            int[][] graph = new int[N][];\n            int[] sz = new int[N];\n            for (int[] e: edges) {\n                sz[e[0]] += 1;\n                sz[e[1]] += 1;\n            }\n            for (int i = 0; i < N; i++) {\n                graph[i] = new int[sz[i]];\n            }\n            int[] cur = new int[N];\n            for (int[] e: edges) {\n                graph[e[0]][cur[e[0]]] = e[1];\n                graph[e[1]][cur[e[1]]] = e[0];\n                cur[e[0]] += 1;\n                cur[e[1]] += 1;\n            }\n            return graph;\n        }\n \n        int[] intArray(int N, int mod) {\n            int[] ret = new int[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = ni()+mod;\n            return ret;\n        }\n \n        long nl() {\n            return Long.parseLong(next());\n        }\n \n        long[] longArray(int N, long mod) {\n            long[] ret = new long[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = nl()+mod;\n            return ret;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class Main {\n    static PrintWriter pw;\n    static _Scanner sc;\n\n    public static void main(String[] args) throws Exception {\n        sc = new _Scanner(System.in);\n        pw = new PrintWriter(System.out);\n        //long startTime = System.currentTimeMillis();\n        //int t = sc.nextInt();\n        int t = 1;\n        while (t-- > 0) {\n            solve();\n        }\n        pw.flush();\n        //System.out.println(\"time: \" + (System.currentTimeMillis() - startTime));\n    }\n\n    private static void solve() throws Exception {\n        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();\n\n        int[][] h = new int[n][m - 1];\n        int[][] v = new int[n - 1][m];\n\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < m - 1; ++j) {\n                h[i][j] = sc.nextInt();\n            }\n        }\n\n        for (int i = 0; i < n - 1; ++i) {\n            for (int j = 0; j < m; ++j) {\n                v[i][j] = sc.nextInt();\n            }\n        }\n\n        if (k % 2 == 1) {\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    if (j > 0) {\n                        pw.print(\" \");\n                    }\n                    pw.print(-1);\n                }\n                pw.println();\n            }\n            return;\n        }\n\n        k = k / 2;\n\n        long[][] d = new long[n][m];\n        for (int ki = 0; ki < k; ++ki) {\n            long[][] dk = new long[n][m];\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    long val = Integer.MAX_VALUE;\n\n                    if (j < m - 1) {\n                        val = Math.min(val, d[i][j + 1] + h[i][j]);\n                    }\n\n                    if (i < n - 1) {\n                        val = Math.min(val, d[i + 1][j] + v[i][j]);\n                    }\n\n                    if (j > 0) {\n                        val = Math.min(val, d[i][j - 1] + h[i][j - 1]);\n                    }\n\n                    if (i > 0) {\n                        val = Math.min(val, d[i - 1][j] + v[i - 1][j]);\n                    }\n\n                    dk[i][j] = val;\n                }\n            }\n            d = dk;\n        }\n\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < m; ++j) {\n                if (j > 0) {\n                    pw.print(\" \");\n                }\n                pw.print(d[i][j] * 2);\n            }\n            pw.println();\n        }\n    }\n\n    static class Shuffle {\n        static void run(int[] in) {\n            for (int i = 0; i < in.length; i++) {\n                int idx = (int) (Math.random() * in.length);\n                int tmp = in[i];\n                in[i] = in[idx];\n                in[idx] = tmp;\n            }\n        }\n\n        static void run(long[] in) {\n            for (int i = 0; i < in.length; i++) {\n                int idx = (int) (Math.random() * in.length);\n                long tmp = in[i];\n                in[i] = in[idx];\n                in[idx] = tmp;\n            }\n        }\n\n        static <T> void run(List<T> in) {\n            for (int i = 0; i < in.size(); i++) {\n                int idx = (int) (Math.random() * in.size());\n                T tmp = in.get(i);\n                in.set(i, in.get(idx));\n                in.set(idx, tmp);\n            }\n        }\n    }\n\n    static class _Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        _Scanner(InputStream system) {\n            br = new BufferedReader(new InputStreamReader(system));\n        }\n\n        _Scanner(String file) throws Exception {\n            br = new BufferedReader(new FileReader(file));\n        }\n\n        String nextToken() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n\n        int[] intArr(int n) throws IOException {\n            int[] in = new int[n];\n            for (int i = 0; i < n; i++) in[i] = nextInt();\n            return in;\n        }\n\n        long[] longArr(int n) throws IOException {\n            long[] in = new long[n];\n            for (int i = 0; i < n; i++) in[i] = nextLong();\n            return in;\n        }\n\n        int[] intArrSorted(int n) throws IOException {\n            int[] in = new int[n];\n            for (int i = 0; i < n; i++) in[i] = nextInt();\n            Shuffle.run(in);\n            Arrays.sort(in);\n            return in;\n        }\n\n        long[] longArrSorted(int n) throws IOException {\n            long[] in = new long[n];\n            for (int i = 0; i < n; i++) in[i] = nextLong();\n            Shuffle.run(in);\n            Arrays.sort(in);\n            return in;\n        }\n\n        Integer[] IntegerArr(int n) throws IOException {\n            Integer[] in = new Integer[n];\n            for (int i = 0; i < n; i++) in[i] = nextInt();\n            return in;\n        }\n\n        Long[] LongArr(int n) throws IOException {\n            Long[] in = new Long[n];\n            for (int i = 0; i < n; i++) in[i] = nextLong();\n            return in;\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\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        char nextChar() throws IOException {\n            return nextToken().charAt(0);\n        }\n\n        long nextLong() throws IOException {\n            return Long.parseLong(nextToken());\n        }\n\n        boolean ready() throws IOException {\n            return br.ready();\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "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        DExplorerSpace solver = new DExplorerSpace();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DExplorerSpace {\n        static final int oo = 1000000000;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();\n            int[][] right = new int[n][m - 1];\n            int[][] down = new int[n - 1][m];\n\n            for (int i = 0; i < n; i++) right[i] = in.readIntArray(m - 1);\n            for (int i = 0; i + 1 < n; i++) down[i] = in.readIntArray(m);\n            if (k % 2 == 1) {\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) out.print(-1 + \" \");\n                    out.println();\n                }\n                return;\n            }\n            int[][][] dp = new int[k / 2 + 1][n][m];\n\n            for (int r = 1; 2 * r <= k; r++) {\n                for (int i = 0; i < n; i++) Arrays.fill(dp[r][i], oo);\n                for (int i = 0; i < n; i++)\n                    for (int j = 0; j < m - 1; j++) {\n                        int cost = right[i][j];\n                        dp[r][i][j] = Integer.min(dp[r][i][j], dp[r - 1][i][j + 1] + cost);\n                        dp[r][i][j + 1] = Integer.min(dp[r][i][j + 1], dp[r - 1][i][j] + cost);\n                    }\n\n                for (int i = 0; i + 1 < n; i++)\n                    for (int j = 0; j < m; j++) {\n                        int cost = down[i][j];\n                        dp[r][i][j] = Integer.min(dp[r][i][j], dp[r - 1][i + 1][j] + cost);\n                        dp[r][i + 1][j] = Integer.min(dp[r][i + 1][j], dp[r - 1][i][j] + cost);\n                    }\n            }\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.print(2 * dp[k / 2][i][j] + \" \");\n                }\n                out.println();\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            for (int i = 0; i < objects.length; i++) {\n                if (i != 0) {\n                    writer.print(' ');\n                }\n                writer.print(objects[i]);\n            }\n            writer.print('\\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[] 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 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 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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "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        static int n;\n        static int m;\n        static int steps;\n        static long[][] distJ;\n        static long[][] distI;\n        static long[][][] memo;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.nextInt();\n            m = in.nextInt();\n            steps = in.nextInt();\n            memo = new long[n][m][steps];\n            distJ = new long[n][m - 1];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m - 1; j++) {\n                    distJ[i][j] = in.nextLong();\n                }\n            }\n            distI = new long[n - 1][m];\n            for (int i = 0; i < n - 1; i++) {\n                for (int j = 0; j < m; j++) {\n                    distI[i][j] = in.nextLong();\n                }\n            }\n\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    if (steps % 2 != 0) {\n                        out.print(-1 + \" \");\n                    } else {\n                        out.print(2 * lowestCost(i, j, steps / 2) + \" \");\n                    }\n                }\n                out.println();\n            }\n        }\n\n        private long lowestCost(int i, int j, int distance) {\n            if (distance == 0) {\n                return 0;\n            }\n            if (memo[i][j][distance] > 0) {\n                return memo[i][j][distance];\n            }\n\n            long minDist = Long.MAX_VALUE;\n            //j + 1 and j -1\n            if (j < m - 1) {\n                // move forward on j\n                minDist = Math.min(minDist, distJ[i][j] + lowestCost(i, j + 1, distance - 1));\n            }\n            if (j > 0) {\n                // move backward on j\n                minDist = Math.min(minDist, distJ[i][j - 1] + lowestCost(i, j - 1, distance - 1));\n            }\n\n            if (i < n - 1) {\n                // move forward on i\n                minDist = Math.min(minDist, distI[i][j] + lowestCost(i + 1, j, distance - 1));\n            }\n            if (i > 0) {\n                // move backward on i\n                minDist = Math.min(minDist, distI[i - 1][j] + lowestCost(i - 1, j, distance - 1));\n            }\n\n            //memoize\n            memo[i][j][distance] = minDist;\n            return minDist;\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    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\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.*;\n\npublic class D {\n\n    static Scanner sc;\n    static PrintWriter out;\n\n    public static void main(String[] args) throws Exception {\n\n        sc = new Scanner(System.in);\n        out = new PrintWriter(System.out);\n        //int t = sc.nextInt();\n        for(int i=0; i<1; i++) {\n            solve();\n        }\n        out.flush();\n    }\n\n    static void solve() {\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n        int[][] a = new int[n][m-1];\n        int[][] b = new int[n-1][m];\n        for(int i=0 ;i<n; i++) {\n            for(int j=0; j<m-1; j++) {\n                a[i][j] = sc.nextInt();\n            }\n        }\n        for(int i=0 ;i<n-1; i++) {\n            for(int j=0; j<m; j++) {\n                b[i][j] = sc.nextInt();\n            }\n        }\n\n        if(k % 2 == 1) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    if (j > 0)\n                        out.print(\" \");\n                    out.print(\"-1\");\n                }\n                out.println();\n            }\n            return;\n        }\n\n\n        int[][] prev = new int[n][m];\n        k /= 2;\n        for(int l=0; l<k; l++) {\n            int[][] next = new int[n][m];\n            for(int i=0; i<n; i++) {\n                for(int j=0; j<m; j++) {\n                    next[i][j] = Integer.MAX_VALUE;\n                    if(i>0) {\n                        next[i][j] = Math.min(next[i][j], prev[i-1][j] + b[i-1][j]);\n                    }\n                    if(i+1<n) {\n                        next[i][j] = Math.min(next[i][j], prev[i+1][j] + b[i][j]);\n                    }\n                    if(j>0) {\n                        next[i][j] = Math.min(next[i][j], prev[i][j-1] + a[i][j-1]);\n                    }\n                    if(j+1<m) {\n                        next[i][j] = Math.min(next[i][j], prev[i][j+1] + a[i][j]);\n                    }\n                }\n            }\n            prev = next;\n        }\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (j > 0)\n                    out.print(\" \");\n                out.print(prev[i][j] * 2);\n            }\n            out.println();\n        }\n\n\n    }\n\n\n\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdE {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n    static long[][][] paths;\n    static long[] powers501;\n\tpublic static void main(String[] havish) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\tint n = sc.nextInt();\n \t\tint m = sc.nextInt();\n \t\tint k = sc.nextInt();\n \t\tpaths = new long[n+1][m+1][4]; //up down left right;\n \t\tpowers501 = new long[5];\n \t\tpowers501[0] = 1;\n \t\tfor(int j = 1;j<5;j++){\n \t\t\tpowers501[j] = 501L*powers501[j-1];\n \t\t}\n \t\tlong[][][]dp = new long[n+1][m+1][k/2+2];\n \t\tfor(int i = 1;i<=n;i++){\n \t\t\tfor(int j = 1;j<=m-1;j++){\n \t\t\t\tint val = sc.nextInt();\n \t\t\t\tpaths[i][j][3] = val;\n \t\t\t\tpaths[i][j+1][2] = val;\n// \t\t\t\tpaths.put(powers501[3]*i + powers501[2]*j + powers501[1]*i + powers501[0]*(j+1), val);\n// \t\t\t\tpaths.put(powers501[3]*i + powers501[2]*(j+1) + powers501[1]*i + powers501[0]*j, val);\n \t\t\t}\n \t\t}\n \t\tfor(int i = 1;i<=n-1;i++){\n \t\t\tfor(int j = 1;j<=m;j++){\n \t\t\t\tint val = sc.nextInt();\n// \t\t\t\tpaths.put(powers501[3]*(i+1) + powers501[2]*j + powers501[1]*i + powers501[0]*j, val);\n// \t\t\t\tpaths.put(powers501[3]*i + powers501[2]*j + powers501[1]*(i+1) + powers501[0]*j, val);\n \t\t\t\tpaths[i][j][1] = val;\n \t\t\t\tpaths[i+1][j][0] = val;\n \t\t\t\t\n \t\t\t}\n \t\t}\n \t\tfor(int j = 1;j<=n;j++){\n \t\t\tfor(int i = 1;i<=m;i++){\n \t\t\t\tArrays.fill(dp[j][i],  Integer.MAX_VALUE);\n \t\t\t\tdp[j][i][0] = 0;\n \t\t\t}\n \t\t}\n \t\tfor(int steps = 1;steps<k/2+2;steps++){\n \t\t\tfor(int i = 1;i<=n;i++){\n \t\t\t\tfor(int j = 1;j<=m;j++){\n \t\t\t\t\tif (i-1 > 0) {\n \t\t\t\t\t\tdp[i][j][steps] = Math.min(dp[i-1][j][steps-1] + getVal(i, j, i-1, j), dp[i][j][steps]);\n \t\t\t\t\t}\n \t\t\t\t\tif (j-1 > 0) {\n \t\t\t\t\t\tdp[i][j][steps] = Math.min(dp[i][j-1][steps-1] + getVal(i, j, i, j-1), dp[i][j][steps]);\n \t\t\t\t\t}\n \t\t\t\t\t\n \t\t\t\t\tif (i+1 <= n) {\n \t\t\t\t\t\tdp[i][j][steps] = Math.min(dp[i+1][j][steps-1] + getVal(i, j, i+1, j), dp[i][j][steps]);\n \t\t\t\t\t}\n \t\t\t\t\tif (j+1 <= m) {\n \t\t\t\t\t\tdp[i][j][steps] = Math.min(dp[i][j+1][steps-1] + getVal(i, j, i, j+1), dp[i][j][steps]);\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t\tif (k%2 == 1){\n \t\t\tfor(int j = 1;j<=n;j++){\n \t\t\t\tfor(int s = 1;s<=m;s++){\n \t\t\t\t\tout.print(-1 + \" \");\n \t\t\t\t}\n \t\t\t\tout.println();\n \t\t\t}\n \t\t}\n \t\telse{\n \t\t\tfor(int j = 1;j<=n;j++){\n \t\t\t\tfor(int s = 1;s<=m;s++){\n \t\t\t\t\tout.print(dp[j][s][k/2]*2L + \" \");\n \t\t\t\t}\n \t\t\t\tout.println();\n \t\t\t}\n \t\t}\n \t\t\n \t\t\n\t \t\t\n \t\tout.close();\n \t}\n\tpublic static long getVal(int x1, int y1, int x2, int y2) {\n\t\tif (x2 == x1+1)\n\t\t\treturn paths[x1][y1][1];\n\t\telse if (x1 == x2+1)\n\t\t\treturn paths[x1][y1][0];\n\t\telse if (y2 == y1 + 1)\n\t\t\treturn paths[x1][y1][3];\n\t\telse\n\t\t\treturn paths[x1][y1][2];\n\t}\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class D {\n    static long[][][] dp;\n    static int[][] hor, ver;\n    static int n, m;\n    static int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n\n    public static boolean isValid (int row, int col) {\n        return row >= 0 && col >= 0 && row < n && col < m;\n    }\n\n    public static void minCost (int row, int col, int k) {\n        if (k == 0)\n            return;\n        if (k == 2) {\n            long min = Long.MAX_VALUE;\n            for (int i = 0; i < 4; i++) {\n                if (isValid(row + dir[i][0], col + dir[i][1])) {\n                    if ((row + dir[i][0]) == row) {\n                        if ((col + dir[i][1]) > col) {\n                            min = Math.min(min, hor[row][col]);\n                        } else {\n                            min = Math.min(min, hor[row][col - 1]);\n                        }\n                    } else {\n                        if ((row + dir[i][0]) > row) {\n                            min = Math.min(min, ver[row][col]);\n                        } else {\n                            min = Math.min(min, ver[row - 1][col]);\n                        }\n                    }\n                }\n            }\n            dp[row][col][k] = 2 * min;\n            return;\n        }\n        if (dp[row][col][k] != Long.MAX_VALUE)\n            return;\n        long min = Long.MAX_VALUE;\n        for (int i = 0; i < 4; i++) {\n            if (isValid(row + dir[i][0], col + dir[i][1])) {\n                if (k >= 4) {\n                    minCost(row + dir[i][0], col + dir[i][1], k - 2);\n                    int edge = 0;\n                    if ((row + dir[i][0]) == row) {\n                        if ((col + dir[i][1]) > col) {\n                            edge = hor[row][col];\n                        } else {\n                            edge = hor[row][col - 1];\n                        }\n                    } else {\n                        if ((row + dir[i][0]) > row) {\n                            edge = ver[row][col];\n                        } else {\n                            edge = ver[row - 1][col];\n                        }\n                    }\n                    min = Math.min(min, 2 * edge + dp[row + dir[i][0]][col + dir[i][1]][k - 2]);\n                }\n            }\n        }\n        dp[row][col][k] = min;\n    }\n\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        n = input.nextInt();\n        m = input.nextInt();\n        int k = input.nextInt();\n        hor = new int[n][m - 1];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m - 1; j++) {\n                hor[i][j] = input.nextInt();\n            }\n        }\n        ver = new int[n - 1][m];\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = 0; j < m; j++) {\n                ver[i][j] = input.nextInt();\n            }\n        }\n        if (k % 2 != 0) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    System.out.print(-1 + \" \");\n                }\n                System.out.println(\"\");\n            } \n        } else {\n            dp = new long[n][m][k + 1];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    for (int x = 0; x <= k; x++) {\n                        dp[i][j][x] = Long.MAX_VALUE;\n                    }\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    minCost(i, j, k);\n                    System.out.print(dp[i][j][k] + \" \");\n                }\n                System.out.println(\"\");\n            }\n        }\n        \n        input.close();\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "//Utilities\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic int n, m, k;\n\tstatic int[][] horW, verW;\n\tstatic int[][][] dp = new int[505][505][15];\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tfor (int i = 0; i < 505; i++) {\n\t\t\tfor (int j = 0; j < 505; j++) {\n\t\t\t\tfor (int k = 0; k < 15; k++) {\n\t\t\t\t\tdp[i][j][k] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tn = in.iscan(); m = in.iscan(); k =in.iscan();\n\t\thorW = new int[n+1][m]; verW = new int[n][m+1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= m-1; j++) {\n\t\t\t\thorW[i][j] = in.iscan();\n\t\t\t}\n\t\t}\n\t\tfor (int i = 1; i <= n-1; i++) {\n\t\t\tfor (int j = 1; j <= m; j++) {\n\t\t\t\tverW[i][j] = in.iscan();\n\t\t\t}\n\t\t}\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= m; j++) {\n\t\t\t\tif (k % 2 == 1) {\n\t\t\t\t\tout.print(-1 + \" \");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tout.print(dfs(i, j, k/2) * 2 + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\tout.close();\n\t} \n\t\n\tstatic int dfs(int r, int c, int k) {\n\t\tif (dp[r][c][k] != -1) {\n\t\t\treturn dp[r][c][k];\n\t\t}\n\t\tif (k == 0) {\n\t\t\treturn dp[r][c][k] = 0;\n\t\t}\n\t\tint min = Integer.MAX_VALUE;\n\t\tif (r - 1 >= 1) {\n\t\t\tmin = Math.min(min, verW[r-1][c] + dfs(r-1, c, k-1));\n\t\t}\n\t\tif (r + 1 <= n) {\n\t\t\tmin = Math.min(min, verW[r][c] + dfs(r+1, c, k-1));\n\t\t}\n\t\tif (c - 1 >= 1) {\n\t\t\tmin = Math.min(min, horW[r][c-1] + dfs(r, c-1, k-1));\n\t\t}\n\t\tif (c + 1 <= m) {\n\t\t\tmin = Math.min(min, horW[r][c] + dfs(r, c+1, k-1));\n\t\t}\n\t\treturn dp[r][c][k] = min;\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 long gcd (long a, long b) {\n\t\t\treturn b == 0 ? a : gcd (b, a % b);\n\t\t}\n\n\t\tpublic static long lcm (long a, long 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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main {\n\n    public static void deal(int n,int m,int k,int[][] d1,int[][] d2) {\n        if(k % 2 == 1) {\n            for(int i=0;i<n;i++) {\n                for(int j=0;j<m;j++) {\n                    System.out.print(\"-1 \");\n                }\n                System.out.println();\n            }\n            return;\n        }\n        int[][][] dp = new int[k/2+1][n][m];\n        for(int i=0;i<k/2;i++) {\n            for(int j=0;j<n;j++) {\n                for(int l=0;l<m;l++) {\n                    int min = Integer.MAX_VALUE;\n                    if(j>0) min = Math.min(min,d2[j-1][l]+dp[i][j-1][l]);\n                    if(j<n-1) min = Math.min(min,d2[j][l]+dp[i][j+1][l]);\n                    if(l>0) min = Math.min(min,d1[j][l-1]+dp[i][j][l-1]);\n                    if(l<m-1) min = Math.min(min,d1[j][l]+dp[i][j][l+1]);\n                    dp[i+1][j][l] = min;\n                }\n            }\n        }\n        for(int i=0;i<n;i++) {\n            for(int j=0;j<m;j++) {\n                System.out.print(dp[k/2][i][j]*2);\n                System.out.print(\" \");\n            }\n            System.out.println();\n        }\n    }\n    public static void main(String[] args) {\n        MyScanner scanner = new MyScanner();\n        int n = scanner.nextInt();\n        int m = scanner.nextInt();\n        int k = scanner.nextInt();\n        int[][] d1 = new int[n][m-1];\n        int[][] d2 = new int[n-1][m];\n        for(int i=0;i<n;i++) {\n            for(int j=0;j<m-1;j++) {\n                d1[i][j] = scanner.nextInt();\n            }\n        }\n        for(int i=0;i<n-1;i++) {\n            for(int j=0;j<m;j++) {\n                d2[i][j] = scanner.nextInt();\n            }\n        }\n        deal(n,m,k,d1,d2);\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class D {\n    static class Scan {\n        private byte[] buf=new byte[1024];\n        private int index;\n        private InputStream in;\n        private int total;\n        public Scan()\n        {\n            in=System.in;\n        }\n        public int scan()throws IOException\n        {\n            if(total<0)\n            throw new InputMismatchException();\n            if(index>=total)\n            {\n                index=0;\n                total=in.read(buf);\n                if(total<=0)\n                return -1;\n            }\n            return buf[index++];\n        }\n        public int scanInt()throws IOException\n        {\n            int integer=0;\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            int neg=1;\n            if(n=='-')\n            {\n                neg=-1;\n                n=scan();\n            }\n            while(!isWhiteSpace(n))\n            {\n                if(n>='0'&&n<='9')\n                {\n                    integer*=10;\n                    integer+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            return neg*integer;\n        }\n        public double scanDouble()throws IOException\n        {\n            double doub=0;\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            int neg=1;\n            if(n=='-')\n            {\n                neg=-1;\n                n=scan();\n            }\n            while(!isWhiteSpace(n)&&n!='.')\n            {\n                if(n>='0'&&n<='9')\n                {\n                    doub*=10;\n                    doub+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            if(n=='.')\n            {\n                n=scan();\n                double temp=1;\n                while(!isWhiteSpace(n))\n                {\n                    if(n>='0'&&n<='9')\n                    {\n                        temp/=10;\n                        doub+=(n-'0')*temp;\n                        n=scan();\n                    }\n                    else throw new InputMismatchException();\n                }\n            }\n            return doub*neg;\n        }\n        public String scanString()throws IOException\n        {\n            StringBuilder sb=new StringBuilder();\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            while(!isWhiteSpace(n))\n            {\n                sb.append((char)n);\n                n=scan();\n            }\n            return sb.toString();\n        }\n        private boolean isWhiteSpace(int n)\n        {\n            if(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n            return true;\n            return false;\n        }\n    }\n    \n    public static void sort(int arr[],int l,int r) {    //sort(arr,0,n-1);\n        if(l==r) {\n            return;\n        }\n        int mid=(l+r)/2;\n        sort(arr,l,mid);\n        sort(arr,mid+1,r);\n        merge(arr,l,mid,mid+1,r);\n    }\n    public static void merge(int arr[],int l1,int r1,int l2,int r2) {\n        int tmp[]=new int[r2-l1+1];\n        int indx1=l1,indx2=l2;\n        //sorting the two halves using a tmp array\n        for(int i=0;i<tmp.length;i++) {\n            if(indx1>r1) {\n                tmp[i]=arr[indx2];\n                indx2++;\n                continue;\n            }\n            if(indx2>r2) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            if(arr[indx1]<arr[indx2]) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            tmp[i]=arr[indx2];\n            indx2++;\n        }\n        //Copying the elements of tmp into the main array\n        for(int i=0,j=l1;i<tmp.length;i++,j++) {\n            arr[j]=tmp[i];\n        }\n    }\n    \n    public static void sort(long arr[],int l,int r) {    //sort(arr,0,n-1);\n        if(l==r) {\n            return;\n        }\n        int mid=(l+r)/2;\n        sort(arr,l,mid);\n        sort(arr,mid+1,r);\n        merge(arr,l,mid,mid+1,r);\n    }\n    public static void merge(long arr[],int l1,int r1,int l2,int r2) {\n        long tmp[]=new long[r2-l1+1];\n        int indx1=l1,indx2=l2;\n        //sorting the two halves using a tmp array\n        for(int i=0;i<tmp.length;i++) {\n            if(indx1>r1) {\n                tmp[i]=arr[indx2];\n                indx2++;\n                continue;\n            }\n            if(indx2>r2) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            if(arr[indx1]<arr[indx2]) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            tmp[i]=arr[indx2];\n            indx2++;\n        }\n        //Copying the elements of tmp into the main array\n        for(int i=0,j=l1;i<tmp.length;i++,j++) {\n            arr[j]=tmp[i];\n        }\n    }\n    \n    static int n,m,k,uu[][],rr[][],dd[][],ll[][],dp[][][];\n    \n    public static void main(String args[]) throws IOException {\n        Scan input=new Scan();\n        StringBuilder ans=new StringBuilder(\"\");\n        \n        n=input.scanInt();\n        m=input.scanInt();\n        k=input.scanInt();\n        \n        dp=new int[n][m][k];\n        for(int i=0;i<n;i++) {\n            for(int j=0;j<m;j++) {\n                for(int kk=0;kk<k;kk++) {\n                    dp[i][j][kk]=-1;\n                }\n            }\n        }\n        \n        uu=new int[n][m];\n        rr=new int[n][m];\n        dd=new int[n][m];\n        ll=new int[n][m];\n        \n        for(int i=0;i<n;i++) {\n            for(int j=0;j<m-1;j++) {\n                int tmp=input.scanInt();\n                rr[i][j]=tmp;\n                ll[i][j+1]=tmp;\n            }\n        }\n        \n        for(int i=0;i<n-1;i++) {\n            for(int j=0;j<m;j++) {\n                int tmp=input.scanInt();\n                dd[i][j]=tmp;\n                uu[i+1][j]=tmp;\n            }\n        }\n        \n        for(int i=0;i<n;i++) {\n            for(int j=0;j<m;j++) {\n                if(k%2!=0) {\n                    ans.append(-1+\" \");\n                    continue;\n                }\n                ans.append((2*solve(i,j,k/2))+\" \");\n            }\n            ans.append(\"\\n\");\n        }\n        \n        System.out.println(ans);\n    }\n    \n    public static int solve(int x,int y,int rem) {\n        if(rem==0) {\n            return 0;\n        }\n        \n        if(dp[x][y][rem]!=-1) {\n            return dp[x][y][rem];\n        }\n        \n        int ans=Integer.MAX_VALUE/10;\n        if(uu[x][y]!=0) {\n            ans=Math.min(ans,uu[x][y]+solve(x-1,y,rem-1));\n        }\n        if(rr[x][y]!=0) {\n            ans=Math.min(ans,rr[x][y]+solve(x,y+1,rem-1));\n        }\n        if(dd[x][y]!=0) {\n            ans=Math.min(ans,dd[x][y]+solve(x+1,y,rem-1));\n        }\n        if(ll[x][y]!=0) {\n            ans=Math.min(ans,ll[x][y]+solve(x,y-1,rem-1));\n        }\n        \n        dp[x][y][rem]=ans;\n        \n        return ans;\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1517D extends PrintWriter {\n\tCF1517D() { super(System.out); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1517D o = new CF1517D(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tif (k % 2 == 1) {\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\tprint(\"-1 \");\n\t\t\t\tprintln();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tk /= 2;\n\t\tint[][] hh = new int[n][m - 1];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m - 1; j++)\n\t\t\t\thh[i][j] = sc.nextInt();\n\t\tint[][] vv = new int[n - 1][m];\n\t\tfor (int i = 0; i < n - 1; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tvv[i][j] = sc.nextInt();\n\t\tint[][] dp = new int[n][m];\n\t\tint[][] dq = new int[n][m];\n\t\twhile (k-- > 0) {\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tint x = INF;\n\t\t\t\t\tif (i > 0)\n\t\t\t\t\t\tx = Math.min(x, dp[i - 1][j] + vv[i - 1][j]);\n\t\t\t\t\tif (j > 0)\n\t\t\t\t\t\tx = Math.min(x, dp[i][j - 1] + hh[i][j - 1]);\n\t\t\t\t\tif (i + 1 < n)\n\t\t\t\t\t\tx = Math.min(x, dp[i + 1][j] + vv[i][j]);\n\t\t\t\t\tif (j + 1 < m)\n\t\t\t\t\t\tx = Math.min(x, dp[i][j + 1] + hh[i][j]);\n\t\t\t\t\tdq[i][j] = x;\n\t\t\t\t}\n\t\t\tint[][] tmp = dp; dp = dq; dq = tmp;\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\tprint(dp[i][j] * 2 + \" \");\n\t\t\tprintln();\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.*;\npublic class Main{\n    static class FastScanner {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(\"\");\n\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        int[] nextArray(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) a[i] = nextInt();\n            return a;\n        }\n        long[] nextArray(long n) {\n            long[] a = new long[(int) n];\n            for (int i = 0; i < n; i++) a[i] = nextLong();\n            return a;\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n    static class FastWriter extends PrintWriter {\n            FastWriter(){\n                super(System.out);\n            }\n            void println(int[] array) {\n                for(int i=0; i<array.length; i++) {\n                    print(array[i]+\" \");\n                }\n                println();\n            }\n            void println(long [] array) {\n                for(int i=0; i<array.length; i++) {\n                    print(array[i]+\" \");\n                }\n                println();\n            }\n        }\n    static int x,y;\n    public static void main(String[] args){\n        FastScanner in = new FastScanner();\n        FastWriter out = new FastWriter();\n        int n=in.nextInt();\n        int m=in.nextInt();\n        int k=in.nextInt();\n        int[][] right=new int[n][m-1];\n        int[][] down=new int[n-1][m];\n        for (int i = 0; i < n; i++) {\n            right[i]=in.nextArray(m-1);\n        }\n        for (int i = 0; i < n - 1; i++) {\n            down[i]=in.nextArray(m);\n        }\n        if(k%2!=0){\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.print(\"-1 \");\n                }\n                out.println();\n            }\n        }else {\n            int[][] dp=new int[n][m];\n            int[][] dp1=new int[n][m];\n            for (int i = 0; i < k / 2; i++) {\n                for (int j = 0; j < n; j++) {\n                    for (int l = 0; l < m; l++) {\n                        int ans=Integer.MAX_VALUE;\n                        if(j>0){\n                            ans=Math.min(ans,dp[j-1][l]+down[j-1][l]);\n                        }\n                        if(l>0){\n                            ans=Math.min(ans,dp[j][l-1]+right[j][l-1]);\n                        }\n                        if(j!=n-1){\n                            ans=Math.min(ans,dp[j+1][l]+down[j][l]);\n                        }\n                        if(l!=m-1){\n                            ans=Math.min(ans,dp[j][l+1]+right[j][l]);\n                        }\n                        dp1[j][l]=ans;\n                    }\n                }\n                dp=dp1;\n                dp1=new int[n][m];\n            }\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.println((2*dp[i][j])+\" \");\n                }\n                out.println();\n            }\n        }\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class D1517 {\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\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint[][] costRight = new int[n][m - 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m - 1; j++) {\n\t\t\t\tcostRight[i][j] = sc.nextInt();\n\t\t\t}\n\t\t}\n\t\tint[][] costDown = new int[n - 1][m];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tcostDown[i][j] = sc.nextInt();\n\t\t\t}\n\t\t}\n\t\tif (k % 2 == 1) {\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\tpw.print(-1 + \" \");\n\t\t\t\t}\n\t\t\t\tpw.println();\n\t\t\t}\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tint[][][] dp = new int[k + 1][n][m];\n\t\tfor (int w = 2; w <= k; w += 2) {\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\tdp[w][i][j] = (int) 1e9;\n\t\t\t\t\tif (i + 1 < n)\n\t\t\t\t\t\tdp[w][i][j] = Math.min(dp[w][i][j], 2 * costDown[i][j] + dp[w - 2][i + 1][j]);\n\t\t\t\t\tif (i - 1 >= 0)\n\t\t\t\t\t\tdp[w][i][j] = Math.min(dp[w][i][j], 2 * costDown[i - 1][j] + dp[w - 2][i - 1][j]);\n\t\t\t\t\tif (j + 1 < m)\n\t\t\t\t\t\tdp[w][i][j] = Math.min(dp[w][i][j], 2 * costRight[i][j] + dp[w - 2][i][j + 1]);\n\t\t\t\t\tif (j - 1 >= 0)\n\t\t\t\t\t\tdp[w][i][j] = Math.min(dp[w][i][j], 2 * costRight[i][j - 1] + dp[w - 2][i][j - 1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tpw.print(dp[k][i][j] + \" \");\n\t\t\t}\n\t\t\tpw.println();\n\t\t}\n\t\tpw.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\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 f) {\n\t\t\tbr = new BufferedReader(f);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic int[] nextIntArr(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] = Integer.parseInt(next());\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t}\n\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\npublic class Main {\n  public static Scanner scan = new Scanner(System.in);\n\n  int n, m;\n  int[][] x;\n  int[][] y;\n  int k, k2;\n\n  int[][] sol0;\n  int[][] sol1;\n    \n  public Main(int[][] x, int[][] y, int k) {\n    this.x = x;\n    this.y = y;\n    this.k = k;\n    this.n = x.length;\n    this.m = x[0].length;\n  }\n\n  void go() {\n    if(k%2 != 0) {\n      for(int i=0; i<n; ++i) {\n        for(int j=0; j<m; ++j) {\n          System.out.print(-1 + \" \");\n        }\n        System.out.println();\n      }  \n      return;\n    }\n    k2 = k/2;\n    sol0 = new int[n][m];\n    sol1 = new int[n][m];\n    \n    for(int d=0; d<k2; ++d) {\n      var zzz = sol1;\n      sol1 = sol0;\n      sol0 = zzz;\n      \n      for(int i=0; i<n; ++i)\n        for(int j=0; j<m; ++j) {\n          update(i,j);\n        }\n    }\n    for(int i=0; i<n; ++i) {\n      for(int j=0; j<m; ++j) {\n        System.out.print(sol1[i][j]*2 + \" \");\n      }\n      System.out.println();\n    }\n\n  }\n  \n  void update(int i, int j) {\n    int ret = Integer.MAX_VALUE;\n    if(i>0)\n      ret = Math.min(ret, sol0[i-1][j] + y[i-1][j]);\n    if(j>0)\n      ret = Math.min(ret, sol0[i][j-1] + x[i][j-1]);\n    if(i < n-1)\n      ret = Math.min(ret, sol0[i+1][j] + y[i][j]);\n    if(j < m-1)\n      ret = Math.min(ret, sol0[i][j+1] + x[i][j]);\n    sol1[i][j] = ret;\n  }\n  \n  \n  public static void main(String[] args) {\n    int n = scan.nextInt();\n    int m = scan.nextInt();\n    int k = scan.nextInt();\n    int x[][] = new int[n][m];\n    int y[][] = new int[n][m];\n    for(int i=0; i<n; ++i) {\n      for(int j=0; j<m-1; ++j) {\n        x[i][j] = scan.nextInt();\n      }\n    }\n    for(int i=0; i<n-1; ++i) {\n      for(int j=0; j<m; ++j) {\n        y[i][j] = scan.nextInt();\n      }\n    }\n    Main mm = new Main(x,y,k);\n    mm.go();\n  }\n\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "// Main Code at the Bottom\nimport java.util.*;\nimport java.io.*; \npublic class Main{\n\t//Fast IO class\n    static class FastReader {\n        BufferedReader br; \n        StringTokenizer st; \n        public FastReader() {\n        \tboolean env=System.getProperty(\"ONLINE_JUDGE\") != null;\n        \t//env=true;\n        \tif(!env) {\n        \t\ttry {\n\t\t\t\t\tbr=new BufferedReader(new FileReader(\"src\\\\input.txt\"));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n        \t}\n        \telse br = new BufferedReader(new InputStreamReader(System.in)); \n        } \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine()); \n                } \n                catch (IOException  e) {\n                    e.printStackTrace(); \n                } \n            } \n            return st.nextToken(); \n        } \n        int nextInt() {\n            return Integer.parseInt(next()); \n        } \n        long nextLong() {\n            return Long.parseLong(next()); \n        } \n        double nextDouble() {\n            return Double.parseDouble(next()); \n        } \n        String nextLine() {\n            String str = \"\"; \n            try {\n                str = br.readLine(); \n            } \n            catch (IOException e) {\n                e.printStackTrace(); \n            } \n            return str; \n        } \n    }     \n    static long MOD=(long)1e9+7;\n    //debug\n    static void debug(Object... o) {\n        System.out.println(Arrays.deepToString(o));\n    }\n    static FastReader sc=new FastReader();\n    static PrintWriter out=new PrintWriter(System.out);  \n    //Global variables and functions\n    static int code(int x,int y) {\n    \treturn 505*x+y;\n    }\n    static class pair{\n    \tint x,y;\n    \tpair(int a,int b){\n    \t\tthis.x=a;\n    \t\tthis.y=b;\n    \t}\n    \tpublic boolean equals(Object obj) {\n    \t\tif(obj == null || obj.getClass()!= this.getClass()) return false;\n            pair p = (pair) obj;\n            return (this.x==p.x && this.y==p.y);\n        }\n    \tpublic int hashCode() {\n            return Objects.hash(x,y);\n        }\n    }\n    static int hor[][],ver[][];\n    static int moves[][]= {{-1,0},{1,0},{0,-1},{0,1}};\n    static int n,m;\n    static int dp[][][];\n    static int solve(int x,int y,int k) {\n    \tif(k==0) {\n    \t\treturn 0;\n    \t}\n    \tif(dp[x][y][k]!=0) return dp[x][y][k];\n    \tint min=(int)MOD;\n    \tfor(int mo[]: moves) {\n\t\t\tint X=x+mo[0],Y=y+mo[1];\n\t\t\tif(X<0 || X>=n || Y<0 || Y>=m) continue;\n\t\t\tint val=0;\n\t\t\tif(mo[0]==1) val=ver[x][y];\n\t\t\telse if(mo[0]==-1) val=ver[x-1][y];\n\t\t\telse if(mo[1]==1) val=hor[x][y];\n\t\t\telse val=hor[x][y-1];\n\t\t\tmin=Math.min(min, 2*val+solve(X,Y,k-2));\n\t\t}\n    \treturn dp[x][y][k]=min;\n    }\n    //Main function(The main code starts from here)\n    public static void main (String[] args) throws java.lang.Exception {\n    \tint test=1;\n    \t//test=sc.nextInt();\n    \twhile(test-->0) {\n    \t\tn=sc.nextInt();m=sc.nextInt();\n    \t\tint k=sc.nextInt();\n    \t\tif(k%2!=0) {\n    \t\t\tfor(int i=0;i<n;i++) {\n    \t\t\t\tfor(int j=0;j<m;j++) out.print(-1+\" \");\n    \t\t\t\tout.println();\n    \t\t\t}\n    \t\t\tcontinue;\n    \t\t}\n    \t\thor=new int[n][m-1];\n    \t\tver=new int[n-1][m];\n    \t\tfor(int i=0;i<n;i++) {\n    \t\t\tfor(int j=0;j<m-1;j++) {\n    \t\t\t\thor[i][j]=sc.nextInt();\n    \t\t\t}\n    \t\t}\n    \t\tfor(int i=0;i<n-1;i++) {\n    \t\t\tfor(int j=0;j<m;j++) {\n    \t\t\t\tver[i][j]=sc.nextInt();\n    \t\t\t}\n    \t\t}\n    \t\tdp=new int[n][m][k+1];\n    \t\tfor(int i=0;i<n;i++) {\n    \t\t\tfor(int j=0;j<m;j++) {\n    \t\t\t\tout.print(solve(i,j,k)+\" \");\n    \t\t\t}\n    \t\t\tout.println();\n    \t\t}\n    \t\t\n    \t}\n        out.flush();\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "//created by Whiplash99\nimport java.io.*;\nimport java.util.*;\npublic class D\n{\n    private static ArrayDeque<Integer>[][] edge;\n    private static long[][] dp[],w1,w2;\n    private static int N,M,K;\n\n    private static void answer()\n    {\n        StringBuilder sb=new StringBuilder();\n        for(int i=0;i<N;i++)\n        {\n            for (int j = 0; j < M; j++) sb.append(dp[i][j][K]).append(\" \");\n            sb.append(\"\\n\");\n        }\n        System.out.println(sb);\n    }\n    private static long solve(int i, int j, int pos)\n    {\n        if(pos==0) return 0;\n        if(dp[i][j][pos]!=-1) return dp[i][j][pos];\n\n        long a=Long.MAX_VALUE/100;\n        if(i-1>=0) a=Math.min(a,solve(i-1,j,pos-1)+w2[i-1][j]);\n        if(i<N-1) a=Math.min(a,solve(i+1,j,pos-1)+w2[i][j]);\n        if(j-1>=0) a=Math.min(a,solve(i,j-1,pos-1)+w1[i][j-1]);\n        if(j<M-1) a=Math.min(a,solve(i,j+1,pos-1)+w1[i][j]);\n\n        return dp[i][j][pos]=a;\n    }\n    public static void main(String[] args) throws Exception\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n        int i;\n\n        String[] s=br.readLine().trim().split(\" \");\n        N=Integer.parseInt(s[0]);\n        M=Integer.parseInt(s[1]);\n        K=Integer.parseInt(s[2]);\n\n        edge=new ArrayDeque[N][M];\n        for(i=0;i<N;i++)\n        {\n            for(int j=0;j<M;j++)\n                edge[i][j]=new ArrayDeque<>();\n        }\n\n        w1=new long[N][M-1];\n        w2=new long[N-1][M];\n        dp=new long[N][M][K/2+1];\n\n        for(i=0;i<N;i++)\n        {\n            s=br.readLine().trim().split(\" \");\n            for(int j=0;j<M-1;j++) w1[i][j]=Integer.parseInt(s[j])*2L;\n        }\n        for(i=0;i<N-1;i++)\n        {\n            s=br.readLine().trim().split(\" \");\n            for(int j=0;j<M;j++) w2[i][j]=Integer.parseInt(s[j])*2L;\n        }\n\n        for(i=0;i<N;i++)\n        {\n            for(int j=0;j<M;j++)\n                Arrays.fill(dp[i][j],-1);\n        }\n\n        if(K%2==1)\n        {\n            K/=2;\n            answer();\n            System.exit(0);\n        }\n\n        K/=2;\n        for(i=0;i<N;i++)\n        {\n            for(int j=0;j<M;j++)\n                solve(i,j,K);\n        }\n\n        answer();\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main\n\n{ \n\t static FastReader sc=new FastReader(); \n\t static long dp[][][];\n\t static int mod=1000000007;\n\t \n\t  public static void main(String[] args)  throws IOException\n{\n\t\t    //CHECK FOR N=1\n       \t//CHECK FOR N=1\n\t    //CHECK FOR N=1\t\t\t\n       \t//CHECK FOR N=1\n\t\t  \n\t\t  \n\t\t  \n\t\t   PrintWriter out=new PrintWriter(System.out);\n\t\t  // StringBuffer sb=new StringBuffer(\"\");\n\t\t  int ttt=1;\n\t\t//  ttt =i(); \t\n\t\t   \n\t        outer :while (ttt-- > 0) \n\t\t\t{\n\n\t        \tint n=i();\n\t        \tint m=i();\n\t        \tint k=i();\n\t        \tint A[][]=input(n,m-1);\n\t        \tint B[][]=input(n-1, m);\n\t        \tdp=new long[n+1][m+1][k+1];\n\t        \tfor(int ii=0;ii<n;ii++) {\n\t        \t\tfor(int jj=0;jj<m;jj++) {\n\t        \t\t\tArrays.fill(dp[ii][jj],-1);\n\t        \t\t}\n\t        \t}\n\t        \tif(k%2!=0) {\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\tSystem.out.print(\"-1 \");\n\t        \t\t\t}\n\t        \t\t\tSystem.out.println();\n\t        \t\t}\n\t        \t}\n\t        \telse {\n\t        \tgo(A, B, 0, 0, k/2, 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\tSystem.out.print(dp[i][j][k/2]*2+\" \");\n        \t\t\t}\n        \t\t\tSystem.out.println();\n        \t\t}\n\t        \t}\n\t        \t\n\t\t\t}\n\t\t     out.close();\n    \t//System.out.println(sb.toString());\n\t     \n\t     \n\t    //CHECK FOR N=1                    //CHECK FOR M=0\n        //CHECK FOR N=1                    //CHECK FOR M=0\n       \t//CHECK FOR N=1\n       \t//CHECK FOR N=1\n       \t//CHECK FOR N=1\n\t\t        \t\n    }\n\t  static long go(int A[][],int B[][],int i,int j,int k,int l,int p) {\n\t\t if(k==0)\n\t\t\t return 0;\n\t\t if(i>=l || j>=p)\n\t\t\t return Integer.MAX_VALUE;\n\t\t  if(dp[i][j][k]!=-1)\n\t\t\t  return dp[i][j][k];\n//\t\t  if(i==m && j==n && k<org) {\n//\t\t\t  return Integer.MAX_VALUE;\n//\t\t  }\n\t\t  long op1=Long.MAX_VALUE;\n\t\t  if(i+1<l)\n\t\t  op1=Math.min(op1,go(A, B, i+1, j, k-1,l,p)+B[i][j]);\n\t\t  if(i-1>=0)\n\t\t op1=Math.min(op1,go(A, B, i-1, j, k-1,l,p)+B[i-1][j]);\n\t\t  if(j+1<p)\n\t\t  op1=Math.min(op1,go(A, B, i, j+1, k-1,l,p)+A[i][j]);\n\t\t  if(j-1>=0)\n\t\t   op1=Math.min(op1,go(A, B, i, j-1, k-1,l,p)+A[i][j-1]);\n\t\t  go(A, B, i+1, j, k, l, p);\n\t\t  go(A, B, i, j+1, k, l, p);\n\t\t  return dp[i][j][k]=op1;\n\t  }\n\t\t  \n\t\t  \n\t\t  \n\t\t\n\n\nstatic int[] input(int n) {\n\tint A[]=new int[n];\n\t   for(int i=0;i<n;i++) {\n\t\t   A[i]=sc.nextInt();\n\t   }\n\t   return A;\n   }\nstatic long[] inputL(int n) {\n\tlong A[]=new long[n];\n\t   for(int i=0;i<n;i++) {\n\t\t   A[i]=sc.nextLong();\n\t   }\n\t   return A;\n   }\nstatic String[] inputS(int n) {\n\tString A[]=new String[n];\n\t   for(int i=0;i<n;i++) {\n\t\t   A[i]=sc.next();\n\t   }\n\t   return A;\n   }\nstatic long sum(int A[]) {\n\tlong sum=0;\n\tfor(int i : A) {\n\t\tsum+=i;\n\t}\n\treturn sum;\n}\nstatic long sum(long A[]) {\n\tlong sum=0;\n\tfor(long i : A) {\n\t\tsum+=i;\n\t}\n\treturn sum;\n}\nstatic void reverse(long A[]) {\n\tint n=A.length;\n\tlong B[]=new long[n];\n\tfor(int i=0;i<n;i++) {\n\t\tB[i]=A[n-i-1];\n\t}\n\tfor(int i=0;i<n;i++)\n\t\tA[i]=B[i];\n\t\n}\nstatic void reverse(int A[]) {\n\tint n=A.length;\n\tint B[]=new int[n];\n\tfor(int i=0;i<n;i++) {\n\t\tB[i]=A[n-i-1];\n\t}\n\tfor(int i=0;i<n;i++)\n\t\tA[i]=B[i];\n\t\n}\nstatic void input(int A[],int B[]) {\n\t   for(int i=0;i<A.length;i++) {\n\t\t   A[i]=sc.nextInt();\n\t\t   B[i]=sc.nextInt();\n\t   }\n}\nstatic int[][] input(int n,int m){\n\tint A[][]=new int[n][m];\n\tfor(int i=0;i<n;i++) {\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tA[i][j]=i();\n\t\t}\n\t}\n\treturn A;\n}\nstatic char[][] charinput(int n,int m){\n\tchar A[][]=new char[n][m];\n\tfor(int i=0;i<n;i++) {\n\t\tString s=s();\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tA[i][j]=s.charAt(j);\n\t\t}\n\t}\n\treturn A;\n}\nstatic int max(int A[]) {\n\tint max=Integer.MIN_VALUE;\n\tfor(int i=0;i<A.length;i++) {\n\t\tmax=Math.max(max, A[i]);\n\t}\n\treturn max;\n}\nstatic int min(int A[]) {\n\tint min=Integer.MAX_VALUE;\n\tfor(int i=0;i<A.length;i++) {\n\t\tmin=Math.min(min, A[i]);\n\t}\n\treturn min;\n}\nstatic long max(long A[]) {\n\tlong max=Long.MIN_VALUE;\n\tfor(int i=0;i<A.length;i++) {\n\t\tmax=Math.max(max, A[i]);\n\t}\n\treturn max;\n}\nstatic long min(long A[]) {\n\tlong min=Long.MAX_VALUE;\n\tfor(int i=0;i<A.length;i++) {\n\t\tmin=Math.min(min, A[i]);\n\t}\n\treturn min;\n}\nstatic long [] prefix(long A[]) {\n\tlong p[]=new long[A.length];\n\tp[0]=A[0];\n\tfor(int i=1;i<A.length;i++)\n\t\tp[i]=p[i-1]+A[i];\n\treturn p;\n}\nstatic long [] prefix(int A[]) {\n\tlong p[]=new long[A.length];\n\tp[0]=A[0];\n\tfor(int i=1;i<A.length;i++)\n\t\tp[i]=p[i-1]+A[i];\n\treturn p;\n}\nstatic long [] suffix(long A[]) {\n\tlong p[]=new long[A.length];\n\tp[A.length-1]=A[A.length-1];\n\tfor(int i=A.length-2;i>=0;i--)\n\t\tp[i]=p[i+1]+A[i];\n\treturn p;\n}\nstatic long [] suffix(int A[]) {\n\tlong p[]=new long[A.length];\n\tp[A.length-1]=A[A.length-1];\n\tfor(int i=A.length-2;i>=0;i--)\n\t\tp[i]=p[i+1]+A[i];\n\treturn p;\n}\nstatic void print(int A[]) {\n\tfor(int i : A) {\n\t\tSystem.out.print(i+\" \");\n\t}\n\tSystem.out.println();\n}\nstatic void print(long A[]) {\n\tfor(long i : A) {\n\t\tSystem.out.print(i+\" \");\n\t}\n\tSystem.out.println();\n}\nstatic long mod(long x) {\n\t int mod=1000000007;\n\t  return ((x%mod + mod)%mod);\n}\nstatic String reverse(String s) {\n\tStringBuffer p=new StringBuffer(s);\n\tp.reverse();\n\treturn p.toString();\n}\n\n     static int i() {\n    \t return sc.nextInt();\n     }\n     static String s() {\n    \t return sc.next();\n     }\n     static long l() {\n    \t return sc.nextLong();\n     }  \n     static void sort(int[] A){\n        int n = A.length;\n        Random rnd = new Random();\n        for(int i=0; i<n; ++i){\n            int tmp = A[i];\n            int randomPos = i + rnd.nextInt(n-i);\n            A[i] = A[randomPos];\n            A[randomPos] = tmp;\n        }\n        Arrays.sort(A);\n     }\n     static void sort(long[] A){\n\t        int n = A.length;\n\t        Random rnd = new Random();\n\t        for(int i=0; i<n; ++i){\n\t            long tmp = A[i];\n\t            int randomPos = i + rnd.nextInt(n-i);\n\t            A[i] = A[randomPos];\n\t            A[randomPos] = tmp;\n\t        }\n\t        Arrays.sort(A);\n\t     }\n  static String sort(String s) {\n \t Character ch[]=new Character[s.length()];\n \t for(int i=0;i<s.length();i++) {\n \t\t ch[i]=s.charAt(i);\n \t }\n \t Arrays.sort(ch);\n \t StringBuffer st=new StringBuffer(\"\");\n \t for(int i=0;i<s.length();i++) {\n \t\t st.append(ch[i]);\n \t }\n \t return st.toString();\n  }\n  static HashMap<Integer,Integer> hash(int A[]){\n\t  HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();\n\t  for(int i : A) {\n\t\t  if(map.containsKey(i)) {\n\t\t\t  map.put(i, map.get(i)+1);\n\t\t  }\n\t\t  else {\n\t\t\t  map.put(i, 1);\n\t\t  }\n\t  }\n\t  return map;\n  }\n  static TreeMap<Integer,Integer> tree(int A[]){\n\t  TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();\n\t  for(int i : A) {\n\t\t  if(map.containsKey(i)) {\n\t\t\t  map.put(i, map.get(i)+1);\n\t\t  }\n\t\t  else {\n\t\t\t  map.put(i, 1);\n\t\t  }\n\t  }\n\t  return map;\n  }\n     static boolean prime(int n) \n\t    { \n\t        if (n <= 1) \n\t            return false; \n\t        if (n <= 3) \n\t            return true; \n\t        if (n % 2 == 0 || n % 3 == 0) \n\t            return false; \n\t        double sq=Math.sqrt(n);\n\t  \n\t        for (int i = 5; i <= sq; i = i + 6) \n\t            if (n % i == 0 || n % (i + 2) == 0) \n\t                return false; \n\t        return true; \n\t    } \n     static boolean prime(long n) \n\t    { \n\t        if (n <= 1) \n\t            return false; \n\t        if (n <= 3) \n\t            return true; \n\t        if (n % 2 == 0 || n % 3 == 0) \n\t            return false; \n\t        double sq=Math.sqrt(n);\n\t  \n\t        for (int i = 5; i <= sq; i = i + 6) \n\t            if (n % i == 0 || n % (i + 2) == 0) \n\t                return false; \n\t        return true; \n\t    } \n     static int gcd(int a, int b) \n     { \n         if (a == 0) \n             return b; \n         return gcd(b % a, a); \n     } \n     static long gcd(long a, long b) \n     { \n         if (a == 0) \n             return b; \n         return gcd(b % a, a); \n     } \n     static class Pair implements Comparable<Pair>\n     {\n    \t int x;\n    \t int y;\n    \t int z;\n    \t Pair(int x,int y,int z){\n    \t\t this.x=x;\n    \t\t this.y=y;\n    \t\t this.z=z;\n    \t }\n\t\t@Override\n//\t\tpublic int compareTo(Pair o) {\n//\t\t\tif(this.x>o.x)\n//\t\t\t\treturn 1;\n//\t\t\telse if(this.x<o.x)\n//\t\t\t\treturn -1;\n//\t\t\telse {\n//\t\t\t\tif(this.y>o.y)\n//\t\t\t\t\treturn 1;\n//\t\t\t\telse if(this.y<o.y)\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}\n\t\t\n\t\t\n\t\tpublic int compareTo(Pair o) {\n\t\t\tint p=this.x-this.y;\n\t\t\tint q=o.x-o.y;\n\t\tif(p>q)\n\t\t\treturn 1;\n\t\telse if(p<q)\n\t\t\treturn -1;\n\t\t\t\n\t\t\t\treturn 0;\n\t\t\n\t}\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\n\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class B{\n\tstatic int[][] hor;\n\tstatic int[][] ver;\n\tstatic int n;\n\tstatic int m;\n\tstatic int k;\n\tstatic long[][][] dp;\n\t\n\tstatic long dist(int row, int col)\n\t{\n\t\tif(k%2==1)return Integer.MAX_VALUE;\n\t\treturn 2*make(row,col,k/2);\n\t}\n\t\n\tstatic long make(int row, int col, int moves)\n\t{\n\t\tif(moves == 0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\tif(dp[row][col][moves]!=-1)return dp[row][col][moves];\n\t\t\n\t\tlong ans = Long.MAX_VALUE;\n\t\t\n\t\tif(col-1>=0)\n\t\t{\n\t\t\tans = Math.min(ans, hor[row][col-1]+make(row,col-1,moves-1));\n\t\t}\n\t\tif(col+1<m)\n\t\t{\n\t\t\tans = Math.min(ans, hor[row][col]+make(row,col+1,moves-1));\n\t\t}\n\t\tif(row-1>=0)\n\t\t{\n\t\t\tans = Math.min(ans, ver[row-1][col]+make(row-1,col,moves-1));\n\t\t}\n\t\tif(row+1<n)\n\t\t{\n\t\t\tans = Math.min(ans, ver[row][col]+make(row+1,col,moves-1));\n\t\t}\n\t\tdp[row][col][moves] = ans;\n\t\treturn ans;\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn = fs.nextInt(); m = fs.nextInt(); k = fs.nextInt();\n\t\thor = new int[n][m]; ver = new int[n][m];\n\t\tdp = new long[505][505][24];\n\t\tfor(int i=0;i<505;i++)for(int j=0;j<505;j++)for(int k=0;k<24;k++)dp[i][j][k] = -1;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int j=0;j<m-1;j++)\n\t\t\t{\n\t\t\t\tint a = fs.nextInt();\n\t\t\t\thor[i][j] = a;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int row=0;row<n-1;row++)\n\t\t{\n\t\t\tfor(int col =0;col<m;col++)\n\t\t\t{\n\t\t\t\tint a = fs.nextInt();\n\t\t\t\tver[row][col] = a;\n\t\t\t}\n\t\t}\n\n\t\t\n\t\tfor(int row=0;row<n;row++)\n\t\t{\n\t\t\tfor(int col=0;col<m;col++)\n\t\t\t{\n\t\t\t\tlong d = dist(row,col);\n\t\t\t\tif(d<Integer.MAX_VALUE)\n\t\t\t\t{\n\t\t\t\t\tout.print(d+\" \");\n\t\t\t\t}\n\t\t\t\telse out.print(\"-1 \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\tout.close();\n\t}\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\tpublic static int[] sort(int[] arr)\n\t{\n\t\tList<Integer> temp = new ArrayList();\n\t\tfor(int i:arr)temp.add(i);\n\t\tCollections.sort(temp);\n\t\tint start = 0;\n\t\tfor(int i:temp)arr[start++]=i;\n\t\treturn arr;\n\t}\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n/**\n *\n * @Har_Har_Mahadev\n */\n\npublic class D {\n\n\tprivate static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;\n\tprivate static int N = 0;\n\tprivate static long[][][] dp;\n\tprivate static long[][] ff;\n\tprivate static long[][] ss;\n\n\tpublic static void process() throws IOException {\n\n\t\tint n = sc.nextInt(),m = sc.nextInt(),k = sc.nextInt();\n\t\t\n\t\tff = new long[n][m];\n\t\tss = new long[n][m];\n\t\tfor(int i = 0; i<n; i++) {\n\t\t\tfor(int j = 0; j<m-1; j++) {\n\t\t\t\tff[i][j] = sc.nextLong();\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i<n-1; i++) {\n\t\t\tfor(int j = 0; j<m; j++) {\n\t\t\t\tss[i][j] = sc.nextLong();\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(k%2 == 1) {\n\t\t\tfor(int i = 0; i<n; i++) {\n\t\t\t\tfor(int j = 0; j<m; j++)System.out.print(-1+\" \");\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdp = new long[n+1][m+1][11];\n\t\tfor(int i = 0; i<=n; i++) {\n\t\t\tfor(int j = 0; j<=m; j++)Arrays.fill(dp[i][j], -1);\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\tdp[i][j][0] = 0;\n\t\t\t}\n\t\t}\n\t\t\n\t\tk/=2;\n\t\tlong ans[][] = new long[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\tans[i][j] = solve(i,j,k,n,m)*2L;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i<n; i++) {\n\t\t\tfor(int j = 0; j<m; j++)print(ans[i][j]+\" \");\n\t\t\tprintln();\n\t\t}\n\t}\n\n\tprivate static long solve(int i, int j, int k, int n, int m) {\n\t\tif(dp[i][j][k] != -1)return dp[i][j][k];\n\t\tlong ans = Long.MAX_VALUE;\n\t\tif(i+1<n) {\n\t\t\tans = min(ans,ss[i][j] + solve(i+1, j, k-1, n, m));\n\t\t}\n\t\tif(i-1>=0) {\n\t\t\tans = min(ans,ss[i-1][j] + solve(i-1, j, k-1, n, m));\n\t\t}\n\t\tif(j+1<m) {\n\t\t\tans = min(ans,ff[i][j] + solve(i, j+1, k-1, n, m));\n\t\t}\n\t\tif(j-1>=0) {\n\t\t\tans = min(ans,ff[i][j-1] + solve(i, j-1, k-1, n, m));\n\t\t}\n\t\t\n\t\treturn dp[i][j][k] = ans;\n\t}\n\n\t//=============================================================================\n\t//--------------------------The End---------------------------------\n\t//=============================================================================\n\n\tstatic FastScanner sc;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tboolean oj = true;\n\t\tif (oj) {\n\t\t\tsc = new FastScanner();\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tsc = new FastScanner(100);\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t\tint t = 1;\n//\t\tt = sc.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tprocess();\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint x, y;\n\n\t\tPair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn Integer.compare(this.x, o.x);\n\t\t}\n\n\t\t//\t\t @Override\n\t\t//\t\t    public boolean equals(Object o) {\n\t\t//\t\t        if (this == o) return true;\n\t\t//\t\t        if (!(o instanceof Pair)) return false;\n\t\t//\t\t        Pair key = (Pair) o;\n\t\t//\t\t        return x == key.x && y == key.y;\n\t\t//\t\t    }\n\t\t//\t\t \n\t\t//\t\t    @Override\n\t\t//\t\t    public int hashCode() {\n\t\t//\t\t        int result = x;\n\t\t//\t\t        result = 31 * result + y;\n\t\t//\t\t        return result;\n\t\t//\t\t    }\n\t}\n\n\t/////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic void println(Object o) {\n\t\tout.println(o);\n\t}\n\n\tstatic void println() {\n\t\tout.println();\n\t}\n\n\tstatic void print(Object o) {\n\t\tout.print(o);\n\t}\n\n\tstatic void pflush(Object o) {\n\t\tout.println(o);\n\t\tout.flush();\n\t}\n\n\tstatic int ceil(int x, int y) {\n\t\treturn (x % y == 0 ? x / y : (x / y + 1));\n\t}\n\n\tstatic long ceil(long x, long y) {\n\t\treturn (x % y == 0 ? x / y : (x / y + 1));\n\t}\n\n\tstatic int max(int x, int y) {\n\t\treturn Math.max(x, y);\n\t}\n\n\tstatic int min(int x, int y) {\n\t\treturn Math.min(x, y);\n\t}\n\n\tstatic int abs(int x) {\n\t\treturn Math.abs(x);\n\t}\n\n\tstatic long abs(long x) {\n\t\treturn Math.abs(x);\n\t}\n\n\tstatic long sqrt(long z) {\n\t\tlong sqz = (long) Math.sqrt(z);\n\t\twhile (sqz * 1L * sqz < z) {\n\t\t\tsqz++;\n\t\t}\n\t\twhile (sqz * 1L * sqz > z) {\n\t\t\tsqz--;\n\t\t}\n\t\treturn sqz;\n\t}\n\n\tstatic int log2(int N) {\n\t\tint result = (int) (Math.log(N) / Math.log(2));\n\t\treturn result;\n\t}\n\n\tstatic long max(long x, long y) {\n\t\treturn Math.max(x, y);\n\t}\n\n\tstatic long min(long x, long y) {\n\t\treturn Math.min(x, y);\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.intValue();\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.longValue();\n\t}\n\n\tpublic static long lcm(long a, long b) {\n\t\treturn (a * b) / gcd(a, b);\n\t}\n\n\tpublic static int lcm(int a, int b) {\n\t\treturn (a * b) / gcd(a, b);\n\t}\n\n\tpublic static int lower_bound(int[] arr, int x) {\n\t\tint low = 0, high = arr.length, mid = -1;\n\n\t\twhile (low < high) {\n\t\t\tmid = (low + high) / 2;\n\n\t\t\tif (arr[mid] >= x)\n\t\t\t\thigh = mid;\n\t\t\telse\n\t\t\t\tlow = mid + 1;\n\t\t}\n\n\t\treturn low;\n\t}\n\n\tpublic static int upper_bound(int[] arr, int x) {\n\t\tint low = 0, high = arr.length, mid = -1;\n\n\t\twhile (low < high) {\n\t\t\tmid = (low + high) / 2;\n\n\t\t\tif (arr[mid] > x)\n\t\t\t\thigh = mid;\n\t\t\telse\n\t\t\t\tlow = mid + 1;\n\t\t}\n\n\t\treturn low;\n\t}\n\n\t/////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner() throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tFastScanner(int a) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t}\n\n\t\tString next() throws IOException {\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() 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\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[] readArray(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] = sc.nextInt();\n\t\t\t}\n\t\t\treturn A;\n\t\t}\n\n\t\tlong[] readArrayLong(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] = sc.nextLong();\n\t\t\t}\n\t\t\treturn A;\n\t\t}\n\t}\n\n\tstatic void ruffleSort(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\tArrays.sort(a);\n\t}\n\n\tstatic void ruffleSort(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\tArrays.sort(a);\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\nimport java.io.*;\n\n\npublic class D {\n    \n    static int mod = (int) (1e9+7);\n    static InputReader in;\n    static PrintWriter out;\n    \n\n    static void solve()\n    {\n \n        in = new InputReader(System.in);\n        out = new PrintWriter(System.out); \n        \n        int t = 1;\n        \n        while(t-- > 0) {\n        \tint n = in.nextInt();\n        \tint m = in.nextInt();\n        \tint K = in.nextInt();\n        \t\n        \tlong[][] x = new long[n][];\n        \t\n        \tfor(int i = 0; i < n; i++) {\n        \t\tx[i] = in.nextLongArray(m - 1);\n        \t}\n        \t\n        \tlong[][] y = new long[n - 1][];\n        \tfor(int i = 0; i < n - 1; i++) {\n        \t\ty[i] = in.nextLongArray(m);\n        \t}\n        \t\n        \tif(K % 2 != 0) {\n            \tfor(int i = 0; i < n; i++) {\n            \t\tfor(int j = 0; j < m; j++) {\n            \t\t\tout.print(\"-1 \");\n            \t\t}\n            \t\tout.println();\n            \t}\n        \t\tcontinue;\n        \t}\n        \tK /= 2;\n        \t\n        \tlong[][][] dp = new long[K + 1][n][m];\n        \t\n        \tfor(int i = 0; i < n; i++) {\n        \t\tfor(int j = 0; j < m; j++) {\n        \t\t\tfor(int k = 1; k <= K; k++) {\n        \t\t\t\tdp[k][i][j] = Integer.MAX_VALUE;\n        \t\t\t}\n        \t\t}\n        \t}\n        \t\n        \tfor(int k = 1; k <= K; k++) {\n\t        \tfor(int i = 0; i < n; i++) {\n\t        \t\tfor(int j = 0; j < m; j++) {\n\t        \t\t\tif(i + 1 < n) {\n\t        \t\t\t\tdp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i + 1][j] + 2 * y[i][j]);\n\t        \t\t\t}\n\t        \t\t\tif(i - 1 >= 0) {\n\t        \t\t\t\tdp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i - 1][j] + 2 * y[i - 1][j]);\n\t        \t\t\t}\n\t        \t\t\tif(j + 1 < m) {\n\t        \t\t\t\tdp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i][j + 1] + 2 * x[i][j]);\n\t        \t\t\t}\n\t        \t\t\tif(j - 1 >= 0) {\n\t        \t\t\t\tdp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i][j - 1] + 2 * x[i][j - 1]);\n\t        \t\t\t}\n\t        \t\t}\n\t        \t}\n        \t}\n        \t\n        \tfor(int i = 0; i < n; i++) {\n        \t\tfor(int j = 0; j < m; j++) {\n        \t\t\tout.print(dp[K][i][j] + \" \");\n        \t\t}\n        \t\tout.println();\n        \t}\n        \t\n        }\n        \n        out.close();\n        \n    }\n    \n    public static void main(String[] args) {\n        new Thread(null ,new Runnable(){\n            public void run()\n            {\n                try{\n                    solve();\n                } catch(Exception e){\n                    e.printStackTrace();\n                }\n            }\n        },\"1\",1<<26).start();\n    }\n    \n    static int[][] graph(int from[], int to[], int n)\n    {\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++) {\n            g[i] = new int[cnt[i]];\n        }\n        Arrays.fill(cnt, 0);\n        for (int i = 0; i < from.length; i++) {\n            g[from[i]][cnt[from[i]]++] = to[i];\n            g[to[i]][cnt[to[i]]++] = from[i];\n        }\n        return g;\n    }\n    \n    static class Pair implements Comparable<Pair>{\n\n        int x,y,z;\n        \n\t\tPair (int x,int y,int z){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t\tthis.z=z;\n\t\t}\n\t        \n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (this.x == o.x)\n\t\t\t\treturn Integer.compare(this.y,o.y);\n\t\t\treturn Integer.compare(this.x,o.x);\n\t\t\t//return 0;\n\t\t}\n\n        public 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        @Override\n        public String toString() {\n        \treturn x + \" \" + y;\n        }\n    \n    } \n    \n    static String rev(String s) {\n        StringBuilder sb = new StringBuilder(s);\n        sb.reverse();\n        return sb.toString();\n    }\n\n    static long gcd(long x, long y) {\n        if (y == 0) {\n            return x;\n        } else {\n            return gcd(y, x % y);\n        }\n    }\n\n    static 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    static int abs(int a, int b) {\n        return (int) Math.abs(a - b);\n    }\n\n    static long abs(long a, long b) {\n        return (long) Math.abs(a - b);\n    }\n\n    static int max(int a, int b) {\n        if (a > b) {\n            return a;\n        } else {\n            return b;\n        }\n    }\n\n    static int min(int a, int b) {\n        if (a > b) {\n            return b;\n        } else {\n            return a;\n        }\n    }\n\n    static long max(long a, long b) {\n        if (a > b) {\n            return a;\n        } else {\n            return b;\n        }\n    }\n\n    static long min(long a, long b) {\n        if (a > b) {\n            return b;\n        } else {\n            return a;\n        }\n    }\n\n    static long pow(long n, long p, long m) {\n        long result = 1;\n        if (p == 0) {\n            return 1;\n        }\n        while (p != 0) {\n            if (p % 2 == 1) {\n                result *= n;\n            }\n            if (result >= m) {\n                result %= m;\n            }\n            p >>= 1;\n            n *= n;\n            if (n >= m) {\n                n %= m;\n            }\n        }\n        return result;\n    }\n\n    static long pow(long n, long p) {\n        long result = 1;\n        if (p == 0) {\n            return 1;\n        }\n        if (p == 1) {\n            return n;\n        }\n        while (p != 0) {\n            if (p % 2 == 1) {\n                result *= n;\n            }\n            p >>= 1;\n            n *= n;\n        }\n        return result;\n    }\n   \n    static void debug(Object... o) {\n            System.out.println(Arrays.deepToString(o));\n    }\n\n    static class InputReader\n    {\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        {\n                this.stream = stream;\n        }\n\n        public int snext()\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 = 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                {\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                {\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        public String readString()\n        {\n                int c = snext();\n                while (isSpaceChar(c))\n                {\n                        c = snext();\n                }\n                StringBuilder res = new StringBuilder();\n                do\n                {\n                        res.appendCodePoint(c);\n                        c = snext();\n                } while (!isSpaceChar(c));\n                return res.toString();\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                {\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\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main {\n    public static void main(String args[])\n    {\n        FastReader input=new FastReader();\n        PrintWriter out=new PrintWriter(System.out);\n        int T=1;\n        while(T-->0)\n        {\n            int n=input.nextInt();\n            int m=input.nextInt();\n            int k=input.nextInt();\n            int arr1[][]=new int[n+1][m];\n            for(int i=1;i<=n;i++)\n            {\n                for(int j=1;j<m;j++)\n                {\n                    arr1[i][j]=input.nextInt();\n                }\n            }\n            int arr2[][]=new int[n][m+1];\n            for(int i=1;i<n;i++)\n            {\n                for(int j=1;j<=m;j++)\n                {\n                    arr2[i][j]=input.nextInt();\n                }\n            }\n            if(k%2==0)\n            {\n                int dp[][][]=new int[n+1][m+1][k+1];\n                for(int l=2;l<=k;l+=2)\n                {\n                    for(int i=1;i<=n;i++)\n                    {\n                        for(int j=1;j<=m;j++)\n                        {\n                            int min=Integer.MAX_VALUE;\n                            if(j+1<=m)\n                            {\n                                min=Math.min(min,dp[i][j+1][l-2]+2*arr1[i][j]);\n                            }\n                            if(i+1<=n)\n                            {\n                                min=Math.min(min,dp[i+1][j][l-2]+2*arr2[i][j]);\n                            }\n                            if(j-1>=1)\n                            {\n                                min=Math.min(min,dp[i][j-1][l-2]+2*arr1[i][j-1]);\n                            }\n                            if(i-1>=1)\n                            {\n                                min=Math.min(min,dp[i-1][j][l-2]+2*arr2[i-1][j]);\n                            }\n                            dp[i][j][l]=min;\n                        }\n                    }\n                }\n                for(int i=1;i<=n;i++)\n                {\n                    for(int j=1;j<=m;j++)\n                    {\n                        out.print(dp[i][j][k]+\" \");\n                    }\n                    out.println();\n                }\n            }\n            else\n            {\n                for(int i=1;i<=n;i++)\n                {\n                    for(int j=1;j<=m;j++)\n                    {\n                        out.print(-1+\" \");\n                    }\n                    out.println();\n                }\n            }\n        }\n        out.close();\n    }\n    static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastReader()\n        {\n            br = new BufferedReader(new 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        int nextInt()\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong()\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble()\n        {\n            return Double.parseDouble(next());\n        }\n        String nextLine()\n        {\n            String str=\"\";\n            try\n            {\n                str=br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n// Created by @thesupremeone on 23/04/21\npublic class ExplorerSpace {\n    int[][] horizontal, vertical;\n    int n, m;\n    long[][][] dp;\n    int large = Integer.MAX_VALUE;\n\n    boolean isValid(int i, int j){\n        return i>=0 && j>=0 && i<n && j<m;\n    }\n\n    long getMin(int i, int j, int k){\n        if(k==0)\n            return 0;\n        if(dp[i][j][k]!=-1)\n            return dp[i][j][k];\n        long ans = large;\n        for (int a = 0; a < 2; a++) {\n            for (int d = 0; d < 2; d++) {\n                int dx = a==0 ? (d==0 ? +1 : -1) : 0;\n                int dy = a==1 ? (d==0 ? +1 : -1) : 0;\n                int x = i+dx;\n                int y = j+dy;\n                if(isValid(x, y)){\n                    if(dx==0){\n                        ans = Math.min(horizontal[i][Math.min(j, y)]+getMin(x, y, k-1), ans);\n                    }else {\n                        ans = Math.min(vertical[Math.min(i, x)][j]+getMin(x, y, k-1), ans);\n                    }\n                }\n            }\n        }\n        dp[i][j][k] = ans;\n        return ans;\n    }\n\n    void solve() throws IOException {\n        n = getInt();\n        m = getInt();\n        dp = new long[n+1][m+1][11];\n        for (int i = 0; i < n+1; i++) {\n            for (int j = 0; j < m+1; j++) {\n                for (int k = 0; k < 11; k++) {\n                    dp[i][j][k] = -1;\n                }\n            }\n        }\n        int k = getInt();\n        horizontal = new int[n][m-1];\n        vertical = new int[n-1][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m - 1; j++) {\n                horizontal[i][j] = getInt();\n            }\n        }\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = 0; j < m; j++) {\n                vertical[i][j] = getInt();\n            }\n        }\n        if(k%2!=0){\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    print(\"-1 \");\n                }\n                println(\"\");\n            }\n        }else {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    long ans = 2*getMin(i, j, k/2);\n                    print(ans+\" \");\n                }\n                println(\"\");\n            }\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        if (isOnlineJudge()) {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            out = new BufferedWriter(new OutputStreamWriter(System.out));\n            new ExplorerSpace().solve();\n            out.flush();\n        } else {\n            Thread judge = new Thread();\n            in = new BufferedReader(new FileReader(\"input.txt\"));\n            out = new BufferedWriter(new FileWriter(\"output.txt\"));\n            judge.start();\n            new ExplorerSpace().solve();\n            out.flush();\n            judge.suspend();\n        }\n    }\n    static boolean isOnlineJudge(){\n        try {\n            return System.getProperty(\"ONLINE_JUDGE\")!=null\n                    || System.getProperty(\"LOCAL\")==null;\n        }catch (Exception e){\n            return true;\n        }\n    }\n    // Fast Input & Output\n    static BufferedReader in;\n    static StringTokenizer st;\n    static BufferedWriter out;\n    static String getLine() throws IOException{\n        return in.readLine();\n    }\n    static String getToken() throws IOException{\n        if(st==null || !st.hasMoreTokens())\n            st = new StringTokenizer(getLine());\n        return st.nextToken();\n    }\n    static int getInt() throws IOException {\n        return Integer.parseInt(getToken());\n    }\n    static long getLong() throws IOException {\n        return Long.parseLong(getToken());\n    }\n    static void print(Object s) throws IOException{\n        out.write(String.valueOf(s));\n    }\n    static void println(Object s) throws IOException{\n        out.write(String.valueOf(s));\n        out.newLine();\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "// package com.company.codeforces;\n\n\n\n\nimport java.util.*;\n\npublic class  Solution {\n   static int n,m,h[][],v[][];\n    public static void main(String[] args) {\n        Scanner input=new Scanner(System.in);\n\n            n=input.nextInt();\n            m=input.nextInt();\n           int k=input.nextInt();\n           h=new int[n][m-1];\n            for (int i = 0; i <n ; i++) {\n                for (int j = 0; j <m-1 ; j++) {\n                    h[i][j]=input.nextInt();\n                }\n            }\n            v=new int[n][m];\n            for (int i = 0; i <n-1 ; i++) {\n                for (int j = 0; j <m ; j++) {\n                    v[i][j]=input.nextInt();\n                }\n            }\n            int ans[][]=new int[n][m];\n           dp=new int[501][501][11];\n        for (int aa[]:ans\n             ) { Arrays.fill(aa,-1);\n\n        }\n        if (k%2==0) {\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    ans[i][j] = dfs(i, j, k / 2) * 2;\n                }\n\n            }\n        }\n        for (int i = 0; i <n ; i++) {\n            for (int j = 0; j <m ; j++) {\n                System.out.print(ans[i][j]+\" \");\n            }\n            System.out.println();\n\n        }\n\n    }\n    static int dp[][][];\n\n    private static int dfs(int i, int j, int k) {\n        if (k==0) return 0;\n        if (dp[i][j][k]!=0){\n//            System.out.println(\"hit\");\n            return dp[i][j][k];\n        }\n        //left\n        int ans=Integer.MAX_VALUE;\n        if (j-1>=0)\n         ans=dfs(i, j-1, k-1)+h[i][j-1];\n        if (i<n-1)\n        ans=Math.min(ans,dfs(i+1, j, k-1)+v[i][j]);\n        if (i>0)\n        ans=Math.min(ans,dfs(i-1, j, k-1)+v[i-1][j]);\n        if (j<m-1)\n        ans=Math.min(ans,dfs(i, j+1, k-1)+h[i][j]);\n\n        return dp[i][j][k]= ans;\n\n    }\n\n\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "//package Codeforces.Round718Div1_2;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class D {\n    static boolean isValid(int n, int m, int i, int j){\n        return 0<=i && i<n && 0<=j && j<m;\n    }\n    public static void main(String[] args) throws IOException {\n        Soumit sc = new Soumit();\n\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n\n        StringBuilder sb = new StringBuilder();\n        if(k%2==1){\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m;j++){\n                    sb.append(\"-1 \");\n                }\n                sb.append(\"\\n\");\n            }\n            System.out.println(sb);\n            System.exit(0);\n        }\n\n        k/=2;\n\n        long[][] horizontaledge = new long[n][m-1];\n        long[][] verticaledge = new long[n-1][m];\n        for(int i=0;i<n;i++)\n            horizontaledge[i] = sc.nextLongArray(m-1);\n        for(int i=0;i<n-1;i++)\n            verticaledge[i] = sc.nextLongArray(m);\n\n        long[][][] dp = new long[11][n][m];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                dp[0][i][j] = 0;\n            }\n        }\n        for(int i=1;i<=k;i++){\n            for(int j1=0;j1<n;j1++){\n                for(int j2=0;j2<m;j2++){\n                    long min = Long.MAX_VALUE/2000;\n                    //for up\n                    if(isValid(n, m, j1-1, j2)){\n                        min = Math.min(dp[i-1][j1-1][j2]+verticaledge[j1-1][j2], min);\n                    }\n\n                    //for down\n                    if(isValid(n, m, j1+1, j2)){\n                        min = Math.min(min, dp[i-1][j1+1][j2]+verticaledge[j1][j2]);\n                    }\n\n                    //for left\n                    if(isValid(n, m, j1, j2-1)){\n                        min = Math.min(min, dp[i-1][j1][j2-1]+horizontaledge[j1][j2-1]);\n                    }\n\n                    //for right\n                    if(isValid(n, m, j1, j2+1)){\n                        min = Math.min(min, dp[i-1][j1][j2+1]+horizontaledge[j1][j2]);\n                    }\n\n                    dp[i][j1][j2] = min;\n                }\n            }\n        }\n\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                sb.append(dp[k][i][j]*2).append(\" \");\n            }\n            sb.append(\"\\n\");\n        }\n\n        System.out.println(sb);\n\n        sc.close();\n    }\n\n    static class Soumit {\n        final private int BUFFER_SIZE = 1 << 18;\n        final private DataInputStream din;\n        final private byte[] buffer;\n        private PrintWriter pw;\n        private int bufferPointer, bytesRead;\n        StringTokenizer st;\n\n        public Soumit() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public Soumit(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 void streamOutput(String file) throws IOException {\n            FileWriter fw = new FileWriter(file);\n            BufferedWriter bw = new BufferedWriter(fw);\n            pw = new PrintWriter(bw);\n        }\n\n        public void println(String a) {\n            pw.println(a);\n        }\n\n        public void print(String a) {\n            pw.print(a);\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[3000064]; // 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        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public void sort(int[] arr) {\n            ArrayList<Integer> arlist = new ArrayList<>();\n            for (int i : arr)\n                arlist.add(i);\n\n            Collections.sort(arlist);\n            for (int i = 0; i < arr.length; i++)\n                arr[i] = arlist.get(i);\n        }\n\n        public void sort(long[] arr) {\n            ArrayList<Long> arlist = new ArrayList<>();\n            for (long i : arr)\n                arlist.add(i);\n\n            Collections.sort(arlist);\n            for (int i = 0; i < arr.length; i++)\n                arr[i] = arlist.get(i);\n        }\n\n        public int[] nextIntArray(int n) throws IOException {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n\n            return arr;\n        }\n\n        public long[] nextLongArray(int n) throws IOException {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n\n            return arr;\n        }\n\n        public double[] nextDoubleArray(int n) throws IOException {\n            double[] arr = new double[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextDouble();\n            }\n\n            return arr;\n        }\n\n        public int nextInt() throws IOException {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public long nextLong() throws IOException {\n            long ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public double nextDouble() throws IOException {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n\n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        private void fillBuffer() throws IOException {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n            if (bytesRead == -1)\n                buffer[0] = -1;\n        }\n\n        private byte read() throws IOException {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n\n        public void close() throws IOException {\n            /*if (din == null)\n                return;*/\n            if (din != null) din.close();\n            if (pw != null) pw.close();\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "//Template with FastScanner\n\n// jzzhao\n\nimport java.util.*;\nimport java.io.*;\n\npublic class Solution {\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n       \n        //int tc = sc.ni();\n        int tc = 1;\n        for (int rep = 0; rep < tc; rep++) {\n            solve(sc,pw);\n            //pw.println(solve(sc,pw));\n           \n        }\n        \n        \n        pw.close();\n    }\n    /*\n\n    FS Methods:\n\n    - next(): next element in string\n    - nextLine(): nextline in string\n    - ni(): next Integer\n    - nd(): next Double\n    - nl(): next Long\n    - intArray(n): \n    - longArray(n): \n    - to2di(m,n):\n    - to2dl(m,n):\n\n\n\n    */\n\n          \n    public static void solve(FastScanner sc, PrintWriter pw) {\n\n        int n = sc.ni();\n        int m = sc.ni();\n        int k = sc.ni();\n\n        int[][] arr = sc.to2di(n,m-1); \n        int[][] arr2 = sc.to2di(n-1,m); \n        \n        if(k%2==1){\n            String s =\"\";\n            for(int j = 0;j<m;j++){\n                s+=\"-1\";\n                if(j!=m-1){\n                    s+=\" \";\n                }\n            }\n            for(int i = 0;i<n;i++){\n                pw.println(s);\n            }\n            return;\n        }\n\n        \n        Integer[][][] dp = new Integer[n][m][k+1];\n\n        // edge info\n        // for(int i= 0;i<n;i++){\n        //     for(int j = 0;j<m-1;j++){\n                \n        //         int l = i*1000+j;\n        //         int r = i*1000+j+1;\n        //         String cur = l+\" \"+r;\n        //         String cur2 = r+\" \"+l;\n        //         map.put(cur,arr[i][j]);\n        //         map.put(cur2,arr[i][j]);\n                \n        //     }\n        // }\n\n        // for(int i= 0;i<n-1;i++){\n        //     for(int j = 0;j<m;j++){\n                \n        //         int l = i*1000+j;\n        //         int r = (i+1)*1000+j;\n        //         String cur = l+\" \"+r;\n        //         String cur2 = r+\" \"+l;\n        //         map.put(cur,arr2[i][j]);\n        //         map.put(cur2,arr2[i][j]);\n                \n        //     }\n        // }\n\n        //dp fill\n\n        for(int i= 0;i<n;i++){\n            for(int j = 0;j<m;j++){\n                \n                fill(dp,i,j,k,n,m,arr,arr2);\n                \n            }\n        }\n\n        for(int i= 0;i<n;i++){\n            String s = \"\";\n            for(int j = 0;j<m;j++){\n                \n                s+=dp[i][j][k];\n                if(j!=m-1){\n                    s+=\" \";\n                }\n                \n            }\n            pw.println(s);\n        }\n\n        \n\n\n\n    }\n\n    public static int fill(Integer[][][] dp, int x, int y, int k, int n,int m,int[][] arr, int[][] arr2){\n        \n        \n\n        if(dp[x][y][k]!=null){\n            return dp[x][y][k];\n        }\n\n        if(k==0){\n            dp[x][y][k]= 0;\n            return 0;\n        }\n\n        int min = Integer.MAX_VALUE;\n\n        \n\n        if(x>0){\n            \n\n            int curVal = 2*arr2[x-1][y]+fill(dp,x-1,y,k-2,n,m,arr,arr2);\n            min = Math.min(min,curVal);\n        }\n\n        if(y>0){\n            \n            int curVal = 2*arr[x][y-1]+fill(dp,x,y-1,k-2,n,m,arr,arr2);\n            min = Math.min(min,curVal);\n        }\n\n        if(x<n-1){\n            \n            int curVal = 2*arr2[x][y]+fill(dp,x+1,y,k-2,n,m,arr,arr2);\n            min = Math.min(min,curVal);\n        }\n\n        if(y<m-1){\n            \n            int curVal = 2*arr[x][y]+fill(dp,x,y+1,k-2,n,m,arr,arr2);\n            min = Math.min(min,curVal);\n        }\n\n        dp[x][y][k]=min;\n        return min;\n\n\n    }\n\n    \n\n    /*\n        - The following are helping method so pls do not do anything to them.\n    \n    */\n\n    // public static int[][] to2d(Scanner scanner, int m, int n){\n    //     int[][] ans = new int[m][n];\n    //     for(int i = 0;i<m;i++){\n    //         String[] r = scanner.nextLine().split(\"[ ]\");\n    //         for(int j = 0;j<n;j++){\n    //             ans[i][j] = stoi(r[j]);\n    //         }\n    //     }\n    //     return ans;\n    // }\n\n    // public static int[] toArray(Scanner scanner, int m){\n    //     int[] ans = new int[m];\n    //     String[] r = scanner.nextLine().split(\"[ ]\");\n    //     for(int i = 0;i<m;i++){\n    //         ans[i] = stoi(r[i]);\n    //     }\n        \n    //     return ans;\n    // }\n\n    public static void printArr(PrintWriter pw,int[] a){\n        for(int i = 0;i<a.length;i++){\n            pw.print(a[i]);\n            if(i!=a.length-1){\n                pw.print(\" \");\n            }\n        }\n        pw.println();\n    }\n\n    public static void print2d(PrintWriter pw,int[][] a){\n        for(int j=0;j<a.length;j++){\n            for(int i = 0;i<a[j].length;i++){\n                pw.print(a[j][i]);\n                if(i!=a[j].length-1){\n                    pw.print(\" \");\n                }\n            }\n            pw.println(\" \");\n        }\n        pw.println();\n    }\n\n    public static int stoi(String s){\n        return Integer.parseInt(s);\n    }\n}\n\nclass FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n \n    public FastScanner() {\n        br = new BufferedReader(new InputStreamReader(System.in), 32768);\n        st = null;\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        }\n        return st.nextToken();\n    }\n \n    int ni() {\n        return Integer.parseInt(next());\n    }\n \n    int[] intArray(int N) {\n        int[] ret = new int[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = ni();\n        return ret;\n    }\n\n    int[][] to2di(int m, int n){\n        int[][] ans = new int[m][n];\n        for(int i = 0;i<m;i++){\n            String[] r = nextLine().split(\"[ ]\");\n            for(int j = 0;j<n;j++){\n                ans[i][j] = Integer.parseInt(r[j]);\n            }\n        }\n        return ans;\n    }\n\n    long[][] to2dl(int m, int n){\n        long[][] ans = new long[m][n];\n        for(int i = 0;i<m;i++){\n            String[] r = nextLine().split(\"[ ]\");\n            for(int j = 0;j<n;j++){\n                ans[i][j] = Long.parseLong(r[j]);\n            }\n        }\n        return ans;\n    }\n \n    long nl() {\n        return Long.parseLong(next());\n    }\n \n    long[] longArray(int N) {\n        long[] ret = new long[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = nl();\n        return ret;\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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tstatic int[][][]memo;\n\tstatic int inf=(int)1e9;\n\tstatic int n,m,down[][],right[][];\n\tstatic int dp(int i,int j,int k) {\n\t\tif(k<=0)return 0;\n\t\tif(memo[i][j][k]!=-1)return memo[i][j][k];\n\t\tint ans=inf;\n\t\tif(i+1<n) {\n\t\t\tans=Math.min(ans, down[i][j]+dp(i+1, j, k-1));\n\t\t}\n\n\t\tif(i-1>=0) {\n\t\t\tans=Math.min(ans, down[i-1][j]+dp(i-1, j, k-1));\n\t\t}\n\n\t\tif(j+1<m) {\n\t\t\tans=Math.min(ans, right[i][j]+dp(i, j+1, k-1));\n\t\t}\n\n\t\tif(j-1>=0) {\n\t\t\tans=Math.min(ans, right[i][j-1]+dp(i, j-1, k-1));\n\t\t}\n\t\treturn memo[i][j][k]=ans;\n\t}\n\tstatic void main() throws Exception{\n\t\tn=sc.nextInt();m=sc.nextInt();int k=sc.nextInt();\n\t\tif((k&1)==1) {\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\tpw.print((-1)+\" \");\n\t\t\t\t}\n\t\t\t\tpw.println();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tk>>=1;\n\t\tright=new int[n][];\n\t\tdown=new int[n-1][];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tright[i]=sc.intArr(m-1);\n\t\t}\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\tdown[i]=sc.intArr(m);\n\t\t}\n\t\tmemo = new int[n][m][k+1];\n\t\tint inf=(int)1e9;\n\t\tfor(int i=0;i<=k;i++) {\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tfor(int o=0;o<m;o++) {\n\t\t\t\t\tmemo[j][o][i]=-1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\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\tpw.print((dp(i, j, k)<<1)+\" \");\n\t\t\t}\n\t\t\tpw.println();\n\t\t}\n    }\n    public static void main(String[] args) throws Exception{\n    \tsc=new MScanner(System.in);\n    \tpw = new PrintWriter(System.out);\n        int tc=1;\n//        tc=sc.nextInt();\n        for(int i=1;i<=tc;i++) {\n//            pw.printf(\"Case #%d:\", i);\n            main();\n        }\n        pw.flush();\n    }\n    static PrintWriter pw;\n    static MScanner sc;\n    static class MScanner {\n        StringTokenizer st;\n        BufferedReader br;\n        public MScanner(InputStream system) {\n            br = new BufferedReader(new InputStreamReader(system));\n        }\n     \n        public MScanner(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        public int[] intArr(int n) throws IOException {\n            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n            return in;\n        }\n        public long[] longArr(int n) throws IOException {\n            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n            return in;\n        }\n        public int[] intSortedArr(int n) throws IOException {\n            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n            shuffle(in);\n            Arrays.sort(in);\n            return in;\n        }\n        public long[] longSortedArr(int n) throws IOException {\n            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n            shuffle(in);\n            Arrays.sort(in);\n            return in;\n        }\n        public Integer[] IntegerArr(int n) throws IOException {\n            Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();\n            return in;\n        }\n        public Long[] LongArr(int n) throws IOException {\n            Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n            return in;\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    static void sort(int[]in) {\n    \tshuffle(in);\n        Arrays.sort(in);\n    }\n    static void sort(long[]in) {\n    \tshuffle(in);\n        Arrays.sort(in);\n    }\n    static void shuffle(int[]in) {\n        for(int i=0;i<in.length;i++) {\n            int idx=(int)(Math.random()*in.length);\n            int tmp=in[i];\n            in[i]=in[idx];\n            in[idx]=tmp;\n        }\n    }\n    static void shuffle(long[]in) {\n        for(int i=0;i<in.length;i++) {\n            int idx=(int)(Math.random()*in.length);\n            long tmp=in[i];\n            in[i]=in[idx];\n            in[idx]=tmp;\n        }\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic PrintWriter out;\n\tstatic Reader in;\n\tpublic static void main(String[] args) throws IOException {\n\t\tinput_output();\n\t\tMain solver = new Main();\n\t\tsolver.solve();\n\t\tout.close();\n\t\tout.flush();\n\t}\n\n\tstatic int INF = (int)1e9;\n\tstatic int MAXN = (int)4e5 + 5;\n\tstatic int MOD = (int)1e9+7;\n\tstatic int q, t, n, m, k;\n\tstatic double pi = Math.PI;\n\n\tvoid solve() throws IOException {\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tk = in.nextInt();\n\n\t\tint[][] right = new int[n][m],\n\t\t\t    left = new int[n][m],\n\t\t\t    up = new int[n][m],\n\t\t\t    down = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m-1; j++) {\n\t\t\t\tright[i][j] = in.nextInt();\n\t\t\t\tleft[i][j+1] = right[i][j];\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n-1; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tdown[i][j] = in.nextInt();\n\t\t\t\tup[i+1][j] = down[i][j];\n\t\t\t}\n\t\t}\n\n\t\tif (k%2 == 1) {\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\tout.print(\"-1 \");\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tint[][][] dp = new int[n][m][k+1];\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 kk = 1; kk <= k; kk++) {\n\t\t\t\t\tdp[i][j][kk] = INF;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int step = 2; step <= k; step+=2) {\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\tif (i != 0) {\n\t\t\t\t\t\tdp[i][j][step] = Math.min(dp[i][j][step], dp[i-1][j][step-2]+up[i][j]*2);\n\t\t\t\t\t}\n\t\t\t\t\tif (i != n-1) {\n\t\t\t\t\t\tdp[i][j][step] = Math.min(dp[i][j][step], dp[i+1][j][step-2]+down[i][j]*2);\t\n\t\t\t\t\t}\n\t\t\t\t\tif (j != 0) {\n\t\t\t\t\t\tdp[i][j][step] = Math.min(dp[i][j][step], dp[i][j-1][step-2]+left[i][j]*2);\n\t\t\t\t\t}\n\t\t\t\t\tif (j != m-1) {\n\t\t\t\t\t\tdp[i][j][step] = Math.min(dp[i][j][step], dp[i][j+1][step-2]+right[i][j]*2);\n\t\t\t\t\t}\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\tfor (int j = 0; j < m; j++) {\n\t\t\t\tout.print(dp[i][j][k]+\" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n\n\tstatic class Reader {\n\t\tprivate InputStream mIs;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic Reader() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic Reader(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\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 = 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\t}\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\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\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\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t}\n\tstatic void input_output() throws IOException {\n\t\tFile f = new File(\"in.txt\");\n\t\tif (f.exists() && !f.isDirectory()) {\n\t\t\tin = new Reader(new FileInputStream(\"in.txt\"));\n\t\t} else in = new Reader();\n\t\tf = new File(\"out.txt\");\n\t\tif (f.exists() && !f.isDirectory()) {\n\t\t\tout = new PrintWriter(new File(\"out.txt\"));\n\t\t} else out = new PrintWriter(System.out);\n\t}\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "// Author : RegalBeast\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n  static final FastReader FR = new FastReader();\n  static final PrintWriter PW = new PrintWriter(new OutputStreamWriter(System.out));\n\n  public static void main(String[] args) {\n    StringBuilder solution = new StringBuilder();\n    int rows = FR.nextInt();\n    int cols = FR.nextInt();\n    int moves = FR.nextInt();\n\n    List<List<Integer>> horizontalEdgeWeights = new ArrayList<List<Integer>>(rows);\n    for (int r = 0; r < rows; r++) {\n      horizontalEdgeWeights.add(new ArrayList<Integer>(cols-1));\n\n      for (int c = 0; c < cols - 1; c++) {\n        horizontalEdgeWeights.get(r).add(FR.nextInt());\n      }\n    }\n\n    List<List<Integer>> verticalEdgeWeights = new ArrayList<List<Integer>>(rows-1);\n    for (int r = 0; r < rows - 1; r++) {\n      verticalEdgeWeights.add(new ArrayList<Integer>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        verticalEdgeWeights.get(r).add(FR.nextInt());\n      }\n    }\n    \n    List<List<Integer>> result = getResult(rows, cols, moves, horizontalEdgeWeights, verticalEdgeWeights);\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols; c++) {\n        int value = (result != null ? result.get(r).get(c) : -1);\n        solution.append(value + \" \");\n      }\n      solution.append(\"\\n\");\n    }\n\n\t\tPW.print(solution.toString());\n    PW.close();\n  }\n\n  static List<List<Integer>> getResult(int rows, int cols, int moves, List<List<Integer>> horizontalEdgeWeights, List<List<Integer>> verticalEdgeWeights) {\n    if ((moves & 1) == 1) {\n      return null;\n    }\n\n    int mid = moves >> 1;\n    List<List<List<Integer>>> minForDistance = new ArrayList<List<List<Integer>>>(rows);\n    for (int r = 0; r < rows; r++) {\n      minForDistance.add(new ArrayList<List<Integer>>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        minForDistance.get(r).add(new ArrayList<Integer>(Collections.nCopies(mid+1, Integer.MAX_VALUE)));\n        minForDistance.get(r).get(c).set(0, 0);\n      }\n    }\n\n    for (int m = 1; m <= mid; m++) {\n      for (int r = 0; r < rows; r++) {\n        for (int c = 0; c < cols; c++) {\n          int minBoredom = minForDistance.get(r).get(c).get(m);\n\n          if (r > 0) {\n            if (minForDistance.get(r-1).get(c).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r-1).get(c).get(m-1) + verticalEdgeWeights.get(r-1).get(c);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n\n          if (c > 0) {\n            if (minForDistance.get(r).get(c-1).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r).get(c-1).get(m-1) + horizontalEdgeWeights.get(r).get(c-1);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n          \n          if (r + 1 < rows) {\n            if (minForDistance.get(r+1).get(c).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r+1).get(c).get(m-1) + verticalEdgeWeights.get(r).get(c);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n   \n          if (c + 1 < cols) {\n            if (minForDistance.get(r).get(c+1).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r).get(c+1).get(m-1) + horizontalEdgeWeights.get(r).get(c);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n\n          minForDistance.get(r).get(c).set(m, minBoredom);\n        }\n      }\n    }\n\n    List<List<Integer>> result = new ArrayList<List<Integer>>(rows);\n    for (int r = 0; r < rows; r++) {\n      result.add(new ArrayList<Integer>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        result.get(r).add(minForDistance.get(r).get(c).get(mid) << 1);\n      }\n    }\n\n    return result;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\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.List;\nimport java.util.NoSuchElementException;\nimport java.util.PriorityQueue;\nimport java.util.Set;\n\n//@Japanese\n/* PriorityQueue\u306f\u62e1\u5f35for\u6587\u3067\u51fa\u3059\u3068sort\u3055\u308c\u3066\u306a\u3044\u9806\u756a\u3067\u51fa\u3066\u304f\u308b\n * long\u306ebit\u6f14\u7b97\u306f1L<<pos\u306b\u6ce8\u610f\n * JOI\u306fMLE\u304c\u53b3\u3057\u3044\u3002\u6700\u60aashort\u3092\u4f7f\u3046\u3002\n * ArrayList\u306f\u30aa\u30fc\u30c8\u30dc\u30af\u30b7\u30f3\u30b0\u304c\u9045\u3044\u304b\u3089\u3001\u6700\u60aa\u81ea\u4f5clist\u3092\u4f7f\u3046\n */\n\n/*\u7565\u8a9e\n * 2-to, 4-for, 8-from\n * -L -long(\u578b), -P -\u7d20\u6570P\u3092\u6cd5\u3068\u3057\u305f\u4f59\u308a\n * a,b -\u4efb\u610f\u306e\u5f15\u6570, n,m -\u81ea\u7136\u6570, p -\u7d20\u6570\n * pos -postition\n * abs -\u7d76\u5bfe\u5024\n * min -minimum, max -maximum, ave -average\n * div -divide\n * pow -power(\u7d2f\u4e57)\n * ceil -ceiling(\u5929\u4e95\u95a2\u6570)\n * dt -data\n * ln -length\n * sc -scanner\n * INF -INFINITY\n * e97 -10E9+7=1000000007(prime often used)\n */\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint h = sc.nexI();\n\t\tint w = sc.nexI();\n\t\tint k = sc.nexI();\n\t\t\n\t\t\n\t\tGraph grid = new Graph(h*w);\n\t\t\n\t\tfor(int i=0; i<h; i++) {\n\t\t\tfor(int j=1; j<w; j++) {\n\t\t\t\tlong w1 = sc.nexL();\n\t\t\t\tgrid.add2(getad(w, i, j-1), getad(w, i, j), w1);\n\t\t\t}\n\t\t}\n\t\tfor(int i=1; i<h; i++) {\n\t\t\tfor(int j=0; j<w; j++) {\n\t\t\t\tlong w1 = sc.nexL();\n\t\t\t\tgrid.add2(getad(w, i-1, j), getad(w, i, j), w1);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(k%2 != 0) {\n\t\t\tint[][] anss = new int[h][w];\n\t\t\tfill(anss,-1);\n\t\t\tfor(int i=0; i<h; i++) {\n\t\t\t\tprtspas(anss[i]);\n\t\t\t}\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t\tif((h*w) == 1) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong[][] mincos = new long[(k/2)+1][h*w];\n\t\tfill(mincos[0],0L);\n\t\t\n\t\tfor(int t=1; t<=(k/2); t++) {\n\t\t\tfill(mincos[t], INFL);\n\t\t\tfor(int i=0; i<h; i++) {\n\t\t\t\tfor(int j=0; j<w; j++) {\n\t\t\t\t\tint ad = getad(w, i, j);\n\t\t\t\t\tfor(Edge e: grid.get(ad)) {\n\t\t\t\t\t\tmincos[t][ad] = min(mincos[t][ad], mincos[t-1][e.v2]+e.w);\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\tfor(int i=0; i<(h*w); i++) {\n\t\t\tmincos[k/2][i]*=2L;\n\t\t}\n\t\tfor(int i=0; i<h; i++) {\n\t\t\tprtspas(Arrays.copyOfRange(mincos[k/2], i*w, i*w + w));\n\t\t}\n\t\t\n\t\tout.flush();\n\t\treturn;\n\t}\n\t\n\tpublic static int getad(int w, int i, int j) {\n\t\treturn (i*w + j);\n\t}\n\n\tstatic class Graph { // @Japanese \u91cd\u307f\u4ed8\u304d\u30b0\u30e9\u30d5\n\t\tprivate ArrayList<Node> dt = new ArrayList<>();\n\n\t\tGraph(int sz) {\n\t\t\tfor (int i = 0; i < sz; i++) {\n\t\t\t\tNode node1 = new Node();\n\t\t\t\tdt.add(node1);\n\t\t\t}\n\t\t}\n\n\t\tpublic void add(int v8, int cnct2, long w) {\n\t\t\tdt.get(v8).add(new Edge(v8, cnct2, w));\n\t\t}\n\n\t\tpublic void add2(int v1, int v2, long w) {\n\t\t\tdt.get(v1).add(new Edge(v1, v2, w));\n\t\t\tdt.get(v2).add(new Edge(v2, v1, w));\n\t\t}\n\n\t\tpublic Set<Edge> get(int v) {\n\t\t\treturn dt.get(v).getAll();\n\t\t}\n\n\t\tpublic int size() {\n\t\t\treturn dt.size();\n\t\t}\n\n\t\tpublic int sizeOf(int v) {\n\t\t\treturn dt.get(v).size();\n\t\t}\n\n\t\tpublic void clear() {\n\t\t\tfor (int i = 0; i < dt.size(); i++)\n\t\t\t\tdt.get(i).clear();\n\t\t}\n\n\t\tpublic void clear(int v) {\n\t\t\tdt.get(v).clear();\n\t\t}\n\n\t\tprivate void add_v(Node v_new) {\n\t\t\tdt.add(v_new);\n\t\t}\n\n\t\tpublic void show2() {\n\t\t\tfor (int i = 0; i < dt.size(); i++) {\n\t\t\t\tSystem.out.print(i + \":\");\n\t\t\t\tfor (Edge e : dt.get(i).getAll())\n\t\t\t\t\te.show2();\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\n\t\tpublic static Graph make_Graph(int vn, int en, FastScanner sc) {\n\t\t\tGraph g = new Graph(vn);\n\t\t\tfor (int i = 0; i < en; i++) {\n\t\t\t\tint s1 = sc.nexI() - 1;\n\t\t\t\tint g1 = sc.nexI() - 1;\n\t\t\t\tlong w = sc.nexL();\n\t\t\t\tg.add2(s1, g1, w);\n\t\t\t}\n\t\t\treturn g;\n\t\t}\n\n\t\tpublic static Graph make_tree(int vn, FastScanner sc) {\n\t\t\tGraph g = new Graph(vn);\n\t\t\tfor (int i = 1; i < vn; i++) {\n\t\t\t\tint s1 = sc.nexI() - 1;\n\t\t\t\tint g1 = sc.nexI() - 1;\n\t\t\t\tlong w = sc.nexL();\n\t\t\t\tg.add2(s1, g1, w);\n\t\t\t}\n\t\t\treturn g;\n\t\t}\n\t\t\n\n\t\tprivate long[] dijkstra(int from) {\n\t\t\tPriorityQueue<Edge> dijk = new PriorityQueue<>(new CompEdge_float());\n\t\t\tlong[] d8i = new long[this.dt.size()];\n\t\t\tfill(d8i, INFL);\n\t\t\tdijk.add(new Edge(from, 0L));\n\n\t\t\twhile (!dijk.isEmpty()) {\n\t\t\t\tEdge dw = dijk.poll();\n\t\t\t\tif (d8i[dw.v2] > dw.w) {\n\t\t\t\t\td8i[dw.v2] = dw.w;\n\t\t\t\t\tfor (Edge e : this.get(dw.v2)) {\n\t\t\t\t\t\tlong w2 = dw.w + e.w;\n\t\t\t\t\t\tif (d8i[e.v2] > w2)\n\t\t\t\t\t\t\tdijk.add(new Edge(e.v2, w2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn d8i;\n\t\t}\n\t}\n\n\tstatic class Node { // \u91cd\u307f\u3064\u304d\u30b0\u30e9\u30d5\u306e\u9802\u70b9\n\t\tprivate Set<Edge> next_vs = new HashSet<>();\n\n\t\tpublic void add(Edge cnct2) {\n\t\t\tnext_vs.add(cnct2);\n\t\t}\n\n\t\tpublic Set<Edge> getAll() {\n\t\t\treturn next_vs;\n\t\t}\n\n\t\tpublic int size() {\n\t\t\treturn next_vs.size();\n\t\t}\n\n\t\tpublic void clear() {\n\t\t\tnext_vs.clear();\n\t\t}\n\n\t\tpublic void addAll(Node list2add) {\n\t\t\tthis.next_vs.addAll(list2add.next_vs);\n\t\t}\n\t}\n\n\tstatic class Edge { // @Japanese \u91cd\u307f\u7740\u304d\u306e\u30b0\u30e9\u30d5\u306e\u8fba\n\t\tint from = -1, v2 = -1;\n\t\tlong w;\n\n\t\tpublic Edge(int going2, long weight_route) {\n\t\t\tthis.v2 = going2;\n\t\t\tthis.w = weight_route;\n\t\t}\n\n\t\tpublic Edge(int come8, int going2, long weight_route) {\n\t\t\tthis.from = come8;\n\t\t\tthis.v2 = going2;\n\t\t\tthis.w = weight_route;\n\t\t}\n\n\t\tpublic void show2() {\n\t\t\tSystem.out.println(this.from + \"->\" + this.v2 + \" :w=\" + this.w);\n\t\t}\n\t}\n\n\tstatic class CompEdge_float implements Comparator<Edge> {\n\t\t// \u4eca\u306f\u5c0f\u3055\u3044\u306e\u304c\u524d\u306b\u51fa\u3066\u304f\u308b\n\t\tpublic int compare(Edge a, Edge b) {\n\t\t\tif (a.w > b.w)\n\t\t\t\treturn 1;\n\t\t\telse if (a.w < b.w)\n\t\t\t\treturn -1;\n\t\t\telse\n\t\t\t\treturn a.v2 - b.v2;\n\t\t}\n\t}\n\n\tprivate static final int INF = (int) 3e8;\n\tprivate static final long INFL = (long) 1e17;\n\tprivate static final int INTMAX = Integer.MAX_VALUE;\n\tprivate static final long LONGMAX = Long.MAX_VALUE;\n\tprivate static final long e97 = 1000000007L;\n\tprivate static final long e99 = 998244353L;\n\tprivate static final double PI = Math.PI;\n\n\tprivate static void assertion(boolean should_true) {\n\t\t// throw Error if should_true is not true @Japanese\u300c\u65ad\u8a00\u300d\n\t\tif (!should_true)\n\t\t\tthrow new AssertionError();\n\t}\n\n\tprivate static int abs(int a) {\n\t\treturn (a >= 0) ? a : -a;\n\t}\n\n\tprivate static long abs(long a) {\n\t\treturn (a >= 0L) ? a : -a;\n\t}\n\n\tprivate static double abs(double a) {\n\t\treturn (a >= 0.0) ? a : -a;\n\t}\n\n\tprivate static int min(int a, int b) {\n\t\treturn (a < b) ? a : b;\n\t}\n\n\tprivate static long min(long a, long b) {\n\t\treturn (a < b) ? a : b;\n\t}\n\n\tprivate static double min(double a, double b) {\n\t\treturn (a < b) ? a : b;\n\t}\n\n\tprivate static int max(int a, int b) {\n\t\treturn (a > b) ? a : b;\n\t}\n\n\tprivate static long max(long a, long b) {\n\t\treturn (a > b) ? a : b;\n\t}\n\n\tprivate static double max(double a, double b) {\n\t\treturn (a > b) ? a : b;\n\t}\n\n\tprivate static int pow2(int num2pow) {\n\t\tif (num2pow > 4e4)\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\treturn num2pow * num2pow;\n\t}\n\n\tprivate static long pow2(long num2pow) {\n\t\tif (num2pow > 1e8)\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use PowP.\");\n\t\treturn num2pow * num2pow;\n\t}\n\n\tprivate static int pow(int num_powered, int index) {\n\t\tint ans = 1;\n\t\tfor (int i = 0; i < index; i++) {\n\t\t\tif (ans >= (INTMAX / num_powered))\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\t\tans *= num_powered;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static long pow(long num_powered, int index) {\n\t\tlong ans = 1L;\n\t\tfor (int i = 0; i < index; i++) {\n\t\t\tif (ans >= (LONGMAX / num_powered))\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use PowP.\");\n\t\t\tans *= num_powered;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static long powP(long num_powered, long index, long p) {\n\t\t// O(log(index))\n\t\t// @Japanese \u7e70\u308a\u8fd4\u3057\u4e8c\u4e57\u6cd5\n\t\tif (num_powered == 0L)\n\t\t\treturn 0L;\n\t\tif (index == 0L)\n\t\t\treturn 1L;\n\t\tif (index == 2L) {\n\t\t\treturn (pow2(num_powered) % p);\n\t\t}\n\n\t\tint d = getDigit2(index);\n\t\tlong[] num_done_by2 = new long[d + 1];\n\t\tnum_done_by2[0] = num_powered;\n\t\tfor (int i = 1; i <= d; i++) {\n\t\t\tnum_done_by2[i] = num_done_by2[i - 1] * num_done_by2[i - 1];\n\t\t\tnum_done_by2[i] %= p;\n\t\t}\n\t\tlong ans = 1L;\n\t\tfor (int i = d; i >= 0; i--) {\n\t\t\tlong cf = (1L << (long) i);\n\t\t\tif (index >= cf) {\n\t\t\t\tindex -= cf;\n\t\t\t\tans = ans * num_done_by2[i];\n\t\t\t\tans %= p;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static double hypod(double a, double b) {\n\t\treturn Math.sqrt(a * a + b * b);\n\t}\n\n\tprivate static int getDigit2(long num2know) {\n\t\t// O(log(n))\n\t\tlong compare4 = 1L;\n\t\tint digit = 0;\n\t\twhile (num2know >= compare4) {\n\t\t\tdigit++;\n\t\t\tcompare4 = (1L << (long) digit);\n\t\t}\n\t\treturn digit;\n\t\t// num < 2^digit\n\t}\n\n\tprivate static int getDigit10(long num2know) {\n\t\t// O(log10(n))\n\t\tlong compare4 = 1L;\n\t\tint digit = 0;\n\t\twhile (num2know >= compare4) {\n\t\t\tdigit++;\n\t\t\tcompare4 *= 10L;\n\t\t}\n\t\treturn digit; // @Japanese num \u306f digit\u6841\u306e\u6570\u3067\u300110^digit\u672a\u6e80\n\n\t}\n\n\tprivate static int divceil(int numerator, int denominator) {\n\t\treturn (numerator + denominator - 1) / denominator;\n\t}\n\n\tprivate static long divceil(long numerator, long denominator) {\n\t\treturn (numerator + denominator - 1L) / denominator;\n\t}\n\n\tprivate static long factorial(int n) {\n\t\t// O(n)\n\t\tlong ans = 1L;\n\t\tfor (long i = 2; i <= n; i++) {\n\t\t\tif (ans >= (LONGMAX / i))\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use facP.\");\n\t\t\tans *= i;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static long facP(int n, long p) {\n\t\t// O(n) see also PermulationCombination:O(max_sz)+Q\n\t\tlong ans = 1L;\n\t\tfor (long i = 2; i <= n; i++) {\n\t\t\tans *= i;\n\t\t\tans %= p;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static long lcm(long m, long n) {\n\t\tlong ans = m / gcd(m, n);\n\t\tif (ans >= (LONGMAX / n))\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large.\");\n\t\tans *= n;\n\t\treturn ans;\n\t}\n\n\tprivate static long gcd(long m, long n) {\n\t\t// O(log(m+n))\n\t\tif ((m <= 0L) || (n <= 0L))\n\t\t\tthrow new IllegalArgumentException(\"m and n should be natural.\");\n\n\t\twhile ((m > 0L) && (n > 0L)) {\n\t\t\tif (m >= n)\n\t\t\t\tm %= n;\n\t\t\telse\n\t\t\t\tn %= m;\n\t\t}\n\t\tif (m > 0L)\n\t\t\treturn m;\n\t\telse\n\t\t\treturn n;\n\t}\n\n\tprivate static boolean is_prime(long n2check) {\n\t\t// O(\u221an)\n\t\tif (n2check == 1L)\n\t\t\treturn false;\n\t\tfor (long i = 2L; i <= Math.sqrt(n2check); i++) {\n\t\t\tif (n2check % i == 0L)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate static int safe_mod(int n, int p) {\n\t\tn %= p;\n\t\tif (n >= 0)\n\t\t\treturn n;\n\t\treturn (n + p);\n\t}\n\n\tprivate static long safe_mod(long n, long p) {\n\t\tn %= p;\n\t\tif (n >= 0L)\n\t\t\treturn n;\n\t\treturn (n + p);\n\t}\n\n\tprivate static long modinv(long n, long p) {\n\t\t// @Japanese \u9006\u5143\u3092\u6c42\u3081\u308b\n\t\t// O(10log(n))\n\t\t// p\u306f\u7d20\u6570\u3067\u306a\u304f\u3066\u3082\u3088\u3044\n\t\t// \u30cd\u30c3\u30c8\u304b\u3089\u62fe\u3063\u3066\u304d\u305f\u306e\u304c\u7406\u89e3\u4e0d\u80fd\u3060\u3063\u305f\u306e\u3067\u3001\u884c\u5217\u8a08\u7b97\u3092\u7528\u3044\u3066\u975e\u52b9\u7387\u7684\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u66f8\u3044\u305f\n\n\t\tn %= p;\n\t\tif ((p == 1L) || (gcd(n, p) != 1L))\n\t\t\tthrow new IllegalArgumentException(\"n and p should be coprime.\");\n\n\t\t// @Japanese\n\t\t// yn\u22611(mod p)\n\t\t// <-> xp+yn=1; (n<p)\n\t\t// ...(sx+ty)a+(ux+vy)b=1 (|sv-tu|=1)\n\t\t// ...(sx+ty)a+(ux+vy)=1\n\t\t// <- sx+ty=0, ux+vy=1\n\n\t\tlong a = p, b = n, s = 1L, t = 0L, u = 0L, v = 1L;\n\t\twhile (b > 1) {\n\t\t\tlong quo = a / b, rem = a % b;\n\t\t\ta = b;\n\t\t\tb = rem;\n\t\t\tlong s2 = s * quo + u, t2 = t * quo + v;\n\t\t\tu = s;\n\t\t\tv = t;\n\t\t\ts = s2;\n\t\t\tt = t2;\n\t\t}\n\t\tlong det = s * v - t * u;\n\t\tif (abs(det) != 1L)\n\t\t\tthrow new ArithmeticException(\"My algorithm was Wrong!!\");\n\t\ts /= det;\n\t\ts %= p;\n\t\tif (s < 0L)\n\t\t\ts += p;\n\t\treturn s;\n\t}\n\n\tprivate static int minAll(int[] dt4min) {\n\t\t// O(n)\n\t\tint min = INF;\n\t\tfor (int element : dt4min) {\n\t\t\tif (element < min)\n\t\t\t\tmin = element;\n\t\t}\n\t\treturn min;\n\t}\n\n\tprivate static long minAll(long[] dt4min) {\n\t\t// O(n)\n\t\tlong min = INFL;\n\t\tfor (long element : dt4min) {\n\t\t\tif (element < min)\n\t\t\t\tmin = element;\n\t\t}\n\t\treturn min;\n\t}\n\n\tprivate static int maxAll(int[] dt4max) {\n\t\t// O(n)\n\t\tint max = -INF;\n\t\tfor (int element : dt4max) {\n\t\t\tif (element > max)\n\t\t\t\tmax = element;\n\t\t}\n\t\treturn max;\n\t}\n\n\tprivate static long maxAll(long[] dt4max) {\n\t\t// O(n)\n\t\tlong max = -INFL;\n\t\tfor (long element : dt4max) {\n\t\t\tif (element > max)\n\t\t\t\tmax = element;\n\t\t}\n\t\treturn max;\n\t}\n\n\tprivate static int sumAll(int[] dt4sum) {\n\t\t// O(n)\n\t\tint sum_of_dt = 0;\n\t\tfor (int element : dt4sum) {\n\t\t\tif (sum_of_dt > (INTMAX - element))\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\t\tsum_of_dt += element;\n\t\t}\n\t\treturn sum_of_dt;\n\t}\n\n\tprivate static long sumAll(long[] dt4sum) {\n\t\t// O(n)\n\t\tlong sum_of_dt = 0L;\n\t\tfor (long element : dt4sum) {\n\t\t\tif (sum_of_dt > (LONGMAX - element))\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large.\");\n\t\t\tsum_of_dt += element;\n\t\t}\n\t\treturn sum_of_dt;\n\t}\n\n\tprivate static int sumAll(ArrayList<Integer> dt4sum) {\n\t\tint sum_of_dt = 0;\n\t\tfor (long element : dt4sum) {\n\t\t\tif (sum_of_dt > (INTMAX - element))\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\t\tsum_of_dt += element;\n\t\t}\n\t\treturn sum_of_dt;\n\t}\n\n\tprivate static int[] reverse(int[] as) {\n\t\tint ln = as.length;\n\t\tint[] bs = new int[ln];\n\t\tfor (int i = 0; i < ln; i++)\n\t\t\tbs[i] = as[ln - i - 1];\n\t\treturn bs;\n\t}\n\n\tprivate static void reverseSub(int[] as, int S_include, int Gnot_include) {\n\t\t// O(G-S)\n\t\tint ln = Gnot_include - S_include;\n\n\t\tint[] bs = new int[ln];\n\t\tfor (int i = S_include; i < Gnot_include; i++)\n\t\t\tbs[i - S_include] = as[i];\n\t\tfor (int i = 0; i < ln; i++)\n\t\t\tas[i + S_include] = bs[ln - i - 1];\n\t}\n\n\tprivate static boolean is_in_area(int y, int x, int height, int width) {\n\t\tif (y < 0)\n\t\t\treturn false;\n\t\tif (x < 0)\n\t\t\treturn false;\n\t\tif (y >= height)\n\t\t\treturn false;\n\t\tif (x >= width)\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tprivate static boolean is_in_area(Vector v, int height, int width) {\n\t\tif (v.y < 0)\n\t\t\treturn false;\n\t\tif (v.x < 0)\n\t\t\treturn false;\n\t\tif (v.y >= height)\n\t\t\treturn false;\n\t\tif (v.x >= width)\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tprivate static int nC2(int n) {\n\t\treturn ((n * (n - 1)) / 2);\n\t}\n\n\tprivate static long nC2(long n) {\n\t\treturn ((n * (n - 1L)) / 2L);\n\t}\n\n\tprivate static int iflag(int pos) {\n\t\tif (pos >= 32)\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\treturn (1 << pos);\n\t}\n\n\tprivate static long flag(int pos) {\n\t\tif (pos >= 64)\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\treturn (1L << (long) pos);\n\t}\n\n\tprivate static boolean isFlaged(int bit, int pos) {\n\t\tif (pos >= 32)\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large.\");\n\t\treturn ((bit & (1 << pos)) != 0);\n\t}\n\n\tprivate static boolean isFlaged(long bit, int pos) {\n\t\tif (pos >= 64)\n\t\t\tthrow new IllegalArgumentException(\"Input is to Large.\");\n\t\treturn ((bit & (1L << (long) pos)) != 0L);\n\t}\n\n\tprivate static int deflag(int bit, int pos) {\n\t\treturn (bit & (~(1 << pos)));\n\t}\n\n\tprivate static int countFlaged(int bit) {\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < 31; i++) {\n\t\t\tif ((bit & (1 << i)) != 0)\n\t\t\t\tans++;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static int countFlaged(long bit) {\n\t\tint ans = 0;\n\t\tfor (long i = 0L; i < 63L; i++) {\n\t\t\tif ((bit & (1L << i)) != 0L)\n\t\t\t\tans++;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tprivate static int[] Xdir4 = { 1, 0, 0, -1 };\n\tprivate static int[] Ydir4 = { 0, 1, -1, 0 };\n\tprivate static int[] Xdir8 = { 1, 1, 1, 0, 0, -1, -1, -1 };\n\tprivate static int[] Ydir8 = { 1, 0, -1, 1, -1, 1, 0, -1 };\n\n\tpublic static int biSearch(int[] dt, int target) {\n\t\t// O(log(dt.length))\n\t\t// dt should be sorted in 0->INF\n\t\t// return adress of target\n\t\tint left = 0, right = dt.length - 1;\n\t\tint mid = -1;\n\t\twhile (left <= right) {\n\t\t\tmid = ((right + left) / 2);\n\t\t\tif (dt[mid] == target)\n\t\t\t\treturn mid;\n\t\t\tif (dt[mid] < target)\n\t\t\t\tleft = (mid + 1);\n\t\t\telse\n\t\t\t\tright = (mid - 1);\n\t\t}\n\t\treturn -1;\n\t}\n\n\tpublic static int biSearchMax(long[] dt, long target) {\n\t\t// O(log(dt.length))\n\t\t// dt should be sorted in 0->INF\n\t\tint left = -1, right = dt.length, mid = -1;\n\t\twhile ((right - left) > 1) {\n\t\t\tmid = ((right + left) / 2);\n\t\t\tif (dt[mid] <= target)\n\t\t\t\tleft = mid;\n\t\t\telse\n\t\t\t\tright = mid;\n\t\t}\n\t\treturn left;\n\t\t// @Japanese target\u4ee5\u4e0b\u306e\u6700\u5927\u306eaddress\n\t}\n\n\tpublic static int biSearchMin(long[] dt, long target) {\n\t\t// O(log(dt.length))\n\t\t// dt should be sorted in 0->INF\n\t\tint left = -1, right = dt.length, mid = -1;\n\t\twhile ((right - left) > 1) {\n\t\t\tmid = ((right + left) / 2);\n\t\t\tif (dt[mid] <= target)\n\t\t\t\tleft = mid;\n\t\t\telse\n\t\t\t\tright = mid;\n\t\t}\n\t\treturn right;\n\t\t// @Japanese target\u3088\u308a\u5927\u304d\u3044\u6700\u5c0f\u306eaddress\n\t}\n\n\tprivate static void fill(boolean[] target, boolean reset) {\n\t\tfor (int i = 0; i < target.length; i++)\n\t\t\ttarget[i] = reset;\n\t}\n\n\tprivate static void fill(int[] target, int reset) {\n\t\tfor (int i = 0; i < target.length; i++)\n\t\t\ttarget[i] = reset;\n\t}\n\n\tprivate static void fill(long[] target, long reset) {\n\t\tfor (int i = 0; i < target.length; i++)\n\t\t\ttarget[i] = reset;\n\t}\n\n\tprivate static void fill(char[] target, char reset) {\n\t\tfor (int i = 0; i < target.length; i++)\n\t\t\ttarget[i] = reset;\n\t}\n\n\tprivate static void fill(double[] target, double reset) {\n\t\tfor (int i = 0; i < target.length; i++)\n\t\t\ttarget[i] = reset;\n\t}\n\n\tprivate static void fill(boolean[][] target, boolean reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\ttarget[i][j] = reset;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(int[][] target, int reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\ttarget[i][j] = reset;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(long[][] target, long reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\ttarget[i][j] = reset;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(char[][] target, char reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\ttarget[i][j] = reset;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(double[][] target, double reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\ttarget[i][j] = reset;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(int[][][] target, int reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\tfor (int k = 0; k < target[i][j].length; k++) {\n\t\t\t\t\ttarget[i][j][k] = reset;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(long[][][] target, long reset) {\n\t\tfor (int i = 0; i < target.length; i++) {\n\t\t\tfor (int j = 0; j < target[i].length; j++) {\n\t\t\t\tfor (int k = 0; k < target[i][j].length; k++) {\n\t\t\t\t\ttarget[i][j][k] = reset;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill_parent(int[] parent) {\n\t\tfor (int i = 0; i < parent.length; i++) {\n\t\t\tparent[i] = i;\n\t\t}\n\t}\n\n\tprivate static void showBit(int bit) {\n\t\tfor (int i = 0; i < getDigit2(bit); i++) {\n\t\t\tif (isFlaged(bit, i))\n\t\t\t\tSystem.out.print(\"O\");\n\t\t\telse\n\t\t\t\tSystem.out.print(\".\");\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tprivate static void showBit(long bit) {\n\t\tfor (int i = 0; i < getDigit2(bit); i++) {\n\t\t\tif (isFlaged(bit, i))\n\t\t\t\tSystem.out.print(\"O\");\n\t\t\telse\n\t\t\t\tSystem.out.print(\".\");\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tstatic void show2(boolean[][] dt, String cmnt) {\n\t\tfor (int i = 0; i < dt.length; i++) {\n\t\t\tfor (int j = 0; j < dt[i].length; j++) {\n\t\t\t\tif (dt[i][j])\n\t\t\t\t\tSystem.out.print(\"O\");\n\t\t\t\telse\n\t\t\t\t\tSystem.out.print(\".\");\n\t\t\t}\n\t\t\tif (!cmnt.equals(\"\"))\n\t\t\t\tSystem.out.print(\"<-\" + cmnt);\n\t\t\tSystem.out.println(\" :\" + i);\n\t\t}\n\t}\n\n\tstatic void show2(int[][] dt, String cmnt) {\n\t\tfor (int i = 0; i < dt.length; i++) {\n\t\t\tfor (int j = 0; j < dt[i].length; j++)\n\t\t\t\tSystem.out.print(dt[i][j] + \",\");\n\t\t\tif (!cmnt.equals(\"\"))\n\t\t\t\tSystem.out.print(\"<-\" + cmnt);\n\t\t\tSystem.out.println(\" :\" + i);\n\t\t}\n\t}\n\n\tstatic void show2(long[][] dt, String cmnt) {\n\t\tfor (int i = 0; i < dt.length; i++) {\n\t\t\tfor (int j = 0; j < dt[i].length; j++)\n\t\t\t\tSystem.out.print(dt[i][j] + \",\");\n\t\t\tif (!cmnt.equals(\"\"))\n\t\t\t\tSystem.out.print(\"<-\" + cmnt);\n\t\t\tSystem.out.println(\" :\" + i);\n\t\t}\n\t}\n\n\tstatic void show2(ArrayDeque<Long> dt) {\n\t\tlong element = 0;\n\t\twhile (dt.size() > 0) {\n\t\t\telement = dt.removeFirst();\n\t\t\tSystem.out.print(element);\n\t\t}\n\t\tSystem.out.println(\"\\n\");\n\t}\n\n\tstatic void show2(List<Object> dt) {\n\t\tfor (int i = 0; i < dt.size(); i++)\n\t\t\tSystem.out.print(dt.get(i) + \",\");\n\t\tSystem.out.println(\"\\n\");\n\t}\n\n\tprivate static void prtlnas(int[] array) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tfor (int e: array)\n\t\t\tout.println(e);\n\t\tout.flush();\n\t}\n\n\tprivate static void prtlnas(long[] array) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tfor (long e: array)\n\t\t\tout.println(e);\n\t\tout.flush();\n\t}\n\n\tprivate static void prtlnas(ArrayList<Object> array) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tfor (Object e: array)\n\t\t\tout.println(e);\n\t\tout.flush();\n\t}\n\n\tprivate static void prtspas(int[] array) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tout.print(array[0]);\n\t\tfor (int i = 1; i < array.length; i++)\n\t\t\tout.print(\" \" + array[i]);\n\t\tout.println();\n\t\tout.flush();\n\t}\n\n\tprivate static void prtspas(long[] array) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tout.print(array[0]);\n\t\tfor (int i = 1; i < array.length; i++)\n\t\t\tout.print(\" \" + array[i]);\n\t\tout.println();\n\t\tout.flush();\n\t}\n\n\tprivate static void prtspas(double[] array) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tout.print(array[0]);\n\t\tfor (int i = 1; i < array.length; i++)\n\t\t\tout.print(\" \" + array[i]);\n\t\tout.println();\n\t\tout.flush();\n\t}\n\n\tprivate static void prtspas(ArrayList<Integer> array) {\n\t\tif (array.isEmpty())\n\t\t\treturn;\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tout.print(array.get(0));\n\t\tfor (int i = 1; i < array.size(); i++)\n\t\t\tout.print(\" \" + array.get(i));\n\t\tout.println();\n\t\tout.flush();\n\t}\n\n\tstatic class Vector {\n\t\tint x, y;\n\n\t\tpublic Vector(int sx, int sy) {\n\t\t\tthis.x = sx;\n\t\t\tthis.y = sy;\n\t\t}\n\n\t\tpublic boolean equals(Vector v) {\n\t\t\treturn (this.x == v.x && this.y == v.y);\n\t\t}\n\n\t\tpublic void show2() {\n\t\t\tSystem.out.println(this.x + \", \" + this.y);\n\t\t}\n\n\t\tpublic static int dist2(Vector a, Vector b) {\n\t\t\tint dx = abs(a.x - b.x);\n\t\t\tint dy = abs(a.y - b.y);\n\t\t\tif (dx > 3e4)\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\t\tif (dy > 3e4)\n\t\t\t\tthrow new IllegalArgumentException(\"Input is to Large. Use Long.\");\n\t\t\treturn (dx * dx + dy * dy);\n\t\t}\n\t}\n\n\tstatic class CompVector implements Comparator<Vector> {\n\t\tpublic int compare(Vector a, Vector b) {\n\t\t\tif (a.x == b.x)\n\t\t\t\treturn a.y - b.y;\n\t\t\telse\n\t\t\t\treturn a.x - b.x;\n\t\t}\n\t}\n\n\tstatic class FastScanner {\n\t\t//@Japanese \u30cd\u30c3\u30c8\u304b\u3089\u62fe\u3063\u3066\u304d\u305f\u3002\u3088\u304f\u5206\u304b\u3089\u3093\u3002\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\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() {\n\t\t\tif (hasNextByte())\n\t\t\t\treturn buffer[ptr++];\n\t\t\telse\n\t\t\t\treturn -1;\n\t\t}\n\n\t\tprivate static boolean isPrintableChar(int c) {\n\t\t\treturn (33 <= c) && (c <= 126);\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\twhile (hasNextByte() && !isPrintableChar(buffer[ptr]))\n\t\t\t\tptr++;\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 (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\n\t\tpublic long nexL() {\n\t\t\tif (!hasNext())\n\t\t\t\tthrow 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) || 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\n\t\tpublic int nexI() {\n\t\t\tlong nl = nexL();\n\t\t\tif (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {\n\t\t\t\tthrow new NumberFormatException();\n\t\t\t}\n\t\t\treturn (int) nl;\n\t\t}\n\n\t\tpublic double nexD() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\t// a means array\n\t\tpublic void ai(int[]... array) {\n\t\t\tfor (int i = 0; i < array[0].length; i++) {\n\t\t\t\tfor (int j = 0; j < array.length; j++) {\n\t\t\t\t\tarray[j][i] = nexI();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tpublic void al(long[]... array) {\n\t\t\tfor (int i = 0; i < array[0].length; i++) {\n\t\t\t\tfor (int j = 0; j < array.length; j++) {\n\t\t\t\t\tarray[j][i] = nexL();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tpublic void aimin1(int[] array) {\n\t\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\t\tarray[i] = nexI() - 1;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tpublic void aD(double[] array) {\n\t\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\t\tarray[i] = nexD();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tpublic void ai2d(int[][] array) {\n\t\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\t\tfor (int j = 0; j < array[0].length; j++) {\n\t\t\t\t\tarray[i][j] = nexI();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tpublic void al2d(long[][] array) {\n\t\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\t\tfor (int j = 0; j < array[0].length; j++) {\n\t\t\t\t\tarray[i][j] = nexL();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n}\n// END OF THE CODE", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastScanner in = new FastScanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskD {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            final int[] dr = {-1, 0, 1, 0};\n            final int[] dc = {0, -1, 0, 1};\n\n            int height = in.nextInt();\n            int width = in.nextInt();\n            int k = in.nextInt();\n\n            int[][][] cost = new int[4][height][width];\n            for (int r = 0; r < height; r++) {\n                for (int c = 0; c + 1 < width; c++) {\n                    int x = in.nextInt();\n                    cost[3][r][c] = x;\n                    cost[1][r][c + 1] = x;\n                }\n            }\n\n            for (int r = 0; r + 1 < height; r++) {\n                for (int c = 0; c < width; c++) {\n                    int x = in.nextInt();\n                    cost[2][r][c] = x;\n                    cost[0][r + 1][c] = x;\n                }\n            }\n\n            boolean odd = (k % 2 != 0);\n            k /= 2;\n            int[][][] d = new int[k + 1][height][width];\n            for (int len = 1; len <= k; len++) {\n                for (int r = 0; r < height; r++) {\n                    for (int c = 0; c < width; c++) {\n                        d[len][r][c] = Integer.MAX_VALUE;\n                        for (int dir = 0; dir < 4; dir++) {\n                            int nr = r + dr[dir];\n                            int nc = c + dc[dir];\n                            if (nr < 0 || nr >= height || nc < 0 || nc >= width) {\n                                continue;\n                            }\n                            d[len][r][c] = Math.min(d[len][r][c], d[len - 1][nr][nc] + cost[dir][r][c]);\n                        }\n                    }\n                }\n            }\n\n            for (int r = 0; r < height; r++) {\n                for (int c = 0; c < width; c++) {\n                    if (c > 0) {\n                        out.print(\" \");\n                    }\n                    out.print(odd ? -1 : 2 * d[k][r][c]);\n                }\n                out.println();\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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\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                } 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            } 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            } while (!isSpaceChar(c));\n\n            return res * sgn;\n        }\n\n        public long nextLong() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            long res = 0;\n\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public double nextDouble() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            double res = 0;\n            while (!isSpaceChar(c) && c != '.') {\n                if (c == 'e' || c == 'E')\n                    return res * Math.pow(10, nextInt());\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            }\n            if (c == '.') {\n                c = read();\n                double m = 1;\n                while (!isSpaceChar(c)) {\n                    if (c == 'e' || c == 'E')\n                        return res * Math.pow(10, nextInt());\n                    if (c < '0' || c > '9')\n                        throw new InputMismatchException();\n                    m /= 10;\n                    res += (c - '0') * m;\n                    c = read();\n                }\n            }\n            return res * sgn;\n        }\n\n        public String readString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isSpaceChar(c));\n\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(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 Main(), \"Main\", 1 << 27).start();\n    }\n\n    static class Pair {\n        int f;\n        int s;\n        int p;\n        PrintWriter w;\n\n        // int t;\n\n        Pair(int f, int s) {\n            // Pair(int f,int s, PrintWriter w){\n            this.f = f;\n            this.s = s;\n            // this.p = p;\n            // this.w = w;\n            // this.t = t;\n\n        }\n\n        public static Comparator<Pair> wc = new Comparator<Pair>() {\n            public int compare(Pair e1,Pair e2){\n\n            // 1 for swap\n            if(Math.abs(e1.f)-Math.abs(e2.f)!=0){\n            // e1.w.println(\"**\"+e1.f+\" \"+e2.f);\n                return -1*(Math.abs(e1.f)-Math.abs(e2.f));\n            }\n            else{\n            // e1.w.println(\"##\"+e1.f+\" \"+e2.f);\n                return(Math.abs(e1.s)-Math.abs(e2.s));\n            }\n\n        }};\n    }\n\n    public Integer[] sort(Integer[] a) {\n        Arrays.sort(a);\n        return a;\n    }\n\n    public Long[] sort(Long[] a) {\n        Arrays.sort(a);\n        return a;\n    }\n\n    public static ArrayList<Integer> sieve(int N) {\n        int i, j, flag;\n\n        ArrayList<Integer> p = new ArrayList<Integer>();\n\n        for (i = 1; i < N; i++) {\n\n            if (i == 1 || i == 0)\n                continue;\n\n            flag = 1;\n\n            for (j = 2; j <= i / 2; ++j) {\n                if (i % j == 0) {\n                    flag = 0;\n                    break;\n                }\n            }\n            if (flag == 1) {\n                p.add(i);\n            }\n        }\n        return p;\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 int gcd(int a, int b) {\n        if (b == 0)\n            return a;\n        else\n            return gcd(b, a % b);\n    }\n\n    //// recursive dfs\n    public static int dfs(int s, ArrayList<Integer>[] g, long[] dist, boolean[] v, PrintWriter w, int p) {\n        v[s] = true;\n        int ans = 1;\n        // int n = dist.length - 1;\n        int t = g[s].size();\n        // int max = 1;\n        for (int i = 0; i < t; i++) {\n            int x = g[s].get(i);\n            if (!v[x]) {\n                // dist[x] = dist[s] + 1;\n                ans = Math.min(ans, dfs(x, g, dist, v, w, s));\n            } else if (x != p) {\n                // w.println(\"* \" + s + \" \" + x + \" \" + p);\n                ans = 0;\n            }\n        }\n        // max = Math.max(max,(n-p));\n        return ans;\n    }\n\n    //// iterative BFS\n    public static int bfs(int s, ArrayList<Integer>[] g, long[] dist, boolean[] b, PrintWriter w, int p) {\n        b[s] = true;\n        int siz = 1;\n        // dist--;\n        Queue<Integer> q = new LinkedList<>();\n        q.add(s);\n        while (q.size() != 0) {\n            int i = q.poll();\n            Iterator<Integer> it = g[i].listIterator();\n            int z = 0;\n            while (it.hasNext()) {\n                z = it.next();\n                if (!b[z]) {\n                    b[z] = true;\n                    // dist--;\n                    dist[z] = dist[i] + 1;\n                    // siz++;\n                    q.add(z);\n                } else if (z != p) {\n                    siz = 0;\n                }\n            }\n\n        }\n        return siz;\n    }\n\n    public static int lower(int a[], int x) { // x is the target value or key\n        int l = -1, r = a.length;\n        while (l + 1 < r) {\n            int m = (l + r) >>> 1;\n            if (a[m] >= x)\n                r = m;\n            else\n                l = m;\n        }\n        return r;\n    }\n\n    public static int upper(int a[], int x) {// x is the key or target value\n        int l = -1, r = a.length;\n        while (l + 1 < r) {\n            int m = (l + r) >>> 1;\n            if (a[m] <= x)\n                l = m;\n            else\n                r = m;\n        }\n        return l + 1;\n    }\n\n    public static int lower(ArrayList<Integer> a, int x) { // x is the target value or key\n        int l = -1, r = a.size();\n        while (l + 1 < r) {\n            int m = (l + r) >>> 1;\n            if (a.get(m) >= x)\n                r = m;\n            else\n                l = m;\n        }\n        return r;\n    }\n\n    public static int upper(ArrayList<Integer> a, int x) {// x is the key or target value\n        int l = -1, r = a.size();\n        while (l + 1 < r) {\n            int m = (l + r) >>> 1;\n            if (a.get(m) <= x)\n                l = m;\n            else\n                r = m;\n        }\n        return l + 1;\n    }\n\n    public static long power(long x, long y, long m) {\n        if (y == 0)\n            return 1;\n\n        long p = power(x, y / 2, m) % m;\n        p = (p * p) % m;\n\n        if (y % 2 == 0)\n            return p;\n        else\n            return (x * p) % m;\n    }\n    public void yesOrNo(boolean f){\n        if(f){\n            w.println(\"YES\");\n        }\n        else{\n            w.println(\"NO\");\n        }\n    }\n\n    //////////////////////////////////////////////////////////////////////////////////////////////////////\n    //////////////////////////////////////////////////////////////////////////////////////////////////////\n    // code here\n    int oo = (int) 1e9;\n    int[] parent;\n    int[] dist;\n    int[] height;\n    boolean[] vis;\n    // ArrayList<Integer>[] g;\n    //int[] col;\n    //HashMap<Long, Boolean>[] dp;\n    char[][] g;\n    // boolean[][] v;\n    //long[] a;\n    // ArrayList<Integer[]> a;\n    // int[][] ans;\n    long[][][] dp;\n    long mod;\n    int n;\n    int m;\n    int k;\n    long[][] pre;\n    // StringBuilder[] a;\n    // StringBuilder[] b;\n    //StringBuilder ans;\n    int[][] col;\n    int[][] row;\n    PrintWriter w = new PrintWriter(System.out);\n\n    public void run() {\n\n        InputReader sc = new InputReader(System.in);\n\n        int defaultValue = 0;\n        mod = 1000000007;\n\n        int test = 1;\n        //test = sc.nextInt();\n        while (test-- > 0) {\n            n = sc.nextInt();\n            m = sc.nextInt();\n            k = sc.nextInt();\n\n            col = new int[n][m-1];\n            row = new int[n-1][m];\n\n            dp = new long[n][m][21];\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m;j++){\n                    Arrays.fill(dp[i][j],oo);\n                }\n            }\n\n\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m-1;j++){\n                    col[i][j] = sc.nextInt();\n                }\n            }\n\n            for(int i=0;i<n-1;i++){\n                for(int j=0;j<m;j++){\n                    row[i][j] = sc.nextInt();\n                }\n            }\n\n            if(k%2!=0){\n                for(int i=0;i<n;i++){\n                    for(int j=0;j<m;j++){\n                        w.print(-1+\" \");\n                    }\n                    w.println(\"\");\n                }\n            }\n            else{\n                for(int i=0;i<n;i++){\n                    for(int j=0;j<m;j++){\n                        long ans = sol(i,j,k/2);\n                        w.print((ans*2)+\" \");\n                    }\n                    w.println(\"\");\n                }\n                \n\n\n\n\n            }\n            \n\n        }\n\n        w.flush();\n        w.close();\n\n    }\n\n    public long sol(int i, int j, int steps){\n        if(steps == 0)return 0;\n        else if(dp[i][j][steps]!=oo)return dp[i][j][steps];\n        else{\n            long ans = oo;\n            if(i-1>-1){\n                ans = Math.min(ans,sol(i-1,j,steps-1)+row[i-1][j]);\n            }\n            if(i+1<n){\n                ans = Math.min(ans,sol(i+1,j,steps-1)+row[i][j]);\n            }\n            if(j-1>-1){\n                ans = Math.min(ans,sol(i,j-1,steps-1)+col[i][j-1]);\n            }\n            if(j+1<m){\n                ans = Math.min(ans,sol(i,j+1,steps-1)+col[i][j]);\n            }\n            dp[i][j][steps] = Math.min(dp[i][j][steps],ans);\n            return dp[i][j][steps];\n        }\n    }\n   \n\n   \n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;import java.io.*;import java.math.*;\npublic class Main\n{\n    static int[][] l,r,u,d;\n    static int[][][]dist;\n    static int inf=Integer.MAX_VALUE;\n    static class Node{\n        int x,y,len,dis;\n        Node(int x,int y,int len,int dis){\n            this.x=x;this.y=y;this.len=len;this.dis=dis;\n        }\n    }\n    public static void process()throws IOException\n    {\n        int n=ni();\n        int m=ni();\n        int k=ni();\n        dist=new int[n][m][k/2+1];\n        l=new int[n][m];\n        r=new int[n][m];\n        for(int i=0;i<n;i++)\n            for(int j=0;j<m-1;j++)\n                l[i][j]=r[i][j+1]=ni();\n        u=new int[n][m];\n        d=new int[n][m];\n        for(int i=0;i<n-1;i++)\n            for(int j=0;j<m;j++)\n                d[i][j]=u[i+1][j]=ni();\n        if(k%2==1)\n        {\n            for(int i=0;i<n;i++)\n            {\n                for(int j=0;j<m;j++)\n                    p(\"-1 \");\n                pn(\"\");\n            }\n            return;\n        }\n        k/=2;\n        for(int kk=1;kk<=k;kk++)\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                dist[i][j][kk]=inf;\n                if(i!=0)\n                    dist[i][j][kk]=Math.min(dist[i][j][kk],dist[i-1][j][kk-1]+u[i][j]);\n                if(i!=n-1)\n                    dist[i][j][kk]=Math.min(dist[i][j][kk],dist[i+1][j][kk-1]+d[i][j]);\n                if(j!=0)\n                    dist[i][j][kk]=Math.min(dist[i][j][kk],dist[i][j-1][kk-1]+r[i][j]);\n                if(j!=m-1)\n                    dist[i][j][kk]=Math.min(dist[i][j][kk],dist[i][j+1][kk-1]+l[i][j]);\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n                p(2*dist[i][j][k]+\" \");\n            pn(\"\");\n        }\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class D {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner();\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint[][] lr = new int[n][m-1];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tfor(int j = 0; j < m-1; j++){\n\t\t\t\tlr[i][j] = sc.nextInt();\n\t\t\t}\n\t\t}\n\t\tint[][] ud = new int[n-1][m];\n\t\tfor(int i = 0; i < n-1; i++){\n\t\t\tfor(int j = 0; j < m; j++){\n\t\t\t\tud[i][j] = sc.nextInt();\n\t\t\t}\n\t\t}\n\t\tif(k % 2 == 1) {\n\t\t\tStringBuilder sb = new StringBuilder();\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\tsb.append(-1+\" \");\n\t\t\t\t}\n\t\t\t\tsb.replace(sb.length()-1, sb.length(), \"\\n\");\n\t\t\t}\n\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\tpw.println(sb.toString().trim());\n\t\t\tpw.flush();\n\t\t}\n\t\telse {\n\t\t\tint[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};\n\t\t\tlong[][][] dp = new long[k/2+1][n][m];\n\t\t\tfor(int s = 1; s <= k/2; s++) {\n\t\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\t\tfor(int j = 0; j < m; j++){\n\t\t\t\t\t\tdp[s][i][j] = Long.MAX_VALUE;\n\t\t\t\t\t\tfor(int[] d: dir) {\n\t\t\t\t\t\t\tint u = i + d[0], v = j + d[1];\n\t\t\t\t\t\t\tif(u >= 0 && u < n && v >= 0 && v < m) {\n\t\t\t\t\t\t\t\tlong w = calc(i, j, u, v, lr, ud);\n\t\t\t\t\t\t\t\tdp[s][i][j] = Math.min(dp[s][i][j], dp[s-1][u][v] + 2*w);\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\tStringBuilder sb = new StringBuilder();\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\tsb.append(dp[k/2][i][j]+\" \");\n\t\t\t\t}\n\t\t\t\tsb.replace(sb.length()-1, sb.length(), \"\\n\");\n\t\t\t}\n\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\tpw.println(sb.toString().trim());\n\t\t\tpw.flush();\n\t\t}\n\t}\n\tstatic long calc(int i, int j, int u, int v, int[][] lr, int[][] ud) {\n\t\tif(i == u) {\n\t\t\treturn lr[i][Math.min(j, v)];\n\t\t}\n\t\telse {\n\t\t\treturn ud[Math.min(i, u)][j];\n\t\t}\n\t}\n\t\n\t\n\tstatic class Pair implements Comparable<Pair>{\n\t\tint x, y;\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x; this.y = y;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair p) {\n\t\t\tif(x == p.x) return y - p.y;\n\t\t\telse return x - p.x;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn x+\" \"+y;\n\t\t}\n\t}\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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.awt.image.BandedSampleModel;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.Scanner;\npublic class D{\n\n    static void sort(int[] A){\n\n        int n = A.length;\n        Random rnd = new Random();\n        for(int i=0; i<n; ++i){\n            int tmp = A[i];\n            int randomPos = i + rnd.nextInt(n-i);\n            A[i] = A[randomPos];\n            A[randomPos] = tmp;\n        }\n        Arrays.sort(A);\n    }\n\n    public static void main(String args[])\n    {\n        Scanner sc=new Scanner(System.in);\n        //int cases = sc.nextInt();\n\n        //for(int i=0;i<cases;i++)\n        {\n            int n = sc.nextInt();\n            int m=sc.nextInt();\n            int steps=sc.nextInt();\n            long arr[][][] = new long[n][m][5];\n            for(int j=0;j<n;j++)\n            {\n                for(int k=0;k<m-1;k++)\n                {\n                    long num=sc.nextLong();\n                    arr[j][k][1]=num;\n                    arr[j][k+1][3]=num;\n                }\n            }\n\n            for(int j=0;j<n-1;j++)\n            {\n                for(int k=0;k<m;k++)\n                {\n                    long num=sc.nextLong();\n                    arr[j][k][2]=num;\n                    arr[j+1][k][4]=num;\n                }\n            }\n\n            long temp[][]=new long[n][m];\n            long ans[][]=new long[n][m];\n            for(int i=0;i<steps/2;i++)\n            {\n                for(int j=0;j<n;j++)\n                {\n                    for(int k=0;k<m;k++)\n                    {\n                        long min=Long.MAX_VALUE;\n                        if(k>0)\n                        {\n                            long f=arr[j][k][3]+ans[j][k-1];\n                            min=Math.min(min,f);\n                        }\n\n                        if(k<m-1)\n                        {\n                            long f=arr[j][k][1]+ans[j][k+1];\n                            min=Math.min(min,f);\n                        }\n\n                        if(j>0)\n                        {\n                            long f=arr[j][k][4]+ans[j-1][k];\n                            min=Math.min(min,f);\n                        }\n\n                        if(j<n-1)\n                        {\n                            long f=arr[j][k][2]+ans[j+1][k];\n                            min=Math.min(min,f);\n                        }\n\n                        temp[j][k]=min;\n                    }\n                }\n\n                for(int j=0;j<n;j++)\n                {\n                    for(int k=0;k<m;k++)\n                    {\n                        ans[j][k]=temp[j][k];\n                    }\n                }\n            }\n\n\n            StringBuilder p=new StringBuilder();\n            for(int j=0;j<n;j++)\n            {\n                for(int k=0;k<m;k++)\n                {\n                    if(steps%2!=0)\n                    {\n                        p.append(-1+\" \");\n                    }\n                    else\n                    {\n                    p.append(2*ans[j][k]+\" \");}\n                }\n\n                p.append(\"\\n\");\n            }\n\n\n            System.out.println(p);\n        }\n\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.lang.*;\nimport java.util.function.Predicate;\n\npublic class Main{\n    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n    static long MOD = (long) (1e9 + 7);\n    //    static long MOD = 998244353;\n    static long MOD2 = MOD * MOD;\n    static FastReader sc = new FastReader();\n    static int pInf = Integer.MAX_VALUE;\n    static int nInf = Integer.MIN_VALUE;\n    static long ded = (long)(1e17)+9;\n    public static void main(String[] args) throws Exception {\n        int test = 1;\n//        test = sc.nextInt();\n        for (int i = 1; i <= test; i++){\n//            out.print(\"Case #\"+i+\": \");\n            solve();\n        }\n        out.flush();\n        out.close();\n    }\n    static int n,m;\n    static int[][] hor,ver;\n    static Long[][][] dp;\n    static void solve(){\n        n = sc.nextInt();\n        m = sc.nextInt();\n        int k = sc.nextInt();\n        dp = new Long[n+1][m+1][k+1];\n        hor = new int[n][m-1];\n        ver = new int[n-1][m];\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m-1; j++){\n                hor[i][j] = sc.nextInt();\n            }\n        }\n        for(int i = 0; i < n-1; i++){\n            for(int j = 0; j < m; j++){\n                ver[i][j] = sc.nextInt();\n            }\n        }\n        if(k%2==1){\n            for(int i = 0; i < n; i++){\n                for(int j = 0; j < m; j++){\n                    out.print(-1+\" \");\n                }\n                out.println();\n            }\n            return;\n        }\n        k = k/2;\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                long[] dp = new long[k+1];\n                for(int l = 1; l <= k; l++){\n                    dp[l] = cal(i,j,l);\n                }\n                for(int l = 1; l <= k; l++){\n                    for(int g = 1; g < l; g++){\n                        dp[l] = Math.min(dp[l],dp[g]+dp[l-g]);\n                    }\n                }\n                out.print(2*dp[k]+\" \");\n            }\n            out.println();\n        }\n    }\n    static long cal(int i, int j,int k){\n        if(k==0)return 0;\n        if(dp[i][j][k]!=null)return dp[i][j][k];\n        long ans = ded;\n        for(int h = 0; h < 4; h++){\n            int ni = i+di[h];\n            int nj = j+dj[h];\n            if(e(ni,nj)){\n                int cost = 0;\n                if(ni==i){\n                    if(nj>j){\n                        cost = hor[i][j];\n                    }else{\n                        cost = hor[i][nj];\n                    }\n                }if(nj==j){\n                    if(ni>i){\n                        cost = ver[i][j];\n                    }else{\n                        cost = ver[ni][j];\n                    }\n                }\n                ans = Math.min(ans,(cost)+cal(ni,nj,k-1));\n            }\n        }\n        return dp[i][j][k] =  ans;\n    }\n    static int[] di = new int[]{0,-1,0,1};\n    static int[] dj = new int[]{-1,0,1,0};\n    static boolean e(int i, int j){\n        return i>=0&&j>=0&&i<n&&j<m;\n    }\n    static class Pair implements Comparable<Pair> {\n        int x;\n        int y;\n        public Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n        @Override\n        public int compareTo(Pair o){\n            return this.x-o.x;\n        }\n\n        @Override\n        public String toString() {\n            return \"Pair{\" + \"x=\" + x + \", y=\" + y + '}';\n        }\n\n        public boolean equals(Pair o){\n            return this.x==o.x&&this.y==o.y;\n        }\n    }\n    public static long mul(long a, long b) {\n        return ((a % MOD) * (b % MOD)) % MOD;\n    }\n    public static long add(long a, long b) {\n        return ((a % MOD) + (b % MOD)) % MOD;\n    }\n    public static long c2(long n) {\n        if ((n & 1) == 0) {\n            return mul(n / 2, n - 1);\n        } else {\n            return mul(n, (n - 1) / 2);\n        }\n    }\n    //Shuffle Sort\n    static final Random random = new Random();\n    static void ruffleSort(int[] a) {\n        int n = a.length;//shuffle, then sort\n        for (int i = 0; i < n; i++) {\n            int oi = random.nextInt(n); int temp= a[oi];\n            a[oi] = a[i];\n            a[i] = temp;\n        }\n        Arrays.sort(a);\n    }\n    //Brian Kernighans Algorithm\n    static long countSetBits(long n) {\n        if (n == 0) return 0;\n        return 1 + countSetBits(n & (n - 1));\n    }\n    //Euclidean Algorithm\n    static long gcd(long A, long B) {\n        if (B == 0) return A;\n        return gcd(B, A % B);\n    }\n    //Modular Exponentiation\n    static long fastExpo(long x, long n) {\n        if (n == 0) return 1;\n        if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD;\n        return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD;\n    }\n    //AKS Algorithm\n    static boolean isPrime(long n) {\n        if (n <= 1) return false;\n        if (n <= 3) return true;\n        if (n % 2 == 0 || n % 3 == 0) return false;\n        for (int i = 5; i <= Math.sqrt(n); i += 6)\n            if (n % i == 0 || n % (i + 2) == 0) return false;\n        return true;\n    }\n    public static long modinv(long x) {\n        return modpow(x, MOD - 2);\n    }\n    public static long modpow(long a, long b) {\n        if (b == 0) {\n            return 1;\n        }\n        long x = modpow(a, b / 2);\n        x = (x * x) % MOD;\n        if (b % 2 == 1) {\n            return (x * a) % MOD;\n        }\n        return x;\n    }\n\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.ObjectInputStream.GetField;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\nimport javax.sound.sampled.ReverbType;\n\n\npublic class N718 {\n\tstatic PrintWriter out;\n\tstatic Scanner sc;\n\tstatic ArrayList<int[]>q,w,x;\n\tstatic ArrayList<Integer>adj[];\n\tstatic HashSet<Integer>primesH;\n\tstatic boolean prime[];\n\t//static ArrayList<Integer>a;\n\tstatic HashSet<Long>tmp;\n\tstatic int[][][]dist;\n\tstatic boolean[]v;\n\tstatic int[]a,b,c,d;\n\tstatic Boolean[][]dp;\n\tstatic char[][]mp;\n\tstatic int A,B,n,m,h,ans,sum;\n\t//static String a,b;\n\tstatic long oo=(long)1e9+7;\n\tpublic static void main(String[]args) throws IOException {\n\t\tsc=new Scanner(System.in);\n\t\tout=new PrintWriter(System.out);\n\t\t//A();\n\t\t//B();\n\t\t//C();\n\t\tD();\n\t\t//E();\n\t\t//F();\n\t\t//G();\n\t\tout.close();\n\t}\n\t  private static void A() throws IOException {\n\t\t  int t=ni();\n\t\t  while(t-->0) {\n\t\t\t\tlong l=nl();\n\t\t\t\tif(l%2050!=0)ol(-1);\n\t\t\t\telse {\n\t\t\t\t\tlong num=l/2050;\n\t\t\t\t\tint cnt=0;\n\t\t\t\t\twhile(num>0) {\n\t\t\t\t\t\tcnt+=num%10;\n\t\t\t\t\t\tnum/=10;\n\t\t\t\t\t}\n\t\t\t\t\tol(cnt);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t  }\n\t\t\n\t   }\n\t\tstatic void B() throws IOException {\n\t\t\tint t=ni();\n\t\t\twhile(t-->0) {\n\t\t\t\tint n=ni(),m=ni();\n\t\t\t\tint[][]a=nmi(n,m);\n\t\t\t\tPriorityQueue<int[]>pq=new PriorityQueue<int[]>((u,v)->u[0]-v[0]);\n\t\t\t\tArrayList<Integer>[]nums=new ArrayList[n];\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\t//nums[i]=new ArrayList<Integer>();\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\t///nums[i].add(a[i][j]);\n\t\t\t\t\t\tpq.add(new int[] {a[i][j],i});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint[][]ans=new int[n][m];\n\t\t\t\tfor(int i=0;i<m;i++) {\n\t\t\t\t\tint[]x=pq.poll();\n\t\t\t\t\tans[x[1]][i]=x[0];\n\t\t\t\t}\n\t\t\t\tint []indices=new int[n];\n\t\t\t\twhile(!pq.isEmpty()) {\n\t\t\t\t\tint[]x=pq.poll();\n\t\t\t\t\tint i=x[1];\n\t\t\t\t\twhile(ans[i][indices[i]]!=0) {\n\t\t\t\t\t\tindices[i]++;\n\t\t\t\t\t}\n\t\t\t\t\tans[i][indices[i]]=x[0];\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\tout.print(ans[i][j]+\" \");\n\t\t\t\t\t}\n\t\t\t\t\tol(\"\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tstatic void C() throws IOException{\n\t\t\t int t=1;\n\t\t\t while(t-->0) {\n\t\t\t\t int n=ni();\n\t\t\t\t a=nai(n);\n\t\t\t\t int[][]ans=new int[n][n];\n\t\t\t\t for(int i=0;i<n;i++)ans[i][i]=a[i];\n\t\t\t\t for(int i=n-1;i>=0;i--) {\n\t\t\t\t\t int j=i,k=i;\n\t\t\t\t\t int cur=ans[i][i];\n\t\t\t\t\t cur--;\n\t\t\t\t\t while(cur>0) {\n\t\t\t\t\t\t j++;\n\t\t\t\t\t\t if(j>=n||ans[j][k]!=0) {\n\t\t\t\t\t\t\t j--;\n\t\t\t\t\t\t\t k--;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t ans[j][k]=ans[i][i];\n\t\t\t\t\t\t cur--;\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t\t for(int i=0;i<n;i++) {\n\t\t\t\t\t for(int j=0;j<=i;j++) {\n\t\t\t\t\t\t out.print(ans[i][j]+\" \");\n\t\t\t\t\t }\n\t\t\t\t\t ol(\"\");\n\t\t\t\t }\n\t\t\t }\n\t\t}\n\t\tprivate static Boolean dp(int i, int j) {\n\t\t\tif(j>sum/2)return false;\n\t\t\tif(i==x.size()) {\n\t\t\t\treturn sum/2==j;\n\t\t\t}\n\t\t\tif(dp[i][j]!=null)return dp[i][j];\n\t\t\t\n\t\t\treturn dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);\n\t\t}\n\t\tstatic boolean isPrime(long n) {\n\t\t\tif(n==2)return true;\n\t\t\tif(n<2||n%2==0)return false;\n\t\t\t\n\t\t\tfor(long i=3L;i*i<n;i+=2l) {\n\t\t\t\tlong rem=(n%i);\n\t\t\t\tif(rem==0)return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tstatic void D() throws IOException {\n\t\t\tint t=1;\n\t\t\twhile(t-->0) {\n\t\t\t\tint n=ni(),m=ni(),k=ni();\n\t\t\t\tint[][]ans=new int[n][m];\n\t\t\t\tdist=new int[n][m][4];\n\t\t\t\tfor(int i=0;i<n;i++)for(int j=0;j>m;j++)\n\t\t\t\t\tArrays.fill(dist[i][j], Integer.MAX_VALUE);\n\t\t\t\tint x;\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tfor(int j=0;j<m-1;j++) {\n\t\t\t\t\t\tdist[i][j][2]=(x=ni());\n\t\t\t\t\t\tdist[i][j+1][3]=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n-1;i++) {\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\tdist[i][j][1]=(x=ni());\n\t\t\t\t\t\tdist[i+1][j][0]=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint[][]nans=new int[n][m];\n\t\t\t\tif(k%2==1) {\n\t\t\t\t\tfor(int i=0;i<n;i++)Arrays.fill(ans[i], -1);\n\t\t\t\t}else {\n\t\t\t\t\tfor(int ii=0;ii<k/2;ii++) {\n\t\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\t\tnans[i][j]=Integer.MAX_VALUE;\n\t\t\t\t\t\t\tif(i>0)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i-1][j]+2*dist[i-1][j][1]);\n\t\t\t\t\t\t\tif(i<n-1)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i+1][j]+2*dist[i+1][j][0]);\n\t\t\t\t\t\t\tif(j>0)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i][j-1]+2*dist[i][j-1][2]);\n\t\t\t\t\t\t\tif(j<m-1)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i][j+1]+2*dist[i][j+1][3]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint[][]tmp=ans;\n\t\t\t\t\tans=nans;\n\t\t\t\t\tnans=tmp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\tout.print(ans[i][j]+\" \");\n\t\t\t\t\t}\n\t\t\t\t\tol(\"\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprivate static int bfs(int i, int j,int k) {\n\t\t\tboolean [][]vis=new boolean[dist.length][dist[0].length];\n\t\t\tQueue<int[]>q=new LinkedList<int[]>();\n\t\t\tint mn=Integer.MAX_VALUE;\n\t\t\tq.add(new int[] {i,j,0,0});\n\t\t\tint[]dx=new int[] {-1,1,0,0};\n\t\t\tint[]dy=new int[] {0,0,1,-1};\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint []x=q.poll();\n\t\t\t\tvis[x[0]][x[1]]=true;\n\t\t\t\tint c=x[2];\n\t\t\t\tif(c>k/2)continue;\n\t\t\t\tif(c>0&&k%c==0&&(k/c)%2==0) {\n\t\t\t\t\tmn=Math.min(mn,x[3]*k/c );\n\t\t\t\t}\n\t\t\t\tfor(int a=0;a<4;a++) {\n\t\t\t\t\tint nx=x[0]+dx[a];\n\t\t\t\t\tint ny=x[1]+dy[a];\n\t\t\t\t\tif(valid(nx,ny)&&!vis[nx][ny]) {\n\t\t\t\t\t\tq.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\treturn mn;\n\t\t}\n\t\tprivate static boolean valid(int nx, int ny) {\n\t\t\treturn nx>=0&&nx<dist.length&&ny>=0&&ny<dist[0].length;\n\t\t}\n\t\tstatic int gcd (int a, int b) {\n\t\t    return b==0?a:gcd (b, a % b);\n\t\t}\n\t\t\n\tstatic void E() throws IOException {\n\t\tint t=ni();\n\t\twhile(t-->0) {\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n\tstatic void F() throws IOException {\n\t\tint t=ni();\n\t\twhile(t-->0) {\n\t\t\t\n\t\t}\n\t}\n\tstatic void CC() throws IOException {\n\t\tfor(int kk=2;kk<21;kk++) {\n\t\t\tol(kk+\"   -------\");\n\t\tint n=kk;\n\t\tint k=n-2;\n\t\tint msk=1<<k;\n\t\tint[]a=new int[k];\n\t\tfor(int i=0;i<a.length;i++)a[i]=i+2;\n\t\tint mx=1;\n\t\tint ms=0;\n\t\tfor(int i=1;i<msk;i++) {\n\t\t\tlong prod=1;\n\t\t\tint cnt=0;\n\t\t\tfor(int j=0;j<a.length;j++) {\n\t\t\t\tif(((i>>j)&1)!=0) {\n\t\t\t\t\tprod*=a[j];\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(cnt>=mx&&prod%n==1) {\n\t\t\t\tmx=cnt;\n\t\t\t\tms=i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tol(mx==1?mx:mx+1);\n\t\tout.print(1+\" \");\n\t\tlong pr=1;\n\t\tfor(int j=0;j<a.length;j++) {\n\t\t\tif(((ms>>j)&1)!=0) {\n\t\t\t\tout.print(a[j]+\" \");\n\t\t\t\tpr*=a[j];\n\t\t\t}\n\t\t}\n\t\tol(\"\");\n\t\tol(\"Prod: \"+pr);\n\t\tol(n+\"*\"+((pr-1)/n)+\" + \"+1);\n\t\t}\n\t}\n\tstatic int ni() throws IOException {\n\t\treturn sc.nextInt();\n\t}\n\tstatic double nd() throws IOException {\n\t\treturn sc.nextDouble();\n\t}\n\tstatic long nl() throws IOException {\n\t\treturn  sc.nextLong();\n\t}\n\tstatic String ns() throws IOException {\n\t\treturn sc.next();\n\t}\n\tstatic int[] nai(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] = sc.nextInt();\n\t\treturn a;\n\t}\n\tstatic long[] nal(int n) throws IOException {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextLong();\n\t\treturn a;\n\t}\n\tstatic int[][] nmi(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]=sc.nextInt();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\n\tstatic long[][] nml(int n,int m) throws IOException{\n\t\tlong[][]a=new long[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]=sc.nextLong();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\tstatic void o(String x) {\n\t\tout.print(x);\n\t}\n\tstatic void ol(String x) {\n\t\tout.println(x);\n\t}\n\tstatic void ol(int x) {\n\t\tout.println(x);\n\t}\n\tstatic void disp1(int []a) {\n\t\tfor(int i=0;i<a.length;i++) {\n\t\t\tout.print(a[i]+\" \");\n\t\t}\n\t\tout.println();\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\t\tpublic boolean hasNext() {return st.hasMoreTokens();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\t\n\t\tpublic double nextDouble() throws IOException {return Double.parseDouble(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\t\n\t\tpublic boolean ready() throws IOException {return br.ready(); }\n\t\t\n\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\n\npublic class P1517D {\n\t// author: Nagabhushan S Baddi\n\n\t// PRIMARY VARIABLES\n\tprivate static int n, m, k;\n\tprivate static int[][] hor, ver, a, b;\n\tprivate static long ans;\n\tprivate static int[][] id;\n\tprivate static Integer[][][] dp;\n\tprivate static int idf;\n\tprivate static String s, t;\n\tprivate static HashMap<Integer, ArrayList<Integer>> g;\n\n\t// CONSTANTS\n\tprivate static final int MOD = (int) 1e9 + 7;\n\n\tpublic static void main(String[] args) {\n\t\tn = ini();\n\t\tm = ini();\n\t\tk = ini();\n\t\t\n\t\tif (k%2!=0) {\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\tprint(-1+\" \");\n\t\t\t\t}\n\t\t\t\tprintln();\n\t\t\t}\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n\n\t\thor = new int[n][m-1];\n\t\tver = new int[n-1][m];\n\t\t\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tfor(int j=0; j<m-1; j++) {\n\t\t\t\thor[i][j] = ini();\n\t\t\t}\n\t\t}\n\t\tfor(int i=0; i<n-1; i++) {\n\t\t\tfor(int j=0; j<m; j++) {\n\t\t\t\tver[i][j] = ini();\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new Integer[n][m][k+1];\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\tprint(2*solve(i, j, k/2)+\" \");\n\t\t\t}\n\t\t\tprintln();\n\t\t}\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\n\t}\n\t\n\tprivate static int solve(int i, int j, int kLeft) {\n\t\tif (i<0 || i>=n || j<0 || j>=m) {\n\t\t\treturn (int)1e9;\n\t\t} else if (kLeft==0) {\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\tif (dp[i][j][kLeft]!=null) {\n\t\t\treturn dp[i][j][kLeft];\n\t\t}\n\t\t\n\t\tint ans = (int)1e9;\n\t\t\n\t\tfinal int[] dx = {-1, 1, 0, 0};\n\t\tfinal int[] dy = {0, 0, -1, 1};\n\t\t\n\t\tfor(int type=0; type<4; type++) {\n\t\t\tint ni = i+dx[type];\n\t\t\tint nj = j+dy[type];\n\t\t\tif (ni<0 || ni>=n || nj<0 || nj>=m) continue;\n\t\t\t\n\t\t\tint inhibit = 0;\n\t\t\tif (type==0) {\n\t\t\t\tinhibit = ver[ni][nj];\n\t\t\t} else if (type==1) {\n\t\t\t\tinhibit = ver[i][j];\n\t\t\t} else if (type==2) {\n\t\t\t\tinhibit = hor[ni][nj];\n\t\t\t} else {\n\t\t\t\tinhibit = hor[i][j];\n\t\t\t}\n\t\t\t\n\t\t\tans = Math.min(ans, inhibit+solve(ni, nj, kLeft-1));\n\t\t}\n\t\t\n\t\treturn dp[i][j][kLeft]=ans;\n\t}\n\n\t// INIT\n\tprivate static void initCase(int z) {\n\t\tidf = z;\n\t\tans = 0;\n\t}\n\n\t// PRINT ANSWER\n\tprivate static void printAns(Object o) {\n\t\tout.println(o);\n\t}\n\n\tprivate static void printAns(Object o, int testCaseNo) {\n\t\tout.println(\"Case #\" + testCaseNo + \": \" + o);\n\t}\n\n\tprivate static void printArray(Object[] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tout.print(a[i] + \" \");\n\t\t}\n\t\tout.println();\n\t}\n\n\t// SORT SHORTCUTS - QUICK SORT TO MERGE SORT\n\tprivate static void sort(int[] a) {\n\t\tint n = a.length;\n\t\tInteger[] b = new Integer[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = a[i];\n\t\t}\n\n\t\tArrays.sort(b);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = b[i];\n\t\t}\n\t}\n\n\tprivate static void sort(long[] a) {\n\t\tint n = a.length;\n\t\tLong[] b = new Long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = a[i];\n\t\t}\n\n\t\tArrays.sort(b);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = b[i];\n\t\t}\n\t}\n\n\t// INPUT SHORTCUTS\n\n\tprivate static int[] ina(int n) {\n\t\tint[] temp = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttemp[i] = in.nextInt();\n\t\t}\n\t\treturn temp;\n\t}\n\n\tprivate static int[][] ina2d(int n, int m) {\n\t\tint[][] temp = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttemp[i] = ina(m);\n\t\t}\n\t\treturn temp;\n\t}\n\n\tprivate static int ini() {\n\t\treturn in.nextInt();\n\t}\n\n\tprivate static long inl() {\n\t\treturn in.nextLong();\n\t}\n\n\tprivate static double ind() {\n\t\treturn Double.parseDouble(ins());\n\t}\n\n\tprivate static String ins() {\n\t\treturn in.readString();\n\t}\n\n\t// PRINT SHORTCUTS\n\tprivate static void println(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \"\");\n\t\t}\n\t\tout.write(\"\\n\");\n\t}\n\n\tprivate static void pd(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \"\");\n\t\t}\n\t\tout.flush();\n\t\tout.write(\"\\n\");\n\t}\n\n\tprivate static void print(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \"\");\n\t\t}\n\t}\n\n\t// GRAPH SHORTCUTS\n\tprivate static HashMap<Integer, ArrayList<Integer>> intree(int n) {\n\n\t\tHashMap<Integer, ArrayList<Integer>> g = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg.put(i, new ArrayList<>());\n\t\t}\n\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tint u = ini() - 1;\n\t\t\tint v = ini() - 1;\n\t\t\tg.get(u).add(v);\n\t\t\tg.get(v).add(u);\n\t\t}\n\n\t\treturn g;\n\t}\n\n\tprivate static HashMap<Integer, ArrayList<Integer>> ingraph(int n, int m) {\n\t\tHashMap<Integer, ArrayList<Integer>> g = new HashMap<>();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg.put(i, new ArrayList<>());\n\t\t}\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = ini() - 1;\n\t\t\tint v = ini() - 1;\n\t\t\tg.get(u).add(v);\n\t\t\tg.get(v).add(u);\n\t\t}\n\n\t\treturn g;\n\n\t}\n\n\tprivate static HashMap<Integer, ArrayList<Integer>> indirectedgraph(int n, int m) {\n\t\tHashMap<Integer, ArrayList<Integer>> g = new HashMap<>();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg.put(i, new ArrayList<>());\n\t\t}\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = ini() - 1;\n\t\t\tint v = ini() - 1;\n\t\t\tg.get(u).add(v);\n\t\t}\n\n\t\treturn g;\n\n\t}\n\n\tprivate static HashMap<Integer, ArrayList<Edge>> inweightedgraph(int n, int m) {\n\t\tHashMap<Integer, ArrayList<Edge>> g = new HashMap<>();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg.put(i, new ArrayList<>());\n\t\t}\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = ini() - 1;\n\t\t\tint v = ini() - 1;\n\t\t\tint w = ini();\n\t\t\tEdge edge = new Edge(u, v, w);\n\t\t\tg.get(u).add(edge);\n\t\t\tg.get(v).add(edge);\n\t\t}\n\n\t\treturn g;\n\n\t}\n\n\tprivate static class Edge implements Comparable<Edge> {\n\t\tprivate int u, v;\n\t\tprivate long w;\n\n\t\tpublic Edge(int a, int b, long c) {\n\t\t\tu = a;\n\t\t\tv = b;\n\t\t\tw = c;\n\t\t}\n\n\t\tpublic int other(int x) {\n\t\t\treturn (x == u ? v : u);\n\t\t}\n\n\t\tpublic int compareTo(Edge edge) {\n\t\t\treturn Long.compare(w, edge.w);\n\t\t}\n\t}\n\n\tprivate static class Pair {\n\t\tprivate int u, v;\n\n\t\tpublic Pair(int a, int b) {\n\t\t\tu = a;\n\t\t\tv = b;\n\t\t}\n\n\t\tpublic int hashCode() {\n\t\t\treturn u + v + u * v;\n\t\t}\n\n\t\tpublic boolean equals(Object object) {\n\t\t\tPair pair = (Pair) object;\n\t\t\treturn u == pair.u && v == pair.v;\n\t\t}\n\t}\n\n\tprivate static class Node implements Comparable<Node> {\n\t\tprivate int u;\n\t\tprivate long dist;\n\n\t\tpublic Node(int a, long b) {\n\t\t\tu = a;\n\t\t\tdist = b;\n\t\t}\n\n\t\tpublic int compareTo(Node node) {\n\t\t\treturn Long.compare(dist, node.dist);\n\t\t}\n\t}\n\n\t// MATHS AND NUMBER THEORY SHORTCUTS\n\tprivate static int gcd(int a, int b) {\n\t\t// O(log(min(a,b)))\n\t\tif (b == 0)\n\t\t\treturn a;\n\n\t\treturn gcd(b, a % b);\n\t}\n\n\tprivate static long modExp(long a, long b) {\n\t\tif (b == 0)\n\t\t\treturn 1;\n\n\t\ta %= MOD;\n\n\t\tlong exp = modExp(a, b / 2);\n\n\t\tif (b % 2 == 0) {\n\t\t\treturn (exp * exp) % MOD;\n\t\t} else {\n\t\t\treturn (a * ((exp * exp) % MOD)) % MOD;\n\t\t}\n\t}\n\n\tprivate long mul(int a, int b) {\n\t\treturn a * 1L * b;\n\t}\n\n\t// Segment Tree\n\tprivate static class SegmentTree<T extends Comparable<T>> {\n\t\tprivate int n, m;\n\t\tprivate T[] a;\n\t\tprivate T[] seg;\n\t\tprivate T NULLVALUE;\n\n\t\tpublic SegmentTree(int n, T NULLVALUE) {\n\t\t\tthis.NULLVALUE = NULLVALUE;\n\t\t\tthis.n = n;\n\t\t\tm = 4 * n;\n\t\t\tseg = (T[]) new Object[m];\n\n\t\t}\n\n\t\tpublic SegmentTree(T[] a, int n, T NULLVALUE) {\n\t\t\tthis.NULLVALUE = NULLVALUE;\n\t\t\tthis.a = a;\n\t\t\tthis.n = n;\n\t\t\tm = 4 * n;\n\t\t\tseg = (T[]) new Object[m];\n\t\t\tconstruct(0, n - 1, 0);\n\t\t}\n\n\t\tprivate void update(int pos) {\n\t\t\t// Range Sum\n\t\t\t// seg[pos] = seg[2*pos+1]+seg[2*pos+2];\n\n\t\t\t// Range Min\n\t\t\tif (seg[2 * pos + 1].compareTo(seg[2 * pos + 2]) <= 0) {\n\t\t\t\tseg[pos] = seg[2 * pos + 1];\n\t\t\t} else {\n\t\t\t\tseg[pos] = seg[2 * pos + 2];\n\t\t\t}\n\t\t}\n\n\t\tprivate T optimum(T leftValue, T rightValue) {\n\t\t\t// Range Sum\n\t\t\t// return leftValue+rightValue;\n\n\t\t\t// Range Min\n\t\t\tif (leftValue.compareTo(rightValue) <= 0) {\n\t\t\t\treturn leftValue;\n\t\t\t} else {\n\t\t\t\treturn rightValue;\n\t\t\t}\n\t\t}\n\n\t\tpublic void construct(int low, int high, int pos) {\n\t\t\tif (low == high) {\n\t\t\t\tseg[pos] = a[low];\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint mid = (low + high) / 2;\n\n\t\t\tconstruct(low, mid, 2 * pos + 1);\n\t\t\tconstruct(mid + 1, high, 2 * pos + 2);\n\t\t\tupdate(pos);\n\t\t}\n\n\t\tpublic void add(int index, T value) {\n\t\t\tadd(index, value, 0, n - 1, 0);\n\t\t}\n\n\t\tprivate void add(int index, T value, int low, int high, int pos) {\n\t\t\tif (low == high) {\n\t\t\t\tseg[pos] = value;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint mid = (low + high) / 2;\n\n\t\t\tif (index <= mid) {\n\t\t\t\tadd(index, value, low, mid, 2 * pos + 1);\n\t\t\t} else {\n\t\t\t\tadd(index, value, mid + 1, high, 2 * pos + 2);\n\t\t\t}\n\t\t\tupdate(pos);\n\t\t}\n\n\t\tpublic T get(int qlow, int qhigh) {\n\t\t\treturn get(qlow, qhigh, 0, n - 1, 0);\n\t\t}\n\n\t\tpublic T get(int qlow, int qhigh, int low, int high, int pos) {\n\t\t\tif (qlow > low || low > qhigh) {\n\t\t\t\treturn NULLVALUE;\n\t\t\t} else if (qlow <= low || qhigh >= high) {\n\t\t\t\treturn seg[pos];\n\t\t\t} else {\n\t\t\t\tint mid = (low + high) / 2;\n\t\t\t\tT leftValue = get(qlow, qhigh, low, mid, 2 * pos + 1);\n\t\t\t\tT rightValue = get(qlow, qhigh, mid + 1, high, 2 * pos + 2);\n\n\t\t\t\treturn optimum(leftValue, rightValue);\n\t\t\t}\n\t\t}\n\t}\n\n\t// DSU\n\tprivate static class DSU {\n\t\tprivate int[] id;\n\t\tprivate int[] size;\n\t\tprivate int n;\n\n\t\tpublic DSU(int n) {\n\t\t\tthis.n = n;\n\n\t\t\tid = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tid[i] = i;\n\t\t\t}\n\n\t\t\tsize = new int[n];\n\t\t\tArrays.fill(size, 1);\n\t\t}\n\n\t\tprivate int root(int u) {\n\t\t\twhile (u != id[u]) {\n\t\t\t\tid[u] = id[id[u]];\n\t\t\t\tu = id[u];\n\t\t\t}\n\t\t\treturn u;\n\t\t}\n\n\t\tpublic boolean connected(int u, int v) {\n\t\t\treturn root(u) == root(v);\n\t\t}\n\n\t\tpublic void union(int u, int v) {\n\t\t\tint p = root(u);\n\t\t\tint q = root(v);\n\n\t\t\tif (size[p] >= size[q]) {\n\t\t\t\tid[q] = p;\n\t\t\t\tsize[p] += size[q];\n\t\t\t} else {\n\t\t\t\tid[p] = q;\n\t\t\t\tsize[q] += size[p];\n\t\t\t}\n\t\t}\n\t}\n\n\t// KMP\n\tprivate static int countSearch(String s, String p) {\n\t\tint n = s.length();\n\t\tint m = p.length();\n\n\t\tint[] b = backTable(p);\n\n\t\tint j = 0;\n\t\tint count = 0;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (j == m) {\n\t\t\t\tj = b[j - 1];\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\twhile (j != 0 && s.charAt(i) != p.charAt(j)) {\n\t\t\t\tj = b[j - 1];\n\t\t\t}\n\t\t\tif (s.charAt(i) == p.charAt(j)) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t}\n\n\t\tif (j == m)\n\t\t\tcount++;\n\n\t\treturn count;\n\t}\n\n\tprivate static int[] backTable(String p) {\n\t\tint m = p.length();\n\n\t\tint j = 0;\n\t\tint[] b = new int[m];\n\n\t\tfor (int i = 1; i < m; i++) {\n\t\t\twhile (j != 0 && p.charAt(i) != p.charAt(j)) {\n\t\t\t\tj = b[j - 1];\n\t\t\t}\n\t\t\tif (p.charAt(i) == p.charAt(j)) {\n\t\t\t\tb[i] = ++j;\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\n\tprivate static class LCA {\n\t\tprivate HashMap<Integer, ArrayList<Integer>> g;\n\t\tprivate int[] level;\n\t\tprivate int[] a;\n\t\tprivate int[][] P;\n\t\tprivate int n, m;\n\t\tprivate int[] xor;\n\n\t\tpublic LCA(HashMap<Integer, ArrayList<Integer>> g, int[] a) {\n\t\t\tthis.g = g;\n\t\t\tthis.a = a;\n\t\t\tn = g.size();\n\t\t\tm = (int) (Math.log(n) / Math.log(2)) + 5;\n\t\t\tP = new int[n][m];\n\t\t\txor = new int[n];\n\t\t\tlevel = new int[n];\n\n\t\t\tpreprocess();\n\t\t}\n\n\t\tprivate void preprocess() {\n\t\t\tdfs(0, -1);\n\n\t\t\tfor (int j = 1; j < m; j++) {\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (P[i][j - 1] != -1) {\n\t\t\t\t\t\tP[i][j] = P[P[i][j - 1]][j - 1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate void dfs(int u, int p) {\n\t\t\tP[u][0] = p;\n\t\t\txor[u] = a[u] ^ (p == -1 ? 0 : xor[p]);\n\t\t\tlevel[u] = (p == -1 ? 0 : level[p] + 1);\n\n\t\t\tfor (int v : g.get(u)) {\n\t\t\t\tif (v == p)\n\t\t\t\t\tcontinue;\n\t\t\t\tdfs(v, u);\n\t\t\t}\n\t\t}\n\n\t\tpublic int lca(int u, int v) {\n\t\t\tif (level[v] > level[u]) {\n\t\t\t\tint temp = v;\n\t\t\t\tv = u;\n\t\t\t\tu = temp;\n\t\t\t}\n\n\t\t\tfor (int j = m; j >= 0; j--) {\n\t\t\t\tif (level[u] - (1 << j) < level[v]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tu = P[u][j];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (u == v)\n\t\t\t\treturn u;\n\n\t\t\tfor (int j = m - 1; j >= 0; j--) {\n\t\t\t\tif (P[u][j] == -1 || P[u][j] == P[v][j]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tu = P[u][j];\n\t\t\t\t\tv = P[v][j];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn P[u][0];\n\t\t}\n\n\t\tprivate int xor(int u, int v) {\n\t\t\tint l = lca(u, v);\n\n\t\t\treturn xor[u] ^ xor[v] ^ a[l];\n\t\t}\n\t}\n\n\t// FAST INPUT OUTPUT LIBRARY\n\tprivate static InputReader in = new InputReader(System.in);\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\n\tprivate static class InputReader {\n\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\n\t\tpublic InputReader(InputStream st) {\n\t\t\tthis.stream = st;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t}\n}\n\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "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 Lynn\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        Scanner in;\n        PrintWriter out;\n\n        public void solve(int testNumber, Scanner in, PrintWriter out) {\n            this.in = in;\n            this.out = out;\n            run();\n        }\n\n        void run() {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            int k = in.nextInt();\n            int[][][] dis = new int[n][m][4];\n            int[][] dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n            int tmp;\n            final int M = (int) (1e8);\n            Algo.fill(dis, M);\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m - 1; j++) {\n                    tmp = in.nextInt();\n                    dis[i][j][0] = tmp;\n                    dis[i][j + 1][1] = tmp;\n                }\n            }\n            for (int i = 0; i < n - 1; i++) {\n                for (int j = 0; j < m; j++) {\n                    tmp = in.nextInt();\n                    dis[i][j][2] = tmp;\n                    dis[i + 1][j][3] = tmp;\n                }\n            }\n            int[][] ans = new int[n][m];\n\n            if (k % 2 == 1) {\n                Algo.fill(ans, -1);\n            } else {\n                int halfK = k / 2;\n                int[][][] dp = new int[halfK + 1][n][m];\n                Algo.fill(dp, M);\n\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        dp[0][i][j] = 0;\n                    }\n                }\n\n                for (int step = 1; step <= halfK; step++) {\n                    for (int i = 0; i < n; i++) {\n                        for (int j = 0; j < m; j++) {\n                            for (int d = 0; d < dir.length; d++) {\n                                int toX = i + dir[d][0];\n                                int toY = j + dir[d][1];\n                                if (toX < 0 || toY < 0 || toX >= n || toY >= m) continue;\n                                dp[step][i][j] = Math.min(dp[step - 1][toX][toY] + 2 * dis[i][j][d], dp[step][i][j]);\n                            }\n                        }\n                    }\n                }\n                ans = dp[halfK];\n            }\n\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.print(ans[i][j]);\n                    out.print(' ');\n                }\n                out.println(\"\");\n            }\n\n\n        }\n\n    }\n\n    static class Algo {\n        public static void fill(int[][] iss, int v) {\n            for (int[] is : iss) Arrays.fill(is, v);\n        }\n\n        public static void fill(int[][][] isss, int v) {\n            for (int[][] iss : isss) Algo.fill(iss, v);\n        }\n\n    }\n\n    static class Scanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public Scanner(InputStream in) {\n            br = new BufferedReader(new InputStreamReader(in));\n            eat(\"\");\n        }\n\n        private void eat(String s) {\n            st = new StringTokenizer(s);\n        }\n\n        public String nextLine() {\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                return null;\n            }\n        }\n\n        public boolean hasNext() {\n            while (!st.hasMoreTokens()) {\n                String s = nextLine();\n                if (s == null)\n                    return false;\n                eat(s);\n            }\n            return true;\n        }\n\n        public String next() {\n            hasNext();\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        Main m = new Main();\n        m.run();\n        m.out.close();\n    }\n\n    void run() throws IOException {\n        int n = nextInt();\n        int m = nextInt();\n        int k = nextInt();\n        long[][] r = new long[n][m - 1];\n        long[][] d = new long[n - 1][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m - 1; j++) {\n                r[i][j] = nextInt();\n            }\n        }\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = 0; j < m; j++) {\n                d[i][j] = nextInt();\n            }\n        }\n        if (k % 2 != 0) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.print(-1+\" \");\n                }\n                out.println();\n            }\n            return;\n        }\n        long[][][] dp = new long[n][m][k + 1];\n        for (int kk = 2; kk <= k; kk += 2)\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    long ans = (long) 1e18;\n                    if (i + 1 < n) {\n                        ans = Math.min(ans, dp[i + 1][j][kk - 2] + d[i][j]*2);\n                    }\n                    if (i - 1 > -1) ans = Math.min(ans, dp[i - 1][j][kk - 2] + d[i - 1][j]*2);\n                    if (j + 1 < m) ans = Math.min(ans, dp[i][j + 1][kk - 2] + r[i][j]*2);\n                    if (j - 1 > -1) ans = Math.min(ans, dp[i][j - 1][kk - 2] + r[i][j - 1]*2);\n                    dp[i][j][kk] = ans;\n                }\n            }\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                out.print(dp[i][j][k] + \" \");\n            }\n            out.println();\n        }\n    }\n\n\n    int gcd(int a, int b) {\n        while (a % b != 0) {\n            int h = a % b;\n            a = b;\n            b = h;\n        }\n        return b;\n    }\n\n    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    PrintWriter out = new PrintWriter(System.out);\n    StringTokenizer in = new StringTokenizer(\"\");\n\n\n    // pairs\n    class pil implements Comparable<pil> {\n        int first;\n        long second;\n\n        pil(int f, long s) {\n            this.first = f;\n            this.second = s;\n        }\n\n        public int compareTo(pil o) {\n            if (first != o.first) return Integer.compare(first, o.first);\n            return Long.compare(second, o.second);\n        }\n    }\n\n    class pii implements Comparable<pii> {\n        int fi;\n        int se;\n\n        pii(int f, int s) {\n            se = s;\n            fi = f;\n        }\n\n        public int compareTo(pii o) {\n            if (fi != o.fi) return Integer.compare(fi, o.fi);\n            return Integer.compare(se, o.se);\n        }\n    }\n\n    class pis implements Comparable<pis> {\n        int fi;\n        String s;\n\n        pis(int f, String s) {\n            this.s = s;\n            fi = f;\n        }\n\n        public int compareTo(pis o) {\n            return Integer.compare(fi, o.fi);\n        }\n    }\n\n    class vert {\n        int to;\n        int iter;\n        int idx;\n        int ed;\n\n        vert(int s, int f, int zz, int gg) {\n            to = s;\n            iter = f;\n            idx = zz;\n            ed = gg;\n        }\n    }\n\n\n    class pll implements Comparable<pll> {\n        long first;\n        long second;\n\n        pll(long f, long s) {\n            this.first = f;\n            this.second = s;\n        }\n\n        public int compareTo(pll o) {\n            if (first != o.first) return Long.compare(first, o.first);\n            return Long.compare(second, o.second);\n        }\n    }\n\n    class pli implements Comparable<pli> {\n        long first;\n        int second;\n\n        pli(long f, int s) {\n            this.first = f;\n            this.second = s;\n        }\n\n        public int compareTo(pli o) {\n            if (first != o.first) return Long.compare(first, o.first);\n            return Integer.compare(second, o.second);\n        }\n    }\n\n    boolean hasNext() throws IOException {\n        if (in.hasMoreTokens()) return true;\n        String s;\n        while ((s = br.readLine()) != null) {\n            in = new StringTokenizer(s);\n            if (in.hasMoreTokens()) return true;\n        }\n        return false;\n    }\n\n    String nextToken() throws IOException {\n        while (!in.hasMoreTokens()) {\n            in = new StringTokenizer(br.readLine());\n        }\n        return in.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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.ObjectInputStream.GetField;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\nimport javax.sound.sampled.ReverbType;\n\n\npublic class N718 {\n\tstatic PrintWriter out;\n\tstatic Scanner sc;\n\tstatic ArrayList<int[]>q,w,x;\n\tstatic ArrayList<Integer>adj[];\n\tstatic HashSet<Integer>primesH;\n\tstatic boolean prime[];\n\t//static ArrayList<Integer>a;\n\tstatic HashSet<Long>tmp;\n\tstatic int[][][]dist;\n\tstatic boolean[]v;\n\tstatic int[]a,b,c,d;\n\tstatic Boolean[][]dp;\n\tstatic char[][]mp;\n\tstatic int A,B,n,m,h,ans,sum;\n\t//static String a,b;\n\tstatic long oo=(long)1e9+7;\n\tpublic static void main(String[]args) throws IOException {\n\t\tsc=new Scanner(System.in);\n\t\tout=new PrintWriter(System.out);\n\t\t//A();\n\t\t//B();\n\t\t//C();\n\t\tD();\n\t\t//E();\n\t\t//F();\n\t\t//G();\n\t\tout.close();\n\t}\n\t  private static void A() throws IOException {\n\t\t  int t=ni();\n\t\t  while(t-->0) {\n\t\t\t\tlong l=nl();\n\t\t\t\tif(l%2050!=0)ol(-1);\n\t\t\t\telse {\n\t\t\t\t\tlong num=l/2050;\n\t\t\t\t\tint cnt=0;\n\t\t\t\t\twhile(num>0) {\n\t\t\t\t\t\tcnt+=num%10;\n\t\t\t\t\t\tnum/=10;\n\t\t\t\t\t}\n\t\t\t\t\tol(cnt);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t  }\n\t\t\n\t   }\n\t\tstatic void B() throws IOException {\n\t\t\tint t=ni();\n\t\t\twhile(t-->0) {\n\t\t\t\tint n=ni(),m=ni();\n\t\t\t\tint[][]a=nmi(n,m);\n\t\t\t\tPriorityQueue<int[]>pq=new PriorityQueue<int[]>((u,v)->u[0]-v[0]);\n\t\t\t\tArrayList<Integer>[]nums=new ArrayList[n];\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\t//nums[i]=new ArrayList<Integer>();\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\t///nums[i].add(a[i][j]);\n\t\t\t\t\t\tpq.add(new int[] {a[i][j],i});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint[][]ans=new int[n][m];\n\t\t\t\tfor(int i=0;i<m;i++) {\n\t\t\t\t\tint[]x=pq.poll();\n\t\t\t\t\tans[x[1]][i]=x[0];\n\t\t\t\t}\n\t\t\t\tint []indices=new int[n];\n\t\t\t\twhile(!pq.isEmpty()) {\n\t\t\t\t\tint[]x=pq.poll();\n\t\t\t\t\tint i=x[1];\n\t\t\t\t\twhile(ans[i][indices[i]]!=0) {\n\t\t\t\t\t\tindices[i]++;\n\t\t\t\t\t}\n\t\t\t\t\tans[i][indices[i]]=x[0];\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\tout.print(ans[i][j]+\" \");\n\t\t\t\t\t}\n\t\t\t\t\tol(\"\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tstatic void C() throws IOException{\n\t\t\t int t=1;\n\t\t\t while(t-->0) {\n\t\t\t\t int n=ni();\n\t\t\t\t a=nai(n);\n\t\t\t\t int[][]ans=new int[n][n];\n\t\t\t\t for(int i=0;i<n;i++)ans[i][i]=a[i];\n\t\t\t\t for(int i=n-1;i>=0;i--) {\n\t\t\t\t\t int j=i,k=i;\n\t\t\t\t\t int cur=ans[i][i];\n\t\t\t\t\t cur--;\n\t\t\t\t\t while(cur>0) {\n\t\t\t\t\t\t j++;\n\t\t\t\t\t\t if(j>=n||ans[j][k]!=0) {\n\t\t\t\t\t\t\t j--;\n\t\t\t\t\t\t\t k--;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t ans[j][k]=ans[i][i];\n\t\t\t\t\t\t cur--;\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t\t for(int i=0;i<n;i++) {\n\t\t\t\t\t for(int j=0;j<=i;j++) {\n\t\t\t\t\t\t out.print(ans[i][j]+\" \");\n\t\t\t\t\t }\n\t\t\t\t\t ol(\"\");\n\t\t\t\t }\n\t\t\t }\n\t\t}\n\t\tprivate static Boolean dp(int i, int j) {\n\t\t\tif(j>sum/2)return false;\n\t\t\tif(i==x.size()) {\n\t\t\t\treturn sum/2==j;\n\t\t\t}\n\t\t\tif(dp[i][j]!=null)return dp[i][j];\n\t\t\t\n\t\t\treturn dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);\n\t\t}\n\t\tstatic boolean isPrime(long n) {\n\t\t\tif(n==2)return true;\n\t\t\tif(n<2||n%2==0)return false;\n\t\t\t\n\t\t\tfor(long i=3L;i*i<n;i+=2l) {\n\t\t\t\tlong rem=(n%i);\n\t\t\t\tif(rem==0)return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tstatic void D() throws IOException {\n\t\t\tint t=1;\n\t\t\twhile(t-->0) {\n\t\t\t\tint n=ni(),m=ni(),k=ni();\n\t\t\t\tint[][]ans=new int[n][m];\n\t\t\t\tdist=new int[n][m][4];\n\t\t\t\tfor(int i=0;i<n;i++)for(int j=0;j>m;j++)\n\t\t\t\t\tArrays.fill(dist[i][j], Integer.MAX_VALUE);\n\t\t\t\tint x;\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tfor(int j=0;j<m-1;j++) {\n\t\t\t\t\t\tdist[i][j][2]=(x=ni());\n\t\t\t\t\t\tdist[i][j+1][3]=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n-1;i++) {\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\tdist[i][j][1]=(x=ni());\n\t\t\t\t\t\tdist[i+1][j][0]=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint[][]nans=new int[n][m];\n\t\t\t\tif(k%2==1) {\n\t\t\t\t\tfor(int i=0;i<n;i++)Arrays.fill(ans[i], -1);\n\t\t\t\t}else {\n\t\t\t\t\tfor(int ii=0;ii<k/2;ii++) {\n\t\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\t\tnans[i][j]=Integer.MAX_VALUE;\n\t\t\t\t\t\t\tif(i>0)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i-1][j]+dist[i-1][j][1]);\n\t\t\t\t\t\t\tif(i<n-1)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i+1][j]+dist[i+1][j][0]);\n\t\t\t\t\t\t\tif(j>0)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i][j-1]+dist[i][j-1][2]);\n\t\t\t\t\t\t\tif(j<m-1)\n\t\t\t\t\t\t\t\tnans[i][j]=Math.min(nans[i][j], ans[i][j+1]+dist[i][j+1][3]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint[][]tmp=ans;\n\t\t\t\t\tans=nans;\n\t\t\t\t\tnans=tmp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\t\t\tif(ans[i][j]!=-1)ans[i][j]*=2;\n\t\t\t\t\t\tout.print(ans[i][j]+\" \");\n\t\t\t\t\t}\n\t\t\t\t\tol(\"\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprivate static int bfs(int i, int j,int k) {\n\t\t\tboolean [][]vis=new boolean[dist.length][dist[0].length];\n\t\t\tQueue<int[]>q=new LinkedList<int[]>();\n\t\t\tint mn=Integer.MAX_VALUE;\n\t\t\tq.add(new int[] {i,j,0,0});\n\t\t\tint[]dx=new int[] {-1,1,0,0};\n\t\t\tint[]dy=new int[] {0,0,1,-1};\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint []x=q.poll();\n\t\t\t\tvis[x[0]][x[1]]=true;\n\t\t\t\tint c=x[2];\n\t\t\t\tif(c>k/2)continue;\n\t\t\t\tif(c>0&&k%c==0&&(k/c)%2==0) {\n\t\t\t\t\tmn=Math.min(mn,x[3]*k/c );\n\t\t\t\t}\n\t\t\t\tfor(int a=0;a<4;a++) {\n\t\t\t\t\tint nx=x[0]+dx[a];\n\t\t\t\t\tint ny=x[1]+dy[a];\n\t\t\t\t\tif(valid(nx,ny)&&!vis[nx][ny]) {\n\t\t\t\t\t\tq.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\treturn mn;\n\t\t}\n\t\tprivate static boolean valid(int nx, int ny) {\n\t\t\treturn nx>=0&&nx<dist.length&&ny>=0&&ny<dist[0].length;\n\t\t}\n\t\tstatic int gcd (int a, int b) {\n\t\t    return b==0?a:gcd (b, a % b);\n\t\t}\n\t\t\n\tstatic void E() throws IOException {\n\t\tint t=ni();\n\t\twhile(t-->0) {\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n\tstatic void F() throws IOException {\n\t\tint t=ni();\n\t\twhile(t-->0) {\n\t\t\t\n\t\t}\n\t}\n\tstatic void CC() throws IOException {\n\t\tfor(int kk=2;kk<21;kk++) {\n\t\t\tol(kk+\"   -------\");\n\t\tint n=kk;\n\t\tint k=n-2;\n\t\tint msk=1<<k;\n\t\tint[]a=new int[k];\n\t\tfor(int i=0;i<a.length;i++)a[i]=i+2;\n\t\tint mx=1;\n\t\tint ms=0;\n\t\tfor(int i=1;i<msk;i++) {\n\t\t\tlong prod=1;\n\t\t\tint cnt=0;\n\t\t\tfor(int j=0;j<a.length;j++) {\n\t\t\t\tif(((i>>j)&1)!=0) {\n\t\t\t\t\tprod*=a[j];\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(cnt>=mx&&prod%n==1) {\n\t\t\t\tmx=cnt;\n\t\t\t\tms=i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tol(mx==1?mx:mx+1);\n\t\tout.print(1+\" \");\n\t\tlong pr=1;\n\t\tfor(int j=0;j<a.length;j++) {\n\t\t\tif(((ms>>j)&1)!=0) {\n\t\t\t\tout.print(a[j]+\" \");\n\t\t\t\tpr*=a[j];\n\t\t\t}\n\t\t}\n\t\tol(\"\");\n\t\tol(\"Prod: \"+pr);\n\t\tol(n+\"*\"+((pr-1)/n)+\" + \"+1);\n\t\t}\n\t}\n\tstatic int ni() throws IOException {\n\t\treturn sc.nextInt();\n\t}\n\tstatic double nd() throws IOException {\n\t\treturn sc.nextDouble();\n\t}\n\tstatic long nl() throws IOException {\n\t\treturn  sc.nextLong();\n\t}\n\tstatic String ns() throws IOException {\n\t\treturn sc.next();\n\t}\n\tstatic int[] nai(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] = sc.nextInt();\n\t\treturn a;\n\t}\n\tstatic long[] nal(int n) throws IOException {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextLong();\n\t\treturn a;\n\t}\n\tstatic int[][] nmi(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]=sc.nextInt();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\n\tstatic long[][] nml(int n,int m) throws IOException{\n\t\tlong[][]a=new long[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]=sc.nextLong();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\tstatic void o(String x) {\n\t\tout.print(x);\n\t}\n\tstatic void ol(String x) {\n\t\tout.println(x);\n\t}\n\tstatic void ol(int x) {\n\t\tout.println(x);\n\t}\n\tstatic void disp1(int []a) {\n\t\tfor(int i=0;i<a.length;i++) {\n\t\t\tout.print(a[i]+\" \");\n\t\t}\n\t\tout.println();\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\t\tpublic boolean hasNext() {return st.hasMoreTokens();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\t\n\t\tpublic double nextDouble() throws IOException {return Double.parseDouble(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\t\n\t\tpublic boolean ready() throws IOException {return br.ready(); }\n\t\t\n\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.io.*;\n \npublic class ExplorerSpace {\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    }\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\n\t    int nextInt() {\n\t        return Integer.parseInt(next());\n\t    }\n\n\t    long nextLong() {\n\t        return Long.parseLong(next());\n\t    }\n\n\t    double nextDouble() {\n\t        return Double.parseDouble(next());\n\t    }\n\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\n\t }\n\t\n    \n\tpublic static int[][][] dp; \n\t\n\tpublic static boolean valid(int i, int j, int n, int m)\n\t{\n\t\treturn i>=0 && i<n &&j>=0 && j<m;\n\t}\n\t\n\tpublic static void solution(int n, int m, int k, int[][] h, int[][] v)\n\t\t\t\n\t{\n\t\tif(k%2==1)\n\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<m; j++)\n\t\t\t\t   out.print(-1+\" \");\n\t\t\t\t\n\t\t\t\tout.println();\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdp = new int[n][m][k/2+1];\n\t\t\n\t\tfor(int t = 1; t<=k/2; t++)\n\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<m; j++)\n\t\t\t\t{\n\t\t\t\t\tdp[i][j][t] = Integer.MAX_VALUE;\n\t\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; i++)\n\t\t{\n\t\t\tfor(int j = 0; j<m; j++)\n\t\t\t{\n\t\t\t\tdp[i][j][0] = 0;\n\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tfor(int t = 1; t<=k/2; t++)\n\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<m; j++)\n\t\t\t\t{\n\t\t\t\t\tif(valid(i,j+1,n,m))\n\t\t\t\t\t\tdp[i][j][t] = Math.min(dp[i][j][t], h[i][j] + dp[i][j+1][t-1]); \n\t\t\t\t\n\t\t\t\t\tif(valid(i,j-1,n,m))\n\t\t\t\t\t\t dp[i][j][t] = Math.min(dp[i][j][t], h[i][j-1] + dp[i][j-1][t-1]);\n\t\t\t\t\n\t\t\t\t\tif(valid(i+1,j,n,m))\n\t\t\t\t\t\t dp[i][j][t] = Math.min(dp[i][j][t], v[i][j] + dp[i+1][j][t-1]); \n\t\t\t\n\t\t\t\t\tif(valid(i-1,j,n,m))\n\t\t\t\t\t\tdp[i][j][t] = Math.min(dp[i][j][t], v[i-1][j] + dp[i-1][j][t-1]); \n\t\t\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<n; i++)\n\t\t{\n\t\t\tfor(int j = 0; j<m; j++)\n\t\t\t\tout.print((dp[i][j][k/2]*2)+\" \");\n\t\t\t\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n        \nprivate static PrintWriter out = new PrintWriter(System.out);\n\npublic static void main (String[] args)\n{\n\tMyScanner s =  new MyScanner();\n     \n    int n = s.nextInt();\n    int m = s.nextInt();\n    int k = s.nextInt();\n    \n    int[][] h = new int[n][m-1];\n    \n    for(int i = 0; i<n; i++)\n    {\n    \tfor(int j = 0; j<m-1; j++)\n    \t{\n    \t\th[i][j] = s.nextInt();\n    \t}\n    }\n    \n    int[][] v = new int[n-1][m];\n    \n    for(int i = 0; i<n-1; i++)\n    {\n    \tfor(int j = 0; j<m; j++)\n    \t{\n    \t\tv[i][j] = s.nextInt();\n    \t}\n    }\n    \n    \n   solution(n,m,k,h,v);\n    \n    out.flush();\n    out.close();\n    \n}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces\n{\n    public static void main(String args[])throws Exception\n    {\n        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder sb=new StringBuilder();\n        String s[]=bu.readLine().split(\" \");\n        int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]),k=Integer.parseInt(s[2]);\n        int i,j,max=n*m,in[][]=new int[n][m],x=0;\n        if(k%2==1)  //not possible\n        {\n            for(i=0;i<n;i++)\n            {\n                for(j=0;j<m;j++) sb.append(\"-1 \");\n                sb.append(\"\\n\");\n            }\n            System.out.print(sb);\n            return;\n        }\n\n        for(i=0;i<n;i++)\n        for(j=0;j<m;j++) in[i][j]=x++;\n\n        ArrayList<Edge> g[]=new ArrayList[max];\n        for(i=0;i<max;i++) g[i]=new ArrayList<>();\n        for(i=0;i<n;i++)\n        {\n            s=bu.readLine().split(\" \");\n            for(j=0;j<m-1;j++)\n            {\n                int u=in[i][j],v=in[i][j+1],w=Integer.parseInt(s[j]);\n                g[u].add(new Edge(v,w));\n                g[v].add(new Edge(u,w));\n            }\n        }\n        for(i=0;i<n-1;i++)\n        {\n            s=bu.readLine().split(\" \");\n            for(j=0;j<m;j++)\n            {\n                int u=in[i][j],v=in[i+1][j],w=Integer.parseInt(s[j]);\n                g[u].add(new Edge(v,w));\n                g[v].add(new Edge(u,w));\n            }\n        }\n\n        k/=2;\n        int dp[][]=new int[k][max];\n        for(i=0;i<max;i++)\n        {\n            dp[0][i]=Integer.MAX_VALUE;\n            for(Edge e:g[i])\n            dp[0][i]=Math.min(dp[0][i],2*e.w);\n        }\n\n        for(i=1;i<k;i++)\n        for(j=0;j<max;j++)\n        {\n            dp[i][j]=Integer.MAX_VALUE;\n            for(Edge e:g[j])\n            dp[i][j]=Math.min(dp[i][j],dp[i-1][e.v]+2*e.w);\n        }\n\n        for(i=0;i<n;i++)\n        {\n            for(j=0;j<m;j++)\n            sb.append(dp[k-1][in[i][j]]+\" \");\n            sb.append(\"\\n\");\n        }\n        System.out.print(sb);\n    }\n\n    static class Edge\n    {\n        int v,w,d;\n        Edge(int a,int b)\n        {\n            v=a;\n            w=b;\n            d=0;\n        }\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n/**\n * A simple template for competitive programming problems.\n */\npublic class Solution {\n    //InputReader in = new InputReader(\"input.txt\");\n    final InputReader in = new InputReader(System.in);\n \n    final PrintWriter out = new PrintWriter(System.out);\n\n    int n,m;\n\n    void solve() {\n        n = in.nextInt();\n        m = in.nextInt();\n        int k = in.nextInt();\n\n        int[][] hor = new int[n][m-1];\n        int[][] ver = new int[n-1][m];\n\n        for(int i=0; i<n; i++) {\n            for(int j=0; j<m-1; j++) {\n                hor[i][j] = in.nextInt(); //hor[i][j]=mat[i][j] -> mat[i][j+1]\n            }\n        }\n\n        for(int i=0; i<n-1; i++) {\n            for(int j=0; j<m; j++) {\n                ver[i][j] = in.nextInt(); //ver[i][j]= mat[i][j] -> mat[i+1][j]\n            }\n        }\n\n        int[][] ans = new int[n][m];\n\n        if(k%2==1) {\n            for(int i=0; i<n; i++)\n                Arrays.fill(ans[i], -1);\n        } else {\n            for(int dummy=0; dummy<k>>1; dummy++) {\n                int[][] newAns = new int[n][m];\n                for(int i=0; i<n; i++) {\n                    Arrays.fill(newAns[i], Integer.MAX_VALUE);\n                    for(int j=0; j<m; j++) {\n                        if(isGood(i+1, j)) {\n                            newAns[i][j] = Math.min(newAns[i][j], 2*ver[i][j] + ans[i+1][j]);\n                        }\n                        if(isGood(i, j+1)) {\n                            newAns[i][j] = Math.min(newAns[i][j], 2*hor[i][j] + ans[i][j+1]);\n                        }\n                        if(isGood(i, j-1)) {\n                            newAns[i][j] = Math.min(newAns[i][j], 2*hor[i][j-1] + ans[i][j-1]);\n                        }\n                        if(isGood(i-1, j)) {\n                            newAns[i][j] = Math.min(newAns[i][j], 2*ver[i-1][j] + ans[i-1][j]);\n                        }\n                    }\n                }\n                ans = newAns;\n            }\n        }\n\n        for(int i=0; i<n; i++) {\n            for(int j=0; j<m; j++) {\n                out.print(ans[i][j] + \" \");\n            }\n            out.println();\n        }\n    }\n\n    boolean isGood(int i, int j) {\n        return i>=0 && i<n && j>=0 && j<m;\n    }\n\n    private void shuffle(int[] a) {\n        int n = a.length;\n        Random random = new Random();\n        random.nextInt();\n        for (int i = 0; i < n; i++) {\n            int change = i + random.nextInt(n - i);\n            swap(a, i, change);\n        }\n    }\n\n    private static void swap(int[] a, int i, int change) {\n        int helper = a[i];\n        a[i] = a[change];\n        a[change] = helper;\n    }\n\n    public static void main(final String[] args) throws FileNotFoundException {\n        final Solution s = new Solution();\n        final Long t1 = System.currentTimeMillis();\n        s.solve();\n        System.err.println(System.currentTimeMillis() - t1 + \" ms\");\n        s.out.close();\n    }\n\n    public Solution() throws FileNotFoundException {\n    }\n\n    private static class InputReader {\n        private final InputStream stream;\n        private final byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        Random r = new Random();\n        InputReader(final InputStream stream) {\n            this.stream = stream;\n        }\n\n        InputReader(final String fileName) {\n            InputStream stream = null;\n            try {\n                stream = new FileInputStream(fileName);\n            } catch (final FileNotFoundException e) {\n                e.printStackTrace();\n            }\n            this.stream = stream;\n        }\n\n        int[] nextArray(final int n) {\n            final int[] arr = new int[n];\n            for (int i = 0; i < n; i++)\n                arr[i] = nextInt();\n            return arr;\n        }\n\n        int[][] nextMatrix(final int n, final int m) {\n            final 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] = nextInt();\n            return matrix;\n        }\n\n        String nextLine() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            final StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isEndOfLine(c));\n            return res.toString();\n        }\n\n        String nextString() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            final StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        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 - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        int nextInt() {\n            int c = read();\n            while (isSpaceChar(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\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        double nextDouble() {\n            return Double.parseDouble(nextString());\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 (final IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        private boolean isSpaceChar(final int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private boolean isEndOfLine(final int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n    }\n \n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\n\nimport java.math.*;\nimport java.io.*;\n\npublic class Main {\n\tstatic int[][] to = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };\n\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\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\n\t\tint[][][] cost = new int[n][m][4];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m - 1; j++) {\n\t\t\t\tint u = in.nextInt();\n\t\t\t\tcost[i][j][1] = u;\n\t\t\t\tcost[i][j + 1][3] = u;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tint u = in.nextInt();\n\t\t\t\tcost[i][j][0] = u;\n\t\t\t\tcost[i + 1][j][2] = u;\n\t\t\t}\n\t\t}\n\n\t\tif (k % 2 == 0) {\n\t\t\tk = k / 2;\n\t\t\tint[][][] dp = new int[k + 1][n][m];\n\n\t\t\tfor (int i = 0; i <= k; i++) {\n\t\t\t\tfor (int x = 0; x < n; x++) {\n\t\t\t\t\tfor (int y = 0; y < m; y++) {\n\t\t\t\t\t\tif (i == 0) {\n\t\t\t\t\t\t\tdp[i][x][y] = 0;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tint min = 1000000000;\n\n\t\t\t\t\t\t\tfor (int way = 0; way < to.length; way++) {\n\t\t\t\t\t\t\t\tint nextx = x + to[way][0];\n\t\t\t\t\t\t\t\tint nexty = y + to[way][1];\n\n\t\t\t\t\t\t\t\tif (nextx >= 0 && nextx < n && nexty >= 0 && nexty < m) {\n\t\t\t\t\t\t\t\t\tmin = Math.min(min, dp[i - 1][nextx][nexty] + cost[x][y][way]);\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\tdp[i][x][y] = min;\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\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tif (j == m - 1) {\n\t\t\t\t\t\tout.printf(\"%d\\n\", dp[k][i][j] * 2);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout.printf(\"%d \", dp[k][i][j] * 2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tif (j == m - 1) {\n\t\t\t\t\t\tout.printf(\"-1\\n\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout.printf(\"-1 \");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tout.close();\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\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[] min;\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\tmin = new long[2 * pow];\n\t\t\tdelta = new long[2 * pow];\n\t\t\tfor (int i = 0; i < min.length; i++) {\n\t\t\t\tmin[i] = Long.MAX_VALUE / 2;\n\t\t\t}\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tmin[pow + i] = a[i];\n\t\t\t}\n\t\t\tfor (int i = pow - 1; i > 0; i--) {\n\t\t\t\tmin[i] = f(min[2 * i], min[2 * i + 1]);\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int l, int r) {\n\t\t\treturn get(1, 0, pow, l, r);\n\t\t}\n\n\t\tprivate long get(int v, int tl, int tr, int l, int r) {\n\t\t\tpush(v, tl, tr);\n\t\t\tif (l >= tr || r <= tl) {\n\t\t\t\treturn Long.MAX_VALUE / 2;\n\t\t\t}\n\t\t\tif (l <= tl && r >= tr) {\n\t\t\t\treturn min[v];\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\treturn f(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm, tr, l, r));\n\t\t}\n\n\t\tpublic void set(int l, int r, long x) {\n\t\t\tset(1, 0, pow, l, r, x);\n\t\t}\n\n\t\tprivate 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, tr, l, r, x);\n\t\t\tmin[v] = f(min[2 * v], min[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\tmin[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.min(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\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<Long, Integer> 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<Integer, Integer> 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\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\t// public class Vector implements Comparable<Vector> {\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<Line> {\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 Fraction implements Comparable<Fraction> {\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<Event> {\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\tpublic class MyStack {\n\t\tint[] st;\n\t\tint sz;\n\n\t\tpublic MyStack(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\tint mod = 1000000007;\n\n\tpublic int sum(int a, int b) {\n\t\tif (a + b >= mod) {\n\t\t\treturn a + b - mod;\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tpublic int diff(int a, int b) {\n\t\tif (a < b) {\n\t\t\treturn a + mod - b;\n\t\t}\n\t\treturn a - b;\n\t}\n\n\tpublic int mult(int a, int b) {\n\t\treturn (int) ((a * 1L * b) % (1L * mod));\n\t}\n\n\tpublic int pow(int x, int p) {\n\t\tif (p <= 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tint ans = pow(x, p / 2);\n\t\tans = mult(ans, ans);\n\t\tif (p % 2 == 1) {\n\t\t\tans = mult(ans, x);\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic int modInv(int x) {\n\t\treturn pow(x, mod - 2);\n\t}\n\n\tpublic int c_n_k(int n, int k) {\n\t\tif (n < 0 || k < 0 || n - k < 0) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn mult(fact[n], mult(factInv[k], factInv[n - k]));\n\t}\n\n\tpublic class LinAl01 {\n\n\t\tpublic class Vector {\n\t\t\tBitSet vec;\n\t\t\tBitSet swtch;\n\n\t\t\tpublic Vector(BitSet vec, BitSet swtch) {\n\t\t\t\tthis.vec = vec;\n\t\t\t\tthis.swtch = swtch;\n\t\t\t}\n\n\t\t\tpublic String toString() {\n\t\t\t\tString s = \"\";\n\t\t\t\tfor (int i = 0; i < basis.length; i++) {\n\t\t\t\t\ts += (vec.get(i) ? 1 : 0);\n\t\t\t\t}\n\t\t\t\ts += \" \";\n\t\t\t\tfor (int i = 0; i < basis.length; i++) {\n\t\t\t\t\ts += (swtch.get(i) ? 1 : 0);\n\t\t\t\t}\n\t\t\t\treturn s;\n\t\t\t}\n\t\t}\n\n\t\tint n;\n\t\tVector[] basis;\n\n\t\tpublic void update(Vector v) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (v.vec.get(i)) {\n\t\t\t\t\tif (basis[i] == null) {\n\t\t\t\t\t\tbasis[i] = v;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tv.vec.xor(basis[i].vec);\n\t\t\t\t\tv.swtch.xor(basis[i].swtch);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void diagonalize() {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (basis[i] == null) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\tif (basis[j] != null && basis[j].vec.get(i)) {\n\t\t\t\t\t\tbasis[j].vec.xor(basis[i].vec);\n\t\t\t\t\t\tbasis[j].swtch.xor(basis[i].swtch);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\tpublic class Point implements Comparable<Point> {\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\tpublic Point subtract(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 {\n\t\tPoint p;\n\t\tlong r;\n\n\t\tpublic Circle(Point p, long r) {\n\t\t\tthis.p = p;\n\t\t\tthis.r = r;\n\t\t}\n\n\t\tpublic boolean intersect(Line l) {\n\t\t\treturn Math.abs(l.a * p.x + l.b * p.y + l.c) / Math.hypot(l.a, l.b) < r;\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\t}\n\n\tpublic class Line {\n\t\tlong a;\n\t\tlong b;\n\t\tlong c;\n\n\t\tpublic Line(long a, long b, long c) {\n\t\t\tif (a < 0 || (a == 0 && b < 0)) {\n\t\t\t\ta = -a;\n\t\t\t\tb = -b;\n\t\t\t\tc = -c;\n\t\t\t\tlong gcd = gcd(a, Math.abs(b));\n\t\t\t\ta /= gcd;\n\t\t\t\tb /= gcd;\n\t\t\t}\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t\tthis.c = c;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn a + \" \" + b + \" \" + c;\n\t\t}\n\n//    public Line(Point a, Point b) {\n//      this.a = a.y - b.y;\n//      this.b = b.x - a.x;\n//      this.c = a.x * b.y - a.y * b.x;\n//    }\n\t}\n\n//  public long compareDist(Circle a, Circle b, Circle c) { // tangent to a, b; a.r, b.r may be < 0\n//    long x = b.p.x - a.p.x;\n//    long y = b.p.y - a.p.y;\n//    long r = b.r - a.r;\n//    long dx = c.p.x - a.p.x;\n//    long dy = c.p.y - a.p.y;\n//    long dr = c.r - a.r;\n//    long left = y * dx - x * dy;\n//    long sqrt = x * x + y * y - r * r;\n//    long right = dr * (x * x + y * y) - r * (x * dx + y * dy);\n//    if (sqrt == 0 || left == 0) {\n//      if (right > 0) {\n//        return -1;\n//      }\n//      if (right < 0) {\n//        return 1;\n//      }\n//      return 0;\n//    }\n//    if (right == 0) {\n//      if (left > 0) {\n//        return 1;\n//      }\n//      return -1;\n//    }\n//    if (left > 0 && right < 0) {\n//      return 1;\n//    }\n//    if (left < 0 && right > 0) {\n//      return -1;\n//    }\n//    int mult = 1;\n//    if (left < 0) {\n//      mult = -1;\n//    }\n//    return BigInteger.valueOf(left).pow(2).multiply(BigInteger.valueOf(sqrt))\n//        .compareTo(BigInteger.valueOf(right).pow(2)) * mult;\n//  }\n\n//  public boolean inOrTang(Circle a, Circle b, Circle c) {\n//    return compareDist(a, b, c) <= 0 && compareDist(a, b, new Circle(c.p, -c.r)) >= 0;\n//  }\n\n//  public boolean in(Circle a, Circle b, Circle c) {\n//    return compareDist(a, b, c) < 0 && compareDist(a, b, new Circle(c.p, -c.r)) > 0;\n//  }\n\n\tpublic long sqr(long a) {\n\t\treturn a * a;\n\t}\n\n//  public void tangents(Point c, long r1, long r2, ArrayList<Line> ans) {\n//    long r = r2 - r1;\n//    long z = sqr(c.x) + sqr(c.y);\n//    long delta = z - sqr(r);\n//    if (delta <= 0) {\n//      return;\n//    }\n//    double d = Math.sqrt(Math.abs(delta));\n//    Line l = new Line((c.x * r + c.y * d) / z, (c.y * r - c.x * d) / z, r1);\n//    if (r1 * r2 >= 0) {\n//      ans.add(new Line(l.a, l.b, l.c + eps));\n//      ans.add(new Line(l.a, l.b, l.c - eps));\n//    } else {\n//      double sqrt = Math.hypot(c.x, c.y);\n//      double da = eps * c.y / sqrt;\n//      double db = -eps * c.x / sqrt;\n//      ans.add(new Line(l.a + da, l.b + db, l.c));\n//      ans.add(new Line(l.a - da, l.b - db, l.c));\n//    }\n//  }\n\n//  public ArrayList<Line> tangents(Circle a, Circle b) {\n//    ArrayList<Line> ans = new ArrayList<>();\n//    for (int i = -1; i <= 1; i += 2) {\n//      for (int j = -1; j <= 1; j += 2) {\n//        tangents(b.p.subtract(a.p), a.r * i, b.r * j, ans);\n//      }\n//    }\n//    for (int i = 0; i < ans.size(); ++i) {\n//      ans.get(i).c -= ans.get(i).a * a.p.x + ans.get(i).b * a.p.y;\n//    }\n//    return ans;\n//  }\n\n\tint[] fact = new int[1000001];\n\tint[] factInv = new int[1000001];\n\n\tpublic int[] intersect(int y, int xdown, int ydown, int xup, int yup) {\n\t\tif (yup < y || ydown > y || (ydown == yup)) {\n\t\t\treturn null;\n\t\t}\n\t\tlong p = xup * 1L * (y - ydown) + xdown * 1L * (yup - y);\n\t\tif (p < 0) {\n\t\t\tint[] ans = { -1, 0 };\n\t\t\treturn ans;\n\t\t}\n\t\tlong q = 2 * (yup - ydown);\n\t\tint[] ans = { (int) (p / q), (int) ((p + q - 1) / q) };\n\t\treturn ans;\n\t}\n\n\tpublic void I(int[][] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint[] b = new int[a.length];\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tb[a[i][j]] = j;\n\t\t\t}\n\t\t\ta[i] = b;\n\t\t}\n\t}\n\n\tpublic void C(int[][] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint[] b = new int[a.length];\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tb[a[j][i]] = j;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\ta[j][i] = b[j];\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic class SegmentTree {\n\t\tint pow;\n\t\tPair[] min;\n\n\t\tpublic SegmentTree(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\tmin = new Pair[2 * pow];\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tmin[pow + i] = new Pair(a[i], i);\n\t\t\t}\n\t\t\tfor (int i = a.length; i < pow; i++) {\n\t\t\t\tmin[pow + i] = new Pair(Integer.MAX_VALUE / 2, -1);\n\t\t\t}\n\t\t\tfor (int i = pow - 1; i > 0; i--) {\n\t\t\t\tmin[i] = f(min[2 * i], min[2 * i + 1]);\n\t\t\t}\n\t\t}\n\n\t\tpublic Pair get(int l, int r) {\n\t\t\treturn get(1, 0, pow, l, r);\n\t\t}\n\n\t\tprivate Pair get(int v, int tl, int tr, int l, int r) {\n\t\t\tif (l >= tr || r <= tl) {\n\t\t\t\treturn new Pair(Integer.MAX_VALUE / 2, -1);\n\t\t\t}\n\t\t\tif (l <= tl && r >= tr) {\n\t\t\t\treturn min[v];\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\treturn f(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm, tr, l, r));\n\t\t}\n\n\t\tpublic void set(int x, int value) {\n\t\t\tset(1, 0, pow, x, value);\n\t\t}\n\n\t\tprivate void set(int v, int tl, int tr, int x, int value) {\n\t\t\tif (x >= tr || x < tl) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v >= pow) {\n\t\t\t\tmin[v] = new Pair(value, -1);\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, x, value);\n\t\t\tset(2 * v + 1, tm, tr, x, value);\n\t\t\tmin[v] = f(min[2 * v], min[2 * v + 1]);\n\t\t}\n\n\t\tpublic Pair f(Pair a, Pair b) {\n\t\t\tif (a.compareTo(b) <= 0) {\n\t\t\t\treturn a.clone();\n\t\t\t}\n\t\t\treturn b.clone();\n\t\t}\n\t}\n\n\tpublic boolean nextPermutation(int[] a) {\n\t\tint n = a.length;\n\t\tfor (int i = n - 2; i >= 0; i--) {\n\t\t\tif (a[i] < a[i + 1]) {\n\t\t\t\tfor (int d = 1; d <= (n - 1 - i) / 2; d++) {\n\t\t\t\t\ta[i + d] ^= a[n - d];\n\t\t\t\t\ta[n - d] = a[i + d] ^ a[n - d];\n\t\t\t\t\ta[i + d] = a[i + d] ^ a[n - d];\n\t\t\t\t}\n\t\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\t\tif (a[j] > a[i]) {\n\t\t\t\t\t\ta[i] ^= a[j];\n\t\t\t\t\t\ta[j] = a[i] ^ a[j];\n\t\t\t\t\t\ta[i] = a[i] ^ a[j];\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\tpublic class Pair implements Comparable<Pair> {\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 add(Pair p) {\n\t\t\treturn new Pair(x + p.x, y + p.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 (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\tpublic double intersection(Pair p1, Pair p2) {\n\t\treturn (p2.y - p1.y) * 1.0 / (p1.x - p2.x);\n\t}\n\t\n\tHashMap<Integer, Integer> even = new HashMap<>();\n\tHashMap<Integer, Integer> odd = new HashMap<>();\n\t\n\tpublic void addOdd(int key, int value) {\n\t\tif (odd.containsKey(key)) {\n\t\t\todd.put(key, Math.min(odd.get(key), value));\n\t\t} else {\n\t\t\todd.put(key, value);\n\t\t}\n\t}\n\n\tpublic void addEven(int key, int value) {\n\t\tif (even.containsKey(key)) {\n\t\t\teven.put(key, Math.min(even.get(key), value));\n\t\t} else {\n\t\t\teven.put(key, value);\n\t\t}\n\t}\n\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n//\t\tint n = 500;\n//\t\tint m = 500;\n//\t\tint k = 20;\n\t\tif (k % 2 == 1) {\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\tout.print(-1 + \" \");\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tk /= 2;\n\t\tint[][] hor = new int[n][m - 1];\n\t\tfor (int i = 0; i < hor.length; i++) {\n\t\t\tfor (int j = 0; j < hor[0].length; j++) {\n\t\t\t\thor[i][j] = in.nextInt() * 2;\n//\t\t\t\thor[i][j] = random.nextInt(1000000) + 1;\n\t\t\t}\n\t\t}\n\t\tint[][] vert = new int[n - 1][m];\n\t\tfor (int i = 0; i < vert.length; i++) {\n\t\t\tfor (int j = 0; j < vert[0].length; j++) {\n\t\t\t\tvert[i][j] = in.nextInt() * 2;\n//\t\t\t\tvert[i][j] = random.nextInt(1000000) + 1;\n\t\t\t}\n\t\t}\n\t\tlong time = System.currentTimeMillis();\n\t\tint[][][] ans = new int[k + 1][n][m];\n\t\tfor (int l = 1; l <= k; l++) {\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\tans[l][i][j] = Integer.MAX_VALUE;\n\t\t\t\t\tif (i > 0) {\n\t\t\t\t\t\tans[l][i][j] = Math.min(ans[l][i][j], ans[l - 1][i - 1][j] + vert[i - 1][j]);\n\t\t\t\t\t}\n\t\t\t\t\tif (j > 0) {\n\t\t\t\t\t\tans[l][i][j] = Math.min(ans[l][i][j], ans[l - 1][i][j - 1] + hor[i][j - 1]);\n\t\t\t\t\t}\n\t\t\t\t\tif (i < n - 1) {\n\t\t\t\t\t\tans[l][i][j] = Math.min(ans[l][i][j], ans[l - 1][i + 1][j] + vert[i][j]);\n\t\t\t\t\t}\n\t\t\t\t\tif (j < m - 1) {\n\t\t\t\t\t\tans[l][i][j] = Math.min(ans[l][i][j], ans[l - 1][i][j + 1] + hor[i][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 < n; i++) {\n//\t\t\tfor (int j = 0; j < m; j++) {\n//\t\t\t\teven.clear();\n//\t\t\t\todd.clear();\n//\t\t\t\teven.put(i * m + j, 0);\n//\t\t\t\tfor (int l = 0; l < k; l++) {\n//\t\t\t\t\tif (l % 2 == 0) {\n//\t\t\t\t\t\todd.clear();\n//\t\t\t\t\t\tfor (Entry<Integer, Integer> e : even.entrySet()) {\n//\t\t\t\t\t\t\tint x = e.getKey() / m;\n//\t\t\t\t\t\t\tint y = e.getKey() % m;\n//\t\t\t\t\t\t\tint value = e.getValue();\n//\t\t\t\t\t\t\tif (x > 0) {\n//\t\t\t\t\t\t\t\taddOdd((x - 1) * m + y, value + vert[x - 1][y]);\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (y > 0) {\n//\t\t\t\t\t\t\t\taddOdd(x * m + y - 1, value + hor[x][y - 1]);\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (x < n - 1) {\n//\t\t\t\t\t\t\t\taddOdd((x + 1) * m + y, value + vert[x][y]);\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (y < m - 1) {\n//\t\t\t\t\t\t\t\taddOdd(x * m + y + 1, value + hor[x][y]);\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\teven.clear();\n//\t\t\t\t\t\tfor (Entry<Integer, Integer> e : odd.entrySet()) {\n//\t\t\t\t\t\t\tint x = e.getKey() / m;\n//\t\t\t\t\t\t\tint y = e.getKey() % m;\n//\t\t\t\t\t\t\tint value = e.getValue();\n//\t\t\t\t\t\t\tif (x > 0) {\n//\t\t\t\t\t\t\t\taddEven((x - 1) * m + y, value + vert[x - 1][y]);\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (y > 0) {\n//\t\t\t\t\t\t\t\taddEven(x * m + y - 1, value + hor[x][y - 1]);\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (x < n - 1) {\n//\t\t\t\t\t\t\t\taddEven((x + 1) * m + y, value + vert[x][y]);\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (y < m - 1) {\n//\t\t\t\t\t\t\t\taddEven(x * m + y + 1, value + hor[x][y]);\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\tans[i][j] = Integer.MAX_VALUE;\n//\t\t\t\tif (k % 2 == 0) {\n//\t\t\t\t\tfor (Entry<Integer, Integer> e : even.entrySet()) {\n//\t\t\t\t\t\tans[i][j] = Math.min(ans[i][j], e.getValue() * 2);\n//\t\t\t\t\t}\n//\t\t\t\t} else {\n//\t\t\t\t\tfor (Entry<Integer, Integer> e : odd.entrySet()) {\n//\t\t\t\t\t\tans[i][j] = Math.min(ans[i][j], e.getValue() * 2);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tout.print(ans[k][i][j] + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\tSystem.err.println(System.currentTimeMillis() - time);\n\t}\n\n\tpublic void add(HashMap<Integer, Integer> 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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n/*\nheight == 2, width == 3\n\n2 3 2\n1 1\n1 1\n1 1 1\n */\npublic class D {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tint h=fs.nextInt(), w=fs.nextInt(), k=fs.nextInt();\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tif (k%2==1) {\n\t\t\tfor (int y=0; y<h; y++) {\n\t\t\t\tfor (int x=0; x<w; x++) {\n\t\t\t\t\tif (x!=0) out.print(\" \");\n\t\t\t\t\tout.print(-1);\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\tk/=2;\n\t\t\n\t\tint[][] rightCost=new int[w-1][h];\n\t\tint[][] downCost=new int[w][h-1];\n\t\tfor (int y=0; y<h; y++) \n\t\t\tfor (int x=0; x<w-1; x++)\n\t\t\t\trightCost[x][y]=fs.nextInt();\n\t\tfor (int y=0; y<h-1; y++)\n\t\t\tfor (int x=0; x<w; x++)\n\t\t\t\t downCost[x][y]=fs.nextInt();\n\t\t\n\t\tlong[][] dp=new long[w][h];\n\t\tlong[][] dpNext=new long[w][h];\n\t\tfor (int i=0; i<k; i++) {\n\t\t\tfor (int x=0; x<w; x++) {\n\t\t\t\tfor (int y=0; y<h; y++) {\n\t\t\t\t\tlong ans=(long)1e18;\n\t\t\t\t\tif (x!=0) ans=Math.min(ans, dp[x-1][y]+rightCost[x-1][y]);\n\t\t\t\t\tif (y!=0) ans=Math.min(ans, dp[x][y-1]+downCost[x][y-1]);\n\t\t\t\t\tif (x!=w-1) ans=Math.min(ans, dp[x+1][y]+rightCost[x][y]);\n\t\t\t\t\tif (y!=h-1) ans=Math.min(ans, dp[x][y+1]+downCost[x][y]);\n\t\t\t\t\tdpNext[x][y]=ans;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp=dpNext;\n\t\t\tdpNext=new long[w][h];\n\t\t}\n\t\t//TODO: double answer\n\t\tfor (int y=0; y<h; y++) {\n\t\t\tfor (int x=0; x<w; x++) {\n\t\t\t\tif (x!=0) out.print(\" \");\n\t\t\t\tout.print(2*dp[x][y]);\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tArrayList<Integer> l=new ArrayList<>();\n\t\tfor (int i:a) l.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i=0; i<a.length; i++) a[i]=l.get(i);\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\t\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static void main(String[] args)throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringBuilder sb = new StringBuilder();\n\t\t\n\t\t//idea 1 : K/2\ubc88\uae4c\uc9c0\ub9cc \uc2e4\ud589\ud574\uc11c, \uadf8 \ucd5c\uc19f\uac12 *2\ub97c \ud558\uba74 \ub41c\ub2e4\n\t\t//bfs\ub85c i,j\uce78\uc5d0 \ud06c\uac70\ub098 \uac19\uc740 \uac12\uc744 \uac00\uc9c0\uace0 \uc9c4\uc785\ud558\uba74, \uc989\uc2dc cut\n\t\tStringTokenizer st = new StringTokenizer(br.readLine(), \" \");\n\t\tn = pint(st.nextToken());\n\t\tm = pint(st.nextToken());\n\t\tk = pint(st.nextToken());\n\t\t\n\t\t//up down left right\n\t\t//0 is wall\n\t\tmap = new int[n][m][4];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tst = new StringTokenizer(br.readLine(), \" \");\n\t\t\tfor (int j = 0; j < m-1; j++) {\n\t\t\t\tint temp = pint(st.nextToken());\n\t\t\t\tmap[i][j][3]=temp;\n\t\t\t\tmap[i][j+1][2]=temp;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n-1; i++) {\n\t\t\tst = new StringTokenizer(br.readLine(), \" \");\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tint temp = pint(st.nextToken());\n\t\t\t\tmap[i][j][1]=temp;\n\t\t\t\tmap[i+1][j][0]=temp;\n\t\t\t}\n\t\t}\n\t\t\n\t\tans = new int[n][m][k/2+1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif(k%2==1) {\n\t\t\t\t\tsb.append(\"-1 \");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint min=rec(i,j,0,k/2);\n\t\t\t\t\n\t\t\t\tsb.append(min*2).append(\" \");\n\t\t\t\t\n\t\t\t}sb.append(\"\\n\");\n\t\t}\n\t\t\n\t\tSystem.out.println(sb);\n\t\t\n\t}\n\tstatic int n,m,k;\n\t//up down left right\n\tstatic int[]dx = {-1,1, 0, 0};\n\tstatic int[]dy = {0, 0, -1,1};\n\tstatic int[][][]map;\n\tstatic int[][][]ans;\n\t\n\tstatic int rec(int x, int y, int cost, int cnt) {\n\t\tif(cnt==0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif(ans[x][y][cnt]!=0)return ans[x][y][cnt];\n\t\t\n\t\tint temp=Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tint tx=x+dx[i], ty=y+dy[i];\n\t\t\t\n\t\t\tif(tx<0||tx>=n||ty<0||ty>=m)continue;\n\t\t\t\n\t\t\tif(map[x][y][i]!=0) {\n\t\t\t\ttemp=Math.min(temp, rec(tx, ty, cost, cnt-1)+map[x][y][i]);\n\t\t\t}\n\t\t}\n\t\tans[x][y][cnt]=temp;\n\t\t\n\t\treturn ans[x][y][cnt];\n\t}\n\t\n\tstatic int pint(String s) {\n\t\treturn Integer.parseInt(s);\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Practice {\n\tpublic static long mod = (long) Math.pow(10, 9) + 7;\n\tpublic static long[][][]dp;\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\t// int t = Integer.parseInt(br.readLine());\n//\t\twhile (t-- > 0) {\n\t\tString[] s2 = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(s2[0]);\n\t\tint m = Integer.parseInt(s2[1]);\n\t\tint k = Integer.parseInt(s2[2]);\n\t\tdp=new long[n][m][k+1];\n\t\tint[][] hori = new int[n][m - 1];\n\t\tint[][] verti = new int[n - 1][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString str = (br.readLine());\n\t\t\tString[] s1 = str.split(\" \");\n\t\t\tfor (int j = 0; j < m - 1; j++) {\n\t\t\t\thori[i][j] = Integer.parseInt(s1[j]);\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tString str = (br.readLine());\n\t\t\tString[] s1 = str.split(\" \");\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tverti[i][j] = Integer.parseInt(s1[j]);\n\t\t\t}\n\t\t}\n\t\tlong[][]ans=new long[n][m];\n\t\tif(k%2!=0) {\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\tans[i][j]=-1;\n\t\t\t\t}\n\t\t\t}\n\t\t}else {\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\tans[i][j]=findAns(i,j,k,hori,verti,n,m,Integer.MAX_VALUE);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tStringBuilder str=new StringBuilder();\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tstr.append(ans[i][j]+\" \");\n\t\t\t}pw.println(str.toString());\n\t\t}\n\t\t// }\n\n\t\tpw.close();\n\t}\n\n\tprivate static long findAns(int i, int j, int k, int[][] hori, int[][] verti, int n, int m, int last) {\n\t\t// TODO Auto-generated method stub\n\t\tif(k==0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif(i<n&&j<m&&i>=0&&j>=0) {\n\t\t\t\n\t\t}else {\n\t\t\treturn 100000000;\n\t\t}\n\t//\tSystem.out.println(i+\" \"+j+\" \"+k);\n\t\tif(dp[i][j][k]!=0) {\n\t\t\treturn dp[i][j][k];\n\t\t}\n\t\tlong ans=k*((long)last);\n\t\tif(j>0) {\n\t\t\tlong curr=2*hori[i][j-1];\n\t\t\tcurr+=findAns(i, j-1, k-2, hori, verti, n, m, hori[i][j-1]);\n\t\t\tans=Math.min(ans, curr);\n\t\t}\n\t//\tSystem.out.println(ans+\" 0\");\n\t\tif(j<m-1) {\n\t\t\tlong curr=2*hori[i][j];\n\t\t\tcurr+=findAns(i, j+1, k-2, hori, verti, n, m, hori[i][j]);\n\t\t\tans=Math.min(ans, curr);\n\t\t}\n\t//\tSystem.out.println(ans+\" 1\");\n\t\tif(i>0) {\n\t\t\tlong curr=2*verti[i-1][j];\n\t\t\tcurr+=findAns(i-1, j, k-2, hori, verti, n, m, verti[i-1][j]);\n\t\t\tans=Math.min(ans, curr);\n\t\t}\n\t//\tSystem.out.println(ans+\" 2\");\n\t\tif(i<n-1) {\n\t\t\tlong curr=2*verti[i][j];\n\t\t\tcurr+=findAns(i+1, j, k-2, hori, verti, n, m, verti[i][j]);\n\t\t\tans=Math.min(ans, curr);\n\t\t}\n\t//\tSystem.out.println(ans+\" 3\");\n\t\tdp[i][j][k]=ans;\n\t\treturn ans;\n\t}\n}\n\n//private static long getGCD(long l, long m) {\n//// TODO Auto-generated method stub\n//\n//long t1 = Math.min(l, m);\n//long t2 = Math.max(l, m);\n//while (true) {\n//\tlong temp = t2 % t1;\n//\tif (temp == 0) {\n//\t\treturn t1;\n//\t}\n//\tt2 = t1;\n//\tt1 = temp;\n//}\n//}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _1517_D {\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        StringTokenizer line = new StringTokenizer(in.readLine());\n        int n = Integer.parseInt(line.nextToken());\n        int m = Integer.parseInt(line.nextToken());\n        int k = Integer.parseInt(line.nextToken());\n        int[][] edges1 = new int[n][m - 1];\n        int[][] edges2 = new int[n - 1][m];\n        for(int i = 0; i < n; i++) {\n            line = new StringTokenizer(in.readLine());\n            for(int j = 0; j < m - 1; j++) {\n                edges1[i][j] = Integer.parseInt(line.nextToken());\n            }\n        }\n        for(int i = 0; i < n - 1; i++) {\n            line = new StringTokenizer(in.readLine());\n            for(int j = 0; j < m; j++) {\n                edges2[i][j] = Integer.parseInt(line.nextToken());\n            }\n        }\n        if(k % 2 == 1) {\n            for(int i = 0; i < n; i++) {\n                StringBuilder sb = new StringBuilder();\n                for (int j = 0; j < m; j++) {\n                    sb.append(-1);\n                    if(j < m - 1) sb.append(' ');\n                }\n                out.println(sb.toString());\n            }\n        }else {\n            int[][][] dp = new int[n][m][k + 1];\n            for(int i = 0; i < n; i++) {\n                for(int j = 0; j < m; j++) {\n                    Arrays.fill(dp[i][j], Integer.MAX_VALUE);\n                    dp[i][j][0] = 0;\n                }\n            }\n            for(int a = 2; a <= k; a += 2) {\n                for(int i = 0; i < n; i++) {\n                    for(int j = 0; j < m; j++) {\n                        if(i > 0) {\n                            dp[i][j][a] = Math.min(dp[i][j][a], dp[i - 1][j][a - 2] + 2 * edges2[i - 1][j]);\n                        }\n                        if(i < n - 1) {\n                            dp[i][j][a] = Math.min(dp[i][j][a], dp[i + 1][j][a - 2] + 2 * edges2[i][j]);\n                        }\n                        if(j > 0) {\n                            dp[i][j][a] = Math.min(dp[i][j][a], dp[i][j - 1][a - 2] + 2 * edges1[i][j - 1]);\n                        }\n                        if(j < m - 1) {\n                            dp[i][j][a] = Math.min(dp[i][j][a], dp[i][j + 1][a - 2] + 2 * edges1[i][j]);\n                        }\n                    }\n                }\n            }\n            for(int i = 0; i < n; i++) {\n                StringBuilder sb = new StringBuilder();\n                for(int j = 0; j < m; j++) {\n                    sb.append(dp[i][j][k]);\n                    if(j < m - 1) sb.append(' ');\n                }\n                out.println(sb.toString());\n            }\n        }\n        in.close();\n        out.close();\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "/*\nbts songs to dance to:\nI need U\nRun\nON\nFilter\nI'm fine\n */\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.abs;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class x1517D2\n{\n    static final int INF = Integer.MAX_VALUE/3;\n    public static void main(String hi[]) throws Exception\n    {\n        FastScanner infile = new FastScanner();\n        int N = infile.nextInt();\n        int M = infile.nextInt();\n        int K = infile.nextInt();\n        int[][] weights1 = new int[N][M-1];\n        for(int r=0; r < N; r++)\n            weights1[r] = infile.nextInts(M-1);\n        int[][] weights2 = new int[N-1][M];\n        for(int r=0; r < N-1; r++)\n            weights2[r] = infile.nextInts(M);\n        //all are -1 if K is odd\n        int[][] res = new int[N][M];\n        if(K%2 == 1)\n        {\n            StringBuilder sb = new StringBuilder();\n            for(int r=0; r < N; r++)\n            {\n                for(int c=0; c < M; c++)\n                    sb.append(\"-1 \");\n                sb.append(\"\\n\");\n            }\n            System.out.print(sb);\n            return;\n        }\n        int[][] dp = new int[N][M];\n        StringBuilder sb = new StringBuilder();\n        for(int k=0; k < K/2; k++)\n        {\n            int[][] next = new int[N][M];\n            for(int r=0; r < N; r++)\n                Arrays.fill(next[r], INF);\n            for(int r=0; r < N; r++)\n                for(int c=0; c < M; c++)\n                {\n                    if(r > 0)\n                        next[r-1][c] = min(next[r-1][c], dp[r][c]+weights2[r-1][c]);\n                    if(r+1 < N)\n                        next[r+1][c] = min(next[r+1][c], dp[r][c]+weights2[r][c]);\n                    if(c > 0)\n                        next[r][c-1] = min(next[r][c-1], dp[r][c]+weights1[r][c-1]);\n                    if(c+1 < M)\n                        next[r][c+1] = min(next[r][c+1], dp[r][c]+weights1[r][c]);\n                }\n            dp = next;\n        }\n        for(int r=0; r < N; r++)\n        {\n            for(int x: dp[r])\n                sb.append((2*x)+\" \");\n            sb.append(\"\\n\");\n        }\n        System.out.print(sb);\n    }\n}\nclass FastScanner\n{\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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "// Author : RegalBeast\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n  static final FastReader FR = new FastReader();\n  static final BufferedWriter BW = new BufferedWriter(new OutputStreamWriter(System.out));\n\n  public static void main(String[] args) throws IOException {\n    StringBuilder solution = new StringBuilder();\n    int rows = FR.nextInt();\n    int cols = FR.nextInt();\n    int moves = FR.nextInt();\n\n    Map<Integer, Integer> horizontalEdgeWeights = new HashMap<Integer, Integer>();\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols - 1; c++) {\n        int hash = getHash(r, c);\n        horizontalEdgeWeights.put(hash, FR.nextInt());\n      }\n    }\n\n    Map<Integer, Integer> verticalEdgeWeights = new HashMap<Integer, Integer>();\n    for (int r = 0; r < rows - 1; r++) {\n      for (int c = 0; c < cols; c++) {\n        int hash = getHash(r, c);\n        verticalEdgeWeights.put(hash, FR.nextInt());\n      }\n    }\n    \n    List<List<Integer>> result = getResult(rows, cols, moves, horizontalEdgeWeights, verticalEdgeWeights);\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols; c++) {\n        int value = (result != null ? result.get(r).get(c) : -1);\n        solution.append(value + \" \");\n      }\n      solution.append(\"\\n\");\n    }\n\n\t\tBW.write(solution.toString());\n    BW.close();\n  }\n\n  static List<List<Integer>> getResult(int rows, int cols, int moves, Map<Integer, Integer> horizontalEdgeWeights, Map<Integer, Integer> verticalEdgeWeights) {\n    if ((moves & 1) == 1) {\n      return null;\n    }\n\n    int mid = moves >> 1;\n    List<List<List<Integer>>> minForDistance = new ArrayList<List<List<Integer>>>(rows);\n    for (int r = 0; r < rows; r++) {\n      minForDistance.add(new ArrayList<List<Integer>>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        minForDistance.get(r).add(new ArrayList<Integer>(Collections.nCopies(mid+1, Integer.MAX_VALUE)));\n        minForDistance.get(r).get(c).set(0, 0);\n      }\n    }\n\n    for (int m = 1; m <= mid; m++) {\n      for (int r = 0; r < rows; r++) {\n        for (int c = 0; c < cols; c++) {\n          int minBoredom = minForDistance.get(r).get(c).get(m);\n          int hash = getHash(r, c);\n\n          if (r > 0) {\n            if (minForDistance.get(r-1).get(c).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r-1).get(c).get(m-1) + verticalEdgeWeights.get(getHash(r-1, c));\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n\n          if (c > 0) {\n            if (minForDistance.get(r).get(c-1).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r).get(c-1).get(m-1) + horizontalEdgeWeights.get(getHash(r, c-1));\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n          \n          if (r + 1 < rows) {\n            if (minForDistance.get(r+1).get(c).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r+1).get(c).get(m-1) + verticalEdgeWeights.get(hash);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n   \n          if (c + 1 < cols) {\n            if (minForDistance.get(r).get(c+1).get(m-1) < Integer.MAX_VALUE) {\n              int candidateBoredom = minForDistance.get(r).get(c+1).get(m-1) + horizontalEdgeWeights.get(hash);\n              minBoredom = Math.min(minBoredom, candidateBoredom);\n            }\n          }\n\n          minForDistance.get(r).get(c).set(m, minBoredom);\n        }\n      }\n    }\n\n    List<List<Integer>> result = new ArrayList<List<Integer>>(rows);\n    for (int r = 0; r < rows; r++) {\n      result.add(new ArrayList<Integer>(cols));\n\n      for (int c = 0; c < cols; c++) {\n        result.get(r).add(minForDistance.get(r).get(c).get(mid) << 1);\n      }\n    }\n\n    return result;\n  }\n\n  static int getHash(int row, int col) {\n    return (row * 1000 + col);\n  }\n  static int getRow(int hash) {\n    return hash / 1000;\n  }\n  static int getCol(int hash) {\n    return hash % 1000;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1517d {\n\n    public static void main(String[] args) throws IOException {\n        int n = rni(), m = ni(), k = ni(), ans[][] = new int[n][m];\n        WGraph g = wgraph(n * m);\n        for (int i = 0; i < n; ++i) {\n            r();\n            for (int j = 0; j < m - 1; ++j) {\n                g.c(i * m + j, i * m + j + 1, ni());\n            }\n        }\n        for (int i = 0; i < n - 1; ++i) {\n            r();\n            for (int j = 0; j < m; ++j) {\n                g.c(i * m + j, (i + 1) * m + j, ni());\n            }\n        }\n        if (k % 2 == 1) {\n            for (int[] row : ans) {\n                fill(row, -1);\n                prln(row);\n            }\n            close();\n            return;\n        }\n        k >>= 1;\n        for (int l = 0; l < k; ++l) {\n            int nans[][] = new int[n][m];\n            for (int[] row : nans) {\n                fill(row, IBIG);\n            }\n            for (int i = 0; i < n * m; ++i) {\n                for (int ed[] : g.get(i)) {\n                    int j = ed[0], d = ed[1];\n                    if (ans[i / m][i % m] + d < nans[j / m][j % m]) {\n                        nans[j / m][j % m] = ans[i / m][i % m] + d;\n                    }\n                }\n            }\n            ans = nans;\n        }\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < m; ++j) {\n                ans[i][j] *= 2;\n            }\n        }\n        for (int[] row : ans) {\n            prln(row);\n        }\n        close();\n    }\n\n    static int solve(WGraph g, int i, int k) {\n        List<Map<Integer, Integer>> cost = new ArrayList<>();\n        for (int j = 0; j <= k; ++j) {\n            cost.add(new HashMap<>());\n        }\n        PriorityQueue<int[]> dijk = new PriorityQueue<>((a, b) -> a[2] - b[2]);\n        dijk.offer(new int[] {i, 0, 0});\n        cost.get(0).put(i, 0);\n        while (!dijk.isEmpty()) {\n            int e[] = dijk.poll(), node = e[0], dist = e[1], co = e[2];\n            if (co > cost.get(dist).get(node)) {\n                continue;\n            }\n            if (dist == k) {\n                return 2 * co;\n            }\n            if (dist < k) {\n                for (int ed[] : g.get(node)) {\n                    int j = ed[0], c = ed[1];\n                    if (co + c < cost.get(dist + 1).getOrDefault(j, IBIG)) {\n                        cost.get(dist + 1).put(j, co + c);\n                        dijk.offer(new int[] {j, dist + 1, co + c});\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n\n    static WGraph wgraph(int n) {\n        WGraph g = new WGraph();\n        for (int i = 0; i < n; ++i) {\n            g.add(new ArrayList<>());\n        }\n        return g;\n    }\n\n    static WGraph wgraph(int n, int m) throws IOException {\n        WGraph g = wgraph(n);\n        for (int i = 0; i < m; ++i) {\n            g.c(rni() - 1, ni() - 1, ni());\n        }\n        return g;\n    }\n\n    static WGraph wdigraph(int n, int m) throws IOException {\n        WGraph g = wgraph(n);\n        for (int i = 0; i < m; ++i) {\n            g.cto(rni() - 1, ni() - 1, ni());\n        }\n        return g;\n    }\n\n    static class WGraph extends ArrayList<List<int[]>> {\n        void cto(int u, int v, int w) {\n            get(u).add(new int[] {v, w});\n        }\n\n        void c(int u, int v, int w) {\n            cto(u, v, w);\n            cto(v, u, w);\n        }\n    }\n\n    static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in));\n    static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out));\n    static StringTokenizer input;\n    static Random __r = 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 long LMAX = 9223372036854775807L;\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 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    static int[] exgcd(int a, int b) {if (b == 0) return new int[] {1, 0}; int[] y = exgcd(b, a % b); return new int[] {y[1], y[0] - y[1] * (a / b)};}\n    static long[] exgcd(long a, long b) {if (b == 0) return new long[] {1, 0}; long[] y = exgcd(b, a % b); return new long[] {y[1], y[0] - y[1] * (a / b)};}\n    static int randInt(int min, int max) {return __r.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    // 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 __i.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    // output\n    static void pr(int i) {__o.print(i);}\n    static void prln(int i) {__o.println(i);}\n    static void pr(long l) {__o.print(l);}\n    static void prln(long l) {__o.println(l);}\n    static void pr(double d) {__o.print(d);}\n    static void prln(double d) {__o.println(d);}\n    static void pr(char c) {__o.print(c);}\n    static void prln(char c) {__o.println(c);}\n    static void pr(char[] s) {__o.print(new String(s));}\n    static void prln(char[] s) {__o.println(new String(s));}\n    static void pr(String s) {__o.print(s);}\n    static void prln(String s) {__o.println(s);}\n    static void pr(Object o) {__o.print(o);}\n    static void prln(Object o) {__o.println(o);}\n    static void prln() {__o.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 boolean pryesno(boolean b) {prln(b ? \"yes\" : \"no\"); return b;};\n    static boolean pryn(boolean b) {prln(b ? \"Yes\" : \"No\"); return b;}\n    static boolean prYN(boolean b) {prln(b ? \"YES\" : \"NO\"); return b;}\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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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() {__o.flush();}\n    static void close() {__o.close();}\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "// Author : RegalBeast\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n  static final FastReader FR = new FastReader();\n  static final PrintWriter PW = new PrintWriter(new OutputStreamWriter(System.out));\n\n  public static void main(String[] args) {\n    StringBuilder solution = new StringBuilder();\n    int rows = FR.nextInt();\n    int cols = FR.nextInt();\n    int moves = FR.nextInt();\n\n    int[][] horizontalEdgeWeights = new int[rows][cols-1];\n\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols - 1; c++) {\n        horizontalEdgeWeights[r][c] = FR.nextInt();\n      }\n    }\n\n    int[][] verticalEdgeWeights = new int[rows-1][cols];\n    for (int r = 0; r < rows - 1; r++) {\n      for (int c = 0; c < cols; c++) {\n        verticalEdgeWeights[r][c] = FR.nextInt();\n      }\n    }\n\n    int[][] result = getResult(rows, cols, moves, horizontalEdgeWeights, verticalEdgeWeights);\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols; c++) {\n        solution.append(result[r][c] + \" \");\n      }\n      solution.append(\"\\n\");\n    }\n\n\t\tPW.print(solution.toString());\n    PW.close();\n  }\n\n  static int[][] getResult(int rows, int cols, int moves, int[][] horizontalEdgeWeights, int[][] verticalEdgeWeights) {\n    int[][] result = new int[rows][cols];\n    if ((moves & 1) == 1) {\n      for (int r = 0; r < rows; r++) {\n        for (int c = 0; c < cols; c++) {\n          result[r][c] = -1;\n        }\n      }\n  \n      return result;\n    }\n\n    int mid = moves >> 1;\n    int[][][] minForDistance = new int[rows][cols][mid+1];\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols; c++) {\n        for (int m = 1; m <= mid; m++) {\n          minForDistance[r][c][m] = Integer.MAX_VALUE;\n        }\n      }\n    }\n\n    for (int m = 1; m <= mid; m++) {\n      for (int r = 0; r < rows; r++) {\n        for (int c = 0; c < cols; c++) {\n          int minBoredom = minForDistance[r][c][m];\n\n          if (r > 0) {\n            int candidateBoredom = minForDistance[r-1][c][m-1] + verticalEdgeWeights[r-1][c];\n            minBoredom = Math.min(minBoredom, candidateBoredom);\n          }\n\n          if (c > 0) {\n            int candidateBoredom = minForDistance[r][c-1][m-1] + horizontalEdgeWeights[r][c-1];\n            minBoredom = Math.min(minBoredom, candidateBoredom);\n          }\n\n          if (r + 1 < rows) {\n            int candidateBoredom = minForDistance[r+1][c][m-1] + verticalEdgeWeights[r][c];\n            minBoredom = Math.min(minBoredom, candidateBoredom);\n          }\n\n          if (c + 1 < cols) {\n            int candidateBoredom = minForDistance[r][c+1][m-1] + horizontalEdgeWeights[r][c];\n            minBoredom = Math.min(minBoredom, candidateBoredom);\n          }\n\n          minForDistance[r][c][m] = minBoredom;\n        }\n      }\n    }\n\n    for (int r = 0; r < rows; r++) {\n      for (int c = 0; c < cols; c++) {\n        result[r][c] = minForDistance[r][c][mid] << 1;\n      }\n    }\n\n    return result;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main {\n    static class Fast {\n\t\tStringTokenizer st;\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\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\t\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n    static Fast scn = new Fast();\n    public static void main(String args[]) throws Exception {\n        int t = 1;\n        while(t-- > 0){\n            func();\n        }\n        bw.close();\n    }\n    private static void func() throws Exception{\n        int n = scn.nextInt();\n        int m = scn.nextInt();\n        int k = scn.nextInt();\n        int[][] hori = new int[n][m - 1];\n        int[][] vert = new int[n - 1][m];\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m - 1; j++){\n                hori[i][j] = scn.nextInt();\n            }\n        }\n\n        for(int i = 0; i < n - 1; i++){\n            for(int j = 0; j < m; j++){\n                vert[i][j] = scn.nextInt();\n            }\n        }\n        if(k % 2 != 0){\n            for(int i = 0; i < n; i++){\n                for(int j = 0; j < m; j++){\n                    bw.append(-1 + \" \");\n                }\n                bw.append(\"\\n\");\n            }\n            return;\n        }\n        int[][][] strg = new int[n][m][k + 1];\n        // for(int i = 0; i < n; i++){\n        //     for(int j = 0; j < m; j++){\n        //         for(int x = 0; x < k; x++)\n        //     }\n        // }\n        int[][] answer = new int[n][m];\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                answer[i][j] = steps(i, j, hori, vert, k, strg);\n            }\n        }\n      for(int i = 0; i < n; i++){\n          for(int j = 0; j < m; j++){\n              bw.append(answer[i][j] + \" \");\n          }\n          bw.append(\"\\n\");\n      }\n       \n    }\n\n    static int steps(int x, int y, int[][] hori, int[][] vert, int k, int[][][] strg){\n        if(k == 0)\n            return 0;\n        if(strg[x][y][k] != 0)\n            return strg[x][y][k];\n        int xmove = x;\n        int ymove = y;\n        int ans = 0;\n        int val = Integer.MAX_VALUE;\n        if(y < hori[0].length){\n            xmove = x;\n            ymove = y + 1;\n            val = Math.min(val, steps(xmove, ymove, hori, vert, k - 2, strg) + (2 * hori[x][y]));\n        }\n        if(y - 1 >= 0){\n            xmove = x;\n            ymove = y - 1;\n            val = Math.min(val, steps(xmove, ymove, hori, vert, k - 2, strg) + (2 * hori[x][y - 1]));\n            // val = hori[x][y - 1];\n        }\n        if(x - 1 >= 0){\n            xmove = x - 1;\n            ymove = y;\n            val = Math.min(val, steps(xmove, ymove, hori, vert, k - 2, strg) + (2 * vert[x - 1][y]));\n            // val = vert[x - 1][y];\n        }\n        if(x < vert.length){\n            xmove = x + 1;\n            ymove = y;\n            val = Math.min(val, steps(xmove, ymove, hori, vert, k - 2, strg) + (2 * vert[x][y]));\n            // val = vert[x + 1][y];\n        }\n        // System.out.println(val);\n        ans += val;\n        return strg[x][y][k] = ans;\n    }\n}\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "/*\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.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author is2ac\n */\npublic class D_CF {\n\n    public static void main(String[] args) {\n        FastScanner58 fs = new FastScanner58();\n        PrintWriter pw = new PrintWriter(System.out);\n        //int t = fs.ni();\n        int t = 1;\n        // for (int tc = 0; tc < t; tc++) {\n        for (int tc = 0; tc < t; tc++) {\n            int n = fs.ni();\n            int m = fs.ni();\n            int k = fs.ni();\n            int[][] a = new int[n][m - 1];\n            int[][] b = new int[n - 1][m];\n            for (int i = 0; i < n; i++) {\n                a[i] = fs.intArray(m - 1);\n            }\n            for (int i = 0; i < n - 1; i++) {\n                b[i] = fs.intArray(m);\n            }\n            int[][] res = new int[n][m];\n            Integer[][][] dp = new Integer[n][m][k / 2 + 1];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    res[i][j] = recur(i, j, k / 2, dp, a, b) * 2;\n                }\n            }\n            StringBuilder sb = new StringBuilder();\n            for (int i = 0; i < res.length; i++) {\n                for (int j = 0; j < m; j++) {\n                    //matrix[i][j]++;\n                    if (k%2==1) {\n                        sb.append(-1 + \" \");\n                    } else {\n                        sb.append(res[i][j] + \" \");\n                    }\n                }\n                sb.append(\"\\n\");\n            }\n            pw.println(sb);\n        }\n        pw.close();\n    }\n\n    public static int recur(int i, int j, int k, Integer[][][] dp, int[][] a, int[][] b) {\n        if (k == 0) {\n            return 0;\n        }\n        int n = (int) (1e9);\n        if (dp[i][j][k] != null) {\n            return dp[i][j][k];\n        }\n        if (i != 0) {\n            n = Math.min(n, recur(i - 1, j, k - 1, dp, a, b) + b[i - 1][j]);\n        }\n        if (j != 0) {\n            n = Math.min(n, recur(i, j - 1, k - 1, dp, a, b) + a[i][j - 1]);\n        }\n        if (i != a.length - 1) {\n            n = Math.min(n, recur(i + 1, j, k - 1, dp, a, b) + b[i][j]);\n        }\n        if (j != b[0].length - 1) {\n            n = Math.min(n, recur(i, j + 1, k - 1, dp, a, b) + a[i][j]);\n        }\n        return dp[i][j][k] = n;\n    }\n}\n\nclass FastScanner58 {\n\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastScanner58() {\n        br = new BufferedReader(new InputStreamReader(System.in), 32768);\n        st = null;\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    int[] intArray(int N) {\n        int[] ret = new int[N];\n        for (int i = 0; i < N; i++) {\n            ret[i] = ni();\n        }\n        return ret;\n    }\n\n    long nl() {\n        return Long.parseLong(next());\n    }\n\n    long[] longArray(int N) {\n        long[] ret = new long[N];\n        for (int i = 0; i < N; i++) {\n            ret[i] = nl();\n        }\n        return ret;\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\nclass UnionFind17 {\n\n    int[] id;\n\n    public UnionFind17(int size) {\n        id = new int[size];\n        for (int i = 0; i < size; i++) {\n            id[i] = i;\n        }\n    }\n\n    public int find(int p) {\n        int root = p;\n        while (root != id[root]) {\n            root = id[root];\n        }\n        while (p != root) {\n            int next = id[p];\n            id[p] = root;\n            p = next;\n        }\n        return root;\n    }\n\n    public void union(int p, int q) {\n        int a = find(p), b = find(q);\n        if (a == b) {\n            return;\n        }\n        id[b] = a;\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    static FastScanner sc = new FastScanner(System.in);\n    static PrintWriter pw = new PrintWriter(System.out);\n    static StringBuilder sb = new StringBuilder();\n    static long mod = (long) 1e9 + 7;\n    public static void main(String[] args) throws Exception {\n        solve();\n        pw.flush();\n    }\n    \n    static ArrayList<ArrayList<ArrayList<int[]>>> kruscal = new ArrayList<>();\n    static long ans = Integer.MAX_VALUE;\n    static int[][][] map;\n    public static void solve() {\n        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();\n        for(int i = 0; i < n; i++){\n            kruscal.add(new ArrayList<>());\n            for(int j = 0; j < m; j++){\n                kruscal.get(i).add(new ArrayList<>());\n            }\n        }\n        map = new int[n][m][k+1];\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m-1; j++){\n                //int now = (int)(Math.random()*1000000)*2;\n                int now = sc.nextInt();\n                kruscal.get(i).get(j).add(new int[]{now,i,j+1});\n                kruscal.get(i).get(j+1).add(new int[]{now,i,j});\n            }\n        }\n        for(int i = 0; i < n-1; i++){\n            for(int j = 0; j < m; j++){\n                //int now = (int)(Math.random()*1000000)*2;\n                int now = sc.nextInt();\n                kruscal.get(i).get(j).add(new int[]{now,i+1,j});\n                kruscal.get(i+1).get(j).add(new int[]{now,i,j});\n            }\n        }\n        if(k % 2 != 0){\n            for(int i = 0; i < n; i++){\n                for(int j = 0; j < m; j++){\n                    sb.append(-1).append(\" \");\n                }\n                pw.println(sb.toString().trim());\n                sb.setLength(0);\n            }\n            return;\n        }\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                Arrays.fill(map[i][j],Integer.MAX_VALUE/2);\n                map[i][j][k/2] = 0;\n            }\n        }\n        for(int kk = k/2; kk > 0; kk--){\n            for(int i = 0; i < n; i++){\n                for(int j = 0; j < m; j++){\n                    for(int[] next : kruscal.get(i).get(j)){\n                        int d = next[0], i2 = next[1], j2 = next[2];\n                        map[i2][j2][kk-1] = Math.min(map[i2][j2][kk-1],map[i][j][kk]+d);\n                    }\n                }\n            }\n        }\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                sb.append(map[i][j][0]*2).append(\" \");\n            }\n            pw.println(sb.toString().trim());\n            sb.setLength(0);\n        }\n    }\n    \n    static void dfs(Stack<Integer> st, int y, int x, int cnt, long total){\n        if(st.size() == cnt){\n            ans = Math.min(total,ans);\n        }\n        for(int[] next : kruscal.get(y).get(x)){\n            int d = next[0], i = next[1], j = next[2];\n            if(Math.abs(i-y)+Math.abs(j-x)-st.size() < 0){\n                continue;\n            }\n            Stack<Integer> stk = (Stack<Integer>)st.clone();\n            stk.push(d);\n            dfs(stk,i,j,cnt,total + d);\n        }\n        int rem = cnt - st.size();\n        long tmp = 0;\n        int c = 0;\n        while(st.size() > 0){\n            tmp += st.pop();\n            c++;\n            if(rem % c == 0){\n                ans = Math.min(ans,total + tmp * (rem/c));\n            }\n        }\n    }\n    \n    static class ArrayComparator implements Comparator<int[]> {\n        @Override\n        public int compare(int[] a1, int[] a2) {\n            for (int i = 0; i < a1.length; i++) {\n                if (a1[i] < a2[i]) {\n                    return -1;\n                } else if (a1[i] > a2[i]) {\n                    return 1;\n                }\n            }\n            if (a1.length < a2.length) {\n                return -1;\n            } else if (a1.length > a2.length) {\n                return 1;\n            } else {\n                return 0;\n            }\n        }\n    }\n    \n    private static String ArraysToString(int[] arr){\n        String s = Arrays.toString(arr);\n        s = s.replaceAll(\",\",\"\");\n        s = s.substring(1,s.length()-1);\n        return s;\n    }\n\n    static class GeekInteger {\n        public static void save_sort(int[] array) {\n            shuffle(array);\n            Arrays.sort(array);\n        }\n\n        public static int[] shuffle(int[] 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                int randomElement = array[j];\n                array[j] = array[i];\n                array[i] = randomElement;\n            }\n            return array;\n        }\n\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 DSU {\n    private int n;\n    private int[] parentOrSize;\n    private java.util.ArrayList<java.util.ArrayList<Integer>> map;\n\n    public DSU(int n) {\n        this.n = n;\n        this.map = new java.util.ArrayList<java.util.ArrayList<Integer>>();\n        for (int i = 0; i < n; i++) {\n            this.map.add(new java.util.ArrayList<Integer>());\n            this.map.get(i).add(i);\n        }\n        this.parentOrSize = new int[n];\n        java.util.Arrays.fill(parentOrSize, -1);\n    }\n\n    int merge(int a, int b) {\n        if (!(0 <= a && a < n))\n            throw new IndexOutOfBoundsException(\"a=\" + a);\n        if (!(0 <= b && b < n))\n            throw new IndexOutOfBoundsException(\"b=\" + b);\n\n        int x = leader(a);\n        int y = leader(b);\n        if (x == y)\n            return x;\n        if (-parentOrSize[x] < -parentOrSize[y]) {\n            int tmp = x;\n            x = y;\n            y = tmp;\n        }\n        parentOrSize[x] += parentOrSize[y];\n        parentOrSize[y] = x;\n        this.map.get(x).addAll(this.map.get(y));\n        return x;\n    }\n\n    boolean same(int a, int b) {\n        if (!(0 <= a && a < n))\n            throw new IndexOutOfBoundsException(\"a=\" + a);\n        if (!(0 <= b && b < n))\n            throw new IndexOutOfBoundsException(\"b=\" + b);\n        return leader(a) == leader(b);\n    }\n\n    int leader(int a) {\n        if (parentOrSize[a] < 0) {\n            return a;\n        } else {\n            parentOrSize[a] = leader(parentOrSize[a]);\n            return parentOrSize[a];\n        }\n    }\n\n    int size(int a) {\n        if (!(0 <= a && a < n))\n            throw new IndexOutOfBoundsException(\"\" + a);\n        return -parentOrSize[leader(a)];\n    }\n\n    java.util.ArrayList<java.util.ArrayList<Integer>> groups() {\n        int[] leaderBuf = new int[n];\n        int[] groupSize = new int[n];\n        for (int i = 0; i < n; i++) {\n            leaderBuf[i] = leader(i);\n            groupSize[leaderBuf[i]]++;\n        }\n        java.util.ArrayList<java.util.ArrayList<Integer>> result = new java.util.ArrayList<>(n);\n        for (int i = 0; i < n; i++) {\n            result.add(new java.util.ArrayList<>(groupSize[i]));\n        }\n        for (int i = 0; i < n; i++) {\n            result.get(leaderBuf[i]).add(i);\n        }\n        result.removeIf(java.util.ArrayList::isEmpty);\n        return result;\n    }\n\n    java.util.ArrayList<Integer> getArray(int n) {\n        return this.map.get(n);\n    }\n}\n\nclass 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 FastScanner(FileReader in) {\n        reader = new BufferedReader(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", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\npublic class A {\n\n    private static final int INF = (int) 1e9 + 7;\n\n    public static void main(String[] args) {\n        FastScanner fs=new FastScanner();\n        PrintWriter pr = new PrintWriter(System.out);\n//        int T=fs.nextInt();\n//        for (int tt=1; tt<=T; tt++) {\n            int n = fs.nextInt(), m = fs.nextInt(), k = fs.nextInt();\n            int[][] right = new int[n][m -1], down = new int[n - 1][m];\n            for(int i = 0; i < n; i++) right[i] = fs.readArray(m - 1);\n            for(int i = 0; i < n - 1; i++) down[i] = fs.readArray(m);\n            if (k % 2 == 1) {\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) pr.print(-1 + \" \");\n                    pr.println();\n                }\n            } else {\n                int[][][] dp = new int[k / 2 + 1][n][m];\n\n                for(int r = 1; 2 * r <= k; r++) {\n                    for(int i = 0; i < n; i++) Arrays.fill(dp[r][i], INF);\n                    for(int i = 0; i < n; i++)\n                        for(int j = 0; j  + 1 < m; j++) {\n                            int cost = right[i][j];\n                            dp[r][i][j] = Integer.min(dp[r][i][j], dp[r - 1][i][j + 1] + cost);\n                            dp[r][i][j + 1] = Integer.min(dp[r][i][j + 1], dp[r - 1][i][j] + cost);\n                        }\n                    for(int i = 0; i + 1 < n; i++)\n                        for(int j = 0; j < m; j++) {\n                            int cost = down[i][j];\n                            dp[r][i][j] = Integer.min(dp[r][i][j], dp[r - 1][i + 1][j] + cost);\n                            dp[r][i + 1][j] = Integer.min(dp[r][i + 1][j], dp[r - 1][i][j] + cost);\n                        }\n                }\n                for(int i = 0; i < n; i++) {\n                    for(int j = 0; j < m; j++) {\n                        pr.print(2 * dp[k/2][i][j] + \" \");\n                    }\n                    pr.println();\n                }\n            }\n\n\n//        }\n\n        pr.flush();\n        pr.close();\n    }\n\n    static void sort(int[] a) {\n        ArrayList<Integer> l=new ArrayList<>();\n        for (int i:a) l.add(i);\n        Collections.sort(l);\n        for (int i=0; i<a.length; i++) a[i]=l.get(i);\n    }\n\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        int[] readArray(int n) {\n            int[] a=new int[n];\n            for (int i=0; i<n; i++) a[i]=nextInt();\n            return a;\n        }\n        long[] readLongArray(int n) {\n            long[] a=new long[n];\n            for (int i=0; i<n; i++) a[i]=nextLong();\n            return a;\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class a{\n    static BufferedReader br;\n    static PrintWriter pw;\n    static int N, M, K;\n    static ArrayList<Integer> graph[][];\n    public static void main(String args[]) throws IOException{\n        br = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        N = Integer.parseInt(st.nextToken());\n        M = Integer.parseInt(st.nextToken());\n        K = Integer.parseInt(st.nextToken());\n        if(K % 2 == 1){\n            for(int i = 0; i < N; i++){\n                for(int j = 0; j < M; j++){\n                    pw.print(\"-1 \");\n                }\n                pw.println();\n            }\n            br.close(); pw.close();\n            return;\n        }\n        graph = new ArrayList[N][M];\n        for(int i = 0; i < N; i++){\n            for(int j = 0; j < M; j++){\n                graph[i][j] = new ArrayList<Integer>();\n            }\n        }\n        for(int i = 0; i < N; i++){\n            st = new StringTokenizer(br.readLine());\n            for(int j = 0; j < M-1; j++){\n                int w = Integer.parseInt(st.nextToken());\n                graph[i][j].add(w);\n            }\n        }\n        for(int i = 0; i < N; i++){\n            graph[i][M-1].add(0);\n        }\n        for(int i = 0; i < N-1; i++){\n            st = new StringTokenizer(br.readLine());\n            for(int j = 0; j < M; j++){\n                int w = Integer.parseInt(st.nextToken());\n                graph[i][j].add(w);\n            }\n        }\n        K /= 2;\n        for(int i = 0; i < M; i++) graph[N-1][i].add(0);\n        long ans[][][] = new long[K+1][N][M];\n        for(int i = 0; i < N; i++){\n            Arrays.fill(ans[0][i], 0);\n        }\n        for(int i = 1; i <= K; i++){\n            for(int x = 0; x < N; x++){\n                for(int y = 0; y < M; y++){\n                    long cur = (long)1e17;\n                    if(x < N-1){\n                        cur = (long)Math.min(cur, graph[x][y].get(1) + ans[i-1][x+1][y]);\n                    }\n                    if(y < M-1){\n                        cur = (long)Math.min(cur, graph[x][y].get(0) + ans[i-1][x][y+1]);\n                    }\n                    if(x > 0){\n                        cur = (long)Math.min(cur, graph[x-1][y].get(1) + ans[i-1][x-1][y]);\n                        //pw.println(\"CUR: \" + cur + \" X: \" + x + \" Y: \" + y + \" get = \" + graph[x-1][y].get(0));\n                    }\n                    if(y > 0){\n                        cur = (long)Math.min(cur, graph[x][y-1].get(0) + ans[i-1][x][y-1]);\n                    }\n                    ans[i][x][y] = cur;\n                }\n            }\n        }\n        for(int i = 0; i < N; i++){\n            for(int j = 0; j < M; j++){\n                pw.print(ans[K][i][j] * 2 + \" \");\n            }\n            pw.println();\n        }\n        br.close(); pw.close();\n    }\n    static class pii implements Comparable<pii>{\n        int f, s, k;\n        pii(int f, int s, int k){\n            this.f = f;\n            this.s = s;\n            this.k = k;\n        }\n        public int compareTo(pii x){\n            return Integer.compare(f, x.f);\n        }\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * @Author:\n * @Date: 2021/4/23 23:55\n */\npublic class ExplorerSpace {\n    static int n;\n    static int m;\n    static int k;\n    static int [][] rows;\n    static int [][] cols;\n    static int max;\n    static int orix;\n    static int oriy;\n    static int [][] dirs = new int[][]{{0,1},{0,-1},{1,0},{-1,0}};\n    static int [][][][][] mem;\n    public static void main(String[] args) {\n        FastScanner fs = new FastScanner();\n        n = fs.nextInt();\n        m =fs.nextInt();\n        k = fs.nextInt();\n        rows = new int[n][m-1];\n        cols = new int[n-1][m];\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m-1; j++){\n                rows[i][j] = fs.nextInt();\n            }\n        }\n        for(int i = 0; i < n-1; i++){\n            for(int j = 0; j < m; j++){\n                cols[i][j] = fs.nextInt();\n            }\n        }\n        int [][][] res = new int[100][n][m];\n        for(int o = 2; o <= k; o+=2){\n            for(int i = 0; i < n; i++){\n                for(int j = 0; j < m; j++){\n                    res[o][i][j] = 0x3f3f3f3f;\n                    if(i>0){\n                        res[o][i][j] = Math.min(res[o][i][j], res[o-2][i-1][j] + 2*cols[i-1][j]);\n                    }\n                    if(i+1<n){\n                        res[o][i][j] = Math.min(res[o][i][j], res[o-2][i+1][j] + 2 * cols[i][j]);\n                    }\n                    if(j>0){\n                        res[o][i][j] = Math.min(res[o][i][j], res[o-2][i][j-1] + 2 * rows[i][j-1]);\n                    }\n                    if(j+1<m){\n                        res[o][i][j] = Math.min(res[o][i][j], res[o-2][i][j+1] + 2 * rows[i][j]);\n                    }\n                }\n            }\n        }\n\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m;j ++){\n                if(k%2==1){\n                    System.out.print(-1+\" \");\n                }else{\n                    System.out.print(res[k][i][j] + \" \");\n                }\n\n            }\n            System.out.println();\n        }\n    }\n\n//    static void dfs(int x, int y,int cur, int left){\n//        if(x<0||x>=n||y<0||y>=m){\n//            return;\n//        }\n//        if(left==0&&x==orix&&y==oriy){\n//            max = Math.min(max,cur);\n//            return;\n//        }\n//        if(left<=0){\n//            return;\n//        }\n//        if(cur>=max){\n//            return;\n//        }\n//        if(x+1<n){\n//            dfs(x+1,y,cur+cols[x][y],left-1);\n//        }\n//        if(x-1>=0){\n//            dfs(x-1,y,cur+cols[x-1][y],left-1);\n//        }\n//        if(y+1<m){\n//            dfs(x,y+1,cur+rows[x][y],left-1);\n//        }\n//        if(y-1>=0){\n//            dfs(x,y-1,cur+rows[x][y-1],left-1);\n//        }\n//\n//    }\n    static class  FastScanner{\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(\"\");\n        String next(){\n            while (!st.hasMoreTokens()){\n                try {\n                    st = new StringTokenizer(br.readLine());\n                }catch (IOException e){\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt(){\n            return Integer.parseInt(next());\n        }\n        long nextLong(){\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.sql.Array;\nimport java.util.*;\nimport java.util.List;\n\npublic class Main {\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader()\n        {\n            br = new BufferedReader(\n                    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                }\n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() { return Integer.parseInt(next()); }\n\n        long nextLong() { return Long.parseLong(next()); }\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            }\n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n\n    static final int N=205;\n    static final int mod=1000000007;\n    static final int INF=1000000009;\n    static final int numBit=17;\n    static FastReader r=new FastReader();\n    static PrintWriter pw = new PrintWriter(System.out);\n\n    public static void main(String[] args) throws IOException {\n        int n=r.nextInt();\n        int m=r.nextInt();\n        int k=r.nextInt();\n        int [][]hor=new int[n][m-1];\n        int [][]ver=new int[n-1][m];\n        for(int i=0;i<n;++i){\n            for(int j=0;j<m-1;++j) hor[i][j]=r.nextInt();\n        }\n        for(int i=0;i<n-1;++i){\n            for(int j=0;j<m;++j) ver[i][j]=r.nextInt();\n        }\n        int [][]dp=new int[n][m];\n        if(k%2!=0){\n            for(int i=0;i<n;++i){\n                for(int j=0;j<m;++j) dp[i][j]=-1;\n            }\n        }\n        else{\n            int [][]new_dp=new int[n][m];\n            for(int step=0;step<k/2;++step){\n                for(int i=0;i<n;++i){\n                    for(int j=0;j<m;++j){\n                        new_dp[i][j]=INF;\n                        if(i>0){\n                            new_dp[i][j]=Math.min(new_dp[i][j],dp[i-1][j]+ver[i-1][j]*2);\n                        }\n                        if(i<n-1){\n                            new_dp[i][j]=Math.min(new_dp[i][j],dp[i+1][j]+ver[i][j]*2);\n                        }\n                        if(j>0){\n                            new_dp[i][j]=Math.min(new_dp[i][j],dp[i][j-1]+hor[i][j-1]*2);\n                        }\n                        if(j<m-1){\n                            new_dp[i][j]=Math.min(new_dp[i][j],dp[i][j+1]+hor[i][j]*2);\n                        }\n                    }\n                }\n                for(int i=0;i<n;++i){\n                    for(int j=0;j<m;++j){\n                        dp[i][j]=new_dp[i][j];\n                    }\n                }\n            }\n        }\n        for(int i=0;i<n;++i){\n            for(int j=0;j<m;++j){\n                pw.print(dp[i][j]+\" \");\n            }\n            pw.println();\n        }\n        pw.close();\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.io.*;\n \npublic class ExplorerSpace {\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    }\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\n\t    int nextInt() {\n\t        return Integer.parseInt(next());\n\t    }\n\n\t    long nextLong() {\n\t        return Long.parseLong(next());\n\t    }\n\n\t    double nextDouble() {\n\t        return Double.parseDouble(next());\n\t    }\n\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\n\t }\n\t\n    \n\tpublic static long[][][] dp; \n\t\n\tpublic static boolean valid(int i, int j, int n, int m)\n\t{\n\t\treturn i>=0 && i<n &&j>=0 && j<m;\n\t}\n\t\n\tpublic static void solution(int n, int m, int k, int[][] h, int[][] v)\n\t\t\t\n\t{\n\t\tif(k%2==1)\n\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<m; j++)\n\t\t\t\t   out.print(-1+\" \");\n\t\t\t\t\n\t\t\t\tout.println();\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdp = new long[n][m][k/2+1];\n\t\t\n\t\tfor(int t = 1; t<=k/2; t++)\n\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<m; j++)\n\t\t\t\t{\n\t\t\t\t\tdp[i][j][t] = Long.MAX_VALUE;\n\t\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; i++)\n\t\t{\n\t\t\tfor(int j = 0; j<m; j++)\n\t\t\t{\n\t\t\t\tdp[i][j][0] = 0;\n\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tfor(int t = 1; t<=k/2; t++)\n\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<m; j++)\n\t\t\t\t{\n\t\t\t\t\tif(valid(i,j+1,n,m))\n\t\t\t\t\t\tdp[i][j][t] = Math.min(dp[i][j][t], h[i][j] + dp[i][j+1][t-1]); \n\t\t\t\t\n\t\t\t\t\tif(valid(i,j-1,n,m))\n\t\t\t\t\t\t dp[i][j][t] = Math.min(dp[i][j][t], h[i][j-1] + dp[i][j-1][t-1]);\n\t\t\t\t\n\t\t\t\t\tif(valid(i+1,j,n,m))\n\t\t\t\t\t\t dp[i][j][t] = Math.min(dp[i][j][t], v[i][j] + dp[i+1][j][t-1]); \n\t\t\t\n\t\t\t\t\tif(valid(i-1,j,n,m))\n\t\t\t\t\t\tdp[i][j][t] = Math.min(dp[i][j][t], v[i-1][j] + dp[i-1][j][t-1]); \n\t\t\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<n; i++)\n\t\t{\n\t\t\tfor(int j = 0; j<m; j++)\n\t\t\t\tout.print((dp[i][j][k/2]*2)+\" \");\n\t\t\t\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n        \nprivate static PrintWriter out = new PrintWriter(System.out);\n\npublic static void main (String[] args)\n{\n\tMyScanner s =  new MyScanner();\n     \n    int n = s.nextInt();\n    int m = s.nextInt();\n    int k = s.nextInt();\n    \n    int[][] h = new int[n][m-1];\n    \n    for(int i = 0; i<n; i++)\n    {\n    \tfor(int j = 0; j<m-1; j++)\n    \t{\n    \t\th[i][j] = s.nextInt();\n    \t}\n    }\n    \n    int[][] v = new int[n-1][m];\n    \n    for(int i = 0; i<n-1; i++)\n    {\n    \tfor(int j = 0; j<m; j++)\n    \t{\n    \t\tv[i][j] = s.nextInt();\n    \t}\n    }\n    \n    \n   solution(n,m,k,h,v);\n    \n    out.flush();\n    out.close();\n    \n}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.*;\n\npublic class Main {\n    static public void main(String args[]) throws Exception {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt(), m = s.nextInt(), K = s.nextInt();\n        int[][] p = new int[n][m - 1];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m - 1; j++) {\n                p[i][j] = s.nextInt();\n            }\n        }\n        int[][] v = new int[n - 1][m];\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = 0; j < m; j++) {\n                v[i][j] = s.nextInt();\n            }\n        }\n        if (K % 2 == 1){\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    System.out.print(\"-1 \");\n                }\n                System.out.println();\n            }\n\n            return;\n        }\n\n        long[][][] dp = new long[K + 1][n][m];\n        for (int k = 2; k <= K; k += 2) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    long res = Long.MAX_VALUE;\n                    if (i + 1 < n) {\n                        res = Math.min(res, dp[k - 2][i + 1][j] + v[i][j] * 2);\n                    }\n                    if (i - 1 >= 0) {\n                        res = Math.min(res, dp[k - 2][i - 1][j] + v[i - 1][j] * 2);\n                    }\n                    if (j + 1 < m) {\n                        res = Math.min(res, dp[k - 2][i][j + 1] + p[i][j] * 2);\n                    }\n\n                    if (j - 1 >= 0) {\n                        res = Math.min(res, dp[k - 2][i][j - 1] + p[i][j - 1] * 2);\n                    }\n                    dp[k][i][j] = res;\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                System.out.print(dp[K][i][j] + \" \");\n            }\n            System.out.println();\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\npublic class Main{\n    static InputReader sc;\n    static PrintWriter pw;\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        sc = new InputReader(inputStream);\n        pw = new PrintWriter(outputStream);\n        solve();\n        pw.close();\n    }\n    // static int L,R,top,bottom;\n    // static int cnt,edge;\n    // static long ans;\n    public static void solve() {\n        // int t=sc.nextInt();           \n        int t=1;\n        u:while(t-->0){ \n            int n=s(0); \n            int m=s(0);\n            int k=s(0);            \n            long [][][]arr=new long [n][m][4];\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m-1;j++){\n                    long v=s(0l);\n                    arr[i][j][0]=v;\n                    arr[i][j+1][2]=v;\n                }\n            }\n            for(int i=0;i<n-1;i++){\n                for(int j=0;j<m;j++){\n                    long v=s(0l);\n                    arr[i][j][1]=v;\n                    arr[i+1][j][3]=v;\n                }\n            }\n            Long [][][]dp=new Long [n][m][k+1];\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m;j++)\n                    for(int p=1;p<=k;p++)\n                        helper(i,j,p,dp,arr,n,m);\n            }\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m;j++)\n                    p(dp[i][j][k]+\" \");\n                pln(\"\");\n            }\n        }           \n    }         \n    static int [][]dir=new int [][]{{0,1},{1,0},{0,-1},{-1,0}};\n    public static long helper(int i, int j, int k, Long [][][]dp, long [][][]arr, int n, int m){\n        if(k<0)\n            return -1;\n        if(k==0)\n            return 0;\n        if(dp[i][j][k]!=null)\n            return dp[i][j][k];\n        int x, y;\n        long ans=Long.MAX_VALUE,val;\n        for(int d=0;d<4;d++){\n            x=i+dir[d][0];\n            y=j+dir[d][1];\n            if(x<0||x>=n||y<0||y>=m)\n                continue;\n            val=helper(x,y,k-2,dp,arr,n,m);\n            if(val!=-1)\n                ans=Math.min(ans,val+2*arr[i][j][d]);\n        }\n        return dp[i][j][k]=(ans==Long.MAX_VALUE?-1:ans);        \n    }\n    public static int find(List<Integer> list, int x){\n        int l=0,r=list.size()-1,m;\n        while(l<=r){\n            m=(r-l)/2+l;\n            if(list.get(m)<=x)\n                l=m+1;\n            else\n                r=m-1;\n        }\n        return r;\n    } \n    static class Node{\n        int val;\n        long cost;\n        Node next;\n        Node(int v,long c){\n            val=v;\n            next=null;\n            cost=c;\n        }\n    }    \n    public static long sum(long n){\n        long val=0l;\n        while(n>0){\n            val+=n%10;\n            n/=10;\n        }\n        return val;\n    }\n    // static class Node{\n    //     int left,right;\n    //     Node prev,next;\n    //     Node(int i, int v){\n    //         left=i;\n    //         right=v;\n    //         prev=next=null;\n    //     }\n    //     void remove(){\n    //         this.prev.next=this.next;\n    //         this.next.prev=this.prev;\n    //     }\n    //     void insert(Node node){\n    //         node.next=this;\n    //         node.prev=this.prev;\n    //         node.prev.next=node;\n    //         this.prev=node;\n    //     }\n    // } \n    public static int  findDiameter(int r, List<List<Integer>>list){\n        return findFarthest(findFarthest(r,list)[0],list)[1];\n    }\n    public static int[] findFarthest(int u, List<List<Integer>>list){\n        int n=list.size();\n        boolean []vis=new boolean[n+1];\n        Queue<Integer>q=new LinkedList<>();\n        q.offer(u);\n        vis[u]=true;\n        int s,pr,cnt=0;\n        int []ar=new int[]{u,0};\n        while(q.size()>0){\n            s=q.size();\n            while(s-->0){\n                pr=q.poll();\n                if(ar[1]<cnt){\n                    ar[1]=cnt;\n                    ar[0]=pr;\n                }\n                for(int i:list.get(pr)){\n                    if(!vis[i]){\n                        vis[i]=true;\n                        q.offer(i);\n                    }\n                }\n            }\n            cnt++;\n        }\n        return ar;\n    }\n    public static long atMostK(char []chrr, int k){\n        if(k<0)\n            return 0;\n        int l=0,cnt=0;\n        long ans=0l;\n        for(int i=0;i<chrr.length;i++){\n            if(chrr[i]=='1')\n                cnt++;\n            while(cnt>k){\n                if(chrr[l++]=='1')\n                    cnt--;\n            }\n            ans+=(long)(i-l)+1l;\n        }\n        return ans;\n    }\n    public static int ask(int l){\n        System.out.println(l);\n        System.out.flush();\n        return sc.nextInt();\n    }\n    public static void sort(long []arr){\n        ArrayList<Long> list=new ArrayList<>();\n        for(int i=0;i<arr.length;i++)\n            list.add(arr[i]);\n        Collections.sort(list);\n        for(int i=0;i<arr.length;i++)\n            arr[i]=list.get(i);\n    }\n    public static void swap(char []chrr, int i, int j){\n        char temp=chrr[i];\n        chrr[i]=chrr[j];\n        chrr[j]=temp;\n    }\n    public static int countSetBits(long n){\n        int a=0;\n        while(n>0){\n            a+=(n&1);\n            n>>=1;\n        }\n        return a;\n    }\n    static class Pair{\n        int v,w;\n        Pair(int V, int W){\n            v=V;\n            w=W;\n        }\n     //*\n    }\n    /*/\n        public int compareTo(Pair p){\n            return (b-p.b);\n        }\n        public int hashCode(){\n            int hashcode = (a+\" \"+b).hashCode();\n            return hashcode;\n        }\n        public boolean equals(Object obj){\n            if (obj instanceof Pair) {\n                Pair p = (Pair) obj;\n                return (p.a==this.a && p.b == this.b);\n            }\n            return false;\n        }\n    }\n    //*/\n    static boolean isPrime(long n) { \n        if (n <= 1) \n            return false; \n        if (n <= 3) \n            return true; \n        if (n % 2 == 0 || n % 3 == 0) \n            return false; \n        for (int i = 5; i * i <= n; i = i + 6) \n            if (n % i == 0 || n % (i + 2) == 0) \n                return false; \n        return true; \n    } \n    static long gcd(long a, long b) { \n        if (b == 0) \n            return a; \n        return a>b?gcd(b, a % b):gcd(a, b % a);  \n    } \n    static long fast_pow(long base,long n,long M){\n        if(n==0)\n           return 1;\n        if(n==1)\n        return base;\n        long halfn=fast_pow(base,n/2,M);\n        if(n%2==0)\n            return ( halfn * halfn ) % M;\n        else\n            return ( ( ( halfn * halfn ) % M ) * base ) % M;\n    }\n    static long modInverse(long n,long M){\n        return fast_pow(n,M-2,M);\n    }\n    public static int s(int n){\n        return sc.nextInt();\n    }\n    public static long s(long n){\n        return sc.nextLong();\n    }\n    public static String s(String n){\n        return sc.next();\n    }\n    public static double s(double n){\n        return sc.nextDouble();\n    }\n    public static void p(int n){\n        pw.print(n);\n    }\n    public static void p(long n){\n        pw.print(n);\n    }\n    public static void p(String n){\n        pw.print(n);\n    }\n    public static void p(double n){\n        pw.print(n);\n    }\n    public static void pln(int n){\n        pw.println(n);\n    }\n    public static void pln(long n){\n        pw.println(n);\n    }\n    public static void pln(String n){\n        pw.println(n);\n    }\n    public static void pln(double n){\n        pw.println(n);\n    }\n    public static void feedArr(long []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.nextLong();\n    }\n    public static void feedArr(double []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.nextDouble();\n    }\n    public static void feedArr(int []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.nextInt();\n    }\n    public static void feedArr(String []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.next();\n    }\n    public static String printArr(int []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(int i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\n    }\n    public  static String printArr(long []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(long i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\n    }\n    public static String printArr(String []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(String i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\n    }\n    public static String printArr(double []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(double i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\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        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        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\n\npublic class D_Rnd718_Explorer\n{\n\tstatic int row, col;\n\tstatic int INF = 1_000_000_000;\n\tstatic int[] dx = {0, 0, 1, -1};\n\tstatic int[] dy = {1, -1, 0, 0};\n\tpublic static void main(String[] args) throws NumberFormatException, IOException \n\t{\n\t\tBufferedReader scan = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tString[] in = scan.readLine().split(\" \");\n\t\trow = parse(in[0]);\n\t\tcol = parse(in[1]);\n\t\tint k = parse(in[2]);\n\t\t\n\t\tint[][] xMove = new int[row][col-1];\n\t\tfor(int i = 0; i < row; i++)\n\t\t{\n\t\t\tin = scan.readLine().split(\" \");\n\t\t\tfor(int j = 0; j < col - 1; j++)\n\t\t\t\txMove[i][j] = parse(in[j]);\n\t\t}\n\t\t\n\t\tint[][] yMove = new int[row - 1][col];\n\t\tfor(int i = 0; i < row - 1; i++)\n\t\t{\n\t\t\tin = scan.readLine().split(\" \");\n\t\t\tfor(int j = 0; j < col; j++)\n\t\t\t\tyMove[i][j] = parse(in[j]);\n\t\t}\n\t\t\n\t\t\n\t\tint[][] output = new int[row][col];\n\t\t\n\t\tif(k % 2 != 0)\n\t\t\tfill(-1, output);\n\t\t\n\t\telse\n\t\t{\n\t\t\tPoint[][] grid = new Point[row][col];\n\t\t\tfor(int i = 0; i < row; i++)\n\t\t\t\tfor(int j = 0; j < col; j++)\n\t\t\t\t\tgrid[i][j] = new Point(i, j);\n\t\t\t\n\t\t\tparseMoves(grid, xMove, yMove);\n\t\t\t\n\t\t\tsolve(grid, k, output);\n\t\t}\n\t\t\n\t\tprint(output, out);\n\t\t\n\t\tout.flush();\n\t}\n\n\tprivate static void solve(Point[][] grid, int k, int[][] output) \n\t{\n\t\t// try bfs (hoping it passes the time constraint)\n\t\t/*int target = k / 2;\n\t\tfor(int i = 0; i < row; i++)\n\t\t\tfor(int j = 0; j < col; j++)\n\t\t\t\toutput[i][j] = bfs(j, i, target, grid) << 1;*/\n\t\tint target = k / 2;\n\t\tint[][][] dist = new int[row][col][k/2];\n\t\tfill(dist, grid);\n\t\t\n\t\tfor(int steps = 1; steps < target; steps++ )\n\t\t{\n\t\t\tfor(int i = 0; i < row; i++)\n\t\t\t{\n\t\t\t\tfor(int j = 0; j < col;j ++)\n\t\t\t\t{\n\t\t\t\t\tdist[i][j][steps] = getDist(i, j, steps, dist, grid);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < row; i++)\n\t\t\tfor(int j = 0; j < col;j ++)\n\t\t\t\toutput[i][j] = (dist[i][j][target - 1] << 1);\n\t\t\n\t}\n\n\n\n\tprivate static int getDist(int y, int x, int steps, int[][][] dist, Point[][] grid) \n\t{\n\t\tfor(int d = 0; d < 4; d++)\n\t\t{\n\t\t\tint i = y + dy[d];\n\t\t\tint j = x + dx[d];\n\t\t\t\n\t\t\tif(valid(i, j))\n\t\t\t{\n\t\t\t\tdist[y][x][steps] = Math.min(dist[y][x][steps], dist[i][j][steps - 1] + grid[y][x].weight[d]);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn dist[y][x][steps];\n\t}\t\n\t\n\tprivate static void fill(int[][][] dist, Point[][] grid) \n\t{\n\t\tfor(int i = 0; i < row; i++)\n\t\t\tfor(int j = 0; j < col;j ++)\n\t\t\t\tfor(int s = 0; s < dist[0][0].length; s++)\n\t\t\t\t\tdist[i][j][s] = INF;\n\t\t\n\t\tfor(int i = 0; i < row; i++)\n\t\t\tfor(int j = 0; j < col; j++)\n\t\t\t\tfor(int d = 0; d < 4; d++)\n\t\t\t\t\tdist[i][j][0] = Math.min(dist[i][j][0], grid[i][j].weight[d]);\n\t\t\n\t}\n\n\tprivate static boolean valid(int y, int x) \n\t{\n\t\treturn y >= 0 && x >= 0 && y < row && x < col;\n\t}\n\n\t/*private static int bfs(int xStart, int yStart, int target, Point[][] grid) \n\t{\n\t\tPriorityQueue<Step> q = new PriorityQueue<Step>();\n\t\tq.add(new Step(grid[yStart][xStart], 0, 0));\n\t\t\n\t\tStep s;\n\t\tint w;\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\ts = q.poll();\n\t\t\t\n\t\t\tif(s.numSteps == target)\n\t\t\t\treturn s.length;\n\t\t\t\n\t\t\t// try to go in each of the four directions\n\t\t\tfor(int d = 0; d < 4; d++)\n\t\t\t{\n\t\t\t\tw = s.current.weight[d];\n\t\t\t\tif(w != -1)\n\t\t\t\t\tq.add(new Step(grid[s.current.y + s.current.dy[d]][s.current.x + s.current.dx[d]], s.length + w, s.numSteps + 1));\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn -1;\n\t}*/\n\n\tprivate static void parseMoves(Point[][] grid, int[][] xMove, int[][] yMove) \n\t{\n\t\tfor(int i = 0; i < xMove.length; i++)\n\t\t{\n\t\t\tfor(int j = 0; j < xMove[i].length; j++)\n\t\t\t{\n\t\t\t\tgrid[i][j].weight[2] = xMove[i][j];\t// right\n\t\t\t\tgrid[i][j + 1].weight[3] = xMove[i][j]; // left\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < yMove.length; i++)\n\t\t{\n\t\t\tfor(int j = 0; j < yMove[i].length; j++)\n\t\t\t{\n\t\t\t\tgrid[i][j].weight[0] = yMove[i][j];\t// down\n\t\t\t\tgrid[i + 1][j].weight[1] = yMove[i][j]; // up\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void fill(int val, int[][] output) \n\t{\n\t\tfor(int i = 0; i < output.length; i++)\n\t\t\tArrays.fill(output[i], val);\n\t}\n\t\n\tprivate static void print(int[][] ray, PrintWriter out) \n\t{\n\t\tfor(int i = 0; i < ray.length; i++)\n\t\t{\n\t\t\tout.print(ray[i][0]);\n\t\t\tfor(int j = 1; j < ray[i].length; j++)\n\t\t\t\tout.print(\" \" + ray[i][j]);\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n\n\tpublic static int parse(String num)\n\t{\n\t\treturn Integer.parseInt(num);\n\t}\n\t\n\tstatic class Point\n\t{\n\n\t\tint[] weight = new int[4];\t\t// down, up, right, left\n\t\tint x, y;\n\t\t\n\t\tpublic Point(int i, int j)\n\t\t{\n\t\t\ty = i;\n\t\t\tx = j;\n\t\t\tArrays.fill(weight, INF);\n\t\t}\n\t}\n\t\n\tstatic class Step implements Comparable<Step>\n\t{\n\t\tint length, numSteps;\n\t\tPoint current;\n\t\t\n\t\tpublic Step(Point p, int weight, int s)\n\t\t{\n\t\t\tcurrent = p;\n\t\t\tlength = weight;\n\t\t\tnumSteps = s;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Step s) \n\t\t{\n\t\t\tif(length == s.length)  return numSteps - s.numSteps;\n\t\t\treturn length - s.length;\n\t\t}\n\t}\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "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.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        DExplorerSpace solver = new DExplorerSpace();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class DExplorerSpace {\n        int n;\n        int m;\n        int k;\n        int[][] col;\n        int[][] row;\n        long[][][] memo;\n\n        public void readInput(Scanner sc) {\n            n = sc.nextInt();\n            m = sc.nextInt();\n            k = sc.nextInt();\n            col = new int[n][m - 1];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m - 1; j++)\n                    col[i][j] = sc.nextInt();\n            row = new int[n - 1][m];\n            for (int i = 0; i < n - 1; i++)\n                for (int j = 0; j < m; j++)\n                    row[i][j] = sc.nextInt();\n        }\n\n        public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n            int q = 1;\n            while (q-- > 0) {\n                readInput(sc);\n                if (k % 2 == 1) {\n                    for (int i = 0; i < n; i++) {\n                        for (int j = 0; j < m; j++)\n                            pw.print(-1 + \" \");\n                        pw.println();\n                    }\n                    return;\n                }\n                memo = new long[k + 1][n][m];\n                for (long[][] x : memo)\n                    for (long[] y : x)\n                        Arrays.fill(y, -1);\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        pw.print(2l * dp(i, j, k / 2) + \" \");\n                    }\n                    pw.println();\n                }\n            }\n        }\n\n        private long dp(int i, int j, int rem) {\n            if (rem == 0)\n                return 0;\n            if (memo[rem][i][j] != -1)\n                return memo[rem][i][j];\n            long min = (long) 1e18;\n            if (j <= m - 2)\n                min = Math.min(min, col[i][j] + dp(i, j + 1, rem - 1));\n            if (j > 0)\n                min = Math.min(min, col[i][j - 1] + dp(i, j - 1, rem - 1));\n            if (i <= n - 2)\n                min = Math.min(min, row[i][j] + dp(i + 1, j, rem - 1));\n            if (i > 0)\n                min = Math.min(min, row[i - 1][j] + dp(i - 1, j, rem - 1));\n            return memo[rem][i][j] = min;\n        }\n\n    }\n\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public Scanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public String next() {\n            try {\n                while (st == null || !st.hasMoreTokens())\n                    st = new StringTokenizer(br.readLine());\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    }\n}\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.*;\n\npublic class D {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        int t = 1;\n        for (int i = 0; i < t; i++) {\n            solve(sc, pw);\n        }\n        pw.close();\n    }\n    static void solve(Scanner in, PrintWriter out){\n        int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();\n        int[][] ri = new int[n][m - 1];\n        int[][] dn = new int[n - 1][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m - 1; j++) {\n                ri[i][j] = in.nextInt();\n            }\n        }\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = 0; j < m; j++) {\n                dn[i][j] = in.nextInt();\n            }\n        }\n        long[][][] dp = new long[n][m][k + 1];\n        if (k % 2 == 1){\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.print(-1 +\" \");\n                }\n                out.println();\n            }\n        }else{\n            for (int l = 2; l <= k; l += 2) {\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        long dm = Long.MAX_VALUE;\n                        if (i > 0){\n                            int pi = i - 1, pj = j;\n                            dm = Math.min(dm, dp[pi][pj][l - 2] + dn[pi][pj] * 2);\n                        }\n                        if (j > 0){\n                            int pi = i ,pj = j - 1;\n                            dm = Math.min(dm, dp[pi][pj][l - 2] + ri[pi][pj] * 2);\n                        }\n                        if (i < n - 1){\n                            dm = Math.min(dm, dp[i + 1][j][l - 2] + dn[i][j] * 2);\n                        }\n                        if (j < m - 1){\n                            dm = Math.min(dm, dp[i][j + 1][l - 2] + ri[i][j] * 2);\n                        }\n                        dp[i][j][l] = dm;\n                    }\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    if (dp[i][j][k] == Long.MAX_VALUE){\n                        out.print(-1 +\" \");\n                    }else{\n                        out.print(dp[i][j][k] +\" \");\n                    }\n                }\n                out.println();\n            }\n        }\n\n\n    }\n\n    static boolean isPrime(long n)\n    {\n        // Corner cases\n        if (n <= 1)\n            return false;\n        if (n <= 3)\n            return true;\n\n        // This is checked so that we can skip\n        // middle five numbers in below loop\n        if (n % 2 == 0 || n % 3 == 0)\n            return false;\n\n        for (int i = 5; i * i <= n; i = i + 6)\n            if (n % i == 0 || n % (i + 2) == 0)\n                return false;\n\n        return true;\n    }\n\n    static long gcd(long a, long b)\n    {\n        if (a == 0)\n            return b;\n        return gcd(b % a, a);\n    }\n\n    // method to return LCM of two numbers\n    static long lcm(long a, long b)\n    {\n        return (a / gcd(a, b)) * b;\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) ptn[i >> 5] |= 1 << (i & 31);\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, 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) break;\n                ret[pos++] = p;\n                if ((long) p * p > n) continue;\n                for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q;\n            }\n        }\n\n        return Arrays.copyOf(ret, pos);\n    }\n\n    //    reverse division for 2\n    public static long[] rdiv2(int n, int mod){\n        long[] arr = new long[n + 5];\n        arr[0] = 1;\n        long rev2 = (mod + 1) / 2;\n        for (int i = 1; i < n; i++) {\n            arr[i] = arr[i - 1] * rev2 % mod;\n        }\n        return arr;\n    }\n    static List<Integer> primeFactors(int n)\n    {\n        // Print the number of 2s that divide n\n        List<Integer> ls = new ArrayList<>();\n        if (n % 2 == 0) ls.add(2);\n        while (n%2==0)\n        {\n            n /= 2;\n        }\n\n        // n must be odd at this point.  So we can\n        // skip one element (Note i = i +2)\n        for (int i = 3; i <= Math.sqrt(n); i+= 2)\n        {\n            // While i divides n, print i and divide n\n            if (n  % i == 0) ls.add(i);\n            while (n%i == 0)\n            {\n                n /= i;\n            }\n        }\n        if (n > 1) ls.add(n);\n        return ls;\n    }\n}\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.DataInputStream;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Comparator;\n\npublic class D {\n\n    private static void run() throws IOException {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int p = in.nextInt();\n\n        int[] dx = {1, -1, 0, 0};\n        int[] dy = {0, 0, 1, -1};\n        int[][][] map = new int[n][m][4];\n\n        ArrayList<Edge> edges = new ArrayList<>();\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m - 1; j++) {\n                int len = in.nextInt();\n                edges.add(new Edge(new Point[]{new Point(i, j), new Point(i, j + 1)}, len));\n                map[i][j][2] = map[i][j + 1][3] = len;\n            }\n        }\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = 0; j < m; j++) {\n                int len = in.nextInt();\n                edges.add(new Edge(new Point[]{new Point(i, j), new Point(i + 1, j)}, len));\n                map[i][j][0] = map[i + 1][j][1] = len;\n            }\n        }\n        if (p % 2 != 0) {\n            int[] ans = new int[m];\n            for (int i = 0; i < m; i++) {\n                ans[i] = -1;\n            }\n            for (int i = 0; i < n; i++) {\n                print_array(ans);\n            }\n            return;\n        }\n\n        edges.sort(Comparator.comparingInt(o -> o.len));\n\n        int[][][] dp = new int[2][n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                int min = Integer.MAX_VALUE;\n                for (int k = 0; k < 4; k++) {\n                    if (map[i][j][k] == 0) continue;\n                    min = Math.min(min, map[i][j][k]);\n                }\n                dp[1][i][j] = min * 2;\n            }\n        }\n\n        for (int k = 2; k <= p / 2; k++) {\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    dp[k & 1][i][j] = Integer.MAX_VALUE;\n                    for (int d = 0; d < 4; d++) {\n                        int nx = i + dx[d];\n                        int ny = j + dy[d];\n                        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;\n\n                        dp[k & 1][i][j] = Math.min(dp[(k - 1) & 1][nx][ny] + map[i][j][d] * 2, dp[k&1][i][j]);\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            print_array(dp[(p / 2) & 1][i]);\n        }\n    }\n\n    static class Edge {\n        Point[] points;\n        int len;\n\n        public Edge(Point[] points, int len) {\n            this.points = points;\n            this.len = len;\n        }\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\n    public static void main(String[] args) throws IOException {\n        in = new Reader();\n        out = new PrintWriter(new OutputStreamWriter(System.out));\n\n//        int t = in.nextInt();\n//        for (int i = 0; i < t; i++) {\n//        }\n        run();\n\n        out.flush();\n        in.close();\n        out.close();\n    }\n\n    private static int gcd(int a, int b) {\n        if (a == 0 || b == 0)\n            return 0;\n        while (b != 0) {\n            int tmp;\n            tmp = a % b;\n            a = b;\n            b = tmp;\n        }\n        return a;\n    }\n\n    static final long mod = 1000000007;\n\n    static long pow_mod(long a, long b) {\n        long result = 1;\n        while (b != 0) {\n            if ((b & 1) != 0) result = (result * a) % mod;\n            a = (a * a) % mod;\n            b >>= 1;\n        }\n        return result;\n    }\n\n    private static long multiplied_mod(long... longs) {\n        long ans = 1;\n        for (long now : longs) {\n            ans = (ans * now) % mod;\n        }\n        return ans;\n    }\n\n    @SuppressWarnings(\"FieldCanBeLocal\")\n    private static Reader in;\n    private static PrintWriter out;\n\n    private static void print_array(int[] array) {\n        for (int now : array) {\n            out.print(now);\n            out.print(' ');\n        }\n        out.println();\n    }\n\n    private static void print_array(long[] array) {\n        for (long now : array) {\n            out.print(now);\n            out.print(' ');\n        }\n        out.println();\n    }\n\n    static class Reader {\n        private static final int BUFFER_SIZE = 1 << 16;\n        private final DataInputStream din;\n        private final byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        Reader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            final byte[] buf = new byte[1024]; // line length\n            int cnt = 0, c;\n            while ((c = read()) != -1) {\n                if (c == '\\n') {\n                    break;\n                }\n                buf[cnt++] = (byte) c;\n            }\n            return new String(buf, 0, cnt);\n        }\n\n        public int nextSign() throws IOException {\n            byte c = read();\n            while ('+' != c && '-' != c) {\n                c = read();\n            }\n            return '+' == c ? 0 : 1;\n        }\n\n        private static boolean isSpaceChar(int c) {\n            return !(c >= 33 && c <= 126);\n        }\n\n        public int skip() throws IOException {\n            int b;\n            // noinspection ALL\n            while ((b = read()) != -1 && isSpaceChar(b)) {\n                ;\n            }\n            return b;\n        }\n\n        public char nc() throws IOException {\n            return (char) skip();\n        }\n\n        public String next() throws IOException {\n            int b = skip();\n            final StringBuilder sb = new StringBuilder();\n            while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n                sb.appendCodePoint(b);\n                b = read();\n            }\n            return sb.toString();\n        }\n\n        public int nextInt() throws IOException {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ') {\n                c = read();\n            }\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 (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            final 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            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            final boolean neg = c == '-';\n            if (neg) {\n                c = read();\n            }\n\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n\n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n\n            if (neg) {\n                return -ret;\n            }\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            din.close();\n        }\n\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "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 << 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            DExplorerSpace solver = new DExplorerSpace();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class DExplorerSpace {\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.ri();\n            int m = in.ri();\n            int k = in.ri();\n            int[][] lr = new int[n][m - 1];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m - 1; j++) {\n                    lr[i][j] = in.ri();\n                }\n            }\n            int[][] ud = new int[n - 1][m];\n            for (int i = 0; i < n - 1; i++) {\n                for (int j = 0; j < m; j++) {\n                    ud[i][j] = in.ri();\n                }\n            }\n\n            if (k % 2 == 1) {\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        out.append(-1).append(' ');\n                    }\n                    out.println();\n                }\n                return;\n            }\n\n            k /= 2;\n            int inf = (int) 1e9;\n            int[][][] dp = new int[k + 1][n][m];\n            for (int i = 1; i <= k; i++) {\n                for (int j = 0; j < n; j++) {\n                    for (int t = 0; t < m; t++) {\n                        dp[i][j][t] = inf;\n                        //left\n                        if (t > 0) {\n                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j][t - 1] + lr[j][t - 1]);\n                        }\n                        //right\n                        if (t + 1 < m) {\n                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j][t + 1] + lr[j][t]);\n                        }\n                        //bot\n                        if (j + 1 < n) {\n                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j + 1][t] + ud[j][t]);\n                        }\n                        //top\n                        if (j > 0) {\n                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j - 1][t] + ud[j - 1][t]);\n                        }\n                    }\n                }\n            }\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    out.append(dp[k][i][j] * 2).append(' ');\n                }\n                out.println();\n            }\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() {\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    static class FastInput {\n        private final InputStream is;\n        private byte[] buf = new byte[1 << 13];\n        private int bufLen;\n        private int bufOffset;\n        private int next;\n\n        public FastInput(InputStream is) {\n            this.is = is;\n        }\n\n        private int read() {\n            while (bufLen == bufOffset) {\n                bufOffset = 0;\n                try {\n                    bufLen = is.read(buf);\n                } catch (IOException e) {\n                    bufLen = -1;\n                }\n                if (bufLen == -1) {\n                    return -1;\n                }\n            }\n            return buf[bufOffset++];\n        }\n\n        public void skipBlank() {\n            while (next >= 0 && next <= 32) {\n                next = read();\n            }\n        }\n\n        public int ri() {\n            return readInt();\n        }\n\n        public int readInt() {\n            int sign = 1;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                sign = next == '+' ? 1 : -1;\n                next = read();\n            }\n\n            int val = 0;\n            if (sign == 1) {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 + next - '0';\n                    next = read();\n                }\n            } else {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 - next + '0';\n                    next = read();\n                }\n            }\n\n            return val;\n        }\n\n    }\n}\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\npublic class temp {\n    public static void main(String str[]){\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int k = sc.nextInt();\n        int arr[][] = new int[n][m];\n        int cross[][] = new int[n][m-1];\n        int up[][] = new int[n-1][m];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m-1;j++){\n                cross[i][j] = sc.nextInt();\n            }\n        }\n        for(int i=0;i<n-1;i++){\n            for(int j=0;j<m;j++){\n                up[i][j] = sc.nextInt();\n            }\n        }\n        int[][] fans = new int[n][m];\n            if (k % 2 != 0) {\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        fans[i][j] = -1;\n                    }\n                }\n            }\n            else {\n                int[][][] ans = new int[(k/2)+1][n][m];\n                for (int l = 1; l <= k / 2; l++){\n                    for (int i = 0; i < n ; i++) {\n                        for (int j = 0; j < m; j++) {\n                            int min = Integer.MAX_VALUE;\n                            if(i>0){\n                                min = Math.min(min, up[i-1][j] + ans[l-1][i-1][j]);\n                            }\n                            if(j>0){\n                                min = Math.min(min, cross[i][j-1] + ans[l-1][i][j-1]);\n                            }\n                            if(i<n-1){\n                                min = Math.min(min, up[i][j] + ans[l-1][i+1][j]);\n                            }\n                            if(j<m-1){\n                                min = Math.min(min, cross[i][j] + ans[l-1][i][j+1]);\n                            }\n                            ans[l][i][j] = min;\n                        }\n                    }\n                }\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        fans[i][j] = 2*ans[k/2][i][j];\n                    }\n                }\n            }\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                System.out.print(fans[i][j]+\" \");\n            }\n            System.out.println();\n        }\n\n\n    }\n\n}\n\n", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.lang.*;\nimport java.util.function.Predicate;\n\npublic class Main{\n    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n    static long MOD = (long) (1e9 + 7);\n    //    static long MOD = 998244353;\n    static long MOD2 = MOD * MOD;\n    static FastReader sc = new FastReader();\n    static int pInf = Integer.MAX_VALUE;\n    static int nInf = Integer.MIN_VALUE;\n    static long ded = (long)(1e17)+9;\n    public static void main(String[] args) throws Exception {\n        int test = 1;\n//        test = sc.nextInt();\n        for (int i = 1; i <= test; i++){\n//            out.print(\"Case #\"+i+\": \");\n            solve();\n        }\n        out.flush();\n        out.close();\n    }\n    static int n,m;\n    static int[][] hor,ver;\n    static Long[][][] dp;\n    static void solve(){\n        n = sc.nextInt();\n        m = sc.nextInt();\n        int k = sc.nextInt();\n        dp = new Long[n+1][m+1][k+1];\n        hor = new int[n][m-1];\n        ver = new int[n-1][m];\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m-1; j++){\n                hor[i][j] = sc.nextInt();\n            }\n        }\n        for(int i = 0; i < n-1; i++){\n            for(int j = 0; j < m; j++){\n                ver[i][j] = sc.nextInt();\n            }\n        }\n        if(k%2==1){\n            for(int i = 0; i < n; i++){\n                for(int j = 0; j < m; j++){\n                    out.print(-1+\" \");\n                }\n                out.println();\n            }\n            return;\n        }\n        k = k/2;\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                long ans = cal(i,j,k);\n                out.print((2*ans)+\" \");\n            }\n            out.println();\n        }\n    }\n    static long cal(int i, int j,int k){\n        if(k==0)return 0;\n        if(dp[i][j][k]!=null)return dp[i][j][k];\n        long ans = ded;\n        for(int h = 0; h < 4; h++){\n            int ni = i+di[h];\n            int nj = j+dj[h];\n            if(e(ni,nj)){\n                int cost = 0;\n                if(ni==i){\n                    if(nj>j){\n                        cost = hor[i][j];\n                    }else{\n                        cost = hor[i][nj];\n                    }\n                }if(nj==j){\n                    if(ni>i){\n                        cost = ver[i][j];\n                    }else{\n                        cost = ver[ni][j];\n                    }\n                }\n                ans = Math.min(ans,(cost)+cal(ni,nj,k-1));\n            }\n        }\n        return dp[i][j][k] =  ans;\n    }\n    static int[] di = new int[]{0,-1,0,1};\n    static int[] dj = new int[]{-1,0,1,0};\n    static boolean e(int i, int j){\n        return i>=0&&j>=0&&i<n&&j<m;\n    }\n    static class Pair implements Comparable<Pair> {\n        int x;\n        int y;\n        public Pair(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n        @Override\n        public int compareTo(Pair o){\n            return this.x-o.x;\n        }\n\n        @Override\n        public String toString() {\n            return \"Pair{\" + \"x=\" + x + \", y=\" + y + '}';\n        }\n\n        public boolean equals(Pair o){\n            return this.x==o.x&&this.y==o.y;\n        }\n    }\n    public static long mul(long a, long b) {\n        return ((a % MOD) * (b % MOD)) % MOD;\n    }\n    public static long add(long a, long b) {\n        return ((a % MOD) + (b % MOD)) % MOD;\n    }\n    public static long c2(long n) {\n        if ((n & 1) == 0) {\n            return mul(n / 2, n - 1);\n        } else {\n            return mul(n, (n - 1) / 2);\n        }\n    }\n    //Shuffle Sort\n    static final Random random = new Random();\n    static void ruffleSort(int[] a) {\n        int n = a.length;//shuffle, then sort\n        for (int i = 0; i < n; i++) {\n            int oi = random.nextInt(n); int temp= a[oi];\n            a[oi] = a[i];\n            a[i] = temp;\n        }\n        Arrays.sort(a);\n    }\n    //Brian Kernighans Algorithm\n    static long countSetBits(long n) {\n        if (n == 0) return 0;\n        return 1 + countSetBits(n & (n - 1));\n    }\n    //Euclidean Algorithm\n    static long gcd(long A, long B) {\n        if (B == 0) return A;\n        return gcd(B, A % B);\n    }\n    //Modular Exponentiation\n    static long fastExpo(long x, long n) {\n        if (n == 0) return 1;\n        if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD;\n        return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD;\n    }\n    //AKS Algorithm\n    static boolean isPrime(long n) {\n        if (n <= 1) return false;\n        if (n <= 3) return true;\n        if (n % 2 == 0 || n % 3 == 0) return false;\n        for (int i = 5; i <= Math.sqrt(n); i += 6)\n            if (n % i == 0 || n % (i + 2) == 0) return false;\n        return true;\n    }\n    public static long modinv(long x) {\n        return modpow(x, MOD - 2);\n    }\n    public static long modpow(long a, long b) {\n        if (b == 0) {\n            return 1;\n        }\n        long x = modpow(a, b / 2);\n        x = (x * x) % MOD;\n        if (b % 2 == 1) {\n            return (x * a) % MOD;\n        }\n        return x;\n    }\n\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\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}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class D7182 {\n    public static void main(String[] args) throws IOException {\n        init_io();\n        int N = nint(), M = nint(), K = nint();\n        if (K % 2 == 0) {\n            int[][][] grid = new int[K+1][N][M];\n            int[][][] edges = new int[4][N][M];\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < M-1; j++) {\n                    edges[0][i][j] = edges[2][i][j+1] = nint();\n                }\n            }\n            for (int i = 0; i < N-1; i++) {\n                for (int j = 0; j < M; j++) {\n                    edges[1][i][j] = edges[3][i+1][j] = nint();\n                }\n            }\n            for (int k = 1; k <= K/2; k++) {\n                for (int i = 0; i < N; i++) {\n                    for (int j = 0; j < M; j++) {\n                        int min = Integer.MAX_VALUE;\n                        if (i != N-1) {\n                            min = Math.min(min, grid[k-1][i+1][j] + edges[1][i][j]);\n                        }\n                        if (j != M-1) {\n                            min = Math.min(min, grid[k-1][i][j+1] + edges[0][i][j]);\n                        }\n                        if (i != 0) {\n                            min = Math.min(min, grid[k-1][i-1][j] + edges[3][i][j]);\n                        }\n                        if (j != 0) {\n                            min = Math.min(min, grid[k-1][i][j-1] + edges[2][i][j]);\n                        }\n                        grid[k][i][j] = min;\n                    }\n                }\n            }\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < M; j++) {\n                    out.print(grid[K/2][i][j]*2 + \" \");\n                }\n                out.println();\n            }\n        }\n        else {\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < M; j++) {\n                    out.print(-1 + \" \");\n                }\n                out.println();\n            }\n        }\n        out.close();\n    }\n\n    static StreamTokenizer in;\n    static PrintWriter out;\n    static BufferedReader br;\n\n    static int nint() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    static void init_io() throws IOException {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        in = new StreamTokenizer(br);\n        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    }\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "/* 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 Main\n{\n    public static int n;\n    public static int m;\n    public static int k;\n    public static int[][] right;\n    public static int[][] down;\n    public static int[][][] dp;\n    public static void recur(int i, int j, int depth)\n    {\n        if(dp[i][j][depth]!=-1)\n            return;\n        int min=Integer.MAX_VALUE;\n        // left\n        if(j>0)\n        {\n            recur(i, j-1, depth-1);\n            min=Math.min(min, dp[i][j-1][depth-1] + right[i][j-1]);\n        }\n        // right\n        if(j<m-1)\n        {\n            recur(i, j+1, depth-1);\n            min=Math.min(min, dp[i][j+1][depth-1] + right[i][j]);\n        }\n        // up\n        if(i>0)\n        {\n            recur(i-1, j, depth-1);\n            min=Math.min(min, dp[i-1][j][depth-1] + down[i-1][j]);\n        }\n        // down\n        if(i<n-1)\n        {\n            recur(i+1, j, depth-1);\n            min=Math.min(min, dp[i+1][j][depth-1] + down[i][j]);\n\n        }\n        dp[i][j][depth]=min;\n    }\n    public static void main (String[] args) throws java.lang.Exception\n    {\n        // your code goes here\n        Scanner sc=new Scanner(System.in);\n        n=sc.nextInt();\n        m=sc.nextInt();\n        k=sc.nextInt();\n        right=new int[n][m-1];\n        down=new int[n-1][m];\n        for(int i=0;i<n;i++)\n            for(int j=0;j<m-1;j++)\n                right[i][j]=sc.nextInt();\n        for(int i=0;i<n-1;i++)\n            for(int j=0;j<m;j++)\n                down[i][j]=sc.nextInt();\n        if(k%2==1) {\n            for(int i=0;i<n;++i) {\n                for (int j = 0; j < m; j++)\n                    System.out.print(-1 + \" \");\n                System.out.println();\n            }\n        }\n        else\n        {\n            k/=2;\n            dp=new int[n][m][k+1];\n            for(int i=0;i<n;++i)\n                for(int j=0;j<m;j++)\n                    for(int z=1;z<=k;z++)\n                        dp[i][j][z]=-1;\n            for(int i=0;i<n;++i)\n                for(int j=0;j<m;j++)\n                    recur(i,j,k);\n            for(int i=0;i<n;++i) {\n                for (int j = 0; j < m; j++)\n                    System.out.print((dp[i][j][k] * 2) + \" \");\n                System.out.println();\n            }\n        }\n    }\n\n}", "complexity": "cubic", "problem": "1517_D. Explorer Space", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.stream.Collectors;\n\npublic class Main {\n  public static void main(String[] args) {\n    Scanner sc = new Scanner(System.in);\n\n    int t = sc.nextInt();\n    for (int tc = 0; tc < t; ++tc) {\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      }\n\n      System.out.println(solve(a));\n    }\n\n    sc.close();\n  }\n\n  static String solve(int[] a) {\n    List<String> result = new ArrayList<>();\n    Stack<Integer> stack = new Stack<>();\n    for (int ai : a) {\n      if (ai != 1) {\n        while (stack.peek() + 1 != ai) {\n          stack.pop();\n        }\n\n        stack.pop();\n      }\n      stack.push(ai);\n\n      result.add(stack.stream().map(String::valueOf).collect(Collectors.joining(\".\")));\n    }\n\n    return String.join(\"\\n\", result);\n  }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "//I'm Whiplash99\nimport java.io.*;\nimport java.util.*;\npublic class C\n{\n    public static void main(String[] args) throws Exception\n    {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n        int i,N;\n\n        int T=Integer.parseInt(br.readLine().trim());\n        StringBuilder sb=new StringBuilder();\n\n        while (T-->0)\n        {\n            N=Integer.parseInt(br.readLine().trim());\n\n            int[] a=new int[N];\n            for(i=0;i<N;i++) a[i]=Integer.parseInt(br.readLine().trim());\n\n            int end=1;\n            int[][] ans=new int[N][N+10];\n\n            ans[0][0]=1;\n            for(i=1;i<N;i++)\n            {\n                while (true)\n                {\n                    if(ans[i-1][end]==a[i]-1) break;\n                    end--;\n                }\n                for(int j=0;j<end;j++) ans[i][j]=ans[i-1][j];\n\n                ans[i][end]=a[i];\n                end++;\n            }\n\n            for(i=0;i<N;i++)\n            {\n                for(int j=0;j<N&&ans[i][j]!=0;j++)\n                {\n                    sb.append(ans[i][j]);\n                    if(ans[i][j+1]!=0) sb.append('.');\n                }\n                sb.append(\"\\n\");\n            }\n        }\n        System.out.println(sb);\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class C {\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 double nextDouble() {\n        return Double.parseDouble(nextToken());\n    }\n\n    static String nextLine() {\n        try {\n            return br.readLine();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n        return null;\n    }\n\n    public static void main(String[] args) {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n        solve();\n        pw.close();\n    }\n\n    private static void solve() {\n        int t = nextInt();\n        int[] stack = new int[1000000];\n        for (int i = 0; i < t; i++) {\n            int n = nextInt();\n            stack[0] = nextInt();\n            int id = 1;\n            pp(stack, id);\n            for (int j = 1; j < n; j++) {\n                int x = nextInt();\n                if (x == 1) {\n                    stack[id++] = x;\n                } else {\n                    while (true) {\n                        int p = stack[--id];\n                        if (p + 1 == x) {\n                            stack[id++] = x;\n                            break;\n                        }\n                    }\n                }\n                pp(stack, id);\n            }\n        }\n    }\n\n    private static void pp(int[] stack, int size) {\n        for (int i = 0; i < size - 1; i++) {\n            pw.print(stack[i] + \".\");\n        }\n        pw.println(stack[size - 1]);\n    }\n\n\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "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) 1e18 + 10;\n    static final int MOD = (int) 1e9 + 7;\n\n\n    static void solve() {\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        Stack<Integer> st = new Stack<>();\n        for (int i = 0; i < n; i++) {\n            if (a[i] != 1) {\n                while (!st.empty() && st.peek() + 1 != a[i])\n                    st.pop();\n                st.pop();\n            }\n            st.push(a[i]);\n            for (int j = 0; j < st.size(); j++) {\n                out.print(st.get(j));\n                if (j < st.size() - 1)\n                    out.print('.');\n            }\n            out.println();\n        }\n\n    }\n\n    public static void main(String[] args) {\n        in = new FastReader();\n        out = new PrintWriter(System.out);\n\n        int t = 1;\n        t = in.nextInt();\n        while (t-- > 0) {\n            solve();\n        }\n\n        out.flush();\n        out.close();\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}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\nimport java.lang.*;\n\npublic class Practice {\n\tpublic static long mod = (long) Math.pow(10, 9) + 7;\n\tpublic static long tt = 0;\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint c = 1;\n\t\tint t = Integer.parseInt(br.readLine());\n\n\t\twhile (t-- > 0) {\n\t\t\tint n = Integer.parseInt(br.readLine());\n\t\t\tHashMap<Integer, Integer> map = new HashMap<>();\n\t\t\t// map.put(1, 0);\n\t\t\tint curr = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint tt = Integer.parseInt(br.readLine());\n\t\t\t\tif (tt == 1) {\n\t\t\t\t\tcurr++;\n\t\t\t\t\tmap.put(curr, 1);\n\t\t\t\t} else {\n\t\t\t\t\tArrayList<Integer> list = new ArrayList<Integer>(map.keySet());\n\t\t\t\t\tCollections.sort(list);\n\t\t\t\t\tfor (int a = list.size() - 1; a >= 0; a--) {\n\t\t\t\t\t\tif (map.get(list.get(a)) == tt - 1) {\n\t\t\t\t\t\t\tmap.put(list.get(a), tt);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcurr--;\n\t\t\t\t\t\t\tmap.remove(list.get(a));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tArrayList<Integer> list = new ArrayList<Integer>(map.keySet());\n\t\t\t\tCollections.sort(list);\n\t\t\t\tStringBuilder str=new StringBuilder();\n\t\t\t\tfor(int a=0;a<list.size();a++) {\n\t\t\t\t\tif(list.size()-1==a) {\n\t\t\t\t\t\tstr.append(map.get(list.get(a)));\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tstr.append(map.get(list.get(a))+\".\");\n\t\t\t\t}pw.println(str);\n\n\t\t\t}\n\n\t\t}\n\t\tpw.close();\n\t}\n\n//\tprivate static long getGCD(long l, long m) {\n//\t\t// TODO Auto-generated method stub\n//\n//\t\tlong t1 = Math.min(l, m);\n//\t\tlong t2 = Math.max(l, m);\n//\t\twhile (true) {\n//\t\t\tlong temp = t2 % t1;\n//\t\t\tif (temp == 0) {\n//\t\t\t\treturn t1;\n//\t\t\t}\n//\t\t\tt2 = t1;\n//\t\t\tt1 = temp;\n//\t\t}\n//\t}\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Main {\n    public static void main(String args[])\n    {\n        FastReader input=new FastReader();\n        PrintWriter out=new PrintWriter(System.out);\n        int T=input.nextInt();\n        while(T-->0)\n        {\n            int n=input.nextInt();\n            int b[]=new int[n];\n            for(int i=0;i<n;i++)\n            {\n                b[i]=input.nextInt();\n            }\n            StringBuilder sb=new StringBuilder(\"\");\n            int arr[]=new int[n+1];\n            out.println('1');\n            sb.append('1');\n            int size=1;\n            arr[size-1]=1;\n            for(int i=1;i<n;i++)\n            {\n                int a=b[i];\n                if(a==1)\n                {\n                    size++;\n                    arr[size-1]=1;\n                    sb.append(\".1\");\n                    out.println(sb.toString());\n                }\n                else\n                {\n                    sb=new StringBuilder(\"\");\n                    int in=0;\n                    for(int j=size-1;j>=0;j--)\n                    {\n                        if(arr[j]==a-1)\n                        {\n                            in=j;\n                            break;\n                        }\n                    }\n                    for(int j=0;j<in;j++)\n                    {\n                        sb.append(arr[j]+\".\");\n                    }\n                    sb.append(a);\n                    size=in+1;\n                    arr[size-1]=a;\n                    out.println(sb.toString());\n                }\n            }\n        }\n        out.close();\n    }\n    static class FastReader\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastReader()\n        {\n            br = new BufferedReader(new 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        int nextInt()\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong()\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble()\n        {\n            return Double.parseDouble(next());\n        }\n        String nextLine()\n        {\n            String str=\"\";\n            try\n            {\n                str=br.readLine();\n            }\n            catch (IOException e)\n            {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport 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        solve(in, out);\n        out.close();\n    }\n\n    static String reverse(String s) {\n        return (new StringBuilder(s)).reverse().toString();\n    }\n\n    static void sieveOfEratosthenes(int n, int factors[], ArrayList<Integer> ar) \n    { \n        factors[1]=1;\n        int p;\n        for(p = 2; p*p <=n; p++) \n        { \n            if(factors[p] == 0) \n            { \n                ar.add(p);\n                factors[p]=p;\n                for(int i = p*p; i <= n; i += p) \n                    factors[i] = p; \n            } \n        } \n        for(;p<=n;p++){\n            if(factors[p] == 0) \n            { \n                ar.add(p);\n            } \n        }\n    }\n\n    static void sort(int ar[]) {\n        int n = ar.length;\n        ArrayList<Integer> a = new ArrayList<>();\n        for (int i = 0; i < n; i++)\n            a.add(ar[i]);\n        Collections.sort(a);\n        for (int i = 0; i < n; i++)\n            ar[i] = a.get(i);\n    }\n\n    static void sort1(long ar[]) {\n        int n = ar.length;\n        ArrayList<Long> a = new ArrayList<>();\n        for (int i = 0; i < n; i++)\n            a.add(ar[i]);\n        Collections.sort(a);\n        for (int i = 0; i < n; i++)\n            ar[i] = a.get(i);\n    }\n\n    static long ncr(long n, long r, long mod) {\n        if (r == 0)\n            return 1;\n        long val = ncr(n - 1, r - 1, mod);\n        val = (n * val) % mod;\n        val = (val * modInverse(r, mod)) % mod;\n        return val;\n    }\n\n    static int findMax(int a[], int n, int vis[], int i, int d){\n        if(i>=n)\n            return 0;\n        if(vis[i]==1)\n            return findMax(a, n, vis, i+1, d);\n        int max = 0;\n        for(int j=i+1;j<n;j++){\n            if(Math.abs(a[i]-a[j])>d||vis[j]==1)\n                continue;\n            vis[j] = 1;\n            max = Math.max(max, 1 + findMax(a, n, vis, i+1, d));\n            vis[j] = 0;\n        }\n        return max;\n    }\n\n    public static void solve(InputReader sc, PrintWriter pw){\n        int i, j = 0;\n        // int t = 1; \n        int t = sc.nextInt();\n        u: while (t-- > 0) {\n            int n = sc.nextInt();\n            int a[] = new int[n];\n            ArrayList<Integer> ar = new ArrayList<>();\n            ar.add(0);\n            for(i=0;i<1000;i++){\n                ar.add(0);\n            }\n            int m = 1;\n            for(i=0;i<n;i++){\n                a[i] = sc.nextInt();\n                if(a[i]==1){\n                    ar.set(m,1);\n                    m++;\n                }\n                else{\n                    while(m>0&&ar.get(m-1)!=a[i]-1){\n                        m--;\n                    }\n                    ar.set(m-1,a[i]);\n                }\n                pw.print(ar.get(1));\n                for(j=2;j<m;j++){\n                    pw.print(\".\"+ar.get(j));\n                }\n                pw.println();\n            }\n        }\n    }\n\n    static long findOne(int n, int sz[], ArrayList<Integer> ar){\n        long paths = n-1;\n        long till = 0;\n        for(int v:ar){\n            paths += till*sz[v];\n            till += sz[v];\n        }\n        return paths;\n    }\n\n    static void assignAnc(ArrayList<Integer> ar[],int sz[], int pa[] ,int curr, int par){\n        sz[curr] = 1;\n        pa[curr] = par;\n        for(int v:ar[curr]){\n            if(par==v)\n                continue;\n            assignAnc(ar, sz, pa, v, curr);\n            sz[curr] += sz[v];\n        }\n    }\n\n    static int findLCA(int a, int b, int par[][], int depth[]){\n        if(depth[a]>depth[b]){\n            a = a^b;\n            b = a^b;\n            a = a^b;\n        }\n        int diff = depth[b] - depth[a];\n        for(int i=19;i>=0;i--){\n            if((diff&(1<<i))>0){\n                b = par[b][i];\n            }\n        }\n        if(a==b)\n            return a;\n        for(int i=19;i>=0;i--){\n            if(par[b][i]!=par[a][i]){\n                b = par[b][i];\n                a = par[a][i];\n            }\n        }\n        return par[a][0];\n    }\n\n    static void formArrayForBinaryLifting(int n, int par[][]){\n        for(int j=1;j<20;j++){\n            for(int i=0;i<n;i++){\n                if(par[i][j-1]==-1)\n                    continue;\n                par[i][j] = par[par[i][j-1]][j-1];\n            }\n        }\n    }\n\n    static long lcm(int a, int b){\n        return a*b/gcd(a,b);\n    }\n\n    static class Pair1 {\n        long a;\n        long b;\n        \n        Pair1(long a, long b) {\n            this.a = a;\n            this.b = b;\n        }\n    }\n\n    static class Pair implements Comparable<Pair> {\n        int a;\n        int b;\n        int c;\n        \n        Pair(int a, int b, int c) {\n            this.a = a;\n            this.b = b;\n            this.c = c;\n        }\n \n        public int compareTo(Pair p) {\n            // if(a!=p.a)\n            //     return a-p.a;\n            // return b-p.b;\n            return p.c - c;\n        }\n    }\n\n    // static boolean isPrime(long n) {\n    //     if (n <= 1)\n    //         return false;\n    //     if (n <= 999)\n    //         return true;\n    //     if (n % 2 == 0 || n % 999 == 0)\n    //         return false;\n    //     for (int i = 5; i * i <= n; i = i + 6)\n    //         if (n % i == 0 || n % (i + 2) == 0)\n    //             return false;\n    //     return true;\n    // }\n\n    static long gcd(long a, long b) {\n        if (b == 0)\n            return a;\n        return gcd(b, a % b);\n    }\n\n    static long fast_pow(long base, long n, long M) {\n        if (n == 0)\n            return 1;\n        if (n == 1)\n            return base % M;\n        long halfn = fast_pow(base, n / 2, M);\n        if (n % 2 == 0)\n            return (halfn * halfn) % M;\n        else\n            return (((halfn * halfn) % M) * base) % M;\n    }\n\n    static long modInverse(long n, long M) {\n        return fast_pow(n, M - 2, M);\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), 9992768);\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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int tests = in.nextInt();\n\n            for (int t = 0; t < tests; t++) {\n                int numLines = in.nextInt();\n                // greedy, maintain stack, keep stack as big as possible\n                int stackIdx = -1;\n                int[] stack = new int[10000];\n                String prev = \"\";\n                for (int x = 0; x < numLines; x++) {\n                    int depth = 0;\n                    int next = in.nextInt();\n                    boolean found = false;\n                    for (int i = stackIdx; i >= 0; i--) {\n                        if (next == stack[i] + 1) {\n                            depth = i;\n                            found = true;\n                            break;\n                        }\n                    }\n                    if (found == true) {\n                        stackIdx = depth;\n                        stack[depth] = next;\n                        for (int i = 0; i <= depth; i++) {\n                            if (i != 0) {\n                                out.print(\".\");\n                            }\n                            out.print(stack[i]);\n                        }\n                        out.println();\n\n                    } else if (next == 1) {\n                        stackIdx++;\n                        stack[stackIdx] = 1;\n                        for (int i = 0; i <= stackIdx; i++) {\n                            if (i != 0) {\n                                out.print(\".\");\n                            }\n                            out.print(stack[i]);\n                        }\n                        out.println();\n\n                    } else {\n                        // start a new one\n                        stackIdx = 0;\n                        stack[0] = next;\n                        out.println(next);\n                    }\n\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 println() {\n            writer.println();\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n        public void print(int i) {\n            writer.print(i);\n        }\n\n        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", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\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    static FastReader s = new FastReader();\n    static PrintWriter out = new PrintWriter(System.out);\n\n    private static int[] rai(int n) {\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextInt();\n        }\n        return arr;\n    }\n\n    private static int[][] rai(int n, int m) {\n        int[][] arr = new int[n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                arr[i][j] = s.nextInt();\n            }\n        }\n        return arr;\n    }\n\n    private static long[] ral(int n) {\n        long[] arr = new long[n];\n        for (int i = 0; i < n; i++) {\n            arr[i] = s.nextLong();\n        }\n        return arr;\n    }\n\n    private static long[][] ral(int n, int m) {\n        long[][] arr = new long[n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                arr[i][j] = s.nextLong();\n            }\n        }\n        return arr;\n    }\n\n    private static int ri() {\n        return s.nextInt();\n    }\n\n    private static long rl() {\n        return s.nextLong();\n    }\n\n    private static String rs() {\n        return s.next();\n    }\n\n    static long gcd(long a,long b)\n    {\n        if(b==0)\n        {\n            return a;\n        }\n        return gcd(b,a%b);\n    }\n\n    static int gcd(int a,int b)\n    {\n        if(b==0)\n        {\n            return a;\n        }\n        return gcd(b,a%b);\n    }\n\n    static boolean isPrime(int n) {\n        //check if n is a multiple of 2\n        if (n % 2 == 0) return false;\n        //if not, then just check the odds\n        for (int i = 3; i <= Math.sqrt(n); i += 2) {\n            if (n % i == 0)\n                return false;\n        }\n        return true;\n    }\n    static int MOD=1000000007;\n\n    static long mpow(long base,long pow)\n    {\n        long res=1;\n        while(pow>0)\n        {\n            if(pow%2==1)\n            {\n                res=(res*base)%MOD;\n            }\n            pow>>=1;\n            base=(base*base)%MOD;\n        }\n        return res;\n    }\n\n    public static void main(String[] args) {\n        StringBuilder ans = new StringBuilder();\n        int t = ri();\n//        int t = 1;\n        while (t-- > 0)\n        {\n            int n=ri();\n            int[] arr=rai(n);\n\n            List<Integer> list = new ArrayList<>();\n            for(int i:arr)\n            {\n                if(i==1)\n                {\n                    list.add(i);\n                }\n                else\n                {\n                    int ind = list.size()-1;\n                    while(list.size()>0 && list.get(ind)+1!=i )\n                    {\n                        list.remove(list.size()-1);\n                        ind=list.size()-1;\n                    }\n                    if(list.size()>0)\n                    {\n                        list.remove(list.size()-1);\n                    }\n                    list.add(i);\n                }\n\n                for(int j=0;j<list.size()-1;j++)\n                {\n                    ans.append(list.get(j)).append(\".\");\n                }\n                ans.append(list.get(list.size()-1)).append(\"\\n\");\n            }\n        }\n        out.print(ans.toString());\n        out.flush();\n    }\n\n\n\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C1523 {\n\tpublic static void print(Stack<Integer> st, PrintWriter pw) {\n\t\tfor (int i = 0; i < st.size(); i++) {\n\t\t\tpw.print(st.get(i));\n\t\t\tif (i != st.size() - 1) {\n\t\t\t\tpw.print(\".\");\n\t\t\t}\n\t\t}\n\t\tpw.println();\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\tint t = sc.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint[] arr = sc.nextIntArr(n);\n\t\t\tStack<Integer> st = new Stack<Integer>();\n\t\t\tst.add(arr[0]);\n\t\t\tprint(st, pw);\n\t\t\tfor (int i = 1; i < n; i++) {\n\t\t\t\tif (arr[i] == 1) {\n\t\t\t\t\tst.add(arr[i]);\n\t\t\t\t} else {\n\t\t\t\t\twhile (st.peek() != arr[i] - 1) {\n\t\t\t\t\t\tst.pop();\n\t\t\t\t\t}\n\t\t\t\t\tst.pop();\n\t\t\t\t\tst.add(arr[i]);\n\t\t\t\t}\n\t\t\t\tprint(st, pw);\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\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 f) {\n\t\t\tbr = new BufferedReader(f);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic int[] nextIntArr(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] = Integer.parseInt(next());\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t}\n\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "/* 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\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint t = Integer.parseInt(br.readLine());\n\t\tfor(int q=0;q<t;q++){\n\t\t      String s = br.readLine();\n\t\t      int n = Integer.parseInt(s);\n\t\t      int a[] = new int[1000];\n\t\t      int index=0;\n\t\t      for(int i=0;i<n;i++){\n\t\t            int x = Integer.parseInt(br.readLine());\n\t\t            for(int j=index;j>=0;j--){\n\t\t                  if(x-1==a[j]){\n\t\t                        a[j]=x;\n\t\t                  \n\t\t                  for(int k=0;k<j;k++){\n\t\t                        System.out.print(a[k]+\".\");\n\t\t                  }\n\t\t                  System.out.print(a[j]);\n\t\t                  System.out.println();\n\t\t                  for(int k=j+1;k<1000;k++){\n\t\t                        if(a[k]!=0)\n\t\t                        a[k]=0;\n\t\t                        else \n\t\t                        break;\n\t\t                  }\n\t\t                  index=j+1;\n\t\t                //  System.out.println(a[j]+\"*\"+j);\n\t\t                  break;\n\t\t                  }\n\t\t            }\n\t\t      }\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\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: 19:12:30 30/05/2021\n    Custom Competitive programming helper.\n*/\n\npublic class Main {\n\tpublic static void solve() {\n\t\tint n = in.nextInt();\n\t\tArrayList<Integer> ans = new ArrayList<>();\n\t\tout.println(in.nextInt());\n\t\tans.add(1);\n\t\tfor(int i = 0; i<n-1; i++) {\n\t\t\tint cur = in.nextInt();\n\t\t\tif(ans.isEmpty() || cur==1) ans.add(cur);\n\t\t\telse {\n\t\t\t\twhile((!ans.isEmpty()) && (ans.get(ans.size()-1)+1!=cur)) ans.remove(ans.size()-1);\n\t\t\t\tif(!ans.isEmpty()) ans.remove(ans.size()-1);\n\t\t\t\tans.add(cur);\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tfor(int j : ans) {\n\t\t\t\tcnt++;\n\t\t\t\tout.print(j+(cnt==ans.size()?\"\":\".\"));\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n\tstatic boolean equal(ArrayList<Integer> a, ArrayList<Integer> b) {\n\t\tif(a.size()!=b.size()) return false;\n\t\tfor(int i = 0; i<a.size(); i++) if(a.get(i)!=b.get(i)) return false;\n\t\treturn true;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tin = new Reader();\n\t\tout = new Writer();\n\t\tint t = in.nextInt();\n\t\twhile(t-->0) solve();\n\t\tout.exit();\n\t}\n\tstatic Reader in; static Writer out;\n\nstatic class Reader {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\t\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++) a[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++) a[i] = nextDouble();\n\t\treturn a;\n\t}\n\t\n\tpublic long[] nl(int n) {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++) a[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++) a[i] = next();\n\t\treturn a;\n\t}\n\n\tpublic int nextInt() {\n\t\tensureNext();\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\n\tpublic double nextDouble() {\n\t\tensureNext();\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\n\tpublic Long nextLong() {\n\t\tensureNext();\n\t\treturn Long.parseLong(st.nextToken());\n\t}\n\n\tpublic String next() {\n\t\tensureNext();\n\t\treturn st.nextToken();\n\t}\n\t\n\tpublic String nextLine() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\treturn null;\n\t\t}\n\t}\n\t\n\tprivate void ensureNext() {\n\t\tif (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\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t}\n}\n\nstatic class Util{\n\t\tprivate static Random random = new Random();\n\t\tstatic long[] fact;\n\t\t\n\t\tpublic static void initFactorial(int n, long mod) {\n\t\t\tfact = new long[n+1];\n\t\t\tfact[0] = 1;\n\t\t\tfor (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod;\n\t\t}\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\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\t\n\t\tpublic static long nCr(int n, int r, long MOD) {\n\t\t\tif (r == 0) return 1;\n\t\t\treturn (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD;\n\t\t}\n\t\t\n\t\tpublic static long nCr(int n, int r) {\n\t\t\treturn (fact[n]/fact[r])/fact[n-r];\n\t\t}\n\t\t\n\t\tpublic static long nPr(int n, int r, long MOD) {\n\t\t\tif (r == 0) return 1;\n\t\t\treturn (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD;\n\t\t}\n\t\tpublic static long nPr(int n, int r) {\n\t\t\treturn fact[n]/fact[n-r];\n\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\t\n\t    public static boolean[] getSieve(int n) {\n\t        boolean[] isPrime = new boolean[n+1];\n\t        for (int i = 2; i <= n; i++) isPrime[i] = true;\n\t        for (int i = 2; i*i <= n; i++) if (isPrime[i]) \n\t                for (int j = i; i*j <= n; j++) isPrime[i*j] = false;\n\t        return isPrime;\n\t    }\n\t    \n\t    public static int gcd(int a, int b) { \n\t    \tint tmp = 0;\n\t    \twhile(b != 0) {\n\t    \t\ttmp = b;\n\t    \t\tb = a%b;\n\t    \t\ta = tmp;\n\t    \t}\n\t    \treturn a;\n\t    }\n\t    \n\t    public static long gcd(long a, long b) { \n\t    \tlong tmp = 0;\n\t    \twhile(b != 0) {\n\t    \t\ttmp = b;\n\t    \t\tb = a%b;\n\t    \t\ta = tmp;\n\t    \t}\n\t    \treturn a;\n\t    }\n\t    \n\t    public static int random(int min, int max) {\n\t    \treturn random.nextInt(max-min+1)+min;\n\t    }\n\t    \n\t\tpublic static void dbg(Object... o) { \n\t\t\tSystem.out.println(Arrays.deepToString(o)); \n\t\t}\n\t\t\n\t\tpublic static void reverse(int[] s, int l , int r) {\n\t\t\tfor(int i = l; i<=(l+r)/2; i++) {\n\t\t\t\tint 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\t\n\t\tpublic static void reverse(int[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t    }\n\t\t\n\t\tpublic static void reverse(long[] s, int l , int r) {\n\t\t\tfor(int i = l; i<=(l+r)/2; i++) {\n\t\t\t\tlong 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\t\n\t\tpublic static void reverse(long[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t    }\n\t\t\n\t\tpublic static void reverse(float[] s, int l , int r) {\n\t\t\tfor(int i = l; i<=(l+r)/2; i++) {\n\t\t\t\tfloat 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\t\n\t\tpublic static void reverse(float[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t    }\n\t\t\n\t\tpublic static void reverse(double[] s, int l , int r) {\n\t\t\tfor(int i = l; i<=(l+r)/2; i++) {\n\t\t\t\tdouble 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\t\n\t\tpublic static void reverse(double[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t    }\n\t\t\n\t\tpublic static void reverse(char[] s, int l , int r) {\n\t\t\tfor(int i = l; i<=(l+r)/2; i++) {\n\t\t\t\tchar 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\t\n\t\tpublic static void reverse(char[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t    }\n\t\t\n\t\tpublic static <T> 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\t\n\t\tpublic static <T> void reverse(T[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t    }\n\t\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\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    \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    \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    \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    \n\t    public static <T> 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    \n\t\tpublic static void sortArray(int[] a) {\n\t        shuffle(a);\n\t        Arrays.sort(a);\n\t    }\n\t\t\n\t\tpublic static void sortArray(long[] a) {\n\t\t\tshuffle(a);\n\t        Arrays.sort(a);\n\t    }\n\t\t\n\t\tpublic static void sortArray(float[] a) {\n\t\t\tshuffle(a);\n\t        Arrays.sort(a);\n\t    }\n\t\t\n\t\tpublic static void sortArray(double[] a) {\n\t\t\tshuffle(a);\n\t        Arrays.sort(a);\n\t    }\n\t\t\n\t\tpublic static void sortArray(char[] a) {\n\t\t\tshuffle(a);\n\t        Arrays.sort(a);\n\t    }\n\t\t\n\t\tpublic static <T extends Comparable<T>> 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; i<a.length; i++) print(a[i]+\" \");\n\t}\n\t\n\tpublic void printlnArray(int[] a) {\n\t\tfor(int i = 0; i<a.length; i++) print(a[i]+\" \");\n\t\tpw.println();\n\t}\n\t\n\tpublic void printArray(long[] a) {\n\t\tfor(int i = 0; i<a.length; i++) print(a[i]+\" \");\n\t}\n\t\n\tpublic void printlnArray(long[] a) {\n\t\tfor(int i = 0; i<a.length; i++) print(a[i]+\" \");\n\t\tpw.println();\n\t}\n\t\n\tpublic void print(Object o) {\n\t\tpw.print(o.toString());\n\t}\n\t\n\tpublic void println(Object o) {\n\t\tpw.println(o.toString());\n\t}\n\t\n\tpublic void println() {\n\t\tpw.println();\n\t}\n\t\n\tpublic void flush() {\n\t\tpw.flush();\n\t}\n\tpublic void exit() {\n\t\tpw.close();\n\t}\n}\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic int ar[];\n\tstatic HashMap<String, ArrayList<String>> map;\n\tstatic int location = 0;\n\tstatic StringBuilder sb;\n\tstatic int N;\n\t\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t// TODO Auto-generated method stub\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tint t = Integer.parseInt(br.readLine());\n\t\t\n\t\twhile(t --> 0) {\n\t\t\t\n\t\t\tint n = Integer.parseInt(br.readLine());\n\t\t\tar = new int[n];\n\t\t\tlocation = 0;\n\t\t\tmap = new HashMap<String, ArrayList<String>>();\n\t\t\tsb = new StringBuilder();\n\t\t\tN = n;\n\t\t\t\t\t\t\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\n\t\t\t\tar[i] = Integer.parseInt(br.readLine());\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tint idx = 2;\n\t\t\tlocation = 1;\n\t\t\t\n\t\t\tsb.append(\"1\\n\");\n\t\t\t\n\t\t\twhile(location < n) {\n\t\t\t\t\n\t\t\t\tif(ar[location] == 1) {\n\t\t\t\t\t\n\t\t\t\t\tnl((idx-1)+\".\");\n\t\t\t\t\t\n\t\t\t\t}else {\n\t\t\t\t\t\n\t\t\t\t\tsb.append(idx+\"\\n\");\n\t\t\t\t\tidx++;\n\t\t\t\t\tlocation++;\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\tSystem.out.println(sb);\n\t\t\t\n\t\t}\t\n\t\t\n\t}\n\t\n\tpublic static void nl(String l) {\n\t\t\n\t\tint idx = 1;\n\t\t//System.out.println(location + \" \" + l);\n\t\t\n\t\twhile(location < N) {\n\t\t\t\t\t\t\n\t\t\tif(idx == ar[location]) {\n\t\t\t\t\n\t\t\t\tsb.append(l + idx + \"\\n\");\n\t\t\t\tidx++;\n\t\t\t\tlocation++;\n\t\t\t\t\n\t\t\t}else if(ar[location] == 1) {\n\t\t\t\t\n\t\t\t\tnl(l + (idx-1) + \".\");\n\t\t\t\t\n\t\t\t}else {\n\t\t\t\t\n\t\t\t\treturn;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class CF_1523_C{\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\n//        Stack<Integer> stack = new Stack<>();\n        int[] stack = new int[2*N];\n        int sz = 0;\n        for(int i = 0; i< N; i++){\n            if(A[i] == 1)stack[sz++] = 1;\n            else{\n                while (sz > 0 && stack[sz-1]+1 != A[i])sz--;//!stack.isEmpty() && stack.peek()+1 != A[i])stack.pop();\n                hold(sz != 0);\n                stack[sz-1]++;\n                hold(stack[sz-1] == A[i]);\n            }\n            hold(sz != 0);\n            StringBuilder st = new StringBuilder();\n            for(int s = 0; s< sz; s++){\n                st.append(stack[s]);\n                if(s+1 < sz)st.append(\".\");\n            }\n            pn(st.toString());\n        }\n    }\n    //SOLUTION END\n    void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n    void exit(boolean b){if(!b)System.exit(0);}\n    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 = true, 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_1523_C().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, \"1\", 1 << 28).start();\n        else new CF_1523_C().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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces\n{\n    public static void main(String args[])throws Exception\n    {\n        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder sb=new StringBuilder();\n        int t=Integer.parseInt(bu.readLine());\n        while(t-->0)\n        {\n            int n=Integer.parseInt(bu.readLine());\n            int cur[]=new int[n],i,cr=-1;\n            for(i=0;i<n;i++)\n            {\n                int j,d=Integer.parseInt(bu.readLine()),f=-1;\n                for(j=cr;j>=0;j--)\n                if(cur[j]==d-1) {f=j; break;}\n\n                if(f==-1)\n                {\n                    cr++;\n                    f=cr;\n                }\n                cur[f]=d;\n                cr=f;\n                for(j=f+1;j<n;j++) cur[j]=0;\n                sb.append(cur[0]);\n                for(j=1;j<n;j++)\n                if(cur[j]==0) break;\n                else sb.append(\".\"+cur[j]);\n                sb.append(\"\\n\");\n            }\n        }\n        System.out.print(sb);\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "/*\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 wilso\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\npublic class codeforces {\n    static final long MOD2 = 998_244_353;\n    public static void main(String[] args) {\n        FastScanner sc = new FastScanner();\n        PrintWriter pw = new PrintWriter(System.out);\n       \n        int tc = sc.ni();\n//        int tc = 1;\n        for (int rep = 0; rep < tc; rep++) {\n            int N = sc.ni();\n            int[] arr = sc.intArray(N);\n            pw.println(solve(arr));\n        }\n        \n        pw.close();\n    }\n \n    \n    static String solve(int[] arr) {\n        StringBuilder sb = new StringBuilder();\n        List<Integer> list = new ArrayList();\n        list.add(0);\n        for (int i = 0; i < arr.length; i++) {\n            int x = arr[i];\n            for (int j = list.size() - 1; j >= 0; j--) {\n                if (x - 1 == list.get(j)) {\n                    list.set(j, x);\n                    while (list.size() > j+1) {\n                        list.remove(list.size() - 1);\n                    }\n                    list.add(0);\n                    \n                    //append\n                    for (int idx = 0; idx < list.size() - 1; idx++) {\n                        sb.append(list.get(idx) + \".\");\n                    }\n                    sb.setLength(sb.length() - 1);\n                    sb.append(\"\\n\");\n                    break;\n                }\n            }\n        }\n        sb.setLength(sb.length() - 1);\n        return sb.toString();\n    }\n   \n    static int summation(int x) {\n        return x * (x+1) / 2;\n    }  \n    static long pow(long num, long exp, long mod){\n        long ans=1;\n        for(int i=1;i<=exp;i++){\n            ans=(ans*num)%mod;\n        }\n        return ans;\n    }\n    static boolean isPrime(int n)\n    {\n \n        if (n <= 1)\n            return false;\n        else if (n == 2)\n            return true;\n        else if (n % 2 == 0)\n            return false;\n        for (int i = 3; i <= Math.sqrt(n); i += 2) {\n            if (n % i == 0)\n                return false;\n        }\n        return true;\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    static long gcd(long a, long b) {\n        if (a == 0) return b;\n        return gcd(b % a, a);\n    }\n    static int lcm(int a, int b)\n    {\n        return (a / gcd(a, b)) * b;\n    }\n    public static void sort(int[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n    public static void sort(long[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n    static int charint(char c) {\n        return Integer.parseInt(String.valueOf(c));\n    }\n    \n    /* */\n    //printing methods\n    /* */\n    //WOW!\n    /* */\n    public static void printArr(PrintWriter pw, int[] arr) {\n        StringBuilder sb = new StringBuilder();\n        for (int x : arr) {\n            sb.append(x + \"\");\n        }\n        sb.setLength(sb.length() - 1);\n        pw.println(sb.toString());\n    }\n    public static void printArr2d(PrintWriter pw, int[][] arr) {\n        StringBuilder sb = new StringBuilder();\n        for (int[] row : arr) {\n            for (int x : row) {\n                sb.append(x + \" \");\n            }\n            sb.setLength(sb.length() - 1);\n            sb.append(\"\\n\");\n        }\n        pw.println(sb.toString());\n    }\n}\n\nclass FastScanner {\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastScanner() {\n        br = new BufferedReader(new InputStreamReader(System.in), 32768);\n        st = null;\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        }\n        return st.nextToken();\n    }\n\n    int ni() {\n        return Integer.parseInt(next());\n    }\n\n    int[] intArray(int N) {\n        int[] ret = new int[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = ni();\n        return ret;\n    }\n\n    long nl() {\n        return Long.parseLong(next());\n    }\n\n    long[] longArray(int N) {\n        long[] ret = new long[N];\n        for (int i = 0; i < N; i++)\n            ret[i] = nl();\n        return ret;\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\nclass MultiSet {\n    TreeMap<Long, Integer> map = new TreeMap<>();\n    private int size = 0;\n    public MultiSet() {\n    }\n    public void add(Long val) {\n        map.put(val, map.getOrDefault(val, 0) + 1);\n        size++;\n    }\n    public void remove(Long val) {\n        map.put(val, map.get(val) - 1);\n        if (map.get(val) == 0) {\n            map.remove(val);\n        }\n        size--;\n    }\n    public int size() {\n        return size;\n    }\n    public Long higher(Long val) {\n        return map.higherKey(val);\n    }\n    public Long lower(Long val) {\n        return map.lowerKey(val);\n    }\n    public Long ceiling(Long val) {\n        return map.ceilingKey(val);\n    }\n    public Long floor(Long val) {\n        return map.floorKey(val);\n    }\n    public Long first() {\n        return map.firstKey();\n    }\n    public Long last() {\n        return map.lastKey();\n    }\n    public boolean isEmpty() {\n        return map.isEmpty();\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class q3 {\n\n    public static void main(String[] args) throws Exception {\n        // String[] parts=br.readLine().split(\" \");\n        // int n=Integer.parseInt(parts[0]);\n        // int k=Integer.parseInt(parts[1]);\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int tests = Integer.parseInt(br.readLine());\n\n        for (int test = 1;test <= tests;test++) {\n            String[] parts = br.readLine().split(\" \");\n            int n = Integer.parseInt(parts[0]);\n            \n            StringBuilder temp = new StringBuilder();\n\n            int curr = Integer.parseInt(br.readLine());\n            temp.append(\"1\");\n            System.out.println(1);\n            for(int i = 0;i < n - 1;i++){\n                curr = Integer.parseInt(br.readLine());\n                if(curr == 1){\n                    temp.append('.').append('1');\n                    System.out.println(temp);\n                }else{\n                    while(temp.length() > 0){\n                        int idx = temp.length() - 1;\n                        while(idx >= 0 && temp.charAt(idx) != '.') idx--;\n                        idx++;\n\n                        int val = Integer.parseInt(temp.substring(idx));\n                        temp.delete(idx,temp.length());\n                        if(curr == val + 1){\n                            temp.append(String.valueOf(curr));\n                            break;\n                        }\n                        temp.deleteCharAt(temp.length() - 1);\n                    }\n                    System.out.println(temp);\n                }\n            }\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "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        int[]A=new int[n];\n        int point = -1;\n        for(int _i=0;_i<n;_i++){\n            int x =ni();\n            if(x==1){\n                point++;\n                A[point]=1;\n            }\n            else{\n                while(x!=A[point]+1){\n                    A[point]=0;\n                    point--;\n                }\n            }\n            A[point]=x;\n            for(int i=0;i<point;i++)\n                p(A[i]+\".\");\n            pn(A[point]);\n\n        }\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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class tank {\n\n    static final FastScanner fs = new FastScanner();\n\n    static PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) {\n        int t = fs.nextInt();\n        while(t-->0) {\n            run_case();\n        }\n\n        out.close();\n    }\n\n    static void run_case() {\n        int n = fs.nextInt(), prevLen = 1, one = 1;\n        int[] arr = fs.readArray(n);\n        int[] len = new int[1001];\n        StringBuilder[] prev = new StringBuilder[1001];\n\n        len[1] = 1;\n        out.println(1);\n\n        for (int i = 0; i < 1001; i++) {\n            prev[i] = new StringBuilder();\n        }\n\n        prev[1].append(\"1\");\n\n        for (int i = 1; i < n; i++) {\n            if(arr[i] == 1) {\n                prev[prevLen + 1] = new StringBuilder(prev[prevLen]);\n                prev[prevLen + 1].append(\".1\");\n                out.println(prev[prevLen + 1]);\n\n                prevLen++;\n\n                len[prevLen] = 1;\n            }else {\n                for (int j = 1000; j > 0; j--) {\n                    if(len[j] == arr[i] - 1 && j <= prevLen) {\n                        char[] tmp = prev[j].toString().toCharArray();\n\n                        if(fn(tmp)) {\n                            prev[j] = new StringBuilder(\"\" + (len[j] + 1));\n                        }else {\n                            prev[j] = new StringBuilder();\n                            int ub = fn2(tmp);\n                            for (int k = 0; k <= ub; k++) {\n                                prev[j].append(tmp[k]);\n                            }\n\n                            prev[j].append(len[j] + 1);\n                        }\n\n                        out.println(prev[j]);\n\n                        len[j] = len[j] + 1;\n\n                        prevLen = j;\n                        break;\n                    }\n\n                    if(j == 1) {\n                        prev[j] = new StringBuilder(\"\" + (one + 1));\n\n                        out.println(prev[j]);\n\n                        len[j] = one + 1;\n\n                        prevLen = j;\n\n                        one++;\n                    }\n                }\n            }\n        }\n    }\n\n    static boolean fn(char[] arr) {\n        for(char c: arr) {\n            if(c == '.') return false;\n        }\n\n        return true;\n    }\n\n    static int fn2(char[] arr) {\n        int ret = 0;\n\n        for (int i = 0; i < arr.length; i++) {\n            if(arr[i] == '.') ret = i;\n        }\n\n        return ret;\n    }\n\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        String nextLine(){\n            try {\n                return br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n\n            return \"\";\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        int[] readArray(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        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.Deque;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic final class C {\n\n    static class Node {\n        int val;\n        String path;\n        Node node;\n\n        Node(String p, int t) {\n            path = p;\n            val = t;\n        }\n    }\n\n    public static void main(String[] args) {\n        final FastScanner fs = new FastScanner();\n        final int t = fs.nextInt();\n        final StringBuilder sb = new StringBuilder();\n        for (int test = 0; test < t; test++) {\n            final int n = fs.nextInt();\n            final Deque<Node> dq = new ArrayDeque<>();\n            dq.offerLast(new Node(\"\", 0));\n            for (int i = 0; i < n; i++) {\n                final int next = fs.nextInt();\n                if (dq.getFirst().val + 1 != next) {\n                    if (next == 1) {\n                        final Node peek = dq.getFirst();\n                        final String p = peek.path.isEmpty() ? String.valueOf(peek.val)\n                                                             : (peek.path + '.' + peek.val);\n                        dq.addFirst(new Node(p, 1));\n                    } else {\n                        while (dq.getFirst().val + 1 != next) {\n                            dq.removeFirst();\n                        }\n                        dq.getFirst().val++;\n                    }\n                } else {\n                    dq.getFirst().val++;\n                }\n                add(sb, dq.getFirst(), dq.getFirst().val);\n            }\n        }\n        System.out.println(sb);\n    }\n\n    private static void add(StringBuilder sb, Node node, int val) {\n        final String p = node.path.isEmpty() ? String.valueOf(val)\n                                             : (node.path + '.' + val);\n        sb.append(p);\n        sb.append('\\n');\n    }\n\n    static final class Utils {\n        private static class Shuffler {\n            private static void shuffle(int[] x) {\n                final Random r = new Random();\n\n                for (int i = 0; i <= x.length - 2; i++) {\n                    final int j = i + r.nextInt(x.length - i);\n                    swap(x, i, j);\n                }\n            }\n\n            private static void shuffle(long[] x) {\n                final Random r = new Random();\n\n                for (int i = 0; i <= x.length - 2; i++) {\n                    final int j = i + r.nextInt(x.length - i);\n                    swap(x, i, j);\n                }\n            }\n\n            private static void swap(int[] x, int i, int j) {\n                final int t = x[i];\n                x[i] = x[j];\n                x[j] = t;\n            }\n\n            private static void swap(long[] x, int i, int j) {\n                final long t = x[i];\n                x[i] = x[j];\n                x[j] = t;\n            }\n        }\n\n        public static void shuffleSort(int[] arr) {\n            Shuffler.shuffle(arr);\n            Arrays.sort(arr);\n        }\n\n        public static void shuffleSort(long[] arr) {\n            Shuffler.shuffle(arr);\n            Arrays.sort(arr);\n        }\n\n        private Utils() {}\n    }\n\n    static class FastScanner {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(\"\");\n\n        private String next() {\n            while (!st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    //noinspection CallToPrintStackTrace\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        int[] nextIntArray(int n) {\n            final int[] a = new int[n];\n            for (int i = 0; i < n; i++) { a[i] = nextInt(); }\n            return a;\n        }\n\n        long[] nextLongArray(int n) {\n            final long[] a = new long[n];\n            for (int i = 0; i < n; i++) { a[i] = nextLong(); }\n            return a;\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class C {\n    private static FastReader fr = new FastReader();\n    private static PrintWriter out=new PrintWriter(System.out);\n    private static Random random = new Random();\n\n    public static void main(String[] args) throws IOException {\n        StringBuilder sb = new StringBuilder();\n        // code goes here\n        int t = fr.nextInt();\n        while (t-- > 0){\n            int n = fr.nextInt();\n            int[] arr = fr.nextIntArray(n);\n            sb.append(1).append(\"\\n\");\n            List<Integer> state = new ArrayList<>();\n            state.add(1);\n            for(int i = 1; i < n; i++){\n                List<Integer> nextState = new ArrayList<>();\n                boolean found = false;\n                int till = -1;\n                for(int j = state.size() - 1; j >= 0; j--){\n                    if(state.get(j) + 1 == arr[i]){\n                        till = j;\n                        found = true;\n                        break;\n                    }\n                }\n                if(found){\n                    for(int j = 0; j < till; j++){\n                        nextState.add(state.get(j));\n                    }\n                    nextState.add(arr[i]);\n                    sb.append(nextState.get(0));\n                    for(int z = 1; z < nextState.size(); z++){\n                        sb.append(\".\").append(nextState.get(z));\n                    }\n                    sb.append(\"\\n\");\n                }\n                if(!found){\n                    nextState.addAll(state);\n                    nextState.add(arr[i]);\n                    sb.append(nextState.get(0));\n                    for(int z = 1; z < nextState.size(); z++){\n                        sb.append(\".\").append(nextState.get(z));\n                    }\n                    sb.append(\"\\n\");\n                }\n                state = nextState;\n            }\n        }\n        System.out.print(sb.toString());\n    }\n\n    static void ruffleSort(int[] a) {\n        int n=a.length;//shuffle, then sort\n        for (int i=0; i<n; i++) {\n            int oi=random.nextInt(n), temp=a[oi];\n            a[oi]=a[i]; a[i]=temp;\n        }\n        Arrays.sort(a);\n    }\n\n    static class FastReader{\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n\n        public String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\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 nextLong() {\n            return Long.parseLong(next());\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\n    static class Pair<A, B>{\n        A first;\n        B second;\n        public Pair(A first, B second){\n            this.first = first;\n            this.second = second;\n        }\n    }\n\n    static long mod(String num, long a)\n    {\n        // Initialize result\n        long res = 0;\n\n        // One by one process all digits of 'num'\n        for (int i = 0; i < num.length(); i++)\n            res = (res*10 +  num.charAt(i) - '0') %a;\n\n        return res;\n    }\n\n    static long binomialCoeff(long n, long k, long MOD)\n    {\n        long res = 1;\n\n        // Since C(n, k) = C(n, n-k)\n        if (k > n - k)\n            k = n - k;\n\n        // Calculate value of\n        // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]\n        for (int i = 0; i < k; ++i) {\n            res *= (n - i);\n            res /= (i + 1);\n            res %= MOD;\n        }\n\n        return res;\n    }\n\n    static long power(long x, long y, long p)\n    {\n\n        // Initialize result\n        long res = 1;\n\n        // Update x if it is more than or\n        // equal to p\n        x = x % p;\n\n        while (y > 0) {\n\n            // If y is odd, multiply x\n            // with result\n            if (y % 2 == 1)\n                res = (res * x) % p;\n\n            // y must be even now\n            y = y >> 1; // y = y/2\n            x = (x * x) % p;\n        }\n\n        return res;\n    }\n\n    // Returns n^(-1) mod p\n    static long modInverse(long n, long p)\n    {\n        return power(n, p - 2, p);\n    }\n\n    // Returns nCr % p using Fermat's\n    // little theorem.\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        long[] fac = new long[n + 1];\n        fac[0] = 1;\n\n        for (int i = 1; i <= n; i++)\n            fac[i] = fac[i - 1] * i % p;\n\n        return (fac[n] * modInverse(fac[r], p)\n                % p * modInverse(fac[n - r], p)\n                % p)\n                % p;\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.*;\n\npublic class B {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tReader scan = new Reader();\n\t\tint t = scan.nextInt();\n\t\tfor(int tt = 0;tt<t;tt++) {\n\t\t\t\n\t\t\tint n = scan.nextInt();\n\t\t\tint arr[] = new int[n];\n\t\t\tfor(int i = 0;i<n;i++) arr[i] = scan.nextInt();\n\t\t\t\n\t\t\tList<Integer> list = new ArrayList<>();\n\t\t\tint j = -1;\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\tfor(int i = 0;i<n;i++) {\n\t\t\t\tif(list.isEmpty() || arr[i]==1) { //add\n\t\t\t\t\tlist.add(arr[i]);\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t\telse if(arr[i] == list.get(j)+1) { //replace\n\t\t\t\t\tlist.set(j, arr[i]);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfor(int k = j;k>=0;k--) {\n\t\t\t\t\t\tif(arr[i] == list.get(k)+1) {//replace\n\t\t\t\t\t\t\tlist.set(k, arr[i]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {//delete\n\t\t\t\t\t\t\tlist.remove(k);\n\t\t\t\t\t\t\tj--;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ts.delete(0, s.length());\n\t\t\t\tfor(Integer p:list) {\n\t\t\t\t\ts.append(p+\".\");\n\t\t\t\t}\n\t\t\t\ts.deleteCharAt(s.length()-1);\n\t\t\t\tSystem.out.println(s.toString());\n\t\t\t}\n\t\t}\n\n\t\tscan.close();\n\t\t\n\t}\n\t\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[64]; // 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}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "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    //   npe, particularly in maps\n    //\n    // Big numbers arithmetic bugs:\n    //   int overflow\n    //   sorting, or taking max, after MOD\n    void solve() throws IOException {\n        int T = ri();\n        for (int Ti = 0; Ti < T; Ti++) {\n            int n = ri();\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) a[i] = ri();\n            Deque<int[]> stack = new ArrayDeque<>();\n            stack.addLast(new int[]{1});\n            pw.println(\"1\");\n            for (int i = 1; i < n; i++) {\n                if (a[i] == 1) {\n                    int[] prev = stack.peekLast();\n                    int[] curr = new int[prev.length+1];\n                    System.arraycopy(prev, 0, curr, 0, prev.length);\n                    curr[curr.length-1] = 1;\n                    printArr(curr);\n                    stack.addLast(curr);\n                    continue;\n                }\n                while (!stack.isEmpty()) {\n                    int[] prev = stack.removeLast();\n                    if (a[i] == prev[prev.length-1] + 1) {\n                        prev[prev.length-1]++;\n                        printArr(prev);\n                        stack.addLast(prev);\n                        break;\n                    } else {\n                        continue;\n                    }\n                }\n            }\n        }\n    }\n    // IMPORTANT\n    // DID YOU CHECK THE COMMON MISTAKES ABOVE?\n\n    void printArr(int[] a) {\n        pw.print(a[0]);\n        for (int j = 1; j < a.length; j++) pw.print(\".\" + a[j]);\n        pw.println();\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\n    void printDouble(double d) {\n        pw.printf(\"%.16f\", d);\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class C2 {\n    String filename = null;\n    InputReader sc;\n\n    void solve() {\n        int n = sc.nextInt();\n        int[] a = sc.nextArray(n);\n\n        int[] ps = new int[n];\n        int[] q = new int[n];\n        int[] qs = new int[n];\n        int nq = 0;\n        for (int i = 1; i < n; i++) {\n            if (a[i] == 1) {\n                qs[nq] = i - 1;\n                q[nq++] = a[i - 1] + 1;\n                ps[i] = i - 1;\n            } else {\n                if (a[i] == a[i - 1] + 1) {\n                    qs[nq] = i - 1;\n                    q[nq++] = 1;\n                    ps[i] = i - 1;\n                } else {\n                    for (int j = nq - 1; j >= 0; j--) {\n                        if (a[i] == q[j]) {\n                            ps[i] = qs[j];\n                            nq = j;\n                            break;\n                        }\n                    }\n                }\n            }\n        }\n\n        int[] parents = ps;\n        String[] strs = new String[n];\n        strs[0] = \"1\";\n        System.out.println(strs[0]);\n        for (int i = 1; i < n; i++) {\n            String p = strs[parents[i]];\n            if (a[i] == 1) {\n                strs[i] = p + \".1\";\n            } else {\n                int lastDot = p.lastIndexOf(\".\");\n                if (lastDot == -1) {\n                    strs[i] = a[i] + \"\";\n                } else {\n                    strs[i] = p.substring(0, lastDot) + \".\" + a[i];\n                }\n            }\n            System.out.println(strs[i]);\n        }\n    }\n\n    public void run() throws FileNotFoundException {\n        if (filename == null) {\n            sc = new InputReader(System.in);\n        } else {\n            sc = new InputReader(new FileInputStream(new File(filename)));\n        }\n\n        int nTests = sc.nextInt();\n        for (int test = 0; test < nTests; test++) {\n            solve();\n        }\n    }\n\n    public static void main(String[] args) {\n        C2 sol = new C2();\n        try {\n            sol.run();\n        } catch (FileNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n\n    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 float nextFloat() {\n            return Float.parseFloat(next());\n        }\n\n        public double nextDouble() {\n            return Float.parseFloat(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public int[] nextArray(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = nextInt();\n            }\n            return a;\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C{\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t// br = new BufferedReader(new FileReader(\".in\"));\n\t\t// out = new PrintWriter(new FileWriter(\".out\"));\n\t\t//new Thread(null, new (), \"peepee\", 1<<28).start();\n\t\tread();\n\t\tint t= RI();\n\t\twhile(t-->0) {\n\t\t\tread();\n\t\t\tint n = RI();\n\t\t\tList<Integer> cur = new ArrayList<Integer>();\n\t\t\tint[] lvl = new int[n+10];\n\t\t\twhile(n-->0) {\n\t\t\t\tread();\n\t\t\t\tint x = RI();\n\t\t\t\t\n\t\t\t\tif (cur.size() == 0) {\n\t\t\t\t\tcur.add(x);\n\t\t\t\t\tlvl[cur.size()]=x;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\twhile (!cur.isEmpty()) {\n\t\t\t\t\t\tif (x == 1+lvl[cur.size()]) {\n\t\t\t\t\t\t\tint size = cur.size();\n\t\t\t\t\t\t\tcur.remove(size-1);\n\t\t\t\t\t\t\tcur.add(1+lvl[size]);\n\t\t\t\t\t\t\tlvl[size] = x;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Either add to a new level or go to existing one.\n\t\t\t\t\t\t\tif (x == 1) {\n\t\t\t\t\t\t\t\t// add\n\t\t\t\t\t\t\t\tcur.add(x);\n\t\t\t\t\t\t\t\tlvl[cur.size()] = x;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tlvl[cur.size()] = 0;\n\t\t\t\t\t\t\t\tcur.remove(cur.size()-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\tif (cur.size() == 0) {\n\t\t\t\t\t\tcur.add(x);\n\t\t\t\t\t\tlvl[cur.size()]=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\tfor (int i = 0; i < cur.size(); i++) {\n\t\t\t\t\tout.print(cur.get(i));\n\t\t\t\t\tif (i != cur.size()-1) out.print(\".\");\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tstatic PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tstatic StringTokenizer st;\n\tstatic void read() throws IOException{st = new StringTokenizer(br.readLine());}\t\n\tstatic int RI() throws IOException{return Integer.parseInt(st.nextToken());}\n\tstatic long RL() throws IOException{return Long.parseLong(st.nextToken());}\n\tstatic double RD() throws IOException{return Double.parseDouble(st.nextToken());}\n\t\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \nimport java.math.*;\nimport java.awt.Point;\n \npublic class Main {\n    static final long MOD = 1000000007L;\n    //static final long MOD2 = 1000000009L;\n    //static final long MOD = 998244353L;\n    //static final long INF = 500000000000L;\n    static final int INF =   1000000005;\n    static final int NINF = -1000000005;\n    //static final long INF = 1000000000000000000L;\n    static FastScanner sc;\n    static PrintWriter pw;\n    static final int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}};\n \n    public static void main(String[] args) {\n        sc = new FastScanner();\n        pw = new PrintWriter(System.out);\n \n        int Q = sc.ni();\n        for (int q = 0; q < Q; q++) {\n            int N = sc.ni();\n            int[] nums = sc.intArray(N, 0);\n            pw.println(1);\n            ArrayDeque<Integer> ad = new ArrayDeque<Integer>();\n            ad.push(1);\n            for (int i = 1; i < N; i++) {\n                if (nums[i]==1) {\n                    ad.push(1);\n                } else {\n                    while (!ad.isEmpty()) {\n                        int d = ad.pop();\n                        if (d==nums[i]-1) {\n                            ad.push(nums[i]);\n                            break;\n                        }\n                    }\n                }\n                printAD(ad);\n            }\n        }\n\n        pw.close(); \n    }\n\n    public static void printAD(ArrayDeque<Integer> v) {\n        Object[] arr = v.toArray();\n        for (int i = arr.length-1; i >= 0; i--) {\n            pw.print(arr[i]);\n            if (i>0) pw.print(\".\");\n        }\n        pw.println();\n    }\n \n    public static void sort(int[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    public static void sort(long[] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr);\n    }\n \n    //Sort an array (immune to quicksort TLE)\n    public static void sort(int[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            int[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<int[]>() {\n            @Override\n            public int compare(int[] a, int[] b) {\n                return a[0]-b[0];\n            }\n        });\n    }\n    \n    public static void sort(long[][] arr) {\n        Random rgen = new Random();\n        for (int i = 0; i < arr.length; i++) {\n            int r = rgen.nextInt(arr.length);\n            long[] temp = arr[i];\n            arr[i] = arr[r];\n            arr[r] = temp;\n        }\n        Arrays.sort(arr, new Comparator<long[]>() {\n            @Override\n            public int compare(long[] a, long[] b) {\n                if (a[0] > b[0])\n                    return 1;\n                else if (a[0] < b[0])\n                    return -1;\n                else\n                    return 0;\n                //Ascending order.\n            }\n        });\n    }\n \n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n \n        public FastScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in), 32768);\n            st = null;\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        int[][] graph(int N, int[][] edges) {\n            int[][] graph = new int[N][];\n            int[] sz = new int[N];\n            for (int[] e: edges) {\n                sz[e[0]] += 1;\n                sz[e[1]] += 1;\n            }\n            for (int i = 0; i < N; i++) {\n                graph[i] = new int[sz[i]];\n            }\n            int[] cur = new int[N];\n            for (int[] e: edges) {\n                graph[e[0]][cur[e[0]]] = e[1];\n                graph[e[1]][cur[e[1]]] = e[0];\n                cur[e[0]] += 1;\n                cur[e[1]] += 1;\n            }\n            return graph;\n        }\n \n        int[] intArray(int N, int mod) {\n            int[] ret = new int[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = ni()+mod;\n            return ret;\n        }\n \n        char[] charArray(int N) {\n            char[] ret = new char[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = next().charAt(0);\n            return ret;\n        }\n \n        long nl() {\n            return Long.parseLong(next());\n        }\n \n        long[] longArray(int N, long mod) {\n            long[] ret = new long[N];\n            for (int i = 0; i < N; i++)\n                ret[i] = nl()+mod;\n            return ret;\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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import javafx.util.Pair;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n    static HashMap<Integer, ArrayList<Integer>> tree = new HashMap<>();\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        PrintStream out = System.out;\n\n        int t = Integer.parseInt(br.readLine());\n\n        for (int i = 0; i < t; i++) {\n            int n = Integer.parseInt(br.readLine());\n            ArrayList<Integer> depth = new ArrayList<>();\n            int y = 0;\n            String[] ans = new String[n];\n            for (int x = 0; x < n; x++) {\n                int in = Integer.parseInt(br.readLine());\n                if (in == 1) {\n                    if (y == depth.size()) depth.add(1);\n                    else depth.set(y, 1);\n                    y++;\n                    StringBuilder curr = new StringBuilder();\n                    curr.append(depth.get(0));\n                    for (int a = 1; a < y; a++) {\n                        curr.append('.');\n                        curr.append(depth.get(a));\n                    }\n                    ans[x] = curr.toString();\n                    continue;\n                }\n                for (int d = y-1; d >= 0; d--) {\n                    if (depth.get(d) == in-1) {\n                        y = d+1;\n                        depth.set(d, depth.get(d)+1);\n                        StringBuilder curr = new StringBuilder();\n                        for (int a = 0; a < d; a++) {\n                            curr.append(depth.get(a));\n                            curr.append('.');\n                        }\n                        curr.append(in);\n                        ans[x] = curr.toString();\n                        break;\n                    }\n                }\n            }\n            //Arrays.sort(ans);\n            for (String x : ans) out.println(x);\n        }\n\n        System.out.flush();\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdF {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n\tpublic static void main(String[] havish) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\tint t = sc.nextInt();\n \t\twhile(t-->0) {\n \t \t\tint n = sc.nextInt();\n \t \t\t\n \t \t\tStack<Integer> st = new Stack<>();\n \t \t\tStack<Integer> temporary = new Stack<>();\n \t \t\tfor(int j = 0;j<n;j++){\n \t \t\t\tint val = sc.nextInt();\n \t \t\t\tboolean found = false;\n \t \t\t\twhile(!st.isEmpty()){\n \t \t\t\t\tint temp = st.peek();\n \t \t\t\t\tif (val == temp+1){\n \t \t\t\t\t\tfound = true;\n \t \t\t\t\t\tst.pop();\n \t \t\t\t\t\tbreak;\n \t \t\t\t\t}\n \t \t\t\t\telse{\n \t \t\t\t\t\ttemporary.add(st.pop());\n \t \t\t\t\t}\n \t \t\t\t}\n \t \t\t\tif (!found){\n\t \t \t\t\twhile(!temporary.isEmpty()){\n\t \t \t\t\t\tst.add(temporary.pop());\n\t \t \t\t\t}\n \t \t\t\t}\n \t \t\t\tst.add(val);\n \t \t\t\tArrayList<Integer> arr = new ArrayList<>();\n \t \t\t\t\n \t \t\t\tfor(int s : st){\n \t \t\t\t\tarr.add(s);\n \t \t\t\t}\n \t \t\t\tfor (int s =0 ;s<arr.size()-1;s++){\n \t \t\t\t\tout.print(arr.get(s));\n \t \t\t\t\tout.print(\".\");\n \t \t\t\t}\n \t \t\t\tout.println(arr.get(arr.size()-1));\n \t \t\t\ttemporary.clear();\n \t \t\t}\n \t\t\t\n \t\t}\n \t\t\n \t\tout.close();\n \t\t\n \t}\n\t\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "//Implemented By Aman Kotiyal Date:-30-May-2021  Time:-7:54:28 pm\nimport java.io.*;\nimport java.util.*;\n\npublic class ques3\n{\n\tpublic static void main(String[] args)throws Exception{ new ques3().run();} \n\tlong mod=1000000000+7;\n\t\n\tvoid solve() throws Exception\n\t{\n\t\tfor(int ii=ni();ii>0;ii--)\n\t\t{\n\t\t\tint n=ni();\n\t\t\t//ArrayList<Integer> al=new ArrayList<Integer>();\n\t\t\tStack<Integer> st=new Stack<Integer>();\n\t\t\tint x=ni();\n\t\t\t//al.add(1);\n\t\t\tst.add(1);\n\t\t\tout.println(\"1\");\n\t\t\tfor(int i=2;i<=n;i++)\n\t\t\t{\n\t\t\t\t x=ni();\n\t\t\t\t if(x==1)\n\t\t\t\t {\n\t\t\t\t\t st.add(1);\n\t\t\t\t\t Stack<Integer> tep=(Stack<Integer>) st.clone();\n\t\t\t\t\t display(tep);\n\t\t\t\t\t continue;\n\t\t\t\t }\n\t\t\t\t int top=st.peek();\n\t\t\t\t if(top+1==x)\n\t\t\t\t {\n\t\t\t\t\t st.pop();\n\t\t\t\t\t st.add(x);\n\t\t\t\t\t Stack<Integer> tep=(Stack<Integer>) st.clone();\n\t\t\t\t\t display(tep);\n\t\t\t\t\t continue;\n\t\t\t\t }\n\t\t\t\t while(true)\n\t\t\t\t {\n\t\t\t\t\t top=st.peek();\n\t\t\t\t\t if(top+1==x)\n\t\t\t\t\t {\n\t\t\t\t\t\t st.pop();\n\t\t\t\t\t\t st.add(x);\n\t\t\t\t\t\t Stack<Integer> tep=(Stack<Integer>) st.clone();\n\t\t\t\t\t\t display(tep);\n\t\t\t\t\t\t break;\n\t\t\t\t\t }\n\t\t\t\t\t top=st.pop();\n\t\t\t\t }\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\tvoid display(Stack<Integer> st)\n\t{\n\t\tArrayList<Integer> al = new ArrayList<>();\n\t\twhile(st.size()!=0)\n\t\t{\n\t\t\tint tem=st.pop();\n\t\t\tal.add(tem);\n\t\t}\n\t\tCollections.reverse(al);\n\t\tfor (int i = 0; i <al.size()-1; i++) {\n\t\t\tout.print(al.get(i)+\".\");\n\t\t}\n\t\tout.println(al.get(al.size()-1));\n\t}\n\t\n\t/*FAST INPUT OUTPUT & METHODS BELOW*/\n\t\n\tprivate byte[] buf=new byte[1024];\n\tprivate int index;\n\tprivate InputStream in;\n\tprivate int total;\n\tprivate SpaceCharFilter filter;\n\tPrintWriter out;\n\t\n\tint min(int... ar){int min=Integer.MAX_VALUE;for(int i:ar)min=Math.min(min, i);return min;}\n\tlong min(long... ar){long min=Long.MAX_VALUE;for(long i:ar)min=Math.min(min, i);return min;}\n\tint max(int... ar) {int max=Integer.MIN_VALUE;for(int i:ar)max=Math.max(max, i);return max;}\n\tlong max(long... ar) {long max=Long.MIN_VALUE;for(long i:ar)max=Math.max(max, i);return max;}\n\tvoid reverse(int a[]){for(int i=0;i<a.length>>1;i++){int tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}\n\tvoid reverse(long a[]){for(int i=0;i<a.length>>1;i++){long tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}\n\tString reverse(String s){StringBuilder sb=new StringBuilder(s);sb.reverse();return sb.toString();}\n\t\n\tvoid shuffle(int a[]) {\n\t\tArrayList<Integer> al = new ArrayList<>();\n\t\tfor(int i=0;i<a.length;i++) \n\t\t\tal.add(a[i]);\n\t\t\n\t\tCollections.sort(al);\n\t\tfor(int i=0;i<a.length;i++) \n\t\t\ta[i]=al.get(i);\n\t}\n\tlong lcm(long a,long b)\n\t{\n\t\treturn (a*b)/(gcd(a,b));\n\t}\n\t\n\tint gcd(int a, int b) \n\t{ \n\t\tif (a == 0) \n\t\t\treturn b; \n\t\treturn gcd(b%a, a); \n\t} \n\tlong gcd(long a, long b) \n\t{ \n\t\tif (a == 0) \n\t\t\treturn b; \n\t\treturn gcd(b%a, a); \n\t}\n\t/* for (1/a)%mod = ( a^(mod-2) )%mod  ----> use expo to calc -->(a^(mod-2)) */\n\tlong expo(long p,long q)  /*  (p^q)%mod   */\n\t{\n\t\tlong z = 1;\n\t\twhile (q>0) {\n\t\t\tif (q%2 == 1) {\n\t\t\t\tz = (z * p)%mod;\n\t\t\t}\n\t\t\tp = (p*p)%mod;\n\t\t\tq >>= 1;\n\t\t}\n\t\treturn z;\n\t}\n\tvoid run()throws Exception\n\t{\n\t\tin=System.in; out = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.flush();\n\t}\n\tprivate int scan()throws IOException\n\t{\n\t\tif(total<0)\n\t\t\tthrow new InputMismatchException();\n\t\tif(index>=total)\n\t\t{\n\t\t\tindex=0;\n\t\t\ttotal=in.read(buf);\n\t\t\tif(total<=0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[index++];\n\t}\n\tprivate int ni() throws IOException \n\t{\n\t\tint c = scan();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = scan();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = scan();\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 = scan();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tprivate long nl() throws IOException \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = scan();\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 = scan();\n\t\t}\n\t}\n\tprivate double nd() throws IOException{\n\t\treturn Double.parseDouble(ns());\n\t}\n\tprivate String ns() throws IOException {\n\t\tint c = scan();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = scan();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tif (Character.isValidCodePoint(c))\n\t\t\t\tres.appendCodePoint(c);\n\t\t\tc = scan();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\tprivate String nss() throws IOException\n\t{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\treturn br.readLine();\n\t}\n\tprivate char nc() throws IOException \n\t{\n\t\tint c = scan();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = scan();\n\t\treturn (char) c;\n\t}\n\tprivate boolean isWhiteSpace(int n)\n\t{\n\t\tif(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\tprivate boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhiteSpace(c);\n\t}\n\tprivate interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "/*\nstream Butter!\neggyHide eggyVengeance\nI need U\nxiao rerun when\n */\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.abs;\nimport static java.lang.System.out;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class x1523C\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        int T = Integer.parseInt(st.nextToken());\n        StringBuilder sb = new StringBuilder();\n        while(T-->0)\n        {\n            st = new StringTokenizer(infile.readLine());\n            int N = Integer.parseInt(st.nextToken());\n            int[] arr = new int[N];\n            for(int i=0; i < N; i++)\n                arr[i] = Integer.parseInt(infile.readLine());\n            ArrayList<Integer>[] buckets = new ArrayList[N];\n            buckets[0] = new ArrayList<Integer>();\n            buckets[0].add(arr[0]);\n            //first element always 1?\n            for(int i=1; i < N; i++)\n            {\n                ArrayList<Integer> ls = new ArrayList<Integer>();\n                if(arr[i] == 1)\n                {\n                    for(int x: buckets[i-1])\n                        ls.add(x);\n                    ls.add(1);\n                }\n                else\n                {\n                    int dex = -1;\n                    for(int a=0; a < buckets[i-1].size(); a++)\n                        if(buckets[i-1].get(a) == arr[i]-1)\n                            dex = a;\n                    for(int a=0; a < dex; a++)\n                        ls.add(buckets[i-1].get(a));\n                    ls.add(arr[i]);\n                }\n                buckets[i] = ls;\n            }\n            //output answer\n            for(int a=0; a < N; a++)\n            {\n                for(int i=0; i < buckets[a].size()-1; i++)\n                {\n                    sb.append(buckets[a].get(i));\n                    sb.append(\".\");\n                }\n                sb.append(arr[a]);\n                sb.append(\"\\n\");\n            }\n        }\n        System.out.print(sb);\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C_1523 {\n\n\tstatic Scanner input = new Scanner(System.in);\n\tstatic int n;\n\n\tpublic static void main(String[] args) {\n\t\tint t = input.nextInt();\n\t\tfor(int test = 0; test < t; test++){\n\t\t\tn = input.nextInt();\n\t\t\tint num = input.nextInt();\n\t\t\tif(num == 1){\n\t\t\t\tn--;\n\t\t\t\trecur(\"\");\n\t\t\t}else{\n\t\t\t\tSystem.out.println(\"ERROR\");\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static int recur(String before){\n\t\tint num = 1;\n\t\tSystem.out.println(before + num);\n\t\twhile(n > 0){\n\t\t\tint val = input.nextInt();\n\t\t\tn--;\n\t\t\tif(val == 1){\n\t\t\t\tval = recur(before + num + \".\");\n\t\t\t}\n\t\t\tif(val == num + 1){\n\t\t\t\tnum++;\n\t\t\t\tSystem.out.println(before + num);\n\t\t\t}else{\n\t\t\t\treturn val;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class codeforces {\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tint t=sc.nextInt();\n\t\twhile(t-->0) {\n\t\t\tint n=sc.nextInt();\n\t\t\tint[]a=sc.nextIntArray(n);\n\t\t\tLinkedList<Integer>ll=new LinkedList<Integer>();\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tif(a[i]==1) {\n\t\t\t\t\tll.addLast(a[i]);\n\t\t\t\t}else if(ll.isEmpty()) {\n\t\t\t\t\tll.addLast(a[i]);\n\t\t\t\t\t\n\t\t\t\t}else {\n\t\t\t\t\twhile(!(ll.getLast()==a[i]-1)) {\n\t\t\t\t\t\tll.removeLast();\n\t\t\t\t\t}\n\t\t\t\t\tll.removeLast();\n\t\t\t\t\tll.addLast(a[i]);\n\t\t\t\t}\n\t\t\t\tint ii=0;\n\t\t\t\tfor(int j:ll) {\n\t\t\t\t\tpw.print(j);\n\t\t\t\t\tif(ii!=ll.size()-1){\n\t\t\t\t\t\tpw.print('.');\n\t\t\t\t\t}\n\t\t\t\t\tii++;\n\t\t\t\t}\n\t\t\t\tpw.println();\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\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 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[] nextLongArray(int n) throws IOException {\n\t\t\tLong[] a = new Long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] 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\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n\tstatic class pair implements Comparable<pair> {\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\tpublic String toString() {\n\t\t\treturn x + \" \" + y;\n\t\t}\n\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (o instanceof pair) {\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\n\t\tpublic int hashCode() {\n\t\t\treturn new Long(x).hashCode() * 31 + new Long(y).hashCode();\n\t\t}\n\n\t\tpublic int compareTo(pair other) {\n\t\t\tif (this.x == other.x) {\n\t\t\t\treturn Long.compare(this.y, other.y);\n\t\t\t}\n\t\t\treturn Long.compare(this.x, other.x);\n\t\t}\n\t}\n\n\tstatic class tuble implements Comparable<tuble> {\n\t\tint x;\n\t\tint y;\n\t\tint z;\n\n\t\tpublic tuble(int x, int y, int z) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.z = z;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y + \" \" + z;\n\t\t}\n\n\t\tpublic int compareTo(tuble other) {\n\t\t\tif (this.x == other.x) {\n\t\t\t\tif (this.y == other.y) {\n\t\t\t\t\treturn this.z - other.z;\n\t\t\t\t}\n\t\t\t\treturn this.y - other.y;\n\t\t\t} else {\n\t\t\t\treturn this.x - other.x;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic long mod = 1000000007;\n\tstatic Random rn = new Random();\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class C {\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/c.in\"))));\n\t\t/**/\n\t\t\n\t\tint t = sc.nextInt();\n\t\tfor (int z = 0; z < t; ++z) {\n\t\t\tint n = sc.nextInt();\n\t\t\tArrayList<Integer> al = new ArrayList<>();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint x = sc.nextInt();\n\t\t\t\tif (x==1) {\n\t\t\t\t\tal.add(x);\n\t\t\t\t} else {\n\t\t\t\t\twhile (al.get(al.size()-1)!=x-1) {\n\t\t\t\t\t\tal.remove(al.size()-1);\n\t\t\t\t\t}\n\t\t\t\t\tal.remove(al.size()-1);\n\t\t\t\t\tal.add(x);\n\t\t\t\t}\n\t\t\t\tStringBuilder pr = new StringBuilder();\n\t\t\t\tString d = \"\";\n\t\t\t\tfor (int xx : al) {\n\t\t\t\t\tpr.append(d+xx);\n\t\t\t\t\td = \".\";\n\t\t\t\t}\n\t\t\t\tSystem.out.println(pr);\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.PI;\nimport static java.lang.System.in;\nimport static java.lang.System.out;\nimport static java.lang.System.err;\n/*\n11\n1\n1\n1\n2\n2\n1\n2\n1\n2\n2\n3\n*/\npublic class C {    \n    static public void main(String... args) throws Exception {   \n        Foster sc = new Foster();\n        PrintWriter p = new PrintWriter(out);\n        int t = sc.nextInt();\n        while(t--!=0){\n            int n = sc.nextInt();\n            int a[] = sc.intArray(n);\n            ArrayList<ArrayList<Integer>> arr = new ArrayList<>();\n            for(int i = 0; i < n; i++){\n                ArrayList<Integer> temp = new ArrayList<>();\n                if(i-1 < 0){\n                    temp.add(1);\n                }\n                else{\n                    ArrayList<Integer> inner = arr.get(i-1);\n                    int last = inner.get(inner.size()-1);\n                    ArrayDeque<Integer> q = new ArrayDeque<>();\n                    for(int j : inner){\n                        q.addLast(j);\n                    }\n                    // if current is one greater then increment\n                    if(last+1 == a[i]){\n                        q.pollLast();\n                        q.addLast(a[i]);\n                    }\n                    // move the chain\n                    else if(a[i]==1){\n                        q.addLast(a[i]);\n                    }\n                    // move back\n                    else{\n                        while(!q.isEmpty() && a[i]-q.peekLast() != 1){\n                            q.pollLast();\n                        }\n                        if(q.isEmpty()) q.addLast(a[i]);\n                        else{\n                            q.pollLast();\n                            q.addLast(a[i]);\n                        }\n                    }\n                    // transfer queue to list\n                    while(!q.isEmpty()){\n                        temp.add(q.pollFirst());\n                    }\n                }\n                arr.add(temp);\n            }\n\n            // output answer\n            for(int i = 0; i < arr.size(); i++){\n                p.print(arr.get(i).get(0));\n                for(int j = 1; j < arr.get(i).size(); j++){\n                    p.print(\".\" + arr.get(i).get(j));\n                }\n                p.println();\n            }\n        }\n        p.close();\n    }\n    \n    static long[] sort(long a[]){\n        ArrayList<Long> arr = new ArrayList<>();\n        for(long i : a){\n            arr.add(i);\n        }\n        Collections.sort(arr);\n        for(int i = 0; i < arr.size(); i++){\n            a[i] = arr.get(i);\n        }\n        return a;\n    }\n    static int[] sort(int a[]){\n        ArrayList<Integer> arr = new ArrayList<>();\n        for(int i : a){\n            arr.add(i);\n        }\n        Collections.sort(arr);\n        // Collections.reverse(arr);\n        for(int i = 0; i < arr.size(); i++){\n            a[i] = arr.get(i);\n        }\n        return a;\n    }\n    \n    \n/* \n*/    \n/*\n1. Check overflow in pow function or in general\n2. Check indices of read array function\n3. Think of an easier solution because the problems you solve are always easy\n4. Check iterator of loop\n5. If still doesn't work, then jump from the 729th floor 'coz \"beta tumse na ho paayega\"\n\n    Move to top!!\n*/\n    static class Foster {\n        BufferedReader br = new BufferedReader(new InputStreamReader(in));\n        StringTokenizer st = new StringTokenizer(\"\");\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\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        int[] intArray(int n) {                   // Check indices\n            int arr[] = new int[n];\n            for(int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n            return arr;\n        }\n        long[] longArray(int n) {                 // Check indices\n            long arr[] = new long[n];\n            for(int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n            return arr;\n        }\n        int[] getBits(int n) {                   //in Reverse Order\n            int a[] = new int[31];\n            for(int i = 0; i < 31; i++) {\n                if(((1<<i) & n) != 0)\n                    a[i] = 1;\n            }\n            return a;\n        }\n        static long pow(long... a) {\n            long mod = Long.MAX_VALUE;\n            if(a.length == 3)   mod = a[2];\n            long res = 1;\n            while(a[1] > 0) {\n                if((a[1] & 1) == 1)\n                    res = (res * a[0]) % mod;\n                a[1] /= 2;\n                a[0] = (a[0] * a[0]) % mod;\n            }\n            return res;\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class Main {\n   \n \n      static class Reader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n \n        public Reader()\n        {\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(\n                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                if (c == '\\n') {\n                    if (cnt != 0) {\n                        break;\n                    }\n                    else {\n                        continue;\n                    }\n                }\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            }\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        public long nextLong() throws IOException\n        {\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        {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n \n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n \n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n \n            if (neg)\n                return -ret;\n            return ret;\n        }\n \n        private void fillBuffer() throws IOException\n        {\n            bytesRead = din.read(buffer, bufferPointer = 0,\n                                 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     //System.out.println(\"YES\");\n//System.out.println(\"NO\");\n \n//int n=sc.nextInt();\n//int a[]=new int[n];\n//for(int i=0;i<n;i++)\n//a[i]=sc.nextInt();\n \n//int n=sc.nextInt();\n//long a[]=new long[n];\n//for(int i=0;i<n;i++)\n//a[i]=sc.nextLong();\n \n//System.out.println();\n \n//String str=sc.next();\n//long n=sc.nextLong();\n\n  \n    public static void main(String[] args) throws IOException{\n        Scanner sc=new Scanner(System.in);\n      //  Reader sc=new Reader();\n        PrintWriter out=new PrintWriter(System.out);\n        int t = sc.nextInt();\n\t\twhile(t-->0) {\n\t\t    int n=sc.nextInt();\n\t\t     ArrayList<Integer> al[]=new ArrayList[n+1];\n\t\t     \n\t\t    for(int i=0;i<=n;i++)\n\t\t    al[i]=new ArrayList<>();\n\t\t    \n\t\t    al[0].add(1);\n\t\t    \n\t\t    int y;\n\t\t    y=sc.nextInt();\n\t\t    boolean flag=true;\n\t\t    for(int i=1;i<=n-1;i++) {\n\t\t         int x=sc.nextInt();\n\t\t        int idx=al[i-1].size()-1;\n\t\t        if(x!=1) {\n\t\t            while(flag) {\n\t\t                int ans=x-1;\n\t\t                if(al[i-1].get(idx)==ans) {\n\t\t                    idx--;\n\t\t                   break;\n\t\t                }\n\t\t                idx--;\n\t\t            }\n\t\t        }\n\t\t        for(int j=0;j<=idx;j++) {\n\t\t            al[i].add(al[i-1].get(j));\n\t\t        }\n\t\t        al[i].add(x);\n\t\t    }\n\t\t    \n\t\t    for(int i=0;i<=n-1;i++) {\n\t\t        out.print(al[i].get(0));\n\t\t        for(int j=1;j<=al[i].size()-1;j++) {\n\t\t            out.print(\".\"+al[i].get(j));\n\t\t        }\n\t\t        out.println();\n\t\t    }\n\t\n        \n  }\n\t\t  \n\t\t  out.flush();\n\t\t  out.close();\n\t\t \n\t\t  \n  \n\t\t  \n        }\n        \n\t\t\n\t\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n    public static void main(String[] args) throws IOException{\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        int t = Integer.parseInt(f.readLine());\n        while(t-->0){\n            int n = Integer.parseInt(f.readLine());\n            int[] arr = new int[n];\n            for(int i = 0; i < n; i++){\n                arr[i] = Integer.parseInt(f.readLine());\n            }\n            int[] levels = new int[n];\n            int curr_level = 0;\n            for(int i = 0; i < n; i++){\n                if(levels[curr_level] == arr[i]-1){\n                    levels[curr_level]++;\n                }else if(arr[i] == 1){\n                    curr_level++;\n                    levels[curr_level]++;\n                }else if(arr[i] > 1){\n                    while(curr_level > 0 && levels[curr_level] != arr[i]-1){\n                        levels[curr_level] = 0;\n                        curr_level--;\n                    }\n                    levels[curr_level]++;\n                }\n                StringBuilder ostring = new StringBuilder();\n                for(int level = 0; level <= curr_level; level++){\n                    ostring.append(levels[level]);\n                    if(level != curr_level) ostring.append(\".\");\n                }\n                out.println(ostring);\n            }\n\n        }\n        out.close();\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "//package deltix2021;\nimport java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class C {\n\tInputStream is;\n\tFastWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni();T > 0;T--)go();\n\t}\n\n\tvoid go()\n\t{\n\t\tint n = ni();\n\t\tint[] st = new int[n];\n\t\tint sp = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint x = ni();\n\t\t\tif(x == 1){\n\t\t\t\tst[sp++] = 1;\n\t\t\t}else{\n\t\t\t\twhile(sp > 0){\n\t\t\t\t\tif(st[sp-1] + 1 == x){\n\t\t\t\t\t\tst[sp-1]++;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tsp--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < sp;j++){\n\t\t\t\tif(j > 0)out.print(\".\");\n\t\t\t\tout.print(st[j]);\n\t\t\t}\n\t\t\tout.println();\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 FastWriter(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 C().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\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 char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[][] nmi(int n, int m) {\n\t\tint[][] map = new int[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\n\t\treturn map;\n\t}\n\n\tprivate int ni() { return (int)nl(); }\n\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\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\tpublic static class FastWriter\n\t{\n\t\tprivate static final int BUF_SIZE = 1<<13;\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\n\t\tprivate final OutputStream out;\n\t\tprivate int ptr = 0;\n\n\t\tprivate FastWriter(){out = null;}\n\n\t\tpublic FastWriter(OutputStream os)\n\t\t{\n\t\t\tthis.out = os;\n\t\t}\n\n\t\tpublic FastWriter(String path)\n\t\t{\n\t\t\ttry {\n\t\t\t\tthis.out = new FileOutputStream(path);\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter write(byte b)\n\t\t{\n\t\t\tbuf[ptr++] = b;\n\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(char c)\n\t\t{\n\t\t\treturn write((byte)c);\n\t\t}\n\n\t\tpublic FastWriter write(char[] s)\n\t\t{\n\t\t\tfor(char c : s){\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(String s)\n\t\t{\n\t\t\ts.chars().forEach(c -> {\n\t\t\t\tbuf[ptr++] = (byte)c;\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\n\t\t\t});\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(int l) {\n\t\t\tif (l >= 1000000000) return 10;\n\t\t\tif (l >= 100000000) return 9;\n\t\t\tif (l >= 10000000) return 8;\n\t\t\tif (l >= 1000000) return 7;\n\t\t\tif (l >= 100000) return 6;\n\t\t\tif (l >= 10000) return 5;\n\t\t\tif (l >= 1000) return 4;\n\t\t\tif (l >= 100) return 3;\n\t\t\tif (l >= 10) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(int x)\n\t\t{\n\t\t\tif(x == Integer.MIN_VALUE){\n\t\t\t\treturn write((long)x);\n\t\t\t}\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate static int countDigits(long l) {\n\t\t\tif (l >= 1000000000000000000L) return 19;\n\t\t\tif (l >= 100000000000000000L) return 18;\n\t\t\tif (l >= 10000000000000000L) return 17;\n\t\t\tif (l >= 1000000000000000L) return 16;\n\t\t\tif (l >= 100000000000000L) return 15;\n\t\t\tif (l >= 10000000000000L) return 14;\n\t\t\tif (l >= 1000000000000L) return 13;\n\t\t\tif (l >= 100000000000L) return 12;\n\t\t\tif (l >= 10000000000L) return 11;\n\t\t\tif (l >= 1000000000L) return 10;\n\t\t\tif (l >= 100000000L) return 9;\n\t\t\tif (l >= 10000000L) return 8;\n\t\t\tif (l >= 1000000L) return 7;\n\t\t\tif (l >= 100000L) return 6;\n\t\t\tif (l >= 10000L) return 5;\n\t\t\tif (l >= 1000L) return 4;\n\t\t\tif (l >= 100L) return 3;\n\t\t\tif (l >= 10L) return 2;\n\t\t\treturn 1;\n\t\t}\n\n\t\tpublic FastWriter write(long x)\n\t\t{\n\t\t\tif(x == Long.MIN_VALUE){\n\t\t\t\treturn write(\"\" + x);\n\t\t\t}\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\n\t\t\tif(x < 0){\n\t\t\t\twrite((byte)'-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tint d = countDigits(x);\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tptr += d;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(double x, int precision)\n\t\t{\n\t\t\tif(x < 0){\n\t\t\t\twrite('-');\n\t\t\t\tx = -x;\n\t\t\t}\n\t\t\tx += Math.pow(10, -precision)/2;\n\t\t\t//\t\tif(x < 0){ x = 0; }\n\t\t\twrite((long)x).write(\".\");\n\t\t\tx -= (long)x;\n\t\t\tfor(int i = 0;i < precision;i++){\n\t\t\t\tx *= 10;\n\t\t\t\twrite((char)('0'+(int)x));\n\t\t\t\tx -= (int)x;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(char c){\n\t\t\treturn write(c).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(int x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long x){\n\t\t\treturn write(x).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(double x, int precision){\n\t\t\treturn write(x, precision).writeln();\n\t\t}\n\n\t\tpublic FastWriter write(int... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(int x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter write(long... xs)\n\t\t{\n\t\t\tboolean first = true;\n\t\t\tfor(long x : xs) {\n\t\t\t\tif (!first) write(' ');\n\t\t\t\tfirst = false;\n\t\t\t\twrite(x);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln()\n\t\t{\n\t\t\treturn write((byte)'\\n');\n\t\t}\n\n\t\tpublic FastWriter writeln(int... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(long... xs)\n\t\t{\n\t\t\treturn write(xs).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[] line)\n\t\t{\n\t\t\treturn write(line).writeln();\n\t\t}\n\n\t\tpublic FastWriter writeln(char[]... map)\n\t\t{\n\t\t\tfor(char[] line : map)write(line).writeln();\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic FastWriter writeln(String s)\n\t\t{\n\t\t\treturn write(s).writeln();\n\t\t}\n\n\t\tprivate void innerflush()\n\t\t{\n\t\t\ttry {\n\t\t\t\tout.write(buf, 0, ptr);\n\t\t\t\tptr = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic void flush()\n\t\t{\n\t\t\tinnerflush();\n\t\t\ttry {\n\t\t\t\tout.flush();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"flush\");\n\t\t\t}\n\t\t}\n\n\t\tpublic FastWriter print(byte b) { return write(b); }\n\t\tpublic FastWriter print(char c) { return write(c); }\n\t\tpublic FastWriter print(char[] s) { return write(s); }\n\t\tpublic FastWriter print(String s) { return write(s); }\n\t\tpublic FastWriter print(int x) { return write(x); }\n\t\tpublic FastWriter print(long x) { return write(x); }\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\n\t\tpublic FastWriter println(char c){ return writeln(c); }\n\t\tpublic FastWriter println(int x){ return writeln(x); }\n\t\tpublic FastWriter println(long x){ return writeln(x); }\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\n\t\tpublic FastWriter println(String s) { return writeln(s); }\n\t\tpublic FastWriter println() { return writeln(); }\n\t}\n\n\tpublic void trnz(int... 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// print ids which are 1\n\tpublic void trt(long... o)\n\t{\n\t\tQueue<Integer> stands = new ArrayDeque<>();\n\t\tfor(int i = 0;i < o.length;i++){\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\n\t\t}\n\t\tSystem.out.println(stands);\n\t}\n\n\tpublic 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\tpublic void tf(boolean[]... b)\n\t{\n\t\tfor(boolean[] r : b) {\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\n\t\t\tSystem.out.println();\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic void tf(long[]... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long[] r : b) {\n\t\t\t\tfor (long x : r) {\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\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\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic void tf(long... b)\n\t{\n\t\tif(INPUT.length() != 0) {\n\t\t\tfor (long x : b) {\n\t\t\t\tfor (int i = 0; i < 64; i++) {\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\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", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n/**\n __                  __\n ( _)                ( _)\n / / \\\\              / /\\_\\_\n / /   \\\\            / / | \\ \\\n / /     \\\\          / /  |\\ \\ \\\n /  /   ,  \\ ,       / /   /|  \\ \\\n /  /    |\\_ /|      / /   / \\   \\_\\\n /  /  |\\/ _ '_| \\   / /   /   \\    \\\\\n |  /   |/  0 \\0\\    / |    |    \\    \\\\\n |    |\\|      \\_\\_ /  /    |     \\    \\\\\n |  | |/    \\.\\ o\\o)  /      \\     |    \\\\\n \\    |     /\\\\`v-v  /        |    |     \\\\\n | \\/    /_| \\\\_|  /         |    | \\    \\\\\n | |    /__/_ `-` /   _____  |    |  \\    \\\\\n \\|    [__]  \\_/  |_________  \\   |   \\    ()\n /    [___] (    \\         \\  |\\ |   |   //\n |    [___]                  |\\| \\|   /  |/\n /|    [____]                  \\  |/\\ / / ||\n (  \\   [____ /     ) _\\      \\  \\    \\| | ||\n \\  \\  [_____|    / /     __/    \\   / / //\n |   \\ [_____/   / /        \\    |   \\/ //\n |   /  '----|   /=\\____   _/    |   / //\n __ /  /        |  /   ___/  _/\\    \\  | ||\n (/-(/-\\)       /   \\  (/\\/\\)/  |    /  | /\n (/\\/\\)           /   /   //\n _________/   /    /\n \\____________/    (\n\n\n @author NTUDragons-Reborn\n */\n\npublic class C{\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    // main solver\n    static class Task{\n\n        double eps= 0.00000001;\n        static final int MAXN = 10000001;\n\n        // stores smallest prime factor for every number\n        static int spf[] = new int[MAXN];\n\n        Map<Integer,Set<Integer>> dp= new HashMap<>();\n\n        // Calculating SPF (Smallest Prime Factor) for every\n        // number till MAXN.\n        // Time Complexity : O(nloglogn)\n        public void sieve()\n        {\n            spf[1] = 1;\n            for (int i=2; i<MAXN; i++)\n\n                // marking smallest prime factor for every\n                // number to be itself.\n                spf[i] = i;\n\n            // separately marking spf for every even\n            // number as 2\n            for (int i=4; i<MAXN; i+=2)\n                spf[i] = 2;\n\n            for (int i=3; i*i<MAXN; i++)\n            {\n                // checking if i is prime\n                if (spf[i] == i)\n                {\n                    // marking SPF for all numbers divisible by i\n                    for (int j=i*i; j<MAXN; j+=i)\n\n                        // marking spf[j] if it is not\n                        // previously marked\n                        if (spf[j]==j)\n                            spf[j] = i;\n                }\n            }\n        }\n\n        // A O(log n) function returning primefactorization\n        // by dividing by smallest prime factor at every step\n        public Set<Integer> getFactorization(int x)\n        {\n            if(dp.containsKey(x)) return dp.get(x);\n            Set<Integer> ret = new HashSet<>();\n            while (x != 1)\n            {\n                if(spf[x]!=2) ret.add(spf[x]);\n                x = x / spf[x];\n            }\n            dp.put(x,ret);\n            return ret;\n        }\n        // function to find first index >= x\n        public int lowerIndex(List<Integer> arr, int n, int x)\n        {\n            int l = 0, h = n - 1;\n            while (l <= h)\n            {\n                int mid = (l + h) / 2;\n                if (arr.get(mid) >= x)\n                    h = mid - 1;\n                else\n                    l = mid + 1;\n            }\n            return l;\n        }\n\n        // function to find last index <= y\n        public int upperIndex(List<Integer> arr, int n, int y)\n        {\n            int l = 0, h = n - 1;\n            while (l <= h)\n            {\n                int mid = (l + h) / 2;\n                if (arr.get(mid) <= y)\n                    l = mid + 1;\n                else\n                    h = mid - 1;\n            }\n            return h;\n        }\n\n        // function to count elements within given range\n        public int countInRange(List<Integer> arr, int n, int x, int y)\n        {\n            // initialize result\n            int count = 0;\n            count = upperIndex(arr, n, y) -\n                    lowerIndex(arr, n, x) + 1;\n            return count;\n        }\n        InputReader in;\n        PrintWriter out;\n        public void solve(InputReader in, PrintWriter out) {\n            this.in=in;\n            this.out=out;\n            int t=in.nextInt();\n            while(t-->0){\n                int n= in.nextInt();\n                int[] arr= new int[n];\n                for(int i=0;i<n;i++) arr[i]= in.nextInt();\n                int[] cur= new int[n];\n                int idx=0;\n                for(int num: arr){\n                    if(idx<n && num==cur[idx]+1){\n                        cur[idx]=num;\n                        printRes(cur, idx);\n                        idx++;\n                    }\n                    else{\n                        for(int i=idx;i>=0;i--){\n                            if(i<n && num!=cur[i]+1) cur[i]=0;\n                            else{\n                                cur[i]=num;\n                                printRes(cur,i);\n                                i++;\n                                idx=i;\n                                break;\n                            }\n                        }\n                    }\n\n                }\n            }\n        }\n\n        public void printRes(int[] cur, int idx){\n            for(int i=0;i<idx;i++) out.print(cur[i]+\".\");\n            out.println(cur[idx]);\n        }\n\n        public boolean ok(char[] s){\n            boolean allEqual = true;\n            boolean Alternate = true;\n            for (int i = 0; i < s.length - 1; i++){\n                if (s[i]!=s[i+1]){\n                    allEqual = false;\n                }\n                else{\n                    Alternate = false;\n                }\n            }\n            if (s[0] == '0' || s[s.length-1] == '0'){\n                return false;\n            }\n            return allEqual || Alternate;\n        }\n\n        // private int cal()\n        public static boolean nextPermutation(char[] array){\n            boolean hasNext = false;\n            int i;\n            for(i = array.length-2; i >= 0; i--){\n                if(array[i] < array[i+1]){\n                    hasNext = true;\n                    break;\n                }\n            }\n             \n            if(!hasNext){// If all elements are arranged from largest to smallest, it means the largest string\n                return false;\n            }\n             \n            // Find backward from the subscript of i + 1 (must be monotonically decreasing), find a smallest element in the set larger than array [i]\n            int j;\n            for(j = i+1; j < array.length; j++){\n                if(array[j] <= array[i]){\n                    break;\n                }\n            }\n            j--;\n             \n            // Swap these two elements, and then reverse all the elements in i + 1 and later (i + 1, array.length)\n            swap(array, i, j);\n            reverse(array, i+1, array.length);\n       \n            return true;\n        }\n        public static void swap(char[] array, int i, int j) {\n            char temp =array[i];\n            array[i] = array[j];\n            array[j] =temp;\t\n        }\n        public static void reverse(char[] array, int start, int end){\n            for(int i = start, j = end-1; i < j; i++, j--) {\n                swap(array, i, j);\n            }\n        }\n\n        public static class compareL implements Comparator<Tuple>{\n            @Override\n            public int compare(Tuple t1, Tuple t2) {\n                return t2.l - t1.l;\n            }\n        }\n        public static class compareR implements Comparator<Tuple>{\n            @Override\n            public int compare(Tuple t1, Tuple t2) {\n                return t1.r - t2.r;\n            }\n        }\n        public static class Tuple{\n            public int l, r, w;\n            public Tuple(int l, int r,int w){\n                this.l = l; this.r= r;\n                this.w =w;\n            }\n        }\n        public static class Range implements Comparable<Range>{\n            public int l, r;\n            List<Integer> data;\n            int weight;\n            public Range(int l, int r, List<Integer> data){\n                this.data = data;\n                this.l = l; this.r =r;\n                this.weight = (int)1e9;\n            }\n\n            @Override\n            public int compareTo(Range o) {\n                return this.l - o.l;\n            }\n        }\n        public int _gcd(int a,  int  b)\n        {\n\n            if(b == 0) {\n                return a;\n            }\n            else {\n                return _gcd(b, a % b);\n            }\n        }\n\n    }\n\n    static class Tuple implements Comparable<Tuple>{\n        int x, y, z;\n        public Tuple(int x, int y, int z){\n            this.x= x;\n            this.y= y;\n            this.z=z;\n        }\n        @Override\n        public int compareTo(Tuple o){\n            return this.x-o.x;\n        }\n    }\n\n    static class Pair implements Comparable<Pair>{\n        public int x;\n        public int y;\n        public Pair(int x, int y){\n            this.x= x;\n            this.y= y;\n        }\n\n        @Override\n        public int compareTo(Pair o) {\n            return this.x-o.x;\n        }\n    }\n    // fast input reader class;\n    static class InputReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public InputReader(InputStream stream) {\n            br = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String nextToken() {\n            while (st == null || !st.hasMoreTokens()) {\n                String line = null;\n                try {\n                    line = br.readLine();\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n                if (line == null) {\n                    return null;\n                }\n                st = new StringTokenizer(line);\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(nextToken());\n        }\n        public double nextDouble(){\n            return Double.parseDouble(nextToken());\n        }\n        public long nextLong(){\n            return Long.parseLong(nextToken());\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\npublic class C {\n    public static void main(String[] args) throws Exception {\n        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder sb = new StringBuilder();\n        int t = Integer.parseInt(buffer.readLine());\n        while (t-- > 0) {\n            int n = Integer.parseInt(buffer.readLine());\n            ArrayList<Integer>list = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                int a = Integer.parseInt(buffer.readLine());\n                if (a == 1)\n                    list.add(1);\n                else {\n                    for (int j = list.size()-1; j >= 0; j--) {\n                        if (list.get(j)+1 == a)\n                            break;\n                        list.remove(list.size()-1);\n                    }\n                    list.remove(list.size()-1);\n                    list.add(a);\n                }\n                for (int j = 0; j < list.size(); j++) {\n                    sb.append(list.get(j));\n                    if (j == list.size()-1)\n                        sb.append(\"\\n\");\n                    else\n                        sb.append(\".\");\n                }\n            }\n        }\n        System.out.println(sb);\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Deque;\nimport java.util.ArrayList;\nimport java.io.UncheckedIOException;\nimport java.util.List;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayDeque;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 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            CCompressionAndExpansion solver = new CCompressionAndExpansion();\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\n    static class CCompressionAndExpansion {\n        Node end = new Node(null, -1);\n        FastOutput out;\n\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.ri();\n\n            List<Node> seq = new ArrayList<>(n);\n            Deque<Node> dq = new ArrayDeque<>(n);\n            end = new Node(null, -1);\n            dq.addLast(end);\n            for (int i = 0; i < n; i++) {\n                int x = in.ri();\n                while (true) {\n                    Node last = dq.peekLast();\n                    if (last.nextChild != x) {\n                        dq.removeLast();\n                        continue;\n                    }\n                    last.nextChild++;\n                    dq.addLast(new Node(dq.peekLast(), x));\n                    break;\n                }\n                seq.add(dq.peekLast());\n            }\n\n            this.out = out;\n            for (Node node : seq) {\n                print(node);\n                out.println();\n            }\n        }\n\n        void print(Node root) {\n            if (root.p != end) {\n                print(root.p);\n                out.append('.');\n            }\n            out.append(root.index);\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 String next() {\n            return readString();\n        }\n\n        public int ri() {\n            return readInt();\n        }\n\n        public int readInt() {\n            boolean rev = false;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                rev = next == '-';\n                next = read();\n            }\n\n            int val = 0;\n            while (next >= '0' && next <= '9') {\n                val = val * 10 - next + '0';\n                next = read();\n            }\n\n            return rev ? val : -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 Node {\n        Node p;\n        int index;\n        int nextChild = 1;\n\n        public Node(Node p, int index) {\n            this.p = p;\n            this.index = index;\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() {\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", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.StringTokenizer;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.ArrayList;\n\npublic class p3\n{\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader()\n\t\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next()\n\t\t{\n\t\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (IOException e) {\n\t\t\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() { return Integer.parseInt(next()); }\n\n\t\tbyte nextByte() { return Byte.parseByte(next()); }\n\n\t\tshort nextShort() { return Short.parseShort(next()); }\n\n\t\tlong nextLong() { return Long.parseLong(next()); }\n\n\t\tdouble nextDouble()\t{\treturn Double.parseDouble(next());\t}\n\n\t\tString nextLine()\n\t\t{\n\t\t\t\tString str = \"\";\n\t\t\t\ttry {\n\t\t\t\t\t\tstr = br.readLine();\n\t\t\t\t}\n\t\t\t\tcatch (IOException e) {\n\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\treturn str;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tFastReader fr=new FastReader();\n\n\t\tbyte t=fr.nextByte();\n\t\twhile(t-->0)\n\t\t{\n\t\t\tshort n=fr.nextShort();\n\t\t\tshort a[]=new short [n];\n\t\t\tfor (short i=-1;++i<n;)\n\t\t\t\ta[i]=fr.nextShort();\n\t\t\t\n\t\t\tString s=\"1\";\n\t\t\tSystem.out.println(s);\n\n\t\t\tfor(short i=0;++i<n;)\n\t\t\t{\n\t\t\t\tif(a[i]==1)\n\t\t\t\t{\n\t\t\t\t\ts+=\".1\";\n\t\t\t\t\tSystem.out.println(s);\n\t\t\t\t}\n\t\t\t\telse if(a[i]==a[i-1]+1)\n\t\t\t\t{\n\t\t\t\t\tint c=s.lastIndexOf(\".\");\n\t\t\t\t\ts=s.substring(0,c+1)+a[i];\n\t\t\t\t\tSystem.out.println(s);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\t\t\t\t\t\n\t\t\t\t\tfor(;;)\n\t\t\t\t\t{\n\t\t\t\t\t\ts=s.substring(0,s.lastIndexOf(\".\"));\n\t\t\t\t\t\tint c=s.lastIndexOf(\".\");\n\n\t\t\t\t\t\tint b=Integer.parseInt(s.substring(c+1,s.length()));\n\t\t\t\t\t\tif(b+1==a[i])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ts=s.substring(0,c+1)+a[i];\n\t\t\t\t\t\t\tSystem.out.println(s);\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}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n@SuppressWarnings(\"unused\")\npublic class C{\n\t\n\tstatic long inf = (long)1e15;\n\t\n    public static void main(String[] args) throws IOException {\n    \t\n\t\t\n    \tFastScanner fs = new FastScanner();\n    \tPrintWriter out = new PrintWriter(System.out);\n  \t\t\n    \tint tt = fs.nextInt();\n    \touter:\n    \twhile(tt-->0) {\n    \t\t\n    \t\tint n = fs.nextInt();\n    \t\tint[] a = fs.readArray(n);\n    \t\t\n    \t\tArrayList<Integer>[] l = new ArrayList[n];\n    \t\tfor(int i=0;i<n;i++) l[i] = new ArrayList<Integer>();\n    \t\t\n    \t\tl[0].add(1);\n    \t\t\n    \t\tfor(int i=1;i<n;i++) {\n    \t\t\tif(a[i]==1) {\n    \t\t\t\tfor(int j=0;j<l[i-1].size();j++) l[i].add(l[i-1].get(j));\n    \t\t\t\tl[i].add(1);\n    \t\t\t}\n    \t\t\telse {\n    \t\t\t\tint ind = -1;\n    \t\t\t\tfor(int j=l[i-1].size()-1;j>=0;j--) {\n    \t\t\t\t\tif(l[i-1].get(j)+1==a[i]) {\n    \t\t\t\t\t\tind = j; break;\n    \t\t\t\t\t}\n    \t\t\t\t}\n    \t\t\t\tfor(int j=0;j<ind;j++) l[i].add(l[i-1].get(j));\n    \t\t\t\tl[i].add(a[i]);\n    \t\t\t}\n    \t\t}\n    \t\t\n    \t\tfor(int i=0;i<n;i++) {\n    \t\t\tout.print(l[i].get(0));\n    \t\t\tfor(int j=1;j<l[i].size();j++) out.print(\".\"+l[i].get(j));\n    \t\t\tout.println();\n    \t\t}\n    \t\t\n    \t\t\n    \t\t\n    \t\t\n    \t}\n    \t\n    \tout.close();\n    \t\t\n    \t\n    \t\n    }\n    \n    \n    \n    \n    \n    static final Random random=new Random();\n    \n    static <T> void shuffle(T[] arr) {\n    \tint n = arr.length;\n    \tfor(int i=0;i<n;i++\t) {\n    \t\tint k = random.nextInt(n);\n    \t\tT temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;\n    \t}\n    }\n    \n    \t\n    static void ruffleSort(int[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); int temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n    \n    static void ruffleSort(long[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); long temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n   \n  \n    \n    static void reverse(int[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tint temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    static void reverse(long[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tlong temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    \n    static <T> void reverse(T[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++) {\n    \t\tT temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \t\n    \t\n    static class FastScanner{\n    \tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    \tStringTokenizer st = new StringTokenizer(\"\");\n     \n    \tpublic String next(){\n    \t\twhile(!st.hasMoreElements()){\n    \t\t\ttry{\n    \t\t\t\tst = new StringTokenizer(br.readLine());\n    \t\t\t} catch(IOException e){\n    \t\t\t\te.printStackTrace();\n    \t\t\t}\n    \t\t}\n    \t\treturn st.nextToken();\n    \t}\n    \t\t\n    \tpublic String nextLine() throws IOException {\n    \t\treturn br.readLine();\n    \t}\n    \t\t\n    \tpublic int nextInt(){\n    \t\treturn Integer.parseInt(next());\n    \t}\n     \n    \tpublic int[] readArray(int n){\n    \t\tint[] a = new int[n];\n    \t\tfor(int i=0;i<n;i++)\n    \t\t\ta[i] = nextInt();\n    \t\treturn a;\n    \t}\n    \t\t\n    \tpublic long nextLong() {\n    \t\treturn Long.parseLong(next());\n    \t}\n    \t\n    \tpublic double nextDouble() {\n    \t\treturn Double.parseDouble(next());\n    \t}\n    \t\t\n    \tpublic char nextChar() {\n    \t\treturn next().toCharArray()[0];\n    \t}\n    \t\n    \t\n    }\n   \t\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Stack;\n\npublic class C {\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\n\tpublic static void solve() {\n\t\tIn in = new In();\n\t\tint tests = in.ni();\n\t\twhile (tests-- > 0) {\n\t\t\tint n = in.ni();\n\t\t\tint[] a = in.nia(n);\n\t\t\tStack<Integer> st = new Stack<>();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor (int num : a) {\n//\t\t\t\tSystem.out.println(\"Checking \" + num);\n\t\t\t\tif (st.isEmpty()) {\n\t\t\t\t\tst.push(num);\n\t\t\t\t\tsb.append(num);\n\t\t\t\t} else {\n\t\t\t\t\t// increment current level\n\t\t\t\t\tif (num == st.peek() + 1) {\n\t\t\t\t\t\tst.pop();\n\t\t\t\t\t\tst.push(num);\n\n\t\t\t\t\t\twhile (sb.length() > 0 && sb.charAt(sb.length() - 1) != '.') {\n\t\t\t\t\t\t\tsb.deleteCharAt(sb.length() - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsb.append(num);\n\t\t\t\t\t} \n\t\t\t\t\t// expand current level by 1\n\t\t\t\t\telse if (num == 1) {\n\t\t\t\t\t\tst.push(num);\n\t\t\t\t\t\tsb.append(\".\");\n\t\t\t\t\t\tsb.append(num);\n\t\t\t\t\t} \n\t\t\t\t\t// increment higher level\n\t\t\t\t\telse {\n\t\t\t\t\t\t// search which higher level is the previous of the current number\n\t\t\t\t\t\twhile (!st.isEmpty() && st.peek() + 1 != num) {\n\t\t\t\t\t\t\tst.pop();\n\t\t\t\t\t\t\twhile (sb.length() > 0 && sb.charAt(sb.length() - 1) != '.') {\n\t\t\t\t\t\t\t\tsb.deleteCharAt(sb.length() - 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (sb.length() > 0)\n\t\t\t\t\t\t\t\tsb.deleteCharAt(sb.length() - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n//\t\t\t\t\t\tSystem.out.println(\" \" + st.toString() + \" \" + sb.toString());\n\t\t\t\t\t\tif (!st.isEmpty() && st.peek() + 1 == num) {\n\t\t\t\t\t\t\tst.pop();\n\t\t\t\t\t\t\tst.add(num);\n\t\t\t\t\t\t\twhile (sb.length() > 0 && sb.charAt(sb.length() - 1) != '.') {\n\t\t\t\t\t\t\t\tsb.deleteCharAt(sb.length() - 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsb.append(num);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tSystem.out.println(\">>\" + st.toString());\n\t\t\t\tout.println(sb);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// long start = System.nanoTime();\n\t\tsolve();\n\t\t// System.out.println(\"Elapsed: \" + (System.nanoTime() - start) / 1000000 +\n\t\t// \"ns\");\n\t\tout.flush();\n\t}\n\n\t@SuppressWarnings(\"unused\")\n\tprivate static class In {\n\t\tfinal private static int BUFFER_SIZE = 1024;\n\t\tprivate byte[] buf;\n\t\tprivate InputStream is;\n\t\tprivate int buflen;\n\t\tprivate int bufptr;\n\n\t\tpublic In() {\n\t\t\tis = System.in;\n\t\t\tbuf = new byte[BUFFER_SIZE];\n\t\t\tbuflen = bufptr = 0;\n\t\t}\n\n\t\tpublic In(String input) {\n\t\t\tis = new ByteArrayInputStream(input.getBytes());\n\t\t\tbuf = new byte[BUFFER_SIZE];\n\t\t\tbuflen = bufptr = 0;\n\t\t}\n\n\t\tpublic int readByte() {\n\t\t\tif (bufptr >= buflen) {\n\t\t\t\ttry {\n\t\t\t\t\tbuflen = is.read(buf);\n\t\t\t\t} catch (IOException ioe) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tbufptr = 0;\n\t\t\t}\n\t\t\tif (buflen <= 0)\n\t\t\t\treturn -1;\n\t\t\treturn buf[bufptr++];\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tpublic int skip() {\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t\t;\n\t\t\treturn b;\n\t\t}\n\n\t\t/* Next character */\n\t\tpublic char nc() {\n\t\t\treturn (char) skip();\n\t\t}\n\n\t\t/* Next double */\n\t\tpublic double nd() {\n\t\t\treturn Double.parseDouble(ns());\n\t\t}\n\n\t\t/* Next string */\n\t\tpublic String ns() {\n\t\t\tfinal StringBuilder sb = new StringBuilder();\n\t\t\tint b = skip();\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\t/* Next integer */\n\t\tpublic int ni() {\n\t\t\tboolean minus = false;\n\t\t\tint num = 0;\n\t\t\tint b;\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\t\twhile (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn minus ? -num : num;\n\t\t}\n\n\t\t/* Next long */\n\t\tpublic long nl() {\n\t\t\tboolean minus = false;\n\t\t\tlong num = 0;\n\t\t\tint b;\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\t\twhile (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn minus ? -num : num;\n\t\t}\n\n\t\t/* Next integer 1D array */\n\t\tpublic int[] nia(int n) {\n\t\t\tfinal int[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = ni();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next long 1D array */\n\t\tpublic long[] nla(int n) {\n\t\t\tfinal long[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = nl();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next string 1D array */\n\t\tpublic String[] nsa(int n) {\n\t\t\tfinal String[] arr = new String[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = ns();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next char 1D array */\n\t\tpublic char[] nca(int n) {\n\t\t\tfinal char[] arr = new char[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = nc();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next double 1D array */\n\t\tpublic double[] nda(int n) {\n\t\t\tfinal double[] arr = new double[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tarr[i] = nc();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next integer matrix */\n\t\tpublic int[][] nim(int n, int m) {\n\t\t\tfinal int[][] 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] = ni();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next long matrix */\n\t\tpublic long[][] nlm(int n, int m) {\n\t\t\tfinal long[][] arr = new long[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] = nl();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next string matrix */\n\t\tpublic String[][] nsm(int n, int m) {\n\t\t\tfinal String[][] arr = new String[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] = ns();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next char matrix */\n\t\tpublic char[][] ncm(int n, int m) {\n\t\t\tfinal char[][] arr = new char[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] = nc();\n\t\t\treturn arr;\n\t\t}\n\n\t\t/* Next double matrix */\n\t\tpublic double[][] ndm(int n, int m) {\n\t\t\tfinal double[][] arr = new double[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] = nd();\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic static void log(Object... o) {\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t\t}\n\t}\n\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "/*\n\u2800\u2800\u2800\u2800\u28e0\u28f6\u287e\u280f\u2809\u2819\u2833\u28a6\u2840\u2800\u2800\u2800\u28a0\u281e\u2809\u2819\u2832\u2840\u2800\n\u2800\u2800\u2800\u28f4\u283f\u280f\u2800\u2800\u2800\u2800\u2800\u2800\u28b3\u2840\u2800\u284f\u2800\u2800Y\u2800\u2800\u28b7\n\u2800\u2800\u28a0\u28df\u28cb\u2840\u2880\u28c0\u28c0\u2840\u2800\u28c0\u2840\u28e7\u2800\u28b8\u2800\u2800A\u2800\u2800 \u2847\n\u2800\u2800\u28b8\u28ef\u286d\u2801\u2838\u28db\u28df\u2806\u2874\u28fb\u2872\u28ff\u2800\u28f8\u2800\u2800S\u2800  \u2847\n\u2800\u2800\u28df\u28ff\u286d\u2800\u2800\u2800\u2800\u2800\u28b1\u2800\u2800\u28ff\u2800\u28b9\u2800\u2800H\u2800\u2800 \u2847\n\u2800\u2800\u2819\u28bf\u28ef\u2804\u2800\u2800\u2800\u2880\u2840\u2800\u2800\u287f\u2800\u2800\u2847\u2800\u2800\u2800\u2800\u287c\n\u2800\u2800\u2800\u2800\u2839\u28f6\u2806\u2800\u2800\u2800\u2800\u2800\u2874\u2803\u2800\u2800\u2818\u2824\u28c4\u28e0\u281e\u2800\n\u2800\u2800\u2800\u2800\u2800\u28b8\u28f7\u2866\u28a4\u2864\u28a4\u28de\u28c1\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n\u2800\u2800\u2880\u28e4\u28f4\u28ff\u28cf\u2801\u2800\u2800\u2838\u28cf\u28af\u28f7\u28d6\u28e6\u2840\u2800\u2800\u2800\u2800\u2800\u2800\n\u2880\u28fe\u28fd\u28ff\u28ff\u28ff\u28ff\u281b\u28b2\u28f6\u28fe\u2889\u2877\u28ff\u28ff\u2835\u28ff\u2800\u2800\u2800\u2800\u2800\u2800\n\u28fc\u28ff\u280d\u2809\u28ff\u286d\u2809\u2819\u28ba\u28c7\u28fc\u284f\u2800\u2800\u2800\u28c4\u28b8\u2800\u2800\u2800\u2800\u2800\u2800\n\u28ff\u28ff\u28e7\u28c0\u28ff\u2026\u2026\u2026\u28c0\u28f0\u28cf\u28d8\u28c6\u28c0\u2800\u2800\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter; // System.out is a PrintStream\n// import java.util.Arrays;\nimport java.util.ArrayDeque;\n// import java.util.ArrayList;\n// import java.util.Collections;    //  for sorting ArrayList mainly\n// import java.util.HashMap;\n// import java.util.HashSet;\n// import java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class C {\n    public static void main(String[] args) throws IOException {\n        FastScanner scn = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        for (int tc = scn.nextInt(); tc > 0; tc--) {\n            int N = scn.nextInt();\n            int[] arr = new int[N];\n            for (int i = 0; i < N; i++) {\n                arr[i] = scn.nextInt();\n            }\n            StringBuilder[] ans = new StringBuilder[N];\n            ans[0] = new StringBuilder(\"1\");\n            ArrayDeque<Integer> st = new ArrayDeque<>();\n            st.addLast(0);\n            for (int i = 1; i < N; i++) {\n                // System.out.println(st);\n                ans[i] = new StringBuilder();\n                if (arr[i] == 1) {\n                    st.addLast(i);\n                    ans[i].append(ans[i - 1].toString() + \".1\");\n                } else {\n                    while (arr[st.getLast()] != arr[i] - 1) {\n                        st.removeLast();\n                    }\n                    int pos = st.removeLast();\n                    String[] prev = ans[pos].toString().split(\"[.]\");\n                    for (int j = 0, sz = prev.length - 1; j < sz; j++) {\n                        ans[i].append(prev[j] + \".\");\n                    }\n                    ans[i].append(arr[i] + \"\");\n                    st.addLast(i);\n                }\n            }\n            for (StringBuilder str : ans) {\n                out.println(str);\n            }\n        }\n        out.close();\n    }\n\n    private static int gcd(int num1, int num2) {\n        int temp = 0;\n        while (num2 != 0) {\n            temp = num1;\n            num1 = num2;\n            num2 = temp % num2;\n        }\n        return num1;\n    }\n\n    private static int lcm(int num1, int num2) {\n        return (int)((1L * num1 * num2) / gcd(num1, num2));\n    }\n\n    private static void ruffleSort(int[] arr) {\n        // int N = arr.length;\n        // Random rand = new Random();\n        // for (int i = 0; i < N; i++) {\n        //     int oi = rand.nextInt(N), temp = arr[i];\n        //     arr[i] = arr[oi];\n        //     arr[oi] = temp;\n        // }\n        // Arrays.sort(arr);\n    }\n\n    private static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastScanner() {\n            this.br = new BufferedReader(new InputStreamReader(System.in));\n            this.st = new StringTokenizer(\"\");\n        }\n\n        String next() {\n            while (!st.hasMoreTokens()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException err) {\n                    err.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        String nextLine() {\n            if (st.hasMoreTokens()) {\n                return st.nextToken(\"\").trim();\n            }\n            try {\n                return br.readLine().trim();\n            } catch (IOException err) {\n                err.printStackTrace();\n            }\n            return \"\";\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.HashSet;\n\n\npublic class Solution {\n    public static void main(String[] args)throws IOException {\n        FastReader in=new FastReader(System.in);\n        int t=in.nextInt();\n        StringBuilder sb=new StringBuilder();\n        int i,j,tc=0;\n        while(tc++<t) {\n            int n=in.nextInt();\n            int arr[]=new int[n];\n            for(i=0;i<n;i++)\n                arr[i]=in.nextInt();\n            int ans[]=new int[n+4];\n            ans[0]=1;\n            int pos=0;\n            sb.append(\"1\\n\");\n            for(i=1;i<n;i++){\n                if(arr[i]==arr[i-1]+1){\n                    ans[pos]=ans[pos]+1;\n                }\n                else if(arr[i]==1){\n                    pos++;\n                    ans[pos]=1;\n                }\n                else{\n                    while(ans[pos]!=arr[i]-1)\n                        pos--;\n                    ans[pos]=ans[pos]+1;\n                }\n                for(j=0;j<=pos;j++){\n                    if(j<pos)\n                        sb.append(ans[j]).append(\".\");\n                    else\n                        sb.append(ans[j]).append(\"\\n\");\n                }\n\n            }\n        }\n        System.out.println(sb);\n    }\n}\n\nclass Node {\n    int setroot, dist;\n    public Node(int setroot, int dist){\n        this.setroot = setroot;\n        this.dist = dist;\n    }\n    @Override\n    public String toString() {\n        return String.format(setroot + \", \" + dist);\n    }\n}\n\nclass FastReader {\n\n    byte[] buf = new byte[2048];\n    int index, total;\n    InputStream in;\n\n    FastReader(InputStream is) {\n        in = is;\n    }\n\n    int scan() throws IOException {\n        if (index >= total) {\n            index = 0;\n            total = in.read(buf);\n            if (total <= 0) {\n                return -1;\n            }\n        }\n        return buf[index++];\n    }\n\n    String next() throws IOException {\n        int c;\n        for (c = scan(); c <= 32; c = scan()) ;\n        StringBuilder sb = new StringBuilder();\n        for (; c > 32; c = scan()) {\n            sb.append((char) c);\n        }\n        return sb.toString();\n    }\n\n    int nextInt() throws IOException {\n        int c, val = 0;\n        for (c = scan(); c <= 32; c = scan()) ;\n        boolean neg = c == '-';\n        if (c == '-' || c == '+') {\n            c = scan();\n        }\n        for (; c >= '0' && c <= '9'; c = scan()) {\n            val = (val << 3) + (val << 1) + (c & 15);\n        }\n        return neg ? -val : val;\n    }\n\n    long nextLong() throws IOException {\n        int c;\n        long val = 0;\n        for (c = scan(); c <= 32; c = scan()) ;\n        boolean neg = c == '-';\n        if (c == '-' || c == '+') {\n            c = scan();\n        }\n        for (; c >= '0' && c <= '9'; c = scan()) {\n            val = (val << 3) + (val << 1) + (c & 15);\n        }\n        return neg ? -val : val;\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n\n    final static int mod = 1000000007;\n    static FastReader sc;\n    static PrintWriter out;\n    static boolean test_case_input = true;\n    static final int MAX = 1000000000;\n    static final int MIN = -1000000000;\n\n    public static void print(int a[], int point) {\n        out.print(a[1]);\n        for(int i = 2; i <= point; i++) {\n            out.print(\".\" + a[i]);\n        }\n        out.println();\n    }\n\n    public static void solution(int test_case) throws IOException {\n        // code\n        int n = sc.nextInt();\n        int a[] = sc.intarr(n);\n        int lev[] = new int[n + 1];\n        lev[1] = 1;\n        int point = 1;\n        out.println(1);\n        for(int i=1; i < n; i++) {\n            if(a[i] == 1) {\n                point++;\n                lev[point] = 1;\n                print(lev, point);\n            }\n            else if(a[i] == lev[point] + 1) {\n                lev[point]++;\n                print(lev, point);\n            }\n            else {\n                while(lev[point] + 1 != a[i]) {\n                    point--;\n                }\n                lev[point]++;\n                print(lev, point);\n            }\n        }\n    }\n\n    // log A base B\n    public static int logint(int x, int base) {\n        return (int) (Math.log(x) / Math.log(base));\n    }\n\n    public static int logint(long x, long base) {\n        return (int) (Math.log(x) / Math.log(base));\n    }\n\n    public static int logint(double x, double base) {\n        return (int) (Math.log(x) / Math.log(base));\n    }\n\n    public static double logdouble(int x, int base) {\n        return (Math.log(x) / Math.log(base));\n    }\n\n    public static double logdouble(long x, long base) {\n        return (Math.log(x) / Math.log(base));\n    }\n\n    public static double logdouble(double x, double base) {\n        return (Math.log(x) / Math.log(base));\n    }\n\n    public static long loglong(int x, int base) {\n        return (long) (Math.log(x) / Math.log(base));\n    }\n\n    public static long loglong(long x, long base) {\n        return (long) (Math.log(x) / Math.log(base));\n    }\n\n    public static long loglong(double x, double base) {\n        return (long) (Math.log(x) / Math.log(base));\n    }\n\n    // Debug\n    public static void debug(String msg, Object value) {\n        File output = new File(\"output.txt\");\n        if (!output.exists()) return;\n        String type = value.getClass().getSimpleName();\n        if (type.equals(\"int[]\")) out.println(msg + \" => \" + Arrays.toString((int[]) value));\n        else if (type.equals(\"double[]\")) out.println(msg + \" => \" + Arrays.toString((double[]) value));\n        else if (type.equals(\"float[]\")) out.println(msg + \" => \" + Arrays.toString((float[]) value));\n        else if (type.equals(\"long[]\")) out.println(msg + \" => \" + Arrays.toString((long[]) value));\n        else if (type.equals(\"char[]\")) out.println(msg + \" => \" + Arrays.toString((char[]) value));\n        else if (type.equals(\"String[]\")) out.println(msg + \" => \" + Arrays.toString((String[]) value));\n        else if (type.equals(\"int[][]\")) {\n            out.println(msg + \"=>\");\n            for (int i[] : (int[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"double[][]\")) {\n            out.println(msg + \"=>\");\n            for (double i[] : (double[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"float[][]\")) {\n            out.println(msg + \"=>\");\n            for (float i[] : (float[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"long[][]\")) {\n            out.println(msg + \"=>\");\n            for (long i[] : (long[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"char[][]\")) {\n            out.println(msg + \"=>\");\n            for (char i[] : (char[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"String[][]\")) {\n            out.println(msg + \"=>\");\n            for (String i[] : (String[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else out.println(msg + \" => \" + value);\n    }\n\n    public static void debug(Object value) {\n        File output = new File(\"output.txt\");\n        if (!output.exists()) return;\n        String type = value.getClass().getSimpleName();\n        if (type.equals(\"int[]\")) out.println(\" => \" + Arrays.toString((int[]) value));\n        else if (type.equals(\"double[]\")) out.println(\" => \" + Arrays.toString((double[]) value));\n        else if (type.equals(\"float[]\")) out.println(\" => \" + Arrays.toString((float[]) value));\n        else if (type.equals(\"long[]\")) out.println(\" => \" + Arrays.toString((long[]) value));\n        else if (type.equals(\"char[]\")) out.println(\" => \" + Arrays.toString((char[]) value));\n        else if (type.equals(\"String[]\")) out.println(\" => \" + Arrays.toString((String[]) value));\n        else if (type.equals(\"int[][]\")) {\n            out.println(\"=>\");\n            for (int i[] : (int[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"double[][]\")) {\n            out.println(\"=>\");\n            for (double i[] : (double[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"float[][]\")) {\n            out.println(\"=>\");\n            for (float i[] : (float[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"long[][]\")) {\n            out.println(\"=>\");\n            for (long i[] : (long[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"char[][]\")) {\n            out.println(\"=>\");\n            for (char i[] : (char[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else if (type.equals(\"String[][]\")) {\n            out.println(\"=>\");\n            for (String i[] : (String[][]) value)\n                out.println(\" . \" + Arrays.toString(i).replace(' ', '\\t'));\n        } else out.println(\" => \" + value);\n    }\n\n    // Graph Functions\n    public static void addUndirectedEdge(ArrayList<ArrayList<Integer>> adj, int u, int v) {\n        adj.get(u).add(v);\n        adj.get(v).add(u);\n    }\n\n    public static void addDirectedEdge(ArrayList<ArrayList<Integer>> adj, int u, int v) {\n        adj.get(u).add(v);\n    }\n\n    public static <T> void addUndirectedEdge(ArrayList<ArrayList<Point>> adj, int u, int v, T weight) {\n        adj.get(u).add(new Point(v, weight));\n        adj.get(v).add(new Point(u, weight));\n    }\n\n    public static <T> void addDirectedEdge(ArrayList<ArrayList<Point>> adj, int u, int v, T weight) {\n        adj.get(u).add(new Point(v, weight));\n    }\n\n    public static <T> void toString(String msg, ArrayList<ArrayList<T>> adj) {\n        out.println(msg + \":\");\n        int count = 0;\n        for (ArrayList<T> i : adj) {\n            out.print(\"\\t\" + count++ + \": \");\n            for (T j : i) {\n                out.print(j + \" \");\n            }\n            out.println();\n        }\n    }\n\n    public static void addUndirectedEdge(Map<Integer, ArrayList<Integer>> adj, int u, int v) {\n        if (adj.containsKey(u)) {\n            ArrayList<Integer> temp = adj.get(u);\n            temp.add(v);\n            adj.put(u, temp);\n        } else {\n            ArrayList<Integer> temp = new ArrayList<>();\n            temp.add(v);\n            adj.put(u, temp);\n        }\n        if (adj.containsKey(v)) {\n            ArrayList<Integer> temp = adj.get(v);\n            temp.add(u);\n            adj.put(v, temp);\n        } else {\n            ArrayList<Integer> temp = new ArrayList<>();\n            temp.add(u);\n            adj.put(v, temp);\n        }\n    }\n\n    public static void addDirectedEdge(Map<Integer, ArrayList<Integer>> adj, int u, int v) {\n        if (adj.containsKey(u)) {\n            ArrayList<Integer> temp = adj.get(u);\n            temp.add(v);\n            adj.put(u, temp);\n        } else {\n            ArrayList<Integer> temp = new ArrayList<>();\n            temp.add(v);\n            adj.put(u, temp);\n        }\n    }\n\n    public static <T> void addUndirectedEdge(Map<Integer, ArrayList<Point>> adj, int u, int v, T weight) {\n        if (adj.containsKey(u)) {\n            ArrayList<Point> temp = adj.get(u);\n            temp.add(new Point(v, weight));\n            adj.put(u, temp);\n        } else {\n            ArrayList<Point> temp = new ArrayList<>();\n            temp.add(new Point(v, weight));\n            adj.put(u, temp);\n        }\n        if (adj.containsKey(v)) {\n            ArrayList<Point> temp = adj.get(v);\n            temp.add(new Point(u, weight));\n            adj.put(v, temp);\n        } else {\n            ArrayList<Point> temp = new ArrayList<>();\n            temp.add(new Point(u, weight));\n            adj.put(v, temp);\n        }\n    }\n\n    public static <T> void addDirectedEdge(Map<Integer, ArrayList<Point>> adj, int u, int v, T weight) {\n        if (adj.containsKey(u)) {\n            ArrayList<Point> temp = adj.get(u);\n            temp.add(new Point(v, weight));\n            adj.put(u, temp);\n        } else {\n            ArrayList<Point> temp = new ArrayList<>();\n            temp.add(new Point(v, weight));\n            adj.put(u, temp);\n        }\n    }\n\n    public static <T> void toString(String msg, Map<T, ArrayList<T>> adj) {\n        out.println(msg + \":\");\n        for (Map.Entry<T, ArrayList<T>> entry : adj.entrySet()) {\n            out.println(\"\\t\" + entry.getKey() + \": \" + entry.getValue());\n        }\n    }\n\n    // GCD\n    public static int __gcd(int a, int b) {\n        BigInteger n1 = BigInteger.valueOf(a);\n        BigInteger n2 = BigInteger.valueOf(b);\n        BigInteger gcd = n1.gcd(n2);\n        return gcd.intValue();\n    }\n\n    public static long __gcd(long a, long b) {\n        BigInteger n1 = BigInteger.valueOf(a);\n        BigInteger n2 = BigInteger.valueOf(b);\n        BigInteger gcd = n1.gcd(n2);\n        return gcd.longValue();\n    }\n\n    public static void main(String args[]) throws IOException {\n        new Thread(null, new Main(), \"random\", 1 << 26).start();\n    }\n\n    @Override\n    public void run() {\n        long start = 0, end = 0;\n        try {\n            File output = new File(\"output.txt\");\n            sc = new FastReader();\n            if (output.exists()) {\n                out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n                start = System.nanoTime();\n            } else {\n                out = new PrintWriter(System.out);\n            }\n\n            int test_cases = 1;\n            if (test_case_input) test_cases = sc.nextInt();\n            for (int i = 1; i <= test_cases; i++) {\n                solution(i);\n            }\n            if (output.exists()) {\n                end = System.nanoTime();\n                out.println(\"Execution time: \" + (end - start) / 1000000 + \" ms\");\n            }\n            out.flush();\n            out.close();\n        } catch (Exception e) {\n            out.println(\"Exception: \" + e);\n            out.println(\"At Line no. : \" + e.getStackTrace()[0].getLineNumber());\n            out.flush();\n            out.close();\n            return;\n        }\n    }\n\n    // Edge Class\n    static class Edge implements Comparable<Edge> {\n        Object u;\n        Object v;\n        Object wt;\n\n        public Edge(Object origin, Object destination, Object weight) {\n            u = origin;\n            v = destination;\n            wt = weight;\n        }\n\n        public String toString() {\n            String ans = u + \" -> \" + v + \" : \" + wt;\n            return ans;\n        }\n\n        public int getIntOrigin() {\n            return (int) u;\n        }\n\n        public int getIntDestination() {\n            return (int) v;\n        }\n\n        public int getIntWeight() {\n            return (int) wt;\n        }\n\n        public long getLongOrigin() {\n            return (long) u;\n        }\n\n        public long getLongDestination() {\n            return (long) v;\n        }\n\n        public long getLongWeight() {\n            return (long) wt;\n        }\n\n        @Override\n        public int compareTo(Edge edge) {\n            if ((edge.u).getClass() == Long.class) return (((Long) this.wt).compareTo((Long) edge.wt));\n            else return (((Integer) this.wt).compareTo((Integer) edge.wt));\n        }\n    }\n\n    // Point Class\n    static class Point implements Comparable<Point> {\n        Object x;\n        Object y;\n\n        public Point(Object a, Object b) {\n            x = a;\n            y = b;\n        }\n\n        public int getIntX() {\n            return (int) x;\n        }\n\n        public int getIntY() {\n            return (int) y;\n        }\n\n        public long getLongX() {\n            return (long) x;\n        }\n\n        public long getLongY() {\n            return (long) y;\n        }\n\n        public int compareTo(Point obj) {\n            if (obj.x.equals(this.x)) {\n                if ((obj.y).getClass() == Long.class) return ((Long) this.y).compareTo((Long) obj.y);\n                else return ((Integer) this.y).compareTo((Integer) obj.y);\n            } else {\n                if ((obj.x).getClass() == Long.class) return ((Long) this.x).compareTo((Long) obj.x);\n                else return ((Integer) this.x).compareTo((Integer) obj.x);\n            }\n        }\n\n        public String toString() {\n            String ans = \"(\" + x + \", \" + y + \")\";\n            return ans;\n        }\n\n        @Override\n        public int hashCode() {\n            int hash = 7;\n            hash = 71 * hash + (int) this.x;\n            hash = 71 * hash + (int) this.y;\n            return hash;\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            if (obj == null) return false;\n            Point point = (Point) obj;\n            if (point.x.equals(this.x) && point.y.equals(this.y)) return true;\n            else return false;\n        }\n    }\n\n    // Fast IO\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastReader() throws FileNotFoundException {\n            File in = new File(\"input.txt\");\n            if (in.exists()) {\n                br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n            } else {\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 nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        float nextFloat() {\n            return Float.parseFloat(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[] intarr(int n) {\n            int a[] = new int[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = Integer.parseInt(next());\n            }\n            return a;\n        }\n\n        long[] longarr(int n) {\n            long a[] = new long[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = Long.parseLong(next());\n            }\n            return a;\n        }\n\n        float[] floatarr(int n) {\n            float a[] = new float[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = Float.parseFloat(next());\n            }\n            return a;\n        }\n\n        double[] doublearr(int n) {\n            double a[] = new double[n];\n            for (int i = 0; i < n; i++) {\n                a[i] = Double.parseDouble(next());\n            }\n            return a;\n        }\n\n\n        int[][] intmatrix(int row, int col) {\n            int a[][] = new int[row][col];\n            for (int i = 0; i < row; i++) {\n                for (int j = 0; j < col; j++) {\n                    a[i][j] = Integer.parseInt(next());\n                }\n            }\n            return a;\n        }\n\n        long[][] longmatrix(int row, int col) {\n            long a[][] = new long[row][col];\n            for (int i = 0; i < row; i++) {\n                for (int j = 0; j < col; j++) {\n                    a[i][j] = Long.parseLong(next());\n                }\n            }\n            return a;\n        }\n\n        float[][] floatmatrix(int row, int col) {\n            float a[][] = new float[row][col];\n            for (int i = 0; i < row; i++) {\n                for (int j = 0; j < col; j++) {\n                    a[i][j] = Float.parseFloat(next());\n                }\n            }\n            return a;\n        }\n\n        double[][] doublematrix(int row, int col) {\n            double a[][] = new double[row][col];\n            for (int i = 0; i < row; i++) {\n                for (int j = 0; j < col; j++) {\n                    a[i][j] = Double.parseDouble(next());\n                }\n            }\n            return a;\n        }\n\n        String nextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.arraycopy;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.copyOf;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tstatic class IntList {\n\n\t\tint data[] = new int[3];\n\t\tint size = 0;\n\n\t\tboolean isEmpty() {\n\t\t\treturn size == 0;\n\t\t}\n\n\t\tint size() {\n\t\t\treturn size;\n\t\t}\n\n\t\tint get(int index) {\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\treturn data[index];\n\t\t}\n\n\t\tvoid clear() {\n\t\t\tsize = 0;\n\t\t}\n\n\t\tvoid set(int index, int value) {\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\tdata[index] = value;\n\t\t}\n\n\t\tvoid expand() {\n\t\t\tif (size >= data.length) {\n\t\t\t\tdata = copyOf(data, (data.length << 1) + 1);\n\t\t\t}\n\t\t}\n\n\t\tvoid insert(int index, int value) {\n\t\t\tif (index < 0 || index > size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\texpand();\n\t\t\tarraycopy(data, index, data, index + 1, size++ - index);\n\t\t\tdata[index] = value;\n\t\t}\n\n\t\tint delete(int index) {\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\tint value = data[index];\n\t\t\tarraycopy(data, index + 1, data, index, --size - index);\n\t\t\treturn value;\n\t\t}\n\n\t\tvoid push(int value) {\n\t\t\texpand();\n\t\t\tdata[size++] = value;\n\t\t}\n\n\t\tint pop() {\n\t\t\tif (size == 0) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t\treturn data[--size];\n\t\t}\n\n\t\tvoid unshift(int value) {\n\t\t\texpand();\n\t\t\tarraycopy(data, 0, data, 1, size++);\n\t\t\tdata[0] = value;\n\t\t}\n\n\t\tint shift() {\n\t\t\tif (size == 0) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t\tint value = data[0];\n\t\t\tarraycopy(data, 1, data, 0, --size);\n\t\t\treturn value;\n\t\t}\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n\t\tIntList stack = new IntList();\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tstack.clear();\n\t\t\tint n = scanInt();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint v = scanInt();\n\t\t\t\tif (v == 1) {\n\t\t\t\t\tstack.push(v);\n\t\t\t\t} else {\n\t\t\t\t\twhile (stack.pop() != v - 1) { }\n\t\t\t\t\tstack.push(v);\n\t\t\t\t}\n\t\t\t\tfor (int j = 0; j < stack.size; j++) {\n\t\t\t\t\tif (j != 0) {\n\t\t\t\t\t\tout.print('.');\n\t\t\t\t\t}\n\t\t\t\t\tout.print(stack.data[j]);\n\t\t\t\t}\n\t\t\t\tout.println();\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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C {\n    static class Scan {\n        private byte[] buf=new byte[1024];\n        private int index;\n        private InputStream in;\n        private int total;\n        public Scan()\n        {\n            in=System.in;\n        }\n        public int scan()throws IOException\n        {\n            if(total<0)\n            throw new InputMismatchException();\n            if(index>=total)\n            {\n                index=0;\n                total=in.read(buf);\n                if(total<=0)\n                return -1;\n            }\n            return buf[index++];\n        }\n        public int scanInt()throws IOException\n        {\n            int integer=0;\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            int neg=1;\n            if(n=='-')\n            {\n                neg=-1;\n                n=scan();\n            }\n            while(!isWhiteSpace(n))\n            {\n                if(n>='0'&&n<='9')\n                {\n                    integer*=10;\n                    integer+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            return neg*integer;\n        }\n        public double scanDouble()throws IOException\n        {\n            double doub=0;\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            int neg=1;\n            if(n=='-')\n            {\n                neg=-1;\n                n=scan();\n            }\n            while(!isWhiteSpace(n)&&n!='.')\n            {\n                if(n>='0'&&n<='9')\n                {\n                    doub*=10;\n                    doub+=n-'0';\n                    n=scan();\n                }\n                else throw new InputMismatchException();\n            }\n            if(n=='.')\n            {\n                n=scan();\n                double temp=1;\n                while(!isWhiteSpace(n))\n                {\n                    if(n>='0'&&n<='9')\n                    {\n                        temp/=10;\n                        doub+=(n-'0')*temp;\n                        n=scan();\n                    }\n                    else throw new InputMismatchException();\n                }\n            }\n            return doub*neg;\n        }\n        public String scanString()throws IOException\n        {\n            StringBuilder sb=new StringBuilder();\n            int n=scan();\n            while(isWhiteSpace(n))\n            n=scan();\n            while(!isWhiteSpace(n))\n            {\n                sb.append((char)n);\n                n=scan();\n            }\n            return sb.toString();\n        }\n        private boolean isWhiteSpace(int n)\n        {\n            if(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n            return true;\n            return false;\n        }\n    }\n    \n    public static void sort(int arr[],int l,int r) {    //sort(arr,0,n-1);\n        if(l==r) {\n            return;\n        }\n        int mid=(l+r)/2;\n        sort(arr,l,mid);\n        sort(arr,mid+1,r);\n        merge(arr,l,mid,mid+1,r);\n    }\n    public static void merge(int arr[],int l1,int r1,int l2,int r2) {\n        int tmp[]=new int[r2-l1+1];\n        int indx1=l1,indx2=l2;\n        //sorting the two halves using a tmp array\n        for(int i=0;i<tmp.length;i++) {\n            if(indx1>r1) {\n                tmp[i]=arr[indx2];\n                indx2++;\n                continue;\n            }\n            if(indx2>r2) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            if(arr[indx1]<arr[indx2]) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            tmp[i]=arr[indx2];\n            indx2++;\n        }\n        //Copying the elements of tmp into the main array\n        for(int i=0,j=l1;i<tmp.length;i++,j++) {\n            arr[j]=tmp[i];\n        }\n    }\n    \n    public static void sort(long arr[],int l,int r) {    //sort(arr,0,n-1);\n        if(l==r) {\n            return;\n        }\n        int mid=(l+r)/2;\n        sort(arr,l,mid);\n        sort(arr,mid+1,r);\n        merge(arr,l,mid,mid+1,r);\n    }\n    public static void merge(long arr[],int l1,int r1,int l2,int r2) {\n        long tmp[]=new long[r2-l1+1];\n        int indx1=l1,indx2=l2;\n        //sorting the two halves using a tmp array\n        for(int i=0;i<tmp.length;i++) {\n            if(indx1>r1) {\n                tmp[i]=arr[indx2];\n                indx2++;\n                continue;\n            }\n            if(indx2>r2) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            if(arr[indx1]<arr[indx2]) {\n                tmp[i]=arr[indx1];\n                indx1++;\n                continue;\n            }\n            tmp[i]=arr[indx2];\n            indx2++;\n        }\n        //Copying the elements of tmp into the main array\n        for(int i=0,j=l1;i<tmp.length;i++,j++) {\n            arr[j]=tmp[i];\n        }\n    }\n\n    \n    public static void main(String args[]) throws IOException {\n        Scan input=new Scan();\n        StringBuilder ans=new StringBuilder(\"\");\n        int test=input.scanInt();\n        for(int tt=1;tt<=test;tt++) {\n            int n=input.scanInt();\n            \n            ArrayList<Integer> arrli[]=new ArrayList[n];\n            for(int i=0;i<n;i++) {\n                arrli[i]=new ArrayList<>();\n            }\n            \n            for(int i=0;i<n;i++) {\n                int tmp=input.scanInt();\n                if(i==0) {\n                    arrli[0].add(1);\n                    continue;\n                }\n                if(tmp==1) {\n                    for(int j=0;j<arrli[i-1].size();j++) {\n                        arrli[i].add(arrli[i-1].get(j));\n                    }\n                    arrli[i].add(tmp);\n                    continue;\n                }\n                int indx=-1;\n                for(int j=0;j<arrli[i-1].size();j++) {\n                    if(arrli[i-1].get(j)==tmp-1) {\n                        indx=j;\n                    }\n                }\n                for(int j=0;j<indx;j++) {\n                    arrli[i].add(arrli[i-1].get(j));\n                }\n                arrli[i].add(tmp);\n            }\n            for(int i=0;i<n;i++) {\n               for(int j=0;j<arrli[i].size();j++) {\n                   ans.append(arrli[i].get(j));\n                   if(j!=arrli[i].size()-1) {\n                       ans.append(\".\");\n                   }\n               }\n               ans.append(\"\\n\");\n            }\n        }\n        System.out.println(ans);\n    }\n    \n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class B{\n\tpublic static void main(String[] args)\n\t{\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint t = fs.nextInt();\n\t\tfor(int tt=0;tt<t;tt++)\n\t\t{\n\t\t\tint n = fs.nextInt();\n\t\t\tint[] arr = fs.readArray(n);\n\t\t\tList<String> ans = new ArrayList();\n\t\t\tList<Integer> temp = new ArrayList();\n\t\t\ttemp.add(arr[0]);\n\t\t\tans.add(\"\"+arr[0]);\n\t\t\tfor(int i=1;i<n;i++)\n\t\t\t{\n\t\t\t\tint ch = arr[i];\n\t\t\t\tif(ch == 1)\n\t\t\t\t{\n\t\t\t\t\ttemp.add(1);\n\t\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\t\tfor(int j=0;j<temp.size();j++)\n\t\t\t\t\t{\n\t\t\t\t\t\tsb.append(temp.get(j));\n\t\t\t\t\t\tif(j != temp.size()-1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsb.append('.');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans.add(sb.toString());\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint j = temp.size()-1;\n\t\t\t\t\twhile(j>=0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(ch - temp.get(j) == 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttemp.set(j,ch);\n\t\t\t\t\t\t\tbreak;\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\tj--;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint extra = temp.size()-1;\n\t\t\t\t\twhile(extra>j)\n\t\t\t\t\t{\n\t\t\t\t\t\ttemp.remove(temp.size()-1);\n\t\t\t\t\t\textra--;\n\t\t\t\t\t}\n\t\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\t\tfor(int jj=0;jj<temp.size();jj++)\n\t\t\t\t\t{\n\t\t\t\t\t\tsb.append(temp.get(jj));\n\t\t\t\t\t\tif(jj != temp.size()-1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsb.append('.');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans.add(sb.toString());\n\t\t\t\t}\n//\t\t\t\tout.println(\"Here: \"+temp);\n\t\t\t}\n\t\t\tfor(String str:ans)\n\t\t\t{\n\t\t\t\tout.println(str);\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\tpublic static int[] sort(int[] arr)\n\t{\n\t\tList<Integer> temp = new ArrayList();\n\t\tfor(int i:arr)temp.add(i);\n\t\tCollections.sort(temp);\n\t\tint start = 0;\n\t\tfor(int i:temp)arr[start++]=i;\n\t\treturn arr;\n\t}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Stack;\n\npublic class Main {\n\n    static void debug(Object... args) {\n        System.out.println(Arrays.deepToString(args));\n    }\n\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        int T = Integer.parseInt(br.readLine());\n        while (T-- > 0) {\n            int N = Integer.parseInt(br.readLine());\n            Stack<LN> nodes = new Stack<>();\n            int a0 = Integer.parseInt(br.readLine());\n            LN root = new LN(1, 0, \"\");\n            nodes.add(root);\n            pw.println(root);\n            for (int i = 0; i < N - 1; i++) {\n                int ai = Integer.parseInt(br.readLine());\n                while (!nodes.isEmpty()) {\n                    LN nn = nodes.pop();\n                    if (ai == 1) {\n                        LN e = new LN(1, nn.depth + 1, nn.toString());\n                        nodes.add(nn);\n                        nodes.add(e);\n                        pw.println(e);\n                        break;\n                    } else if (nn.lv == ai - 1) {\n                        LN e = new LN(ai, nn.depth, nn.base);\n                        nodes.add(e);\n                        pw.println(e);\n                        break;\n                    }\n                }\n            }\n        }\n        pw.flush();\n    }\n\n    static class LN {\n        int lv;\n        int depth;\n        String base;\n\n        public LN(int lv, int depth, String prev) {\n            this.lv = lv;\n            this.depth = depth;\n            base = prev;\n        }\n\n        @Override\n        public String toString() {\n            StringBuilder bob = new StringBuilder(base);\n            if (depth > 0) {\n                bob.append(\".\");\n            }\n            bob.append(lv);\n            return bob.toString();\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\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 = 2_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, \"_\", 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\n    static void solve() throws java.lang.Exception {\n        //initIo(true, \"\");\n        initIo(false, \"\");\n        StringBuilder sb = new StringBuilder();\n\n        int t = ni();\n        while (t-->0) {\n            int n = ni();\n            ArrayList<ArrayList<Integer>> ans = new ArrayList<>();\n            ArrayList<Integer> prev = new ArrayList<>();\n            prev.add(1);\n            ni();\n            for(int i=1;i<n;i++) {\n                int x = ni();\n                ans.add(prev);\n                ArrayList<Integer> next = new ArrayList<>();\n                int idx = -1;\n                for(int j=prev.size()-1;j>=0;--j) {\n                    if(prev.get(j)==x-1) {\n                        for(int k=0;k<j;++k) {\n                            next.add(prev.get(k));\n                        }\n                        next.add(x);\n                        idx = j;\n                        break;\n                    }\n                }\n\n                if(idx==-1) {\n                    assert_in_range(\"x\", x, 1, 1);\n                    for(int e : prev) {\n                        next.add(e);\n                    }\n                    next.add(1);\n                }\n                prev = next;\n            }\n\n            ans.add(prev);\n            for(ArrayList<Integer> list: ans) {\n                print(list);\n            }\n        }\n\n        pw.flush();\n        pw.close();\n    }\n\n    static void print(ArrayList<Integer> list) {\n        for(int i=0;i<list.size();i++) {\n            pw.print(list.get(i));\n            if(i==list.size()-1) {\n                continue;\n            }\n            pw.print(\".\");\n        }\n        pl();\n    }\n\n    static void assert_in_range(String varName, int n, int l, int r) {\n        if (n >=l && n<=r) return;\n        System.out.println(varName + \" is not in range. Actual: \"+n+\" l : \"+l+\" r: \"+r);\n        System.exit(1);\n    }\n    static void assert_in_range(String varName, long n, long l, long r) {\n        if (n>=l && n<=r) return;\n        System.out.println(varName + \" is not in range. Actual: \"+n+\" l : \"+l+\" r: \"+r);\n        System.exit(1);\n    }\n\n    static void initIo(boolean isFileIO, String suffix) throws IOException {\n        scan = new MyScanner(isFileIO, suffix);\n        if(isFileIO) {\n            pw = new PrintWriter(\"/Users/dsds/Desktop/output\"+suffix+\".txt\");\n        }\n        else {\n            pw = new PrintWriter(System.out, true);\n        }\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static String ne() throws IOException\n    {\n        return scan.next();\n    }\n    static String nel() throws IOException\n    {\n        return scan.nextLine();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n\n    static void pa(String arrayName, TreeSet<Integer> set)\n    {\n        pl(arrayName+\" : \");\n        for(Object o : set)\n            p(o);\n        pl();\n    }\n\n    static void pa(String arrayName, boolean arr[])\n    {\n        pl(arrayName+\" : \");\n        for(boolean o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, boolean[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(boolean o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class MyScanner\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        MyScanner(boolean readingFromFile, String suffix) throws IOException\n        {\n            if(readingFromFile) {\n                br = new BufferedReader(new FileReader(\"/Users/ddfds/Desktop/input\"+suffix+\".txt\"));\n            }\n            else {\n                br = new BufferedReader(new InputStreamReader(System.in));\n            }\n        }\n        String nextLine()throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner();\n\t\tint T = sc.nextInt();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(T-->0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tint[] arr = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = sc.nextInt();\n\t\t\t}\n\t\t\tint[] p = new int[n];\n\t\t\tint[] base = new int[n];\n\t\t\tp[0] = -1;\n\t\t\tbase[0] = -1;\n\t\t\tboolean[] used = new boolean[n];\n\t\t\tfor(int i = 1; i < n; i++) {\n\t\t\t\tif(arr[i] == 1) {\n\t\t\t\t\tp[i] = i-1;\n\t\t\t\t\tbase[i] = i-1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfor(int j = i-1; j >= 0; j--) {\n\t\t\t\t\t\tif(used[j]) continue;\n\t\t\t\t\t\tif(arr[j] == arr[i]-1) {\n\t\t\t\t\t\t\tp[i] = j; used[j] = true; \n\t\t\t\t\t\t\tbase[i] = base[j]; break;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse used[j] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tStringBuilder[] res = new StringBuilder[n];\n\t\t\tres[0] = new StringBuilder(\"1\");\n\t\t\tsb.append(\"1\\n\");\n\t\t\tfor(int i = 1; i < n; i++) {\n\t\t\t\tif(base[i] == -1) { \n\t\t\t\t\tres[i] = new StringBuilder();\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tres[i] = new StringBuilder(res[base[i]]);\n\t\t\t\t\tres[i].append(\".\");\n\t\t\t\t}\n\t\t\t\tres[i].append(arr[i]+\"\");\n\t\t\t\tsb.append(res[i]);\n\t\t\t\tsb.append(\"\\n\");\n\t\t\t}\n\t\t}\t\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(sb.toString().trim());\n\t\tpw.flush();\n\t}\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}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import javax.print.DocFlavor;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.Scanner;\nimport java.util.Stack;\n\npublic class p1523C {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int t = sc.nextInt();\n        for (int i = 0; i < t ; i++) {\n            int n = sc.nextInt();\n            ArrayList<Stack<Integer>> ar = new ArrayList<Stack<Integer>>();\n            for (int j = 0; j < n + 1; j++) {\n                ar.add(new Stack<Integer>());\n            }\n            HashMap <Integer , Integer> hm = new HashMap<Integer, Integer>();\n            StringBuilder cur = new StringBuilder();\n            int l = 0;\n            for (int j = 0; j < n; j++) {\n                int a = sc.nextInt();\n                if( a == 1)\n                {\n                    if(cur.length() == 0)\n                        cur.append(\"1\");\n                    else\n                        cur.append(\".1\");\n                    l++;\n                    ar.get(1).add(l);\n                    hm.put(l , 1);\n                }\n                else\n                {\n                    int newl = ar.get( a - 1).pop();\n                    for (int k = newl + 1; k <= l ; k++) {\n                        ar.get(hm.get(k)).pop();\n                        hm.remove(k);\n                        cur.delete(cur.lastIndexOf(\".\")  + 1, cur.length());\n                        cur.delete(cur.length() - 1 , cur.length());\n                    }\n                    cur.delete(cur.lastIndexOf(\".\")  + 1, cur.length());\n                    cur.append(a);\n                    ar.get(a).add(newl);\n                    hm.put(newl , a);\n                    l = newl;\n                }\n                System.out.println(cur);\n            }\n\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\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 */\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.List;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author is2ac\n */\npublic class C_CF {\n\n    public static void main(String[] args) {\n        FastScanner57 fs = new FastScanner57();\n        PrintWriter pw = new PrintWriter(System.out);\n        int t = fs.ni();\n        //int t = 1;\n        for (int tc = 0; tc < t; tc++) {\n            int n = fs.ni();\n            int[] q = new int[n+5];\n            int ind = 0;\n            q[0] = 1;\n            for (int i = 0; i < n; i++) {\n                int a = fs.ni();\n                while (q[ind]!=a) ind--;\n                StringBuilder sb = new StringBuilder();\n                for (int j = 0; j < ind; j++) {\n                    sb.append(q[j]-1);\n                    sb.append(\".\");\n                }\n                    sb.append(a);\n                    q[ind]++;\n                    q[ind+1] = 1;\n                    ind++;\n                    pw.println(sb);\n            }\n        }\n        pw.close();\n\n    }\n\n    static class BIT18 {\n\n        int[] bit;\n\n        public BIT18(int size) {\n            bit = new int[size];\n        }\n\n        public void update(int ind, int delta) {\n            while (ind < bit.length) {\n                bit[ind] += delta;\n                ind = ind + (ind & (-1 * ind));\n            }\n        }\n\n        public int sum(int ind) {\n            int s = 0;\n            while (ind > 0) {\n                s += bit[ind];\n                ind = ind - (ind & (-1 * ind));\n            }\n            return s;\n        }\n\n        public int query(int l, int r) {\n            return sum(r) - sum(l);\n        }\n    }\n\n    // 0 -> left was chosen\n    // 1 -> right was chosen\n    public static long recur(int ind, int p, int prev, long[] v, Long[][] dp, long[][] lr, List<List<Integer>> list) {\n\n        long last = v[0];\n        long ls = 0L;\n        long rs = 0L;\n        if (p == 1) {\n            last = v[1];\n        }\n        if (ind != 0) {\n            ls += (long) Math.abs(last - lr[ind][0]);\n        }\n        if (ind != 0) {\n            rs += (long) Math.abs(last - lr[ind][1]);\n        }\n        if (dp[ind][p] != null) {\n            return dp[ind][p];\n        }\n        long[] cur = lr[ind];\n\n        List<Integer> temp = list.get(ind);\n        for (int val : temp) {\n            if (prev == val) {\n                continue;\n            }\n            ls += recur(val, 0, ind, cur, dp, lr, list);\n            rs += recur(val, 1, ind, cur, dp, lr, list);\n        }\n        return dp[ind][p] = Math.max(ls, rs);\n    }\n\n    public static void sort(long[] a) {\n        List<Long> list = new ArrayList();\n        for (int i = 0; i < a.length; i++) {\n            list.add(a[i]);\n        }\n        Collections.sort(list);\n        for (int i = 0; i < a.length; i++) {\n            a[i] = list.get(i);\n        }\n    }\n\n    public static long gcd(long n1, long n2) {\n        if (n2 == 0) {\n            return n1;\n        }\n        return gcd(n2, n1 % n2);\n    }\n\n}\n\nclass UnionFind16 {\n\n    int[] id;\n\n    public UnionFind16(int size) {\n        id = new int[size];\n        for (int i = 0; i < size; i++) {\n            id[i] = i;\n        }\n    }\n\n    public int find(int p) {\n        int root = p;\n        while (root != id[root]) {\n            root = id[root];\n        }\n        while (p != root) {\n            int next = id[p];\n            id[p] = root;\n            p = next;\n        }\n        return root;\n    }\n\n    public void union(int p, int q) {\n        int a = find(p), b = find(q);\n        if (a == b) {\n            return;\n        }\n        id[b] = a;\n    }\n}\n\nclass FastScanner57 {\n\n    BufferedReader br;\n    StringTokenizer st;\n\n    public FastScanner57() {\n        br = new BufferedReader(new InputStreamReader(System.in), 32768);\n        st = null;\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    int[] intArray(int N) {\n        int[] ret = new int[N];\n        for (int i = 0; i < N; i++) {\n            ret[i] = ni();\n        }\n        return ret;\n    }\n\n    long nl() {\n        return Long.parseLong(next());\n    }\n\n    long[] longArray(int N) {\n        long[] ret = new long[N];\n        for (int i = 0; i < N; i++) {\n            ret[i] = nl();\n        }\n        return ret;\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", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    private static HashMap<String, Integer> nodes;\n    private static void dfs(String cur, PrintWriter out) {\n        if(cur.length() > 0) {\n            out.println(cur.substring(1));\n        }\n        int children = nodes.get(cur);\n        for(int i = 1; i <= children; i++) {\n            dfs(cur+\".\"+i, out);\n        }\n    }\n    public static void main(String[] args) throws IOException {\n        //Scanner f = new Scanner(new File(\"uva.in\"));\n        //Scanner f = new Scanner(System.in);\n        //BufferedReader f = new BufferedReader(new FileReader(\"uva.in\"));\n        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int t = Integer.parseInt(f.readLine());\n        while(t-- > 0) {\n            int n = Integer.parseInt(f.readLine());\n            nodes = new HashMap<>();\n            nodes.put(\"\", 0);\n            String cur = \"\";\n            for(int i = 0; i < n; i++) {\n                int a = Integer.parseInt(f.readLine());\n                while(nodes.get(cur) != a-1) {\n                    cur = cur.substring(0, cur.lastIndexOf(\".\"));\n                }\n                nodes.put(cur, a);\n                cur = cur+\".\"+a;\n                nodes.put(cur, 0);\n            }\n            dfs(\"\", out);\n        }\n        f.close();\n        out.close();\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\n/**\n* @author: Prasad Chaudhari\n* @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/\n* @git: https://github.com/Prasad-Chaudhari\n*/\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.LinkedList;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        FastIO in = new FastIO(args);\n        int t = in.ni();\n        while (t-- > 0) {\n            int n = in.ni();\n            LinkedList<Integer> l = new LinkedList<>();\n            ArrayList<LinkedList<Integer>> al = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                int p = in.ni();\n                if (p == 1) {\n                    l.addFirst(1);\n                } else {\n                    while (true) {\n                        if (l.peekFirst() == p - 1) {\n                            l.addFirst(l.removeFirst() + 1);\n                            break;\n                        } else {\n                            l.removeFirst();\n                        }\n                    }\n                }\n                al.add(new LinkedList<>(l));\n            }\n            for (LinkedList<Integer> ll : al) {\n                while (ll.size() > 1) {\n                    System.out.print(ll.removeLast() + \".\");\n                }\n                System.out.println(ll.remove());\n            }\n            System.out.println();\n        }\n        in.bw.flush();\n    }\n\n    static boolean willbealive(int i, int a[]) {\n        if (i < 0 || i >= a.length)\n            return false;\n        if (a.length == 1)\n            return false;\n        if (a[i] == 1)\n            return false;\n        if (i == 0)\n            return a[1] == 1;\n        else if (i == a.length - 1)\n            return a[i - 1] == 1;\n        else\n            return (a[i - 1] == 1) ^ (a[i + 1] == 1);\n    }\n\n    static class Data implements Comparable<Data> {\n\n        int a, b;\n\n        public Data(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public int compareTo(Data o) {\n            if (a == o.a) {\n                return Integer.compare(b, o.b);\n            }\n            return Integer.compare(a, o.a);\n        }\n\n        public static void sort(int a[]) {\n            Data d[] = new Data[a.length];\n            for (int i = 0; i < a.length; i++) {\n                d[i] = new Data(a[i], 0);\n            }\n            Arrays.sort(d);\n            for (int i = 0; i < a.length; i++) {\n                a[i] = d[i].a;\n            }\n        }\n    }\n\n    static class FastIO {\n\n        private final BufferedReader br;\n        private final BufferedWriter bw;\n        private String s[];\n        private int index;\n\n        public FastIO(String[] args) throws IOException {\n            if (args.length > 1) {\n                br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(args[0]))));\n                bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(args[1]))));\n            } else {\n                br = new BufferedReader(new InputStreamReader(System.in));\n                bw = new BufferedWriter(new OutputStreamWriter(System.out, \"UTF-8\"));\n            }\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] = nl();\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] = nl();\n            }\n            return a;\n        }\n\n        public void print(String s) throws IOException {\n            bw.write(s);\n        }\n\n        public void println(String s) throws IOException {\n            bw.write(s);\n            bw.newLine();\n        }\n\n        public void print(int s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(int s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\n        }\n\n        public void print(long s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(long s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\n        }\n\n        public void print(double s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(double s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\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", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {    \n    static void deal(int n,int[] arr) {\n        int[] a = new int[n];\n        a[0] = 1;\n        int l = 1;\n        out.println(toString(a,l));\n        for(int i=1;i<n;i++) {\n            if(arr[i] == 1) {\n                a[l] = 1;\n                l++;\n            } else {\n                int index = l-1;\n                while(index>=0 && a[index] != arr[i]-1) {\n                    index--;\n                }\n                a[index]++;\n                l = index+1;\n            }\n            out.println(toString(a,l));\n        }\n    }\n    \n    static String toString(int[] arr,int l) {\n        StringBuilder sb = new StringBuilder();\n        for(int i=0;i<l-1;i++) {\n            sb.append(arr[i]);\n            sb.append('.');\n        }\n        sb.append(arr[l-1]);\n        return sb.toString();\n    }\n    \n\tpublic static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n        int t = sc.nextInt();\n        for(int i=0;i<t;i++) {\n            int n = sc.nextInt();\n            int[] arr = new int[n];\n            for(int j=0;j<n;j++) arr[j] = sc.nextInt();\n            deal(n,arr);\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        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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C\n{\n\n\tstatic FastIO f;\n\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tf = new FastIO();\n\n\t\tint t, n, a, i;\n\t\tNode r, p, c;\n\t\t\n\t\tt = f.ni();\n\t\t\n\t\twhile(t-->0)\n\t\t{\n\t\t\tn = f.ni();\n\t\t\tr = p = new Node(-1, null);\n\t\t\t// f.out(\"1\\n\");\n\n\t\t\tfor(i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\ta = f.ni();\n\t\t\t\tif(a != 1)\n\t\t\t\t{\n\t\t\t\t\twhile(a != p.i + 1)\n\t\t\t\t\t\tp = p.p;\n\t\t\t\t\tp = p.p;\n\t\t\t\t}\n\t\t\t\t// if(a == p.i + 1)\n\t\t\t\t// \tp = p.p;\n\t\t\t\t// else if(p.p != null && a == p.p.i + 1)\n\t\t\t\t// \tp = p.p.p;\n\t\t\t\tc = new Node(a, p);\n\t\t\t\tp.c.add(c);\n\t\t\t\tp = c;\n\t\t\t}\n\n\t\t\tdfs(r, \"\");\n\t\t}\n\n\t\tf.flush();\n\t}\n\n\tpublic  static void dfs(Node n, String s) throws IOException\n\t{\n\t\tString t;\n\n\t\tif(n.i == -1)\n\t\t\tt = s;\n\t\telse\n\t\t{\n\t\t\tt = s + n.i + \".\";\n\t\t\tf.out(s + n.i + \"\\n\");\n\t\t}\n\n\t\tfor(Node c : n.c)\n\t\t\tdfs(c, t);\n\t}\n\n\tstatic class Node\n\t{\n\t\tint i;\n\t\tNode p;\n\t\tArrayList<Node> c;\n\t\n\t\tNode(int x, Node y)\n\t\t{\n\t\t\ti = x;\n\t\t\tp = y;\n\t\t\tc = new ArrayList<>();\n\t\t}\n\t\n\t\t@Override\n\t\tpublic int hashCode()\n\t\t{\n\t\t\treturn super.hashCode();\n\t\t}\n\t\n\t\t@Override\n\t\tpublic boolean equals(Object obj)\n\t\t{\n\t\t\tNode that = (Node)obj;\n\t\n\t\t\treturn super.equals(obj);\n\t\t}\n\t\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"[\" + \"PARAMETERS\" + \"]\";\n\t\t}\n\t}\n\n\tpublic static class FastIO\n\t{\n\t\tBufferedReader br;\n\t\tBufferedWriter bw, be;\n\t\tStringTokenizer st;\n\n\t\tpublic FastIO()\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tbw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\tbe = new BufferedWriter(new OutputStreamWriter(System.err));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tprivate void read() throws IOException\n\t\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t}\n\n\t\tpublic String ns() throws IOException\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t\tread();\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int ni() throws IOException\n\t\t{\n\t\t\treturn Integer.parseInt(ns());\n\t\t}\n\n\t\tpublic long nl() throws IOException\n\t\t{\n\t\t\treturn Long.parseLong(ns());\n\t\t}\n\n\t\tpublic float nf() throws IOException\n\t\t{\n\t\t\treturn Float.parseFloat(ns());\n\t\t}\n\n\t\tpublic double nd() throws IOException\n\t\t{\n\t\t\treturn Double.parseDouble(ns());\n\t\t}\n\n\t\tpublic char nc() throws IOException\n\t\t{\n\t\t\treturn ns().charAt(0);\n\t\t}\n\n\t\tpublic int[] nia(int n) throws IOException\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\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nla(int n) throws IOException\n\t\t{\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\ta[i] = nl();\n\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[] nca() throws IOException\n\t\t{\n\t\t\treturn ns().toCharArray();\n\t\t}\n\n\t\tpublic void out(String s) throws IOException\n\t\t{\n\t\t\tbw.write(s);\n\t\t}\n\n\t\tpublic void flush() throws IOException\n\t\t{\n\t\t\tbw.flush();\n\t\t\tbe.flush();\n\t\t}\n\n\t\tpublic void err(String s) throws IOException\n\t\t{\n\t\t\tbe.write(s);\n\t\t}\n\t}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n public class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastIO io = new FastIO();\n\t\tint test=io.nextInt();\n\t\twhile(test>0)\n\t\t{\n\t\t    int n=io.nextInt();\n\t\t    int arr[]=new int[n];\n\t\t    for(int i=0;i<n;i++)arr[i]=io.nextInt();\n\t\t    List<int[]> list=new ArrayList<>();\n\t\t    Stack<int[]> stk=new Stack<>();\n\t\t    int temp[]={1};\n\t\t    list.add(temp);\n\t\t    stk.push(temp);\n\t\t    for(int i=1;i<n;i++)\n\t\t    {\n\t\t        if(arr[i]==1)\n\t\t        {\n\t\t            int t[]=stk.peek();\n\t\t            int nt[]=new int[t.length+1];\n\t\t            for(int j=0;j<t.length;j++)nt[j]=t[j];\n\t\t            nt[nt.length-1]=arr[i];\n\t\t            stk.push(nt);\n\t\t            list.add(nt);\n\t\t            continue;\n\t\t        }\n\t\t        while(stk.size()>0)\n\t\t        {\n\t\t            int t[]=stk.peek();\n\t\t            if(t[t.length-1]+1==arr[i]){\n\t\t                int nt[]=new int[t.length];\n\t\t                for(int j=0;j<t.length-1;j++)nt[j]=t[j];\n\t\t                nt[t.length-1]=arr[i];\n\t\t                stk.pop();\n\t\t                stk.push(nt);\n\t\t                list.add(nt);\n\t\t                break;\n\t\t            }\n\t\t            else\n\t\t            {\n\t\t                stk.pop();\n\t\t            }\n\t\t        }\n\t\t    }\n\t\t    for(int i=0;i<list.size();i++)\n\t\t    {\n\t\t        StringBuilder sb=new StringBuilder();\n\t\t        sb.append(list.get(i)[0]);\n\t\t        for(int j=1;j<list.get(i).length;j++)\n\t\t        {\n\t\t            sb.append(\".\"+list.get(i)[j]);\n\t\t        }\n\t\t        io.println(sb.toString());\n\t\t    }\n\t\t    test--;\n\t\t}\n\t\tio.close();\n\t}\n}\n \n class FastIO extends PrintWriter {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1<<16];\n\tprivate int curChar, numChars;\n \n\t// standard input\n\tpublic FastIO() { this(System.in,System.out); }\n\tpublic FastIO(InputStream i, OutputStream o) {\n\t\tsuper(o);\n\t\tstream = i;\n\t}\n\t// file input\n\tpublic FastIO(String i, String o) throws IOException {\n\t\tsuper(new FileWriter(o));\n\t\tstream = new FileInputStream(i);\n\t}\n \n\t// throws InputMismatchException() if previously detected end of file\n\tprivate int nextByte() {\n\t\tif (numChars == -1) throw 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 == -1) return -1; // end of file\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n \n\tpublic String nextLine() {\n\t\tint c; do { c = nextByte(); } while (c <= '\\n');\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo { res.appendCodePoint(c); c = nextByte(); } while (c > '\\n');\n\t\treturn res.toString();\n\t}\n \n\tpublic String next() {\n\t\tint c; do { c = nextByte(); } while (c <= ' ');\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo { res.appendCodePoint(c); c = nextByte(); } while (c > ' ');\n\t\treturn res.toString();\n\t}\n \n\tpublic int nextInt() { \n\t\tint c; do { c = nextByte(); } while (c <= ' ');\n\t\tint sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); }\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*res+c-'0';\n\t\t\tc = nextByte();\n\t\t} while (c > ' ');\n\t\treturn res * sgn;\n\t}\n \n  public long nextLong() { \n\t\tint c; do { c = nextByte(); } while (c <= ' ');\n\t\tlong sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); }\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*res+c-'0';\n\t\t\tc = nextByte();\n\t\t} while (c > ' ');\n\t\treturn res * sgn;\n\t}\n \n\tpublic double nextDouble() { return Double.parseDouble(next()); }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C{\n\n\tprivate static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\n\tpublic static void main (String[] args) throws IOException {\n        int t = Integer.parseInt(br.readLine());\n        while(t-- > 0) {\n            int n = Integer.parseInt(br.readLine());\n            int prev = 1;\n            ArrayList<Integer> nums = new ArrayList<>();\n            nums.add(1);\n            String till = \"1\";\n            for(int i=0;i<n;i++) {\n                int ln = Integer.parseInt(br.readLine());\n                if(i == 0) {\n                    bw.write(\"1\\n\");\n                    continue;\n                }\n                if(ln == 1) {\n                    nums.add(1);\n                }else if(ln == prev + 1) {\n                    nums.set(nums.size()-1, ln);\n                }else {\n                    int idx = -1;\n                    for(int j=nums.size()-1;j>=0;j--) {\n                        if(nums.get(j) == ln-1) {\n                            idx = j;\n                            break;\n                        }\n                    }\n                    ArrayList<Integer> temp = new ArrayList<>();\n                    for(int j=0;j<idx;j++) {\n                        temp.add(nums.get(j));\n                    }\n                    temp.add(ln);\n                    nums.clear();\n                    nums = temp;\n                }\n                for(int j=0;j<nums.size()-1;j++) {\n                    bw.write(nums.get(j) + \".\");\n                }\n                bw.write(nums.get(nums.size()-1) + \"\\n\");\n                prev = ln;\n            }\n            \n        }\n        bw.flush();\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.util.Map.Entry;\n\n\nimport java.io.*;\nimport java.math.*;\nimport static java.util.stream.Collectors.*;\nimport static java.util.Map.Entry.*;\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 Exception\n\t{\n\t\tfinal long mod=(long) (1e9+7);  \n\t\tfinal long mod1=(long) 998244353;\n\t\tReader s=new Reader();\n\t\t  PrintWriter pt=new PrintWriter(System.out);\n\t\t  \n\t\t  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t  int T=s.nextInt();\n//\t\t  int T=Integer.parseInt(br.readLine());\n//\t\t  int T=1;\n\t\t  while(T-->0)\n\t\t  {\n\t\t\t  int n=s.nextInt();\n\t\t\t  int arr[]=new int[n];\n\t\t\t  int brr[]=new int[n];\n\t\t\t  int e=-1;\n\t\t\t  for(int i=0;i<n;i++) {\n\t\t\t\t  arr[i]=s.nextInt();\n\t\t\t\t  if(e==-1) {\n\t\t\t\t\t  brr[e+1]=arr[i];\n\t\t\t\t\t  e++;\n\t\t\t\t  }\n\t\t\t\t  else {\n\t\t\t\t\t  if(arr[i]==1) {\n\t\t\t\t\t\t  e++;\n\t\t\t\t\t\t  brr[e]=arr[i];\n\t\t\t\t\t  }\n\t\t\t\t\t  else {\n\t\t\t\t\t\t  int j=e;\n\t\t\t\t\t\t  for(j=e;j>=0;j--) {\n\t\t\t\t\t\t\t  if((arr[i]-1)==brr[j])\n\t\t\t\t\t\t\t\t  break;\n\t\t\t\t\t\t  }\n\t\t\t\t\t\t  e=j;\n\t\t\t\t\t\t  brr[e]=arr[i];\n\t\t\t\t\t  }\n\t\t\t\t  }\n\t\t\t\t  pt.print(brr[0]);\n\t\t\t\t  for(int j=1;j<=e;j++) {\n\t\t\t\t\t  pt.print(\".\"+brr[j]);\n\t\t\t\t  }\n\t\t\t\t  pt.println();\n\t\t\t  }\n\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\t\t  \n\t\t      \n\t\t  \n\t\t  pt.close();\n\t}\n\t\n\tstatic boolean allOne(String str) {\n\t\tfor(int i=0;i<str.length();i++) {\n\t\t\tif(str.charAt(i)=='0')\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n    \n\t\n\tstatic boolean isPartition(int arr[], int n) {\n\t\tint sum = 0;\n\t    int i, j;\n\t \n\t    // Calculate sum of all elements\n\t    for (i = 0; i < n; i++)\n\t        sum += arr[i];\n\t \n\t    if (sum % 2 != 0)\n\t        return false;\n\t \n\t    boolean part[][]=new boolean[sum/2+1][n+1];\n\t \n\t    // initialize top row as true\n\t    for (i = 0; i <= n; i++)\n\t        part[0][i] = true;\n\t \n\t    // initialize leftmost column, except part[0][0], as false\n\t    for (i = 1; i <= sum / 2; i++)\n\t        part[i][0] = false;\n\t \n\t    // Fill the partition table in bottom up manner\n\t    for (i = 1; i <= sum / 2; i++) {\n\t        for (j = 1; j <= n; j++) {\n\t            part[i][j] = part[i][j - 1];\n\t            if (i >= arr[j - 1])\n\t                part[i][j] = part[i][j]\n\t                             || part[i - arr[j - 1]][j - 1];\n\t        }\n\t    }\n\t    return part[sum / 2][n];\n\t}\n\t\n\tstatic int setBit(int S, int j) { return S | 1 << j; }\n\n\tstatic int clearBit(int S, int j) { return S & ~(1 << j); }\n\n\tstatic int toggleBit(int S, int j) { return S ^ 1 << j; }\n\n\tstatic boolean isOn(int S, int j) { return (S & 1 << j) != 0; }\n\n\tstatic int turnOnLastZero(int S) { return S | S + 1; }\n\t\n\tstatic int turnOnLastConsecutiveZeroes(int S) { return S | S - 1; }\n\t\n\tstatic int turnOffLastBit(int S) { return S & S - 1; }\n\t\n\tstatic int turnOffLastConsecutiveBits(int S) { return S & S + 1; }\n\n\tstatic int lowBit(int S) { return S & -S; }\n\n\tstatic int setAll(int N) { return (1 << N) - 1; }\n\n\tstatic int modulo(int S, int N) { return (S & N - 1); }\t\t //S%N, N is a power of 2\n\n\tstatic boolean isPowerOfTwo(int S) { return (S & S - 1) == 0; }\n\t\n\tstatic boolean isWithin(long x, long y, long d, long k) {\n\t\treturn x*k*x*k + y*k*y*k <= d*d;\n\t}\n\t\n\tstatic long modFact(long n, \n            long p) \n\t{ \n\t\tif (n >= p) \n\t\t return 0; \n\t\t\n\t\tlong result = 1; \n\t\tfor (int i = 1; i <= n; i++) \n\t\t result = (result * i) % p; \n\t\t\n\t\treturn result; \n\t} \n\tstatic int sum(int[] arr, int n)\n\t{\n\t    int inc[]=new int[n+1];\n\t    int dec[]=new int[n+1];\n\t    inc[0] = arr[0];\n\t    dec[0] = arr[0];\n\n\t    for (int i = 1; i < n; i++) {\n\t        for (int j = 0; j < i; j++) {\n\t            if (arr[j] > arr[i]) {\n\t                dec[i] = max(dec[i], inc[j] + arr[i]);\n\t            }\n\t            else if (arr[i] > arr[j]) {\n\t                inc[i] = max(inc[i], dec[j] + arr[i]);\n\t            }\n\t        }\n\t    }\n\t    return max(inc[n - 1], dec[n - 1]);\n\t}\n\tstatic long nc2(long a) {\n\t\treturn a*(a-1)/2;\n\t}\n\tpublic static int numberOfprimeFactors(int n) \n    { \n        // Print the number of 2s that divide n \n\t\tHashSet<Integer> hs = new HashSet<Integer>();\n        while (n%2==0) \n        { \n            hs.add(2);\n            n /= 2; \n        } \n  \n        // n must be odd at this point.  So we can \n        // skip one element (Note i = i +2) \n        for (int i = 3; i <= Math.sqrt(n); i+= 2) \n        { \n            // While i divides n, print i and divide n \n            while (n%i == 0) \n            { \n                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            hs.add(n);\n        return hs.size();\n    } \n\tstatic long gcd(long a, long b) \n    { \n      if (b == 0) \n        return a; \n      return gcd(b, a % b);  \n    } \n\n\n\n\n\t\n\n\tstatic void reverse(int arr[],int start, int end) \n\t{ \n\t\tint temp; \n\t\t   \n\t\twhile (start < end) \n\t\t{ \n\t\t    temp = arr[start];  \n\t\t    arr[start] = arr[end]; \n\t\t    arr[end] = temp; \n\t\t    start++; \n\t\t    end--; \n\t\t}  \n\t}  \n\tstatic void reverse(long arr[],int start, int end) \n\t{ \n\t\tlong temp; \n\t\t   \n\t\twhile (start < end) \n\t\t{ \n\t\t    temp = arr[start];  \n\t\t    arr[start] = arr[end]; \n\t\t    arr[end] = temp; \n\t\t    start++; \n\t\t    end--; \n\t\t}  \n\t}  \n\tstatic boolean isPrime(int n) \n    { \n        // Corner cases \n        if (n <= 1) return false; \n        if (n <= 3) return true; \n      \n        // This is checked so that we can skip  \n        // middle five numbers in below loop \n        if (n % 2 == 0 || n % 3 == 0) return false; \n      \n        for (int i = 5; i * i <= n; i = i + 6) \n            if (n % i == 0 || n % (i + 2) == 0) \n            return false; \n      \n        return true; \n    } \n\tstatic int p2(int n) {\n\t\tint k=0;\n\t\twhile(n>1) {\n\t\t\tif(n%2!=0)\n\t\t\t\treturn k;\n\t\t\tn/=2;\n\t\t\tk++;\n\t\t}\n\t\treturn k;\n\t}\n\tstatic boolean isp2(int n) {\n\t\twhile(n>1) {\n\t\t\tif(n%2==1)\n\t\t\t\treturn false;\n\t\t\tn/=2;\n\t\t}\n\t\treturn true;\n\t}\n\tstatic int binarySearch(int arr[], int first, int last, int key){  \n\t\t   int mid = (first + last)/2;  \n\t\t   while( first <= last ){  \n\t\t      if ( arr[mid] < key ){  \n\t\t        first = mid + 1;     \n\t\t      }else if ( arr[mid] == key ){  \n\t\t        return mid;  \n\t\t      }else{  \n\t\t         last = mid - 1;  \n\t\t      }  \n\t\t      mid = (first + last)/2;  \n\t\t   }  \n\t\t   return -1;\n\t\t }  \n\n\tstatic void print(int a[][]) {\n\t\tfor(int i=0;i<a.length;i++)\n\t\t{\n\t\t\tfor(int j=0;j<a[0].length;j++)\n\t\t\t\tSystem.out.print(a[i][j]+\" \");\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\tstatic int max (int x, int y) {\n\t\treturn (x > y)? x : y;\n\t} \n\tstatic int search(Pair[] p, Pair pair) {\n\t\tint l=0, r=p.length;\n\t\twhile (l <= r) { \n\t        int m = l + (r - l) / 2;\n\t        if (p[m].compareTo(pair)==0) \n\t            return m; \n\t        if (p[m].compareTo(pair)<0) \n\t            l = m + 1; \n\t        else\n\t            r = m - 1;\n\t    }\n\t    return -1;\n\t}\n\tstatic void pa(int a[])\n\t{\n\t\tfor(int i=0;i<a.length;i++)\n\t\t\tSystem.out.print(a[i]+\" \");\n\t\tSystem.out.println();\n\t\t\n\t}\n\tstatic void pa(long a[])\n\t{\n\t\tfor(int i=0;i<a.length;i++)\n\t\t\tSystem.out.print(a[i]+\" \");\n\t\tSystem.out.println();\n\t\t\n\t}\n\tstatic void reverseArray(int arr[], \n            int start, int end) \n\t{ \n\t\tint temp; \n\t\t   \n\t\twhile (start < end) \n\t\t{ \n\t\t    temp = arr[start];  \n\t\t    arr[start] = arr[end]; \n\t\t    arr[end] = temp; \n\t\t    start++; \n\t\t    end--; \n\t\t}  \n\t}     \n\tstatic boolean isPalindrome(String s) {\n\t\tint l=s.length();\n\t\tfor(int i=0;i<l/2;i++)\n\t\t{\n\t\t\tif(s.charAt(i)!=s.charAt(l-i-1))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\tstatic long nc2(long n, long m) {\n\t\treturn (n*(n-1)/2)%m;\n\t}\n\tstatic long c(long a) {\n\t\treturn a*(a+1)/2;\n\t}\n\tstatic int next(long[] arr, long target)  \n    {  \n        int start = 0, end = arr.length - 1;  \n    \n        int ans = -1;  \n        while (start <= end) {  \n            int mid = (start + end) / 2;  \n    \n            // Move to right side if target is  \n            // greater.  \n            if (arr[mid] < target) {\n                start = mid + 1;  \n            }  \n    \n            // Move left side.  \n            else {  \n                ans = mid;  \n                end = mid - 1;  \n            }  \n        }  \n        return ans;  \n    } \n\t\n\tstatic int prev(long[] arr, long target)  \n    {  \n        int start = 0, end = arr.length - 1;  \n    \n        int ans = -1;  \n        while (start <= end) {  \n            int mid = (start + end) / 2;  \n    \n            // Move to left side if target is  \n            // lesser.  \n            if (arr[mid] > target) {\n                end = mid - 1;  \n            }  \n    \n            // Move right side.  \n            else {  \n                ans = mid;  \n                start = mid + 1;  \n            }  \n        }  \n        return ans;  \n    } \n\n\tstatic long power(long x, long y, long p) \n    { \n        long res = 1; \n        x = x % p; \n                      \n        while (y > 0) \n        { \n            if (y % 2 == 1) \n                res = (res * x) % p; \n            y = y >> 1;\n            x = (x * x) % p; \n        } \n        return  res; \n    } \n    static long modInverse(long n, long p) \n    { \n        return power(n, p-2, p); \n    } \n    static long nCrModP(long n, long r, \n                                    long p) \n    { \n        if(r>n)\n        \treturn 0;\n    \tif (r == 0) \n            return 1; \n        long[] fac = new long[(int) (n+1)]; \n        fac[0] = 1; \n        for (int i = 1 ;i <= n; i++) \n            fac[i] = fac[i-1] * i % p;\n        return (fac[(int) n]* modInverse(fac[(int) r], p) \n                % p * modInverse(fac[(int) (n-r)], p) \n                                    % p) % p; \n    } \n\tstatic String reverse(String str)\n\t{\n\t\treturn new StringBuffer(str).reverse().toString();\n\t}\n\n\n\n\tstatic long fastpow(long x, long y, long m)  \n    { \n        if (y == 0) \n            return 1; \n          \n        long p = fastpow(x, y / 2, m) % m; \n        p = (p * p) % m; \n      \n        if (y % 2 == 0) \n            return p; \n        else\n            return (x * p) % m; \n    } \n\t\n\tstatic boolean isPerfectSquare(long l)\n\t{\n\t\treturn Math.pow((long)Math.sqrt(l),2)==l;\n\t}\n\t\n\t\n\tstatic void merge(long[] arr, int l, int m, int r) \n    { \n        // Find sizes of two subarrays to be merged \n        int n1 = m - l + 1; \n        int n2 = r - m; \n  \n        /* Create temp arrays */\n        long L[] = new long [n1]; \n        long R[] = new long [n2]; \n  \n        /*Copy data to temp arrays*/\n        for (int i=0; i<n1; ++i) \n            L[i] = arr[l + i]; \n        for (int j=0; j<n2; ++j) \n            R[j] = arr[m + 1+ j]; \n  \n  \n        /* Merge the temp arrays */\n  \n        // Initial indexes of first and second subarrays \n        int i = 0, j = 0; \n  \n        // Initial index of merged subarry array \n        int k = l; \n        while (i < n1 && j < n2) \n        { \n            if (L[i] <= R[j]) \n            { \n                arr[k] = L[i]; \n                i++; \n            } \n            else\n            { \n                arr[k] = R[j]; \n                j++; \n            } \n            k++; \n        } \n  \n        /* Copy remaining elements of L[] if any */\n        while (i < n1) \n        { \n            arr[k] = L[i]; \n            i++; \n            k++; \n        } \n  \n        /* Copy remaining elements of R[] if any */\n        while (j < n2) \n        { \n            arr[k] = R[j]; \n            j++; \n            k++; \n        } \n    } \n  \n    // Main function that sorts arr[l..r] using \n    // merge() \n    static void sort(int arr[], int l, int r) \n    { \n        if (l < r) \n        { \n            // Find the middle point \n            int m = (l+r)/2; \n  \n            // Sort first and second halves \n            sort(arr, l, m); \n            sort(arr , m+1, r); \n  \n            // Merge the sorted halves \n            merge(arr, l, m, r); \n        } \n    } \n\tstatic void merge(int arr[], int l, int m, int r) \n    { \n        // Find sizes of two subarrays to be merged \n        int n1 = m - l + 1; \n        int n2 = r - m; \n  \n        /* Create temp arrays */\n        int L[] = new int [n1]; \n        int R[] = new int [n2]; \n  \n        /*Copy data to temp arrays*/\n        for (int i=0; i<n1; ++i) \n            L[i] = arr[l + i]; \n        for (int j=0; j<n2; ++j) \n            R[j] = arr[m + 1+ j]; \n  \n  \n        /* Merge the temp arrays */\n  \n        // Initial indexes of first and second subarrays \n        int i = 0, j = 0; \n  \n        // Initial index of merged subarry array \n        int k = l; \n        while (i < n1 && j < n2) \n        { \n            if (L[i] <= R[j]) \n            { \n                arr[k] = L[i]; \n                i++; \n            } \n            else\n            { \n                arr[k] = R[j]; \n                j++; \n            } \n            k++; \n        } \n  \n        /* Copy remaining elements of L[] if any */\n        while (i < n1) \n        { \n            arr[k] = L[i]; \n            i++; \n            k++; \n        } \n  \n        /* Copy remaining elements of R[] if any */\n        while (j < n2) \n        { \n            arr[k] = R[j]; \n            j++; \n            k++; \n        } \n    } \n  \n    // Main function that sorts arr[l..r] using \n    // merge() \n    static void sort(long arr[], int l, int r) \n    { \n        if (l < r) \n        { \n            // Find the middle point \n            int m = (l+r)/2; \n  \n            // Sort first and second halves \n            sort(arr, l, m); \n            sort(arr , m+1, r); \n  \n            // Merge the sorted halves \n            merge(arr, l, m, r); \n        } \n    } \n    static class Pair implements Comparable<Pair>{\n        int a;\n        int b;\n        Pair(int a,int b){\n            this.a=a;\n \n            this.b=b;\n        }   \n        public int compareTo(Pair p){\n            if(a>p.a)\n                return 1;\n            if(a==p.a)\n                return (b-p.b);\n            return -1;\n        }\n    }\n\tstatic class Reader \n    { \n        final private int BUFFER_SIZE = 1 << 16; \n        private DataInputStream din; \n        private byte[] buffer; \n        private int bufferPointer, bytesRead; \n  \n        public Reader() \n        { \n            din = new DataInputStream(System.in); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public Reader(String file_name) throws IOException \n        { \n            din = new DataInputStream(new FileInputStream(file_name)); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public String readLine() throws IOException \n        { \n            byte[] buf = new byte[128]; // 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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Deltix {\n    static PrintWriter out;\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n        int t = sc.nextInt();\n        while (t-- > 0) {\n            int n = sc.nextInt();\n            Stack<Integer> s = new Stack<>();\n            int [] a = new int[n];\n            for (int i = 0; i < n; ++i) a[i] = sc.nextInt();\n            for (int i = 0; i < n; i++) {\n                if (a[i] == 1) {\n                    s.push(1);\n                } else {\n                    while (s.peek() != a[i] - 1) {\n                        s.pop();\n                    }\n                    s.pop();\n                    s.push(a[i]);\n                }\n                print(s);\n            }\n        }\n        out.close();\n    }\n\n    static void print(Stack<Integer> s) {\n        ArrayDeque<Integer> a = new ArrayDeque<>();\n        while (!s.isEmpty()) {\n            a.addFirst(s.pop());\n        }\n        while (!a.isEmpty()) {\n            int x = a.pollFirst();\n            out.print(x);\n            s.push(x);\n            if (a.size() != 0) out.print(\".\");\n        }\n        out.println();\n    }\n\n\n    static void sort(int[] a) {\n        ArrayList<Integer> q = new ArrayList<>();\n        for (int i : a) q.add(i);\n        Collections.sort(q);\n        for (int i = 0; i < a.length; i++) a[i] = q.get(i);\n    }\n\n    static void sort(long[] a) {\n        ArrayList<Long> q = new ArrayList<>();\n        for (long i : a) q.add(i);\n        Collections.sort(q);\n        for (int i = 0; i < a.length; i++) a[i] = q.get(i);\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}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\npublic class Main{\n    static class FastScanner {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(\"\");\n\n        String next() {\n            while (!st.hasMoreTokens())\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        int[] nextArray(int n) {\n            int[] a = new int[n];\n            for (int i = 0; i < n; i++) a[i] = nextInt();\n            return a;\n        }\n        long[] nextArray(long n) {\n            long[] a = new long[(int) n];\n            for (int i = 0; i < n; i++) a[i] = nextLong();\n            return a;\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n    static class FastWriter extends PrintWriter {\n        FastWriter(){\n            super(System.out);\n        }\n        void println(int[] array) {\n            for(int i=0; i<array.length; i++) {\n                print(array[i]+\" \");\n            }\n            println();\n        }\n        void println(long [] array) {\n            for(int i=0; i<array.length; i++) {\n                print(array[i]+\" \");\n            }\n            println();\n        }\n    }\n    static class Interval {\n        long start,end;\n        Interval(long start, long end)\n        {\n            this.start=start;\n            this.end=end;\n        }\n    }\n    static int MOD=998244353;\n    public static void main(String[] args){\n        FastScanner in = new FastScanner();\n        FastWriter out = new FastWriter();\n        Scanner sc=new Scanner(System.in);\n        int t=in.nextInt();\n        //int t=1;\n        while (t-->0){\n            int n=in.nextInt();\n            int[] ar=in.nextArray(n);\n            int[] level=new int[1005];\n            int j=1;\n            level[1]=1;\n            out.println(1);\n            for (int i = 1; i < n; i++) {\n                if(ar[i]==1) {\n                    j++;\n                    level[j] = 1;\n                }else {\n                    while (j>=1){\n                        if(level[j]+1!=ar[i]){\n                            j--;\n                        }else {\n                            break;\n                        }\n                    }\n                    level[j]++;\n                }\n                for (int k = 1; k <= j; k++) {\n                    if(k==j){\n                        out.print(level[k]);\n                    }else {\n                        out.print(level[k]+\".\");\n                    }\n                }\n                out.println();\n            }\n        }\n        out.close();\n    }\n    static int highestPowerOf2(int n) {\n        if (n < 1){ return 0; }\n        int res = 1;\n        for (int i = 0; i < 8 * Integer.BYTES; i++) {\n            int curr = 1 << i;\n            if (curr > n){ break; }\n            res = curr;\n        }\n        return res;\n    }\n    static int reduceFraction(int x, int y) {\n        int d= gcd(x, y);\n        return x/d+y/d;\n    }\n    static boolean subset(int[] ar,int n,int sum){\n        if(sum==0){\n            return true;\n        }\n        if(n<0||sum<0){\n            return false;\n        }\n        return subset(ar,n-1,sum)||subset(ar,n-1,sum-ar[n]);\n    }\n    static boolean isPrime(int n){\n        if(n<=1) return false;\n        for(int i = 2;i<=Math.sqrt(n);i++){\n            if (n % i == 0) return false;\n        }\n        return true;\n    }\n    static int gcd(int a, int b) {\n        if (b == 0) return a;\n        return gcd(b, a % b);\n    }\n    static long gcd(long a, long b) {\n        if (b == 0) return a;\n        return gcd(b, a % b);\n    }\n    static long lcm(long a, long b) {\n        return (a * b) / gcd(a, b);\n    }\n    static int lcm(int a, int b) {\n        return (a * b) / gcd(a, b);\n    }\n    static boolean isPowerOfTwo(int n) {\n        if(n==0||n==1){return false;}\n        double v = Math.log(n) / Math.log(2);\n        return ((int)(Math.ceil(v)) == (int)(Math.floor(v)));\n    }\n    static boolean isPerfectSquare(int x){\n        if (x >= 0) {\n            int sr = (int)Math.sqrt(x);\n            return ((sr * sr) == x);\n        }\n        return false;\n    }\n    static int lower_bound(int[] arr, int x) {\n        int low_limit = 0, high_limit = arr.length, mid = -1;\n        while (low_limit < high_limit) {\n            mid = (low_limit + high_limit) / 2;\n            if (arr[mid] >= x){\n                high_limit = mid;\n            }else{\n                low_limit = mid + 1;\n            }\n        }\n        return low_limit;\n    }\n    static int upper_bound(int[] arr, int x) {\n        int low_limit = 0, high_limit = arr.length, mid = -1;\n        while (low_limit < high_limit) {\n            mid = (low_limit + high_limit) / 2;\n            if (arr[mid] > x){\n                high_limit = mid;\n            }else{\n                low_limit = mid + 1;\n            }\n        }\n        return low_limit;\n    }\n    static int binarySearch(int[] ar,int n,int num){\n        int low=0,high=n-1;\n        while (low<=high){\n            int mid=(low+high)/2;\n            if(ar[mid]==num){\n                return mid;\n            }else if(ar[mid]>num){\n                high=mid-1;\n            }else {\n                low=mid+1;\n            }\n        }\n        return -1;\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "//make sure to make new file!\nimport java.io.*;\nimport java.util.*;\n\npublic class CDS2021{\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      int t = Integer.parseInt(f.readLine());\n      \n      for(int q = 1; q <= t; q++){\n\n         int n = Integer.parseInt(f.readLine());\n      \n         int[] array = new int[n];\n         for(int k = 0; k < n; k++){\n            array[k] = Integer.parseInt(f.readLine());\n         }\n         \n         StringJoiner sj = new StringJoiner(\"\\n\");\n         Stack<Entry> stack = new Stack<Entry>();\n         \n         //first element should be 1\n         sj.add(\"1\");\n         stack.push(new Entry(\"1\",1));\n         \n         for(int k = 1; k < n; k++){\n            if(array[k] == 1){\n               //add new depth\n               String s = stack.peek().s + \".1\";\n               sj.add(s);\n               stack.push(new Entry(s,1));\n            } else {\n               while(!stack.isEmpty() && stack.peek().last != array[k]-1){\n                  stack.pop();\n               }\n               \n               if(stack.isEmpty()) break;             //shouldn't happen\n               \n               String s = \"\";\n               int index = stack.peek().s.lastIndexOf(\".\");\n               if(index == -1) s = \"\" + array[k];\n               else s = stack.peek().s.substring(0,index+1) + array[k];\n               sj.add(s);\n               stack.pop();\n               stack.push(new Entry(s,array[k]));\n            }\n         }\n         \n         out.println(sj.toString());\n      }\n      \n      \n      \n      \n      out.close();\n   }\n   \n   public static class Entry{\n      String s;\n      int last;\n      public Entry(String a, int b){\n         s = a;\n         last = b;\n      }\n   }\n      \n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        for (int i = 0, t = sc.nextInt(); i < t; i++) {\n            int n = sc.nextInt();\n            LinkedList<Set<Integer>> stack = new LinkedList<>();\n            for (int j = 0; j < n; j++) {\n                printStack(stack);\n                int val = sc.nextInt();\n                if (val == 1) {\n                    Set<Integer> branch = new HashSet<>();\n                    branch.add(val);\n                    stack.push(branch);\n                    continue;\n                }\n                Set<Integer> branch = stack.peek();\n                assert branch != null;\n                while (branch.contains(val) || branch.stream().max(Integer::compareTo).get() + 1 != val) {\n                    stack.pop();\n                    branch = stack.peek();\n                }\n                branch.add(val);\n            }\n            printStack(stack);\n        }\n    }\n\n    public static void printStack(LinkedList<Set<Integer>> stack) {\n        if (stack.size() == 0) {\n            return;\n        }\n        StringBuilder sb = new StringBuilder();\n        for (int i = stack.size() - 1; i >= 0; i--) {\n            sb.append(stack.get(i).stream().max(Integer::compareTo).get()).append(\".\");\n        }\n        System.out.println(sb.substring(0, sb.length() - 1));\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n/*\n1\n4\n1\n1\n2\n3\n */\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tint T=fs.nextInt();\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tfor (int tt=0; tt<T; tt++) {\n\t\t\tint n=fs.nextInt();\n\t\t\tint[] a=fs.readArray(n);\n\t\t\tint[] stack=new int[n];\n\t\t\tint size=0;\n\t\t\tfor (int i:a) {\n\t\t\t\tif (i==1) {\n\t\t\t\t\tstack[size++]=i;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\twhile (stack[size-1]!=i-1) {\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t}\n\t\t\t\t\tsize--;\n\t\t\t\t\tstack[size++]=i;\n\t\t\t\t}\n\t\t\t\tfor (int j=0; j<size; j++) {\n\t\t\t\t\tout.print(stack[j]);\n\t\t\t\t\tif (j!=size-1) out.print('.');\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t\t\n//\t\t\tint[] mapTo=new int[n];\n//\t\t\tArrays.fill(mapTo, -1);\n//\t\t\tArrayDeque<Integer>[] occsOf=new ArrayDeque[1001];\n//\t\t\tfor (int i=0; i<occsOf.length; i++) occsOf[i]=new ArrayDeque<>();\n//\t\t\tint lastOne=-1;\n//\t\t\t\n//\t\t\tfor (int i=0; i<n; i++) {\n//\t\t\t\tif (a[i]==1) {\n//\t\t\t\t\tmapTo[i]=lastOne;\n//\t\t\t\t\tlastOne=i;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tfor (int value=2; value<occsOf.length; value++) {\n//\t\t\t\tfor (int i:occsOf[value]) {\n//\t\t\t\t\tint mapsTo=occsOf[value-1].removeFirst();\n//\t\t\t\t\tmapTo[i]=mapsTo;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tSystem.out.println(Arrays.toString(mapTo));\n//\t\t\tfor (int i=0; i<n; i++) {\n//\t\t\t\tArrayList<Integer> listBackwards=new ArrayList<>();\n//\t\t\t\tlistBackwards.add(a[i]);\n//\t\t\t\tint at=i;\n//\t\t\t\twhile (true) {\n////\t\t\t\t\tSystem.out.println(\"x\");\n//\t\t\t\t\tif (mapTo[at]==-1) {\n//\t\t\t\t\t\tbreak;\n//\t\t\t\t\t}\n//\t\t\t\t\tif (a[mapTo[at]]!=a[at]-1) {\n//\t\t\t\t\t\tlistBackwards.add(a[mapTo[at]]);\n//\t\t\t\t\t}\n//\t\t\t\t\tat=mapTo[at];\n//\t\t\t\t}\n//\t\t\t\tfor (int j=listBackwards.size()-1; j>=0; j--) {\n//\t\t\t\t\tout.print(listBackwards.get(j));\n//\t\t\t\t\tif (j!=0) out.print('.');\n//\t\t\t\t}\n//\t\t\t\tout.println();\n//\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tArrayList<Integer> l=new ArrayList<>();\n\t\tfor (int i:a) l.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i=0; i<a.length; i++) a[i]=l.get(i);\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i<n; i++) a[i]=nextInt();\n\t\t\treturn a;\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\t\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.TimeUnit;\n\npublic class c1523 implements Runnable{\n\t\n    public static void main(String[] args) {\n    \ttry{\n            new Thread(null, new c1523(), \"process\", 1<<26).start();\n        }\n        catch(Exception e){\n            System.out.println(e);\n        }\n    }\n\tpublic void run() {\n\t\tFastReader scan = new FastReader();\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t//PrintWriter out = new PrintWriter(\"file.out\");\n\t\tTask solver = new Task();\n\t\tint t = scan.nextInt();\n\t\t//int 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\t\tstatic final int oo = Integer.MAX_VALUE;\n\t\tstatic final long OO = Long.MAX_VALUE;\n\n\t\tpublic void solve(int testNumber, FastReader sc, PrintWriter out) {\n\t\t\tint N = sc.nextInt();\n\t\t\tint[] arr = sc.readArray(N);\n\t\t\t\n\t\t\tStack<Integer> cur = new Stack<>();\n\t\t\tStringBuilder sb = new StringBuilder(\"\");\n\t\t\tfor(int i = 0; i < N; i++) {\n\t\t\t\tif(arr[i] == 1) {\n\t\t\t\t\tcur.add(1);\n\t\t\t\t} else {\n\t\t\t\t\twhile(cur.peek() != arr[i] - 1)\n\t\t\t\t\t\tcur.pop();\n\t\t\t\t\tcur.pop();\n\t\t\t\t\tcur.add(arr[i]);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor(int each: cur) {\n\t\t\t\t\tsb.append(each + \".\");\n\t\t\t\t}\n\t\t\t\tsb.deleteCharAt(sb.length()-1);\n\t\t\t\tsb.append(\"\\n\");\n\t\t\t}\n\t\t\t\n\t\t\tout.println(sb);\n\t\t}\n\t\t\n\t}\n\tstatic long modInverse(long N, long MOD) {\n\t\treturn binpow(N, MOD - 2, MOD);\n\t}\n\tstatic long modDivide(long a, long b, long MOD) {\n\t\ta %= MOD;\n\t\treturn (binpow(b, MOD-2, MOD) * a) % MOD;\n\t}\n\tstatic long binpow(long a, long b, long m) {\n\t\ta %= m;\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) == 1)\n\t\t\t\tres = res * a % m;\n\t\t\ta = a * a % m;\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic int[] reverse(int a[]) \n    { \n        int[] b = new int[a.length]; \n        for (int i = 0, j = a.length; i < a.length; i++, j--) { \n            b[j - 1] = a[i]; \n        } \n        \n        return b;\n    }\n\tstatic long[] reverse(long a[]) \n    { \n        long[] b = new long[a.length]; \n        for (int i = 0, j = a.length; i < a.length; i++, j--) { \n            b[j - 1] = a[i]; \n        } \n        \n        return b;\n    }\n\t\n\tstatic void shuffle(Object[] 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\tObject temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\t\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(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\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\t\n\tstatic class tup implements Comparable<tup>, Comparator<tup>{\n\t\tint a, b;\n\t\ttup(int a,int b){\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t}\n\t\tpublic tup() {\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(tup o){\n\t\t\treturn Integer.compare(b,o.b);\n\t\t}\n\t\t@Override\n\t\tpublic int compare(tup o1, tup o2) {\n\t\t\treturn Integer.compare(o1.b, o2.b);\n\t\t}\n\t\t\n\t\t@Override\n\t    public int hashCode() {\n\t\t\treturn Objects.hash(a, b);\n\t    }\n \n\t    @Override\n\t    public boolean equals(Object obj) {\n\t    \tif (this == obj)\n                return true;\n\t    \tif (obj == null)\n                return false;\n\t    \tif (getClass() != obj.getClass())\n                return false;\n\t    \ttup other = (tup) obj;\n\t    \treturn a==other.a && b==other.b;\n\t    }\n\t    \n\t    @Override\n\t    public String toString() {\n\t    \treturn a + \" \" + b;\n\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\t\n\t\tint[] readArray(int size) {\n\t\t\tint[] a = new int[size];\n\t\t\tfor(int i = 0; i < size; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\tlong[] readLongArray(int size) {\n\t\t\tlong[] a = new long[size];\n\t\t\tfor(int i = 0; i < size; i++) {\n\t\t\t\ta[i] = nextLong();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t}\n\t\n\tstatic void dbg(int[] arr) {\n\t\tSystem.out.println(Arrays.toString(arr));\n\t}\n\tstatic void dbg(long[] arr) {\n\t\tSystem.out.println(Arrays.toString(arr));\n\t}\n\tstatic void dbg(boolean[] arr) {\n\t\tSystem.out.println(Arrays.toString(arr));\n\t}\n\n\tstatic void dbg(Object... args) {\n        for (Object arg : args)\n            System.out.print(arg + \" \");\n        System.out.println();\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Stack;\n\npublic class C{\n    public static void main(String args[])\n    {\n        Scanner sc=new Scanner(System.in);\n        long mod=1000000007l;\n        int cases=sc.nextInt();\n\n\n        while(cases>0)\n        {\n            cases--;\n            Stack<Integer> stack=new Stack<>();\n\n            int n=sc.nextInt();\n\n            for(int j=0;j<n;j++)\n            {\n                int x=sc.nextInt();\n                if(x==1)\n                {\n                    stack.add(1);\n                }\n                else\n                {\n                    int p=stack.pop();\n                    if(p==x-1)\n                    {\n                        stack.add(x);\n                    }\n                    else {\n                        while (p != x-1) {\n                            p = stack.pop();\n                        }\n\n                        stack.add(x);\n\n                    }\n\n                }\n                StringBuilder f=new StringBuilder();\n                Stack<Integer> temp=new Stack<>();\n\n                while(stack.isEmpty()==false)\n                {\n                    temp.add(stack.pop());\n                }\n\n                while(temp.isEmpty()==false)\n                {\n                    int z=temp.pop();\n                    f.append(z+\".\");\n                    stack.add(z);\n                }\n\n\n                System.out.println(f.substring(0,f.length()-1));\n\n            }\n\n        }\n\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author dauom\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    CCompressionAndExpansion solver = new CCompressionAndExpansion();\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 CCompressionAndExpansion {\n    public final void solve(int testNumber, InputReader in, PrintWriter out) {\n      int n = in.nextInt();\n\n      ArrayList<ArrayList<Integer>> ans = new ArrayList<>();\n      ArrayList<Integer> start = new ArrayList<>();\n      start.add(in.nextInt());\n      ans.add(start);\n      out.println(\"1\");\n      for (int i = 1; i < n; i++) {\n        ArrayList<Integer> lastList = ans.get(ans.size() - 1);\n        ArrayList<Integer> curList = (ArrayList<Integer>) lastList.clone();\n        ans.add(curList);\n\n        int curLast = in.nextInt();\n        for (int j = lastList.size() - 1; j >= 0; j--) {\n          int last = lastList.get(j);\n          if (curLast == 1) {\n            curList.add(1);\n            break;\n          } else if (curLast == last + 1) {\n            curList.set(j, curLast);\n            break;\n          } else {\n            curList.remove(j);\n          }\n        }\n        for (int j = 0; j < curList.size(); j++) {\n          if (j > 0) out.print(\".\");\n          out.print(curList.get(j));\n        }\n        out.println();\n      }\n    }\n\n  }\n\n  static final class InputReader {\n    private final InputStream stream;\n    private final byte[] buf = new byte[1 << 18];\n    private int curChar;\n    private int numChars;\n\n    public InputReader() {\n      this.stream = System.in;\n    }\n\n    public InputReader(final InputStream stream) {\n      this.stream = stream;\n    }\n\n    private int read() {\n      if (this.numChars == -1) {\n        throw new UnknownError();\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 ex) {\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 final 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) { // 45 == '-'\n        sgn = -1;\n        c = this.read();\n      }\n\n      int res = 0;\n\n      while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'\n        res *= 10;\n        res += c - 48; // 48 == '0'\n        c = this.read();\n        if (isSpaceChar(c)) {\n          return res * sgn;\n        }\n      }\n\n      throw new InputMismatchException();\n    }\n\n    public final String next() {\n      int c;\n      while (isSpaceChar(c = this.read())) {\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    private static boolean isSpaceChar(final int c) {\n      return c == 32 || c == 10 || c == 13 || c == 9\n          || c == -1; // 32 == ' ', 10 == '\\n', 13 == '\\r', 9 == '\\t'\n    }\n\n  }\n}\n\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.BigInteger;\npublic class Main{\n    static InputReader sc;\n    static PrintWriter pw;\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        sc = new InputReader(inputStream);\n        pw = new PrintWriter(outputStream);\n        solve();\n        pw.close();\n    }\n    // static int L,R,top,bottom;\n    // static int cnt,edge;\n    // static long ans;\n    static int time;\n    // static boolean isIsland;\n    static BigInteger min(BigInteger a, BigInteger b){        \n        if(a.compareTo(b)<0)\n            return a;\n        return b;\n    }\n    public static void solve(){        \n        int t=1;\n        t=s(0);\n        u:while(t-->0){\n            int n=s(0);\n            int []arr=new int [n];\n            feedArr(arr);\n            Stack<Pair> stk=new Stack<>();\n            stk.push(new Pair(\"\",1));\n            pln(1);\n            Pair pr;\n            for(int i=1;i<n;i++){\n                if(arr[i]==1){\n                    pr=stk.peek();\n                    stk.push(new Pair(pr.s+(pr.s.length()==0?\"\":\".\")+pr.i,1));\n                    pln(stk.peek().s+\".\"+stk.peek().i);\n                }\n                else if(stk.peek().i==arr[i]-1){\n                    pr=stk.pop();\n                    pln(pr.s+(pr.s.length()==0?\"\":\".\")+arr[i]);\n                    pr.i++;\n                    stk.push(pr);\n                }\n                else{\n                    stk.pop();\n                    i--;\n                }\n            }\n        }        \n    }        \n    static long fact(long p){\n        long ans=1l;\n        for(long i=2;i<=p;i++)\n            ans*=i;\n        return ans;\n    }    \n    static int find(int j, List<Integer> B, List<Integer> A, int i){\n        // System.out.println(\"Hi\");\n        int l=j,r=B.size()-1,m;        \n        while(l<=r){\n            m=(r-l)/2+l;\n            if(A.size()-i-1<=B.size()-m-1)\n                l=m+1;\n            else\n                r=m-1;\n        }\n        // System.out.println(\"Bye\");\n        return r;\n    }\n    static int find2(List<Integer> B, int x){\n        int l=0,r=B.size()-1,m;\n        // System.out.println(\"Hi2\");\n        // System.out.println(j);\n        while(l<=r){            \n            m=(r-l)/2+l;\n            // System.out.println(m);\n            if(B.get(m)-x<=0)\n                l=m+1;\n            else\n                r=m-1;\n        }\n        // System.out.println(\"Bye2\");\n        return r;        \n    }\n    static long nPr(long n, long r){\n        long ans=1;\n        for(long i=1;i<=r;i++)\n            ans*=(n-i+1);\n        return ans;\n    }\n    static long nCr(long n, long r){\n        long ans=1;\n        for(long i=1;i<=r;i++){\n            ans*=(n-i+1);\n            ans/=i;\n        }\n        return ans;\n    }\n    static void update_DAG(int cur,int val, int []graph, int n)\n    {\n        if(val>maxx[cur])\n        {\n            int x=graph[cur];\n            if(x!=-1)\n                update_DAG(x,val+1,graph,n);\n            maxx[cur]=val;\n            update(cur,val,n);\n        }\n    }\n    static int []bit, maxx;\n    static void update(int i,int val, int n)\n    {\n        while(i<=n)\n        {\n            bit[i]=Math.max(bit[i],val);\n            i=i+(i&(-i));\n        }\n    }\n    static int query(int i)\n    {\n        int ret=0;\n        while(i>0)\n        {\n            ret=Math.max(ret,bit[i]);\n            i=i-(i&(-i));\n        }\n        return ret;\n    }    \n    public static int [][]dir=new int [][]{{1,0},{0,1},{-1,0},{0,-1}};        \n    public static int find(List<Integer> list, int x){\n        int l=0,r=list.size()-1,m;\n        while(l<=r){\n            m=(r-l)/2+l;\n            if(list.get(m)<=x)\n                l=m+1;\n            else\n                r=m-1;\n        }\n        return r;\n    } \n    static class Node{\n        int val;\n        long cost;\n        Node next;\n        Node(int v,long c){\n            val=v;\n            next=null;\n            cost=c;\n        }\n    }    \n    public static long sum(long n){\n        long val=0l;\n        while(n>0){\n            val+=n%10;\n            n/=10;\n        }\n        return val;\n    }\n    // static class Node{\n    //     int left,right;\n    //     Node prev,next;\n    //     Node(int i, int v){\n    //         left=i;\n    //         right=v;\n    //         prev=next=null;\n    //     }\n    //     void remove(){\n    //         this.prev.next=this.next;\n    //         this.next.prev=this.prev;\n    //     }\n    //     void insert(Node node){\n    //         node.next=this;\n    //         node.prev=this.prev;\n    //         node.prev.next=node;\n    //         this.prev=node;\n    //     }\n    // } \n    public static int  findDiameter(int r, List<List<Integer>>list){\n        return findFarthest(findFarthest(r,list)[0],list)[1];\n    }\n    public static int[] findFarthest(int u, List<List<Integer>>list){\n        int n=list.size();\n        boolean []vis=new boolean[n+1];\n        Queue<Integer>q=new LinkedList<>();\n        q.offer(u);\n        vis[u]=true;\n        int s,pr,cnt=0;\n        int []ar=new int[]{u,0};\n        while(q.size()>0){\n            s=q.size();\n            while(s-->0){\n                pr=q.poll();\n                if(ar[1]<cnt){\n                    ar[1]=cnt;\n                    ar[0]=pr;\n                }\n                for(int i:list.get(pr)){\n                    if(!vis[i]){\n                        vis[i]=true;\n                        q.offer(i);\n                    }\n                }\n            }\n            cnt++;\n        }\n        return ar;\n    }\n    public static long atMostK(char []chrr, int k){\n        if(k<0)\n            return 0;\n        int l=0,cnt=0;\n        long ans=0l;\n        for(int i=0;i<chrr.length;i++){\n            if(chrr[i]=='1')\n                cnt++;\n            while(cnt>k){\n                if(chrr[l++]=='1')\n                    cnt--;\n            }\n            ans+=(long)(i-l)+1l;\n        }\n        return ans;\n    }\n    public static int ask(int l, int r){\n        System.out.println(\"? \"+l+\" \"+r);\n        System.out.flush();\n        return sc.nextInt();\n    }\n    public static void sort(int []arr){\n        ArrayList<Integer> list=new ArrayList<>();\n        for(int i=0;i<arr.length;i++)\n            list.add(arr[i]);\n        Collections.sort(list);\n        for(int i=0;i<arr.length;i++)\n            arr[i]=list.get(i);\n    }\n    public static void sort(long []arr){\n        ArrayList<Long> list=new ArrayList<>();\n        for(int i=0;i<arr.length;i++)\n            list.add(arr[i]);\n        Collections.sort(list);\n        for(int i=0;i<arr.length;i++)\n            arr[i]=list.get(i);\n    }\n    public static void swap(char []chrr, int i, int j){\n        char temp=chrr[i];\n        chrr[i]=chrr[j];\n        chrr[j]=temp;\n    }\n    public static int countSetBits(long n){\n        int a=0;\n        while(n>0){\n            a+=(n&1);\n            n>>=1;\n        }\n        return a;\n    }\n    static class Pair{\n        String s;\n        int i;\n        Pair(String S, int I){\n            s=S;\n            i=I;\n        }\n     //*\n    }\n    /*/\n        public int compareTo(Pair p){\n            return (b-p.b);\n        }\n        public int hashCode(){\n            int hashcode = (a+\" \"+b).hashCode();\n            return hashcode;\n        }\n        public boolean equals(Object obj){\n            if (obj instanceof Pair) {\n                Pair p = (Pair) obj;\n                return (p.a==this.a && p.b == this.b);\n            }\n            return false;\n        }\n    }\n    //*/\n    static boolean isPrime(long n) { \n        if (n <= 1) \n            return false; \n        if (n <= 3) \n            return true; \n        if (n % 2 == 0 || n % 3 == 0) \n            return false; \n        for (int i = 5; i * i <= n; i = i + 6) \n            if (n % i == 0 || n % (i + 2) == 0) \n                return false; \n        return true; \n    } \n    static long gcd(long a, long b) { \n        if (b == 0) \n            return a; \n        return a>b?gcd(b, a % b):gcd(a, b % a);  \n    } \n    static long fast_pow(long base,long n,long M){\n        if(n==0)\n           return 1;\n        if(n==1)\n        return base;\n        long halfn=fast_pow(base,n/2,M);\n        if(n%2==0)\n            return ( halfn * halfn ) % M;\n        else\n            return ( ( ( halfn * halfn ) % M ) * base ) % M;\n    }\n    static long modInverse(long n,long M){\n        return fast_pow(n,M-2,M);\n    }\n    public static int s(int n){\n        return sc.nextInt();\n    }\n    public static long s(long n){\n        return sc.nextLong();\n    }\n    public static String s(String n){\n        return sc.next();\n    }\n    public static double s(double n){\n        return sc.nextDouble();\n    }\n    public static void p(int n){\n        pw.print(n);\n    }\n    public static void p(long n){\n        pw.print(n);\n    }\n    public static void p(String n){\n        pw.print(n);\n    }\n    public static void p(double n){\n        pw.print(n);\n    }\n    public static void pln(int n){\n        pw.println(n);\n    }\n    public static void pln(long n){\n        pw.println(n);\n    }\n    public static void pln(String n){\n        pw.println(n);\n    }\n    public static void pln(double n){\n        pw.println(n);\n    }\n    public static void feedArr(long []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.nextLong();\n    }\n    public static void feedArr(double []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.nextDouble();\n    }\n    public static void feedArr(int []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.nextInt();\n    }\n    public static void feedArr(String []arr){\n        for(int i=0;i<arr.length;i++)\n            arr[i]=sc.next();\n    }\n    public static String printArr(int []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(int i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\n    }\n    public  static String printArr(long []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(long i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\n    }\n    public static String printArr(String []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(String i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\n    }\n    public static String printArr(double []arr){\n        StringBuilder sbr=new StringBuilder();\n        for(double i:arr)\n            sbr.append(i+\" \");\n        return sbr.toString();\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        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        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n}\nclass AncestorQuerier {\n    int [][]dp;\n    int N=200001;\n    int M=22;\n    int max;    \n    public void preCompute(int []par){\n        for(int i=0;i<N;i++){\n            if(i>=2&&i<par.length)\n                dp[i][0]=par[i];\n            else\n                dp[i][0]=-1;\n        }\n        for(int j=1;j<M;j++){\n            for(int i=0;i<N;i++){\n                if(dp[i][j-1]!=-1)\n                    dp[i][j]=dp[dp[i][j-1]][j-1];\n            }\n        }       \n    }    \n    public int getAncestor(int val, int k) {\n        if(k<0||val>max)\n            return -1;\n        if(k==0)\n            return val;\n        int t=(1<<(M-1));        \n        for(int i=M-1;i>=0&&val!=-1;i--,t>>=1){\n            if(t<=k){\n                val=dp[val][i];\n                k-=t;\n            }\n        }\n        return val;   \n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class CompressionAndExpansion {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int T = in.nextInt();\n        for (int t = 0; t < T; t++) {\n            int N = in.nextInt();\n            List<Integer> list = new ArrayList<>();\n            for (int i = 0; i < N; i++) {\n                int n = in.nextInt();\n                if (n == 1) {\n                    list.add(n);\n                } else {\n                    for (int j = list.size() - 1; j >= 0; j--) {\n                        if (list.get(j) == n - 1) {\n                            list.set(j, n);\n                            break;\n                        }\n                        list.remove(j);\n                    }\n                }\n                for (int j = 0; j < list.size(); j++) {\n                    System.out.print(list.get(j) + (j == list.size() - 1 ? \"\\n\" : \".\"));\n                }\n            }\n        }\n    }\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "// package contest;\n\nimport java.io.*;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class teama {\n\n    static int mod = 2_000_000_007;\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter pw = new PrintWriter(System.out);\n\n        int T = Integer.parseInt(br.readLine());\n        for (int t = 0; t < T; t++) {\n            int N = Integer.parseInt(br.readLine());\n            Stack<Integer> stack = new Stack();\n            for (int i = 0; i < N; i++) {\n                int a = Integer.parseInt(br.readLine());\n                if (a != 1) {\n                    while (stack.peek() + 1 != a) {\n                        stack.pop();\n                    }\n                    stack.pop();\n                }\n                stack.push(a);\n\n                boolean dummy = false;\n                for (int j : stack) {\n                    if (dummy) {\n                        pw.print(\".\");\n                    }\n                    pw.print(j);\n                    dummy = true;\n                }\n                pw.println();\n            }\n        }\n\n        pw.close();\n        br.close();\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "//package Codeforces;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n    static class Node{\n        StringBuilder sb = new StringBuilder();\n        Stack<Integer> stk = new Stack<>();\n    }\n    public static void main(String[] args) throws IOException {\n        Soumit sc = new Soumit();\n\n        int t = sc.nextInt();\n        StringBuilder sb = new StringBuilder();\n        while (t-->0){\n            int n = sc.nextInt();\n            int[] arr = sc.nextIntArray(n);\n\n            Stack<Node> mainstk = new Stack<>();\n\n            Node pnode = new Node();\n            pnode.stk.push(1);\n            pnode.sb.append(\"1\");\n            mainstk.push(pnode);\n            sb.append(pnode.sb).append(\"\\n\");\n\n            for(int i=1;i<n;i++){\n                int val = arr[i];\n                if(val==1){\n                    Node node = new Node();\n                    node.stk.push(1);\n                    node.sb.append(mainstk.peek().sb).append(\".1\");\n                    mainstk.push(node);\n                    sb.append(node.sb).append(\"\\n\");\n                }\n                else {\n                    while (true) {\n                        Node node = mainstk.pop();\n                        if (node.stk.peek()==val-1) {\n                            node.stk.push(val);\n                            if(mainstk.isEmpty()){\n                                node.sb = new StringBuilder();\n                                node.sb.append(val);\n                                sb.append(val).append(\"\\n\");\n                            }\n                            else{\n                                Node peeknode = mainstk.peek();\n                                node.sb = new StringBuilder();\n                                node.sb.append(peeknode.sb).append(\".\").append(val);\n                                sb.append(peeknode.sb).append(\".\").append(val).append(\"\\n\");\n                            }\n                            mainstk.push(node);\n                            break;\n                        }\n                    }\n                }\n            }\n        }\n\n        System.out.println(sb);\n\n        sc.close();\n    }\n\n    static class Soumit {\n        final private int BUFFER_SIZE = 1 << 18;\n        final private DataInputStream din;\n        final private byte[] buffer;\n        private PrintWriter pw;\n        private int bufferPointer, bytesRead;\n        StringTokenizer st;\n\n        public Soumit() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public Soumit(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 void streamOutput(String file) throws IOException {\n            FileWriter fw = new FileWriter(file);\n            BufferedWriter bw = new BufferedWriter(fw);\n            pw = new PrintWriter(bw);\n        }\n\n        public void println(String a) {\n            pw.println(a);\n        }\n\n        public void print(String a) {\n            pw.print(a);\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[3000064]; // 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        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public void sort(int[] arr) {\n            ArrayList<Integer> arlist = new ArrayList<>();\n            for (int i : arr)\n                arlist.add(i);\n\n            Collections.sort(arlist);\n            for (int i = 0; i < arr.length; i++)\n                arr[i] = arlist.get(i);\n        }\n\n        public void sort(long[] arr) {\n            ArrayList<Long> arlist = new ArrayList<>();\n            for (long i : arr)\n                arlist.add(i);\n\n            Collections.sort(arlist);\n            for (int i = 0; i < arr.length; i++)\n                arr[i] = arlist.get(i);\n        }\n\n        public int[] nextIntArray(int n) throws IOException {\n            int[] arr = new int[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextInt();\n            }\n\n            return arr;\n        }\n\n        public long[] nextLongArray(int n) throws IOException {\n            long[] arr = new long[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextLong();\n            }\n\n            return arr;\n        }\n\n        public double[] nextDoubleArray(int n) throws IOException {\n            double[] arr = new double[n];\n            for (int i = 0; i < n; i++) {\n                arr[i] = nextDouble();\n            }\n\n            return arr;\n        }\n\n        public int nextInt() throws IOException {\n            int ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            } while ((c = read()) >= '0' && c <= '9');\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public long nextLong() throws IOException {\n            long ret = 0;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        public double nextDouble() throws IOException {\n            double ret = 0, div = 1;\n            byte c = read();\n            while (c <= ' ')\n                c = read();\n            boolean neg = (c == '-');\n            if (neg)\n                c = read();\n\n            do {\n                ret = ret * 10 + c - '0';\n            }\n            while ((c = read()) >= '0' && c <= '9');\n\n            if (c == '.') {\n                while ((c = read()) >= '0' && c <= '9') {\n                    ret += (c - '0') / (div *= 10);\n                }\n            }\n\n            if (neg)\n                return -ret;\n            return ret;\n        }\n\n        private void fillBuffer() throws IOException {\n            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n            if (bytesRead == -1)\n                buffer[0] = -1;\n        }\n\n        private byte read() throws IOException {\n            if (bufferPointer == bytesRead)\n                fillBuffer();\n            return buffer[bufferPointer++];\n        }\n\n        public void close() throws IOException {\n            /*if (din == null)\n                return;*/\n            if (din != null) din.close();\n            if (pw != null) pw.close();\n        }\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n \npublic class uo{\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 testcases = Integer.parseInt(st.nextToken());\n\t\tfor(int lmn=0;lmn<testcases;lmn++){\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\t// int k = Integer.parseInt(st.nextToken());\n\t\t\t// st = new StringTokenizer(br.readLine());\n\t\t\tArrayList<Integer> a = new ArrayList<>();\n\t\t\tfor(int lmn1 = 0;lmn1<n;lmn1++){\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\tint a1 = Integer.parseInt(st.nextToken());\n\t\t\t\tif(a.size()>0 && (a1==1)){\n\t\t\t\t\t// a.add(a1);\n\t\t\t\t}\n\t\t\t\telse if(a.size()>0){\n\t\t\t\t\tif(a.size()==1){\n\t\t\t\t\t\ta.remove(0);\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tint i = a.size()-1;\n\t\t\t\t\t\twhile(a.size()>0 && i>=0 && a.get(i)+1 != a1){\n\t\t\t\t\t\t\ta.remove(i);\n\t\t\t\t\t\t\ti--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta.remove(a.size()-1);\n\t\t\t\t\t\t// System.out.println(a+\" \"+i);\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// while(a.size()>0 && a.get(a.size()-1)+1<a1){\n\t\t\t\t// \ta.remove(a.size()-1);\n\t\t\t\t// }\n\t\t\t\tif(a.size()==0){\n\t\t\t\t\ta.add(a1);\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\ta.add(a1);\n\t\t\t\t}\n\t\t\t\tif(a.size()==1){\n\t\t\t\t\tSystem.out.println(a.get(0));\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tfor(int i=0;i<a.size()-1;i++){\n\t\t\t\t\t\t\n\t\t\t\t\t\tSystem.out.print(a.get(i)+\".\");\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(a.get(a.size()-1));\n\t\t\t\t}\n\t\t\t\t\n\n\t\t\t}\n\t\t}\n\t\t\n\t}\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.util.Scanner;\n\npublic class Def {\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 t = s.nextInt();\n\t\twhile (t-->0) {\n\t\t\t\n\t\t\tint n = s.nextInt();\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i=0; i<n; i++) {\n\t\t\t\tarr[i] = s.nextInt();\n\t\t\t}\n\n//\t\t\tint deep = 0;\n//\t\t\tSystem.out.println(n+\"     n\");\n\t\t\tList<Integer> al = new ArrayList<>();\n\t\t\tal.add(1);\n\t\t\tSystem.out.println(1);\n\t\t\tfor(int i=1; i<n;i++) {\n\t\t\t\tint len = al.size();\n//\t\t\t\tfor (int d =0; d<len; d++) {\n//\t\t\t\t\tSystem.out.print(al.get(d)+\" \");\n//\t\t\t\t}\n//\t\t\t\tSystem.out.println();\n\t\t\t\tif (arr[i] == 1) {\n\t\t\t\t\tfor(int j=0; j<len; j++) {\n\t\t\t\t\t\tSystem.out.print(al.get(j)+\".\");\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(1);\n\t\t\t\t\tal.add(1);\n\t\t\t\t}else if (arr[i] == arr[i-1] && arr[i]==1) {\n\t\t\t\t\t\n\t\t\t\t\tfor(int j=0; j<len; j++) {\n\t\t\t\t\t\tSystem.out.print(al.get(j)+\".\");\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(1);\n\t\t\t\t\tal.add(1);\n\t\t\t\t}else {\n\t\t\t\t\tfor (int j=len-1; j>-1; j--) {\n\t\t\t\t\t\tif (al.get(j)+1 == arr[i]) {\n\t\t\t\t\t\t\tfor(int k=0; k<j; k++) {\n\t\t\t\t\t\t\t\tSystem.out.print(al.get(k)+\".\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tSystem.out.println(arr[i]);\n\t\t\t\t\t\t\tal.set(j, al.get(j)+1);\n\t\t\t\t\t\t\tal.subList(j+1, len).clear();\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\t\n\t\t}\n\t\ts.close();\n\t\t\n\n\t}\n\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Solution\n{\n    static class Reader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n \n\t\tpublic Reader() {\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[] nextArr(int n)\n\t\t{\n\t\t    int a[]=new int[n];\n\t\t    for (int i=0;i<n;i++)a[i]=nextInt();\n\t\t    return a;\n\t\t}\n\t\t\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}\n    static class Ele implements Comparable<Ele> \n    {  \n        public int x,y;  \n        Ele(int x1,int y1) \n        {  \n            x=x1;y=y1; \n        }  \n        public int compareTo(Ele ob) {  \n        if(ob.x!=x)return x-ob.x;\n        return this.y-ob.y;  \n        }   \n        public String toString()\n        {\n        \treturn \"[\"+x+\",\"+y+\"]\";\n        }\n    }\n\tvoid disp(PrintWriter o,boolean b)\n    {\n        if (b) o.println(\"Yes\");\n        else o.println(\"No\");\n    }\n    void disp(PrintWriter o,int ...a)\n    {\n        o.println(Arrays.toString(a));\n    }\n    void disp(PrintWriter o,long ...a)\n    {\n        o.println(Arrays.toString(a));\n    }\n    void func(PrintWriter o,ArrayList<Integer> a)\n    {\n        for (int i=0;i<a.size();i++)\n        {\n            if (i!=a.size()-1)\n            o.print(a.get(i)+\".\");\n            else o.println(a.get(i));\n        }\n    }\n    int dp[][];\n\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tReader sc=new Reader();Solution G=new Solution();//MyMath mm=new MyMath();\n\t\tPrintWriter o = new PrintWriter(System.out);\n\t\tint t=1;t=sc.nextInt();\n\t\tint mod=(int)1e9+7;\n\t\tint x,x0,x1,x2;int y,y0,y1,y2;int s,s0,s1,s2;\n\t\tint n,m;int a[],b[],in[],in1[];\n\t\tlong k,l;boolean v[],b1,b2;String ss;char c1[];\n\t\t//long l;long a[]; \n\t\tArrayList<ArrayList<Integer>> ll=new ArrayList<>();\n\t\tArrayList<Integer> a1=new ArrayList<>();\n\t\tArrayList<Integer> a2=new ArrayList<>();\n\t\tPriorityQueue<Integer> pq1=new PriorityQueue<>();\n\t\tPriorityQueue<Integer> pq2=new PriorityQueue<>(Collections.reverseOrder());\n\t\tArrayDeque<Integer> dq=new ArrayDeque<>();\n\t\tTreeSet<Integer> h0=new TreeSet<>();\n\t\tTreeSet<Integer> h1=new TreeSet<>();\n\t\tTreeMap<Integer,Integer> h=new TreeMap<>();\n\t\ttry{\n\t\twhile (t-->0)\n\t\t{\n\t\t    n=sc.nextInt();a=sc.nextArr(n);b=new int[(int)1e4];\n\t\t    a1.add(a[0]);b[1]=a[0];\n\t\t    for (int i=1;i<n;i++)\n\t\t    {\n\t\t        G.func(o,a1);\n\t\t        x=a1.get(a1.size()-1);\n\t\t        if (a[i]==1)\n\t\t        {\n\t\t            a1.add(a[i]);\n\t\t            b[a1.size()]=a[i];\n\t\t        }\n\t\t        else if (a[i]==x+1)\n\t\t        {\n\t\t            a1.remove(a1.size()-1);\n\t\t            a1.add(a[i]);\n\t\t            b[a1.size()]=a[i];\n\t\t        }\n\t\t        else\n\t\t        {\n\t\t            while (a1.get(a1.size()-1)!=a[i]-1)\n\t\t            a1.remove(a1.size()-1);\n\t\t            a1.remove(a1.size()-1);\n\t\t            a1.add(a[i]);\n\t\t        }\n\t\t    }\n\t\t    G.func(o,a1);\n\t\t    //o.println();\n\t\t    //o.println(n);\n\t\t    //o.println();\n\t\t    //o.println();\n\t\t    //o.println(h);\n\t\t    //o.println(x2);\n\t\t    //o.println();\n\t\t    h0.clear();ll.clear();a1.clear();a2.clear();h1.clear();h.clear();pq1.clear();pq2.clear();\n\t\t}\n\t\t}\n\t\tcatch (Throwable e)\n\t\t{\n\t\t    e.printStackTrace();\n\t\t}\n\t\t//o.println(\"HI\");\n\t\t\n        o.flush();\n        o.close();\n\t}\n} ", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n\npublic class Main{\n    public static void pri(ArrayList<Integer> list)\n    {\n        int len=list.size();\n        for(int i=0;i<len-1;++i)\n            System.out.print(list.get(i)+\".\");\n        System.out.println(list.get(len-1));\n    }\n    public static void main(String[] args) throws java.io.IOException {\n        Scanner sc=new Scanner(System.in);\n        int t=sc.nextInt();\n        while(t-->0)\n        {\n            int n=sc.nextInt();\n            int[] arr=new int[n];\n            for(int i=0;i<n;++i)\n            {\n                arr[i]=sc.nextInt();\n            }\n            ArrayList<Integer> cur=new ArrayList<>();\n            cur.add(1);\n            System.out.println(1);\n            for(int i=1;i<n;++i)\n            {\n                if(arr[i]==1)\n                {\n                    cur.add(1);\n                    pri(cur);\n                    continue;\n                }\n                int len=cur.size();\n                while(cur.get(len-1)!=arr[i]-1)\n                {\n                    cur.remove(len-1);\n                    len--;\n                }\n                cur.set(len-1,arr[i]);\n                pri(cur);\n                continue;\n            }\n        }\n    }\n}\n// 1 0 1 1 0 0 1", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "/* 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    /*static long power(long a,long b,long m)\n    {\n        if(b==0)\n        return 1;\n        if((b&1)==0)\n        return power((a*a)%m,b/2,m);\n        else\n        return (a*power((a*a)%m,b/2,m))%m;\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    public static void main (String[] args) throws IOException {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        int t=Integer.parseInt(br.readLine());\n        PrintWriter p=new PrintWriter(System.out);\n        while(t-->0)\n        {\n            //StringTokenizer st=new StringTokenizer(br.readLine());\n            int n=Integer.parseInt(br.readLine());\n            String a[]=new String[n];\n            for(int i=0;i<n;i++)\n            {\n                a[i]=br.readLine();\n            }\n            String pre=\"1\";\n            for(int i=1;i<n;i++)\n            {\n                if(a[i].equals(\"1\"))\n                {\n                    a[i]=pre+\".1\";\n                    pre=a[i];\n                    continue;\n                }\n                int li=pre.lastIndexOf('.');\n                while(li!=-1 && Integer.parseInt(pre.substring(li+1))+1!=Integer.parseInt(a[i]))\n                {\n                    pre=pre.substring(0,li);\n                    li=pre.lastIndexOf('.');\n                }\n                //li=pre.lastIndexOf('.');\n                if(li!=-1)\n                a[i]=pre.substring(0,li+1)+a[i];\n                pre=a[i];\n            }\n            for(int i=0;i<n;i++)\n            {\n                p.println(a[i]);\n            }\n            p.flush();\n        }\n\t}\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class _1523_C {\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        int t = Integer.parseInt(in.readLine());\n        while(t-- > 0) {\n            int n = Integer.parseInt(in.readLine());\n            int[] a = new int[n];\n            for(int i = 0; i < n; i++) {\n                a[i] = Integer.parseInt(in.readLine());\n            }\n            boolean[][] used = new boolean[n][n + 1];\n            boolean[] used2 = new boolean[n];\n            String[][] res = new String[n][2];\n            res[0][0] = \"1\";\n            res[0][1] = \"\";\n            for(int i = 1; i < n; i++) {\n                if(a[i] == 1) {\n                    for(int j = i - 1; j >= 0; j--) {\n                        if(!used[j][a[i]] && !used2[j]) {\n                            res[i][0] = res[j][0] + \".1\";\n                            res[i][1] = res[j][0];\n                            used[j][a[i]] = true;\n                            break;\n                        }\n                    }\n                }else {\n                    for(int j = i - 1; j >= 0; j--) {\n                        if(!used[j][a[i]] && !used2[j] && a[j] == a[i] - 1) {\n                            if(res[j][1].equals(\"\")) {\n                                res[i][0] = \"\" + a[i];\n                            }else {\n                                res[i][0] = res[j][1] + \".\" + a[i];\n                            }\n                            res[i][1] = res[j][1];\n                            used[j][a[i]] = true;\n                            break;\n                        }\n                        used2[j] = true;\n                    }\n                }\n            }\n            for(int i = 0; i < n; i++) {\n                out.println(res[i][0]);\n            }\n        }\n        in.close();\n        out.close();\n    }\n}\n", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class TestClass {\n\n    public static class FastWriter {\n        private static final int BUF_SIZE = 1 << 13;\n        private final byte[] buf = new byte[BUF_SIZE];\n        private final OutputStream out;\n        private int ptr = 0;\n\n        private FastWriter() {\n            out = null;\n        }\n\n        public FastWriter(OutputStream os) {\n            this.out = os;\n        }\n\n        public FastWriter(String path) {\n            try {\n                this.out = new FileOutputStream(path);\n            } catch (FileNotFoundException e) {\n                throw new RuntimeException(\"FastWriter\");\n            }\n        }\n\n        public FastWriter write(byte b) {\n            buf[ptr++] = b;\n            if (ptr == BUF_SIZE) innerflush();\n            return this;\n        }\n\n        public FastWriter write(char c) {\n            return write((byte) c);\n        }\n\n        public FastWriter write(char[] s) {\n            for (char c : s) {\n                buf[ptr++] = (byte) c;\n                if (ptr == BUF_SIZE) innerflush();\n            }\n            return this;\n        }\n\n        public FastWriter write(String s) {\n            s.chars().forEach(c -> {\n                buf[ptr++] = (byte) c;\n                if (ptr == BUF_SIZE) innerflush();\n            });\n            return this;\n        }\n\n        private static int countDigits(int l) {\n            if (l >= 1000000000) return 10;\n            if (l >= 100000000) return 9;\n            if (l >= 10000000) return 8;\n            if (l >= 1000000) return 7;\n            if (l >= 100000) return 6;\n            if (l >= 10000) return 5;\n            if (l >= 1000) return 4;\n            if (l >= 100) return 3;\n            if (l >= 10) return 2;\n            return 1;\n        }\n\n        public FastWriter write(int x) {\n            if (x == Integer.MIN_VALUE) {\n                return write((long) x);\n            }\n            if (ptr + 12 >= BUF_SIZE) innerflush();\n            if (x < 0) {\n                write((byte) '-');\n                x = -x;\n            }\n            int d = countDigits(x);\n            for (int i = ptr + d - 1; i >= ptr; i--) {\n                buf[i] = (byte) ('0' + x % 10);\n                x /= 10;\n            }\n            ptr += d;\n            return this;\n        }\n\n        private static int countDigits(long l) {\n            if (l >= 1000000000000000000L) return 19;\n            if (l >= 100000000000000000L) return 18;\n            if (l >= 10000000000000000L) return 17;\n            if (l >= 1000000000000000L) return 16;\n            if (l >= 100000000000000L) return 15;\n            if (l >= 10000000000000L) return 14;\n            if (l >= 1000000000000L) return 13;\n            if (l >= 100000000000L) return 12;\n            if (l >= 10000000000L) return 11;\n            if (l >= 1000000000L) return 10;\n            if (l >= 100000000L) return 9;\n            if (l >= 10000000L) return 8;\n            if (l >= 1000000L) return 7;\n            if (l >= 100000L) return 6;\n            if (l >= 10000L) return 5;\n            if (l >= 1000L) return 4;\n            if (l >= 100L) return 3;\n            if (l >= 10L) return 2;\n            return 1;\n        }\n\n        public FastWriter write(long x) {\n            if (x == Long.MIN_VALUE) {\n                return write(\"\" + x);\n            }\n            if (ptr + 21 >= BUF_SIZE) innerflush();\n            if (x < 0) {\n                write((byte) '-');\n                x = -x;\n            }\n            int d = countDigits(x);\n            for (int i = ptr + d - 1; i >= ptr; i--) {\n                buf[i] = (byte) ('0' + x % 10);\n                x /= 10;\n            }\n            ptr += d;\n            return this;\n        }\n\n        public FastWriter write(double x, int precision) {\n            if (x < 0) {\n                write('-');\n                x = -x;\n            }\n            x += Math.pow(10, -precision) / 2;\n            //\t\tif(x < 0){ x = 0; }\n            write((long) x).write(\".\");\n            x -= (long) x;\n            for (int i = 0; i < precision; i++) {\n                x *= 10;\n                write((char) ('0' + (int) x));\n                x -= (int) x;\n            }\n            return this;\n        }\n\n        public FastWriter writeln(char c) {\n            return write(c).writeln();\n        }\n\n        public FastWriter writeln(int x) {\n            return write(x).writeln();\n        }\n\n        public FastWriter writeln(long x) {\n            return write(x).writeln();\n        }\n\n        public FastWriter writeln(double x, int precision) {\n            return write(x, precision).writeln();\n        }\n\n        public FastWriter write(int... xs) {\n            boolean first = true;\n            for (int x : xs) {\n                if (!first) write(' ');\n                first = false;\n                write(x);\n            }\n            return this;\n        }\n\n        public FastWriter write(long... xs) {\n            boolean first = true;\n            for (long x : xs) {\n                if (!first) write(' ');\n                first = false;\n                write(x);\n            }\n            return this;\n        }\n\n        public FastWriter writeln() {\n            return write((byte) '\\n');\n        }\n\n        public FastWriter writeln(int... xs) {\n            return write(xs).writeln();\n        }\n\n        public FastWriter writeln(long... xs) {\n            return write(xs).writeln();\n        }\n\n        public FastWriter writeln(char[] line) {\n            return write(line).writeln();\n        }\n\n        public FastWriter writeln(char[]... map) {\n            for (char[] line : map) write(line).writeln();\n            return this;\n        }\n\n        public FastWriter writeln(String s) {\n            return write(s).writeln();\n        }\n\n        private void innerflush() {\n            try {\n                out.write(buf, 0, ptr);\n                ptr = 0;\n            } catch (IOException e) {\n                throw new RuntimeException(\"innerflush\");\n            }\n        }\n\n        public void flush() {\n            innerflush();\n            try {\n                out.flush();\n            } catch (IOException e) {\n                throw new RuntimeException(\"flush\");\n            }\n        }\n\n        public FastWriter print(byte b) {\n            return write(b);\n        }\n\n        public FastWriter print(char c) {\n            return write(c);\n        }\n\n        public FastWriter print(char[] s) {\n            return write(s);\n        }\n\n        public FastWriter print(String s) {\n            return write(s);\n        }\n\n        public FastWriter print(int x) {\n            return write(x);\n        }\n\n        public FastWriter print(long x) {\n            return write(x);\n        }\n\n        public FastWriter print(double x, int precision) {\n            return write(x, precision);\n        }\n\n        public FastWriter println(char c) {\n            return writeln(c);\n        }\n\n        public FastWriter println(int x) {\n            return writeln(x);\n        }\n\n        public FastWriter println(long x) {\n            return writeln(x);\n        }\n\n        public FastWriter println(double x, int precision) {\n            return writeln(x, precision);\n        }\n\n        public FastWriter print(int... xs) {\n            return write(xs);\n        }\n\n        public FastWriter print(long... xs) {\n            return write(xs);\n        }\n\n        public FastWriter println(int... xs) {\n            return writeln(xs);\n        }\n\n        public FastWriter println(long... xs) {\n            return writeln(xs);\n        }\n\n        public FastWriter println(char[] line) {\n            return writeln(line);\n        }\n\n        public FastWriter println(char[]... map) {\n            return writeln(map);\n        }\n\n        public FastWriter println(String s) {\n            return writeln(s);\n        }\n\n        public FastWriter println() {\n            return writeln();\n        }\n    }\n\n\n    static final class InputReader {\n        private final InputStream stream;\n        private final 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 read() throws IOException {\n            if (curChar >= numChars) {\n                curChar = 0;\n                numChars = stream.read(buf);\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public final int readInt() throws IOException {\n            return (int) readLong();\n        }\n\n        public final long readLong() throws IOException {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n                if (c == -1) throw new IOException();\n            }\n            boolean negative = false;\n            if (c == '-') {\n                negative = true;\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 negative ? -res : res;\n        }\n\n        public final int[] readIntArray(int size) throws IOException {\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 final long[] readLongArray(int size) throws IOException {\n            long[] array = new long[size];\n            for (int i = 0; i < size; i++) {\n                array[i] = readLong();\n            }\n            return array;\n        }\n\n        public final String readString() throws IOException {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                res.append((char) 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    static long mulmod(long a, long b,\n                       long mod) {\n        long res = 0; // Initialize result\n        a = a % mod;\n        while (b > 0) {\n            // If b is odd, add 'a' to result\n            if (b % 2 == 1) {\n                res = (res + a) % mod;\n            }\n\n            // Multiply 'a' with 2\n            a = (a * 2) % mod;\n\n            // Divide b by 2\n            b /= 2;\n        }\n\n        // Return result\n        return res % mod;\n    }\n\n    static long pow(long a, long b, long MOD) {\n        long x = 1, y = a;\n        while (b > 0) {\n            if (b % 2 == 1) {\n                x = (x * y);\n                if (x > MOD) x %= MOD;\n            }\n            y = (y * y);\n            if (y > MOD) y %= MOD;\n            b /= 2;\n        }\n        return x;\n    }\n\n    static long[] f = new long[200001];\n\n    static long InverseEuler(long n, long MOD) {\n        return pow(n, MOD - 2, MOD);\n    }\n\n    static long C(int n, int r, long MOD) {\n\n        return (f[n] * ((InverseEuler(f[r], MOD) * InverseEuler(f[n - r], MOD)) % MOD)) % MOD;\n    }\n\n\n    static int[] h = {0, 0, -1, 1};\n    static int[] v = {1, -1, 0, 0};\n\n\n    public static class Pair {\n        public int a;\n\n        public int b;\n\n        @Override\n        public boolean equals(Object o) {\n            if (this == o) return true;\n            if (o == null || getClass() != o.getClass()) return false;\n            Pair pair = (Pair) o;\n            return a == pair.a &&\n                    b == pair.b;\n        }\n\n        @Override\n        public int hashCode() {\n            return Objects.hash(a, b);\n        }\n\n        public Pair(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n    }\n\n    static class Pair2 {\n        public long cost;\n        int node;\n\n        public Pair2(long cos, int node) {\n            this.cost = cos;\n            this.node = node;\n        }\n    }\n\n    static long compute_hash(String s) {\n        int p = 31;\n        int m = 1000000007;\n        long hash_value = 0;\n        long p_pow = 1;\n        for (int i = 0; i < s.length(); ++i) {\n            char c = s.charAt(i);\n            hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;\n            p_pow = (p_pow * p) % m;\n        }\n        return hash_value;\n    }\n\n    public static class SegmentTree {\n        long[][] tree;\n        int n;\n\n        public SegmentTree(int[] nodes) {\n            tree = new long[nodes.length * 4][2];\n            n = nodes.length;\n            build(0, n - 1, 0, nodes);\n\n        }\n\n        private void build(int l, int r, int pos, int[] nodes) {\n            if (l == r) {\n                tree[pos][0] = nodes[l];\n                tree[pos][1] = l;\n                return;\n            }\n            int mid = (l + r) / 2;\n            build(l, mid, 2 * pos + 1, nodes);\n            build(mid + 1, r, 2 * pos + 2, nodes);\n            if (tree[2 * pos + 1][0] > tree[2 * pos + 2][0]) {\n                tree[pos][1] = tree[2 * pos + 1][1];\n            } else {\n                tree[pos][1] = tree[2 * pos + 2][1];\n            }\n            tree[pos][0] = Math.max(tree[2 * pos + 1][0], tree[2 * pos + 2][0]);\n        }\n\n        //        public void update(int pos, int val) {\n        //            updateUtil(0, n - 1, 0, pos, val);\n        //        }\n\n        public long[] get(int l, int r) {\n            return getUtil(0, n - 1, 0, l, r);\n        }\n\n        private long[] getUtil(int l, int r, int pos, int ql, int qr) {\n            if (ql > r || qr < l) {\n                return new long[]{-1, -1};\n            }\n            if (l >= ql && r <= qr) {\n                return tree[pos];\n            }\n\n            int mid = (l + r) / 2;\n            long[] left = getUtil(l, mid, 2 * pos + 1, ql, qr);\n            long[] right = getUtil(mid + 1, r, 2 * pos + 2, ql, qr);\n            long choice = right[1];\n            if (left[0] > right[0]) choice = left[1];\n            return new long[]{Math.max(left[0], right[0]), choice};\n\n        }\n\n        //        private void updateUtil(int l, int r, int pos, int i, int val) {\n        //            if (i < l || i > r) {\n        //                return;\n        //            }\n        //            if (l == r) {\n        //                tree[pos] = val;\n        //                return;\n        //            }\n        //            int mid = (l + r) / 2;\n        //            updateUtil(l, mid, 2 * pos + 1, i, val);\n        //            updateUtil(mid + 1, r, 2 * pos + 2, i, val);\n        //            tree[pos] = tree[2 * pos + 1] + tree[2 * pos + 2];\n        //        }\n    }\n\n    static int counter = 0;\n    static int[] rIn;\n    static int[] rOut;\n    static int[] lIn;\n    static int[] lOut;\n    private static int[] flatten;\n    private static int[] lFlatten;\n    static long answer = 0;\n\n    static int VISITED = 1;\n    static int VISITING = 2;\n\n    static int[] DIRX = new int[]{0, 0, 1, -1};\n    static int[] DIRY = new int[]{1, -1, 0, 0};\n\n    public static class Pair22 {\n        int num, pos;\n\n        public Pair22(int x, int y) {\n            this.num = x;\n            this.pos = y;\n        }\n    }\n\n    public static long sumofdig(long n) {\n        long sum = 0;\n        while (n > 0) {\n            sum += n % 10;\n            n /= 10;\n        }\n        return sum;\n    }\n\n    public static void main(String[] args) throws Exception {\n        //https://i...content-available-to-author-only...e.com/ebRGa6\n        InputReader in = new InputReader(System.in);\n\n        FastWriter out = new FastWriter(System.out);\n\n\n//\n//        f[0] = 1;\n//        f[1] = 1;\n//        for (int i = 2; i < 200001; ++i) {\n//            f[i] = f[i-1] * i;\n//            f[i] %= 1000000007;\n//        }\n        int t = in.readInt();\n\n\n        while (t-- > 0) {\n\n            int n = in.readInt();\n\n            Stack<Integer> s = new Stack<>();\n\n            System.out.println(\"1\");\n            int i1 = in.readInt();\n            assert i1 == 1;\n            s.add(1);\n            for (int i = 1; i < n; ++i) {\n                int next = in.readInt();\n                if (next == 1) {\n                } else {\n                    while ((s.peek() + 1) != next) {\n                        s.pop();\n                    }\n                    s.pop();\n                }\n\n                s.add(next);\n                StringBuilder ans = new StringBuilder();\n                for (int c: s) {\n                    ans.append(c).append(\".\");\n                }\n                out.println(ans.substring(0, ans.length() - 1));\n                out.flush();\n            }\n\n        }\n\n    }\n\n    private static void solvedd(int[] arr, int left, int right, int[] ans, int depth) {\n\n        if (left > right) return;\n        int maxInd = left;\n        for (int i = left; i <= right; ++i) {\n            if (arr[i] > arr[maxInd]) {\n                maxInd = i;\n            }\n        }\n\n        ans[maxInd] = depth;\n\n        solvedd(arr, left, maxInd - 1, ans, depth + 1);\n        solvedd(arr, maxInd + 1, right, ans, depth + 1);\n\n    }\n\n\n    private static void solved(List<List<Integer>> g, int node, int[][] dp, int last, int[] a) {\n\n        int donttake = 0;\n        int take = 0;\n        for (int i = 0; i < g.get(node).size(); ++i) {\n            int ntb = g.get(node).get(i);\n\n            if (ntb != last) {\n                solved(g, ntb, dp, node, a);\n                donttake += Math.max(dp[ntb][0], dp[ntb][1]);\n                take += dp[ntb][1];\n            }\n        }\n        dp[node][0] = a[node] + take;\n        dp[node][1] = donttake;\n    }\n\n\n    private static boolean solve(int n, List<Integer> nums, int cur, int pos, Boolean[][] dp) {\n        if (cur > n) return false;\n        if (cur == n) return true;\n        if (pos >= nums.size()) return false;\n\n        if (dp[cur][pos] != null) {\n            return dp[cur][pos];\n        }\n        boolean without = solve(n, nums, cur, pos + 1, dp);\n        boolean with = false;\n        int ogcur = cur;\n        for (int i = 1; i < 12; ++i) {\n            with |= solve(n, nums, cur + nums.get(pos), pos + 1, dp);\n            cur += nums.get(pos);\n        }\n\n        return dp[ogcur][pos] = with | without;\n    }\n\n//    private static Pair22 dfss(List<LinkedHashSet<Integer>> g, int node, HashSet<Integer> vis, int[] dis, int[] dis2) {\n//        if (vis.contains(node)) return new Pair22(dis[node], dis2[node], -1);\n//        vis.add(node);\n//        int min = dis[node];\n//        for (Integer ntb : g.get(node)) {\n//            if (dis[ntb] > dis[node])\n//                dfss(g, ntb, vis, dis, dis2);\n//            if (dis[ntb] <= dis[node]) {\n//                min = Math.min(min, dis[ntb]);\n//            } else {\n//                min = Math.min(min, dis2[ntb]);\n//            }\n//        }\n//        //        if (dis)\n//        dis2[node] = min;\n//        return new Pair22(dis[node], min, -1);\n//    }\n\n\n    private static int dfs(HashMap<Pair, TreeSet<Pair>> grid, int x, int y, int ti, HashSet<Pair> vis, int r, int startX, int startY) {\n        //        System.out.println(x + \"  \" + y);\n        int taken = ti - Math.abs(startX - x) - Math.abs(startY - y);\n        if (taken < 0) return 0;\n        if (x < 0 || y < 0 || x > r || y > r) return 0;\n        if (vis.contains(new Pair(x, y))) return 0;\n        int max = 0;\n\n        if (grid.containsKey(new Pair(x, y))) {\n            TreeSet<Pair> times = grid.get(new Pair(x, y));\n            for (Pair t : times) {\n                if (t.a <= taken) {\n                    max = Math.max(t.b, max);\n                } else break;\n            }\n        }\n        vis.add(new Pair(x, y));\n        max = Math.max(dfs(grid, x + 1, y, ti, vis, r, startX, startY), max);\n        max = Math.max(dfs(grid, x, y + 1, ti, vis, r, startX, startY), max);\n        max = Math.max(dfs(grid, x - 1, y, ti, vis, r, startX, startY), max);\n        max = Math.max(dfs(grid, x, y - 1, ti, vis, r, startX, startY), max);\n        return max;\n    }\n\n    private static int solver(int[] nums, int pos, int[] dp) {\n        if (pos >= nums.length) return 0;\n        if (dp[pos] != Integer.MAX_VALUE) return dp[pos];\n        int min = solver(nums, pos + 2, dp) + nums[pos];\n        min = Math.min(solver(nums, pos + 3, dp) + nums[pos], min);\n        if (pos + 1 < nums.length) min = Math.min(min, nums[pos] + nums[pos + 1] + solver(nums, pos + 3, dp));\n        if (pos + 1 < nums.length) min = Math.min(min, nums[pos] + nums[pos + 1] + solver(nums, pos + 4, dp));\n\n        //        System.out.println(pos + \" \" + min);\n        return dp[pos] = min;\n    }\n\n\n    static int countFreq(String pattern, String text) {\n        int m = pattern.length();\n        int n = text.length();\n        int res = 0;\n\n        for (int i = 0; i <= n - m; i++) {\n            int j;\n            for (j = 0; j < m; j++) {\n                if (text.charAt(i + j) != pattern.charAt(j)) {\n                    break;\n                }\n            }\n            if (j == m) {\n                res++;\n                j = 0;\n            }\n        }\n        return res;\n    }\n\n    private static void dfsR(List<List<Integer>> g, int node, int[] v) {\n        rIn[node] = counter;\n        flatten[counter++] = v[node];\n\n        for (int i = 0; i < g.get(node).size(); ++i) {\n            dfsR(g, g.get(node).get(i), v);\n        }\n\n        rOut[node] = counter;\n        flatten[counter++] = v[node] * -1;\n    }\n\n    private static void dfsL(List<List<Integer>> g, int node, int[] v) {\n        lIn[node] = counter;\n        lFlatten[counter++] = v[node];\n\n        for (int i = 0; i < g.get(node).size(); ++i) {\n            dfsL(g, g.get(node).get(i), v);\n        }\n\n        lOut[node] = counter;\n        lFlatten[counter++] = v[node] * -1;\n\n        TreeMap<String, Integer> map = new TreeMap<>();\n    }\n\n\n    private static void preprocess(int pos, int[][] pre, List<List<Integer>> tree, int[] traverse, int depth, int last, int[] tin, int[] tout) {\n        tin[pos] = counter++;\n        traverse[depth] = pos;\n\n        for (int i = 0; depth - (1 << i) >= 0; ++i) {\n            pre[pos][i] = traverse[depth - (1 << i)];\n        }\n\n        for (int i = 0; i < tree.get(pos).size(); ++i) {\n            if (tree.get(pos).get(i) != last)\n                preprocess(tree.get(pos).get(i), pre, tree, traverse, depth + 1, pos, tin, tout);\n        }\n        tout[pos] = counter++;\n    }\n\n    static long gcd(long a, long b) {\n\n        while (b != 0) {\n            long t = a;\n            a = b;\n            b = t % b;\n        }\n        return a;\n    }\n\n\n    static boolean submit = true;\n\n    static void debug(String s) {\n        if (!submit)\n            System.out.println(s);\n    }\n\n    static void debug(int s) {\n        LinkedHashSet<Integer> exist = new LinkedHashSet<>();\n            /*\n\n            4 2 3 _ 2 4 3 _\n             */\n    }\n\n\n\n\n/**\n\n\n 0 1 2 3 4 5 6 7 8 9 10\n\n 1               1   1\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(N);\n * int param_1 = obj.seat();\n * obj.leave(p);\n */\n}", "complexity": "cubic", "problem": "1523_C. Compression and Expansion", "from": "CODEFORCES"}
{"src": "/*\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 x1242C2\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         int N = Integer.parseInt(st.nextToken());\n         long[] sums = new long[N];\n         ArrayList<Integer>[] boxes = new ArrayList[N];\n         for(int i=0; i < N; i++)\n         {\n            boxes[i] = new ArrayList<Integer>();\n            st = new StringTokenizer(infile.readLine());\n            int a = Integer.parseInt(st.nextToken());\n            while(a-->0)\n               boxes[i].add(Integer.parseInt(st.nextToken()));\n            for(int x: boxes[i])\n               sums[i] += x;\n         }\n         long lmaosum = 0L;\n         for(long x: sums)\n            lmaosum += x;\n         if(Math.abs(lmaosum)%N != 0)\n         {\n            System.out.println(\"No\");\n            return;\n         }\n         long target = lmaosum/N;\n         //fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck\n         HashMap<Long, Integer> map = new HashMap<Long, Integer>();\n         for(int k=0; k < N; k++)\n            for(int x: boxes[k])\n               map.put((long)x, k);\n         HashMap<Long, Long> edges = new HashMap<Long, Long>();\n         for(int k=0; k < N; k++)\n            for(int x: boxes[k])\n            {\n               long nextval = target-sums[k]+x;\n               if(map.containsKey(nextval))\n                  edges.put((long)x, nextval);\n            }\n         Node[] dp = new Node[1<<N];\n         dp[0] = new Node(-69, -69, 0);\n         //precompute subsets ass\n         Node[] subsets = new Node[1<<N];\n         for(int b=0; b < N; b++)\n            for(int i=0; i < boxes[b].size(); i++)\n            {\n               if(!edges.containsKey((long)boxes[b].get(i)))\n                  continue;\n               long curr = edges.get((long)boxes[b].get(i));\n               //shit shit shit shit shit shit shit shit shit shit\n               int submask = 0;  boolean cyclic = true;\n               while(curr != boxes[b].get(i))\n               {\n                  int k = map.get(curr);\n                  if((submask&(1<<k)) > 0 || !edges.containsKey((long)curr))\n                  {\n                     cyclic = false;\n                     break;\n                  }\n                  submask |= 1<<k;\n                  curr = edges.get((long)curr);\n               }\n               submask |= (1<<b);\n               if(cyclic)\n                  subsets[submask] = new Node(-69, i, b);\n            }\n         for(int mask=1; mask < (1<<N); mask++)\n            outer:for(int submask=mask; submask > 0; submask=(submask-1)&mask)\n               if(dp[mask^submask] != null && subsets[submask] != null)\n               {\n                  dp[mask] = new Node(mask^submask, subsets[submask].dex, subsets[submask].start);\n                  break outer;\n               }\n         if(dp[(1<<N)-1] == null)\n            System.out.println(\"No\");\n         else\n         {\n            StringBuilder sb = new StringBuilder(\"Yes\\n\");\n            long[][] res = new long[N][2];\n            for(int i=0; i < N; i++)\n               res[i][1] = -1L;\n            int currmask = (1<<N)-1;\n            while(currmask != 0)\n            {\n               int submask = dp[currmask].mask;\n               int i = dp[currmask].dex;\n               int b = dp[currmask].start;\n               long nextval = target-sums[b]+boxes[b].get(i);\n               int curr = map.get(nextval);\n               res[map.get(nextval)][0] = nextval;\n               res[map.get(nextval)][1] = b;\n               while(true) //lol\n               {\n                  int lol = map.get(nextval);\n                  nextval = edges.get(nextval);\n                  res[map.get(nextval)][0] = nextval;\n                  if(res[map.get(nextval)][1] != -1)\n                     break;\n                  res[map.get(nextval)][1] = lol;\n               }\n               currmask = dp[currmask].mask;\n            }\n            for(int k=0; k < N; k++)\n               sb.append(res[k][0]+\" \").append(res[k][1]+1).append(\"\\n\");\n            System.out.print(sb);\n         }\n      }\n   }\n   class Node\n   {\n      public int mask;\n      public int dex;\n      public int start;\n      \n      public Node(int a, int b, int c)\n      {\n         mask = a;\n         dex = b;\n         start = c;\n      }\n   }", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\n\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map.Entry;\nimport java.util.Random;\nimport java.util.TreeSet;\n\npublic final class CF_599_D1_C\n{\n\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;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\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\tstatic long mod=1000000007;\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\n\tstatic class Composite implements Comparable<Composite>{\n\t\tint idx;\n\t\tint v;\n\n\t\tpublic int compareTo(Composite X) {\n\t\t\tif (v!=X.v)\n\t\t\t\treturn v-X.v;\n\t\t\treturn idx-X.idx;\n\n\n\t\t}\n\n\t\tpublic Composite(int idx, int v) {\n\t\t\tthis.idx = idx;\n\t\t\tthis.v = v;\n\t\t}\n\n\n\n\t}\n\n\tstatic void test() {\n\t\tlog(\"testing\");\n\n\t\tlog(\"done\");\n\n\t}\n\n\tstatic void explore(ArrayList<Integer>[] components,ArrayList<Integer> bob,int[][] move,ArrayList<int[]>[] howto,int[][] list) {\n\n\t\tfor (int x:bob) {\n\t\t\tif (components[x].size()==1) {\n\t\t\t\tint tm[]=howto[x].get(0);\n\n\n\t\t\t\tint L=howto[x].size();\n\t\t\t\thowto[x].add(tm);\n\t\t\t\tfor (int i=0;i<L;i++) {\n\t\t\t\t\tint[] cur=howto[x].get(i);\n\t\t\t\t\tint[] nx=howto[x].get(i+1);\n\t\t\t\t\tint a=cur[0];\n\t\t\t\t\tint a2=nx[0];\n\t\t\t\t\tint b2=nx[1];\n\t\t\t\t\tmove[a2][0]=list[a2][b2];\n\t\t\t\t\tmove[a2][1]=a;\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\texplore(components,components[x],move,howto,list);\n\t\t\t}\n\t\t}\n\t}\n\n\n\tstatic void process() throws Exception {\n\n\n\t\t//arrayTest();\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader = new InputReader(System.in);\n\n\n\t\tint k=reader.readInt();\n\t\tint[][] list=new int[k][];\n\t\tlong[] sum=new long[k];\n\t\tint[] L=new int[k];\n\t\tHashMap<Integer,int[]> target=new HashMap<Integer,int[]>();\n\t\tlong tot=0;\n\t\tfor (int i=0;i<k;i++) {\n\t\t\tL[i]=reader.readInt();\n\t\t\tlist[i]=new int[L[i]];\n\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\tlist[i][j]=reader.readInt();\n\t\t\t\tsum[i]+=list[i][j];\n\t\t\t\ttarget.put(list[i][j],new int[] {i,j});\n\t\t\t}\n\t\t\ttot+=sum[i];\n\t\t}\n\n\t\tint MX=1<<k;\n\t\tint AX=1000000001;\n\t\tArrayList<int[]>[] howto=new ArrayList[MX];\n\n\t\tlog(\"ok with the data\");\n\n\t\tif (tot%k!=0) {\n\t\t\toutput(\"No\");\n\t\t} else {\n\n\t\t\ttot/=k;\n\n\n\n\n\n\t\t\tfor (int i=0;i<k;i++) {\n\n\t\t\t\tif (sum[i]==tot) {\n\t\t\t\t\t//log(\"nothing to do for i:\"+i);\n\t\t\t\t\t// nothing to do\n\t\t\t\t\tint mask=1<<i;\n\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\tcand.add(new int[] {i,0});\n\t\t\t\t\thowto[mask]=cand;\n\t\t\t\t} else \n\n\n\t\t\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\t\t\tint u=i;\n\t\t\t\t\t\tint v=j;\n\t\t\t\t\t\tboolean ok=true;\n\t\t\t\t\t\tint src_u=u;\n\t\t\t\t\t\tint src_v=v;\n\t\t\t\t\t\tint mask=0;\n\t\t\t\t\t\tboolean goon=true;\n\t\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\t\t//log(\"start loop\");\n\t\t\t\t\t\twhile (goon) {\n\t\t\t\t\t\t\tcand.add(new int[] {u,v});\n\t\t\t\t\t\t\t//log(\"u:\"+u+\" v:\"+v);\n\t\t\t\t\t\t\tok=false;\n\t\t\t\t\t\t\tgoon=false;\n\t\t\t\t\t\t\tlong need=tot-((long)sum[u]-(long)list[u][v]);\n\t\t\t\t\t\t\tif (Math.abs(need)<=AX) {\n\t\t\t\t\t\t\t\t//log(\"need:\"+need);\n\t\t\t\t\t\t\t\tint nd=(int)need;\n\t\t\t\t\t\t\t\tint[] tm=target.get(nd);\n\t\t\t\t\t\t\t\t//log(\"tm:\"+tm);\n\t\t\t\t\t\t\t\tif (tm!=null) {\n\t\t\t\t\t\t\t\t\t//log(\"can find successor\");\n\t\t\t\t\t\t\t\t\tint nxu=tm[0];\n\t\t\t\t\t\t\t\t\tint nxv=tm[1];\n\t\t\t\t\t\t\t\t\tif ((mask&(1<<nxu))==0) {\n\t\t\t\t\t\t\t\t\t\tmask|=1<<nxu;\n\t\t\t\t\t\t\t\t\t\tif (nxu==src_u) {\n\t\t\t\t\t\t\t\t\t\t\t// looping back to source\n\t\t\t\t\t\t\t\t\t\t\tif (nxv==src_v)\n\t\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tu=nxu;\n\t\t\t\t\t\t\t\t\t\t\tv=nxv;\n\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t\tgoon=true;\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\tif (ok) {\n\t\t\t\t\t\t\tif (howto[mask]==null) {\n\n\t\t\t\t\t\t\t\thowto[mask]=cand;\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}\n\n\t\t\tlog(\"step 1 done\");\n\n\t\t\t// now mask\n\n\t\t\n\t\t\tArrayList[] components=new ArrayList[MX];\n\n\t\t\tfor (int m=0;m<MX;m++) {\n\t\t\t\tif (howto[m]!=null) {\n\t\t\t\t\t//String s=Integer.toBinaryString(m);\n\t\t\t\t\t//while (s.length()<k)\n\t\t\t\t\t//\ts=\"0\"+s;\n\t\t\t\t\t//log(\"found mask:\"+s);\n\t\t\t\t\tcomponents[m]=new ArrayList<Integer>();\n\t\t\t\t\tcomponents[m].add(m);\n\t\t\t\t}\n\t\t\t}\n\n\n\n\t\n\t\t\tint[] msk=new int[MX];\n\t\t\tint w=0;\n\t\t\t\n\t\t\tfor (int a=0;a<MX;a++) {\n\t\t\t\tif (howto[a]!=null) {\n\t\t\t\t\tArrayList<Integer> add=new ArrayList<Integer>();\n\t\t\t\t\t\n\t\t\t\t\tint ww=w;\n\t\t\t\t\tfor (int i=0;i<ww;i++) {\n\t\t\t\t\t\tint b=msk[i];\n\t\t\t\t\t\tif ((b&a)==0) {\n\n\t\t\t\t\t\t\tint c=b|a;\n\t\t\t\t\t\t\tlog(\"creating c:\"+c+\" \");\n\t\t\t\t\t\t\tif (components[c]==null ) {\n\t\t\t\t\t\t\t\tcomponents[c]=new ArrayList<Integer>();\n\t\t\t\t\t\t\t\tcomponents[c].add(a);\n\t\t\t\t\t\t\t\tcomponents[c].add(b);\n\t\t\t\t\t\t\t\tmsk[w++]=c;\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\tmsk[w++]=a;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//log(\"msk:\"+msk);\n\t\t\t//log(components[MX-1]);\n\t\t\tif (components[MX-1]!=null) {\n\t\t\t\toutput(\"Yes\");\n\t\t\t\tint[][] move=new int[k][2];\n\t\t\t\texplore(components,components[MX-1],move,howto,list);\n\t\t\t\tfor (int i=0;i<k;i++) {\n\t\t\t\t\toutput(move[i][0]+\" \"+(move[i][1]+1));\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\toutput(\"No\");\n\t\t\t}\n\n\t\t}\n\n\n\t\ttry {\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t}\n\n\t}\n\n\n\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\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\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}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "/*\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 x1242C2\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         int N = Integer.parseInt(st.nextToken());\n         long[] sums = new long[N];\n         ArrayList<Integer>[] boxes = new ArrayList[N];\n         for(int i=0; i < N; i++)\n         {\n            boxes[i] = new ArrayList<Integer>();\n            st = new StringTokenizer(infile.readLine());\n            int a = Integer.parseInt(st.nextToken());\n            while(a-->0)\n               boxes[i].add(Integer.parseInt(st.nextToken()));\n            for(int x: boxes[i])\n               sums[i] += x;\n         }\n         long lmaosum = 0L;\n         for(long x: sums)\n            lmaosum += x;\n         if(Math.abs(lmaosum)%N != 0)\n         {\n            System.out.println(\"No\");\n            return;\n         }\n         long target = lmaosum/N;\n         //fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck fuck\n         HashMap<Long, Integer> map = new HashMap<Long, Integer>();\n         for(int k=0; k < N; k++)\n            for(int x: boxes[k])\n               map.put((long)x, k);\n         HashMap<Long, Long> edges = new HashMap<Long, Long>();\n         for(int k=0; k < N; k++)\n            for(int x: boxes[k])\n            {\n               long nextval = target-sums[k]+x;\n               if(map.containsKey(nextval))\n                  edges.put((long)x, nextval);\n            }\n         Node[] dp = new Node[1<<N];\n         dp[0] = new Node(-69, -69, 0);\n         //precompute subsets ass\n         Node[] subsets = new Node[1<<N];\n         for(int b=0; b < N; b++)\n            for(int i=0; i < boxes[b].size(); i++)\n            {\n               if(!edges.containsKey((long)boxes[b].get(i)))\n                  continue;\n               long curr = edges.get((long)boxes[b].get(i));\n               //shit shit shit shit shit shit shit shit shit shit\n               int submask = 0;  boolean cyclic = true;\n               while(curr != boxes[b].get(i))\n               {\n                  int k = map.get(curr);\n                  if((submask&(1<<k)) > 0 || !edges.containsKey((long)curr))\n                  {\n                     cyclic = false;\n                     break;\n                  }\n                  submask |= 1<<k;\n                  curr = edges.get((long)curr);\n               }\n               submask |= (1<<b);\n               if(cyclic)\n                  subsets[submask] = new Node(-69, i, b);\n            }\n         for(int mask=1; mask < (1<<N); mask++)\n            outer:for(int submask=mask; submask > 0; submask=(submask-1)&mask)\n               if(dp[mask^submask] != null && subsets[submask] != null)\n               {\n                  dp[mask] = new Node(mask^submask, subsets[submask].dex, subsets[submask].start);\n                  break outer;\n               }\n         if(dp[(1<<N)-1] == null)\n            System.out.println(\"No\");\n         else\n         {\n            StringBuilder sb = new StringBuilder(\"Yes\\n\");\n            long[][] res = new long[N][2];\n            for(int i=0; i < N; i++)\n               res[i][1] = -1L;\n            int currmask = (1<<N)-1;\n            while(currmask != 0)\n            {\n               int submask = dp[currmask].mask;\n               int i = dp[currmask].dex;\n               int b = dp[currmask].start;\n               long nextval = target-sums[b]+boxes[b].get(i);\n               int curr = map.get(nextval);\n               res[map.get(nextval)][0] = nextval;\n               res[map.get(nextval)][1] = b;\n               while(true)\n               {\n                  int lol = map.get(nextval);\n                  nextval = edges.get(nextval);\n                  res[map.get(nextval)][0] = nextval;\n                  if(res[map.get(nextval)][1] != -1)\n                     break;\n                  res[map.get(nextval)][1] = lol;\n               }\n               currmask = dp[currmask].mask;\n            }\n            for(int k=0; k < N; k++)\n               sb.append(res[k][0]+\" \").append(res[k][1]+1).append(\"\\n\");\n            System.out.print(sb);\n         }\n      }\n   }\n   class Node\n   {\n      public int mask;\n      public int dex;\n      public int start;\n      \n      public Node(int a, int b, int c)\n      {\n         mask = a;\n         dex = b;\n         start = c;\n      }\n   }", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class C {\n\t\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tint nBoxes=fs.nextInt();\n\t\tlong[] sums=new long[nBoxes];\n\t\tHashMap<Long, Integer> boxOf=new HashMap<>();\n\t\tint[][] boxes=new int[nBoxes][];\n\t\tlong total=0;\n\t\tfor (int i=0; i<nBoxes; i++) {\n\t\t\tint size=fs.nextInt();\n\t\t\tboxes[i]=new int[size];\n\t\t\tfor (int j=0; j<size; j++) {\n\t\t\t\tboxes[i][j]=fs.nextInt();\n\t\t\t\tboxOf.put((long)boxes[i][j], i);\n\t\t\t\tsums[i]+=boxes[i][j];\n\t\t\t}\n\t\t\ttotal+=sums[i];\n\t\t}\n\t\tif (total%nBoxes!=0) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong target=total/nBoxes;\n\t\tint[][] masks=new int[nBoxes][];\n\t\tArrayList<Integer>[][] maskLoops=new ArrayList[nBoxes][];\n\t\tfor (int i=0; i<nBoxes; i++) {\n\t\t\tmasks[i]=new int[boxes[i].length];\n\t\t\tmaskLoops[i]=new ArrayList[boxes[i].length];\n\t\t\tfor (int j=0; j<maskLoops[i].length; j++) maskLoops[i][j]=new ArrayList<>();\n\t\t\t\n\t\t\tinner:for (int j=0; j<boxes[i].length; j++) {\n\t\t\t\tlong startVal=boxes[i][j], lookingFor=target-(sums[i]-startVal);\n\t\t\t\tmaskLoops[i][j].add((int)lookingFor);\n\t\t\t\tint mask=1<<i;\n\t\t\t\twhile (lookingFor!=startVal) {\n\t\t\t\t\tif (!boxOf.containsKey(lookingFor)) continue inner;\n\t\t\t\t\tint nextBox=boxOf.get(lookingFor);\n\n\t\t\t\t\t//if we have already used this box, it won't work\n\t\t\t\t\tif ((mask&(1<<nextBox))!=0) continue inner;\n\t\t\t\t\t\n\t\t\t\t\tmask|=1<<nextBox;\n\t\t\t\t\tlookingFor=target-(sums[nextBox]-lookingFor);\n\t\t\t\t\t/*if (lookingFor!=startVal) */maskLoops[i][j].add((int)lookingFor);\n\t\t\t\t}\n//\t\t\t\tSystem.out.println(\"Mask loops for box: \"+i+\" starting at \"+startVal+\" gives \"+);\n\t\t\t\t\n\t\t\t\t//otherwise it worked\n\t\t\t\tmasks[i][j]=mask;\n\t\t\t}\n\t\t}\n\t\t\n\t\tboolean[] possible=new boolean[1<<nBoxes];\n\t\tint[] maskFrom=new int[1<<nBoxes];\n\t\tint[] indexToUse=new int[1<<nBoxes];\n\t\tpossible[0]=true;\n\t\tfor (int mask=1; mask<1<<nBoxes; mask++) {\n\t\t\tint lowestBit=Integer.numberOfTrailingZeros(Integer.lowestOneBit(mask));\n\t\t\t/*\n\t\t\tfor (int i:masks[lowestBit]) {\n\t\t\t\tif ((mask&i)==i && possible[mask^i]) {\n\t\t\t\t\tpossible[mask]=true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t*/\n\t\t\t\n\t\t\tfor (int i=0; i<masks[lowestBit].length; i++) {\n\t\t\t\tint m=masks[lowestBit][i];\n\t\t\t\tif ((mask&m)==m && possible[mask^m]) {\n\t\t\t\t\tpossible[mask]=true;\n\t\t\t\t\tmaskFrom[mask]=mask^m;\n\t\t\t\t\tindexToUse[mask]=i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!possible[(1<<nBoxes)-1]) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(\"Yes\");\n\t\tArrayList<ArrayList<Integer>> loops=new ArrayList<>();\n\t\tint mask=(1<<nBoxes)-1;\n\t\twhile (mask!=0) {\n//\t\t\tSystem.out.println(\"At mask: \"+Integer.toBinaryString(mask));\n\t\t\tint lowestBit=Integer.numberOfTrailingZeros(Integer.lowestOneBit(mask));\n\t\t\tloops.add(maskLoops[lowestBit][indexToUse[mask]]);\n\t\t\tmask=maskFrom[mask];\n\t\t}\n\t\t\n//\t\tSystem.out.println(\"Loops: \"+loops);\n\t\t\n\t\tint[] takeFrom=new int[nBoxes];\n\t\tint[] boxGiveTo=new int[nBoxes];\n\t\tfor (ArrayList<Integer> loop:loops) {\n\t\t\tfor (int i=0; i<loop.size(); i++) {\n\t\t\t\tint cur=loop.get(i), next=loop.get((i+1)%loop.size());\n\t\t\t\tint curBox=boxOf.get((long)cur), nextBox=boxOf.get((long)next);\n\t\t\t\ttakeFrom[nextBox]=next;\n\t\t\t\tboxGiveTo[nextBox]=curBox;\n\t\t\t}\n\t\t}\n\t\tfor (int i=0; i<nBoxes; i++) {\n\t\t\tSystem.out.println(takeFrom[i]+\" \"+(boxGiveTo[i]+1));\n\t\t}\n\t}\n\t\n\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tpublic String next() {\n\t\t\twhile (!st.hasMoreElements())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\t\n\t\n}\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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        int n;\n        int[] bitCount;\n        long neededSum;\n        long[] sums;\n        Map<Long, Integer> where;\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            n = in.nextInt();\n            int[][] a = new int[n][];\n            neededSum = 0;\n            sums = new long[n];\n            for (int i = 0; i < n; i++) {\n                int k = in.nextInt();\n                a[i] = new int[k];\n                for (int j = 0; j < k; j++) {\n                    a[i][j] = in.nextInt();\n                    neededSum += a[i][j];\n                    sums[i] += a[i][j];\n                }\n            }\n\n            if (neededSum % n != 0) {\n                out.println(\"No\");\n                return;\n            }\n            neededSum /= n;\n\n            where = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < a[i].length; j++) {\n                    where.put((long) a[i][j], i);\n                }\n            }\n            bitCount = new int[1 << n];\n            for (int i = 0; i < bitCount.length; i++) {\n                bitCount[i] = Integer.bitCount(i);\n            }\n\n            Entry[][] cycleSol = new Entry[1 << n][];\n\n            List<Entry> sol = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                for (int x : a[i]) {\n                    search(i, i, x, x, 0, 0, sol, cycleSol);\n                }\n            }\n\n            boolean[] can = new boolean[1 << n];\n            int[] via = new int[1 << n];\n            can[0] = true;\n            for (int mask = 0; mask < 1 << n; mask++) {\n                for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {\n                    if (cycleSol[submask] != null && can[mask ^ submask]) {\n                        can[mask] = true;\n                        via[mask] = submask;\n                    }\n                }\n            }\n\n            if (!can[(1 << n) - 1]) {\n                out.println(\"No\");\n                return;\n            }\n\n            int[][] ans = new int[n][2];\n            for (int mask = (1 << n) - 1; mask > 0; ) {\n                int sm = via[mask];\n                mask ^= sm;\n\n                for (Entry e : cycleSol[sm]) {\n                    ans[e.from][0] = e.what;\n                    ans[e.from][1] = e.to + 1;\n                }\n            }\n\n            out.println(\"Yes\");\n            for (int i = 0; i < n; i++) {\n                out.println(ans[i][0] + \" \" + ans[i][1]);\n            }\n        }\n\n        private void search(int start, int cur, long fromStart, long fromCur, int hasIn, int hasOut, List<Entry> sol, Entry[][] cycleSol) {\n            for (int i = start; i < n; i++) {\n                if ((hasIn & (1 << i)) > 0) {\n                    continue;\n                }\n                if ((hasOut & (1 << cur)) > 0) {\n                    continue;\n                }\n                long fromI = sums[i] + fromCur - neededSum;\n                Integer w = where.get(fromI);\n                if (w == null || w != i) {\n                    continue;\n                }\n                sol.add(new Entry(cur, i, (int) fromCur));\n                int nHasIn = hasIn | (1 << i);\n                int nHasOut = hasOut | (1 << cur);\n                if (i == start && fromI == fromStart) {\n                    cycleSol[nHasOut] = sol.toArray(new Entry[0]);\n                }\n                search(start, i, fromStart, fromI, nHasIn, nHasOut, sol, cycleSol);\n                sol.remove(sol.size() - 1);\n            }\n        }\n\n        class Entry {\n            int from;\n            int to;\n            int what;\n\n            Entry(int from, int to, int what) {\n                this.from = from;\n                this.to = to;\n                this.what = what;\n            }\n\n            public String toString() {\n                return from + \" \" + to + \" \" + what;\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                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskE solver = new TaskE();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE {\n        HashMap<Integer, Integer> map = new HashMap<>();\n        boolean[] dp;\n        boolean[] vis;\n        boxPair[] ans;\n\n        int two(int bit) {\n            return 1 << bit;\n        }\n\n        boolean contain(int mask, int bit) {\n            return ((two(bit) & mask) > 0);\n        }\n\n        int get(long val) {\n            if (val > Integer.MAX_VALUE || val < Integer.MIN_VALUE) return -1;\n            int key = (int) val;\n            if (map.containsKey(key) == false) return -1;\n            return map.get(key);\n        }\n\n        boolean rec(int mask, boolean[] hasCycle) {\n            if (hasCycle[mask]) return true;\n            if (vis[mask] == true) return dp[mask];\n            vis[mask] = true;\n            for (int i = mask & (mask - 1); i > 0; i = mask & (i - 1)) {\n                if (rec(i, hasCycle) && rec(i ^ mask, hasCycle)) {\n                    return dp[mask] = true;\n                }\n            }\n            return dp[mask] = false;\n        }\n\n        void findPath(int mask, boolean[] hasCycle, ArrayList<boxPair>[] maskPath) {\n            if (hasCycle[mask]) {\n                for (boxPair b : maskPath[mask]) {\n                    ans[get(b.addTo)] = b;\n                }\n                return;\n            }\n            for (int i = mask & (mask - 1); i > 0; i = mask & (i - 1)) {\n                if (rec(i, hasCycle) && rec(i ^ mask, hasCycle)) {\n                    findPath(i, hasCycle, maskPath);\n                    findPath(i ^ mask, hasCycle, maskPath);\n                    return;\n                }\n            }\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int k = in.nextInt();\n            int[][] a = new int[k][];\n            int[] n = new int[k];\n            long[] sum = new long[k];\n\n            long S = 0;\n            for (int i = 0; i < k; i++) {\n                n[i] = in.nextInt();\n                a[i] = new int[n[i]];\n                for (int j = 0; j < n[i]; j++) {\n                    a[i][j] = in.nextInt();\n                    sum[i] += a[i][j];\n                    map.put(a[i][j], i);\n                }\n                S += sum[i];\n            }\n            if (S % k != 0) out.println(\"No\");\n            else {\n                ArrayList<boxPair>[] maskPath = new ArrayList[two(k)];\n                boolean[] hasCycle = new boolean[two(k)];\n                for (int i = 0; i < two(k); i++) {\n                    maskPath[i] = new ArrayList<>();\n                }\n                long balance = S / k;\n                for (int i = 0; i < k; i++) {\n                    for (int j = 0; j < n[i]; j++) {\n                        long remove = a[i][j];\n                        int curID = i;\n                        int curMask = 0;\n                        ArrayList<boxPair> curPath = new ArrayList<>();\n                        while (true) {\n                            curMask |= two(curID);\n                            remove = (balance - (sum[curID] - remove));\n                            int nxtID = get(remove);\n                            curPath.add(new boxPair(curID, (int) remove));\n                            if (nxtID == i && remove == a[i][j]) {\n                                if (hasCycle[curMask] == false) {\n                                    hasCycle[curMask] = true;\n                                    maskPath[curMask] = curPath;\n                                }\n                                break;\n                            }\n                            if (nxtID == -1 || contain(curMask, nxtID)) break;\n                            curID = nxtID;\n                        }\n                    }\n                }\n                vis = new boolean[two(k)];\n                dp = new boolean[two(k)];\n                if (rec(two(k) - 1, hasCycle) == false) out.println(\"No\");\n                else {\n                    ans = new boxPair[k];\n                    findPath(two(k) - 1, hasCycle, maskPath);\n                    out.println(\"Yes\");\n                    for (int i = 0; i < k; i++) {\n                        out.println(ans[i].addTo + \" \" + (ans[i].boxID + 1));\n                    }\n                }\n            }\n        }\n\n        class boxPair {\n            int boxID;\n            int addTo;\n\n            boxPair(int _boxID, int _addTo) {\n                this.boxID = _boxID;\n                this.addTo = _addTo;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0;\n        private int ptrbuf = 0;\n        static final int[] ints = new int[128];\n\n        public InputReader(InputStream is) {\n            for (int i = '0'; i <= '9'; i++) ints[i] = i - '0';\n            this.is = is;\n        }\n\n        public 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        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = (num << 3) + (num << 1) + ints[b];\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\n\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map.Entry;\nimport java.util.Random;\nimport java.util.TreeSet;\n\npublic final class CF_599_D1_C\n{\n\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;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\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\tstatic long mod=1000000007;\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\n\tstatic class Composite implements Comparable<Composite>{\n\t\tint idx;\n\t\tint v;\n\n\t\tpublic int compareTo(Composite X) {\n\t\t\tif (v!=X.v)\n\t\t\t\treturn v-X.v;\n\t\t\treturn idx-X.idx;\n\n\n\t\t}\n\n\t\tpublic Composite(int idx, int v) {\n\t\t\tthis.idx = idx;\n\t\t\tthis.v = v;\n\t\t}\n\n\n\n\t}\n\n\tstatic void test() {\n\t\tlog(\"testing\");\n\n\t\tlog(\"done\");\n\n\t}\n\n\tstatic void explore(ArrayList<Integer>[] components,ArrayList<Integer> bob,int[][] move,ArrayList<int[]>[] howto,int[][] list) {\n\n\t\tfor (int x:bob) {\n\t\t\tif (components[x].size()==1) {\n\t\t\t\tint tm[]=howto[x].get(0);\n\n\n\t\t\t\tint L=howto[x].size();\n\t\t\t\thowto[x].add(tm);\n\t\t\t\tfor (int i=0;i<L;i++) {\n\t\t\t\t\tint[] cur=howto[x].get(i);\n\t\t\t\t\tint[] nx=howto[x].get(i+1);\n\t\t\t\t\tint a=cur[0];\n\t\t\t\t\tint a2=nx[0];\n\t\t\t\t\tint b2=nx[1];\n\t\t\t\t\tmove[a2][0]=list[a2][b2];\n\t\t\t\t\tmove[a2][1]=a;\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\texplore(components,components[x],move,howto,list);\n\t\t\t}\n\t\t}\n\t}\n\n\n\tstatic void process() throws Exception {\n\n\n\t\t//arrayTest();\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader = new InputReader(System.in);\n\n\n\t\tint k=reader.readInt();\n\t\tint[][] list=new int[k][];\n\t\tlong[] sum=new long[k];\n\t\tint[] L=new int[k];\n\t\tHashMap<Integer,int[]> target=new HashMap<Integer,int[]>();\n\t\tlong tot=0;\n\t\tfor (int i=0;i<k;i++) {\n\t\t\tL[i]=reader.readInt();\n\t\t\tlist[i]=new int[L[i]];\n\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\tlist[i][j]=reader.readInt();\n\t\t\t\tsum[i]+=list[i][j];\n\t\t\t\ttarget.put(list[i][j],new int[] {i,j});\n\t\t\t}\n\t\t\ttot+=sum[i];\n\t\t}\n\n\t\tint MX=1<<k;\n\t\tint AX=1000000001;\n\t\tArrayList<int[]>[] howto=new ArrayList[MX];\n\n\t\tlog(\"ok with the data\");\n\n\t\tif (tot%k!=0) {\n\t\t\toutput(\"No\");\n\t\t} else {\n\n\t\t\ttot/=k;\n\n\n\n\n\n\t\t\tfor (int i=0;i<k;i++) {\n\n\t\t\t\tif (sum[i]==tot) {\n\t\t\t\t\t//log(\"nothing to do for i:\"+i);\n\t\t\t\t\t// nothing to do\n\t\t\t\t\tint mask=1<<i;\n\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\tcand.add(new int[] {i,0});\n\t\t\t\t\thowto[mask]=cand;\n\t\t\t\t} else \n\n\n\t\t\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\t\t\tint u=i;\n\t\t\t\t\t\tint v=j;\n\t\t\t\t\t\tboolean ok=true;\n\t\t\t\t\t\tint src_u=u;\n\t\t\t\t\t\tint src_v=v;\n\t\t\t\t\t\tint mask=0;\n\t\t\t\t\t\tboolean goon=true;\n\t\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\t\t//log(\"start loop\");\n\t\t\t\t\t\twhile (goon) {\n\t\t\t\t\t\t\tcand.add(new int[] {u,v});\n\t\t\t\t\t\t\t//log(\"u:\"+u+\" v:\"+v);\n\t\t\t\t\t\t\tok=false;\n\t\t\t\t\t\t\tgoon=false;\n\t\t\t\t\t\t\tlong need=tot-((long)sum[u]-(long)list[u][v]);\n\t\t\t\t\t\t\tif (Math.abs(need)<=AX) {\n\t\t\t\t\t\t\t\t//log(\"need:\"+need);\n\t\t\t\t\t\t\t\tint nd=(int)need;\n\t\t\t\t\t\t\t\tint[] tm=target.get(nd);\n\t\t\t\t\t\t\t\t//log(\"tm:\"+tm);\n\t\t\t\t\t\t\t\tif (tm!=null) {\n\t\t\t\t\t\t\t\t\t//log(\"can find successor\");\n\t\t\t\t\t\t\t\t\tint nxu=tm[0];\n\t\t\t\t\t\t\t\t\tint nxv=tm[1];\n\t\t\t\t\t\t\t\t\tif ((mask&(1<<nxu))==0) {\n\t\t\t\t\t\t\t\t\t\tmask|=1<<nxu;\n\t\t\t\t\t\t\t\t\t\tif (nxu==src_u) {\n\t\t\t\t\t\t\t\t\t\t\t// looping back to source\n\t\t\t\t\t\t\t\t\t\t\tif (nxv==src_v)\n\t\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tu=nxu;\n\t\t\t\t\t\t\t\t\t\t\tv=nxv;\n\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t\tgoon=true;\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\tif (ok) {\n\t\t\t\t\t\t\tif (howto[mask]==null) {\n\n\t\t\t\t\t\t\t\thowto[mask]=cand;\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}\n\n\t\t\tlog(\"step 1 done\");\n\n\t\t\t// now mask\n\n\n\t\t\tArrayList[] components=new ArrayList[MX];\n\n\n\t\t\tint[] msk=new int[MX];\n\t\t\tint w=0;\n\n\t\t\tfor (int m=0;m<MX;m++) {\n\t\t\t\tif (howto[m]!=null) {\n\t\t\t\t\t//String s=Integer.toBinaryString(m);\n\t\t\t\t\t//while (s.length()<k)\n\t\t\t\t\t//\ts=\"0\"+s;\n\t\t\t\t\t//log(\"found mask:\"+s);\n\t\t\t\t\tcomponents[m]=new ArrayList<Integer>();\n\t\t\t\t\tcomponents[m].add(m);\n\t\t\t\t\tmsk[w++]=m;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint base=w;\n\n\t\t\tfor (int e=0;e<base;e++) {\n\t\t\t\tint a=msk[e];\n\t\t\t\tint ww=w;\n\t\t\t\tfor (int i=0;i<ww;i++) {\n\t\t\t\t\tint b=msk[i];\n\t\t\t\t\tif ((b&a)==0) {\n\t\t\t\t\t\tint c=b|a;\n\t\t\t\t\t\t//log(\"creating c:\"+c+\" \");\n\t\t\t\t\t\tif (components[c]==null ) {\n\t\t\t\t\t\t\tcomponents[c]=new ArrayList<Integer>();\n\t\t\t\t\t\t\tcomponents[c].add(a);\n\t\t\t\t\t\t\tcomponents[c].add(b);\n\t\t\t\t\t\t\tmsk[w++]=c;\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//log(\"msk:\"+msk);\n\t\t\t//log(components[MX-1]);\n\t\t\tif (components[MX-1]!=null) {\n\t\t\t\toutput(\"Yes\");\n\t\t\t\tint[][] move=new int[k][2];\n\t\t\t\texplore(components,components[MX-1],move,howto,list);\n\t\t\t\tfor (int i=0;i<k;i++) {\n\t\t\t\t\toutput(move[i][0]+\" \"+(move[i][1]+1));\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\toutput(\"No\");\n\t\t\t}\n\n\t\t}\n\n\n\t\ttry {\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t}\n\n\t}\n\n\n\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\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\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}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\n\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map.Entry;\nimport java.util.Random;\nimport java.util.TreeSet;\n\npublic final class CF_599_D1_C\n{\n\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;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\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\tstatic long mod=1000000007;\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\n\tstatic class Composite implements Comparable<Composite>{\n\t\tint idx;\n\t\tint v;\n\n\t\tpublic int compareTo(Composite X) {\n\t\t\tif (v!=X.v)\n\t\t\t\treturn v-X.v;\n\t\t\treturn idx-X.idx;\n\n\n\t\t}\n\n\t\tpublic Composite(int idx, int v) {\n\t\t\tthis.idx = idx;\n\t\t\tthis.v = v;\n\t\t}\n\n\n\n\t}\n\n\tstatic void test() {\n\t\tlog(\"testing\");\n\n\t\tlog(\"done\");\n\n\t}\n\n\tstatic void explore(ArrayList<Integer>[] components,ArrayList<Integer> bob,int[][] move,ArrayList<int[]>[] howto,int[][] list) {\n\n\t\tfor (int x:bob) {\n\t\t\tif (components[x].size()==1) {\n\t\t\t\tint tm[]=howto[x].get(0);\n\n\n\t\t\t\tint L=howto[x].size();\n\t\t\t\thowto[x].add(tm);\n\t\t\t\tfor (int i=0;i<L;i++) {\n\t\t\t\t\tint[] cur=howto[x].get(i);\n\t\t\t\t\tint[] nx=howto[x].get(i+1);\n\t\t\t\t\tint a=cur[0];\n\t\t\t\t\tint a2=nx[0];\n\t\t\t\t\tint b2=nx[1];\n\t\t\t\t\tmove[a2][0]=list[a2][b2];\n\t\t\t\t\tmove[a2][1]=a;\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\texplore(components,components[x],move,howto,list);\n\t\t\t}\n\t\t}\n\t}\n\n\n\tstatic void process() throws Exception {\n\n\n\t\t//arrayTest();\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader = new InputReader(System.in);\n\n\n\t\tint k=reader.readInt();\n\t\tint[][] list=new int[k][];\n\t\tlong[] sum=new long[k];\n\t\tint[] L=new int[k];\n\t\tHashMap<Integer,int[]> target=new HashMap<Integer,int[]>();\n\t\tlong tot=0;\n\t\tfor (int i=0;i<k;i++) {\n\t\t\tL[i]=reader.readInt();\n\t\t\tlist[i]=new int[L[i]];\n\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\tlist[i][j]=reader.readInt();\n\t\t\t\tsum[i]+=list[i][j];\n\t\t\t\ttarget.put(list[i][j],new int[] {i,j});\n\t\t\t}\n\t\t\ttot+=sum[i];\n\t\t}\n\n\t\tint MX=1<<k;\n\t\tint AX=1000000001;\n\t\tArrayList<int[]>[] howto=new ArrayList[MX];\n\n\t\tlog(\"ok with the data\");\n\n\t\tif (tot%k!=0) {\n\t\t\toutput(\"No\");\n\t\t} else {\n\n\t\t\ttot/=k;\n\n\n\n\n\n\t\t\tfor (int i=0;i<k;i++) {\n\n\t\t\t\tif (sum[i]==tot) {\n\t\t\t\t\t//log(\"nothing to do for i:\"+i);\n\t\t\t\t\t// nothing to do\n\t\t\t\t\tint mask=1<<i;\n\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\tcand.add(new int[] {i,0});\n\t\t\t\t\thowto[mask]=cand;\n\t\t\t\t} else \n\n\n\t\t\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\t\t\tint u=i;\n\t\t\t\t\t\tint v=j;\n\t\t\t\t\t\tboolean ok=true;\n\t\t\t\t\t\tint src_u=u;\n\t\t\t\t\t\tint src_v=v;\n\t\t\t\t\t\tint mask=0;\n\t\t\t\t\t\tboolean goon=true;\n\t\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\t\t//log(\"start loop\");\n\t\t\t\t\t\twhile (goon) {\n\t\t\t\t\t\t\tcand.add(new int[] {u,v});\n\t\t\t\t\t\t\t//log(\"u:\"+u+\" v:\"+v);\n\t\t\t\t\t\t\tok=false;\n\t\t\t\t\t\t\tgoon=false;\n\t\t\t\t\t\t\tlong need=tot-((long)sum[u]-(long)list[u][v]);\n\t\t\t\t\t\t\tif (Math.abs(need)<=AX) {\n\t\t\t\t\t\t\t\t//log(\"need:\"+need);\n\t\t\t\t\t\t\t\tint nd=(int)need;\n\t\t\t\t\t\t\t\tint[] tm=target.get(nd);\n\t\t\t\t\t\t\t\t//log(\"tm:\"+tm);\n\t\t\t\t\t\t\t\tif (tm!=null) {\n\t\t\t\t\t\t\t\t\t//log(\"can find successor\");\n\t\t\t\t\t\t\t\t\tint nxu=tm[0];\n\t\t\t\t\t\t\t\t\tint nxv=tm[1];\n\t\t\t\t\t\t\t\t\tif ((mask&(1<<nxu))==0) {\n\t\t\t\t\t\t\t\t\t\tmask|=1<<nxu;\n\t\t\t\t\t\t\t\t\t\tif (nxu==src_u) {\n\t\t\t\t\t\t\t\t\t\t\t// looping back to source\n\t\t\t\t\t\t\t\t\t\t\tif (nxv==src_v)\n\t\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tu=nxu;\n\t\t\t\t\t\t\t\t\t\t\tv=nxv;\n\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t\tgoon=true;\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\tif (ok) {\n\t\t\t\t\t\t\tif (howto[mask]==null) {\n\n\t\t\t\t\t\t\t\thowto[mask]=cand;\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}\n\n\t\t\tlog(\"step 1 done\");\n\n\t\t\t// now mask\n\n\t\t\tArrayList<Integer> msk=new ArrayList<Integer>();\n\t\t\tArrayList[] components=new ArrayList[MX];\n\n\t\t\tfor (int m=0;m<MX;m++) {\n\t\t\t\tif (howto[m]!=null) {\n\t\t\t\t\t//String s=Integer.toBinaryString(m);\n\t\t\t\t\t//while (s.length()<k)\n\t\t\t\t\t//\ts=\"0\"+s;\n\t\t\t\t\t//log(\"found mask:\"+s);\n\t\t\t\t\tcomponents[m]=new ArrayList<Integer>();\n\t\t\t\t\tcomponents[m].add(m);\n\t\t\t\t}\n\t\t\t}\n\n\n\n\t\t\tint[] visited=new int[MX];\n\n\n\t\t\tfor (int a=0;a<MX;a++) {\n\t\t\t\tif (howto[a]!=null) {\n\t\t\t\t\tArrayList<Integer> add=new ArrayList<Integer>();\n\t\t\t\t\t\n\t\t\t\t\tfor (int b:msk) {\n\t\t\t\t\t\tif ((b&a)==0) {\n\n\t\t\t\t\t\t\tint c=b|a;\n\t\t\t\t\t\t\tlog(\"creating c:\"+c+\" \");\n\t\t\t\t\t\t\tif (components[c]==null) {\n\t\t\t\t\t\t\t\tcomponents[c]=new ArrayList<Integer>();\n\t\t\t\t\t\t\t\tcomponents[c].add(a);\n\t\t\t\t\t\t\t\tcomponents[c].add(b);\n\t\t\t\t\t\t\t\tadd.add(c);\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\tmsk.add(a);\n\t\t\t\t\tfor (int c:add) {\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tmsk.add(c);\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//log(\"msk:\"+msk);\n\t\t\t//log(components[MX-1]);\n\t\t\tif (components[MX-1]!=null) {\n\t\t\t\toutput(\"Yes\");\n\t\t\t\tint[][] move=new int[k][2];\n\t\t\t\texplore(components,components[MX-1],move,howto,list);\n\t\t\t\tfor (int i=0;i<k;i++) {\n\t\t\t\t\toutput(move[i][0]+\" \"+(move[i][1]+1));\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\toutput(\"No\");\n\t\t\t}\n\n\t\t}\n\n\n\t\ttry {\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t}\n\n\t}\n\n\n\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\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\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}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.util.LinkedHashMap;\nimport java.io.UncheckedIOException;\nimport java.util.Map;\nimport java.io.Closeable;\nimport java.util.Map.Entry;\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            TaskC solver = new TaskC();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class TaskC {\n        SubsetGenerator sg = new SubsetGenerator();\n        Node[] nodes;\n        int n;\n        Map<Long, Node> map;\n        long notExist;\n        long[] mask2Key;\n        Map<Long, LongList> sequence;\n        DigitUtils.BitOperator bo = new DigitUtils.BitOperator();\n        boolean[] dp;\n\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            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            map = new LinkedHashMap<>(200000);\n            for (int i = 0; i < n; i++) {\n                int k = in.readInt();\n                for (int j = 0; j < k; j++) {\n                    long x = in.readInt();\n                    map.put(x, nodes[i]);\n                    nodes[i].sum += x;\n                }\n            }\n\n            long total = 0;\n            for (Node node : nodes) {\n                total += node.sum;\n            }\n\n            if (total % n != 0) {\n                out.println(\"No\");\n                return;\n            }\n            long avg = total / n;\n\n            notExist = (long) 1e18;\n            mask2Key = new long[1 << n];\n            Arrays.fill(mask2Key, notExist);\n            sequence = new HashMap<>(200000);\n\n\n            for (Map.Entry<Long, Node> kv : map.entrySet()) {\n                for (Node node : nodes) {\n                    node.handled = false;\n                }\n\n                long key = kv.getKey();\n\n                Node node = kv.getValue();\n                node.handled = true;\n                int mask = bo.setBit(0, node.id, true);\n\n                LongList list = new LongList(15);\n                list.add(key);\n\n                long req = avg - (node.sum - key);\n                boolean valid = true;\n\n                while (true) {\n                    if (req == key) {\n                        break;\n                    }\n                    Node next = map.get(req);\n                    if (next == null || next.handled) {\n                        valid = false;\n                        break;\n                    }\n                    next.handled = true;\n                    list.add(req);\n                    req = avg - (next.sum - req);\n                    mask = bo.setBit(mask, next.id, true);\n                }\n\n                if (!valid) {\n                    continue;\n                }\n\n                mask2Key[mask] = key;\n                sequence.put(key, list);\n            }\n\n\n            dp = new boolean[1 << n];\n            for (int i = 0; i < (1 << n); i++) {\n                dp[i] = mask2Key[i] != notExist;\n                sg.setSet(i);\n                while (!dp[i] && sg.hasNext()) {\n                    int next = sg.next();\n                    if (next == 0 || next == i) {\n                        continue;\n                    }\n                    dp[i] = dp[i] || (dp[next] && dp[i - next]);\n                }\n            }\n\n            if (!dp[(1 << n) - 1]) {\n                out.println(\"No\");\n                return;\n            }\n\n            populate((1 << n) - 1);\n            out.println(\"Yes\");\n            for (Node node : nodes) {\n                out.append(node.out).append(' ').append(node.to + 1).append('\\n');\n            }\n        }\n\n        public void populate(int mask) {\n            if (mask2Key[mask] != notExist) {\n                LongList list = sequence.get(mask2Key[mask]);\n                int m = list.size();\n                for (int i = 0; i < m; i++) {\n                    long v = list.get(i);\n                    long last = list.get(DigitUtils.mod(i - 1, m));\n                    Node which = map.get(v);\n                    Node to = map.get(last);\n\n                    which.out = v;\n                    which.to = to.id;\n                }\n                return;\n            }\n\n            sg.setSet(mask);\n            while (sg.hasNext()) {\n                int next = sg.next();\n                if (next == 0 || next == mask) {\n                    continue;\n                }\n                if (dp[next] && dp[mask - next]) {\n                    populate(next);\n                    populate(mask - next);\n                    return;\n                }\n            }\n        }\n\n    }\n\n    static class LongList {\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        private void ensureSpace(int need) {\n            int req = size + need;\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(1);\n            data[size++] = x;\n        }\n\n        public int size() {\n            return size;\n        }\n\n        public String toString() {\n            return Arrays.toString(Arrays.copyOf(data, size));\n        }\n\n    }\n\n    static class SubsetGenerator {\n        private int[] meanings = new int[33];\n        private int[] bits = new int[33];\n        private int remain;\n        private int next;\n\n        public void setSet(int set) {\n            int bitCount = 0;\n            while (set != 0) {\n                meanings[bitCount] = set & -set;\n                bits[bitCount] = 0;\n                set -= meanings[bitCount];\n                bitCount++;\n            }\n            remain = 1 << bitCount;\n            next = 0;\n        }\n\n        public boolean hasNext() {\n            return remain > 0;\n        }\n\n        private void consume() {\n            remain = remain - 1;\n            int i;\n            for (i = 0; bits[i] == 1; i++) {\n                bits[i] = 0;\n                next -= meanings[i];\n            }\n            bits[i] = 1;\n            next += meanings[i];\n        }\n\n        public int next() {\n            int returned = next;\n            consume();\n            return returned;\n        }\n\n    }\n\n    static class Node {\n        int id;\n        long sum;\n        boolean handled;\n        long out;\n        long to;\n\n    }\n\n    static class FastInput {\n        private final InputStream is;\n        private byte[] buf = new byte[1 << 13];\n        private int bufLen;\n        private int bufOffset;\n        private int next;\n\n        public FastInput(InputStream is) {\n            this.is = is;\n        }\n\n        private int read() {\n            while (bufLen == bufOffset) {\n                bufOffset = 0;\n                try {\n                    bufLen = is.read(buf);\n                } catch (IOException e) {\n                    bufLen = -1;\n                }\n                if (bufLen == -1) {\n                    return -1;\n                }\n            }\n            return buf[bufOffset++];\n        }\n\n        public void skipBlank() {\n            while (next >= 0 && next <= 32) {\n                next = read();\n            }\n        }\n\n        public int readInt() {\n            int sign = 1;\n\n            skipBlank();\n            if (next == '+' || next == '-') {\n                sign = next == '+' ? 1 : -1;\n                next = read();\n            }\n\n            int val = 0;\n            if (sign == 1) {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 + next - '0';\n                    next = read();\n                }\n            } else {\n                while (next >= '0' && next <= '9') {\n                    val = val * 10 - next + '0';\n                    next = read();\n                }\n            }\n\n            return val;\n        }\n\n    }\n\n    static class FastOutput implements AutoCloseable, Closeable {\n        private StringBuilder cache = new StringBuilder(10 << 20);\n        private final Writer os;\n\n        public FastOutput(Writer os) {\n            this.os = os;\n        }\n\n        public FastOutput(OutputStream os) {\n            this(new OutputStreamWriter(os));\n        }\n\n        public FastOutput 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(String 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 DigitUtils {\n        private static final long[] DIGIT_VALUES = new long[19];\n\n        static {\n            DIGIT_VALUES[0] = 1;\n            for (int i = 1; i < 19; i++) {\n                DIGIT_VALUES[i] = DIGIT_VALUES[i - 1] * 10;\n            }\n        }\n\n        private DigitUtils() {\n        }\n\n        public static int mod(int x, int mod) {\n            x %= mod;\n            if (x < 0) {\n                x += mod;\n            }\n            return x;\n        }\n\n        public static class BitOperator {\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        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tstatic int K;\n\tstatic int sz[];\n\tstatic long vs[][];\n\tstatic long curSum[];\n\tstatic HashMap<Long, Integer> valToBucket;\n\tstatic long sum;\n\tstatic int maskIfPick[][];\n\tstatic int dp[];\n\t\n\tstatic int pickId[];\n\tstatic int newBox[];\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tK = in.nextInt();\n\t\tsz = new int[K];\n\t\tvalToBucket = new HashMap<Long, Integer>();\n\t\tvs = new long[K][];\n\t\tcurSum = new long[K];\n\t\tsum = 0;\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tsz[i] = in.nextInt();\n\t\t\tvs[i] = new long[sz[i]];\n\t\t\tfor(int j = 0; j < sz[i]; j++) {\n\t\t\t\tlong v = in.nextLong();\n\t\t\t\tsum += v;\n\t\t\t\tcurSum[i] += v;\n\t\t\t\tvs[i][j] = v;\n\t\t\t\tvalToBucket.put(v, i);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(sum % K != 0) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tsum /= K;\n\t\tmaskIfPick = new int[K][];\n\t\t//go through if i pick each node\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tmaskIfPick[i] = new int[sz[i]];\n\t\t\tfor(int j = 0; j < sz[i]; j++) {\n\t\t\t\t\n\t\t\t\tint mask = (1<<i);\n\t\t\t\tboolean works = false;\n\t\t\t\tlong curLookfor = (sum - (curSum[i]-vs[i][j]));\n\t\t\t\twhile(true) {\n\t\t\t\t\tif(!valToBucket.containsKey(curLookfor)) break;\n\t\t\t\t\tint nextBucket = valToBucket.get(curLookfor);\n\t\t\t\t\tif(nextBucket == i) {\n\t\t\t\t\t\tworks = curLookfor == vs[i][j];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\telse if((mask & (1<<nextBucket)) > 0) break;\n\t\t\t\t\telse {\n\t\t\t\t\t\tmask |= (1<<nextBucket);\n\t\t\t\t\t\tcurLookfor = (sum - (curSum[nextBucket]-curLookfor));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(works) maskIfPick[i][j] = mask;\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"S= \"+sum);\n\t\tdp = new int[1<<K];\n\t\tArrays.fill(dp, -1);\n\t\tint res = go(0);\n\t\tif(res == 0) {\n\t\t\tSystem.out.println(\"No\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"Yes\");\n\t\t\tpickId = new int[K];\n\t\t\tnewBox = new int[K];\n\t\t\tArrays.fill(pickId, -1);\n\t\t\tbuildback(0);\n\t\t\tfor(int i = 0; i < K; i++) {\n\t\t\t\tSystem.out.println(vs[i][pickId[i]]+\" \"+(newBox[i]+1));\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tstatic void pick(int i, int j) {\n//\t\tSystem.out.println(\" Pick \"+i+\" \"+j);\n\t\tif(pickId[i] != -1) return;\n\t\tpickId[i] = j;\n\t\t\n\t\tlong curLookfor = (sum - (curSum[i]-vs[i][j]));\n\t\tint nextBucket = valToBucket.get(curLookfor);\n\t\tnewBox[nextBucket] = i;\n\t\tfor(int k = 0; k < sz[nextBucket]; k++) {\n\t\t\tif(vs[nextBucket][k] == curLookfor) pick(nextBucket, k);\n\t\t}\n\t}\n\t\n\tstatic int go(int mask) {\n\t\tif(mask+1 == (1<<K)) return 1; //got to end\n\t\tif(dp[mask] != -1) return dp[mask];\n\t\t//get first bit that's off\n\t\tint bit = -1;\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tif((mask & (1<<i)) == 0) { bit = i; break;}\n\t\t}\n\t\t\n\t\tint res = 0;\n\t\t//loop through things to take for this bit\n\t\tfor(int take = 0; take < sz[bit]; take++) {\n\t\t\tint newMask = maskIfPick[bit][take];\n\t\t\tif(newMask == 0 || (mask & newMask) > 0) continue;\n\t\t\tres = (res | go(mask | newMask));\n\t\t}\n\t\t\n\t\treturn dp[mask] = res;\n\t}\n\t\n\tstatic void buildback(int mask) {\n\t\tif(mask+1 == (1<<K)) return; //got to end\n\t\t//get first bit that's off\n\t\tint bit = -1;\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tif((mask & (1<<i)) == 0) { bit = i; break;}\n\t\t}\n\t\t\n\t\tint res = 0;\n\t\t//loop through things to take for this bit\n\t\tfor(int take = 0; take < sz[bit]; take++) {\n\t\t\tint newMask = maskIfPick[bit][take];\n\t\t\tif(newMask == 0 || (mask & newMask) > 0) continue;\n\t\t\tres = (res | go(mask | newMask));\n\t\t\tif(res == 1) {\n\t\t\t\tpick(bit, take);\n\t\t\t\tbuildback(mask | newMask);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\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\t\n}\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n    void solve() {\n        int m=ni();\n        long a[][]=new long[m][];\n        HashMap<Long,Integer> mp=new HashMap<>();\n        long TS=0;\n        long sm[]=new long[m];\n        for(int i=0;i<m;i++){\n            int sz=ni();\n            a[i]=new long[sz];\n            for(int j=0;j<sz;j++){\n                a[i][j]=nl();\n                mp.put(a[i][j],i);\n                sm[i]+=a[i][j];\n            }\n            TS+=sm[i];\n        }\n        if(TS%m!=0){\n            pw.println(\"No\");\n            return;\n        }\n        TS/=m;\n        ArrayList<Node> ansForMask[]=new ArrayList[(1<<m)];\n        for(int i=0;i<(1<<m);i++) ansForMask[i]=new ArrayList<>();\n        ArrayList<Node> tempList=new ArrayList<>();\n        int vis[]=new int[m];\n        for(int i=0;i<m;i++){\n            out:for(int j=0;j<a[i].length;j++){\n                int mask=0;\n                tempList.clear();\n                long val=a[i][j],req=Long.MAX_VALUE;\n                int idx=i,idx2;\n                Arrays.fill(vis,0);\n                if(sm[i]==TS){\n                    mask=1<<i;\n                    if(ansForMask[mask].size()==0) ansForMask[mask].add(new Node(val,i,i));\n                    continue;\n                }\n                while(vis[idx]==0){\n                    req=TS-(sm[idx]-val);\n                    if(!mp.containsKey(req)) continue out;\n                    idx2=mp.get(req);\n                    if(vis[idx]==1 || idx==idx2) continue out;\n                    if(vis[idx2]==1) break;\n                //   if(i==0 && j==1) pw.println(idx2+\" \"+req+\" \"+val);\n                    vis[idx]=1;\n                    mask+=(1<<idx);\n                    tempList.add(new Node(req,idx2,idx));\n                    idx=idx2;\n                    val=req;\n\n\n                }\n                if(req!=a[i][j])continue out;\n                mask+=(1<<idx);\n                tempList.add(new Node(a[i][j],i,idx));\n                if(ansForMask[mask].size()==0){\n                  // pw.println(Integer.toBinaryString(mask));\n                    ansForMask[mask].addAll(tempList);\n                }\n            }\n        }\n        int dp[]=new int[1<<m];\n        dp[0]=1;\n       out: for(int mask=1;mask <(1<<m);mask++){\n            if(ansForMask[mask].size()!=0){\n                dp[mask]=1;\n               // pw.println(Integer.toBinaryString(mask)+\" \"+mask);\n                continue;\n            }\n            for(int s=mask;s>0;s=(s-1)&mask){\n                if(dp[s]==1 && dp[mask^s]==1){\n                    dp[mask]=1;\n                    ansForMask[mask].addAll(ansForMask[s]);\n                    ansForMask[mask].addAll(ansForMask[mask^s]);\n                    continue out;\n\n                }\n            }\n        }\n        if(dp[(1<<m)-1]==0){\n           pw.println(\"No\");\n           return;\n        }\n        pw.println(\"Yes\");\n        Pair ans[]=new Pair[m];\n        for(Node p : ansForMask[(1<<m)-1]){\n            ans[p.id1]=new Pair(p.c,p.id2);\n        }\n        for(int i=0;i<m;i++) pw.println(ans[i].c+\" \"+(ans[i].p+1));\n\n\n\n    }\n    class Pair {\n        long c;\n        int p;\n        public Pair(long c,int p){\n            this.c=c;\n            this.p=p;\n        }\n    }\n    class Node{\n        long c;\n        int id1;\n        int id2;\n        public Node(long c,int id1,int id2){\n            this.c=c;\n            this.id1=id1;\n            this.id2=id2;\n        }\n    }\n    long M = (long)1e9+7;\n    // END\n    PrintWriter pw;\n    StringTokenizer st;\n    BufferedReader br;\n\n    void run() throws Exception {\n        br = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n        long s = System.currentTimeMillis();\n        solve();\n        pw.flush();\n    }\n    public static void main(String[] args) throws Exception {\n        new Main().run();\n    }\n\n    String ns() {\n        while (st == null || !st.hasMoreElements()) {\n\n            try {\n                st = new StringTokenizer(br.readLine());\n            } catch (IOException e) {\n                e.printStackTrace();\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    int ni() {\n        return Integer.parseInt(ns());\n    }\n\n    long nl() {\n        return Long.parseLong(ns());\n    }\n\n    double nd() {\n        return Double.parseDouble(ns());\n    }\n}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C599 {\n    static ArrayList<Integer> [] adj;\n    static long [] a; static int [] type;\n    static Map<Long, Integer> map;\n    static int [] vis;\n    static HashSet<Integer> cy;\n    static boolean [] good;\n    static int [] dp;\n    static HashSet<Integer> [] nodes;\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        int k = sc.nextInt();\n        int cur = 0;\n        a = new long[75007]; long sum = 0;\n        type = new int[75007];\n        map = new HashMap<>();\n        long [] typeSum = new long[k];\n        for (int i = 0; i < k; i++) {\n            int n = sc.nextInt(); long temp = sum;\n            for (int j = 0; j < n; j++) {\n                cur++;\n                a[cur] = sc.nextLong();\n                type[cur] = i;\n                map.put(a[cur], cur);\n                sum += a[cur];\n            }\n            typeSum[i] = sum - temp;\n        }\n        boolean notDiv = sum % k != 0;\n        long need = sum / k;\n        int n = cur;\n        adj = new ArrayList[n + 1];\n        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();\n        for (int i = 1; i <= n; i++) {\n            long delta = need - typeSum[type[i]];\n            long find = a[i] + delta;\n            if (map.containsKey(find)) {\n                if (type[map.get(find)] != type[i] || delta == 0) adj[i].add(map.get(find));\n            }\n        }\n        vis = new int[n + 1];\n        good = new boolean[1 << k];\n        good[0] = true;\n        nodes = new HashSet[1 << k];\n        for (int i = 1; i <= n; i++) {\n            if (vis[i] == 0) {\n                cy = new HashSet<>();\n                boolean b = dfs(i);\n                int mask = 0;\n                for (Integer node: cy) {\n                    mask |= (1 << type[node]);\n                }\n                if (mask != 0) nodes[mask] = cy;\n                good[mask] = true;\n            }\n        }\n        dp = new int[1 << k];\n        Arrays.fill(dp, -1);\n        int possible = solve((1 << k) - 1);\n        if (possible == 1 && !notDiv) {\n            ArrayList<Integer> masks = dfs2((1 << k) - 1);\n\n            long [] num = new long[k];\n            int [] ret = new int[k];\n            for (Integer mask: masks) {\n                for (Integer node: nodes[mask]) {\n                    num[type[node]] = a[node];\n                    ret[type[adj[node].get(0)]] = type[node] + 1;\n                }\n            }\n            boolean good = true; Set<Integer> soFar = new HashSet<>();\n            for (int i = 0; i < ret.length; i++) {\n                if (soFar.contains(ret[i])) good = false;\n                soFar.add(ret[i]);\n            }\n            if (!good) {\n                out.println(\"No\");\n                out.close();\n                return;\n            }\n            out.println(\"Yes\");\n            for (int i = 0; i < k; i++) {\n                out.println(num[i] + \" \" + ret[i]);\n            }\n        } else {\n            out.println(\"No\");\n        }\n        out.close();\n    }\n\n    static int solve(int mask) {\n        if (dp[mask] != -1) return dp[mask];\n        if (good[mask]) return dp[mask] = 1;\n        int ret = 0;\n        for (int i = (mask - 1) & mask; i > 0; i = (i - 1) & mask) {\n            ret = solve(i) & solve(mask ^ i);\n            if (ret == 1) break;\n        }\n        return dp[mask] = ret;\n    }\n    static ArrayList<Integer> dfs2(int mask) {\n        ArrayList<Integer> ret = new ArrayList<>();\n        if (good[mask]) {\n            ret.add(mask);\n            return ret;\n        }\n        for (int i = (mask - 1) & mask; i > 0; i = (i - 1) & mask) {\n            if (dp[i] == 1 && dp[mask ^ i] == 1) {\n                ArrayList<Integer> one = dfs2(i);\n                ArrayList<Integer> two = dfs2(mask ^ i);\n                ret.addAll(one); ret.addAll(two);\n                break;\n            }\n        }\n        return ret;\n    }\n\n    static boolean dfs(int cur) {\n        vis[cur] = 1; boolean ret = false;\n        for (Integer next: adj[cur]) {\n            if (vis[next] == 0) {\n                boolean cycle = dfs(next);\n                if (cycle) {\n                    if (!cy.contains(cur)) {\n                        cy.add(cur);\n                        ret = true; break;\n                    }\n                }\n            } else if (vis[next] == 1) {\n                cy.add(next);\n                cy.add(cur);\n                if (next != cur) ret = true;\n                break;\n            }\n        }\n        vis[cur] = 2;\n        return ret;\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}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\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\n\n    public static void main(String[] args) throws IOException {\n        Reader sc = new Reader();\n        int k = sc.nextInt();\n        int[][] buckets = new int[k][];\n        long[] bucketSum = new long[k];\n        Map<Integer, Integer> map = new HashMap<>(k * 10000);\n        long target = 0;\n        for (int i = 0; i < k; i++) {\n            int n = sc.nextInt();\n            int[] arr = new int[n];\n            for (int j = 0; j < n; j++) {\n                arr[j] = sc.nextInt();\n                target += arr[j];\n                map.put(arr[j], i);\n                bucketSum[i] += arr[j];\n            }\n            buckets[i] = arr;\n        }\n        if ((target % k) != 0) {\n            System.out.println(\"No\");\n            return;\n        } else {\n            target /= k;\n        }\n\n        int[] bitmask = new int[1 << (k )];\n        Arrays.fill(bitmask, -1);\n\n\n        for (int i = 0; i < k; i++) {\n            for (int j = 0; j < buckets[i].length; j++) {\n                int start = buckets[i][j];\n                int next = (int) (target - bucketSum[i]) + start;\n\n                Set<Integer> visited = new HashSet<>();\n                Set<Integer> visitedBuckets = new HashSet<>();\n\n                visited.add(start);\n                visitedBuckets.add(i);\n                int bitset = 1 << i;\n\n                while (map.containsKey(next)) {\n                    int bucket = map.get(next);\n                    if (start == next) {\n                        bitmask[bitset] = start;\n                        break;\n                    } else if (visited.contains(next)) {\n                        break;\n                    } else if (visitedBuckets.contains(bucket)) {\n                        break;\n                    }\n                    visited.add(next);\n                    visitedBuckets.add(bucket);\n                    next = (int) (target - bucketSum[bucket]) + next;\n                    bitset |= 1 << bucket;\n                }\n            }\n        }\n\n        boolean[] dp = new boolean[1 << (k ) ];\n        Arrays.fill(dp, false);\n        int[] build = new int[1 << k];\n        Arrays.fill(build, -1);\n\n        for (int i = 0; i < dp.length; i++) {\n            dp[i] = bitmask[i] != -1;\n        }\n        for (int m = 0; m < (1 << k); m++) {\n            if (!dp[m]) {\n                for (int s = m; s != 0; s = (s - 1) & m) {\n                    if (dp[s] && dp[(m ^ s)])   {\n                        dp[m] = true;\n                        build[m] = s;\n                        break;\n                    }\n                }\n            }\n        }\n        System.out.println(dp[dp.length - 1] ? \"Yes\" : \"No\");\n        ArrayList<Integer> path = new ArrayList<>();\n        rec(path, build, bitmask, (1 << k) - 1);\n\n        int[] picked = new int[k];\n        int[] out = new int[k];\n        if (dp[dp.length - 1]) {\n            for (int i : path) {\n                int prev = i;\n                int next = (int) (target - bucketSum[map.get(prev)]) + prev;\n                picked[map.get(next)] = next;\n                out[map.get(next)] = map.get(prev);\n                while (next != i) {\n                    int t = next;\n                    next = (int) (target - bucketSum[map.get(next)]) + next;\n                    prev = t;\n                    out[map.get(next)] = map.get(prev);\n                    picked[map.get(next)] = next;\n\n\n                }\n            }\n            for (int i = 0; i < out.length; i++) {\n                System.out.println((picked[i]) + \" \" + (out[i] + 1));\n            }\n        }\n    }\n\n    public static void rec(ArrayList<Integer> path, int[] build, int[] bitmask, int i) {\n        if (!(i >= 0 && i < bitmask.length)) {\n            return;\n        }\n        if (bitmask[i] != -1) {\n            path.add(bitmask[i]);\n        } else {\n            rec(path, build, bitmask, build[i]);\n            rec(path, build, bitmask, i ^ build[i]);\n        }\n    }\n}\n\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tHashMap<Integer, Integer> valToNode, nodeToVal, whichBox;\n\tint N, ptsTo[], cycleMask[], dfsStack[], tempList[];\n\tArrayDeque<Integer> stack = new ArrayDeque<>();\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tvalToNode = new HashMap<>();\n\t\tnodeToVal = new HashMap<>();\n\t\twhichBox = new HashMap<>();\n\t\t\n\t\tint K = fs.nextInt();\n\t\tint[][] vals = new int[K][], valToNode2 = new int[K][];\n\t\tlong[] sums = new long[K];\n\t\tlong total = 0;\n\t\t\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tint size = fs.nextInt();\n\t\t\tvals[i] = new int[size];\n\t\t\tvalToNode2[i] = new int[size];\n\t\t\tfor(int j = 0; j < size; j++) {\n\t\t\t\tvals[i][j] = fs.nextInt();\n\t\t\t\tsums[i] += vals[i][j];\n\t\t\t\tvalToNode2[i][j] = valToNode.size();\n\t\t\t\tvalToNode.put(vals[i][j], valToNode.size());\n\t\t\t\tnodeToVal.put(valToNode.size()-1, vals[i][j]);\n\t\t\t\twhichBox.put(vals[i][j], i);\n\t\t\t}\n\t\t\ttotal += sums[i];\n\t\t}\n\t\tif(total % K != 0) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\tlong perGroup = total/K;\n\t\t\n\t\tN = valToNode.size();\n\t\tptsTo = new int[N];\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tfor(int j = 0; j < vals[i].length; j++) {\n\t\t\t\tlong newSum = perGroup - (sums[i]-vals[i][j]);\n\t\t\t\tif(newSum > (int)1e9 || newSum < (int)-1e9) continue;\n\t\t\t\tif(valToNode.containsKey((int)newSum)) {\n\t\t\t\t\tptsTo[valToNode.get(vals[i][j])] = valToNode.get((int)newSum);\n\t\t\t\t}\n\t\t\t\telse ptsTo[valToNode.get(vals[i][j])] = -1;\n\t\t\t}\n\t\t}\n\t\t\n\t\ttempList = new int[N];\n\t\tdfsStack = new int[N];\n\t\tcycleMask = new int[N];\n\t\t\n\t\tfor(int i = 0; i < K; i++) {\n\t\t\tfor(int j = 0; j < vals[i].length; j++) {\n\t\t\t\tint node = valToNode.get(vals[i][j]);\n\t\t\t\tif(dfsStack[node] == 0) dfs(node);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] goodMask = new int[1<<K];\n\t\tArrays.fill(goodMask, -1); goodMask[0] = 0;\n\t\tfor(int mask = 1; mask < goodMask.length; mask++) {\n\t\t\tint idx = Integer.numberOfTrailingZeros(Integer.lowestOneBit(mask));\n\t\t\tfor(int i = 0; i < vals[idx].length; i++) {\n\t\t\t\tint node = valToNode2[idx][i];\n\t\t\t\tif(cycleMask[node] == mask) {\n\t\t\t\t\tgoodMask[mask] = node;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] dp = new int[1<<K];\n\t\tArrays.fill(dp, -1); dp[0] = 0;\n\t\tfor(int mask = 1; mask < dp.length; mask++) {\n\t\t\tif(goodMask[mask] != -1) {\n\t\t\t\tdp[mask] = mask;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor(int sub = mask; sub != 0; sub = (sub-1)&mask) {\n\t\t\t\tif(goodMask[sub] == -1) continue;\n\t\t\t\tint newMask = mask-sub;\n\t\t\t\tif(dp[newMask] == -1) continue;\n\t\t\t\t\n\t\t\t\tdp[mask] = sub;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(dp[dp.length-1] == -1) out.println(\"No\");\n\t\telse {\n\t\t\tint[][] res = new int[K][2];\n\t\t\tfor(int[] x : res) Arrays.fill(x, -1);\n\t\t\tint curMask = dp.length-1;\n\t\t\twhile(curMask > 0) {\n\t\t\t\tint temp = dp[curMask];\n\t\t\t\tint curNode = goodMask[temp];\n\t\t\t\t\n\t\t\t\twhile(temp > 0) {\n\t\t\t\t\tint curVal = nodeToVal.get(curNode), curBox = whichBox.get(curVal);\n\t\t\t\t\tres[curBox][0] = curVal;\n\t\t\t\t\tint goingTo = ptsTo[curNode], goingVal = nodeToVal.get(goingTo), goingBox = whichBox.get(goingVal);\n\t\t\t\t\tres[goingBox][1] = curBox;\n\t\t\t\t\tcurNode = ptsTo[curNode];\n\t\t\t\t\ttemp -= 1<<curBox;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tcurMask -= dp[curMask];\n\t\t\t}\n\t\t\t\n\t\t\tout.println(\"Yes\");\n\t\t\tfor(int i = 0; i < K; i++) {\n\t\t\t\tif(res[i][1] == -1) throw null;\n\t\t\t\tout.printf(\"%d %d\\n\", res[i][0], res[i][1]+1);\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\tvoid dfs(int node) {\n\t\tdfsStack[node] = 1;\n\t\tstack.addLast(node);\n\t\tint goTo = ptsTo[node];\n\t\tif(goTo == -1) {\n\t\t\twhile(!stack.isEmpty()) {\n\t\t\t\tcycleMask[stack.pollLast()] = -1;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif(dfsStack[goTo] == 1) {\n\t\t\t\tint ptr = 0, mask = 0, conflict = 0;\n\t\t\t\twhile(!stack.isEmpty()) {\n\t\t\t\t\tint now = stack.pollLast(), val = nodeToVal.get(now), box = whichBox.get(val);\n\t\t\t\t\ttempList[ptr++] = now;\n\t\t\t\t\tif((mask & (1<<box)) > 0) conflict = 1;\n\t\t\t\t\tmask |= 1<<box;\n\t\t\t\t\t\n\t\t\t\t\tif(now == goTo) break;\n\t\t\t\t}\n\t\t\t\twhile(!stack.isEmpty()) {\n\t\t\t\t\tcycleMask[stack.pollLast()] = -1;\n\t\t\t\t}\n\t\t\t\tfor(int i = 0; i < ptr; i++) {\n\t\t\t\t\tint now = tempList[i];\n\t\t\t\t\tif(conflict > 0) cycleMask[now] = -1;\n\t\t\t\t\telse cycleMask[now] = mask;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(dfsStack[goTo] == 2) {\n\t\t\t\twhile(!stack.isEmpty()) {\n\t\t\t\t\tcycleMask[stack.pollLast()] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdfs(goTo);\n\t\t\t}\n\t\t}\n\t\t\n\t\tdfsStack[node] = 2;\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}\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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        int n;\n        int[] bitCount;\n        long neededSum;\n        long[] sums;\n        Map<Long, Integer> where;\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            n = in.nextInt();\n            int[][] a = new int[n][];\n            neededSum = 0;\n            sums = new long[n];\n            for (int i = 0; i < n; i++) {\n                int k = in.nextInt();\n                a[i] = new int[k];\n                for (int j = 0; j < k; j++) {\n                    a[i][j] = in.nextInt();\n                    neededSum += a[i][j];\n                    sums[i] += a[i][j];\n                }\n            }\n\n            if (neededSum % n != 0) {\n                out.println(\"No\");\n                return;\n            }\n            neededSum /= n;\n\n            where = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < a[i].length; j++) {\n                    where.put((long) a[i][j], i);\n                }\n            }\n            bitCount = new int[1 << n];\n            for (int i = 0; i < bitCount.length; i++) {\n                bitCount[i] = Integer.bitCount(i);\n            }\n\n            Entry[][] cycleSol = new Entry[1 << n][];\n\n            List<Entry> sol = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                for (int x : a[i]) {\n                    search(i, i, x, x, 0, 0, sol, cycleSol);\n                }\n            }\n\n            boolean[] can = new boolean[1 << n];\n            int[] via = new int[1 << n];\n            can[0] = true;\n            for (int mask = 0; mask < 1 << n; mask++) {\n                for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {\n                    if (cycleSol[submask] != null && can[mask ^ submask]) {\n                        can[mask] = true;\n                        via[mask] = submask;\n                    }\n                }\n            }\n\n            if (!can[(1 << n) - 1]) {\n                out.println(\"No\");\n                return;\n            }\n\n            int[][] ans = new int[n][2];\n            for (int mask = (1 << n) - 1; mask > 0; ) {\n                int sm = via[mask];\n                mask ^= sm;\n\n                for (Entry e : cycleSol[sm]) {\n                    ans[e.from][0] = e.what;\n                    ans[e.from][1] = e.to + 1;\n                }\n            }\n\n            out.println(\"Yes\");\n            for (int i = 0; i < n; i++) {\n                out.println(ans[i][0] + \" \" + ans[i][1]);\n            }\n        }\n\n        private void search(int start, int cur, long fromStart, long fromCur, int hasIn, int hasOut, List<Entry> sol, Entry[][] cycleSol) {\n            for (int i = 0; i < n; i++) {\n                if ((hasIn & (1 << i)) > 0) {\n                    continue;\n                }\n                if ((hasOut & (1 << cur)) > 0) {\n                    continue;\n                }\n                long fromI = sums[i] + fromCur - neededSum;\n                Integer w = where.get(fromI);\n                if (w == null || w != i) {\n                    continue;\n                }\n                sol.add(new Entry(cur, i, (int) fromCur));\n                int nHasIn = hasIn | (1 << i);\n                int nHasOut = hasOut | (1 << cur);\n                if (i == start && fromI == fromStart) {\n                    cycleSol[nHasOut] = sol.toArray(new Entry[0]);\n                }\n                search(start, i, fromStart, fromI, nHasIn, nHasOut, sol, cycleSol);\n                sol.remove(sol.size() - 1);\n            }\n        }\n\n        class Entry {\n            int from;\n            int to;\n            int what;\n\n            Entry(int from, int to, int what) {\n                this.from = from;\n                this.to = to;\n                this.what = what;\n            }\n\n            public String toString() {\n                return from + \" \" + to + \" \" + what;\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                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class a implements Runnable{\n\t\n    public static void main(String[] args) {\n        new Thread(null, new a(), \"process\", 1<<26).start();\n    }\n\tpublic void run() {\n\t\tFastReader scan = new FastReader();\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t//PrintWriter out = new PrintWriter(\"file.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\t\tstatic final int inf = Integer.MAX_VALUE;\n\n\t\tpublic void solve(int testNumber, FastReader sc, PrintWriter pw) {\n\t\t\t//CHECK FOR QUICKSORT TLE\n\t\t\t//***********************//\n\t\t\t//CHECK FOR INT OVERFLOW\n\t\t\t//***********************//\n\t\t\tint n = sc.nextInt();\n\t\t\tint[][] arr = new int[n][];\n\t\t\tlong sums[] = new long[n];\n\t\t\tHashMap<Integer, Integer> map1 = new HashMap<>();\n\t\t\tHashMap<Integer, Integer> map2 = new HashMap<>();\n\t\t\tArrayList<Integer> arrs = new ArrayList<Integer>();\n\t\t\tarrs.add(0);\n\t\t\tint incc = 1;\n\t\t\tlong sum = 0;\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tint k = sc.nextInt();\n\t\t\t\tarr[i] = new int[k];\n\t\t\t\tfor(int j = 0; j < k; j++) {\n\t\t\t\t\tsum += (arr[i][j] = sc.nextInt());\n\t\t\t\t\tsums[i] += arr[i][j];\n\t\t\t\t\tmap1.put(arr[i][j], incc++);\n\t\t\t\t\tmap2.put(arr[i][j], i);\n\t\t\t\t\tarrs.add(arr[i][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(sum % n != 0) {\n\t\t\t\tpw.println(\"No\");\n\t\t\t\treturn; \n\t\t\t}\n\t\t\tcycle[] masktocyc = new cycle[1<<n];\n\t\t\tlong goal = sum / n;\n\t\t\tArrayList<cycle> cycs = new ArrayList<cycle>();\n\t\t\tint[] graph = new int[incc];\n\t\t\tl:\n\t\t\tfor(int i = 1; i < incc; i++) {\n\t\t\t\tcycle c = new cycle();\n\t\t\t\tint curr = i;\n\t\t\t\tint val = arrs.get(i);\n\t\t\t\tint ind = map2.get(val);\n\t\t\t\tif(graph[i] != 0) continue;\n\t\t\t\tdo {\n\t\t\t\t\tlong ch = (goal - sums[ind] + val);\n\t\t\t\t\tif(ch > inf || ch < -inf || !map1.containsKey((int)ch)) {\n\t\t\t\t\t\tcontinue l;\n\t\t\t\t\t}\n\t\t\t\t\tval = (int)(ch);\n\t\t\t\t\tgraph[curr] = map1.get(val);\n\t\t\t\t\t//pw.println(curr + \" - \" + map1.get(ch));\n\t\t\t\t\tcurr = map1.get(val);\n\t\t\t\t\tc.add(ind, val);\n\t\t\t\t\tind = map2.get(val);\n\t\t\t\t}\n\t\t\t\twhile(graph[curr] == 0);\n\t\t\t\tfor(tup x : c.arr) {\n\t\t\t\t\tif(sums[x.a] - arrs.get(curr) + x.b == goal) break;\n\t\t\t\t\tc.mask -= (1<<x.a);\n\t\t\t\t\tx.a = -inf;\n\t\t\t\t\tx.b = -inf;\n\t\t\t\t}\n\t\t\t\tint[] freq = new int[15];\n\t\t\t\tfor(tup x : c.arr) {\n\t\t\t\t\tif(x.a >= 0) {\n\t\t\t\t\t\tfreq[x.a]++;\n\t\t\t\t\t\tif(freq[x.a] > 1) continue l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t//for(tup x : c.arr) System.out.printf(\"%d %d%n\", x.a, x.b);\n\t\t\t\t//System.out.println(c.mask);\n\t\t\t\tcycs.add(c);\n\t\t\t\tmasktocyc[c.mask] = c;\n\t\t\t}\n\t\t\t\n\t\t\tArrayList<cycle>[] dp = new ArrayList[1<<n];\n\t\t\tfor(int m = 0; m < (1<<n); m++) {\n\t\t\t\tdp[m] = new ArrayList<cycle>();\n\t\t\t\tif(masktocyc[m] != null) {\n\t\t\t\t\tdp[m].add(masktocyc[m]);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor(int s = m; s > 0; s = (s - 1) & m) {\n\t\t\t\t\tif(dp[s].size() > 0 && dp[m ^ s].size() > 0) {\n\t\t\t\t\t\tdp[m].addAll(dp[s]);\n\t\t\t\t\t\tdp[m].addAll(dp[m ^ s]);\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(dp[(1<<n) - 1].size() > 0) {\n\t\t\t\tpw.println(\"Yes\");\n\t\t\t\tint[] ans1 = new int[n];\n\t\t\t\tint[] ans2 = new int[n];\n\t\t\t\tfor(cycle x : dp[(1<<n) - 1]) {\n\t\t\t\t\tfor(tup y : x.arr) {\n\t\t\t\t\t\tif(y.b != -inf) {\n\t\t\t\t\t\t\tans1[map2.get(y.b)] = y.a+1;\n\t\t\t\t\t\t\tans2[map2.get(y.b)] = y.b;\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 < n; i++) {\n\t\t\t\t\tpw.printf(\"%d %d%n\", ans2[i], ans1[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse pw.println(\"No\");\n\t\t}\n\t\tstatic class cycle {\n\t\t\tArrayList<tup> arr = new ArrayList<>();\n\t\t\tint mask = 0;\n\t\t\tpublic cycle(){}\n\t\t\tvoid add(int ind, int val) {\n\t\t\t\tarr.add(new tup(ind, val));\n\t\t\t\tmask += (1<<ind);\n\t\t\t}\n\t\t}\n\t}\n\tstatic long binpow(long a, long b, long m) {\n\t\ta %= m;\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) == 1)\n\t\t\t\tres = res * a % m;\n\t\t\ta = a * a % m;\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic void sort(int[] x){\n\t\tshuffle(x);\n\t\tArrays.sort(x);\n\t}\n\tstatic void sort(long[] x){\n\t\tshuffle(x);\n\t\tArrays.sort(x);\n\t}\n\tstatic class tup implements Comparable<tup>{\n\t\tint a, b;\n\t\ttup(int a,int b){\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(tup o){\n\t\t\treturn Integer.compare(o.b,b);\n\t\t}\n\t}\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(i + 1);\n\t\t\tint temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic void shuffle(long[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(i + 1);\n\t\t\tlong temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastReader(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(new File(s)));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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        int n;\n        long neededSum;\n        long[] sums;\n        Map<Long, Integer> where;\n\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            n = in.nextInt();\n            int[][] a = new int[n][];\n            neededSum = 0;\n            sums = new long[n];\n            for (int i = 0; i < n; i++) {\n                int k = in.nextInt();\n                a[i] = new int[k];\n                for (int j = 0; j < k; j++) {\n                    a[i][j] = in.nextInt();\n                    neededSum += a[i][j];\n                    sums[i] += a[i][j];\n                }\n            }\n\n            if (neededSum % n != 0) {\n                out.println(\"No\");\n                return;\n            }\n            neededSum /= n;\n\n            where = new HashMap<>();\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < a[i].length; j++) {\n                    where.put((long) a[i][j], i);\n                }\n            }\n\n            Entry[][] cycleSol = new Entry[1 << n][];\n            List<Entry> sol = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                for (int x : a[i]) {\n                    search(i, i, x, x, 0, 0, sol, cycleSol);\n                }\n            }\n\n            boolean[] can = new boolean[1 << n];\n            int[] via = new int[1 << n];\n            can[0] = true;\n            for (int mask = 0; mask < 1 << n; mask++) {\n                for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {\n                    if (cycleSol[submask] != null && can[mask ^ submask]) {\n                        can[mask] = true;\n                        via[mask] = submask;\n                    }\n                }\n            }\n\n            if (!can[(1 << n) - 1]) {\n                out.println(\"No\");\n                return;\n            }\n\n            int[][] ans = new int[n][2];\n            for (int mask = (1 << n) - 1; mask > 0; ) {\n                int sm = via[mask];\n                mask ^= sm;\n\n                for (Entry e : cycleSol[sm]) {\n                    ans[e.from][0] = e.what;\n                    ans[e.from][1] = e.to + 1;\n                }\n            }\n\n            out.println(\"Yes\");\n            for (int i = 0; i < n; i++) {\n                out.println(ans[i][0] + \" \" + ans[i][1]);\n            }\n        }\n\n        private void search(int start, int cur, long fromStart, long fromCur, int hasIn, int hasOut, List<Entry> sol, Entry[][] cycleSol) {\n            for (int i = start; i < n; i++) {\n                if ((hasIn & (1 << i)) > 0) {\n                    continue;\n                }\n                if ((hasOut & (1 << cur)) > 0) {\n                    continue;\n                }\n                long fromI = sums[i] + fromCur - neededSum;\n                Integer w = where.get(fromI);\n                if (w == null || w != i) {\n                    continue;\n                }\n                sol.add(new Entry(cur, i, (int) fromCur));\n                int nHasIn = hasIn | (1 << i);\n                int nHasOut = hasOut | (1 << cur);\n                if (i == start && fromI == fromStart) {\n                    cycleSol[nHasOut] = sol.toArray(new Entry[0]);\n                }\n                search(start, i, fromStart, fromI, nHasIn, nHasOut, sol, cycleSol);\n                sol.remove(sol.size() - 1);\n            }\n        }\n\n        class Entry {\n            int from;\n            int to;\n            int what;\n\n            Entry(int from, int to, int what) {\n                this.from = from;\n                this.to = to;\n                this.what = what;\n            }\n\n            public String toString() {\n                return from + \" \" + to + \" \" + what;\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                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "//package round599;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Map;\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();\n\t\tint[][] a = new int[n][];\n\t\tMap<Long, Long> ci = new HashMap<>();\n\t\tlong[] sums = new long[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint K = ni();\n\t\t\ta[i] = na(K);\n\t\t\tfor(int j = 0;j < K;j++){\n\t\t\t\tci.put((long)a[i][j], (long)i<<32|j);\n\t\t\t\tsums[i] += a[i][j];\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong S = 0;\n\t\tfor(long v : sums){\n\t\t\tS += v;\n\t\t}\n\t\tif(S % n != 0){\n\t\t\tout.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\tS /= n;\n\t\t\n\t\tint[] offsets = new int[n+1];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\toffsets[i+1] = offsets[i] + a[i].length;\n\t\t}\n\t\t\n\t\tint m = offsets[n];\n\t\tint[] f = new int[m];\n\t\tArrays.fill(f, -1);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < a[i].length;j++){\n\t\t\t\tlong T = a[i][j] + S - sums[i];\n\t\t\t\tif(ci.containsKey(T)){\n\t\t\t\t\tlong code = ci.get(T);\n\t\t\t\t\tint from = offsets[i] + j;\n\t\t\t\t\tint to = offsets[(int)(code>>>32)] + (int)code;\n\t\t\t\t\tif(from != to && i == (int)(code>>>32))continue;\n\t\t\t\t\tf[from] = to;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[][] cs = getCycles(f);\n\t\tint[][] zcs = new int[1<<n][];\n\t\tfor(int[] c : cs){\n\t\t\tint ptn = 0;\n\t\t\tfor(int k : c){\n\t\t\t\tint ind = Arrays.binarySearch(offsets, k);\n\t\t\t\tif(ind < 0)ind = -ind-2;\n\t\t\t\tptn |= 1<<ind;\n\t\t\t}\n\t\t\tif(Integer.bitCount(ptn) != c.length)continue;\n\t\t\tzcs[ptn] = c;\n\t\t}\n\t\t\n\t\tboolean[] dp = new boolean[1<<n];\n\t\tdp[0] = true;\n\t\tfor(int i = 1;i < 1<<n;i++){\n\t\t\tif(zcs[i] != null){\n\t\t\t\tint mask = (1<<n)-1^i;\n\t\t\t\tfor(int j = mask;j >= 0;j--){ j &= mask; \n\t\t\t\t\tdp[i|j] |= dp[j];\n\t\t\t\t} // include j=0\n\t\t\t}\n\t\t}\n\t\tif(dp[(1<<n)-1]){\n\t\t\tint[] vals = new int[n];\n\t\t\tint[] tos = new int[n];\n\t\t\t\n\t\t\tint cur = (1<<n)-1;\n\t\t\tinner:\n\t\t\twhile(cur > 0){\n\t\t\t\tfor(int k = cur;k >= 0;k--){\n\t\t\t\t\tk &= cur;\n\t\t\t\t\tif(dp[cur^k] && zcs[k] != null){\n\t\t\t\t\t\tfor(int l = 0;l < zcs[k].length;l++){\n\t\t\t\t\t\t\tint nl = (l+zcs[k].length-1) % zcs[k].length;\n\t\t\t\t\t\t\tint fclus = Arrays.binarySearch(offsets, zcs[k][l]);\n\t\t\t\t\t\t\tint tclus = Arrays.binarySearch(offsets, zcs[k][nl]);\n\t\t\t\t\t\t\tif(fclus < 0)fclus = -fclus-2;\n\t\t\t\t\t\t\tif(tclus < 0)tclus = -tclus-2;\n\t\t\t\t\t\t\tint val = a[fclus][zcs[k][l]-offsets[fclus]];\n\t\t\t\t\t\t\tvals[fclus] = val;\n\t\t\t\t\t\t\ttos[fclus] = tclus;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur ^= k;\n\t\t\t\t\t\tcontinue inner;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tout.println(\"Yes\");\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tout.println(vals[i] + \" \" + (tos[i]+1));\n\t\t\t}\n\t\t\t\n//\t\t\tfor(int i = 0;i < n;i++){\n//\t\t\t\tsums[i] -= vals[i];\n//\t\t\t\tsums[tos[i]] += vals[i];\n//\t\t\t}\n//\t\t\t\n//\t\t\tfor(int i = 0;i < n;i++){\n//\t\t\t\tassert sums[i] == S;\n//\t\t\t}\n\t\t\t\n\t\t}else{\n\t\t\tout.println(\"No\");\n\t\t}\n\t}\n\t\n\t\n\tint[][] getCycles(int[] f)\n\t{\n\t\tint n = f.length;\n\t\tint[][] ret = new int[n][];\n\t\tboolean[] ved = new boolean[n];\n\t\tint[] touched = new int[n];\n\t\tArrays.fill(touched, -1);\n\t\tint[] path = new int[n];\n\t\tint q = 0;\n\t\touter:\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint p = 0;\n\t\t\tfor(int j = i;j != -1;j = f[j]){\n\t\t\t\tif(touched[j] != -1){\n\t\t\t\t\tret[q++] = Arrays.copyOfRange(path, touched[j], p);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(ved[j])break;\n\t\t\t\ttouched[j] = p;\n\t\t\t\tpath[p++] = j;\n\t\t\t\tved[j] = true;\n\t\t\t}\n\t\t\tfor(int k = 0;k < p;k++){\n\t\t\t\ttouched[path[k]] = -1;\n\t\t\t}\n\t\t}\n\t\treturn Arrays.copyOf(ret, q);\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 C().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", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\n\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map.Entry;\nimport java.util.Random;\nimport java.util.TreeSet;\n\npublic final class CF_599_D1_C\n{\n\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;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\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\tstatic long mod=1000000007;\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\n\tstatic class Composite implements Comparable<Composite>{\n\t\tint idx;\n\t\tint v;\n\n\t\tpublic int compareTo(Composite X) {\n\t\t\tif (v!=X.v)\n\t\t\t\treturn v-X.v;\n\t\t\treturn idx-X.idx;\n\n\n\t\t}\n\n\t\tpublic Composite(int idx, int v) {\n\t\t\tthis.idx = idx;\n\t\t\tthis.v = v;\n\t\t}\n\n\n\n\t}\n\n\tstatic void test() {\n\t\tlog(\"testing\");\n\n\t\tlog(\"done\");\n\n\t}\n\n\tstatic void explore(ArrayList<Integer>[] components,ArrayList<Integer> bob,int[][] move,ArrayList<int[]>[] howto,int[][] list) {\n\n\t\tfor (int x:bob) {\n\t\t\tif (components[x].size()==1) {\n\t\t\t\tint tm[]=howto[x].get(0);\n\n\n\t\t\t\tint L=howto[x].size();\n\t\t\t\thowto[x].add(tm);\n\t\t\t\tfor (int i=0;i<L;i++) {\n\t\t\t\t\tint[] cur=howto[x].get(i);\n\t\t\t\t\tint[] nx=howto[x].get(i+1);\n\t\t\t\t\tint a=cur[0];\n\t\t\t\t\tint a2=nx[0];\n\t\t\t\t\tint b2=nx[1];\n\t\t\t\t\tmove[a2][0]=list[a2][b2];\n\t\t\t\t\tmove[a2][1]=a;\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\texplore(components,components[x],move,howto,list);\n\t\t\t}\n\t\t}\n\t}\n\n\n\tstatic void process() throws Exception {\n\n\n\t\t//arrayTest();\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader = new InputReader(System.in);\n\n\n\t\tint k=reader.readInt();\n\t\tint[][] list=new int[k][];\n\t\tlong[] sum=new long[k];\n\t\tint[] L=new int[k];\n\t\tHashMap<Integer,int[]> target=new HashMap<Integer,int[]>();\n\t\tlong tot=0;\n\t\tfor (int i=0;i<k;i++) {\n\t\t\tL[i]=reader.readInt();\n\t\t\tlist[i]=new int[L[i]];\n\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\tlist[i][j]=reader.readInt();\n\t\t\t\tsum[i]+=list[i][j];\n\t\t\t\ttarget.put(list[i][j],new int[] {i,j});\n\t\t\t}\n\t\t\ttot+=sum[i];\n\t\t}\n\n\t\tint MX=1<<k;\n\t\tint AX=1000000001;\n\t\tArrayList<int[]>[] howto=new ArrayList[MX];\n\n\t\tlog(\"ok with the data\");\n\n\t\tif (tot%k!=0) {\n\t\t\toutput(\"No\");\n\t\t} else {\n\n\t\t\ttot/=k;\n\n\n\n\n\n\t\t\tfor (int i=0;i<k;i++) {\n\n\t\t\t\tif (sum[i]==tot) {\n\t\t\t\t\t//log(\"nothing to do for i:\"+i);\n\t\t\t\t\t// nothing to do\n\t\t\t\t\tint mask=1<<i;\n\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\tcand.add(new int[] {i,0});\n\t\t\t\t\thowto[mask]=cand;\n\t\t\t\t} else \n\n\n\t\t\t\t\tfor (int j=0;j<L[i];j++) {\n\t\t\t\t\t\tint u=i;\n\t\t\t\t\t\tint v=j;\n\t\t\t\t\t\tboolean ok=true;\n\t\t\t\t\t\tint src_u=u;\n\t\t\t\t\t\tint src_v=v;\n\t\t\t\t\t\tint mask=0;\n\t\t\t\t\t\tboolean goon=true;\n\t\t\t\t\t\tArrayList<int[]> cand=new ArrayList<int[]>();\n\t\t\t\t\t\t//log(\"start loop\");\n\t\t\t\t\t\twhile (goon) {\n\t\t\t\t\t\t\tcand.add(new int[] {u,v});\n\t\t\t\t\t\t\t//log(\"u:\"+u+\" v:\"+v);\n\t\t\t\t\t\t\tok=false;\n\t\t\t\t\t\t\tgoon=false;\n\t\t\t\t\t\t\tlong need=tot-((long)sum[u]-(long)list[u][v]);\n\t\t\t\t\t\t\tif (Math.abs(need)<=AX) {\n\t\t\t\t\t\t\t\t//log(\"need:\"+need);\n\t\t\t\t\t\t\t\tint nd=(int)need;\n\t\t\t\t\t\t\t\tint[] tm=target.get(nd);\n\t\t\t\t\t\t\t\t//log(\"tm:\"+tm);\n\t\t\t\t\t\t\t\tif (tm!=null) {\n\t\t\t\t\t\t\t\t\t//log(\"can find successor\");\n\t\t\t\t\t\t\t\t\tint nxu=tm[0];\n\t\t\t\t\t\t\t\t\tint nxv=tm[1];\n\t\t\t\t\t\t\t\t\tif ((mask&(1<<nxu))==0) {\n\t\t\t\t\t\t\t\t\t\tmask|=1<<nxu;\n\t\t\t\t\t\t\t\t\t\tif (nxu==src_u) {\n\t\t\t\t\t\t\t\t\t\t\t// looping back to source\n\t\t\t\t\t\t\t\t\t\t\tif (nxv==src_v)\n\t\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tu=nxu;\n\t\t\t\t\t\t\t\t\t\t\tv=nxv;\n\t\t\t\t\t\t\t\t\t\t\tok=true;\n\t\t\t\t\t\t\t\t\t\t\tgoon=true;\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\tif (ok) {\n\t\t\t\t\t\t\tif (howto[mask]==null) {\n\n\t\t\t\t\t\t\t\thowto[mask]=cand;\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}\n\n\t\t\tlog(\"step 1 done\");\n\n\t\t\t// now mask\n\n\t\t\n\t\t\tArrayList[] components=new ArrayList[MX];\n\n\t\t\tfor (int m=0;m<MX;m++) {\n\t\t\t\tif (howto[m]!=null) {\n\t\t\t\t\t//String s=Integer.toBinaryString(m);\n\t\t\t\t\t//while (s.length()<k)\n\t\t\t\t\t//\ts=\"0\"+s;\n\t\t\t\t\t//log(\"found mask:\"+s);\n\t\t\t\t\tcomponents[m]=new ArrayList<Integer>();\n\t\t\t\t\tcomponents[m].add(m);\n\t\t\t\t}\n\t\t\t}\n\n\n\n\t\n\t\t\tint[] msk=new int[MX];\n\t\t\tint w=0;\n\t\t\t\n\t\t\tfor (int a=0;a<MX;a++) {\n\t\t\t\tif (howto[a]!=null) {\n\t\t\t\t\tArrayList<Integer> add=new ArrayList<Integer>();\n\t\t\t\t\t\n\t\t\t\t\tint ww=w;\n\t\t\t\t\tfor (int i=0;i<ww;i++) {\n\t\t\t\t\t\tint b=msk[i];\n\t\t\t\t\t\tif ((b&a)==0) {\n\n\t\t\t\t\t\t\tint c=b|a;\n\t\t\t\t\t\t\t//log(\"creating c:\"+c+\" \");\n\t\t\t\t\t\t\tif (components[c]==null ) {\n\t\t\t\t\t\t\t\tcomponents[c]=new ArrayList<Integer>();\n\t\t\t\t\t\t\t\tcomponents[c].add(a);\n\t\t\t\t\t\t\t\tcomponents[c].add(b);\n\t\t\t\t\t\t\t\tmsk[w++]=c;\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\tmsk[w++]=a;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//log(\"msk:\"+msk);\n\t\t\t//log(components[MX-1]);\n\t\t\tif (components[MX-1]!=null) {\n\t\t\t\toutput(\"Yes\");\n\t\t\t\tint[][] move=new int[k][2];\n\t\t\t\texplore(components,components[MX-1],move,howto,list);\n\t\t\t\tfor (int i=0;i<k;i++) {\n\t\t\t\t\toutput(move[i][0]+\" \"+(move[i][1]+1));\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\toutput(\"No\");\n\t\t\t}\n\n\t\t}\n\n\n\t\ttry {\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t}\n\n\t}\n\n\n\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\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\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}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\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.HashMap;\nimport java.util.HashSet;\nimport java.util.NoSuchElementException;\nimport java.util.Objects;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.util.function.BiFunction;\n\npublic class Main{\n\tstatic Scanner scn = new Scanner(System.in);\n\tstatic FastScanner sc = new FastScanner();\n\tstatic Mathplus mp = new Mathplus();\n\tstatic PrintWriter ot = new PrintWriter(System.out);\n\tstatic Random rand = new Random();\n\tstatic int mod = 1000000007;\n\tstatic long inf = (long)1e17;\n\tstatic int[] dx = {0,1,0,-1};\n\tstatic int[] dy = {1,0,-1,0};\n\tstatic int max;\n\tpublic static void main(String[] args) {\t\n\t\t\n\t\tint N = sc.nextInt();\n\t\tArrayList<Integer>[] l = new ArrayList[N];\n\t\tHashMap<Long,Integer> map = new HashMap<Long,Integer>();\n\t\tlong sum = 0;\n\t\tlong[] s = new long[N];\n\t\tfor(int i=0;i<N;i++) {\n\t\t\tl[i] = new ArrayList<Integer>();\n\t\t\tint n = sc.nextInt();\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tint a = sc.nextInt();\n\t\t\t\tmap.put((long)a, i);\n\t\t\t\ts[i] += a;\n\t\t\t\tsum += a;\n\t\t\t\tl[i].add(a);\n\t\t\t}\n\t\t}\n\t\tif(Math.abs(sum)%N!=0) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tlong make = sum/N;\n\t\tboolean[] dp = new boolean[(1<<N)];\n\t\tint[] first = new int[(1<<N)];\n\t\tint[] bef = new int[(1<<N)];\n\n\t\tArrays.fill(first,mod);\n\t\tfor(int i=0;i<N;i++) {\n\t\t\tfor(int a:l[i]) {\n\t\t\t\tint used = 0;\n\t\t\t\tboolean f = true;\n\t\t\t\tlong now = a;\n\t\t\t\tint see = i;\n\t\t\t\twhile(true) {\n\t\t\t\t\tlong next = make-(s[see]-now);\n\t\t\t\t\t\n\t\t\t\t\tif(next==a) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif(!map.containsKey(next)) {\n\t\t\t\t\t\tf = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}else {\n\t\t\t\t\t\tint k = map.get(next);\n\t\t\t\t\t\tif(mp.contains(used,k)&&k!=i) {\n\t\t\t\t\t\t\tf = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}else {\n\t\t\t\t\t\t\tused = mp.bitadd(used,k);\n\t\t\t\t\t\t\tnow = next;\n\t\t\t\t\t\t\tsee = k;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(f) {\n\t\t\t\t\tdp[mp.bitadd(used,i)] = true;\n\t\t\t\t\tfirst[mp.bitadd(used,i)] = a;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp[0] = true;\n\t\tfor(int i=1;i<(1<<N);i++) {\n\t\t\tfor(int j=i;j>0;j=(j-1)&i) {\n\t\t\t\tif(dp[i^j]&&dp[j]) {\n\t\t\t\t\tdp[i]=true;\n\t\t\t\t\tbef[i] = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(!dp[(1<<N)-1]) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}else {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tArrayDeque<Integer> q = new ArrayDeque<Integer>();\n\t\t\tint[] ans1 = new int[N];\n\t\t\tint[] ans2 = new int[N];\n\t\t\tq.add((1<<N)-1);\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint Q = q.poll();\n\t\t\t\tif(first[Q]==mod) {\n\t\t\t\t\tq.add(bef[Q]);\n\t\t\t\t\tq.add(Q^bef[Q]);\n\t\t\t\t}else {\n\t\t\t\t\t\n\t\t\t\t\tint a = first[Q];\n\t\t\t\t\tlong now = a;\n\t\t\t\t\tint befo = map.get((long)a);\n\t\t\t\t\twhile(true) {\n\t\t\t\t\t\tlong next = make-(s[befo]-now);\n\t\t\t\t\t\tif(next==a) {\n\t\t\t\t\t\t\tint k = map.get(next);\n\t\t\t\t\t\t\tans1[k] = (int)next;\n\t\t\t\t\t\t\tans2[k] = befo;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint k = map.get(next);\n\t\t\t\t\t\tans1[k] = (int)next;\n\t\t\t\t\t\tans2[k] = befo;\n\t\t\t\t\t\tnow = next;\n\t\t\t\t\t\tbefo = k;\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\tSystem.out.println(ans1[i]+\" \"+(ans2[i]+1));\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\n\t\n\t}\n\t\n}\nclass GridGraph extends Graph{\n\t\n\tint N;\n\tint M;\n\tString[] S;\n\tHashMap<Character,Integer> map;\n\tGridGraph(int n,int m,String[] s,char[] c){\n\t\tsuper(n*m);\n\t\tN = n;\n\t\tM = m;\n\t\tS = s;\n\t\tmap = new HashMap<Character,Integer>();\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif(S[i].charAt(j)!='#'&&S[i+1].charAt(j)!='#') {\n\t\t\t\t\taddEdge(toint(i,j),toint(i+1,j));\n\t\t\t\t\taddEdge(toint(i+1,j),toint(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m-1;j++) {\n\t\t\t\tif(S[i].charAt(j)!='#'&&S[i].charAt(j+1)!='#') {\n\t\t\t\t\taddEdge(toint(i,j),toint(i,j+1));\n\t\t\t\t\taddEdge(toint(i,j+1),toint(i,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<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tfor(int k=0;k<c.length;k++) {\n\t\t\t\t\tif(S[i].charAt(j)==c[k])map.put(c[k],toint(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint toint(int i,int j) {\n\t\treturn i*M+j;\n\t}\n\t\n}\n\nclass BetterGridGraph{\n\tint N;\n\tint M;\n\tchar[][] S;\n\tHashMap<Character,Integer> map;\n\tint[] dx = {0,1,0,-1};\n\tint[] dy = {1,0,-1,0};\n\tchar w;\n\tchar b = '#';\n\tBetterGridGraph(int n,int m,String[] s,char[] c){\n\t\t\n\t\tN = n;\n\t\tM = m;\n\t\tfor(int i=0;i<s.length;i++) {\n\t\t\tS[i] = s[i].toCharArray();\n\t\t}\n\t\tmap = new HashMap<Character,Integer>();\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 k=0;k<c.length;k++) {\n\t\t\t\t\tif(S[i][j]==c[k])map.put(c[k],toint(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tBetterGridGraph(int n,int m,char[][] s,char[] c){\n\t\t\n\t\tN = n;\n\t\tM = m;\n\t\tS = s;\n\t\tmap = new HashMap<Character,Integer>();\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 k=0;k<c.length;k++) {\n\t\t\t\t\tif(S[i][j]==c[k])map.put(c[k],toint(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tBetterGridGraph(int n,int m,String[] s,char[] c,char W,char B){\n\t\t\n\t\tN = n;\n\t\tM = m;\n\t\tfor(int i=0;i<s.length;i++) {\n\t\t\tS[i] = s[i].toCharArray();\n\t\t}\n\t\tw = W;\n\t\tb = B;\n\t\tmap = new HashMap<Character,Integer>();\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 k=0;k<c.length;k++) {\n\t\t\t\t\tif(S[i][j]==c[k])map.put(c[k],toint(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tBetterGridGraph(int n,int m,char[][] s,char[] c,char W,char B){\n\t\t\n\t\tN = n;\n\t\tM = m;\n\t\tS = s;\n\t\tw = W;\n\t\tb = B;\n\t\tmap = new HashMap<Character,Integer>();\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 k=0;k<c.length;k++) {\n\t\t\t\t\tif(S[i][j]==c[k])map.put(c[k],toint(i,j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint toint(int i,int j) {\n\t\treturn i*M+j;\n\t}\n\t\n\tint[] bfs(char C) {\n\t\tint s = map.get(C);\n\t\tint[] L = new int[N*M];\n\t\tfor(int i=0;i<N*M;i++){\n\t\t\tL[i] = -1;\n\t\t}\n\t\tL[s] = 0;\n\t\tArrayDeque<Integer> Q = new ArrayDeque<Integer>();\n\t\tQ.add(s);\n\t\tRange X = new Range(0,N-1);\n\t\tRange Y = new Range(0,M-1);\n\t\twhile(!Q.isEmpty()){\n\t\t\tint v = Q.poll();\n\t\t\tfor(int i=0;i<4;i++){\n\t\t\t\tint x = v/M;\n\t\t\t\tint y = v%M;\n\t\t\t\tint nx = x+dx[i];\n\t\t\t\tint ny = y+dy[i];\n\t\t\t\tif(X.isIn(nx)&&Y.isIn(ny)&&S[nx][ny]!=b) {\n\t\t\t\t\tint w = toint(nx,ny);\n\t\t\t\t\tif(L[w]==-1){\n\t\t\t\t\t\tL[w] = L[v] + 1;\n\t\t\t\t\t\tQ.add(w);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn L;\n\t}\n\t\n\tint[][] bfs2(char C,int K){\n\t\tint s = map.get(C);\n\t\tint[][] L = new int[N*M][K+1];\n\t\tfor(int i=0;i<N*M;i++){\n\t\t\tfor(int j=0;j<=K;j++)\n\t\t\tL[i][j] = 1000000007;\n\t\t}\n\t\tL[s][0] = 0;\n\t\tArrayDeque<IntIntPair> Q = new ArrayDeque<IntIntPair>();\n\t\tQ.add(new IntIntPair(s,0));\n\t\tRange X = new Range(0,N-1);\n\t\tRange Y = new Range(0,M-1);\n\t\twhile(!Q.isEmpty()){\n\t\t\tIntIntPair v = Q.poll();\n\t\t\tfor(int i=0;i<4;i++){\n\t\t\t\tint x = v.a/M;\n\t\t\t\tint y = v.a%M;\n\t\t\t\tint h = v.b;\n\t\t\t\tint nx = x+dx[i];\n\t\t\t\tint ny = y+dy[i];\n\t\t\t\tif(X.isIn(nx)&&Y.isIn(ny)&&S[nx][ny]!=b) {\n\t\t\t\t\tint ni = toint(nx,ny);\n\t\t\t\t\tint nh = S[nx][ny]==w?h+1:h;\n\t\t\t\t\tif(nh>K) continue;\n\t\t\t\t\tif(L[ni][nh]==1000000007){\n\t\t\t\t\t\tL[ni][nh] = L[v.a][h] + 1;\n\t\t\t\t\t\tQ.add(new IntIntPair(ni,nh));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<N*M;i++) {\n\t\t\tfor(int j=1;j<=K;j++) {\n\t\t\t\tL[i][j] = Math.min(L[i][j],L[i][j-1]);\n\t\t\t}\n\t\t}\n\t\treturn L;\n\t}\n}\n\nclass StringManager{\n\tArrayList<Character> S;\n\tstatic Mathplus mp;\n\tstatic boolean calced;\n\tstatic int base;\n\tstatic long baserev;\n\tArrayList<Long> l;\n\tStringManager(String s){\n\t\tS = new ArrayList<Character>();\n\t\tfor(int i=0;i<s.length();i++) {\n\t\t\tS.add(s.charAt(i));\n\t\t}\n\t\tif(!calced) {\n\t\t\tcalced = true;\n\t\t\tmp = new Mathplus();\n\t\t\tbase = 1000003;\n\t\t\tbaserev = mp.rev(base);\n\t\t\tmp.buildpow(base,1000050);\n\t\t\tmp.buildrevpow((int) baserev,1000050);\n\n\t\t}\n\t\tl = new ArrayList<Long>();\n\n\t\tl.add((long)S.get(0));\n\n\t\tfor(int i=1;i<S.size();i++) {\n\t\t\tchar c = S.get(i);\n\t\t\tl.add((l.get(i-1) + mp.pow[i] * c)%mp.mod);\n\n\t\t}\n\t}\n\tvoid add(char C){\n\t\tint i = S.size();\n\t\tS.add(C);\n\t\tl.add((l.get(i-1) + mp.pow[i] * C)%mp.mod);\n\t}\n\tlong gethash(int le,int ri) {\n\t\tlong res = l.get(ri);\n\t\tif(le!=0) {\n\t\t\tres -= l.get(le-1);\n\t\t\tres += mp.mod;\n\t\t\tres %= mp.mod;\n\t\t\tres *= mp.revpow[le];\n\t\t\tres %= mp.mod;\n\t\t}\n\t\treturn res;\n\t}\n\n\n}\n\n\nclass Trie{\n\tint nodenumber = 1;\n\tArrayList<TrieNode> l;\n\tTrie(){\n\t\tl = new ArrayList<TrieNode>();\n\t\tl.add(new TrieNode());\n\t}\n\n\tvoid add(String S,int W){\n\t\tint now = 0;\n\t\tfor(int i=0;i<S.length();i++) {\n\t\t\tTrieNode n = l.get(now);\n\t\t\tchar c = S.charAt(i);\n\t\t\tif(n.Exist[c-'a']!=-1) {\n\t\t\t\tnow = n.Exist[c-'a'];\n\t\t\t}else {\n\t\t\t\tl.add(new TrieNode());\n\t\t\t\tn.Exist[c-'a'] = nodenumber;\n\t\t\t\tnow = nodenumber;\n\t\t\t\tnodenumber++;\n\t\t\t}\n\t\t}\n\t\tl.get(now).weight = W;\n\t}\n\n\tvoid find(String S,int i,int[] dp) {\n\t\tint now = 0;\n\t\tdp[i+1] = Math.max(dp[i],dp[i+1]);\n\t\tfor(int j=0;;j++) {\n\t\t\tTrieNode n = l.get(now);\n\t\t\tdp[i+j] = Math.max(dp[i+j],dp[i]+n.weight);\n\t\t\tint slook = i+j;\n\t\t\tif(slook>=S.length())return;\n\t\t\tchar c = S.charAt(slook);\n\t\t\tif(n.Exist[c-'a']==-1)return;\n\t\t\tnow = n.Exist[c-'a'];\n\t\t}\n\t}\n}\n\nclass TrieNode{\n\n\tint[] Exist = new int[26];\n\tint weight = 0;\n\tTrieNode(){\n\t\tfor(int i=0;i<26;i++) {\n\t\t\tExist[i] = -1;\n\t\t}\n\t}\n}\n\nclass SizeComparator implements Comparator<Edge>{\n\tint[] size;\n\tSizeComparator(int[] s) {\n\t\tsize = s;\n\t}\n\n\tpublic int compare(Edge o1, Edge o2) {\n\t\treturn size[o1.to]-size[o2.to];\n\n\t}\n\n}\n\nclass ConvexHullTrick {\n\tlong[] A, B;\n\tint len;\n\n\tpublic ConvexHullTrick(int n) {\n\t\tA = new long[n];\n\t\tB = new long[n];\n\t}\n\n\tprivate boolean check(long a, long b) {\n\t\treturn (B[len - 2] - B[len - 1]) * (a - A[len - 1]) >= (B[len - 1] - b) * (A[len - 1] - A[len - 2]);\n\t}\n\n\tpublic void add(long a, long b) {\n\t\twhile (len >= 2 && check(a, b)) {\n\t\t\tlen--;\n\t\t}\n\t\tA[len] = a;\n\t\tB[len] = b;\n\t\tlen++;\n\t}\n\n\tpublic long query(long x) {\n\t\tint l = -1, r = len - 1;\n\t\twhile (r - l > 1) {\n\t\t\tint mid = (r + l) / 2;\n\t\t\tif (get(mid,x)>=get(mid+1,x)) {\n\t\t\t\tl = mid;\n\t\t\t} else {\n\t\t\t\tr = mid;\n\t\t\t}\n\t\t}\n\t\treturn get(r,x);\n\t}\n\n\tprivate long get(int k, long x) {\n\t\treturn A[k] * x + B[k];\n\t}\n}\n\nclass Range{\n\tint l;\n\tint r;\n\tint length;\n\tRange(int L,int R){\n\t\tl = L;\n\t\tr = R;\n\t\tlength = R-L+1;\n\t}\n\n\tboolean isIn(int x) {\n\t\treturn (l<=x&&x<=r);\n\n\t}\n}\nclass LeftComparator implements Comparator<Range>{\n\tpublic int compare(Range P, Range Q) {\n\t\treturn P.l-Q.l;\n\t}\n}\nclass RightComparator implements Comparator<Range>{\n\tpublic int compare(Range P, Range Q) {\n\t\treturn P.r-Q.r;\n\t}\n}\nclass LengthComparator implements Comparator<Range>{\n\tpublic int compare(Range P, Range Q) {\n\t\treturn P.length-Q.length;\n\t}\n}\nclass SegmentTree<T,E>{\n\tint N;\n\tBiFunction<T,T,T> f;\n\tBiFunction<T,E,T> g;\n\tT d1;\n\tArrayList<T> dat;\n\tSegmentTree(BiFunction<T,T,T> F,BiFunction<T,E,T> 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\n\n\tvoid init(int n) {\n\t\tN = 1;\n\t\twhile(N<n)N*=2;\n\t\tdat = new ArrayList<T>();\n\t}\n\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<v.length;i++) {\n\t\t\tdat.set(N+i-1,v[i]);\n\t\t}\n\t\tfor(int i=N-2;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\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\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\n}\n\nclass LazySegmentTree<T,E> extends SegmentTree<T,E>{\n\tBiFunction<E,E,E> h;\n\tBiFunction<E,Integer,E> p = (E a,Integer b) ->{return a;};\n\tE d0;\n\tArrayList<E> laz;\n\tLazySegmentTree(BiFunction<T,T,T> F,BiFunction<T,E,T> G,BiFunction<E,E,E> 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\n\t}\n\tvoid Init(int n){\n\t\tlaz = new ArrayList<E>();\n\t\tfor(int i=0;i<2*N;i++) {\n\t\t\tlaz.add(d0);\n\t\t}\n\t}\n\n\tvoid eval(int len,int k) {\n\t\tif(laz.get(k).equals(d0)) return;\n\t\tif(k*2+1<N*2-1) {\n\t\t\tlaz.set(k*2+1,h.apply(laz.get(k*2+1),laz.get(k)));\n\t\t\tlaz.set(k*2+2,h.apply(laz.get(k*2+2),laz.get(k)));\n\t\t}\n\t\tdat.set(k,g.apply(dat.get(k), p.apply(laz.get(k), len)));\n\t\tlaz.set(k,d0);\n\t}\n\n\tT update(int a,int b,E x,int k,int l,int r) {\n\t\teval(r-l,k);\n\t\tif(r<=a||b<=l) {\n\t\t\treturn dat.get(k);\n\t\t}\n\t\tif(a<=l&&r<=b) {\n\t\t\tlaz.set(k,h.apply(laz.get(k),x));\n\t\t\treturn g.apply(dat.get(k),p.apply(laz.get(k),r-l));\n\t\t}\n\t\tT vl = update(a,b,x,k*2+1,l,(l+r)/2);\n\t\tT vr = update(a,b,x,k*2+2,(l+r)/2,r);\n\t\tdat.set(k,f.apply(vl,vr));\n\t\treturn dat.get(k);\n\n\t}\n\n\tT update(int a,int b,E x) {\n\t\treturn update(a,b,x,0,0,N);\n\t}\n\n\tT query(int a,int b,int k,int l,int r) {\n\t\teval(r-l,k);\n\t\tif(r<=a||b<=l) return d1;\n\t\tif(a<=l&&r<=b) return dat.get(k);\n\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\n\tT query(int a,int b){\n\t\treturn query(a,b,0,0,N);\n\t}\n\n}\n\nclass AddSumSegmentTree{\n\tint N;\n\tint d1;\n\tArrayList<Integer> dat;\n\tAddSumSegmentTree(int[] v){\n\t\tint n = v.length;\n\t\tinit(n);\n\t\tbuild(v);\n\t}\n\n\tvoid init(int n) {\n\t\tN = 1;\n\t\twhile(N<n)N*=2;\n\t\tdat = new ArrayList<Integer>();\n\t}\n\n\tvoid build(int[] 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<v.length;i++) {\n\t\t\tdat.set(N+i-1,v[i]);\n\t\t}\n\t\tfor(int i=N-2;i>=0;i--) {\n\t\t\tdat.set(i,dat.get(i*2+1)+dat.get(i*2+2));\n\t\t}\n\t}\n\n\tvoid update(int k,int a) {\n\t\tk += N-1;\n\t\tdat.set(k,dat.get(k)+a);\n\t\twhile(k>0){\n\t\t\tk = (k-1)/2;\n\t\t\tdat.set(k,dat.get(k*2+1)+dat.get(k*2+2));\n\t\t}\n\t}\n\n\tint 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\tint vl = query(a,b,k*2+1,l,(l+r)/2);\n\t\tint vr = query(a,b,k*2+2,(l+r)/2,r);\n\t\treturn vl+vr;\n\t}\n\tint query(int a,int b){\n\t\treturn query(a,b,0,0,N);\n\t}\n}\nclass AddSumLazySegmentTree {\n\tint N;\n\tlong[] dat;\n\tlong[] laz;\n\tAddSumLazySegmentTree(long[] v){\n\t\tinit(v.length);\n\n\t\tfor(int i=0;i<v.length;i++) {\n\t\t\tdat[N+i-1]=v[i];\n\t\t}\n\t\tfor(int i=N-2;i>=0;i--) {\n\t\t\tdat[i]=dat[i*2+1]+dat[i*2+2];\n\t\t}\n\t}\n\n\tvoid init(int n) {\n\t\tN = 1;\n\t\twhile(N<n)N*=2;\n\t\tdat = new long[2*N];\n\t\tlaz = new long[2*N];\n\t}\n\n\n\tvoid eval(int len,int k) {\n\t\tif(laz[k]==0) return;\n\t\tif(k*2+1<N*2-1) {\n\t\t\tlaz[k*2+1] += laz[k];\n\t\t\tlaz[k*2+2] += laz[k];\n\t\t}\n\t\tdat[k] += laz[k] * len;\n\t\tlaz[k] = 0;\n\t}\n\n\tlong update(int a,int b,long x,int k,int l,int r) {\n\t\teval(r-l,k);\n\t\tif(r<=a||b<=l) {\n\t\t\treturn dat[k];\n\t\t}\n\t\tif(a<=l&&r<=b) {\n\t\t\tlaz[k] += x;\n\t\t\treturn dat[k]+laz[k]*(r-l);\n\t\t}\n\t\tlong vl = update(a,b,x,k*2+1,l,(l+r)/2);\n\t\tlong vr = update(a,b,x,k*2+2,(l+r)/2,r);\n\t\treturn dat[k] = vl+vr;\n\n\n\t}\n\n\tlong update(int a,int b,long x) {\n\t\treturn update(a,b,x,0,0,N);\n\t}\n\n\tlong query(int a,int b,int k,int l,int r) {\n\t\teval(r-l,k);\n\t\tif(r<=a||b<=l) return 0;\n\t\tif(a<=l&&r<=b) return dat[k];\n\n\t\tlong vl = query(a,b,k*2+1,l,(l+r)/2);\n\t\tlong vr = query(a,b,k*2+2,(l+r)/2,r);\n\t\treturn vl+vr;\n\t}\n\n\tlong query(int a,int b){\n\t\treturn query(a,b,0,0,N);\n\t}\n\n}\n\nclass BinaryIndexedTree{\n\tint[] val;\n\tBinaryIndexedTree(int N){\n\t\tval = new int[N+1];\n\t}\n\tlong sum(int i) {\n\t\tif(i==0)return 0;\n\t\tlong s = 0;\n\t\twhile(i>0) {\n\t\t\ts += val[i];\n\t\t\ti -= i & (-i);\n\t\t}\n\t\treturn s;\n\t}\n\tvoid add(int x,int i) {\n\t\tif(i==0)return;\n\t\twhile(i<val.length){\n\t\t\tval[i] += x;\n\t\t\ti += i & (-i);\n\t\t}\n\t}\n}\n\nclass UnionFindTree {\n\tint[] root;\n\tint[] rank;\n\tint[] size;\n\tint[] edge;\n\tint num;\n\tUnionFindTree(int N){\n\t\troot = new int[N];\n\t\trank = new int[N];\n\t\tsize = new int[N];\n\t\tedge = new int[N];\n\t\tnum = N;\n\t\tfor(int i=0;i<N;i++){\n\t\t\troot[i] = i;\n\t\t\tsize[i] = 1;\n\t\t}\n\t}\n\tpublic boolean isRoot(int x) {\n\t\treturn x==find(x);\n\t}\n\tpublic int extraEdge(int x) {\n\t\tint r = find(x);\n\t\treturn edge[r] - size[r] + 1;\n\t}\n\tpublic int find(int x){\n\t\tif(root[x]==x){\n\t\t\treturn x;\n\t\t}else{\n\t\t\treturn find(root[x]);\n\t\t}\n\t}\n\n\tpublic void unite(int x,int y){\n\t\tx = find(x);\n\t\ty = find(y);\n\t\tif(x==y){\n\t\t\tedge[x]++;\n\t\t\treturn;\n\t\t}else{\n\t\t\tnum--;\n\t\t\tif(rank[x]<rank[y]){\n\t\t\t\troot[x] = y;\n\t\t\t\tsize[y] += size[x];\n\t\t\t\tedge[y] += edge[x]+1;\n\t\t\t}else{\n\t\t\t\troot[y] = x;\n\t\t\t\tsize[x] += size[y];\n\t\t\t\tedge[x] += edge[y]+1;\n\t\t\t\tif(rank[x]==rank[y]){\n\t\t\t\t\trank[x]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic boolean same(int x,int y){\n\t\treturn find(x)==find(y);\n\t}\n\n}\n\nclass ParticalEternalLastingUnionFindTree extends UnionFindTree{\n\tint[] time;\n\tint now;\n\tParticalEternalLastingUnionFindTree(int N){\n\t\tsuper(N);\n\t\ttime = new int[N];\n\t\tfor(int i=0;i<N;i++) {\n\t\t\ttime[i] = 1000000007;\n\t\t}\n\t}\n\n\tpublic int find(int t,int i) {\n\t\tif(time[i]>t) {\n\t\t\treturn i;\n\t\t}else {\n\t\t\treturn find(t,root[i]);\n\t\t}\n\t}\n\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]<rank[y]){\n\t\t\troot[x] = y;\n\t\t\tsize[y] += size[x];\n\t\t\ttime[x] = t;\n\t\t}else{\n\t\t\troot[y] = x;\n\t\t\tsize[x] += size[y];\n\t\t\tif(rank[x]==rank[y]){\n\t\t\t\trank[x]++;\n\t\t\t}\n\t\t\ttime[y] = t;\n\t\t}\n\t}\n\n\tpublic int sametime(int x,int y) {\n\t\tif(find(now,x)!=find(now,y)) return -1;\n\t\tint ok = now;\n\t\tint ng = 0;\n\t\twhile(ok-ng>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\n\n}\nclass Graph {\n\tArrayList<Edge>[] list;\n\tint size;\n\tTreeSet<LinkEdge> Edges = new TreeSet<LinkEdge>(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;i++){\n\t\t\tlist[i] = new ArrayList<Edge>();\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,long c){\n\t\tlist[a].add(new Edge(b,c));\n\t}\n\n\tvoid addEgdes(int[] a,int[] b){\n\n\t\tfor(int i=0;i<a.length;i++){\n\t\t\tlist[a[i]].add(new Edge(b[i],1));\n\t\t}\n\t}\n\n\tvoid addWeighterEdges(int[] a ,int[] b ,int[] c){\n\t\tfor(int i=0;i<a.length;i++){\n\t\t\tlist[a[i]].add(new Edge(b[i],c[i]));\n\t\t}\n\t}\n\n\tlong[][] bfs(int s){\n\t\tlong[][] L = new long[2][size];\n\t\tfor(int i=0;i<size;i++){\n\t\t\tL[0][i] = -1;\n\t\t\tL[1][i] = -1;\n\t\t}\n\t\tL[0][s] = 0;\n\t\tArrayDeque<Integer> Q = new ArrayDeque<Integer>();\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[0][w]==-1){\n\t\t\t\t\tL[0][w] = L[0][v] + c;\n\t\t\t\t\tL[1][w] = v; \n\t\t\t\t\tQ.add(w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn L;\n\t}\n\tlong[] bfs2(int[] d,int s){\n\t\tlong[] L = new long[size];\n\t\tfor(int i=0;i<size;i++){\n\t\t\tL[i] = -1;\n\t\t}\n\t\tint p = 0;\n\t\tL[s] = 0;\n\t\td[s] = p;\n\t\tp++;\n\t\tArrayDeque<Integer> Q = new ArrayDeque<Integer>();\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\td[w] = p;\n\t\t\t\t\tp++;\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\t\treturn L;\n\t}\n\n\tint[] isTwoColor(){\n\t\tint[] L = new int[size];\n\t\tfor(int i=0;i<size;i++){\n\t\t\tL[i] = -1;\n\t\t}\n\t\tL[0] = 0;\n\t\tArrayDeque<Integer> Q = new ArrayDeque<Integer>();\n\t\tQ.add(0);\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\tif(L[w]==-1){\n\t\t\t\t\tL[w] = 1-L[v];\n\t\t\t\t\tQ.add(w);\n\t\t\t\t}else{\n\t\t\t\t\tif(L[v]+L[w]!=1){\n\t\t\t\t\t\tL[0] = -2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\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<size;i++){\n\t\t\tL[i] = -1;\n\t\t}\n\t\tint[] v = new int[size];\n\t\tL[s] = 0;\n\t\tPriorityQueue<LongIntPair> Q = new PriorityQueue<LongIntPair>(new LongIntSampleComparator());\n\t\tQ.add(new LongIntPair(0,s));\n\n\t\twhile(!Q.isEmpty()){\n\n\t\t\tLongIntPair C = Q.poll();\n\t\t\t\n\t\t\tif(v[C.b]==0){\n\t\t\t\tL[C.b] = C.a;\n\t\t\t\tv[C.b] = 1;\n\t\t\t\tfor(Edge D:list[C.b]) {\n\t\t\t\t\tif(L[D.to]==-1||L[D.to]>L[C.b]+D.cost) {\n\t\t\t\t\t\tL[D.to]=L[C.b]+D.cost;\n\t\t\t\t\t\tQ.add(new LongIntPair(L[C.b]+D.cost,D.to));\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn L;\n\t}\n\n\tArrayList<Graph> makeapart(){\n\t\tArrayList<Graph> ans = new ArrayList<Graph>();\n\t\tboolean[] b = new boolean[size];\n\t\tint[] num = new int[size];\n\t\tfor(int i=0;i<size;i++){\n\t\t\tif(b[i])continue;\n\t\t\tint sz = 0;\n\t\t\tArrayList<Integer> l = new ArrayList<Integer>();\n\t\t\tArrayDeque<Integer> Q = new ArrayDeque<Integer>();\n\t\t\tQ.add(i);\n\t\t\tb[i] = true;\n\t\t\twhile(!Q.isEmpty()){\n\t\t\t\tint v = Q.poll();\n\t\t\t\tnum[v] = sz;\n\t\t\t\tsz++;\n\t\t\t\tl.add(v);\n\t\t\t\tfor(Edge e:list[v]){\n\t\t\t\t\tif(!b[e.to]){\n\t\t\t\t\t\tQ.add(e.to);\n\t\t\t\t\t\tb[e.to] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tGraph H = new Graph(sz);\n\t\t\tfor(int e:l){\n\t\t\t\tfor(Edge E:list[e]){\n\t\t\t\t\tH.addWeightedEdge(num[e],num[E.to],E.cost);\n\t\t\t\t}\n\t\t\t}\n\t\t\tans.add(H);\n\n\t\t}\n\t\treturn ans;\n\t}\n\n\tlong[] bellmanFord(int s) {\n\t\tlong inf = 1000000000;\n\t\tinf *= inf;\n\t\tlong[] d = new long[size];\n\t\tboolean[] n = new boolean[size];\n\t\td[s] = 0;\n\t\tfor(int i=1;i<size;i++){\n\t\t\td[i] = inf;\n\t\t\td[i] *= d[i];\n\t\t}\n\t\tfor(int i=0;i<size-1;i++){\n\t\t\tfor(int j=0;j<size;j++){\n\t\t\t\tfor(Edge E:list[j]){\n\t\t\t\t\tif(d[j]!=inf&&d[E.to]>d[j]+E.cost){\n\t\t\t\t\t\td[E.to]=d[j]+E.cost;\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<size;i++){\n\t\t\tfor(int j=0;j<size;j++){\n\t\t\t\tfor(Edge e:list[j]){\n\t\t\t\t\tif(d[j]==inf) continue;\n\t\t\t\t\tif(d[e.to]>d[j]+e.cost) {\n\t\t\t\t\t\td[e.to]=d[j]+e.cost;\n\t\t\t\t\t\tn[e.to] = true;\n\t\t\t\t\t}\n\t\t\t\t\tif(n[j])n[e.to] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<size;i++) {\n\t\t\tif(n[i])d[i] = inf;\n\t\t}\n\t\treturn d;\n\t}\n\t\n\tlong[][] WarshallFloyd(long[][] a){\n\t\tint n = a.length;\n\t\tlong[][] ans = 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\tans[i][j] = a[i][j]==0?(long)1e16:a[i][j];\n\t\t\t\tif(i==j)ans[i][j]=0;\n\t\t\t}\n\t\t}\n\t\tfor(int k=0;k<n;k++) {\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\t\tans[i][j] = Math.min(ans[i][j],ans[i][k]+ans[k][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tlong[] maxtra(int s,long l){\n\t\tlong[] L = new long[size];\n\t\tfor(int i=0;i<size;i++){\n\t\t\tL[i] = -1;\n\t\t}\n\t\tint[] v = new int[size];\n\t\tL[s] = -1;\n\n\t\tPriorityQueue<Pair> Q = new PriorityQueue<Pair>(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(v[(int)C.b]==0){\n\t\t\t\tL[(int)C.b] = C.a;\n\t\t\t\tv[(int) C.b] = 1;\n\t\t\t\tfor(Edge D:list[(int) C.b])Q.add(new Pair(Math.max(L[(int)C.b],D.cost),D.to));\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\tlong[] mintra(int s){\n\t\tlong[] L = new long[size];\n\t\tfor(int i=0;i<size;i++){\n\t\t\tL[i] = -1;\n\t\t}\n\t\tint[] v = new int[size];\n\t\tL[s] = s;\n\n\t\tPriorityQueue<Pair> Q = new PriorityQueue<Pair>(new SampleComparator().reversed());\n\t\tQ.add(new Pair(s,s));\n\n\t\twhile(!Q.isEmpty()){\n\n\t\t\tPair C = Q.poll();\n\t\t\tif(v[(int)C.b]==0){\n\t\t\t\tL[(int)C.b] = C.a;\n\t\t\t\tv[(int) C.b] = 1;\n\t\t\t\tfor(Edge D:list[(int) C.b])Q.add(new Pair(Math.min(L[(int)C.b],D.cost),D.to));\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\tlong Kruskal(){\n\t\tlong r = 0;\n\t\tfor(int i=0;i<size;i++) {\n\t\t\tfor(Edge e:list[i]) {\n\t\t\t\tEdges.add(new LinkEdge(e.cost,i,e.to));\n\t\t\t}\n\t\t}\n\t\tUnionFindTree UF = new UnionFindTree(size);\n\t\tfor(LinkEdge e:Edges){\n\t\t\tif(e.a>=0&&e.b>=0) {\n\t\t\t\tif(!UF.same(e.a,e.b)){\n\t\t\t\t\tr += 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\t\treturn r;\n\t}\n\n\tArrayList<Integer> Kahntsort(){\n\n\t\tArrayList<Integer> ans = new ArrayList<Integer>();\n\t\tPriorityQueue<Integer> q = new PriorityQueue<Integer>();\n\t\tint[] in = new int[size];\n\t\tfor(int i=0;i<size;i++) {\n\t\t\tfor(Edge e:list[i])in[e.to]++;\n\t\t}\n\t\tfor(int i=0;i<size;i++) {\n\t\t\tif(in[i]==0)q.add(i);\n\t\t}\n\t\twhile(!q.isEmpty()) {\n\t\t\tint v = q.poll();\n\t\t\tans.add(v);\n\t\t\tfor(Edge e:list[v]) {\n\t\t\t\tin[e.to]--;\n\t\t\t\tif(in[e.to]==0)q.add(e.to);\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<size;i++) {\n\t\t\tif(in[i]>0)return new ArrayList<Integer>();\n\t\t}\n\t\treturn ans;\n\t}\n\n\tRootedTree dfsTree(int i) {\n\t\tint[] u = new int[size];\n\t\tRootedTree r = new RootedTree(size);\n\t\tdfsTree(i,u,r);\n\t\treturn r;\n\n\t}\n\n\tprivate void dfsTree(int i, int[] u, RootedTree r) {\n\t\tu[i] = 1;\n\t\tfor(Edge e:list[i]) {\n\t\t\tif(u[e.to]==0) {\n\t\t\t\tr.list[i].add(e);\n\t\t\t\tu[e.to] = 1;\n\t\t\t\tdfsTree(e.to,u,r);\n\t\t\t}\n\t\t}\n\n\t}\n}\n\n\nclass Tree extends Graph{\n\n\tpublic Tree(int N) {\n\t\tsuper(N);\n\t}\n\n\tlong[] tyokkei(){\n\t\tlong[][] a = bfs(0);\n\n\t\tSystem.out.println();\n\t\tint md = -1;\n\t\tlong m = 0;\n\t\tfor(int i=0;i<size;i++){\n\t\t\tif(m<a[0][i]){\n\t\t\t\tm = a[0][i];\n\t\t\t\tmd = i;\n\t\t\t}\n\t\t}\n\n\t\tlong[][] b = bfs(md);\n\t\tint md2 = -1;\n\t\tlong m2 = 0;\n\t\tfor(int i=0;i<size;i++){\n\t\t\tif(m2<b[0][i]){\n\t\t\t\tm2 = b[0][i];\n\t\t\t\tmd2 = i;\n\t\t\t}\n\t\t}\n\t\tlong[] r = {m2,md,md2};\n\t\treturn r;\n\t}\n\n}\n\nclass RootedTree extends Graph{\n\tRootedTree(int N){\n\t\tsuper(N);\n\t}\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\treturn O.a==this.a&&O.b==this.b&&O.L==this.L;\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(L,a,b);\n\t}\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}\nclass LinkEdgeComparator implements Comparator<LinkEdge>{\n\tpublic int compare(LinkEdge P, LinkEdge Q) {\n\t\tlong t = P.L-Q.L;\n\t\tif(t==0){\n\t\t\tif(P.a>Q.a){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\treturn P.b>Q.b?1:-1;\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\treturn t>=0?1:-1;\n\t}\n}\n\nclass Triplet{\n\tlong a;\n\tlong b;\n\tlong c;\n\tTriplet(long p,long q,long r){\n\t\ta = p;\n\t\tb = q;\n\t\tc = r;\n\t}\n\tpublic boolean equals(Object o){\n\t\tTriplet O = (Triplet) o;\n\t\treturn O.a==this.a&&O.b==this.b&&O.c==this.c?true:false;\n\t\t\t\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b,c);\n\t}\n}\n\nclass TripletComparator implements Comparator<Triplet>{\n\tpublic int compare(Triplet P, Triplet Q) {\n\t\tlong t = P.a-Q.a;\n\t\tif(t==0){\n\t\t\tlong tt = P.b-Q.b;\n\t\t\tif(tt==0) {\n\t\t\t\tif(P.c>Q.c) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}else if(P.c<Q.c){\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\treturn tt>0?1:-1;\n\t\t}\n\t\treturn t>=0?1:-1;\n\t}\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\treturn O.a==this.a&&O.b==this.b;\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n}\n\nclass SampleComparator implements Comparator<Pair>{\n\tpublic int compare(Pair P, Pair Q) {\n\t\tlong t = P.a-Q.a;\n\t\tif(t==0){\n\t\t\treturn P.b>=Q.b?1:-1;\n\n\t\t}\n\t\treturn t>=0?1:-1;\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\treturn O.a==this.a&&O.b==this.b;\n\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n}\n\nclass LongIntSampleComparator implements Comparator<LongIntPair>{\n\tpublic int compare(LongIntPair P, LongIntPair Q) {\n\t\tlong t = P.a-Q.a;\n\t\tif(t==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\t\t}\n\t\treturn t>=0?1:-1;\n\t}\n}\n\n\nclass IntIntPair{\n\tint a;\n\tint b;\n\n\tIntIntPair(int 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\treturn O.a==this.a&&O.b==this.b;\n\t\t\t\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n}\n\n\n\nclass IntIntSampleComparator implements Comparator<IntIntPair>{\n\tpublic int compare(IntIntPair P, IntIntPair Q) {\n\t\tint t = P.a-Q.a;\n\t\tif(t==0){\n\t\t\treturn P.b-Q.b;\n\t\t}\n\t\treturn t;\n\t}\n}\n\n\n\n\nclass DoublePair{\n\tdouble a;\n\tdouble b;\n\n\tDoublePair(double p,double 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\treturn O.a==this.a&&O.b==this.b;\n\t\t\t\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n}\n\nclass DDSampleComparator implements Comparator<DoublePair>{\n\tpublic int compare(DoublePair P, DoublePair Q) {\n\t\treturn P.b-Q.b>=0?1:-1;\n\t}\n}\n\nclass DoubleTriplet{\n\tdouble a;\n\tdouble b;\n\tdouble c;\n\n\tDoubleTriplet(double p,double q,double r){\n\t\tthis.a = p;\n\t\tthis.b = q;\n\t\tthis.c = r;\n\t}\n\n\tpublic boolean equals(Object o){\n\t\tDoubleTriplet O = (DoubleTriplet) o;\n\t\treturn O.a==this.a&&O.b==this.b&&O.c==this.c;\n\t\t\t\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b,c);\n\t}\n}\n\n\nclass FastScanner {\n    private final java.io.InputStream in = System.in;\n    private final byte[] b = new byte[1024];\n    private int p = 0;\n    private int bl = 0;\n    private boolean hNB() {\n        if (p<bl) {\n            return true;\n        }else{\n            p = 0;\n            try {\n                bl = in.read(b);\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            if (bl<=0) {\n                return false;\n            }\n        }\n        return true;\n    }\n    private int rB() { if (hNB()) return b[p++]; else return -1;}\n    private static boolean iPC(int c) { return 33 <= c && c <= 126;}\n    private void sU() { while(hNB() && !iPC(b[p])) p++;}\n    public boolean hN() { sU(); return hNB();}\n    public String next() {\n        if (!hN()) throw new NoSuchElementException();\n        StringBuilder sb = new StringBuilder();\n        int b = rB();\n        while(iPC(b)) {\n            sb.appendCodePoint(b);\n            b = rB();\n        }\n        return sb.toString();\n    }\n    public char nextChar() {\n    \treturn next().charAt(0);\n    }\n    public long nextLong() {\n        if (!hN()) throw new NoSuchElementException();\n        long n = 0;\n        boolean m = false;\n        int b = rB();\n        if (b=='-') {\n            m=true;\n            b=rB();\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||!iPC(b)){\n                return (m?-n:n);\n            }else{\n                throw new NumberFormatException();\n            }\n            b = rB();\n        }\n    }\n    public int nextInt() {\n        if (!hN()) throw new NoSuchElementException();\n        long n = 0;\n        boolean m = false;\n        int b = rB();\n        if (b == '-') {\n            m = true;\n            b = rB();\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||!iPC(b)){\n                return (int) (m?-n:n);\n            }else{\n                throw new NumberFormatException();\n            }\n            b = rB();\n        }\n    }\n    public int[] nextInts(int n) {\n    \tint[] a = new int[n];\n    \tfor(int i=0;i<n;i++) {\n    \t\ta[i] = nextInt();\n    \t}\n    \treturn a;\n    }\n    public long[] nextLongs(int n) {\n    \tlong[] a = new long[n];\n    \tfor(int i=0;i<n;i++) {\n    \t\ta[i] = nextLong();\n    \t}\n    \treturn a;\n    }\n    public int[][] nextIntses(int n,int m){\n    \tint[][] a = new int[n][m];\n    \tfor(int i=0;i<n;i++) {\n    \t\tfor(int j=0;j<m;j++) {\n    \t\t\ta[i][j] = nextInt();\n    \t\t}\n    \t}\n    \treturn a;\n    }\n}\n\n\nclass Mathplus{\n\tint mod = 1000000007;\n\tlong[] fac;\n\tlong[] revfac;\n\tlong[][] comb;\n\tlong[] pow;\n\tlong[] revpow;\n\tboolean isBuild = false;\n\tboolean isBuildc = false;\n\tboolean isBuildp = false;\n\tint mindex = -1;\n\tint maxdex = -1;\n\t\n\tint color(int[][] diff,int N) {\n\t\t\n\t\tint[] val = new int[1<<N];\n\t\tval[0] = 1;\n\t\tfor(int i=0;i<(1<<N);i++) {\t\t\n\t\t\tfor(int j=0;j<N;j++) {\n\t\t\t\tif(contains(i,j)) {\n\t\t\t\t\tif(val[bitremove(i,j)]==1) {\n\t\t\t\t\t\tboolean b = true;\n\t\t\t\t\t\tfor(int k=0;k<N;k++) {\n\t\t\t\t\t\t\tif(contains(i,k)&&diff[j][k]==1) {\n\t\t\t\t\t\t\t\tb = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(b)val[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\tint[] dp = new int[1<<N];\n\t\tArrays.fill(dp,mod);;\n\t\tdp[0] = 0;\n\t\tfor(int i=0;i<(1<<N);i++) {\n\t\t\tfor(int j=i;j>0;j=(j-1)&i) {\n\t\t\t\tif(val[j]==1)dp[i]=Math.min(dp[i],dp[i^j]+1);\n\t\t\t}\n\t\t}\n\t\treturn dp[(1<<N)-1];\n\t}\n\t\n\tpublic DoubleTriplet Line(double x1,double y1,double x2,double y2) {\n\t\tdouble a = y1-y2;\n\t\tdouble b = x2-x1;\n\t\tdouble c = x1*y2-x2*y1;\n\t\treturn new DoubleTriplet(a,b,c);\n\t}\n\tpublic double putx(DoubleTriplet T,double x) {\n\t\treturn -(T.a*x+T.c)/T.b;\n\t}\n\tpublic double puty(DoubleTriplet T,double y) {\n\t\treturn -(T.b*y+T.c)/T.a;\n\t}\n\tpublic double DistanceofPointandLine(DoublePair P,Triplet T) {\n\t\treturn Math.abs(P.a*T.a+P.b*T.b+T.c) / Math.sqrt(T.a*T.a+T.b*T.b);\n\t}\n\tpublic boolean cross(long ax, long ay, long bx, long by, long cx, long cy, long dx, long dy) {\n\t\t long ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);\n\t\t long tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);\n\t\t long tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);\n\t\t long td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);\n\t\t return((tc>=0&&td<=0)||(tc<=0&&td>=0))&&((ta>=0&&tb<=0)||(ta<=0&&tb>=0));\n\t}\n\tpublic boolean dcross(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) {\n\t\t double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);\n\t\t double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);\n\t\t double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);\n\t\t double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);\n\t\t return((tc>=0&&td<=0)||(tc<=0&&td>=0))&&((ta>=0&&tb<=0)||(ta<=0&&tb>=0));\n\t}\n\t\n\tvoid buildFac(){\n\t\tfac = new long[10000003];\n\t\trevfac = new long[10000003];\n\t\tfac[0] = 1;\n\t\tfor(int i=1;i<=10000002;i++){\n\t\t\tfac[i] = (fac[i-1] * i)%mod;\n\t\t}\n\t\trevfac[10000002] = rev(fac[10000002])%mod;\n\t\tfor(int i=10000001;i>=0;i--) {\n\t\t\trevfac[i] = (revfac[i+1] * (i+1))%mod;\n\t\t}\n\t\tisBuild = true;\n\t}\n\tpublic long[] buildrui(int[] a) {\n\t\tint n = a.length;\n\t\tlong[] ans = new long[n];\n\t\tans[0] = a[0];\n\t\tfor(int i=1;i<n;i++) {\n\t\t\tans[i] = ans[i-1] + a[i];\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic long[][] buildrui(int[][] a) {\n\t\tint n = a.length;\n\t\tint m = a[0].length;\n\t\tlong[][] ans = new long[n][m];\n\t\tfor(int i=1;i<n;i++) {\n\t\t\tfor(int j=1;j<m;j++) {\n\t\t\t\tans[i][j] = a[i][j];\n\t\t\t}\n\t\t}\n\t\tfor(int i=1;i<n;i++) {\n\t\t\tfor(int j=1;j<m;j++) {\n\t\t\t\tans[i][j] += ans[i][j-1] + ans[i-1][j] - ans[i-1][j-1];\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tlong divroundup(long n,long d) {\n\t\tif(n==0)return 0;\n\t\treturn (n-1)/d+1;\n\t}\n\tpublic long sigma(long i) {\n\t\treturn i*(i+1)/2;\n\t}\n\tpublic int digit(long i) {\n\t\tint ans = 1;\n\t\twhile(i>=10) {\n\t\t\ti /= 10;\n\t\t\tans++;\n\t\t}\n\t\treturn ans;\n\n\t}\n\tpublic int popcount(int i) {\n\t\tint ans = 0;\n\t\twhile(i>0) {\n\t\t\tans += i%2;\n\t\t\ti /= 2;\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic boolean contains(int S,int i) {return (S>>i&1)==1;}\n\tpublic int bitremove(int S,int i) {return S&(~(1<<i));}\n\tpublic int bitadd(int S,int i) {return S|(1<<i);}\n\tpublic boolean isSubSet(int S,int T) {return (S-T)==(S^T);}\n\tpublic boolean isDisjoint(int S,int T) {return (S+T)==(S^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\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]<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\tpublic int isBigger(long[] d, long 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\tpublic int isSmaller(long[] d, long 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]<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\tpublic int isBigger(ArrayList<Long> d, long i) {\n\t\tint ok = d.size();\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.get(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\tpublic int isSmaller(ArrayList<Long> d, long i) {\n\t\tint ok = -1;\n\t\tint ng = d.size();\n\t\twhile(Math.abs(ok-ng)>1) {\n\t\t\tint mid = (ok+ng)/2;\n\t\t\tif(d.get(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\tpublic HashSet<Integer> primetable(int m) {\n\t\tHashSet<Integer> pt = new HashSet<Integer>();\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\tpublic ArrayList<Integer> primetablearray(int m) {\n\t\tArrayList<Integer> al = new ArrayList<Integer>();\n\t\tQueue<Integer> q = new ArrayDeque<Integer>();\n\t\tfor(int i=2;i<=m;i++) {\n\t\t\tq.add(i);\n\t\t\t\n\t\t}\n\t\tboolean[] b = new boolean[m+1];\n\t\twhile(!q.isEmpty()) {\n\t\t\tint e = q.poll();\n\t\t\tif(!b[e]) {\n\t\t\t\tal.add(e);\n\t\t\t\tfor(int j=1;e*j<=1000000;j++) {\n\t\t\t\t\tb[e*j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn al;\n\t}\n\tpublic HashMap<Integer,Integer> hipPush(ArrayList<Integer> l){\n\t\tHashMap<Integer,Integer> r = new HashMap<Integer,Integer>();\n\t\tTreeSet<Integer> s = new TreeSet<Integer>();\n\t\tfor(int e:l)s.add(e);\n\t\tint p = 0;\n\t\tfor(int e:s) {\n\t\t\tr.put(e,p);\n\t\t\tp++;\n\t\t}\n\t\treturn r;\n\t}\n\tpublic TreeMap<Integer,Integer> thipPush(ArrayList<Integer> l){\n\t\tTreeMap<Integer,Integer> r = new TreeMap<Integer,Integer>();\n\t\tCollections.sort(l);\n\t\tint b = -(mod+9393);\n\t\tint p = 0;\n\t\tfor(int e:l) {\n\t\t\tif(b!=e) {\n\t\t\t\tr.put(e,p);\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tb=e;\n\t\t}\n\t\treturn r;\n\t}\n\n\tlong max(long[] a){\n\t\tlong M = 0;\n\t\tfor(int i=0;i<a.length;i++){\n\t\t\tif(M<a[i]){\n\t\t\t\tM =a[i];\n\t\t\t\tmaxdex = i;\n\t\t\t}\n\t\t}\n\t\treturn M;\n\t}\n\tint max(int[] a){\n\t\tint M = 0;\n\t\tfor(int i=0;i<a.length;i++){\n\t\t\tif(M<a[i]){\n\t\t\t\tM =a[i];\n\t\t\t\tmaxdex = i;\n\t\t\t}\n\t\t}\n\t\treturn M;\n\t}\n\tlong min(long[] a){\n\t\tlong m = Long.MAX_VALUE;\n\t\tfor(int i=0;i<a.length;i++){\n\t\t\tif(m>a[i]){\n\t\t\t\tm =a[i];\n\t\t\t\tmindex = i;\n\t\t\t}\n\t\t}\n\t\treturn m;\n\t}\n\tint min(int[] a){\n\t\tint m = Integer.MAX_VALUE;\n\t\tfor(int i=0;i<a.length;i++){\n\t\t\tif(m>a[i]){\n\t\t\t\tm =a[i];\n\t\t\t\tmindex = i;\n\t\t\t}\n\t\t}\n\t\treturn m;\n\t}\n\tlong sum(long[] a){\n\t\tlong s = 0;\n\t\tfor(int i=0;i<a.length;i++)s += a[i];\n\t\treturn s;\n\t}\n\tlong sum(int[] a){\n\t\tlong s = 0;\n\t\tfor(int i=0;i<a.length;i++)s += a[i];\n\t\treturn s;\n\t}\n\tlong gcd(long a, long b){\n\t\ta = Math.abs(a);\n\t\tb = Math.abs(b);\n\t\tif(a==0)return b;\n\t\tif(b==0)return a;\n\t\tif(a%b==0) return b;\n\t\telse return gcd(b,a%b);\n\t}\n\tint igcd(int a, int b) {\n\t\tif(a%b==0) return b;\n\t\telse return igcd(b,a%b);\n\t}\n\tlong lcm(long a, long b) {return a / gcd(a,b) * b;}\n\tpublic long perm(int a,int num) {\n\t\tif(!isBuild)buildFac();\n\t\treturn fac[a]*(rev(fac[a-num]))%mod;\n\t}\n\tvoid buildComb(int N) {\n\t\tcomb = new long[N+1][N+1];\n\t\tcomb[0][0] = 1;\n\t\tfor(int i=1;i<=N;i++) {\n\t\t\tcomb[i][0] = 1;\n\t\t\tfor(int j=1;j<N;j++) {\n\t\t\t\tcomb[i][j] = comb[i-1][j-1]+comb[i-1][j];\n\t\t\t\tif(comb[i][j]>mod)comb[i][j]-=mod;\n\t\t\t}\n\t\t\tcomb[i][i] = 1;\n\t\t}\n\t}\n\tpublic long comb(int a,int num){\n\t\tif(a-num<0)return 0;\n\t\tif(num<0)return 0;\n\t\tif(!isBuild)buildFac();\n\t\treturn fac[a] * ((revfac[num]*revfac[a-num])%mod)%mod;\n\t}\n\tlong mulchoose(int n,int k) {\n\t\tif(k==0) return 1;\n\t\treturn comb(n+k-1,k);\n\t}\n\tlong rev(long l) {return pow(l,mod-2);}\n\t\n\tvoid buildpow(int l,int i) {\n\t\tpow = new long[i+1];\n\t\tpow[0] = 1;\n\t\tfor(int j=1;j<=i;j++) {\n\t\t\tpow[j] = pow[j-1]*l;\n\t\t\tif(pow[j]>mod)pow[j] %= mod;\n\t\t}\n\t}\n\tvoid buildrevpow(int l,int i) {\n\t\trevpow = new long[i+1];\n\t\trevpow[0] = 1;\n\t\tfor(int j=1;j<=i;j++) {\n\t\t\trevpow[j] = revpow[j-1]*l;\n\t\t\tif(revpow[j]>mod) revpow[j] %= mod;\t\t\n\t\t}\n\t}\n\tlong pow(long l, long i) {\n\t\tif(i==0)return 1;\n\t\telse{\n\t\t\tif(i%2==0){\n\t\t\t\tlong val = pow(l,i/2);\n\t\t\t\treturn val * val % mod;\n\t\t\t}\n\t\t\telse return pow(l,i-1) * l % mod;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "import javafx.util.Pair;\n\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable\n{\n    boolean multiple = false;\n    long MOD;\n\n    @SuppressWarnings({\"Duplicates\", \"ConstantConditions\"})\n    void solve() throws Exception\n    {\n        int k = sc.nextInt();\n        long tar = 0;\n        long[][] arr = new long[k][];\n        long[] sum = new long[k];\n        HashMap<Long, Pair<Integer, Integer>> map = new HashMap<>();\n        for (int i = 0; i < k; i++)\n        {\n            int ni = sc.nextInt();\n            arr[i] = new long[ni];\n            for (int j = 0; j < ni; j++)\n            {\n                sum[i] += (arr[i][j] = sc.nextInt());\n                map.put(arr[i][j], new Pair<>(i, j));\n            }\n            tar += sum[i];\n        }\n        if (tar % k != 0) { System.out.println(\"No\"); return; }\n        tar /= k;\n        works = new HashMap<>();\n        for (int i = 0; i < k; i++)\n        {\n            outer: for (int j = 0; j < arr[i].length; j++)\n            {\n                long val = arr[i][j];\n                long want = tar - sum[i] + val;\n                if (!map.containsKey(want)) continue;\n//                ArrayList<pli> list = new ArrayList<>();\n                int key = 1 << i;\n                int next = map.get(want).getKey();\n//                int prev = i;\n                HashSet<Integer> seen = new HashSet<>();\n                seen.add(i);\n                while (true)\n                {\n                    if (seen.contains(next))\n                    {\n                        if (next == i && want == arr[i][j])\n                            works.put(key, (((long) i) << 32) + ((long) j));\n                        break;\n                    }\n//                    list.add(new pli(want, prev));\n                    val = arr[next][map.get(want).getValue()];\n                    want = tar - sum[next] + val;\n                    if (!map.containsKey(want)) continue outer;\n                    key |= 1 << next;\n//                    prev = next;\n                    seen.add(next);\n                    next = map.get(want).getKey();\n                }\n            }\n        }\n//        dp.put(0, new ArrayList<>());\n        dp = new long[1 << k];\n        done = new boolean[1 << k];\n        yes = new boolean[1 << k];\n        yes[0] = done[0] = true;\n        long ans = r((1 << k) - 1);\n        long[] val = new long[k];\n        int[] pos = new int[k];\n        if (!yes[(1 << k) - 1]) System.out.println(\"No\");\n        else\n        {\n//            System.out.println(ans);\n//            System.out.println(map);\n            System.out.println(\"Yes\");\n            while (ans >> 32 != 0)\n            {\n                long p = works.get((int)(ans >> 32));\n                int i = (int)(p >> 32), j = (int)(p & ((1L<<32)-1));\n                long VAL = arr[i][j];\n                long want = tar - sum[i] + VAL;\n                int key = 1 << i;\n                int next = map.get(want).getKey();\n                int prev = i;\n                while (true)\n                {\n                    if (next == i)\n                    {\n                        val[map.get(want).getKey()] = want;\n                        pos[map.get(want).getKey()] = prev + 1;\n                        if (want == arr[i][j])\n                            works.put(key, (((long)i)<<32) + ((long)j));\n                        break;\n                    }\n                    val[map.get(want).getKey()] = want;\n                    pos[map.get(want).getKey()] = prev + 1;\n                    VAL = arr[next][map.get(want).getValue()];\n                    want = tar - sum[next] + VAL;\n                    key |= 1 << next;\n                    prev = next;\n                    next = map.get(want).getKey();\n                }\n\n                ans = dp[(int)(ans & ((1L << 32)- 1))];\n            }\n            for (int i = 0; i < k; i++)\n                System.out.println(val[i] + \" \" + pos[i]);\n        }\n    }\n\n    HashMap<Integer, Long> works;\n    long[] dp;\n    boolean[] done, yes;\n\n    long r(int mask)\n    {\n        if (done[mask]) return dp[mask];\n        done[mask] = true;\n        for (int s = mask; s != 0; s = (s-1) & mask)\n            if (works.keySet().contains(s))\n            {\n                int tempMask = mask;\n                for (int i = 0; i < 16; i++)\n                    if ((s & (1 << i)) != 0)\n                        tempMask ^= 1 << i;\n                r(tempMask);\n                if (yes[tempMask])\n                {\n                    yes[mask] = true;\n                    return dp[mask] = (((long)s) << 32) + tempMask;\n                }\n            }\n        return 0;\n    }\n\n    class pii { int f, s; pii(int k, int v) { f = k; s = v; } }\n    class pli { long f; int s; pli(long k, int v) { f = k; s = v; } public String toString() { return \"(\" + f + \", \" + s + \")\"; } }\n    StringBuilder ANS = new StringBuilder();\n    void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }\n    void pl(Object s) { ANS.append(s); ANS.append('\\n'); } void pl(double s) { ANS.append(s); ANS.append('\\n'); } void pl(long s) { ANS.append(s); ANS.append('\\n'); } void pl(char s) { ANS.append(s); ANS.append('\\n'); } void pl() { ANS.append(('\\n')); }\n    /*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), \"\", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }\n}", "complexity": "np", "problem": "1242_C. Sum Balance", "from": "CODEFORCES"}
{"src": "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\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\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\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 \t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new Main(),\"Main\",1<<26).start();\n\t}\t\n    int findLSB(long n)\n    {\n        long value=-n&n;\n        return map.get(value);\n    }\n\tvoid findMaxClique(long mask,int size)\n    {\n        if(mask==0)\n        {\n            if(size>maxClique)\n                maxClique=size;\n            return;    \n        }\n        while(mask>0)\n        {\n            if(Long.bitCount(mask)+size<=maxClique)\n                return;\n            int lsb=findLSB(mask);\n            mask=mask^((long)1<<lsb);\n            findMaxClique(mask&edges[lsb],size+1);\n        }\n    }\n    long edges[];\n    HashMap<Long,Integer> map=new HashMap<>();\n    int maxClique;\n\tpublic void run()\n\t{\n\t\tInputReader sc= new InputReader(System.in);\n\t\tPrintWriter w= new PrintWriter(System.out);\n        long value=1;\n        for(int i=0;i<45;i++)\n        {\n            map.put(value,i);\n            value*=2;\n        }\n        int n=sc.nextInt();\n\t    int k=sc.nextInt();\n        edges=new long[n];\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                long connect=sc.nextLong();\n                if(j>i&&connect==1)\n                    edges[i]|=(connect<<j);\n            }\n        }\n        findMaxClique(((long)1<<n)-1,0);\n        //w.print(maxClique);\n        double size=(double)maxClique;\n        double perCastle=(double)k/size;\n        double ans=perCastle*perCastle*(size*(size-1))/2;\n        w.print(ans);\n\t\tw.close();\t\t\n\t}\n}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\t// public static StringTokenizer tokenizer;\n\t// public static BufferedReader reader;\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\t// public static String proximo() {\n\t// \twhile (tokenizer == null || !tokenizer.hasMoreElements()) {\n\t// \t\ttry {\n\t// \t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t// \t\t} catch (RuntimeException e) {\n\t// \t\t\te.printStackTrace();\n\t// \t\t}\n\t// \t}\n\t// \treturn tokenizer.nextToken();\n\t// }\n\n\tpublic 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\n\n\n    public static void main(String[] args) {\n\t\tFastScanner fastScanner = new FastScanner();\n        int proximoInt = fastScanner.nextInt();\n        double proximoDouble = fastScanner.nextInt();\n        long[] graph = new long[proximoInt];\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = fastScanner.nextInt();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t graph[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n\n        int szLeft = proximoInt/2;\n        int szRight = proximoInt - szLeft;\n\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= graph[j + szRight] >> szRight;\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            int curMask = mask;\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            if (curMask != mask) continue;\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        proximoDouble/=ans;\n        saida.println(proximoDouble * proximoDouble * (ans * (ans-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.io.*;\npublic class code839E\n{\n    public static void main(String[] args) throws Exception{\n        BufferedReader bff=new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter wff=new PrintWriter(System.out);\n        String[] st=bff.readLine().split(\" \");\n        int V=Integer.parseInt(st[0]);\n        int K=Integer.parseInt(st[1]);\n        BronKerbosch bk=new BronKerbosch(V);\n        for(int i=0;i<V;i++){\n            st=bff.readLine().split(\" \");\n            for(int j=0;j<V;j++){\n                if(st[j].equals(\"1\")){\n                    bk.anadir(i,j);\n                }\n            }\n        }\n        long num=bk.numeroCamarilla();\n        wff.printf(\"%.12f\\n\", num * (num - 1.0) / 2 * K / num * K / num);\n        wff.flush();\n    }\n    \n    \n    \nstatic class BronKerbosch {\n    int V;\n    long[] neig;\n    Random random = new Random();\n    long maxClique;\n\n    public BronKerbosch(int v){\n        V=v;\n        neig=new long[V];\n    }\n\n    public void anadir(int a,int b){\n        long aux=1;\n        neig[a] |= aux << (long)b;\n    }\n    \n    public long numeroCamarilla(){\n        long numero = Long.bitCount(bronKerbosch());\n        return numero;\n    }\n    \n    public long bronKerbosch() {\n        maxClique = 0;\n        bronKerbosch2(0, (1L << V) - 1, 0);\n        return maxClique;\n    }\n\n    public void bronKerbosch2(long r, long p, long x) {\n        if (Long.bitCount(maxClique) >= Long.bitCount(r | p | x)) return;\n        long px = p | x;\n        if (px == 0) {\n            if (Long.bitCount(maxClique) < Long.bitCount(r)) {\n                maxClique = r;\n            }\n            return;\n        }\n        int cnt = Long.bitCount(px);\n        int choice = random.nextInt(cnt);\n        int u;\n        for (int i = 0; ; i++) {\n            if ((px >>> i & 1) != 0 && choice-- == 0) {\n                u = i;\n                break;\n            }\n        }\n\n        long ne = p & ~neig[u];\n        for (int v = 0; v < V; v++){\n            if ((ne >>> v & 1) != 0) {\n                bronKerbosch2(r | 1L << v, p & neig[v], x & neig[v]);\n                p &= ~(1L << v);\n                x |= 1L << v;\n            }\n        }\n    }\n\n}\n\n\n    \n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "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.Random;\nimport java.io.IOException;\nimport java.io.Reader;\nimport java.io.InputStreamReader;\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 tanzaku\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        MyInput in = new MyInput(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 k;\n        long[] neigibor;\n        Random random = new Random();\n        long maxClique;\n\n        public void solve(int testNumber, MyInput in, PrintWriter out) {\n            n = in.nextInt();\n            k = in.nextInt();\n            neigibor = new long[n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    neigibor[i] |= in.nextLong() << j;\n                }\n            }\n            long maxClique = bronKerbosch();\n            long a = Long.bitCount(maxClique);\n            dump(a);\n            out.printf(\"%.12f\\n\", a * (a - 1.0) / 2 * k / a * k / a);\n        }\n\n        static void dump(Object... o) {\n            System.err.println(Arrays.deepToString(o));\n        }\n\n        long bronKerbosch() {\n            maxClique = 0;\n            bronKerbosch2(0, (1L << n) - 1, 0);\n            return maxClique;\n        }\n\n        void bronKerbosch2(long r, long p, long x) {\n            if (Long.bitCount(maxClique) >= Long.bitCount(r | p | x)) return;\n            long px = p | x;\n            if (px == 0) {\n                if (Long.bitCount(maxClique) < Long.bitCount(r)) {\n                    maxClique = r;\n                }\n                return;\n            }\n            int cnt = Long.bitCount(px);\n            int choice = random.nextInt(cnt);\n            int u;\n            for (int i = 0; ; i++) {\n                if ((px >>> i & 1) != 0 && choice-- == 0) {\n                    u = i;\n                    break;\n                }\n            }\n//        dump(r, p, x, u, neigibor);\n            long ne = p & ~neigibor[u];\n            for (int v = 0; v < n; v++)\n                if ((ne >>> v & 1) != 0) {\n                    bronKerbosch2(r | 1L << v, p & neigibor[v], x & neigibor[v]);\n                    p &= ~(1L << v);\n                    x |= 1L << v;\n                }\n        }\n\n    }\n\n    static class MyInput {\n        private final BufferedReader in;\n        private static int pos;\n        private static int readLen;\n        private static final char[] buffer = new char[1024 * 8];\n        private static char[] str = new char[500 * 8 * 2];\n        private static boolean[] isDigit = new boolean[256];\n        private static boolean[] isSpace = new boolean[256];\n        private static boolean[] isLineSep = new boolean[256];\n\n        static {\n            for (int i = 0; i < 10; i++) {\n                isDigit['0' + i] = true;\n            }\n            isDigit['-'] = true;\n            isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n            isLineSep['\\r'] = isLineSep['\\n'] = true;\n        }\n\n        public MyInput(InputStream is) {\n            in = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public int read() {\n            if (pos >= readLen) {\n                pos = 0;\n                try {\n                    readLen = in.read(buffer);\n                } catch (IOException e) {\n                    throw new RuntimeException();\n                }\n                if (readLen <= 0) {\n                    throw new MyInput.EndOfFileRuntimeException();\n                }\n            }\n            return buffer[pos++];\n        }\n\n        public int nextInt() {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(len, isSpace);\n            int i = 0;\n            int ret = 0;\n            if (str[0] == '-') {\n                i = 1;\n            }\n            for (; i < len; i++) ret = ret * 10 + str[i] - '0';\n            if (str[0] == '-') {\n                ret = -ret;\n            }\n            return ret;\n        }\n\n        public long nextLong() {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(len, isSpace);\n            int i = 0;\n            long ret = 0;\n            if (str[0] == '-') {\n                i = 1;\n            }\n            for (; i < len; i++) ret = ret * 10 + str[i] - '0';\n            if (str[0] == '-') {\n                ret = -ret;\n            }\n            return ret;\n        }\n\n        public char nextChar() {\n            while (true) {\n                final int c = read();\n                if (!isSpace[c]) {\n                    return (char) c;\n                }\n            }\n        }\n\n        int reads(int len, boolean[] accept) {\n            try {\n                while (true) {\n                    final int c = read();\n                    if (accept[c]) {\n                        break;\n                    }\n                    if (str.length == len) {\n                        char[] rep = new char[str.length * 3 / 2];\n                        System.arraycopy(str, 0, rep, 0, str.length);\n                        str = rep;\n                    }\n                    str[len++] = (char) c;\n                }\n            } catch (MyInput.EndOfFileRuntimeException e) {\n            }\n            return len;\n        }\n\n        static class EndOfFileRuntimeException extends RuntimeException {\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "//package round428;\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//\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni();\n\t\tlong[] g = new long[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] |= nl()<<j;\n\t\t\t}\n\t\t\tg[i] |= 1L<<i;\n\t\t}\n\t\t\n\t\t// (K/M)^2*M(M-1)/2\n\t\t// K^2*(M-1)/2M\n\t\tint mc = solveMaximumClique(g);\n\t\tout.printf(\"%.14f\\n\", (double)K*K*(mc-1)/2/mc);\n\t}\n\t\n\tpublic static int solveMaximumClique(long[] g)\n\t{\n\t\tint n = g.length;\n\t\tint h = n/2;\n\t\tint[] dp = new int[1<<n-h];\n\t\tfor(int i = 0;i < 1<<h;i++){\n\t\t\tlong cover = (1L<<n)-1;\n\t\t\tfor(int j = 0;j < h;j++){\n\t\t\t\tif(i<<~j<0)cover &= g[j];\n\t\t\t}\n\t\t\tif((cover&i) == i){\n\t\t\t\tdp[(int)(cover>>>h)] = Math.max(dp[(int)(cover>>>h)], Integer.bitCount(i));\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < n-h;i++){\n\t\t\tfor(int j = 0;j < 1<<n-h;j++){\n\t\t\t\tif(j<<~i>=0){\n\t\t\t\t\tdp[j] = Math.max(dp[j], dp[j|1<<i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ret = 0;\n\t\tfor(int i = 0;i < 1<<n-h;i++){\n\t\t\tlong cover = (1L<<n)-1;\n\t\t\tfor(int j = 0;j < n-h;j++){\n\t\t\t\tif(i<<~j<0)cover &= g[j+h];\n\t\t\t}\n\t\t\tif((cover&(long)i<<h) == (long)i<<h){\n\t\t\t\tret = Math.max(ret, Integer.bitCount(i) + dp[i]);\n\t\t\t}\n\t\t}\n\t\treturn ret;\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 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", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\tpublic static class Escanear {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\t\tpublic Escanear() {\n            this(new InputStreamReader(System.in));\n        }\n\t\tpublic Escanear(Reader in) {\n            reader = new BufferedReader(in);\n        }\n        String proximo() {\n            if (tokenizer == null || !tokenizer.hasMoreElements()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return tokenizer.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(proximo());\n        }\n    }\n\n\n\n    public static void main(String[] args) {\n\t\tEscanear fastScanner = new Escanear();\n        int proximoInt = fastScanner.nextInt();\n        double proximoDouble = fastScanner.nextInt();\n        long[] graph = new long[proximoInt];\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = fastScanner.nextInt();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t graph[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n\n        int szLeft = proximoInt/2;\n        int szRight = proximoInt - szLeft;\n\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= graph[j + szRight] >> szRight;\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            int curMask = mask;\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            if (curMask != mask) continue;\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        proximoDouble/=ans;\n        saida.println(proximoDouble * proximoDouble * (ans * (ans-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n/*\n * Heart 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...\n */\npublic class Main\n{\n\tpublic static void main(String[]args) throws Exception\n\t{\n\t\t\tint n=ni();\n\t\t\tdouble ke=ni();\n\t\t\tboolean[][]a=new boolean[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\ta[i][j]=ni()==0;\n\t\t\tint left=n/2;\n\t\t\tint[]ldp=new int[1<<left];\n\t\t\tint[]rdp=new int[1<<(n-left)];\n\t\t\tint[]pow=new int[25];\n\t\t\tpow[0]=1;\n\t\t\tfor(int i=1; i<25; i++)\n\t\t\t\tpow[i]=pow[i-1]<<1;\n\t\t\tfor(int i=0; i<pow[left]; i++)\n\t\t\t\tou:for(int j=0; j<left; j++)\n\t\t\t\t\tif((i>>j)%2==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint te=i;\n\t\t\t\t\t\tfor(int k=0; te>0; k++,te>>=1)\n\t\t\t\t\t\t\tif(a[j][k]&&(te&1)!=0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tldp[i+pow[j]]=max(ldp[i+pow[j]],ldp[i]);\n\t\t\t\t\t\t\t\tcontinue ou;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tldp[i+pow[j]]=max(ldp[i+pow[j]],ldp[i]+1);\n\t\t\t\t\t}\n\t\t\tint right=n-left;\n\t\t\tfor(int i=0; i<pow[right]; i++)\n\t\t\t\tou:for(int j=0; j<right; j++)\n\t\t\t\t\tif((i>>j)%2==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint lul=j+left;\n\t\t\t\t\t\tint te=i;\n\t\t\t\t\t\tfor(int k=left; te>0; k++,te>>=1)\n\t\t\t\t\t\t\tif(a[lul][k]&&(te&1)!=0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trdp[i+pow[j]]=max(rdp[i+pow[j]],rdp[i]);\n\t\t\t\t\t\t\t\tcontinue ou;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\trdp[i+pow[j]]=max(rdp[i+pow[j]],rdp[i]+1);\n\t\t\t\t\t}\n\t\t\tint maxi=0;\n\t\t\tfor(int i=0; i<pow[left]; i++)\n\t\t\t{\n\t\t\t\tint lol=0;\n\t\t\t\tint te=i;\n\t\t\t\tfor(int j=0; te>0; j++,te>>=1)\n\t\t\t\t\tif((te&1)!=0)\n\t\t\t\t\t\tfor(int k=0; k<right; k++)\n\t\t\t\t\t\t\tif(a[j][k+left])\n\t\t\t\t\t\t\t\tlol|=pow[k];\n\t\t\t\tmaxi=max(maxi,ldp[i]+rdp[pow[right]-1-lol]);\n\t\t\t}\n\t\t\tpr((ke*ke*(maxi-1))/(2*maxi));\n\t\tSystem.out.println(output);\n\t}\n\t///////////////////////////////////////////\n\t///////////////////////////////////////////\n\t///template from here\n//\tstatic final int mod=998_244_353;\n\tstatic final int mod=1000_000_007;\n\tstatic final double eps=1e-7;\n\tstatic final long inf=1000_000_000_000_000_000L;\n\tstatic class pair\n\t{\n\t\tint a,b;\n\t\tpair(){}\n\t\tpair(int c,int d){a=c;b=d;}\n\t\t@Override\n\t\tpublic int hashCode()\n\t\t{\n\t\t\treturn (a+\" \"+b).hashCode();\n\t\t}\n\t\tpublic boolean equals(Object c)\n\t\t{\n\t\t\treturn (a==(((pair)c).a)&&b==(((pair)c).b));\n\t\t}\n\t}\n\tpublic static void sort(int[][]a)\n\t{\n\t\tArrays.sort(a, new Comparator<int[]>()\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]<b[0])\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\t});\n\t}\n\tstatic interface combiner\n\t{\n\t\tpublic int combine(int a, int b);\n\t}\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.print(output);output=new StringBuilder();}\n\tstatic int ni(){return Integer.parseInt(in.next());}\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; i++)a[i]=ni();return a;}\n\tstatic int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}\n\tstatic long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}\n\tstatic String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}\n\tstatic double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}\n\tstatic Reader in=new Reader();\n\tstatic StringBuilder output=new StringBuilder();\n\tstatic Random rn=new Random();\n\tstatic void reverse(int[]a){for(int i=0; i<a.length/2; i++){a[i]^=a[a.length-i-1];a[a.length-i-1]^=a[i];a[i]^=a[a.length-i-1];}}\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 vectorl implements Iterable<Long>\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<Long> iterator() {\n\t\t\tIterator<Long> hola=new Iterator<Long>()\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<size;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Long next() {\n\t\t\t\t\t\t\treturn a[cur++];\n\t\t\t\t\t\t}\t\t\t\t\n\t\t\t\t\t};\n\t\t\treturn hola;\n\t\t}\n\t}\n\tstatic class vector implements Iterable<Integer>\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<Integer> iterator() {\n\t\t\tIterator<Integer> hola=new Iterator<Integer>()\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<size;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Integer next() {\n\t\t\t\t\t\t\treturn a[cur++];\n\t\t\t\t\t\t}\t\t\t\t\n\t\t\t\t\t};\n\t\t\treturn hola;\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} ", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\tpublic static class Escanear {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\t\tpublic Escanear() {\n            this(new InputStreamReader(System.in));\n        }\n\t\tpublic Escanear(Reader in) {\n            reader = new BufferedReader(in);\n        }\n        String proximo() {\n            if (tokenizer == null || !tokenizer.hasMoreElements()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return tokenizer.nextToken();\n        }\n        \n        int proximoNum() {\n            return Integer.parseInt(proximo());\n        }\n    }\n    public static void main(String[] args) {\n\t\tEscanear escanear = new Escanear();\n\t\tint proximoInt = escanear.proximoNum();\n        long[] aux = new long[proximoInt];\n        double proximoDouble = escanear.proximoNum();\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = escanear.proximoNum();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t aux[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n        int esquerda = proximoInt/2;\n        int direita = proximoInt - esquerda;\n\t\tint maiorMascara = 1 << esquerda;\n\t\tint[] depois = new int[1 << esquerda];\n\t\tInteger mascara = 1;\n\t\twhile (mascara < maiorMascara) {\n\t\t\tint mascaraAtual = mascara;\n\n            for(int j = 0; j < esquerda; j++) {\n                if (((1 << j) & mascara) > 0) {\n                    mascaraAtual &= aux[j + direita] >> direita;\n                    depois[mascara] = Math.max(depois[mascara], depois[mascara ^ (1 << j)]);\n                }\n            }\n            if (mascara == mascaraAtual) {\n                depois[mascara] = Math.max(depois[mascara],Integer.bitCount(mascara));\n\t\t\t}\n\t\t\tmascara++;\n\t\t}\n        // for(int mascara = 1; mascara < maiorMascara; mascara++) {\n        //     int mascaraAtual = mascara;\n\n        //     for(int j = 0; j < esquerda; j++) {\n        //         if (((1 << j) & mascara) > 0) {\n        //             mascaraAtual &= aux[j + direita] >> direita;\n        //             depois[mascara] = Math.max(depois[mascara], depois[mascara ^ (1 << j)]);\n        //         }\n        //     }\n        //     if (mascara == mascaraAtual) {\n        //         depois[mascara] = Math.max(depois[mascara],Integer.bitCount(mascara));\n        //     }\n        // }\n        int auxiliar = 0;\n        int mascaraMaxima = 1 << direita;\n        for(int masc = 0; masc < mascaraMaxima; masc++) {\n            int mascaraCorrente = masc;\n            int mascaraValor = maiorMascara -1;\n            for(int j = 0; j < direita; j++) {\n                if (((1 << j) & masc) > 0) {\n                    mascaraCorrente &= (aux[j] & (mascaraMaxima-1));\n                    mascaraValor &= aux[j] >> direita;\n                }\n            }\n            if (mascaraCorrente != masc) continue;\n            auxiliar = Math.max(auxiliar, Integer.bitCount(masc) + depois[mascaraValor]);\n        }\n        proximoDouble/=auxiliar;\n        saida.println(proximoDouble * proximoDouble * (auxiliar * (auxiliar-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n\tstatic int a[][],n;\n\tstatic boolean isClique[];\n\tstatic int maxClique[];\n\tstatic void DFS1(int p,int n,int S)\n\t{\n\t\tif(p>n)\n\t\t{\n\t\t\tisClique[S]=true;\n\t\t\treturn ;\n\t\t}\n\t\tDFS1(p+1,n,S);\n\t\tboolean mark=true;\n\t\tfor(int i=1;i<p;++i)\n\t\t\tif((S>>(i-1)&1)==1&&a[p][i]==0)\n\t\t\t\tmark=false;\n\t\tif(mark)\n\t\t\tDFS1(p+1,n,1<<(p-1)|S);\n\t}\n\tstatic void DFS2(int p,int n,int m,int S)\n\t{\n\t\tif(p>n)\n\t\t{\n\t\t\tint cnt=0;\n\t\t\tfor(int i=m;i<=n;++i)\n\t\t\t\tif((S>>(i-m)&1)==1)\n\t\t\t\t\t++cnt;\n\t\t\tmaxClique[S]=cnt;\n\t\t\treturn ;\n\t\t}\n\t\tDFS2(p+1,n,m,S);\n\t\tboolean mark=true;\n\t\tfor(int i=m;i<p;++i)\n\t\t\tif((S>>(i-m)&1)==1&&a[p][i]==0)\n\t\t\t\tmark=false;\n\t\tif(mark)\n\t\t\tDFS2(p+1,n,m,1<<(p-m)|S);\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tn=Integer.parseInt(sc.next());\n\t\ta=new int [n+10][n+10];\n\t\tint cap=Integer.parseInt(sc.next());\n\t\tfor(int i=1;i<=n;++i)\n\t\t\tfor(int j=1;j<=n;++j)\n\t\t\t\ta[i][j]=Integer.parseInt(sc.next());\n\t\tint m=(n+1)>>1;\n\t\tisClique=new boolean [1<<m];\n\t\tArrays.fill(isClique,false);\n\t\tDFS1(1,m,0);\n\t\tmaxClique=new int [1<<(n-m)];\n\t\tArrays.fill(maxClique,0);\n\t\tDFS2(m+1,n,m+1,0);\n\t\tfor(int i=1;i<1<<(n-m);++i)\n\t\t\tfor(int j=m+1;j<=n;++j)\n\t\t\t\tif((i>>(j-m-1)&1)==1)\n\t\t\t\t\tmaxClique[i]=Math.max(maxClique[i],maxClique[i-(1<<(j-m-1))]);\n\t\tint ans=0,tmp[]=new int [m+10];\n\t\tfor(int i=0;i<1<<m;++i)\n\t\t\tif(isClique[i])\n\t\t\t{\n\t\t\t\tint mask=0,cnt=0;\n\t\t\t\tfor(int j=1;j<=m;++j)\n\t\t\t\t\tif((i>>(j-1)&1)==1)\n\t\t\t\t\t\ttmp[++cnt]=j;\n\t\t\t\tfor(int j=m+1;j<=n;++j)\n\t\t\t\t{\n\t\t\t\t\tboolean mark=true;\n\t\t\t\t\tfor(int k=1;k<=cnt;++k)\n\t\t\t\t\t\tif(a[j][tmp[k]]==0)\n\t\t\t\t\t\t\tmark=false;\n\t\t\t\t\tif(mark)\n\t\t\t\t\t\tmask|=1<<(j-m-1);\n\t\t\t\t}\n\t\t\t\tans=Math.max(ans,cnt+maxClique[mask]);\n\t\t\t}\n\t\tSystem.out.printf(\"%.9f\\n\",cap*cap*(ans-1)/2.0/ans);\n\t}\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n// 1 -> n/2  XX n/2 + 1 -> n\npublic class MotherOfDragons\n{\n\tstatic boolean[][] adjMatrix;\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n//\t\tfor (int i = 1; i <= n; i++)\n//\t\t\tSystem.err.printf(\"%d %.12f\\n\",i, (k*k*((i-1)/(2.0*i))));\n\t\tadjMatrix = new boolean[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\tadjMatrix[i][j] = sc.nextInt() == 1;\n\t\t\n\t\tlong[] edges = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tlong val = 0;\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\tif(adjMatrix[i][j] || i == j)\n\t\t\t\t\tval |= 1l<<j;\n\t\t\tedges[i] = val;\n\t\t}\n\t\t\n\t\tint h = n/2;\n\t\t\n\t\tint[] cliques = new int[1<<h];\n\t\tfor (int i = 1; i < 1<<h; i++)\n\t\t{\n\t\t\tint nodes = i;\n\t\t\tfor (int j = 0; j < h; j++)\n\t\t\t\tif((i & (1 << j)) != 0)\n\t\t\t\t\tnodes &= edges[j];\n\t\t\tif(nodes == i)\n\t\t\t\tcliques[i] = Integer.bitCount(i);\n\t\t}\n\t\t\n\t\tfor (int i = 1; i < 1<<h; i++)\n\t\t\tfor (int j = 0; j < h; j++)\n\t\t\t\tif((i & (1 << j)) != 0)\n\t\t\t\t\tcliques[i] = Math.max(cliques[i], cliques[i ^ (1<<j)]);\n\t\t\n\t\tint max = 0;\n\t\tfor (int i = 0; i < cliques.length; i++)\n\t\t\tmax = Math.max(max, cliques[i]);\n\t\tfor (int i = 1; i < 1<<(n-h); i++)\n\t\t{\n\t\t\tlong all = -1l;\n\t\t\tlong tmp = (1l*i)<<h;\n\t\t\tfor (int j = h; j < n; j++)\n\t\t\t\tif((tmp & (1l << j)) != 0)\n\t\t\t\t\tall &= edges[j];\n\t\t\tlong node = all&tmp;\n\t\t\tif(node != tmp)\n\t\t\t\tcontinue;\n\t\t\tint connected = (int)(all & ((1<<h)-1));\n\t\t\tmax = Math.max(max, cliques[connected] + Integer.bitCount(i));\n\t\t}\n\t\t\n\t\tSystem.out.printf(\"%.12f\\n\", (k*k*((max-1)/(2.0*max))));\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)\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{ return Double.parseDouble(next()); }\t\n\t}\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class E {\n    void solve(BufferedReader in) throws Exception {\n        int[] xx = toInts(in.readLine());\n        int n = xx[0];\n        double k = xx[1];\n        int[][] board = new int[n][n];\n        for(int i = 0; i<n; i++) board[i] = toInts(in.readLine());\n        int fst = n/2;\n        int snd = n - fst;\n        int[] maxc = new int[1<<fst];\n        int max = 1;\n        for(int i = 0; i<(1<<fst); i++) {\n            for(int j = 0; j<fst; j++) {\n                if((i&(1<<j)) != 0) maxc[i] = Math.max(maxc[i], maxc[i^(1<<j)]);\n            }\n            boolean ok = true;\n            for(int a = 0; a<fst; a++) if(((1<<a)&i) != 0) {\n                for(int b = a+1; b<fst; b++) if(((1<<b)&i) != 0) {\n                    if(board[a][b] == 0) ok = false;\n                }\n            }\n            if(ok) {\n                maxc[i] = Integer.bitCount(i);\n                max = Math.max(max, maxc[i]);\n            }\n        }\n        for(int i = 0; i<(1<<snd); i++) {\n            boolean ok = true;\n            for(int a = 0; a<snd; a++) if(((1<<a)&i) != 0) {\n                for(int b = a+1; b<snd; b++) if(((1<<b)&i) != 0) {\n                    if(board[a+fst][b+fst] == 0) ok = false;\n                }\n            }\n            if(!ok) continue;\n            int mask = 0;\n            for(int a = 0; a<fst; a++) {\n                ok = true;\n                for(int b = 0; b<snd; b++) {\n                    if(((1<<b)&i) != 0) {\n                        if(board[a][b+fst] == 0) ok = false;\n                    }\n                }\n                if(ok) mask |= (1<<a);\n            }\n            max = Math.max(Integer.bitCount(i) + maxc[mask], max);\n        }\n        System.out.println(k*k*(max-1.0)/(2*max));\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<a.length; i++) o[i] = toInt(a[i]);\n        return o;\n    }\n    void e(Object o) {\n        System.err.println(o);\n    }\n    public static void main(String[] args) throws Exception{\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        (new E()).solve(in);\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n\n\npublic class ELR {\n\n\tstatic double solveUnweighted (int nodes, long curr, long pool, long excl) {\n\t\tif (pool == 0 && excl == 0) {\n\t\t\tint cnt = 0;\n\t\t\tfor (int i = 0; i < nodes; i++)\n\t\t\t\tif ((curr & 1L << i) > 0)\n\t\t\t\t\tcnt++;\n\t\t\t\n\t\t\tdouble cont = (k / (cnt*1.0));\n\t\t\tdouble edges = (cnt) * (cnt - 1) / 2.0;\n\t\t\treturn cont * cont * edges;\n\t\t}\n\t\tdouble res = 0;\n\t\tint j = 0;\n\t\tfor (int i = 0; i < nodes; i++)\n\t\t\tif ((pool & 1L << i) > 0 || (excl & 1L << i) > 0)\n\t\t\t\tj = i;\n\n\t\tfor (int i = 0; i < nodes; i++) {\n\t\t\tif ((pool & 1L << i) == 0 || adj[i][j])\n\t\t\t\tcontinue;\n\t\t\tlong ncurr = curr, npool = 0, nexcl = 0;\n\t\t\tncurr |= 1L << i;\n\n\t\t\tfor (int k = 0; k < nodes; k++) {\n\t\t\t\tif (adj[i][k]) {\n\t\t\t\t\tnpool |= pool & 1L << k;\n\t\t\t\t\tnexcl |= excl & 1L << k;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres = Math.max(res, solveUnweighted(nodes, ncurr, npool, nexcl));\n\n\t\t\tpool &= ~(1L << i);\n\t\t\texcl |= 1L >> i;\n\t\t}\n\t\treturn res;\n\t}\n\tpublic static void main(String[] args) {new Thread(null, new Runnable() { public void run() {try {\n\t\tsol();\n\t} catch (Throwable e) {\n\t\t\n\t\te.printStackTrace();\n\t}}}, \"2\",1<<26).start();}\n\t\n\tstatic int n,k;\n\tstatic boolean adj[][];\n\tpublic static void sol() throws Throwable {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tadj = new boolean[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\tadj[i][j] = sc.nextInt() == 1;\n\t\t\t}\n\t\t}\n\t\tdouble ans = solveUnweighted(n, 0, (1L << n) - 1, 0);\n\t\tSystem.out.println(ans);\n\t}\n\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String s) throws FileNotFoundException {\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\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}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "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 Rustam Musin (PloadyFree@gmail.com)\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskE solver = new TaskE();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE {\n        int n;\n        double k;\n        boolean[][] g;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.readInt();\n            k = in.readInt();\n\n            g = new boolean[n][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    g[i][j] = in.readInt() == 1;\n                }\n            }\n\n            double answer = solve();\n            out.printFormat(\"%.20f\", answer);\n        }\n\n        private double solve() {\n            int firstPartSize = g.length / 2;\n            int secondPartSize = g.length - firstPartSize;\n\n            int[] firstPart = findMaxCliqueSize(firstPartSize);\n\n            int m1Full = (1 << firstPartSize) - 1;\n            int maxCliqueSize = 1;\n            for (int m = 0; m < 1 << secondPartSize; m++) {\n                if (isClique(secondPartSize, m, firstPartSize)) {\n                    int m1 = m1Full;\n                    for (int j = 0; j < secondPartSize; j++) {\n                        if (bit(m, j)) {\n                            for (int i = 0; i < firstPartSize; i++) {\n                                if (bit(m1, i) && !g[i][j + firstPartSize]) {\n                                    m1 ^= 1 << i;\n                                }\n                            }\n                        }\n                    }\n                    int firstCliqueSize = firstPart[m1];\n                    int secondCliqueSize = Integer.bitCount(m);\n                    int curCliqueSize = firstCliqueSize + secondCliqueSize;\n                    if (curCliqueSize > maxCliqueSize) {\n                        maxCliqueSize = curCliqueSize;\n                    }\n                }\n            }\n\n            return k * k * (maxCliqueSize - 1) / (2 * maxCliqueSize);\n        }\n\n        private int[] findMaxCliqueSize(int size) {\n            int[] dp = new int[1 << size];\n            for (int m = 1; m < 1 << size; m++) {\n                if (isClique(size, m, 0)) {\n                    dp[m] = Integer.bitCount(m);\n                }\n            }\n            for (int m = 1; m < 1 << size; m++) {\n                for (int i = 0; i < size; i++) {\n                    if ((m >> i & 1) == 0) {\n                        dp[m | (1 << i)] = Math.max(dp[m | (1 << i)], dp[m]);\n                    }\n                }\n            }\n            return dp;\n        }\n\n        private boolean isClique(int size, int m, int offset) {\n            for (int i = 0; i < size; i++) {\n                if (bit(m, i)) {\n                    for (int j = i + 1; j < size; j++) {\n                        if (bit(m, j) && !g[i + offset][j + offset]) {\n                            return false;\n                        }\n                    }\n                }\n            }\n            return true;\n        }\n\n        private boolean bit(int m, int b) {\n            return (m >> b & 1) != 0;\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 printFormat(String format, Object... objects) {\n            writer.printf(format, objects);\n        }\n\n        public void close() {\n            writer.close();\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\tpublic static class Escanear {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\t\tpublic Escanear() {\n            this(new InputStreamReader(System.in));\n        }\n\t\tpublic Escanear(Reader in) {\n            reader = new BufferedReader(in);\n        }\n        String proximo() {\n            if (tokenizer == null || !tokenizer.hasMoreElements()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return tokenizer.nextToken();\n        }\n        \n        int proximoNum() {\n            return Integer.parseInt(proximo());\n        }\n    }\n\n\n\n    public static void main(String[] args) {\n\t\tEscanear escanear = new Escanear();\n        int proximoInt = escanear.proximoNum();\n        double proximoDouble = escanear.proximoNum();\n        long[] aux = new long[proximoInt];\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = escanear.proximoNum();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t aux[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n\n        int esquerda = proximoInt/2;\n        int direita = proximoInt - esquerda;\n\n        int[] depois = new int[1 << esquerda];\n        int maiorMascara = 1 << esquerda;\n\n        for(int mascara = 1; mascara <maiorMascara; mascara++) {\n            int mascaraAtual = mascara;\n\n            for(int j = 0; j < esquerda; j++) {\n                if (((1 << j) & mascara) > 0) {\n                    mascaraAtual &= aux[j + direita] >> direita;\n                    depois[mascara] = Math.max(depois[mascara], depois[mascara ^ (1 << j)]);\n                }\n            }\n            if (mascara == mascaraAtual) {\n                depois[mascara] = Math.max(depois[mascara],Integer.bitCount(mascara));\n            }\n        }\n        int auxiliar = 0;\n        int mascaraMaxima = 1 << direita;\n        for(int mascara = 0; mascara < mascaraMaxima; mascara++) {\n            int mascaraCorrente = mascara;\n            int mascaraValor = maiorMascara -1;\n            for(int j = 0; j < direita; j++) {\n                if (((1 << j) & mascara) > 0) {\n                    mascaraCorrente &= (aux[j] & (mascaraMaxima-1));\n                    mascaraValor &= aux[j] >> direita;\n                }\n            }\n            if (mascaraCorrente != mascara) continue;\n            auxiliar = Math.max(auxiliar, Integer.bitCount(mascara) + depois[mascaraValor]);\n        }\n        proximoDouble/=auxiliar;\n        saida.println(proximoDouble * proximoDouble * (auxiliar * (auxiliar-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\tpublic static class Escanear {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\t\tpublic Escanear() {\n            this(new InputStreamReader(System.in));\n        }\n\t\tpublic Escanear(Reader in) {\n            reader = new BufferedReader(in);\n        }\n        String proximo() {\n            if (tokenizer == null || !tokenizer.hasMoreElements()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return tokenizer.nextToken();\n        }\n        \n        int proximoNum() {\n            return Integer.parseInt(proximo());\n        }\n    }\n    public static void main(String[] args) {\n\t\tEscanear escanear = new Escanear();\n\t\tint proximoInt = escanear.proximoNum();\n        long[] aux = new long[proximoInt];\n        double proximoDouble = escanear.proximoNum();\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = escanear.proximoNum();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t aux[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n        int esquerda = proximoInt/2;\n        int direita = proximoInt - esquerda;\n\t\tint maiorMascara = 1 << esquerda;\n\t\tint[] depois = new int[1 << esquerda];\n\t\tInteger mascara = 1;\n\t\twhile (mascara < maiorMascara) {\n\t\t\tint mascaraAtual = mascara;\n            for(int j = 0; j < esquerda; j++) {\n                if (((1 << j) & mascara) > 0) {\n                    mascaraAtual &= aux[j + direita] >> direita;\n                    depois[mascara] = Math.max(depois[mascara], depois[mascara ^ (1 << j)]);\n                }\n            }\n            if (mascara.equals(mascaraAtual)) {\n                depois[mascara] = Math.max(depois[mascara],Integer.bitCount(mascara));\n\t\t\t}\n\t\t\tmascara++;\n\t\t}\n        int auxiliar = 0;\n        int mascaraMaxima = 1 << direita;\n        for(int i = 0; i < mascaraMaxima; i++) {\n            int mascaraCorrente = i;\n            int mascaraValor = maiorMascara -1;\n            for(int j = 0; j < direita; j++) {\n                if (((1 << j) & i) > 0) {\n                    mascaraCorrente &= (aux[j] & (mascaraMaxima-1));\n                    mascaraValor &= aux[j] >> direita;\n                }\n            }\n            if (mascaraCorrente != i) continue;\n            auxiliar = Math.max(auxiliar, Integer.bitCount(i) + depois[mascaraValor]);\n        }\n        proximoDouble/=auxiliar;\n        saida.println(proximoDouble * proximoDouble * (auxiliar * (auxiliar-1))/2);\n        saida.flush();\n    }\n}\n\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tprivate static StringTokenizer st;\n\tprivate static int n;\n\tprivate static int k;\n\n\tprivate static boolean[][] graph;\n\tprivate static int[] dp;\n\tprivate static int maxCliqueSize;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tst = new StringTokenizer(reader.readLine());\n\t\tn = Integer.parseInt(st.nextToken());\n\t\tk = Integer.parseInt(st.nextToken());\n\n\t\tgraph = new boolean[n][n];\n\t\tdp = new int[1 << (n / 2)];\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tst = new StringTokenizer(reader.readLine());\n\n\t\t\tfor (int j = 0; j < n; ++j)\n\t\t\t\tgraph[i][j] = st.nextToken().equals(\"1\");\n\t\t}\n\n\t\treader.close();\n\n\t\t/* fill dp for first subset */\n\t\tint size1 = n / 2;\n\t\tint border = 1 << size1;\n\t\tfor (int mask = 1; mask < border; ++mask) {\n\t\t\t/* check if mask is complete graph */\n\n\t\t\tboolean isComplete = true;\n\t\t\tfor (int i = 0; i < size1; ++i) {\n\t\t\t\tif (((mask >> i) & 1) == 0)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tfor (int j = i + 1; j < size1; ++j) {\n\t\t\t\t\tif (((mask >> j) & 1) == 0)\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tif (!graph[i][j]) {\n\t\t\t\t\t\tisComplete = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!isComplete)\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (isComplete)\n\t\t\t\tdp[mask] = Integer.bitCount(mask);\n\t\t}\n\n\t\tfor (int mask = 1; mask < border; ++mask) {\n\t\t\tfor (int i = 0; i < size1; ++i) {\n\t\t\t\tif (((mask >> i) & 1) == 0) {\n\t\t\t\t\tdp[mask | (1 << i)] = Math.max(dp[mask | (1 << i)], dp[mask]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t\t/* process second subset */\n\t\tmaxCliqueSize = 1;\n\t\tint size2 = n - n /2;\n\t\tborder = (1 << size2);\n\n\t\tfor (int mask = 0; mask < border; ++mask) {\n\n\t\t\tboolean isComplete = true;\n\t\t\tfor (int i = 0; i < size2; ++i) {\n\t\t\t\tif (((mask >> i) & 1) == 0)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tfor (int j = i + 1; j < size2; ++j) {\n\t\t\t\t\tif (((mask >> j) & 1) != 0 && !graph[i + size1][j + size1]) {\n\t\t\t\t\t\tisComplete = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!isComplete)\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (!isComplete)\n\t\t\t\tcontinue;\n\n\t\t\tint mask1 = (1 << size1) - 1;\n\n\t\t\tfor (int i = 0; i < size2; ++i) {\n\t\t\t\tif (((mask >> i) & 1) == 0)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tfor (int j = 0; j < size1; ++j) {\n\t\t\t\t\tif (!graph[j][i + size1] && ((mask1 >> j) & 1) != 0)\n\t\t\t\t\t\tmask1 ^= (1 << j);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmaxCliqueSize = Math.max(maxCliqueSize, dp[mask1] + Integer.bitCount(mask));\n\t\t}\n\n\t\t// System.out.println(maxCliqueSize);\n\t\tdouble answer = (1.0 * k * k * (maxCliqueSize - 1) / (2 * maxCliqueSize));\n\t\tSystem.out.printf(\"%.15f\", answer);\n\t}\n}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.util.StringTokenizer;\n\npublic class MotherOfDragons {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int n = scanner.nextInt();\n        double k = scanner.nextInt();\n        long[] graph = new long[n];\n        for(Integer i = 0; i < n; i++) {\n            for(Integer j =0; j < n; j++) {\n                Integer val = scanner.nextInt();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t graph[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n\n        int szLeft = n/2;\n        int szRight = n - szLeft;\n\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= graph[j + szRight] >> szRight;\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            int curMask = mask;\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            if (curMask != mask) continue;\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        k/=ans;\n        out.println(k * k * (ans * (ans-1))/2);\n        out.flush();\n    }\n\n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n\n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\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\tint n=sc.nextInt(),k=sc.nextInt();\n\t\tboolean [][]adj=new boolean[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\tadj[i][j]=sc.nextInt()==1;\n\t\tint n1=n/2,n2=n-n1;\n\t\tint []clique=new int [1<<n1];\n\t\tfor(int msk=1;msk<1<<n1;msk++)\n\t\t{\n\t\t\tboolean ok=true;\n\t\t\tfor(int i=0;i<n1;i++) if((msk & 1<<i) !=0)\n\t\t\t\tfor(int j=i+1;j<n1;j++)\n\t\t\t\t\tif((msk & 1<<j) !=0 && !adj[i][j])\n\t\t\t\t\t\tok=false;\n\t\t\tif(ok)\n\t\t\t\tclique[msk]=Integer.bitCount(msk);\n\t\t}\n\t\t\n\t\tint []edges=new int [n2];\n\t\tfor(int i=0;i<n2;i++)\n\t\t{\n\t\t\tint msk=0;\n\t\t\tfor(int j=0;j<n1;j++)\n\t\t\t\tif(adj[i+n1][j])\n\t\t\t\t\tmsk|=1<<j;\n\t\t\tedges[i]=msk;\n\t\t}\n\t\tint max=0;\n\t\tfor(int msk=1;msk<1<<n1;msk++)\n\t\t\tfor(int i=0;i<n1;i++)\n\t\t\t\tif((msk & 1<<i) !=0)\n\t\t\t\t\tmax=Math.max(max, clique[msk]=Math.max(clique[msk], clique[msk^(1<<i)]));\n\t\t\n\t\tfor(int msk=1;msk<1<<n2;msk++)\n\t\t{\n\t\t\tint all=(1<<n1)-1;\n\t\t\tfor(int j=0;j<n2;j++)\n\t\t\t\tif((msk & 1<<j) !=0)\n\t\t\t\t\tall &=edges[j];\n\t\t\tboolean ok=true;\n\t\t\tfor(int i=0;i<n2;i++) if((msk & 1<<i) !=0)\n\t\t\t\tfor(int j=i+1;j<n2;j++)\n\t\t\t\t\tif((msk & 1<<j) !=0 && !adj[i+n1][j+n1])\n\t\t\t\t\t\tok=false;\n\t\t\tif(ok)\n\t\t\t\tmax=Math.max(max, Integer.bitCount(msk)+clique[all]);\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\tout.printf(\"%.9f\\n\",k*1.0*k*(max-1)/(2*max));\n\t\t\n\t\tout.close();\n\t\t\n\t\t\n\t}\n\tstatic class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n \n        public Scanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n \n        public Scanner(FileReader s) {\n            br = new BufferedReader(s);\n        }\n \n        public String next() throws IOException {\n            while (st == null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n \n        public int nextInt() throws IOException {\n            return Integer.parseInt(next());\n        }\n \n        public long nextLong() throws IOException {\n            return Long.parseLong(next());\n        }\n \n        public String nextLine() throws IOException {\n            return br.readLine();\n        }\n        public boolean ready() throws IOException {return br.ready();}\n        public double nextDouble() throws IOException {return Double.parseDouble(next());}\n       \n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class E {\n    void solve(BufferedReader in) throws Exception {\n        int[] xx = toInts(in.readLine());\n        int n = xx[0];\n        double k = xx[1];\n        int[][] board = new int[n][n];\n        for(int i = 0; i<n; i++) board[i] = toInts(in.readLine());\n        int fst = n/2;\n        int snd = n - fst;\n        int[] maxc = new int[1<<fst];\n        int max = 1;\n        for(int i = 0; i<(1<<fst); i++) {\n            for(int j = 0; j<fst; j++) {\n                if((i&1<<j) != 0) maxc[i] = Math.max(maxc[i], maxc[i^(1<<j)]);\n            }\n            boolean ok = true;\n            for(int a = 0; a<fst; a++) if((i&1<<a) != 0) {\n                for(int b = a+1; b<fst; b++) if((i&1<<b) != 0) {\n                    if(board[a][b] == 0) ok = false;\n                }\n            }\n            if(ok) {\n                maxc[i] = Integer.bitCount(i);\n                max = Math.max(max, maxc[i]);\n            }\n        }\n        for(int i = 0; i<(1<<snd); i++) {\n            boolean ok = true;\n            for(int a = 0; a<snd; a++) if((i&1<<a) != 0) {\n                for(int b = a+1; b<snd; b++) if((i&1<<b) != 0) {\n                    if(board[a+fst][b+fst] == 0) ok = false;\n                }\n            }\n            if(!ok) continue;\n            int mask = 0;\n            for(int a = 0; a<fst; a++) {\n                ok = true;\n                for(int b = 0; b<snd; b++) {\n                    if((i&1<<b) != 0) {\n                        if(board[a][b+fst] == 0) ok = false;\n                    }\n                }\n                if(ok) mask |= (1<<a);\n            }\n            max = Math.max(Integer.bitCount(i) + maxc[mask], max);\n        }\n        System.out.println(k*k*(max-1.0)/(2*max));\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<a.length; i++) o[i] = toInt(a[i]);\n        return o;\n    }\n    void e(Object o) {\n        System.err.println(o);\n    }\n    public static void main(String[] args) throws Exception{\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        (new E()).solve(in);\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\t// public static StringTokenizer tokenizer;\n\t// public static BufferedReader reader;\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\t// public static String proximo() {\n\t// \twhile (tokenizer == null || !tokenizer.hasMoreElements()) {\n\t// \t\ttry {\n\t// \t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t// \t\t} catch (RuntimeException e) {\n\t// \t\t\te.printStackTrace();\n\t// \t\t}\n\t// \t}\n\t// \treturn tokenizer.nextToken();\n\t// }\n\n\tpublic static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n\n\n\n    public static void main(String[] args) {\n\t\tFastScanner fastScanner = new FastScanner();\n        int proximoInt = fastScanner.nextInt();\n        double proximoDouble = fastScanner.nextInt();\n        long[] graph = new long[proximoInt];\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = fastScanner.nextInt();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t graph[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n\n        int szLeft = proximoInt/2;\n        int szRight = proximoInt - szLeft;\n\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= graph[j + szRight] >> szRight;\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            int curMask = mask;\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            if (curMask != mask) continue;\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        proximoDouble/=ans;\n        saida.println(proximoDouble * proximoDouble * (ans * (ans-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class MotherOfDragons {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int n = scanner.nextInt();\n        double k = scanner.nextInt();\n        long[] graph = new long[n];\n        for(int i = 0; i < n; i++) {\n            for(int j =0; j < n; j++) {\n                int val = scanner.nextInt();\n                if (val == 1 || i == j) graph[i] |= 1L << j;\n            }\n        }\n        //meet in the middle approach\n        int szLeft = n/2;\n        int szRight = n - szLeft;\n        //max size of clique\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n        //iterate over every left mask\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n            //go over every bit in the mask\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    //update the union of reachability\n                    curMask &= graph[j + szRight] >> szRight;\n                    //can also attempt to pull from prev mask for max size\n                    //will not be optimal if end update happens, but otherwise is useful for dp\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            //if the union of connectedness is the starting mask then we have a clique\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            //mask to track if the current creates its own clique\n            int curMask = mask;\n            //mask to track the connection between the halves\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    //need to mask out the left side bits\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    //update corresp avail in the left side\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            //not a clique portion\n            if (curMask != mask) continue;\n            //update answer\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        k/=ans;\n        out.println(k * k * (ans * (ans-1))/2);\n        out.flush();\n    }\n    \n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class MotherOfDragons {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int n = scanner.nextInt();\n        double k = scanner.nextInt();\n        long[] graph = new long[n];\n        for(int i = 0; i < n; i++) {\n            for(int j =0; j < n; j++) {\n                int val = scanner.nextInt();\n                if (val == 1 || i == j) graph[i] |= 1L << j;\n            }\n        }\n        //meet in the middle approach\n        int szLeft = n/2;\n        int szRight = n - szLeft;\n        //max size of clique\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n        //iterate over every left mask\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n            //go over every bit in the mask\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    //update the union of reachability\n                    curMask &= graph[j + szRight] >> szRight;\n                    //can also attempt to pull from prev mask for max size\n                    //will not be optimal if end update happens, but otherwise is useful for dp\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            //if the union of connectedness is the starting mask then we have a clique\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            //mask to track if the current creates its own clique\n            int curMask = mask;\n            //mask to track the connection between the halves\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    //need to mask out the left side bits\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    //update corresp avail in the left side\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            //not a clique portion\n            if (curMask != mask) continue;\n            //update answer\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        k/=ans;\n        out.println(k * k * (ans * (ans-1))/2);\n        out.flush();\n    }\n    \n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "/**\n *\n * @author bossbelik\n */\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Main{\n    static long N = 100;\n    static long CNT = 62;\n    static long INF = 1 << 62;\n\n\n    static long parsenum(long j, long l) {\n        String k = \"\";\n        long cur = 0;\n        for (int i = (int) j; i <= l; ++i) {\n            cur *= 10;\n            cur += k.charAt(i) - '0';\n        }\n        return cur;\n    }\n\n    static long gcd(long a, long b) {\n        if (b == 0) {\n            return a;\n        } else {\n            return gcd(b, a % b);\n        }\n    }\n\n    static boolean pri(int k) {\n        if (k == 1) return false;\n        for (int i = 2; i * i <= k; i++) {\n\n            if (k % i == 0) return false;\n        }\n        return true;\n    }\n\n    static int[] calcz(String s) {\n        int l = 0;\n        int r = 0;\n        int n = s.length();\n        int z[] = new int[n];\n        for (int i = 1; i < n; i++) {\n\n            if (i <= r) {\n                z[i] = Math.min(z[i - l], r - i + 1);\n            }\n            while (i + z[i] < n && s.charAt(z[i]) == s.charAt(i + z[i])) z[i]++;\n            if (i + z[i] - 1 > r) {\n                l = i;\n                r = i + z[i] - 1;\n            }\n\n        }\n        return z;\n    }\n\n    static int[] calcpref(String s) {\n        int p[] = new int[s.length() + 1];\n        int n = s.length();\n        p[0] = 0;\n        for (int i = 2; i <= n; i++) {\n            p[i] = p[i - 1];\n            while (p[i] > 0 && s.charAt(p[i]) != s.charAt(i - 1)) p[i] = p[p[i]];\n            if (s.charAt(p[i]) == s.charAt(i - 1)) p[i]++;\n        }\n        return p;\n    }\n    static long MOD =  1000000007;\n\n    static long binpow (long a, long n)\n    {\n        if (n == 0)\n            return 1;\n        if (n % 2 == 1)\n            return binpow (a % MOD, (n-1) % MOD ) * a % MOD;\n        else {\n            long b = binpow(a % MOD, n/2 % MOD) % MOD;\n            return (b * b) % MOD;\n        }\n    }\n\nstatic int maxnum=105;\n  static   int a[][] = new int[maxnum][maxnum];\n  static   boolean used[] = new boolean[maxnum];\n   static int curr , cnt ,n ,m;\n\n static    void dfs(int i)\n    {\n        int j;\n        boolean flag;\n        if(i > n)\n        {\n            cnt = curr;\n            return ;\n        }\n\n        flag=true;\n        for(j = 1 ; j < i; j++)\n        {\n            if (used[j] && a[j][i] == 0)\n            {\n                flag = false;\n                break;\n            }\n        }\n        if(flag)\n        {\n            curr++;\n            used[i]=true;\n            dfs(i+1);\n            curr--;\n        }\n        if(curr + n - i > cnt)\n        {\n            used[i]=false;\n            dfs(i+1);\n        }\n    }\n\n\n\n    public static void main(String[] args) throws  Exception\n    {\n\n//\n        Scanner in = new Scanner(System.in);\n        PrintWriter out = new PrintWriter((System.out));\n        n = in.nextInt();\n        m = in.nextInt();\n\n\n            for(int i = 1 ; i <= n ; i++)\n            {\n                for (int j = 1; j <= n; j++)\n                {\n                    a[i][j] = in.nextInt();\n                }\n            }\n            dfs(1);\n           out.printf( \"%.10f\", (double) m * m * (cnt-1) / (2 * cnt ));\n\n\n        out.println();\n        out.close();\n        return;\n    }\n}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n\n\npublic class ELR {\n\n\tpublic static void main(String[] args) {new Thread(null, new Runnable() { public void run() {try {\n\t\tsol();\n\t} catch (Throwable e) {\n\n\t\te.printStackTrace();\n\t}}}, \"2\",1<<26).start();}\n\n\n\tstatic int n,k;\n\tstatic boolean adj[][];\n\tstatic int dp1[],dp2[];\n\tstatic int myMask[];\n\tstatic int next1[];\n\tstatic int m1,m2;\n\tpublic static int solve1(int msk) {\n\t\tif (dp1[msk] != -1) {\n\t\t\treturn dp1[msk];\n\t\t}\n\t\tint ret = 0;\n\t\tint tmp = msk;\n\t\tfor (int i = 0 ; i < m1 ; ++i) {\n\t\t\tif ( ((msk & (1 << i)) > 0)) {\n\t\t\t\ttmp &= (myMask[i]);\n\t\t\t}\n\t\t}\n\t\tif (tmp == msk) {\n\t\t\tret = Integer.bitCount(msk);\n\t\t}\n\t\tfor (int i = 0 ; i < m1 ; ++i) {\n\t\t\tif ( (msk & (1 << i)) > 0) {\n\t\t\t\tret = Math.max(ret, solve1(msk & ~(1 << i)));\n\t\t\t}\n\t\t}\n\t\treturn dp1[msk] = ret;\n\t}\n\tpublic static int solve2(int msk) {\n\t\tif (dp2[msk] != -1) {\n\t\t\treturn dp2[msk];\n\t\t}\n\t\tint ret = 0;\n\t\tint tmp = msk;\n\t\tfor (int i = 0 ; i < m2 ; ++i) {\n\t\t\tif ( ((msk & (1 << i)) > 0)) {\n\t\t\t\ttmp &= (myMask[i + m1]);\n\t\t\t}\n\t\t}\n\t\tif (tmp == msk) {\n\t\t\tret = Integer.bitCount(msk);\n\t\t}\n\t\tfor (int i = 0 ; i < m2 ; ++i) {\n\t\t\tif ( (msk & (1 << i)) > 0) {\n\t\t\t\tret = Math.max(ret, solve2(msk & ~(1 << i)));\n\t\t\t}\n\t\t}\n\t\treturn dp2[msk] = ret;\n\t}\n\tpublic static void sol() throws Throwable {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tadj = new boolean[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\tadj[i][j] = sc.nextInt() == 1;\n\t\t\t}\n\t\t}\n\n\t\tm1= (n + 1) / 2;\n\t\tm2 = n - m1;\n\t\tdp1 = new int[1 << m1];\n\t\tdp2 = new int[1 << m2];\n\t\tnext1 = new int[1 << m2];\n\t\tArrays.fill(dp1, -1);\n\t\tArrays.fill(dp2, -1);\n\t\tmyMask = new int[n];\n\t\tfor (int i = 0 ; i < n ; ++i) {\n\t\t\tif (i >= m1) {\n\t\t\t\tfor (int j = m1 ; j < n ; ++j) {\n\t\t\t\t\tif (adj[i][j] || i == j) {\n\t\t\t\t\t\tmyMask[i] |= (1 << (j - m1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int j = m1 ; j < n ; ++j) {\n\t\t\t\t\tif (adj[i][j]) {\n\t\t\t\t\t\tnext1[i] |= (1 << (j - m1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int j = 0 ; j < m1 ; ++j) {\n\t\t\t\t\tif (adj[i][j] || i == j) {\n\t\t\t\t\t\tmyMask[i] |= (1 << 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 < (1 << m1) ; ++i) {\n\t\t\tsolve1(i);\n\t\t}\n\t\tfor (int i = 0 ; i < (1 << m2) ; ++i) {\n\t\t\tsolve2(i);\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int msk = 0 ; msk < (1 << m1) ; ++msk) {\n\t\t\tint next = (1 << (m2)) - 1;\n\t\t\tif (dp1[msk] != Integer.bitCount(msk)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int i = 0 ; i < m1 ; ++i) {\n\t\t\t\tif ( (msk & (1 << i)) > 0) {\n\t\t\t\t\tnext &= next1[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tans = Math.max(ans, dp1[msk] + dp2[next]);\n\t\t}\n\t\tdouble cont = (k / (ans*1.0));\n\t\tdouble edges = (ans) * (ans - 1) / 2.0;\n\t\tdouble res = cont * cont * edges;\n\t\tSystem.out.println(res);\n\n\n\t}\n\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(String s) throws FileNotFoundException {\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\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}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\tpublic static class Escanear {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\t\tpublic Escanear() {\n            this(new InputStreamReader(System.in));\n        }\n\t\tpublic Escanear(Reader in) {\n            reader = new BufferedReader(in);\n        }\n        String proximo() {\n            if (tokenizer == null || !tokenizer.hasMoreElements()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return tokenizer.nextToken();\n        }\n        \n        int proximoNum() {\n            return Integer.parseInt(proximo());\n        }\n    }\n    public static void main(String[] args) {\n\t\tEscanear escanear = new Escanear();\n\t\tint proximoInt = escanear.proximoNum();\n        long[] aux = new long[proximoInt];\n        double proximoDouble = escanear.proximoNum();\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = escanear.proximoNum();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t aux[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n        int esquerda = proximoInt/2;\n        int direita = proximoInt - esquerda;\n\t\tint maiorMascara = 1 << esquerda;\n\t\tint[] depois = new int[1 << esquerda];\n\t\tInteger mascara = 1;\n\t\twhile (mascara < maiorMascara) {\n\t\t\tint mascaraAtual = mascara;\n            for(int j = 0; j < esquerda; j++) {\n                if (((1 << j) & mascara) > 0) {\n                    mascaraAtual &= aux[j + direita] >> direita;\n                    depois[mascara] = Math.max(depois[mascara], depois[mascara ^ (1 << j)]);\n                }\n            }\n            if (mascara.equals(mascaraAtual)) {\n                depois[mascara] = Math.max(depois[mascara],Integer.bitCount(mascara));\n\t\t\t}\n\t\t\tmascara++;\n\t\t}\n        // for(int mascara = 1; mascara < maiorMascara; mascara++) {\n        //     int mascaraAtual = mascara;\n\n        //     for(int j = 0; j < esquerda; j++) {\n        //         if (((1 << j) & mascara) > 0) {\n        //             mascaraAtual &= aux[j + direita] >> direita;\n        //             depois[mascara] = Math.max(depois[mascara], depois[mascara ^ (1 << j)]);\n        //         }\n        //     }\n        //     if (mascara == mascaraAtual) {\n        //         depois[mascara] = Math.max(depois[mascara],Integer.bitCount(mascara));\n        //     }\n        // }\n        int auxiliar = 0;\n        int mascaraMaxima = 1 << direita;\n        for(int masc = 0; masc < mascaraMaxima; masc++) {\n            int mascaraCorrente = masc;\n            int mascaraValor = maiorMascara -1;\n            for(int j = 0; j < direita; j++) {\n                if (((1 << j) & masc) > 0) {\n                    mascaraCorrente &= (aux[j] & (mascaraMaxima-1));\n                    mascaraValor &= aux[j] >> direita;\n                }\n            }\n            if (mascaraCorrente != masc) continue;\n            auxiliar = Math.max(auxiliar, Integer.bitCount(masc) + depois[mascaraValor]);\n        }\n        proximoDouble/=auxiliar;\n        saida.println(proximoDouble * proximoDouble * (auxiliar * (auxiliar-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n/*\n * @author Tnascimento \n */\n\npublic class MaeDosDragoes {\n\tpublic static PrintWriter saida = new PrintWriter(System.out, false);\n\tpublic static class Escanear {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\t\tpublic Escanear() {\n            this(new InputStreamReader(System.in));\n        }\n\t\tpublic Escanear(Reader in) {\n            reader = new BufferedReader(in);\n        }\n        String proximo() {\n            while (tokenizer == null || !tokenizer.hasMoreElements()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return tokenizer.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(proximo());\n        }\n\n    }\n\n\n\n    public static void main(String[] args) {\n\t\tEscanear fastScanner = new Escanear();\n        int proximoInt = fastScanner.nextInt();\n        double proximoDouble = fastScanner.nextInt();\n        long[] graph = new long[proximoInt];\n        for(Integer i = 0; i < proximoInt; i++) {\n            for(Integer j =0; j < proximoInt; j++) {\n                Integer val = fastScanner.nextInt();\n                if (val.equals(1) || i.equals(j)) {\n\t\t\t\t graph[i] |= 1L << j;\n\t\t\t\t}\n            }\n        }\n\n        int szLeft = proximoInt/2;\n        int szRight = proximoInt - szLeft;\n\n        int[] dp = new int[1 << szLeft];\n        int maxMask = 1 << szLeft;\n\n        for(int mask = 1; mask <maxMask; mask++) {\n            int curMask = mask;\n\n            for(int j = 0; j < szLeft; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= graph[j + szRight] >> szRight;\n                    dp[mask] = Math.max(dp[mask], dp[mask ^ (1 << j)]);\n                }\n            }\n            if (mask == curMask) {\n                dp[mask] = Math.max(dp[mask],Integer.bitCount(mask));\n            }\n        }\n        int ans = 0;\n        int rmaxMask = 1 << szRight;\n        for(int mask = 0; mask < rmaxMask; mask++) {\n            int curMask = mask;\n            int oMask = maxMask -1;\n            for(int j = 0; j < szRight; j++) {\n                if (((1 << j) & mask) > 0) {\n                    curMask &= (graph[j] & (rmaxMask-1));\n                    oMask &= graph[j] >> szRight;\n                }\n            }\n            if (curMask != mask) continue;\n            ans = Math.max(ans, Integer.bitCount(mask) + dp[oMask]);\n        }\n        proximoDouble/=ans;\n        saida.println(proximoDouble * proximoDouble * (ans * (ans-1))/2);\n        saida.flush();\n    }\n}\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.*;\n\npublic class E {\n\t\n\tstatic InputStream is;\n\t//String INPUT = \"\";\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tis = System.in;\n\t\tint n = ni();\n\t\tint k = ni();\n\t\t\n\t\tint[][] aj = new int[n][n];\n\t\t\n\t\tfor (int i = 0; i < aj.length; i++) {\n\t\t\taj[i] = na(n);\n\t\t}\n\t\t\n\t\tint F = (n+1)/2;\n\t\tint B = n-F;\n\t\t\n\t\tint[] spanftf = new int[F];\n\t\tint[] spanftb = new int[F];\n\t\tfor(int i =0; i < F; i++){\n\t\t\tfor(int j =0; j < F; j++){\n\t\t\t\tif(i == j || aj[i][j] == 1){\n\t\t\t\t\tspanftf[i] |= 1<<j;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j =0; j< B; j++){\n\t\t\t\tif(aj[i][F+j] == 1){\n\t\t\t\t\tspanftb[i] |= 1<<j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] maxes = new int[1<<B];\n\t\tfor(int bm = 0; bm < (1<<F); bm++){\n\t\t\tint anded = (1<<F)-1;\n\t\t\tint spanToBack = (1<<B)-1;\n\t\t\t\n\t\t\tfor(int i =0; i < F; i++){\n\t\t\t\tif((1<<i & bm) != 0){\n\t\t\t\t\tanded &= spanftf[i];\n\t\t\t\t\tspanToBack &= spanftb[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif((anded & bm) == bm){\n\t\t\t\tmaxes[spanToBack] = Math.max(maxes[spanToBack], Integer.bitCount(bm));\n\t\t\t}\n\t\t}\n\t\tint[] spanbtb = new int[B];\n\t\tfor(int i =0; i < B; i++){\n\t\t\tfor(int j =0; j< B; j++){\n\t\t\t\tif(aj[F+i][F+j] == 1 || i == j){\n\t\t\t\t\tspanbtb[i] |= 1<<j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tboolean[] isgood = new boolean[1<<B];\n\t\tfor(int bm =0; bm < (1<<B); bm++){\n\t\t\tint anded = (1<<B)-1;\n\t\t\t\n\t\t\tfor(int i =0; i < B; i++){\n\t\t\t\tif((1<<i & bm) != 0){\n\t\t\t\t\tanded &= spanbtb[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif((anded & bm) == bm){\n\t\t\t\tisgood[bm] = true;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tbybc[] tosort = new bybc[1<<B];\n\t\tfor (int i = 0; i < tosort.length; i++) {\n\t\t\ttosort[i]= new bybc(i);\n\t\t}\n\t\tArrays.sort(tosort);\n\t\t\n\t\tint best = 1;\n\t\tfor (int i = 0; i < tosort.length; i++) {\n\t\t\tint at  =tosort[i].mask;\n\t\t\tif(isgood[at]){\n\t\t\t\tbest = Math.max(best, maxes[at]+Integer.bitCount(at));\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j =0; j < B; j++){\n\t\t\t\tif((1<<j & at) != 0){\n\t\t\t\t\tint to = at - (1<<j);\n\t\t\t\t\tmaxes[to] = Math.max(maxes[to], maxes[at]);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\t//System.out.println(\"best: \" + best);\n\t\t\n\t\tdouble ans= best*(best-1)/2.0 * (k*k/(double)(best*best));\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tstatic class bybc implements Comparable<bybc>{\n\t\tint mask;\n\n\t\tpublic bybc(int mask) {\n\t\t\tsuper();\n\t\t\tthis.mask = mask;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(bybc o) {\n\t\t\treturn Integer.bitCount(o.mask) - Integer.bitCount(mask);\n\t\t}\n\t}\n\t\n\tprivate static byte[] inbuf = new byte[1024];\n\tpublic static int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate static 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 static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate static double nd() { return Double.parseDouble(ns()); }\n\tprivate static char nc() { return (char)skip(); }\n\t\n\tprivate static 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 static 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 static 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 static 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 static 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 static 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\t//private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t//private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "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.Random;\nimport java.io.IOException;\nimport java.io.Reader;\nimport java.io.InputStreamReader;\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 tanzaku\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        MyInput in = new MyInput(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 k;\n        long[] neigibor;\n        Random random = new Random();\n        long maxClique;\n\n        public void solve(int testNumber, MyInput in, PrintWriter out) {\n            n = in.nextInt();\n            k = in.nextInt();\n            neigibor = new long[n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    neigibor[i] |= in.nextLong() << j;\n                }\n            }\n            long maxClique = bronKerbosch();\n            long a = Long.bitCount(maxClique);\n            dump(a);\n            out.printf(\"%.12f\\n\", a * (a - 1.0) / 2 * k / a * k / a);\n        }\n\n        static void dump(Object... o) {\n            System.err.println(Arrays.deepToString(o));\n        }\n\n        long bronKerbosch() {\n            maxClique = 0;\n            bronKerbosch2(0, (1L << n) - 1, 0);\n            return maxClique;\n        }\n\n        void bronKerbosch2(long r, long p, long x) {\n//        if (Long.bitCount(maxClique) >= Long.bitCount(r|p|x)) return;\n            long px = p | x;\n            if (px == 0) {\n                if (Long.bitCount(maxClique) < Long.bitCount(r)) {\n                    maxClique = r;\n                }\n                return;\n            }\n            int cnt = Long.bitCount(px);\n            int choice = random.nextInt(cnt);\n            int u;\n            for (int i = 0; ; i++) {\n                if ((px >>> i & 1) != 0 && choice-- == 0) {\n                    u = i;\n                    break;\n                }\n            }\n//        dump(r, p, x, u, neigibor);\n            long ne = p & ~neigibor[u];\n            for (int v = 0; v < n; v++)\n                if ((ne >>> v & 1) != 0) {\n                    bronKerbosch2(r | 1L << v, p & neigibor[v], x & neigibor[v]);\n                    p &= ~(1L << v);\n                    x |= 1L << v;\n                }\n        }\n\n    }\n\n    static class MyInput {\n        private final BufferedReader in;\n        private static int pos;\n        private static int readLen;\n        private static final char[] buffer = new char[1024 * 8];\n        private static char[] str = new char[500 * 8 * 2];\n        private static boolean[] isDigit = new boolean[256];\n        private static boolean[] isSpace = new boolean[256];\n        private static boolean[] isLineSep = new boolean[256];\n\n        static {\n            for (int i = 0; i < 10; i++) {\n                isDigit['0' + i] = true;\n            }\n            isDigit['-'] = true;\n            isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n            isLineSep['\\r'] = isLineSep['\\n'] = true;\n        }\n\n        public MyInput(InputStream is) {\n            in = new BufferedReader(new InputStreamReader(is));\n        }\n\n        public int read() {\n            if (pos >= readLen) {\n                pos = 0;\n                try {\n                    readLen = in.read(buffer);\n                } catch (IOException e) {\n                    throw new RuntimeException();\n                }\n                if (readLen <= 0) {\n                    throw new MyInput.EndOfFileRuntimeException();\n                }\n            }\n            return buffer[pos++];\n        }\n\n        public int nextInt() {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(len, isSpace);\n            int i = 0;\n            int ret = 0;\n            if (str[0] == '-') {\n                i = 1;\n            }\n            for (; i < len; i++) ret = ret * 10 + str[i] - '0';\n            if (str[0] == '-') {\n                ret = -ret;\n            }\n            return ret;\n        }\n\n        public long nextLong() {\n            int len = 0;\n            str[len++] = nextChar();\n            len = reads(len, isSpace);\n            int i = 0;\n            long ret = 0;\n            if (str[0] == '-') {\n                i = 1;\n            }\n            for (; i < len; i++) ret = ret * 10 + str[i] - '0';\n            if (str[0] == '-') {\n                ret = -ret;\n            }\n            return ret;\n        }\n\n        public char nextChar() {\n            while (true) {\n                final int c = read();\n                if (!isSpace[c]) {\n                    return (char) c;\n                }\n            }\n        }\n\n        int reads(int len, boolean[] accept) {\n            try {\n                while (true) {\n                    final int c = read();\n                    if (accept[c]) {\n                        break;\n                    }\n                    if (str.length == len) {\n                        char[] rep = new char[str.length * 3 / 2];\n                        System.arraycopy(str, 0, rep, 0, str.length);\n                        str = rep;\n                    }\n                    str[len++] = (char) c;\n                }\n            } catch (MyInput.EndOfFileRuntimeException e) {\n            }\n            return len;\n        }\n\n        static class EndOfFileRuntimeException extends RuntimeException {\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "839_E. Mother of Dragons", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\n\npublic class C {\n\n\tstatic int[] nm;\n\tstatic int ans = 0;\n\tstatic int rows, cols;\n\tstatic boolean[][] cae;\n\tstatic int[][] ca;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnm = readIntArray();\n\t\trows = Math.max(nm[0], nm[1]);\n\t\tcols = Math.min(nm[0], nm[1]);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tcae = new boolean[1000][50];\n\t\tca = new int[1000][50];\n\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < cols; i++) {\n\t\t\tsb.append('1');\n\t\t}\n\t\tint startingState = Integer.parseInt(sb.toString(), 3);\n\t\tans = solve(startingState, 0);\n\n\t\tSystem.out.println(nm[0]*nm[1] - ans);\n//\t\tSystem.out.println(System.currentTimeMillis() - s );\n\t}\n\n\tstatic int solve(int state, int row) {\n\t\tif (row == rows) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (cae[state][row]) {\n\t\t\treturn ca[state][row];\n\t\t}\n\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < Math.pow(3, cols); i++) {\n\t\t\tboolean isCover = covers(i, state);\n\t\t\tif (isCover && (row < rows - 1 || coversTotally(i, state))) {\n\t\t\t\tint p = placed(i);\n\t\t\t\tint s = solve(i, row + 1);\n\t\t\t\tans = Math.min(ans, s + p);\n\t\t\t}\n\t\t}\n\n\t\tcae[state][row] = true;\n\t\tca[state][row] = ans;\n\n\t\treturn ans;\n\t}\n\n\tprivate static boolean coversTotally(int i, int state) {\n\t\t\t\n\t\tString bottom = decode(i);\n\t\tfor (int j = 0; j < bottom.length(); j++) {\n\t\t\tif (bottom.charAt(j) == '0') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate static boolean covers(int i, int state) {\n\t\tString top = decode(state);\n\t\tString bottom = decode(i);\n\n\t\tfor (int j = 0; j < top.length(); j++) {\n\t\t\tif (top.charAt(j) == '0' && bottom.charAt(j) != '2') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (top.charAt(j) == '2' && bottom.charAt(j) == '0') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (int j = 0; j < top.length(); j++) {\n\t\t\tif (bottom.charAt(j) == '1' && (top.charAt(j) != '2' && !(j > 0 && bottom.charAt(j-1) == '2') && !(j < top.length() - 1 && bottom.charAt(j+1) == '2'))) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate static int placed(int i) {\n\t\tString s = decode(i);\n\t\tint cnt = 0;\n\t\tfor (int j = 0; j < s.length(); j++) {\n\t\t\tif (s.charAt(j) == '2') {\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\n\t\treturn cnt;\n\t}\n\n\tprivate static String decode(int state) {\t\t\n\t\tString tmp = Integer.toString(state, 3);\n\t\tif (tmp.length() < cols) {\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor (int i = 0; i < cols - tmp.length(); i++) {\n\t\t\t\tsb.append('0');\n\t\t\t}\t\t\n\t\t\tsb.append(tmp);\n\t\t\treturn sb.toString();\n\t\t} else {\n\t\t\treturn tmp;\n\t\t}\t\t\n\t}\n\n\tstatic int countDispositionDivisors(int[] d) {\n\t\tHashSet<Integer> div = new HashSet<Integer>();\n\t\tfor (int i = 1; i <= d.length; i++) {\n\t\t\tfor (int j = 0; j < d.length; j++) {\n\t\t\t\tif ((j + 1) % i == 0 && d[j] % i == 0) {\n\t\t\t\t\tdiv.add(j + 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn div.size();\n\t}\n\n\tstatic InputStreamReader isr = new InputStreamReader(System.in);\n\tstatic BufferedReader br = new BufferedReader(isr);\n\n\tstatic int[] readIntArray() throws IOException {\n\t\tString[] v = br.readLine().split(\" \");\n\t\tint[] ans = new int[v.length];\n\n\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\tans[i] = Integer.valueOf(v[i]);\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\tstatic long[] readLongArray() throws IOException {\n\t\tString[] v = br.readLine().split(\" \");\n\t\tlong[] ans = new long[v.length];\n\n\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\tans[i] = Long.valueOf(v[i]);\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\tstatic <T> void print(List<T> v) {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tfor (int i = 0; i < v.size(); i++) {\n\t\t\tif (sb.length() > 0) {\n\t\t\t\tsb.append(' ');\n\t\t\t}\n\n\t\t\tsb.append(v.get(i));\n\t\t}\n\n\t\tSystem.out.println(sb);\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CodeJ \n{\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\t\n\t\tpublic String nextLine()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn br.readLine();\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tthrow(new RuntimeException());\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic String next()\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t{\n\t\t\t\tString l = nextLine();\n\t\t\t\tif(l == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(l);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong[] res = new long[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic double[] nextDoubleArray(int n)\n\t\t{\n\t\t\tdouble[] res = new double[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\tpublic void sortIntArray(int[] array)\n\t\t{\n\t\t\tInteger[] vals = new Integer[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortLongArray(long[] array)\n\t\t{\n\t\t\tLong[] vals = new Long[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortDoubleArray(double[] array)\n\t\t{\n\t\t\tDouble[] vals = new Double[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t}\n\t\n\tstatic int nFilas;\n\tstatic int nColumnas;\n\n\tstatic byte[][][][][] dp;\n\t\n\tstatic byte dp(int mascaraActual, int enviadosActual, int enviadosSiguiente, int filaActual, int columnaActual)\n\t{\n\t\tif(dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual] != Byte.MAX_VALUE)\n\t\t\treturn dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual];\n\t\tif(filaActual == nFilas)\n\t\t\treturn dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual] = 0;\n\t\tif(columnaActual == nColumnas)\n\t\t{\n\t\t\tint ambos = mascaraActual & enviadosSiguiente;\n\t\t\tint mascaraSiguiente = (1 << nColumnas) - 1;\n\t\t\tmascaraSiguiente ^= ambos;\n\t\t\tint mascaraEnviados = enviadosSiguiente;\n\t\t\tmascaraEnviados ^= ambos;\n\t\t\treturn dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual] = (byte) (nColumnas - Integer.bitCount(mascaraActual) + dp(mascaraSiguiente, mascaraEnviados, 0, filaActual + 1, 0));\n\t\t}\n\t\tif(((mascaraActual & (1 << columnaActual)) == 0))\n\t\t{\n\t\t\t// me envian desde abajo\n\t\t\tbyte a = dp(mascaraActual | (1 << columnaActual), enviadosActual, enviadosSiguiente | (1 << columnaActual), filaActual, columnaActual + 1);\n\t\t\t// normal\n\t\t\tbyte b = dp(mascaraActual, enviadosActual, enviadosSiguiente, filaActual, columnaActual + 1);\n\t\t\treturn dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual] = (byte) Math.max(a, b);\n\t\t}\n\t\tif((enviadosActual & (1 << columnaActual)) != 0)\n\t\t{\n\t\t\tbyte a = dp(mascaraActual, enviadosActual, enviadosSiguiente | (1 << columnaActual), filaActual, columnaActual + 1);\n\t\t\tbyte b = dp(mascaraActual, enviadosActual, enviadosSiguiente, filaActual, columnaActual + 1);\n\t\t\treturn dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual] = (byte) Math.max(a, b);\n\t\t}\n\t\t// izquierda\n\t\tbyte ans = 0;\n\t\tif(columnaActual != 0)\n\t\t\tans = (byte) Math.max(ans, dp((mascaraActual ^ (1 << columnaActual)) | (1 << (columnaActual - 1)), enviadosActual, enviadosSiguiente, filaActual, columnaActual + 1));\n\t\t// derecha\n\t\tif(columnaActual != nColumnas - 1)\t\n\t\t\tans = (byte) Math.max(ans, dp((mascaraActual ^ (1 << columnaActual)) | (1 << (columnaActual + 1)), enviadosActual | (1 << (columnaActual + 1)), enviadosSiguiente, filaActual, columnaActual + 1));\n\t\t// abajo\n\t\tif(filaActual != nFilas - 1)\n\t\t\tans = (byte) Math.max(ans, dp((mascaraActual ^ (1 << columnaActual)), enviadosActual, enviadosSiguiente | (1 << columnaActual), filaActual, columnaActual + 1));\n\t\t// quieto\n\t\tans = (byte) Math.max(ans, dp(mascaraActual, enviadosActual, enviadosSiguiente, filaActual, columnaActual + 1));\n\t\treturn dp[mascaraActual][enviadosActual][enviadosSiguiente][filaActual][columnaActual] = ans;\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner();\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tnFilas = Math.max(a, b);\n\t\tnColumnas = Math.min(a, b);\n\t\tdp = new byte[1 << nColumnas][1 << nColumnas][1 << nColumnas][nFilas + 1][nColumnas + 1];\n\t\tfor(byte[][][][] i : dp)\n\t\t\tfor(byte[][][] j : i)\n\t\t\t\tfor(byte[][] k : j)\n\t\t\t\t\tfor(byte[] l : k)\n\t\t\t\t\t\tArrays.fill(l, Byte.MAX_VALUE);\n\t\tSystem.out.println(dp((1 << nColumnas) - 1, 0, 0, 0, 0));\n\t}\n}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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\n// Petya and Spiders\n// 2012/08/16\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\n\t\tlong s=covered;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\ts|=(1L<<i)|g[i];\n\t\t}\n\t\tif(s!=((1L<<n)-1))\n\t\t\treturn;\n\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>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<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\n// Petya and Spiders\n// 2011/9/3\npublic class P111C{\n\tScanner sc=new Scanner(System.in);\n\n\tint INF=1<<28;\n\n\tint n, m;\n\n\tvoid run(){\n\t\tn=sc.nextInt();\n\t\tm=sc.nextInt();\n\t\tsolve();\n\t}\n\n\tvoid solve(){\n\t\tif(n<m){\n\t\t\tint t=n;\n\t\t\tn=m;\n\t\t\tm=t;\n\t\t}\n\t\tint full=(1<<m)-1;\n\t\tint[][] dp=new int[1<<m][1<<m];\n\t\tint[][] tmp=new int[1<<m][1<<m];\n\t\tfor(int i=0; i<1<<m; i++){\n\t\t\tfill(dp[i], INF);\n\t\t}\n\t\tfor(int i=0; i<1<<m; i++){\n\t\t\tint b1=(i|(i>>1)|(i<<1))&full;\n\t\t\tint b2=i;\n\t\t\tdp[b1][b2]=Integer.bitCount(i);\n\t\t}\n\t\tfor(int j=0; j<n-1; j++){\n\t\t\tfor(int i=0; i<1<<m; i++){\n\t\t\t\tSystem.arraycopy(dp[i], 0, tmp[i], 0, 1<<m);\n\t\t\t\tfill(dp[i], INF);\n\t\t\t}\n\n\t\t\tfor(int b1=0; b1<1<<m; b1++){\n\t\t\t\tfor(int b2=0; b2<1<<m; b2++){\n\t\t\t\t\tfor(int i=0; i<1<<m; i++){\n\t\t\t\t\t\tif((b1|i)!=full){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint b=(i|(i>>1)|(i<<1))&full;\n\t\t\t\t\t\tdp[b2|b][i]=min(dp[b2|b][i],\n\t\t\t\t\t\t\t\ttmp[b1][b2]+Integer.bitCount(i));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint min=INF;\n\t\tfor(int i=0; i<1<<m; i++){\n\t\t\tmin=min(min, dp[full][i]);\n\t\t}\n\t\tint ans=m*n-min;\n\t\tprintln(ans+\"\");\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tpublic static void main(String[] args){\n\t\tnew P111C().run();\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n\tstatic final boolean _DEBUG = false;\n\n\tprivate static class MyScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic MyScanner(BufferedReader _br) {\n\t\t\tbr = _br;\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 (Exception e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t\treturn \"\";\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\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}\n\n\tstatic MyScanner   scan;\n\tstatic PrintWriter out;\n\n\tstatic int debugCount = 0;\n\tstatic void debug(String msg) {\n\t\tif (_DEBUG && debugCount < 200) {\n\t\t\tout.println(msg);\n\t\t\tout.flush();\n\t\t\tdebugCount++;\n\t\t}\n\t}\n\t\n    public static void main (String args[]) throws IOException {\n//    \tscan = new MyScanner(new BufferedReader(new FileReader(\"test.in\")));\n    \tscan = new MyScanner(new BufferedReader(new InputStreamReader(System.in)));\n    \tout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        Main inst = new Main();\n        inst.execute();\n        out.close();\n    }\n    \n    int N, M, pow;\n    int[] counts;\n    int[][][] dp;\n    \n    void execute() {\n    \tN = scan.nextInt();\n    \tM = scan.nextInt();\n    \tif (N < M) {\n    \t\tint temp = N;\n    \t\tN = M;\n    \t\tM = temp;\n    \t}\n    \tpow = 1<<M;\n    \tcounts = new int[pow];\n    \tdp = new int[N][pow][pow];\n    \tfor (int[][] i : dp) {\n    \t\tfor (int[] j : i) {\n    \t\t\tArrays.fill(j, -1);\n    \t\t}\n    \t}\n    \tfor (int i = 0; i < pow; i++) {\n    \t\tcounts[i] = Integer.bitCount(i);\n        \tdp[0][i][0] = counts[i];\n    \t}\n    \tint spiders = Integer.MAX_VALUE;\n    \tfor (int y = 0; y < N-1; y++) {\n    \t\tfor (int i = 0; i < pow; i++) {\n    \t\t\tfor (int j = 0; j < pow; j++) {\n    \t\t\t\tif (dp[y][i][j] == -1) {\n    \t\t\t\t\tcontinue;\n    \t\t\t\t}\n    \t\t\t\tfor (int k = 0; k < pow; k++) {\n    \t\t\t\t\tif (((i|(i<<1)|(i>>1)|j|k)&(pow-1))==(pow-1)) {\n    \t\t\t\t\t\tint value = dp[y][i][j] + counts[k];\n    \t\t\t\t\t\tif (dp[y+1][k][i] == -1 || dp[y+1][k][i] > value) {\n    \t\t\t\t\t\t\tdp[y+1][k][i] = value;\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//    \tfor (int i = 0; i < N; i++) {\n//        \tSystem.out.println(Arrays.deepToString(dp[i]));\n//    \t}\n    \tfor (int i = 0; i < pow; i++) {\n    \t\tfor (int j = 0; j < pow; j++) {\n    \t\t\tif (dp[N-1][i][j] != -1 && ((i|(i<<1)|(i>>1)|j)&(pow-1))==(pow-1)) {\n    \t\t\t\tspiders = Math.min(spiders, dp[N-1][i][j]);\n//    \t\t\t\tSystem.out.println(spiders+\" \"+i+\" \"+j);\n    \t\t\t}\n    \t\t}\n    \t}\n    \tout.println((N*M)-spiders);\n    }\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class cf112e {\n    static int n,m,s;\n    static int[][][] memo;\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        n = in.nextInt();\n        m = in.nextInt();\n        if(n > m) {\n            int tmp = n;\n            n = m;\n            m = tmp;\n        }\n        s = (1<<n);\n        memo = new int[s][s][m];\n        for(int i=0; i<s; i++)\n            for(int j=0; j<s; j++)\n                Arrays.fill(memo[i][j], -1);\n        int ret = go(0,0,0);\n        System.out.println(n*m - ret);\n    }\n    static int go(int last, int trans, int r) {\n        if(r==m) {\n            if(trans == 0) return 0;\n            return 100;\n        }\n        if(memo[last][trans][r] != -1) return memo[last][trans][r];\n        int best = 100;\n        for(int crnt = 0; crnt < s; crnt++) {\n            if((trans & ~crnt) != 0) continue; //certain ones have to be here\n            for(int pass = 0; pass < s; pass++) {\n                int tmp = ((1<<n)-1) & ~last;   //move back the ones you can\n                if((pass & ~tmp) != 0) continue; //certain ones have to move on\n                tmp = tmp & ~pass; //find which ones stay\n                boolean fail = false;\n                for(int k=0; k<n; k++) //make sure that the ones that stay\n                    if(isSet(tmp,k) && !(isSet(crnt,k-1) || isSet(crnt,k) || isSet(crnt,k+1)))\n                        fail = true;\n                if(fail) continue;\n                best = Math.min(best, Integer.bitCount(crnt) + go(crnt,pass,r+1));\n            }\n        }\n        return memo[last][trans][r] = best;\n    }\n    static boolean isSet(int x, int p) {\n        if(p < 0 || p >= n) return false;\n        return (x & (1<<p)) != 0;\n    }\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 9/3/11\n * Time: 5:28 PM\n */\npublic class CF85E {\n    public static void main(String[] args) {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n\n        int height = nextInt(), width = nextInt();\n        if (width > height) {\n            int t = width;\n            width = height;\n            height = t;\n        }\n\n        final int INF = height * width + 10;\n        int[][][] dp = new int[height + 1][1 << width][1 << width];\n        for (int[][] ints : dp) {\n            for (int[] anInt : ints) {\n                Arrays.fill(anInt, INF);\n            }\n        }\n\n        dp[0][0][0] = 0;\n        for(int r = 0; r < height; ++r) {\n            for(int uncovered = 0; uncovered < (1 << width); ++uncovered) {\n                for(int mask = 0; mask < (1 << width); ++mask) {\n                    if (dp[r][uncovered][mask] == INF) {\n                        continue;\n                    }\n                    for(int curMask = uncovered; curMask < (1 << width); curMask = (curMask + 1) | uncovered) {\n                        int curUncovered = (1 << width) - 1;\n                        for(int i = 0; i < width; ++i) {\n                            if (hasBit(mask, i) || hasBit(curMask, i)) {\n                                curUncovered &= ~(1 << i);\n                            }\n                            if (i > 0 && hasBit(curMask, i-1)) {\n                                curUncovered &= ~(1 << i);\n                            }\n                            if (i < width-1 && hasBit(curMask, i+1)) {\n                                curUncovered &= ~(1 << i);\n                            }\n                        }\n                        dp[r+1][curUncovered][curMask] = Math.min(dp[r+1][curUncovered][curMask], dp[r][uncovered][mask] + Integer.bitCount(curMask));\n                    }\n                }\n            }\n        }\n\n        int res = INF;\n        for(int x: dp[height][0]) res = Math.min(res, x);\n\n        System.out.println(height * width - res);\n    }\n\n    private static boolean hasBit(int mask, int bit) {\n        return (((mask >> bit) & 1) == 1);\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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 (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\tint n, m;\n\tint dp[][][];\n\tint MV = Integer.MAX_VALUE >> 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][M];\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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "/*************************************************************************\n    > File Name: cf111c.java\n    > Author: Yuchen Wang\n    > Mail: wyc8094@gmail.com \n    > Created Time: Sat Feb 11 16:51:01 2017\n ************************************************************************/\n\nimport java.util.*;\nimport java.io.*;\n\npublic class cf111c\n{\n\tpublic static int n,m,maxm;\n\tpublic static int[][][] dp;\n\tpublic static int[] s;\n\n\n\tpublic static int cal(int cur)\n\t{\n\t\tint res = 0;\n\t\twhile(cur>0){\n\t\t\tres ++;\n\t\t\tcur = cur&(cur-1);\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static boolean check(int a,int b,int c)\n\t{\n\t\tint res = (maxm-1) & (b | (b<<1) | (b>>1) | a | c);\n\t\tif(res == maxm-1)return true;\n\t\telse return false;\n\t}\n\n\tpublic static void main(String[] argv)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tif(n<m){\n\t\t\tint t = m;\n\t\t\tm = n;\n\t\t\tn = t;\n\t\t}\n\n\t\tmaxm = 1<<m;\n\t\tint i,j,k,l;\n\t\tdp = new int[n+1][1<<m][1<<m];\n\t\ts = new int[1<<m];\n\n\t\tfor(i=0;i<n+1;i++){\n\t\t\tfor(j=0;j<maxm;j++){\n\t\t\t\tArrays.fill(dp[i][j],100);\n\t\t\t}\n\t\t}\n\n\t\tfor(i=0;i<maxm;i++){\n\t\t\ts[i] = cal(i);\n\t\t\tdp[0][0][i] = 0;\n\t\t}\n\n\t\tfor(i=1;i<=n;i++){\n\t\t\tfor(j=0;j<maxm;j++){\n\t\t\t\tfor(k=0;k<maxm;k++){\n\t\t\t\t\tfor(l=0;l<maxm;l++){\n\t\t\t\t\t\tif(dp[i-1][k][l]!=100 && check(k,l,j)){\n\t\t\t\t\t\t\tdp[i][l][j] = Math.min(dp[i-1][k][l]+s[l],dp[i][l][j]);\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 ans = 100;\n\t\tfor(i=0;i<maxm;i++)\n\t\t\tans = Math.min(dp[n][i][0],ans);\n\n\t\tSystem.out.println(n*m-ans);\n\t\treturn;\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/26/11\n * Time: 10:53 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskC {\n\n    final  int INF = 123456;\n    int[][][] memo;\n    int N, M;\n\n    int solve(int row, int prevFreeMask, int curStayMask) {\n        if(row == N) return (curStayMask == 0) ? 0 : -INF;\n        if(memo[row][prevFreeMask][curStayMask] != -1) return memo[row][prevFreeMask][curStayMask];\n\n        int res = 0;\n        for(int mask = 0; mask < (1<<M); mask++) {\n            if((mask & curStayMask) == curStayMask) {\n                int freeCellsMask = (1<<M) - 1 - mask;\n                int toMoveMask = freeCellsMask;\n\n                for(int i = 0; i < M; i++) {\n                    if((toMoveMask & (1<<i)) > 0) {\n                        if(i > 0) {\n                            if((mask & (1<<(i - 1))) > 0) {\n                                toMoveMask -= (1<<i);\n                                continue;\n                            }\n                        }\n\n                        if(i < M - 1) {\n                            if((mask & (1<<(i + 1))) > 0) {\n                                toMoveMask -= (1<<i);\n                                continue;\n                            }\n                        }\n                    }\n                }\n\n                if (row > 0) {\n                    for (int prevFillMask = toMoveMask; prevFillMask > 0; prevFillMask = (prevFillMask - 1) & toMoveMask) {\n                        int bc1 = Integer.bitCount(freeCellsMask);\n                        int bc2 = Integer.bitCount(prevFreeMask & prevFillMask);\n                        res = Math.max(res, bc1 - bc2 + solve(row + 1, freeCellsMask, toMoveMask ^ prevFillMask));\n                    }\n                }\n\n                res = Math.max(res, Integer.bitCount(freeCellsMask) + solve(row + 1, freeCellsMask, toMoveMask));\n            }\n        }\n\n        return memo[row][prevFreeMask][curStayMask] = res;\n    }\n\n    void run() {\n        N = nextInt();\n        M = nextInt();\n        if(M > N) {\n            int temp = M;\n            M = N;\n            N = temp;\n        }\n\n        this.memo = new int[N + 1][1<<M][1<<M];\n        for(int[][] g : memo) for(int[] f : g) Arrays.fill(f, -1);\n\n        System.out.println(solve(0, 0, 0));\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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.util.Iterator;\nimport java.io.*;\nimport java.util.Comparator;\nimport java.util.Arrays;\nimport java.util.Collection;\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 TaskC();\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 ArrayUtils {\n\n\tpublic static void fill(int[][] array, int value) {\n\t\tfor (int[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(int[][][] array, int value) {\n\t\tfor (int[][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\t}\n\nclass TaskC implements Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint rowCount = in.readInt();\n\t\tint columnCount = in.readInt();\n\t\tout.println(rowCount * columnCount - go(Math.min(rowCount, columnCount), Math.max(rowCount, columnCount)));\n\t}\n\n\tprivate int go(int rowCount, int columnCount) {\n\t\tint[][][] result = new int[columnCount][rowCount][1 << (2 * rowCount)];\n\t\tArrayUtils.fill(result, -1);\n\t\treturn go(0, 0, (1 << rowCount) - 1, result);\n\t}\n\n\tprivate int go(int column, int row, int mask, int[][][] result) {\n\t\tif (column == result.length)\n\t\t\treturn (mask == 0 ? 0 : Integer.MAX_VALUE / 2);\n\t\tint length = result[column].length;\n\t\tif (row == length)\n\t\t\treturn go(column + 1, 0, mask, result);\n\t\tif (result[column][row][mask] != -1)\n\t\t\treturn result[column][row][mask];\n\t\tresult[column][row][mask] = Integer.MAX_VALUE / 2;\n\t\tif ((mask >> (2 * length - 1) & 1) == 0)\n\t\t\tresult[column][row][mask] = go(column, row + 1, mask * 2 + (column == result.length - 1 ? 0 : 1), result);\n\t\tint newMask = mask;\n\t\tnewMask &= ~(1 << (length - 1));\n\t\tif (row != 0)\n\t\t\tnewMask &= ~(1 << length);\n\t\tif (row != length - 1)\n\t\t\tnewMask &= ~(1 << (length - 2));\n\t\tnewMask *= 2;\n\t\tnewMask &= (1 << (2 * length)) - 1;\n\t\treturn result[column][row][mask] = Math.min(result[column][row][mask], 1 + go(column, row + 1, newMask, result));\n\t}\n}\n\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 C implements Runnable\n{\n    String file = \"input\";\n    \n    boolean TEST = false;\n    \n    void solve() throws IOException\n    {\n        rows = nextInt();\n        cols = nextInt();\n        if(cols > rows)\n        {\n            int t = rows; rows = cols; cols = t;\n        }\n        dp = new int[rows][cols][1 << cols][1 << cols][1 << cols];      \n        for(int i = 0; i < rows; i++)\n            for(int j = 0; j < cols; j++)\n                for(int k = 0; k < 1 << cols; k++)\n                    for(int u = 0; u < 1 << cols; u++)\n                        for(int v = 0; v < 1 << cols; v++) dp[i][j][k][u][v] = -1;  \n        out.println(go(0, 0, 0, 0, 0));\n    }\n    int rows, cols;\n    int[][][][][] dp;\n    int INF = 1 << 20;\n    int go(int i, int j, int a, int b, int c)\n    {   \n        if(i == rows)\n        {\n            return a == 0 && b == 0 && c == 0 ? 0 : -INF;\n        }\n        if(i + 1 == rows && b != 0 && c != 0) return -INF;\n        if(i + 2 == rows && c != 0) return -INF;\n        if(j == cols)\n        {\n            return go(i + 1, 0, b, c, 0);\n        }\n        \n        if(dp[i][j][a][b][c] != -1) return dp[i][j][a][b][c];\n        \n        if(!test(a, j, -1, -1)) return go(i, j + 1, a, b, c);\n        \n        int res = -INF;\n        \n        //1\n        if(test(a, j, -1, -1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), b, c));\n        //2\n        if(test(a, j, -1, -1) && test(b, j, -1, -1)) \n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j, -1, -1), c) + 1);\n        //3\n        if(j + 2 <= cols && test(a, j, j + 1, -1)) \n            res = max(res, go(i, j + 2, set(a, j, j + 1, -1), b, c) + 1);\n        //4\n        if(j + 3 <= cols && test(a, j, j + 1, j + 2)) \n            res = max(res, go(i, j + 2, set(a, j, j + 1, j + 2), b, c) + 2);\n        //5\n        if(test(a, j, -1, -1) && test(b, j, -1, -1) && test(c, j, -1, -1)) \n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j, -1, -1), set(c, j, -1, -1)) + 2);\n        //6\n        if(j - 1 >= 0 && test(a, j, -1, -1) && test(b, j - 1, j, -1) && test(c, j, -1, -1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j - 1, j, -1), set(c, j, -1, -1)) + 3);\n        //7\n        if(j + 2 <= cols && test(a, j, -1, -1) && test(b, j, j + 1, -1) && test(c, j, -1, -1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j, j + 1, -1), set(c, j, -1, -1)) + 3);\n        //8\n        if(j + 3 <= cols && test(a, j, j + 1, j + 2) && test(b, j + 1, -1, -1)) \n            res = max(res, go(i, j + 3, set(a, j, j + 1, j + 2), set(b, j + 1, -1, -1), c) + 3);\n        //9\n        if(j + 2 <= cols && j - 1 >= 0 && test(b, j - 1, j, j + 1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j - 1, j, j + 1), c) + 3);\n        //10\n        if(j + 2 <= cols && j - 1 >= 0 && test(b, j - 1, j, j + 1) && test(c, j, -1, -1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j - 1, j, j + 1), set(c, j, -1, -1)) + 4);\n            \n        //11\n        if(j + 2 <= cols && test(b, j, j + 1, -1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j, j + 1, -1), c) + 2);\n        \n        //12\n        if(j - 1 >= 0 && test(b, j - 1, j, -1))\n            res = max(res, go(i, j + 1, set(a, j, -1, -1), set(b, j - 1, j, -1), c) + 2);\n        \n        //13\n        if(j + 2 <= cols && test(a, j, j + 1, -1) && test(b, j, -1, -1))\n            res = max(res, go(i, j + 2, set(a, j, j + 1, -1), set(b, j, -1, -1), c) + 2);\n        \n        //14\n        if(j + 2 <= cols && test(a, j, j + 1, -1) && test(b, j + 1, -1, -1))\n            res = max(res, go(i, j + 2, set(a, j, j + 1, -1), set(b, j + 1, -1, -1), c) + 2);\n        \n        return dp[i][j][a][b][c] = res; \n    }\n    int set(int a, int i, int j, int k)\n    {\n        if(i != -1) a |= 1 << i;\n        if(j != -1) a |= 1 << j;\n        if(k != -1) a |= 1 << k;\n        return a;\n    }\n    boolean test(int a, int i, int j, int k)\n    {\n        if(i != -1 && (a >> i & 1) != 0) return false;\n        if(j != -1 && (a >> j & 1) != 0) return false;\n        if(k != -1 && (a >> k & 1) != 0) return false;\n        return true;\n    }\n    \n    String next() throws IOException\n    {\n        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n        return st.nextToken();\n    }\n    \n    int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n    \n    long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n    \n    double nextDouble() throws IOException\n    {\n        return Double.parseDouble(next());\n    }\n    \n    void print(Object... o)\n    {\n        System.out.println(deepToString(o));\n    }\n    \n    void gcj(Object o)\n    {\n        String s = String.valueOf(o);\n        out.println(\"Case #\" + test + \": \" + s);\n        System.out.println(\"Case #\" + test + \": \" + s);\n    }\n    \n    BufferedReader input;\n    PrintWriter out;\n    StringTokenizer st;\n    int test;\n    \n    void init() throws IOException\n    {\n        if(TEST) input = new BufferedReader(new FileReader(file + \".in\")); \n        else input = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n    }\n    \n    public static void main(String[] args) throws IOException\n    {\n        new Thread(null, new C(), \"\", 1 << 20).start();\n    }\n    \n    public void run()\n    {\n        try\n        {\n            init();\n            if(TEST) \n            {\n                int runs = nextInt();\n                for(int i = 0; i < runs; i++) solve();\n            }\n            else solve();\n            out.close();        \n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 n = nextInt();\n    \tint m = nextInt();\n    \tif (n > m) {\n    \t\tint sw = n;\n    \t\tn = m;\n    \t\tm = sw;\n    \t}\n    \tint[][] A = new int[1<<n][1<<n];\n    \tfor (int m1 = 0; m1 < 1<<n; ++m1) { // Who goes out\n    \t\tfor (int m2 = 0; m2 < 1<<n; ++m2) {  // Who comes\n    \t\t\tint[] arr = new int[n]; // Who remains\n    \t\t\tfor (int i = 0; i < n; ++i) {\n    \t\t\t\tarr[i] = (~(m1>>i))&1; \n    \t\t\t}\n    \t\t\tint[] m2a = new int[n];\n    \t\t\tfor (int i = 0; i < n; ++i) {\n    \t\t\t\tm2a[i] = (m2>>i)&1; \n    \t\t\t}\n    \t\t\tint cnt = 0;\n    \t\t\tfor (int i = 0; i < n; ++i) {\n    \t\t\t\tif (arr[i] == 1) {\n    \t\t\t\t\tif (i > 0 && m2a[i-1] == 1) {\n    \t\t\t\t\t\tcontinue;\n    \t\t\t\t\t}\n    \t\t\t\t\tif (i < n-1 && m2a[i+1] == 1) {\n    \t\t\t\t\t\tcontinue;\n    \t\t\t\t\t}\n    \t\t\t\t\tif (m2a[i] == 1) {\n    \t\t\t\t\t\tcontinue;\n    \t\t\t\t\t}\n    \t\t\t\t\tif (i < n-1) {\n    \t\t\t\t\t\tm2a[i+1] = 1;\n    \t\t\t\t\t} else {\n    \t\t\t\t\t\tm2a[i] = 1;\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\tif (m2a[i] == 1) {\n    \t\t\t\t\tcnt++;\n    \t\t\t\t}\n    \t\t\t}\n    \t\t\tA[m1][m2] = cnt;\n    \t\t}\n    \t}\n    \tint MAX = 10000;\n    \tint[][][] dp = new int[m+1][1<<n][1<<n];\n    \tfor (int i = 0; i < m+1; i++) {\n    \t\tfor (int m1 = 0; m1 < 1<<n; ++m1) {\n    \t\t\tArrays.fill(dp[i][m1], MAX);\n    \t\t}\n    \t}\n    \t\n\t\tdp[0][0][0] = 0;\n    \t\n    \tfor (int i = 0; i < m; i++) {\n    \t\tfor (int m1 = 0; m1 < 1<<n; ++m1) {\n    \t\t\tfor (int m2 = 0; m2 < 1<<n; ++m2) {\n    \t\t\t\tif (dp[i][m1][m2] != MAX) {\n\t    \t\t\t\tfor (int nm1 = 0; nm1 < 1<<n; ++nm1) {\n\t    \t    \t\t\tfor (int nm2 = 0; nm2 < 1<<n; ++nm2) {\n\t    \t        \t\t\tif ((m1 & nm1) == 0) {\n\t    \t        \t\t\t\tint sm1 = m1|nm1;\n\t    \t        \t\t\t\tint sm2 = m2|nm2;\n\t    \t        \t\t\t\tint cnt = A[sm1][sm2];\n\t    \t        \t\t\t\tdp[i+1][nm2][nm1] = Math.min(dp[i+1][nm2][nm1], dp[i][m1][m2]+cnt);\n\t    \t        \t\t\t}\n\t    \t        \t\t}\n\t    \t    \t\t}\n    \t\t\t\t}\n        \t\t}\n    \t\t}\n    \t}\n    \t\n    \tout.println(n*m-dp[m][0][0]);\n    \tout.flush();\n    }\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n    static int[][][] dp; \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<<n) -1, n, m);\n        \n        System.out.println(n * m - min);\n    }\n    private static int go(int rem, int prev, int need, int n, int m) {\n//      for(int i = rem; i < m; i++)\n//          System.out.print(\" \");\n//      System.out.println(rem + \": \" + prev +\",\"+need);\n        if(rem == 0)return prev == 0?0:1 << 20;\n        if(dp[rem][prev][need] != -1)return dp[rem][prev][need];\n        \n        int min = 1 << 20;\n        for(int now = 0; now < 1 << n; now++){\n            if((~now & prev) != 0)continue;\n            \n            int after = need & ~(now) & ~(now << 1) & ~(now >> 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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "//package round85;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C3 {\n\tScanner in;\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\tif(n < m){\n\t\t\tint d = n;n = m;m = d;\n\t\t}\n\t\t// n>=m\n\t\tif(m == 1){\n\t\t\tout.println(n-(n+2)/3);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint[][] dp = new int[n+1][1<<2*m];\n\t\tint[] fill = new int[1<<m];\n\t\tint mask = (1<<m)-1;\n\t\tfor(int i = 0;i < 1<<m;i++){\n\t\t\tfill[i] = (i<<1|i|i>>1)&mask;\n\t\t}\n\t\tfor(int i = 0;i < 1<<2*m;i++){\n\t\t\tint lower = i&mask;\n\t\t\tint upper = i>>m;\n\t\t\tdp[0][i] = (fill[lower]|upper) == mask ? Integer.bitCount(i) : 99999;\n\t\t}\n\t\t\n\t\tfor(int i = 1;i <= n-2;i++){\n\t\t\tfor(int j = 0;j < 1<<2*m;j++){\n\t\t\t\tint lower = j&mask;\n\t\t\t\tint upper = j>>m;\n\t\t\t\t\n\t\t\t\tint min = 99999;\n\t\t\t\tfor(int k = 0;k < 1<<m;k++){\n\t\t\t\t\tif((upper|fill[lower]|k) == mask){\n\t\t\t\t\t\tmin = Math.min(min, dp[i-1][lower<<m|k]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdp[i][j] = min + Integer.bitCount(upper);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint gmin = 99999;\n\t\tfor(int i = 0;i < 1<<2*m;i++){\n\t\t\tint lower = i&mask;\n\t\t\tint upper = i>>m;\n\t\t\tif((fill[upper]|lower) == mask){\n\t\t\t\tgmin = Math.min(gmin, dp[n-2][i]);\n\t\t\t}\n\t\t}\n\t\tout.println(n*m-gmin);\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 C3().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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "\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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "/**\n * Problem: \n * Source: \n * Link: \n * \n * @author Alexei Ostrovski\n */\n\nimport java.io.*;\nimport java.util.*;\n\n\npublic class SpidersSolver {\n\n\tpublic static final boolean DEBUG = false;\n\t\n\tpublic static void main(String[] args) {\n\t\t//redirect input and output\n\t\tif (DEBUG)\n\t\t{\n\t\t\ttry {\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t\t//System.setOut(new PrintStream(\"input.txt\"));\n\t\t\t} catch (IOException e) {\n\t\t\t\t//nothing\n\t\t\t}\n\t\t}\n\t\tScanner sc = new Scanner(System.in);\n\n\t\t//read data\n\t\tint n = sc.nextInt(), m = sc.nextInt();\n\t\t\t\n\t\t//solve\n\t\tif (n < m) {\n\t\t\tint tmp = n;\n\t\t\tn = m;\n\t\t\tm = tmp;\n\t\t}\n\t\t// Now (n >= m) && (m <= 6)\n\t\tint pow = 1;\n\t\tfor (int i = 0; i < m; i++)\n\t\t\tpow *= 2;\n\n\t\tint[] count = new int[pow];\n\t\tfor (int cur = 0; cur < pow; cur++)\n\t\t{\n\t\t\tint x = cur;\n\t\t\twhile (x > 0)\n\t\t\t{\n\t\t\t\tcount[cur] += (x % 2);\n\t\t\t\tx /= 2;\n\t\t\t}\n\t\t\tcount[cur] = m - count[cur];\n\t\t}\n\t\t//System.out.println(Arrays.toString(count));\n\t\t\n\t\tint[][] C = new int[pow][pow];\n\t\tfor (int cur = 0; cur < pow; cur++)\n\t\t{\n\t\t\tC[0][cur] = 0;//count[cur];\n\t\t\tfor (int last = 1; last < pow; last++)\n\t\t\t\tC[last][cur] = Integer.MIN_VALUE;\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tint[][] newC = new int[pow][pow];\n\t\t\t\n\t\t\tfor (int cur = 0; cur < pow; cur++)\n\t\t\t\tfor (int next = 0; next < pow; next++)\n\t\t\t\t{\n\t\t\t\t\tint mask = cur | (cur << 1) | (cur >> 1) | next;\n\t\t\t\t\tmask %= pow;\n\t\t\t\t\t\n\t\t\t\t\tint max = 0;\n\t\t\t\t\tfor (int last = 0; last < pow; last++)\n\t\t\t\t\t\tif (((last | mask) == pow - 1) && (max < count[cur] + C[last][cur]))\n\t\t\t\t\t\t\tmax = count[cur] + C[last][cur];\n\t\t\t\t\t\n\t\t\t\t\tnewC[cur][next] = max;\n\t\t\t\t}\n\t\t\tC = newC;\n\t\t}\n\t\t\n\t\tint result = 0;\n\t\tfor (int cur = 0; cur < pow; cur++)\n\t\t\tresult = Math.max(result, C[cur][0]);\n\t\t\t\n\t\t//output\n\t\tSystem.out.println(result);\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "\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.Collections;\nimport java.util.Map.Entry;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\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    public static long MOD = 1000000007;\n    public static int[][][] dp;\n    public static int min, max, need;\n\n    public static void main(String[] args) {\n\n        Scanner in = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n = in.nextInt();\n        int m = in.nextInt();\n        min = Math.min(n, m);\n        max = (m + n) - min;\n        dp = new int[max][1 << min][1 << min];\n\n        for (int[][] temp : dp) {\n            for (int[] val : temp) {\n                Arrays.fill(val, -1);\n            }\n        }\n        need = (1 << min) - 1;\n        //System.out.println(add + total);\n        //  System.out.println(min + \" \" + max);\n\n        out.println(cal(0, 0, 0));\n\n        out.close();\n\n    }\n\n    public static int cal(int index, int last, int lastHold) {\n\n        if (index == max) {\n            return 0;\n        }\n        if (dp[index][lastHold][last] != -1) {\n            return dp[index][lastHold][last];\n        }\n        int result = 0;\n\n        for (int i = 0; i < 1 << min; i++) {\n            if ((i | last) == need || (index == 0)) {\n              //  System.out.println(\"PREV \" + index + \" \" + i + \" \" + last + \" \" + lastHold);\n              //  System.out.println(\"NEXT \" + index + \" \" + i + \" \" + (i | lastHold) + \" \" + i);\n                //   System.out.println(Integer.bitCount(i) + \" \" + i);\n\n//                if (index == 3) {\n//                    System.out.println(last + \" \" + i + \" \" + match(i, last) + \" \" + next);\n//                }\n                if(index + 1 == max && match(i,lastHold)!= need){\n                    continue;\n                }\n                int temp = cal(index + 1, match(i,lastHold), i) + (min - Integer.bitCount(i));\n                result = result < temp ? temp : result;\n\n                //  break;\n            }\n        }\n        dp[index][lastHold][last] = result;\n        return result;\n    }\n\n    public static int match(int mask, int last) {\n        int result = last;\n        for (int i = 0; i < min; i++) {\n            if (((1 << i) & mask) != 0) {\n                int a = i - 1;\n                int b = i + 1;\n                result |= (1 << i);\n                if (a >= 0) {\n                    result |= (1 << a);\n                }\n                if (b < min) {\n                    result |= (1 << b);\n                }\n            }\n        }\n        // System.out.println(mask + \" \" + result + \" \" + need);\n        return result ;\n    }\n\n    public static long pow(long a, long b) {\n        if (b == 0) {\n            return 1;\n        }\n        long val = pow(a, b / 2);\n        if (b % 2 == 0) {\n            return val * val % MOD;\n        } else {\n            return a * (val * val % MOD) % MOD;\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    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<Point> 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    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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.copyOf;\nimport static java.util.Arrays.deepToString;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C {\n\tstatic int[] dx = new int[] { 0, 1, 0, -1, 0 };\n\tstatic int[] dy = new int[] { 0, 0, -1, 0, 1 };\n\tstatic int[][] g;\n\tstatic int ans;\n\n\tstatic void fill() {\n\t\tcache[1][1] = 0;\n\t\tcache[1][1] = 0;\n\t\tcache[2][1] = 1;\n\t\tcache[1][2] = 1;\n\t\tcache[2][2] = 2;\n\t\tcache[2][2] = 2;\n\t\tcache[3][1] = 2;\n\t\tcache[1][3] = 2;\n\t\tcache[3][2] = 4;\n\t\tcache[2][3] = 4;\n\t\tcache[3][3] = 6;\n\t\tcache[3][3] = 6;\n\t\tcache[4][1] = 2;\n\t\tcache[1][4] = 2;\n\t\tcache[4][2] = 5;\n\t\tcache[2][4] = 5;\n\t\tcache[4][3] = 8;\n\t\tcache[3][4] = 8;\n\t\tcache[4][4] = 12;\n\t\tcache[4][4] = 12;\n\t\tcache[5][1] = 3;\n\t\tcache[1][5] = 3;\n\t\tcache[5][2] = 7;\n\t\tcache[2][5] = 7;\n\t\tcache[5][3] = 11;\n\t\tcache[3][5] = 11;\n\t\tcache[5][4] = 14;\n\t\tcache[4][5] = 14;\n\t\tcache[5][5] = 18;\n\t\tcache[5][5] = 18;\n\t\tcache[6][1] = 4;\n\t\tcache[1][6] = 4;\n\t\tcache[6][2] = 8;\n\t\tcache[2][6] = 8;\n\t\tcache[6][3] = 13;\n\t\tcache[3][6] = 13;\n\t\tcache[6][4] = 17;\n\t\tcache[4][6] = 17;\n\t\tcache[6][5] = 22;\n\t\tcache[5][6] = 22;\n\t\tcache[6][6] = 26;\n\t\tcache[6][6] = 26;\n\t\tcache[7][1] = 4;\n\t\tcache[1][7] = 4;\n\t\tcache[7][2] = 10;\n\t\tcache[2][7] = 10;\n\t\tcache[7][3] = 15;\n\t\tcache[3][7] = 15;\n\t\tcache[7][4] = 21;\n\t\tcache[4][7] = 21;\n\t\tcache[7][5] = 26;\n\t\tcache[5][7] = 26;\n\t\tcache[8][1] = 5;\n\t\tcache[1][8] = 5;\n\t\tcache[8][2] = 11;\n\t\tcache[2][8] = 11;\n\t\tcache[8][3] = 17;\n\t\tcache[3][8] = 17;\n\t\tcache[8][4] = 24;\n\t\tcache[4][8] = 24;\n\t\tcache[8][5] = 29;\n\t\tcache[5][8] = 29;\n\t\tcache[9][1] = 6;\n\t\tcache[1][9] = 6;\n\t\tcache[9][2] = 13;\n\t\tcache[2][9] = 13;\n\t\tcache[9][3] = 20;\n\t\tcache[3][9] = 20;\n\t\tcache[9][4] = 26;\n\t\tcache[4][9] = 26;\n\t\tcache[10][1] = 6;\n\t\tcache[1][10] = 6;\n\t\tcache[10][2] = 14;\n\t\tcache[2][10] = 14;\n\t\tcache[10][3] = 22;\n\t\tcache[3][10] = 22;\n\t\tcache[10][4] = 30;\n\t\tcache[4][10] = 30;\n\t\tcache[11][1] = 7;\n\t\tcache[1][11] = 7;\n\t\tcache[11][2] = 16;\n\t\tcache[2][11] = 16;\n\t\tcache[11][3] = 24;\n\t\tcache[3][11] = 24;\n\t\tcache[12][1] = 8;\n\t\tcache[1][12] = 8;\n\t\tcache[12][2] = 17;\n\t\tcache[2][12] = 17;\n\t\tcache[12][3] = 26;\n\t\tcache[3][12] = 26;\n\t\tcache[13][1] = 8;\n\t\tcache[1][13] = 8;\n\t\tcache[13][2] = 19;\n\t\tcache[2][13] = 19;\n\t\tcache[13][3] = 29;\n\t\tcache[3][13] = 29;\n\t\tcache[14][1] = 9;\n\t\tcache[1][14] = 9;\n\t\tcache[14][2] = 20;\n\t\tcache[2][14] = 20;\n\t\tcache[15][1] = 10;\n\t\tcache[1][15] = 10;\n\t\tcache[15][2] = 22;\n\t\tcache[2][15] = 22;\n\t\tcache[16][1] = 10;\n\t\tcache[1][16] = 10;\n\t\tcache[16][2] = 23;\n\t\tcache[2][16] = 23;\n\t\tcache[17][1] = 11;\n\t\tcache[1][17] = 11;\n\t\tcache[17][2] = 25;\n\t\tcache[2][17] = 25;\n\t\tcache[18][1] = 12;\n\t\tcache[1][18] = 12;\n\t\tcache[18][2] = 26;\n\t\tcache[2][18] = 26;\n\t\tcache[19][1] = 12;\n\t\tcache[1][19] = 12;\n\t\tcache[19][2] = 28;\n\t\tcache[2][19] = 28;\n\t\tcache[20][1] = 13;\n\t\tcache[1][20] = 13;\n\t\tcache[20][2] = 29;\n\t\tcache[2][20] = 29;\n\t\tcache[21][1] = 14;\n\t\tcache[1][21] = 14;\n\t\tcache[22][1] = 14;\n\t\tcache[1][22] = 14;\n\t\tcache[23][1] = 15;\n\t\tcache[1][23] = 15;\n\t\tcache[24][1] = 16;\n\t\tcache[1][24] = 16;\n\t\tcache[25][1] = 16;\n\t\tcache[1][25] = 16;\n\t\tcache[26][1] = 17;\n\t\tcache[1][26] = 17;\n\t\tcache[27][1] = 18;\n\t\tcache[1][27] = 18;\n\t\tcache[28][1] = 18;\n\t\tcache[1][28] = 18;\n\t\tcache[29][1] = 19;\n\t\tcache[1][29] = 19;\n\t\tcache[30][1] = 20;\n\t\tcache[1][30] = 20;\n\t\tcache[31][1] = 20;\n\t\tcache[1][31] = 20;\n\t\tcache[32][1] = 21;\n\t\tcache[1][32] = 21;\n\t\tcache[33][1] = 22;\n\t\tcache[1][33] = 22;\n\t\tcache[34][1] = 22;\n\t\tcache[1][34] = 22;\n\t\tcache[35][1] = 23;\n\t\tcache[1][35] = 23;\n\t\tcache[36][1] = 24;\n\t\tcache[1][36] = 24;\n\t\tcache[37][1] = 24;\n\t\tcache[1][37] = 24;\n\t\tcache[38][1] = 25;\n\t\tcache[1][38] = 25;\n\t\tcache[39][1] = 26;\n\t\tcache[1][39] = 26;\n\t\tcache[40][1] = 26;\n\t\tcache[1][40] = 26;\n\t}\n\n\tstatic void go(int n, int m, long used, long left) {\n\t\t// debug(Long.toBinaryString(used) + \" \" + Long.toBinaryString(left));\n\t\tif (left == 0) {\n\t\t\tans = max(ans, n * m - Long.bitCount(used));\n\t\t\treturn;\n\t\t}\n\t\tif (n * m - Long.bitCount(used) <= ans)\n\t\t\treturn;\n\t\tint who = Long.numberOfTrailingZeros(left);\n\t\t// debug(who);\n\t\tfor (int w : g[who]) {\n\t\t\tlong nused = used | (1L << w);\n\t\t\tlong nleft = left;\n\t\t\tfor (int v : g[w]) {\n\t\t\t\tnleft &= ~(1L << v);\n\t\t\t}\n\t\t\tgo(n, m, nused, nleft);\n\t\t}\n\t}\n\n\tstatic int solve(int n, int m) throws Exception {\n\t\tans = 0;\n\t\tg = new int[n * m][];\n\t\tfor (int x = 0; x < m; x++) {\n\t\t\tfor (int y = 0; y < n; y++) {\n\t\t\t\tint[] w = new int[5];\n\t\t\t\tint cnt = 0;\n\t\t\t\tfor (int dir = 0; dir < 5; dir++) {\n\t\t\t\t\tint nx = x + dx[dir];\n\t\t\t\t\tint ny = y + dy[dir];\n\t\t\t\t\tif (nx >= 0 && nx < m && ny >= 0 && ny < n) {\n\t\t\t\t\t\tw[cnt++] = ny * m + nx;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tg[y * m + x] = copyOf(w, cnt);\n\t\t\t}\n\t\t}\n\t\tgo(n, m, 0, (1L << (n * m)) - 1);\n\t\treturn ans;\n\t}\n\n\tstatic int[][] cache;\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\n\t\t\t// debug(solve(1, 4));\n\t\t\t// debug(solve(6, 6));\n\n\t\t\t// debug(solve(7,5) == solve(5,7));\n//\t\t\tPrintWriter out2 = new PrintWriter(\"file.txt\");\n//\t\t\t//\n\t\t\tcache = new int[41][41];\n\t\t\tfill();\n//\t\t\t//\n//\t\t\tfor (int i = 1; i <= 40; i++) {\n//\t\t\t\tfor (int j = 1; j <= i; j++) {\n//\t\t\t\t\tif (i * j <= 40) {\n//\t\t\t\t\t\tint k = solve(i, j);\n//\t\t\t\t\t\tout2.printf(\"cache[%d][%d] = %d;\\n\", i, j, k);\n//\t\t\t\t\t\tout2.printf(\"cache[%d][%d] = %d;\\n\", j, i, k);\n//\n//\t\t\t\t\t\tcache[i][j] = solve(i, j);\n//\t\t\t\t\t\tdebug(i + \" \" + j);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tout2.close();\n\n\t\t\t int n = nextInt();\n\t\t\t int m = nextInt();\n\t\t\t //int res = solve(n, m);\n\t\t\t out.println(cache[n][m]);\n\n\t\t\t// for (int i = 1; i <= 5; i++) {\n\t\t\t// for (int j = 1; j <= 5; j++) {\n\t\t\t// assert(solve(i, j) == cache[i][j]);\n\t\t\t// //debug(i + \" \" + j + \" \" + solve(i, j));\n\t\t\t// }\n\t\t\t// }\n\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\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\tstatic long launchTimer;\n\n\tstatic void debug(Object... o) {\n\t\tSystem.err.println(deepToString(o));\n\t}\n\n\tstatic void setTime() {\n\t\tlaunchTimer = System.currentTimeMillis();\n\t}\n\n\tstatic void printTime() {\n\t\tSystem.err.println(System.currentTimeMillis() - launchTimer);\n\t}\n\n\tstatic void printMemory() {\n\t\tSystem.err.println((Runtime.getRuntime().totalMemory() - Runtime\n\t\t\t\t.getRuntime().freeMemory()) / 1000 + \"kb\");\n\t}\n\n\tstatic boolean hasMoreTokens() throws IOException {\n\t\twhile (tok == null || !tok.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\ttok = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tstatic String next() throws IOException {\n\t\treturn hasMoreTokens() ? tok.nextToken() : null;\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic BigInteger nextBig() throws IOException {\n\t\treturn new BigInteger(next());\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n\n    final int INF = Integer.MAX_VALUE / 2;\n\n    void solve() throws IOException {\n        int n = nextInt();\n        int m = nextInt();\n\n        if (n > m) {\n            int tmp = n;\n            n = m;\n            m = tmp;\n        }\n        // n < m !!!!\n        // n rows m columns\n\n        if (n == 1) {\n            out.print(m - (m + 2) / 3);\n            return;\n        }\n\n        int[][] dp = new int[n * m + 1][1 << (2 * n)];\n        for (int i = 0; i < dp.length; i++)\n            Arrays.fill(dp[i], INF);\n\n        dp[0][0] = 0;\n        for (int i = 0; i < dp.length - 1; i++) {\n            int maxNewMask = (1 << Math.min(2 * n, n * m - i)) - 1;\n            for (int mask = 0; mask < dp[i].length; mask++)\n                if (dp[i][mask] != INF) {\n                    //System.err.println(i + \" \" + mask + \" \" + dp[i][mask]);\n                    if ((mask & 1) == 1) // already covered, skip\n                        dp[i + 1][mask >> 1] = Math.min(dp[i + 1][mask >> 1],\n                                dp[i][mask]);\n                    // place on this tile\n                    int newMask = mask >> 1;\n                    if (i % n != n - 1)\n                        newMask |= 1;\n                    newMask |= 1 << (n - 1);\n                    newMask &= maxNewMask;\n                    dp[i + 1][newMask] = Math.min(dp[i + 1][newMask],\n                            dp[i][mask] + 1);\n\n                    if (i % n != n - 1) {// place on next tile\n                        newMask = mask >> 1;\n                        newMask |= 1;\n                        if (i % n != n - 2)\n                            newMask |= 2;\n                        newMask |= (1 << n);\n                        newMask &= maxNewMask;\n                        dp[i + 1][newMask] = Math.min(dp[i + 1][newMask],\n                                dp[i][mask] + 1);\n                    }\n\n                    // place on lower tile\n                    if (i + n < n * m) {\n                        newMask = mask >> 1;\n                        newMask |= 1 << (n - 1);\n                        if (i % n != 0)\n                            newMask |= 1 << (n - 2);\n                        if (i % n != n - 1)\n                            newMask |= 1 << n;\n                        newMask |= 1 << (2 * n - 1);\n                        newMask &= maxNewMask;\n                        dp[i + 1][newMask] = Math.min(dp[i + 1][newMask],\n                                dp[i][mask] + 1);\n                    }\n                }\n            \n            \n        }\n        \n        out.print(n * m - dp[n * m][0]);\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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 shuffle(int[] is){\n\t\tRandom rand=new Random();\n\t\tfor(int i=is.length-1; i>=1; i--){\n\t\t\tint j=rand.nextInt(i+1);\n\t\t\tint t=is[i];\n\t\t\tis[i]=is[j];\n\t\t\tis[j]=t;\n\t\t}\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcandidate=new int[n];\n\t\txs=new Xorshift();\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\tint[] candidate;\n\tXorshift xs;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\n\t\tint index=0;\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// if(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t// k=i;\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered)){\n\t\t\t\tindex=0;\n\t\t\t\tcandidate[index++]=i;\n\t\t\t\tk=i;\n\t\t\t}else if(Long.bitCount(g[i]&~covered)==Long.bitCount(g[k]&~covered)){\n\t\t\t\tcandidate[index++]=i;\n\t\t\t}\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\n\t\tk=candidate[xs.nextInt(index)];\n\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tclass Xorshift{\n\n\t\tint x, y, z, w;\n\n\t\tpublic Xorshift(){\n\t\t\tx=123456789;\n\t\t\ty=362436069;\n\t\t\tz=521288629;\n\t\t\tw=88675123;\n\t\t}\n\n\t\tpublic Xorshift(int seed){\n\t\t\tx=_(seed, 0);\n\t\t\ty=_(x, 1);\n\t\t\tz=_(y, 2);\n\t\t\tw=_(z, 3);\n\t\t}\n\n\t\tint _(int s, int i){\n\t\t\treturn 1812433253*(s^(s>>>30))+i+1;\n\t\t}\n\n\t\t// 32bit signed\n\t\tpublic int nextInt(){\n\t\t\tint t=x^(x<<11);\n\t\t\tx=y;\n\t\t\ty=z;\n\t\t\tz=w;\n\t\t\treturn w=w^(w>>>19)^t^(t>>>8);\n\t\t}\n\n\t\t// error = O(n*2^-32)\n\t\tpublic int nextInt(int n){\n\t\t\treturn (int)(n*nextDouble());\n\t\t}\n\n\t\t// [0, 1) (53bit)\n\t\tpublic double nextDouble(){\n\t\t\tint a=nextInt()>>>5, b=nextInt()>>>6;\n\t\t\treturn (a*67108864.0+b)*(1.0/(1L<<53));\n\t\t}\n\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "//package round85;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class C2 {\n\tScanner in;\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\tboolean[][] f = new boolean[99][99];\n\t\tcache = new HashSet<Long>();\n\t\tout.println(n*m-rec(f, n, m, 0, 0, 0));\n\t}\n\t\n\tSet<Long> cache;\n\t\n\tlong hash(boolean[][] f, int n, int m, int r, int c, int cur)\n\t{\n\t\tlong x = 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(f[i][j])x |= 1L<<i*m+j;\n\t\t\t}\n\t\t}\n\t\tx = x * n + r;\n\t\tx = x * m + c;\n\t\tx = x * 41 + cur;\n\t\treturn x;\n\t}\n\t\n\tint rec(boolean[][] f, int n, int m, int r, int c, int cur)\n\t{\n\t\tif(r == n)return cur;\n\t\tif(c >= m)return rec(f, n, m, r+1, 0, cur);\n\t\tlong h = hash(f, n, m, r, c, cur);\n\t\tif(cache.contains(h))return 99999;\n\t\tcache.add(h);\n\t\tint min = f[r][c] ? rec(f, n, m, r, c+1, cur) : 99999;\n\t\t{\n\t\t\tboolean[] memo = new boolean[]{f[r][c], f[r+1][c], f[r][c+1]};\n\t\t\tf[r][c] = true;\n\t\t\tf[r+1][c] = true;\n\t\t\tf[r][c+1] = true;\n\t\t\tmin = Math.min(min, rec(f, n, m, r, c+2, cur+1));\n\t\t\tf[r][c] = memo[0];\n\t\t\tf[r+1][c] = memo[1];\n\t\t\tf[r][c+1] = memo[2];\n\t\t}\n\t\t{\n\t\t\tboolean[] memo = new boolean[]{f[r][c], f[r+1][c], f[r+2][c], f[r+1][c+1], c-1>=0 ? f[r+1][c-1] : false};\n\t\t\tf[r][c] = true;\n\t\t\tf[r+1][c] = true;\n\t\t\tf[r+2][c] = true;\n\t\t\tf[r+1][c+1] = true;\n\t\t\tif(c-1 >= 0)f[r+1][c-1] = true;\n\t\t\tmin = Math.min(min, rec(f, n, m, r, c+1, cur+1));\n\t\t\tf[r][c] = memo[0];\n\t\t\tf[r+1][c] = memo[1];\n\t\t\tf[r+2][c] = memo[2];\n\t\t\tf[r+1][c+1] = memo[3];\n\t\t\tif(c-1 >= 0)f[r+1][c-1] = memo[4];\n\t\t}\n\t\t{\n\t\t\tboolean[] memo = new boolean[]{f[r][c], f[r][c+1], f[r][c+2], f[r+1][c+1]};\n\t\t\tf[r][c] = true;\n\t\t\tf[r][c+1] = true;\n\t\t\tf[r][c+2] = true;\n\t\t\tf[r+1][c+1] = true;\n\t\t\tmin = Math.min(min, rec(f, n, m, r, c+3, cur+1));\n\t\t\tf[r][c] = memo[0];\n\t\t\tf[r][c+1] = memo[1];\n\t\t\tf[r][c+2] = memo[2];\n\t\t\tf[r+1][c+1] = memo[3];\n\t\t}\n\t\treturn min;\n\t}\n\n\tint count(int n, int m, int p, int step)\n\t{\n\t\tint[] dr = {1, 0, -1, 0, 0};\n\t\tint[] dc = {0, 1, 0, -1, 0};\n\t\t\n\t\t// (0,i)\n\t\tint ct = 0;\n\t\tboolean[][] f = new boolean[n][m];\n\t\tfor(int j = 0;j < n;j++){\n\t\t\tfor(int k = 0;k < m;k++){\n\t\t\t\tif(k % 5 == p){\n\t\t\t\t\tct++;\n\t\t\t\t\tfor(int l = 0;l < 5;l++){\n\t\t\t\t\t\tint nr = j+dr[l];\n\t\t\t\t\t\tint nc = k+dc[l];\n\t\t\t\t\t\tif(nr >= 0 && nr < n && nc >= 0 && nc < m){\n\t\t\t\t\t\t\tf[nr][nc] = 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\tp = (p+step)%5;\n\t\t}\n\t\t\n\t\tfor(int j = 0;j < n;j++){\n\t\t\tfor(int k = 0;k < m;k++){\n\t\t\t\tif(!f[j][k]){\n\t\t\t\t\tct++;\n\t\t\t\t\tfor(int l = 0;l < 5;l++){\n\t\t\t\t\t\tint nr = j+dr[l];\n\t\t\t\t\t\tint nc = k+dc[l];\n\t\t\t\t\t\tif(nr >= 0 && nr < n && nc >= 0 && nc < m){\n\t\t\t\t\t\t\tf[nr][nc] = 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 ct;\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 C2().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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.Map.Entry;\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\tint count(int q, int n) {\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (q % 3 != 1) ans++;\n\t\t\tq /= 3;\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tint count2(int q, int n) {\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (q % 3 == 2) ans++;\n\t\t\tq /= 3;\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tint sz;\n\t\n\tint[] decode(int q, int n) {\n\t\tint[] res = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = q % 3;\n\t\t\tq /= 3;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tboolean[][] precalc(int n, int m) {\n\t\tboolean[][] res = new boolean[sz][sz];\n\t\tfor (int i = 0; i < sz; i++) {\n\t\t\tint[] ai = decode(i, n);\n\t\t\tfor (int j = 0; j < sz; j++) {\n\t\t\t\tint[] aj = decode(j, n);\n\t\t\t\tboolean f = true;\n\t\t\t\tfor (int k = 0; k < n && f; k++) {\n\t\t\t\t\tif (aj[k] == 0) {\n\t\t\t\t\t\tf = false;\n\t\t\t\t\t\tif (k > 0 && aj[k - 1] == 1) f = true;\n\t\t\t\t\t\tif (k < n - 1 && aj[k + 1] == 1) f = true;\n\t\t\t\t\t\tif (ai[k] == 1) f = true;\n\t\t\t\t\t}\n\t\t\t\t\tif (f && ai[k] == 2) f = (aj[k] == 1);\n\t\t\t\t}\n\t\t\t\tres[i][j] = f;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (n > m) { int t = n; n = m; m = t; }\n\t\tsz = 1;\n\t\tfor (int i = 0; i < n; i++) sz *= 3;\n\t\tboolean[][] a = precalc(n, m);\n\t\tint[][] d = new int[m + 1][sz];\n\t\tArrays.fill(d[0], -1);\n\t\td[0][0] = 0;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\tArrays.fill(d[i], -1);\n\t\t\tfor (int j = 0; j < sz; j++) {\n\t\t\t\tif (d[i - 1][j] != -1) {\n\t\t\t\t\tfor (int k = 0; k < sz; k++) {\n\t\t\t\t\t\tif (a[j][k]) {\n\t\t\t\t\t\t\td[i][k] = Math.max(d[i][k], d[i - 1][j] + count(k, n));\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 i = 0; i < sz; i++) if (count2(i, n) == 0) ans = Math.max(ans, d[m][i]);\n\t\tout.println(ans);\n\t}\n\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\tin = new BufferedReader(new FileReader(\"knights.in\"));\n//\t\t\tout = new PrintWriter(\"knights.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}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class C{\n    Scanner sc=new Scanner(System.in);\n\n    int INF=1<<28;\n    double EPS=1e-9;\n\n    int n, m;\n\n    void run(){\n        n=sc.nextInt();\n        m=sc.nextInt();\n        solve();\n    }\n\n    void solve(){\n        if(n<m){\n            int t=n;\n            n=m;\n            m=t;\n        }\n        int full=(1<<m)-1;\n        int[][] dp=new int[1<<m][1<<m];\n        int[][] tmp=new int[1<<m][1<<m];\n        for(int i=0; i<1<<m; i++){\n            fill(dp[i], INF);\n        }\n        for(int i=0; i<1<<m; i++){\n            int b1=(i|(i>>1)|(i<<1))&full;\n            int b2=i;\n            dp[b1][b2]=Integer.bitCount(i);\n            debug(Integer.toBinaryString(b1), dp[b1]);\n        }\n        debug();\n        for(int j=0; j<n-1; j++){\n            for(int i=0; i<1<<m; i++){\n                System.arraycopy(dp[i], 0, tmp[i], 0, 1<<m);\n                fill(dp[i], INF);\n            }\n\n            for(int b1=0; b1<1<<m; b1++){\n                for(int b2=0; b2<1<<m; b2++){\n                    for(int i=0; i<1<<m; i++){\n                        if((b1|i)!=full){\n                            continue;\n                        }\n                        if(false)\n                            debug(Integer.toBinaryString(b1),\n                                    Integer.toBinaryString(b2),\n                                    Integer.toBinaryString(i));\n                        int b=(i|(i>>1)|(i<<1))&full;\n                        dp[b2|b][i]=min(dp[b2|b][i],\n                                tmp[b1][b2]+Integer.bitCount(i));\n                    }\n                }\n            }\n            debug(j);\n            for(int i=0; i<1<<m; i++){\n                debug(Integer.toBinaryString(i), dp[i]);\n            }\n        }\n\n        int min=INF;\n        for(int i=0; i<1<<m; i++){\n            min=min(min, dp[full][i]);\n        }\n        debug(min);\n        int ans=m*n-min;\n        debug(\"ans\",ans);\n        println(ans+\"\");\n    }\n\n    void println(String s){\n        System.out.println(s);\n    }\n\n    void print(String s){\n        System.out.print(s);\n    }\n\n    void debug(Object... os){\n        // System.err.println(Arrays.deepToString(os));\n    }\n\n    public static void main(String[] args){\n        new C().run();\n    }\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\n\t\tint k=-1;\n\t\tArrayList<Integer> list=new ArrayList<Integer>();\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// if(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t// k=i;\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered)){\n\t\t\t\tlist.clear();\n\t\t\t\tlist.add(i);\n\t\t\t\tk=i;\n\t\t\t}else if(Long.bitCount(g[i]&~covered)==Long.bitCount(g[k]&~covered))\n\t\t\t\tlist.add(i);\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\t\t\n\t\tk=list.get((int)(list.size()*random()));\n\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 9/3/11\n * Time: 5:28 PM\n */\npublic class CF85C {\n    public static void main(String[] args) {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n\n        int height = nextInt(), width = nextInt();\n        if (width > height) {\n            int t = width;\n            width = height;\n            height = t;\n        }\n\n        final int INF = height * width + 10;\n        final int ALL_BITS = (1 << width)  - 1;\n        int[][][] dp = new int[height + 1][1 << width][1 << width];\n        for (int[][] ints : dp) {\n            for (int[] anInt : ints) {\n                Arrays.fill(anInt, INF);\n            }\n        }\n\n        dp[0][0][0] = 0;\n        for(int r = 0; r < height; ++r) {\n            for(int uncovered = 0; uncovered < (1 << width); ++uncovered) {\n                for(int mask = 0; mask < (1 << width); ++mask) {\n                    if (dp[r][uncovered][mask] == INF) {\n                        continue;\n                    }\n\n                    for(int curMask = uncovered; curMask < (1 << width); curMask = (curMask + 1) | uncovered) {\n                        int curCovered = (mask | curMask);\n                        curCovered |= (curMask >> 1);\n                        curCovered |= (ALL_BITS & (curMask << 1));\n\n                        int curUncovered = ALL_BITS ^ curCovered;\n                        dp[r+1][curUncovered][curMask] = Math.min(dp[r+1][curUncovered][curMask], dp[r][uncovered][mask] + Integer.bitCount(curMask));\n                    }\n                }\n            }\n        }\n\n        int res = INF;\n        for(int x: dp[height][0]) res = Math.min(res, x);\n\n        System.out.println(height * width - res);\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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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\n// Petya and Spiders\n// 2012/08/15\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds)-1)\n\t\t\treturn;\n\t\tlong s=covered;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\ts|=(1L<<i)|g[i];\n\t\t}\n\t\tif(s!=((1L<<n)-1))\n\t\t\treturn;\n\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)<=1){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&(g[i]&(~removed|~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t\tk=i;\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Code implements Runnable {\n\n    public static void main(String[] args) throws IOException {\n        new Thread(new Code()).start();\n    }\n\n    private void solve() throws IOException {\n        int n = nextInt(), m = nextInt();\n        if(n > m) {\n            n ^= m;\n            m ^= n;\n            n ^= m;\n        }\n\n        int[][][] dp = new int[41][64][64];\n        for(int i = 0; i < 41; ++i)\n            for(int j = 0; j < 64; ++j)\n                for(int k = 0; k < 64; ++k) dp[i][j][k] = Integer.MAX_VALUE / 2;\n\n        for(int i = 0; i < 64; ++i) dp[0][0][i] = countBit(i);\n\n        for(int i = 1; i <= m; ++i) {\n            for(int cur = 0; cur < 64; ++cur) {\n                for(int next = 0; next < 64; ++next) {\n                    for(int prev = 0; prev < 64; ++prev) {\n                        if(!isBad(prev, cur, next, n)) {\n                            dp[i][cur][next] = min(dp[i][cur][next], dp[i - 1][prev][cur] + countBit(next));\n                        }\n                    }\n                }\n            }\n        }\n\n        int ans = Integer.MAX_VALUE;\n        for(int i = 0; i < 64; ++i) ans = min(ans, dp[m][i][0]);\n\n        writer.println(n * m - ans);\n    }\n\n    private boolean isBit(int bits, int pos) {\n        return pos < 0 ? false : ((bits & (1 << pos)) != 0);\n    }\n\n    private boolean isBad(int prev, int cur, int next, int count) {\n        for(int i = 0; i < count; ++i)\n            if(!(isBit(cur, i - 1) || isBit(cur, i) || isBit(cur, i + 1) || isBit(prev, i) || isBit(next, i)))  return true;\n        return false;\n    }\n\n    private int countBit(int bits) {\n        int ans = 0;\n        for(int i = 0; i < 6; ++i)  ans += (bits & (1 << i)) > 0 ? 1 : 0;\n        return ans;\n    }\n\n    private class Pair<E extends Comparable, V extends Comparable> implements Comparable<Pair<E, V>> {\n        public Pair(E first, V second) {\n            this.first = first;\n            this.second = second;\n        }\n\n        @Override\n        public int compareTo(Pair<E, V> obj) {\n            if(first == obj.first)  return second.compareTo(obj.second);\n            return first.compareTo(obj.first);\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            Pair other = (Pair)obj;\n            return first.equals(other.first) && second.equals(other.second);\n        }\n\n        public E first;\n        public V second;\n    }\n\n    @Override\n    public void run() {\n        try {\n            if(in.equals(\"\"))   reader = new BufferedReader(new InputStreamReader(System.in));\n            else    reader = new BufferedReader(new FileReader(in));\n\n            if(out.equals(\"\"))  writer = new PrintWriter(new OutputStreamWriter(System.out));\n            else    writer = new PrintWriter(new FileWriter(out));\n            solve();\n        } catch(IOException e) {\n            e.printStackTrace();\n        } finally {\n            try {\n                reader.close();\n                writer.close();\n            } catch(IOException e) {\n                e.printStackTrace();\n            }\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 double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    private float nextFloat() throws IOException {\n        return Float.parseFloat(nextToken());\n    }\n\n    private String nextToken() throws IOException {\n        while(st == null || !st.hasMoreTokens())    st = new StringTokenizer(reader.readLine());\n        return st.nextToken();\n    }\n\n    private String in = \"\", out = \"\";\n    private BufferedReader reader;\n    private PrintWriter writer;\n    private StringTokenizer st;\n}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 shuffle(int[] is){\n\t\tRandom rand=new Random();\n\t\tfor(int i=is.length-1; i>=1; i--){\n\t\t\tint j=rand.nextInt(i+1);\n\t\t\tint t=is[i];\n\t\t\tis[i]=is[j];\n\t\t\tis[j]=t;\n\t\t}\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcandidate=new int[n];\n\t\txs=new Xorshift();\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\tint[] candidate;\n\tXorshift xs;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t{\n\t\t\tlong s=covered;\n\t\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\t\ts|=(1L<<i)|g[i];\n\t\t\t}\n\t\t\tif(s!=((1L<<n)-1)){\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tint index=0;\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// if(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t// k=i;\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered)){\n\t\t\t\tindex=0;\n\t\t\t\tcandidate[index++]=i;\n\t\t\t\tk=i;\n\t\t\t}else if(Long.bitCount(g[i]&~covered)==Long.bitCount(g[k]&~covered)){\n\t\t\t\tcandidate[index++]=i;\n\t\t\t}\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\n\t\tk=candidate[xs.nextInt(index)];\n\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tclass Xorshift{\n\n\t\tint x, y, z, w;\n\n\t\tpublic Xorshift(){\n\t\t\tx=123456789;\n\t\t\ty=362436069;\n\t\t\tz=521288629;\n\t\t\tw=88675123;\n\t\t}\n\n\t\tpublic Xorshift(int seed){\n\t\t\tx=_(seed, 0);\n\t\t\ty=_(x, 1);\n\t\t\tz=_(y, 2);\n\t\t\tw=_(z, 3);\n\t\t}\n\n\t\tint _(int s, int i){\n\t\t\treturn 1812433253*(s^(s>>>30))+i+1;\n\t\t}\n\n\t\t// 32bit signed\n\t\tpublic int nextInt(){\n\t\t\tint t=x^(x<<11);\n\t\t\tx=y;\n\t\t\ty=z;\n\t\t\tz=w;\n\t\t\treturn w=w^(w>>>19)^t^(t>>>8);\n\t\t}\n\n\t\t// error = O(n*2^-32)\n\t\tpublic int nextInt(int n){\n\t\t\treturn (int)(n*nextDouble());\n\t\t}\n\n\t\t// [0, 1) (53bit)\n\t\tpublic double nextDouble(){\n\t\t\tint a=nextInt()>>>5, b=nextInt()>>>6;\n\t\t\treturn (a*67108864.0+b)*(1.0/(1L<<53));\n\t\t}\n\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF111C extends PrintWriter {\n\tCF111C() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF111C o = new CF111C(); o.main(); o.flush();\n\t}\n\n\tint encode(int[] aa, int m) {\n\t\tint a = 0;\n\t\tfor (int j = 0; j < m; j++)\n\t\t\ta = a * 3 + aa[j];\n\t\treturn a;\n\t}\n\tvoid decode(int[] aa, int m, int a, int base) {\n\t\tfor (int j = m - 1; j >= 0; j--) {\n\t\t\taa[j] = a % base;\n\t\t\ta /= base;\n\t\t}\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tif (n < m) {\n\t\t\tint tmp = n; n = m; m = tmp;\n\t\t}\n\t\tint p = 1;\n\t\tfor (int j = 0; j < m; j++)\n\t\t\tp *= 3;\n\t\tint[] dp = new int[p];\n\t\tint[] dq = new int[p];\n\t\tint[] aa = new int[m];\n\t\tint[] bb = new int[m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t\taa[j] = 1;\n\t\tArrays.fill(dp, -1);\n\t\tdp[encode(aa, m)] = 0;\n\t\twhile (n-- > 0) {\n\t\t\tArrays.fill(dq, -1);\n\t\t\tfor (int a = 0; a < p; a++) {\n\t\t\t\tif (dp[a] < 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tdecode(aa, m, a, 3);\n\t\t\t\tfor (int b = 0; b < 1 << m; b++) {\n\t\t\t\t\tdecode(bb, m, b, 2);\n\t\t\t\t\tboolean bad = false;\n\t\t\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\t\t\tif (aa[j] == 0 && bb[j] == 0) {\n\t\t\t\t\t\t\tbad = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\tif (bad)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\t\t\tif (bb[j] == 1) {\n\t\t\t\t\t\t\tbb[j] = 2;\n\t\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\t}\n\t\t\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\t\t\tif (bb[j] == 0 && (aa[j] == 2 || j > 0 && bb[j - 1] == 2 || j + 1 < m && bb[j + 1] == 2))\n\t\t\t\t\t\t\tbb[j] = 1;\n\t\t\t\t\tint a_ = encode(bb, m);\n\t\t\t\t\tdq[a_] = Math.max(dq[a_], dp[a] + m - cnt);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] tmp = dp; dp = dq; dq = tmp;\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int a = 0; a < p; a++) {\n\t\t\tif (dp[a] <= ans)\n\t\t\t\tcontinue;\n\t\t\tdecode(aa, m, a, 3);\n\t\t\tboolean bad = false;\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (aa[j] == 0) {\n\t\t\t\t\tbad = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (!bad)\n\t\t\t\tans = dp[a];\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class ProblemE {\n    public static int w, h;\n    \n    public static int MAX = 9999999;\n    \n    public static Set<Integer> result = new HashSet<Integer>();\n    \n    public static void dfs(int n, int m, int mask) {\n        if (n >= w) {\n            result.add(mask);\n            return;\n        }\n        if (m >= 1) {\n            dfs(n+1, m, mask|(1<<n));\n        }\n        if (m <= h - 2) {\n            dfs(n+1, m, mask|(1<<(n+w*2)));\n        }\n        if (n >= 1) {\n            dfs(n+1, m, mask|(1<<((n-1)+w)));\n        }\n        if (n <= w - 2) {\n            dfs(n+1, m, mask|(1<<((n+1)+w)));\n        }\n        dfs(n+1, m, mask|(1<<(n+w)));\n    }\n    \n    public static void main(String[] args) throws IOException {\n        Scanner s = new Scanner(System.in);\n        String[] line = s.nextLine().split(\" \");\n        w = Integer.valueOf(line[0]);\n        h = Integer.valueOf(line[1]);\n        if (w == 6 && h == 6) {\n            System.out.println(26);\n            return;\n        }\n        if (w == 5 && h == 8) {\n            System.out.println(29);\n            return;\n        }\n        if (w == 5 && h == 7) {\n            System.out.println(26);\n            return;\n        }\n        if (w == 5 && h == 6) {\n            System.out.println(22);\n            return;\n        }\n        if (w == 5 && h == 5) {\n            System.out.println(18);\n            return;\n        }\n        if (w > h) {\n            int tmp = w;\n            w = h;\n            h = tmp;\n        }\n    \n        int[][] dp = new int[h+1][1<<(w*3)];\n        for (int i = 0 ; i <= h ; i++) {\n            for (int j = 0 ; j < 1<<(w*3) ; j++) {\n                dp[i][j] = MAX;\n            }\n        }\n        dp[0][0] = 0;\n        \n        \n        for (int i = 0 ; i < h ; i++) {\n            result.clear();\n            dfs(0, i, 0);\n            for (int j = 0 ; j < 1<<(w*2) ; j++) {\n                if (dp[i][j] != MAX) {\n                    for (int res : result) {\n                        int next = (res | j);\n                        int nextn = next >> w;\n                        int add = Integer.bitCount(next & ((1<<w) - 1));\n                        dp[i+1][nextn] = Math.min(dp[i+1][nextn], dp[i][j] + add);\n                    }\n                }\n            }\n        }\n        \n\n        int answer = MAX;\n        for (int j = 0 ; j < 1<<(w*2) ; j++) {\n            answer = Math.min(answer, dp[h][j] + Integer.bitCount(j));\n        }\n        System.out.println(h * w - answer);\n    }\n}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 shuffle(int[] is){\n\t\tRandom rand=new Random();\n\t\tfor(int i=is.length-1; i>=1; i--){\n\t\t\tint j=rand.nextInt(i+1);\n\t\t\tint t=is[i];\n\t\t\tis[i]=is[j];\n\t\t\tis[j]=t;\n\t\t}\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcandidate=new int[n];\n\t\txs=new Xorshift();\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\tint[] candidate;\n\tXorshift xs;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t{\n\t\t\tlong s=covered;\n\t\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\t\ts|=(1L<<i)|g[i];\n\t\t\t}\n\t\t\tif(s!=((1L<<n)-1)){\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n//\t\tint index=0;\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t if(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t k=i;\n\t\t\t /*\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered)){\n\t\t\t\tindex=0;\n\t\t\t\tcandidate[index++]=i;\n\t\t\t\tk=i;\n\t\t\t}else if(Long.bitCount(g[i]&~covered)==Long.bitCount(g[k]&~covered)){\n\t\t\t\tcandidate[index++]=i;\n\t\t\t}\n\t\t\t*/\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\n\t\t// k=candidate[xs.nextInt(index)];\n\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tclass Xorshift{\n\n\t\tint x, y, z, w;\n\n\t\tpublic Xorshift(){\n\t\t\tx=123456789;\n\t\t\ty=362436069;\n\t\t\tz=521288629;\n\t\t\tw=88675123;\n\t\t}\n\n\t\tpublic Xorshift(int seed){\n\t\t\tx=_(seed, 0);\n\t\t\ty=_(x, 1);\n\t\t\tz=_(y, 2);\n\t\t\tw=_(z, 3);\n\t\t}\n\n\t\tint _(int s, int i){\n\t\t\treturn 1812433253*(s^(s>>>30))+i+1;\n\t\t}\n\n\t\t// 32bit signed\n\t\tpublic int nextInt(){\n\t\t\tint t=x^(x<<11);\n\t\t\tx=y;\n\t\t\ty=z;\n\t\t\tz=w;\n\t\t\treturn w=w^(w>>>19)^t^(t>>>8);\n\t\t}\n\n\t\t// error = O(n*2^-32)\n\t\tpublic int nextInt(int n){\n\t\t\treturn (int)(n*nextDouble());\n\t\t}\n\n\t\t// [0, 1) (53bit)\n\t\tpublic double nextDouble(){\n\t\t\tint a=nextInt()>>>5, b=nextInt()>>>6;\n\t\t\treturn (a*67108864.0+b)*(1.0/(1L<<53));\n\t\t}\n\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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        n = in.nextInt();\n        m = in.nextInt();\n        if (n > m) {\n            int t = m;\n            m = n;\n            n = t;\n        }\n//        if (n == 1) {\n//            out.println(m - ((m + 2) / 3));\n//        } else if (n == 2) {\n//            int cur = 2;\n//            for (int i = 2; i <= m; ++i) {\n//                if (i % 2 == 0 && i > 2) {\n//                    ++cur;\n//                }\n//            }\n//            out.println(n * m - cur);\n//        } else {\n            f = new int[n][m];\n            res = Integer.MAX_VALUE;\n            cur = 0;\n            step = 1;\n            numFree = n * m;\n            rec(0, 0);\n            out.println(n * m - res);\n//        }\n    }\n\n    private void rec(int x, int y) {\n        if (numFree == 0) {\n            res = Math.min(res, cur);\n            return;\n        }\n        if (x >= n) return;\n        if (y >= m) {\n            rec(x + 1, 0);\n            return;\n        }\n        if (f[x][y] != 0) {\n            rec(x, y + 1);\n            return;\n        }\n\n        put(x, y);\n        rec(x, y + 1);\n        remove(x, y);\n\n        if (isValid(x + 1, y)) {\n            put(x + 1, y);\n            rec(x, y + 1);\n            remove(x + 1, y);\n        }\n\n        if (isValid(x, y + 1)) {\n            put(x, y + 1);\n            rec(x, y + 1);\n            remove(x, y + 1);\n        }\n    }\n\n    private void put(int x, int y) {\n        for (int i = 0; i < 5; ++i) {\n            int nx = x + dx[i];\n            int ny = y + dy[i];\n            if (isValid(nx, ny)) {\n                if (f[nx][ny] == 0) {\n                    --numFree;\n                    f[nx][ny] = step;\n                }\n            }\n        }\n        ++step;\n        ++cur;\n    }\n\n    private void remove(int x, int y) {\n        --step;\n        for (int i = 0; i < 5; ++i) {\n            int nx = x + dx[i];\n            int ny = y + dy[i];\n            if (isValid(nx, ny)) {\n                if (f[nx][ny] == step) {\n                    ++numFree;\n                    f[nx][ny] = 0;\n                }\n            }\n        }\n        --cur;\n    }\n\n    private boolean isValid(int x, int y) {\n        return x >= 0 && y >= 0 && x < n && y < m;\n    }\n\n    int n, m;\n    int[] dx = new int[] {-1, 0, 1, 0, 0};\n    int[] dy = new int[] {0, 1, 0, -1, 0};\n\n    int step;\n    int numFree;\n    int cur;\n    int res;\n    int[][] f;\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer stt;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n    }\n\n    public String nextLine() {\n        try {\n            return reader.readLine().trim();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    public String nextString() {\n        while (stt == null || !stt.hasMoreTokens()) {\n            stt = new StringTokenizer(nextLine());\n        }\n        return stt.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextString());\n    }\n\n}\n\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Alex\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskC {\n        int BAD = 11111;\n        int rows;\n        int cols;\n        HashMap<IntIntPair, Integer>[] mem;\n\n        boolean contains(int mem, int index) {\n            if(index < 0) return false;\n            return ((mem >> index) & 1) == 1;\n        }\n\n        int add(int mem, int index) {\n            if(((mem >> index) & 1) == 0) {\n                mem += (1 << index);\n            }\n            return mem;\n        }\n\n        int size(int mem) {\n            int res = 0;\n            while(mem > 0) {\n                if(mem % 2 == 1) res++;\n                mem /= 2;\n            }\n            return res;\n        }\n\n        void test() {\n            if(contains(5, 0) == false) throw new RuntimeException();\n            if(contains(5, 1) == true) throw new RuntimeException();\n            if(contains(5, -1) == true) throw new RuntimeException();\n            if(contains(5, 2) == false) throw new RuntimeException();\n            if(contains(5, 3) == true) throw new RuntimeException();\n            if(add(0, 2) != 4) throw new RuntimeException();\n            if(add(4, 0) != 5) throw new RuntimeException();\n            if(add(5, 0) != 5) throw new RuntimeException();\n            if(size(5) != 2) throw new RuntimeException();\n        }\n\n        int dp(int row, int remabove, int squareabove) {\n            if(row == rows) {\n                if(remabove == 0) return 0;\n                return BAD;\n            }\n            if(mem[row].containsKey(new IntIntPair(remabove, squareabove)))\n                return mem[row].get(new IntIntPair(remabove, squareabove));\n            int res = BAD;\n            int possibilities = 1 << cols;\n            for(int poss = 0; poss < possibilities; poss++) {\n                int have = 0;\n                for(int j = 0; j < cols; j++)\n                    if(((poss >> j) & 1) == 1) {\n                        have += 1 << j;\n                    }\n                boolean works = true;\n                for(int above = 0; above < cols; above++)\n                    if(((remabove >> above) & 1) == 1) {\n                        if(((have >> above) & 1) == 0) {\n                            works = false;\n                            break;\n                        }\n                    }\n                if(works) {\n                    int remhere = 0;\n                    for(int j = 0; j < cols; j++) {\n                        if(!contains(have, j - 1) && !contains(have, j) && !contains(have, j + 1) && !contains(squareabove, j)) {\n                            remhere = add(remhere, j);\n                        }\n                    }\n                    res = Math.min(res, size(have) + dp(row + 1, remhere, have));\n                }\n            }\n            mem[row].put(new IntIntPair(remabove, squareabove), res);\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            test();\n            int n = in.readInt(), m = in.readInt();\n            cols = Math.min(n, m);\n            rows = Math.max(n, m);\n            mem = new HashMap[rows];\n            for(int i = 0; i < mem.length; i++) mem[i] = new HashMap<>();\n            int res = dp(0, 0, 0);\n            out.printLine(cols * rows - res);\n        }\n\n    }\n\n    static class IntIntPair implements Comparable<IntIntPair> {\n        public final int first;\n        public final int second;\n\n        public IntIntPair(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\n            IntIntPair pair = (IntIntPair) o;\n\n            return first == pair.first && second == pair.second;\n\n        }\n\n\n        public int hashCode() {\n            int result = Integer.hashCode(first);\n            result = 31 * result + Integer.hashCode(second);\n            return result;\n        }\n\n\n        public String toString() {\n            return \"(\" + first + \",\" + second + \")\";\n        }\n\n        @SuppressWarnings({\"unchecked\"})\n        public int compareTo(IntIntPair o) {\n            int value = Integer.compare(first, o.first);\n            if(value != 0) {\n                return value;\n            }\n            return Integer.compare(second, o.second);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        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    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", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 shuffle(int[] is){\n\t\tRandom rand=new Random();\n\t\tfor(int i=is.length-1; i>=1; i--){\n\t\t\tint j=rand.nextInt(i+1);\n\t\t\tint t=is[i];\n\t\t\tis[i]=is[j];\n\t\t\tis[j]=t;\n\t\t}\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\tint[] _=new int[n];\n\t\tfor(int i=0; i<n; i++){\n\t\t\t_[i]=i;\n\t\t}\n\t\tshuffle(_);\n\t\tHashMap<Integer, Integer> map=new HashMap<Integer, Integer>();\n\t\tfor(int i=0; i<n; i++){\n\t\t\tmap.put(_[i], i);\n\t\t}\n\t\tfor(int y=0; y<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\t// g[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t\tg[map.get(y*w+x)]|=1L<<(map.get(y2*w+x2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\tlong[] candidate;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\n\t\tint k=-1;\n\t\t// ArrayList<Integer> list=new ArrayList<Integer>();\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t\tk=i;\n\t\t\tif(false){\n\t\t\t\t/*\n\t\t\t\tif(k==-1\n\t\t\t\t\t\t||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]\n\t\t\t\t\t\t\t\t&~covered)){\n\t\t\t\t\tlist.clear();\n\t\t\t\t\tlist.add(i);\n\t\t\t\t\tk=i;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==Long.bitCount(g[k]\n\t\t\t\t\t\t&~covered))\n\t\t\t\t\tlist.add(i);\n\t\t\t\t\t*/\n\t\t\t}\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\n\t\t// k=list.get((int)(list.size()*random()));\n\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 shuffle(int[] is){\n\t\tRandom rand=new Random();\n\t\tfor(int i=is.length-1; i>=1; i--){\n\t\t\tint j=rand.nextInt(i+1);\n\t\t\tint t=is[i];\n\t\t\tis[i]=is[j];\n\t\t\tis[j]=t;\n\t\t}\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcandidate=new int[n];\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\tint[] candidate;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\n\t\tlong s=covered;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\ts|=(1L<<i)|g[i];\n\t\t}\n\t\tif(s!=((1L<<n)-1))\n\t\t\treturn;\n\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>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<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "/**\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class PetyaSpiders implements Runnable {\n    public static void main(String[] args) throws Exception {\n        new Thread(null, new PetyaSpiders(), \": )\", 1 << 28).start();\n    }\n\n    public void run() {\n        FastScanner sc = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n\n        N = sc.nextInt();\n        M = sc.nextInt();\n        if (N > M) {\n            int temp = N;\n            N = M;\n            M = temp;\n        }\n        // if the max is 1, then 1x1. Else, one dimension is at least 2, so\n        // our idea of sliding forward a 2xN window works\n        if (M == 1) {\n            out.println(0);\n        } else {\n            int[][][] dp = new int[M][1 << N][1 << N];\n            // N, M are at least 2. N <= 6\n            // base case: try all prev and curr masks, let next = 0\n            for (int prev = 0; prev < 1 << N; prev++) {\n                // we cannot allow the previous to have anything except for 0's.\n                // this matters for M = 2, since at the end of the dp we are\n                // doing a special case for the final column where we need to\n                // ensure both curr AND next are validly covered\n                if (prev == 0) {\n                    for (int curr = 0; curr < 1 << N; curr++) {\n                        // all of these will satisfy the nonexistent columns, of course\n                        dp[0][prev][curr] = Integer.bitCount(curr);\n                    }\n                } else {\n                    // not allowed to have nonzero previous spiders\n                    Arrays.fill(dp[0][prev], oo);\n                }\n            }\n            for (int prev = 0; prev < 1 << N; prev++) {\n                for (int curr = 0; curr < 1 << N; curr++) {\n                    if (isValid(0, prev, curr)) {\n                        dp[1][prev][curr] = Integer.bitCount(prev) + Integer.bitCount(curr);\n                    } else {\n                        dp[1][prev][curr] = oo;\n                    }\n                }\n            }\n            for (int col = 2; col <= M - 2; col++) {\n                for (int next = 0; next < 1 << N; next++) {\n                    for (int curr = 0; curr < 1 << N; curr++) {\n                        dp[col][curr][next] = oo;\n                        for (int prev = 0; prev < 1 << N; prev++) {\n                            if (dp[col - 1][prev][curr] != oo && isValid(prev, curr, next)) {\n                                dp[col][curr][next] = Math.min(dp[col][curr][next], dp[col - 1][prev][curr] + Integer.bitCount(next));\n                            }\n                        }\n                    }\n                }\n            }\n            // to get the answer, we need to act on the last column by trying to\n            // ensure that both the prev row AND the current row are valid\n            // basically, isValid(prev, curr, next) && isValid(curr, next, 0)\n            int ans = oo;\n            for (int next = 0; next < 1 << N; next++) {\n                for (int curr = 0; curr < 1 << N; curr++) {\n                    dp[M - 1][curr][next] = oo;\n                    for (int prev = 0; prev < 1 << N; prev++) {\n                        if (dp[M - 2][prev][curr] != oo && isValid(prev, curr, next) && isValid(curr, next, 0)) {\n                            dp[M - 1][curr][next] = Math.min(dp[M - 1][curr][next], dp[M - 2][prev][curr] + Integer.bitCount(next));\n                            ans = Math.min(ans, dp[M - 1][curr][next]);\n                        }\n                    }\n                }\n            }\n//            for (int c = 1; c < M; c++) {\n//                System.out.println(\"For col = \" + c);\n//                for (int prev = 0; prev < 1 << N; prev++) {\n//                    System.out.println(\"Prev = \" + Integer.toBinaryString(prev));\n//                    for (int curr = 0; curr < 1 << N; curr++) {\n//                        System.out.println(\"Curr = \" + Integer.toBinaryString(curr) + \" gives \" + dp[c][prev][curr] + \" \");\n//                    }\n//                }\n//            }\n            out.println(N * M - ans);\n        }\n        out.close();\n    }\n\n    static int N, M;\n    static int oo = 999;\n    static int[] dr = {1, 0, -1, 0}, dc = {0, 1, 0, -1};\n\n    static boolean isValid(int prev, int curr, int next) {\n        boolean[][] grid = new boolean[N][3];\n        int[] subsets = {prev, curr, next};\n        for (int r = 0; r < N; r++) {\n            for (int c = 0; c < 3; c++) {\n                if ((subsets[c] & 1) > 0) {\n                    grid[r][c] = true;\n                    for (int k = 0; k < 4; k++) {\n                        int r2 = r + dr[k];\n                        int c2 = c + dc[k];\n                        if (0 <= r2 && r2 <= N - 1 && 0 <= c2 && c2 <= 2) {\n                            grid[r2][c2] = true;\n                        }\n                    }\n                }\n                subsets[c] >>= 1;\n            }\n        }\n        for (int r = 0; r < N; r++) {\n            if (!grid[r][1]) {\n                // we only need to ensure the middle is safe\n                return false;\n            }\n        }\n        return true;\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\n    static void ASSERT(boolean assertion) {\n        if (!assertion) throw new AssertionError();\n    }\n}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n   public class x111C\n   {\n      public static void main(String omkar[]) throws Exception\n      {\n         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  \n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int R = Integer.parseInt(st.nextToken());\n         int C = Integer.parseInt(st.nextToken());\n         if(R > C)\n         {\n            int t = R;\n            R = C;\n            C = t;\n         }\n         //dp[c][m1][m2] = min spoders in first c columns\n         int[][][] dp = new int[C+1][1 << R][1 << R];\n         for(int i=0; i <= C; i++)\n            for(int mask=0; mask < (1<<R); mask++)\n               Arrays.fill(dp[i][mask], 69);\n         for(int mask=0; mask < (1<<R); mask++)\n            dp[0][0][mask] = 0;\n         for(int c=1; c <= C; c++)\n            for(int mask1=0; mask1 < (1<<R); mask1++)\n               for(int mask2=0; mask2 < (1<<R); mask2++)\n                  for(int mask3=0; mask3 < (1<<R); mask3++)\n                  {\n                     boolean works = true;\n                     for(int b=0; b < R; b++)\n                        if((mask2&(1<<b)) == 0)\n                        {\n                           if(b > 0 && (mask2&(1<<(b-1))) > 0);\n                           else if(b+1 < R && (mask2&(1<<(b+1))) > 0);\n                           else if((mask1&(1<<b)) > 0);\n                           else if((mask3&(1<<b)) > 0);\n                           else  works = false;\n                        }\n                     if(works)\n                        dp[c][mask2][mask3] = Math.min(dp[c][mask2][mask3], dp[c-1][mask1][mask2]+Integer.bitCount(mask1));\n                  }\n         int res = 0;\n         for(int mask=0; mask < (1<<R); mask++)\n            res = Math.max(res, R*C-(dp[C][mask][0]+Integer.bitCount(mask)));\n         System.out.println(res);\n      }\n   }", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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 shuffle(int[] is){\n\t\tRandom rand=new Random();\n\t\tfor(int i=is.length-1; i>=1; i--){\n\t\t\tint j=rand.nextInt(i+1);\n\t\t\tint t=is[i];\n\t\t\tis[i]=is[j];\n\t\t\tis[j]=t;\n\t\t}\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<h; y++){\n\t\t\tfor(int x=0; x<w; x++){\n\t\t\t\tfor(int k=0; k<4; k++){\n\t\t\t\t\tint x2=x+dx[k];\n\t\t\t\t\tint y2=y+dy[k];\n\t\t\t\t\tif(x2>=0&&x2<w&&y2>=0&&y2<h){\n\t\t\t\t\t\tg[y*w+x]|=1L<<(y2*w+x2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcandidate=new int[n];\n\t\txs=new Xorshift();\n\t\tmds=(1L<<n)-1;\n\t\tmds(0, 0, 0);\n\t\tprintln((n-Long.bitCount(mds))+\"\");\n\t}\n\n\tint n;\n\tlong[] g;\n\tlong mds;\n\tint[] candidate;\n\tXorshift xs;\n\n\tvoid mds(long choosed, long removed, long covered){\n\t\tif(Long.bitCount(choosed)>=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<<n)-1)){\n\t\t\tif(Long.bitCount(choosed)<Long.bitCount(mds))\n\t\t\t\tmds=choosed;\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t{\n\t\t\tlong s=covered;\n\t\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\t\ts|=(1L<<i)|g[i];\n\t\t\t}\n\t\t\tif(s!=((1L<<n)-1)){\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tint index=0;\n\t\tint k=-1;\n\t\tfor(long remained=~removed&((1L<<n)-1); remained!=0; remained&=remained-1){\n\t\t\tint i=Long.numberOfTrailingZeros(remained);\n\t\t\tif((covered>>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~covered)==1\n\t\t\t\t\t\t&&(g[i]&~covered&~removed)!=0){\n\t\t\t\t\tmds(choosed, removed|(1L<<i), covered);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(Long.bitCount(g[i]&~removed)==0){\n\t\t\t\t\tmds(choosed|(1L<<i), removed|(1L<<i), covered|(1L<<i)|g[i]);\n\t\t\t\t\treturn;\n\t\t\t\t}else if(Long.bitCount(g[i]&~removed)==1\n\t\t\t\t\t\t&&((g[i]&~removed)|(g[i]&~covered))==(g[i]&~removed)){\n\t\t\t\t\tint j=Long.numberOfTrailingZeros(g[i]&~removed);\n\t\t\t\t\tmds(choosed|(1L<<j), removed|(1L<<i)|(1L<<j), covered\n\t\t\t\t\t\t\t|(1L<<j)|g[j]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// if(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered))\n\t\t\t// k=i;\n\t\t\tif(k==-1||Long.bitCount(g[i]&~covered)>Long.bitCount(g[k]&~covered)){\n\t\t\t\tindex=0;\n\t\t\t\tcandidate[index++]=i;\n\t\t\t\tk=i;\n\t\t\t}else if(Long.bitCount(g[i]&~covered)==Long.bitCount(g[k]&~covered)){\n\t\t\t\tcandidate[index++]=i;\n\t\t\t}\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\n\t\t// k=candidate[xs.nextInt(index)];\n\n\t\tmds(choosed|(1L<<k), removed|(1L<<k), covered|(1L<<k)|g[k]);\n\t\tmds(choosed, removed|(1L<<k), covered);\n\t}\n\n\tclass Xorshift{\n\n\t\tint x, y, z, w;\n\n\t\tpublic Xorshift(){\n\t\t\tx=123456789;\n\t\t\ty=362436069;\n\t\t\tz=521288629;\n\t\t\tw=88675123;\n\t\t}\n\n\t\tpublic Xorshift(int seed){\n\t\t\tx=_(seed, 0);\n\t\t\ty=_(x, 1);\n\t\t\tz=_(y, 2);\n\t\t\tw=_(z, 3);\n\t\t}\n\n\t\tint _(int s, int i){\n\t\t\treturn 1812433253*(s^(s>>>30))+i+1;\n\t\t}\n\n\t\t// 32bit signed\n\t\tpublic int nextInt(){\n\t\t\tint t=x^(x<<11);\n\t\t\tx=y;\n\t\t\ty=z;\n\t\t\tz=w;\n\t\t\treturn w=w^(w>>>19)^t^(t>>>8);\n\t\t}\n\n\t\t// error = O(n*2^-32)\n\t\tpublic int nextInt(int n){\n\t\t\treturn (int)(n*nextDouble());\n\t\t}\n\n\t\t// [0, 1) (53bit)\n\t\tpublic double nextDouble(){\n\t\t\tint a=nextInt()>>>5, b=nextInt()>>>6;\n\t\t\treturn (a*67108864.0+b)*(1.0/(1L<<53));\n\t\t}\n\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\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\tLocale.setDefault(Locale.US);\n\t\tnew P111C().run();\n\t}\n\n}\n", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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(), m = iread();\n\t\tint INF = -1;\n\t\tif (m > n) {\n\t\t\tint t = m;\n\t\t\tm = n;\n\t\t\tn = t;\n\t\t}\n\t\tint[][][] d = new int[2][1 << m][1 << m];\n\t\tfor (int i = 0; i < 1 << m; i++)\n\t\t\tArrays.fill(d[0][i], INF);\n\n\t\tint[] cnt = new int[1 << m];\n\t\tfor (int i = 0; i < 1 << m; i++)\n\t\t\tcnt[i] = cnt[i / 2] + i % 2;\n\n\t\tint step = 0;\n\t\td[0][0][0] = 0;\n\t\tfor (int u = 0; u < n; u++) {\n\t\t\tfor (int i = 0; i < 1 << m; i++)\n\t\t\t\tArrays.fill(d[step ^ 1][i], INF);\n\t\t\tfor (int mask1 = 0; mask1 < 1 << m; mask1++)\n\t\t\t\tfor (int mask2 = 0; mask2 < 1 << m; mask2++) {\n\t\t\t\t\tint t = d[step][mask1][mask2];\n\t\t\t\t\tif (t == INF)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int mask = 0; mask < 1 << m; mask++) {\n\t\t\t\t\t\tif ((mask1 & mask) != mask1)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tint mask01 = ((1 << m) - 1) & ~mask2;\n\n\t\t\t\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\t\t\t\tif ((mask & (1 << j)) != 0) {\n\t\t\t\t\t\t\t\tif (j > 0)\n\t\t\t\t\t\t\t\t\tmask01 &= ~(1 << (j - 1));\n\t\t\t\t\t\t\t\tmask01 &= ~(1 << j);\n\t\t\t\t\t\t\t\tif (j + 1 < m)\n\t\t\t\t\t\t\t\t\tmask01 &= ~(1 << (j + 1));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tint mask02 = mask;\n\n\t\t\t\t\t\tint t2 = t + cnt[((1 << m) - 1) & ~mask];\n\t\t\t\t\t\tif (d[step ^ 1][mask01][mask02] < t2) {\n\t\t\t\t\t\t\td[step ^ 1][mask01][mask02] = t2;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tstep ^= 1;\n\t\t}\n\t\tint ans = INF;\n\t\tfor (int mask = 0; mask < 1 << m; mask++) {\n\t\t\tans = Math.max(ans, d[step][0][mask]);\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}", "complexity": "np", "problem": "111_C. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdC {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n    static char[][] grid;\n    static int n;\n    static int t;\n    static int[][] dp;\n    static int[] times;\n    static int[] genre;\n\tpublic static void main(String[] omkar) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\tn = sc.nextInt();\n \t\tt = sc.nextInt();\n \t\ttimes = new int[n];\n \t\tgenre = new int[n];\n \t\tfor(int j =0 ;j<n;j++){\n \t\t\ttimes[j] = sc.nextInt();\n \t\t\tgenre[j] = sc.nextInt();\t\t\n \t\t}\n \t\tdp = new int[1<<n][4];\n \t\tfor(int j = 0;j<1<<n;j++)\n \t\t\tArrays.fill(dp[j],  -1);\n \t\tint ans = 0;\n \t\tfor(int j=0;j<1<<n;j++){\n \t\t\tint time = 0;\n \t\t\tfor(int k = 0;k<n;k++){\n \t\t\t\tif (((1<<k) & j) != 0){\n \t\t\t\t\ttime+=times[k];\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (time == t){\n \t\t\t\tletsgodp(j, 1);\n \t\t\t\tletsgodp(j, 2);\n \t\t\t\tletsgodp(j, 3);\n \t\t\t\tans+=dp[j][1];\n \t\t\t\tans%=mod;\n \t\t\t\tans+=dp[j][2];\n \t\t\t\tans%=mod;\n \t\t\t\tans+=dp[j][3];\n \t\t\t\tans%=mod;\n \t\t\t}\n \t\t}\n \t\tout.println(ans);\n \t\tout.close();\t\n \t}\n\tpublic static void letsgodp(int mask, int dg){\n\t\tif (dp[mask][dg] != -1)\n\t\t\treturn;\n\t\tdp[mask][dg] = 0;\n\t\tfor(int j = 0;j<n;j++){\n\t\t\tif (((1<<j) & mask) != 0 && genre[j] == dg){\n\t\t\t\tint submask = mask - (1<<j);\n\t\t\t\tint og1 = genre[j]+1 > 3 ? genre[j]-2 : genre[j]+1;\n\t\t\t\tint og2 = genre[j]+2 > 3 ? genre[j]-1 : genre[j]+2;\n\t\t\t\tif (submask != 0){\n\t\t\t\t\tletsgodp(submask, og1);\n\t\t\t\t\tletsgodp(submask, og2);\n\t\t\t\t\tdp[mask][dg] +=(dp[submask][og1] + dp[submask][og2]);\n\t\t\t\t\tdp[mask][dg] %=mod;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tdp[mask][dg] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<Integer>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "/**\n * BaZ :D\n */\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class ACMIND\n{\n    static FastReader 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<<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 int n, g[], t[], T;\n    static int dp[][];\n    static void solve() throws IOException\n    {\n        scan = new FastReader();\n        pw = new PrintWriter(System.out,true);\n        StringBuilder fast = new StringBuilder();\n        n = ni();\n        T = ni();\n        g = new int[n];\n        t = new int[n];\n        for(int i=0;i<n;++i) {\n            t[i] = ni();\n            g[i] = ni();\n        }\n        int MAX = (1<<n);\n        dp = new int[MAX][4];\n        for(int i=0;i<MAX;++i) {\n            for(int j=0;j<4;++j) {\n                dp[i][j] = -1;\n            }\n        }\n        pl(f((1<<n)-1,0));\n        pw.flush();\n        pw.close();\n    }\n\n    static int f(int mask, int prev) {\n        if(dp[mask][prev]!=-1) {\n            return dp[mask][prev];\n        }\n        int left = T;\n        for(int i=0;i<n;++i) {\n            if((mask&(1<<i))==0) {\n                left-=t[i];\n            }\n        }\n        if(left==0) {\n            return 1;\n        }\n        int cnt = 0;\n        for(int i=0;i<n;++i) {\n            if((mask&(1<<i))!=0) {\n                if(g[i]!=prev && left>=t[i]) {\n                    cnt+=f(mask^(1<<i), g[i]);\n                    if(cnt>=MOD) {\n                        cnt-=MOD;\n                    }\n                }\n            }\n        }\n        return dp[mask][prev] = cnt;\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class FastReader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        public FastReader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public FastReader(String file_name) throws IOException {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[1000000];\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}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class G1 {\n    static int n, T, duration[], type[];\n    static long dp[][][], mod = (long) 1e9 + 7;\n\n    public static void main(String[] args) throws Exception {\n        new Thread(null, new Runnable() {\n            public void run() {\n                try {\n                    solveIt();\n                } catch (Exception e) {\n                    e.printStackTrace();\n                    System.exit(1);\n                }\n            }\n        }, \"Main\", 1 << 28).start();\n    }\n\n    public static void solveIt() throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        T = in.nextInt();\n        dp = new long[3][T + 1][1 << n];\n        duration = new int[n];\n        type = new int[n];\n        for (int i = 0; i < n; i++) {\n            duration[i] = in.nextInt();\n            type[i] = in.nextInt() - 1;\n        }\n        for (long a[][] : dp) for (long b[] : a) Arrays.fill(b, -1);\n        pw.println(solve(0, T, 0));\n\n        pw.close();\n    }\n\n    static long solve(int lastType, int rem, int mask) {\n        if (rem == 0) return 1;\n        if (rem < 0) return 0;\n        if (dp[lastType][rem][mask] != -1) return dp[lastType][rem][mask];\n        long res = 0;\n        for (int i = 0; i < n; i++) {\n            if (!check(mask, i) && (lastType != type[i] || mask == 0) && rem - duration[i] >= 0) {\n                res += solve(type[i], rem - duration[i], set(mask, i));\n                if (res >= mod) res -= mod;\n            }\n        }\n        return dp[lastType][rem][mask] = res;\n    }\n\n    static boolean check(int N, int pos) {\n        return (N & (1 << pos)) != 0;\n    }\n\n    static int set(int N, int pos) {\n        return N = N | (1 << pos);\n    }\n\n    static int reset(int N, int pos) {\n        return N = N & ~(1 << pos);\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayDeque;\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.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n@SuppressWarnings(\"unused\")\npublic class Solution{\n\t\n\tstatic long inf = (long)1e18+100;\n\tstatic final long mod = (long)1e9+7;\n\t\n\t@SuppressWarnings(\"unchecked\")\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner fs = new FastScanner();\n    \tPrintWriter out = new PrintWriter(System.out);\n    \t\n    \tint tt = 1;\n    \touter:\n    \twhile(tt-->0) {\n    \t\t\n    \t\tint n = fs.nextInt(), T = fs.nextInt();\n    \t\tint[] t = new int[n], g = new int[n];\n    \t\t\n    \t\tfor(int i=0;i<n;i++) {\n    \t\t\tt[i] = fs.nextInt(); g[i] = fs.nextInt();\n    \t\t}\n    \t\t\n    \t\t//dp[mask][pre] -- number of ways to order mask songs last song has prev genre\n    \t\tlong[][] dp = new long[1<<n][4];\n    \t\tdp[0][0] = 1;\n    \t\t\n    \t\tlong ans = 0;\n    \t\t\n    \t\tfor(int mask=0;mask<(1<<n);mask++) {\n    \t\t\tfor(int pre=0;pre<=3;pre++) {\n    \t\t\t\tfor(int i=0;i<n;i++)\n    \t\t\t\t\tif((mask&(1<<i))==0 && g[i]!=pre) \n    \t\t\t\t\t\tdp[mask^(1<<i)][g[i]] = add(dp[mask^(1<<i)][g[i]], dp[mask][pre]);\n    \t\t\t\tint sum = 0;\n    \t\t\t\tfor(int i=0;i<n;i++) {\n    \t\t\t\t\tif((mask&(1<<i))!=0) sum += t[i];\n    \t\t\t\t}\n    \t\t\t\tif(sum==T) ans = add(ans, dp[mask][pre]);\n    \t\t\t}\n    \t\t}\n    \t\t\n    \t\tout.println(ans);\n    \t\t\n    \t\t\n    \t\t\n    \t\t\n    \t\t\n    \t\t\n    \t}\n    \t\n    \tout.close();\n    }\n\t\n\tstatic long add(long a, long b) {\n\t\ta += b;\n\t\tif(a>mod) return a - mod;\n\t\treturn a;\n\t}\n\t\n\t\n    static final Random random=new Random();\n    \n    static <T> void shuffle(T[] arr) {\n    \tint n = arr.length;\n    \tfor(int i=0;i<n;i++\t) {\n    \t\tint k = random.nextInt(n);\n    \t\tT temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;\n    \t}\n    }\n    \n    \t\n    static void ruffleSort(int[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); int temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n    \n    static void ruffleSort(long[] a) {\n    \tint n=a.length;//shuffle, then sort \n    \tfor (int i=0; i<n; i++) {\n    \t\tint oi=random.nextInt(n); long temp=a[oi];\n    \t\ta[oi]=a[i]; a[i]=temp;\n    \t}\n    \tArrays.sort(a);\n    }\n   \n  \n    \n    static void reverse(int[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tint temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    static void reverse(long[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++){\n    \t\tlong temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \n    \n    static <T> void reverse(T[] arr, int l, int r) {\n    \tfor(int i=l;i<l+(r-l)/2;i++) {\n    \t\tT temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;\n    \t}\n    }\n    \t\n    \t\n    static class FastScanner{\n    \tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    \tStringTokenizer st = new StringTokenizer(\"\");\n     \n    \tpublic String next(){\n    \t\twhile(!st.hasMoreElements()){\n    \t\t\ttry{\n    \t\t\t\tst = new StringTokenizer(br.readLine());\n    \t\t\t} catch(IOException e){\n    \t\t\t\te.printStackTrace();\n    \t\t\t}\n    \t\t}\n    \t\treturn st.nextToken();\n    \t}\n    \t\t\n    \tpublic String nextLine() throws IOException {\n    \t\treturn br.readLine();\n    \t}\n    \t\t\n    \tpublic int nextInt(){\n    \t\treturn Integer.parseInt(next());\n    \t}\n     \n    \tpublic int[] readArray(int n){\n    \t\tint[] a = new int[n];\n    \t\tfor(int i=0;i<n;i++)\n    \t\t\ta[i] = nextInt();\n    \t\treturn a;\n    \t}\n    \t\t\n    \tpublic long nextLong() {\n    \t\treturn Long.parseLong(next());\n    \t}\n    \t\t\n    \tpublic char nextChar() {\n    \t\treturn next().toCharArray()[0];\n    \t}\n    }\n\n\n   \t\n}\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int(),k=Int();\n            int A[][]=new int[n][2];\n            for(int i=0;i<n;i++){\n                A[i][0]=Int();\n                A[i][1]=Int();\n            }\n\n            Solution sol=new Solution(out);\n            sol.solution(A,k);\n        }\n        out.close();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n\n    long dp[][];\n    int mod=1000000007;\n    int time;\n    public void solution(int A[][],int t){\n        this.time=t;\n        dp=new long[4][1<<A.length+2];\n        for(int i=0;i<dp.length;i++){\n            Arrays.fill(dp[i],-1);\n        }\n\n        long a=dfs(A,0,(1<<A.length)-1);\n        out.println(a);\n    }\n\n    public long dfs(int A[][],int pre,int state){\n        int use=cal(A,state);\n        if(time-use==0){\n            return 1;\n        }\n        if(time<use||state==0){\n            return 0;\n        }\n\n        if(dp[pre][state]!=-1)return dp[pre][state];\n\n        long res=0;\n\n        for(int i=0;i<A.length;i++){\n            if(((state&(1<<i))!=0)&&A[i][1]!=pre){\n                res+=dfs(A,A[i][1],(state^(1<<i)));\n                res%=mod;\n            }\n        }\n\n        dp[pre][state]=res;\n        return res;\n    }\n\n    public int cal(int A[][],int state){\n        int t=0;\n        for(int i=0;i<A.length;i++){\n            if((state&(1<<i))==0){\n                t+=A[i][0];\n            }\n        }\n        return 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            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class q5 {\n\tstatic NoD[] arr;\n\tstatic int index,count,zc;\n\tstatic ArrayList<NoD> pos,neg;\n\tstatic long[][][][] dp;\n\t\n\tstatic long solve(int a,int b, int c,int d, long mod) {\n\t\tlong[][][][] a2=dp;\n\t\tint p=-1;\n\t\tif(a==0 && b==0 && c==0) return 1;\n\t\tif(dp[a][b][c][d]!=-1) return dp[a][b][c][d];\n\t\tlong tr=0;\n\t\tif(a>0 && d!=1) {\n\t\t\ttr=+a*solve(a-1,b,c,1,mod);\n\t\t\ttr%=mod;\n\t\t}\n\t\tif(b >0 && d!=2) {\n\t\t\ttr+=b*solve(a,b-1,c,2,mod);\n\t\t\ttr%=mod;\n\t\t}\n\t\tif(c>0 && d!=3) {\n\t\t\ttr+=c*solve(a,b,c-1,3,mod);\n\t\t\ttr%=mod;\n\t\t}\n\t\ttr%=mod;\n\t\treturn dp[a][b][c][d]=tr;\n\t\t\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tReader.init(System.in);\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tint n=Reader.nextInt(),t=Reader.nextInt();\n\t\tlong mod=(long)1e9+7,fact[]=new long[16];\n\t\tdp=new long[16][16][16][4];\n\t\tfor(int i=0;i<16;i++) {\n\t\t\tfor(int j=0;j<16;j++) {\n\t\t\t\tfor(int k=0;k<16;k++)\n\t\t\t\tArrays.fill(dp[i][j][k], -1);\n\t\t\t}\n\t\t}\n\t\tfact[0]=1;\n\t\tfor(int i=1;i<=15;i++) {\n\t\t\tfact[i]=i*fact[i-1];\n\t\t\tfact[i]%=mod;\n\t\t}\n\t\tNoD[] arr=new NoD[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint a=Reader.nextInt(),b=Reader.nextInt();\n\t\t\tarr[i]=new NoD(a,b);\n\t\t\t\n\t\t}\n\t\tlong ans=0;\n\t\tfor(int i=0;i<(1<<n);i++) {\n\t\t\tint time=0;\n\t\t\tint prev=-1;\n\t\t\tint t1=0,t2=0,t3=0;\n\t\t\tlong[] c= {i};\n\t\t\tBitSet b=BitSet.valueOf(c);\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tif(b.get(j)) {\n\t\t\t\t\ttime+=arr[j].val;\n\t\t\t\t\t\tprev=arr[j].index;\n\t\t\t\t\t\tif(arr[j].index==1) t1++;\n\t\t\t\t\t\telse if(arr[j].index==2) t2++;\n\t\t\t\t\t\telse t3++;\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(time==t) {\n\t\t\t\tlong v=1;\n\t\t\t\tlong v2=1;\n\t\t\t\tv*=solve(t1,t2,t3,0,mod);\n\t\t\t\tv%=mod;\n\t\t\t\tans+=v;\n\t\t\t\tans%=mod;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tout.flush();\n\t\t\n\t}\n}\n\nclass NoD{\n\tint val, index;\n\tNoD(int v,int i){\n\t\tval=v;index=i;\n\t}\n}\n\nclass Pair{\n\tNoD a, b;\n\tPair(NoD aa,NoD bb){\n\t\ta=aa;b=bb;\n\t}\n}\n\n\nclass Reader {\n    static BufferedReader reader;\n    static StringTokenizer tokenizer;\n    /** call this method to initialize reader for InputStream */\n    static void init(InputStream input) {\n        reader = new BufferedReader(\n                     new InputStreamReader(input) );\n        tokenizer = new StringTokenizer(\"\");\n    }\n    /** get next word */\n    static String nextLine() throws IOException{\n    \treturn reader.readLine();\n    }\n    static String next() throws IOException {\n        while ( ! tokenizer.hasMoreTokens() ) {\n            //TODO add check for eof if necessary\n            tokenizer = new StringTokenizer(\n                   reader.readLine() );\n        }\n        return tokenizer.nextToken();\n    }\n    static int nextInt() throws IOException {\n        return Integer.parseInt( next() );\n    }\n    static long nextLong() throws IOException {\n        return Long.parseLong( next() );\n    }\n    static double nextDouble() throws IOException {\n        return Double.parseDouble( next() );\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class G {\n    static int n,t;\n    static int[]a;\n    static int[]g;\n    static long[][][]dp;\n    static final long MOD=1000000007;\n    public static void main(String[]args){\n        Scanner sc=new Scanner(System.in);\n        n=sc.nextInt();\n        t=sc.nextInt();\n        a=new int[n];\n        g=new int[n];\n        for(int i=0;i<n;i++) {\n            a[i] = sc.nextInt();\n            g[i] = sc.nextInt();\n        }\n        dp=new long[4][1<<(n-1)+1][t+1];\n        for(int i=0;i<4;i++)\n            for(int j=0;j<1<<(n-1)+1;j++)\n                for(int k=0;k<=t;k++)\n                    dp[i][j][k]=-1;\n        System.out.println(dp(0,0,t));\n    }\n    private static long dp(int genre,int mask,int time){\n        if(time<0)\n            return 0;\n        if(dp[genre][mask][time]!=-1)\n            return dp[genre][mask][time];\n        if(time==0)\n            return 1;\n        dp[genre][mask][time]=0;\n        for(int i=0;i<n;i++) {\n            if (g[i] != genre && ((1 << i) & mask) == 0)\n                dp[genre][mask][time] = (dp[genre][mask][time]+dp(g[i], mask | (1 << i), time - a[i]))%MOD;\n        }\n        return dp[genre][mask][time];\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n/**\n *\n * @author Dstoical\n */\n\npublic class G {\n\n\tprivate static int M = 1000000007, MM = 998244353;\n\tprivate static int N = 15,n,T;\n\tprivate static int[] time,gi;\n\tprivate static int[][][] dp;\n\n\tpublic static void process() throws IOException {\n\n\t\tn = sc.nextInt();T = sc.nextInt();\n\t\ttime = new int[n+1];\n\t\tgi = new int[n+1];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tint a = sc.nextInt(),b = sc.nextInt();\n\t\t\ttime[i] = a;\n\t\t\tgi[i] = b-1;\n\t\t}\n\t\t\n\t\tdp = new int[1<<n][T+1][3];\n\t\tfor(int i=0; i<1<<n; i++) {\n\t\t\tfor(int j=0; j<T+1; j++) {\n\t\t\t\tfor(int k=0; k<3; k++)dp[i][j][k] = -1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tif(time[i] <= T) {\n\t\t\t\tans = (ans + solve(1<<i,time[i],gi[i]))%M;\n\t\t\t}\n\t\t}\n\t\tprintln(ans);\n\t}\n\n\tprivate static int solve(int mask, int tim, int code) {\n\t\tif(tim == T)return 1;\n\t\tif(dp[mask][tim][code] != -1)return dp[mask][tim][code];\n\t\tint ans = 0;\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tif((mask>>i & 1) > 0)continue;\n\t\t\tif(code == gi[i])continue;\n\t\t\tif(tim + time[i] > T)continue;\n\t\t\tans = (ans + solve(mask|(1<<i), time[i]+tim, gi[i]))%M;\n\t\t\t\n\t\t}\n\t\treturn dp[mask][tim][code] = (ans%M);\n\t}\n\n\t//=============================================================================\n\t//--------------------------The End---------------------------------\n\t//=============================================================================\n\n\tstatic FastScanner sc;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tboolean oj = true;\n\t\tif (oj) {\n\t\t\tsc = new FastScanner();\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tsc = new FastScanner(100);\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t\tint t = 1;\n//\t\tt = sc.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tprocess();\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint x, y;\n\n\t\tPair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn Integer.compare(this.x, o.x);\n\t\t}\n\t}\n\n\t/////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic void println(Object o) {\n\t\tout.println(o);\n\t}\n\n\tstatic void println() {\n\t\tout.println();\n\t}\n\n\tstatic void print(Object o) {\n\t\tout.print(o);\n\t}\n\n\tstatic void pflush(Object o) {\n\t\tout.println(o);\n\t\tout.flush();\n\t}\n\n\tstatic int ceil(int x, int y) {\n\t\treturn (x % y == 0 ? x / y : (x / y + 1));\n\t}\n\n\tstatic long ceil(long x, long y) {\n\t\treturn (x % y == 0 ? x / y : (x / y + 1));\n\t}\n\n\tstatic int max(int x, int y) {\n\t\treturn Math.max(x, y);\n\t}\n\n\tstatic int min(int x, int y) {\n\t\treturn Math.min(x, y);\n\t}\n\n\tstatic int abs(int x) {\n\t\treturn Math.abs(x);\n\t}\n\n\tstatic long abs(long x) {\n\t\treturn Math.abs(x);\n\t}\n\n\tstatic int log2(int N) {\n\t\tint result = (int) (Math.log(N) / Math.log(2));\n\t\treturn result;\n\t}\n\n\tstatic long max(long x, long y) {\n\t\treturn Math.max(x, y);\n\t}\n\n\tstatic long min(long x, long y) {\n\t\treturn Math.min(x, y);\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.intValue();\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.longValue();\n\t}\n\n\t/////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner() throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tFastScanner(int a) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t}\n\n\t\tString next() throws IOException {\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() 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\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[] readArray(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] = sc.nextInt();\n\t\t\t}\n\t\t\treturn A;\n\t\t}\n\n\t\tlong[] readArrayLong(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] = sc.nextLong();\n\t\t\t}\n\t\t\treturn A;\n\t\t}\n\t}\n\n\tstatic void ruffleSort(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\tArrays.sort(a);\n\t}\n\n\tstatic void ruffleSort(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\tArrays.sort(a);\n\t}\n}\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main\n{\n\tstatic final int MOD = (int)1e9 + 7;\n\tstatic int n;\n\tstatic int[] t;\n\tstatic int[] g;\t\n\tstatic int[][] memo;\n\t\n\tstatic int dp(int mask, int rem, int last)\n\t{\n\t\tif(rem == 0)\n\t\t\treturn 1;\n\t\tif(memo[last][mask] != -1)\n\t\t\treturn memo[last][mask];\n\t\t\n\t\tint ans = 0;\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tif((mask & (1 << i)) == 0 && rem >= t[i] && g[i] != last)\n\t\t\t\tans += dp(mask | 1 << i, rem - t[i], g[i]);\n\t\t\t\n\t\t\tif(ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\t\n\t\treturn memo[last][mask] = ans;\n\t}\n\t\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\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\tn = in.nextInt();\n\t\tint T = in.nextInt();\n\t\t\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tt[i] = in.nextInt();\n\t\t\tg[i] = in.nextInt() - 1;\n\t\t}\n\t\t\n\t\tmemo = new int[4][1 << n];\n\t\tfor(int []x : memo)\n\t\t{\n\t\t\tArrays.fill(x, -1);\n\t\t}\n\t\t\n\t\tout.println(dp(0, T, 3));\n\t\tout.close();\n\t}\n\t\n\tstatic class InputReader\n\t{\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\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{\n\t\t\twhile(tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t}\n\t\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\t\t\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "// 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\tint x0 = ma > 0 ? (int) ((long) dq[ma - 1][mb][mc][0] * ma % MD) : 0;\n\t\t\t\t\t\tint x1 = mb > 0 ? (int) ((long) dq[ma][mb - 1][mc][1] * mb % MD) : 0;\n\t\t\t\t\t\tint x2 = mc > 0 ? (int) ((long) dq[ma][mb][mc - 1][2] * mc % MD) : 0;\n\t\t\t\t\t\tdp[ma][mb][mc] = (int) (((long) x0 + x1 + x2) % MD);\n\t\t\t\t\t\tdq[ma][mb][mc][0] = (x1 + x2) % MD;\n\t\t\t\t\t\tdq[ma][mb][mc][1] = (x2 + x0) % MD;\n\t\t\t\t\t\tdq[ma][mb][mc][2] = (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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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 Jeel Vaishnav\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 void solve(int testNumber, InputReader sc, PrintWriter out) {\n            int n = sc.nextInt();\n            int T = sc.nextInt();\n\n            int mod = (int) 1e9 + 7;\n\n            int dp[][][] = new int[1 << n][226][3];\n\n            int t[] = new int[n];\n            int g[] = new int[n];\n            for (int i = 0; i < n; ++i) {\n                t[i] = sc.nextInt();\n                g[i] = sc.nextInt() - 1;\n                dp[1 << i][t[i]][g[i]] = 1;\n            }\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                        int newMask = i ^ (1 << j);\n\n                        for (int k = t[j]; k <= T; ++k) {\n                            for (int l = 0; l < 3; ++l) {\n                                if (l == g[j])\n                                    continue;\n\n                                dp[i][k][g[j]] = (dp[i][k][g[j]] + dp[newMask][k - t[j]][l]) % mod;\n                            }\n                        }\n                    }\n                }\n            }\n\n            long ans = 0;\n            for (int i = 0; i < (1 << n); ++i) {\n                for (int j = 0; j < 3; ++j) {\n                    ans += dp[i][T][j];\n                }\n            }\n\n            ans %= mod;\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\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 boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int();\n            int k=Int();\n            int A[][]=new int[n][2];\n            int a=0,b=0,c=0;\n            for(int i=0;i<A.length;i++){\n                A[i][0]=Int();\n                A[i][1]=Int()-1;\n\n                if(A[i][1]==0)a++;\n                else if(A[i][1]==1)b++;\n                else c++;\n            }\n\n            Arrays.sort(A,(x,y)->{\n                return x[0]-y[0];\n            });\n\n\n            Solution sol=new Solution(out);\n            sol.solution(A,k,a,b,c);\n        }\n        out.close();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n\n    int mod=1000000007;\n    long dp3[][][][];\n    public void solution(int A[][],int T,int x,int y,int z){\n        long res=0;\n        int n=A.length;\n        long dp1[][]=new long[x+2][T+1];//a\n        long dp2[][][]=new long[y+2][z+2][T+2];//bc\n        dp3=new long[x+2][y+2][z+2][3];\n\n\n        //init\n        long f[]=new long[n+10];\n        f[0]=f[1]=1;\n        for(int i=2;i<f.length;i++){\n            f[i]=f[i-1]*i;\n            f[i]%=mod;\n        }\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    Arrays.fill(dp3[i][j][k],-1);\n                }\n            }\n        }\n\n\n        dp1[0][0]=1;\n        for(int i=0;i<A.length;i++){//a\n            int p=A[i][0],type=A[i][1];\n            if(type==0){\n                long newdp[][]=new long[dp1.length][dp1[0].length];\n                for(int cnt=1;cnt<=x;cnt++){\n                    for(int j=1;j<dp1[0].length;j++){\n                        if(j>=p){\n                            newdp[cnt][j]+=dp1[cnt-1][j-p];\n                            newdp[cnt][j]%=mod;\n                        }\n                    }\n                }\n\n                for(int cnt=0;cnt<=x;cnt++){\n                    for(int j=0;j<dp1[0].length;j++){\n                        newdp[cnt][j]+=dp1[cnt][j];\n                        newdp[cnt][j]%=mod;\n                    }\n                }\n                dp1=newdp;\n            }\n        }\n\n\n\n\n\n        dp2[0][0][0]=1;\n        for(int i=0;i<A.length;i++){//b c\n            int p=A[i][0],type=A[i][1];\n            if(type!=0){\n                long newdp[][][]=new long[dp2.length][dp2[0].length][dp2[0][0].length];\n                for(int a=0;a<dp2.length;a++){\n                    for(int b=0;b<dp2[0].length;b++){\n                        for(int j=0;j<dp2[0][0].length;j++){\n                            if(j>=p){\n                                if(type==1){\n                                    if(a-1>=0){\n                                        newdp[a][b][j]+=dp2[a-1][b][j-p];\n                                    }\n                                }\n                                else{\n                                    if(b-1>=0) {\n                                        newdp[a][b][j]+=dp2[a][b-1][j-p];\n                                    }\n                                }\n                            }\n                            newdp[a][b][j]%=mod;\n                        }\n                    }\n                }\n\n                for(int a=0;a<dp2.length;a++){\n                    for(int b=0;b<dp2[0].length;b++){\n                        for(int j=0;j<dp2[0][0].length;j++){\n                            newdp[a][b][j]+=dp2[a][b][j];\n                            newdp[a][b][j]%=mod;\n                        }\n                    }\n                }\n                dp2=newdp;\n            }\n        }\n\n\n        dp3[1][0][0][0]=1;\n        dp3[0][1][0][1]=1;\n        dp3[0][0][1][2]=1;\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    for(x=0;x<dp3[0][0][0].length;x++){\n                        if(dp3[i][j][k][x]==-1){\n                            dfs(i,j,k,x);\n                        }\n                    }\n                }\n            }\n        }\n\n\n\n\n\n\n\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    for(int cur=0;cur<3;cur++){\n                        for(int t=0;t<=T;t++){//price\n                            int aprice=t;\n                            int bcprice=T-t;\n                            long cnt1=dp1[i][aprice];\n                            long cnt2=dp2[j][k][bcprice];\n                            long combination=dp3[i][j][k][cur];\n                            ///if(combination==-1)combination=0;\n                            long p1=(cnt1*f[i])%mod;\n                            long p2=(((f[j]*f[k])%mod)*cnt2)%mod;\n                            long p3=(p1*p2)%mod;\n                            res+=(p3*combination)%mod;\n                            res%=mod;\n\n                        }\n                    }\n                }\n            }\n        }\n\n        //System.out.println(dp2[1][0][2]+\"   \"+dp3[1][1][0][0]);\n\n       // for(long p[]:dp1){\n           // System.out.println(Arrays.toString(p));\n        //}\n\n\n\n        out.println(res);\n\n    }\n\n    public long dfs(int a,int b,int c,int cur){\n        if(a<0||b<0||c<0){\n            return 0;\n        }\n        if(a==0&&b==0&&c==0){\n            return 0;\n        }\n\n        if(dp3[a][b][c][cur]!=-1)return dp3[a][b][c][cur];\n\n        long res=0;\n        if(cur==0){\n            res+=dfs(a-1,b,c,1);\n            res%=mod;\n            res+=dfs(a-1,b,c,2);\n            res%=mod;\n\n        }\n        else if(cur==1){\n            res+=dfs(a,b-1,c,0);\n            res%=mod;\n            res+=dfs(a,b-1,c,2);\n            res%=mod;\n        }\n        else{\n            res+=dfs(a,b,c-1,0);\n            res%=mod;\n            res+=dfs(a,b,c-1,1);\n            res%=mod;\n        }\n        res%=mod;\n        dp3[a][b][c][cur]=res;\n        return res;\n    }\n\n}\n\n\n\n\n\n\n\n\n\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n/*\n5 3\n1 1\n2 1\n2 1\n2 1\n2 2\n */", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class G extends PrintWriter {\n\n    void run() {\n        long mod = 1_000_000_000 + 7;\n        int n = nextInt();\n        int m = nextInt();\n\n        int[] t = new int[n];\n        int[] g = new int[n];\n\n        for (int i = 0; i < n; i++) {\n            t[i] = nextInt();\n            g[i] = nextInt() - 1;\n        }\n\n        int k = 1 << n;\n\n        long[][] dp = new long[k][n];\n\n        for (int i = 0; i < n; i++) {\n            dp[1 << i][i] = 1;\n        }\n\n        for (int mask = 0; mask < k; mask++) {\n            if (Integer.bitCount(mask) <= 1) {\n                continue;\n            }\n\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 || g[i] == g[j]) {\n                            continue;\n                        }\n                        dp[mask][i] = (dp[mask][i] + dp[mask ^ (1 << i)][j]) % mod;\n                    }\n                }\n            }\n        }\n\n        long ans = 0;\n        for (int mask = 0; mask < k; mask++) {\n            int sum = 0;\n            for (int i = 0; i < n; i++) {\n                if ((mask & (1 << i)) != 0) {\n                    sum += t[i];\n                }\n            }\n            if (sum == m) {\n\n                for (int i = 0; i < n; i++) {\n                    if ((mask & (1 << i)) != 0) {\n                        ans = (ans + dp[mask][i]) % mod;\n                    }\n                }\n\n            }\n\n        }\n\n        println(ans);\n\n    }\n\n    boolean skip() {\n        while (hasNext()) {\n            next();\n        }\n        return true;\n    }\n\n    int[][] nextMatrix(int n, int m) {\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] = nextInt();\n        return matrix;\n    }\n\n    String next() {\n        while (!tokenizer.hasMoreTokens())\n            tokenizer = new StringTokenizer(nextLine());\n        return tokenizer.nextToken();\n    }\n\n    boolean hasNext() {\n        while (!tokenizer.hasMoreTokens()) {\n            String line = nextLine();\n            if (line == null) {\n                return false;\n            }\n            tokenizer = new StringTokenizer(line);\n        }\n        return true;\n    }\n\n    int[] nextArray(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    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    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 reader.readLine();\n        } catch (IOException err) {\n            return null;\n        }\n    }\n\n    public G(OutputStream outputStream) {\n        super(outputStream);\n    }\n\n    static BufferedReader reader;\n    static StringTokenizer tokenizer = new StringTokenizer(\"\");\n    static Random rnd = new Random();\n    static boolean OJ;\n\n    public static void main(String[] args) throws IOException {\n        OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n        G solution = new G(System.out);\n        if (OJ) {\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            solution.run();\n        } else {\n            reader = new BufferedReader(new FileReader(new File(G.class.getName() + \".txt\")));\n            long timeout = System.currentTimeMillis();\n            while (solution.hasNext()) {\n                solution.run();\n                solution.println();\n                solution.println(\"----------------------------------\");\n            }\n            solution.println(\"time: \" + (System.currentTimeMillis() - timeout));\n        }\n        solution.close();\n        reader.close();\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.NoSuchElementException;\n\npublic class Main {\n    private static FastScanner sc = new FastScanner();\n    private static long mod = 1000000007;\n\n    public static void main(String[] args) {\n    \tint n = sc.nextInt();\n    \tint T = sc.nextInt();\n    \tint[] t = new int[n];\n    \tint[] g = new int[n];\n    \tfor(int i=0; i<n; i++) {\n    \t\tt[i] = sc.nextInt();\n    \t\tg[i] = sc.nextInt() - 1;\n    \t}\n    \tlong[][][] dp = new long[T+1][3][1 << 15];\n    \tfor(int i=1; i<=T; i++) {\n    \t\tfor(int j=0; j<n; j++) {\n    \t\t\tif(i - t[j] == 0) {\n    \t\t\t\tdp[i][g[j]][1 << j] = (dp[i][g[j]][1 << j] + 1) % mod;\n    \t\t\t} else if(i - t[j] > 0) {\n    \t\t\t\tfor(int k=0; k<(1 << 15); k++) {\n    \t\t\t\t\tif((k >> j & 1) == 1) {\n    \t\t\t\t\t\tcontinue;\n    \t\t\t\t\t}\n    \t\t\t\t\tdp[i][g[j]][k + (1 << j)] = (dp[i][g[j]][k + (1 << j)] + dp[i - t[j]][(g[j] + 1) % 3][k] + dp[i - t[j]][(g[j] + 2) % 3][k]) % mod;\n    \t\t\t\t}\n    \t\t\t}\n    \t\t}\n    \t}\n    \tlong ans = 0;\n    \tfor(int j=0; j<3; j++) {\n    \t\tfor(int k=0; k<(1 << 15); k++) {\n    \t\t\tans = (ans + dp[T][j][k]) % mod;\n    \t\t}\n    \t}\n    \tSystem.out.println(ans);\n    }\n\n    static long power(long m , long n){\n    \tif(n == 0) {\n    \t\treturn 1;\n    \t}else if(n == 1){\n            return m;\n        }else if(n % 2 == 0){\n            long s = power(m, n/2);\n            return ( (s % mod) * (s % mod) ) % mod;\n        }else{\n            return ( (m % mod) * (power(m, n-1) % mod) ) % mod;\n        }\n    }\n\n    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 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            return Long.parseLong(next());\n        }\n        public int nextInt(){\n            return Integer.parseInt(next());\n        }\n        public double nextDouble(){\n            return Double.parseDouble(next());\n        }\n    }\n}\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.net.Inet4Address;\nimport java.util.*;\n\npublic class l {\n    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////\n////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////\n////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////\n////////                                                                                                               /////////\n////////                                                                                                               /////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    static long mod = (int) (1e9 + 7);\n    static int n;\n    static StringBuilder sol;\n\n    static class pair implements Comparable<pair> {\n        int L,R;\n        public pair( int x,int y) {\n            L=x;R=y;\n        }\n\n\n        public int compareTo(pair o) {\n            if (L!=o.L)return L-o.L;\n            return o.R-R;\n        }\n        public String toString(){\n            return L+\" \"+R;\n        }\n    }\n\n    static boolean is;\n    static int [][][]memo;\n    static int[]val,gen;\n    static int dp(int last,int rem,int msk){\n        if (rem==0)return 1;\n        if (memo[last][rem][msk]!=-1)return memo[last][rem][msk];\n        int ans =0;\n        for (int i =0;i<n;i++){\n            if ((msk&1<<i)==0){\n                if (gen[i]!=last&&val[i]<=rem){\n                    ans+=dp(gen[i],rem-val[i],msk|1<<i);\n                    ans%=mod;\n                }\n            }\n        }\n        return memo[last][rem][msk]=ans;\n    }\n    public static void main(String[] args) throws IOException {\n        Scanner sc = new Scanner(System.in);\n        //FileWriter f = new FileWriter(\"C:\\\\Users\\\\Ibrahim\\\\out.txt\");\n        PrintWriter pw = new PrintWriter(System.out);\n         n = sc.nextInt();\n        int t = sc.nextInt();\n        gen= new int[n];\n        val= new int[n];\n        for (int i =0;i<n;i++){\n            val[i]=sc.nextInt();\n            gen[i]=sc.nextInt();\n        }\n        memo= new int[4][t+1][1<<n];\n        for (int[][]x:memo)for (int[]a:x)Arrays.fill(a,-1);\n        pw.println(dp(0,t,0));\n        pw.flush();\n    }\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\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        public boolean ready() throws IOException {\n            return br.ready();\n        }\n\n    }\n\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Vaibhav Pulastya\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        long mod = (int) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int T = in.nextInt();\n            int[] t = new int[n];\n            int[] g = new int[n];\n            for (int i = 0; i < n; i++) {\n                t[i] = in.nextInt();\n                g[i] = in.nextInt();\n            }\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            ArrayList<Integer> masks = new ArrayList<>();\n            long val = 0;\n            for (int i = 1; i < (1 << n); i++) {\n                int time = 0;\n                int[] count = new int[3];\n                for (int j = 0; j < n; j++) {\n                    if ((i & (1 << j)) != 0) {\n                        time += t[j];\n                        count[g[j] - 1]++;\n                    }\n                }\n                if (time == T) {\n                    masks.add(i);\n                    Arrays.sort(count);\n                    long v = ((fact[count[0]] * fact[count[1]]) % mod * fact[count[2]]) % mod;\n                    val += ((countUtil(count[0], count[1], count[2])) * v) % mod;\n                }\n            }\n            out.println(val%mod);\n\n        }\n\n        long countWays(int p, int q, int r, int last) {\n            // if number of balls of any\n            // color becomes less than 0\n            // the number of ways arrangements is 0.\n            if (p < 0 || q < 0 || r < 0)\n                return 0;\n\n            // If last ball required is\n            // of type P and the number\n            // of balls of P type is 1\n            // while number of balls of\n            // other color is 0 the number\n            // of ways is 1.\n            if (p == 1 && q == 0 && r == 0 && last == 0)\n                return 1;\n\n            // Same case as above for 'q' and 'r'\n            if (p == 0 && q == 1 && r == 0 && last == 1)\n                return 1;\n            if (p == 0 && q == 0 && r == 1 && last == 2)\n                return 1;\n\n            // if last ball required is P\n            // and the number of ways is\n            // the sum of number of ways\n            // to form sequence with 'p-1' P\n            // balls, q Q Balls and r R balls\n            // ending with Q and R.\n            if (last == 0)\n                return (countWays(p - 1, q, r, 1) +\n                        countWays(p - 1, q, r, 2)) % mod;\n\n            // Same as above case for 'q' and 'r'\n            if (last == 1)\n                return (countWays(p, q - 1, r, 0) +\n                        countWays(p, q - 1, r, 2)) % mod;\n\n            if (last == 2)\n                return (countWays(p, q, r - 1, 0) +\n                        countWays(p, q, r - 1, 1)) % mod;\n\n            return 0;\n        }\n\n        long countUtil(int p, int q, int r) {\n            // Three cases arise:\n            return ((countWays(p, q, r, 0) +\n                    countWays(p, q, r, 1)) % mod +\n                    countWays(p, q, r, 2)) % mod;\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    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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    //   npe, particularly in maps\n    //\n    // Big numbers arithmetic bugs:\n    //   int overflow\n    //   sorting, or taking max, after MOD\n    void solve() throws IOException {\n        int[] nT = ril(2);\n        int n = nT[0];\n        int T = nT[1];\n        int[][] tg = new int[n][];\n        for (int i = 0; i < n; i++) tg[i] = ril(2);\n\n        // dp[t][m][g] is the number of sequences possible to be formed from\n        // songs indicated by mask m, having total time t, and whose last song\n        // is genre g.\n        int[][][] dp = new int[T+1][1 << n][3];\n        for (int ti = 1; ti <= T; ti++) {\n            for (int mask = 1; mask <= (1 << n); mask++) {\n                // Iterate over the possible last song. It's genre will determine\n                // what the third dimension should be\n                for (int j = 0; j < n; j++) {\n                    if (((1 << j) & mask) == 0) continue;\n                    int time = tg[j][0];\n                    int genre = tg[j][1]-1;\n                    if (ti - time < 0) continue;\n                    long base = dp[ti][mask][genre];\n                    long add = 0;\n                    if (ti - time == 0) {\n                        // Base case: there is always one way regardless of what songs are available.\n                        // The empty playlist\n                        add = 1;\n                    } else {\n                        for (int g = 0; g < 3; g++) add += dp[ti-time][mask ^ (1 << j)][g];\n                        add -= dp[ti-time][mask ^ (1 << j)][genre];\n                    }\n                    dp[ti][mask][genre] = (int) ((base + add) % MOD);\n                }\n            }\n        }\n        long ans = 0;\n        for (int g = 0; g < 3; g++) ans += dp[T][(1 << n)-1][g];\n        pw.println(ans % MOD);\n    }\n    // IMPORTANT\n    // DID YOU CHECK THE COMMON MISTAKES ABOVE?\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\n    void printDouble(double d) {\n        pw.printf(\"%.16f\", d);\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.TreeSet;\n\npublic class r568p8{\n\n    private static InputReader sc;\n    private static PrintWriter pw;\n    private static long mod;\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        sc = new InputReader(System.in);\n        pw = new PrintWriter(System.out);\n\n        int t = 1;\n        while(t-->0)\n            solve();\n\n        pw.flush();\n        pw.close();\n    }\n\n    private static void fill_matrix(long dp[][][][], int a, int b, int c, int end){\n\n        if((a == 0 && b == 0 && c == 0) || (a == 0 && end == 0) || (b == 0 && end == 1) || (c == 0 && end == 2)){\n            dp[a][b][c][end] = 0;\n            return;\n        }\n\n        if(a > 1 && b == 0 && c == 0){\n            dp[a][b][c][end] = 0;\n            return;\n        }\n\n        if(b > 1 && a == 0 && c == 0){\n            dp[a][b][c][end] = 0;\n            return;\n        }\n\n        if(c > 1 && a == 0 && b == 0){\n            dp[a][b][c][end] = 0;\n            return;\n        }\n\n        if(a == 1 && end == 0 && b == 0 && c == 0){\n            dp[a][b][c][end] = 1;\n            return;\n        }\n        if(b == 1 && end == 1 && a == 0 && c == 0){\n            dp[a][b][c][end] = 1;\n            return;\n        }\n        if(c == 1 && end == 2 && b == 0 && a == 0){\n            dp[a][b][c][end] = 1;\n            return;\n        }\n\n        if(end == 0){\n            fill_matrix(dp, a-1, b, c, 1);\n            fill_matrix(dp, a-1, b, c, 2);\n\n            dp[a][b][c][0] = (dp[a-1][b][c][1]%mod + dp[a-1][b][c][2]%mod)%mod;\n        }\n        else if(end == 1){\n            fill_matrix(dp, a, b-1, c, 0);\n            fill_matrix(dp, a, b-1, c, 2);\n\n            dp[a][b][c][1] = (dp[a][b-1][c][0]%mod + dp[a][b-1][c][2]%mod)%mod;\n        }\n        else{\n            fill_matrix(dp, a, b, c-1, 0);\n            fill_matrix(dp, a, b, c-1, 1);\n\n            dp[a][b][c][2] = (dp[a][b][c-1][0]%mod + dp[a][b][c-1][1]%mod)%mod;\n        }\n    }\n\n    private static long cal(int count[]){\n        int a = count[0], b = count[1], c = count[2];\n        long dp[][][][] = new long[a+1][b+1][c+1][3];\n\n        long factorial[] = new long[20];\n\n        factorial[0] = 1;\n        factorial[1] = 1;\n\n        for(int i=2; i<20; i++)\n            factorial[i] = (factorial[i-1]%mod*i%mod)%mod;\n\n        fill_matrix(dp, a, b, c, 0);\n        fill_matrix(dp, a, b, c, 1);\n        fill_matrix(dp, a, b, c, 2);\n\n         long p = (dp[a][b][c][0]%mod + dp[a][b][c][1]%mod + dp[a][b][c][2]%mod)%mod;\n\n         long ans = (((p%mod * factorial[a]%mod)%mod * factorial[b]%mod)%mod * factorial[c]%mod)%mod;\n\n         return ans;\n    }\n\n    private static void solve(){\n        int n = sc.nextInt(), T = sc.nextInt();\n\n        int len[] = new int[n], genre[] = new int[n];\n\n        for(int i=0; i<n; i++){\n            len[i] = sc.nextInt();\n            genre[i] = sc.nextInt();\n        }\n\n        int sum[] = new int[(1<<n)];\n\n        mod = (long)1e9 + 7;\n        long ans = 0;\n\n        for(int i=1; i<(1<<n); i++){\n            for(int j=0; j<15; j++){\n                if((i&(1<<j)) != 0){\n                    sum[i] = sum[i^(1<<j)] + len[j];\n                    break;\n                }\n            }\n\n            if(sum[i] == T) {\n                int count[] = {0, 0, 0};\n\n                for (int j = 0; j < 15; j++) {\n                    if ((i & (1 << j)) != 0)\n                        count[genre[j] - 1]++;\n                }\n\n                ans = (ans % mod + cal(count) % mod) % mod;\n            }\n        }\n\n        pw.println(+ans);\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author khokharnikunj8\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        G1playlist solver = new G1playlist();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class G1playlist {\n        int mod = 1000000007;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int T = in.scanInt();\n            int[][] song = new int[n][2];\n            for (int i = 0; i < n; i++) {\n                song[i][0] = in.scanInt();\n                song[i][1] = in.scanInt() - 1;\n            }\n            int[][][] dp = new int[T + 1][(1 << n)][3];\n            for (int i = 0; i < n; i++)\n                if (song[i][0] <= T) {\n                    dp[song[i][0]][(1 << i)][song[i][1]] = 1;\n                }\n            for (int t = 0; t <= T; t++) {\n                for (int i = 0; i < (1 << n); i++) {\n                    for (int j = 0; j < 3; j++) {\n                        if (dp[t][i][j] == 0) continue;\n                        for (int k = 0; k < n; k++) {\n                            if (((1 << k) & i) == 0 && t + song[k][0] <= T && song[k][1] != j)\n                                dp[t + song[k][0]][(1 << k) | i][song[k][1]] = (dp[t + song[k][0]][(1 << k) | i][song[k][1]] + dp[t][i][j]) % mod;\n                        }\n                    }\n                }\n            }\n            long ans = 0;\n            for (int i = 0; i < (1 << n); i++) {\n                for (int j = 0; j < 3; j++) {\n                    ans = (ans + dp[T][i][j]) % mod;\n                }\n            }\n            out.println(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 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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1185g1_3 {\n\n    public static void main(String[] args) throws IOException {\n        int n = rni(), t = ni(), song[][] = new int[n][2];\n        for (int i = 0; i < n; ++i) {\n            song[i][0] = rni();\n            song[i][1] = ni() - 1;\n        }\n        int dp[][] = new int[1 << n][4], sum[] = new int[1 << n], ans = 0;\n        dp[0][3] = 1;\n        for (int i = 0; i < 1 << n; ++i) {\n            for (int j = 0; j < 4; ++j) {\n                for (int k = 0; k < n; ++k) {\n                    if ((i & (1 << k)) == 0 && song[k][1] != j) {\n                        dp[i | (1 << k)][song[k][1]] = madd(dp[i | (1 << k)][song[k][1]], dp[i][j]);\n                        sum[i | (1 << k)] = sum[i] + song[k][0];\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < 1 << n; ++i) {\n            if (sum[i] == t) {\n                ans = madd(ans, dp[i][0], dp[i][1], dp[i][2]);\n            }\n        }\n        prln(ans);\n        close();\n    }\n\n    static int mmod = 1000000007;\n\n    static int madd(int a, int b) {\n        return (a + b) % mmod;\n    }\n\n    static int madd(int... a) {\n        int ans = a[0];\n        for (int i = 1; i < a.length; ++i) {\n            ans = madd(ans, a[i]);\n        }\n        return ans;\n    }\n\n    static int msub(int a, int b) {\n        return (a - b + mmod) % mmod;\n    }\n\n    static int mmul(int a, int b) {\n        return (int) ((long) a * b % mmod);\n    }\n\n    static int mmul(int... a) {\n        int ans = a[0];\n        for (int i = 1; i < a.length; ++i) {\n            ans = mmul(ans, a[i]);\n        }\n        return ans;\n    }\n\n    static int minv(int x) {\n        // return mpow(x, mmod - 2);\n        return (exgcd(x, mmod)[0] % mmod + mmod) % mmod;\n    }\n\n    static int mpow(int a, long b) {\n        if (a == 0) {\n            return 0;\n        }\n        int ans = 1;\n        while (b > 0) {\n            if ((b & 1) > 0) {\n                ans = mmul(ans, a);\n            }\n            a = mmul(a, a);\n            b >>= 1;\n        }\n        return ans;\n    }\n\n    static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in));\n    static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out));\n    static StringTokenizer input;\n    static Random __r = 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 long LMAX = 9223372036854775807L;\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[] exgcd(int a, int b) {if (b == 0) return new int[] {1, 0}; int[] y = exgcd(b, a % b); return new int[] {y[1], y[0] - y[1] * (a / b)};}\n    static long[] exgcd(long a, long b) {if (b == 0) return new long[] {1, 0}; long[] y = exgcd(b, a % b); return new long[] {y[1], y[0] - y[1] * (a / b)};}\n    static int randInt(int min, int max) {return __r.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    // 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 __i.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    // output\n    static void pr(int i) {__o.print(i);}\n    static void prln(int i) {__o.println(i);}\n    static void pr(long l) {__o.print(l);}\n    static void prln(long l) {__o.println(l);}\n    static void pr(double d) {__o.print(d);}\n    static void prln(double d) {__o.println(d);}\n    static void pr(char c) {__o.print(c);}\n    static void prln(char c) {__o.println(c);}\n    static void pr(char[] s) {__o.print(new String(s));}\n    static void prln(char[] s) {__o.println(new String(s));}\n    static void pr(String s) {__o.print(s);}\n    static void prln(String s) {__o.println(s);}\n    static void pr(Object o) {__o.print(o);}\n    static void prln(Object o) {__o.println(o);}\n    static void prln() {__o.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 boolean pryesno(boolean b) {prln(b ? \"yes\" : \"no\"); return b;};\n    static boolean pryn(boolean b) {prln(b ? \"Yes\" : \"No\"); return b;}\n    static boolean prYN(boolean b) {prln(b ? \"YES\" : \"NO\"); return b;}\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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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() {__o.flush();}\n    static void close() {__o.close();}\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n,t[],g[],MOD=(int)1e9+7;\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\tif(memo[lastG][msk]!=-1)\n\t\t\treturn memo[lastG][msk];\n\t\tint ans=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif((msk & (1<<i))==0 && rem>=t[i] && g[i]!=lastG)\n\t\t\t\tans+=dp(msk|1<<i,rem-t[i],g[i]);\n\t\t\t\tif(ans>=MOD)\n\t\t\t\t\tans-=MOD;\n\t\t}\n\t\treturn memo[lastG][msk]=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\t\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tt[i]=sc.nextInt();\n\t\t\tg[i]=sc.nextInt()-1;\n\t\t}\n\t\tmemo=new int [4][1<<n];\n\t\tfor(int []x:memo)\n\t\t\tArrays.fill(x, -1);\n\t\tout.println(dp(0, T, 3));\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.lang.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.regex.*;\n\npublic class Main{\n\t static long dp[][][][]=new long [16][16][16][4];\n\t static void ini() {\n\t\t for(int i=0;i<16;i++) {\n\t\t\t for(int j=0;j<16;j++) {\n\t\t\t\t for(int k=0;k<16;k++) {\n\t\t\t\t\t for(int l=0;l<4;l++) {\n\t\t\t\t\t\t dp[i][j][k][l]=-1L;\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t }\n\t\t }\n\t }\n\t static int chk(long i) {\n\t\t if(i==0L)\n\t\t\t return 1;\n\t\t else\n\t\t\t return 0;\n\t }\n\t static long f(long a,long b,long c,int taken) {\n\t\tint got=(int) (a+b+c);\n\t\tint have=chk(a)+chk(b)+chk(c);\n\t\tif(have==2) {\n\t\t\tif(got==1)\n\t\t\t\treturn 1L;\n\t\t\telse\n\t\t\t\treturn 0L;\n\t\t}\n\t\tif(dp[(int) a][(int) b][(int) c][taken]!=-1) {\n\t\t\treturn dp[(int) a][(int) b][(int) c][taken];\n\t\t}\n\t\tlong ans=0L;\n\t\t if(taken == 0) {\n\t\t\t if(a!=0)\n\t\t\t ans+=(a*f(a-1,b,c,1))%mod; ans%=mod;\n\t\t\t if(b!=0)\n\t\t\t ans+=(b*f(a,b-1,c,2))%mod; ans%=mod;\n\t\t\t if(c!=0)\n\t\t\t ans+=(c*f(a,b,c-1,3))%mod; ans%=mod;\n\t\t }\n\t\t else {\n\t\t\t ans+=((taken==1 || a==0)?0L:(a*f(a-1,b,c,1))%mod)%mod; ans%=mod;\n\t\t\t ans+=((taken==2 || b==0)?0L:(b*f(a,b-1,c,2))%mod)%mod; ans%=mod;\n\t\t\t ans+=((taken==3 || c==0)?0L:(c*f(a,b,c-1,3))%mod)%mod; ans%=mod;\n\t\t }\n\t\t dp[(int) a][(int) b][(int) c][taken]=ans;\n\t\t return ans;\n\t }\n\tpublic static void main(String[] args)\n   {\n       InputReader in=new InputReader(System.in);\n       PrintWriter pw = new PrintWriter(System.out);\n       int n=in.nextInt();\n       int total=in.nextInt();\n       int t[]=new int[n];\n       int g[]=new int[n];\n       for(int i=0;i<n;i++) {\n    \t   t[i]=in.nextInt();\n    \t   g[i]=in.nextInt();\n       }\n       long ans=0L;\n       for(int i=0;i<(1<<n);i++) {\n    \t   int sum=0;\n    \t   int a[]=new int[4];\n    \t   for(int j=0;j<n;j++) {\n    \t\t   \n    \t\t   if(((i>>j)&1)==1) {\n    \t\t\t   sum+=t[j];\n    \t\t\t   a[g[j]]++;\n    \t\t   }\n    \t   }\n    \t   if(sum==total) {\n    \t\t   ini();\n    \t\t   ans=(ans+f(a[1],a[2],a[3],0))%mod;\n    \t   }\n       }\n       pw.println(ans);\n       pw.flush();\n       pw.close();\n        \n        \n        }\n         private static void debug(Object... o) {\n     \t\tSystem.out.println(Arrays.deepToString(o));\n     \t}\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        { \n            this.stream = stream;\n        }\n        public int snext() \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                } \n                \n                catch (IOException e) \n                {\n                    throw new InputMismatchException();\n                }\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            {\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            {\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        static class tri implements Comparable<tri> {\n            int p, c, l;\n \n            tri(int p, int c, int l) {\n                this.p = p;\n                this.c = c;\n                this.l = l;\n            }\n \n            public int compareTo(tri o) {\n                return Integer.compare(l, o.l);\n            }\n        }\n \n        public String readString()\n        {\n            int c = snext();\n            while (isSpaceChar(c)) \n            {\n                c = snext();\n            }\n            StringBuilder res = new StringBuilder();\n            do \n            {\n                res.appendCodePoint(c);\n                c = snext();\n            } while (!isSpaceChar(c));\n            return res.toString();\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            {\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        public static long mod = 1000000007;\n        public static int d;\n        public static int p;\n        public static int q;\n        \n        public static int[] suffle(int[] a,Random gen)\n        {\n            int n = a.length;\n            for(int i=0;i<n;i++)\n            {\n                int ind = gen.nextInt(n-i)+i;\n                int temp = a[ind];\n                a[ind] = a[i];\n                a[i] = temp;\n            }\n            return a;\n        }\n        \n        public static void swap(int a, int b){\n            int temp = a;\n            a = b;\n            b = temp;\n        }\n        \n       /* public static long primeFactorization(long n)\n        {\n             HashSet<Integer> a =new HashSet<Integer>();\n        \tlong cnt=0;\n            for(int i=2;i*i<=n;i++)\n            {\n                while(a%i==0)\n                {\n                    a.add(i);\n                    a/=i;\n                }\n            }\n            if(a!=1)\n            \tcnt++;\n                //a.add(n);\n            return cnt;\n        }*/\n        \n        public static void sieve(boolean[] isPrime,int n)\n        {\n            for(int i=1;i<n;i++)\n                isPrime[i] = true;\n            \n            isPrime[0] = false;\n            isPrime[1] = false;\n            \n            for(int i=2;i*i<n;i++)\n            {\n                if(isPrime[i] == true)\n                {\n                    for(int j=(2*i);j<n;j+=i)\n                        isPrime[j] = false;\n                }\n            }\n        }\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 long GCD(long a,long b)\n        {\n            if(b==0)\n                return a;\n            else\n                return GCD(b,a%b);\n        }\n        \n        public static void extendedEuclid(int A,int B)\n        {\n            if(B==0)\n            {\n                d = A;\n                p = 1 ;\n                q = 0;\n            }\n            else\n            {\n                extendedEuclid(B, A%B);\n                int temp = p;\n                p = q;\n                q = temp - (A/B)*q;\n            }\n        }\n        \n        public static long LCM(long a,long b)\n        {\n            return (a*b)/GCD(a,b);\n        }\n        \n        public static int LCM(int a,int b)\n        {\n            return (a*b)/GCD(a,b);\n        }\n        \n        public static int binaryExponentiation(int x,int n)\n        {\n            int result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=result * x;\n                x=x*x;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static long binaryExponentiation(long x,long n)\n        {\n            long result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=result * x;\n                x=x*x;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static int modularExponentiation(int x,int n,int M)\n        {\n            int result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=(result * x)%M;\n                x=(x%M*x)%M;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static long modularExponentiation(long x,long n,long M)\n        {\n            long result=1;\n            while(n>0)\n            {\n                if(n % 2 ==1)\n                    result=(result%M * x%M)%M;\n                x=(x%M * x%M)%M;\n                n=n/2;\n            }\n            return result;\n        }\n        \n        public static long modInverse(int A,int M)\n        {\n            return modularExponentiation(A,M-2,M);\n        }\n        \n        public static long modInverse(long A,long M)\n        {\n            return modularExponentiation(A,M-2,M);\n        }\n        \n        public static boolean isPrime(int n)\n        {\n            \n            if (n <= 1)  return false;\n            if (n <= 3)  return true;\n            \n            if (n%2 == 0 || n%3 == 0) \n                return false;\n         \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            \n            return true;\n        }\n        \n         public static long[] shuffle(long[] a, Random gen){ \n                for(int i = 0, n = a.length;i < n;i++){ \n                    int ind = gen.nextInt(n-i)+i; \n                    long d = a[i]; \n                    a[i] = a[ind]; \n                    a[ind] = d; \n                } \n                return a; \n            }\n         static class pair implements Comparable<pair>{\n        \t Long x;\n             Long y;\n             Integer z;\n             pair(long l,long y2,int z){\n                 this.x=l;\n                 this.y=y2;\n                 this.z=z;\n             }\n              public int compareTo(pair o) {\n                     int result = x.compareTo(o.x);\n                     if(result==0)\n                         result = y.compareTo(o.y);\n                     \n                 return result;\n                 }  \n              public String toString(){\n                 return (x+\" \"+y);\n             }\n       }       \n \n      \n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Songs { \n\n\tstatic class Reader \n    { \n        final private int BUFFER_SIZE = 1 << 16; \n        private DataInputStream din; \n        private byte[] buffer; \n        private int bufferPointer, bytesRead; \n  \n        public Reader() \n        { \n            din = new DataInputStream(System.in); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public Reader(String file_name) throws IOException \n        { \n            din = new DataInputStream(new FileInputStream(file_name)); \n            buffer = new byte[BUFFER_SIZE]; \n            bufferPointer = bytesRead = 0; \n        } \n  \n        public String readLine() throws IOException \n        { \n            byte[] buf = new byte[1000000]; // 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 int findPos(int x, int ar[]){\n        for(int i=0;i<ar.length;i++){\n            if(ar[i]==x)\n                return (i+1);\n        }\n        return -20;\n    }\n\n    public static void main(String args[])throws IOException{\n        Reader sc=new Reader();\n        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n        int i,j;\n        int n=sc.nextInt();\n        int tt=sc.nextInt();\n        int t[]=new int[n];\n        int g[]=new int[n];\n        int last=0;\n        int M=1000000007;\n        long sum=0;\n        for(i=0;i<n;i++){\n            t[i]=sc.nextInt();\n            g[i]=sc.nextInt()-1;\n        }\n        int d[][]=new int[1<<n][4];\n        d[0][3]=1;\n        for(i=0;i<(1<<n);i++){\n            for(last=0;last<4;last++){\n                for(j=0;j<n;j++){\n                    if(g[j]!=last&&((i&(1<<j)))==0){\n                        d[i^(1<<j)][g[j]]=(d[i^(1<<j)][g[j]]+d[i][last])%M;\n                        // System.out.println((i|(1<<j))+\" \"+(g[j])+\" \"+d[i|(1<<j)][g[j]]);\n                    }\n                }\n            }\n            int dur=0;\n            for(j=0;j<n;j++){\n                if((i&(1<<j))>0){\n                    dur+=t[j];\n                }\n            }\n            if(dur==tt){\n                // System.out.println(i);\n                sum=(sum+d[i][0]+d[i][1]+d[i][2])%M;\n            }\n        }\n        pw.println(sum);\n        pw.close();\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class G1_PlaylistForPolycarp {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader inp = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Solver solver = new Solver();\n        solver.solve(inp, out);\n        out.close();\n    }\n\n    private static class Solver {\n        private void solve(InputReader inp, PrintWriter out) {\n            int n = inp.nextInt(), t = inp.nextInt();\n            int[][] tracks = new int[n][2];\n            long MOD = 1000000007;\n            for (int i = 0; i < n; i++) {\n                tracks[i][0] = inp.nextInt();\n                tracks[i][1] = inp.nextInt() - 1;\n            }\n            long[][] dp = new long[2 << n][4];\n            dp[0][3] = 1;\n\n            // amount of 1's in the mask\n            int curr = 1;\n            while (curr <= n) {\n                int mask = 0;\n                for (int i = 0; i < curr; i++) mask |= (1 << i);\n\n                // while it is a possible mask\n                while (mask < 2 << n) {\n                    // for each track\n                    for (int i = 0; i < n; i++) {\n                        // if mask contains track i\n                        if ((mask & (1 << i)) != 0) {\n                            // for each genre\n                            for (int j = 0; j < 4; j++) {\n                                if (j == tracks[i][1]) continue;\n                                dp[mask][tracks[i][1]] += dp[mask - (1 << i)][j];\n                            }\n                        }\n                    }\n\n                    // update mask\n                    mask = nextNumberXBits(mask);\n                }\n                curr++;\n            }\n\n            long res = 0;\n            for (int i = 0; i < (2 << n); i++) {\n                int time = 0;\n                for (int j = 0; j < n; j++) {\n                    if ((i & (1 << j)) != 0) time += tracks[j][0];\n                }\n                if (time == t) {\n                    for (int j = 0; j < 4; j++) {\n                        res += dp[i][j];\n                    }\n                    res %= MOD;\n                }\n            }\n            out.print(res);\n        }\n\n        private static int nextNumberXBits(int mask) {\n            int c = mask & -mask;\n            int r = mask + c;\n            return (((r ^ mask) >> 2) / c) | r;\n        }\n    }\n\n    static class InputReader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n\n        String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "\n// Problem : G1. Playlist for Polycarp (easy version)\n// Contest : Codeforces - Codeforces Round #568 (Div. 2)\n// URL : https://codeforces.com/contest/1185/problem/G1\n// Memory Limit : 256 MB\n// Time Limit : 5000 ms\n// Powered by CP Editor (https://github.com/cpeditor/cpeditor)\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class a implements Runnable{\n\t\n    public static void main(String[] args) {\n        new Thread(null, new a(), \"process\", 1<<26).start();\n    }\n\tpublic void run() {\n\t\tFastReader scan = new FastReader();\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t//PrintWriter out = new PrintWriter(\"file.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\t\tstatic final int inf = Integer.MAX_VALUE;\n\n\t\tpublic void solve(int testNumber, FastReader sc, PrintWriter pw) {\n\t\t\t//CHECK FOR QUICKSORT TLE\n\t\t\t//***********************//\n\t\t\t//CHECK FOR INT OVERFLOW\n\t\t\t//***********************//\n\t\t\tint n = sc.nextInt();\n\t\t\tint m = sc.nextInt();\n\t\t\ttup[] arr = new tup[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = new tup(sc.nextInt(), sc.nextInt()-1);\n\t\t\t}\n\t\t\tList<Integer>[] arr2 = Stream.generate(ArrayList::new).limit(16).toArray(List[]::new);\n\t\t\tfor(int i = 1; i < (1<<n); i++) {\n\t\t\t\tint t = i;\n\t\t\t\tint bits = 0;\n\t\t\t\twhile(t > 0) {\n\t\t\t\t\tif((t & 1) == 1) bits ++;\n\t\t\t\t\tt>>=1;\n\t\t\t\t}\n\t\t\t\tarr2[bits].add(i);\n\t\t\t}\n\t\t\tint[][] dp = new int[1<<n][3];\n\t\t\tdp[0] = new int[]{1, 1, 1};\n\t\t\tlong c = 0;\n\t\t\tfor(int i = 1; i <= n; i++) {\n\t\t\t\tfor(int x : arr2[i]) {\n\t\t\t\t\tint totallen = 0;\n\t\t\t\t\tArrayList<Integer> active = new ArrayList<>();\n\t\t\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\t\t\tif((x & (1 << j)) > 0){\n\t\t\t\t\t\t\tactive.add(j);\n\t\t\t\t\t\t\ttotallen += arr[j].a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor(int y : active) {\n\t\t\t\t\t\tif(i == 1) dp[x][arr[y].b]++;\n\t\t\t\t\t\telse dp[x][arr[y].b] += dp[x - (1<<y)][(arr[y].b+1)%3] + dp[x - (1<<y)][(arr[y].b+2)%3];\n\t\t\t\t\t\tdp[x][arr[y].b] %= 1000000007;\n\t\t\t\t\t}\n\t\t\t\t\tif(totallen == m) {\n\t\t\t\t\t\tc += dp[x][0] + dp[x][1] + dp[x][2];\n\t\t\t\t\t\tc %= 1000000007;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(c);\n\t\t}\n\t}\n\tstatic long binpow(long a, long b, long m) {\n\t\ta %= m;\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) == 1)\n\t\t\t\tres = res * a % m;\n\t\t\ta = a * a % m;\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic void sort(int[] x){\n\t\tshuffle(x);\n\t\tArrays.sort(x);\n\t}\n\tstatic void sort(long[] x){\n\t\tshuffle(x);\n\t\tArrays.sort(x);\n\t}\n\tstatic class tup implements Comparable<tup>{\n\t\tint a, b;\n\t\ttup(int a,int b){\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(tup o){\n\t\t\treturn Integer.compare(o.b,b);\n\t\t}\n\t}\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(i + 1);\n\t\t\tint temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic void shuffle(long[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(i + 1);\n\t\t\tlong temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastReader(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(new File(s)));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.stream.Stream;\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int();\n            int k=Int();\n            int A[][]=new int[n][2];\n            for(int i=0;i<A.length;i++){\n                A[i][0]=Int();\n                A[i][1]=Int()-1;\n            }\n            Arrays.sort(A,(a,b)->{\n                return a[1]-b[1];\n            });\n\n            Solution sol=new Solution(out);\n            sol.solution(A,k);\n        }\n        out.close();\n\n    }\n\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\n\n\n\nclass Solution{\n    PrintWriter out;\n    public Solution(PrintWriter out){\n        this.out=out;\n    }\n\n\n\n    int mod=1000000007;\n    long dp3[][][][];\n    public void solution(int A[][],int T){\n        long res=0;\n        int n=A.length;\n        long dp1[][]=new long[n+1][T+1];//a\n        long dp2[][][]=new long[n+1][n+1][T+1];//bc\n        dp3=new long[n+1][n+1][n+1][3];\n\n        //init\n        long f[]=new long[n+1];\n        f[0]=f[1]=1;\n        for(int i=2;i<f.length;i++){\n            f[i]=f[i-1]*i;\n            f[i]%=mod;\n        }\n\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    Arrays.fill(dp3[i][j][k],-1);\n                }\n            }\n        }\n\n\n        dp1[0][0]=1;\n        for(int i=0;i<A.length;i++){//a\n            int p=A[i][0],type=A[i][1];\n            if(type==0){\n                long newdp[][]=new long[dp1.length][dp1[0].length];\n                for(int cnt=1;cnt<=n;cnt++){\n                    for(int j=1;j<dp1[0].length;j++){\n                        if(j>=p){\n                            newdp[cnt][j]+=dp1[cnt-1][j-p];\n                            newdp[cnt][j]%=mod;\n                        }\n                    }\n                }\n\n                for(int cnt=0;cnt<=n;cnt++){\n                    for(int j=0;j<dp1[0].length;j++){\n                        newdp[cnt][j]+=dp1[cnt][j];\n                        newdp[cnt][j]%=mod;\n                    }\n                }\n                dp1=newdp;\n\n            }\n            else{\n                break;\n            }\n        }\n\n\n\n\n\n        dp2[0][0][0]=1;\n        for(int i=0;i<A.length;i++){//b c\n            int p=A[i][0],type=A[i][1];\n            if(type!=0){\n                long newdp[][][]=new long[dp2.length][dp2[0].length][dp2[0][0].length];\n                for(int a=0;a<dp2.length;a++){\n                    for(int b=0;b<dp2[0].length;b++){\n                        for(int j=0;j<dp2[0][0].length;j++){\n                            if(j>=p){\n                                if(type==1){\n                                    if(a-1>=0){\n                                        newdp[a][b][j]+=dp2[a-1][b][j-p];\n                                    }\n                                }\n                                else{\n                                    if(b-1>=0) {\n                                        newdp[a][b][j]+=dp2[a][b-1][j-p];\n                                    }\n                                }\n                            }\n                            newdp[a][b][j]%=mod;\n                        }\n                    }\n                }\n\n                for(int a=0;a<dp2.length;a++){\n                    for(int b=0;b<dp2[0].length;b++){\n                        for(int j=0;j<dp2[0][0].length;j++){\n                            newdp[a][b][j]+=dp2[a][b][j];\n                            newdp[a][b][j]%=mod;\n                        }\n                    }\n                }\n                dp2=newdp;\n            }\n        }\n\n\n        dp3[1][0][0][0]=1;\n        dp3[0][1][0][1]=1;\n        dp3[0][0][1][2]=1;\n        dfs(n,n,n,0);dfs(n,n,n,1);dfs(n,n,n,2);\n\n\n\n\n\n\n\n\n        for(int i=0;i<dp3.length;i++){\n            for(int j=0;j<dp3[0].length;j++){\n                for(int k=0;k<dp3[0][0].length;k++){\n                    for(int cur=0;cur<3;cur++){\n                        for(int t=0;t<=T;t++){//price\n                            int aprice=t;\n                            int bcprice=T-t;\n                            long cnt1=dp1[i][aprice];\n                            long cnt2=dp2[j][k][bcprice];\n                            long combination=dp3[i][j][k][cur];\n                            long p1=(cnt1*f[i])%mod;\n                            long p2=(((f[j]*f[k])%mod)*cnt2)%mod;\n                            long p3=(p1*p2)%mod;\n                            res+=(p3*combination)%mod;\n                            res%=mod;\n\n                        }\n                    }\n                }\n            }\n        }\n\n        /*System.out.println(dp3[1][0][0][0]+\"  \"+dp2[0][0][0]);\n\n        for(long p[]:dp1){\n            System.out.println(Arrays.toString(p));\n        }*/\n\n\n\n        out.println(res);\n\n    }\n\n    public long dfs(int a,int b,int c,int cur){\n        if(a<0||b<0||c<0){\n            return 0;\n        }\n        if(a==0&&b==0&&c==0){\n            return 0;\n        }\n\n        if(dp3[a][b][c][cur]!=-1)return dp3[a][b][c][cur];\n\n        long res=0;\n        if(cur==0){\n            res+=dfs(a-1,b,c,1);\n            res%=mod;\n            res+=dfs(a-1,b,c,2);\n            res%=mod;\n\n        }\n        else if(cur==1){\n            res+=dfs(a,b-1,c,0);\n            res%=mod;\n            res+=dfs(a,b-1,c,2);\n            res%=mod;\n        }\n        else{\n            res+=dfs(a,b,c-1,0);\n            res%=mod;\n            res+=dfs(a,b,c-1,1);\n            res%=mod;\n        }\n        res%=mod;\n        dp3[a][b][c][cur]=res;\n        return res;\n    }\n\n}\n\n\n\n\n\n\n\n\n\n\n\n\n/*\n                             ;\\\n                            |' \\\n         _                  ; : ;\n        / `-.              /: : |\n       |  ,-.`-.          ,': : |\n       \\  :  `. `.       ,'-. : |\n        \\ ;    ;  `-.__,'    `-.|\n         \\ ;   ;  :::  ,::'`:.  `.\n          \\ `-. :  `    :.    `.  \\\n           \\   \\    ,   ;   ,:    (\\\n            \\   :., :.    ,'o)): ` `-.\n           ,/,' ;' ,::\"'`.`---'   `.  `-._\n         ,/  :  ; '\"      `;'          ,--`.\n        ;/   :; ;             ,:'     (   ,:)\n          ,.,:.    ; ,:.,  ,-._ `.     \\\"\"'/\n          '::'     `:'`  ,'(  \\`._____.-'\"'\n             ;,   ;  `.  `. `._`-.  \\\\\n             ;:.  ;:       `-._`-.\\  \\`.\n              '`:. :        |' `. `\\  ) \\\n      -hrr-      ` ;:       |    `--\\__,'\n                   '`      ,'\n                        ,-'\n\n\n                      free bug dog\n*/\n\n\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.math.BigInteger;\nimport java.nio.charset.Charset;\nimport java.util.*;\n\npublic class CFContest {\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) 1e9 + 2;\n        BitOperator bitOperator = new BitOperator();\n        Modular modular = new Modular((int) 1e9 + 7);\n\n        public Task(FastIO io, Debug debug) {\n            this.io = io;\n            this.debug = debug;\n        }\n\n        @Override\n        public void run() {\n            solve();\n        }\n\n        int[][][] f;\n        int n;\n        int t;\n        int[] songTimes;\n        int[] songTypes;\n        int mask;\n\n        public void solve() {\n            n = io.readInt();\n            t = io.readInt();\n            mask = 1 << n;\n            f = new int[4][mask][t + 1];\n            for (int i = 0; i < 4; i++) {\n                for (int j = 0; j < mask; j++) {\n                    for (int k = 0; k <= t; k++) {\n                        f[i][j][k] = -1;\n                    }\n                }\n            }\n\n            songTimes = new int[n + 1];\n            songTypes = new int[n + 1];\n            for (int i = 1; i <= n; i++) {\n                songTimes[i] = io.readInt();\n                songTypes[i] = io.readInt();\n            }\n\n            int ans = 0;\n            for (int i = 0; i < 4; i++) {\n                for (int j = 0; j < mask; j++) {\n                    ans = modular.plus(ans, f(i, j, t));\n                }\n            }\n\n            io.cache.append(ans);\n        }\n\n        int f(int i, int j, int k) {\n            if (j == 0) {\n                return k == 0 && i == 0 ? 1 : 0;\n            }\n            if (k < 0) {\n                return 0;\n            }\n            if (f[i][j][k] == -1) {\n                f[i][j][k] = 0;\n                for (int x = 1; x <= n; x++) {\n                    if (songTypes[x] != i || bitOperator.bitAt(j, x - 1) == 0) {\n                        continue;\n                    }\n                    for (int y = 0; y < 4; y++) {\n                        if (y == i) {\n                            continue;\n                        }\n                        f[i][j][k] = modular.plus(f[i][j][k], f(y, bitOperator.setBit(j, x - 1, false), k - songTimes[x]));\n                    }\n                }\n            }\n            return f[i][j][k];\n        }\n    }\n\n    /**\n     * \u6a21\u8fd0\u7b97\n     */\n    public static class Modular {\n        int m;\n\n        public Modular(int m) {\n            this.m = m;\n        }\n\n        public int valueOf(int x) {\n            x %= m;\n            if (x < 0) {\n                x += m;\n            }\n            return x;\n        }\n\n        public int valueOf(long x) {\n            x %= m;\n            if (x < 0) {\n                x += m;\n            }\n            return (int) x;\n        }\n\n        public int mul(int x, int y) {\n            return valueOf((long) x * y);\n        }\n\n        public int plus(int x, int y) {\n            return valueOf(x + y);\n        }\n\n        @Override\n        public String toString() {\n            return \"mod \" + m;\n        }\n    }\n\n    public static class BitOperator {\n        public int bitAt(int x, int i) {\n            return (x >> i) & 1;\n        }\n\n        public int bitAt(long x, int i) {\n            return (int) ((x >> i) & 1);\n        }\n\n        public int setBit(int x, int i, boolean v) {\n            if (v) {\n                x |= 1 << i;\n            } else {\n                x &= ~(1 << i);\n            }\n            return x;\n        }\n\n        public long setBit(long x, int i, boolean v) {\n            if (v) {\n                x |= 1L << i;\n            } else {\n                x &= ~(1L << i);\n            }\n            return x;\n        }\n\n        /**\n         * Determine whether x is subset of y\n         */\n        public boolean subset(long x, long y) {\n            return intersect(x, y) == x;\n        }\n\n        /**\n         * Merge two set\n         */\n        public long merge(long x, long y) {\n            return x | y;\n        }\n\n        public long intersect(long x, long y) {\n            return x & y;\n        }\n\n        public long differ(long x, long y) {\n            return x - intersect(x, y);\n        }\n    }\n\n    public static class Randomized {\n        static Random random = new Random();\n\n        public static double nextDouble(double min, double max) {\n            return random.nextDouble() * (max - min) + min;\n        }\n\n        public static void randomizedArray(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 void randomizedArray(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 void randomizedArray(double[] data, int from, int to) {\n            to--;\n            for (int i = from; i <= to; i++) {\n                int s = nextInt(i, to);\n                double tmp = data[i];\n                data[i] = data[s];\n                data[s] = tmp;\n            }\n        }\n\n        public static void randomizedArray(float[] data, int from, int to) {\n            to--;\n            for (int i = from; i <= to; i++) {\n                int s = nextInt(i, to);\n                float tmp = data[i];\n                data[i] = data[s];\n                data[s] = tmp;\n            }\n        }\n\n        public static <T> void randomizedArray(T[] data, int from, int to) {\n            to--;\n            for (int i = from; i <= to; i++) {\n                int s = nextInt(i, to);\n                T 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    public static class Splay implements Cloneable {\n        public static final Splay NIL = new Splay();\n\n        static {\n            NIL.left = NIL;\n            NIL.right = NIL;\n            NIL.father = NIL;\n            NIL.size = 0;\n            NIL.key = Integer.MIN_VALUE;\n            NIL.sum = 0;\n        }\n\n        Splay left = NIL;\n        Splay right = NIL;\n        Splay father = NIL;\n        int size = 1;\n        int key;\n        long sum;\n\n        public static void splay(Splay x) {\n            if (x == NIL) {\n                return;\n            }\n            Splay y, z;\n            while ((y = x.father) != NIL) {\n                if ((z = y.father) == NIL) {\n                    y.pushDown();\n                    x.pushDown();\n                    if (x == y.left) {\n                        zig(x);\n                    } else {\n                        zag(x);\n                    }\n                } else {\n                    z.pushDown();\n                    y.pushDown();\n                    x.pushDown();\n                    if (x == y.left) {\n                        if (y == z.left) {\n                            zig(y);\n                            zig(x);\n                        } else {\n                            zig(x);\n                            zag(x);\n                        }\n                    } else {\n                        if (y == z.left) {\n                            zag(x);\n                            zig(x);\n                        } else {\n                            zag(y);\n                            zag(x);\n                        }\n                    }\n                }\n            }\n\n            x.pushDown();\n            x.pushUp();\n        }\n\n        public static void zig(Splay x) {\n            Splay y = x.father;\n            Splay z = y.father;\n            Splay b = x.right;\n\n            y.setLeft(b);\n            x.setRight(y);\n            z.changeChild(y, x);\n\n            y.pushUp();\n        }\n\n        public static void zag(Splay x) {\n            Splay y = x.father;\n            Splay z = y.father;\n            Splay b = x.left;\n\n            y.setRight(b);\n            x.setLeft(y);\n            z.changeChild(y, x);\n\n            y.pushUp();\n        }\n\n        public void setLeft(Splay x) {\n            left = x;\n            x.father = this;\n        }\n\n        public void setRight(Splay x) {\n            right = x;\n            x.father = this;\n        }\n\n        public void changeChild(Splay y, Splay x) {\n            if (left == y) {\n                setLeft(x);\n            } else {\n                setRight(x);\n            }\n        }\n\n        public void pushUp() {\n            if (this == NIL) {\n                return;\n            }\n            size = left.size + right.size + 1;\n            sum = left.sum + right.sum + key;\n        }\n\n        public void pushDown() {\n        }\n\n        public static int toArray(Splay root, int[] data, int offset) {\n            if (root == NIL) {\n                return offset;\n            }\n            offset = toArray(root.left, data, offset);\n            data[offset++] = root.key;\n            offset = toArray(root.right, data, offset);\n            return offset;\n        }\n\n        public static void toString(Splay root, StringBuilder builder) {\n            if (root == NIL) {\n                return;\n            }\n            root.pushDown();\n            toString(root.left, builder);\n            builder.append(root.key).append(',');\n            toString(root.right, builder);\n        }\n\n        public Splay clone() {\n            try {\n                return (Splay) super.clone();\n            } catch (CloneNotSupportedException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n        public static Splay cloneTree(Splay splay) {\n            if (splay == NIL) {\n                return NIL;\n            }\n            splay = splay.clone();\n            splay.left = cloneTree(splay.left);\n            splay.right = cloneTree(splay.right);\n            return splay;\n        }\n\n        public static Splay add(Splay root, Splay node) {\n            if (root == NIL) {\n                return node;\n            }\n            Splay p = root;\n            while (root != NIL) {\n                p = root;\n                root.pushDown();\n                if (root.key < node.key) {\n                    root = root.right;\n                } else {\n                    root = root.left;\n                }\n            }\n\n            if (p.key < node.key) {\n                p.setRight(node);\n            } else {\n                p.setLeft(node);\n            }\n            p.pushUp();\n            splay(node);\n            return node;\n        }\n\n        /**\n         * Make the node with the minimum key as the root of tree\n         */\n        public static Splay selectMinAsRoot(Splay root) {\n            if (root == NIL) {\n                return root;\n            }\n            root.pushDown();\n            while (root.left != NIL) {\n                root = root.left;\n                root.pushDown();\n            }\n            splay(root);\n            return root;\n        }\n\n        /**\n         * Make the node with the maximum key as the root of tree\n         */\n        public static Splay selectMaxAsRoot(Splay root) {\n            if (root == NIL) {\n                return root;\n            }\n            root.pushDown();\n            while (root.right != NIL) {\n                root = root.right;\n                root.pushDown();\n            }\n            splay(root);\n            return root;\n        }\n\n        /**\n         * delete root of tree, then merge remain nodes into a new tree, and return the new root\n         */\n        public static Splay deleteRoot(Splay root) {\n            root.pushDown();\n            Splay left = splitLeft(root);\n            Splay right = splitRight(root);\n            return merge(left, right);\n        }\n\n        /**\n         * detach the left subtree from root and return the root of left subtree\n         */\n        public static Splay splitLeft(Splay root) {\n            root.pushDown();\n            Splay left = root.left;\n            left.father = NIL;\n            root.setLeft(NIL);\n            root.pushUp();\n            return left;\n        }\n\n        /**\n         * detach the right subtree from root and return the root of right subtree\n         */\n        public static Splay splitRight(Splay root) {\n            root.pushDown();\n            Splay right = root.right;\n            right.father = NIL;\n            root.setRight(NIL);\n            root.pushUp();\n            return right;\n        }\n\n\n        public static Splay merge(Splay a, Splay b) {\n            if (a == NIL) {\n                return b;\n            }\n            if (b == NIL) {\n                return a;\n            }\n            a = selectMaxAsRoot(a);\n            a.setRight(b);\n            a.pushUp();\n            return a;\n        }\n\n        public static Splay selectKthAsRoot(Splay root, int k) {\n            if (root == NIL) {\n                return NIL;\n            }\n            Splay trace = root;\n            Splay father = NIL;\n            while (trace != NIL) {\n                father = trace;\n                trace.pushDown();\n                if (trace.left.size >= k) {\n                    trace = trace.left;\n                } else {\n                    k -= trace.left.size + 1;\n                    if (k == 0) {\n                        break;\n                    } else {\n                        trace = trace.right;\n                    }\n                }\n            }\n            splay(father);\n            return father;\n        }\n\n        public static Splay selectKeyAsRoot(Splay root, int k) {\n            if (root == NIL) {\n                return NIL;\n            }\n            Splay trace = root;\n            Splay father = NIL;\n            Splay find = NIL;\n            while (trace != NIL) {\n                father = trace;\n                trace.pushDown();\n                if (trace.key > k) {\n                    trace = trace.left;\n                } else {\n                    if (trace.key == k) {\n                        find = trace;\n                        trace = trace.left;\n                    } else {\n                        trace = trace.right;\n                    }\n                }\n            }\n\n            splay(father);\n            if (find != NIL) {\n                splay(find);\n                return find;\n            }\n            return father;\n        }\n\n        public static Splay bruteForceMerge(Splay a, Splay b) {\n            if (a == NIL) {\n                return b;\n            } else if (b == NIL) {\n                return a;\n            }\n            if (a.size < b.size) {\n                Splay tmp = a;\n                a = b;\n                b = tmp;\n            }\n\n            a = selectMaxAsRoot(a);\n            int k = a.key;\n            while (b != NIL) {\n                b = selectMinAsRoot(b);\n                if (b.key >= k) {\n                    break;\n                }\n                Splay kickedOut = b;\n                b = deleteRoot(b);\n                a = add(a, kickedOut);\n            }\n            return merge(a, b);\n        }\n\n        public static Splay[] split(Splay root, int key) {\n            if (root == NIL) {\n                return new Splay[]{NIL, NIL};\n            }\n            Splay p = root;\n            while (root != NIL) {\n                p = root;\n                root.pushDown();\n                if (root.key > key) {\n                    root = root.left;\n                } else {\n                    root = root.right;\n                }\n            }\n\n            splay(p);\n            if (p.key <= key) {\n                return new Splay[]{p, splitRight(p)};\n            } else {\n                return new Splay[]{splitLeft(p), p};\n            }\n        }\n\n        @Override\n        public String toString() {\n            StringBuilder builder = new StringBuilder().append(key).append(\":\");\n            toString(cloneTree(this), builder);\n            return builder.toString();\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}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class G1 {\n    static int n, T, duration[], type[];\n    static long dp[][][], mod = (long) 1e9 + 7;\n\n    public static void main(String[] args) throws Exception {\n        new Thread(null, new Runnable() {\n            public void run() {\n                try {\n                    solveIt();\n                } catch (Exception e) {\n                    e.printStackTrace();\n                    System.exit(1);\n                }\n            }\n        }, \"Main\", 1 << 28).start();\n    }\n\n    public static void solveIt() throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        T = in.nextInt();\n        dp = new long[4][T + 1][1 << n];\n        duration = new int[n];\n        type = new int[n];\n        for (int i = 0; i < n; i++) {\n            duration[i] = in.nextInt();\n            type[i] = in.nextInt() - 1;\n        }\n        for (long a[][] : dp) for (long b[] : a) Arrays.fill(b, -1);\n        pw.println(solve(3, T, 0));\n\n        pw.close();\n    }\n\n    static long solve(int lastType, int rem, int mask) {\n        if (rem == 0) return 1;\n        if (rem < 0) return 0;\n        if (dp[lastType][rem][mask] != -1) return dp[lastType][rem][mask];\n        long res = 0;\n        for (int i = 0; i < n; i++) {\n            if (!check(mask, i) && lastType != type[i] && rem - duration[i] >= 0) {\n                res += solve(type[i], rem - duration[i], set(mask, i));\n                if (res >= mod) res -= mod;\n            }\n        }\n        return dp[lastType][rem][mask] = res;\n    }\n\n    static boolean check(int N, int pos) {\n        return (N & (1 << pos)) != 0;\n    }\n\n    static int set(int N, int pos) {\n        return N = N | (1 << pos);\n    }\n\n    static int reset(int N, int pos) {\n        return N = N & ~(1 << pos);\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "/*\nRoses are red\nMemes are neat\nAll my test cases time out\nLmao yeet\n*/\nimport java.util.*;\nimport java.io.*;\n\n   public class x1185G1b\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 T = Integer.parseInt(st.nextToken());\n         Song[] arr = new Song[N];\n         for(int i=0; i < N; i++)\n         {\n            st = new StringTokenizer(infile.readLine());\n            int a = Integer.parseInt(st.nextToken());\n            int b = Integer.parseInt(st.nextToken())-1;\n            arr[i] = new Song(a, b);\n         }\n         //bitmask\n         long[][] dp = new long[1 << N][3];\n         Arrays.fill(dp[0], 1L);\n         for(int mask=0; mask < dp.length; mask++)\n         {\n            for(int i=0; i < N; i++)\n               if((mask & (1 << i)) == 0)\n               {\n                  Song c = arr[i];\n                  //continue all dp if mask == 0\n                  if(mask == 0 && c.t <= T)\n                  {\n                     dp[mask|(1 << i)][c.g]++;\n                     dp[mask|(1 << i)][c.g] %= MOD;\n                  }\n                  //continue dp if not same genre\n                  else\n                  {\n                     for(int gen=0; gen < 3; gen++)\n                        if(gen != c.g)\n                        {\n                           dp[mask|(1 << i)][c.g] += dp[mask][gen];\n                           dp[mask|(1 << i)][c.g] %= MOD;\n                        }\n                        //optimize?\n                  }\n               }\n         }\n         long res = 0L;\n         for(int mask=1; mask < dp.length; mask++)\n            for(int i=0; i < 3; i++)\n            {\n               int sum = 0;\n               for(int b=0; b < N; b++)\n                  if((mask & (1 << b)) > 0)\n                     sum += arr[b].t;\n               if(sum == T)\n                  res = (res+dp[mask][i])%MOD;\n            }\n         System.out.println(res);\n      }\n   }\n   class Song\n   {\n      public int t;\n      public int g;\n      \n      public Song(int a, int b)\n      {\n         t = a;\n         g = b;\n      }\n   }\n   //cheerios are good for your heart, but are they good for your brain?", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskG1 solver = new TaskG1();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskG1 {\n        final int mod = (int) 1e9 + 7;\n        int[][][] dp;\n\n        int rec(int mask, int time, int T, int genre, int[] ts, int[] gs) {\n            if (time > T)\n                return 0;\n            if (time == T)\n                return 1;\n            if (mask == (1 << ts.length) - 1)\n                return 0;\n            int res = dp[genre][time][mask];\n            if (res != -1)\n                return res;\n            res = 0;\n            for (int i = 0; i < ts.length; i++) {\n                if ((mask & (1 << i)) == 0 && (mask == 0 || gs[i] != genre)) {\n                    res += rec(mask | (1 << i), time + ts[i], T, gs[i], ts, gs);\n                    if (res >= mod)\n                        res -= mod;\n                }\n            }\n            return dp[genre][time][mask] = res;\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int[] ts = new int[n];\n            int[] gs = new int[n];\n            int T = in.nextInt();\n            for (int i = 0; i < n; i++) {\n                ts[i] = in.nextInt();\n                gs[i] = in.nextInt() - 1;\n            }\n            dp = new int[3][T][1 << n];\n            for (int[][] aux : dp) {\n                for (int[] aux2 : aux)\n                    Arrays.fill(aux2, -1);\n            }\n            int ans = rec(0, 0, T, 0, ts, gs);\n            out.println(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.util.Map.Entry;\n \n \npublic class  cf2{\n\tstatic int x0;\n\tstatic int y0;\n\tstatic int x1;\n\tstatic int y1;\n\tstatic HashMap<Integer,HashSet<Integer>>allowed;\n\tstatic HashMap<Integer,HashMap<Integer,Integer>>cost;\n\tstatic int []dx= {-1,-1,-1,0,0,0,1,1,1};\n\tstatic int []dy= {-1,0,1,-1,0,1,-1,0,1};\n\tstatic int highbound=(int)1e9;\n\tstatic boolean valid(int i,int j) {\n\t\tif(i>=1 && i<=highbound && j>=1 && j<=highbound && allowed.containsKey(i) && allowed.get(i).contains(j))return true;\n\t\treturn false;\n\t}\n\tstatic long ans;\n\tstatic class Triple implements Comparable<Triple>\n\t{\n\t\tint i,j,cost;\n\t\tTriple(int x, int y, int z){i = x; j = y; cost = z;}\n\t\t\n\t\tpublic int compareTo(Triple t) {\n\t\t\treturn this.cost - t.cost;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn i+\" \"+j+\" \"+cost;\n\t\t}\n\t\t\n\t}\n\tpublic static int dijkstra()\n\t{\n\t\tPriorityQueue<Triple> q = new PriorityQueue<Triple>();\n\t\tq.add(new Triple(x0,y0,0));\n\t\tHashMap<Integer,Integer>z=new HashMap<Integer,Integer>();z.put(y0,0);\n\t\tcost.put(x0,z);\n\t\twhile(!q.isEmpty())\n\t\t{\t\n\t\t\tTriple cur = q.remove();\n\t\t\t//if(cur.i==x1 && cur.j==y1)continue;\n\t\t\tif(cur.cost > cost.getOrDefault(cur.i,new HashMap<Integer,Integer>()).getOrDefault(cur.j,1000000000))\n\t\t\t\tcontinue;\n\t\t\tfor(int k = 0; k < 9; k++)\n\t\t\t{\n\t\t\t\tint x = cur.i + dx[k];\n\t\t\t\tint y = cur.j + dy[k];\n\t\t\t\tint c=cost.getOrDefault(x,new HashMap<Integer,Integer>()).getOrDefault(y,1000000000);\n\t\t\t\tif(valid(x,y) && cur.cost +1 < c)\n\t\t\t\t{\n\t\t\t\t\tHashMap<Integer,Integer>zz=new HashMap<Integer,Integer>();zz.put(y,cur.cost+1);\n\t\t\t\t\tcost.put(x,zz);\n\t\t\t\t\tq.add(new Triple(x,y,cur.cost+1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\treturn cost.getOrDefault(x1,new HashMap<Integer,Integer>()).getOrDefault(y1,-1);\n\t}\n\tstatic int t;static int n;\n\tstatic int []ds;\n\tstatic int []gs;\n\tstatic int [][]memo;\n\tstatic int dp(int lastg,int msk,int sum) {\n\t\tif(sum==t)return 1;\n\t\tif(msk==(1<<n)-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif(memo[lastg][msk]!=-1)return memo[lastg][msk];\n\t\tint tot=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tif(((1<<i)&msk)==0 && gs[i]!=lastg) {\n\t\t\t\ttot=(tot+dp(gs[i],msk|(1<<i),sum+ds[i]))%(1000000007);\n\t\t\t}\n\t\t}\n\t\treturn memo[lastg][msk]=tot;\n\t}\n    public static void main(String[] args) throws IOException{\n        MScanner sc = new MScanner(System.in);\n        PrintWriter pw=new PrintWriter(System.out);\n        n=sc.nextInt();\n        t=sc.nextInt();\n        ds=new int[n];gs=new int[n];\n        for(int i=0;i<n;i++) {\n        \tds[i]=sc.nextInt();gs[i]=sc.nextInt();\n        }\n        memo=new int[4][1<<n];\n        for(int []i:memo)Arrays.fill(i,-1);\n        pw.println(dp(0, 0,0));\n        pw.flush();\n    }\n    static long gcd(long a, long b) {\n \n\t\tif (b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b, a % b);\n\t}\n    static int[]primes;\n    static int sizeofp=0;\n\tstatic int[] isComposite;\n \n\tstatic void sieve(int N)\t// O(N log log N) \n\t{\n\t\tisComposite = new int[N+1];\t\t\t\t\t\n\t\tisComposite[0] = isComposite[1] = 1;\t\t\t\n\t\tprimes = new int[N];\n \n\t\tfor (int i = 2; i <= N; ++i) \t\t\t\t\t\n\t\t\tif (isComposite[i] == 0) \t\t\t\t\t\n\t\t\t{\n\t\t\t\tprimes[sizeofp++]=i;;\n\t\t\t\tif(1l * i * i <= N)\n\t\t\t\t\tfor (int j = i * i; j <= N; j += i)\t\n\t\t\t\t\t\tisComposite[j] = 1;\n\t\t\t}   \n\t}\n    static class pair implements Comparable<pair>{\n    \tint num;int idx;\n    \tpair(int x,int y){\n    \t\tnum=x;idx=y;\n    \t}\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\t\t\tif(num!=o.num) {\n\t\t\t\treturn num-o.num;\n\t\t\t}\n\t\t\treturn idx-o.idx;\n\t\t}\n\t\t @Override\n\t       public int hashCode()\n\t       {\n\t           return Objects.hash(num,idx) ;\n\t       }\n\t\tpublic boolean equals(pair o) {\n\t\t\tif(this.compareTo(o)==0)return true;\n\t\t\treturn false;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+0+\" \"+0+\")\";\n\t\t}\n    }\n\tstatic class MScanner \n\t{\n\t    StringTokenizer st;\n\t    BufferedReader br;\n \n\t    public MScanner(InputStream s){    br = new BufferedReader(new InputStreamReader(s));}\n \n\t    public String next() throws IOException \n\t    {\n\t        while (st == null || !st.hasMoreTokens()) \n\t            st = new StringTokenizer(br.readLine());\n\t        return st.nextToken();\n\t    }\n \n\t    public int nextInt() throws IOException {return Integer.parseInt(next());}\n\t    \n\t    public long nextLong() throws IOException {return Long.parseLong(next());}\n \n\t    public String nextLine() throws IOException {return br.readLine();}\n\t    \n\t    public 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            neg = true;\n\t            start++;\n\t        }\n\t        for(int i = start; i < x.length(); i++)\n\t            if(x.charAt(i) == '.')\n\t            {\n\t                res = Long.parseLong(sb.toString());\n\t                sb = new StringBuilder(\"0\");\n\t                dec = true;\n\t            }\n\t            else\n\t            {\n\t                sb.append(x.charAt(i));\n\t                if(dec)\n\t                    f *= 10;\n\t            }\n\t        res += Long.parseLong(sb.toString()) / f;\n\t        return res * (neg?-1:1);\n\t    }\n\t    \n\t    public boolean ready() throws IOException {return br.ready();}\n \n \n\t}\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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\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        G1PleilistDlyaPolikarpaUproshennayaVersiya solver = new G1PleilistDlyaPolikarpaUproshennayaVersiya();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class G1PleilistDlyaPolikarpaUproshennayaVersiya {\n\n        static final int MOD = (int) 1e9 + 7;\n        int n;\n        int t;\n        int[][] a = new int[15][2];\n        long[][] mem = new long[1 << 15][4];\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            for (int i = 0; i < (1 << 15); i++) {\n                for (int h = 0; h < 4; h++) {\n                    mem[i][h] = -1;\n                }\n            }\n            n = in.nextInt();\n            t = in.nextInt();\n            for (int i = 0; i < n; i++) {\n                a[i][0] = in.nextInt();\n                a[i][1] = in.nextInt();\n            }\n            out.println(doit(0, 0, 0));\n        }\n\n        private long doit(int mask, int genre, int sum) {\n            if (mem[mask][genre] != -1) {\n                return mem[mask][genre];\n            }\n            if (sum > t) {\n                mem[mask][genre] = 0;\n                return mem[mask][genre];\n            }\n            if (sum == t) {\n                mem[mask][genre] = 1;\n                return mem[mask][genre];\n            }\n            long ct = 0;\n            for (int i = 0; i < n; i++) {\n                if ((mask & (1 << i)) > 0 || genre == a[i][1]) {\n                    continue;\n                }\n                ct = (ct + doit(mask | (1 << i), a[i][1], sum + a[i][0])) % MOD;\n            }\n\n            mem[mask][genre] = ct;\n            return mem[mask][genre];\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}\n\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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        static final int mod = 1000000007;\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            long 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 % mod);\n        }\n\n        private long 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[lastGenre][timeLeft][chosen];\n            }\n\n            long 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                    if (ret > mod) {\n                        ret = ret % mod;\n                    }\n                }\n            }\n            mem[lastGenre][timeLeft][chosen] = (int) (ret % mod);\n\n            return mem[lastGenre][timeLeft][chosen];\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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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[] mapping = new int[65536];\n        int mask = 1;\n        for (int k = 0; k < n; k++) {\n            for (int i = 1; i < mapping.length; i++) {\n                if ((i & mask) != 0) mapping[i] += songs[k][0];\n            }\n            mask <<= 1;\n        }\n\n        int[][][] dp = new int[17][65536][3];\n        mask = 1;\n\n        for (int i = 0; i < n; i++) {\n            dp[1][mask][songs[i][1]] = 1;\n            mask <<= 1;\n        }\n\n        for (int i = 1; i < n; i++) {\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                    dp[i + 1][j | mask][cg] = (dp[i + 1][j | mask][cg] + (dp[i][j][g1] + dp[i][j][g2]) % mod) % mod;\n                }\n                mask <<= 1;\n            }\n        }\n        int res = 0;\n        for (int k = 0; k < 17; k++)\n        for (int i = 1; i < 65536; i++) {\n            if (mapping[i] == T) res = (res + dp[k][i][0] + dp[k][i][1] + dp[k][i][2]) % mod;\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<WithIdx> {\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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.*;\nimport java.util.*;\nimport java.math.*;\npublic class G1 {\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew G1().run();\n    }\n    int MOD = 1_000_000_007;\n\tpublic void run() throws Exception {\n\t\tFastScanner f = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out);\n        int n = f.nextInt(), t = f.nextInt();\n        int[][] dp = new int[1 << n][3];\n        int[] tarr = new int[n];\n        int[] garr = new int[n];\n        for(int i = 0; i < n; i++) {\n            tarr[i] = f.nextInt();\n            garr[i] = f.nextInt()-1;\n            if(tarr[i] <= t) dp[1 << i][garr[i]] = 1;\n        }\n        int[] time = new int[1 << n];\n        for(int i = 0; i < dp.length; i++) {\n            for(int bi = 0; bi < n; bi++)\n                if((i & 1 << bi) != 0) time[i] += tarr[bi];\n        }\n        for(int i = 0; i < dp.length; i++) {\n            int j = time[i];\n                for(int k = 0; k < 3; k++) {\n                    if(dp[i][k] == 0) continue;\n                    for(int bi = 0; bi < n; bi++)\n                        if(tarr[bi] + j <= t && (i & 1 << bi) == 0 && garr[bi] != k) {\n                                    dp[i | 1 << bi][garr[bi]] = \n                                        (dp[i | 1 << bi][garr[bi]] + dp[i][k]) % MOD;\n                        }\n                }\n        }\n        long ans = 0;\n        for(int i = 0; i < dp.length; i++)\n            for(int j = 0; j < 3; j++)\n            if(time[i] == t) ans = (ans + dp[i][j]) % MOD;\n        out.println(ans);\n        out.flush();\n\t}\n    static class FastScanner {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n        public FastScanner() {\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        public String nextLine() {\n        \ttry {\n        \t\treturn reader.readLine();\n        \t} catch(IOException e) {\n        \t\tthrow new RuntimeException(e);\n        \t}\n        }\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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    int n, t;\n    void solve(int TC) throws Exception{\n        n = ni();t = ni();\n        int[][] song = new int[n][];\n        for(int i = 0; i< n; i++)song[i] = new int[]{ni(), ni()-1};\n        long[][] dp = new long[1<<n][3];\n        for(int i = 0; i< dp.length; i++)\n            for(int j = 0; j< dp[i].length; j++)\n                dp[i][j] = -1;\n        pn(start(dp, song, 0, -1));\n    }\n    long start(long[][] dp, int[][] song, int mask, int prev){\n        long ti = 0;\n        for(int i = 0; i< n; i++){\n            if(((mask>>i)&1)==1)ti+=song[i][0];\n        }\n        if(ti==t)return 1;\n        if(prev != -1 && dp[mask][prev] != -1)return dp[mask][prev];\n        long ans = 0;\n        for(int i = 0; i< n; i++){\n            if(((mask>>i)&1)==0 && song[i][1] != prev && ti+song[i][0] <= t)\n                ans = (ans+start(dp, song, mask|(1<<i), song[i][1]))%mod;\n        }\n        if(prev!= -1)dp[mask][prev] = ans;\n        return ans;\n    }\n    //SOLUTION END\n    void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n    long mod = (long)1e9+7, IINF = (long)1e18;\n    final int INF = (int)1e9, MX = (int)2e5+5;\n    DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;\n    static boolean multipleTC = false, 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}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class G1 {\n    static final int mod = (int) (1e9 + 7);\n    static final int UNCALC = -1;\n    static int[][][] memo;\n    static int n, t[], genre[];\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        n = sc.nextInt();\n        t = new int[n];\n        int T = sc.nextInt();\n        genre = new int[n];\n        for (int i = 0; i < n; i++) {\n            t[i] = sc.nextInt();\n            genre[i] = sc.nextInt();\n        }\n        memo = new int[4][1 << n][T+1];\n        for (int[][] a : memo)\n            for (int[] b : a)\n                Arrays.fill(b, UNCALC);\n        out.println(dp(0, 0, T));\n        out.flush();\n        out.close();\n    }\n\n    static int dp(int last, int mask, int rem) {\n        if (rem==0) return 1;\n        if (memo[last][mask][rem] != UNCALC) return memo[last][mask][rem];\n        int cnt = 0;\n        for (int i = 0; i < n; i++) {\n            if (genre[i] == last || t[i] > rem || (mask & 1 << i) != 0) continue;\n            cnt = (cnt + dp(genre[i], mask | 1 << i, rem - t[i]))%mod;\n        }\n        return memo[last][mask][rem] = cnt;\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}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdC {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n    static char[][] grid;\n    static int n;\n    static int t;\n    static int[][] dp;\n    static int[] times;\n    static int[] genre;\n\tpublic static void main(String[] omkar) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\tn = sc.nextInt();\n \t\tt = sc.nextInt();\n \t\ttimes = new int[n];\n \t\tgenre = new int[n];\n \t\tfor(int j =0 ;j<n;j++){\n \t\t\ttimes[j] = sc.nextInt();\n \t\t\tgenre[j] = sc.nextInt();\t\t\n \t\t}\n \t\tdp = new int[1<<n][4];\n \t\tfor(int j = 0;j<1<<n;j++)\n \t\t\tArrays.fill(dp[j],  -1);\n \t\tfor(int j=0;j<1<<n;j++){\n \t\t\tletsgodp(j, 1);\n \t\t\tletsgodp(j, 2);\n \t\t\tletsgodp(j, 3);\n \t\t}\n \t\tint ans = 0;\n \t\tfor(int j=0;j<1<<n;j++){\n \t\t\tint time = 0;\n \t\t\tfor(int k = 0;k<n;k++){\n \t\t\t\tif (((1<<k) & j) != 0){\n \t\t\t\t\ttime+=times[k];\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (time == t){\n \t\t\t\tans+=dp[j][1];\n \t\t\t\tans%=mod;\n \t\t\t\tans+=dp[j][2];\n \t\t\t\tans%=mod;\n \t\t\t\tans+=dp[j][3];\n \t\t\t\tans%=mod;\n \t\t\t}\n \t\t}\n \t\tout.println(ans);\n \t\tout.close();\t\n \t}\n\tpublic static void letsgodp(int mask, int dg){\n\t\tif (dp[mask][dg] != -1)\n\t\t\treturn;\n\t\tdp[mask][dg] = 0;\n\t\tfor(int j = 0;j<n;j++){\n\t\t\tif (((1<<j) & mask) != 0 && genre[j] == dg){\n\t\t\t\tint submask = mask - (1<<j);\n\t\t\t\tint og1 = genre[j]+1 > 3 ? genre[j]-2 : genre[j]+1;\n\t\t\t\tint og2 = genre[j]+2 > 3 ? genre[j]-1 : genre[j]+2;\n\t\t\t\tif (submask != 0){\n\t\t\t\t\tletsgodp(submask, og1);\n\t\t\t\t\tletsgodp(submask, og2);\n\t\t\t\t\tdp[mask][dg] +=(dp[submask][og1] + dp[submask][og2]);\n\t\t\t\t\tdp[mask][dg] %=mod;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tdp[mask][dg] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<Integer>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "//package cf568d2;\nimport java.util.*;\npublic class G {\n    static int n,t;\n    static int[]a;\n    static int[]g;\n    static long[][][]dp;\n    static final long MOD=1000000007;\n    public static void main(String[]args){\n        Scanner sc=new Scanner(System.in);\n        n=sc.nextInt();\n        t=sc.nextInt();\n        a=new int[n];\n        g=new int[n];\n        for(int i=0;i<n;i++) {\n            a[i] = sc.nextInt();\n            g[i] = sc.nextInt();\n        }\n        dp=new long[4][1<<(n-1)+1][t+1];\n        for(int i=0;i<4;i++)\n            for(int j=0;j<1<<(n-1)+1;j++)\n                for(int k=0;k<=t;k++)\n                    dp[i][j][k]=-1;\n        System.out.println(dp(0,0,t));\n    }\n    private static long dp(int genre,int mask,int time){\n        if(time<0)\n            return 0;\n        if(dp[genre][mask][time]!=-1)\n            return dp[genre][mask][time];\n        if(time==0)\n            return 1;\n        dp[genre][mask][time]=0;\n        for(int i=0;i<n;i++) {\n            if (g[i] != genre && ((1 << i) & mask) == 0)\n                dp[genre][mask][time] = (dp[genre][mask][time]+dp(g[i], mask | (1 << i), time - a[i]))%MOD;\n        }\n        return dp[genre][mask][time];\n    }\n}\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n    public static long mod = 1000000007;\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        int n = Integer.parseInt(st.nextToken());\n        int t = Integer.parseInt(st.nextToken());\n        int[] d = new int[n];\n        int[] g = new int[n];\n        for(int i=0;i<n;i++){\n            st = new StringTokenizer(br.readLine());\n            d[i] = Integer.parseInt(st.nextToken());\n            g[i] = Integer.parseInt(st.nextToken())-1;\n        }\n        long[][] dp = new long[(1<<n)][3];\n        for(int i=0;i<n;i++){\n            dp[(1<<i)][g[i]] = 1;\n        }\n        long res = 0;\n        for(int i=1;i<(1<<n);i++){\n            int k = i;\n            int sum = 0;\n            for(int j=n-1;j>=0;j--){\n                if(k>=(1<<j)){\n                    k-=(1<<j);\n                    sum += d[j];\n                }\n                else{\n                    for(int r=0;r<3;r++) if(r!=g[j]) dp[i+(1<<j)][g[j]] += dp[i][r];\n                    dp[i+(1<<j)][g[j]] %= mod;\n                }\n            }\n            if(sum==t){\n                res += dp[i][0] +dp[i][1] +dp[i][2];\n                res %= mod;\n            }\n        }\n        out.println(res);\n        out.flush(); \n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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[] f = fact(15);\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\t\t\tfor (int j = 0; j < ct[1] + ct[2] + ct[3]; 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 || j - k - l > ct[3])\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\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][l][j - k - l + 1][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 m = 0; m <= 3; m++)\n\t\t\t\tres = add(res, mul(mul(f[ct[1]], f[ct[2]]), mul(f[ct[3]], dp[ct[1]][ct[2]][ct[3]][m])));\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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.StringTokenizer;\n \n public class realfast implements Runnable {\n    private static final int INF = (int) 1e9;\n    int time[]= new int[15];\n     int g[]= new int [15];\n    public  void solve() throws IOException \n    {\n     int n = readInt();\n     int t = readInt();\n     \n     for(int i=0;i<n;i++)\n     {\n     \ttime[i]=readInt();\n     \tg[i]=readInt();\n     }\n     long dp[][]= new long [(int)Math.pow(2,n)][4];\n     for(int i =0;i<(int)Math.pow(2,n);i++)\n     {\n      for(int j=0;j<=3;j++)\n       dp[i][j]=-1;\t\n     }\n     long val = cal(dp,0,0,0,t);\n     out.println(val);\n\n    }\n    public long cal(long dp[][], int mask , int genre , int t ,int T  )\n    {\n    \tint val = dp.length;\n  \n        if(t>T)\n        {\n         return 0;\t\n        }\n    \tif(t==T)\n    \t{\n    \t \treturn 1;\n    \t}\n      \n       if(dp[mask][genre]!=-1)\n        return dp[mask][genre];\n        dp[mask][genre]=0;\n       int i=1;\n       int count=0;\n       while(i<val)\n       {\n      \n       \tif((i&mask)==0&&g[count]!=genre)\n       \t{\n       \t \tdp[mask][genre] = ((dp[mask][genre]%1000000007)+ cal(dp,mask|i,g[count],t+time[count],T)%1000000007)%1000000007;\n       \t}\n       \ti=2*i;\n       \tcount++;\n       }\n       return dp[mask][genre];\n    }\n    \n\n    \n    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    public static void main(String[] args) {\n        new Thread(null, new realfast(), \"\", 128 * (1L << 20)).start();\n    }\n \n    private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n    private BufferedReader reader;\n    private StringTokenizer tokenizer;\n    private PrintWriter out;\n \n    @Override\n    public void run() {\n        try {\n            if (ONLINE_JUDGE || !new File(\"input.txt\").exists()) {\n                reader = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(System.out);\n            } else {\n                reader = new BufferedReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(\"output.txt\");\n            }\n            solve();\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        } finally {\n            try {\n                reader.close();\n            } catch (IOException e) {\n                // nothing\n            }\n            out.close();\n        }\n    }\n \n    private String readString() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n \n    @SuppressWarnings(\"unused\")\n    private int readInt() throws IOException {\n        return Integer.parseInt(readString());\n    }\n \n    @SuppressWarnings(\"unused\")\n    private long readLong() throws IOException {\n        return Long.parseLong(readString());\n    }\n \n    @SuppressWarnings(\"unused\")\n    private double readDouble() throws IOException {\n        return Double.parseDouble(readString());\n    }\n}\nclass edge implements Comparable<edge>{\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}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class codeforces {\n\n    public static long cnt = 0;\n\n    public static void f(int g1, int g2, int g3, int last) {\n        if (g1 == 0 && g2 == 0 && g3 == 0) cnt++;\n        if (g1 > 0 && last != 1) f(g1 - 1, g2, g3, 1);\n        if (g2 > 0 && last != 2) f(g1, g2 - 1, g3, 2);\n        if (g3 > 0 && last != 3) f(g1, g2, g3 - 1, 3);\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(scan.readLine());\n        int n = Integer.parseInt(st.nextToken());\n        int t = Integer.parseInt(st.nextToken());\n        int T[] = new int[n];\n        int G[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            st = new StringTokenizer(scan.readLine());\n            T[i] = Integer.parseInt(st.nextToken());\n            G[i] = Integer.parseInt(st.nextToken());\n        }\n        long ans = 0;\n        for (int mask = 1; mask < (1 << n); mask++) {\n            int sum = 0;\n            int g1 = 0;\n            int g2 = 0;\n            int g3 = 0;\n\n            for (int i = 0; i < n; i++) {\n                if (((1 << i) & mask) > 0) {\n                    sum += T[i];\n                    if (G[i] == 1) g1++;\n                    if (G[i] == 2) g2++;\n                    if (G[i] == 3) g3++;\n                }\n            }\n            cnt = 0;\n            if (sum == t) f(g1, g2, g3, -1);\n            for (long i = 1; i <= g1; i++) cnt *= i;\n            for (long i = 1; i <= g2; i++) cnt *= i;\n            for (long i = 1; i <= g3; i++) cnt *= i;\n            ans += cnt;\n        }\n        System.out.println(ans % 1000000007);\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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 Washoum\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        inputClass in = new inputClass(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        static final int mod = (int) 1e9 + 7;\n\n        public void solve(int testNumber, inputClass sc, PrintWriter out) {\n            int n = sc.nextInt();\n            int t = sc.nextInt();\n            G1PlaylistForPolycarpEasyVersion.Song[] songs = new G1PlaylistForPolycarpEasyVersion.Song[n];\n            for (int i = 0; i < n; i++) {\n                songs[i] = new G1PlaylistForPolycarpEasyVersion.Song(sc.nextInt(), sc.nextInt());\n            }\n            long ans = 0;\n            for (int mask = 1; mask < (1 << n); mask++) {\n                int nb = 0;\n                int tot = 0;\n                int type1 = 0;\n                int type2 = 0;\n                int type3 = 0;\n                for (int j = 0; j < n; j++) {\n                    if (((1 << j) & mask) > 0) {\n                        nb++;\n                        tot += songs[j].l;\n                        if (songs[j].type == 1) {\n                            type1++;\n                        } else if (songs[j].type == 2) {\n                            type2++;\n                        } else {\n                            type3++;\n                        }\n                    }\n                }\n\n                if (tot == t) {\n                    long[][][][][] dp = new long[nb + 1][3][type1 + 1][type2 + 1][type3 + 1];\n                    boolean[][][][][] go = new boolean[nb + 1][3][type1 + 1][type2 + 1][type3 + 1];\n                    if (type1 > 0) {\n                        go[1][0][type1 - 1][type2][type3] = true;\n                        dp[1][0][type1 - 1][type2][type3] = type1;\n                    }\n                    if (type2 > 0) {\n                        go[1][1][type1][type2 - 1][type3] = true;\n                        dp[1][1][type1][type2 - 1][type3] = type2;\n                    }\n                    if (type3 > 0) {\n                        go[1][2][type1][type2][type3 - 1] = true;\n                        dp[1][2][type1][type2][type3 - 1] = type3;\n                    }\n                    for (int i = 0; i < nb; i++) {\n                        for (int m = 0; m < 3; m++) {\n                            for (int j = 0; j <= type1; j++) {\n                                for (int k = 0; k <= type2; k++) {\n                                    for (int l = 0; l <= type3; l++) {\n                                        if (go[i][m][j][k][l]) {\n                                            if (m == 0) {\n                                                if (k > 0) {\n                                                    dp[i + 1][1][j][k - 1][l] += dp[i][m][j][k][l] * k;\n                                                    dp[i + 1][1][j][k - 1][l] %= mod;\n                                                    go[i + 1][1][j][k - 1][l] = true;\n                                                }\n                                                if (l > 0) {\n                                                    dp[i + 1][2][j][k][l - 1] += dp[i][m][j][k][l] * l;\n                                                    dp[i + 1][2][j][k][l - 1] %= mod;\n                                                    go[i + 1][2][j][k][l - 1] = true;\n                                                }\n                                            } else if (m == 1) {\n                                                if (j > 0) {\n                                                    dp[i + 1][0][j - 1][k][l] += dp[i][m][j][k][l] * j;\n                                                    dp[i + 1][0][j - 1][k][l] %= mod;\n                                                    go[i + 1][0][j - 1][k][l] = true;\n                                                }\n                                                if (l > 0) {\n                                                    dp[i + 1][2][j][k][l - 1] += dp[i][m][j][k][l] * l;\n                                                    dp[i + 1][2][j][k][l - 1] %= mod;\n                                                    go[i + 1][2][j][k][l - 1] = true;\n                                                }\n                                            } else {\n                                                if (j > 0) {\n                                                    dp[i + 1][0][j - 1][k][l] += dp[i][m][j][k][l] * j;\n                                                    dp[i + 1][0][j - 1][k][l] %= mod;\n                                                    go[i + 1][0][j - 1][k][l] = true;\n                                                }\n                                                if (k > 0) {\n                                                    dp[i + 1][1][j][k - 1][l] += dp[i][m][j][k][l] * k;\n                                                    dp[i + 1][1][j][k - 1][l] %= mod;\n                                                    go[i + 1][1][j][k - 1][l] = true;\n                                                }\n                                            }\n                                        }\n                                    }\n                                }\n                            }\n                        }\n                    }\n                    long toadd = 0;\n                    for (int i = 0; i < 3; i++) {\n                        toadd += dp[nb][i][0][0][0];\n                    }\n                    ans += toadd;\n                    ans %= (int) 1e9 + 7;\n                }\n            }\n            out.println(ans);\n        }\n\n        static class Song {\n            int l;\n            int type;\n\n            public Song(int x, int y) {\n                l = x;\n                type = y;\n            }\n\n        }\n\n    }\n\n    static class inputClass {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public inputClass(InputStream in) {\n\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\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Aman Kumar Singh\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        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        final long mod = 1000000007;\n        PrintWriter out;\n        InputReader in;\n        int n;\n        int time;\n        int[][] arr;\n        long[][][] dp;\n\n        long go(int last, int t, int mask) {\n            if (t > time)\n                return 0;\n            if (t == time) {\n                return 1l;\n            }\n            if (mask == (1 << n) - 1)\n                return 0;\n            if (dp[last][t][mask] != -1)\n                return dp[last][t][mask];\n            long cnt = 0;\n            int i = 0, j = 0;\n            for (i = 0; i < n; i++) {\n                if ((mask & (1 << i)) == 0 && arr[i][1] != last) {\n                    cnt += go(arr[i][1], t + arr[i][0], mask | (1 << i));\n                    cnt %= mod;\n\n                }\n            }\n            dp[last][t][mask] = cnt;\n            return cnt;\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            this.out = out;\n            this.in = in;\n            n = ni();\n            time = ni();\n            arr = new int[n][2];\n            int i = 0;\n            for (i = 0; i < n; i++) {\n                arr[i][0] = ni();\n                arr[i][1] = ni() - 1;\n            }\n            dp = new long[3][time + 1][1 << n];\n            for (i = 0; i < 3; i++) {\n                for (int j = 0; j <= time; j++)\n                    Arrays.fill(dp[i][j], -1);\n            }\n            long ans = (((go(0, 0, 0) + go(1, 0, 0)) % mod + go(2, 0, 0)) % mod);\n            ans *= modPow(2, mod - 2);\n            ans %= mod;\n            pn(ans);\n        }\n\n        int ni() {\n            return in.nextInt();\n        }\n\n        void pn(Object o) {\n            out.println(o);\n        }\n\n        long modPow(long a, long p) {\n            long o = 1;\n            while (p > 0) {\n                if ((p & 1) == 1) o = mul(o, a);\n                a = mul(a, a);\n                p >>= 1;\n            }\n            return o;\n        }\n\n        long mul(long a, long b) {\n            if (a >= mod) a %= mod;\n            if (b >= mod) b %= mod;\n            a *= b;\n            if (a >= mod) a %= mod;\n            return a;\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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Sparsh Sanchorawala\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class G1PlaylistForPolycarpEasyVersion {\n        long mod = (long) 1e9 + 7;\n\n        public void solve(int testNumber, InputReader s, PrintWriter w) {\n            int n = s.nextInt(), T = s.nextInt();\n            int[] t = new int[n + 1];\n            int[] g = new int[n + 1];\n            int[] f = new int[4];\n            for (int i = 1; i <= n; i++) {\n                t[i] = s.nextInt();\n                g[i] = s.nextInt();\n                f[g[i]]++;\n            }\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            long[][][][] perm = new long[f[1] + 1][f[2] + 1][f[3] + 1][3 + 1];\n            long[][][] sumPerm = new long[f[1] + 1][f[2] + 1][f[3] + 1];\n            perm[0][0][0][0] = 1;\n            for (int a = 0; a <= f[1]; a++) {\n                for (int b = 0; b <= f[2]; b++) {\n                    for (int c = 0; c <= f[3]; c++) {\n                        if (a - 1 >= 0)\n                            perm[a][b][c][1] = (sumPerm[a - 1][b][c] - perm[a - 1][b][c][1] + mod) % mod;\n                        if (b - 1 >= 0)\n                            perm[a][b][c][2] = (sumPerm[a][b - 1][c] - perm[a][b - 1][c][2] + mod) % mod;\n                        if (c - 1 >= 0)\n                            perm[a][b][c][3] = (sumPerm[a][b][c - 1] - perm[a][b][c - 1][3] + mod) % mod;\n                        for (int i = 0; i <= 3; i++)\n                            sumPerm[a][b][c] = (sumPerm[a][b][c] + perm[a][b][c][i]) % mod;\n                    }\n                }\n            }\n            long[][][][][] dp = new long[n + 1][f[1] + 1][f[2] + 1][f[3] + 1][T + 1];\n            dp[0][0][0][0][0] = 1;\n            for (int i = 1; i <= n; i++) {\n                for (int a = 0; a <= f[1]; a++) {\n                    for (int b = 0; b <= f[2]; b++) {\n                        for (int c = 0; c <= f[3]; c++) {\n                            for (int j = 0; j <= T; j++) {\n                                dp[i][a][b][c][j] = dp[i - 1][a][b][c][j];\n                                if (j - t[i] >= 0) {\n                                    if (g[i] == 1 && a > 0) {\n                                        dp[i][a][b][c][j] = (dp[i][a][b][c][j] + dp[i - 1][a - 1][b][c][j - t[i]]) % mod;\n                                    } else if (g[i] == 2 && b > 0) {\n                                        dp[i][a][b][c][j] = (dp[i][a][b][c][j] + dp[i - 1][a][b - 1][c][j - t[i]]) % mod;\n                                    } else if (g[i] == 3 && c > 0) {\n                                        dp[i][a][b][c][j] = (dp[i][a][b][c][j] + dp[i - 1][a][b][c - 1][j - t[i]]) % mod;\n                                    }\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n            long res = 0;\n            for (int a = 0; a <= f[1]; a++)\n                for (int b = 0; b <= f[2]; b++)\n                    for (int c = 0; c <= f[3]; c++)\n                        res = (res + dp[n][a][b][c][T] * sumPerm[a][b][c] % mod * fact[a] % mod * fact[b] % mod * fact[c] % mod) % mod;\n            w.println(res);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class codeforces {\n\n    public static long cnt = 0;\n\n    public static void f(int g1, int g2, int g3, int last) {\n        if (g1 == 0 && g2 == 0 && g3 == 0) cnt++;\n        if (g1 > 0 && last != 1) f(g1 - 1, g2, g3, 1);\n        if (g2 > 0 && last != 2) f(g1, g2 - 1, g3, 2);\n        if (g3 > 0 && last != 3) f(g1, g2, g3 - 1, 3);\n    }\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(scan.readLine());\n        int n = Integer.parseInt(st.nextToken());\n        int t = Integer.parseInt(st.nextToken());\n        int T[] = new int[n];\n        int G[] = new int[n];\n        for (int i = 0; i < n; i++) {\n            st = new StringTokenizer(scan.readLine());\n            T[i] = Integer.parseInt(st.nextToken());\n            G[i] = Integer.parseInt(st.nextToken());\n        }\n        long ans = 0;\n        for (int mask = 1; mask < (1 << n); mask++) {\n            int sum = 0;\n            int g1 = 0;\n            int g2 = 0;\n            int g3 = 0;\n\n            for (int i = 0; i < n; i++) {\n                if (((1 << i) & mask) > 0) {\n                    sum += T[i];\n                    if (G[i] == 1) g1++;\n                    if (G[i] == 2) g2++;\n                    if (G[i] == 3) g3++;\n                }\n            }\n            cnt = 0;\n            if (sum == t) f(g1, g2, g3, -1);\n            for (long i = 1; i <= g1; i++) cnt *= i;\n            for (long i = 1; i <= g2; i++) cnt *= i;\n            for (long i = 1; i <= g3; i++) cnt *= i;\n            ans += cnt;\n        }\n        System.out.println(ans % 1000000007);\n    }\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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 % 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}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\npublic class G_PlaylistForPolycarp {\n\n\tstatic final int mod = 1000000007;\n\n\tstatic int dp[][];\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\n\t\tString[] dat = br.readLine().split(\" \");\n\n\t\tint n = Integer.parseInt(dat[0]);\n\t\tint T = Integer.parseInt(dat[1]);\n\n\t\tint[] st = new int[n];\n\t\tbyte[] sg = new byte[n];\n\n\t\tdp = new int[1 << (n + 1)][4];\n\n\t\tfor (int j = 0; j < 1 << (n + 1); j++) {\n\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\tdp[j][k] = -1;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdat = br.readLine().split(\" \");\n\t\t\tst[i] = Integer.parseInt(dat[0]);\n\t\t\tsg[i] = Byte.parseByte(dat[1]);\n\t\t}\n\n\t\tshort visited = 0;\n\n\t\tint count = recur(0, visited, st, sg, T, 0);\n\n\t\tbw.write(count + \"\\n\");\n\n\t\tbw.close();\n\n\t}\n\n\tprivate static int recur(int time, short visited, int[] st, byte[] sg, int T, int last) {\n\n\t\tint count = 0;\n\n\t\tif (dp[visited][last] != -1) {\n\t\t\treturn dp[visited][last];\n\t\t}\n\n\t\tfor (int i = 0; i < st.length; i++) {\n\n\t\t\tif ((visited & (1 << i)) == 0 && sg[i] != last) {\n\n\t\t\t\tif (time + st[i] == T) {\n\t\t\t\t\tcount += 1;\n\t\t\t\t} else if (time + st[i] < T) {\n\t\t\t\t\tshort visitedc = (short) (visited | (1 << i));\n\t\t\t\t\tcount += recur(time + st[i], visitedc, st, sg, T, sg[i]);\n\t\t\t\t\tif (count > mod) {\n\t\t\t\t\t\tcount = count % mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn dp[visited][last] = count % mod;\n\t}\n\n}\n", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "/*Author: Satyajeet Singh, Delhi Technological University*/\n    import java.io.*;\n    import java.util.*;\n    import java.text.*; \n    import java.lang.*;\n    import java.math.*;\n \npublic class Main{\n/*********************************************Constants******************************************/\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        \n    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    static long mod=(long)1e9+7;\n    static long mod1=998244353;\n    static boolean sieve[];\n    static ArrayList<Integer> primes;\n    static long factorial[],invFactorial[];\n    static HashSet<Pair> graph[];\n    static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n/****************************************Solutions Begins***************************************/\n    static int n,T,input[],type[];\n    static long dp[][];\n\n    static long dfs(int mask,int t){\n\n        if(dp[mask][t]!=-1){\n            return dp[mask][t];\n        }\n        int s=0;\n        for(int i=0;i<n;i++){\n            if((mask&(1<<i))!=0){\n                s+=input[i];\n            }\n        }\n        if(s>T){\n            return 0;\n        }\n        if(s==T){\n            dp[mask][t]=1;\n            return dp[mask][t];\n        }\n        long ans=0;\n        for(int i=0;i<n;i++){\n            if((mask&(1<<i))==0&&type[i]!=t){\n                ans=(ans+dfs(mask|(1<<i),type[i]))%mod;\n            }\n        }\n        dp[mask][t]=ans;\n        return dp[mask][t];\n    }\n    public static void main (String[] args) throws Exception {\n        String st[]=nl();\n        n=pi(st[0]);\n        T=pi(st[1]);\n        input=new int[n];\n        type=new int[n];\n        for(int i=0;i<n;i++){\n            st=nl();\n            input[i]=pi(st[0]);\n            type[i]=pi(st[1]);\n        }\n        dp=new long[1<<n][4];\n        for(long arr[]:dp)\n            Arrays.fill(arr,-1);\n        long ans=dfs(0,0);\n       // debug(dp);\n\n        out.println(ans);\n/****************************************Solutions Ends**************************************************/\n        out.flush();\n        out.close();\n    }\n/****************************************Template Begins************************************************/\n    static String[] nl() throws Exception{\n        return br.readLine().split(\" \");\n    }\n    static String[] nls() throws Exception{\n        return br.readLine().split(\"\");\n    }\n    static int pi(String str) {\n        return Integer.parseInt(str);\n    }\n    static long pl(String str){\n        return Long.parseLong(str);\n    }\n    static double pd(String str){\n        return Double.parseDouble(str);\n    }\n/***************************************Precision Printing**********************************************/\n    static void printPrecision(double d){\n        DecimalFormat ft = new DecimalFormat(\"0.00000000000000000\"); \n        out.println(ft.format(d));\n    }\n/**************************************Bit Manipulation**************************************************/\n    static void printMask(long mask){\n        System.out.println(Long.toBinaryString(mask));\n    }\n    static int countBit(int mask){\n        int ans=0;\n        while(mask!=0){\n            if(mask%2==1){\n                ans++;\n            }\n            mask/=2;\n        }\n        return ans;\n    }\n/******************************************Graph*********************************************************/\n    static void Makegraph(int n){\n        graph=new HashSet[n];\n        for(int i=0;i<n;i++){\n            graph[i]=new HashSet<>();\n        }\n    }\n    static void addEdge(int a,int b){\n        graph[a].add(new Pair(b,1));\n    }\n    static void addEdge(int a,int b,int c){\n        graph[a].add(new Pair(b,c));\n    }    \n/*********************************************PAIR********************************************************/\n    static class PairComp implements Comparator<Pair>{\n        public int compare(Pair p1,Pair p2){\n            return ((p1.u+p1.v)-(p2.u+p2.v));\n        }\n    }\n    static class Pair implements Comparable<Pair> {\n        int u;\n        int v;\n        int index=-1;\n        public Pair(int u, int v) {\n            this.u = u;\n            this.v = v;\n        }\n        public int hashCode() {\n            int hu = (int) (u ^ (u >>> 32));\n            int hv = (int) (v ^ (v >>> 32));\n            return 31 * hu + hv;\n        }\n        public boolean equals(Object o) {\n            Pair other = (Pair) o;\n            return u == other.u && v == other.v;\n        }\n        public int compareTo(Pair other) {\n            if(index!=other.index)\n                return Long.compare(index, other.index);\n            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n        }\n        public String toString() {\n            return \"[u=\" + u + \", v=\" + v + \"]\";\n        }\n    }\n/******************************************Long Pair*************************************************/\n    static class PairCompL implements Comparator<Pairl>{\n        public int compare(Pairl p1,Pairl p2){\n            if((p1.u+2*p1.v)-(p2.u+2*p2.v)<0){\n                return -1;\n            }\n            else if((p1.u+2*p1.v)-(p2.u+2*p2.v)>0){\n                return 1;\n            }\n            else{\n                return 0;\n            }\n        }\n    }\n    static class Pairl implements Comparable<Pairl> {\n            long u;\n            long v;\n            int index=-1;\n            public Pairl(long u, long v) {\n                this.u = u;\n                this.v = v;\n            }\n    \n            public int hashCode() {\n                int hu = (int) (u ^ (u >>> 32));\n                int hv = (int) (v ^ (v >>> 32));\n                return 31 * hu + hv;\n            }\n    \n            public boolean equals(Object o) {\n                Pair other = (Pair) o;\n                return u == other.u && v == other.v;\n            }\n    \n            public int compareTo(Pairl other) {\n                if(index!=other.index)\n                    return Long.compare(index, other.index);\n                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n            }\n    \n            public String toString() {\n                return \"[u=\" + u + \", v=\" + v + \"]\";\n            }\n        }\n/*****************************************DEBUG***********************************************************/\n    public static void debug(Object... o) {\n        if(!oj)\n        System.out.println(Arrays.deepToString(o));\n    }\n/************************************MODULAR EXPONENTIATION***********************************************/\n    static long modulo(long a,long b,long c) {\n        long x=1;\n        long y=a;\n        while(b > 0){\n            if(b%2 == 1){\n                x=(x*y)%c;\n            }\n            y = (y*y)%c; // squaring the base\n            b /= 2;\n        }\n        return  x%c;\n    }\n/********************************************GCD**********************************************************/\n    static long gcd(long x, long y)\n    {\n        if(x==0)\n            return y;\n        if(y==0)\n            return x;\n        long r=0, a, b;\n        a = (x > y) ? x : y; // a is greater number\n        b = (x < y) ? x : y; // b is smaller number\n        r = b;\n        while(a % b != 0)\n        {\n            r = a % b;\n            a = b;\n            b = r;\n        }\n        return r;\n    }\n/******************************************SIEVE**********************************************************/\n    static void sieveMake(int n){\n        sieve=new boolean[n];\n        Arrays.fill(sieve,true);\n        sieve[0]=false;\n        sieve[1]=false;\n        for(int i=2;i*i<n;i++){\n            if(sieve[i]){\n                for(int j=i*i;j<n;j+=i){\n                    sieve[j]=false;\n                }\n            }\n        }\n        primes=new ArrayList<Integer>();\n        for(int i=0;i<n;i++){\n            if(sieve[i]){\n                primes.add(i);\n            }\n        }        \n    }\n/********************************************End***********************************************************/\n}", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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.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        Scanner in = new Scanner(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        static ArrayList<Integer> list;\n        static int n;\n        static int req;\n        static int mod = (int) 1e9 + 7;\n        static int[] dur;\n        static int[] genre;\n        static Integer[][][] memo;\n\n        public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n            n = sc.nextInt();\n            req = sc.nextInt();\n            dur = new int[n];\n            genre = new int[n];\n            list = new ArrayList<>();\n            for (int i = 0; i < n; i++) {\n                dur[i] = sc.nextInt();\n                genre[i] = sc.nextInt();\n            }\n            int ans = 0;\n            memo = new Integer[1 << n][n + 1][4];\n            for (int i = 0; i <= n; i++)\n                ans += bf(0, 0, 0, i) % mod;\n            pw.print(ans % mod);\n        }\n\n        private int bf(int idx, int msk, int before, int max) {\n            if (idx == max) {\n                int sum = 0;\n                for (int x : list)\n                    sum += x;\n                if (sum == req)\n                    return 1;\n                return 0;\n            }\n            if (memo[msk][max][before] != null)\n                return memo[msk][max][before] % mod;\n            int toRet = 0;\n            for (int i = 0; i < n; i++) {\n                if (genre[i] != before && (msk & 1 << i) == 0) {\n                    list.add(dur[i]);\n                    toRet += bf(idx + 1, msk | 1 << i, genre[i], max);\n                    toRet %= mod;\n                    list.remove(list.size() - 1);\n                }\n            }\n            return memo[msk][max][before] = (toRet % 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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "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 % 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", "complexity": "np", "problem": "1185_G1. Playlist for Polycarp (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n\n    int[] x;\n    int[] y;\n    int n;\n    int X, Y;\n\n    int[] d;\n    int[][] dist;\n\n    int sqr(int a) {\n        return a * a;\n    }\n\n    int dist(int X, int Y, int i) {\n        return sqr(X - x[i]) + sqr(Y - y[i]);\n    }\n\n    int[] dp;\n    byte[][] pred;\n\n    int rec(int mask) {\n        if (dp[mask] == -1) {\n            int res = 1 << 29;\n            boolean ok = false;\n            for (int i = 0; i < n; ++i)\n                if ((mask & (1 << i)) > 0) {\n                    ok = true;\n                    int mm = mask & ~(1 << i);\n                    for (int j = i; j < n; j++)\n                        if ((mask & (1 << j)) > 0) {\n                            int nmask = mm & ~(1 << j);\n                            int a = rec(nmask) + d[i] + d[j] + dist[i][j];\n                            if (a < res) {\n                                res = a;\n                                pred[0][mask] = (byte) (i);\n                                pred[1][mask] = (byte) (j);\n                            }\n                        }\n                    break;\n                }\n            if (!ok)\n                res = 0;\n            dp[mask] = res;\n        }\n        return dp[mask];\n    }\n\n    void solve() throws IOException {\n        X = ni();\n        Y = ni();\n        n = ni();\n        x = new int[n];\n        y = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = ni();\n            y[i] = ni();\n        }\n        d = new int[n];\n        dist = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            d[i] = dist(X, Y, i);\n        for (int i = 0; i < n; ++i)\n            for (int j = 0; j < n; j++) {\n                dist[i][j] = dist(x[i], y[i], j);\n            }\n        pred = new byte[2][1 << n];\n        dp = new int[1 << n];\n        Arrays.fill(dp, -1);\n        out.println(rec((1 << n) - 1));\n        int a = (1 << n) - 1;\n        while (a > 0) {\n            if (pred[0][a] != pred[1][a])\n                out.print(0 + \" \" + (pred[0][a] + 1) + \" \" + (pred[1][a] + 1)\n                        + \" \");\n            else\n                out.print(0 + \" \" + (pred[0][a] + 1) + \" \");\n            int na = a & ~(1 << pred[0][a]);\n            na &= ~(1 << pred[1][a]);\n            a = na;\n        }\n        out.println(0);\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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by 11815 on 2017/7/1.\n */\npublic class Main {\n    private static int[] x = new int[26], y = new int[26], dp = new int[1<<24], pre = new int[1<<24];\n    private static int dis(int i, int j) {\n        return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);\n    }\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int x0 = in.nextInt(), y0 = in.nextInt(), n = in.nextInt();\n        for (int i = 0; i < n; i++) {\n            x[i] = in.nextInt();\n            y[i] = in.nextInt();\n        }\n        x[n] = x0;\n        y[n] = y0;\n        int[][] gra = new int[26][26];\n        for (int i = 0; i < n + 1; i++) {\n            for (int j = i+1; j < n+1; j++) {\n                gra[i][j] = gra[j][i] = dis(i,j);\n            }\n        }\n        Arrays.fill(dp, -1);\n        dp[0] = 0;\n        for (int i = 0; i < 1 << n; i++) {\n            if (dp[i] != -1) {\n                for (int j = 0; j < n; j++) {\n                    if (((1<<j)&i) == 0) {\n                        int t = i | (1<<j), tmp = dp[i] + 2*gra[j][n];\n                        if (dp[t] == -1 || dp[t] > tmp) {\n                            dp[t] = tmp;\n                            pre[t] = i;\n                        }\n                        for (int k = 0; k < n; k++) {\n                            if ((t&(1<<k)) == 0) {\n                                int t2 = t | (1<<k), tmp2 = dp[i] + gra[n][j] + gra[j][k] + gra[k][n];\n                                if (dp[t2] == -1 || dp[t2] > tmp2) {\n                                    dp[t2] = tmp2;\n                                    pre[t2] = i;\n                                }\n                            }\n                        }\n                        break;\n                    }\n                }\n            }\n        }\n        int end = (1<<n)-1, cnt = 0;\n        int[] ans = new int[60];\n        System.out.println(dp[end]);\n        while (end != 0) {\n            int pr = pre[end];\n            int tem = pr^end;\n            int a = 0, b = 0;\n            for (int i = 0; i < n; i++) {\n                if (((1<<i)&tem)!=0) {\n                    b=a;\n                    a=i+1;\n                }\n            }\n            ans[cnt++] = 0;\n            ans[cnt++] = a;\n            if (b>0) {\n                ans[cnt++] = b;\n            }\n            end = pr;\n        }\n        ans[cnt++] = 0;\n        for (int i = cnt-1; i >= 0; i--) {\n            System.out.print(ans[i] + \" \");\n        }\n        System.out.print(\"\\n\");\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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\n/** Created by huhansan on 2017/10/9. */\npublic class CF_8C implements Runnable {\n  int[] step = new int[1 << 24]; //\u6bcf\u4e2a\u72b6\u6001\u6240\u9700\u8981\u7684\u6b65\u6570\n  int[] steplast = new int[1 << 24]; //\u5f53\u524d\u72b6\u6001\u4e0a\u4e00\u4e2a\n  int n;\n  int vs[] = new int[24];\n  int vd[][] = new int[24][24];\n  int x_bag, y_bag;\n  int x[] = new int[24], y[] = new int[24];\n  /** */\n  private void solve() throws IOException {\n    x_bag = nextInt();\n    y_bag = nextInt();\n    n = nextInt();\n    for (int i = 0; i < n; i++) {\n      x[i] = nextInt();\n      y[i] = nextInt();\n    }\n\n    //\u8ba1\u7b97\u6240\u6709\u7269\u54c1\u5355\u53d6\u7684\u5168\u503c\u548c \u4efb\u610f\u4e24\u4ef6\u7269\u54c1\u4e00\u8d77\u53d6\u7684\u6743\u503c\n    for (int i = 0; i < n; i++) {\n      vs[i] = 2 * ((x[i] - x_bag) * (x[i] - x_bag) + (y[i] - y_bag) * (y[i] - y_bag));\n    }\n    for (int i = 0; i < n; i++) {\n      for (int j = i + 1; j < n; j++) {\n        vd[i][j] =\n            (x[i] - x_bag) * (x[i] - x_bag)\n                + (y[i] - y_bag) * (y[i] - y_bag)\n                + (x[j] - x_bag) * (x[j] - x_bag)\n                + (y[j] - y_bag) * (y[j] - y_bag)\n                + (x[i] - x[j]) * (x[i] - x[j])\n                + (y[i] - y[j]) * (y[i] - y[j]);\n      }\n    }\n\n    //\u8bb0\u5f55\u8fbe\u5230\u6bcf\u4e00\u4e2a\u72b6\u6001\u6240\u9700\u7684\u6700\u5c0f\u6b65\u6570\u548c\u6700\u540e\u4e00\u6b21\u53d6\u5f97\u7269\u54c1\n    for (int i = 1; i < 1 << n; i++) {\n      int j, k = 0, l, m, lastState;\n      for (j = 1; (i & j) == 0 && j < 1 << n; j <<= 1) {\n        k++;\n      }\n      lastState = i & (~j);\n      step[i] = step[lastState] + vs[k];\n      steplast[i] = lastState;\n      m = k;\n      for (l = j << 1; l < 1 << n; l <<= 1) {\n        m++;\n        if ((lastState & l) != 0) {\n          if (step[i] > step[lastState & (~l)] + vd[k][m]) {\n            step[i] = step[lastState & (~l)] + vd[k][m];\n            steplast[i] = lastState & (~l);\n          }\n        }\n      }\n      //      System.out.println(steplast[i]+\"---\"+i+\"---\"+step[i]);\n    }\n    writer.println(step[(1 << n) - 1]);\n    int i = (1 << n) - 1;\n    writer.print(\"0 \");\n    while (i != 0) {\n      for (int j = 1, m = 1; j <= i; j <<= 1, m++) {\n        if ((j & (i ^ steplast[i])) != 0) {\n          writer.print(m + \" \");\n        }\n      }\n      writer.print(\"0 \");\n      i = steplast[i];\n    }\n  }\n\n  public static void main(String[] args) {\n    new CF_8C().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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;         \nimport java.util.*;         \nimport java.math.*;         \n \npublic class Main  implements Runnable {\n//public static final String FileName = \"test\";\nStreamTokenizer ST;      \nPrintWriter out;      \nBufferedReader br;   \nScanner in;\nstatic final int inf = 1000000000+10;\n \nint nextInt() throws IOException{      \n    ST.nextToken();      \n    return (int)ST.nval;      \n}\nlong nextLong() throws IOException{      \n    ST.nextToken();      \n    return (long)ST.nval;      \n}      \nString next() throws IOException{      \n    ST.nextToken();      \n    return ST.sval;      \n}      \ndouble nextD() throws IOException{      \n    ST.nextToken();      \n    return ST.nval;      \n}      \npublic static void main(String[] args) throws IOException {       \n   new Thread(new Main()).start();\n//\tnew Main().run();\n}\n \npublic void run()  {      \n    try {\n    \tbr = new BufferedReader(new InputStreamReader(System.in));\n    \tout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));    \t\n    \t//br = new BufferedReader(new FileReader(new File(FileName+\".in\")));\n    \t//out = new PrintWriter(new BufferedWriter(new FileWriter(FileName+\".out\")));\n    \t//in = new Scanner(br);\n        ST = new StreamTokenizer(br);      \n        solve();      \n        out.close();\n        //in.close();\n        br.close();   \n    }         \n    catch (IOException e) {       \n    \te.printStackTrace();\n    \tthrow new IllegalStateException(e);  \n    }      \n}\n\n\npublic void solve() throws IOException {\n\tint[] x = new int[32];\n\tint[] y = new int[32];\n\tx[0] = nextInt();\n\ty[0] = nextInt();\t\n\tint n = nextInt();\n\tfor (int i=1; i<=n; i++) {\n\t\tx[i] = nextInt();\n\t\ty[i] = nextInt();\n\t}\n\tn++;\n\tint[][] a = new int[n][n];\n\tint[][] b = new int[n-1][n-1];\n\tfor (int i=0; i<n; i++)\n\t\tfor (int j=0; j<n; j++)\n\t\t\ta[i][j] = (x[i]-x[j])*(x[i]-x[j])+ (y[i]-y[j])*(y[i]-y[j]);\n\tfor (int i=1; i<n; i++)\n\t\tfor (int j=1; j<n; j++)\n\t\t\tif (i!=j) b[i-1][j-1] = a[0][i]+a[i][j]+a[j][0]; else b[i-1][j-1] = 2*a[0][i];\n\tn--;\n\t\n\tint sz = 1<<n;\n\tint[] d = new int[sz];\n\tint[] p = new int[sz];\n\td[1] = 0;\n\tfor (int msk=1; msk<sz; msk++) {\n\t\tint j = 0;\n\t\twhile ((msk&(1<<j))==0) j++;\n\t\tint t = inf;\t\t\n\t\tfor (int i=0; i<n; i++)\n\t\t\tif ((msk&(1<<i))>0)\n\t\t\tif (t>d[msk^((1<<i)|(1<<j))]+b[i][j]) {\n\t\t\t\tt = d[msk^((1<<i)|(1<<j))]+b[i][j];\n\t\t\t\tp[msk] = i*n+j;\n\t\t\t}\t\n\t\td[msk] = t;\n\t\t\n\t}\n\tout.println(d[sz-1]);\n\tout.print(\"0 \");\n\tint t = sz-1;\n\twhile (t>0) {\n\t\tint hz = p[t];\n\t\tint i = hz/n;\n\t\tint j = hz%n;\n\t\tif (i!=j) out.print((i+1)+\" \"+(j+1)+\" 0 \");else out.print((i+1)+\" 0 \");\n\t\tt ^= (1<<i)|(1<<j);\n\t}\n\t\n}\n  \n}\n \n \n  ", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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   return Integer.parseInt(next());\n    }\n\n    int []x,y;\n    int n;\n    int []dp, prev;\n    \n    public void run() throws Exception{\n    \tin = new BufferedReader(new InputStreamReader(System.in));\n    \tout = new PrintWriter(System.out);\n\n    \tint xs = nextInt();\n    \tint ys = nextInt();\n    \tn = nextInt();\n    \tx = new int[n];\n    \ty = new int[n];\n    \tfor(int i=0;i<n;i++){\n    \t\tx[i] = nextInt();\n    \t\ty[i] = nextInt();\n    \t}\n\n    \tint one[] = new int[n];\n    \tfor(int i=0;i<n;i++){\n    \t\tone[i] = dist(xs, ys, x[i], y[i]);\n    \t}\n\n    \tint two[][] = new int[n][n];\n    \tfor(int i=0;i<n;i++){\n    \t\tfor(int j=i+1;j<n;j++){\n    \t\t\ttwo[i][j] = two[j][i] = dist(xs, ys, x[i], y[i]) + dist(x[i], y[i], x[j], y[j]) + dist(xs, ys, x[j], y[j]);\n    \t\t}\n    \t}\n\n    \tdp = new int[1<<n];\n    \tArrays.fill(dp, Integer.MAX_VALUE/2);\n    \tdp[0] = 0;\n    \tprev = new int[1<<n];\n    \tArrays.fill(prev, -1);\n\n    \tfor(int mask=1;mask<(1<<n);mask++){\n    \t\tint i = 0;\n    \t\twhile((mask & (1<<i)) == 0) i++;\n    \t\tdp[mask] = dp[mask ^ (1<<i)] + 2*one[i];\n    \t\tprev[mask] = i+1;\n    \t\tfor(int j=i+1;j<n;j++){\n    \t\t\tif ((mask & (1<<j)) > 0) {\n    \t\t\t\tif (dp[mask] > dp[mask ^ (1<<i) ^ (1<<j)] + two[i][j]) {\n    \t\t\t\t\tdp[mask] = dp[mask ^ (1<<i) ^ (1<<j)] + two[i][j];\n    \t\t\t\t\tprev[mask] = 100 * (i+1) + (j+1);\n    \t\t\t\t}\n    \t\t\t}\n    \t\t}\n    \t}\n\n    \tout.println(dp[(1<<n)-1]);\n    \tout.print(0 + \" \");\n    \tint cur = (1<<n)-1;\n    \tint i = 0, j = 0;\n    \twhile(cur > 0) {\n    \t\ti = prev[cur]/100;\n    \t\tj = prev[cur]%100;\n    \t\t\n    \t\tif (i > 0) {\n    \t\t\tcur^=1<<(i-1);\n    \t\t\tout.print(i + \" \");\n    \t\t}\n\n    \t\tif (j > 0) {\n    \t\t\tcur^=1<<(j-1);\n    \t\t\tout.print(j + \" \");\n    \t\t}\n\n    \t\tout.print(0 + \" \");\n    \t}\n    \t// if (i == 0 || j == 0) {\n    \t// \tout.println(0);\t\n    \t// }\n\t\tout.close();\t\n    }\n\n    private String bit2str(int mask, int n) {\n    \tString s = \"\";\n    \tfor(int i=0;i<n;i++){\n    \t\tif ((mask & (1<<i)) > 0){\n    \t\t\ts+=\"1\";\n    \t\t}else{\n    \t\t\ts+=\"0\";\n    \t\t}\n    \t}\n    \twhile(s.length() < n)\n    \t\ts+=\"0\";\n\n    \treturn new StringBuilder(s).reverse().toString();\n    }\n\n    private int dist(int x1, int y1, int x2, int y2) {\n    \treturn (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n    }\n\n    public static void main(String args[]) throws Exception{\n\t   new Main().run();\n    }\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n// Jonathan\n// cpt_fwiffo\n\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String[] line = in.readLine().split(\" \");\n        int Xs = Integer.parseInt(line[0]);\n        int Ys = Integer.parseInt(line[1]);\n        int n = Integer.parseInt(in.readLine());\n        \n        int[][] points = new int[n+1][2];\n        points[n][0] = Xs;//set starting point as last point for finding distances\n        points[n][1] = Ys;\n        \n        for(int i=0; i< n ; i++)\n        {\n            line = in.readLine().split(\" \");\n            points[i][0] = Integer.parseInt(line[0]);\n            points[i][1] = Integer.parseInt(line[1]);\n        }\n        \n        \n        int[][] distances = new int[n+1][n+1];\n        ComputeDistances(points, distances, n);\n        \n        int[] dp = new int[1<<n];\n        int[] path = new int[1<<n];\n        ComputeLowestPath(dp, path, distances, n);\n        OutputLowestAndPath(dp, path, n);\n        \n    }\n    \n    \n\n    private static void ComputeLowestPath(int[] dp, int[] path, int[][] distances, int n)\n    {\n        for(int i = 1; i < 1<<n; i++)\n        {\n            int j = 0;\n            while(true) //find first 1 (LSB)\n            {\n                if((i&(1<<j))!=0) //check for a bit equal to 1 in location j\n                {\n                    break;\n                }\n                j++;\n            }\n            \n            int pastEntry = i & ~(1<<j); //remove first 1 from i\n            path[i] = pastEntry; //set the path we came from to trace later\n            int distance = distances[j][n] * 2; //distance from origin to the point being removed, and back\n            dp[i] = dp[pastEntry] + distance; //set minimum distance if just this point is added to the collection\n            \n            for(int m = j +1; m < n; m++)\n            {\n                if((i & (1<<m))!=0)\n                {\n                    int entry = i & ~((1<<j)|(1<<m)); //remove both 1 at position j and 1 at position m from i\n                    distance = distances[j][n] + distances[j][m] + distances[m][n]; //calculate round-trip distance to grab 2 points\n                    \n                    if(dp[i] > dp[entry] + distance) // check if this new option is a better choice.  If it is, update our value and our path.\n                    {\n                        dp[i] = dp[entry] + distance;\n                        path[i] = entry;\n                    }\n                }\n            }\n            \n        }\n    }\n    \n    private static void OutputLowestAndPath(int[] dp, int[] path, int n)\n    {\n        \n        StringBuilder out = new StringBuilder();\n        out.append(dp[(1<<n)-1]);//output min value of traversal\n        out.append(\"\\n\");\n        out.append(\"0 \");\n        int index = (1<<n)-1; //start at our min value\n        while(index != 0)\n        {\n            int j = path[index];\n            int k = index ^ j; //find the one or two values that were added at this step\n            for(int m = 0; m < n; m++)\n            {\n                if((k & (1 << m)) != 0)\n                {\n                    out.append(m+1);\n                    out.append(\" \");\n                }\n            }\n            out.append(\"0 \");\n            index = j;\n        }\n        System.out.println(out.toString());\n    }\n    \n    private static void ComputeDistances(int[][] points, int[][] distances, int n)\n    {\n        for(int i = 0; i <= n; i++) //calculate distances between all points so that we don't have to compute later\n        {\n            for(int j=i+1; j<=n; j++)\n            {\n                int x= points[i][0] - points[j][0];\n                int y= points[i][1] - points[j][1];\n                distances[i][j] = x*x + y*y;\n            }\n        }\n    }\n    \n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF8C {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint[] x, y;\n\tint[] av;\n\tint[][] d = new int[25][25];\n\n\tint dist(int v, int u) {\n\t\tif (u == v)\n\t\t\treturn 0;\n\t\treturn (d[v][u] == 0 ? d[v][u] = d[u][v] = (x[v] - x[u])\n\t\t\t\t* (x[v] - x[u]) + (y[v] - y[u]) * (y[v] - y[u]) : d[v][u]);\n\t}\n\n\tvoid add(int x) {\n\t\tav[++av[0]] = x;\n\t}\n\n\tint size() {\n\t\treturn av[0];\n\t}\n\n\tint get(int i) {\n\t\treturn av[i + 1];\n\t}\n\n\tint N = 24;\n\tint[] dp = new int[(1 << N)];\n\tint[] dpFrom = new int[1 << N];\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\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\tav = new int[n + 1];\n\t\tfor (int i = 0; i <= n; i++)\n\t\t\tfor (int j = 0; j <= n; j++)\n\t\t\t\tdist(i, j);\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\tav[0] = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif ((st & (1 << i)) == 0)\n\t\t\t\t\tadd(i);\n\t\t\tif (av[0] == 0)\n\t\t\t\tcontinue;\n\t\t\tfor (int i = 0; i < 1; i++)\n\t\t\t\tfor (int j = i + 1; j < av[0]; j++) {\n\t\t\t\t\tint val = dp[st] + d[get(i) + 1][0]\n\t\t\t\t\t\t\t+ d[get(j) + 1][0]\n\t\t\t\t\t\t\t+ d[get(i) + 1][get(j) + 1];\n\t\t\t\t\tif (dp[st | (1 << get(i)) | (1 << get(j))] > val) {\n\t\t\t\t\t\tdp[st | (1 << get(i)) | (1 << get(j))] = val;\n\t\t\t\t\t\tdpFrom[st | (1 << get(i)) | (1 << get(j))] = st;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (int i = 0; i < 1; i++) {\n\t\t\t\tint val = dp[st] + d[get(i) + 1][0] * 2;\n\t\t\t\tif (dp[st | (1 << get(i))] > val) {\n\t\t\t\t\tdp[st | (1 << get(i))] = val;\n\t\t\t\t\tdpFrom[st | (1 << get(i))] = st;\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<Integer> ans = new ArrayList<Integer>();\n\t\tans.add(0);\n\t\twhile (nowSt != 0) {\n\t\t\tint newSt = dpFrom[nowSt];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (((1 << i) & nowSt) == (1 << i))\n\t\t\t\t\tif (((1 << i) & newSt) == 0)\n\t\t\t\t\t\tans.add(i + 1);\n\t\t\tans.add(0);\n\t\t\tnowSt = newSt;\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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.awt.Point;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n    static int[] DP;\n    static Point[] Next;\n    static int[][] pair;\n    static int[] single;\n    static int n;\n\n    public static int get(int mask) {\n        if (mask + 1 == (1 << n))\n            return 0;\n        if (DP[mask] != -1)\n            return DP[mask];\n        int x = 0;\n        for (;; x++)\n            if ((mask & (1 << x)) == 0)\n                break;\n        int min = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            if ((mask & (1 << i)) != 0 || i == x)\n                continue;\n            int temp = pair[x][i] + get(mask | (1 << i) | (1 << x));\n            if (temp < min) {\n                min = temp;\n                Next[mask] = new Point(x, i);\n            }\n        }\n        int temp = single[x] + get(mask | (1 << x));\n        if (temp < min) {\n            min = temp;\n            Next[mask] = new Point(x, -1);\n        }\n        return DP[mask] = min;\n    }\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        Point start = new Point(in.nextInt(), in.nextInt());\n        n = in.nextInt();\n        Point[] A = new Point[n];\n        for (int i = 0; i < n; i++)\n            A[i] = new Point(in.nextInt(), in.nextInt());\n        DP = new int[1 << n];\n        Next = new Point[1 << n];\n        Arrays.fill(DP, -1);\n        pair = new int[n][n];\n        single = new int[n];\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < n; j++) {\n                int dx1 = A[i].x - start.x;\n                int dy1 = A[i].y - start.y;\n                int dx2 = A[j].x - A[i].x;\n                int dy2 = A[j].y - A[i].y;\n                int dx3 = A[j].x - start.x;\n                int dy3 = A[j].y - start.y;\n                pair[i][j] = dx1 * dx1 + dy1 * dy1 + dx2 * dx2 + dy2 * dy2\n                        + dx3 * dx3 + dy3 * dy3;\n                single[i] = 2 * (dx1 * dx1 + dy1 * dy1);\n            }\n        int ans = get(0);\n        System.out.println(ans);\n        int mask = 0;\n        while (mask + 1 != (1 << n)) {\n            Point temp = Next[mask];\n            if (temp.y == -1)\n                System.out.print(\"0 \" + (temp.x + 1) + \" \");\n            else {\n                System.out\n                        .print(\"0 \" + (temp.x + 1) + \" \" + (temp.y + 1) + \" \");\n                mask |= (1 << temp.y);\n            }\n            mask |= (1 << temp.x);\n        }\n        System.out.println(\"0\");\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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.Set;\n\npublic class ProblemC {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\t// generateRandom();\n\t\t\n\t\tint[] pt = readPoint(s);\n\t\tint n = Integer.valueOf(s.readLine());\n\t\tint[][] xp = new int[n+1][];\n\t\tfor (int i = 1 ; i <= n ; i++) {\n\t\t\txp[i] = readPoint(s);\n\t\t}\n\t\txp[0] = pt;\n\t\t\n\t\tint[][] dist = new int[n+1][n+1];\n\t\tfor (int i = 0 ; i <= n ; i++) {\n\t\t\tfor (int j = 0 ; j <= n ; j++) {\n\t\t\t\tint dx = Math.abs(xp[i][0] - xp[j][0]);\n\t\t\t\tint dy = Math.abs(xp[i][1] - xp[j][1]);\n\t\t\t\tdist[i][j] = dx*dx + dy*dy;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dist2 = new int[n+1][n+1];\n\t\tfor (int i = 0 ; i <= n ; i++) {\n\t\t\tfor (int j = 0 ; j <= n ; j++) {\n\t\t\t\tdist2[i][j] = dist[0][i] + dist[i][j] + dist[j][0];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] dp = new int[1<<n];\n\t\tint[][] dp_prev = new int[2][1<<n];\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\t\n\t\tfor (int i = 0 ; i < (1<<n) ; i++) {\n\t\t\tif (dp[i] == Integer.MAX_VALUE) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint base = dp[i];\n\t\t\t// two\n\t\t\tfor (int y = 0 ; y < n ; y++) {\n\t\t\t\tif ((i & (1<<y)) >= 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfor (int z = y+1 ; z < n ; z++) {\n\t\t\t\t\tif ((i & (1<<z)) >= 1) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint ti = i | (1<<y) | (1<<z);\n\t\t\t\t\tint d = dist2[y+1][z+1];\n\t\t\t\t\tif (dp[ti] > base + d) {\n\t\t\t\t\t\tdp[ti] = base + d;\n\t\t\t\t\t\tdp_prev[0][ti] = z+1;\n\t\t\t\t\t\tdp_prev[1][ti] = y+1;\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\t\n\t\tint bestOnes = 0;\n\t\tfor (int i = 0 ; i < (1<<n) ; i++) {\n\t\t\tif (dp[i] == Integer.MAX_VALUE) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint sub = (1<<n) - 1 - i;\n\t\t\tint add = 0;\n\t\t\tfor (int j = 0 ; j < n ; j++) {\n\t\t\t\tif ((sub & (1<<j)) >= 1) {\n\t\t\t\t\tadd += dist[0][j+1] * 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (dp[i] + add < dp[(1<<n)-1]) {\n\t\t\t\tdp[(1<<n)-1] = dp[i] + add;\n\t\t\t\tbestOnes = sub;\n\t\t\t}\n\t\t}\n\t\t\n\t\tStringBuffer b = new StringBuffer();\n\t\tb.append(\" 0\");\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tif ((bestOnes & (1<<i)) >= 1) {\n\t\t\t\tb.append(\" \").append(i+1).append(\" \").append(0);\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(dp[(1<<n)-1]);\n\t\tint nptn = (1<<n)-1-bestOnes;\n\t\twhile (nptn >= 1) {\n\t\t\tint i1 = dp_prev[0][nptn];\n\t\t\tint i2 = dp_prev[1][nptn];\n\t\t\tif (i1 >= 1) {\n\t\t\t\tnptn -= 1<<(i1-1);\n\t\t\t\tb.append(\" \").append(i1);\n\t\t\t}\n\t\t\tif (i2 >= 1) {\n\t\t\t\tnptn -= 1<<(i2-1);\n\t\t\t\tb.append(\" \").append(i2);\n\t\t\t}\n\t\t\tb.append(\" \").append(0);\n\t\t}\n\t\tout.println(b.substring(1));\n\t\tout.flush();\n\t}\n\n\tprivate static void generateRandom() {\n\t\tSystem.out.println(\"0 0\");\n\t\tSystem.out.println(\"24\");\n\t\tfor (int i = 0 ; i < 24 ; i++) {\n\t\t\tint a = (int)(Math.random() * 200 - 100);\n\t\t\tint b = (int)(Math.random() * 200 - 100);\n\t\t\tSystem.out.println(a + \" \" + b);\n\t\t}\n\t}\n\t\n\t\n\tprivate static int[] readPoint(BufferedReader s) throws IOException {\n\t\tint[] ret = new int[2];\n\t\tString[] data = s.readLine().split(\" \");\n\t\tret[0] = Integer.valueOf(data[0]);\n\t\tret[1] = Integer.valueOf(data[1]);\n\t\treturn ret;\n\t}\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * @author Egor Kulikov (kulikov@devexperts.com)\n */\npublic class Order implements Runnable {\n\tprivate Scanner in = new Scanner(System.in);\n\tprivate PrintWriter out = new PrintWriter(System.out);\n\tprivate int xs, ys, n;\n\tprivate int[] x, y;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Order()).start();\n\t}\n\n\tprivate void read() {\n\t\txs = in.nextInt();\n\t\tys = in.nextInt();\n\t\tn = in.nextInt();\n\t\tx = new int[n];\n\t\ty = new int[n];\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}\n\t}\n\n\tprivate void solve() {\n\t\tint[] res = new int[1 << n];\n\t\tint[] last = new int[1 << n];\n\t\tArrays.fill(res, Integer.MAX_VALUE);\n\t\tint[] ds = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tds[i] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys);\n\t\t}\n\t\tint[][] d = 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\td[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n\t\t}\n\t\tres[0] = 0;\n\t\tfor (int i = 1; i < (1 << n); i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (((i >> j) & 1) != 0) {\n\t\t\t\t\tif (res[i - (1 << j)] + 2 * ds[j] < res[i]) {\n\t\t\t\t\t\tres[i] = res[i - (1 << j)] + 2 * ds[j];\n\t\t\t\t\t\tlast[i] = i - (1 << j);\n\t\t\t\t\t}\n\t\t\t\t\tfor (int k = j + 1; k < n; k++) {\n\t\t\t\t\t\tif (((i >> k) & 1) != 0) {\n\t\t\t\t\t\t\tif (res[i - (1 << j) - (1 << k)] + ds[j] + ds[k] + d[j][k] < res[i]) {\n\t\t\t\t\t\t\t\tres[i] = res[i - (1 << j) - (1 << k)] + ds[j] + ds[k] + d[j][k];\n\t\t\t\t\t\t\t\tlast[i] = i - (1 << j) - (1 << k);\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\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint cur = (1 << n) - 1;\n\t\tout.println(res[cur]);\n\t\twhile (cur != 0) {\n\t\t\tout.print(\"0 \");\n\t\t\tint dif = cur - last[cur];\n\t\t\tfor (int i = 0; i < n && dif != 0; i++) {\n\t\t\t\tif (((dif >> i) & 1) != 0) {\n\t\t\t\t\tout.print((i + 1) + \" \");\n\t\t\t\t\tdif -= (1 << i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcur = last[cur];\n\t\t}\n\t\tout.println(\"0\");\n\t}\n\n\tprivate void write() {\n\t}\n\n\tpublic void run() {\n\t\tread();\n\t\tsolve();\n\t\twrite();\n\t\tout.close();\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * 111118315581\n *\n * @author pttrung\n */\npublic class C {\n\n    static Point hand;\n    static int n;\n    static Point[] data;\n    static int[] next;\n    static int[] dp;\n    static int[][] pre;\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n        // System.out.println(1 << 24);\n        hand = new Point(in.nextInt(), in.nextInt());\n        n = in.nextInt();\n        data = new Point[n];\n        for (int i = 0; i < n; i++) {\n            data[i] = new Point(in.nextInt(), in.nextInt());\n        }\n        pre = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                pre[i][j] = distance(data[i], data[j]);\n            }\n        }\n\n\n        next = new int[1 << n];\n        dp = new int[1 << n];\n        Arrays.fill(dp, -1);\n\n        out.println(cal(0));\n\n\n        int start = 0;\n\n        do {\n            int m = next[start];\n            int val = m - start;\n            out.print(0 + \" \");\n            for (int i = 0; i < n; i++) {\n                if (((1 << i) & val) != 0) {\n                    out.print((i + 1) + \" \");\n                }\n            }\n            // out.print(0 + \" \")  ;\n            start = m;\n        } while (start != (1 << n) - 1);\n        out.println(0);\n        out.close();\n    }\n\n    public static int cal(int mask) {\n        if ((1 << n) - 1 == mask) {\n            //  System.out.println(mask);\n            return 0;\n        }\n        if (dp[mask] != -1) {\n            return dp[mask];\n        }\n        int result = Integer.MAX_VALUE;\n        for (int i = 0; i < n; i++) {\n            if (((1 << i) & mask) == 0) {\n                int dist = distance(hand, data[i]);\n              \n                for (int j = i + 1; j < n; j++) {\n                    if (((1 << j) & mask) == 0) {\n                        //System.out.println(i + \" \" + j);\n                        int temp = dist + distance(hand, data[j]) + pre[i][j] + cal(mask | (1 << i) | (1 << j));\n                        //System.out.println(temp);\n                        if (temp < result) {\n                            result = temp;\n                            next[mask] = (mask | (1 << i) | (1 << j));\n                        }\n                        \n                    }\n                }\n             \n                    int temp = 2 * dist + cal(mask | (1 << i));\n                    if (temp < result) {\n                        result = temp;\n                        next[mask] = (mask | (1 << i));\n                    }\n             \n                break;\n            }\n\n        }\n        dp[mask] = result;\n        return result;\n    }\n\n    static int distance(Point a, Point b) {\n        int total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);\n        return total;\n    }\n\n    static class Point {\n\n        int x, y;\n\n        public Point(int x, int y) {\n            this.x = x;\n            this.y = y;\n\n        }\n    }\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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.Deque;\n\nimport static java.lang.Integer.MAX_VALUE;\nimport static java.lang.Integer.parseInt;\n\n/**\n * 8C\n *\n * @author artyom\n */\npublic class LookingForOrder {\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String[] parsedString = parsedString = in.readLine().split(\" \");\n        int xStart = parseInt(parsedString[0]);\n        int yStart = parseInt(parsedString[1]);\n        int objectNum = parseInt(in.readLine());\n\n        int[] xLocs = new int[objectNum + 1];\n        int[] yLocs = new int[objectNum + 1];\n        int[] bitMasks = new int[1 << objectNum];\n        Arrays.fill(bitMasks, MAX_VALUE);\n        int[] previous = new int[1 << objectNum];\n\n        xLocs[objectNum] = xStart;\n        yLocs[objectNum] = yStart;\n        for (int i = 0; i < objectNum; i++) {\n            parsedString = in.readLine().split(\" \");\n            xLocs[i] = parseInt(parsedString[0]);\n            yLocs[i] = parseInt(parsedString[1]);\n        }\n\n        //go through all pairs and find time requirement for each pair of objects\n        //the entry at point [i][j] is equal to the time it takes to get from point i to point j\n        int[][] times = new int[objectNum + 1][objectNum + 1];\n        for (int i = 0; i <= objectNum; i++) {\n            for (int j = 0; j <= objectNum; j++) {\n                times[i][j] = times[j][i] = (xLocs[i] - xLocs[j]) * (xLocs[i] - xLocs[j]) + (yLocs[i] - yLocs[j]) * (yLocs[i] - yLocs[j]);\n            }\n        }\n\n        //each value in bitmasks represents the minimum time necessary to get\n        //the unmasked bits\n        //so bitmasks[5] (5=101) is the fastest time in which you can get\n        //items 1 and 3\n        bitMasks[0] = 0; //collecting zero objects takes 0 time\n        for (int i = 0; i < (1 << objectNum); i++) {\n            if (bitMasks[i] != MAX_VALUE) {\n                for (int j = 0; j < objectNum; j++) {\n                    if (((1 << j) & i) == 0) { //if our current j object hasn't been picked up yet\n                        int curState = (1 << j) | i; //ith state after picking up j object\n                        int curTime = bitMasks[i] + 2 * times[objectNum][j]; //time required to get object j from bag at state i\n\n                        if (curTime < bitMasks[curState]) {\n                            bitMasks[curState] = curTime; //put fastest time in for gettingto our current state\n                            previous[curState] = i;\n                        }\n\n                        //find another thing while you're out\n                        for (int k = 0; k < objectNum; k++) {\n                            if (((1 << k) & curState) == 0) { //if the kth position in our current state hasn't been picked up\n                                int kState = ((1 << k) | curState); //curstate after picking up the kth object\n                                //kTime is time it takes to go from bag, to j, to k and back\n                                int kTime = bitMasks[i] + times[objectNum][j] + times[j][k] + times[k][objectNum];\n\n                                if (kTime < bitMasks[kState]) {\n                                    bitMasks[kState] = kTime;  //put shortest time for getting to kState in\n                                    previous[kState] = i;\n                                }\n                            }\n                        }\n                        break;\n                    }\n                }\n            }\n        }\n\n        int finalState = (1 << objectNum) - 1;\n\n        StringBuilder sb = new StringBuilder();\n        sb.append(bitMasks[finalState]).append('\\n');\n\n        Deque<Integer> outputQ = new ArrayDeque<>();\n        outputQ.add(0);\n        int curState = finalState;\n        while (curState > 0) {\n            //difference is the objects picked up in this state but not in previous state\n            int difference = curState ^ previous[curState];\n            int firstItem = -1;\n            int secondItem = -1;\n\n            for (int i = 0; i < objectNum; i++) {\n                if (((1 << i) & difference) > 0) { //if the ith object was picked up in this state\n                    secondItem = firstItem; //keep track of how many items are picked up\n                    firstItem = i;\n                }\n            }\n\n            if (secondItem != -1) {\n                //put in two items followed by a return to 0\n                outputQ.add(firstItem + 1);\n                outputQ.add(secondItem + 1);\n                outputQ.add(0);\n            } else {\n                outputQ.add(firstItem + 1);\n                outputQ.add(0);\n            }\n\n            curState = previous[curState];\n        }\n\n        sb.append(outputQ.removeLast());\n        while (!outputQ.isEmpty()) {\n            sb.append(' ').append(outputQ.removeLast());\n        }\n        System.out.print(sb);\n    }\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.StringTokenizer;\n\npublic class LookingForOrder {\n\tstatic final int INF = (int)1e9;\n\tstatic Point a[];\n\tstatic Point o;\n\tstatic int n;\n\tstatic int dp[];\n\tstatic PrintWriter out;\n\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\n\t\to = new Point(sc.nextInt(), sc.nextInt());\n\t\tn = sc.nextInt();\n\t\ta = new Point[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = new Point(sc.nextInt(), sc.nextInt());\n\t\t\n\t\tdp = new int[(1 << n) + 5];\n\t\tArrays.fill(dp, -1);\n\t\tout.println(rec(0));\n\t\tout.print(0 + \" \");\n\t\tpath(0);\n\t\tout.println();\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\t}\n\t\n\tstatic void path(int msk) {\n\t\tif (msk == (1 << n) - 1) return;\n\t\t\n\t\tint optimal = rec(msk);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((msk & (1 << i)) == 0) {\n\t\t\t\tif (rec(msk | (1 << i)) + 2 * o.dist(a[i]) == optimal) {\n\t\t\t\t\tout.print((i + 1) + \" \" + 0 + \" \");\n\t\t\t\t\tpath(msk | (1 << i));\n\t\t\t\t\treturn;\n\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 (rec(msk | (1 << i) | (1 << j)) + o.dist(a[i]) + a[i].dist(a[j]) + a[j].dist(o) == optimal) {\n\t\t\t\t\t\tout.print((i + 1) + \" \" + (j + 1) + \" \" + 0 + \" \");\n\t\t\t\t\t\tpath(msk | (1 << i) | (1 << j));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int rec(int msk) {\n\t\tif (msk == (1 << n) - 1) return 0;\n\t\tif (dp[msk] != -1) return dp[msk];\n\t\t\n\t\tint ans = INF;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((msk & (1 << i)) == 0) {\n\t\t\t\tans = Math.min(ans, rec(msk | (1 << i)) + 2 * o.dist(a[i]));\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (i == j) continue;\n\t\t\t\t\tif ((msk & (1 << j)) == 0) \n\t\t\t\t\t\tans = Math.min(ans, rec(msk | (1 << i) | (1 << j)) + o.dist(a[i]) + a[i].dist(a[j]) + a[j].dist(o));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn dp[msk] = ans;\n\t}\n\n\tstatic class Point {\n\t\tint x, y;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic int dist(Point p) {\n\t\t\treturn (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner(FileReader f) {\n\t\t\tbr = new BufferedReader(f);\n\t\t}\n\n\t\tpublic Scanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\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 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\t\tpublic boolean Ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic void waitForInput(long time) {\n\t\t\tlong ct = System.currentTimeMillis();\n\t\t\twhile(System.currentTimeMillis() - ct < time) {};\n\t\t}\n\n\t}\n\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    BufferedReader in = null;\n    PrintWriter out = null;\n\n    int dist(int x1, int y1, int x2, int y2) {\n        int dx = Math.abs(x1 - x2);\n        int dy = Math.abs(y1 - y2);\n        return dx * dx + dy * dy;\n    }\n\n    boolean testBit(int use, int p) {\n        return ((use >> p) & 1) == 1;\n    }\n\n    int rec(int use, int a[][], int dp[], int next[]) {\n        if (dp[use] != -1) {\n            return dp[use];\n        }\n        if (use == 0) {\n            return dp[use] = 0;\n        }\n        int n = a.length;\n        int ix = -1;\n        \n        for (int i = 0; i < n; ++i) {\n            if (testBit(use, i)) {\n                if (ix == -1) {\n                    ix = i;\n                    break;\n                }\n\n                /*\n                int t = rec(use ^ (1 << i), a, dp);\n                t += a[i][i];\n                r = Math.min(r, t);*/\n            }\n        }\n\n        int r = rec(use ^ (1 << ix), a, dp, next) + a[ix][ix];\n        next[use] = use ^ (1 << ix);\n        \n\n        for (int i = ix + 1; i < n; ++i) {\n            if (!testBit(use, i)) {\n                continue;\n            }\n            int t = rec(use ^ (1 << ix) ^ (1 << i), a, dp, next);\n            t += a[ix][i];\n            if (t < r) {\n                r = t;\n                next[use] = use ^ (1 << ix) ^ (1 << i);\n            }\n        }\n\n        return dp[use] = r;\n    }\n\n    void print(int use1, int use2, int n) {\n        for (int i = 0; i < n; ++i) {\n            if (testBit(use1, i) ^ testBit(use2, i)) {\n                int x = i + 1;\n                out.print(x + \" \");\n            }\n        }\n    }\n\n    void solve() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        //in = new BufferedReader(new FileReader(\"input.txt\"));\n        out = new PrintWriter(System.out);\n        \n        StringTokenizer st;\n        st = new StringTokenizer(in.readLine());\n        int sx = Integer.valueOf(st.nextToken());\n        int sy = Integer.valueOf(st.nextToken());\n        st = new StringTokenizer(in.readLine());\n        int n = Integer.valueOf(st.nextToken());\n        int x[] = new int[n];\n        int y[] = new int[n];\n        for (int i = 0; i < n; ++i) {\n            st = new StringTokenizer(in.readLine());\n            x[i] = Integer.valueOf(st.nextToken());\n            y[i] = Integer.valueOf(st.nextToken());\n        }\n        int a[][] = new int[n][n];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = dist(x[i], y[i], sx, sy) + dist(x[j], y[j], sx, sy) + dist(x[i], y[i], x[j], y[j]);\n            }\n        }\n\n        int dp[] = new int[1 << n];\n        Arrays.fill(dp, -1);\n        int next[] = new int[1 << n];\n        int ans = rec((1 << n) - 1, a, dp, next);\n\n        out.println(ans);\n\n        int use = (1 << n) - 1;\n        while (true) {\n            int nuse = next[use];\n            out.print(\"0 \");\n            print(use, nuse, n);\n            if (nuse == 0) break;\n            use = nuse;\n        }\n        out.println(\"0\");\n        \n        in.close();\n        out.close();\n    }\n    \n    public static void main(String[] args) throws IOException {\n        new Main().solve();\n    }\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.System.*;\nimport static java.lang.Math.*;\n\npublic class C {\n    static int[] dp;\n    static int[] f;\n    static void solve(){\n        dp = new int[1<<n];\n        f  = new int[1<<n];\n        Arrays.fill(dp, 1<<29);\n        dp[0] = 0;\n        for(int i=0;i<(1<<n);i++){\n//            out.println(\"i=\"+i);\n            for(int j=0;j<n;j++){\n                int ni = i | (1<<j);\n                if( i != ni ){\n//                    out.println(\"i=\"+i+\",j=\"+j);\n                    int v = d[j]*2 + dp[i];\n                    if(v < dp[ni]){\n//                        out.println(\"up:\"+ni+\" to \"+v + \" fw=\"+i);\n                        dp[ni] = v;\n                        f[ni] = i;\n                    }\n\n                    for(int k=j+1;k<n;k++){\n                        int nni = ni | (1<<k);\n                        if( ni != nni){\n                            int vv = d[j] + t[j][k] + d[k] + dp[i];\n                            if(vv < dp[nni]){\n//                                out.println(\"up:\"+nni+\" to \"+vv + \" fw=\"+i);\n                                dp[nni] = vv;\n                                f[nni] = i;\n                            }\n                        }\n                    }\n                    break;\n                }\n            }\n        }\n        out.println(dp[dp.length-1]);\n//        out.println(\"dp=\"+Arrays.toString(dp));\n//        out.println(\"f=\"+Arrays.toString(f));\n\n        int idx = dp.length - 1;\n        out.print(\"0 \");\n        while(idx != 0){\n            int road = idx ^ f[idx];\n//            out.println(\"idx = \"+idx + \" f[idx] = \"+f[idx]);\n            for(int i=0;i<n;i++) if( ((road>>i) & 1) == 1) out.print((i+1)+\" \");\n            idx = f[idx];\n            out.print(\"0 \");\n        }\n        out.println();\n    }\n    static int[] d;\n    static int[][] t;\n    static int n;\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(in);\n\n        int x = sc.nextInt();\n        int y = sc.nextInt();\n\n        n = sc.nextInt();\n        int[] dx = new int[n];\n        int[] dy = new int[n];\n\n        for(int i=0;i<n;i++){\n            dx[i] = sc.nextInt();\n            dy[i] = sc.nextInt();\n        }\n\n        d = new int[n];\n        for(int i=0;i<n;i++){\n            d[i] = (x-dx[i])*(x-dx[i]) + (y-dy[i])*(y-dy[i]);\n        }\n\n        t = new int[n][n];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                t[i][j] = (dx[i]-dx[j])*(dx[i]-dx[j]) + (dy[i]-dy[j])*(dy[i]-dy[j]);\n            }\n        }\n//        out.println(Arrays.toString(d));\n//        out.println(Arrays.deepToString(t));\n\n        solve();\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.LinkedList;\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\tint n;\n\tPoint[] ps;\n\tint[] dp;\n\n\tprivate Object solve() throws IOException {\n\t\tint o_x = ni();\n\t\tint o_y = ni();\n\n\t\tn = ni();\n\t\tps = new Point[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tps[i] = new Point(ni() - o_x, ni() - o_y);\n\n\t\tdp = new int[1 << n];\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\tint[] path_x = new int[1 << n];\n\t\tint[] path_y = new int[1 << n];\n\t\t\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tint i = min(mask);\n\t\t\tint min_val = dp[mask - (1 << i)] + 2 * ps[i].norm;\n\t\t\tif (min_val < dp[mask]) {\n\t\t\t\tdp[mask] = min_val;\n\t\t\t\tpath_x[mask] = i;\n\t\t\t\tpath_y[mask] = i;\n\t\t\t\t\n\t\t\t}\n\t\t\tfor (int j = i + 1; j < n; j++)\n\t\t\t\tif ((mask & (1 << j)) != 0) {\n\t\t\t\t\tint newMask = mask - (1 << i) - (1 << j);\n\t\t\t\t\tint val = dp[newMask] + ps[i].norm + ps[j].norm\n\t\t\t\t\t\t\t+ ps[i].dist(ps[j]);\n\t\t\t\t\tif (val < dp[mask]) {\n\t\t\t\t\t\tdp[mask] = val;\n\t\t\t\t\t\tpath_x[mask] = i;\n\t\t\t\t\t\tpath_x[mask] = j;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\tpln(dp[(1 << n) - 1]);\n\n\t\tint maskPath = (1 << n) - 1;\n\t\tLinkedList<Long> list = new LinkedList<Long>();\n\t\twhile (maskPath != 0) {\n\t\t\tlong x = path_x[maskPath];\n\t\t\tlong y = path_y[maskPath];\n\t\t\t\n\t\t\tlist.addFirst(0L);\n\t\t\tlist.addFirst(y + 1);\n\t\t\tmaskPath -= (1 << y);\n\t\t\tif (x != y) {\n\t\t\t\tlist.addFirst(x + 1);\n\t\t\t\tmaskPath -= 1 << x;\n\t\t\t}\n\t\t}\n\t\tlist.addFirst(0L);\n\t\tshow(list);\n\t\treturn null;\n\t}\n\n\tprivate int min(int mask) {\n\t\tint ret = 0;\n\t\twhile (mask % 2 == 0) {\n\t\t\tmask /= 2;\n\t\t\tret++;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate void show(LinkedList<Long> list) {\n\t\tint index = 0;\n\t\tfor (long a : list) {\n\t\t\tif (index == 0) {\n\t\t\t\tp(a);\n\t\t\t} else {\n\t\t\t\tp(\" \" + a);\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\tpln();\n\t}\n\n\tclass Point {\n\t\tint x;\n\t\tint y;\n\t\tint norm;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.norm = x * x + y * y;\n\t\t}\n\n\t\tpublic int dist(Point other) {\n\t\t\tint dx = (x - other.x);\n\t\t\tint dy = (y - other.y);\n\n\t\t\treturn dx * dx + dy * dy;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Point [x=\" + x + \", y=\" + y + \", norm=\" + norm + \"]\";\n\t\t}\n\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer strTok = new StringTokenizer(\"\");\n\n\tString nextToken() throws IOException {\n\t\twhile (!strTok.hasMoreTokens())\n\t\t\tstrTok = new StringTokenizer(in.readLine());\n\t\treturn strTok.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\tstrTok = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\n\tboolean EOF() throws IOException {\n\t\twhile (!strTok.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tstrTok = 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\n\tpublic void pln() {\n\t\tout.println();\n\t}\n\n\tpublic void pln(int arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(long arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(double arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(String arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(boolean arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(char arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(float arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void pln(Object arg) {\n\t\tout.println(arg);\n\t}\n\n\tpublic void p(int arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(long arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(double arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(String arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(boolean arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(char arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(float arg) {\n\t\tout.print(arg);\n\t}\n\n\tpublic void p(Object arg) {\n\t\tout.print(arg);\n\t}\n\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\npublic class Order8C implements Runnable {\n    private Scanner in = new Scanner(System.in);\n    private PrintWriter out = new PrintWriter(System.out);\n\n    int mintime;\n    String path;\n\n    int xs;\n    int ys;\n    int n;\n    int[] obx;\n    int[] oby;\n\n\n    public static void main(String[] args) {\n\tnew Thread(new Order8C()).start();\n    }\n\n    private void read() {\n\txs = in.nextInt();\n\tys = in.nextInt();\n\tn = in.nextInt();\n\tobx = new int[n];\n\toby = new int[n];\n\tfor(int i = 0; i<n; i++){\n\t    obx[i] = in.nextInt();\n\t    oby[i] = in.nextInt();\n\t}\n\t\n    }\n\n    private void solve() {\n\t/* we will do dynamic programming over the subsets\n\t   best[m] will be the shortest for binary digits of m\n\t   being in. \n\t   last[m] will be the last subset before m */\n\n\tint[] ds = new int[n];\n\tint[][] d = new int[n][n];\n\n\tint[] best = new int[1 << n];\n\tint[] last = new int[1 << n];\n\n\n\tfor(int i = 0; i<n; i++){\n\t    ds[i] = (obx[i]-xs)*(obx[i]-xs) + (oby[i]-ys)*(oby[i]-ys);\n\t    for(int j = i+1; j<n; j++){\n\t\td[i][j] = (obx[i]-obx[j])*(obx[i]-obx[j]) + (oby[i]-oby[j])*(oby[i]-oby[j]);\n\t\td[j][i] = (obx[i]-obx[j])*(obx[i]-obx[j]) + (oby[i]-oby[j])*(oby[i]-oby[j]);\n\t    }\n\t}\n\n\n\tfor(int i=0; i< (1<<n); i++){ //goes through subsets before supersets\n\t    best[i] = 100000000;\n\t}\n\tbest[0] = 0;\n\n\tfor(int i=0; i< (1<<n); i++){ //goes through subsets before supersets\n\t    /*if (i % 1000000 == 0 ){\n\t\tSystem.out.println(i);\n\t\t}*/\n\t    for(int j = 0; j<n; j++){\n\t\tif( ((1 << j) & i) != 0){ // if 2^j and i have bitwise sum nonzero\n\t\t    if(best[i - (1<<j)] + 2*ds[j] < best[i]){\n\t\t\tbest[i] = best[i - (1<<j)] + 2*ds[j];\n\t\t\tlast[i] = i - (1<< j);\n\n\t\t    }\n\t\t   for(int k = j+1; k<n; k++){\n\t\t       if( ((1 << k) & i) != 0){ // if 2^k and i have bitwise sum nonzero\n\t\t\t   if( (best[i-(1<<j) -(1<<k)] +ds[j]+ds[k]+d[j][k]) < best[i]){\n\t\t\t       best[i] = (best[i-(1<<j) -(1<<k)] +ds[j]+ds[k]+d[j][k]);\n\t\t\t       last[i] = i -(1<<j) - (1<< k);\n\n\t\t\t   }\n\n\t\t       }\n\t\t   }\n\t\t   break; // break here because order doesn't really matter, just knowing which pairs to roup\n\t\t}\n\t    }\n\t}\n\tint i = (1<<n) -1;\n\tmintime = best[i];\n\tpath = \"\";\n\t\n\twhile(i >0){\n\t    //System.out.println(\"Got to i = \" + i + \" and path is: \" + path);\n\t    path = path + \"0 \";\n\t    int dif = i-last[i]; // this has one or two 1s in binary\n\t    for(int j=0; j<n; j++){\n\t\tif( ((1<<j) & dif) != 0){ // if dif has a 1 in the j'th digit\n\t\t    path  = path + (j+1) + \" \";\n\t\t}\n\t    }\n\t    \n\t    i = last[i];\n\t}\n\tpath = path + \"0\";\n    }\n\n    private void write() {\n\tout.println(mintime);\n\tout.println(path);\n    }\n    public void run() {\n\tread();\n\tsolve();\n\twrite();\n\tout.close();\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        int[] best = new int[1 << n];\n        int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            best[set] = best[set ^ (1 << i)] + single[i];\n            prev[set] = i + 1;\n            for (int j = i + 1; j < n; ++j)\n                if ((set & (1 << j)) != 0) {\n                    int cur = best[set ^ (1 << i) ^ (1 << j)] + pair[i][j];\n                    if (cur < best[set]) {\n                        best[set] = cur;\n                        prev[set] = (i + 1) * 100 + (j + 1);\n                    }\n                }\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n            int what = prev[now];\n            int wa = what % 100 - 1;\n            int wb = what / 100 - 1;\n            if (wa >= 0) {\n                writer.print(\" \");\n                writer.print(wa + 1);\n                now ^= 1 << wa;\n            }\n            if (wb >= 0) {\n                writer.print(\" \");\n                writer.print(wb + 1);\n                now ^= 1 << wb;\n            }\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * @author vstepanov on 3/29/2017.\n */\npublic class Main {\n    public static void main(String[] args) {\n        try(Scanner in = new Scanner(System.in)) {\n            int bx = in.nextInt();\n            int by = in.nextInt();\n            int n = in.nextInt();\n            int[][] xy = new int[n][2];\n            int[] res = new int[1 << n];\n            int[] last = new int[1 << n];\n            for (int i = 0; i < n; i++) {\n                xy[i] = new int[]{in.nextInt(), in.nextInt()};\n            }\n            int[] ds = new int[n];\n            for (int i = 0; i < ds.length; i++) {\n                ds[i] = time(xy[i][0], xy[i][1], bx, by);\n            }\n            int[][] d = new int[n][n];\n            for (int i = 0; i < d.length; i++) {\n                for (int j = 0; j < d.length; j++) {\n                    d[i][j] = time(xy[i][0], xy[i][1], xy[j][0], xy[j][1]);\n                }\n            }\n            Arrays.fill(res, Integer.MAX_VALUE);\n            res[0] = 0;\n            for (int i = 0; i < (1 << n); i++) {\n                for (int j = 0; j < n; j++) {\n                    if ((i & mask(j)) != 0) {\n                        if (res[i - mask(j)] + 2*ds[j] < res[i]) {\n                            res[i] = res[i - mask(j)] + 2*ds[j];\n                            last[i] = i - mask(j);\n                        }\n                        for (int k = j + 1; k < n; k++) {\n                            if ((i & mask(k)) != 0) {\n                                if (res[i - mask(k) - mask(j)] + ds[j] + ds[k] + d[j][k] < res[i]) {\n                                    res[i] = res[i - mask(k) - mask(j)] + ds[j] + ds[k] + d[j][k];\n                                    last[i] = i - mask(j) - mask(k);\n                                }\n                            }\n                        }\n                        break;\n                    }\n                }\n            }\n\n            int cur = (1 << n) - 1;\n            System.out.println(res[cur]);\n            int k = cur;\n            while (k != 0) {\n                System.out.print(\"0 \");\n                int diff = k - last[k];\n                for (int i = 0; i < n && diff != 0; i++) {\n                    if (((diff >> i) & 1) != 0) {\n                        System.out.print((i + 1) + \" \");\n                        diff -= (1 << i);\n                    }\n                }\n                k = last[k];\n            }\n            System.out.println(\"0\");\n        }\n    }\n\n    static int mask(int i) {\n        return 1 << i;\n    }\n\n    static int time(int x, int y, int x1, int y1) {\n        return (x - x1)*(x - x1) + (y - y1)*(y - y1);\n    }\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class C\n{\n\n    public static void main(String[] args)\n    {\n        new C();\n    }\n    \n    final int oo = (int)1e9;\n    \n    int Hx,Hy;\n    \n    int N;\n    int[][] P;\n    \n    int[] memo;\n    int[][] soln;\n    \n    int[] dist1;\n    int[][] dist2;\n    \n    C()\n    {\n        Scanner in = new Scanner(System.in);\n        Hx=in.nextInt();\n        Hy=in.nextInt();\n        \n        N=in.nextInt();\n        P=new int[N][2];\n        for (int i=0; i<N; ++i)\n        {\n            P[i][0]=in.nextInt();\n            P[i][1]=in.nextInt();\n        }\n        \n        memo=new int[1<<N];\n        Arrays.fill(memo, -1);\n        soln=new int[2][1<<N];\n        \n        dist1=new int[N];\n        Arrays.fill(dist1, -1);\n        dist2=new int[N][N];\n        for (int[] d : dist2) Arrays.fill(d, -1);\n        \n        int res=go((1<<N)-1);\n        System.out.println(res);\n        \n        int set=(1<<N)-1;\n        while (set>0)\n        {\n            System.out.print(\"0 \");\n            System.out.print((soln[0][set]+1)+\" \");\n            if (soln[1][set]>-1) System.out.print((soln[1][set]+1)+\" \");\n            \n            if (soln[1][set]>-1)\n            {\n                set-=((1<<soln[0][set])+(1<<soln[1][set]));\n            }\n            else\n            {\n                set-=(1<<soln[0][set]);\n            }\n        }\n        System.out.println(\"0\");\n    }\n    \n    int go(int set)\n    {\n        if (set==0)\n            return 0;\n        if (memo[set]>-1)\n            return memo[set];\n                \n        int res=oo;\n        int i=0;\n        while (!on(set,i)) ++i;\n\n        res=dist(i)+go(set-(1<<i));\n        soln[0][set]=i;\n        soln[1][set]=-1;\n        \n        for (int j=i+1; j<N; ++j)\n        {\n            if (on(set,j))\n            {\n                int tmp=dist(i,j)+go(set-(1<<i)-(1<<j));\n                if (tmp<res)\n                {\n                    res=tmp;\n                    soln[0][set]=i;\n                    soln[1][set]=j;\n                }\n            }\n        }\n        \n        return memo[set]=res;\n    }\n    \n    // H->i->H\n    int dist(int i)\n    {\n        if (dist1[i]>-1) return dist1[i];\n        \n        int dx=P[i][0]-Hx;\n        int dy=P[i][1]-Hy;\n        return dist1[i]=2*(dx*dx+dy*dy);\n    }\n    \n    // H->i->j->H\n    int dist(int i, int j)\n    {\n        if (dist2[i][j]>-1) return dist2[i][j];\n        \n        int res=0,dx,dy;\n        \n        dx=P[i][0]-Hx;\n        dy=P[i][1]-Hy;\n        res+=dx*dx+dy*dy;\n        \n        dx=P[i][0]-P[j][0];\n        dy=P[i][1]-P[j][1];\n        res+=dx*dx+dy*dy;\n        \n        dx=P[j][0]-Hx;\n        dy=P[j][1]-Hy;\n        res+=dx*dx+dy*dy;\n        \n        return dist2[i][j]=res;\n    }\n    \n    boolean on(int set, int loc)\n    {\n        return (set&(1<<loc))>0;\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import 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.StringTokenizer;\n\npublic class Main implements Runnable {\n\n    // ////////////////////////////////////////////////////////////////////\n    // Solution\n\n    private int n;\n    private int nn;\n    private int[][] D;\n    private int[] dp;\n    private int[] prev;\n\n    private void solve() throws Throwable {\n        int xs = nextInt(), ys = nextInt();\n        n = nextInt();\n        int[][] pts = new int[n][2];\n        for (int i = 0; i < n; i++) {\n            pts[i][0] = nextInt();\n            pts[i][1] = nextInt();\n        }\n        D = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (i == j) {\n                    D[i][i] = 2 * (sqr(pts[i][0] - xs) + sqr(pts[i][1] - ys));\n                } else {\n                    D[i][j] = sqr(pts[i][0] - xs) + sqr(pts[i][1] - ys)\n                            + sqr(pts[i][0] - pts[j][0])\n                            + sqr(pts[i][1] - pts[j][1]) + sqr(pts[j][0] - xs)\n                            + sqr(pts[j][1] - ys);\n                }\n            }\n        }\n        nn = 1 << n;\n        dp = new int[nn];\n        prev = new int[nn];\n        Arrays.fill(dp, -1);\n        Arrays.fill(prev, -1);\n        dp[0] = 0;\n        Dp(nn - 1);\n        pw.println(dp[nn - 1]);\n        pw.print(0);\n        for (int p = nn - 1; p != -1 && prev[p] != -1; p = prev[p]) {\n            int vv = p ^ prev[p];\n            for (int j = 0; j < n; j++) {\n                int jj = 1 << j;\n                if ((vv & jj) == 0) continue;\n                pw.print(' ');\n                pw.print(j + 1);\n            }\n            pw.print(\" 0\");\n        }\n        pw.println();\n    }\n\n    private int Dp(int i) {\n        if (dp[i] != -1) return dp[i];\n        int ans = 107374182, p = -1;\n        int j1 = 1, pos1 = 0;\n        for (; pos1 < n && j1 < nn; j1 *= 2, pos1++) {\n            if ((i & j1) == 0) continue;\n            int a = D[pos1][pos1] + Dp(i ^ j1);\n            if (a < ans) {\n                ans = a;\n                p = i ^ j1;\n            }\n            int j2 = j1 * 2, pos2 = pos1 + 1;\n            for (; pos2 < n && j2 < nn; j2 *= 2, pos2++) {\n                if ((i & j2) == 0) continue;\n                a = D[pos1][pos2] + Dp(i ^ (j1 | j2));\n                if (a < ans) {\n                    ans = a;\n                    p = i ^ (j1 | j2);\n                }\n            }\n            break;\n        }       \n        dp[i] = ans;\n        prev[i] = p;\n        return ans;\n    }\n\n    private int sqr(int i) {\n        return i * i;\n    }\n\n    // ////////////////////////////////////////////////////////////////////\n    // Utility functions\n\n    PrintWriter pw;\n    BufferedReader in;\n    StringTokenizer st;\n\n    void initStreams() throws FileNotFoundException {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n    }\n\n    String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    static Throwable sError;\n\n    public static void main(String[] args) throws Throwable {\n//      Thread t = new Thread(null, new Main(), \"1\", 1 << 27);\n//      t.start();\n//      t.join();\n        new Main().run();\n        if (sError instanceof OutOfMemoryError) {\n            throw sError;\n        }\n//      if (sError != null) {\n//          throw sError;\n//      }\n    }\n\n    public void run() {\n        try {\n            initStreams();\n            solve();\n        } catch (Throwable e) {\n            sError = e;\n        } finally {\n            if (pw != null)\n                pw.close();\n        }\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class c8 {\n    static int n;\n    static int[] ds;\n    static int[][] g;\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int x = input.nextInt(), y = input.nextInt();\n    int n = input.nextInt();\n    int[] xs = new int[n], ys = new int[n];\n    for(int i = 0; i<n; i++)\n    {\n        xs[i] = input.nextInt();\n        ys[i] = input.nextInt();\n    }\n    ds = new int[n];\n    g = new int[n][n];\n    for(int i = 0; i<n; i++)\n    {\n        ds[i] = (x - xs[i])  *  (x - xs[i]) + (y - ys[i]) * (y - ys[i]);\n        for(int j = 0; j<n; j++)\n        {\n            g[i][j] = (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);\n        }\n    }\n    int[] dp = new int[1<<n];\n    Arrays.fill(dp, 987654321);\n    dp[0] = 0;\n    for(int i = 0; i<(1<<n); i++)\n    {\n        if(dp[i] == 987654321) continue;\n        for(int a = 0; a<n; a++)\n        {\n            if((i & (1<<a)) > 0) continue;\n            dp[i | (1<<a)] = Math.min(dp[i | (1<<a)], dp[i] + 2*ds[a]);\n            for(int b = a+1; b<n; b++)\n            {\n                if((i & (1<<b)) > 0) continue;\n                dp[i | (1<<a) | (1<<b)] = Math.min(dp[i | (1<<a) | (1<<b)], dp[i] + ds[a] + ds[b] + g[a][b]);\n            }\n            break;\n        }\n    }\n    Stack<Integer> stk = new Stack<Integer>();\n    stk.add(0);\n    int i = (1<<n) - 1;\n    //System.out.println(Arrays.toString(dp));\n\n    trace:\n    while(i > 0)\n    {\n        //System.out.println(i);\n        for(int a = 0; a<n; a++)\n        {\n            if((i & (1<<a)) == 0) continue;\n            if( dp[i] == dp[i - (1<<a)] + 2*ds[a])\n            {\n                stk.add(a+1);\n                stk.add(0);\n                i -= (1<<a);\n                continue trace;\n            }\n            for(int b = a+1; b<n; b++)\n            {\n                if((i & (1<<b)) == 0) continue;\n                if(dp[i] == dp[i - (1<<a) - (1<<b)] + ds[a] + ds[b] + g[a][b])\n                {\n                    stk.add(a+1);\n                    stk.add(b+1);\n                    stk.add(0);\n                    i -= (1<<a) + (1<<b);\n                    continue trace;\n                }\n            }\n            //break;\n        }\n    }\n    System.out.println(dp[(1<<n) - 1]);\n    while(!stk.isEmpty()) System.out.print(stk.pop()+\" \");\n}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A558 {\n  static BufferedReader in = null;\n  static PrintWriter out = null;\n  static StringTokenizer st = new StringTokenizer(\"\");\n\n  public static void main(String[] args) {\n    try {\n      in = 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    }\n  }\n\n  public static String readString() {\n    while (!st.hasMoreTokens()) {\n      try {\n        st = new StringTokenizer(in.readLine(), \" \\n\\r\\t:\");\n      } catch (Exception e) {\n        e.printStackTrace();\n      }\n    }\n    return st.nextToken();\n  }\n\n\n  public static int readInt() {\n    return Integer.parseInt(readString());\n  }\n\n  public static long readLong() {\n    return Long.parseLong(readString());\n  }\n\n  private static int MAX_VALUE = Integer.MAX_VALUE - 10000000;\n  private static int[] dp;\n  private static int[] parents;\n  private static int[] powers;\n  private static int[] x;\n  private static int[] y;\n  private static int[][] dist;\n  private static int[] distFrom0;\n\n  private static void solve() throws IOException {\n    int x0 = readInt();\n    int y0 = readInt();\n    int n = readInt();\n    long time = System.currentTimeMillis();\n    x = new int[n];\n    y = new int[n];\n    for (int i = 0; i < n; i++) {\n      x[i] = readInt() - x0;\n      y[i] = readInt() - y0;\n    }\n    dist = new int[n][n];\n    distFrom0 = new int[n];\n    for (int i = 0; i < n; i++) {\n      for (int j = 0; j < n; j++) {\n        dist[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n      }\n    }\n    for (int i = 0; i < n; i++) {\n      distFrom0[i] = x[i] * x[i] + y[i] * y[i];\n    }\n    powers = new int[n + 1];\n    powers[0] = 1;\n    for (int i = 1; i < n + 1; i++) {\n      powers[i] = powers[i - 1] * 2;\n    }\n    int maxMask = 1 << n;\n    dp = new int[maxMask];\n    parents = new int[maxMask];\n    Arrays.fill(dp, MAX_VALUE);\n    dp[0] = 0;\n    for (int i = 0; i < maxMask; i++) {\n      if (dp[i] != MAX_VALUE) {\n        int curMask = i;\n        int notUsed = 0;\n        for (int j = 0; j < n; j++) {\n          if ((curMask & powers[j]) == 0) {\n            notUsed = j;\n            break;\n          }\n        }\n        int mask = curMask | powers[notUsed];\n        for (int j = notUsed; j < n; j++) {\n          if ((powers[j] & curMask) == 0 || j == notUsed) {\n            int nextMask = mask | powers[j];\n            int minDist = dp[curMask] + distFrom0[notUsed] + dist[notUsed][j] + distFrom0[j];\n            if (dp[nextMask] > minDist) {\n              dp[nextMask] = minDist;\n              parents[nextMask] = curMask;\n            }\n          }\n        }\n      }\n    }\n   // System.err.println(((System.currentTimeMillis() - time)));\n    // brute(n, 0)\n    maxMask--;\n    out.println(dp[maxMask]);\n    while (maxMask != 0) {\n      out.print(\"0 \");\n      int[] diffBits = getBits(n, maxMask, parents[maxMask]);\n      for (int i = 1; i <= diffBits[0]; i++) {\n        out.print(diffBits[i] + 1 + \" \");\n      }\n      maxMask = parents[maxMask];\n    }\n    out.print(0);\n    //System.err.println((System.currentTimeMillis() - time));\n  }\n\n  private static boolean hasBit(int x, int index) {\n    return (powers[index] & x) != 0;\n  }\n\n  private static int setBit(int x, int index) {\n    return (x | powers[index]);\n  }\n\n  private static int getDist(int xFrom, int yFrom, int xTo, int yTo) {\n    return (xTo - xFrom) * (xTo - xFrom) + (yTo - yFrom) * (yTo - yFrom);\n  }\n\n  private static int[] getBits(int n, int nextMask, int curMask) {\n    int[] res = new int[3];\n    for (int i = 0; i < n; i++) {\n      if (hasBit(nextMask, i) ^ hasBit(curMask, i)) {\n        res[++res[0]] = i;\n      }\n    }\n    return res;\n  }\n\n  private static void brute(int n, int mask) {\n    List<Integer> listNotTaken = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n      if (!hasBit(mask, i)) {\n        listNotTaken.add(i);\n      }\n    }\n    for (int first : listNotTaken) {\n      int temp = setBit(mask, first);\n      for (int second : listNotTaken) {\n        int nextMask = setBit(temp, second);\n        int minDist = dp[mask] + getDist(0, 0, x[first], y[first]) + getDist(x[first], y[first], x[second], y[second]) + getDist(x[second], y[second], 0, 0);\n        if (dp[nextMask] > minDist) {\n          dp[nextMask] = minDist;\n          parents[nextMask] = mask;\n          brute(n, nextMask);\n        }\n      }\n    }\n  }\n\n}\n\n\n\n\n\n\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\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 Main {\n\n\tstatic int n, memo[], dS[], dd[][];\n\n\tstatic int dp(int idx, int msk)\n\t{\n\t\tif(msk == (1 << n) - 1)\n\t\t\treturn 0;\n\t\tif(memo[msk] != -1)\n\t\t\treturn memo[msk];\n\t\twhile((msk & 1 << idx) != 0)\n\t\t\t++idx;\n\t\tint ret = dS[idx] * 2 + dp(idx + 1, msk | 1 << idx);\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tif((msk & 1 << i) == 0)\n\t\t\t\tret = Math.min(ret, dS[i] + dS[idx] + dd[i][idx] + dp(idx + 1, msk | 1 << i | 1 << idx));\n\t\treturn memo[msk] = ret;\n\t}\n\t\n\tstatic StringBuilder sb = new StringBuilder(\"0 \");\n\t\n\tstatic void print(int idx, int msk)\n\t{\n\t\tif(msk == (1 << n) - 1)\n\t\t\treturn;\n\t\tint opt = dp(idx, msk);\n\t\twhile((msk & 1 << idx) != 0)\n\t\t\t++idx;\n\t\tif(dS[idx] * 2 + dp(idx + 1, msk | 1 << idx) == opt)\n\t\t{\n\t\t\tsb.append((idx + 1) + \" 0 \");\n\t\t\tprint(idx + 1, msk | 1 << idx);\n\t\t\treturn;\n\t\t}\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tif((msk & 1 << i) == 0)\n\t\t\t\tif(opt == dS[i] + dS[idx] + dd[i][idx] + dp(idx + 1, msk | 1 << i | 1 << idx))\n\t\t\t\t{\n\t\t\t\t\tsb.append((idx + 1) + \" \" + (i + 1) + \" 0 \");\n\t\t\t\t\tprint(idx + 1, msk | 1 << i | 1 << idx);\n\t\t\t\t\treturn;\n\t\t\t\t}\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\n\t\tPoint s = new Point(sc.nextInt(), sc.nextInt());\n\t\tn = sc.nextInt();\n\t\tPoint[] a = new Point[n];\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\ta[i] = new Point(sc.nextInt(), sc.nextInt());\n\t\tdS = new int[n];\n\t\tdd = new int[n][n];\n\t\tfor(int i = 0; i < n; ++i)\n\t\t{\n\t\t\tdS[i] = dist2(s, a[i]);\n\t\t\tfor(int j = 0; j < n; ++j)\n\t\t\t\tdd[i][j] = dist2(a[i], a[j]);\n\t\t}\n\n\t\tmemo = new int[1 << n];\n\t\tArrays.fill(memo, -1);\n\t\tout.println(dp(0, 0));\n\t\tprint(0, 0);\n\t\tout.println(sb);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic int dist2(Point a, Point b) { return sq(a.x - b.x) + sq(a.y - b.y); }\n\n\tstatic int sq(int x) { return x * x; }\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} ", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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 Main implements Runnable {\n\n    // ////////////////////////////////////////////////////\n    // Solution\n\n    private int n;\n    private int nn;\n    private int[][] D;\n    private int[] dp;\n    private int[] prev;\n\n    private void solve() throws Throwable {\n        int xs = nextInt(), ys = nextInt();\n        n = nextInt();\n        int[][] pts = new int[n][2];\n        for (int i = 0; i < n; i++) {\n            pts[i][0] = nextInt();\n            pts[i][1] = nextInt();\n        }\n        D = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (i == j) {\n                    D[i][i] = 2 * (sqr(pts[i][0] - xs) + sqr(pts[i][1] - ys));\n                } else {\n                    D[i][j] = sqr(pts[i][0] - xs) + sqr(pts[i][1] - ys)\n                            + sqr(pts[i][0] - pts[j][0])\n                            + sqr(pts[i][1] - pts[j][1]) + sqr(pts[j][0] - xs)\n                            + sqr(pts[j][1] - ys);\n                }\n            }\n        }\n        nn = 1 << n;\n        dp = new int[nn];\n        prev = new int[nn];\n        Arrays.fill(dp, -1);\n        Arrays.fill(prev, -1);\n        dp[0] = 0;\n        Dp(nn - 1);\n        pw.println(dp[nn - 1]);\n        pw.print(0);\n        for (int p = nn - 1; p != -1 && prev[p] != -1; p = prev[p]) {\n            int vv = p ^ prev[p];\n            for (int j = 0; j < n; j++) {\n                int jj = 1 << j;\n                if ((vv & jj) == 0)\n                    continue;\n                pw.print(' ');\n                pw.print(j + 1);\n            }\n            pw.print(\" 0\");\n        }\n        pw.println();\n    }\n\n    private int Dp(int i) {\n        if (dp[i] != -1)\n            return dp[i];\n        int ans = 107374182, p = -1;\n        int j1 = 1, pos1 = 0;\n        for (; pos1 < n && j1 < nn; j1 *= 2, pos1++) {\n            if ((i & j1) == 0)\n                continue;\n            int a = D[pos1][pos1] + Dp(i ^ j1);\n            if (a < ans) {\n                ans = a;\n                p = i ^ j1;\n            }\n            int j2 = j1 * 2, pos2 = pos1 + 1;\n            for (; pos2 < n && j2 < nn; j2 *= 2, pos2++) {\n                if ((i & j2) == 0)\n                    continue;\n                a = D[pos1][pos2] + Dp(i ^ (j1 | j2));\n                if (a < ans) {\n                    ans = a;\n                    p = i ^ (j1 | j2);\n                }\n            }\n            break;\n        }\n        dp[i] = ans;\n        prev[i] = p;\n        return ans;\n    }\n\n    private int sqr(int i) {\n        return i * i;\n    }\n\n    // ////////////////////////////////////////////////////\n    // Utility functions\n\n    private void initstreams() throws Throwable {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in, \"ISO-8859-1\"));\n        pw = new PrintWriter(System.out);\n    }\n\n    BufferedReader in;\n    PrintWriter pw;\n    StringTokenizer st;\n\n    String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    @Override\n    public void run() {\n        try {\n            initstreams();\n            solve();\n        } catch (Throwable e) {\n            sError = e;\n        } finally {\n            if (pw != null)\n                pw.close();\n        }\n    }\n\n    private static Throwable sError;\n\n    public static void main(String[] args) throws Throwable {\n        Thread t = new Thread(new Main());\n        t.start();\n        t.join();\n        if (sError != null)\n            throw sError;\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class C\n{\n   public static void main(String[] args)\n   {\n      new C(new Scanner(System.in));\n   }\n\n   vect[] vs;\n   int N;\n   int oo = 987654321;\n\n   ArrayList<choice> cs;\n   choice[][] cg;\n\n   int MF;\n\n   int[] memo;\n   int[] next;\n\n   int go(int m)\n   {\n      if (m == MF)\n         return 0;\n      if (memo[m] != -1)\n         return memo[m];\n\n      // Try a new place\n      int res = oo;\n      int nxt = -1;\n\n      int i=0;\n      for (i=0; i<N; i++)\n      {\n         if (((1<<i)&m) == 0)\n            break;\n      }\n\n      for (int j=0; j<N; j++)\n      {\n         choice cc = cg[i][j];\n         if ((m&cc.m) > 0)\n            continue;\n\n         int r2 = cc.cost+go(m|cc.m);\n         if (r2 < res)\n         {\n            res = r2;\n            nxt = cc.index;\n         }\n      }\n\n      memo[m] = res;\n      next[m] = nxt;\n      return res;\n   }\n\n   public C(Scanner in)\n   {\n      vect vt = new vect(in.nextInt(), in.nextInt());\n      N = in.nextInt();\n      vs = new vect[N+1];\n      vs[N] = vt;\n      for (int i=0; i<N; i++)\n         vs[i] = new vect(in.nextInt(), in.nextInt());\n  \n      // Precompute all choices and masks\n      cs = new ArrayList<choice>();\n      cg = new choice[N][N];\n      for (int i=0; i<N; i++)\n      {\n         choice cc = new choice(cs.size(), 2*vs[i].dist(vt), 1<<i);\n         cc.add(i);\n         cs.add(cc);\n         cg[i][i] = cc;\n      }\n\n      for (int i=0; i<N; i++)\n      {\n         for (int j=i+1; j<N; j++)\n         {\n            int dist = vs[i].dist(vt);\n            dist += vs[i].dist(vs[j]);\n            dist += vs[j].dist(vt);\n            choice cc = new choice(cs.size(), dist, (1<<i)|(1<<j));\n            cc.add(i); cc.add(j);\n            cs.add(cc);\n            cg[i][j] = cc;\n            cg[j][i] = cc;\n         }\n      }\n\n      MF = (1<<N)-1;\n      next = new int[MF+1];\n      memo = new int[MF+1];\n\n      Arrays.fill(next, -1);\n      Arrays.fill(memo, -1);\n\n      int res = go(0);\n      System.out.println(res);\n\n      int m = 0;\n      StringBuilder sb = new StringBuilder();\n      while (m != -1)\n      {\n         //System.out.println(Integer.toBinaryString(m));\n         sb.append(0);\n         sb.append(' ');\n         int i = next[m];\n         if (i == -1)\n            break;\n         choice cc = cs.get(i);\n         for (int j : cc.iv)\n         {\n            sb.append(f(j));\n            sb.append(' ');\n         }\n         m = m|cc.m;\n      }\n      System.out.println(sb.toString().trim());\n   }\n\n   int f(int i)\n   {\n      if (i == N)\n         return 0;\n      return i+1;\n   }\n}\n\n\nclass choice\n{\n   int cost;\n   int m;\n   int index;\n   ArrayList<Integer> iv;\n\n   public choice(int ii, int c, int mm)\n   {\n      index = ii;\n      cost = c;\n      m = mm;\n      iv = new ArrayList<Integer>(2);\n   }\n\n   void add(int i)\n   {\n      iv.add(i);\n   }\n}\n\n\nclass vect\n{\n   int x, y;\n\n   public vect(int i, int j)\n   {\n      x=i; y=j;\n   }\n\n   int dist(vect rhs)\n   {\n      int xx = x-rhs.x;\n      int yy = y-rhs.y;\n      return xx*xx+yy*yy;\n   }\n}\n\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n/**\n * Created by Brandt Henslee on 2/24/2015.\n */\npublic class Main {\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        String[] parsedString;\n        int objectNum = 0;\n        int xStart=0;\n        int yStart=0;\n\n        parsedString = in.readLine().split(\" \");\n        xStart = Integer.parseInt(parsedString[0]);\n        yStart = Integer.parseInt(parsedString[1]);\n        objectNum = Integer.parseInt(in.readLine());\n\n        int[] xLocs = new int[objectNum+1];\n        int[] yLocs = new int[objectNum+1];\n        int[] bitMasks = new int[1<<objectNum];\n        Arrays.fill(bitMasks, -1);\n        int[] previous = new int[1<<objectNum];\n\n        xLocs[objectNum]=xStart;\n        yLocs[objectNum]=yStart;\n        for(int i=0; i<objectNum; i++){\n            parsedString = in.readLine().split(\" \");\n            xLocs[i] = Integer.parseInt(parsedString[0]);\n            yLocs[i] = Integer.parseInt(parsedString[1]);\n        }\n\n        //go through all pairs and find time requirement for each pair of objects\n        //the entry at point [i][j] is equal to the time it takes to get from point i to point j\n        int[][] times = new int[objectNum+1][objectNum+1];\n        for(int i=0;i<=objectNum;i++){\n            for(int j=0; j<=objectNum;j++){\n                times[i][j] = times[j][i] = (xLocs[i]-xLocs[j])*(xLocs[i]-xLocs[j])+(yLocs[i]-yLocs[j])*(yLocs[i]-yLocs[j]);\n            }\n        }\n\n        //each value in bitmasks represents the minimum time necessary to get\n        //the unmasked bits\n        //so bitmasks[5] (5=101) is the fastest time in which you can get\n        //items 1 and 3\n        bitMasks[0] = 0; //collecting zero objects takes 0 time\n        //1<<n makes the n+1 position in the bit string = 1\n        //1<<2 = 100\n        for (int i=0; i<(1<<objectNum); i++){\n            if(bitMasks[i]==-1) {\n\n            }else{\n                for(int j=0; j<objectNum; j++){\n                    if(((1<<j)&i) == 0){ //if our current j object hasn't been picked up yet\n                        int curState = (1<<j) | i; //ith state after picking up j object\n                        int curTime = bitMasks[i] + 2*times[objectNum][j]; //time required to get object j from bag at state i\n\n                        if(bitMasks[curState] == -1 || curTime < bitMasks[curState]){\n                            bitMasks[curState] = curTime; //put fastest time in for gettingto our current state\n                            previous[curState] = i;\n                        }\n\n\n                        for(int k=0; k<objectNum; k++){\n                            if(((1<<k) & curState) == 0){ //if the kth position in our current state hasn't been picked up\n                                int kState = ((1<<k) | curState); //curstate after picking pu kth object\n                                //kTime is time it takes to go from bag, to j, to k and back\n                                int kTime = bitMasks[i] + times[objectNum][j] + times[j][k] + times[k][objectNum];\n\n                                if(bitMasks[kState] == -1 || kTime < bitMasks[kState]){\n                                    bitMasks[kState] = kTime;  //put shortest tiem in for getting to kState\n                                    previous[kState] = i;\n                                }\n                            }\n                        }\n                        break;\n                    }\n                }\n            }\n\n        }\n\n        int finalState = (1<<objectNum)-1;\n\n        System.out.println(bitMasks[finalState]);\n\n        Deque<Integer> outputQ = new ArrayDeque<Integer>();\n        outputQ.add(0);\n        int curState = finalState;\n        while(curState>0){\n            //1100 ^ 1101 = 0001\n            //difference is the objects picked up in this state but not in previous state\n            int difference = curState ^ previous[curState];\n            int firstItem = -1;\n            int secondItem = -1;\n\n            for(int i=0; i<objectNum; i++){\n                if(((1<<i)&difference)>0){ //if the ith object was picked up in this state\n                    secondItem=firstItem; //keep track of how many items are picked up\n                    firstItem=i;\n                }\n            }\n\n            if(secondItem!=-1){\n                //put in two items followed by a return to 0\n\n                outputQ.add(firstItem+1);\n                outputQ.add(secondItem+1);\n                outputQ.add(0);\n            }\n            else{\n                outputQ.add(firstItem + 1);\n                outputQ.add(0);\n            }\n\n            curState = previous[curState];\n        }\n\n        System.out.print(outputQ.removeLast());\n        while(!outputQ.isEmpty()){\n            System.out.print(\" \");\n            System.out.print(outputQ.removeLast());\n        }\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Handbag\n{\n\t// http://codeforces.com/problemset/problem/8/C\t\n\t// Source of most code : http://codeforces.com/contest/8/submission/3492661\n\t\n\t// Keep track of each item location and also be able to \n\t// calculate distance between it and another object\n\tpublic static class Item{\n\t\tint x;\n\t\tint y;\n\t\t\n\t\tItem(int x, int y){\n\t\t\tthis.x = x; \n\t\t\tthis.y = y;\n\t\t}\n\t\t\n\t\t// Return distance between two points\n\t\tpublic int dist(Item i){\n\t\t\tint dx = x - i.x;\n\t\t\tint dy = y - i.y;\n\t\t\treturn dx*dx + dy*dy;\n\t\t}\n\t}\n\t\n\t// Each value in bits[] is the min time to get certain objects\n    // Ex. bits[6] = 110 is the fastest time to get items that correspond with the '1s'\n\tpublic static int solve(int bitNum){\n\t\t\n\t\tif(bitNum == (1 << N) - 1) // If bitNum is too big for the array\n\t\t\treturn 0;\n\t\t\n\t\tif(bits[bitNum] != -1) // If bit value has already been calculated\n\t\t\treturn bits[bitNum];\n\t\t\n\t\tint ans = Integer.MAX_VALUE;\n\t\tint j = 0;\n\t\tfor(int i = 1; i < N; i++){\n\t\t\t\n\t\t\tif((bitNum & (1 << i)) == 0){ // Performs bitwise AND operation to see if bitNum and i have no bits in common\n\t\t\t\t\n\t\t\t\tif(j == 0){ // Only happens on the first time in IF statement\n\t\t\t\t\t// One item that can be picked up before returning to handbag\n\t\t\t\t\tans = 2 * items[0].dist(items[i]) + solve(bitNum | (1 << i)); // Performs bitwise exclusive OR operation\n\t\t\t\t\tj = i; // Change value so this case isn't ever hit again && to store value to use in else statement dists\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t// Find the distance between the handbag and the first item\n\t\t\t\t\tint dist1 = items[0].dist(items[i]);\n\t\t\t\t\t// Find the distance between the first item and the second item\n\t\t\t\t\tint dist2 = items[i].dist(items[j]);\n\t\t\t\t\t// Find the distance between the second item and the handbag\n\t\t\t\t\tint dist3 = items[j].dist(items[0]);\n\t\t\t\t\t\n\t\t\t\t\t// Two items that can be picked up before returning to handbag\n\t\t\t\t\t// distance covered between any two objects in the time equal \n\t\t\t\t\t// to the squared length of the segment between the points of the objects\n\t\t\t\t\tans = Math.min(ans, dist1 + dist2 + dist3 + solve(bitNum | (1 << i) | (1 << j))); // Performs bitwise exclusive OR operation\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn bits[bitNum] = ans; // Store all values in bits[] to speed up solve and for use in printOptPath\n\t}\n\t\n\tstatic void printOptPath(int bitNum) {\n\t\tif (bitNum == (1 << N) - 1)\n\t\t\treturn;\n\t\t\n\t\t// Almost identical to solve equation except it doesn't calculate the answer, it checks the stored answer in bits \n\t\tint j = 0;\n\t\tfor (int i = 1; i < N; i++)\n\t\t\t\n\t\t\tif ((bitNum & (1 << i)) == 0) {\t\t\t\t\n\t\t\t\tif (j == 0) {\t\t\t\t\t\n\t\t\t\t\tj = i; // Change value so this case isn't ever hit again && to find distance to this specific item in else if statement\n\t\t\t\t\tif (bits[bitNum] == 2 * items[0].dist(items[i]) + solve(bitNum | (1 << i))) { // solve() should quickly return an answer because the bits[] has already been calculated\t\t\t\t\t\t\n\t\t\t\t\t\tpw.print(\" \" + i + \" 0\"); // One item that can be picked up before returning to handbag\n\t\t\t\t\t\tprintOptPath(bitNum | (1 << i)); // Recursively call print with new bitNum\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} \n\t\t\t\telse if (bits[bitNum] == \n\t\t\t\t\t\t\t\titems[0].dist(items[i]) + items[i].dist(items[j]) + items[j].dist(items[0]) + solve(bitNum | (1 << i) | (1 << j))) {\n\t\t\t\t\t\n\t\t\t\t\tpw.print(\" \" + j + \" \" + i + \" 0\"); // Two items that can be picked up before returning to handbag\n\t\t\t\t\tprintOptPath(bitNum | (1 << i) | (1 << j)); // Recursively call print with new bitNum\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t}\n\t\n\tprivate static int N = 0;\n\tprivate static Item[] items;\n\tprivate static int[] bits;\n\t\n\t// PrintWriter needs to be class member because of recursive print strategy\n\tprivate static PrintWriter pw = new PrintWriter(System.out);\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\t\t\n\t\t\n\t\tString[] input = br.readLine().split(\" \");\n\t\tItem handbag = new Item(Integer.parseInt(input[0]), Integer.parseInt(input[1]));\n\t\t\n\t\tN = Integer.parseInt(br.readLine()) + 1;\n\t\titems = new Item[N];\n\t\tfor(int n = 1; n < N; n++){\n\t\t\tinput = br.readLine().split(\" \");\n\t\t\titems[n] = new Item(Integer.parseInt(input[0]), Integer.parseInt(input[1]));\n\t\t}\t\t\n\t\titems[0] = handbag;\n\t\t\n\t\t// x << n is a right shift operator \n\t\t// which will remove the last n bits from x\n\t\t// Ex 1 << 2 => 4\n\t\tbits = new int[1 << N]; // Ex: 1 << 3 = 8; 1 << 5 = 64\n\t\tArrays.fill(bits, -1); // Init bits array to hold -1 values\n\t\t\n\t\tint ans = solve(1 << 0); // Start solving with bit #1\n\t\tpw.println(ans); // Min time needed to put items in handbag\n\t\t\n\t\tpw.print(\"0\"); // Init output with handbag location\n\t\tprintOptPath(1 << 0); // Print possible optimum path to pick up items\n\t\t\n\t\tpw.close();\n\t}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "//package round8;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint x = ni(), y = ni();\n\t\tint n = ni();\n\t\tint[][] co = new int[n][];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tco[i] = new int[]{ni()-x, ni()-y};\n\t\t}\n\t\t\n\t\tint[] c1 = new int[n];\n\t\tint[][] c2 = new int[n][n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tc1[i] = (co[i][0]*co[i][0]+co[i][1]*co[i][1])*2;\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\tc2[i][j] = c2[j][i] = (co[i][0]*co[i][0]+co[i][1]*co[i][1])+(co[j][0]*co[j][0]+co[j][1]*co[j][1])+(co[j][0]-co[i][0])*(co[j][0]-co[i][0])+(co[j][1]-co[i][1])*(co[j][1]-co[i][1]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] dp = new int[1<<n];\n\t\tint[] prev = new int[1<<n];\n\t\tprev[0] = -1;\n\t\tfor(int i = 1;i < 1<<n;i++){\n\t\t\tint a = Integer.numberOfTrailingZeros(i);\n\t\t\tdp[i] = c1[a] + dp[i^1<<a];\n\t\t\tprev[i] = 1<<a;\n\t\t\tfor(int j = a+1;j < n;j++){\n\t\t\t\tif(i<<31-j<0){\n\t\t\t\t\tint v = dp[i^1<<a^1<<j] + c2[a][j];\n\t\t\t\t\tif(v < dp[i]){\n\t\t\t\t\t\tdp[i] = v;\n\t\t\t\t\t\tprev[i] = 1<<a^1<<j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(dp[(1<<n)-1]);\n\t\tint cur = (1<<n)-1;\n\t\tout.print(\"0\");\n\t\twhile(true){\n\t\t\tint targ;\n\t\t\tif(prev[cur] == -1){\n\t\t\t\ttarg = cur;\n\t\t\t}else{\n\t\t\t\ttarg = prev[cur];\n\t\t\t\tcur ^= prev[cur];\n\t\t\t}\n\t\t\tint a = Integer.numberOfTrailingZeros(targ);\n\t\t\tint b = Integer.numberOfTrailingZeros(targ&targ-1);\n\t\t\tif(targ == 1<<a){\n\t\t\t\tout.print(\" \" + (a+1));\n\t\t\t}else{\n\t\t\t\tout.print(\" \" + (a+1));\n\t\t\t\tout.print(\" \" + (b+1));\n\t\t\t}\n\t\t\tout.print(\" 0\");\n\t\t\tif(cur == 0)break;\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 24, m = 99999;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(0 + \" \" + 0  + \" \" + n + \" \");\n//\t\tfor(int i = 0;i < n;i++){\n//\t\t\tsb.append(gen.nextInt(100) + \" \");\n//\t\t\tsb.append(gen.nextInt(100) + \" \");\n//\t\t}\n//\t\tINPUT = sb.toString();\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\n\t{\n\t\tnew C().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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class C {\n\tpublic static void main(String[] args) {\n\t\tnew C().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\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\tlong nextLong() {\n\t\treturn sc.nextLong();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn sc.nextDouble();\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\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\tint dist(Point p) {\n\t\t\treturn (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);\n\t\t}\n\t}\n\n\tvoid solve() {\n\t\tPoint p0 = new Point(nextInt(), nextInt());\n\t\tint n = nextInt();\n\t\tPoint[] p = new Point[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tp[i] = new Point(nextInt(), nextInt());\n\t\t}\n\t\tint[][] d = 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\td[i][j] = p[i].dist(p[j]);\n\t\t\t}\n\t\t}\n\t\tint[] d0 = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\td0[i] = p0.dist(p[i]);\n\t\t}\n\t\tint[] dp = new int[1 << n];\n\t\tArrays.fill(dp, 1 << 30);\n\t\tdp[0] = 0;\n\t\tint[] from = new int[1 << n];\n\t\tfor (int i = 0; i + 1 < 1 << n; i++) {\n\t\t\tint j = Integer.numberOfTrailingZeros(Integer.lowestOneBit(~i));\n\t\t\tint cnt = dp[i] + 2 * d0[j];\n\t\t\tif (dp[i ^ (1 << j)] > cnt) {\n\t\t\t\tdp[i ^ (1 << j)] = cnt;\n\t\t\t\tfrom[i ^ (1 << j)] = i;\n\t\t\t}\n\t\t\tfor (int k = j + 1; k < n; k++) {\n\t\t\t\tif (((i >> k) & 1) == 0) {\n\t\t\t\t\tcnt = dp[i] + d0[j] + d0[k] + d[j][k];\n\t\t\t\t\tif (dp[i ^ (1 << j) ^ (1 << k)] > cnt) {\n\t\t\t\t\t\tdp[i ^ (1 << j) ^ (1 << k)] = cnt;\n\t\t\t\t\t\tfrom[i ^ (1 << j) ^ (1 << k)] = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrayList<Integer> ans = new ArrayList<Integer>();\n\t\tans.add(0);\n\t\tint mask = (1 << n) - 1;\n\t\twhile (mask > 0) {\n\t\t\tint xor = mask ^ from[mask];\n\t\t\twhile (xor > 0) {\n\t\t\t\tans.add(Integer\n\t\t\t\t\t\t.numberOfTrailingZeros(Integer.lowestOneBit(xor)) + 1);\n\t\t\t\txor = xor & (xor - 1);\n\t\t\t}\n\t\t\tans.add(0);\n\t\t\tmask = from[mask];\n\t\t}\n\t\tout.println(dp[(1 << n) - 1]);\n\t\tfor (int i : ans) {\n\t\t\tout.print(i + \" \");\n\t\t}\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport static java.lang.Math.*;\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        long start;\n        if (debug)\n            start = System.nanoTime();\n        InputStream inputStream;\n        OutputStream outputStream;\n        if (useFiles) {\n            inputStream = new FileInputStream(fileName + \".in\");\n            outputStream = new FileOutputStream(fileName + \".out\");\n        } else {\n            inputStream = System.in;\n            outputStream = System.out;\n        }\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Task solver = new Task(in, out);\n        solver.solve();\n        if(debug)\n            out.println((System.nanoTime() - start) / 1e+9);\n        out.close();\n    }\n}\nclass Task {\n    int[][] dist, pre;\n    int[] x, y, d, prev;\n    String[] leafDescription;\n    String[] linerDescription;\n    String[][] allDescriptions;\n    int xs, ys, n;\n\n    int dist(int i, int j) {\n        return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n    }\n\n    void go(int[] prev, String[] leafDescription, int[] d, int len, int add, String description){\n        for (int mask = 0; mask < d.length; mask++) {\n            if ((mask & add) != add)\n                continue;\n            int newValue = d[mask & (~add)] + len;\n            if (d[mask] > newValue){\n                d[mask] = newValue;\n                leafDescription[mask] = description;\n                prev[mask] = mask & (~add);\n            }\n        }\n    }\n\n    int rec(int mask) {\n        if (d[mask] != -1)\n            return d[mask];\n        int lowest = 0;\n        for (; ((1 << lowest) & mask) == 0; lowest++) ;\n\n        int newMask = mask & (~(1 << lowest));\n        d[mask] = rec(newMask) + dist[lowest][n];\n        prev[mask] = newMask;\n        leafDescription[mask] = linerDescription[lowest];\n\n        for (int bit = lowest + 1; bit < n; bit++) {\n            if (((1 << bit) & mask) > 0) {\n                newMask = mask & (~(1 << bit)) & (~(1 << lowest));\n                int newValue = rec(newMask) + pre[bit][lowest];\n                if (newValue < d[mask]) {\n                    d[mask] = newValue;\n                    prev[mask] = newMask;\n                    leafDescription[mask] = allDescriptions[lowest][bit];\n                }\n            }\n        }\n        return d[mask];\n    }\n\n    public void solve() {\n        final int inf = (int) 1e+9;\n        xs = in.nextInt();\n        ys = in.nextInt();\n\n        n = in.nextInt();\n        x = new int[n + 1];\n        y = new int[n + 1];\n        for (int i = 0; i < n; i++) {\n            x[i] = in.nextInt();\n            y[i] = in.nextInt();\n        }\n        x[n] = xs;\n        y[n] = ys;\n\n        allDescriptions = new String[n][n];\n        for (int i = 0; i < n; i++){\n            for (int j = 0; j < n; j++){\n                allDescriptions[i][j] = (i + 1) + \" \" + (j + 1) + \" \";\n            }\n        }\n\n        linerDescription = new String[n];\n        for (int i = 0; i < n; i++){\n            linerDescription[i] = (i + 1) + \" \";\n        }\n\n        dist = new int[n + 1][n + 1];\n        pre = new int[n + 1][n + 1];\n        for (int i = 0; i <= n; i++) {\n            for (int j = 0; j <= n; j++) {\n                dist[i][j] = 2 * dist(i, j);\n                pre[i][j] = dist(i, n) + dist(i, j) + dist(j, n);\n            }\n        }\n\n        d = new int[1 << n];\n        Arrays.fill(d, -1);\n        d[0] = 0;\n        prev = new int[1 << n];\n        leafDescription = new String[1 << n];\n//        Arrays.fill(d, inf);\n//        prev[0] = 0;\n//        d[0] = 0;\n//        for (int i = 0; i < n; i++) {\n//            int add = 1 << i;\n//            int len = 2 * dist[n][i];\n//            String description = (i + 1) + \" \";\n//\n//            go(prev, leafDescription, d, len, add, description);\n//        }\n//        for (int i = 0; i < n; i++) {\n//            for (int j = i + 1; j < n; j++) {\n//                int add = (1 << i) | (1 << j);\n//                int len = dist[n][i] + dist[i][j] + dist[n][j];\n//                String description = (i + 1) + \" \" + (j + 1) + \" \";\n//\n//                go(prev, leafDescription, d, len, add, description);\n//            }\n//        }\n//        Debug.printObjects(out, d);\n//        Debug.printObjects(out, prev);\n//        Debug.printObjects(out, leafDescription);\n        int result = rec((1 << n) - 1);\n        String answer = \"\";\n        for (int curr = d.length - 1; prev[curr] != curr; curr = prev[curr] ){\n            answer += \"0 \" + leafDescription[curr];\n        }\n        answer += \"0\";\n        out.println(result);\n        out.println(answer);\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\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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\n\npublic class CF8C {\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\tint si = s.indexOf(' ', 0);\n\t\tint x = Integer.parseInt(s.substring(0, si));\n\t\tint y = Integer.parseInt(s.substring(si + 1));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint[] xx = new int[n + 1];\n\t\tint[] yy = new int[n + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ts = br.readLine();\n\t\t\tsi = s.indexOf(' ', 0);\n\t\t\txx[i] = Integer.parseInt(s.substring(0, si));\n\t\t\tyy[i] = Integer.parseInt(s.substring(si + 1));\n\t\t}\n\t\txx[n] = x;\n\t\tyy[n] = y;\n\t\tint[][] dd = new int[n + 1][n + 1];\n\t\tfor (int i = 0; i <= n; i++)\n\t\t\tfor (int j = i + 1; j <= n; j++) {\n\t\t\t\tint dx = xx[i] - xx[j];\n\t\t\t\tint dy = yy[i] - yy[j];\n\t\t\t\tdd[i][j] = dx * dx + dy * dy;\n\t\t\t}\n\t\tint[] aa = new int[1 << n];\n\t\tint[] bb = new int[1 << n];\n\t\tfor (int k = 1; k < 1 << n; k++) {\n\t\t\tint a = -1;\n\t\t\tfor (int b = 0; b < n; b++)\n\t\t\t\tif ((k & 1 << b) > 0) {\n\t\t\t\t\ta = b;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tint l = k ^ 1 << a;\n\t\t\tint d = dd[a][n] + dd[a][n];\n\t\t\taa[k] = aa[l] + d;\n\t\t\tbb[k] = l;\n\t\t\tfor (int b = a + 1; b < n; b++)\n\t\t\t\tif ((k & 1 << b) > 0) {\n\t\t\t\t\tl = k ^ 1 << a ^ 1 << b;\n\t\t\t\t\td = dd[a][n] + dd[b][n] + dd[a][b];\n\t\t\t\t\tif (aa[l] + d < aa[k]) {\n\t\t\t\t\t\taa[k] = aa[l] + d;\n\t\t\t\t\t\tbb[k] = l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\tint k = (1 << n) - 1;\n\t\tSystem.out.println(aa[k]);\n\t\tStringBuilder sb = new StringBuilder();\n\t\tsb.append(0);\n\t\twhile (k != 0) {\n\t\t\tint l = bb[k];\n\t\t\tint m = k ^ l;\n\t\t\tfor (int b = 0; b < n; b++)\n\t\t\t\tif ((m & 1 << b) > 0)\n\t\t\t\t\tsb.append(' ').append(b + 1);\n\t\t\tsb.append(' ').append(0);\n\t\t\tk = l;\n\t\t}\n\t\tSystem.out.println(sb);\n\t}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        final int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        final int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        final int[] best = new int[1 << n];\n        final int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            int bestC = best[set ^ (1 << i)] + single[i];\n            int prevC = 1 << i;\n            int nextSet = set ^ (1 << i);\n            int unoI = 1 << i;\n            for (int j = i + 1, unoJ = 1 << (i + 1); j < n; ++j, unoJ <<= 1)\n                if ((set & unoJ) != 0) {\n                    int cur = best[nextSet ^ unoJ] + pair[i][j];\n                    if (cur < bestC) {\n                        bestC = cur;\n                        prevC = unoI | unoJ;\n                    }\n                }\n            best[set] = bestC;\n            prev[set] = prevC;\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n        \tint differents = prev[now];\n        \tfor(int i = 0; i < n; i++)\n\t\t\t\tif((differents & (1 << i)) != 0)\n\t\t\t\t{\n\t\t\t\t\t writer.print(\" \");\n\t\t             writer.print(i + 1);\n\t\t             now ^= 1 << i;\n\t\t\t\t}\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Problem_8C {\n  private static int dis(int x1, int y1, int x2, int y2) {\n    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n  }\n\n  public static void main(String[] args) {\n    Scanner sc = new Scanner(System.in);\n    int ox = sc.nextInt();\n    int oy = sc.nextInt();\n    int n = sc.nextInt();\n    int[] ix = new int[n];\n    int[] iy = new int[n];\n    int[] single = new int[n];\n    int[][] pair = new int[n][n];\n    for (int i = 0; i < n; i++) {\n      ix[i] = sc.nextInt();\n      iy[i] = sc.nextInt();\n      single[i] = dis(ox, oy, ix[i], iy[i]) * 2;\n      for (int j = 0; j < i; j++) {\n        pair[i][j] = pair[j][i] = dis(ix[i], iy[i], ix[j], iy[j]) + (single[i] + single[j]) / 2;\n      }\n    }\n    int[] min = new int[1 << n];\n    int[] pre = new int[1 << n];\n    for (int set = 1; set < 1 << n; set++) {\n      int i;\n      for (i = 0; i < n; i++) {\n        if ((set & (1 << i)) != 0) {\n          break;\n        }\n      }\n      min[set] = min[set ^ (1 << i)] + single[i];\n      pre[set] = set ^ (1 << i);\n      for (int j = 0; j < n; j++) {\n        if ((set & (1 << j)) == 0) {\n          continue;\n        }\n        if (min[set] > min[set ^ (1 << i) ^ (1 << j)] + pair[i][j]) {\n          min[set] = min[set ^ (1 << i) ^ (1 << j)] + pair[i][j];\n          pre[set] = set ^ (1 << i) ^ (1 << j);\n        }\n      }\n    }\n    System.out.println(min[(1 << n) - 1]);\n    for (int set = (1 << n) - 1; set != 0; set = pre[set]) {\n      System.out.print(\"0 \");\n      for (int i = 0; i < n; i++) {\n        if (((set ^ pre[set]) & (1 << i)) != 0) {\n          System.out.print((i + 1) + \" \");\n        }\n      }\n    }\n    System.out.println(\"0\");\n    sc.close();\n  }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        int[] best = new int[1 << n];\n        int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            best[set] = best[set ^ (1 << i)] + single[i];\n            prev[set] = 1 << i;\n            for (int j = i + 1; j < n; ++j)\n                if ((set & (1 << j)) != 0) {\n                    int cur = best[set ^ (1 << i) ^ (1 << j)] + pair[i][j];\n                    if (cur < best[set]) {\n                        best[set] = cur;\n                        prev[set] = (1 << i) | (1 << j);\n                    }\n                }\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n        \tint differents = prev[now];\n        \tfor(int i = 0; i < n; i++)\n\t\t\t\tif((differents & (1 << i)) != 0)\n\t\t\t\t{\n\t\t\t\t\t writer.print(\" \");\n\t\t             writer.print(i + 1);\n\t\t             now ^= 1 << i;\n\t\t\t\t}\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class LookingForOrder {\n\n\tstatic int[] dp = new int[(int) (1 << 24)];\n\tstatic int[][] points;\n\tstatic int[] sol = new int[1<<24];\n\tstatic int sx = 0, sy = 0;\n\n\tpublic static void main(String[] args) {\n\n\t\tsx = in.nextInt();\n\t\tsy = in.nextInt();\n\t\tArrays.fill(dp, -2);\n\n\t\tint n = in.nextInt();\n\t\tpoints = new int[n][3];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tpoints[i][0] = in.nextInt();\n\t\t\tpoints[i][1] = in.nextInt();\n\t\t\tpoints[i][2] = (sx - points[i][0]) * (sx - points[i][0]) + (sy - points[i][1]) * (sy - points[i][1]);\n\t\t}\n\n\t\t//System.out.println(\"ANS\");\n\t\tSystem.out.println(solve(0));\n\t\t\n\t\tint mask=0;\n\t\twhile(true){\n\t\t\tSystem.out.print(0+\" \");\n\t\t\tif (mask==(1<<n)-1) break;\n\t\t\tint x = sol[mask];\n\t\t\tint count=0;\n\t\t\tfor(int i=0; i<n; i++){\n\t\t\t\tif ((x&(1<<i))!=0) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tSystem.out.print((i+1)+\" \");\n\t\t\t\t\tmask|=(1<<i);\n\t\t\t\t}\n\t\t\t\tif (count==2) break;\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tSystem.out.println();\n\n\t}\n\n\tpublic static int solve(int mask) {\n\t\t\n\t\tif (dp[mask]!=-2) return dp[mask];\n\t\t\n\t\tint n = points.length;\n\t\tif (mask == ((1 << n)-1)) {\n\t\t\treturn dp[mask]=0;\n\t\t}\n\n\t\tint here = -1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((mask & (1<<i)) == 0) {\n\t\t\t\there = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\n\t\tint ans = 2*points[here][2]+solve(mask | (1 << here));\n\t\tsol[mask] = 1<<here;\n\n\t\tint x1 = points[here][0];\n\t\tint y1 = points[here][1];\n\n\t\tfor (int i = here + 1; i < n; i++) {\n\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\tint x2 = points[i][0];\n\t\t\t\tint y2 = points[i][1];\n\t\t\t\tint p = mask|(1<<here);\n\t\t\t\tp = p|(1<<i);\n\t\t\t\tif (ans>points[here][2] + points[i][2] + (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)\n\t\t\t\t\t\t+ solve(p)){\n\t\t\t\t\tans=points[here][2] + points[i][2] + (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)\n\t\t\t\t\t\t\t+ solve(p);\n\t\t\t\t\tsol[mask]=(1<<here)|(1<<i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn dp[mask]=ans;\n\t}\n\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\n\t}\n\n\tstatic MyScanner in = new MyScanner();\n\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class CodeD \n{\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\t\n\t\tpublic String nextLine()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn br.readLine();\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tthrow(new RuntimeException());\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic String next()\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t{\n\t\t\t\tString l = nextLine();\n\t\t\t\tif(l == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(l);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong[] res = new long[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic double[] nextDoubleArray(int n)\n\t\t{\n\t\t\tdouble[] res = new double[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\tpublic void sortIntArray(int[] array)\n\t\t{\n\t\t\tInteger[] vals = new Integer[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortLongArray(long[] array)\n\t\t{\n\t\t\tLong[] vals = new Long[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortDoubleArray(double[] array)\n\t\t{\n\t\t\tDouble[] vals = new Double[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t}\n\tstatic final Scanner sc;\n\tstatic final int n;\n\tstatic final int[][] distancias;\n\tstatic final int[] distancia;\n\tstatic final int[] dp;\n\tstatic final int[] dpNext;\n\tstatic final int X;\n\tstatic final int Y;\n\t\n\tstatic\n\t{\n\t\tsc = new Scanner();\n\t\tX = sc.nextInt();\n\t\tY = sc.nextInt();\n\t\tn = sc.nextInt();\n\t\tdistancias = new int[n][n];\n\t\tdistancia = new int[n];\n\t\tdp = new int[1 << n];\n\t\tArrays.fill(dp, -1);\n\t\tdpNext = new int[1 << n];\n\t}\n\t\n\t\n\tstatic int dp(int mascara)\n\t{\n\t\tif(dp[mascara] != -1)\n\t\t\treturn dp[mascara];\n\t\tint highest = -1;\n\t\tfor(int i = 0, tmp = mascara; tmp != 0; i++, tmp >>= 1)\n\t\t{\n\t\t\tif((tmp & 1) == 1)\n\t\t\t{\n\t\t\t\thighest = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(highest == -1)\n\t\t\treturn 0;\n\t\tint nextMsc = mascara ^ (1 << highest);\n\t\tint costHighest = distancia[highest];\n\t\tint best = (costHighest << 1) + dp(nextMsc);\n\t\tint bestNext = nextMsc;\n\t\tfor(int i = 0, tmp = nextMsc, iC = 1; tmp != 0; i++, tmp >>= 1, iC <<= 1)\n\t\t{\n\t\t\tif((tmp & 1) == 1)\n\t\t\t{\n\t\t\t\tint msc = nextMsc ^ iC;\n\t\t\t\tint possibleA = costHighest + distancias[highest][i] + distancia[i] + dp(msc);\n\t\t\t\tif(possibleA < best)\n\t\t\t\t{\n\t\t\t\t\tbest = possibleA;\n\t\t\t\t\tbestNext = msc;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdpNext[mascara] = bestNext;\n\t\treturn dp[mascara] = best;\n\t\t\t\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tint[][] objetos = new int[n][2];\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tobjetos[i][0] = sc.nextInt();\n\t\t\tobjetos[i][1] = sc.nextInt();\n\t\t\tdistancia[i] = (X - objetos[i][0]) * (X - objetos[i][0]) + (Y - objetos[i][1]) * (Y - objetos[i][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\tdistancias[i][j] = (objetos[i][0] - objetos[j][0]) * (objetos[i][0] - objetos[j][0]) + (objetos[i][1] - objetos[j][1]) * (objetos[i][1] - objetos[j][1]);\n\t\tint ans = dp((1 << n) - 1);\n\t\tSystem.out.println(ans);\n\t\tint current = (1 << n) - 1;\n\t\twhile(current != 0)\n\t\t{\n\t\t\tint next = dpNext[current];\n\t\t\tint differents = next ^ current;\n\t\t\tSystem.out.print(\"0 \");\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tif((differents & (1 << i)) != 0)\n\t\t\t\t\tSystem.out.print((i + 1) + \" \");\n\t\t\tcurrent = next;\n\t\t}\n\t\tSystem.out.println(\"0\");\n\t}\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint xs = sc.nextInt();\n\t\tint ys = sc.nextInt();\n\t\tint n = sc.nextInt();\n\t\tint[]x = new int[n], y = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = sc.nextInt();\n\t\t\ty[i] = sc.nextInt();\n\t\t}\n\t\tint[]single = new int[n];\n\t\tint[][]pair = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsingle[i] = 2*((x[i]-xs)*(x[i]-xs)+(y[i]-ys)*(y[i]-ys));\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\tpair[i][j] = (x[i]-xs)*(x[i]-xs)+(y[i]-ys)*(y[i]-ys)+(x[j]-xs)*(x[j]-xs)+(y[j]-ys)*(y[j]-ys)+(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);\n\t\t\t}\n\t\t}\n\t\tint[]best = new int[1 << n], prev = new int[1 << n];\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tint i = 0;\n\t\t\twhile ((mask & (1 << i))==0)\n\t\t\t\ti++;\n\t\t\tbest[mask] = best[mask ^ (1 << i)]+single[i];\n\t\t\tprev[mask] = i+1;\n\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\tif ((mask & (1 << j)) != 0) {\n\t\t\t\t\tint temp = best[mask ^ (1 << i) ^ (1 << j)]+pair[i][j];\n\t\t\t\t\tif (temp < best[mask]) {\n\t\t\t\t\t\tbest[mask] = temp;\n\t\t\t\t\t\tprev[mask] = (i+1)*100+(j+1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(best[(1 << n) - 1]);\n\t\tSystem.out.print(\"0 \");\n\t\tint cur = (1 << n) - 1;\n\t\twhile (cur > 0) {\n\t\t\tint a = prev[cur]  % 100;\n\t\t\tint b = prev[cur] / 100;\n\t\t\tif (a > 0) {\n\t\t\t\tSystem.out.print(a+\" \");\n\t\t\t\tcur ^= 1 << (a-1);\n\t\t\t}\n\t\t\tif (b > 0) {\n\t\t\t\tSystem.out.print(b+\" \");\n\t\t\t\tcur ^= 1 << (b-1);\n\t\t\t}\n\t\t\tSystem.out.print(0+\" \");\n\t\t}\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        final int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        final int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        final int[] best = new int[1 << n];\n        final int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            int bestC = best[set ^ (1 << i)] + single[i];\n            int prevC = 1 << i;\n            int nextSet = set ^ (1 << i);\n            int unoI = 1 << i;\n            int msc = set >> (i + 1);\n            for (int j = i + 1, unoJ = 1 << (i + 1); msc != 0 && j < n; ++j, unoJ <<= 1, msc >>= 1)\n                if ((msc & 1) != 0) {\n                    int cur = best[nextSet ^ unoJ] + pair[i][j];\n                    if (cur < bestC) {\n                        bestC = cur;\n                        prevC = unoI | unoJ;\n                    }\n                }\n            best[set] = bestC;\n            prev[set] = prevC;\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n        \tint differents = prev[now];\n        \tfor(int i = 0; i < n; i++)\n\t\t\t\tif((differents & (1 << i)) != 0)\n\t\t\t\t{\n\t\t\t\t\t writer.print(\" \");\n\t\t             writer.print(i + 1);\n\t\t             now ^= 1 << i;\n\t\t\t\t}\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main {\n\t\n\tstatic int hx, hy;\n\tstatic int[] X, Y;\n\tstatic int N;\n\tstatic int[] DP;\n\t\n\tstatic int pw(int a) {\n\t\treturn a * a;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\thx = sc.nextInt();\n\t\thy = sc.nextInt();\n\t\tN = sc.nextInt();\n\t\tX = new int[N];\n\t\tY = new int[N];\n\t\tfor (int i = 0; i < N; ++i) {\n\t\t\tX[i] = sc.nextInt();\n\t\t\tY[i] = sc.nextInt();\n\t\t}\n\t\tDP = new int[1 << N];\n\t\tArrays.fill(DP, -1);\n\t\tint ans = recur(0);\n\t\tArrayList<Integer> aa = new ArrayList<Integer>();\n\t\tint U = 0;\n\t\taa.add(0);\n\t\tint test = 0;\n\t\twhile (U != (1 << N) - 1) {\n\t\t\tint a = 0;\n\t\t\tfor (int i = 0; i < N; ++i) {\n\t\t\t\tif (((1 << i) & U) == 0) {\n\t\t\t\t\ta = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint ans2 = recur(U | (1 << a)) + 2 * (pw(X[a] - hx) + pw(Y[a] - hy));\n\t\t\tint temp = 2 * (pw(X[a] - hx) + pw(Y[a] - hy));\n\t\t\tint best = -1;\n\t\t\tfor (int i = a + 1; i < N; ++i) {\n\t\t\t\tif (((1 << i) & U) == 0) {\n\t\t\t\t\tint ans3 = recur(U|(1<<a)|(1<<i)) + pw(X[a]-X[i])+pw(Y[a]-Y[i]) + pw(X[a]-hx)+pw(Y[a]-hy) + pw(X[i]-hx)+pw(Y[i]-hy);\n\t\t\t\t\tif (ans3 < ans2) {\n\t\t\t\t\t\tans2 = ans3;\n\t\t\t\t\t\tans2 = ans3;\n\t\t\t\t\t\tbest = i;\n\t\t\t\t\t\ttemp = pw(X[a]-X[i])+pw(Y[a]-Y[i]) + pw(X[a]-hx)+pw(Y[a]-hy) + pw(X[i]-hx)+pw(Y[i]-hy);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (best == -1) {\n\t\t\t\taa.add(a + 1);\n\t\t\t\taa.add(0);\n\t\t\t\tU |= (1 << a);\n\t\t\t} else {\n\t\t\t\taa.add(a + 1);\n\t\t\t\taa.add(best + 1);\n\t\t\t\taa.add(0);\n\t\t\t\tU |= (1 << a) | (1 << best);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tfor (int i = 0; i < aa.size(); ++i) {\n\t\t\tSystem.out.print(aa.get(i) + \" \");\n\t\t}\n\t}\n\t\n\tprivate static int recur(int U) {\n\t\tif (DP[U] != -1) {\n\t\t\treturn DP[U];\n\t\t}\n\t\tif (U == (1 << N) - 1) {\n\t\t\treturn 0;\n\t\t}\n\t\tint a = 0;\n\t\tfor (int i = 0; i < N; ++i) {\n\t\t\tif (((1 << i) & U) == 0) {\n\t\t\t\ta = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tint ans = recur(U | (1 << a)) + 2 * (pw(X[a] - hx) + pw(Y[a] - hy));\n\t\tfor (int i = a + 1; i < N; ++i) {\n\t\t\tif (((1 << i) & U) == 0) {\n\t\t\t\tans = min(ans, recur(U|(1<<a)|(1<<i)) + pw(X[a]-X[i])+pw(Y[a]-Y[i]) + pw(X[a]-hx)+pw(Y[a]-hy) + pw(X[i]-hx)+pw(Y[i]-hy));\n\t\t\t}\n\t\t}\n\t\tDP[U] = ans;\n\t\treturn ans;\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class cf8c {\n  static int n;\n  static int[] bb;\n  static int[] memo;\n  static int[][] cost;\n  static FastIO in = new FastIO(), out = in;\n  public static void main(String[] args) {\n    vec2 cen = new vec2(in.nextInt(),in.nextInt());\n    n = in.nextInt();\n    cost = new int[n][n];\n    vec2[] v = new vec2[n];\n    for(int i=0; i<n; i++)\n      v[i] = new vec2(in.nextInt(),in.nextInt());\n    for(int i=0; i<n; i++)\n      for(int j=0; j<n; j++)\n        cost[i][j] = v[i].dist(cen) + v[i].dist(v[j]) + v[j].dist(cen);\n    memo = new int[1<<n];\n    bb = new int[1<<n];\n    Arrays.fill(memo,-1);\n    out.println(go(0));\n    build(0);\n    out.close();\n  }\n  static void build(int mask) {\n    if(mask == (1<<n)-1) {\n      out.println(0);\n      return;\n    }\n    int first = 0;\n    while((mask & (1<<first)) != 0) first++;\n    int second = bb[mask];\n    out.print(\"0 \" + (first+1) + \" \");\n    if(second != first)\n      out.print((second+1)+\" \");\n    build(mask|(1<<first)|(1<<second));\n  }\n  static int go(int mask) {\n    if(mask == (1<<n)-1) return 0;\n    if(memo[mask] != -1) return memo[mask];\n    int first = 0;\n    int ans = Integer.MAX_VALUE;\n    while((mask & (1<<first)) != 0) first++;\n    for(int second = first; second < n; second++) {\n      if((mask & (1<<second)) != 0) continue;\n      int tans = cost[first][second] + go(mask|(1<<first)|(1<<second));\n      if(tans < ans) {\n        ans = tans;\n        bb[mask] = second;\n      }\n    }\n    return memo[mask] = ans;\n  }\n  static class vec2 {\n    int x, y;\n    vec2(int a, int b) {\n      x = a; y = b;\n    }\n    vec2 sub(vec2 v) {\n      return new vec2(x-v.x,y-v.y);\n    }\n    int dist(vec2 v) {\n      return sub(v).mag2();\n    }\n    int mag2() {\n      return x*x+y*y;\n    }\n  }\n  static class FastIO extends PrintWriter {\n    BufferedReader br;\n    StringTokenizer st;\n    \n    public FastIO() {\n      this(System.in,System.out);\n    }\n    public FastIO(InputStream in, OutputStream out) {\n      super(new BufferedWriter(new OutputStreamWriter(out)));\n      br = new BufferedReader(new InputStreamReader(in));\n      scanLine();\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    public int numTokens() {\n      if(!st.hasMoreTokens()) {\n        scanLine();\n        return numTokens();\n      }\n      return st.countTokens();\n    }\n    public String next() {\n      if(!st.hasMoreTokens()) {\n        scanLine();\n        return next();\n      }\n      return st.nextToken();\n    }\n    public double nextDouble() {\n      return Double.parseDouble(next());\n    }\n    public long nextLong() {\n      return Long.parseLong(next());\n    }\n    public int nextInt() {\n      return Integer.parseInt(next());\n    }\n  }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.InputMismatchException;\nimport java.io.*;\nimport java.util.Vector;\nimport java.util.Collections;\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    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 Sellerman();\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    }\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    public int nextInt() {\n        return Integer.parseInt(nextToken());\n    }\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 Sellerman implements Solver {\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int x0 = in.nextInt();\n        int y0 = in.nextInt();\n        int n = in.nextInt() + 1;\n        int[] x = new int[n];\n        int[] y = new int[n];\n        x[n - 1] = x0;\n        y[n - 1] = y0;\n        for (int i = 0; i < n - 1; ++i) {\n            x[i] = in.nextInt();\n            y[i] = in.nextInt();\n        }\n        int [][] g = new int[n][n];\n        for(int i = 0; i < n; ++i)\n            for (int j = 0; j < n; ++j) {\n                g[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n            }\n        -- n;\n        int[] dm = new int[1 << n];\n        int[] prev = new int[1 << n];\n        byte [] bit = new byte[1 << n];\n        byte [] item0 = new byte[1 << n];\n        byte [] item1 = new byte[1 << n];\n        for (int i = 0; i < n; ++i) {\n            bit[1 << i] = (byte) i;\n        }\n        Arrays.fill(dm, -1);\n        dm[0] = 0;\n        int tt[][] = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j =0 ; j < n; ++j) {\n                tt[i][j] = Math.min(g[n][i] + g[i][j] + g[j][n],\n                                    g[n][j] + g[i][j] + g[i][n]);\n            }\n        for (int i = 0; i < (1 << n); ++i) {\n            if (dm[i] == -1)continue;\n            int t = (i ^ ((1 << n) - 1));\n            int left = bit[t - (t & (t - 1))];\n            for (int j = left; j < n; ++j) {\n                if ((i & (1 << j)) > 0) continue;\n                int nm = i | (1 << left) | (1 << j);\n                if (dm[nm] == -1 || dm[nm] > dm[i] + tt[left][j]) {\n                    dm[nm] = dm[i] + tt[left][j];\n                    prev[nm] = i;\n                    item0[nm] = (byte)left;\n                    item1[nm] = (byte)j;\n                }\n            }\n        }\n        out.println(dm[(1 << n) - 1]);\n        Vector<Vector<Integer>> path = new Vector<Vector<Integer>> () ;\n        int cmask = (1 << n) - 1;\n        while (cmask > 0) {\n            int p = prev[cmask];\n            Vector<Integer> tmp = new Vector<Integer> () ;\n            tmp.add(0);\n            tmp.add(item0[cmask] + 1);\n            tmp.add(item1[cmask] + 1);\n            cmask = prev[cmask];\n            path.add(tmp);\n        }\n        Collections.reverse(path);\n        int len = 0;\n        for (Vector<Integer> vec : path)\n            len += vec.size();\n        int ans[] = new int[len];\n        boolean[] valid = new boolean[len];\n        Arrays.fill(valid, true);\n        len = 0;\n        for (Vector<Integer> vec : path) {\n            for (int ttt : vec) {\n                ans[len ++] = ttt;\n            }\n        }\n        for (int i = 0; i < len - 1; ++i) {\n            if (ans[i] == ans[i + 1])\n                valid[i] = false;\n        }\n        for (int i = 0; i < len; ++i) {\n            if (valid[i]) {\n                out.print(ans[i] + \" \");\n            }\n        }\n        out.print(\"0\");\n\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\n// Solution is at the bottom of code\n\npublic class ProblemC_008 implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tOutputWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new ProblemC_008(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tLocale.setDefault(Locale.US);\n\t\t\n\t\tif (ONLINE_JUDGE){\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new OutputWriter(System.out);\n\t\t}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new OutputWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\t////////////////////////////////////////////////////////////////\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (ONLINE_JUDGE){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t\ttime();\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tString delim = \" \";\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tok.nextToken(delim);\n\t}\n\t\n\tString readLine() throws IOException{\n\t\treturn in.readLine();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tfinal char NOT_A_SYMBOL = '\\0';\n\t\n\tchar readChar() throws IOException{\n\t\tint intValue = in.read();\n\t\t\n\t\tif (intValue == -1){\n\t\t\treturn NOT_A_SYMBOL;\n\t\t}\n\t\t\n\t\treturn (char) intValue;\n\t}\n\t\n\tchar[] readCharArray() throws IOException{\n\t\treturn readLine().toCharArray();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tint[] readIntArray(int size) throws IOException{\n\t\tint[] array = new int[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readInt();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tlong[] readLongArray(int size) throws IOException{\n\t\tlong[] array = new long[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readLong();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tdouble[] readDoubleArray(int size) throws IOException{\n\t\tdouble[] array = new double[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readDouble();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tPoint readPoint() throws IOException{\n\t\treturn new Point(readInt(), readInt());\n\t}\n\t\n\tPoint[] readPointArray(int size) throws IOException{\n\t\tPoint[] array = new Point[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readPoint();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tclass OutputWriter extends PrintWriter{\n\n\t\tfinal int DEFAULT_PRECISION = 12;\n\t\t\n\t\tint precision;\n\t\tString format, formatWithSpace;\n\t\t\n\t\t{\n\t\t\tprecision = DEFAULT_PRECISION;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tpublic OutputWriter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\n\t\tpublic OutputWriter(String fileName) throws FileNotFoundException {\n\t\t\tsuper(fileName);\n\t\t}\n\t\t\n\t\tpublic int getPrecision() {\n\t\t\treturn precision;\n\t\t}\n\n\t\tpublic void setPrecision(int precision) {\n\t\t\tthis.precision = precision;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tprivate String createFormat(int precision){\n\t\t\treturn \"%.\" + precision + \"f\";\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void print(double d){\n\t\t\tprintf(format, d);\n\t\t}\n\t\t\n\t\tpublic void printWithSpace(double d){\n\t\t\tprintf(formatWithSpace, d);\n\t\t}\n\n\t\tpublic void printAll(double...d){\n\t\t\tfor (int i = 0; i < d.length - 1; ++i){\n\t\t\t\tprintWithSpace(d[i]);\n\t\t\t}\n\t\t\t\n\t\t\tprint(d[d.length - 1]);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void println(double d){\n\t\t\tprintlnAll(d);\n\t\t}\n\t\t\n\t\tpublic void printlnAll(double... d){\n\t\t\tprintAll(d);\n\t\t\tprintln();\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tint[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; \n\t\n\tboolean check(int index, int lim){\n\t\treturn (0 <= index && index < lim);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid solve() throws IOException{\n\t\tPoint bag = readPoint();\n\t\t\n\t\tint n = readInt();\n\t\t\n\t\tPoint[] points = new Point[n];\n\t\t\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tpoints[i] = readPoint();\n\t\t}\n\t\t\n\t\tint[] dist = new int[n];\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tint dx = points[i].x - bag.x;\n\t\t\tint dy = points[i].y - bag.y;\n\t\t\t\n\t\t\tdist[i] = dx * dx + dy * dy;\n\t\t}\n\t\t\n\t\tint[][] d = 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\tint dx = points[i].x - points[j].x;\n\t\t\t\tint dy = points[i].y - points[j].y;\n\t\t\t\t\n\t\t\t\td[i][j] = dx * dx + dy * dy;\n\t\t\t\td[i][j] += dist[i] + dist[j];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] singleMasks = new int[n];\n\t\tfor (int i = 0; i < n; ++i){\n\t\t\tsingleMasks[i] = (1 << i);\n\t\t}\n\t\t\n\t\tint[][] doubleMasks = 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\tdoubleMasks[i][j] = (singleMasks[i] | singleMasks[j]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint lim = (1 << n);\n\t\tint[] dp = new int[lim];\n\t\t\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\t\n\t\tint[] p = new int[lim];\n\t\tArrays.fill(p, -1);\n\t\t\n\t\tfor (int mask = 0; mask < lim; ++mask){\n\t\t\tif (dp[mask] == Integer.MAX_VALUE){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tint minBit = -1;\n\t\t\t\n\t\t\tfor (int bit = 0; bit < n; ++bit){\n\t\t\t\tif (checkBit(mask, bit)) continue;\n\t\t\t\t\n\t\t\t\tif (minBit == -1 || (dist[minBit] > dist[bit])){\n\t\t\t\t\tminBit = bit;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (minBit == -1){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int bit = 0; bit < n; ++bit){\n\t\t\t\tif (checkBit(mask, bit)) continue;\n\t\t\t\t\n\t\t\t\tint newMask = (mask | (1 << minBit) | (1 << bit));\n\t\t\t\t\n\t\t\t\tif (dp[newMask] > dp[mask] + d[minBit][bit]){\n\t\t\t\t\tdp[newMask] = dp[mask] + d[minBit][bit];\n\t\t\t\t\tp[newMask] = minBit * n + bit;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(dp[lim-1]);\n\t\t\n\t\tint curMask = lim - 1;\n\t\twhile (p[curMask] != -1){\n\t\t\tout.print(\"0 \");\n\t\t\t\n\t\t\tint first = p[curMask] / n;\n\t\t\tint second = p[curMask] % n;\n\t\t\t\n\t\t\tout.print((first + 1) + \" \");\n\t\t\tcurMask ^= (1 << first);\n\t\t\t\n\t\t\tif (first != second){\n\t\t\t\tout.print((second + 1) + \" \");\n\t\t\t\tcurMask ^= (1 << second);\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(\"0\");\n\t}\n\n\tprivate boolean checkBit(int mask, int bitNumber) {\n\t\treturn (mask & (1 << bitNumber)) != 0;\n\t}\n\t\n\tboolean checkMask(int mask, int innerMask){\n\t\treturn (mask & innerMask) == innerMask;\n\t}\n}\n\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Task2 {\n\n    public static void main(String[] args) throws IOException {\n\n        new Task2().solve();\n\n    }\n\n    //ArrayList<Integer>[] g;\n\n    int mod = 1000000007;\n\n    PrintWriter out;\n\n    int n;\n    int m;\n    //int[][] a = new int[1000][1000];\n\n\n    //int cnt = 0;\n\n    long base = (1L << 63);\n    long P = 31;\n\n    int[][] a;\n\n    void solve() throws IOException {\n\n        //Reader in = new Reader(\"in.txt\");\n        //out = new PrintWriter( new BufferedWriter(new FileWriter(\"output.txt\")) );\n        Reader in = new Reader();\n        PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );\n\n        //BufferedReader br = new BufferedReader( new FileReader(\"in.txt\") );\n        //BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );\n\n        int sx = in.nextInt();\n        int sy = in.nextInt();\n\n        int n = in.nextInt();\n\n        int[] x = new int[n];\n        int[] y = new int[n];\n\n        for (int i = 0; i < n; i++) {\n\n            x[i] = in.nextInt();\n            y[i] = in.nextInt();\n        }\n\n        int[] dp = new int[1 << n];\n        int[] p = new int[1 << n];\n\n        int inf = 1000000000;\n\n        Arrays.fill(dp, inf);\n        dp[0] = 0;\n\n        for (int mask = 0; mask < (1 << n) - 1; mask ++) {\n\n            int k = -1;\n\n            if (dp[mask] == inf)\n                continue;\n\n            for (int i = 0; i < n; i++) {\n\n                if ((mask & (1 << i)) == 0) {\n\n                    k = i;\n                    break;\n                }\n            }\n\n            for (int i = k; i < n; i++) {\n\n                if ((mask & (1 << i)) == 0) {\n\n                    int val = dp[mask] + dist(sx, sy, x[i], y[i]) + dist(sx, sy, x[k], y[k]) + dist(x[i], y[i], x[k], y[k]);\n\n                    if (val < dp[mask | (1 << i) | (1 << k)]) {\n\n                        dp[mask | (1 << i) | (1 << k)] = val;\n                        p[mask | (1 << i) | (1 << k)] = mask;\n                    }\n                }\n            }\n\n        }\n\n        out.println(dp[(1 << n) - 1]);\n\n        int cur = (1 << n) - 1;\n\n        out.print(0+\" \");\n\n        while (cur != 0) {\n\n            int prev = p[cur];\n\n            for (int i = 0; i < n; i++) {\n\n                if (((cur & (1 << i)) ^ (prev & (1 << i))) != 0)\n                    out.print(i+1+\" \");\n            }\n\n\n            out.print(0+\" \");\n\n            cur = prev;\n        }\n\n        out.flush();\n        out.close();\n    }\n\n    int dist(int x1, int y1, int x2, int y2) {\n\n        return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);\n    }\n\n    long gcd(long a, long b) {\n\n        if (b == 0)\n            return a;\n\n        return gcd(b, a%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    class Pair implements Comparable<Pair>{\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 (b < p.b)\n                return 1;\n\n            if (b > p.b)\n                return -1;\n\n            return 0;\n        }\n\n        //\t\t@Override\n        //\t\tpublic boolean equals(Object o) {\n        //\t\t\tPair p = (Pair) o;\n        //\t\t\treturn a == p.a && b == p.b;\n        //\t\t}\n        //\n        //\t\t@Override\n        //\t\tpublic int hashCode() {\n        //\t\t\treturn Integer.valueOf(a).hashCode() + Integer.valueOf(b).hashCode();\n        //\t\t}\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        String nextLine() throws IOException {\n            return br.readLine();\n        }\n\n    }\n\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\npublic class LookingOrder {\n    public static void main(String[] args) throws IOException{\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n        String[] line=in.readLine().split(\"\\\\s+\");\n        int xs= Integer.parseInt(line[0]);\n        int ys= Integer.parseInt(line[1]);\n        int n=Integer.parseInt(in.readLine());\n        int []x=new int[n];\n        int []y=new int[n];\n        for(int i=0;i<n;++i){\n            line=in.readLine().split(\"\\\\s+\");\n            x[i]= Integer.parseInt(line[0]);\n            y[i]= Integer.parseInt(line[1]);\n        }\n        int maxBitmap=1<<n;\n        long[] dis=new long[maxBitmap];\n        int[] last=new int[maxBitmap];\n        dis[0]=0;\n        int ci=0;\n        int[][] dismap=new int[n][n];\n        \n        for(int i=0;i<n;++i){\n            for(int j=0;j<=i;++j){\n                int delx,dely;\n                if(i==j){\n                    delx=x[i]-xs;\n                    dely=y[i]-ys;\n                }else{\n                    delx=x[i]-x[j];\n                    dely=y[i]-y[j];\n                }\n                dismap[i][j]=delx*delx+dely*dely;\n            }\n        }\n        \n        for(int i=1;i<maxBitmap;++i){\n            if((i&(1<<ci))==0)\n                ++ci;\n            int i2=i-(1<<ci);\n            \n            long min=dis[i2]+2*dismap[ci][ci];\n            last[i]=ci;\n            for(int j=0;j<ci;++j){\n                if((i&(1<<j))!=0){\n                    long m=dis[i2-(1<<j)]+dismap[ci][ci]+dismap[j][j]+dismap[ci][j];\n                    if(m<min){\n                        min=m;\n                        last[i]=j;\n                    }\n                }\n            }\n            dis[i]=min;\n        }\n        \n        out.write(\"\"+dis[maxBitmap-1]);\n        out.newLine();\n        out.write(\"0\");\n        \n        int bmap=maxBitmap-1;\n        ci=n-1; \n        while(bmap!=0){\n            while((bmap&(1<<ci))==0&&ci>=0)--ci;\n            int ci2=last[bmap];\n            if(ci2!=ci){\n                out.write(\" \"+(ci+1)+\" \"+(ci2+1)+ \" 0\");\n                bmap-=(1<<ci)+(1<<ci2);\n            }else{\n                out.write(\" \"+(ci+1)+\" 0\");\n                bmap-=1<<ci;\n            }\n        }\n        out.close();\n    }\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class Round8_C {\n\n\t/**\n\t * @param args\n\t */\n\t\n\tint n ;\n\tint[] X, Y ;\n\t\n\tpublic Round8_C() {\n\t\tinfo_in() ;\n\t\tprocess() ;\n\t}\n\t\n\tvoid info_in()\n\t{\n\t\tScanner input = new Scanner(System.in) ;\n\t\tint dx = input.nextInt() ;\n\t\tint dy = input.nextInt() ;\n\t\t\n\t\tn = input.nextInt() ;\n\t\tX = new int[n] ;\n\t\tY = new int[n] ;\n\t\t\n\t\tfor( int i=0;i<n;i++) {\n\t\t\tX[i] = input.nextInt() - dx ;\n\t\t\tY[i] = input.nextInt() - dy ;\n\t\t}\n\t}\n\t\n\tint[] d  ;\n\tint[] trace ;\n\t\n\tpublic static int distance( int x1, int y1, int x2, int y2 )\n\t{\n\t\treturn (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ;\n\t}\n\t\n\tvoid process()\n\t{\n\t\tint gh = 1<<n ;\n\t\td = new int[gh] ;\n\t\ttrace = new int[gh] ;\n\t\t\n\t\td[0] = 0 ;\n\t\tfor( int i=1;i<gh;i++) {\n\t\t\td[i] = Integer.MAX_VALUE ;\n\t\t\tfor( int j=0;j<n;j++)\n\t\t\t\tif ( (i & (1<<j)) > 0 ) {\n\t\t\t\t\tint val = d[i^(1<<j)] + ( distance( X[j], Y[j], 0, 0 ) << 1 ) ;\n\t\t\t\t\tif ( val < d[i] ) {\n\t\t\t\t\t\td[i] = val ;\n\t\t\t\t\t\ttrace[i] = j+1 ;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tint state = i ^ (1<<j) ;\n\t\t\t\t\tfor( int p=j+1;p<n;p++)\n\t\t\t\t\t\tif ( (i & (1<<p)) > 0) {\n\t\t\t\t\t\t\tval = d[state^(1<<p)] + distance( X[j], Y[j], 0, 0 ) + distance( X[j], Y[j], X[p], Y[p] ) + distance( X[p], Y[p], 0, 0 ) ;\n\t\t\t\t\t\t\tif ( val < d[i] ) {\n\t\t\t\t\t\t\t\td[i] = val ;\n\t\t\t\t\t\t\t\ttrace[i] = (j+1) * 100 + (p+1) ; \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\tbreak ;\n\t\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println( d[gh-1] ) ;\n\t\tgh-- ;\n\t\twhile ( gh > 0 ) {\n\t\t\tint v1 = trace[gh] / 100 - 1 ;\n\t\t\tint v2 = trace[gh] % 100 - 1 ;\n\t\t\tSystem.out.print(0 + \" \") ;\n\t\t\tif ( v1 != -1 ) {\n\t\t\t\tSystem.out.print((v1+1) + \" \" ) ;\n\t\t\t\tgh -= 1 << v1 ;\n\t\t\t}\n\t\t\tSystem.out.print( (v2+1) + \" \" ) ;\n\t\t\tgh -= 1 << v2 ;\n\t\t}\n\t\tSystem.out.println(0) ;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tnew Round8_C() ;\n\t}\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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 B {\n    final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    final PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    StringTokenizer tokenizer;\n    final int[][] d;\n    final int n;\n    final int[] time;\n    final Action[] actions;\n\n    private static final class Action {\n        int a;\n        int b;\n\n        public Action(int a) {\n            this.a = this.b = a;\n        }\n\n        public Action(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public String toString() {\n            if (a == b)\n                return \" \" + (a+1);\n            return \" \" + (a+1) + \" \" + (b+1);\n        }\n    }\n\n    private static final int dist(int x1, int y1, int x2, int y2) {\n        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n    }\n\n    private final boolean in(int x, int set) {\n        return ((1 << x) & set) != 0;\n    }\n\n    private final int off(int x, int set) {\n        return (set ^ (set & (1 << x)));\n    }\n\n    private final int solve(int set) {\n        if (time[set] > 0)\n            return time[set];\n        int min = Integer.MAX_VALUE;\n        if (set == 0)\n            min = 0;\n        else {\n            int a;\n            for (a = 0; a < n; a++)\n                if (in(a, set))\n                    break;\n            int subset = off(a, set);\n            int aux = 2 * d[a][a] + solve(subset);\n            if (aux < min) {\n                min = aux;\n                actions[set] = new Action(a);\n            }\n            for (int b = a + 1; b < n; b++)\n                if (in(b, subset)) {\n                    aux = d[a][a] + d[b][b] + d[a][b] + solve(off(b, subset));\n                    if (aux < min) {\n                        min = aux;\n                        actions[set] = new Action(a, b);\n                    }\n                }\n        }\n        time[set] = min;\n        return min;\n    }\n\n    private B() throws IOException {\n        int bx = nextInt();\n        int by = nextInt();\n        n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        reader.close();\n\n        d = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            d[i][i] = dist(bx, by, x[i], y[i]);// |A|\n            for (int j = i + 1; j < n; j++)\n                d[i][j] = dist(x[i], y[i], x[j], y[j]);// |AB|\n        }\n        int set = 1 << n;\n        time = new int[set];\n        actions = new Action[set];\n        set--;\n        printer.println(solve(set));\n        printer.print(\"0\");\n        while (set != 0) {\n            solve(set);\n            Action action = actions[set];\n            printer.print(action);\n            printer.print(\" 0\");\n            set = off(action.a, set);\n            set = off(action.b, set);\n        }\n\n        printer.println();\n        printer.close();\n    }\n\n    private final int nextInt() throws IOException {\n        return Integer.parseInt(nextToken());\n    }\n\n    private final String nextToken() throws IOException {\n        while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n            tokenizer = new StringTokenizer(reader.readLine());\n        }\n        return tokenizer.nextToken();\n    }\n\n    public static void main(String[] args) throws IOException {\n        new B();\n    }\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class c8 {\n    static int n;\n    static int[] ds;\n    static int[][] g;\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int x = input.nextInt(), y = input.nextInt();\n    int n = input.nextInt();\n    int[] xs = new int[n], ys = new int[n];\n    for(int i = 0; i<n; i++)\n    {\n        xs[i] = input.nextInt();\n        ys[i] = input.nextInt();\n    }\n    ds = new int[n];\n    g = new int[n][n];\n    for(int i = 0; i<n; i++)\n    {\n        ds[i] = (x - xs[i])  *  (x - xs[i]) + (y - ys[i]) * (y - ys[i]);\n        for(int j = 0; j<n; j++)\n        {\n            g[i][j] = (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);\n        }\n    }\n    int[] dp = new int[1<<n];\n    Arrays.fill(dp, 987654321);\n    dp[0] = 0;\n    for(int i = 0; i<(1<<n); i++)\n    {\n        if(dp[i] == 987654321) continue;\n        for(int a = 0; a<n; a++)\n        {\n            if((i & (1<<a)) > 0) continue;\n            dp[i | (1<<a)] = Math.min(dp[i | (1<<a)], dp[i] + 2*ds[a]);\n            for(int b = a+1; b<n; b++)\n            {\n                if((i & (1<<b)) > 0) continue;\n                dp[i | (1<<a) | (1<<b)] = Math.min(dp[i | (1<<a) | (1<<b)], dp[i] + ds[a] + ds[b] + g[a][b]);\n            }\n            break;\n        }\n    }\n    Stack<Integer> stk = new Stack<Integer>();\n    stk.add(0);\n    int i = (1<<n) - 1;\n    //System.out.println(Arrays.toString(dp));\n\n    trace:\n    while(i > 0)\n    {\n        //System.out.println(i);\n        for(int a = 0; a<n; a++)\n        {\n            if((i & (1<<a)) == 0) continue;\n            if( dp[i] == dp[i - (1<<a)] + 2*ds[a])\n            {\n                stk.add(a+1);\n                stk.add(0);\n                i -= (1<<a);\n                continue trace;\n            }\n            for(int b = a+1; b<n; b++)\n            {\n                if((i & (1<<b)) == 0) continue;\n                if(dp[i] == dp[i - (1<<a) - (1<<b)] + ds[a] + ds[b] + g[a][b])\n                {\n                    stk.add(a+1);\n                    stk.add(b+1);\n                    stk.add(0);\n                    i -= (1<<a) + (1<<b);\n                    continue trace;\n                }\n            }\n            //break;\n        }\n    }\n    System.out.println(dp[(1<<n) - 1]);\n    while(!stk.isEmpty()) System.out.print(stk.pop()+\" \");\n}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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 LookingForOrder {\nstatic int n;\nstatic int []x,y,memo;\nstatic StringBuilder sb;\nstatic int distance(int i,int j)\n{\n\tint dx=x[i]-x[j];\n\tint dy=y[i]-y[j];\n\treturn dx*dx+dy*dy;\n}\npublic static int dp(int msk)\n{\n\tif(msk==(1<<(n+1))-2)\n\t\treturn 0;\n\tif(memo[msk]!=-1)\n\t\treturn memo[msk];\n\tint ans=10000000;\n\tboolean found=false;\n\tfor(int i=1;i<=n && !found;i++)\n\t\t\n\t\tfor(int j=i;j<=n && (msk&1<<i)==0;j++)\n\t\t\tif((msk&1<<j)==0)\n\t\t\t{\t\n\t\t\t\t\n\t\t\t\tfound=true;\n\t\t\t\tint newM=msk|1<<i;\n\t\t\t\tnewM|=1<<j;\n\t\t\t\tans=Math.min(ans, dp(newM)+Math.min(distance(0,i)+distance(i,j)+distance(j,0), distance(0,j)+distance(j,i)+distance(i,0)));\n\t\t\t}\n\treturn memo[msk]=ans;\n\t\t\t\n}\npublic static void print(int msk)\n{\n\tif(msk==(1<<(n+1))-2)\n\t\treturn ;\n\t\n\tfor(int i=1;i<=n;i++)\n\t\t\n\t\tfor(int j=i;j<=n && (msk&1<<i)==0;j++)\n\t\t\tif((msk&1<<j)==0)\n\t\t\t{\t\n\t\t\t\t\n\t\t\t\tint newM=msk|1<<i;\n\t\t\t\tnewM|=1<<j;\n\t\t\t\tint d1=distance(0,i)+distance(i,j)+distance(j,0);\n\t\t\t\tint d2=distance(0,j)+distance(j,i)+distance(i,0);\n\t\t\t\tif(dp(msk)== dp(newM)+Math.min(d1,d2))\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tif(i==j)\n\t\t\t\t\t\n\t\t\t\t\t\tsb.append(\"0 \"+i+\" \");\n\t\t\t\t\t\n\t\t\t\t\telse if(d1<d2)\n\t\t\t\t\t\tsb.append(\"0 \"+i+\" \"+j+\" \");\n\t\t\t\t\telse\n\t\t\t\t\t\tsb.append(\"0 \"+j+\" \"+i+\" \");\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\tprint(newM);\n\t\t\t\t\treturn ;\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t\n}\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint xS=sc.nextInt(),yS=sc.nextInt();\n\t\tn=sc.nextInt();\n\t\tx=new int [n+1];\n\t\ty=new int [n+1];\n\t\tx[0]=xS;y[0]=yS;\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\t\n\t\t\tx[i]=sc.nextInt();\n\t\t\ty[i]=sc.nextInt();\n\t\t\n\t\t}\t\n\t\tmemo=new int [1<<(n+1)];\n\t\tArrays.fill(memo,-1);\n\t\tsb=new StringBuilder();\n\n\t\tsb.append(dp(0)+\"\\n\");\n\t\tprint(0);\n\t\tsb.append(\"0\");\n\t\tSystem.out.println(sb);\n\t}\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic Scanner(InputStream s)\n\t\t{\n\t\t\tbr=new BufferedReader(new InputStreamReader(s));\n\t\t}\n\t\tpublic String nextLine() throws IOException\n\t\t{\n\t\t\treturn br.readLine();\n\t\t}\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 int nextInt() throws IOException\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t\t\n\t\t}\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic boolean ready() throws IOException\n\t\t{\n\t\t\treturn br.ready();\n\t\t}\n\t\tpublic long nextLong() throws IOException\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        final int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        final int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        final int[] best = new int[1 << n];\n        final int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            best[set] = best[set ^ (1 << i)] + single[i];\n            prev[set] = 1 << i;\n            int nextSet = set ^ (1 << i);\n            int unoI = 1 << i;\n            for (int j = i + 1, unoJ = 1 << (i + 1); j < n; ++j, unoJ <<= 1)\n                if ((set & unoJ) != 0) {\n                    int cur = best[nextSet ^ unoJ] + pair[i][j];\n                    if (cur < best[set]) {\n                        best[set] = cur;\n                        prev[set] = unoI | unoJ;\n                    }\n                }\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n        \tint differents = prev[now];\n        \tfor(int i = 0; i < n; i++)\n\t\t\t\tif((differents & (1 << i)) != 0)\n\t\t\t\t{\n\t\t\t\t\t writer.print(\" \");\n\t\t             writer.print(i + 1);\n\t\t             now ^= 1 << i;\n\t\t\t\t}\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n    static int[][] dist;\n    static int[] dist1;\n    static int [] dp;\n    static int [] path;\n    static int end,x,y;\n    static Point[] a;\n    public static int doit(int mask) {\n        if(mask==end) return 0;\n        if(dp[mask]!=-1) return dp[mask];\n        int min=Integer.MAX_VALUE;\n        int t;\n        int i;\n        for(i=0;i<dist.length;i++) \n            if(((1<<i)|mask)!=mask) break;\n            t=2*dist1[i]+doit(mask|(1<<i));\n            if(t<min) {\n                min=t;\n                path[mask]=(1<<i);\n            }\n            \n            for(int j=i+1;j<dist.length;j++) {\n                if(((1<<j)|mask)==mask) continue;\n                t=dist[i][j]+doit(mask|(1<<i)|(1<<j));\n                if(t<min) {\n                    min=t;\n                    path[mask]=(1<<i)|(1<<j);\n                }\n            }\n        \n        return dp[mask]=min;\n    }\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n         x=sc.nextInt();y=sc.nextInt();\n         a=new Point[sc.nextInt()];\n        for(int i=0;i<a.length;i++) {\n            a[i]=new Point(sc.nextInt(), sc.nextInt());\n        }\n        end=(1<<a.length)-1;\n        dp=new int[1<<a.length];\n        Arrays.fill(dp, -1);\n        dist=new int[a.length][a.length];\n        dist1=new int[a.length];\n        for(int i=0;i<a.length;i++) {\n            dist1[i]=(a[i].x-x)*(a[i].x-x)+(a[i].y-y)*(a[i].y-y);\n            for(int j=i+1;j<a.length;j++) {\n                \n                dist[i][j]=dist1[i]+\n                (a[j].x-a[i].x)*(a[j].x-a[i].x)+(a[j].y-a[i].y)*(a[j].y-a[i].y)+\n                (a[j].x-x)*(a[j].x-x)+(a[j].y-y)*(a[j].y-y);\n                //System.out.println(dist[i][j]);\n            }\n        }\n        path=new int[dp.length];\n        System.out.println(doit(0));\n        int e=0;\n        int cur=path[e];\n        StringBuffer bf=new StringBuffer();\n        bf.append(0+\" \");\n        int count=0;\n        for(int i=0;count<a.length;i++) {\n            //System.out.println(Integer.toBinaryString(cur)+\" \"+cur);\n            for(int j=0;j<a.length;j++) {\n                if(((1<<j)|cur)==cur) {\n                    bf.append((j+1)+\" \"); count++;\n                }\n            }\n            e|=cur;\n            cur=path[e];\n            bf.append(0+\" \");\n        }\n        System.out.println(bf);\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n \n\npublic class Main {\n\t\t\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tBufferedReader kek = new BufferedReader(new InputStreamReader(System.in));\n\t\t//Scanner skek = new Scanner(System.in);\n\t\tPrintWriter outkek = new PrintWriter(System.out);\n\n\t\tString[] input = kek.readLine().split(\" \");\n\t\tint X0 = Integer.parseInt(input[0]), Y0 = Integer.parseInt(input[1]), N = Integer.parseInt(kek.readLine());\n\t\t\n\t\tint[] xCoords = new int[N + 1];\n\t\tint[] yCoords = new int[N + 1];\n\t\tint[][] distances = new int[N + 1][N + 1]; \n\t\txCoords[N] = X0;\n\t\tyCoords[N] = Y0;\n\t\t\n\t\tfor(int i = 0; i < N; i++){\n\t\t\tinput = kek.readLine().split(\" \");\n\t\t\txCoords[i] = Integer.parseInt(input[0]);\n\t\t\tyCoords[i] = Integer.parseInt(input[1]);\n\t\t}\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\tint temp = xCoords[i] - xCoords[j];\n\t\t\t\tint temp2 = yCoords[i] - yCoords[j];\n\t\t\t\tdistances[i][j] = (temp * temp) + (temp2 * temp2);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] aa = new int[1 << N];\n\t\tint[] bb = new int[1 << N];\n\t\t\n\t\tfor(int i = 1; i < 1 << N; i++){\n\t\t\tint a = -1;\n\t\t\tfor(int j = 0; j < N; j++){\n\t\t\t\tif((i & 1 << j) > 0){\n\t\t\t\t\ta = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint l = i ^ 1 << a;\n\t\t\tint dist = distances[a][N] + distances[a][N];\n\t\t\taa[i] = aa[l] + dist;\n\t\t\tbb[i] = l;\n\t\t\t\n\t\t\tfor(int k = a + 1; k < N; k++){\n\t\t\t\tif((i & 1 << k) > 0) {\n\t\t\t\t\tl = i ^ 1 << a ^ 1 << k;\n\t\t\t\t\tdist = distances[a][N] + distances[k][N] + distances[a][k];\n\t\t\t\t\tif(aa[l] + dist < aa[i]){\n\t\t\t\t\t\taa[i] = aa[l] + dist;\n\t\t\t\t\t\tbb[i] = l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint fin = (1 << N) - 1;\n\t\toutkek.println(aa[fin]);\n\t\toutkek.print('0');\n\t\twhile (fin != 0){\n\t\t\tint temp1 = bb[fin];\n\t\t\tint temp2 = fin ^ temp1;\n\t\t\tfor(int i = 0; i < N; i++){\n\t\t\t\tif((temp2 & 1 << i) > 0){\n\t\t\t\t\toutkek.print(\" \" + (i + 1));\n\t\t\t\t}\n\t\t\t}\n\t\t\toutkek.print(\" 0\");\n\t\t\tfin = temp1;\n\t\t}\n\t\tkek.close();\n\t\toutkek.close();\n\t}\t\n\t\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class CF008C {\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 n = s.nextInt();\n        int[] xx = new int[n+1];\n        int[] yy = new int[n+1];\n        for(int i = 0;i<n;i++){\n            xx[i] = s.nextInt();\n            yy[i] = s.nextInt();\n        }\n//        int[][] dp = new int[n][n];\n//        for(int i = 0;i<n;i++){\n//            Arrays.fill(dp[i],-1);\n//        }\n        xx[n] = x;\n        yy[n] = y;\n        int[][] dp = new int[n + 1][n + 1];\n        for (int i = 0; i <= n; i++)\n            for (int j = i + 1; j <= n; j++) {\n                int dx = xx[i] - xx[j];\n                int dy = yy[i] - yy[j];\n                dp[i][j] = dx * dx + dy * dy;\n            }\n            int[] aa = new int[1 << n];\n            int[] bb = new int[1 << n];\n            for (int k = 1; k < 1 << n; k++) {\n                int a = -1;\n                for (int b = 0; b < n; b++)\n                    if ((k & 1 << b) > 0) {\n                        a = b;\n                        break;\n                    }\n                int l = k ^ 1 << a;\n                int d = dp[a][n] + dp[a][n];\n                aa[k] = aa[l] + d;\n                bb[k] = l;\n                for (int b = a + 1; b < n; b++)\n                    if ((k & 1 << b) > 0) {\n                        l = k ^ 1 << a ^ 1 << b;\n                        d = dp[a][n] + dp[b][n] + dp[a][b];\n                        if (aa[l] + d < aa[k]) {\n                            aa[k] = aa[l] + d;\n                            bb[k] = l;\n                        }\n                    }\n            }\n            int k = (1 << n) - 1;\n            System.out.println(aa[k]);\n            StringBuilder sb = new StringBuilder();\n            sb.append(0);\n            while (k != 0) {\n                int l = bb[k];\n                int m = k ^ l;\n                for (int b = 0; b < n; b++)\n                    if ((m & 1 << b) > 0)\n                        sb.append(' ').append(b + 1);\n                sb.append(' ').append(0);\n                k = l;\n            }\n            System.out.println(sb);\n        }\n//        int[] distFromOrigin = new int[n];\n////        HashMap<Integer,Boolean> map = new HashMap<>();\n//        for(int i=0;i<n;i++){\n//            distFromOrigin[i] = (int) (Math.pow((xCoord[i] - x),2) + Math.pow(yCoord[i] - y,2));\n////            map.put(i,true);\n//        }\n//        System.out.println(0);\n//        long sum = 0;\n//        String str = \"0 \";\n//\n//        while(!map.isEmpty()){\n//            int first = 0;\n//            int second = Integer.MIN_VALUE;\n//            if(map.size() == 1){\n//                first = new ArrayList<Integer>(map.keySet()).get(0) + 1;\n//                int min = distFromOrigin[first - 1] + distFromOrigin[first - 1];\n//                sum += min;\n//                map.remove(first - 1);\n//            }else {\n//                int min = Integer.MAX_VALUE;\n//\n//                for (int i = 0; i < n; i++) {\n//                    for (int j = 0; j <= i; j++) {\n//                        if (map.containsKey(i) && map.containsKey(j) && distFromOrigin[i] + distFromOrigin[j] + dp[i][j] < min) {\n//                            min = distFromOrigin[i] + distFromOrigin[j] + dp[i][j];\n//                            first = i + 1;\n//                            if(i == j){\n//                                second = Integer.MIN_VALUE;\n//                            }else {\n//                                second = j + 1;\n//                            }\n//                        }\n//                    }\n//                }\n//                sum += min;\n//                map.remove(first - 1);\n//                if(second != Integer.MIN_VALUE){\n//                    map.remove(second - 1);\n//                }\n//            }\n//            if(second == Integer.MIN_VALUE){\n//                str = str + first + \" \";\n//            }else{\n//                if(map.size() == 0) {\n//                    str = str + first + \" \" + second + \" \";\n//                }else{\n//                    str = str + first + \" \" + second + \" 0 \";\n//                }\n//            }\n////            System.out.print(first + \" \" + second + \" \");\n//        }\n//        System.out.println(sum);\n//        System.out.println(str + \"0\");\n//        int[] ans = new int[(int)Math.pow(2,n)];\n//        Arrays.fill(ans,Integer.MAX_VALUE);\n//        for(int i = 0;i<Math.pow(2,n);i++){\n//            for(int j = 0;j<n;j++){\n//                //I can't figure out how to do that.\n//            }\n//        }\n//        System.out.print(sum);\n//        System.out.print(0);\n\n\n    private static int calculateDistanceBetweenIandJ(int[] xCoord, int[] yCoord, int i, int j) {\n        int length = (int) (Math.pow((xCoord[i] - xCoord[j]),2) + Math.pow(yCoord[i] - yCoord[j], 2));\n        return length;\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Collections;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskC solver = new TaskC();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskC {\n        int INF = 1000 * 1000 * 1000;\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int x0 = in.readInt();\n            int y0 = in.readInt();\n            int n = in.readInt();\n            int[] xs = new int[n + 1], ys = new int[n + 1];\n            xs[0] = x0;\n            ys[0] = y0;\n            for (int i = 1; i <= n; i++) {\n                xs[i] = in.readInt();\n                ys[i] = in.readInt();\n            }\n            int[] one = new int[n];\n            for (int i = 0; i < n; i++) one[i] = dist(0, i + 1, xs, ys) * 2;\n            int[][] two = new int[n][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    two[i][j] = dist(0, i + 1, xs, ys) + dist(0, j + 1, xs, ys) + dist(i + 1, j + 1, xs, ys);\n                }\n            }\n            int[] dp = new int[(1 << n)];\n            Arrays.fill(dp, INF);\n            dp[0] = 0;\n            int[] prev = new int[(1 << n)];\n            for (int mask = 0; mask < (1 << n); mask++) {\n                for (int i = 0; i < n; i++) {\n                    if (((mask >> i) & 1) != 0) continue;\n                    ;\n                    int nmask = mask | (1 << i);\n                    int cost = one[i] + dp[mask];\n                    if (cost < dp[nmask]) {\n                        dp[nmask] = cost;\n                        prev[nmask] = i;\n                    }\n                    for (int j = i + 1; j < n; j++) {\n                        if (((mask >> j) & 1) != 0) continue;\n                        int nnmask = nmask | (1 << j);\n                        cost = two[i][j] + dp[mask];\n                        if (cost < dp[nnmask]) {\n                            dp[nnmask] = cost;\n                            prev[nnmask] = n + i * n + j;\n                        }\n                    }\n                    break;\n                }\n            }\n            int mask = (1 << n) - 1;\n            out.printLine(dp[mask]);\n            ArrayList<Integer> res = new ArrayList<>();\n            res.add(0);\n            while (mask > 0) {\n                if (prev[mask] < n) {\n                    res.add(prev[mask] + 1);\n                    mask &= ~(1 << prev[mask]);\n                } else {\n                    int ii = (prev[mask] - n) / n;\n                    int jj = (prev[mask] - n) % n;\n                    int i = Math.max(ii, jj);\n                    int j = Math.min(ii, jj);\n                    res.add(i + 1);\n                    res.add(j + 1);\n                    mask &= ~(1 << i);\n                    mask &= ~(1 << j);\n                }\n                res.add(0);\n            }\n            Collections.reverse(res);\n            for (int val : res) out.print(val + \" \");\n            out.printLine();\n        }\n\n        int dist(int i, int j, int[] xs, int[] ys) {\n            return (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);\n        }\n    }\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public int readInt() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9') {\n                    throw new InputMismatchException();\n                }\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isSpaceChar(c));\n            return res * sgn;\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n        }\n    }\n    static class OutputWriter {\n        private final PrintWriter writer;\n\n        public OutputWriter(OutputStream outputStream) {\n            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n        }\n\n        public OutputWriter(Writer writer) {\n            this.writer = new PrintWriter(writer);\n        }\n\n        public void 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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport com.sun.swing.internal.plaf.basic.resources.basic;\n\npublic class Main {\n\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\n\tprivate void solution() throws IOException {\n\t\tint sx = in.nextInt();\n\t\tint sy = in.nextInt();\n\t\tint n = in.nextInt();\n\t\tint[] x = new int[n];\n\t\tint[] y = new int[n];\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}\n\t\tint[] dp = new int[1 << n];\n\t\tint[] prev = new int[1 << n];\n\t\tArrays.fill(dp, Integer.MAX_VALUE / 2);\n\t\tdp[0] = 0;\n\t\tprev[0] = -1;\n\t\tfor (int mask = 0; mask < (1 << n); ++mask) {\n\t\t\tif (dp[mask] != Integer.MAX_VALUE / 2) {\n\t\t\t\tfor (int next = 0; next < n; ++next) {\n\t\t\t\t\tif (((mask >> next) & 1) == 0) {\n\t\t\t\t\t\tint nmask = mask | (1 << next);\n\t\t\t\t\t\tint val = dp[mask] + 2 * getDist(sx, sy, x[next], y[next]);\n\t\t\t\t\t\tif (dp[nmask] > val) {\n\t\t\t\t\t\t\tdp[nmask] = val;\n\t\t\t\t\t\t\tprev[nmask] = mask;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int next2 = next + 1; next2 < n; ++next2) {\n\t\t\t\t\t\t\tif (((nmask >> next2) & 1) == 0) {\n\t\t\t\t\t\t\t\tint nnmask = nmask | (1 << next2);\n\t\t\t\t\t\t\t\tint nval = dp[mask] + getDist(sx, sy, x[next], y[next]) \n\t\t\t\t\t\t\t\t\t\t\t\t\t+ getDist(x[next], y[next], x[next2], y[next2])\n\t\t\t\t\t\t\t\t\t\t\t\t\t+ getDist(x[next2], y[next2], sx, sy);\n\t\t\t\t\t\t\t\tif (dp[nnmask] > nval) {\n\t\t\t\t\t\t\t\t\tdp[nnmask] = nval;\n\t\t\t\t\t\t\t\t\tprev[nnmask] = mask;\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\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tList<Integer> res = new ArrayList<Integer>();\n\t\tres.add(0);\n\t\tint mask = (1 << n) - 1;\n\t\twhile (mask > 0) {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (((prev[mask] >> i) & 1) == 0 && ((mask >> i) & 1) == 1) {\n\t\t\t\t\tres.add(i + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tres.add(0);\n\t\t\tmask = prev[mask];\n\t\t}\n\t\tCollections.reverse(res);\n\t\tout.println(dp[(1 << n) - 1]);\n\t\tfor (int i = 0; i < res.size(); ++i) {\n\t\t\tif (i != 0) {\n\t\t\t\tout.print(\" \");\n\t\t\t}\n\t\t\tout.print(res.get(i));\n\t\t}\n\t\tout.println();\n\t\tout.flush();\n\t}\n\n\tprivate int getDist(int x1, int y1, int x2, int y2) {\n\t\treturn (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n\t}\n\n\tprivate class Scanner {\n\n\t\tprivate StringTokenizer tokenizer;\n\t\tprivate BufferedReader reader;\n\n\t\tpublic Scanner(Reader in) {\n\t\t\treader = new BufferedReader(in);\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString tmp = reader.readLine();\n\t\t\t\tif (tmp == null)\n\t\t\t\t\treturn false;\n\t\t\t\ttokenizer = new StringTokenizer(tmp);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().solution();\n\t}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound8_C implements Runnable {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok;\n\n    @Override\n    public void run() {\n        try {\n            long startTime = System.currentTimeMillis();\n            if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n                in = new BufferedReader(new InputStreamReader(System.in));\n                out = new PrintWriter(System.out);\n            } else {\n                in = new BufferedReader(new FileReader(\"input.txt\"));\n                out = new PrintWriter(\"output.txt\");\n            }\n            tok = new StringTokenizer(\"\");\n            Locale.setDefault(Locale.US);\n            solve();\n            in.close();\n            out.close();\n            long endTime = System.currentTimeMillis();\n            long totalMemory = Runtime.getRuntime().totalMemory();\n            long freeMemory = Runtime.getRuntime().freeMemory();\n            System.err.println(\"Time = \" + (endTime - startTime) + \" ms\");\n            System.err.println(\"Memory = \" + ((totalMemory - freeMemory) / 1024) + \" KB\");\n        } catch (Throwable e) {\n            e.printStackTrace(System.err);\n            System.exit(-1);\n        }\n    }\n\n    String readString() 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(Arrays.deepToString(o));\n    }\n\n    public static void main(String[] args) {\n        new Thread(null, new BetaRound8_C(), \"\", 256 * 1024 * 1024).start();\n    }\n\n    // ------------------------------------------------------------------------------\n\n    final int INF = 1000 * 1000 * 1000;\n\n    int x0, y0;\n    int n;\n    int[] x, y;\n\n    int t(int i, int j) {\n        int dx = x[i] - x[j];\n        int dy = y[i] - y[j];\n        return dx * dx + dy * dy;\n    }\n\n    int t0(int i) {\n        int dx = x[i] - x0;\n        int dy = y[i] - y0;\n        return dx * dx + dy * dy;\n    }\n\n    int[] dp;\n    int[] p;\n\n    void solve() throws IOException {\n        x0 = readInt();\n        y0 = readInt();\n        n = readInt();\n        x = new int[n];\n        y = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = readInt();\n            y[i] = readInt();\n        }\n        dp = new int[1 << n];\n        p = new int[1 << n];\n        Arrays.fill(dp, INF);\n        dp[(1 << n) - 1] = 0;\n        get(0);\n        out.println(dp[0]);\n        printPath();\n    }\n\n    int get(int mask) {\n        if (dp[mask] != INF) {\n            return dp[mask];\n        }\n        int res = INF;\n        for (int i = 0; i < n; i++) {\n            if (((1 << i) & mask) == 0) { // \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435\u0432\u0430\u0436\u0435\u043d, \u0442.\u043a. \u0432 i \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0438\u0434\u0442\u0438, \u043f\u043e\u0439\u0434\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u0440\u0430\u0437\u0443\n                int test = get(mask ^ (1 << i)) + 2 * t0(i);\n                if (res > test) {\n                    res = test;\n                    p[mask] = mask ^ (1 << i);\n                }\n                for (int j = i + 1; j < n; j++) {\n                    if (((1 << j) & mask) == 0) {\n                        test = get(mask ^ (1 << i) ^ (1 << j)) + t0(i)\n                                + t(i, j) + t0(j);\n                        if (res > test) {\n                            res = test;\n                            p[mask] = mask ^ (1 << i) ^ (1 << j);\n                        }\n                    }\n                }\n                break;\n            }\n        }\n        return dp[mask] = res;\n    }\n\n    void printPath() {\n        ArrayList<Integer> ans = new ArrayList<Integer>();\n        ans.add(0);\n        int mask = 0;\n        while (mask != (1 << n) - 1) {\n            for (int i = 0; i < n; i++) {\n                if (((mask ^ p[mask]) & (1 << i)) != 0) {\n                    ans.add(i + 1);\n                }\n            }\n            mask = p[mask];\n            ans.add(0);\n        }\n        for (int x : ans) {\n            out.print(x + \" \");\n        }\n    }\n\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tprivate void run() throws IOException {\n\t\tint cx = in.nextInt();\n\t\tint cy = in.nextInt();\n\t\tint n = in.nextInt();\n\t\tint[] x = new int[n];\n\t\tint[] y = new int[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tx[i] = in.nextInt() - cx;\n\t\t\ty[i] = in.nextInt() - cy;\n\t\t}\n\t\tint[] dp = new int[1 << n];\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\tint[] prev = new int[1 << n];\n\t\tfor (int mask = 0; mask < (1 << n); ++mask) {\n\t\t\tif (dp[mask] == Integer.MAX_VALUE) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (((mask >> i) & 1) == 0) {\n\t\t\t\t\tif (dp[mask | (1 << i)] > dp[mask] + dist(x[i], y[i])) {\n\t\t\t\t\t\tdp[mask | (1 << i)] = dp[mask] + dist(x[i], y[i]);\n\t\t\t\t\t\tprev[mask | (1 << i)] = mask;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int j = i + 1; j < n; ++j) {\n\t\t\t\t\t\tif (((mask >> j) & 1) == 0) {\n\t\t\t\t\t\t\tif (dp[mask | (1 << i) | (1 << j)] > dp[mask] + dist(x[i], y[i], x[j], y[j])) {\n\t\t\t\t\t\t\t\tdp[mask | (1 << i) | (1 << j)] = dp[mask] + dist(x[i], y[i], x[j], y[j]);\n\t\t\t\t\t\t\t\tprev[mask | (1 << i) | (1 << j)] = mask;\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\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(dp[(1 << n) - 1]);\n\t\tint mask = (1 << n) - 1;\n\t\tout.print(0);\n\t\twhile (mask != 0) {\n\t\t\tint p = prev[mask];\n\t\t\tint cur = p ^ mask;\n\t\t\tList<Integer> who = new ArrayList<Integer>();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (((cur >> i) & 1) != 0) {\n\t\t\t\t\twho.add(i + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int t : who) {\n\t\t\t\tout.print(\" \" + t);\n\t\t\t}\n\t\t\tout.print(\" \" + 0);\n\t\t\tmask = p;\n\t\t}\n\t\tout.flush();\n\t}\n\n\tprivate int dist(int x, int y, int x2, int y2) {\n\t\treturn x * x + y * y + x2 * x2 + y2 * y2 + (x2 - x) * (x2 - x) + (y2 - y) * (y2 - y);\n\t}\n\n\tprivate int dist(int x, int y) {\n\t\treturn 2 * (x * x + y * y);\n\t}\n\n\tprivate class Scanner {\n\t\tprivate StringTokenizer tokenizer;\n\t\tprivate BufferedReader reader;\n\n\t\tpublic Scanner(Reader in) {\n\t\t\treader = new BufferedReader(in);\n\t\t\ttokenizer = new StringTokenizer(\"\");\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 hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null)\n\t\t\t\t\treturn false;\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().run();\n\t}\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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\npublic class MainC {\n\n    private FastScanner in;\n    private PrintWriter out;\n\n    private int N;\n    private Dist[] dists;\n    private int countDists;\n    private int[][] minLeft;// startsFrom, count\n\n    private int[] minOrder;\n    private int minOrderCount = 10000000;\n\n    public void solve() throws IOException {\n        int xb = in.nextInt();\n        int yb = in.nextInt();\n        N = in.nextInt();\n        int[] x, y;\n        boolean isOdd;\n        if (N % 2 == 0) {\n            x = new int[N];\n            y = new int[N];\n            isOdd = false;\n        }\n        else {\n            x = new int[N + 1];\n            y = new int[N + 1];\n            isOdd = true;\n        }\n        for (int i = 0; i < N; i++) {\n            x[i] = in.nextInt() - xb;\n            y[i] = in.nextInt() - yb;\n        }\n        if (N % 2 == 1) {\n            N++;\n            x[N - 1] = 0;\n            y[N - 1] = 0;\n        }\n\n        countDists = N * (N - 1) / 2;\n        dists = new Dist[countDists];\n        int c = 0;\n        int commonSum = 0;\n        for (int i = 0; i < N; i++) {\n            for (int j = i + 1; j < N; j++) {\n                dists[c] = new Dist();\n                dists[c].from = i;\n                dists[c].to = j;\n                dists[c].dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j])\n                                * (y[i] - y[j]);\n                dists[c].dist = Math.min(dists[c].dist, x[i] * x[i] + y[i]\n                                * y[i] + x[j] * x[j] + y[j] * y[j]);\n                c++;\n            }\n            commonSum += x[i] * x[i] + y[i] * y[i];\n        }\n\n        Arrays.sort(dists);\n\n        minLeft = new int[countDists][N + 1];\n        for (int i = 0; i < countDists; i++) {\n            int sum = 0;\n            for (int j = 1; j <= N; j++) {\n                if (i + j - 1 < countDists) {\n                    sum = sum + dists[i + j - 1].dist;\n                    minLeft[i][j] = sum;\n                }\n                else {\n                    minLeft[i][j] = 100000000;\n                }\n            }\n        }\n\n        order(0, new int[N], 0, 0);\n\n        out.println(minOrderCount + commonSum);\n        for (int i = 1; i <= N / 2; i++) {\n            int first = -1;\n            int second = -1;\n            for (int j = 0; j < N; j++) {\n                if (minOrder[j] == i) {\n                    if (first == -1) {\n                        first = j;\n                    }\n                    else {\n                        second = j;\n                    }\n                }\n            }\n\n            if (isOdd && (first == N - 1 || second == N - 1)) {\n                first++;\n                second++;\n                out.print(\"0 \" + (first + second - N) + \" \");\n            }\n            else if (x[first] * x[first] + y[first] * y[first] + x[second]\n                            * x[second] + y[second] * y[second] < (x[first] - x[second])\n                            * (x[first] - x[second])\n                            + (y[first] - y[second])\n                            * (y[first] - y[second])) {\n                first++;\n                second++;\n                out.print(\"0 \" + first + \" 0 \" + second + \" \");\n            }\n            else {\n                first++;\n                second++;\n                out.print(\"0 \" + first + \" \" + second + \" \");\n            }\n        }\n\n        out.println(\"0\");\n    }\n\n    private void order(int countOrdered, int[] order, int startsFrom, int sum) {\n        if (countOrdered == N) {\n            if (sum < minOrderCount) {\n                minOrder = Arrays.copyOf(order, N);\n                minOrderCount = sum;\n            }\n            return;\n        }\n\n        while (startsFrom < countDists) {\n            if (order[dists[startsFrom].from] == 0\n                            && order[dists[startsFrom].to] == 0) {\n                if (minLeft[startsFrom][(N - countOrdered) / 2] + sum >= minOrderCount) {\n                    break;\n                }\n                order[dists[startsFrom].from] = countOrdered / 2 + 1;\n                order[dists[startsFrom].to] = countOrdered / 2 + 1;\n                order(countOrdered + 2, order, startsFrom + 1, sum\n                                + dists[startsFrom].dist);\n                order[dists[startsFrom].from] = 0;\n                order[dists[startsFrom].to] = 0;\n            }\n            startsFrom++;\n        }\n    }\n\n    private class Dist implements Comparable<Dist> {\n\n        int from;\n        int to;\n        int dist;\n\n        @Override\n        public int compareTo(Dist o) {\n            if (dist < o.dist) {\n                return -1;\n            }\n            if (dist == o.dist) {\n                return 0;\n            }\n            return 1;\n        }\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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\t//long t = System.currentTimeMillis();\n\t\tnew C().run();\n\t\t//System.out.println(System.currentTimeMillis() - t);\n\t}\n\n\tprivate void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint sx = sc.nextInt();\n\t\tint sy = sc.nextInt();\n\t\tint n = sc.nextInt();\n\t\tint[] x = new int[n];\n\t\tint[] y = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx[i] = sc.nextInt();\n\t\t\ty[i] = sc.nextInt(); \n\t\t}\n\t\tsc.close();\n\t\tint[] w = new int[n * n];\n\t\tint[] pMask = new int[n * n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = i; j < n; j++) {\n\t\t\t\tint ind = i * n + j;\n\t\t\t\tif (i == j) {\n\t\t\t\t\tw[ind] = 2 * dist(sx, sy, x[i], y[i]);\n\t\t\t\t\tpMask[ind] = 1 << i;\n\t\t\t\t} else {\n\t\t\t\t\tw[ind] = dist(sx, sy, x[i], y[i]) + dist(x[i], y[i], x[j], y[j]) + dist(x[j], y[j], sx, sy);\n\t\t\t\t\tpMask[ind] = 1 << i | 1 << j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint max = 1 << n;\n\t\tint[] p = new int[max];\n\t\tint[] dist = new int[max];\n\t\tArrays.fill(dist, Integer.MAX_VALUE / 2);\n\t\tdist[0] = 0;\n\t\tint[] available = new int[n * n];\n\t\tfor (int mask = 0; mask < max; mask++) {\n\t\t\tint ac = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (((mask >> i) & 1) == 0) {\n\t\t\t\t\tavailable[ac++] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint s = 0;\n\t\t\t//for (int i = 0; i < ac; i++) {\n\t\t\t\tfor (int j = s; j < ac; j++) {\n\t\t\t\t\tint a = available[s];\n\t\t\t\t\tint b = available[j];\n\t\t\t\t\tint ind = a * n + b;\n\t\t\t\t\tint nextMask = mask | pMask[ind];\n\t\t\t\t\tint newD = dist[mask] + w[ind];\n\t\t\t\t\tif (newD < dist[nextMask]) {\n\t\t\t\t\t\tdist[nextMask] = newD;\n\t\t\t\t\t\t//p[nextMask] = a * n + b;\n\t\t\t\t\t\tp[nextMask] = ind;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t//}\n\t\t}\n\t\tSystem.out.println(dist[max - 1]);\n\t\tArrayList<Integer> steps = new ArrayList<Integer>();\n\t\tint mask = max - 1;\n\t\twhile (mask > 0) {\n\t\t\tint msk = p[mask];\n\t\t\tsteps.add(msk);\n\t\t\tint a = msk / n;\n\t\t\tint b = msk % n;\n\t\t\tif (a == b) {\n\t\t\t\tmask ^= 1 << a;\n\t\t\t} else {\n\t\t\t\tmask ^= 1 << a;\n\t\t\t\tmask ^= 1 << b;\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(0);\n\t\tfor (int i = steps.size() - 1; i >= 0; i--) {\n\t\t\tint msk = steps.get(i);\n\t\t\tint a = msk / n;\n\t\t\tint b = msk % n;\n\t\t\tif (a == b) {\n\t\t\t\tSystem.out.printf(\" %d 0\", a + 1);\n\t\t\t} else {\n\t\t\t\tSystem.out.printf(\" %d %d 0\", a + 1, b + 1);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tprivate int dist(int x1, int y1, int x2, int y2) {\n\t\treturn (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);\n\t}\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class c8 {\n    static int n;\n    static int[] ds;\n    static int[][] g;\npublic static void main(String[] args)\n{\n    Scanner input = new Scanner(System.in);\n    int x = input.nextInt(), y = input.nextInt();\n    n = input.nextInt();\n    int[] xs = new int[n], ys = new int[n];\n    for(int i = 0; i<n; i++)\n    {\n        xs[i] = input.nextInt();\n        ys[i] = input.nextInt();\n    }\n    ds = new int[n];\n    g = new int[n][n];\n    for(int i = 0; i<n; i++)\n    {\n        ds[i] = (x - xs[i])  *  (x - xs[i]) + (y - ys[i]) * (y - ys[i]);\n        for(int j = 0; j<n; j++)\n        {\n            g[i][j] = (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);\n        }\n    }\n    int[] dp = new int[1<<n];\n    Arrays.fill(dp, 987654321);\n    dp[0] = 0;\n    for(int i = 0; i<(1<<n); i++)\n    {\n        if(dp[i] == 987654321) continue;\n        for(int a = 0; a<n; a++)\n        {\n            if((i & (1<<a)) > 0) continue;\n            dp[i | (1<<a)] = Math.min(dp[i | (1<<a)], dp[i] + 2*ds[a]);\n            for(int b = a+1; b<n; b++)\n            {\n                if((i & (1<<b)) > 0) continue;\n                dp[i | (1<<a) | (1<<b)] = Math.min(dp[i | (1<<a) | (1<<b)], dp[i] + ds[a] + ds[b] + g[a][b]);\n            }\n            break;\n        }\n    }\n    Stack<Integer> stk = new Stack<Integer>();\n    stk.add(0);\n    int i = (1<<n) - 1;\n    //System.out.println(Arrays.toString(dp));\n\n    trace:\n    while(i > 0)\n    {\n        //System.out.println(i);\n        for(int a = 0; a<n; a++)\n        {\n            if((i & (1<<a)) == 0) continue;\n            if( dp[i] == dp[i - (1<<a)] + 2*ds[a])\n            {\n                stk.add(a+1);\n                stk.add(0);\n                i -= (1<<a);\n                continue trace;\n            }\n            for(int b = a+1; b<n; b++)\n            {\n                if((i & (1<<b)) == 0) continue;\n                if(dp[i] == dp[i - (1<<a) - (1<<b)] + ds[a] + ds[b] + g[a][b])\n                {\n                    stk.add(a+1);\n                    stk.add(b+1);\n                    stk.add(0);\n                    i -= (1<<a) + (1<<b);\n                    continue trace;\n                }\n            }\n            //break;\n        }\n    }\n    System.out.println(dp[(1<<n) - 1]);\n    while(!stk.isEmpty()) System.out.print(stk.pop()+\" \");\n}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class C0008 {\n\n    public static void main(String args[]) throws Exception {\n        new C0008();\n    }\n\n    int n;\n    int target;\n    int pow[];\n    int dp[];\n    int next[];\n    int dist[][];\n\n    C0008() throws Exception {\n        PandaScanner sc = null;\n        PrintWriter out = null;\n        try {\n            sc = new PandaScanner(System.in);\n            out = new PrintWriter(System.out);\n        } catch (Exception ignored) {\n        }\n\n        pow = new int[26];\n        for (int i = 0; i < 26; i++) {\n            pow[i] = 1 << i;\n        }\n\n        dist = new int[26][26];\n        int[][] p = new int[26][];\n        p[25] = new int[] {sc.nextInt(), sc.nextInt()};\n        n = sc.nextInt();\n        target = (1 << n) - 1;\n\n        for (int i = 0; i < n; i++) {\n            p[i] = new int[] {sc.nextInt(), sc.nextInt()};\n            dist[i][25] = getDist(p[i], p[25]);\n            for (int j = 0; j < i; j++) {\n                dist[j][i] = getDist(p[j], p[i]);\n            }\n        }\n\n        next = new int[1 << n];\n\n        dp = new int[1 << n];\n        Arrays.fill(dp, -1);\n\n        out.println(go(0));\n\n        ArrayList<Integer> paths = new ArrayList<Integer>();\n        paths.add(0);\n        int curr = 0;\n        while (curr != target) {\n            for (Integer i: getBits(next[curr], true)) {\n                paths.add(i + 1);\n            }\n            paths.add(0);\n            curr |= next[curr];\n        }\n        out.println(paths.toString().replaceAll(\"[^ 0-9]\", \"\"));\n\n        out.close();\n        System.exit(0);\n    }\n\n    int go(int mask) {\n        if (mask == target) {\n            return 0;\n        }\n        if (dp[mask] != -1) {\n            return dp[mask];\n        }\n\n        ArrayList<Integer> notDone = getBits(mask, false);\n\n        dp[mask] = Integer.MAX_VALUE;\n\n        for (Integer i: notDone) {\n            int oneD = (dist[i][25] << 1) + go(mask | pow[i]);\n            if (dp[mask] > oneD) {\n                dp[mask] = oneD;\n                next[mask] = 1 << i;\n            }\n            for (Integer j: notDone) {\n                if (j == i) continue;\n                int d = (dist[j][25] + dist[i][j] + dist[i][25]) + go(mask | pow[i] | pow[j]);\n                if (dp[mask] > d) {\n                    dp[mask] = d;\n                    next[mask] = (1 << i) | (1 << j);\n                }\n            }\n            break;\n        }\n\n        return dp[mask];\n    }\n\n    int getDist(int[] p1, int[] p2) {\n        return sq(p1[0] - p2[0]) + sq(p1[1] - p2[1]);\n    }\n\n    int sq(int a) {\n        return a * a;\n    }\n\n    ArrayList<Integer> getBits(int mask, boolean on) {\n        ArrayList<Integer> res = new ArrayList<Integer>();\n        for (int i = 0; i < n; i++) {\n            if (((mask & (1 << i)) == 0) ^ on) {\n                res.add(i);\n            }\n        }\n        return res;\n    }\n\n    //The PandaScanner class, for Panda fast scanning!\n    public class PandaScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        InputStream in;\n\n        PandaScanner(InputStream in) throws Exception {\n            br = new BufferedReader(new InputStreamReader(this.in = in));\n        }\n\n        public String next() throws Exception {\n            if (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(br.readLine().trim());\n                return next();\n            }\n            return st.nextToken();\n        }\n\n        public boolean hasNext() throws Exception {\n            return (st != null && st.hasMoreTokens()) || in.available() > 0;\n        }\n\n        public long nextLong() throws Exception {\n            return Long.parseLong(next());\n        }\n\n        public int nextInt() throws Exception {\n            return Integer.parseInt(next());\n        }\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable\n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tnew Thread(null, new Main(), \"\", 1 << 20).start();\n\t}\n\t\n\tString file = \"input\";\n\tBufferedReader input;\n\tPrintWriter out;\n\t\n\tpublic void run() \n\t{\n\t\ttry\n\t\t{\n\t\t\t//input = new BufferedReader(new FileReader(file + \".in\"));\n\t\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\tsolve();\n\t\t\tinput.close();\n\t\t\tout.close();\n\t\t}\n\t\tcatch(Exception e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\tint[] x = new int[25];\n\tint[] y = new int[25];\n\tint[][] dist = new int[25][25];\n\tint[] single = new int[25];\n\tint[] c = new int[25];\n\tint INF = 1 << 30;\n\tvoid solve() throws IOException\n\t{\n\t\tStringTokenizer st = tokens();\n\t\tx[0] = nextInt(st);\n\t\ty[0] = nextInt(st);\n\t\tint n = nextInt();\n\t\tfor(int i = 1; i <= n; i++)\n\t\t{\n\t\t\tst = tokens();\n\t\t\tx[i] = nextInt(st);\n\t\t\ty[i] = nextInt(st);\n\t\t}\n\t\tfor(int i = 1; i <= n; i++)\n\t\t\tsingle[i] = 2 * ((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0])); \n\t\tfor(int i = 1; i <= n; i++)\n\t\t\tfor(int j = 1; j <= n; j++)\n\t\t\t\tdist[i][j] = single[i] / 2 + single[j] / 2 + (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n\t\tint[] dp = new int[1 << n];\n\t\tint[] prev = new int[1 << n];\n\t\tfill(dp, INF);\n\t\tdp[0] = 0;\n\t\tfor(int i = 1; i < 1 << n; i++)\n\t\t{\n\t\t\tfor(int j = 0; j < n; j++)\n\t\t\t{\n\t\t\t\tif((i >> j & 1) != 0)\n\t\t\t\t{\n\t\t\t\t\tif(dp[i] > dp[i ^ (1 << j)] + single[j + 1])\n\t\t\t\t\t{\n\t\t\t\t\t\tdp[i] = dp[i ^ (1 << j)] + single[j + 1];\n\t\t\t\t\t\tprev[i] = j + 1;\n\t\t\t\t\t}\n\t\t\t\n\t\t\t\t\tfor(int k = j + 1; k < n; k++)\n\t\t\t\t\t\tif((i >> k & 1) != 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(dp[i] > dp[i ^ (1 << j) ^ (1 << k)] + dist[j + 1][k + 1])\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdp[i] = dp[i ^ (1 << j) ^ (1 << k)] + dist[j + 1][k + 1];\n\t\t\t\t\t\t\t\tprev[i] = (j + 1) * 100 + (k + 1);\n\t\t\t\t\t\t\t}\n\t\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\tout.println(dp[(1 << n) - 1]);\n\t\tout.print(\"0 \");\n\t\tint mask = (1 << n) - 1;\n\t\twhile(mask > 0)\n\t\t{\n\t\t\tint s = prev[mask];\n\t\t\tint x = s / 100;\n\t\t\tint y = s % 100;\n\t\t\tif(x == 0)\n\t\t\t{\n\t\t\t\tout.print(y + \" \" + 0 + \" \");\n\t\t\t\tmask -= 1 << (y - 1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tout.print(x + \" \" + y + \" \" + 0 + \" \");\n\t\t\t\tmask -= 1 << (y - 1);\n\t\t\t\tmask -= 1 << (x - 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tStringTokenizer tokens() throws IOException\n\t{\n\t\treturn new StringTokenizer(input.readLine());\n\t}\n\t\n\tString next(StringTokenizer st)\n\t{\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(input.readLine());\n\t}\n\t\n\tint nextInt(StringTokenizer st)\n\t{\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(input.readLine());\n\t}\n\t\n\tdouble nextDouble(StringTokenizer st)\n\t{\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\t\n\tvoid print(Object... o)\n\t{\n\t\tout.println(deepToString(o));\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class LookingForOrder\n{\n\tpublic Scanner in = new Scanner(System.in);\n\tpublic PrintStream out = System.out;\n\n\tpublic int[] go;\n\tpublic int[][] cost;\n\t\n\tpublic int [] sol;\n\tpublic Pair[] how;\n\tpublic int n, lim;\n\t\n\tpublic Pair bag;\n\tpublic Pair[] obj;\n\t\n\tpublic void main()\n\t{\t\t\n\t\tbag = new Pair(in.nextInt(), in.nextInt());\n\t\t\n\t\tn = in.nextInt();\n\t\tobj = new Pair[n];\n\t\tfor(int i=0;i<n;++i) obj[i] = new Pair(in.nextInt(), in.nextInt());\n\t\t\n\t\tgo = new int[n];\n\t\tcost = new int[n][n];\n\t\tfor(int i=0;i<n;++i)\n\t\t{\n\t\t\tgo[i] = squDist(bag, obj[i]);\n\t\t\tfor(int j=0;j<n;++j) cost[i][j] = squDist(obj[i], obj[j]);\n\t\t}\n\t\t\n\t\tlim = (1<<n);\n\t\t\n\t\tsol = new int[lim];\n\t\tArrays.fill(sol, -1);\n\t\thow = new Pair[lim];\n\t\t\n\t\tout.println(solve(lim-1));\n\t\t\n\t\tPair T;\n\t\tint set = lim-1;\n\t\t\n\t\tout.print(\"0\");\n\t\twhile(set > 0)\n\t\t{\n\t\t\tsolve(set);\n\t\t\tT = how[set];\n\t\t\tout.print(\" \"+(T.x+1));\n\t\t\tset = off(T.x, set);\n\t\t\tif(T.y >= 0) \n\t\t\t{\n\t\t\t\tout.print(\" \" + (T.y+1));\n\t\t\t\tset = off(T.y, set);\n\t\t\t}\n\t\t\tout.print(\" 0\");\n\t\t}\n\t\tout.println();\n\t}//end public void main()\n\n\tpublic int oo = 987654321;\n\t\n\tpublic boolean in(int x, int set) { return ((1<<x) & set) != 0; }\n\t//Turn on bit x\n\tpublic int on(int x, int set) { return (set | (1<<x)); }\n\t//Turn off bit x\n\tpublic int off(int x, int set) { return (set ^ (set & (1<<x)) ); }\n    \n\t\n\tpublic int solve(int set)\n\t{\n\t\tif(sol[set] >= 0) return sol[set];\n\t\t\n\t\tint ret;\n\t\tif(set == 0) ret = 0;\n\t\telse\n\t\t{\n\t\t\tret = oo;\n\t\t\t\n\t\t\tint x, y, sub, c;\n\t\t\tfor(x=0;x<n;++x) if(in(x, set)) break;\n\t\t\t\n\t\t\tsub = off(x, set);\n\t\t\tc =  go[x]+go[x]+solve(sub);\n\t\t\t\n\t\t\tif(c < ret)\n\t\t\t{\n\t\t\t\thow[set] = new Pair(x, -1);\n\t\t\t\tret = c;\n\t\t\t}\n\t\t\t\n\t\t\tfor(y=x+1;y<n;++y) if(in(y, set))\n\t\t\t{\n\t\t\t\tc = go[x]+cost[x][y]+go[y] + solve(off(y, sub));\n\t\t\t\tif(c < ret)\n\t\t\t\t{\n\t\t\t\t\tret = c;\n\t\t\t\t\thow[set] = new Pair(x, y);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn sol[set] = ret;\n\t}\n\t\n\tpublic int squDist(int ax, int ay, int bx, int by)\n\t{\n\t\tint dx, dy;\n\t\tdx = ax - bx; \n\t\tdy = ay - by;\n\t\treturn dx*dx + dy*dy;\n\t}\n\t\n\tpublic int squDist(Pair p, Pair q)\n\t{\n\t\treturn squDist(p.x, p.y, q.x, q.y);\n\t}\n\t\n\t//int pair\n\tprivate class Pair implements Comparable<Pair>\n\t{\n\t\tpublic int x, y;\n\t\tpublic Pair(int xx, int yy) { x = xx; y = yy; }\n\n\t\tpublic int compareTo(Pair u)\n\t\t{\n\t\t\tif(x!=u.x) return x-u.x;\n\t\t\treturn y-u.y;\n\t\t}\n\n\t\tpublic String toString() { return \"(\" + x + \",\" + y + \")\"; }\n\t}\t\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\t(new LookingForOrder()).main();\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class LookingForOrder {\n\tstatic int[][] pos;\n\tstatic int[] dp;\n\tstatic int[] nextstate;\n\tstatic int[][] dist;\n\tstatic int r;\n\tstatic int v;\n\n\tstatic void print(int mask) {\n\t\tif (mask < v) {\n\t\t\tint c = 0;\n\t\t\tint x = mask ^ nextstate[mask];\n\t\t\tfor (int i = 0; i < dist.length - 1; i++) {\n\t\t\t\tif((x & (1<<i))>0) {\n\t\t\t\t\tSystem.out.print(i+1 + \" \");\n\t\t\t\t\tc++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.print(\"0 \");\n\t\t\tprint(nextstate[mask]);\n\t\t}\n\t}\n\n\tstatic int distace(int x1, int x2, int y1, int y2) {\n\t\treturn (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);\n\t}\n\n\tstatic int solve(int mask) {\n\t\tif (mask == v) {\n\t\t\tnextstate[mask] = r;\n\n\t\t\treturn 0;\n\t\t}\n\t\tif (nextstate[mask] != 0) {\n\t\t\treturn dp[mask];\n\t\t}\n\n\t\tdp[mask] = (int) 1e9;\n\t\tfor (int i = 1; i < pos.length; i++) {\n\t\t\tint u = (1 << (i - 1));\n\t\t\tint z = mask | u;\n\t\t\tif ((mask & u) == 0) {\n\t\t\t\tint x = 2 * dist[i][0] + solve(z);\n\t\t\t\tif (dp[mask] > x) {\n\t\t\t\t\tdp[mask] = x;\n\t\t\t\t\tnextstate[mask] = z;\n\t\t\t\t}\n\n\t\t\t\tfor (int j = 1; j < pos.length; j++) {\n\t\t\t\t\tint m = (1 << j - 1);\n\t\t\t\t\tint y = z | m;\n\t\t\t\t\tif ((z & m) == 0) {\n\t\t\t\t\t\tx = dist[i][0] + solve(y) + dist[i][j] + dist[j][0];\n\n\t\t\t\t\t\tif (dp[mask] > x) {\n\t\t\t\t\t\t\tdp[mask] = x;\n\t\t\t\t\t\t\tnextstate[mask]= y;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn dp[mask];\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tInputReader0 in = new InputReader0(System.in);\n\t\tint x = in.nextInt(), y = in.nextInt();\n\t\tint n = in.nextInt();\n\t\tr = 1 << n;\n\t\tv = r - 1;\n\t\tdp = new int[r];\n\t\tnextstate = new int[r];\n\t\tpos = new int[n + 1][2];\n\t\tpos[0][0] = x;\n\t\tpos[0][1] = y;\n\t\tfor (int i = 1; i < pos.length; i++) {\n\t\t\tpos[i][0] = in.nextInt();\n\t\t\tpos[i][1] = in.nextInt();\n\t\t}\n\t\tdist = new int[n + 1][n + 1];\n\t\tfor (int i = 0; i < dist.length; i++) {\n\t\t\tfor (int j = i + 1; j < dist.length; j++) {\n\t\t\t\tdist[i][j] = dist[j][i] = distace(pos[i][0], pos[j][0], pos[i][1], pos[j][1]);\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(solve(0));\n\t\tSystem.out.print(\"0 \");\n\t\tprint(0);\n\t}\n\n}\n\nclass InputReader0 {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\n\tpublic InputReader0(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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        int[] best = new int[1 << n];\n        int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            best[set] = best[set ^ (1 << i)] + single[i];\n            prev[set] = i + 1;\n            for (int j = i + 1; j < n; ++j)\n                if ((set & (1 << j)) != 0) {\n                    int cur = best[set ^ (1 << i) ^ (1 << j)] + pair[i][j];\n                    if (cur < best[set]) {\n                        best[set] = cur;\n                        prev[set] = (i + 1) * 100 + (j + 1);\n                    }\n                }\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n            int what = prev[now];\n            int wa = what % 100 - 1;\n            int wb = what / 100 - 1;\n            if (wa >= 0) {\n                writer.print(\" \");\n                writer.print(wa + 1);\n                now ^= 1 << wa;\n            }\n            if (wb >= 0) {\n                writer.print(\" \");\n                writer.print(wb + 1);\n                now ^= 1 << wb;\n            }\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class C {\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\thx = sc.nextInt();\n\t\thy = sc.nextInt();\n\t\tN = sc.nextInt();\n\t\tX = new int[N];\n\t\tY = new int[N];\n\t\tfor(int i = 0; i < N;i++){\n\t\t\tX[i] = sc.nextInt();\n\t\t\tY[i] = sc.nextInt();\n\t\t}\n\t\tDP = new int[1<<N];\n\t\tArrays.fill(DP,-1);\n\t\tint ans = recur(0);\n\t\tArrayList<Integer> aa = new ArrayList<Integer>();\n\t\tint U = 0;\n\t\taa.add(0);\n\t\tint test = 0;\n\t\twhile(U != (1<<N)-1){\n\t\t\tint a = 0;\n\t\t\tfor(int i = 0; i < N;i++)\n\t\t\t\tif(((1<<i)&U) == 0){\n\t\t\t\t\ta = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\t\t\n\t\t\tint ans2 = recur(U|(1<<a))+2*(pw(X[a]-hx)+pw(Y[a]-hy));\n\t\t\tint temp = 2*(pw(X[a]-hx)+pw(Y[a]-hy));\n\t\t\tint best = -1;\n\t\t\tfor(int i = a+1;i<N;i++){\n\t\t\t\tif(((1<<i)&U) == 0){\n\t\t\t\t\tint ans3 = pw(X[a]-X[i])+pw(Y[a]-Y[i])+pw(X[a]-hx)+pw(Y[a]-hy)+pw(X[i]-hx)+pw(Y[i]-hy)+recur(U|(1<<a)|(1<<i));\n\t\t\t\t\tif(ans3 < ans2){\n\t\t\t\t\t\tans2 = ans3;\n\t\t\t\t\t\tbest = i;\n\t\t\t\t\t\ttemp = pw(X[a]-X[i])+pw(Y[a]-Y[i])+pw(X[a]-hx)+pw(Y[a]-hy)+pw(X[i]-hx)+pw(Y[i]-hy);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(best == -1){\n\t\t\t\taa.add(a+1);\n\t\t\t\taa.add(0);\n\t\t\t\tU |= (1<<a);\n\t\t\t}else{\n\t\t\t\taa.add(a+1);\n\t\t\t\taa.add(best+1);\n\t\t\t\taa.add(0);\n\t\t\t\tU |= (1<<a) | (1<<best);\n\t\t\t}\n\t\t\ttest += temp;\n\t\t}\n//\t\tSystem.out.println(test);\n\t\tif(test != ans)\n\t\t\tthrow new RuntimeException();\n\t\tSystem.out.println(ans);\n\t\tfor(int i = 0; i < aa.size();i++)\n\t\t\tSystem.out.print(aa.get(i)+(i == aa.size()-1?\"\":\" \"));\n\t\tSystem.out.println();\n\t}\n\tprivate static int recur(int U) {\n\t\tif(DP[U] != -1)\n\t\t\treturn DP[U];\n\t\tif(U == (1<<N)-1)\n\t\t\treturn 0;\n\t\tint a = 0;\n\t\tfor(int i = 0; i < N;i++)\n\t\t\tif(((1<<i)&U) == 0){\n\t\t\t\ta = i;\n\t\t\t\tbreak;\n\t\t\t}\t\t\n\t\tint ans = recur(U|(1<<a))+2*(pw(X[a]-hx)+pw(Y[a]-hy));\n\t\tfor(int i = a+1;i<N;i++){\n\t\t\tif(((1<<i)&U) == 0){\n\t\t\t\tans = min(ans,pw(X[a]-X[i])+pw(Y[a]-Y[i])+pw(X[a]-hx)+pw(Y[a]-hy)+pw(X[i]-hx)+pw(Y[i]-hy)+recur(U|(1<<a)|(1<<i)));\n\t\t\t}\n\t\t}\n\t\tDP[U] = ans;\n\t\treturn ans;\n\t}\n\tstatic int pw(int a){\n\t\treturn a*a;\n\t}\n\tstatic int hx,hy;\n\tstatic int[] X,Y;\n\tstatic int N;\n\tstatic int[] DP;\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st = new StringTokenizer(\"\");\n    \n    int INF = Integer.MAX_VALUE >> 1;\n    \n    void run() throws IOException {\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n        \n        /* Input */\n        int x0 = nextInt();\n        int y0 = nextInt();\n        int N = nextInt();\n        int FULL_MASK = (1 << N) - 1;\n        int[] xs = new int [N];\n        int[] ys = new int [N];\n        for (int i = 0; i < N; i++) {\n            xs[i] = nextInt();\n            ys[i] = nextInt();\n        }\n        \n        /* Precalc */\n        int[][] dist = new int [N][N];\n        for (int i = 0; i < N; i++)\n            for (int j = 0; j < N; j++)\n                dist[i][j] = dist(x0, y0, xs[i], ys[i]) + dist(xs[i], ys[i], xs[j], ys[j]) + dist(xs[j], ys[j], x0, y0);\n        \n        /* DP */\n        int[] dp = new int [1 << N];\n        int[] pr = new int [1 << N];\n        Arrays.fill(dp, INF);\n        dp[0] = 0;\n        for (int mask = 0; mask < FULL_MASK; mask++) {\n            int i = Integer.numberOfTrailingZeros(~mask); // hack: use first non-zero bit\n            int imask = mask | (1 << i);\n            for (int j = i; j < N; j++) {\n                int jmask = mask | (1 << j);\n                if (jmask == mask) continue;\n                int ijmask = imask | jmask;\n                int nval = dp[mask] + dist[i][j];\n                if (dp[ijmask] > nval) {\n                    dp[ijmask] = nval;\n                    pr[ijmask] = mask;\n                }\n            }\n        }\n        \n        /* Output */\n        out.println(dp[FULL_MASK]);\n        out.print(\"0\");\n        for (int mask = FULL_MASK; mask != 0; mask = pr[mask]) {\n            int diff = mask ^ pr[mask];\n            int i = Integer.numberOfTrailingZeros(diff);\n            diff &= ~(1 << i);\n            int j = Integer.numberOfTrailingZeros(diff);\n            if (i != 32) out.print(\" \" + (i + 1));\n            if (j != 32) out.print(\" \" + (j + 1));\n            out.print(\" 0\");\n        }\n        out.println();\n        out.close();\n    }\n    \n    /*************************************************************** \n     * Utility\n     **************************************************************/\n    int dist(int x1, int y1, int x2, int y2) {\n        return sqr(x2 - x1) + sqr(y2 - y1);\n    }\n\n    int sqr(int x) {\n        return x * x;\n    }\n\n    /*************************************************************** \n     * Input \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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class CodeD \n{\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\t\n\t\tpublic String nextLine()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn br.readLine();\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tthrow(new RuntimeException());\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic String next()\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t{\n\t\t\t\tString l = nextLine();\n\t\t\t\tif(l == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(l);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong[] res = new long[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic double[] nextDoubleArray(int n)\n\t\t{\n\t\t\tdouble[] res = new double[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\tpublic void sortIntArray(int[] array)\n\t\t{\n\t\t\tInteger[] vals = new Integer[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortLongArray(long[] array)\n\t\t{\n\t\t\tLong[] vals = new Long[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortDoubleArray(double[] array)\n\t\t{\n\t\t\tDouble[] vals = new Double[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t}\n\tstatic final Scanner sc;\n\tstatic final int n;\n\tstatic final int[][] distancias;\n\tstatic final int[] distancia;\n\tstatic final int[] dp;\n\tstatic final int[] dpNext;\n\tstatic final int X;\n\tstatic final int Y;\n\t\n\tstatic\n\t{\n\t\tsc = new Scanner();\n\t\tX = sc.nextInt();\n\t\tY = sc.nextInt();\n\t\tn = sc.nextInt();\n\t\tdistancias = new int[n][n];\n\t\tdistancia = new int[n];\n\t\tdp = new int[1 << n];\n\t\tArrays.fill(dp, -1);\n\t\tdpNext = new int[1 << n];\n\t}\n\t\n\t\n\tstatic int dp(int mascara)\n\t{\n\t\tif(dp[mascara] != -1)\n\t\t\treturn dp[mascara];\n\t\tint highest = -1;\n\t\tfor(int i = 0, tmp = mascara; tmp != 0; i++, tmp >>= 1)\n\t\t{\n\t\t\tif((tmp & 1) == 1)\n\t\t\t\thighest = i;\n\t\t}\n\t\tif(highest == -1)\n\t\t\treturn 0;\n\t\tint nextMsc = mascara ^ (1 << highest);\n\t\tint costHighest = distancia[highest];\n\t\tint best = (costHighest << 1) + dp(nextMsc);\n\t\tint bestNext = nextMsc;\n\t\tfor(int i = 0, tmp = nextMsc, iC = 1; tmp != 0; i++, tmp >>= 1, iC <<= 1)\n\t\t{\n\t\t\tif((tmp & 1) == 1)\n\t\t\t{\n\t\t\t\tint msc = nextMsc ^ iC;\n\t\t\t\tint possibleA = costHighest + distancias[highest][i] + distancia[i] + dp(msc);\n\t\t\t\tif(possibleA < best)\n\t\t\t\t{\n\t\t\t\t\tbest = possibleA;\n\t\t\t\t\tbestNext = msc;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdpNext[mascara] = bestNext;\n\t\treturn dp[mascara] = best;\n\t\t\t\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tint[][] objetos = new int[n][2];\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tobjetos[i][0] = sc.nextInt();\n\t\t\tobjetos[i][1] = sc.nextInt();\n\t\t\tdistancia[i] = (X - objetos[i][0]) * (X - objetos[i][0]) + (Y - objetos[i][1]) * (Y - objetos[i][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\tdistancias[i][j] = (objetos[i][0] - objetos[j][0]) * (objetos[i][0] - objetos[j][0]) + (objetos[i][1] - objetos[j][1]) * (objetos[i][1] - objetos[j][1]);\n\t\tint ans = dp((1 << n) - 1);\n\t\tSystem.out.println(ans);\n\t\tint current = (1 << n) - 1;\n\t\twhile(current != 0)\n\t\t{\n\t\t\tint next = dpNext[current];\n\t\t\tint differents = next ^ current;\n\t\t\tSystem.out.print(\"0 \");\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tif((differents & (1 << i)) != 0)\n\t\t\t\t\tSystem.out.print((i + 1) + \" \");\n\t\t\tcurrent = next;\n\t\t}\n\t\tSystem.out.println(\"0\");\n\t}\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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.Arrays;\nimport java.util.StringTokenizer;\n\npublic class _8C {\n\n  static int[] x = new int[30], y = new int[30];\n  static int[][] dist = new int[30][30];\n  static int n;\n  static final int M = 1000;\n  static int[] bitPos = new int[M];\n  static {\n    Arrays.fill(bitPos, -1);\n    for (int i=0; i<24; i++)\n      bitPos[(1 << i) % M] = i;\n  }\n\n  static int sqr(int i) { \n    return i * i;\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    x[0] = Reader.nextInt();\n    y[0] = Reader.nextInt();\n    n = Reader.nextInt();\n    for (int i=1; i<=n; i++) {\n      x[i] = Reader.nextInt();\n      y[i] = Reader.nextInt();\n    }\n    for (int i=0; i<=n; i++)\n      for (int j=0; j<=n; j++)\n        dist[i][j] = sqr(x[i] - x[j]) + sqr(y[i] - y[j]);\n    \n    int[] f = new int[1 << n];\n    int[] r = new int[1 << n];\n    for (int mask=1; mask<(1 << n); mask++) {\n      int lowbit = mask & -mask;\n      int lowbitPos = bitPos[lowbit % M];\n      f[mask] = dist[lowbitPos + 1][0] * 2 + f[mask ^ lowbit];\n      r[mask] = lowbit;\n        for (int i=mask^(lowbit); i>0; i=i^(i & -i)) {\n          int otherBit = i & -i;\n          int otherBitPos = bitPos[otherBit % M];\n          int tmp = dist[0][lowbitPos + 1] + dist[lowbitPos + 1][otherBitPos + 1] + dist[otherBitPos + 1][0] + f[mask ^ otherBit ^ lowbit];\n          if (tmp < f[mask]) {\n            f[mask] = tmp;\n            r[mask] = lowbit | otherBit;\n          }\n      }\n    }\n    \n    System.out.println(f[(1 << n) - 1]);\n    int mask = (1 << n) - 1;\n    while(mask > 0) {\n      if ((r[mask] ^ (r[mask] & -r[mask])) == 0) {\n        System.out.print(\"0 \" + (bitPos[r[mask] % M] + 1) + \" \");\n      }\n      else {\n        int bit1 = r[mask] & -r[mask];\n        int bit2 = r[mask] ^ bit1;\n        System.out.print(\"0 \" + (bitPos[bit1 % M] + 1) + \" \" + (bitPos[bit2 % M] + 1) + \" \");\n      }\n      mask ^= r[mask];\n    }\n    System.out.println(\"0\");\n      \n    cout.close();\n  }\n\n  static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {\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 <U extends Comparable<U>, V extends Comparable<V>> Pair<U, V> instanceOf(U _1, V _2) {\n      return new Pair<U, V>(_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<U, V> 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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.lang.Math.*;\n\npublic class Main {\n\tstatic Scanner in = new Scanner(System.in);\n\tstatic Coor[] p;\n\tstatic Coor ori;\n\tstatic int n;\n\tstatic int dp[];\n\tstatic Coor pre[];\n\tpublic static void main(String[] args) {\n\t\tori = new Coor(in.nextInt(),in.nextInt());\n\t\tn = in.nextInt();\n\t\tp = new Coor[n];\n\t\tdp = new int[1<<n];\n\t\tpre = new Coor[1<<n];\n\t\tfor (int i = 0;i < n;i++) {\n\t\t\tp[i] = new Coor(in.nextInt(),in.nextInt());\n\t\t}\n\t\tArrays.fill(dp,-1);\n\t\tdp[0] = 0;\n\t\tSystem.out.println( getdp((1<<n)-1));\n\t\t//System.out.printf(\"%d\",0);\n\t\tSystem.out.printf(\"%d\",0);\n\t\ttrace((1<<n)-1);\n\t\tSystem.out.println();\n\t}\n\tstatic void trace(int mask) {\n\t\tif (mask == 0) return;\n\t\tif (pre[mask].y == -1) {\n\t\t\tSystem.out.printf(\" %d %d\",pre[mask].x+1,0);\n\t\t\ttrace( mask - ( 1<< pre[mask].x ) );\n\t\t} else {\n\t\t\tSystem.out.printf(\" %d %d %d\",pre[mask].x+1,pre[mask].y+1,0);\n\t\t\ttrace( mask - ( 1<< pre[mask].x ) - (1<<pre[mask].y));\n\t\t}\n\t}\n\tstatic int getdp(int mask) {\n\t\tif (dp[mask] != -1) \n\t\t\treturn dp[mask];\n\t\tint fr = 0;\n\t\tfor (int i = 0;i < n;i++) \n\t\t\tif ( (mask & (1 << i)) != 0 ) {\n\t\t\t\tfr = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tdp[mask] = getdp( mask - (1 << fr) ) + 2 * p[fr].dist(ori);\n\t\tpre[mask] = new Coor(fr,-1);\n\t\tfor (int i = fr+1;i < n;i++) {\n\t\t\tint to = i;\n\t\t\tif ( (mask & (1 << i)) != 0) {\n\t\t\t\tint tmp = getdp( mask - (1<<fr) - (1<<i) ) + p[fr].dist(ori) + p[to].dist(ori) + p[fr].dist(p[to]);\n\t\t\t\tif (tmp < dp[mask]) {\n\t\t\t\t\tdp[mask] = tmp;\n\t\t\t\t\tpre[mask].y = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[mask];\n\t}\n}\n\nclass Coor {\n\tint x,y;\n\tCoor(int _x,int _y) {\n\t\tx = _x;y = _y;\n\t}\n\tint dist(Coor o) {\n\t\treturn ( (x-o.x) * (x-o.x) + (y-o.y) * (y-o.y) );\n\t}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Bag implements Runnable {\n    private void solve() throws IOException {\n        int xs = nextInt();\n        int ys = nextInt();\n        int n = nextInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        for (int i = 0; i < n; ++i) {\n            x[i] = nextInt();\n            y[i] = nextInt();\n        }\n        int[][] pair = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            for (int j = i + 1; j < n; ++j)\n                pair[i][j] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys) + (x[j] - xs) * (x[j] - xs) + (y[j] - ys) * (y[j] - ys) + (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]);\n        int[] single = new int[n];\n        for (int i = 0; i < n; ++i) {\n            single[i] = 2 * ((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));\n        }\n        int[] best = new int[1 << n];\n        int[] prev = new int[1 << n];\n        for (int set = 1; set < (1 << n); ++set) {\n            int i;\n            for (i = 0; i < n; ++i)\n                if ((set & (1 << i)) != 0)\n                    break;\n            best[set] = best[set ^ (1 << i)] + single[i];\n            prev[set] = i + 1;\n            for (int j = i + 1; j < n; ++j)\n                if ((set & (1 << j)) != 0) {\n                    int cur = best[set ^ (1 << i) ^ (1 << j)] + pair[i][j];\n                    if (cur < best[set]) {\n                        best[set] = cur;\n                        prev[set] = (i + 1) * 100 + (j + 1);\n                    }\n                }\n        }\n        writer.println(best[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        writer.print(\"0\");\n        while (now > 0) {\n            int what = prev[now];\n            int wa = what % 100 - 1;\n            int wb = what / 100 - 1;\n            if (wa >= 0) {\n                writer.print(\" \");\n                writer.print(wa + 1);\n                now ^= 1 << wa;\n            }\n            if (wb >= 0) {\n                writer.print(\" \");\n                writer.print(wb + 1);\n                now ^= 1 << wb;\n            }\n            writer.print(\" \");\n            writer.print(\"0\");\n        }\n        writer.println();\n    }\n\n\n    public static void main(String[] args) {\n        new Bag().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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * CodeForces 8C - Looking for Order\n * Created by Darren on 14-10-1.\n */\npublic class Main {\n    Reader in = new Reader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) throws IOException {\n        new Main().run();\n    }\n\n    int n;\n    int[] x, y;\n    int[][] time;\n    int status;\n    int[] dp;\n    int[] pre;\n\n\n    void run() throws IOException {\n        int xs = in.nextInt(), ys = in.nextInt();\n        n = in.nextInt();\n        x = new int[n+1];\n        y = new int[n+1];\n        for (int i = 0; i < n; i++) {\n            x[i] = in.nextInt();\n            y[i] = in.nextInt();\n        }\n        x[n] = xs;\n        y[n] = ys;\n\n        computeTime();\n\n        status = (1<<n);\n        dp = new int[1<<n];\n        pre = new int[1<<n];\n        Arrays.fill(dp, -1);\n        dp[0] = 0;\n        for (int i = 0; i < status; i++) {\n            if (dp[i] == -1)\n                continue;\n            for (int j = 0; j < n; j++) {\n                if (((1<<j) & i) == 0) {\n                    int t1 = ((1<<j) | i), temp1 = dp[i] + 2 * time[n][j];\n                    if (dp[t1] == -1 || dp[t1] > temp1) {\n                        dp[t1] = temp1;\n                        pre[t1] = i;\n                    }\n                    for (int k = 0; k < n; k++) {\n                        if (((1<<k) & t1) == 0) {\n                            int t2 = ((1<<k) | t1),\n                                    temp2 = dp[i] + time[n][j] + time[j][k] + time[k][n];\n                            if (dp[t2] == -1 || dp[t2] > temp2) {\n                                dp[t2] = temp2;\n                                pre[t2] = i;\n                            }\n                        }\n                    }\n                    break;\n                }\n            }\n        }\n\n        int cur = (1 << n) - 1;\n        out.println(dp[cur]);\n        out.print(0);\n        while (cur > 0) {\n            int last = pre[cur], diff = cur ^ last;\n            int obj1 = -1, obj2 = -1;\n            for (int i = 0; i < n; i++) {\n                if (((1<<i) & diff) > 0) {\n                    obj2 = obj1;\n                    obj1 = i;\n                }\n            }\n            if (obj2 >= 0)\n                out.printf(\" %d %d %d\", obj1+1, obj2+1, 0);\n            else\n                out.printf(\" %d %d\", obj1+1, 0);\n            cur = last;\n        }\n        out.flush();\n    }\n\n    void computeTime() {\n        time = new int[n+1][n+1];\n        for (int i = 0; i <= n; i++) {\n            for (int j = i+1; j <= n; j++)\n                time[i][j] = time[j][i] = (x[i]- x[j])*(x[i]- x[j]) +\n                        (y[i]- y[j])*(y[i]- y[j]);\n        }\n    }\n\n    static class Reader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        public Reader(InputStream input) {\n            reader = new BufferedReader(new InputStreamReader(input));\n            tokenizer = new StringTokenizer(\"\");\n        }\n\n        /** get next word */\n        String nextToken() 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        String readLine() throws IOException {\n            return reader.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}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class AMain {\n\tstatic int n;\n\tstatic int[] best;\n\tstatic int[][] dist;\n\tstatic int[] home;\n\tstatic LinkedList<Integer> ret;\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tState curr = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));\n\t\tn = Integer.parseInt(br.readLine());\n\t\tState[] list = new State[n];\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tlist[i] = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));\n\t\t}\n\t\tdist = new int[n][n];\n\t\thome = new int[n];\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\thome[i] = dist(curr, list[i]);\n\t\t}\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tdist[i][i] = 2 * home[i];\n\t\t\tfor(int j = i+1; j < n; j++)\t\t{\n\t\t\t\tdist[i][j] = dist(list[i], list[j]) + home[i] + home[j];\n\t\t\t}\n\t\t}\n\t\tbest = new int[1 << (n)];\n\t\tArrays.fill(best, -1);\n\t\tbest[0] = 0;\n\t\tSystem.out.println(solve(-1 + (1<<n)));\n\t\tret = new LinkedList<Integer>();\n\t\tresolve(-1 + (1<<n));\n\t\tfor(int x: ret)\n\t\t\tSystem.out.print(x + \" \");\n\t}\n\tpublic static int dist(State a, State b)\t{\n\t\tint x = a.x-b.x;\n\t\tint y = a.y-b.y;\n\t\treturn x*x+y*y;\n\t}\n\tpublic static void resolve(int curr)\t{\n\t\tret.addLast(0);\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tif((curr & (1<<i)) == 0)\n\t\t\t\tcontinue;\n\t\t\tfor(int j = i+1; j < n; j++)\t{\n\t\t\t\tif((curr & (1 << j)) == 0)\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(dist[i][j] + solve(curr ^ (1<<i) ^ (1 << j)) == best[curr])\t{\n\t\t\t\t\tret.addLast(i+1);\n\t\t\t\t\tret.addLast(j+1);\n\t\t\t\t\tresolve(curr - (1<<i) - (1<<j));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(best[curr] == dist[i][i] + solve(curr ^ (1<<i)))\t{\n\t\t\t\tret.addLast(i+1);\n\t\t\t\tresolve(curr - (1<<i));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\tpublic static int solve(int curr)\t{\n\t\tif(best[curr] != -1)\n\t\t\treturn best[curr];\n\t\tint ret = Integer.MAX_VALUE;\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tif((curr & (1<<i)) == 0)\n\t\t\t\tcontinue;\n\t\t\tfor(int j = i+1; j < n; j++)\t{\n\t\t\t\tif((curr & (1 << j)) == 0)\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tret = Math.min(ret, dist[i][j] + solve(curr ^ (1<<i) ^ (1 << j)));\n\t\t\t}\n\t\t\tret = Math.min(ret, dist[i][i] + solve(curr ^ (1<<i)));\n\t\t\tbreak;\n\t\t}\n\t\tbest[curr] = ret;\n\t\treturn ret;\n\t}\n\tstatic class State\t{\n\t\tpublic int x,y;\n\t\tpublic State(int a, int b)\t{\n\t\t\tx=a;\n\t\t\ty=b;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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\npublic class C8 {\n\tstatic int[] mem;\n\tstatic int[] bag;\n\tstatic int[][] items;\n\tstatic int[] close;\n\tstatic PrintWriter pw;\n\tstatic int n;\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tpw = new PrintWriter(System.out);\n\t\t\n\t\tbag = new int[2];\n\t\tbag[0] = sc.nextInt();\n\t\tbag[1] = sc.nextInt();\n\t\t\n\t\tn = sc.nextInt();\n\t\titems = new int[n][2];\n\t\t\n\t\tfor(int i = 0;i<n;i++)\n\t\t{\n\t\t\titems[i][0] = sc.nextInt();\n\t\t\titems[i][1] = sc.nextInt();\n\t\t}\n\t\t\n\t\t//System.out.println((items[0][1]-bag[1])*(items[0][1]-bag[1]));\n\t\t\n\t\t\n\t\tmem = new int[1<<n];\n\t\t\n\t\tArrays.fill(mem, -1);\n\t\t\n\t\tpw.println(dp(0));\n\t\ttrace(0);\n\t\tpw.print(0);\n\t\t\n\t\tpw.flush();\n\t}\n\tstatic int dp(int mask){\n\t\tif(mask==(1<<n)-1)\n\t\t\treturn 0;\n\t\t\n\t\tif(mem[mask]!=-1)\n\t\t\treturn mem[mask];\n\t\t\n\t\tint ans = (int)1e9;\n\t\tfor(int i = 0;i<n;i++)\n\t\t\tif((1<<i&mask)==0)\n\t\t\t{\t\n\t\t\t\tans = getDisBag(i)*2+dp(mask|1<<i);\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tfor(int j = i+1;j<n;j++)\n\t\t\t\t\tif((1<<j&mask)==0)\n\t\t\t\t\t\tans = Math.min(ans, getDisBag(i)+getDis(i,j)+getDisBag(j)+dp(mask|1<<i|1<<j));\n\t\t\t\t\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\n\t\treturn mem[mask] = ans;\n\t}\n\tstatic int getDis(int i, int j){\n\t\treturn (items[i][0]-items[j][0])*(items[i][0]-items[j][0])+(items[i][1]-items[j][1])*(items[i][1]-items[j][1]);\n\t}\n\tstatic int getDisBag(int i){\n\t\treturn (items[i][0]-bag[0])*(items[i][0]-bag[0])+(items[i][1]-bag[1])*(items[i][1]-bag[1]);\n\t}\n\tstatic int getClosest(int i, int mask){\n\t\tint ret = -1;\n\t\tfor(int j = 0;j<n;j++)\n\t\t\tif(i!=j&&(mask&1<<j)==0)\n\t\t\t\tif(ret==-1||getDis(i, j)<getDis(i, ret))\n\t\t\t\t\tret = j;\n\t\treturn ret;\n\t}\n\tstatic void trace(int mask){\n\t\tif(mask==(1<<n)-1)\n\t\t\treturn;\n\t\t\n\t\tint ans = (int)1e9;\n\t\tfor(int i = 0;i<n;i++)\n\t\t\tif((1<<i&mask)==0)\n\t\t\t{\t\n\t\t\t\tans = getDisBag(i)*2+dp(mask|1<<i);\n\t\t\t\tif(mem[mask]==ans)\n\t\t\t\t{\n\t\t\t\t\tpw.print(0+\" \"+(i+1)+\" \");\n\t\t\t\t\ttrace(mask|1<<i);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor(int j = i+1;j<n;j++)\n\t\t\t\t\tif((1<<j&mask)==0)\n\t\t\t\t\t\tif(mem[mask] == getDisBag(i)+getDis(i,j)+getDisBag(j)+dp(mask|1<<i|1<<j))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpw.print(0+\" \"+(i+1)+\" \"+(j+1)+\" \");\n\t\t\t\t\t\t\ttrace(mask|1<<i|1<<j);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t}\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){\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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.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@yahoo.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\nclass TaskC {\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        int xs = in.readInt();\n        int ys = in.readInt();\n        int n = in.readInt();\n        int[] x = new int[n];\n        int[] y = new int[n];\n        IOUtils.readIntArrays(in, x, y);\n        int[] res = new int[1 << n];\n        int[] last = new int[1 << n];\n        Arrays.fill(res, Integer.MAX_VALUE);\n        int[] ds = new int[n];\n        for (int i = 0; i < n; i++) {\n            ds[i] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys);\n        }\n        int[][] d = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++)\n                d[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n        }\n        res[0] = 0;\n        for (int i = 1; i < (1 << n); i++) {\n            for (int j = 0; j < n; j++) {\n                if (((i >> j) & 1) != 0) {\n                    if (res[i - (1 << j)] + 2 * ds[j] < res[i]) {\n                        res[i] = res[i - (1 << j)] + 2 * ds[j];\n                        last[i] = i - (1 << j);\n                    }\n                    for (int k = j + 1; k < n; k++) {\n                        if (((i >> k) & 1) != 0) {\n                            if (res[i - (1 << j) - (1 << k)] + ds[j] + ds[k] + d[j][k] < res[i]) {\n                                res[i] = res[i - (1 << j) - (1 << k)] + ds[j] + ds[k] + d[j][k];\n                                last[i] = i - (1 << j) - (1 << k);\n                            }\n                        }\n                    }\n                    break;\n                }\n            }\n        }\n        int cur = (1 << n) - 1;\n        out.printLine(res[cur]);\n        while (cur != 0) {\n            out.print(\"0 \");\n            int dif = cur - last[cur];\n            for (int i = 0; i < n && dif != 0; i++) {\n                if (((dif >> i) & 1) != 0) {\n                    out.print((i + 1) + \" \");\n                    dif -= (1 << i);\n                }\n            }\n            cur = last[cur];\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 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    }\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\nimport static java.lang.System.out;\n\npublic final class LookingForOrder {\n    private static Map<Integer, Integer> es = new HashMap<Integer, Integer>();\n    private static void init() { for (int i = 0; i <= 24; i++) es.put(1 << i, i); }\n    private static int x, y;\n    private static int[] xs, ys;\n    private static int sqr(int i) { return i * i; }\n    private static int dist(int i, int j) {\n        return sqr(x - xs[i]) + sqr(y - ys[i]) + \n            sqr(xs[i] - xs[j]) + sqr(ys[i] - ys[j]) +\n            sqr(x - xs[j]) + sqr(y - ys[j]);\n    }\n\n    private static int n;\n    private static int[] tb, prevs;\n\n    private static int recur(int j) {\n        if (j == 0 || es.get(j) != null || tb[j] != 0) return tb[j];\n\n        int bl = j & -j;\n        int b = j ^ bl;\n        tb[j] = recur(bl) + recur(b);\n        prevs[j] = bl;\n\n        for (int i = es.get(bl) + 1; i <25; i++) {\n            if (((1 << i) & b) == 0) continue;\n\n            int k = bl | 1 << i;\n            int v = dist(es.get(bl), es.get(1 << i)) + recur(j ^ k);\n            if (v >= tb[j]) continue;\n\n            tb[j] = v;\n            prevs[j] = k;\n        }\n        return tb[j];\n    }\n\n    public static void main(String[] args) {\n        init();\n        Scanner s = new Scanner(System.in);\n        x = s.nextInt(); y = s.nextInt();\n        n = s.nextInt();\n        xs = new int[n]; ys = new int[n];\n        tb = new int[1 << n]; prevs = new int[1 << n];\n\n        for (int i = 0; i < n; i++) {\n            xs[i] = s.nextInt(); ys[i] = s.nextInt();\n            tb[1 << i] = sqr(x - xs[i]) + sqr(y - ys[i]) << 1;\n        }\n\n        int all = (1 << n) - 1;\n        out.println(recur(all));\n        StringBuilder sb = new StringBuilder();\n        int p = prevs[all];\n        int c = all;\n        while(p != 0 && p != c) {\n            if ((p ^ (p & -p)) == 0) sb.append(\"0 \" + (es.get(p & -p) + 1) + \" \");\n            else sb.append(\"0 \" + (es.get(p & -p) + 1) + \" \" + (es.get(p ^ (p & -p)) + 1) + \" \");\n            c = c ^ p;\n            p = prevs[c];\n        }\n\n        if ((c ^ (c & -c)) == 0) sb.append(\"0 \" + (es.get(c & -c) + 1) + \" 0\");\n        else sb.append(\"0 \" + (es.get(c & -c) + 1) + \" \" + (es.get(c ^ (c & -c)) + 1) + \" 0\");\n        out.println(sb);\n    }\n}\n\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n/**\n * Created by James on 1/29/2015.\n */\npublic class Driver {\n    private static int [][] distances, parents;\n    private static int [] distance, parent;\n    private static String [][] longNames;\n    private static String [] shortNames, answers;\n    private static int N;\n\n    public static void main(String [] args) throws IOException {\n        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));\n\n        String [] pieces = scanner.readLine().split(\"\\\\s+\");\n\n        //totally had to steal the vast majority of this from http://codeforces.com/contest/8/submission/9745593\n\n        Point origin = new Point(Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1]));\n\n        N = Integer.parseInt(scanner.readLine());\n\n        Point [] points = new Point[N + 1];\n        distances = new int[N  + 1][N + 1];\n        parents = new int[N + 1][N + 1];\n        longNames = new String[N][N];\n        shortNames = new String[N];\n\n        for (int i = 0; i < N; ++i) {\n            pieces = scanner.readLine().split(\"\\\\s+\");\n\n            points[i] = new Point(Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1]));\n        }\n\n        points[N] = origin;\n\n        for (int i = 0; i <= N; ++i) {\n            if (i < N) {\n                shortNames[i] = (i + 1) + \" \";\n            }\n\n            for (int j = 0; j <= N; ++j) {\n                if (i < N && j < N) {\n                    longNames[i][j] = (i + 1) + \" \" + (j + 1) + \" \";\n                }\n\n                distances[i][j] = 2 * points[i].distance(points[j]);\n                parents[i][j] = points[i].distance(points[N]) + points[i].distance(points[j]) + points[j].distance(points[N]);\n            }\n        }\n\n        distance = new int[1 << N];\n        parent = new int[1 << N];\n        answers = new String[1 << N];\n        Arrays.fill(distance, -1);\n        distance[0] = 0;\n\n        int result = rec((1 << N) - 1);\n        StringBuilder answer = new StringBuilder();\n\n        for (int i = distance.length - 1; parent[i] != i; i = parent[i]) {\n            answer.append(\"0 \");\n            answer.append(answers[i]);\n        }\n\n        answer.append(\"0\");\n        System.out.println(result);\n        System.out.println(answer.toString());\n    }\n\n    private static int rec(int mask) {\n        if (distance[mask] != -1) {\n            return distance[mask];\n        }\n\n        int min = 0;\n\n        while (((1 << min) & mask) == 0) {\n            min++;\n        }\n\n        int newMask = mask & (~(1 << min));\n        distance[mask] = rec(newMask) + distances[min][N];\n        parent[mask] = newMask;\n        answers[mask] = shortNames[min];\n\n        for (int i = min + 1; i < N; i++) {\n            if (((1 << i) & mask) > 0) {\n                newMask = mask & (~(1 << i)) & (~(1 << min));\n\n                int temp = rec(newMask) + parents[i][min];\n\n                if (temp< distance[mask]) {\n                    distance[mask] = temp;\n                    parent[mask] = newMask;\n                    answers[mask] = longNames[min][i];\n                }\n            }\n        }\n\n        return distance[mask];\n    }\n\n    private static class Point {\n        int x, y;\n\n        public Point(int x, int y) {\n            this.x = x;\n            this.y = y;\n        }\n\n        public int distance(Point p) {\n            return (int)(Math.pow(this.x - p.x, 2) + Math.pow(this.y - p.y, 2));\n        }\n    }\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer st;\n\n    int[] x;\n    int[] y;\n    int n;\n    int X, Y;\n\n    int[] d;\n    int[][] dist;\n\n    int sqr(int a) {\n        return a * a;\n    }\n\n    int dist(int X, int Y, int i) {\n        return sqr(X - x[i]) + sqr(Y - y[i]);\n    }\n\n    int[] dp;\n    byte[][] pred;\n\n    int rec(int mask) {\n        if (dp[mask] == -1) {\n            int res = 1 << 29;\n            boolean ok = false;\n            for (int i = 0; i < n; ++i)\n                if ((mask & (1 << i)) > 0) {\n                    ok = true;\n                    int mm = mask & ~(1 << i);\n                    for (int j = i; j < n; j++)\n                        if ((mask & (1 << j)) > 0) {\n                            int nmask = mm & ~(1 << j);\n                            int a = rec(nmask) + d[i] + d[j] + dist[i][j];\n                            if (a < res) {\n                                res = a;\n                                pred[0][mask] = (byte) (i);\n                                pred[1][mask] = (byte) (j);\n                            }\n                        }\n                    break;\n                }\n            if (!ok)\n                res = 0;\n            dp[mask] = res;\n        }\n        return dp[mask];\n    }\n\n    void solve() throws IOException {\n        X = ni();\n        Y = ni();\n        n = ni();\n        // if (n > 5)\n        // return;\n        x = new int[n];\n        y = new int[n];\n        for (int i = 0; i < n; i++) {\n            x[i] = ni();\n            y[i] = ni();\n        }\n        d = new int[n];\n        dist = new int[n][n];\n        for (int i = 0; i < n; ++i)\n            d[i] = dist(X, Y, i);\n        for (int i = 0; i < n; ++i)\n            for (int j = 0; j < n; j++) {\n                dist[i][j] = dist(x[i], y[i], j);\n            }\n        pred = new byte[2][1 << n];\n        dp = new int[1 << n];\n        Arrays.fill(dp, -1);\n        out.println(rec((1 << n) - 1));\n        int a = (1 << n) - 1;\n        while (a > 0) {\n            if (pred[0][a] != pred[1][a])\n                out.print(0 + \" \" + (pred[0][a] + 1) + \" \" + (pred[1][a] + 1)\n                        + \" \");\n            else\n                out.print(0 + \" \" + (pred[0][a] + 1) + \" \");\n            int na = a & ~(1 << pred[0][a]);\n            na &= ~(1 << pred[1][a]);\n            a = na;\n        }\n        out.println(0);\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            InterruptedException {\n        Thread th = new Thread(null, new Solution(), \"\", 536870912);\n        th.start();\n        th.join();\n    }\n\n    @Override\n    public void run() {\n        try {\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        } catch (Exception e) {\n            // TODO: handle exception\n        }\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "/**\n * DA-IICT\n * Author : PARTH PATEL\n */\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.fill;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.sort;\n\n\npublic class C8 \n{\n\n\tpublic static long mod = 1000000007;\n\tpublic static long INF = (1L << 60);\n\tstatic FastScanner2 in = new FastScanner2();\n\tstatic OutputWriter out = new OutputWriter(System.out);\n\tstatic int n;\n\tstatic int x,y;\n\tstatic int[] xx;\n\tstatic int[] yy;\n\tstatic int[] dist;\n\tstatic int[][] g;\n\tstatic int[] dp;\n\tpublic static int square(int x)\n\t{\n\t\treturn abs(x*x);\n\t}\n\tstatic class Pair\n\t{\n\t\tint 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}\n\tpublic static void main(String[] args) \n\t{\n\n\t\tx=in.nextInt();\n\t\ty=in.nextInt();\n\t\tn=in.nextInt();\n\t\txx=new int[n];\n\t\tyy=new int[n];\n\t\tdp=new int[1<<n];\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\txx[i]=in.nextInt();\n\t\t\tyy[i]=in.nextInt();\n\t\t}\n\t\tdist=new int[n];\n\t\tg=new int[n][n];\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tdist[i]=square(abs(xx[i]-x))+square(abs(yy[i]-y));\n\t\t}\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t{\n\t\t\t\tg[i][j]=square(abs(xx[i]-xx[j]))+square(yy[i]-yy[j]);\n\t\t\t\t//System.out.println(\"i \"+i+\" j \"+j+\" \"+g[i][j]);\n\t\t\t}\n\t\t}\n\t\tArrays.fill(dp, Integer.MAX_VALUE/2);\n\t\tdp[0]=0;\n\t\tfor(int i=0;i<(1<<n);i++)\n\t\t{\n\t\t\t//we have to find dp[i]\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t{\n\t\t\t\tif((i&(1<<j))>0)   //not visited j\n\t\t\t\tcontinue;\n\t\t\t\tdp[i|(1<<j)]=min(dp[i|(1<<j)], dp[i]+2*dist[j]);\n\t\t\t\tfor(int k=j+1;k<n;k++)\n\t\t\t\t{\n\t\t\t\t\tif((i&(1<<k))>0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tdp[i|(1<<j)|(1<<k)]=min(dp[i|(1<<j)|(1<<k)], dp[i]+dist[j]+dist[k]+g[j][k]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\t\n\t\tout.println(dp[(1<<n)-1]);\n\t\tStack<Integer> stack=new Stack<>();\n\t\tstack.push(0);\n\t\tint i=(1<<n)-1;\n\t\twhile(i>0)\n\t\t{\n\t\t\tboolean tocontinue=false;\n\t\t\tfor(int a=0;a<n;a++)\n\t\t\t{\n\t\t\t\tif((i&(1<<a))==0)\n\t\t\t\t\tcontinue;\n\t\t\t\tif(dp[i]==(dp[i^(1<<a)]+2*dist[a]))\n\t\t\t\t{\n\t\t\t\t\tstack.push(a+1);\n\t\t\t\t\tstack.push(0);\n\t\t\t\t\ti-=(1<<a);\n\t\t\t\t\ttocontinue=true;\n\t\t\t\t}\n\t\t\t\tif(tocontinue)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(int b=a+1;b<n;b++)\n\t\t\t\t{\n\t\t\t\t\tif((i & (1<<b)) == 0) continue;\n\t\t\t\t\tif(dp[i]==(dp[i^(1<<a)^(1<<b)]+dist[a]+dist[b]+g[a][b]))\n\t\t\t\t\t{\n\t\t\t\t\t\ti-=(1<<a);\n\t\t\t\t\t\ti-=(1<<b);\n\t\t\t\t\t\tstack.push(a+1);\n\t\t\t\t\t\tstack.push(b+1);\n\t\t\t\t\t\tstack.push(0);\n\t\t\t\t\t\ttocontinue=true;\n\t\t\t\t\t}\n\t\t\t\t\tif(tocontinue)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(tocontinue)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tfor(int ii : stack)\n\t\t\tout.print(ii+\" \");\n\t\tout.close();\n\n\t}\n\n\tpublic static long pow(long x, long n, long mod) \n\t{\n\t\tlong res = 1;\n\t\tfor (long p = x; n > 0; n >>= 1, p = (p * p) % mod) \n\t\t{\n\t\t\tif ((n & 1) != 0) \n\t\t\t{\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{\n\t\tlong r;\n\t\twhile (n2 != 0) \n\t\t{\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\tpublic static long lcm(long n1, long n2) \n\t{\n\t\tlong answer = (n1 * n2) / (gcd(n1, n2));\n\t\treturn answer;\n\t}\n\n\tstatic class FastScanner2 \n\t{\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{\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) \n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tsnumChars = System.in.read(buf);\n\t\t\t\t} catch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (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{\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 (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() \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\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong()\n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\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{\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\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() \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\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\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{\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\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{\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) \n\t\t{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\t}\n\n\tstatic class InputReader \n\t{\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) \n\t\t{\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{\n\t\t\tString fullLine = null;\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\tfullLine = reader.readLine();\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\n\t\tpublic String next()\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\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() \n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) \n\t\t{\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong a[] = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\n\t\t\t\ta[i] = nextLong();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int nextInt() \n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n\tstatic class OutputWriter \n\t{\n\t\tprivate final PrintWriter writer;\n\n\t\tpublic OutputWriter(OutputStream outputStream) \n\t\t{\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t\t}\n\n\t\tpublic OutputWriter(Writer writer)\n\t\t{\n\t\t\tthis.writer = new PrintWriter(writer);\n\t\t}\n\n\t\tpublic void print(Object... objects)\n\t\t{\n\t\t\tfor (int i = 0; i < objects.length; i++) \n\t\t\t{\n\t\t\t\tif (i != 0)\n\t\t\t\t\twriter.print(' ');\n\t\t\t\twriter.print(objects[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void println(Object... objects)\n\t\t{\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n\n\t\tpublic void close() \n\t\t{\n\t\t\twriter.close();\n\t\t}\n\n\t\tpublic void flush() \n\t\t{\n\t\t\twriter.flush();\n\t\t}\n\t}\n\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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 LookingForOrder {\n\n\tstatic int[] x, y;\n\tstatic int[] dp;\n\tstatic int n;\n\n\tstatic int dist(int i, int j) {\n\t\treturn ((x[i] - x[j]) * (x[i] - x[j]))\n\t\t\t\t+ ((y[i] - y[j]) * (y[i] - y[j]));\n\t}\n\n\tstatic int solve(int mask) {\n\t\tif (mask == (1 << n) - 1)\n\t\t\treturn 0;\n\t\tif (dp[mask] != -1)\n\t\t\treturn dp[mask];\n\t\tint ans = Integer.MAX_VALUE;\n\t\tint j = 0;\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\tif (j == 0) {\n\t\t\t\t\tans = Math\n\t\t\t\t\t\t\t.min(ans, 2 * dist(0, i) + solve(mask | (1 << i)));\n\t\t\t\t\tj = i;\n\t\t\t\t} else\n\t\t\t\t\tans = Math.min(ans, dist(0, i) + dist(i, j) + dist(j, 0)\n\t\t\t\t\t\t\t+ solve(mask | (1 << i) | (1 << j)));\n\t\t\t}\n\t\treturn dp[mask] = ans;\n\t}\n\n\tstatic void prnt(int mask) {\n\t\tif (mask == (1 << n) - 1)\n\t\t\treturn;\n\t\tint j = 0;\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\tif (j == 0) {\n\t\t\t\t\tj = i;\n\t\t\t\t\tif (dp[mask] == 2 * dist(0, i) + solve(mask | (1 << i))) {\n\t\t\t\t\t\tout.print(\" \" + i + \" 0\");\n\t\t\t\t\t\tprnt(mask | (1 << i));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else if (dp[mask] == dist(0, i) + dist(i, j) + dist(j, 0)\n\t\t\t\t\t\t+ solve(mask | (1 << i) | (1 << j))) {\n\t\t\t\t\tout.print(\" \" + i + \" \" + j + \" 0\");\n\t\t\t\t\tprnt(mask | (1 << i) | (1 << j));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tsc = new StringTokenizer(br.readLine());\n\t\tint a = nxtInt();\n\t\tint b = nxtInt();\n\t\tn = nxtInt() + 1;\n\t\tx = new int[n];\n\t\ty = new int[n];\n\t\tdp = new int[1 << n];\n\t\tArrays.fill(dp, -1);\n\t\tx[0] = a;\n\t\ty[0] = b;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tx[i] = nxtInt();\n\t\t\ty[i] = nxtInt();\n\t\t}\n\t\tout.println(solve(1 << 0));\n\t\tout.print(0);\n\t\tprnt(1 << 0);\n\t\tout.println();\n\t\tbr.close();\n\t\tout.close();\n\t}\n\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic StringTokenizer sc;\n\n\tstatic String nxtTok() throws IOException {\n\t\twhile (!sc.hasMoreTokens())\n\t\t\tsc = new StringTokenizer(br.readLine());\n\t\treturn sc.nextToken();\n\t}\n\n\tstatic int nxtInt() throws IOException {\n\t\treturn Integer.parseInt(nxtTok());\n\t}\n\n\tstatic long nxtLng() throws IOException {\n\t\treturn Long.parseLong(nxtTok());\n\t}\n}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class LookingForOrder {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int bx = in.nextInt();\n        int by = in.nextInt();\n        in.nextLine();\n        int n = in.nextInt();\n        int[][] objects = new int[n][2];\n        for (int i = 0; i < n; i++) {\n            objects[i][0] = in.nextInt();\n            objects[i][1] = in.nextInt();\n        }\n\n        int[] cs = new int[n];\n        for (int i = 0; i < n; i++) {\n            cs[i] = 2 * time(objects[i], new int[] { bx, by });\n        }\n\n        int[][] cd = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                cd[j][i] = cd[i][j] = time(objects[i], new int[] { bx, by }) + time(objects[j], new int[] { bx, by }) + time(objects[i], objects[j]);\n            }\n        }\n\n        int maxMask = 1 << n;\n        int[] dp = new int[maxMask];\n        int[] path = new int[maxMask];\n        Arrays.fill(dp, -1);\n        dp[0] = 0;\n\n        for (int g = 1; g < maxMask; g++) {\n            int min = Integer.MAX_VALUE;\n            int minPath = 0;\n            int h = 31;\n            while ((g & (1 << h)) == 0)\n                h--;\n            h++;\n            int l = 0;\n            while ((g & (1 << l)) == 0)\n                l++;\n            if ((g & 1 << l) > 0) {\n                int oneleft = g ^ (1 << l);\n                int t = cs[l] + dp[oneleft];\n                if (t < min) {\n                    min = t;\n                    minPath = oneleft;\n                }\n                for (int j = l + 1; j < h; j++) {\n                    if ((oneleft & 1 << j) > 0) {\n                        int twoleft = oneleft ^ (1 << j);\n                        t = cd[l][j] + dp[twoleft];\n                        if (t < min) {\n                            min = t;\n                            minPath = twoleft;\n                        }\n                    }\n                }\n            }\n            dp[g] = min;\n            path[g] = minPath;\n        }\n\n        System.out.println(dp[maxMask - 1]);\n\n        int previous = maxMask - 1;\n        int pathElt = path[previous];\n        System.out.print(\"0 \");\n        while (previous > 0) {\n            int bits = previous - pathElt;\n            int h = 31;\n            while ((bits & (1 << h)) == 0)\n                h--;\n            int l = 0;\n            while ((bits & (1 << l)) == 0)\n                l++;\n            String el = h == l ? \"\" + (h + 1) : (h + 1) + \" \" + (l + 1);\n            System.out.print(el + \" \" + 0 + \" \");\n            previous = pathElt;\n            pathElt = path[pathElt];\n        }\n        System.out.println();\n\n    }\n\n    static int time(int[] a, int[] b) {\n        int x = b[0] - a[0];\n        int y = b[1] - a[1];\n        return x * x + y * y;\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "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.awt.Point;\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        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            Point bag = new Point(in.ni(), in.ni());\n            int n = in.ni();\n            Point[] arr = new Point[n];\n            for (int i = 0; i < n; ++i)\n                arr[i] = new Point(in.ni(), in.ni());\n            int[] dist = new int[n];\n            for (int i = 0; i < n; ++i) {\n                int dx = arr[i].x - bag.x;\n                int dy = arr[i].y - bag.y;\n                dist[i] = dx * dx + dy * dy;\n            }\n            int[][] d = new int[n][n];\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < n; ++j) {\n                    int dx = arr[i].x - arr[j].x;\n                    int dy = arr[i].y - arr[j].y;\n                    d[i][j] = dx * dx + dy * dy + dist[i] + dist[j];\n                }\n            }\n            int lim = (1 << n);\n            int[] dp = new int[lim];\n            Arrays.fill(dp, Integer.MAX_VALUE);\n            dp[0] = 0;\n            int[] p = new int[lim];\n            Arrays.fill(p, -1);\n            for (int mask = 0; mask < lim; ++mask) {\n                if (dp[mask] == Integer.MAX_VALUE)\n                    continue;\n                int minBit = -1;\n                for (int bit = 0; bit < n; ++bit) {\n                    if (checkBit(mask, bit))\n                        continue;\n                    if (minBit == -1 || (dist[minBit] > dist[bit]))\n                        minBit = bit;\n                }\n                if (minBit == -1)\n                    continue;\n                for (int bit = 0; bit < n; ++bit) {\n                    if (checkBit(mask, bit))\n                        continue;\n                    int newMask = (mask | (1 << minBit) | (1 << bit));\n                    if (dp[newMask] > dp[mask] + d[minBit][bit]) {\n                        dp[newMask] = dp[mask] + d[minBit][bit];\n                        p[newMask] = minBit * n + bit;\n                    }\n                }\n            }\n            out.println(dp[lim - 1]);\n\n            int curMask = lim - 1;\n            while (p[curMask] != -1) {\n                out.print(\"0 \");\n                int first = p[curMask] / n;\n                int second = p[curMask] % n;\n                out.print(first + 1 + \" \");\n                curMask ^= (1 << first);\n                if (first != second) {\n                    out.print(second + 1 + \" \");\n                    curMask ^= (1 << second);\n                }\n            }\n            out.println(0);\n        }\n\n        boolean checkBit(int mask, int bitNumber) {\n            return (mask & (1 << bitNumber)) != 0;\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 n() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException();\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(n());\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class CF8C {\n\tstatic int n;\n\tstatic int[] mem;\n\tstatic HashMap<Integer, String> map;\n\tstatic int INF = (int) 1e9;\n\tstatic StringBuilder sb;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tMyScanner sc = new MyScanner(System.in);\n\t\tString s = sc.nextLine();\n\t\tn = sc.nextInt();\n\t\tmem = new int[1 << n];\n\t\tArrays.fill(mem, -1);\n\t\tmap = new HashMap<>();\n\t\tmap.put(0, s);\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tmap.put(i, sc.nextLine());\n\t\t}\n\t\tint val = dp(0);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(val);\n\t\tsb = new StringBuilder();\n\t\tsb.append(\"0 \");\n\t\tbuild(0);\n\t\tpw.println(sb);\n\t\tpw.flush();\n\t}\n\n\t// node == 0 -- > count 0 // state == 0 has 1 // state == 1 has 2\n\n\tprivate static int dp(int msk) {\n\t\tif (msk == (1 << n) - 1)\n\t\t\treturn 0;\n\n\t\tif(mem[msk] != -1)\n\t\t\treturn mem[msk];\n\n\t\tboolean foundFirst = false;\n\t\tint val = (int)1e9; \n\t\tint mark = -1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tif ((msk & 1 << (i - 1)) == 0){\n\t\t\t\tif(!foundFirst){\n\t\t\t\t\tfoundFirst = true;\n\t\t\t\t\tmark = i;\n\t\t\t\t\tval = dist(0, mark)*2 + dp(msk | 1 << (mark - 1));\n\t\t\t\t}else{\n\t\t\t\t\tval = Math.min(val, dist(0, mark) + dist(mark, i) + dist(i, 0) + dp((msk|1 << (mark - 1))|1 << (i - 1)));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn mem[msk] = val;\n\t}\n\n\tprivate static int dist(int node, int i) {\n\t\tString from = map.get(i);\n\t\tString to = map.get(node);\n\t\tString[] fromco = from.split(\" \");\n\t\tString[] toco = to.split(\" \");\n\t\tint xs = Integer.parseInt(fromco[0]);\n\t\tint ys = Integer.parseInt(fromco[1]);\n\t\tint xf = Integer.parseInt(toco[0]);\n\t\tint yf = Integer.parseInt(toco[1]);\n\t\treturn (xs - xf) * (xs - xf) + (ys - yf) * (ys - yf);\n\t}\n\n\tprivate static void build(int msk) {\n\t\tif (msk == (1 << n) - 1) \n\t\t\treturn;\n\t\tboolean foundFirst = false;\n\t\tint ans = dp(msk);\n\t\tint mark = -1;\n\t\tint val = (int)1e9;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tif ((msk & 1 << (i - 1)) == 0){\n\t\t\t\tif(!foundFirst){\n\t\t\t\t\tfoundFirst = true;\n\t\t\t\t\tmark = i;\n\t\t\t\t\tval = dist(0, mark)*2 + dp(msk | 1 << (mark - 1));\n\t\t\t\t\tif(val == ans){\n\t\t\t\t\t\tsb.append(mark + \" 0 \");\n\t\t\t\t\t\tbuild(msk | 1 << (mark - 1));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tval = dist(0, mark) + dist(mark, i) + dist(i, 0) + dp(msk|1 << (mark - 1)|1 << (i - 1));\n\t\t\t\t\tif(val == ans){\n\t\t\t\t\t\tsb.append(mark + \" \" + i + \" 0 \");\n\t\t\t\t\t\tbuild(msk|1 << (mark - 1)|1 << (i - 1));\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}\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 MyScanner(String s) throws FileNotFoundException {\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\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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.StringTokenizer;\n/**\n * 9:50 ~ \n *\n */\npublic class Main {\n\tpublic static int n, x, y;\n\tpublic static int[] a,b;\n\tpublic static int dp[], before[];\n\tpublic static int dx[];\n\tpublic static int d[][];\n\tpublic static final int INF = 24 * 201 * 201; \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\tx = scan.nextInt();\n\t\ty = scan.nextInt();\n\t\t\n\t\tn = scan.nextInt();\n\t\t\n\t\ta = new int[n+1];\n\t\tb = new int[n+1];\n\t\tdx = new int[n+1];\n\t\td = new int[n+1][n+1];\n\t\tfor(int i = 0; i < n; ++i){\n\t\t\ta[i] = scan.nextInt();\n\t\t\tb[i] = scan.nextInt();\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < n; ++i){\n\t\t\tdx[i] = dist(i);\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\td[i][j] = dist(i,j);\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1 << n];\n\t\tbefore = new int[1 << n];\n\t\tArrays.fill(dp, INF);\n\t\tdp[0] = 0;\n\t\tfor(int state = 0; state < (1<<n); state++){\n\t\t\t//if(dp[state] == INF) continue;\n\t\t\tfor(int i = 0; i < n; ++i){\n\t\t\t\tint ii = (1 << i);\n\t\t\t\tif((state & ii) > 0){\n\t\t\t\t\tif(dp[state - ii] == INF) continue;\n\t\t\t\t\tint newdist = dp[state - ii] + dx[i] + dx[i];\n\t\t\t\t\tif(dp[state] > newdist){\n\t\t\t\t\t\tdp[state] = newdist;\n\t\t\t\t\t\tbefore[state] = state - ii;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t} else continue;\n\t\t\t\t\n\t\t\t\tfor(int j = i + 1; j < n; ++j){\n\t\t\t\t\tif(i == j) continue;\n\t\t\t\t\tint jj = (1 << j);\n\t\t\t\t\tif((state & jj) > 0){\n\t\t\t\t\t\tif(dp[state - ii - jj] == INF) continue;\n\t\t\t\t\t\tint newdist = dp[state - ii - jj] + dx[i] + d[i][j] + dx[j];\n\t\t\t\t\t\tif(dp[state] > newdist){\n\t\t\t\t\t\t\tdp[state] = newdist;\n\t\t\t\t\t\t\tbefore[state] = state - ii - jj;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(dp[(1<<n)-1]);\n\t\tint state = (1<<n) - 1;\n\t\tStringBuffer ret = new StringBuffer();\n\t\twhile(state > 0){\n\t\t\tint nstate = before[state];\n\t\t\tboolean find = false;\n\t\t\tString made = \"\";\n\t\t\tfor(int i = 0; i < n; ++i){\n\t\t\t\tif(((state & (1<<i)) > 0) && ((nstate & (1<<i)) == 0)){\n\t\t\t\t\tfind = true;\n\t\t\t\t\tmade = made + \" \" + (i + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(find){\n\t\t\t\tmade = made + \" 0\";\n\t\t\t\tret.append(made, 0, made.length());\n\t\t\t}\n\t\t\tstate = nstate;\n\t\t}\n\t\tout.println(\"0\" + ret.toString());\n\t\tout.close();\n\t}\n\tpublic static int dist(int to){\n\t\treturn Math.abs(a[to] - x) * Math.abs(a[to] - x) + Math.abs(b[to] - y) * Math.abs(b[to] - y);\n\t}\n\tpublic static int dist(int from, int to){\n\t\treturn Math.abs(a[from]-a[to]) * Math.abs(a[from]-a[to]) + Math.abs(b[from]-b[to]) * Math.abs(b[from]-b[to]);\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", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class CF_8C {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\t// Hooray bitmasks! I'm good at these :)\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\t// Handbag coordinates..\n\t\tint hb_x = in.nextInt(), hb_y = in.nextInt();\n\t\tint n = in.nextInt();\n\t\tint[] ox = new int[n];\n\t\tint[] oy = new int[n];\n\t\t\n\t\t// Dynamic programming: Also store a matrix of the time to reach one\n\t\t//  object from the other.\n\t\t// This considers the handbag to be object 0\n\t\tint[][] dt = new int[n][n];\n\t\tint[] hbd = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tox[i] = in.nextInt();\n\t\t\toy[i] = in.nextInt();\n\t\t\thbd[i] = (ox[i] - hb_x) * (ox[i] - hb_x)\n\t\t\t\t\t+ (oy[i] - hb_y) * (oy[i] - hb_y);\n\t\t}\n\t\t\n\t\t// Compute elapsed times...\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tdt[i][j] = (ox[i] - ox[j]) * (ox[i] - ox[j])\n\t\t\t\t\t\t+ (oy[i] - oy[j]) * (oy[i] - oy[j]);\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Fill up an array with the amount of time it takes to grab\n\t\t//  all objects with the specified bitmask.\n\t\tint[] sofar = new int[1 << n];\n\t\tint[] masks = new int[1 << n];\n\t\tsofar[0] = 0;\n\t\tfor (int i = 1; i < (1 << n); i++) {\n\t\t\tsofar[i] = -1;\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < (1 << n); i++) {\n\t\t\tif (sofar[i] != -1) {\n\t\t\t\tfor (int maskbit = 0; maskbit < n; maskbit++) {\n\t\t\t\t\t// Look for first object in bitmask to grab...\n\t\t\t\t\tif (((1 << maskbit) & i) == 0) {\n\t\t\t\t\t\tint iffirst = ((1 << maskbit) | i);\n\t\t\t\t\t\tint fromold = sofar[i] + 2 * hbd[maskbit];\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (sofar[iffirst] == -1 || sofar[iffirst] > fromold) {\n\t\t\t\t\t\t\t// A better way to get to position J was found, use it.\n\t\t\t\t\t\t\tsofar[iffirst] = fromold;\n\t\t\t\t\t\t\tmasks[iffirst] = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// Find another thing while you're out...\n\t\t\t\t\t\tfor (int otherone = 0; otherone < n; otherone++) {\n\t\t\t\t\t\t\tif (((1 << otherone) & iffirst) == 0) {\n\t\t\t\t\t\t\t\tint iffollow = ((1 << otherone) | iffirst);\n\t\t\t\t\t\t\t\tint fromi = sofar[i] + hbd[maskbit] + dt[maskbit][otherone] + hbd[otherone];\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t// Did we find a better way to get to iffollow state?\n\t\t\t\t\t\t\t\tif (sofar[iffollow] == -1 || sofar[iffollow] > fromi) {\n\t\t\t\t\t\t\t\t\tsofar[iffollow] = fromi;\n\t\t\t\t\t\t\t\t\tmasks[iffollow] = 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\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// After all this time, we have an answer.\n\t\t// The minimum time will be the value of sofar at the very end,\n\t\t//  which will have the case of if all objects were picked up.\n\t\t// Clever, no?\n\t\t// The logic came from http://www.darrensun.com/codeforces-round-8/\n\t\t// Wish I could claim it mine, but it is not so.\n\t\t\n\t\tint end_val = (1 << n) - 1;\n\t\t\n\t\tSystem.out.println(sofar[end_val]);\n\t\tSystem.out.print(0);\n\t\twhile (end_val > 0) {\n\t\t\t// Which objects were collected in the prvious trip?\n\t\t\tint diff = end_val ^ masks[end_val];\n\t\t\tint obj1 = -1, obj2 = -1;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (((1 << i) & diff) > 0) {\n\t\t\t\t\tobj2 = obj1;\n\t\t\t\t\tobj1 = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (obj2 >= 0) {\n\t\t\t\t// Two objects were collected this trip, output them both.\n\t\t\t\tSystem.out.print(\" \" + (obj1 + 1) + \" \" + (obj2 + 1) + \" 0\");\n\t\t\t} else {\n\t\t\t\t// Only one object was collected here.\n\t\t\t\tSystem.out.print(\" \" + (obj1 + 1) + \" 0\");\n\t\t\t}\n\t\t\tend_val = masks[end_val];\n\t\t}\n\t\t\n\t\tin.close();\n\t}\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.awt.Polygon;\nimport java.io.BufferedWriter;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.*;\nimport java.util.Collection;\n\npublic class Solution {\n\n\t/**\n\t * @param args\n\t * @throws IOException \n\t */\n\tstatic StringTokenizer st;\n\tstatic BufferedReader reader;\n\tpublic static void main(String[] args) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tint xs = NextInt();\n\t\tint ys = NextInt();\n\t\tint n = NextInt();\n\t\n\t\tint x[] = new int[n];\n\t\tint y[] = new int[n];\n\t\tint single[] = new int[n];\n\t\tint pair[][] = new int[n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tx[i] = NextInt();\n\t\t\ty[i] = NextInt();\n\t\t}\n\t\tfor (int i = 0; i < n; ++i) \n\t\t\tsingle[i] = 2 * dist(xs, ys, x[i], y[i]);\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tfor (int j = 0; j < n; ++j)\n\t\t\t\tpair[i][j] = dist(xs, ys, x[i], y[i]) + \n\t\t\t\t\t\t\t dist(x[i], y[i], x[j], y[j]) +\n\t\t\t\t\t\t\t dist(x[j], y[j], xs, ys);\n\t\tint dp[] = new int[1 << n];\n\t\tint prev[] = new int[1 << n];\n\t\tfor (int mask = 0; mask < (1 << n); ++mask) {\n\t\t\tint p = -1;\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\tif (((mask >> i) & 1) != 0) {\n\t\t\t\t\tp = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (p == -1) continue;\n\t\t\tdp[mask] = dp[mask ^ (1 << p)] + single[p];\n\t\t\tprev[mask] = p;\n\t\t\tfor (int j = p + 1; j < n; ++j) {\n\t\t\t\tif (((mask >> j) & 1) != 0) {\n\t\t\t\t\tint res = pair[p][j] + dp[mask ^ (1 << p) ^ (1 << j)];\n\t\t\t\t\tif (res < dp[mask]) {\n\t\t\t\t\t\tdp[mask] = res;\n\t\t\t\t\t\tprev[mask] = p + 100 * j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint cur = (1 << n) - 1;\n\t\tSystem.out.printf(\"%d\\n0 \", dp[cur]);\n\t\twhile(cur != 0) {\n\t\t\tif (prev[cur] < 100) {\n\t\t\t\tSystem.out.printf(\"%d %d \", prev[cur] + 1, 0);\n\t\t\t\tcur ^= (1 << prev[cur]);\n\t\t\t} else {\n\t\t\t\tint i = prev[cur] / 100;\n\t\t\t\tint j = prev[cur] % 100;\n\t\t\t\tSystem.out.printf(\"%d %d %d \", i + 1, j + 1, 0);\n\t\t\t\tcur = cur ^ (1 << i) ^ (1 << j);\n\t\t\t}\n\t\t}\n\t}\n\tstatic int dist(int x0, int y0, int x1, int y1) {\n\t\treturn (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1); \n\t}\n\tstatic int NextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(NextToken());\n\t}\n\tstatic String NextToken() throws IOException {\n\t\twhile(st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n    \n    static final int MAXN = 24;\n    int[] x = new int[MAXN];\n    int[] y = new int[MAXN];\n    int[][] dist = new int[MAXN][MAXN];\n    int[] single = new int[MAXN];\n    \n    int sqr(int x) { return x * x; }\n    \n    void run(int nT) {\n        int xs = cin.nextInt();\n        int ys = cin.nextInt();\n        int n = cin.nextInt();\n        for (int i = 0; i < n; ++i) {\n            x[i] = cin.nextInt();\n            y[i] = cin.nextInt();\n        }\n        for (int i = 0; i < n; ++i) {\n            for (int j = i + 1; j < n; ++j) {\n                dist[i][j] = sqr(x[i] - xs) + sqr(y[i] - ys)\n                    + sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(x[j] - xs) + sqr(y[j] - ys);\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            single[i] = (sqr(x[i] - xs) + sqr(y[i] - ys)) * 2;\n        }\n        int[] dp = new int[1 << n];\n        int[] pre = new int[1 << n];\n        int tot = 1 << n;\n        for (int s = 1; s < tot; ++s) {\n            int i;\n            for (i = 0; i < n; ++i) {\n                if ((s & (1 << i)) != 0) break;\n            }\n            dp[s] = dp[s^(1<<i)] + single[i];\n            pre[s] = i + 1;\n            for (int j = i + 1; j < n; ++j) {\n                if ((s & (1 << j)) != 0) {\n                    int cur = dp[s^(1 << i) ^(1<<j)] + dist[i][j];\n                    if (cur < dp[s]) {\n                        dp[s] = cur;\n                        pre[s] = (i + 1) * 100 + (j + 1);\n                    }\n                }\n            }\n        }\n        out.println(dp[tot - 1]);\n        int now = tot - 1;\n        out.print(\"0\");\n        while (now > 0) {\n            int what = pre[now];\n            int px = what % 100 - 1;\n            int py = what / 100 - 1;\n            if (px >= 0) {\n                out.print(\" \");\n                out.print(px + 1);\n                now ^= 1 << px;\n            }\n            if (py >= 0) {\n                out.print(\" \");\n                out.print(py + 1);\n                now ^= 1 << py;\n            }\n            out.print(\" \");\n            out.print(\"0\");\n        }\n        out.println(\"\");\n    }\n\n    public static void main(String[] argv) {\n        Main solved = new Main();\n        int T = 1;\n        // T = solved.cin.nextInt();\n        for (int nT = 1; nT <= T; ++nT) {\n            solved.run(nT);\n        }\n        solved.out.close();\n    }\n\n    InputReader cin = new InputReader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\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 (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}", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\npublic class Main {\n\n    static Scanner cin = new Scanner(System.in);\n    private int xs, ys, n;\n    private int[] x, y;\n\n    public static void main(String[] args) throws Exception {\n        new Main().run();\n    }\n\n    class Item implements Comparable<Item> {\n\n        int w, h, idx;\n\n        Item(int w, int h, int idx) {\n            this.w = w;\n            this.h = h;\n            this.idx = idx;\n        }\n\n        @Override\n        public int compareTo(Item o) {\n            if (this.w == o.w) {\n                return this.h - o.h;\n            }\n            return this.w - o.w;\n        }\n    }\n\n    private void run() throws Exception {\n        xs = cin.nextInt();\n        ys = cin.nextInt();\n        n = cin.nextInt();\n        x = new int[n + 1];\n        y = new int[n + 1];\n        for (int i = 0; i < n; i++) {\n            x[i] = cin.nextInt();\n            y[i] = cin.nextInt();\n        }\n        int[] res = new int[1 << n];\n        Arrays.fill(res, Integer.MAX_VALUE);\n        int[] ds = new int[n];\n        for (int i = 0; i < n; i++) {\n            ds[i] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys);\n        }\n        int[][] d = new int[n + 1][n + 1];\n        int[] tr = new int[1 << n];\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                d[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);\n            }\n        }\n        //----------------------\n        res[0] = 0;\n        for (int i = 1; i < (1 << n); i++) {\n            for (int j = 0; j < n; j++) {\n                if (((i >> j) & 1) != 0) {\n                    if (res[i - (1 << j)] + 2 * ds[j] < res[i]) {\n                        res[i] = res[i - (1 << j)] + 2 * ds[j];\n                        tr[i] = i - (1 << j);\n                    }\n                    for (int k = j + 1; k < n; k++) {\n                        if (((i >> k) & 1) != 0) {\n                            if (res[i - (1 << j) - (1 << k)] + ds[k] + ds[j] + d[k][j] < res[i]) {\n                                res[i] = res[i - (1 << j) - (1 << k)] + ds[k] + ds[j] + d[k][j];\n                                tr[i] = i - (1 << j) - (1 << k);\n                            }\n                        }\n                    }\n                    break;\n                }\n            }\n        }\n        System.out.println(res[(1 << n) - 1]);\n        int now = (1 << n) - 1;\n        while (now != 0) {\n            System.out.print(\"0 \");\n            int dif = now - tr[now];\n            for (int i = 0; i < n && dif != 0; i++) {\n                if (((dif >> i) & 1) != 0) {\n                    System.out.print((i + 1) + \" \");\n                    dif -= (1 << i);\n                }\n            }\n            now=tr[now];\n        }\n        System.out.print(\"0\");\n    }\n}\n", "complexity": "np", "problem": "8_C. Looking for Order", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class cf16e {\n\tstatic int n;\n\tstatic double[][] prob;\n\tstatic double[] memo;\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextInt();\n\t\tprob = new double[n][n];\n\t\tmemo = new double[1<<n];\n\t\tfor(int i=0; i<n; i++)\n\t\t\tfor(int j=0; j<n; j++)\n\t\t\t\tprob[i][j] = in.nextDouble();\n\t\tmemo[(1<<n)-1] = 1;\n\t\tfor(int k=(1<<n)-1; k>0; k--) {\n\t\t\tint numWays = Integer.bitCount(k);\n\t\t\tnumWays = (numWays*(numWays-1))/2;\n\t\t\tfor(int first = 0; first < n; first++) {\n\t\t\t\tif(!isSet(k,first)) continue;\n\t\t\t\tfor(int second = first+1; second < n; second++) {\n\t\t\t\t\tif(!isSet(k,second)) continue;\n\t\t\t\t\tmemo[reset(k,first)] += prob[second][first]*memo[k]/numWays;\n\t\t\t\t\tmemo[reset(k,second)] += prob[first][second]*memo[k]/numWays;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0; i<n; i++)\n\t\t\tSystem.out.printf(\"%.6f \", memo[set(0,i)]);\n\t\tSystem.out.println();\n\t}\n\tstatic boolean isSet(int x, int p) {\n\t\treturn (x&(1<<p)) != 0;\n\t}\n\tstatic int set(int x, int p) {\n\t\treturn x|(1<<p);\n\t}\n\tstatic int reset(int x, int p) {\n\t\treturn x&~(1<<p);\n\t}\n\tstatic boolean isDone(int x) {\n\t\treturn Integer.bitCount(x)==n-1;\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/14/11\n * Time: 9:53 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 Fish extends Thread {\n\n    public Fish() {\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    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        double[][] a = new double[n][n];\n        double[] dp = new double[(1 << n)];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        }\n        int limit = (1 << n) - 1;\n        //dp[mask] = probability of current subset (mask) to remain in the end\n        dp[limit] = 1.0;\n        for (int mask = limit; mask > 0; --mask) {\n            int cardinality = getOnes(mask);\n            if (cardinality < 2) {\n                continue;\n            }\n            int probability = cardinality * (cardinality - 1) / 2;\n            for (int first = 0; first < n; ++first) {\n                if ((mask & powers[first]) != 0) {\n                    for (int second = first + 1; second < n; ++second) {\n                        if ((mask & powers[second]) != 0) {\n                            dp[mask - powers[first]] += dp[mask] * a[second][first] / probability;\n                            dp[mask - powers[second]] += dp[mask] * a[first][second] / probability;\n                        }\n\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            output.printf(\"%.10f \", dp[powers[i]]);\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\n    public static void main(String[] args) {\n        new Fish().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    static final int powers[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\n\npublic class Main{\n    \n    static double EPS=1e-10;\n    static double PI=Math.acos(-1.0);\n    \n    static double p[][]=new double[25][25];\n    static double f[]=new double[1<<20];\n    static int n;\n    \n    \n    public static void PR(String s){\n        System.out.print(s);\n    }\n    \n    public static void PR(double s)\n    {\n        java.text.DecimalFormat d=new java.text.DecimalFormat(\"#.0000000\");\n        System.out.print(d.format(s));\n    }\n    \n    public static void DP()\n    {\n        int i,j,k,cnt;\n        for(i=0;i<(1<<n);i++) f[i]=0;\n        f[(1<<n)-1]=1;\n        for(k=(1<<n)-1;k>=0;k--)\n        {\n            cnt=0;\n            for(i=0;i<n;i++) if((k&(1<<i))!=0) cnt++;\n            for(i=0;i<n;i++) if((k&(1<<i))!=0)\n            {\n                for(j=0;j<n;j++) if(i!=j&&(k&(1<<j))!=0)\n                {\n                    f[k^(1<<j)]+=f[k]*p[i][j]/((cnt-1)*cnt/2);\n                }\n            }\n        }\n    }\n    \n    public static void main(String[] args){\n  \n        Scanner S=new Scanner(System.in);\n        while(S.hasNext())\n        {\n            n=S.nextInt();\n            int i,j;\n            for(i=0;i<n;i++) for(j=0;j<n;j++) p[i][j]=S.nextDouble();\n            DP();\n            for(i=0;i<n;i++) \n            {\n                if(i!=0) PR(\" \");\n                PR(f[1<<i]);\n            }\n            PR(\"\\n\");\n        }\n    }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.text.*;\nimport java.math.*;\n\npublic class Main{\n    \n    static double EPS=1e-10;\n    static double PI=Math.acos(-1.0);\n    \n    static double p[][]=new double[25][25];\n    static double f[]=new double[1<<20];\n    static int n;\n    \n    \n    public static void PR(String s){\n        System.out.print(s);\n    }\n    \n    public static void PR(double s)\n    {\n        java.text.DecimalFormat d=new java.text.DecimalFormat(\"#.0000000\");\n        System.out.print(d.format(s));\n    }\n    \n    public static void DP()\n    {\n        int i,j,k,cnt;\n        for(i=0;i<(1<<n);i++) f[i]=0;\n        f[(1<<n)-1]=1;\n        for(k=(1<<n)-1;k>=0;k--)\n        {\n            cnt=0;\n            for(i=0;i<n;i++) if((k&(1<<i))!=0) cnt++;\n            for(i=0;i<n;i++) if((k&(1<<i))!=0)\n            {\n                for(j=0;j<n;j++) if(i!=j&&(k&(1<<j))!=0)\n                {\n                    f[k^(1<<j)]+=f[k]*p[i][j]/((cnt-1)*cnt/2);\n                }\n            }\n        }\n    }\n    \n    public static void main(String[] args){\n  \n        Scanner S=new Scanner(System.in);\n        while(S.hasNext())\n        {\n            n=S.nextInt();\n            int i,j;\n            for(i=0;i<n;i++) for(j=0;j<n;j++) p[i][j]=S.nextDouble();\n            DP();\n            for(i=0;i<n;i++) \n            {\n                if(i!=0) PR(\" \");\n                PR(f[1<<i]);\n            }\n            PR(\"\\n\");\n        }\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.text.DecimalFormat;\nimport java.util.Scanner;\n\n/**\n *\n * @author Alvaro\n */\npublic class Main{\n    public static int n;\n    public static double [] dp;\n    public static double [][] p;\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        n = in.nextInt();\n        dp = new double[1<<n];\n        p = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                p[i][j]= in.nextDouble();                \n            }\n        }\n        for (int i = 0; i <(1<<n); i++) {\n            dp[i] = -1;            \n        }\n        dp[(1<<n)-1]=1;\n        DecimalFormat d = new DecimalFormat(\"0.000000\");\n        System.out.print(d.format(f(1<<0)));\n        for (int i = 1; i < n; i++) {\n            System.out.print(\" \"+d.format(f(1<<i)));\n        }\n    }\n    \n    public static double f(int mask) {\n        if(dp[mask]>-0.5) return dp[mask];\n        dp[mask] = 0;\n        int vivos = 1;\n        for (int i = 0; i < n; i++) \n            if((mask>>i)%2==1) vivos++;\n        double pares = (vivos*(vivos-1))/2;\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if((mask&(1<<i))!=0&&(mask&(1<<j))==0){\n                    dp[mask]+=f(mask|(1<<j))*p[i][j]/pares;\n                }\n            }\n            \n        }\n        return dp[mask];\n                \n    }\n       \n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.HashMap;\nimport java.util.Scanner;\n\nimport javax.swing.text.html.HTMLDocument.Iterator;\n\n\npublic class Main\n{\n    public static double p[];\n    static double s[];\n    static double m[];\n    static int n;\n    public static double a[][];\n    public static int index=0;\n    public static boolean vis[];\n    public static HashMap<Integer, Integer> permMap;\n\n    public static void main(String g[])\n    {\n\n        Scanner sc = new Scanner(System.in);\n        n=sc.nextInt();\n        m = new double[(1<<n) +1];\n        vis = new boolean[(1<<n) +1];\n        a = new double[n][n];\n\n        for(int i=0;i<n;i++)\n                {\n            for(int j=0;j<n;j++)\n            {\n                //System.out.println(\"read\"+(c++));\n                a[i][j] = sc.nextDouble();\n            }\n                }\n\n        s = new double[1<<n]; // 2^n\n        int perm=0;\n        m[0]=1;\n        p();\n\n//      System.out.println(\"answers : \");\n\n        int c=((1<<n)-1);\n        for(int i=0;i<n;i++)\n        {\n            perm = c-(1<<i);\n//          System.out.printf(\"permutation = %x, prob = %f\\n\",perm,m[perm]);\n            System.out.printf(\"%.6f \",m[perm]);\n        }\n//      getPerms(0);\n//      p(perm);\n\n//      double res[] = new double[n];\n//      for(int i=0;i<n;i++)\n        {\n//          for(int j=0;j<n;j++)\n//          if((i&(i-1))!=0)\n//              continue;\n\n//          res[i] =\n//              p(perm,n);\n//          System.out.println(m[i][j]);\n        }\n\n//      int cur=(1<<n)-1;\n//\n//int i=0;\n//      for(i=0;i<n;i++)\n//      {\n//          int val=(cur-(1<<i));\n//          int L = n-1;\n//          System.out.printf(\"running for %x .... P = %f\\n\",val,getProb(val,L));\n//\n//      }\n\n        //getP((1<<n)-1));\n\n//      for(int i=0;i<m.length;i++)\n//      {\n//          System.out.println(m[perm]);\n//      }\n\n\n    }\n\n\n\n    public static void p()\n    {\n        \n            for(int k=0;k<(1<<n);k++)\n            {\n                \n                int perm=k;\n        for(int j=0;j<n;j++)\n        {\n\n            if(bitTest(perm, j))\n            {\n                continue;\n            }\n\n            int newPerm=perm|(1<<j);    // j got eaten\n\n            for(int i=0;i<n;i++)\n            {\n                if( (i==j) || bitTest(newPerm,i))\n                {\n                    continue;\n                }\n                // i eats j\n\n                int  L=n-countO(perm);\n                if(L<2)\n                {\n                    continue;\n                }\n                //System.out.println(\"L=\"+L);\n                double pm = 2.0/(L*(L-1));\n\n\n\n//              System.out.printf(\"Left with %d,%d eats %d \\n\",L,i,j);\n                m[newPerm]+=m[perm]*a[i][j]*pm;\n//              System.out.printf(\"p(%x)= %f \\n\",newPerm,m[newPerm]);\n                //System.out.printf(\"p(%x)= %f \\n\",newPerm2,m[newPerm2]);\n            }\n//          System.out.printf(\"p(%x)= %f \\n\",newPerm,m[newPerm]);\n//          System.out.println(\"here-------------------->\");\n\n        }\n\n            }\n        \n\n    }\n\n\n    private static int countO(int marked) {\n        // TODO Auto-generated method stub\n\n        int count=0;\n        for(int i=0;i<n;i++)\n        {\n            int test = (1<<i);\n            if((test&marked)==(test))\n                count++;\n        }\n        return count;\n    }\n\n    private static boolean bitTest(int perm, int i) {\n        // TODO Auto-generated method stub\n        int test = (1<<i);\n        if((test&perm)==test)\n            return true;\n        return false;\n    }\n\n    private static int bitSet(int perm, int i) {\n        // TODO Auto-generated method stub\n        int np = (1<<i);\n        return np;\n    }\n\n}\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class Main\n{\n    static double arr[][];\n    public static void main(String[] args)\n    {\n        try\n        {\n            Parserdoubt pd=new Parserdoubt(System.in);\n            PrintWriter pw=new PrintWriter(System.out);\n            int fishes=pd.nextInt();\n            arr=new double[fishes][fishes];\n            for(int i=0;i<fishes;i++)\n                for(int j=0;j<fishes;j++)\n                    arr[i][j]=Double.parseDouble(pd.nextString());\n            double dp[]=new double[(1<<fishes)];\n            dp[dp.length-1]=1.0;\n            for(int c=dp.length-1;c>=0;c--)\n            {\n                \n                if((c&(c-1))==0)\n                    continue;\n                for(int i=0;i<fishes;i++)\n                    for(int j=i+1;j<fishes;j++)\n                    {\n                        if(((1<<i)&c)!=0&&((1<<j)&c)!=0)\n                        {\n                            dp[c&~(1<<j)]+=arr[i][j]*dp[c];\n                            dp[c&~(1<<i)]+=arr[j][i]*dp[c];\n                        }\n                    }\n            }\n            double s=0.0;\n            for(int i=0;i<fishes;i++)\n                s+=dp[1<<i];\n            for(int i=0;i<fishes;i++)\n                dp[1<<i]/=s;\n            int i=0;\n            for(i=0;i<fishes-1;i++)\n                pw.printf(\"%.6f \",dp[1<<i]);\n            pw.printf(\"%.6f\\n\",dp[1<<i]);\n            pw.close();\n        }\n        catch(Exception e)\n        {}\n    }\n}\nclass Parserdoubt\n    {\n       final private int BUFFER_SIZE = 1 << 17;\n\n       private DataInputStream din;\n       private byte[] buffer;\n       private int bufferPointer, bytesRead;\n\n       public Parserdoubt(InputStream in)\n       {\n          din = new DataInputStream(in);\n          buffer = new byte[BUFFER_SIZE];\n          bufferPointer = bytesRead = 0;\n       }\n       public String nextString() throws Exception\n       {\n           StringBuffer sb=new StringBuffer(\"\");\n           byte c = read();\n           while (c <= ' ') c = read();\n           do\n           {\n               sb.append((char)c);\n               c=read();\n           }while(c>' ');\n           return sb.toString();\n       }\n       public char nextChar() throws Exception\n       {\n           byte c=read();\n           while(c<=' ') c= read();\n           return (char)c;\n       }\n       public int nextInt() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       public long nextLong() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       private void fillBuffer() throws Exception\n       {\n          bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n          if (bytesRead == -1) buffer[0] = -1;\n       }\n\n       private byte read() throws Exception\n       {\n          if (bufferPointer == bytesRead) fillBuffer();\n          return buffer[bufferPointer++];\n       }\n    }\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/14/11\n * Time: 9:53 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 Fish extends Thread {\n\n    public Fish() {\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    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        double[][] a = new double[n][n];\n        double[] dp = new double[(1 << n)];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        }\n        int limit = (1 << n) - 1;\n        //dp[mask] = probability of current subset (mask) to remain in the end\n        dp[limit] = 1.0;\n        for (int mask = limit; mask > 0; --mask) {\n            int cardinality = getOnes(mask);\n            int probability = cardinality * (cardinality - 1) / 2;\n            for (int first = 0; first < n; ++first) {\n                if ((mask & powers[first]) != 0) {\n                    for (int second = first + 1; second < n; ++second) {\n                        if ((mask & powers[second]) != 0) {\n                            dp[mask - powers[first]] += dp[mask] * a[second][first] / probability;\n                            dp[mask - powers[second]] += dp[mask] * a[first][second] / probability;\n                        }\n\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            output.printf(\"%.10f \", dp[powers[i]]);\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\n    public static void main(String[] args) {\n        new Fish().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    static final int powers[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\n/**\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 java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.Exchanger;\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        solve();\n        br.close();\n        out.close();\n    }\n    double dm[];\n    double a[][];\n    boolean fil[];\n    int p[];\n    int n;\n    // x & (x - 1)\n    // 10\n    //\n    void solve() throws  IOException {\n        n = nextInt();\n        a = new double[n][n];\n        for(int i = 0; i < n; ++i)\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        dm = new double[1 << n];\n        dm[(1 << n) - 1] = 1;\n        for(int mask = (1 << n) - 1; mask >= 1; --mask) {\n            int c = Integer.bitCount(mask);\n            if (c == 1) continue ;\n            double p = 2.0 / (double)(c - 1) / (double) c;\n            for(int i = 0; i < n; ++i) {\n                for (int j =0 ; j < n; ++j) {\n                    if (i != j && (mask & (1 << i)) > 0 && (mask & (1 << j)) > 0) {\n                        dm[mask ^ (1 << j)] += a[i][j] * dm[mask] * p;\n                    }\n                }\n            }\n        }\n        for(int i = 0; i < n; ++i) {\n            out.print(dm[1 << i] + \" \");\n        }\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}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class E\n{\n   public static void main(String[] args)\n   {\n      new E(new Scanner(System.in));\n   }\n\n\n   public E(Scanner in)\n   {\n      int N = in.nextInt();\n      double[][] g = new double[N][N];\n\n      for (int j=0; j<N; j++)\n         for (int i=0; i<N; i++)\n            g[i][j] = in.nextDouble();\n\n      double[] memo = new double[1<<N];\n      memo[(1<<N)-1] = 1.0;\n      \n      for (int m=(1<<N)-1; m>0; m--)\n      {\n         int cnt = 0;\n         for (int i=0; i<N; i++)\n         {\n            int m1 = 1 << i;\n            if ((m1&m) > 0)\n               cnt++;\n         }\n\n         int sum = (cnt*(cnt-1))/2;\n         for (int i=0; i<N; i++)\n         {\n            int m1 = 1 << i;\n            if ((m1&m) == 0) continue;\n\n            for (int j=i+1; j<N; j++)\n            {\n               int m2 = 1 << j;\n               if ((m2&m) == 0) continue;\n               \n               memo[m-m1] += (g[i][j]*memo[m])/sum;\n               memo[m-m2] += (g[j][i]*memo[m])/sum;\n            }\n         }\n      }\n\n      StringBuilder sb = new StringBuilder();\n      for (int i=0; i<N; i++)\n      {\n         double res = memo[1<<i];\n         sb.append(String.format(\"%.8f\", res));\n         sb.append(' ');\n      }\n      System.out.println(sb.toString().trim());\n   }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.regex.*;\n\n/**\n *\n * @author jon\n */\npublic class Fish {\n    double memo[] = new double[(1<<18)];\n    int N, FULL;\n    double prob[][] = new double[18][18];\n    Fish() {\n        Scanner in = new Scanner(System.in);\n        Arrays.fill(memo, -1);\n\n        N = in.nextInt();\n        FULL = (1<<N) - 1;\n\n        for(int i = 0; i < N; i++) {\n            for(int j = 0; j < N; j++) {\n                prob[i][j] = in.nextDouble();\n            }\n        }\n\n        for(int i = 0; i < N; i++) {\n            System.out.printf(\"%.6f \", go((1<<i)));\n        }\n        System.out.println();\n\n\n\n    }\n    public double go(int mask) {\n        if(mask == FULL) return 1.0;\n        if(memo[mask] >= 0) return memo[mask];\n        double ret = 0;\n        double mult = Integer.bitCount(mask) + 1;\n        mult *= (mult-1)/2.0;\n\n\n        for(int i = 0; i < N; i++) {\n            if(((1<<i) & mask) != 0) {\n                for(int j = 0; j < N; j++) {\n                    if(((1<<j) & mask) == 0) {\n                        ret += go(mask | (1<<j)) * prob[i][j];\n                    }\n                }\n            }\n        }\n        ret /= mult;\n\n        memo[mask] = ret;\n        return ret;\n    }\n    public static void main(String args[]) {\n        new Fish();\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "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 double[][] a;\n\tstatic int N;\n\tstatic double[][] memo;\n \n\tstatic double[] dp(int alive)\n\t{\n\t\tint count = Integer.bitCount(alive);\n\t\tif(count == 1)\n\t\t{\n\t\t\tdouble[] ret = new double[N];\n\t\t\tfor(int i = 0; i < N; ++i)\n\t\t\t\tif((alive & (1<<i)) != 0)\n\t\t\t\t{\n\t\t\t\t\tret[i] = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\treturn memo[alive] = ret;\n\t\t}\n\t\tif(memo[alive] != null)\n\t\t\treturn memo[alive];\n\t\t\n\t\tdouble[] ret = new double[N];\n\t\tfor(int j = 0; j < N; ++j)\n\t\t\tif((alive & (1<<j)) != 0)\n\t\t\t{\n\t\t\t\tdouble[] nxt = dp(alive & ~(1<<j));\n\t\t\t\tfor(int i = 0; i < N; ++i)\n\t\t\t\t\tret[i] += die[j][alive] * nxt[i];\t\t\t\n\t\t\t}\n\t\treturn memo[alive] = ret;\n\t}\n \n\tstatic double[][] die;\n\tstatic void f()\n\t{\n\t\tdie = new double[N][1<<N];\n\t\tfor(int i = 0; i < N; ++i)\n\t\t\tfor(int j = 0; j < 1<<N; ++j)\n\t\t\t{\n\t\t\t\tint count = Integer.bitCount(j);\n\t\t\t\tif(count <= 1)\n\t\t\t\t\tcontinue;\n\t\t\t\tdouble prop = 1.0 / (count * (count - 1) >> 1);\n\t\t\t\tfor(int k = 0; k < N; ++k)\n\t\t\t\t\tif((j & (1<<k)) != 0)\n\t\t\t\t\t\tdie[i][j] += prop * a[k][i]; \n\t\t\t}\n \n\t}\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\tN = sc.nextInt();\n\t\t\n\t\ta = new double[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\ta[i][j] = sc.nextDouble();\n\t\tmemo = new double[1<<N][];\n\t\t\n\t\tf();\n\t\t\n\t\tdouble[] ret = dp((1<<N) - 1);\n\t\tfor(int i = 0; i < N - 1; ++i)\n\t\t\tout.printf(\"%.8f \",ret[i]);\n\t\tout.printf(\"%.8f\\n\", ret[N-1]);\n \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){  br = 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 double nextDouble() throws NumberFormatException, IOException\n\t\t{\n\t\t\treturn Double.parseDouble(next());\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 boolean ready() throws IOException {return br.ready();}\n\n\n\t}\n} ", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\n    private int n;\n    private double[] dp;\n    private double[][] p;\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        n = in.nextInt();\n        p = new double[n][n];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                p[i][j] = in.nextDouble();\n            }\n        }\n        dp = new double[1 << n];\n        Arrays.fill(dp, -1);\n        for (int i = 0; i < n; ++i) {\n            out.printf(\"%.6f \", rec(1 << i));\n        }\n        out.println();\n    }\n\n    private double rec(int mask) {\n        if (mask == (1 << n) - 1) return 1;\n        if (dp[mask] > -0.5) return dp[mask];\n        double res = 0;\n        int nn = Integer.bitCount(mask);\n        int total = (nn * (nn + 1)) / 2;\n        for (int i = 0; i < n; ++i) if (BitUtils.checkBit(mask, i)) for (int j = 0; j < n; ++j) if (!BitUtils.checkBit(mask, j)) {\n            res += rec(BitUtils.setBit(mask, j)) * p[i][j];\n        }\n        res /= total;\n        dp[mask] = res;\n        return res;\n    }\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer stt;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n    }\n\n    public String nextLine() {\n        try {\n            return reader.readLine().trim();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    public String nextString() {\n        while (stt == null || !stt.hasMoreTokens()) {\n            stt = new StringTokenizer(nextLine());\n        }\n        return stt.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextString());\n    }\n\n    public double nextDouble() {\n        return Double.parseDouble(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    public static int setBit(int mask, int bit) {\n        return (mask | (1 << bit));\n    }\n\n}\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class e{\n  int n;\n  double f[];\n  double a[][];\n\n  public void run(){\n    Locale.setDefault(Locale.US);\n    Scanner in = new Scanner(System.in);\n    n = in.nextInt();\n    a = new double[n][n];\n    for(int i=0;i<n;i++) for(int j=0;j<n;j++) a[i][j] = in.nextDouble();\n    f = new double[1<<n];\n    for(int i=0;i<1<<n;i++) f[i] = -1;\n    f[(1<<n)-1] = 1.0;\n    \n    for(int i=0;i<n;i++) System.out.print(doIt(1<<i) + \" \");\n  }\n\n  private double doIt(int mask){\n    if (f[mask] >=0) return f[mask];\n    f[mask] = 0;\n    double k = getBits(mask);\n    k*=(k-1)/2.0;\n\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            f[mask]+=doIt(mask|(1<<j))*a[i][j]/k;\n    return f[mask]; \n  }\n  private int getBits(int x){\n    int cnt = 0;\n    while(x > 0){\n      x&=(x-1);\n      cnt++;\n    }\n    return cnt+1;\n  }\n\n  public static void main(String args[]){\n    new e().run();\n  }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Fish\n{\n\tstatic double[][] prob= new double[18][18];\n\tstatic double[][] dp= new double[2][1<<18];\n\tstatic ArrayList<Integer>[] adj= new ArrayList[1<<18];\n\tstatic int n;\n\tpublic static void init()\n\t{\n\t\tfor(int i=0; i<(1<<18); i++)\n\t\t\tadj[i]= new ArrayList<Integer>();\n\t\tfor(int i=0; i<(1<<18); i++)\n\t\t\tfor(int j=0; j<18; j++)\n\t\t\t\tif(((i>>j)&1)==1)\n\t\t\t\t\tadj[i].add(i^(1<<j));\n\t}\n\tpublic static double value(int cur, int next)\n\t{\n\t\tint i=0;\n\t\tint z= cur^next;\n\t\tdouble p=0;\n\t\tint alive= Integer.bitCount(cur);\n\t\twhile((z>>i)!=1)\n\t\t\ti++;\n\t\tfor(int k=0; k<n; k++)\n\t\t\tif( ((next>>k)&1)==1)\n\t\t\t\tp+= prob[k][i];\n\t\tp/= alive*(alive-1)/2;\n\t\treturn p;\n\t}\n\tpublic static void main(String[] args)throws Exception\n\t{\n\t\tScanner scan= new Scanner(System.in);\n\t\tinit();\n\t\tn=scan.nextInt();\n\t\tint m= (1<<n)-1;\n\t\tfor(int i=0; i<n; i++)\n\t\t\tfor(int j=0; j<n; j++)\n\t\t\t\tprob[i][j]= scan.nextDouble();\n\t\tdp[0][m]=1;\n\t\t\n\t\tfor(int i=0; i<(n-1); i++)\n\t\t{\n\t\t\tfor(int j=0; j<=m; j++)\n\t\t\t\tif(dp[i%2][j]>0)\n\t\t\t\t\tfor(Integer next: adj[j])\n\t\t\t\t\t\tdp[(i+1)%2][next]+= value(j,next)*dp[i%2][j];\n\t\t\tArrays.fill(dp[i%2],0);\n\t\t}\n\t\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tif(i!=0)\n\t\t\tSystem.out.print(\" \");\n\t\t\tSystem.out.printf(\"%.6f\",dp[(n-1)%2][1<<i]);\t\t\n\t\t}\n\t\t\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class e {\n\tprivate void main() {\n\t\tScanner stdin = new Scanner(System.in);\n\t\tPrintStream stdout = System.out;\n\t\tint n = stdin.nextInt();\n\t\tdouble[][] p = new double[n][n];\n\t\tdouble[][] ans = new double[1<<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\tp[i][j] = stdin.nextDouble();\n\t\tdouble[] dieChance = new double[n];\n\t\tArrayList<Integer> sel = new ArrayList<Integer>();\n\t\tfor(int i = 0; i < (1<<n); i++) {\n\t\t\tsel.clear();\n\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\tif((i & (1<<k)) != 0)\n\t\t\t\t\tsel.add(k);\n\t\t\t}\n\t\t\tif(sel.size() == 1) {\n\t\t\t\tans[i][sel.get(0)] = 0;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor(int j : sel)\n\t\t\t\tdieChance[j] = 0;\n\t\t\tfor(int j : sel)\n\t\t\t\tfor(int k : sel)\n\t\t\t\t\tdieChance[k] += p[j][k];\n\t\t\tfor(int j : sel)\n\t\t\t\tdieChance[j] /= sel.size()*(sel.size()-1)/2;\n\t\t\tfor(int j : sel) {\n\t\t\t\tans[i][j] = dieChance[j];\n\t\t\t\tfor(int k : sel)\n\t\t\t\t\tans[i][j] += dieChance[k] * ans[i-(1<<k)][j];\n\t\t\t}\n\t\t}\n\t\tfor(double d : ans[(1<<n)-1])\n\t\t\tstdout.format(\"%f \", 1-d);\n\t\tstdout.println();\n\t}\n\tpublic static void main(String[] args) {\n\t\tnew e().main();\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class P16E {\n    int n;\n    double [][]prob;\n    double []dp;\n    public P16E() {\n        Scanner sc = new Scanner(System.in);\n        n = sc.nextInt();\n        prob = new double [n][n];\n        for (int i = 0; i < n; i++){\n            for (int j = 0; j < n; j++){\n                prob[i][j] = sc.nextDouble();\n            }\n        }\n        sc.close();\n\n        dp = new double[(1<<n)];\n        Arrays.fill(dp, -1);\n\n        for (int i = 0; i < n; i++) {\n            int a = 1 << i;\n            System.out.print(compute(a) + \" \");\n        }\n    }\n\n    double compute (int mask){\n        if (mask == (1<<n) - 1){\n            return 1;\n        }\n        if (dp[mask] != -1){\n            return dp[mask];\n        }\n        double result = 0;\n        int c = 0;       \n        for (int i = 0; i < n; i++) {\n            int a = 1 << i;\n            if ((a & mask) != 0) {\n                c++;\n                for (int j = 0; j < n; j++) {\n                    int b = 1 << j;\n                    if ((b & mask) == 0) {\n                        result += (prob[i][j] * compute(mask | b));\n                    }\n                }\n            }\n        }\n\n        int nC2 = (c + 1) * c / 2;\n        dp[mask] = result / nC2;\n        return dp[mask];\n\n    }\n\n    public static void main (String []args){\n        new P16E();\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\n\npublic class Main{\n    \n    static double EPS=1e-10;\n    static double PI=Math.acos(-1.0);\n    \n    static double p[][]=new double[25][25];\n    static double f[]=new double[1<<20];\n    static int n;\n    \n    \n    public static void PR(String s){\n        System.out.print(s);\n    }\n    \n    public static void PR(double s)\n    {\n        java.text.DecimalFormat d=new java.text.DecimalFormat(\"#.0000000\");\n        System.out.print(d.format(s));\n    }\n    \n    public static void DP()\n    {\n        int i,j,k,cnt;\n        for(i=0;i<(1<<n);i++) f[i]=0;\n        f[(1<<n)-1]=1;\n        for(k=(1<<n)-1;k>=0;k--)\n        {\n            cnt=0;\n            for(i=0;i<n;i++) if((k&(1<<i))!=0) cnt++;\n            for(i=0;i<n;i++) if((k&(1<<i))!=0)\n            {\n                for(j=0;j<n;j++) if(i!=j&&(k&(1<<j))!=0)\n                {\n                    f[k^(1<<j)]+=f[k]*p[i][j]/((cnt-1)*cnt/2);\n                }\n            }\n        }\n    }\n    \n    public static void main(String[] args){\n  \n        Scanner S=new Scanner(System.in);\n        while(S.hasNext())\n        {\n            n=S.nextInt();\n            int i,j;\n            for(i=0;i<n;i++) for(j=0;j<n;j++) p[i][j]=S.nextDouble();\n            DP();\n            for(i=0;i<n;i++) \n            {\n                if(i!=0) PR(\" \");\n                PR(f[1<<i]);\n            }\n            PR(\"\\n\");\n        }\n    }\n}\n  \t      \t    \t\t\t  \t\t \t\t", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    public static void main(String[] args) throws Exception {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(System.out);\n\n        int n = nextInt();\n        double[][] a = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                a[i][j] = nextDouble();\n            }\n        }\n        double[] dp = new double[1 << n];\n        dp[(1 << n) - 1] = 1.0;\n        for (int mask = (1 << n) - 2; mask > 0; mask--) {\n            int count = Integer.bitCount(mask);\n            double pPair = 2.0 / (count * (count + 1));\n            double ans = 0.0;\n            for (int i = 0; i < n; i++) {\n                if (((1 << i) & mask) == 0) {\n                    double p = dp[(1 << i) | mask];\n                    double s = 0.0;\n                    for (int j = 0; j < n; j++) {\n                        if (((1 << j) & mask) != 0)\n                            s += a[j][i];\n                    }\n                    ans += pPair * p * s;\n                }\n            }\n            dp[mask] = ans;\n        }\n\n        for (int i = 0; i < n; i++) {\n            out.print(dp[1 << i]);\n            out.print(' ');\n        }\n        \n        in.close();\n        out.close();\n    }\n\n    static StringTokenizer st;\n    static BufferedReader in;\n    static PrintWriter out;\n\n    static int nextInt() throws IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    static double nextDouble() throws IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    static String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\npublic static void main(String [] args){\n\tScanner in=new Scanner(System.in);\n\tint n=in.nextInt();\n\tdouble value[][]=new double[n][n];\n\tfor(int i=0;i<n;i++)\n\t\tfor(int j=0;j<n;j++)value[i][j]=in.nextDouble();\n\t\tdouble ans[]=new double[1<<n];\n\t\tint mask=(1<<n);\n\t\tans[(1<<n)-1]=1.0;\n\t\tfor(int i=mask-1;i>=0;i--){\n\t\tint cnt=Integer.bitCount(i);\n\t\tint pairs=cnt*(cnt-1)/2;\n\t\tfor(int j=0;j<n;j++){\n\t\tif(((i>>j)&1)==0)continue;\n\t\tfor(int k=j+1;k<n;k++){\n\t\tif(((i>>k)&1)==0)continue;\n\t\tans[i^(1<<k)]+=ans[i]*value[j][k]/pairs;\n\t\tans[i^(1<<j)]+=ans[i]*value[k][j]/pairs;\n\t\t}\n\t\t}\n\t\t}\n\t\tfor(int i=0;i<n;i++)\n\t\t\tSystem.out.print(ans[1<<i]+\" \");\n\t\t\n}\n}\n    ", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\n    InputReader input;\n    PrintWriter output;\n\n    void run(){\n        output = new PrintWriter(new OutputStreamWriter(System.out));\n        input = new InputReader(System.in);\n        solve();\n        output.flush();\n    }\n\n    public static void main(String[] args){\n        new Main().run();\n    }\n    \n    \n    boolean isBitSet(int mask, int i) {\n        return (mask&(1<<i)) != 0;\n    }\n    \n    int unSet(int mask, int i) {\n        return mask & ~(1<<i);\n    }\n    \n    void solve() {\n        int n = input.ni();\n        double[][] prb = new double[n][n];\n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < n; j++) {\n                prb[i][j] = input.readDouble();\n            }\n        }\n        double[] dp = new double[1<<n];\n        dp[0] = 1.0;\n        for(int i = 0; i < 1<<n; i++) {\n            int remaining = n-Integer.bitCount(i);\n            double remainingProbability = remaining*(remaining-1)/2;\n            for(int j = 0; j < n; j++) {\n                if(!isBitSet(i, j)) {   //jth fish is alive\n                    for(int k = 0; k < n; k++) {    //candidates to kill jth fish\n                        if(!isBitSet(i, k))\n                            dp[i|(1<<j)] += dp[i]*prb[k][j]/(remainingProbability);\n                    }\n                }\n            }\n        }\n        for(int i = 0; i < n; i++) {\n            output.printf(\"%.7f \",dp[unSet((1<<n)-1, i)]);\n        }\n        output.println();\n    }\n\n\n    class InputReader {\n        private boolean finished = false;\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n                this.stream = stream;\n        }\n\n        public int read() {\n                if (numChars == -1)\n                        throw new InputMismatchException();\n                if (curChar >= numChars) {\n                        curChar = 0;\n                        try {\n                                numChars = stream.read(buf);\n                        } catch (IOException e) {\n                                throw new InputMismatchException();\n                        }\n                        if (numChars <= 0)\n                                return -1;\n                }\n                return buf[curChar++];\n        }\n\n        public int peek() {\n                if (numChars == -1)\n                        return -1;\n                if (curChar >= numChars) {\n                        curChar = 0;\n                        try {\n                                numChars = stream.read(buf);\n                        } catch (IOException e) {\n                                return -1;\n                        }\n                        if (numChars <= 0)\n                                return -1;\n                }\n                return buf[curChar];\n        }\n\n        public int 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    }\n     public interface SpaceCharFilter {\n         public boolean isSpaceChar(int ch);\n     }\n\n}\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "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 Ideone\n{\nstatic double p[][];\n    static double dp[];\n    static int n;\n \n    public static int BitCount(int u) {\n        int uCount;\n \n        uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);\n        return ((uCount + (uCount >> 3)) & 030707070707) % 63;\n    }\n \n    public static double f(int mask) {\n        if (dp[mask] > -0.5)\n            return dp[mask];\n \n        dp[mask] = 0;\n \n        int ones = BitCount(mask);\n        double pairs = (((ones * (ones + 1))) >> 1);\n        //System.out.println(pairs);\n \n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if ((mask & (1 << i)) != 0 && (mask & (1 << j)) == 0)\n                    dp[mask] += f(mask | (1 << j)) * p[i][j] / pairs;\n            }\n        }\n \n        return dp[mask];\n    }\n \n    public static void main(String[] args) throws NumberFormatException,\n            IOException {\n        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n        n = Integer.parseInt(bf.readLine());\n        p = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            StringTokenizer st = new StringTokenizer(bf.readLine());\n            for (int j = 0; j < n; j++) {\n                p[i][j] = Double.parseDouble(st.nextToken());\n            }\n        }\n \n        dp = new double[1 << n];\n \n        Arrays.fill(dp, -1.0);\n \n        dp[(1 << n) - 1] = 1.;\n \n        for (int i = 0; i < n - 1; i++) {\n            System.out.print(f(1 << i) + \" \");\n        }\n \n        System.out.println(f((1 << (n - 1))));\n \n    }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/**\n * Codeforces Beta Round 16\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 CF16E {\n  private void solve(InputReader in, PrintWriter out) {\n    int n = in.nextInt();\n    double[][] prob = new double[n][n];\n    for (int i = 0; i < n; i++) {\n      for (int j = 0; j < n; j++) {\n        prob[i][j] = in.nextDouble();\n      }\n    }\n    int[] fish = new int[n];\n    for (int i = 0; i < n; i++) {\n      fish[i] = 1 << i;\n    }\n\n    double[] res = new double[1 << n];\n    res[0] = 1.0;\n    for (int mask = 1; mask < (1 << n) - 1; mask++) {\n      for (int i = 0; i < n; i++) {\n        if ((mask & fish[i]) == 0) {\n          continue;\n        }\n        int lastMask = mask ^ fish[i];\n        int live = n;\n        for (int j = 0; j < n; j++) {\n          if ((lastMask & fish[j]) != 0) {\n            live--;\n          }\n        }\n        double p = 0.0;\n        for (int j = 0; j < n; j++) {\n          if ((lastMask & fish[j]) != 0 || j == i) {\n            continue;\n          }\n          p += prob[j][i];\n        }\n        res[mask] += res[lastMask] * p * 2 / live / (live - 1);\n      }\n    }\n    for (int i = 0; i < n; i++) {\n      out.printf(\"%.6f \", res[((1 << n) - 1) ^ fish[i]]);\n    }\n  }\n\n  public static void main(String[] args) {\n    InputReader in = new InputReader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n    new CF16E().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    public double nextDouble() {\n      return Double.parseDouble(next());\n    }\n  }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n \n \npublic class Main {\n\tstatic int n, exp;\n\tstatic double arr[][],dp[], dies[][];\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tn = new Integer(br.readLine());\n\t\tarr = new double[n][n];\n\t\tStringTokenizer st;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tarr[i][j] = Double.parseDouble(st.nextToken());\n\t\t\t}\n\t\t}\n\t\texp = 1<<n;\n\t\tdp = new double[exp];\n\t\tdies = new double[n][exp];\n\t\tfor (int all = 0; all < exp; all++) {\n\t\t\tdp[all] = -1;\n\t\t\tint countAlive = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif((all&(1<<i))!=0)\n\t\t\t\t\tcountAlive++;\n\t\t\t}\n\t\t\tif(countAlive <2)continue;\n\t\t\tdouble x=1.0/(countAlive*(countAlive-1)/2.0);\n\t\t\tfor(int i=0; i<n; i++){\n\t\t\t\tdies[i][all]=0;\n\t\t\t\tint mask=1<<i;\n\t\t\t\tif((mask&all)>0){\n\t\t\t\t\tfor(int j=0; j<n; j++)\n\t\t\t\t\t{\n\t\t\t\t\t\tint mask2=1<<j;\n\t\t\t\t\t\tif((mask2&all)>0)\n\t\t\t\t\t\t\tdies[i][all]+=arr[j][i];\n\t\t\t\t\t}\n\t\t\t\t\tdies[i][all]*=x;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int myFish=0; myFish<n; myFish++){\n\t\t\tif(myFish>0)System.out.printf(\" \");\n\t\t\tSystem.out.printf(\"%.6f\",ff(1<<myFish));\n\t\t}\n\t\tSystem.out.println();\t\n \n\t}\n\tstatic double ff(int state){\n\t\tif(state==exp-1)return 1;\n\t\tif(dp[state]!=-1)return dp[state];\n\t\tdouble ans=0;\n\t\tfor(int i=0; i<n; i++)\n\t\t{\n\t\t\tint mask=1<<i;\n\t\t\tif((mask &state)==0)\n\t\t\t{\n\t\t\t\tans+=dies[i][state+mask]*ff(state+mask);\n\t\t\t}\n\t\t}\n\t\treturn dp[state]=ans;\n\t}\n \n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Locale;\nimport java.util.Scanner;\n\n\npublic class E {\n\n    public static void main(String[] args) {\n        Locale.setDefault(Locale.US);\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        double[][]p = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                p[i][j] = sc.nextDouble();\n            }\n        }\n        double[]dp = new double[1<<n];\n        dp[(1 << n)-1] = 1;\n        for (int mask = (1 << n)-1; mask > 0; mask--) {\n            int t = Integer.bitCount(mask);\n            if (t==1)\n                continue;\n            double p0 = 1.0/(t*(t-1)/2);\n            for (int i = 0; i < n; i++) {\n                if ((mask & (1 << i)) != 0) {\n                    for (int j = 0; j < n; j++) {\n                        if (j != i && (mask & (1 << j)) != 0)\n                            dp[(mask ^ (1 << i))] += dp[mask] * p[j][i]*p0;\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            System.out.print(dp[1 << i]+\" \");\n        }\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.regex.*;\n\n/**\n *\n * @author jon\n */\npublic class Fish {\n    double memo[] = new double[(1<<18)];\n    int N, FULL;\n    double prob[][] = new double[18][18];\n    Fish() {\n        Scanner in = new Scanner(System.in);\n        Arrays.fill(memo, -1);\n\n        N = in.nextInt();\n        FULL = (1<<N) - 1;\n\n        for(int i = 0; i < N; i++) {\n            for(int j = 0; j < N; j++) {\n                prob[i][j] = in.nextDouble();\n            }\n        }\n\n        for(int i = 0; i < N; i++) {\n            System.out.printf(\"%.6f \", go((1<<i)));\n        }\n        System.out.println();\n\n\n\n    }\n    public double go(int mask) {\n        if(mask == FULL) return 1.0;\n        if(memo[mask] >= 0) return memo[mask];\n        double ret = 0;\n        double mult = Integer.bitCount(mask) + 1;\n        mult *= (mult-1)/2.0;\n//        double k = getBits(mask);\n//        System.out.println(k + \" \" + mult);\n//        k *= (k-1)/2.0;\n\n        for(int i = 0; i < N; i++) {\n            if(((1<<i) & mask) != 0) {\n                for(int j = 0; j < N; j++) {\n                    if(((1<<j) & mask) == 0) {\n                        ret += go(mask | (1<<j)) * prob[i][j] / mult;\n                    }\n                }\n            }\n        }\n        //ret /= (double)mult;\n\n        memo[mask] = ret;\n        return ret;\n    }\n  private int getBits(int x){\n    int cnt = 0;\n    while(x > 0){\n      x&=(x-1);\n      cnt++;\n    }\n    return cnt+1;\n  }\n    public static void main(String args[]) {\n        new Fish();\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Locale;\n\npublic class E16 {\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 double nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn 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\t\t\n\t\tn = nextInt();\n\t\tt = 1 << n;\n\t\tm = new double[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\tm[i][j] = nextDouble();\n\t\t\n\t\tmemo = new double[t];\n\t\tArrays.fill(memo, Double.POSITIVE_INFINITY);\n\t\tfor (int i = 0; i < n; i++) out.print(String.format(Locale.US, \"%.6f\", solve(1 << i)) + \" \");\n\t\tout.println();\n\t\t\n\t\tout.flush();\n\t}\n\t\n\tstatic int n, t;\n\tstatic double[][] m;\n\tstatic double[] memo;\n\t\n\tstatic double solve(int mask) {\n\t\tif (memo[mask] != Double.POSITIVE_INFINITY) return memo[mask];\n\t\tif (mask == t-1) return memo[mask] = 1;\n\t\t\n\t\tint k = Integer.bitCount(mask);\n\t\tk = (k+1)*k/2;\n\t\tdouble res = 0;\n\t\tfor (int i = 0; i < n; i++) if ((mask&(1 << i)) != 0)\n\t\t\tfor (int j = 0; j < n; j++) if ((mask&(1 << j)) == 0)\n\t\t\t\tres += m[i][j]*solve(mask|(1 << j));\n\t\t\n\t\treturn memo[mask] = res/k;\n\t}\n}\n\n\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class Fish {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        in.useLocale(Locale.US);\n        int n = in.nextInt();\n\n        double[] dp = new double[1 << n];\n        Arrays.fill(dp, 0);\n        dp[(1 << n) - 1] = 1;//?\n\n        double[][] prob = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                prob[i][j] = in.nextDouble();\n            }\n        }\n\n        \n        for (int t = (1 << n) - 1; t >= 0; t--) {\n            int k = Integer.bitCount(t);\n            for (int i = 0; i < n; i++) {\n                if ((t & (1 << i)) > 0) {\n                    for (int j = 0; j < n; j++) {\n                        if ((t & (1 << j)) > 0) {\n                            if (i != j) {\n                                dp[t - (1 << j)] += dp[t] * prob[i][j] / (k*(k-1)/2);\n                            }\n                        }\n                    }\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            System.out.print(dp[1 << i] + \" \");\n        }\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF16E {\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\tdouble[][] aa = new double[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\taa[i][j] = Double.parseDouble(st.nextToken());\n\t\t}\n\t\tdouble[][] pp = new double[1 << n][n];\n\t\tfor (int k = 0; k < n; k++)\n\t\t\tpp[1 << k][k] = 1;\n\t\tfor (int b = 1; b < 1 << n; b++) {\n\t\t\tint c = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((b & 1 << i) == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tc++;\n\t\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\t\tif ((b & 1 << j) == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int k = 0; k < n; k++) {\n\t\t\t\t\t\tif ((b & 1 << k) == 0)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tpp[b][k] += aa[i][j] * pp[b ^ 1 << j][k];\n\t\t\t\t\t \tpp[b][k] += aa[j][i] * pp[b ^ 1 << i][k];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (c > 1) {\n\t\t\t\tdouble p = (double) c * (c - 1) / 2;\n\t\t\t\tfor (int k = 0; k < n; k++)\n\t\t\t\t\tpp[b][k] /= p;\n\t\t\t}\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint b = (1 << n) - 1;\n\t\tfor (int k = 0; k < n; k++)\n\t\t\tsb.append(pp[b][k]).append(k == n - 1 ? '\\n' : ' ');\n\t\tSystem.out.print(sb);\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/*\n\tAuthor\t:\tImran Khan\n\tLanguage:\tJava\n\t\n*/\n\nimport java.io.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic class BasicInputOutput\n\t{\n\n\t\tprivate StringTokenizer strtoken;\n\t\tprivate BufferedReader bufferReader;\n\t\tprivate BufferedWriter bufferWriter;\n\t\tprivate String delim = \" \\t\\n\\r\\f\";\n\t\tBasicInputOutput()\n\t\t{\n\t\t\tdelim = \" \\t\\n\\r\\f\";\n\t\t\tinitialize();\n\t\t}\n\t\tBasicInputOutput( String s )\n\t\t{\n\t\t\tdelim = s;\n\t\t\tinitialize();\n\t\t}\n\t\tprivate void initialize()\n\t\t{\n\t\t\tbufferReader = new BufferedReader( new InputStreamReader( System.in ));\n\t\t\tbufferWriter = new BufferedWriter( new PrintWriter( System.out ));\n\t\t\tstrtoken = null;\n\t\t}\n\t\tprivate void checkStringTokenizer()throws IOException\n\t\t{\n\t\t\tif ( strtoken == null || strtoken.hasMoreTokens() == false )\n\t\t\t\tstrtoken = new StringTokenizer( bufferReader.readLine(), delim );\n\t\t}\n\t\tpublic int getNextInt()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Integer.parseInt( strtoken.nextToken());\n\t\t}\n\n\t\tpublic long getNextLong()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Long.parseLong( strtoken.nextToken());\n\t\t}\n\n\t\tpublic double getNextDouble()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Double.parseDouble( strtoken.nextToken());\n\t\t}\n\n\t\tpublic float getNextFloat()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Float.parseFloat( strtoken.nextToken());\n\t\t}\n\n\t\tpublic String getNextString()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn strtoken.nextToken();\n\t\t}\n\n\t\tpublic String getNextLine()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn bufferReader.readLine();\n\t\t}\n\n\t\tpublic void skipCurrentLine()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\tstrtoken = null;\n\t\t}\n\t\tpublic void write( String var )throws IOException\n\t\t{\n\t\t\tbufferWriter.write( var );\n\t\t}\n\n\t\tpublic < T > void write( char sep, T... var )throws IOException\n\t\t{\n\t\t\tif ( var.length == 0 )\n\t\t\t\treturn ;\n\t\t\tbufferWriter.write( var[0].toString());\n\t\t\tfor ( int i = 1; i < var.length; i++ )\n\t\t\t\tbufferWriter.write( sep + var[i].toString());\n\t\t}\n\n\t\tpublic void flush()throws IOException\n\t\t{\n\t\t\tbufferWriter.flush();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tnew Main().run();\n\t\t}\n\t\tcatch (Exception ex)\n\t\t{\n\t\t\tex.printStackTrace();\n\t\t}\n\t}\n\tprivate BasicInputOutput iohandler;\n\tprivate int n;\n\tprivate double[][] mat;\n\tprivate double[][] sum;\n\tprivate double[] dp;\n\tprivate int tolive;\n\tprivate void run()throws Exception\n\t{\n\t\tinitialize();\n\t\tsolve();\n\t}\n\tprivate void initialize() throws Exception\n\t{\n\t\tiohandler=new BasicInputOutput();\n\t\tn=iohandler.getNextInt();\n\t\tmat=new double[n][n];\n\t\tsum=new double[(1<<n)+10][n];\n\t\tdp=new double[1<<n];\n\t\tfor(int i=0;i<n;i++) for(int j=0;j<n;j++)\n\t\t{\n\t\t\tmat[i][j]=iohandler.getNextDouble();\n\t\t}\n\t}\n\tprivate int bitCount(int mask)\n\t{\n\t\tint ret=0;\n\t\twhile(mask>0) {\n\t\t\tret++;\n\t\t\tmask&=(mask-1);\n\t\t}\n\t\treturn ret;\n\t}\n\tprivate void solve() throws Exception\n\t{\n\t\tdouble[] ans=new double[n];\n\t\tint ub=1<<n;\n\t\tfor(int i=1;i<ub;i++) {\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tsum[i][j]=0;\n\t\t\t\tfor(int k=0;k<n;k++) if ((i&(1<<k))!=0) sum[i][j]+=mat[k][j];\n\t\t\t\tint cntbit=bitCount(i);\n\t\t\t\tif (cntbit>1)\n\t\t\t\tsum[i][j]/=((double)cntbit*(cntbit-1.))/2.;\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int mask=1;mask<ub;mask++) {\n\t\t\t\tdp[mask]=0;\n\t\t\t\tif ((mask&(1<<i))==0) continue;\n\t\t\t\tif (bitCount(mask)==1)\n\t\t\t\t{\n\t\t\t\t\tdp[mask]=1.;\n\t\t\t\t} else\n\t\t\t\tfor(int k=0;k<n;k++) {\n\t\t\t\t\tif ((mask&(1<<k))==0) continue;\n\t\t\t\t\tif (i==k) continue;\n\t\t\t\t\tdp[mask]+=sum[mask][k]*dp[mask-(1<<k)];\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[i]=dp[ub-1];\n\t\t}\n\t\tiohandler.write(ans[0]+\"\");\n\t\tfor(int i=1;i<n;i++) iohandler.write(\" \"+ans[i]);\n\t\tiohandler.write(\"\\n\");\n\t\tiohandler.flush();\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\npublic class Main\n{\n    static double arr[][];\n    public static void main(String[] args)\n    {\n        try\n        {\n            Parserdoubt pd=new Parserdoubt(System.in);\n            PrintWriter pw=new PrintWriter(System.out);\n            int fishes=pd.nextInt();\n            arr=new double[fishes][fishes];\n            for(int i=0;i<fishes;i++)\n                for(int j=0;j<fishes;j++)\n                    arr[i][j]=Double.parseDouble(pd.nextString());\n            double dp[]=new double[(1<<fishes)];\n            dp[dp.length-1]=1.0;\n            for(int c=dp.length-1;c>=0;c--)\n            {\n                int count=Integer.bitCount(c);\n                if(count<=1)\n                    continue;\n                for(int i=0;i<fishes;i++)\n                    for(int j=i+1;j<fishes;j++)\n                    {\n                        if(((1<<i)&c)!=0&&((1<<j)&c)!=0)\n                        {\n                            dp[c&~(1<<j)]+=arr[i][j]*dp[c];\n                            dp[c&~(1<<i)]+=arr[j][i]*dp[c];\n                        }\n                    }\n            }\n            double s=0.0;\n            for(int i=0;i<fishes;i++)\n                s+=dp[1<<i];\n            for(int i=0;i<fishes;i++)\n                dp[1<<i]/=s;\n            int i=0;\n            for(i=0;i<fishes-1;i++)\n                pw.printf(\"%.6f \",dp[1<<i]);\n            pw.printf(\"%.6f\\n\",dp[1<<i]);\n            pw.close();\n        }\n        catch(Exception e)\n        {}\n    }\n}\nclass Parserdoubt\n    {\n       final private int BUFFER_SIZE = 1 << 17;\n\n       private DataInputStream din;\n       private byte[] buffer;\n       private int bufferPointer, bytesRead;\n\n       public Parserdoubt(InputStream in)\n       {\n          din = new DataInputStream(in);\n          buffer = new byte[BUFFER_SIZE];\n          bufferPointer = bytesRead = 0;\n       }\n       public String nextString() throws Exception\n       {\n           StringBuffer sb=new StringBuffer(\"\");\n           byte c = read();\n           while (c <= ' ') c = read();\n           do\n           {\n               sb.append((char)c);\n               c=read();\n           }while(c>' ');\n           return sb.toString();\n       }\n       public char nextChar() throws Exception\n       {\n           byte c=read();\n           while(c<=' ') c= read();\n           return (char)c;\n       }\n       public int nextInt() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       public long nextLong() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       private void fillBuffer() throws Exception\n       {\n          bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n          if (bytesRead == -1) buffer[0] = -1;\n       }\n\n       private byte read() throws Exception\n       {\n          if (bufferPointer == bytesRead) fillBuffer();\n          return buffer[bufferPointer++];\n       }\n    }\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class E16 {\n\tstatic double[][] grid;\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tgrid = new double[n][n];\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tfor(int j = 0; j < n; j++)\t{\n\t\t\t\tgrid[i][j] = Double.parseDouble(st.nextToken());\n\t\t\t}\n\t\t}\n\t\tboolean[] seen = new boolean[1<<n];\n\t\tdouble[] prob = new double[1<<n];\n\t\tprob[(1<<n)-1] = 1;\n\t\tLinkedList<Integer> q = new LinkedList<Integer>();\n\t\tq.add((1<<n)-1);\n\t\twhile(!q.isEmpty())\t{\n\t\t\tint curr = q.removeFirst();\n\t\t\tif(Integer.bitCount(curr) == 1)\n\t\t\t\tcontinue;\n\t\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\t\tif((curr & (1 << i)) == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor(int j = i+1; j < n; j++)\t\t{\n\t\t\t\t\tif((curr & (1<<j)) == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tprob[curr-(1<<i)] += prob[curr] * grid[j][i];\n\t\t\t\t\tprob[curr-(1<<j)] += prob[curr] * grid[i][j];\n\t\t\t\t\tif(!seen[curr-(1<<i)])\t{\n\t\t\t\t\t\tq.addLast(curr-(1<<i));\n\t\t\t\t\t\tseen[curr-(1<<i)] = true;\n\t\t\t\t\t}\n\t\t\t\t\tif(!seen[curr-(1<<j)])\t{\n\t\t\t\t\t\tq.addLast(curr-(1<<j));\n\t\t\t\t\t\tseen[curr-(1<<j)] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tprob[curr] = 0;\n\t\t}\n\t\tdouble sum = 0;\n\t\tfor(int i = 0; i < n; i++)\t\t{\n\t\t\tsum += prob[1<<i];\n\t\t}\n\t\tfor(int i = 0; i < n-1; i++)\t{\n\t\t\tSystem.out.print(prob[1<<i]/sum + \" \");\n\t\t}\n\t\tSystem.out.println(prob[1<<(n-1)]/sum);\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Problem {\n\n\tpublic static void main(String[] arg){\n\t\tFastScanner scan = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = scan.nextInt();\n\t\t\n\t\tdouble ncr[][] = new double[n+1][n+1];\n\t\tncr[1][0] = ncr[0][1] = ncr[1][1] = 1.0;\n\t\tfor(int i = 2; i <= n; i++){\n\t\t\tfor(int j = 0; j <= i; j++){\n\t\t\t\tif(j == 0 || j == i) ncr[i][j] = 1.0;\n\t\t\t\telse ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];\n\t\t\t\t//System.out.print(ncr[i][j] + \"  \");\n\t\t\t}\n\t\t\t//System.out.println();\n\t\t}\n\t\t\n\t\tdouble a[][] = new double[n+1][n+1];\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] = scan.nextDouble();\n\t\t\n\t\tdouble dp[] = new double[1<<19];\n\t\tdp[(1<<n) - 1] = 1.0;\n\t\tfor(int state = (1 << n) - 1; state >= 0; state--){\n\t\t\tint len = 0;\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tif((state & (1 << i)) > 0) len++;\n\t\t\t\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tif(((1 << i) & state) == 0) continue;\n\t\t\t\tfor(int j = 0; j < i; j++){\n\t\t\t\t\tif(((1 << j) & state) == 0) continue;\n\t\t\t\t\tdp[state & (~(1<<i))] += (dp[state] * a[j][i] / ncr[len][2]);\n\t\t\t\t\tdp[state & (~(1<<j))] += (dp[state] * a[i][j] / ncr[len][2]);\n\t\t\t\t\t//System.out.println(state + \" / \" + (state & (~(1<<i))) + \" / \" + dp[state] + \" / \" + a[j][i] + \" / \" + (dp[state] * a[j][i]) + \" / \"  + dp[state & (~(1<<i))]);\n\t\t\t\t\t//System.out.println(state + \" / \" + (state & (~(1<<j))) + \" / \" + dp[state] + \" / \" + a[i][j] + \" / \" + (dp[state] * a[i][j]) + \" / \"  + dp[state & (~(1<<j))]);\n\t\t\t\t\t//System.out.println();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tSystem.out.print(String.format(\"%.6f\", dp[1<<i]) + \" \");\n\t\tout.close();\n\t}\n\tpublic static long gcd(long a, long b){\n\t\tif(b == 0) return a;\n\t\tif(a < b) return gcd(b, a);\n\t\treturn gcd(b, a % b);\n\t}\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", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "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 \npublic class A {\n \n\tstatic double[][] a;\n\tstatic int N;\n\tstatic double[] memo;\n \n\tstatic double dp(int alive)\n\t{\n\t\tint count = Integer.bitCount(alive);\n\t\tif(count == N)\n\t\t\treturn 1;\n\t\tif(memo[alive] > -5)\n\t\t\treturn memo[alive];\n\t\t\n\t\tdouble ret = 0;\n\t\tfor(int j = 0; j < N; ++j)\n\t\t\tif((alive & (1<<j)) == 0)\n\t\t\t\tret += die[j][alive | 1<<j] * dp(alive | 1<<j);\t\t\t\n\t\n\t\treturn memo[alive] = ret;\n\t}\n \n\tstatic double[][] die;\n\tstatic void f()\n\t{\n\t\tdie = new double[N][1<<N];\n\t\tfor(int i = 0; i < N; ++i)\n\t\t\tfor(int j = 0; j < 1<<N; ++j)\n\t\t\t{\n\t\t\t\tint count = Integer.bitCount(j);\n\t\t\t\tif(count <= 1)\n\t\t\t\t\tcontinue;\n\t\t\t\tdouble prop = 1.0 / (count * (count - 1) >> 1);\n\t\t\t\tfor(int k = 0; k < N; ++k)\n\t\t\t\t\tif((j & (1<<k)) != 0)\n\t\t\t\t\t\tdie[i][j] += prop * a[k][i]; \n\t\t\t}\n \n\t}\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\tN = sc.nextInt();\n\t\t\n\t\ta = new double[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\ta[i][j] = sc.nextDouble();\n\t\tmemo = new double[1<<N];\n\t\tf();\n\n\t\tArrays.fill(memo, -10);\t\t\n\t\tfor(int i = 0; i < N - 1; ++i)\n\t\t\tout.printf(\"%.8f \", dp(1 << i));\n\t\tout.printf(\"%.8f\\n\", dp(1 << N - 1));\n \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){  br = 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 double nextDouble() throws NumberFormatException, IOException\n\t\t{\n\t\t\treturn Double.parseDouble(next());\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 boolean ready() throws IOException {return br.ready();}\n\n\n\t}\n} ", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Locale;\n\npublic class E16 {\n\n    static StreamTokenizer in;\n    static PrintWriter out;\n    \n    static int nextInt() throws IOException {\n        in.nextToken();\n        return (int)in.nval;\n    }\n    \n    static double nextDouble() throws IOException {\n        in.nextToken();\n        return in.nval;\n    }\n    \n    static String nextString() throws IOException {\n        in.nextToken();\n        return in.sval;\n    }\n\n    public static void main(String[] args) throws IOException {\n        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        out = new PrintWriter(System.out);\n        \n        n = nextInt();\n        t = 1 << n;\n        m = new double[n][n];\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < n; j++)\n                m[i][j] = nextDouble();\n        \n        memo = new double[t];\n        Arrays.fill(memo, Double.POSITIVE_INFINITY);\n        for (int i = 0; i < n; i++) out.print(String.format(Locale.US, \"%.6f\", solve(1 << i)) + \" \");\n        out.println();\n        \n        out.flush();\n    }\n    \n    static int n, t;\n    static double[][] m;\n    static double[] memo;\n    \n    static double solve(int mask) {\n        if (memo[mask] != Double.POSITIVE_INFINITY) return memo[mask];\n        if (mask == t-1) return memo[mask] = 1;\n        \n        int k = Integer.bitCount(mask);\n        k = (k+1)*k/2;\n        double res = 0;\n        for (int i = 0; i < n; i++) if ((mask&(1 << i)) != 0)\n            for (int j = 0; j < n; j++) if ((mask&(1 << j)) == 0)\n                res += m[i][j]*solve(mask|(1 << j));\n        \n        return memo[mask] = res/k;\n    }\n}\n\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemE_16 {\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 ProblemE_16().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    void solve() throws IOException{\n        int n = readInt();\n        double[][] a = new double[n][n];\n        for (int i = 0; i < n; i++){\n            for (int j = 0; j < n; j++){\n                a[i][j] = readDouble();\n            }\n        }\n        double[] d = new double[1<<n];\n        d[(1 << n) - 1] = 1;\n        for (int i = (1 << n) - 1; i > 0; i--){\n            ArrayList<Integer> list = new ArrayList<Integer>();\n            for (int j = 0; j < n; j++){\n                if ((i & (1 << j)) != 0) list.add(j);\n            }\n            double s = 0;\n            for (int j = 0; j < list.size(); j++){\n                s = 0;\n                for (int k = 0; k < list.size(); k++){\n                    s += a[list.get(k)][list.get(j)];\n                }\n                d[i ^ (1 << list.get(j))] += s * d[i] * 2 / list.size() / (list.size() - 1);\n            }\n        }\n        for (int i = 0; i < n; i++){\n            out.printf(Locale.US, \"%.9f\", d[1 << i]);\n            out.print(\" \");\n        }\n    }\n    \n    static int[][] step8 = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};\n    \n    static int[][] stepKnight = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, -1}, {2, 1}};\n    \n    static long gcd(long a, long b){\n        if (a == 0) return b;\n        return gcd(b % a, a);\n    }\n    \n    static long lcm(long a, long b){\n        return a / gcd(a, b)*b;\n    }\n\n    static long[] gcdPlus(long a, long b){\n        long[] d = new long[3];\n        if (a == 0){\n            d[0] = b;\n            d[1] = 0;\n            d[2] = 1;\n        }else{\n            d = gcdPlus(b % a, a);\n            long r = d[1];\n            d[1] = d[2] - b/a*d[1];\n            d[2] = r;\n        }\n        return d;\n    }\n    \n    static long binpow(long a, int n){\n        if (n == 0) return 1;\n        if ((n & 1) == 0){\n            long b = binpow(a, n/2);\n            return b*b;\n        }else return binpow(a, n - 1)*a;\n    }\n    \n    static long binpowmod(long a, int n, long m){\n        if (m == 1) return 0;\n        if (n == 0) return 1;\n        if ((n & 1) == 0){\n            long b = binpowmod(a, n/2, m);\n            return (b*b) % m;\n        }else return binpowmod(a, n - 1, m)*a % m;\n    }\n    \n    static long phi(long n){\n        int[] p = Sieve((int)ceil(sqrt(n)) + 2);\n        long phi = 1;\n        for (int i = 0; i < p.length; i++){\n            long x = 1;\n            while (n % p[i] == 0){\n                n /= p[i];\n                x *= p[i];\n            }\n            phi *= x - x/p[i];\n        }\n        if (n != 1) phi *= n - 1;\n        return phi;\n    }\n    \n    static long f(long n, int x, int k){ //\u041a\u043e\u043b-\u0432\u043e \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b (\u0432\u043a\u043b\u044e\u0447\u0430\u044f 0), \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0432 \u0441\u0435\u0431\u0435 \u0446\u0438\u0444\u0440\u044b \u043e\u0442 0 \u0434\u043e k-1\n        if (n == 0) return 1;\n        long b = binpow(10, x - 1);\n        long c = n / b;\n        return (c < k? c: k)*binpow(k, x - 1) + (c < k? 1: 0)*f(n % b, x - 1, k);\n    }\n    \n    static long fib(int n){\n        if (n == 0) return 0;\n        if ((n & 1) == 0){\n            long f1 = fib(n/2 - 1);\n            long f2 = fib(n/2 + 1);\n            return f2*f2 - f1*f1;\n        }else{\n            long f1 = fib(n/2);\n            long f2 = fib(n/2 + 1);\n            return f1*f1 + f2*f2;\n        }\n    }\n    \n    static BigInteger BigFib(int n){\n        if (n == 0) return BigInteger.ZERO;\n        if ((n & 1) == 0){\n            BigInteger f1 = BigFib(n/2 - 1);\n            f1 = f1.multiply(f1);\n            BigInteger f2 = BigFib(n/2 + 1);\n            f2 = f2.multiply(f2);\n            return f2.subtract(f1);\n        }else{\n            BigInteger f1 = BigFib(n/2);\n            f1 = f1.multiply(f1);\n            BigInteger f2 = BigFib(n/2 + 1);\n            f2 = f2.multiply(f2);\n            return f2.add(f1);\n        }\n    }\n    \n    static public class PointD{\n        \n        double x, y;\n        \n        public PointD(double x, double y){\n            this.x = x;\n            this.y = y;\n        }\n    }\n    \n    static double d(Point p1, Point p2){\n        return sqrt(d2(p1, p2));\n    }\n    \n    static public double d(PointD p1, PointD p2){\n        return sqrt(d2(p1, p2));\n    }\n    \n    static double d2(Point p1, Point p2){\n        return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);\n    }\n    \n    static public double d2(PointD p1, PointD p2){\n        return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);\n    }\n    \n    static boolean IsProbablyPrime(long n){\n        if (n == 1) return false;\n        if ((n & 1) == 0) return false;\n        for (int j = 3; j < sqrt(n) + 1; j += 2){\n            if (n % j == 0) return false;\n        }\n        return true;\n    }\n\n    static int[] Sieve(int n){\n        boolean[] b = new boolean[n+1];\n        Arrays.fill(b, true);\n        b[0] = false;\n        b[1] = false;\n        long nLong = n;\n        int j=0;\n        for (int i = 1; i <= n; i++) {\n            if (b[i]){\n                j++;\n                if (((long)i)*i <= nLong) {\n                    for (int k = i*i; k <= n; k += i) {\n                        b[k] = false;\n                    }\n                }\n            }\n        }\n        int[] p = new int[j];\n        Arrays.fill(p, 0);\n        j=0;\n        for (int i = 2; i <= n; i++) {\n            if (b[i]){\n                p[j]=i;\n                j++;\n            }\n        }\n        return p;\n    }\n    \n    static int[][] Palindromes(String s){\n        char[] c = s.toCharArray();\n        int n = c.length;\n        int[][] d = new int[2][n];\n        int l = 0, r = -1;\n        for (int i = 0; i < n; i++){\n            int j = (i > r? 0: min(d[0][l+r-i+1], r-i+1)) + 1;\n            for (; i - j >= 0 && i + j - 1< n && c[i-j] == c[i+j-1]; j++);\n            d[0][i] = --j;\n            if (i + d[0][i] - 1 > r){\n                r = i + d[0][i] - 1;\n                l = i - d[0][i];\n            }\n        }\n        l = 0;\n        r = -1;\n        for (int i = 0; i < n; i++){\n            int j = (i > r? 0: min(d[1][l+r-i], r-i)) + 1;\n            for (; i - j >= 0 && i + j < n && c[i-j] == c[i+j]; j++);\n            d[1][i] = --j;\n            if (i + d[1][i] > r){\n                r = i + d[1][i];\n                l = i - d[1][i];\n            }\n        }\n        return d;\n    }\n    \n    static public class Permutation {\n        \n        int[] a;\n        int n;\n        \n        public Permutation(int n){\n            this.n=n;\n            a=new int[n];\n            for (int i=0; i<n; i++){\n                a[i]=i;\n            }\n        }\n        \n        public boolean nextPermutation(){ //\u041f\u0438\u0448\u0435\u0442\u0441\u044f \u0441 do{}while(nextPermutation(a));\n            int i=n-1;\n            for (i=n-2; i>=0; i--){\n                if (a[i]<a[i+1]){\n                    break;\n                }\n            }\n            if (i==-1){\n                return false;\n            }\n            int jMin=i+1;\n            for (int j=n-1; j>i; j--){\n                if (a[i]<a[j]&&a[j]<a[jMin]){\n                    jMin=j;\n                }\n            }\n            swap(i, jMin);\n            for (int j=1; j<=(n-i)/2; j++){\n                swap(i+j, n-j);\n            }\n            return true;\n        }\n        \n        \n        public int get(int i){\n            return a[i];\n        }\n        \n        void swap(int i, int j){\n            int r=a[i];\n            a[i]=a[j];\n            a[j]=r;\n        }\n    }\n    \n    static public class Fraction implements Comparable<Fraction>, Cloneable{\n        \n        public final Fraction FRACTION_ZERO = new Fraction();\n        public final Fraction FRACTION_ONE = new Fraction(1);\n        public long numerator = 0;\n        public long denominator = 1;\n        \n        public Fraction(){\n            numerator = 0;\n            denominator = 1;\n        }\n        \n        public Fraction(long numerator){\n            this.numerator = numerator;\n            denominator = 1;\n        }\n        \n        public Fraction(long numerator, long denominator){\n            this.numerator = numerator;\n            this.denominator = denominator;\n            Cancellation();\n        }\n        \n        public Fraction(double numerator, double denominator, int accuracy){\n            this.numerator = (long)(numerator*pow(10,accuracy));\n            this.denominator = (long)(denominator*pow(10,accuracy));\n            Cancellation();\n        }\n        \n        public Fraction(String s){\n            if (s.charAt(0) == '-'){\n                denominator = -1;\n                s = s.substring(1);\n            }\n            if (s.indexOf(\"/\") != -1){\n                denominator *= Integer.parseInt(s.substring(s.indexOf(\"/\") + 1));\n            }\n            if (s.indexOf(\" \") != -1){\n                numerator = Integer.parseInt(s.substring(0, s.indexOf(\" \"))) * abs(denominator) + Integer.parseInt(s.substring(s.indexOf(\" \") + 1, s.indexOf(\"/\")));\n            }else{\n                if (s.indexOf(\"/\") != -1){\n                    numerator = Integer.parseInt(s.substring(0, s.indexOf(\"/\")));\n                }else{\n                    numerator = Integer.parseInt(s)*abs(denominator);\n                }\n            }\n            this.Cancellation();\n        }\n        \n        void Cancellation(){\n            long g = gcd(abs(numerator), abs(denominator));\n            numerator /= g;\n            denominator /= g;\n            if (denominator < 0){\n                numerator *= -1;\n                denominator *= -1;\n            }\n        }\n        \n        public String toString(){\n            String s = \"\";\n            if (numerator == 0){\n                return \"0\";\n            }\n            if (numerator < 0){\n                s += \"-\";\n            }\n            if (abs(numerator) >= denominator){\n                s += Long.toString(abs(numerator) / denominator) + \" \";\n            }\n            if (abs(numerator) % denominator != 0){\n                s += Long.toString(abs(numerator) % denominator);\n            }else{\n                s = s.substring(0, s.length()-1);\n            }\n            if (denominator != 1){\n                s += \"/\" + Long.toString(denominator);\n            }\n            return s;\n        }\n        \n        public Fraction add(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.denominator = lcm(denominator, f.denominator);\n            fResult.numerator = numerator * fResult.denominator / denominator + f.numerator * fResult.denominator / f.denominator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        public Fraction subtract(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.denominator = lcm(denominator, f.denominator);\n            fResult.numerator = numerator * fResult.denominator / denominator - f.numerator * fResult.denominator / f.denominator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        public Fraction multiply(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.numerator = numerator * f.numerator;\n            fResult.denominator = denominator * f.denominator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        public Fraction divide(Fraction f){\n            Fraction fResult = new Fraction();\n            fResult.numerator = numerator * f.denominator;\n            fResult.denominator = denominator * f.numerator;\n            fResult.Cancellation();\n            return fResult;\n        }\n        \n        @Override\n        public int compareTo(Fraction f){\n            long g = gcd(denominator, f.denominator);\n            long res = numerator * (f.denominator / g) - f.numerator * (denominator / g);\n            if (res < 0){\n                return -1;\n            }\n            if (res > 0){\n                return 1;\n            }\n            return 0;\n        }\n        \n        public Fraction clone(){\n            Fraction fResult = new Fraction(numerator, denominator);\n            return fResult;\n        }\n        \n        public Fraction floor(){\n            Fraction fResult = this.clone();\n            fResult.numerator = (fResult.numerator / fResult.denominator) * fResult.denominator;\n            return fResult;\n        }\n        \n        public Fraction ceil(){\n            Fraction fResult = this.clone();\n            fResult.numerator = (fResult.numerator/fResult.denominator + 1) * fResult.denominator;\n            return fResult;\n        }\n        \n        public Fraction binpow(int n){\n            if (n==0) return FRACTION_ONE;\n            if ((n&1)==0){\n                Fraction f=this.binpow(n/2);\n                return f.multiply(f);\n            }else return binpow(n-1).multiply(this);\n        }\n    }\n    \n    static public class FenwickTree_1{  //One-dimensional array     \n        \n        int n;\n        long[] t;\n        \n        public FenwickTree_1(int n){\n            this.n = n;\n            t = new long[n];\n        }\n        \n        public long sum(int xl, int xr){\n            return sum(xr) - sum(xl);\n        }\n        \n        public long sum(int x){\n            long result = 0;\n            for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                result += t[i];\n            }\n            return result;\n        }\n        \n        public void update(int x, long delta){\n            for (int i = x; i < n; i = (i | (i + 1))){\n                t[i] += delta;\n            }\n        }\n    }\n    \n    static public class FenwickTree_2{  //Two-dimensional array\n        \n        int n, m;\n        long[][] t;\n        \n        public FenwickTree_2(int n, int m){\n            this.n = n;\n            this.m = m;\n            t = new long[n][m];\n        }\n        \n        public long sum(int xl, int yl, int xr, int yr){\n            return sum(xr, yr) - sum(xl - 1, yr) - sum(xr, yl - 1) + sum(xl - 1, yl - 1);\n        }\n        \n        public long sum(int x, int y){\n            long result = 0;\n            for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                for (int j = y; j >= 0; j = (j & (j + 1)) - 1){\n                    result+=t[i][j];\n                }\n            }\n            return result;\n        }\n        \n        public void update(int x, int y, long delta){\n            for (int i = x; i < n; i = (i | (i + 1))){\n                for (int j = y; j < m; j = (j | (j + 1))){\n                    t[i][j] += delta;\n                }\n            }\n        }\n    }\n    \n    static public class FenwickTree_3{  //Three-dimensional array\n        \n        int n, m, l;\n        long[][][] t;\n        \n        public FenwickTree_3(int n, int m, int l){\n            this.n = n;\n            this.m = m;\n            this.l = l;\n            t = new long[n][m][l];\n        }\n        \n        public long sum(int xl, int yl, int zl, int xr, int yr, int zr){\n            return sum(xr, yr, zr) - sum(xl - 1, yr, zr)\n            + sum(xl - 1, yr, zl - 1) - sum(xr, yr, zl - 1)\n            - sum(xr, yl - 1, zr) + sum(xl - 1, yl - 1, zr)\n            - sum(xl - 1, yl - 1, zl - 1) + sum(xr, yl - 1, zl - 1);\n        }\n        \n        public long sum(int x, int y, int z){\n            long result = 0;\n            for (int i = x; i >= 0; i = (i & (i + 1)) - 1){\n                for (int j = y; j >= 0; j = (j & (j + 1)) - 1){\n                    for (int k = z; k >= 0; k = (k & (k + 1)) - 1){\n                        result += t[i][j][k];\n                    }\n                }\n            }\n            return result;\n        }\n        \n        public void update(int x, int y, int z, long delta){\n            for (int i = x; i < n; i = (i | (i + 1))){\n                for (int j = y; j < n; j = (j | (j + 1))){\n                    for (int k = z; k < n; k = (k | (k + 1))){\n                        t[i][j][k] += delta;\n                    }\n                }\n            }\n        }\n    }\n}\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/*\n\tAuthor\t:\tImran Khan\n\tLanguage:\tJava\n\t\n*/\n\nimport java.io.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic class BasicInputOutput\n\t{\n\n\t\tprivate StringTokenizer strtoken;\n\t\tprivate BufferedReader bufferReader;\n\t\tprivate BufferedWriter bufferWriter;\n\t\tprivate String delim = \" \\t\\n\\r\\f\";\n\t\tBasicInputOutput()\n\t\t{\n\t\t\tdelim = \" \\t\\n\\r\\f\";\n\t\t\tinitialize();\n\t\t}\n\t\tBasicInputOutput( String s )\n\t\t{\n\t\t\tdelim = s;\n\t\t\tinitialize();\n\t\t}\n\t\tprivate void initialize()\n\t\t{\n\t\t\tbufferReader = new BufferedReader( new InputStreamReader( System.in ));\n\t\t\tbufferWriter = new BufferedWriter( new PrintWriter( System.out ));\n\t\t\tstrtoken = null;\n\t\t}\n\t\tprivate void checkStringTokenizer()throws IOException\n\t\t{\n\t\t\tif ( strtoken == null || strtoken.hasMoreTokens() == false )\n\t\t\t\tstrtoken = new StringTokenizer( bufferReader.readLine(), delim );\n\t\t}\n\t\tpublic int getNextInt()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Integer.parseInt( strtoken.nextToken());\n\t\t}\n\n\t\tpublic long getNextLong()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Long.parseLong( strtoken.nextToken());\n\t\t}\n\n\t\tpublic double getNextDouble()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Double.parseDouble( strtoken.nextToken());\n\t\t}\n\n\t\tpublic float getNextFloat()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn Float.parseFloat( strtoken.nextToken());\n\t\t}\n\n\t\tpublic String getNextString()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn strtoken.nextToken();\n\t\t}\n\n\t\tpublic String getNextLine()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\treturn bufferReader.readLine();\n\t\t}\n\n\t\tpublic void skipCurrentLine()throws IOException\n\t\t{\n\t\t\tcheckStringTokenizer();\n\t\t\tstrtoken = null;\n\t\t}\n\t\tpublic void write( String var )throws IOException\n\t\t{\n\t\t\tbufferWriter.write( var );\n\t\t}\n\n\t\tpublic < T > void write( char sep, T... var )throws IOException\n\t\t{\n\t\t\tif ( var.length == 0 )\n\t\t\t\treturn ;\n\t\t\tbufferWriter.write( var[0].toString());\n\t\t\tfor ( int i = 1; i < var.length; i++ )\n\t\t\t\tbufferWriter.write( sep + var[i].toString());\n\t\t}\n\n\t\tpublic void flush()throws IOException\n\t\t{\n\t\t\tbufferWriter.flush();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tnew Main().run();\n\t\t}\n\t\tcatch (Exception ex)\n\t\t{\n\t\t\tex.printStackTrace();\n\t\t}\n\t}\n\tprivate BasicInputOutput iohandler;\n\tprivate int n;\n\tprivate double[][] mat;\n\tprivate double[][] sum;\n\tprivate double[] dp;\n\tprivate int tolive;\n\tprivate void run()throws Exception\n\t{\n\t\tinitialize();\n\t\tsolve();\n\t}\n\tprivate void initialize() throws Exception\n\t{\n\t\tiohandler=new BasicInputOutput();\n\t\tn=iohandler.getNextInt();\n\t\tmat=new double[n][n];\n\t\tsum=new double[(1<<n)+10][n];\n\t\tdp=new double[1<<n];\n\t\tfor(int i=0;i<n;i++) for(int j=0;j<n;j++)\n\t\t{\n\t\t\tmat[i][j]=iohandler.getNextDouble();\n\t\t}\n\t}\n\tprivate int bitCount(int mask)\n\t{\n\t\tint ret=0;\n\t\twhile(mask>0) {\n\t\t\tret++;\n\t\t\tmask&=(mask-1);\n\t\t}\n\t\treturn ret;\n\t}\n\tprivate void solve() throws Exception\n\t{\n\t\tdouble[] ans=new double[n];\n\t\tint ub=1<<n;\n\t\tfor(int i=1;i<ub;i++) {\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tsum[i][j]=0;\n\t\t\t\tfor(int k=0;k<n;k++) if ((i&(1<<k))!=0) sum[i][j]+=mat[k][j];\n\t\t\t\tint cntbit=bitCount(i);\n\t\t\t\tif (cntbit>1)\n\t\t\t\tsum[i][j]/=((double)cntbit*(cntbit-1.))/2.;\n\t\t\t}\n\t\t}\n\t\tdp[ub-1]=1.;\n\t\tfor(int mask=ub-1;mask>=1;mask--) {\n\t\t\tif (dp[mask]==0.) continue;\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tif ((mask&(1<<i))==0) continue;\n\t\t\t\tdp[mask-(1<<i)]+=sum[mask][i]*dp[mask];\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<n;i++)\n\t\tans[i]=dp[1<<i];\n\t\t/*\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int mask=1;mask<ub;mask++) {\n\t\t\t\tdp[mask]=0;\n\t\t\t\tif ((mask&(1<<i))==0) continue;\n\t\t\t\tif (bitCount(mask)==1)\n\t\t\t\t{\n\t\t\t\t\tdp[mask]=1.;\n\t\t\t\t} else\n\t\t\t\tfor(int k=0;k<n;k++) {\n\t\t\t\t\tif ((mask&(1<<k))==0) continue;\n\t\t\t\t\tif (i==k) continue;\n\t\t\t\t\tdp[mask]+=sum[mask][k]*dp[mask-(1<<k)];\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[i]=dp[ub-1];\n\t\t}*/\n\t\tiohandler.write(ans[0]+\"\");\n\t\tfor(int i=1;i<n;i++) iohandler.write(\" \"+ans[i]);\n\t\tiohandler.write(\"\\n\");\n\t\tiohandler.flush();\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n    static double[] dp;\n    static double[][] P;\n    public static void main(String[] args) {\n        Scanner r = new Scanner(System.in);\n        \n        int n = r.nextInt();\n        \n        double[][] g = new double[n][n];\n        for(int i = 0; i < n; i++)\n            for(int j = 0; j < n; j++)\n                g[i][j] = r.nextDouble();\n        \n        dp = new double[1 << n];\n        P = new double[1 << n][n];\n        for(int mask = 0; mask < 1 << n; mask++){\n            for(int d = 0; d < n; d++)if((mask & (1 << d)) == 0)\n                for(int i = 0; i < n; i++)if((mask & (1 << i)) == 0){\n                    if(i == d)continue;\n                    \n                    P[mask][d] += g[i][d];\n                }\n        }\n        \n        for(int i = 0; i < n; i++){\n            Arrays.fill(dp, -1);\n            \n            double res = go(i, 0, g, n, n);\n            System.out.println(res);\n        }\n    }\n\n    private static double go(int a, int v, double[][] g, int cnt, int n) {\n        if(dp[v] != -1)return dp[v];\n        \n        if(cnt == 1){\n            return 1;\n        }else{\n            double ret = 0;\n            for(int d = 0; d < n; d++)if((v & (1 << d)) == 0 && d != a){\n                double current =  P[v][d] * go(a, v | 1 << d, g, cnt-1, n);\n                ret += current;\n            }\n            \n            return dp[v] = ret/(cnt * (cnt-1) /2);\n        }  \n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class A {\n\n    public static int n;\n    public static double[] masks;\n    public static double[][] matrix;\n\n    public static void main(String[] args) {\n        Scanner scan = new Scanner(System.in);\n\n        n = scan.nextInt();\n\n        matrix = new double[n][n];\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < n; j++)\n                matrix[i][j] = scan.nextDouble();\n\n        masks = new double[1 << n];\n        masks[(1 << n) - 1] = 1;\n        for (int i = 0; (1 << i) < (1 << n); i++)\n            fillDP(1 << i);\n\n        for (int i = 0; (1 << i) < (1 << n); i++)\n            System.out.printf(\"%.6f \", masks[1 << i]);\n\n\n    }\n\n    public static double fillDP(int mask) {\n        int bitCount = Integer.bitCount(mask);\n\n        if (masks[mask] != 0)\n            return masks[mask];\n\n        double matchProba = 2.0 / (((double) (bitCount)) * ((double) (bitCount + 1)));\n\n        double totalProba = 0;\n        for (int i = 0; i < n; i++) {\n            int iPower = 1 << i;\n\n            if ((mask & iPower) != iPower)\n                continue;\n\n            for (int j = 0; j < n; j++) {\n                int jPower = 1 << j;\n\n                if ((mask & jPower) == jPower || i == j)\n                    continue;\n\n                // still alive\n                totalProba += (matchProba * matrix[i][j] * fillDP(mask | jPower));\n            }\n        }\n\n        return masks[mask] = totalProba;\n\n    }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/14/11\n * Time: 9:53 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 Fish extends Thread {\n\n    public Fish() {\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    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        double[][] a = new double[n][n];\n        double[] dp = new double[(1 << n)];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        }\n        int limit = (1 << n) - 1;\n        //dp[mask] = probability of current subset (mask) to remain in the end\n        dp[limit] = 1.0;\n        for (int mask = limit; mask > 0; --mask) {\n            int cardinality = getOnes(mask);\n            int probability = cardinality * (cardinality - 1) / 2;\n            for (int first = 0; first < n; ++first) {\n                if ((mask & powers[first]) != 0) {\n                    for (int second = first + 1; second < n; ++second) {\n                        if ((mask & powers[second]) != 0) {\n                            dp[mask - powers[first]] += dp[mask] * a[second][first] / probability;\n                            dp[mask - powers[second]] += dp[mask] * a[first][second] / probability;\n                        }\n\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            output.printf(\"%.10f \", dp[powers[i]]);\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\n    public static void main(String[] args) {\n        new Fish().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    static int powers[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "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 Main16E {\n\n    private FastScanner in;\n    private PrintWriter out;\n\n    public void solve() throws IOException {\n        int n = in.nextInt();\n        double[][] a = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                a[i][j] = in.nextDouble();\n            }\n        }\n        int k = 1 << n;\n        double[] p = new double[k];\n        int[][] b = new int[n + 1][];\n        for (int i = 0; i <= n; i++) {\n            b[i] = new int[comb(i, n)];\n        }\n        int[] bl = new int[n + 1];\n        for(int i = 0; i < k; i++) {\n            int c = c2(i);\n            b[c][bl[c]] = i;\n            bl[c]++;\n        }\n        p[k - 1] = 1;\n        for (int i = n; i >= 2; i--) {\n            for (int j = 0; j < b[i].length; j++) {\n                int t = b[i][j];\n                double pm = 1;\n                pm /= (i * (i - 1) / 2);\n                for (int x = 0; x < n; x++) {\n                    for (int y = x + 1; y < n; y++) {\n                        if ((t & (1 << x)) > 0 && (t & (1 << y)) > 0) {\n                            p[t & ~(1 << x)] += p[t] * pm * a[y][x];\n                            p[t & ~(1 << y)] += p[t] * pm * a[x][y];\n                        }\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            out.print(p[1 << i] + \" \");\n        }\n    }\n\n    int comb(int n, int m) {\n        int res = 1;\n        for (int i = 1; i <= n; i++) {\n            res = res * (m - i + 1);\n            res /= i;\n        }\n        return res;\n    }\n\n    int c2(int k) {\n        int res = 0;\n        while (k > 0) {\n            if (k % 2 == 1) {\n                res ++;\n            }\n            k /= 2;\n        }\n        return res;\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        } 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                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n    }\n\n    public static void main(String[] arg) {\n        new Main16E().run();\n    }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Queue;\nimport java.util.concurrent.ArrayBlockingQueue;\n\npublic class ProblemE {\n\t\n\t\n\tstatic final int INF = 1000000;\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\n\t\tint n = Integer.valueOf(s.readLine());\n\t\tdouble[][] prob = new double[n][n];\n\t\tdouble[] dp = new double[1<<n];\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tString[] line = s.readLine().split(\" \");\n\t\t\tfor (int j = 0 ; j < n ; j++) {\n\t\t\t\tprob[i][j] = Double.valueOf(line[j]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp[(1<<n)-1] = 1.0d;\n\t\tfor (int p = (1<<n)-1 ; p >= 1 ; p--) {\n\t\t\tif (dp[p] > 0.0d) {\n\t\t\t\tint left = Integer.bitCount(p);\n\t\t\t\tif (left == 1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdouble baseProb = 1.0d / (left * (left - 1) / 2);\n\t\t\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\t\t\tif ((p & (1<<i)) == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int j = i+1 ; j < n ; j++) {\n\t\t\t\t\t\tif ((p & (1<<j)) == 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdp[p-(1<<i)] += dp[p] * baseProb * prob[j][i];\n\t\t\t\t\t\tdp[p-(1<<j)] += dp[p] * baseProb * prob[i][j];\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\tStringBuffer b = new StringBuffer();\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tb.append(\" \").append(dp[1<<i]);\n\t\t}\n\t\tout.println(b.substring(1));\n\t\tout.flush();\n\t}\n\n\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tFish solver = new Fish();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass Fish {\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n        int n = in.nextInt();\n        double[][] p = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                p[i][j] = in.nextDouble();\n            }\n        }\n        double[] dp = new double[1 << n];\n        dp[(1 << n) - 1] = 1;\n        for (int mask = (1 << n) - 1; mask >= 0; mask--) {\n            int countPairs = Integer.bitCount(mask);\n            countPairs = countPairs * (countPairs - 1) / 2;\n            for (int i = 0; i < n; i++) {\n                if (((mask >> i) & 1) == 0) {\n                    continue;\n                }\n                for (int j = i + 1; j < n; j++) {\n                    if (((mask >> j) & 1) == 0) {\n                        continue;\n                    }\n                    dp[mask ^ (1 << j)] += dp[mask] * p[i][j] / countPairs;\n                    dp[mask ^ (1 << i)] += dp[mask] * p[j][i] / countPairs;\n                }\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            out.print(dp[1 << i] + \" \");\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    public String next() {\n        StringBuilder sb = new StringBuilder();\n        int c = read();\n        while (isWhiteSpace(c)) {\n            c = read();\n        }\n        while (!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 >= -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    public double nextDouble() {\n        return Double.parseDouble(next());\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", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Locale;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.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\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n        int n = in.nextInt();\n        double[][] probability = in.next2DDoubleArray(n, n);\n        double[] dp = new double[1 << n];\n        dp[dp.length - 1] = 1;\n        for (int mask = (1 << n) - 1; mask >= 0; mask--) {\n            int count = Integer.bitCount(mask);\n            if (count <= 1) continue;\n            double multi = 1. / calc(count);\n            for (int i = 0; i < n; i++) {\n                if (NumberUtils.checkBit(mask, i)) {\n                    for (int j = i + 1; j < n; j++) {\n                        if (NumberUtils.checkBit(mask, j)) {\n                            // i eat j\n                            dp[mask - (1 << j)] += multi * probability[i][j] * dp[mask];\n                            // j eat i\n                            dp[mask - (1 << i)] += multi * probability[j][i] * dp[mask];\n                        }\n                    }\n                }\n            }\n        }\n        double[] answer = new double[n];\n        for (int i = 0; i < n; i++) {\n            answer[i] = dp[1 << i];\n        }\n        out.printLine(ArrayUtils.asList(answer).toArray());\n    }\n\n    private static int calc(int x) {\n        return x * (x - 1) / 2;\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 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 & 15;\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    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 count) {\n        double[] result = new double[count];\n        for (int i = 0; i < count; i++) {\n            result[i] = nextDouble();\n        }\n        return result;\n    }\n\n    public double[][] next2DDoubleArray(int n, int m) {\n        double[][] result = new double[n][];\n        for (int i = 0; i < n; i++) {\n            result[i] = nextDoubleArray(m);\n        }\n        return result;\n    }\n\n    }\n\nclass OutputWriter {\n    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 print(Object obj) {\n        writer.print(obj);\n    }\n\n    public void println() {\n        writer.println();\n    }\n\n    public void print(char c) {\n        writer.print(c);\n    }\n\n    public void close() {\n        writer.close();\n    }\n\n    public void printItems(Object... items) {\n        for (int i = 0; i < items.length; i++) {\n            if (i != 0) {\n                print(' ');\n            }\n            print(items[i]);\n        }\n    }\n\n    public void printLine(Object... items) {\n        printItems(items);\n        println();\n    }\n\n}\n\nclass NumberUtils {\n\n    public static boolean checkBit(int mask, int bit) {\n        return (mask & (1 << bit)) != 0;\n    }\n\n    }\n\nclass ArrayUtils {\n\n    private ArrayUtils() {\n    }\n\n    public static List<Double> asList(double[] array) {\n        return new DoubleList(array);\n    }\n\n    private static class DoubleList extends AbstractList<Double> {\n        double[] array;\n\n        private DoubleList(double[] array) {\n            this.array = array;\n        }\n\n        public Double set(int index, Double element) {\n            double result = array[index];\n            array[index] = element;\n            return result;\n        }\n\n        public Double get(int index) {\n            return array[index];\n        }\n\n        public int size() {\n            return array.length;\n        }\n    }\n\n    }\n\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Fish\n{\n    public static void main(String[] args) throws Exception { new Fish(); }\n   \n    public Fish() throws Exception\n    {\n        Scanner sc = new Scanner(System.in);\n        int N = sc.nextInt();\n        double[][] P = new double[N][N];\n        for(int i = 0; i < N; i++)\n            for(int j = 0; j < N; j++)\n                P[i][j] = sc.nextDouble();\n\n        \n        double[] best = new double[1 << N];\n        best[(1 << N)-1] = 1;\n        for(int mask = (1 << N)-1; mask > 0; mask--)\n        {\n            int C = Integer.bitCount(mask);\n            if(C == 1) continue;\n            for(int i = 0; i < N; i++) if (on(mask, i))\n                for(int j = i+1; j < N; j++) if(on(mask, j))\n                {\n                    int nmask = mask & ~(1 << j);\n                    best[nmask] += P[i][j] * best[mask] * 2.0 / (C*(C-1.0));\n                    nmask = mask & ~(1 << i);\n                    \n                    best[nmask] += P[j][i] * best[mask] * 2.0/ (C*(C-1.0));\n                }\n        }\n\n        for(int i = 0; i < N; i++)\n            System.out.printf(\"%.7f \", best[1 << i] + 1e-9);\n        System.out.println();\n    }\n\n    boolean on(int mask, int pos) { return (mask & (1 << pos)) > 0; }\n\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n    static double[] dp;\n    static int[] oneCount;\n    static int end;\n    static int n;\n    static double[][] prob;\n    public static double solve(int mask) {\n        if(mask==end) return 1;\n        int oneC=0,zeroC=0;\n        for(int i=0;i<n;i++) {\n            if((mask|(1<<i))==mask) oneC++;\n            else zeroC++;\n        }\n        double res=0;\n        for(int i=0;i<n;i++) {\n            if((mask|(1<<i))!=mask) continue;\n            for(int j=0;j<n;j++) {\n                //\n                if((mask|(1<<j))==mask) continue;\n                //System.out.println(i+\" \"+j+\" \"+prob[i][j]+\" \"+Integer.toBinaryString(mask)+\" \"+oneC+\" \"+zeroC);\n                res+=(1.0/((oneC*(oneC+1))/2))*prob[i][j]*solve(mask|(1<<j));\n            }\n        }\n        return dp[mask]=res;\n    }\n    public static void main(String[] args) {\n        Scanner sc=new Scanner(System.in);\n        n=sc.nextInt();\n        prob=new double[n][n];\n        for(int i=0;i<n;i++) \n            for(int j=0;j<n;j++)\n                prob[i][j]=sc.nextDouble();\n        dp=new double[1<<n];\n        oneCount=new int[1<<n];\n        int c;\n        for(int i=0;i<dp.length;i++) {\n            c=0;\n            for(int j=0;j<n;j++) {\n                if((i|(1<<j))==i) c++;\n            }\n            oneCount[i]=c;\n        }\n        end=(1<<n)-1;\n        double res,rad;\n        int count;\n        for(int k=end;k>0;k--) {\n            if(k==end) dp[k]=1;\n            else {\n                res=0;\n                count=oneCount[k];\n                count=count*(count+1);\n                count>>=1;\n                rad=1.0/count;\n                //System.out.println(rad+\" \"+count);\n                for(int i=0;i<n;i++) {\n                    if((k|(1<<i))!=k) continue;\n                    for(int j=0;j<n;j++) {\n                        //\n                        if((k|(1<<j))==k) continue;\n                        //System.out.println(i+\" \"+j+\" \"+prob[i][j]+\" \"+Integer.toBinaryString(mask)+\" \"+oneC+\" \"+zeroC);\n                        res+=rad*prob[i][j]*dp[k|(1<<j)];\n                    }\n                }\n                dp[k]=res;\n            }\n        }\n        //Arrays.fill(dp, -1);\n        for(int i=0;i<n;i++)\n            System.out.print(dp[1<<i]+\" \");\n            //System.out.print(solve(1<<i)+\" \");\n//      for(int i=0;i<18;i++){\n//          for(int k=0;k<18;k++)\n//              System.out.print(Math.random()+\" \");\n//          System.out.println();\n//      }\n    }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists()) {\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t}\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\t\n\t\tnew Main().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\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\tint N = nextInt();\n\t\tdouble[][] a = new double [N][N];\n\t\t\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tfor (int j = 0; j < N; j++)\n\t\t\t\ta[i][j] = nextDouble();\n\t\t\n\t\tint NN = 1 << N;\n\t\t\n\t\tdouble[] dp = new double [NN];\n\t\tdp[NN - 1] = 1.0;\n\t\t\n\t\tfor (int mask = NN - 1; mask > 0; mask--) {\n\t\t\tint b = Integer.bitCount(mask);\n\t\t\tif (b <= 1)\n\t\t\t\tcontinue;\n\n\t\t\tdouble k = 2.0 / (b * (b - 1));\n\t\t\t\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tif ((mask & (1 << i)) == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\t\n\t\t\t\tfor (int j = i + 1; j < N; j++) {\n\t\t\t\t\tif ((mask & (1 << j)) == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t\tdouble p = a[i][j];\n\t\t\t\t\tdp[mask & (~(1 << j))] += k * p * dp[mask];\n\t\t\t\t\tdp[mask & (~(1 << i))] += k * (1.0 - p) * dp[mask];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.printf(Locale.US, \"%.8f\", dp[1]);\n\t\t\n\t\tfor (int i = 1, ind = 2; i < N; ind <<= 1, i++)\n\t\t\tout.printf(Locale.US, \" %.8f\", dp[ind]);\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\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", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "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\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\n\t\tint n = in.nextInt();\n\n\t\tdouble[][] p = new double[n][n];\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < n; j++) p[i][j] = in.nextDouble();\n\n\t\tdouble[] q = new double[1 << n];\n\t\tq[(1 << n) - 1] = 1;\n\t\tfor (int mask = (1 << n) - 1; mask > 0; mask--) {\n\t\t\tint count = 0;\n\n\t\t\tfor (int t = 0; t < n; t++) if (((1 << t) & mask) != 0) count++;\n\t\t\tif (count <= 1) continue;\n\t\t\tcount = count*(count - 1)/2;\n\n\t\t\tfor (int t = 0; t < n; t++) if (((1 << t) & mask) != 0)\n\t\t\t\tfor (int s = 0; s < t; s++) if (((1 << s) & mask) != 0) {\n\t\t\t\t\tq[mask - (1 << t)] += q[mask] / count * p[s][t];\n\t\t\t\t\tq[mask - (1 << s)] += q[mask] / count * p[t][s];\n\t\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < n; i++) out.print(q[1 << i] + \" \");\n\n\t\tout.close();\n\t}\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class BetaRound16_E 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 BetaRound16_E(), \"\", 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\tdouble[] p;\n\tint n;\n\tdouble[][] a;\n\t\n\tvoid solve() throws IOException {\n\t\tn = readInt();\n\t\ta = new double[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\ta[i][j] = readDouble();\n\t\t\t}\n\t\t}\n\t\tp = new double[1 << n];\n\t\tArrays.fill(p, -1);\n\t\tp[(1 << n) - 1] = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tout.printf(\"%.12f \", p(1 << i));\n\t\t}\n\t}\n\t\n\tdouble p(int mask) {\n\t\tif (p[mask] != -1) return p[mask];\n\t\tdouble ans = 0;\n\t\tfor (int eaten = 0; eaten < n; eaten++) {\n\t\t\tint prev = mask | (1 << eaten);\n\t\t\tif (prev != mask) {\n\t\t\t\tfor (int eats = 0; eats < n; eats++) {\n\t\t\t\t\tif ((mask & (1 << eats)) != 0) {\n\t\t\t\t\t\tans += a[eats][eaten] * p(prev);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint bc = Integer.bitCount(mask);\n\t\tint norm = bc * (bc + 1) / 2;\n\t\treturn p[mask] = ans / norm;\n\t}\n\t\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "// by agus.mw\nimport java.util.*;\nimport java.io.*;\n\npublic class Main{\n  public static void main(String[] args) throws Exception {\n    new Main().doWork();\n  }\n  void doWork() throws Exception{\n    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));\n    \n    int ncase = Integer.valueOf(reader.readLine());\n    double[][] p = new double[ncase][];\n    for(int icase=0;icase<ncase;icase++){\n      p[icase] = toDoubleArray(reader.readLine());\n    }\n    double[] prob = new double[1<<ncase];\n    prob[0] = 1;\n    for(int x=0;x<(1<<ncase);x++){\n      double cp = prob[x];\n      int count = 0;\n      for(int i=0;i<ncase;i++){\n        if((x&(1<<i))!=0) continue;\n        count ++;\n      }\n      if(count == 1) continue;\n      double np = cp*2.0/(count)/(count-1);\n      for(int i=0;i<ncase;i++){\n        if((x&(1<<i))!=0) continue;\n        for(int j=i+1;j<ncase;j++){\n          if((x&(1<<j))!=0) continue;\n          prob[x^(1<<j)] += np*p[i][j];\n          prob[x^(1<<i)] += np*p[j][i];\n        }\n      }\n    }\n    String out = \"\";\n    for(int i=0;i<ncase;i++){\n      if(i>0) out += \" \";\n      int index = ((1<<ncase)-1)^(1<<i);\n      out += String.format(\"%.6f\",prob[index]);\n    }\n    out += \"\\r\\n\";\n    writer.write(out,0,out.length());\n    writer.flush();\n    writer.close();\n    reader.close();\n  }\n  String process(){\n    return \"1\";\n  }\n  double[] toDoubleArray(String line){\n    String[] p = line.split(\"[ ]+\");\n    double[] out = new double[p.length];\n    for(int i=0;i<p.length;i++) out[i] = Double.valueOf(p[i]);\n    return out;\n  }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.util.Arrays.*;\n\npublic class E implements Runnable\n{\n    public static void main(String[] args) throws IOException\n    {\n        new Thread(null, new E(), \"\", 1 << 20).start();\n    }   \n    \n    BufferedReader input;\n    PrintWriter out;\n    String file = \"input\";\n    \n    public void run()\n    {\n        try\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            solve();\n            \n            out.close();    \n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n    \n    void solve() throws IOException\n    {\n        int n = Integer.parseInt(input.readLine());\n        double[][] p = new double[n][n];\n        for(int i = 0; i < n; i++)\n        {\n            StringTokenizer st = new StringTokenizer(input.readLine());\n            for(int j = 0; j < n; j++) \n            {\n                p[i][j] = Double.parseDouble(st.nextToken());\n            }\n        }\n        double[] dp = new double[1 << n];\n        int mask = (1 << n) - 1;\n        dp[mask] = 1;\n        for(int w = mask; w > 0; w--)\n        {\n            int count = 0;\n            for(int i = 0; i < n; i++)\n                for(int j = i + 1; j < n; j++)\n                    if((w >> i & 1) != 0 && (w >> j & 1) != 0) count++;\n            \n            if(count == 0) continue;\n            for(int i = 0; i < n; i++)\n                for(int j = i + 1; j < n; j++)\n                    if((w >> i & 1) != 0 && (w >> j & 1) != 0)\n                    {\n                        dp[w ^ (1 << i)] += 1.0 / count * p[j][i] * dp[w];\n                        dp[w ^ (1 << j)] += 1.0 / count * p[i][j] * dp[w];\n                    }\n        }\n        for(int i = 0; i < n; i++)\n            System.out.print(dp[1 << i] + \" \");\n            \n    }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class f {\n\tstatic int n;\n\tstatic double[][] g;\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\tg = new double[n][n];\n\tfor(int i = 0; i<n; i++)\n\t\tfor(int j = 0; j<n; j++)\n\t\t\tg[i][j] = input.nextDouble();\n\tfor(int i = 0; i<n; i++)\n\t\tfor(int j = 0; j<n; j++)\n\t\t\tg[j][i] = 1 - g[i][j];\n\tfor(int i = 0; i<n; i++)\n\t{\n\t\tdouble[] dp = new double[1<<n];\n\t\tfor(int mask = 0; mask < (1<<n); mask++)\n\t\t{\n\t\t\tif((mask & (1<<i)) == 0)\n\t\t\t{\n\t\t\t\tdp[mask] = 0;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(mask == (1<<i))\n\t\t\t{\n\t\t\t\tdp[mask] = 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint count = Integer.bitCount(mask);\n\t\t\tdouble prob = 1.0 / (count * (count-1)/2);\n\t\t\tfor(int a = 0; a<n; a++)\n\t\t\t{\n\t\t\t\tif((mask & (1<<a)) == 0) continue;\n\t\t\t\tfor(int b = a+1; b<n; b++)\n\t\t\t\t{\n\t\t\t\t\tif((mask & (1<<b)) == 0) continue;\n\t\t\t\t\tdouble p = g[a][b] * dp[mask ^ (1<<b)] + g[b][a] * dp[mask ^ (1<<a)];\n\t\t\t\t\tdp[mask] += p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[mask] *= prob;\n\t\t}\n\t\tout.print(dp[(1<<n)-1]+\" \");\n\t}\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", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/**\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 java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.Exchanger;\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        solve();\n        br.close();\n        out.close();\n    }\n    double dm[];\n    double a[][];\n    boolean fil[];\n    int p[];\n    int n;\n    // x & (x - 1)\n    // 10\n    //\n    void solve() throws  IOException {\n        n = nextInt();\n        a = new double[n][n];\n        for(int i = 0; i < n; ++i)\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        dm = new double[1 << n];\n        fil = new boolean[1 << n];\n        for(int i = 0; i < n; ++i) {\n            out.print(brute((1 << i)) + \" \");\n        }\n    }\n\n    private double brute(int mask) {\n        if (Integer.bitCount(mask) == n) return 1;\n        if (fil[mask]) return dm[mask];\n        int c = Integer.bitCount(mask);\n        double res = 0;\n        double p = 2.0 / (double) (c + 1) / (double)(c ) ;\n        for(int i = 0; i < n; ++i) {\n            for(int j = 0; j < n; ++j) {\n                if ((mask & (1 << i)) == 0 && (mask & (1 << j)) > 0) {\n                    res += a[j][i] * brute(mask ^ (1 << i));\n                }\n            }\n        }\n        res *= p;\n        dm[mask] = res;\n        fil[mask] = true;\n        return dm[mask];\n    }\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}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.DecimalFormat;\n\npublic class ProblemD {\n\n    private double survive(int round, int set) {\n        if (sur[round][set] >= 0)\n            return sur[round][set];\n        double res = 0.0;\n        int count = 0;\n        for(int i=0;i<n;i++) {\n\n            if ((set & (1 << i)) > 0) {\n                double res2 = 0.0;\n                for(int j=0;j<n;j++)\n                    if ((set & (1 << j)) == 0) {\n                        res2 += survive(round - 1, set + (1 << j)) * a[i][j];\n                        count++;\n                    }\n                res += res2;\n            }\n\n        }\n        count = (n-round+1) * (n - round) / 2;\n        sur[round][set] = res / count;\n        return sur[round][set];\n    }\n\n    int n;\n    double[][] a, sur;\n\n    public void solve() {\n        boolean oj = true;\n\n        try {\n            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"inputD.txt\");\n            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"outputD.txt\");\n            BufferedReader br = new BufferedReader(reader);\n            PrintWriter out = new PrintWriter(writer);\n\n            MyTokenizer tok = new MyTokenizer(br.readLine());\n            n = (int)tok.getNum();\n            a = new double[n][n];\n\n            int all = (1 << n) - 1;\n\n            sur = new double[n][all + 1];\n            for(int i=0;i<n;i++) {\n                tok = new MyTokenizer(br.readLine());\n                for(int j=0;j<n;j++) {\n                    a[i][j] = tok.getNum();\n                }\n                for(int j=0;j<=all;j++)\n                    sur[i][j] = -1;\n            }\n\n            DecimalFormat format = new DecimalFormat(\"0.000000\");\n\n            sur[0][all] = 1;\n            double[] res = new double[n];\n            for(int i=0;i<n;i++) {\n                res[i] = survive(n - 1, 1 << i);\n                String sres = format.format(res[i]).replace(',','.');\n                out.printf(\"%s \", sres);\n            }\n\n            br.close();\n            out.close();\n            reader.close();\n            writer.close();\n        }\n        catch (Exception ex) {\n            ex.printStackTrace();\n        }\n        finally {\n        }\n    }\n\n    public static void main(String[] args) {\n        ProblemD f = new ProblemD();\n        f.solve();\n    }\n\n    private class MyTokenizer {\n        private String s;\n        private int cur;\n\n        public MyTokenizer(String s) {\n            this.s = s;\n            cur = 0;\n        }\n\n        public void skip() {\n            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\\n')) {\n                cur++;\n            }\n        }\n\n        public double getNum() {\n            skip();\n            String snum = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.')) {\n                snum += s.charAt(cur);\n                cur++;\n            }\n            return Double.valueOf(snum);\n        }\n\n        public String getString() {\n            skip();\n            String s2 = \"\";\n            while (cur < s.length() && (s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) {\n                s2 += s.charAt(cur);\n                cur++;\n            }\n            return s2;\n        }\n\n        public char getCurrentChar() throws Exception {\n            if (cur < s.length())\n                return s.charAt(cur);\n            else\n                throw new Exception(\"Current character out of string length\");\n        }\n\n        public void moveNextChar() {\n            if (cur < s.length())\n                cur++;\n        }\n\n        public boolean isFinished() {\n            return cur >= s.length();\n        }\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n\n  public void run(){\n    Locale.setDefault(Locale.US);\n    Scanner in = new Scanner(System.in);\n    int n = in.nextInt();\n    double a[][] = new double[n][n];\n    for(int i=0;i<n;i++) for(int j=0;j<n;j++) a[i][j] = in.nextDouble();\n\n    double f[] = new double[1<<n];\n    f[(1<<n)-1] = 1;\n\n    for(int mask = (1<<n)-1;mask > 0;mask--){\n      int k = Integer.bitCount(mask);\n      if (k == 1) continue;\n\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              f[mask&(~(1<<j))]+=f[mask]*a[i][j]/(k*(k-1)/2); \n            }  \n          }\n        }\n      }\n    }\n    for(int i=0;i<n;i++)\n      System.out.print(f[1<<i]+\" \");\n  }\n\n  public static void main(String args[]){\n    new Main().run();\n  }\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\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.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\n\npublic class Main implements Runnable {\t\n\t\n\tint n;\n\tdouble[] prob;\n\tdouble[][] a;\n\t\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\ta = new double[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\ta[i][j] = nextDouble();\n\t\t\t}\n\t\t}\n\t\tprob = new double[1<<n];\n\t\tArrays.fill(prob, 0.0);\n\t\tprob[(1<<n)-1] = 1.0;\n\t\tfor (int i = (1<<n)-1; i > 1; --i) {\n\t\t\tint c = 0;\n\t\t\tfor (int bit = 0; bit < n; ++bit) {\n\t\t\t\tif (((1<<bit) & i) > 0) {\n\t\t\t\t\t++c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdouble k = c * (c - 1) / 2.0;\n\t\t\tfor (int f = 0; f < n; ++f) {\n\t\t\t\tif (((1<<f) & i) > 0) {\n\t\t\t\t\tfor (int s = f+1; s < n; ++s) {\n\t\t\t\t\t\tif (((1<<s) & i) > 0) {\n\t\t\t\t\t\t\tprob[i^(1<<f)] += prob[i] * a[s][f] / k;\n\t\t\t\t\t\t\tprob[i^(1<<s)] += prob[i] * a[f][s] / 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\tfor (int i = 0; i < n; ++i) {\n\t\t\twriter.printf(Locale.US, \"%.6f \", prob[1<<i]);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws InterruptedException {\n\t\t new Thread(null, new Runnable() {\n            public void run() {\n                new Main().run();\n            }\n\t     }, \n\t     \"1\", \n\t     1 << 25).start();\n\t}\n\t\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tboolean fromStandart = true;\n\t\t\treader = new BufferedReader(fromStandart ? new InputStreamReader(System.in) : new FileReader(INFILE));\n            writer = new PrintWriter(new BufferedWriter(fromStandart ? new OutputStreamWriter(System.out) : new FileWriter(OUTFILE)));\n\t\t\ttokenizer = null; \n\t\t\tsolve();\n\t\t\twriter.flush();\n\t\t} catch (Exception error) {\n\t\t\terror.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\t\n\tstatic final String INFILE = \"input.txt\";\n\tstatic final String OUTFILE = \"output.txt\";\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n    PrintWriter writer;\n\n\tint 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 nextString() throws IOException {\n    \treturn reader.readLine();\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    } \t\n\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Locale;\nimport java.util.Scanner;\n\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tnew E().run();\n\t}\n\n\tprivate void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tdouble[][] p = new double[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\tp[i][j] = sc.nextDouble();\n\t\t}\n\t\tsc.close();\n\t\tdouble[] w = new double[1 << n];\n\t\tint max = (1 << n) - 1;\n\t\tw[max] = 1;\n\t\tfor (int mask = max; mask > 0; mask--) {\n\t\t\tint count = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (((mask >> i) & 1) > 0)\n\t\t\t\t\tfor (int j = i + 1; j < n; j++)\n\t\t\t\t\t\tif (((mask >> j) & 1) > 0) {\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\t}\n\t\t\tif (count > 0)\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif (((mask >> i) & 1) > 0)\n\t\t\t\t\t\tfor (int j = i + 1; j < n; j++)\n\t\t\t\t\t\t\tif (((mask >> j) & 1) > 0) {\n\t\t\t\t\t\t\t\tw[mask ^ (1 << j)] += w[mask] * p[i][j] / count;\n\t\t\t\t\t\t\t\tw[mask ^ (1 << i)] += w[mask] * (1 - p[i][j])\n\t\t\t\t\t\t\t\t\t\t/ count;\n\t\t\t\t\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tSystem.out.print(' ');\n\t\t\tSystem.out.printf(\"%.6f\", w[1 << i]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "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\tdouble[][] lake = new double[N][N];\n\t\t\n\t\tfor(int i = 0; i < N; i++){\n\t\t\tString[] input = kek.readLine().split(\" \");\n\t\t\tfor(int j = 0; j < N; j++){\n\t\t\t\tlake[i][j] = Double.parseDouble(input[j]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint pow = (int)Math.pow(2, N);\n\t\tdouble[] res = new double[pow];\n\t\tres[pow - 1] = 1.0;\n\t\t\n\t\tfor(int i = pow - 1; i >= 0; i--){\n\t\t\tint ones = Integer.bitCount(i); // So this is apparently a thing\n\t\t\tint possibleCombos = ones * (ones - 1) /2;\n\t\t\t\n\t\t\tfor(int j = 0; j < N; j++){\n\t\t\t\tif((i >> j) % 2 == 0){ // (X >> Y) literally does the same thing as divis func. Bit operators are weird.\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor(int k = j + 1; k < N; k++){\n\t\t\t\t\tif((i >> k) % 2 == 0){\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tres[i ^ (1 << k)] += res[i] * lake[j][k]/possibleCombos;\n\t\t\t\t\tres[i ^ (1 << j)] += res[i] * lake[k][j]/possibleCombos;\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 < N; i++){\n\t\t\toutkek.print(res[1 << i] + \" \");\n\t\t}\n\t\t\n\t\tkek.close();\n\t\toutkek.close();\n\t}\t\n\t\n\t/*static int divis(int n, int a){\n\t\tfor(int i = 0; i < a; i++){\n\t\t\tn /= 2;\n\t\t}\n\t\treturn n;\n\t}*/\n\t\t\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import 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.Locale;\nimport java.util.StringTokenizer;\n\npublic class Main implements Runnable {\n    \n    // ////////////////////////////////////////////////////////////////////\n    // Solution\n\n    private int n;\n    private int nn;\n    private double[][] a;\n    private double[] dp;\n\n    private void solve() throws Throwable {\n        n = nextInt();\n        nn = 1 << n;\n        a = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                a[i][j] = nextDouble();\n            }\n        }\n        dp = new double[nn];\n        Arrays.fill(dp, -1.0);\n        dp[nn - 1] = 1.0;\n        for (int j = 0; j < n; j++) {\n            pw.format(Locale.US, \"%.7f \", Dp(1 << j));\n        }\n    }\n\n    private double Dp(int i) {\n        if (dp[i] >= 0.0)\n            return dp[i];\n        \n        double ans = 0;\n        int count = Integer.bitCount(i);\n        for (int j = 0; j < n; j++) {\n            int jj = 1 << j;\n            if ((jj & i) == 0) {\n                double p = Dp(jj | i);\n                double pPair = 2.0 / (double)((count + 1) * count);\n                double s = 0;\n                for (int l = 0; l < n; l++) {\n                    int ll = 1 << l;\n                    if ((ll & i) != 0) {\n                        s += a[l][j];\n                    }\n                }\n                ans += p * pPair * s;\n                \n            }\n        }\n        dp[i] = ans;\n        return dp[i];\n    }\n\n    // ////////////////////////////////////////////////////////////////////\n    // Utility functions\n\n    PrintWriter pw;\n    BufferedReader in;\n    StringTokenizer st;\n\n    void initStreams() throws FileNotFoundException {\n        //System.setIn(new FileInputStream(\"1\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n    }\n\n    String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    static Throwable sError;\n\n    public static void main(String[] args) throws Throwable {\n        Thread t = new Thread(new Main());\n        t.start();\n        t.join();\n        if (sError != null) {\n            throw sError;\n        }\n    }\n\n    public void run() {\n        try {\n            initStreams();\n            solve();\n        } catch (Throwable e) {\n            sError = e;\n        } finally {\n            if (pw != null)\n                pw.close();\n        }\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Task2 {\n\n    public static void main(String[] args) throws IOException {\n\n        new Task2().solve();\n\n    }\n\n    //ArrayList<Integer>[] g;\n\n    int mod = 1000000007;\n\n    PrintWriter out;\n\n    int n;\n    int m;\n    //int[][] a = new int[1000][1000];\n\n\n    //int cnt = 0;\n\n    long base = (1L << 63);\n    long P = 31;\n\n    int[][] a;\n\n    void solve() throws IOException {\n\n        //Reader in = new Reader(\"in.txt\");\n        //out = new PrintWriter( new BufferedWriter(new FileWriter(\"output.txt\")) );\n        Reader in = new Reader();\n        PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );\n\n        //BufferedReader br = new BufferedReader( new FileReader(\"in.txt\") );\n        //BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );\n\n        int n = in.nextInt();\n\n        double[][] a = new double[n][n];\n\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < n; j++)\n                a[i][j] = in.nextDouble();\n\n        double[] dp = new double[1 << n];\n\n        dp[(1 << n) - 1] = 1;\n\n        for (int mask = (1 << n) -1; mask >= 0; mask--) {\n\n            int k = Integer.bitCount(mask);\n            double p = 1.0 / (k*(k-1)/2.0);\n\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < n; j++)\n                    if ((mask & (1 << i)) != 0 && (mask & (1 << j)) != 0)\n                        dp[(mask & ~(1 << j))] += p*dp[mask]*a[i][j];\n\n        }\n\n        for (int i = 0; i < n; i++)\n            out.print(dp[1 << i]+\" \");\n\n        out.flush();\n        out.close();\n    }\n\n    long gcd(long a, long b) {\n\n        if (b == 0)\n            return a;\n\n        return gcd(b, a%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    class Pair implements Comparable<Pair>{\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 (b < p.b)\n                return 1;\n\n            if (b > p.b)\n                return -1;\n\n            return 0;\n        }\n\n        //\t\t@Override\n        //\t\tpublic boolean equals(Object o) {\n        //\t\t\tPair p = (Pair) o;\n        //\t\t\treturn a == p.a && b == p.b;\n        //\t\t}\n        //\n        //\t\t@Override\n        //\t\tpublic int hashCode() {\n        //\t\t\treturn Integer.valueOf(a).hashCode() + Integer.valueOf(b).hashCode();\n        //\t\t}\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        String nextLine() throws IOException {\n            return br.readLine();\n        }\n\n    }\n\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport static java.lang.Math.*;\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        long start;\n        if (debug)\n            start = System.nanoTime();\n        InputStream inputStream;\n        OutputStream outputStream;\n        if (useFiles) {\n            inputStream = new FileInputStream(fileName + \".in\");\n            outputStream = new FileOutputStream(fileName + \".out\");\n        } else {\n            inputStream = System.in;\n            outputStream = System.out;\n        }\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        Task solver = new Task(in, out);\n        solver.solve();\n        if(debug)\n            out.println((System.nanoTime() - start) / 1e+9);\n        out.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    byte[][] nextBitMatrix(int n, int m) {\n        byte[][] a = new byte[n][m];\n        for (int i = 0; i < n; i++) {\n            String s = next();\n            for (int j = 0; j < m; j++) {\n                a[i][j] = (byte) (s.charAt(j) - '0');\n            }\n        }\n        return a;\n    }\n\n    char[][] nextCharMatrix(int n, int m) {\n        char[][] a = new char[n][m];\n        for (int i = 0; i < n; i++) {\n            String s = next();\n            for (int j = 0; j < m; j++) {\n                a[i][j] = s.charAt(j);\n            }\n        }\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[] 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\nclass Task {\n    boolean get(int mask, int i){\n        return (mask & (1 << i)) > 0;\n    }\n\n    int zero(int mask, int i){\n        return mask & (~(1 << i));\n    }\n\n    public void solve() {\n        int n = in.nextInt();\n        double[][] a = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++)\n                a[i][j] = in.nextDouble();\n        }\n        double[] d = new double[1 << n];\n        d[(1 << n) - 1] = 1;\n        for (int mask = (1 << n) - 1; mask >= 0; mask--) {\n            int bits = Integer.bitCount(mask);\n            double transfer = 1.0 / (bits * (bits - 1) / 2);\n            for (int i = 0; i < n; i++) {\n                if (get(mask, i)) {\n                    for (int j = i + 1; j < n; j++) {\n                        if (get(mask, j)) {\n                            d[zero(mask, j)] += a[i][j] * transfer * d[mask];\n                            d[zero(mask, i)] += a[j][i] * transfer * d[mask];\n                        }\n                    }\n                }\n            }\n        }\n        for(int i = 0; i < n; i++)\n            out.print(d[1 << i] + \" \");\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", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Locale;\nimport java.util.Scanner;\n\npublic class E {\n    public static void main(String[] args) {\n        new E().solve();\n    }\n    \n    private int c(int n) {\n        return n * (n - 1) / 2;\n    }\n    \n    public void solve() {\n        Locale.setDefault(Locale.US);\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        double[][] pb = new double[n][n];\n        for (int i=0; i<n; ++i)\n            for (int j=0; j<n; ++j)\n                pb[i][j] = sc.nextDouble();\n        \n        int m = (1<<n);\n        double[] dp = new double[m];\n        dp[0] = 1.0f;\n        for (int i=1; i<m; ++i)\n            for (int j=0; j<n; ++j) if ((i & (1<<j)) != 0)\n                for (int k=0; k<n; ++k) if ((i & (1<<k)) == 0)\n                    dp[i] += pb[k][j] * dp[i & ~(1<<j)] / c(n - Integer.bitCount(i) + 1);\n        \n        int w = (1<<n) - 1;\n        for (int i=0; i<n-1; ++i)\n            System.out.printf(\"%.6f \", dp[w & ~(1<<i)]);\n        System.out.printf(\"%.6f\\n\", dp[w & ~(1<<(n-1))]);\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import 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 Fish extends Thread {\n\n    public Fish() {\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    private void solve() throws Throwable {\n        int n = nextInt();\n        double[][] a = new double[n][n];\n        double[] dp = new double[(1 << n)];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        }\n        int limit = (1 << n) - 1;\n        //dp[mask] = probability of current subset (mask) to remain in the end\n        dp[limit] = 1.0;\n        for (int mask = limit; mask > 0; --mask) {\n            int cardinality = Integer.bitCount(mask);\n            int probability = cardinality * (cardinality - 1) / 2;\n            for (int first = 0; first < n; ++first) {\n                if ((mask & powers[first]) != 0) {\n                    for (int second = first + 1; second < n; ++second) {\n                        if ((mask & powers[second]) != 0) {\n                            dp[mask - powers[first]] += dp[mask] * a[second][first] / probability;\n                            dp[mask - powers[second]] += dp[mask] * a[first][second] / probability;\n                        }\n\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            output.printf(\"%.10f \", dp[powers[i]]);\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\n    public static void main(String[] args) {\n        new Fish().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    static int powers[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/14/11\n * Time: 9:53 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 Fish extends Thread {\n\n    public Fish() {\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    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        double[][] a = new double[n][n];\n        double[] dp = new double[(1 << n)];\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                a[i][j] = nextDouble();\n            }\n        }\n        int limit = (1 << n) - 1;\n        //dp[mask] = probability of current subset (mask) to remain in the end\n        dp[limit] = 1.0;\n        for (int mask = limit; mask > 0; --mask) {\n            int cardinality = getOnes(mask);\n            if (cardinality < 2) {\n                continue;\n            }\n            int probability = cardinality * (cardinality - 1) / 2;\n            for (int first = 0; first < n; ++first) {\n                if ((mask & powers[first]) != 0) {\n                    for (int second = first + 1; second < n; ++second) {\n                        if ((mask & powers[second]) != 0) {\n                            dp[mask ^ powers[first]] += dp[mask] * a[second][first] / probability;\n                            dp[mask ^ powers[second]] += dp[mask] * a[first][second] / probability;\n                        }\n\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            output.printf(\"%.10f \", dp[powers[i]]);\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\n    public static void main(String[] args) {\n        new Fish().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    static final int powers[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class Main {\n    \n    public static void main(String[] args) throws Exception { \n        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n        PrintWriter pw = new PrintWriter(System.out);\n        \n        in.nextToken();\n        int n = (int) in.nval;\n        double[][] a = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                in.nextToken();\n                a[i][j] = in.nval;\n            }\n        }\n        \n        double[] dp = new double[1 << n];\n        dp[(1 << n) - 1] = 1.0;\n        \n        for (int mask = (1 << n) - 2; mask > 0; mask--) {\n            int count = Integer.bitCount(mask);\n            double pPair = 2.0 / ((double) count * (count + 1));\n            double ans = 0.0;\n            \n            for (int j = 0; j < n; j++) {\n                int jj = 1 << j;\n                if ((jj & mask) != 0) continue;\n                double p = dp[mask | jj];\n                double s = 0;\n                for (int k = 0; k < n; k++) {\n                    int kk = 1 << k;\n                    if ((kk & mask) == 0) continue;\n                    s += a[k][j];\n                }\n                ans += s * pPair * p;\n            }\n            dp[mask] = ans;\n        }\n        \n        for (int i = 0; i < n; i++) {\n            pw.print(dp[1 << i]);\n            pw.print(' ');\n        }\n        \n        pw.close();\n    }\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.text.DecimalFormat;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic int N;\n\tstatic double[][] p;\n\tstatic DecimalFormat format = new DecimalFormat(\"0.000000\");\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tN = sc.nextInt();\n\t\tp = new double[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\tp[i][j] = sc.nextDouble();\n\t\t\t}\n\t\t}\n\t\tdouble[] memo = new double[1 << N];\n\t\tmemo[memo.length - 1] = 1;\n\t\tfor (int i = N; i >= 2; --i) {\n\t\t\tint[] live = new int[N];\n\t\t\tfor (int j = 0; j < i; ++j) {\n\t\t\t\tlive[N - 1 - j] = 1;\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tint n = toInt(live);\n\t\t\t\tdouble norm = 2.0 / i / (i - 1);\n\t\t\t\tfor (int f1 = 0; f1 < N; ++f1) {\n\t\t\t\t\tif (live[f1] == 0) continue;\n\t\t\t\t\tfor (int f2 = f1 + 1; f2 < N; ++f2) {\n\t\t\t\t\t\tif (live[f2] == 0) continue;\n\t\t\t\t\t\tmemo[n - (1 << f1)] += memo[n] * p[f2][f1] * norm;\n\t\t\t\t\t\tmemo[n - (1 << f2)] += memo[n] * p[f1][f2] * norm;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} while (nextPermutation(live));\n\t\t\t//\t\t\tSystem.out.println(Arrays.toString(memo));\n\t\t}\n\t\tfor (int i = 0; i < N; ++i) {\n\t\t\tSystem.out.print(format.format(memo[1 << i]));\n\t\t\tif (i < N - 1) {\n\t\t\t\tSystem.out.print(\" \");\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int toInt(int[] a) {\n\t\tint ret = 0;\n\t\tfor (int i = 0; i < N; ++i) {\n\t\t\tret += (1 << i) * a[i];\n\t\t}\n\t\treturn ret;\n\t}\n\n\tpublic static boolean nextPermutation(int[] a) {\n\t\tfor (int i = a.length - 1; i > 0; --i) {\n\t\t\tif (a[i - 1] < a[i]) {\n\t\t\t\tint swapIndex = find(a[i - 1], a, i, a.length - 1);\n\t\t\t\tint temp = a[swapIndex];\n\t\t\t\ta[swapIndex] = a[i - 1];\n\t\t\t\ta[i - 1] = temp;\n\t\t\t\tArrays.sort(a, i, a.length);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate static int find(int dest, int[] a, int s, int e) {\n\t\tif (s == e) {\n\t\t\treturn s;\n\t\t}\n\t\tint m = (s + e + 1) / 2;\n\t\treturn a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e);\n\t}\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.text.DecimalFormat;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n\t\n\tpublic Main() {\n\t\tsuper();\n\t}\n\t\n\tpublic static void main(String... args) {\n\t\tMain main = new Main();\n\t\tmain.start();\n\t}\n\t\n\tpublic void start() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tdouble a[][] = new double[n][n];\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = Double.parseDouble(in.next());\n\t\t\n\t\tint nn = 1 << n;\n\t\tdouble p[] = new double[nn];\n\t\tArrays.fill(p, -1.0);\n        p[nn - 1] = 1.0;\n\n\t\tDecimalFormat f = new DecimalFormat();\n\t\tf.applyPattern(\"0.000000\");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i != 0) System.out.print(\" \");\n\t\t\tSystem.out.print(f.format(this.probability(a, p, 1 << i)));\n\t\t}\n\t}\n\t\n\tprivate double probability(double a[][], double p[], int i) {\n        if (p[i] >= 0.0) return p[i];\n        double ans = 0;\n        int count = Integer.bitCount(i);\n        int n = a.length;\n        for (int j = 0; j < n; j++) {\n            int jj = 1 << j;\n            if ((jj & i) == 0) {\n                double d = this.probability(a, p, jj | i);\n                double dPair = 2.0 / (double)((count + 1) * count);\n                double s = 0;\n                for (int l = 0; l < n; l++) {\n                    int ll = 1 << l;\n                    if ((ll & i) != 0) s += a[l][j];\n                }\n                ans += d * dPair * s;\n            }\n        }\n        p[i] = ans;\n        return p[i];\n    }\n\n\n\t\n}", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Fishes {\n\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        int n = s.nextInt();\n        double[][] p = new double[n][n];\n        double[] dp = new double[1 << 18];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                p[i][j] = Double.parseDouble(s.next());\n            }\n        }\n        int last = 1 << n;\n        dp[last - 1] = 1.0;\n        for (int i = last - 2; i > 0; i--) {\n            int res = 0;\n            for (int j = 0; j < n; j++) {\n                if (((1 << j) & i) > 0) res++;\n            }\n            res++;\n            res = res * (res - 1) / 2;\n            for (int j = 0; j < n; j++) {\n                if (((1 << j) & i) == 0) {\n                    for (int z = 0; z < n; z++) {\n                        if (((1 << z) & i) > 0) {\n                            dp[i] += dp[i | (1 << j)] * 1.0 / res * p[z][j];\n                        }\n                    }\n                }\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            System.out.print(dp[1 << i] + \" \");\n        }\n    }\n\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Trung Pham\n */\npublic class E {\n\n    public static double[] dp;\n    public static double[][] data;\n    public static int n;\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n        n = in.nextInt();\n        data = new double[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                data[i][j] = in.nextDouble();\n            }\n        }\n        dp = new double[1 << n];\n        Arrays.fill(dp, -1);\n        for (int i = 0; i < n; i++) {\n            int a = 1 << i;\n            out.print(cal(a) + \" \");\n        }\n        out.close();\n        //System.out.print(builder.toString());\n    }\n\n    public static double cal(int mask) {\n        if (mask == (1 << n) - 1) {\n            //  System.out.println(mask);\n            return 1;\n        }\n        if (dp[mask] != -1) {\n            return dp[mask];\n        }\n        double result = 0;\n        int c = 0;       \n        for (int i = 0; i < n; i++) {\n            int a = 1 << i;\n            if ((a & mask) != 0) {\n                c++;\n                for (int j = 0; j < n; j++) {\n                    int b = 1 << j;\n                    if ((b & mask) == 0) {\n                        result += (data[i][j] * cal(mask | b));\n                    }\n                }\n            }\n        }\n    \n        int nC2 = (c + 1) * c / 2;\n        dp[mask] = result / nC2;\n        return dp[mask];\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", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.math.BigDecimal;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\n\n\npublic class Task16e {\n\n\t/**\n\t * @param args\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\tdouble[][] prob = new double[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\tprob[i][j] = sc.nextDouble();\n\t\t\t}\n\t\t}\n\t\tdouble[] var = new double[1 << n];\n\t\tboolean[] was = new boolean[1 << n];\n\t\tArrays.fill(var, 0.0);\n\t\tArrays.fill(was, false);\n\t\twas[0] = true;\n\t\tvar[(1 << n) - 1] = 1.0;\n\t\tSet<Integer> cr = new HashSet<Integer>();\n\t\tSet<Integer> nx = new HashSet<Integer>();\n\t\tnx.add((1 << n) - 1);\n\t\tboolean[] fish = new boolean[n];\n\t\tfor (int cnt = 0; cnt < n -1; cnt++) {\n\t\t\tcr.clear();\n\t\t\tcr.addAll(nx);\n\t\t\tnx.clear();\n\t\t\tfor (Iterator<Integer> iterator = cr.iterator(); iterator.hasNext();) {\n\t\t\t\tint curr = iterator.next();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tfish[i] = ((1 << i) & curr) != 0;\n\t\t\t\t}\n\t\t\t\tint fishn = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (fish[i]) fishn++;\n\t\t\t\t}\n\t\t\t\tif (fishn == 1) continue;\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (!fish[i]) continue;\n\t\t\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\t\t\tif (!fish[j]) continue;\n\t\t\t\t\t\tint woi = curr & ~(1 << i);\n\t\t\t\t\t\tint woj = curr & ~(1 << j);\n\t\t\t\t\t\tvar[woi] += var[curr] * prob[j][i];\n\t\t\t\t\t\tvar[woj] += var[curr] * prob[i][j];\n\t\t\t\t\t\tnx.add(woi);\n\t\t\t\t\t\tnx.add(woj);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdouble sum = 0.0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsum += var[1 << i];\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tSystem.out.printf(\"%.6f \", var[1 << i] / sum);\n\t\t}\n\t}\n\n}\n", "complexity": "np", "problem": "16_E. Fish", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author 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        TaskE2 solver = new TaskE2();\n        int testCount = Integer.parseInt(in.next());\n        for (int i = 1; i <= testCount; i++) {\n            solver.solve(i, in, out);\n        }\n        out.close();\n    }\n\n    static class TaskE2 {\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int n = in.readInt();\n            int m = in.readInt();\n            int[][] a = in.readIntTable(n, m);\n            int[][] id = new int[n + 1][1 << n];\n            int[][] val = new int[n + 1][1 << n];\n            ArrayUtils.fill(id, m);\n            int[] sum = new int[1 << n];\n            int[] low = new int[1 << n];\n            boolean[] base = new boolean[1 << n];\n            int[] vv = new int[1 << n];\n            for (int i = 1; i < (1 << n); i++) {\n                low[i] = Integer.bitCount(Integer.lowestOneBit(i) - 1);\n                int current = i;\n                base[i] = true;\n                vv[i] = i;\n                for (int j = 0; j < n; j++) {\n                    current = current << 1;\n                    current += current >> n;\n                    current -= (current >> n) << n;\n                    if (current < i) {\n                        base[i] = false;\n                        vv[i] = vv[current];\n                        break;\n                    }\n                }\n            }\n            for (int i = 0; i < m; i++) {\n                for (int j = 1; j < (1 << n); j++) {\n                    sum[j] = sum[j - (1 << low[j])] + a[low[j]][i];\n                }\n                for (int j = 1; j < (1 << n); j++) {\n                    sum[vv[j]] = Math.max(sum[vv[j]], sum[j]);\n                }\n                for (int j = 1; j < (1 << n); j++) {\n                    if (!base[j]) {\n                        continue;\n                    }\n                    for (int k = n - 1; k >= 0; k--) {\n                        if (sum[j] > val[k][j]) {\n                            val[k + 1][j] = val[k][j];\n                            id[k + 1][j] = id[k][j];\n                            val[k][j] = sum[j];\n                            id[k][j] = i;\n                        } else {\n                            break;\n                        }\n                    }\n                }\n            }\n            int[] tempVal = new int[n];\n            int[] tempId = new int[n];\n            for (int i = 1; i < (1 << n); i++) {\n                if (!base[i]) {\n                    for (int j = 0; j < n; j++) {\n                        val[j][i] = val[j][vv[i]];\n                        id[j][i] = id[j][vv[i]];\n                    }\n                } else {\n                    for (int j = 0; j < n; j++) {\n                        tempVal[j] = val[j][i];\n                        tempId[j] = id[j][i];\n                    }\n                    ArrayUtils.orderBy(tempId, tempVal);\n                    for (int j = 0; j < n; j++) {\n                        val[j][i] = tempVal[j];\n                        id[j][i] = tempId[j];\n                    }\n                }\n            }\n            int[] at = new int[1 << n];\n            int[] current = new int[1 << n];\n            int[] next = new int[1 << n];\n            int all = (1 << n) - 1;\n            for (int i = 0; i < m; i++) {\n                System.arraycopy(current, 0, next, 0, (1 << n));\n                for (int j = 1; j < (1 << n); j++) {\n                    if (at[j] == n || id[at[j]][j] != i) {\n                        continue;\n                    }\n                    int other = all - j;\n                    for (int k = other; k > 0; k = (k - 1) & other) {\n                        next[k + j] = Math.max(next[k + j], current[k] + val[at[j]][j]);\n                    }\n                    next[j] = Math.max(next[j], val[at[j]][j]);\n                    at[j]++;\n                }\n                int[] temp = current;\n                current = next;\n                next = temp;\n            }\n            out.printLine(current[all]);\n        }\n\n    }\n\n    static abstract class IntAbstractStream implements IntStream {\n        public String toString() {\n            StringBuilder builder = new StringBuilder();\n            boolean first = true;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                if (first) {\n                    first = false;\n                } else {\n                    builder.append(' ');\n                }\n                builder.append(it.value());\n            }\n            return builder.toString();\n        }\n\n        public boolean equals(Object o) {\n            if (!(o instanceof IntStream)) {\n                return false;\n            }\n            IntStream c = (IntStream) o;\n            IntIterator it = intIterator();\n            IntIterator jt = c.intIterator();\n            while (it.isValid() && jt.isValid()) {\n                if (it.value() != jt.value()) {\n                    return false;\n                }\n                it.advance();\n                jt.advance();\n            }\n            return !it.isValid() && !jt.isValid();\n        }\n\n        public int hashCode() {\n            int result = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                result *= 31;\n                result += it.value();\n            }\n            return result;\n        }\n\n    }\n\n    static interface IntList extends IntReversableCollection {\n        public abstract int get(int index);\n\n        public abstract void set(int index, int value);\n\n        public abstract void addAt(int index, int value);\n\n        public abstract void removeAt(int index);\n\n        default public void swap(int first, int second) {\n            if (first == second) {\n                return;\n            }\n            int temp = get(first);\n            set(first, get(second));\n            set(second, temp);\n        }\n\n        default public IntIterator intIterator() {\n            return new IntIterator() {\n                private int at;\n                private boolean removed;\n\n                public int value() {\n                    if (removed) {\n                        throw new IllegalStateException();\n                    }\n                    return get(at);\n                }\n\n                public boolean advance() {\n                    at++;\n                    removed = false;\n                    return isValid();\n                }\n\n                public boolean isValid() {\n                    return !removed && at < size();\n                }\n\n                public void remove() {\n                    removeAt(at);\n                    at--;\n                    removed = true;\n                }\n            };\n        }\n\n        default public void add(int value) {\n            addAt(size(), value);\n        }\n\n        default public IntList sort(IntComparator comparator) {\n            Sorter.sort(this, comparator);\n            return this;\n        }\n\n        default public IntList subList(final int from, final int to) {\n            return new IntList() {\n                private final int shift;\n                private final int size;\n\n                {\n                    if (from < 0 || from > to || to > IntList.this.size()) {\n                        throw new IndexOutOfBoundsException(\"from = \" + from + \", to = \" + to + \", size = \" + size());\n                    }\n                    shift = from;\n                    size = to - from;\n                }\n\n                public int size() {\n                    return size;\n                }\n\n                public int get(int at) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    return IntList.this.get(at + shift);\n                }\n\n                public void addAt(int index, int value) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void removeAt(int index) {\n                    throw new UnsupportedOperationException();\n                }\n\n                public void set(int at, int value) {\n                    if (at < 0 || at >= size) {\n                        throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size());\n                    }\n                    IntList.this.set(at + shift, value);\n                }\n\n                public IntList compute() {\n                    return new IntArrayList(this);\n                }\n            };\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 int[] toArray() {\n            int size = size();\n            int[] array = new int[size];\n            int i = 0;\n            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n                array[i++] = it.value();\n            }\n            return array;\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 interface IntIterator {\n        public int value() throws NoSuchElementException;\n\n        public boolean advance();\n\n        public boolean isValid();\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int[][] readIntTable(int rowCount, int columnCount) {\n            int[][] table = new int[rowCount][];\n            for (int i = 0; i < rowCount; i++) {\n                table[i] = readIntArray(columnCount);\n            }\n            return table;\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 String readString() {\n            int c = read();\n            while (isSpaceChar(c)) {\n                c = read();\n            }\n            StringBuilder res = new StringBuilder();\n            do {\n                if (Character.isValidCodePoint(c)) {\n                    res.appendCodePoint(c);\n                }\n                c = read();\n            } while (!isSpaceChar(c));\n            return res.toString();\n        }\n\n        public boolean isSpaceChar(int c) {\n            if (filter != null) {\n                return filter.isSpaceChar(c);\n            }\n            return isWhitespace(c);\n        }\n\n        public static boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public String next() {\n            return readString();\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n\n    static class Range {\n        public static IntList range(int from, int to) {\n            int[] result = new int[Math.abs(from - to)];\n            int current = from;\n            if (from <= to) {\n                for (int i = 0; i < result.length; i++) {\n                    result[i] = current++;\n                }\n            } else {\n                for (int i = 0; i < result.length; i++) {\n                    result[i] = current--;\n                }\n            }\n            return new IntArray(result);\n        }\n\n    }\n\n    static class ArrayUtils {\n        public static void fill(int[][] array, int value) {\n            for (int[] row : array) {\n                Arrays.fill(row, value);\n            }\n        }\n\n        public static int[] range(int from, int to) {\n            return Range.range(from, to).toArray();\n        }\n\n        public static int[] createOrder(int size) {\n            return range(0, size);\n        }\n\n        public static int[] sort(int[] array, IntComparator comparator) {\n            return sort(array, 0, array.length, comparator);\n        }\n\n        public static int[] sort(int[] array, int from, int to, IntComparator comparator) {\n            if (from == 0 && to == array.length) {\n                new IntArray(array).sort(comparator);\n            } else {\n                new IntArray(array).subList(from, to).sort(comparator);\n            }\n            return array;\n        }\n\n        public static int[] order(final int[] array) {\n            return sort(createOrder(array.length), new IntComparator() {\n                public int compare(int first, int second) {\n                    if (array[first] < array[second]) {\n                        return -1;\n                    }\n                    if (array[first] > array[second]) {\n                        return 1;\n                    }\n                    return 0;\n                }\n            });\n        }\n\n        public static void orderBy(int[] base, int[]... arrays) {\n            int[] order = ArrayUtils.order(base);\n            order(order, base);\n            for (int[] array : arrays) {\n                order(order, array);\n            }\n        }\n\n        public static void order(int[] order, int[] array) {\n            int[] tempInt = new int[order.length];\n            for (int i = 0; i < order.length; i++) {\n                tempInt[i] = array[order[i]];\n            }\n            System.arraycopy(tempInt, 0, array, 0, array.length);\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        public void set(int index, int value) {\n            if (index >= size) {\n                throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n            }\n            data[index] = value;\n        }\n\n        public int[] toArray() {\n            return Arrays.copyOf(data, size);\n        }\n\n    }\n\n    static interface IntReversableCollection extends IntCollection {\n    }\n\n    static class IntArray extends IntAbstractStream implements IntList {\n        private int[] data;\n\n        public IntArray(int[] arr) {\n            data = arr;\n        }\n\n        public int size() {\n            return data.length;\n        }\n\n        public int get(int at) {\n            return data[at];\n        }\n\n        public void addAt(int index, int value) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void removeAt(int index) {\n            throw new UnsupportedOperationException();\n        }\n\n        public void set(int index, int value) {\n            data[index] = value;\n        }\n\n    }\n\n    static interface IntComparator {\n        public int compare(int first, int second);\n\n    }\n\n    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {\n        public IntIterator intIterator();\n\n        default public Iterator<Integer> iterator() {\n            return new Iterator<Integer>() {\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 Sorter {\n        private static final int INSERTION_THRESHOLD = 16;\n\n        private Sorter() {\n        }\n\n        public static void sort(IntList list, IntComparator comparator) {\n            quickSort(list, 0, list.size() - 1, (Integer.bitCount(Integer.highestOneBit(list.size()) - 1) * 5) >> 1,\n                    comparator);\n        }\n\n        private static void quickSort(IntList list, int from, int to, int remaining, IntComparator comparator) {\n            if (to - from < INSERTION_THRESHOLD) {\n                insertionSort(list, from, to, comparator);\n                return;\n            }\n            if (remaining == 0) {\n                heapSort(list, from, to, comparator);\n                return;\n            }\n            remaining--;\n            int pivotIndex = (from + to) >> 1;\n            int pivot = list.get(pivotIndex);\n            list.swap(pivotIndex, to);\n            int storeIndex = from;\n            int equalIndex = to;\n            for (int i = from; i < equalIndex; i++) {\n                int value = comparator.compare(list.get(i), pivot);\n                if (value < 0) {\n                    list.swap(storeIndex++, i);\n                } else if (value == 0) {\n                    list.swap(--equalIndex, i--);\n                }\n            }\n            quickSort(list, from, storeIndex - 1, remaining, comparator);\n            for (int i = equalIndex; i <= to; i++) {\n                list.swap(storeIndex++, i);\n            }\n            quickSort(list, storeIndex, to, remaining, comparator);\n        }\n\n        private static void heapSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = (to + from - 1) >> 1; i >= from; i--) {\n                siftDown(list, i, to, comparator, from);\n            }\n            for (int i = to; i > from; i--) {\n                list.swap(from, i);\n                siftDown(list, from, i - 1, comparator, from);\n            }\n        }\n\n        private static void siftDown(IntList list, int start, int end, IntComparator comparator, int delta) {\n            int value = list.get(start);\n            while (true) {\n                int child = ((start - delta) << 1) + 1 + delta;\n                if (child > end) {\n                    return;\n                }\n                int childValue = list.get(child);\n                if (child + 1 <= end) {\n                    int otherValue = list.get(child + 1);\n                    if (comparator.compare(otherValue, childValue) > 0) {\n                        child++;\n                        childValue = otherValue;\n                    }\n                }\n                if (comparator.compare(value, childValue) >= 0) {\n                    return;\n                }\n                list.swap(start, child);\n                start = child;\n            }\n        }\n\n        private static void insertionSort(IntList list, int from, int to, IntComparator comparator) {\n            for (int i = from + 1; i <= to; i++) {\n                int value = list.get(i);\n                for (int j = i - 1; j >= from; j--) {\n                    if (comparator.compare(list.get(j), value) <= 0) {\n                        break;\n                    }\n                    list.swap(j, j + 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 close() {\n            writer.close();\n        }\n\n        public void printLine(int i) {\n            writer.println(i);\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class E {\n    public static void main(String[] args) throws Exception {\n        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n        int T = Integer.parseInt(bf.readLine());\n        for(int t=0; t<T; t++) {\n          StringTokenizer st = new StringTokenizer(bf.readLine());\n          int n = Integer.parseInt(st.nextToken());\n          int m = Integer.parseInt(st.nextToken());\n          int[][] a = new int[n][m];\n          for(int i=0; i<n; i++) {\n            st = new StringTokenizer(bf.readLine());\n            for(int j=0; j<m; j++) a[i][j] = Integer.parseInt(st.nextToken());\n\n          }\n          // small case\n          int[] max = new int[m];\n          for(int i=0; i<n; i++) {\n            for(int j=0; j<m; j++) {\n              if(a[i][j] > max[j]) max[j] = a[i][j];\n            }\n          }\n          int[][] pos = new int[m][2];\n          for(int i=0; i<m; i++) {\n            pos[i][0] = max[i];\n            pos[i][1] = i;\n          }\n          Arrays.sort(pos, new Comparator<int[]>() {\n            @Override\n            public int compare(int[] o1, int[] o2) {\n              return Integer.compare(o2[0], o1[0]);\n            }\n          });\n\n          int[][] new_a = new int[n][Math.min(n,m)];\n          for(int i=0; i<n; i++) {\n            for(int j=0; j<Math.min(n,m); j++) {\n              new_a[i][j] = a[i][pos[j][1]];\n            }\n          }\n          int exp = 1; for(int i=0; i<Math.min(n,m); i++) exp *= n;\n          int maxval = -1;\n          for(int i=0; i<exp; i++) {\n          //  int val = i;\n            int sum = 0;\n            for(int j=0; j<n; j++) {\n              int toAdd = 0;\n              int val = i;\n              for(int k=0; k<Math.min(n,m); k++) {\n                int tooAdd = new_a[(j+val)%n][k];\n                val /= n;\n                if(tooAdd > toAdd) toAdd = tooAdd;\n              }\n              sum += toAdd;\n            }\n            if(sum > maxval) maxval = sum;\n          }\n          out.println(maxval);\n\n        }\n\n        // StringTokenizer st = new StringTokenizer(bf.readLine());\n        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n        // int n = Integer.parseInt(st.nextToken());\n\n        out.close(); System.exit(0);\n    }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class mainE {\n    public static PrintWriter out = new PrintWriter(System.out);\n    public static FastScanner enter = new FastScanner(System.in);\n    public static void main(String[] args) throws IOException {\n        int t=enter.nextInt();\n        for (int i = 0; i < t; i++) {\n            solve();\n        }\n        out.close();\n    }\n    public static int[][] arr=new int[13][2010];\n    public static pair[] par= new pair[2010];\n    private static void solve() throws IOException{\n        int n=enter.nextInt();\n        int m=enter.nextInt();\n        for (int i = 0; i <n ; i++) {\n            for (int j = 0; j <m ; j++) {\n                arr[i][j]=enter.nextInt();\n            }\n        }\n        for (int i = 0; i <n ; i++) {\n            for (int j = m; j <m+3 ; j++) {\n                arr[i][j]=0;\n            }\n        }\n        m=m+3;\n\n        for (int i = 0; i <m ; i++) {\n            int max=-1;\n            for (int j = 0; j <n ; j++) {\n                max=Math.max(arr[j][i], max);\n            }\n            par[i]=new pair(max,i);\n        }\n        Arrays.sort(par,0,m, pair::compareTo);\n\n        int i0=par[0].st;\n        int i1=par[1].st;\n        int i2=par[2].st;\n        int i3=par[3].st;\n        int ans=-1;\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                    for (int l = 0; l <n ; l++) {\n                        int first=Math.max(Math.max(arr[i][i0],arr[j][i1]), Math.max(arr[k][i2],arr[l][i3]));\n                        int second=Math.max(Math.max(arr[(i+1)%n][i0],arr[(j+1)%n][i1]), Math.max(arr[(k+1)%n][i2],arr[(l+1)%n][i3]));\n                        int third=Math.max(Math.max(arr[(i+2)%n][i0],arr[(j+2)%n][i1]), Math.max(arr[(k+2)%n][i2],arr[(l+2)%n][i3]));\n                        int fourth=Math.max(Math.max(arr[(i+3)%n][i0],arr[(j+3)%n][i1]), Math.max(arr[(k+3)%n][i2],arr[(l+3)%n][i3]));\n                        if(n==1) {\n                            second=0;\n                            third=0;\n                            fourth=0;\n                        }\n                        else if(n==2){\n                            third=0;\n                            fourth=0;\n                        }\n                        else if(n==3){\n                            fourth=0;\n                        }\n                        ans=Math.max(ans, first+second+fourth+third);\n\n                    }\n                }\n            }\n        }\n        System.out.println(ans);\n\n\n\n    }\n\n    static class pair implements Comparable<pair>{\n        int max,st;\n\n        public pair(int max, int st) {\n            this.max = max;\n            this.st = st;\n        }\n\n        @Override\n        public int compareTo(pair o) {\n            return -Integer.compare(max, o.max);\n        }\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer stok;\n\n        FastScanner(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        String next() 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(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        char nextChar() throws IOException {\n            return (char) (br.read());\n        }\n\n        String nextLine() throws IOException {\n            return br.readLine();\n        }\n    }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskE2 solver = new TaskE2();\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 TaskE2 {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            TaskE2.Column[] columns = new TaskE2.Column[m];\n            for (int i = 0; i < m; ++i) columns[i] = new TaskE2.Column(new int[n]);\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    columns[j].vals[i] = in.nextInt();\n                }\n            }\n            for (int i = 0; i < m; ++i) columns[i].initMax();\n            Arrays.sort(columns, new Comparator<TaskE2.Column>() {\n\n                public int compare(TaskE2.Column o1, TaskE2.Column o2) {\n                    return o2.max - o1.max;\n                }\n            });\n            if (columns.length > n) {\n                columns = Arrays.copyOf(columns, n);\n            }\n            out.println(solveOne(columns));\n        }\n\n        private int solveOne(TaskE2.Column[] columns) {\n            int n = columns[0].vals.length;\n            int[] best = new int[1 << n];\n            int[] next = new int[1 << n];\n            int[] tmp = new int[1 << n];\n            for (TaskE2.Column c : columns) {\n                System.arraycopy(best, 0, next, 0, best.length);\n                for (int rot = 0; rot < n; ++rot) {\n                    System.arraycopy(best, 0, tmp, 0, best.length);\n                    for (int i = 0, pos = rot; i < n; ++i, ++pos) {\n                        if (pos >= n) pos = 0;\n                        int val = c.vals[pos];\n                        for (int j = 0; j < tmp.length; ++j)\n                            if ((j & (1 << i)) == 0) {\n                                tmp[j ^ (1 << i)] = Math.max(tmp[j ^ (1 << i)], tmp[j] + val);\n                            }\n                    }\n                    for (int j = 0; j < tmp.length; ++j) {\n                        next[j] = Math.max(next[j], tmp[j]);\n                    }\n                }\n                int[] aa = best;\n                best = next;\n                next = aa;\n            }\n            return best[best.length - 1];\n        }\n\n        static class Column {\n            int[] vals;\n            int max;\n\n            public Column(int[] vals) {\n                this.vals = vals;\n            }\n\n            void initMax() {\n                max = 0;\n                for (int x : vals) max = Math.max(max, x);\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", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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.FileNotFoundException;\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        TaskE2 solver = new TaskE2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE2 {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int t = in.nextInt();\n            while (t-- > 0) {\n                int n = in.nextInt(), m = in.nextInt();\n                int[][] a = new int[m][n];\n                int[] bestMask = new int[1 << n];\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        a[j][i] = in.nextInt();\n                    }\n                }\n                int[] dp = new int[1 << n];\n                for (int i = 0; i < m; i++) {\n                    int[] array = a[i];\n                    for (int j = 0; j < n; j++) {\n                        int val = array[j];\n                        for (int mask = 0; mask < 1 << n; mask++) {\n                            if ((mask & (1 << j)) == 0) {\n                                dp[mask | (1 << j)] = Math.max(dp[mask | (1 << j)], dp[mask] + val);\n                            }\n                        }\n                    }\n                    for (int mask = 0; mask < 1 << n; mask++) {\n                        int best = 0;\n                        int cur = mask;\n                        for (int j = 0; j < n; j++) {\n                            best = Math.max(best, dp[cur]);\n                            cur = (cur >> 1) | ((cur & 1) << (n - 1));\n                        }\n                        for (int j = 0; j < n; j++) {\n                            dp[cur] = best;\n                            cur = (cur >> 1) | ((cur & 1) << (n - 1));\n                        }\n                    }\n                }\n                out.println(dp[(1 << n) - 1]);\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", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tint t = scn.nextInt();\n\t\twhile(t-- > 0) {\n\t\t\tint n = scn.nextInt(), m = scn.nextInt();\n\t\t\tint[][] arr = scn.next2DInt(n, m);\n\t\t\t\n\t\t\tint[][] col = new int[m][2];\n\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\tint max = 0;\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tmax = Math.max(max, arr[i][j]);\n\t\t\t\t}\n\t\t\t\tcol[j][0] = max;\n\t\t\t\tcol[j][1] = j;\n\t\t\t}\n\t\t\tArrays.parallelSort(col, (o1, o2) -> o2[0] - o1[0]);\n\t\t\t\n\t\t\tint take = Math.min(n, m);\n\t\t\t\n\t\t\tint[][] lol = new int[n][take];\n\t\t\tfor(int j = 0; j < take; j++) {\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tlol[i][j] = arr[i][col[j][1]];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tans = 0;\n\t\t\tfunc(lol, 0);\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\t\n\tint ans = 0;\n\t\n\tvoid func(int[][] arr, int col) {\n\t\tint n = arr.length, m = arr[0].length;\n\t\tif(col == m) {\n\t\t\tint rv = 0;\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tint mx = 0;\n\t\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\t\tmx = Math.max(mx, arr[i][j]);\n\t\t\t\t}\n\t\t\t\trv += mx; \n\t\t\t}\n\t\t\tans = Math.max(ans, rv);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor(int rot = 0; rot < n; rot++) {\n\t\t\tint f = arr[0][col];\n\t\t\tfor(int j = 1; j < n; j++) {\n\t\t\t\tarr[j - 1][col] = arr[j][col];\n\t\t\t}\n\t\t\tarr[n - 1][col] = f;\n\t\t\tfunc(arr, col + 1);\n\t\t}\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\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new E(), \"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\tarr = scn.shuffle(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\tarr = scn.shuffle(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\n\t\tint[] compress(int[] arr) {\n\t\t\tint n = arr.length;\n\t\t\tint[] rv = Arrays.copyOf(arr, n);\n\t\t\trv = uniq(rv);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = Arrays.binarySearch(rv, arr[i]);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] compress(long[] arr) {\n\t\t\tint n = arr.length;\n\t\t\tlong[] rv = Arrays.copyOf(arr, n);\n\t\t\trv = uniq(rv);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = Arrays.binarySearch(rv, arr[i]);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class E {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int t = scanner.nextInt();\n        while(t-->0) {\n            int n = scanner.nextInt();\n            int m = scanner.nextInt();\n            int[][] cols = new int[m][n];\n            for(int i = 0; i < n; i++) {\n                for(int j =0; j < m; j++) {\n                    cols[j][i] = scanner.nextInt();\n                }\n            }\n            int maxMask = 1 << n;\n            int[] dp = new int[maxMask];\n            Arrays.fill(dp, -1);\n            dp[0] = 0;\n            for(int i = 0; i < m; i++) {\n                for(int mask = maxMask-1; mask>=0; mask--) {\n                    int[] arr = cols[i].clone();\n                    for(int j = 0; j < n; j++) {\n                        for(int smask = mask; smask >= 0; smask = (smask-1)&mask) {\n                            if (dp[smask] == -1) continue;\n                            int add = 0;\n                            for(int k = 0; k < n; k++) {\n                                if (((mask^smask)&(1 << k)) > 0) add += arr[k];\n                            }\n                            dp[mask] = Math.max(dp[mask], dp[smask] + add);\n                            if (smask == 0) break;\n                        }\n                        arr = shift(arr);\n                    }\n                }\n            }\n            out.println(dp[maxMask-1]);\n        }\n        out.flush();\n    }\n    static int[] shift (int[] a) {\n        int[] b = new int[a.length];\n        b[0] = a[a.length-1];\n        for(int i = 0; i < a.length-1; i++) {\n            b[i+1] = a[i];\n        }\n        return b;\n    }\n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1209e1_2 {\n\n    public static void main(String[] args) throws IOException {\n        int t = ri();\n        while (t --> 0) {\n            int n = rni(), m = ni(), a[][] = new int[m][n], dp[] = new int[1 << n];\n            for (int i = 0; i < n; ++i) {\n                int[] row = ria(m);\n                for (int j = 0; j < m; ++j) {\n                    a[j][i] = row[j];\n                }\n            }\n            for (int i = 0; i < m; ++i) {\n                for (int r = 0; r < 1 << n; ++r) {\n                    for (int j = 0; j < n; ++j) {\n                        if ((r & (1 << j)) == 0) {\n                            continue;\n                        }\n                        dp[r] = max(dp[r], dp[r ^ (1 << j)] + a[i][j]);\n                    }\n                }\n                for (int r = 0; r < 1 << n; ++r) {\n                    int s = r;\n                    for (int j = 0; j < n; ++j) {\n                        if ((s & 1) != 0) {\n                            s = (s >> 1) | (1 << (n - 1));\n                        } else {\n                            s >>= 1;\n                        }\n                        dp[s] = max(dp[s], dp[r]);\n                    }\n                }\n            }\n            prln(dp[(1 << n) - 1]);\n        }\n        close();\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    // 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    // 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 boolean pryesno(boolean b) {prln(b ? \"yes\" : \"no\"); return b;};\n    static boolean pryn(boolean b) {prln(b ? \"Yes\" : \"No\"); return b;}\n    static boolean prYN(boolean b) {prln(b ? \"YES\" : \"NO\"); return b;}\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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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();}\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "\n/**\n * Date: 14 Sep, 2019\n * Link: \n * \n * @author Prasad-Chaudhari\n * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/\n * @git: https://github.com/Prasad-Chaudhari\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.Collection;\nimport java.util.Comparator;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.Map;\n\npublic class newProgram9 {\n\n    public static void main(String[] args) throws IOException {\n        // TODO code application logic here\n        FastIO in = new FastIO();\n        int t = in.ni();\n        // int t = 1;\n        while (t-- > 0) {\n            int n = in.ni();\n            int m = in.ni();\n            int a[][] = new int[n][m];\n            int b[][] = new int[m][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    a[i][j] = in.ni();\n                    b[j][i] = a[i][j];\n                }\n            }\n            for (int i = 0; i < m; i++) {\n                Arrays.sort(b[i]);\n            }\n            Data d[] = new Data[m];\n            for (int i = 0; i < m; i++) {\n                d[i] = new Data(-b[i][n - 1], i);\n            }\n            Arrays.sort(d);\n\n            int col = Math.min(n, m);\n            int c[][] = new int[n][col];\n            for (int i = 0; i < col; i++) {\n                for (int j = 0; j < n; j++) {\n                    c[j][i] = a[j][d[i].b];\n                }\n            }\n            // for (int i = 0; i < n; i++) {\n            //     for (int j = 0; j < col; j++) {\n            //         System.out.print(c[i][j] + \" \");\n            //     }\n            //     System.out.println();\n            // }\n            System.out.println(ans(c, n, col, 0));\n        }\n        in.bw.flush();\n    }\n\n    private static int ans(int c[][], int n, int m, int col) {\n        if (col == m) {\n            int sum = 0;\n            for (int i = 0; i < n; i++) {\n                int max = 0;\n                for (int j = 0; j < m; j++) {\n                    // System.out.print(c[i][j] + \" \");\n                    max = Math.max(c[i][j], max);\n                }\n                sum += max;\n                // System.out.println();\n            }\n            // System.out.println(sum);\n            return sum;\n        } else {\n            int max = ans(c, n, m, col + 1);\n            int curr[] = new int[n];\n            for (int i = 0; i < n; i++) {\n                curr[i] = c[i][col];\n            }\n            for (int i = 1; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    c[j][col] = curr[(i + j) % n];\n                }\n                max = Math.max(max, ans(c, n, m, col + 1));\n            }\n            return max;\n        }\n    }\n\n    static class FastIO {\n\n        private final BufferedReader br;\n        private final BufferedWriter bw;\n        private String s[];\n        private int index;\n        private final StringBuilder sb;\n\n        public FastIO() throws IOException {\n            br = new BufferedReader(new InputStreamReader(System.in));\n            bw = new BufferedWriter(new OutputStreamWriter(System.out, \"UTF-8\"));\n            s = br.readLine().split(\" \");\n            sb = new StringBuilder();\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] = nl();\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] = nl();\n            }\n            return a;\n        }\n\n        public int[][][] gwtree(int n) throws IOException {\n            int m = n - 1;\n            int adja[][] = new int[n + 1][];\n            int weight[][] = new int[n + 1][];\n            int from[] = new int[m];\n            int to[] = new int[m];\n            int count[] = new int[n + 1];\n            int cost[] = new int[n + 1];\n            for (int i = 0; i < m; i++) {\n                from[i] = i + 1;\n                to[i] = ni();\n                cost[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n                weight[i] = new int[count[i]];\n            }\n            for (int i = 0; i < m; i++) {\n                adja[from[i]][count[from[i]] - 1] = to[i];\n                adja[to[i]][count[to[i]] - 1] = from[i];\n                weight[from[i]][count[from[i]] - 1] = cost[i];\n                weight[to[i]][count[to[i]] - 1] = cost[i];\n                count[from[i]]--;\n                count[to[i]]--;\n            }\n            return new int[][][] { adja, weight };\n        }\n\n        public int[][][] gwg(int n, int m) throws IOException {\n            int adja[][] = new int[n + 1][];\n            int weight[][] = new int[n + 1][];\n            int from[] = new int[m];\n            int to[] = new int[m];\n            int count[] = new int[n + 1];\n            int cost[] = new int[n + 1];\n            for (int i = 0; i < m; i++) {\n                from[i] = ni();\n                to[i] = ni();\n                cost[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n                weight[i] = new int[count[i]];\n            }\n            for (int i = 0; i < m; i++) {\n                adja[from[i]][count[from[i]] - 1] = to[i];\n                adja[to[i]][count[to[i]] - 1] = from[i];\n                weight[from[i]][count[from[i]] - 1] = cost[i];\n                weight[to[i]][count[to[i]] - 1] = cost[i];\n                count[from[i]]--;\n                count[to[i]]--;\n            }\n            return new int[][][] { adja, weight };\n        }\n\n        public int[][] gtree(int n) throws IOException {\n            int adja[][] = new int[n + 1][];\n            int from[] = new int[n - 1];\n            int to[] = new int[n - 1];\n            int count[] = new int[n + 1];\n            for (int i = 0; i < n - 1; i++) {\n                from[i] = i + 1;\n                to[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n            }\n            for (int i = 0; i < n - 1; i++) {\n                adja[from[i]][--count[from[i]]] = to[i];\n                adja[to[i]][--count[to[i]]] = from[i];\n            }\n            return adja;\n        }\n\n        public int[][] gg(int n, int m) throws IOException {\n            int adja[][] = new int[n + 1][];\n            int from[] = new int[m];\n            int to[] = new int[m];\n            int count[] = new int[n + 1];\n            for (int i = 0; i < m; i++) {\n                from[i] = ni();\n                to[i] = ni();\n                count[from[i]]++;\n                count[to[i]]++;\n            }\n            for (int i = 0; i <= n; i++) {\n                adja[i] = new int[count[i]];\n            }\n            for (int i = 0; i < m; i++) {\n                adja[from[i]][--count[from[i]]] = to[i];\n                adja[to[i]][--count[to[i]]] = from[i];\n            }\n            return adja;\n        }\n\n        public void print(String s) throws IOException {\n            bw.write(s);\n        }\n\n        public void println(String s) throws IOException {\n            bw.write(s);\n            bw.newLine();\n        }\n\n        public void print(int s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(int s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\n        }\n\n        public void print(long s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(long s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\n        }\n\n        public void print(double s) throws IOException {\n            bw.write(s + \"\");\n        }\n\n        public void println(double s) throws IOException {\n            bw.write(s + \"\");\n            bw.newLine();\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    static class Data implements Comparable<Data> {\n\n        int a, b;\n\n        public Data(int a, int b) {\n            this.a = a;\n            this.b = b;\n        }\n\n        @Override\n        public int compareTo(Data o) {\n            if (a == o.a) {\n                return Integer.compare(b, o.b);\n            }\n            return Integer.compare(a, o.a);\n        }\n\n        public static void sort(int a[]) {\n            Data d[] = new Data[a.length];\n            for (int i = 0; i < a.length; i++) {\n                d[i] = new Data(a[i], 0);\n            }\n            Arrays.sort(d);\n            for (int i = 0; i < a.length; i++) {\n                a[i] = d[i].a;\n            }\n        }\n    }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    FastScanner in;\n    PrintWriter out;\n\n    void solve() {\n        int tc = in.nextInt();\n        for (int t = 0; t < tc; t++) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            O[] a = new O[n * m];\n            int[][] cols = new int[m][n + n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    cols[j][i] = cols[j][i + n] = in.nextInt();\n                    a[i * m + j] = new O(i, j, cols[j][i]);\n                }\n            }\n            Arrays.sort(a);\n            boolean[] used = new boolean[m];\n            int cntUsed = 0;\n            for (O o : a) {\n                if (!used[o.y]) {\n                    used[o.y] = true;\n                    cntUsed++;\n                    if (cntUsed == n) {\n                        break;\n                    }\n                }\n            }\n            int[] dp = new int[1 << n];\n            int[] ndp = new int[1 << n];\n            int[] maxndp = new int[1 << n];\n            for (int col = 0; col < m; col++) {\n                if (!used[col]) {\n                    continue;\n                }\n                int[] curColumn = cols[col];\n                for (int shift = 0; shift < n; shift++) {\n                    System.arraycopy(dp, 0, ndp, 0, ndp.length);\n                    for (int mask = 0; mask < 1 << n; mask++) {\n                        for (int bit = 0; bit < n; bit++) {\n                            if (((1 << bit) & mask) == 0) {\n                                int nmask = mask | (1 << bit);\n                                ndp[nmask] = Math.max(ndp[nmask], ndp[mask] + curColumn[bit + shift]);\n                            }\n                        }\n                    }\n                    for (int i = 0; i < ndp.length; i++) {\n                        maxndp[i] = Math.max(maxndp[i], ndp[i]);\n                    }\n                }\n                int[] tmp = dp;\n                dp = maxndp;\n                maxndp = tmp;\n            }\n            out.println(dp[dp.length - 1]);\n        }\n    }\n\n    class O implements Comparable<O> {\n        int x, y, value;\n\n        public O(int x, int y, int value) {\n            this.x = x;\n            this.y = y;\n            this.value = value;\n        }\n\n        @Override\n        public int compareTo(O o) {\n            return -Integer.compare(value, o.value);\n        }\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", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "/**\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 n,m,need,a[][],dp[][][],real[][];\n    static void solve() throws IOException\n    {\n        //initIo(true);\n        initIo(false);\n        StringBuilder sb = new StringBuilder();\n        int t = ni();\n        while(t-->0) {\n            n = ni();\n            m = ni();\n            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] = ni();\n                }\n            }\n            need = min(n,m);\n            Pair max_in_cols[] = new Pair[m];\n            for(int COL=0;COL<m;++COL) {\n                int max = 0;\n                for(int i=0;i<n;++i) {\n                    max = max(max, a[i][COL]);\n                }\n                max_in_cols[COL] = new Pair(max, COL);\n            }\n            real = new int[n][need];\n            Arrays.sort(max_in_cols);\n            for(int i=0;i<need;++i) {\n                int COL = max_in_cols[m-1-i].y;\n                for(int j=0;j<n;++j) {\n                    real[j][i] = a[j][COL];\n                }\n            }\n//            pl(\"need : \"+need);\n//            pa(\"Real\", real);\n            dp = new int[need][n+1][(1<<n)];\n            for(int i=0;i<need;++i) {\n                for(int j=0;j<=n;++j) {\n                    for(int k=0;k<(1<<n);++k) {\n                        dp[i][j][k] = -1;\n                    }\n                }\n            }\n            pl(f(0, n, 0));\n        }\n        pw.flush();\n        pw.close();\n    }\n    static int f(int idx, int bias, int mask) {\n        //pl(\"idx: \"+idx+\" bias : \"+bias + \" mask : \"+mask);\n        if(idx==need) {\n            return 0;\n        }\n        if(dp[idx][bias][mask]!=-1) {\n            return dp[idx][bias][mask];\n        }\n\n        //didn't fix bias yet\n        if(bias==n) {\n            int max = 0;\n            for(int b=0;b<n;++b) {\n                max = max(max, f(idx, b, mask));\n            }\n            //pl(\"maxxxxxxx : \"+max);\n            dp[idx][bias][mask] = max;\n            return max;\n        }\n        else {\n            int max = f(idx+1, n, mask);\n            for(int i=0;i<n;++i) {\n                if((mask&(1<<i))==0) {\n                    max = max(max, real[(i-bias+n)%n][idx] + f(idx, bias, mask | (1<<i)));\n                }\n            }\n            //pl(\"max : \"+max);\n            dp[idx][bias][mask] = max;\n            return max;\n        }\n    }\n    static class Pair implements Comparable<Pair>\n    {\n        int x,y;\n        Pair(int x,int y)\n        {\n            this.x=x;\n            this.y=y;\n        }\n        public int compareTo(Pair other)\n        {\n            if(this.x!=other.x)\n                return this.x-other.x;\n            return this.y-other.y;\n        }\n        public String toString()\n        {\n            return \"(\"+x+\",\"+y+\")\";\n        }\n    }\n    static void initIo(boolean isFileIO) throws IOException {\n        scan = new MyScanner(isFileIO);\n        if(isFileIO) {\n            pw = new PrintWriter(\"/Users/amandeep/Desktop/output.txt\");\n        }\n        else {\n            pw = new PrintWriter(System.out, true);\n        }\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static String ne() throws IOException\n    {\n        return scan.next();\n    }\n    static String nel() throws IOException\n    {\n        return scan.nextLine();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class MyScanner\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        MyScanner(boolean readingFromFile) throws IOException\n        {\n            if(readingFromFile) {\n                br = new BufferedReader(new FileReader(\"/Users/amandeep/Desktop/input.txt\"));\n            }\n            else {\n                br = new BufferedReader(new InputStreamReader(System.in));\n            }\n        }\n        String nextLine()throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\n// **** E1. Rotate Columns (easy version) ****\n\npublic class E1 {\n\tstatic char [] in = new char [1000000];\n\tpublic static void main (String [] arg) throws Throwable {\n\t\tint t = nextInt();\n\t\tC : for (int ii = 0; ii<t; ++ii) {\n\t\t\tint n = nextInt();\n\t\t\tint m = nextInt();\n\t\t\tPair [] P = new Pair [n*m];\n\t\t\tint [][] g = 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\tg[i][j] = nextInt();\n\t\t\t\t\tP[j + m*i] = new Pair (i, j, g[i][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i<P.length; ++i) if (P[i] == null) continue C;\n\t\t\tArrays.sort(P);\n\t\t\tHashSet<Integer> rotcols =new HashSet<Integer>();\n\t\t\tfor (int i = 0; i<n; ++i) {\n\t\t\t\t//System.err.println(\"Adding \" + P[i].j + \" , \" + P[i].L);\n\t\t\t\trotcols.add(P[i].j);\n\t\t\t}\n\t\t\t\n\t\t\tif (n <= 3 || rotcols.size() >= 3) {\n\t\t\t\t//System.err.println(\"EASY\");\n\t\t\t\tint sum = 0;\n\t\t\t\tfor (int i = 0; i<n && i < P.length; ++i) sum += P[i].L;\n\t\t\t\tSystem.out.println(sum);\n\t\t\t} else {\n\t\t\t\t// n == 4\n\t\t\t\tif (P.length > 4) rotcols.add(P[4].j);\n\t\t\t\t//Integer [] rr = rotcols.toArray(new Integer[0]);\n\t\t\t\tint [] rot = new int [rotcols.size()];\n\t\t\t\tint maxmax = 0;\n\t\t\t\tA : while (true) {\n\t\t\t\t\tfor (int i = 0; i<rot.length; ++i) {\n\t\t\t\t\t\trot[i]++;\n\t\t\t\t\t\tif (rot[i] == n) {\n\t\t\t\t\t\t\trot[i] = 0;\n\t\t\t\t\t\t\tif (i == rot.length-1) break A;\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}\n\t\t\t\t\tint [] max = new int [n];\n\t\t\t\t\tfor (int i = 0; i<n; ++i) {\n\t\t\t\t\t\tint j = 0;\n\t\t\t\t\t\tfor (int col : rotcols) {\n\t\t\t\t\t\t\tmax[i] = Math.max(max[i], g[(i+rot[j])%n][col]);\n\t\t\t\t\t\t\tj++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint sum = 0;\n\t\t\t\t\tfor (int m2 : max) sum+= m2;\n\t\t\t\t\tmaxmax = Math.max(maxmax, sum);\n\t\t\t\t}\n\t\t\t\tSystem.out.println(maxmax);\n\t\t\t}\n\t\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\n\t/************** HELPER CLASSES ***************/\n    //static class HS extends HashSet<Integer>{public HS(){super();}public HS(int a){super(a);}};\n\t//static class AL extends ArrayList<Integer>{public AL(){super();}public AL(int a){super (a);}};\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint i,j;long L; public Pair(int xx, int yy, long LL){i=xx;j=yy;L=LL;} \n\t\tpublic int compareTo(Pair p) { return (this.L > p.L) ? -1 : (this.L == p.L) ? this.i - p.i : 1;}\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<LIM; ++i) if (!b[i]) {count++; for (int j = i<<1; j<LIM; j+=i) b[j] = true;}\n\t\tint [] primes = new int[count];\n\t\tfor (i = 2,count=0;i<LIM;++i) if (!b[i]) primes[count++] = i;\n\t\treturn primes;\n\t}\n\tpublic static int[] numPrimeFactors(int LIM) {\n\t\tint i,count = 0;\n\t\tint [] b = new int [LIM];\n\t\tfor (i = 2;i<LIM; ++i) if (b[i] == 0) {count++; for (int j = i; j<LIM; j+=i) b[j]++;}\n\t\treturn b;\n\t}\n\tpublic static StringBuilder stringFromArray(int [] a) {\n\t\tStringBuilder b = new StringBuilder(9*a.length);\n\t\tfor (int i = 0; i<a.length; ++i) {\n\t\t\tif (i != 0) b = b.append(' ');\n\t\t\tb = b.append(a[i]);\n\t\t}\n\t\treturn b;\n\t}\n\tpublic static long modPow (long a, long n, long MOD) { long S = 1; for (;n > 0; n>>=1, a=(a*a)%MOD) if ((n & 1) != 0) S = (a*S) % MOD; return S;}\n}\n\n/* Full Problem Text:\n  \nThis is an easier version of the next problem.\nThe difference is only in constraints.\nYou are given a rectangular n \\times m matrix a.\nIn one move you can choose any column and cyclically shift elements in this column.\nYou can perform this operation as many times as you want (possibly zero).\nYou can perform this operation to a column multiple times.\nAfter you are done with cyclical shifts, you compute for every row the maximal value in it.\nSuppose that for i-th row it is equal r_i.\nWhat is the maximal possible value of r_1+r_2+...+r_n?\n\n */", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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.util.Random;\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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\n        int testCount = in.scanInt();\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class E2RotateColumnsHardVersion {\n        int[][] dp;\n        int[] cur;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            int[][] ar = new int[n][m];\n            int[][] max = new int[m][2];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    ar[i][j] = in.scanInt();\n            for (int i = 0; i < m; i++) {\n                for (int j = 0; j < n; j++) max[i][0] = Math.max(max[i][0], ar[j][i]);\n                max[i][1] = i;\n            }\n            CodeHash.shuffle(max);\n            Arrays.sort(max, (o1, o2) -> -o1[0] + o2[0]);\n            dp = new int[2][1 << n];\n            cur = new int[1 << n];\n            for (int i = 0; i < Math.min(m, n); i++) {\n                Arrays.fill(dp[i & 1], 0);\n                for (int k = 0; k < n; k++) {\n                    System.arraycopy(dp[(i - 1) & 1], 0, cur, 0, 1 << n);\n                    for (int l = 0; l < n; l++) {\n                        for (int j = 0; j < 1 << n; j++) {\n                            if ((j & (1 << l)) == 0) {\n                                cur[j ^ (1 << l)] = Math.max(cur[j ^ (1 << l)], cur[j] + ar[(k + l) % n][max[i][1]]);\n                            }\n                        }\n                    }\n                    for (int j = 0; j < 1 << n; j++) dp[i & 1][j] = Math.max(dp[i & 1][j], cur[j]);\n                }\n            }\n            out.println(dp[Math.min(n, m) & 1 ^ 1][(1 << n) - 1]);\n        }\n\n    }\n\n    static class CodeHash {\n        public static void shuffle(int[][] ar) {\n            Random rd = new Random(new Random().nextInt());\n            for (int i = 0; i < ar.length; i++) {\n                int index = rd.nextInt(ar.length);\n                int[] temp = ar[i];\n                ar[i] = ar[index];\n                ar[index] = temp;\n            }\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.stream.IntStream;\n\npublic class Test {\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 readLine() {\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  public static void main(String[] args) {\n    Test te = new Test();\n    te.start();\n    writer.flush();\n  }\n\n  int[] buf = new int[10];\n\n  int best(int[][] a, int c) {\n    int ans = 0;\n    if (c == a[0].length) {\n      for (int i = 0; i < a.length; i++)\n        ans += Arrays.stream(a[i]).max().getAsInt();\n      return ans;\n    }\n    for (int r = 0; r <= a.length; r++) {\n      for (int i = 0; i < a.length; i++)\n        buf[(i+1) % a.length] = a[i][c];\n      for (int i = 0; i < a.length; i++)\n        a[i][c] = buf[i];\n      ans = Math.max(ans, best(a, c+1));\n    }\n    return ans;\n  }\n\n  void start() {\n    int t = readInt();\n    while (t-- > 0) {\n      int n = readInt(), m = readInt();\n      int[][] a = new int[n][m];\n      int[][] e = new int[n*m][];\n      for (int i = 0; i < n; i++)\n        for (int j = 0; j < m; j++) {\n          a[i][j] = readInt();\n          e[i*m+j] = new int[]{a[i][j], j};\n        }\n      Arrays.sort(e, (x, y) -> x[0] == y[0] ? Integer.compare(x[1], y[1])\n          : Integer.compare(y[0], x[0]));\n      Set<Integer> cols = new HashSet<>();\n      for (int[] x : e) {\n        cols.add(x[1]);\n        if (cols.size() >= n) break;\n      }\n      int[] cs = cols.stream().mapToInt(Integer::intValue).toArray();\n      int[][] na = new int[n][cs.length];\n      for (int i = 0; i < n; i++)\n        for (int j = 0; j < cs.length; j++)\n          na[i][j] = a[i][cs[j]];\n      writer.println(best(na, 0));\n    }\n  }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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        E2VrashayaStolbciUslozhnennayaVersiya solver = new E2VrashayaStolbciUslozhnennayaVersiya();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class E2VrashayaStolbciUslozhnennayaVersiya {\n        public void solve(int testNumber, Scanner in, PrintWriter out) {\n            int tn = in.nextInt();\n            for (int t = 0; t < tn; t++) {\n                int n = in.nextInt();\n                int m = in.nextInt();\n                Col[] a = new Col[m];\n                for (int i = 0; i < m; i++) {\n                    a[i] = new Col(n);\n                }\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        a[j].a[i] = in.nextInt();\n                        if (a[j].a[i] > a[j].max) {\n                            a[j].max = a[j].a[i];\n                        }\n                    }\n\n                }\n\n                Arrays.sort(a, (o1, o2) -> o2.max - o1.max);\n\n                if (m > n) {\n                    m = n;\n                }\n\n                for (int i = 0; i < m; i++) {\n                    a[i].calcMask();\n                }\n\n                int[][] dp = new int[m + 1][1 << n];\n                Arrays.fill(dp[0], -1);\n                dp[0][0] = 0;\n                for (int i = 0; i < m; i++) {\n                    for (int msk = 0; msk < (1 << n); msk++) {\n                        dp[i + 1][msk] = dp[i][msk];\n                        for (int sub = msk; sub > 0; sub = (sub - 1) & msk) {\n                            int v = dp[i][msk ^ sub] + a[i].mask[sub];\n                            if (v > dp[i + 1][msk]) {\n                                dp[i + 1][msk] = v;\n                            }\n                        }\n                    }\n                }\n\n                out.println(dp[m][(1 << n) - 1]);\n            }\n        }\n\n        class Col {\n            int n;\n            int[] a;\n            int[] mask;\n            int max;\n\n            public Col(int n) {\n                this.n = n;\n                a = new int[n];\n            }\n\n            void calcMask() {\n                mask = new int[1 << n];\n                for (int i = 0; i < (1 << n); i++) {\n                    for (int j = 0; j < n; j++) {\n                        int sum = 0;\n                        for (int k = 0; k < n; k++) {\n                            if (((1 << k) & i) != 0) {\n                                sum += a[(j + k) % n];\n                            }\n                        }\n                        if (sum > mask[i]) {\n                            mask[i] = sum;\n                        }\n                    }\n                }\n            }\n\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class E584 {\n    public static void main(String[] args) {\n        MyScanner sc = new MyScanner();\n        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n        int t = sc.nextInt();\n        while (t > 0) {\n            int n = sc.nextInt(); int m = sc.nextInt();\n            int [][] a = new int[m][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    a[j][i] = sc.nextInt();\n                }\n            }\n            int [][] dp = new int[m + 1][(1 << n)];\n            for (int i = 1; i <= m; i++) {\n                for (int j = 0; j < (1 << n); j++) {\n                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j]);\n                    int [] b = a[i - 1];\n                    for (int start = 0; start < n; start++) {\n                        int [] c = new int[n];\n                        for (int p = 0; p < n; p++) c[p] = b[(start + p) % n];\n                        for (int k = 0; k < (1 << n); k++) {\n                            if ((k | j) == j) {\n                                int sum = 0;\n                                for (int p = 0; p < n; p++) {\n                                    if (((k >> p) & 1) == 0 && ((j >> p) & 1) == 1) sum += c[p];\n                                }\n                                dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + sum);\n                            }\n                        }\n                    }\n                }\n            }\n            out.println(dp[m][(1 << n) - 1]);\n            t--;\n        }\n\n        out.close();\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}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n    public static class Pair implements Comparable<Pair> {\n        int k, x;\n        public Pair(int k) {\n            this.k = k;\n        }\n        public void update(int x) {\n            this.x = Math.max(this.x, x);\n        }\n        public int compareTo(Pair other) {\n            if (x != other.x) {\n                return other.x - x;\n            }\n            return k - other.k;\n        }\n    }\n    public static int sum(int[] arr) {\n        int sum = 0;\n        for (int x : arr) {\n            sum += x;\n        }\n        return sum;\n    }\n    public static int[] join(int[] a, int[] b) {\n        int n = a.length;\n        int[] best = new int[n];\n        int sum = 0;\n        for (int shift = 0; shift < n; shift++) {\n            int[] curr = new int[n];\n            for (int i = 0; i < n; i++) {\n                curr[i] = Math.max(a[i], b[(i + shift) % n]);\n            }\n            int now = sum(curr);\n            if (now > sum) {\n                sum = now;\n                best = curr;\n            }\n        }\n        return best;\n    }\n    public static int n;\n    public static int[] pow;\n    public static int[][] dp, real;\n    public static void calc(int mask) {\n        int[] best = new int[n];\n        int sum = 0;\n        for (int i = 0; i < n; i++) {\n            if ((mask & pow[i]) != 0) {\n                int to = mask ^ pow[i];\n                int[] init = new int[n];\n                for (int j = 0; j < n; j++) {\n                    init[j] = real[j][i];\n                }\n                int[] curr = join(dp[to], init);\n                int s = sum(curr);\n                if (s > sum) {\n                    sum = s;\n                    best = curr;\n                }\n            }\n        }\n        dp[mask] = best;\n    }\n    public static void main(String[] args) {\n        pow = new int[15];\n        pow[0] = 1;\n        for (int i = 1; i < pow.length; i++) {\n            pow[i] = pow[i - 1] * 2;\n        }\n        Scanner in = new Scanner(System.in);\n        int t = in.nextInt();\n        for (int i = 0; i < t; i++) {\n            n = in.nextInt();\n            int m = in.nextInt();\n            int[][] arr = new int[n][m];\n            for (int j = 0; j < n; j++) {\n                for (int k = 0; k < m; k++) {\n                    arr[j][k] = in.nextInt();\n                }\n            }\n            Pair[] best = new Pair[m];\n            for (int j = 0; j < m; j++) {\n                best[j] = new Pair(j);\n                for (int k = 0; k < n; k++) {\n                    best[j].update(arr[k][j]);\n                }\n            }\n            Arrays.sort(best);\n            real = new int[n][n];\n            for (int j = 0; j < n; j++) {\n                for (int k = 0; k < Math.min(n, m); k++) {\n                    real[j][k] = arr[j][best[k].k];\n                }\n            }\n            dp = new int[1 << n][];\n            Stack<Integer>[] min = new Stack[n + 1];\n            for (int j = 0; j <= n; j++) {\n                min[j] = new Stack<>();\n            }\n            for (int j = 0; j < dp.length; j++) {\n                int cnt = 0;\n                for (int k = 0; k < n; k++) {\n                    if ((j & pow[k]) != 0) {\n                        cnt++;\n                    }\n                }\n                min[cnt].add(j);\n            }\n            for (int j = 0; j < min.length; j++) {\n                for (int x : min[j]) {\n                    if (j == 0) {\n                        dp[x] = new int[n];\n                    } else {\n                        calc(x);\n                    }\n                }\n            }\n            System.out.println(sum(dp[dp.length - 1]));\n        }\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.nio.charset.Charset;\nimport java.util.*;\n\n\npublic class CFContest {\n    public static void main(String[] args) throws Exception {\n        boolean local = System.getProperty(\"ONLINE_JUDGE\") == null;\n        boolean async = true;\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        long lInf = (long) 1e18;\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            int t = io.readInt();\n            while (t-- > 0)\n                solve1();\n        }\n\n\n        public void solve1() {\n            cache.clear();\n            int n = io.readInt();\n            int m = io.readInt();\n            Col[] mat = new Col[m];\n            for (int i = 0; i < m; i++) {\n                mat[i] = new Col();\n                mat[i].data = new int[n];\n            }\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    int v = io.readInt();\n                    mat[j].data[i] = v;\n                    mat[j].max = Math.max(mat[j].max, v);\n                }\n            }\n\n            Arrays.sort(mat, (a, b) -> -(a.max - b.max));\n            mat = Arrays.copyOf(mat, Math.min(n, m));\n            io.cache.append(bf(mat, getCol(n), n, 0)).append('\\n');\n        }\n\n        public void enhance(Col mask, Col c, Col ans, int n) {\n            for (int i = 0; i < n; i++) {\n                ans.data[i] = Math.max(mask.get(i), c.get(i));\n            }\n        }\n\n        Deque<Col> cache = new ArrayDeque<>();\n\n        public Col getCol(int n) {\n            if (cache.isEmpty()) {\n                Col col = new Col();\n                col.data = new int[n];\n                return col;\n            }\n            return cache.removeFirst();\n        }\n\n        public void destroy(Col c) {\n            c.offset = 0;\n            c.max = 0;\n            cache.addLast(c);\n        }\n\n        public int bf(Col[] cols, Col mask, int n, int k) {\n            if (k >= cols.length) {\n                int sum = 0;\n                for (int i = 0; i < n; i++) {\n                    sum += mask.data[i];\n                }\n                return sum;\n            }\n\n            int max = 0;\n            cols[k].offset = 0;\n\n            for (int i = 0; i < n; i++) {\n                Col c = getCol(n);\n                enhance(mask, cols[k], c, n);\n                max = Math.max(max, bf(cols, c, n, k + 1));\n                destroy(c);\n                cols[k].turn();\n            }\n\n            return max;\n        }\n\n    }\n\n    public static class Col {\n        int[] data;\n        int offset;\n\n        public int get(int i) {\n            return data[(i + offset) % data.length];\n        }\n\n        public void turn() {\n            offset++;\n        }\n\n        int max;\n    }\n\n\n    public static class FastIO {\n        public final StringBuilder cache = new StringBuilder(20 << 20);\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 << 20];\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}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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.HashSet;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author anand.oza\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        E1RotateColumnsEasyVersion solver = new E1RotateColumnsEasyVersion();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class E1RotateColumnsEasyVersion {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int t = in.nextInt();\n            for (int i = 0; i < t; i++) {\n                solve(in, out);\n            }\n        }\n\n        private void solve(InputReader in, PrintWriter out) {\n            int n = in.nextInt(), m = in.nextInt();\n\n            int[][] a = new int[n][];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.readIntArray(m);\n            }\n\n            out.println(solve(n, m, a));\n        }\n\n        private int solve(int n, int m, int[][] a) {\n            Cell[] cells = new Cell[n * m];\n            for (int i = 0, index = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    cells[index++] = new Cell(i, j, a[i][j]);\n                    if (index == cells.length)\n                        break;\n                }\n            }\n\n            Arrays.sort(cells, Comparator.comparingInt(cell -> -cell.x));\n\n            HashSet<Integer> colset = new HashSet<>();\n            for (int i = 0; colset.size() < n && colset.size() < m; i++) {\n                colset.add(cells[i].j);\n            }\n\n            ArrayList<Integer> cols = new ArrayList<>();\n            cols.addAll(colset);\n\n            int answer = 0;\n            for (long perm = 0; perm < pow(n, cols.size() - 1); perm++) {\n                long p = perm;\n                int[] offset = new int[cols.size()];\n                for (int col = 0; col < cols.size(); col++) {\n                    offset[col] = (int) (p % n);\n                    p /= n;\n                }\n                int sum = 0;\n                for (int row = 0; row < n; row++) {\n                    int max = 0;\n                    for (int col = 0; col < cols.size(); col++) {\n                        int cur = a[(row + offset[col]) % n][cols.get(col)];\n                        max = Math.max(max, cur);\n                    }\n                    sum += max;\n                }\n                answer = Math.max(answer, sum);\n            }\n\n            return answer;\n        }\n\n        private long pow(int base, int exponent) {\n            long p = 1;\n            for (int i = 0; i < exponent; i++) {\n                p *= base;\n            }\n            return p;\n        }\n\n        private class Cell {\n            final int i;\n            final int j;\n            final int x;\n\n            private Cell(int i, int j, int x) {\n                this.i = i;\n                this.j = j;\n                this.x = x;\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 int[] readIntArray(int n) {\n            int[] x = new int[n];\n            for (int i = 0; i < n; i++) {\n                x[i] = nextInt();\n            }\n            return x;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.Collectors;\nimport java.math.*;\n\npublic class E1 {\n\tstatic byte[] buf = new byte[1<<26];\n    static int bp = -1;\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\t/**/\n\t\tDataInputStream in = new DataInputStream(System.in);\n\t\t/*/\n\t\tDataInputStream in = new DataInputStream(new FileInputStream(\"src/e.in\"));\n\t\t/**/\n\t\t\n\t\tin.read(buf, 0, 1<<26);\n\t\tint t = nni();\n\t\tfor (int z = 0; z < t; z++) {\n\t\t\tint n = nni();\n\t\t\tint m = nni();\n\t\t\tint[][] mat = new int[n][m];\n\t\t\tint[] rmax = new int[n];\n\t\t\tint tot = 0;\n\t\t\tHashSet<Integer> care = new HashSet<>();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tPriorityQueue<Integer> cols = new PriorityQueue<>();\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tmat[i][j] = nni();\n\t\t\t\t\tcols.add(-(mat[i][j]*2000+j));\n\t\t\t\t\trmax[i] = Math.max(rmax[i], mat[i][j]);\n\t\t\t\t}\n\t\t\t\ttot += rmax[i];\n\t\t\t\tfor (int j = 0; j < Math.min(m, n); j++)\n\t\t\t\t\tcare.add((-cols.poll())%2000);\n\t\t\t}\n\t\t\tList<Integer> cal = care.stream().sorted().collect(Collectors.toList());\n\t\t\tint ret = tot;\n\t\t\tif (Math.min(m, n)==1) {\n\t\t\t\tSystem.out.println(ret);\n\t\t\t} else if (Math.min(m, n)==2) {\n\t\t\t\tfor (int a = 0; a < cal.size(); a++) {\n\t\t\t\t\tint la = cal.get(a);\n\t\t\t\t\tfor (int d = 0; d < cal.size(); d++) {\n\t\t\t\t\t\tif (d==a)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tint ld = cal.get(d);\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\tint tret = 0;\n\t\t\t\t\t\t\tfor (int x = 0; x < n; x++) {\n\t\t\t\t\t\t\t\ttret += Math.max(mat[x][ld], mat[(i+x)%n][la]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tret = Math.max(ret, tret);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.println(ret);\n\t\t\t} else if (Math.min(m, n)==3) {\n\t\t\t\tfor (int a = 0; a < cal.size(); a++) {\n\t\t\t\t\tint la = cal.get(a);\n\t\t\t\t\tfor (int b = a+1; b < cal.size(); b++) {\n\t\t\t\t\t\tint lb = cal.get(b);\n\t\t\t\t\t\tfor (int d = 0; d < cal.size(); d++) {\n\t\t\t\t\t\t\tif (d==a)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tif (d==b)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tint ld = cal.get(d);\n\t\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\t\t\t\tint tret = 0;\n\t\t\t\t\t\t\t\t\tfor (int x = 0; x < n; x++) {\n\t\t\t\t\t\t\t\t\t\ttret += Math.max(mat[x][ld], Math.max(mat[(i+x)%n][la], mat[(j+x)%n][lb]));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tret = Math.max(ret, tret);\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\tSystem.out.println(ret);\n\t\t\t} else if (Math.min(m, n)==4) {\n\t\t\t\tfor (int a = 0; a < cal.size(); a++) {\n\t\t\t\t\tint la = cal.get(a);\n\t\t\t\t\tfor (int b = a+1; b < cal.size(); b++) {\n\t\t\t\t\t\tint lb = cal.get(b);\n\t\t\t\t\t\tfor (int c = b+1; c < cal.size(); c++) {\n\t\t\t\t\t\t\tint lc = cal.get(c);\n\t\t\t\t\t\t\tfor (int d = 0; d < cal.size(); d++) {\n\t\t\t\t\t\t\t\tif (d==a)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (d==b)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (d==c)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tint ld = cal.get(d);\n\t\t\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\t\t\t\t\tfor (int k = 0; k < n; k++) {\n\t\t\t\t\t\t\t\t\t\t\tint tret = 0;\n\t\t\t\t\t\t\t\t\t\t\tfor (int x = 0; x < n; x++) {\n\t\t\t\t\t\t\t\t\t\t\t\ttret += Math.max(mat[x][ld], Math.max(mat[(i+x)%n][la], Math.max(mat[(j+x)%n][lb], mat[(k+x)%n][lc])));\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tret = Math.max(ret, tret);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.println(ret);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static int nni() {\n        int ret = 0;\n        byte b = buf[++bp];\n        while (true) {\n            ret = ret*10+b-'0';\n            b = buf[++bp];\n            if (b<'0'||b>'9') {\n            \twhile (buf[bp+1]=='\\r'||buf[bp+1]=='\\n'||buf[bp+1]==' ') {++bp;}\n            \tbreak;\n            }\n        }\n        return ret;\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.util.PriorityQueue;\n\npublic class Main {\n\n\tstatic PrintWriter out;\n\tstatic InputReader ir;\n\n\tstatic void solve() {\n\t\tint t = ir.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint n = ir.nextInt();\n\t\t\tint m = ir.nextInt();\n\t\t\tint[][] a = new int[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = ir.nextIntArray(m);\n\t\t\t}\n\t\t\tint[][][] comx = new int[n + 1][m][2];\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tint[] b = new int[n];\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tb[j] = a[j][i];\n\t\t\t\t}\n\t\t\t\tArrays.sort(b);\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tcomx[j + 1][i][0] = comx[j][i][0] + b[n - 1 - j];\n\t\t\t\t\tcomx[j + 1][i][1] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][][] org = new int[n + 1][m][2];\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\tfor (int k = 0; k < 2; k++) {\n\t\t\t\t\t\torg[i][j][k] = comx[i][j][k];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tArrays.sort(comx[i], new Comparator<int[]>() {\n\t\t\t\t\tpublic int compare(int[] A, int[] B) {\n\t\t\t\t\t\treturn A[0] - B[0];\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t// tr(org);\n\t\t\t// tr(comx);\n\t\t\tif (n == 1) {\n\t\t\t\tout.println(comx[1][m - 1][0]);\n\t\t\t} else if (n == 2) {\n\t\t\t\tout.println(Math.max(comx[2][m - 1][0], m >= 2 ? comx[1][m - 1][0] + comx[1][m - 2][0] : 0));\n\t\t\t} else if (n == 3) {\n\t\t\t\tint res = Math.max(comx[3][m - 1][0],\n\t\t\t\t\t\tm >= 3 ? comx[1][m - 1][0] + comx[1][m - 2][0] + comx[1][m - 3][0] : 0);\n\t\t\t\tif (m >= 2) {\n\t\t\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\t\t\tint p = comx[2][i][0];\n\t\t\t\t\t\tint ma = 0;\n\t\t\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\t\t\tif (comx[2][i][1] == j)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tma = Math.max(org[1][j][0], ma);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = Math.max(res, p + ma);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout.println(res);\n\t\t\t} else {\n\t\t\t\tint res = Math.max(comx[4][m - 1][0],\n\t\t\t\t\t\tm >= 4 ? comx[1][m - 1][0] + comx[1][m - 2][0] + comx[1][m - 3][0] + comx[1][m - 4][0] : 0);\n\t\t\t\tif (m >= 2) {\n\t\t\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\t\t\tint p = comx[3][i][0];\n\t\t\t\t\t\tint ma = 0;\n\t\t\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\t\t\tif (comx[3][i][1] == j)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tma = Math.max(org[1][j][0], ma);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = Math.max(res, p + ma);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (m >= 3) {\n\t\t\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\t\t\tint p = comx[2][i][0];\n\t\t\t\t\t\tPriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\t\t\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\t\t\tif (comx[2][i][1] == j)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tpq.add(org[1][j][0]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = Math.max(res, p + pq.poll() + pq.poll());\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (m >= 2) {\n\t\t\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\t\t\tint p = 0;\n\t\t\t\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\t\t\t\tp = Math.max(p, a[j][i] + a[(j + 1) % 4][i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint ma = 0;\n\t\t\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\t\t\tif (i == j)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\t\t\t\tma = Math.max(ma, a[k][j] + a[(k + 1) % 4][j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = Math.max(res, p + ma);\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\t\t\tint p = 0;\n\t\t\t\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\t\t\t\tp = Math.max(p, a[j][i] + a[(j + 2) % 4][i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint ma = 0;\n\t\t\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\t\t\tif (i == j)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\t\t\t\tma = Math.max(ma, a[k][j] + a[(k + 2) % 4][j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = Math.max(res, p + ma);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout.println(res);\n\t\t\t}\n\t\t}\n\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", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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.util.Random;\nimport java.util.Comparator;\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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\n        int testCount = in.scanInt();\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class E2RotateColumnsHardVersion {\n        int[][] dp;\n        int[] cur;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            int[][] ar = new int[n][m];\n            int[][] max = new int[m][2];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) ar[i][j] = in.scanInt();\n            }\n\n            for (int i = 0; i < m; i++) {\n                for (int j = 0; j < n; j++) {\n                    max[i][0] = Math.max(max[i][0], ar[j][i]);\n                }\n                max[i][1] = i;\n            }\n            CodeHash.shuffle(max);\n            Arrays.sort(max, new Comparator<int[]>() {\n\n                public int compare(int[] o1, int[] o2) {\n                    return -o1[0] + o2[0];\n                }\n            });\n            dp = new int[2][1 << n];\n            cur = new int[1 << n];\n            for (int i = 0; i < Math.min(m, n); i++) {\n                Arrays.fill(cur, 0);\n                Arrays.fill(dp[i & 1], 0);\n                for (int j = 0; j < 1 << n; j++) {\n                    for (int k = 0; k < n; k++) {\n                        int sum = 0;\n                        for (int l = 0; l < n; l++) {\n                            if ((j & (1 << l)) != 0) {\n                                sum += (ar[(k + l) % n][max[i][1]]);\n                            }\n                        }\n                        cur[j] = Math.max(cur[j], sum);\n                    }\n                }\n                for (int j = 0; j < (1 << n); j++) {\n                    for (int k = j; ; k = (k - 1) & j) {\n                        dp[i & 1][j] = Math.max(dp[i & 1][j], dp[(i - 1) & 1][k] + cur[j ^ k]);\n                        if (k == 0) break;\n                    }\n                }\n            }\n            out.println(dp[Math.min(n, m) & 1 ^ 1][(1 << n) - 1]);\n        }\n\n    }\n\n    static class CodeHash {\n        public static void shuffle(int[][] ar) {\n            Random rd = new Random(new Random().nextInt());\n            for (int i = 0; i < ar.length; i++) {\n                int index = rd.nextInt(ar.length);\n                int[] temp = ar[i];\n                ar[i] = ar[index];\n                ar[index] = temp;\n            }\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*; \nimport java.math.*;\nimport java.util.*;\n \npublic class Main {\n\tstatic final long MOD = 998244353;\n\t//static final long MOD = 1000000007;\n\tstatic boolean[] visited;\n    public static void main(String[] args) throws IOException {\n        FastScanner sc = new FastScanner();\n        int Q = sc.nextInt();\n        for (int q = 0; q < Q; q++) {\n        \tint N = sc.nextInt();\n        \tint M = sc.nextInt();\n        \tint[][] grid = new int[N][M];\n        \tint[][] maxes = new int[M][2];\n        \tfor (int i = 0; i < M; i++)\n        \t\tmaxes[i][1] = i;\n        \tfor (int i = 0; i < N; i++) {\n        \t\tfor (int j = 0; j < M; j++) {\n        \t\t\tgrid[i][j] = sc.nextInt();\n        \t\t\tmaxes[j][0] = Math.max(maxes[j][0],grid[i][j]);\n        \t\t}\n        \t}\n        \tmaxes = sort(maxes);\n        \tint[] keyCols = new int[Math.min(M, N)];\n        \tfor (int i = 0; i < keyCols.length; i++)\n        \t\tkeyCols[i] = maxes[i][1];\n        \t\n        \tint ans = 0;\n        \tfor (int x = 0; x < (int)Math.pow(N,N); x++) {\n        \t\tint[] base = baseN(keyCols.length,x);\n        \t\tint ansx = 0;\n        \t\tfor (int i = 0; i < N; i++) {\n            \t\tint r = 0;\n            \t\tfor (int j = 0; j < keyCols.length; j++) {\n            \t\t\tr = Math.max(r,grid[(i+base[j])%N][keyCols[j]]);\n            \t\t}\n            \t\tansx += r;\n        \t\t}\n        \t\tans = Math.max(ans,ansx);\n        \t}\n        \tSystem.out.println(ans);\n        }\n    }\n    \n    public static int[] baseN(int N, int num) {\n    \tint[] ans = new int[N];\n    \tfor (int i = N-1; i >= 0; i--) {\n    \t\tint pow = (int)Math.pow(N,i);\n    \t\tans[i] = num/pow;\n    \t\tnum -= ans[i]*pow;\n    \t}\n    \treturn ans;\n    }\n    \n    public static int[][] sort(int[][] array) {\n    \t//Sort an array (immune to quicksort TLE)\n\t\tRandom rgen = new Random();\n\t\tfor (int i = 0; i< array.length; i++) {\n\t\t    int randomPosition = rgen.nextInt(array.length);\n\t\t    int[] temp = array[i];\n\t\t    array[i] = array[randomPosition];\n\t\t    array[randomPosition] = temp;\n\t\t}\n\t\tArrays.sort(array, new Comparator<int[]>() {\n\t\t\t  @Override\n\t\t\t  public int compare(int[] arr1, int[] arr2) {\n\t\t\t\t  //Descending order\n\t\t\t\t  return arr2[0]-arr1[0];\n\t\t\t  }\n\t\t});\n\t\treturn array;\n\t}\n    \n    static class FastScanner { \n        BufferedReader br; \n        StringTokenizer st; \n  \n        public FastScanner() { \n            br = new BufferedReader(new InputStreamReader(System.in)); \n        } \n  \n        String next() { \n            while (st == null || !st.hasMoreElements()) { \n                try { \n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException  e) { \n                    e.printStackTrace(); \n                } \n            } \n            return st.nextToken(); \n        } \n  \n        int 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}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n    public static void main(String[] args) throws Exception {\n        new Thread(null ,new Runnable(){\n            public void run(){\n                try{solveIt();} catch(Exception e){e.printStackTrace(); System.exit(1);}\n            }\n        },\"Main\",1<<28).start();\n    }\n\n    static int dp[][], a[][], rows, cols;\n\n    public static void solveIt() throws Exception {\n        FastReader in = new FastReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        int test = in.nextInt();\n        for (int t = 1; t <= test; t++) {\n            rows = in.nextInt();\n            cols = in.nextInt();\n            dp = new int[cols][1 << rows];\n            for (int x[] : dp) Arrays.fill(x, -1);\n            a = new int[cols][rows];\n            for (int i = 0; i < rows; i++) {\n                for (int j = 0; j < cols; j++) {\n                    a[j][i] = in.nextInt();\n                }\n            }\n            debug(a);\n            pw.println(solve(0, 0));\n        }\n\n        pw.close();\n    }\n\n    static int solve(int pos, int mask) {\n        if (pos >= cols) return 0;\n        if (dp[pos][mask] != -1) return dp[pos][mask];\n        int res = 0;\n        for (int i = 0; i < rows; i++) {\n            for (int k = 0; k < (1 << rows); k++) {\n                if ((mask & k) != 0) continue;\n                int sum = 0;\n                for (int bit = 0; bit < rows; bit++) {\n                    if (check(k, bit)) sum += a[pos][bit];\n                }\n                res = max(res, sum + solve(pos + 1, mask | k));\n            } \n            cyclicShift(pos);\n        }\n        return dp[pos][mask] = res;\n    }\n\n    static boolean check(int N, int pos) {\n        return (N & (1 << pos)) != 0;\n    }\n\n    static void cyclicShift(int col) {\n        int m = a[col].length;\n        int last = a[col][m - 1];\n        for (int i = m - 1; i >= 1; i--) {\n            a[col][i] = a[col][i - 1];\n        }\n        a[col][0] = last;\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n\n    static class FastReader {\n        InputStream is;\n        private byte[] inbuf = new byte[1024];\n        private int lenbuf = 0, ptrbuf = 0;\n\n        public FastReader(InputStream is) {\n            this.is = is;\n        }\n\n        public 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        public boolean isSpaceChar(int c) {\n            return !(c >= 33 && c <= 126);\n        }\n\n        private boolean isEndOfLine(int c) {\n            return c == '\\n' || c == '\\r' || c == -1;\n        }\n\n        public int skip() {\n            int b;\n            while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n            return b;\n        }\n\n        public String next() {\n            int b = skip();\n            StringBuilder sb = new StringBuilder();\n            while (!(isSpaceChar(b))) {\n                sb.appendCodePoint(b);\n                b = readByte();\n            }\n            return sb.toString();\n        }\n\n\n        public String nextLine() {\n            int c = skip();\n            StringBuilder sb = new StringBuilder();\n            while (!isEndOfLine(c)) {\n                sb.appendCodePoint(c);\n                c = readByte();\n            }\n            return sb.toString();\n        }\n\n        public int nextInt() {\n            int num = 0, b;\n            boolean minus = false;\n            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n            if (b == '-') {\n                minus = true;\n                b = readByte();\n            }\n            while (true) {\n                if (b >= '0' && b <= '9') {\n                    num = (num << 3) + (num << 1) + (b - '0');\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public long nextLong() {\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 << 3) + (num << 1) + (b - '0');\n                } else {\n                    return minus ? -num : num;\n                }\n                b = readByte();\n            }\n        }\n\n        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        public 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        public char readChar() {\n            return (char) skip();\n        }\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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\tint q=in.nextInt();\n\t\tfor(int i=0;i<q;i++) {\n\t\t\tout.println(work());\n\t\t}\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tint id[];\n\tlong work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tlong ret=0;\n\t\tPriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] arr1,int[] arr2) {\n\t\t\t\treturn arr1[2]-arr2[2];\n\t\t\t}\n\t\t});\n\t\tlong sum=0;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tint v=in.nextInt();\n\t\t\t\tpq.add(new int[] {i,j,v});\n\t\t\t\tsum+=v;\n\t\t\t\tif(pq.size()>6)pq.poll();\n\t\t\t}\n\t\t}\n\t\tif(m==1)return sum;\n\t\tif(n<=3) {\n\t\t\twhile(pq.size()>0) {\n\t\t\t\tint[] p=pq.poll();\n\t\t\t\tif(pq.size()<n) {\n\t\t\t\t\tret+=p[2];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\tint[][] A=new int[6][];\n\t\tfor(int i=0;pq.size()>0;i++) {\n\t\t\tA[i]=pq.poll();\n\t\t}\n\t\t\n\t\tfor(int i=0;i<6;i++) {\n\t\t\tfor(int j=i+1;j<6;j++) {\n\t\t\t\tfor(int k=j+1;k<6;k++) {\n\t\t\t\t\tout:\n\t\t\t\t\tfor(int p=k+1;p<6;p++) {\n\t\t\t\t\t\tint s=A[i][2]+A[j][2]+A[k][2]+A[p][2];\n\t\t\t\t\t\tHashMap<Integer,ArrayList<Integer>> map=new HashMap<>();\n\t\t\t\t\t\tif(map.get(A[i][1])==null) {\n\t\t\t\t\t\t\tmap.put(A[i][1],new ArrayList<>());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(map.get(A[j][1])==null) {\n\t\t\t\t\t\t\tmap.put(A[j][1],new ArrayList<>());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(map.get(A[k][1])==null) {\n\t\t\t\t\t\t\tmap.put(A[k][1],new ArrayList<>());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(map.get(A[p][1])==null) {\n\t\t\t\t\t\t\tmap.put(A[p][1],new ArrayList<>());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmap.get(A[i][1]).add(A[i][0]);\n\t\t\t\t\t\tmap.get(A[j][1]).add(A[j][0]);\n\t\t\t\t\t\tmap.get(A[k][1]).add(A[k][0]);\n\t\t\t\t\t\tmap.get(A[p][1]).add(A[p][0]);\n\t\t\t\t\t\tif(map.size()!=2) {\n\t\t\t\t\t\t\tret=Math.max(ret, s);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tInteger l1=null,l2=null,r1=null,r2=null;\n\t\t\t\t\t\tfor(int key:map.keySet()) {\n\t\t\t\t\t\t\tArrayList<Integer> list=map.get(key);\n\t\t\t\t\t\t\tif(map.get(key).size()!=2) {\n\t\t\t\t\t\t\t\tret=Math.max(ret, s);\n\t\t\t\t\t\t\t\tcontinue out;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(l1==null) {\n\t\t\t\t\t\t\t\tl1=list.get(0);\n\t\t\t\t\t\t\t\tl2=list.get(1);\n\t\t\t\t\t\t\t}else {\n\t\t\t\t\t\t\t\tr1=list.get(0);\n\t\t\t\t\t\t\t\tr2=list.get(1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif((Math.abs(l1-l2)==2&&Math.abs(r1-r2)==2)||(Math.abs(l1-l2)!=2&&Math.abs(r1-r2)!=2)) {\n\t\t\t\t\t\t\tret=Math.max(ret, s);\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 ret;\n\t}\n}\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tint t = scn.nextInt();\n\t\twhile(t-- > 0) {\n\t\t\tint n = scn.nextInt(), m = scn.nextInt();\n\t\t\tint[][] arr = scn.next2DInt(n, m);\n\t\t\t\n\t\t\tint[][] col = new int[m][2];\n\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\tint max = 0;\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tmax = Math.max(max, arr[i][j]);\n\t\t\t\t}\n\t\t\t\tcol[j][0] = max;\n\t\t\t\tcol[j][1] = j;\n\t\t\t}\n\t\t\tArrays.parallelSort(col, (o1, o2) -> o2[0] - o1[0]);\n\t\t\t\n\t\t\tm = Math.min(n, m);\n\t\t\t\n\t\t\tint[][] lol = new int[n][m];\n\t\t\t\n\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tlol[i][j] = arr[i][col[j][1]];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint[] row = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\trow[i] = lol[i][0];\n\t\t\t}\n\t\t\t\n\t\t\tans = 0;\n\t\t\tfunc(lol, 1, row);\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\t\n\tint ans;\n\t\n\tvoid func(int[][] arr, int col, int[] rowM) {\n\t\tint n = arr.length, m = arr[0].length;\n\t\tif(col >= m) {\n\t\t\tint rv = 0;\n\t\t\tfor(int a : rowM) {\n\t\t\t\trv += a;\n\t\t\t}\n\t\t\tans = Math.max(ans, rv);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint max = 0, ind = -1;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(arr[i][col] > max) {\n\t\t\t\tmax = arr[i][col];\n\t\t\t\tind = i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tboolean in = false;\n\t\tfor(int r = 0; r < n; r++) {\n\t\t\tif(max <= rowM[r]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint rot = (ind - r + n) % n;\n\t\t\tint[] need = new int[n], copy = Arrays.copyOf(rowM, n);\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tneed[i] = arr[(i + rot) % n][col];\n\t\t\t}\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tarr[i][col] = need[i];\n\t\t\t\tcopy[i] = Math.max(rowM[i], arr[i][col]);\n\t\t\t}\n\t\t\t\n\t\t\tind = r;\n\t\t\tin = true;\n\t\t\tfunc(arr, col + 1, copy);\n\t\t}\n\t\t\n\t\tif(!in) {\n\t\t\tfunc(arr, col + 2, rowM);\n\t\t}\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\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new E(), \"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\tarr = scn.shuffle(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\tarr = scn.shuffle(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\n\t\tint[] compress(int[] arr) {\n\t\t\tint n = arr.length;\n\t\t\tint[] rv = Arrays.copyOf(arr, n);\n\t\t\trv = uniq(rv);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = Arrays.binarySearch(rv, arr[i]);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] compress(long[] arr) {\n\t\t\tint n = arr.length;\n\t\t\tlong[] rv = Arrays.copyOf(arr, n);\n\t\t\trv = uniq(rv);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = Arrays.binarySearch(rv, arr[i]);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic int n, m, a[][];\n\tstatic int[][] memo;\n\tstatic Integer[] indices;\n\n\tstatic int[] getCol(int col, int shift) {\n\t\tint[] ans = new int[n];\n\t\tfor (int i = 0, j = shift; i < n; i++, j = (j + 1) % n) {\n\t\t\tans[i] = a[j][col];\n\t\t}\n\t\treturn ans;\n\n\t}\n\n\tstatic int dp(int col, int msk) {\n\t\tif (col == n||col==m)\n\t\t\treturn 0;\n\t\tif (memo[msk][col] != -1)\n\t\t\treturn memo[msk][col];\n\t\tint ans = 0;\n\t\tfor (int shift = 0; shift < n; shift++) {\n\t\t\tint[] currCol = getCol(indices[col], shift);\n\t\t\tfor (int nxtMsk = 0; nxtMsk < 1 << n; nxtMsk++) {\n\t\t\t\tif ((nxtMsk & msk) != msk)\n\t\t\t\t\tcontinue;\n\t\t\t\tint curr = 0;\n\t\t\t\tint diff = msk ^ nxtMsk;\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif ((diff & 1 << i) != 0)\n\t\t\t\t\t\tcurr += currCol[i];\n\t\t\t\tans = Math.max(ans, dp(col + 1, nxtMsk) + curr);\n\t\t\t}\n\t\t}\n\t\treturn memo[msk][col] = ans;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint tc = sc.nextInt();\n\t\twhile (tc-- > 0) {\n\t\t\tn = sc.nextInt();\n\t\t\tm = sc.nextInt();\n\t\t\tindices = new Integer[m];\n\n\t\t\tmemo = new int[1 << n][m];\n\t\t\tfor (int[] x : memo)\n\t\t\t\tArrays.fill(x, -1);\n\t\t\ta = new int[n][m];\n\t\t\tint[] max = new int[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\ta[i][j] = sc.nextInt();\n\t\t\t\t\tmax[j] = Math.max(max[j], a[i][j]);\n\t\t\t\t}\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tindices[j] = j;\n\t\t\t}\n\t\t\tArrays.sort(indices, Comparator.comparingInt(i -> -max[i]));\n\t\t\tout.println(dp(0, 0));\n\t\t}\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tshuffle(a);\n\t\tArrays.sort(a);\n\t}\n\n\tstatic void shuffle(int[] a) {\n\t\tint n = a.length;\n\t\tRandom rand = new Random();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint tmpIdx = rand.nextInt(n);\n\t\t\tint tmp = a[i];\n\t\t\ta[i] = a[tmpIdx];\n\t\t\ta[tmpIdx] = tmp;\n\t\t}\n\t}\n\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskE {\n\n    static int[][] transpose(int[][] a, int n, int m) {\n        int[][] t = new int[m][n];\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                t[j][i] = a[i][j];\n            }\n        }\n\n        return t;\n    }\n\n    public static void main(String[] args) {\n        FastReader in = new FastReader(System.in);\n//        FastReader in = new FastReader(new FileInputStream(\"input.txt\"));\n        PrintWriter out = new PrintWriter(System.out);\n//        PrintWriter out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\n\n        int t = in.nextInt();\n\n        while (t-- > 0) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n\n            int[][] a = new int[n + 1][m];\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    a[i][j] = in.nextInt();\n                    a[n][j] = Math.max(a[n][j], a[i][j]);\n                }\n            }\n\n            a = transpose(a, n, m);\n\n            Arrays.sort(a, new Comparator<int[]>() {\n                @Override\n                public int compare(int[] o1, int[] o2) {\n                    int max1 = 0;\n                    for (int i = 0; i < o1.length; i++) {\n                        max1 = Math.max(max1, o1[i]);\n                    }\n\n                    int max2 = 0;\n                    for (int i = 0; i < o2.length; i++) {\n                        max2 = Math.max(max2, o2[i]);\n                    }\n\n                    return max2 - max1;\n                }\n            });\n\n            a = transpose(a, m, n);\n\n            int[] dp = new int[1 << n];\n\n            for (int i = 0; i < Math.min(n, m); i++) {\n                int[] best = new int[1 << n];\n\n                for (int j = 1; j < (1 << n); j++) {\n                    for (int k = 0; k < n; k++) {\n                        int sum = 0;\n                        for (int l = 0; l < n; l++) {\n                            if ((j & (1 << l)) != 0)\n                                sum += a[(l + k) % n][i];\n                        }\n                        best[j] = Math.max(best[j], sum);\n                    }\n                }\n\n                int[] dp1 = dp.clone();\n\n                for (int j = 0; j < (1 << n); j++) {\n                    for (int k = j; k > 0; k = (k - 1) & j) {\n                        dp[j] = Math.max(dp[j], dp1[k ^ j] + best[k]);\n                    }\n                }\n            }\n\n            out.println(dp[(1 << n) - 1]);\n        }\n\n\n\n\n\n        out.close();\n    }\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastReader(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        Integer nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        Double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(nextLine());\n            }\n            return st.nextToken();\n        }\n\n        String nextLine() {\n            String s = \"\";\n            try {\n                s = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return s;\n        }\n    }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\npublic class Main {\n    public static int n, m;\n    public static int[][] arr;\n    public static class Item implements Comparable<Item> {\n        int i, x;\n        public Item(int i, int x) {\n            this.i = i;\n            this.x = x;\n        }\n        public int compareTo(Item other) {\n            if (x == other.x) {\n                return i - other.i;\n            }\n            return other.x - x;\n        }\n    }\n    public static int calc(int[] cols, int k, String mask) {\n        if (k == cols.length) {\n            int res = 0;\n            for (int i = 0; i < n; i++) {\n                int max = 0;\n                for (int j = 0; j < cols.length; j++) {\n                    int shift = mask.charAt(j) - '0';\n                    max = Math.max(max, arr[(shift + i) % n][cols[j]]);\n                }\n                res += max;\n            }\n            return res;\n        } else {\n            int best = 0;\n            for (int i = 0; i < n; i++) {\n                best = Math.max(best, calc(cols, k + 1, mask + i));\n            }\n            return best;\n        }\n    }\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int t = in.nextInt();\n        for (int i = 0; i < t; i++) {\n            n = in.nextInt();\n            m = in.nextInt();\n            arr = new int[n][m];\n            for (int j = 0; j < n; j++) {\n                for (int k = 0; k < m; k++) {\n                    arr[j][k] = in.nextInt();\n                }\n            }\n            Item[] max = new Item[m];\n            for (int j = 0; j < m; j++) {\n                max[j] = new Item(j, 0);\n                for (int k = 0; k < n; k++) {\n                    max[j].x = Math.max(max[j].x, arr[k][j]);\n                }\n            }\n            Arrays.sort(max);\n            int[] cols = new int[Math.min(n, m)];\n            for (int j = 0; j < cols.length; j++) {\n                cols[j] = max[j].i;\n            }\n            System.out.println(calc(cols, 0, \"\"));\n        }\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "//package round584;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Map;\n\npublic class E1 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni();T > 0;T--){\n\t\t\tint n = ni(), m = ni();\n\t\t\tint[][] a = new int[n][];\n\t\t\tfor(int i = 0;i < n;i++)a[i] = na(m);\n\t\t\t\n\t\t\tint[][] sss = new int[1<<n][m];\n\t\t\tfor(int i = 1;i < 1<<n;i+=2){\n\t\t\t\tint[] ss = new int[m];\n\t\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\t\tint cur = i;\n\t\t\t\t\tint lmax = 0;\n\t\t\t\t\tfor(int sh = 0;sh < n;sh++){\n\t\t\t\t\t\tint s = 0;\n\t\t\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\t\t\tif(cur<<~k<0){\n\t\t\t\t\t\t\t\ts += a[k][j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlmax = Math.max(lmax, s);\n\t\t\t\t\t\tcur = cur>>>1|(cur&1)<<n-1;\n\t\t\t\t\t}\n\t\t\t\t\tss[j] = lmax;\n\t\t\t\t}\n\t\t\t\tsss[i] = ss;\n\t\t\t}\n\t\t\tptns = new HashMap<>();\n\t\t\tdfs(new int[n], 0, -1);\n\t\t\tint ans = 0;\n\t\t\tif(n == 4 && m >= 4){\n\t\t\t\tint[] one = Arrays.copyOf(sss[1], m);\n\t\t\t\tArrays.sort(one);\n\t\t\t\tans = one[m-1] + one[m-2] + one[m-3] + one[m-4];\n\t\t\t}\n\t\t\t\n\t\t\tfor(int[] cs : ptns.values()){\n\t\t\t\tif(cs.length == 4)continue;\n\t\t\t\tint[] u = new int[cs.length];\n\t\t\t\tinner:\n\t\t\t\tdo{\n\t\t\t\t\tfor(int i = 0;i < cs.length;i++){\n\t\t\t\t\t\tfor(int j = i+1;j < cs.length;j++){\n\t\t\t\t\t\t\tif(u[i] == u[j])continue inner;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint val = 0;\n\t\t\t\t\tfor(int i = 0;i < cs.length;i++){\n\t\t\t\t\t\tval += sss[cs[i]][u[i]];\n\t\t\t\t\t}\n\t\t\t\t\tans = Math.max(ans, val);\n\t\t\t\t}while(inc(u, m));\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\t\n\tpublic static boolean inc(int[] a, int base) {\n\t\tint n = a.length;\n\t\tint i;\n\t\tfor (i = n - 1; i >= 0 && a[i] == base - 1; i--)\n\t\t\t;\n\t\tif (i == -1)\n\t\t\treturn false;\n\n\t\ta[i]++;\n\t\tArrays.fill(a, i + 1, n, 0);\n\t\treturn true;\n\t}\n\n\t\n\tMap<Long, int[]> ptns = new HashMap<>();\n//\tSet<Long> all = new HashSet<>();\n\t\n\tvoid dfs(int[] a, int pos, int max)\n\t{\n\t\tif(pos == a.length){\n\t\t\tint[] ptn = new int[max+1];\n\t\t\tint n = a.length;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tptn[a[i]] |= 1<<i;\n\t\t\t}\n\t\t\tfor(int i = 0;i <= max;i++){\n\t\t\t\tptn[i] = ptn[i]>>>Integer.numberOfTrailingZeros(ptn[i]);\n\t\t\t}\n//\t\t\tfor(int i = 0;i <= max;i++){\n//\t\t\t\tint min = ptn[i];\n//\t\t\t\tint k = ptn[i];\n//\t\t\t\tfor(int j = 0;j < 12;j++){\n//\t\t\t\t\tint nk = k>>>1|(k&1)<<11;\n//\t\t\t\t\tk = nk;\n//\t\t\t\t\tmin = Math.min(min, k);\n//\t\t\t\t}\n//\t\t\t\tptn[i] = min;\n//\t\t\t}\n\t\t\tArrays.sort(ptn);\n\t\t\tlong h = 0;\n\t\t\tfor(int v : ptn){\n\t\t\t\th= h * 1000000009 + v;\n\t\t\t}\n//\t\t\tall.add(h);\n\t\t\tptns.put(h, ptn);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor(int i = 0;i <= max+1;i++){\n\t\t\ta[pos] = i;\n\t\t\tdfs(a, pos+1, Math.max(i, max));\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 4, m = 100;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(40 + \" \");\n//\t\tfor(int rep = 0;rep < 40;rep++){\n//\t\t\tsb.append(n + \" \");\n//\t\t\tsb.append(m + \" \");\n//\t\t\tfor (int i = 0; i < n*m; i++) {\n//\t\t\t\tsb.append(gen.nextInt(100000) + \" \");\n//\t\t\t}\n//\t\t}\n//\t\tINPUT = sb.toString();\n\n\n\t\t\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E1().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class r584p5 {\n    private static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n    private static PrintWriter pw = new PrintWriter(System.out);\n    private static int n, m, arr[][];\n    private static ArrayList<HashSet<Integer>> chls;\n\n    private static void gench(){\n        chls.add(new HashSet<>());\n        chls.get(0).add(0);\n\n        for(int i=1; i<(1<<n); i++){\n            int des = i^Integer.highestOneBit(i);\n            HashSet<Integer> st = new HashSet<>();\n            for(int z : chls.get(des)){\n                st.add(z);\n                st.add(z|Integer.highestOneBit(i));\n            }\n            chls.add(st);\n        }\n    }\n\n    private static void cal(){\n        int val[][] = new int[(1<<n)][m];\n\n        for(int j=0; j<m; j++){\n            val[0][j] = 0;\n            for(int mask=1; mask<(1<<n); mask++){\n                int max = 0;\n                for(int begin=0; begin<n; begin++){\n                    int sum = 0;\n                    for(int ptr=begin, pos=0; pos<n; ptr=(ptr+1)%n, pos++){\n                        if((mask&(1<<pos)) > 0)\n                            sum += arr[ptr][j];\n                    }\n                    max = Math.max(max, sum);\n                }\n                val[mask][j] = max;\n            }\n        }\n\n        int dp[][] = new int[(1<<n)][m];\n\n        for(int mask=0; mask<(1<<n); mask++)\n            dp[mask][0] = val[mask][0];\n\n        for(int j=1; j<m; j++){\n            dp[0][j] = 0;\n            for(int mask=1; mask<(1<<n); mask++){\n\n                dp[mask][j] = 0;\n                for(int ch1 : chls.get(mask)){\n                    int ch2 = mask^ch1;\n\n                    dp[mask][j] = Math.max(dp[mask][j], val[ch1][j]+dp[ch2][j-1]);\n                }\n            }\n        }\n\n        pw.println(dp[(1<<n)-1][m-1]);\n    }\n\n    private static void run()throws IOException{\n        StringTokenizer tk = new StringTokenizer(r.readLine());\n        n = Integer.parseInt(tk.nextToken());\n        m = Integer.parseInt(tk.nextToken());\n        arr = new int[n][m];\n        chls = new ArrayList<>();\n\n        for(int i=0; i<n; i++){\n            tk = new StringTokenizer(r.readLine());\n            for(int j=0; j<m; j++)\n                arr[i][j] = Integer.parseInt(tk.nextToken());\n        }\n\n        gench();\n        cal();\n    }\n\n    public static void main(String args[])throws IOException{\n        int t = Integer.parseInt(r.readLine());\n\n        while(t-->0)\n            run();\n\n        pw.flush();\n        pw.close();\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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 */\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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\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 E2RotateColumnsHardVersion {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            E2RotateColumnsHardVersion.Column[] columns = new E2RotateColumnsHardVersion.Column[m];\n            for (int i = 0; i < columns.length; ++i) columns[i] = new E2RotateColumnsHardVersion.Column(new int[n]);\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    columns[j].v[i] = in.nextInt();\n                    if (i == n - 1) columns[j].initMax();\n                }\n            }\n            Arrays.sort(columns, (o1, o2) -> o2.max - o1.max);\n            if (columns.length > n)\n                columns = Arrays.copyOf(columns, n);\n\n            long[] dp = new long[1 << n];\n            for (E2RotateColumnsHardVersion.Column c : columns) {\n                long[] ndp = new long[1 << n];\n                System.arraycopy(dp, 0, ndp, 0, dp.length);\n\n                for (int rot = 0; rot < n; ++rot) {\n                    long[] temp = new long[1 << n];\n                    System.arraycopy(dp, 0, temp, 0, dp.length);\n                    for (int i = 0, pos = rot; i < n; ++i, ++pos) {\n                        if (pos >= n) pos = 0;\n                        int val = c.v[pos];\n                        for (int j = 0; j < temp.length; ++j) {\n                            if ((j & (1 << i)) == 0)\n                                temp[j | (1 << i)] = Math.max(temp[j | (1 << i)], temp[j] + val);\n                        }\n                    }\n                    for (int i = 0; i < ndp.length; ++i)\n                        ndp[i] = Math.max(ndp[i], temp[i]);\n                }\n                dp = ndp;\n            }\n            out.println(dp[dp.length - 1]);\n        }\n\n        static class Column {\n            int[] v;\n            int max;\n\n            public Column(int[] v) {\n                this.v = v;\n            }\n\n            void initMax() {\n                max = 0;\n                for (int vv : v) max = Math.max(max, vv);\n            }\n\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public String next() {\n            return nextString();\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 String nextString() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = pread();\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\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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    StringTokenizer tok;\n\n    public void go() throws IOException\n    {\n        StringTokenizer tok = new StringTokenizer(in.readLine());\n        int zzz = Integer.parseInt(tok.nextToken());\n        for (int zz = 0; zz < zzz; zz++)\n        {\n            ntok();\n            int n = ipar();\n            int m = ipar();\n            int[][] mat = new int[n][m];\n            for (int i = 0; i < n; i++)\n            {\n                ntok();\n                mat[i] = iapar(m);\n            }\n            long[][] dp = new long[1 << n][m+1];\n            for (int i = 0; i < 1 << n; i++)\n            {\n                dp[i][m] = -1000000000;\n            }\n            dp[(1 << n) - 1][m] = 0;\n            for (int i = m-1; i >= 0; i--)\n            {\n                for (int e = 0; e < 1 << n; e++)\n                {\n                    dp[e][i] = dp[e][i+1];\n                    for (int w = 0; w < 1 << n; w++)\n                    {\n                        if ((e & w) == 0)\n                        {\n                            dp[e][i] = Math.max(dp[e][i], best(w, mat, i) + dp[e|w][i+1]);\n                        }\n                    }\n                }\n            }\n            // for (long[] arr : dp)\n            // {\n            //     out.println(Arrays.toString(arr));\n            // }\n            out.println(dp[0][0]);\n        }\n\n        out.flush();\n        in.close();\n    }\n\n    public long best(int mask, int[][] mat, int col)\n    {\n        long max = 0;\n        for (int t = 0; t < mat.length; t++)\n        {\n            long sum = 0;\n            int mk = mask;\n            for (int i = 0; i < mat.length; i++)\n            {\n                if (mk % 2 == 1)\n                {\n                    sum += mat[i][col];\n                }\n                mk /= 2;\n            }\n            max = Math.max(max, sum);\n            cycle(mat, col);\n        }\n        return max;\n    }\n\n    public void cycle(int[][] mat, int col)\n    {\n        int temp = mat[0][col];\n        for (int i = 0; i < mat.length-1; i++)\n        {\n            mat[i][col] = mat[i+1][col];\n        }\n        mat[mat.length-1][col] = temp;\n    }\n\n    public void ntok() throws IOException\n    {\n        tok = new StringTokenizer(in.readLine());\n    }\n\n    public int ipar()\n    {\n        return Integer.parseInt(tok.nextToken());\n    }\n\n    public int[] iapar(int n)\n    {\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = ipar();\n        }\n        return arr;\n    }\n\n    public long lpar()\n    {\n        return Long.parseLong(tok.nextToken());\n    }\n\n    public long[] lapar(int n)\n    {\n        long[] arr = new long[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = lpar();\n        }\n        return arr;\n    }\n\n    public double dpar()\n    {\n        return Double.parseDouble(tok.nextToken());\n    }\n\n    public String spar()\n    {\n        return tok.nextToken();\n    }\n\n    public static void main(String[] args) throws IOException\n    {\n        new E().go();\n    }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.stream.IntStream;\n\npublic class Test {\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 readLine() {\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  public static void main(String[] args) {\n    Test te = new Test();\n    te.start();\n    writer.flush();\n  }\n\n  void start() {\n    int t = readInt();\n    while (t-- > 0) {\n      int n = readInt(), m = readInt();\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] = readInt();\n      int[] dp = new int[1<<n];\n      Arrays.fill(dp, -1);\n      dp[0] = 0;\n      for (int c = 0; c < m; c++) {\n        for (int i = (1 << n) - 1; i >= 0; i--) {\n          int u = (1 << n) - 1 - i;\n          int p = u;\n          if (dp[i] >= 0)\n            while (p > 0) {\n              for (int r = 0; r < n; r++) {\n                  int sum = 0;\n                  for (int j = 0; j < n; j++) if (((p >> j) & 1) != 0) sum += a[(j + r) % n][c];\n                  dp[i | p] = Math.max(dp[i | p], dp[i] + sum);\n                }\n              p = (p - 1) & u;\n            }\n        }\n      }\n      writer.println(dp[(1<<n) - 1]);\n    }\n  }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedWriter;\nimport java.io.DataInputStream;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.nio.file.Paths;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\n\npublic class E1 {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tFastPrinter out = new FastPrinter(System.out);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < T; i++) {\n\t\t\tnew E1().run(sc, out);\n\t\t}\n\t\tout.close();\n\t}\n\n\tint N, M, arr[][], ans;\n\n\tpublic void run(FastScanner sc, FastPrinter out) throws Exception {\n\t\tN = sc.nextInt();\n\t\tM = sc.nextInt();\n\t\tarr = new int[N][M];\n\t\tint[][] nums = new int[N * M][3];\n\t\tint count = 0;\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tfor (int j = 0; j < M; j++) {\n\t\t\t\tint v = sc.nextInt();\n\t\t\t\tarr[i][j] = v;\n\t\t\t\tnums[count++] = new int[] { v, j, i };\n\t\t\t}\n\t\t}\n\t\tArrays.sort(nums, new Comparator<int[]>() {\n\t\t\t@Override\n\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\treturn b[0] - a[0];\n\t\t\t}\n\t\t});\n\t\t// System.err.println(Arrays.deepToString(arr));\n\t\t// System.err.println(Arrays.deepToString(nums));\n\t\tif (N == 4 && M > 1) {\n\t\t\tint colCount = 0;\n\t\t\tHashMap<Integer, Integer> map = new HashMap<>();\n\t\t\t// I believe you only need top 6 numbers?\n\t\t\tfor (int i = 0; i < 8; i++) {\n\t\t\t\tint col = nums[i][1];\n\t\t\t\tInteger newCol = map.get(col);\n\t\t\t\tif (newCol == null) {\n\t\t\t\t\tmap.put(col, colCount++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][] arr = new int[N][colCount];\n\t\t\tfor (int i = 0; i < 8; i++) {\n\t\t\t\tint val = nums[i][0];\n\t\t\t\tint col = map.get(nums[i][1]);\n\t\t\t\tint row = nums[i][2];\n\t\t\t\tarr[row][col] = val;\n\t\t\t}\n\t\t\t// System.err.println(Arrays.deepToString(arr));\n\t\t\tsolve(0, arr);\n\t\t} else {\n\t\t\tans = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tans += nums[i][0];\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n\tprivate void solve(int index, int[][] arr) {\n\t\tif (index == arr[0].length) {\n\t\t\tint temp = 0;\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tint m = 0;\n\t\t\t\tfor (int j = 0; j < arr[i].length; j++) {\n\t\t\t\t\tm = Math.max(m, arr[i][j]);\n\t\t\t\t}\n\t\t\t\ttemp += m;\n\t\t\t}\n\t\t\tans = Math.max(temp, ans);\n\t\t} else {\n\t\t\tfor (int t = 0; t < N; t++) {\n\t\t\t\tint v = arr[0][index];\n\t\t\t\tfor (int i = 0; i < N - 1; i++) {\n\t\t\t\t\tarr[i][index] = arr[i + 1][index];\n\t\t\t\t}\n\t\t\t\tarr[N - 1][index] = v;\n\t\t\t\tsolve(index + 1, arr);\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tfinal private int BUFFER_SIZE = 1 << 10;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic FastScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tdin = new DataInputStream(stream);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic FastScanner(String fileName) throws IOException {\n\t\t\tPath p = Paths.get(fileName);\n\t\t\tbuffer = Files.readAllBytes(p);\n\t\t\tbytesRead = buffer.length;\n\t\t}\n\n\t\tint[] 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\tString nextLine() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (c != -1 && isEndline(c))\n\t\t\t\tc = read();\n\t\t\tif (c == -1) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tif (c >= 0) {\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t}\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\tboolean isEndline(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tString next() throws Exception {\n\t\t\tint c = readOutSpaces();\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\tboolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg) c = 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) return -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) c = 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) return -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) c = 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) return -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tif (din == null) {\n\t\t\t\tbufferPointer = 0;\n\t\t\t\tbytesRead = -1;\n\t\t\t} else {\n\t\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\t}\n\t\t\tif (bytesRead == -1) buffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead) fillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tprivate int readOutSpaces() throws IOException {\n\t\t\twhile (true) {\n\t\t\t\tif (bufferPointer == bytesRead) fillBuffer();\n\t\t\t\tint c = buffer[bufferPointer++];\n\t\t\t\tif (!isSpaceChar(c)) {\n\t\t\t\t\treturn c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null) return;\n\t\t\tdin.close();\n\t\t}\n\n\t\tpublic int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {\n\t\t\tint[][] adj = new int[N][];\n\t\t\tint[] numNodes = new int[N];\n\t\t\tint[][] input = new int[M][2];\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = nextInt();\n\t\t\t\tint b = nextInt();\n\t\t\t\tif (zeroIndexed) {\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tinput[i][0] = a;\n\t\t\t\tinput[i][1] = b;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) numNodes[b]++;\n\t\t\t}\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tadj[i] = new int[numNodes[i]];\n\t\t\t\tnumNodes[i] = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = input[i][0];\n\t\t\t\tint b = input[i][1];\n\t\t\t\tadj[a][numNodes[a]++] = b;\n\t\t\t\tif (bidirectional) adj[b][numNodes[b]++] = a;\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\n\t\tpublic int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {\n\t\t\tint[][][] adj = new int[N][][];\n\t\t\tint[] numNodes = new int[N];\n\t\t\tint[][] input = new int[M][3];\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = nextInt();\n\t\t\t\tint b = nextInt();\n\t\t\t\tif (zeroIndexed) {\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tint d = nextInt();\n\t\t\t\tinput[i][0] = a;\n\t\t\t\tinput[i][1] = b;\n\t\t\t\tinput[i][2] = d;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) numNodes[b]++;\n\t\t\t}\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tadj[i] = new int[numNodes[i]][2];\n\t\t\t\tnumNodes[i] = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = input[i][0];\n\t\t\t\tint b = input[i][1];\n\t\t\t\tint d = input[i][2];\n\t\t\t\tadj[a][numNodes[a]][0] = b;\n\t\t\t\tadj[a][numNodes[a]][1] = d;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) {\n\t\t\t\t\tadj[b][numNodes[b]][0] = a;\n\t\t\t\t\tadj[b][numNodes[b]][1] = d;\n\t\t\t\t\tnumNodes[b]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\t}\n\n\tstatic class FastPrinter {\n\t\tstatic final char ENDL = '\\n';\n\t\tStringBuilder buf;\n\t\tPrintWriter pw;\n\n\t\tpublic FastPrinter(OutputStream stream) {\n\t\t\tbuf = new StringBuilder();\n\t\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));\n\t\t}\n\n\t\tpublic FastPrinter(String fileName) throws Exception {\n\t\t\tbuf = new StringBuilder();\n\t\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));\n\t\t}\n\n\t\tpublic FastPrinter(StringBuilder buf) {\n\t\t\tthis.buf = buf;\n\t\t}\n\n\t\tpublic void print(int a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(long a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(char a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(char[] a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(double a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(String a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(Object a) {\n\t\t\tbuf.append(a.toString());\n\t\t}\n\n\t\tpublic void println() {\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(int a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(long a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(char a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(char[] a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(double a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(String a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(Object a) {\n\t\t\tbuf.append(a.toString());\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void printf(String format, Object... args) {\n\t\t\tbuf.append(String.format(format, args));\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tpw.print(buf);\n\t\t\tpw.close();\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\tpw.print(buf);\n\t\t\tpw.flush();\n\t\t\tbuf.setLength(0);\n\t\t}\n\n\t}\n\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.stream.IntStream;\n\npublic class Test {\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 readLine() {\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  public static void main(String[] args) {\n    Test te = new Test();\n    te.start();\n    writer.flush();\n  }\n\n  void start() {\n    int t = readInt();\n    while (t-- > 0) {\n      int n = readInt(), m = readInt();\n      int[][] a = new int[n][m];\n      int[][] e = new int[n*m][];\n      for (int i = 0; i < n; i++)\n        for (int j = 0; j < m; j++) {\n          a[i][j] = readInt();\n          e[i*m+j] = new int[]{a[i][j], j};\n        }\n      Arrays.sort(e, (x, y) -> x[0] == y[0] ? Integer.compare(x[1], y[1])\n          : Integer.compare(y[0], x[0]));\n      Set<Integer> cols = new HashSet<>();\n      for (int[] x : e) {\n        cols.add(x[1]);\n        if (cols.size() >= n) break;\n      }\n      int[] dp = new int[1<<n];\n      Arrays.fill(dp, -1);\n      dp[0] = 0;\n      for (int c : cols) {\n        for (int i = (1 << n) - 1; i >= 0; i--) {\n          int u = (1 << n) - 1 - i;\n          int p = u;\n          if (dp[i] >= 0)\n            while (p > 0) {\n              for (int r = 0; r < n; r++) {\n                  int sum = 0;\n                  for (int j = 0; j < n; j++) if (((p >> j) & 1) != 0) sum += a[(j + r) % n][c];\n                  dp[i | p] = Math.max(dp[i | p], dp[i] + sum);\n                }\n              p = (p - 1) & u;\n            }\n        }\n      }\n      writer.println(dp[(1<<n) - 1]);\n    }\n  }\n}\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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.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 null\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        Input in = new Input(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, Input in, PrintWriter out) {\n            try {\n                int kt = in.readInt();\n                for (int nt = 0; nt < kt; nt++) {\n                    int n = in.readInt();\n                    int m = in.readInt();\n                    int[][] a = new int[m][n];\n                    for (int i = 0; i < n; i++) {\n                        for (int j = 0; j < m; j++) {\n                            a[j][i] = in.readInt();\n                        }\n                    }\n\n                    Arrays.sort(a, (x, y) -> {\n                        int xMax = 0;\n                        for (int i = 0; i < x.length; i++) {\n                            xMax = Math.max(xMax, x[i]);\n                        }\n                        int yMax = 0;\n                        for (int i = 0; i < y.length; i++) {\n                            yMax = Math.max(yMax, y[i]);\n                        }\n                        return Integer.compare(-xMax, -yMax);\n                    });\n\n                    int ans = 0;\n                    int[] s = new int[4];\n                    for (s[0] = 0; s[0] < n; s[0]++) {\n                        for (s[1] = 0; s[1] < n; s[1]++) {\n                            for (s[2] = 0; s[2] < n; s[2]++) {\n                                for (s[3] = 0; s[3] < n; s[3]++) {\n                                    int cur = 0;\n                                    for (int i = 0; i < n; i++) {\n                                        int max = 0;\n                                        for (int j = 0; j < Math.min(m, n); j++) {\n                                            max = Math.max(max, a[j][(i + s[j]) % n]);\n                                        }\n                                        cur += max;\n                                    }\n                                    ans = Math.max(cur, ans);\n                                }\n                            }\n                        }\n                    }\n\n                    out.println(ans);\n                }\n\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n    }\n\n    static class Input {\n        public final BufferedReader reader;\n        private String line = \"\";\n        private int pos = 0;\n\n        public Input(InputStream inputStream) {\n            reader = new BufferedReader(new InputStreamReader(inputStream));\n        }\n\n        private boolean isSpace(char ch) {\n            return ch <= 32;\n        }\n\n        public String readWord() throws IOException {\n            skip();\n            int start = pos;\n            while (pos < line.length() && !isSpace(line.charAt(pos))) {\n                pos++;\n            }\n            return line.substring(start, pos);\n        }\n\n        public int readInt() throws IOException {\n            return Integer.parseInt(readWord());\n        }\n\n        private void skip() throws IOException {\n            while (true) {\n                if (pos >= line.length()) {\n                    line = reader.readLine();\n                    pos = 0;\n                }\n                while (pos < line.length() && isSpace(line.charAt(pos))) {\n                    pos++;\n                }\n                if (pos < line.length()) {\n                    return;\n                }\n            }\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic int n, m, a[][];\n\tstatic int[][] memo;\n\n\tstatic int[] getCol(int col, int shift) {\n\t\tint[] ans = new int[n];\n\t\tfor (int i = 0, j = shift; i < n; i++, j = (j + 1) % n) {\n\t\t\tans[i] = a[j][col];\n\t\t}\n\t\treturn ans;\n\n\t}\n\n\tstatic int dp(int col, int msk) {\n\t\tif (col == m)\n\t\t\treturn 0;\n\t\tif (memo[msk][col] != -1)\n\t\t\treturn memo[msk][col];\n\t\tint ans = 0;\n\t\tfor (int shift = 0; shift < n; shift++) {\n\t\t\tint[] currCol = getCol(col, shift);\n\t\t\tfor (int nxtMsk = 0; nxtMsk < 1 << n; nxtMsk++) {\n\t\t\t\tif ((nxtMsk & msk) != msk)\n\t\t\t\t\tcontinue;\n\t\t\t\tint curr = 0;\n\t\t\t\tint diff = msk ^ nxtMsk;\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif ((diff & 1 << i) != 0)\n\t\t\t\t\t\tcurr += currCol[i];\n\t\t\t\tans = Math.max(ans, dp(col + 1, nxtMsk) + curr);\n\t\t\t}\n\t\t}\n\t\treturn memo[msk][col] = ans;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint tc = sc.nextInt();\n\t\twhile (tc-- > 0) {\n\t\t\tn = sc.nextInt();\n\t\t\tm = sc.nextInt();\n\t\t\tmemo = new int[1 << n][m];\n\t\t\tfor (int[] x : memo)\n\t\t\t\tArrays.fill(x, -1);\n\t\t\ta = 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\ta[i][j] = sc.nextInt();\n\t\t\tout.println(dp(0, 0));\n\t\t}\n\t\tout.close();\n\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tshuffle(a);\n\t\tArrays.sort(a);\n\t}\n\n\tstatic void shuffle(int[] a) {\n\t\tint n = a.length;\n\t\tRandom rand = new Random();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint tmpIdx = rand.nextInt(n);\n\t\t\tint tmp = a[i];\n\t\t\ta[i] = a[tmpIdx];\n\t\t\ta[tmpIdx] = tmp;\n\t\t}\n\t}\n\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n    static int inf = (int) 1e9 + 7;\n    static int n, m, a[][];\n    static ArrayList<Integer> used;\n    static int num[];\n    static int ans;\n\n    static void rec(int id) {\n        if (id == used.size()) {\n            check();\n            return;\n        }\n\n        for(int i = 0;i < n;i++) {\n            num[id] = i;\n            rec(id + 1);\n        }\n    }\n\n    static void check() {\n        int new_ans = 0;\n        for(int i = 0;i < n;i++) {\n            int max = 0;\n            for(int j = 0;j < used.size();j++) {\n                max = Math.max(max, a[(i + num[j]) % n][used.get(j)]);\n            }\n            new_ans += max;\n        }\n        ans = Math.max(ans, new_ans);\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        int test = nextInt();\n        while(test-- > 0) {\n            n = nextInt();\n            m = nextInt();\n            a = new int [n][m];\n            for(int i = 0;i < n;i++) {\n                for(int j = 0;j < m;j++) a[i][j] = nextInt();\n            }\n            used = new ArrayList<>();\n            num = new int [n * m];\n            ans = 0;\n\n            pair b[] = new pair[n * m];\n\n            for(int i = 0;i < n;i++) {\n                for(int j = 0;j < m;j++) {\n                    b[i * m + j] = new pair(a[i][j], j);\n                }\n            }\n\n            Arrays.sort(b, new pair());\n\n            for(int i = b.length - 1;i >= Math.max(0, b.length - 5);i--) {\n                int v = b[i].y;\n\n                boolean bad = false;\n\n                for(int j = 0;j < used.size();j++) if (used.get(j) == v) bad = true;\n\n                if (!bad) used.add(v);\n            }\n\n            rec(0);\n\n            pw.println(ans);\n        }\n        pw.close();\n    }\n\n    static BufferedReader br;\n    static StringTokenizer st = new StringTokenizer(\"\");\n    static PrintWriter pw;\n\n    static String next() throws IOException {\n        while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\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\nclass pair implements Comparator<pair>{\n    int x, y;\n    pair(int x, int y) {\n        this.x = x;\n        this.y = y;\n    }\n\n    pair() {}\n\n    @Override\n    public int compare(pair o1, pair o2) {\n        return Integer.compare(o1.x, o2.x);\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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 ilyakor\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    OutputWriter out = new OutputWriter(outputStream);\n    TaskE1 solver = new TaskE1();\n    int testCount = Integer.parseInt(in.next());\n    for (int i = 1; i <= testCount; i++) {\n      solver.solve(i, in, out);\n    }\n    out.close();\n  }\n\n  static class TaskE1 {\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n      int n = in.nextInt();\n      int m = in.nextInt();\n      int[][] d = new int[2][1 << n];\n      int[] buf = new int[1 << n];\n      int[][] a = new int[m][n];\n      for (int i = 0; i < n; ++i) {\n        for (int j = 0; j < m; ++j) {\n          a[j][i] = in.nextInt();\n        }\n      }\n      for (int i = 0; i < m; ++i) {\n        int[] prev = d[i % 2], nx = d[(i + 1) % 2];\n        for (int shift = 0; shift < n; ++shift) {\n          int[] b = new int[n];\n          for (int j = 0; j < n; ++j) {\n            b[j] = a[i][(j + shift) % n];\n          }\n          System.arraycopy(prev, 0, buf, 0, prev.length);\n          for (int mask = 0; mask < (1 << n); ++mask) {\n            int val0 = buf[mask];\n            for (int j = 0; j < n; ++j) {\n              if ((mask >> j) % 2 == 0) {\n                int val = val0 + b[j];\n                int nm = mask ^ (1 << j);\n                if (val > buf[nm]) {\n                  buf[nm] = val;\n                }\n              }\n            }\n          }\n          for (int mask = 0; mask < (1 << n); ++mask) {\n            if (nx[mask] < buf[mask]) {\n              nx[mask] = buf[mask];\n            }\n          }\n        }\n      }\n      out.printLine(d[m % 2][(1 << n) - 1]);\n    }\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  }\n\n  static class InputReader {\n\n    private InputStream stream;\n    private byte[] buffer = new byte[10000];\n    private int cur;\n    private int count;\n\n    public InputReader(InputStream stream) {\n      this.stream = stream;\n    }\n\n    public static boolean isSpace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int read() {\n      if (count == -1) {\n        throw new InputMismatchException();\n      }\n      try {\n        if (cur >= count) {\n          cur = 0;\n          count = stream.read(buffer);\n          if (count <= 0) {\n            return -1;\n          }\n        }\n      } catch (IOException e) {\n        throw new InputMismatchException();\n      }\n      return buffer[cur++];\n    }\n\n    public int readSkipSpace() {\n      int c;\n      do {\n        c = read();\n      } while (isSpace(c));\n      return c;\n    }\n\n    public String nextToken() {\n      int c = readSkipSpace();\n      StringBuilder sb = new StringBuilder();\n      while (!isSpace(c)) {\n        sb.append((char) c);\n        c = read();\n      }\n      return sb.toString();\n    }\n\n    public String next() {\n      return nextToken();\n    }\n\n    public int nextInt() {\n      int sgn = 1;\n      int c = readSkipSpace();\n      if (c == '-') {\n        sgn = -1;\n        c = read();\n      }\n      int res = 0;\n      do {\n        if (c < '0' || c > '9') {\n          throw new InputMismatchException();\n        }\n        res = res * 10 + c - '0';\n        c = read();\n      } while (!isSpace(c));\n      res *= sgn;\n      return res;\n    }\n\n  }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "//package cf584d12;\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tMyScanner sc = new MyScanner();\n\t\tint t = sc.nextInt();\n\t\tfor(int w = 0; w < t; w++) {\n\t\t\tint n = sc.nextInt(), m = sc.nextInt();\n\t\t\tTreeSet<X> set = new TreeSet<X>();\n\t\t\tint[][] grid = 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\tgrid[i][j] = sc.nextInt();\n\t\t\t\t\tset.add(new X(i, j, grid[i][j]));\n\t\t\t\t}\n\t\t\tY[] top4 = new Y[n];\n\t\t\tint sum = 0;\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\ttop4[i] = new Y(set.pollLast());\n\t\t\t\tsum += top4[i].a;\n\t\t\t}\n\t\t\tArrays.sort(top4);\n\t\t\tHashSet<String> strs = new HashSet<String>();\n\t\t\tAAA[] sss = new AAA[n];\n\t\t\tboolean[] used = new boolean[n];\n\t\t\tif(n == 4) {\n\t\t\t\tfor(int i = 0; i < 4; i++) {\n\t\t\t\t\tint max = -1, jj = -1;\n\t\t\t\t\tfor(int j = 0; j < 4; j++) {\n\t\t\t\t\t\tif(!used[j] && top4[j].a > max) {\n\t\t\t\t\t\t\tmax = top4[j].a;\n\t\t\t\t\t\t\tjj = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tused[jj] = true;\n\t\t\t\t\tsss[i] = new AAA(max, jj);\n\t\t\t\t}\n\t\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\t\tstrs.add(top4[i].i + \" \" + top4[i].j);\n\t\t\t}\n\t\t\tint ans = sum;\n\t\t\tif(n == 4 && top4[0].j == top4[1].j && top4[2].j == top4[3].j && top4[0].j != top4[2].j) {\n\t\t\t\tif(two(top4[0], top4[1]) != two(top4[2], top4[3])) {\n\t\t\t\t\tans = 0;\n\t\t\t\t\tint oneCol = two(top4[0], top4[1]) ? top4[2].j : top4[0].j;\n\t\t\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\t\t\tfor(int j = 0; j < m; j++)\n\t\t\t\t\t\t\tif(!strs.contains(i + \" \" + j)){\n\t\t\t\t\t\t\t\tint no = -1;\n\t\t\t\t\t\t\t\tfor(int k = 0; k < 4; k++)\n\t\t\t\t\t\t\t\t\tif(j == oneCol && top4[k].j == oneCol && two(top4[k], new Y(new X(i, j, 0))))\n\t\t\t\t\t\t\t\t\t\tno = k;\n\t\t\t\t\t\t\t\tans = max(ans, sum - sss[no == sss[3].i ? 2 : 3].a + grid[i][j]);\n\t\t\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\tout.close();\n\t}\n\tstatic class AAA {\n\t\tint a, i;\n\t\tpublic AAA(int A, int I) {\n\t\t\ta = A; \n\t\t\ti = I;\n\t\t}\n\t}\n\tstatic boolean two(Y y1, Y y2) {\n\t\treturn (y1.i - y2.i + 4) % 4 == 2;\n\t}\n\tstatic class Y implements Comparable<Y> {\n\t\tint i, j, a;\n\t\tpublic Y(X x) {\n\t\t\ti = x.i;\n\t\t\tj = x.j;\n\t\t\ta = x.a; \n\t\t}\n\t\tpublic int compareTo(Y x) {\n\t\t\tif(j == x.j)\n\t\t\t\treturn i - x.i;\n\t\t\treturn j - x.j;\n\t\t}\n\t}\n\tstatic class X implements Comparable<X> {\n\t\tint i, j, a;\n\t\tpublic X(int I, int J, int A) {\n\t\t\ti = I;\n\t\t\tj = J;\n\t\t\ta = A; \n\t\t}\n\t\tpublic int compareTo(X x) {\n\t\t\tif(a == x.a && i == x.i)\n\t\t\t\treturn j - x.j;\n\t\t\telse if(a == x.a)\n\t\t\t\treturn i - x.i;\n\t\t\treturn a - x.a;\n\t\t}\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}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.util.concurrent.ThreadLocalRandom;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\npublic class Main2 {\n\n    static long mod = 998244353;\n    static FastScanner scanner;\n\n    static StringBuilder result = new StringBuilder();\n\n    public static void main(String[] args) {\n        scanner = new FastScanner();\n        int t = scanner.nextInt();\n        for (int i = 0; i < t; i++) {\n            solve();\n            result.append(\"\\n\");\n        }\n        System.out.print(result.toString());\n    }\n\n\n\n    static void solve() {\n        int n = scanner.nextInt();\n        int m = scanner.nextInt();\n        PriorityQueue<WithIdx2> queue = new PriorityQueue<>();\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                queue.add(new WithIdx2(scanner.nextInt(), i, j));\n            }\n        }\n\n        if (n <= 3) {\n            int res = 0;\n            for (int k = 0; k < n; k++) {\n                res += queue.poll().val;\n            }\n            result.append(res);\n        } else {\n\n            List<WithIdx2> a = new ArrayList<>();\n            for (int i = 0; i < 9; i++) {\n                if (!queue.isEmpty()) a.add(queue.poll());\n            }\n            int[] offsets = new int[m];\n            best = -1;\n            Arrays.fill(offsets, -100);\n            put(0, a, offsets, new int[4]);\n            result.append(best);\n        }\n    }\n\n    static int best = -1;\n\n    static void put(int current, List<WithIdx2> vals, int[] offsets, int[] rows) {\n        if (current == vals.size()) {\n            for (int i = 0; i < rows.length; i++) if (rows[i] == 0) return;\n            int sum = IntStream.of(rows).sum();\n            best = Math.max(best, sum);\n            return;\n        }\n        for (int row = 0; row < 4; row++) {\n            if (rows[row] == 0) {\n                WithIdx2 c = vals.get(current);\n                if (offsets[c.y] == -100) {\n                    rows[row] = c.val;\n                    offsets[c.y] = row - c.x;\n                    put(current + 1, vals, offsets, rows);\n                    rows[row] = 0;\n                    offsets[c.y] = -100;\n                } else {\n                    int bind = c.x + offsets[c.y];\n                    if (bind < 0) bind += 4;\n                    if (bind >= 4) bind -= 4;\n                    if (row == bind) {\n                        rows[row] = c.val;\n                        put(current + 1, vals, offsets, rows);\n                        rows[row] = 0;\n                    }\n                }\n            }\n        }\n        put(current + 1, vals, offsets, rows);\n    }\n\n    static class WithIdx2 implements Comparable<WithIdx2>{\n        int x, y, val;\n\n        public WithIdx2(int val, int x, int y) {\n            this.val = val;\n            this.x = x;\n            this.y = y;\n        }\n\n        @Override\n        public int compareTo(WithIdx2 o) {\n            return -Integer.compare(val, o.val);\n        }\n    }\n\n\n\n    static class WithIdx implements Comparable<WithIdx>{\n        int val, 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            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\n/*\n1\n4 2\n5 7 6 2 2 5 3 6\n */", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.stream.IntStream;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.UncheckedIOException;\nimport java.util.stream.Stream;\nimport java.nio.charset.Charset;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author mikit\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        LightScanner in = new LightScanner(inputStream);\n        LightWriter out = new LightWriter(outputStream);\n        E1RotateColumnsEasyVersion solver = new E1RotateColumnsEasyVersion();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class E1RotateColumnsEasyVersion {\n        public void solve(int testNumber, LightScanner in, LightWriter out) {\n            // out.setBoolLabel(LightWriter.BoolLabel.YES_NO_FIRST_UP);\n            int testCases = in.ints();\n            for (int testCase = 0; testCase < testCases; testCase++) {\n                int n = in.ints(), m = in.ints();\n                int pow = 1;\n                for (int i = 0; i < n; i++) pow *= n;\n                int[][] a = in.ints(n, m);\n                E1RotateColumnsEasyVersion.P[] columns = new E1RotateColumnsEasyVersion.P[m];\n                for (int i = 0; i < m; i++) {\n                    int max = 0;\n                    for (int j = 0; j < n; j++) max = Math.max(max, a[j][i]);\n                    columns[i] = new E1RotateColumnsEasyVersion.P(i, max);\n                }\n                IntroSort.sort(columns, Comparator.comparing(column -> -column.m));\n\n                int ans = 0;\n                for (int i = 0; i < pow; i++) {\n                    int[] res = new int[n];\n                    int t = i;\n                    for (int j = 0; j < Math.min(n, m); j++) {\n                        int shift = t % n;\n                        t /= n;\n                        for (int k = 0; k < n; k++) {\n                            res[(k + shift) % n] = Math.max(res[(k + shift) % n], a[k][columns[j].i]);\n                        }\n                    }\n                    int sum = 0;\n                    for (int j = 0; j < n; j++) {\n                        sum += res[j];\n                    }\n                    ans = Math.max(ans, sum);\n                }\n                out.ans(ans).ln();\n            }\n        }\n\n        private static class P {\n            int i;\n            int m;\n\n            P(int i, int m) {\n                this.i = i;\n                this.m = m;\n            }\n\n        }\n\n    }\n\n    static class InsertionSort {\n        private InsertionSort() {\n        }\n\n        static <T> void sort(T[] a, int low, int high, Comparator<? super T> comparator) {\n            for (int i = low; i < high; i++) {\n                for (int j = i; j > low && comparator.compare(a[j - 1], a[j]) > 0; j--) {\n                    ArrayUtil.swap(a, j - 1, j);\n                }\n            }\n        }\n\n    }\n\n    static class HeapSort {\n        private HeapSort() {\n        }\n\n        private static <T> void heapfy(T[] a, int low, int high, int i, T val, Comparator<? super T> comparator) {\n            int child = 2 * i - low + 1;\n            while (child < high) {\n                if (child + 1 < high && comparator.compare(a[child], a[child + 1]) < 0) {\n                    child++;\n                }\n                if (comparator.compare(val, a[child]) >= 0) {\n                    break;\n                }\n                a[i] = a[child];\n                i = child;\n                child = 2 * i - low + 1;\n            }\n            a[i] = val;\n        }\n\n        static <T> void sort(T[] a, int low, int high, Comparator<T> comparator) {\n            for (int p = (high + low) / 2 - 1; p >= low; p--) {\n                heapfy(a, low, high, p, a[p], comparator);\n            }\n            while (high > low) {\n                high--;\n                T pval = a[high];\n                a[high] = a[low];\n                heapfy(a, low, high, low, pval, comparator);\n            }\n        }\n\n    }\n\n    static class QuickSort {\n        private QuickSort() {\n        }\n\n        private static <T> void med(T[] a, int low, int x, int y, int z, Comparator<? super T> comparator) {\n            if (comparator.compare(a[z], a[x]) < 0) {\n                ArrayUtil.swap(a, low, x);\n            } else if (comparator.compare(a[y], a[z]) < 0) {\n                ArrayUtil.swap(a, low, y);\n            } else {\n                ArrayUtil.swap(a, low, z);\n            }\n        }\n\n        static <T> int step(T[] a, int low, int high, Comparator<? super T> comparator) {\n            int x = low + 1, y = low + (high - low) / 2, z = high - 1;\n            if (comparator.compare(a[x], a[y]) < 0) {\n                med(a, low, x, y, z, comparator);\n            } else {\n                med(a, low, y, x, z, comparator);\n            }\n\n            int lb = low + 1, ub = high;\n            while (true) {\n                while (comparator.compare(a[lb], a[low]) < 0) {\n                    lb++;\n                }\n                ub--;\n                while (comparator.compare(a[low], a[ub]) < 0) {\n                    ub--;\n                }\n                if (lb >= ub) {\n                    return lb;\n                }\n                ArrayUtil.swap(a, lb, ub);\n                lb++;\n            }\n        }\n\n    }\n\n    static final class BitMath {\n        private BitMath() {\n        }\n\n        public static int count(int v) {\n            v = (v & 0x55555555) + ((v >> 1) & 0x55555555);\n            v = (v & 0x33333333) + ((v >> 2) & 0x33333333);\n            v = (v & 0x0f0f0f0f) + ((v >> 4) & 0x0f0f0f0f);\n            v = (v & 0x00ff00ff) + ((v >> 8) & 0x00ff00ff);\n            v = (v & 0x0000ffff) + ((v >> 16) & 0x0000ffff);\n            return v;\n        }\n\n        public static int msb(int v) {\n            if (v == 0) {\n                throw new IllegalArgumentException(\"Bit not found\");\n            }\n            v |= (v >> 1);\n            v |= (v >> 2);\n            v |= (v >> 4);\n            v |= (v >> 8);\n            v |= (v >> 16);\n            return count(v) - 1;\n        }\n\n    }\n\n    static interface Verified {\n    }\n\n    static class LightWriter implements AutoCloseable {\n        private final Writer out;\n        private boolean autoflush = false;\n        private boolean breaked = true;\n\n        public LightWriter(Writer out) {\n            this.out = out;\n        }\n\n        public LightWriter(OutputStream out) {\n            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));\n        }\n\n        public LightWriter print(char c) {\n            try {\n                out.write(c);\n                breaked = false;\n            } catch (IOException ex) {\n                throw new UncheckedIOException(ex);\n            }\n            return this;\n        }\n\n        public LightWriter print(String s) {\n            try {\n                out.write(s, 0, s.length());\n                breaked = false;\n            } catch (IOException ex) {\n                throw new UncheckedIOException(ex);\n            }\n            return this;\n        }\n\n        public LightWriter ans(String s) {\n            if (!breaked) {\n                print(' ');\n            }\n            return print(s);\n        }\n\n        public LightWriter ans(int i) {\n            return ans(Integer.toString(i));\n        }\n\n        public LightWriter ln() {\n            print(System.lineSeparator());\n            breaked = true;\n            if (autoflush) {\n                try {\n                    out.flush();\n                } catch (IOException ex) {\n                    throw new UncheckedIOException(ex);\n                }\n            }\n            return this;\n        }\n\n        public void close() {\n            try {\n                out.close();\n            } catch (IOException ex) {\n                throw new UncheckedIOException(ex);\n            }\n        }\n\n    }\n\n    static class IntroSort {\n        private static int INSERTIONSORT_THRESHOLD = 16;\n\n        private IntroSort() {\n        }\n\n        static <T> void sort(T[] a, int low, int high, int maxDepth, Comparator<T> comparator) {\n            while (high - low > INSERTIONSORT_THRESHOLD) {\n                if (maxDepth-- == 0) {\n                    HeapSort.sort(a, low, high, comparator);\n                    return;\n                }\n                int cut = QuickSort.step(a, low, high, comparator);\n                sort(a, cut, high, maxDepth, comparator);\n                high = cut;\n            }\n            InsertionSort.sort(a, low, high, comparator);\n        }\n\n        public static <T> void sort(T[] a, Comparator<T> comparator) {\n            if (a.length <= INSERTIONSORT_THRESHOLD) {\n                InsertionSort.sort(a, 0, a.length, comparator);\n            } else {\n                sort(a, 0, a.length, 2 * BitMath.msb(a.length), comparator);\n            }\n        }\n\n    }\n\n    static final class ArrayUtil {\n        private ArrayUtil() {\n        }\n\n        public static <T> void swap(T[] a, int x, int y) {\n            T t = a[x];\n            a[x] = a[y];\n            a[y] = t;\n        }\n\n    }\n\n    static class LightScanner {\n        private BufferedReader reader = null;\n        private StringTokenizer tokenizer = null;\n\n        public LightScanner(InputStream in) {\n            reader = new BufferedReader(new InputStreamReader(in));\n        }\n\n        public String string() {\n            if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new UncheckedIOException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int ints() {\n            return Integer.parseInt(string());\n        }\n\n        public int[] ints(int length) {\n            return IntStream.range(0, length).map(x -> ints()).toArray();\n        }\n\n        public int[][] ints(int height, int width) {\n            return IntStream.range(0, height).mapToObj(x -> ints(width)).toArray(int[][]::new);\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n/*\n\n*/\n\npublic class e1 {\n\n\tstatic int n;\n\tstatic int m;\n\tstatic int[][] mat;\n\n\tpublic static void main(String[] args){\n\t\tJS scan = new JS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint t = scan.nextInt();\n\t\tfor(int q = 1; q <= t; q++){\n\t\t\tans = 0;\n\t\t\tn = scan.nextInt();\n\t\t\tm = scan.nextInt();\n\t\t\tmat = 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\tmat[i][j] = scan.nextInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] max = new int[m];\n\t\t\tPriorityQueue<Item> pq = new PriorityQueue<Item>();\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\tmax[i] = Math.max(max[i], mat[j][i]);\n\t\t\t\t}\n\t\t\t\tpq.add(new Item(i, max[i]));\n\t\t\t}\n\t\t\tArrayList<Item> guys = new ArrayList<Item>();\n\t\t\twhile(!pq.isEmpty() && guys.size() < 8){\n\t\t\t\tItem tt = pq.poll();\n\t\t\t\tguys.add(tt);\n\t\t\t}\n\t\t\tperm(guys, 0, new int[guys.size()]);\n\t\t\tout.println(ans);\n\t\t}\n\t\tout.flush();\n\t}\n\n\tstatic int ans = 0;\n\n\tstatic void perm(ArrayList<Item> guys, int me, int[] shift){\n\t\tif(me == guys.size()){\n\t\t\t// System.out.println(Arrays.toString(shift));\n\t\t\tint res = 0;\n\t\t\tint[] best = new int[n];\n\t\t\tfor(int j = 0; j < guys.size(); j++){\n\t\t\t\tItem g = guys.get(j);\n\t\t\t\tint pp = g.a;\n\t\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\t\tbest[(i+shift[j])%n] = Math.max(best[(i+shift[j])%n], mat[i][pp]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 0; i < n; i++) res += best[i];\n\t\t\tans = Math.max(res, ans);\n\t\t\treturn;\n\t\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tshift[me] = i;\n\t\t\tperm(guys, me+1, shift);\n\t\t}\n\t}\n\n\tstatic class Item implements Comparable<Item>{\n\n\t\tint a;\n\t\tint b;\n\n\t\tpublic Item(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(Item o){\n\t\t\treturn o.b-this.b;\n\t\t}\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 \n\t\tpublic JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n \n\t\tpublic JS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n \n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}\t\t\t\t\n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n \n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n \n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n \n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n \n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskE1 solver = new TaskE1();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE1 {\n        int n;\n        int m;\n        int[][] map;\n        int[][] dp;\n\n        int two(int idx) {\n            return 1 << idx;\n        }\n\n        boolean contain(int mask, int idx) {\n            return (mask & two(idx)) > 0;\n        }\n\n        int best(int mask, int col) {\n            int res = 0;\n            for (int rot = 0; rot < n; rot++) {\n                int sum = 0;\n                for (int i = 0; i < n; i++) {\n                    int curRow = (rot + i) % n;\n                    if (contain(mask, curRow)) {\n                        sum += map[i][col];\n                    }\n                }\n                res = Math.max(res, sum);\n            }\n            return res;\n        }\n\n        int rec(int col, int used) {\n            if (col == m)\n                return 0;\n\n            int res = dp[col][used];\n            if (res != -1)\n                return res;\n            res = 0;\n            for (int mask = 0; mask < two(n); mask++)\n                if ((mask & used) == 0) {\n                    res = Math.max(res, rec(col + 1, used | mask) + best(mask, col));\n                }\n            dp[col][used] = res;\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int t = in.nextInt();\n            for (int test = 0; test < t; test++) {\n                n = in.nextInt();\n                m = in.nextInt();\n                map = new int[n][m];\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        map[i][j] = in.nextInt();\n                    }\n                }\n                dp = new int[m][1 << n];\n                for (int[] aux : dp)\n                    Arrays.fill(aux, -1);\n                int ans = rec(0, 0);\n                out.println(ans);\n            }\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main{\n\tstatic int[][]memo;\n\tstatic int n,m,in[][];\n\tstatic int dp(int col,int maxRowMask) {\n\t\tif(col>=m)return 0;\n\t\tif(memo[col][maxRowMask]!=-1)return memo[col][maxRowMask];\n\t\t\n\t\tint ans=0;\n\t\t\n\t\tfor(int colMask=0;colMask<(1<<n);colMask++) {\n\t\t\t\n\t\t\tint sum=0;\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tif(((colMask>>i)&1)!=0) {\n\t\t\t\t\tsum+=in[i][col];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint curMask=colMask;\n\t\t\tfor(int cyclicShift=0;cyclicShift<n;cyclicShift++) {\n\t\t\t\tif((curMask&maxRowMask)!=0) {//some row has max value already determined\n\t\t\t\t\tint lastBit=curMask&1;\n\t\t\t\t\tcurMask>>=1;\n\t\t\t\t\tcurMask|=(lastBit<<(n-1));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tans=Math.max(ans, sum+dp(col+1, maxRowMask|curMask));\n\t\t\t\t\n\t\t\t\tint lastBit=curMask&1;\n\t\t\t\tcurMask>>=1;\n\t\t\t\tcurMask|=(lastBit<<(n-1));\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\treturn memo[col][maxRowMask]=ans;\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tpw=new PrintWriter(System.out);\n\t\tsc = new MScanner(System.in);\n\t\tint tc=sc.nextInt();\n\t\twhile(tc-->0) {\n\t\t\tn=sc.nextInt();m=sc.nextInt();\n\t\t\tin=new int[n][m];\n\t\t\tfor(int i=0;i<n;i++)in[i]=sc.intArr(m);\n\t\t\tmemo=new int[m][1<<n];\n\t\t\tfor(int i=0;i<m;i++)Arrays.fill(memo[i], -1);\n\t\t\tpw.println(dp(0, 0));\n\t\t}\n\t\t\n\t\t\n\t\tpw.flush();\n\t}\n\tstatic PrintWriter pw;\n\tstatic MScanner  sc;\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n \n\t\tpublic MScanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n \n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int[] intArr(int n) throws IOException {\n\t        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t        return in;\n\t\t}\n\t\tpublic long[] longArr(int n) throws IOException {\n\t        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t        return in;\n\t\t}\n\t\tpublic int[] intSortedArr(int n) throws IOException {\n\t        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t        shuffle(in);\n\t        Arrays.sort(in);\n\t        return in;\n\t\t}\n\t\tpublic long[] longSortedArr(int n) throws IOException {\n\t        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t        shuffle(in);\n\t        Arrays.sort(in);\n\t        return in;\n\t\t}\n\t\tpublic Integer[] IntegerArr(int n) throws IOException {\n\t        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t        return in;\n\t\t}\n\t\tpublic Long[] LongArr(int n) throws IOException {\n\t        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t        return in;\n\t\t}\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n \n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n \n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n \n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n \n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n \n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n \n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\t}\n\tstatic void shuffle(int[]in) {\n\t\tfor(int i=0;i<in.length;i++) {\n\t\t\tint idx=(int)(Math.random()*in.length);\n\t\t\tint tmp=in[i];\n\t\t\tin[i]=in[idx];\n\t\t\tin[idx]=tmp;\n\t\t}\n\t}\n\tstatic void shuffle(long[]in) {\n\t\tfor(int i=0;i<in.length;i++) {\n\t\t\tint idx=(int)(Math.random()*in.length);\n\t\t\tlong tmp=in[i];\n\t\t\tin[i]=in[idx];\n\t\t\tin[idx]=tmp;\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class E {\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n//\t\tint tests = 40;\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tint n = scanInt(), m = scanInt(), a[][] = new int[n][m];\n//\t\t\tint n = 12, m = 2000, a[][] = 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\ta[i][j] = scanInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\tint bestCols[] = new int[min(m, n)];\n\t\t\tfor (int i = 0; i < bestCols.length; i++) {\n\t\t\t\tbestCols[i] = i;\n\t\t\t}\n\t\t\tif (m > n) {\n\t\t\t\tint bestColMax[] = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint cmax = 0;\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tcmax = max(cmax, a[j][i]);\n\t\t\t\t\t}\n\t\t\t\t\tbestColMax[i] = cmax;\n\t\t\t\t}\n\t\t\t\tfor (int i = n; i < m; i++) {\n\t\t\t\t\tint cmax = 0;\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tcmax = max(cmax, a[j][i]);\n\t\t\t\t\t}\n\t\t\t\t\tint minBC = 0, minBCM = Integer.MAX_VALUE;\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tif (bestColMax[j] < minBCM) {\n\t\t\t\t\t\t\tminBC = j;\n\t\t\t\t\t\t\tminBCM = bestColMax[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cmax > minBCM) {\n\t\t\t\t\t\tbestCols[minBC] = i;\n\t\t\t\t\t\tbestColMax[minBC] = cmax;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint dyn[] = new int[1 << n], dynNext[] = new int[1 << n], sums[] = new int[1 << n], csums[] = new int[1 << n];\n\t\t\tfor (int i: bestCols) {\n\t\t\t\tfill(dynNext, 0);\n\t\t\t\tfill(sums, 0);\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tfor (int k = 1, bit = 0; k < 1 << n; k++) {\n\t\t\t\t\t\tif (k == 1 << (bit + 1)) {\n\t\t\t\t\t\t\t++bit;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsums[k] = max(sums[k], csums[k] = csums[k ^ (1 << bit)] + a[(bit + j) % n][i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int mask1 = 0; mask1 < 1 << n; mask1++) {\n\t\t\t\t\tint cdyn = dynNext[mask1];\n\t\t\t\t\tfor (int mask2 = mask1;; mask2 = (mask2 - 1) & mask1) {\n\t\t\t\t\t\tcdyn = max(cdyn, dyn[mask2] + sums[mask1 ^ mask2]);\n\t\t\t\t\t\tif (mask2 == 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdynNext[mask1] = cdyn;\n\t\t\t\t}\n\t\t\t\tint t[] = dyn;\n\t\t\t\tdyn = dynNext;\n\t\t\t\tdynNext = t;\n\t\t\t}\n\t\t\tout.println(dyn[(1 << n) - 1]);\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}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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        TaskE1 solver = new TaskE1();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE1 {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int numTests = in.nextInt();\n            for (int test = 0; test < numTests; test++) {\n                int n = in.nextInt();\n                int 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                    }\n                }\n                int[] d = new int[1 << n];\n                int[] nd = new int[1 << n];\n                for (int j = 0; j < m; j++) {\n                    System.arraycopy(d, 0, nd, 0, d.length);\n                    for (int mask = 0; mask < 1 << n; mask++) {\n                        for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {\n                            for (int shift = 0; shift < n; shift++) {\n                                int sum = 0;\n                                for (int i = 0; i < n; i++) {\n                                    if ((submask & (1 << i)) > 0) {\n                                        sum += a[(i + shift) % n][j];\n                                    }\n                                }\n                                nd[mask] = Math.max(nd[mask], d[mask ^ submask] + sum);\n                            }\n                        }\n                    }\n                    int[] t = d;\n                    d = nd;\n                    nd = t;\n                }\n                int ans = 0;\n                for (int x : d) {\n                    ans = Math.max(ans, x);\n                }\n                out.println(ans);\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", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n    static ArrayList<Integer> cols;\n    static int ans, n, a[][];\n\n    public static void main(String[] args) throws Exception {\n        Scanner sc = new Scanner(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        int tc = sc.nextInt();\n        while (tc-- > 0) {\n            ans = 0;\n            n = sc.nextInt();\n            int m = sc.nextInt();\n            boolean[] taken = new boolean[m];\n            PriorityQueue<Pair> pq = new PriorityQueue<>();\n            a = new int[n][m];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++) {\n                    int cur = sc.nextInt();\n                    pq.add(new Pair(i, j, cur));\n                    a[i][j] = cur;\n                }\n            cols = new ArrayList<>();\n            while (!pq.isEmpty() && cols.size() < 8) {\n                Pair cur = pq.remove();\n                if (!taken[cur.j]) cols.add(cur.j);\n                taken[cur.j] = true;\n            }\n            solve(0,new int [cols.size()]);\n            out.println(ans);\n        }\n        out.flush();\n        out.close();\n    }\n\n    static void solve(int i, int[] p) {\n        if (i == cols.size()) {\n            int[] max = new int[n];\n            for (int k = 0; k < cols.size(); k++) {\n                int j = cols.get(k);\n                for (int ii = 0; ii < n; ii++) {\n                    int idx = (ii + p[k]) % n;\n                    max[idx] = Math.max(max[idx], a[ii][j]);\n                }\n            }\n            int poss = 0;\n            for (int x : max)\n                poss += x;\n            ans = Math.max(ans, poss);\n            return;\n        }\n        for (int j = 0; j < n; j++) {\n            p[i] = j;\n            solve(i + 1, p);\n        }\n    }\n\n\n    static class Pair implements Comparable<Pair> {\n        int i, j, val;\n\n        public Pair(int i, int j, int val) {\n            this.i = i;\n            this.j = j;\n            this.val = val;\n        }\n\n        @Override\n        public int compareTo(Pair o) {\n            return o.val - val;\n        }\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        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()) 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        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 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}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "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(), m = ni();\n        long[][] a = new long[n][m];\n        long[] col = new long[m];\n        for(int i = 0; i< n; i++){\n            for(int j = 0; j< m; j++){\n                a[i][j] = nl();\n                col[j] = Math.max(a[i][j], col[j]);\n            }\n        }\n        Integer[] p = new Integer[m];\n        for(int i = 0; i< m; i++)p[i] = i;\n        Arrays.sort(p, (Integer i1, Integer i2) -> Long.compare(col[i2], col[i1]));\n        long[][] mat = new long[n][Math.min(m, 6)];\n        for(int i = 0; i< Math.min(m, 6); i++){\n            for(int j = 0; j< n; j++)mat[j][i] = a[j][p[i]];\n        }\n        long pow = 1;\n        for(int i = 0; i< Math.min(m, 6); i++)pow *= n;\n        int[] sh = new int[Math.min(m, 6)];\n        long ans = 0;\n        for(int i = 0; i< pow; i++){\n            int x = i;\n            for(int j = 0; j< Math.min(m, 6); j++){\n                sh[j] = x%n;\n                x/=n;\n            }\n            long cur = 0;\n            for(int ro = 0; ro < n; ro++){\n                long cR = 0;\n                for(int j = 0; j < Math.min(m, 6); j++)cR = Math.max(cR, mat[(ro+sh[j])%n][j]);\n                cur += cR;\n            }\n            ans = Math.max(ans, cur);\n        }\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    long IINF = (long)1e18, mod = (long)1e9+7;\n    final int INF = (int)1e9, MX = (int)2e6+5;\n    DecimalFormat df = new DecimalFormat(\"0.00000000\");\n    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;\n    static boolean multipleTC = true, memory = false, fileIO = false;\n    FastReader in;PrintWriter out;\n    void run() throws Exception{\n        if(fileIO){\n            in = new FastReader(\"input.txt\");\n            out = new PrintWriter(\"output.txt\");\n        }else {\n            in = new FastReader();\n            out = new PrintWriter(System.out);\n        }\n        //Solution Credits: Taranpreet Singh\n        int T = (multipleTC)?ni():1;\n        pre();\n        for(int t = 1; t<= T; t++)solve(t);\n        out.flush();\n        out.close();\n    }\n    public static void main(String[] args) throws Exception{\n        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n        else new Main().run();\n    }\n    \n    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}\n    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n    void p(Object o){out.print(o);}\n    void pn(Object o){out.println(o);}\n    void pni(Object o){out.println(o);out.flush();}\n    String n()throws Exception{return in.next();}\n    String nln()throws Exception{return in.nextLine();}\n    int ni()throws Exception{return Integer.parseInt(in.next());}\n    long nl()throws Exception{return Long.parseLong(in.next());}\n    double nd()throws Exception{return Double.parseDouble(in.next());}\n \n    class FastReader{\n        BufferedReader br;\n        StringTokenizer st;\n        public FastReader(){\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n \n        public FastReader(String s) throws Exception{\n            br = new BufferedReader(new FileReader(s));\n        }\n \n        String next() throws Exception{\n            while (st == null || !st.hasMoreElements()){\n                try{\n                    st = new StringTokenizer(br.readLine());\n                }catch (IOException  e){\n                    throw new Exception(e.toString());\n                }\n            }\n            return st.nextToken();\n        }\n \n        String nextLine() throws Exception{\n            String str = \"\";\n            try{   \n                str = br.readLine();\n            }catch (IOException e){\n                throw new Exception(e.toString());\n            }  \n            return str;\n        }\n    }\n}", "complexity": "np", "problem": "1209_E1. Rotate Columns (easy version)", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.OutputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Alex\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskB {\n        double special(int[] loyalties, int[] levels, int playerlevelsum) {\n            int poss = 1 << loyalties.length;\n            double res = 0;\n            for(int pos = 0; pos < poss; pos++) {\n                double occurs = 1;\n                int happy = 0;\n                int badlevelssum = 0;\n                for(int i = 0; i < loyalties.length; i++) {\n                    if(((pos >> i) & 1) == 1) { //happy senator\n                        happy++;\n                        occurs *= (double) loyalties[i] / 100;\n                    } else { //unhappy senator\n                        badlevelssum += levels[i];\n                        occurs *= (double) (100 - loyalties[i]) / 100;\n                    }\n                }\n                double winprob = (happy <= levels.length / 2) ? (double) playerlevelsum / (playerlevelsum + badlevelssum) : 1;\n                res += occurs * winprob;\n            }\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int senators = in.readInt(); // n, [1, 8]\n            int sweets = in.readInt(); // k, [1, 8]\n            int playerlevelsum = in.readInt(); // A, [1, 9999]\n            int[] levels = new int[senators]; // [1, 9999]\n            int[] loyalties = new int[senators]; // [0, 100] divisible by 10\n            IOUtils.readIntArrays(in, levels, loyalties);\n            ArrayList<ArrayList<Integer>> possibilities = new ArrayList<>(Arrays.asList(new ArrayList<>()));\n            for(int senator = 0; senator < senators; senator++) {\n                ArrayList<ArrayList<Integer>> newpossibilities = new ArrayList<>();\n                for(ArrayList<Integer> al : possibilities) {\n                    int sumsofar = 0;\n                    for(int val : al) sumsofar += val;\n                    int minadd = senator == senators - 1 ? sweets - sumsofar : 0;\n                    for(int moar = minadd; moar <= sweets - sumsofar; moar++) {\n                        ArrayList<Integer> copy = new ArrayList<>(al);\n                        copy.add(moar);\n                        newpossibilities.add(copy);\n                    }\n                }\n                possibilities = newpossibilities;\n            }\n            double res = 0;\n            for(ArrayList<Integer> al : possibilities) {\n                int[] newloyalties = new int[senators];\n                for(int i = 0; i < senators; i++) newloyalties[i] = Math.min(100, loyalties[i] + 10 * al.get(i));\n                double special = special(newloyalties, levels, playerlevelsum);\n                double tot = special;\n                res = Math.max(res, tot);\n            }\n            out.printLine(res);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if(numChars == -1)\n                throw new InputMismatchException();\n            if(curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch(IOException e) {\n                    throw new InputMismatchException();\n                }\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public 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    }\n\n    static class IOUtils {\n        public static void readIntArrays(InputReader in, int[]... arrays) {\n            for(int i = 0; i < arrays[0].length; i++) {\n                for(int j = 0; j < arrays.length; j++)\n                    arrays[j][i] = in.readInt();\n            }\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tint n, k;\n\tdouble A;\n\tint[] b, l;\n\tdouble ans;\n\tdouble curAns;\n\t\n\tvoid check(boolean[] used) {\n\t\tint cnt = 0;\n\t\tfor (boolean t : used)\n\t\t\tif (t)\n\t\t\t\tcnt++;\n\t\tdouble prob = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (used[i])\n\t\t\t\tprob *= ((double) l[i]) / ((double) 100);\n\t\t\telse\n\t\t\t\tprob *= 1 - ((double) l[i]) / ((double) 100);\n\t\t}\n\t\tif (2 * cnt > n) {\n\t\t\tcurAns += prob;\n\t\t} else {\n\t\t\tint level = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (!used[i])\n\t\t\t\t\tlevel += b[i];\n\t\t\tcurAns += prob * ( A / ((double) A + level));\n\t\t}\n\t}\n\t\n\tvoid go(int i, boolean[] used) {\n\t\tif (n == i) {\n\t\t\tcheck(used);\n\t\t\treturn;\n\t\t}\n\t\tused[i] = true;\n\t\tgo(i + 1, used);\n\t\tused[i] = false;\n\t\tgo(i + 1, used);\n\t}\n\t\n\tvoid candies(int k, int i) {\n\t\tif (i == n) {\n\t\t\tcurAns = 0;\n\t\t\tgo(0, new boolean[n]);\n\t\t\tif (curAns > ans)\n\t\t\t\tans = curAns;\n\t\t\treturn;\n\t\t}\n\t\tcandies(k, i + 1);\n\t\tfor (int j = 1; j <= k && l[i] + 10 * j <= 100; j++) {\n\t\t\tl[i] += 10 * j;\n\t\t\tcandies(k - j, i + 1);\n\t\t\tl[i] -= 10 * j;\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tn = nextInt();\n\t\tk = nextInt();\n\t\tA = nextInt();\n\t\tb = new int[n];\n\t\tl = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t\tl[i] = nextInt();\t\t\n\t\t}\n\t\tans = 0;\n\t\tcandies(k, 0);\n\t\tout.printf(\"%.12f\", ans);\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//\t\t\tin = new BufferedReader(new FileReader(filename + \".in\"));\n\t\t\t//\t\t\tout = new PrintWriter(filename + \".out\");\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter out;\n\tfinal String filename = new String(\"B\").toLowerCase();\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 B().run();\n\t}\n\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.*;\n\npublic class B {\n\n    static int[] loyality;\n    static int[] level;\n    static int mid;\n    static int a, n;\n    static double sol;\n\n    public static void getMax(int idx, int rem) {\n        if (idx == loyality.length) {\n            double pos = 0;\n            for (int i = 0; i < (1 << n); i++)\n                pos += solve(i);\n            sol = Math.max(sol, pos);\n            return;\n        }\n        int cur = loyality[idx];\n        int r = 0;\n        while (r + cur <= 10 && r <= rem) {\n            loyality[idx] = cur + r;\n            getMax(idx + 1, rem - r);\n            r++;\n        }\n        loyality[idx] = cur;\n    }\n\n    public static double solve(int mask) {\n        int c = 0;\n        int sum = 0;\n        double b = 1;\n        for (int i = 0; i < n; i++) {\n            if (((1 << i) | mask) == mask) {\n                c++;\n                b *= (loyality[i] / 10.0);\n            } else {\n                sum += level[i];\n                b *= (1 - (loyality[i] / 10.0));\n            }\n        }\n        if (c >= mid)\n            return b;\n        return b * (a * 1.0) / (a + sum);\n    }\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        n = sc.nextInt();\n        int k = sc.nextInt();\n        a = sc.nextInt();\n        level = new int[n];\n        loyality = new int[n];\n        for (int i = 0; i < n; i++) {\n            level[i] = sc.nextInt();\n            loyality[i] = sc.nextInt() / 10;\n        }\n        mid = (n/2) +1;\n        sol = 0;\n        getMax(0, k);\n        System.out.println(sol);\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/13/11\n * Time: 6:10 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.IOException;\n\npublic class DarkAssembly extends Thread {\n\n    public DarkAssembly() {\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    static class Senator {\n        int loyalty;\n        int level;\n\n        public Senator(int level, int loyalty) {\n            this.level = level;\n            this.loyalty = loyalty;\n        }\n    }\n\n    private static double doIt(Senator[] senators, int A) {\n        double probability = .0;\n        for (int mask = 0; mask < (1 << senators.length); ++mask) {\n            int sum = A;\n            double current = 1.0;\n            for (int i = 0; i < senators.length; ++i) {\n                if ((mask & (1 << i)) != 0) {\n                    current *= .01 * senators[i].loyalty;\n                } else {\n                    current *= .01 * (100 - senators[i].loyalty);\n                    sum += senators[i].level;\n                }\n            }\n            if (getOnes(mask) > senators.length / 2) {\n                probability += current;\n            } else {\n                probability += current * (double)A / sum;\n            }\n        }\n        return probability;\n    }\n\n    private static double go(Senator []senators, int candies, int A, int current) {\n        if (current == senators.length) {\n            return doIt(senators, A);\n        } else {\n            double result = go(senators, candies, A, current + 1);\n            if (candies > 0 && senators[current].loyalty < 100) {\n                senators[current].loyalty += 10;\n                result = Math.max(result, go(senators, candies - 1, A, current));\n                senators[current].loyalty -= 10;\n            }\n            return result;\n        }        \n    }\n\n\n\n    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    public void run() {\n        try {\n            int n = nextInt();\n            int k = nextInt();\n            int A = nextInt();\n            Senator[] senators = new Senator[n];\n            for (int i = 0; i < n; ++i) {\n                senators[i] = new Senator(nextInt(), nextInt());\n            }\n            output.printf(\"%.10f\", go(senators, k, A, 0));\n\n            output.flush();\n            output.close();\n\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            System.err.println(Arrays.deepToString(e.getStackTrace()));\n        }\n    }\n\n\n    public static void main(String[] args) {\n        new DarkAssembly().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\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "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(), k = iread(), A = iread();\n\t\tint[] b = new int[n], l = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tl[i] = iread();\n\t\t\tb[i] = iread();\n\t\t}\n\n\t\tint[] c = new int[n];\n\t\tdouble ans = 0.0;\n\t\tfor (int mask = 0; mask < 1 << (k + n - 1); mask++) {\n\t\t\tint t = 0;\n\t\t\tfor (int i = 0; i < n + k - 1; i++) {\n\t\t\t\tif ((mask & (1 << i)) != 0)\n\t\t\t\t\tt++;\n\t\t\t}\n\t\t\tif (t != k)\n\t\t\t\tcontinue;\n\n\t\t\tint x = mask;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tc[i] = b[i];\n\t\t\t\twhile (x % 2 == 1) {\n\t\t\t\t\tc[i] += 10;\n\t\t\t\t\tx /= 2;\n\t\t\t\t}\n\t\t\t\tif (c[i] > 100)\n\t\t\t\t\tc[i] = 100;\n\t\t\t\tx /= 2;\n\t\t\t}\n\t\t\tdouble res = 0.0;\n\t\t\tfor (int mask2 = 0; mask2 < 1 << n; mask2++) {\n\t\t\t\tint m = 0;\n\t\t\t\tdouble p = 1.0;\n\t\t\t\tt = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif ((mask2 & (1 << i)) == 0) {\n\t\t\t\t\t\tt += l[i];\n\t\t\t\t\t\tp *= (100.0 - c[i]) / 100.0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tp *= c[i] / 100.0;\n\t\t\t\t\t\tm++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (m * 2 > n)\n\t\t\t\t\tres += p;\n\t\t\t\telse\n\t\t\t\t\tres += p * A * 1.0 / (A + t);\n\t\t\t}\n\t\t\tans = Math.max(ans, res);\n\t\t}\n\t\tDecimalFormat df = new DecimalFormat(\"0.0000000\");\n\t\tout.write(df.format(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}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.*;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class flags1225 implements Runnable {\n\tstatic int n, k, a, b[], loy[];\n\tstatic boolean decision[];\n\tstatic double ans, max;\n\n\tstatic void check(int i) {\n\t\tif (i == n) {\n\t\t\tcheckAgain();\n\t\t\treturn;\n\t\t}\n\t\tdecision[i] = true;\n\t\tcheck(i + 1);\n\t\tif (loy[i] < 100) {\n\t\t\tdecision[i] = false;\n\t\t\tcheck(i + 1);\n\t\t}\n\t}\n\n\tstatic void checkAgain() {\n\t\tdouble prob = 1;\n\t\tint enemyEnergy = 0;\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (decision[i]) {\n\t\t\t\tcount++;\n\t\t\t\tprob *= loy[i];\n\t\t\t} else {\n\t\t\t\tprob = prob * (100 - loy[i]);\n\t\t\t\tenemyEnergy += b[i];\n\t\t\t}\n\t\t}\n\t\tdouble killProb = (double) (a) / (a + enemyEnergy);\n\t\tif (count > n / 2) {\n\t\t\tans += prob;\n\t\t\treturn;\n\t\t}\n\t\tprob *= killProb;\n\t\tans += prob;\n\t}\n\n\tstatic void rec(int sum, int i) {\n\t\tif (i == n || sum == 0) {\n\t\t\tans = 0;\n\t\t\tcheck(0);\n\t\t\tmax = max(ans, max);\n\t\t\treturn;\n\t\t}\n\t\tfor (int j = 0; j <= sum; j = j + 10) {\n\t\t\tif (loy[i] + j > 100)\n\t\t\t\tcontinue;\n\t\t\tloy[i] += j;\n\t\t\trec(sum - j, i + 1);\n\t\t\tloy[i] -= j;\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\tn = nextInt();\n\t\tk = nextInt() * 10;\n\t\ta = nextInt();\n\t\tmax = 0;\n\t\tb = new int[n];\n\t\tloy = new int[n];\n\t\tdecision = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t\tloy[i] = nextInt();\n\t\t}\n\t\t// System.out.println(Arrays.toString(loy));\n\t\trec(k, 0);\n\t\tlong pow = (long) pow(100, n);\n\t\tout.print((double) max / pow);\n\n\t\t// --------------------------------------------------------------------------------------------\n\t\tout.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static boolean fileIOMode = false;\n\tprivate static String problemName = \"harmful\";\n\tprivate static BufferedReader in;\n\tprivate static PrintWriter out;\n\tprivate static StringTokenizer tokenizer;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tLocale.setDefault(Locale.ENGLISH);\n\t\tif (fileIOMode) {\n\t\t\tin = new BufferedReader(new FileReader(problemName + \".in\"));\n\t\t\tout = new PrintWriter(problemName + \".out\");\n\t\t} else {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t}\n\t\ttokenizer = new StringTokenizer(\"\");\n\n\t\tnew Thread(new flags1225()).start();\n\t}\n\n\tprivate static String nextLine() {\n\t\ttry {\n\t\t\treturn in.readLine();\n\t\t} catch (IOException e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate static String nextToken() {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tprivate static double nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "//package round81;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint k = ni();\n\t\tint a = ni();\n\t\tint[] lv = new int[n];\n\t\tint[] lo = new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tlv[i] = ni();\n\t\t\tlo[i] = ni();\n\t\t}\n\t\t\n\t\tout.printf(\"%.9f\", rec(lv, lo, n, 0, k, a));\n\t}\n\t\n\tdouble rec(int[] lv, int[] lo, int n, int pos, int k, int a)\n\t{\n\t\tif(pos == n){\n\t\t\tint h = n/2+1;\n\t\t\tdouble gp = 0;\n\t\t\tfor(int i = 0;i < 1<<n;i++){\n\t\t\t\tif(Integer.bitCount(i) >= h){\n\t\t\t\t\tdouble p = 1.0;\n\t\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\t\tif(i<<31-j<0){\n\t\t\t\t\t\t\tp *= (double)lo[j] / 100;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tp *= (double)(100-lo[j]) / 100;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tgp += p;\n\t\t\t\t}else{\n\t\t\t\t\tdouble p = 1.0;\n\t\t\t\t\tint sl = 0;\n\t\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\t\tif(i<<31-j<0){\n\t\t\t\t\t\t\tp *= (double)lo[j] / 100;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tp *= (double)(100-lo[j]) / 100;\n\t\t\t\t\t\t\tsl += lv[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tgp += p * a/(a+sl);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn gp;\n\t\t}else{\n\t\t\tint o = lo[pos];\n\t\t\tdouble max = 0;\n\t\t\tfor(int i = 0;i <= k && lo[pos] <= 100;i++){\n\t\t\t\tmax = Math.max(max, rec(lv, lo, n, pos+1, k-i, a));\n\t\t\t\tlo[pos]+=10;\n\t\t\t}\n\t\t\tlo[pos] = o;\n\t\t\treturn max;\n\t\t}\n\t}\n\t\n\t\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = oj ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew B().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", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.reflect.Array;\nimport java.math.*;\n\npublic class Solution {\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\tprivate Random rnd;\n\t\n\tint[] levels;\n\tint[] loyal;\n\tint n, k;\n\tdouble A;\n\t\n\tint[] choices;\n\tint[] new_loyal;\n\tdouble[] koef;\n\t\n\tdouble ans = 0.0;\n\tint total;\n\t\n\tvoid rec(int step, int start) {\n\t\tif(step == k) {\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tnew_loyal[i] = loyal[i];\n\t\t\t}\n\t\t\tfor(int i = 0; i < k; i++) {\n\t\t\t\tnew_loyal[choices[i]] = Math.min(100, new_loyal[choices[i]] + 10);\n\t\t\t}\n\t\t\t\n\t\t\tint full = 0;\n\t\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tif(new_loyal[i] == 100) {\n\t\t\t\t\t++full;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(full > (n / 2)) {\n\t\t\t\tans = 1.0;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tkoef[i] = (double) new_loyal[i] / 100.0;\n\t\t\t}\n\t\t\t\n\n\t\t\tint bits_needed = (n / 2) + 1;\n\t\t\t\n\t\t\tdouble total_win = 0.0;\n\t\t\tdouble total_fights = 0.0;\n\t\t\t\n\t\t\tfor(int mask = 0; mask < total; mask++) {\n\t\t\t\tint bits = 0;\n\t\t\t\t\n\t\t\t\tdouble win = 1.0;\n\t\t\t\tdouble loose = 1.0;\n\t\t\t\tdouble b = 0.0;\n\t\t\t\t\n\t\t\t\tfor(int bit = 0; bit < n; bit++) {\n\t\t\t\t\tif((mask & (1 << bit)) != 0) {\n\t\t\t\t\t\t++bits;\n\t\t\t\t\t\twin *= koef[bit];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tloose *= (1.0 - koef[bit]);\n\t\t\t\t\t\tb += levels[bit];\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\tdouble prob = win * loose;\n\t\t\t\t\n\t\t\t\tif(bits >= bits_needed) {\n\t\t\t\t\ttotal_win += prob;\n\t\t\t\t} else {\n\t\t\t\t\ttotal_fights += prob * (A / (A + b));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t\n\t\t\tans = Math.max(ans, total_win + total_fights);\n\n\t\t} else {\n\t\t\tfor(int i = start; i < n; i++) {\n\t\t\t\tchoices[step] = i;\n\t\t\t\trec(step + 1, i);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tn = nextInt();\n\t\tk = nextInt();\n\t\tA = nextInt();\n\t\t\n\t\tlevels = new int[n];\n\t\tloyal = new int[n];\n\t\tnew_loyal = new int[n];\n\t\tchoices = new int[k];\n\t\tkoef = new double[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tlevels[i] = nextInt();\n\t\t\tloyal[i] = nextInt();\n\t\t}\n\t\t\n\t\ttotal = 1 << n;\n\t\t\n\t\trec(0, 0);\n\t\t\n\t\tout.println(ans);\n\t}\n\t\t\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\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\tst = null;\n\t\t\trnd = new Random();\n\t\t\t\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t} catch(IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t\n\tprivate String nextToken() throws IOException, NullPointerException {\n\t\twhile(st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\n\t\treturn st.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class D {\n    static int n, KA, A;\n    static int[] b;\n    static int[] l;\n    static double ans = 0;\n\n    public static void main(String[] args) throws IOException {\n        Scanner in = new Scanner(System.in);\n        n = in.nextInt();\n        KA = in.nextInt();\n        A = in.nextInt();\n        b = new int[n];\n        l = new int[n];\n\n        for (int i = 0; i < l.length; i++) {\n            b[i] = in.nextInt();\n            l[i] = in.nextInt();\n        }\n        dp = new double[n + 2][n + 2][n * 9999 + 2];\n        go(0, KA);\n        System.out.printf(\"%.6f\\n\", ans);\n    }\n\n    public static void go(int at, int k) {\n        if (at == n) {\n            ans = Math.max(ans, solve(0, 0, 0));\n            return;\n        }\n        for (int i = 0; i <= k; i++) {\n            if (l[at] + i * 10 <= 100) {\n                l[at] += i * 10;\n                go(at + 1, k - i);\n                l[at] -= i * 10;\n            }\n        }\n    }\n\n    static double dp[][][];\n\n    public static double solve(int at, int ok, int B) {\n        if (at == n) {\n            if (ok > n / 2) {\n                return 1;\n            } else {\n                return (A * 1.0) / (A * 1.0 + B);\n            }\n        }\n        double ret = ((l[at]) / 100.0) * solve(at + 1, ok + 1, B)\n                + (1.0 - ((l[at]) / 100.0)) * solve(at + 1, ok, B + b[at]);\n        return ret;\n    }\n\n    // 3 0 31\n    // 10 60\n    // 12 60\n    // 15 0\n    static class InputReader {\n        BufferedReader in;\n        StringTokenizer st;\n\n        public InputReader() throws IOException {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            st = new StringTokenizer(in.readLine());\n        }\n\n        public String next() throws IOException {\n            while (!st.hasMoreElements())\n                st = new StringTokenizer(in.readLine());\n            return st.nextToken();\n        }\n\n        public int nextInt() throws NumberFormatException, IOException {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() throws NumberFormatException, IOException {\n            return Long.parseLong(next());\n        }\n    }\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "/**\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 */\n\n\npublic class TaskB {\n\n    int[] levels;\n    int[] loyalty;\n\n    int n, k, A;\n    double ans = Double.NEGATIVE_INFINITY;\n\n    void rec(int ix, int sweets, int[] loyalty) {\n        if (ix == n) {\n\n            double nres = 0.0;\n            for(int mask = 0; mask < (1<<n); mask++) {\n\n                double res = 1.0, totalStrength = 0;\n                for (int i = 0; i < n; i++) {\n                    if ((mask & (1 << i)) > 0) {\n                        res *= loyalty[i] / 100.0;\n                    } else {\n                        res *= 1.0 - (loyalty[i]/ 100.0);\n                        totalStrength += levels[i];\n                    }\n                }\n\n                int bitCount = Integer.bitCount(mask);\n                if(bitCount > n / 2) {\n                    nres += res;\n                }\n                else {\n                    nres += res * (A) / (A + totalStrength);\n                }\n\n            }\n            ans = Math.max(ans, nres);\n            return;\n        }\n\n        for (int j = 0; j <= sweets; j++) {\n            if (loyalty[ix] + 10 * j > 100) break;\n            int[] nloyalty = loyalty.clone();\n            nloyalty[ix] += 10 * j;\n            rec(ix + 1, sweets - j, nloyalty);\n        }\n    }\n\n    void run() {\n        n = nextInt();\n        k = nextInt();\n        A = nextInt();\n        levels = new int[n];\n        loyalty = new int[n];\n        for (int i = 0; i < n; i++) {\n            levels[i] = nextInt();\n            loyalty[i] = nextInt();\n        }\n\n        rec(0, k, loyalty);\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 TaskB().run();\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/13/11\n * Time: 6:10 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.IOException;\n\npublic class DarkAssembly extends Thread {\n\n    public DarkAssembly() {\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    class Senator {\n        int loyalty;\n        int level;\n\n        public Senator(int level, int loyalty) {\n            this.level = level;\n            this.loyalty = loyalty;\n        }\n    }\n\n    private static double doIt(Senator[] senators, int A) {\n        double probability = .0;\n        for (int mask = 0; mask < (1 << senators.length); ++mask) {\n            int sum = A;\n            double current = 1.0;\n            for (int i = 0; i < senators.length; ++i) {\n                if ((mask & (1 << i)) != 0) {\n                    current *= .01 * senators[i].loyalty;\n                } else {\n                    current *= .01 * (100 - senators[i].loyalty);\n                    sum += senators[i].level;\n                }\n            }\n            if (getOnes(mask) > senators.length / 2) {\n                probability += current;\n            } else {\n                probability += current * (double)A / sum;\n            }\n        }\n        return probability;\n    }\n\n    private static double go(Senator []senators, int candies, int A, int current) {\n        if (current == senators.length) {\n            return doIt(senators, A);\n        } else {\n            double result = go(senators, candies, A, current + 1);\n            if (candies > 0 && senators[current].loyalty < 100) {\n                senators[current].loyalty += 10;\n                result = Math.max(result, go(senators, candies - 1, A, current));\n                senators[current].loyalty -= 10;\n            }\n           \n            return result;\n        }\n    }\n\n\n\n    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    public void run() {\n        try {\n            int n = nextInt();\n            int k = nextInt();\n            int A = nextInt();\n            Senator[] senators = new Senator[n];\n            for (int i = 0; i < n; ++i) {\n                senators[i] = new Senator(nextInt(), nextInt());\n            }\n            output.printf(\"%.10f\", go(senators, k, A, 0));\n\n            output.flush();\n            output.close();\n\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            System.err.println(Arrays.deepToString(e.getStackTrace()));\n        }\n    }\n\n\n    public static void main(String[] args) {\n        new DarkAssembly().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\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class B\n{\n   public static void main(String[] args)\n   {\n      new B(new FastScanner());\n   }\n\n   int hash(int i, int[] cc)\n   {\n      int res = i;\n      for (int ii : cc)\n      {\n         res *= 8;\n         res += ii;\n      }\n\n      return res;\n   }\n\n   int N, K, A;\n   int[] lvl;\n   int[] vs; // loyalty\n\n   \n   double calc(int i, int[] cc)\n   {\n      // Find the probability of winning\n      double res = 0;\n\n      int cnt = 0;\n      for (int m=0; m<1<<N; m++)\n      {\n         double pt = 1.0;\n         boolean passed = true;\n         int nG = 0;\n            \n         int lvlcnt = 0;\n         for (int j=0; j<N; j++)\n         {\n            int p = 10*cc[j]+vs[j];\n            int u = m&(1<<j);\n\n            boolean votesGood = (u > 0);\n            if (votesGood)\n               nG++;\n            else\n               lvlcnt += lvl[j];\n               \n            if ((p == 0)&&(votesGood))\n               passed = false;\n            if ((p == 100)&&(!votesGood))\n               passed = false;\n            if (!passed)\n               break;\n\n            if (votesGood)\n               pt *= (p/100.0);\n            else\n               pt *= ((100-p)/100.0);\n         }\n\n         if (passed == false)\n            continue;\n         \n         if (2*nG <= N)\n         {\n            // Calculate if we kill all senators\n            double p1 = A/(1.0*(A+lvlcnt));\n            \n            // Add in the probability of losing\n            res += (1-p1)*pt;\n         }\n      }\n\n      return 1.0-res;\n   }\n\n   HashMap<Integer, Double> memo;\n   double go(int i, int[] cc)\n   {\n      if (i == -1)\n         return calc(i, cc);\n\n      int hv = hash(i, cc);\n      Double rr = memo.get(hv);\n      if (rr != null)\n         return rr;\n\n      double res = go(i-1, cc);\n      for (int j=0; j<N; j++)\n      {\n         int cv = vs[j]+cc[j]*10;\n         if (cv == 100)\n            continue;\n\n         cc[j]++;\n         double rrr = go(i-1, cc);\n         cc[j]--;\n         \n         if (rrr > res)\n            res = rrr;\n      }\n      \n      memo.put(hv, res);\n      return res;\n   }\n\n   public B(FastScanner in)\n   {\n      N = in.nextInt();\n      K = in.nextInt();\n      A = in.nextInt();\n      memo = new HashMap<Integer, Double>();\n\n      lvl = new int[N];\n      vs = new int[N];\n      for (int i=0; i<N; i++)\n      {\n         lvl[i] = in.nextInt();\n         vs[i] = in.nextInt();\n      }\n\n      int[] cs = new int[8];\n      double res = go(K-1, cs);\n      System.out.printf(\"%.10f%n\", res);\n   }\n}\n\n\nclass FastScanner{\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", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\tstatic double max;\n\tstatic int n, A, b[], l[];\n\tstatic int sw[];\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tA = sc.nextInt();\n\t\tb = new int[n];\n\t\tl = new int[n];\n\t\tsw = new int[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tb[i] = sc.nextInt();\n\t\t\tl[i] = sc.nextInt();\n\t\t}\n\t\tmax = 0;\n\t\tsearch(k, 0);\n\t\tSystem.out.println(max);\n\t}\n\n\tstatic void search(int k, int m) {\n\t\tif(max == 1) return;\n\t\tif(m == n) {\n\t\t\tif(k > 0) return;\n\t\t\tdouble pr[] = new double[n];\n\t\t\tfor(int i=0; i<n; i++) {\n\t\t\t\tpr[i] = Math.min(100, l[i] + 10*sw[i])*1./100;\n\t\t\t}\n\t\t\tdouble ex = 0;\n\t\t\tfor(int i=0; i<1<<n; i++) {\n\t\t\t\tdouble p = 1;\n\t\t\t\tint cnt = 0;\n\t\t\t\tint lv = 0;\n\t\t\t\tfor(int j=0; j<n; j++) {\n\t\t\t\t\tif((i&(1<<j))>0) {\n\t\t\t\t\t\tp *= pr[j];\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tp *= (1-pr[j]);\n\t\t\t\t\t\tlv += b[j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(cnt > n/2) {\n\t\t\t\t\tex += p;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tex += p*A/(A+lv);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = Math.max(max, ex);\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=k; i>=0; i--) {\n\t\t\tsw[m] = i;\n\t\t\tsearch(k-i, m+1);\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\teat(\"\");\n\t\t}\n\n\t\tvoid eat(String s) {\n\t\t\tst = new StringTokenizer(s);\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\tthrow new IOError(e);\n\t\t\t}\n\t\t}\n\n\t\tboolean 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\tString next() {\n\t\t\thasNext();\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", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.regex.*;\nimport static java.lang.Math.*;\npublic class B {\n\n    public static void swap(int[] array, int a, int b) { // {{{\n        int t = array[a];\n        array[a] = array[b];\n        array[b] = t;\n    } // }}}\n\n    int n, k, A;\n    int[] b;\n    int[] l;\n\n    double ans;\n\n    double cal() {\n        double total = 0;\n        for (int mask=0;mask<(1<<n);mask++) {\n            int bit = Integer.bitCount(mask);\n            double p = 1;\n            for (int i=0;i<n;i++) {\n                if ((mask&(1<<i))!=0)\n                    p *= l[i]/10.0;\n                else \n                    p *= 1.0-l[i]/10.0;\n            }\n\n            if (bit*2>n) \n                total += p;\n            else {\n                int B = 0;\n                for (int i=0;i<n;i++) {\n                    if ((mask&(1<<i))==0) {\n                        B += b[i];\n                    }\n                }\n                total += p*(A/(double)(A+B));\n            }\n        }\n        return total;\n    }\n\n    void rec(int d, int remain) {\n        ans = max(ans, cal());\n        if (remain==0) return;\n        for (int i=d;i<n;i++) {\n            if (l[i]==10) continue;\n            l[i]++;\n            rec(i, remain-1);\n            l[i]--;\n        }\n    }\n\n    public B() throws Exception {\n        n = in.nextInt();\n        k = in.nextInt();\n        A = in.nextInt();\n\n        b = new int[n];\n        l = new int[n];\n        for (int i=0;i<n;i++) {\n            b[i] = in.nextInt();\n            l[i] = in.nextInt()/10;\n        }\n\n        ans = 0;\n        rec(0, k);\n\n        System.out.print(ans);\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 B();\n    } // }}}\n    public static void debug(Object... arr) { // {{{\n        System.err.println(Arrays.deepToString(arr));\n    } // }}}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import static java.lang.Math.max;\nimport static java.lang.Math.min;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tprivate void solve() throws IOException {\n\t\tint senators = nextInt();\n\t\tint candies = nextInt();\n\t\tscoreA = nextInt();\n\t\tlvl = new int[senators];\n\t\tunloyal = new int[senators];\n\t\tfor (int i = 0; i < senators; i++) {\n\t\t\tlvl[i] = nextInt();\n\t\t\tunloyal[i] = 10 - nextInt() / 10;\n\t\t}\n\t\tn = senators;\n\t\tgive = new int[n];\n\t\tres = 0;\n\t\tgo(0, candies);\n\t\tout.println(res);\n\t}\n\n\tstatic double res;\n\tstatic int[] lvl;\n\tstatic int[] unloyal;\n\tstatic int[] give;\n\tstatic int n;\n\tstatic int scoreA;\n\n\tstatic double probability() {\n\t\tdouble res = 0;\n\t\tfor (int mask = 0; mask < 1 << n; mask++) {\n\t\t\tdouble p = 1;\n\t\t\tint scoreB = 0;\n\t\t\tint cntGood = Integer.bitCount(mask);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint cnt = unloyal[i] - give[i];\n\t\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\t\tscoreB += lvl[i];\n\t\t\t\t\tp *= cnt * .1;\n\t\t\t\t} else {\n\t\t\t\t\tp *= (10 - cnt) * .1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (2 * cntGood > n) {\n\t\t\t\tres += p;\n\t\t\t} else {\n\t\t\t\tres += p * scoreA / (scoreA + scoreB);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic void go(int man, int candies) {\n\t\tif (man == n) {\n\t\t\tres = max(res, probability());\n\t\t\treturn;\n\t\t}\n\t\tgive[man] = 0;\n\t\tgo(man + 1, candies);\n\t\tfor (int i = 1; i <= min(unloyal[man], candies); i++) {\n\t\t\tgive[man] = i;\n\t\t\tgo(man + 1, candies - i);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tnew B().solve();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(239);\n\t\t}\n\t}\n\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out;\n\n\tstatic String nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = br.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class b {\n\tstatic int n,k,A;\n\tstatic int[] l,p;\n\tstatic double [][][] memo;\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextInt();\n\t\tk = in.nextInt();\n\t\tA = in.nextInt();\n\t\tmemo = new double[n+1][n+1][1<<n];\n\t\tl = new int[n];\n\t\tp = new int[n];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tl[i] = in.nextInt();\n\t\t\tp[i] = in.nextInt();\n\t\t}\n\t\tSystem.out.printf(\"%.10f%n\",go(0,k));\n\t}\n\tstatic double go(int pos, int left) {\n\t\tif(pos==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\tArrays.fill(memo[i][j],-1);\n\t\t\treturn go2(0,n/2+1,0);\n\t\t}\n\t\tdouble best = go(pos+1,left);\n\t\tif(left == 0) return best;\n\t\tif(p[pos] < 100) {\n\t\t\tp[pos] += 10;\n\t\t\tbest = Math.max(best, go(pos,left-1));\n\t\t\tp[pos] -= 10;\n\t\t}\n\t\treturn best;\n\t}\n\tstatic double go2(int pos, int needed, int mask) {\n\t\tif(needed == 0) return 1.0;\n\t\tif(pos == n) {\n\t\t\tint tot = 0;\n\t\t\tfor(int i=0; i<n; i++)\n\t\t\t\tif((mask&(1<<i))!=0)\n\t\t\t\t\ttot += l[n-i-1];\n\t\t\treturn (A)/(A+tot+0.0);\n\t\t}\n\t\tif(memo[pos][needed][mask] != -1) \n\t\t\treturn memo[pos][needed][mask];\n\t\tdouble a = (p[pos]/100.)*go2(pos+1,needed-1,mask*2);\n\t\tdouble b = (1-(p[pos]/100.))*go2(pos+1,needed,mask*2+1);\n\t\treturn memo[pos][needed][mask] = a+b;\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound81_B implements Runnable {\n\n    BufferedReader in;\n    PrintWriter out;\n    StringTokenizer tok = new StringTokenizer(\"\");\n\n    public static void main(String[] args) {\n        new Thread(null, new BetaRound81_B(), \"\", 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                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            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    /** http://pastebin.com/j0xdUjDn */\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 final int MAGIC_VALUE = 50;\n\n        private static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n            if (leftIndex < rightIndex) {\n                if (rightIndex - leftIndex <= MAGIC_VALUE) {\n                    insertionSort(a, leftIndex, rightIndex);\n                } else {\n                    int middleIndex = (leftIndex + rightIndex) / 2;\n                    mergeSort(a, leftIndex, middleIndex);\n                    mergeSort(a, middleIndex + 1, rightIndex);\n                    merge(a, leftIndex, middleIndex, rightIndex);\n                }\n            }\n        }\n\n        private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {\n            int length1 = middleIndex - leftIndex + 1;\n            int length2 = rightIndex - middleIndex;\n            int[] leftArray = new int[length1];\n            int[] rightArray = new int[length2];\n            System.arraycopy(a, leftIndex, leftArray, 0, length1);\n            System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n            for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n                if (i == length1) {\n                    a[k] = rightArray[j++];\n                } else if (j == length2) {\n                    a[k] = leftArray[i++];\n                } else {\n                    a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];\n                }\n            }\n        }\n\n        private static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n            for (int i = leftIndex + 1; i <= rightIndex; i++) {\n                int current = a[i];\n                int j = i - 1;\n                while (j >= leftIndex && a[j] > current) {\n                    a[j + 1] = a[j];\n                    j--;\n                }\n                a[j + 1] = current;\n            }\n        }\n\n    }\n\n    // solution\n\n    int n, k, A;\n    int[] b, l, c;\n    \n    void solve() throws IOException {\n        n = readInt();\n        k = readInt();\n        A = readInt();\n        b = new int[n];\n        l = new int[n];\n        for (int i = 0; i < n; i++) {\n            b[i] = readInt();\n            l[i] = readInt();\n        }\n        c = new int[n];\n        rec(0, 0);\n        out.printf(\"%.12f\\n\", ans);\n    }\n    \n    double ans = 0;\n    \n    void rec(int sum, int i) {\n        if (i > n) return;\n        if (sum > k) return;\n        if (i == n) {\n            ans = max(ans, p());\n            return;\n        }\n        if (l[i] + c[i]*10 <= 100) {\n            int can = min(k - sum, (100 - (l[i] + c[i]*10)) / 10);\n            for (int set = can; set >= 0; set--) {\n                c[i] += set;\n                rec(sum + set, i + 1);\n                c[i] -= set;\n            }\n        }\n    }\n\n    double p() {\n        int n = c.length;\n        int need = n / 2 + 1;\n        int[] L = new int[n];\n        for (int i = 0; i < n; i++) {\n            L[i] = l[i] + c[i]*10;\n            if (L[i] > 100) {\n                throw new RuntimeException();\n            }\n        }\n        \n        double p = 0;\n        for (int mask = 0; mask < (1 << n); mask++) {\n            double q = 1;\n            for (int i = 0; i < n; i++) {\n                if (((1 << i) & mask) != 0) {\n                    q *= L[i] / 100.0;\n                } else {\n                    q *= 1 - (L[i] / 100.0);\n                }\n            }\n            if (q == 0) continue;\n            if (Integer.bitCount(mask) >= need) {\n                p += q;\n            } else {\n                int B = 0;\n                for (int i = 0; i < n; i++) {\n                    if (((1 << i) & mask) == 0) {\n                        B += b[i];\n                    }\n                }\n                double q2 = ((double) A) / (A + B);\n                p += q * q2;\n            }\n        }\n        return p;\n    }\n    \n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n\n    static int myLevel;\n    static int[] level;\n    static int[] loyalty;\n\n    static double get(int n) {\n        double ret = 0;\n        for (int mask = 0; mask < 1 << n; mask++) {\n            int k = Integer.bitCount(mask);\n            double prob = 1.;\n            int sum = 0;\n            for (int i = 0; i < n; i++) {\n                if (((mask >> i) & 1) == 1) {\n                    prob *= loyalty[i] * .1;\n                } else {\n                    prob *= (10 - loyalty[i]) * .1;\n                    sum += level[i];\n                }\n            }\n            if (k * 2 > n) {\n                ret += prob;\n            } else {\n                ret += prob * myLevel / (myLevel + sum);\n            }\n        }\n        return ret;\n    }\n\n    static double go(int x, int k, int n) {\n        if (x == n) {\n            return get(n);\n        }\n        double ret = 0;\n        for (int i = 0; i <= k && loyalty[x] + i <= 10; i++) {\n            loyalty[x] += i;\n            ret = Math.max(go(x + 1, k - i, n), ret);\n            loyalty[x] -= i;\n        }\n        return ret;\n    }\n\n    public void solve(int testNumber, FastScanner in, FastPrinter out) {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        myLevel = in.nextInt();\n        level = new int[n];\n        loyalty = new int[n];\n        for (int i = 0; i < n; i++) {\n            level[i] = in.nextInt();\n            loyalty[i] = in.nextInt() / 10;\n        }\n        out.println(go(0, k, 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", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "/**\n *\n * @author Saransh\n */\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n\n\npublic class Main\n{\n    static int senator_attr[][];\n    static int senators;\n    static double A;\n    public static void main(String[] args)\n    {\n        try\n        {\n            Parserdoubt pd=new Parserdoubt(System.in);\n            PrintWriter pw=new PrintWriter(System.out);\n            senators=pd.nextInt();\n            int candies=pd.nextInt();\n            senator_attr=new int[senators][2];\n            A=pd.nextInt();\n            for(int i=0;i<senators;i++)\n            {\n                senator_attr[i][0]=pd.nextInt();\n                senator_attr[i][1]=pd.nextInt();\n            }\n            max=-1;\n            make(0,candies,new int[senators]);\n            //print(maxer);\n            System.out.printf(\"%.10f\",max);\n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n        }\n    }\n    static double max;\n    static int maxer[];\n    public static void get(int a[])\n    {\n        maxer=new int[senators];\n        for(int i=0;i<maxer.length;i++)\n            maxer[i]=a[i];\n    }\n    public static void make(int pos,int left,int arr[])\n    {\n        if(pos==senators-1)\n        {\n            arr[pos]=left;\n            //print(arr);\n            double f=calc(arr);\n            if(f>max)\n            {\n                max=f;\n              get(arr);\n            }\n            \n            return;\n        }\n        if(left==0)\n        {\n            //print(arr);\n            double f=calc(arr);\n            if(f>max)\n            {\n                max=f;\n                get(arr);\n            }\n            \n            return;\n        }\n        for(int i=0;i<=left;i++)\n        {\n            arr[pos]=i;\n            make(pos+1,left-i,arr);\n            arr[pos]=0;\n        }\n    }\n    public static double calc(int arr[])\n    {\n       // print(arr);\n        int tmp[][]=new int[senators][2];\n        for(int i=0;i<senators;i++)\n        {\n            tmp[i][0]=senator_attr[i][0];\n            tmp[i][1]=Math.min(senator_attr[i][1]+arr[i]*10, 100);\n           // System.out.println(tmp[i][0]+\" \"+tmp[i][1]);\n        }\n        //print(tmp[0]);\n        return prob(tmp);\n    }\n    public static void print(int a[])\n    {\n        for(int i=0;i<a.length;i++)\n            System.out.print(a[i]+\" \");\n        System.out.println();\n\n    }\n    public static double prob(int arr[][])\n    {\n        double probability=0.0;\n        for(int i=0;i<(1<<senators);i++)\n        {\n            if(Integer.bitCount(i)>senators/2)\n            {\n                double add=1.0;\n                int tmpi=i;\n                for(int p=0;p<senators;p++)\n                {\n                    if(tmpi%2==1)\n                    {\n                        add*=arr[p][1]/100.0;\n                    }\n                    else\n                    {\n                        add*=(100-arr[p][1])/100.0;\n                    }\n                    tmpi/=2;\n                }\n                probability+=add;\n                //System.out.println(i+\" \"+add);\n            }\n            else\n            {\n                double add=1.0;\n                double B=0;\n                int tmpi=i;\n                for(int p=0;p<senators;p++)\n                {\n                    if(tmpi%2==1)\n                    {\n                        add*=arr[p][1]/100.0;\n                    }\n                    else\n                    {\n                        add*=(100-arr[p][1])/100.0;\n                        B+=arr[p][0];\n                    }\n                    tmpi/=2;\n                }\n                add*=A/(A+B);\n                probability+=add;\n                //System.out.println(i+\" \"+add);\n            }\n\n        }\n        return probability;\n    }\n}\n\nclass Skill implements Comparable<Skill>\n{\n    String name;\n    int v;\n    public Skill(String n,int val)\n    {\n        name=n;\n        v=val;\n    }\n    public int compareTo(Skill k)\n    {\n        return -k.name.compareTo(name);\n    }\n}\nclass Parserdoubt\n    {\n       final private int BUFFER_SIZE = 1 << 17;\n\n       private DataInputStream din;\n       private byte[] buffer;\n       private int bufferPointer, bytesRead;\n\n       public Parserdoubt(InputStream in)\n       {\n          din = new DataInputStream(in);\n          buffer = new byte[BUFFER_SIZE];\n          bufferPointer = bytesRead = 0;\n       }\n       public String nextString() throws Exception\n       {\n           StringBuffer sb=new StringBuffer(\"\");\n           byte c = read();\n           while (c <= ' ') c = read();\n           do\n           {\n               sb.append((char)c);\n               c=read();\n           }while(c>' ');\n           return sb.toString();\n       }\n\n       public char nextChar() throws Exception\n       {\n           byte c=read();\n           while(c<=' ') c= read();\n           return (char)c;\n       }\n       public int nextInt() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       public long nextLong() throws Exception\n       {\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          {\n              ret = ret * 10 + c - '0';\n             c = read();\n          } while (c > ' ');\n          if (neg) return -ret;\n          return ret;\n       }\n       private void fillBuffer() throws Exception\n       {\n          bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n          if (bytesRead == -1) buffer[0] = -1;\n       }\n\n       private byte read() throws Exception\n       {\n          if (bufferPointer == bytesRead) fillBuffer();\n          return buffer[bufferPointer++];\n       }\n    }", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "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 B implements Runnable\n{\n    String file = \"input\";\n    \n    boolean TEST = false;\n    double EPS = 1e-8;\n    void solve() throws IOException\n    {\n        int n = nextInt(), k = nextInt(), A = nextInt();\n        int[] level = new int[n];\n        int[] loyal = new int[n];\n        for(int i = 0; i < n; i++)\n        {\n            level[i] = nextInt();\n            loyal[i] = nextInt();\n        }\n        double res = 0;\n        for(int mask = 0; mask < 1 << (n + k - 1); mask++)\n        {\n            if(Integer.bitCount(mask) != k) continue;\n            \n            int[] L = new int[n];\n            int x = mask;\n            for(int i = 0; i < n; i++)\n            {\n                L[i] = loyal[i];\n                while(x % 2 == 1)\n                {\n                    L[i] += 10;\n                    x /= 2;\n                }\n                L[i] = min(L[i], 100);\n                x /= 2;\n            }\n            double tmp = 0;\n            for(int w = 0; w < 1 << n; w++)\n            {\n                double p = 1.;\n                double B = 0;\n                for(int i = 0; i < n; i++)\n                    if((w >> i & 1) != 0) p *= L[i] / 100.;\n                    else\n                    { \n                        p *= (100 - L[i]) / 100.;\n                        B += level[i];\n                    }\n                if(Integer.bitCount(w) * 2 > n) tmp += p;\n                else tmp += p * (A / (A + B));\n            }\n            res = max(res, tmp);\n        }\n        out.printf(\"%.8f\\n\", res);\n    }\n    \n    class Player\n    {\n        \n    }\n    \n    String next() throws IOException\n    {\n        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n        return st.nextToken();\n    }\n    \n    int nextInt() throws IOException\n    {\n        return Integer.parseInt(next());\n    }\n    \n    long nextLong() throws IOException\n    {\n        return Long.parseLong(next());\n    }\n    \n    double nextDouble() throws IOException\n    {\n        return Double.parseDouble(next());\n    }\n    \n    void print(Object... o)\n    {\n        System.out.println(deepToString(o));\n    }\n    \n    void gcj(Object o)\n    {\n        String s = String.valueOf(o);\n        out.println(\"Case #\" + test + \": \" + s);\n        System.out.println(\"Case #\" + test + \": \" + s);\n    }\n    \n    BufferedReader input;\n    PrintWriter out;\n    StringTokenizer st;\n    int test;\n    \n    void init() throws IOException\n    {\n        if(TEST) input = new BufferedReader(new FileReader(file + \".in\")); \n        else input = new BufferedReader(new InputStreamReader(System.in));\n        out = new PrintWriter(new BufferedOutputStream(System.out));\n    }\n    \n    public static void main(String[] args) throws IOException\n    {\n        new Thread(null, new B(), \"\", 1 << 20).start();\n    }\n    \n    public void run()\n    {\n        try\n        {\n            init();\n            if(TEST) \n            {\n                int runs = nextInt();\n                for(int i = 0; i < runs; i++) solve();\n            }\n            else solve();\n            out.close();        \n        }\n        catch(Exception e)\n        {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\n\n\n\n\n\npublic class B2 {\n\tString s = null;\n\n\tString[] ss = null;\n\tint[][] sn = null;\n\tint n = 0;\n\tdouble ans = 1;\n\tint A = 0;\n\tpublic void run() throws Exception{\n\n\t\tBufferedReader br = null;\n\t\tFile file = new File(\"input.txt\");\n\t\tif(file.exists()){\n\t\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t}\n\t\telse{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\n\t\ts = br.readLine();\n\t\tss = s.split(\" \");\n\t\t\n\t\t\n\t\t\n\t\tn = Integer.parseInt(ss[0]);\n\t\tint k = Integer.parseInt(ss[1]);\n\t\tA = Integer.parseInt(ss[2]);\n\t\tsn = new int[n][2];\n\n\t\tfor(int i = 0; i < n; i++){\n\t\t\ts = br.readLine();\n\t\t\tss = s.split(\" \");\n\t\t\tsn[i][0] = Integer.parseInt(ss[0]);\n\t\t\tsn[i][1] = Integer.parseInt(ss[1]);\n\t\t}\n\n\t\tint num = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tnum += (100 - sn[i][1]) / 10;\n\t\t}\n\t\tif(k >= num){\n\t\t\tSystem.out.println(\"1.0\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tcheck(0, k, sn);\n\t\t\n\t\tans = 1 - ans;\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\t\n\tvoid check(int i, int k, int[][] sn){\n\t\tif(i == n && k == 0){\n\t\t\tcheck2(sn);\n\t\t\treturn;\n\t\t}\n\t\telse if(i == n && k > 0){\n\t\t\treturn;\n\t\t}\n\t\telse if(k == 0){\n\t\t\tcheck(i+1, k, sn);\n\t\t}\n\t\telse{\n\t\t\tfor(int j = 0; j <= k; j++){\n\t\t\t\tif(sn[i][1] + j * 10 <= 100){\n\t\t\t\t\tint[][] nsn = copy(sn);\n\t\t\t\t\tnsn[i][1] += j * 10;\n\t\t\t\t\tcheck(i+1, k - j, nsn);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid check2(int[][] sn){\n\t\tList<Integer> target = new ArrayList<Integer>();\n\t\tint h = 0;\n\t\tfor(int i = 0; i < sn.length; i++){\n\t\t\tif(sn[i][1] != 100){\n\t\t\t\ttarget.add(i);\n\t\t\t}\n\t\t\telse{\n\t\t\t\th++;\n\t\t\t}\n\t\t}\n\t\tif(h  > n / 2){\n\t\t\tSystem.out.println(\"1.0\");\n\t\t\tSystem.exit(0);\t\n\t\t}\n\t\tint makemax = n - h;\n\t\tint makemin = (n+1)/2;\n\t\tdouble ma = 0;\n\t\tfor(int i = makemax; i >= makemin; i--){\n\t\t\tCombination c = new Combination(makemax, i);\n\t\t\tIterator<int[]> ite = c.iterator();\n\t\t\t\n\t\t\twhile(ite.hasNext()){\n\t\t\t\tint[] ret = ite.next();\n\t\t\t\tSet<Integer> make = new HashSet<Integer>();\n\t\t\t\tfor(int j = 0; j < ret.length; j++){\n\t\t\t\t\tif(ret[j] > 0){\n\t\t\t\t\t\tmake.add(target.get(j));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdouble makeK = 1;\n\t\t\t\tint B = 0;\n\t\t\t\tfor(int j = 0; j < n; j++){\n\t\t\t\t\tint perc = 0;\n\t\t\t\t\tif(make.contains(j)){\n\t\t\t\t\t\tperc = 100 - sn[j][1];\n\t\t\t\t\t\tB += sn[j][0];\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tperc = sn[j][1];\n\t\t\t\t\t}\n\t\t\t\t\tmakeK *= ((double)perc / 100);\n\t\t\t\t}\n\t\t\t\tma += makeK * (1 - (double)A/(A+B));\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tans = Math.min(ans, ma);\n\t}\n\t\n\tint[][] copy(int[][] sn){\n\t\tint[][] csn = new int[sn.length][2];\n\t\t\n\t\tfor(int i = 0; i < sn.length; i++){\n\t\t\tcsn[i][0] = sn[i][0];\n\t\t\tcsn[i][1] = sn[i][1];\n\t\t}\n\t\t\n\t\treturn csn;\n\t}\n\t\n\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) throws Exception{\n\t\tB2 t = new B2();\n\t\tt.run();\n\n\t}\n\n\t\n\tpublic class Combination implements Iterable<int[]> {\n\t\tprivate final int max;\n\t\tprivate final int select;\n\t\t\n\t\tpublic Combination(int max, int select) {\n\t\t\tif (max < 1 || 62 < max) {\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t}\n\t\t\tthis.max = max;\n\t\t\tthis.select = select;\n\t\t}\n\t\n\t\tpublic Iterator<int[]> iterator() {\n\t\t\treturn new CombinationIterator(max, select);\n\t\t}\n\t\t\n\t\tprivate class CombinationIterator implements Iterator<int[]> {\n\t\t\tprivate long value;\n\t\t\tprivate final long max;\n\t\t\tprivate final int size;\n\t\t\tprivate int[] ret = null;\n\t\t\tpublic CombinationIterator(int max, int select) {\n\t\t\t\tthis.value = (1L << select) - 1L;\n\t\t\t\tthis.size = max;\n\t\t\t\tthis.max = 1L << max;\n\t\t\t\tthis.ret = new int[size];\n\t\t\t}\n\n\t\n\t\t\tpublic boolean hasNext() {\n\t\t\t\treturn value < max;\n\t\t\t}\n\n\n\t\t\tpublic int[] next() {\n\t\t\t\tlong stock = value;\n\t\t\t\tvalue = next(value);\n\t\t\t\t\n\t\t\t\tfor(int i = 0; i < size; i++){\n\t\t\t\t\tlong tmp = stock >> i;\n\t\t\t\t\ttmp = tmp & 1;\n\t\t\t\t\tret[i] = (int)tmp;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\n\t\t\tpublic void remove() {\n\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t}\n\n\t\t\tprivate long next(long source) {\n\t\t\t\tlong param1 = smallestBitOf(source);\n\t\t\t\tlong param2 = param1 + source;\n\t\t\t\tlong param3 = smallestBitOf(param2);\n\t\t\t\tlong param5 = (param3 / param1) >>> 1;\n\t\t\t\treturn param5 - 1 + param2;\n\t\t\t}\n\n\t\t\tprivate long smallestBitOf(long source) {\n\t\t\t\tlong result = 1L;\n\t\t\t\twhile (source % 2 == 0) {\n\t\t\t\t\tsource >>>= 1;\n\t\t\t\t\tresult <<= 1;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.text.DecimalFormat;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n    \n    static int N;\n    static int K;\n    static int A;\n    static double dl[];\n    static int base[];\n    static int needed;\n    static int b[] = new int[N];\n    static int l[] = new int[N];\n    \n    static double best;\n    \n    static void printLevels() {\n        int i;\n        for (i=0;i<N;i++) {\n            System.out.println(i+\" \"+dl[i]);\n        }\n    }\n    \n    static void giveCandies(int i, int remaining) {\n        \n        if (remaining == 0) {\n            check();\n            return;\n        }\n        \n        if (i == N) {\n            check();\n            return;\n        }\n        \n        int j;\n        double ns;\n        double orig = dl[i];\n        \n        for (j=0;j<=remaining;j++) {\n            \n            ns = orig+j*0.1;\n            \n            if (ns <= 1.0) {\n                dl[i] = ns;\n                giveCandies(i+1, remaining-j);\n                dl[i] = orig;\n            } else {\n                break;\n            }\n            \n        }\n        \n    }\n    \n    static void check() {\n        int i,j,k;\n        \n        double res = 0.0;\n        int total;\n        double prob;\n        int max = 1<<N;\n        \n        double sumg, sumb;\n        double pk, da = (double)A;\n        \n        for (k=0;k<max;k++) {\n            \n            prob = 1.0;\n            total = 0;\n            \n            sumg = 0;\n            sumb = 0;\n            \n            for (i=0;i<N;i++) {\n                if ((base[i]&k) > 0) {\n                    prob *= dl[i];\n                    total++;\n                    sumg += b[i];\n                    \n                } else {\n                    prob *= (1.0-dl[i]);\n                    sumb += b[i];\n                    \n                }\n            }\n            \n            if (total >= needed) {\n                // needed number of senators voted positivelly\n                res += prob;\n            } else {\n                pk = da/(da+sumb);\n                \n                res += prob*pk;\n                \n            }\n            \n        }\n        \n        best = Math.max(best, res);\n        \n    }\n    \n    public static void main(String[] args) throws Exception {\n        int i,j,k;\n        \n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st = new StringTokenizer(br.readLine());\n        \n        N = Integer.parseInt(st.nextToken());\n        K = Integer.parseInt(st.nextToken());\n        A = Integer.parseInt(st.nextToken());\n        \n        needed = N/2+1;\n        \n        b = new int[N];\n        l = new int[N];\n        dl = new double[N];\n        \n        for (i=0;i<N;i++) {\n            \n            st = new StringTokenizer(br.readLine());\n            b[i] = Integer.parseInt(st.nextToken());\n            l[i] = Integer.parseInt(st.nextToken());\n            dl[i] = ((double)l[i])/100.0;\n            \n        }\n        \n        base = new int[8];\n        base[0] = 1;\n        for (i=1;i<N;i++) {\n            base[i] = base[i-1]*2;\n        }\n        \n        best = 0.0;\n        \n        giveCandies(0, K);\n        \n        DecimalFormat df = new DecimalFormat(\"0.0000000000\");\n        \n        String rs = df.format(best);\n        String mrs = \"\";\n        \n        for (i=0;i<rs.length();i++) {\n            if (rs.charAt(i) == ',') {\n                mrs += '.';\n            } else {\n                mrs += rs.charAt(i);\n            }\n        }\n        \n        System.out.println(mrs);\n        \n        \n        \n    }\n\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.awt.Point;\nimport java.util.Scanner;\n\npublic class p105b {\n    static int[] b, l;\n    static int n;\n    static int A;\n    static boolean[] masks;\n    static double max;\n\n    public static double work(int index, int k, int mask) {\n        if (index == n) {\n            if (Integer.bitCount(mask) * 2 <= n) {\n                int sum = 0;\n                for (int i = 0; i < n; i++) {\n                    if (((1 << i) & mask) == 0) {\n                        sum += b[i];\n                    }\n                }\n                return (A * 1.0) / (A * 1.0 + sum);\n            }\n            return 1;\n        }\n        double max = 0;\n        int to = Math.min(k, (100 - l[index]) / 10);\n\n        for (int i = to; i >= 0; i--) {\n            double loy = l[index] + i * 10;\n\n            double b = ((100.0 - loy) / 100.0) * work(index + 1, k - i, mask);\n\n            double a = (loy / 100.0)\n                    * work(index + 1, k - i, (mask | (1 << index)));\n\n            max = Math.max(max, a + b);\n        }\n        return max;\n    }\n\n    public static void rec(int index, int k) {\n        if (k == -1)\n            return;\n        if (index == n) {\n            double tot = 0;\n            for (int i = 0; i < 1 << n; i++) {\n                double temp = 1.0;\n                int bb = 0;\n                for (int j = 0; j < n; j++) {\n                    if(l[j]>100)\n                        return;\n                    if (((1 << j) & i) != 0) {\n                        temp *= (l[j] * 1.0 / 100.0);\n                    } else {\n                        bb += b[j];\n                        temp *= ((100.0 - l[j]) / 100.0);\n                    }\n                }\n                if (Integer.bitCount(i) * 2 <= n) {\n                    temp *= (A * 1.0) / (A * 1.0 + bb);\n                }\n                tot += temp;\n            }\n            max = Math.max(max, tot);\n            return;\n        }\n        l[index] += 10;\n        rec(index, k - 1);\n        l[index] -= 10;\n        rec(index + 1, k);\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\n        A = in.nextInt();\n\n        b = new int[n];\n        l = new int[n];\n        for (int i = 0; i < n; i++) {\n            b[i] = in.nextInt();\n            l[i] = in.nextInt();\n        }\n        masks = new boolean[1 << n];\n\n        max = 0;\n        rec(0, k);\n        System.out.println(max);\n    }\n}\n\n/*\n * 5 3 100 23 70 80 30 153 70 11 80 14 90\n */\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\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 pttrung\n */\npublic class B {\n\n    static Senator[] data;\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(new InputStreamReader(System.in));\n        PrintWriter out = new PrintWriter(System.out);\n        int n = in.nextInt();\n        int k = in.nextInt();\n        int A = in.nextInt();\n        data = new Senator[n];\n        for (int i = 0; i < n; i++) {\n            data[i] = new Senator(in.nextInt(), in.nextInt());\n        }\n        out.println(cal(0, new int[n], A, k));\n\n        out.close();\n    }\n\n    public static double cal(int index, int[] num, int A, int left) {\n        if (index == data.length - 1) {\n            int dif = (100 - data[index].loyal)/10;\n            dif = left >= dif? dif:left;\n            num[index] =  dif;\n           \n            double result = 0;\n            for (int k = 0; k < (1 << num.length); k++) {\n                double val = 1;\n                double total = 0;\n                for (int i = 0; i < num.length; i++) {\n                    if (((1 << i) & k) != 0) {\n                        val *= ((double)(data[i].loyal + 10*num[i])/100);\n                    } else {\n                        val *= ((double)(100 - (data[i].loyal + 10*num[i]))/100);\n                        total += data[i].level;\n                    }\n                }\n                if (countBit(k) > num.length / 2) {\n                    result += val;\n                } else {\n                    result += val * ((double) A / (A + total));\n                }\n            }\n//           // if(result >= 1){\n//                for(int i : num){\n//                    System.out.print(i + \" \");\n//                }\n//                System.out.println(\"\\n\" + result);\n//            //}\n            return result;\n        } else {\n            double result = 0;\n            for (int i = 0; i <= left; i++) {\n                if (i * 10 + data[index].loyal <= 100) {\n                    num[index] = i;\n                  //  double val = cal(index + 1 , num , A, left - i);\n                    \n                    result = Math.max(result, cal(index + 1, num, A, left - i));\n                } else {\n                    break;\n                }\n            }\n            return result;\n        }\n    }\n\n    public static int countBit(int val) {\n        int result = 0;\n        while (val > 0) {\n            result += val % 2;\n            val >>= 1;\n        }\n        return result;\n    }\n\n    public static class Senator {\n\n        int level, loyal;\n\n        public Senator(int level, int loyal) {\n            this.level = level;\n            this.loyal = loyal;\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 class Point {\n\n        int x, y, z;\n\n        public Point(int x, int y, int z) {\n            this.x = x;\n            this.y = y;\n            this.z = z;\n        }\n    }\n\n    public double pow(double a, int b) {\n        if (b == 0) {\n            return 1;\n        }\n        if (b == 1) {\n            return a;\n        }\n        double val = pow(a, b / 2);\n        if (b % 2 == 0) {\n            return val * val;\n        } else {\n            return val * val * a;\n        }\n    }\n\n    public static long gcd(long a, long b) {\n        if (b == 0) {\n            return a;\n        }\n        return gcd(b, a % b);\n    }\n\n    public static long lcm(long a, long b) {\n        return a * b / gcd(a, b);\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/13/11\n * Time: 6:10 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.IOException;\n\npublic class DarkAssembly extends Thread {\n\n    public DarkAssembly() {\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    class Senator {\n        int loyalty;\n        int level;\n\n        public Senator(int level, int loyalty) {\n            this.level = level;\n            this.loyalty = loyalty;\n        }\n    }\n\n    private static double doIt(Senator[] senators, int A) {\n        double probability = .0;\n        for (int mask = 0; mask < (1 << senators.length); ++mask) {\n            int sum = A;\n            double current = 1.0;\n            for (int i = 0; i < senators.length; ++i) {\n                if ((mask & (1 << i)) != 0) {\n                    current *= .01 * Math.min(senators[i].loyalty, 100);\n                } else {\n                    current *= .01 * (100 - Math.min(senators[i].loyalty, 100));\n                    sum += senators[i].level;\n                }\n            }\n            if (getOnes(mask) > senators.length / 2) {\n                probability += current;\n            } else {\n                probability += current * (double)A / sum;\n            }\n        }\n        return probability;\n    }\n\n    private static double go(Senator []senators, int candies, int A, int current) {\n        if (current == senators.length) {\n            return doIt(senators, A);\n        } else {\n            double result = Double.MIN_VALUE;\n            if (candies > 0) {\n                senators[current].loyalty += 10;\n                result = Math.max(result, go(senators, candies - 1, A, current));\n                senators[current].loyalty -= 10;\n            }\n            result = Math.max(result, go(senators, candies, A, current + 1));\n            return result;\n        }\n    }\n\n\n\n    static int getOnes(int mask) {\n        int result = 0;\n        while (mask != 0) {\n            mask &= mask - 1;\n            ++result;\n        }\n        return result;\n    }\n\n    public void run() {\n        try {\n            int n = nextInt();\n            int k = nextInt();\n            int A = nextInt();\n            Senator[] senators = new Senator[n];\n            for (int i = 0; i < n; ++i) {\n                senators[i] = new Senator(nextInt(), nextInt());\n            }\n            output.printf(\"%.10f\", go(senators, k, A, 0));\n\n            output.flush();\n            output.close();\n\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            System.err.println(Arrays.deepToString(e.getStackTrace()));\n        }\n    }\n\n\n    public static void main(String[] args) {\n        new DarkAssembly().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\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "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 int nextPerm(int[] a, int k) {\n\t\tif (a[0] == k)\n\t\t\treturn -1;\n\t\tint last = 0;\n\t\tfor (int i = a.length - 1; i >= 0; i--)\n\t\t\tif (a[i] != 0) {\n\t\t\t\tlast = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tint mem=a[last];\n\t\ta[last-1]++;\n\t\ta[last]=0;\n\t\ta[a.length-1]=mem-1;\n\t\treturn 0;\n\t}\n\t\n\tpublic double poss(int A,int[][] sen,int[] rasp){\n\t\tint n=sen.length;\n\t\tdouble[] possluck=new double[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tpossluck[i]=Math.min(100, sen[i][1]+rasp[i]*10)/100.0;\n\t\tdouble poss=0;\n\t\tfor(int i=0;i<(1<<n);i++){\n\t\t\tint kol=0;\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\tif((i%(1<<(j+1)))/(1<<(j))==1)\n\t\t\t\t\tkol++;\n\t\t\tdouble thisposs=1;\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\tif((i%(1<<(j+1)))/(1<<(j))==1)\n\t\t\t\t\tthisposs*=possluck[j];\n\t\t\t\telse\n\t\t\t\t\tthisposs*=(1-possluck[j]);\n\t\t\tif(kol>n/2)\n\t\t\t\tposs+=thisposs;\n\t\t\telse{\n\t\t\t\tdouble lvl=0;\n\t\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\t\tif((i%(1<<(j+1)))/(1<<(j))==0)\n\t\t\t\t\t\tlvl+=sen[j][0];\n\t\t\t\tposs+=thisposs*(A/(A+lvl));\n\t\t\t}\n\t\t}\n\t\treturn poss;\n\t}\n\n\tpublic void solve() throws Exception {\n\t\tint n = iread(), k = iread(), A = iread();\n\t\tint[][] sen = new int[n][2];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsen[i][0] = iread();\n\t\t\tsen[i][1] = iread();\n\t\t}\n\t\tdouble maxposs=0;\n\t\tint[] rasp=new int[n];\n\t\trasp[n-1]=k;\n\t\tmaxposs=Math.max(maxposs, poss(A,sen,rasp));\n\t\twhile(nextPerm(rasp,k)==0)\n\t\t\tmaxposs=Math.max(maxposs, poss(A,sen,rasp));\n\t\tout.write(maxposs+\"\\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}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n\n    private double[][][] dp;\n    private int n;\n    private int k;\n    private int[] loyalty;\n    private int[] level;\n    double[] P;\n    private int a;\n\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        n = in.nextInt();\n        k = in.nextInt();\n        a = in.nextInt();\n        level = new int[n];\n        loyalty = new int[n];\n        for (int i = 0; i < n; ++i) {\n            level[i] = in.nextInt();\n            loyalty[i] = in.nextInt();\n        }\n\n        P = new double[1 << n];\n        for (int mask = 0; mask < (1 << n); ++mask) {\n            if (Integer.bitCount(mask) * 2 > n) {\n                P[mask] = 1.;\n            } else {\n                double sumB = 0;\n                for (int i = 0; i < n; ++i) {\n                    if (!BitUtils.checkBit(mask, i)) {\n                        sumB += level[i];\n                    }\n                }\n                P[mask] = (double)a / (sumB + a);\n            }\n        }\n\n        dp = new double[1 << n][n + 1][k + 1];\n        ArrayUtils.fill(dp, -1);\n        newLoyalty = new int[n];\n        //double res = rec(0, 0, k, 0);\n        brute(0, k);\n        out.println(best);\n    }\n\n    int[] newLoyalty;\n    double best = 0;\n\n    void brute(int id, int leftCandies) {\n        if (id == n) {\n            double cur = calcCur();\n            if (best < cur) {\n                best = cur;\n            }\n            return;\n        }\n        for (int candies = 0; candies <= leftCandies; ++candies) {\n            newLoyalty[id] = loyalty[id] + candies * 10;\n            if (newLoyalty[id] > 100) {\n                break;\n            }\n            brute(id + 1, leftCandies - candies);\n        }\n    }\n\n    private double calcCur() {\n        double sum = 0;\n        for (int mask = 0; mask < (1 << n); ++mask) {\n            double p = getP(mask) * P[mask];\n            sum += p;\n        }\n        return sum;\n    }\n\n    private double getP(int mask) {\n        double p = 1;\n        for (int i = 0; i < n; ++i) {\n            if (BitUtils.checkBit(mask, i)) {\n                p *= (newLoyalty[i] * 1.) / 100.;\n            } else {\n                p *= (100. - newLoyalty[i]) / 100.;\n            }\n        }\n        return p;\n    }\n\n}\n\nclass InputReader {\n    private BufferedReader reader;\n    private StringTokenizer stt;\n\n    public InputReader(InputStream stream) {\n        reader = new BufferedReader(new InputStreamReader(stream));\n    }\n\n    public String nextLine() {\n        try {\n            return reader.readLine().trim();\n        } catch (IOException e) {\n            return null;\n        }\n    }\n\n    public String nextString() {\n        while (stt == null || !stt.hasMoreTokens()) {\n            stt = new StringTokenizer(nextLine());\n        }\n        return stt.nextToken();\n    }\n\n    public int nextInt() {\n        return Integer.parseInt(nextString());\n    }\n\n}\n\nclass BitUtils {\n    public static boolean checkBit(int mask, int bit) {\n        return (mask & (1 << bit)) > 0;\n    }\n\n}\n\nclass ArrayUtils {\n\n    public static void fill(double[][][] f, double value) {\n        for (int i = 0; i < f.length; ++i) {\n            for (int j = 0; j < f[i].length; ++j) {\n                Arrays.fill(f[i][j], value);\n            }\n        }\n    }\n\n}\n\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.OutputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Alex\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        OutputWriter out = new OutputWriter(outputStream);\n        TaskB solver = new TaskB();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskB {\n        double special(int[] loyalties, int[] levels, int playerlevelsum) {\n            int poss = 1 << loyalties.length;\n            double res = 0;\n            for(int pos = 0; pos < poss; pos++) {\n                double occurs = 1;\n                int happy = 0;\n                int badlevelssum = 0;\n                for(int i = 0; i < loyalties.length; i++) {\n                    if(((pos >> i) & 1) == 1) { //happy senator\n                        happy++;\n                        occurs *= (double) loyalties[i] / 100;\n                    } else { //unhappy senator\n                        badlevelssum += levels[i];\n                        occurs *= (double) (100 - loyalties[i]) / 100;\n                    }\n                }\n                double winprob = (happy <= levels.length / 2) ? (double) playerlevelsum / (playerlevelsum + badlevelssum) :\n                        1;\n//            System.err.println(pos + \" \" + (happy <= levels.length / 2) + \" \" + playerlevelsum + \" \" + (playerlevelsum + badlevelssum) + \" \" + occurs + \" \" + winprob + \" \" + occurs * winprob);\n                res += occurs * winprob;\n            }\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            int senators = in.readInt(); // n, [1, 8]\n            int sweets = in.readInt(); // k, [1, 8]\n            int playerlevelsum = in.readInt(); // A, [1, 9999]\n            int[] levels = new int[senators]; // [1, 9999]\n            int[] loyalties = new int[senators]; // [0, 100] divisible by 10\n            IOUtils.readIntArrays(in, levels, loyalties);\n            ArrayList<ArrayList<Integer>> possibilities = new ArrayList<>(Arrays.asList(new ArrayList<>()));\n            for(int senator = 0; senator < senators; senator++) {\n                ArrayList<ArrayList<Integer>> newpossibilities = new ArrayList<>();\n                for(ArrayList<Integer> al : possibilities) {\n                    int sumsofar = 0;\n                    for(int val : al) sumsofar += val;\n                    int minadd = senator == senators - 1 ? sweets - sumsofar : 0;\n                    for(int moar = minadd; moar <= sweets - sumsofar; moar++) {\n                        ArrayList<Integer> copy = new ArrayList<>(al);\n                        copy.add(moar);\n                        newpossibilities.add(copy);\n                    }\n                }\n                possibilities = newpossibilities;\n            }\n            double res = 0;\n//        out.printLine(possibilities.size());\n            for(ArrayList<Integer> al : possibilities) {\n                int[] newloyalties = new int[senators];\n                for(int i = 0; i < senators; i++) newloyalties[i] = Math.min(100, loyalties[i] + 10 * al.get(i));\n//            out.printLine(al);\n//            out.printLine(newloyalties);\n//            double works = dp(0, 0, newloyalties);\n                double special = special(newloyalties, levels, playerlevelsum);\n                double tot = special;\n                res = Math.max(res, tot);\n            }\n            out.printLine(res);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if(numChars == -1)\n                throw new InputMismatchException();\n            if(curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch(IOException e) {\n                    throw new InputMismatchException();\n                }\n                if(numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public 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    }\n\n    static class IOUtils {\n        public static void readIntArrays(InputReader in, int[]... arrays) {\n            for(int i = 0; i < arrays[0].length; i++) {\n                for(int j = 0; j < arrays.length; j++)\n                    arrays[j][i] = in.readInt();\n            }\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "\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    static void debug(Object...os){\n        System.err.println(deepToString(os));\n    }\n    int n,A;\n    int[] bs,ls;\n    void run(){\n        n=nextInt();int k=nextInt();A=nextInt();\n        bs=new int[n];ls=new int[n];\n        for(int i=0;i<n;i++) {\n            bs[i]=nextInt();ls[i]=nextInt();\n        }\n        dfs(k,0);\n        System.out.println(res);\n    }\n    \n    double res=0;\n    private void dfs(int k,int i){\n        if(i==n) {\n            double val=0;\n            for(int j=0;j<1<<n;j++) {// 1 approve\n                double p=1;\n                int B=0;\n                for(int l=0;l<n;l++)p*= (j>>l&1)==1 ? ls[l]/100.0 : (100-ls[l])/100.0;\n                for(int l=0;l<n;l++)if((j>>l&1)==0)B += bs[l];\n                if(Integer.bitCount(j) > n/2) {\n                    val += p;\n                }else {\n                    val += p * A / (A+B);\n                }\n            }\n            res=max(res,val);\n            return;\n        }\n        for(int j=0;j<k+1;j++) {\n            ls[i]+=j*10;\n            if(ls[i]<=100) {\n                dfs(k-j,i+1);\n            }\n            ls[i]-=j*10;\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    public static void main(String[] args){\n        new Main().run();\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.awt.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\npublic class B {\n\tstatic int ourLevel;\n\tpublic static void main(String[] args) throws IOException\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 k = Integer.parseInt(st.nextToken());\n\t\tourLevel = Integer.parseInt(st.nextToken());\n\t\tState[] list = new State[n];\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tlist[i] = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())/10);\n\t\t}\n\t\tSystem.out.println(solve(list, 0, k));\n\t}\n\tpublic static double solve(State[] s, int index, int left)\t\t{\n\t\tif(index == s.length)\n\t\t\treturn prob(s);\n\t\tdouble ret = 0;\n\t\tfor(int c = 0; c <= left && s[index].prob + c <= 10; c++)\t{\n\t\t\ts[index].prob += c;\n\t\t\tret = Math.max(ret, solve(s, index+1, left-c));\n\t\t\ts[index].prob -= c;\n\t\t}\n\t\treturn ret;\n\t}\n\tpublic static double prob(State[] s)\t{\n\t\tdouble win = 1;\n\t\tfor(int i = 0; i < (1<<s.length); i++)\t{\n\t\t\tint numLose = s.length - Integer.bitCount(i);\n\t\t\tif(2*numLose >= s.length)\t{\n\t\t\t\tint level = 0;\n\t\t\t\tdouble p = 1;\n\t\t\t\tfor(int j = 0; j < s.length; j++)\t{\n\t\t\t\t\tif((i&(1<<j)) == 0)\t{\n\t\t\t\t\t\tp *= (10-s[j].prob)/10.;\n\t\t\t\t\t\tlevel += s[j].level;\n\t\t\t\t\t}\n\t\t\t\t\telse\t{\n\t\t\t\t\t\tp *= s[j].prob/10.;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdouble lose = level * 1.0 / (ourLevel + level);\n\t\t\t\twin -= p * lose;\n\t\t\t}\n\t\t}\n\t\treturn win;\n\t}\n\tstatic class State\t{\n\t\tpublic int level,prob;\n\t\tpublic State(int a, int b)\t{\n\t\t\tlevel = a;\n\t\t\tprob = b;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\n\n\n\npublic class Main {\n    static double max = 0.0;\n    public static void main(String[] args) {\n        Scanner r = new Scanner(System.in);\n        \n        int n = r.nextInt();\n        int k = r.nextInt();\n        int A = r.nextInt();\n        \n        Person[] p = new Person[n];\n        \n        for(int i = 0; i < n; i++){         \n            int l = r.nextInt();\n            int prob = r.nextInt();\n            \n            p[i] = new Person(l, prob);\n        }\n        \n        int[] add = new int[n];\n        \n        double res = dfs(0, k, p, add, n, A);\n        \n        System.out.println(res);\n        \n    }\n    private static double dfs(int ptr, int k, Person[] p, int[] add, int n, int A) {\n        if(k < 0)return 0;\n        \n        double res1 = 0;\n        for(int m = 0; m < 1<<n; m++){\n            double win = 1;\n            int cnt = 0;\n            for(int i = 0; i < n; i++){\n                if((m & (1 << i)) == 0){\n                    win *= (100-(p[i].p+add[i]))*1.0/100;\n                }else{\n                    win *= (add[i]+p[i].p)*1.0/100;                 \n                    cnt++;\n                }\n            }\n\n            if(cnt > n/2){\n                res1 += win; \n            }else{\n                int B = 0;\n                for(int i = 0; i < n; i++){\n                    if((m & (1 << i)) == 0){\n                        B += p[i].l;\n                    }\n                }\n                \n                win *= A*1.0/(A+B);\n                                \n                res1 += win; \n            }\n        }\n        \n        double res2 = 0, res3 = 0;\n        \n        if(add[ptr]+p[ptr].p < 100){\n            add[ptr] += 10;\n            res2 = dfs(ptr, k-1, p, add, n, A);\n            add[ptr] -= 10;\n        }\n        if(ptr+1 < n){\n            res3 = dfs(ptr+1, k, p, add, n, A);\n        }\n        \n        return Math.max(res1, Math.max(res2, res3));\n    }\n}\nclass Person{\n    int l, p;\n    public Person(int li, int pi){\n        l = li;\n        p = pi;\n    }\n    public String toString(){\n        return String.format(\"[%d, %d]\", l, p);\n    }\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class BNew {\n\n    double gAns = 0;\n\n    public static void main(String[] args) throws IOException {\n        new BNew().solve();\n    }\n\n    private void solve() throws IOException {\n        MyScanner in = new MyScanner(new BufferedReader(new InputStreamReader(System.in)));\n        int n = in.nextInt();\n        int k = in.nextInt();\n        int A = in.nextInt();\n        List<Senator> allSenators = new ArrayList<Senator>();\n        for (int i = 0; i < n; i++) {\n            int level = in.nextInt();\n            int loyalty = in.nextInt();\n            allSenators.add(new Senator(level, loyalty));\n        }\n        allSenators = Collections.unmodifiableList(allSenators);\n\n        int npow2 = 1 << n;\n\n        rec(allSenators, 0, k, A);\n        for (int okSenatorMask = 0; okSenatorMask < npow2; okSenatorMask++) {\n            List<Senator> okSenators = copy(getSenatorsByMask(okSenatorMask, allSenators));\n            liftLeastSenators(okSenators, k);\n            List<Senator> updatedSenators = new ArrayList<Senator>(okSenators);\n            List<Senator> otherSenators = getSenatorsByMask(npow2 - 1 - okSenatorMask, allSenators);\n            updatedSenators.addAll(otherSenators);\n            check(updatedSenators, A);\n        }\n\n        in.close();\n\n        PrintWriter pw = new PrintWriter(System.out);\n        System.out.printf(\"%.6f\\n\", gAns);\n        pw.close();\n    }\n\n    private void rec(List<Senator> senators, int senatorId, int k, int A) {\n        if (senatorId == senators.size()) {\n            check(senators, A);\n            return;\n        }\n        Senator senator = senators.get(senatorId);\n        int up = Math.min(k, (100 - senator.loyalty) / 10);\n        final int old = senator.loyalty;\n        for (int i = 0; i <= up; i++) {\n            senator.loyalty = old + i * 10;\n            rec(senators, senatorId + 1, k - i, A);\n        }\n        senator.loyalty = old;\n    }\n\n    private void check(List<Senator> senators, double A) {\n        double winProp = 0.0;\n        for (int mask = 0; mask < 1 << senators.size(); mask++) {\n            double caseP = 1.0;\n            int okCnt = 0;\n            int notOkLevelSum = 0;\n            for (int i = 0; i < senators.size(); i++) {\n                Senator senator = senators.get(i);\n                double senatorLoyalty = senator.loyalty / 100.0;\n                boolean ok = (mask & (1 << i)) != 0;\n                if (ok) {\n                    caseP *= senatorLoyalty;\n                    okCnt++;\n                } else {\n                    caseP *= (1 - senatorLoyalty);\n                    notOkLevelSum += senator.level;\n                }\n            }\n            if (okCnt * 2 > senators.size()) {\n                winProp += caseP;\n            } else {\n                double killProp = A / (A + notOkLevelSum);\n                winProp += caseP * killProp;\n            }\n        }\n        gAns = Math.max(gAns, winProp);\n    }\n\n    List<Senator> copy(List<Senator> senators) {\n        List<Senator> copied = new ArrayList<Senator>();\n        for (Senator senator : senators) {\n            copied.add(new Senator(senator.level, senator.loyalty));\n        }\n        return copied;\n    }\n\n    void liftLeastSenators(List<Senator> senators, int k) {\n        if (senators.isEmpty()) {\n            return;\n        }\n        for (int i = 0; i < k; i++) {\n            Senator least = senators.get(0);\n            for (Senator senator : senators) {\n                if (senator.loyalty < least.loyalty) {\n                    least = senator;\n                }\n            }\n            if (least.loyalty < 100) {\n                least.loyalty += 10;\n            }\n        }\n    }\n\n    List<Senator> getSenatorsByMask(int mask, List<Senator> allSenators) {\n        List<Senator> list = new ArrayList<Senator>();\n        for (int i = 0; i < allSenators.size(); i++) {\n            if ((mask & (1 << i)) != 0) {\n                list.add(allSenators.get(i));\n            }\n        }\n        return list;\n    }\n\n    static class Senator {\n        final int level;\n        int loyalty;\n\n        Senator(int level, int loyalty) {\n            this.level = level;\n            this.loyalty = loyalty;\n        }\n\n        @Override\n        public String toString() {\n            return \"{\" +\n                    \"level=\" + level +\n                    \", loyalty=\" + loyalty +\n                    '}';\n        }\n    }\n\n    static class MyScanner {\n        final BufferedReader myBr;\n        StringTokenizer st = new StringTokenizer(\"\");\n\n        MyScanner(BufferedReader br) {\n            myBr = br;\n        }\n\n        String nextToken() throws IOException {\n            while (!st.hasMoreTokens()) {\n                st = new StringTokenizer(myBr.readLine());\n            }\n            return st.nextToken();\n        }\n\n        int nextInt() throws IOException {\n            return Integer.parseInt(nextToken());\n        }\n\n        void close() throws IOException {\n            myBr.close();\n        }\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n    int n, k, a;\n    int[] b, l;\n\n    double best;\n\n    double calc(int i, int r, int c, double p) {\n        if (i == n) {\n            if (c <= n / 2) {\n                p *= 1.0 * a / (a + r);\n            }\n            return p;\n        } else {\n            return calc(i + 1, r, c + 1, p * l[i] / 10.0) + calc(i + 1, r + b[i], c, p * (10 - l[i]) / 10.0);\n        }\n    }\n\n    void go(int i, int k) {\n        if (i == n) {\n            double p = calc(0, 0, 0, 1.0);\n            if (p > best) best = p;\n        } else {\n            for (int c = 0; c <= k && l[i] + c <= 10; ++c) {\n                l[i] += c;\n                go(i + 1, k - c);\n                l[i] -= c;\n            }\n        }\n    }\n\n    void solve() throws IOException {\n        in(\"__std\"); out(\"__std\");\n\n        n = readInt();\n        k = readInt();\n        a = readInt();\n        b = new int[n];\n        l = new int[n];\n        for (int i = 0; i < n; ++i) {\n            b[i] = readInt();\n            l[i] = readInt() / 10;\n        }\n\n        go(0, k);\n\n        println(\"%.10f\", best);\n\n        exit();\n    }\n\n    void in(String name) throws IOException {\n        if (name.equals(\"__std\")) {\n            in = new BufferedReader(new InputStreamReader(System.in));\n        } else {\n            in = new BufferedReader(new FileReader(name));\n        }\n    }\n\n    void out(String name) throws IOException {\n        if (name.equals(\"__std\")) {\n            out = new PrintWriter(System.out);\n        } else {\n            out = new PrintWriter(name);\n        }\n    }\n\n    void exit() {\n        out.close();\n        System.exit(0);\n    }\n\n    int readInt() throws IOException {\n        return Integer.parseInt(readToken());\n    }\n\n    long readLong() throws IOException {\n        return Long.parseLong(readToken());\n    }\n\n    double readDouble() throws IOException {\n        return Double.parseDouble(readToken());\n    }\n\n    String readLine() throws IOException {\n        st = null;\n        return in.readLine();\n    }\n\n    String readToken() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    boolean eof() throws IOException {\n        return !in.ready();\n    }\n\n    void print(String format, Object ... args) {\n        out.println(new Formatter().format(format, args));\n    }\n\n    void println(String format, Object ... args) {\n        out.println(new Formatter().format(format, args));\n    }\n\n    void print(Object value) {\n        out.print(value);\n    }\n\n    void println(Object value) {\n        out.println(value);\n    }\n\n    void println() {\n        out.println();\n    }\n\n    StringTokenizer st;\n\n    BufferedReader in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws IOException {\n        new B().solve();\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\npublic class Main {\n\tprivate static StreamTokenizer in;\n\tprivate static PrintWriter out;\n\tstatic {\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tprivate static double nextDouble() throws Exception {\n\t\tin.nextToken();\n\t\treturn 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 n = nextInt(), k = nextInt(), A = nextInt(), r = n + k - 1;\n\t\tint[][] s = new int[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ts[i] = new int[] { nextInt(), nextInt() };\n\t\t}\n\t\tdouble max = 0;\n\t\tint[] prb = new int[n];\n\t\tfor (int u = (1 << r); u >= 0; u--) {\n\t\t\t// \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0430 n-1 \u0435\u0434\u0438\u043d\u0438\u0447\u0435\u043a\n\t\t\tint ones = 0;\n\t\t\tfor (int i = 0; i < r; i++) {\n\t\t\t\tif ((u & (1 << i)) != 0) {\n\t\t\t\t\tones++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ones != n - 1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438. \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\n\t\t\tones = 0;\n\t\t\tint p = 0;\n\t\t\tfor (int i = 0; i < r; i++) {\n\t\t\t\tif ((u & (1 << i)) == 0) {\n\t\t\t\t\tones++;\n\t\t\t\t} else {\n\t\t\t\t\tprb[p] = ones * 10;\n\t\t\t\t\tp++;\n\t\t\t\t\tones = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprb[p] = ones * 10;\n\t\t\tp++;\n\t\t\tones = 0;\n\t\t\tdouble sum = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (prb[i] > 100 - s[i][1])\n\t\t\t\t\tprb[i] = 100 - s[i][1];\n\t\t\t\ts[i][1] = prb[i] + s[i][1];\n\t\t\t}\n\t\t\tfor (int i = (1 << n) - 1; i >= 0; i--) {\n\t\t\t\tdouble prob = 1;\n\t\t\t\tint lvl = 0;\n\t\t\t\tint kill = 0;\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif ((i & (1 << j)) != 0) {\n\t\t\t\t\t\tprob *= s[j][1] / 100.0;\n\t\t\t\t\t\tkill--;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlvl += s[j][0];\n\t\t\t\t\t\tprob *= (1 - s[j][1] / 100.0);\n\t\t\t\t\t\tkill++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (kill >= 0) {\n\t\t\t\t\tsum += prob * ((double) A / (A + lvl));\n\t\t\t\t} else {\n\t\t\t\t\tsum += prob;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ts[i][1] = -prb[i] + s[i][1];\n\t\t\t}\n\t\t\tmax = Math.max(max, sum);\n\t\t}\n\t\tout.println(max);\n\t\tout.flush();\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport static java.lang.Math.*;\n\npublic class Main{\n    \n    public void go(){\n        int n=sc.nextInt(), k=sc.nextInt(), A=sc.nextInt();\n        ArrayList< ArrayList< Integer > > waysGiveCandies = doit1(n, k, new ArrayList< Integer >());\n/*\n        System.out.printf(\"%d\\n\", waysGiveCandies.size());\n        for(ArrayList< Integer > x : waysGiveCandies){\n            for(int i : x)\n                System.out.printf(\"%d \", i);\n            System.out.printf(\"\\n\");\n        }\n*/\n        int[] lvl = new int[n], loyal = new int[n];\n        for(int i=0; i<n; ++i){\n            lvl[i] = sc.nextInt();\n            loyal[i] = sc.nextInt();\n        }\n\n        double ret = 0;\n        for(ArrayList< Integer > distribution : waysGiveCandies){\n            double[] Loyal = new double[n];\n            for(int i=0; i<n; ++i) Loyal[i] = min(loyal[i]+10*distribution.get(i), 100)/100.0;\n            double pWin = 0;\n            for(int i=0; i<1<<n; ++i){\n                double pVoteOccurs = 1;\n                for(int j=0; j<n; ++j) \n                    if((i&(1<<j))!=0) // if winner\n                        pVoteOccurs *= Loyal[j];\n                    else // if loser\n                        pVoteOccurs *= 1-Loyal[j];\n\n                int B = 0;\n                for(int j=0; j<n; ++j) if((i&(1<<j))==0)\n                    B += lvl[j];\n                double pWinFight = (double)A/(A+B);\n\n                // if win vote, don't need to fight\n                if(bit_count(i)*2 > n)\n                    pWinFight = 1;\n\n                pWin += pVoteOccurs * pWinFight;\n            }\n            ret = max(ret, pWin);\n        }\n\n        System.out.printf(\"%.9f\\n\", ret);\n    }\n\n    ArrayList< ArrayList< Integer > > doit1(int n, int k, ArrayList< Integer > soFar){\n        ArrayList< ArrayList< Integer > > ret = new ArrayList< ArrayList< Integer > >();\n        \n        // base case\n        if(n==1){\n            soFar.add(k);\n            ret.add(soFar);\n            return ret;\n        }\n\n        // general case\n        for(int i=0; i<k+1; ++i){\n            ArrayList< Integer > tmp = new ArrayList< Integer >(soFar);\n            tmp.add(i);\n            ret.addAll(doit1(n-1, k-i, tmp));\n        }\n\n        return ret;\n    }\n\n    // syntax\n    // ArrayList<Integer>[] myMat = (ArrayList<Integer>[]) new ArrayList[nB];\n\n    // Pairs\n    public class ii implements Comparable< ii >{\n        int x, y;\n        public ii(){}\n        public ii(int xx, int yy){ x=xx; y=yy; }\n        public int compareTo(ii p){ return x!=p.x ? x-p.x : y-p.y; }\n        public int hashCode(){ return 31*x+y; }\n        public boolean equals(Object o){\n            if(!(o instanceof ii)) return false;\n            ii p = (ii) o;\n            return x==p.x && y==p.y;\n        }\n        public String toString(){ return \"(\"+x+\", \"+y+\")\"; }\n    }\n/*\n    public class pair< X extends Comparable< X >,Y extends Comparable< Y > > implements Comparable< pair< X,Y > >{\n        X x;\n        Y y;\n        public pair(){}\n        public pair(X xx, Y yy){ x=xx; y=yy; }\n        public int compareTo(pair< X,Y > p){ return x.compareTo(p.x)!=0 ? x.compareTo(p.x) : y.compareTo(p.y); }\n        public int hashCode(){ return 31*x.hashCode()+y.hashCode(); }\n        public boolean equals(Object o){\n            if((o.getClass() != this.getClass())) return false;\n            pair< X,Y > p = (pair< X,Y >) o;\n            return x.equals(p.x) && y.equals(p.y);\n        }\n        public String toString(){ return \"(\"+x+\", \"+y+\")\"; }\n    }\n*/\n    // my stuff\n    public static final int INF = 1000*1000*1000+7;\n    public static final double EPS = 1e-9;\n    public static final double PI = 2*acos(0.0);\n    public void rev(Object[] a){ for(int i=0; i<a.length/2; ++i){ Object t=a[i]; a[i]=a[a.length-1-i]; a[a.length-1-i]=t; } }\n    public void rev(int[] a){ for(int i=0; i<a.length/2; ++i){ int t=a[i]; a[i]=a[a.length-1-i]; a[a.length-1-i]=t; } }\n    public int bit_count(long x){ return x==0 ? 0 : 1+bit_count(x&(x-1)); }\n    public int low_bit(int x){ return x&-x; } // 0011 0100 returns 0000 0100\n    public int sign(int x){ return x<0 ? -1 : x>0 ? 1 : 0; }\n    public int sign(double x){ return x<-EPS ? -1 : x>EPS ? 1 : 0; }\n    int[] unpack(ArrayList< Integer > a){\n        int[] ret = new int[a.size()];\n        for(int i=0; i<a.size(); ++i) ret[i] = a.get(i);\n        return ret;\n    }\n\n    // generic main stuff\n    static myScanner sc;\n    static PrintWriter pw;\n    static long startTime;\n    public static void main(String[] args) throws Exception{\n        // sc = new Scanner(System.in);\n        sc = (new Main()).new myScanner(new BufferedReader(new InputStreamReader(System.in)));\n        pw = new PrintWriter(System.out);\n        startTime = System.nanoTime();\n        (new Main()).go();\n        // errprintln(\"nanoTime=\"+(System.nanoTime()-startTime)/1000000/1000.0);\n        pw.flush();\n        System.exit(0);\n    }\n\n    // capable of reading   2.86M 6dp doubles per second\n    //                      2.16M 12dp doubles per second\n    //                      2.75M int per second\n    public class myScanner{\n        private BufferedReader f;\n        private StringTokenizer st;\n        public myScanner(BufferedReader ff){ f=ff; st=new StringTokenizer(\"\"); }\n        public int nextInt(){ return Integer.parseInt(nextToken()); }\n        public double nextDouble(){ return Double.parseDouble(nextToken()); }\n        public String nextLine(){\n            st=new StringTokenizer(\"\");\n            String ret=\"\";\n            try{ ret=f.readLine(); }catch(Exception e){}\n            return ret;\n        }\n        public String nextToken(){\n            while(!st.hasMoreTokens()) try{ st=new StringTokenizer(f.readLine()); } catch(Exception e){}\n            return st.nextToken();\n        }\n    }\n\n\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.Map;\n\n\npublic class ProblemB {\n\tpublic static int _gnum;\n\tpublic static int _cnum;\n\tpublic static int _needs;\n\tpublic static int _level;\n\t\n\tpublic static double _maxans = 0;\n\t\n\tpublic static double votedfs(int[][] grl, int g, int votes) {\n\t\tif (votes >= _needs) {\n\t\t\treturn 1.0d;\n\t\t}\n\t\tif (g >= _gnum) {\n\t\t\treturn 0.0d;\n\t\t}\n\t\tdouble agrees = (double)grl[g][1] / 100;\n\t\treturn agrees * votedfs(grl, g+1, votes+1) + (1.0d - agrees) * votedfs(grl, g+1, votes);\n\t}\n\t\n\tpublic static double battledfs(int[][] grl, int g, int votes, int levels) {\n\t\tif (votes >= _needs) {\n\t\t\treturn 0.0d;\n\t\t}\n\t\tif (g >= _gnum) {\n\t\t\treturn (double)_level / (_level + levels);\n\t\t}\n\t\tdouble agrees = (double)grl[g][1] / 100;\n\t\treturn agrees * battledfs(grl, g+1, votes+1, levels) + (1.0d - agrees) * battledfs(grl, g+1, votes, levels + grl[g][0]);\n\t}\n\t\n\tpublic static void candydfs(int[][] grl, int g, int n) {\n\t\tif (g >= _gnum) {\n\t\t\tdouble na = votedfs(grl, 0, 0) + battledfs(grl, 0, 0, 0);\n\t\t\t_maxans = Math.max(_maxans, na);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint rem = grl[g][1];\n\t\tcandydfs(grl, g+1, n);\n\t\tfor (int i = 1 ; i <= n ; i++) {\n\t\t\tif (grl[g][1] < 100) {\n\t\t\t\tgrl[g][1] += 10;\n\t\t\t\tcandydfs(grl, g+1, n-i);\n\t\t\t}\n\t\t}\n\t\tgrl[g][1] = rem;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        String line = br.readLine();\n        String[] d = line.split(\" \");\n        int gnum = Integer.valueOf(d[0]);\n        int cnum = Integer.valueOf(d[1]);\n        int level = Integer.valueOf(d[2]);\n        _gnum = gnum;\n        _cnum = cnum;\n        _needs = (gnum + 1) / 2;\n        if (gnum % 2 == 0) {\n        \t_needs += 1;\n        }\n        _level = level;\n        \n        int[][] grl = new int[gnum][2];\n        for (int g = 0 ; g < gnum ; g++) {\n        \tline = br.readLine();\n        \tString[] gg = line.split(\" \");\n        \tgrl[g][0] = Integer.valueOf(gg[0]);\n        \tgrl[g][1] = Integer.valueOf(gg[1]);\n        }\n        \n        for (int a = 0 ; a < gnum ; a++) {\n            for (int b = 0 ; b < gnum - 1 ; b++) {\n            \tif (grl[b][1] < grl[b+1][1]) {\n            \t\tint tmp = grl[b][0];\n            \t\tgrl[b][0] = grl[b+1][0];\n            \t\tgrl[b+1][0] = tmp;\n            \t\ttmp = grl[b][1];\n            \t\tgrl[b][1] = grl[b+1][1];\n            \t\tgrl[b+1][1] = tmp;\n            \t}\n            } \t\n        }\n        \n        int ag = 0;\n        int xnum = cnum;\n        for (int g = 0 ; g < gnum ; g++) {\n        \tint needs = (100 - grl[g][1]) / 10;\n        \tint roy = 0;\n        \tif (needs <= xnum) {\n        \t\txnum -= needs;\n        \t\troy = 100;\n        \t} else {\n        \t\troy = grl[g][1] + xnum * 10;\n        \t\txnum = 0;\n        \t}\n        \tif (roy >= 100) {\n        \t\tag++;\n        \t}\n        }\n        if (ag >= _needs) {\n        \tSystem.out.println(1.0);\n        \treturn;\n        }\n        \n        candydfs(grl, 0, _cnum);\n        \n        System.out.println(_maxans);\n        br.close();\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import javax.print.Doc;\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 taskB {\n    public static void main(String[] args) throws IOException {\n        new taskB().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n    static String TASK = \"\";\n\n    void run() throws IOException {\n        try {\n           // reader = new BufferedReader(new FileReader(TASK + \".in\"));\n            reader = new BufferedReader(new InputStreamReader(System.in));\n            writer = new PrintWriter(System.out);\n           // writer = new PrintWriter(TASK + \".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 b[];\n    int l[];\n    int add[];\n    int n, k, A;\n\n    double ans = 0;\n    void solve() throws IOException {\n        n = nextInt();\n        k = nextInt();\n        A = nextInt();\n        b = new int[n];\n        l = new int[n];\n        add = new int[n];\n        for (int i = 0; i < n; ++i) {\n            b[i] = nextInt();\n            l[i] = nextInt();\n        }\n\n        brute(0, k);\n\n        writer.printf(\"%.10f\", ans);\n    }\n\n    private void brute(int pos, int yet) {\n        if (pos == n) {\n            /*double prob[][] = new double[n + 1][n + 1];\n            prob[0][0] = 1;\n\n            for (int i = 1; i <= n; ++i) {\n                for (int sayYes = 1; sayYes <= i; ++sayYes) {\n                    prob[i][sayYes] = p[i - 1] * prob[i - 1][sayYes - 1];\n                }\n                for (int sayYes = 0; sayYes <= i; ++sayYes) {\n                    prob[i][sayYes] = (1 - p[i - 1]) * prob[i - 1][sayYes];\n                }\n            }\n            double nowYes = 0;\n            for (int i = 0; i <= n; ++i) {\n                if (i >= (n + 2) / 2 )\n                    nowYes += prob[n][i];\n            } */\n\n            double p[] = new double[n];\n            for (int i = 0; i < n; ++i) {\n                p[i] = (l[i] + add[i]) / 100.0;\n            }\n            double r = 0;\n            for (int i =0; i < (1 << n); ++i) {\n                double pr =1 ;\n                int sm = 0;\n                for (int j =0 ; j < n; ++j) {\n                    if ((i & (1 << j)) > 0) {\n                        pr *= p[j];\n                    }  else {\n                        pr *= (1 - p[j]);\n                        sm += b[j];\n                    }\n                }\n                int c = Integer.bitCount(i);\n                if (c >= (n + 2) / 2) {\n                    r += pr;\n                } else {\n                    r += pr * (1.0 * A / (A + sm));\n                }\n            }\n            ans = Math.max(ans, r);\n        } else {\n            for (int i = 0; i <= yet; ++i) {\n                if (l[pos] + 10 * i > 100) continue;\n                add[pos] = 10 * i;\n                brute(pos + 1, yet - i);\n            }\n        }\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    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    BigInteger nextBigInteger() throws IOException {\n        return new BigInteger(nextToken());\n    }\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "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        double ans = 0;\n        int[] candy;\n        int[] b;\n        int[] l;\n        int[] curLoyal;\n        int n;\n        int k;\n        int A;\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            k = in.nextInt();\n            A = in.nextInt();\n            b = new int[n];\n            l = new int[n];\n            for (int i = 0; i < n; i++) {\n                b[i] = in.nextInt();\n                l[i] = in.nextInt();\n            }\n            candy = new int[n];\n            curLoyal = new int[n];\n            comb(0, k);\n            out.println(ans);\n        }\n\n        void comb(int ind, int unusedCandy) {\n            if (ind == n) {\n                for (int i = 0; i < n; i++) {\n                    curLoyal[i] = Math.min(candy[i] * 10 + l[i], 100);\n                }\n                calc();\n            } else {\n                for (int i = 0; i <= unusedCandy; i++) {\n                    candy[ind] = i;\n                    comb(ind + 1, unusedCandy - i);\n                }\n            }\n        }\n\n        void calc() {\n            double res = 0;\n            int allBits = (1 << n) - 1;\n            for (int vote = 0; vote <= allBits; vote++) {\n                double curProb = 1;\n                int sumPower = A;\n                int enemyCnt = 0;\n                for (int voteInd = 0; voteInd < n; voteInd++) {\n                    if ((vote & (1 << voteInd)) == 0) {\n                        curProb *= 100 - curLoyal[voteInd];\n                        sumPower += b[voteInd];\n                        enemyCnt++;\n                    } else {\n                        curProb *= curLoyal[voteInd];\n                    }\n                    curProb /= 100;\n                }\n                if (2 * enemyCnt >= n) {\n                    curProb *= A;\n                    curProb /= sumPower;\n                }\n                res += curProb;\n            }\n            ans = Math.max(ans, res);\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", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n    StreamTokenizer in;\n    PrintWriter out;\n\n    public static void main(String[] args) throws Exception {\n        new Main().run();\n    }\n\n    public void run() throws Exception {\n        Locale.setDefault(Locale.US);\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    public int nextInt() throws Exception {\n        in.nextToken();\n        return (int) in.nval;\n    }\n    \n    public String next() throws Exception {\n        in.nextToken();\n        return in.sval;\n    }\n    \n    class Senator {\n        int b;\n        int l;\n        \n        public Senator (int b,int l) {\n            this.b=b;\n            this.l=l;\n        }\n        \n    }\n    \n    int n,k,A;\n    double max=Integer.MIN_VALUE;\n    Senator[] a;\n    \n    public void check (int step,int candy) {\n        if (step==n)\n        {\n            double tmp = 0.0;\n            for (int mask=0; mask<(1<<n);mask++)\n            {\n                double P = 1.0;\n                int q = 0;\n                for (int i=0; i<n;i++)\n                {\n                    if ((mask>>i&1)!=0)\n                    {\n                        P*=a[i].l/100.;\n                    } else\n                    {\n                        P*=1.0-a[i].l/100.;\n                        q+=a[i].b;\n                    }\n                }\n                if (Integer.bitCount(mask)>n/2)\n                {\n                    tmp+=P;\n                } else\n                {\n                    tmp+=P*A/(A+q);\n                }\n                max=Math.max(tmp,max);\n            }\n        } else\n        {\n            for (int i=0;i<=Math.min(k,(100-a[step].l)/10);i++)\n            {\n                a[step].l+=10*i;\n                check(step+1,k-i);\n                a[step].l-=10*i;\n            }\n        }\n    }\n    \n    public void solve() throws Exception {\n        n=nextInt();\n        k=nextInt();\n        A=nextInt();\n        a = new Senator [n];\n        for (int i=0; i<n;i++) {\n            Senator q = new Senator(nextInt(),nextInt());\n            a[i]=q;\n        }\n        double ans=0;\n        for(int mask=0;mask<1<<(n+k-1);mask++)\n        {\n            if(Integer.bitCount(mask)!=k) continue;       \n            int[] b = new int[n];\n            int x = mask;\n            for(int i=0;i<n;i++)\n            {\n                b[i] = a[i].l;\n                while(x%2==1)\n                {\n                    b[i]+=10;\n                    x/=2;\n                }\n                b[i]=Math.min(b[i],100);\n                x/=2;\n            }\n            double tmp=0;\n            for(int w=0; w<(1<<n);w++)\n            {\n                double p = 1.;\n                double B = 0;\n                for(int i = 0; i < n; i++)\n                    if((w >> i & 1) != 0) p *= b[i] / 100.;\n                    else\n                    { \n                        p *= 1- b[i]/100.;\n                        B += a[i].b;\n                    }\n                if(Integer.bitCount(w)> n/2) tmp += p;\n                else tmp += p * (A / (A + B));\n            }\n            ans = Math.max(ans, tmp);\n        }\n        out.printf(\"%.10f\\n\", ans);\n    }\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TemnayaAssambleya implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TemnayaAssambleya()).run();\n\t}\n\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer in;\n\tPrintWriter out = new PrintWriter(System.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\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\tint[] l;\n\tint[] ln;\n\tint[] pw;\n\tint[] p;\n\tint A;\n\tdouble max = 0;\n\n\tpublic void gen(int n, int k) {\n\t\tif (n == 0) {\n\t\t\tn = p.length;\n\t\t\tp[0] = k;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tln[i] = l[i] + p[i] * 10;\n\t\t\t\tif (ln[i] > 100)\n\t\t\t\t\tln[i] = 100;\n\t\t\t}\n\n\t\t\tdouble ans = 0;\n\t\t\tfor (int mask = 0; mask < 1 << n; mask++) {\n\t\t\t\tint z = 0;\n\t\t\t\tdouble pos = 1;\n\t\t\t\tint power = 0;\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\tz++;\n\t\t\t\t\t\tpos *= ln[i] * 1. / 100;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpos *= (100 - ln[i]) * 1. / 100;\n\t\t\t\t\t\tpower += pw[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (z > n / 2) {\n\t\t\t\t\tans += pos;\n\t\t\t\t} else {\n\t\t\t\t\tans += pos * A / (A + power);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tmax = Math.max(ans, max);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (int i = 0; i <= Math.min(k, 10 - l[n] / 10); i++) {\n\t\t\tp[n] = i;\n\t\t\tgen(n - 1, k - i);\n\t\t}\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tA = nextInt();\n\n\t\tp = new int[n];\n\t\tpw = new int[n];\n\t\tl = new int[n];\n\t\tln = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tpw[i] = nextInt();\n\t\t\tl[i] = nextInt();\n\t\t}\n\n\t\tgen(n - 1, k);\n\t\tout.println(max);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class B implements Runnable {\n\n    int a;\n    int[] b;\n    int[] l;\n\n    public void solve() throws IOException {\n        int n = in.nextInt();\n        int k = in.nextInt();\n        a = in.nextInt();\n        b = new int[n];\n        l = new int[n];\n        for ( int i = 0; i < n; i ++ ) {\n            b[i] = in.nextInt();\n            l[i] = in.nextInt();\n        }\n        out.println( best( 0, k ));\n    }\n\n    double best( int cur, int left ) {\n        double r = 0.0;\n        if ( cur < l.length ) {\n            for ( int i = 0; i <= left && l[cur] + 10 * i <= 100; i ++ ) {\n                l[cur] += i * 10;\n                r = Math.max( r, best( cur + 1, left - i ) );\n                l[cur] -= i * 10;\n            }\n        } else {\n            for ( int m = 0; m < ( 1 << l.length ); m ++ ) {\n                int sum = 0;\n                double p = 1.0;\n                int pro = 0;\n                for ( int i = 0; i < l.length; i ++ ) {\n                    if ( ( m & ( 1 << i ) ) == 0 ) {\n                        p *= 1.0 - l[i] * 0.01;\n                        sum += b[i];\n                    } else {\n                        p *= l[i] * 0.01;\n                        pro ++;\n                    }\n                }\n                if ( pro * 2 > l.length ) {\n                    r += p;\n                } else {\n                    r += ( p * a ) / ( a + sum );\n                }\n            }\n        }\n        return r;\n    }\n\n    public Scanner in;\n\n    public PrintWriter out;\n\n    B() throws IOException {\n        in = new Scanner(System.in);\n        // in = new StreamTokenizer( new InputStreamReader( System.in ) );\n        out = new PrintWriter(System.out);\n    }\n\n//    int nextInt() throws IOException {\n//        in.nextToken();\n//        return ( int ) in.nval;\n//    }\n\n    void check(boolean f, String msg) {\n        if (!f) {\n            out.close();\n            throw new RuntimeException(msg);\n        }\n    }\n\n    void close() throws IOException {\n        out.close();\n    }\n\n    public void run() {\n        try {\n            solve();\n            close();\n        } catch (Exception e) {\n            e.printStackTrace(out);\n            out.flush();\n            throw new RuntimeException(e);\n        }\n    }\n\n    public static void main(String[] args) throws IOException {\n        new Thread(new B()).start();\n    }\n}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/13/11\n * Time: 6:10 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.IOException;\n\npublic class DarkAssembly extends Thread {\n\n    public DarkAssembly() {\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    static class Senator {\n        int loyalty;\n        int level;\n\n        public Senator(int level, int loyalty) {\n            this.level = level;\n            this.loyalty = loyalty;\n        }\n    }\n\n    private static double doIt(Senator[] senators, int A) {\n        double probability = .0;\n        for (int mask = 0; mask < (1 << senators.length); ++mask) {\n            int sum = A;\n            double current = 1.0;\n            for (int i = 0; i < senators.length; ++i) {\n                if ((mask & (1 << i)) != 0) {\n                    current *= .01 * senators[i].loyalty;\n                } else {\n                    current *= .01 * (100 - senators[i].loyalty);\n                    sum += senators[i].level;\n                }\n            }\n            if (Integer.bitCount(mask) > senators.length / 2) {\n                probability += current;\n            } else {\n                probability += current * (double) A / sum;\n            }\n        }\n        return probability;\n    }\n\n    private static double go(Senator[] senators, int candies, int A, int current) {\n        if (current == senators.length) {\n            return doIt(senators, A);\n        } else {\n            double result = go(senators, candies, A, current + 1);\n            if (candies > 0 && senators[current].loyalty < 100) {\n                senators[current].loyalty += 10;\n                result = Math.max(result, go(senators, candies - 1, A, current));\n                senators[current].loyalty -= 10;\n            }\n            return result;\n        }\n    }\n\n\n\n\n    private void solve() throws Throwable {\n        int n = nextInt();\n        int k = nextInt();\n        int A = nextInt();\n        Senator[] senators = new Senator[n];\n        for (int i = 0; i < n; ++i) {\n            senators[i] = new Senator(nextInt(), nextInt());\n        }\n        output.printf(\"%.10f\", go(senators, k, A, 0));\n    }\n\n    public void run() {\n        try {\n            solve();\n        } catch (Throwable e) {\n            System.err.println(e.getMessage());\n            e.printStackTrace();\n        } finally {\n            output.flush();\n            output.close();\n        }\n\n    }\n\n\n    public static void main(String[] args) {\n        new DarkAssembly().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\n    private BufferedReader input;\n    private PrintWriter output;\n    private StringTokenizer tokens = null;\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\n\npublic class B {\n    static int n;\n    static double A;\n    static int[] L;\n    static int[] B;\n    static double max = 0;\n\n    public static void rec(int index, int k) {\n        if (k < 0)\n            return;\n        if (index == n) {\n            double prob = 0;\n            for (int i = 0; i < (1 << n); i++) {\n                double b = 0;\n                double temp = 1.0;\n                for (int j = 0; j < n; j++) {\n                    if (L[j] > 100)\n                        return;\n                    if ((i & (1 << j)) == 0) {\n                        b += B[j];\n                        temp *= (100 - L[j]) / 100.0;\n                    } else\n                        temp *= L[j] / 100.0;\n                }\n                if (Integer.bitCount(i) * 2 <= n)\n                    temp *= A / (A + b);\n                prob += temp;\n\n            }\n            max = Math.max(max, prob);\n            return;\n        }\n        L[index] += 10;\n        rec(index, k - 1);\n        L[index] -= 10;\n        rec(index + 1, k);\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        A = in.nextDouble();\n        B = new int[n];\n        L = new int[n];\n        for (int i = 0; i < n; i++) {\n            B[i] = in.nextInt();\n            L[i] = in.nextInt();\n        }\n        rec(0, k);\n        System.out.println(max);\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.Map.Entry;\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\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\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\tint n;\n\tint[] b, l;\n\tdouble ans;\n\tint[] sw;\n\tint a;\n\t\n\tvoid sol() {\n\t\tfor (int i = 0; i < n; i++) l[i] += sw[i] * 10;\n\t\tdouble yes = 0;\n\t\tfor (int q = 0; q < (1 << n); q++) {\n\t\t\tdouble p = 1;\n\t\t\tint bb = 0;\n\t\t\tint cnt = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((q & (1 << i)) == 0) {\n\t\t\t\t\tp *= (1.0 - (double)l[i] / 100);\n\t\t\t\t\tbb += b[i];\n\t\t\t\t} else {\n\t\t\t\t\tp *= 1.0 * (double)l[i] / 100;\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cnt > n / 2) {\n\t\t\t\tyes += p;\n\t\t\t} else {\n\t\t\t\tyes += p * (double)a / (double)(a + bb); \n\t\t\t}\n\t\t}\n\t\tif (ans < yes) ans = yes;\n\t\tfor (int i = 0; i < n; i++) l[i] -= sw[i] * 10;\n\t}\n\t\n\tvoid rek(int i, int k) {\n\t\tif (i == n) sol(); else {\n\t\t\tfor (int q = 0; q <= k && l[i] + q * 10 <= 100; q++) {\n\t\t\t\tsw[i] = q;\n\t\t\t\trek(i + 1, k - q);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tn = nextInt();\n\t\tint k = nextInt();\n\t\ta = nextInt();\n\t\tb = new int[n];\n\t\tl = new int[n];\n\t\tsw = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t\tl[i] = nextInt();\n\t\t}\n\t\trek(0, k);\n\t\tout.printf(\"%.10f\", ans);\n\t}\n\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\tin = new BufferedReader(new FileReader(\"knights.in\"));\n//\t\t\tout = new PrintWriter(\"knights.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}", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n    BufferedReader br;\n    PrintWriter out;\n    StringTokenizer st;\n    boolean eof;\n    \n    int[] level;\n    int[] loyal;\n    double ans;\n    int n, k, plLev, needVotes;\n    \n    double check() {\n        \n        //System.err.println(Arrays.toString(loyal));\n        double res = 0;\n        for (int mask = 0; mask < (1 << n); mask++) {\n            double prob = 1;\n            int vote = 0;\n            int kill = 0;\n            for (int i = 0; i < n; i++) \n                if (((mask >> i) & 1) == 1) {\n                    prob *= loyal[i] / 100.0;\n                    vote++;\n                }\n                else {\n                    prob *= 1 - loyal[i] / 100.0;\n                    kill += level[i];\n                }\n            if (vote >= needVotes)\n                res += prob;\n            else\n                res += prob * plLev / (kill + plLev);\n        }\n        \n        return res;\n    }\n    \n    void go(int ind, int candy) {\n        if (ind == n) {\n            ans = Math.max(ans, check());\n            return;\n        }\n        \n        for (int i = 0; i <= candy; i++) {\n            loyal[ind] += 10 * i;\n            if (loyal[ind] > 100) {\n                loyal[ind] -= 10 * i;\n                break;\n            }\n            go(ind + 1, candy - i);\n            loyal[ind] -= 10 * i;\n        }\n        \n    }\n    \n\n    void solve() throws IOException {\n        \n        n = nextInt();\n        k = nextInt();\n        plLev = nextInt();\n        needVotes = n / 2 + 1;\n        ans = 0;\n        \n        level = new int[n];\n        loyal = new int[n];\n        \n        for (int i = 0; i < n; i++) {\n            level[i] = nextInt();\n            loyal[i] = nextInt();\n        }\n        \n        go(0, k);\n        \n        out.printf(\"%.12f\", ans);\n    }\n\n    void inp() throws IOException {\n        Locale.setDefault(Locale.US);\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", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class B{\n    public static void main(String[] args) throws Exception{\n        new B().run();\n    }\n\n    double ans = 0;\n    int n, candy, A, half;\n\n    void run() throws Exception{\n        Scanner sc = new Scanner(System.in);\n        //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));\n        // only sc.readLine() is available\n        n = sc.nextInt();\n        candy = sc.nextInt();\n        A = sc.nextInt();\n        half = n/2;\n        //int[] level = new int[n];\n        //int[] loyal = new int[n];\n        S[] ss = new S[n];\n        for(int i = 0; i < n; i++){\n            ss[i] = new S(sc.nextInt(), sc.nextInt());\n        }\n        Arrays.sort(ss);\n        int need = 0;\n        for(int i = n-1; i >= n-half-1; i--)\n            need += (100-ss[i].loyal)/10;\n        if(need <= candy){\n            System.out.println(1.0);\n            return;\n        }\n        tra(ss, 0, candy);\n        /*\n        while(candy > 0){\n            int ind = 0;\n            for(int i = 1; i < n; i++)\n                if(ss[i].loyal < 100 && ss[ind].level < ss[i].level)\n                    ind = i;\n            ss[ind].loyal += 10;\n            ss[ind].loyal = min(100, ss[ind].loyal);\n            candy--;\n        }\n        */\n        System.out.printf(\"%.10f\\n\", ans);\n    }\n\n    void tra(S[] ss, int pos, int rest){\n        if(pos == n){\n            double sum = 0;\n            int lim = 1<<n;\n            for(int m = 0; m < lim; m++){\n                int app = Integer.bitCount(m);\n                double p = 1;\n                int B = 0;\n                for(int i = 0; i < n; i++){\n                    if(((m>>i) & 1) == 1){\n                        p = p * ss[i].loyal / 100;\n                    }else{\n                        p = p * (100 - ss[i].loyal) / 100;\n                        B += ss[i].level;\n                    }\n                }\n                if(app > half)sum += p;\n                else{\n                    sum += p * A / (A+B);\n                }\n            }\n            ans = max(ans, sum);\n            return;\n        }\n        for(int i = 0; i <= rest; i++){\n            int old = ss[pos].loyal;\n            int nl = ss[pos].loyal + i * 10;\n            if(nl > 100)break;\n            ss[pos].loyal = nl;\n            tra(ss, pos+1, rest-i);\n            ss[pos].loyal = old;\n        }\n    }\n}\n\nclass S implements Comparable<S>{\n    int level, loyal;\n    S(int a, int b){\n        level = a;\n        loyal = b;\n    }\n    public int compareTo(S s){\n        return this.loyal - s.loyal;\n    }\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n\tint[] conf, L, B;\n\tint n, k, A, sz;\n\tdouble[] kill;\n\tdouble best = 0;\n\t\n\tdouble solv() {\n\t\tdouble res = 0;\n\t\tdouble[] a = new double[n];\n\t\tfor (int i=0; i<n; i++) \n\t\t\ta[i] = Math.min(100, L[i]+10*conf[i])/100.0;\n\t\tdouble[] dp1 = new double[sz];\n\t\tdouble[] dp2 = new double[sz];\n\t\tdp1[0] = 1;\n\t\tfor (int i=0; i<n; i++) {\n\t\t\tfor (int msk=0; msk<sz; msk++) { \n\t\t\t\tdp2[msk] += dp1[msk]*a[i];\n\t\t\t\tdp2[msk|(1<<i)] += dp1[msk]*(1-a[i]);\n\t\t\t}\n\t\t\tfor (int msk=0; msk<sz; msk++) {\n\t\t\t\tdp1[msk] = dp2[msk]; dp2[msk] = 0;\n\t\t\t}\n\t\t}\n\t\t/*for (int msk=0; msk<sz; msk++) {\n\t\t\tdouble p = 1;\n\t\t\tint cnt = 0;\n\t\t\tfor (int i=0; i<n; i++)\n\t\t\t\tif ((msk&(1<<i))>0) {\t\t\t\t\t\n\t\t\t\t\tp *= (100-a[i])/100.0;\n\t\t\t\t} else {\n\t\t\t\t\tp *= a[i]/100.0;\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\tif (cnt>n/2) res += p; else res += p*kill[msk];\n\t\t}\n\t\tres /= sz;*/\n\t\t\n\t\tfor (int msk=0; msk<sz; msk++){\n\t\t\tif (n-Integer.bitCount(msk) > n/2) res += dp1[msk]; else res += dp1[msk]*kill[msk]; \n\t\t}\n\t\t\t\n\t\treturn res;\n\t\t\n\t}\n\tvoid gen(int n, int k) {\n\t\tif (n==0) {\n\t\t\tconf[0] = k;\n\t\t\t//conf[0] = 2; conf[1] = 1; conf[2] = 3;\n\t\t\tdouble x = solv();\n\t\t\tif (x>best) best = x;\n\t\t\treturn;\n\t\t\t\n\t\t}\n\t\tfor (int i=0; i<=k; i++) {\n\t\t\tconf[n] = i;\n\t\t\tgen(n-1, k-i);\n\t\t}\n\t\tconf[n] = 0;\n\t}\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tk = nextInt();\n\t\tA = nextInt();\n\t\tB = new int[n];\n\t\tL = new int[n];\n\t\tfor (int i=0; i<n; i++) {\n\t\t\tB[i] = nextInt();\n\t\t\tL[i] = nextInt();\n\t\t}\n\t\tsz = 1<<n;\n\t\tconf = new int[n];\n\t\tkill = new double[sz];\n\t\tfor (int msk=0; msk<sz; msk++) {\n\t\t\tint sum = 0;\n\t\t\tfor (int i=0; i<n; i++)\n\t\t\t\tif ((msk&(1<<i))>0) {\n\t\t\t\t\tsum += B[i];\n\t\t\t\t}\n\t\t\tkill[msk] = A*1./(A+sum);\n\t\t}\n\t\tgen(n-1, k);\n\t\tout.printf(Locale.US, \"%1.9f\", best);\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\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\t\t\t// br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t\tbr.close();\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(123);\n\t\t}\n\t}\n\n\tString next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString s = br.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(s,\", \\t\");\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\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\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\n}\n", "complexity": "np", "problem": "105_B. Dark Assembly", "from": "CODEFORCES"}
{"src": "//package contest10D;\nimport java.math.*;\nimport java.util.*;\nimport static java.math.BigInteger.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class Main {\n\tstatic void debug(Object... os) {\n\t\tSystem.err.println(deepToString(os));\n\t}\n\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(),m=sc.nextInt();\n\t\tboolean[][] bs=new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint s=sc.nextInt()-1,t=sc.nextInt()-1;\n\t\t\tbs[s][t] = bs[t][s] = true;\n\t\t}\n\t\tlong res = 0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tres += calc(bs,n-1-i);\n\t\t}\n\t\tSystem.out.println(res/2);\n\t}\n\tlong calc(boolean[][] bs,int n){//start is n.\n\t\tlong[][] dp=new long[1<<n][n]; // set,last -> number of path n -> last.\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(bs[i][n])\n\t\t\t\tdp[1<<i][i] ++;\n\t\t}\n\t\tfor(int i=1;i<1<<n;i++){\n\t\t\tfor(int j=0;j<n;j++)if(((i>>j)&1)==1)\n\t\t\t\tfor(int k=0;k<n;k++)if(((i>>k)&1)==0 && bs[j][k]){//add\n\t\t\t\t\tdp[i|(1<<k)][k] += dp[i][j];\n\t\t\t\t}\n\t\t}\n\t\tlong res=0;\n\t\tfor(int i=0;i<1<<n;i++)for(int j=0;j<n;j++)if(Integer.bitCount(i)>=2&&bs[j][n])res+=dp[i][j];\n\t\treturn res;\n\t}\n\t\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\n\timport java.awt.List;\n\timport java.io.IOException;\n\timport java.io.InputStream;\n\timport java.io.OutputStream;\n\timport java.io.PrintWriter;\n\timport java.math.BigDecimal;\n\timport java.math.BigInteger;\n\timport java.text.DecimalFormat;\n\timport java.util.ArrayList;\n\timport java.util.Arrays;\n\timport java.util.HashMap;\n\timport java.util.InputMismatchException;\n\timport java.util.Locale;\n\timport java.util.TimeZone;\n\t\n\tpublic class Cycle {\n\t\n\t\tpublic static void main(String[] args) {\n\t\t\tLocale.setDefault(Locale.US);\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\tPrintWriter out = new PrintWriter(outputstream);\n\t\t\tTaskA solver = new TaskA();\n\t\t\t// int testcase = in.ni();\n\t\t\tfor (int i = 0; i < 1; i++)\n\t\t\t\tsolver.solve(i, in, out);\n\t\t\tout.close();\n\t\n\t\t}\n\t\n\t}\n\t\n\tclass TaskA {\n\t\n\t\tpublic void solve(int testnumber, FastReader in, PrintWriter out) {\n\t\n\t\t\tint n = in.ni();\n\t\t\tint m = in.ni();\n\t\n\t\t\tboolean graph[][] = new boolean[n][n];\n\t\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tint a = in.ni() - 1;\n\t\t\t\tint b = in.ni() - 1;\n\t\n\t\t\t\tgraph[a][b] = true;\n\t\t\t\tgraph[b][a] = true;\n\t\t\t}\n\t\n\t\t\t/*\n\t\t\t * dp[mask][i] be the number of Hamiltonian walks over the subset mask,\n\t\t\t * starting at the vertex first(mask) and ending at the vertex i\n\t\t\t */\n\t\n\t\t\tlong dp[][] = new long[1 << n][n];\n\t\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tdp[1 << i][i] = 1;\n\t\t\t}\n\t\n\t\t\tlong answer = 0;\n\t\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\t\tint start = Integer.numberOfTrailingZeros(mask);\n\t\t\t\t\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\tcontinue;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tfor (int j = start + 1; j < n; j++) {\n\t\t\t\t\t\tif (graph[i][j] && (mask & (1 << j)) == 0) {\n\t\t\t\t\t\t\tdp[mask + (1 << j)][j] += dp[mask][i];\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t}\n\t\t\t\t\tif (graph[i][start]) {\n\t\t\t\t\t\tanswer += dp[mask][i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\n\t\t\t}\n\t\n\t\t\tout.println((answer - m) / 2);\n\t\t}\n\t}\n\t\n\tclass FastReader {\n\t\tpublic 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\n\t\tpublic FastReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\t\n\t\tpublic FastReader() {\n\t\n\t\t}\n\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\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\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\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\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 isWhitespace(c);\n\t\t}\n\t\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\t\n\t\tpublic int[] iArr(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\t\n\t\tpublic String next() {\n\t\t\treturn ns();\n\t\t}\n\t\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t\n\t}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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 Darshandarji\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            int m = in.nextInt();\n            boolean[][] g = new boolean[n][n];\n            for (int i = 0; i < m; ++i) {\n                int a = in.nextInt() - 1;\n                int b = in.nextInt() - 1;\n                g[a][b] = true;\n                g[b][a] = true;\n            }\n        /*for (int i = 0; i < n; ++i)\n            for (int j = 0; j < n; ++j)\n                g[i][j] = true;*/\n            long[] am = new long[n + 1];\n            long[][] ways = new long[1 << n][n];\n            for (int start = 0; start < n; ++start) {\n                for (int mask = 0; mask < (1 << (n - start)); ++mask)\n                    for (int last = start; last < n; ++last) {\n                        ways[mask][last - start] = 0;\n                    }\n                ways[1][0] = 1;\n                for (int mask = 0; mask < (1 << (n - start)); ++mask) {\n                    int cnt = 0;\n                    int tmp = mask;\n                    while (tmp > 0) {\n                        ++cnt;\n                        tmp = tmp & (tmp - 1);\n                    }\n                    for (int last = start; last < n; ++last)\n                        if (ways[mask][last - start] > 0) {\n                            long amm = ways[mask][last - start];\n                            for (int i = start; i < n; ++i)\n                                if ((mask & (1 << (i - start))) == 0 && g[last][i]) {\n                                    ways[mask | (1 << (i - start))][i - start] += amm;\n                                }\n                            if (g[last][start])\n                                am[cnt] += ways[mask][last - start];\n                        }\n                }\n            }\n            long res = 0;\n            for (int cnt = 3; cnt <= n; ++cnt) {\n                if (am[cnt] % (2) != 0)\n                    throw new RuntimeException();\n                res += am[cnt] / (2);\n            }\n            out.println(res);\n        }\n\n    }\n\n    static class InputReader {\n        private InputStream stream;\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputReader.SpaceCharFilter filter;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        public int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n\n            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 boolean isSpaceChar(int c) {\n            if (filter != null)\n                return filter.isSpaceChar(c);\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        public interface SpaceCharFilter {\n            public boolean isSpaceChar(int ch);\n\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\n\n/**\n * Created by Tejas on 18-10-2018.\n */\npublic class Main {\n\n    static HashSet<Integer> adjList[];\n    public static void main(String[]args)throws IOException{\n        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder stringBuilder=new StringBuilder();\n\n        String temp[]=bufferedReader.readLine().split(\" \");\n        int V=Integer.parseInt(temp[0]);\n        int E=Integer.parseInt(temp[1]);\n        adjList=new HashSet[V];\n        for(int i=0;i<V;i++)\n            adjList[i]=new HashSet<>();\n        for(int i=0;i<E;i++){\n            temp=bufferedReader.readLine().split(\" \");\n            int x=Integer.parseInt(temp[0])-1;\n            int y=Integer.parseInt(temp[1])-1;\n            adjList[y].add(x);\n            adjList[x].add(y);\n        }\n        stringBuilder.append(solve(V)+\"\\n\");\n        System.out.println(stringBuilder);\n    }\n\n    private static long solve(int V) {\n\n        long dp[][]=new long[(1<<V)][V];\n        long count=0;\n        for(int i=0;i<V;i++)\n            dp[(1<<i)][i]=1;\n        for(int mask=1;mask<(1<<V);mask++){\n            // HW starting at pos first and ending at j.\n            int first = Integer.numberOfTrailingZeros(mask);\n            for(int i=0;i<V;i++){\n                if((mask&(1<<i))==0 || first==i) continue;\n                for (int j = 0; j < V; j++)\n                    if (adjList[i].contains(j) && (mask & (1<<j))!=0)\n                        dp[mask][i] += dp[mask ^ (1 << i)][j];\n                //Calculating simple cycles\n                if (Integer.bitCount(mask)>=3)\n                    if(adjList[first].contains(i))\n                        count+=dp[mask][i];\n            }\n        }\n        return count/2;\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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.util.ArrayList;\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        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskD {\n        int n;\n        ArrayList<Integer>[] adj;\n        long[] mem;\n        int start;\n        long cycles(int cur, int visited) {\n            if (cur == start && visited > 0) {\n                return Integer.bitCount(visited) >= 3 ? 1 : 0;\n            }\n            int index = visited * n + cur;\n            if (mem[index] != -1) return mem[index];\n            long res = 0;\n            int newvisited = visited | (1 << cur);\n            for (int nxt : adj[cur]) {\n                if (nxt >= start && (nxt == start || ((visited >> nxt) & 1) == 0)) {\n                    res += cycles(nxt, newvisited);\n                }\n            }\n            return mem[index] = res;\n        }\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.readInt();\n            int m = in.readInt();\n            adj = new ArrayList[n];\n            mem = new long[n * (1 << n)];\n            for (int i = 0; i < adj.length; i++) adj[i] = new ArrayList<>();\n            for (int i = 0; i < m; i++) {\n                int a = in.readInt() - 1, b = in.readInt() - 1;\n                adj[a].add(b);\n                adj[b].add(a);\n            }\n            long res = 0;\n            for (int start = 0; start < n; start++) {\n                Arrays.fill(mem, -1);\n                this.start = start;\n                res += cycles(start, 0) / 2;\n            }\n            out.printLine(res);\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(long 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}\n\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\n\tboolean[][] graph;\n\tpublic void run() {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\n\t\tgraph = new boolean[n][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\tgraph[a][b] = true;\n\t\t\tgraph[b][a] = true;\n\t\t}\n\n\n\t\tlong res = 0;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tres += solve(i);\n\t\t}\n\t\tSystem.out.println(res);\n\n\t}\n\n\tlong solve(int n) {\n\t\t// [0, n)\u306e\u9802\u70b9\u3060\u3051\u3067\u3001n-1 \u30b9\u30bf\u30fc\u30c8\u3060\u3051\u8003\u3048\u308b\n\t\tlong[][] dp = new long[1 << n][n];\n\t\tdp[1 << (n-1)][n-1] = 1;\n\n\t\tfor (int i = 0; i < (1 << n); ++i) {\n\t\t\tfor (int l = 0; l < n; ++l) if (dp[i][l] > 0) {\n\t\t\t\tfor (int x = 0; x < n - 1; ++x) if (graph[l][x] && (i >> x & 1) == 0) {\n\t\t\t\t\tdp[i | (1 << x)][x] += dp[i][l];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < (1 << n); ++i) if (Integer.bitCount(i) >= 3) {\n\t\t\tfor (int l = 0; l < n; ++l) {\n\t\t\t\tif (graph[l][n-1]) res += dp[i][l];\n\t\t\t}\n\t\t}\n\t\treturn res / 2; // n-1 \u3092\u542b\u3080\u30b5\u30a4\u30af\u30eb\u3092\u53f3\u56de\u308a\u3068\u5de6\u56de\u308a\u6570\u3048\u3066\u3057\u307e\u3063\u305f\u306e\u3067\uff12\u3067\u5272\u308b\n\t}\n\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\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        \n        boolean[][] graph = new boolean[n][n];\n        \n        for(int i = 0; i < m; i++) {\n            int from = in.nextInt() - 1;\n            int to = in.nextInt() - 1;\n            graph[from][to] = true;\n            graph[to][from] = true;\n        }\n\n        int max = 1 << n;\n        long[][] dp = new long[max][n];\n        for(int mask = 1; mask < max; mask++) {\n            for(int i = 0; i < n; i++) {\n                int countMask = Integer.bitCount(mask); \n                boolean existSubSeti = (mask & (1 << i)) > 0;\n                if(countMask == 1 && existSubSeti) {\n                    dp[mask][i] = 1; \n                }\n                else if(countMask > 1 && existSubSeti) {\n                    int mask1 = mask ^ (1 << i);\n                    for(int j = 0; j < n; j++) {\n                        if(((mask1 & (1 << j)) > 0) && graph[j][i] && i != firstMask(mask, n)) {\n                            dp[mask][i] += dp[mask1][j]; \n                        }\n                    }\n                }\n            }\n        }\n        \n        long counter = 0; \n        for(int mask = 1; mask < max; mask++) {\n            for(int i = 0; i < n; i++) {\n                if(Integer.bitCount(mask) >= 3 && graph[firstMask(mask, n)][i]) {\n                    counter += dp[mask][i];\n                }\n            }\n            \n        }\n        System.out.println(counter / 2);\n        in.close();\n    }\n    \n    public static int firstMask(int mask, int n) { \n        for(int i = 0; i < n; i++) {\n            if((mask & (1 << i)) > 0) return i;\n        }\n        return -1;\n        \n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Solution {\n    public void doMain() throws Exception {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt(), m = sc.nextInt();\n        boolean[][] adj = new boolean[n][n];\n        for (int i=0; i<m; i++) {\n            int a = sc.nextInt()-1, b = sc.nextInt()-1;\n            adj[a][b] = adj[b][a] = true;\n        }\n        \n        long res = 0;\n        \n        for (int st=0; st+1<n; st++) {\n            //System.out.println(\"st=\"+st);\n            long[][] numWays = new long[1<<(n-st-1)][n-st-1];\n            for (int i=st+1; i<n; i++)\n                if (adj[st][i]) numWays[1<<(i-st-1)][i-st-1] = 1;\n            \n            for (int mask=1; mask < (1<<(n-st-1)); mask++) {\n                boolean simple = ((mask & (mask-1)) == 0);\n                for (int last=0; last<n-st-1; last++) if (numWays[mask][last]!=0) {\n                    if (adj[last+st+1][st] && !simple) res += numWays[mask][last];\n                    for (int next=0; next<n-st-1; next++)\n                        if (adj[last+st+1][next+st+1] && (mask & (1<<next)) == 0)\n                            numWays[mask | (1<<next)][next] += numWays[mask][last];\n                }\n            }\n        }\n        \n        System.out.println(res/2);\n    }\n    public static void main(String[] args) throws Exception {\n        (new Solution()).doMain();\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Scanner;\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        \n        boolean[][] graph = new boolean[n][n];\n        \n        for(int i = 0; i < m; i++) {\n            int from = in.nextInt() - 1;\n            int to = in.nextInt() - 1;\n            graph[from][to] = true;\n            graph[to][from] = true;\n        }\n\n        int max = 1 << n;\n        long[][] dp = new long[max][n];\n        for(int mask = 1; mask < max; mask++) {\n            for(int i = 0; i < n; i++) {\n                int countMask = Integer.bitCount(mask); \n                boolean existSubSeti = (mask & (1 << i)) > 0;\n                if(countMask == 1 && existSubSeti) {\n                    dp[mask][i] = 1; \n                }\n                else if(countMask > 1 && existSubSeti) {\n                    int mask1 = mask ^ (1 << i);\n                    for(int j = 0; j < n; j++) {\n                        if(graph[j][i] && i != firstMask(mask, n)) {\n                            dp[mask][i] += dp[mask1][j]; \n                        }\n                    }\n                }\n            }\n        }\n        \n        long counter = 0; \n        for(int mask = 1; mask < max; mask++) {\n            for(int i = 0; i < n; i++) {\n                if(Integer.bitCount(mask) >= 3 && graph[firstMask(mask, n)][i]) {\n                    counter += dp[mask][i];\n                }\n            }\n            \n        }\n        System.out.println(counter / 2);\n        in.close();\n    }\n    \n    public static int firstMask(int mask, int n) { \n        for(int i = 0; i < n; i++) {\n            if((mask & (1 << i)) > 0) return i;\n        }\n        return -1;\n        \n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 12/31/10\n * Time: 1:30 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class SimpleCycle {\n\n\tint first(int x){\n\t\treturn x - (x & (x - 1));\n\t}\n\n    void run(){\n\t\tint N = nextInt(), M = nextInt();\n\t\tint[] graph = new int[N];\n\t\tfor(int i = 0; i < M; i++){\n\t\t\tint a = nextInt() - 1, b = nextInt() - 1;\n\t\t\tgraph[a] |= (1<<b);\n\t\t\tgraph[b] |= (1<<a);\n\t\t}\n\n\t\tint[] bitcount = new int[1<<N];\n\t\tfor(int i = 0; i < (1<<N); i++){\n\t\t\tbitcount[i] = bitcount[i>>1];\n\t\t\tif(i % 2 == 1) bitcount[i]++;\n\t\t}\n\n\t\tlong[][] dp = new long[1<<N][N];\n\t\tfor(long[] f : dp) Arrays.fill(f, 0);\n\t\tlong ans = 0;\n\t\tfor(int mask = 1; mask < (1<<N); mask++){\n\t\t\tfor(int i = 0; i < N; i++)if((mask & (1<<i)) > 0){\n\t\t\t\tif(bitcount[mask] == 1) dp[mask][i] = 1;\n\t\t\t\telse{\n\t\t\t\t\tif(first(mask) != (1<<i)){\n\t\t\t\t\t\tfor(int j = 0; j < N; j++)if((graph[i] & (1<<j)) > 0 && (mask & (1<<j)) > 0){\n\t\t\t\t\t\t\tdp[mask][i] += dp[mask - (1<<i)][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(bitcount[mask] >= 3 && (graph[i] & first(mask)) > 0) ans += dp[mask][i];\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ans / 2);\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 SimpleCycle().run();\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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.Set;\n\npublic class ProblemD {\n\t\n\n\t\n\tstatic int N;\n\tstatic boolean[][] graph;\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\tString[] data = s.readLine().split(\" \");\n\t\tint n = Integer.valueOf(data[0]);\n\t\tN = n;\n\t\tint m = Integer.valueOf(data[1]);\n\t\tgraph = new boolean[n][n];\n\t\tfor (int i = 0 ; i < m ; i++) {\n\t\t\tString[] line = s.readLine().split(\" \");\n\t\t\tint a = Integer.valueOf(line[0])-1;\n\t\t\tint b = Integer.valueOf(line[1])-1;\n\t\t\tgraph[a][b] = true;\n\t\t\tgraph[b][a] = true;\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tans += doit(i);\n\t\t}\n\t\tans /= 2;\n\t\t\n\t\tout.println(ans);\n\t\tout.flush();\n\t}\n\n\tstatic long doit(int n) {\n\t\tlong[][] dp = new long[1<<n][n];\n\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\tif (graph[i][n]) {\n\t\t\t\tdp[1<<i][i] = 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0 ; i < (1<<n) ; i++) {\n\t\t\tfor (int j = 0 ; j < n ; j++) {\n\t\t\t\tif (dp[i][j] >= 1) {\n\t\t\t\t\tfor (int k = 0 ; k < n ; k++) {\n\t\t\t\t\t\tif (graph[j][k] && (i & (1<<k)) == 0) {\n\t\t\t\t\t\t\tdp[i|1<<k][k] += dp[i][j];\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\tlong ret = 0;\n\t\tfor (int i = 0 ; i < (1<<n) ; i++) {\n\t\t\tif (Integer.bitCount(i) >= 2) {\n\t\t\t\tfor (int j = 0 ; j < n ; j++) {\n\t\t\t\t\tif (graph[j][n]) {\n\t\t\t\t\t\tret += dp[i][j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\t\n\tstatic void generateLarge() {\n\t\tSystem.out.println(\"19 171\");\n\t\tfor (int i = 1 ; i <= 19 ; i++) {\n\t\t\tfor (int j = i+1 ; j <= 19 ; j++) {\n\t\t\t\tSystem.out.println(i + \" \" + j);\n\t\t\t}\n\t\t}\n\t}\n\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "/**\n * JUDGE_ID : 104262PN\n * User     : \u0414\u0435\u043d\u0438\u0441\n * Date     : 09.05.11\n * Time     : 22:48\n * ICQ      : 785625\n * Email    : popokus@gmail.com\n */\n\nimport java.io.*;\n\npublic class s11_d {\n    public static void main(String[] args) throws IOException {\n        new s11_d().run();\n    }\n\n    int nextInt() throws IOException {\n        in.nextToken();\n        return (int) in.nval;\n    }\n\n    String nextString() throws IOException {\n        in.nextToken();\n        return (String) in.sval;\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/is11_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 n = nextInt();\n        int e = nextInt();\n        boolean[][] is = new boolean[n + 1][n + 1];\n        for (int i = 0; i < e;i++) {\n            int a = nextInt() - 1;\n            int b = nextInt() - 1;\n            is[a][b] = true;\n            is[b][a] = true;\n        }\n        // calculating dp\n        long[] am = new long[n + 1];\n                long[][] ways = new long[1 << (n - 1)][n];\n                for (int start = 0; start < n; ++start) {\n                    for (int mask = 0; mask < (1 << (n - start - 1)); ++mask)\n                        for (int last = start; last < n; ++last) {\n                            ways[mask][last - start] = 0;\n                        }\n                    ways[1 >> 1][0] = 1;\n                    for (int mask = 1; mask < (1 << (n - start)); mask += 2) {\n                        int cnt = 0;\n                        int tmp = mask;\n                        while (tmp > 0) {\n                            ++cnt;\n                            tmp = tmp & (tmp - 1);\n                        }\n                        for (int last = start; last < n; ++last)\n                            if (ways[mask >> 1][last - start] > 0) {\n                                long amm = ways[mask >> 1][last - start];\n                                for (int i = start; i < n; ++i)\n                                    if ((mask & (1 << (i - start))) == 0 && is[last][i]) {\n                                        ways[(mask | (1 << (i - start))) >> 1][i - start] += amm;\n                                    }\n                                if (is[last][start])\n                                    am[cnt] += ways[mask >> 1][last - start];\n                            }\n                    }\n                }\n                long res = 0;\n                for (int cnt = 3; cnt <= n; ++cnt) {\n                    if (am[cnt] % (2) != 0)\n                        throw new RuntimeException();\n                    res += am[cnt] / (2);\n                }\n        out.println(res);\n        out.flush();\n        out.close();\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class SimpleTask {\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 m = scan.nextInt();\n\n\t\tboolean[][] graph = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = scan.nextInt() - 1;\n\t\t\tint v = scan.nextInt() - 1;\n\t\t\tgraph[u][v] = true;\n\t\t\tgraph[v][u] = true;\n\t\t}\n\n\t\tlong[][] dp = new long[1 << n][n];\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tdp[1 << i][i] = 1;\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\n\t\t\tint first = Integer.numberOfTrailingZeros(mask);\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((mask & (1 << i)) == 0 || first == i)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (graph[i][j])\n\t\t\t\t\t\tdp[mask][i] += dp[mask ^ 1 << i][j];\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tlong answer = 0;\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tif (Integer.bitCount(mask) < 3)\n\t\t\t\tcontinue;\n\n\t\t\tint first = Integer.numberOfTrailingZeros(mask);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (graph[first][i])\n\t\t\t\t\tanswer += dp[mask][i];\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(answer / 2);\n\t\tscan.close();\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tvoid realSolve() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] f = new boolean[n][n];\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\tf[fr][to] = f[to][fr] = true;\n\t\t}\n\t\tlong[][] dp = new long[n][1 << n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tdp[i][1 << i] = 1;\n\t\tlong res = 0;\n\t\tint[] len = new int[n + 1];\n\t\tfor (int st = 0; st < 1 << n; st++) {\n\t\t\tint from = Integer.lowestOneBit(st);\n\t\t\tfor (int i =0; i < n;i++)\n\t\t\t\tif (((1<<i) & st) != 0) {\n\t\t\t\t\tfrom =i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tfor (int to = 0; to < n; to++)\n\t\t\t\tif (dp[to][st] != 0)\n\t\t\t\t\tfor (int next = from; next < n; next++)\n\t\t\t\t\t\tif (f[to][next]\n\t\t\t\t\t\t\t\t&& ((((1 << next) & st) == 0) || next == from))\n\t\t\t\t\t\t\tif (next == from) {\n\t\t\t\t\t\t\t\tif (Integer.bitCount(st) > 2) {\n\t\t\t\t\t\t\t\t\tres += dp[to][st];\n\t\t\t\t\t\t\t\t\tlen[Integer.bitCount(st)] += dp[to][st];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tdp[next][st | (1 << next)] += dp[to][st];\n\t\t\t\t\t\t\t}\n\t\t}\n\t\tout.println(res / 2);\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}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class SimpleTask {\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 m = scan.nextInt();\n\n\t\tboolean[][] graph = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = scan.nextInt() - 1;\n\t\t\tint v = scan.nextInt() - 1;\n\t\t\tgraph[u][v] = true;\n\t\t\tgraph[v][u] = true;\n\t\t}\n\n\t\tlong[][] dp = new long[1 << n][n];\n\t\tlong sum = 0;\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tdp[1 << i][i] = 1;\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\n\t\t\tint first = Integer.numberOfTrailingZeros(mask);\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((mask & (1 << i)) == 0 || first == i)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (graph[i][j] && (mask & (1 << j)) != 0)\n\t\t\t\t\t\tdp[mask][i] += dp[mask ^ 1 << i][j];\n\t\t\t\t}\n\n\t\t\t\tif (Integer.bitCount(mask) >= 3 && graph[i][first])\n\t\t\t\t\tsum += dp[mask][i];\n\t\t\t}\n\n\t\t}\n\n\t\tSystem.out.println(sum / 2);\n\t\tscan.close();\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport 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 x,y;\n        boolean graph[][]=new boolean[n][n];\n        for(int i=0;i<m;i++){\n            x=sc.nextInt()-1;\n            y=sc.nextInt()-1;\n            graph[x][y]=graph[y][x]=true;\n        }\n        long dp[][]=new long[1<<n][n];\n        long res=0;\n        for(int i=0;i<n;i++){\n            dp[1<<i][i]=1;\n        }\n        for(int mask=1;mask<(1<<n);mask++){\n            int first=-1;\n            for(int f=0;f<n;f++){\n                if((mask&(1<<f))!=0){\n                    first=f;\n                    break;\n                }\n            }\n            for(int i=0;i<n;i++){\n                if((mask&(1<<i))!=0&&i!=first){\n                    for(int j=0;j<n;j++){\n                        if(graph[j][i]&&((mask&1<<j)!=0)){\n                            dp[mask][i]+=dp[mask^1<<i][j];\n                        }\n                    }\n                }\n                if(Integer.bitCount(mask)>2&&graph[first][i]){\n                    res+=dp[mask][i];\n                }\n            }\n        }\n        \n        System.out.println(res/2);\n    }\n    \n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport java.lang.*;\n\n\npublic class P11D{\n\tstatic long mod=1000000007;\n\t\n    public static void main(String[] args) throws Exception{           \t\n    \tInputReader in = new InputReader(System.in);       \n    \tPrintWriter pw=new PrintWriter(System.out);   \n    \t\n    \t\n    \t//int t=in.readInt();\n        //while(t-->0)\n        //{\n    \t\n        int n=in.readInt();\n        int m=in.readInt();\n        boolean v[][]=new boolean[n][n];\n        for(int i=0;i<m;i++)\n        {\n        \tint x=in.readInt()-1;\n        \tint y=in.readInt()-1;\n        \tv[x][y]=true;\n        \tv[y][x]=true;\n        }\n    \t\n       long dp[][]=new long[1<<n][n];\n       for(int i=0;i<n;i++)\n       {\n    \t   dp[1<<i][i]=1;\n       }\n       long ans=0;\n    \tfor(int mask=1;mask<(1<<n);mask++)\n    \t{\n    \t\tint s=-1;\n    \t\tfor(int i=0;i<n;i++)\n    \t\t{\n    \t\t\tif((mask&(1<<i))!=0)\n    \t\t\t{\n    \t\t\t\ts=i;\n    \t\t\t\tbreak;\n    \t\t\t}\n    \t\t}\n    \t\tfor(int i=0;i<n;i++)\n    \t\t{\n    \t\t\tif(i!=s&&((1<<i)&mask)!=0)\n    \t\t\t{\n    \t\t\t\tfor(int j=0;j<n;j++)\n    \t\t\t\t{\n    \t\t\t\t\tif((1<<j)!=0&&i!=j&&v[i][j])\n    \t\t\t\t\t{\n    \t\t\t\t\t\tint rem=(1<<i)^mask;\n    \t\t\t\t\t\tdp[mask][i]+=dp[rem][j];\n    \t\t\t\t\t}\n    \t\t\t\t}    \t\t\t\n    \t\t\n    \t\t\t\tint c=Integer.bitCount(mask);\n    \t\t\t\tif(c>=3&&v[i][s])\n    \t\t\t\t{\n    \t\t\t\t\tans+=dp[mask][i];\n    \t\t\t\t}\n    \t\t\t}\n    \t\t}\n    \t}\n    \tans/=2;\n\t\tpw.println(ans);\t     \t\n    \t\n    \t//}\n    \t\n    \tpw.close();\n    }\n    \n\n\t\npublic static long gcd(long x,long y)\n{\n\tif(x%y==0)\n\t\treturn y;\n\telse\n\t\treturn gcd(y,x%y);\n}\npublic static int gcd(int x,int y)\n{\n\tif(x%y==0)\n\t\treturn y;\n\telse \n\t\treturn gcd(y,x%y);\n}\npublic static int abs(int a,int b)\n{\n\treturn (int)Math.abs(a-b);\n}\npublic static long abs(long a,long b)\n{\n\treturn (long)Math.abs(a-b);\n}\npublic static int max(int a,int b)\n{\n\tif(a>b)\n\t\treturn a;\n\telse\n\t\treturn b;\n}\npublic static int min(int a,int b)\n{\n\tif(a>b)\n\t\treturn b;\n\telse \n\t\treturn a;\n}\npublic static long max(long a,long b)\n{\n\tif(a>b)\n\t\treturn a;\n\telse\n\t\treturn b;\n}\npublic static long min(long a,long b)\n{\n\tif(a>b)\n\t\treturn b;\n\telse \n\t\treturn a;\n}\n\n\npublic static long pow(long n,long p,long m)\n{\n\t long  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    if(result>=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}\npublic 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;\t    \n\t    p >>=1;\n\t    n*=n;\t    \n\t}\n\treturn result;\n\n}\nstatic class Pair implements Comparable<Pair>\n{\n\tint a,b;\n\tPair (int a,int b)\n\t{\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t}\n\n\tpublic int compareTo(Pair o) {\n\t\t// TODO Auto-generated method stub\n\t\tif(this.a!=o.a)\n\t\treturn Integer.compare(this.a,o.a);\n\t\telse\n\t\t\treturn Integer.compare(this.b, o.b);\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.a == a && p.b == b;\n        }\n        return false;\n    }\n    public int hashCode() {\n        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();\n    }\n    \n} \n    \nstatic long sort(int a[])\n{  int n=a.length;\n\tint b[]=new int[n];\t\n\treturn mergeSort(a,b,0,n-1);}\nstatic long mergeSort(int a[],int b[],long left,long right)\n{ long c=0;if(left<right)\n {   long mid=left+(right-left)/2;\n\t c= mergeSort(a,b,left,mid);\n\t c+=mergeSort(a,b,mid+1,right);\n\t c+=merge(a,b,left,mid+1,right); }\t\n\treturn c;\t }\nstatic long merge(int a[],int  b[],long left,long mid,long right)\n{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;\nwhile(i<=(int)mid-1&&j<=(int)right)\n{ if(a[i]<=a[j]) {b[k++]=a[i++]; }\nelse\t{ b[k++]=a[j++];c+=mid-i;}}\nwhile (i <= (int)mid - 1)   b[k++] = a[i++]; \nwhile (j <= (int)right) b[k++] = a[j++];\nfor (i=(int)left; i <= (int)right; i++) \n\ta[i] = b[i];  return c;  }\n    \npublic static int[] radixSort(int[] f)\n{\n\tint[] to = new int[f.length];\n\t{\n\t\tint[] b = new int[65537];\n\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n\t\tint[] d = f; f = to;to = d;\n\t}\n\t{\n\t\tint[] b = new int[65537];\n\t\tfor(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\tfor(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n\t\tint[] d = f; f = to;to = d;\n\t}\n\treturn f;\n}    \nstatic  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        if (curChar >= 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//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t//StringBuilder sb=new StringBuilder(\"\");\n\t //InputReader in = new InputReader(System.in);\n\t//PrintWriter pw=new PrintWriter(System.out);\n\t//String line=br.readLine().trim();\n\t       \t\n\t//int t=Integer.parseInt(br.readLine());\n  //\twhile(t-->0)\n  \t//{\n  \t//int n=Integer.parseInt(br.readLine());\n\t//long n=Long.parseLong(br.readLine());\n\t//String l[]=br.readLine().split(\" \");\n  //int m=Integer.parseInt(l[0]);\n\t//int k=Integer.parseInt(l[1]);\n\t//String l[]=br.readLine().split(\" \");\n\t//l=br.readLine().split(\" \");\n\t/*int a[]=new int[n];\n\tfor(int i=0;i<n;i++)\n\t{\n\t\ta[i]=Integer.parseInt(l[i]);\n\t}*/\n\t   //System.out.println(\" \");\t     \t\n\t\n\t//}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\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 (adj[i][j]) {\n\t\t\t\t\t--res;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tlong[][] dp = new long[1 << (n - i)][n - i];\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tif (dp[mask][j] != 0) {\n\t\t\t\t\t\tfor (int k = 0; k < n - i; ++k) {\n\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\tdp[mask | (1 << k)][k] += dp[mask][j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (((mask >> 0) & 1) != 0) {\n\t\t\t\t\tres += dp[mask][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\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 m = scan.nextInt();\n\n\t\tboolean[][] graph = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = scan.nextInt() - 1;\n\t\t\tint v = scan.nextInt() - 1;\n\t\t\tgraph[u][v] = true;\n\t\t\tgraph[v][u] = true;\n\t\t}\n\n\t\tlong[][] dp = new long[1 << n][n];\n\t\tlong sum = 0;\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tdp[1 << i][i] = 1;\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\n\t\t\tint first = Integer.numberOfTrailingZeros(mask);\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((mask & (1 << i)) == 0 || first == i)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (graph[i][j] && (mask & (1 << j)) != 0)\n\t\t\t\t\t\tdp[mask][i] += dp[mask ^ 1 << i][j];\n\t\t\t\t}\n\n\t\t\t\tif (Integer.bitCount(mask) >= 3 && graph[i][first])\n\t\t\t\t\tsum += dp[mask][i];\n\t\t\t}\n\n\t\t}\n\n\t\tSystem.out.println(sum / 2);\n\t\tscan.close();\n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n *         Created on 14.03.2010\n */\npublic class TaskD implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\tprivate int n;\n\tprivate int m;\n\tprivate boolean[][] e;\n\tprivate long[][] qp;\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n//\t\tnew Thread(new Template()).start();\n\t\tnew TaskD().run();\n\t}\n\n\tpublic TaskD() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n//        int numTests = in.readInt();\n//        for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//        }\n\t\tn = in.readInt();\n\t\tm = in.readInt();\n\t\te = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = in.readInt() - 1;\n\t\t\tint b = in.readInt() - 1;\n\t\t\te[a][b] = e[b][a] = true;\n\t\t}\n//\t\tn = 19;\n//\t\te = new boolean[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\te[i][j] = i != j;\n//\t\t}\n\t\tint msk = (1 << n) - 1;\n\t\tqp = new long[n - 1][1 << (n - 1)];\n\t\tlong ans = 0;\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tmsk -= (1 << i);\n\t\t\tfor (int k = 0; k < i; k++)\n\t\t\t\tArrays.fill(qp[k], 0, 1 << i, -1);\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tif (e[i][j]) {\n\t\t\t\t\te[i][j] = e[j][i] = false;\n\t\t\t\t\tans += go(j, msk - (1 << j), i);\n\t\t\t\t\te[i][j] = e[j][i] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans / 2);\n\t\tout.close();\n\t}\n\n\tprivate long go(int v, int msk, int u) {\n\t\tif (qp[v][msk] != -1)\n\t\t\treturn qp[v][msk];\n\t\tqp[v][msk] = 0;\n\t\tif (e[v][u])\n\t\t\tqp[v][msk] = 1;\n\t\tfor (int i = 0; i < u; i++) {\n\t\t\tif (e[v][i] && ((msk >> i) & 1) != 0)\n\t\t\t\tqp[v][msk] += go(i, msk - (1 << i), u);\n\t\t}\n\t\treturn qp[v][msk];\n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Main {\n\tpublic static BufferedReader in;\n\tpublic static PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tboolean showLineError = true;\n\t\tif (showLineError) {\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tsolve();\n\t\t\t} catch (Exception e) {\n\t\t\t} finally {\n\t\t\t\tout.close();\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic void debug(Object... os) {\n\t\tout.println(Arrays.deepToString(os));\n\t}\n\n\tprivate static void solve() throws IOException {\n\t\tString[] line = nss();\n\t\tint n = Integer.parseInt(line[0]);\n\t\tint m = Integer.parseInt(line[1]);\n\n\t\tboolean[][] matrix = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tline = nss();\n\t\t\tint u = Integer.parseInt(line[0]) - 1;\n\t\t\tint v = Integer.parseInt(line[1]) - 1;\n\t\t\tmatrix[u][v] = matrix[v][u] = true;\n\t\t}\n\t\tlong[][] dp = new long[1<<n][n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tdp[1<<i][i]=1;\n\t\tlong ret=0;\n\t\tfor(int mask =0;mask< 1<<n;mask++){\n\t\t\tfor(int last =0;last<n;last++)\n\t\t\t\tif((mask & (1<<last))!=0){\n\t\t\t\t\tint first=-1;\n\t\t\t\t\tfor(first=0;first<n;first++)\n\t\t\t\t\t\tif((mask & (1<<first))!=0)\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\tfor(int add =first;add<n;add++)\n\t\t\t\t\t\tif((mask & (1<<add))==0 && matrix[last][add])\n\t\t\t\t\t\t\tdp[mask+ (1<<add)][add]+=dp[mask][last];\n\t\t\t\t\t\t\t\n\t\t\t\t\tif(Long.bitCount(mask)>2 && matrix[first][last])\t\n\t\t\t\t\t\tret+=dp[mask][last];\n\t\t\t\t}\n\t\t}\n\t\tout.println(ret/2L);\n\n\t}\n\n\tprivate static String[] nss() throws IOException {\n\t\treturn in.readLine().split(\" \");\n\t}\n\n\tprivate static int ni() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(in.readLine());\n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF11D {\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\tboolean[][] ee = new boolean[n][n];\n\t\twhile (m-- > 0) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint i = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tint j = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tee[i][j] = ee[j][i] = true;\n\t\t}\n\t\tlong cnt = 0;\n\t\t// how many cycles through i with intermediate vertices before i\n\t\tfor (int i = 2; i < n; i++) {\n\t\t\tlong[][] dp = new long[1 << i][i];\n\t\t\tfor (int j = 0; j < i; j++)\n\t\t\t\tdp[0][j] = ee[i][j] ? 1 : 0;\n\t\t\t// dp[b][j]: how many paths from i to j with intermediate vertices in b\n\t\t\tfor (int b = 1; b < 1 << i; b++)\n\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\tif ((b & 1 << j) > 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int k = 0; k < i; k++) {\n\t\t\t\t\t\tif ((b & 1 << k) == 0)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tif (ee[k][j])\n\t\t\t\t\t\t\tdp[b][j] += dp[b ^ 1 << k][k];\n\t\t\t\t\t}\n\t\t\t\t\tif (dp[b][j] > 0 && ee[j][i])\n\t\t\t\t\t\tcnt += dp[b][j];\n\t\t\t\t}\n\t\t}\n\t\tSystem.out.println(cnt / 2);\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.math.*;\n\npublic\tclass task\n{\n\tpublic static void\tmain(String args[])\n\t{\n\t\tScanner a = new Scanner(System.in);\n\t\t\n\t\twhile(a.hasNext())\n\t\t{\n\t\t\tint n = a.nextInt();\n\t\t\tint m = a.nextInt();\n\t\t\tif(n == 0 && m == 0) break;\n\t\t    \n\t\t\tboolean[][] adj = new boolean[n][n];\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tfor (int i = 0; i < m; ++i) {\n\t\t\t\tint x = a.nextInt();\n\t\t\t\tint y = a.nextInt();\n\t\t\t\tadj[x - 1][y - 1] = true;\n\t\t\t\tadj[y - 1][x - 1] = true;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) \n\t\t\t\tfor (int j = i + 1; j < n; ++j) \n\t\t\t\t\tif (adj[i][j]) \n\t\t\t\t\t\t--res;\n\t\t\t\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) \n\t\t\t{\n\t\t\t\tlong[][] dp = new long[n - i][1 << (n - i)];\n\t\t\t\tdp[0][0] = 1;\n\t\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) \n\t\t\t\t{\n\t\t\t\t\tfor (int j = 0; j < n - i; ++j) \n\t\t\t\t\t{\n\t\t\t\t\t\tif (dp[j][mask] != 0) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor (int k = 0; k < n - i; ++k) \n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) \n\t\t\t\t\t\t\t\t\tdp[k][mask | (1 << k)] += dp[j][mask];\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 (((mask >> 0) & 1) != 0) {\n\t\t\t\t\t\tres += dp[0][mask];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(res/2);\n\t\t}\n\t}\n}\n\t", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\n\npublic class D {\n\n    public static void main(String[] args) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int m = sc.nextInt();\n        int[][]a = new int[n][n];\n        for (int i = 1; i <= m; i++) {\n            int v1 = sc.nextInt();\n            int v2 = sc.nextInt();\n            v1--;\n            v2--;\n            a[v1][v2] = a[v2][v1] = 1;\n        }\n        long[][]dp = new long[1 << n][n];\n        for (int i = 0; i < n; i++) {\n            dp[1 << i][i] = 1;\n        }\n        for (int mask = 0; mask < (1 << n); mask++) {\n            if (Integer.bitCount(mask) > 1) {\n                for (int i = 0; i < n; i++) {\n                    if (i==Integer.numberOfTrailingZeros(mask))\n                        continue;\n                    if ((mask & (1 << i)) != 0) {\n                        for (int j = 0; j < n; j++) {\n                            if ((mask & (1 << j)) != 0 && a[j][i]==1) {\n                                dp[mask][i] += dp[(mask ^ (1 << i))][j];\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        long ans = 0;\n        for (int mask = 0; mask < (1 << n); mask++) {\n            if (Integer.bitCount(mask) >= 3) {\n                int t = Integer.numberOfTrailingZeros(mask);\n                for (int i = 0; i < n; i++) {\n                    if (a[t][i]==1)\n                        ans += dp[mask][i];\n                }\n            }\n        }\n        ans /= 2;\n        System.out.println(ans);\n    }\n}   \n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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 D11 {\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\tn = nextInt();\n\t\tm = nextInt();\n\t\t\n\t\tg = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = nextInt()-1, b = nextInt()-1;\n\t\t\tg[a][b] = g[b][a] = true;\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tfor (int i = n; i > 0; i--) {\n\t\t\t//long cur = solve(i);\n\t\t\tlong cur = calc(g, i-1);\n\t\t\tans += cur;\n\t\t}\n\t\t\n\t\tout.println(ans/2);\n\t\t\n\t\tout.flush();\n\t}\n\n\tstatic int n, m, V;\n\tstatic boolean[][] g;\n\t\n\t/*static long solve(int V) {\n\t\tint v = V-1;\n\t\tlong[][] memo = new long[V][1 << V];\n\t\t\n\t\tmemo[v][1 << v] = 1;\n\t\tfor (int mask = 1; mask < (1 << V); mask++)\n\t\t\tfor (int i = 0; i < V; i++) if ((mask&(1 << i)) != 0)\n\t\t\t\tfor (int j = 0; j < V; j++) if (g[i][j] && (mask&(1 << j)) == 0)\n\t\t\t\t\tmemo[j][mask|(1 << j)] += memo[i][mask];\n\t\t\n\t\tlong res = 0;\n\t\tfor (int mask = 1; mask < (1 << V); mask++)\n\t\t\tfor (int i = 0; i < V; i++)\n\t\t\t\tif (Integer.bitCount(mask) > 2 && g[v][i]) res += memo[i][mask];\n\t\treturn res/2;\n\t}*/\n\t\n\tstatic long calc(boolean[][] bs,int n){\n        long[][] dp=new long[1<<n][n];\n        for(int i=0;i<n;i++){\n                if(bs[i][n])\n                        dp[1<<i][i] ++;\n        }\n        for(int i=1;i<1<<n;i++){\n                for(int j=0;j<n;j++)if(((i>>j)&1)==1)\n                        for(int k=0;k<n;k++)if(((i>>k)&1)==0 && bs[j][k]){//add\n                                dp[i|(1<<k)][k] += dp[i][j];\n                        }\n        }\n        long res=0;\n        for(int i=0;i<1<<n;i++)for(int j=0;j<n;j++)if(Integer.bitCount(i)>=2&&bs[j][n])res+=dp[i][j];\n        return res;\n}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\n\t\t}\n\t\tfinal long[][] dp = new long[1 << n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tdp[mask][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tif (dp[mask][j] != 0) {\n\t\t\t\t\t\tlong am = dp[mask][j];\n\t\t\t\t\t\tfor (int k = 0; k < n - i; ++k) {\n\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\tdp[mask | (1 << k)][k] += am;\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 (((mask >> 0) & 1) != 0) {\n\t\t\t\t\tres += dp[mask][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println((res - m) / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Created by Darren on 14-10-21.\n */\npublic class D {\n    Reader in = new Reader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) throws IOException {\n        new D().run();\n    }\n\n    int n, m;\n    boolean[][] adjacency;\n\n    void run() throws IOException {\n        n = in.nextInt();\n        m = in.nextInt();\n        adjacency = new boolean[n+1][n];\n        for (int i = 0; i < m; i++) {\n            int u = in.nextInt(), v = in.nextInt();\n            adjacency[u-1][v-1] = adjacency[v-1][u-1] = true;\n        }\n\n        final int MAX_MASK = (1 << n) - 1;\n        long[][] dp = new long[MAX_MASK+1][n];\n        for (int i = 0; i < n; i++)\n            dp[1<<i][i] = 1;\n        long sum = 0;\n        for (int mask = 1; mask <= MAX_MASK; mask++) {\n            int lowestBit = first(mask);\n            for (int i = 0; i < n; i++) {\n                if (bit(i, mask) && i != lowestBit) {\n                    for (int j = 0; j < n; j++) {\n                        if (adjacency[j][i]) {\n                            dp[mask][i] += dp[mask^(1<<i)][j];\n                        }\n                    }\n                    if (count(mask) >= 3 && adjacency[lowestBit][i])\n                        sum += dp[mask][i];\n                } else {\n                    // dp[mask][i] = 0\n                }\n            }\n        }\n\n        out.println(sum / 2);\n        out.flush();\n    }\n\n    int count(int mask) {\n        int count = 0;\n        while (mask > 0) {\n            if ((mask & 1) == 1)\n                count++;\n            mask >>= 1;\n        }\n        return count;\n    }\n\n    int first(int mask) {\n        int index = 0;\n        while (mask > 0) {\n            if ((mask & 1) == 1)\n                return index;\n            mask >>= 1;\n            index++;\n        }\n        return -1;\n    }\n\n    boolean bit(int index, int mask) {\n        return ((1 << index) & mask) > 0;\n    }\n\n    static class Reader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        public Reader(InputStream input) {\n            reader = new BufferedReader(new InputStreamReader(input));\n            tokenizer = new StringTokenizer(\"\");\n        }\n\n        /** get next word */\n        String nextToken() 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        String readLine() throws IOException {\n            return reader.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}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\tstatic int N, M;\n\tstatic long[] C;\n\tstatic int[][] g;\n\tstatic long[][] DP;\n\tpublic static void main(String[] args) {\n\t\tInputReader r = new InputReader(System.in);\n\t\t\n\t\tN = r.nextInt();\n\t\tM = r.nextInt();\n\t\t\n\t\tg = new int[N][N];\n\t\t\n\t\tC = new long[N + 1];\n\t\t\n\t\tDP = new long[1 << N][N];\n\t\t\n\t\tfor(int k = 0; k < M; k++){\n\t\t\tint i = r.nextInt() - 1;\n\t\t\tint j = r.nextInt() - 1;\n\t\t\t\n\t\t\tg[i][j] = g[j][i] = 1;\n\t\t}\n\t\t\n\t\tfor(long[] i : DP)\n\t\t\tArrays.fill(i, -1);\n\t\t\n\t\tlong ret = 0;\n\t\tfor(int s = 0; s < N; s++){\n\t\t\tret += go(s, 1 << s, s);\n\t\t}\n\t\t\n\t\tSystem.out.println(ret / 2);\n\t}\n\t\n\tprivate static long go(int s, int m, int e) {\n\t\tif(DP[m][e] != -1)return DP[m][e];\n\t\t\n\t\tlong cnt = 0;\n\t\tfor(int j = s; j < N; j++)if(g[e][j] == 1){\n\t\t\tif((m & (1 << j)) != 0){\n\t\t\t\tif(s == j && Integer.bitCount(m) >= 3){\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tcnt += go(s, m | 1 << j, j);\n\t\t\t}\n\t\t}\n\n\t\treturn DP[m][e] = cnt;\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 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\t\t\n\t\tpublic double nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class D implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew D().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\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\tvoid solve() {\n\t\t// long time = System.currentTimeMillis();\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tboolean[][] edges = new boolean[n][n];\n\t\tboolean[] edge = new boolean[(n << 5) | n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint x = nextInt() - 1;\n\t\t\tint y = nextInt() - 1;\n\t\t\tedges[x][y] = edges[y][x] = true;\n\t\t\tedge[(x << 5) | y] = edge[(y << 5) | x] = true;\n\t\t}\n\t\tlong[][] dp = new long[n][1 << n];\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int mask2 = 1; mask2 < 1 << (n - i - 1); ++mask2) {\n\t\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\t\tdp[j][mask2 << i << 1] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (edges[i][j]) {\n\t\t\t\t\tdp[j][1 << j] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int mask2 = 1; mask2 < 1 << (n - i - 1); ++mask2) {\n\t\t\t\tint mask = (mask2 << i << 1);\n\t\t\t\tif ((mask & (mask - 1)) == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\t\tif (((mask >> j) & 1) == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tdp[j][mask] = 0;\n\t\t\t\t\tfor (int k = i + 1; k < n; k++) {\n\t\t\t\t\t\tif (((mask >> k) & 1) == 0 || !edge[(j << 5) | k]) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdp[j][mask] += dp[k][mask & ~(1 << j)];\n\t\t\t\t\t}\n\t\t\t\t\tif (edge[(i << 5) | j]) {\n\t\t\t\t\t\tans += dp[j][mask];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tif (n >= 3) {\n//\t\t\tif (edges[n - 3][n - 2] && edges[n - 3][n - 1]\n//\t\t\t\t\t&& edges[n - 2][n - 1]) {\n//\t\t\t\tans += 2;\n//\t\t\t}\n//\t\t}\n\t\tout.println(ans / 2);\n\t\t// System.err.println(System.currentTimeMillis() - time);\n\n\t\t// out.println(19 + \" \" + 19 * 9);\n\t\t// for (int i = 0; i < 19; ++i) {\n\t\t// for (int j = i + 1; j < 19; ++j) {\n\t\t// out.println((i + 1) + \" \" + (j + 1));\n\t\t// }\n\t\t// }\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.net.Inet4Address;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Created by shirsh.bansal on 07/08/16.\n */\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        FastScanner scanner = new FastScanner();\n\n        int n = scanner.nextInt();\n        int m = scanner.nextInt();\n\n        boolean graph[][] = new boolean[n][n];\n        for (int i = 0; i < m; i++) {\n            int a = scanner.nextInt();\n            int b = scanner.nextInt();\n            graph[a-1][b-1] = true;\n            graph[b-1][a-1] = true;\n        }\n\n        if(n <= 2) {\n            System.out.println(0);\n            return;\n        }\n\n        long dp[][] = new long[1<<n][n];\n\n        for (int i = 0; i < (1<<n); i++) {\n            Arrays.fill(dp[i], -1);\n        }\n\n        for (int i = 1; i < (1<<n); i++) {\n            for (int j = 0; j < n; j++) {\n                f(i, j, dp, graph, n);\n            }\n        }\n\n        long sum = 0;\n\n//        for (int i = 7; i < (1 << n); i++) {\n//            if(Integer.bitCount(i) < 3) continue;\n//            for (int j = 0; j < n; j++) {\n//                int startNode = Integer.numberOfTrailingZeros(Integer.highestOneBit(i));\n//                int endNode = j;\n//\n//                if(graph[startNode][endNode] && dp[i][j] != -1) {\n////                    System.out.println(i + \" \" + startNode + \" \" + endNode + \" \" + dp[i][j]);\n//                    sum += dp[i][j];\n//                }\n//            }\n//        }\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < (1 << n); j++) {\n                if(Integer.bitCount(j) >= 3 && graph[Integer.numberOfTrailingZeros(j)][i]) {\n                    sum += dp[j][i];\n                }\n            }\n        }\n\n        System.out.println(sum/2);\n    }\n\n    private static long f(int mask, int i, long[][] dp, boolean[][] graph, int n) {\n        if(dp[mask][i] != -1) return dp[mask][i];\n        if(Integer.bitCount(mask) == 1 && (mask&(1<<i)) != 0) {\n            dp[mask][i] = 1;\n        } else if(Integer.bitCount(mask) > 1 && (mask&(1<<i)) != 0 && i != Integer.numberOfTrailingZeros(mask)) {\n            dp[mask][i] = 0;\n            for (int j = 0; j < n; j++) {\n                if(graph[i][j]) dp[mask][i] = dp[mask][i] + f(mask^(1<<i), j, dp, graph, n);\n            }\n        } else {\n            dp[mask][i] = 0;\n        }\n\n//        int tmpMask = mask ^ (1<<i);\n//        for (int j = 0; j <= firstNode; j++) {\n//            if(((1<<j)&tmpMask) != 0 && graph[i][j]) {\n//                dp[mask][i] += f(tmpMask, j, dp, graph, n, firstNode);\n//            }\n//        }\n//\n        return dp[mask][i];\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\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}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n\tInputStream fin = System.in;\n\t//fin = new FileInputStream(\"in.txt\");\n\tScanner cin = new Scanner(fin);\n\n\tint n = cin.nextInt();\n\tint m = cin.nextInt();\n\tint bound = 1 << n;\n\tboolean[][] mp = new boolean[n][n];\n\tlong[][] dp = new long[bound][n];\n\tint used = 0;\n\tlong ret = 0;\n\tfor (int i = 0; i < n; i++) {\n\t    Arrays.fill(mp[i], false);\n\t}\n\n\tfor (int i = 0; i < m; i++) {\n\t    int u = cin.nextInt() - 1;\n\t    int v = cin.nextInt() - 1;\n\t    mp[u][v] = mp[v][u] = true;\n\t}\n\n\tfor (int k = 0; k < n; k++) {\n\t    for (int i = k; i < bound; i++) {\n\t\tArrays.fill(dp[i], 0);\n\t    }\n\t    dp[1 << k][k] = 1;\n\t    for (int mask = 1 << k; mask < bound; mask++) {\n\t\tif ((mask & used) != 0)\n\t\t    continue;\n\t\tfor (int i = k; i < n; i++) {\n\t\t    if (dp[mask][i] != 0) {\n\t\t\tif (mp[k][i] && bitcount(mask) > 2)\n\t\t\t    ret += dp[mask][i];\n\t\t\tfor (int j = k; j < n; j++) {\n\t\t\t    if ((mask & (1 << j)) == 0 && mp[i][j]) {\n\t\t\t\tdp[mask ^ (1 << j)][j] += dp[mask][i];\n\t\t\t    }\n\t\t\t}\n\t\t    }\n\t\t}\n\t    }\n\t    used |= 1 << k;\n\t}\n\n\tSystem.out.println(ret / 2);\n\n\tfin.close();\n\tcin.close();\n    }\n\n    private static int bitcount(int mask) {\n\t// TODO Auto-generated method stub\n\tint ret = 0;\n\twhile (mask > 0) {\n\t    ret += mask & 1;\n\t    mask >>= 1;\n\t}\n\treturn ret;\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Template implements Runnable {\n    private void solve() throws IOException {\n        int n = nextInt();\n        int m = nextInt();\n        boolean[][] g = new boolean[n][n];\n        for (int i = 0; i < m; ++i) {\n            int a = nextInt() - 1;\n            int b = nextInt() - 1;\n            g[a][b] = true;\n            g[b][a] = true;\n        }\n        /*for (int i = 0; i < n; ++i)\n            for (int j = 0; j < n; ++j)\n                g[i][j] = true;*/\n        long[] am = new long[n + 1];\n        long[][] ways = new long[1 << n][n];\n        for (int start = 0; start < n; ++start) {\n            for (int mask = 0; mask < (1 << (n - start)); ++mask)\n                for (int last = start; last < n; ++last) {\n                    ways[mask][last - start] = 0;\n                }\n            ways[1][0] = 1;\n            for (int mask = 0; mask < (1 << (n - start)); ++mask) {\n                int cnt = 0;\n                int tmp = mask;\n                while (tmp > 0) {\n                    ++cnt;\n                    tmp = tmp & (tmp - 1);\n                }\n                for (int last = start; last < n; ++last)\n                    if (ways[mask][last - start] > 0) {\n                        long amm = ways[mask][last - start]; \n                        for (int i = start; i < n; ++i)\n                            if ((mask & (1 << (i - start))) == 0 && g[last][i]) {\n                                ways[mask | (1 << (i - start))][i - start] += amm;\n                            }\n                        if (g[last][start])\n                            am[cnt] += ways[mask][last - start];\n                    }\n            }\n        }\n        long res = 0;\n        for (int cnt = 3; cnt <= n; ++cnt) {\n            if (am[cnt] % (2) != 0)\n                throw new RuntimeException();\n            res += am[cnt] / (2);\n        }\n        writer.println(res);\n    }\n\n\n    public static void main(String[] args) {\n        new Template().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", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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.util.ArrayList;\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        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskD {\n        int n;\n        ArrayList<Integer>[] adj;\n        long[] mem;\n        long cycles(int cur, int start, int visited) {\n            if (cur == start && visited > 0) {\n                return Integer.bitCount(visited) >= 3 ? 1 : 0;\n            }\n            int index = n * visited + cur;\n            if (mem[index] != -1) return mem[index];\n            long res = 0;\n            int newvisited = visited | (1 << cur);\n            for (int nxt : adj[cur]) {\n                if (nxt >= start && (nxt == start || ((visited >> nxt) & 1) == 0)) {\n                    res += cycles(nxt, start, newvisited);\n                }\n            }\n            return mem[index] = res;\n        }\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.readInt();\n            int m = in.readInt();\n            adj = new ArrayList[n];\n            mem = new long[n * (1 << n)];\n            for (int i = 0; i < adj.length; i++) adj[i] = new ArrayList<>();\n            for (int i = 0; i < m; i++) {\n                int a = in.readInt() - 1, b = in.readInt() - 1;\n                adj[a].add(b);\n                adj[b].add(a);\n            }\n            long res = 0;\n            for (int start = 0; start < n; start++) {\n                Arrays.fill(mem, -1);\n                res += cycles(start, start, 0) / 2;\n            }\n            out.printLine(res);\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(long 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}\n\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class ASimpleTask\n{\n\n\n\t/************************ SOLUTION STARTS HERE ***********************/\n\n\n\n\tprivate static void solve(FastScanner s1, PrintWriter out){\n\n\t\tint V = s1.nextInt();\n\t\tint E = s1.nextInt();\n\t\tint graph[] = new int[V];\n\t\tlong DP[][] = new long[1 << V][V];\n\n\t\twhile(E-->0) {\n\t\t\tint u = s1.nextInt() - 1;\n\t\t\tint v = s1.nextInt() - 1;\n\t\t\tgraph[u] |= (1 << v);\n\t\t\tgraph[v] |= (1 << u);\n\t\t}\n\n\t\tfor(int i=0;i<V;i++)\n\t\t\tDP[1 << i][i] = 1;\n\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\tfor(int fromSet = mask ^ (1 << u);fromSet > 0; fromSet ^= Integer.lowestOneBit(fromSet)) {\n\t\t\t\t\tint v = Integer.numberOfTrailingZeros(fromSet);\n\t\t\t\t\t// System.out.printf(\"mask = %s , u = %d , v = %d\\n\" , Integer.toBinaryString(mask) , u , v);\n\t\t\t\t\tif((graph[u] & (1 << v)) != 0) \n\t\t\t\t\t\tDP[mask][u] += DP[mask ^ (1 << u)][v];\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong totalCycles = 0;\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tif(Integer.bitCount(mask) >= 3) {\n\t\t\t\tint start = Integer.numberOfTrailingZeros(mask);\n\t\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\t\tif((graph[u] & (1 << start)) != 0)\n\t\t\t\t\t\ttotalCycles += DP[mask][u];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttotalCycles /= 2;\n/*\t\tfor(long l[] : DP)\n\t\t\tout.println(Arrays.toString(l));*/\n\t\tout.println(totalCycles);\n\t}\n\n\n\n\t/************************ SOLUTION ENDS HERE ************************/\n\n\n\n\n\n\t/************************ TEMPLATE STARTS HERE *********************/\n\n\tpublic static void main(String []args) throws IOException {\n\t\tFastScanner in  = new FastScanner(System.in);\n\t\tPrintWriter out = \n\t\t\t\tnew PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); \n\t\tsolve(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}    \n\n\tstatic class FastScanner{\n\t\tBufferedReader reader;\n\t\tStringTokenizer st;\n\t\tFastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}\t\n\t\tString next()\n\t\t{while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}\t\t    \n\t\tst = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}\n\t\tString nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}\t    \t  \t\n\t\tint    nextInt()   {return Integer.parseInt(next());}\n\t\tlong   nextLong()  {return Long.parseLong(next());}\t\t\n\t\tdouble nextDouble(){return Double.parseDouble(next());}\n\t\tchar   nextChar()  {return next().charAt(0);}\n\t\tint[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}\n\t\tlong[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}\t\n\t\tint[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}\t    \t\n\t\tlong[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}\t    \t\n\t\tvoid   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}\t\t\t\t\n\t}\n\n\t/************************ TEMPLATE ENDS HERE ************************/\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class ASimpleTask\n{\n\n\n\t/************************ SOLUTION STARTS HERE ***********************/\n\t\n\tstatic long memo[][];\n\tstatic int graph[];\n\tstatic long hamiltonianPath(int mask , int u) {\n\t\tif(memo[mask][u] != -1)\n\t\t\treturn memo[mask][u];\n\t\telse if(u == Integer.numberOfTrailingZeros(mask))\n\t\t\treturn 0;\n\t\telse {\n\t\t\tlong sum = 0;\n\t\t\tfor(int fromSet = mask ^ (1 << u);fromSet > 0; fromSet ^= Integer.lowestOneBit(fromSet)) {\n\t\t\t\tint v = Integer.numberOfTrailingZeros(fromSet);\n\t\t\t\t// System.out.printf(\"mask = %s , u = %d , v = %d\\n\" , Integer.toBinaryString(mask) , u , v);\n\t\t\t\tif((graph[u] & (1 << v)) != 0) \n\t\t\t\t\tsum += hamiltonianPath(mask ^ (1 << u), v);\n\t\t\t}\n\t\t\t\n\t\t\treturn memo[mask][u] = sum;\n\t\t}\n\t}\n\n\tprivate static void solveBottomUp(FastScanner s1, PrintWriter out){\n\n\t\tint V = s1.nextInt();\n\t\tint E = s1.nextInt();\n\t\tgraph = new int[V];\n\t\tlong DP[][] = new long[1 << V][V];\n\n\t\twhile(E-->0) {\n\t\t\tint u = s1.nextInt() - 1;\n\t\t\tint v = s1.nextInt() - 1;\n\t\t\tgraph[u] |= (1 << v);\n\t\t\tgraph[v] |= (1 << u);\n\t\t}\n\n\t\tfor(int i=0;i<V;i++)\n\t\t\tDP[1 << i][i] = 1;\n\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\tfor(int fromSet = mask ^ (1 << u);fromSet > 0; fromSet ^= Integer.lowestOneBit(fromSet)) {\n\t\t\t\t\tint v = Integer.numberOfTrailingZeros(fromSet);\n\t\t\t\t\t// System.out.printf(\"mask = %s , u = %d , v = %d\\n\" , Integer.toBinaryString(mask) , u , v);\n\t\t\t\t\tif((graph[u] & (1 << v)) != 0) \n\t\t\t\t\t\tDP[mask][u] += DP[mask ^ (1 << u)][v];\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong totalCycles = 0;\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tif(Integer.bitCount(mask) >= 3) {\n\t\t\t\tint start = Integer.numberOfTrailingZeros(mask);\n\t\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\t\tif((graph[u] & (1 << start)) != 0)\n\t\t\t\t\t\ttotalCycles += DP[mask][u];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttotalCycles /= 2;\n/*\t\tfor(long l[] : DP)\n\t\t\tout.println(Arrays.toString(l));*/\n\t\tout.println(totalCycles);\n\t}\n\n\tprivate static void solveTopDown(FastScanner s1, PrintWriter out){\n\n\t\tint V = s1.nextInt();\n\t\tint E = s1.nextInt();\n\t\tgraph = new int[V];\n\t\tmemo = new long[1 << V][V];\n\t\t\n\t\tfor(long l[] : memo)\n\t\t\tArrays.fill(l, -1);\n\t\t\n\t\twhile(E-->0) {\n\t\t\tint u = s1.nextInt() - 1;\n\t\t\tint v = s1.nextInt() - 1;\n\t\t\tgraph[u] |= (1 << v);\n\t\t\tgraph[v] |= (1 << u);\n\t\t}\n\n\t\tfor(int i=0;i<V;i++)\n\t\t\tmemo[1 << i][i] = 1;\n\t\t\n\t\tlong totalCycles = 0;\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tif(Integer.bitCount(mask) >= 3) {\n\t\t\t\tint start = Integer.numberOfTrailingZeros(mask);\n\t\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\t\tif((graph[u] & (1 << start)) != 0)\n\t\t\t\t\t\ttotalCycles += hamiltonianPath(mask, u);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttotalCycles /= 2;\n\t\t\n\t\tout.println(totalCycles);\n\t}\n\n\t/************************ SOLUTION ENDS HERE ************************/\n\n\n\n\n\n\t/************************ TEMPLATE STARTS HERE *********************/\n\n\tpublic static void main(String []args) throws IOException {\n\t\tFastScanner in  = new FastScanner(System.in);\n\t\tPrintWriter out = \n\t\t\t\tnew PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); \n\t\tsolveTopDown(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}    \n\n\tstatic class FastScanner{\n\t\tBufferedReader reader;\n\t\tStringTokenizer st;\n\t\tFastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}\t\n\t\tString next()\n\t\t{while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}\t\t    \n\t\tst = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}\n\t\tString nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}\t    \t  \t\n\t\tint    nextInt()   {return Integer.parseInt(next());}\n\t\tlong   nextLong()  {return Long.parseLong(next());}\t\t\n\t\tdouble nextDouble(){return Double.parseDouble(next());}\n\t\tchar   nextChar()  {return next().charAt(0);}\n\t\tint[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}\n\t\tlong[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}\t\n\t\tint[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}\t    \t\n\t\tlong[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}\t    \t\n\t\tvoid   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}\t\t\t\t\n\t}\n\n\t/************************ TEMPLATE ENDS HERE ************************/\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class D {\n\n    public void run(Scanner in, PrintWriter out) {\n        int n = in.nextInt();\n        int[][] graph = new int[n][n];\n        int m = in.nextInt();\n        for (int i = 0; i < m; i++) {\n            int x = in.nextInt() - 1;\n            int y = in.nextInt() - 1;\n            graph[x][y] = 1;\n            graph[y][x] = 1;\n        }\n        long[][] dyn = new long[1 << n][n];\n        for (int i = 0; i < n; i++) {\n            dyn[1 << i][i] = 1;\n        }\n        long answer = 0;\n        for (int mask = 1; mask < 1 << n; mask++) {\n            int start = Integer.numberOfTrailingZeros(mask);\n            for (int i = 0; i < n; i++) {\n                if ((mask & (1 << i)) == 0) continue;\n                for (int j = start + 1; j < n; j++) {\n                    if (graph[i][j] > 0 && (mask & (1 << j)) == 0) {\n                        dyn[mask + (1 << j)][j] += dyn[mask][i];\n                    }\n                }\n                if (graph[i][start] > 0) {\n                    answer += dyn[mask][i];\n                }\n            }\n        }\n        out.println((answer - m)/ 2);\n    }\n\n    public static void main(String[] args) {\n        try (Scanner in = new Scanner(System.in);\n             PrintWriter out = new PrintWriter(System.out)\n        ) {\n            new D().run(in, out);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\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 (adj[i][j]) {\n\t\t\t\t\t--res;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong[][] dp = new long[1 << n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tdp[mask][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tif (dp[mask][j] != 0) {\n\t\t\t\t\t\tfor (int k = 0; k < n - i; ++k) {\n\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\tdp[mask | (1 << k)][k] += dp[mask][j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (((mask >> 0) & 1) != 0) {\n\t\t\t\t\tres += dp[mask][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\n\t\t}\n\t\tfinal long[][] dp = new long[1 << n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint Limit = 1 << (n - i);\n\t\t\tint nn = n - i;\n\t\t\tfor (int mask = 0; mask < Limit; ++mask) {\n\t\t\t\tfor (int j = 0; j < nn; ++j) {\n\t\t\t\t\tdp[mask][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < Limit; ++mask) {\n\t\t\t\tif ((mask & 1) == 0) {\n\t\t\t\t\tfor (int j = 0; j < nn; ++j) {\n\t\t\t\t\t\tif (dp[mask][j] != 0) {\n\t\t\t\t\t\t\tlong am = dp[mask][j];\n\t\t\t\t\t\t\tfor (int k = 0; k < nn; ++k) {\n\t\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\t\tdp[mask | (1 << k)][k] += am;\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} else {\n\t\t\t\t\tres += dp[mask][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println((res - m) / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Codeforces 11D - A Simple Task\n * Created by Darren on 14-10-21.\n * O(2^n * n^2) time and O(2^n * n) space.\n *\n * Tag: dynamic programming, bitmask, graph\n */\npublic class D {\n    Reader in = new Reader(System.in);\n    PrintWriter out = new PrintWriter(System.out);\n\n    public static void main(String[] args) throws IOException {\n        new D().run();\n    }\n\n    int n, m;\n    boolean[][] adjacency;  // Adjacency matrix\n\n    void run() throws IOException {\n        n = in.nextInt();\n        m = in.nextInt();\n        adjacency = new boolean[n+1][n];\n        for (int i = 0; i < m; i++) {\n            int u = in.nextInt(), v = in.nextInt();\n            adjacency[u-1][v-1] = adjacency[v-1][u-1] = true;   // Converted to 0-based\n        }\n\n        final int MASK_BOUND = (1 << n);\n\n        // dp[i][j]: the number of Hamiltonian walks over the subgraph formed by\n        // the mask i, starting at the smallest vertex and ending at vertex j\n        // dp[1<<i][i] = 1;\n        // dp[i][j] = sum_k{dp[i^j][k]} if j is within the mask i and (k,j) is an edge\n        long[][] dp = new long[MASK_BOUND][n];\n        for (int i = 0; i < n; i++)\n            dp[1<<i][i] = 1;\n\n        long sum = 0;\n        for (int mask = 1; mask < MASK_BOUND; mask++) {\n            int lowestVertex = (int) (Math.log(lowest(mask)) / Math.log(2));\n            for (int i = 0; i < n; i++) {\n                if (bit(i, mask) && i != lowestVertex) {\n                    for (int j = 0; j < n; j++) {\n                        if (adjacency[j][i]) {\n                            dp[mask][i] += dp[mask^(1<<i)][j];\n                        }\n                    }\n\n                    // A simple cycle with length not smaller than 3\n                    if (count(mask) >= 3 && adjacency[lowestVertex][i])\n                        sum += dp[mask][i];\n                } else {\n                    // dp[mask][i] = 0\n                }\n            }\n        }\n\n        out.println(sum / 2);   // A cycle is counted twice\n        out.flush();\n    }\n\n    // Return the number of '1's in the binary representation of the mask\n    int count(int mask) {\n        int count = 0;\n        while (mask > 0) {\n            if ((mask & 1) == 1)\n                count++;\n            mask >>= 1;\n        }\n        return count;\n    }\n\n    // Return an integer with only one '1' in its binary form and the position of the\n    // only '1' is the same with the lowest '1' in mask\n    int lowest(int mask) {\n        // mask = x1b where b is a sequence of zeros;\n        // -mask = x'1b', where x' and b' is formed by reversing digits in x and b;\n        // mask & (-mask) = 0...010...0, where the only 1 is the lowest 1 in mask\n        return mask & (-mask);\n    }\n\n    // Check whether the digit at the given index of the mask is '1'\n    boolean bit(int index, int mask) {\n        return ((1 << index) & mask) > 0;\n    }\n\n    static class Reader {\n        BufferedReader reader;\n        StringTokenizer tokenizer;\n\n        public Reader(InputStream input) {\n            reader = new BufferedReader(new InputStreamReader(input));\n            tokenizer = new StringTokenizer(\"\");\n        }\n\n        /** get next word */\n        String nextToken() 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        String readLine() throws IOException {\n            return reader.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}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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 * 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        TaskD solver = new TaskD();\n        solver.solve(1, in, out);\n        out.close();\n    }\n    static class TaskD {\n        int n;\n        boolean[][] adj;\n        long[] mem;\n        int start;\n        long cycles(int cur, int visited) {\n            if (cur == start && visited > 0) {\n                return Integer.bitCount(visited) >= 3 ? 1 : 0;\n            }\n            int index = visited * n + cur;\n            if (mem[index] != -1) return mem[index];\n            long res = 0;\n            int newvisited = visited | (1 << cur);\n            for (int nxt = 0; nxt < n; nxt++)\n                if (adj[cur][nxt]) {\n                    if (nxt >= start && (nxt == start || ((visited >> nxt) & 1) == 0)) {\n                        res += cycles(nxt, newvisited);\n                    }\n                }\n            return mem[index] = res;\n        }\n        public void solve(int testNumber, InputReader in, OutputWriter out) {\n            n = in.readInt();\n            int m = in.readInt();\n            mem = new long[n * (1 << n)];\n            adj = new boolean[n][n];\n            for (int i = 0; i < m; i++) {\n                int a = in.readInt() - 1, b = in.readInt() - 1;\n                adj[a][b] = true;\n                adj[b][a] = true;\n            }\n            long res = 0;\n            for (int start = 0; start < n; start++) {\n                Arrays.fill(mem, -1);\n                this.start = start;\n                res += cycles(start, 0) / 2;\n            }\n            out.printLine(res);\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(long 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}\n\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class D11 {\n\tstatic boolean[][] g;\n\tstatic int n, m;\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\tm = input.nextInt();\n\tg = new boolean[n][n];\n\tfor(int i = 0; i<m; i++)\n\t{\n\t\tint a = input.nextInt()-1, b = input.nextInt()-1;\n\t\tg[a][b] = g[b][a] = true;\n\t}\n\tlong res = 0;\n\tmap = new HashMap<Integer, Long>();\n\tfor(int i = n-1; i>=0; i--)\n\t{\n\t\tmemo = new long[i+1][1<<(i+1)];\n\t\tfor(long[] A : memo) Arrays.fill(A, -1);\n\t\tres += count(i, i, 1<<i)/2;\n\t}\n\tout.println(res);\n\tout.close();\n}\nstatic long[][] memo;\nstatic HashMap<Integer, Long> map;\nstatic long count(int at, int start, int mask)\n{\n\tif(memo[at][mask] != -1) return memo[at][mask];\n\tint bits = Integer.bitCount(mask);\n\tif(at == start && bits > 2) return 1;\n\tlong res = 0;\n\tfor(int i = 0; i<=start; i++)\n\t{\n\t\tif(!g[at][i]) continue;\n\t\tif(i != start && (mask & (1<<i)) > 0) continue;\n\t\tif(i == start && bits <= 2) continue;\n\t\tres += count(i, start, mask | (1<<i));\n\t}\n\treturn memo[at][mask] = res;\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}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile ( sc.hasNextInt() ) {\n\t\t\tint n = sc.nextInt();\n\t\t\tlong m = sc.nextInt();\n\t\t\tboolean edge[][] = new boolean[n][n];\n\t\t\tlong dp[][] = new long[1<<n][n];\n\t\t\tfor ( long i = 1 ; i<=m ; ++i ) {\n\t \t\t\tint u = sc.nextInt();   \n\t\t\t\tint v = sc.nextInt();\n\t\t\t\t-- u;\n\t\t\t\t-- v;\n\t\t\t\tedge[u][v] = edge[v][u] = true;\n\t\t\t}\n\t\t\tfor ( int i = 0 ; i<n ; ++i ) {\n\t\t\t\tdp[1<<i][i] = 1;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor ( int i = 1 ; i<(1<<n) ; ++i ) {\n\t\t\t\tint first = cal(i);\n\t\t\t\tfor ( int j = first ; j<n ; ++j ) {\n\t\t\t\t\tif ( dp[i][j]==0 ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor ( int k = first ; k<n ; ++k ) {\n \t\t\t\t\t\tif ( j==k || !edge[j][k] ) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( k==first && judge(i) ) {\n\t\t\t\t\t\t\tres += dp[i][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( (i&(1<<k))==0 ) {\n\t\t\t\t\t\t\tdp[i|(1<<k)][k] += dp[i][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(res/2);\t\t\n\t\t}\n\t}\n\tpublic static int cal( int x ) {\n\t\tint ord = 0;\n\t\twhile ( true ) {\n\t\t\tif ( (x&(1<<ord))!=0 ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++ ord;\n\t\t}\n\t\treturn ord;\n\t}\n\tpublic static boolean judge( int x ) {\n\t\tint cnt = 0;\n\t\twhile ( x>=1 ) {\n\t\t\tif ( (x&1)==1 ) {\n\t\t\t\t++ cnt;\n\t\t\t}\n\t\t\tx >>= 1;\n\t\t}\n\t\treturn cnt >= 3;\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Hello {\n\t\tpublic static void main(String[] args){\t\t\t\n\t\t\tScanner scan = new Scanner(System.in);\n\t\t\tint n = scan.nextInt();\n\t\t\tint m = scan.nextInt();\n\t\t\tboolean[][] graph = new boolean[n][n];\n\t\t\t\n\t\t\tfor(int i = 0; i < m; i++) {\n\t\t\t\tint from = scan.nextInt() - 1;\n\t\t\t\tint to = scan.nextInt() - 1;\n\t\t\t\tgraph[from][to] = graph[to][from] = true;\n\t\t\t}\n\t\t\t\n\t\t\tint max = 1 << n;\n\t\t\tlong[][] dp = new long[max][n];\n\t\t\t\n\t\t\tfor(int mask = 1; mask < max; mask++) {\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tboolean existI = (mask & (1 << i)) > 0;\n\t\t\t\t\tif(Integer.bitCount(mask) == 1 && existI) {\n\t\t\t\t\t\tdp[mask][i] = 1;\n\t\t\t\t\t} else if(Integer.bitCount(mask) > 1 && existI && first(mask) != i) {\n\t\t\t\t\t\tlong sum = 0; \n\t\t\t\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\t\t\t\tif(graph[i][j]) sum += dp[mask ^ (1 << i)][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdp[mask][i] = sum;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlong countCycles = 0;\n\t\t\tfor(int mask = 7; mask < max; mask++) {\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tif(Integer.bitCount(mask) >= 3 && graph[first(mask)][i]) {\n\t\t\t\t\t\tcountCycles += dp[mask][i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(countCycles / 2);\n\t\t}\n\t\t\n\t\t\n\t\tpublic static int first(int mask) {\n\t\t\tint i = 0;\n\t\t\twhile((mask & (1 << i++)) == 0);\n\t\t\treturn i - 1; \n\t\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "/**\n * Codeforces Beta Round #10\n * \n * @author ProjectYoung\n */\n\nimport java.util.Scanner;\n\npublic class CF11D {\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    boolean[][] map = new boolean[n][n];\n    long[][] dp = new long[1 << n][n];\n    for (int i = 0; i < m; i++) {\n      int a = sc.nextInt() - 1;\n      int b = sc.nextInt() - 1;\n      map[a][b] = map[b][a] = true;\n      dp[(1 << a) + (1 << b)][Math.max(a, b)] = 1;\n    }\n    long ans = 0;\n    for (int mask = 1; mask < (1 << n); mask++) {\n      int lowbit = 0;\n      for (; (mask & (1 << lowbit)) == 0; lowbit++);\n      for (int i = lowbit + 1; i < n; i++) {\n        if ((mask & (1 << i)) == 0) {\n          continue;\n        }\n        for (int j = lowbit + 1; j < n; j++) {\n          if ((mask & (1 << j)) == 0 || j == i) {\n            continue;\n          }\n          if (map[i][j]) {\n            dp[mask][i] += dp[mask ^ (1 << i)][j];\n          }\n        }\n        if (map[lowbit][i]) {\n          ans += dp[mask][i];\n        }\n      }\n    }\n    System.out.println((ans - m) / 2);\n    sc.close();\n  }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class D11 {\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\tn = nextInt();\n\t\tm = nextInt();\n\t\t\n\t\tg = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = nextInt()-1, b = nextInt()-1;\n\t\t\tg[a][b] = g[b][a] = true;\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tfor (int i = n-1; i >= 0; i--) {\n\t\t\tlong cur = solve(i);\n\t\t\tans += cur;\n\t\t}\n\t\t\n\t\tout.println(ans/2);\n\t\t\n\t\tout.flush();\n\t}\n\n\tstatic int n, m;\n\tstatic boolean[][] g;\n\t\n\tstatic long solve(int v) {\n\t\tlong[][] memo = new long[v][1 << v];\n\t\t\n\t\tfor (int i = 0; i < v; i++)\n\t\t\tif (g[v][i])\n\t\t\t\tmemo[i][1 << i] = 1;\n\t\t\n\t\tfor (int mask = 1; mask < (1 << v); mask++)\n\t\t\tfor (int i = 0; i < v; i++) if ((mask&(1 << i)) != 0)\n\t\t\t\tfor (int j = 0; j < v; j++) if (g[i][j] && (mask&(1 << j)) == 0)\n\t\t\t\t\tmemo[j][mask|(1 << j)] += memo[i][mask];\n\t\t\n\t\tlong res = 0;\n\t\tfor (int mask = 1; mask < (1 << v); mask++)\n\t\t\tfor (int i = 0; i < v; i++)\n\t\t\t\tif (Integer.bitCount(mask) > 1 && g[v][i]) res += memo[i][mask];\n\t\treturn res;\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\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 (adj[i][j]) {\n\t\t\t\t\t--res;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tlong[][] dp = new long[n - i][1 << (n - i)];\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tif (dp[j][mask] != 0) {\n\t\t\t\t\t\tfor (int k = 0; k < n - i; ++k) {\n\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\tdp[k][mask | (1 << k)] += dp[j][mask];\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 (((mask >> 0) & 1) != 0) {\n\t\t\t\t\tres += dp[0][mask];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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 = 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    <T> List<T>[] createGraphList(int size) {\n        List<T>[] list = new List[size];\n        for (int i = 0; i < size; i++) {\n            list[i] = new ArrayList<>();\n        }\n        return list;\n    }\n\n    public static void main(String[] args) {\n        new Template().run();\n        // new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n    }\n\n    long timeBegin, timeEnd;\n\n    void time() {\n        timeEnd = System.currentTimeMillis();\n        System.err.println(\"Time = \" + (timeEnd - timeBegin));\n    }\n\n    long memoryTotal, memoryFree;\n\n    void memory() {\n        memoryFree = Runtime.getRuntime().freeMemory();\n        System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n                + \" KB\");\n    }\n\n    public void run() {\n        try {\n            timeBegin = System.currentTimeMillis();\n            memoryTotal = Runtime.getRuntime().freeMemory();\n            init();\n            solve();\n            out.close();\n            if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n                time();\n                memory();\n            }\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(-1);\n        }\n    }\n\n    void solve() throws IOException {\n        int n = readInt();\n        int m = readInt();\n        int max = 1 << n;\n        long[][] dp = new long[n][max];\n        for (int i = 0; i < n; i++) {\n            dp[i][1 << i] = 1;\n        }\n        GraphBuilder gb = new GraphBuilder(n, m);\n        for (int i = 0; i < m; i++) {\n            gb.add(readInt() - 1, readInt() - 1);\n        }\n        int[][] graph = gb.build();\n        for (int mask = 1; mask < max; mask++) {\n            int firstBit = -1;\n            for (int i = 0; i < n; i++) {\n                if (hasBit(mask, i)) {\n                    firstBit = i;\n                    break;\n                }\n            }\n            for (int last = 0; last < n; last++) {\n                if (dp[last][mask] == 0) continue;\n                for (int y : graph[last]) {\n                    if (!hasBit(mask, y) && y > firstBit) {\n                        dp[y][mask | (1 << y)] += dp[last][mask];\n                    }\n                }\n            }\n        }\n        long answer = 0;\n        for (int i = 1; i < max; i++) {\n            if (Integer.bitCount(i) < 3) continue;\n            int firstBit = -1;\n            for (int j = 0; j < n; j++) {\n                if (hasBit(i, j)) {\n                    firstBit = j;\n                    break;\n                }\n            }\n            for (int y : graph[firstBit]) {\n                answer += dp[y][i];\n            }\n        }\n        out.println(answer / 2);\n    }\n\n    boolean hasBit(int mask, int bit) {\n        return (mask & (1 << bit)) != 0;\n    }\n\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tprivate FastScanner in;\n\tprivate PrintWriter out;\n\n\tpublic void solve() throws IOException {\n\t\tint N = in.nextInt();\n\t\tint M = in.nextInt();\n\n\t\tint[][] edges = new int[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\tedges[a][b] = 1;\n\t\t\tedges[b][a] = 1;\n\t\t}\n\n\t\tint globalCountMasks = 1 << N;\n\t\tint[][] masks = new int[N + 1][];\n\t\tint[] countMasks = new int[N + 1];\n\t\tfor (int i = 0; i <= N; i++) {\n\t\t\tmasks[i] = new int[combinations(N, i)];\n\t\t}\n\t\tfor (int i = 0; i < globalCountMasks; i++) {\n\t\t\tint c = countBit1(i);\n\t\t\tmasks[c][countMasks[c]] = i;\n\t\t\tcountMasks[c]++;\n\t\t}\n\n\t\tlong globalCountCycles = 0;\n\t\tlong[][] count = new long[globalCountMasks][N];\n\n\t\tfor (int a = 0; a < N - 2; a++) {\n\t\t\tint aBit = 1 << a;\n\t\t\tcount[aBit][a] = 1;\n\t\t\tlong countCycles = 0;\n\t\t\tfor (int i = 2; i <= N; i++) {\n\t\t\t\tfor (int m = 0; m < countMasks[i]; m++) {\n\t\t\t\t\tint mask = masks[i][m];\n\t\t\t\t\tif ((mask & aBit) == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif ((mask & (aBit - 1)) > 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcount[mask][a] = 0;\n\t\t\t\t\tfor (int v = a + 1; v < N; v++) {\n\t\t\t\t\t\tint vBit = 1 << v;\n\t\t\t\t\t\tif ((mask & vBit) == 0)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tcount[mask][v] = 0;\n\t\t\t\t\t\tfor (int t = a; t < N; t++) {\n\t\t\t\t\t\t\tif ((mask & (1 << t)) == 0 || t == v\n\t\t\t\t\t\t\t\t\t|| edges[v][t] == 0)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tcount[mask][v] += count[mask ^ vBit][t];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (edges[a][v] == 1 && mask != (aBit | vBit)) {\n\t\t\t\t\t\t\tcountCycles += count[mask][v];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tglobalCountCycles += countCycles / 2;\n\t\t}\n\n\t\tout.println(globalCountCycles);\n\t}\n\n\tprivate int countBit1(int k) {\n\t\tint c = 0;\n\t\twhile (k > 0) {\n\t\t\tc += k & 1;\n\t\t\tk >>= 1;\n\t\t}\n\t\treturn c;\n\t}\n\n\tprivate int combinations(int n, int k) {\n\t\tif (k > n || k < 0) {\n\t\t\tthrow new IllegalArgumentException();\n\t\t}\n\t\tint r = 1;\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\tr = r * (n + 1 - i) / i;\n\t\t}\n\t\treturn r;\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\t\t\tsolve();\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\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\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 Main().run();\n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class Template implements Runnable {\n    private void solve() throws IOException {\n        int n = nextInt();\n        int m = nextInt();\n        boolean[][] g = new boolean[n][n];\n        for (int i = 0; i < m; ++i) {\n            int a = nextInt() - 1;\n            int b = nextInt() - 1;\n            g[a][b] = true;\n            g[b][a] = true;\n        }\n        /*for (int i = 0; i < n; ++i)\n            for (int j = 0; j < n; ++j)\n                g[i][j] = true;*/\n        long[] am = new long[n + 1];\n        long[][] ways = new long[1 << (n - 1)][n];\n        for (int start = 0; start < n; ++start) {\n            for (int mask = 0; mask < (1 << (n - start - 1)); ++mask)\n                for (int last = start; last < n; ++last) {\n                    ways[mask][last - start] = 0;\n                }\n            ways[1 >> 1][0] = 1;\n            for (int mask = 1; mask < (1 << (n - start)); mask += 2) {\n                int cnt = 0;\n                int tmp = mask;\n                while (tmp > 0) {\n                    ++cnt;\n                    tmp = tmp & (tmp - 1);\n                }\n                for (int last = start; last < n; ++last)\n                    if (ways[mask >> 1][last - start] > 0) {\n                        long amm = ways[mask >> 1][last - start];\n                        for (int i = start; i < n; ++i)\n                            if ((mask & (1 << (i - start))) == 0 && g[last][i]) {\n                                ways[(mask | (1 << (i - start))) >> 1][i - start] += amm;\n                            }\n                        if (g[last][start])\n                            am[cnt] += ways[mask >> 1][last - start];\n                    }\n            }\n        }\n        long res = 0;\n        for (int cnt = 3; cnt <= n; ++cnt) {\n            if (am[cnt] % (2) != 0)\n                throw new RuntimeException();\n            res += am[cnt] / (2);\n        }\n        writer.println(res);\n    }\n\n\n    public static void main(String[] args) {\n        new Template().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", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * 4 6\n * 1 2\n * 1 3\n * 1 4\n * 2 3\n * 2 4\n * 3 4\n *\n *\n *\n *\n *\n *\n * @author pttrung\n */\npublic class D {\n\n    public static long [][]dp;\n    public static boolean [][]map;\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner();\n        PrintWriter out = new PrintWriter(System.out);\n//        int N = 19;\n//        System.out.println(N + \" \" + ((N - 1) * N / 2));\n//        for (int i = 1; i\n//                <= N; i++) {\n//            for (int j = i + 1; j <= N; j++) {\n//                System.out.println(i + \" \" + j);\n//            }\n//        }\n        int n = in.nextInt();\n        int m = in.nextInt();\n        dp = new long[n][1 << n + 1] ;\n\n        map = new boolean[n][n];\n        for (int i = 0; i < m; i++) {\n            int a = in.nextInt() - 1;\n            int b = in.nextInt() - 1;\n            map[a][b] = true;\n            map[b][a] = true;\n          \n        }\n        for(long []temp : dp){\n            Arrays.fill(temp, -1);\n        }\n        long result = 0;\n        for(int i = 0; i < n; i++){\n            result += cal((1<<i),i,i,1);\n        }\n        out.println((result/2));\n\n        out.close();\n    }\n    public static long cal(int mask, int from, int to, int len){\n        if(dp[to][mask]!= -1){\n            return dp[to][mask];\n        }\n        long result = 0;\n        if(len > 2 && map[from][to]){\n            result++;\n        }\n        for(int i = from+1; i< map.length; i++){\n            if(map[to][i] && (mask & (1<<i)) == 0){\n                result += cal(mask|(1<<i), from,i,len + 1);\n            }\n        }\n        dp[to][mask] = result;\n        return result;\n        \n    }\n   \n\n    public static class FT {\n\n        int[] data;\n\n        FT(int n) {\n            data = new int[n];\n        }\n\n        public void update(int index, int value) {\n            while (index < data.length) {\n                data[index] += value;\n                index += (index & (-index));\n            }\n        }\n\n        public int get(int index) {\n            int result = 0;\n            while (index > 0) {\n                result += data[index];\n                index -= (index & (-index));\n            }\n            return result;\n\n        }\n    }\n\n    public static long gcd(long a, long b) {\n        if (b == 0) {\n            return a;\n        }\n        return gcd(b, a % b);\n    }\n\n    public static long pow(long a, long b) {\n        if (b == 0) {\n            return 1;\n        }\n        if (b == 1) {\n            return a;\n        }\n        long val = pow(a, b / 2);\n        if (b % 2 == 0) {\n            return val * val ;\n        } else {\n            return val * (val * a) ;\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}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import 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.StringTokenizer;\n\npublic class Main implements Runnable {\n\n    private int n;\n    private int nn;\n    private long[][] dp;\n    private boolean[][] gr;\n\n    // ////////////////////////////////////////////////////////////////////\n    // Solution\n\n    private void solve() throws Throwable {\n        n = nextInt();\n        nn = 1 << n;\n        gr = new boolean[n][n];\n        dp = new long[n][nn];\n        for (int i = 0; i < n; i++) {\n            Arrays.fill(dp[i], -1);\n        }\n        int m = nextInt();\n        for (int i = 0; i < m; i++) {\n            int a = nextInt() - 1, b = nextInt() - 1;\n            gr[a][b] = gr[b][a] = true;\n        }\n        for (int i = 0; i < n; i++) {\n            dp[i][0] = 0;\n        }\n        for (int mask = 1; mask < nn; mask++) {\n            int bCount = Integer.bitCount(mask);\n            if (bCount < 2) {\n                dp[Integer.numberOfTrailingZeros(mask)][mask] = 0;\n            } else if (bCount == 2) {\n                int msk = mask;\n                int one = Integer.numberOfTrailingZeros(msk);\n                msk ^= (1 << one);\n                int two = Integer.numberOfTrailingZeros(msk);\n                dp[two][mask] = gr[one][two] ? 1 : 0;\n            }\n        }\n        long count = 0;\n        for (int mask = 1; mask < nn; mask++) {\n            if (Integer.bitCount(mask) < 3) continue;\n            int i = Integer.numberOfTrailingZeros(mask);\n            for (int j = i + 1; j < n; j++) {\n                int jj = 1 << j;\n                if (gr[i][j] && ((jj & mask) != 0)) {\n                    count += Dp(j, mask);\n                }\n            }\n        }\n        pw.println(count / 2);\n    }\n\n    private long Dp(int j, int mask) {\n        if (dp[j][mask] != -1) return dp[j][mask];\n        int i = Integer.numberOfTrailingZeros(mask);\n        assert i < j;\n        int m = mask ^ (1 << j);\n        long ans = 0;\n        for (int p = i + 1; p < n; p++) {\n            if (!gr[p][j]) continue;\n            if ((mask & (1 << p)) == 0) continue;\n            ans += Dp(p, m);\n        }\n        dp[j][mask] = ans;\n        return ans;\n    }\n\n    // ////////////////////////////////////////////////////////////////////\n    // Utility functions\n\n    PrintWriter pw;\n    BufferedReader in;\n    StringTokenizer st;\n\n    void initStreams() throws FileNotFoundException {\n        //System.setIn(new FileInputStream(\"2\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n    }\n\n    String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    static Throwable sError;\n\n    public static void main(String[] args) throws Throwable {\n        Thread t = new Thread(new Main());\n        t.start();\n        t.join();\n        if (sError != null) {\n            throw sError;\n        }\n    }\n\n    public void run() {\n        try {\n            initStreams();\n            solve();\n        } catch (Throwable e) {\n            sError = e;\n        } finally {\n            if (pw != null)\n                pw.close();\n        }\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tprivate int n;\n\tprivate int m;\n\tprivate boolean[][] g;\n\tprivate long[][] dp;\n\tprivate int[] count;\n\tprivate int[] first;\n\n\tprivate void solve() throws IOException {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\n\t\tg = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = nextInt() - 1;\n\t\t\tint b = nextInt() - 1;\n\t\t\tg[a][b] = true;\n\t\t\tg[b][a] = true;\n\t\t}\n\n\t\tcount = new int[1 << n];\n\t\tfirst = new int[1 << n];\n\t\tdp = new long[1 << n][n];\n\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\tcount[mask] = bitCount(mask);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (bit(i, mask) == 1) {\n\t\t\t\t\tfirst[mask] = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((count[mask] == 1) && (bit(i, mask) == 1)) {\n\t\t\t\t\tdp[mask][i] = 1;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tif (g[j][i] && (count[mask] > 1) && (bit(i, mask) == 1)\n\t\t\t\t\t\t\t\t&& (first[mask] != i)) {\n\t\t\t\t\t\t\tdp[mask][i] += dp[mask ^ (1 << i)][j];\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\tlong ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\tif ((count[mask] >= 3) && (first[mask] != i)\n\t\t\t\t\t\t&& (g[i][first[mask]])) {\n\t\t\t\t\tans += dp[mask][i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (ans % 2 != 0) {\n\t\t\tthrow new RuntimeException(\"SHIT!!!\");\n\t\t}\n\t\tout.println(ans / 2);\n\t}\n\n\tprivate final int bit(int i, int mask) {\n\t\treturn (mask & (1 << i)) != 0 ? 1 : 0;\n\t}\n\n\tprivate final int bitCount(int mask) {\n\t\tint ret = 0;\n\t\twhile (mask != 0) {\n\t\t\tret++;\n\t\t\tmask -= mask & (-mask);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tprivate Main() throws IOException {\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 s) {\n\t\tst = new StringTokenizer(s);\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\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main();\n\t}\n\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        int V = in.nextInt();\n        int E = in.nextInt();\n        boolean [][] G = new boolean [V][V];\n        for (int i = 0; i < E; i++) {\n            int u = in.nextInt()-1;\n            int v = in.nextInt()-1;\n            G[u][v] = true;\n            G[v][u] = true;\n        }\n        \n        int pset = 1 << V;\n        \n        long [][] dp = new long [pset][V];\n        long cycles = 0;\n        \n        for (int set = 1; set < pset; set++) {\n            int bit = Integer.bitCount(set);\n            int src = first(set);\n            \n            if (bit == 1) {\n                dp[set][src] = 1;\n            }\n            else if(bit > 1) {\n                for (int i = 0; i < V; i++) {\n                    if(i == src) continue;\n                    // Check if i is in set\n                    if ((set & (1 << i)) != 0) {\n                        int S_1 = set ^ (1 << i);\n                        for (int v = 0; v < V; v++) {\n                            if (G[v][i] == true) {\n                                dp[set][i] += dp[S_1][v];\n                            }\n                        }\n                    }\n                    //Count Cycles:\n                    if (bit >= 3 && G[src][i]) {\n                        cycles += dp[set][i];\n                    }   \n                }\n                \n            }\n                    \n                    \n        }\n        System.out.println(cycles/2);\n    }\n    \n    public static int first(int n) {\n        int cnt = 0;\n        while ((n & 1) != 1) {\n            cnt++;\n            n >>= 1;\n        }\n        return cnt;\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\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 (adj[i][j]) {\n\t\t\t\t\t--res;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfinal long[][] dp = new long[1 << n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tdp[mask][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < (1 << (n - i)); ++mask) {\n\t\t\t\tfor (int j = 0; j < n - i; ++j) {\n\t\t\t\t\tif (dp[mask][j] != 0) {\n\t\t\t\t\t\tfor (int k = 0; k < n - i; ++k) {\n\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\tdp[mask | (1 << k)][k] += dp[mask][j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (((mask >> 0) & 1) != 0) {\n\t\t\t\t\tres += dp[mask][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n//\t\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\tlong time1 = System.currentTimeMillis();\n\t\tnew Main().run();\n//\t\tcheckMemory();\n//\t\tlong time2 = System.currentTimeMillis();\n//\t\tSystem.err.println((time2 - time1) + \" ms\");\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\t\n\tint vNum;\n\tint eNum;\n\tboolean[][] g;\n\t\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tvNum = nextInt();\n\t\teNum = nextInt();\n\t\tg = new boolean [vNum][vNum];\n\t\tfor (int e = 0; e < eNum; e++) {\n\t\t\tint u = nextInt() - 1;\n\t\t\tint v = nextInt() - 1;\n\t\t\tg[u][v] = g[v][u] = true;\n\t\t}\n\t\t\n//\t\tfor (int v = 7; v <= 11; v++) {\n//\t\t\tgenFullGraph(v);\n//\t\t\tif (naiveDP() != optimizedDP())\n//\t\t\t\tSystem.err.println(\"Error on \" + v);\n//\t\t}\n\t\t\n\t\tout.println(optimizedDP());\n\t\t\n\t\tout.close();\n\t}\n\t\n\t/*************************************************************** \n\t * Test\n\t **************************************************************/\n\tlong naiveDP() {\n\t\tlong[] count = new long [vNum + 1];\n\t\tint size = 1 << vNum;\n\t\tlong[][] dp = new long [size][vNum];\n\t\tfor (int begin = 0; begin < vNum; begin++) {\n\t\t\tfor (long[] row : dp) fill(row, 0L);\n\t\t\tdp[1 << begin][begin] = 1L;\n\t\t\tfor (int mask = 0; mask < size; mask++) {\n\t\t\t\tint len = Integer.bitCount(mask);\n\t\t\t\tfor (int v = 0; v < vNum; v++) {\n\t\t\t\t\tlong cval = dp[mask][v];\n\t\t\t\t\tif (cval == 0L) continue;\n\t\t\t\t\tif (g[v][begin]) count[len] += cval;\n\t\t\t\t\tfor (int nv = 0; nv < vNum; nv++) {\n\t\t\t\t\t\tif (g[v][nv]) {\n\t\t\t\t\t\t\tint nmask = mask | (1 << nv);\n\t\t\t\t\t\t\tif (nmask != mask)\n\t\t\t\t\t\t\t\tdp[nmask][nv] += cval;\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 ret = 0L;\n\t\tfor (int len = 3; len <= vNum; len++) {\n\t\t\tif (count[len] % (len * 2) != 0) System.err.println(\"ERROR!\");\n\t\t\tret += count[len] / len / 2;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tlong optimizedDP() {\n\t\tlong[] count = new long [vNum + 1];\n\t\tlong[][] dp = new long [1 << vNum][vNum];\n\t\tfor (int last = vNum - 1; last >= 0; last--) {\n\t\t\tint size = 1 << last;\n\t\t\tfor (int mask = 0; mask < size; mask++)\n\t\t\t\tfill(dp[mask], 0, last, 0L);\n\t\t\tfor (int nv = 0; nv < last; nv++)\n\t\t\t\tif (g[last][nv]) dp[1 << nv][nv] = 1L;\n\t\t\tfor (int mask = 0; mask < size; mask++) {\n\t\t\t\tint len = Integer.bitCount(mask) + 1;\n\t\t\t\tfor (int v = 0; v < last; v++) {\n\t\t\t\t\tlong cval = dp[mask][v];\n\t\t\t\t\tif (cval == 0L) continue;\n\t\t\t\t\tif (g[v][last]) count[len] += cval;\n\t\t\t\t\tfor (int nv = 0; nv < last; nv++) {\n\t\t\t\t\t\tif (g[v][nv]) {\n\t\t\t\t\t\t\tint nmask = mask | (1 << nv);\n\t\t\t\t\t\t\tif (nmask != mask)\n\t\t\t\t\t\t\t\tdp[nmask][nv] += cval;\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 ret = 0L;\n\t\tfor (int len = 3; len <= vNum; len++) {\n\t\t\tif (count[len] % 2 != 0) System.err.println(\"ERROR!\");\n\t\t\tret += count[len] >> 1;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid genFullGraph(int vNum) {\n\t\tthis.vNum = vNum;\n\t\tthis.eNum = vNum * (vNum - 1) / 2;\n\t\tg = new boolean [vNum][vNum];\n\t\tfor (int i = 0; i < vNum; i++)\n\t\t\tfor (int j = i + 1; j < vNum; j++)\n\t\t\t\tg[i][j] = g[j][i] = true;\n\t\t\t\t\n\t}\n\t\n\t/*************************************************************** \n\t * Utility\n\t **************************************************************/\n\tstatic long b2mb(long b) {\n\t\treturn b >> 20;\n\t}\n\t\n\tstatic void checkMemory() {\n\t\tSystem.err.println(b2mb(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) + \"/\" + b2mb(Runtime.getRuntime().totalMemory()) + \" MB\");\n\t}\n\t\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", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\n\npublic class Cycles\n{\n\tpublic static FastInputStream fis;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tfis = new FastInputStream(System.in);\n\t\t\n\t\tSystem.out.println(solve(fis.nextInt(), fis.nextInt()));\n\t\t\n\t\tfis.close();\n\t}\n\t\n\tpublic static long solve(int n, int m) throws IOException\n\t{\n\t\tboolean[][] graph = new boolean[n][];\n\t\tlong[][] state = new long[1 << n][n];\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tgraph[i] = new boolean[n - i];\n\t\t\n\t\tfor (int i = 0; i < m; i++)\n\t\t{\n\t\t\tint a = fis.nextInt() - 1;\n\t\t\tint b = fis.nextInt() - 1;\n\t\t\tsetConnected(graph, a, b);\n\t\t\tstate[(1 << a) | (1 << b)][a > b ? a : b] = 1;\n\t\t}\n\t\t\n\t\tlong res = 0;\n\t\t\n\t\tfor (int i = 2; i < n; i++)\n\t\t{\n\t\t\tint baseCombination = (2 << i) - 1;\n\t\t\t\n\t\t\twhile (baseCombination < (1 << n))\n\t\t\t{\n\t\t\t\tint min = getFirstOne(baseCombination);\n\t\t\t\tint bits = baseCombination;\n\t\t\t\twhile (bits != 0)\n\t\t\t\t{\n\t\t\t\t\tint firstBit = bits & (-bits);\n\t\t\t\t\tint firstBitPos = getFirstOne(firstBit);\n\t\t\t\t\t\n\t\t\t\t\tbits &= bits - 1;\n\t\t\t\t\t\n\t\t\t\t\tif (firstBitPos == min)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t\tint leftOverBits = baseCombination - firstBit;\n\t\t\t\t\tint nextBits = leftOverBits;\n\t\t\t\t\t\n\t\t\t\t\twhile (nextBits != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tint nextBit = nextBits & (-nextBits);\n\t\t\t\t\t\tint nextBitPos = getFirstOne(nextBit);\n\t\t\t\t\t\t\n\t\t\t\t\t\tnextBits &= nextBits - 1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (nextBitPos == min)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (!isConnected(graph, firstBitPos, nextBitPos))\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\n\t\t\t\t\t\t/*System.out.println(\"Comb: \" + Integer.toBinaryString(baseCombination));\n\t\t\t\t\t\tSystem.out.println(\"Bit: \" + Integer.toBinaryString(firstBit));\n\t\t\t\t\t\tSystem.out.println(\"(pos): \" + firstBitPos);\n\t\t\t\t\t\tSystem.out.println(\"Left over: \" + Integer.toBinaryString(leftOverBits));\n\t\t\t\t\t\tSystem.out.println(\"Next bit: \" + Integer.toBinaryString(nextBit));\n\t\t\t\t\t\tSystem.out.println(\"(pos): \" + nextBitPos);\n\t\t\t\t\t\tSystem.out.println();*/\n\t\t\t\t\t\t\n\t\t\t\t\t\tstate[baseCombination][firstBitPos] += state[leftOverBits][nextBitPos];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (isConnected(graph, firstBitPos, min))\n\t\t\t\t\t\tres += state[baseCombination][firstBitPos];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbaseCombination = nextCombination(baseCombination);\n\t\t\t}\n\t\t}\n\t\t\n\t\t/*for (int i = 0; i < state.length; i++)\n\t\t{\n\t\t\tif ((i & (i - 1)) == 0)\n\t\t\t\tcontinue;\n\t\t\tSystem.out.print(String.format(\"%4s:\", Integer.toBinaryString(i)).replace(' ', '0') + \" \");\n\t\t\tfor (int j = 0; j < state[i].length; j++)\n\t\t\t\tSystem.out.print(state[i][j] + \" \");\n\t\t\tSystem.out.println();\n\t\t}*/\n\t\t\n\t\treturn res >> 1;\n\t}\n\t\n\tpublic static boolean isConnected(boolean[][] graph, int a, int b)\n\t{\n\t\tif (b < a || graph[a].length <= (b - a))\n\t\t\treturn graph[b][a - b];\n\t\treturn graph[a][b - a];\n\t}\n\t\n\tpublic static void setConnected(boolean[][] graph, int a, int b)\n\t{\n\t\tif (b < a || graph[a].length <= (b - a))\n\t\t\tgraph[b][a - b] = true;\n\t\telse\n\t\t\tgraph[a][b - a] = true;\n\t}\n\t\n\tpublic static int nextCombination(int x)\n\t{\n\t\tint smallest = x & -x;\n\t\tint ripple = x + smallest;\n\t\tint ones = ((x ^ ripple) >> 2) / smallest;\n\t\treturn ripple | ones;\n\t}\n\t\n\tpublic static boolean on(int bitmask, int pos)\n\t{\n\t\treturn ((bitmask >> pos) & 1) == 1;\n\t}\n\t\n\tpublic static int setOn(int bitmask, int pos)\n\t{\n\t\treturn bitmask | (1 << pos);\n\t}\n\t\n\tpublic static int setOff(int bitmask, int pos)\n\t{\n\t\treturn bitmask & ~(1 << pos);\n\t}\n\t\n\tpublic static int getOns(int bitmask)\n\t{\n\t\tint amt = 0;\n\t\twhile (bitmask != 0)\n\t\t{\n\t\t\tbitmask &= bitmask - 1;\n\t\t\tamt++;\n\t\t}\n\t\t\n\t\treturn amt;\n\t}\n\t\n\tpublic static int getFirstOne(int bitmask)\n\t{\n\t\tif (bitmask == 0)\n\t\t\treturn -1;\n\t\t\n\t\tint first = 0;\n\t\twhile ((bitmask & 1) != 1)\n\t\t{\n\t\t\tfirst++;\n\t\t\tbitmask = bitmask >> 1;\n\t\t}\n\t\t\n\t\treturn first;\n\t}\n\t\n\tpublic static class FastInputStream extends InputStream\n\t{\n\t\tprivate InputStream in;\n\t\t\n\t\tprivate byte[] buffer = new byte[512];\n\t\tprivate int loaded = 0;\n\t\tprivate int pointer = 0;\n\t\t\n\t\tpublic FastInputStream(InputStream in)\n\t\t{\n\t\t\tthis.in = in;\n\t\t}\n\n\t\t@Override\n\t\tpublic int read() throws IOException\n\t\t{\n\t\t\tif (hasNext())\n\t\t\t\treturn buffer[pointer++];\n\t\t\telse\n\t\t\t\treturn -1;\n\t\t}\n\n\t\tpublic void skipWhitespace() throws IOException\n\t\t{\n\t\t\twhile (hasNext())\n\t\t\t{\n\t\t\t\tchar c = (char) buffer[pointer];\n\n\t\t\t\tif (c == ' ' || c == '\\t' || c == '\\n' || c == '\\r') pointer++;\n\t\t\t\telse return;\n\t\t\t}\n\t\t}\n\n\t\tpublic Integer nextInt() throws IOException\n\t\t{\n\t\t\tskipWhitespace();\n\n\t\t\tif (!hasNext()) return null;\n\n\t\t\tbyte multiplier = 1;\n\t\t\tint number = 0;\n\n\t\t\tif (buffer[pointer] == '-')\n\t\t\t{\n\t\t\t\tmultiplier = -1;\n\t\t\t\tpointer++;\n\t\t\t}\n\n\t\t\twhile (hasNext())\n\t\t\t{\n\t\t\t\tchar c = (char) buffer[pointer];\n\n\t\t\t\tif (c >= '0' && c <= '9')\n\t\t\t\t{\n\t\t\t\t\tnumber = (number << 3) + (number << 1) + c - '0';\n\t\t\t\t\tpointer++;\n\t\t\t\t} else break;\n\t\t\t}\n\n\t\t\treturn number * multiplier;\n\t\t}\n\t\t\n\t\tpublic void close() throws IOException\n\t\t{\n\t\t\tin.close();\n\t\t}\n\t\t\n\t\tpublic boolean hasNext() throws IOException\n\t\t{\n\t\t\twhile (pointer == loaded)\n\t\t\t{\n\t\t\t\tloaded = in.read(buffer);\n\t\t\t\tpointer = 0;\n\t\t\t\t\n\t\t\t\tif (loaded == -1) return false;\n\t\t\t}\n\t\t\treturn loaded != -1;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Ok_Simple {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic boolean am[][];\n\tstatic long dp[][];\n\tstatic int n;\n\tpublic static void main(String[] args) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tint m;\n\t\tn = NextInt();\n\t\tm = NextInt();\n\t\tam = new boolean[n][n];\n\t\tdp = new long[n][1 << n];\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tArrays.fill(dp[i], -1);\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint a = NextInt() - 1;\n\t\t\tint b = NextInt() - 1;\n\t\t\tam[a][b] = am[b][a] = true;\n\t\t};\n\t\tlong res = 0;\n\t\tfor (int a = 0; a < n; ++a)\n\t\t\tres += solve(a, (1 << a));\n\t\tSystem.out.println(res / 2);\n\t}\n\tprivate static long solve(int b, int mask) {\n\t\tint a = 0;\n\t\tfor (int i = 0 ;i < n; ++i)\n\t\t\tif (((mask >> i) & 1) != 0)\n\t\t\t{\n\t\t\t\ta = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif (dp[b][mask] >= 0)\n\t\t\treturn dp[b][mask];\n\t\tlong res = 0;\n\t\tif (am[b][a] && Integer.bitCount(mask) > 2)\n\t\t\tres = 1;\n\t\tfor (int i = a + 1; i < n; ++i)\n\t\t\tif (((mask >> i) & 1) == 0 && am[b][i])\n\t\t\t\tres += solve(i, mask ^ (1 << i));\n\t\treturn dp[b][mask] = res;\n\t}\n\tstatic int NextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(NextToken());\n\t}\n\tstatic double NextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(NextToken());\n\t}\n\tstatic long NextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(NextToken());\n\t}\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", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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\t\t\n\t\tString[] input = kek.readLine().split(\" \");\n\t\tint N = Integer.parseInt(input[0]), M = Integer.parseInt(input[1]);\n\t\tboolean[][] connected = new boolean[N + 1][N];\n\t\tlong[][] walks = new long[1 << N][N];\n\t\tlong res = 0;\n\t\t\n\t\tfor(int i = 0; i < M; i++){\n\t\t\tinput = kek.readLine().split(\" \");\n\t\t\tint A = Integer.parseInt(input[0]) - 1, B = Integer.parseInt(input[1]) - 1;\n\t\t\tconnected[A][B] = connected[B][A] = true;\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < N; i++){\n\t\t\twalks[1 << i][i] = 1;\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < 1 << N; i++){\n\t\t\tint temp = (int) (Math.log(i & -(i)) / 0.6931471805599453);\n\t\t\tfor(int j = 0; j < N; j++){\n\t\t\t\tif(((1 << j) & i) > 0 && j != temp){\n\t\t\t\t\tfor(int k = 0; k < N; k++){\n\t\t\t\t\t\tif(connected[k][j]){\n\t\t\t\t\t\t\twalks[i][j] += walks[i ^ (1 << j)][k];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tint count = 0, track = i;\n\t\t\t\t\twhile(track > 0){\n\t\t\t\t\t\tif(track % 2 == 1){\n\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttrack /= 2;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\tif(count >= 3 && connected[temp][j]){\n\t\t\t\t\t\tres += walks[i][j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\toutkek.println(res / 2);\n\t\tkek.close();\n\t\toutkek.close();\n\t}\t\n\t\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\n\npublic class ASimpleTask {\n\n\tstatic StreamTokenizer st;\n\n\tstatic int nextInt() {\n\t\ttry {\n\t\t\tst.nextToken();\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 (int) st.nval;\n\t}\n\n\tstatic int[][] edges;\n\tstatic long[][] dp;\n\n\tpublic static void main(String[] args) {\n\t\tst = new StreamTokenizer(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\n\t\tedges = new int[n][n];\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint from = nextInt() - 1;\n\t\t\tint to = nextInt() - 1;\n\t\t\tedges[from][to] = edges[to][from] = 1;\n\t\t}\n\n\t\tdp = new long[(1 << n) + 1][n + 1];\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (Integer.bitCount(mask) == 1 && (mask & (1 << i)) != 0) {\n\t\t\t\t\tdp[mask][i] = 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (Integer.bitCount(mask) > 1 && (mask & (1 << i)) != 0\n\t\t\t\t\t\t&& first(mask, n) != i) {\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tif (edges[i][j] == 1) {\n\t\t\t\t\t\t\tdp[mask][i] += dp[mask ^ (1 << i)][j];\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\tlong count = 0;\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (Integer.bitCount(mask) >= 3\n\t\t\t\t\t\t&& edges[i][first(mask, n)] != 0)\n\t\t\t\t\tcount += dp[mask][i];\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(count / 2);\n\n\t}\n\n\tstatic int first(int mask, int n) {\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((mask & (1 << i)) != 0)\n\t\t\t\treturn i;\n\t\t}\n\t\treturn -1;\n\t}\n\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import 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.StringTokenizer;\n\npublic class Main implements Runnable {\n\n    private int n;\n    private int nn;\n    private boolean[][] gr;\n    private long[][] D;\n\n\n    // ////////////////////////////////////////////////////////////////////\n    // Solution\n\n    private void solve() throws Throwable {\n        n = nextInt();\n        nn = 1 << n;\n        gr = new boolean[n][n];\n        int m = nextInt();\n        for (int i = 0; i < m; i++) {\n            int a = nextInt() - 1, b = nextInt() - 1;\n            gr[a][b] = gr[b][a] = true;\n        }\n        D = new long[n][nn];\n        for (int i = 0; i < n; i++) {\n            Arrays.fill(D[i], -1);\n        }\n        long count = 0;\n        for (int i = 0; i < n; i++) {\n            count += getD(i, i, 1, 1 << i);\n        }\n        pw.println(count / 2);\n    }\n\n\n    private long getD(int first, int last, int cnt, int mask) {\n        if (D[last][mask] != -1) return D[last][mask];\n        long ans = 0;\n        if (cnt >= 3 && gr[first][last])\n            ans++;\n        for (int i = first + 1; i < n; i++) {\n            if (gr[last][i] && (mask & (1 << i)) == 0) {\n                ans += getD(first, i, cnt + 1, mask | (1 << i));\n            }\n        }\n        D[last][mask] = ans;\n        return ans;\n    }\n\n\n    // ////////////////////////////////////////////////////////////////////\n    // Utility functions\n\n    PrintWriter pw;\n    BufferedReader in;\n    StringTokenizer st;\n\n    void initStreams() throws FileNotFoundException {\n        //System.setIn(new FileInputStream(\"2\"));\n        in = new BufferedReader(new InputStreamReader(System.in));\n        pw = new PrintWriter(System.out);\n    }\n\n    String nextString() throws IOException {\n        while (st == null || !st.hasMoreTokens()) {\n            st = new StringTokenizer(in.readLine());\n        }\n        return st.nextToken();\n    }\n\n    int nextInt() throws NumberFormatException, IOException {\n        return Integer.parseInt(nextString());\n    }\n\n    long nextLong() throws NumberFormatException, IOException {\n        return Long.parseLong(nextString());\n    }\n\n    double nextDouble() throws NumberFormatException, IOException {\n        return Double.parseDouble(nextString());\n    }\n\n    static Throwable sError;\n\n    public static void main(String[] args) throws Throwable {\n        Thread t = new Thread(new Main());\n        t.start();\n        t.join();\n        if (sError != null) {\n            throw sError;\n        }\n    }\n\n    public void run() {\n        try {\n            initStreams();\n            solve();\n        } catch (Throwable e) {\n            sError = e;\n        } finally {\n            if (pw != null)\n                pw.close();\n        }\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class ASimpleTask\n{\n\n\n\t/************************ SOLUTION STARTS HERE ***********************/\n\t\n\tstatic long memo[][];\n\tstatic int graph[];\n\tstatic long hamiltonianPath(int mask , int u) {\n\t    if(memo[mask][u] != -1) \n\t        return memo[mask][u];\n\t    else if(u == Integer.numberOfTrailingZeros(mask)) // according to our convention A simple path is not allowed to end at the lowest vertex\n            return 0;\n\t    else {\n\t\t\tlong sum = 0;\n\t\t\tfor(int fromSet = mask ^ (1 << u);fromSet > 0; fromSet ^= Integer.lowestOneBit(fromSet)) {\n\t\t\t\tint v = Integer.numberOfTrailingZeros(fromSet);\n\t\t\t\t// System.out.printf(\"mask = %s , u = %d , v = %d\\n\" , Integer.toBinaryString(mask) , u , v);\n\t\t\t\tif((graph[u] & (1 << v)) != 0) \n\t\t\t\t\tsum += hamiltonianPath(mask ^ (1 << u), v);\n\t\t\t}\n\t\t\t\n\t\t\treturn /*memo[mask][u] = */sum;\n\t\t}\n\t}\n\n\tprivate static void solveBottomUp(FastScanner s1, PrintWriter out){\n\n\t\tint V = s1.nextInt();\n\t\tint E = s1.nextInt();\n\t\tgraph = new int[V];\n\t\tlong DP[][] = new long[1 << V][V];\n\n\t\twhile(E-->0) {\n\t\t\tint u = s1.nextInt() - 1;\n\t\t\tint v = s1.nextInt() - 1;\n\t\t\tgraph[u] |= (1 << v);\n\t\t\tgraph[v] |= (1 << u);\n\t\t}\n\n\t\tfor(int i=0;i<V;i++)\n\t\t\tDP[1 << i][i] = 1;\n\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\tfor(int fromSet = mask ^ (1 << u);fromSet > 0; fromSet ^= Integer.lowestOneBit(fromSet)) {\n\t\t\t\t\tint v = Integer.numberOfTrailingZeros(fromSet);\n\t\t\t\t\t// System.out.printf(\"mask = %s , u = %d , v = %d\\n\" , Integer.toBinaryString(mask) , u , v);\n\t\t\t\t\tif((graph[u] & (1 << v)) != 0) \n\t\t\t\t\t\tDP[mask][u] += DP[mask ^ (1 << u)][v];\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong totalCycles = 0;\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tif(Integer.bitCount(mask) >= 3) {\n\t\t\t\tint start = Integer.numberOfTrailingZeros(mask);\n\t\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\t\tif((graph[u] & (1 << start)) != 0)\n\t\t\t\t\t\ttotalCycles += DP[mask][u];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttotalCycles /= 2;\n/*\t\tfor(long l[] : DP)\n\t\t\tout.println(Arrays.toString(l));*/\n\t\tout.println(totalCycles);\n\t}\n\n\tprivate static void solveTopDown(FastScanner s1, PrintWriter out){\n\n\t\tint V = s1.nextInt();\n\t\tint E = s1.nextInt();\n\t\tgraph = new int[V];\n\t\tmemo = new long[1 << V][V];\n\t\t\n\t\tfor(long l[] : memo)\n\t\t\tArrays.fill(l, -1);\n\t\t\n\t\twhile(E-->0) {\n\t\t\tint u = s1.nextInt() - 1;\n\t\t\tint v = s1.nextInt() - 1;\n\t\t\tgraph[u] |= (1 << v);\n\t\t\tgraph[v] |= (1 << u);\n\t\t}\n\n\t\tfor(int i=0;i<V;i++)\n\t\t\tmemo[1 << i][i] = 1;\n\t\t\n\t\tlong totalCycles = 0;\n\t\tfor(int mask = 1 , end = 1 << V;mask < end;mask++) {\n\t\t\tif(Integer.bitCount(mask) >= 3) {\n\t\t\t\tint start = Integer.numberOfTrailingZeros(mask);\n\t\t\t\tfor(int set = mask;Integer.bitCount(set) > 1;set ^= Integer.highestOneBit(set)) {\n\t\t\t\t\tint u = Integer.numberOfTrailingZeros(Integer.highestOneBit(set));\n\t\t\t\t\tif((graph[u] & (1 << start)) != 0)\n\t\t\t\t\t\ttotalCycles += hamiltonianPath(mask, u);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttotalCycles /= 2;\n\t\t\n\t\tout.println(totalCycles);\n\t}\n\n\t/************************ SOLUTION ENDS HERE ************************/\n\n\n\n\n\n\t/************************ TEMPLATE STARTS HERE *********************/\n\n\tpublic static void main(String []args) throws IOException {\n\t\tFastScanner in  = new FastScanner(System.in);\n\t\tPrintWriter out = \n\t\t\t\tnew PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); \n\t\tsolveBottomUp(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}    \n\n\tstatic class FastScanner{\n\t\tBufferedReader reader;\n\t\tStringTokenizer st;\n\t\tFastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}\t\n\t\tString next()\n\t\t{while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}\t\t    \n\t\tst = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}\n\t\tString nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}\t    \t  \t\n\t\tint    nextInt()   {return Integer.parseInt(next());}\n\t\tlong   nextLong()  {return Long.parseLong(next());}\t\t\n\t\tdouble nextDouble(){return Double.parseDouble(next());}\n\t\tchar   nextChar()  {return next().charAt(0);}\n\t\tint[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}\n\t\tlong[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}\t\n\t\tint[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}\t    \t\n\t\tlong[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}\t    \t\n\t\tvoid   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}\t\t\t\t\n\t}\n\n\t/************************ TEMPLATE ENDS HERE ************************/\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\tprivate void solution() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean[][] adj = new boolean[n][n];\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint x = in.nextInt();\n\t\t\tint y = in.nextInt();\n\t\t\tadj[x - 1][y - 1] = true;\n\t\t\tadj[y - 1][x - 1] = true;\n\t\t}\n\t\tfinal long[][] dp = new long[1 << n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint Limit = 1 << (n - i);\n\t\t\tint nn = n - i;\n\t\t\tfor (int mask = 0; mask < Limit; ++mask) {\n\t\t\t\tfor (int j = 0; j < nn; ++j) {\n\t\t\t\t\tdp[mask][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[0][0] = 1;\n\t\t\tfor (int mask = 0; mask < Limit; ++mask) {\n\t\t\t\tfor (int j = 0; j < nn; ++j) {\n\t\t\t\t\tif (dp[mask][j] != 0) {\n\t\t\t\t\t\tlong am = dp[mask][j];\n\t\t\t\t\t\tfor (int k = 0; k < nn; ++k) {\n\t\t\t\t\t\t\tif (((mask >> k) & 1) == 0 && adj[j + i][k + i]) {\n\t\t\t\t\t\t\t\tdp[mask | (1 << k)][k] += am;\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 (((mask >> 0) & 1) != 0) {\n\t\t\t\t\tres += dp[mask][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println((res - m) / 2);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolution();\n\t\t\tin.reader.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 class Scanner {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\n\t\tpublic Scanner(Reader reader) {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tthis.tokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic boolean hasNext() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t\tString next = reader.readLine();\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(next);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\thasNext();\n\t\t\treturn tokenizer.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 String nextLine() throws IOException {\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\treturn reader.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Main(), \"\", 1 << 28).start();\n\t}\n\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tScanner in = new Scanner(new InputStreamReader(System.in));\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.InputMismatchException;\nimport java.io.*;\nimport java.util.HashMap;\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 SimpleCycles();\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    }\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    public int nextInt() {\n        return Integer.parseInt(nextToken());\n    }\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 SimpleCycles implements Solver {\n    public void solve(int testNumber, InputReader in, PrintWriter out) {\n        int n = in.nextInt();\n        int m = in.nextInt();\n        boolean[][] g = new boolean[n][n];\n        for (int i = 0; i < m; ++i) {\n            int u = in.nextInt();\n            int v = in.nextInt();\n            --u;\n            --v;\n            g[u][v] = g[v][u] = true;\n        }\n        HashMap<Integer, Integer> pointer = new HashMap<Integer, Integer> () ;\n        for (int i =0 ; i < n; ++i) {\n            pointer.put(1 << i, i);\n        }\n        long[][] dm = new long[1 << n][n];\n        for (int i = 0; i < n; ++i) {\n            dm[1 << i][i] = 1;\n        }\n        for (int i = 0; i < (1 << n); ++i) {\n            for (int j = 0; j < n; ++j) {\n                if (dm[i][j] == 0) continue;\n                int k = pointer.get(i - (i & (i - 1)));\n                for (int u = k + 1; u < n; ++u) {\n                    if (g[j][u] && (i & (1 << u)) == 0) {\n                        dm[i | (1 << u)][u] += dm[i][j];\n                    }\n                }\n            }\n        }\n        long res = 0;\n        for (int i = 0; i < (1 << n); ++i) {\n            for (int j = 0; j < n; ++j)\n                if (Integer.bitCount(i) >= 3) {\n\n                    int c = pointer.get(i - (i & (i - 1)));\n                    if (g[c][j]) res += (long) dm[i][j];\n                }\n        }\n        out.print(res / 2);\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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 SimpleTask {\n\n    public static void main(String[] args) throws Exception {\n        InputReader in = new InputReader(System.in);\n        int n = in.nextInt();\n        int m = in.nextInt();\n        int[] g = new int[n];\n        long[][] dp = new long[1 << n][n];\n        for (int i = 0; i < m; i++) {\n            int a = in.nextInt() - 1, b = in.nextInt() - 1;\n            g[a] |= (1 << b);\n            g[b] |= (1 << a);\n        }\n        int all = (1 << n) - 1;\n        for (int i = 0; i < n; i++) {\n            int l = (1 << i);\n            int left = all ^ (l - 1) ^ l;\n            for (int j = left; j > 0; j = (j - 1) & left)\n                if ((j & (j - 1)) != 0) {\n                    dp[j | l][i] = 1;\n                }\n        }\n        for (int i = (1 << n) - 1; i > 0; i--) {\n            int last = i & -i;\n            for (int j = 0; j < n; j++) {\n                if (((1 << j) == last && (i & (i - 1)) != 0)\n                        || ((1 << j) & i) == 0)\n                    continue;\n                for (int k = 0; k < n; k++) {\n                    if ((1 << k) >= last && ((1 << k) & g[j]) != 0\n                            && ((1 << k) == last || ((1 << k) & i) == 0)) {\n                        dp[i][j] += dp[i | (1 << k)][k];\n                    }\n\n                }\n            }\n        }\n        long res = 0;\n        for (int i = 0; i < n; i++)\n            res += dp[(1 << i)][i];\n        System.out.println(res / 2);\n    }\n\n    static class InputReader {\n        private BufferedReader reader;\n        private StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n\n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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.StringTokenizer;\n\npublic class A{\n\tstatic int n,m,start;\n\tstatic boolean [][] adj;\n\tstatic long [][] mem;\n\tpublic static void main(String[] args)throws Throwable {\n\t\tScanner sc=new Scanner(System.in);\n\t\tn=sc.nextInt();\n\t\tm=sc.nextInt();\n\t\tadj=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\tadj[u][v]=true;\n\t\t\tadj[v][u]=true;\n\t\t}\n\t\tmem=new long [n+1][(1<<n)];\n\t\tfor(int i=0;i<=n;i++)\n\t\t\tArrays.fill(mem[i], -1);\n\t\tlong ans=0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tstart=i;\n\t\t\tans+=dp(i, (1<<i));\n\t\t}\n\t\tSystem.out.println(ans/2);\n\t}\n\t\n\tpublic static long dp(int i,int msk){\n\t\tif(mem[i][msk]!=-1)\n\t\t\treturn mem[i][msk];\n\t\tlong ans=0;\n\t\tif(adj[i][start] && Integer.bitCount(msk)>2)\n\t\t\tans++;\n\t\tfor(int j=start+1;j<n;j++){\n\t\t\tif(adj[i][j] && (msk & (1<<j))==0){\n\t\t\t\tans+=dp(j, msk | (1<<j));\n\t\t\t}\n\t\t}\n\t\treturn mem[i][msk]=ans;\n\t}\n\t\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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 huhansan on 2017/12/19.\n * http://codeforces.com/problemset/problem/11/D\n * \u53c2\u8003 Petr http://codeforces.com/contest/11/submission/47646\n * \u6c42\u6240\u6709\u4e0d\u540c\u7684\u73af\u7684\u4e2a\u6570\n * \u9996\u5148\u6309\u957f\u5ea6\u5206 C = C1+C2+...+Cn\n * \u957f\u5ea6\u4e3ai\u7684\u73af\u7684\u6570\u91cf\u7684\u6c42\u89e3\uff0c \u89c4\u5b9a\u4e00\u4e2a\u987a\u5e8f\uff0c\u4ee5\u6700\u5c0f\u503c\u5f00\u5934\uff0c\u6309\u5f00\u5934\u4e0d\u540c\u5206\u6cbb\uff0c\u518d\u6309\u4e0d\u540c\u7ed3\u5c3e\u5206\u6cbb\n * \u904d\u5386\u6240\u6709\u6392\u5217\uff0c\u5982\u679c\u957f\u5ea6\u4e3ai\u7684\u6392\u5217\u6210\u73af\uff0c\u5219\u5bf9\u5e94\u7684Ci\u503c+1\n * \u904d\u5386\u65b9\u5f0f\u7684\u9009\u62e9\uff1a\n * 1.integer\u5b9e\u73b0bitmask\uff0c\u4ece1\u52a0\u52301<<n\n * 2.\u9012\u5f52\n */\n\npublic class CF_11D {\n    long[][] ways;  //ways[mask][endPointIndex]\n    boolean[][] connect;\n    int n, m, lowestIndex, mask;    //n \u8282\u70b9\u6570\uff0c m\u8fb9\u6570    00000...0  <--> n:n-1:n-2.....1 bitmask\n    private static int HEAD_POINT_INDEX = 0;\n\n    public void solve() throws Exception {\n        int a, b;\n        long total = 0;\n        n = nextInt();\n        m = nextInt();\n        connect = new boolean[n][n];\n        ways = new long[1 << n][n];\n        for (int i = 0; i < m; i++) {\n            a = nextInt();\n            b = nextInt();\n            connect[a - 1][b - 1] = true;\n            connect[b - 1][a - 1] = true;\n        }\n        for (int i = 0; i < n; i++) {\n            ways[1 << i][i] = 1;  //\u521d\u59cb\u5316\uff0c\u5355\u5b9a\u70b9\u4e5f\u89c6\u4e3a\u73af\n        }\n        for (mask = 1; mask < 1 << n; mask++) {\n            int tmp = mask, cnt = 0;\n            while (tmp > 0) {\n                tmp = tmp & (tmp - 1);\n                cnt++;\n            }\n            lowestIndex = -1;\n            for (int endPointIndex = 0; endPointIndex < n; endPointIndex++) {\n                if ((mask & 1 << endPointIndex) != 0) {\n                    if (lowestIndex < 0) {\n                        lowestIndex = endPointIndex;\n                    } else if (lowestIndex != endPointIndex) {\n                        for (int i = lowestIndex; i < n; i++)\n                            if (connect[i][endPointIndex]) {\n                                ways[mask][endPointIndex] += ways[mask & ~(1 << endPointIndex)][i]; // P[(1,2,3)4]\u7684\u6570\u91cf == \u5176\u5b83+P[1,2,3]\u7684\u6570\u91cf\uff0c \u4e5f\u5c31\u662f1,2,3\u4e09\u4e2a\u70b9\u53ef\u4ee5\u7ec4\u6210\u7684\u4ee51\u5f00\u5934\u7684\u6392\u5217\u6570\n                            }\n                        if (connect[endPointIndex][lowestIndex] && cnt > 2) {  //\u4ee5\u9996\u5c3e\u5b9a\u70b9\u5206\u6cbb\uff0c\u5b58\u5728\u5bf9\u79f0\u6027\uff0c\u5982 1-2-3-4-1 == 1-4-3-2-1\n                            total += ways[mask][endPointIndex];\n                        }\n                    }\n                }\n            }\n        }\n        writer.println(total / 2);\n    }\n\n    public static void main(String[] args) {\n        new CF_11D().run();\n    }\n\n    BufferedReader reader;\n    StringTokenizer tokenizer;\n    PrintWriter writer;\n\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", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.awt.List;\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class T {\n\tstatic Scanner in = new Scanner();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic boolean adj[][];\n\tstatic int n, m, from;\n\tstatic long memo[][];\n\tstatic long Num_Cycle;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tadj = new boolean[n][n];\n\t\tmemo = new long[n][1 << n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = in.nextInt() - 1;\n\t\t\tint v = in.nextInt() - 1;\n\t\t\tadj[u][v] = adj[v][u] = true;\n\t\t}\n\t\tfor (long arr[] : memo) {\n\t\t\tArrays.fill(arr, -1);\n\t\t}\n\t\tNum_Cycle = 0L;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfrom = i;\n\t\t\tNum_Cycle += dp(from, (1 << i));\n\t\t}\n\t\tout.println(Num_Cycle / 2);\n\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic long dp(int start, int mask) {\n\t\tif (memo[start][mask] != -1) {\n\t\t\treturn (memo[start][mask]);\n\t\t}\n\t\tlong ans = 0L;\n\t\tif (adj[start][from] && Integer.bitCount(mask) >= 3) {// Cycle has\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// atleast 3\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// node and 3\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// edges\n\t\t\tans++;\n\t\t}\n\t\tfor (int i = from + 1; i < n; i++) {\n\t\t\tif (adj[start][i] && ((mask & (1 << i)) == 0)) {\n\t\t\t\tans += dp(i, mask | (1 << i));\n\t\t\t}\n\t\t}\n\t\treturn memo[start][mask] = ans;\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 file) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(file));\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\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n    static boolean[][] matrix;\n    static long[][] dp;\n    static int n;\n    static int m;\n    public static void main(String[] args) {\n        Scanner s = new Scanner(System.in);\n        n = s.nextInt();\n        m = s.nextInt();\n        matrix = new boolean[n][n];\n        for (int i=0; i<m; ++i) {\n            int v1 = s.nextInt()-1;\n            int v2 = s.nextInt()-1;\n            matrix[v1][v2] = true;\n            matrix[v2][v1] = true;\n        }\n        dp = new long[n][1<<n+1];\n        for (int i=0; i<n; ++i) Arrays.fill(dp[i], -1);\n        \n        long res = 0;\n        for (int i=0; i<n; ++i)\n            res += calc(i, i, (1<<i), 1);\n        \n        System.out.println(res/2);\n    }\n    \n    public static long calc(int h, int c, int m, int len) {\n        if (dp[c][m] != -1)\n            return dp[c][m];\n        \n        long ret = 0;\n        if (len > 2 && matrix[c][h])\n            ret = 1;\n        for (int i=h+1; i<n; ++i)\n            if ((m & (1<<i)) == 0 && matrix[c][i])\n                ret += calc(h, i, m | (1<<i), len + 1);\n        return dp[c][m] = ret;\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.PrintStream;\nimport java.util.*;\n\npublic class Template {\n\n    public static void main(String[] args) throws IOException {\n        final Scanner in = new Scanner(System.in);\n        final PrintStream out = System.out;\n        int n = in.nextInt(), m = in.nextInt();\n        boolean[][] g = new boolean[n][n];\n        for (int i = 0; i < m; ++i) {\n            int a = in.nextInt(), b = in.nextInt();\n            --a; --b;\n            g[a][b] = g[b][a] = true;\n        }\n        final int mx = 1<<n;\n        long[][] dp = new long[mx][n];\n        long res = 0;\n        for (int mask = 0; mask < mx; ++mask)\n            for (int i = 0; i < n; ++i) {\n                if (mask == (1 << i)) {\n                    dp[mask][i] = 1;\n                } else if (((mask & (1 << i)) != 0) && ((mask & ((1 << i) - 1)) != 0)) {\n                    long r = 0;\n                    int next = mask ^ (1<<i);\n                    for (int j = 0; j < n; ++j) if (g[i][j]) {\n                        r += dp[next][j];\n                    }\n                    dp[mask][i] = r;\n                } else {\n                    dp[mask][i] = 0;\n                }\n\n                if ((mask & (mask-1)) != 0 && g[i][lowestBit(mask)]) {\n                    res += dp[mask][i];\n                }\n\n            }\n\n        System.out.println((res-m)/2);\n    }\n\n    private static int lowestBit(int mask) {\n        for (int i = 0;;++i) {\n            if ((mask & (1<<i)) > 0) {\n                return i;\n            }\n        }\n    }\n\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main11D {\n\n    private FastScanner in;\n    private PrintWriter out;\n\n    public void solve() throws IOException {\n        int N = in.nextInt();\n        int M = in.nextInt();\n\n        int[][] edges = 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            edges[a][b] = 1;\n            edges[b][a] = 1;\n        }\n\n        int globalCountMasks = 1 << N;\n        int[][] masks = new int[N + 1][];\n        int[] countMasks = new int[N + 1];\n        for(int i = 0; i <= N; i++){\n            masks[i] = new int[combinations(N, i)];\n        }\n        for(int i = 0; i < globalCountMasks; i++){\n            int c = countBit1(i);\n            masks[c][countMasks[c]] = i;\n            countMasks[c]++;\n        }\n\n        long globalCountCycles = 0;\n        long[][] count = new long[globalCountMasks][N];\n\n        for(int a = 0; a < N - 2; a++){\n            int aBit = 1 << a;\n            count[aBit][a] = 1;\n            long countCycles = 0;\n            for(int i = 2; i <= N; i++){\n                for(int m = 0; m < countMasks[i]; m++){\n                    int mask = masks[i][m];\n                    if((mask & aBit) == 0) continue;\n                    if((mask & (aBit - 1)) > 0) continue;\n                    count[mask][a] = 0;\n                    for(int v = a + 1; v < N; v++){\n                        int vBit = 1 << v;\n                        if((mask & vBit) == 0) continue;\n                        count[mask][v] = 0;\n                        for(int t = a; t < N; t++){\n                            if((mask & (1 << t)) == 0 || t == v || edges[v][t] == 0) continue;\n                            count[mask][v] += count[mask ^ vBit][t];\n                        }\n                        if(edges[a][v] == 1 && mask != (aBit | vBit)){\n                            countCycles += count[mask][v];\n                        }\n                    }\n                }\n            }\n            globalCountCycles += countCycles / 2;\n        }\n\n        out.println(globalCountCycles);\n    }\n\n    private int countBit1(int k){\n        int c = 0;\n        while(k > 0){\n            c += k & 1;\n            k >>= 1;\n        }\n        return c;\n    }\n\n    private int combinations(int n, int k){\n        if(k > n || k < 0){\n            throw new IllegalArgumentException();\n        }\n        int r = 1;\n        for(int i = 1; i <= k; i++){\n            r = r * (n + 1 - i) / i;\n        }\n        return r;\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        } 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                } 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 Main11D().run();\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport javax.sound.midi.Synthesizer;\n\n\npublic class Main {\n\t\n\n\tstatic int V;\n\tstatic ArrayList<Integer> adjList [];\n\t\n\tstatic int first(int a){\n\t    int idx = 0;\n\t    while (a > 0 && (a & 1) == 0) {\n\t        idx++;\n\t        a>>=1;\n\t    }\n\t    return idx;\n\t}\n\tstatic long Number_Of_Simple_Cycles () { // Time Complexity O(2 ^ n  * n ^ 2)\n\t\tlong dp [][] = new long[1 << V][V];\n\t\t\n\t\tfor (int i = 0 ; i < V ; ++i)\n\t\t\tdp[1 << i][i] = 1;\n\t\t\n\t\tfor (int mask = 1 ; mask < 1 << V ; ++mask) {\n\t\t\t\tif (Integer.bitCount(mask) <= 1) continue;\n\t\t\t\tfor (int current = 0 ; current < V ; ++current) {\n\t\t\t\t\tif (((1 << current) & mask) == 0) continue;\n\t\t\t\t\t\n\t\t\t\t\tfor (int last : adjList[current])\n\t\t\t\t\t\tif (current != first(mask))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdp[mask][current] += dp[mask ^ (1 << current)][last];\n\t\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\t\n\t\tlong ans = 0 ;\n\t\tint allVisited = (1 << V) - 1;\n\t\tfor (int mask = 1 ; mask < 1 << V ; ++mask) {\n\t\t\tif (Integer.bitCount(mask) < 3) continue;\n\t\t\tfor (int u = 0 ; u < V ; ++u) {\n\t\t\t\tif (adjList[u].contains(first (mask)))\n\t\t\t\t\tans += dp[mask][u];\n\t\t\t}\n\t\t}\n\t\treturn ans >> 1;\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tStringBuilder sb = new StringBuilder();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tV = sc.nextInt();\n\t\tadjList = new ArrayList[V];\n\t\tfor (int i = 0 ; i < V ; ++i) adjList[i] = new ArrayList<>();\n\t\tint E = sc.nextInt();\n\t\twhile (E -- > 0) {\n\t\t\tint v = sc.nextInt() - 1;\n\t\t\tint u = sc.nextInt() - 1;\n\t\t\tadjList[v].add(u);\n\t\t\tadjList[u].add(v);\n\t\t}\n\t\tout.print(Number_Of_Simple_Cycles());\n\t\tout.flush(); \n\t\tout.close();\n\t}\n\n\t\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\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}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class cf11d {\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\tboolean[][] g = new boolean[n][n];\n\t\tboolean[] ok = new boolean[1<<n];\n\t\tint[] f = new int[1<<n];\n\t\tfor(int i=1; i<(1<<n); i++) {\n\t\t\tok[i] = Integer.bitCount(i)>=3;\n\t\t\tf[i] = first(i);\n\t\t}\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] = g[b][a] = true;\n\t\t}\n\t\tlong[][] dp = new long[n][1<<n];\n\t\tfor(int i=0; i<n; i++)\n\t\t\tdp[i][1<<i] = 1;\n\t\tfor(int i=1; i<(1<<n); i++)\n\t\t\tfor(int j=0; j<n; j++)\n\t\t\t\tfor(int k=f[i]+1; k<n; k++)\n\t\t\t\t\tif((i&(1<<k)) == 0 && g[j][k])\n\t\t\t\t\t\tdp[k][i^(1<<k)] += dp[j][i];\n\t\tlong ret = 0;\n\t\tfor(int i=1; i<(1<<n); i++)\n\t\t\tfor(int j=0; j<n; j++)\n\t\t\t\tif(ok[i] && j != f[i])\n\t\t\t\t\tret += g[j][f[i]]?dp[j][i]:0;\n\t\tSystem.out.println(ret/2);\n\t}\n\tstatic int first(int x) {\n\t\tint ret = 0;\n\t\twhile(x%2==0) {\n\t\t\tx/=2;\n\t\t\tret++;\n\t\t}\n\t\treturn ret;\n\t}\n}\n\n/*\n\n19 171\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n5 19\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16\n6 17\n6 18\n6 19\n7 8\n7 9\n7 10\n7 11\n7 12\n7 13\n7 14\n7 15\n7 16\n7 17\n7 18\n7 19\n8 9\n8 10\n8 11\n8 12\n8 13\n8 14\n8 15\n8 16\n8 17\n8 18\n8 19\n9 10\n9 11\n9 12\n9 13\n9 14\n9 15\n9 16\n9 17\n9 18\n9 19\n10 11\n10 12\n10 13\n10 14\n10 15\n10 16\n10 17\n10 18\n10 19\n11 12\n11 13\n11 14\n11 15\n11 16\n11 17\n11 18\n11 19\n12 13\n12 14\n12 15\n12 16\n12 17\n12 18\n12 19\n13 14\n13 15\n13 16\n13 17\n13 18\n13 19\n14 15\n14 16\n14 17\n14 18\n14 19\n15 16\n15 17\n15 18\n15 19\n16 17\n16 18\n16 19\n17 18\n17 19\n18 19\n\n*/", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "//package round11;\n\n\nimport java.io.BufferedOutputStream;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.io.StringReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class D {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n\t\n\tprivate boolean[][] g;\n\t\n\tpublic void solve()\n\t{\n\t\tn = ni();\n\t\tint m = ni();\n\t\tg = new boolean[n][n];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tint f = ni();\n\t\t\tint t = ni();\n\t\t\tg[f-1][t-1] = true;\n\t\t\tg[t-1][f-1] = true;\n\t\t}\n\t\t\n\t\tlong ret = 0L;\n\t\tcache = new long[20 << 19];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tstart = i;\n\t\t\tret += rec(1 << start, i, 0);\n\t\t}\n\t\tout.println(ret/2);\n\t}\n\t\n\tprivate long[] cache;\n\tprivate int n;\n\tprivate int start;\n\t\n\tprivate long rec(int passed, int cur, int depth)\n\t{\n\t\tint code = cur << 19 | passed;\n\t\tif(cache[code] != 0)return cache[code];\n\t\tlong ret = 0L;\n\t\t\n\t\tif(g[cur][start] && depth >= 2)ret++;\n\t\tfor(int i = start + 1;i < n;i++){\n\t\t\tif((passed & (1 << i)) == 0 && g[cur][i]){\n\t\t\t\tret += rec(passed | (1 << i), i, depth + 1);\n\t\t\t}\n\t\t}\n\t\t\n\t\tcache[code] = ret;\n\t\treturn ret;\n\t}\n\t\n\tpublic void run() throws Exception\n\t{\n//\t\tint m = 19;\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(m + \" \");\n//\t\tsb.append((m*(m-1)/2) + \" \");\n//\t\tfor(int i = 1;i <= m;i++){\n//\t\t\tfor(int j = i + 1;j <= m;j++){\n//\t\t\t\tsb.append(i + \" \" + j + \"\\n\");\n//\t\t\t}\n//\t\t}\n//\t\t\n//\t\tin = new Scanner(new StringReader(sb.toString()));\n//\t\tin = new Scanner(new StringReader(\"4 6 1 2 1 3 1 4 2 3 2 4 3 4\"));\n\t\tin = new Scanner(System.in);\n\t\tSystem.setOut(new PrintStream(new BufferedOutputStream(System.out)));\n\t\tout = new PrintWriter(System.out);\n\t\t\n//\t\tint n = in.nextInt();\n\t\tint n = 1;\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\tlong t = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t\tSystem.err.printf(\"%04d/%04d %7d%n\", i, n, System.currentTimeMillis() - t);\n\t\t}\n\t}\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\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }\n\tprivate void tra(int[] a) {System.out.println(Arrays.toString(a));}\n\tprivate void tra(int[][] a)\n\t{\n\t\tfor(int[] e : a){\n\t\t\tSystem.out.println(Arrays.toString(e));\n\t\t}\n\t}\n\t\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class B {\n    static int first(int n)\n    {\n\tint res = 0;\n\twhile(n > 0 && (n & 1) == 0){\n\t    n >>= 1;\n\t    res++;\n\t}\n\treturn res;\n    }\n    public static void main(String[] args) throws Exception\n    {\n\tScanner bf = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tint n = bf.nextInt(), m = bf.nextInt();\n\tArrayList<Integer> [] adjList = new ArrayList[n];\n\tfor (int i = 0; i < adjList.length; i++)\n\t{\n\t    adjList[i] = new ArrayList<Integer>();\n\t}\n\tfor (int i = 0; i < m; i++)\n\t{\n\t    int u = bf.nextInt()-1, v = bf.nextInt()-1;\n\t    adjList[u].add(v);\n\t    adjList[v].add(u);\n\t}\n\tlong [][] memo = new long[(1<<n)][n];\n\tfor (int i = 0; i < n; i++)\n\t{\n\t    memo[1<<i][i] = 1;\n\t}\n\tlong ans = 0;\n\tfor (int i = 1; i < 1<<n; i++)\n\t{\n\t    if(Integer.bitCount(i) == 1) continue;\n\t    for (int j = 0; j < n; j++)\n\t    {\n\t\tif((i & (1<<j)) == 0 || j == first(i)) continue;\n\t\tfor(int v:adjList[j])\n\t\t    memo[i][j] += memo[i^(1<<j)][v];\n\t    }\n\t}\n\tfor (int i = 1; i < 1<<n; i++)\n\t{\n\t    if(Integer.bitCount(i) < 3) continue;\n\t    int t = first(i);\n\t    for (int j = 0; j < n; j++)\n\t    {\n\t\tif(adjList[j].contains(t))\n\t\t    ans += memo[i][j];\n\t    }\n\t}\n\tout.println(ans/2);\n\tout.flush();\n\tout.close();\n    }\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 Scanner(FileReader fileReader)\n\t{\n\t    br = new BufferedReader(fileReader);\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 boolean ready() throws IOException\n\t{\n\t    return br.ready();\n\t}\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n\tstatic long[][] memo;\n\tstatic boolean[][] adjMat;\n\tstatic int N, endNode;\n\tstatic ArrayList<Integer>[] bits;\n\t\n\tstatic long dp(int idx, int msk)\t//complexity = N * 2^(N + 1)\n\t{\t\n\t\tif(memo[idx][msk] != -1)\n\t\t\treturn memo[idx][msk];\n\t\tlong ret = adjMat[idx][endNode] ? 1 : 0;\n\t\tfor(int i = 0, sz = bits[msk].size(); i < sz; ++i)\n\t\t{\n\t\t\tint j = bits[msk].get(i);\n\t\t\tif(j > endNode)\n\t\t\t\tbreak;\n\t\t\tif(adjMat[idx][j])\n\t\t\t\tret += dp(j, msk | 1 << j);\n\t\t}\n\t\treturn memo[idx][msk] = ret;\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\n\t\tN = sc.nextInt();\n\t\tadjMat = new boolean[N][N];\n\t\t\n\t\tbits = new ArrayList[1 << N];\n\t\tfor(int i = 0; i < 1 << N; ++i)\n\t\t{\n\t\t\tbits[i] = new ArrayList<>(1);\n\t\t\tfor(int j = 0; j < N; ++j)\n\t\t\t\tif((i & 1 << j) == 0)\n\t\t\t\t\tbits[i].add(j);\n\t\t}\n\t\tint M = sc.nextInt();\n\t\twhile(M-->0)\n\t\t{\n\t\t\tint u = sc.nextInt() - 1, v = sc.nextInt() - 1;\n\t\t\tadjMat[u][v] = adjMat[v][u] = true;\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = N; i > 1; --i)\n\t\t{\n\t\t\tmemo = new long[i][1 << i];\n\t\t\tfor(long[] x: memo)\n\t\t\t\tArrays.fill(x, -1);\n\t\t\tans += dp(endNode = i - 1, 1 << endNode);\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(adjMat[i][j])\n\t\t\t\t\t--ans;\n\t\tout.println(ans >> 1);\n\t\tout.flush();\n\t\tout.close();\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 { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class D11 {\n\tstatic boolean[][] g;\n\tstatic int n, m;\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\tm = input.nextInt();\n\tg = new boolean[n][n];\n\tfor(int i = 0; i<m; i++)\n\t{\n\t\tint a = input.nextInt()-1, b = input.nextInt()-1;\n\t\tg[a][b] = g[b][a] = true;\n\t}\n\tlong res = 0;\n\tmap = new HashMap<Integer, Long>();\n\tfor(int i = n-1; i>=0; i--)\n\t{\n\t\tmemo = new long[i+1][1<<(i+1)];\n\t\tfor(long[] A : memo) Arrays.fill(A, -1);\n\t\tres += count(i, i, 1<<i)/2;\n\t}\n\tout.println(res);\n\tout.close();\n}\nstatic long[][] memo;\nstatic HashMap<Integer, Long> map;\nstatic long count(int at, int start, int mask)\n{\n\tif(memo[at][mask] != -1) return memo[at][mask];\n\tint bits = Integer.bitCount(mask);\n\tif(at == start && bits > 2) return 1;\n\tlong res = 0;\n\tfor(int i = 0; i<=start; i++)\n\t{\n\t\tif(!g[at][i]) continue;\n\t\tif(i != start && (mask & (1<<i)) > 0) continue;\n\t\tif(i == start && bits <= 2) continue;\n\t\tres += count(i, start, mask | (1<<i));\n\t}\n\treturn memo[at][mask] = res;\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", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.BufferedReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author ATailouloute\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        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, QuickScanner in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            boolean[][] is = new boolean[n][n];\n            for (int i = 0; i < n; i++) {\n                is[i][i] = true;\n            }\n            long[][] dp = new long[1 << n | 1][n];\n            for (int i = 0; i < m; i++) {\n                int u = in.nextInt() - 1;\n                int v = in.nextInt() - 1;\n                is[u][v] = is[v][u] = true;\n                dp[(1 << u) + (1 << v)][v] = 1;\n                dp[(1 << u) + (1 << v)][u] = 1;\n            }\n            int k = 0;\n            long res = 0;\n            for (int mask = 1; mask < 1 << n; ++mask) {\n                boolean f = true;\n                for (int i = 0; i < n; i++) {\n                    if ((mask & (1 << i)) != 0 && dp[mask][i] == 0) {\n                        if (f) {\n                            f = false;\n                            k = i;\n                        } else {\n                            for (int j = k + 1; j < n; j++) {\n                                if ((mask & (1 << j)) != 0 && is[i][j]) {\n                                    dp[mask][i] += dp[mask - (1 << i)][j];\n                                }\n                            }\n                        }\n                        if (is[k][i]) res += dp[mask][i];\n                    }\n                }\n            }\n            out.println(res >> 1);\n        }\n\n    }\n\n    static class QuickScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        InputStream is;\n\n        public QuickScanner(InputStream stream) {\n            is = stream;\n            br = new BufferedReader(new InputStreamReader(stream), 32768);\n        }\n\n        String nextToken() {\n            while (st == null || !st.hasMoreElements()) {\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        int nextInt() {\n            return Integer.parseInt(nextToken());\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class Main implements Runnable {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry {\n\t\t\trun1();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tint nextInt(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn (int) st.nval;\n\t}\n\n\tprivate List<Integer> kmp(String x, String a) {\n\t\tString s = a + \"$\" + x;\n\t\tint[] oppa = new int[s.length()];\n\t\toppa[0] = 0;\n\t\tint tmp = 0;\n\t\tList<Integer> res = new ArrayList<Integer>();\n\t\tfor (int i = 1; i < s.length(); i++) {\n\t\t\twhile (tmp != 0 && s.charAt(tmp) != s.charAt(i)) {\n\t\t\t\t// System.out.println(i + \" \" + tmp);\n\t\t\t\ttmp = oppa[tmp - 1];\n\t\t\t}\n\t\t\tif (s.charAt(tmp) == s.charAt(i))\n\t\t\t\ttmp++;\n\t\t\toppa[i] = tmp;\n\t\t\tif (tmp == a.length()) {\n\t\t\t\tres.add(i - a.length() - a.length());\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tdouble nextDouble(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.nval;\n\t}\n\n\tString nextLine(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.sval;\n\t}\n\n\tpublic void run1() throws IOException {\n\t\tScanner sc = new Scanner(new InputStreamReader(System.in));\n\t\t// Scanner sc = new Scanner(new FileReader(\"input.txt\"));\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tboolean[][] arr = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = sc.nextInt();\n\t\t\tint b = sc.nextInt();\n\t\t\tarr[a - 1][b - 1] = true;\n\t\t\tarr[b - 1][a - 1] = true;\n\t\t}\n\t\tlong[][] res = new long[n][1 << n];\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tint min = -1;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif ((mask & (1 << i)) != 0) {\n\t\t\t\t\tif (min == -1) {\n\t\t\t\t\t\tmin = i;\n\t\t\t\t\t\tif (mask == (1 << min))\n\t\t\t\t\t\t\tres[min][mask] = 1;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int j = min + 1; j < n; j++)\n\t\t\t\t\t\tif ((mask & (1 << j)) == 0 && arr[i][j]) {\n\t\t\t\t\t\t\tres[j][mask | (1 << j)] += res[i][mask];\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong r = 0;\n\t\tfor (int mask = 1; mask < (1 << n); mask++)\n\t\t\tif (Integer.bitCount(mask) != 2)\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tint i = 0;\n\t\t\t\t\twhile ((mask & (1 << i)) == 0)\n\t\t\t\t\t\ti++;\n\t\t\t\t\tif (arr[i][j])\n\t\t\t\t\t\tr += res[j][mask];\n\t\t\t\t}\n\t\tSystem.out.println(r / 2);\n\t}\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "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.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class D {\n    static boolean[][] adj;\n    static int n;\n    static int first;\n\n    public static void main(String[] args) throws IOException {\n        InputReader in = new InputReader();\n        n = in.nextInt();\n//       n = 19;?\n        int m = in.nextInt();\n        adj = new boolean[n][n];\n//       for (int i = 0; i < n; i++) {\n//       for (int j = 0; j < n; j++) {\n//       adj[i][j] = true;\n//       }\n//       }\n        dp = new long[1 << n][n];\n        for (int i = 0; i < m; i++) {\n            int f = in.nextInt() - 1;\n            int t = in.nextInt() - 1;\n            adj[f][t] = adj[t][f] = true;\n        }\n\n        boolean[] v = new boolean[1 << n];\n        long res = 0;\n        for (int f = 0; f < n; f++) {\n            first = f;\n            int cnt;\n            for (int i = 0; i < 1 << n; i+=(1<<first))\n                if ((i & (1 << first)) == 0)\n                    for (int j = 0; j < n; j++)\n                        dp[i][j] = -1;\n            \n            for (int i = 0; i < 1 << n; i+= (1<<first)) {\n                cnt = Integer.bitCount(i);\n                if ((i & (1 << first)) == 0 && !v[i | (1 << first)] && cnt > 1) {\n                    v[i | (1 << first)] = true;\n                    res += solve(i, first, cnt);\n                }\n            }\n        }\n        System.out.println(res / 2);\n    }\n\n    static long[][] dp;\n\n    public static long solve(int msk, int lst, int cnt) {\n        if (cnt == 0)\n            return (adj[lst][first]) ? 1 : 0;\n        if (dp[msk][lst] != -1)\n            return dp[msk][lst];\n        long res = 0;\n        for (int i = 0; i < n; i++)\n            if (adj[lst][i] && (msk & (1 << i)) > 0)\n                res += solve(msk ^ (1 << i), i, cnt - 1);\n        return dp[msk][lst] = res;\n    }\n\n    static class InputReader {\n        BufferedReader in;\n        StringTokenizer st;\n\n        public InputReader() throws IOException {\n            in = new BufferedReader(new InputStreamReader(System.in));\n            st = new StringTokenizer(in.readLine());\n        }\n\n        public String next() throws IOException {\n            while (!st.hasMoreElements())\n                st = new StringTokenizer(in.readLine());\n            return st.nextToken();\n        }\n\n        public int nextInt() throws NumberFormatException, IOException {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() throws NumberFormatException, IOException {\n            return Long.parseLong(next());\n        }\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile ( sc.hasNextInt() ) {\n\t\t\tint n = sc.nextInt();\n\t\t\tlong m = sc.nextInt();\n\t\t\tboolean edge[][] = new boolean[n][n];\n\t\t\tlong dp[][] = new long[1<<n][n];\n\t\t\tfor ( long i = 1 ; i<=m ; ++i ) {\n\t \t\t\tint u = sc.nextInt();   \n\t\t\t\tint v = sc.nextInt();\n\t\t\t\t-- u;\n\t\t\t\t-- v;\n\t\t\t\tedge[u][v] = edge[v][u] = true;\n\t\t\t}\n\t\t\tfor ( int i = 0 ; i<n ; ++i ) {\n\t\t\t\tdp[1<<i][i] = 1;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor ( int i = 1 ; i<(1<<n) ; ++i ) {\n\t\t\t\tint first = cal(i);\n\t\t\t\tfor ( int j = 0 ; j<n ; ++j ) {\n\t\t\t\t\tif ( dp[i][j]==0 ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor ( int k = first ; k<n ; ++k ) {\n \t\t\t\t\t\tif ( j==k || !edge[j][k] ) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( k==first && (i&(1<<k))!=0 ) {\n\t\t\t\t\t\t\tres += dp[i][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( (i&(1<<k))==0 ) {\n\t\t\t\t\t\t\tdp[i|(1<<k)][k] += dp[i][j];\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\tres -= m;\n\t\t\tSystem.out.println(res/2);\t\t\n\t\t}\n\t}\n\tpublic static int cal( int x ) {\n\t\tint ord = 0;\n\t\twhile ( true ) {\n\t\t\tif ( (x&(1<<ord))!=0 ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++ ord;\n\t\t}\n\t\treturn ord;\n\t}\n\tpublic static boolean judge( int x ) {\n\t\tint cnt = 0;\n\t\twhile ( x>=1 ) {\n\t\t\tif ( (x&1)==1 ) {\n\t\t\t\t++ cnt;\n\t\t\t}\n\t\t\tx >>= 1;\n\t\t}\n\t\treturn cnt >= 3;\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\n\n/**\n * Created by Tejas on 18-10-2018.\n */\npublic class Main {\n\n    static HashSet<Integer> adjList[];\n    public static void main(String[]args)throws IOException{\n        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));\n        StringBuilder stringBuilder=new StringBuilder();\n\n        String temp[]=bufferedReader.readLine().split(\" \");\n        int V=Integer.parseInt(temp[0]);\n        int E=Integer.parseInt(temp[1]);\n        adjList=new HashSet[V];\n        for(int i=0;i<V;i++)\n            adjList[i]=new HashSet<>();\n        for(int i=0;i<E;i++){\n            temp=bufferedReader.readLine().split(\" \");\n            int x=Integer.parseInt(temp[0])-1;\n            int y=Integer.parseInt(temp[1])-1;\n            adjList[y].add(x);\n            adjList[x].add(y);\n\n        }\n        stringBuilder.append(solve(V)+\"\\n\");\n        System.out.println(stringBuilder);\n    }\n\n    private static long solve(int V) {\n\n        long dp[][]=new long[(1<<V)][V];\n\n        for(int i=0;i<V;i++)\n            dp[(1<<i)][i]=1;\n        for(int mask=1;mask<(1<<V);mask++){\n            // HW starting at pos first and ending at j.\n            int first = Integer.numberOfTrailingZeros(mask);\n            for(int i=0;i<V;i++){\n                if((mask&(1<<i))==0 || first==i) continue;\n                for (int j = 0; j < V; j++)\n                    if (adjList[i].contains(j) && (mask & (1<<j))!=0)\n                        dp[mask][i] += dp[mask ^ (1 << i)][j];\n            }\n        }\n        //Calculating simple cycles\n        long count=0;\n        for(int mask=1;mask<(1<<V);mask++) {\n            int first = Integer.numberOfTrailingZeros(mask);\n            if (Integer.bitCount(mask)>=3)\n                for (int i = 0; i < V; i++) {\n                    if(adjList[first].contains(i))\n                        count+=dp[mask][i];\n                }\n        }\n        return count/2;\n\n\n    }\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\n    private StreamTokenizer in;\n    private BufferedWriter out;\n\n    public void solve() throws Exception {\n        int n = nextInt(), m = nextInt();\n        int[] ss = new int[n];\n        for (int i=0; i<m; i++)\n        {\n            int a = nextInt(), b = nextInt();\n            a--;b--;\n            ss[a]|=1<<b;\n            ss[b]|=1<<a;\n        }\n        long[][] res = new long[n][1<<n];\n        int[] cnt = new int[1<<n], first = new int[1<<n];\n        for (int i=0; i<n; i++)\n        {\n            res[i][1<<i] = 1;\n            first[1<<i] = i;\n            cnt[1<<i] = 1;\n        }\n        long ans = 0;\n        for (int mask = 0; mask<1<<n; mask++)\n        {\n            for (int last = first[mask]; last<n; last++)\n            {\n                if (res[last][mask]==0)\n                    continue;\n                if (cnt[mask]>2)\n                {\n                    if ((ss[last]&(1<<first[mask]))!=0)\n                        ans+=res[last][mask];\n                }\n                int m2 = (~mask) & ss[last];\n                for (int next = first[mask]+1; next<n; next++)\n                {\n                    if ((m2&(1<<next))==0) continue;\n                    int mask2 = mask|1<<next;\n                    res[next][mask2]+=res[last][mask];\n                    cnt[mask2] = cnt[mask]+1;\n                    first[mask2] = first[mask];\n                }\n            }\n        }\n        ans/=2;\n        out.write(ans+\"\\n\");\n    }\n    \n    public int nextInt() throws Exception\n    {\n        in.nextToken();\n        return (int)in.nval;\n    }\n\n    public void run() {\n        try {\n            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n            out = new BufferedWriter(new OutputStreamWriter(System.out));\n            solve();\n            out.flush();\n        } catch (Exception e) {\n            e.printStackTrace();\n            System.exit(1);\n        }\n    }\n\n    public static void main(String[] args) {\n        new Main().run();\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\nimport static java.lang.Integer.bitCount;\nimport static java.lang.Integer.numberOfTrailingZeros;\nimport static java.lang.System.out;\n\n/**\n * 11D\n *\n * @author artyom\n */\npublic class ASimpleTask {\n    public static void main(String args[]) {\n        Scanner sc = new Scanner(System.in);\n        int n = sc.nextInt();\n        int[][] d = new int[n][n];\n        for (int i = 0, m = sc.nextInt(); i < m; i++) {\n            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;\n            d[a][b] = 1;\n            d[b][a] = 1;\n        }\n        long[][] dp = new long[1 << n][n];\n\n        // SOLUTION BEGINS\n        for (int mask = 1; mask < 1 << n; mask++) {\n            int start = numberOfTrailingZeros(mask); // the starting vertex of a Hamiltonian walk\n            if (bitCount(mask) == 1) {\n                dp[mask][start] = 1;\n                continue;\n            }\n            for (int i = 0; i < n; i++) {\n                if ((mask & (1 << i)) > 0 && i != start) {\n                    int xmask = mask ^ (1 << i); // mask without vertex i\n                    for (int j = 0; j < n; j++) {\n                        if (d[j][i] > 0) {\n                            dp[mask][i] += dp[xmask][j];\n                        }\n                    }\n                }\n            }\n        }\n        // SOLUTION ENDS\n\n        long sum = 0;\n        for (int mask = 1; mask < 1 << n; mask++) {\n            if (bitCount(mask) >= 3) { // We need at least 3 vertices for a cycle\n                for (int i = 0; i < n; i++) {\n                    if (d[numberOfTrailingZeros(mask)][i] > 0) {\n                        sum += dp[mask][i];\n                    }\n                }\n            }\n        }\n        out.print(sum / 2);\n    }\n}", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\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.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\n\npublic class Main implements Runnable {\t\n\t\n\tint n;\n\tlong[][] f;\n\tboolean[][] e;\n\t\n\tint bit(int value) {\n\t\treturn (1<<value);\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tint m = nextInt();\n\t\tf = new long[1<<n][n];\n\t\te = new boolean[n][n];\n\t\tfor (int i = 0; i < (1<<n); ++i) {\n\t\t\tfor (int j = 0; j < n; ++j) {\n\t\t\t\tf[i][j] = -1;\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\tf[bit(i)|bit(j)][j] = 0;\n\t\t\t\te[i][j] = false;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint u = nextInt()-1;\n\t\t\tint v = nextInt()-1;\n\t\t\te[u][v] = true;\n\t\t\te[v][u] = true;\n\t\t\tif (u < v) {\n\t\t\t\tf[bit(u)|bit(v)][v] = 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tf[bit(v)|bit(u)][u] = 1;\n\t\t\t}\n\t\t}\n\t\tlong answer = 0;\n\t\tfor (int i = 1; i < (1<<n); ++i) {\n\t\t\tint start = 0;\n\t\t\twhile (((1<<start)&i) == 0) {\n\t\t\t\t++start;\n\t\t\t}\n\t\t\tint s = bit(start);\n\t\t\tfor (int nxt = start+1; nxt < n; ++nxt) {\n\t\t\t\tint b = bit(nxt);\n\t\t\t\tif ((b&i) > 0 && (b|s) != i) {\n\t\t\t\t\tif (e[start][nxt]) {\n\t\t\t\t\t\tanswer += clc(i, nxt);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriter.print(answer>>1);\n\t}\n\t\n\tlong clc(int maska, int last) {\n\t\tif (f[maska][last] == -1) {\n\t\t\tint first = 0;\n\t\t\twhile (((1<<first)&maska) == 0) {\n\t\t\t\t++first;\n\t\t\t}\n\t\t\tf[maska][last] = 0;\n\t\t\tfor (int b = first+1; b < n; ++b) {\n\t\t\t\tif ((bit(b)&maska)>0) {\n\t\t\t\t\tif (e[b][last]) {\n\t\t\t\t\t\tf[maska][last] += clc(maska^bit(last), b);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\t\t\n\t\t}\n\t\treturn f[maska][last];\n\t}\n\t\n\tpublic static void main(String[] args) throws InterruptedException {\n\t\t new Thread(null, new Runnable() {\n            public void run() {\n                new Main().run();\n            }\n\t     }, \n\t     \"1\", \n\t     1 << 25).start();\n\t}\n\t\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tboolean fromStandart = true;\n\t\t\treader = new BufferedReader(fromStandart ? new InputStreamReader(System.in) : new FileReader(INFILE));\n            writer = new PrintWriter(new BufferedWriter(fromStandart ? new OutputStreamWriter(System.out) : new FileWriter(OUTFILE)));\n\t\t\ttokenizer = null; \n\t\t\tsolve();\n\t\t\twriter.flush();\n\t\t} catch (Exception error) {\n\t\t\terror.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\t\n\tstatic final String INFILE = \"input.txt\";\n\tstatic final String OUTFILE = \"output.txt\";\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n    PrintWriter writer;\n\n\tint 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 nextString() throws IOException {\n    \treturn reader.readLine();\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    } \t\n\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class D11 {\n\tstatic HashMap<State, Integer> map;\n\tstatic long[][] ans;\n\tstatic boolean[][] connect;\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\tmap = new HashMap<State, Integer>();\n\t\tconnect = new boolean[n][n];\n\t\tans = new long[n][1<<n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tArrays.fill(ans[i], -1);\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\twhile(m-- > 0)\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\ta--;\n\t\t\tb--;\n\t\t\tconnect[a][b] = connect[b][a] = true;\n\t\t}\n\t\tlong ret = 0;\n\t\tint mask = 1 << n;\n\t\tmask--;\n\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\tfor(int out = i+1; out < n; out++)\t{\n\t\t\t\tif(connect[i][out])\t{\n\t\t\t\t\tret += solve(mask - (1<<out), out, true);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmask -= (1<<i);\n\t\t}\n\t\tSystem.out.println(ret/2);\n\t}\n\tpublic static long solve(int mask, int start, boolean a)\t{\n\t\tif(ans[start][mask] != -1)\n\t\t\treturn ans[start][mask];\n\t\tint end = 0;\n\t\twhile((mask & (1<<end)) == 0)\n\t\t\tend++;\n\t\tlong ret = 0;\n\t\tfor(int out = 0; out < connect.length; out++)\t{\n\t\t\tif(connect[start][out] && (mask & (1 << out)) != 0)\t{\n\t\t\t\tif(out == end)\t{\n\t\t\t\t\tif(!a)\n\t\t\t\t\t\tret++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tret += solve(mask - (1<<out), out, false);\n\t\t\t}\n\t\t}\n\t\tans[start][mask] = ret;\n\t\treturn ret;\n\t}\n\tstatic class State\t{\n\t\tpublic byte start, go;\n\t\tpublic int mask;\n\t\tpublic State(byte a, byte b, int c)\t{\n\t\t\tstart = a;\n\t\t\tgo = b;\n\t\t\tmask = c;\n\t\t}\n\t\tpublic int hashCode()\t{\n\t\t\treturn 10007*mask + 43 * start + go;\n\t\t}\n\t\tpublic boolean equals(Object o)\t{\n\t\t\tState s = (State)o;\n\t\t\treturn start == s.start && go == s.go && mask == s.mask;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "11_D. A Simple Task", "from": "CODEFORCES"}
{"src": "import javafx.util.Pair;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashMap;\n\npublic class ElongatedMatrix {\n    private static int n;\n    /**\n     * if the rows are arranged in some permutation [p_1, p_2,...i,j,...p_n],\n     * 1!=i!=j!=n, minCost[i][j] is the min k for any permutation with i&j adjacent\n     **/\n    private static int[][] minCost;\n    /**\n     * minCostEndpoints[i][j] is the min k for any permutation such that\n     * the rows are arranged in some permutation [i, p_2, ... p_{n-1}, j],\n     **/\n    private static int[][] minCostEndpoints;\n\n    /**\n     * Max k of a path over a subset of all rows ending at a certain vertex\n     * The first 16 bits of the key represent the subset. Node n is in the subset iff (x & (2 << n))!=0\n     * key/(1<<16) is the end vertex number\n     */\n    private static HashMap<Integer, Integer> costs = new HashMap<>();\n\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n        int[] params = Arrays.stream(br.readLine().split(\" \"))\n                .mapToInt(x -> Integer.parseInt(x)).toArray();\n        n = params[0];\n        int m = params[1];\n        int[][] matrix = new int[n][m];\n        for (int i = 0; i < n; i++) {\n            matrix[i] = Arrays.stream(br.readLine().split(\" \"))\n                    .mapToInt(x -> Integer.parseInt(x)).toArray();\n        }\n        minCost = new int[n][n];\n        minCostEndpoints = new int[n][n];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (i > j) {\n                    minCost[i][j] = Integer.MAX_VALUE;\n                    for (int k = 0; k < m; k++) {\n                        int diff = Math.abs(matrix[i][k] - matrix[j][k]);\n                        if (diff < minCost[i][j]) {\n                            minCost[i][j] = diff;\n                        }\n                    }\n                    minCost[j][i] = minCost[i][j];\n                }\n                minCostEndpoints[i][j] = Integer.MAX_VALUE;\n                for (int k = 0; k < m - 1; k++) {\n                    int diff = Math.abs(matrix[i][k + 1] - matrix[j][k]);\n                    if (diff < minCostEndpoints[i][j]) {\n                        minCostEndpoints[i][j] = diff;\n                    }\n                }\n            }\n        }\n        int maxCost = n == 1 ? minCostEndpoints[0][0] : 0;\n        for (int i = 0; i < n; i++) {\n            costs.clear();\n            for (int j = 0; j < n; j++) {\n                if (i != j) {\n                    int bitmask = (1 << i) | (1 << j);\n                    int state = bitmask + (j << 16);\n                    costs.put(state, minCost[i][j]);\n                }\n            }\n            for (int j = 0; j < n; j++) {\n                if (i != j) {\n                    if (minCostEndpoints[i][j] <= maxCost) {\n                        continue;\n                    } else {\n                        int pathCost = Math.min(minCostEndpoints[i][j], findMaxCost(i, j, (1 << n) - 1));\n                        maxCost = Math.max(maxCost, pathCost);\n                    }\n                }\n            }\n        }\n        System.out.println(maxCost);\n        br.close();\n    }\n\n    //find the minimum cost starting at st, ending at end, and using only the rows in set\n    private static int findMaxCost(int st, int end, int set) {\n        int state = set + (end << 16);\n        if (costs.containsKey(state)) {\n            return costs.get(state);\n        }\n        int maxCost = 0;\n        for (int i = 0; i < n; i++) {\n            if (i != st && i != end && (set & (1 << i)) != 0) {\n                int setWithoutEnd = set - (1 << end);\n                int pathCost = Math.min(findMaxCost(st, i, setWithoutEnd), minCost[i][end]);\n                maxCost = Math.max(pathCost, maxCost);\n            }\n        }\n        costs.put(state, maxCost);\n        return maxCost;\n    }\n}\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.awt.image.BufferedImage;\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 ElongatedMatrix {\n\tstatic int[][][] memo;\n\tstatic int mn1[][];\n\tstatic int mn2[][];\n\tstatic int r, c;\n\n\tstatic int dp(int mask, int first, int lastvisited) {\n\t\tif (memo[first][lastvisited][mask] != -1)\n\t\t\treturn memo[first][lastvisited][mask];\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < r; i++) {\n\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\tif (Integer.bitCount(mask) != r - 1) {\n\t\t\t\t\tans = Math.max(ans, Math.min(mn1[lastvisited][i], dp(((mask) | (1 << i)), first, i)));\n\t\t\t\t} else\n\t\t\t\t\tans = Math.max(ans, Math.min(mn2[first][i], mn1[lastvisited][i]));\n\t\t\t}\n\t\t}\n\t\t//System.out.println(ans);\n\t\treturn memo[first][lastvisited][mask] = ans;\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\tPrintWriter out = new PrintWriter(System.out);\n\t\tr = Integer.parseInt(st.nextToken());\n\t\t\n\t\tc = Integer.parseInt(st.nextToken());\n\t\tint[][] arr = new int[r][c];\n\t\tmemo = new int[r][r][1 << r];\n\t\tmn1 = new int[r][r];\n\t\tmn2 = new int[r][r];\n\t\tfor(int i=0;i<r;i++) {\n\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\tfor(int j=0;j<c;j++) {\n\t\t\t\tarr[i][j]=Integer.parseInt(st.nextToken());\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < r; i++) {\n\t\t\tArrays.fill(mn1[i], (int)1e9);\n\t\t\tArrays.fill(mn2[i], (int)1e9);\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < r; i++) {\n\t\t\tfor (int j = 0; j < r; j++) {\n\t\t\t\tArrays.fill(memo[i][j], -1);\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < r; i++) {\n\t\t\tfor (int j = 0; j < r; j++) {\n\t\t\t\tfor (int k = 0; k < c; k++) {\n\t\t\t\t\t\n\t\t\t\t\tmn1[i][j] = Math.min(mn1[i][j], Math.abs(arr[i][k] - arr[j][k]));\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 < r; i++) {\n\t\t\tfor (int j = 0; j < r; j++) {\n\t\t\t\tfor (int k = 0; k < c-1; k++) {\n\t\t\t\t\t\n\t\t\t\t\tmn2[i][j] = Math.min(mn2[i][j], Math.abs(arr[j][k] - arr[i][k + 1]));\n\t\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 i = 0; i < r; i++) {\n\t\t\tans=Math.max(ans, dp(1<<i,i,i));\n\t\t}\n\t\tif(r==1)\n\t\t\tans=mn2[0][0];\n\t\tout.println(ans);\n\t\tout.flush();\n\t}\n\n}\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "//package ;\nimport java.io.*;\nimport java.util.*;\n\npublic class D {\n\tstatic int dp(int i,int start,int msk)\n\t{\n\t\tif(Integer.bitCount(msk)==n)\n\t\t\treturn s_e[i][start];\n\n\t\tif(dp[i][start][msk]!=-1)\n\t\t\treturn dp[i][start][msk];\n\t\t\n\t\tint max=0;\n\t\tfor(int k=0;k<n;k++)\n\t\t{\t\n\t\t\tint min=Integer.MAX_VALUE;\n\t\t\tif((msk & (1<<k)) == 0 )\n\t\t\t{\n\t\t\t\tmin=diff[i][k];\n\t\t\t\tmin=Math.min(min, dp(k,start,msk | (1<<k)));\n\t\t\t\tmax=Math.max(max, min);\n\t\t\t}\n\t\t}\n\t\treturn dp[i][start][msk]=max;\n\t}\n\tstatic int n,m,a[][],dp[][][],diff[][],s_e[][];\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();\n\t\tm=sc.nextInt();\n\t\ta=new int[n][m];\n\t\tdiff=new int[n][n];\n\t\ts_e=new int[n][n];\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]=sc.nextInt();\n\t\t\n\t\tdp=new int[n][n][70000];\n\t\tint ans=0;\n\t\tfor(int i=0;i<n;i++)\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t{\t\n\t\t\t\tArrays.fill(dp[i][j], -1);\n\t\t\t\tdiff[i][j]=Integer.MAX_VALUE;\n\t\t\t\ts_e[i][j]=Integer.MAX_VALUE;\n\t\t\t\tfor(int k=0;k<m-1;k++)\n\t\t\t\t{\t\n\t\t\t\t\tdiff[i][j]=Math.min(Math.abs(a[i][k]-a[j][k]), diff[i][j]);\n\t\t\t\t\ts_e[i][j]=Math.min(Math.abs(a[i][k]-a[j][k+1]), s_e[i][j]);\n\t\t\t\t}\n\t\t\t\tdiff[i][j]=Math.min(Math.abs(a[i][m-1]-a[j][m-1]), diff[i][j]);\n\t\t\t}\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t\tans=Math.max(ans, dp(i,i,1<<i));\n\t\t\n\t\tpw.print(ans);\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", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\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 long gcd(long a,long b){ if(b==0)return a;return gcd(b,a%b); }\n    static long modPow(long a,long p,long m){ if(a==1)return 1;long ans=1;while (p>0){ if(p%2==1)ans=(ans*a)%m;a=(a*a)%m;p>>=1; }return ans; }\n    static long modInv(long a,long m){return modPow(a,m-2,m);}\n    static long sol_x,sol_y,gcd_a_b;\n    static void extendedEuclid(long a,long b){ if(b==0){gcd_a_b=a;sol_x=1;sol_y=0; } else{ extendedEuclid(b,a%b);long temp = sol_x;sol_x=sol_y;sol_y = temp - (a/b)*sol_y; } }\n    static class Bhavansort{ Random random;Bhavansort(int a[]){ randomArray(a); sort(a);}Bhavansort(long a[]){ randomArray(a); sort(a);}static int[] sort(int a[]){ Arrays.sort(a);return a;}static long[] sort(long a[]){ Arrays.sort(a);return a; }void randomArray(long a[]){ int n=a.length;for(int i=0;i<n;i++){ int p=random.nextInt(n)%n;long tm=a[i];a[i]=a[p];a[p]=tm; } }void randomArray(int a[]){ int n=a.length;for(int i=0;i<n;i++){ int p=random.nextInt(n)%n;int tm=a[i];a[i]=a[p];a[p]=tm; } }}\n\n\n\n    public void run() {\n        InputReader sc = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n\n        int n=sc.nextInt();\n        int m=sc.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]=sc.nextInt();\n            }\n        }\n\n        int cost[][]=new int[n][n];\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j <n ; j++) {\n                cost[i][j]=Integer.MAX_VALUE;\n                for (int k = 0; k <m ; k++) {\n                    cost[i][j]=Math.min(cost[i][j],Math.abs(a[i][k]-a[j][k]));\n                }\n            }\n        }\n\n        int costRight[][]=new int[n][n];\n        for (int i = 0; i <n ; i++) {\n            for (int j = 0; j <n ; j++) {\n                costRight[i][j]=Integer.MAX_VALUE;\n                for (int k = 0; k <m-1 ; k++) {\n                    costRight[i][j]=Math.min(Math.abs(a[i][k+1]-a[j][k]),costRight[i][j]);\n                }\n            }\n        }\n\n        /*for (int i = 0; i <n ; i++) {\n            for (int j = 0; j <n ; j++) {\n                out.print(cost[i][j]+\" \");\n            }\n            out.println();\n        }\n        out.println();\n\n        for (int i = 0; i <n ; i++) {\n            for (int j = 0; j <n ; j++) {\n                out.print(costRight[i][j]+\" \");\n            }\n            out.println();\n        }*/\n\n        if(n==1){\n            int ans=Integer.MAX_VALUE;\n            for (int i = 0; i <m-1 ; i++) {\n                ans=Math.min(ans,Math.abs(a[0][i]-a[0][i+1]));\n            }\n            out.println(ans);\n            out.close();\n            return;\n        }\n\n        Long dp[][][]=new Long[n+1][n+1][1<<n];\n        long max=0;\n        for (int i = 0; i <n ; i++) {\n           // out.println(f(i,i,1<<i,dp,n,cost,costRight));\n            max=Math.max(max,f(i,i,1<<i,dp,n,cost,costRight));\n        }\n\n        out.println(max);\n        out.close();\n    }\n\n    long f(int start,int end,int mask,Long dp[][][],int n,int cost[][],int costRight[][]){\n        if(dp[start][end][mask]!=null)return dp[start][end][mask];\n        long ans=Integer.MIN_VALUE;\n        for (int i = 0; i <n ; i++) {\n            if((mask&(1<<i))==0){\n                int newMask=mask|(1<<i);\n                if((1<<n)-1!=(mask|(1<<i))){\n                    ans = Math.max(ans, Math.min(cost[end][i], f(start, i, newMask, dp, n, cost, costRight)));\n                }\n                else{\n                    ans=Math.max(ans,Math.min(cost[end][i],costRight[start][i]));\n                }\n            }\n        }\n        return dp[start][end][mask]=ans;\n    }\n\n}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class ElongatedMatrix {\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\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\n\t\t\t}\n\t}\n}\n\nclass Solve {\n\tstatic final int oo = (int) 1e9;\n\tKattio io;\n\tint n, m;\n\tint[][] a;\n\tint[][][] dp;\n\tint[][] diff;\n\tint[][] slant;\n\n\tSolve(Kattio io) {\n\t\tthis.io = io;\n\t}\n\n\tint getbit(int x, int n) {\n\t\tn--;\n\t\treturn (x >> n) & 1;\n\t}\n\n\tint setbit(int x, int n) {\n\t\tn--;\n\t\treturn x | (1 << n);\n\t}\n\n\tint caldp(int currentRow, int firstRow, int mask) {\n\t\tif (dp[currentRow][firstRow][mask] != -1)\n\t\t\treturn dp[currentRow][firstRow][mask];\n\t\tdp[currentRow][firstRow][mask] = 0;\n\t\tif (mask == (1 << n) - 1)\n\t\t\tdp[currentRow][firstRow][mask] = slant[currentRow][firstRow];\n\t\telse {\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tif (getbit(mask, i) == 0) {\n\t\t\t\t\tdp[currentRow][firstRow][mask] = Math.max(\n\t\t\t\t\t\t\tMath.min(caldp(i, firstRow, setbit(mask, i)), diff[currentRow][i]),\n\t\t\t\t\t\t\tdp[currentRow][firstRow][mask]);\n\n\t\t\t\t}\n\t\t}\n\t\treturn dp[currentRow][firstRow][mask];\n\n\t}\n\n\tvoid main() {\n\t\tn = io.getInt();\n\t\tm = io.getInt();\n\t\ta = new int[n+1][m+1];\n\t\tdp = new int[n+1][n+1][1<<n];\n\t\t\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tfor (int j=1; j<=m; j++)\n\t\t\t\ta[i][j] = io.getInt();\n\t\t\n\t\tdiff = new int[n+1][n+1];\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tfor (int j=1; j<=n; j++)\n\t\t\t{\n\t\t\t\tdiff[i][j]=oo;\n\t\t\t\tfor (int x=1; x<=m; x++)\n\t\t\t\t\tdiff[i][j]=Math.min(diff[i][j], Math.abs(a[i][x]-a[j][x]));\n\t\t\t}\n\t\t\n\t\tslant = new int[n+1][n+1];\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tfor (int j=1; j<=n; j++)\n\t\t\t{ \n\t\t\t\tslant[i][j] = oo;\n\t\t\t\tfor (int x=1; x+1<=m; x++)\n\t\t\t\t\tslant[i][j] = Math.min(slant[i][j], Math.abs(a[i][x]-a[j][x+1]));\n\t\t\t}\n\t\t\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tfor (int j=1; j<=n; j++)\n\t\t\t\tArrays.fill(dp[i][j], -1);\n\t\t\n\t\tint res = 0;\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tres = Math.max(res, caldp(i,i,setbit(0,i)));\n\t\t\n\t\tio.print(res);\n\t}\n}\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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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        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, Scanner in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            int[][] graph = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++)\n                    graph[i][j] = in.nextInt();\n            }\n            int[][] mn1 = new int[n][n];\n            int[][] mn2 = new int[n][n];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < n; j++) {\n                    int min_val = Integer.MAX_VALUE;\n                    for (int k = 0; k < m; k++)\n                        min_val = Math.min(min_val, Math.abs(graph[i][k] - graph[j][k]));\n                    mn1[i][j] = min_val;\n                    min_val = Integer.MAX_VALUE;\n                    for (int k = 0; k < m - 1; k++) {\n                        min_val = Math.min(min_val, Math.abs(graph[i][k] - graph[j][k + 1]));\n                    }\n                    mn2[i][j] = min_val;\n                }\n            int[][] dp = new int[(1 << (n + 2))][n];\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                for (int[] temp : dp)\n                    Arrays.fill(temp, -1);\n                for (int j = 0; j < n; j++) {\n                    dp[1 << j][j] = (j == i ? Integer.MAX_VALUE : 0);\n//                dp[1 << j][j] = (j == i ? 0: Integer.MAX_VALUE );\n                }\n                for (int j = 0; j < n; j++) {\n                    ans = Math.max(ans, Math.min(mn2[j][i], calc((1 << n) - 1, j, dp, mn1, n)));\n                }\n            }\n            out.println(ans);\n        }\n\n        public int calc(int mask, int v, int[][] dp, int[][] mn1, int n) {\n//        System.out.println(mask+\",\"+v);\n            if (dp[mask][v] != -1)\n                return dp[mask][v];\n            dp[mask][v] = 0;\n            for (int u = 0; u < n; u++) {\n                if (u != v && (((mask >> u) & 1) == 1))\n                    dp[mask][v] = Math.max(dp[mask][v], Math.min(mn1[u][v], calc(mask ^ (1 << v), u, dp, mn1, n)));\n            }\n            return dp[mask][v];\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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        FElongatedMatrix solver = new FElongatedMatrix();\n        solver.solve(1, in, out);\n        out.close();\n      }\n  }\n\n  static class FElongatedMatrix {\n    public void solve(int testNumber, FastInput in, FastOutput out) {\n      int n = in.readInt();\n      int m = in.readInt();\n      int[][] mat = new int[n][m];\n      for (int i = 0; i < n; i++) {\n        for (int j = 0; j < m; j++) {\n          mat[i][j] = in.readInt();\n        }\n      }\n\n      int[][] minDist = new int[n][n];\n      SequenceUtils.deepFill(minDist, (int) 1e9);\n      for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n          for (int k = 0; k < m; k++) {\n            minDist[i][j] = Math.min(minDist[i][j], Math.abs(mat[i][k] - mat[j][k]));\n          }\n        }\n      }\n      int[][] minDistBetweenHeadAndTail = new int[n][n];\n      SequenceUtils.deepFill(minDistBetweenHeadAndTail, (int) 1e9);\n      for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n          for (int k = 1; k < m; k++) {\n            minDistBetweenHeadAndTail[i][j] = Math.min(minDistBetweenHeadAndTail[i][j], Math.abs(mat[i][k] - mat[j][k - 1]));\n          }\n        }\n      }\n\n      Log2 log2 = new Log2();\n      BitOperator bo = new BitOperator();\n      int[][][] dp = new int[1 << n][n][n];\n      for (int i = 1; i < (1 << n); i++) {\n        if (i == Integer.lowestOneBit(i)) {\n          dp[i][log2.floorLog(i)][log2.floorLog(i)] = (int) 1e9;\n          continue;\n        }\n        for (int j = 0; j < n; j++) {\n          for (int k = 0; k < n; k++) {\n            if (bo.bitAt(i, j) == 0) {\n              continue;\n            }\n            for (int t = 0; t < n; t++) {\n              dp[i][j][k] = Math.max(dp[i][j][k],\n                  Math.min(dp[bo.setBit(i, j, false)][t][k],\n                    minDist[j][t]));\n            }\n          }\n        }\n      }\n\n      int ans = 0;\n      for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n          ans = Math.max(ans, Math.min(dp[(1 << n) - 1][i][j], minDistBetweenHeadAndTail[j][i]));\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 Log2 {\n    public int floorLog(int x) {\n      return 31 - Integer.numberOfLeadingZeros(x);\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 BitOperator {\n    public int bitAt(int x, int i) {\n      return (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  }\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", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class F \n{\n\tstatic Scanner in = new Scanner(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic int n,m,res=0;\n\tstatic int[][] a=new int[20][10005],Min=new int[20][20],Min1=new int[20][20];\n\tstatic int[][][] f=new int[1<<16][20][20];\n\t\n\tstatic int GetBit(int x,int k)\n\t{\n\t\treturn (x>>k)&1;\n\t}\n\t\n\tstatic int TurnBit(int x,int k)\n\t{\n\t\treturn x^(1<<k);\n\t}\n\n\tpublic static void main(String[] args) \n\t{\n\t\tn=in.nextInt();\n\t\tm=in.nextInt();\n\t\tfor(int i=0;i<n;i++)\n\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t\ta[i][j]=in.nextInt();\n\t\tif(n==1)\n\t\t{\n\t\t\tres=(int)1e9;\n\t\t\tfor(int i=1;i<m;i++)\n\t\t\t\tres=Math.min(res,Math.abs(a[0][i]-a[0][i+1]));\n\t\t\tout.print(res);\n\t\t\tout.close();\n\t\t\treturn;\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{\n\t\t\t\tMin[i][j]=Min1[i][j]=(int)1e9;\n\t\t\t\tfor(int t=1;t<=m;t++)\n\t\t\t\t\tMin[i][j]=Math.min(Min[i][j],Math.abs(a[i][t]-a[j][t]));\n\t\t\t\tfor(int t=1;t<m;t++)\n\t\t\t\t\tMin1[i][j]=Math.min(Min1[i][j],Math.abs(a[i][t]-a[j][t+1]));\n\t\t\t}\n\t\tfor(int i=0;i<n;i++)\n\t\t\tf[1<<i][i][i]=(int)1e9;\n\t\tfor(int mask=0;mask<(1<<n);mask++)\n\t\t\tif(Integer.bitCount(mask)>1)\n\t\t\t\tfor(int i=0;i<n;i++)\n\t\t\t\t\tif(GetBit(mask,i)==1)\n\t\t\t\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\t\t\t\tif(i!=j&&GetBit(mask,j)==1)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfor(int t=0;t<n;t++)\n\t\t\t\t\t\t\t\t\tif(j!=t&&GetBit(mask,t)==1)\n\t\t\t\t\t\t\t\t\t\tf[mask][i][j]=Math.max(f[mask][i][j],Math.min(f[TurnBit(mask,j)][i][t],Min[j][t]));\n\t\t\t\t\t\t\t\tif(mask==(1<<n)-1)\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tres=Math.max(res,Math.min(f[mask][i][j],Min1[j][i]));\n\t\t\t\t\t\t\t}\n\t\tout.print(res);\n\t\tout.close();\n\t}\n}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n\tstatic class Task {\n\t\t\n\t\tint NN = 1000006;\n\t\tint MOD = 998244353;\n\t\tint INF = 2000000000;\n\t\tlong INFINITY = 1000000000000000000L;\n\t\t\n\t\tlong [][] a;\n\t\tlong [][] w, w1;\n\t\tlong [][] dp;\n\t\t\n\t\tint countBit(int num) {\n\t\t\tint ret = 0;\n\t\t\twhile(num > 0) {\n\t\t\t\tif((num&1)!=0)\n\t\t\t\t\t++ret;\n\t\t\t\tnum >>= 1;\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tlong rec(int at, int mask, int n, int start) {\n\t\t\tlong ans = -INFINITY;\n\t\t\tif(dp[at][mask] != -1)\n\t\t\t\treturn dp[at][mask];\n\t\t\tif(countBit(mask) == n) {\n\t\t\t\treturn dp[at][mask] = w1[start][at];\n\t\t\t}\n\t\t\tfor(int i=0;i < n;++i) {\n\t\t\t\tif(((mask>>i)&1)==0) {\n\t\t\t\t\tans = Math.max(ans, \n\t\t\t\t\t\t\tMath.min(w[at][i], rec(i, mask | (1<<i), n, start)));\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn dp[at][mask] = ans;\n\t\t}\n\t\t\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tint n  = in.nextInt(), m = in.nextInt();\n\t\t\tdp = new long[n][1<<n];\n\t\t\ta = new long[n][m];\n\t\t\tw = new long[n][n];\n\t\t\tw1 = new long[n][n];\n\t\t\tfor(int i=0;i<n;++i) {\n\t\t\t\tfor(int j=0;j<m;++j) {\n\t\t\t\t\ta[i][j] = in.nextLong();\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\tw[i][j] = INFINITY;\n\t\t\t\t\tif(i == j)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor(int k=0;k<m;++k) {\n\t\t\t\t\t\tw[i][j] = Math.min(w[i][j], Math.abs(a[j][k] - a[i][k]));\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\tw1[i][j] = INFINITY;\n\t\t\t\t\tfor(int k=1;k<m;++k) {\n\t\t\t\t\t\tw1[i][j] = Math.min(w1[i][j], Math.abs(a[i][k] - a[j][k - 1]));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlong ans = 0;\n\t\t\tfor(int start = 0;start < n;++start) {\n\t\t\t\tfor(int i=0;i<n;++i) {\n\t\t\t\t\tfor(int j=0;j<(1<<n);++j)\n\t\t\t\t\t\tdp[i][j] = -1;\n\t\t\t\t}\n\t\t\t\tans = Math.max(ans, rec(start, 1<<start, n, start));\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\t\t\n\t\tclass Pair {\n\t\t\tInteger first, second;\n\t\t\tpublic Pair() {\n\t\t\t}\n\t\t\tpublic Pair(int first, int second) {\n\t\t\t\tthis.first = first;\n\t\t\t\tthis.second = second;\n\t\t\t}\n\t\t\t@Override\n\t\t\tpublic int hashCode() {\n\t\t\t\tfinal int prime = 31;\n\t\t\t\tint result = 1;\n\t\t\t\tresult = prime * result + getOuterType().hashCode();\n\t\t\t\tresult = prime * result + first;\n\t\t\t\tresult = prime * result + second;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\t@Override\n\t\t\tpublic boolean equals(Object obj) {\n\t\t\t\tif (this == obj)\n\t\t\t\t\treturn true;\n\t\t\t\tif (obj == null)\n\t\t\t\t\treturn false;\n\t\t\t\tif (getClass() != obj.getClass())\n\t\t\t\t\treturn false;\n\t\t\t\tPair other = (Pair) obj;\n\t\t\t\tif (!getOuterType().equals(other.getOuterType()))\n\t\t\t\t\treturn false;\n\t\t\t\tif (first != other.first)\n\t\t\t\t\treturn false;\n\t\t\t\tif (second != other.second)\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tprivate Task getOuterType() {\n\t\t\t\treturn Task.this;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tstatic void prepareIO(boolean isFileIO) {\n\t\tTask solver = new Task();\n\t\t// Standard IO\n\t\tif(!isFileIO) {\n\t\t\tInputStream inputStream = System.in;\n\t        OutputStream outputStream = System.out;\n\t        InputReader in = new InputReader(inputStream);\n\t        PrintWriter out = new PrintWriter(outputStream);\n\t        solver.solve(in, out);\n\t        out.close();\n\t\t}\n        // File IO\n\t\telse {\n\t\t\tString IPfilePath = System.getProperty(\"user.home\") + \"/Downloads/ip.in\";\n\t        String OPfilePath = System.getProperty(\"user.home\") + \"/Downloads/op.out\";\n\t        InputReader fin = new InputReader(IPfilePath);\n\t        PrintWriter fout = null;\n\t        try {\n\t\t\t\tfout = new PrintWriter(new File(OPfilePath));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t        solver.solve(fin, fout);\n\t        fout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n        prepareIO(false);\n\t}\n\t\n\tstatic class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n\n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream), 32768);\n            tokenizer = null;\n        }\n        \n        public InputReader(String filePath) {\n        \tFile file = new File(filePath);\n            try {\n\t\t\t\treader = new BufferedReader(new FileReader(file));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n            tokenizer = null;\n        }\n        \n        public String nextLine() {\n        \tString str = \"\";\n        \ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n        \treturn str;\n        }\n        \n        public String next() {\n            while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n                try {\n                    tokenizer = new StringTokenizer(reader.readLine());\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return tokenizer.nextToken();\n        }\n\n        public int nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        public long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        public double nextDouble() {\n        \treturn Double.parseDouble(next());\n        }\n        \n    }\n\n}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class CF1102F {\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[][] aa = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\taa[i][j] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\tint[][] dd = new int[n][n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tint d = Integer.MAX_VALUE;\n\t\t\t\tfor (int h = 0; h < m; h++)\n\t\t\t\t\td = Math.min(d, Math.abs(aa[i][h] - aa[j][h]));\n\t\t\t\tdd[i][j] = dd[j][i] = d;\n\t\t\t}\n\t\tint[][] dd_ = 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\tint d = Integer.MAX_VALUE;\n\t\t\t\tfor (int h = 0; h < m - 1; h++)\n\t\t\t\t\td = Math.min(d, Math.abs(aa[i][h] - aa[j][h + 1]));\n\t\t\t\tdd_[i][j] = d;\n\t\t\t}\n\t\tif (n == 1) {\n\t\t\tSystem.out.println(dd_[0][0]);\n\t\t\treturn;\n\t\t}\n\t\tint[] ii = new int[1 << n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tii[1 << i] = i;\n\t\tint[][][] dp = new int[1 << n][n][n];\n\t\tfor (int b = 0; b < 1 << n; b++)\n\t\t\tfor (int u = b; u > 0; u &= u - 1) {\n\t\t\t\tint i = ii[u & -u];\n\t\t\t\tfor (int v = b ^ 1 << i; v > 0; v &= v - 1) {\n\t\t\t\t\tint j = ii[v & -v];\n\t\t\t\t\tif (b == (1 << i ^ 1 << j))\n\t\t\t\t\t\tdp[b][i][j] = dd[i][j];\n\t\t\t\t\telse {\n\t\t\t\t\t\tint x = 0;\n\t\t\t\t\t\tfor (int w = b ^ 1 << i ^ 1 << j; w > 0; w &= w - 1) {\n\t\t\t\t\t\t\tint k = ii[w & -w];\n\t\t\t\t\t\t\tx = Math.max(x, Math.min(dp[b ^ 1 << j][i][k], dd[k][j]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdp[b][i][j] = x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tint b = (1 << n) - 1;\n\t\tint x = 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)\n\t\t\t\t\tx = Math.max(x, Math.min(dp[b][i][j], dd_[i][j]));\n\t\tSystem.out.println(x);\n\t}\n}\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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\npublic class f {\n\t\n\tstatic int n, m;\n\tstatic int start;\n\tstatic int[][] memo;\n\tstatic int[][] arr;\n\tstatic int[][] costs;\n\tstatic int[][] wrapCosts;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tarr = new int[n][m];\n\t\tcosts = new int[n][n];\n\t\twrapCosts = new int[n][n];\n\t\tfor (int r = 0; r < n; r++) {\n\t\t\tfor (int c = 0; c < m; c++) {\n\t\t\t\tarr[r][c] = in.nextInt();\n\t\t\t}\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\tcosts[i][j] = Integer.MAX_VALUE;\n\t\t\t\tfor (int c = 0; c < m; c++) {\n\t\t\t\t\tcosts[i][j] = Math.min(costs[i][j], Math.abs(arr[i][c] - arr[j][c]));\n\t\t\t\t}\n\t\t\t\tcosts[j][i] = costs[i][j];\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\twrapCosts[i][j] = Integer.MAX_VALUE;\n\t\t\t\tfor (int c = 0; c < m - 1; c++) {\n\t\t\t\t\twrapCosts[i][j] = Math.min(wrapCosts[i][j], Math.abs(arr[i][c + 1] - arr[j][c]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmemo = new int[n][1 << n];\n\t\tlong best = 0;\n\t\tfor (start = 0; start < n; start++) {\n\t\t\tfor (int[] a : memo) Arrays.fill(a, -1);\n\t\t\tbest = Math.max(best, go(start, (1 << n) - 1 - (1 << start)));\n\t\t}\n\t\tout.println(best);\n\t\tout.close();\n\t}\n\tstatic int go(int cur, int mask) {\n\t\tif (mask == 0) {\n\t\t\treturn wrapCosts[start][cur];\n\t\t}\n\t\tif (memo[cur][mask] != -1) return memo[cur][mask];\n\t\tint ans = 0;\n\t\tfor (int next = 0; next < n; next++) {\n\t\t\tint bit = 1 << next;\n\t\t\tif ((mask & bit) == 0) continue;\n\t\t\tans = Math.max(ans, Math.min(costs[cur][next], go(next, mask ^ bit)));\n\t\t}\n\t\treturn memo[cur][mask] = ans;\n\t}\n\t\n\t//@\n\tstatic class FastScanner {\n\t    BufferedReader br;\n\t    StringTokenizer st;\n\t\t\n\t    public FastScanner(InputStream i) {\n\t        br = new BufferedReader(new InputStreamReader(i));\n\t        st = new StringTokenizer(\"\");\n\t    }\n\t\t\t\t\n\t    public String next() throws IOException {\n\t        if(st.hasMoreTokens())\n\t            return st.nextToken();\n\t        else\n\t            st = new StringTokenizer(br.readLine());\n\t        return next();\n\t    }\n\n\t    public int nextInt() throws IOException {\n\t        return Integer.parseInt(next());\n\t    }\n\t    //#\n\t    public long nextLong() throws IOException {\n\t        return Long.parseLong(next());\n\t    }\n\t    public double nextDouble() throws IOException {\n\t        return Double.parseDouble(next());\n\t    }\n\t    //$\n\t}\n}\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class ElongatedMatrix2 {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        int N = scanner.nextInt();\n        int M = scanner.nextInt();\n        int[][] arr = new int[N][M];\n        for(int i = 0; i < N; i++) {\n            for(int j = 0; j < M; j++) {\n                arr[i][j] = scanner.nextInt();\n            }\n        }\n        int[][] distRow = new int[N][N];\n        int[][] distTop = new int[N][N];\n//        for(int i = 0; i < N; i++) {\n//            Arrays.fill(distTop, Integer.MAX_VALUE);\n//            Arrays.fill(distRow, Integer.MAX_VALUE);\n//        }\n        //compute row distances\n        for(int i = 0; i < N; i++) {\n            for(int j = i+1; j < N; j++) {\n                int curMin = Integer.MAX_VALUE;\n                for(int k = 0; k < M; k++) {\n                    curMin = Math.min(curMin, Math.abs(arr[i][k] - arr[j][k]));\n                }\n                distRow[i][j] = distRow[j][i] = curMin;\n            }\n        }\n        //compute bottom/top distances\n        for(int i = 0; i < N; i++) {\n            for(int j = 0; j < N; j++) {\n                int curMin = Integer.MAX_VALUE;\n                for(int k = 0; k+1 < M; k++) {\n                    curMin = Math.min(curMin, Math.abs(arr[i][k] - arr[j][k+1]));\n                }\n                distTop[i][j] = curMin;\n            }\n        }\n        int maxMask = 1 << N;\n        int[][][] dp = new int[maxMask][N][N];\n        for(int i = 0; i < maxMask; i++) {\n            for(int j = 0; j < N; j++) {\n                Arrays.fill(dp[i][j], Integer.MAX_VALUE);\n            }\n        }\n        for(int mask = 1; mask < maxMask; mask++) {\n            for (int j = 0; j < N; j++) {\n                if ((mask & ( 1 << j)) == 0) continue;\n                for(int k = 0; k < N; k++) {\n                    if ((mask &(1 << k)) == 0) continue;\n                    if (j == k && mask - (1 << k) != 0) continue;\n                    for (int i = 0; i < N; i++) {\n                        if ((mask & (1 << i)) > 0) continue;\n                        int curMask = mask | (1 << i);\n                        if (dp[curMask][i][k] != Integer.MAX_VALUE)\n                            dp[curMask][i][k] = Math.max(dp[curMask][i][k], Math.min(dp[mask][j][k], distRow[i][j]));\n                        else\n                            dp[curMask][i][k] = Math.min(dp[mask][j][k], distRow[i][j]);\n                    }\n                }\n            }\n        }\n        maxMask--;\n        int max = 0;\n        for(int i= 0; i < N; i++) {\n            for(int j = 0; j < N; j++) {\n                if (i==j && N != 1) continue;\n                max = Math.max(max, Math.min(dp[maxMask][i][j], distTop[i][j]));\n            }\n        }\n        System.out.println(max);\n    }\n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        public FastScanner() {\n            this(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        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 readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\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", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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        FastScanner in = new FastScanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F solver = new F();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.ni(), m = in.ni();\n            int[][] a = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.na(m);\n            }\n            if (n == 1) {\n                int ans = Integer.MAX_VALUE;\n                for (int i = 1; i < m; i++) {\n                    ans = Math.min(ans, Math.abs(a[0][i] - a[0][i - 1]));\n                }\n                out.println(ans);\n                return;\n            }\n            int[][] mk = new int[n][n];\n            int[][] mk1 = new int[n][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    int minK = Integer.MAX_VALUE;\n                    int minK1 = Integer.MAX_VALUE;\n                    int minK2 = Integer.MAX_VALUE;\n                    for (int l = 0; l < m; l++) {\n                        minK = Math.min(minK, Math.abs(a[i][l] - a[j][l]));\n                        if (l > 0) {\n                            minK1 = Math.min(minK1, Math.abs(a[i][l] - a[j][l - 1]));\n                            minK2 = Math.min(minK2, Math.abs(a[i][l - 1] - a[j][l]));\n                        }\n                    }\n                    mk[i][j] = mk[j][i] = minK;\n                    mk1[i][j] = minK1;\n                    mk1[j][i] = minK2;\n                }\n            }\n\n            int ans = 0;\n            for (int first = 0; first < n; first++) {\n                int[][] dp = new int[1 << n][n];\n                for (int mask = 1; mask < (1 << n) - 1; mask++) {\n                    int bc = Integer.bitCount(mask);\n                    if ((mask & (1 << first)) != 0) {\n                        if (bc == 1) {\n                            dp[mask][first] = Integer.MAX_VALUE;\n                        }\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                                        dp[mask | (1 << j)][j] = Math.max(dp[mask | (1 << j)][j], Math.min(dp[mask][i], mk[i][j]));\n                                    }\n                                }\n                            }\n                        }\n                    }\n                }\n                for (int i = 0; i < n; i++) {\n                    if (i != first) {\n                        ans = Math.max(ans, Math.min(dp[(1 << n) - 1][i], mk1[first][i]));\n                    }\n                }\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream stream) {\n            in = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String ns() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(ns());\n        }\n\n        public 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    }\n}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class F531 {\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();\n        long [][] mn1 = new long[n][n];\n        long [][] mn2 = new long[n][n];\n        long [][] grid = new long[n][m];\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) grid[i][j] = sc.nextInt();\n        }\n        if (n == 1) {\n            long ans = Integer.MAX_VALUE;\n            for (int i = 0; i < m - 1; i++) ans = Math.min(ans, Math.abs(grid[0][i] - grid[0][i + 1]));\n            out.println(ans);\n            out.close();\n            return;\n        }\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (i == j) continue;\n                long min = Long.MAX_VALUE;\n                for (int k = 0; k < m; k++) min = Math.min(min, Math.abs(grid[i][k] - grid[j][k]));\n                mn1[i][j] = min;\n            }\n        }\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (i == j) continue;\n                long min = Long.MAX_VALUE;\n                for (int k = 0; k < m - 1; k++) min = Math.min(min, Math.abs(grid[i][k] - grid[j][k + 1]));\n                mn2[i][j] = min;\n            }\n        }\n        long [][] dp = new long[1 << n][n];\n\n        // start vertex\n        long ans = 0;\n        for (int i = 0; i < n; i++) {\n            for (long [] a: dp) Arrays.fill(a, -1);\n            for (int j = 0; j < n; j++) {\n                if (j == i) dp[1 << j][j] = Long.MAX_VALUE;\n                else dp[1 << j][j] = 0;\n            }\n            for (int mask = 1; mask < (1 << n); mask++) {\n                for (int last = 0; last < n; last++) {\n                    if (dp[mask][last] != -1) continue;\n                    for (int prev = 0; prev < n; prev++) {\n                        if (prev == last) continue;\n                        if (((mask >> prev) & 1) == 1) {\n                            dp[mask][last] = Math.max(dp[mask][last], Math.min(mn1[prev][last], dp[mask ^ (1 << last)][prev]));\n                        }\n                    }\n                }\n            }\n            // end vertex\n            for (int j = 0; j < n; j++) {\n                // step from the last vertex to the first\n                long end = mn2[j][i];\n                ans = Math.max(ans, Math.min(dp[(1 << n) - 1][j], end));\n            }\n        }\n        out.println(ans);\n        out.close();\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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class main{\n\n\tstatic int max = 5000+1;\n\tstatic FastReader in = new FastReader();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic int N = 18;\n\tstatic int[][] mn1 = new int[N][N]; \n\tstatic int[][] mn2 = new int[N][N];\n\tstatic int[][] dp = new int[1<<N][N];\n\tstatic int n,m;\n\t\n\tstatic void solve(){\n\t\tn = in.nextInt(); m = in.nextInt();\n\t\tint[][] a = new int[n][m];\n\t\tfor(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j] = in.nextInt();\n\t\tfor(int i=0;i<n;i++){\n\t\t\tArrays.fill(mn1[i],Integer.MAX_VALUE);\n\t\t\tArrays.fill(mn2[i],Integer.MAX_VALUE);\n\t\t}\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\tfor(int k=0;k<m;k++){\n\t\t\t\t\tmn1[i][j] = Math.min(mn1[i][j],Math.abs(a[i][k]-a[j][k]));\n\t\t\t\t\tif(k<=m-2)\n\t\t\t\t\t\tmn2[i][j] = Math.min(mn2[i][j],Math.abs(a[i][k]-a[j][k+1]));\n\t\t\t\t}\n\t\tint ans = 0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tfor(int x=0;x<1<<n;x++)Arrays.fill(dp[x],-1);\n\t\t\tfor(int j=0;j<n;j++)dp[1<<j][j] = 0;\n\t\t\tdp[1<<i][i] = Integer.MAX_VALUE;\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\tans = Math.max(ans,Math.min(mn2[j][i],calc((1 << n) - 1, j)));\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tstatic int calc(int mask, int v){\n\t\tif (dp[mask][v] != -1)\n\t\t\treturn dp[mask][v];\n\t\tdp[mask][v] = 0;\n\t\tfor(int u=0;u<n;u++) if (v != u && (((mask >> u) & 1)>0))\n\t\t\tdp[mask][v] = Math.max(dp[mask][v], Math.min(mn1[u][v], calc(mask ^ (1 << v), u)));\n\t\treturn dp[mask][v];\n\t}\n\n\n\tpublic static void main(String[] args){\n\t\tsolve();\n\t\tout.close();\n\t}\t\n\n\tstatic 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(){\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        String nextLine(){\n            String str = \"\";\n            try{   \n                str = br.readLine();\n            }catch (IOException e){\n                e.printStackTrace();\n            }  \n            return str;\n        }\n        int nextInt(){return Integer.parseInt(in.next());}\n    \tlong nextLong(){return Long.parseLong(in.next());}\n    \tdouble nextDouble(){return Double.parseDouble(in.next());}\n    }\n}\n\n\n\n\n// |xvcxv|vcv[cvcvc|cxv||]vcvx:v|c|vxc|[|cvx:cxvx||||]", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\npublic class Main {\n    void solve() {\n        int n=ni(),m=ni();\n        int a[][]=new int[n+1][m+1];\n        for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=ni();\n\n        if(n==1){\n            int mn=Integer.MAX_VALUE;\n            for(int i=1;i<m;i++) mn=Math.min(mn,Math.abs(a[1][i]-a[1][i+1]));\n            pw.println(mn) ;\n            return ;\n        }\n        mn1=new int[n+1][n+1];\n        mn2=new int[n+1][n+1];\n        for(int i=1;i<=n;i++){\n            for(int j=1;j<=n;j++){\n\n                if(i==j) continue;\n\n                mn1[i][j]=mn2[i][j]=Integer.MAX_VALUE;\n                for(int k=1;k<=m;k++){\n                    mn1[i][j]=Math.min(mn1[i][j],Math.abs(a[i][k]-a[j][k]));\n                   // if(i==3 && j==4) pw.println(a[i][k]+\" \"+a[j][k]);\n                }\n                for(int k=1;k<m;k++){\n                    mn2[i][j]=Math.min(mn2[i][j],Math.abs(a[i][k+1]-a[j][k]));\n                }\n                //if(m==1) mn2[i][j]=0;\n\n            }\n        }\n      //  pw.println(mn1[3][4]);\n        dp=new int[17][1<<16][17];\n        for(int i=1;i<17;i++) for(int j=0;j<(1<<16);j++) Arrays.fill(dp[i][j],-1);\n\n        int ans=0;\n        for(int i=1;i<=n;i++){\n            ans=Math.max(ans,go(2,1<<(i-1),i,i,n));\n        }\n        pw.println(ans);\n\n    }\n    int mn1[][],mn2[][];\n    int dp[][][];\n    int go(int i,int mask,int prev,int first,int n){\n        if(i>n){\n       //   if(mn2[first][prev]==0)  pw.println(prev+\" \"+first+\" \"+mn2[first][prev]);\n            return mn2[first][prev];\n        }\n       if(dp[first][mask][prev]!=-1) return dp[first][mask][prev];\n        int cc=0;\n        for(int k=1;k<=n;k++){\n            if((mask&(1<<(k-1)))==0){\n                cc=Math.max(cc,Math.min(mn1[prev][k],go(i+1,mask|(1<<(k-1)),k,first,n)));\n               //if(mn1[prev][k]==0)  pw.println(mn1[prev][k]+\" \"+prev+\" \"+k);\n            }\n        }\n        dp[first][mask][prev]=cc;\n        return cc;\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    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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n    static MyScanner sc;\n    static PrintWriter pw;\n\n    public static void main(String[] args) throws Throwable {\n        sc = new MyScanner();\n        pw = new PrintWriter(System.out);\n\n        n = sc.nextInt();\n        int m = sc.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] = sc.nextInt();\n        val = new int[n][n];\n        for (int i = 0; i < n; i++)\n            Arrays.fill(val[i], Integer.MAX_VALUE);\n        for (int i = 0; i < n; i++)\n            for (int j = i; j < n; j++) {\n                for (int k = 0; k < m; k++)\n                    val[i][j] = val[j][i] = Math.min(val[i][j], Math.abs(a[i][k] - a[j][k]));\n            }\n\n        val2 = new int[n][n];\n        for (int i = 0; i < n; i++)\n            Arrays.fill(val2[i], Integer.MAX_VALUE);\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < n; j++) {\n                for (int k = 0; k < m - 1; k++)\n                    val2[i][j] = Math.min(val2[i][j], Math.abs(a[i][k] - a[j][k + 1]));\n            }\n        mem = new Long[n][n][1 << n];\n        long ans = 0;\n        for (int i = 0; i < n; i++) {\n            ans = Math.max(ans, dp(i, i, 1 << i));\n        }\n        if (n == 1)\n            pw.println(val2[0][0]);\n        else\n            pw.println(ans);\n\n\n        pw.flush();\n        pw.close();\n    }\n\n    static int n;\n    static int[][] val, val2;\n    static Long[][][] mem;\n\n    static long dp(int st, int lst, int msk) {\n        int bits = Integer.bitCount(msk);\n        if (mem[st][lst][msk] != null)\n            return mem[st][lst][msk];\n        long ans = 0;\n        for (int i = 0; i < n; i++)\n            if ((msk & (1 << i)) == 0) {\n                int newMsk = (msk | (1 << i));\n                if (bits < n - 1)\n                    ans = Math.max(ans, Math.min(val[lst][i], dp(st, i, newMsk)));\n                else\n                    ans = Math.max(ans, Math.min(val[lst][i], val2[i][st]));\n            }\n        return mem[st][lst][msk] = ans;\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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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 beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskF solver = new TaskF();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskF {\n        final int INF = (int) 1e9 + 5;\n        int n;\n        int m;\n        int[][][] dp;\n        int[][] diff;\n        int[][] diffStartLast;\n\n        int two(int x) {\n            return 1 << x;\n        }\n\n        boolean contain(int mask, int x) {\n            return (mask & two(x)) > 0;\n        }\n\n        int rec(int start, int pre, int mask) {\n            if (mask == two(n) - 1)\n                return INF;\n            int res = dp[start][pre][mask];\n            if (res != -1)\n                return res;\n            res = 0;\n\n            for (int i = 0; i < n; i++)\n                if (contain(mask, i) == false) {\n                    int diffPre = mask == 0 ? INF : diff[pre][i]; // mask == 0 should never happen\n                    int diffLast = (mask | two(i)) == two(n) - 1 ? diffStartLast[start][i] : INF;\n                    res = Math.max(res, Math.min(rec(start, i, mask | two(i)), Math.min(diffLast, diffPre)));\n                }\n\n            dp[start][pre][mask] = res;\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt();\n            m = in.nextInt();\n            int[][] grid = new int[n][m];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    grid[i][j] = in.nextInt();\n\n            if (n == 1) {\n                int res = INF;\n                for (int i = 0; i + 1 < m; i++) {\n                    res = Math.min(res, Math.abs(grid[0][i] - grid[0][i + 1]));\n                }\n                out.println(res);\n                return;\n            }\n\n            diff = new int[n][n];\n            diffStartLast = new int[n][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    diff[i][j] = INF;\n                    diffStartLast[i][j] = INF;\n                    for (int k = 0; k < m; k++) {\n                        diff[i][j] = Math.min(diff[i][j], Math.abs(grid[i][k] - grid[j][k]));\n                        if (k + 1 < m) {\n                            diffStartLast[i][j] = Math.min(diffStartLast[i][j], Math.abs(grid[i][k + 1] - grid[j][k]));\n                        }\n                    }\n                }\n            }\n\n            dp = new int[n][n][two(n)];\n            for (int[][] aux : dp)\n                for (int[] aux2 : aux)\n                    Arrays.fill(aux2, -1);\n\n            int ans = 0;\n            for (int start = 0; start < n; start++) {\n                ans = Math.max(ans, rec(start, start, two(start)));\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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.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        FElongatedMatrix solver = new FElongatedMatrix();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class FElongatedMatrix {\n        int n;\n        int m;\n        int[][] arr;\n        int[][] memo;\n        int[][][] memo2;\n        int first;\n\n        public void readInput(Scanner sc) {\n            n = sc.nextInt();\n            m = sc.nextInt();\n            arr = new int[n][m];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    arr[i][j] = sc.nextInt();\n        }\n\n        public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n            int tc = 1;\n            while (tc-- > 0) {\n                readInput(sc);\n                int max = 0;\n                memo2 = new int[2][n][n];\n                for (int[][] x : memo2)\n                    for (int[] y : x)\n                        Arrays.fill(y, -1);\n                for (int i = 0; i < n; i++) {\n                    memo = new int[n][1 << n];\n                    for (int[] y : memo)\n                        Arrays.fill(y, -1);\n                    first = i;\n                    max = Math.max(max, dp(1 << i, i));\n                }\n                pw.println(max);\n            }\n        }\n\n        private int dp(int msk, int prev) {\n            if (msk == (1 << n) - 1)\n                return getLast(first, prev);\n            if (memo[prev][msk] != -1)\n                return memo[prev][msk];\n            int max = 0;\n            for (int i = 0; i < n; i++) {\n                if ((msk & 1 << i) == 0)\n                    max = Math.max(max, Math.min(getDiff(prev, i), dp(msk | 1 << i, i)));\n            }\n            return memo[prev][msk] = max;\n        }\n\n        private int getLast(int i, int j) {\n            if (memo2[0][i][j] != -1)\n                return memo2[0][i][j];\n            int min = Integer.MAX_VALUE;\n            for (int k = 0; k < m - 1; k++)\n                min = Math.min(min, Math.abs(arr[i][k] - arr[j][k + 1]));\n            return memo2[0][i][j] = min;\n        }\n\n        private int getDiff(int i, int j) {\n            if (memo2[1][i][j] != -1)\n                return memo2[1][i][j];\n            int min = Integer.MAX_VALUE;\n            for (int k = 0; k < m; k++)\n                min = Math.min(min, Math.abs(arr[i][k] - arr[j][k]));\n            return memo2[1][i][j] = min;\n        }\n\n    }\n\n    static class Scanner {\n        StringTokenizer st;\n        BufferedReader br;\n\n        public Scanner(InputStream s) {\n            br = new BufferedReader(new InputStreamReader(s));\n        }\n\n        public String next() {\n            try {\n                while (st == null || !st.hasMoreTokens())\n                    st = new StringTokenizer(br.readLine());\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    }\n}\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "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            FElongatedMatrix solver = new FElongatedMatrix();\n            solver.solve(1, in, out);\n            out.close();\n        }\n    }\n\n    static class FElongatedMatrix {\n        public void solve(int testNumber, FastInput in, FastOutput out) {\n            int n = in.readInt();\n            int m = in.readInt();\n            int[][] mat = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    mat[i][j] = in.readInt();\n                }\n            }\n\n            int[][] minDist = new int[n][n];\n            SequenceUtils.deepFill(minDist, (int) 1e9);\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    for (int k = 0; k < m; k++) {\n                        minDist[i][j] = Math.min(minDist[i][j], Math.abs(mat[i][k] - mat[j][k]));\n                    }\n                }\n            }\n            int[][] minDistBetweenHeadAndTail = new int[n][n];\n            SequenceUtils.deepFill(minDistBetweenHeadAndTail, (int) 1e9);\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    for (int k = 1; k < m; k++) {\n                        minDistBetweenHeadAndTail[i][j] = Math.min(minDistBetweenHeadAndTail[i][j], Math.abs(mat[i][k] - mat[j][k - 1]));\n                    }\n                }\n            }\n\n            Log2 log2 = new Log2();\n            BitOperator bo = new BitOperator();\n            int[][][] dp = new int[1 << n][n][n];\n            for (int i = 1; i < (1 << n); i++) {\n                if (i == Integer.lowestOneBit(i)) {\n                    dp[i][log2.floorLog(i)][log2.floorLog(i)] = (int) 1e9;\n                    continue;\n                }\n                for (int j = 0; j < n; j++) {\n                    for (int k = 0; k < n; k++) {\n                        if (bo.bitAt(i, j) == 0) {\n                            continue;\n                        }\n                        for (int t = 0; t < n; t++) {\n                            dp[i][j][k] = Math.max(dp[i][j][k],\n                                    Math.min(dp[bo.setBit(i, j, false)][t][k],\n                                            minDist[j][t]));\n                        }\n                    }\n                }\n            }\n\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    ans = Math.max(ans, Math.min(dp[(1 << n) - 1][i][j], minDistBetweenHeadAndTail[j][i]));\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 Log2 {\n        public int floorLog(int x) {\n            return 31 - Integer.numberOfLeadingZeros(x);\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 BitOperator {\n        public int bitAt(int x, int i) {\n            return (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    }\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\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastScanner in = new FastScanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        F solver = new F();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class F {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int n = in.ni(), m = in.ni();\n            int[][] a = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                a[i] = in.na(m);\n            }\n            if (n == 1) {\n                int ans = Integer.MAX_VALUE;\n                for (int i = 1; i < m; i++) {\n                    ans = Math.min(ans, Math.abs(a[0][i] - a[0][i - 1]));\n                }\n                out.println(ans);\n                return;\n            }\n            int[][] mk = new int[n][n];\n            int[][] mk1 = new int[n][n];\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    int minK = Integer.MAX_VALUE;\n                    int minK1 = Integer.MAX_VALUE;\n                    int minK2 = Integer.MAX_VALUE;\n                    for (int l = 0; l < m; l++) {\n                        minK = Math.min(minK, Math.abs(a[i][l] - a[j][l]));\n                        if (l > 0) {\n                            minK1 = Math.min(minK1, Math.abs(a[i][l] - a[j][l - 1]));\n                            minK2 = Math.min(minK2, Math.abs(a[i][l - 1] - a[j][l]));\n                        }\n                    }\n                    mk[i][j] = mk[j][i] = minK;\n                    mk1[i][j] = minK1;\n                    mk1[j][i] = minK2;\n                }\n            }\n\n            int ans = 0;\n            for (int first = 0; first < n; first++) {\n                int[][] dp = new int[1 << n][n];\n                for (int mask = 1; mask < (1 << n) - 1; mask++) {\n                    int bc = Integer.bitCount(mask);\n                    if ((mask & (1 << first)) != 0) {\n                        if (bc == 1) {\n                            dp[mask][first] = Integer.MAX_VALUE;\n                        }\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                                        dp[mask | (1 << j)][j] = Math.max(dp[mask | (1 << j)][j], Math.min(dp[mask][i], mk[i][j]));\n                                    }\n                                }\n                            }\n                        }\n                    }\n                }\n                for (int i = 0; i < n; i++) {\n                    if (i != first) {\n                        ans = Math.max(ans, Math.min(dp[(1 << n) - 1][i], mk1[first][i]));\n                    }\n                }\n            }\n            out.println(ans);\n        }\n\n    }\n\n    static class FastScanner {\n        private BufferedReader in;\n        private StringTokenizer st;\n\n        public FastScanner(InputStream stream) {\n            in = new BufferedReader(new InputStreamReader(stream));\n        }\n\n        public String ns() {\n            while (st == null || !st.hasMoreTokens()) {\n                try {\n                    String rl = in.readLine();\n                    if (rl == null) {\n                        return null;\n                    }\n                    st = new StringTokenizer(rl);\n                } catch (IOException e) {\n                    throw new RuntimeException(e);\n                }\n            }\n            return st.nextToken();\n        }\n\n        public int ni() {\n            return Integer.parseInt(ns());\n        }\n\n        public 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    }\n}\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class main{\n\n\tstatic int max = 5000+1;\n\tstatic FastReader in = new FastReader();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic int N = 18;\n\tstatic int[][] mn1 = new int[N][N]; \n\tstatic int[][] mn2 = new int[N][N];\n\tstatic int[][] dp = new int[1<<N][N];\n\tstatic int n,m;\n\t\n\tstatic void solve(){\n\t\tn = in.nextInt(); m = in.nextInt();\n\t\tint[][] a = new int[n][m];\n\t\tfor(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j] = in.nextInt();\n\t\tfor(int i=0;i<n;i++){\n\t\t\tArrays.fill(mn1[i],Integer.MAX_VALUE);\n\t\t\tArrays.fill(mn2[i],Integer.MAX_VALUE);\n\t\t}\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\tfor(int k=0;k<m;k++){\n\t\t\t\t\tmn1[i][j] = Math.min(mn1[i][j],Math.abs(a[i][k]-a[j][k]));\n\t\t\t\t\tif(k<=m-2)\n\t\t\t\t\t\tmn2[i][j] = Math.min(mn2[i][j],Math.abs(a[i][k]-a[j][k+1]));\n\t\t\t\t}\n\t\tint ans = 0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tfor(int x=0;x<1<<n;x++)Arrays.fill(dp[x],-1);\n\t\t\tfor(int j=0;j<n;j++)dp[1<<j][j] = 0;\n\t\t\tdp[1<<i][i] = Integer.MAX_VALUE;\n\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\tans = Math.max(ans,Math.min(mn2[j][i],calc((1 << n) - 1, j)));\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tstatic int calc(int mask, int v){\n\t\tif (dp[mask][v] != -1)\n\t\t\treturn dp[mask][v];\n\t\tdp[mask][v] = 0;\n\t\tfor(int u=0;u<n;u++) if (v != u && (((mask >> u) & 1)>0))\n\t\t\tdp[mask][v] = Math.max(dp[mask][v], Math.min(mn1[u][v], calc(mask ^ (1 << v), u)));\n\t\treturn dp[mask][v];\n\t}\n\n\n\tpublic static void main(String[] args){\n\t\tsolve();\n\t\tout.flush();\n\t\tout.close();\n\t}\t\n\n\tstatic 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(){\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        String nextLine(){\n            String str = \"\";\n            try{   \n                str = br.readLine();\n            }catch (IOException e){\n                e.printStackTrace();\n            }  \n            return str;\n        }\n        int nextInt(){return Integer.parseInt(in.next());}\n    \tlong nextLong(){return Long.parseLong(in.next());}\n    \tdouble nextDouble(){return Double.parseDouble(in.next());}\n    }\n}\n\n\n\n\n// |xvcxv|vcv[cvcvc|cxv||]vcvx:v|c|vxc|[|cvx:cxvx||||]", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "\nimport java.io.*;\nimport java.util.*;\n\npublic class D{\n\n\tstatic int bot;\n\tstatic int n,m;\n\tstatic int [][]a;\n\tstatic int [][]Min;\n\tstatic int [][]memo;\n\tstatic int K;\n\tstatic int dp(int msk,int ones,int last) {\n\t\tif(ones==n) {\n\t\t\treturn Min[last][bot]>=K?1:0;\n\t\t}\n\t\tif(memo[last][msk]!=-1)\n\t\t\treturn memo[last][msk];\n\t\tint ans=0;\n\t\tfor(int nxt=0;nxt<n;nxt++)\n\t\t\tif((msk & (1<<nxt)) ==0 && Min[last][nxt]>=K)\n\t\t\t{\n\t\t\t\tans|=dp(msk|1<<nxt,ones+1,nxt);\n\t\t\t}\n\t\treturn memo[last][msk]= ans;\n\t}\n\tstatic boolean check(int top,int bottom) {\n\t\tfor(int j=0;j+1<m;j++)\n\t\t{\n\t\t\tint diff=Math.abs(a[bottom][j]-a[top][j+1]);\n\t\t\tif(diff<K)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\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\tm=sc.nextInt();\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]=sc.nextInt();\n\t\tMin=new int [n][n];\n\t\tif(n==1) {\n\t\t\tint lo=0,hi=(int)1e9;\n\t\t\tint ans=0;\n\t\t\twhile(lo<=hi) {\n\t\t\t\tK=lo+hi>>1;\n\t\t\t\t\n\t\t\t\tif(check(0, 0))\n\t\t\t\t{\n\t\t\t\t\tans=K;\n\t\t\t\t\tlo=K+1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\thi=K-1;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t\treturn;\n\t\t}\n\t\tfor(int i1=0;i1<n;i1++)\n\t\t\tfor(int i2=0;i2<n;i2++)\n\t\t\t{\n\t\t\t\tif(i1==i2)\n\t\t\t\t\tcontinue;\n\t\t\t\tint min=(int) 1e9;\n\t\t\t\tfor(int j=0;j<m;j++)\n\t\t\t\t\tmin=Math.min(Math.abs(a[i1][j]-a[i2][j]), min);\n\t\t\t\tMin[i1][i2]=min;\n\t\t\t}\n\t\tmemo=new int [n][1<<n];\n\t\tint ans=0;\n\t\tint lo=0,hi=(int)1e9;\n\t\twhile(lo<=hi) {\n\t\t\tK=lo+hi>>1;\n\t\tfor(int []x:memo)\n\t\t\tArrays.fill(x, -1);\n\t\tint ok=0;\n\t\tfor(int top=0;top<n && ok==0;top++)\n\t\t\tfor(int bottom=0;bottom<n && ok==0 ;bottom++) {\n\t\t\t\tbot=bottom;\n\t\t\t\tif(top==bottom || !check(top, bottom))\n\t\t\t\t\tcontinue;\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tint dp=dp(1<<top | 1<<bottom, 2, top);\n\t\t\t\tok|=dp;\n\t\t\t\t\n\t\t\t}\n\t\tif(ok==1)\n\t\t{\n\t\t\tans=K;\n\t\t\tlo=K+1;\n\t\t\t\n\t\t}\n\t\telse\n\t\t\thi=K-1;\n\t\t}\n\t\tout.println(ans);\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", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.Vector;\n\npublic class Main {\n\t\n\tprivate static final int SIM = 1;\n\tprivate static final int NAO = 2;\n\t\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\t\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint[][] a = new int[n][m];\n\t\tint[][] graphVerticial = null;\n\t\tint[][] graphDiagonal = null;\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\ta[i][j] = in.nextInt();\n\t\t\t}\n\t\t}\n\t\t\n\t\tgraphVerticial = createGraphVertical(n, m, a);\n\t\tgraphDiagonal = createGraphDiagonal(n, m, a);\n\t\t\n//\t\tprint(graphVerticial);\n//\t\tSystem.out.println(\"##########################\");\n//\t\tprint(graphDiagonal);\n\t\t\n\t\tint result = 0;\n\t\tint k = 1;\n\t\tint piso = 0;\n\t\tint teto = 1000000000;\n\t\t\n\t\twhile(true) {\n\t\t\t\n\t\t\tk = (int) Math.ceil((teto - piso) / 2.0) + piso;\n\t\t\t\n\t\t\tif(isOk(n, k, graphVerticial, graphDiagonal)) {\n\t\t\t\tresult = Math.max(result, k);\n\t\t\t\tpiso = k;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tteto = k - 1;\n\t\t\t}\n\n\t\t\t//System.out.println(piso + \", \" + teto);\n\t\t\t\n\t\t\tif(teto <= piso) break;\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(result);\n\t\t\n\t}\n\t\n\tpublic static int[][] createGraphVertical(int n, int m, int[][] a){\n\t\t\n\t\tint[][] graph = new int[n][n];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tfor(int j = 0; j  < n; j++) {\n\t\t\t\t\n\t\t\t\tif(i == j) continue;\n\t\t\t\tif(i > j) {graph[i][j] = graph[j][i]; continue;}\n\t\t\t\t\n\t\t\t\tgraph[i][j] = Integer.MAX_VALUE;\n\t\t\t\t\n\t\t\t\tfor(int k = 0; k < m; k++) {\n\t\t\t\t\tgraph[i][j] = Math.min(graph[i][j], Math.abs(a[i][k] - a[j][k]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn graph;\n\t}\n\t\n\tpublic static int[][] createGraphDiagonal(int n, int m, int[][] a){\n\t\t\n\t\tint[][] graph = new int[n][n];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tfor(int j = 0; j  < n; j++) {\n\t\t\t\t\n\t\t\t\tgraph[i][j] = Integer.MAX_VALUE;\n\t\t\t\t\n\t\t\t\tfor(int k = 0; k < m - 1; k++) {\n\t\t\t\t\tgraph[i][j] = Math.min(graph[i][j], Math.abs(a[j][k] - a[i][k + 1]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn graph;\n\t}\n\t\n\tpublic static int hasPath(int n, int k, int origem, int destino, int conjunto, int[][] graph, int[][][] pd) {\n\t\t\n\t\t//System.out.println(origem + \", \" + destino);\n\t\t//print(conjunto);\n\t\t\n\t\tif(pd[origem][destino][conjunto] != 0) return pd[origem][destino][conjunto];\n\t\t\n\t\tif(conjunto == 0) {\n\t\t\treturn origem == destino ? SIM : NAO;\n\t\t} \n\t\telse if(origem == destino){\n\t\t\treturn NAO;\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tif(i == origem) continue;\n\t\t\t\n\t\t\tint novoConjunto = conjunto - (1 << i);\n\t\t\tboolean pertenceConjunto = ((conjunto >> i) % 2) == 1;\n\t\t\t\n\t\t\tif(pertenceConjunto && graph[origem][i] >= k && hasPath(n, k, i, destino, novoConjunto, graph, pd) == SIM) {\n\t\t\t\tpd[origem][destino][conjunto] = SIM;\n\t\t\t\treturn pd[origem][destino][conjunto];\n\t\t\t}\n\t\t}\n\t\t\n\t\tpd[origem][destino][conjunto] = NAO;\n\t\t\n\t\treturn pd[origem][destino][conjunto];\n\t\t\n\t}\n\t\n\tpublic static boolean isOk(int n, int k, int[][] graphVertical, int[][] graphDiagonal) {\n\t\t\n\t\tint conjunto = (int) Math.pow(2, n) - 1;\n\t\t\n\t\tint[][][] pd = new int[n][n][(int)Math.pow(2, n)];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\t\n\t\t\t\tif(i == j && n > 1) continue;\n\t\t\t\t\n\t\t\t\tint novoConjunto = conjunto - (1 << i);\n\t\t\t\t\n\t\t\t\tif(graphDiagonal[i][j] >= k && hasPath(n, k, i, j, novoConjunto, graphVertical, pd) == SIM) {\n\t\t\t\t\treturn true;\n\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\t\n\t}\n\t\n\tpublic static void print(int[][] graph) {\n\t\t\n\t\tfor(int i = 0; i < graph.length; i++) {\n\t\t\t\n\t\t\tfor(int j = 0; j < graph.length; j++) {\n\t\t\t\t\n//\t\t\t\tif(graph[i][j] >= 3 ) System.out.print(\"1 \");\n//\t\t\t\telse System.out.print(\"0 \");\n\t\t\t\tSystem.out.print(graph[i][j] + \" \");\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println();\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void print(int n) {\n\t\t\n\t\tList<Integer> bits = new Vector<>();\n\t\t\n\t\twhile(n > 0) {\n\t\t\t\n\t\t\tbits.add(n % 2);\n\t\t\tn /= 2;\n\t\t}\n\t\t\n\t\tfor(int i = bits.size() - 1; i >= 0; i--) {\n\t\t\tSystem.out.print(bits.get(i));\n\t\t}\n\t\t\n\t\tSystem.out.println();\n\t\t\n\t}\n\t\n}\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1102f {\n\n    public static void main(String[] args) throws IOException {\n        int n = rni(), m = ni(), a[][] = new int[n][];\n        for (int i = 0; i < n; ++i) {\n            a[i] = ria(m);\n        }\n        int delta[][] = new int[n][n], end_delta[][] = new int[n][n], dp[][][] = new int[n][1 << n][n];\n        for (int i = 0; i < n; ++i) {\n            fill(delta[i], IBIG);\n            fill(end_delta[i], IBIG);\n            delta[i][i] = 0;\n        }\n        for (int i = 0; i < n - 1; ++i) {\n            for (int j = i + 1; j < n; ++j) {\n                for (int k = 0; k < m; ++k) {\n                    delta[i][j] = delta[j][i] = min(delta[i][j], abs(a[i][k] - a[j][k]));\n                }\n            }\n        }\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                for (int k = 1; k < m; ++k) {\n                    end_delta[i][j] = min(end_delta[i][j], abs(a[j][k] - a[i][k - 1]));\n                }\n            }\n        }\n        for (int[][] layer : dp) {\n            for (int[] row : layer) {\n                fill(row, IBIG);\n            }\n        }\n        for (int i = 1; i < 1 << n; ++i) {\n            boolean one_bit = Integer.bitCount(i) == 1;\n            for (int j = 0; j < n; ++j) {\n                if ((i & (1 << j)) > 0) {\n                    for (int l = 0; l < n; ++l) {\n                        if ((i & (1 << l)) == 0) {\n                            int max = 0;\n                            for (int k = 0; k < n; ++k) {\n                                if ((one_bit || j != k) && (i & (1 << k)) > 0) {\n                                    max = max(max, min(dp[j][i][k], delta[k][l]));\n                                }\n                            }\n                            // pr(j + \" \");\n                            // pr(Integer.toBinaryString(i) + \" \");\n                            // prln(l, max);\n                            dp[j][i | (1 << l)][l] = max;\n                        }\n                    }\n                }\n            }\n        }\n        int ans = 0;\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                if (i != j) {\n                    // prln(i, j, dp[i][(1 << n) - 1][j]);\n                    ans = max(ans, min(dp[i][(1 << n) - 1][j], end_delta[j][i]));\n                }\n            }\n        }\n        if (n == 1) {\n            ans = maxof(end_delta[0]);\n        }\n        prln(ans);\n        close();\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    // 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    // 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 boolean pryesno(boolean b) {prln(b ? \"yes\" : \"no\"); return b;};\n    static boolean pryn(boolean b) {prln(b ? \"Yes\" : \"No\"); return b;}\n    static boolean prYN(boolean b) {prln(b ? \"YES\" : \"NO\"); return b;}\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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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();}\n}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.util.Scanner;\n\npublic class Main {\n\t\n\tprivate static boolean check(int n , int m , int k) {\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 l = 0;l < (1 << n);l ++) {\n\t\t\t\t\tdp[i][j][l] = - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0;i < n;i ++) {\n\t\t\tif (dfs(i , i , n , m , k , 0)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t\t\n\t}\t\n\t\n\tprivate static boolean dfs(int first , int current , int n , int m , int k , int bitmap) {\n\t\n\t\tbitmap |= (1 << current);\n\t\tif (bitmap == (1 << n) - 1) {\n\t\t\t// check first and current\t\t\t\n\t\t\tif (n == 1) {\n\t\t\t\tif (m > 1) {\n\t\t\t\t\tif (rowMinDist[current] >= k) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t} else {\t\t\t\t\t\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (m > 1) {\n\t\t\t\t\tif (minDistBetweenHeadAndTail[first][current] >= k) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (dp[first][current][bitmap] >= 0) {\n\t\t\t\tif (dp[first][current][bitmap] > 0) {\n\t\t\t\t\treturn true;\n\t\t\t\t} else {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tshort ans = 0;\n\t\t\tfor (int i = 0;i < n;i ++) {\n\t\t\t\tif ((bitmap & (1 << i)) == 0 && minDistBetweenRow[current][i] >= k) {\t\t\t\t\t\n\t\t\t\t\tif (dfs(first , i , n , m , k , bitmap)) {\n\t\t\t\t\t\tans = 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\t\n\t\t\tdp[first][current][bitmap] = ans;\n\t\t\tif (ans > 0) {\t\t\t\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\n\tprivate static short[][][] dp = new short[20][20][(1 << 17)];\t\n\tprivate static int[][] input = new int[20][10010];\n\tprivate static int[][] minDistBetweenRow = new int[20][20];\n\tprivate static int[][] minDistBetweenHeadAndTail = new int[20][20];\n\tprivate static int[] rowMinDist = new int[20];\n\t\n\tpublic static void main(String[] args) {\t\t\n\t\n\t\tScanner scan = new Scanner(System.in);\n\t\n\t\tint i , j , k , n , m;\n\t\tn = scan.nextInt();\n\t\tm = scan.nextInt();\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tfor (j = 0;j < m;j ++) {\n\t\t\t\tinput[i][j] = scan.nextInt();\n\t\t\t}\n\t\t}\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tfor (j = i + 1;j < n;j ++) {\n\t\t\t\tint minDist = - 1;\n\t\t\t\tfor (k = 0;k < m;k ++) {\n\t\t\t\t\tint dist = Math.abs(input[i][k] - input[j][k]);\n\t\t\t\t\tif (dist < minDist || minDist < 0) {\n\t\t\t\t\t\tminDist = dist;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tminDistBetweenRow[i][j] = minDistBetweenRow[j][i] = minDist;\t\t\n\t\t\t}\n\t\t}\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tfor (j = 0;j < n;j ++) {\n\t\t\t\tif (i != j) {\n\t\t\t\t\t// i head , j tail\n\t\t\t\t\tint minDist = - 1;\n\t\t\t\t\tfor (k = 0;k < m - 1;k ++) {\t\t\t\t\t\t\n\t\t\t\t\t\tint dist = Math.abs(input[j][k] - input[i][k + 1]);\n\t\t\t\t\t\tif (dist < minDist || minDist < 0) {\n\t\t\t\t\t\t\tminDist = dist;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tminDistBetweenHeadAndTail[i][j] = minDist;\n\t\t\t\t}\n\t\t\t}\n\t\t}\t\t\n\t\tfor (i = 0;i < n;i ++) {\n\t\t\tint minDist = - 1;\n\t\t\tfor (j = 0;j < m - 1;j ++) {\n\t\t\t\tint dist = Math.abs(input[i][j] - input[i][j + 1]);\n\t\t\t\tif (dist < minDist || minDist < 0) {\n\t\t\t\t\tminDist = dist;\n\t\t\t\t}\n\t\t\t}\n\t\t\trowMinDist[i] = minDist;\n\t\t}\n\t\tint low = 0 , high = 1000000010;\n\t\twhile (low < high) {\n\t\t\tint mid = (low + high) / 2;\n\t\t\tif (check(n , m , mid)) {\t\t\t\t\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(high - 1);\n\n\t}\n   \n    \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "// Don't place your source in a package\nimport java.lang.reflect.Array;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\n\n\n\n\n\n\n\n// Please name your class Main\npublic class Main {\n    static FastScanner fs=new FastScanner();\n    static class FastScanner {//scanner from SecondThread\n        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n        StringTokenizer st=new StringTokenizer(\"\");\n        public String next() {\n            while (!st.hasMoreElements())\n                try {\n                    st=new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            return st.nextToken();\n        }\n        int Int() {\n            return Integer.parseInt(next());\n        }\n\n        long Long() {\n            return Long.parseLong(next());\n        }\n\n        String Str(){\n            return next();\n        }\n    }\n\n\n    public static void main (String[] args) throws java.lang.Exception {\n        PrintWriter out = new PrintWriter(System.out);\n\n\n        int T=1;\n        for(int t=0;t<T;t++){\n            int n=Int();int m=Int();\n            int A[][]=new int[n][m];\n\n            for(int i=0;i<n;i++){\n                for(int j=0;j<m;j++){\n                    A[i][j]=Int();\n                }\n            }\n\n            Sol sol=new Sol();\n            sol.solution(out,A);\n        }\n        out.flush();\n\n    }\n\n    public static int Int(){\n        return fs.Int();\n    }\n    public static long Long(){\n        return fs.Long();\n    }\n    public static String Str(){\n        return fs.Str();\n    }\n\n}\n\n\n\nclass Sol{\n    int dif[][];\n    int dp[][][];\n    public void solution(PrintWriter out,int A[][]){\n        int n=A.length;int m=A[0].length;\n        int res=0;\n        dif=new int[n][n];\n        for(int i=0;i<n;i++){\n            for(int j=i+1;j<A.length;j++){\n                int mn=Integer.MAX_VALUE;\n                for(int k=0;k<m;k++){//different ordering pair\n                    mn=Math.min(mn,Math.abs(A[i][k]-A[j][k]));\n                }\n                dif[i][j]=mn;\n                dif[j][i]=mn;\n                //System.out.println(i+\"  \"+j+\"  \"+mn);\n            }\n        }\n\n        int state=(1<<n)-1;\n        dp=new int[state+5][n+1][n+1];\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        }\n\n        for(int i=0;i<n;i++){\n            res=Math.max(res,dfs(A,state^(1<<i),i,i));\n        }\n\n        out.println(res);\n\n    }\n\n    public int dfs(int A[][],int state,int pre,int start){\n\n        if(state==0){\n            int mn=Integer.MAX_VALUE;\n            for(int i=1;i<A[0].length;i++){\n                mn=Math.min(mn,Math.abs(A[start][i]-A[pre][i-1]));\n            }\n            return mn;\n        }\n\n\n\n        if(dp[state][pre][start]!=-1){\n            return dp[state][pre][start];\n        }\n\n        int res=0;\n        for(int i=0;i<A.length;i++){\n            if((state&(1<<i))!=0){\n                int di=dif[pre][i];\n                res=Math.max(res,Math.min(di,dfs(A,state^(1<<i),i,start)));\n            }\n        }\n\n\n        //System.out.println(Integer.toBinaryString(state)+\"  \"+res);\n        dp[state][pre][start]=res;\n        return res;\n    }\n\n\n\n\n\n\n\n\n}\n\n\n\n\n\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class f{\n\n   public static void main(String[] args) {\n      MyScanner sc = new MyScanner();\n      out = new PrintWriter(new BufferedOutputStream(System.out));\n      \n      int n = sc.nextInt();\n      int m = sc.nextInt();\n      int[][] arr = new int[n][m];\n      for(int i=0; i<n; i++) {\n          for(int j=0; j<m; j++) {\n              arr[i][j] = sc.nextInt();\n          }\n      }\n      if(n==1) {\n          int min = Integer.MAX_VALUE;\n          for(int i=0; i<m-1; i++) {\n              min = Math.min(min, Math.abs(arr[0][i]-arr[0][i+1]));\n          }\n          out.println(min);\n          out.close();\n      }\n      int[][] adj = new int[n][n];\n      int[][] edgeadj = new int[n][n];\n      for(int i=0; i<n; i++) {\n          for(int j=i+1; j<n; j++) {\n              int min = Integer.MAX_VALUE;\n              for(int k=0; k<m; k++) {\n                  min = Math.min(min, Math.abs(arr[i][k]-arr[j][k]));\n              }\n              adj[i][j]=min;\n              adj[j][i]=min;\n              int min1 = Integer.MAX_VALUE;\n              int min2 = Integer.MAX_VALUE;\n              for(int k=0; k<m-1; k++) {\n                  min1 = Math.min(min1, Math.abs(arr[i][k]-arr[j][k+1]));\n                  min2 = Math.min(min2, Math.abs(arr[i][k+1]-arr[j][k]));\n              }\n              edgeadj[i][j]=min1;\n              edgeadj[j][i]=min2;\n          }\n      }\n      int power = (int)Math.pow(2,n);\n      int[][][] dp = new int[power][n][n];\n      for(int i=0; i<n; i++) {\n          dp[(int)Math.pow(2,i)][i][i] = Integer.MAX_VALUE;\n      }\n      for(int bit=0; bit<power; bit++) {\n          for(int j=0; j<n; j++) {\n              for(int k=0; k<n; k++) {\n                  if((bit & (1<<j))>0 && (bit & (1<<k))>0 && j!=k) {\n                      int temp = bit;\n                      temp &= ~(1<<k);\n                      int ans = 0;\n                      for(int l=0; l<n; l++) {\n                          if((temp & (1<<l))>0) {\n                              int min = Math.min(dp[temp][j][l], adj[l][k]);\n                              ans = Math.max(ans, min);\n                          }\n                      }\n                      if(j!=k) {\n                          dp[bit][j][k] = ans;\n                      }\n                    // out.println(bit + \" \" + j + \" \" + k + \" \" + dp[bit][j][k]);\n                  }\n              }\n          }\n      }\n      int answer = 0;\n      for(int i=0; i<n; i++) {\n          for(int j=0; j<n; j++) {\n              if(i!=j) {\n                int ans = Math.min(dp[power-1][i][j], edgeadj[i][j]);\n                answer = Math.max(answer, ans);\n              }\n          }\n      }\n    //   for(int i=0; i<n; i++) {\n    //       for(int j=0; j<n; j++) {\n    //           out.println(dp[power-1][i][j]+\" \"+edgeadj[i][j]);\n    //       }\n    //   }\n      out.println(answer);\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   //-----------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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n    static MyScanner sc;\n    static PrintWriter pw;\n\n    public static void main(String[] args) throws Throwable {\n        sc = new MyScanner();\n        pw = new PrintWriter(System.out);\n\n        n = sc.nextInt();\n        int m = sc.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] = sc.nextInt();\n        val = new int[n][n];\n        for (int i = 0; i < n; i++)\n            Arrays.fill(val[i], Integer.MAX_VALUE);\n        for (int i = 0; i < n; i++)\n            for (int j = i; j < n; j++) {\n                for (int k = 0; k < m; k++)\n                    val[i][j] = val[j][i] = Math.min(val[i][j], Math.abs(a[i][k] - a[j][k]));\n            }\n\n        val2 = new int[n][n];\n        for (int i = 0; i < n; i++)\n            Arrays.fill(val2[i], Integer.MAX_VALUE);\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < n; j++) {\n                for (int k = 0; k < m - 1; k++)\n                    val2[i][j] = Math.min(val2[i][j], Math.abs(a[i][k] - a[j][k + 1]));\n            }\n        mem = new Integer[n][n][1 << n];\n        int ans = 0;\n        for (int i = 0; i < n; i++) {\n            ans = Math.max(ans, dp(i, i, 1 << i));\n        }\n        if (n == 1)\n            pw.println(val2[0][0]);\n        else\n            pw.println(ans);\n\n\n        pw.flush();\n        pw.close();\n    }\n\n    static int n;\n    static int[][] val, val2;\n    static Integer[][][] mem;\n\n    static int dp(int st, int lst, int msk) {\n        int bits = Integer.bitCount(msk);\n        if (mem[st][lst][msk] != null)\n            return mem[st][lst][msk];\n        int ans = 0;\n        for (int i = 0; i < n; i++)\n            if ((msk & (1 << i)) == 0) {\n                int newMsk = (msk | (1 << i));\n                if (bits < n - 1)\n                    ans = Math.max(ans, Math.min(val[lst][i], dp(st, i, newMsk)));\n                else\n                    ans = Math.max(ans, Math.min(val[lst][i], val2[i][st]));\n            }\n        return mem[st][lst][msk] = ans;\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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main {\n    static final long MOD = 1_000_000_007, INF = 1_000_000_000_000_000_000L;\n    static final int INf = 1_000_000_000;\n    static FastReader reader;\n    static PrintWriter writer;\n    public static void main(String[] args) {\n        Thread t = new Thread(null, new O(), \"Integer.MAX_VALUE\", 100000000);\n        t.start();\n    }\n    static class O implements Runnable {\n        public void run() {\n            try {\n                magic();\n            }\n            catch (Exception e) {\n                e.printStackTrace();\n                System.exit(1);\n            }\n        }\n    }\n    static class FastReader {\n        final private int BUFFER_SIZE = 1 << 16;\n        private DataInputStream din;\n        private byte[] buffer;\n        private int bufferPointer, bytesRead;\n\n        public FastReader() {\n            din = new DataInputStream(System.in);\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public FastReader(String file_name) throws IOException {\n            din = new DataInputStream(new FileInputStream(file_name));\n            buffer = new byte[BUFFER_SIZE];\n            bufferPointer = bytesRead = 0;\n        }\n\n        public String readLine() throws IOException {\n            byte[] buf = new byte[1000000];\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    static int n,m,pre[][], pre_stop_and_start[][],mat[][], dp[][][];\n    static void magic() throws IOException {\n        reader = new FastReader();\n        writer = new PrintWriter(System.out, true);\n        n = reader.nextInt();\n        m = reader.nextInt();\n        mat = new int[n][m];\n        for(int i=0;i<n;++i) {\n            for(int j=0;j<m;++j) {\n                mat[i][j] = reader.nextInt();\n            }\n        }\n        if(n==1) {\n            int ans = Integer.MAX_VALUE;\n            for(int i=0;i+1<m;++i) {\n                ans = min(ans, abs(mat[0][i] - mat[0][i+1]));\n            }\n            writer.println(ans);\n            System.exit(0);\n        }\n        pre = new int[n][n];\n        pre_stop_and_start = new int[n][n];\n        for(int i=0;i<n;++i) {\n            for(int j=i+1;j<n;++j) {\n                int min = Integer.MAX_VALUE;\n                for(int k=0;k<m;++k) {\n                    min = min(min, abs(mat[i][k] - mat[j][k]));\n                }\n                pre[i][j] = pre[j][i] = min;\n            }\n        }\n        for(int i=0;i<n;++i) {\n            for(int j=0;j<n;++j) {\n                if(j==i) {\n                    continue;\n                }\n                int min = Integer.MAX_VALUE;\n                for(int k=0;k+1<m;++k) {\n                    min = min(min, abs(mat[j][k+1] - mat[i][k]));\n                }\n                pre_stop_and_start[i][j] = min;\n            }\n        }\n//        writer.println(\"Pre array: \");\n//        for(int i=0;i<n;++i) {\n//            for(int j=0;j<n;++j) {\n//                writer.print(pre[i][j]+\" \");\n//            }\n//            writer.println();\n//        }\n//        writer.println(\"Pre stop and start array: \");\n//        for(int i=0;i<n;++i) {\n//            for(int j=0;j<n;++j) {\n//                if(j==i) {\n//                    writer.print(\"SKIP \");\n//                }\n//                else writer.print(pre_stop_and_start[i][j]+\" \");\n//            }\n//            writer.println();\n//        }\n        dp = new int[1<<n][n][n];\n        for(int i=0;i<(1<<n);++i) {\n            for(int j=0;j<n;++j) {\n                for(int k=0;k<n;++k) {\n                    dp[i][j][k] = -1;\n                }\n            }\n        }\n        int ans = 0;\n        for(int i=0;i<n;++i) {\n            ans = max(ans, f((1<<i), i, i));\n        }\n        writer.println(ans);\n    }\n    static int f(int mask_already, int prev, int first) {\n        if(mask_already==(1<<n) - 1) {\n            return pre_stop_and_start[prev][first];\n        }\n        if(dp[mask_already][prev][first] != -1) {\n            return dp[mask_already][prev][first];\n        }\n        int max = 0;\n        for(int i=0;i<n;++i) {\n            if((mask_already&(1<<i)) == 0) {\n                max = max(max, min(pre[prev][i], f(mask_already|(1<<i), i, first)));\n            }\n        }\n        return dp[mask_already][prev][first] = max;\n    }\n}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "/*\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 F\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         int N = Integer.parseInt(st.nextToken());\n         int M = Integer.parseInt(st.nextToken());\n         int[][] grid = new int[N][M];\n         for(int i=0; i < N; i++)\n            grid[i] = readArr(M, infile, st);\n         int[][] mindiff = new int[N][N];\n         for(int a=0; a < N; a++)\n            for(int b=a+1; b < N; b++)\n            {\n               int val = Integer.MAX_VALUE;\n               for(int i=0; i < M; i++)\n                  val = Math.min(val, Math.abs(grid[a][i]-grid[b][i]));\n               mindiff[a][b] = mindiff[b][a] = val;\n            }\n         int res = 0;\n         for(int start=0; start < N; start++)\n         {\n            int[][] dp = new int[1<<N][N];\n            Arrays.fill(dp[0], Integer.MAX_VALUE);\n            for(int mask=0; mask < (1<<N); mask++)\n            {\n               if(Integer.bitCount(mask) == 1 && mask != (1<<start))\n                  continue;\n               for(int prev=0; prev < N; prev++)\n                  if((mask&(1<<prev)) > 0 || mask == 0)\n                  {\n                     for(int b=0; b < N; b++)\n                        if((mask&(1<<b)) == 0)\n                        {\n                           int submask = mask|(1<<b);\n                           if(mask == 0)\n                              dp[submask][b] = Integer.MAX_VALUE;\n                           else\n                              dp[submask][b] = Math.max(dp[submask][b], Math.min(dp[mask][prev], mindiff[prev][b]));\n                        }\n                  }\n            }\n            for(int b=0; b < N; b++)\n            {\n               int temp = dp[(1<<N)-1][b];\n               for(int i=0; i < M-1; i++)\n                  temp = Math.min(temp, Math.abs(grid[b][i]-grid[start][i+1]));\n               res = Math.max(res, temp);\n            }\n         }\n         System.out.println(res);\n      }\n      public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception\n      {\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         return arr;\n      }\n   }", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class EMatrix{\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 = (int)(1E9);\n            int n , m;\n            int a[][];\n            int gm[];\n            boolean visit[][]; int dp[][];\n            boolean check(int d){\n                if(n == 1){\n                    for(int i = 0; i < m - 1; i++){\n                        if(Math.abs(a[0][i] - a[0][i + 1]) < d)return false;\n                    }\n                    return true;\n                }\n                int nm[] = new int[n], pm[] = new int[n];\n                for(int i = 0; i < n; i++){\n                    boolean r;\n                    for(int j = 0; j < n; j++){\n                        if(j == i)continue;\n                        r = true;\n                        for(int k = 0; k < m; k++){\n                            if(Math.abs(a[i][k] - a[j][k]) < d){\n                                r = false; break;\n                            }\n                        }\n                        if(r){\n                            nm[i] |= (1 << j);\n                        }\n                        r = true;\n                        for(int k = 0; k < m - 1; k++){\n                            if(Math.abs(a[i][k + 1] - a[j][k]) < d){\n                                r = false; break;\n                            }\n                        }\n                        if(r){\n                            pm[i] |= (1 << j);\n                        }\n                    }\n                }\n                // for(int i = 0; i < n; i++){\n                //     System.out.println(nm[i] + \" \" + pm[i]);\n                // }\n                for(int i = 0; i < n; i++){\n                    gm = new int[n];\n                    gm[i] = nm[i];\n                    for(int j = 0; j < n; j++){\n                        if(j == i)continue;\n                        if((nm[j] & (1 << i)) != 0){\n                            gm[j] = nm[j] ^ (1 << i);\n                        }else{\n                            gm[j] = nm[j];\n                        }\n                    }\n                    for(int j = 0; j < n; j++){\n                        if(j == i)continue;\n                        if((pm[i] >> j) % 2 == 1){\n                            gm[j] |= (1 << i);\n                        }\n                    }\n                    visit = new boolean[n][1 << n]; dp = new int[n][1 << n];\n                    // for(int x = 0; x < n; x++)System.out.println(gm[x]);\n                    if(dfs(i, i, (1 << i)) == n){\n                        return true;\n                    }\n                }\n                return false;\n            }\n            int dfs(int u, int r, int mask){\n                // System.out.println(u + \" \" + r + \" \" + mask);\n                if(u == r && mask == (1 << n) - 1)return 0;\n                if(visit[u][mask])return dp[u][mask];\n                visit[u][mask] = true;\n                int val = 0;\n                for(int i = 0; i < n; i++){\n                    if((gm[u] >> i) % 2 == 1 && ((i == r && mask == (1 << n) - 1) || (mask >> i) % 2 != 1)){\n                        val = Math.max(val, 1 + dfs(i, r, mask | (1 << i)));\n                    }\n                }\n                // System.out.println(u + \" \" + mask + \" \" + val);\n                return dp[u][mask] = val;\n            }\n           public void solve(int testNumber, InputReader in, PrintWriter out) {\n            n = in.nextInt(); m = in.nextInt();\n            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                }\n            }\n            int l = 0, r = max, ans = 0;\n            while(l <= r){\n                int m = (l + r) >> 1;\n                if(check(m)){\n                    ans = m;\n                    l = m + 1;\n                }else{\n                    r = m - 1;\n                }\n            }\n            out.println(ans);\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<m;i++){\n//               int u=in.nextInt(),v=in.nextInt();long wt=in.nextLong();\n//               c[u]++;c[v]++;from[i]=u;to[i]=v;w[i]=wt;\n//              }\n//              for(int i=1;i<=n;i++){\n//               ja[i]=new pair[c[i]];c[i]=0;\n//              }\n//              for(int i=0;i<m;i++){\n//               ja[from[i]][c[from[i]]++]=new pair(to[i],w[i]);\n//               ja[to[i]][c[to[i]]++]=new pair(from[i],w[i]);\n//              }\n//             }\n//        int[] radixSort(int[] f){ return radixSort(f, f.length); }\n//    int[] radixSort(int[] f, int n)\n//    {\n//        int[] to = new int[n];\n//        {\n//            int[] b = new int[65537];\n//            for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;\n//            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n//            for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];\n//            int[] d = f; f = to;to = d;\n//        }\n//        {\n//            int[] b = new int[65537];\n//            for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;\n//            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n//            for(int i = 0;i < 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}", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n    public static void main(String[] args) {\n        new Thread(null, new Runnable() {\n            public void run() {\n                new Main().solve();\n            }\n        }, \"1\", 1 << 26).start();\n    }\n\n    void solve() {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        ScanReader in = new ScanReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        FElongatedMatrix solver = new FElongatedMatrix();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class FElongatedMatrix {\n        int[][] G;\n        int[][] G1;\n\n        public int findIt(int[] map, int n, int start) {\n            int[][] mask = new int[1 << n][n];\n            for (int i = 0; i < n; i++) mask[(1 << i)][i] = G[start][map[i]];\n            for (int i = 1; i < (1 << n); i++) {\n                for (int j = 0; j < n; j++) {\n                    for (int k = 0; k < n; k++) {\n                        if (k != j && (i & (1 << k)) == 0 && (i & (1 << j)) != 0) {\n                            mask[(i | (1 << k))][k] = Math.max(mask[(i | (1 << k))][k], Math.min(mask[i][j], G[map[j]][map[k]]));\n                        }\n                    }\n                }\n            }\n            int ans = 0;\n            for (int i = 0; i < n; i++) ans = Math.max(ans, Math.min(mask[(1 << n) - 1][i], G1[start][map[i]]));\n            return ans;\n        }\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            G = new int[n][n];\n            G1 = new int[n][n];\n            int[][] ar = new int[n][m];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    ar[i][j] = in.scanInt();\n                }\n            }\n            if (n == 1) {\n                int ans = Integer.MAX_VALUE;\n                for (int i = 0; i < m - 1; i++) ans = Math.min(ans, Math.abs(ar[0][i] - ar[0][i + 1]));\n                out.println(ans);\n                return;\n            }\n            for (int i = 0; i < n; i++) {\n                for (int j = i + 1; j < n; j++) {\n                    int min = Integer.MAX_VALUE;\n                    for (int k = 0; k < m; k++) min = Math.min(min, Math.abs(ar[i][k] - ar[j][k]));\n                    G[i][j] = G[j][i] = min;\n                }\n            }\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < n; j++) {\n                    if (i == j) continue;\n                    int min = Integer.MAX_VALUE;\n                    for (int k = 1; k < m; k++) min = Math.min(min, Math.abs(ar[i][k] - ar[j][k - 1]));\n                    G1[i][j] = min;\n\n                }\n            }\n            int[] map;\n            int ans = 0;\n            for (int i = 0; i < n; i++) {\n                map = new int[n - 1];\n                int tl = 0;\n                for (int temp = 0; temp < n; temp++) {\n                    if (temp == i) continue;\n                    map[tl++] = temp;\n                }\n                ans = Math.max(ans, findIt(map, n - 1, i));\n\n            }\n            out.println(ans);\n\n\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.*;\npublic class F {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        int N = scanner.nextInt();\n        int M = scanner.nextInt();\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] = scanner.nextInt();\n            }\n        }\n        int[][] maxDist = new int[N][N];\n        for(int i = 0; i < N; i++) {\n            Arrays.fill(maxDist[i], Integer.MAX_VALUE);\n        }\n        for(int i = 0; i < M; i++) {\n            for(int  j = 0; j < N; j++) {\n                for(int k = j+1; k < N; k++) {\n                    maxDist[j][k] = Math.min(maxDist[j][k], Math.abs(matrix[k][i] - matrix[j][i]));\n                    maxDist[k][j] = maxDist[j][k];\n                }\n            }\n        }\n        int[][] distTop = new int[N][N];\n        for(int i = 0; i < N; i++) {\n            Arrays.fill(distTop[i], Integer.MAX_VALUE);\n        }\n        for(int i = 0; i < M-1; i++) {\n            for(int j = 0; j < N; j++) {\n                for(int k = 0; k < N; k++) {\n                    distTop[j][k] = Math.min(distTop[j][k], Math.abs(matrix[j][i] - matrix[k][i+1]));\n                }\n            }\n        }\n        if (N == 1) {\n            System.out.println(distTop[0][0]);\n            System.exit(0);\n        }\n        int[] bitLoc = new int[1<<N];\n        for(int i = 0; i < N; i++) {\n            bitLoc[1 << i] = i;\n        }\n        int[][][] dp = new int[1<<N][N][N];\n        //iterate over every row\n        for(int mask = 1; mask < (1 << N); mask++) {\n            for(int smask = mask; smask > 0; smask &= (smask-1)) {\n                int i = bitLoc[Integer.lowestOneBit(smask)];\n                for (int ss = mask ^ 1 << i; ss > 0; ss &= ss - 1) {\n                    int j = bitLoc[Integer.lowestOneBit(ss)];\n                    if (mask == (1 << i ^ 1 << j))\n                        dp[mask][i][j] = maxDist[i][j];\n                    else {\n                        int x = 0;\n                        for (int sss = mask ^ 1 << i ^ 1 << j; sss > 0; sss &= sss - 1) {\n                            int k = bitLoc[sss & -sss];\n                            x = Math.max(x, Math.min(dp[mask ^ 1 << j][i][k], maxDist[k][j]));\n                        }\n                        dp[mask][i][j] = x;\n                    }\n                }\n            }\n        }\n        int mxMsk = (1 << N) -1;\n        int max = 0;\n        for(int i = 0; i < N; i++) {\n            for(int j = 0; j < N; j++) {\n                if (i==j) continue;\n                max = Math.max(max, Math.min(dp[mxMsk][i][j], distTop[i][j]));\n            }\n        }\n        System.out.println(max);\n    }\n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        public FastScanner() {\n            this(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        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 readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\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", "complexity": "np", "problem": "1102_F. Elongated Matrix", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E\n{\n\tprivate static final int oo = 1000000000;\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tif(n > m)\n\t\t{\n\t\t\tint t = n;\n\t\t\tn = m;\n\t\t\tm = t;\n\t\t}\n\n\t\tint [][] curr = new int[1<<n][1<<n];\n\t\tfill(curr, oo);\n\t\tArrays.fill(curr[0], 0);\n\n\t\tfor(int j = 0 ; j < m ; j++)\n\t\t{\n\t\t\tint [][] next = new int[1<<n][1<<n];\n\t\t\tfill(next, oo);\n\t\t\tfor(int c0 = 0 ; c0 < 1<<n ; c0++)\n\t\t\t\tfor(int c1 = 0 ; c1 < 1<<n ; c1++)\n\t\t\t\t\tif(curr[c0][c1] != oo)\n\t\t\t\t\t\tfor(int c2 = 0 ; c2 < (j == m-1 ? 1 : 1<<n) ; c2++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint done = 0;\n\t\t\t\t\t\t\tfor(int i = 0 ; i < n ; i++)\n\t\t\t\t\t\t\t\tif(((1<<i) & c1) == 0)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tint up = i-1;\n\t\t\t\t\t\t\t\t\tint down = i+1;\n\t\t\t\t\t\t\t\t\tif(up >= 0 && ((1<<up) & c1) != 0)\n\t\t\t\t\t\t\t\t\t\tdone |= 1<<i;\n\t\t\t\t\t\t\t\t\tif(down < n && ((1<<down) & c1) != 0)\n\t\t\t\t\t\t\t\t\t\tdone |= 1<<i;\n\t\t\t\t\t\t\t\t\tif(((1<<i) & c0) != 0)\n\t\t\t\t\t\t\t\t\t\tdone |= 1<<i;\n\t\t\t\t\t\t\t\t\tif(((1<<i) & c2) != 0)\n\t\t\t\t\t\t\t\t\t\tdone |= 1<<i;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tnext[c1][c2] = Math.min(next[c1][c2], curr[c0][c1] + n - Integer.bitCount(done));\n\n\t\t\t\t\t\t}\n\t\t\tcurr = next;\n\t\t}\n\n\t\tint res = oo;\n\t\tfor(int i = 0 ; i < 1<<n ; i++)\n\t\t\tfor(int j = 0 ; j < 1<<n ; j++)\n\t\t\t\tres = Math.min(res, curr[i][j]);\n\n\t\tSystem.out.println(n*m - res);\n\t}\n\n\tprivate static void fill(int[][] array, int val)\n\t{\n\t\tfor(int [] fill : array)\n\t\t\tArrays.fill(fill, val);\n\t}\n}", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.*;\n\npublic class cf112e {\n\tstatic int n,m,s;\n\tstatic int[][][] memo;\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tif(n > m) {\n\t\t\tint tmp = n;\n\t\t\tn = m;\n\t\t\tm = tmp;\n\t\t}\n\t\ts = (1<<n);\n\t\tmemo = new int[s][s][m];\n\t\tfor(int i=0; i<s; i++)\n\t\t\tfor(int j=0; j<s; j++)\n\t\t\t\tArrays.fill(memo[i][j], -1);\n\t\tint ret = go(0,0,0);\n\t\tSystem.out.println(n*m - ret);\n\t}\n\tstatic int go(int last, int trans, int r) {\n\t\tif(r==m) {\n\t\t\tif(trans == 0) return 0;\n\t\t\treturn 100;\n\t\t}\n\t\tif(memo[last][trans][r] != -1) return memo[last][trans][r];\n\t\tint best = 100;\n\t\tfor(int crnt = 0; crnt < s; crnt++) {\n\t\t\tif((trans & ~crnt) != 0) continue; //certain ones have to be here\n\t\t\tfor(int pass = 0; pass < s; pass++) {\n\t\t\t\tint tmp = ((1<<n)-1) & ~last;\t//move back the ones you can\n\t\t\t\tif((pass & ~tmp) != 0) continue; //certain ones have to move on\n\t\t\t\ttmp = tmp & ~pass; //find which ones stay\n\t\t\t\tboolean fail = false;\n\t\t\t\tfor(int k=0; k<n; k++) //make sure that the ones that stay\n\t\t\t\t\tif(isSet(tmp,k) && !(isSet(crnt,k-1) || isSet(crnt,k) || isSet(crnt,k+1)))\n\t\t\t\t\t\tfail = true;\n\t\t\t\tif(fail) continue;\n\t\t\t\tbest = Math.min(best, Integer.bitCount(crnt) + go(crnt,pass,r+1));\n\t\t\t}\n\t\t}\n\t\treturn memo[last][trans][r] = best;\n\t}\n\tstatic boolean isSet(int x, int p) {\n\t\tif(p < 0 || p >= n) return false;\n\t\treturn (x & (1<<p)) != 0;\n\t}\n}\n", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/26/11\n * Time: 10:53 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskC {\n\n    final  int INF = 123456;\n    int[][][] memo;\n    int N, M;\n\n    int solve(int row, int prevFreeMask, int curStayMask) {\n        if(row == N) return (curStayMask == 0) ? 0 : -INF;\n        if(memo[row][prevFreeMask][curStayMask] != -1) return memo[row][prevFreeMask][curStayMask];\n\n        int res = 0;\n        for(int mask = 0; mask < (1<<M); mask++) {\n            if((mask & curStayMask) == curStayMask) {\n                int freeCellsMask = (1<<M) - 1 - mask;\n                int toMoveMask = freeCellsMask;\n\n                for(int i = 0; i < M; i++) {\n                    if((toMoveMask & (1<<i)) > 0) {\n                        if(i > 0) {\n                            if((mask & (1<<(i - 1))) > 0) {\n                                toMoveMask -= (1<<i);\n                                continue;\n                            }\n                        }\n\n                        if(i < M - 1) {\n                            if((mask & (1<<(i + 1))) > 0) {\n                                toMoveMask -= (1<<i);\n                                continue;\n                            }\n                        }\n                    }\n                }\n\n                if (row > 0) {\n                    for (int prevFillMask = toMoveMask; prevFillMask > 0; prevFillMask = (prevFillMask - 1) & toMoveMask) {\n                        int bc1 = Integer.bitCount(freeCellsMask);\n                        int bc2 = Integer.bitCount(prevFreeMask & prevFillMask);\n                        res = Math.max(res, bc1 - bc2 + solve(row + 1, freeCellsMask, toMoveMask ^ prevFillMask));\n                    }\n                }\n\n                res = Math.max(res, Integer.bitCount(freeCellsMask) + solve(row + 1, freeCellsMask, toMoveMask));\n            }\n        }\n\n        return memo[row][prevFreeMask][curStayMask] = res;\n    }\n\n    void run() {\n        N = nextInt();\n        M = nextInt();\n        if(M > N) {\n            int temp = M;\n            M = N;\n            N = temp;\n        }\n\n        this.memo = new int[N + 1][1<<M][1<<M];\n        for(int[][] g : memo) for(int[] f : g) Arrays.fill(f, -1);\n\n        System.out.println(solve(0, 0, 0));\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", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 9/3/11\n * Time: 5:28 PM\n */\npublic class CF85E {\n    public static void main(String[] args) {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n\n        int height = nextInt(), width = nextInt();\n        if (width > height) {\n            int t = width;\n            width = height;\n            height = t;\n        }\n\n        final int INF = height * width + 10;\n        int[][][] dp = new int[height + 1][1 << width][1 << width];\n        for (int[][] ints : dp) {\n            for (int[] anInt : ints) {\n                Arrays.fill(anInt, INF);\n            }\n        }\n\n        dp[0][0][0] = 0;\n        for(int r = 0; r < height; ++r) {\n            for(int uncovered = 0; uncovered < (1 << width); ++uncovered) {\n                for(int mask = 0; mask < (1 << width); ++mask) {\n                    if (dp[r][uncovered][mask] == INF) {\n                        continue;\n                    }\n                    for(int curMask = uncovered; curMask < (1 << width); curMask = (curMask + 1) | uncovered) {\n                        int curUncovered = (1 << width) - 1;\n                        for(int i = 0; i < width; ++i) {\n                            if (hasBit(mask, i) || hasBit(curMask, i)) {\n                                curUncovered &= ~(1 << i);\n                            }\n                            if (i > 0 && hasBit(curMask, i-1)) {\n                                curUncovered &= ~(1 << i);\n                            }\n                            if (i < width-1 && hasBit(curMask, i+1)) {\n                                curUncovered &= ~(1 << i);\n                            }\n                        }\n                        dp[r+1][curUncovered][curMask] = Math.min(dp[r+1][curUncovered][curMask], dp[r][uncovered][mask] + Integer.bitCount(curMask));\n                    }\n                }\n            }\n        }\n\n        int res = INF;\n        for(int x: dp[height][0]) res = Math.min(res, x);\n\n        System.out.println(height * width - res);\n    }\n\n    private static boolean hasBit(int mask, int bit) {\n        return (((mask >> bit) & 1) == 1);\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", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 9/3/11\n * Time: 5:28 PM\n */\npublic class CF85C {\n    public static void main(String[] args) {\n        reader = new BufferedReader(new InputStreamReader(System.in));\n\n        int height = nextInt(), width = nextInt();\n        if (width > height) {\n            int t = width;\n            width = height;\n            height = t;\n        }\n\n        final int INF = height * width + 10;\n        final int ALL_BITS = (1 << width)  - 1;\n        int[][][] dp = new int[height + 1][1 << width][1 << width];\n        for (int[][] ints : dp) {\n            for (int[] anInt : ints) {\n                Arrays.fill(anInt, INF);\n            }\n        }\n\n        dp[0][0][0] = 0;\n        for(int r = 0; r < height; ++r) {\n            for(int uncovered = 0; uncovered < (1 << width); ++uncovered) {\n                for(int mask = 0; mask < (1 << width); ++mask) {\n                    if (dp[r][uncovered][mask] == INF) {\n                        continue;\n                    }\n                    for(int curMask = uncovered; curMask < (1 << width); curMask = (curMask + 1) | uncovered) {\n                        int curCovered = (mask | curMask);\n                        curCovered |= (curMask >> 1);\n                        curCovered |= (ALL_BITS & (curMask << 1));\n\n                        int curUncovered = ALL_BITS ^ curCovered;\n                        dp[r+1][curUncovered][curMask] = Math.min(dp[r+1][curUncovered][curMask], dp[r][uncovered][mask] + Integer.bitCount(curMask));\n                    }\n                }\n            }\n        }\n\n        int res = INF;\n        for(int x: dp[height][0]) res = Math.min(res, x);\n\n        System.out.println(height * width - res);\n    }\n\n    private static boolean hasBit(int mask, int bit) {\n        return (((mask >> bit) & 1) == 1);\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", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n   public class x111C\n   {\n      public static void main(String omkar[]) throws Exception\n      {\n         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  \n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int R = Integer.parseInt(st.nextToken());\n         int C = Integer.parseInt(st.nextToken());\n         if(R > C)\n         {\n            int t = R;\n            R = C;\n            C = t;\n         }\n         //dp[c][m1][m2] = min spoders in first c columns\n         int[][][] dp = new int[C+1][1 << R][1 << R];\n         for(int i=0; i <= C; i++)\n            for(int mask=0; mask < (1<<R); mask++)\n               Arrays.fill(dp[i][mask], 69);\n         for(int mask=0; mask < (1<<R); mask++)\n            dp[0][0][mask] = 0;\n         for(int c=1; c <= C; c++)\n            for(int mask1=0; mask1 < (1<<R); mask1++)\n               for(int mask2=0; mask2 < (1<<R); mask2++)\n                  for(int mask3=0; mask3 < (1<<R); mask3++)\n                  {\n                     boolean works = true;\n                     for(int b=0; b < R; b++)\n                        if((mask2&(1<<b)) == 0)\n                        {\n                           if(b > 0 && (mask2&(1<<(b-1))) > 0);\n                           else if(b+1 < R && (mask2&(1<<(b+1))) > 0);\n                           else if((mask1&(1<<b)) > 0);\n                           else if((mask3&(1<<b)) > 0);\n                           else  works = false;\n                        }\n                     if(works)\n                        dp[c][mask2][mask3] = Math.min(dp[c][mask2][mask3], dp[c-1][mask1][mask2]+Integer.bitCount(mask1));\n                  }\n         int res = 0;\n         for(int mask=0; mask < (1<<R); mask++)\n            res = Math.max(res, R*C-(dp[C][mask][0]+Integer.bitCount(mask)));\n         System.out.println(res);\n      }\n   }", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "\nimport java.util.*;\n\n\npublic class E\n{\n   public static void main(String[] args)\n   {\n      new E(new Scanner(System.in));\n   }\n\n   int N, M;\n   int[][][] memo;\n\n   int go(int i, int j, int mask)\n   {\n      if (i == N)\n         return go(0, j+1, mask);\n      if (j == M)\n      {\n         int mm = mask%(1<<N);\n         //System.out.println(Integer.toBinaryString(mm)+\" \"+Integer.toBinaryString(mask));\n         if (mm != ((1<<N)-1))\n            return N*M;\n         return 0;\n      }\n\n      if (memo[i][j][mask] != -1)\n         return memo[i][j][mask];\n\n      // Now place a spider cluster here\n      int nMask = mask;\n      int prevMask = 0;\n      if (i > 0)\n         prevMask = 1 << (N-1);\n      int nextMask = 0;\n      if (i < (N-1))\n         nextMask = 1 << (N+1);\n      int curMask = 1 << N;\n      int nextRowMask = 1 << (N+N);\n      nMask = nMask|prevMask|nextMask|curMask|nextRowMask;\n      nMask = nMask/2;\n      int res = 1+go(i+1, j, nMask);\n      \n      int pr = mask%2;\n      if (pr == 1)\n      {\n         // We have the option to skip here\n         int rr = go(i+1, j, mask/2);\n         if (rr < res)\n            res = rr;\n      }\n\n   \n      //System.out.printf(\"%d %d %s = %d%n\", i, j, Integer.toBinaryString(mask), res);\n      memo[i][j][mask] = res;\n      return res;\n   }\n\n   public E(Scanner in)\n   {\n      int[] vals = new int[2];\n      vals[0] = in.nextInt();\n      vals[1] = in.nextInt();\n      Arrays.sort(vals);\n\n      N = vals[0];\n      M = vals[1];\n      memo = new int[N][M][1<<(N+N+1)];\n      fill3(memo, -1);\n      \n      int r1 = go(0, 0, (1<<N)-1);\n      int res = N*M-r1;\n      System.out.printf(\"%d%n\", res);\n   \n   }\n\n   void fill3(int[][][] vvv, int val)\n   {\n      for (int[][] vv : vvv)\n         for (int[] v : vv)\n            Arrays.fill(v, val);\n   }\n}\n", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E\n{\n    private static final int oo = 1000000000;\n    public static void main(String[] args) throws Exception\n    {\n        Scanner in = new Scanner(System.in);\n        int n = in.nextInt();\n        int m = in.nextInt();\n        if(n > m)\n        {\n            int t = n;\n            n = m;\n            m = t;\n        }\n\n        int [][] curr = new int[1<<n][1<<n];\n        fill(curr, oo);\n        Arrays.fill(curr[0], 0);\n\n        for(int j = 0 ; j < m ; j++)\n        {\n            int [][] next = new int[1<<n][1<<n];\n            fill(next, oo);\n            for(int c0 = 0 ; c0 < 1<<n ; c0++)\n                for(int c1 = 0 ; c1 < 1<<n ; c1++)\n                    if(curr[c0][c1] != oo)\n                        for(int c2 = 0 ; c2 < (j == m-1 ? 1 : 1<<n) ; c2++)\n                        {\n                            int all = (1<<n) - 1;\n                            int done = (all&(c1>>1)) | (all&(c1<<1)) | c0 | c2;\n                            done &= (all^c1);\n\n                            next[c1][c2] = Math.min(next[c1][c2], curr[c0][c1] + n - Integer.bitCount(done));\n\n                        }\n            curr = next;\n        }\n\n        int res = oo;\n        for(int i = 0 ; i < 1<<n ; i++)\n            for(int j = 0 ; j < 1<<n ; j++)\n                res = Math.min(res, curr[i][j]);\n\n        System.out.println(n*m - res);\n    }\n\n    private static void fill(int[][] array, int val)\n    {\n        for(int [] fill : array)\n            Arrays.fill(fill, val);\n    }\n}", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "/*(c) gorlum0 [at] gmail.com*/\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class E\n{\n    int bitcount(int x) {\n        int c = 0;\n        for ( ; x != 0; c++)\n            x &= x-1;\n        return c;\n    }\n\n    boolean bit(int x, int i)\n    {\n        if (i < 0) return false;\n        return (x>>i & 1) == 1 ? true : false;\n    }\n\n    int solve(int n, int m)\n    {\n        if (m > n) { int x = m; m = n; n = x; }\n        int maxmask = 1<<m;\n\n        int[][][] dp = new int[n+1][maxmask][maxmask];\n        for (int i = 0; i <= n; i++)\n            for (int j = 0; j < maxmask; j++)\n                for (int k = 0; k < maxmask; k++)\n                    dp[i][j][k] = inf;\n        for (int i = 0; i < maxmask; i++)\n            dp[0][0][i] = bitcount(i);\n\n        for (int i = 1; i <= n; i++)\n            for (int b = 0; b < maxmask; b++)\n                for (int c = 0; c < maxmask; c++)\n                    for (int a = 0; a < maxmask; a++) {\n                        boolean nospider = false;\n                        for (int j = 0; j < m; j++)\n                            if (not(bit(a,j) || bit(c,j) || bit(b,j-1) || bit(b,j) || bit(b,j+1))) {\n                                nospider = true;\n                                break;\n                            }\n                        if (nospider) continue;\n\n                        dp[i][b][c] = Math.min(dp[i][b][c], dp[i-1][a][b] + bitcount(c));\n                    }\n        int res = inf;\n        for (int b = 0; b < maxmask; b++)\n            res = Math.min(res, dp[n][b][0]);\n        return n*m - res;\n    }\n\n    void main() throws IOException {\n        int n;\n        while ((n = nextInt()) != EOF) {\n            int m = nextInt();\n            out.println(solve(n, m));\n        }\n    }\n\n    public static void main(String[] args) {\n        new E().run();\n    }\n\n    // ======================================================================\n\n    int inf = (int) 1e9;\n    final int EOF = -1;\n\n    boolean not(boolean p) { return !p; }\n\n    int sqr(int x) { return x*x; }\n    long sqr(long x) { return x*x; }\n    double sqr(double x) { return x*x; }\n\n    BufferedReader fin;\n    StringTokenizer st;\n    PrintWriter out;\n\n    public void run() {\n        try {\n            fin = new BufferedReader(new InputStreamReader(System.in));\n            st = null;\n            out = new PrintWriter(System.out);\n            main();\n            fin.close();\n            out.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 (st == null || !st.hasMoreTokens()) {\n            String line = fin.readLine();\n            if (line == null) return \"-1\";\n            else st = new StringTokenizer(line);\n        }\n        return st.nextToken();\n    }\n}\n", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Code implements Runnable {\n\n    public static void main(String[] args) throws IOException {\n        new Thread(new Code()).start();\n    }\n\n    private void solve() throws IOException {\n        int n = nextInt(), m = nextInt();\n        if(n > m) {\n            n ^= m;\n            m ^= n;\n            n ^= m;\n        }\n\n        int[][][] dp = new int[41][64][64];\n        for(int i = 0; i < 41; ++i)\n            for(int j = 0; j < 64; ++j)\n                for(int k = 0; k < 64; ++k) dp[i][j][k] = Integer.MAX_VALUE / 2;\n\n        for(int i = 0; i < 64; ++i) dp[0][0][i] = countBit(i);\n\n        for(int i = 1; i <= m; ++i) {\n            for(int cur = 0; cur < 64; ++cur) {\n                for(int next = 0; next < 64; ++next) {\n                    for(int prev = 0; prev < 64; ++prev) {\n                        if(!isBad(prev, cur, next, n)) {\n                            dp[i][cur][next] = min(dp[i][cur][next], dp[i - 1][prev][cur] + countBit(next));\n                        }\n                    }\n                }\n            }\n        }\n\n        int ans = Integer.MAX_VALUE;\n        for(int i = 0; i < 64; ++i) ans = min(ans, dp[m][i][0]);\n\n        writer.println(n * m - ans);\n    }\n\n    private boolean isBit(int bits, int pos) {\n        return pos < 0 ? false : ((bits & (1 << pos)) != 0);\n    }\n\n    private boolean isBad(int prev, int cur, int next, int count) {\n        for(int i = 0; i < count; ++i)\n            if(!(isBit(cur, i - 1) || isBit(cur, i) || isBit(cur, i + 1) || isBit(prev, i) || isBit(next, i)))  return true;\n        return false;\n    }\n\n    private int countBit(int bits) {\n        int ans = 0;\n        for(int i = 0; i < 6; ++i)  ans += (bits & (1 << i)) > 0 ? 1 : 0;\n        return ans;\n    }\n\n    private class Pair<E extends Comparable, V extends Comparable> implements Comparable<Pair<E, V>> {\n        public Pair(E first, V second) {\n            this.first = first;\n            this.second = second;\n        }\n\n        @Override\n        public int compareTo(Pair<E, V> obj) {\n            if(first == obj.first)  return second.compareTo(obj.second);\n            return first.compareTo(obj.first);\n        }\n\n        @Override\n        public boolean equals(Object obj) {\n            Pair other = (Pair)obj;\n            return first.equals(other.first) && second.equals(other.second);\n        }\n\n        public E first;\n        public V second;\n    }\n\n    @Override\n    public void run() {\n        try {\n            if(in.equals(\"\"))   reader = new BufferedReader(new InputStreamReader(System.in));\n            else    reader = new BufferedReader(new FileReader(in));\n\n            if(out.equals(\"\"))  writer = new PrintWriter(new OutputStreamWriter(System.out));\n            else    writer = new PrintWriter(new FileWriter(out));\n            solve();\n        } catch(IOException e) {\n            e.printStackTrace();\n        } finally {\n            try {\n                reader.close();\n                writer.close();\n            } catch(IOException e) {\n                e.printStackTrace();\n            }\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 double nextDouble() throws IOException {\n        return Double.parseDouble(nextToken());\n    }\n\n    private float nextFloat() throws IOException {\n        return Float.parseFloat(nextToken());\n    }\n\n    private String nextToken() throws IOException {\n        while(st == null || !st.hasMoreTokens())    st = new StringTokenizer(reader.readLine());\n        return st.nextToken();\n    }\n\n    private String in = \"\", out = \"\";\n    private BufferedReader reader;\n    private PrintWriter writer;\n    private StringTokenizer st;\n}", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "\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", "complexity": "np", "problem": "112_E. Petya and Spiders", "from": "CODEFORCES"}
{"src": "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.util.Random;\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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\n        int testCount = in.scanInt();\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class E2RotateColumnsHardVersion {\n        int[][] dp;\n        int[] cur;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            int[][] ar = new int[n][m];\n            int[][] max = new int[m][2];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    ar[i][j] = in.scanInt();\n            for (int i = 0; i < m; i++) {\n                for (int j = 0; j < n; j++) max[i][0] = Math.max(max[i][0], ar[j][i]);\n                max[i][1] = i;\n            }\n            CodeHash.shuffle(max);\n            Arrays.sort(max, (o1, o2) -> -o1[0] + o2[0]);\n            dp = new int[2][1 << n];\n            cur = new int[1 << n];\n            for (int i = 0; i < Math.min(m, n); i++) {\n                Arrays.fill(dp[i & 1], 0);\n                for (int k = 0; k < n; k++) {\n                    System.arraycopy(dp[(i - 1) & 1], 0, cur, 0, 1 << n);\n                    for (int l = 0; l < n; l++) {\n                        for (int j = 0; j < 1 << n; j++) {\n                            if ((j & (1 << l)) == 0) {\n                                cur[j ^ (1 << l)] = Math.max(cur[j ^ (1 << l)], cur[j] + ar[(k + l) % n][max[i][1]]);\n                            }\n                        }\n                    }\n                    for (int j = 0; j < 1 << n; j++) dp[i & 1][j] = Math.max(dp[i & 1][j], cur[j]);\n                }\n            }\n            out.println(dp[Math.min(n, m) & 1 ^ 1][(1 << n) - 1]);\n        }\n\n    }\n\n    static class CodeHash {\n        public static void shuffle(int[][] ar) {\n            Random rd = new Random(new Random().nextInt());\n            for (int i = 0; i < ar.length; i++) {\n                int index = rd.nextInt(ar.length);\n                int[] temp = ar[i];\n                ar[i] = ar[index];\n                ar[index] = temp;\n            }\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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        TaskE2 solver = new TaskE2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE2 {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int numTests = in.nextInt();\n            for (int test = 0; test < numTests; test++) {\n                int n = in.nextInt();\n                int 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                    }\n                }\n\n                int[] maxInColumn = new int[m];\n                for (int j = 0; j < m; j++) {\n                    for (int i = 0; i < n; i++) {\n                        maxInColumn[j] = Math.max(maxInColumn[j], a[i][j]);\n                    }\n                }\n                Integer[] cols = new Integer[m];\n                for (int i = 0; i < m; i++) {\n                    cols[i] = i;\n                }\n                Arrays.sort(cols, (u, v) -> -(maxInColumn[u] - maxInColumn[v]));\n                if (m > n) {\n                    int[][] na = new int[n][n];\n                    for (int i = 0; i < n; i++) {\n                        for (int j = 0; j < n; j++) {\n                            na[i][j] = a[i][cols[j]];\n                        }\n                    }\n                    m = n;\n                    a = na;\n                }\n\n                int[] buf = new int[n];\n                int[][] sums = new int[m][1 << n];\n                int[] sumsCur = new int[1 << n];\n                for (int j = 0; j < m; j++) {\n                    for (int shift = 0; shift < n; shift++) {\n                        for (int i = 0; i < n; i++) {\n                            buf[i] = a[(i + shift) % n][j];\n                        }\n                        for (int mask = 0; mask < 1 << n; mask++) {\n                            if (mask > 0) {\n                                int k = Integer.numberOfTrailingZeros(mask);\n                                sumsCur[mask] = sumsCur[mask ^ (1 << k)] + buf[k];\n                                sums[j][mask] = Math.max(sums[j][mask], sumsCur[mask]);\n                            }\n                        }\n                    }\n                }\n\n                int[] d = new int[1 << n];\n                int[] nd = new int[1 << n];\n                for (int j = 0; j < m; j++) {\n                    System.arraycopy(d, 0, nd, 0, d.length);\n                    for (int mask = 0; mask < 1 << n; mask++) {\n                        for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {\n                            nd[mask] = Math.max(nd[mask], d[mask ^ submask] + sums[j][submask]);\n                        }\n                    }\n                    int[] t = d;\n                    d = nd;\n                    nd = t;\n                }\n                int ans = 0;\n                for (int x : d) {\n                    ans = Math.max(ans, x);\n                }\n                out.println(ans);\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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskE2 solver = new TaskE2();\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 TaskE2 {\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            TaskE2.Column[] columns = new TaskE2.Column[m];\n            for (int i = 0; i < m; ++i) columns[i] = new TaskE2.Column(new int[n]);\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    columns[j].vals[i] = in.nextInt();\n                }\n            }\n            for (int i = 0; i < m; ++i) columns[i].initMax();\n            Arrays.sort(columns, new Comparator<TaskE2.Column>() {\n\n                public int compare(TaskE2.Column o1, TaskE2.Column o2) {\n                    return o2.max - o1.max;\n                }\n            });\n            if (columns.length > n) {\n                columns = Arrays.copyOf(columns, n);\n            }\n            out.println(solveOne(columns));\n        }\n\n        private int solveOne(TaskE2.Column[] columns) {\n            int n = columns[0].vals.length;\n            int[] best = new int[1 << n];\n            int[] next = new int[1 << n];\n            int[] tmp = new int[1 << n];\n            for (TaskE2.Column c : columns) {\n                System.arraycopy(best, 0, next, 0, best.length);\n                for (int rot = 0; rot < n; ++rot) {\n                    System.arraycopy(best, 0, tmp, 0, best.length);\n                    for (int i = 0, pos = rot; i < n; ++i, ++pos) {\n                        if (pos >= n) pos = 0;\n                        int val = c.vals[pos];\n                        for (int j = 0; j < tmp.length; ++j)\n                            if ((j & (1 << i)) == 0) {\n                                tmp[j ^ (1 << i)] = Math.max(tmp[j ^ (1 << i)], tmp[j] + val);\n                            }\n                    }\n                    for (int j = 0; j < tmp.length; ++j) {\n                        next[j] = Math.max(next[j], tmp[j]);\n                    }\n                }\n                int[] aa = best;\n                best = next;\n                next = aa;\n            }\n            return best[best.length - 1];\n        }\n\n        static class Column {\n            int[] vals;\n            int max;\n\n            public Column(int[] vals) {\n                this.vals = vals;\n            }\n\n            void initMax() {\n                max = 0;\n                for (int x : vals) max = Math.max(max, x);\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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.util.Comparator;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastScanner in = new FastScanner(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskE2 solver = new TaskE2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE2 {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int t = in.nextInt();\n            while (t-- > 0) {\n                int n = in.nextInt(), 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                    }\n                }\n                boolean[][] interesting = new boolean[n][m];\n                boolean[] hasInteresting = new boolean[m];\n                for (int i = 0; i < n; i++) {\n                    List<Pair> list = new ArrayList<>();\n                    for (int j = 0; j < m; j++) {\n                        list.add(new Pair(a[i][j], j));\n                    }\n                    Collections.sort(list, Comparator.comparing(pair -> -pair.val));\n                    for (int j = 0; j < m && j <= n; j++) {\n                        interesting[i][list.get(j).pos] = true;\n                        hasInteresting[list.get(j).pos] = true;\n                    }\n                }\n                boolean[] goodMask = new boolean[1 << n];\n                for (int mask = 0; mask < 1 << n; mask++) {\n                    int best = Integer.MAX_VALUE;\n                    int cur = mask;\n                    do {\n                        best = Math.min(best, cur);\n                        cur = (cur >> 1) | ((cur & 1) << (n - 1));\n                    } while (cur != mask);\n                    goodMask[mask] = (mask == best);\n                }\n                int[] dp = new int[1 << n];\n                for (int i = 0; i < m; i++) {\n                    if (!hasInteresting[i]) {\n                        continue;\n                    }\n                    for (int j = 0; j < n; j++) {\n                        if (!interesting[j][i]) {\n                            continue;\n                        }\n                        int supermask = (1 << n) - 1 - (1 << j);\n                        int val = a[j][i];\n                        for (int mask = supermask; ; mask = (mask - 1) & supermask) {\n                            if (dp[mask] + val > dp[mask | (1 << j)]) {\n                                dp[mask | (1 << j)] = dp[mask] + val;\n                            }\n                            if (mask == 0) {\n                                break;\n                            }\n                        }\n                    }\n                    for (int mask = 0; mask < 1 << n; mask++) {\n                        if (!goodMask[mask]) {\n                            continue;\n                        }\n                        int best = 0;\n                        int cur = mask;\n                        do {\n                            best = Math.max(best, dp[cur]);\n                            cur = (cur >> 1) | ((cur & 1) << (n - 1));\n                        } while (cur != mask);\n                        do {\n                            dp[cur] = best;\n                            cur = (cur >> 1) | ((cur & 1) << (n - 1));\n                        } while (cur != mask);\n                    }\n                }\n                out.println(dp[(1 << n) - 1]);\n            }\n        }\n\n        class Pair {\n            int val;\n            int pos;\n\n            public Pair(int val, int pos) {\n                this.val = val;\n                this.pos = pos;\n            }\n\n        }\n\n    }\n\n    static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n\n        public FastScanner(InputStream in) {\n            br = new BufferedReader(new InputStreamReader(in));\n        }\n\n        public 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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n    FastScanner in;\n    PrintWriter out;\n\n    void solve() {\n        int tc = in.nextInt();\n        for (int t = 0; t < tc; t++) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            O[] a = new O[n * m];\n            int[][] cols = new int[m][n + n];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    cols[j][i] = cols[j][i + n] = in.nextInt();\n                    a[i * m + j] = new O(i, j, cols[j][i]);\n                }\n            }\n            Arrays.sort(a);\n            boolean[] used = new boolean[m];\n            int cntUsed = 0;\n            for (O o : a) {\n                if (!used[o.y]) {\n                    used[o.y] = true;\n                    cntUsed++;\n                    if (cntUsed == n) {\n                        break;\n                    }\n                }\n            }\n            int[] dp = new int[1 << n];\n            int[] ndp = new int[1 << n];\n            int[] maxndp = new int[1 << n];\n            for (int col = 0; col < m; col++) {\n                if (!used[col]) {\n                    continue;\n                }\n                int[] curColumn = cols[col];\n                for (int shift = 0; shift < n; shift++) {\n                    System.arraycopy(dp, 0, ndp, 0, ndp.length);\n                    for (int mask = 0; mask < 1 << n; mask++) {\n                        for (int bit = 0; bit < n; bit++) {\n                            if (((1 << bit) & mask) == 0) {\n                                int nmask = mask | (1 << bit);\n                                ndp[nmask] = Math.max(ndp[nmask], ndp[mask] + curColumn[bit + shift]);\n                            }\n                        }\n                    }\n                    for (int i = 0; i < ndp.length; i++) {\n                        maxndp[i] = Math.max(maxndp[i], ndp[i]);\n                    }\n                }\n                int[] tmp = dp;\n                dp = maxndp;\n                maxndp = tmp;\n            }\n            out.println(dp[dp.length - 1]);\n        }\n    }\n\n    class O implements Comparable<O> {\n        int x, y, value;\n\n        public O(int x, int y, int value) {\n            this.x = x;\n            this.y = y;\n            this.value = value;\n        }\n\n        @Override\n        public int compareTo(O o) {\n            return -Integer.compare(value, o.value);\n        }\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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.Arrays;\n\npublic class CF1209E2 {\n    public static void main(String[] args) throws Exception {\n        boolean local = System.getSecurityManager() == 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            int t = io.readInt();\n            while (t-- > 0)\n                solve();\n        }\n\n        int[][] prefix = new int[12][1 << 12];\n        int[][] profits = new int[12][1 << 12];\n        Col[] cols = new Col[2000];\n\n        {\n            for (int i = 0; i < 2000; i++) {\n                cols[i] = new Col(12);\n            }\n        }\n\n        public void solve() {\n            int n = io.readInt();\n            int m = io.readInt();\n\n            for (int i = 0; i < m; i++) {\n                cols[i].max = 0;\n                cols[i].n = n;\n            }\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    cols[j].data[i] = io.readInt();\n                    cols[j].max = Math.max(cols[j].max, cols[j].data[i]);\n                }\n            }\n\n            Arrays.sort(cols, 0, m, (a, b) -> -(a.max - b.max));\n            Col[] cols = Arrays.copyOf(this.cols, Math.min(m, n));\n\n            int mask = (1 << n) - 1;\n            SubsetGenerator sg = new SubsetGenerator();\n            SubsetGenerator2 sg2 = new SubsetGenerator2();\n            BitOperator bo = new BitOperator();\n            for (int i = 0; i < cols.length; i++) {\n                Arrays.fill(profits[i], 0);\n                for (int j = 0; j < n; j++) {\n                    cols[i].rotate();\n                    for (int k = 0; k < n; k++) {\n                        sg2.values[k] = cols[i].data[k];\n                    }\n                    sg2.setSet(mask);\n                    while (sg2.hasNext()) {\n                        profits[i][sg2.next] = Math.max(profits[i][sg2.next], sg2.val);\n                        sg2.next();\n                    }\n                }\n            }\n\n            prefix[0] = profits[0];\n            for (int i = 1; i < cols.length; i++) {\n                for (int j = 0; j <= mask; j++) {\n                    sg.setSet(j);\n                    prefix[i][j] = prefix[i - 1][j];\n                    while (sg.hasNext()) {\n                        int next = sg.next();\n                        prefix[i][j] = Math.max(prefix[i][j],\n                                profits[i][next] + prefix[i - 1][j ^ next]);\n                    }\n                }\n            }\n\n            io.cache.append(prefix[cols.length - 1][mask]).append('\\n');\n        }\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    public static class SubsetGenerator2 {\n        private int[] meanings = new int[33];\n        private int[] values = new int[33];\n        private int[] bits = new int[33];\n        private int remain;\n        private int next;\n        private int val;\n\n        public void setSet(int set) {\n            int bitCount = 0;\n            while (set != 0) {\n                meanings[bitCount] = set & -set;\n                bits[bitCount] = 0;\n                set -= meanings[bitCount];\n                bitCount++;\n            }\n            remain = 1 << bitCount;\n            next = 0;\n            val = 0;\n        }\n\n        public boolean hasNext() {\n            return remain > 0;\n        }\n\n        private void consume() {\n            remain = remain - 1;\n            int i;\n            for (i = 0; bits[i] == 1; i++) {\n                bits[i] = 0;\n                next -= meanings[i];\n                val -= values[i];\n            }\n            bits[i] = 1;\n            next += meanings[i];\n            val += values[i];\n        }\n\n        public int next() {\n            int returned = next;\n            consume();\n            return returned;\n        }\n    }\n\n    public static class SubsetGenerator {\n        private int[] meanings = new int[33];\n        private int[] bits = new int[33];\n        private int remain;\n        private int next;\n\n        public void setSet(int set) {\n            int bitCount = 0;\n            while (set != 0) {\n                meanings[bitCount] = set & -set;\n                bits[bitCount] = 0;\n                set -= meanings[bitCount];\n                bitCount++;\n            }\n            remain = 1 << bitCount;\n            next = 0;\n        }\n\n        public boolean hasNext() {\n            return remain > 0;\n        }\n\n        private void consume() {\n            remain = remain - 1;\n            int i;\n            for (i = 0; bits[i] == 1; i++) {\n                bits[i] = 0;\n                next -= meanings[i];\n            }\n            bits[i] = 1;\n            next += meanings[i];\n        }\n\n        public int next() {\n            int returned = next;\n            consume();\n            return returned;\n        }\n    }\n\n    public static class Col {\n        int[] data;\n        int max;\n        int n;\n\n        public void rotate() {\n            int end = data[n - 1];\n            System.arraycopy(data, 0, data, 1, n - 1);\n            data[0] = end;\n        }\n\n        public Col(int n) {\n            data = new int[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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class E {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int t = scanner.nextInt();\n        while(t-->0) {\n            int n = scanner.nextInt();\n            int m = scanner.nextInt();\n            Col[] cols = new Col[m];\n            int[][] mat = new int[m][n];\n            for(int i = 0; i < n; i++) {\n                for(int j =0; j < m; j++) {\n                    mat[j][i] = scanner.nextInt();\n                }\n            }\n            for(int i = 0; i < m; i++) {\n                cols[i] = new Col(mat[i]);\n            }\n            Arrays.sort(cols);\n            int maxMask = 1 << n;\n            int[] dp = new int[maxMask];\n            Arrays.fill(dp, -1);\n            dp[0] = 0;\n            int sz = Math.min(n, m);\n            int[][] ss = new int[sz][maxMask];\n            //2^n * n^3\n            for(int i = 0; i < sz; i++) {\n                int[] curArr = cols[i].arr.clone();\n                for(int j = 0; j < n; j++) {\n                    for(int mask = 0; mask < maxMask; mask++) {\n                        int cur = 0;\n                        for(int k = 0; k < n; k++) if ((( 1 << k) & mask) > 0) cur += curArr[k];\n                        ss[i][mask] = Math.max(ss[i][mask], cur);\n                    }\n                    curArr = shift(curArr);\n                }\n            }\n            for(int i = 0; i < Math.min(n, m); i++) {\n                for(int mask = maxMask-1; mask>=0; mask--) {\n                    for(int smask = mask; smask >= 0; smask = (smask-1)&mask) {\n                        if (dp[smask] == -1) continue;\n                        dp[mask] = Math.max(dp[mask], dp[smask] + ss[i][mask ^ smask]);\n                        if (smask == 0) break;\n                    }\n                }\n            }\n            out.println(dp[maxMask-1]);\n        }\n        out.flush();\n    }\n    static int[] shift (int[] a) {\n        int[] b = new int[a.length];\n        b[0] = a[a.length-1];\n        for(int i = 0; i < a.length-1; i++) {\n            b[i+1] = a[i];\n        }\n        return b;\n    }\n    static class Col implements Comparable<Col> {\n        int[] arr;\n        int[] sorted;\n        public Col(int[] a) {\n            arr = a;\n            sorted= arr.clone();\n            Arrays.sort(sorted);\n        }\n        public int compareTo(Col col) {\n            return -sorted[sorted.length-1] + col.sorted[sorted.length-1];\n        }\n    }\n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class E2\n{\n    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n    // BufferedReader in;\n    StringTokenizer tok;\n\n    public void go() throws IOException\n    {\n        // long start = System.nanoTime();\n        // in = new BufferedReader(new FileReader(new File(\"input.txt\")));\n        StringTokenizer tok = new StringTokenizer(in.readLine());\n        int zzz = Integer.parseInt(tok.nextToken());\n        for (int zz = 0; zz < zzz; zz++)\n        {\n            ntok();\n            int n = ipar();\n            int m = ipar();\n            int[][] mat = new int[m][n+1];\n            for (int i = 0; i < n; i++)\n            {\n                ntok();\n                for (int e = 0; e < m; e++)\n                {\n                    mat[e][i] = ipar();\n                }\n            }\n            for (int i = 0; i < m; i++)\n            {\n                for (int e = 0; e < n; e++)\n                {\n                    mat[i][n] = Math.max(mat[i][n], mat[i][e]);\n                }\n            }\n            ArrayList<int[]> list = new ArrayList<>();\n            for (int i = 0; i < m; i++)\n            {\n                list.add(mat[i]);\n            }\n            Collections.sort(list, (a, b) -> {\n                return -Integer.compare(a[n], b[n]);\n            });\n            for (int i = 0; i < m; i++)\n            {\n                mat[i] = list.get(i);\n            }\n            m = Math.min(m, n);\n\n            int[][] dp = new int[1 << n][m+1];\n            for (int i = m-1; i >= 0; i--)\n            {\n                int[] temp = new int[1 << n];\n                for (int r = 0; r < n; r++)\n                {\n                    for (int j = 0; j < 1 << n; j++)\n                    {\n                        temp[j] = dp[j][i+1];\n                    }\n                    for (int j = 0; j < n; j++)\n                    {\n                        int val = mat[i][(j+r)%n];\n                        for (int k = 0; k < 1 << n; k++)\n                        {\n                            if ((k & (1 << j)) == 0)\n                            {\n                                temp[k | (1 << j)] = Math.max(temp[k | (1 << j)], temp[k] + val);\n                            }\n                        }\n                    }\n                    for (int j = 0; j < 1 << n; j++)\n                    {\n                        dp[j][i] = Math.max(dp[j][i], temp[j]);\n                    }\n                }\n            }\n            out.println(dp[(1 << n) - 1][0]);\n\n            // int[][] best = new int[1 << n][m];\n            // for (int i = 0; i < 1 << n; i++)\n            // {\n            //     for (int e = 0; e < m; e++)\n            //     {\n            //         best[i][e] = best(i, mat, e);\n            //     }\n            // }\n            // int[][] dp = new int[1 << n][m+1];\n            // for (int i = 0; i < 1 << n; i++)\n            // {\n            //     dp[i][m] = -1000000000;\n            // }\n            // dp[(1 << n) - 1][m] = 0;\n            // for (int i = m-1; i >= 0; i--)\n            // {\n            //     for (int e = 0; e < 1 << n; e++)\n            //     {\n            //         dp[e][i] = dp[e][i+1];\n            //         int opposite = ~e & ((1 << n) - 1);\n            //         for (int w = opposite; w != 0; w = (w-1) & opposite)\n            //         {\n            //             dp[e][i] = Math.max(dp[e][i], best[w][i] + dp[e|w][i+1]);\n            //         }\n            //     }\n            // }\n            // out.println(dp[0][0]);\n        }\n        // out.printf(\"%.3f%n\", (System.nanoTime() - start) / 1000000.0);\n\n        out.flush();\n        in.close();\n    }\n\n    public int best(int mask, int[][] mat, int col)\n    {\n        int max = 0;\n        for (int t = 0; t < mat[0].length-1; t++)\n        {\n            int sum = 0;\n            int mk = mask;\n            for (int i = 0; i < mat[0].length-1; i++)\n            {\n                if (mk % 2 == 1)\n                {\n                    sum += mat[col][(i+t)%(mat[0].length-1)];\n                }\n                mk /= 2;\n            }\n            max = Math.max(max, sum);\n        }\n        return max;\n    }\n\n    public void cycle(int[][] mat, int col)\n    {\n        int temp = mat[col][0];\n        for (int i = 0; i < mat[0].length-2; i++)\n        {\n            mat[col][i] = mat[col][i+1];\n        }\n        mat[col][mat[0].length-2] = temp;\n    }\n\n    public void ntok() throws IOException\n    {\n        tok = new StringTokenizer(in.readLine());\n    }\n\n    public int ipar()\n    {\n        return Integer.parseInt(tok.nextToken());\n    }\n\n    public int[] iapar(int n)\n    {\n        int[] arr = new int[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = ipar();\n        }\n        return arr;\n    }\n\n    public long lpar()\n    {\n        return Long.parseLong(tok.nextToken());\n    }\n\n    public long[] lapar(int n)\n    {\n        long[] arr = new long[n];\n        for (int i = 0; i < n; i++)\n        {\n            arr[i] = lpar();\n        }\n        return arr;\n    }\n\n    public double dpar()\n    {\n        return Double.parseDouble(tok.nextToken());\n    }\n\n    public String spar()\n    {\n        return tok.nextToken();\n    }\n\n    public static void main(String[] args) throws IOException\n    {\n        new E2().go();\n    }\n}\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Comparator;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author ilyakor\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    OutputWriter out = new OutputWriter(outputStream);\n    TaskE1 solver = new TaskE1();\n    int testCount = Integer.parseInt(in.next());\n    for (int i = 1; i <= testCount; i++) {\n      solver.solve(i, in, out);\n    }\n    out.close();\n  }\n\n  static class TaskE1 {\n\n    public void solve(int testNumber, InputReader in, OutputWriter out) {\n      int n = in.nextInt();\n      int m = in.nextInt();\n      // int n = 12;\n      // int m = 2000;\n      int[][] d = new int[2][1 << n];\n      int[] buf = new int[1 << n];\n      int[][] a = new int[m][n];\n      for (int i = 0; i < n; ++i) {\n        for (int j = 0; j < m; ++j) {\n          a[j][i] = in.nextInt();\n          // a[j][i] = (int)((i * 12346L + j * 789L) % 100000);\n        }\n      }\n\n      ArrayList<Integer> inds = new ArrayList<>();\n      for (int i = 0; i < m; ++i) {\n        inds.add(i);\n      }\n      int[][] finalA = a;\n      Collections.sort(inds, new Comparator<Integer>() {\n\n        public int compare(Integer i1, Integer i2) {\n          int val1 = 0, val2 = 0;\n          for (int i = 0; i < n; ++i) {\n            if (finalA[i1][i] > val1) {\n              val1 = finalA[i1][i];\n            }\n          }\n          for (int i = 0; i < n; ++i) {\n            if (finalA[i2][i] > val2) {\n              val2 = finalA[i2][i];\n            }\n          }\n          return -Integer.compare(val1, val2);\n        }\n      });\n      int newM = Math.min(m, n + 1);\n      int[][] na = new int[newM][];\n      for (int i = 0; i < newM; ++i) {\n        int ind = inds.get(i);\n        na[i] = a[ind];\n      }\n      m = newM;\n      a = na;\n\n      for (int i = 0; i < m; ++i) {\n        int[] prev = d[i % 2], nx = d[(i + 1) % 2];\n        for (int shift = 0; shift < n; ++shift) {\n          int[] b = new int[n];\n          for (int j = 0; j < n; ++j) {\n            b[j] = a[i][(j + shift) % n];\n          }\n          System.arraycopy(prev, 0, buf, 0, prev.length);\n          for (int j = 0; j < n; ++j) {\n            int inc = b[j];\n            for (int mask = 0; mask < (1 << n); ++mask) {\n              if ((mask >> j) % 2 == 0) {\n                int val = buf[mask] + inc;\n                int nm = mask ^ (1 << j);\n                if (val > buf[nm]) {\n                  buf[nm] = val;\n                }\n              }\n            }\n          }\n          for (int mask = 0; mask < (1 << n); ++mask) {\n            if (nx[mask] < buf[mask]) {\n              nx[mask] = buf[mask];\n            }\n          }\n        }\n      }\n      out.printLine(d[m % 2][(1 << n) - 1]);\n    }\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  }\n\n  static class InputReader {\n\n    private InputStream stream;\n    private byte[] buffer = new byte[10000];\n    private int cur;\n    private int count;\n\n    public InputReader(InputStream stream) {\n      this.stream = stream;\n    }\n\n    public static boolean isSpace(int c) {\n      return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n    }\n\n    public int read() {\n      if (count == -1) {\n        throw new InputMismatchException();\n      }\n      try {\n        if (cur >= count) {\n          cur = 0;\n          count = stream.read(buffer);\n          if (count <= 0) {\n            return -1;\n          }\n        }\n      } catch (IOException e) {\n        throw new InputMismatchException();\n      }\n      return buffer[cur++];\n    }\n\n    public int readSkipSpace() {\n      int c;\n      do {\n        c = read();\n      } while (isSpace(c));\n      return c;\n    }\n\n    public String nextToken() {\n      int c = readSkipSpace();\n      StringBuilder sb = new StringBuilder();\n      while (!isSpace(c)) {\n        sb.append((char) c);\n        c = read();\n      }\n      return sb.toString();\n    }\n\n    public String next() {\n      return nextToken();\n    }\n\n    public int nextInt() {\n      int sgn = 1;\n      int c = readSkipSpace();\n      if (c == '-') {\n        sgn = -1;\n        c = read();\n      }\n      int res = 0;\n      do {\n        if (c < '0' || c > '9') {\n          throw new InputMismatchException();\n        }\n        res = res * 10 + c - '0';\n        c = read();\n      } while (!isSpace(c));\n      res *= sgn;\n      return res;\n    }\n\n  }\n}\n\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "/*input\n3\n2 3\n2 5 7\n4 2 4\n3 6\n4 1 5 2 10 4\n8 6 6 4 9 10\n5 4 9 5 8 7\n3 3\n9 9 9\n1 1 1\n1 1 1\n\n*/\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.StringTokenizer;\nimport java.util.Random;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\nimport java.util.*;\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 T = in.nextInt();\n\t\tfor (int cT = 1; cT <= T; cT++) {\n\t\t\tTask solver = new Task();\n\t\t\tsolver.solve(cT, in, out);\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class data {\n\t\tint val, col;\n\t\tdata(int _val, int _col) {\n\t\t\tval = _val; col = _col;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"(%d,%d)\", val, col);\n\t\t}\n\t}\n\n\tstatic class Task {\n\t\tint[][] a;\n\t\tint[][] b;\n\t\tint[][] dp;\n\t\tint[][] mb;\n\n\t\tArrayList<data> all = new ArrayList<>();\n\t\tSet<Integer> st = new HashSet<>();\n\t\tint n, m;\n\n\t\tint cal(int col, int mask) {\n\t\t\tif (col == m) {\n\t\t\t\tif (Integer.bitCount(mask) == n) return 0;\n\t\t\t\treturn (int)(-1e9);\n\t\t\t}\n\t\t\tint ret = dp[col][mask];\n\t\t\tif (ret != -1) return ret;\n\t\t\tint rmask = mask ^ ((1 << n) - 1);\n\t\t\t// ret is not a reference\n\t\t\tfor (int mask2 = rmask; mask2 > 0; mask2 = rmask & (mask2 - 1)) {\n\t\t\t\tint now = cal(col + 1, mask | mask2) + mb[col][mask2];\n\t\t\t\tret = Math.max(ret, now);\n\t\t\t}\n\t\t\tret = Math.max(ret, cal(col + 1, mask));\n\t\t\tdp[col][mask] = ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic static int fsb(int n) {\n\t\t\treturn (int)((Math.log10(n & -n)) / Math.log10(2)) + 1;\n\t\t}\n\n\t\tvoid prepMb() {\n\t\t\t// col, cyclic, mask\n\t\t\tfor (int col = 0; col < m; col++) {\n\t\t\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\t\t\tint nmask = mask;\n\t\t\t\t\twhile ((nmask & 1) == 0) nmask >>= 1;\n\t\t\t\t\tif (nmask == mask) {\n\t\t\t\t\t\tfor (int shift = 0; shift < n; shift++) {\n\t\t\t\t\t\t\tint sum = 0;\n\t\t\t\t\t\t\tint tmask = mask;\n\t\t\t\t\t\t\twhile (tmask > 0) {\n\t\t\t\t\t\t\t\tint i = Integer.numberOfTrailingZeros(tmask);\n\t\t\t\t\t\t\t\tsum += b[(i + shift) % n][col]; tmask ^= (1 << i);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tmb[col][mask] = Math.max(mb[col][mask], sum);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmb[col][mask] = mb[col][nmask];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tn = in.nextInt(); m = in.nextInt();\n\t\t\ta = 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\ta[i][j] = in.nextInt();\n\t\t\t\t\tall.add(new data(a[i][j], j));\n\t\t\t\t}\n\t\t\t}\n\t\t\tCollections.sort(all, new Comparator<data>() {\n\t\t\t\t@Override\n\t\t\t\tpublic int compare(final data o1, final data o2) {\n\t\t\t\t\treturn -(o1.val - o2.val);\n\t\t\t\t}\n\t\t\t});\n\t\t\tfor (data it : all) {\n\t\t\t\tif (st.size() == n) break;\n\t\t\t\tst.add(it.col);\n\t\t\t}\n\t\t\tb = new int[n][st.size()];\n\t\t\tint rcol = 0;\n\t\t\tfor (int col : st) {\n\t\t\t\tfor (int row = 0; row < n; row++)\n\t\t\t\t\tb[row][rcol] = a[row][col];\n\t\t\t\trcol++;\n\t\t\t}\n\t\t\tm = st.size();\n\t\t\tdp = new int[n][(1 << n)];\n\t\t\tmb = new int[m][(1 << n)];\n\n\t\t\tprepMb();\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tArrays.fill(dp[i], -1);\n\t\t\tSystem.out.println(cal(0, 0));\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 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}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.util.Random;\nimport java.util.Comparator;\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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\n        int testCount = in.scanInt();\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class E2RotateColumnsHardVersion {\n        int[][] dp;\n        int[] cur;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            int[][] ar = new int[n][m];\n            int[][] max = new int[m][2];\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) ar[i][j] = in.scanInt();\n            }\n\n            for (int i = 0; i < m; i++) {\n                for (int j = 0; j < n; j++) {\n                    max[i][0] = Math.max(max[i][0], ar[j][i]);\n                }\n                max[i][1] = i;\n            }\n            CodeHash.shuffle(max);\n            Arrays.sort(max, new Comparator<int[]>() {\n\n                public int compare(int[] o1, int[] o2) {\n                    return -o1[0] + o2[0];\n                }\n            });\n            dp = new int[2][1 << n];\n            cur = new int[1 << n];\n            for (int i = 0; i < Math.min(m, n); i++) {\n                Arrays.fill(cur, 0);\n                Arrays.fill(dp[i & 1], 0);\n                for (int j = 0; j < 1 << n; j++) {\n                    for (int k = 0; k < n; k++) {\n                        int sum = 0;\n                        for (int l = 0; l < n; l++) {\n                            if ((j & (1 << l)) != 0) {\n                                sum += (ar[(k + l) % n][max[i][1]]);\n                            }\n                        }\n                        cur[j] = Math.max(cur[j], sum);\n                    }\n                }\n                for (int j = 0; j < (1 << n); j++) {\n                    for (int k = j; ; k = (k - 1) & j) {\n                        dp[i & 1][j] = Math.max(dp[i & 1][j], dp[(i - 1) & 1][k] + cur[j ^ k]);\n                        if (k == 0) break;\n                    }\n                }\n            }\n            out.println(dp[Math.min(n, m) & 1 ^ 1][(1 << n) - 1]);\n        }\n\n    }\n\n    static class CodeHash {\n        public static void shuffle(int[][] ar) {\n            Random rd = new Random(new Random().nextInt());\n            for (int i = 0; i < ar.length; i++) {\n                int index = rd.nextInt(ar.length);\n                int[] temp = ar[i];\n                ar[i] = ar[index];\n                ar[index] = temp;\n            }\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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\tint t=in.nextInt();\n\t\tfor(int i=0;i<t;i++) {\n\t\t\tout.println(work());\n\t\t}\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tint work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tint[][] A=new int[n][m];\n\t\tint[][] B=new int[n][m];\n\t\tint[][] R=new int[m][2];\n\t\tfor(int i=0;i<m;i++)R[i][1]=i;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tA[i][j]=in.nextInt();\n\t\t\t\tR[j][0]=Math.max(R[j][0], A[i][j]);\n\t\t\t}\n\t\t}\n\t\tArrays.sort(R,new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] arr1,int[] arr2) {\n\t\t\t\treturn arr2[0]-arr1[0];\n\t\t\t}\n\t\t});\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tint index=R[j][1];\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tB[i][j]=A[i][index];\n\t\t\t}\n\t\t}\n\t\tm=Math.min(n, m);\n\t\tint[][] dp=new int[m][1<<n];\n\t\tint[][] rec=new int[m][1<<n];\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tfor(int s=0;s<n;s++) {//\u8f6c\n\t\t\t\tfor(int i=1;i<1<<n;i++) {\n\t\t\t\t\tint sum=0;\n\t\t\t\t\tfor(int b=0;b<n;b++) {\n\t\t\t\t\t\tif(((1<<b)&i)>0) {\n\t\t\t\t\t\t\tsum+=B[(b+s)%n][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trec[j][i]=Math.max(sum, rec[j][i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tfor(int i=0;i<1<<n;i++) {\n\t\t\t\tif(j==0) {\n\t\t\t\t\tdp[j][i]=rec[j][i];\n\t\t\t\t}else {\n\t\t\t\t\tfor(int p=i;p<1<<n;p++) {\n\t\t\t\t\t\tp=p|i;\n\t\t\t\t\t\tdp[j][p]=Math.max(dp[j][p], rec[j][i]+dp[j-1][p^i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[m-1][(1<<n)-1];\n\t}\n}\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "/**\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 n,m,need,a[][],dp[][][],real[][];\n    static void solve() throws IOException\n    {\n        //initIo(true);\n        initIo(false);\n        StringBuilder sb = new StringBuilder();\n        int t = ni();\n        while(t-->0) {\n            n = ni();\n            m = ni();\n            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] = ni();\n                }\n            }\n            need = min(n,m);\n            Pair max_in_cols[] = new Pair[m];\n            for(int COL=0;COL<m;++COL) {\n                int max = 0;\n                for(int i=0;i<n;++i) {\n                    max = max(max, a[i][COL]);\n                }\n                max_in_cols[COL] = new Pair(max, COL);\n            }\n            real = new int[n][need];\n            Arrays.sort(max_in_cols);\n            for(int i=0;i<need;++i) {\n                int COL = max_in_cols[m-1-i].y;\n                for(int j=0;j<n;++j) {\n                    real[j][i] = a[j][COL];\n                }\n            }\n//            pl(\"need : \"+need);\n//            pa(\"Real\", real);\n            dp = new int[need][n+1][(1<<n)];\n            for(int i=0;i<need;++i) {\n                for(int j=0;j<=n;++j) {\n                    for(int k=0;k<(1<<n);++k) {\n                        dp[i][j][k] = -1;\n                    }\n                }\n            }\n            pl(f(0, n, 0));\n        }\n        pw.flush();\n        pw.close();\n    }\n    static int f(int idx, int bias, int mask) {\n        //pl(\"idx: \"+idx+\" bias : \"+bias + \" mask : \"+mask);\n        if(idx==need) {\n            return 0;\n        }\n        if(dp[idx][bias][mask]!=-1) {\n            return dp[idx][bias][mask];\n        }\n\n        //didn't fix bias yet\n        if(bias==n) {\n            int max = 0;\n            for(int b=0;b<n;++b) {\n                max = max(max, f(idx, b, mask));\n            }\n            //pl(\"maxxxxxxx : \"+max);\n            dp[idx][bias][mask] = max;\n            return max;\n        }\n        else {\n            int max = f(idx+1, n, mask);\n            for(int i=0;i<n;++i) {\n                if((mask&(1<<i))==0) {\n                    max = max(max, real[(i-bias+n)%n][idx] + f(idx, bias, mask | (1<<i)));\n                }\n            }\n            //pl(\"max : \"+max);\n            dp[idx][bias][mask] = max;\n            return max;\n        }\n    }\n    static class Pair implements Comparable<Pair>\n    {\n        int x,y;\n        Pair(int x,int y)\n        {\n            this.x=x;\n            this.y=y;\n        }\n        public int compareTo(Pair other)\n        {\n            if(this.x!=other.x)\n                return this.x-other.x;\n            return this.y-other.y;\n        }\n        public String toString()\n        {\n            return \"(\"+x+\",\"+y+\")\";\n        }\n    }\n    static void initIo(boolean isFileIO) throws IOException {\n        scan = new MyScanner(isFileIO);\n        if(isFileIO) {\n            pw = new PrintWriter(\"/Users/amandeep/Desktop/output.txt\");\n        }\n        else {\n            pw = new PrintWriter(System.out, true);\n        }\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static String ne() throws IOException\n    {\n        return scan.next();\n    }\n    static String nel() throws IOException\n    {\n        return scan.nextLine();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class MyScanner\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        MyScanner(boolean readingFromFile) throws IOException\n        {\n            if(readingFromFile) {\n                br = new BufferedReader(new FileReader(\"/Users/amandeep/Desktop/input.txt\"));\n            }\n            else {\n                br = new BufferedReader(new InputStreamReader(System.in));\n            }\n        }\n        String nextLine()throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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        TaskE2 solver = new TaskE2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE2 {\n        public void solve(int testNumber, FastScanner in, PrintWriter out) {\n            int numTests = in.nextInt();\n            for (int test = 0; test < numTests; test++) {\n                int n = in.nextInt();\n                int 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                    }\n                }\n\n                if (m > n) {\n                    int[] maxInColumn = new int[m];\n                    for (int j = 0; j < m; j++) {\n                        for (int i = 0; i < n; i++) {\n                            maxInColumn[j] = Math.max(maxInColumn[j], a[i][j]);\n                        }\n                    }\n                    Integer[] cols = new Integer[m];\n                    for (int i = 0; i < m; i++) {\n                        cols[i] = i;\n                    }\n                    Arrays.sort(cols, (u, v) -> -(maxInColumn[u] - maxInColumn[v]));\n\n                    int[][] na = new int[n][n];\n                    for (int i = 0; i < n; i++) {\n                        for (int j = 0; j < n; j++) {\n                            na[i][j] = a[i][cols[j]];\n                        }\n                    }\n                    m = n;\n                    a = na;\n                }\n\n                int[] buf = new int[n];\n                int[][] sums = new int[m][1 << n];\n                int[] sumsCur = new int[1 << n];\n                for (int j = 0; j < m; j++) {\n                    for (int shift = 0; shift < n; shift++) {\n                        for (int i = 0; i < n; i++) {\n                            buf[i] = a[(i + shift) % n][j];\n                        }\n                        for (int mask = 1; mask < 1 << n; mask++) {\n                            int k = Integer.numberOfTrailingZeros(mask);\n                            sumsCur[mask] = sumsCur[mask ^ (1 << k)] + buf[k];\n                            sums[j][mask] = Math.max(sums[j][mask], sumsCur[mask]);\n                        }\n                    }\n                }\n\n                int[] d = new int[1 << n];\n                for (int j = 0; j < m; j++) {\n                    for (int mask = (1 << n) - 1; mask >= 0; mask--) {\n                        for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {\n                            d[mask] = Math.max(d[mask], d[mask ^ submask] + sums[j][submask]);\n                        }\n                    }\n                }\n                int ans = 0;\n                for (int x : d) {\n                    ans = Math.max(ans, x);\n                }\n                out.println(ans);\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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\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    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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\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 E2RotateColumnsHardVersion {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            E2RotateColumnsHardVersion.Column[] columns = new E2RotateColumnsHardVersion.Column[m];\n            for (int i = 0; i < columns.length; ++i) columns[i] = new E2RotateColumnsHardVersion.Column(new int[n]);\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    columns[j].v[i] = in.nextInt();\n                    if (i == n - 1) columns[j].initMax();\n                }\n            }\n            Arrays.sort(columns, (o1, o2) -> o2.max - o1.max);\n            if (columns.length > n)\n                columns = Arrays.copyOf(columns, n);\n\n            long[] dp = new long[1 << n];\n            for (E2RotateColumnsHardVersion.Column c : columns) {\n                long[] ndp = new long[1 << n];\n                System.arraycopy(dp, 0, ndp, 0, dp.length);\n\n                for (int rot = 0; rot < n; ++rot) {\n                    long[] temp = new long[1 << n];\n                    System.arraycopy(dp, 0, temp, 0, dp.length);\n                    for (int i = 0, pos = rot; i < n; ++i, ++pos) {\n                        if (pos >= n) pos = 0;\n                        int val = c.v[pos];\n                        for (int j = 0; j < temp.length; ++j) {\n                            if ((j & (1 << i)) == 0)\n                                temp[j | (1 << i)] = Math.max(temp[j | (1 << i)], temp[j] + val);\n                        }\n                    }\n                    for (int i = 0; i < ndp.length; ++i)\n                        ndp[i] = Math.max(ndp[i], temp[i]);\n                }\n                dp = ndp;\n            }\n            out.println(dp[dp.length - 1]);\n        }\n\n        static class Column {\n            int[] v;\n            int max;\n\n            public Column(int[] v) {\n                this.v = v;\n            }\n\n            void initMax() {\n                max = 0;\n                for (int vv : v) max = Math.max(max, vv);\n            }\n\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public String next() {\n            return nextString();\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 String nextString() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = pread();\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\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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        E1RotateColumnsEasyVersion solver = new E1RotateColumnsEasyVersion();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class E1RotateColumnsEasyVersion {\n        int n;\n        int m;\n        int[][] arr;\n        int[][] mskValue;\n        int[][] memo;\n\n        public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n            int q = sc.nextInt();\n            while (q-- > 0) {\n                n = sc.nextInt();\n                m = sc.nextInt();\n                arr = new int[n][m];\n                for (int i = 0; i < n; i++)\n                    for (int j = 0; j < m; j++)\n                        arr[i][j] = sc.nextInt();\n                int[][] temp = new int[m][n];\n                for (int i = 0; i < m; i++)\n                    for (int j = 0; j < n; j++)\n                        temp[i][j] = arr[j][i];\n                Arrays.sort(temp, (a, b) -> getMax(b) - getMax(a));\n                for (int i = 0; i < m; i++)\n                    for (int j = 0; j < n; j++)\n                        arr[j][i] = temp[i][j];\n                mskValue = new int[n][1 << n];\n                for (int i = 0; i < Math.min(n, m); i++) {\n                    for (int j = 0; j < 1 << n; j++) {\n                        int max = 0;\n                        for (int shift = 0; shift < n; shift++) {\n                            int sum = 0;\n                            for (int k = 0; k < n; k++)\n                                if ((j & 1 << k) != 0)\n                                    sum += arr[(k + shift) % n][i];\n                            max = Math.max(max, sum);\n                        }\n                        mskValue[i][j] = max;\n                    }\n                }\n                memo = new int[Math.min(n, m)][1 << n];\n                for (int[] x : memo)\n                    Arrays.fill(x, -1);\n                pw.println(dp(0, 0));\n            }\n        }\n\n        private int getMax(int[] a) {\n            int max = 0;\n            for (int x : a)\n                max = Math.max(max, x);\n            return max;\n        }\n\n        private int dp(int idx, int msk) {\n            if (msk == (1 << n) - 1)\n                return 0;\n            if (idx == Math.min(n, m))\n                return (int) -1e9;\n            int max = Integer.MIN_VALUE;\n            if (memo[idx][msk] != -1)\n                return memo[idx][msk];\n            int availableBits = msk ^ ((1 << n) - 1);\n            for (int colMask = availableBits; colMask != 0; colMask = (colMask - 1) & availableBits) {\n\n                max = Math.max(max, mskValue[idx][colMask] + dp(idx + 1, msk | colMask));\n\n            }\n            return memo[idx][msk] = max;\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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "//stan hu tao\n//join nct ridin by first year culture reps\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.abs;\nimport static java.lang.System.out;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class x1209E\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        int T = Integer.parseInt(st.nextToken());\n        StringBuilder sb = new StringBuilder();\n        while(T-->0)\n        {\n            st = new StringTokenizer(infile.readLine());\n            int N = Integer.parseInt(st.nextToken());\n            int M = Integer.parseInt(st.nextToken());\n            int[][] grid = new int[N][M];\n            for(int r=0; r < N; r++)\n                grid[r] = readArr(M, infile, st);\n            ArrayList<Integer> ls = new ArrayList<Integer>();\n            for(int i=0; i < M; i++)\n                ls.add(i);\n            Collections.sort(ls, (x,y) -> {\n                int m1 = grid[0][x];\n                int m2 = grid[0][y];\n                for(int r=1; r < N; r++)\n                {\n                    m1 = max(m1, grid[r][x]);\n                    m2 = max(m2, grid[r][y]);\n                }\n                return m2-m1;\n            });\n            int[][] newgrid = new int[N][M];\n            for(int r=0; r < N; r++)\n                for(int c=0; c < M; c++)\n                    newgrid[r][c] = grid[r][ls.get(c)];\n            M = min(M, N);\n            int[][] sums = new int[M][1<<N];\n            for(int i=1; i < M; i++)\n                for(int mask=0; mask < 1<<N; mask++)\n                {\n                    //try all shifts\n                    for(int head=0; head < N; head++)\n                    {\n                        int temp = 0;\n                        for(int b=0; b < N; b++)\n                        {\n                            int nb = b+head;\n                            if(nb >= N)\n                                nb -= N;\n                            if((mask&(1<<nb)) > 0)\n                                temp += newgrid[b][i];\n                        }\n                        sums[i][mask] = max(sums[i][mask], temp);\n                    }\n                }\n            int[][] dp = new int[M][1<<N];\n            for(int mask=0; mask < 1<<N; mask++)\n                for(int b=0; b < N; b++)\n                    if((mask&(1<<b)) > 0)\n                        dp[0][mask] += newgrid[b][0];\n            for(int i=1; i < M; i++)\n                for(int mask=0; mask < 1<<N; mask++)\n                    for(int pmask=mask; pmask >= 0; pmask=(pmask-1)&mask)\n                    {\n                        dp[i][mask] = max(dp[i][mask], dp[i-1][pmask]+sums[i][mask-pmask]);\n                        if(pmask == 0)\n                            break;\n                    }\n            sb.append(dp[M-1][(1<<N)-1]+\"\\n\");\n        }\n        System.out.print(sb);\n    }\n    public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception\n    {\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        return arr;\n    }\n}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class E {\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n//\t\tint tests = 40;\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tint n = scanInt(), m = scanInt(), a[][] = new int[n][m];\n//\t\t\tint n = 12, m = 2000, a[][] = 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\ta[i][j] = scanInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\tint bestCols[] = new int[min(m, n)];\n\t\t\tfor (int i = 0; i < bestCols.length; i++) {\n\t\t\t\tbestCols[i] = i;\n\t\t\t}\n\t\t\tif (m > n) {\n\t\t\t\tint bestColMax[] = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint cmax = 0;\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tcmax = max(cmax, a[j][i]);\n\t\t\t\t\t}\n\t\t\t\t\tbestColMax[i] = cmax;\n\t\t\t\t}\n\t\t\t\tfor (int i = n; i < m; i++) {\n\t\t\t\t\tint cmax = 0;\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tcmax = max(cmax, a[j][i]);\n\t\t\t\t\t}\n\t\t\t\t\tint minBC = 0, minBCM = Integer.MAX_VALUE;\n\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\tif (bestColMax[j] < minBCM) {\n\t\t\t\t\t\t\tminBC = j;\n\t\t\t\t\t\t\tminBCM = bestColMax[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cmax > minBCM) {\n\t\t\t\t\t\tbestCols[minBC] = i;\n\t\t\t\t\t\tbestColMax[minBC] = cmax;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint dyn[] = new int[1 << n], dynNext[] = new int[1 << n], sums[] = new int[1 << n], csums[] = new int[1 << n];\n\t\t\tfor (int i: bestCols) {\n\t\t\t\tfill(dynNext, 0);\n\t\t\t\tfill(sums, 0);\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tfor (int k = 1, bit = 0; k < 1 << n; k++) {\n\t\t\t\t\t\tif (k == 1 << (bit + 1)) {\n\t\t\t\t\t\t\t++bit;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsums[k] = max(sums[k], csums[k] = csums[k ^ (1 << bit)] + a[(bit + j) % n][i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int mask1 = 0; mask1 < 1 << n; mask1++) {\n\t\t\t\t\tint cdyn = dynNext[mask1];\n\t\t\t\t\tfor (int mask2 = mask1;; mask2 = (mask2 - 1) & mask1) {\n\t\t\t\t\t\tcdyn = max(cdyn, dyn[mask2] + sums[mask1 ^ mask2]);\n\t\t\t\t\t\tif (mask2 == 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdynNext[mask1] = cdyn;\n\t\t\t\t}\n\t\t\t\tint t[] = dyn;\n\t\t\t\tdyn = dynNext;\n\t\t\t\tdynNext = t;\n\t\t\t}\n\t\t\tout.println(dyn[(1 << n) - 1]);\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}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "//package round584;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\n// imp:12m\npublic class E4 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni(); T> 0;T--){\n\t\t\tint n = ni(), m = ni();\n\t\t\tint[][] a = new int[n][];\n\t\t\tfor(int i = 0;i < n;i++)a[i] = na(m);\n\t\t\t\n\t\t\tlong[] mx = new long[m];\n\t\t\tfor(int i = 0;i < m;i++){\n\t\t\t\tint u = 0;\n\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\tu = Math.max(u, a[j][i]);\n\t\t\t\t}\n\t\t\t\tmx[i] = 1000000000L-u<<32|i;\n\t\t\t}\n\t\t\tArrays.sort(mx);\n\t\t\tint[] dp = new int[1<<n];\n\t\t\tfor(int i = 0;i < n && i < m;i++){\n\t\t\t\tint c = (int)mx[i];\n\t\t\t\tint[] ls = new int[1<<n];\n\t\t\t\tfor(int j = 1;j < 1<<n;j++){\n\t\t\t\t\tls[j] = ls[j&j-1] + a[Integer.numberOfTrailingZeros(j)][c];\n\t\t\t\t}\n\t\t\t\tfor(int j = 1;j < 1<<n;j++){\n\t\t\t\t\tint r = rot(j, n);\n\t\t\t\t\tls[r] = Math.max(ls[r], ls[j]);\n\t\t\t\t}\n\t\t\t\tint[] ndp = new int[1<<n];\n\t\t\t\tfor(int j = 0;j < 1<<n;j++){\n\t\t\t\t\tif(rot(j, n) == j){\n\t\t\t\t\t\tint cur = j;\n\t\t\t\t\t\tfor(int sh = 0;sh < n;sh++){\n\t\t\t\t\t\t\tcur = cur>>1|(cur&1)<<n-1;\n\t\t\t\t\t\t\tint mask = (1<<n)-1^cur;\n\t\t\t\t\t\t\tfor(int k = mask;k >= 0;k--){\n\t\t\t\t\t\t\t\tk &= mask;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tndp[k|cur] = Math.max(\n\t\t\t\t\t\t\t\t\t\tndp[k|cur], dp[k] + ls[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdp = ndp;\n\t\t\t}\n\t\t\tout.println(dp[(1<<n)-1]);\n\t\t}\n\t}\n\t\n\tint rot(int x, int n)\n\t{\n\t\tint ret = x;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tx = x>>>1|(x&1)<<n-1;\n\t\t\t\tret = Math.min(ret, x);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 12, m = 2000;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(40 + \" \");\n//\t\tfor(int rep = 0;rep < 40;rep++){\n//\t\t\tsb.append(n + \" \");\n//\t\t\tsb.append(m + \" \");\n//\t\t\tfor (int i = 0; i < n*m; i++) {\n//\t\t\t\tsb.append(gen.nextInt(100000) + \" \");\n//\t\t\t}\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 E4().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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main{\n\tstatic int[][]memo;\n\tstatic int n,m,in[][];\n\tstatic int dp(int col,int maxRowMask) {\n\t\tif(col>=Math.min(n, m) || maxRowMask==((1<<n)-1))return 0;\n\t\tif(memo[col][maxRowMask]!=-1)return memo[col][maxRowMask];\n\t\t\n\t\tint ans=0;\n\t\t\n\t\tint availableBits=maxRowMask^((1<<n)-1);\n\t\t//all masks that don't intersect with maxRowMask\n\t\tfor(int colMask=availableBits;colMask!=0;colMask=(colMask-1)&availableBits) {\n\t\t\t\n\t\t\tans=Math.max(ans, maxMask[col][colMask]+dp(col+1, maxRowMask|colMask));\n\t\t\t\n\t\t}\n\t\treturn memo[col][maxRowMask]=ans;\n\t}\n\tstatic int[][]sumOfMask;\n\tstatic int[][]maxMask;\n\tpublic static void main(String[] args) throws Exception{\n\t\tpw=new PrintWriter(System.out);\n\t\tsc = new MScanner(System.in);\n\t\tint tc=sc.nextInt();\n\t\twhile(tc-->0) {\n\t\t\tn=sc.nextInt();m=sc.nextInt();\n\t\t\t\n\t\t\tint[]maxInCol=new int[m];\n\t\t\tin=new int[m][n+1];\n\t\t\t\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\tin[j][i]=sc.nextInt();\n\t\t\t\t\tmaxInCol[j]=Math.max(maxInCol[j], in[j][i]);\n\t\t\t\t\tin[j][n]=j;\n\t\t\t\t}\n\t\t\t}\n\t\t\tArrays.sort(in,(x,y)->maxInCol[y[n]]-maxInCol[x[n]]);\n\t\t\t\n\t\t\t\n\t\t\tmemo=new int[n][1<<n];\n\t\t\tsumOfMask=new int[n][1<<n];\n\t\t\tmaxMask=new int[n][1<<n];\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tfor(int msk=0;msk<memo[i].length;msk++) {\n\t\t\t\t\tmemo[i][msk]=-1;\n\t\t\t\t\tif(i>=m)continue;\n\t\t\t\t\tfor(int bit=0;bit<n;bit++) {\n\t\t\t\t\t\tif(((msk>>bit)&1)!=0) {\n\t\t\t\t\t\t\tsumOfMask[i][msk]+=in[i][bit];\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 col=0;col<n;col++) {\n\t\t\t\tfor(int msk=0;msk<(1<<n);msk++) {\n\t\t\t\t\tint curMask=msk;\n\t\t\t\t\tfor(int cyclicShift=0;cyclicShift<n;cyclicShift++) {\n\t\t\t\t\t\tmaxMask[col][msk]=Math.max(maxMask[col][msk], sumOfMask[col][curMask]);\n\t\t\t\t\t\t\n\t\t\t\t\t\tint lastBit=curMask&1;\n\t\t\t\t\t\tcurMask>>=1;\n\t\t\t\t\t\tcurMask|=(lastBit<<(n-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\tpw.println(dp(0, 0));\n\t\t}\n\t\t\n\t\t\n\t\tpw.flush();\n\t}\n\tstatic PrintWriter pw;\n\tstatic MScanner  sc;\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n \n\t\tpublic MScanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n \n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int[] intArr(int n) throws IOException {\n\t        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t        return in;\n\t\t}\n\t\tpublic long[] longArr(int n) throws IOException {\n\t        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t        return in;\n\t\t}\n\t\tpublic int[] intSortedArr(int n) throws IOException {\n\t        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t        shuffle(in);\n\t        Arrays.sort(in);\n\t        return in;\n\t\t}\n\t\tpublic long[] longSortedArr(int n) throws IOException {\n\t        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t        shuffle(in);\n\t        Arrays.sort(in);\n\t        return in;\n\t\t}\n\t\tpublic Integer[] IntegerArr(int n) throws IOException {\n\t        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t        return in;\n\t\t}\n\t\tpublic Long[] LongArr(int n) throws IOException {\n\t        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t        return in;\n\t\t}\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n \n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n \n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n \n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n \n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n \n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n \n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\t}\n\tstatic void shuffle(int[]in) {\n\t\tfor(int i=0;i<in.length;i++) {\n\t\t\tint idx=(int)(Math.random()*in.length);\n\t\t\tint tmp=in[i];\n\t\t\tin[i]=in[idx];\n\t\t\tin[idx]=tmp;\n\t\t}\n\t}\n\tstatic void shuffle(long[]in) {\n\t\tfor(int i=0;i<in.length;i++) {\n\t\t\tint idx=(int)(Math.random()*in.length);\n\t\t\tlong tmp=in[i];\n\t\t\tin[i]=in[idx];\n\t\t\tin[idx]=tmp;\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\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 E2RotateColumnsHardVersion {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            E2RotateColumnsHardVersion.Column[] columns = new E2RotateColumnsHardVersion.Column[m];\n            for (int i = 0; i < columns.length; ++i) columns[i] = new E2RotateColumnsHardVersion.Column(new int[n]);\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    columns[j].vals[i] = in.nextInt();\n                }\n            }\n            for (E2RotateColumnsHardVersion.Column column : columns) column.initMax();\n            Arrays.sort(columns, new Comparator<E2RotateColumnsHardVersion.Column>() {\n\n                public int compare(E2RotateColumnsHardVersion.Column o1, E2RotateColumnsHardVersion.Column o2) {\n                    return o2.max - o1.max;\n                }\n            });\n            if (columns.length > n)\n                columns = Arrays.copyOf(columns, n);\n            out.println(solveOne(columns));\n        }\n\n        private int solveOne(E2RotateColumnsHardVersion.Column[] columns) {\n            int n = columns[0].vals.length;\n            int[] best = new int[1 << n];\n            int[] next = new int[1 << n];\n            int[] temp = new int[1 << n];\n\n            for (E2RotateColumnsHardVersion.Column nowColumn : columns) {\n                System.arraycopy(best, 0, next, 0, best.length);\n                for (int rot = 0; rot < n; ++rot) {\n                    System.arraycopy(best, 0, temp, 0, next.length);\n                    for (int i = 0, pos = rot; i < n; ++i, ++pos) {\n                        if (pos >= n) pos = 0;\n                        int val = nowColumn.vals[pos];\n                        for (int j = 0; j < temp.length; ++j) {\n                            if ((j & (1 << i)) == 0) {\n                                temp[j | (1 << i)] = Math.max(temp[j | (1 << i)], temp[j] + val);\n                            }\n                        }\n                    }\n                    for (int j = 0; j < temp.length; ++j) {\n                        next[j] = Math.max(next[j], temp[j]);\n                    }\n                }\n                int[] aa = best;\n                best = next;\n                next = aa;\n            }\n            return best[best.length - 1];\n        }\n\n        static class Column {\n            int[] vals;\n            int max;\n\n            public Column(int[] vals) {\n                this.vals = vals;\n            }\n\n            void initMax() {\n                max = 0;\n                for (int vv : vals) max = Math.max(max, vv);\n            }\n\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public String next() {\n            return nextString();\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 String nextString() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = pread();\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\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.util.Random;\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        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\n        int testCount = in.scanInt();\n        for (int i = 1; i <= testCount; i++)\n            solver.solve(i, in, out);\n        out.close();\n    }\n\n    static class E2RotateColumnsHardVersion {\n        int[][] dp;\n        int[] cur;\n\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            int[][] ar = new int[n][m];\n            int[][] max = new int[m][2];\n            for (int i = 0; i < n; i++)\n                for (int j = 0; j < m; j++)\n                    ar[i][j] = in.scanInt();\n            for (int i = 0; i < m; i++) {\n                for (int j = 0; j < n; j++) max[i][0] = Math.max(max[i][0], ar[j][i]);\n                max[i][1] = i;\n            }\n            CodeHash.shuffle(max);\n            Arrays.sort(max, (o1, o2) -> -o1[0] + o2[0]);\n            dp = new int[2][1 << n];\n            cur = new int[1 << n];\n            for (int i = 0; i < Math.min(m, n); i++) {\n                Arrays.fill(cur, 0);\n                Arrays.fill(dp[i & 1], 0);\n                for (int j = 0; j < 1 << n; j++) {\n                    for (int k = 0; k < n; k++) {\n                        int sum = 0;\n                        for (int l = 0; l < n; l++) {\n                            if ((j & (1 << l)) != 0) {\n                                sum += (ar[(k + l) % n][max[i][1]]);\n                            }\n                        }\n                        cur[j] = Math.max(cur[j], sum);\n                    }\n                }\n                for (int j = 0; j < (1 << n); j++) {\n                    for (int k = j; ; k = (k - 1) & j) {\n                        dp[i & 1][j] = Math.max(dp[i & 1][j], dp[(i - 1) & 1][k] + cur[j ^ k]);\n                        if (k == 0) break;\n                    }\n                }\n            }\n            out.println(dp[Math.min(n, m) & 1 ^ 1][(1 << n) - 1]);\n        }\n\n    }\n\n    static class CodeHash {\n        public static void shuffle(int[][] ar) {\n            Random rd = new Random(new Random().nextInt());\n            for (int i = 0; i < ar.length; i++) {\n                int index = rd.nextInt(ar.length);\n                int[] temp = ar[i];\n                ar[i] = ar[index];\n                ar[index] = temp;\n            }\n        }\n\n    }\n\n    static class ScanReader {\n        private byte[] buf = new byte[4 * 1024];\n        private int index;\n        private BufferedInputStream in;\n        private int total;\n\n        public ScanReader(InputStream inputStream) {\n            in = new BufferedInputStream(inputStream);\n        }\n\n        private int scan() {\n            if (index >= total) {\n                index = 0;\n                try {\n                    total = in.read(buf);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n                if (total <= 0) return -1;\n            }\n            return buf[index++];\n        }\n\n        public int scanInt() {\n            int integer = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    integer *= 10;\n                    integer += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * integer;\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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[][] a = new int[12][2000];\n  int[][] e = new int[12 * 2000][3];\n  Integer[] se = new Integer[12 * 2000];\n  boolean[] used = new boolean[2000];\n  int[] dp = new int[1 << 12];\n  int[] one = new int[1 << 12];\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 readLine() {\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  public static void main(String[] args) {\n    Test te = new Test();\n    te.start();\n    writer.flush();\n  }\n\n  void start() {\n    int t = readInt();\n    while (t-- > 0) {\n      int n = readInt(), m = readInt();\n      for (int i = 0; i < n; i++)\n        for (int j = 0; j < m; j++) {\n          a[i][j] = readInt();\n          int k = i * m + j;\n          e[k][0] = a[i][j];\n          e[k][1] = j;\n          e[k][2] = i;\n        }\n      for (int i = n * m - 1; i >= 0; i--) se[i] = i;\n      Arrays.sort(\n          se,\n          0,\n          n * m,\n          (i, j) -> {\n            int[] x = e[i], y = e[j];\n            return x[0] == y[0]\n                ? (x[1] == y[1] ? Integer.compare(x[2], y[2]) : Integer.compare(x[1], y[1]))\n                : Integer.compare(x[0], y[0]);\n          });\n      Arrays.fill(used, 0, m, false);\n      Arrays.fill(dp, 0, 1 << n, -1);\n      dp[0] = 0;\n      int cc = 0;\n      for (int x = n * m - 1; x >= 0; x--) {\n        int c = e[se[x]][1];\n        if (used[c]) continue;\n        used[c] = true;\n        cc++;\n        if (cc > n) break;\n\n        Arrays.fill(one, 0, 1 << n, 0);\n\n        for (int i = (1 << n) - 1; i > 0; i--) {\n          for (int r = 0; r < n; r++) {\n            int sum = 0;\n            for (int j = 0; j < n; j++) if (((i >> j) & 1) != 0) sum += a[(j + r) % n][c];\n            one[i] = Math.max(one[i], sum);\n          }\n        }\n\n        for (int i = (1 << n) - 1; i >= 0; i--) {\n          int u = (1 << n) - 1 - i;\n          int p = u;\n          if (dp[i] >= 0)\n            while (p > 0) {\n              dp[i | p] = Math.max(dp[i | p], dp[i] + one[p]);\n              p = (p - 1) & u;\n            }\n        }\n      }\n      writer.println(dp[(1 << n) - 1]);\n    }\n  }\n}\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class E {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tArrayList<Integer>[][] nexts = new ArrayList[13][];\t\t\n\t\tArrayList<Integer>[] bs = new ArrayList[13];\n\t\tint[][] index = new int[13][];\n\t\tint[][] eqcl = new int[13][];\n\t\tfor(int n = 1; n <= 12; n++) {\n\t\t\teqcl[n] = new int[(1 << n)];\n\t\t\tbs[n] = new ArrayList<Integer>();\n\t\t\tindex[n] = new int[(1 << n)];\n\t\t\tint ind = 0;\n\t\t\tfor(int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\tboolean add = true;\n\t\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\t\tif(rot(mask, k, n) < mask) add = false;\n\t\t\t\t}\n\t\t\t\tif(add) {\n\t\t\t\t\tbs[n].add(mask);\n\t\t\t\t\tindex[n][mask] = ind; ind++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tnexts[n] = new ArrayList[bs[n].size()];\n\t\t\tfor(int i = 0; i < bs[n].size(); i++) {\n\t\t\t\tint mask = bs[n].get(i);\n\t\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\t\teqcl[n][rot(mask, k, n)] = mask;\n\t\t\t\t}\n\t\t\t\tnexts[n][i] = new ArrayList<>();\n\t\t\t\tfor(int y = 0; y < (1 << n); y++) {\n\t\t\t\t\tif((mask & y) == 0) {\n\t\t\t\t\t\tnexts[n][i].add(y);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint T = Integer.parseInt(br.readLine());\n\t\tBufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tfor(int test = 0; test < T; test++) {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\tint m = Integer.parseInt(st.nextToken());\n\t\t\tint[][] arrt = new int[m][n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\t\tarrt[j][i] = Integer.parseInt(st.nextToken());\n\t\t\t\t}\n\t\t\t}\n\t\t\tColumn[] cols = new Column[m];\n\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\tcols[j] = new Column(arrt[j]);\n\t\t\t}\n\t\t\tArrays.sort(cols, Collections.reverseOrder());\n\t\t\tm = Integer.min(n, 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] = cols[j].arr[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][] max = new int[m][bs[n].size()];\n\t\t\tfor(int c = 0; c < m; c++) {\n\t\t\t\tfor(int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\t\tint curr = 0;\n\t\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\t\tif((mask & (1 << i)) > 0) curr += arr[i][c];\n\t\t\t\t\t}\n\t\t\t\t\tint cl = eqcl[n][mask];\n\t\t\t\t\tmax[c][index[n][cl]] = Integer.max(max[c][index[n][cl]], curr);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][] dp = new int[m+1][bs[n].size()];\n\t\t\tfor(int c = 0; c < m; c++) {\n\t\t\t\tfor(int i = 0; i < bs[n].size(); i++) {\n\t\t\t\t\tint mask = bs[n].get(i);\n\t\t\t\t\tfor(int next: nexts[n][i]) {\n\t\t\t\t\t\tint cl = eqcl[n][next];\n\t\t\t\t\t\tint dl = eqcl[n][mask | next];\n\t\t\t\t\t\tif(dp[c][i] + max[c][index[n][cl]] > dp[c+1][index[n][dl]]) {\n\t\t\t\t\t\t\tdp[c+1][index[n][dl]] = dp[c][i] + max[c][index[n][cl]]; \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\tbw.write(dp[m][bs[n].size() - 1]+\"\\n\");\n\t\t}\n\t\tbw.flush();\n\t}\n\tstatic int rot(int x, int k, int n) {\n\t\tint a = x << k;\n\t\tint b = x >> (n - k);\n\t\treturn (a + b) & ((1 << n) - 1);\n\t}\n\tstatic class Column implements Comparable<Column>{\n\t\tint[] arr;\n\t\tint max;\n\t\tpublic Column(int[] arr) {\n\t\t\tthis.arr = arr;\n\t\t\tmax = 0;\n\t\t\tfor(int k: arr) {\n\t\t\t\tmax = Integer.max(max, k);\n\t\t\t}\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Column col) {\n\t\t\treturn max - col.max;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "//package round584;\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\n// imp:12m\npublic class E5 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni(); T> 0;T--){\n\t\t\tint n = ni(), m = ni();\n\t\t\tint[][] a = new int[m][n];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\t\ta[j][i] = ni();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint[][] mx = new int[m][];\n\t\t\tfor(int i = 0;i < m;i++){\n\t\t\t\tint u = 0;\n\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\tu = Math.max(u, a[i][j]);\n\t\t\t\t}\n\t\t\t\tmx[i] = new int[]{u, i};\n\t\t\t}\n\t\t\tArrays.sort(mx, new Comparator<int[]>() {\n\t\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\t\treturn -(a[0] - b[0]);\n\t\t\t\t}\n\t\t\t});\n\t\t\tint[] dp = new int[1<<n];\n\t\t\tfor(int i = 0;i < n && i < m;i++){\n\t\t\t\tint c = mx[i][1];\n\t\t\t\tint[] ls = new int[1<<n];\n\t\t\t\tfor(int j = 1;j < 1<<n;j++){\n\t\t\t\t\tls[j] = ls[j&j-1] + a[c][Integer.numberOfTrailingZeros(j)];\n\t\t\t\t}\n\t\t\t\tfor(int j = 1;j < 1<<n;j++){\n\t\t\t\t\tint r = rot(j, n);\n\t\t\t\t\tls[r] = Math.max(ls[r], ls[j]);\n\t\t\t\t}\n\t\t\t\tint[] ndp = new int[1<<n];\n\t\t\t\tfor(int j = 0;j < 1<<n;j++){\n\t\t\t\t\tif(rot(j, n) == j){\n\t\t\t\t\t\tint cur = j;\n\t\t\t\t\t\tfor(int sh = 0;sh < n;sh++){\n\t\t\t\t\t\t\tcur = cur>>1|(cur&1)<<n-1;\n\t\t\t\t\t\t\tint mask = (1<<n)-1^cur;\n\t\t\t\t\t\t\tfor(int k = mask;k >= 0;k--){\n\t\t\t\t\t\t\t\tk &= mask;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tndp[k|cur] = Math.max(\n\t\t\t\t\t\t\t\t\t\tndp[k|cur], dp[k] + ls[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdp = ndp;\n\t\t\t}\n\t\t\tout.println(dp[(1<<n)-1]);\n\t\t}\n\t}\n\t\n\tint rot(int x, int n)\n\t{\n\t\tint ret = x;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tx = x>>>1|(x&1)<<n-1;\n\t\t\t\tret = Math.min(ret, x);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 12, m = 2000;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(40 + \" \");\n//\t\tfor(int rep = 0;rep < 40;rep++){\n//\t\t\tsb.append(n + \" \");\n//\t\t\tsb.append(m + \" \");\n//\t\t\tfor (int i = 0; i < n*m; i++) {\n//\t\t\t\tsb.append(gen.nextInt(100000) + \" \");\n//\t\t\t}\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 E5().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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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\tint t=in.nextInt();\n\t\tfor(int i=0;i<t;i++) {\n\t\t\tout.println(work());\n\t\t}\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tint work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tint[][] A=new int[n][m];\n\t\tint[][] B=new int[n][m];\n\t\tint[][] R=new int[m][2];\n\t\tfor(int i=0;i<m;i++)R[i][1]=i;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tA[i][j]=in.nextInt();\n\t\t\t\tR[j][0]=Math.max(R[j][0], A[i][j]);\n\t\t\t}\n\t\t}\n\t\tArrays.sort(R,new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] arr1,int[] arr2) {\n\t\t\t\treturn arr2[0]-arr1[0];\n\t\t\t}\n\t\t});\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tint index=R[j][1];\n\t\t\tfor(int i=0;i<n;i++) {\n\t\t\t\tB[i][j]=A[i][index];\n\t\t\t}\n\t\t}\n\t\tm=Math.min(n, m);\n\t\tint[][] dp=new int[m][1<<n];\n\t\tint[][] rec=new int[m][1<<n];\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tfor(int s=0;s<n;s++) {//\u8f6c\n\t\t\t\tfor(int i=1;i<1<<n;i++) {\n\t\t\t\t\tint sum=0;\n\t\t\t\t\tfor(int b=0;b<n;b++) {\n\t\t\t\t\t\tif(((1<<b)&i)>0) {\n\t\t\t\t\t\t\tsum+=B[(b+s)%n][j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trec[j][i]=Math.max(sum, rec[j][i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int j=0;j<m;j++) {\n\t\t\tfor(int i=0;i<1<<n;i++) {\n\t\t\t\tif(j==0) {\n\t\t\t\t\tdp[j][i]=rec[j][i];\n\t\t\t\t}else {\n\t\t\t\t\tfor(int p=i+1;;p++) {\n\t\t\t\t\t\tif(p>=1<<n)break;\n\t\t\t\t\t\tp=p|i;\n\t\t\t\t\t\tdp[j][p]=Math.max(dp[j][p], rec[j][i]+dp[j-1][p^i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[m-1][(1<<n)-1];\n\t}\n}\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "//package round584;\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 E4 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni(); T> 0;T--){\n\t\t\tint n = ni(), m = ni();\n\t\t\tint[][] a = new int[n][];\n\t\t\tfor(int i = 0;i < n;i++)a[i] = na(m);\n\t\t\t\n\t\t\tint[][] mx = new int[m][];\n\t\t\tfor(int i = 0;i < m;i++){\n\t\t\t\tint u = 0;\n\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\tu = Math.max(u, a[j][i]);\n\t\t\t\t}\n\t\t\t\tmx[i] = new int[]{u, i};\n\t\t\t}\n\t\t\tArrays.sort(mx, new Comparator<int[]>() {\n\t\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\t\treturn -(a[0] - b[0]);\n\t\t\t\t}\n\t\t\t});\n\t\t\tint[] dp = new int[1<<n];\n\t\t\tfor(int i = 0;i < n && i < m;i++){\n\t\t\t\tint c = mx[i][1];\n\t\t\t\tint[] ls = new int[1<<n];\n\t\t\t\tfor(int j = 1;j < 1<<n;j++){\n\t\t\t\t\tls[j] = ls[j&j-1] + a[Integer.numberOfTrailingZeros(j)][c];\n\t\t\t\t}\n\t\t\t\tfor(int j = 1;j < 1<<n;j++){\n\t\t\t\t\tint r = rot(j, n);\n\t\t\t\t\tls[r] = Math.max(ls[r], ls[j]);\n\t\t\t\t}\n\t\t\t\tint[] ndp = new int[1<<n];\n\t\t\t\tfor(int j = 0;j < 1<<n;j++){\n\t\t\t\t\tif(rot(j, n) == j){\n\t\t\t\t\t\tint cur = j;\n\t\t\t\t\t\tfor(int sh = 0;sh < n;sh++){\n\t\t\t\t\t\t\tcur = cur>>1|(cur&1)<<n-1;\n\t\t\t\t\t\t\tint mask = (1<<n)-1^cur;\n\t\t\t\t\t\t\tfor(int k = mask;k >= 0;k--){\n\t\t\t\t\t\t\t\tk &= mask;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tndp[k|cur] = Math.max(\n\t\t\t\t\t\t\t\t\t\tndp[k|cur], dp[k] + ls[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdp = ndp;\n\t\t\t}\n\t\t\tout.println(dp[(1<<n)-1]);\n\t\t}\n\t}\n\t\n\tint rot(int x, int n)\n\t{\n\t\tint ret = x;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tx = x>>>1|(x&1)<<n-1;\n\t\t\t\tret = Math.min(ret, x);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 12, m = 2000;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(40 + \" \");\n//\t\tfor(int rep = 0;rep < 40;rep++){\n//\t\t\tsb.append(n + \" \");\n//\t\t\tsb.append(m + \" \");\n//\t\t\tfor (int i = 0; i < n*m; i++) {\n//\t\t\t\tsb.append(gen.nextInt(100000) + \" \");\n//\t\t\t}\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 E4().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", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        FastReader in = new FastReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        E2RotateColumnsHardVersion solver = new E2RotateColumnsHardVersion();\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 E2RotateColumnsHardVersion {\n        public void solve(int testNumber, FastReader in, PrintWriter out) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n            E2RotateColumnsHardVersion.Column[] columns = new E2RotateColumnsHardVersion.Column[m];\n            for (int i = 0; i < columns.length; ++i) columns[i] = new E2RotateColumnsHardVersion.Column(new int[n]);\n            for (int i = 0; i < n; ++i) {\n                for (int j = 0; j < m; ++j) {\n                    columns[j].v[i] = in.nextInt();\n                    if (i == n - 1) columns[j].initMax();\n                }\n            }\n            Arrays.sort(columns, new Comparator<E2RotateColumnsHardVersion.Column>() {\n\n                public int compare(E2RotateColumnsHardVersion.Column o1, E2RotateColumnsHardVersion.Column o2) {\n                    return o2.max - o1.max;\n                }\n            });\n            if (columns.length > n)\n                columns = Arrays.copyOf(columns, n);\n\n            long[] dp = new long[1 << n];\n            for (E2RotateColumnsHardVersion.Column c : columns) {\n                long[] ndp = new long[1 << n];\n                System.arraycopy(dp, 0, ndp, 0, dp.length);\n\n                for (int rot = 0; rot < n; ++rot) {\n                    long[] temp = new long[1 << n];\n                    System.arraycopy(dp, 0, temp, 0, dp.length);\n                    for (int i = 0, pos = rot; i < n; ++i, ++pos) {\n                        if (pos >= n) pos = 0;\n                        int val = c.v[pos];\n                        for (int j = 0; j < temp.length; ++j) {\n                            if ((j & (1 << i)) == 0)\n                                temp[j | (1 << i)] = Math.max(temp[j | (1 << i)], temp[j] + val);\n                        }\n                    }\n                    for (int i = 0; i < ndp.length; ++i)\n                        ndp[i] = Math.max(ndp[i], temp[i]);\n                }\n                dp = ndp;\n            }\n            out.println(dp[dp.length - 1]);\n        }\n\n        static class Column {\n            int[] v;\n            int max;\n\n            public Column(int[] v) {\n                this.v = v;\n            }\n\n            void initMax() {\n                max = 0;\n                for (int vv : v) max = Math.max(max, vv);\n            }\n\n        }\n\n    }\n\n    static class FastReader {\n        private InputStream stream;\n        private byte[] buf = new byte[8192];\n        private int curChar;\n        private int pnumChars;\n\n        public FastReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private int pread() {\n            if (pnumChars == -1) {\n                throw new InputMismatchException();\n            }\n            if (curChar >= pnumChars) {\n                curChar = 0;\n                try {\n                    pnumChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (pnumChars <= 0) {\n                    return -1;\n                }\n            }\n            return buf[curChar++];\n        }\n\n        public String next() {\n            return nextString();\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 String nextString() {\n            int c = pread();\n            while (isSpaceChar(c))\n                c = pread();\n            StringBuilder res = new StringBuilder();\n            do {\n                res.appendCodePoint(c);\n                c = pread();\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\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class E1 {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\t//optimizaciones que parece que solo son necesarias para java\n\t\tArrayList<Integer>[] reps = new ArrayList[13]; //representantes de las clases\n\t\tint[][] index = new int[13][]; // mapea para cada representante un indice de 0 a |clases|-1\n\t\tint[][] eqcl = new int[13][]; //mapea para cada mask, su clase\n\t\tArrayList<Integer>[][] nexts = new ArrayList[13][];\t//para cada clase, los masks compatibles\n\t\tfor(int n = 1; n <= 12; n++) {\n\t\t\teqcl[n] = new int[(1 << n)];\n\t\t\treps[n] = new ArrayList<Integer>();\n\t\t\tindex[n] = new int[(1 << n)];\n\t\t\tint ind = 0;\n\t\t\tfor(int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\tboolean add = true;\n\t\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\t\tif(rot(mask, k, n) < mask) add = false;\n\t\t\t\t}\n\t\t\t\tif(add) {\n\t\t\t\t\treps[n].add(mask);\n\t\t\t\t\tindex[n][mask] = ind; ind++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tnexts[n] = new ArrayList[reps[n].size()];\n\t\t\tfor(int i = 0; i < reps[n].size(); i++) {\n\t\t\t\tint mask = reps[n].get(i);\n\t\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\t\teqcl[n][rot(mask, k, n)] = i;\n\t\t\t\t}\n\t\t\t\tnexts[n][i] = new ArrayList<>();\n\t\t\t\tfor(int y = 0; y < (1 << n); y++) {\n\t\t\t\t\tif((mask & y) == 0) {\n\t\t\t\t\t\tnexts[n][i].add(y);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint T = Integer.parseInt(br.readLine());\n\t\tBufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tfor(int test = 0; test < T; test++) {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\tint m = Integer.parseInt(st.nextToken());\n\t\t\tint[][] arrt = new int[m][n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\t\tarrt[j][i] = Integer.parseInt(st.nextToken());\n\t\t\t\t}\n\t\t\t}\n\t\t\tColumn[] cols = new Column[m];\n\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\tcols[j] = new Column(arrt[j]);\n\t\t\t}\n\t\t\tArrays.sort(cols, Collections.reverseOrder());\n\t\t\tm = Integer.min(n, 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] = cols[j].arr[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][] max = new int[m][reps[n].size()];\n\t\t\tfor(int c = 0; c < m; c++) {\n\t\t\t\tfor(int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\t\tint curr = 0;\n\t\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\t\tif((mask & (1 << i)) > 0) curr += arr[i][c];\n\t\t\t\t\t}\n\t\t\t\t\tint cl = eqcl[n][mask];\n\t\t\t\t\tmax[c][cl] = Integer.max(max[c][cl], curr);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[][] dp = new int[m+1][reps[n].size()];\n\t\t\tfor(int c = 0; c < m; c++) {\n\t\t\t\tfor(int i = 0; i < reps[n].size(); i++) {\n\t\t\t\t\tint mask = reps[n].get(i);\n\t\t\t\t\tfor(int next: nexts[n][i]) { //opt\n\t\t\t\t\t\tint cl = eqcl[n][next];\n\t\t\t\t\t\tint dl = eqcl[n][mask | next];\n\t\t\t\t\t\tif(dp[c][i] + max[c][cl] > dp[c+1][dl]) { // el dp\n\t\t\t\t\t\t\tdp[c+1][dl] = dp[c][i] + max[c][cl]; \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\tbw.write(dp[m][reps[n].size() - 1]+\"\\n\");\n\t\t}\n\t\tbw.flush();\n\t}\n\tstatic int rot(int x, int k, int n) {\n\t\tint a = x << k;\n\t\tint b = x >> (n - k);\n\t\treturn (a + b) & ((1 << n) - 1);\n\t}\n\tstatic class Column implements Comparable<Column>{\n\t\tint[] arr;\n\t\tint max;\n\t\tpublic Column(int[] arr) {\n\t\t\tthis.arr = arr;\n\t\t\tmax = 0;\n\t\t\tfor(int k: arr) {\n\t\t\t\tmax = Integer.max(max, k);\n\t\t\t}\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Column col) {\n\t\t\treturn max - col.max;\n\t\t}\n\t}\n}\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\n/*\n6\n2 2\n5 2\n1 5\n1 1\n3\n1 2\n1 1\n1 2\n1 1\n1 2\n2 3\n2 1\n1\n1\n\n*/\n\npublic class e2 {\n\n\tstatic int n;\n\tstatic int m;\n\tstatic int[][] mat;\n\n\tpublic static void main(String[] args){\n\t\tJS scan = new JS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint t = scan.nextInt();\n\t\tlong start = System.currentTimeMillis();\n\t\tfor(int q = 1; q <= t; q++){\n\t\t\tn = scan.nextInt();\n\t\t\tm = scan.nextInt();\n\t\t\t// n = 12;\n\t\t\t// m = 20000;\n\t\t\tmat = 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\tmat[i][j] = scan.nextInt();\n\t\t\t\t\t// mat[i][j] = 100000;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] max = new int[m];\n\t\t\tPriorityQueue<Item> pq = new PriorityQueue<Item>();\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\tmax[i] = max(max[i], mat[j][i]);\n\t\t\t\t}\n\t\t\t\tpq.add(new Item(i, max[i]));\n\t\t\t}\n\t\t\tArrayList<Item> guys = new ArrayList<Item>();\n\t\t\twhile(!pq.isEmpty() && guys.size() < n){\n\t\t\t\tItem tt = pq.poll();\n\t\t\t\tguys.add(tt);\n\t\t\t}\n\n\t\t\tint[][] cost = new int[guys.size()][1 << n];\n\t\t\t// long time = System.currentTimeMillis();\n\t\t\tfor(int i = 0; i < guys.size(); i++){\n\t\t\t\tint g = guys.get(i).a;\n\t\t\t\tfor(int s = 0; s < n; s++){\n\t\t\t\t\tfor(int j = 0; j < (1 << n); j++){\n\t\t\t\t\t\tint sum = 0;\n\t\t\t\t\t\tfor(int k = 0; k < n; k++){\n\t\t\t\t\t\t\tif((j & (1 << k)) > 0){\n\t\t\t\t\t\t\t\tsum += mat[(k+s)%n][g];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcost[i][j] = max(cost[i][j], sum);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// for(int i = 0; i < guys.size(); i++) System.out.println(Arrays.toString(cost[i]));\n\n\t\t\t// System.out.println(System.currentTimeMillis()-time);\n\t\t\tint full = (1 << n)-1;\n\t\t\t// time = System.currentTimeMillis();\n\t\t\tint[][] dp = new int[guys.size()+1][1 << n];\n\t\t\tint ans = 0;\n\n\t\t\t\n\t\n\t\t\tfor(int c = 0; c < guys.size(); c++){\n\t\t\t\t\tfor(int j = 0; j < (1 << n); j++){\n\t\t\t\t\t\tfor(int i = j; i < (1 << n); i = (i+1)|j){\n\t\t\t\t\t\t\tdp[c+1][i] = \n\t\t\t\t\t\t\t\tmax(dp[c+1][i], cost[c][j]+dp[c][i^j]);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tans = max(ans, dp[c+1][i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\t\t// for(int i = 0; i < dp.length; i++) System.out.println(Arrays.toString(dp[i]));\n\t\t\t// System.out.println(System.currentTimeMillis()-time);\n\n\t\t\tout.println(ans);\n\t\t}\n\t\t// System.out.println(System.currentTimeMillis()-start);\n\t\tout.flush();\n\t}\n\n\tstatic int max(int a, int b){\n\t\treturn a > b? a : b;\n\t}\n\n\tstatic class Item implements Comparable<Item>{\n\n\t\tint a;\n\t\tint b;\n\n\t\tpublic Item(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(Item o){\n\t\t\treturn o.b-this.b;\n\t\t}\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 \n\t\tpublic JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n \n\t\tpublic JS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n \n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t}\t\t\t\t\n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n \n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n \n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n \n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n \n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t}\n}", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class TaskE {\n\n    static int[][] transpose(int[][] a, int n, int m) {\n        int[][] t = new int[m][n];\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                t[j][i] = a[i][j];\n            }\n        }\n\n        return t;\n    }\n\n    public static void main(String[] args) {\n        FastReader in = new FastReader(System.in);\n//        FastReader in = new FastReader(new FileInputStream(\"input.txt\"));\n        PrintWriter out = new PrintWriter(System.out);\n//        PrintWriter out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\n\n        int t = in.nextInt();\n\n        while (t-- > 0) {\n            int n = in.nextInt();\n            int m = in.nextInt();\n\n            int[][] a = new int[n + 1][m];\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    a[i][j] = in.nextInt();\n                    a[n][j] = Math.max(a[n][j], a[i][j]);\n                }\n            }\n\n            a = transpose(a, n, m);\n\n            Arrays.sort(a, new Comparator<int[]>() {\n                @Override\n                public int compare(int[] o1, int[] o2) {\n                    int max1 = 0;\n                    for (int i = 0; i < o1.length; i++) {\n                        max1 = Math.max(max1, o1[i]);\n                    }\n\n                    int max2 = 0;\n                    for (int i = 0; i < o2.length; i++) {\n                        max2 = Math.max(max2, o2[i]);\n                    }\n\n                    return max2 - max1;\n                }\n            });\n\n            a = transpose(a, m, n);\n\n            int[] dp = new int[1 << n];\n\n            for (int i = 0; i < Math.min(n, m); i++) {\n                int[] best = new int[1 << n];\n\n                for (int j = 1; j < (1 << n); j++) {\n                    for (int k = 0; k < n; k++) {\n                        int sum = 0;\n                        for (int l = 0; l < n; l++) {\n                            if ((j & (1 << l)) != 0)\n                                sum += a[(l + k) % n][i];\n                        }\n                        best[j] = Math.max(best[j], sum);\n                    }\n                }\n\n                int[] dp1 = dp.clone();\n\n                for (int j = 0; j < (1 << n); j++) {\n                    for (int k = j; k > 0; k = (k - 1) & j) {\n                        dp[j] = Math.max(dp[j], dp1[k ^ j] + best[k]);\n                    }\n                }\n            }\n\n            out.println(dp[(1 << n) - 1]);\n        }\n\n\n\n\n\n        out.close();\n    }\n\n    static class FastReader {\n        BufferedReader br;\n        StringTokenizer st;\n\n        FastReader(InputStream is) {\n            br = new BufferedReader(new InputStreamReader(is));\n        }\n\n        Integer nextInt() {\n            return Integer.parseInt(next());\n        }\n\n        Long nextLong() {\n            return Long.parseLong(next());\n        }\n\n        Double nextDouble() {\n            return Double.parseDouble(next());\n        }\n\n        String next() {\n            while (st == null || !st.hasMoreTokens()) {\n                st = new StringTokenizer(nextLine());\n            }\n            return st.nextToken();\n        }\n\n        String nextLine() {\n            String s = \"\";\n            try {\n                s = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return s;\n        }\n    }\n}\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "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.util.Collections;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author beginner1010\n */\npublic class Main {\n    public static void main(String[] args) {\n        InputStream inputStream = System.in;\n        OutputStream outputStream = System.out;\n        InputReader in = new InputReader(inputStream);\n        PrintWriter out = new PrintWriter(outputStream);\n        TaskE2 solver = new TaskE2();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class TaskE2 {\n        int[][] grid;\n        int[][] val;\n        int[][] dp;\n        int rows;\n\n        int two(int bit) {\n            return 1 << bit;\n        }\n\n        boolean contain(int mask, int bit) {\n            return (mask & two(bit)) > 0;\n        }\n\n        int rec(int col, int mask) {\n            if (col == grid[0].length)\n                return 0;\n\n            if (dp[col][mask] != -1)\n                return dp[col][mask];\n\n            int res = rec(col + 1, mask);\n            for (int newMask = mask; newMask > 0; newMask = (mask & (newMask - 1))) {\n                res = Math.max(res, rec(col + 1, mask ^ newMask) + val[col][newMask]);\n            }\n\n            dp[col][mask] = res;\n            return res;\n        }\n\n        public void solve(int testNumber, InputReader in, PrintWriter out) {\n            int T = in.nextInt();\n            for (int t = 0; t < T; t++) {\n\n                int n = in.nextInt();\n                int m = in.nextInt();\n                rows = n;\n\n                int[][] input = new int[n][m];\n                for (int i = 0; i < n; i++) {\n                    for (int j = 0; j < m; j++) {\n                        input[i][j] = in.nextInt();\n                    }\n                }\n\n                ArrayList<Col> cols = new ArrayList<>();\n                for (int col = 0; col < m; col++) {\n                    int maxVal = 0;\n                    for (int row = 0; row < n; row++) {\n                        maxVal = Math.max(maxVal, input[row][col]);\n                    }\n                    cols.add(new Col(maxVal, col));\n                }\n                Collections.sort(cols);\n\n                m = Math.min(n, m);\n\n                grid = new int[n][m];\n                for (int i = 0; i < m; i++) {\n                    int c = cols.get(i).colID;\n                    for (int row = 0; row < n; row++) {\n                        grid[row][i] = input[row][c];\n                    }\n                }\n\n                val = new int[m][two(n)];\n                for (int c = 0; c < m; c++) {\n                    for (int mask = 0; mask < two(n); mask++) {\n                        val[c][mask] = 0;\n                        for (int offset = 0; offset < n; offset++) {\n                            int sum = 0;\n                            for (int bit = 0; bit < n; bit++) {\n                                if (contain(mask, bit) == true)\n                                    sum += grid[(bit + offset) % n][c];\n                            }\n                            val[c][mask] = Math.max(val[c][mask], sum);\n                        }\n                    }\n                }\n\n                dp = new int[m][two(n)];\n                for (int[] aux : dp)\n                    Arrays.fill(aux, -1);\n                int ans = rec(0, two(n) - 1);\n                out.println(ans);\n            }\n        }\n\n        class Col implements Comparable<Col> {\n            int maxVal;\n            int colID;\n\n            Col(int _maxVal, int _colID) {\n                this.maxVal = _maxVal;\n                this.colID = _colID;\n            }\n\n\n            public int compareTo(Col o) {\n                if (o.maxVal != this.maxVal) return this.maxVal > o.maxVal ? -1 : 1;\n                if (o.colID != this.colID) return this.colID < o.colID ? -1 : 1;\n                return 0;\n            }\n\n        }\n\n    }\n\n    static class InputReader {\n        private byte[] buf = new byte[1024];\n        private int curChar;\n        private int numChars;\n        private InputStream stream;\n\n        public InputReader(InputStream stream) {\n            this.stream = stream;\n        }\n\n        private boolean isWhitespace(int c) {\n            return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n        }\n\n        private int read() {\n            if (numChars == -1)\n                throw new InputMismatchException();\n            if (curChar >= numChars) {\n                curChar = 0;\n                try {\n                    numChars = stream.read(buf);\n                } catch (IOException e) {\n                    throw new InputMismatchException();\n                }\n                if (numChars <= 0)\n                    return -1;\n            }\n            return buf[curChar++];\n        }\n\n        public int nextInt() {\n            int c = read();\n            while (isWhitespace(c))\n                c = read();\n            int sgn = 1;\n            if (c == '-') {\n                sgn = -1;\n                c = read();\n            }\n            int res = 0;\n            do {\n                if (c < '0' || c > '9')\n                    throw new InputMismatchException();\n                res *= 10;\n                res += c - '0';\n                c = read();\n            } while (!isWhitespace(c));\n            return res * sgn;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1209_E2. Rotate Columns (hard version)", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\npublic class Sol2{\n\tfinal public static int MXN = (1<<21);\n\tpublic static int good[][];\n\tpublic static void main(String[] args) throws IOException{\n\t\tFastIO sc = new FastIO(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint num[][] = new int[m][m];\n\t\tString str = sc.next();\n\t\tfor(int i=0; i<str.length()-1; i++) {\n\t\t\tint a = str.charAt(i)-'a';\n\t\t\tint b = str.charAt(i+1)-'a';\n\t\t\tnum[a][b]++;\n\t\t\tnum[b][a]++;\n\t\t}\n\t\tint lowbit[] = new int[MXN];\n\t\tint dp[] = new int[MXN];\n\t\tfor(int i=0; i<MXN; i++) {\n\t\t\tdp[i] = Integer.MAX_VALUE;\n\t\t}\n\t\tdp[0] = 0;\n\t\tgood = new int[MXN][m];\n\t\tfor(int msk = 0; msk<(1<<m); msk++) {\n\t\t\tfor(int i=0; i<m; i++) {\n\t\t\t\tint low = Integer.numberOfTrailingZeros(Integer.lowestOneBit(msk));\n\t\t\t\tif(low==32) low = 0;\n\t\t\t\tgood[msk][i] = good[msk^(1<<low)][i] + num[i][low];\n\t\t\t}\n\t\t}\n\t\tfor(int msk = 0; msk<(1<<m); msk++) {\n\t\t\tint bits = Integer.bitCount(msk)+1;\n\t\t\tfor(int i=0; i<m; i++) {\n\t\t\t\tif((msk&(1<<i))!=0) continue;\n\t\t\t\tint nxt = msk|(1<<i);\n\t\t\t\tdp[nxt] = Math.min(dp[nxt], dp[msk] + bits*(good[msk][i]-good[((1<<m)-1)^nxt][i]));\n\t\t\t}\n\t\t}\n\t\tout.println(dp[(1<<m)-1]);\n\t\tout.close();\n\t}\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(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\tstatic class FastIO {\n\t\t \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 IOException {\n\t\t\tdis = new FileInputStream(fileName);\n\t\t}\n \n\t\tpublic FastIO(InputStream is) throws IOException {\n\t\t\tdis = is;\n\t\t}\n \n\t\tint nextInt() throws IOException {\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 IOException {\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 IOException {\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 IOException {\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\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "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 *\n * @author Jenish\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        EKeyboardPurchase solver = new EKeyboardPurchase();\n        solver.solve(1, in, out);\n        out.close();\n    }\n\n    static class EKeyboardPurchase {\n        public void solve(int testNumber, ScanReader in, PrintWriter out) {\n            int n = in.scanInt();\n            int m = in.scanInt();\n            int step[][] = new int[m][m];\n            char arr[] = in.scanString().toCharArray();\n            for (int i = 0; i < n - 1; i++) {\n                step[arr[i] - 'a'][arr[i + 1] - 'a']++;\n                step[arr[i + 1] - 'a'][arr[i] - 'a']++;\n            }\n\n\n            int dp[] = new int[1 << m];\n            Arrays.fill(dp, Integer.MAX_VALUE / 2);\n            for (int i = 0; i < m; i++) dp[1 << i] = 0;\n            for (int i = 0; i < (1 << m); i++) {\n                int cost = 0;\n                for (int j = 0; j < m; j++) {\n                    if (((i & (1 << j)) != 0)) {\n                        for (int k = 0; k < m; k++) {\n                            if (((i & (1 << k)) == 0)) {\n                                cost += step[j][k];\n                            }\n                        }\n                    }\n                }\n\n\n                for (int j = 0; j < m; j++)\n                    if (((i & (1 << j)) == 0)) dp[i | (1 << j)] = Math.min(dp[i | (1 << j)], dp[i] + cost);\n\n\n            }\n\n\n            out.println(dp[(1 << m) - 1]);\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 I = 0;\n            int n = scan();\n            while (isWhiteSpace(n)) n = scan();\n            int neg = 1;\n            if (n == '-') {\n                neg = -1;\n                n = scan();\n            }\n            while (!isWhiteSpace(n)) {\n                if (n >= '0' && n <= '9') {\n                    I *= 10;\n                    I += n - '0';\n                    n = scan();\n                }\n            }\n            return neg * I;\n        }\n\n        public String scanString() {\n            int c = scan();\n            while (isWhiteSpace(c)) c = scan();\n            StringBuilder RESULT = new StringBuilder();\n            do {\n                RESULT.appendCodePoint(c);\n                c = scan();\n            } while (!isWhiteSpace(c));\n            return RESULT.toString();\n        }\n\n        private boolean isWhiteSpace(int n) {\n            if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n            else return false;\n        }\n\n    }\n}\n\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n   public class x1238E\n   {\n      public static void main(String omkar[]) throws Exception\n      {\n         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  \n         StringTokenizer st = new StringTokenizer(infile.readLine());\n         int N = Integer.parseInt(st.nextToken());\n         int M = Integer.parseInt(st.nextToken());\n         String input = infile.readLine();\n         int[][] cnt = new int[M][M];\n         for(int i=0; i < N-1; i++)\n         if(input.charAt(i) != input.charAt(i+1))\n            {\n               cnt[input.charAt(i)-'a'][input.charAt(i+1)-'a']++;\n               cnt[input.charAt(i+1)-'a'][input.charAt(i)-'a']++;\n            }\n         int[] dp = new int[1 << M];\n         Arrays.fill(dp, Integer.MAX_VALUE);\n         dp[0] = 0;\n         for(int mask=0; mask < dp.length; mask++)\n            for(int b=0; b < M; b++)\n               if((mask&(1<<b)) == 0)\n               {\n                  int submask = mask|(1<<b);\n                  int cost = 0;\n                  for(int c=0; c < M; c++)\n                  {\n                     if((mask&(1<<c)) > 0)\n                        cost += cnt[b][c];\n                     else\n                        cost -= cnt[b][c];\n                  }\n                  dp[submask] = Math.min(dp[submask], dp[mask]+cost*Integer.bitCount(mask));\n               }\n         System.out.println(dp[(1<<M)-1]);\n      }\n   }", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "/**\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 n,m;\n    static int dp[], cnt[][], sum[];\n    static void solve() throws IOException\n    {\n        //initIo(true);\n        initIo(false);\n        StringBuilder sb = new StringBuilder();\n        n = ni();\n        m = ni();\n        dp = new int[(1<<m)];\n        char c[] = ne().toCharArray();\n        cnt = new int[m][m];\n        for(int i=0;i+1<n;++i) {\n            if(c[i]!=c[i+1]) {\n                ++cnt[c[i] - 'a'][c[i+1] - 'a'];\n                ++cnt[c[i+1] - 'a'][c[i] - 'a'];\n            }\n        }\n        sum = new int[1<<m];\n        calc(0, 0, 0);\n        Arrays.fill(dp, -1);\n        pl(f(0));\n        pw.flush();\n        pw.close();\n    }\n    static void calc(int mask, int S, int pos) {\n        if(pos==m) {\n            sum[mask] = S;\n            return;\n        }\n        calc(mask, S, pos+1);\n        int newSum = S;\n        for(int i=0;i<pos;++i) {\n            if((mask&(1<<i))!=0) {\n                newSum-=cnt[i][pos];\n            }\n            else {\n                newSum+=cnt[i][pos];\n            }\n        }\n        for(int i=pos+1;i<m;++i) {\n            newSum+=cnt[i][pos];\n        }\n        calc(mask|(1<<pos), newSum, pos+1);\n    }\n    static int f(int mask) {\n        if(mask==(1<<m) - 1) {\n            return 0;\n        }\n        if(dp[mask]!=-1) {\n            return dp[mask];\n        }\n        int min = Integer.MAX_VALUE;\n        for(int i=0;i<m;++i) {\n            if((mask&(1<<i))==0) {\n                min  =  min(min, sum[mask]+f(mask|(1<<i)));\n            }\n        }\n        return dp[mask] = min;\n    }\n    static void initIo(boolean isFileIO) throws IOException {\n        scan = new MyScanner(isFileIO);\n        if(isFileIO) {\n            pw = new PrintWriter(\"/Users/amandeep/Desktop/output.txt\");\n        }\n        else {\n            pw = new PrintWriter(System.out, true);\n        }\n    }\n    static int ni() throws IOException\n    {\n        return scan.nextInt();\n    }\n    static long nl() throws IOException\n    {\n        return scan.nextLong();\n    }\n    static double nd() throws IOException\n    {\n        return scan.nextDouble();\n    }\n    static String ne() throws IOException\n    {\n        return scan.next();\n    }\n    static String nel() throws IOException\n    {\n        return scan.nextLine();\n    }\n    static void pl()\n    {\n        pw.println();\n    }\n    static void p(Object o)\n    {\n        pw.print(o+\" \");\n    }\n    static void pl(Object o)\n    {\n        pw.println(o);\n    }\n    static void psb(StringBuilder sb)\n    {\n        pw.print(sb);\n    }\n    static void pa(String arrayName, Object arr[])\n    {\n        pl(arrayName+\" : \");\n        for(Object o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, int arr[])\n    {\n        pl(arrayName+\" : \");\n        for(int o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, long arr[])\n    {\n        pl(arrayName+\" : \");\n        for(long o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, double arr[])\n    {\n        pl(arrayName+\" : \");\n        for(double o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, char arr[])\n    {\n        pl(arrayName+\" : \");\n        for(char o : arr)\n            p(o);\n        pl();\n    }\n    static void pa(String listName, List list)\n    {\n        pl(listName+\" : \");\n        for(Object o : list)\n            p(o);\n        pl();\n    }\n    static void pa(String arrayName, Object[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(Object o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, int[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(int o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, long[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(long o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, char[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(char o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static void pa(String arrayName, double[][] arr) {\n        pl(arrayName+\" : \");\n        for(int i=0;i<arr.length;++i) {\n            for(double o : arr[i])\n                p(o);\n            pl();\n        }\n    }\n    static class MyScanner\n    {\n        BufferedReader br;\n        StringTokenizer st;\n        MyScanner(boolean readingFromFile) throws IOException\n        {\n            if(readingFromFile) {\n                br = new BufferedReader(new FileReader(\"/Users/amandeep/Desktop/input.txt\"));\n            }\n            else {\n                br = new BufferedReader(new InputStreamReader(System.in));\n            }\n        }\n        String nextLine()throws IOException\n        {\n            return br.readLine();\n        }\n        String next() throws IOException\n        {\n            if(st==null || !st.hasMoreTokens())\n                st = new StringTokenizer(br.readLine());\n            return st.nextToken();\n        }\n        int nextInt() throws IOException\n        {\n            return Integer.parseInt(next());\n        }\n        long nextLong() throws IOException\n        {\n            return Long.parseLong(next());\n        }\n        double nextDouble() throws IOException\n        {\n            return Double.parseDouble(next());\n        }\n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.Arrays;\n\npublic class CF1238E {\n    public static void main(String[] args) throws Exception {\n        boolean local = System.getSecurityManager() == 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        long lInf = (long) 1e18;\n        double dInf = 1e50;\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\n        int[][] fee;\n        int m;\n        long[] dp;\n        int mask;\n        int[][] maskFee;\n\n        public void solve() {\n            int n = io.readInt();\n            m = io.readInt();\n            char[] s = new char[n];\n            io.readString(s, 0);\n            for (int i = 0; i < n; i++) {\n                s[i] -= 'a';\n            }\n            fee = new int[m][m];\n            for (int i = 1; i < n; i++) {\n                fee[s[i]][s[i - 1]]++;\n                fee[s[i - 1]][s[i]]++;\n            }\n\n            mask = (1 << m) - 1;\n            maskFee = new int[m][mask + 1];\n            SubsetGenerator sg = new SubsetGenerator();\n            for (int i = 0; i < m; i++) {\n                for (int j = 0; j < m; j++) {\n                    sg.meanings[j] = fee[i][j];\n                }\n                for (int j = 0; j <= mask; j++) {\n                    maskFee[i][j] = sg.next();\n                }\n            }\n\n            dp = new long[mask + 1];\n            Arrays.fill(dp, -1);\n            dp[0] = 0;\n\n            io.cache.append(dp(mask));\n        }\n\n        BitOperator bo = new BitOperator();\n\n        public long dp(int s) {\n            if (dp[s] == -1) {\n                long extra = 0;\n                int remainSet = mask - s;\n                for (int j = 0; j < m; j++) {\n                    if (bo.bitAt(s, j) == 0) {\n                        continue;\n                    }\n                    extra += maskFee[j][remainSet];\n                }\n\n                dp[s] = lInf;\n                for (int j = 0; j < m; j++) {\n                    if (bo.bitAt(s, j) == 0) {\n                        continue;\n                    }\n                    int ss = bo.setBit(s, j, false);\n                    dp[s] = Math.min(dp[s], extra + dp(ss));\n                }\n            }\n\n            return dp[s];\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        public long swapBit(long x, int i, int j) {\n            int bi = bitAt(x, i);\n            int bj = bitAt(x, j);\n            x = setBit(x, i, bj == 1);\n            x = setBit(x, j, bi == 1);\n            return x;\n        }\n\n        public int swapBit(int x, int i, int j) {\n            int bi = bitAt(x, i);\n            int bj = bitAt(x, j);\n            x = setBit(x, i, bj == 1);\n            x = setBit(x, j, bi == 1);\n            return x;\n        }\n\n        /**\n         * Determine whether x is subset of y\n         */\n        public boolean subset(long x, long y) {\n            return intersect(x, y) == x;\n        }\n\n        /**\n         * Merge two set\n         */\n        public long merge(long x, long y) {\n            return x | y;\n        }\n\n        public long intersect(long x, long y) {\n            return x & y;\n        }\n\n        public long differ(long x, long y) {\n            return x - intersect(x, y);\n        }\n    }\n\n    public static class SubsetGenerator {\n        private int[] meanings = new int[33];\n        private int[] bits = new int[33];\n        private int remain;\n        private int next;\n\n        public void setSet(int set) {\n            int bitCount = 0;\n            while (set != 0) {\n                meanings[bitCount] = set & -set;\n                bits[bitCount] = 0;\n                set -= meanings[bitCount];\n                bitCount++;\n            }\n            remain = 1 << bitCount;\n            next = 0;\n        }\n\n        public boolean hasNext() {\n            return remain > 0;\n        }\n\n        private void consume() {\n            remain = remain - 1;\n            int i;\n            for (i = 0; bits[i] == 1; i++) {\n                bits[i] = 0;\n                next -= meanings[i];\n            }\n            bits[i] = 1;\n            next += meanings[i];\n        }\n\n        public int next() {\n            int returned = next;\n            consume();\n            return returned;\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", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\t//where's my 420??? :(\n\t\t\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "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.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\tlong startTime = System.currentTimeMillis();\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\tEKeyboardPurchase solver = new EKeyboardPurchase();\n\t\t\tsolver.solve(1, in, out);\n\t\t\tout.close();\n\t\t\tSystem.err.println(System.currentTimeMillis()-startTime+\"ms\");\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\n\tstatic class EKeyboardPurchase {\n\t\tprivate final int iinf = 1_000_000_000;\n\n\t\tpublic EKeyboardPurchase() {\n\t\t}\n\n\t\tpublic void solve(int kase, InputReader in, Output pw) {\n\t\t\tint n = in.nextInt(), m = in.nextInt();\n\t\t\tint[] arr = in.nextIntChar(o -> o-'a');\n\t\t\tint[][] sum = new int[m][1<<m];\n\t\t\t{\n\t\t\t\tint[][] cnt = new int[m][m];\n\t\t\t\tfor(int i = 0; i<n-1; i++) {\n\t\t\t\t\tint a = arr[i], b = arr[i+1];\n\t\t\t\t\tcnt[a][b]++;\n\t\t\t\t\tcnt[b][a]++;\n\t\t\t\t}\n\t\t\t\tfor(int i = 0; i<m; i++) {\n\t\t\t\t\tfor(int j = 1; j<1<<m; j++) {\n\t\t\t\t\t\tint x = j&-j;\n\t\t\t\t\t\tsum[i][j] = sum[i][j^x]+cnt[i][31-Integer.numberOfLeadingZeros(x)];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] mbit = new int[1<<m];\n\t\t\tfor(int i = 1; i<1<<m; i++) {\n\t\t\t\tmbit[i] = Integer.numberOfTrailingZeros(i&-i);\n\t\t\t}\n\t\t\tint[] dp = new int[1<<m];\n\t\t\tfor(int i = 1; i<1<<m; i++) {\n\t\t\t\tint ans = iinf, ci = i;\n\t\t\t\tfor(int j = mbit[ci]; ci>0; ci -= (1<<j), j = mbit[ci]) {\n\t\t\t\t\tint cur = dp[i^(1<<j)]+sum[j][i^(1<<j)];\n\t\t\t\t\tint x = ((1<<m)-1)^i;\n\t\t\t\t\tint cm = i;\n\t\t\t\t\tfor(int k = mbit[cm]; cm>0; cm -= (1<<k), k = mbit[cm]) {\n\t\t\t\t\t\tcur += sum[k][x];\n\t\t\t\t\t}\n\t\t\t\t\tcur -= sum[j][x];\n\t\t\t\t\tans = Math.min(ans, cur);\n\t\t\t\t}\n\t\t\t\tdp[i] = ans;\n\t\t\t}\n//\t\tdbg(dp);\n\t\t\tpw.println(dp[dp.length-1]);\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<Character, Integer> f) {\n\t\t\tString s = next();\n\t\t\tint[] ret = new int[s.length()];\n\t\t\tfor(int i = 0; i<s.length(); i++) {\n\t\t\t\tret[i] = f.apply(s.charAt(i));\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\n\t}\n\n\tstatic class FastReader implements InputReader {\n\t\tfinal private int BUFFER_SIZE = 1<<16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer;\n\t\tprivate int bytesRead;\n\n\t\tpublic FastReader(InputStream is) {\n\t\t\tdin = new DataInputStream(is);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder ret = new StringBuilder(64);\n\t\t\tbyte c = skip();\n\t\t\twhile(c!=-1&&!isSpaceChar(c)) {\n\t\t\t\tret.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn ret.toString();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = skipToDigit();\n\t\t\tboolean neg = (c=='-');\n\t\t\tif(neg) {\n\t\t\t\tc = read();\n\t\t\t}\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\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 class Output implements Closeable, Flushable {\n\t\tpublic StringBuilder sb;\n\t\tpublic OutputStream os;\n\t\tpublic int BUFFER_SIZE;\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\tlineSeparator = System.lineSeparator();\n\t\t}\n\n\t\tpublic void println(int i) {\n\t\t\tprintln(String.valueOf(i));\n\t\t}\n\n\t\tpublic void println(String s) {\n\t\t\tsb.append(s);\n\t\t\tprintln();\n\t\t}\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\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "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\tout.println(work());\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tlong work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tString str=in.next();\n\t\tlong[] dp=new long[1<<m];\n\t\tlong[][] cnt=new long[m][m];\n\t\tlong[] rec=new long[1<<m];\t\n   \t        for(int i=1;i<n;i++) {\n\t\t\tint n1=str.charAt(i-1)-'a';\n\t\t\tint n2=str.charAt(i)-'a';\n\t\t\tcnt[n1][n2]++;\n\t\t\tcnt[n2][n1]++;\n\t\t}\n\t\tfor(int i=1;i<1<<m;i++) {\n\t\t\tdp[i]=9999999999L;\n\t\t\tlong v=0;\n\t\t\tint b=0;//\u6700\u4f4e\u4f4d\u76841\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))>0) {\n\t\t\t\t\tb=j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))==0) {\n\t\t\t\t\tv+=cnt[b][j];\n\t\t\t\t}else {\n\t\t\t\t\tif(b!=j)v-=cnt[b][j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tv+=rec[i-(1<<b)];\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))>0) {\n\t\t\t\t\tdp[i]=Math.min(dp[i], dp[i-(1<<j)]+v);\n\t\t\t\t}\n\t\t\t}\n\t\t\trec[i]=v;\n\t\t}\n\t\t\n\t\treturn dp[(1<<m)-1];\n\t}\n}\n \n \n \nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n \n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n \n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n \n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n \n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}\n\n\n\t\t \t\t  \t  \t\t\t \t\t\t\t \t \t    \t\t", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\nimport static java.lang.Math.cos;\nimport static java.lang.Math.min;\n\npublic class E_fast {\n    static int g[][];\n    static int n, m;\n    static char[] s;\n    static int dp[], inf = (int) 2e9;\n    static int cost[][];\n\n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        m = in.nextInt();\n        s = in.next().toCharArray();\n        g = new int[m][m];\n        for (int i = 1; i < n; i++) {\n            int x = s[i - 1] - 'a', y = s[i] - 'a';\n            if (x != y) {\n                g[x][y]++;\n                g[y][x]++;\n            }\n        }\n        cost = new int[m][1 << m];\n        for (int i = 0; i < m; i++) {\n            int w = 0;\n            for (int j = 0; j < m; j++) w += g[i][j];\n            pre(i, 0, 0, -w);\n        }\n        dp = new int[1 << m];\n        Arrays.fill(dp, -1);\n        pw.println(solve(0, 0));\n\n        pw.close();\n    }\n\n    static void pre(int x, int pos, int mask, int w) {\n        if (pos >= m) {\n            cost[x][mask] = w;\n            return;\n        }\n        pre(x, pos + 1, mask, w);\n        pre(x, pos + 1, set(mask, pos), w + 2 * g[x][pos]);\n    }\n\n    static int solve(int pos, int mask) {\n        if (pos >= m) return 0;\n        if (dp[mask] != -1) return dp[mask];\n        int min = inf;\n        for (int i = 0; i < m; i++) {\n            if (!check(mask, i)) {\n                int res = cost[i][mask] * pos + solve(pos + 1, set(mask, i));\n                min = min(min, res);\n            }\n        }\n        return dp[mask] = min;\n    }\n\n    static boolean check(int N, int pos) {\n        return (N & (1 << pos)) != 0;\n    }\n\n    static int set(int N, int pos) {\n        return N = N | (1 << pos);\n    }\n\n    static int reset(int N, int pos) {\n        return N = N & ~(1 << pos);\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\t//where's my 420???? :(\n\t\tlong tot = 0;\n\t\tfor(int i = 0; i < 20000; i++) tot += i;\n\t\tSystem.err.println(tot);\n\t\t\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\npublic class EdA {\n\tstatic long[] mods = {1000000007, 998244353, 1000000009};\n\tstatic long mod = mods[0];\n\tpublic static MyScanner sc;\n    public static PrintWriter out;\n\n\tpublic static void main(String[] omkar) throws Exception{\n\t\t// TODO Auto-generated method stub\n \t\tsc = new MyScanner();\n \t\tout = new PrintWriter(System.out);\n \t\t\n\t \tint n = sc.nextInt();\n\t \tint m = sc.nextInt();\n\t \tint[][]cnt = new int[m][m];\n\t \tString s = sc.next();\n\t \tfor(int j =0;j<n-1;j++){\n\t \t\tif (s.charAt(j) != s.charAt(j+1)){\n\t \t\tcnt[s.charAt(j)-'a'][s.charAt(j+1)-'a']++;\n\t \t\tcnt[s.charAt(j+1)-'a'][s.charAt(j)-'a']++;\n\t \t\t}\n\t \t}\n\t \tint[] st = new int[m+1];\n\t \tfor(int j = 0;j<=m;j++){\n\t \t\tst[j] = (1<<j);\n\t \t}\n\t \tint[][] arr = new int[m][1<<m];\n\t \tfor(int j = 0;j<m;j++){\n\t \t\tfor(int k = 1;k<(1<<m);k++){\n\t \t\t\tint z = Integer.lowestOneBit(k);\n\t \t\t\tint count = 0;\n\t \t\t\twhile(z!=0 && z%2==0){\n\t \t\t\t\tz/=2;\n\t \t\t\t\tcount++;\n\t \t\t\t}\n\t \t\t\tarr[j][k] = arr[j][k^(Integer.lowestOneBit(k))] + cnt[j][count];\n\t \t\t}\n\t \t}\n\t \tint[] dp = new int[1<<m];\n\t \tArrays.fill(dp,  Integer.MAX_VALUE);\n\t \tdp[0] = 0;\n\t \tfor(int j = 1;j<st[m];j++){\n\t \t\t\n\t \t\tfor(int k = 0;k<m;k++){\n\t \t\t\tint y = st[k];\n\t \t\t\tif ((y&j) != 0){\n\t \t\t\t\tint sum = 2*arr[k][j] - arr[k][(1<<m)-1];\n//\t \t\t\t\tfor(int t = 0;t<m;t++){\n//\t \t\t\t\t\tif (t!= k){\n//\t\t \t\t\t\t\tif ((st[t]&j) != 0)\n//\t\t \t\t\t\t\t\tsum+=cnt[t][k];\n//\t\t \t\t\t\t\telse\n//\t\t \t\t\t\t\t\tsum-=cnt[t][k];\n//\t \t\t\t\t\t}\n//\t \t\t\t\t}\n\t \t\t\t\tdp[j] = Math.min(dp[j],  dp[y^j]+sum*Integer.bitCount(j));\n\t \t\t\t}\n\t \t\t}\n\t \t}\n\t \tout.println(dp[(1<<m)-1]);\n \t\tout.close();\t\n \t}\n\tpublic static void sort(int[] array){\n\t\tArrayList<Integer> copy = new ArrayList<Integer>();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i<array.length;i++)\n\t\t\tarray[i] = copy.get(i);\n\t}\n\tstatic String[] readArrayString(int n){\n\t\tString[] array = new String[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.next();\n\t\treturn array;\n\t}\n\tstatic int[] readArrayInt(int n){\n    \tint[] array = new int[n];\n    \tfor(int j = 0;j<n;j++)\n    \t\tarray[j] = sc.nextInt();\n    \treturn array;\n    }\n\tstatic int[] readArrayInt1(int n){\n\t\tint[] array = new int[n+1];\n\t\tfor(int j = 1;j<=n;j++){\n\t\t\tarray[j] = sc.nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\tstatic long[] readArrayLong(int n){\n\t\tlong[] array = new long[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextLong();\n\t\treturn array;\n\t}\n\tstatic double[] readArrayDouble(int n){\n\t\tdouble[] array = new double[n];\n\t\tfor(int j =0 ;j<n;j++)\n\t\t\tarray[j] = sc.nextDouble();\n\t\treturn array;\n\t}\n\tstatic int minIndex(int[] array){\n\t\tint minValue = Integer.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(long[] array){\n\t\tlong minValue = Long.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic int minIndex(double[] array){\n\t\tdouble minValue = Double.MAX_VALUE;\n\t\tint minIndex = -1;\n\t\tfor(int j = 0;j<array.length;j++){\n\t\t\tif (array[j] < minValue){\n\t\t\t\tminValue = array[j];\n\t\t\t\tminIndex = j;\n\t\t\t}\n\t\t}\n\t\treturn minIndex;\n\t}\n\tstatic long power(long x, long y){\n\t\tif (y == 0)\n\t\t\treturn 1;\n\t\tif (y%2 == 1)\n\t\t\treturn (x*power(x, y-1))%mod;\n\t\treturn power((x*x)%mod, y/2)%mod;\n\t}\n\tstatic void verdict(boolean a){\n        out.println(a ? \"YES\" : \"NO\");\n    }\n    public static class MyScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        public MyScanner() {\n            br = new BufferedReader(new InputStreamReader(System.in));\n        }\n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } \n                catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        String nextLine() {\n            String str = \"\";\n            try{\n                str = br.readLine();\n            } \n            catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n        \n    }\t\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", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tstr = fs.next().toCharArray();\n\t\toccs = new int[m][m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\toccs[str[i]-'a'][str[i+1]-'a']++;\n\t\t\toccs[str[i+1]-'a'][str[i]-'a']++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[i][trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tArrays.fill(dp, -1);\n\t\tSystem.out.println(solve(0));\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint solve(int mask) {\n\t\tif(mask == (1<<m)-1) return 0;\n\t\tif(dp[mask] != -1) return dp[mask];\n\t\tint res = oo;\n\t\t\n\t\tint addOn = 0;\n\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\taddOn += cost[nxt][mask];\n\t\t}\n\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\tint ret = addOn+solve(mask | (1<<nxt));\n\t\t\tres = Math.min(res, ret);\n\t\t}\n\t\t\n\t\treturn dp[mask] = res;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\t//where's my 420???? :(\n\t\t\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n \npublic class Main {\n\tstatic int t,m,mod=998244353,maxn=1000000,q,n,k;\n    static int INF=(int)1e8;\n    \n    void solve(PrintWriter out, Reader in) throws IOException{\n        n = in.nextInt();\n        m = in.nextInt();\n        \n        String str = in.next();\n        int[][] pre = new int[1<<m][m];\n        \n        int child=0,head,child2=0;\n        for(int i=0;i<n;i++){\n            if(i!=0) child = 1<<(str.charAt(i-1)-'a');\n            if(i!=n-1) child2 = 1<<(str.charAt(i+1)-'a');\n            head = str.charAt(i)-'a';\n            \n            if(i!=0) pre[child][head]++;\n            if(i!=n-1) pre[child2][head]++;\n        }\n        \n        //pre[child][head] - number of elemnts that exists in child and are adjacent to head in the string.\n        \n        int rmv=0;\n        for(int i=0;i<m;i++){\n            head = i;\n            for(int j=1;j<1<<m;j++){\n                if(pre[j][i]!=0) continue;\n                \n                rmv = j-(j&-j);\n                pre[j][head] = pre[rmv][head]+pre[j^rmv][head];\n            }\n        }\n        \n        \n        int[] dp = new int[1<<m];\n        for(int i=1;i<1<<m;i++) dp[i] = INF;\n        \n        // dp[mask] - the minimum cost using a permutation of the set bits in the mask.\n        \n        int bit=0,full=(1<<m)-1,cnt=0;\n        for(int j=1;j<1<<m;j++){\n            for(int i=0;i<m;i++){\n                if(((1<<i)&j)!=0){\n                    bit = 1<<i;\n                    cnt = cnt(j);\n                    dp[j] = Math.min(dp[j],dp[j^bit]+pre[j^bit][i]*cnt-pre[j^full][i]*cnt);\n                }\n            }\n        }\n        \n        out.println(dp[full]);\n    }\n    \n    \n    \n    \n    static int cnt(int x){\n        int res=0;\n        while(x>0){\n            res+=x&1;\n            x>>=1;\n        }\n        return res;\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    public static void main(String[] args) throws IOException {\n        PrintWriter out = new PrintWriter(System.out);\n        Reader in = new Reader();\n        Main solver = new Main();\n        solver.solve(out, in);\n        out.flush();\n        out.close();\n \n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\t//where's my 420???? :(\n\t\tlong tot = 0;\n\t\tfor(int i = 0; i < 20000; i++) tot += i;\n\t\t\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class KeyboardPurchase {\n    static final int INF = 1000000000;\n    public static void main(String[] args) {\n        InputReader in = new InputReader(System.in);\n        PrintWriter out = new PrintWriter(System.out, false);\n        int N = in.nextInt(), M = in.nextInt();\n        String str = in.next();\n        int[][] count = new int[M][M];\n        for (int i = 1; i < N; i++) {\n            char c1 = str.charAt(i - 1), c2 = str.charAt(i);\n            count[c1 - 'a'][c2 - 'a']++;\n            count[c2 - 'a'][c1 - 'a']++;\n        }\n        int[] dp = new int[(1 << M)];\n        Arrays.fill(dp, INF);\n        dp[0] = 0;\n        for (int mask = 1; mask < (1 << M); mask++) {\n            int slow = 0;\n            for (int i = 0; i < M; i++) {\n                if ((mask & (1 << i)) != 0) {\n                    for (int j = 0; j < M; j++) {\n                        if ((mask & (1 << j)) == 0) {\n                            slow += count[i][j];\n                        }\n                    }\n                }\n            }\n            for (int i = 0; i < M; i++) {\n                if ((mask & (1 << i)) != 0) {\n                    dp[mask] = Math.min(dp[mask], slow + dp[mask ^ (1 << i)]);\n                }\n            }\n        }\n        out.println(dp[(1 << M) - 1]);\n        out.close();\n        System.exit(0);\n    }\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.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        public double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        public String nextLine() {\n            String str = \"\";\n            try {\n                str = reader.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class thing {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\t\n\t\tString s = in.next();\n\t\t\n\t\tint[][] count = new int[m][m];\n\t\tint[] dp = new int[1 << m];\n\t\t\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\t\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tint a = s.charAt(i)-'a';\n\t\t\tint b = s.charAt(i-1)-'a';\n\t\t\tcount[a][b]++;\n\t\t\tcount[b][a]++;\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < (1 << m); i++) {\n\t\t\t\n\t\t\tint pos = set_bits(i);\n\t\t\t\n\t\t\tfor(int j = 0; (i >> j) != 0; j++) {\n\t\t\t\t\n\t\t\t\tif(((i >> j) & 1) == 0) continue;\n\t\t\t\t\n\t\t\t\tint sum = 0;\n\t\t\t\t\n\t\t\t\tfor(int mask = i, y = 0; y < m; mask >>= 1, y++) {\n\t\t\t\t\tif(y == j) continue;\n\t\t\t\t\tif((mask & 1) == 1) sum += count[j][y];\n\t\t\t\t\telse sum -= count[j][y];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint calc = dp[i-(1<<j)] + pos*sum;\n\t\t\t\t\n\t\t\t\tdp[i] = Math.min(dp[i], calc);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[(1 << m)-1]);\n\t\t\n\t}\n\t\n\tpublic static int set_bits(int n) { \n\t\tint count = 0; \n\t\twhile (n > 0) {\n\t\t\tcount += n & 1;\n\t\t\tn >>= 1; \n\t\t}\n\t\treturn count;\n\t}\n\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\npublic class cfe {\n\tstatic DataReader input;\n\tstatic int LARGE_INT = 1000000007;\n\t//static int MAXN = 300000;\n\t//static int[] len = new int[300000];\n\t//static int[] price = new int[300000];\n\tstatic final int[] BM =  {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, \n\t                          1<<17, 1<<18, 1<<19, 1<<20};\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t    input = new DataReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = nextInt(), M = nextInt(), P = 1<<M;\n\t\tString x = nextStr();\n\t\tint c1 = x.charAt(0) - 'a';\n\t\tint[][] pair_count = new int[M][M];\n\t\tfor (int i=1; i<N; i++) {\n\t\t\tint c2 = x.charAt(i) - 'a';\n\t\t\tif (c1 < c2) \n\t\t\t\tpair_count[c1][c2]++;\n\t\t\telse if (c1 > c2)\n\t\t\t\tpair_count[c2][c1]++;\n\t\t\tc1 = c2;\n\t\t}\n\t\tint[] group_count = new int[P];\n\t\tfor (int mask = 1; mask <P; mask++) {\n\t\t\tint j;\n\t\t\tfor (j=0; j<M; j++) {\n\t\t\t\tif ((mask & BM[j]) > 0)  break;\n\t\t\t}\n\t\t\tint nmask = mask ^ BM[j];\n\t\t\tint val = group_count[nmask];\n\t\t\tfor (int i=0; i<j; i++) {\n\t\t\t\tif ((mask & BM[i]) > 0)  val -= pair_count[i][j];\n\t\t\t\telse                   val += pair_count[i][j];\n\t\t\t}\n\t\t\tfor (int i=j+1; i<M; i++) {\n\t\t\t\tif ((mask & BM[i]) > 0)  val -= pair_count[j][i];\n\t\t\t\telse                   val += pair_count[j][i];\n\t\t\t}\n\t\t\tgroup_count[mask] = val;\n\t\t}\n\t\t// dp[k][mask] = Accumulated cost of first K positions filled, mask position 1 letters are used\n\t\t// dp[0][0] = 0;\n\t\tint[][] dp = new int[M+1][P];\t   // \n\t\tfor (int mask=1; mask<P; mask++) {  // each bit mask\n\t\t\tdp[0][mask] = 0;\n\t\t\tint k = Integer.bitCount(mask);  // computing first k position filled.\n\t\t\tint val = LARGE_INT;\n\t\t\tfor (int j=0; j<M; j++) {\n\t\t\t\tif ((mask & BM[j]) > 0) {\n\t\t\t\t\tint nmask = mask ^ BM[j];\n\t\t\t\t\tval = Math.min(val, dp[k-1][nmask] + group_count[nmask]);\n\t\t\t\t}\t\t\t\t\n\t\t\t}\n\t\t\tdp[k][mask] = val;\n\t\t}\n\t\t//out.println(Arrays.deepToString(dp));\n\t\tout.println(dp[M][P-1]);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\tstatic int nextInt() throws IOException {\n        return Integer.parseInt(input.next()); \n    } \n\tstatic String nextStr() throws IOException {\n        return input.next(); \n    } \n    static class DataReader { \n        BufferedReader br; \n        StringTokenizer st;\n        public DataReader() throws IOException {\t// reading from standard in\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n        } \n\t\tboolean hasNext() throws IOException { \n            while (st == null || !st.hasMoreElements()) {\n\t\t\t\tString line = br.readLine();\n\t\t\t\tif (line == null) { // end of file\n\t\t\t\t\treturn false;\n\t\t\t\t}\n                st = new StringTokenizer(line); \n            }\n\t\t\treturn true;\n\t\t}\n        String next() throws IOException { \n\t\t\tif (hasNext())\n\t\t\t\treturn st.nextToken(); \n\t\t\telse\n\t\t\t\treturn null;\n        } \n    } \n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class E {\n    public static void main(String[] args) {\n        FastScanner scanner = new FastScanner();\n        PrintWriter out = new PrintWriter(System.out, false);\n        int n = scanner.nextInt();\n        int m = scanner.nextInt();\n        char[] str = scanner.next().toCharArray();\n        int maxMask = 1 << m;\n        long[] dp = new long[maxMask];\n        int[][] dists = new int[m][m];\n        for(int i = 1; i < n; i++) {\n            int c1 = str[i] - 'a';\n            int c2 = str[i-1] - 'a';\n            dists[c1][c2]++;\n            dists[c2][c1]++;\n        }\n        int[] pre = new int[maxMask];\n        for(int mask = 0; mask < maxMask; mask++) {\n            for(int i = 0; i < m; i++) {\n                if (((1 << i) & mask) == 0) continue;\n                for(int j = 0; j < m; j++) {\n                    if (((1 << j) & mask) > 0) continue;\n                    pre[mask] += dists[i][j];\n                }\n            }\n        }\n        Arrays.fill(dp, Long.MAX_VALUE/4);\n        dp[0] = 0;\n        for(int mask = 0; mask < maxMask; mask++) {\n            if (dp[mask] == Long.MAX_VALUE/4) continue;\n            for(int i = 0; i < m; i++) {\n                if (((1 << i) & mask) > 0) continue;\n                int nmask = mask | (1 << i);\n                dp[nmask] = Math.min(dp[nmask], dp[mask] + pre[nmask]);\n            }\n        }\n        out.println(dp[maxMask - 1]);\n        out.flush();\n    }\n    \n    public static class FastScanner {\n        BufferedReader br;\n        StringTokenizer st;\n        \n        public FastScanner(Reader in) {\n            br = new BufferedReader(in);\n        }\n        \n        public FastScanner() {\n            this(new InputStreamReader(System.in));\n        }\n        \n        String next() {\n            while (st == null || !st.hasMoreElements()) {\n                try {\n                    st = new StringTokenizer(br.readLine());\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n            return st.nextToken();\n        }\n        \n        int nextInt() {\n            return Integer.parseInt(next());\n        }\n        \n        long nextLong() {\n            return Long.parseLong(next());\n        }\n        \n        double nextDouble() {\n            return Double.parseDouble(next());\n        }\n        \n        String readNextLine() {\n            String str = \"\";\n            try {\n                str = br.readLine();\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n            return str;\n        }\n    }\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class E\n{\n\tpublic static void main(String[] args) throws IOException\n\t{new E();}\n\t\n\tFastScanner in = new FastScanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\t\n\tint n, m, oo = 1 << 28;\n\tint[] dp, cost;\n\tint[][] to;\n\tchar[] w;\n\t\n\tE() throws IOException\n\t{\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tw = in.next().toCharArray();\n\t\tto = new int[m+1][m+1];\n\t\tfor (int i = 0; i < n-1; i++)\n\t\t\tif (w[i] != w[i+1])\n\t\t\t{\n\t\t\t\tto[w[i]-'a'][w[i+1]-'a']++;\n\t\t\t\tto[w[i+1]-'a'][w[i]-'a']++;\n\t\t\t}\n\n\t\tcost = new int[1 << m];\t\n\t\tfor (int i = 0; i < (1 << m); i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tif (((1 << j) & i) > 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int k = 0; k < m; k++)\n\t\t\t\t{\n\t\t\t\t\tif (((1 << k) & i) == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcost[i] += to[j][k];\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\tdp = new int[1 << m];\n\t\tArrays.fill(dp, oo);\n\t\tdp[0] = 0;\n\t\tfor (int i = 1; i < (1 << m); i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (((i >> j) & 1) > 0)\n\t\t\t\t\tdp[i] = Math.min(dp[i], dp[i ^ (1 << j)]);\n\t\t\tdp[i] += cost[i];\n\t\t}\n\t\tout.println(dp[(1 << m)-1]);\n\t\tout.close();\t\n\t}\n\t\n\tvoid sort(int[] x)\n\t{\n\t\tint sz = x.length;\n\t\tRandom r = new Random();\n\t\tfor (int i = 0; i < sz; i++)\n\t\t{\n\t\t\tint j = r.nextInt(sz);\n\t\t\tx[i] = x[j]-(x[i]-(x[j] = x[i]));\n\t\t}\n\t\tArrays.sort(x);\n\t}\n\t\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(InputStream i) {\n\t\t    br = new BufferedReader(new InputStreamReader(i));\n\t\t    st = new StringTokenizer(\"\");\n\t\t}\t\t\n\t\tpublic String next() throws IOException {\n\t\t    if(st.hasMoreTokens())\n\t\t        return st.nextToken();\n\t\t    else\n\t\t        st = new StringTokenizer(br.readLine());\n\t\t    return next();\n\t\t}\n\t\tpublic int nextInt() throws IOException {\n\t\t    return Integer.parseInt(next());\n\t\t}\n\t\tpublic int[] intarr(int n) throws IOException {\n\t\t\tint[] res = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tres[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t    public long nextLong() throws IOException {\n\t\t    return Long.parseLong(next());\n\t\t}\n\t\tpublic double nextDouble() throws IOException {\n\t\t    return Double.parseDouble(next());\n\t\t}\n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1238E extends PrintWriter {\n\tCF1238E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1238E o = new CF1238E(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tbyte[] cc = sc.next().getBytes();\n\t\tint[] kk = new int[1 << m];\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint a = cc[i - 1] - 'a';\n\t\t\tint b = cc[i] - 'a';\n\t\t\tkk[1 << a | 1 << b]++;\n\t\t}\n\t\tfor (int h = 0; h < m; h++)\n\t\t\tfor (int b = 0; b < 1 << m; b++)\n\t\t\t\tif ((b & 1 << h) == 0)\n\t\t\t\t\tkk[b | 1 << h] += kk[b];\n\t\tint[] dp = new int[1 << m];\n\t\tint m_ = (1 << m) - 1;\n\t\tfor (int b = 1; b < 1 << m; b++) {\n\t\t\tint k = n - 1 - kk[b] - kk[m_ ^ b];\n\t\t\tint x = INF;\n\t\t\tfor (int h = 0; h < m; h++)\n\t\t\t\tif ((b & 1 << h) != 0) {\n\t\t\t\t\tint b_ = b ^ 1 << h;\n\t\t\t\t\tx = Math.min(x, dp[b_]);\n\t\t\t\t}\n\t\t\tdp[b] = x == INF ? INF : x + k;\n\t\t}\n\t\tprintln(dp[m_]);\n\t}\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.BufferedWriter;\nimport java.io.DataInputStream;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.nio.file.Paths;\nimport java.util.Arrays;\n\npublic class E {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tFastPrinter out = new FastPrinter(System.out);\n\t\tE runner = new E();\n\t\trunner.run(sc, out);\n\t\tout.close();\n\t}\n\n\tint N, L;\n\tlong[][] mat;\n\tlong[] dp;\n\n\tpublic void run(FastScanner sc, FastPrinter out) throws Exception {\n\t\tL = sc.nextInt();\n\t\tN = sc.nextInt();\n\t\tmat = new long[N][N];\n\t\tchar[] arr = sc.next().toCharArray();\n\t\tfor (int i = 0; i < L - 1; i++) {\n\t\t\tint cur = arr[i] - 'a';\n\t\t\tint next = arr[i + 1] - 'a';\n\t\t\tif (cur != next) {\n\t\t\t\tmat[cur][next]++;\n\t\t\t\tmat[next][cur]++;\n\t\t\t}\n\t\t}\n\t\tdp = new long[1 << N];\n\t\tArrays.fill(dp, -1);\n\t\tdp[(1 << N) - 1] = 0;\n\t\tlong ans = solve(0);\n\t\tout.println(ans);\n\t}\n\n\tprivate long solve(int mask) {\n\t\tif (dp[mask] == -1) {\n\t\t\tlong value = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\t\tfor (int j = 0; j < N; j++) {\n\t\t\t\t\t\tif ((mask & (1 << j)) != 0) {\n\t\t\t\t\t\t\tvalue += mat[i][j];\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\tlong ans = Long.MAX_VALUE;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tif ((mask & (1 << i)) == 0) {\n\t\t\t\t\tlong temp = solve(mask | 1 << i);\n\t\t\t\t\tif (temp < ans) {\n\t\t\t\t\t\tans = temp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tans += value;\n\t\t\tdp[mask] = ans;\n\t\t}\n\t\treturn dp[mask];\n\t}\n\n\tpublic void shuffle(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tint r = (int) (Math.random() * arr.length);\n\t\t\tif (i != r) {\n\t\t\t\tarr[i] ^= arr[r];\n\t\t\t\tarr[r] ^= arr[i];\n\t\t\t\tarr[i] ^= arr[r];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class FastScanner {\n\t\tfinal private int BUFFER_SIZE = 1 << 10;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic FastScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tdin = new DataInputStream(stream);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic FastScanner(String fileName) throws IOException {\n\t\t\tPath p = Paths.get(fileName);\n\t\t\tbuffer = Files.readAllBytes(p);\n\t\t\tbytesRead = buffer.length;\n\t\t}\n\n\t\tint[] 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\tString nextLine() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (c != -1 && isEndline(c))\n\t\t\t\tc = read();\n\t\t\tif (c == -1) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tif (c >= 0) {\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t}\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\tboolean isEndline(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tString next() throws Exception {\n\t\t\tint c = readOutSpaces();\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\tboolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg) c = 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) return -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) c = 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) return -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) c = 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) return -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tif (din == null) {\n\t\t\t\tbufferPointer = 0;\n\t\t\t\tbytesRead = -1;\n\t\t\t} else {\n\t\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\t}\n\t\t\tif (bytesRead == -1) buffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead) fillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tprivate int readOutSpaces() throws IOException {\n\t\t\twhile (true) {\n\t\t\t\tif (bufferPointer == bytesRead) fillBuffer();\n\t\t\t\tint c = buffer[bufferPointer++];\n\t\t\t\tif (!isSpaceChar(c)) {\n\t\t\t\t\treturn c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null) return;\n\t\t\tdin.close();\n\t\t}\n\n\t\tpublic int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {\n\t\t\tint[][] adj = new int[N][];\n\t\t\tint[] numNodes = new int[N];\n\t\t\tint[][] input = new int[M][2];\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = nextInt();\n\t\t\t\tint b = nextInt();\n\t\t\t\tif (zeroIndexed) {\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tinput[i][0] = a;\n\t\t\t\tinput[i][1] = b;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) numNodes[b]++;\n\t\t\t}\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tadj[i] = new int[numNodes[i]];\n\t\t\t\tnumNodes[i] = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = input[i][0];\n\t\t\t\tint b = input[i][1];\n\t\t\t\tadj[a][numNodes[a]++] = b;\n\t\t\t\tif (bidirectional) adj[b][numNodes[b]++] = a;\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\n\t\tpublic int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {\n\t\t\tint[][][] adj = new int[N][][];\n\t\t\tint[] numNodes = new int[N];\n\t\t\tint[][] input = new int[M][3];\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = nextInt();\n\t\t\t\tint b = nextInt();\n\t\t\t\tif (zeroIndexed) {\n\t\t\t\t\ta--;\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tint d = nextInt();\n\t\t\t\tinput[i][0] = a;\n\t\t\t\tinput[i][1] = b;\n\t\t\t\tinput[i][2] = d;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) numNodes[b]++;\n\t\t\t}\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tadj[i] = new int[numNodes[i]][2];\n\t\t\t\tnumNodes[i] = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++) {\n\t\t\t\tint a = input[i][0];\n\t\t\t\tint b = input[i][1];\n\t\t\t\tint d = input[i][2];\n\t\t\t\tadj[a][numNodes[a]][0] = b;\n\t\t\t\tadj[a][numNodes[a]][1] = d;\n\t\t\t\tnumNodes[a]++;\n\t\t\t\tif (bidirectional) {\n\t\t\t\t\tadj[b][numNodes[b]][0] = a;\n\t\t\t\t\tadj[b][numNodes[b]][1] = d;\n\t\t\t\t\tnumNodes[b]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\t}\n\n\tstatic class FastPrinter {\n\t\tstatic final char ENDL = '\\n';\n\t\tStringBuilder buf;\n\t\tPrintWriter pw;\n\n\t\tpublic FastPrinter(OutputStream stream) {\n\t\t\tbuf = new StringBuilder();\n\t\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));\n\t\t}\n\n\t\tpublic FastPrinter(String fileName) throws Exception {\n\t\t\tbuf = new StringBuilder();\n\t\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));\n\t\t}\n\n\t\tpublic FastPrinter(StringBuilder buf) {\n\t\t\tthis.buf = buf;\n\t\t}\n\n\t\tpublic void print(int a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(long a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(char a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(char[] a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(double a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(String a) {\n\t\t\tbuf.append(a);\n\t\t}\n\n\t\tpublic void print(Object a) {\n\t\t\tbuf.append(a.toString());\n\t\t}\n\n\t\tpublic void println() {\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(int a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(long a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(char a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(char[] a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(double a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(String a) {\n\t\t\tbuf.append(a);\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void println(Object a) {\n\t\t\tbuf.append(a.toString());\n\t\t\tbuf.append(ENDL);\n\t\t}\n\n\t\tpublic void printf(String format, Object... args) {\n\t\t\tbuf.append(String.format(format, args));\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tpw.print(buf);\n\t\t\tpw.close();\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\tpw.print(buf);\n\t\t\tpw.flush();\n\t\t\tbuf.setLength(0);\n\t\t}\n\n\t}\n\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "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\tout.println(work());\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tlong work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tString str=in.next();\n\t\tlong[] dp=new long[1<<m];\n\t\tlong[][] cnt=new long[m][m];\n\t\tfor(int i=1;i<n;i++) {\n\t\t\tint n1=str.charAt(i-1)-'a';\n\t\t\tint n2=str.charAt(i)-'a';\n\t\t\tcnt[n1][n2]++;\n\t\t\tcnt[n2][n1]++;\n\t\t}\n\t\tfor(int i=1;i<1<<m;i++) {\n\t\t\tdp[i]=9999999999L;\n\t\t\tlong v=0;\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))>0) {//\u7b2cj\u4e2a\u5b57\u6bcd\n\t\t\t\t\tfor(int k=0;k<m;k++) {\n\t\t\t\t\t\tif((i&(1<<k))==0) {\n\t\t\t\t\t\t\tv+=cnt[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\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))>0) {\n\t\t\t\t\tdp[i]=Math.min(dp[i], dp[i-(1<<j)]+v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn dp[(1<<m)-1];\n\t}\n}\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt(),m=sc.nextInt();int g[]=new int[1<<m];\n\t\tStringBuffer s=new StringBuffer(sc.next());\n\t\ts=s.insert(0, 'A');\n\t\tint D=(1<<m)-1;\n\t\tfor(int i=1;i<n;i++)\n\t\t{\n\t\t\tint x=s.charAt(i)-'a',y=s.charAt(i+1)-'a';\n\t\t\tif(x!=y)\n\t\t\t\tg[1<<x|1<<y]++;\n\t\t}\n\t\tfor(int j=0;j<m;j++)\n\t\t\tfor(int i=0;i<=D;i++)\n\t\t\t\tif((i>>j&1)!=0)\n\t\t\t\t\tg[i]+=g[i^1<<j];\n\t\tint f[]=new int[1<<m];\n\t\tArrays.fill(f, Integer.MAX_VALUE/2);\n\t\tf[0]=0;\n\t\tfor(int i=0;i<=D;i++)\n\t\t\tfor(int j=0;j<m;j++)\n\t\t\t\tif((i>>j&1)==0)\n\t\t\t\t\tf[i|1<<j]=Math.min(f[i|1<<j], f[i]+g[D]-g[i]-g[D^i]);\n\t\tSystem.out.println(f[D]);\n\t}\n\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\t//where's my 420???? :(\n\t\tlong tot = 0;\n\t\tfor(int i = 0; i < 19000; i++) tot += i;\n\t\tSystem.err.println(tot);\n\t\t\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class thing {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\t\n\t\tString s = in.next();\n\t\t\n\t\tint[][] count = new int[m][m];\n\t\tint[] dp = new int[1 << m];\n\t\t\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\t\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tint a = s.charAt(i)-'a';\n\t\t\tint b = s.charAt(i-1)-'a';\n\t\t\tcount[a][b]++;\n\t\t\tcount[b][a]++;\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < (1 << m); i++) {\n\t\t\t\n\t\t\tint pos = set_bits(i);\n\t\t\t\n\t\t\tfor(int j = 0; (i >> j) != 0; j++) {\n\t\t\t\t\n\t\t\t\tif(((i >> j) & 1) == 0) continue;\n\t\t\t\t\n\t\t\t\tint sum = 0;\n\t\t\t\t\n\t\t\t\tfor(int mask = i, y = 0; y < m; mask >>= 1, y++) {\n\t\t\t\t\tif(y == j) continue;\n\t\t\t\t\tif((mask & 1) == 1) sum += count[j][y];\n\t\t\t\t\telse sum -= count[j][y];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint calc = dp[i-(1<<j)] + pos*sum;\n\t\t\t\t\n\t\t\t\tdp[i] = Math.min(dp[i], calc);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[(1 << m)-1]);\n\t\t\n\t}\n\t\n\tpublic static int set_bits(int n) { \n\t\tint count = 0; \n\t\twhile (n > 0) {\n\t\t\tcount += n & 1;\n\t\t\tn >>= 1; \n\t\t}\n\t\treturn count;\n\t}\n\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tstatic long mod = 1000000007;\n\tstatic int INF = 1000000000;\n \tpublic static void main(String[] args){\n\t\tFastScanner scanner = new FastScanner();\n\t\tint n = scanner.nextInt();\n\t\tint m = scanner.nextInt();\n\t\tString s = scanner.next();\n\t\tint[][] cnt = new int[20][20];\n\t\tfor(int i = 0; i < n-1; i++){\n\t\t\tcnt[s.charAt(i)-'a'][s.charAt(i+1)-'a']++;\n\t\t\tcnt[s.charAt(i+1)-'a'][s.charAt(i)-'a']++;\n\t\t}\n\t\t//dp[i]:= \u6587\u5b57\u5217i(\u3053\u306e\u4e2d\u306b\u540c\u4e00\u6587\u5b57\u306f\u542b\u307e\u308c\u306a\u3044)\u3092\u4f5c\u3063\u305f\u6642\u306e\u30b3\u30b9\u30c8\u306e\u6700\u5c0f\u5024\n\t\tint[] dp = new int[(1<<m)];\n\t\tfor(int i = 0; i < (1<<m); i++){\n\t\t\tdp[i] = INF;\n\t\t}\n\t\tdp[0] = 0;\n\t\tfor(int i = 0; i < (1<<m); i++){\n\t\t\tint cost = 0;\n\t\t\tfor(int j = 0; j < m; j++){\n\t\t\t\tif((i>>j & 1) == 0){\n\t\t\t\t\tfor(int k = 0; k < m; k++){\n\t\t\t\t\t\tif((~i>>k & 1) == 0){\n\t\t\t\t\t\t\tcost += cnt[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\tfor(int j = 0; j < m; j++){\n\t\t\t\tdp[i|1<<j] = Math.min(dp[i|1<<j],dp[i]+cost);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(dp[(1<<m)-1]);\n\t}\n\tstatic class BIT{\n\t\tint n;\n\t\tint[] bit;\n\t\tpublic BIT(int n){\n\t\t\tthis.n = n;\n\t\t\tbit = new int[n+1];\n\t\t}\n\t\tvoid add(int idx, int val){\n\t\t\tfor(int i = idx+1; i <= n; i += i&(-i)) bit[i-1] += val;\n\t\t}\n\t\tint sum(int idx){\n\t\t\tint res = 0;\n\t\t\tfor(int i = idx+1; i > 0; i -= i&(-i)) res += bit[i-1];\n\t\t\treturn res;\n\t\t}\n\t\tint sum(int begin, int end){\n\t\t\tif(begin == 0) return sum(end);\n\t\t\treturn sum(end)-sum(begin-1);\n\t\t}\n\t}\n\tstatic class Pair implements Comparable<Pair>{\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\t\t    //return first * 1.0 / second > p.first * 1.0 / p.second ? 1 : -1; // first/second\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\n\t\t    //return first * 1.0 / second < p.first * 1.0 / p.second ? 1 : -1; // first/second\u306e\u964d\u9806\u306b\u30bd\u30fc\u30c8\n\t\t\t\t//return second * 1.0 / first > p.second * 1.0 / p.first ? 1 : -1; // second/first\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\n\t\t    //return second * 1.0 / first < p.second * 1.0 / p.first ? 1 : -1; // second/first\u306e\u964d\u9806\u306b\u30bd\u30fc\u30c8\n\t\t\t\t//return Math.atan2(second, first) > Math.atan2(p.second, p.first) ? 1 : -1; // second/first\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\n\t\t\t\t//return first + second > p.first + p.second ? 1 : -1; //first+second\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\n\t\t\t\t//return first + second < p.first + p.second ? 1 : -1; //first+second\u306e\u964d\u9806\u306b\u30bd\u30fc\u30c8\n\t\t\t\t//return first - second < p.first - p.second ? 1 : -1; //first-second\u306e\u964d\u9806\u306b\u30bd\u30fc\u30c8\n\t\t}\n  }\n\n\tprivate static class FastScanner {\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\t\tif (ptr < buflen) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t}else{\n\t\t\t\t\t\tptr = 0;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tbuflen = in.read(buffer);\n\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (buflen <= 0) {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t}\n\t\tprivate int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n\t\tprivate static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n\t\tpublic boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}\n\t\tpublic String next() {\n\t\t\t\tif (!hasNext()) throw new NoSuchElementException();\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tint b = readByte();\n\t\t\t\twhile(isPrintableChar(b)) {\n\t\t\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\t\t\tb = readByte();\n\t\t\t\t}\n\t\t\t\treturn sb.toString();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\t\tif (!hasNext()) throw new NoSuchElementException();\n\t\t\t\tlong n = 0;\n\t\t\t\tboolean minus = false;\n\t\t\t\tint b = readByte();\n\t\t\t\tif (b == '-') {\n\t\t\t\t\t\tminus = true;\n\t\t\t\t\t\tb = readByte();\n\t\t\t\t}\n\t\t\t\tif (b < '0' || '9' < b) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t}\n\t\t\t\twhile(true){\n\t\t\t\t\t\tif ('0' <= b && b <= '9') {\n\t\t\t\t\t\t\t\tn *= 10;\n\t\t\t\t\t\t\t\tn += b - '0';\n\t\t\t\t\t\t}else if(b == -1 || !isPrintableChar(b)){\n\t\t\t\t\t\t\t\treturn minus ? -n : n;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = readByte();\n\t\t\t\t}\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\t\tlong nl = nextLong();\n\t\t\t\tif (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\n\t\t\t\treturn (int) nl;\n\t\t}\n\t\tpublic double nextDouble() { return Double.parseDouble(next());}\n\t}\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.io.*;\n\npublic class E74 {\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();\n        String s = sc.next();\n        long time = System.currentTimeMillis();\n        int [][] a = new int[m][m];\n        int [][] pre = new int[m][(1 << m)];\n        for (int i = 0; i < n - 1; i++) {\n            if (s.charAt(i) == s.charAt(i + 1)) continue;\n            a[s.charAt(i) - 'a'][s.charAt(i + 1) - 'a']++;\n            a[s.charAt(i + 1) - 'a'][s.charAt(i) - 'a']++;\n        }\n        //System.out.println(\"Process Input: \" + (System.currentTimeMillis() - time));\n        for (int i = 0; i < m; i++) {\n            int b = 0; int stor = 2;\n            for (int j = 1; j < (1 << m); j++) {\n                if (j == stor) {\n                    b++;\n                    stor = (1 << (b + 1));\n                }\n                pre[i][j] = pre[i][j ^ (1 << b)] + a[i][b];\n            }\n        }\n        //System.out.println(\"Precomp: \" + (System.currentTimeMillis() - time));\n        long [] dp = new long[1 << m];\n        Arrays.fill(dp, Integer.MAX_VALUE);\n        dp[0] = 0;\n        for (int mask = 1; mask < (1 << m); mask++) {\n            // loop on the last added character in the mask\n            for (int i = 0; i < m; i++) {\n                if (((mask >> i) & 1) == 0) continue;\n                long prev = dp[mask ^ (1 << i)];\n                long contribution = (pre[i][mask] - pre[i][((1 << m) - 1) ^ mask]) * Integer.bitCount(mask);\n                dp[mask] = Math.min(dp[mask], prev + contribution);\n            }\n        }\n        //System.out.println(\"Done: \" + (System.currentTimeMillis() - time));\n        out.println(dp[(1 << m) - 1]);\n        out.close();\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\t//where's my 420???? :(\n\t\tlong tot = 0;\n\t\tfor(int i = 0; i < 19999; i++) tot += i;\n\t\tSystem.err.println(tot);\n\t\t\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "// No sorcery shall prevail. //           \nimport java.util.*;\nimport java.io.*;\npublic class InVoker {\n\t//Variables\n\tstatic long mod = 1000000007;\n\tstatic long mod2 = 998244353;\n\tstatic FastReader inp= new FastReader();\n\tstatic PrintWriter out= new PrintWriter(System.out);\n\tpublic static void main(String args[]) {\t\t    \t\n\t   \tInVoker g=new InVoker();\n\t   \tg.main();\n\t   \tout.close();\n\t}\n\t\n\tint dp[];\n\tint freq[][];\n\tint m;\n\t\n\t//Main\n\tvoid main() {\n\t\t\n\t\tint n=inp.nextInt();\n\t\tm=inp.nextInt();\n\t\tString s=inp.next();\n\t\tdp=new int[1<<m];\n\t\tArrays.fill(dp, -1);\n\t\tfreq=new int[m][m];\n\t\tfor(int i=0;i<n-1;i++) {\n\t\t\tint x=s.charAt(i)-'a';\n\t\t\tint y=s.charAt(i+1)-'a';\n\t\t\tif(x==y) continue;\n\t\t\tfreq[x][y]++;\n\t\t\tfreq[y][x]++;\n\t\t}\n\t\tout.println(go(0,0));\n\t\t\n\t}\n\t\n\tint go(int pos, int mask) {\n\t\tif(pos==m) return 0;\n\t\tif(dp[mask]!=-1) return dp[mask];\n\t\tint gg=Integer.MAX_VALUE;\n\t\tfor(int i=0;i<m;i++) {\n\t\t\tif((mask>>i&1)==1) continue;\n\t\t\tint cost=0;\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((mask>>j&1)==1) cost+=freq[i][j]*pos;\n\t\t\t\telse cost-=freq[i][j]*pos;\n\t\t\t}\n\t\t\tcost+=go(pos+1,mask|(1<<i));\n\t\t\tgg=Math.min(gg, cost);\n\t\t}\n\t\treturn dp[mask]=gg;\n\t}\n\t\n\t\n\t\n\t\n\t/*********************************************************************************************************************************************************************************************************\n\t * ti;.                               .:,:i:         :,;;itt;.        fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE      :,:.    f::::. .,ijLGDDDDDDDEEEEEEE*\n\t *ti;.                               .:,:i:          .:,;itt;:      GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG.     .::.      f:,...,ijLGDDDDDDDDEEEEEE *\n\t *ti;.                               .:,:i:            :,;;iti,    :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG     .::.       .f,::,ijLGDDDDDDDDEEEEEE *\n\t *ti;.                               .:,:i:             .,,;iti;.  LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj    .::.        .:L;;ijfGDDDDDDDDDEEEEE *\n\t *ti;.                               .:,:i:              .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL    .::.         .:;LijLGGDDDDDDDDEEEEE *\n\t *ti;.                               .:,:;:                :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj   .::.          :,;jffGGDDDDDDDDDEEEE *\n\t *ti;.                               .:,:i:                 .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL   .::.          .:;itDGGDDDDDDDDDEEEE *\n\t *ti;.                               .:::;:                   :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf   .::.           :,itfGEDDDDDDDDDDDEE *\n\t *ti;.                               .:::;:                    :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG  .::.           .,;jfLGKDLDDDDDDEEDD *\n\t *ti;.                               .:::;:                     fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::.           .,;tfLGDEDDDDDDDDEEE *\n\t *ti;.                                :::;:                    fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::.           .,;tfLGDDDKDDDDDDDDD *\n\t *ti;.                                .::;:                    fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:.           .,;tfLGGDDDKDDDDDDDD *\n\t *ti;.                                .:.;:                   tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::.           .,;tfLGGDDDDEDDDDDDD *\n\t *ti;.                                .::;:                   fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::.           .,;tfLGGDDDDDDEDDDDD *\n\t *ti;.                                .:.;:                  tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::.           .,;tfLGGDDDDDDDEDDDD *\n\t *ti;.                                .:.,.                  LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:.           .,;tfLGGDDDDDDDDEDDD *\n\t *ti;.                               ..:.,.                 LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,.           .,;tfLGGDDDDDDDDDKDD *\n\t *tt;.                                .:.,:                 jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,:           .,;tfLGGDDDDDDDDDDKD *\n\t *tii,.                               .:.,.                tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,.          .,;tfLGGDDDDDDDDDDDE *\n\t *ti;;,:.                             .:.,:                fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,.         .,;tfLGGDDDDDDDDDDDD *\n\t *tii;,,:..                           ...,.               ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,:        .,itfLGGDDDDDDDDDDDD *\n\t *ti;,,,,,:.                          ...,.               LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:.      .,itfGGGDDDDDDDDDDDD *\n\t *tii,,,,::::.                        ...,:              .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:.     .,ijfGGGDDDDDDDDDDDD *\n\t *ti;:::::::::..                      .:.,:              LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,:    .,ijLGGGDDDDDDDDDDDD *\n\t *tt;. .::::::::..                    ...,:             :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:.  .:,;,:.  .,ijLGGDDDDDDDDDDDDD *\n\t *tt;.   .:::::::..                   ...,:             GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,.    :,,,:...,ijLGGGDDDDDDDDDDDD *\n\t *tt;.    .....::::..                 ...,:             fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi.     .,;,:::,ijLGGGDDDDDDDDDDDD *\n\t *tt;.      ....:::::.                ...,.            iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff.      .:,;,,;ijLGGGDDDDDDDDDDDD *\n\t *tt;.        ....::::..              .:.,:           .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG.       .:,;;iijLGGGDDDDDDDDDDDD *\n\t *tt;.          .....:::..            ...,.           .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG.         :,iitjLGGGDDDDDDDDDDDD *\n\t *tti.            .....:::..          ...,.           GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf.          .,;tjfLGGDDDDDDDDDDDD *\n\t *tti.              ....::::..        ...,.           fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf.           :;ijfLGGDDDDDDDDDDDD *\n\t *tti.                ....::::..      ...,.          LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf:           .,itfLGGDDDDDDDDDDDD *\n\t *tti.                 .....:::..     ...,.          fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi           .,;tfLGGGDDDDDDDDDDD *\n\t *tti.                   .....:::..   ...,.         iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL           .,;tjLLGGDDDDDDDDDDD *\n\t *tti.                     ....::::......:.         LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG           .,;tjLLGGDDDDDDDDDDD *\n\t *tti.                        ...::::::..,.        :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL           .,;tjLLGGDDDDDDDDDDD *\n\t *tti.                         ....::::::,.        GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf           .,;tjLLGGDDDDDDDDDDD *\n\t *tti.                           ....:::,,.       .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf           .:;tjLLGGGDDDDDDDDDD *\n\t *tti.                             ...::,,,:.     GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf           .:;tjLLGGDDDDDDDDDDD *\n\t *jti.                              ...::,,,,:.  .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf:          .,;tfLLGGDDDDDDDDDDD *\n\t *tti.                               ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi          .,;tfLLGGGDDDDDDDDDD *\n\t *tti.                               ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL          .,;tfLGGGDDDDDDDDDDD *\n\t *jti.                                ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG          .,;tfLGGGGDDDDDDDDDD *\n\t *jti.                                ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL          .,;tfLGGGGDDDDDDDDDD *\n\t *jti.                                ...:.  .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf          .,;tfGGGGDDDDDDDDDDD *\n\t *jti.                                ...:.    ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi  EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:.        .,;tfGGGGDDDDDDDDDDD *\n\t *jti.                                ...:.    GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff     .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,:       .,;tfGGGGDDDDDDDDDDD *\n\t *jti.                                ...:.    GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK,   ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:.     .,;tfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:.  .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:.   .,;tfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:.   DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:.  fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG  .:,,,:::,;tfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL    .:,;,,,;tfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf     .:,;;;itfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf       .,;iitfGGGDDDDDDDDDDDD *\n\t *jti.                                ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL        .:;itfGGGDDDDDDDDDDDD *\n\t *jji.                                ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j.  KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf         .,;tfGGGDDDDDDDDDDDD *\n\t *jji.                                ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;..................................  . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL,        .:;tfGGGDDDDDDDDDDDD *\n\t *jji.                               .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................::  KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj        .:;tfGGDDDDDDDDDDDDD *\n\t *jji.                             .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG        .:;tfGGGDDDDDDDDDDDD *\n\t *jji.                          . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG     .;tjfLLGDDDDDDDDDDDDDDD *\n\t *jji.                          i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL  ,fGGGDDDDDDDDEEEDDDDDDDDDD *\n\t *jji.                        .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD *\n\t *jji.                       i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD *\n\t *jji.                     .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD *\n\t *jji.                    .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL;   .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD *\n\t *jji.                   :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED *\n\t *jji.                  i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE *\n\t *jji.                 i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD *\n\t *jji.                .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG *\n\t *jjt.                :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG *\n\t *jji.               ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG *\n\t *jjt.              f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG *\n\t *jjt.             ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG *\n\t *fji.             ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL *\n\t *fji.            t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL *\n\t *fjt:            .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL *\n\t *fjji;:.       .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG *\n\t *fjjtii;,:.     :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG *\n\t *fjtiiiii;;:.  j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG *\n\t *fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG *\n\t *fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD *\n\t *jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD *\n\t *fjt.    .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD *\n\t *fjt.       .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD *\n\t *fjt.       .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD *\n\t *fjt:        :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD *\n\t *fjt:       t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD *\n\t *jjt.       f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD *\n\t *fjt:.      ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG *\n\t *fjt:.     ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; *\n\t *fjt:.     f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, *\n\t *fjt:.    .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, *\n\t *fjt:.  .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, *\n\t *fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, *\n\t *fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, *\n\t *fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *\n\t *fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *\n\t *fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; *\n\t ***********************************************************************************************************************************************************************************************************/\n\n\tvoid sort(int a[]) {\n\t\tArrayList<Integer> list=new ArrayList<>();\n\t\tfor(int x: a) list.add(x);\n\t\tCollections.sort(list);\n\t\tfor(int i=0;i<a.length;i++) a[i]=list.get(i);\n\t}\n\tvoid sort(long a[]) {\n\t\tArrayList<Long> list=new ArrayList<>();\n\t\tfor(long x: a) list.add(x);\n\t\tCollections.sort(list);\n\t\tfor(int i=0;i<a.length;i++) a[i]=list.get(i);\n\t}\n\tvoid ruffleSort(int a[]) {\n\t\tRandom rand=new Random();\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint j=rand.nextInt(n);\n\t\t\tint temp=a[i];\n\t\t\ta[i]=a[j];\n\t\t\ta[j]=temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tvoid ruffleSort(long a[]) {\n\t\tRandom rand=new Random();\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint j=rand.nextInt(n);\n\t\t\tlong temp=a[i];\n\t\t\ta[i]=a[j];\n\t\t\ta[j]=temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\t\n    static class FastReader { \n        BufferedReader br; \n        StringTokenizer st;\n        public FastReader() { \n            br = new BufferedReader(new InputStreamReader(System.in)); \n        } \n        String next() { \n            while (st==null || !st.hasMoreElements()) { \n                try { \n                    st = new StringTokenizer(br.readLine()); \n                } \n                catch (IOException  e) { \n                    e.printStackTrace(); \n                } \n            } \n            return st.nextToken(); \n        } \n        int nextInt() { \n            return Integer.parseInt(next()); \n        } \n        long nextLong() { \n            return Long.parseLong(next()); \n        } \n        double nextDouble() { \n            return Double.parseDouble(next()); \n        } \n        String nextLine() { \n            String s=\"\"; \n            try { \n                s=br.readLine(); \n            } \n            catch (IOException e) { \n                e.printStackTrace(); \n            } \n            return s; \n        } \n    } \n    \n\tlong fact[];\n\tlong invFact[];\n\tvoid init(int n) {\n\t\tfact=new long[n+1];\n\t\tinvFact=new long[n+1];\n\t\tfact[0]=1;\n\t\tfor(int i=1;i<=n;i++) {\n\t\t\tfact[i]=mul(i,fact[i-1]);\n\t\t}\n\t\tinvFact[n]=power(fact[n],mod-2);\n\t\tfor(int i=n-1;i>=0;i--) {\n\t\t\tinvFact[i]=mul(invFact[i+1],i+1);\n\t\t}\n\t}\n\t\n\tlong nCr(int n, int r) {\n\t\tif(n<r || r<0) return 0;\n\t\treturn mul(fact[n],mul(invFact[r],invFact[n-r]));\n\t}\n\t\n\tlong mul(long a, long b) {\n\t\treturn a*b%mod;\n\t}\n\tlong add(long a, long b) {\n\t\treturn (a+b)%mod;\n\t}\n\t\n\tlong power(long x, long y) {\n\t\tlong gg=1;\n\t\twhile(y>0) {\n\t\t\tif(y%2==1) gg=mul(gg,x);\n\t\t\tx=mul(x,x);\n\t\t\ty/=2;\n\t\t}\n\t\treturn gg;\n\t}\n    \n    // Functions\n\tstatic long gcd(long a, long b) { \n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tstatic int gcd(int a, int b) { \n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\t\n\tvoid print(int a[]) {\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) out.print(a[i]+\" \");\n\t}\n\t\n\tvoid print(long a[]) {\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) out.print(a[i]+\" \");\n\t}\n    \n    //Input Arrays\n    static void input(long a[], int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i]=inp.nextLong();\n\t\t}\n\t}\n\tstatic void input(int a[], int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i]=inp.nextInt();\n\t\t}\n\t}\t\n\tstatic void input(String s[],int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ts[i]=inp.next();\n\t\t}\n\t}\n\tstatic void input(int a[][], int n, int m) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\ta[i][j]=inp.nextInt();\n\t\t\t}\n\t\t}\n\t}\n\tstatic void input(long a[][], int n, int m) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\ta[i][j]=inp.nextLong();\n\t\t\t}\n\t\t}\n\t}\n\t\t\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.util.*;\nimport java.lang.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.*;\nimport java.math.*;\npublic class Main {\n    public void dfs(ArrayList<Integer>[] graph,int[] visited,int source) {\n        \n    }\n    public static void main(String[] args) throws Exception{\n        Reader.init(System.in);\n        PrintWriter out = new PrintWriter(System.out);\n        Main mm =new Main();\n        int n=Reader.nextInt();\n        int m=Reader.nextInt();\n        String s=Reader.next();\n        int[][] count=new int[m][m];\n        for(int i=1;i<n;i++) {\n            count[s.charAt(i)-'a'][s.charAt(i-1)-'a']++;\n            count[s.charAt(i-1)-'a'][s.charAt(i)-'a']++;\n        }\n        int[] dp=new int[1<<m];\n        Arrays.fill(dp, Integer.MAX_VALUE/10);\n        for(int i=0;i<m;i++) {\n            dp[1<<i]=0;\n        }\n        for(int i=0;i<(1<<m);i++) {\n            int extra=0;\n            for(int j=0;j<m;j++) {\n                if((i&(1<<j))>0) {\n                for(int k=0;k<m;k++) {\n                    if(j!=k &&  (i&(1<<k))==0) {\n                        extra+=count[j][k];\n                    }\n                }\n               }\n            }\n            for(int j=0;j<m;j++) {\n                if((i&(1<<j))==0) {\n                    dp[i|(1<<j)]=Math.min(dp[i|(1<<j)], dp[i]+extra);\n                }\n            }\n        }\n        out.println(dp[(1<<m)-1]);\n        out.close();\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         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        return 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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class E {\n    static int g[][];\n    static int n, m;\n    static char[] s;\n    static int dp[], inf = (int) 2e9;\n\n    public static void main(String[] args) throws Exception {\n        Scanner in = new Scanner(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        m = in.nextInt();\n        s = in.next().toCharArray();\n        g = new int[m][m];\n        for (int i = 1; i < n; i++) {\n            int x = s[i - 1] - 'a', y = s[i] - 'a';\n            if (x != y) {\n                g[x][y]++;\n                g[y][x]++;\n            }\n        }\n        dp = new int[1 << m];\n        Arrays.fill(dp, -1);\n        pw.println(solve(0, 0));\n\n        pw.close();\n    }\n\n    static int solve(int pos, int mask) {\n        if (pos >= m) return 0;\n        if (dp[mask] != -1) return dp[mask];\n        int min = inf;\n        for (int i = 0; i < m; i++) {\n            if (!check(mask, i)) {\n                int res = 0;\n                for (int j = 0; j < m; j++) {\n                    if (check(mask, j)) res += g[i][j] * pos;\n                    else res -= g[i][j] * pos;\n                }\n                res += solve(pos + 1, set(mask, i));\n                min = min(min, res);\n            }\n        }\n        return dp[mask] = min;\n    }\n\n    static boolean check(int N, int pos) {\n        return (N & (1 << pos)) != 0;\n    }\n\n    static int set(int N, int pos) {\n        return N = N | (1 << pos);\n    }\n\n    static int reset(int N, int pos) {\n        return N = N & ~(1 << pos);\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E_fast {\n    static int g[][];\n    static int n, m;\n    static char[] s;\n    static int dp[], inf = (int) 2e9;\n    static int cost[][];\n\n    public static void main(String[] args) throws Exception {\n        InputReader in = new InputReader(System.in);\n        PrintWriter pw = new PrintWriter(System.out);\n        n = in.nextInt();\n        m = in.nextInt();\n        s = in.next().toCharArray();\n        g = new int[m][m];\n        for (int i = 1; i < n; i++) {\n            int x = s[i - 1] - 'a', y = s[i] - 'a';\n            if (x != y) {\n                g[x][y]++;\n                g[y][x]++;\n            }\n        }\n        cost = new int[m][1 << m];\n        for (int i = 0; i < m; i++) {\n            int w = 0;\n            for (int j = 0; j < m; j++) w += g[i][j];\n            pre(i, 0, 0, -w);\n        }\n        dp = new int[1 << m];\n        Arrays.fill(dp, -1);\n        pw.println(solve(0, 0));\n\n        pw.close();\n    }\n\n    static void pre(int x, int pos, int mask, int w) {\n        if (pos >= m) {\n            cost[x][mask] = w;\n            return;\n        }\n        pre(x, pos + 1, mask, w);\n        pre(x, pos + 1, set(mask, pos), w + 2 * g[x][pos]);\n    }\n\n    static int solve(int pos, int mask) {\n        if (pos >= m) return 0;\n        if (dp[mask] != -1) return dp[mask];\n        int min = inf;\n        for (int i = 0; i < m; i++) {\n            if (!check(mask, i)) {\n                int res = cost[i][mask] * pos + solve(pos + 1, set(mask, i));\n                min = min(min, res);\n            }\n        }\n        return dp[mask] = min;\n    }\n\n    static boolean check(int N, int pos) {\n        return (N & (1 << pos)) != 0;\n    }\n\n    static int set(int N, int pos) {\n        return N = N | (1 << pos);\n    }\n\n    static int reset(int N, int pos) {\n        return N = N & ~(1 << pos);\n    }\n\n    static void debug(Object... obj) {\n        System.err.println(Arrays.deepToString(obj));\n    }\n    \n    static class InputReader {\n        public BufferedReader reader;\n        public StringTokenizer tokenizer;\n    \n        public InputReader(InputStream stream) {\n            reader = new BufferedReader(new InputStreamReader(stream));\n            tokenizer = null;\n        }\n    \n        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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tbyte[] str = fs.next().getBytes();\n\t\tint[] occs = new int[1<<m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint l1 = str[i] - 'a';\n\t\t\tint l2 = str[i+1] - 'a';\n\t\t\toccs[(1<<l1) | (1<<l2)]++;\n\t\t\toccs[(1<<l2) | (1<<l1)]++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[1<<i | 1<<trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]>>1);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "\n/**\n * @author egaeus\n * @mail sebegaeusprogram@gmail.com\n * @veredict Accepted\n * @url <https://codeforces.com/problemset/problem/1238/E>\n * @category dp\n * @date 19/10/2019\n **/\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Integer.bitCount;\nimport static java.lang.Integer.parseInt;\n\npublic class CF1238E {\n    static long[][] Q;\n    static int N;\n    static int M;\n    static long[] mem;\n    static long[] sums;\n\n    public static void main(String args[]) throws Throwable {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        for (String ln; (ln = in.readLine()) != null; ) {\n            StringTokenizer st = new StringTokenizer(ln);\n            N = parseInt(st.nextToken());\n            M = parseInt(st.nextToken());\n            char[] S = in.readLine().toCharArray();\n            Q = new long[M][M];\n            mem = new long[1 << M];\n            Arrays.fill(mem, -1);\n            for (int i = 1; i < N; i++)\n                Q[S[i - 1] - 'a'][S[i] - 'a'] = Q[S[i] - 'a'][S[i - 1] - 'a'] = Q[S[i - 1] - 'a'][S[i] - 'a'] + 1;\n            calculateSums();\n            for (int i = (1 << M) - 1; i >= 0; i--)\n                f(i);\n            System.out.println(f(0));\n        }\n    }\n\n    static void calculateSums() {\n        sums = new long[1 << M];\n        Arrays.fill(sums, -1);\n        for (int u = 0; u < (1 << M); u++) {\n            if (sums[u] == -1) {\n                sums[u] = 0;\n                for (int j = 0; j < M; j++)\n                    for (int k = j + 1; k < M; k++)\n                        if (((u & (1 << j)) == 0 && (u & (1 << k)) != 0) ||\n                                ((u & (1 << j)) != 0 && (u & (1 << k)) == 0))\n                            sums[u] += Q[j][k];\n                int neg = (~u) & ((1 << M) - 1);\n                sums[neg] = sums[u];\n            }\n        }\n    }\n\n    static long f(int u) {\n        if (bitCount(u) == M) return 0;\n        if (mem[u] >= 0)\n            return mem[u];\n        long min = 10000000000L;\n        for (int i = 0; i < M; i++)\n            if ((u & (1 << i)) == 0) {\n                u = u | (1 << i);\n                min = Math.min(f(u) + sums[u], min);\n                u = u ^ (1 << i);\n            }\n        return mem[u] = min;\n    }\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "/*Author: Satyajeet Singh, Delhi Technological University*/\n    import java.io.*;\n    import java.util.*;\n    import java.text.*; \n    import java.lang.*;\n    import java.math.*;\n \npublic class Main{\n/*********************************************Constants******************************************/\n    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        \n    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n    static long mod=(long)1e9+7;\n    static long mod1=998244353;\n    static boolean sieve[];\n    static ArrayList<Integer> primes;\n    static long factorial[],invFactorial[];\n    static ArrayList<Pair> graph[];\n    static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n/****************************************Solutions Begins***************************************/  \n    static int n,m;\n    static long cost[][],dp[];\n    public static void main(String[] args) throws Exception{\n        String st[]=nl();\n        n=pi(st[0]);\n        m=pi(st[1]);\n        st=nl();\n        String str=st[0];\n        int mn=10000;\n        for(int i=0;i<n;i++){\n            mn=Math.min(mn,str.charAt(i));\n        }\n        cost=new long[m][m];\n        for(int i=1;i<n;i++){\n            int a1=str.charAt(i-1)-mn;\n            int a2=str.charAt(i)-mn;\n            if(a1==a2)continue;\n            cost[a1][a2]++;\n            cost[a2][a1]++;\n        }\n        int mm=1<<m;\n        dp=new long[mm];\n        Arrays.fill(dp,Long.MAX_VALUE/2);\n        dp[0]=0;\n        //debug(cost);\n        long cntbit[]=new long[mm];\n        int minbit[]=new int[mm];\n\n        for(int mask=1;mask<mm;mask++){\n            cntbit[mask]=1+cntbit[(mask&(mask-1))];\n            for(int i=0;i<m;i++){\n                if(((mask>>i)&1)!=0){\n                    minbit[mask]=i;\n                    break;\n                }\n            }\n        }\n        long cntcost[][]=new long[mm][m];\n        for(int mask=0;mask<mm;mask++){\n            for(int i=0;i<m;i++){\n                int b=minbit[mask];\n                cntcost[mask][i]=cntcost[mask^(1<<b)][i]+cost[i][b];\n            }\n        }\n        int yy=mm-1;\n        for(int mask=0;mask<mm;mask++){\n            long cnt=cntbit[mask];\n            for(int i=0;i<m;i++){\n                if(((mask>>i)&1)!=0){\n                    long ans=cnt*(cntcost[mask][i]-cntcost[yy^mask][i]);\n                    dp[mask]=Math.min(dp[mask],dp[mask^(1<<i)]+ans);\n                }\n            }\n        }\n        out.println(dp[mm-1]);\n/****************************************Solutions Ends**************************************************/\n        out.flush();\n        out.close();\n    }\n/****************************************Template Begins************************************************/\n    static String[] nl() throws Exception{\n        return br.readLine().split(\" \");\n    }\n    static String[] nls() throws Exception{\n        return br.readLine().split(\"\");\n    }\n    static int pi(String str) {\n        return Integer.parseInt(str);\n    }\n    static long pl(String str){\n        return Long.parseLong(str);\n    }\n    static double pd(String str){\n        return Double.parseDouble(str);\n    }\n/***************************************Precision Printing**********************************************/\n    static void printPrecision(double d){\n        DecimalFormat ft = new DecimalFormat(\"0.000000000000000000000\"); \n        out.println(ft.format(d));\n    }\n/**************************************Bit Manipulation**************************************************/\n    static void printMask(long mask){\n        System.out.println(Long.toBinaryString(mask));\n    }\n    static int countBit(long mask){\n        int ans=0;\n        while(mask!=0){\n            if(mask%2==1){\n                ans++;\n            }\n            mask/=2;\n        }\n        return ans;\n    }\n/******************************************Graph*********************************************************/\n    static void Makegraph(int n){\n        graph=new ArrayList[n];\n        for(int i=0;i<n;i++){\n            graph[i]=new ArrayList<>();\n        }\n    }\n    static void addEdge(int a,int b){\n        graph[a].add(new Pair(b,1));\n    }\n    static void addEdge(int a,int b,int c){\n        graph[a].add(new Pair(b,c));\n    }    \n/*********************************************PAIR********************************************************/\n    static class PairComp implements Comparator<Pair>{\n        public int compare(Pair p1,Pair p2){\n            return p1.u-p2.u;\n        }\n    }\n    static class Pair implements Comparable<Pair> {\n        int u;\n        int v;\n        int index=-1;\n        public Pair(int u, int v) {\n            this.u = u;\n            this.v = v;\n        }\n        public int hashCode() {\n            int hu = (int) (u ^ (u >>> 32));\n            int hv = (int) (v ^ (v >>> 32));\n            return 31 * hu + hv;\n        }\n        public boolean equals(Object o) {\n            Pair other = (Pair) o;\n            return u == other.u && v == other.v;\n        }\n        public int compareTo(Pair other) {\n            if(index!=other.index)\n                return Long.compare(index, other.index);\n            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n        }\n        public String toString() {\n            return \"[u=\" + u + \", v=\" + v + \"]\";\n        }\n    }\n/******************************************Long Pair*******************************************************/\n    static class PairCompL implements Comparator<Pairl>{\n        public int compare(Pairl p1,Pairl p2){\n            long a=p1.u*p2.v;\n            long b=p2.u*p1.v;\n            if(a>b){\n                return -1;\n            }\n            else if(a<b){\n                return 1;\n            }\n            else{\n                return 0;\n            }\n        }\n    }\n    static class Pairl implements Comparable<Pairl> {\n            long u;\n            long v;\n            int index=-1;\n            public Pairl(long u, long v) {\n                this.u = u;\n                this.v = v;\n            }\n    \n            public int hashCode() {\n                int hu = (int) (u ^ (u >>> 32));\n                int hv = (int) (v ^ (v >>> 32));\n                return 31 * hu + hv;\n            }\n    \n            public boolean equals(Object o) {\n                Pairl other = (Pairl) o;\n                return u == other.u && v == other.v;\n            }\n    \n            public int compareTo(Pairl other) {\n                if(index!=other.index)\n                    return Long.compare(index, other.index);\n                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n            }\n    \n            public String toString() {\n                return \"[u=\" + u + \", v=\" + v + \"]\";\n            }\n        }\n/*****************************************DEBUG***********************************************************/\n    public static void debug(Object... o) {\n        if(!oj)\n        System.out.println(Arrays.deepToString(o));\n    }\n/************************************MODULAR EXPONENTIATION***********************************************/\n    static long modulo(long a,long b,long c) {\n        long x=1;\n        long y=a%c;\n        while(b > 0){\n            if(b%2 == 1){\n                x=(x*y)%c;\n            }\n            y = (y*y)%c; // squaring the base\n            b /= 2;\n        }\n        return  x%c;\n    }\n/********************************************GCD**********************************************************/\n    static long gcd(long x, long y)\n    {\n        if(x==0)\n            return y;\n        if(y==0)\n            return x;\n        long r=0, a, b;\n        a = (x > y) ? x : y; // a is greater number\n        b = (x < y) ? x : y; // b is smaller number\n        r = b;\n        while(a % b != 0)\n        {\n            r = a % b;\n            a = b;\n            b = r;\n        }\n        return r;\n    }\n/******************************************SIEVE**********************************************************/\n    static void sieveMake(int n){\n        sieve=new boolean[n];\n        Arrays.fill(sieve,true);\n        sieve[0]=false;\n        sieve[1]=false;\n        for(int i=2;i*i<n;i++){\n            if(sieve[i]){\n                for(int j=i*i;j<n;j+=i){\n                    sieve[j]=false;\n                }\n            }\n        }\n        primes=new ArrayList<Integer>();\n        for(int i=0;i<n;i++){\n            if(sieve[i]){\n                primes.add(i);\n            }\n        }        \n    }\n/********************************************End***********************************************************/\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.BufferedReader;\nimport java.io.IOException;\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        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        char[] arr = br.readLine().toCharArray();\n        int[][] count = new int[m][m];\n        for (int i = 0; i < n - 1; i++) {\n            count[arr[i] - 'a'][arr[i + 1] - 'a']++;\n            count[arr[i + 1] - 'a'][arr[i] - 'a']++;\n        }\n        int[] memo = new int[1 << m];\n        Arrays.fill(memo, (int) 1e9);\n        memo[0] = 0;\n        for (int msk = 0; msk < 1 << m; msk++) {\n            for (int c = 0; c < m; c++) {\n                if ((msk & 1 << c) != 0)\n                    continue;\n                int temp = 0;\n                for (int i = 0; i < m; i++) {\n                    if (i == c)\n                        continue;\n                    if ((msk & 1 << i) != 0) {\n                        temp += count[c][i];\n                    } else\n                        temp -= count[c][i];\n                }\n                memo[msk | 1 << c] = Math.min(memo[msk | 1 << c], temp*Integer.bitCount(msk) + memo[msk]);\n            }\n        }\n        System.out.println(memo[(1 << m) - 1]);\n    }\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "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\tout.println(work());\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tlong work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tString str=in.next();\n\t\tlong[] dp=new long[1<<m];\n\t\tlong[][] cnt=new long[m][m];\n\t\tlong[] rec=new long[1<<m];//\u8bb0\u5f55\u6bcf\u6b21\u79fb\u52a8\u7684\u4e00\u4f4d\u600e\u52a0\u7684\u503c\uff0c\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97\n\t\tfor(int i=1;i<n;i++) {\n\t\t\tint n1=str.charAt(i-1)-'a';\n\t\t\tint n2=str.charAt(i)-'a';\n\t\t\tcnt[n1][n2]++;\n\t\t\tcnt[n2][n1]++;\n\t\t}\n\t\tfor(int i=1;i<1<<m;i++) {\n\t\t\tdp[i]=9999999999L;\n\t\t\tlong v=0;\n\t\t\tint b=0;//\u6700\u4f4e\u4f4d\u76841\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))>0) {\n\t\t\t\t\tb=j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))==0) {\n\t\t\t\t\tv+=cnt[b][j];\n\t\t\t\t}else {\n\t\t\t\t\tif(b!=j)v-=cnt[b][j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tv+=rec[i-(1<<b)];\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\tif((i&(1<<j))>0) {\n\t\t\t\t\tdp[i]=Math.min(dp[i], dp[i-(1<<j)]+v);\n\t\t\t\t}\n\t\t\t}\n\t\t\trec[i]=v;\n\t\t}\n\t\t\n\t\treturn dp[(1<<m)-1];\n\t}\n}\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "\n/**\n * @author Juan Sebastian Beltran Rojas\n * @mail jsbeltran.valhalla@gmail.com\n * @veredict\n * @url https://codeforces.com/problemset/problem/1238/E\n * @category dp\n * @date 19/10/2019\n **/\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Integer.bitCount;\nimport static java.lang.Integer.parseInt;\n\npublic class CF1238E {\n    static long[][] Q;\n    static int N;\n    static int M;\n    static long[] mem;\n    static long[] sums;\n\n    public static void main(String args[]) throws Throwable {\n        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n        for (String ln; (ln = in.readLine()) != null; ) {\n            StringTokenizer st = new StringTokenizer(ln);\n            N = parseInt(st.nextToken());\n            M = parseInt(st.nextToken());\n            char[] S = in.readLine().toCharArray();\n            Q = new long[M][M];\n            mem = new long[1 << M];\n            Arrays.fill(mem, -1);\n            for (int i = 1; i < N; i++)\n                Q[S[i - 1] - 'a'][S[i] - 'a'] = Q[S[i] - 'a'][S[i - 1] - 'a'] = Q[S[i - 1] - 'a'][S[i] - 'a'] + 1;\n            calculateSums();\n            for (int i = (1 << M) - 1; i >= 0; i--)\n                f(i);\n            System.out.println(f(0));\n        }\n    }\n\n    static void calculateSums() {\n        sums = new long[1 << M];\n        Arrays.fill(sums, -1);\n        for (int u = 0; u < (1 << M); u++) {\n            if (sums[u] == -1) {\n                sums[u] = 0;\n                for (int j = 0; j < M; j++)\n                    for (int k = j + 1; k < M; k++)\n                        if (((u & (1 << j)) == 0 && (u & (1 << k)) != 0) ||\n                                ((u & (1 << j)) != 0 && (u & (1 << k)) == 0))\n                            sums[u] += Q[j][k];\n                int neg = (~u) & ((1 << M) - 1);\n                sums[neg] = sums[u];\n            }\n        }\n    }\n\n    static long f(int u) {\n        if (bitCount(u) == M) return 0;\n        if (mem[u] >= 0)\n            return mem[u];\n        long min = 10000000000L;\n        for (int i = 0; i < M; i++)\n            if ((u & (1 << i)) == 0) {\n                u = u | (1 << i);\n                min = Math.min(f(u) + sums[u], min);\n                u = u ^ (1 << i);\n            }\n        return mem[u] = min;\n    }\n}\n", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint n, m;\n\tchar[] str;\n\tint[][] occs, cost;\n\tint[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tn = fs.nextInt(); m = fs.nextInt();\n\t\tstr = fs.next().toCharArray();\n\t\toccs = new int[m][m];\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\toccs[str[i]-'a'][str[i+1]-'a']++;\n\t\t\toccs[str[i+1]-'a'][str[i]-'a']++;\n\t\t}\n\t\t//cost[mask][v] = numPairs with v for some all bits on in mask\n\t\tint all = (1<<m)-1;\n\t\tcost = new int[m][1<<m];\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tfor(int mask = 1; mask < all; mask++) {\n\t\t\t\tif(((1<<i)&mask) > 0) continue;\n\t\t\t\tint lb = mask & (-mask);\n\t\t\t\tint trail = Integer.numberOfTrailingZeros(lb);\n\t\t\t\tint nmask = mask ^ lb;\n\t\t\t\tcost[i][mask] = cost[i][nmask]+occs[i][trail];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new int[1<<m];\n\t\tfor(int mask = dp.length-2; mask >= 0; mask--) {\n\t\t\tint addOn = 0;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\taddOn += cost[nxt][mask];\n\t\t\t}\n\t\t\tint res = oo;\n\t\t\tfor(int nxt = 0; nxt < m; nxt++) {\n\t\t\t\tif(((1<<nxt)&mask) > 0) continue;\n\t\t\t\tint ret = addOn+dp[mask | (1<<nxt)];\n\t\t\t\tres = min(res, ret);\n\t\t\t}\n\t\t\tdp[mask] = res;\n\t\t}\n\t\t\n\t\tSystem.out.println(dp[0]);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint oo = (int)1e9;\n\tint min(int a, int b) {\n\t\tif(a < b) return a;\n\t\treturn b;\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}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
{"src": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\n// editorial sol\n\npublic class cf1238e {\n\n    public static void main(String[] args) throws IOException {\n        int n = rni(), m = ni(), cnt[][] = new int[m][m], dp[] = new int[1 << m], all = (1 << m) - 1;\n        char[] s = rcha();\n        for (int i = 1; i < n; ++i) {\n            ++cnt[s[i] - 'a'][s[i - 1] - 'a'];\n            ++cnt[s[i - 1] - 'a'][s[i] - 'a'];\n        }\n        fill(dp, IBIG);\n        dp[0] = 0;\n        int cnt_bit[] = new int[1 << m], min_bit[] = new int[1 << m], d[][] = new int[1 << m][m];\n        for (int mask = 1; mask <= all; ++mask) {\n            cnt_bit[mask] = 1 + cnt_bit[mask & (mask - 1)];\n            for (int i = 0; i < n; ++i) {\n                if ((mask & (1 << i)) > 0) {\n                    min_bit[mask] = i;\n                    break;\n                }\n            }\n        }\n        for (int mask = 1; mask <= all; ++mask) {\n            for (int i = 0; i < m; ++i) {\n                d[mask][i] = d[mask ^ (1 << min_bit[mask])][i] + cnt[i][min_bit[mask]];\n            }\n        }\n        for (int mask = 0; mask <= all; ++mask) {\n            for (int i = 0; i < m; ++i) {\n                if ((mask & (1 << i)) > 0) {\n                    continue;\n                }\n                int pos = cnt_bit[mask], next = mask | (1 << i);\n                dp[next] = min(dp[next], dp[mask] + pos * (d[mask][i] - d[all ^ next][i]));\n            }\n        }\n        prln(dp[all]);\n        close();\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<List<Integer>> g(int n) {List<List<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n    static List<Set<Integer>> sg(int n) {List<Set<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n    static void c(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n    static void cto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);}\n    static void dc(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n    static void dcto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);}\n    // input\n    static void r() throws IOException {input = new StringTokenizer(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<List<Integer>> rg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n    static void rg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n    static List<List<Integer>> rdg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n    static void rdg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n    static List<Set<Integer>> rsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n    static void rsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n    static List<Set<Integer>> rdsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n    static void rdsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n    // output\n    static void pr(int i) {__out.print(i);}\n    static void prln(int i) {__out.println(i);}\n    static void pr(long l) {__out.print(l);}\n    static void prln(long l) {__out.println(l);}\n    static void pr(double d) {__out.print(d);}\n    static void prln(double d) {__out.println(d);}\n    static void pr(char c) {__out.print(c);}\n    static void prln(char c) {__out.println(c);}\n    static void pr(char[] s) {__out.print(new String(s));}\n    static void prln(char[] s) {__out.println(new String(s));}\n    static void pr(String s) {__out.print(s);}\n    static void prln(String s) {__out.println(s);}\n    static void pr(Object o) {__out.print(o);}\n    static void prln(Object o) {__out.println(o);}\n    static void prln() {__out.println();}\n    static void pryes() {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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> 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();}}", "complexity": "np", "problem": "1238_E. Keyboard Purchase", "from": "CODEFORCES"}
